#==============================================================================
# â– Passability Mini Map
#------------------------------------------------------------------------------
# made by squall //
squall@loeher.zzn.com
# released on 20 December 2005
#==============================================================================
#==============================================================================
# â– Scene_Map
#------------------------------------------------------------------------------
#  draw the mini map
# @corner is the corner you want the mini map to be displayed in.
# 1 is upper left, 2 is upper right, 3 is bottom left and 4 is bottom right
#==============================================================================
class Scene_Map
alias main_passminimap main
alias update_passminimap update
alias transfer_passminimap transfer_player
#--------------------------------------------------------------------------
# â— initialize
#--------------------------------------------------------------------------
def initialize
@corner = 4 # 1 or 2 or 3 or 4
end
#--------------------------------------------------------------------------
# â— main
#--------------------------------------------------------------------------
def main
@mini_map = Map_Event.new(@corner)
main_passminimap
@mini_map.dispose
end
#--------------------------------------------------------------------------
# â— update
#--------------------------------------------------------------------------
def update
@mini_map.update
if $game_system.map_interpreter.running?
@mini_map.visible = false
elsif not $game_system.map_interpreter.running? and @mini_map.on?
@mini_map.visible = true
end
update_passminimap
end
#--------------------------------------------------------------------------
# â— transfer_player
#--------------------------------------------------------------------------
def transfer_player
transfer_passminimap
@mini_map.dispose
@mini_map = Map_Event.new(@corner)
end
end
#==============================================================================
# â– Map_Base
#------------------------------------------------------------------------------
#  Base class for mini maps
#==============================================================================
class Map_Base < Sprite
#--------------------------------------------------------------------------
# â— constants and instances
#--------------------------------------------------------------------------
PMP_VERSION = 5
OBJECT_ID = 1 # set the switch id for the object drawing autorisation
ACTIVATED_ID = 2 # set the switch id for the minimap display (on/off)
attr_reader :event
#--------------------------------------------------------------------------
# â— initialize
#--------------------------------------------------------------------------
def initialize(corner)
super(nil)
self.z = 8000
case corner
when 1
self.x = 16
self.y = 16
when 2
self.x = 640 - width - 16
self.y = 16
when 3
self.x = 16
self.y = 480 - height - 16
when 4
self.x = 640 - width - 16
self.y = 480 - height - 16
else
self.x = 16
self.y = 16
end
@draw_object = draw_object?
@event = Sprite.new
@event.x, @event.y, @event.z = self.x, self.y, self.z
@event.bitmap = Bitmap.new(160, 120)
@border = Sprite.new
@border.x, @border.y, @border.z = self.x - 8, self.y - 8, self.z
@border.bitmap = RPG::Cache.picture("mapback")
@temp_x = $game_player.real_x
@temp_y = $game_player.real_y
self.visible = on?
end
#--------------------------------------------------------------------------
# â— draw_object?
#--------------------------------------------------------------------------
def draw_object?
return $game_switches[OBJECT_ID]
end
#--------------------------------------------------------------------------
# â— minimap_on?
#--------------------------------------------------------------------------
def on?
return $game_switches[ACTIVATED_ID]
end
#--------------------------------------------------------------------------
# â— update
#--------------------------------------------------------------------------
def update
super
self.visible = on?
if self.src_rect.x < display_x
self.src_rect.x += 1
elsif self.src_rect.x > display_x
self.src_rect.x -= 1
end
if self.src_rect.y < display_y
self.src_rect.y += 1
elsif self.src_rect.y > display_y
self.src_rect.y -= 1
end
if @temp_x != $game_player.real_x or @temp_y != $game_player.real_y
@temp_x = $game_player.real_x
@temp_y = $game_player.real_y
refresh_event_map
end
if @draw_object != draw_object?
@draw_object = draw_object?
setup($game_map.map_id)
end
end
#--------------------------------------------------------------------------
# â— dispose
#--------------------------------------------------------------------------
def dispose
super
@event.dispose
@border.dispose
end
#--------------------------------------------------------------------------
# â— visible=
#--------------------------------------------------------------------------
def visible=(bool)
super
@event.visible = bool
@border.visible = bool
end
#--------------------------------------------------------------------------
# â— width
#--------------------------------------------------------------------------
def width
return 160
end
#--------------------------------------------------------------------------
# â— height
#--------------------------------------------------------------------------
def height
return 120
end
#--------------------------------------------------------------------------
# â— display_x
#--------------------------------------------------------------------------
def display_x
return $game_map.display_x / 16
end
#--------------------------------------------------------------------------
# â— display_y
#--------------------------------------------------------------------------
def display_y
return $game_map.display_y / 16
end
end
#==============================================================================
# â– Map_Passability
#------------------------------------------------------------------------------
# draws the mini map
#
#  thanks to Fanha Giang (aka fanha99) for the autotile drawing method
#==============================================================================
class Map_Passability < Map_Base
#--------------------------------------------------------------------------
# â— instances
#--------------------------------------------------------------------------
INDEX =
[
26, 27, 32, 33, 4, 27, 32, 33, 26, 5, 32, 33, 4, 5, 32, 33,
26, 27, 32, 11, 4, 27, 32, 11, 26, 5, 32, 11, 4, 5, 32, 11,
26, 27, 10, 33, 4, 27, 10, 33, 26, 5, 10, 33, 4, 5, 10, 33,
26, 27, 10, 11, 4, 27, 10, 11, 26, 5, 10, 11, 4, 5, 10, 11,
24, 25, 30, 31, 24, 5, 30, 31, 24, 25, 30, 11, 24, 5, 30, 11,
14, 15, 20, 21, 14, 15, 20, 11, 14, 15, 10, 21, 14, 15, 10, 11,
28, 29, 34, 35, 28, 29, 10, 35, 4, 29, 34, 35, 4, 29, 10, 35,
38, 39, 44, 45, 4, 39, 44, 45, 38, 5, 44, 45, 4, 5, 44, 45,
24, 29, 30, 35, 14, 15, 44, 45, 12, 13, 18, 19, 12, 13, 18, 11,
16, 17, 22, 23, 16, 17, 10, 23, 40, 41, 46, 47, 4, 41, 46, 47,
36, 37, 42, 43, 36, 5, 42, 43, 12, 17, 18, 23, 12, 13, 42, 43,
36, 41, 42, 47, 16, 17, 46, 47, 12, 17, 42, 47, 0, 1, 6, 7
]
X = [0, 1, 0, 1]
Y = [0, 0, 1, 1]
#--------------------------------------------------------------------------
# â— initialize
#--------------------------------------------------------------------------
def initialize(corner = 4)
super(corner)
temp = RPG::Cache.autotile("minimap")
@autotile = Bitmap.new(24, 32)
@autotile.stretch_blt(Rect.new(0, 0, 24, 32), temp, Rect.new(0, 0, 96, 128))
setup($game_map.map_id)
end
#--------------------------------------------------------------------------
# â— setup
#--------------------------------------------------------------------------
def setup(map_id)
@map_id = map_id
@map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))
tileset = $data_tilesets[@map.tileset_id]
@passages = tileset.passages
@priorities = tileset.priorities
redefine_tiles
refresh
end
#--------------------------------------------------------------------------
# â— pass
#--------------------------------------------------------------------------
def pass(tile_id)
return 15 if tile_id == nil
return @passages[tile_id] != nil ? @passages[tile_id] : 15
end
#--------------------------------------------------------------------------
# â— redefine_tile
#--------------------------------------------------------------------------
def redefine_tiles
width = @map.width
height = @map.height
map = RPG::Map.new(width, height)
map.data = @map.data.dup
RPG::Cache.clear
for y in 0...height
for x in 0...width
for level in [0, 1, 2]
id = @map.data[x, y, level]
@passages[id] = 15 if pass(id) == 31
next if level == 0
if pass(id) != 15 and @priorities[id] == 0
@map.data[x, y, 0] = 384
elsif pass(id) == 15 and id.between?(48, 383)
@map.data[x, y, 0] = id
@passages[@map.data[x, y, 0]] = pass(id)
elsif pass(id) == 15 and @priorities[id] == 0 and draw_object?
@map.data[x, y, 0] = 48
end
end
end
end
for y in 0...height
for x in 0...width
tile = @map.data[x, y, 0]
u = @map.data[x, y - 1, 0]
d = @map.data[x, y + 1, 0]
r = @map.data[x + 1, y, 0]
l = @map.data[x - 1, y, 0]
ul = @map.data[x - 1, y - 1, 0]
ur = @map.data[x + 1, y - 1, 0]
dl = @map.data[x - 1, y + 1, 0]
dr = @map.data[x + 1, y + 1, 0]
map.data[x, y, 0] = 94
if pass(tile) == 15
if pass(u) != 15 and pass(r) != 15 and pass(l) != 15 and pass(d) != 15
map.data[x, y, 0] = 94
end
if pass(u) != 15 and pass(r) != 15 and pass(l) != 15 and pass(d) == 15
map.data[x, y, 0] = 90
end
if pass(u) != 15 and pass(r) != 15 and pass(d) != 15 and pass(l) == 15
map.data[x, y, 0] = 93
end
if pass(u) != 15 and pass(r) != 15 and pass(l) == 15 and pass(d) == 15
map.data[x, y, 0] = 84
end
if pass(u) != 15 and pass(l) != 15 and pass(d) != 15 and pass(r) == 15
map.data[x, y, 0] = 91
end
if pass(u) != 15 and pass(l) != 15 and pass(r) == 15 and pass(d) == 15
map.data[x, y, 0] = 82
end
if pass(u) != 15 and pass(d) != 15 and pass(r) == 15 and pass(l) == 15
map.data[x, y, 0] = 81
end
if pass(u) != 15 and pass(r) == 15 and pass(l) == 15 and pass(d) == 15
map.data[x, y, 0] = 68
end
if pass(r) != 15 and pass(l) != 15 and pass(d) != 15 and pass(u) == 15
map.data[x, y, 0] = 92
end
if pass(r) != 15 and pass(l) != 15 and pass(u) == 15 and pass(d) == 15
map.data[x, y, 0] = 80
end
if pass(r) != 15 and pass(d) != 15 and pass(u) == 15 and pass(l) == 15
map.data[x, y, 0] = 86
end
if pass(r) != 15 and pass(u) == 15 and pass(l) == 15 and pass(d) == 15
map.data[x, y, 0] = 72
end
if pass(l) != 15 and pass(d) != 15 and pass(u) == 15 and pass(r) == 15
map.data[x, y, 0] = 88
end
if pass(l) != 15 and pass(u) == 15 and pass(r) == 15 and pass(d) == 15
map.data[x, y, 0] = 64
end
if pass(d) != 15 and pass(u) == 15 and pass(r) == 15 and pass(l) == 15
map.data[x, y, 0] = 76
end
if pass(u) == 15 and pass(r) == 15 and pass(l) == 15 and pass(d) == 15
map.data[x, y, 0] = 48
end
else
map.data[x, y, 0] = 384
end
end
end
@map = map.dup
map = nil
end
#--------------------------------------------------------------------------
# â— refresh
#--------------------------------------------------------------------------
def refresh
self.visible = false
self.bitmap = Bitmap.new(@map.width * 8, @map.height * 8)
bitmap = Bitmap.new(@map.width * 8, @map.height * 8)
rect1 = Rect.new(8, 0, 8, 8)
for y in
0...@map.height
for x in
0...@map.width
tile_id = @map.data[x, y, 0]
if tile_id >= 384
bitmap.blt(x * 8, y * 8, @autotile, rect1)
end
if tile_id >= 48 and tile_id < 384
id = tile_id / 48 - 1
tile_id %= 48
for g in 0..3
h = 4 * tile_id + g
y1 = INDEX[h] / 6
x1 = INDEX[h] % 6
rect2 = Rect.new(x1 * 4, y1 * 4, 4, 4)
bitmap.blt(x * 8 + X[g] * 4, y * 8 + Y[g] * 4, @autotile, rect2)
end
end
end
end
d_rect = Rect.new(0, 0, @map.width * 8, @map.height * 8)
s_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
self.bitmap.stretch_blt(d_rect, bitmap, s_rect)
self.src_rect.set(display_x, display_y, width, height)
bitmap.clear
bitmap.dispose
end
end
#==============================================================================
# â– Map_Event
#------------------------------------------------------------------------------
#  draw the events and hero position
#==============================================================================
class Map_Event < Map_Passability
#--------------------------------------------------------------------------
# â— initialize
#--------------------------------------------------------------------------
def initialize(corner = 4)
super(corner)
@dots = []
refresh_event_map
end
#--------------------------------------------------------------------------
# â— refresh_dots
#--------------------------------------------------------------------------
def refresh_events
for event in $game_map.events.values
bitmap = nil
x = event.x * 8 - display_x
y = event.y * 8 - display_y
next if event.list == nil
for i in 0...event.list.size
if event.list
.parameters[0].is_a?(String)
if event.list.parameters[0] == "event"
bitmap = RPG::Cache.picture(event.list.parameters[0])
break
elsif event.list.parameters[0] == "enemy"
bitmap = RPG::Cache.picture(event.list.parameters[0])
break
elsif event.list.parameters[0].include?("teleport")
bitmap = RPG::Cache.picture("teleport")
break
elsif event.list.parameters[0] == "chest"
bitmap = RPG::Cache.picture(event.list.parameters[0])
break
elsif event.list.parameters[0] == "npc"
bitmap = RPG::Cache.picture(event.list.parameters[0])
break
elsif event.list.parameters[0] == "savepoint"
bitmap = RPG::Cache.picture(event.list.parameters[0])
break
else
bitmap = nil
end
end
end
@dots.push([x, y, bitmap])
end
end
#--------------------------------------------------------------------------
# â— refresh_dots
#--------------------------------------------------------------------------
def refresh_player
x = $game_player.real_x / 16 - display_x
y = $game_player.real_y / 16 - display_y
bitmap = RPG::Cache.picture("hero")
@dots.push([x, y, bitmap])
end
#--------------------------------------------------------------------------
# â— update
#--------------------------------------------------------------------------
def refresh_event_map
@dots.clear
self.event.bitmap.clear
refresh_events
refresh_player
for dot in @dots
unless dot[2] == nil
self.event.bitmap.blt(dot[0], dot[1], dot[2], Rect.new(0, 0, 8, 8))
end
end
end
end