--	Stratagus Map - Single player campaign

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

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

AddTrigger(
   function() return IfNearUnit("this", "==", 1, "unit-double-head", "unit-circle-of-power") end,
   function() return ActionVictory() end)
AddTrigger(
  function() return GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-double-head") == 0 and
    GetPlayerData(3, "UnitTypesCount", "unit-double-head") == 0 end,
   function() return ActionDefeat() 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-ranger", "unit-ballista",
	"unit-elven-lumber-mill", "upgrade-arrow1", "upgrade-arrow2",
	"upgrade-ranger", "upgrade-longbow", "upgrade-ranger-scouting", "upgrade-ranger-marksmanship",
	"unit-human-blacksmith", "upgrade-sword1", "upgrade-human-shield1", "upgrade-ballista1",
	"upgrade-sword2", "upgrade-human-shield2", "upgrade-ballista2",
	"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",
	"unit-stables", "unit-knight"
}
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",
	"upgrade-berserker", "upgrade-light-axes", "upgrade-berserker-scouting", "upgrade-berserker-regeneration",
	"unit-orc-blacksmith", "upgrade-battle-axe1", "upgrade-orc-shield1", "upgrade-catapult1",
	"upgrade-battle-axe2", "upgrade-orc-shield2", "upgrade-catapult2",
	"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",
	"unit-ogre-mound", "unit-ogre"
}
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_06_loop_funcs = {
	function() DebugMessage("AI looping"); return false end,
	function() return AiSleep(65535) end,
	function() stratagus.gameData.AIState.loop_index[1 + AiPlayer()] = 0; return false; end,
}

local orc_06_funcs = {
	function() return AiSet(AiWorker(), 2) end,
	function() return AiSet(AiTanker(), 1) end,
	function() return AiLoop(orc_06_loop_funcs, stratagus.gameData.AIState.loop_index) end,
}

function AiOrc06() return AiLoop(orc_06_funcs, stratagus.gameData.AIState.index) end
DefineAi("orc-06", "*", "orc-06", AiOrc06)

-- Map

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