-- Stratagus Map - Single player campaign

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

Briefing(
	title,
	objectives,
	"../campaigns/orc/interface/introscreen1.png",
	"campaigns/orc/level04o.txt",
	{"campaigns/orc/level04o-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)

local allowedHumanUnits = {"unit-farm",
	"unit-town-hall", "unit-peasant",
	"unit-human-barracks", "unit-footman", "unit-archer",
	"unit-elven-lumber-mill", "upgrade-arrow1", "upgrade-arrow2",
	"unit-human-watch-tower", "unit-human-guard-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"
}
local allowedOrcUnits = {"unit-pig-farm",
	"unit-great-hall", "unit-peon",
	"unit-orc-barracks", "unit-grunt", "unit-axethrower",
	"unit-troll-lumber-mill", "upgrade-throwing-axe1", "upgrade-throwing-axe2",
	"unit-orc-watch-tower", "unit-orc-guard-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"
}
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")

-- orc 04 campaign AI

local orc_04_loop_funcs = {
	function() DebugMessage("AI looping"); return false end,
	function() return AiSleep(19500) end,
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiSleep(19500) end,
	function() return AiForce(2, {AiTransporter(), 1, AiSoldier(), 5, AiShooter(), 1}) end,
	function() return AiForce(3, {AiTransporter(), 1, AiShooter(), 4}) end,
	function() return AiWaitForce(2) end,
	function() return AiWaitForce(3) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(2) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(3) end,
	function() stratagus.gameData.AIState.loop_index[1 + AiPlayer()] = 0; return false; end,
}

local orc_04_funcs = {
	function() return AiSetBuildDepots(false) end,
	function() return AiSet(AiWorker(), 4) end,
    function() return AiSet(AiTanker(), 1) end,
    function() return AiForce(1, {AiDestroyer(), 2}) end,
	function() return AiForce(2, {AiTransporter(), 1, AiSoldier(), 5, AiShooter(), 1}) end,
	function() return AiForce(3, {AiTransporter(), 1, AiShooter(), 4}) end,
	function() return AiSleep(27000) end,
	function() return AiWaitForce(2) end,
	function() return AiWaitForce(3) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(2) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(3) end,
	function() return AiSleep(15000) end,
	function() return AiForce(2, {AiTransporter(), 1, AiSoldier(), 5, AiShooter(), 1}) end,
	function() return AiForce(3, {AiTransporter(), 1, AiShooter(), 4}) end,
	function() return AiWaitForce(2) end,
	function() return AiWaitForce(3) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(2) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(3) end,
	function() return AiSleep(15000) end,
	
	function() return AiWaitForce(1) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(1) end,
	function() return AiSleep(19500) end,

	function() return AiForce(2, {AiTransporter(), 1, AiSoldier(), 5, AiShooter(), 1}) end,
	function() return AiForce(3, {AiTransporter(), 1, AiShooter(), 4}) end,
	function() return AiWaitForce(2) end,
	function() return AiWaitForce(3) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(2) end,
	function() DebugMessage("Attacking..."); return AiAttackWithForce(3) end,

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

function AiOrc04() return AiLoop(orc_04_funcs, stratagus.gameData.AIState.index) end
DefineAi("orc-04", "*", "orc-04", AiOrc04)


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