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
|
2023-06-21 14:38:57 +02:00
|
|
|
&& 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
|
2024-03-17 09:34:54 +02:00
|
|
|
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
|
|
|
|
|
|
|
}
|