CPreGame.cpp 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037
  1. #include "stdafx.h"
  2. #include "CPreGame.h"
  3. #include "SDL.h"
  4. #include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
  5. #include "boost/algorithm/string.hpp"
  6. //#include "boost/foreach.hpp"
  7. #include "zlib.h"
  8. #include "timeHandler.h"
  9. #include <sstream>
  10. #include "SDL_Extensions.h"
  11. #include "CGameInfo.h"
  12. #include "hch\CGeneralTextHandler.h"
  13. #include "CCursorHandler.h"
  14. #include "CScreenHandler.h"
  15. #include "hch\CLodHandler.h"
  16. #include "hch\CTownHandler.h"
  17. #include "hch\CHeroHandler.h"
  18. #include <cmath>
  19. extern SDL_Surface * ekran;
  20. extern SDL_Color tytulowy, tlo, zwykly ;
  21. extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
  22. SDL_Rect genRect(int hh, int ww, int xx, int yy);
  23. SDL_Color genRGB(int r, int g, int b, int a=0);
  24. //void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran);
  25. CPreGame * CPG;
  26. bool isItIn(const SDL_Rect * rect, int x, int y);
  27. namespace fs = boost::filesystem;
  28. namespace s = CSDL_Ext;
  29. void HighButton::show()
  30. {
  31. blitAt(imgs->ourImages[state].bitmap,pos.x,pos.y);
  32. updateRect(&pos);
  33. }
  34. void HighButton::press(bool down)
  35. {
  36. int i;
  37. if (down) state=i=1;
  38. else state=i=0;
  39. SDL_BlitSurface(imgs->ourImages[i].bitmap,NULL,ekran,&pos);
  40. updateRect(&pos);
  41. }
  42. template <class T> void SetrButton<T>::press(bool down=true)
  43. {
  44. if (!down && state==1)
  45. *poin=key;
  46. HighButton::press(down);
  47. }
  48. void HighButton::hover(bool on)
  49. {
  50. if (!highlightable) return;
  51. int i;
  52. if (on)
  53. {
  54. state=i=3;
  55. highlighted=true;
  56. }
  57. else
  58. {
  59. state=i=0;
  60. highlighted=false;
  61. }
  62. SDL_BlitSurface(imgs->ourImages[i].bitmap,NULL,ekran,&pos);
  63. updateRect(&pos);
  64. }
  65. template <class T> void Button<T>::hover(bool on=true)
  66. {
  67. HighButton::hover(on);
  68. }
  69. template <class T> void Button<T>::select(bool on)
  70. {
  71. int i;
  72. if (on) state=i=3;
  73. else state=i=0;
  74. SDL_BlitSurface(imgs->ourImages[i].bitmap,NULL,ekran,&pos);
  75. updateRect(&pos);
  76. if (ourGroup && on && ourGroup->type==1)
  77. {
  78. if (ourGroup->selected && ourGroup->selected!=this)
  79. ourGroup->selected->select(false);
  80. ourGroup->selected =this;
  81. }
  82. }
  83. //void Slider::clickDown(int x, int y, bool bzgl=true);
  84. //void Slider::clickUp(int x, int y, bool bzgl=true);
  85. //void Slider::mMove(int x, int y, bool bzgl=true);
  86. void Slider<>::updateSlid()
  87. {
  88. float perc = ((float)whereAreWe)/((float)positionsAmnt-capacity);
  89. float myh;
  90. if (vertical)
  91. {
  92. myh=perc*((float)pos.h-48)+pos.y+16;
  93. SDL_FillRect(ekran,&genRect(pos.h-32,pos.w,pos.x,pos.y+16),0);
  94. blitAt(slider.imgs->ourImages[0].bitmap,pos.x,(int)myh);
  95. slider.pos.y=(int)myh;
  96. }
  97. else
  98. {
  99. myh=perc*((float)pos.w-48)+pos.x+16;
  100. SDL_FillRect(ekran,&genRect(pos.h,pos.w-32,pos.x+16,pos.y),0);
  101. blitAt(slider.imgs->ourImages[0].bitmap,(int)myh,pos.y);
  102. slider.pos.x=(int)myh;
  103. }
  104. updateRect(&pos);
  105. }
  106. void Slider<>::moveDown()
  107. {
  108. if (whereAreWe<positionsAmnt-capacity)
  109. (CPG->*fun)(++whereAreWe);
  110. updateSlid();
  111. }
  112. void Slider<>::moveUp()
  113. {
  114. if (whereAreWe>0)
  115. (CPG->*fun)(--whereAreWe);
  116. updateSlid();
  117. }
  118. //void Slider::moveByOne(bool up);
  119. Slider<>::Slider(int x, int y, int h, int amnt, int cap, bool ver)
  120. {
  121. vertical=ver;
  122. positionsAmnt = amnt;
  123. capacity = cap;
  124. if (ver)
  125. {
  126. pos = genRect(h,16,x,y);
  127. down = Button<void(Slider::*)()>(genRect(16,16,x,y+h-16),&Slider::moveDown,CGI->spriteh->giveDef("SCNRBDN.DEF"),false);
  128. up = Button<void(Slider::*)()>(genRect(16,16,x,y),&Slider::moveUp,CGI->spriteh->giveDef("SCNRBUP.DEF"),false);
  129. slider = Button<void(Slider::*)()>(genRect(16,16,x,y+16),NULL,CGI->spriteh->giveDef("SCNRBSL.DEF"),false);
  130. }
  131. else
  132. {
  133. pos = genRect(16,h,x,y);
  134. down = Button<void(Slider::*)()>(genRect(16,16,x+h-16,y),&Slider::moveDown,CGI->spriteh->giveDef("SCNRBRT.DEF"),false);
  135. up = Button<void(Slider::*)()>(genRect(16,16,x,y),&Slider::moveUp,CGI->spriteh->giveDef("SCNRBLF.DEF"),false);
  136. slider = Button<void(Slider::*)()>(genRect(16,16,x+16,y),NULL,CGI->spriteh->giveDef("SCNRBSL.DEF"),false);
  137. }
  138. moving = false;
  139. whereAreWe=0;
  140. }
  141. void Slider<>::deactivate()
  142. {
  143. CPG->interested.erase(std::find(CPG->interested.begin(),CPG->interested.end(),this));
  144. }
  145. void Slider<>::activate()
  146. {
  147. SDL_FillRect(ekran,&pos,0);
  148. up.show();
  149. down.show();
  150. slider.show();
  151. //SDL_Flip(ekran);
  152. CSDL_Ext::update(ekran);
  153. CPG->interested.push_back(this);
  154. }
  155. void Slider<>::handleIt(SDL_Event sEvent)
  156. {
  157. if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT))
  158. {
  159. if (isItIn(&down.pos,sEvent.motion.x,sEvent.motion.y))
  160. {
  161. down.press();
  162. }
  163. else if (isItIn(&up.pos,sEvent.motion.x,sEvent.motion.y))
  164. {
  165. up.press();
  166. }
  167. else if (isItIn(&slider.pos,sEvent.motion.x,sEvent.motion.y))
  168. {
  169. //slider.press();
  170. moving=true;
  171. }
  172. else if (isItIn(&pos,sEvent.motion.x,sEvent.motion.y))
  173. {
  174. float dy;
  175. float pe;
  176. if (vertical)
  177. {
  178. dy = sEvent.motion.y-pos.y-16;
  179. pe = dy/((float)(pos.h-32));
  180. if (pe>1) pe=1;
  181. if (pe<0) pe=0;
  182. }
  183. else
  184. {
  185. dy = sEvent.motion.x-pos.x-16;
  186. pe = dy/((float)(pos.w-32));
  187. if (pe>1) pe=1;
  188. if (pe<0) pe=0;
  189. }
  190. whereAreWe = pe*(positionsAmnt-capacity);
  191. if (whereAreWe<0)whereAreWe=0;
  192. updateSlid();
  193. (CPG->*fun)(whereAreWe);
  194. }
  195. }
  196. else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
  197. {
  198. if ((down.state==1) && isItIn(&down.pos,sEvent.motion.x,sEvent.motion.y))
  199. {
  200. (this->*down.fun)();
  201. }
  202. if ((up.state==1) && isItIn(&up.pos,sEvent.motion.x,sEvent.motion.y))
  203. {
  204. (this->*up.fun)();
  205. }
  206. if (down.state==1) down.press(false);
  207. if (up.state==1) up.press(false);
  208. if (moving)
  209. {
  210. //slider.press();
  211. moving=false;
  212. }
  213. }
  214. else if (sEvent.type==SDL_KEYDOWN)
  215. {
  216. switch (sEvent.key.keysym.sym)
  217. {
  218. case (SDLK_UP):
  219. CPG->ourScenSel->mapsel.moveByOne(true);
  220. break;
  221. case (SDLK_DOWN):
  222. CPG->ourScenSel->mapsel.moveByOne(false);
  223. break;
  224. }
  225. }
  226. else if (moving && sEvent.type==SDL_MOUSEMOTION)
  227. {
  228. if (isItIn(&genRect(pos.h,pos.w+64,pos.x-32,pos.y),sEvent.motion.x,sEvent.motion.y))
  229. {
  230. int my;
  231. int all;
  232. float ile;
  233. if (vertical)
  234. {
  235. my = sEvent.motion.y-(pos.y+16);
  236. all =pos.h-48;
  237. ile = (float)my / (float)all;
  238. if (ile>1) ile=1;
  239. if (ile<0) ile=0;
  240. }
  241. else
  242. {
  243. my = sEvent.motion.x-(pos.x+16);
  244. all =pos.w-48;
  245. ile = (float)my / (float)all;
  246. if (ile>1) ile=1;
  247. if (ile<0) ile=0;
  248. }
  249. int ktory = ile*(positionsAmnt-capacity);
  250. if (ktory!=whereAreWe)
  251. {
  252. whereAreWe=ktory;
  253. updateSlid();
  254. }
  255. (CPG->*fun)(whereAreWe);
  256. }
  257. }
  258. /*else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
  259. {
  260. if (ourScenSel->pressed)
  261. {
  262. ourScenSel->pressed->press(false);
  263. ourScenSel->pressed=NULL;
  264. }
  265. for (int i=0;i<btns.size(); i++)
  266. {
  267. if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
  268. {
  269. if (btns[i]->selectable)
  270. btns[i]->select(true);
  271. if (btns[i]->fun)
  272. (this->*(btns[i]->fun))();
  273. return;
  274. }
  275. }
  276. if (isItIn(&down.pos,sEvent.motion.x,sEvent.motion.y))
  277. {
  278. (this->*down.fun)();
  279. }
  280. if (isItIn(&up.pos,sEvent.motion.x,sEvent.motion.y))
  281. {
  282. (this->*up.fun)();
  283. }
  284. if (isItIn(&slider.pos,sEvent.motion.x,sEvent.motion.y))
  285. {
  286. (this->*slider.fun)();
  287. }
  288. }*/
  289. }
  290. /********************************************************************************************/
  291. void PreGameTab::show()
  292. {
  293. if (CPG->currentTab)
  294. CPG->currentTab->hide();
  295. showed=true;
  296. CPG->currentTab=this;
  297. }
  298. void PreGameTab::hide()
  299. {
  300. showed=false;
  301. CPG->currentTab=NULL;
  302. }
  303. PreGameTab::PreGameTab()
  304. {
  305. showed=false;
  306. }
  307. /********************************************************************************************/
  308. Options::PlayerOptions::PlayerOptions(int serial, int player)
  309. :Cleft(genRect(24,11,164,133+serial*50),CPG->ourOptions->left,true,-1), //left castle arrow
  310. Cright(genRect(24,11,225,133+serial*50),CPG->ourOptions->right,false,-1), //right castle arrow
  311. Hleft(genRect(24,11,240,133+serial*50),CPG->ourOptions->left,true,0), //left hero arrow
  312. Hright(genRect(24,11,301,133+serial*50),CPG->ourOptions->right,false,0), //right hero arrow
  313. Bleft(genRect(24,11,316,133+serial*50),CPG->ourOptions->left,true,1), //left bonus arrow
  314. Bright(genRect(24,11,377,133+serial*50),CPG->ourOptions->right,false,1), //right bonus arrow
  315. flag(genRect(50,42,14,130+serial*50),CPG->ourOptions->flags[player],player)
  316. {
  317. Bleft.playerID=Bright.playerID=Hleft.playerID=Hright.playerID=Cleft.playerID=Cright.playerID=player;
  318. Bleft.serialID=Bright.serialID=Hleft.serialID=Hright.serialID=Cleft.serialID=Cright.serialID=serial;
  319. }
  320. void Options::OptionSwitch::press(bool down)
  321. {
  322. HighButton::press(down);
  323. StartInfo::PlayerSettings * ourOpt = &CPG->ret.playerInfos[serialID];
  324. PlayerInfo * ourInf = &CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].players[playerID];
  325. int dir = (left) ? (-1) : (1);
  326. if (down) return;
  327. switch (which)
  328. {
  329. case -1:
  330. {
  331. int oCas = ourOpt->castle;
  332. if (ourOpt->castle==-2) //no castle - no change
  333. return;
  334. else if (ourOpt->castle==-1) //random => first/last available
  335. {
  336. int pom = (left) ? (F_NUMBER-1) : (0); // last or first
  337. for (;pom>=0 && pom<F_NUMBER;pom+=dir)
  338. {
  339. if (((int)pow((double)2,pom))&ourInf->allowedFactions)
  340. {
  341. ourOpt->castle=pom;
  342. break;
  343. }
  344. else continue;
  345. }
  346. }
  347. else // next/previous available
  348. {
  349. for (;;)
  350. {
  351. ourOpt->castle+=dir;
  352. if (((int)pow((double)2,ourOpt->castle))&ourInf->allowedFactions)
  353. {
  354. break;
  355. }
  356. if (ourOpt->castle>=F_NUMBER || ourOpt->castle<0)
  357. {
  358. double p1 = log((double)ourInf->allowedFactions)/log(2.0f)+0.000001f;
  359. double check = p1-((int)p1);
  360. if (check < 0.001)
  361. ourOpt->castle=(int)p1;
  362. else
  363. ourOpt->castle=-1;
  364. break;
  365. }
  366. }
  367. }
  368. if (oCas!=ourOpt->castle) //changed castle
  369. {
  370. ourOpt->hero=-1;
  371. ourOpt->bonus = Ebonus::brandom;
  372. CPG->ourOptions->showIcon(0,serialID,false);
  373. CPG->ourOptions->showIcon(1,serialID,false);
  374. }
  375. break;
  376. }
  377. case 0:
  378. {
  379. if (ourOpt->castle<0)
  380. {
  381. break;
  382. }
  383. if (ourOpt->hero==-2) //no hero - no change
  384. return;
  385. else if (ourOpt->hero==-1) //random => first/last available
  386. {
  387. int pom = (left) ? (ourOpt->castle*HEROES_PER_TYPE*2+15) : (ourOpt->castle*HEROES_PER_TYPE*2); // last or first
  388. for (;pom>=0 && pom<CGI->heroh->heroes.size();pom+=dir)
  389. {
  390. //TODO: checked allowed heroes
  391. {
  392. ourOpt->hero=pom;
  393. break;
  394. }
  395. }
  396. }
  397. else
  398. {
  399. ourOpt->hero+=dir;
  400. if (ourOpt->hero>HEROES_PER_TYPE*ourOpt->castle*2+15 || ourOpt->hero<HEROES_PER_TYPE*ourOpt->castle*2)
  401. {
  402. ourOpt->hero=-1;
  403. if( ourOpt->bonus == bartifact )
  404. {
  405. ourOpt->bonus = brandom;
  406. CPG->ourOptions->showIcon(1, serialID, false);
  407. }
  408. }
  409. break;
  410. }
  411. break;
  412. }
  413. case 1:
  414. {
  415. if (dir>0 && ourOpt->bonus==bresource)
  416. ourOpt->bonus=brandom;
  417. else if (dir<0 && ourOpt->bonus==brandom)
  418. ourOpt->bonus=bresource;
  419. else ourOpt->bonus=(Ebonus)(ourOpt->bonus+dir);
  420. if (ourOpt->hero==-2 && ourOpt->bonus==bartifact) //no hero - can't be artifact
  421. {
  422. if (dir>0)
  423. ourOpt->bonus=brandom;
  424. else ourOpt->bonus=bgold;
  425. }
  426. if (ourOpt->castle==-1 && ourOpt->bonus==bresource)
  427. {
  428. if (dir<0)
  429. ourOpt->bonus=bgold;
  430. else ourOpt->bonus=brandom;
  431. }
  432. break;
  433. }
  434. }
  435. CPG->ourOptions->showIcon(which,serialID,false);
  436. }
  437. void Options::PlayerFlag::press(bool down)
  438. {
  439. HighButton::press(down);
  440. };
  441. void Options::PlayerFlag::hover(bool on)
  442. {
  443. HighButton::hover(on);
  444. }
  445. void Options::showIcon (int what, int nr, bool abs) //what: -1=castle, 0=hero, 1=bonus, 2=all; abs=true -> nr is absolute
  446. {
  447. if (what==-2)
  448. {
  449. showIcon(-1,nr,abs);
  450. showIcon(0,nr,abs);
  451. showIcon(1,nr,abs);
  452. }
  453. int ab, se;
  454. if (!abs)
  455. {
  456. ab = CPG->ret.playerInfos[nr].color;
  457. se = nr;
  458. }
  459. else
  460. {
  461. ab = nr;
  462. for (int i=0; i<CPG->ret.playerInfos.size();i++)
  463. {
  464. if (CPG->ret.playerInfos[i].color==nr)
  465. {
  466. se=i;
  467. break;
  468. }
  469. }
  470. }
  471. StartInfo::PlayerSettings * ourOpt = &CPG->ret.playerInfos[se];
  472. switch (what)
  473. {
  474. case -1:
  475. {
  476. int pom=ourOpt->castle;
  477. if (ourOpt->castle<F_NUMBER && ourOpt->castle>=0)
  478. {
  479. blitAtWR(CGI->townh->getPic(ourOpt->castle,true,false),176,130+50*se);
  480. }
  481. else if (ourOpt->castle==-1)
  482. {
  483. blitAtWR(CPG->ourOptions->rCastle,176,130+50*se);
  484. }
  485. else if (ourOpt->castle==-2)
  486. {
  487. blitAtWR(CPG->ourOptions->nCastle,176,130+50*se);
  488. }
  489. break;
  490. }
  491. case 0:
  492. {
  493. int pom=ourOpt->hero;
  494. if (ourOpt->hero==-1)
  495. {
  496. blitAtWR(CPG->ourOptions->rHero,252,130+50*se);
  497. }
  498. else if (ourOpt->hero==-2)
  499. {
  500. blitAtWR(CPG->ourOptions->nHero,252,130+50*se);
  501. }
  502. else
  503. {
  504. blitAtWR(CGI->heroh->heroes[pom]->portraitSmall,252,130+50*se);
  505. }
  506. break;
  507. }
  508. case 1:
  509. {
  510. int pom;
  511. switch (ourOpt->bonus)
  512. {
  513. case -1:
  514. pom=10;
  515. break;
  516. case 0:
  517. pom=9;
  518. break;
  519. case 1:
  520. pom=8;
  521. break;
  522. case 2:
  523. pom=CGI->townh->towns[ourOpt->castle].bonus;
  524. break;
  525. }
  526. blitAtWR(bonuses->ourImages[pom].bitmap,328,130+50*se);
  527. break;
  528. }
  529. }
  530. }
  531. Options::~Options()
  532. {
  533. if (!inited) return;
  534. for (int i=0; i<bgs.size();i++)
  535. SDL_FreeSurface(bgs[i]);
  536. for (int i=0; i<flags.size();i++)
  537. delete flags[i];
  538. SDL_FreeSurface(bg);
  539. SDL_FreeSurface(rHero);
  540. SDL_FreeSurface(rCastle);
  541. SDL_FreeSurface(nHero);
  542. SDL_FreeSurface(nCastle);
  543. delete turnLength;
  544. delete left;
  545. delete right;
  546. delete bonuses;
  547. }
  548. void Options::init()
  549. {
  550. inited=true;
  551. bg = CGI->bitmaph->loadBitmap("ADVOPTBK.bmp");
  552. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  553. left = CGI->spriteh->giveDef("ADOPLFA.DEF");
  554. right = CGI->spriteh->giveDef("ADOPRTA.DEF");
  555. bonuses = CGI->spriteh->giveDef("SCNRSTAR.DEF");
  556. rHero = CGI->bitmaph->loadBitmap("HPSRAND1.bmp");
  557. rCastle = CGI->bitmaph->loadBitmap("HPSRAND0.bmp");
  558. nHero = CGI->bitmaph->loadBitmap("HPSRAND6.bmp");
  559. nCastle = CGI->bitmaph->loadBitmap("HPSRAND5.bmp");
  560. turnLength = new Slider<>(57,557,195,11,1,false);
  561. turnLength->fun=&CPreGame::setTurnLength;
  562. flags.push_back(CGI->spriteh->giveDef("AOFLGBR.DEF"));
  563. flags.push_back(CGI->spriteh->giveDef("AOFLGBB.DEF"));
  564. flags.push_back(CGI->spriteh->giveDef("AOFLGBY.DEF"));
  565. flags.push_back(CGI->spriteh->giveDef("AOFLGBG.DEF"));
  566. flags.push_back(CGI->spriteh->giveDef("AOFLGBO.DEF"));
  567. flags.push_back(CGI->spriteh->giveDef("AOFLGBP.DEF"));
  568. flags.push_back(CGI->spriteh->giveDef("AOFLGBT.DEF"));
  569. flags.push_back(CGI->spriteh->giveDef("AOFLGBS.DEF"));
  570. bgs.push_back(CGI->bitmaph->loadBitmap("ADOPRPNL.bmp"));
  571. bgs.push_back(CGI->bitmaph->loadBitmap("ADOPBPNL.bmp"));
  572. bgs.push_back(CGI->bitmaph->loadBitmap("ADOPYPNL.bmp"));
  573. bgs.push_back(CGI->bitmaph->loadBitmap("ADOPGPNL.bmp"));
  574. bgs.push_back(CGI->bitmaph->loadBitmap("ADOPOPNL.bmp"));
  575. bgs.push_back(CGI->bitmaph->loadBitmap("ADOPPPNL.bmp"));
  576. bgs.push_back(CGI->bitmaph->loadBitmap("ADOPTPNL.bmp"));
  577. bgs.push_back(CGI->bitmaph->loadBitmap("ADOPSPNL.bmp"));
  578. }
  579. void Options::show()
  580. {
  581. if (showed)return;
  582. PreGameTab::show();
  583. MapSel & ms = CPG->ourScenSel->mapsel;
  584. blitAt(bg,3,6);
  585. CPG->ourScenSel->listShowed=false;
  586. for (int i=0;i<CPG->btns.size();i++)
  587. {
  588. if (CPG->btns[i]->ID!=10) //leave only right panel buttons
  589. {
  590. CPG->btns.erase(CPG->btns.begin()+i);
  591. i--;
  592. }
  593. }
  594. CPG->interested.clear();
  595. CSDL_Ext::printAtMiddle("Advanced Options",225,35,GEORXX);
  596. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[521],224,544,GEOR13); // Player Turn Duration
  597. int playersSoFar=0;
  598. for (int i=0;i<PLAYER_LIMIT;i++)
  599. {
  600. if (!(ms.ourMaps[ms.selected].players[i].canComputerPlay || ms.ourMaps[ms.selected].players[i].canComputerPlay))
  601. continue;
  602. blitAt(bgs[i],57,128+playersSoFar*50);
  603. poptions.push_back(new PlayerOptions(playersSoFar,i));
  604. poptions[poptions.size()-1]->nr=playersSoFar;
  605. poptions[poptions.size()-1]->color=(Ecolor)i;
  606. poptions[poptions.size()-1]->Cleft.show();
  607. poptions[poptions.size()-1]->Cright.show();
  608. poptions[poptions.size()-1]->Hleft.show();
  609. poptions[poptions.size()-1]->Hright.show();
  610. poptions[poptions.size()-1]->Bleft.show();
  611. poptions[poptions.size()-1]->Bright.show();
  612. CPG->btns.push_back(&poptions[poptions.size()-1]->Cleft);
  613. CPG->btns.push_back(&poptions[poptions.size()-1]->Cright);
  614. CPG->btns.push_back(&poptions[poptions.size()-1]->Hleft);
  615. CPG->btns.push_back(&poptions[poptions.size()-1]->Hright);
  616. CPG->btns.push_back(&poptions[poptions.size()-1]->Bleft);
  617. CPG->btns.push_back(&poptions[poptions.size()-1]->Bright);
  618. CSDL_Ext::printAtMiddle(CPG->ret.playerInfos[playersSoFar].name,111,137+playersSoFar*50,GEOR13,zwykly);
  619. if (ms.ourMaps[ms.selected].players[i].canHumanPlay)
  620. {
  621. poptions[poptions.size()-1]->flag.show();
  622. CPG->btns.push_back(&poptions[poptions.size()-1]->flag);
  623. if (ms.ourMaps[ms.selected].players[i].canComputerPlay)
  624. CSDL_Ext::printAtMiddleWB("Human or CPU",86,163+playersSoFar*50,GEORM,7,zwykly);
  625. else
  626. CSDL_Ext::printAtMiddleWB("Human",86,163+playersSoFar*50,GEORM,6,zwykly);
  627. }
  628. else
  629. CSDL_Ext::printAtMiddleWB("CPU",86,163+playersSoFar*50,GEORM,6,zwykly);
  630. playersSoFar++;
  631. }
  632. CSDL_Ext::printAtMiddleWB(CGI->generaltexth->allTexts[516],221,63,GEOR13,55,zwykly);
  633. CSDL_Ext::printAtMiddleWB(CGI->preth->getTitle(CGI->preth->singlePlayerHandicapHeaderID),109,109,GEOR13,14);
  634. CSDL_Ext::printAtMiddleWB(CGI->preth->getTitle(CGI->preth->singleStartingTownHeaderWConfluxID),201,109,GEOR13,10);
  635. CSDL_Ext::printAtMiddleWB(CGI->preth->getTitle(CGI->preth->singleStartingHeroHeaderID),275,109,GEOR13,10);
  636. CSDL_Ext::printAtMiddleWB(CGI->preth->getTitle(CGI->preth->singleStartingBonusHeaderID),354,109,GEOR13,10);
  637. turnLength->activate();
  638. for (int i=0;i<poptions.size();i++)
  639. showIcon(-2,i,false);
  640. SDL_Flip(ekran);
  641. }
  642. void Options::hide()
  643. {
  644. if (!showed) return;
  645. PreGameTab::hide();
  646. for (int i=0; i<CPG->btns.size();i++)
  647. if (CPG->btns[i]->ID==7)
  648. CPG->btns.erase(CPG->btns.begin()+i--);
  649. for (int i=0;i<poptions.size();i++)
  650. delete poptions[i];
  651. poptions.clear();
  652. turnLength->deactivate();
  653. }
  654. MapSel::~MapSel()
  655. {
  656. SDL_FreeSurface(bg);
  657. for (int i=0;i<scenImgs.size();i++)
  658. SDL_FreeSurface(scenImgs[i]);
  659. for (int i=0;i<scenList.size();i++)
  660. delete scenList[i];
  661. delete sFlags;
  662. }
  663. int MapSel::countWL()
  664. {
  665. int ret=0;
  666. for (int i=0;i<ourMaps.size();i++)
  667. {
  668. if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
  669. continue;
  670. else ret++;
  671. }
  672. return ret;
  673. }
  674. void MapSel::printMaps(int from, int to, int at, bool abs)
  675. {
  676. if (true)//
  677. {
  678. int help=-1;
  679. for (int i=0;i<ourMaps.size();i++)
  680. {
  681. if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
  682. continue;
  683. else help++;
  684. if (help==from)
  685. {
  686. from=i;
  687. break;
  688. }
  689. }
  690. }
  691. SDL_Surface * scenin = SDL_CreateRGBSurface(ekran->flags,351,25,ekran->format->BitsPerPixel,ekran->format->Rmask,ekran->format->Gmask,ekran->format->Bmask,ekran->format->Amask);
  692. SDL_Color nasz;
  693. for (int i=at;i<to;i++)
  694. {
  695. if ((i-at+from) > ourMaps.size()-1)
  696. {
  697. SDL_Surface * scenin = SDL_CreateRGBSurface(ekran->flags,351,25,ekran->format->BitsPerPixel,ekran->format->Rmask,ekran->format->Gmask,ekran->format->Bmask,ekran->format->Amask);
  698. SDL_BlitSurface(bg,&genRect(25,351,22,(i-at)*25+115),scenin,NULL);
  699. blitAt(scenin,24,121+(i-at)*25);
  700. //SDL_Flip(ekran);
  701. CSDL_Ext::update(ekran);
  702. SDL_FreeSurface(scenin);
  703. continue;
  704. }
  705. if (sizeFilter && ((ourMaps[(i-at)+from].width) != sizeFilter))
  706. {
  707. to++;
  708. at++;
  709. from++;
  710. if (((i-at)+from)>ourMaps.size()-1) break;
  711. else continue;
  712. }
  713. if ((i-at+from) == selected)
  714. nasz=tytulowy;
  715. else nasz=zwykly;
  716. //SDL_Rect pier = genRect(25,351,24,126+(i*25));
  717. SDL_BlitSurface(bg,&genRect(25,351,22,(i-at)*25+115),scenin,NULL);
  718. int temp=-1;
  719. std::ostringstream ostr(std::ostringstream::out); ostr << ourMaps[(i-at)+from].playerAmnt << "/" << ourMaps[(i-at)+from].humenPlayers;
  720. CSDL_Ext::printAt(ostr.str(),6,4,GEOR13,nasz,scenin, 2);
  721. std::string temp2;
  722. switch (ourMaps[(i-at)+from].width)
  723. {
  724. case 36:
  725. temp2="S";
  726. break;
  727. case 72:
  728. temp2="M";
  729. break;
  730. case 108:
  731. temp2="L";
  732. break;
  733. case 144:
  734. temp2="XL";
  735. break;
  736. default:
  737. temp2="C";
  738. break;
  739. }
  740. CSDL_Ext::printAtMiddle(temp2,50,13,GEOR13,nasz,scenin, 2);
  741. switch (ourMaps[(i-at)+from].version)
  742. {
  743. case Eformat::RoE:
  744. temp=0;
  745. break;
  746. case Eformat::AB:
  747. temp=1;
  748. break;
  749. case Eformat::SoD:
  750. temp=2;
  751. break;
  752. case Eformat::WoG:
  753. temp=3;
  754. break;
  755. }
  756. blitAt(Dtypes->ourImages[temp].bitmap,67,2,scenin);
  757. if (!(ourMaps[(i-at)+from].name.length()))
  758. ourMaps[(i-at)+from].name = "Unnamed";
  759. CSDL_Ext::printAtMiddle(ourMaps[(i-at)+from].name,192,13,GEOR13,nasz,scenin, 2);
  760. if (ourMaps[(i-at)+from].victoryCondition==EvictoryConditions::winStandard)
  761. temp=11;
  762. else temp=ourMaps[(i-at)+from].victoryCondition;
  763. blitAt(Dvic->ourImages[temp].bitmap,285,2,scenin);
  764. if (ourMaps[(i-at)+from].lossCondition.typeOfLossCon == ElossCon::lossStandard)
  765. temp=3;
  766. else temp=ourMaps[(i-at)+from].lossCondition.typeOfLossCon;
  767. blitAt(Dloss->ourImages[temp].bitmap,318,2,scenin);
  768. blitAt(scenin,24,121+(i-at)*25);
  769. SDL_UpdateRect(ekran,24,121+(i-at)*25,scenin->w,scenin->h);
  770. }
  771. SDL_FreeSurface(scenin);
  772. }
  773. int MapSel::whichWL(int nr)
  774. {
  775. int help=-1;
  776. for (int i=0;i<ourMaps.size();i++)
  777. {
  778. if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
  779. continue;
  780. else help++;
  781. if (help==nr)
  782. {
  783. help=i;
  784. break;
  785. }
  786. }
  787. return help;
  788. }
  789. void MapSel::hide()
  790. {
  791. if (!showed)return;
  792. PreGameTab::hide();
  793. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&small));
  794. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&medium));
  795. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&large));
  796. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&xlarge));
  797. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&all));
  798. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&nrplayer));
  799. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&mapsize));
  800. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&type));
  801. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&name));
  802. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&viccon));
  803. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&loscon));
  804. slid->deactivate();
  805. };
  806. void MapSel::show()
  807. {
  808. if (showed)return;
  809. PreGameTab::show();
  810. //blit bg
  811. blitAt(bg,3,6);
  812. CSDL_Ext::printAt("Map Sizes",55,60,GEOR13);
  813. CSDL_Ext::printAt("Select a Scenario to Play",110,25,TNRB16);
  814. //size buttons
  815. small.show();
  816. medium.show();
  817. large.show();
  818. xlarge.show();
  819. all.show();
  820. CPG->btns.push_back(&small);
  821. CPG->btns.push_back(&medium);
  822. CPG->btns.push_back(&large);
  823. CPG->btns.push_back(&xlarge);
  824. CPG->btns.push_back(&all);
  825. //sort by buttons
  826. nrplayer.show();
  827. mapsize.show();
  828. type.show();
  829. name.show();
  830. viccon.show();
  831. loscon.show();
  832. CPG->btns.push_back(&nrplayer);
  833. CPG->btns.push_back(&mapsize);
  834. CPG->btns.push_back(&type);
  835. CPG->btns.push_back(&name);
  836. CPG->btns.push_back(&viccon);
  837. CPG->btns.push_back(&loscon);
  838. //print scenario list
  839. printMaps(0,18);
  840. slid->activate();
  841. //SDL_Flip(ekran);
  842. CSDL_Ext::update(ekran);
  843. }
  844. void MapSel::init()
  845. {
  846. bg = CGI->bitmaph->loadBitmap("SCSELBCK.bmp");
  847. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  848. small.imgs = CGI->spriteh->giveDef("SCSMBUT.DEF");
  849. small.fun = NULL;
  850. small.pos = genRect(small.imgs->ourImages[0].bitmap->h,small.imgs->ourImages[0].bitmap->w,161,52);
  851. small.ourGroup=NULL;
  852. medium.imgs = CGI->spriteh->giveDef("SCMDBUT.DEF");
  853. medium.fun = NULL;
  854. medium.pos = genRect(medium.imgs->ourImages[0].bitmap->h,medium.imgs->ourImages[0].bitmap->w,208,52);
  855. medium.ourGroup=NULL;
  856. large.imgs = CGI->spriteh->giveDef("SCLGBUT.DEF");
  857. large.fun = NULL;
  858. large.pos = genRect(large.imgs->ourImages[0].bitmap->h,large.imgs->ourImages[0].bitmap->w,255,52);
  859. large.ourGroup=NULL;
  860. xlarge.imgs = CGI->spriteh->giveDef("SCXLBUT.DEF");
  861. xlarge.fun = NULL;
  862. xlarge.pos = genRect(xlarge.imgs->ourImages[0].bitmap->h,xlarge.imgs->ourImages[0].bitmap->w,302,52);
  863. xlarge.ourGroup=NULL;
  864. all.imgs = CGI->spriteh->giveDef("SCALBUT.DEF");
  865. all.fun = NULL;
  866. all.pos = genRect(all.imgs->ourImages[0].bitmap->h,all.imgs->ourImages[0].bitmap->w,349,52);
  867. all.ourGroup=NULL;
  868. all.selectable=xlarge.selectable=large.selectable=medium.selectable=small.selectable=false;
  869. small.what=medium.what=large.what=xlarge.what=all.what=&sizeFilter;
  870. small.key=36;medium.key=72;large.key=108;xlarge.key=144;all.key=0;
  871. //Button<> nrplayer, mapsize, type, name, viccon, loscon;
  872. nrplayer.imgs = CGI->spriteh->giveDef("SCBUTT1.DEF");
  873. nrplayer.fun = NULL;
  874. nrplayer.pos = genRect(nrplayer.imgs->ourImages[0].bitmap->h,nrplayer.imgs->ourImages[0].bitmap->w,26,92);
  875. nrplayer.key=ESortBy::playerAm;
  876. mapsize.imgs = CGI->spriteh->giveDef("SCBUTT2.DEF");
  877. mapsize.fun = NULL;
  878. mapsize.pos = genRect(mapsize.imgs->ourImages[0].bitmap->h,mapsize.imgs->ourImages[0].bitmap->w,58,92);
  879. mapsize.key=ESortBy::size;
  880. type.imgs = CGI->spriteh->giveDef("SCBUTCP.DEF");
  881. type.fun = NULL;
  882. type.pos = genRect(type.imgs->ourImages[0].bitmap->h,type.imgs->ourImages[0].bitmap->w,91,92);
  883. type.key=ESortBy::format;
  884. name.imgs = CGI->spriteh->giveDef("SCBUTT3.DEF");
  885. name.fun = NULL;
  886. name.pos = genRect(name.imgs->ourImages[0].bitmap->h,name.imgs->ourImages[0].bitmap->w,124,92);
  887. name.key=ESortBy::name;
  888. viccon.imgs = CGI->spriteh->giveDef("SCBUTT4.DEF");
  889. viccon.fun = NULL;
  890. viccon.pos = genRect(viccon.imgs->ourImages[0].bitmap->h,viccon.imgs->ourImages[0].bitmap->w,309,92);
  891. viccon.key=ESortBy::viccon;
  892. loscon.imgs = CGI->spriteh->giveDef("SCBUTT5.DEF");
  893. loscon.fun = NULL;
  894. loscon.pos = genRect(loscon.imgs->ourImages[0].bitmap->h,loscon.imgs->ourImages[0].bitmap->w,342,92);
  895. loscon.key=ESortBy::loscon;
  896. nrplayer.poin=mapsize.poin=type.poin=name.poin=viccon.poin=loscon.poin=(int*)(&sortBy);
  897. nrplayer.fun=mapsize.fun=type.fun=name.fun=viccon.fun=loscon.fun=&CPreGame::sortMaps;
  898. Dtypes = CGI->spriteh->giveDef("SCSELC.DEF");
  899. Dvic = CGI->spriteh->giveDef("SCNRVICT.DEF");
  900. Dloss = CGI->spriteh->giveDef("SCNRLOSS.DEF");
  901. //Dsizes = CPG->slh->giveDef("SCNRMPSZ.DEF");
  902. Dsizes = CGI->spriteh->giveDef("SCNRMPSZ.DEF");
  903. sFlags = CGI->spriteh->giveDef("ITGFLAGS.DEF");
  904. //get map files names
  905. std::vector<std::string> pliczkiTemp;
  906. fs::path tie( (fs::initial_path<fs::path>())/"\maps" );
  907. fs::directory_iterator end_iter;
  908. for ( fs::directory_iterator dir (tie); dir!=end_iter; ++dir )
  909. {
  910. if (fs::is_regular(dir->status()));
  911. {
  912. if (boost::ends_with(dir->path().leaf(),std::string(".h3m")))
  913. pliczkiTemp.push_back("Maps/"+(dir->path().leaf()));
  914. }
  915. }
  916. for (int i=0; i<pliczkiTemp.size();i++)
  917. {
  918. gzFile tempf = gzopen(pliczkiTemp[i].c_str(),"rb");
  919. std::string sss;
  920. int iii=0;
  921. while(++iii)
  922. {
  923. if (iii>4000) break;
  924. int z = gzgetc (tempf);
  925. if (z>=0)
  926. {
  927. sss+=unsigned char(z);
  928. }
  929. else break;
  930. }
  931. gzclose(tempf);
  932. //if (sss[0]<28) continue; //zly format
  933. if (!sss[4]) continue; //nie ma graczy? mapa niegrywalna //już to kiedyś komentowałem- - to bzdura //tu calkiem pasuje...
  934. unsigned char* file2 = new unsigned char[sss.length()];
  935. for (int j=0;j<sss.length();j++)
  936. file2[j]=sss[j];
  937. ourMaps.push_back(CMapInfo(pliczkiTemp[i],file2));
  938. delete file2;
  939. }
  940. std::sort(ourMaps.begin(),ourMaps.end(),mapSorter(ESortBy::name));
  941. slid = new Slider<>(375,92,480,ourMaps.size(),18,true);
  942. slid->fun = &CPreGame::printMapsFrom;
  943. }
  944. void MapSel::moveByOne(bool up)
  945. {
  946. int help=selected;
  947. if (up) selected--;
  948. else selected ++;
  949. for (int i=selected;i<ourMaps.size() && i>=0;)
  950. {
  951. help=i;
  952. if (!(sizeFilter && ((ourMaps[i].width) != sizeFilter)))
  953. break;
  954. if (up)
  955. {
  956. i--;
  957. }
  958. else
  959. {
  960. i++;
  961. if (i<0) break;
  962. }
  963. }
  964. select(help);
  965. slid->updateSlid();
  966. }
  967. void MapSel::select(int which, bool updateMapsList)
  968. {
  969. selected = which;
  970. if(updateMapsList)printMaps(slid->whereAreWe,18,0,true);
  971. CPG->ret.playerInfos.clear();
  972. bool wasntpl = true;
  973. for (int i=0;i<PLAYER_LIMIT;i++)
  974. {
  975. if (!(ourMaps[selected].players[i].canComputerPlay || ourMaps[selected].players[i].canComputerPlay))
  976. continue; // this caused some serious problems becouse of lack of simple bijection between two sets of player's numbers (one is returned by CPreGame, second is used in h3m)
  977. StartInfo::PlayerSettings pset;
  978. pset.color=(Ecolor)i;
  979. pset.bonus=Ebonus::brandom;
  980. pset.castle=-2;
  981. if (ourMaps[which].players[i].canHumanPlay && wasntpl)
  982. {
  983. pset.name=CGI->generaltexth->allTexts[434];
  984. CPG->playerColor = i;
  985. wasntpl = false;
  986. }
  987. else
  988. {
  989. pset.name=CGI->generaltexth->allTexts[468];
  990. }
  991. if ( (ourMaps[which].players[i].heroesNames.size()>1) ||
  992. (((ourMaps[which].players[i].heroesNames.size()>1)==1) && ourMaps[which].players[i].generateHeroAtMainTown==false) )
  993. pset.hero=-2;
  994. else if (ourMaps[which].players[i].heroesNames.size()==1)
  995. {
  996. pset.hero=ourMaps[which].players[i].heroesNames[0].heroID;
  997. }
  998. else
  999. pset.hero=-1;
  1000. for (int j=0;j<F_NUMBER;j++)
  1001. {
  1002. if (((int)pow((double)2,j))&ourMaps[selected].players[i].allowedFactions)
  1003. {
  1004. if (pset.castle>=0)
  1005. pset.castle=-1;
  1006. if (pset.castle==-2)
  1007. pset.castle=j;
  1008. }
  1009. }
  1010. if (ourMaps[selected].players[i].generateHeroAtMainTown || ourMaps[selected].players[i].generateHero)
  1011. pset.hero=-1;
  1012. else if (ourMaps[selected].players[i].mainHeroName.length())
  1013. {
  1014. pset.heroName=ourMaps[selected].players[i].mainHeroName;
  1015. pset.heroPortrait=ourMaps[selected].players[i].mainHeroPortrait;
  1016. }
  1017. else
  1018. pset.hero=-2;
  1019. pset.handicap=0;
  1020. pset.heroPortrait=-1;
  1021. CPG->ret.playerInfos.push_back(pset);
  1022. }
  1023. printSelectedInfo();
  1024. }
  1025. MapSel::MapSel():selected(0),sizeFilter(0)
  1026. {
  1027. }
  1028. void MapSel::printSelectedInfo()
  1029. {
  1030. SDL_BlitSurface(CPG->ourScenSel->scenInf,&genRect(399,337,17,23),ekran,&genRect(399,337,413,29));
  1031. SDL_BlitSurface(CPG->ourScenSel->scenInf,&genRect(50,91,18,447),ekran,&genRect(50,91,414,453));
  1032. SDL_BlitSurface(CPG->ourScenSel->bScens.imgs->ourImages[0].bitmap,NULL,ekran,&CPG->ourScenSel->bScens.pos);
  1033. SDL_BlitSurface(CPG->ourScenSel->bOptions.imgs->ourImages[0].bitmap,NULL,ekran,&CPG->ourScenSel->bOptions.pos);
  1034. SDL_BlitSurface(CPG->ourScenSel->bRandom.imgs->ourImages[0].bitmap,NULL,ekran,&CPG->ourScenSel->bRandom.pos);
  1035. //blit texts
  1036. CSDL_Ext::printAt(CPG->preth->singleScenarioName,420,25,GEOR13);
  1037. CSDL_Ext::printAt("Scenario Description:",420,135,GEOR13);
  1038. CSDL_Ext::printAt("Victory Condition:",420,285,GEOR13);
  1039. CSDL_Ext::printAt("Loss Condition:",420,340,GEOR13);
  1040. CSDL_Ext::printAt("Allies:",420,406,GEOR13,zwykly);
  1041. CSDL_Ext::printAt("Enemies:",585,406,GEOR13,zwykly);
  1042. int temp = ourMaps[selected].victoryCondition+1;
  1043. if (temp>20) temp=0;
  1044. std::string sss = CPG->preth->victoryConditions[temp];
  1045. if (temp && ourMaps[selected].vicConDetails->allowNormalVictory) sss+= "/" + CPG->preth->victoryConditions[0];
  1046. CSDL_Ext::printAt(sss,452,310,GEOR13,zwykly);
  1047. temp = ourMaps[selected].lossCondition.typeOfLossCon+1;
  1048. if (temp>20) temp=0;
  1049. sss = CPG->preth->lossCondtions[temp];
  1050. CSDL_Ext::printAt(sss,452,370,GEOR13,zwykly);
  1051. //blit descrption
  1052. std::vector<std::string> desc = *CMessage::breakText(ourMaps[selected].description,50);
  1053. for (int i=0;i<desc.size();i++)
  1054. CSDL_Ext::printAt(desc[i],417,152+i*13,GEOR13,zwykly);
  1055. if ((selected < 0) || (selected >= ourMaps.size()))
  1056. return;
  1057. if (ourMaps[selected].name.length())
  1058. CSDL_Ext::printAt(ourMaps[selected].name,420,41,GEORXX);
  1059. else CSDL_Ext::printAt("Unnamed",420,41,GEORXX);
  1060. std::string diff;
  1061. switch (ourMaps[selected].difficulty)
  1062. {
  1063. case 0:
  1064. diff=gdiff(CPG->preth->singleEasy);
  1065. break;
  1066. case 1:
  1067. diff=gdiff(CPG->preth->singleNormal);
  1068. break;
  1069. case 2:
  1070. diff=gdiff(CPG->preth->singleHard);
  1071. break;
  1072. case 3:
  1073. diff=gdiff(CPG->preth->singleExpert);
  1074. break;
  1075. case 4:
  1076. diff=gdiff(CPG->preth->singleImpossible);
  1077. break;
  1078. }
  1079. temp=-1;
  1080. switch (ourMaps[selected].width)
  1081. {
  1082. case 36:
  1083. temp=0;
  1084. break;
  1085. case 72:
  1086. temp=1;
  1087. break;
  1088. case 108:
  1089. temp=2;
  1090. break;
  1091. case 144:
  1092. temp=3;
  1093. break;
  1094. default:
  1095. temp=4;
  1096. break;
  1097. }
  1098. blitAt(Dsizes->ourImages[temp].bitmap,714,28);
  1099. temp=ourMaps[selected].victoryCondition;
  1100. if (temp>12) temp=11;
  1101. blitAt(Dvic->ourImages[temp].bitmap,420,308); //v
  1102. temp=ourMaps[selected].lossCondition.typeOfLossCon;
  1103. if (temp>12) temp=3;
  1104. blitAt(Dloss->ourImages[temp].bitmap,420,366); //l
  1105. CSDL_Ext::printAtMiddle(diff,458,477,GEOR13,zwykly);
  1106. //SDL_Flip(ekran);
  1107. printFlags();
  1108. CSDL_Ext::update(ekran);
  1109. }
  1110. void MapSel::printFlags()
  1111. {
  1112. int hy=405, fx=460, ex=640, myT;
  1113. if (ourMaps[selected].howManyTeams)
  1114. myT = ourMaps[selected].players[CPG->playerColor].team;
  1115. else myT = -1;
  1116. for (int i=0;i<CPG->ret.playerInfos.size();i++)
  1117. {
  1118. if (myT>=0)
  1119. {
  1120. if(ourMaps[selected].players[CPG->ret.playerInfos[i].color].team==myT)
  1121. {
  1122. blitAt(sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap,fx,hy);
  1123. fx+=sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap->w;
  1124. }
  1125. else
  1126. {
  1127. blitAt(sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap,ex,hy);
  1128. ex+=sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap->w;
  1129. }
  1130. }
  1131. else
  1132. {
  1133. if(CPG->ret.playerInfos[i].color==CPG->playerColor)
  1134. {
  1135. blitAt(sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap,fx,hy);
  1136. fx+=sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap->w;
  1137. }
  1138. else
  1139. {
  1140. blitAt(sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap,ex,hy);
  1141. ex+=sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap->w;
  1142. }
  1143. }
  1144. }
  1145. }
  1146. std::string MapSel::gdiff(std::string ss)
  1147. {
  1148. std::string ret;
  1149. for (int i=2;i<ss.length();i++)
  1150. {
  1151. if (ss[i]==' ')
  1152. break;
  1153. ret+=ss[i];
  1154. }
  1155. return ret;
  1156. }
  1157. void CPreGame::printRating()
  1158. {
  1159. SDL_BlitSurface(CPG->ourScenSel->scenInf,&genRect(38,71,276,453),ekran,&genRect(38,71,673,459));
  1160. std::string tob;
  1161. switch (ourScenSel->selectedDiff)
  1162. {
  1163. case 1:
  1164. tob="80%";
  1165. break;
  1166. case 2:
  1167. tob="100%";
  1168. break;
  1169. case 3:
  1170. tob="130%";
  1171. break;
  1172. case 4:
  1173. tob="160%";
  1174. break;
  1175. case 5:
  1176. tob="200%";
  1177. break;
  1178. }
  1179. CSDL_Ext::printAtMiddle(tob,703,477,GEOR13,zwykly);
  1180. }
  1181. void CPreGame::printMapsFrom(int from)
  1182. {
  1183. ourScenSel->mapsel.printMaps(from);
  1184. }
  1185. void CPreGame::showScenList()
  1186. {
  1187. if (currentTab!=&ourScenSel->mapsel)
  1188. {
  1189. ourScenSel->listShowed=true;
  1190. ourScenSel->mapsel.show();
  1191. }
  1192. else currentTab->hide();
  1193. }
  1194. CPreGame::CPreGame()
  1195. {
  1196. highlighted=NULL;
  1197. currentTab=NULL;
  1198. run=true;
  1199. timeHandler tmh;tmh.getDif();
  1200. tytulowy.r=229;tytulowy.g=215;tytulowy.b=123;tytulowy.unused=0;
  1201. zwykly.r=255;zwykly.g=255;zwykly.b=255;zwykly.unused=0; //gbr
  1202. tlo.r=66;tlo.g=44;tlo.b=24;tlo.unused=0;
  1203. preth = new CPreGameTextHandler;
  1204. preth->loadTexts();
  1205. CGI->preth=preth;
  1206. THC std::cout<<"\tCPreGame: loading txts: "<<tmh.getDif()<<std::endl;
  1207. currentMessage=NULL;
  1208. behindCurMes=NULL;
  1209. initMainMenu();
  1210. THC std::cout<<"\tCPreGame: main menu initialization: "<<tmh.getDif()<<std::endl;
  1211. initNewMenu();
  1212. THC std::cout<<"\tCPreGame: newgame menu initialization: "<<tmh.getDif()<<std::endl;
  1213. initScenSel();
  1214. THC std::cout<<"\tCPreGame: scenario choice initialization: "<<tmh.getDif()<<std::endl;
  1215. initOptions();
  1216. THC std::cout<<"\tCPreGame: scenario options initialization: "<<tmh.getDif()<<std::endl;
  1217. showMainMenu();
  1218. THC std::cout<<"\tCPreGame: displaying main menu: "<<tmh.getDif()<<std::endl;
  1219. CPG=this;
  1220. playerName="Player";
  1221. }
  1222. void CPreGame::initOptions()
  1223. {
  1224. ourOptions = new Options();
  1225. ourOptions->init();
  1226. }
  1227. void CPreGame::initScenSel()
  1228. {
  1229. ourScenSel = new ScenSel();
  1230. ourScenSel->listShowed=false;
  1231. if (rand()%2) ourScenSel->background=CGI->bitmaph->loadBitmap("ZPIC1000.bmp");
  1232. else ourScenSel->background=CGI->bitmaph->loadBitmap("ZPIC1001.bmp");
  1233. ourScenSel->pressed=NULL;
  1234. ourScenSel->scenInf=CGI->bitmaph->loadBitmap("GSELPOP1.bmp");//SDL_LoadBMP("h3bitmap.lod\\GSELPOP1.bmp");
  1235. ourScenSel->randMap=CGI->bitmaph->loadBitmap("RANMAPBK.bmp");
  1236. ourScenSel->options=CGI->bitmaph->loadBitmap("ADVOPTBK.bmp");
  1237. SDL_SetColorKey(ourScenSel->scenInf,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->scenInf->format,0,255,255));
  1238. //SDL_SetColorKey(ourScenSel->scenList,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->scenList->format,0,255,255));
  1239. SDL_SetColorKey(ourScenSel->randMap,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->randMap->format,0,255,255));
  1240. SDL_SetColorKey(ourScenSel->options,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->options->format,0,255,255));
  1241. ourScenSel->difficulty = new CPoinGroup<>();
  1242. ourScenSel->difficulty->type=1;
  1243. ourScenSel->selectedDiff=-77;
  1244. ourScenSel->difficulty->gdzie = &ourScenSel->selectedDiff;
  1245. ourScenSel->bEasy = IntSelBut<>(genRect(0,0,506,456),NULL,CGI->spriteh->giveDef("GSPBUT3.DEF"),true,ourScenSel->difficulty,0);
  1246. ourScenSel->bNormal = IntSelBut<>(genRect(0,0,538,456),NULL,CGI->spriteh->giveDef("GSPBUT4.DEF"),true,ourScenSel->difficulty,1);
  1247. ourScenSel->bHard = IntSelBut<>(genRect(0,0,570,456),NULL,CGI->spriteh->giveDef("GSPBUT5.DEF"),true,ourScenSel->difficulty,2);
  1248. ourScenSel->bExpert = IntSelBut<>(genRect(0,0,602,456),NULL,CGI->spriteh->giveDef("GSPBUT6.DEF"),true,ourScenSel->difficulty,3);
  1249. ourScenSel->bImpossible = IntSelBut<>(genRect(0,0,634,456),NULL,CGI->spriteh->giveDef("GSPBUT7.DEF"),true,ourScenSel->difficulty,4);
  1250. ourScenSel->bBack = Button<>(genRect(0,0,584,535),&CPreGame::showNewMenu,CGI->spriteh->giveDef("SCNRBACK.DEF"));
  1251. ourScenSel->bBegin = Button<>(genRect(0,0,414,535),&CPreGame::begin,CGI->spriteh->giveDef("SCNRBEG.DEF"));
  1252. ourScenSel->bScens = Button<>(genRect(0,0,414,81),&CPreGame::showScenList,CGI->spriteh->giveDef("GSPBUTT.DEF"));
  1253. for (int i=0; i<ourScenSel->bScens.imgs->ourImages.size(); i++)
  1254. CSDL_Ext::printAt(CGI->generaltexth->allTexts[500],25+i,2+i,GEOR13,zwykly,ourScenSel->bScens.imgs->ourImages[i].bitmap); //"Show Available Scenarios"
  1255. ourScenSel->bRandom = Button<>(genRect(0,0,414,105),&CPreGame::showScenList,CGI->spriteh->giveDef("GSPBUTT.DEF"));
  1256. for (int i=0; i<ourScenSel->bRandom.imgs->ourImages.size(); i++)
  1257. CSDL_Ext::printAt(CGI->generaltexth->allTexts[740],25+i,2+i,GEOR13,zwykly,ourScenSel->bRandom.imgs->ourImages[i].bitmap);
  1258. ourScenSel->bOptions = Button<>(genRect(0,0,414,509),&CPreGame::showOptions,CGI->spriteh->giveDef("GSPBUTT.DEF"));
  1259. for (int i=0; i<ourScenSel->bOptions.imgs->ourImages.size(); i++)
  1260. CSDL_Ext::printAt(CGI->generaltexth->allTexts[501],25+i,2+i,GEOR13,zwykly,ourScenSel->bOptions.imgs->ourImages[i].bitmap); //"Show Advanced Options"
  1261. CPG=this;
  1262. ourScenSel->mapsel.init();
  1263. }
  1264. void CPreGame::showScenSel()
  1265. {
  1266. state=EState::ScenarioList;
  1267. SDL_BlitSurface(ourScenSel->background,NULL,ekran,NULL);
  1268. SDL_BlitSurface(ourScenSel->scenInf,NULL,ekran,&genRect(ourScenSel->scenInf->h,ourScenSel->scenInf->w,396,6));
  1269. CSDL_Ext::printAt(CGI->generaltexth->allTexts[494],427,438,GEOR13);//"Map Diff:"
  1270. CSDL_Ext::printAt(CGI->generaltexth->allTexts[492],527,438,GEOR13); //player difficulty
  1271. CSDL_Ext::printAt(CGI->generaltexth->allTexts[218],685,438,GEOR13);//"Rating:"
  1272. //blit buttons
  1273. SDL_BlitSurface(ourScenSel->bEasy.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bEasy.pos);
  1274. SDL_BlitSurface(ourScenSel->bNormal.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bNormal.pos);
  1275. SDL_BlitSurface(ourScenSel->bHard.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bHard.pos);
  1276. SDL_BlitSurface(ourScenSel->bExpert.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bExpert.pos);
  1277. SDL_BlitSurface(ourScenSel->bImpossible.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bImpossible.pos);
  1278. SDL_BlitSurface(ourScenSel->bBegin.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bBegin.pos);
  1279. SDL_BlitSurface(ourScenSel->bBack.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bBack.pos);
  1280. //blitAt(ourScenSel->bScens.imgs->ourImages[0].bitmap,ourScenSel->bScens.pos.x,ourScenSel->bScens.pos.y);
  1281. //blitAt(ourScenSel->bRandom.imgs->ourImages[0].bitmap,414,105);
  1282. //blitAt(ourScenSel->bOptions.imgs->ourImages[0].bitmap,414,509);
  1283. //blitAt(ourScenSel->bBegin.imgs->ourImages[0].bitmap,414,535);
  1284. //blitAt(ourScenSel->bBack.imgs->ourImages[0].bitmap,584,535);
  1285. //add buttons info
  1286. btns.push_back(&ourScenSel->bEasy);
  1287. btns.push_back(&ourScenSel->bNormal);
  1288. btns.push_back(&ourScenSel->bHard);
  1289. btns.push_back(&ourScenSel->bExpert);
  1290. btns.push_back(&ourScenSel->bImpossible);
  1291. btns.push_back(&ourScenSel->bScens);
  1292. btns.push_back(&ourScenSel->bRandom);
  1293. btns.push_back(&ourScenSel->bOptions);
  1294. btns.push_back(&ourScenSel->bBegin);
  1295. btns.push_back(&ourScenSel->bBack);
  1296. ourScenSel->selectedDiff=1;
  1297. ourScenSel->bNormal.select(true);
  1298. for (int i=0;i<btns.size();i++)
  1299. {
  1300. btns[i]->pos.w=btns[i]->imgs->ourImages[0].bitmap->w;
  1301. btns[i]->pos.h=btns[i]->imgs->ourImages[0].bitmap->h;
  1302. btns[i]->ID=10;
  1303. }
  1304. handleOther = &CPreGame::scenHandleEv;
  1305. ourScenSel->mapsel.select(0,false);
  1306. //ourScenSel->mapsel.printSelectedInfo(); // this is already called in select()
  1307. //SDL_Flip(ekran);
  1308. CSDL_Ext::update(ekran);
  1309. }
  1310. void CPreGame::showOptions()
  1311. {
  1312. ourOptions->show();
  1313. }
  1314. void CPreGame::initNewMenu()
  1315. {
  1316. ourNewMenu = new menuItems();
  1317. ourNewMenu->bgAd = CGI->bitmaph->loadBitmap("ZNEWGAM.bmp");
  1318. ourNewMenu->background = CGI->bitmaph->loadBitmap("ZPIC1005.bmp");
  1319. blitAt(ourNewMenu->bgAd,114,312,ourNewMenu->background);
  1320. slh = new CSemiLodHandler();
  1321. slh->openLod("H3sprite.lod");
  1322. //loading menu buttons
  1323. ourNewMenu->newGame = CGI->spriteh->giveDef("ZTSINGL.DEF");
  1324. ourNewMenu->loadGame = CGI->spriteh->giveDef("ZTMULTI.DEF");
  1325. ourNewMenu->highScores = CGI->spriteh->giveDef("ZTCAMPN.DEF");
  1326. ourNewMenu->credits = CGI->spriteh->giveDef("ZTTUTOR.DEF");
  1327. ourNewMenu->quit = CGI->spriteh->giveDef("ZTBACK.DEF");
  1328. ok = CGI->spriteh->giveDef("IOKAY.DEF");
  1329. cancel = CGI->spriteh->giveDef("ICANCEL.DEF");
  1330. // single scenario
  1331. ourNewMenu->lNewGame.h=ourNewMenu->newGame->ourImages[0].bitmap->h;
  1332. ourNewMenu->lNewGame.w=ourNewMenu->newGame->ourImages[0].bitmap->w;
  1333. ourNewMenu->lNewGame.x=545;
  1334. ourNewMenu->lNewGame.y=4;
  1335. ourNewMenu->fNewGame=&CPreGame::showScenSel;
  1336. //multiplayer
  1337. ourNewMenu->lLoadGame.h=ourNewMenu->loadGame->ourImages[0].bitmap->h;
  1338. ourNewMenu->lLoadGame.w=ourNewMenu->loadGame->ourImages[0].bitmap->w;
  1339. ourNewMenu->lLoadGame.x=568;
  1340. ourNewMenu->lLoadGame.y=120;
  1341. //campaign
  1342. ourNewMenu->lHighScores.h=ourNewMenu->highScores->ourImages[0].bitmap->h;
  1343. ourNewMenu->lHighScores.w=ourNewMenu->highScores->ourImages[0].bitmap->w;
  1344. ourNewMenu->lHighScores.x=541;
  1345. ourNewMenu->lHighScores.y=233;
  1346. //tutorial
  1347. ourNewMenu->lCredits.h=ourNewMenu->credits->ourImages[0].bitmap->h;
  1348. ourNewMenu->lCredits.w=ourNewMenu->credits->ourImages[0].bitmap->w;
  1349. ourNewMenu->lCredits.x=545;
  1350. ourNewMenu->lCredits.y=358;
  1351. //back
  1352. ourNewMenu->lQuit.h=ourNewMenu->quit->ourImages[0].bitmap->h;
  1353. ourNewMenu->lQuit.w=ourNewMenu->quit->ourImages[0].bitmap->w;
  1354. ourNewMenu->lQuit.x=582;
  1355. ourNewMenu->lQuit.y=464;
  1356. ourNewMenu->fQuit=&CPreGame::showMainMenu;
  1357. ourNewMenu->highlighted=0;
  1358. }
  1359. void CPreGame::showNewMenu()
  1360. {
  1361. btns.clear();
  1362. interested.clear();
  1363. handleOther=NULL;
  1364. state = EState::newGame;
  1365. SDL_BlitSurface(ourNewMenu->background,NULL,ekran,NULL);
  1366. SDL_BlitSurface(ourNewMenu->newGame->ourImages[0].bitmap,NULL,ekran,&ourNewMenu->lNewGame);
  1367. SDL_BlitSurface(ourNewMenu->loadGame->ourImages[0].bitmap,NULL,ekran,&ourNewMenu->lLoadGame);
  1368. SDL_BlitSurface(ourNewMenu->highScores->ourImages[0].bitmap,NULL,ekran,&ourNewMenu->lHighScores);
  1369. SDL_BlitSurface(ourNewMenu->credits->ourImages[0].bitmap,NULL,ekran,&ourNewMenu->lCredits);
  1370. SDL_BlitSurface(ourNewMenu->quit->ourImages[0].bitmap,NULL,ekran,&ourNewMenu->lQuit);
  1371. //SDL_Flip(ekran);
  1372. CSDL_Ext::update(ekran);
  1373. }
  1374. void CPreGame::initMainMenu()
  1375. {
  1376. ourMainMenu = new menuItems();
  1377. ourMainMenu->background = CGI->bitmaph->loadBitmap("ZPIC1005.bmp"); //SDL_LoadBMP("h3bitmap.lod\\ZPIC1005.bmp");
  1378. CSemiLodHandler * slh = new CSemiLodHandler();
  1379. slh->openLod("H3sprite.lod");
  1380. //loading menu buttons
  1381. ourMainMenu->newGame = CGI->spriteh->giveDef("ZMENUNG.DEF");
  1382. ourMainMenu->loadGame = CGI->spriteh->giveDef("ZMENULG.DEF");
  1383. ourMainMenu->highScores = CGI->spriteh->giveDef("ZMENUHS.DEF");
  1384. ourMainMenu->credits = CGI->spriteh->giveDef("ZMENUCR.DEF");
  1385. ourMainMenu->quit = CGI->spriteh->giveDef("ZMENUQT.DEF");
  1386. ok = CGI->spriteh->giveDef("IOKAY.DEF");
  1387. cancel = CGI->spriteh->giveDef("ICANCEL.DEF");
  1388. // new game button location
  1389. ourMainMenu->lNewGame.h=ourMainMenu->newGame->ourImages[0].bitmap->h;
  1390. ourMainMenu->lNewGame.w=ourMainMenu->newGame->ourImages[0].bitmap->w;
  1391. ourMainMenu->lNewGame.x=540;
  1392. ourMainMenu->lNewGame.y=10;
  1393. ourMainMenu->fNewGame=&CPreGame::showNewMenu;
  1394. //load game location
  1395. ourMainMenu->lLoadGame.h=ourMainMenu->loadGame->ourImages[0].bitmap->h;
  1396. ourMainMenu->lLoadGame.w=ourMainMenu->loadGame->ourImages[0].bitmap->w;
  1397. ourMainMenu->lLoadGame.x=532;
  1398. ourMainMenu->lLoadGame.y=132;
  1399. //high scores
  1400. ourMainMenu->lHighScores.h=ourMainMenu->highScores->ourImages[0].bitmap->h;
  1401. ourMainMenu->lHighScores.w=ourMainMenu->highScores->ourImages[0].bitmap->w;
  1402. ourMainMenu->lHighScores.x=524;
  1403. ourMainMenu->lHighScores.y=251;
  1404. //credits
  1405. ourMainMenu->lCredits.h=ourMainMenu->credits->ourImages[0].bitmap->h;
  1406. ourMainMenu->lCredits.w=ourMainMenu->credits->ourImages[0].bitmap->w;
  1407. ourMainMenu->lCredits.x=557;
  1408. ourMainMenu->lCredits.y=359;
  1409. //quit
  1410. ourMainMenu->lQuit.h=ourMainMenu->quit->ourImages[0].bitmap->h;
  1411. ourMainMenu->lQuit.w=ourMainMenu->quit->ourImages[0].bitmap->w;
  1412. ourMainMenu->lQuit.x=586;
  1413. ourMainMenu->lQuit.y=468;
  1414. ourMainMenu->fQuit=&CPreGame::quitAskBox;
  1415. ourMainMenu->highlighted=0;
  1416. handledLods.push_back(slh);
  1417. delete slh;
  1418. }
  1419. void CPreGame::showMainMenu()
  1420. {
  1421. state = EState::mainMenu;
  1422. SDL_BlitSurface(ourMainMenu->background,NULL,ekran,NULL);
  1423. SDL_BlitSurface(ourMainMenu->newGame->ourImages[0].bitmap,NULL,ekran,&ourMainMenu->lNewGame);
  1424. SDL_BlitSurface(ourMainMenu->loadGame->ourImages[0].bitmap,NULL,ekran,&ourMainMenu->lLoadGame);
  1425. SDL_BlitSurface(ourMainMenu->highScores->ourImages[0].bitmap,NULL,ekran,&ourMainMenu->lHighScores);
  1426. SDL_BlitSurface(ourMainMenu->credits->ourImages[0].bitmap,NULL,ekran,&ourMainMenu->lCredits);
  1427. SDL_BlitSurface(ourMainMenu->quit->ourImages[0].bitmap,NULL,ekran,&ourMainMenu->lQuit);
  1428. //SDL_Flip(ekran);
  1429. CSDL_Ext::update(ekran);
  1430. }
  1431. void CPreGame::highlightButton(int which, int on)
  1432. {
  1433. menuItems * current = currentItems();
  1434. switch (which)
  1435. {
  1436. case 1:
  1437. {
  1438. SDL_BlitSurface(current->newGame->ourImages[on].bitmap,NULL,ekran,&current->lNewGame);
  1439. break;
  1440. }
  1441. case 2:
  1442. {
  1443. SDL_BlitSurface(current->loadGame->ourImages[on].bitmap,NULL,ekran,&current->lLoadGame);
  1444. break;
  1445. }
  1446. case 3:
  1447. {
  1448. SDL_BlitSurface(current->highScores->ourImages[on].bitmap,NULL,ekran,&current->lHighScores);
  1449. break;
  1450. }
  1451. case 4:
  1452. {
  1453. SDL_BlitSurface(current->credits->ourImages[on].bitmap,NULL,ekran,&current->lCredits);
  1454. break;
  1455. }
  1456. case 5:
  1457. {
  1458. SDL_BlitSurface(current->quit->ourImages[on].bitmap,NULL,ekran,&current->lQuit);
  1459. break;
  1460. }
  1461. }
  1462. //SDL_Flip(ekran);
  1463. CSDL_Ext::update(ekran);
  1464. }
  1465. void CPreGame::showCenBox (std::string data)
  1466. {
  1467. CMessage * cmh = new CMessage();
  1468. SDL_Surface * infoBox = cmh->genMessage(preth->getTitle(data), preth->getDescr(data));
  1469. behindCurMes = SDL_CreateRGBSurface(ekran->flags,infoBox->w,infoBox->h,ekran->format->BitsPerPixel,ekran->format->Rmask,ekran->format->Gmask,ekran->format->Bmask,ekran->format->Amask);
  1470. SDL_Rect pos = genRect(infoBox->h,infoBox->w,
  1471. (ekran->w/2)-(infoBox->w/2),(ekran->h/2)-(infoBox->h/2));
  1472. SDL_BlitSurface(ekran,&pos,behindCurMes,NULL);
  1473. SDL_BlitSurface(infoBox,NULL,ekran,&pos);
  1474. SDL_UpdateRect(ekran,pos.x,pos.y,pos.w,pos.h);
  1475. SDL_FreeSurface(infoBox);
  1476. currentMessage = new SDL_Rect(pos);
  1477. delete cmh;
  1478. }
  1479. void CPreGame::showAskBox (std::string data, void(*f1)(),void(*f2)())
  1480. {
  1481. CMessage * cmh = new CMessage();
  1482. std::vector<CDefHandler*> * przyciski = new std::vector<CDefHandler*>(0);
  1483. std::vector<SDL_Rect> * btnspos= new std::vector<SDL_Rect>(0);
  1484. przyciski->push_back(ok);
  1485. przyciski->push_back(cancel);
  1486. SDL_Surface * infoBox = cmh->genMessage(preth->getTitle(data), preth->getDescr(data), EWindowType::yesOrNO, przyciski, btnspos);
  1487. behindCurMes = SDL_CreateRGBSurface(ekran->flags,infoBox->w,infoBox->h,ekran->format->BitsPerPixel,ekran->format->Rmask,ekran->format->Gmask,ekran->format->Bmask,ekran->format->Amask);
  1488. SDL_Rect pos = genRect(infoBox->h,infoBox->w,
  1489. (ekran->w/2)-(infoBox->w/2),(ekran->h/2)-(infoBox->h/2));
  1490. SDL_BlitSurface(ekran,&pos,behindCurMes,NULL);
  1491. SDL_BlitSurface(infoBox,NULL,ekran,&pos);
  1492. SDL_UpdateRect(ekran,pos.x,pos.y,pos.w,pos.h);
  1493. SDL_FreeSurface(infoBox);
  1494. currentMessage = new SDL_Rect(pos);
  1495. (*btnspos)[0].x+=pos.x;
  1496. (*btnspos)[0].y+=pos.y;
  1497. (*btnspos)[1].x+=pos.x;
  1498. (*btnspos)[1].y+=pos.y;
  1499. btns.push_back(new Button<>((*btnspos)[0],&CPreGame::quit,ok,false, NULL,2));
  1500. btns.push_back(new Button<>((*btnspos)[1],(&CPreGame::hideBox),cancel,false, NULL,2));
  1501. delete cmh;
  1502. delete przyciski;
  1503. delete btnspos;
  1504. }
  1505. void CPreGame::hideBox ()
  1506. {
  1507. SDL_BlitSurface(behindCurMes,NULL,ekran,currentMessage);
  1508. SDL_UpdateRect
  1509. (ekran,currentMessage->x,currentMessage->y,currentMessage->w,currentMessage->h);
  1510. for (int i=0;i<btns.size();i++)
  1511. {
  1512. if (btns[i]->ID==2)
  1513. {
  1514. delete btns[i];
  1515. btns.erase(btns.begin()+i);
  1516. i--;
  1517. }
  1518. }
  1519. SDL_FreeSurface(behindCurMes);
  1520. delete currentMessage;
  1521. currentMessage = NULL;
  1522. behindCurMes=NULL;
  1523. }
  1524. CPreGame::menuItems * CPreGame::currentItems()
  1525. {
  1526. switch (state)
  1527. {
  1528. case EState::mainMenu:
  1529. return ourMainMenu;
  1530. case EState::newGame:
  1531. return ourNewMenu;
  1532. default:
  1533. return NULL;
  1534. }
  1535. }
  1536. void CPreGame::scenHandleEv(SDL_Event& sEvent)
  1537. {
  1538. if(sEvent.type == SDL_MOUSEMOTION)
  1539. {
  1540. CGI->curh->cursorMove(sEvent.motion.x, sEvent.motion.y);
  1541. }
  1542. if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT))
  1543. {
  1544. for (int i=0;i<btns.size(); i++)
  1545. {
  1546. if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
  1547. {
  1548. btns[i]->press(true);
  1549. ourScenSel->pressed=(Button<>*)btns[i];
  1550. }
  1551. }
  1552. if (ourScenSel->listShowed && (sEvent.button.y>121) &&(sEvent.button.y<570)
  1553. && (sEvent.button.x>55) && (sEvent.button.x<372))
  1554. {
  1555. int py = ((sEvent.button.y-121)/25)+ourScenSel->mapsel.slid->whereAreWe;
  1556. ourScenSel->mapsel.select(ourScenSel->mapsel.whichWL(py));
  1557. }
  1558. }
  1559. else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
  1560. {
  1561. Button<> * prnr=ourScenSel->pressed;
  1562. if (ourScenSel->pressed && ourScenSel->pressed->state==1)
  1563. {
  1564. ourScenSel->pressed->press(false);
  1565. ourScenSel->pressed=NULL;
  1566. }
  1567. for (int i=0;i<btns.size(); i++)
  1568. {
  1569. if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
  1570. {
  1571. if (btns[i]->selectable)
  1572. btns[i]->select(true);
  1573. if (btns[i]->type==1 && ((Button<>*)btns[i])->fun)
  1574. (this->*(((Button<>*)btns[i])->fun))();
  1575. int zz = btns.size();
  1576. if (i>=zz)
  1577. break;
  1578. if (btns[i]==prnr && btns[i]->type==2)
  1579. {
  1580. ((IntBut<> *)(btns[i]))->set();
  1581. ourScenSel->mapsel.slid->whereAreWe=0;
  1582. ourScenSel->mapsel.slid->updateSlid();
  1583. ourScenSel->mapsel.slid->positionsAmnt=ourScenSel->mapsel.countWL();
  1584. ourScenSel->mapsel.printMaps(0);
  1585. }
  1586. }
  1587. }
  1588. }
  1589. else if (sEvent.type==SDL_MOUSEMOTION)
  1590. {
  1591. if (highlighted)
  1592. {
  1593. if (isItIn(&highlighted->pos,sEvent.motion.x,sEvent.motion.y))
  1594. return;
  1595. else
  1596. {
  1597. highlighted->hover(false);
  1598. highlighted = NULL;
  1599. }
  1600. }
  1601. for (int i=0;i<btns.size();i++)
  1602. {
  1603. if (!btns[i]->highlightable)
  1604. continue;
  1605. if(isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
  1606. {
  1607. btns[i]->hover(true);
  1608. highlighted=btns[i];
  1609. return;
  1610. }
  1611. else if (btns[i]->highlighted)
  1612. btns[i]->hover(false);
  1613. }
  1614. }
  1615. }
  1616. StartInfo CPreGame::runLoop()
  1617. {
  1618. SDL_Event sEvent;
  1619. while(run)
  1620. {
  1621. CGI->screenh->updateScreen();
  1622. try
  1623. {
  1624. if(SDL_PollEvent(&sEvent)) //wait for event...
  1625. {
  1626. menuItems * current = currentItems();
  1627. if(sEvent.type==SDL_QUIT)
  1628. return ret;
  1629. for (int i=0;i<interested.size();i++)
  1630. interested[i]->handleIt(sEvent);
  1631. if (!current)
  1632. {
  1633. (this->*handleOther)(sEvent);
  1634. }
  1635. else if (sEvent.type==SDL_KEYDOWN)
  1636. {
  1637. if (sEvent.key.keysym.sym==SDLK_q)
  1638. {
  1639. return ret;
  1640. break;
  1641. }
  1642. /*if (state==EState::newGame)
  1643. {
  1644. switch (sEvent.key.keysym.sym)
  1645. {
  1646. case SDLK_LEFT:
  1647. {
  1648. if(currentItems()->lNewGame.x>0)
  1649. currentItems()->lNewGame.x--;
  1650. break;
  1651. }
  1652. case (SDLK_RIGHT):
  1653. {
  1654. currentItems()->lNewGame.x++;
  1655. break;
  1656. }
  1657. case (SDLK_UP):
  1658. {
  1659. if(currentItems()->lNewGame.y>0)
  1660. currentItems()->lNewGame.y--;
  1661. break;
  1662. }
  1663. case (SDLK_DOWN):
  1664. {
  1665. currentItems()->lNewGame.y++;
  1666. break;
  1667. }
  1668. }
  1669. showNewMenu();
  1670. }*/
  1671. }
  1672. else if (sEvent.type==SDL_MOUSEMOTION)
  1673. {
  1674. CGI->curh->cursorMove(sEvent.motion.x, sEvent.motion.y); //for graphical mouse
  1675. if (currentMessage) continue;
  1676. if (current->highlighted)
  1677. {
  1678. switch (current->highlighted)
  1679. {
  1680. case 1:
  1681. {
  1682. if(isItIn(&current->lNewGame,sEvent.motion.x,sEvent.motion.y))
  1683. continue;
  1684. else
  1685. {
  1686. current->highlighted=0;
  1687. highlightButton(1,0);
  1688. }
  1689. break;
  1690. }
  1691. case 2:
  1692. {
  1693. if(isItIn(&current->lLoadGame,sEvent.motion.x,sEvent.motion.y))
  1694. continue;
  1695. else
  1696. {
  1697. current->highlighted=0;
  1698. highlightButton(2,0);
  1699. }
  1700. break;
  1701. }
  1702. case 3:
  1703. {
  1704. if(isItIn(&current->lHighScores,sEvent.motion.x,sEvent.motion.y))
  1705. continue;
  1706. else
  1707. {
  1708. current->highlighted=0;
  1709. highlightButton(3,0);
  1710. }
  1711. break;
  1712. }
  1713. case 4:
  1714. {
  1715. if(isItIn(&current->lCredits,sEvent.motion.x,sEvent.motion.y))
  1716. continue;
  1717. else
  1718. {
  1719. current->highlighted=0;
  1720. highlightButton(4,0);
  1721. }
  1722. break;
  1723. }
  1724. case 5:
  1725. {
  1726. if(isItIn(&current->lQuit,sEvent.motion.x,sEvent.motion.y))
  1727. continue;
  1728. else
  1729. {
  1730. current->highlighted=0;
  1731. highlightButton(5,0);
  1732. }
  1733. break;
  1734. }
  1735. } //switch (current->highlighted)
  1736. } // if (current->highlighted)
  1737. if (isItIn(&current->lNewGame,sEvent.motion.x,sEvent.motion.y))
  1738. {
  1739. highlightButton(1,2);
  1740. current->highlighted=1;
  1741. }
  1742. else if (isItIn(&current->lLoadGame,sEvent.motion.x,sEvent.motion.y))
  1743. {
  1744. highlightButton(2,2);
  1745. current->highlighted=2;
  1746. }
  1747. else if (isItIn(&current->lHighScores,sEvent.motion.x,sEvent.motion.y))
  1748. {
  1749. highlightButton(3,2);
  1750. current->highlighted=3;
  1751. }
  1752. else if (isItIn(&current->lCredits,sEvent.motion.x,sEvent.motion.y))
  1753. {
  1754. highlightButton(4,2);
  1755. current->highlighted=4;
  1756. }
  1757. else if (isItIn(&current->lQuit,sEvent.motion.x,sEvent.motion.y))
  1758. {
  1759. highlightButton(5,2);
  1760. current->highlighted=5;
  1761. }
  1762. }
  1763. else if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT))
  1764. {
  1765. mush->playClick();
  1766. for (int i=0;i<btns.size(); i++)
  1767. {
  1768. if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
  1769. {
  1770. btns[i]->press(true);
  1771. //SDL_BlitSurface((btns[i].imgs)->ourImages[1].bitmap,NULL,ekran,&btns[i].pos);
  1772. //updateRect(&btns[i].pos);
  1773. }
  1774. }
  1775. if (currentMessage) continue;
  1776. if (isItIn(&current->lNewGame,sEvent.motion.x,sEvent.motion.y))
  1777. {
  1778. highlightButton(1,1);
  1779. current->highlighted=1;
  1780. }
  1781. else if (isItIn(&current->lLoadGame,sEvent.motion.x,sEvent.motion.y))
  1782. {
  1783. highlightButton(2,1);
  1784. current->highlighted=2;
  1785. }
  1786. else if (isItIn(&current->lHighScores,sEvent.motion.x,sEvent.motion.y))
  1787. {
  1788. highlightButton(3,1);
  1789. current->highlighted=3;
  1790. }
  1791. else if (isItIn(&current->lCredits,sEvent.motion.x,sEvent.motion.y))
  1792. {
  1793. highlightButton(4,1);
  1794. current->highlighted=4;
  1795. }
  1796. else if (isItIn(&current->lQuit,sEvent.motion.x,sEvent.motion.y))
  1797. {
  1798. highlightButton(5,1);
  1799. current->highlighted=5;
  1800. }
  1801. }
  1802. else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
  1803. {
  1804. for (int i=0;i<btns.size(); i++)
  1805. {
  1806. if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
  1807. (this->*(((Button<>*)btns[i])->fun))();
  1808. else
  1809. {
  1810. btns[i]->press(false);
  1811. //SDL_BlitSurface((btns[i].imgs)->ourImages[0].bitmap,NULL,ekran,&btns[i].pos);
  1812. //updateRect(&btns[i].pos);
  1813. }
  1814. }
  1815. if (currentMessage) continue;
  1816. if (isItIn(&current->lNewGame,sEvent.motion.x,sEvent.motion.y))
  1817. {
  1818. highlightButton(1,2);
  1819. current->highlighted=1;
  1820. (this->*(current->fNewGame))();
  1821. }
  1822. else if (isItIn(&current->lLoadGame,sEvent.motion.x,sEvent.motion.y))
  1823. {
  1824. highlightButton(2,2);
  1825. current->highlighted=2;
  1826. }
  1827. else if (isItIn(&current->lHighScores,sEvent.motion.x,sEvent.motion.y))
  1828. {
  1829. highlightButton(3,2);
  1830. current->highlighted=3;
  1831. }
  1832. else if (isItIn(&current->lCredits,sEvent.motion.x,sEvent.motion.y))
  1833. {
  1834. highlightButton(4,2);
  1835. current->highlighted=4;
  1836. }
  1837. else if (isItIn(&current->lQuit,sEvent.motion.x,sEvent.motion.y))
  1838. {
  1839. highlightButton(5,2);
  1840. current->highlighted=5;
  1841. (this->*(current->fQuit))();
  1842. }
  1843. }
  1844. else if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_RIGHT))
  1845. {
  1846. if (currentMessage) continue;
  1847. if (isItIn(&current->lNewGame,sEvent.motion.x,sEvent.motion.y))
  1848. {
  1849. showCenBox(buttonText(0));
  1850. }
  1851. else if (isItIn(&current->lLoadGame,sEvent.motion.x,sEvent.motion.y))
  1852. {
  1853. showCenBox(buttonText(1));
  1854. }
  1855. else if (isItIn(&current->lHighScores,sEvent.motion.x,sEvent.motion.y))
  1856. {
  1857. showCenBox(buttonText(2));
  1858. }
  1859. else if (isItIn(&current->lCredits,sEvent.motion.x,sEvent.motion.y))
  1860. {
  1861. showCenBox(buttonText(3));
  1862. }
  1863. else if (isItIn(&ourMainMenu->lQuit,sEvent.motion.x,sEvent.motion.y))
  1864. {
  1865. showCenBox(buttonText(4));
  1866. }
  1867. }
  1868. else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_RIGHT) && currentMessage)
  1869. {
  1870. hideBox();
  1871. }
  1872. }
  1873. }
  1874. catch(...)
  1875. { continue; }
  1876. SDL_Delay(1); //give time for other apps
  1877. }
  1878. return ret;
  1879. }
  1880. std::string CPreGame::buttonText(int which)
  1881. {
  1882. if (state==EState::mainMenu)
  1883. {
  1884. switch (which)
  1885. {
  1886. case 0:
  1887. return preth->mainNewGame;
  1888. case 1:
  1889. return preth->mainLoadGame;
  1890. case 2:
  1891. return preth->mainHighScores;
  1892. case 3:
  1893. return preth->mainCredits;
  1894. case 4:
  1895. return preth->mainQuit;
  1896. }
  1897. }
  1898. else if (state==EState::newGame)
  1899. {
  1900. switch (which)
  1901. {
  1902. case 0:
  1903. return preth->ngSingleScenario;
  1904. case 1:
  1905. return preth->ngMultiplayer;
  1906. case 2:
  1907. return preth->ngCampain;
  1908. case 3:
  1909. return preth->ngTutorial;
  1910. case 4:
  1911. return preth->ngBack;
  1912. }
  1913. }
  1914. }
  1915. void CPreGame::quitAskBox()
  1916. {
  1917. showAskBox("\"{} Are you sure you want to quit?\"",NULL,NULL);
  1918. }
  1919. void CPreGame::sortMaps()
  1920. {
  1921. std::sort(ourScenSel->mapsel.ourMaps.begin(),ourScenSel->mapsel.ourMaps.end(),mapSorter(ourScenSel->mapsel.sortBy));
  1922. ourScenSel->mapsel.select(0);
  1923. printMapsFrom(0);
  1924. }
  1925. void CPreGame::setTurnLength(int on)
  1926. {
  1927. int min;
  1928. switch (on)
  1929. {
  1930. case 0:
  1931. min=1;
  1932. break;
  1933. case 1:
  1934. min=2;
  1935. break;
  1936. case 2:
  1937. min=4;
  1938. break;
  1939. case 3:
  1940. min=6;
  1941. break;
  1942. case 4:
  1943. min=8;
  1944. break;
  1945. case 5:
  1946. min=10;
  1947. break;
  1948. case 6:
  1949. min=15;
  1950. break;
  1951. case 7:
  1952. min=20;
  1953. break;
  1954. case 8:
  1955. min=25;
  1956. break;
  1957. case 9:
  1958. min=30;
  1959. break;
  1960. case 10:
  1961. min=0;
  1962. break;
  1963. }
  1964. SDL_BlitSurface(ourOptions->bg,&genRect(23,134,256,547),ekran,&genRect(23,134,258,553));
  1965. updateRect(&genRect(23,134,258,553));
  1966. if (min)
  1967. {
  1968. std::ostringstream os;
  1969. os<<min<<" Minutes";
  1970. CSDL_Ext::printAtMiddle(os.str(),323,563,GEOR13);
  1971. }
  1972. else CSDL_Ext::printAtMiddle("Unlimited",323,563,GEOR13);
  1973. }