--	Stratagus Map - Single player campaign

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

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

-- FIXME: Check if units are destroyed.
AddTrigger(
  function() return GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-quick-blade") == 1 and
    GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-fad-man") == 1 and
    GetNumOpponents(GetThisPlayer()) == 0 end,
  function() return ActionVictory() end)

AddTrigger(
  function() return GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-quick-blade") == 0 and
    GetPlayerData(6, "UnitTypesCount", "unit-quick-blade") == 0 end,
  function() return ActionDefeat() end)

AddTrigger(
  function() return GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-fad-man") == 0 and
    GetPlayerData(1, "UnitTypesCount", "unit-fad-man") == 0 end,
  function() return ActionDefeat() 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()
DefineAllow("unit-dragon", "FFFFFFFFFFFFFFFF")
DefineAllow("upgrade-eye-of-kilrogg", "RRRRRRRRRRRRRRRR")
DefineAllow("upgrade-bloodlust", "RRRRRRRRRRRRRRRR")
DefineAllow("unit-dragon-roost", "FFFFFFFFFFFFFFFF")

local orc_exp_02_loop_funcs = {
	function() DebugPrint("Looping !\n") return false end,
	function() return AiSleep(500) end,
	function() return AiForce(1, {AiSoldier(), 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 orc_exp_02_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(1, {AiSoldier(), 8, AiShooter(), 7}) end,
	function() return AiSleep(3000) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	
	function() return AiNeed(AiBlacksmith()) end,
	function() return AiNeed(AiCityCenter()) end,
	
	function() return AiNeed(AiTower()) end,
	function() return AiNeed(AiTower()) end,
	function() return AiUpgradeTo(AiGuardTower()) end,
	function() return AiUpgradeTo(AiGuardTower()) end,
	function() return AiNeed(AiTower()) end,
	function() return AiNeed(AiTower()) end,
	function() return AiUpgradeTo(AiGuardTower()) end,
	function() return AiUpgradeTo(AiGuardTower()) end,
	
	function() return AiNeed(AiBarracks()) end,
	function() return AiNeed(AiBarracks()) end,
	
	function() return AiForce(1, {AiSoldier(), 5, AiShooter(), 5, AiCatapult(), 2}, true) end,
	function() return AiSleep(3000) end,
	function() return AiWaitForce(1) 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 AiLoop(orc_exp_02_loop_funcs, stratagus.gameData.AIState.loop_index) end,
}

function AiOrcExp02() return AiLoop(orc_exp_02_funcs, stratagus.gameData.AIState.index) end
DefineAi("orc-exp-2", "*", "orc-exp-2", AiOrcExp02) 

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