mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-07 21:24:59 +00:00
Optimised checking of map connections
This commit is contained in:
@@ -70,8 +70,8 @@ class PokemonMapFactory
|
|||||||
def getNewMap(playerX,playerY)
|
def getNewMap(playerX,playerY)
|
||||||
id = $game_map.map_id
|
id = $game_map.map_id
|
||||||
conns = MapFactoryHelper.getMapConnections
|
conns = MapFactoryHelper.getMapConnections
|
||||||
for conn in conns
|
if conns[id]
|
||||||
next if conn[0]!=id && conn[3]!=id
|
for conn in conns[id]
|
||||||
mapidB = nil
|
mapidB = nil
|
||||||
newx = 0
|
newx = 0
|
||||||
newy = 0
|
newy = 0
|
||||||
@@ -90,6 +90,7 @@ class PokemonMapFactory
|
|||||||
return [getMap(mapidB), newx, newy]
|
return [getMap(mapidB), newx, newy]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -116,7 +117,8 @@ class PokemonMapFactory
|
|||||||
@fixup = true
|
@fixup = true
|
||||||
id = $game_map.map_id
|
id = $game_map.map_id
|
||||||
conns = MapFactoryHelper.getMapConnections
|
conns = MapFactoryHelper.getMapConnections
|
||||||
for conn in conns
|
if conns[id]
|
||||||
|
for conn in conns[id]
|
||||||
if conn[0] == id
|
if conn[0] == id
|
||||||
mapA = getMap(conn[0])
|
mapA = getMap(conn[0])
|
||||||
newdispx = (conn[4] - conn[1]) * Game_Map::REAL_RES_X + mapA.display_x
|
newdispx = (conn[4] - conn[1]) * Game_Map::REAL_RES_X + mapA.display_x
|
||||||
@@ -126,7 +128,7 @@ class PokemonMapFactory
|
|||||||
mapB.display_x = newdispx if mapB.display_x != newdispx
|
mapB.display_x = newdispx if mapB.display_x != newdispx
|
||||||
mapB.display_y = newdispy if mapB.display_y != newdispy
|
mapB.display_y = newdispy if mapB.display_y != newdispy
|
||||||
end
|
end
|
||||||
elsif conn[3]==id
|
else
|
||||||
mapA = getMap(conn[3])
|
mapA = getMap(conn[3])
|
||||||
newdispx = (conn[1] - conn[4]) * Game_Map::REAL_RES_X + mapA.display_x
|
newdispx = (conn[1] - conn[4]) * Game_Map::REAL_RES_X + mapA.display_x
|
||||||
newdispy = (conn[2] - conn[5]) * Game_Map::REAL_RES_Y + mapA.display_y
|
newdispy = (conn[2] - conn[5]) * Game_Map::REAL_RES_Y + mapA.display_y
|
||||||
@@ -137,6 +139,7 @@ class PokemonMapFactory
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
@fixup = false
|
@fixup = false
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -230,30 +233,30 @@ class PokemonMapFactory
|
|||||||
def areConnected?(mapID1, mapID2)
|
def areConnected?(mapID1, mapID2)
|
||||||
return true if mapID1 == mapID2
|
return true if mapID1 == mapID2
|
||||||
conns = MapFactoryHelper.getMapConnections
|
conns = MapFactoryHelper.getMapConnections
|
||||||
for conn in conns
|
if conns[mapID1]
|
||||||
if (conn[0]==mapID1 && conn[3]==mapID2) ||
|
for conn in conns[mapID1]
|
||||||
(conn[0]==mapID2 && conn[3]==mapID1)
|
return true if conn[0] == mapID2 || conn[3] == mapID2
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
def getRelativePos(thisMapID, thisX, thisY, otherMapID, otherX, otherY)
|
def getRelativePos(thisMapID, thisX, thisY, otherMapID, otherX, otherY)
|
||||||
if thisMapID==otherMapID
|
if thisMapID == otherMapID # Both events share the same map
|
||||||
# Both events share the same map
|
|
||||||
return [otherX - thisX, otherY - thisY]
|
return [otherX - thisX, otherY - thisY]
|
||||||
end
|
end
|
||||||
conns = MapFactoryHelper.getMapConnections
|
conns = MapFactoryHelper.getMapConnections
|
||||||
for conn in conns
|
if conns[thisMapID]
|
||||||
if conn[0]==thisMapID && conn[1]==otherMapID
|
for conn in conns[thisMapID]
|
||||||
posX = thisX + conn[4] - conn[1] + otherX
|
if conn[0] == otherMapID
|
||||||
posY = thisY + conn[5] - conn[2] + otherY
|
|
||||||
return [posX,posY]
|
|
||||||
elsif conn[1]==thisMapID && conn[0]==otherMapID
|
|
||||||
posX = thisX + conn[1] - conn[4] + otherX
|
posX = thisX + conn[1] - conn[4] + otherX
|
||||||
posY = thisY + conn[2] - conn[5] + otherY
|
posY = thisY + conn[2] - conn[5] + otherY
|
||||||
return [posX, posY]
|
return [posX, posY]
|
||||||
|
else
|
||||||
|
posX = thisX + conn[4] - conn[1] + otherX
|
||||||
|
posY = thisY + conn[5] - conn[2] + otherY
|
||||||
|
return [posX, posY]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return [0, 0]
|
return [0, 0]
|
||||||
@@ -324,7 +327,8 @@ class PokemonMapFactory
|
|||||||
id = mapID
|
id = mapID
|
||||||
return [id, x, y] if getMapNoAdd(id).valid?(x, y)
|
return [id, x, y] if getMapNoAdd(id).valid?(x, y)
|
||||||
conns = MapFactoryHelper.getMapConnections
|
conns = MapFactoryHelper.getMapConnections
|
||||||
for conn in conns
|
if conns[id]
|
||||||
|
for conn in conns[id]
|
||||||
if conn[0] == id
|
if conn[0] == id
|
||||||
newX = x + conn[4] - conn[1]
|
newX = x + conn[4] - conn[1]
|
||||||
newY = y + conn[5] - conn[2]
|
newY = y + conn[5] - conn[2]
|
||||||
@@ -332,7 +336,7 @@ class PokemonMapFactory
|
|||||||
dims = MapFactoryHelper.getMapDims(conn[3])
|
dims = MapFactoryHelper.getMapDims(conn[3])
|
||||||
next if newX >= dims[0] || newY >= dims[1]
|
next if newX >= dims[0] || newY >= dims[1]
|
||||||
return [conn[3], newX, newY]
|
return [conn[3], newX, newY]
|
||||||
elsif conn[3]==id
|
else
|
||||||
newX = x + conn[1] - conn[4]
|
newX = x + conn[1] - conn[4]
|
||||||
newY = y + conn[2] - conn[5]
|
newY = y + conn[2] - conn[5]
|
||||||
next if newX < 0 || newY < 0
|
next if newX < 0 || newY < 0
|
||||||
@@ -341,6 +345,7 @@ class PokemonMapFactory
|
|||||||
return [conn[0], newX, newY]
|
return [conn[0], newX, newY]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -417,27 +422,35 @@ module MapFactoryHelper
|
|||||||
if !@@MapConnections
|
if !@@MapConnections
|
||||||
@@MapConnections = []
|
@@MapConnections = []
|
||||||
conns = load_data("Data/map_connections.dat")
|
conns = load_data("Data/map_connections.dat")
|
||||||
for i in 0...conns.length
|
conns.each do |conn|
|
||||||
conn = conns[i]
|
# Ensure both maps in a connection are valid
|
||||||
v = getMapEdge(conn[0],conn[1])
|
dimensions = getMapDims(conn[0])
|
||||||
dims = getMapDims(conn[0])
|
next if dimensions[0] == 0 || dimensions[1] == 0
|
||||||
next if dims[0]==0 || dims[1]==0
|
dimensions = getMapDims(conn[3])
|
||||||
if conn[1]=="N" || conn[1]=="S"
|
next if dimensions[0] == 0 || dimensions[1] == 0
|
||||||
|
# Convert first map's edge and coordinate to pair of coordinates
|
||||||
|
edge = getMapEdge(conn[0], conn[1])
|
||||||
|
case conn[1]
|
||||||
|
when "N", "S"
|
||||||
conn[1] = conn[2]
|
conn[1] = conn[2]
|
||||||
conn[2] = v
|
conn[2] = edge
|
||||||
elsif conn[1]=="E" || conn[1]=="W"
|
when "E", "W"
|
||||||
conn[1] = v
|
conn[1] = edge
|
||||||
end
|
end
|
||||||
v = getMapEdge(conn[3],conn[4])
|
# Convert second map's edge and coordinate to pair of coordinates
|
||||||
dims = getMapDims(conn[3])
|
edge = getMapEdge(conn[3], conn[4])
|
||||||
next if dims[0]==0 || dims[1]==0
|
case conn[4]
|
||||||
if conn[4]=="N" || conn[4]=="S"
|
when "N", "S"
|
||||||
conn[4] = conn[5]
|
conn[4] = conn[5]
|
||||||
conn[5] = v
|
conn[5] = edge
|
||||||
elsif conn[4]=="E" || conn[4]=="W"
|
when "E", "W"
|
||||||
conn[4] = v
|
conn[4] = edge
|
||||||
end
|
end
|
||||||
@@MapConnections.push(conn)
|
# Add connection to arrays for both maps
|
||||||
|
@@MapConnections[conn[0]] = [] if !@@MapConnections[conn[0]]
|
||||||
|
@@MapConnections[conn[0]].push(conn)
|
||||||
|
@@MapConnections[conn[3]] = [] if !@@MapConnections[conn[3]]
|
||||||
|
@@MapConnections[conn[3]].push(conn)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return @@MapConnections
|
return @@MapConnections
|
||||||
@@ -445,10 +458,7 @@ module MapFactoryHelper
|
|||||||
|
|
||||||
def self.hasConnections?(id)
|
def self.hasConnections?(id)
|
||||||
conns = MapFactoryHelper.getMapConnections
|
conns = MapFactoryHelper.getMapConnections
|
||||||
for conn in conns
|
return conns[id] ? true : false
|
||||||
return true if conn[0]==id || conn[3]==id
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Gets the height and width of the map with id
|
# Gets the height and width of the map with id
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ class MapScreenScene
|
|||||||
conns=MapFactoryHelper.getMapConnections
|
conns=MapFactoryHelper.getMapConnections
|
||||||
@mapconns=[]
|
@mapconns=[]
|
||||||
for c in conns
|
for c in conns
|
||||||
@mapconns.push(c.clone)
|
@mapconns.push(c.clone) if !@mapconns.any? { |conn| conn[0] == c[0] && conn[3] == c[3] }
|
||||||
end
|
end
|
||||||
if $game_map
|
if $game_map
|
||||||
@currentmap=$game_map.map_id
|
@currentmap=$game_map.map_id
|
||||||
|
|||||||
Reference in New Issue
Block a user