CPreGame.cpp 65 KB

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