1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

TerrainTile: implement exclusion for topVisitable functions

For pathfinder we usually want to check what object hero staying on.
Hero is always top object so we need option to exclude it.
This commit is contained in:
ArseniyShestakov 2015-03-08 15:05:24 +03:00
parent e4f591ba84
commit f145c82031
2 changed files with 10 additions and 6 deletions

View File

@ -125,14 +125,18 @@ bool TerrainTile::isClear(const TerrainTile *from /*= nullptr*/) const
return entrableTerrain(from) && !blocked;
}
int TerrainTile::topVisitableId() const
Obj TerrainTile::topVisitableId(bool excludeTop) const
{
return visitableObjects.size() ? visitableObjects.back()->ID : -1;
return topVisitableObj(excludeTop) ? topVisitableObj(excludeTop)->ID : Obj(Obj::NO_OBJ);
}
CGObjectInstance * TerrainTile::topVisitableObj() const
CGObjectInstance * TerrainTile::topVisitableObj(bool excludeTop) const
{
return visitableObjects.size() ? visitableObjects.back() : nullptr;
auto visitableObj = visitableObjects;
if(excludeTop && visitableObj.size())
visitableObj.pop_back();
return visitableObj.size() ? visitableObj.back() : nullptr;
}
bool TerrainTile::isCoastal() const

View File

@ -289,8 +289,8 @@ struct DLL_LINKAGE TerrainTile
/// Checks for blocking objects and terraint type (water / land).
bool isClear(const TerrainTile * from = nullptr) const;
/// Gets the ID of the top visitable object or -1 if there is none.
int topVisitableId() const;
CGObjectInstance * topVisitableObj() const;
Obj topVisitableId(bool excludeTop = false) const;
CGObjectInstance * topVisitableObj(bool excludeTop = false) const;
bool isWater() const;
bool isCoastal() const;
bool hasFavourableWinds() const;