--	Stratagus Map - Single player campaign

Load("campaigns/human/level02h_c2.sms")

Briefing(
  title,
  objectives,
  "../campaigns/human/interface/introscreen1.png",
  "campaigns/human/level02h.txt",
  {"campaigns/human/level02h-intro1.wav",
   "campaigns/human/level02h-intro2.wav"}
)

local cycle2Win = 120
AddTrigger(
  function()
    return ((GetPlayerData(6, "UnitTypesCount", "unit-ranger") == 0 and
             GetPlayerData(6, "UnitTypesCount", "unit-archer") == 0) and
            (IfRescuedNearUnit("this", ">=", 1, "unit-ranger", "unit-circle-of-power") or
             IfRescuedNearUnit("this", ">=", 1, "unit-archer", "unit-circle-of-power"))) end,
  function()
	if (cycle2Win == 120) then
		PlaySound("rescue (human)")
	end
	cycle2Win = cycle2Win - 1
	if (cycle2Win <= 0) then
		ActionVictory() 
		return false
	end
	
  return true end)

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

--Units
local allowedHumanUnits = {"unit-farm",
	"unit-town-hall", "unit-peasant",
	"unit-human-barracks", "unit-footman", "unit-archer",
	"unit-elven-lumber-mill", "upgrade-arrow1"
}
local allowedOrcUnits = {"unit-grunt", "unit-axethrower"}
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")


Load("campaigns/human/level02h.sms")
