CPreGame.cpp 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347
  1. #include "../stdafx.h"
  2. #include "CPreGame.h"
  3. #include <ctime>
  4. #include <boost/filesystem.hpp> // includes all needed Boost.Filesystem declarations
  5. #include <boost/algorithm/string.hpp>
  6. #include <zlib.h>
  7. #include "../timeHandler.h"
  8. #include <sstream>
  9. #include "SDL_Extensions.h"
  10. #include "CGameInfo.h"
  11. #include "CCursorHandler.h"
  12. #include "../hch/CDefHandler.h"
  13. #include "../hch/CGeneralTextHandler.h"
  14. #include "../hch/CLodHandler.h"
  15. #include "../hch/CTownHandler.h"
  16. #include "../hch/CHeroHandler.h"
  17. #include "../hch/CObjectHandler.h"
  18. #include "../hch/CCampaignHandler.h"
  19. #include "../hch/CCreatureHandler.h"
  20. #include "../hch/CMusicHandler.h"
  21. #include "../hch/CVideoHandler.h"
  22. #include <cmath>
  23. #include "Graphics.h"
  24. //#include <boost/thread.hpp>
  25. #include <boost/bind.hpp>
  26. #include <cstdlib>
  27. #include "../lib/Connection.h"
  28. #include "../lib/VCMIDirs.h"
  29. #include "../lib/map.h"
  30. #include "AdventureMapButton.h"
  31. #include "GUIClasses.h"
  32. #include "CPlayerInterface.h"
  33. #include "../CCallback.h"
  34. #include <boost/lexical_cast.hpp>
  35. #include <cstdlib>
  36. #include "CMessage.h"
  37. /*
  38. * CPreGame.cpp, part of VCMI engine
  39. *
  40. * Authors: listed in file AUTHORS in main folder
  41. *
  42. * License: GNU General Public License v2.0 or later
  43. * Full text of license available in license.txt file, in main folder
  44. *
  45. */
  46. namespace fs = boost::filesystem;
  47. using boost::bind;
  48. using boost::ref;
  49. void startGame(StartInfo * options);
  50. CGPreGame * CGP;
  51. static const CMapInfo *curMap;
  52. static StartInfo *curOpts;
  53. static int playerColor, playerSerial; //if more than one player - applies to the first
  54. static std::vector<std::string> playerNames; // serial id of name <-> player name
  55. static std::string selectedName; //set when game is started/loaded
  56. static void do_quit()
  57. {
  58. SDL_Event event;
  59. event.quit.type = SDL_QUIT;
  60. SDL_PushEvent(&event);
  61. }
  62. void CMapInfo::countPlayers()
  63. {
  64. playerAmnt = humenPlayers = 0;
  65. for(int i=0;i<PLAYER_LIMIT;i++)
  66. {
  67. if(mapHeader->players[i].canHumanPlay)
  68. {
  69. playerAmnt++;
  70. humenPlayers++;
  71. }
  72. else if(mapHeader->players[i].canComputerPlay)
  73. {
  74. playerAmnt++;
  75. }
  76. }
  77. }
  78. //CMapInfo::CMapInfo(const std::string &fname, const unsigned char *map )
  79. //: mapHeader(NULL), campaignHeader(NULL)
  80. //{
  81. // init(fname, map);
  82. //}
  83. CMapInfo::CMapInfo(bool map)
  84. : mapHeader(NULL), campaignHeader(NULL)
  85. {
  86. }
  87. void CMapInfo::mapInit(const std::string &fname, const unsigned char *map )
  88. {
  89. filename = fname;
  90. int i = 0;
  91. mapHeader = new CMapHeader();
  92. mapHeader->version = CMapHeader::invalid;
  93. mapHeader->initFromMemory(map, i);
  94. countPlayers();
  95. }
  96. CMapInfo::~CMapInfo()
  97. {
  98. delete mapHeader;
  99. delete campaignHeader;
  100. }
  101. void CMapInfo::campaignInit()
  102. {
  103. campaignHeader = new CCampaignHeader( CCampaignHandler::getHeader(filename, lodCmpgn) );
  104. }
  105. CMenuScreen::CMenuScreen( EState which )
  106. {
  107. OBJ_CONSTRUCTION;
  108. bgAd = NULL;
  109. switch(which)
  110. {
  111. case mainMenu:
  112. {
  113. buttons[0] = new AdventureMapButton("", CGI->generaltexth->zelp[3].second, bind(&CMenuScreen::moveTo, this, ref(CGP->scrs[newGame])), 540, 10, "ZMENUNG.DEF", SDLK_n);
  114. buttons[1] = new AdventureMapButton("", CGI->generaltexth->zelp[4].second, bind(&CMenuScreen::moveTo, this, ref(CGP->scrs[loadGame])), 532, 132, "ZMENULG.DEF", SDLK_l);
  115. buttons[2] = new AdventureMapButton("", CGI->generaltexth->zelp[5].second, 0, 524, 251, "ZMENUHS.DEF", SDLK_h);
  116. buttons[3] = new AdventureMapButton("", CGI->generaltexth->zelp[6].second, 0 /*cb*/, 557, 359, "ZMENUCR.DEF", SDLK_c);
  117. boost::function<void()> confWindow = bind(CInfoWindow::showYesNoDialog, ref(CGI->generaltexth->allTexts[69]), (const std::vector<SComponent*>*)0, do_quit, 0, false, 1);
  118. buttons[4] = new AdventureMapButton("", CGI->generaltexth->zelp[7].second, confWindow, 586, 468, "ZMENUQT.DEF", SDLK_ESCAPE);
  119. }
  120. break;
  121. case newGame:
  122. {
  123. bgAd = new CPicture(BitmapHandler::loadBitmap("ZNEWGAM.bmp"), 114, 312, true);
  124. buttons[0] = new AdventureMapButton("", CGI->generaltexth->zelp[10].second, bind(&CGPreGame::openSel, CGP, newGame), 545, 4, "ZTSINGL.DEF", SDLK_s);
  125. buttons[1] = new AdventureMapButton("", CGI->generaltexth->zelp[11].second, &pushIntT<CMultiMode>, 568, 120, "ZTMULTI.DEF", SDLK_m);
  126. buttons[2] = new AdventureMapButton("", CGI->generaltexth->zelp[12].second, bind(&CMenuScreen::moveTo, this, ref(CGP->scrs[campaignMain])), 541, 233, "ZTCAMPN.DEF", SDLK_c);
  127. buttons[3] = new AdventureMapButton("", CGI->generaltexth->zelp[13].second, 0 /*cb*/, 545, 358, "ZTTUTOR.DEF", SDLK_t);
  128. buttons[4] = new AdventureMapButton("", CGI->generaltexth->zelp[14].second, bind(&CMenuScreen::moveTo, this, CGP->scrs[mainMenu]), 582, 464, "ZTBACK.DEF", SDLK_ESCAPE);
  129. }
  130. break;
  131. case loadGame:
  132. {
  133. bgAd = new CPicture(BitmapHandler::loadBitmap("ZLOADGAM.bmp"), 114, 312, true);
  134. buttons[0] = new AdventureMapButton("", CGI->generaltexth->zelp[10].second, bind(&CGPreGame::openSel, CGP, loadGame), 545, 4, "ZTSINGL.DEF", SDLK_s);
  135. buttons[1] = new AdventureMapButton("", CGI->generaltexth->zelp[11].second, 0 /*cb*/, 568, 120, "ZTMULTI.DEF", SDLK_m);
  136. buttons[2] = new AdventureMapButton("", CGI->generaltexth->zelp[12].second, 0 /*cb*/, 541, 233, "ZTCAMPN.DEF", SDLK_c);
  137. buttons[3] = new AdventureMapButton("", CGI->generaltexth->zelp[13].second, 0 /*cb*/, 545, 358, "ZTTUTOR.DEF", SDLK_t);
  138. buttons[4] = new AdventureMapButton("", CGI->generaltexth->zelp[14].second, bind(&CMenuScreen::moveTo, this, CGP->scrs[mainMenu]), 582, 464, "ZTBACK.DEF", SDLK_ESCAPE);
  139. }
  140. break;
  141. case campaignMain:
  142. {
  143. buttons[0] = new AdventureMapButton("", "", 0 /*cb*/, 535, 8, "ZSSSOD.DEF", SDLK_s);
  144. buttons[1] = new AdventureMapButton("", "", 0 /*cb*/, 494, 117, "ZSSROE.DEF", SDLK_m);
  145. buttons[2] = new AdventureMapButton("", "", 0 /*cb*/, 486, 241, "ZSSARM.DEF", SDLK_c);
  146. buttons[3] = new AdventureMapButton("", "", bind(&CGPreGame::openSel, CGP, campaignList), 550, 358, "ZSSCUS.DEF", SDLK_t);
  147. buttons[4] = new AdventureMapButton("", "", bind(&CMenuScreen::moveTo, this, CGP->scrs[newGame]), 582, 464, "ZSSEXIT.DEF", SDLK_ESCAPE);
  148. }
  149. break;
  150. }
  151. for(int i = 0; i < ARRAY_COUNT(buttons); i++)
  152. buttons[i]->hoverable = true;
  153. }
  154. CMenuScreen::~CMenuScreen()
  155. {
  156. }
  157. void CMenuScreen::showAll( SDL_Surface * to )
  158. {
  159. blitAt(CGP->mainbg, 0, 0, to);
  160. CIntObject::showAll(to);
  161. }
  162. void CMenuScreen::show( SDL_Surface * to )
  163. {
  164. CIntObject::show(to);
  165. CGI->videoh->update(pos.x + 8, pos.y + 105, screen, true, false);
  166. }
  167. void CMenuScreen::moveTo( CMenuScreen *next )
  168. {
  169. GH.popInt(this);
  170. GH.pushInt(next);
  171. }
  172. CGPreGame::CGPreGame()
  173. {
  174. GH.defActionsDef = 63;
  175. CGP = this;
  176. mainbg = BitmapHandler::loadBitmap("ZPIC1005.bmp");
  177. for(int i = 0; i < ARRAY_COUNT(scrs); i++)
  178. scrs[i] = new CMenuScreen((CMenuScreen::EState)i);
  179. }
  180. CGPreGame::~CGPreGame()
  181. {
  182. SDL_FreeSurface(mainbg);
  183. for(int i = 0; i < ARRAY_COUNT(scrs); i++)
  184. delete scrs[i];
  185. }
  186. void CGPreGame::openSel( CMenuScreen::EState type )
  187. {
  188. playerNames.push_back(CGI->generaltexth->allTexts[434]); //we have only one player and his name is "Player"
  189. GH.pushInt(new CSelectionScreen(type));
  190. }
  191. void CGPreGame::loadGraphics()
  192. {
  193. victory = CDefHandler::giveDef("SCNRVICT.DEF");
  194. loss = CDefHandler::giveDef("SCNRLOSS.DEF");
  195. bonuses = CDefHandler::giveDef("SCNRSTAR.DEF");
  196. rHero = BitmapHandler::loadBitmap("HPSRAND1.bmp");
  197. rTown = BitmapHandler::loadBitmap("HPSRAND0.bmp");
  198. nHero = BitmapHandler::loadBitmap("HPSRAND6.bmp");
  199. nTown = BitmapHandler::loadBitmap("HPSRAND5.bmp");
  200. }
  201. void CGPreGame::disposeGraphics()
  202. {
  203. delete victory;
  204. delete loss;
  205. SDL_FreeSurface(rHero);
  206. SDL_FreeSurface(nHero);
  207. SDL_FreeSurface(rTown);
  208. SDL_FreeSurface(nTown);
  209. }
  210. void CGPreGame::update()
  211. {
  212. if (GH.listInt.size() == 0)
  213. {
  214. #ifdef _WIN32
  215. CGI->videoh->open("ACREDIT.SMK");
  216. #else
  217. CGI->videoh->open("ACREDIT.SMK", true, false);
  218. #endif
  219. GH.pushInt(scrs[CMenuScreen::mainMenu]);
  220. }
  221. CGI->curh->draw1();
  222. SDL_Flip(screen);
  223. CGI->curh->draw2();
  224. GH.topInt()->show(screen);
  225. GH.updateTime();
  226. GH.handleEvents();
  227. }
  228. CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type)
  229. {
  230. OBJ_CONSTRUCTION_CAPTURING_ALL;
  231. IShowActivable::type = BLOCK_ADV_HOTKEYS;
  232. pos.w = 762;
  233. pos.h = 584;
  234. if(Type == CMenuScreen::saveGame)
  235. {
  236. center(pos);
  237. }
  238. else if(Type == CMenuScreen::campaignList)
  239. {
  240. bg = new CPicture(BitmapHandler::loadBitmap("CamCust.bmp"), 0, 0, true);
  241. pos.x = 3;
  242. pos.y = 6;
  243. }
  244. else
  245. {
  246. pos.x = 3;
  247. pos.y = 6;
  248. bg = new CPicture(BitmapHandler::loadBitmap(rand()%2 ? "ZPIC1000.bmp" : "ZPIC1001.bmp"), -3, -6, true);
  249. }
  250. CGP->loadGraphics();
  251. type = Type;
  252. curOpts = &sInfo;
  253. sInfo.difficulty = 1;
  254. current = NULL;
  255. sInfo.mode = (Type == CMenuScreen::newGame ? 0 : 1);
  256. sInfo.turnTime = 0;
  257. curTab = NULL;
  258. card = new InfoCard(type); //right info card
  259. if (type == CMenuScreen::campaignList)
  260. {
  261. opt = NULL;
  262. }
  263. else
  264. {
  265. opt = new OptionsTab(type/*, sInfo*/); //scenario options tab
  266. opt->recActions = DISPOSE;
  267. }
  268. sel = new SelectionTab(type, bind(&CSelectionScreen::changeSelection, this, _1)); //scenario selection tab
  269. sel->recActions = DISPOSE;
  270. switch(type)
  271. {
  272. case CMenuScreen::newGame:
  273. {
  274. card->difficulty->onChange = bind(&CSelectionScreen::difficultyChange, this, _1);
  275. card->difficulty->select(1, 0);
  276. AdventureMapButton *select = new AdventureMapButton(CGI->generaltexth->zelp[45], bind(&CSelectionScreen::toggleTab, this, sel), 411, 75, "GSPBUTT.DEF", SDLK_s);
  277. select->addTextOverlay(CGI->generaltexth->allTexts[500], FONT_SMALL);
  278. AdventureMapButton *opts = new AdventureMapButton(CGI->generaltexth->zelp[46], bind(&CSelectionScreen::toggleTab, this, opt), 411, 503, "GSPBUTT.DEF", SDLK_a);
  279. opts->addTextOverlay(CGI->generaltexth->allTexts[501], FONT_SMALL);
  280. AdventureMapButton *random = new AdventureMapButton(CGI->generaltexth->zelp[47], bind(&CSelectionScreen::toggleTab, this, sel), 411, 99, "GSPBUTT.DEF", SDLK_r);
  281. random->addTextOverlay(CGI->generaltexth->allTexts[740], FONT_SMALL);
  282. start = new AdventureMapButton(CGI->generaltexth->zelp[103], bind(&CSelectionScreen::startGame, this), 411, 529, "SCNRBEG.DEF", SDLK_b);
  283. }
  284. break;
  285. case CMenuScreen::loadGame:
  286. sel->recActions = 255;
  287. start = new AdventureMapButton(CGI->generaltexth->zelp[103], bind(&CSelectionScreen::startGame, this), 411, 529, "SCNRLOD.DEF", SDLK_l);
  288. break;
  289. case CMenuScreen::saveGame:
  290. sel->recActions = 255;
  291. start = new AdventureMapButton("", CGI->generaltexth->zelp[103].second, bind(&CSelectionScreen::startGame, this), 411, 529, "SCNRSAV.DEF");
  292. break;
  293. case CMenuScreen::campaignList:
  294. sel->recActions = 255;
  295. start = new AdventureMapButton(std::pair<std::string, std::string>(), bind(&CSelectionScreen::startCampaign, this), 411, 529, "SCNRLOD.DEF", SDLK_b);
  296. break;
  297. }
  298. start->assignedKeys.insert(SDLK_RETURN);
  299. std::string backName;
  300. if(Type == CMenuScreen::campaignList)
  301. {
  302. backName = "SCNRBACK.DEF";
  303. }
  304. else
  305. {
  306. backName = "SCNRBACK.DEF";
  307. }
  308. back = new AdventureMapButton("", CGI->generaltexth->zelp[105].second, bind(&CGuiHandler::popIntTotally, &GH, this), 581, 529, backName, SDLK_ESCAPE);
  309. }
  310. CSelectionScreen::~CSelectionScreen()
  311. {
  312. curMap = NULL;
  313. curOpts = NULL;
  314. playerSerial = playerColor = -1;
  315. playerNames.clear();
  316. }
  317. void CSelectionScreen::toggleTab(CIntObject *tab)
  318. {
  319. if(curTab && curTab->active)
  320. {
  321. curTab->deactivate();
  322. curTab->recActions = DISPOSE;
  323. }
  324. if(curTab != tab)
  325. {
  326. tab->recActions = 255;
  327. tab->activate();
  328. curTab = tab;
  329. }
  330. else
  331. {
  332. curTab = NULL;
  333. };
  334. GH.totalRedraw();
  335. }
  336. void CSelectionScreen::changeSelection( const CMapInfo *to )
  337. {
  338. curMap = current = to;;
  339. if(to && type == CMenuScreen::loadGame)
  340. curOpts->difficulty = to->seldiff;
  341. if(type != CMenuScreen::campaignList)
  342. {
  343. updateStartInfo(to, sInfo, to->mapHeader);
  344. }
  345. card->changeSelection(to);
  346. if(type != CMenuScreen::campaignList)
  347. {
  348. opt->changeSelection(to->mapHeader);
  349. }
  350. }
  351. void setPlayer(PlayerSettings &pset, unsigned player)
  352. {
  353. if(player < playerNames.size())
  354. {
  355. pset.name = playerNames[player];
  356. pset.human = true;
  357. if(playerColor < 0)
  358. {
  359. playerColor = pset.color;
  360. playerSerial = pset.serial;
  361. }
  362. }
  363. else
  364. {
  365. pset.name = CGI->generaltexth->allTexts[468];//Computer
  366. pset.human = false;
  367. }
  368. }
  369. void CSelectionScreen::updateStartInfo( const CMapInfo * to, StartInfo & sInfo, const CMapHeader * mapHeader )
  370. {
  371. sInfo.playerInfos.clear();
  372. if(!to)
  373. return;
  374. sInfo.playerInfos.resize(to->playerAmnt);
  375. sInfo.mapname = to->filename;
  376. playerSerial = playerColor = -1;
  377. ui8 placedPlayers = 0;
  378. int serialC=0;
  379. for (int i = 0; i < PLAYER_LIMIT; i++)
  380. {
  381. const PlayerInfo &pinfo = mapHeader->players[i];
  382. //neither computer nor human can play - no player
  383. if (!(pinfo.canComputerPlay || pinfo.canComputerPlay))
  384. continue;
  385. PlayerSettings &pset = sInfo.playerInfos[serialC];
  386. pset.color = i;
  387. pset.serial = serialC++;
  388. setPlayer(pset, placedPlayers++);
  389. 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
  390. {
  391. if((1 << j) & pinfo.allowedFactions)
  392. {
  393. if (pset.castle >= 0) //we've already assigned a castle and another one is possible -> set random and let player choose
  394. pset.castle = -1; //breaks
  395. if (pset.castle == -2) //first available castle - pick
  396. pset.castle = j;
  397. }
  398. }
  399. if ((pinfo.generateHeroAtMainTown || mapHeader->version==CMapHeader::RoE) && pinfo.hasMainTown //we will generate hero in front of main town
  400. || pinfo.p8) //random hero
  401. pset.hero = -1;
  402. else
  403. pset.hero = -2;
  404. if(pinfo.mainHeroName.length())
  405. {
  406. pset.heroName = pinfo.mainHeroName;
  407. if((pset.heroPortrait = pinfo.mainHeroPortrait) == 255)
  408. pset.heroPortrait = pinfo.p9;
  409. }
  410. pset.handicap = 0;
  411. }
  412. }
  413. void CSelectionScreen::startCampaign()
  414. {
  415. CCampaign * ourCampaign = CCampaignHandler::getCampaign(curMap->filename, curMap->lodCmpgn);
  416. GH.pushInt( new CBonusSelection(ourCampaign, 0) );
  417. }
  418. void CSelectionScreen::startGame()
  419. {
  420. if(type != CMenuScreen::saveGame)
  421. {
  422. if(!current)
  423. return;
  424. selectedName = sInfo.mapname;
  425. StartInfo *si = new StartInfo(sInfo);
  426. GH.popInt(this);
  427. GH.popInt(GH.topInt());
  428. curMap = NULL;
  429. curOpts = NULL;
  430. ::startGame(si);
  431. }
  432. else
  433. {
  434. if(!(sel && sel->txt && sel->txt->text.size()))
  435. return;
  436. selectedName = GVCMIDirs.UserPath + "/Games/" + sel->txt->text + ".vlgm1";
  437. LOCPLINT->cb->save(sel->txt->text);
  438. GH.popInt(this);
  439. }
  440. }
  441. void CSelectionScreen::difficultyChange( int to )
  442. {
  443. assert(type == CMenuScreen::newGame);
  444. sInfo.difficulty = to;
  445. GH.totalRedraw();
  446. }
  447. // A new size filter (Small, Medium, ...) has been selected. Populate
  448. // selMaps with the relevant data.
  449. void SelectionTab::filter( int size, bool selectFirst )
  450. {
  451. curItems.clear();
  452. if(tabType == CMenuScreen::campaignList)
  453. {
  454. for (size_t i=0; i<allItems.size(); i++)
  455. curItems.push_back(&allItems[i]);
  456. }
  457. else
  458. {
  459. for (size_t i=0; i<allItems.size(); i++)
  460. if( allItems[i].mapHeader && allItems[i].mapHeader->version && (!size || allItems[i].mapHeader->width == size))
  461. curItems.push_back(&allItems[i]);
  462. }
  463. if(curItems.size())
  464. {
  465. slider->block(false);
  466. slider->setAmount(curItems.size());
  467. sort();
  468. if(selectFirst)
  469. {
  470. slider->moveTo(0);
  471. onSelect(curItems[0]);
  472. }
  473. selectAbs(0);
  474. }
  475. else
  476. {
  477. slider->block(true);
  478. onSelect(NULL);
  479. }
  480. }
  481. void SelectionTab::getFiles(std::vector<FileInfo> &out, const std::string &dirname, const std::string &ext)
  482. {
  483. if(!boost::filesystem::exists(dirname))
  484. {
  485. tlog1 << "Cannot find " << dirname << " directory!\n";
  486. }
  487. fs::path tie(dirname);
  488. fs::directory_iterator end_iter;
  489. for ( fs::directory_iterator file (tie); file!=end_iter; ++file )
  490. {
  491. if(fs::is_regular_file(file->status())
  492. && boost::ends_with(file->path().filename(), ext))
  493. {
  494. out.resize(out.size()+1);
  495. out.back().date = fs::last_write_time(file->path());
  496. out.back().name = file->path().string();
  497. }
  498. }
  499. allItems.resize(out.size());
  500. }
  501. void SelectionTab::parseMaps(std::vector<FileInfo> &files, int start, int threads)
  502. {
  503. int read=0;
  504. unsigned char mapBuffer[1500];
  505. while(start < allItems.size())
  506. {
  507. gzFile tempf = gzopen(files[start].name.c_str(),"rb");
  508. read = gzread(tempf, mapBuffer, 1500);
  509. gzclose(tempf);
  510. if(read < 50 || !mapBuffer[4])
  511. {
  512. tlog3 << "\t\tWarning: corrupted map file: " << files[start].name << std::endl;
  513. }
  514. else //valid map
  515. {
  516. allItems[start].mapInit(files[start].name, mapBuffer);
  517. //allItems[start].date = "DATEDATE";// files[start].date;
  518. }
  519. start += threads;
  520. }
  521. }
  522. void SelectionTab::parseGames(std::vector<FileInfo> &files)
  523. {
  524. for(int i=0; i<files.size(); i++)
  525. {
  526. CLoadFile lf(files[i].name);
  527. if(!lf.sfile)
  528. continue;
  529. ui8 sign[8];
  530. lf >> sign;
  531. if(std::memcmp(sign,"VCMISVG",7))
  532. {
  533. tlog1 << files[i].name << " is not a correct savefile!" << std::endl;
  534. continue;
  535. }
  536. allItems[i].mapHeader = new CMapHeader();
  537. lf >> *(allItems[i].mapHeader) >> allItems[i].seldiff;
  538. allItems[i].filename = files[i].name;
  539. allItems[i].countPlayers();
  540. allItems[i].date = std::asctime(std::localtime(&files[i].date));
  541. }
  542. }
  543. void SelectionTab::parseCampaigns( std::vector<FileInfo> & files )
  544. {
  545. for(int i=0; i<files.size(); i++)
  546. {
  547. //allItems[i].date = std::asctime(std::localtime(&files[i].date));
  548. allItems[i].filename = files[i].name;
  549. allItems[i].lodCmpgn = files[i].inLod;
  550. allItems[i].campaignInit();
  551. }
  552. }
  553. SelectionTab::SelectionTab(CMenuScreen::EState Type, const boost::function<void(CMapInfo *)> &OnSelect)
  554. :onSelect(OnSelect), bg(NULL)
  555. {
  556. OBJ_CONSTRUCTION;
  557. selectionPos = 0;
  558. used = LCLICK | WHEEL | KEYBOARD | DOUBLECLICK;
  559. slider = NULL;
  560. txt = NULL;
  561. tabType = Type;
  562. if (Type != CMenuScreen::campaignList)
  563. {
  564. bg = new CPicture(BitmapHandler::loadBitmap("SCSELBCK.bmp"), 0, 0, true);
  565. pos.w = bg->pos.w;
  566. pos.h = bg->pos.h;
  567. }
  568. else
  569. {
  570. SDL_Surface * tmp1 = BitmapHandler::loadBitmap("CAMCUST.bmp");
  571. SDL_Surface * tmp = CSDL_Ext::newSurface(400, tmp1->h);
  572. blitAt(tmp1, 0, 0, tmp);
  573. SDL_FreeSurface(tmp1);
  574. bg = new CPicture(tmp, 0, 0, true);
  575. pos.w = bg->pos.w;
  576. pos.h = bg->pos.h;
  577. bg->pos.x = bg->pos.y = 0;
  578. }
  579. std::vector<FileInfo> toParse;
  580. std::vector<CCampaignHeader> cpm;
  581. switch(tabType)
  582. {
  583. case CMenuScreen::newGame:
  584. getFiles(toParse, DATA_DIR "/Maps", "h3m"); //get all maps
  585. parseMaps(toParse);
  586. positions = 18;
  587. break;
  588. case CMenuScreen::loadGame:
  589. case CMenuScreen::saveGame:
  590. getFiles(toParse, GVCMIDirs.UserPath + "/Games", "vlgm1"); //get all saves
  591. parseGames(toParse);
  592. if(tabType == CMenuScreen::loadGame)
  593. {
  594. positions = 18;
  595. }
  596. else
  597. {
  598. positions = 16;
  599. }
  600. if(tabType == CMenuScreen::saveGame)
  601. txt = new CTextInput(Rect(32, 539, 350, 20), Point(-32, -25), "GSSTRIP.bmp", 0);
  602. break;
  603. case CMenuScreen::campaignList:
  604. getFiles(toParse, DATA_DIR "/Maps", "h3c"); //get all campaigns
  605. for (int g=0; g<toParse.size(); ++g)
  606. {
  607. toParse[g].inLod = false;
  608. }
  609. //add lod cmpgns
  610. cpm = CCampaignHandler::getCampaignHeaders(CCampaignHandler::ALL);
  611. for (int g = 0; g < cpm.size(); g++)
  612. {
  613. FileInfo fi;
  614. fi.inLod = cpm[g].loadFromLod;
  615. fi.name = cpm[g].filename;
  616. toParse.push_back(fi);
  617. if (cpm[g].loadFromLod)
  618. {
  619. allItems.push_back(CMapInfo(false));
  620. }
  621. }
  622. parseCampaigns(toParse);
  623. positions = 18;
  624. break;
  625. default:
  626. assert(0);
  627. break;
  628. }
  629. if (tabType != CMenuScreen::campaignList)
  630. {
  631. //size filter buttons
  632. {
  633. int sizes[] = {36, 72, 108, 144, 0};
  634. const char * names[] = {"SCSMBUT.DEF", "SCMDBUT.DEF", "SCLGBUT.DEF", "SCXLBUT.DEF", "SCALBUT.DEF"};
  635. for(int i = 0; i < 5; i++)
  636. new AdventureMapButton("", CGI->generaltexth->zelp[54+i].second, bind(&SelectionTab::filter, this, sizes[i], true), 158 + 47*i, 46, names[i]);
  637. }
  638. //sort buttons buttons
  639. {
  640. int xpos[] = {23, 55, 88, 121, 306, 339};
  641. const char * names[] = {"SCBUTT1.DEF", "SCBUTT2.DEF", "SCBUTCP.DEF", "SCBUTT3.DEF", "SCBUTT4.DEF", "SCBUTT5.DEF"};
  642. for(int i = 0; i < 6; i++)
  643. new AdventureMapButton("", CGI->generaltexth->zelp[107+i].second, bind(&SelectionTab::sortBy, this, i), xpos[i], 86, names[i]);
  644. }
  645. }
  646. else
  647. {
  648. //sort by buttons
  649. new AdventureMapButton("", "", bind(&SelectionTab::sortBy, this, _numOfMaps), 23, 86, "CamCusM.DEF"); //by num of maps
  650. new AdventureMapButton("", "", bind(&SelectionTab::sortBy, this, _name), 55, 86, "CamCusL.DEF"); //by name
  651. }
  652. slider = new CSlider(372, 86, tabType != CMenuScreen::saveGame ? 480 : 430, bind(&SelectionTab::sliderMove, this, _1), positions, curItems.size(), 0, false, 1);
  653. format = CDefHandler::giveDef("SCSELC.DEF");
  654. sortingBy = _format;
  655. ascending = true;
  656. filter(0);
  657. //select(0);
  658. switch(tabType)
  659. {
  660. case CMenuScreen::newGame:
  661. selectFName(DATA_DIR "/Maps/Arrogance.h3m");
  662. break;
  663. case CMenuScreen::loadGame:
  664. case CMenuScreen::campaignList:
  665. select(0);
  666. break;
  667. case CMenuScreen::saveGame:;
  668. if(selectedName.size())
  669. {
  670. if(selectedName[0] == 'M')
  671. txt->setText("NEWGAME");
  672. else
  673. selectFName(selectedName);
  674. }
  675. }
  676. }
  677. SelectionTab::~SelectionTab()
  678. {
  679. delete format;
  680. }
  681. void SelectionTab::sortBy( int criteria )
  682. {
  683. if(criteria == sortingBy)
  684. {
  685. ascending = !ascending;
  686. }
  687. else
  688. {
  689. sortingBy = (ESortBy)criteria;
  690. ascending = true;
  691. }
  692. sort();
  693. selectAbs(0);
  694. }
  695. void SelectionTab::sort()
  696. {
  697. if(sortingBy != _name)
  698. std::stable_sort(curItems.begin(), curItems.end(), mapSorter(_name));
  699. std::stable_sort(curItems.begin(), curItems.end(), mapSorter(sortingBy));
  700. if(!ascending)
  701. std::reverse(curItems.begin(), curItems.end());
  702. redraw();
  703. }
  704. void SelectionTab::select( int position )
  705. {
  706. if(!curItems.size()) return;
  707. // New selection. py is the index in curItems.
  708. int py = position + slider->value;
  709. amax(py, 0);
  710. amin(py, curItems.size()-1);
  711. selectionPos = py;
  712. if(position < 0)
  713. slider->moveTo(slider->value + position);
  714. else if(position >= positions)
  715. slider->moveTo(slider->value + position - positions + 1);
  716. onSelect(curItems[py]);
  717. }
  718. void SelectionTab::selectAbs( int position )
  719. {
  720. select(position - slider->value);
  721. }
  722. int SelectionTab::getPosition( int x, int y )
  723. {
  724. return -1;
  725. }
  726. void SelectionTab::sliderMove( int slidPos )
  727. {
  728. if(!slider) return; //ignore spurious call when slider is being created
  729. redraw();
  730. }
  731. // Display the tab with the scenario names
  732. //
  733. // elemIdx is the index of the maps or saved game to display on line 0
  734. // slider->capacity contains the number of available screen lines
  735. // slider->positionsAmnt is the number of elements after filtering
  736. void SelectionTab::printMaps(SDL_Surface *to)
  737. {
  738. int elemIdx = slider->value;
  739. // Display all elements if there's enough space
  740. //if(slider->amount < slider->capacity)
  741. // elemIdx = 0;
  742. SDL_Color itemColor;
  743. #define POS(xx, yy) pos.x + xx, pos.y + yy + line*25
  744. for (int line = 0; line < positions && elemIdx < curItems.size(); elemIdx++, line++)
  745. {
  746. CMapInfo* curMap = curItems[elemIdx];
  747. if (elemIdx == selectionPos)
  748. itemColor=tytulowy;
  749. else
  750. itemColor=zwykly;
  751. if(tabType != CMenuScreen::campaignList)
  752. {
  753. //amount of players
  754. std::ostringstream ostr(std::ostringstream::out);
  755. ostr << curMap->playerAmnt << "/" << curMap->humenPlayers;
  756. CSDL_Ext::printAt(ostr.str(), POS(29, 120), FONT_SMALL, itemColor, to);
  757. //map size
  758. std::string temp2 = "C";
  759. switch (curMap->mapHeader->width)
  760. {
  761. case 36:
  762. temp2="S";
  763. break;
  764. case 72:
  765. temp2="M";
  766. break;
  767. case 108:
  768. temp2="L";
  769. break;
  770. case 144:
  771. temp2="XL";
  772. break;
  773. }
  774. CSDL_Ext::printAtMiddle(temp2, POS(70, 128), FONT_SMALL, itemColor, to);
  775. int temp=-1;
  776. switch (curMap->mapHeader->version)
  777. {
  778. case CMapHeader::RoE:
  779. temp=0;
  780. break;
  781. case CMapHeader::AB:
  782. temp=1;
  783. break;
  784. case CMapHeader::SoD:
  785. temp=2;
  786. break;
  787. case CMapHeader::WoG:
  788. temp=3;
  789. break;
  790. default:
  791. // Unknown version. Be safe and ignore that map
  792. tlog2 << "Warning: " << curMap->filename << " has wrong version!\n";
  793. continue;
  794. }
  795. blitAt(format->ourImages[temp].bitmap, POS(88, 117), to);
  796. //victory conditions
  797. if (curMap->mapHeader->victoryCondition.condition == winStandard)
  798. temp = 11;
  799. else
  800. temp = curMap->mapHeader->victoryCondition.condition;
  801. blitAt(CGP->victory->ourImages[temp].bitmap, POS(306, 117), to);
  802. //loss conditions
  803. if (curMap->mapHeader->lossCondition.typeOfLossCon == lossStandard)
  804. temp=3;
  805. else
  806. temp=curMap->mapHeader->lossCondition.typeOfLossCon;
  807. blitAt(CGP->loss->ourImages[temp].bitmap, POS(339, 117), to);
  808. }
  809. else //if campaign
  810. {
  811. //number of maps in campaign
  812. std::ostringstream ostr(std::ostringstream::out);
  813. ostr << CGI->generaltexth->campaignRegionNames[ curMap->campaignHeader->mapVersion ].size();
  814. CSDL_Ext::printAt(ostr.str(), POS(29, 120), FONT_SMALL, itemColor, to);
  815. }
  816. std::string name;
  817. if(tabType != CMenuScreen::campaignList)
  818. {
  819. if (!curMap->mapHeader->name.length())
  820. curMap->mapHeader->name = "Unnamed";
  821. name = curMap->mapHeader->name;
  822. }
  823. else
  824. {
  825. name = curMap->campaignHeader->name;
  826. }
  827. //print name
  828. if (tabType == CMenuScreen::newGame || tabType == CMenuScreen::campaignList) {
  829. CSDL_Ext::printAtMiddle(name, POS(213, 128), FONT_SMALL, itemColor, to);
  830. } else
  831. CSDL_Ext::printAtMiddle(fs::basename(curMap->filename), POS(213, 128), FONT_SMALL, itemColor, to);
  832. }
  833. #undef POS
  834. }
  835. void SelectionTab::showAll( SDL_Surface * to )
  836. {
  837. CIntObject::showAll(to);
  838. printMaps(to);
  839. std::string title;
  840. switch(tabType) {
  841. case CMenuScreen::newGame:
  842. title = CGI->generaltexth->arraytxt[229];
  843. break;
  844. case CMenuScreen::loadGame:
  845. title = CGI->generaltexth->arraytxt[230];
  846. break;
  847. case CMenuScreen::saveGame:
  848. title = CGI->generaltexth->arraytxt[231];
  849. break;
  850. case CMenuScreen::campaignList:
  851. title = "Select a Campaign"; //TODO: find where is the title
  852. break;
  853. }
  854. CSDL_Ext::printAtMiddle(title, pos.x+205, pos.y+28, FONT_MEDIUM, tytulowy, to); //Select a Scenario to Play
  855. if(tabType != CMenuScreen::campaignList)
  856. {
  857. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[510], pos.x+87, pos.y+62, FONT_SMALL, tytulowy, to); //Map sizes
  858. }
  859. }
  860. void SelectionTab::clickLeft( tribool down, bool previousState )
  861. {
  862. if(down)
  863. {
  864. int line = getLine();
  865. if(line != -1)
  866. select(line);
  867. }
  868. }
  869. void SelectionTab::wheelScrolled( bool down, bool in )
  870. {
  871. slider->moveTo(slider->value + 3 * (down ? +1 : -1));
  872. //select(selectionPos - slider->value + (down ? +1 : -1));
  873. }
  874. void SelectionTab::keyPressed( const SDL_KeyboardEvent & key )
  875. {
  876. if(key.state != SDL_PRESSED) return;
  877. int moveBy = 0;
  878. switch(key.keysym.sym)
  879. {
  880. case SDLK_UP:
  881. moveBy = -1;
  882. break;
  883. case SDLK_DOWN:
  884. moveBy = +1;
  885. break;
  886. case SDLK_PAGEUP:
  887. moveBy = -positions+1;
  888. break;
  889. case SDLK_PAGEDOWN:
  890. moveBy = +positions-1;
  891. break;
  892. case SDLK_HOME:
  893. select(-slider->value);
  894. return;
  895. case SDLK_END:
  896. select(curItems.size() - slider->value);
  897. return;
  898. default:
  899. return;
  900. }
  901. select(selectionPos - slider->value + moveBy);
  902. }
  903. void SelectionTab::onDoubleClick()
  904. {
  905. if(getLine() != -1) //double clicked scenarios list
  906. {
  907. //act as if start button was pressed
  908. (static_cast<CSelectionScreen*>(parent))->start->callback();
  909. }
  910. }
  911. int SelectionTab::getLine()
  912. {
  913. int line = -1;
  914. Point clickPos(GH.current->button.x, GH.current->button.y);
  915. clickPos = clickPos - pos.topLeft();
  916. if (clickPos.y > 115 && clickPos.y < 564 && clickPos.x > 22 && clickPos.x < 371)
  917. {
  918. line = (clickPos.y-115) / 25; //which line
  919. }
  920. return line;
  921. }
  922. void SelectionTab::selectFName( const std::string &fname )
  923. {
  924. for(int i = curItems.size() - 1; i >= 0; i--)
  925. {
  926. if(curItems[i]->filename == fname)
  927. {
  928. slider->moveTo(i);
  929. selectAbs(i);
  930. return;
  931. }
  932. }
  933. selectAbs(0);
  934. }
  935. InfoCard::InfoCard( CMenuScreen::EState Type )
  936. : difficulty(NULL), sizes(NULL), sFlags(NULL), bg(NULL)
  937. {
  938. OBJ_CONSTRUCTION;
  939. pos.x += 393;
  940. used = RCLICK;
  941. type = Type;
  942. if(type == CMenuScreen::campaignList)
  943. {
  944. /*bg = new CPicture(BitmapHandler::loadBitmap("CamCust.bmp"), 0, 0, true);
  945. bg->pos.x = 0;
  946. bg->pos.y = 0;*/
  947. }
  948. else
  949. {
  950. bg = new CPicture(BitmapHandler::loadBitmap("GSELPOP1.bmp"), 0, 0, true);
  951. pos.w = bg->pos.w;
  952. pos.h = bg->pos.h;
  953. sizes = CDefHandler::giveDef("SCNRMPSZ.DEF");
  954. sFlags = CDefHandler::giveDef("ITGFLAGS.DEF");
  955. difficulty = new CHighlightableButtonsGroup(0);
  956. {
  957. static const char *difButns[] = {"GSPBUT3.DEF", "GSPBUT4.DEF", "GSPBUT5.DEF", "GSPBUT6.DEF", "GSPBUT7.DEF"};
  958. BLOCK_CAPTURING;
  959. for(int i = 0; i < 5; i++)
  960. {
  961. difficulty->addButton(new CHighlightableButton("", CGI->generaltexth->zelp[24+i].second, 0, 110 + i*32, 450, difButns[i], i));
  962. difficulty->buttons.back()->pos += pos.topLeft();
  963. }
  964. }
  965. if(type != CMenuScreen::newGame)
  966. difficulty->block(true);
  967. }
  968. }
  969. InfoCard::~InfoCard()
  970. {
  971. delete sizes;
  972. delete sFlags;
  973. }
  974. void InfoCard::showAll( SDL_Surface * to )
  975. {
  976. CIntObject::showAll(to);
  977. //blit texts
  978. if(type != CMenuScreen::campaignList)
  979. {
  980. printAtLoc(CGI->generaltexth->allTexts[390] + ":", 24, 400, FONT_SMALL, zwykly, to); //Allies
  981. printAtLoc(CGI->generaltexth->allTexts[391] + ":", 190, 400, FONT_SMALL, zwykly, to); //Enemies
  982. printAtLoc(CGI->generaltexth->allTexts[494], 33, 430, FONT_SMALL, tytulowy, to);//"Map Diff:"
  983. printAtLoc(CGI->generaltexth->allTexts[492] + ":", 133,430, FONT_SMALL, tytulowy, to); //player difficulty
  984. printAtLoc(CGI->generaltexth->allTexts[218] + ":", 290,430, FONT_SMALL, tytulowy, to); //"Rating:"
  985. printAtLoc(CGI->generaltexth->allTexts[495], 26, 22, FONT_SMALL, tytulowy, to); //Scenario Name:
  986. printAtLoc(CGI->generaltexth->allTexts[496], 26, 132, FONT_SMALL, tytulowy, to); //Scenario Description:
  987. printAtLoc(CGI->generaltexth->allTexts[497], 26, 283, FONT_SMALL, tytulowy, to); //Victory Condition:
  988. printAtLoc(CGI->generaltexth->allTexts[498], 26, 339, FONT_SMALL, tytulowy, to); //Loss Condition:
  989. }
  990. if(curMap)
  991. {
  992. if(type != CMenuScreen::campaignList)
  993. {
  994. if(type != CMenuScreen::newGame)
  995. {
  996. for (int i = 0; i < difficulty->buttons.size(); i++)
  997. {
  998. //if(i == curMap->difficulty)
  999. // difficulty->buttons[i]->state = 3;
  1000. //else
  1001. // difficulty->buttons[i]->state = 2;
  1002. difficulty->buttons[i]->showAll(to);
  1003. }
  1004. }
  1005. //victory conditions
  1006. int temp = curMap->mapHeader->victoryCondition.condition+1;
  1007. if (temp>20) temp=0;
  1008. std::string sss = CGI->generaltexth->victoryConditions[temp];
  1009. if (temp && curMap->mapHeader->victoryCondition.allowNormalVictory) sss+= "/" + CGI->generaltexth->victoryConditions[0];
  1010. printAtLoc(sss, 60, 307, FONT_SMALL, zwykly, to);
  1011. //loss conditoins
  1012. temp = curMap->mapHeader->lossCondition.typeOfLossCon+1;
  1013. if (temp>20) temp=0;
  1014. sss = CGI->generaltexth->lossCondtions[temp];
  1015. printAtLoc(sss, 60, 366, FONT_SMALL, zwykly, to);
  1016. //difficulty
  1017. assert(curMap->mapHeader->difficulty <= 4);
  1018. std::string &diff = CGI->generaltexth->arraytxt[142 + curMap->mapHeader->difficulty];
  1019. printAtMiddleLoc(diff, 62, 472, FONT_SMALL, zwykly, to);
  1020. //selecting size icon
  1021. switch (curMap->mapHeader->width)
  1022. {
  1023. case 36:
  1024. temp=0;
  1025. break;
  1026. case 72:
  1027. temp=1;
  1028. break;
  1029. case 108:
  1030. temp=2;
  1031. break;
  1032. case 144:
  1033. temp=3;
  1034. break;
  1035. default:
  1036. temp=4;
  1037. break;
  1038. }
  1039. blitAtLoc(sizes->ourImages[temp].bitmap, 318, 22, to);
  1040. //conditions
  1041. temp = curMap->mapHeader->victoryCondition.condition;
  1042. if (temp>12) temp=11;
  1043. blitAtLoc(CGP->victory->ourImages[temp].bitmap, 24, 302, to); //victory cond descr
  1044. temp=curMap->mapHeader->lossCondition.typeOfLossCon;
  1045. if (temp>12) temp=3;
  1046. blitAtLoc(CGP->loss->ourImages[temp].bitmap, 24, 359, to); //loss cond
  1047. if(type == CMenuScreen::loadGame)
  1048. printToLoc((static_cast<const CMapInfo*>(curMap))->date,308,34, FONT_SMALL, zwykly, to);
  1049. //print flags
  1050. int fx=64, ex=244, myT;
  1051. //if (curMap->howManyTeams)
  1052. myT = curMap->mapHeader->players[playerColor].team;
  1053. //else
  1054. // myT = -1;
  1055. for (std::vector<PlayerSettings>::const_iterator i = curOpts->playerInfos.begin(); i != curOpts->playerInfos.end(); i++)
  1056. {
  1057. int *myx = ((i->color == playerColor || curMap->mapHeader->players[i->color].team == myT) ? &fx : &ex);
  1058. blitAtLoc(sFlags->ourImages[i->color].bitmap, *myx, 399, to);
  1059. *myx += sFlags->ourImages[i->color].bitmap->w;
  1060. }
  1061. std::string tob;
  1062. switch (curOpts->difficulty)
  1063. {
  1064. case 0:
  1065. tob="80%";
  1066. break;
  1067. case 1:
  1068. tob="100%";
  1069. break;
  1070. case 2:
  1071. tob="130%";
  1072. break;
  1073. case 3:
  1074. tob="160%";
  1075. break;
  1076. case 4:
  1077. tob="200%";
  1078. break;
  1079. }
  1080. printAtMiddleLoc(tob, 311, 472, FONT_SMALL, zwykly, to);
  1081. }
  1082. //blit description
  1083. std::string itemDesc, name;
  1084. if (type == CMenuScreen::campaignList)
  1085. {
  1086. itemDesc = curMap->campaignHeader->description;
  1087. name = curMap->campaignHeader->name;
  1088. }
  1089. else
  1090. {
  1091. itemDesc = curMap->mapHeader->description;
  1092. name = curMap->mapHeader->name;
  1093. }
  1094. std::vector<std::string> *desc = CMessage::breakText(itemDesc,52);
  1095. for (int i=0;i<desc->size();i++)
  1096. printAtLoc((*desc)[i], 26, 149 + i*16, FONT_SMALL, zwykly, to);
  1097. delete desc;
  1098. //name
  1099. if (name.length())
  1100. printAtLoc(name, 26, 39, FONT_BIG, tytulowy, to);
  1101. else
  1102. printAtLoc("Unnamed", 26, 39, FONT_BIG, tytulowy, to);
  1103. }
  1104. }
  1105. void InfoCard::changeSelection( const CMapInfo *to )
  1106. {
  1107. if(to && type != CMenuScreen::newGame && type != CMenuScreen::campaignList)
  1108. difficulty->select(curOpts->difficulty, 0);
  1109. GH.totalRedraw();
  1110. }
  1111. void InfoCard::clickRight( tribool down, bool previousState )
  1112. {
  1113. static const Rect flagArea(19, 397, 335, 23);
  1114. if(down && curMap && isItInLoc(flagArea, GH.current->motion.x, GH.current->motion.y))
  1115. showTeamsPopup();
  1116. }
  1117. void InfoCard::showTeamsPopup()
  1118. {
  1119. SDL_Surface *bmp = CMessage::drawBox1(256, 90 + 50 * curMap->mapHeader->howManyTeams);
  1120. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[657], 128, 30, FONT_MEDIUM, tytulowy, bmp); //{Team Alignments}
  1121. for(int i = 0; i < curMap->mapHeader->howManyTeams; i++)
  1122. {
  1123. std::vector<ui8> flags;
  1124. std::string hlp = CGI->generaltexth->allTexts[656]; //Team %d
  1125. hlp.replace(hlp.find("%d"), 2, boost::lexical_cast<std::string>(i+1));
  1126. CSDL_Ext::printAtMiddle(hlp, 128, 65 + 50*i, FONT_SMALL, zwykly, bmp);
  1127. for(int j = 0; j < PLAYER_LIMIT; j++)
  1128. if((curMap->mapHeader->players[j].canHumanPlay || curMap->mapHeader->players[j].canComputerPlay)
  1129. && curMap->mapHeader->players[j].team == i)
  1130. flags.push_back(j);
  1131. int curx = 128 - 9*flags.size();
  1132. for(int j = 0; j < flags.size(); j++)
  1133. {
  1134. blitAt(sFlags->ourImages[flags[j]].bitmap, curx, 75 + 50*i, bmp);
  1135. curx += 18;
  1136. }
  1137. }
  1138. GH.pushInt(new CInfoPopup(bmp, true));
  1139. }
  1140. OptionsTab::OptionsTab( CMenuScreen::EState Type)
  1141. :type(Type)
  1142. {
  1143. OBJ_CONSTRUCTION;
  1144. bg = new CPicture(BitmapHandler::loadBitmap("ADVOPTBK.bmp"), 0, 0, true);
  1145. pos = bg->pos;
  1146. if(type == CMenuScreen::newGame)
  1147. turnDuration = new CSlider(55, 551, 194, bind(&OptionsTab::setTurnLength, this, _1), 1, 11, 11, true, 1);
  1148. }
  1149. OptionsTab::~OptionsTab()
  1150. {
  1151. }
  1152. void OptionsTab::showAll( SDL_Surface * to )
  1153. {
  1154. CIntObject::showAll(to);
  1155. printAtMiddleLoc(CGI->generaltexth->allTexts[515], 222, 30, FONT_BIG, tytulowy, to);
  1156. printAtMiddleWBLoc(CGI->generaltexth->allTexts[516], 222, 58, FONT_SMALL, 55, zwykly, to); //Select starting options, handicap, and name for each player in the game.
  1157. printAtMiddleWBLoc(CGI->generaltexth->allTexts[517], 107, 102, FONT_SMALL, 14, tytulowy, to); //Player Name Handicap Type
  1158. printAtMiddleWBLoc(CGI->generaltexth->allTexts[518], 197, 102, FONT_SMALL, 10, tytulowy, to); //Starting Town
  1159. printAtMiddleWBLoc(CGI->generaltexth->allTexts[519], 273, 102, FONT_SMALL, 10, tytulowy, to); //Starting Hero
  1160. printAtMiddleWBLoc(CGI->generaltexth->allTexts[520], 349, 102, FONT_SMALL, 10, tytulowy, to); //Starting Bonus
  1161. printAtMiddleLoc(CGI->generaltexth->allTexts[521], 222, 538, FONT_SMALL, tytulowy, to); // Player Turn Duration
  1162. if(curOpts->turnTime)
  1163. {
  1164. std::ostringstream os;
  1165. os << (int)curOpts->turnTime << " Minutes";
  1166. printAtMiddleLoc(os.str(), 319,559, FONT_SMALL, zwykly, to);
  1167. }
  1168. else
  1169. printAtMiddleLoc("Unlimited",319,559, FONT_SMALL, zwykly, to);
  1170. }
  1171. void OptionsTab::nextCastle( int player, int dir )
  1172. {
  1173. PlayerSettings &s = curOpts->playerInfos[player];
  1174. si32 &cur = s.castle;
  1175. ui32 allowed = curMap->mapHeader->players[s.color].allowedFactions;
  1176. if (cur == -2) //no castle - no change
  1177. return;
  1178. if (cur == -1) //random => first/last available
  1179. {
  1180. int pom = (dir>0) ? (0) : (F_NUMBER-1); // last or first
  1181. for (;pom >= 0 && pom < F_NUMBER; pom+=dir)
  1182. {
  1183. if((1 << pom) & allowed)
  1184. {
  1185. cur=pom;
  1186. break;
  1187. }
  1188. }
  1189. }
  1190. else // next/previous available
  1191. {
  1192. for (;;)
  1193. {
  1194. cur+=dir;
  1195. if ((1 << cur) & allowed)
  1196. break;
  1197. if (cur >= F_NUMBER || cur<0)
  1198. {
  1199. double p1 = log((double)allowed) / log(2.0f)+0.000001f;
  1200. double check = p1 - ((int)p1);
  1201. if (check < 0.001)
  1202. cur = (int)p1;
  1203. else
  1204. cur = -1;
  1205. break;
  1206. }
  1207. }
  1208. }
  1209. if(s.hero >= 0)
  1210. s.hero = -1;
  1211. if(cur < 0 && s.bonus == bresource)
  1212. s.bonus = brandom;
  1213. entries[player]->selectButtons();
  1214. redraw();
  1215. }
  1216. void OptionsTab::nextHero( int player, int dir )
  1217. {
  1218. PlayerSettings &s = curOpts->playerInfos[player];
  1219. int old = s.hero;
  1220. if (s.castle < 0 || !s.human || s.hero == -2)
  1221. return;
  1222. if (s.hero == -1) //random => first/last available
  1223. {
  1224. int max = (s.castle*HEROES_PER_TYPE*2+15),
  1225. min = (s.castle*HEROES_PER_TYPE*2);
  1226. s.hero = nextAllowedHero(min,max,0,dir);
  1227. }
  1228. else
  1229. {
  1230. if(dir > 0)
  1231. s.hero = nextAllowedHero(s.hero,(s.castle*HEROES_PER_TYPE*2+16),1,dir);
  1232. else
  1233. s.hero = nextAllowedHero(s.castle*HEROES_PER_TYPE*2-1,s.hero,1,dir);
  1234. }
  1235. if(old != s.hero)
  1236. {
  1237. usedHeroes.erase(old);
  1238. usedHeroes.insert(s.hero);
  1239. redraw();
  1240. }
  1241. }
  1242. int OptionsTab::nextAllowedHero( int min, int max, int incl, int dir )
  1243. {
  1244. if(dir>0)
  1245. {
  1246. for(int i=min+incl; i<=max-incl; i++)
  1247. if(canUseThisHero(i))
  1248. return i;
  1249. }
  1250. else
  1251. {
  1252. for(int i=max-incl; i>=min+incl; i--)
  1253. if(canUseThisHero(i))
  1254. return i;
  1255. }
  1256. return -1;
  1257. }
  1258. bool OptionsTab::canUseThisHero( int ID )
  1259. {
  1260. //for(int i=0;i<CPG->ret.playerInfos.size();i++)
  1261. // if(CPG->ret.playerInfos[i].hero==ID) //hero is already taken
  1262. // return false;
  1263. return !vstd::contains(usedHeroes, ID) && curMap->mapHeader->allowedHeroes[ID];
  1264. }
  1265. void OptionsTab::nextBonus( int player, int dir )
  1266. {
  1267. PlayerSettings &s = curOpts->playerInfos[player];
  1268. si8 &ret = s.bonus += dir;
  1269. if (s.hero==-2 && !curMap->mapHeader->players[s.color].heroesNames.size() && ret==bartifact) //no hero - can't be artifact
  1270. {
  1271. if (dir<0)
  1272. ret=brandom;
  1273. else ret=bgold;
  1274. }
  1275. if(ret > bresource)
  1276. ret = brandom;
  1277. if(ret < brandom)
  1278. ret = bresource;
  1279. if (s.castle==-1 && ret==bresource) //random castle - can't be resource
  1280. {
  1281. if (dir<0)
  1282. ret=bgold;
  1283. else ret=brandom;
  1284. }
  1285. redraw();
  1286. }
  1287. void OptionsTab::changeSelection( const CMapHeader *to )
  1288. {
  1289. for(int i = 0; i < entries.size(); i++)
  1290. {
  1291. children -= entries[i];
  1292. delete entries[i];
  1293. }
  1294. entries.clear();
  1295. usedHeroes.clear();
  1296. OBJ_CONSTRUCTION;
  1297. for(int i = 0; i < curOpts->playerInfos.size(); i++)
  1298. {
  1299. entries.push_back(new PlayerOptionsEntry(this, curOpts->playerInfos[i]));
  1300. const std::vector<SheroName> &heroes = curMap->mapHeader->players[curOpts->playerInfos[i].color].heroesNames;
  1301. for(size_t hi=0; hi<heroes.size(); hi++)
  1302. usedHeroes.insert(heroes[hi].heroID);
  1303. }
  1304. }
  1305. void OptionsTab::setTurnLength( int npos )
  1306. {
  1307. static const int times[] = {1, 2, 4, 6, 8, 10, 15, 20, 25, 30, 0};
  1308. amin(npos, ARRAY_COUNT(times) - 1);
  1309. curOpts->turnTime = times[npos];
  1310. redraw();
  1311. }
  1312. void OptionsTab::flagPressed( int player )
  1313. {
  1314. static std::pair<int, int> playerToRestore(-1, -1); //<color serial, player name serial>
  1315. PlayerSettings &clicked = curOpts->playerInfos[player];
  1316. PlayerSettings *old = NULL;
  1317. if(playerNames.size() == 1) //single player -> swap
  1318. {
  1319. if(player == playerSerial) //that color is already selected, no action needed
  1320. return;
  1321. old = &curOpts->playerInfos[playerSerial];
  1322. std::swap(old->human, clicked.human);
  1323. std::swap(old->name, clicked.name);
  1324. playerColor = clicked.color;
  1325. playerSerial = player;
  1326. }
  1327. else
  1328. {
  1329. //identify clicked player
  1330. int curNameID = clicked.human
  1331. ? vstd::findPos(playerNames, clicked.name)
  1332. : -1;
  1333. if(curNameID >= 0 && playerToRestore.second == curNameID) //player to restore is about to being replaced -> put him back to the old place
  1334. {
  1335. PlayerSettings &restPos = curOpts->playerInfos[playerToRestore.first];
  1336. setPlayer(restPos, playerToRestore.second);
  1337. playerToRestore.first = playerToRestore.second = 0;
  1338. }
  1339. //who will be put here?
  1340. if(curNameID < 0) //if possible replace computer with unallocated player
  1341. {
  1342. for(int i = 0; i < playerNames.size(); i++)
  1343. {
  1344. if(!curOpts->getPlayersSettings(playerNames[i]))
  1345. {
  1346. curNameID = i-1; //-1 because it'll incremented soon
  1347. break;
  1348. }
  1349. }
  1350. }
  1351. setPlayer(clicked, ++curNameID); //simply next player
  1352. //if that player was somewhere else, we need to replace him with computer
  1353. if(curNameID < playerNames.size())
  1354. {
  1355. for(std::vector<PlayerSettings>::iterator i = curOpts->playerInfos.begin(); i != curOpts->playerInfos.end(); i++)
  1356. {
  1357. if(i->serial != player && i->name == playerNames[curNameID])
  1358. {
  1359. assert(i->human);
  1360. playerToRestore.first = i->serial;
  1361. playerToRestore.second = vstd::findPos(playerNames, i->name);
  1362. setPlayer(*i, -1); //set computer
  1363. old = &*i;
  1364. break;
  1365. }
  1366. }
  1367. }
  1368. }
  1369. entries[clicked.serial]->selectButtons();
  1370. if(old)
  1371. {
  1372. entries[old->serial]->selectButtons();
  1373. if(!entries[playerSerial]->fixedHero)
  1374. old->hero = -1;
  1375. }
  1376. GH.totalRedraw();
  1377. }
  1378. OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry( OptionsTab *owner, PlayerSettings &S)
  1379. :s(S)
  1380. {
  1381. OBJ_CONSTRUCTION;
  1382. defActions |= SHARE_POS;
  1383. pos = parent->pos + Point(54, 122 + s.serial*50);
  1384. static const char *flags[] = {"AOFLGBR.DEF", "AOFLGBB.DEF", "AOFLGBY.DEF", "AOFLGBG.DEF",
  1385. "AOFLGBO.DEF", "AOFLGBP.DEF", "AOFLGBT.DEF", "AOFLGBS.DEF"};
  1386. static const char *bgs[] = {"ADOPRPNL.bmp", "ADOPBPNL.bmp", "ADOPYPNL.bmp", "ADOPGPNL.bmp",
  1387. "ADOPOPNL.bmp", "ADOPPPNL.bmp", "ADOPTPNL.bmp", "ADOPSPNL.bmp"};
  1388. bg = new CPicture(BitmapHandler::loadBitmap(bgs[s.color]), 0, 0, true);
  1389. if(owner->type == CMenuScreen::newGame)
  1390. {
  1391. btns[0] = new AdventureMapButton(CGI->generaltexth->zelp[132], bind(&OptionsTab::nextCastle, owner, s.serial, -1), 107, 5, "ADOPLFA.DEF");
  1392. btns[1] = new AdventureMapButton(CGI->generaltexth->zelp[133], bind(&OptionsTab::nextCastle, owner, s.serial, +1), 168, 5, "ADOPRTA.DEF");
  1393. btns[2] = new AdventureMapButton(CGI->generaltexth->zelp[148], bind(&OptionsTab::nextHero, owner, s.serial, -1), 183, 5, "ADOPLFA.DEF");
  1394. btns[3] = new AdventureMapButton(CGI->generaltexth->zelp[149], bind(&OptionsTab::nextHero, owner, s.serial, +1), 244, 5, "ADOPRTA.DEF");
  1395. btns[4] = new AdventureMapButton(CGI->generaltexth->zelp[164], bind(&OptionsTab::nextBonus, owner, s.serial, -1), 259, 5, "ADOPLFA.DEF");
  1396. btns[5] = new AdventureMapButton(CGI->generaltexth->zelp[165], bind(&OptionsTab::nextBonus, owner, s.serial, +1), 320, 5, "ADOPRTA.DEF");
  1397. }
  1398. else
  1399. for(int i = 0; i < 6; i++)
  1400. btns[i] = NULL;
  1401. fixedHero = s.hero != -1; //if we doesn't start with "random hero" it must be fixed or none
  1402. selectButtons(false);
  1403. if(owner->type != CMenuScreen::scenarioInfo && curMap->mapHeader->players[s.color].canHumanPlay)
  1404. {
  1405. flag = new AdventureMapButton(CGI->generaltexth->zelp[180], bind(&OptionsTab::flagPressed, owner, s.serial), -43, 2, flags[s.color]);
  1406. flag->hoverable = true;
  1407. }
  1408. else
  1409. flag = NULL;
  1410. defActions &= ~SHARE_POS;
  1411. town = new SelectedBox(TOWN, s.serial);
  1412. town->pos += pos + Point(119, 2);
  1413. hero = new SelectedBox(HERO, s.serial);
  1414. hero->pos += pos + Point(195, 2);
  1415. bonus = new SelectedBox(BONUS, s.serial);
  1416. bonus->pos += pos + Point(271, 2);
  1417. }
  1418. void OptionsTab::PlayerOptionsEntry::showAll( SDL_Surface * to )
  1419. {
  1420. CIntObject::showAll(to);
  1421. printAtMiddleLoc(s.name, 55, 10, FONT_SMALL, zwykly, to);
  1422. }
  1423. void OptionsTab::PlayerOptionsEntry::selectButtons(bool onlyHero)
  1424. {
  1425. if(!btns[0])
  1426. return;
  1427. if(!onlyHero && s.castle != -1)
  1428. {
  1429. btns[0]->disable();
  1430. btns[1]->disable();
  1431. }
  1432. if(fixedHero || !s.human || s.castle < 0)
  1433. {
  1434. btns[2]->disable();
  1435. btns[3]->disable();
  1436. }
  1437. else
  1438. {
  1439. btns[2]->enable(active);
  1440. btns[3]->enable(active);
  1441. }
  1442. }
  1443. void OptionsTab::SelectedBox::showAll( SDL_Surface * to )
  1444. {
  1445. //PlayerSettings &s = curOpts->playerInfos[player];
  1446. SDL_Surface *toBlit = getImg();
  1447. const std::string *toPrint = getText();
  1448. blitAt(toBlit, pos, to);
  1449. printAtMiddleLoc(*toPrint, 23, 39, FONT_TINY, zwykly, to);
  1450. }
  1451. OptionsTab::SelectedBox::SelectedBox( SelType Which, ui8 Player )
  1452. :which(Which), player(Player)
  1453. {
  1454. SDL_Surface *img = getImg();
  1455. pos.w = img->w;
  1456. pos.h = img->h;
  1457. used = RCLICK;
  1458. }
  1459. SDL_Surface * OptionsTab::SelectedBox::getImg() const
  1460. {
  1461. const PlayerSettings &s = curOpts->playerInfos[player];
  1462. switch(which)
  1463. {
  1464. case TOWN:
  1465. if (s.castle < F_NUMBER && s.castle >= 0)
  1466. return graphics->getPic(s.castle, true, false);
  1467. else if (s.castle == -1)
  1468. return CGP->rTown;
  1469. else if (s.castle == -2)
  1470. return CGP->nTown;
  1471. case HERO:
  1472. if (s.hero == -1)
  1473. {
  1474. return CGP->rHero;
  1475. }
  1476. else if (s.hero == -2)
  1477. {
  1478. if(s.heroPortrait >= 0)
  1479. return graphics->portraitSmall[s.heroPortrait];
  1480. else
  1481. return CGP->nHero;
  1482. }
  1483. else
  1484. {
  1485. return graphics->portraitSmall[s.hero];
  1486. }
  1487. break;
  1488. case BONUS:
  1489. {
  1490. int pom;
  1491. switch (s.bonus)
  1492. {
  1493. case -1:
  1494. pom=10;
  1495. break;
  1496. case 0:
  1497. pom=9;
  1498. break;
  1499. case 1:
  1500. pom=8;
  1501. break;
  1502. case 2:
  1503. pom=CGI->townh->towns[s.castle].bonus;
  1504. break;
  1505. default:
  1506. assert(0);
  1507. }
  1508. return CGP->bonuses->ourImages[pom].bitmap;
  1509. }
  1510. default:
  1511. return NULL;
  1512. }
  1513. }
  1514. const std::string * OptionsTab::SelectedBox::getText() const
  1515. {
  1516. const PlayerSettings &s = curOpts->playerInfos[player];
  1517. switch(which)
  1518. {
  1519. case TOWN:
  1520. if (s.castle < F_NUMBER && s.castle >= 0)
  1521. return &CGI->townh->towns[s.castle].Name();
  1522. else if (s.castle == -1)
  1523. return &CGI->generaltexth->allTexts[522];
  1524. else if (s.castle == -2)
  1525. return &CGI->generaltexth->allTexts[523];
  1526. case HERO:
  1527. if (s.hero == -1)
  1528. return &CGI->generaltexth->allTexts[522];
  1529. else if (s.hero == -2)
  1530. {
  1531. if(s.heroPortrait >= 0)
  1532. {
  1533. if(s.heroName.length())
  1534. return &s.heroName;
  1535. else
  1536. return &CGI->heroh->heroes[s.heroPortrait]->name;
  1537. }
  1538. else
  1539. return &CGI->generaltexth->allTexts[523];
  1540. }
  1541. else
  1542. {
  1543. //if(s.heroName.length())
  1544. // return &s.heroName;
  1545. //else
  1546. return &CGI->heroh->heroes[s.hero]->name;
  1547. }
  1548. case BONUS:
  1549. switch (s.bonus)
  1550. {
  1551. case -1:
  1552. return &CGI->generaltexth->allTexts[522];
  1553. default:
  1554. return &CGI->generaltexth->arraytxt[214 + s.bonus];
  1555. }
  1556. default:
  1557. return NULL;
  1558. }
  1559. }
  1560. void OptionsTab::SelectedBox::clickRight( tribool down, bool previousState )
  1561. {
  1562. if(indeterminate(down) || !down) return;
  1563. const PlayerSettings &s = curOpts->playerInfos[player];
  1564. SDL_Surface *bmp = NULL;
  1565. const std::string *title = NULL, *subTitle = NULL;
  1566. subTitle = getText();
  1567. int val;
  1568. switch(which)
  1569. {
  1570. case TOWN:
  1571. val = s.castle;
  1572. break;
  1573. case HERO:
  1574. val = s.hero;
  1575. if(val == -2) //none => we may have some preset info
  1576. {
  1577. int p9 = curMap->mapHeader->players[s.color].p9;
  1578. if(p9 != 255 && curOpts->playerInfos[player].heroPortrait >= 0)
  1579. val = p9;
  1580. }
  1581. break;
  1582. case BONUS:
  1583. val = s.bonus;
  1584. break;
  1585. }
  1586. if(val == -1 || which == BONUS) //random or bonus box
  1587. {
  1588. bmp = CMessage::drawBox1(256, 190);
  1589. std::string *description = NULL;
  1590. switch(which)
  1591. {
  1592. case TOWN:
  1593. title = &CGI->generaltexth->allTexts[103];
  1594. description = &CGI->generaltexth->allTexts[104];
  1595. break;
  1596. case HERO:
  1597. title = &CGI->generaltexth->allTexts[101];
  1598. description = &CGI->generaltexth->allTexts[102];
  1599. break;
  1600. case BONUS:
  1601. {
  1602. switch(val)
  1603. {
  1604. case brandom:
  1605. title = &CGI->generaltexth->allTexts[86]; //{Random Bonus}
  1606. description = &CGI->generaltexth->allTexts[94]; //Gold, wood and ore, or an artifact is randomly chosen as your starting bonus
  1607. break;
  1608. case bartifact:
  1609. title = &CGI->generaltexth->allTexts[83]; //{Artifact Bonus}
  1610. description = &CGI->generaltexth->allTexts[90]; //An artifact is randomly chosen and equipped to your starting hero
  1611. break;
  1612. case bgold:
  1613. title = &CGI->generaltexth->allTexts[84]; //{Gold Bonus}
  1614. subTitle = &CGI->generaltexth->allTexts[87]; //500-1000
  1615. description = &CGI->generaltexth->allTexts[92]; //At the start of the game, 500-1000 gold is added to your Kingdom's resource pool
  1616. break;
  1617. case bresource:
  1618. {
  1619. title = &CGI->generaltexth->allTexts[85]; //{Resource Bonus}
  1620. switch(CGI->townh->towns[s.castle].primaryRes)
  1621. {
  1622. case 1:
  1623. subTitle = &CGI->generaltexth->allTexts[694];
  1624. description = &CGI->generaltexth->allTexts[690];
  1625. break;
  1626. case 3:
  1627. subTitle = &CGI->generaltexth->allTexts[695];
  1628. description = &CGI->generaltexth->allTexts[691];
  1629. break;
  1630. case 4:
  1631. subTitle = &CGI->generaltexth->allTexts[692];
  1632. description = &CGI->generaltexth->allTexts[688];
  1633. break;
  1634. case 5:
  1635. subTitle = &CGI->generaltexth->allTexts[693];
  1636. description = &CGI->generaltexth->allTexts[689];
  1637. break;
  1638. case 127:
  1639. subTitle = &CGI->generaltexth->allTexts[89]; //5-10 wood / 5-10 ore
  1640. description = &CGI->generaltexth->allTexts[93]; //At the start of the game, 5-10 wood and 5-10 ore are added to your Kingdom's resource pool
  1641. break;
  1642. }
  1643. }
  1644. break;
  1645. }
  1646. }
  1647. break;
  1648. }
  1649. if(description)
  1650. CSDL_Ext::printAtMiddleWB(*description, 125, 145, FONT_SMALL, 37, zwykly, bmp);
  1651. }
  1652. else if(val == -2)
  1653. {
  1654. return;
  1655. }
  1656. else if(which == TOWN)
  1657. {
  1658. bmp = CMessage::drawBox1(256, 319);
  1659. title = &CGI->generaltexth->allTexts[80];
  1660. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[79], 135, 137, FONT_MEDIUM, tytulowy, bmp);
  1661. const CTown &t = CGI->townh->towns[val];
  1662. //print creatures
  1663. int x = 60, y = 159;
  1664. for(int i = 0; i < 7; i++)
  1665. {
  1666. int c = t.basicCreatures[i];
  1667. blitAt(graphics->smallImgs[c], x, y, bmp);
  1668. CSDL_Ext::printAtMiddleWB(CGI->creh->creatures[c].nameSing, x + 16, y + 45, FONT_TINY, 10, zwykly, bmp);
  1669. if(i == 2)
  1670. {
  1671. x = 40;
  1672. y += 76;
  1673. }
  1674. else
  1675. {
  1676. x += 52;
  1677. }
  1678. }
  1679. }
  1680. else if(val >= 0)
  1681. {
  1682. const CHero *h = CGI->heroh->heroes[val];
  1683. bmp = CMessage::drawBox1(320, 255);
  1684. title = &CGI->generaltexth->allTexts[77];
  1685. CSDL_Ext::printAtMiddle(*title, 167, 36, FONT_MEDIUM, tytulowy, bmp);
  1686. CSDL_Ext::printAtMiddle(*subTitle + " - " + h->heroClass->name, 160, 99, FONT_SMALL, zwykly, bmp);
  1687. blitAt(getImg(), 136, 56, bmp);
  1688. //print specialty
  1689. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[78], 166, 132, FONT_MEDIUM, tytulowy, bmp);
  1690. blitAt(graphics->un44->ourImages[val].bitmap, 140, 150, bmp);
  1691. CSDL_Ext::printAtMiddle(CGI->generaltexth->hTxts[val].bonusName, 166, 203, FONT_SMALL, zwykly, bmp);
  1692. GH.pushInt(new CInfoPopup(bmp, true));
  1693. return;
  1694. }
  1695. if(title)
  1696. CSDL_Ext::printAtMiddle(*title, 135, 36, FONT_MEDIUM, tytulowy, bmp);
  1697. if(subTitle)
  1698. CSDL_Ext::printAtMiddle(*subTitle, 127, 103, FONT_SMALL, zwykly, bmp);
  1699. blitAt(getImg(), 104, 60, bmp);
  1700. GH.pushInt(new CInfoPopup(bmp, true));
  1701. }
  1702. CScenarioInfo::CScenarioInfo( const CMapHeader *mapHeader, const StartInfo *startInfo, const CMapInfo * makeItCurrent )
  1703. {
  1704. OBJ_CONSTRUCTION_CAPTURING_ALL;
  1705. for(size_t i = 0; i < startInfo->playerInfos.size(); i++)
  1706. {
  1707. if(startInfo->playerInfos[i].human)
  1708. {
  1709. playerColor = startInfo->playerInfos[i].color;
  1710. playerSerial = i;
  1711. }
  1712. }
  1713. pos.w = 762;
  1714. pos.h = 584;
  1715. center(pos);
  1716. if(makeItCurrent)
  1717. {
  1718. curMap = makeItCurrent;
  1719. }
  1720. curOpts = const_cast<StartInfo*>(startInfo); //I hope it's safe
  1721. card = new InfoCard(CMenuScreen::scenarioInfo);
  1722. opt = new OptionsTab(CMenuScreen::scenarioInfo);
  1723. opt->changeSelection(0);
  1724. card->difficulty->select(startInfo->difficulty, 0);
  1725. back = new AdventureMapButton("", CGI->generaltexth->zelp[105].second, bind(&CGuiHandler::popIntTotally, &GH, this), 584, 535, "SCNRBACK.DEF", SDLK_ESCAPE);
  1726. }
  1727. CScenarioInfo::~CScenarioInfo()
  1728. {
  1729. }
  1730. bool mapSorter::operator()(const CMapInfo *aaa, const CMapInfo *bbb)
  1731. {
  1732. const CMapHeader * a = aaa->mapHeader,
  1733. * b = bbb->mapHeader;
  1734. if(a && b) //if we are sorting scenarios
  1735. {
  1736. switch (sortBy)
  1737. {
  1738. case _format: //by map format (RoE, WoG, etc)
  1739. return (a->version<b->version);
  1740. break;
  1741. case _loscon: //by loss conditions
  1742. return (a->lossCondition.typeOfLossCon<b->lossCondition.typeOfLossCon);
  1743. break;
  1744. case _playerAm: //by player amount
  1745. int playerAmntB,humenPlayersB,playerAmntA,humenPlayersA;
  1746. playerAmntB=humenPlayersB=playerAmntA=humenPlayersA=0;
  1747. for (int i=0;i<8;i++)
  1748. {
  1749. if (a->players[i].canHumanPlay) {playerAmntA++;humenPlayersA++;}
  1750. else if (a->players[i].canComputerPlay) {playerAmntA++;}
  1751. if (b->players[i].canHumanPlay) {playerAmntB++;humenPlayersB++;}
  1752. else if (b->players[i].canComputerPlay) {playerAmntB++;}
  1753. }
  1754. if (playerAmntB!=playerAmntA)
  1755. return (playerAmntA<playerAmntB);
  1756. else
  1757. return (humenPlayersA<humenPlayersB);
  1758. break;
  1759. case _size: //by size of map
  1760. return (a->width<b->width);
  1761. break;
  1762. case _viccon: //by victory conditions
  1763. return (a->victoryCondition.condition < b->victoryCondition.condition);
  1764. break;
  1765. case _name: //by name
  1766. return (a->name<b->name);
  1767. break;
  1768. default:
  1769. return (a->name<b->name);
  1770. break;
  1771. }
  1772. }
  1773. else //if we are sorting campaigns
  1774. {
  1775. switch(sortBy)
  1776. {
  1777. case _numOfMaps: //by number of maps in campaign
  1778. return CGI->generaltexth->campaignRegionNames[ aaa->campaignHeader->mapVersion ].size() <
  1779. CGI->generaltexth->campaignRegionNames[ bbb->campaignHeader->mapVersion ].size();
  1780. break;
  1781. case _name: //by name
  1782. return aaa->campaignHeader->name < bbb->campaignHeader->name;
  1783. break;
  1784. default:
  1785. return aaa->campaignHeader->name < bbb->campaignHeader->name;
  1786. break;
  1787. }
  1788. }
  1789. }
  1790. CMultiMode::CMultiMode()
  1791. {
  1792. OBJ_CONSTRUCTION;
  1793. bg = new CPicture("MUPOPUP.bmp");
  1794. bg->convertToScreenBPP(); //so we could draw without problems
  1795. blitAt(CPicture("MUMAP.bmp"), 16, 77, *bg); //blit img
  1796. pos = bg->center(); //center, window has size of bg graphic
  1797. bar = new CGStatusBar(new CPicture(Rect(7, 465, 440, 18), 0));//226, 472
  1798. txt = new CTextInput(Rect(19, 436, 334, 16), *bg);
  1799. txt->setText(CGI->generaltexth->allTexts[434]); //Player
  1800. btns[0] = new AdventureMapButton(CGI->generaltexth->zelp[266], bind(&CMultiMode::openHotseat, this), 373, 78, "MUBHOT.DEF");
  1801. btns[6] = new AdventureMapButton(CGI->generaltexth->zelp[288], bind(&CGuiHandler::popIntTotally, ref(GH), this), 373, 424, "MUBCANC.DEF");
  1802. }
  1803. void CMultiMode::openHotseat()
  1804. {
  1805. GH.pushInt(new CHotSeatPlayers(txt->text));
  1806. }
  1807. CHotSeatPlayers::CHotSeatPlayers(const std::string &firstPlayer)
  1808. {
  1809. OBJ_CONSTRUCTION;
  1810. bg = new CPicture("MUHOTSEA.bmp");
  1811. bg->convertToScreenBPP(); //so we could draw without problems
  1812. bg->printAtMiddleWBLoc(CGI->generaltexth->allTexts[446], 185, 55, FONT_BIG, 50, zwykly, *bg); //HOTSEAT Please enter names
  1813. pos = bg->center(); //center, window has size of bg graphic
  1814. for(int i = 0; i < ARRAY_COUNT(txt); i++)
  1815. txt[i] = new CTextInput(Rect(60, 85 + i*30, 280, 16), *bg);
  1816. txt[0]->setText(firstPlayer);
  1817. txt[0]->giveFocus();
  1818. ok = new AdventureMapButton(CGI->generaltexth->zelp[560], bind(&CHotSeatPlayers::enterSelectionScreen, this), 95, 338, "MUBCHCK.DEF");
  1819. cancel = new AdventureMapButton(CGI->generaltexth->zelp[561], bind(&CGuiHandler::popIntTotally, ref(GH), this), 205, 338, "MUBCANC.DEF");
  1820. bar = new CGStatusBar(new CPicture(Rect(7, 381, 348, 18), 0));//226, 472
  1821. }
  1822. void CHotSeatPlayers::enterSelectionScreen()
  1823. {
  1824. for(int i = 0; i < ARRAY_COUNT(txt); i++)
  1825. if(txt[i]->text.length())
  1826. playerNames.push_back(txt[i]->text);
  1827. GH.popInts(2);
  1828. GH.pushInt(new CSelectionScreen(CMenuScreen::newGame));
  1829. }
  1830. CBonusSelection::CBonusSelection( const CCampaign * _ourCampaign, int _whichMap )
  1831. : ourCampaign(_ourCampaign), whichMap(_whichMap), highlightedRegion(NULL), ourHeader(NULL)
  1832. {
  1833. OBJ_CONSTRUCTION;
  1834. static const std::string bgNames [] = {"E1_BG.BMP", "G2_BG.BMP", "E2_BG.BMP", "G1_BG.BMP", "G3_BG.BMP", "N1_BG.BMP",
  1835. "S1_BG.BMP", "BR_BG.BMP", "IS_BG.BMP", "KR_BG.BMP", "NI_BG.BMP", "TA_BG.BMP", "AR_BG.BMP", "HS_BG.BMP",
  1836. "BB_BG.BMP", "NB_BG.BMP", "EL_BG.BMP", "RN_BG.BMP", "UA_BG.BMP", "SP_BG.BMP"};
  1837. loadPositionsOfGraphics();
  1838. background = BitmapHandler::loadBitmap(bgNames[ourCampaign->header.mapVersion]);
  1839. SDL_Surface * panel = BitmapHandler::loadBitmap("CAMPBRF.BMP");
  1840. blitAt(panel, 456, 6, background);
  1841. startB = new AdventureMapButton("", "", 0 /*cb*/, 475, 536, "SCNRBEG.DEF", SDLK_RETURN);
  1842. backB = new AdventureMapButton("", "", boost::bind(&CBonusSelection::goBack, this), 624, 536, "SCNRBACK.DEF", SDLK_ESCAPE);
  1843. //campaign name
  1844. if (ourCampaign->header.name.length())
  1845. printAtLoc(ourCampaign->header.name, 481, 28, FONT_BIG, tytulowy, background);
  1846. else
  1847. printAtLoc("Unnamed", 481, 28, FONT_BIG, tytulowy, background);
  1848. //map size icon
  1849. sizes = CDefHandler::giveDef("SCNRMPSZ.DEF");
  1850. //campaign description
  1851. printAtLoc(CGI->generaltexth->allTexts[38], 481, 63, FONT_SMALL, tytulowy, background);
  1852. std::vector<std::string> *desc = CMessage::breakText(ourCampaign->header.description, 45);
  1853. for (int i=0; i<desc->size() ;i++)
  1854. printAtLoc((*desc)[i], 481, 86 + i*16, FONT_SMALL, zwykly, background);
  1855. delete desc;
  1856. //set left part of window
  1857. for (int g=0; g<ourCampaign->scenarios.size(); ++g)
  1858. {
  1859. if(ourCampaign->conquerable(g))
  1860. {
  1861. regions.push_back(new CRegion(this, true, true, g));
  1862. regions[regions.size()-1]->rclickText = ourCampaign->scenarios[g].regionText;
  1863. if (highlightedRegion == NULL)
  1864. {
  1865. highlightedRegion = regions.back();
  1866. selectMap(g);
  1867. }
  1868. }
  1869. else if (ourCampaign->scenarios[g].conquered) //display as striped
  1870. {
  1871. regions.push_back(new CRegion(this, false, false, g));
  1872. regions[regions.size()-1]->rclickText = ourCampaign->scenarios[g].regionText;
  1873. }
  1874. }
  1875. //allies / enemies
  1876. printAtLoc(CGI->generaltexth->allTexts[390] + ":", 486, 407, FONT_SMALL, zwykly, background); //Allies
  1877. printAtLoc(CGI->generaltexth->allTexts[391] + ":", 619, 407, FONT_SMALL, zwykly, background); //Enemies
  1878. int fx=64, ex=244, myT;
  1879. myT = ourHeader->players[playerColor].team;
  1880. /*for (std::vector<PlayerSettings>::const_iterator i = curOpts->playerInfos.begin(); i != curOpts->playerInfos.end(); i++)
  1881. {
  1882. int *myx = ((i->color == playerColor || ourHeader.players[i->color].team == myT) ? &fx : &ex);
  1883. blitAtLoc(sFlags->ourImages[i->color].bitmap, *myx, 399, to);
  1884. *myx += sFlags->ourImages[i->color].bitmap->w;
  1885. }*/
  1886. SDL_FreeSurface(panel);
  1887. //bonus choosing
  1888. printAtLoc(CGI->generaltexth->allTexts[71], 510, 431, FONT_MEDIUM, zwykly, background); //Choose a bonus:
  1889. //difficulty
  1890. printAtLoc("Difficulty", 691, 431, FONT_MEDIUM, zwykly, background); //Difficulty
  1891. }
  1892. CBonusSelection::~CBonusSelection()
  1893. {
  1894. SDL_FreeSurface(background);
  1895. delete sizes;
  1896. delete ourHeader;
  1897. }
  1898. void CBonusSelection::goBack()
  1899. {
  1900. GH.popIntTotally(this);
  1901. }
  1902. void CBonusSelection::showAll( SDL_Surface * to )
  1903. {
  1904. CIntObject::showAll(to);
  1905. blitAt(background, pos.x, pos.y, to);
  1906. }
  1907. void CBonusSelection::loadPositionsOfGraphics()
  1908. {
  1909. std::ifstream is((GVCMIDirs.UserPath + "/config/campaign_regions.txt").c_str(), std::ios_base::binary | std::ios_base::in);
  1910. assert(is.is_open());
  1911. for (int g=0; g<CGI->generaltexth->campaignMapNames.size(); ++g)
  1912. {
  1913. SCampPositions sc;
  1914. is >> sc.campPrefix;
  1915. is >> sc.colorSuffixLength;
  1916. bool contReading = true;
  1917. while(contReading)
  1918. {
  1919. SCampPositions::SRegionDesc rd;
  1920. is >> rd.infix;
  1921. if(rd.infix == "END")
  1922. {
  1923. contReading = false;
  1924. }
  1925. else
  1926. {
  1927. is >> rd.xpos >> rd.ypos;
  1928. sc.regions.push_back(rd);
  1929. }
  1930. }
  1931. campDescriptions.push_back(sc);
  1932. }
  1933. }
  1934. void CBonusSelection::selectMap( int whichOne )
  1935. {
  1936. sInfo.difficulty = ourCampaign->scenarios[whichOne].difficulty;
  1937. sInfo.mapname = ourCampaign->header.name;
  1938. sInfo.mode = 2;
  1939. //get header
  1940. int i = 0;
  1941. delete ourHeader;
  1942. ourHeader = new CMapHeader();
  1943. ourHeader->initFromMemory((const unsigned char*)ourCampaign->mapPieces[whichOne].c_str(), i);
  1944. const_cast<CMapInfo *>(curMap)->playerAmnt = ourHeader->players.size();
  1945. CSelectionScreen::updateStartInfo(curMap, *curOpts, ourHeader);
  1946. sInfo.turnTime = 0;
  1947. sInfo.whichMapInCampaign = whichOne;
  1948. }
  1949. void CBonusSelection::show( SDL_Surface * to )
  1950. {
  1951. blitAt(background, pos.x, pos.y, to);
  1952. //map name
  1953. std::string mapDesc = ourHeader->description,
  1954. mapName = ourHeader->name;
  1955. if (mapName.length())
  1956. printAtLoc(mapName, 481, 219, FONT_BIG, tytulowy, to);
  1957. else
  1958. printAtLoc("Unnamed", 481, 219, FONT_BIG, tytulowy, to);
  1959. //map description
  1960. printAtLoc(CGI->generaltexth->allTexts[496], 481, 253, FONT_SMALL, tytulowy, to);
  1961. std::vector<std::string> *desc = CMessage::breakText(mapDesc, 45);
  1962. for (int i=0; i<desc->size(); i++)
  1963. printAtLoc((*desc)[i], 481, 281 + i*16, FONT_SMALL, zwykly, to);
  1964. delete desc;
  1965. //map size icon
  1966. int temp;
  1967. switch (ourHeader->width)
  1968. {
  1969. case 36:
  1970. temp=0;
  1971. break;
  1972. case 72:
  1973. temp=1;
  1974. break;
  1975. case 108:
  1976. temp=2;
  1977. break;
  1978. case 144:
  1979. temp=3;
  1980. break;
  1981. default:
  1982. temp=4;
  1983. break;
  1984. }
  1985. blitAtLoc(sizes->ourImages[temp].bitmap, 735, 26, to);
  1986. CIntObject::show(to);
  1987. }
  1988. CBonusSelection::CRegion::CRegion( CBonusSelection * _owner, bool _accessible, bool _selectable, int _myNumber )
  1989. : owner(_owner), accessible(_accessible), selectable(_selectable), myNumber(_myNumber)
  1990. {
  1991. OBJ_CONSTRUCTION;
  1992. used = LCLICK | RCLICK;
  1993. static const std::string colors[2][8] = {
  1994. {"R", "B", "N", "G", "O", "V", "T", "P"},
  1995. {"Re", "Bl", "Br", "Gr", "Or", "Vi", "Te", "Pi"}};
  1996. const SCampPositions & campDsc = owner->campDescriptions[owner->ourCampaign->header.mapVersion];
  1997. const SCampPositions::SRegionDesc & desc = campDsc.regions[myNumber];
  1998. pos.x = desc.xpos;
  1999. pos.y = desc.ypos;
  2000. //loading of graphics
  2001. std::string prefix = campDsc.campPrefix + desc.infix + "_";
  2002. std::string suffix = colors[campDsc.colorSuffixLength - 1][owner->ourCampaign->scenarios[myNumber].regionColor];
  2003. static const std::string infix [] = {"En", "Se", "Co"};
  2004. for (int g = 0; g < ARRAY_COUNT(infix); g++)
  2005. {
  2006. graphics[g] = BitmapHandler::loadBitmap(prefix + infix[g] + suffix + ".BMP");
  2007. }
  2008. pos.w = graphics[0]->w;
  2009. pos.h = graphics[0]->h;
  2010. }
  2011. CBonusSelection::CRegion::~CRegion()
  2012. {
  2013. for (int g=0; g<ARRAY_COUNT(graphics); ++g)
  2014. {
  2015. SDL_FreeSurface(graphics[g]);
  2016. }
  2017. }
  2018. void CBonusSelection::CRegion::clickLeft( tribool down, bool previousState )
  2019. {
  2020. //select if selectable & clicked inside our graphic
  2021. if( !down && selectable && !CSDL_Ext::isTransparent(graphics[0], GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) )
  2022. {
  2023. owner->selectMap(myNumber);
  2024. owner->highlightedRegion = this;
  2025. }
  2026. }
  2027. void CBonusSelection::CRegion::clickRight( tribool down, bool previousState )
  2028. {
  2029. //show r-click text
  2030. if( down && !CSDL_Ext::isTransparent(graphics[0], GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) &&
  2031. rclickText.size() )
  2032. {
  2033. CSimpleWindow * temp = CMessage::genWindow(rclickText, 0, true);
  2034. CRClickPopupInt *rcpi = new CRClickPopupInt(temp, true);
  2035. GH.pushInt(rcpi);
  2036. }
  2037. }
  2038. void CBonusSelection::CRegion::show( SDL_Surface * to )
  2039. {
  2040. const SCampPositions::SRegionDesc & desc = owner->campDescriptions[owner->ourCampaign->header.mapVersion].regions[myNumber];
  2041. if (!accessible)
  2042. {
  2043. //show as striped
  2044. blitAt(graphics[2], pos.x, pos.y, to);
  2045. }
  2046. else if (this == owner->highlightedRegion)
  2047. {
  2048. //show as selected
  2049. blitAt(graphics[1], pos.x, pos.y, to);
  2050. }
  2051. else
  2052. {
  2053. //show as not selected selected
  2054. blitAt(graphics[0], pos.x, pos.y, to);
  2055. }
  2056. }