CPreGame.cpp 81 KB

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