-- =============================================================================
-- viking-01
-- Enemy soldiers are placed in certain periods at a coast near to the player's 
-- initial area (together with a ship to make it look plausible) 
-- 
-- FINISHED. TESTED WITH V 0.90 522
-- =============================================================================

function InitVar ()

	--// toggling flag for one-time call
	Vars.Save1 = 1 

	--// set time period in minutes here
	Vars.Save6 = 15 +  Game.Random(5)
	
	--// first time of "enemy landing"  
	Vars.Save2 = 15 +  Game.Random(5)

	
	if Game.GetDifficulty() == 0 then	
		--// counters for # of soldiers for EASY
		Vars.Save3 = 1
		Vars.Save4 = 1 
		Vars.Save5 = 1
	else
		--// counters for # of soldiers for NORMAL
		Vars.Save3 = 2
		Vars.Save4 = 2 
		Vars.Save5 = 1
	end
		
end



--// -----------------------------------------------------------------------------
--// Generate Ship & Enemy soldiers every Vars.Save2 min. 
--// With growing number of soldiers
--// -----------------------------------------------------------------------------

function GenerateEnemies()
--// -----------------------------------------------------------------------------
--// switch ship on and deliever soldiers
--// -----------------------------------------------------------------------------
	if Game.Time() == Vars.Save2 and Vars.Save1 == 1 then
		Vehicles.AddVehicle(5, 160, 2, Vehicles.FERRY, 0)
    		Settlers.AddSettlers(14, 168, 2, Settlers.SWORDSMAN_01, Vars.Save3)
    		Settlers.AddSettlers(15, 169, 2, Settlers.BOWMAN_02, Vars.Save4)
    		Settlers.AddSettlers(16, 170, 2, Settlers.BLOWGUNWARRIOR_01, Vars.Save5)
    		Vars.Save1 = 0
    		
--// send new squad home
	
    		AI.NewSquad(2, AI.CMD_MOVE_HOME)
    		
--// set time period for switch ship off

	    	Vars.Save2 = Vars.Save2 + 1
	    	
--// increase number of soldiers for next delievery
		if Game.GetDifficulty() == 0 then	
    			Vars.Save3 = Vars.Save3 + 1
    			Vars.Save4 = Vars.Save4 + 1
    			Vars.Save5 = Vars.Save5 + 1
    		else
    			Vars.Save3 = Vars.Save3 + 2
    			Vars.Save4 = Vars.Save4 + 2
    			Vars.Save5 = Vars.Save5 + 1
    		end
  	end

--// -----------------------------------------------------------------------------
--// switch ship off after one minute
--// -----------------------------------------------------------------------------
  	if Game.Time() == Vars.Save2 and Vars.Save1 == 0 then
    		Vehicles.KillVehicles(2, Vehicles.FERRY,5 ,160, 10, 0)
    		Vars.Save1 = 1
--// set next time period for switch ship on

    		Vars.Save2 = Vars.Save2 - 1
    		Vars.Save2 = Vars.Save2 + Vars.Save6
    		Vars.Save6 = 15 +  Game.Random(5)
  	end
   
end


--// -----------------------------------------------------------------------------

function new_game()

	--// SetPlayerVaribles //--

	  --// Attack Delay //--
	AI.SetPlayerVar(2, "AttackDelay", 60, 40, 10) 

	--// SOLDIERLIMITRELATIVE//--
	AI.SetPlayerVar(2, "SoldierLimitAbsolute", 150,250,400)
	AI.SetPlayerVar(2, "SoldierLimitRelative", 100,130,150)


  request_event(GenerateEnemies, 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")
	ShowEnemies_register_functions()

  reg_func(GenerateEnemies)
  reg_func(InitVar)
end
