-- ===================================
-- dark05
-- Player wins when he destroys all Mushrooms on the map
-- OK. TESTET WITH 0.90.545 ANDI
-- ===================================

function InitVar()

--// Add Dark Gardener in Difficult level NORMAL
	if Game.GetDifficulty() == 1 then	
		Settlers.AddSettlers(112,348,3,Settlers.DARKGARDENER,5)
	end

	--// set time for attack of the dt
		if Game.GetDifficulty() == 0 then	
			--//easy//--
			Vars.Save2 = 70 +  Game.Random(10)
		else
			Vars.Save2 = 40 +  Game.Random(10)
		end

	--// time flag
	Vars.Save1 = 1 

	--// Prist send flag
	Vars.Save3 = 1
end
--------
function PriesterSendAndDTAttackCheck()
	--//DT attack
	
	if Game.Time() == Vars.Save2 and Vars.Save1 == 1 then
		AI.AttackNow(3, 1, 1)
		Vars.Save1 = 0
	
	end
	
	
	
	--//Priester In Area?
	dbg.tp("Settlers.AmountInAreaWait : "..Vars.Save3 )
	if Settlers.AmountInArea(1, Settlers.PRIEST,428,137,10) == 1 and Vars.Save3 == 1 then
    		Game.ShowText("DARKTRIBE_SCRIPT_FIVE_01")
    		dbg.tp("Settlers.AmountInAreaYes : "..Vars.Save3 )
    		Vehicles.AddVehicle(154,12,2,Vehicles.TRANSPORTSHIP,0,0,1)
    		--//Mal sehen, ob es danach nicht nach Hause fahren kann //--
    		--//Ansonsten verschwinden lassen
    		Goods.AddPileEx(151, 22, Goods.SWORD, 4)
    		Goods.AddPileEx(152, 21, Goods.BOW, 1)
    		Goods.AddPileEx(153, 23, Goods.ARMOR, 1)
    		Goods.AddPileEx(163, 25, Goods.SWORD, 5)
    		Goods.AddPileEx(155, 23, Goods.ARMOR, 2)
    		Goods.AddPileEx(160, 27, Goods.BOW, 2)
    		Goods.AddPileEx(154, 26, Goods.SWORD, 5)
    		Goods.AddPileEx(158, 28, Goods.GOLDBAR, 8)
    		Vars.Save3 = 0
    		unrequest_event(PriesterSendCheck, Events.FIVE_TICKS)
  	end
  
end
-----------------
function VictoryConditionCheck()
 
	if Buildings.Amount(3, Buildings.MUSHROOMFARM, Buildings.ALL) == 2 then
		Game.EnemyPlayersLost(1)
	else
		Game.DefaultPlayersLostCheck()
	end

  	Game.DefaultGameEndCheck()
  
end

-- -----------------------------------------------------------------------------
-- The "new_game" function (will be called when a new game starts)
-- -----------------------------------------------------------------------------

function new_game()
	--//GoldOre
	Goods.AddPileEx(116, 67, Goods.GOLDORE, 3)

	--//SetPlayerVar//--	
	--//DTMaxFarmsPerHour//--
	AI.SetPlayerVar(2, "DTMaxFarmsPerHour", 2, 5, 10)

	--// Set Stoagearea
	Buildings.AddBuildingEx(426,135,2,Buildings.STORAGEAREA)

	request_event(VictoryConditionCheck, Events.VICTORY_CONDITION_CHECK)
	request_event(PriesterSendAndDTAttackCheck, Events.FIVE_TICKS)
	request_event(InitVar,Events.FIRST_TICK_OF_NEW_GAME)
	ShowEnemies_new_game()
end

-----------------------------
function register_functions()
	-- Every function, which requests events, must be registered here!

	include("ShowEnemies.txt")
	gShowEnemies_SuppressDefaultTargets = 1
	tinsert(gShowEnemies_Targets, {428,137})
	tinsert(gShowEnemies_Targets, {168,369})
	ShowEnemies_register_functions()

	reg_func(VictoryConditionCheck)
	reg_func(PriesterSendAndDTAttackCheck)  
	reg_func(InitVar)
end

