浏览代码

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
Arseniy Shestakov 9 年之前
父节点
当前提交
9ab7650746
共有 2 个文件被更改,包括 16 次插入16 次删除
  1. 4 4
      client/CPlayerInterface.cpp
  2. 12 12
      client/NetPacksClient.cpp

+ 4 - 4
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();

+ 12 - 12
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<PlayerColor> playersToNotify;
-
-	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);
+	//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;
 
-	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 )