mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-15 00:05:02 +02:00
Small optimization of NKAI pathfinder
This commit is contained in:
@ -119,18 +119,6 @@ void AINodeStorage::clear()
|
|||||||
turnDistanceLimit[HeroRole::SCOUT] = 255;
|
turnDistanceLimit[HeroRole::SCOUT] = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AIPathNode * AINodeStorage::getAINode(const CGPathNode * node) const
|
|
||||||
{
|
|
||||||
return static_cast<const AIPathNode *>(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AINodeStorage::updateAINode(CGPathNode * node, std::function<void(AIPathNode *)> updater)
|
|
||||||
{
|
|
||||||
auto aiNode = static_cast<AIPathNode *>(node);
|
|
||||||
|
|
||||||
updater(aiNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::optional<AIPathNode *> AINodeStorage::getOrCreateNode(
|
boost::optional<AIPathNode *> AINodeStorage::getOrCreateNode(
|
||||||
const int3 & pos,
|
const int3 & pos,
|
||||||
const EPathfindingLayer layer,
|
const EPathfindingLayer layer,
|
||||||
@ -823,13 +811,6 @@ ExchangeCandidate HeroChainCalculationTask::calculateExchange(
|
|||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CGHeroInstance * AINodeStorage::getHero(const CGPathNode * node) const
|
|
||||||
{
|
|
||||||
auto aiNode = getAINode(node);
|
|
||||||
|
|
||||||
return aiNode->actor->hero;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::set<const CGHeroInstance *> AINodeStorage::getAllHeroes() const
|
const std::set<const CGHeroInstance *> AINodeStorage::getAllHeroes() const
|
||||||
{
|
{
|
||||||
std::set<const CGHeroInstance *> heroes;
|
std::set<const CGHeroInstance *> heroes;
|
||||||
|
@ -196,8 +196,24 @@ public:
|
|||||||
int movementLeft,
|
int movementLeft,
|
||||||
float cost) const;
|
float cost) const;
|
||||||
|
|
||||||
const AIPathNode * getAINode(const CGPathNode * node) const;
|
inline const AIPathNode * getAINode(const CGPathNode * node) const
|
||||||
void updateAINode(CGPathNode * node, std::function<void (AIPathNode *)> updater);
|
{
|
||||||
|
return static_cast<const AIPathNode *>(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void updateAINode(CGPathNode * node, std::function<void (AIPathNode *)> updater)
|
||||||
|
{
|
||||||
|
auto aiNode = static_cast<AIPathNode *>(node);
|
||||||
|
|
||||||
|
updater(aiNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const CGHeroInstance * getHero(const CGPathNode * node) const
|
||||||
|
{
|
||||||
|
auto aiNode = getAINode(node);
|
||||||
|
|
||||||
|
return aiNode->actor->hero;
|
||||||
|
}
|
||||||
|
|
||||||
bool hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const;
|
bool hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const;
|
||||||
|
|
||||||
@ -223,18 +239,17 @@ public:
|
|||||||
void setTownsAndDwellings(
|
void setTownsAndDwellings(
|
||||||
const std::vector<const CGTownInstance *> & towns,
|
const std::vector<const CGTownInstance *> & towns,
|
||||||
const std::set<const CGObjectInstance *> & visitableObjs);
|
const std::set<const CGObjectInstance *> & visitableObjs);
|
||||||
const CGHeroInstance * getHero(const CGPathNode * node) const;
|
|
||||||
const std::set<const CGHeroInstance *> getAllHeroes() const;
|
const std::set<const CGHeroInstance *> getAllHeroes() const;
|
||||||
void clear();
|
void clear();
|
||||||
bool calculateHeroChain();
|
bool calculateHeroChain();
|
||||||
bool calculateHeroChainFinal();
|
bool calculateHeroChainFinal();
|
||||||
|
|
||||||
uint64_t evaluateDanger(const int3 & tile, const CGHeroInstance * hero, bool checkGuards) const
|
inline uint64_t evaluateDanger(const int3 & tile, const CGHeroInstance * hero, bool checkGuards) const
|
||||||
{
|
{
|
||||||
return dangerEvaluator->evaluateDanger(tile, hero, checkGuards);
|
return dangerEvaluator->evaluateDanger(tile, hero, checkGuards);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t evaluateArmyLoss(const CGHeroInstance * hero, uint64_t armyValue, uint64_t danger) const
|
inline uint64_t evaluateArmyLoss(const CGHeroInstance * hero, uint64_t armyValue, uint64_t danger) const
|
||||||
{
|
{
|
||||||
double ratio = (double)danger / (armyValue * hero->getFightingStrength());
|
double ratio = (double)danger / (armyValue * hero->getFightingStrength());
|
||||||
|
|
||||||
@ -243,6 +258,7 @@ public:
|
|||||||
|
|
||||||
STRONG_INLINE
|
STRONG_INLINE
|
||||||
void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility);
|
void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility);
|
||||||
|
|
||||||
STRONG_INLINE int getBucket(const ChainActor * actor) const
|
STRONG_INLINE int getBucket(const ChainActor * actor) const
|
||||||
{
|
{
|
||||||
return ((uintptr_t)actor * 395) % AIPathfinding::BUCKET_COUNT;
|
return ((uintptr_t)actor * 395) % AIPathfinding::BUCKET_COUNT;
|
||||||
|
Reference in New Issue
Block a user