CPlayerInterface.cpp 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890
  1. #include "../stdafx.h"
  2. #include "CAdvmapInterface.h"
  3. #include "CBattleInterface.h"
  4. #include "../CCallback.h"
  5. #include "CCastleInterface.h"
  6. #include "CKingdomInterface.h"
  7. #include "CCursorHandler.h"
  8. #include "CGameInfo.h"
  9. #include "CHeroWindow.h"
  10. #include "CMessage.h"
  11. #include "CPlayerInterface.h"
  12. //#include "SDL_Extensions.h"
  13. #include "SDL_Extensions.h"
  14. //#include "SDL_framerate.h"
  15. #include "SDL_framerate.h"
  16. #include "CConfigHandler.h"
  17. #include "CCreatureAnimation.h"
  18. #include "Graphics.h"
  19. #include "../hch/CArtHandler.h"
  20. #include "../hch/CGeneralTextHandler.h"
  21. #include "../hch/CHeroHandler.h"
  22. #include "../hch/CLodHandler.h"
  23. #include "../hch/CObjectHandler.h"
  24. #include "../lib/Connection.h"
  25. #include "../hch/CSpellHandler.h"
  26. #include "../hch/CTownHandler.h"
  27. #include "../lib/CondSh.h"
  28. #include "../lib/NetPacks.h"
  29. #include "../lib/map.h"
  30. #include "../lib/VCMIDirs.h"
  31. #include "../mapHandler.h"
  32. #include "../timeHandler.h"
  33. #include <boost/lexical_cast.hpp>
  34. #include <boost/format.hpp>
  35. #include <boost/algorithm/string.hpp>
  36. #include <boost/algorithm/string/replace.hpp>
  37. #include <boost/assign/std/vector.hpp>
  38. #include <boost/assign/list_of.hpp>
  39. #include <boost/date_time/posix_time/posix_time.hpp>
  40. #include <boost/thread.hpp>
  41. #include <cmath>
  42. #include <queue>
  43. #include <sstream>
  44. #include <boost/filesystem.hpp>
  45. #include "../StartInfo.h"
  46. #ifdef min
  47. #undef min
  48. #endif
  49. #ifdef max
  50. #undef max
  51. #endif
  52. /*
  53. * CPlayerInterface.cpp, part of VCMI engine
  54. *
  55. * Authors: listed in file AUTHORS in main folder
  56. *
  57. * License: GNU General Public License v2.0 or later
  58. * Full text of license available in license.txt file, in main folder
  59. *
  60. */
  61. using namespace boost::assign;
  62. using namespace CSDL_Ext;
  63. void processCommand(const std::string &message, CClient *&client);
  64. extern std::queue<SDL_Event*> events;
  65. extern boost::mutex eventsM;
  66. CPlayerInterface * LOCPLINT;
  67. CBattleInterface * CPlayerInterface::battleInt;
  68. enum EMoveState {STOP_MOVE, WAITING_MOVE, CONTINUE_MOVE, DURING_MOVE};
  69. CondSh<EMoveState> stillMoveHero; //used during hero movement
  70. int howManyPeople = 0;
  71. struct OCM_HLP_CGIN
  72. {
  73. bool inline operator ()(const std::pair<const CGObjectInstance*,SDL_Rect> & a, const std::pair<const CGObjectInstance*,SDL_Rect> & b) const
  74. {
  75. return (*a.first)<(*b.first);
  76. }
  77. } ocmptwo_cgin ;
  78. CPlayerInterface::CPlayerInterface(int Player, int serial)
  79. {
  80. howManyPeople++;
  81. GH.defActionsDef = 0;
  82. LOCPLINT = this;
  83. curAction = NULL;
  84. playerID=Player;
  85. serialID=serial;
  86. human=true;
  87. castleInt = NULL;
  88. battleInt = NULL;
  89. pim = new boost::recursive_mutex;
  90. makingTurn = false;
  91. showingDialog = new CondSh<bool>(false);
  92. sysOpts = GDefaultOptions;
  93. //initializing framerate keeper
  94. mainFPSmng = new FPSmanager;
  95. SDL_initFramerate(mainFPSmng);
  96. SDL_setFramerate(mainFPSmng, 48);
  97. //framerate keeper initialized
  98. cingconsole = new CInGameConsole;
  99. terminate_cond.set(false);
  100. firstCall = 1; //if loading will be overwritten in serialize
  101. autosaveCount = 0;
  102. }
  103. CPlayerInterface::~CPlayerInterface()
  104. {
  105. howManyPeople--;
  106. delete pim;
  107. delete showingDialog;
  108. delete mainFPSmng;
  109. if(adventureInt)
  110. {
  111. if(adventureInt->active & CIntObject::KEYBOARD)
  112. adventureInt->deactivateKeys();
  113. delete adventureInt;
  114. adventureInt = NULL;
  115. }
  116. if(cingconsole->active) //TODO
  117. cingconsole->deactivate();
  118. delete cingconsole;
  119. LOCPLINT = NULL;
  120. }
  121. void CPlayerInterface::init(ICallback * CB)
  122. {
  123. cb = dynamic_cast<CCallback*>(CB);
  124. if(!adventureInt)
  125. adventureInt = new CAdvMapInt();
  126. if(!towns.size() && !wanderingHeroes.size())
  127. {
  128. recreateHeroTownList();
  129. }
  130. }
  131. void CPlayerInterface::yourTurn()
  132. {
  133. {
  134. boost::unique_lock<boost::recursive_mutex> un(*pim);
  135. boost::unique_lock<boost::mutex> lock(eventsM); //block handling events until interface is ready
  136. LOCPLINT = this;
  137. GH.curInt = this;
  138. adventureInt->selection = NULL;
  139. if(firstCall)
  140. {
  141. if(howManyPeople == 1)
  142. adventureInt->setPlayer(playerID);
  143. autosaveCount = getLastIndex("Autosave_");
  144. if(!GH.listInt.size())
  145. {
  146. GH.pushInt(adventureInt);
  147. adventureInt->activateKeys();
  148. }
  149. if(firstCall > 0) //new game, not loaded
  150. {
  151. int index = getLastIndex("Newgame_Autosave_");
  152. index %= SAVES_COUNT;
  153. cb->save("Newgame_Autosave_" + boost::lexical_cast<std::string>(index + 1));
  154. }
  155. firstCall = 0;
  156. }
  157. else
  158. {
  159. LOCPLINT->cb->save("Autosave_" + boost::lexical_cast<std::string>(autosaveCount++ + 1));
  160. autosaveCount %= 5;
  161. }
  162. if(howManyPeople > 1) //hot seat message
  163. {
  164. adventureInt->startHotSeatWait(playerID);
  165. makingTurn = true;
  166. std::string msg = CGI->generaltexth->allTexts[13];
  167. boost::replace_first(msg, "%s", cb->getStartInfo()->playerInfos[serialID].name);
  168. std::vector<SComponent*> cmp;
  169. cmp.push_back(new SComponent(SComponent::flag, playerID, 0));
  170. showInfoDialog(msg, cmp);
  171. }
  172. else
  173. {
  174. makingTurn = true;
  175. adventureInt->startTurn();
  176. }
  177. }
  178. acceptTurn();
  179. }
  180. inline void subRect(const int & x, const int & y, const int & z, const SDL_Rect & r, const int & hid)
  181. {
  182. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  183. for(int h=0; h<hlp.objects.size(); ++h)
  184. if(hlp.objects[h].first->id==hid)
  185. {
  186. hlp.objects[h].second = r;
  187. return;
  188. }
  189. }
  190. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  191. {
  192. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  193. for(int h=0; h<hlp.objects.size(); ++h)
  194. if(hlp.objects[h].first->id==hid)
  195. {
  196. hlp.objects.erase(hlp.objects.begin()+h);
  197. return;
  198. }
  199. }
  200. void CPlayerInterface::heroMoved(const TryMoveHero & details)
  201. {
  202. if(LOCPLINT != this)
  203. return;
  204. boost::unique_lock<boost::recursive_mutex> un(*pim);
  205. const CGHeroInstance * ho = cb->getHeroInfo(details.id); //object representing this hero
  206. int3 hp = details.start;
  207. adventureInt->centerOn(ho); //actualizing screen pos
  208. adventureInt->minimap.draw(screen2);
  209. adventureInt->heroList.draw(screen2);
  210. if(makingTurn && ho->tempOwner == playerID) //we are moving our hero - we may need to update assigned path
  211. {
  212. if(details.result == TryMoveHero::TELEPORTATION || details.start == details.end)
  213. {
  214. if(adventureInt->terrain.currentPath)
  215. eraseCurrentPathOf(ho);
  216. return; //teleport - no fancy moving animation
  217. //TODO: smooth disappear / appear effect
  218. }
  219. if (details.result != TryMoveHero::SUCCESS && details.result != TryMoveHero::FAILED) //hero didn't change tile but visit succeeded
  220. {
  221. eraseCurrentPathOf(ho);
  222. }
  223. else if(adventureInt->terrain.currentPath && details.result == TryMoveHero::SUCCESS) //&& hero is moving
  224. {
  225. //remove one node from the path (the one we went)
  226. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  227. if(!adventureInt->terrain.currentPath->nodes.size()) //if it was the last one, remove entire path
  228. eraseCurrentPathOf(ho);
  229. }
  230. }
  231. if (details.result != TryMoveHero::SUCCESS) //hero failed to move
  232. {
  233. ho->isStanding = true;
  234. stillMoveHero.setn(STOP_MOVE);
  235. GH.totalRedraw();
  236. return;
  237. }
  238. initMovement(details, ho, hp);
  239. //first initializing done
  240. SDL_framerateDelay(mainFPSmng); // after first move
  241. //main moving
  242. for(int i=1; i<32; i+=2*sysOpts.heroMoveSpeed)
  243. {
  244. movementPxStep(details, i, hp, ho);
  245. adventureInt->updateScreen = true;
  246. adventureInt->show(screen);
  247. CSDL_Ext::update(screen);
  248. SDL_framerateDelay(mainFPSmng); //for animation purposes
  249. } //for(int i=1; i<32; i+=4)
  250. //main moving done
  251. //finishing move
  252. finishMovement(details, hp, ho);
  253. ho->isStanding = true;
  254. //move finished
  255. adventureInt->minimap.draw(screen2);
  256. adventureInt->heroList.updateMove(ho);
  257. //check if user cancelled movement
  258. {
  259. boost::unique_lock<boost::mutex> un(eventsM);
  260. while(events.size())
  261. {
  262. SDL_Event *ev = events.front();
  263. events.pop();
  264. switch(ev->type)
  265. {
  266. case SDL_MOUSEBUTTONDOWN:
  267. stillMoveHero.setn(STOP_MOVE);
  268. break;
  269. case SDL_KEYDOWN:
  270. if(ev->key.keysym.sym < SDLK_F1 || ev->key.keysym.sym > SDLK_F15)
  271. stillMoveHero.setn(STOP_MOVE);
  272. break;
  273. }
  274. delete ev;
  275. }
  276. }
  277. if(stillMoveHero.get() == WAITING_MOVE)
  278. stillMoveHero.setn(DURING_MOVE);
  279. }
  280. void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
  281. {
  282. boost::unique_lock<boost::recursive_mutex> un(*pim);
  283. wanderingHeroes -= hero;
  284. adventureInt->heroList.updateHList(hero);
  285. }
  286. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  287. {
  288. boost::unique_lock<boost::recursive_mutex> un(*pim);
  289. wanderingHeroes.push_back(hero);
  290. adventureInt->heroList.updateHList();
  291. }
  292. void CPlayerInterface::openTownWindow(const CGTownInstance * town)
  293. {
  294. castleInt = new CCastleInterface(town);
  295. GH.pushInt(castleInt);
  296. }
  297. SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
  298. {
  299. if(!specific)
  300. specific = adventureInt->selection;
  301. assert(specific);
  302. switch(specific->ID)
  303. {
  304. case HEROI_TYPE:
  305. {
  306. InfoAboutHero iah;
  307. bool gotInfo = LOCPLINT->cb->getHeroInfo(specific, iah);
  308. assert(gotInfo);
  309. return graphics->drawHeroInfoWin(iah);
  310. }
  311. case TOWNI_TYPE:
  312. case 33: // Garrison
  313. case 219:
  314. {
  315. InfoAboutTown iah;
  316. bool gotInfo = LOCPLINT->cb->getTownInfo(specific, iah);
  317. assert(gotInfo);
  318. return graphics->drawTownInfoWin(iah);
  319. }
  320. default:
  321. return NULL;
  322. }
  323. }
  324. int3 CPlayerInterface::repairScreenPos(int3 pos)
  325. {
  326. if(pos.x<-CGI->mh->frameW)
  327. pos.x = -CGI->mh->frameW;
  328. if(pos.y<-CGI->mh->frameH)
  329. pos.y = -CGI->mh->frameH;
  330. if(pos.x>CGI->mh->map->width - adventureInt->terrain.tilesw + CGI->mh->frameW)
  331. pos.x = CGI->mh->map->width - adventureInt->terrain.tilesw + CGI->mh->frameW;
  332. if(pos.y>CGI->mh->map->height - adventureInt->terrain.tilesh + CGI->mh->frameH)
  333. pos.y = CGI->mh->map->height - adventureInt->terrain.tilesh + CGI->mh->frameH;
  334. return pos;
  335. }
  336. void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val)
  337. {
  338. if(which >= PRIMARY_SKILLS) //no need to redraw infowin if this is experience (exp is treated as prim skill with id==4)
  339. return;
  340. boost::unique_lock<boost::recursive_mutex> un(*pim);
  341. updateInfo(hero);
  342. }
  343. void CPlayerInterface::heroManaPointsChanged(const CGHeroInstance * hero)
  344. {
  345. boost::unique_lock<boost::recursive_mutex> un(*pim);
  346. updateInfo(hero);
  347. }
  348. void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero)
  349. {
  350. boost::unique_lock<boost::recursive_mutex> un(*pim);
  351. if(makingTurn && hero->tempOwner == playerID)
  352. adventureInt->heroList.redraw();
  353. }
  354. void CPlayerInterface::receivedResource(int type, int val)
  355. {
  356. boost::unique_lock<boost::recursive_mutex> un(*pim);
  357. GH.totalRedraw();
  358. }
  359. void CPlayerInterface::heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16>& skills, boost::function<void(ui32)> &callback)
  360. {
  361. waitWhileDialog();
  362. CGI->soundh->playSound(soundBase::heroNewLevel);
  363. boost::unique_lock<boost::recursive_mutex> un(*pim);
  364. CLevelWindow *lw = new CLevelWindow(hero,pskill,skills,callback);
  365. GH.pushInt(lw);
  366. }
  367. void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
  368. {
  369. boost::unique_lock<boost::recursive_mutex> un(*pim);
  370. updateInfo(town);
  371. if(town->garrisonHero && vstd::contains(wanderingHeroes,town->garrisonHero)) //wandering hero moved to the garrison
  372. {
  373. CGI->mh->hideObject(town->garrisonHero);
  374. wanderingHeroes -= town->garrisonHero;
  375. }
  376. if(town->visitingHero && !vstd::contains(wanderingHeroes,town->visitingHero)) //hero leaves garrison
  377. {
  378. CGI->mh->printObject(town->visitingHero);
  379. wanderingHeroes.push_back(town->visitingHero);
  380. }
  381. //adventureInt->heroList.updateHList();
  382. CCastleInterface *c = castleInt;
  383. if(c)
  384. {
  385. c->garr->highlighted = NULL;
  386. c->hslotup.hero = town->garrisonHero;
  387. c->garr->odown = c->hslotdown.hero = town->visitingHero;
  388. c->garr->set2 = town->visitingHero ? &town->visitingHero->army : NULL;
  389. c->garr->recreateSlots();
  390. }
  391. GH.totalRedraw();
  392. }
  393. void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town)
  394. {
  395. if(hero->tempOwner != town->tempOwner)
  396. return;
  397. boost::unique_lock<boost::recursive_mutex> un(*pim);
  398. openTownWindow(town);
  399. }
  400. void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
  401. {
  402. boost::unique_lock<boost::recursive_mutex> un(*pim);
  403. updateInfo(obj);
  404. bool wasGarrison = false;
  405. for(std::list<IShowActivable*>::iterator i = GH.listInt.begin(); i != GH.listInt.end(); i++)
  406. {
  407. if((*i)->type & IShowActivable::WITH_GARRISON)
  408. {
  409. CWindowWithGarrison *wwg = static_cast<CWindowWithGarrison*>(*i);
  410. wwg->garr->recreateSlots();
  411. wasGarrison = true;
  412. }
  413. else
  414. {//a cheat for Kingdom Overview window (it has CWindowWithGarrison-childrens which are not present in ListInt)
  415. CKingdomInterface *cki = dynamic_cast<CKingdomInterface*>(*i);//need to create "Garrison Holder" class thingy
  416. if (cki)
  417. cki->updateAllGarrisons();
  418. }
  419. }
  420. GH.totalRedraw();
  421. }
  422. void CPlayerInterface::buildChanged(const CGTownInstance *town, int buildingID, int what) //what: 1 - built, 2 - demolished
  423. {
  424. boost::unique_lock<boost::recursive_mutex> un(*pim);
  425. switch (buildingID)
  426. {
  427. case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 15:
  428. updateInfo(town);
  429. break;
  430. }
  431. if(!castleInt)
  432. return;
  433. if(castleInt->town!=town)
  434. return;
  435. switch(what)
  436. {
  437. case 1:
  438. CGI->soundh->playSound(soundBase::newBuilding);
  439. castleInt->addBuilding(buildingID);
  440. break;
  441. case 2:
  442. castleInt->removeBuilding(buildingID);
  443. break;
  444. }
  445. }
  446. void CPlayerInterface::battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side) //called by engine when battle starts; side=0 - left, side=1 - right
  447. {
  448. if(LOCPLINT != this)
  449. { //another local interface should do this
  450. return;
  451. }
  452. while(showingDialog->get())
  453. SDL_Delay(20);
  454. boost::unique_lock<boost::recursive_mutex> un(*pim);
  455. CGI->musich->playMusicFromSet(CGI->musich->battleMusics, -1);
  456. GH.pushInt(battleInt);
  457. }
  458. void CPlayerInterface::battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles) //called when battlefield is prepared, prior the battle beginning
  459. {
  460. }
  461. void CPlayerInterface::battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks)
  462. {
  463. if(LOCPLINT != this)
  464. { //another local interface should do this
  465. return;
  466. }
  467. for(int b=0; b<healedStacks.size(); ++b)
  468. {
  469. const CStack * healed = cb->battleGetStackByID(healedStacks[b].first);
  470. if(battleInt->creAnims[healed->ID]->getType() == 5)
  471. {
  472. //stack has been resurrected
  473. battleInt->creAnims[healed->ID]->setType(2);
  474. }
  475. }
  476. }
  477. void CPlayerInterface::battleNewStackAppeared(int stackID)
  478. {
  479. if(LOCPLINT != this)
  480. { //another local interface should do this
  481. return;
  482. }
  483. //changing necessary things in battle interface
  484. battleInt->newStack(stackID);
  485. }
  486. void CPlayerInterface::battleObstaclesRemoved(const std::set<si32> & removedObstacles)
  487. {
  488. if(LOCPLINT != this)
  489. { //another local interface should do this
  490. return;
  491. }
  492. for(std::set<si32>::const_iterator it = removedObstacles.begin(); it != removedObstacles.end(); ++it)
  493. {
  494. for(std::map< int, CDefHandler * >::iterator itBat = battleInt->idToObstacle.begin(); itBat != battleInt->idToObstacle.end(); ++itBat)
  495. {
  496. if(itBat->first == *it) //remove this obstacle
  497. {
  498. battleInt->idToObstacle.erase(itBat);
  499. break;
  500. }
  501. }
  502. }
  503. //update accessible hexes
  504. battleInt->redrawBackgroundWithHexes(battleInt->activeStack);
  505. }
  506. void CPlayerInterface::battleCatapultAttacked(const CatapultAttack & ca)
  507. {
  508. if(LOCPLINT != this)
  509. { //another local interface should do this
  510. return;
  511. }
  512. battleInt->stackIsCatapulting(ca);
  513. }
  514. void CPlayerInterface::battleStacksRemoved(const BattleStacksRemoved & bsr)
  515. {
  516. if(LOCPLINT != this)
  517. { //another local interface should do this
  518. return;
  519. }
  520. for(std::set<ui32>::const_iterator it = bsr.stackIDs.begin(); it != bsr.stackIDs.end(); ++it) //for each removed stack
  521. {
  522. battleInt->stackRemoved(*it);
  523. }
  524. }
  525. void CPlayerInterface::battleNewRound(int round) //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  526. {
  527. if(LOCPLINT != this)
  528. { //another local interface should do this
  529. return;
  530. }
  531. boost::unique_lock<boost::recursive_mutex> un(*pim);
  532. battleInt->newRound(round);
  533. }
  534. void CPlayerInterface::actionStarted(const BattleAction* action)
  535. {
  536. if(LOCPLINT != this)
  537. { //another local interface should do this
  538. return;
  539. }
  540. boost::unique_lock<boost::recursive_mutex> un(*pim);
  541. curAction = new BattleAction(*action);
  542. battleInt->startAction(action);
  543. }
  544. void CPlayerInterface::actionFinished(const BattleAction* action)
  545. {
  546. if(LOCPLINT != this)
  547. { //another local interface should do this
  548. return;
  549. }
  550. boost::unique_lock<boost::recursive_mutex> un(*pim);
  551. delete curAction;
  552. curAction = NULL;
  553. battleInt->endAction(action);
  554. }
  555. BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
  556. {
  557. CBattleInterface *b = battleInt;
  558. {
  559. boost::unique_lock<boost::recursive_mutex> un(*pim);
  560. const CStack *stack = cb->battleGetStackByID(stackID);
  561. if(vstd::contains(stack->state,MOVED)) //this stack has moved and makes second action -> high morale
  562. {
  563. std::string hlp = CGI->generaltexth->allTexts[33];
  564. boost::algorithm::replace_first(hlp,"%s",(stack->amount != 1) ? stack->creature->namePl : stack->creature->nameSing);
  565. battleInt->displayEffect(20,stack->position);
  566. battleInt->console->addText(hlp);
  567. }
  568. b->stackActivated(stackID);
  569. }
  570. //wait till BattleInterface sets its command
  571. boost::unique_lock<boost::mutex> lock(b->givenCommand->mx);
  572. while(!b->givenCommand->data)
  573. b->givenCommand->cond.wait(lock);
  574. //tidy up
  575. BattleAction ret = *(b->givenCommand->data);
  576. delete b->givenCommand->data;
  577. b->givenCommand->data = NULL;
  578. //return command
  579. return ret;
  580. }
  581. void CPlayerInterface::battleEnd(BattleResult *br)
  582. {
  583. if(LOCPLINT != this)
  584. { //another local interface should do this
  585. return;
  586. }
  587. boost::unique_lock<boost::recursive_mutex> un(*pim);
  588. battleInt->battleFinished(*br);
  589. }
  590. void CPlayerInterface::battleStackMoved(int ID, int dest, int distance, bool end)
  591. {
  592. if(LOCPLINT != this)
  593. { //another local interface should do this
  594. return;
  595. }
  596. boost::unique_lock<boost::recursive_mutex> un(*pim);
  597. battleInt->stackMoved(ID, dest, end, distance);
  598. }
  599. void CPlayerInterface::battleSpellCast(SpellCast *sc)
  600. {
  601. if(LOCPLINT != this)
  602. { //another local interface should do this
  603. return;
  604. }
  605. boost::unique_lock<boost::recursive_mutex> un(*pim);
  606. battleInt->spellCast(sc);
  607. }
  608. void CPlayerInterface::battleStacksEffectsSet(SetStackEffect & sse)
  609. {
  610. if(LOCPLINT != this)
  611. { //another local interface should do this
  612. return;
  613. }
  614. boost::unique_lock<boost::recursive_mutex> un(*pim);
  615. battleInt->battleStacksEffectsSet(sse);
  616. }
  617. void CPlayerInterface::battleStacksAttacked(std::vector<BattleStackAttacked> & bsa)
  618. {
  619. if(LOCPLINT != this)
  620. { //another local interface should do this
  621. return;
  622. }
  623. tlog5 << "CPlayerInterface::battleStackAttacked - locking...";
  624. boost::unique_lock<boost::recursive_mutex> un(*pim);
  625. tlog5 << "done!\n";
  626. std::vector<SStackAttackedInfo> arg;
  627. for(std::vector<BattleStackAttacked>::iterator i = bsa.begin(); i != bsa.end(); i++)
  628. {
  629. if(i->isEffect() && i->effect != 12) //and not armageddon
  630. {
  631. const CStack *stack = cb->battleGetStackByID(i->stackAttacked, false);
  632. if (stack != NULL)
  633. battleInt->displayEffect(i->effect, stack->position);
  634. }
  635. SStackAttackedInfo to_put = {i->stackAttacked, i->damageAmount, i->killedAmount, i->attackerID, LOCPLINT->curAction->actionType==7, i->killed()};
  636. arg.push_back(to_put);
  637. }
  638. if(bsa.begin()->isEffect() && bsa.begin()->effect == 12) //for armageddon - I hope this condition is enough
  639. {
  640. battleInt->displayEffect(bsa.begin()->effect, -1);
  641. }
  642. battleInt->stacksAreAttacked(arg);
  643. }
  644. void CPlayerInterface::battleAttack(BattleAttack *ba)
  645. {
  646. if(LOCPLINT != this)
  647. { //another local interface should do this
  648. return;
  649. }
  650. tlog5 << "CPlayerInterface::battleAttack - locking...";
  651. boost::unique_lock<boost::recursive_mutex> un(*pim);
  652. tlog5 << "done!\n";
  653. assert(curAction);
  654. if(ba->lucky()) //lucky hit
  655. {
  656. const CStack *stack = cb->battleGetStackByID(ba->stackAttacking);
  657. std::string hlp = CGI->generaltexth->allTexts[45];
  658. boost::algorithm::replace_first(hlp,"%s",(stack->amount != 1) ? stack->creature->namePl.c_str() : stack->creature->nameSing.c_str());
  659. battleInt->console->addText(hlp);
  660. battleInt->displayEffect(18,stack->position);
  661. }
  662. //TODO: bad luck?
  663. if(ba->shot())
  664. {
  665. for(std::vector<BattleStackAttacked>::iterator i = ba->bsa.begin(); i != ba->bsa.end(); i++)
  666. battleInt->stackIsShooting(ba->stackAttacking,cb->battleGetPos(i->stackAttacked), i->stackAttacked);
  667. }
  668. else
  669. {//WARNING: does not support multiple attacked creatures
  670. const CStack * attacker = cb->battleGetStackByID(ba->stackAttacking);
  671. int shift = 0;
  672. if(ba->counter() && BattleInfo::mutualPosition(curAction->destinationTile, attacker->position) < 0)
  673. {
  674. if( BattleInfo::mutualPosition(curAction->destinationTile + 1, attacker->position) >= 0 )
  675. shift = 1;
  676. else
  677. shift = -1;
  678. }
  679. battleInt->stackAttacking( ba->stackAttacking, ba->counter() ? curAction->destinationTile + shift : curAction->additionalInfo, ba->bsa.begin()->stackAttacked );
  680. }
  681. }
  682. void CPlayerInterface::showComp(SComponent comp)
  683. {
  684. boost::unique_lock<boost::recursive_mutex> un(*pim);
  685. CGI->soundh->playSoundFromSet(CGI->soundh->pickupSounds);
  686. adventureInt->infoBar.showComp(&comp,4000);
  687. }
  688. void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID)
  689. {
  690. std::vector<SComponent*> intComps;
  691. for(int i=0;i<components.size();i++)
  692. intComps.push_back(new SComponent(*components[i]));
  693. showInfoDialog(text,intComps,soundID);
  694. }
  695. void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<SComponent*> & components, int soundID)
  696. {
  697. waitWhileDialog();
  698. boost::unique_lock<boost::recursive_mutex> un(*pim);
  699. if(stillMoveHero.get() == DURING_MOVE)//if we are in the middle of hero movement
  700. stillMoveHero.setn(STOP_MOVE); //after showing dialog movement will be stopped
  701. CInfoWindow *temp = CInfoWindow::create(text, playerID, &components);
  702. if(makingTurn && GH.listInt.size() && LOCPLINT == this)
  703. {
  704. CGI->soundh->playSound(static_cast<soundBase::soundID>(soundID));
  705. showingDialog->set(true);
  706. GH.pushInt(temp);
  707. }
  708. else
  709. {
  710. dialogs.push_back(temp);
  711. }
  712. }
  713. void CPlayerInterface::showYesNoDialog(const std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool DelComps)
  714. {
  715. boost::unique_lock<boost::recursive_mutex> un(*pim);
  716. LOCPLINT->showingDialog->setn(true);
  717. CInfoWindow::showYesNoDialog(text, &components, onYes, onNo, DelComps, playerID);
  718. }
  719. void CPlayerInterface::showBlockingDialog( const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel )
  720. {
  721. waitWhileDialog();
  722. boost::unique_lock<boost::recursive_mutex> un(*pim);
  723. CGI->soundh->playSound(static_cast<soundBase::soundID>(soundID));
  724. if(!selection && cancel) //simple yes/no dialog
  725. {
  726. std::vector<SComponent*> intComps;
  727. for(int i=0;i<components.size();i++)
  728. intComps.push_back(new SComponent(components[i])); //will be deleted by close in window
  729. showYesNoDialog(text,intComps,boost::bind(&CCallback::selectionMade,cb,1,askID),boost::bind(&CCallback::selectionMade,cb,0,askID),true);
  730. }
  731. else if(selection)
  732. {
  733. std::vector<CSelectableComponent*> intComps;
  734. for(int i=0;i<components.size();i++)
  735. intComps.push_back(new CSelectableComponent(components[i])); //will be deleted by CSelWindow::close
  736. std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
  737. pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
  738. if(cancel)
  739. {
  740. pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",0));
  741. }
  742. int charperline = 35;
  743. if (pom.size() > 1)
  744. charperline = 50;
  745. CSelWindow * temp = new CSelWindow(text, playerID, charperline, intComps, pom, askID);
  746. GH.pushInt(temp);
  747. intComps[0]->clickLeft(true, false);
  748. }
  749. }
  750. void CPlayerInterface::tileRevealed(const std::set<int3> &pos)
  751. {
  752. boost::unique_lock<boost::recursive_mutex> un(*pim);
  753. for(std::set<int3>::const_iterator i=pos.begin(); i!=pos.end();i++)
  754. adventureInt->minimap.showTile(*i);
  755. if(pos.size())
  756. GH.totalRedraw();
  757. }
  758. void CPlayerInterface::tileHidden(const std::set<int3> &pos)
  759. {
  760. boost::unique_lock<boost::recursive_mutex> un(*pim);
  761. for(std::set<int3>::const_iterator i=pos.begin(); i!=pos.end();i++)
  762. adventureInt->minimap.hideTile(*i);
  763. }
  764. void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
  765. {
  766. boost::unique_lock<boost::recursive_mutex> un(*pim);
  767. adventureInt->heroWindow->setHero(hero);
  768. adventureInt->heroWindow->quitButton->callback = boost::bind(&CHeroWindow::quit,adventureInt->heroWindow);
  769. GH.pushInt(adventureInt->heroWindow);
  770. }
  771. void CPlayerInterface::heroArtifactSetChanged(const CGHeroInstance*hero)
  772. {
  773. boost::unique_lock<boost::recursive_mutex> un(*pim);
  774. if(adventureInt->heroWindow->curHero) //hero window is opened
  775. {
  776. adventureInt->heroWindow->deactivate();
  777. adventureInt->heroWindow->setHero(adventureInt->heroWindow->curHero);
  778. adventureInt->heroWindow->activate();
  779. return;
  780. }
  781. CExchangeWindow* cew = dynamic_cast<CExchangeWindow*>(GH.topInt());
  782. if(cew) //exchange window is open
  783. {
  784. cew->deactivate();
  785. for(int g=0; g<ARRAY_COUNT(cew->heroInst); ++g)
  786. {
  787. if(cew->heroInst[g] == hero)
  788. {
  789. cew->artifs[g]->updateState = true;
  790. cew->artifs[g]->setHero(hero);
  791. cew->artifs[g]->updateState = false;
  792. }
  793. }
  794. cew->prepareBackground();
  795. cew->activate();
  796. }
  797. }
  798. void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
  799. {
  800. boost::unique_lock<boost::recursive_mutex> un(*pim);
  801. if(castleInt && town->ID == TOWNI_TYPE)
  802. {
  803. CFortScreen *fs = dynamic_cast<CFortScreen*>(GH.topInt());
  804. if(fs)
  805. fs->draw(castleInt,false);
  806. }
  807. else if(GH.listInt.size() && (town->ID == 17 || town->ID == 20)) //external dwelling
  808. {
  809. CRecruitmentWindow *crw = dynamic_cast<CRecruitmentWindow*>(GH.topInt());
  810. if(crw)
  811. crw->initCres();
  812. }
  813. }
  814. void CPlayerInterface::heroBonusChanged( const CGHeroInstance *hero, const HeroBonus &bonus, bool gain )
  815. {
  816. if(bonus.type == HeroBonus::NONE) return;
  817. boost::unique_lock<boost::recursive_mutex> un(*pim);
  818. updateInfo(hero);
  819. }
  820. template <typename Handler> void CPlayerInterface::serializeTempl( Handler &h, const int version )
  821. {
  822. h & playerID & serialID;
  823. h & sysOpts;
  824. }
  825. void CPlayerInterface::serialize( COSer<CSaveFile> &h, const int version )
  826. {
  827. serializeTempl(h,version);
  828. }
  829. void CPlayerInterface::serialize( CISer<CLoadFile> &h, const int version )
  830. {
  831. serializeTempl(h,version);
  832. sysOpts.apply();
  833. firstCall = -1;
  834. }
  835. bool CPlayerInterface::moveHero( const CGHeroInstance *h, CGPath path )
  836. {
  837. if (!h)
  838. return false; //can't find hero
  839. pim->unlock();
  840. bool result = false;
  841. {
  842. path.convert(0);
  843. boost::unique_lock<boost::mutex> un(stillMoveHero.mx);
  844. stillMoveHero.data = CONTINUE_MOVE;
  845. enum TerrainTile::EterrainType currentTerrain = TerrainTile::border; // not init yet
  846. enum TerrainTile::EterrainType newTerrain;
  847. int sh = -1;
  848. for(int i=path.nodes.size()-1; i>0 && stillMoveHero.data == CONTINUE_MOVE; i--)
  849. {
  850. //stop sending move requests if the next node can't be reached at the current turn (hero exhausted his move points)
  851. if(path.nodes[i-1].turns)
  852. {
  853. stillMoveHero.data = STOP_MOVE;
  854. break;
  855. }
  856. // Start a new sound for the hero movement or let the existing one carry on.
  857. #if 0
  858. // TODO
  859. if (hero is flying && sh == -1)
  860. sh = CGI->soundh->playSound(soundBase::horseFlying, -1);
  861. #endif
  862. {
  863. newTerrain = cb->getTileInfo(CGHeroInstance::convertPosition(path.nodes[i].coord, false))->tertype;
  864. if (newTerrain != currentTerrain) {
  865. CGI->soundh->stopSound(sh);
  866. sh = CGI->soundh->playSound(CGI->soundh->horseSounds[newTerrain], -1);
  867. currentTerrain = newTerrain;
  868. }
  869. }
  870. stillMoveHero.data = WAITING_MOVE;
  871. int3 endpos(path.nodes[i-1].coord.x, path.nodes[i-1].coord.y, h->pos.z);
  872. cb->moveHero(h,endpos);
  873. eventsM.unlock();
  874. while(stillMoveHero.data != STOP_MOVE && stillMoveHero.data != CONTINUE_MOVE)
  875. stillMoveHero.cond.wait(un);
  876. eventsM.lock();
  877. }
  878. CGI->soundh->stopSound(sh);
  879. cb->recalculatePaths();
  880. }
  881. pim->lock();
  882. return result;
  883. }
  884. bool CPlayerInterface::shiftPressed() const
  885. {
  886. return SDL_GetKeyState(NULL)[SDLK_LSHIFT] || SDL_GetKeyState(NULL)[SDLK_RSHIFT];
  887. }
  888. void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, boost::function<void()> &onEnd )
  889. {
  890. if(stillMoveHero.get() == DURING_MOVE && adventureInt->terrain.currentPath->nodes.size() > 1) //to ignore calls on passing through garrisons
  891. return;
  892. {
  893. boost::unique_lock<boost::mutex> un(showingDialog->mx);
  894. while(showingDialog->data)
  895. showingDialog->cond.wait(un);
  896. }
  897. boost::unique_lock<boost::recursive_mutex> un(*pim);
  898. while(dialogs.size())
  899. {
  900. pim->unlock();
  901. SDL_Delay(20);
  902. pim->lock();
  903. }
  904. CGarrisonWindow *cgw = new CGarrisonWindow(up,down,removableUnits);
  905. cgw->quit->callback += onEnd;
  906. GH.pushInt(cgw);
  907. }
  908. /**
  909. * Shows the dialog that appears when right-clicking an artifact that can be assembled
  910. * into a combinational one on an artifact screen. Does not require the combination of
  911. * artifacts to be legal.
  912. * @param artifactID ID of a constituent artifact.
  913. * @param assembleTo ID of artifact to assemble a constituent into, not used when assemble
  914. * is false.
  915. * @param assemble True if the artifact is to be assembled, false if it is to be disassembled.
  916. */
  917. void CPlayerInterface::showArtifactAssemblyDialog (ui32 artifactID, ui32 assembleTo, bool assemble, CFunctionList<void()> onYes, CFunctionList<void()> onNo)
  918. {
  919. const CArtifact &artifact = CGI->arth->artifacts[artifactID];
  920. std::string text = artifact.Description();
  921. text += "\n\n";
  922. std::vector<SComponent*> scs;
  923. if (assemble) {
  924. const CArtifact &assembledArtifact = CGI->arth->artifacts[assembleTo];
  925. // You possess all of the components to...
  926. text += boost::str(boost::format(CGI->generaltexth->allTexts[732]) % assembledArtifact.Name());
  927. // Picture of assembled artifact at bottom.
  928. SComponent* sc = new SComponent;
  929. sc->type = SComponent::artifact;
  930. sc->subtype = assembledArtifact.id;
  931. sc->description = assembledArtifact.Description();
  932. sc->subtitle = assembledArtifact.Name();
  933. scs.push_back(sc);
  934. } else {
  935. // Do you wish to disassemble this artifact?
  936. text += CGI->generaltexth->allTexts[733];
  937. }
  938. showYesNoDialog(text, scs, onYes, onNo, true);
  939. }
  940. void CPlayerInterface::requestRealized( PackageApplied *pa )
  941. {
  942. if(stillMoveHero.get() == DURING_MOVE)
  943. stillMoveHero.setn(CONTINUE_MOVE);
  944. }
  945. void CPlayerInterface::heroExchangeStarted(si32 hero1, si32 hero2)
  946. {
  947. boost::unique_lock<boost::recursive_mutex> un(*pim);
  948. GH.pushInt(new CExchangeWindow(hero2, hero1));
  949. }
  950. void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop)
  951. {
  952. //redraw minimap if owner changed
  953. boost::unique_lock<boost::recursive_mutex> un(*pim);
  954. if(sop->what == 1)
  955. {
  956. const CGObjectInstance * obj = cb->getObjectInfo(sop->id);
  957. std::set<int3> pos = obj->getBlockedPos();
  958. for(std::set<int3>::const_iterator it = pos.begin(); it != pos.end(); ++it)
  959. {
  960. if(cb->isVisible(*it))
  961. adventureInt->minimap.showTile(*it);
  962. }
  963. if(obj->ID == TOWNI_TYPE)
  964. if(obj->tempOwner == playerID)
  965. towns.push_back(static_cast<const CGTownInstance *>(obj));
  966. else
  967. towns -= obj;
  968. assert(cb->getTownsInfo().size() == towns.size());
  969. }
  970. }
  971. void CPlayerInterface::recreateHeroTownList()
  972. {
  973. wanderingHeroes.clear();
  974. std::vector<const CGHeroInstance*> heroes = cb->getHeroesInfo();
  975. for(size_t i = 0; i < heroes.size(); i++)
  976. if(!heroes[i]->inTownGarrison)
  977. wanderingHeroes.push_back(heroes[i]);
  978. towns.clear();
  979. std::vector<const CGTownInstance*> townInfo = cb->getTownsInfo();
  980. for(size_t i = 0; i < townInfo.size(); i++)
  981. towns.push_back(townInfo[i]);
  982. }
  983. const CGHeroInstance * CPlayerInterface::getWHero( int pos )
  984. {
  985. if(pos < 0 || pos >= wanderingHeroes.size())
  986. return NULL;
  987. return wanderingHeroes[pos];
  988. }
  989. void CPlayerInterface::showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level)
  990. {
  991. waitWhileDialog();
  992. boost::unique_lock<boost::recursive_mutex> un(*pim);
  993. CRecruitmentWindow *cr = new CRecruitmentWindow(dwelling, level, dst, boost::bind(&CCallback::recruitCreatures, cb, dwelling, _1, _2));
  994. GH.pushInt(cr);
  995. }
  996. void CPlayerInterface::waitWhileDialog()
  997. {
  998. boost::unique_lock<boost::mutex> un(showingDialog->mx);
  999. while(showingDialog->data)
  1000. showingDialog->cond.wait(un);
  1001. }
  1002. void CPlayerInterface::showShipyardDialog(const IShipyard *obj)
  1003. {
  1004. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1005. int state = obj->state();
  1006. std::vector<si32> cost;
  1007. obj->getBoatCost(cost);
  1008. CShipyardWindow *csw = new CShipyardWindow(cost, state, obj->getBoatType(), boost::bind(&CCallback::buildBoat, cb, obj));
  1009. GH.pushInt(csw);
  1010. }
  1011. void CPlayerInterface::newObject( const CGObjectInstance * obj )
  1012. {
  1013. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1014. CGI->mh->printObject(obj);
  1015. //we might have built a boat in shipyard in opened town screen
  1016. if(obj->ID == 8
  1017. && LOCPLINT->castleInt
  1018. && obj->pos-obj->getVisitableOffset() == LOCPLINT->castleInt->town->bestLocation())
  1019. {
  1020. CGI->soundh->playSound(soundBase::newBuilding);
  1021. LOCPLINT->castleInt->recreateBuildings();
  1022. }
  1023. }
  1024. void CPlayerInterface::centerView (int3 pos, int focusTime)
  1025. {
  1026. adventureInt->centerOn (pos);
  1027. if(focusTime)
  1028. {
  1029. bool activeAdv = (GH.topInt() == adventureInt && adventureInt->isActive());
  1030. if(activeAdv)
  1031. adventureInt->deactivate();
  1032. SDL_Delay(focusTime);
  1033. if(activeAdv)
  1034. adventureInt->activate();
  1035. }
  1036. }
  1037. void CPlayerInterface::objectRemoved( const CGObjectInstance *obj )
  1038. {
  1039. if(obj->ID == HEROI_TYPE && obj->tempOwner == playerID)
  1040. {
  1041. const CGHeroInstance *h = static_cast<const CGHeroInstance*>(obj);
  1042. heroKilled(h);
  1043. }
  1044. }
  1045. bool CPlayerInterface::ctrlPressed() const
  1046. {
  1047. return SDL_GetKeyState(NULL)[SDLK_LCTRL] || SDL_GetKeyState(NULL)[SDLK_RCTRL];
  1048. }
  1049. void CPlayerInterface::update()
  1050. {
  1051. while(!terminate_cond.get() && !pim->try_lock()) //try acquiring long until it succeeds or we are told to terminate
  1052. boost::this_thread::sleep(boost::posix_time::milliseconds(15));
  1053. if(terminate_cond.get())
  1054. return;
  1055. //if there are any waiting dialogs, show them
  1056. if(dialogs.size() && !showingDialog->get())
  1057. {
  1058. showingDialog->set(true);
  1059. GH.pushInt(dialogs.front());
  1060. dialogs.pop_front();
  1061. }
  1062. GH.updateTime();
  1063. GH.handleEvents();
  1064. if(!adventureInt->isActive() && adventureInt->scrollingDir) //player forces map scrolling though interface is disabled
  1065. GH.totalRedraw();
  1066. else
  1067. GH.simpleRedraw();
  1068. CGI->curh->draw1();
  1069. CSDL_Ext::update(screen);
  1070. CGI->curh->draw2();
  1071. pim->unlock();
  1072. SDL_framerateDelay(mainFPSmng);
  1073. }
  1074. int CPlayerInterface::getLastIndex( std::string namePrefix)
  1075. {
  1076. using namespace boost::filesystem;
  1077. using namespace boost::algorithm;
  1078. std::map<std::time_t, int> dates; //save number => datestamp
  1079. directory_iterator enddir;
  1080. for (directory_iterator dir(GVCMIDirs.UserPath + "/Games"); dir!=enddir; dir++)
  1081. {
  1082. if(is_regular(dir->status()))
  1083. {
  1084. std::string name = dir->path().leaf();
  1085. if(starts_with(name, namePrefix) && ends_with(name, ".vlgm1"))
  1086. {
  1087. char nr = name[namePrefix.size()];
  1088. if(std::isdigit(nr))
  1089. {
  1090. dates[last_write_time(dir->path())] = boost::lexical_cast<int>(nr);
  1091. }
  1092. }
  1093. }
  1094. }
  1095. if(dates.size())
  1096. return (--dates.end())->second; //return latest file number
  1097. return 0;
  1098. }
  1099. void CPlayerInterface::initMovement( const TryMoveHero &details, const CGHeroInstance * ho, const int3 &hp )
  1100. {
  1101. if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl
  1102. {
  1103. //ho->moveDir = 1;
  1104. ho->isStanding = false;
  1105. CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -31)));
  1106. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, -31)));
  1107. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, -31)));
  1108. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, -31)));
  1109. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 1)));
  1110. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  1111. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  1112. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  1113. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 33)));
  1114. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  1115. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  1116. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  1117. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1118. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1119. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1120. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1121. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1122. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1123. }
  1124. else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t
  1125. {
  1126. //ho->moveDir = 2;
  1127. ho->isStanding = false;
  1128. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, -31)));
  1129. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, -31)));
  1130. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, -31)));
  1131. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  1132. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  1133. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  1134. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  1135. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  1136. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  1137. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1138. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1139. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1140. }
  1141. else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr
  1142. {
  1143. //ho->moveDir = 3;
  1144. ho->isStanding = false;
  1145. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, -31)));
  1146. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, -31)));
  1147. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, -31)));
  1148. CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -31)));
  1149. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  1150. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  1151. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  1152. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 1)));
  1153. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  1154. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  1155. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  1156. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 33)));
  1157. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1158. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1159. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1160. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1161. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1162. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1163. }
  1164. else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r
  1165. {
  1166. //ho->moveDir = 4;
  1167. ho->isStanding = false;
  1168. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  1169. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  1170. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  1171. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 0)));
  1172. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  1173. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  1174. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  1175. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 32)));
  1176. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1177. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1178. }
  1179. else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br
  1180. {
  1181. //ho->moveDir = 5;
  1182. ho->isStanding = false;
  1183. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  1184. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  1185. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  1186. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -1)));
  1187. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  1188. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  1189. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  1190. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 31)));
  1191. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, 63)));
  1192. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, 63)));
  1193. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, 63)));
  1194. CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 63)));
  1195. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1196. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1197. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1198. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1199. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1200. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1201. }
  1202. else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b
  1203. {
  1204. //ho->moveDir = 6;
  1205. ho->isStanding = false;
  1206. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  1207. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  1208. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  1209. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  1210. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  1211. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  1212. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, 63)));
  1213. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, 63)));
  1214. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, 63)));
  1215. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1216. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1217. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1218. }
  1219. else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl
  1220. {
  1221. //ho->moveDir = 7;
  1222. ho->isStanding = false;
  1223. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -1)));
  1224. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  1225. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  1226. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  1227. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 31)));
  1228. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  1229. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  1230. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  1231. CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 63)));
  1232. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, 63)));
  1233. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, 63)));
  1234. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, 63)));
  1235. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1236. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1237. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1238. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1239. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1240. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1241. }
  1242. else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l
  1243. {
  1244. //ho->moveDir = 8;
  1245. ho->isStanding = false;
  1246. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 0)));
  1247. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  1248. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  1249. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  1250. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 32)));
  1251. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  1252. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  1253. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  1254. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1255. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1256. }
  1257. }
  1258. void CPlayerInterface::movementPxStep( const TryMoveHero &details, int i, const int3 &hp, const CGHeroInstance * ho )
  1259. {
  1260. if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl
  1261. {
  1262. //setting advmap shift
  1263. adventureInt->terrain.moveX = i-32;
  1264. adventureInt->terrain.moveY = i-32;
  1265. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  1266. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  1267. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  1268. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  1269. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  1270. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  1271. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  1272. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  1273. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  1274. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  1275. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  1276. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  1277. }
  1278. else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t
  1279. {
  1280. //setting advmap shift
  1281. adventureInt->terrain.moveY = i-32;
  1282. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  1283. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  1284. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  1285. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  1286. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  1287. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  1288. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  1289. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  1290. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  1291. }
  1292. else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr
  1293. {
  1294. //setting advmap shift
  1295. adventureInt->terrain.moveX = -i+32;
  1296. adventureInt->terrain.moveY = i-32;
  1297. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  1298. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  1299. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  1300. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  1301. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  1302. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  1303. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  1304. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  1305. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  1306. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  1307. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  1308. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  1309. }
  1310. else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r
  1311. {
  1312. //setting advmap shift
  1313. adventureInt->terrain.moveX = -i+32;
  1314. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  1315. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  1316. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  1317. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  1318. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  1319. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  1320. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  1321. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  1322. }
  1323. else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br
  1324. {
  1325. //setting advmap shift
  1326. adventureInt->terrain.moveX = -i+32;
  1327. adventureInt->terrain.moveY = -i+32;
  1328. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  1329. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  1330. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  1331. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  1332. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  1333. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  1334. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  1335. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  1336. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  1337. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  1338. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  1339. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  1340. }
  1341. else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b
  1342. {
  1343. //setting advmap shift
  1344. adventureInt->terrain.moveY = -i+32;
  1345. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  1346. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  1347. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  1348. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  1349. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  1350. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  1351. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  1352. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  1353. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  1354. }
  1355. else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl
  1356. {
  1357. //setting advmap shift
  1358. adventureInt->terrain.moveX = i-32;
  1359. adventureInt->terrain.moveY = -i+32;
  1360. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  1361. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  1362. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  1363. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  1364. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  1365. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  1366. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  1367. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  1368. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  1369. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  1370. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  1371. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  1372. }
  1373. else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l
  1374. {
  1375. //setting advmap shift
  1376. adventureInt->terrain.moveX = i-32;
  1377. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  1378. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  1379. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  1380. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  1381. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  1382. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  1383. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  1384. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  1385. }
  1386. }
  1387. void CPlayerInterface::finishMovement( const TryMoveHero &details, const int3 &hp, const CGHeroInstance * ho )
  1388. {
  1389. adventureInt->terrain.moveX = adventureInt->terrain.moveY = 0;
  1390. if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl
  1391. {
  1392. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  1393. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1394. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1395. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1396. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1397. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  1398. }
  1399. else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t
  1400. {
  1401. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1402. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1403. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1404. }
  1405. else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr
  1406. {
  1407. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  1408. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1409. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  1410. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1411. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1412. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1413. }
  1414. else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r
  1415. {
  1416. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1417. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1418. }
  1419. else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br
  1420. {
  1421. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  1422. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1423. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  1424. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1425. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1426. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1427. }
  1428. else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b
  1429. {
  1430. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1431. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1432. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1433. }
  1434. else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl
  1435. {
  1436. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1437. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1438. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1439. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  1440. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1441. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  1442. }
  1443. else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l
  1444. {
  1445. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1446. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1447. }
  1448. //restoring good rects
  1449. subRect(details.end.x-2, details.end.y-1, details.end.z, genRect(32, 32, 0, 0), ho->id);
  1450. subRect(details.end.x-1, details.end.y-1, details.end.z, genRect(32, 32, 32, 0), ho->id);
  1451. subRect(details.end.x, details.end.y-1, details.end.z, genRect(32, 32, 64, 0), ho->id);
  1452. subRect(details.end.x-2, details.end.y, details.end.z, genRect(32, 32, 0, 32), ho->id);
  1453. subRect(details.end.x-1, details.end.y, details.end.z, genRect(32, 32, 32, 32), ho->id);
  1454. subRect(details.end.x, details.end.y, details.end.z, genRect(32, 32, 64, 32), ho->id);
  1455. //restoring good order of objects
  1456. std::stable_sort(CGI->mh->ttiles[details.end.x-2][details.end.y-1][details.end.z].objects.begin(), CGI->mh->ttiles[details.end.x-2][details.end.y-1][details.end.z].objects.end(), ocmptwo_cgin);
  1457. std::stable_sort(CGI->mh->ttiles[details.end.x-1][details.end.y-1][details.end.z].objects.begin(), CGI->mh->ttiles[details.end.x-1][details.end.y-1][details.end.z].objects.end(), ocmptwo_cgin);
  1458. std::stable_sort(CGI->mh->ttiles[details.end.x][details.end.y-1][details.end.z].objects.begin(), CGI->mh->ttiles[details.end.x][details.end.y-1][details.end.z].objects.end(), ocmptwo_cgin);
  1459. std::stable_sort(CGI->mh->ttiles[details.end.x-2][details.end.y][details.end.z].objects.begin(), CGI->mh->ttiles[details.end.x-2][details.end.y][details.end.z].objects.end(), ocmptwo_cgin);
  1460. std::stable_sort(CGI->mh->ttiles[details.end.x-1][details.end.y][details.end.z].objects.begin(), CGI->mh->ttiles[details.end.x-1][details.end.y][details.end.z].objects.end(), ocmptwo_cgin);
  1461. std::stable_sort(CGI->mh->ttiles[details.end.x][details.end.y][details.end.z].objects.begin(), CGI->mh->ttiles[details.end.x][details.end.y][details.end.z].objects.end(), ocmptwo_cgin);
  1462. }
  1463. void CPlayerInterface::gameOver(ui8 player, bool victory )
  1464. {
  1465. if(LOCPLINT != this)
  1466. return;
  1467. if(player == playerID)
  1468. {
  1469. if(!victory)
  1470. showInfoDialog(CGI->generaltexth->allTexts[95]);
  1471. // else
  1472. // showInfoDialog("Placeholder message: you won!");
  1473. makingTurn = true;
  1474. while(showingDialog->get() || dialogs.size()); //wait till all dialogs are displayed and closed
  1475. makingTurn = false;
  1476. //return to main menu
  1477. SDL_Event event;
  1478. event.type = SDL_USEREVENT;
  1479. event.user.code = 2;
  1480. SDL_PushEvent(&event);
  1481. }
  1482. else
  1483. {
  1484. if(!victory) //enemy has lost
  1485. {
  1486. std::string txt = CGI->generaltexth->allTexts[5]; //%s has been vanquished!
  1487. boost::algorithm::replace_first(txt, "%s", CGI->generaltexth->capColors[player]);
  1488. showInfoDialog(txt,std::vector<SComponent*>(1, new SComponent(SComponent::flag, player, 0)));
  1489. }
  1490. }
  1491. }
  1492. void CPlayerInterface::playerBonusChanged( const HeroBonus &bonus, bool gain )
  1493. {
  1494. }
  1495. void CPlayerInterface::showPuzzleMap()
  1496. {
  1497. waitWhileDialog();
  1498. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1499. //TODO: interface should not know the real position of Grail...
  1500. float ratio = 0;
  1501. int3 grailPos = cb->getGrailPos(ratio);
  1502. GH.pushInt(new CPuzzleWindow(grailPos, ratio));
  1503. }
  1504. void SystemOptions::setMusicVolume( int newVolume )
  1505. {
  1506. musicVolume = newVolume;
  1507. CGI->musich->setVolume(newVolume);
  1508. settingsChanged();
  1509. }
  1510. void SystemOptions::setSoundVolume( int newVolume )
  1511. {
  1512. soundVolume = newVolume;
  1513. CGI->soundh->setVolume(newVolume);
  1514. settingsChanged();
  1515. }
  1516. void SystemOptions::setHeroMoveSpeed( int newSpeed )
  1517. {
  1518. heroMoveSpeed = newSpeed;
  1519. settingsChanged();
  1520. }
  1521. void SystemOptions::setMapScrollingSpeed( int newSpeed )
  1522. {
  1523. mapScrollingSpeed = newSpeed;
  1524. settingsChanged();
  1525. }
  1526. void SystemOptions::settingsChanged()
  1527. {
  1528. CSaveFile settings(GVCMIDirs.UserPath + "/config/sysopts.bin");
  1529. if(settings.sfile)
  1530. settings << *this;
  1531. else
  1532. tlog1 << "Cannot save settings to config/sysopts.bin!\n";
  1533. }
  1534. void SystemOptions::apply()
  1535. {
  1536. if(CGI->musich->getVolume() != musicVolume)
  1537. CGI->musich->setVolume(musicVolume);
  1538. if(CGI->soundh->getVolume() != soundVolume)
  1539. CGI->soundh->setVolume(soundVolume);
  1540. settingsChanged();
  1541. }
  1542. SystemOptions::SystemOptions()
  1543. {
  1544. heroMoveSpeed = 2;
  1545. mapScrollingSpeed = 2;
  1546. musicVolume = 88;
  1547. soundVolume = 88;
  1548. printCellBorders = true;
  1549. printStackRange = true;
  1550. animSpeed = 2;
  1551. printMouseShadow = true;
  1552. showQueue = true;
  1553. }
  1554. void CPlayerInterface::eraseCurrentPathOf( const CGHeroInstance * ho )
  1555. {
  1556. assert(vstd::contains(paths, ho));
  1557. assert(ho == adventureInt->selection);
  1558. paths.erase(ho);
  1559. adventureInt->terrain.currentPath = NULL;
  1560. }
  1561. CGPath * CPlayerInterface::getAndVerifyPath(const CGHeroInstance * h)
  1562. {
  1563. if(vstd::contains(paths,h)) //hero has assigned path
  1564. {
  1565. CGPath &path = paths[h];
  1566. if(!path.nodes.size())
  1567. {
  1568. tlog3 << "Warning: empty path found...\n";
  1569. paths.erase(h);
  1570. }
  1571. else
  1572. {
  1573. assert(h->getPosition(false) == path.startPos());
  1574. //update the hero path in case of something has changed on map
  1575. if(LOCPLINT->cb->getPath2(path.endPos(), path))
  1576. return &path;
  1577. else
  1578. paths.erase(h);
  1579. }
  1580. }
  1581. return NULL;
  1582. }
  1583. void CPlayerInterface::acceptTurn()
  1584. {
  1585. waitWhileDialog();
  1586. if(howManyPeople > 1)
  1587. adventureInt->startTurn();
  1588. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1589. /* TODO: This isn't quite right. First day in game should play
  1590. * NEWDAY. And we don't play NEWMONTH. */
  1591. int day = cb->getDate(1);
  1592. if (day != 1)
  1593. CGI->soundh->playSound(soundBase::newDay);
  1594. else
  1595. CGI->soundh->playSound(soundBase::newWeek);
  1596. adventureInt->infoBar.newDay(day);
  1597. //select first hero if available.
  1598. //TODO: check if hero is slept
  1599. if(wanderingHeroes.size())
  1600. adventureInt->select(wanderingHeroes.front());
  1601. else
  1602. adventureInt->select(towns.front());
  1603. adventureInt->showAll(screen);
  1604. }
  1605. void CPlayerInterface::tryDiggging(const CGHeroInstance *h)
  1606. {
  1607. std::string hlp;
  1608. if(h->movement < h->maxMovePoints(true))
  1609. showInfoDialog(CGI->generaltexth->allTexts[56]); //"Digging for artifacts requires a whole day, try again tomorrow."
  1610. else if(cb->getTileInfo(h->getPosition(false))->tertype == TerrainTile::water)
  1611. showInfoDialog(CGI->generaltexth->allTexts[60]); //Try looking on land!
  1612. else
  1613. {
  1614. const TerrainTile *t = cb->getTileInfo(h->getPosition());
  1615. CGI->mh->getTerrainDescr(h->getPosition(false), hlp, false);
  1616. if(hlp.length() || t->blockingObjects.size() > 1)
  1617. showInfoDialog(CGI->generaltexth->allTexts[97]); //Try searching on clear ground.
  1618. else
  1619. cb->dig(h);
  1620. }
  1621. }
  1622. void CPlayerInterface::updateInfo(const CGObjectInstance * specific)
  1623. {
  1624. adventureInt->infoBar.updateSelection(specific);
  1625. // if (adventureInt->selection == specific)
  1626. // adventureInt->infoBar.showAll(screen);
  1627. }