CPlayerInterface.cpp 80 KB

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