CPreGame.cpp 67 KB

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