CPreGame.cpp 63 KB

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