--	Stratagus Map - Single player campaign

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

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

AddTrigger(
  function() return GetPlayerData(2, "UnitTypesCount", "unit-orc-shipyard") == 0 and
    GetPlayerData(3, "UnitTypesCount", "unit-orc-shipyard") == 0 and
    GetPlayerData(4, "UnitTypesCount", "unit-orc-shipyard") == 0 and
    GetPlayerData(7, "UnitTypesCount", "unit-orc-shipyard") == 0 and
    GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-human-shipyard") >= 3 end,
  function() return ActionVictory() end)
AddTrigger(
  function() return GetPlayerData(GetThisPlayer(), "TotalNumUnits") == 0 end,
  function() return ActionDefeat() end)

local hum_exp_05a_loop_funcs = {
	function() DebugPrint("Looping !\n") return false end,
	function() return AiSleep(2000) end,
	function() return AiForce(1, {AiSoldier(), 4}) 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_05b_loop_funcs = {
	function() DebugPrint("Looping !\n") return false end,
	function() return AiForce(1, {AiSoldier(), 6, AiShooter(), 5, AiCavalry(), 4, AiCatapult(), 2}) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiSleep(6000) end,
	function() return AiForce(1, {AiSoldier(), 6, AiShooter(), 5, AiCavalry(), 4, AiCatapult(), 2}) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiSleep(10000) end,
	function() stratagus.gameData.AIState.loop_index[1 + AiPlayer()] = 0; return false end,
}

local hum_exp_05c_loop_funcs = {
	function() DebugPrint("Looping !\n") return false end,
	function() return AiForce(1, {AiDestroyer(), 3, AiBattleship(), 2}) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiSleep(30000) end,
	function() stratagus.gameData.AIState.loop_index[1 + AiPlayer()] = 0; return false end,
}

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

local hum_exp_05a_funcs = {
	function() return AiSet(AiWorker(), 1) end,
	function() return AiWait(AiWorker()) end,
	function() return AiForce(0, {AiSoldier(), 1}) end,
	function() return AiSleep(3000) end,
	function() return AiSet(AiWorker(), 7) end,

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

local hum_exp_05b_funcs = {
	function() return AiNeed(AiCityCenter()) end,
	function() return AiNeed(AiBarracks()) end,
	function() return AiNeed(AiLumberMill()) end,
	function() return AiSet(AiWorker(), 5) end,
	function() return AiWait(AiWorker()) end,
	
	function() return AiNeed(AiBlacksmith()) end,
	function() return AiForce(0, {AiSoldier(), 1, AiShooter(), 1}) 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 AiUpgradeTo(AiBetterCityCenter()) end,
	function() return AiWait(AiBetterCityCenter()) end,
	function() return AiForce(1, {AiSoldier(), 2, AiShooter(), 1}) end,
	function() return AiWaitForce(1) end,
	function() return AiSleep(1000) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,

	function() return AiSleep(2000) end,
	function() return AiResearch(AiUpgradeArmor1()) end,
	function() return AiNeed(AiStables()) end,
	function() return AiResearch(AiUpgradeMissile1()) end,
	
	function() return AiNeed(AiBarracks()) end,
	function() return AiForce(0, {AiSoldier(), 1, AiShooter(), 1, AiCavalry(), 1, AiCatapult(), 1}) end,

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

local hum_exp_05c_funcs = {
	function() return AiSet(AiWorker(), 1) end,
	function() return AiNeed(AiCityCenter()) end,
	function() return AiNeed(AiBarracks()) end,
	function() return AiNeed(AiHarbor()) end,
	function() return AiUpgradeTo(AiBetterCityCenter()) end,
	function() return AiNeed(AiFoundry()) end,
	function() return AiResearch(AiMageSpell3()) end,
	
	function() return AiResearch(AiUpgradeShipArmor1()) end,
	function() return AiResearch(AiUpgradeShipCannon1()) end,
	function() return AiResearch(AiUpgradeShipArmor2()) end,
	function() return AiResearch(AiUpgradeShipCannon2()) end,
	
	function() return AiSet(AiWorker(), 8) end,
	function() return AiSet(AiTanker(), 3) end,
	function() return AiWait(AiWorker()) end,
	function() return AiSleep(7000) end,

	function() return AiForce(1, {AiDestroyer(), 3, AiBattleship(), 2}) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiForce(0, {AiSoldier(), 1, AiShooter(), 2, AiCavalry(), 4, AiMage(), 2, AiCatapult(), 3}) end,
	function() return AiSleep(6000) end,
	
	function() return AiLoop(hum_exp_05c_loop_funcs, stratagus.gameData.AIState.loop_index) end,
}

local hum_exp_05d_funcs = {
	function() return AiNeed(AiCityCenter()) end,
	function() return AiNeed(AiLumberMill()) end,
	function() return AiNeed(AiBlacksmith()) end,
	function() return AiNeed(AiBarracks()) end,
	function() return AiNeed(AiBarracks()) end,
	function() return AiNeed(AiHarbor()) end,
	function() return AiNeed(AiHarbor()) end,
	function() return AiUpgradeTo(AiBetterCityCenter()) end,
	
	function() return AiNeed(AiStables()) end,
	function() return AiNeed(AiFoundry()) end,
	function() return AiResearch(AiUpgradeWeapon1()) end,
	function() return AiResearch(AiUpgradeArmor1()) end,
	function() return AiResearch(AiUpgradeMissile1()) end,
	function() return AiResearch(AiUpgradeShipArmor1()) end,
	function() return AiResearch(AiUpgradeShipCannon1()) end,
	function() return AiResearch(AiUpgradeWeapon2()) end,
	function() return AiResearch(AiUpgradeArmor2()) end,
	
	function() return AiSet(AiWorker(), 9) end,
	function() return AiSet(AiTanker(), 3) end,
	function() return AiWait(AiWorker()) end,
	function() return AiSleep(7000) end,
	function() return AiForce(0, {AiDestroyer(), 3, AiBattleship(), 1, AiSubmarine(), 2}) end,
	function() return AiForce(1, {AiSoldier(), 3, AiShooter(), 3, AiTransporter(), 1}) end,
	function() return AiForce(2, {AiShooter(), 1, AiCavalry(), 3, AiCatapult(), 2, AiTransporter(), 1}) end,
	function() return AiWaitForce(1) end,
	function() return AiWaitForce(2) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(2) end,
	function() return AiSleep(3000) end,

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

function AiHumanExp05a() return AiLoop(hum_exp_05a_funcs, stratagus.gameData.AIState.index) end
function AiHumanExp05b() return AiLoop(hum_exp_05b_funcs, stratagus.gameData.AIState.index) end
function AiHumanExp05c() return AiLoop(hum_exp_05c_funcs, stratagus.gameData.AIState.index) end
function AiHumanExp05d() return AiLoop(hum_exp_05d_funcs, stratagus.gameData.AIState.index) end
DefineAi("hum-exp-5a", "*", "hum-exp-5a", AiHumanExp05a) 
DefineAi("hum-exp-5b", "*", "hum-exp-5b", AiHumanExp05b)
DefineAi("hum-exp-5c", "*", "hum-exp-5c", AiHumanExp05c)
DefineAi("hum-exp-5d", "*", "hum-exp-5d", AiHumanExp05d)

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

DefineAllow("unit-gryphon-rider", "FFFFFFFFFFFFFFFF")
DefineAllow("unit-gryphon-aviary", "FFFFFFFFFFFFFFFF")


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