----------------------------------------------------------------------------------------------------------------
-- Restriction tables for single player missions
-- (c) 2003 Relic Entertainment Inc.

----------------------------------------------------------------------------------------------------------------
-- This table holds all the restriction levels for allies
-- Items with a level that are GREATER then the given level will be restricted.
-- Items that are in the game, but not specified in these tables WILL NOT be restricted.
_AllyRestrictions =
{
	Buildings =
	{
	--	ItemName						RestrictionLevel
		{"hq", 								1},
		{"barracks", 						2},
	},

	Squads =
	{
	-- 	ItemName						RestrictionLevel
		{"rifleman_8_squad",				1},
		{"engineer_8_squad",				2},
	},

	-- if we have AddOns add them here

	Research =
	{
	-- 	ItemName						RestrictionLevel
		{"squad_cap_research",				1},
		{"support_cap_research",			1},
	}
}


----------------------------------------------------------------------------------------------------------------
-- Restrict functions

--? @shortdesc Applies restrictions for allies.  You should call this at the begining of your mission for Player 1.
--? @args PlayerID playerId, Integer level
--? @result Void
function Restrict_Allies( playerId, level )
	if(Player_GetRaceName( playerId ) ~= "Allied Rifle Company") then
		fatal("Restrict_Allies can only be called for allies!")
	end

	_RestrictionPrivate.ApplyRestrictionsTable( playerId, level, _AllyRestrictions )
end



----------------------------------------------------------------------------------------------------------------
-- Private implementation

_RestrictionPrivate =
{
	__skipsave = true,

	ApplyRestrictionsTable = function( playerId, level, Restrictions )

		-- Restrictor functions for sub tables
		local RestrictBuilding 	= function( name ) Player_RestrictBuilding( playerId, name ) end
		local RestrictSquad		= function( name ) Player_RestrictSquad( playerId, name ) end
		--local RestrictAddOn 		= function( name ) Player_RestrictAddOn( playerId, name ) end
		local RestrictResearch 	= function( name ) Player_RestrictResearch( playerId, name ) end
		local RestrictWeapon 	= function( name ) Player_RestrictWeapon( playerId, name ) end

		-- Restrict everything greater then level for a given subtable.  Uses one of the above restrictor functions
		local ApplyRestrictionsSubTable = function( SubTable, RestrictorFunction )

			-- Ignore nil subtables
			if( SubTable == nil ) then return end

			for i = 1, table.getn( SubTable ) do
				if( SubTable[i][2] > level ) then
					print( "Restricting "..SubTable[i][1] )
					RestrictorFunction( SubTable[i][1] )
				end
			end
		end

		-- Restrict all subtables
		ApplyRestrictionsSubTable( Restrictions.Buildings, 	RestrictBuilding )
		ApplyRestrictionsSubTable( Restrictions.Squads, 	RestrictSquad )
		--ApplyRestrictionsSubTable( Restrictions.AddOns, 	RestrictAddOn )
		ApplyRestrictionsSubTable( Restrictions.Research, 	RestrictResearch )
		ApplyRestrictionsSubTable( Restrictions.Weapons, 	RestrictWeapon )

	end
}
