CPreGame.cpp 63 KB

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