IncludeScript("base_ctf");
IncludeScript("base_respawnturret")
IncludeScript("base_location")

--startup script
function startup()
    enabled_teams = { Team.kBlue, Team.kRed }
	SetPlayerLimit(Team.kBlue, 0)
	SetPlayerLimit(Team.kRed, 0)
	SetPlayerLimit(Team.kYellow, -1)
	SetPlayerLimit(Team.kGreen, -1)
	
	-- disable civilians
	for index, iteam in ipairs( enabled_teams ) do
	   local team = GetTeam(iteam)
	   team:SetClassLimit(Player.kCivilian, -1)
	end
end

--spy-only teleporter configuration
spytele = trigger_ff_script:new({ team = Team.kUnassigned, allowdisguised=false })

function spytele:allowed( allowed_entity )
	if IsPlayer( allowed_entity ) then
		
		local player = CastToPlayer( allowed_entity )
		
		if player:GetClass() == 8 then
			return EVENT_ALLOWED
		end
		
		if self.allowdisguised then
			if player:IsDisguised() and player:GetDisguisedTeam() == self.team then
				return EVENT_ALLOWED
			end
		end
	end
	return EVENT_DISALLOWED
end

--changing location for spytele
location_bluespytele = location_info:new({ text = "Corridor", team = Team.kBlue })
function location_bluespytele:allowed( allowed_entity )
	if IsPlayer( allowed_entity ) then
		
		local player = CastToPlayer( allowed_entity )
		
		if player:GetClass() == 8 then
			return EVENT_ALLOWED
		end
		
		if self.allowdisguised then
			if player:IsDisguised() and player:GetDisguisedTeam() == self.team then
				return EVENT_ALLOWED
			end
		end
	end
	return EVENT_DISALLOWED
end
location_redspytele = location_info:new({ text = "Corridor", team = Team.kRed })
function location_redspytele:allowed( allowed_entity )
	if IsPlayer( allowed_entity ) then
		
		local player = CastToPlayer( allowed_entity )
		
		if player:GetClass() == 8 then
			return EVENT_ALLOWED
		end
		
		if self.allowdisguised then
			if player:IsDisguised() and player:GetDisguisedTeam() == self.team then
				return EVENT_ALLOWED
			end
		end
	end
	return EVENT_DISALLOWED
end
--What if the player attempting to use the teleporter isn't a spy?
function spytele:onfailtouch( touch_entity )
	if IsPlayer( touch_entity ) then
		local player = CastToPlayer( touch_entity )
		BroadCastMessageToPlayer( player, "Only spies can use the teleport pad!" )
	end
end

--locations
location_yard = location_info:new({ text = "#FF_LOCATION_YARD", team = Team.kUnassigned })
location_bluerespawn = location_info:new({ text = "#FF_LOCATION_RESPAWN", team = Team.kBlue })
location_redrespawn = location_info:new({ text = "#FF_LOCATION_RESPAWN", team = Team.kRed })
location_bluecorridor = location_info:new({ text = "Corridor", team = Team.kBlue })
location_redcorridor = location_info:new({ text = "Corridor", team = Team.kRed })
location_bluebasement = location_info:new({ text = "#FF_LOCATION_UNDERGROUND", team = Team.kBlue })
location_redbasement = location_info:new({ text = "#FF_LOCATION_UNDERGROUND", team = Team.kRed })
location_blueflag = location_info:new({ text = "#FF_LOCATION_FLAGROOM", team = Team.kBlue })
location_redflag = location_info:new({ text = "#FF_LOCATION_FLAGROOM", team = Team.kRed })
location_bluebase = location_info:new({ text = "#FF_LOCATION_BASE", team = Team.kBlue })
location_redbase = location_info:new({ text = "#FF_LOCATION_BASE", team = Team.kRed })
location_bluebalcony = location_info:new({ text = "#FF_LOCATION_BALCONY", team = Team.kBlue })
location_redbalcony = location_info:new({ text = "#FF_LOCATION_BALCONY", team = Team.kRed })
location_bluespiral = location_info:new({ text = "#FF_LOCATION_SPIRAL", team = Team.kBlue })
location_redspiral = location_info:new({ text = "#FF_LOCATION_SPIRAL", team = Team.kRed })
location_bluecappoint = location_info:new({ text = "Capture Point", team = Team.kBlue })
location_redcappoint = location_info:new({ text = "Capture Point", team = Team.kRed })