CPreGame.cpp 64 KB

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