CPlayerInterface.cpp 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418
  1. #include "StdInc.h"
  2. #include "CAdvmapInterface.h"
  3. #include "BattleInterface/CBattleInterface.h"
  4. #include "BattleInterface/CBattleInterfaceClasses.h"
  5. #include "../CCallback.h"
  6. #include "CCastleInterface.h"
  7. #include "UIFramework/CCursorHandler.h"
  8. #include "CKingdomInterface.h"
  9. #include "CGameInfo.h"
  10. #include "CHeroWindow.h"
  11. #include "CCreatureWindow.h"
  12. #include "CQuestLog.h"
  13. #include "CMessage.h"
  14. #include "CPlayerInterface.h"
  15. //#include "UIFramework/SDL_Extensions.h"
  16. #include "UIFramework/SDL_Extensions.h"
  17. #include "CConfigHandler.h"
  18. #include "BattleInterface/CCreatureAnimation.h"
  19. #include "Graphics.h"
  20. #include "../lib/CArtHandler.h"
  21. #include "../lib/CGeneralTextHandler.h"
  22. #include "../lib/CHeroHandler.h"
  23. #include "../lib/CLodHandler.h"
  24. #include "../lib/CObjectHandler.h"
  25. #include "../lib/Connection.h"
  26. #include "../lib/CSpellHandler.h"
  27. #include "../lib/CTownHandler.h"
  28. #include "../lib/BattleState.h"
  29. #include "../lib/JsonNode.h"
  30. #include "CMusicHandler.h"
  31. #include "../lib/CondSh.h"
  32. #include "../lib/NetPacks.h"
  33. #include "../lib/map.h"
  34. #include "../lib/VCMIDirs.h"
  35. #include "mapHandler.h"
  36. #include "../lib/CStopWatch.h"
  37. #include "../lib/StartInfo.h"
  38. #include "../lib/CGameState.h"
  39. #include "../lib/GameConstants.h"
  40. #include "UIFramework/CGuiHandler.h"
  41. #include "../lib/UnlockGuard.h"
  42. #ifdef min
  43. #undef min
  44. #endif
  45. #ifdef max
  46. #undef max
  47. #endif
  48. /*
  49. * CPlayerInterface.cpp, part of VCMI engine
  50. *
  51. * Authors: listed in file AUTHORS in main folder
  52. *
  53. * License: GNU General Public License v2.0 or later
  54. * Full text of license available in license.txt file, in main folder
  55. *
  56. */
  57. // The macro below is used to mark functions that are called by client when game state changes.
  58. // They all assume that CPlayerInterface::pim mutex is locked.
  59. #define EVENT_HANDLER_CALLED_BY_CLIENT
  60. // The macro marks functions that are run on a new thread by client.
  61. // They do not own any mutexes intiially.
  62. #define THREAD_CREATED_BY_CLIENT
  63. using namespace boost::assign;
  64. using namespace CSDL_Ext;
  65. void processCommand(const std::string &message, CClient *&client);
  66. extern std::queue<SDL_Event*> events;
  67. extern boost::mutex eventsM;
  68. boost::recursive_mutex * CPlayerInterface::pim = new boost::recursive_mutex;
  69. CPlayerInterface * LOCPLINT;
  70. CBattleInterface * CPlayerInterface::battleInt;
  71. enum EMoveState {STOP_MOVE, WAITING_MOVE, CONTINUE_MOVE, DURING_MOVE};
  72. CondSh<EMoveState> stillMoveHero; //used during hero movement
  73. int CPlayerInterface::howManyPeople = 0;
  74. struct OCM_HLP_CGIN
  75. {
  76. bool inline operator ()(const std::pair<const CGObjectInstance*,SDL_Rect> & a, const std::pair<const CGObjectInstance*,SDL_Rect> & b) const
  77. {
  78. return (*a.first)<(*b.first);
  79. }
  80. } ocmptwo_cgin ;
  81. CPlayerInterface::CPlayerInterface(int Player)
  82. {
  83. observerInDuelMode = false;
  84. howManyPeople++;
  85. GH.defActionsDef = 0;
  86. LOCPLINT = this;
  87. curAction = NULL;
  88. playerID=Player;
  89. human=true;
  90. castleInt = NULL;
  91. battleInt = NULL;
  92. //pim = new boost::recursive_mutex;
  93. makingTurn = false;
  94. showingDialog = new CondSh<bool>(false);
  95. cingconsole = new CInGameConsole;
  96. terminate_cond.set(false);
  97. firstCall = 1; //if loading will be overwritten in serialize
  98. autosaveCount = 0;
  99. }
  100. CPlayerInterface::~CPlayerInterface()
  101. {
  102. howManyPeople--;
  103. //delete pim;
  104. //vstd::clear_pointer(pim);
  105. delete showingDialog;
  106. if(adventureInt)
  107. {
  108. if(adventureInt->active & CIntObject::KEYBOARD)
  109. adventureInt->deactivateKeys();
  110. delete adventureInt;
  111. adventureInt = NULL;
  112. }
  113. delete cingconsole;
  114. LOCPLINT = NULL;
  115. }
  116. void CPlayerInterface::init(CCallback * CB)
  117. {
  118. cb = dynamic_cast<CCallback*>(CB);
  119. if(observerInDuelMode)
  120. return;
  121. if(!towns.size() && !wanderingHeroes.size())
  122. initializeHeroTownList();
  123. if(!adventureInt)
  124. adventureInt = new CAdvMapInt();
  125. }
  126. void CPlayerInterface::yourTurn()
  127. {
  128. EVENT_HANDLER_CALLED_BY_CLIENT;
  129. {
  130. boost::unique_lock<boost::mutex> lock(eventsM); //block handling events until interface is ready
  131. LOCPLINT = this;
  132. GH.curInt = this;
  133. adventureInt->selection = NULL;
  134. if(firstCall)
  135. {
  136. if(howManyPeople == 1)
  137. adventureInt->setPlayer(playerID);
  138. autosaveCount = getLastIndex("Autosave_");
  139. if(firstCall > 0) //new game, not loaded
  140. {
  141. int index = getLastIndex("Newgame_Autosave_");
  142. index %= SAVES_COUNT;
  143. cb->save("Newgame_Autosave_" + boost::lexical_cast<std::string>(index + 1));
  144. }
  145. firstCall = 0;
  146. }
  147. else
  148. {
  149. LOCPLINT->cb->save("Autosave_" + boost::lexical_cast<std::string>(autosaveCount++ + 1));
  150. autosaveCount %= 5;
  151. }
  152. if(adventureInt->player != playerID)
  153. adventureInt->setPlayer(playerID);
  154. if(howManyPeople > 1) //hot seat message
  155. {
  156. adventureInt->startHotSeatWait(playerID);
  157. makingTurn = true;
  158. std::string msg = CGI->generaltexth->allTexts[13];
  159. boost::replace_first(msg, "%s", cb->getStartInfo()->playerInfos.find(playerID)->second.name);
  160. std::vector<CComponent*> cmp;
  161. cmp.push_back(new CComponent(CComponent::flag, playerID, 0));
  162. showInfoDialog(msg, cmp);
  163. }
  164. else
  165. {
  166. makingTurn = true;
  167. adventureInt->startTurn();
  168. }
  169. }
  170. acceptTurn();
  171. }
  172. STRONG_INLINE void subRect(const int & x, const int & y, const int & z, const SDL_Rect & r, const int & hid)
  173. {
  174. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  175. for(int h=0; h<hlp.objects.size(); ++h)
  176. if(hlp.objects[h].first->id==hid)
  177. {
  178. hlp.objects[h].second = r;
  179. return;
  180. }
  181. }
  182. STRONG_INLINE void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  183. {
  184. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  185. for(int h=0; h<hlp.objects.size(); ++h)
  186. if(hlp.objects[h].first->id==hid)
  187. {
  188. hlp.objects.erase(hlp.objects.begin()+h);
  189. return;
  190. }
  191. }
  192. void CPlayerInterface::heroMoved(const TryMoveHero & details)
  193. {
  194. EVENT_HANDLER_CALLED_BY_CLIENT;
  195. waitWhileDialog();
  196. if(LOCPLINT != this)
  197. return;
  198. const CGHeroInstance * ho = cb->getHero(details.id); //object representing this hero
  199. int3 hp = details.start;
  200. if(!ho)
  201. {
  202. //AI hero left the visible area (we can't obtain info)
  203. //TODO very evil workaround -> retreive pointer to hero so we could animate it
  204. // TODO -> we should not need full CGHeroInstance structure to display animation or it should not be handled by playerint (but by the client itself)
  205. const TerrainTile2 &tile = CGI->mh->ttiles[hp.x-1][hp.y][hp.z];
  206. for(int i = 0; i < tile.objects.size(); i++)
  207. if(tile.objects[i].first->id == details.id)
  208. ho = dynamic_cast<const CGHeroInstance *>(tile.objects[i].first);
  209. if(!ho) //still nothing...
  210. return;
  211. }
  212. adventureInt->centerOn(ho); //actualizing screen pos
  213. adventureInt->minimap.redraw();
  214. adventureInt->heroList.redraw();
  215. bool directlyAttackingCreature =
  216. CGI->mh->map->isInTheMap(details.attackedFrom)
  217. && adventureInt->terrain.currentPath //in case if movement has been canceled in the meantime and path was already erased
  218. && adventureInt->terrain.currentPath->nodes.size() == 3;//FIXME should be 2 but works nevertheless...
  219. if(makingTurn && ho->tempOwner == playerID) //we are moving our hero - we may need to update assigned path
  220. {
  221. //We may need to change music - select new track, music handler will change it if needed
  222. CCS->musich->playMusic(CCS->musich->terrainMusics[LOCPLINT->cb->getTile(ho->visitablePos())->tertype], -1);
  223. if(details.result == TryMoveHero::TELEPORTATION)
  224. {
  225. if(adventureInt->terrain.currentPath)
  226. {
  227. assert(adventureInt->terrain.currentPath->nodes.size() >= 2);
  228. std::vector<CGPathNode>::const_iterator nodesIt = adventureInt->terrain.currentPath->nodes.end() - 1;
  229. if((nodesIt)->coord == CGHeroInstance::convertPosition(details.start, false)
  230. && (nodesIt-1)->coord == CGHeroInstance::convertPosition(details.end, false))
  231. {
  232. //path was between entrance and exit of teleport -> OK, erase node as usual
  233. removeLastNodeFromPath(ho);
  234. }
  235. else
  236. {
  237. //teleport was not along current path, it'll now be invalid (hero is somewhere else)
  238. eraseCurrentPathOf(ho);
  239. }
  240. }
  241. return; //teleport - no fancy moving animation
  242. //TODO: smooth disappear / appear effect
  243. }
  244. if (ho->pos != details.end //hero didn't change tile but visit succeeded
  245. || directlyAttackingCreature) // or creature was attacked from endangering tile.
  246. {
  247. eraseCurrentPathOf(ho);
  248. }
  249. else if(adventureInt->terrain.currentPath && ho->pos == details.end) //&& hero is moving
  250. {
  251. if(details.start != details.end) //so we don't touch path when revisiting with spacebar
  252. removeLastNodeFromPath(ho);
  253. }
  254. }
  255. if (details.result != TryMoveHero::SUCCESS) //hero failed to move
  256. {
  257. ho->isStanding = true;
  258. stillMoveHero.setn(STOP_MOVE);
  259. GH.totalRedraw();
  260. return;
  261. }
  262. initMovement(details, ho, hp);
  263. //first initializing done
  264. GH.mainFPSmng->framerateDelay(); // after first move
  265. ui32 speed = settings["adventure"]["heroSpeed"].Float();
  266. //main moving
  267. for(int i=1; i<32; i+=2*speed)
  268. {
  269. movementPxStep(details, i, hp, ho);
  270. adventureInt->updateScreen = true;
  271. adventureInt->show(screen);
  272. CSDL_Ext::update(screen);
  273. GH.mainFPSmng->framerateDelay(); //for animation purposes
  274. } //for(int i=1; i<32; i+=4)
  275. //main moving done
  276. //finishing move
  277. finishMovement(details, hp, ho);
  278. ho->isStanding = true;
  279. //move finished
  280. adventureInt->minimap.redraw();
  281. adventureInt->heroList.update(ho);
  282. //check if user cancelled movement
  283. {
  284. boost::unique_lock<boost::mutex> un(eventsM);
  285. while(events.size())
  286. {
  287. SDL_Event *ev = events.front();
  288. events.pop();
  289. switch(ev->type)
  290. {
  291. case SDL_MOUSEBUTTONDOWN:
  292. stillMoveHero.setn(STOP_MOVE);
  293. break;
  294. case SDL_KEYDOWN:
  295. if(ev->key.keysym.sym < SDLK_F1 || ev->key.keysym.sym > SDLK_F15)
  296. stillMoveHero.setn(STOP_MOVE);
  297. break;
  298. }
  299. delete ev;
  300. }
  301. }
  302. if(stillMoveHero.get() == WAITING_MOVE)
  303. stillMoveHero.setn(DURING_MOVE);
  304. // Hero attacked creature directly, set direction to face it.
  305. if (directlyAttackingCreature) {
  306. // Get direction to attacker.
  307. int3 posOffset = details.attackedFrom - details.end + int3(2, 1, 0);
  308. static const ui8 dirLookup[3][3] = {
  309. { 1, 2, 3 },
  310. { 8, 0, 4 },
  311. { 7, 6, 5 }
  312. };
  313. // FIXME: Avoid const_cast, make moveDir mutable in some other way?
  314. const_cast<CGHeroInstance *>(ho)->moveDir = dirLookup[posOffset.y][posOffset.x];
  315. }
  316. }
  317. void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
  318. {
  319. EVENT_HANDLER_CALLED_BY_CLIENT;
  320. const CArmedInstance *newSelection = nullptr;
  321. if (makingTurn)
  322. {
  323. //find new object for selection: either hero
  324. int next = adventureInt->getNextHeroIndex(vstd::find_pos(wanderingHeroes, hero));
  325. if (next >= 0)
  326. newSelection = wanderingHeroes[next];
  327. //or town
  328. if (!newSelection || newSelection == hero)
  329. {
  330. if (towns.empty())
  331. newSelection = nullptr;
  332. else
  333. newSelection = towns.front();
  334. }
  335. }
  336. wanderingHeroes -= hero;
  337. if(vstd::contains(paths, hero))
  338. paths.erase(hero);
  339. adventureInt->heroList.update(hero);
  340. if (makingTurn)
  341. adventureInt->select(newSelection, true);
  342. else
  343. adventureInt->selection = nullptr;
  344. }
  345. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  346. {
  347. EVENT_HANDLER_CALLED_BY_CLIENT;
  348. wanderingHeroes.push_back(hero);
  349. adventureInt->heroList.update(hero);
  350. }
  351. void CPlayerInterface::openTownWindow(const CGTownInstance * town)
  352. {
  353. if (castleInt)
  354. castleInt->close();
  355. castleInt = new CCastleInterface(town);
  356. GH.pushInt(castleInt);
  357. }
  358. int3 CPlayerInterface::repairScreenPos(int3 pos)
  359. {
  360. if(pos.x<-CGI->mh->frameW)
  361. pos.x = -CGI->mh->frameW;
  362. if(pos.y<-CGI->mh->frameH)
  363. pos.y = -CGI->mh->frameH;
  364. if(pos.x>CGI->mh->sizes.x - adventureInt->terrain.tilesw + CGI->mh->frameW)
  365. pos.x = CGI->mh->sizes.x - adventureInt->terrain.tilesw + CGI->mh->frameW;
  366. if(pos.y>CGI->mh->sizes.y - adventureInt->terrain.tilesh + CGI->mh->frameH)
  367. pos.y = CGI->mh->sizes.y - adventureInt->terrain.tilesh + CGI->mh->frameH;
  368. return pos;
  369. }
  370. void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val)
  371. {
  372. EVENT_HANDLER_CALLED_BY_CLIENT;
  373. if(which == 4)
  374. {
  375. if(CAltarWindow *ctw = dynamic_cast<CAltarWindow *>(GH.topInt()))
  376. ctw->setExpToLevel();
  377. }
  378. else if(which < GameConstants::PRIMARY_SKILLS) //no need to redraw infowin if this is experience (exp is treated as prim skill with id==4)
  379. updateInfo(hero);
  380. }
  381. void CPlayerInterface::heroSecondarySkillChanged(const CGHeroInstance * hero, int which, int val)
  382. {
  383. EVENT_HANDLER_CALLED_BY_CLIENT;
  384. CUniversityWindow* cuw = dynamic_cast<CUniversityWindow*>(GH.topInt());
  385. if(cuw) //university window is open
  386. {
  387. GH.totalRedraw();
  388. }
  389. }
  390. void CPlayerInterface::heroManaPointsChanged(const CGHeroInstance * hero)
  391. {
  392. EVENT_HANDLER_CALLED_BY_CLIENT;
  393. updateInfo(hero);
  394. if(makingTurn && hero->tempOwner == playerID)
  395. adventureInt->heroList.update(hero);
  396. }
  397. void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero)
  398. {
  399. EVENT_HANDLER_CALLED_BY_CLIENT;
  400. if(makingTurn && hero->tempOwner == playerID)
  401. adventureInt->heroList.update(hero);
  402. }
  403. void CPlayerInterface::receivedResource(int type, int val)
  404. {
  405. EVENT_HANDLER_CALLED_BY_CLIENT;
  406. if(CMarketplaceWindow *mw = dynamic_cast<CMarketplaceWindow *>(GH.topInt()))
  407. mw->resourceChanged(type, val);
  408. GH.totalRedraw();
  409. }
  410. void CPlayerInterface::heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16>& skills, boost::function<void(ui32)> &callback)
  411. {
  412. EVENT_HANDLER_CALLED_BY_CLIENT;
  413. waitWhileDialog();
  414. CCS->soundh->playSound(soundBase::heroNewLevel);
  415. CLevelWindow *lw = new CLevelWindow(hero,pskill,skills,callback);
  416. GH.pushInt(lw);
  417. }
  418. void CPlayerInterface::commanderGotLevel (const CCommanderInstance * commander, std::vector<ui32> skills, boost::function<void(ui32)> &callback)
  419. {
  420. EVENT_HANDLER_CALLED_BY_CLIENT;
  421. waitWhileDialog();
  422. CCS->soundh->playSound(soundBase::heroNewLevel);
  423. CCreatureWindow * cw = new CCreatureWindow(skills, commander, callback);
  424. GH.pushInt(cw);
  425. }
  426. void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
  427. {
  428. EVENT_HANDLER_CALLED_BY_CLIENT;
  429. updateInfo(town);
  430. if(town->garrisonHero && vstd::contains(wanderingHeroes,town->garrisonHero)) //wandering hero moved to the garrison
  431. {
  432. CGI->mh->hideObject(town->garrisonHero);
  433. wanderingHeroes -= town->garrisonHero;
  434. }
  435. if(town->visitingHero && !vstd::contains(wanderingHeroes,town->visitingHero)) //hero leaves garrison
  436. {
  437. CGI->mh->printObject(town->visitingHero);
  438. wanderingHeroes.push_back(town->visitingHero);
  439. }
  440. adventureInt->heroList.update();
  441. adventureInt->updateNextHero(NULL);
  442. if(CCastleInterface *c = castleInt)
  443. {
  444. c->garr->highlighted = NULL;
  445. c->garr->setArmy(town->getUpperArmy(), 0);
  446. c->garr->setArmy(town->visitingHero, 1);
  447. c->garr->recreateSlots();
  448. c->heroes->update();
  449. }
  450. BOOST_FOREACH(IShowActivatable *isa, GH.listInt)
  451. {
  452. CKingdomInterface *ki = dynamic_cast<CKingdomInterface*>(isa);
  453. if (ki)
  454. {
  455. ki->townChanged(town);
  456. ki->updateGarrisons();
  457. }
  458. }
  459. GH.totalRedraw();
  460. }
  461. void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town)
  462. {
  463. EVENT_HANDLER_CALLED_BY_CLIENT;
  464. if(hero->tempOwner != playerID )
  465. return;
  466. waitWhileDialog();
  467. openTownWindow(town);
  468. }
  469. void CPlayerInterface::garrisonChanged( const CGObjectInstance * obj)
  470. {
  471. boost::unique_lock<boost::recursive_mutex> un(*pim);
  472. updateInfo(obj);
  473. for(std::list<IShowActivatable*>::iterator i = GH.listInt.begin(); i != GH.listInt.end(); i++)
  474. {
  475. CGarrisonHolder *cgh = dynamic_cast<CGarrisonHolder*>(*i);
  476. if (cgh)
  477. cgh->updateGarrisons();
  478. if(CTradeWindow *cmw = dynamic_cast<CTradeWindow*>(*i))
  479. {
  480. if(obj == cmw->hero)
  481. cmw->garrisonChanged();
  482. }
  483. }
  484. GH.totalRedraw();
  485. }
  486. void CPlayerInterface::buildChanged(const CGTownInstance *town, int buildingID, int what) //what: 1 - built, 2 - demolished
  487. {
  488. EVENT_HANDLER_CALLED_BY_CLIENT;
  489. switch (buildingID)
  490. {
  491. case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 15:
  492. updateInfo(town);
  493. break;
  494. }
  495. if(!castleInt)
  496. return;
  497. if(castleInt->town!=town)
  498. return;
  499. switch(what)
  500. {
  501. case 1:
  502. CCS->soundh->playSound(soundBase::newBuilding);
  503. castleInt->addBuilding(buildingID);
  504. break;
  505. case 2:
  506. castleInt->removeBuilding(buildingID);
  507. break;
  508. }
  509. adventureInt->townList.update(town);
  510. castleInt->townlist->update(town);
  511. }
  512. void CPlayerInterface::battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side)
  513. {
  514. EVENT_HANDLER_CALLED_BY_CLIENT;
  515. if(LOCPLINT != this)
  516. { //another local interface should do this
  517. return;
  518. }
  519. waitForAllDialogs();
  520. GH.pushInt(battleInt);
  521. }
  522. void CPlayerInterface::battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks, bool lifeDrain, bool tentHeal, si32 lifeDrainFrom)
  523. {
  524. EVENT_HANDLER_CALLED_BY_CLIENT;
  525. if(LOCPLINT != this)
  526. { //another local interface should do this
  527. return;
  528. }
  529. for(int b=0; b<healedStacks.size(); ++b)
  530. {
  531. const CStack * healed = cb->battleGetStackByID(healedStacks[b].first);
  532. if(battleInt->creAnims[healed->ID]->getType() == CCreatureAnim::DEATH)
  533. {
  534. //stack has been resurrected
  535. battleInt->creAnims[healed->ID]->setType(CCreatureAnim::HOLDING);
  536. }
  537. }
  538. if (lifeDrain)
  539. {
  540. const CStack *attacker = cb->battleGetStackByID(healedStacks[0].first, false);
  541. const CStack *defender = cb->battleGetStackByID(lifeDrainFrom, false);
  542. int textOff = 0;
  543. if (attacker)
  544. {
  545. battleInt->displayEffect(52, attacker->position); //TODO: transparency
  546. if (attacker->count > 1)
  547. {
  548. textOff += 1;
  549. }
  550. CCS->soundh->playSound(soundBase::DRAINLIF);
  551. }
  552. //print info about life drain
  553. char textBuf[1000];
  554. sprintf(textBuf, CGI->generaltexth->allTexts[361 + textOff].c_str(), attacker->getCreature()->nameSing.c_str(),
  555. healedStacks[0].second, defender->getCreature()->namePl.c_str());
  556. battleInt->console->addText(textBuf);
  557. }
  558. if (tentHeal)
  559. {
  560. std::string text = CGI->generaltexth->allTexts[414];
  561. boost::algorithm::replace_first(text, "%s", cb->battleGetStackByID(lifeDrainFrom, false)->getCreature()->nameSing);
  562. boost::algorithm::replace_first(text, "%s", cb->battleGetStackByID(healedStacks[0].first, false)->getCreature()->nameSing);
  563. boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(healedStacks[0].second));
  564. battleInt->console->addText(text);
  565. }
  566. }
  567. void CPlayerInterface::battleNewStackAppeared(const CStack * stack)
  568. {
  569. EVENT_HANDLER_CALLED_BY_CLIENT;
  570. if(LOCPLINT != this)
  571. { //another local interface should do this
  572. return;
  573. }
  574. battleInt->newStack(stack);
  575. }
  576. void CPlayerInterface::battleObstaclesRemoved(const std::set<si32> & removedObstacles)
  577. {
  578. EVENT_HANDLER_CALLED_BY_CLIENT;
  579. if(LOCPLINT != this)
  580. { //another local interface should do this
  581. return;
  582. }
  583. // for(std::set<si32>::const_iterator it = removedObstacles.begin(); it != removedObstacles.end(); ++it)
  584. // {
  585. // for(std::map< int, CDefHandler * >::iterator itBat = battleInt->idToObstacle.begin(); itBat != battleInt->idToObstacle.end(); ++itBat)
  586. // {
  587. // if(itBat->first == *it) //remove this obstacle
  588. // {
  589. // battleInt->idToObstacle.erase(itBat);
  590. // break;
  591. // }
  592. // }
  593. // }
  594. //update accessible hexes
  595. battleInt->redrawBackgroundWithHexes(battleInt->activeStack);
  596. }
  597. void CPlayerInterface::battleCatapultAttacked(const CatapultAttack & ca)
  598. {
  599. EVENT_HANDLER_CALLED_BY_CLIENT;
  600. if(LOCPLINT != this)
  601. { //another local interface should do this
  602. return;
  603. }
  604. battleInt->stackIsCatapulting(ca);
  605. }
  606. void CPlayerInterface::battleStacksRemoved(const BattleStacksRemoved & bsr)
  607. {
  608. EVENT_HANDLER_CALLED_BY_CLIENT;
  609. if(LOCPLINT != this)
  610. { //another local interface should do this
  611. return;
  612. }
  613. for(std::set<ui32>::const_iterator it = bsr.stackIDs.begin(); it != bsr.stackIDs.end(); ++it) //for each removed stack
  614. {
  615. battleInt->stackRemoved(*it);
  616. //battleInt->stackRemoved(LOCPLINT->cb->battleGetStackByID(*it));
  617. }
  618. }
  619. void CPlayerInterface::battleNewRound(int round) //called at the beginning of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  620. {
  621. EVENT_HANDLER_CALLED_BY_CLIENT;
  622. if(LOCPLINT != this)
  623. { //another local interface should do this
  624. return;
  625. }
  626. battleInt->newRound(round);
  627. }
  628. void CPlayerInterface::actionStarted(const BattleAction* action)
  629. {
  630. EVENT_HANDLER_CALLED_BY_CLIENT;
  631. if(LOCPLINT != this)
  632. { //another local interface should do this
  633. return;
  634. }
  635. curAction = new BattleAction(*action);
  636. battleInt->startAction(action);
  637. }
  638. void CPlayerInterface::actionFinished(const BattleAction* action)
  639. {
  640. EVENT_HANDLER_CALLED_BY_CLIENT;
  641. if(LOCPLINT != this)
  642. { //another local interface should do this
  643. return;
  644. }
  645. delete curAction;
  646. curAction = NULL;
  647. battleInt->endAction(action);
  648. }
  649. BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when it's turn of that stack
  650. {
  651. THREAD_CREATED_BY_CLIENT;
  652. tlog5 << "Awaiting command for " << stack->nodeName() << std::endl;
  653. CBattleInterface *b = battleInt;
  654. assert(!b->givenCommand->get()); //command buffer must be clean (we don't want to use old command)
  655. {
  656. boost::unique_lock<boost::recursive_mutex> un(*pim);
  657. b->stackActivated(stack);
  658. //Regeneration & mana drain go there
  659. }
  660. //wait till BattleInterface sets its command
  661. boost::unique_lock<boost::mutex> lock(b->givenCommand->mx);
  662. while(!b->givenCommand->data)
  663. {
  664. b->givenCommand->cond.wait(lock);
  665. if(!battleInt) //batle ended while we were waiting for movement (eg. because of spell)
  666. throw boost::thread_interrupted(); //will shut the thread peacefully
  667. }
  668. //tidy up
  669. BattleAction ret = *(b->givenCommand->data);
  670. delete b->givenCommand->data;
  671. b->givenCommand->data = NULL;
  672. //return command
  673. tlog5 << "Giving command for " << stack->nodeName() << std::endl;
  674. return ret;
  675. }
  676. void CPlayerInterface::battleEnd(const BattleResult *br)
  677. {
  678. EVENT_HANDLER_CALLED_BY_CLIENT;
  679. if(LOCPLINT != this)
  680. { //another local interface should do this
  681. return;
  682. }
  683. battleInt->battleFinished(*br);
  684. }
  685. void CPlayerInterface::battleStackMoved(const CStack * stack, std::vector<BattleHex> dest, int distance)
  686. {
  687. EVENT_HANDLER_CALLED_BY_CLIENT;
  688. if(LOCPLINT != this)
  689. { //another local interface should do this
  690. return;
  691. }
  692. battleInt->stackMoved(stack, dest, distance);
  693. }
  694. void CPlayerInterface::battleSpellCast( const BattleSpellCast *sc )
  695. {
  696. EVENT_HANDLER_CALLED_BY_CLIENT;
  697. if(LOCPLINT != this)
  698. { //another local interface should do this
  699. return;
  700. }
  701. battleInt->spellCast(sc);
  702. }
  703. void CPlayerInterface::battleStacksEffectsSet( const SetStackEffect & sse )
  704. {
  705. EVENT_HANDLER_CALLED_BY_CLIENT;
  706. if(LOCPLINT != this)
  707. { //another local interface should do this
  708. return;
  709. }
  710. battleInt->battleStacksEffectsSet(sse);
  711. }
  712. void CPlayerInterface::battleTriggerEffect (const BattleTriggerEffect & bte)
  713. {
  714. EVENT_HANDLER_CALLED_BY_CLIENT;
  715. battleInt->battleTriggerEffect(bte);
  716. }
  717. void CPlayerInterface::battleStacksAttacked(const std::vector<BattleStackAttacked> & bsa)
  718. {
  719. EVENT_HANDLER_CALLED_BY_CLIENT;
  720. if(LOCPLINT != this)
  721. { //another local interface should do this
  722. return;
  723. }
  724. std::vector<StackAttackedInfo> arg;
  725. for(std::vector<BattleStackAttacked>::const_iterator i = bsa.begin(); i != bsa.end(); i++)
  726. {
  727. const CStack *defender = cb->battleGetStackByID(i->stackAttacked, false);
  728. const CStack *attacker = cb->battleGetStackByID(i->attackerID, false);
  729. if(i->isEffect() && i->effect != 12) //and not armageddon
  730. {
  731. if (defender && !i->isSecondary())
  732. battleInt->displayEffect(i->effect, defender->position);
  733. }
  734. bool shooting = (LOCPLINT->curAction ? LOCPLINT->curAction->actionType == BattleAction::SHOOT : false); //FIXME: why action is deleted during enchanter cast?
  735. StackAttackedInfo to_put = {defender, i->damageAmount, i->killedAmount, attacker, shooting, i->killed(), i->willRebirth(), i->cloneKilled()};
  736. arg.push_back(to_put);
  737. }
  738. if(bsa.begin()->isEffect() && bsa.begin()->effect == 12) //for armageddon - I hope this condition is enough
  739. {
  740. battleInt->displayEffect(bsa.begin()->effect, -1);
  741. }
  742. battleInt->stacksAreAttacked(arg);
  743. }
  744. void CPlayerInterface::battleAttack(const BattleAttack *ba)
  745. {
  746. EVENT_HANDLER_CALLED_BY_CLIENT;
  747. if(LOCPLINT != this)
  748. { //another local interface should do this
  749. return;
  750. }
  751. assert(curAction);
  752. if(ba->lucky()) //lucky hit
  753. {
  754. const CStack *stack = cb->battleGetStackByID(ba->stackAttacking);
  755. std::string hlp = CGI->generaltexth->allTexts[45];
  756. boost::algorithm::replace_first(hlp,"%s", (stack->count != 1) ? stack->getCreature()->namePl.c_str() : stack->getCreature()->nameSing.c_str());
  757. battleInt->console->addText(hlp);
  758. battleInt->displayEffect(18, stack->position);
  759. }
  760. //TODO: bad luck?
  761. if (ba->deathBlow())
  762. {
  763. const CStack *stack = cb->battleGetStackByID(ba->stackAttacking);
  764. std::string hlp = CGI->generaltexth->allTexts[(stack->count != 1) ? 366 : 365];
  765. boost::algorithm::replace_first(hlp,"%s", (stack->count != 1) ? stack->getCreature()->namePl.c_str() : stack->getCreature()->nameSing.c_str());
  766. battleInt->console->addText(hlp);
  767. for (std::vector<BattleStackAttacked>::const_iterator i = ba->bsa.begin(); i != ba->bsa.end(); i++)
  768. {
  769. const CStack * attacked = cb->battleGetStackByID(i->stackAttacked);
  770. battleInt->displayEffect(73, attacked->position);
  771. }
  772. }
  773. const CStack * attacker = cb->battleGetStackByID(ba->stackAttacking);
  774. if(ba->shot())
  775. {
  776. for(std::vector<BattleStackAttacked>::const_iterator i = ba->bsa.begin(); i != ba->bsa.end(); i++)
  777. {
  778. if (!i->isSecondary()) //display projectile only for primary target
  779. {
  780. const CStack * attacked = cb->battleGetStackByID(i->stackAttacked);
  781. battleInt->stackAttacking(attacker, cb->battleGetPos(i->stackAttacked), attacked, true);
  782. }
  783. }
  784. }
  785. else
  786. {
  787. int shift = 0;
  788. if(ba->counter() && BattleHex::mutualPosition(curAction->destinationTile, attacker->position) < 0)
  789. {
  790. int distp = BattleHex::getDistance(curAction->destinationTile + 1, attacker->position);
  791. int distm = BattleHex::getDistance(curAction->destinationTile - 1, attacker->position);
  792. if( distp < distm )
  793. shift = 1;
  794. else
  795. shift = -1;
  796. }
  797. const CStack * attacked = cb->battleGetStackByID(ba->bsa.begin()->stackAttacked);
  798. battleInt->stackAttacking( attacker, ba->counter() ? curAction->destinationTile + shift : curAction->additionalInfo, attacked, false);
  799. }
  800. }
  801. void CPlayerInterface::battleObstaclePlaced(const CObstacleInstance &obstacle)
  802. {
  803. EVENT_HANDLER_CALLED_BY_CLIENT;
  804. if(LOCPLINT != this)
  805. { //another local interface should do this
  806. return;
  807. }
  808. battleInt->obstaclePlaced(obstacle);
  809. }
  810. void CPlayerInterface::yourTacticPhase(int distance)
  811. {
  812. THREAD_CREATED_BY_CLIENT;
  813. while(battleInt && battleInt->tacticsMode)
  814. boost::this_thread::sleep(boost::posix_time::millisec(1));
  815. }
  816. void CPlayerInterface::showComp(const Component &comp, std::string message)
  817. {
  818. EVENT_HANDLER_CALLED_BY_CLIENT;
  819. waitWhileDialog(); //Fix for mantis #98
  820. CCS->soundh->playSoundFromSet(CCS->soundh->pickupSounds);
  821. adventureInt->infoBar.showComponent(comp, message);
  822. }
  823. void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID)
  824. {
  825. EVENT_HANDLER_CALLED_BY_CLIENT;
  826. std::vector<CComponent*> intComps;
  827. for(int i=0;i<components.size();i++)
  828. intComps.push_back(new CComponent(*components[i]));
  829. showInfoDialog(text,intComps,soundID);
  830. }
  831. void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<CComponent*> & components, int soundID, bool delComps)
  832. {
  833. waitWhileDialog();
  834. stopMovement();
  835. CInfoWindow *temp = CInfoWindow::create(text, playerID, &components);
  836. temp->setDelComps(delComps);
  837. if(makingTurn && GH.listInt.size() && LOCPLINT == this)
  838. {
  839. CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
  840. showingDialog->set(true);
  841. GH.pushInt(temp);
  842. }
  843. else
  844. {
  845. dialogs.push_back(temp);
  846. }
  847. }
  848. void CPlayerInterface::showYesNoDialog(const std::string &text, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool DelComps, const std::vector<CComponent*> & components)
  849. {
  850. boost::unique_lock<boost::recursive_mutex> un(*pim);
  851. stopMovement();
  852. LOCPLINT->showingDialog->setn(true);
  853. CInfoWindow::showYesNoDialog(text, &components, onYes, onNo, DelComps, playerID);
  854. }
  855. void CPlayerInterface::showBlockingDialog( const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel )
  856. {
  857. EVENT_HANDLER_CALLED_BY_CLIENT;
  858. waitWhileDialog();
  859. stopMovement();
  860. CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
  861. if(!selection && cancel) //simple yes/no dialog
  862. {
  863. std::vector<CComponent*> intComps;
  864. for(int i=0;i<components.size();i++)
  865. intComps.push_back(new CComponent(components[i])); //will be deleted by close in window
  866. showYesNoDialog(text, boost::bind(&CCallback::selectionMade,cb,1,askID),boost::bind(&CCallback::selectionMade,cb,0,askID),true, intComps);
  867. }
  868. else if(selection)
  869. {
  870. std::vector<CSelectableComponent*> intComps;
  871. for(int i=0;i<components.size();i++)
  872. intComps.push_back(new CSelectableComponent(components[i])); //will be deleted by CSelWindow::close
  873. std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
  874. pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
  875. if(cancel)
  876. {
  877. pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",0));
  878. }
  879. int charperline = 35;
  880. if (pom.size() > 1)
  881. charperline = 50;
  882. CSelWindow * temp = new CSelWindow(text, playerID, charperline, intComps, pom, askID);
  883. GH.pushInt(temp);
  884. intComps[0]->clickLeft(true, false);
  885. }
  886. }
  887. void CPlayerInterface::tileRevealed(const boost::unordered_set<int3, ShashInt3> &pos)
  888. {
  889. EVENT_HANDLER_CALLED_BY_CLIENT;
  890. for(boost::unordered_set<int3, ShashInt3>::const_iterator i=pos.begin(); i!=pos.end();i++)
  891. adventureInt->minimap.showTile(*i);
  892. if(pos.size())
  893. GH.totalRedraw();
  894. }
  895. void CPlayerInterface::tileHidden(const boost::unordered_set<int3, ShashInt3> &pos)
  896. {
  897. EVENT_HANDLER_CALLED_BY_CLIENT;
  898. for(boost::unordered_set<int3, ShashInt3>::const_iterator i=pos.begin(); i!=pos.end();i++)
  899. adventureInt->minimap.hideTile(*i);
  900. if(pos.size())
  901. GH.totalRedraw();
  902. }
  903. void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
  904. {
  905. boost::unique_lock<boost::recursive_mutex> un(*pim);
  906. GH.pushInt(new CHeroWindow(hero));
  907. }
  908. /*
  909. void CPlayerInterface::heroArtifactSetChanged(const CGHeroInstance*hero)
  910. {
  911. boost::unique_lock<boost::recursive_mutex> un(*pim);
  912. if(adventureInt->heroWindow->curHero && adventureInt->heroWindow->curHero->id == hero->id) //hero window is opened
  913. {
  914. adventureInt->heroWindow->deactivate();
  915. adventureInt->heroWindow->setHero(hero);
  916. adventureInt->heroWindow->activate();
  917. }
  918. else if(CExchangeWindow* cew = dynamic_cast<CExchangeWindow*>(GH.topInt())) //exchange window is open
  919. {
  920. cew->deactivate();
  921. for(int g=0; g<ARRAY_COUNT(cew->heroInst); ++g)
  922. {
  923. if(cew->heroInst[g]->id == hero->id)
  924. {
  925. cew->heroInst[g] = hero;
  926. cew->artifs[g]->updateState = true;
  927. cew->artifs[g]->setHero(hero);
  928. cew->artifs[g]->updateState = false;
  929. }
  930. }
  931. cew->prepareBackground();
  932. cew->activate();
  933. }
  934. else if(CTradeWindow *caw = dynamic_cast<CTradeWindow*>(GH.topInt()))
  935. {
  936. if(caw->arts)
  937. {
  938. caw->deactivate();
  939. caw->arts->updateState = true;
  940. caw->arts->setHero(hero);
  941. caw->arts->updateState = false;
  942. caw->activate();
  943. }
  944. }
  945. updateInfo(hero);
  946. }*/
  947. void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
  948. {
  949. EVENT_HANDLER_CALLED_BY_CLIENT;
  950. if(const CGTownInstance * townObj = dynamic_cast<const CGTownInstance*>(town))
  951. {
  952. CFortScreen *fs = dynamic_cast<CFortScreen*>(GH.topInt());
  953. if(fs)
  954. fs->creaturesChanged();
  955. BOOST_FOREACH(IShowActivatable *isa, GH.listInt)
  956. {
  957. CKingdomInterface *ki = dynamic_cast<CKingdomInterface*>(isa);
  958. if (ki && townObj)
  959. ki->townChanged(townObj);
  960. }
  961. }
  962. else if(GH.listInt.size() && (town->ID == 17 || town->ID == 20 || town->ID == 106)) //external dwelling
  963. {
  964. CRecruitmentWindow *crw = dynamic_cast<CRecruitmentWindow*>(GH.topInt());
  965. if(crw && crw->dwelling == town)
  966. crw->availableCreaturesChanged();
  967. }
  968. }
  969. void CPlayerInterface::heroBonusChanged( const CGHeroInstance *hero, const Bonus &bonus, bool gain )
  970. {
  971. EVENT_HANDLER_CALLED_BY_CLIENT;
  972. if(bonus.type == Bonus::NONE)
  973. return;
  974. updateInfo(hero);
  975. if ((bonus.type == Bonus::FLYING_MOVEMENT || bonus.type == Bonus::WATER_WALKING) && !gain)
  976. {
  977. //recalculate paths because hero has lost bonus influencing pathfinding
  978. eraseCurrentPathOf(hero, false);
  979. }
  980. }
  981. template <typename Handler> void CPlayerInterface::serializeTempl( Handler &h, const int version )
  982. {
  983. h & playerID;
  984. h & spellbookSettings;
  985. //sleeping heroes
  986. ui8 sleepingSize;
  987. if (h.saving)
  988. sleepingSize = sleepingHeroes.size();
  989. h & sleepingSize;
  990. for (int i = 0; i < sleepingSize; i++)
  991. {
  992. si32 hid;
  993. if (h.saving)
  994. hid = sleepingHeroes[i]->id;
  995. h & hid;
  996. if (!h.saving)
  997. {
  998. const CGHeroInstance *hero = cb->getHero(hid);
  999. sleepingHeroes += hero;
  1000. }
  1001. }
  1002. //hero list order
  1003. ui8 heroListSize;
  1004. if (h.saving)
  1005. heroListSize = wanderingHeroes.size();
  1006. else
  1007. wanderingHeroes.clear();
  1008. h & heroListSize;
  1009. for (int i = 0; i < heroListSize; i++)
  1010. {
  1011. si32 hid;
  1012. if (h.saving)
  1013. hid = wanderingHeroes[i]->id;
  1014. h & hid;
  1015. if (!h.saving)
  1016. {
  1017. const CGHeroInstance *hero = cb->getHero(hid);
  1018. wanderingHeroes += hero;
  1019. }
  1020. }
  1021. }
  1022. void CPlayerInterface::serialize( COSer<CSaveFile> &h, const int version )
  1023. {
  1024. EVENT_HANDLER_CALLED_BY_CLIENT;
  1025. serializeTempl(h,version);
  1026. }
  1027. void CPlayerInterface::serialize( CISer<CLoadFile> &h, const int version )
  1028. {
  1029. EVENT_HANDLER_CALLED_BY_CLIENT;
  1030. serializeTempl(h,version);
  1031. firstCall = -1;
  1032. }
  1033. bool CPlayerInterface::moveHero( const CGHeroInstance *h, CGPath path )
  1034. {
  1035. if(!LOCPLINT->makingTurn)
  1036. return false;
  1037. if (!h)
  1038. return false; //can't find hero
  1039. if (adventureInt && adventureInt->isHeroSleeping(h))
  1040. {
  1041. adventureInt->sleepWake.clickLeft(true, false);
  1042. adventureInt->sleepWake.clickLeft(false, true);
  1043. //could've just called
  1044. //adventureInt->fsleepWake();
  1045. //but no authentic button click/sound ;-)
  1046. }
  1047. int i = 1;
  1048. bool result = false; //TODO why not set to true anywhere?
  1049. {
  1050. //evil...
  1051. auto unlockEvents = vstd::makeUnlockGuard(eventsM);
  1052. auto unlockGs = vstd::makeUnlockSharedGuard(cb->getGsMutex()); //GS mutex is above PIM because CClient::run thread first locks PIM and then GS -> so this way we avoid deadlocks
  1053. auto unlockPim = vstd::makeUnlockGuard(*pim);
  1054. {
  1055. path.convert(0);
  1056. boost::unique_lock<boost::mutex> un(stillMoveHero.mx);
  1057. stillMoveHero.data = CONTINUE_MOVE;
  1058. enum TerrainTile::EterrainType currentTerrain = TerrainTile::border; // not init yet
  1059. enum TerrainTile::EterrainType newTerrain;
  1060. int sh = -1;
  1061. const TerrainTile * curTile = cb->getTile(CGHeroInstance::convertPosition(h->pos, false));
  1062. for(i=path.nodes.size()-1; i>0 && (stillMoveHero.data == CONTINUE_MOVE || curTile->blocked); i--)
  1063. {
  1064. //changing z coordinate means we're moving through subterranean gate -> it's done automatically upon the visit, so we don't have to request that move here
  1065. if(path.nodes[i-1].coord.z != path.nodes[i].coord.z)
  1066. continue;
  1067. //stop sending move requests if the next node can't be reached at the current turn (hero exhausted his move points)
  1068. if(path.nodes[i-1].turns)
  1069. {
  1070. stillMoveHero.data = STOP_MOVE;
  1071. break;
  1072. }
  1073. // Start a new sound for the hero movement or let the existing one carry on.
  1074. #if 0
  1075. // TODO
  1076. if (hero is flying && sh == -1)
  1077. sh = CCS->soundh->playSound(soundBase::horseFlying, -1);
  1078. #endif
  1079. {
  1080. newTerrain = cb->getTile(CGHeroInstance::convertPosition(path.nodes[i].coord, false))->tertype;
  1081. if (newTerrain != currentTerrain)
  1082. {
  1083. CCS->soundh->stopSound(sh);
  1084. sh = CCS->soundh->playSound(CCS->soundh->horseSounds[newTerrain], -1);
  1085. currentTerrain = newTerrain;
  1086. }
  1087. }
  1088. stillMoveHero.data = WAITING_MOVE;
  1089. int3 endpos(path.nodes[i-1].coord.x, path.nodes[i-1].coord.y, h->pos.z);
  1090. bool guarded = CGI->mh->map->isInTheMap(cb->guardingCreaturePosition(endpos - int3(1, 0, 0)));
  1091. cb->moveHero(h,endpos);
  1092. while(stillMoveHero.data != STOP_MOVE && stillMoveHero.data != CONTINUE_MOVE)
  1093. stillMoveHero.cond.wait(un);
  1094. if (guarded) // Abort movement if a guard was fought.
  1095. break;
  1096. }
  1097. CCS->soundh->stopSound(sh);
  1098. }
  1099. //RAII unlocks
  1100. }
  1101. if (adventureInt)
  1102. {
  1103. // (i == 0) means hero went through all the path
  1104. adventureInt->updateMoveHero(h, (i != 0));
  1105. adventureInt->updateNextHero(h);
  1106. }
  1107. return result;
  1108. }
  1109. bool CPlayerInterface::shiftPressed() const
  1110. {
  1111. return SDL_GetKeyState(NULL)[SDLK_LSHIFT] || SDL_GetKeyState(NULL)[SDLK_RSHIFT];
  1112. }
  1113. bool CPlayerInterface::altPressed() const
  1114. {
  1115. return SDL_GetKeyState(NULL)[SDLK_LALT] || SDL_GetKeyState(NULL)[SDLK_RALT];
  1116. }
  1117. void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, boost::function<void()> &onEnd )
  1118. {
  1119. EVENT_HANDLER_CALLED_BY_CLIENT;
  1120. if(stillMoveHero.get() == DURING_MOVE && adventureInt->terrain.currentPath && adventureInt->terrain.currentPath->nodes.size() > 1) //to ignore calls on passing through garrisons
  1121. {
  1122. onEnd();
  1123. return;
  1124. }
  1125. waitForAllDialogs();
  1126. CGarrisonWindow *cgw = new CGarrisonWindow(up,down,removableUnits);
  1127. cgw->quit->callback += onEnd;
  1128. GH.pushInt(cgw);
  1129. }
  1130. /**
  1131. * Shows the dialog that appears when right-clicking an artifact that can be assembled
  1132. * into a combinational one on an artifact screen. Does not require the combination of
  1133. * artifacts to be legal.
  1134. * @param artifactID ID of a constituent artifact.
  1135. * @param assembleTo ID of artifact to assemble a constituent into, not used when assemble
  1136. * is false.
  1137. * @param assemble True if the artifact is to be assembled, false if it is to be disassembled.
  1138. */
  1139. void CPlayerInterface::showArtifactAssemblyDialog (ui32 artifactID, ui32 assembleTo, bool assemble, CFunctionList<void()> onYes, CFunctionList<void()> onNo)
  1140. {
  1141. const CArtifact &artifact = *CGI->arth->artifacts[artifactID];
  1142. std::string text = artifact.Description();
  1143. text += "\n\n";
  1144. std::vector<CComponent*> scs;
  1145. if (assemble) {
  1146. const CArtifact &assembledArtifact = *CGI->arth->artifacts[assembleTo];
  1147. // You possess all of the components to...
  1148. text += boost::str(boost::format(CGI->generaltexth->allTexts[732]) % assembledArtifact.Name());
  1149. // Picture of assembled artifact at bottom.
  1150. CComponent* sc = new CComponent(CComponent::artifact, assembledArtifact.id, 0);
  1151. //sc->description = assembledArtifact.Description();
  1152. //sc->subtitle = assembledArtifact.Name();
  1153. scs.push_back(sc);
  1154. } else {
  1155. // Do you wish to disassemble this artifact?
  1156. text += CGI->generaltexth->allTexts[733];
  1157. }
  1158. showYesNoDialog(text, onYes, onNo, true, scs);
  1159. }
  1160. void CPlayerInterface::requestRealized( PackageApplied *pa )
  1161. {
  1162. EVENT_HANDLER_CALLED_BY_CLIENT;
  1163. if(stillMoveHero.get() == DURING_MOVE)
  1164. stillMoveHero.setn(CONTINUE_MOVE);
  1165. }
  1166. void CPlayerInterface::heroExchangeStarted(si32 hero1, si32 hero2)
  1167. {
  1168. EVENT_HANDLER_CALLED_BY_CLIENT;
  1169. GH.pushInt(new CExchangeWindow(hero1, hero2));
  1170. }
  1171. void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop)
  1172. {
  1173. EVENT_HANDLER_CALLED_BY_CLIENT;
  1174. //redraw minimap if owner changed
  1175. if(sop->what == ObjProperty::OWNER)
  1176. {
  1177. const CGObjectInstance * obj = cb->getObj(sop->id);
  1178. std::set<int3> pos = obj->getBlockedPos();
  1179. for(std::set<int3>::const_iterator it = pos.begin(); it != pos.end(); ++it)
  1180. {
  1181. if(cb->isVisible(*it))
  1182. adventureInt->minimap.showTile(*it);
  1183. }
  1184. if(obj->ID == GameConstants::TOWNI_TYPE)
  1185. {
  1186. if(obj->tempOwner == playerID)
  1187. towns.push_back(static_cast<const CGTownInstance *>(obj));
  1188. else
  1189. towns -= obj;
  1190. adventureInt->townList.update();
  1191. }
  1192. assert(cb->getTownsInfo().size() == towns.size());
  1193. }
  1194. }
  1195. void CPlayerInterface::initializeHeroTownList()
  1196. {
  1197. std::vector<const CGHeroInstance*> allHeroes = cb->getHeroesInfo();
  1198. /*
  1199. std::vector <const CGHeroInstance *> newWanderingHeroes;
  1200. //applying current heroes order to new heroes info
  1201. int j;
  1202. for (int i = 0; i < wanderingHeroes.size(); i++)
  1203. if ((j = vstd::find_pos(allHeroes, wanderingHeroes[i])) >= 0)
  1204. if (!allHeroes[j]->inTownGarrison)
  1205. {
  1206. newWanderingHeroes += allHeroes[j];
  1207. allHeroes -= allHeroes[j];
  1208. }
  1209. //all the rest of new heroes go the end of the list
  1210. wanderingHeroes.clear();
  1211. wanderingHeroes = newWanderingHeroes;
  1212. newWanderingHeroes.clear();*/
  1213. for (int i = 0; i < allHeroes.size(); i++)
  1214. if (!allHeroes[i]->inTownGarrison)
  1215. wanderingHeroes += allHeroes[i];
  1216. std::vector<const CGTownInstance*> allTowns = cb->getTownsInfo();
  1217. /*
  1218. std::vector<const CGTownInstance*> newTowns;
  1219. for (int i = 0; i < towns.size(); i++)
  1220. if ((j = vstd::find_pos(allTowns, towns[i])) >= 0)
  1221. {
  1222. newTowns += allTowns[j];
  1223. allTowns -= allTowns[j];
  1224. }
  1225. towns.clear();
  1226. towns = newTowns;
  1227. newTowns.clear();*/
  1228. for(int i = 0; i < allTowns.size(); i++)
  1229. towns.push_back(allTowns[i]);
  1230. if (adventureInt)
  1231. adventureInt->updateNextHero(NULL);
  1232. }
  1233. void CPlayerInterface::showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level)
  1234. {
  1235. EVENT_HANDLER_CALLED_BY_CLIENT;
  1236. waitWhileDialog();
  1237. CRecruitmentWindow *cr = new CRecruitmentWindow(dwelling, level, dst, boost::bind(&CCallback::recruitCreatures, cb, dwelling, _1, _2, -1));
  1238. GH.pushInt(cr);
  1239. }
  1240. void CPlayerInterface::waitWhileDialog(bool unlockPim /*= true*/)
  1241. {
  1242. if(GH.amIGuiThread())
  1243. {
  1244. tlog3 << "Cannot wait for dialogs in gui thread (deadlock risk)!\n";
  1245. return;
  1246. }
  1247. auto unlock = vstd::makeUnlockGuardIf(*pim, unlockPim);
  1248. boost::unique_lock<boost::mutex> un(showingDialog->mx);
  1249. while(showingDialog->data)
  1250. showingDialog->cond.wait(un);
  1251. }
  1252. void CPlayerInterface::showShipyardDialog(const IShipyard *obj)
  1253. {
  1254. EVENT_HANDLER_CALLED_BY_CLIENT;
  1255. int state = obj->state();
  1256. std::vector<si32> cost;
  1257. obj->getBoatCost(cost);
  1258. CShipyardWindow *csw = new CShipyardWindow(cost, state, obj->getBoatType(), boost::bind(&CCallback::buildBoat, cb, obj));
  1259. GH.pushInt(csw);
  1260. }
  1261. void CPlayerInterface::newObject( const CGObjectInstance * obj )
  1262. {
  1263. EVENT_HANDLER_CALLED_BY_CLIENT;
  1264. //we might have built a boat in shipyard in opened town screen
  1265. if(obj->ID == 8
  1266. && LOCPLINT->castleInt
  1267. && obj->pos-obj->getVisitableOffset() == LOCPLINT->castleInt->town->bestLocation())
  1268. {
  1269. CCS->soundh->playSound(soundBase::newBuilding);
  1270. LOCPLINT->castleInt->addBuilding(20);
  1271. }
  1272. }
  1273. void CPlayerInterface::centerView (int3 pos, int focusTime)
  1274. {
  1275. EVENT_HANDLER_CALLED_BY_CLIENT;
  1276. waitWhileDialog();
  1277. adventureInt->centerOn (pos);
  1278. if(focusTime)
  1279. {
  1280. bool activeAdv = (GH.topInt() == adventureInt && adventureInt->isActive());
  1281. if(activeAdv)
  1282. adventureInt->deactivate();
  1283. SDL_Delay(focusTime);
  1284. if(activeAdv)
  1285. adventureInt->activate();
  1286. }
  1287. }
  1288. void CPlayerInterface::objectRemoved( const CGObjectInstance *obj )
  1289. {
  1290. EVENT_HANDLER_CALLED_BY_CLIENT;
  1291. if(obj->ID == GameConstants::HEROI_TYPE && obj->tempOwner == playerID)
  1292. {
  1293. const CGHeroInstance *h = static_cast<const CGHeroInstance*>(obj);
  1294. heroKilled(h);
  1295. }
  1296. }
  1297. bool CPlayerInterface::ctrlPressed() const
  1298. {
  1299. return SDL_GetKeyState(NULL)[SDLK_LCTRL] || SDL_GetKeyState(NULL)[SDLK_RCTRL];
  1300. }
  1301. void CPlayerInterface::update()
  1302. {
  1303. while(!terminate_cond.get() && !pim->try_lock()) //try acquiring long until it succeeds or we are told to terminate
  1304. boost::this_thread::sleep(boost::posix_time::milliseconds(15));
  1305. if(terminate_cond.get())
  1306. return;
  1307. boost::unique_lock<boost::recursive_mutex> un(*pim, boost::adopt_lock); //create lock from already owned mutex
  1308. //make sure that gamestate won't change when GUI objects may obtain its parts on event processing or drawing request
  1309. boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
  1310. //if there are any waiting dialogs, show them
  1311. if((howManyPeople <= 1 || makingTurn) && dialogs.size() && !showingDialog->get())
  1312. {
  1313. showingDialog->set(true);
  1314. GH.pushInt(dialogs.front());
  1315. dialogs.pop_front();
  1316. }
  1317. //in some conditions we may receive calls before selection is initialized - we must ignore them
  1318. if(adventureInt && !adventureInt->selection && GH.topInt() == adventureInt)
  1319. {
  1320. return;
  1321. }
  1322. // Handles mouse and key input
  1323. GH.updateTime();
  1324. GH.handleEvents();
  1325. if(adventureInt && !adventureInt->isActive() && adventureInt->scrollingDir) //player forces map scrolling though interface is disabled
  1326. GH.totalRedraw();
  1327. else
  1328. GH.simpleRedraw();
  1329. if (settings["general"]["showfps"].Bool())
  1330. GH.drawFPSCounter();
  1331. // draw the mouse cursor and update the screen
  1332. CCS->curh->draw1();
  1333. CSDL_Ext::update(screen);
  1334. CCS->curh->draw2();
  1335. }
  1336. int CPlayerInterface::getLastIndex( std::string namePrefix)
  1337. {
  1338. using namespace boost::filesystem;
  1339. using namespace boost::algorithm;
  1340. std::map<std::time_t, int> dates; //save number => datestamp
  1341. directory_iterator enddir;
  1342. for (directory_iterator dir(GVCMIDirs.UserPath + "/Games"); dir!=enddir; dir++)
  1343. {
  1344. if(is_regular(dir->status()))
  1345. {
  1346. std::string name = dir->path().leaf().string();
  1347. if(starts_with(name, namePrefix) && ends_with(name, ".vlgm1"))
  1348. {
  1349. char nr = name[namePrefix.size()];
  1350. if(std::isdigit(nr))
  1351. {
  1352. dates[last_write_time(dir->path())] = boost::lexical_cast<int>(nr);
  1353. }
  1354. }
  1355. }
  1356. }
  1357. if(dates.size())
  1358. return (--dates.end())->second; //return latest file number
  1359. return 0;
  1360. }
  1361. void CPlayerInterface::initMovement( const TryMoveHero &details, const CGHeroInstance * ho, const int3 &hp )
  1362. {
  1363. if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl
  1364. {
  1365. //ho->moveDir = 1;
  1366. ho->isStanding = false;
  1367. CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -31)));
  1368. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, -31)));
  1369. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, -31)));
  1370. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, -31)));
  1371. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 1)));
  1372. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  1373. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  1374. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  1375. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 33)));
  1376. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  1377. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  1378. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  1379. 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);
  1380. 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);
  1381. 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);
  1382. 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);
  1383. 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);
  1384. 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);
  1385. }
  1386. else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t
  1387. {
  1388. //ho->moveDir = 2;
  1389. ho->isStanding = false;
  1390. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, -31)));
  1391. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, -31)));
  1392. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, -31)));
  1393. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  1394. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  1395. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  1396. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  1397. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  1398. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  1399. 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);
  1400. 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);
  1401. 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);
  1402. }
  1403. else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr
  1404. {
  1405. //ho->moveDir = 3;
  1406. ho->isStanding = false;
  1407. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, -31)));
  1408. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, -31)));
  1409. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, -31)));
  1410. CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -31)));
  1411. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  1412. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  1413. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  1414. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 1)));
  1415. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  1416. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  1417. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  1418. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 33)));
  1419. 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);
  1420. 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);
  1421. 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);
  1422. 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);
  1423. 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);
  1424. 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);
  1425. }
  1426. else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r
  1427. {
  1428. //ho->moveDir = 4;
  1429. ho->isStanding = false;
  1430. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  1431. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  1432. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  1433. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 0)));
  1434. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  1435. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  1436. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  1437. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 32)));
  1438. 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);
  1439. 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);
  1440. }
  1441. else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br
  1442. {
  1443. //ho->moveDir = 5;
  1444. ho->isStanding = false;
  1445. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  1446. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  1447. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  1448. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -1)));
  1449. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  1450. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  1451. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  1452. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 31)));
  1453. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, 63)));
  1454. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, 63)));
  1455. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, 63)));
  1456. CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 63)));
  1457. 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);
  1458. 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);
  1459. 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);
  1460. 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);
  1461. 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);
  1462. 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);
  1463. }
  1464. else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b
  1465. {
  1466. //ho->moveDir = 6;
  1467. ho->isStanding = false;
  1468. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  1469. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  1470. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  1471. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  1472. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  1473. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  1474. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, 63)));
  1475. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, 63)));
  1476. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, 63)));
  1477. 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);
  1478. 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);
  1479. 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);
  1480. }
  1481. else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl
  1482. {
  1483. //ho->moveDir = 7;
  1484. ho->isStanding = false;
  1485. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -1)));
  1486. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  1487. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  1488. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  1489. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 31)));
  1490. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  1491. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  1492. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  1493. CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 63)));
  1494. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, 63)));
  1495. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, 63)));
  1496. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, 63)));
  1497. 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);
  1498. 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);
  1499. 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);
  1500. 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);
  1501. 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);
  1502. 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);
  1503. }
  1504. else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l
  1505. {
  1506. //ho->moveDir = 8;
  1507. ho->isStanding = false;
  1508. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 0)));
  1509. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  1510. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  1511. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  1512. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 32)));
  1513. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  1514. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  1515. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  1516. 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);
  1517. 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);
  1518. }
  1519. }
  1520. void CPlayerInterface::movementPxStep( const TryMoveHero &details, int i, const int3 &hp, const CGHeroInstance * ho )
  1521. {
  1522. if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl
  1523. {
  1524. //setting advmap shift
  1525. adventureInt->terrain.moveX = i-32;
  1526. adventureInt->terrain.moveY = i-32;
  1527. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  1528. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  1529. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  1530. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  1531. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  1532. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  1533. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  1534. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  1535. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  1536. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  1537. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  1538. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  1539. }
  1540. else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t
  1541. {
  1542. //setting advmap shift
  1543. adventureInt->terrain.moveY = i-32;
  1544. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  1545. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  1546. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  1547. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  1548. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  1549. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  1550. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  1551. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  1552. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  1553. }
  1554. else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr
  1555. {
  1556. //setting advmap shift
  1557. adventureInt->terrain.moveX = -i+32;
  1558. adventureInt->terrain.moveY = i-32;
  1559. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  1560. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  1561. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  1562. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  1563. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  1564. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  1565. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  1566. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  1567. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  1568. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  1569. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  1570. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  1571. }
  1572. else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r
  1573. {
  1574. //setting advmap shift
  1575. adventureInt->terrain.moveX = -i+32;
  1576. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  1577. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  1578. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  1579. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  1580. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  1581. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  1582. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  1583. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  1584. }
  1585. else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br
  1586. {
  1587. //setting advmap shift
  1588. adventureInt->terrain.moveX = -i+32;
  1589. adventureInt->terrain.moveY = -i+32;
  1590. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  1591. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  1592. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  1593. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  1594. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  1595. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  1596. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  1597. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  1598. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  1599. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  1600. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  1601. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  1602. }
  1603. else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b
  1604. {
  1605. //setting advmap shift
  1606. adventureInt->terrain.moveY = -i+32;
  1607. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  1608. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  1609. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  1610. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  1611. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  1612. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  1613. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  1614. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  1615. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  1616. }
  1617. else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl
  1618. {
  1619. //setting advmap shift
  1620. adventureInt->terrain.moveX = i-32;
  1621. adventureInt->terrain.moveY = -i+32;
  1622. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  1623. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  1624. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  1625. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  1626. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  1627. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  1628. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  1629. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  1630. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  1631. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  1632. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  1633. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  1634. }
  1635. else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l
  1636. {
  1637. //setting advmap shift
  1638. adventureInt->terrain.moveX = i-32;
  1639. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  1640. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  1641. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  1642. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  1643. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  1644. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  1645. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  1646. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  1647. }
  1648. }
  1649. void CPlayerInterface::finishMovement( const TryMoveHero &details, const int3 &hp, const CGHeroInstance * ho )
  1650. {
  1651. adventureInt->terrain.moveX = adventureInt->terrain.moveY = 0;
  1652. if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl
  1653. {
  1654. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  1655. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1656. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1657. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1658. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1659. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  1660. }
  1661. else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t
  1662. {
  1663. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1664. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1665. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1666. }
  1667. else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr
  1668. {
  1669. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  1670. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1671. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  1672. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1673. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1674. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1675. }
  1676. else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r
  1677. {
  1678. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1679. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1680. }
  1681. else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br
  1682. {
  1683. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  1684. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1685. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  1686. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1687. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1688. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1689. }
  1690. else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b
  1691. {
  1692. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1693. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1694. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1695. }
  1696. else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl
  1697. {
  1698. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1699. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1700. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1701. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  1702. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1703. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  1704. }
  1705. else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l
  1706. {
  1707. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1708. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1709. }
  1710. //restoring good rects
  1711. subRect(details.end.x-2, details.end.y-1, details.end.z, genRect(32, 32, 0, 0), ho->id);
  1712. subRect(details.end.x-1, details.end.y-1, details.end.z, genRect(32, 32, 32, 0), ho->id);
  1713. subRect(details.end.x, details.end.y-1, details.end.z, genRect(32, 32, 64, 0), ho->id);
  1714. subRect(details.end.x-2, details.end.y, details.end.z, genRect(32, 32, 0, 32), ho->id);
  1715. subRect(details.end.x-1, details.end.y, details.end.z, genRect(32, 32, 32, 32), ho->id);
  1716. subRect(details.end.x, details.end.y, details.end.z, genRect(32, 32, 64, 32), ho->id);
  1717. //restoring good order of objects
  1718. 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);
  1719. 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);
  1720. 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);
  1721. 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);
  1722. 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);
  1723. 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);
  1724. }
  1725. void CPlayerInterface::gameOver(ui8 player, bool victory )
  1726. {
  1727. EVENT_HANDLER_CALLED_BY_CLIENT;
  1728. if(LOCPLINT != this)
  1729. return;
  1730. if(player == playerID)
  1731. {
  1732. if(!victory)
  1733. showInfoDialog(CGI->generaltexth->allTexts[95]);
  1734. // else
  1735. // showInfoDialog("Placeholder message: you won!");
  1736. makingTurn = true;
  1737. waitForAllDialogs(); //wait till all dialogs are displayed and closed
  1738. makingTurn = false;
  1739. howManyPeople--;
  1740. if(!howManyPeople) //all human players eliminated
  1741. {
  1742. if(cb->getStartInfo()->mode != StartInfo::CAMPAIGN)
  1743. requestReturningToMainMenu();
  1744. else
  1745. requestStoppingClient();
  1746. }
  1747. cb->unregisterMyInterface(); //we already won/lost, nothing else matters
  1748. }
  1749. else
  1750. {
  1751. if(!victory && cb->getPlayerStatus(playerID) == PlayerState::INGAME) //enemy has lost
  1752. {
  1753. std::string txt = CGI->generaltexth->allTexts[5]; //%s has been vanquished!
  1754. boost::algorithm::replace_first(txt, "%s", CGI->generaltexth->capColors[player]);
  1755. showInfoDialog(txt,std::vector<CComponent*>(1, new CComponent(CComponent::flag, player, 0)));
  1756. }
  1757. }
  1758. }
  1759. void CPlayerInterface::playerBonusChanged( const Bonus &bonus, bool gain )
  1760. {
  1761. EVENT_HANDLER_CALLED_BY_CLIENT;
  1762. }
  1763. void CPlayerInterface::showPuzzleMap()
  1764. {
  1765. EVENT_HANDLER_CALLED_BY_CLIENT;
  1766. waitWhileDialog();
  1767. //TODO: interface should not know the real position of Grail...
  1768. double ratio = 0;
  1769. int3 grailPos = cb->getGrailPos(ratio);
  1770. GH.pushInt(new CPuzzleWindow(grailPos, ratio));
  1771. }
  1772. void CPlayerInterface::advmapSpellCast(const CGHeroInstance * caster, int spellID)
  1773. {
  1774. EVENT_HANDLER_CALLED_BY_CLIENT;
  1775. if (spellID == Spells::FLY || spellID == Spells::WATER_WALK)
  1776. {
  1777. eraseCurrentPathOf(caster, false);
  1778. }
  1779. const CSpell * spell = CGI->spellh->spells[spellID];
  1780. if (vstd::contains(CCS->soundh->spellSounds, spell))
  1781. CCS->soundh->playSound(CCS->soundh->spellSounds[spell]);
  1782. }
  1783. void CPlayerInterface::eraseCurrentPathOf( const CGHeroInstance * ho, bool checkForExistanceOfPath /*= true */ )
  1784. {
  1785. if(checkForExistanceOfPath)
  1786. {
  1787. assert(vstd::contains(paths, ho));
  1788. }
  1789. else if (!vstd::contains(paths, ho))
  1790. {
  1791. return;
  1792. }
  1793. assert(ho == adventureInt->selection);
  1794. paths.erase(ho);
  1795. adventureInt->terrain.currentPath = NULL;
  1796. adventureInt->updateMoveHero(ho, false);
  1797. }
  1798. void CPlayerInterface::removeLastNodeFromPath(const CGHeroInstance *ho)
  1799. {
  1800. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  1801. if(adventureInt->terrain.currentPath->nodes.size() < 2) //if it was the last one, remove entire path and path with only one tile is not a real path
  1802. eraseCurrentPathOf(ho);
  1803. }
  1804. CGPath * CPlayerInterface::getAndVerifyPath(const CGHeroInstance * h)
  1805. {
  1806. if(vstd::contains(paths,h)) //hero has assigned path
  1807. {
  1808. CGPath &path = paths[h];
  1809. if(!path.nodes.size())
  1810. {
  1811. tlog3 << "Warning: empty path found...\n";
  1812. paths.erase(h);
  1813. }
  1814. else
  1815. {
  1816. assert(h->getPosition(false) == path.startPos());
  1817. //update the hero path in case of something has changed on map
  1818. if(LOCPLINT->cb->getPath2(path.endPos(), path))
  1819. return &path;
  1820. else
  1821. paths.erase(h);
  1822. }
  1823. }
  1824. return NULL;
  1825. }
  1826. void CPlayerInterface::acceptTurn()
  1827. {
  1828. if(settings["session"]["autoSkip"].Bool())
  1829. {
  1830. while(CInfoWindow *iw = dynamic_cast<CInfoWindow *>(GH.topInt()))
  1831. iw->close();
  1832. }
  1833. waitWhileDialog();
  1834. if(howManyPeople > 1)
  1835. adventureInt->startTurn();
  1836. //select first hero if available.
  1837. //TODO: check if hero is slept
  1838. if(wanderingHeroes.size())
  1839. adventureInt->select(wanderingHeroes.front());
  1840. else
  1841. adventureInt->select(towns.front());
  1842. //show new day animation and sound on infobar
  1843. adventureInt->infoBar.showDate();
  1844. adventureInt->heroList.update();
  1845. adventureInt->townList.update();
  1846. adventureInt->updateNextHero(NULL);
  1847. adventureInt->showAll(screen);
  1848. if(settings["session"]["autoSkip"].Bool() && !LOCPLINT->shiftPressed())
  1849. {
  1850. if(CInfoWindow *iw = dynamic_cast<CInfoWindow *>(GH.topInt()))
  1851. iw->close();
  1852. adventureInt->endTurn.callback();
  1853. }
  1854. }
  1855. void CPlayerInterface::tryDiggging(const CGHeroInstance *h)
  1856. {
  1857. std::string hlp;
  1858. CGI->mh->getTerrainDescr(h->getPosition(false), hlp, false);
  1859. int msgToShow = -1;
  1860. CGHeroInstance::ECanDig isDiggingPossible = h->diggingStatus();
  1861. if(hlp.length())
  1862. isDiggingPossible = CGHeroInstance::TILE_OCCUPIED; //TODO integrate with canDig
  1863. switch(isDiggingPossible)
  1864. {
  1865. case CGHeroInstance::CAN_DIG:
  1866. break;
  1867. case CGHeroInstance::LACK_OF_MOVEMENT:
  1868. msgToShow = 56; //"Digging for artifacts requires a whole day, try again tomorrow."
  1869. break;
  1870. case CGHeroInstance::TILE_OCCUPIED:
  1871. msgToShow = 97; //Try searching on clear ground.
  1872. break;
  1873. case CGHeroInstance::WRONG_TERRAIN:
  1874. msgToShow = 60; ////Try looking on land!
  1875. break;
  1876. default:
  1877. assert(0);
  1878. }
  1879. if(msgToShow < 0)
  1880. cb->dig(h);
  1881. else
  1882. showInfoDialog(CGI->generaltexth->allTexts[msgToShow]);
  1883. }
  1884. void CPlayerInterface::updateInfo(const CGObjectInstance * specific)
  1885. {
  1886. adventureInt->infoBar.showSelection();
  1887. }
  1888. void CPlayerInterface::battleNewRoundFirst( int round )
  1889. {
  1890. EVENT_HANDLER_CALLED_BY_CLIENT;
  1891. if(LOCPLINT != this)
  1892. { //another local interface should do this
  1893. return;
  1894. }
  1895. battleInt->newRoundFirst(round);
  1896. }
  1897. void CPlayerInterface::stopMovement()
  1898. {
  1899. if(stillMoveHero.get() == DURING_MOVE)//if we are in the middle of hero movement
  1900. stillMoveHero.setn(STOP_MOVE); //after showing dialog movement will be stopped
  1901. }
  1902. void CPlayerInterface::showMarketWindow(const IMarket *market, const CGHeroInstance *visitor)
  1903. {
  1904. EVENT_HANDLER_CALLED_BY_CLIENT;
  1905. if(market->o->ID == 2) //Altar
  1906. {
  1907. //EEMarketMode mode = market->availableModes().front();
  1908. if(market->allowsTrade(EMarketMode::ARTIFACT_EXP) && visitor->getAlignment() != EAlignment::EVIL)
  1909. GH.pushInt(new CAltarWindow(market, visitor, EMarketMode::ARTIFACT_EXP));
  1910. else if(market->allowsTrade(EMarketMode::CREATURE_EXP) && visitor->getAlignment() != EAlignment::GOOD)
  1911. GH.pushInt(new CAltarWindow(market, visitor, EMarketMode::CREATURE_EXP));
  1912. }
  1913. else
  1914. GH.pushInt(new CMarketplaceWindow(market, visitor, market->availableModes().front()));
  1915. }
  1916. void CPlayerInterface::showUniversityWindow(const IMarket *market, const CGHeroInstance *visitor)
  1917. {
  1918. EVENT_HANDLER_CALLED_BY_CLIENT;
  1919. CUniversityWindow *cuw = new CUniversityWindow(visitor, market);
  1920. GH.pushInt(cuw);
  1921. }
  1922. void CPlayerInterface::showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor)
  1923. {
  1924. EVENT_HANDLER_CALLED_BY_CLIENT;
  1925. CHillFortWindow *chfw = new CHillFortWindow(visitor, object);
  1926. GH.pushInt(chfw);
  1927. }
  1928. void CPlayerInterface::availableArtifactsChanged(const CGBlackMarket *bm /*= NULL*/)
  1929. {
  1930. EVENT_HANDLER_CALLED_BY_CLIENT;
  1931. if(CMarketplaceWindow *cmw = dynamic_cast<CMarketplaceWindow*>(GH.topInt()))
  1932. cmw->artifactsChanged(false);
  1933. }
  1934. void CPlayerInterface::showTavernWindow(const CGObjectInstance *townOrTavern)
  1935. {
  1936. EVENT_HANDLER_CALLED_BY_CLIENT;
  1937. CTavernWindow *tv = new CTavernWindow(townOrTavern);
  1938. GH.pushInt(tv);
  1939. }
  1940. void CPlayerInterface::showThievesGuildWindow (const CGObjectInstance * obj)
  1941. {
  1942. EVENT_HANDLER_CALLED_BY_CLIENT;
  1943. CThievesGuildWindow *tgw = new CThievesGuildWindow(obj);
  1944. GH.pushInt(tgw);
  1945. }
  1946. void CPlayerInterface::showQuestLog()
  1947. {
  1948. EVENT_HANDLER_CALLED_BY_CLIENT;
  1949. CQuestLog * ql = new CQuestLog (LOCPLINT->cb->getMyQuests());
  1950. GH.pushInt (ql);
  1951. }
  1952. void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj)
  1953. {
  1954. if(obj->state())
  1955. {
  1956. MetaString txt;
  1957. obj->getProblemText(txt);
  1958. showInfoDialog(txt.toString());
  1959. }
  1960. else
  1961. showShipyardDialog(obj);
  1962. }
  1963. void CPlayerInterface::requestReturningToMainMenu()
  1964. {
  1965. sendCustomEvent(RETURN_TO_MAIN_MENU);
  1966. }
  1967. void CPlayerInterface::requestStoppingClient()
  1968. {
  1969. sendCustomEvent(STOP_CLIENT);
  1970. }
  1971. void CPlayerInterface::sendCustomEvent( int code )
  1972. {
  1973. SDL_Event event;
  1974. event.type = SDL_USEREVENT;
  1975. event.user.code = code;
  1976. SDL_PushEvent(&event);
  1977. }
  1978. void CPlayerInterface::stackChagedCount(const StackLocation &location, const TQuantity &change, bool isAbsolute)
  1979. {
  1980. EVENT_HANDLER_CALLED_BY_CLIENT;
  1981. garrisonChanged(location.army);
  1982. }
  1983. void CPlayerInterface::stackChangedType(const StackLocation &location, const CCreature &newType)
  1984. {
  1985. EVENT_HANDLER_CALLED_BY_CLIENT;
  1986. garrisonChanged(location.army);
  1987. }
  1988. void CPlayerInterface::stacksErased(const StackLocation &location)
  1989. {
  1990. EVENT_HANDLER_CALLED_BY_CLIENT;
  1991. garrisonChanged(location.army);
  1992. }
  1993. void CPlayerInterface::stacksSwapped(const StackLocation &loc1, const StackLocation &loc2)
  1994. {
  1995. EVENT_HANDLER_CALLED_BY_CLIENT;
  1996. garrisonChanged(loc1.army);
  1997. if(loc2.army != loc1.army)
  1998. garrisonChanged(loc2.army);
  1999. }
  2000. void CPlayerInterface::newStackInserted(const StackLocation &location, const CStackInstance &stack)
  2001. {
  2002. EVENT_HANDLER_CALLED_BY_CLIENT;
  2003. garrisonChanged(location.army);
  2004. }
  2005. void CPlayerInterface::stacksRebalanced(const StackLocation &src, const StackLocation &dst, TQuantity count)
  2006. {
  2007. EVENT_HANDLER_CALLED_BY_CLIENT;
  2008. garrisonChanged(src.army);
  2009. if(dst.army != src.army)
  2010. garrisonChanged(dst.army);
  2011. }
  2012. #undef UPDATE_IF
  2013. void CPlayerInterface::artifactPut(const ArtifactLocation &al)
  2014. {
  2015. EVENT_HANDLER_CALLED_BY_CLIENT;
  2016. }
  2017. void CPlayerInterface::artifactRemoved(const ArtifactLocation &al)
  2018. {
  2019. EVENT_HANDLER_CALLED_BY_CLIENT;
  2020. BOOST_FOREACH(IShowActivatable *isa, GH.listInt)
  2021. {
  2022. auto artWin = dynamic_cast<CArtifactHolder*>(isa);
  2023. if(artWin)
  2024. artWin->artifactRemoved(al);
  2025. }
  2026. }
  2027. void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst)
  2028. {
  2029. EVENT_HANDLER_CALLED_BY_CLIENT;
  2030. BOOST_FOREACH(IShowActivatable *isa, GH.listInt)
  2031. {
  2032. auto artWin = dynamic_cast<CArtifactHolder*>(isa);
  2033. if(artWin)
  2034. artWin->artifactMoved(src, dst);
  2035. }
  2036. }
  2037. void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
  2038. {
  2039. EVENT_HANDLER_CALLED_BY_CLIENT;
  2040. BOOST_FOREACH(IShowActivatable *isa, GH.listInt)
  2041. {
  2042. auto artWin = dynamic_cast<CArtifactHolder*>(isa);
  2043. if(artWin)
  2044. artWin->artifactAssembled(al);
  2045. }
  2046. }
  2047. void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
  2048. {
  2049. EVENT_HANDLER_CALLED_BY_CLIENT;
  2050. BOOST_FOREACH(IShowActivatable *isa, GH.listInt)
  2051. {
  2052. auto artWin = dynamic_cast<CArtifactHolder*>(isa);
  2053. if(artWin)
  2054. artWin->artifactDisassembled(al);
  2055. }
  2056. }
  2057. void CPlayerInterface::playerStartsTurn(ui8 player)
  2058. {
  2059. EVENT_HANDLER_CALLED_BY_CLIENT;
  2060. if(!GH.listInt.size())
  2061. {
  2062. GH.pushInt(adventureInt);
  2063. }
  2064. if(howManyPeople == 1)
  2065. {
  2066. GH.curInt = this;
  2067. adventureInt->startTurn();
  2068. }
  2069. if(player != playerID && this == LOCPLINT)
  2070. {
  2071. waitWhileDialog();
  2072. adventureInt->aiTurnStarted();
  2073. }
  2074. }
  2075. void CPlayerInterface::waitForAllDialogs(bool unlockPim /*= true*/)
  2076. {
  2077. while(dialogs.size())
  2078. {
  2079. auto unlock = vstd::makeUnlockGuardIf(*pim, unlockPim);
  2080. SDL_Delay(5);
  2081. }
  2082. waitWhileDialog(unlockPim);
  2083. }
  2084. void CPlayerInterface::proposeLoadingGame()
  2085. {
  2086. showYesNoDialog(CGI->generaltexth->allTexts[68], [this] { sendCustomEvent(RETURN_TO_MENU_LOAD); }, 0, false);
  2087. }
  2088. CPlayerInterface::SpellbookLastSetting::SpellbookLastSetting()
  2089. {
  2090. spellbookLastPageBattle = spellbokLastPageAdvmap = 0;
  2091. spellbookLastTabBattle = spellbookLastTabAdvmap = 4;
  2092. }