From 67132b3e7f00414185097af01dd7d758c8c7e3e1 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 12 Aug 2024 13:06:32 +0000 Subject: [PATCH] Fixed visitation of configurable town buildings by newly recruited heroes and on building construction --- lib/mapObjects/CGTownBuilding.cpp | 2 +- lib/mapObjects/CGTownInstance.cpp | 7 ++----- server/CGameHandler.cpp | 17 ++++++++++------- server/processors/HeroPoolProcessor.cpp | 5 +---- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/mapObjects/CGTownBuilding.cpp b/lib/mapObjects/CGTownBuilding.cpp index 3d84843ea..43b7c1ee1 100644 --- a/lib/mapObjects/CGTownBuilding.cpp +++ b/lib/mapObjects/CGTownBuilding.cpp @@ -476,7 +476,7 @@ void CTownRewardableBuilding::onHeroVisit(const CGHeroInstance *h) const cb->showBlockingDialog(&sd); }; - if(!town->hasBuilt(bID) || cb->isVisitCoveredByAnotherQuery(town, h)) + if(!town->hasBuilt(bID)) return; if(!wasVisitedBefore(h)) diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index f82849523..0c052526f 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -322,8 +322,9 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const cb->heroVisitCastle(this, h); } } - else if(h->visitablePos() == visitablePos()) + else { + assert(h->visitablePos() == this->visitablePos()); bool commander_recover = h->commander && !h->commander->alive; if (commander_recover) // rise commander from dead { @@ -344,10 +345,6 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const cb->showInfoDialog(&iw); } } - else - { - logGlobal->error("%s visits allied town of %s from different pos?", h->getNameTranslated(), getNameTranslated()); - } } void CGTownInstance::onHeroLeave(const CGHeroInstance * h) const diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 0a8ad5fea..bade6ec9e 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1518,11 +1518,14 @@ void CGameHandler::takeCreatures(ObjectInstanceID objid, const std::vectorid; - vc.tid = obj->id; - vc.flags |= 1; - sendAndApply(&vc); + if (obj->visitingHero != hero && obj->garrisonHero != hero) + { + HeroVisitCastle vc; + vc.hid = hero->id; + vc.tid = obj->id; + vc.flags |= 1; + sendAndApply(&vc); + } visitCastleObjects(obj, hero); giveSpells (obj, hero); @@ -2487,9 +2490,9 @@ bool CGameHandler::buildStructure(ObjectInstanceID tid, BuildingID requestedID, changeFogOfWar(t->getSightCenter(), t->getSightRadius(), t->getOwner(), ETileVisibility::REVEALED); if(t->garrisonHero) //garrison hero first - consistent with original H3 Mana Vortex and Battle Scholar Academy levelup windows order - visitCastleObjects(t, t->garrisonHero); + objectVisited(t, t->garrisonHero); if(t->visitingHero) - visitCastleObjects(t, t->visitingHero); + objectVisited(t, t->visitingHero); checkVictoryLossConditionsForPlayer(t->tempOwner); return true; diff --git a/server/processors/HeroPoolProcessor.cpp b/server/processors/HeroPoolProcessor.cpp index 7e8d327ba..c6e328d27 100644 --- a/server/processors/HeroPoolProcessor.cpp +++ b/server/processors/HeroPoolProcessor.cpp @@ -242,10 +242,7 @@ bool HeroPoolProcessor::hireHero(const ObjectInstanceID & objectID, const HeroTy gameHandler->giveResource(player, EGameResID::GOLD, -GameConstants::HERO_GOLD_COST); if(town) - { - gameHandler->visitCastleObjects(town, recruitedHero); - gameHandler->giveSpells(town, recruitedHero); - } + gameHandler->objectVisited(town, recruitedHero); // If new hero has scouting he might reveal more terrain than we saw before gameHandler->changeFogOfWar(recruitedHero->getSightCenter(), recruitedHero->getSightRadius(), player, ETileVisibility::REVEALED);