----------------------------------------------------------------------------------------------------------------
-- AI player scar helper functions
-- (c) 2003 Relic Entertainment Inc.

--? @group AIInterface

--? @shortdesc Set a build order table for the ai_player
--? @extdesc
--? An example build table:\n
--?	local build_table =\n
--?	{\n
--?		{SBP.ALLIED_RIFLEMEN, 1, 5},\n
--?		{SBP.ALLIED_TANKTHINGY, 2, 3}\n
--?	}\n
--? The first number in each entry is the starting value -- the lowest number gets built first\n
--? The second number is the increment that happens each time the unit is built\n
--? NOTE: Setting build demand table clobbers the class preferences
--? @result Void
--? @args PlayerID ai_player, Table build_table
function AI_SetBuildTable( ai_player, build_table )

	for i in pairs(build_table) do
		AI_SetBuildDemand( ai_player, build_table[i][1], build_table[i][2], build_table[i][3] )
	end

end

--? @shortdesc Lock an SGroup from the ai_player
--? @args PlayerID ai_player, SGroup sgroup
--? @result Void
function AI_LockSGroup( ai_player, sgroup )

	local lock = function( sgroupid, itemindex, squadID )
		AI_LockSquad( ai_player, squadID )
	end
	
	SGroup_ForEach( sgroup, lock )

end

--? @shortdesc Unlock an SGroup from the ai_player
--? @args PlayerID ai_player, SGroup sgroup
--? @result Void
function AI_UnlockSGroup( ai_player, sgroup )

	local unlock = function( sgroupid, itemindex, squadID )
		AI_UnlockSquad( ai_player, squadID )
	end
	
	SGroup_ForEach( sgroup, unlock )

end

--? @shortdesc Set limits to the production items that an AI can build
--? @extdesc
--? An example production limites table:\n
--?	local production_limits_table =\n
--?	{\n
--?		{SBP.ENGINEER_SQUAD, PBGTYPE_Squad, 2},\n
--?		{EBP.ALLIED_BARRACKS, PBGTYPE_Entity, 0}\n
--?		{UPG.ALLIED_MINESWEEPER, PBGTYPE_Upgrade, 0}\n
--?	}\n
--? The first argument is the table is the PBG name, the second the PBG Type, and third: the number of those items the AI can build
--? @args PlayerID ai_player, Table limits_table
--? @result Void
function AI_SetProductionLimitsTable( ai_player, limits_table )
	for i in pairs(limits_table) do
		AI_SetProduductionLimits( ai_player, limits_table[i][2], limits_table[i][1], limits_table[i][3] )
	end
end
