----------------------------------------------------------------------------------------------------------------
-- Annihilate Win Condtition
--
--	Last player standing wins.
--
-- (c) 2003 Relic Entertainment Inc.
import("ScarUtil.scar");

function Annihilate()

	-- wait 0.25 secs before adding this rule. this is so it is not executed
	-- on the same frame as the other win conditions
	Rule_AddOneShot( Annihilate_AddMainRule, 0.25 )
	
	obj_table_P1 = { title_id = 60000, short_desc_id = 60300, help_tip_id = 60300 }
	
	Objective_Add( obj_table_P1, 1 )
	
end

function Annihilate_AddMainRule()
	Rule_AddInterval(CheckAnnihilate, 2)
end

_Annihilate = 
{
	--don't count these when counting the number of buildings owned
	g_annihilate_exceptions = 
	{
		"eldar_listening_post",
		"chaos_mine_field",
		"eldar_mine_field",
		"ork_mine_field",
		"space_marine_mine_field",
		"eldar_webway_gate",
		"eldar_support_platform_scatterlaser",
		"chaos_listening_post",
		"chaos_turret_bolter",
		"ork_gork_totem",
		"ork_waagh_banner",
		"space_marine_listening_post",
		"space_marine_turret_bolter",
		"cadinq_turret_bolter",
		"cadinq_listening_post",
		"cadinq_mine_field"
	},
	
	-- at least this number of units if no buildings
	g_NumUnits = 0,
}

function CheckAnnihilate()

	-- total number of players
	local count = World_GetPlayerCount();
	
	--check for annihilated dudes
	for i = 0, count-1
	do
		-- check if player has been annihilated
		local player = World_GetPlayerAt(i);
	
		--if no buildings and less than g_NumUnits, then you die
		if( Player_IsAlive(player) ) then
			if( Player_HasBuildingsExcept(player, _Annihilate.g_annihilate_exceptions) == false ) then
--~ 				if( Player_GetUnitCount(player) < _Annihilate.g_NumUnits ) then
					Player_Kill(player);
--~ 				end
			end
		end
	end
	
	-- check if only one team left -- if only one team left, they win and everybody else loses
	Util_CheckOneTeamLeft("annihilate");
end

Scar_AddInit(Annihilate)