----------------------------------------------------------------------------------------------------------------
-- Timer helper functions
-- (c) 2003 Relic Entertainment Inc.


-------------------------------------------------
--IMPORTS
-------------------------------------------------
import("ScarUtil.scar")

sbps = {
	{"SBPs/Races/Allies/Soldiers/rifleman_squad.lua", 4},
	{"SBPs/Races/Allies/Vehicles/m4_sherman_squad.lua", 2},
}

function MakeArmy( groupName, playerID, team_sign )
	
	local sgroupid = SGroup_Create(groupName)
	
	local sign = 1
	local kOffset = 7
	local curoffset = 0
	local x_extents = World_GetWidth()/3
	local marker_pos = World_Pos(40*team_sign, 0, 0)
	local pos = marker_pos
	local count = table.getn(sbps)
	for i = 1, count do
		
		local unitname = sbps[i][1]
		local unitcount = sbps[i][2]
		for j = 1, unitcount do
			pos.x = marker_pos.x + curoffset*sign;
			
			if (pos.x > x_extents or pos.x < -x_extents) then
				sign = 1
				curoffset = 0
				pos.x = marker_pos.x;
				pos.z = pos.z + kOffset
			else
				-- flip flop offset (7,-14,21,-28,...)
				sign = sign*-1
				curoffset = curoffset + kOffset
			end
	
			print( "pos = "..pos.x.." "..pos.y.." "..pos.z.." - "..curoffset )
			
			Util_CreateSquadsAtPosition(playerID, sgroupid, unitname, pos, 1)
		end
	end
	
	-- attack move to the same position
	Cmd_AttackMovePos( sgroupid, World_Pos( 0,0,0) )
end

MakeArmy( "player1", World_GetPlayerAt(1), 1 )
MakeArmy( "player2", World_GetPlayerAt(2), -1 )
