1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/AI/Nullkiller/Pathfinding/Rules/AIMovementToDestinationRule.cpp

73 lines
1.7 KiB
C++
Raw Normal View History

2021-05-15 18:22:44 +02:00
/*
* AIMovementToDestinationRule.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "AIMovementToDestinationRule.h"
2022-09-26 20:01:07 +02:00
namespace NKAI
{
2021-05-15 18:22:44 +02:00
namespace AIPathfinding
{
2024-02-03 12:20:59 +02:00
AIMovementToDestinationRule::AIMovementToDestinationRule(
std::shared_ptr<AINodeStorage> nodeStorage,
bool allowBypassObjects)
: nodeStorage(nodeStorage), allowBypassObjects(allowBypassObjects)
2021-05-15 18:22:44 +02:00
{
}
void AIMovementToDestinationRule::process(
const PathNodeInfo & source,
CDestinationNodeInfo & destination,
const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const
{
auto blocker = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper);
if(blocker == BlockingReason::NONE)
return;
if(blocker == BlockingReason::DESTINATION_BLOCKED
&& destination.action == EPathNodeAction::EMBARK
2021-05-15 18:22:44 +02:00
&& nodeStorage->getAINode(destination.node)->specialAction)
{
return;
}
2024-02-03 12:20:59 +02:00
if(blocker == BlockingReason::SOURCE_GUARDED)
2021-05-15 18:22:44 +02:00
{
2024-02-03 12:20:59 +02:00
auto actor = nodeStorage->getAINode(source.node)->actor;
if(!allowBypassObjects)
{
2024-03-09 16:20:00 +02:00
if (source.node->getCost() < 0.0001f)
2024-02-03 12:20:59 +02:00
return;
// when actor represents moster graph node, we need to let him escape monster
if(cb->getGuardingCreaturePosition(source.coord) == actor->initialPosition)
2024-02-03 12:20:59 +02:00
return;
}
if(actor->allowBattle)
{
2022-09-26 20:01:07 +02:00
#if NKAI_PATHFINDER_TRACE_LEVEL >= 1
2024-02-03 12:20:59 +02:00
logAi->trace(
"Bypass src guard while moving from %s to %s",
source.coord.toString(),
destination.coord.toString());
2021-05-15 18:22:44 +02:00
#endif
2024-02-03 12:20:59 +02:00
return;
}
2021-05-15 18:22:44 +02:00
}
destination.blocked = true;
}
}
2022-09-26 20:01:07 +02:00
}