--	Stratagus Map - Single player campaign

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

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

AddTrigger(
  function() return GetPlayerData(2, "TotalNumUnits") == 0 and
    GetPlayerData(3, "TotalNumUnits") == 0 end,
  function() return ActionVictory() end)
AddTrigger(
  function() return GetPlayerData(GetThisPlayer(), "TotalNumUnits") == 0 end,
  function() return ActionDefeat() end)
AddTrigger(
  function() return GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-white-mage") == 0 and
    GetPlayerData(0, "UnitTypesCount", "unit-white-mage") == 0 end,
  function() return ActionDefeat() end)
AddTrigger(
  function() return GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-female-hero") == 0 and
    GetPlayerData(0, "UnitTypesCount", "unit-female-hero") == 0 end,
  function() return ActionDefeat() end)
AddTrigger(
  function() return GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-knight-rider") == 0 and
    GetPlayerData(0, "UnitTypesCount", "unit-knight-rider") == 0 end,
  function() return ActionDefeat() end)

local hum_exp_11a_loop_funcs = {
	function() DebugPrint("Looping !\n") return false end,
	function() return AiSleep(3000) end,
	function() return AiForce(1, {AiSoldier(), 3, AiShooter(), 4, AiCavalry(), 4, AiCatapult(), 1, AiMage(), 2}, true) 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_11b_loop_funcs = {
	function() DebugPrint("Looping !\n") return false end,
	function() return AiSleep(1000) end,
	function() return AiForce(1, {AiSoldier(), 6, AiShooter(), 4, AiCatapult(), 1}, true) 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_11a_funcs = {
	function() return AiSet(AiWorker(), 1) end,
	function() return AiNeed(AiCityCenter()) end,
	function() return AiNeed(AiLumberMill()) end,
	function() return AiNeed(AiBarracks()) end,
	function() return AiSet(AiWorker(), 10) end,
	function() return AiWait(AiWorker()) end,
	function() return AiForce(0, {AiSoldier(), 3, AiShooter(), 2}) end,

	function() return AiUpgradeTo(AiBetterCityCenter()) end,
	function() return AiWait(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 AiUpgradeTo(AiGuardTower()) end,
	function() return AiNeed(AiTower()) end,
	function() return AiUpgradeTo(AiGuardTower()) end,
	function() return AiUpgradeTo(AiGuardTower()) end,	
	function() return AiUpgradeTo(AiBestCityCenter()) end,
	function() return AiWait(AiBestCityCenter()) end,
	
	function() return AiForce(0, {AiScout(), 1}) end,
	function() return AiForce(1, {AiSoldier(), 3, AiShooter(), 4, AiCavalry(), 4, AiCatapult(), 1}) 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 AiResearch(AiUpgradeArmor1()) end,
	function() return AiResearch(AiUpgradeMissile1()) end,
	function() return AiResearch(AiUpgradeArmor2()) end,
	function() return AiResearch(AiUpgradeMissile2()) end,
	
	function() return AiForce(1, {AiSoldier(), 3, AiShooter(), 4, AiCavalry(), 4, AiCatapult(), 1}) end,
	function() return AiWaitForce(1) end,
	function() return AiSleep(2000) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	
	function() return AiNeed(AiTemple()) end,
	function() return AiNeed(AiMageTower()) end,
	function() return AiResearch(AiUpgradeCavalryMage()) end,
	function() return AiResearch(AiCavalryMageSpell1()) end,
	function() return AiResearch(AiMageSpell5()) end,
	
	function() return AiForce(1, {AiSoldier(), 3, AiShooter(), 4, AiCavalry(), 4, AiCatapult(), 1, AiMage(), 2}, true) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	
	function() return AiLoop(hum_exp_11a_loop_funcs, stratagus.gameData.AIState.loop_index) end,
}

local hum_exp_11b_funcs = {
	function() return AiSet(AiWorker(), 1) end,
	function() return AiNeed(AiCityCenter()) end,
	function() return AiNeed(AiLumberMill()) end,
	function() return AiNeed(AiBarracks()) end,
	function() return AiNeed(AiBlacksmith()) end,
	function() return AiNeed(AiTower()) end,
	function() return AiNeed(AiTower()) end,
	function() return AiUpgradeTo(AiGuardTower()) end,
	function() return AiUpgradeTo(AiGuardTower()) end,	
	function() return AiResearch(AiUpgradeWeapon1()) end,
	function() return AiResearch(AiUpgradeArmor1()) end,
	function() return AiResearch(AiUpgradeMissile1()) end,
	
	function() return AiSet(AiWorker(), 8) end,
	function() return AiWait(AiWorker()) end,
	function() return AiForce(1, {AiSoldier(), 7, AiShooter(), 5}) end,
	function() return AiSleep(1500) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	
	function() return AiForce(1, {AiSoldier(), 6, AiShooter(), 4, AiCatapult(), 1}, true) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,

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

function AiHumanExp11a() return AiLoop(hum_exp_11a_funcs, stratagus.gameData.AIState.index) end
function AiHumanExp11b() return AiLoop(hum_exp_11b_funcs, stratagus.gameData.AIState.index) end
DefineAi("hum-exp-11a", "*", "hum-exp-11a", AiHumanExp11a)
DefineAi("hum-exp-11b", "*", "hum-exp-11b", AiHumanExp11b)

--Units
DefineAllowNormalHumanUnits("AAAAAAAAAAAAAAAA")
DefineAllowExtraHumanUnits("FFFFFFFFFFFFFFFF")
DefineAllowNormalOrcUnits("AAAAAAAAAAAAAAAA")
DefineAllowExtraOrcUnits("FFFFFFFFFFFFFFFF")
DefineAllowSpecialUnits("FFFFFFFFFFFFFFFF")
DefineAllowHumanAlways()
DefineAllowOrcAlways()
DefineAllow("upgrade-holy-vision", "RRRRRRRRRRRRRRRR")
DefineAllow("upgrade-healing", "RRRRRRRRRRRRRRRR")
DefineAllow("upgrade-exorcism", "RRRRRRRRRRRRRRRR")


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