NetPacksClient.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. /*
  2. * NetPacksClient.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "ClientNetPackVisitors.h"
  12. #include "Client.h"
  13. #include "CPlayerInterface.h"
  14. #include "CGameInfo.h"
  15. #include "windows/GUIClasses.h"
  16. #include "mapView/mapHandler.h"
  17. #include "adventureMap/CInGameConsole.h"
  18. #include "battle/BattleInterface.h"
  19. #include "battle/BattleWindow.h"
  20. #include "gui/CGuiHandler.h"
  21. #include "gui/WindowHandler.h"
  22. #include "widgets/MiscWidgets.h"
  23. #include "CMT.h"
  24. #include "CServerHandler.h"
  25. #include "../CCallback.h"
  26. #include "../lib/filesystem/Filesystem.h"
  27. #include "../lib/filesystem/FileInfo.h"
  28. #include "../lib/serializer/Connection.h"
  29. #include "../lib/serializer/BinarySerializer.h"
  30. #include "../lib/CGeneralTextHandler.h"
  31. #include "../lib/CHeroHandler.h"
  32. #include "../lib/VCMI_Lib.h"
  33. #include "../lib/mapping/CMap.h"
  34. #include "../lib/VCMIDirs.h"
  35. #include "../lib/spells/CSpellHandler.h"
  36. #include "../lib/CSoundBase.h"
  37. #include "../lib/StartInfo.h"
  38. #include "../lib/CConfigHandler.h"
  39. #include "../lib/mapObjects/CGMarket.h"
  40. #include "../lib/gameState/CGameState.h"
  41. #include "../lib/CStack.h"
  42. #include "../lib/battle/BattleInfo.h"
  43. #include "../lib/GameConstants.h"
  44. #include "../lib/CPlayerState.h"
  45. // TODO: as Tow suggested these template should all be part of CClient
  46. // This will require rework spectator interface properly though
  47. template<typename T, typename ... Args, typename ... Args2>
  48. bool callOnlyThatInterface(CClient & cl, PlayerColor player, void (T::*ptr)(Args...), Args2 && ...args)
  49. {
  50. if(vstd::contains(cl.playerint, player))
  51. {
  52. ((*cl.playerint[player]).*ptr)(std::forward<Args2>(args)...);
  53. return true;
  54. }
  55. return false;
  56. }
  57. template<typename T, typename ... Args, typename ... Args2>
  58. bool callInterfaceIfPresent(CClient & cl, PlayerColor player, void (T::*ptr)(Args...), Args2 && ...args)
  59. {
  60. bool called = callOnlyThatInterface(cl, player, ptr, std::forward<Args2>(args)...);
  61. return called;
  62. }
  63. template<typename T, typename ... Args, typename ... Args2>
  64. void callOnlyThatBattleInterface(CClient & cl, PlayerColor player, void (T::*ptr)(Args...), Args2 && ...args)
  65. {
  66. if(vstd::contains(cl.battleints,player))
  67. ((*cl.battleints[player]).*ptr)(std::forward<Args2>(args)...);
  68. if(cl.additionalBattleInts.count(player))
  69. {
  70. for(auto bInt : cl.additionalBattleInts[player])
  71. ((*bInt).*ptr)(std::forward<Args2>(args)...);
  72. }
  73. }
  74. template<typename T, typename ... Args, typename ... Args2>
  75. void callBattleInterfaceIfPresent(CClient & cl, PlayerColor player, void (T::*ptr)(Args...), Args2 && ...args)
  76. {
  77. callOnlyThatInterface(cl, player, ptr, std::forward<Args2>(args)...);
  78. }
  79. //calls all normal interfaces and privileged ones, playerints may be updated when iterating over it, so we need a copy
  80. template<typename T, typename ... Args, typename ... Args2>
  81. void callAllInterfaces(CClient & cl, void (T::*ptr)(Args...), Args2 && ...args)
  82. {
  83. for(auto pInt : cl.playerint)
  84. ((*pInt.second).*ptr)(std::forward<Args2>(args)...);
  85. }
  86. //calls all normal interfaces and privileged ones, playerints may be updated when iterating over it, so we need a copy
  87. template<typename T, typename ... Args, typename ... Args2>
  88. void callBattleInterfaceIfPresentForBothSides(CClient & cl, void (T::*ptr)(Args...), Args2 && ...args)
  89. {
  90. assert(cl.gameState()->curB);
  91. if (!cl.gameState()->curB)
  92. {
  93. logGlobal->error("Attempt to call battle interface without ongoing battle!");
  94. return;
  95. }
  96. callOnlyThatBattleInterface(cl, cl.gameState()->curB->sides[0].color, ptr, std::forward<Args2>(args)...);
  97. callOnlyThatBattleInterface(cl, cl.gameState()->curB->sides[1].color, ptr, std::forward<Args2>(args)...);
  98. if(settings["session"]["spectate"].Bool() && !settings["session"]["spectate-skip-battle"].Bool() && LOCPLINT->battleInt)
  99. {
  100. callOnlyThatBattleInterface(cl, PlayerColor::SPECTATOR, ptr, std::forward<Args2>(args)...);
  101. }
  102. }
  103. void ApplyClientNetPackVisitor::visitSetResources(SetResources & pack)
  104. {
  105. //todo: inform on actual resource set transfered
  106. callInterfaceIfPresent(cl, pack.player, &IGameEventsReceiver::receivedResource);
  107. }
  108. void ApplyClientNetPackVisitor::visitSetPrimSkill(SetPrimSkill & pack)
  109. {
  110. const CGHeroInstance * h = cl.getHero(pack.id);
  111. if(!h)
  112. {
  113. logNetwork->error("Cannot find hero with pack.id %d", pack.id.getNum());
  114. return;
  115. }
  116. callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroPrimarySkillChanged, h, pack.which, pack.val);
  117. }
  118. void ApplyClientNetPackVisitor::visitSetSecSkill(SetSecSkill & pack)
  119. {
  120. const CGHeroInstance *h = cl.getHero(pack.id);
  121. if(!h)
  122. {
  123. logNetwork->error("Cannot find hero with pack.id %d", pack.id.getNum());
  124. return;
  125. }
  126. callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroSecondarySkillChanged, h, pack.which, pack.val);
  127. }
  128. void ApplyClientNetPackVisitor::visitHeroVisitCastle(HeroVisitCastle & pack)
  129. {
  130. const CGHeroInstance *h = cl.getHero(pack.hid);
  131. if(pack.start())
  132. {
  133. callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroVisitsTown, h, gs.getTown(pack.tid));
  134. }
  135. }
  136. void ApplyClientNetPackVisitor::visitSetMana(SetMana & pack)
  137. {
  138. const CGHeroInstance *h = cl.getHero(pack.hid);
  139. callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroManaPointsChanged, h);
  140. for (auto window : GH.windows().findWindows<BattleWindow>())
  141. window->heroManaPointsChanged(h);
  142. }
  143. void ApplyClientNetPackVisitor::visitSetMovePoints(SetMovePoints & pack)
  144. {
  145. const CGHeroInstance *h = cl.getHero(pack.hid);
  146. cl.invalidatePaths();
  147. callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroMovePointsChanged, h);
  148. }
  149. void ApplyClientNetPackVisitor::visitFoWChange(FoWChange & pack)
  150. {
  151. for(auto &i : cl.playerint)
  152. {
  153. if(cl.getPlayerRelations(i.first, pack.player) == PlayerRelations::SAME_PLAYER && pack.waitForDialogs && LOCPLINT == i.second.get())
  154. {
  155. LOCPLINT->waitWhileDialog();
  156. }
  157. if(cl.getPlayerRelations(i.first, pack.player) != PlayerRelations::ENEMIES)
  158. {
  159. if(pack.mode)
  160. i.second->tileRevealed(pack.tiles);
  161. else
  162. i.second->tileHidden(pack.tiles);
  163. }
  164. }
  165. cl.invalidatePaths();
  166. }
  167. static void dispatchGarrisonChange(CClient & cl, ObjectInstanceID army1, ObjectInstanceID army2)
  168. {
  169. auto obj1 = cl.getObj(army1);
  170. if(!obj1)
  171. {
  172. logNetwork->error("Cannot find army with pack.id %d", army1.getNum());
  173. return;
  174. }
  175. callInterfaceIfPresent(cl, obj1->tempOwner, &IGameEventsReceiver::garrisonsChanged, army1, army2);
  176. if(army2 != ObjectInstanceID() && army2 != army1)
  177. {
  178. auto obj2 = cl.getObj(army2);
  179. if(!obj2)
  180. {
  181. logNetwork->error("Cannot find army with pack.id %d", army2.getNum());
  182. return;
  183. }
  184. if(obj1->tempOwner != obj2->tempOwner)
  185. callInterfaceIfPresent(cl, obj2->tempOwner, &IGameEventsReceiver::garrisonsChanged, army1, army2);
  186. }
  187. }
  188. void ApplyClientNetPackVisitor::visitChangeStackCount(ChangeStackCount & pack)
  189. {
  190. dispatchGarrisonChange(cl, pack.army, ObjectInstanceID());
  191. }
  192. void ApplyClientNetPackVisitor::visitSetStackType(SetStackType & pack)
  193. {
  194. dispatchGarrisonChange(cl, pack.army, ObjectInstanceID());
  195. }
  196. void ApplyClientNetPackVisitor::visitEraseStack(EraseStack & pack)
  197. {
  198. dispatchGarrisonChange(cl, pack.army, ObjectInstanceID());
  199. }
  200. void ApplyClientNetPackVisitor::visitSwapStacks(SwapStacks & pack)
  201. {
  202. dispatchGarrisonChange(cl, pack.srcArmy, pack.dstArmy);
  203. }
  204. void ApplyClientNetPackVisitor::visitInsertNewStack(InsertNewStack & pack)
  205. {
  206. dispatchGarrisonChange(cl, pack.army, ObjectInstanceID());
  207. }
  208. void ApplyClientNetPackVisitor::visitRebalanceStacks(RebalanceStacks & pack)
  209. {
  210. dispatchGarrisonChange(cl, pack.srcArmy, pack.dstArmy);
  211. }
  212. void ApplyClientNetPackVisitor::visitBulkRebalanceStacks(BulkRebalanceStacks & pack)
  213. {
  214. if(!pack.moves.empty())
  215. {
  216. auto destArmy = pack.moves[0].srcArmy == pack.moves[0].dstArmy
  217. ? ObjectInstanceID()
  218. : pack.moves[0].dstArmy;
  219. dispatchGarrisonChange(cl, pack.moves[0].srcArmy, destArmy);
  220. }
  221. }
  222. void ApplyClientNetPackVisitor::visitBulkSmartRebalanceStacks(BulkSmartRebalanceStacks & pack)
  223. {
  224. if(!pack.moves.empty())
  225. {
  226. assert(pack.moves[0].srcArmy == pack.moves[0].dstArmy);
  227. dispatchGarrisonChange(cl, pack.moves[0].srcArmy, ObjectInstanceID());
  228. }
  229. else if(!pack.changes.empty())
  230. {
  231. dispatchGarrisonChange(cl, pack.changes[0].army, ObjectInstanceID());
  232. }
  233. }
  234. void ApplyClientNetPackVisitor::visitPutArtifact(PutArtifact & pack)
  235. {
  236. callInterfaceIfPresent(cl, pack.al.owningPlayer(), &IGameEventsReceiver::artifactPut, pack.al);
  237. if(pack.askAssemble)
  238. callInterfaceIfPresent(cl, pack.al.owningPlayer(), &IGameEventsReceiver::askToAssembleArtifact, pack.al);
  239. }
  240. void ApplyClientNetPackVisitor::visitEraseArtifact(EraseArtifact & pack)
  241. {
  242. callInterfaceIfPresent(cl, pack.al.owningPlayer(), &IGameEventsReceiver::artifactRemoved, pack.al);
  243. }
  244. void ApplyClientNetPackVisitor::visitMoveArtifact(MoveArtifact & pack)
  245. {
  246. auto moveArtifact = [this, &pack](PlayerColor player) -> void
  247. {
  248. callInterfaceIfPresent(cl, player, &IGameEventsReceiver::artifactMoved, pack.src, pack.dst);
  249. if(pack.askAssemble)
  250. callInterfaceIfPresent(cl, player, &IGameEventsReceiver::askToAssembleArtifact, pack.dst);
  251. };
  252. moveArtifact(pack.src.owningPlayer());
  253. if(pack.src.owningPlayer() != pack.dst.owningPlayer())
  254. moveArtifact(pack.dst.owningPlayer());
  255. cl.invalidatePaths(); // hero might have equipped/unequipped Angel Wings
  256. }
  257. void ApplyClientNetPackVisitor::visitBulkMoveArtifacts(BulkMoveArtifacts & pack)
  258. {
  259. auto applyMove = [this, &pack](std::vector<BulkMoveArtifacts::LinkedSlots> & artsPack) -> void
  260. {
  261. for(auto & slotToMove : artsPack)
  262. {
  263. auto srcLoc = ArtifactLocation(pack.srcArtHolder, slotToMove.srcPos);
  264. auto dstLoc = ArtifactLocation(pack.dstArtHolder, slotToMove.dstPos);
  265. MoveArtifact ma(&srcLoc, &dstLoc, false);
  266. visitMoveArtifact(ma);
  267. }
  268. };
  269. // Begin a session of bulk movement of arts. It is not necessary but useful for the client optimization.
  270. callInterfaceIfPresent(cl, cl.getCurrentPlayer(), &IGameEventsReceiver::bulkArtMovementStart,
  271. pack.artsPack0.size() + pack.artsPack1.size());
  272. applyMove(pack.artsPack0);
  273. if(pack.swap)
  274. applyMove(pack.artsPack1);
  275. }
  276. void ApplyClientNetPackVisitor::visitAssembledArtifact(AssembledArtifact & pack)
  277. {
  278. callInterfaceIfPresent(cl, pack.al.owningPlayer(), &IGameEventsReceiver::artifactAssembled, pack.al);
  279. cl.invalidatePaths(); // hero might have equipped/unequipped Angel Wings
  280. }
  281. void ApplyClientNetPackVisitor::visitDisassembledArtifact(DisassembledArtifact & pack)
  282. {
  283. callInterfaceIfPresent(cl, pack.al.owningPlayer(), &IGameEventsReceiver::artifactDisassembled, pack.al);
  284. cl.invalidatePaths(); // hero might have equipped/unequipped Angel Wings
  285. }
  286. void ApplyClientNetPackVisitor::visitHeroVisit(HeroVisit & pack)
  287. {
  288. auto hero = cl.getHero(pack.heroId);
  289. auto obj = cl.getObj(pack.objId, false);
  290. callInterfaceIfPresent(cl, pack.player, &IGameEventsReceiver::heroVisit, hero, obj, pack.starting);
  291. }
  292. void ApplyClientNetPackVisitor::visitNewTurn(NewTurn & pack)
  293. {
  294. cl.invalidatePaths();
  295. }
  296. void ApplyClientNetPackVisitor::visitGiveBonus(GiveBonus & pack)
  297. {
  298. cl.invalidatePaths();
  299. switch(pack.who)
  300. {
  301. case GiveBonus::ETarget::HERO:
  302. {
  303. const CGHeroInstance *h = gs.getHero(ObjectInstanceID(pack.id));
  304. callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroBonusChanged, h, pack.bonus, true);
  305. }
  306. break;
  307. case GiveBonus::ETarget::PLAYER:
  308. {
  309. callInterfaceIfPresent(cl, PlayerColor(pack.id), &IGameEventsReceiver::playerBonusChanged, pack.bonus, true);
  310. }
  311. break;
  312. }
  313. }
  314. void ApplyFirstClientNetPackVisitor::visitChangeObjPos(ChangeObjPos & pack)
  315. {
  316. CGObjectInstance *obj = gs.getObjInstance(pack.objid);
  317. if(CGI->mh)
  318. CGI->mh->onObjectFadeOut(obj);
  319. CGI->mh->waitForOngoingAnimations();
  320. }
  321. void ApplyClientNetPackVisitor::visitChangeObjPos(ChangeObjPos & pack)
  322. {
  323. CGObjectInstance *obj = gs.getObjInstance(pack.objid);
  324. if(CGI->mh)
  325. CGI->mh->onObjectFadeIn(obj);
  326. CGI->mh->waitForOngoingAnimations();
  327. cl.invalidatePaths();
  328. }
  329. void ApplyClientNetPackVisitor::visitPlayerEndsGame(PlayerEndsGame & pack)
  330. {
  331. callAllInterfaces(cl, &IGameEventsReceiver::gameOver, pack.player, pack.victoryLossCheckResult);
  332. // In auto testing pack.mode we always close client if red pack.player won or lose
  333. if(!settings["session"]["testmap"].isNull() && pack.player == PlayerColor(0))
  334. handleQuit(settings["session"]["spectate"].Bool()); // if spectator is active ask to close client or not
  335. }
  336. void ApplyClientNetPackVisitor::visitPlayerReinitInterface(PlayerReinitInterface & pack)
  337. {
  338. auto initInterfaces = [this]()
  339. {
  340. cl.initPlayerInterfaces();
  341. auto currentPlayer = cl.gameState()->currentPlayer;
  342. callAllInterfaces(cl, &IGameEventsReceiver::playerStartsTurn, currentPlayer);
  343. callOnlyThatInterface(cl, currentPlayer, &CGameInterface::yourTurn);
  344. };
  345. for(auto player : pack.players)
  346. {
  347. auto & plSettings = CSH->si->getIthPlayersSettings(player);
  348. if(pack.playerConnectionId == PlayerSettings::PLAYER_AI)
  349. {
  350. plSettings.connectedPlayerIDs.clear();
  351. cl.initPlayerEnvironments();
  352. initInterfaces();
  353. }
  354. else if(pack.playerConnectionId == CSH->c->connectionID)
  355. {
  356. plSettings.connectedPlayerIDs.insert(pack.playerConnectionId);
  357. cl.playerint.clear();
  358. initInterfaces();
  359. }
  360. }
  361. }
  362. void ApplyClientNetPackVisitor::visitRemoveBonus(RemoveBonus & pack)
  363. {
  364. cl.invalidatePaths();
  365. switch(pack.who)
  366. {
  367. case GiveBonus::ETarget::HERO:
  368. {
  369. const CGHeroInstance *h = gs.getHero(ObjectInstanceID(pack.id));
  370. callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroBonusChanged, h, pack.bonus, false);
  371. }
  372. break;
  373. case GiveBonus::ETarget::PLAYER:
  374. {
  375. //const PlayerState *p = gs.getPlayerState(pack.id);
  376. callInterfaceIfPresent(cl, PlayerColor(pack.id), &IGameEventsReceiver::playerBonusChanged, pack.bonus, false);
  377. }
  378. break;
  379. }
  380. }
  381. void ApplyFirstClientNetPackVisitor::visitRemoveObject(RemoveObject & pack)
  382. {
  383. const CGObjectInstance *o = cl.getObj(pack.id);
  384. if(CGI->mh)
  385. CGI->mh->onObjectFadeOut(o);
  386. //notify interfaces about removal
  387. for(auto i=cl.playerint.begin(); i!=cl.playerint.end(); i++)
  388. {
  389. //below line contains little cheat for AI so it will be aware of deletion of enemy heroes that moved or got re-covered by FoW
  390. //TODO: loose requirements as next AI related crashes appear, for example another pack.player collects object that got re-covered by FoW, unsure if AI code workarounds this
  391. if(gs.isVisible(o, i->first) || (!cl.getPlayerState(i->first)->human && o->ID == Obj::HERO && o->tempOwner != i->first))
  392. i->second->objectRemoved(o);
  393. }
  394. CGI->mh->waitForOngoingAnimations();
  395. }
  396. void ApplyClientNetPackVisitor::visitRemoveObject(RemoveObject & pack)
  397. {
  398. cl.invalidatePaths();
  399. for(auto i=cl.playerint.begin(); i!=cl.playerint.end(); i++)
  400. i->second->objectRemovedAfter();
  401. }
  402. void ApplyFirstClientNetPackVisitor::visitTryMoveHero(TryMoveHero & pack)
  403. {
  404. CGHeroInstance *h = gs.getHero(pack.id);
  405. if(CGI->mh)
  406. {
  407. switch (pack.result)
  408. {
  409. case TryMoveHero::EMBARK:
  410. CGI->mh->onBeforeHeroEmbark(h, pack.start, pack.end);
  411. break;
  412. case TryMoveHero::TELEPORTATION:
  413. CGI->mh->onBeforeHeroTeleported(h, pack.start, pack.end);
  414. break;
  415. case TryMoveHero::DISEMBARK:
  416. CGI->mh->onBeforeHeroDisembark(h, pack.start, pack.end);
  417. break;
  418. }
  419. CGI->mh->waitForOngoingAnimations();
  420. }
  421. }
  422. void ApplyClientNetPackVisitor::visitTryMoveHero(TryMoveHero & pack)
  423. {
  424. const CGHeroInstance *h = cl.getHero(pack.id);
  425. cl.invalidatePaths();
  426. if(CGI->mh)
  427. {
  428. switch(pack.result)
  429. {
  430. case TryMoveHero::SUCCESS:
  431. CGI->mh->onHeroMoved(h, pack.start, pack.end);
  432. break;
  433. case TryMoveHero::EMBARK:
  434. CGI->mh->onAfterHeroEmbark(h, pack.start, pack.end);
  435. break;
  436. case TryMoveHero::TELEPORTATION:
  437. CGI->mh->onAfterHeroTeleported(h, pack.start, pack.end);
  438. break;
  439. case TryMoveHero::DISEMBARK:
  440. CGI->mh->onAfterHeroDisembark(h, pack.start, pack.end);
  441. break;
  442. }
  443. }
  444. PlayerColor player = h->tempOwner;
  445. for(auto &i : cl.playerint)
  446. if(cl.getPlayerRelations(i.first, player) != PlayerRelations::ENEMIES)
  447. i.second->tileRevealed(pack.fowRevealed);
  448. for(auto i=cl.playerint.begin(); i!=cl.playerint.end(); i++)
  449. {
  450. if(i->first != PlayerColor::SPECTATOR && gs.checkForStandardLoss(i->first)) // Do not notify vanquished pack.player's interface
  451. continue;
  452. if(gs.isVisible(h->convertToVisitablePos(pack.start), i->first)
  453. || gs.isVisible(h->convertToVisitablePos(pack.end), i->first))
  454. {
  455. // pack.src and pack.dst of enemy hero move may be not visible => 'verbose' should be false
  456. const bool verbose = cl.getPlayerRelations(i->first, player) != PlayerRelations::ENEMIES;
  457. i->second->heroMoved(pack, verbose);
  458. }
  459. }
  460. }
  461. void ApplyClientNetPackVisitor::visitNewStructures(NewStructures & pack)
  462. {
  463. CGTownInstance *town = gs.getTown(pack.tid);
  464. for(const auto & id : pack.bid)
  465. {
  466. callInterfaceIfPresent(cl, town->tempOwner, &IGameEventsReceiver::buildChanged, town, id, 1);
  467. }
  468. // invalidate section of map view with our object and force an update
  469. CGI->mh->onObjectInstantRemove(town);
  470. CGI->mh->onObjectInstantAdd(town);
  471. }
  472. void ApplyClientNetPackVisitor::visitRazeStructures(RazeStructures & pack)
  473. {
  474. CGTownInstance * town = gs.getTown(pack.tid);
  475. for(const auto & id : pack.bid)
  476. {
  477. callInterfaceIfPresent(cl, town->tempOwner, &IGameEventsReceiver::buildChanged, town, id, 2);
  478. }
  479. // invalidate section of map view with our object and force an update
  480. CGI->mh->onObjectInstantRemove(town);
  481. CGI->mh->onObjectInstantAdd(town);
  482. }
  483. void ApplyClientNetPackVisitor::visitSetAvailableCreatures(SetAvailableCreatures & pack)
  484. {
  485. const CGDwelling * dw = static_cast<const CGDwelling*>(cl.getObj(pack.tid));
  486. PlayerColor p;
  487. if(dw->ID == Obj::WAR_MACHINE_FACTORY) //War Machines Factory is not flaggable, it's "owned" by visitor
  488. p = cl.getTile(dw->visitablePos())->visitableObjects.back()->tempOwner;
  489. else
  490. p = dw->tempOwner;
  491. callInterfaceIfPresent(cl, p, &IGameEventsReceiver::availableCreaturesChanged, dw);
  492. }
  493. void ApplyClientNetPackVisitor::visitSetHeroesInTown(SetHeroesInTown & pack)
  494. {
  495. CGTownInstance * t = gs.getTown(pack.tid);
  496. CGHeroInstance * hGarr = gs.getHero(pack.garrison);
  497. CGHeroInstance * hVisit = gs.getHero(pack.visiting);
  498. //inform all players that see this object
  499. for(auto i = cl.playerint.cbegin(); i != cl.playerint.cend(); ++i)
  500. {
  501. if(i->first >= PlayerColor::PLAYER_LIMIT)
  502. continue;
  503. if(gs.isVisible(t, i->first) ||
  504. (hGarr && gs.isVisible(hGarr, i->first)) ||
  505. (hVisit && gs.isVisible(hVisit, i->first)))
  506. {
  507. cl.playerint[i->first]->heroInGarrisonChange(t);
  508. }
  509. }
  510. }
  511. void ApplyClientNetPackVisitor::visitHeroRecruited(HeroRecruited & pack)
  512. {
  513. CGHeroInstance *h = gs.map->heroesOnMap.back();
  514. if(h->subID != pack.hid)
  515. {
  516. logNetwork->error("Something wrong with hero recruited!");
  517. }
  518. if(callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroCreated, h))
  519. {
  520. if(const CGTownInstance *t = gs.getTown(pack.tid))
  521. callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroInGarrisonChange, t);
  522. }
  523. if(CGI->mh)
  524. CGI->mh->onObjectInstantAdd(h);
  525. }
  526. void ApplyClientNetPackVisitor::visitGiveHero(GiveHero & pack)
  527. {
  528. CGHeroInstance *h = gs.getHero(pack.id);
  529. if(CGI->mh)
  530. CGI->mh->onObjectInstantAdd(h);
  531. callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroCreated, h);
  532. }
  533. void ApplyFirstClientNetPackVisitor::visitGiveHero(GiveHero & pack)
  534. {
  535. }
  536. void ApplyClientNetPackVisitor::visitInfoWindow(InfoWindow & pack)
  537. {
  538. std::string str = pack.text.toString();
  539. if(!callInterfaceIfPresent(cl, pack.player, &CGameInterface::showInfoDialog, pack.type, str, pack.components,(soundBase::soundID)pack.soundID))
  540. logNetwork->warn("We received InfoWindow for not our player...");
  541. }
  542. void ApplyFirstClientNetPackVisitor::visitSetObjectProperty(SetObjectProperty & pack)
  543. {
  544. //inform all players that see this object
  545. for(auto it = cl.playerint.cbegin(); it != cl.playerint.cend(); ++it)
  546. {
  547. if(gs.isVisible(gs.getObjInstance(pack.id), it->first))
  548. callInterfaceIfPresent(cl, it->first, &IGameEventsReceiver::beforeObjectPropertyChanged, &pack);
  549. }
  550. // invalidate section of map view with our object and force an update with new flag color
  551. if (pack.what == ObjProperty::OWNER)
  552. CGI->mh->onObjectInstantRemove(gs.getObjInstance(pack.id));
  553. }
  554. void ApplyClientNetPackVisitor::visitSetObjectProperty(SetObjectProperty & pack)
  555. {
  556. //inform all players that see this object
  557. for(auto it = cl.playerint.cbegin(); it != cl.playerint.cend(); ++it)
  558. {
  559. if(gs.isVisible(gs.getObjInstance(pack.id), it->first))
  560. callInterfaceIfPresent(cl, it->first, &IGameEventsReceiver::objectPropertyChanged, &pack);
  561. }
  562. // invalidate section of map view with our object and force an update with new flag color
  563. if (pack.what == ObjProperty::OWNER)
  564. CGI->mh->onObjectInstantAdd(gs.getObjInstance(pack.id));
  565. }
  566. void ApplyClientNetPackVisitor::visitHeroLevelUp(HeroLevelUp & pack)
  567. {
  568. const CGHeroInstance * hero = cl.getHero(pack.heroId);
  569. assert(hero);
  570. callOnlyThatInterface(cl, pack.player, &CGameInterface::heroGotLevel, hero, pack.primskill, pack.skills, pack.queryID);
  571. }
  572. void ApplyClientNetPackVisitor::visitCommanderLevelUp(CommanderLevelUp & pack)
  573. {
  574. const CGHeroInstance * hero = cl.getHero(pack.heroId);
  575. assert(hero);
  576. const CCommanderInstance * commander = hero->commander;
  577. assert(commander);
  578. assert(commander->armyObj); //is it possible for Commander to exist beyond armed instance?
  579. callOnlyThatInterface(cl, pack.player, &CGameInterface::commanderGotLevel, commander, pack.skills, pack.queryID);
  580. }
  581. void ApplyClientNetPackVisitor::visitBlockingDialog(BlockingDialog & pack)
  582. {
  583. std::string str = pack.text.toString();
  584. if(!callOnlyThatInterface(cl, pack.player, &CGameInterface::showBlockingDialog, str, pack.components, pack.queryID, (soundBase::soundID)pack.soundID, pack.selection(), pack.cancel()))
  585. logNetwork->warn("We received YesNoDialog for not our player...");
  586. }
  587. void ApplyClientNetPackVisitor::visitGarrisonDialog(GarrisonDialog & pack)
  588. {
  589. const CGHeroInstance *h = cl.getHero(pack.hid);
  590. const CArmedInstance *obj = static_cast<const CArmedInstance*>(cl.getObj(pack.objid));
  591. callOnlyThatInterface(cl, h->getOwner(), &CGameInterface::showGarrisonDialog, obj, h, pack.removableUnits, pack.queryID);
  592. }
  593. void ApplyClientNetPackVisitor::visitExchangeDialog(ExchangeDialog & pack)
  594. {
  595. callInterfaceIfPresent(cl, pack.player, &IGameEventsReceiver::heroExchangeStarted, pack.hero1, pack.hero2, pack.queryID);
  596. }
  597. void ApplyClientNetPackVisitor::visitTeleportDialog(TeleportDialog & pack)
  598. {
  599. callOnlyThatInterface(cl, pack.player, &CGameInterface::showTeleportDialog, pack.channel, pack.exits, pack.impassable, pack.queryID);
  600. }
  601. void ApplyClientNetPackVisitor::visitMapObjectSelectDialog(MapObjectSelectDialog & pack)
  602. {
  603. callOnlyThatInterface(cl, pack.player, &CGameInterface::showMapObjectSelectDialog, pack.queryID, pack.icon, pack.title, pack.description, pack.objects);
  604. }
  605. void ApplyFirstClientNetPackVisitor::visitBattleStart(BattleStart & pack)
  606. {
  607. // Cannot use the usual code because curB is not set yet
  608. callOnlyThatBattleInterface(cl, pack.info->sides[0].color, &IBattleEventsReceiver::battleStartBefore, pack.info->sides[0].armyObject, pack.info->sides[1].armyObject,
  609. pack.info->tile, pack.info->sides[0].hero, pack.info->sides[1].hero);
  610. callOnlyThatBattleInterface(cl, pack.info->sides[1].color, &IBattleEventsReceiver::battleStartBefore, pack.info->sides[0].armyObject, pack.info->sides[1].armyObject,
  611. pack.info->tile, pack.info->sides[0].hero, pack.info->sides[1].hero);
  612. callOnlyThatBattleInterface(cl, PlayerColor::SPECTATOR, &IBattleEventsReceiver::battleStartBefore, pack.info->sides[0].armyObject, pack.info->sides[1].armyObject,
  613. pack.info->tile, pack.info->sides[0].hero, pack.info->sides[1].hero);
  614. }
  615. void ApplyClientNetPackVisitor::visitBattleStart(BattleStart & pack)
  616. {
  617. cl.battleStarted(pack.info);
  618. }
  619. void ApplyFirstClientNetPackVisitor::visitBattleNextRound(BattleNextRound & pack)
  620. {
  621. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleNewRoundFirst, pack.round);
  622. }
  623. void ApplyClientNetPackVisitor::visitBattleNextRound(BattleNextRound & pack)
  624. {
  625. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleNewRound, pack.round);
  626. }
  627. void ApplyClientNetPackVisitor::visitBattleSetActiveStack(BattleSetActiveStack & pack)
  628. {
  629. if(!pack.askPlayerInterface)
  630. return;
  631. const CStack *activated = gs.curB->battleGetStackByID(pack.stack);
  632. PlayerColor playerToCall; //pack.player that will move activated stack
  633. if (activated->hasBonusOfType(BonusType::HYPNOTIZED))
  634. {
  635. playerToCall = (gs.curB->sides[0].color == activated->unitOwner()
  636. ? gs.curB->sides[1].color
  637. : gs.curB->sides[0].color);
  638. }
  639. else
  640. {
  641. playerToCall = activated->unitOwner();
  642. }
  643. cl.startPlayerBattleAction(playerToCall);
  644. }
  645. void ApplyClientNetPackVisitor::visitBattleLogMessage(BattleLogMessage & pack)
  646. {
  647. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleLogMessage, pack.lines);
  648. }
  649. void ApplyClientNetPackVisitor::visitBattleTriggerEffect(BattleTriggerEffect & pack)
  650. {
  651. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleTriggerEffect, pack);
  652. }
  653. void ApplyFirstClientNetPackVisitor::visitBattleUpdateGateState(BattleUpdateGateState & pack)
  654. {
  655. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleGateStateChanged, pack.state);
  656. }
  657. void ApplyFirstClientNetPackVisitor::visitBattleResult(BattleResult & pack)
  658. {
  659. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleEnd, &pack, pack.queryID);
  660. cl.battleFinished();
  661. }
  662. void ApplyFirstClientNetPackVisitor::visitBattleStackMoved(BattleStackMoved & pack)
  663. {
  664. const CStack * movedStack = gs.curB->battleGetStackByID(pack.stack);
  665. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleStackMoved, movedStack, pack.tilesToMove, pack.distance, pack.teleporting);
  666. }
  667. void ApplyFirstClientNetPackVisitor::visitBattleAttack(BattleAttack & pack)
  668. {
  669. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleAttack, &pack);
  670. // battleStacksAttacked should be excuted before BattleAttack.applyGs() to play animation before damaging unit
  671. // so this has to be here instead of ApplyClientNetPackVisitor::visitBattleAttack()
  672. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleStacksAttacked, pack.bsa, pack.shot());
  673. }
  674. void ApplyClientNetPackVisitor::visitBattleAttack(BattleAttack & pack)
  675. {
  676. }
  677. void ApplyFirstClientNetPackVisitor::visitStartAction(StartAction & pack)
  678. {
  679. cl.curbaction = std::make_optional(pack.ba);
  680. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::actionStarted, pack.ba);
  681. }
  682. void ApplyClientNetPackVisitor::visitBattleSpellCast(BattleSpellCast & pack)
  683. {
  684. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleSpellCast, &pack);
  685. }
  686. void ApplyClientNetPackVisitor::visitSetStackEffect(SetStackEffect & pack)
  687. {
  688. //informing about effects
  689. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleStacksEffectsSet, pack);
  690. }
  691. void ApplyClientNetPackVisitor::visitStacksInjured(StacksInjured & pack)
  692. {
  693. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleStacksAttacked, pack.stacks, false);
  694. }
  695. void ApplyClientNetPackVisitor::visitBattleResultsApplied(BattleResultsApplied & pack)
  696. {
  697. callInterfaceIfPresent(cl, pack.player1, &IGameEventsReceiver::battleResultsApplied);
  698. callInterfaceIfPresent(cl, pack.player2, &IGameEventsReceiver::battleResultsApplied);
  699. callInterfaceIfPresent(cl, PlayerColor::SPECTATOR, &IGameEventsReceiver::battleResultsApplied);
  700. }
  701. void ApplyClientNetPackVisitor::visitBattleUnitsChanged(BattleUnitsChanged & pack)
  702. {
  703. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleUnitsChanged, pack.changedStacks);
  704. }
  705. void ApplyClientNetPackVisitor::visitBattleObstaclesChanged(BattleObstaclesChanged & pack)
  706. {
  707. //inform interfaces about removed obstacles
  708. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleObstaclesChanged, pack.changes);
  709. }
  710. void ApplyClientNetPackVisitor::visitCatapultAttack(CatapultAttack & pack)
  711. {
  712. //inform interfaces about catapult attack
  713. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleCatapultAttacked, pack);
  714. }
  715. void ApplyClientNetPackVisitor::visitEndAction(EndAction & pack)
  716. {
  717. callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::actionFinished, *cl.curbaction);
  718. cl.curbaction.reset();
  719. }
  720. void ApplyClientNetPackVisitor::visitPackageApplied(PackageApplied & pack)
  721. {
  722. callInterfaceIfPresent(cl, pack.player, &IGameEventsReceiver::requestRealized, &pack);
  723. if(!CClient::waitingRequest.tryRemovingElement(pack.requestID))
  724. logNetwork->warn("Surprising server message! PackageApplied for unknown requestID!");
  725. }
  726. void ApplyClientNetPackVisitor::visitSystemMessage(SystemMessage & pack)
  727. {
  728. std::ostringstream str;
  729. str << "System message: " << pack.text;
  730. logNetwork->error(str.str()); // usually used to receive error messages from server
  731. if(LOCPLINT && !settings["session"]["hideSystemMessages"].Bool())
  732. LOCPLINT->cingconsole->print(str.str());
  733. }
  734. void ApplyClientNetPackVisitor::visitPlayerBlocked(PlayerBlocked & pack)
  735. {
  736. callInterfaceIfPresent(cl, pack.player, &IGameEventsReceiver::playerBlocked, pack.reason, pack.startOrEnd == PlayerBlocked::BLOCKADE_STARTED);
  737. }
  738. void ApplyClientNetPackVisitor::visitYourTurn(YourTurn & pack)
  739. {
  740. logNetwork->debug("Server gives turn to %s", pack.player.getStr());
  741. callAllInterfaces(cl, &IGameEventsReceiver::playerStartsTurn, pack.player);
  742. callOnlyThatInterface(cl, pack.player, &CGameInterface::yourTurn);
  743. }
  744. void ApplyClientNetPackVisitor::visitPlayerMessageClient(PlayerMessageClient & pack)
  745. {
  746. logNetwork->debug("pack.player %s sends a message: %s", pack.player.getStr(), pack.text);
  747. std::ostringstream str;
  748. if(pack.player.isSpectator())
  749. str << "Spectator: " << pack.text;
  750. else
  751. str << cl.getPlayerState(pack.player)->nodeName() <<": " << pack.text;
  752. if(LOCPLINT)
  753. LOCPLINT->cingconsole->print(str.str());
  754. }
  755. void ApplyClientNetPackVisitor::visitAdvmapSpellCast(AdvmapSpellCast & pack)
  756. {
  757. cl.invalidatePaths();
  758. auto caster = cl.getHero(pack.casterID);
  759. if(caster)
  760. //consider notifying other interfaces that see hero?
  761. callInterfaceIfPresent(cl, caster->getOwner(), &IGameEventsReceiver::advmapSpellCast, caster, pack.spellID);
  762. else
  763. logNetwork->error("Invalid hero instance");
  764. }
  765. void ApplyClientNetPackVisitor::visitShowWorldViewEx(ShowWorldViewEx & pack)
  766. {
  767. callOnlyThatInterface(cl, pack.player, &CGameInterface::showWorldViewEx, pack.objectPositions, pack.showTerrain);
  768. }
  769. void ApplyClientNetPackVisitor::visitOpenWindow(OpenWindow & pack)
  770. {
  771. switch(pack.window)
  772. {
  773. case EOpenWindowMode::RECRUITMENT_FIRST:
  774. case EOpenWindowMode::RECRUITMENT_ALL:
  775. {
  776. const CGDwelling *dw = dynamic_cast<const CGDwelling*>(cl.getObj(ObjectInstanceID(pack.id1)));
  777. const CArmedInstance *dst = dynamic_cast<const CArmedInstance*>(cl.getObj(ObjectInstanceID(pack.id2)));
  778. callInterfaceIfPresent(cl, dst->tempOwner, &IGameEventsReceiver::showRecruitmentDialog, dw, dst, pack.window == EOpenWindowMode::RECRUITMENT_FIRST ? 0 : -1);
  779. }
  780. break;
  781. case EOpenWindowMode::SHIPYARD_WINDOW:
  782. {
  783. const IShipyard *sy = IShipyard::castFrom(cl.getObj(ObjectInstanceID(pack.id1)));
  784. callInterfaceIfPresent(cl, sy->getObject()->getOwner(), &IGameEventsReceiver::showShipyardDialog, sy);
  785. }
  786. break;
  787. case EOpenWindowMode::THIEVES_GUILD:
  788. {
  789. //displays Thieves' Guild window (when hero enters Den of Thieves)
  790. const CGObjectInstance *obj = cl.getObj(ObjectInstanceID(pack.id2));
  791. callInterfaceIfPresent(cl, PlayerColor(pack.id1), &IGameEventsReceiver::showThievesGuildWindow, obj);
  792. }
  793. break;
  794. case EOpenWindowMode::UNIVERSITY_WINDOW:
  795. {
  796. //displays University window (when hero enters University on adventure map)
  797. const IMarket *market = IMarket::castFrom(cl.getObj(ObjectInstanceID(pack.id1)));
  798. const CGHeroInstance *hero = cl.getHero(ObjectInstanceID(pack.id2));
  799. callInterfaceIfPresent(cl, hero->tempOwner, &IGameEventsReceiver::showUniversityWindow, market, hero);
  800. }
  801. break;
  802. case EOpenWindowMode::MARKET_WINDOW:
  803. {
  804. //displays Thieves' Guild window (when hero enters Den of Thieves)
  805. const CGObjectInstance *obj = cl.getObj(ObjectInstanceID(pack.id1));
  806. const CGHeroInstance *hero = cl.getHero(ObjectInstanceID(pack.id2));
  807. const IMarket *market = IMarket::castFrom(obj);
  808. callInterfaceIfPresent(cl, cl.getTile(obj->visitablePos())->visitableObjects.back()->tempOwner, &IGameEventsReceiver::showMarketWindow, market, hero);
  809. }
  810. break;
  811. case EOpenWindowMode::HILL_FORT_WINDOW:
  812. {
  813. //displays Hill fort window
  814. const CGObjectInstance *obj = cl.getObj(ObjectInstanceID(pack.id1));
  815. const CGHeroInstance *hero = cl.getHero(ObjectInstanceID(pack.id2));
  816. callInterfaceIfPresent(cl, cl.getTile(obj->visitablePos())->visitableObjects.back()->tempOwner, &IGameEventsReceiver::showHillFortWindow, obj, hero);
  817. }
  818. break;
  819. case EOpenWindowMode::PUZZLE_MAP:
  820. {
  821. callInterfaceIfPresent(cl, PlayerColor(pack.id1), &IGameEventsReceiver::showPuzzleMap);
  822. }
  823. break;
  824. case EOpenWindowMode::TAVERN_WINDOW:
  825. const CGObjectInstance *obj1 = cl.getObj(ObjectInstanceID(pack.id1)),
  826. *obj2 = cl.getObj(ObjectInstanceID(pack.id2));
  827. callInterfaceIfPresent(cl, obj1->tempOwner, &IGameEventsReceiver::showTavernWindow, obj2);
  828. break;
  829. }
  830. }
  831. void ApplyClientNetPackVisitor::visitCenterView(CenterView & pack)
  832. {
  833. callInterfaceIfPresent(cl, pack.player, &IGameEventsReceiver::centerView, pack.pos, pack.focusTime);
  834. }
  835. void ApplyClientNetPackVisitor::visitNewObject(NewObject & pack)
  836. {
  837. cl.invalidatePaths();
  838. const CGObjectInstance *obj = cl.getObj(pack.createdObjectID);
  839. if(CGI->mh)
  840. CGI->mh->onObjectFadeIn(obj);
  841. for(auto i=cl.playerint.begin(); i!=cl.playerint.end(); i++)
  842. {
  843. if(gs.isVisible(obj, i->first))
  844. i->second->newObject(obj);
  845. }
  846. CGI->mh->waitForOngoingAnimations();
  847. }
  848. void ApplyClientNetPackVisitor::visitSetAvailableArtifacts(SetAvailableArtifacts & pack)
  849. {
  850. if(pack.id < 0) //artifact merchants globally
  851. {
  852. callAllInterfaces(cl, &IGameEventsReceiver::availableArtifactsChanged, nullptr);
  853. }
  854. else
  855. {
  856. const CGBlackMarket *bm = dynamic_cast<const CGBlackMarket *>(cl.getObj(ObjectInstanceID(pack.id)));
  857. assert(bm);
  858. callInterfaceIfPresent(cl, cl.getTile(bm->visitablePos())->visitableObjects.back()->tempOwner, &IGameEventsReceiver::availableArtifactsChanged, bm);
  859. }
  860. }
  861. void ApplyClientNetPackVisitor::visitEntitiesChanged(EntitiesChanged & pack)
  862. {
  863. cl.invalidatePaths();
  864. }