Get path length

Forum closed. All further discussion to be discussed at https://github.com/OpenKore/

Moderator: Moderators

Message
Author
Zloba
Noob
Noob
Posts: 3
Joined: 24 Jun 2009, 03:53
Noob?: Yes

Get path length

#1 Post by Zloba »

Hello dear developers!

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);
			}
		}
Previously it worked (before entering Tasks), but now, as I understand route() never returns 0, that I would like to first estimate the path, and then decide whether to go or not.

Update:
Solution: should use Utils::PathFinding.

Locked