1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/*
* 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"
namespace NKAI
{
namespace AIPathfinding
{
AIMovementToDestinationRule::AIMovementToDestinationRule(
std::shared_ptr<AINodeStorage> nodeStorage,
bool allowBypassObjects)
: nodeStorage(nodeStorage), allowBypassObjects(allowBypassObjects)
{
}
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
&& nodeStorage->getAINode(destination.node)->specialAction)
{
return;
}
if(blocker == BlockingReason::SOURCE_GUARDED)
{
auto actor = nodeStorage->getAINode(source.node)->actor;
if(!allowBypassObjects)
{
if (source.node->getCost() < 0.0001f)
return;
// when actor represents moster graph node, we need to let him escape monster
if(cb->getGuardingCreaturePosition(source.coord) == actor->initialPosition)
return;
}
if(actor->allowBattle)
{
#if NKAI_PATHFINDER_TRACE_LEVEL >= 1
logAi->trace(
"Bypass src guard while moving from %s to %s",
source.coord.toString(),
destination.coord.toString());
#endif
return;
}
}
destination.blocked = true;
}
}
}
|