Post the event code. Did you make it parallel process?
@Zeriab:
Still haven't changed it, since the other day. The virtual map is loaded into $game_map and is being access by any Game_Character sub-class. I think there is a bug. Just like I said, I didn't fix it yet. Ignore $lag, I use it to write out "Hi" when the algorythm is executed to see the difference between that case and the case where it isn't. It works 8-way, BTW.
#==============================================================================
# Virtual_Map
#==============================================================================
class Virtual_Map
def initialize
@matrix = Table.new($game_map.width, $game_map.height)
object = Game_Character.new
for i in 0...$game_map.width
for j in 0...$game_map.height
res = 0
res += 0x01 if object.v_passable?(i, j, 2)
res += 0x02 if object.v_passable?(i, j, 4)
res += 0x04 if object.v_passable?(i, j, 6)
res += 0x08 if object.v_passable?(i, j, 8)
@matrix[i, j] = res
end
end
end
def find_path(object, dest_x, dest_y)
return if object.x == dest_x and object.y == dest_y
x = object.x
y = object.y
st_dir = []
if object.passable?(x, y, 2)
st_dir.push(2)
st_dir.push(1) if object.passable?(x, y+1, 4)
st_dir.push(3) if object.passable?(x, y+1, 6)
end
if object.passable?(x, y, 4)
st_dir.push(4)
st_dir.push(1) if object.passable?(x-1, y, 2)
st_dir.push(7) if object.passable?(x-1, y, 8)
end
if object.passable?(x, y, 6)
st_dir.push(6)
st_dir.push(3) if object.passable?(x+1, y, 2)
st_dir.push(9) if object.passable?(x+1, y, 8)
end
if object.passable?(x, y, 8)
st_dir.push(8)
st_dir.push(7) if object.passable?(x, y-1, 4)
st_dir.push(9) if object.passable?(x, y-1, 6)
end
st_dir |= st_dir
return [] if st_dir == []
coos = [[x, y, 0]]
for i in st_dir
case i
when 1 then coos.push([x-1, y+1, 10-i])
when 2 then coos.push([x, y+1, 10-i])
when 3 then coos.push([x+1, y+1, 10-i])
when 4 then coos.push([x-1, y, 10-i])
when 6 then coos.push([x+1, y, 10-i])
when 7 then coos.push([x-1, y-1, 10-i])
when 8 then coos.push([x, y-1, 10-i])
when 9 then coos.push([x+1, y-1, 10-i])
end
end
path = []
next_x, next_y = dest_x, dest_y
coos.reverse!
coos.size.times do
for i in 0...coos.size
if coos[i][0] == next_x and coos[i][1] == next_y
case coos[i][2]
when 1
next_x -= 1
next_y += 1
when 2
next_y += 1
when 3
next_x += 1
next_y += 1
when 4
next_x -= 1
when 6
next_x += 1
when 7
next_x -= 1
next_y -= 1
when 8
next_y -= 1
when 9
next_x += 1
next_y -= 1
end
path.push(coos[i][2])
coos[i] = nil
break
end
end
coos.compact!
break if next_x == x and next_y == y
end
for i in 0...path.size
path[i] = 10 - path[i]
end
$lag = "Hi"
return path
end
end
#==============================================================================
# Game_Character
#==============================================================================
class Game_Character
def v_passable?(x, y, d)
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
return false unless $game_map.valid?(new_x, new_y)
return false unless $game_map.v_passable?(x, y, d, self)
return true
end
end
#==============================================================================
# Game_Map
#==============================================================================
class Game_Map
attr_reader :vmap
alias setup_vmap_later setup
def setup(id)
setup_vmap_later(id)
@vmap = Virtual_Map.new
end
def v_passable?(x, y, d, self_event = nil)
return false unless valid?(x, y)
bit = (1 << (d / 2 - 1)) & 0x0f
for i in [2, 1, 0]
tile_id = data[x, y, i]
if tile_id == nil
return false
elsif @passages[tile_id] & bit != 0
return false
elsif @passages[tile_id] & 0x0f == 0x0f
return false
elsif @priorities[tile_id] == 0
return true
end
end
return true
end
end