--[[
Don't edit or remove this comment block! It is used by the editor to store information since i'm too lazy to write a good LUA parser... -Haz
SETTINGS
RestrictedEnhancements=
RestrictedCategories=
END
--]]

local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
local ScenarioFramework = import('/lua/ScenarioFramework.lua')

--units to be restricted
local NAVALbuildRestriction = categories.NAVAL + categories.ANTINAVY


function OnPopulate()
	ScenarioUtils.InitializeArmies()
	local tblArmy = ListArmies()
	for index,army in tblArmy do
	
	end
end



function OnStart(self)
	--delete all units on the water layers except air units every 1 second
	ForkThread(function()
		while true do
			WaitSeconds(1)
			killUnitsOnLayer({'Water','Seabed','Sub','AIR'})
		end
	end)
end

--get all units on the map
allUnits = function()
     local xmapsize = ScenarioInfo.size[1]
     local ymapsize = ScenarioInfo.size[2]
     local mapRect = {x0 = 0, x1 = xmapsize, y0 = 0, y1 = ymapsize}
     units = GetUnitsInRect(mapRect) 
	 return units
end

--delete all units on a layer exept those containing the exception categories
killUnitsOnLayer = function(layers,exceptions) 
	--get all units on the map
	local units = allUnits()
	--if there are units on the map
	if units and table.getn(units) > 0 then
		for index,unit in units do 
			local delete = false
			
			--is the unit on one of the specified layers?
			for index,layer in layers do 
				if unit:GetCurrentLayer() == layer then
					delete = true
			
				end
			end
			
			--if the unit is in one of the layers and in no exception category then kill it
			if  delete == true then
				if unit and not unit:IsDead() then
					unit:Kill()
				end
			end
		end
	end
end

