CPreGame.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. #include "../stdafx.h"
  2. #include "CPreGame.h"
  3. #include "../hch/CDefHandler.h"
  4. #include <ctime>
  5. #include <boost/filesystem.hpp> // includes all needed Boost.Filesystem declarations
  6. #include <boost/algorithm/string.hpp>
  7. #include <zlib.h>
  8. #include "../timeHandler.h"
  9. #include <sstream>
  10. #include "SDL_Extensions.h"
  11. #include "CGameInfo.h"
  12. #include "../hch/CGeneralTextHandler.h"
  13. #include "CCursorHandler.h"
  14. #include "../hch/CLodHandler.h"
  15. #include "../hch/CTownHandler.h"
  16. #include "../hch/CHeroHandler.h"
  17. #include <cmath>
  18. #include "Graphics.h"
  19. //#include <boost/thread.hpp>
  20. #include <boost/bind.hpp>
  21. #include <cstdlib>
  22. #include "../lib/Connection.h"
  23. #include "../hch/CMusicHandler.h"
  24. #include "../hch/CVideoHandler.h"
  25. #include "AdventureMapButton.h"
  26. /*
  27. * CPreGame.cpp, part of VCMI engine
  28. *
  29. * Authors: listed in file AUTHORS in main folder
  30. *
  31. * License: GNU General Public License v2.0 or later
  32. * Full text of license available in license.txt file, in main folder
  33. *
  34. */
  35. namespace fs = boost::filesystem;
  36. void startGame(StartInfo * options);
  37. CGPreGame * CGP;
  38. static const CMapInfo *curMap = NULL;
  39. static StartInfo *curOpts = NULL;
  40. static int playerColor;
  41. CMenuScreen::CMenuScreen( EState which )
  42. {
  43. OBJ_CONSTRUCTION;
  44. bgAd = NULL;
  45. switch(which)
  46. {
  47. case mainMenu:
  48. {
  49. buttons[0] = new AdventureMapButton("", CGI->generaltexth->zelp[3].second, bind(&CMenuScreen::moveTo, this, ref(CGP->scrs[newGame])), 540, 10, "ZMENUNG.DEF", SDLK_n);
  50. buttons[1] = new AdventureMapButton("", CGI->generaltexth->zelp[4].second, bind(&CMenuScreen::moveTo, this, ref(CGP->scrs[loadGame])), 532, 132, "ZMENULG.DEF", SDLK_l);
  51. buttons[2] = new AdventureMapButton("", CGI->generaltexth->zelp[5].second, 0 /*cb*/, 524, 251, "ZMENUHS.DEF", SDLK_h);
  52. buttons[3] = new AdventureMapButton("", CGI->generaltexth->zelp[6].second, 0 /*cb*/, 557, 359, "ZMENUCR.DEF", SDLK_c);
  53. buttons[4] = new AdventureMapButton("", CGI->generaltexth->zelp[7].second, bind(std::exit, 0), 586, 468, "ZMENUQT.DEF", SDLK_ESCAPE);
  54. }
  55. break;
  56. case newGame:
  57. {
  58. bgAd = new CPicture(BitmapHandler::loadBitmap("ZNEWGAM.bmp"), 114, 312, true);
  59. buttons[0] = new AdventureMapButton("", CGI->generaltexth->zelp[10].second, bind(&CGPreGame::openSel, CGP, newGame), 545, 4, "ZTSINGL.DEF", SDLK_s);
  60. buttons[1] = new AdventureMapButton("", CGI->generaltexth->zelp[11].second, 0 /*cb*/, 568, 120, "ZTMULTI.DEF", SDLK_m);
  61. buttons[2] = new AdventureMapButton("", CGI->generaltexth->zelp[12].second, 0 /*cb*/, 541, 233, "ZTCAMPN.DEF", SDLK_c);
  62. buttons[3] = new AdventureMapButton("", CGI->generaltexth->zelp[13].second, 0 /*cb*/, 545, 358, "ZTTUTOR.DEF", SDLK_t);
  63. buttons[4] = new AdventureMapButton("", CGI->generaltexth->zelp[14].second, bind(&CMenuScreen::moveTo, this, CGP->scrs[mainMenu]), 582, 464, "ZTBACK.DEF", SDLK_ESCAPE);
  64. }
  65. break;
  66. case loadGame:
  67. {
  68. bgAd = new CPicture(BitmapHandler::loadBitmap("ZLOADGAM.bmp"), 114, 312, true);
  69. buttons[0] = new AdventureMapButton("", CGI->generaltexth->zelp[10].second, bind(&CGPreGame::openSel, CGP, loadGame), 545, 4, "ZTSINGL.DEF", SDLK_s);
  70. buttons[1] = new AdventureMapButton("", CGI->generaltexth->zelp[11].second, 0 /*cb*/, 568, 120, "ZTMULTI.DEF", SDLK_m);
  71. buttons[2] = new AdventureMapButton("", CGI->generaltexth->zelp[12].second, 0 /*cb*/, 541, 233, "ZTCAMPN.DEF", SDLK_c);
  72. buttons[3] = new AdventureMapButton("", CGI->generaltexth->zelp[13].second, 0 /*cb*/, 545, 358, "ZTTUTOR.DEF", SDLK_t);
  73. buttons[4] = new AdventureMapButton("", CGI->generaltexth->zelp[14].second, bind(&CMenuScreen::moveTo, this, CGP->scrs[mainMenu]), 582, 464, "ZTBACK.DEF", SDLK_ESCAPE);
  74. }
  75. break;
  76. }
  77. for(int i = 0; i < ARRAY_COUNT(buttons); i++)
  78. buttons[i]->hoverable = true;
  79. }
  80. CMenuScreen::~CMenuScreen()
  81. {
  82. }
  83. void CMenuScreen::showAll( SDL_Surface * to )
  84. {
  85. blitAt(CGP->mainbg, 0, 0, to);
  86. CIntObject::showAll(to);
  87. }
  88. void CMenuScreen::show( SDL_Surface * to )
  89. {
  90. CIntObject::show(to);
  91. CGI->videoh->update(pos.x + 8, pos.y + 105, screen, true, false);
  92. }
  93. void CMenuScreen::moveTo( CMenuScreen *next )
  94. {
  95. GH.popInt(this);
  96. GH.pushInt(next);
  97. }
  98. void CGPreGame::run()
  99. {
  100. GH.handleEvents();
  101. #ifdef _WIN32
  102. CGI->videoh->open("ACREDIT.SMK");
  103. #else
  104. CGI->videoh->open("ACREDIT.SMK", true, false);
  105. #endif
  106. GH.pushInt(scrs[mainMenu]);
  107. while(1)
  108. {
  109. CGI->curh->draw1();
  110. SDL_Flip(screen);
  111. CGI->curh->draw2();
  112. SDL_Delay(20); //give time for other apps
  113. GH.topInt()->show(screen);
  114. GH.updateTime();
  115. GH.handleEvents();
  116. }
  117. }
  118. CGPreGame::CGPreGame()
  119. {
  120. GH.defActionsDef = 31;
  121. CGP = this;
  122. mainbg = BitmapHandler::loadBitmap("ZPIC1005.bmp");
  123. for(int i = 0; i < ARRAY_COUNT(scrs); i++)
  124. scrs[i] = new CMenuScreen((EState)i);
  125. }
  126. CGPreGame::~CGPreGame()
  127. {
  128. SDL_FreeSurface(mainbg);
  129. for(int i = 0; i < ARRAY_COUNT(scrs); i++)
  130. delete scrs[i];
  131. }
  132. void CGPreGame::openSel( EState type )
  133. {
  134. GH.pushInt(new CSelectionScreen(type));
  135. }
  136. void CGPreGame::loadGraphics()
  137. {
  138. victory = CDefHandler::giveDef("SCNRVICT.DEF");
  139. loss = CDefHandler::giveDef("SCNRLOSS.DEF");
  140. bonuses = CDefHandler::giveDef("SCNRSTAR.DEF");
  141. rHero = BitmapHandler::loadBitmap("HPSRAND1.bmp");
  142. rTown = BitmapHandler::loadBitmap("HPSRAND0.bmp");
  143. nHero = BitmapHandler::loadBitmap("HPSRAND6.bmp");
  144. nTown = BitmapHandler::loadBitmap("HPSRAND5.bmp");
  145. }
  146. void CGPreGame::disposeGraphics()
  147. {
  148. delete victory;
  149. delete loss;
  150. SDL_FreeSurface(rHero);
  151. SDL_FreeSurface(nHero);
  152. SDL_FreeSurface(rTown);
  153. SDL_FreeSurface(nTown);
  154. }
  155. CSelectionScreen::CSelectionScreen( EState Type )
  156. {
  157. OBJ_CONSTRUCTION;
  158. CGP->loadGraphics();
  159. type = Type;
  160. curOpts = &sInfo;
  161. current = NULL;
  162. sInfo.mode = (Type == newGame ? 0 : 1);
  163. sInfo.turnTime = 0;
  164. curTab = NULL;
  165. bg = new CPicture(BitmapHandler::loadBitmap(rand()%2 ? "ZPIC1000.bmp" : "ZPIC1001.bmp"), 0, 0, true);
  166. card = new InfoCard(type);
  167. opt = new OptionsTab(type/*, sInfo*/);
  168. opt->recActions = DISPOSE;
  169. sel = new SelectionTab(type, bind(&CSelectionScreen::changeSelection, this, _1));
  170. sel->recActions = DISPOSE;
  171. switch(type)
  172. {
  173. case newGame:
  174. {
  175. card->difficulty->onChange = bind(&CSelectionScreen::difficultyChange, this, _1);
  176. card->difficulty->select(1, 0);
  177. AdventureMapButton *select = new AdventureMapButton(CGI->generaltexth->zelp[45], bind(&CSelectionScreen::toggleTab, this, sel), 414, 81, "GSPBUTT.DEF", SDLK_s);
  178. select->addTextOverlay(CGI->generaltexth->allTexts[500], FONT_SMALL);
  179. AdventureMapButton *opts = new AdventureMapButton(CGI->generaltexth->zelp[46], bind(&CSelectionScreen::toggleTab, this, opt), 414, 509, "GSPBUTT.DEF", SDLK_a);
  180. opts->addTextOverlay(CGI->generaltexth->allTexts[501], FONT_SMALL);
  181. AdventureMapButton *random = new AdventureMapButton(CGI->generaltexth->zelp[47], bind(&CSelectionScreen::toggleTab, this, sel), 414, 105, "GSPBUTT.DEF", SDLK_r);
  182. random->addTextOverlay(CGI->generaltexth->allTexts[740], FONT_SMALL);
  183. start = new AdventureMapButton(CGI->generaltexth->zelp[103], bind(&CSelectionScreen::startGame, this), 414, 535, "SCNRBEG.DEF", SDLK_b);
  184. }
  185. break;
  186. case loadGame:
  187. card->difficulty->select(current->seldiff, 0);
  188. sel->recActions = 255;
  189. start = new AdventureMapButton(CGI->generaltexth->zelp[103], bind(&CSelectionScreen::startGame, this), 414, 535, "SCNRLOD.DEF", SDLK_b);
  190. break;
  191. }
  192. back = new AdventureMapButton(CGI->generaltexth->zelp[105], bind(&CGuiHandler::popIntTotally, &GH, this), 584, 535, "SCNRBACK.DEF", SDLK_ESCAPE);
  193. }
  194. CSelectionScreen::~CSelectionScreen()
  195. {
  196. }
  197. void CSelectionScreen::toggleTab(CIntObject *tab)
  198. {
  199. if(curTab && curTab->active)
  200. {
  201. curTab->deactivate();
  202. curTab->recActions = DISPOSE;
  203. }
  204. if(curTab != tab)
  205. {
  206. tab->recActions = 255;
  207. tab->activate();
  208. curTab = tab;
  209. }
  210. else
  211. {
  212. curTab = NULL;
  213. };
  214. GH.totalRedraw();
  215. }
  216. void CSelectionScreen::changeSelection( const CMapInfo *to )
  217. {
  218. curMap = current = to;
  219. updateStartInfo(to);
  220. card->changeSelection(to);
  221. opt->changeSelection(to);
  222. }
  223. void CSelectionScreen::updateStartInfo( const CMapInfo * to )
  224. {
  225. sInfo.mapname = to->filename;
  226. sInfo.playerInfos.clear();
  227. sInfo.playerInfos.resize(to->playerAmnt);
  228. playerColor = -1;
  229. int serialC=0;
  230. for (int i = 0; i < PLAYER_LIMIT; i++)
  231. {
  232. const PlayerInfo &pinfo = to->players[i];
  233. //neither computer nor human can play - no player
  234. if (!(pinfo.canComputerPlay || pinfo.canComputerPlay))
  235. continue;
  236. PlayerSettings &pset = sInfo.playerInfos[serialC];
  237. pset.color = i;
  238. pset.serial = serialC++;
  239. if (pinfo.canHumanPlay && playerColor < 0)
  240. {
  241. pset.name = CGI->generaltexth->allTexts[434]; //Player
  242. pset.human = true;
  243. playerColor = i;
  244. }
  245. else
  246. {
  247. pset.name = CGI->generaltexth->allTexts[468];//Computer
  248. pset.human = false;
  249. }
  250. for (int j = 0; j < F_NUMBER && pset.castle != -1; j++) //we start with none and find matching faction. if more than one, then set to random
  251. {
  252. if((1 << j) & pinfo.allowedFactions)
  253. {
  254. if (pset.castle >= 0) //we've already assigned a castle and another one is possible -> set random and let player choose
  255. pset.castle = -1; //breaks
  256. if (pset.castle == -2) //first available castle - pick
  257. pset.castle = j;
  258. }
  259. }
  260. if ((pinfo.generateHeroAtMainTown || to->version==CMapHeader::RoE) && pinfo.hasMainTown //we will generate hero in front of main town
  261. || pinfo.p8) //random hero
  262. pset.hero = -1;
  263. else
  264. pset.hero = -2;
  265. if(pinfo.mainHeroName.length())
  266. {
  267. pset.heroName = pinfo.mainHeroName;
  268. if((pset.heroPortrait = pinfo.mainHeroPortrait) == 255)
  269. pset.heroPortrait = pinfo.p9;
  270. }
  271. pset.handicap = 0;
  272. }
  273. }
  274. void CSelectionScreen::startGame()
  275. {
  276. if(!current)
  277. return;
  278. //CGP->disposeGraphics();
  279. StartInfo *si = new StartInfo(sInfo);
  280. GH.popIntTotally(this);
  281. GH.popIntTotally(GH.topInt());
  282. curMap = NULL;
  283. curOpts = NULL;
  284. ::startGame(si);
  285. delete si; //rather won't be called...
  286. }
  287. void CSelectionScreen::difficultyChange( int to )
  288. {
  289. assert(type == newGame);
  290. sInfo.difficulty = to;
  291. GH.totalRedraw();
  292. }
  293. // A new size filter (Small, Medium, ...) has been selected. Populate
  294. // selMaps with the relevant data.
  295. void SelectionTab::filter( int size )
  296. {
  297. curItems.clear();
  298. for (size_t i=0; i<allItems.size(); i++)
  299. if( allItems[i].version && (!size || allItems[i].width == size))
  300. curItems.push_back(&allItems[i]);
  301. if(curItems.size())
  302. {
  303. slider->block(false);
  304. slider->setAmount(curItems.size());
  305. sort();
  306. slider->moveTo(0);
  307. onSelect(curItems[0]);
  308. }
  309. else
  310. {
  311. slider->block(true);
  312. onSelect(NULL);
  313. }
  314. }
  315. void SelectionTab::getFiles(std::vector<FileInfo> &out, const std::string &dirname, const std::string &ext)
  316. {
  317. if(!boost::filesystem::exists(dirname))
  318. {
  319. tlog1 << "Cannot find " << dirname << " directory!\n";
  320. }
  321. fs::path tie( (fs::initial_path<fs::path>())/dirname );
  322. fs::directory_iterator end_iter;
  323. for ( fs::directory_iterator file (tie); file!=end_iter; ++file )
  324. {
  325. if(fs::is_regular_file(file->status())
  326. && boost::ends_with(file->path().filename(), ext))
  327. {
  328. out.resize(out.size()+1);
  329. out.back().date = fs::last_write_time(file->path());
  330. out.back().name = dirname+"/"+(file->path().leaf());
  331. }
  332. }
  333. allItems.resize(out.size());
  334. }
  335. void SelectionTab::parseMaps(std::vector<FileInfo> &files, int start, int threads)
  336. {
  337. int read=0;
  338. unsigned char mapBuffer[1500];
  339. while(start < allItems.size())
  340. {
  341. gzFile tempf = gzopen(files[start].name.c_str(),"rb");
  342. read = gzread(tempf, mapBuffer, 1500);
  343. gzclose(tempf);
  344. if(read < 50 || !mapBuffer[4])
  345. {
  346. tlog3 << "\t\tWarning: corrupted map file: " << files[start].name << std::endl;
  347. }
  348. else //valid map
  349. {
  350. allItems[start].init(files[start].name, mapBuffer);
  351. //allItems[start].date = "DATEDATE";// files[start].date;
  352. }
  353. start += threads;
  354. }
  355. }
  356. void SelectionTab::parseGames(std::vector<FileInfo> &files)
  357. {
  358. for(int i=0; i<files.size(); i++)
  359. {
  360. CLoadFile lf(files[i].name);
  361. if(!lf.sfile)
  362. continue;
  363. ui8 sign[8];
  364. lf >> sign;
  365. if(std::memcmp(sign,"VCMISVG",7))
  366. {
  367. tlog1 << files[i].name << " is not a correct savefile!" << std::endl;
  368. continue;
  369. }
  370. lf >> static_cast<CMapHeader&>(allItems[i]) >> allItems[i].seldiff;
  371. allItems[i].filename = files[i].name;
  372. allItems[i].countPlayers();
  373. allItems[i].date = std::asctime(std::localtime(&files[i].date));
  374. }
  375. }
  376. SelectionTab::SelectionTab(EState Type, const boost::function<void(CMapInfo *)> &OnSelect)
  377. :onSelect(OnSelect)
  378. {
  379. OBJ_CONSTRUCTION;
  380. selectionPos = 0;
  381. used = LCLICK;
  382. slider = NULL;
  383. type = Type;
  384. std::vector<FileInfo> toParse;
  385. switch(type)
  386. {
  387. case newGame:
  388. getFiles(toParse, "Maps", "h3m");
  389. parseMaps(toParse);
  390. positions = 18;
  391. break;
  392. case loadGame:
  393. case saveGame:
  394. getFiles(toParse, "Games", "vlgm1");
  395. parseGames(toParse);
  396. if(type == loadGame)
  397. {
  398. positions = 18;
  399. }
  400. else
  401. {
  402. positions = 16;
  403. }
  404. break;
  405. default:
  406. assert(0);
  407. }
  408. bg = new CPicture(BitmapHandler::loadBitmap("SCSELBCK.bmp"), 3, 6, true);
  409. pos = bg->pos;
  410. //size filter buttons
  411. {
  412. int sizes[] = {36, 72, 108, 144, 0};
  413. const char * names[] = {"SCSMBUT.DEF", "SCMDBUT.DEF", "SCLGBUT.DEF", "SCXLBUT.DEF", "SCALBUT.DEF"};
  414. for(int i = 0; i < 5; i++)
  415. new AdventureMapButton(CGI->generaltexth->zelp[54+i], bind(&SelectionTab::filter, this, sizes[i]), 161 + 47*i, 52, names[i]);
  416. }
  417. {
  418. int xpos[] = {26, 58, 91, 124, 309, 342};
  419. const char * names[] = {"SCBUTT1.DEF", "SCBUTT2.DEF", "SCBUTCP.DEF", "SCBUTT3.DEF", "SCBUTT4.DEF", "SCBUTT5.DEF"};
  420. for(int i = 0; i < 6; i++)
  421. new AdventureMapButton(CGI->generaltexth->zelp[107+i], bind(&SelectionTab::sortBy, this, i), xpos[i], 92, names[i]);
  422. }
  423. slider = new CSlider(375, 92, 480, bind(&SelectionTab::sliderMove, this, _1), positions, curItems.size(), 0, false, 1);
  424. format = CDefHandler::giveDef("SCSELC.DEF");
  425. sortingBy = _format;
  426. ascending = true;
  427. filter(0);
  428. select(0);
  429. }
  430. SelectionTab::~SelectionTab()
  431. {
  432. delete format;
  433. }
  434. void SelectionTab::sortBy( int criteria )
  435. {
  436. if(criteria == sortingBy)
  437. {
  438. ascending = !ascending;
  439. }
  440. else
  441. {
  442. sortingBy = (ESortBy)criteria;
  443. ascending = true;
  444. }
  445. sort();
  446. }
  447. void SelectionTab::sort()
  448. {
  449. if(sortingBy != _name)
  450. std::stable_sort(curItems.begin(),curItems.end(),mapSorter(_name));
  451. std::stable_sort(curItems.begin(),curItems.end(),mapSorter(sortingBy));
  452. if(!ascending)
  453. std::reverse(curItems.begin(), curItems.end());
  454. redraw();
  455. }
  456. void SelectionTab::select( int position )
  457. {
  458. // New selection. py is the index in curItems.
  459. int py = position + slider->value;
  460. if (py < curItems.size())
  461. {
  462. CGI->soundh->playSound(soundBase::button);
  463. selectionPos = py;
  464. onSelect(curItems[py]);
  465. }
  466. }
  467. int SelectionTab::getPosition( int x, int y )
  468. {
  469. return -1;
  470. }
  471. void SelectionTab::sliderMove( int slidPos )
  472. {
  473. if(!slider) return; //ignore spurious call when slider is being created
  474. redraw();
  475. }
  476. // Display the tab with the scenario names
  477. //
  478. // elemIdx is the index of the maps or saved game to display on line 0
  479. // slider->capacity contains the number of available screen lines
  480. // slider->positionsAmnt is the number of elements after filtering
  481. void SelectionTab::printMaps(SDL_Surface *to)
  482. {
  483. int elemIdx = slider->value;
  484. // Display all elements if there's enough space
  485. //if(slider->amount < slider->capacity)
  486. // elemIdx = 0;
  487. SDL_Color nasz;
  488. #define POS(xx, yy) pos.x + xx, pos.y + yy + line*25
  489. for (int line = 0; line < positions && elemIdx < curItems.size(); elemIdx++, line++)
  490. {
  491. CMapInfo* curMap = curItems[elemIdx];
  492. if (elemIdx == selectionPos)
  493. nasz=tytulowy;
  494. else
  495. nasz=zwykly;
  496. std::ostringstream ostr(std::ostringstream::out);
  497. ostr << curMap->playerAmnt << "/" << curMap->humenPlayers;
  498. CSDL_Ext::printAt(ostr.str(), POS(29, 120), FONT_SMALL, nasz, to);
  499. std::string temp2 = "C";
  500. switch (curMap->width)
  501. {
  502. case 36:
  503. temp2="S";
  504. break;
  505. case 72:
  506. temp2="M";
  507. break;
  508. case 108:
  509. temp2="L";
  510. break;
  511. case 144:
  512. temp2="XL";
  513. break;
  514. }
  515. CSDL_Ext::printAtMiddle(temp2, POS(70, 128), FONT_SMALL, nasz, to);
  516. int temp=-1;
  517. switch (curMap->version)
  518. {
  519. case CMapHeader::RoE:
  520. temp=0;
  521. break;
  522. case CMapHeader::AB:
  523. temp=1;
  524. break;
  525. case CMapHeader::SoD:
  526. temp=2;
  527. break;
  528. case CMapHeader::WoG:
  529. temp=3;
  530. break;
  531. default:
  532. // Unknown version. Be safe and ignore that map
  533. tlog2 << "Warning: " << curMap->filename << " has wrong version!\n";
  534. continue;
  535. }
  536. blitAt(format->ourImages[temp].bitmap, POS(88, 117), to);
  537. if (type == newGame)
  538. {
  539. if (!(curMap->name.length()))
  540. curMap->name = "Unnamed";
  541. CSDL_Ext::printAtMiddle(curMap->name, POS(213, 128), FONT_SMALL, nasz, to);
  542. }
  543. else
  544. {
  545. std::string &name = curMap->filename;
  546. CSDL_Ext::printAtMiddle(name.substr(6,name.size()-12), POS(213, 128), FONT_SMALL, nasz, to);
  547. }
  548. if (curMap->victoryCondition.condition == winStandard)
  549. temp = 11;
  550. else
  551. temp = curMap->victoryCondition.condition;
  552. blitAt(CGP->victory->ourImages[temp].bitmap, POS(306, 117), to);
  553. if (curMap->lossCondition.typeOfLossCon == lossStandard)
  554. temp=3;
  555. else
  556. temp=curMap->lossCondition.typeOfLossCon;
  557. blitAt(CGP->loss->ourImages[temp].bitmap, POS(339, 117), to);
  558. }
  559. #undef POS
  560. }
  561. void SelectionTab::showAll( SDL_Surface * to )
  562. {
  563. CIntObject::showAll(to);
  564. printMaps(to);
  565. CSDL_Ext::printAtMiddle(CGI->generaltexth->arraytxt[type==newGame ? 229 : 230], 208, 34, FONT_MEDIUM, tytulowy, to); //Select a Scenario to Play
  566. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[510], 90, 68, FONT_SMALL, tytulowy, to); //Map sizes
  567. }
  568. void SelectionTab::clickLeft( tribool down, bool previousState )
  569. {
  570. Point clickPos(GH.current->button.x, GH.current->button.y);
  571. clickPos -= pos.topLeft();
  572. if (clickPos.y > 115 && clickPos.y < 564 && clickPos.x > 52 && clickPos.x < 366)
  573. {
  574. int line = (clickPos.y-115) / 25; //which line
  575. select(line);
  576. }
  577. }
  578. InfoCard::InfoCard( EState Type )
  579. {
  580. OBJ_CONSTRUCTION;
  581. sizes = CDefHandler::giveDef("SCNRMPSZ.DEF");
  582. sFlags = CDefHandler::giveDef("ITGFLAGS.DEF");
  583. type = Type;
  584. bg = new CPicture(BitmapHandler::loadBitmap("GSELPOP1.bmp"), 396, 6, true);
  585. pos = bg->pos;
  586. difficulty = new CHighlightableButtonsGroup(0);
  587. {
  588. BLOCK_CAPTURING;
  589. difficulty->addButton(new CHighlightableButton(CGI->generaltexth->zelp[24], 0, 506, 456, "GSPBUT3.DEF", 0));
  590. difficulty->addButton(new CHighlightableButton(CGI->generaltexth->zelp[25], 0, 538, 456, "GSPBUT4.DEF", 1));
  591. difficulty->addButton(new CHighlightableButton(CGI->generaltexth->zelp[26], 0, 570, 456, "GSPBUT5.DEF", 2));
  592. difficulty->addButton(new CHighlightableButton(CGI->generaltexth->zelp[27], 0, 602, 456, "GSPBUT6.DEF", 3));
  593. difficulty->addButton(new CHighlightableButton(CGI->generaltexth->zelp[28], 0, 634, 456, "GSPBUT7.DEF", 4));
  594. }
  595. }
  596. InfoCard::~InfoCard()
  597. {
  598. delete sizes;
  599. delete sFlags;
  600. }
  601. void InfoCard::showAll( SDL_Surface * to )
  602. {
  603. CIntObject::showAll(to);
  604. //blit texts
  605. printAtLoc(CGI->generaltexth->allTexts[390] + ":", 24, 400, FONT_SMALL, zwykly, to); //Allies
  606. printAtLoc(CGI->generaltexth->allTexts[391] + ":", 190, 400, FONT_SMALL, zwykly, to); //Enemies
  607. printAtLoc(CGI->generaltexth->allTexts[494], 33, 430, FONT_SMALL, tytulowy, to);//"Map Diff:"
  608. printAtLoc(CGI->generaltexth->allTexts[492] + ":", 133,430, FONT_SMALL, tytulowy, to); //player difficulty
  609. printAtLoc(CGI->generaltexth->allTexts[218] + ":", 290,430, FONT_SMALL, tytulowy, to); //"Rating:"
  610. printAtLoc(CGI->generaltexth->allTexts[495], 26, 22, FONT_SMALL, tytulowy, to); //Scenario Name:
  611. printAtLoc(CGI->generaltexth->allTexts[496], 26, 132, FONT_SMALL, tytulowy, to); //Scenario Description:
  612. printAtLoc(CGI->generaltexth->allTexts[497], 26, 283, FONT_SMALL, tytulowy, to); //Victory Condition:
  613. printAtLoc(CGI->generaltexth->allTexts[498], 26, 339, FONT_SMALL, tytulowy, to); //Loss Condition:
  614. if(curMap)
  615. {
  616. if(type != newGame)
  617. {
  618. for (int i = 0; i < difficulty->buttons.size(); i++)
  619. {
  620. if(i == curMap->difficulty)
  621. difficulty->buttons[i]->state = 3;
  622. else
  623. difficulty->buttons[i]->state = 2;
  624. difficulty->buttons[i]->showAll(to);
  625. }
  626. }
  627. int temp = curMap->victoryCondition.condition+1;
  628. if (temp>20) temp=0;
  629. std::string sss = CGI->generaltexth->victoryConditions[temp];
  630. if (temp && curMap->victoryCondition.allowNormalVictory) sss+= "/" + CGI->generaltexth->victoryConditions[0];
  631. printAtLoc(sss, 60, 307, FONT_SMALL, zwykly, to);
  632. temp = curMap->lossCondition.typeOfLossCon+1;
  633. if (temp>20) temp=0;
  634. sss = CGI->generaltexth->lossCondtions[temp];
  635. printAtLoc(sss, 60, 366, FONT_SMALL, zwykly, to);
  636. //blit description
  637. std::vector<std::string> *desc = CMessage::breakText(curMap->description,52);
  638. for (int i=0;i<desc->size();i++)
  639. printAtLoc((*desc)[i], 26, 149 + i*16, FONT_SMALL, zwykly, to);
  640. delete desc;
  641. if (curMap->name.length())
  642. printAtLoc(curMap->name, 26, 39, FONT_BIG, tytulowy, to);
  643. else
  644. printAtLoc("Unnamed", 26, 39, FONT_BIG, tytulowy, to);
  645. assert(curMap->difficulty <= 4);
  646. std::string &diff = CGI->generaltexth->arraytxt[142 + curMap->difficulty];
  647. printAtMiddleLoc(diff, 62, 472, FONT_SMALL, zwykly, to);
  648. switch (curMap->width)
  649. {
  650. case 36:
  651. temp=0;
  652. break;
  653. case 72:
  654. temp=1;
  655. break;
  656. case 108:
  657. temp=2;
  658. break;
  659. case 144:
  660. temp=3;
  661. break;
  662. default:
  663. temp=4;
  664. break;
  665. }
  666. blitAtLoc(sizes->ourImages[temp].bitmap, 318, 22, to);
  667. temp = curMap->victoryCondition.condition;
  668. if (temp>12) temp=11;
  669. blitAt(CGP->victory->ourImages[temp].bitmap, 420, 308, to); //vicotry cond descr
  670. temp=curMap->lossCondition.typeOfLossCon;
  671. if (temp>12) temp=3;
  672. blitAt(CGP->loss->ourImages[temp].bitmap, 420, 365, to); //loss cond
  673. if(type == loadGame)
  674. printToLoc(curMap->date,308,34, FONT_SMALL, zwykly, to);
  675. //print flags
  676. int fx=64, ex=244, myT;
  677. if (curMap->howManyTeams)
  678. myT = curMap->players[playerColor].team;
  679. else
  680. myT = -1;
  681. for (std::vector<PlayerSettings>::const_iterator i = curOpts->playerInfos.begin(); i != curOpts->playerInfos.end(); i++)
  682. {
  683. int *myx = ((i->color == playerColor || curMap->players[i->color].team == myT) ? &fx : &ex);
  684. blitAtLoc(sFlags->ourImages[i->color].bitmap, *myx, 399, to);
  685. *myx += sFlags->ourImages[i->color].bitmap->w;
  686. }
  687. std::string tob;
  688. switch (type != newGame ? curMap->seldiff : curOpts->difficulty)
  689. {
  690. case 0:
  691. tob="80%";
  692. break;
  693. case 1:
  694. tob="100%";
  695. break;
  696. case 2:
  697. tob="130%";
  698. break;
  699. case 3:
  700. tob="160%";
  701. break;
  702. case 4:
  703. tob="200%";
  704. break;
  705. }
  706. printAtMiddleLoc(tob, 311, 472, FONT_SMALL, zwykly, to);
  707. }
  708. }
  709. void InfoCard::changeSelection( const CMapInfo *to )
  710. {
  711. //current = to;
  712. GH.totalRedraw();
  713. }
  714. OptionsTab::OptionsTab( EState Type/*, StartInfo &Opts */)
  715. //:opts(Opts)
  716. {
  717. OBJ_CONSTRUCTION;
  718. bg = new CPicture(BitmapHandler::loadBitmap("ADVOPTBK.bmp"), 3, 6, true);
  719. pos = bg->pos;
  720. turnDuration = new CSlider(pos.x + 55, pos.y + 551, 194, bind(&OptionsTab::setTurnLength, this, _1), 1, 11, 11, true, 1);
  721. }
  722. OptionsTab::~OptionsTab()
  723. {
  724. }
  725. void OptionsTab::showAll( SDL_Surface * to )
  726. {
  727. CIntObject::showAll(to);
  728. printAtMiddleLoc(CGI->generaltexth->allTexts[515], 222, 30, FONT_BIG, tytulowy, to);
  729. printAtMiddleWBLoc(CGI->generaltexth->allTexts[516], 222, 58, FONT_SMALL, 55, zwykly, to); //Select starting options, handicap, and name for each player in the game.
  730. printAtMiddleWBLoc(CGI->generaltexth->allTexts[517], 107, 102, FONT_SMALL, 14, tytulowy, to); //Player Name Handicap Type
  731. printAtMiddleWBLoc(CGI->generaltexth->allTexts[518], 197, 102, FONT_SMALL, 10, tytulowy, to); //Starting Town
  732. printAtMiddleWBLoc(CGI->generaltexth->allTexts[519], 273, 102, FONT_SMALL, 10, tytulowy, to); //Starting Hero
  733. printAtMiddleWBLoc(CGI->generaltexth->allTexts[520], 349, 102, FONT_SMALL, 10, tytulowy, to); //Starting Bonus
  734. printAtMiddleLoc(CGI->generaltexth->allTexts[521], 222, 538, FONT_SMALL, tytulowy, to); // Player Turn Duration
  735. if(curOpts->turnTime)
  736. {
  737. std::ostringstream os;
  738. os << (int)curOpts->turnTime << " Minutes";
  739. printAtMiddleLoc(os.str(), 319,559, FONT_SMALL, zwykly, to);
  740. }
  741. else
  742. printAtMiddleLoc("Unlimited",319,559, FONT_SMALL, zwykly, to);
  743. }
  744. void OptionsTab::nextCastle( int player, int dir )
  745. {
  746. PlayerSettings &s = curOpts->playerInfos[player];
  747. si32 &cur = s.castle;
  748. ui32 allowed = curMap->players[s.color].allowedFactions;
  749. if (cur == -2) //no castle - no change
  750. return;
  751. if (cur == -1) //random => first/last available
  752. {
  753. int pom = (dir>0) ? (0) : (F_NUMBER-1); // last or first
  754. for (;pom >= 0 && pom < F_NUMBER; pom+=dir)
  755. {
  756. if((1 << pom) & allowed)
  757. {
  758. cur=pom;
  759. break;
  760. }
  761. }
  762. }
  763. else // next/previous available
  764. {
  765. for (;;)
  766. {
  767. cur+=dir;
  768. if ((1 << cur) & allowed)
  769. break;
  770. if (cur >= F_NUMBER || cur<0)
  771. {
  772. double p1 = log((double)allowed) / log(2.0f)+0.000001f;
  773. double check = p1 - ((int)p1);
  774. if (check < 0.001)
  775. cur = (int)p1;
  776. else
  777. cur = -1;
  778. break;
  779. }
  780. }
  781. }
  782. if(s.hero >= 0)
  783. s.hero = -1;
  784. if(s.bonus == bresource)
  785. s.bonus = brandom;
  786. entries[player]->selectButtons();
  787. redraw();
  788. }
  789. void OptionsTab::nextHero( int player, int dir )
  790. {
  791. PlayerSettings &s = curOpts->playerInfos[player];
  792. int old = s.hero;
  793. if (s.castle < 0 || !s.human || s.hero == -2)
  794. return;
  795. if (s.hero == -1) //random => first/last available
  796. {
  797. int max = (s.castle*HEROES_PER_TYPE*2+15),
  798. min = (s.castle*HEROES_PER_TYPE*2);
  799. s.hero = nextAllowedHero(min,max,0,dir);
  800. }
  801. else
  802. {
  803. if(dir > 0)
  804. s.hero = nextAllowedHero(s.hero,(s.castle*HEROES_PER_TYPE*2+16),1,dir);
  805. else
  806. s.hero = nextAllowedHero(s.castle*HEROES_PER_TYPE*2-1,s.hero,1,dir);
  807. }
  808. if(old != s.hero)
  809. {
  810. usedHeroes.erase(old);
  811. usedHeroes.insert(s.hero);
  812. redraw();
  813. }
  814. }
  815. int OptionsTab::nextAllowedHero( int min, int max, int incl, int dir )
  816. {
  817. if(dir>0)
  818. {
  819. for(int i=min+incl; i<=max-incl; i++)
  820. if(canUseThisHero(i))
  821. return i;
  822. }
  823. else
  824. {
  825. for(int i=max-incl; i>=min+incl; i--)
  826. if(canUseThisHero(i))
  827. return i;
  828. }
  829. return -1;
  830. }
  831. bool OptionsTab::canUseThisHero( int ID )
  832. {
  833. //for(int i=0;i<CPG->ret.playerInfos.size();i++)
  834. // if(CPG->ret.playerInfos[i].hero==ID) //hero is already taken
  835. // return false;
  836. return !vstd::contains(usedHeroes, ID) && curMap->allowedHeroes[ID];
  837. }
  838. void OptionsTab::nextBonus( int player, int dir )
  839. {
  840. PlayerSettings &s = curOpts->playerInfos[player];
  841. si8 &ret = s.bonus += dir;
  842. if (s.hero==-2 && !curMap->players[s.color].heroesNames.size() && ret==bartifact) //no hero - can't be artifact
  843. {
  844. if (dir<0)
  845. ret=brandom;
  846. else ret=bgold;
  847. }
  848. if(ret > bresource)
  849. ret = brandom;
  850. if(ret < brandom)
  851. ret = bresource;
  852. if (s.castle==-1 && ret==bresource) //random castle - can't be resource
  853. {
  854. if (dir<0)
  855. ret=bgold;
  856. else ret=brandom;
  857. }
  858. redraw();
  859. }
  860. void OptionsTab::changeSelection( const CMapInfo *to )
  861. {
  862. for(int i = 0; i < entries.size(); i++)
  863. {
  864. children -= entries[i];
  865. delete entries[i];
  866. }
  867. entries.clear();
  868. usedHeroes.clear();
  869. OBJ_CONSTRUCTION;
  870. for(int i = 0; i < curOpts->playerInfos.size(); i++)
  871. {
  872. entries.push_back(new PlayerOptionsEntry(this, curOpts->playerInfos[i]));
  873. const std::vector<SheroName> &heroes = curMap->players[curOpts->playerInfos[i].color].heroesNames;
  874. for(size_t hi=0; hi<heroes.size(); hi++)
  875. usedHeroes.insert(heroes[hi].heroID);
  876. }
  877. }
  878. void OptionsTab::setTurnLength( int npos )
  879. {
  880. static const int times[] = {1, 2, 4, 6, 8, 10, 15, 20, 25, 30, 0};
  881. amin(npos, ARRAY_COUNT(times) - 1);
  882. curOpts->turnTime = times[npos];
  883. redraw();
  884. }
  885. void OptionsTab::flagPressed( int player )
  886. {
  887. int playerSerial = playerColor; //curMap->players[playerColor].serial;
  888. PlayerSettings &s = curOpts->playerInfos[player],
  889. &old = curOpts->playerInfos[playerSerial];
  890. std::swap(old.human, s.human);
  891. std::swap(old.name, s.name);
  892. playerColor = s.color;
  893. if(!entries[playerSerial]->fixedHero)
  894. old.hero = -1;
  895. entries[s.serial]->selectButtons();
  896. entries[old.serial]->selectButtons();
  897. GH.totalRedraw();
  898. }
  899. OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry( OptionsTab *owner, PlayerSettings &S)
  900. :s(S)
  901. {
  902. OBJ_CONSTRUCTION;
  903. defActions |= SHARE_POS;
  904. pos = parent->pos + Point(54, 122 + s.serial*50);
  905. static const char *flags[] = {"AOFLGBR.DEF", "AOFLGBB.DEF", "AOFLGBY.DEF", "AOFLGBG.DEF",
  906. "AOFLGBO.DEF", "AOFLGBP.DEF", "AOFLGBT.DEF", "AOFLGBS.DEF"};
  907. static const char *bgs[] = {"ADOPRPNL.bmp", "ADOPBPNL.bmp", "ADOPYPNL.bmp", "ADOPGPNL.bmp",
  908. "ADOPOPNL.bmp", "ADOPPPNL.bmp", "ADOPTPNL.bmp", "ADOPSPNL.bmp"};
  909. bg = new CPicture(BitmapHandler::loadBitmap(bgs[s.color]), 0, 0, true);
  910. btns[0] = new AdventureMapButton(CGI->generaltexth->zelp[132], bind(&OptionsTab::nextCastle, owner, s.serial, -1), 107, 5, "ADOPLFA.DEF");
  911. btns[1] = new AdventureMapButton(CGI->generaltexth->zelp[133], bind(&OptionsTab::nextCastle, owner, s.serial, +1), 168, 5, "ADOPRTA.DEF");
  912. btns[2] = new AdventureMapButton(CGI->generaltexth->zelp[148], bind(&OptionsTab::nextHero, owner, s.serial, -1), 183, 5, "ADOPLFA.DEF");
  913. btns[3] = new AdventureMapButton(CGI->generaltexth->zelp[149], bind(&OptionsTab::nextHero, owner, s.serial, +1), 244, 5, "ADOPRTA.DEF");
  914. btns[4] = new AdventureMapButton(CGI->generaltexth->zelp[164], bind(&OptionsTab::nextBonus, owner, s.serial, -1), 259, 5, "ADOPLFA.DEF");
  915. btns[5] = new AdventureMapButton(CGI->generaltexth->zelp[165], bind(&OptionsTab::nextBonus, owner, s.serial, +1), 320, 5, "ADOPRTA.DEF");
  916. fixedHero = s.hero != -1; //if we doesn't start with "random hero" it must be fixed or none
  917. selectButtons(false);
  918. if(curMap->players[s.color].canHumanPlay)
  919. {
  920. flag = new AdventureMapButton(CGI->generaltexth->zelp[180], bind(&OptionsTab::flagPressed, owner, s.serial), -43, 2, flags[s.color]);
  921. flag->hoverable = true;
  922. }
  923. else
  924. flag = NULL;
  925. town = new SelectedBox(TOWN, s.serial);
  926. town->pos = pos + Point(119, 2);
  927. hero = new SelectedBox(HERO, s.serial);
  928. hero->pos = pos + Point(195, 2);
  929. bonus = new SelectedBox(BONUS, s.serial);
  930. bonus->pos = pos + Point(271, 2);
  931. }
  932. void OptionsTab::PlayerOptionsEntry::showAll( SDL_Surface * to )
  933. {
  934. CIntObject::showAll(to);
  935. printAtMiddleLoc(s.name, 55, 10, FONT_SMALL, zwykly, to);
  936. }
  937. void OptionsTab::PlayerOptionsEntry::selectButtons(bool onlyHero)
  938. {
  939. if(!onlyHero && s.castle != -1)
  940. {
  941. btns[0]->disable();
  942. btns[1]->disable();
  943. }
  944. if(fixedHero || !s.human || s.castle < 0)
  945. {
  946. btns[2]->disable();
  947. btns[3]->disable();
  948. }
  949. else
  950. {
  951. btns[2]->enable(active);
  952. btns[3]->enable(active);
  953. }
  954. }
  955. void OptionsTab::SelectedBox::showAll( SDL_Surface * to )
  956. {
  957. PlayerSettings &s = curOpts->playerInfos[player];
  958. SDL_Surface *toBlit = NULL;
  959. const std::string *toPrint = NULL;
  960. switch(which)
  961. {
  962. case TOWN:
  963. {
  964. if (s.castle < F_NUMBER && s.castle >= 0)
  965. {
  966. toBlit = graphics->getPic(s.castle, true, false);
  967. toPrint = &CGI->townh->towns[s.castle].Name();
  968. }
  969. else if (s.castle == -1)
  970. {
  971. toBlit = CGP->rTown;
  972. toPrint = &CGI->generaltexth->allTexts[522];
  973. }
  974. else if (s.castle == -2)
  975. {
  976. toBlit = CGP->nTown;
  977. toPrint = &CGI->generaltexth->allTexts[523];
  978. }
  979. }
  980. break;
  981. case HERO:
  982. {
  983. if (s.hero == -1)
  984. {
  985. toBlit = CGP->rHero;
  986. toPrint = &CGI->generaltexth->allTexts[522];
  987. }
  988. else if (s.hero == -2)
  989. {
  990. if(s.heroPortrait >= 0)
  991. {
  992. toBlit = graphics->portraitSmall[s.heroPortrait];
  993. if(s.heroName.length())
  994. toPrint = &s.heroName;
  995. else
  996. toPrint = &CGI->heroh->heroes[s.heroPortrait]->name;
  997. }
  998. else
  999. {
  1000. toBlit = CGP->nHero;
  1001. toPrint = &CGI->generaltexth->allTexts[523];
  1002. }
  1003. }
  1004. else
  1005. {
  1006. toBlit = graphics->portraitSmall[s.hero];
  1007. toPrint = &s.heroName;
  1008. }
  1009. }
  1010. break;
  1011. case BONUS:
  1012. {
  1013. int pom;
  1014. toPrint = &CGI->generaltexth->arraytxt[214 + s.bonus];
  1015. switch (s.bonus)
  1016. {
  1017. case -1:
  1018. pom=10;
  1019. toPrint = &CGI->generaltexth->allTexts[522];
  1020. break;
  1021. case 0:
  1022. pom=9;
  1023. break;
  1024. case 1:
  1025. pom=8;
  1026. break;
  1027. case 2:
  1028. pom=CGI->townh->towns[s.castle].bonus;
  1029. break;
  1030. }
  1031. toBlit = CGP->bonuses->ourImages[pom].bitmap;
  1032. }
  1033. break;
  1034. }
  1035. blitAt(toBlit, pos, to);
  1036. printAtMiddleLoc(*toPrint, 23, 39, FONT_TINY, zwykly, to);
  1037. }
  1038. OptionsTab::SelectedBox::SelectedBox( SelType Which, ui8 Player )
  1039. :which(Which), player(Player)
  1040. {
  1041. }