--33 BSG demo level - v2 (25/04/2006)

GUID = 
	{ 110, 91, 157, 190, 18, 23, 250, 78, 144, 20, 41, 246, 181, 128, 214, 12, }
GameRulesName = "BSG demo level"
Directories =
{
    Levels = "data:LevelData\\Multiplayer\\BSGdemo\\",
}
Description = "Demo level for BSG mod."
GameSetupOptions = 
	{ 
	{ 
		name = "resources", 
		locName = "$3240", 
		tooltip = "This setting affects resource yield of asteroids. (Low = 0.5x, Standard = 1.0x, High = 2.0x)", 
		default = 1, 
		visible = 0, 
		choices = 
			{ "$3241", "0.5", "$3242", "1.0", "$3243", "2.0", }, }, 
	{ 
		name = "unitcaps", 
		locName = "$3214", 
		tooltip = "$3234", 
		default = 0, 
		visible = 0, 
		choices = 
			{ "$3215", "Normal", }, }, 
	{ 
		name = "resstart", 
		locName = "$3205", 
		tooltip = "Select starting RU levels. Starting off with some RUs in the supply chain is proper for a prepared engagement.", 
		default = 0, 
		visible = 0, 
		choices = 
			{ "$3209", "3000", }, }, 
	{ 
		name = "lockteams", 
		locName = "$3220", 
		tooltip = "$3235", 
		default = 0, 
		visible = 0, 
		choices = 
			{ "$3221", "yes", "$3222", "no", }, }, 
	{ 
		name = "startlocation", 
		locName = "$3225", 
		tooltip = "Lock starting locations: As PDS is meant as a wargame and not a free-for-all, Fixed is recommended for pseudo-scenario-based gameplay.", 
		default = 1, 
		visible = 0, 
		choices = 
			{ "$3226", "random", "$3227", "fixed", }, }, 
	}

function OnInit()
	ATI_LoadTemplates("data:LevelData\\ATI.lua")
	SobGroup_Create("sg_Survivors")
	Player_SetDefaultShipTactic(0, AggressiveTactics)
	Player_SetDefaultShipTactic(1, AggressiveTactics)
	Rule_AddInterval("Rule_SurvivorCount", 3)
	Rule_AddInterval("Rule_Briefing", 8)
	Camera_SetLetterboxStateNoUI(1, 2)
end

function Rule_SurvivorCount()
	DisplaySurvivorCount()
	Rule_Remove("Rule_SurvivorCount")
end

function DisplaySurvivorCount()
	local iSurvivorCount = GetSurvivorCount()
	local message = strsub(tostring(iSurvivorCount), 1, 2)..","..strsub(tostring(iSurvivorCount), 3, 5).." SURVIVORS"
	LocationCard(message, 4)
end

function GetSurvivorCount()
	local tSurvivors = { { name = "hur_galactica", number = 49990, }, {name = "hur_containership", number = 250,}, {name = "hur_raptor", number =2,}, { name = "hur_vipermkii", number = 1,}, {name = "hur_vipermkxii", number = 1,}, {name = "hur_apollo", number = 1,}, {name = "hur_starbuck", number = 1,} }
	local iSurvivorCount = 0
	for i, iCount in tSurvivors do
		SobGroup_Clear("sg_Survivors")
		Player_FillShipsByType("sg_Survivors", 0, iCount.name)
		iSurvivorCount = iSurvivorCount + iCount.number*SobGroup_Count("sg_Survivors")
	end
	return iSurvivorCount
end

function Rule_Briefing()
	Subtitle_Add(Actor_FleetIntel, "To all units: prepare for immediate contact with Cylons. FTL engines operational in approximately 5 minutes.", 5)
	i33 = 1957
	Rule_AddInterval("Rule_33", 1)
	Rule_Remove("Rule_Briefing")
end

function StartPlay()
	Camera_SetLetterboxStateNoUI(0, 2)
	iCountdown = 5*60
	Rule_AddInterval("Rule_FTLCountdown", 1)
	Rule_AddInterval("Rule_WatchGalactica", 1)
	CPU_Enable(1, 0)
	local tVol1 = randomVector(0, 360, 0, 360, 15000)
	Volume_AddSphere("vol_Cylon1", {tVol1[1], tVol1[2], tVol1[3],}, 2000)
	SobGroup_ExitHyperSpace("sg_Cylon_1", "vol_Cylon1")
	SobGroup_AttackPlayer("sg_Cylon_1", 0)
	local tVol2 = randomVector(0, 360, 0, 360, 15000)
	Volume_AddSphere("vol_Cylon2", {tVol2[1], tVol2[2], tVol2[3],}, 2000)
	SobGroup_ExitHyperSpace("sg_Cylon_2", "vol_Cylon2")
	SobGroup_AttackPlayer("sg_Cylon_2", 0)
	SobGroup_SetSpeed("sg_Cylon_Base1", 0.8)
	SobGroup_SetSpeed("sg_Cylon_Base2", 0.8)
	SobGroup_Attack(1, "sg_Cylon_Base1", "sg_Galactica")
	SobGroup_Attack(1, "sg_Cylon_Base2", "sg_Galactica")
end

function Rule_33()
	i33 = i33 + 1
	if i33 < 1981 then
		local m = floor(i33/60)
		local s = i33 - m*60
		local message = format("%02d:%02d", m, s)
		local rect = {0.49, 0.2, 0, 0}
		Display_Message(message, rect)
	else
		StartPlay()
		Rule_Remove("Rule_33")
	end
end
function Rule_FTLCountdown()
	iCountdown = iCountdown - 1
	if iCountdown > 0 then
		local m = floor(iCountdown/60)
		local s = iCountdown - m*60
		local message = format("REMAINING TIME: %02d:%02d", m, s)
		local rect = {0.41, 0.18, 0, 0}
		Display_Message(message, rect)
	else
		LocationCard("FTL ENGINES OPERATIONAL - PREPARE FOR JUMP", 3)
		Rule_AddInterval("Rule_FTLJump", 5)
		Rule_Remove("Rule_FTLCountdown")
	end
end

function Rule_FTLJump()
	SobGroup_EnterHyperSpaceOffMap("Player_Ships0")
	Camera_SetLetterboxStateNoUI(1, 2)
	DisplaySurvivorCount()
	Rule_AddInterval("Rule_End", 5)
	Rule_Remove("Rule_FTLJump")
end

function Rule_WatchGalactica()
	if SobGroup_Empty("sg_Galactica") == 1 then
		Rule_Remove("Rule_FTLCountdown")
		local rect = {0.41, 0.18, 0, 0}
		Display_Message(" ", rect)
		Rule_AddInterval("Rule_End", 5)
	end
end

function Rule_End()
	Player_Kill(0)
	setGameOver()
	Rule_Remove("Rule_End")
end


function randomVector(azimuth, azimuth_var, site, site_var, length)
	local li_si = (site - site_var) + random(site_var*2)
	local li_az = (azimuth - azimuth_var) + random(azimuth_var*2)
	local t_vector = {}
	t_vector[1] = floor(length * cos(li_si) * cos(li_az))
	t_vector[3] = floor(length * cos(li_si) * sin(li_az))
	t_vector[2] = floor(length * sin(li_si))
	return t_vector
end

function Display_Message(message, rect)
	ATI_Clear()
	ATI_CreateParameters(1)
	ATI_AddString(0, message)
	ATI_Display2D("Message", rect, 0)
end
