mirror of
https://github.com/vcmi/vcmi.git
synced 2025-09-16 09:26:28 +02:00
Pathfinding: pass PathfinderOptions to helper and avoid changing them
Original idea behind options is that options should only be set on pathfinder object creation (or via some special method in case pathfinder become persistent).
This commit is contained in:
@@ -20,13 +20,13 @@
|
||||
|
||||
CPathfinder::PathfinderOptions::PathfinderOptions()
|
||||
{
|
||||
useFlying = false;
|
||||
useWaterWalking = false;
|
||||
useFlying = true;
|
||||
useWaterWalking = true;
|
||||
useEmbarkAndDisembark = true;
|
||||
useTeleportTwoWay = true;
|
||||
useTeleportOneWay = true;
|
||||
useTeleportOneWayRandom = false;
|
||||
useTeleportWhirlpool = false;
|
||||
useTeleportWhirlpool = true;
|
||||
|
||||
useCastleGate = false;
|
||||
|
||||
@@ -49,13 +49,7 @@ CPathfinder::CPathfinder(CPathsInfo & _out, CGameState * _gs, const CGHeroInstan
|
||||
throw std::runtime_error("Wrong checksum");
|
||||
}
|
||||
|
||||
hlp = make_unique<CPathfinderHelper>(hero);
|
||||
if(hlp->hasBonusOfType(Bonus::FLYING_MOVEMENT))
|
||||
options.useFlying = true;
|
||||
if(hlp->hasBonusOfType(Bonus::WATER_WALKING))
|
||||
options.useWaterWalking = true;
|
||||
if(hlp->hasBonusOfType(Bonus::WHIRLPOOL_PROTECTION))
|
||||
options.useTeleportWhirlpool = true;
|
||||
hlp = make_unique<CPathfinderHelper>(hero, options);
|
||||
|
||||
initializeGraph();
|
||||
neighbours.reserve(16);
|
||||
@@ -719,8 +713,8 @@ int TurnInfo::getMaxMovePoints(const EPathfindingLayer layer) const
|
||||
return layer == EPathfindingLayer::SAIL ? maxMovePointsWater : maxMovePointsLand;
|
||||
}
|
||||
|
||||
CPathfinderHelper::CPathfinderHelper(const CGHeroInstance * Hero)
|
||||
: turn(-1), hero(Hero)
|
||||
CPathfinderHelper::CPathfinderHelper(const CGHeroInstance * Hero, const CPathfinder::PathfinderOptions & Options)
|
||||
: turn(-1), hero(Hero), options(Options)
|
||||
{
|
||||
turnsInfo.reserve(16);
|
||||
updateTurnInfo();
|
||||
@@ -741,6 +735,21 @@ void CPathfinderHelper::updateTurnInfo(const int Turn)
|
||||
|
||||
bool CPathfinderHelper::isLayerAvailable(const EPathfindingLayer layer) const
|
||||
{
|
||||
switch(layer)
|
||||
{
|
||||
case EPathfindingLayer::AIR:
|
||||
if(!options.useFlying)
|
||||
return false;
|
||||
|
||||
break;
|
||||
|
||||
case EPathfindingLayer::WATER:
|
||||
if(!options.useWaterWalking)
|
||||
return false;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return turnsInfo[turn]->isLayerAvailable(layer);
|
||||
}
|
||||
|
||||
|
@@ -94,6 +94,8 @@ struct DLL_LINKAGE CPathsInfo
|
||||
class CPathfinder : private CGameInfoCallback
|
||||
{
|
||||
public:
|
||||
friend class CPathfinderHelper;
|
||||
|
||||
CPathfinder(CPathsInfo & _out, CGameState * _gs, const CGHeroInstance * _hero);
|
||||
void calculatePaths(); //calculates possible paths for hero, uses current hero position and movement left; returns pointer to newly allocated CPath or nullptr if path does not exists
|
||||
|
||||
@@ -206,7 +208,7 @@ struct DLL_LINKAGE TurnInfo
|
||||
class DLL_LINKAGE CPathfinderHelper
|
||||
{
|
||||
public:
|
||||
CPathfinderHelper(const CGHeroInstance * Hero);
|
||||
CPathfinderHelper(const CGHeroInstance * Hero, const CPathfinder::PathfinderOptions & Options);
|
||||
void updateTurnInfo(const int turn = 0);
|
||||
bool isLayerAvailable(const EPathfindingLayer layer) const;
|
||||
const TurnInfo * getTurnInfo() const;
|
||||
@@ -222,4 +224,5 @@ private:
|
||||
int turn;
|
||||
const CGHeroInstance * hero;
|
||||
std::vector<TurnInfo *> turnsInfo;
|
||||
const CPathfinder::PathfinderOptions & options;
|
||||
};
|
||||
|
Reference in New Issue
Block a user