2
0

CPlayerInterface.cpp 80 KB

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