From 9ab7650746f6f590e7d825e1c27846b41ddfb6ab Mon Sep 17 00:00:00 2001 From: Arseniy Shestakov Date: Sun, 11 Sep 2016 13:56:00 +0300 Subject: [PATCH] SetHeroesInTown: properly update all client interfaces in multiplayer All interfaces that hero or town visible for must be updated when hero position in town changes. Fix issue 2089 --- client/CPlayerInterface.cpp | 8 ++++---- client/NetPacksClient.cpp | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index a5e6f5534..e5fae6d36 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -529,17 +529,17 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town) EVENT_HANDLER_CALLED_BY_CLIENT; updateInfo(town); - if(town->garrisonHero && vstd::contains(wanderingHeroes,town->garrisonHero)) //wandering hero moved to the garrison + if(town->garrisonHero) //wandering hero moved to the garrison { CGI->mh->hideObject(town->garrisonHero); - if (town->garrisonHero->tempOwner == playerID) // our hero + if(town->garrisonHero->tempOwner == playerID && vstd::contains(wanderingHeroes,town->garrisonHero)) // our hero wanderingHeroes -= town->garrisonHero; } - if(town->visitingHero && !vstd::contains(wanderingHeroes,town->visitingHero)) //hero leaves garrison + if(town->visitingHero) //hero leaves garrison { CGI->mh->printObject(town->visitingHero); - if (town->visitingHero->tempOwner == playerID) // our hero + if(town->visitingHero->tempOwner == playerID && !vstd::contains(wanderingHeroes,town->visitingHero)) // our hero wanderingHeroes.push_back(town->visitingHero); } adventureInt->heroList.update(); diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index 4a4bbd67a..a51f7e1ad 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -451,19 +451,19 @@ void SetHeroesInTown::applyCl( CClient *cl ) CGHeroInstance *hGarr = GS(cl)->getHero(this->garrison); CGHeroInstance *hVisit = GS(cl)->getHero(this->visiting); - std::set playersToNotify; + //inform all players that see this object + for(auto i = cl->playerint.cbegin(); i != cl->playerint.cend(); ++i) + { + if(i->first >= PlayerColor::PLAYER_LIMIT) + continue; - if(vstd::contains(cl->playerint,t->tempOwner)) // our town - playersToNotify.insert(t->tempOwner); - - if (hGarr && vstd::contains(cl->playerint, hGarr->tempOwner)) - playersToNotify.insert(hGarr->tempOwner); - - if (hVisit && vstd::contains(cl->playerint, hVisit->tempOwner)) - playersToNotify.insert(hVisit->tempOwner); - - for(auto playerID : playersToNotify) - cl->playerint[playerID]->heroInGarrisonChange(t); + if(GS(cl)->isVisible(t, i->first) || + (hGarr && GS(cl)->isVisible(hGarr, i->first)) || + (hVisit && GS(cl)->isVisible(hVisit, i->first))) + { + cl->playerint[i->first]->heroInGarrisonChange(t); + } + } } // void SetHeroArtifacts::applyCl( CClient *cl )