
Flagmaker = function()

end

CTFFLagtypes = {"ctflag", "ctflagra"}
CTbs = {"oilb"}
aiTicker = DateTime.Seconds(4) -- 0:4

function GetNearFlag (flag) -- function for flag trigger and capture
	--Media.DisplayMessage("Set Up Flag!","")
		local flagactors = Map.ActorsInCircle(flag.CenterPosition , WDist.FromCells(10), function(bld)	
			return  bld.Type == CTbs[1] or  bld.Type == CTbs[2] or  bld.Type == CTbs[3] or  bld.Type == CTbs[4] or  bld.Type == CTbs[5] or  bld.Type == CTbs[6] or  bld.Type == CTbs[7] or  bld.Type == CTbs[8] or  bld.Type == CTbs[9] or  bld.Type == CTbs[10] or  bld.Type == CTbs[11]or  bld.Type == CTbs[12] or  bld.Type == CTbs[13] or  bld.Type == CTbs[14] or  bld.Type == CTbs[15]or  bld.Type == CTbs[16] or  bld.Type == CTbs[17] or  bld.Type == CTbs[18]
		end)
	Trigger.OnEnteredProximityTrigger(flag.CenterPosition, WDist.FromCells(3), function(a, id)
		local mine = flag.Owner
		local yours = a.Owner
		if mine ~= yours and  mine.IsAlliedWith(yours) ~= true and yours ~= Player.GetPlayer("Neutral") and yours ~= Player.GetPlayer("Creeps") and Actor.CruiseAltitude(a.Type) == 0 and a.Type ~= "camera" and a.Type ~= "camera.paradrop" and a.Type ~= "camera.spyplane" and a.MaxHealth ~= 17500 then
			flag.Owner = yours
			if flagactors ~= nil  then
				for i,v in ipairs(flagactors) do
					if v ~= nil then
						v.Owner = yours  -- Desync solved?
					end
				end 
			end
		end
	end)	
end

num = 0
function joinMyTables(t1, t2) -- simple join tables
	for k,v in ipairs(t2) do
		table.insert(t1, v)
		num = num + 1
	end 
	return t1
end


GetandsetFlags = function()
	CTFlags = {}
	Trigger.AfterDelay(DateTime.Seconds(1), function() -- set up Flags
		local neut = Player.GetPlayer("Neutral")
		for i=1,#CTFFLagtypes do
			local T1 = neut.GetActorsByType(CTFFLagtypes[i])
			if T1 ~= nil then
				joinMyTables(CTFlags, T1)			
			end
		end
	end)
	
	Trigger.AfterDelay(DateTime.Seconds(2), function()	 -- fuse flags
		for k,v in ipairs(CTFlags) do
			GetNearFlag(v)
		end
		return CTFlags
	end)
end

