--	Stratagus Map - Single player campaign

Load("campaigns/orc-exp/levelx07o_c2.sms")

Briefing(
  title,
  objectives,
  "../campaigns/orc/interface/introscreen5.png",
  "campaigns/orc-exp/levelx07o.txt",
  {"campaigns/orc-exp/levelx07o-intro1.wav",
   "campaigns/orc-exp/levelx07o-intro2.wav",
   "campaigns/orc-exp/levelx07o-intro3.wav"}
)

-- FIXME: Check if units are destroyed.
AddTrigger(

  function() return GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-orc-shipyard") >= 5 and
    GetPlayerData(2, "UnitTypesCount", "unit-battleship") == 0 and
    GetPlayerData(1, "UnitTypesCount", "unit-battleship") == 0 and
    GetPlayerData(2, "UnitTypesCount", "unit-human-destroyer") == 0 and
    GetPlayerData(1, "UnitTypesCount", "unit-human-destroyer") == 0 and
    GetPlayerData(2, "UnitTypesCount", "unit-human-transport") == 0 and
    GetPlayerData(1, "UnitTypesCount", "unit-human-transport") == 0 end,
  function() return ActionVictory() end)

AddTrigger(
  function() return GetPlayerData(GetThisPlayer(), "TotalNumUnits") == 0 end,
  function() return ActionDefeat() end)

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

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

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

local orc_exp_07a_funcs = {
	function() return AiSet(AiWorker(), 6) end,
	function() return AiSet(AiTanker(), 2) end,
	function() return AiResearch(AiUpgradeShipArmor1()) end,
	function() return AiResearch(AiUpgradeShipCannon1()) end,
	function() return AiForce(1, {AiDestroyer(), 3, AiBattleship(), 1}) end,
	function() return AiSleep(10000) end,
	function() return AiForce(2, {AiFlyer(), 3}) end,
	function() return AiWaitForce(2) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(2) end,
	function() return AiSleep(8000) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	
	function() return AiResearch(AiUpgradeShipArmor2()) end,
	function() return AiResearch(AiUpgradeShipCannon2()) end,
	function() return AiSleep(3500) end,
	function() return AiForce(1, {AiDestroyer(), 3, AiBattleship(), 1}) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiSleep(3500) end,
	function() return AiForce(1, {AiDestroyer(), 3, AiBattleship(), 1}) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiSleep(3500) end,
	
	function() return AiLoop(orc_exp_07a_loop_funcs, stratagus.gameData.AIState.loop_index) end,
}

local orc_exp_07b_funcs = {
	function() return AiNeed(AiCityCenter()) end,
	function() return AiNeed(AiLumberMill()) end,
	function() return AiNeed(AiBarracks()) end,
	function() return AiSet(AiWorker(), 8) end,
	function() return AiWait(AiWorker()) end,
	
	function() return AiNeed(AiBlacksmith()) end,
	function() return AiForce(1, {AiSoldier(), 4, AiShooter(), 3}) end,
	function() return AiWaitForce(1) end,
	function() return AiNeed(AiTower()) end,
	function() return AiNeed(AiTower()) end,
	function() return AiUpgradeTo(AiGuardTower()) end,
	function() return AiUpgradeTo(AiGuardTower()) end,
	function() return AiSleep(2000) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	
	function() return AiResearch(AiUpgradeWeapon1()) end,	
	function() return AiSet(AiWorker(), 10) end,
	function() return AiWait(AiWorker()) end,
	function() return AiUpgradeTo(AiBetterCityCenter()) end,
	function() return AiForce(1, {AiSoldier(), 4, AiShooter(), 3}) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	
	function() return AiSleep(2000) end,
	function() return AiResearch(AiUpgradeMissile1()) end,
	function() return AiNeed(AiStables()) end,
	function() return AiResearch(AiUpgradeArmor1()) end,
	function() return AiNeed(AiBarracks()) end,
	
	function() return AiLoop(orc_exp_07b_loop_funcs, stratagus.gameData.AIState.loop_index) end,
}

function AiOrcExp07a() return AiLoop(orc_exp_07a_funcs, stratagus.gameData.AIState.index) end
function AiOrcExp07b() return AiLoop(orc_exp_07b_funcs, stratagus.gameData.AIState.index) end
DefineAi("orc-exp-7a", "*", "orc-exp-7a", AiOrcExp07a)
DefineAi("orc-exp-7b", "*", "orc-exp-7b", AiOrcExp07b)

Load("campaigns/orc-exp/levelx07o.sms")
