1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Pathfinding: move isLayerAvailable into TurnInfo

This commit is contained in:
ArseniyShestakov 2015-11-12 14:39:22 +03:00
parent abc4ea272f
commit d2baa5b0d0
2 changed files with 31 additions and 26 deletions

View File

@ -130,7 +130,7 @@ void CPathfinder::calculatePaths()
if(!passOneTurnLimitCheck(cp->turns != turn))
continue;
if(!isLayerAvailable(i, turn))
if(!hlp->isLayerAvailable(i))
continue;
if(cp->layer != i && !isLayerTransitionPossible())
@ -280,26 +280,6 @@ void CPathfinder::addTeleportExits(bool noTeleportExcludes)
}
}
bool CPathfinder::isLayerAvailable(const ELayer layer, const int turn) const
{
switch(layer)
{
case ELayer::AIR:
if(!hlp->hasBonusOfType(Bonus::FLYING_MOVEMENT))
return false;
break;
case ELayer::WATER:
if(!hlp->hasBonusOfType(Bonus::WATER_WALKING))
return false;
break;
}
return true;
}
bool CPathfinder::isLayerTransitionPossible() const
{
/// No layer transition allowed when previous node action is BATTLE
@ -707,6 +687,26 @@ TurnInfo::TurnInfo(const CGHeroInstance * Hero, const int turn)
bonuses = hero->getAllBonuses(Selector::days(turn), nullptr);
}
bool TurnInfo::isLayerAvailable(const EPathfindingLayer layer) const
{
switch(layer)
{
case EPathfindingLayer::AIR:
if(!hasBonusOfType(Bonus::FLYING_MOVEMENT))
return false;
break;
case EPathfindingLayer::WATER:
if(!hasBonusOfType(Bonus::WATER_WALKING))
return false;
break;
}
return true;
}
bool TurnInfo::hasBonusOfType(Bonus::BonusType type, int subtype) const
{
return bonuses->getFirst(Selector::type(type).And(Selector::subtype(subtype)));
@ -728,7 +728,7 @@ int TurnInfo::getMaxMovePoints(const EPathfindingLayer layer) const
}
CPathfinderHelper::CPathfinderHelper(const CGHeroInstance * Hero)
: turn(0), hero(Hero)
: turn(-1), hero(Hero)
{
turnsInfo.reserve(16);
updateTurnInfo();
@ -747,6 +747,11 @@ void CPathfinderHelper::updateTurnInfo(const int Turn)
}
}
bool CPathfinderHelper::isLayerAvailable(const EPathfindingLayer layer) const
{
return turnsInfo[turn]->isLayerAvailable(layer);
}
const TurnInfo * CPathfinderHelper::getTurnInfo() const
{
return turnsInfo[turn];

View File

@ -166,7 +166,6 @@ private:
void addNeighbours(const int3 & coord);
void addTeleportExits(bool noTeleportExcludes = false);
bool isLayerAvailable(const ELayer layer, const int turn) const;
bool isLayerTransitionPossible() const;
bool isMovementToDestPossible() const;
bool isMovementAfterDestPossible() const;
@ -200,6 +199,7 @@ struct DLL_LINKAGE TurnInfo
mutable int maxMovePointsWater;
TurnInfo(const CGHeroInstance * Hero, const int Turn = 0);
bool isLayerAvailable(const EPathfindingLayer layer) const;
bool hasBonusOfType(const Bonus::BonusType type, const int subtype = -1) const;
int valOfBonuses(const Bonus::BonusType type, const int subtype = -1) const;
int getMaxMovePoints(const EPathfindingLayer layer) const;
@ -208,11 +208,9 @@ struct DLL_LINKAGE TurnInfo
class DLL_LINKAGE CPathfinderHelper
{
public:
int turn;
const CGHeroInstance * hero;
CPathfinderHelper(const CGHeroInstance * Hero);
void updateTurnInfo(const int turn = 0);
bool isLayerAvailable(const EPathfindingLayer layer) const;
const TurnInfo * getTurnInfo() const;
bool hasBonusOfType(const Bonus::BonusType type, const int subtype = -1) const;
int getMaxMovePoints(const EPathfindingLayer layer) const;
@ -223,5 +221,7 @@ public:
static int getMovementCost(const CGHeroInstance * h, const int3 & dst);
private:
int turn;
const CGHeroInstance * hero;
std::vector<TurnInfo *> turnsInfo;
};