CPlayerInterface.cpp 80 KB

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