CPreGame.cpp 64 KB

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