NetPacksClient.cpp 34 KB

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