Question: Is there a way to calculate the actual path length to the target (not distance)?
What does it do when you stand on a hill somewhere, and at the bottom of the monster, the distance may be small, but to get to the monster you have to pass +100500 cells. There is a place in Attack.pm:
Code: Select all
} elsif ($realMonsterDist > $args->{attackMethod}{maxDistance}
&& !timeOut($args->{ai_attack_giveup})) {
# The target monster moved; move to target
$args->{move_start} = time;
$args->{monsterPos} = {%{$monsterPos}};
my $pos = meetingPosition($target, $args->{attackMethod}{maxDistance});
my $dist = sprintf("%.1f", $monsterDist);
debug "Target distance $dist is >$args->{attackMethod}{maxDistance}; moving to target: " .
"from ($myPos->{x},$myPos->{y}) to ($pos->{x},$pos->{y})\n", "ai_attack";
my $result = $char->route(undef, @{$pos}{qw(x y)},
maxRouteTime => $config{'attackMaxRouteTime'},
maxRouteDistance => $config{'attackMaxRouteDistance'},
attackID => $ID,
noMapRoute => 1,
noAvoidWalls => 1);
if (!$result) {
# Unable to calculate a route to target
$target->{attack_failed} = time;
AI::dequeue;
message T("Unable to calculate a route to target, dropping target\n"), "ai_attack";
if ($config{'teleportAuto_dropTarget'}) {
message T("Teleport due to dropping attack target\n");
useTeleport(1);
}
}
Update:
Solution: should use Utils::PathFinding.