-- Inca_tele.levelgen
function changeTeleportDest(teleporterId, dest)
	local teleporter = levelgen:findObjectById(teleporterId)
	
	if(teleporter ~= nil) then
		teleporter:clearDests()
		teleporter:addDest(dest)
	end
end

function onShipEnteredZone(ship, zone, zoneType, zoneId)
	local info = ship:getPlayerInfo()
	local team = info:getTeamIndex()
	
	if(zoneId == 1) then --when red team crosses this, change teleporter 2
		if(team == 2) then
			local x = -2040
			local y = 0
			changeTeleportDest(2, point.new(x, y))
		end
	elseif(zoneId == 3) then
		if(team == 1) then
			local x = 2040
			local y = 0
			changeTeleportDest(4, point.new(x, y))
		end
	end
end

function main()
	subscribe(Event.ShipEnteredZone)
end