--[[
groupmoveto.lua:
INTERFACE
--1) Moves between the points taken from the table below.
--2) Unloads unit when the last point reached

points = {
		{10, 0, 0},
		{1, 0, 0}
	}
check_timeout = 5;
distance = 5;
unload = false;
move_timeout = 20;

END
--]]
dofile("Scripts/utils.lua");

--count = #points;
local str = "points={\n";
for l,v in ipairs(points) do
	str = str.."\t{"..v[1]..","..v[2]..","..v[3].."},\n";
end
str = str.."};\n";
str = str.."check_timeout = "..tostring(check_timeout)..";\n";
str = str.."distance = "..tostring(distance)..";\n";
str = str.."unload = "..tostring(unload)..";\n";

function Main()
	AIparts:Run();
end

local function TemplateMove(str)
--	log("Move group");
	local list = group.UnitList;
	for k,v in ipairs(list) do
--log("#"..k.." = ".. GetObjectId(v));
		DoObjectScript(v, str .. "dofile(\"Scripts/templates/group/move.lua\");");
	end
end

function Initialize()
--	log("Initialize");
--log(str);
	AIparts = utils.CreateSubsystems();
	AIparts:AddOneTime("TemplateMove", move_timeout, function() TemplateMove(str) end);
end

Initialize();
