1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Remove pointer to objects from TerrainTile

This commit is contained in:
Ivan Savenko
2025-03-19 14:40:45 +00:00
parent 63d00b080e
commit cd7732456a
26 changed files with 164 additions and 113 deletions

View File

@@ -103,6 +103,7 @@ PathNodeInfo::PathNodeInfo()
void PathNodeInfo::setNode(CGameState * gs, CGPathNode * n)
{
node = n;
guarded = false;
if(coord != node->coord)
{
@@ -110,23 +111,25 @@ void PathNodeInfo::setNode(CGameState * gs, CGPathNode * n)
coord = node->coord;
tile = gs->getTile(coord);
nodeObject = tile->topVisitableObj();
nodeObject = nullptr;
nodeHero = nullptr;
if(nodeObject && nodeObject->ID == Obj::HERO)
ObjectInstanceID topObjectID = tile->topVisitableObj();
if (topObjectID.hasValue())
{
nodeHero = dynamic_cast<const CGHeroInstance *>(nodeObject);
nodeObject = tile->topVisitableObj(true);
nodeObject = gs->getObjInstance(topObjectID);
if(!nodeObject)
nodeObject = nodeHero;
}
else
{
nodeHero = nullptr;
if (nodeObject->ID == Obj::HERO)
{
nodeHero = dynamic_cast<const CGHeroInstance *>(nodeObject);
ObjectInstanceID bottomObjectID = tile->topVisitableObj(true);
if (bottomObjectID.hasValue())
nodeObject = gs->getObjInstance(bottomObjectID);
}
}
}
guarded = false;
}
void PathNodeInfo::updateInfo(CPathfinderHelper * hlp, CGameState * gs)

View File

@@ -251,7 +251,8 @@ TeleporterTilesVector CPathfinderHelper::getAllowedTeleportChannelExits(const Te
auto pos = obj->getBlockedPos();
for(const auto & p : pos)
{
if(gs->getMap().getTile(p).topVisitableId() == obj->ID)
ObjectInstanceID topObject = gs->getMap().getTile(p).topVisitableObj();
if(topObject.hasValue() && getObj(topObject)->ID == obj->ID)
allowedExits.push_back(p);
}
}

View File

@@ -34,7 +34,10 @@ namespace PathfinderUtil
case ELayer::SAIL:
if(tinfo.visitable())
{
if(tinfo.visitableObjects.front()->ID == Obj::SANCTUARY && tinfo.visitableObjects.back()->ID == Obj::HERO && tinfo.visitableObjects.back()->tempOwner != player) //non-owned hero stands on Sanctuary
auto frontVisitable = gs->getObjInstance(tinfo.visitableObjects.front());
auto backVisitable = gs->getObjInstance(tinfo.visitableObjects.front());
if(frontVisitable->ID == Obj::SANCTUARY && backVisitable->ID == Obj::HERO && backVisitable->getOwner() != player) //non-owned hero stands on Sanctuary
{
return EPathAccessibility::BLOCKED;
}
@@ -43,8 +46,10 @@ namespace PathfinderUtil
bool hasBlockedVisitable = false;
bool hasVisitable = false;
for(const CGObjectInstance * obj : tinfo.visitableObjects)
for(const auto objID : tinfo.visitableObjects)
{
auto obj = gs->getObjInstance(objID);
if(obj->isBlockedVisitable())
hasBlockedVisitable = true;
else if(!obj->passableFor(player) && obj->ID != Obj::EVENT)