The code is following:
Code: Select all
# planWalk by Snoopy
package planWalk;
use strict;
#use warnings;
use Time::HiRes qw(time);
use Globals;
use Utils;
use Misc;
use AI;
use Log qw(debug message warning error);
use Translation;
use encoding 'utf8';
our $nSpot = -1;;
Plugins::register('planWalk', 'Auto Plan to walk.', \&on_unload, \&on_reload);
my $hooks = Plugins::addHooks(['process_RandomWalk', \&do_planWalk]);
my $prefix = "planWalk_";
sub on_unload {
	Plugins::delHooks($hooks);
}
sub on_reload {
	message "planWalk plugin reloading\n";
	Plugins::delHooks($hooks);
}
sub do_planWalk {
	return if (!$config{autoPlanWalk} || $config{lockMap} ne $field->baseName);
#	message T("Do plan walking route to:\n");
	$nSpot++;
	$nSpot = 0 if (!(exists $config{$prefix.$nSpot}));
	my ($to_x, $to_y);
	$to_x = $config{$prefix.$nSpot."_x"};
	$to_y = $config{$prefix.$nSpot."_y"};
	if ($to_x eq "" || $to_y eq "") {
		error T("Invalid coordinates setting for planWalk (coordinates are unwalkable); planWalk disabled\n");
		$config{autoPlanWalk} = 0;
	} elsif ($field->isWalkable($to_x, $to_y)) {
		AI::clear(qw/move route mapRoute/);
		message TF("Do plan walking route to: %s: %s, %s\n", $field->descString(), $to_x, $to_y), "route";
		main::ai_route($field->baseName, $to_x, $to_y, attackOnRoute => 2, noSitAuto => 1);
	} else {
		error T("Invalid coordinates specified for planWalk (coordinates are unwalkable); planWalk disabled\n");
		$config{autoPlanWalk} = 0;
	}
}
1;
Code: Select all
autoPlanWalk 1
planWalk A {
	label myWalk_0
	x 365
	y 205
}
planWalk B {
	label myWalk_1
	x 360
	y 96
}
planWalk C {
	label myWalk_2
	x 332
	y 180
}
planWalk D {
	label myWalk_3
	x 365
	y 140
}
planWalk E {
	label myWalk_4
	x 332
	y 180
}
planWalk F {
	label myWalk_5
	x 365
	y 140
}
planWalk G {
	label myWalk_6
	x 360
	y 96
}
The line is:
Plugins::callHook('process_RandomWalk');
It is for hooking the "process_RandomWalk" event.
Code: Select all
##### RANDOM WALK #####
sub processRandomWalk {
	if (AI::isIdle && (AI::SlaveManager::isIdle()) && $config{route_randomWalk} && !$ai_v{sitAuto_forcedBySitCommand}
		&& (!$field->isCity || $config{route_randomWalk_inTown})
		&& length($field->{rawMap}) ) {
		my ($randX, $randY);
		my $i = 500;
		do {
			$randX = int(rand($field->width)) + 1;
			$randX = int($config{'lockMap_x'} - $config{'lockMap_randX'} + rand(2*$config{'lockMap_randX'}))+1 if ($config{'lockMap_x'} ne '' && $config{'lockMap_randX'} ne '');
			$randY = int(rand($field->height)) + 1;
			$randY = int($config{'lockMap_y'} - $config{'lockMap_randY'} + rand(2*$config{'lockMap_randY'}))+1 if ($config{'lockMap_y'} ne '' && $config{'lockMap_randY'} ne '');
		} while (--$i && !$field->isWalkable($randX, $randY));
		if (!$i) {
			error T("Invalid coordinates specified for randomWalk (coordinates are unwalkable); randomWalk disabled\n");
			$config{route_randomWalk} = 0;
		} else {
			message TF("Calculating random route to: %s: %s, %s\n", $field->descString(), $randX, $randY), "route";
			ai_route($field->baseName, $randX, $randY,
				maxRouteTime => $config{route_randomWalk_maxRouteTime},
				attackOnRoute => 2,
				noMapRoute => ($config{route_randomWalk} == 2 ? 1 : 0) );
		}
		Plugins::callHook('process_RandomWalk');  // the line for hooking the process_RandomWalk
	}
}


