--[[
patrol.lua:
INTERFACE
-- Moves between the points taken from the table below.
-- Will break the script if stuck for more than MAX_STUCK periods
MAX_STUCK = 10;
positions = {
[0]={-10, 3, 55},
[1]={-4, 3, 17},
[2]={-40, 3, 23},
[3]={-41, 3, 3},
}
END
--]]

function newposition()
	if p < table.getn(positions) then
		p = p + 1;
	else
		p = 0;
	end

	newp = positions[p];
	unit.MoveTo(newp);
end

function go2()
	local newpos = object.GetPosition();

	if CalcDistance(newpos, prevpos) < 1 then
		stuck = stuck + 1;
	end

	local d = CalcDistance(newpos, positions[p])

	if d < 12 then
		newposition();
		stuck = 0;
	end

	if stuck > MAX_STUCK then
		AIparts:RemovePeriodic("go2");
		unit.Stop();
	end

	prevpos = newpos;
end

AIparts:AddPeriodic("go2", 10, go2);
prevpos = object.GetPosition();

p = 0; newp = positions[p]; stuck = 0;
unit.MoveTo(newp);
