--	Stratagus Map - Single player campaign

Load("campaigns/orc/level05o_c2.sms")

Briefing(
  title,
  objectives,
  "../campaigns/orc/interface/introscreen2.png",
  "campaigns/orc/level05o.txt",
  {"campaigns/orc/level05o-intro1.wav"}
)

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

--Units
local allowedHumanUnits = {"unit-farm",
	"unit-town-hall", "unit-keep", "unit-peasant",
	"unit-human-barracks", "unit-footman", "unit-archer", "unit-ballista",
	"unit-elven-lumber-mill", "upgrade-arrow1", "upgrade-arrow2",
	"unit-human-blacksmith", "upgrade-sword1", "upgrade-human-shield1", "upgrade-ballista1",
	"unit-human-watch-tower", "unit-human-guard-tower", "unit-human-cannon-tower",
	"unit-human-shipyard", "unit-human-oil-tanker", "unit-human-destroyer", "unit-human-transport",
	"unit-human-oil-platform", "unit-human-refinery",
	"unit-human-foundry", "upgrade-human-ship-cannon1", "upgrade-human-ship-armor1",
	"unit-inventor", "unit-balloon"
}
local allowedOrcUnits = {"unit-pig-farm",
	"unit-great-hall", "unit-stronghold", "unit-peon",
	"unit-orc-barracks", "unit-grunt", "unit-axethrower", "unit-berserker", "unit-catapult",
	"unit-troll-lumber-mill", "upgrade-throwing-axe1", "upgrade-throwing-axe2",
	"unit-orc-blacksmith", "upgrade-battle-axe1", "upgrade-orc-shield1", "upgrade-catapult1",
	"unit-orc-watch-tower", "unit-orc-guard-tower", "unit-orc-cannon-tower",
	"unit-orc-shipyard", "unit-orc-oil-tanker", "unit-orc-destroyer", "unit-orc-transport",
	"unit-orc-oil-platform", "unit-orc-refinery",
	"unit-orc-foundry", "upgrade-orc-ship-cannon1", "upgrade-orc-ship-armor1",
	"unit-alchemist", "unit-zeppelin"
}
local function DefineAllowTable(table, flags)
	for i, unitName in ipairs(table) do
		DefineAllow(unitName, flags)
	end
end
DefineAllowNormalHumanUnits("FFFFFFFFFFFFFFFF")
DefineAllowExtraHumanUnits("FFFFFFFFFFFFFFFF")
DefineAllowNormalOrcUnits("FFFFFFFFFFFFFFFF")
DefineAllowExtraOrcUnits("FFFFFFFFFFFFFFFF")
DefineAllowSpecialUnits("FFFFFFFFFFFFFFFF")
DefineAllowHumanAlways()
DefineAllowOrcAlways()
DefineAllowTable(allowedHumanUnits, "AAAAAAAAAAAAAAAA")
DefineAllowTable(allowedOrcUnits, "AAAAAAAAAAAAAAAA")

-- AI

local orc_05_loop_funcs = {
	function() DebugMessage("AI looping"); return false end,
	function() return AiSleep(12000) end,
	function() return AiForce(2, {AiTransporter(), 1, AiSoldier(), 3, AiShooter(), 3}) end,
	function() return AiWaitForce(2) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(2) end,
	function() return AiSleep(12000) end,
	function() return AiForce(1, {AiDestroyer(), 3}) 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_05_funcs = {
	function() return AiSet(AiWorker(), 4) end,
    function() return AiSet(AiTanker(), 1) end,
    function() return AiForce(1, {AiDestroyer(), 3}) end,
	function() return AiForce(2, {AiTransporter(), 1, AiSoldier(), 3, AiShooter(), 3}) end,
	function() return AiSleep(6000) end,
	
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiSleep(3000) end,
	function() return AiWaitForce(2) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(2) end,
	function() return AiSleep(4000) end,
	function() return AiForce(2, {AiTransporter(), 1, AiSoldier(), 3, AiShooter(), 3}) end,
	function() return AiWaitForce(2) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(2) end,
	function() return AiSleep(4000) end,
	function() return AiForce(2, {AiTransporter(), 1, AiSoldier(), 3, AiShooter(), 3}) end,
	function() return AiWaitForce(2) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(2) end,

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

function AiOrc05() return AiLoop(orc_05_funcs, stratagus.gameData.AIState.index) end
DefineAi("orc-05", "*", "orc-05", AiOrc05)

-- Map

Load("campaigns/orc/level05o.sms")
