Light = 0.9
 
turnOn = function()
	Lighting.Ambient = Light
	if Light < 1.01 then
		Light = Light + 0.001
		Trigger.AfterDelay(8, function()
			turnOn()
		end)
	
	else
		Trigger.AfterDelay(8000, function()
			turnOff()
		end)
	end
end

turnOff = function()
	Lighting.Ambient = Light
	if Light > 0.6 then
		Light = Light - 0.001
		Trigger.AfterDelay(8, function()
			turnOff()
		end)	
	
	else
		Trigger.AfterDelay(3000, function()
			turnOn()
		end)
	end
end

PlaySound = function()
	Media.PlaySound("JingleBells.wav")
	Trigger.AfterDelay(DateTime.Seconds(175), PlaySound)
end

SetObjectiveandMakeTrees = function()
	if Multi0 ~= nil then
		BurnTree1 = Multi0.AddPrimaryObjective("Burn down the enemys Xmas-Tree")
	end
	if Multi1 ~= nil then
		BurnTree1 = Multi1.AddPrimaryObjective("Burn down the enemys Xmas-Tree")
	end
	if Multi2 ~= nil then
		BurnTree1 = Multi2.AddPrimaryObjective("Burn down the enemys Xmas-Tree")
	end
	if Multi3 ~= nil then
		BurnTree2 = Multi3.AddPrimaryObjective("Burn down the enemys Xmas-Tree")
	end
	if Multi4 ~= nil then
		BurnTree2 = Multi4.AddPrimaryObjective("Burn down the enemys Xmas-Tree")
	end
	if Multi5 ~= nil then
		BurnTree2 = Multi5.AddPrimaryObjective("Burn down the enemys Xmas-Tree")
	end
	Bottomtree = Actor.Create("ctree", true, { Location = CPos.New(8,87), Owner = Neutral })
	Toptree = Actor.Create("ctree", true, { Location = CPos.New(54,11), Owner = Neutral })
	Trigger.OnKilled(Toptree, Team2Won)
	Trigger.OnKilled(Bottomtree, Team1Won)
end

Team1Won = function()
	if Multi0 ~= nil then
		Multi0.MarkCompletedObjective(BurnTree1)
	end
	if Multi1 ~= nil then
		Multi1.MarkCompletedObjective(BurnTree1)
	end
	if Multi2 ~= nil then
		Multi2.MarkCompletedObjective(BurnTree1)
	end
	if Multi3 ~= nil then
		Multi3.MarkFailedObjective(BurnTree2)
	end
	if Multi4 ~= nil then
		Multi4.MarkFailedObjective(BurnTree2)
	end
	if Multi5 ~= nil then
		Multi5.MarkFailedObjective(BurnTree2)
	end
end
Team2Won = function()
	if Multi5 ~= nil then
		Multi5.MarkCompletedObjective(BurnTree2)
	end
	if Multi4 ~= nil then
		Multi4.MarkCompletedObjective(BurnTree2)
	end
	if Multi3 ~= nil then
		Multi3.MarkCompletedObjective(BurnTree2)
	end
	if Multi2 ~= nil then
		Multi2.MarkFailedObjective(BurnTree1)
	end
	if Multi1 ~= nil then
		Multi1.MarkFailedObjective(BurnTree1)
	end
	if Multi0 ~= nil then
		Multi0.MarkFailedObjective(BurnTree1)
	end
end

SetupPlayers = function()
	Neutral = Player.GetPlayer("Neutral")
	Multi0 = Player.GetPlayer("Multi0")
	Multi1 = Player.GetPlayer("Multi1")
	Multi2 = Player.GetPlayer("Multi2")
	Multi3 = Player.GetPlayer("Multi3")
	Multi4 = Player.GetPlayer("Multi4")
	Multi5 = Player.GetPlayer("Multi5")
end

Thiscolor = HSLColor.New(115, 115, 143)

function WorldLoaded()
	SetupPlayers()
	Media.StopMusic()
	PlaySound()
	turnOn()
	SetObjectiveandMakeTrees()
	Trigger.AfterDelay(DateTime.Seconds(5), function()
		Media.DisplayMessage("Protect the Xmas-Tree on your side, you will loose if he gets burned.", "Materia", Thiscolor)
	end)
	Trigger.AfterDelay(DateTime.Seconds(10), function()
		Media.DisplayMessage("You can open the Gifts around your tree with harvesters.", "Materia", Thiscolor)
	end)
	Trigger.AfterDelay(DateTime.Seconds(15), function()
		Media.DisplayMessage("Merry X-mass and enjoy the map ;D", "Materia", Thiscolor)
	end)
	Trigger.AfterDelay(DateTime.Seconds(20), function()
		Media.DisplayMessage("This map is part of the X-mas map contest by Zypres. Join the Sleipnirstuff forum for more information", "Materia", Thiscolor)
	end)
end
