From 908e6892f34c1ac772b17e1cd65c2bc907decb93 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 7 Dec 2022 22:10:08 +0200 Subject: [PATCH] Removed CGHeroInstance::getPosition pseudo-override Now access to hero visible position is always done via visitablePos --- AI/VCAI/Pathfinding/AINodeStorage.cpp | 4 ++-- client/CPlayerInterface.cpp | 4 ++-- client/widgets/AdventureMapClasses.cpp | 2 +- client/windows/CAdvmapInterface.cpp | 2 +- lib/CGameInfoCallback.cpp | 4 ++-- lib/CPathfinder.cpp | 2 +- lib/mapObjects/CGHeroInstance.cpp | 16 ++-------------- lib/mapObjects/CGHeroInstance.h | 3 --- lib/mapObjects/MiscObjects.cpp | 2 +- server/CGameHandler.cpp | 2 +- 10 files changed, 13 insertions(+), 28 deletions(-) diff --git a/AI/VCAI/Pathfinding/AINodeStorage.cpp b/AI/VCAI/Pathfinding/AINodeStorage.cpp index 0b1b3fc70..77f516bf5 100644 --- a/AI/VCAI/Pathfinding/AINodeStorage.cpp +++ b/AI/VCAI/Pathfinding/AINodeStorage.cpp @@ -107,7 +107,7 @@ boost::optional AINodeStorage::getOrCreateNode(const int3 & pos, c std::vector AINodeStorage::getInitialNodes() { - auto hpos = hero->getPosition(false); + auto hpos = hero->visitablePos(); auto initialNode = getOrCreateNode(hpos, hero->boat ? EPathfindingLayer::SAIL : EPathfindingLayer::LAND, NORMAL_CHAIN) .get(); @@ -211,7 +211,7 @@ std::vector AINodeStorage::calculateTeleportations( } } - if(hero->getPosition(false) == source.coord) + if(hero->visitablePos() == source.coord) { calculateTownPortalTeleportations(source, neighbours); } diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index adf8e61f7..bbc9e1a72 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -2008,7 +2008,7 @@ CGPath * CPlayerInterface::getAndVerifyPath(const CGHeroInstance * h) } else { - assert(h->getPosition(false) == path.startPos()); + assert(h->visitablePos() == path.startPos()); //update the hero path in case of something has changed on map if (LOCPLINT->cb->getPathsInfo(h)->getPath(path, path.endPos())) return &path; @@ -2112,7 +2112,7 @@ void CPlayerInterface::acceptTurn() void CPlayerInterface::tryDiggging(const CGHeroInstance * h) { int msgToShow = -1; - const bool isBlocked = CGI->mh->hasObjectHole(h->getPosition(false)); // Don't dig in the pit. + const bool isBlocked = CGI->mh->hasObjectHole(h->visitablePos()); // Don't dig in the pit. const auto diggingStatus = isBlocked ? EDiggingStatus::TILE_OCCUPIED diff --git a/client/widgets/AdventureMapClasses.cpp b/client/widgets/AdventureMapClasses.cpp index ae16aabce..4164e049c 100644 --- a/client/widgets/AdventureMapClasses.cpp +++ b/client/widgets/AdventureMapClasses.cpp @@ -486,7 +486,7 @@ void CMinimapInstance::showAll(SDL_Surface * to) std::vector heroes = LOCPLINT->cb->getHeroesInfo(false); //TODO: do we really need separate function for drawing heroes? for(auto & hero : heroes) { - int3 position = hero->getPosition(false); + int3 position = hero->visitablePos(); if(position.z == level) { const SDL_Color & color = graphics->playerColors[hero->getOwner().getNum()]; diff --git a/client/windows/CAdvmapInterface.cpp b/client/windows/CAdvmapInterface.cpp index 7706af146..a7846f4e9 100644 --- a/client/windows/CAdvmapInterface.cpp +++ b/client/windows/CAdvmapInterface.cpp @@ -1363,7 +1363,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key) CGPath &path = LOCPLINT->paths[h]; terrain.currentPath = &path; - int3 dst = h->getPosition(false) + dir; + int3 dst = h->visitablePos() + dir; if(dst != verifyPos(dst) || !LOCPLINT->cb->getPathsInfo(h)->getPath(path, dst)) { terrain.currentPath = nullptr; diff --git a/lib/CGameInfoCallback.cpp b/lib/CGameInfoCallback.cpp index e037e8926..aa5121da1 100644 --- a/lib/CGameInfoCallback.cpp +++ b/lib/CGameInfoCallback.cpp @@ -294,7 +294,7 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero if(gs->curB && gs->curB->playerHasAccessToHeroInfo(*player, h)) //if it's battle we can get enemy hero full data infoLevel = InfoAboutHero::EInfoLevel::INBATTLE; else - ERROR_RET_VAL_IF(!isVisible(h->getPosition(false)), "That hero is not visible!", false); + ERROR_RET_VAL_IF(!isVisible(h->visitablePos()), "That hero is not visible!", false); } if( (infoLevel == InfoAboutHero::EInfoLevel::BASIC) && nullptr != selectedObject) @@ -734,7 +734,7 @@ std::vector < const CGHeroInstance *> CPlayerSpecificInfoCallback::getHeroesInfo { // !player || // - why would we even get access to hero not owned by any player? if((hero->tempOwner == *player) || - (isVisible(hero->getPosition(false), player) && !onlyOur) ) + (isVisible(hero->visitablePos(), player) && !onlyOur) ) { ret.push_back(hero); } diff --git a/lib/CPathfinder.cpp b/lib/CPathfinder.cpp index d1abb1d74..44a31e971 100644 --- a/lib/CPathfinder.cpp +++ b/lib/CPathfinder.cpp @@ -141,7 +141,7 @@ NodeStorage::NodeStorage(CPathsInfo & pathsInfo, const CGHeroInstance * hero) :out(pathsInfo) { out.hero = hero; - out.hpos = hero->getPosition(false); + out.hpos = hero->visitablePos(); } void NodeStorage::resetTile( diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index 4dcaf28d0..62945c9dc 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -141,18 +141,6 @@ BattleField CGHeroInstance::getBattlefield() const return BattleField::NONE; } -int3 CGHeroInstance::getPosition(bool h3m) const //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation' -{ - if (h3m) - { - return pos; - } - else - { - return convertPosition(pos,false); - } -} - ui8 CGHeroInstance::getSecSkillLevel(SecondarySkill skill) const { for(auto & elem : secSkills) @@ -1121,7 +1109,7 @@ EDiggingStatus CGHeroInstance::diggingStatus() const if((int)movement < maxMovePoints(true)) return EDiggingStatus::LACK_OF_MOVEMENT; - return cb->getTile(getPosition(false))->getDiggingStatus(); + return cb->getTile(visitablePos())->getDiggingStatus(); } ArtBearer::ArtBearer CGHeroInstance::bearerType() const @@ -1375,7 +1363,7 @@ bool CGHeroInstance::hasVisions(const CGObjectInstance * target, const int subty if (visionsMultiplier > 0) vstd::amax(visionsRange, 3); //minimum range is 3 tiles, but only if VISIONS bonus present - const int distance = static_cast(target->pos.dist2d(getPosition(false))); + const int distance = static_cast(target->pos.dist2d(visitablePos())); //logGlobal->debug(boost::to_string(boost::format("Visions: dist %d, mult %d, range %d") % distance % visionsMultiplier % visionsRange)); diff --git a/lib/mapObjects/CGHeroInstance.h b/lib/mapObjects/CGHeroInstance.h index dddf35c77..34af804a8 100644 --- a/lib/mapObjects/CGHeroInstance.h +++ b/lib/mapObjects/CGHeroInstance.h @@ -46,8 +46,6 @@ class DLL_LINKAGE CGHeroInstance : public CArmedInstance, public IBoatGenerator, friend class CCampaignState; friend class CMapLoaderH3M; - using CArmedInstance::getPosition; //FIXME: recheck: overloaded-virtual - private: std::set spells; //known spells (spell IDs) @@ -161,7 +159,6 @@ public: ui32 getTileCost(const TerrainTile &dest, const TerrainTile &from, const TurnInfo * ti) const; //move cost - applying pathfinding skill, road and terrain modifiers. NOT includes diagonal move penalty, last move levelling TerrainId getNativeTerrain() const; ui32 getLowestCreatureSpeed() const; - int3 getPosition(bool h3m = false) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation' si32 manaRegain() const; //how many points of mana can hero regain "naturally" in one day si32 getManaNewTurn() const; //calculate how much mana this hero is going to have the next day int getCurrentLuck(int stack=-1, bool town=false) const; diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index 3e635cb0d..5f3f03a13 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -1920,7 +1920,7 @@ void CGMagi::onHeroVisit(const CGHeroInstance * h) const cb->sendAndApply(&cv); } - cv.pos = h->getPosition(false); + cv.pos = h->visitablePos(); cv.focusTime = 0; cb->sendAndApply(&cv); } diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 58f9b49d3..654043873 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1931,7 +1931,7 @@ void CGameHandler::newTurn() hth.id = h->id; auto ti = make_unique(h, 1); // TODO: this code executed when bonuses of previous day not yet updated (this happen in NewTurn::applyGs). See issue 2356 - hth.move = h->maxMovePointsCached(gs->map->getTile(h->getPosition(false)).terType->isLand(), ti.get()); + hth.move = h->maxMovePointsCached(gs->map->getTile(h->visitablePos()).terType->isLand(), ti.get()); hth.mana = h->getManaNewTurn(); n.heroes.insert(hth);