CPreGame.cpp 81 KB

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