--	Stratagus Map - Single player campaign

Load("campaigns/human-exp/levelx02h_c2.sms")

Briefing(
  title,
  objectives,
  "../campaigns/human/interface/introscreen1.png",
  "campaigns/human-exp/levelx02h.txt",
  {"campaigns/human-exp/levelx02h-intro1.wav",
   "campaigns/human-exp/levelx02h-intro2.wav"}
)

AddTrigger(
  function() return GetNumOpponents(GetThisPlayer()) == 0 and
    GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-arthor-literios") == 1 end,
  function() return ActionVictory() end)
AddTrigger(
  function() return GetPlayerData(GetThisPlayer(), "TotalNumUnits") == 0 end,
  function() return ActionDefeat() end)
AddTrigger(
  function() return GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-arthor-literios") == 0 and
    GetPlayerData(4, "UnitTypesCount", "unit-arthor-literios") == 0 end,
  function() return ActionDefeat() end)

--Units
DefineAllowNormalHumanUnits("AAAAAAAAAAAAAAAA")
DefineAllowExtraHumanUnits("FFFFFFFFFFFFFFFF")
DefineAllowNormalOrcUnits("AAAAAAAAAAAAAAAA")
DefineAllowExtraOrcUnits("FFFFFFFFFFFFFFFF")
DefineAllowSpecialUnits("FFFFFFFFFFFFFFFF")
DefineAllowHumanAlways()
DefineAllowOrcAlways()

DefineAllow("unit-gryphon-aviary", "FFFFFFFFFFFFFFFF")
DefineAllow("unit-human-shipyard", "FFFFFFFFFFFFFFFF")

-- AI

local hum_exp_02a_loop_funcs = {
	function() DebugPrint("Looping !\n") return false end,
	function() return AiSleep(1000) end,
	function() return AiForce(1, {AiSoldier(), 4, AiShooter(), 3, AiCavalry(), 3, AiCatapult(), 1}) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiSleep(2000) end,
	function() return AiForce(1, {AiSoldier(), 3, AiShooter(), 2, AiCavalry(), 2, AiCatapult(), 1}) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() stratagus.gameData.AIState.loop_index[1 + AiPlayer()] = 0; return false end,
}

local hum_exp_02b_loop_funcs = {
	function() DebugPrint("Looping !\n") return false end,
	function() return AiSleep(60000) end,
	function() stratagus.gameData.AIState.loop_index[1 + AiPlayer()] = 0; return false end,
}

local hum_exp_02c_loop_funcs = {
	function() DebugPrint("Looping !\n") return false end,
	function() return AiForce(1, {AiSoldier(), 4, AiShooter(), 3, AiCavalry(), 3, AiCatapult(), 1}) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiSleep(5000) end,
	function() return AiForce(1, {AiFlyer(), 2}) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiForce(1, {AiFlyer(), 1}) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,

	function() stratagus.gameData.AIState.loop_index[1 + AiPlayer()] = 0; return false end,
}

local hum_exp_02a_funcs = {
	function() return AiNeed(AiCityCenter()) end,
	function() return AiNeed(AiBarracks()) end,
	function() return AiNeed(AiLumberMill()) end,
	function() return AiSet(AiWorker(), 7) end,
	function() return AiWait(AiWorker()) end,
	function() return AiNeed(AiBlacksmith()) end,
	function() return AiForce(0, {AiSoldier(), 2, AiShooter(), 2}) end,
	function() return AiForce(1, {AiSoldier(), 4, AiShooter(), 3}) end,
	function() return AiNeed(AiTower()) end,
	function() return AiNeed(AiTower()) end,
	function() return AiWaitForce(1) end,
	function() return AiSleep(2000) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiResearch(AiUpgradeWeapon1()) end,
	function() return AiUpgradeTo(AiBetterCityCenter()) end,
    function() return AiWait(AiBetterCityCenter()) end,
	function() return AiForce(1, {AiSoldier(), 4, AiShooter(), 3}) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiSleep(7000) end,
	function() return AiResearch(AiUpgradeMissile1()) end,
	function() return AiNeed(AiStables()) end,
	function() return AiResearch(AiUpgradeArmor1()) end,
	function() return AiForce(0, {AiSoldier(), 2, AiShooter(), 2, AiCavalry(), 1}) end,
	
	function() return AiLoop(hum_exp_02a_loop_funcs, stratagus.gameData.AIState.loop_index) end,
}

local hum_exp_02b_funcs = {
	function() return AiNeed(AiCityCenter()) end,
	function() return AiNeed(AiBarracks()) end,
	function() return AiNeed(AiLumberMill()) end,
	function() return AiNeed(AiBlacksmith()) end,
	function() return AiNeed(AiTower()) end,
	function() return AiUpgradeTo(AiBetterCityCenter()) end,
	function() return AiNeed(AiBarracks()) end,
	function() return AiNeed(AiStables()) end,
	function() return AiUpgradeTo(AiBestCityCenter()) end,
	function() return AiNeed(AiCityCenter()) end,
	function() return AiNeed(AiMageTower()) end,
	function() return AiNeed(AiMageTower()) end,
	function() return AiResearch(AiMageSpell5()) end,
	
	function() return AiSet(AiWorker(), 9) end,
	function() return AiWait(AiWorker()) end,
	
	function() return AiResearch(AiMageSpell4()) end,
	function() return AiNeed(AiTower()) end,
	function() return AiNeed(AiTower()) end,
	function() return AiResearch(AiUpgradeWeapon1()) end,
	function() return AiWait(AiBetterCityCenter()) end,
	function() return AiResearch(AiUpgradeArmor1()) end,
	function() return AiResearch(AiUpgradeWeapon2()) end,
	function() return AiResearch(AiUpgradeArmor2()) end,
	function() return AiWait(AiBestCityCenter()) end,
	
	function() return AiForce(0, {AiSoldier(), 4, AiShooter(), 4, AiCavalry(), 5, AiMage(), 2, AiCatapult(), 1}) end,

	function() return AiLoop(hum_exp_02b_loop_funcs, stratagus.gameData.AIState.loop_index) end,
}

local hum_exp_02c_funcs = {
	function() return AiNeed(AiCityCenter()) end,
	function() return AiNeed(AiBarracks()) end,
	function() return AiNeed(AiLumberMill()) end,
	function() return AiUpgradeTo(AiBetterCityCenter()) end,
	
	
	function() return AiNeed(AiBlacksmith()) end,
	function() return AiNeed(AiStables()) end,
	function() return AiNeed(AiScientific()) end,
	function() return AiNeed(AiTower()) end,
	function() return AiNeed(AiTower()) end,
	function() return AiNeed(AiTower()) end,
	
	function() return AiUpgradeTo(AiBestCityCenter()) end,	
	function() return AiNeed(AiAirport()) end,
	
	function() return AiResearch(AiUpgradeWeapon1()) end,
	function() return AiResearch(AiUpgradeMissile1()) end,
	function() return AiResearch(AiUpgradeArmor1()) end,
	function() return AiResearch(AiUpgradeMissile2()) end,
	function() return AiResearch(AiUpgradeWeapon2()) end,	
	
	function() return AiSet(AiWorker(), 8) end,
	
	function() return AiForce(0, {AiSoldier(), 4, AiShooter(), 3}) end,

	function() return AiWait(AiBetterCityCenter()) end,
	function() return AiWait(AiBestCityCenter()) end,
	function() return AiForce(0, {AiSoldier(), 4, AiShooter(), 3, AiCavalry(), 3, AiCatapult(), 1}) end,
	function() return AiForce(1, {AiFlyer(), 1}) end,
	function() return AiWaitForce(1) end,
	function() return AiSleep(1500) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiForce(1, {AiFlyer(), 2}) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,

	function() return AiLoop(hum_exp_02c_loop_funcs, stratagus.gameData.AIState.loop_index) end,
}

function AiHumanExp02a() return AiLoop(hum_exp_02a_funcs, stratagus.gameData.AIState.index) end
function AiHumanExp02b() return AiLoop(hum_exp_02b_funcs, stratagus.gameData.AIState.index) end
function AiHumanExp02c() return AiLoop(hum_exp_02c_funcs, stratagus.gameData.AIState.index) end
DefineAi("hum-exp-2a", "*", "hum-exp-2a", AiHumanExp02a) 
DefineAi("hum-exp-2b", "*", "hum-exp-2b", AiHumanExp02b)
DefineAi("hum-exp-2c", "*", "hum-exp-2c", AiHumanExp02c)


Load("campaigns/human-exp/levelx02h.sms")
