mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
Pathfinder now uses IGameInfoCallback instead of CGameState
This commit is contained in:
@@ -29,11 +29,11 @@ AINodeStorage::AINodeStorage(const int3 & Sizes)
|
||||
|
||||
AINodeStorage::~AINodeStorage() = default;
|
||||
|
||||
void AINodeStorage::initialize(const PathfinderOptions & options, const CGameState * gs)
|
||||
void AINodeStorage::initialize(const PathfinderOptions & options, const IGameInfoCallback & gameInfo)
|
||||
{
|
||||
int3 pos;
|
||||
const int3 sizes = gs->getMapSize();
|
||||
const auto & fow = static_cast<const IGameInfoCallback *>(gs)->getPlayerTeam(hero->tempOwner)->fogOfWarMap;
|
||||
const int3 sizes = gameInfo.getMapSize();
|
||||
const auto & fow = gameInfo.getPlayerTeam(hero->tempOwner)->fogOfWarMap;
|
||||
const PlayerColor player = hero->tempOwner;
|
||||
|
||||
//make 200% sure that these are loop invariants (also a bit shorter code), let compiler do the rest(loop unswitching)
|
||||
@@ -46,23 +46,23 @@ void AINodeStorage::initialize(const PathfinderOptions & options, const CGameSta
|
||||
{
|
||||
for(pos.y=0; pos.y < sizes.y; ++pos.y)
|
||||
{
|
||||
const TerrainTile & tile = gs->getMap().getTile(pos);
|
||||
if(!tile.getTerrain()->isPassable())
|
||||
const TerrainTile * tile = gameInfo.getTile(pos);
|
||||
if(!tile->getTerrain()->isPassable())
|
||||
continue;
|
||||
|
||||
if(tile.getTerrain()->isWater())
|
||||
if(tile->getTerrain()->isWater())
|
||||
{
|
||||
resetTile(pos, ELayer::SAIL, PathfinderUtil::evaluateAccessibility<ELayer::SAIL>(pos, tile, fow, player, gs));
|
||||
resetTile(pos, ELayer::SAIL, PathfinderUtil::evaluateAccessibility<ELayer::SAIL>(pos, *tile, fow, player, gameInfo));
|
||||
if(useFlying)
|
||||
resetTile(pos, ELayer::AIR, PathfinderUtil::evaluateAccessibility<ELayer::AIR>(pos, tile, fow, player, gs));
|
||||
resetTile(pos, ELayer::AIR, PathfinderUtil::evaluateAccessibility<ELayer::AIR>(pos, *tile, fow, player, gameInfo));
|
||||
if(useWaterWalking)
|
||||
resetTile(pos, ELayer::WATER, PathfinderUtil::evaluateAccessibility<ELayer::WATER>(pos, tile, fow, player, gs));
|
||||
resetTile(pos, ELayer::WATER, PathfinderUtil::evaluateAccessibility<ELayer::WATER>(pos, *tile, fow, player, gameInfo));
|
||||
}
|
||||
else
|
||||
{
|
||||
resetTile(pos, ELayer::LAND, PathfinderUtil::evaluateAccessibility<ELayer::LAND>(pos, tile, fow, player, gs));
|
||||
resetTile(pos, ELayer::LAND, PathfinderUtil::evaluateAccessibility<ELayer::LAND>(pos, *tile, fow, player, gameInfo));
|
||||
if(useFlying)
|
||||
resetTile(pos, ELayer::AIR, PathfinderUtil::evaluateAccessibility<ELayer::AIR>(pos, tile, fow, player, gs));
|
||||
resetTile(pos, ELayer::AIR, PathfinderUtil::evaluateAccessibility<ELayer::AIR>(pos, *tile, fow, player, gameInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
AINodeStorage(const int3 & sizes);
|
||||
~AINodeStorage();
|
||||
|
||||
void initialize(const PathfinderOptions & options, const CGameState * gs) override;
|
||||
void initialize(const PathfinderOptions & options, const IGameInfoCallback & gameInfo) override;
|
||||
|
||||
std::vector<CGPathNode *> getInitialNodes() override;
|
||||
|
||||
|
||||
@@ -51,11 +51,11 @@ namespace AIPathfinding
|
||||
|
||||
AIPathfinderConfig::~AIPathfinderConfig() = default;
|
||||
|
||||
CPathfinderHelper * AIPathfinderConfig::getOrCreatePathfinderHelper(const PathNodeInfo & source, const CGameState & gs)
|
||||
CPathfinderHelper * AIPathfinderConfig::getOrCreatePathfinderHelper(const PathNodeInfo & source, const IGameInfoCallback & gameInfo)
|
||||
{
|
||||
if(!helper)
|
||||
{
|
||||
helper.reset(new CPathfinderHelper(gs, hero, options));
|
||||
helper.reset(new CPathfinderHelper(gameInfo, hero, options));
|
||||
}
|
||||
|
||||
return helper.get();
|
||||
|
||||
@@ -30,6 +30,6 @@ namespace AIPathfinding
|
||||
|
||||
~AIPathfinderConfig();
|
||||
|
||||
CPathfinderHelper * getOrCreatePathfinderHelper(const PathNodeInfo & source, const CGameState & gs) override;
|
||||
CPathfinderHelper * getOrCreatePathfinderHelper(const PathNodeInfo & source, const IGameInfoCallback & gameInfo) override;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user