#============================================================================== # ** Tileset Reader VX #------------------------------------------------------------------------------ # by DerVVulfman # version 2.0 # 05-04-2008 # RGSS2 #------------------------------------------------------------------------------ # # INTRODUCTION: # # This system re-introduces terrain tags and four-directional passage flags # back into your RPGMaker VX system. This script mimics many of the lost # features, giving you more control over your project. # #------------------------------------------------------------------------------ # # INSTRUCTIONS: # # This script is not for use by itself, but is used to read data from the # .vxdata file created by the 'Tileset Feature Editor.' # # # 4-Way Direction: # ================ # The four-direction passage feature is an enhancement for mappers who may # desire individual tiles where movement on these tiles may be one-way, # two-way or the like. It restricts the character's movement where normal # 'X' and 'O' passage switches cannot suffice. # # To retrieve a 4-way directional value from the map, # use the following call: $game_map.passage_tag(x, y, d) # # The passage system holds 4 flags per tile, so it is required to specify # a direction into the call, not just the x and y coordinates. The value # of 'd' can be 1 (for down), 2 (for left), 3 (for right) or 4 (for up). # If you do retrieve a value other than 0x00 or '0', then that tile is a # four-way passable tile. # # # Terrain Tags: # ============= # The reintroduction of Terrain Tags is an enhancement for mappers and # scripters alike. This feature does nothing on its own, but the terrain # values stored can be called for reasons of the end user's design. # # To retrieve the terrain tag of a select tile from the map, # just use the following call: $game_map.terrain_tag(x, y) # # Please note that the 'Tileset Feature Editor' supports terrain tag values # up to '201' rather than the paltry '8' of the older RPGMaker systems. # # # Debug Pop-Up: # ============= # You can also bring up a 'pop-up' debug window by pressing a predefined # key (that can be changed) in the script's only configurable line. # #------------------------------------------------------------------------------ # # EDITS AND MODIFICATIONS: # # This system Aliases the following methods: # * move_down (Game_Character) # * move_left (Game_Character) # * move_right (Game_Character) # * move_up (Game_Character) # * map_passable? (Game_Player) # * update (Game_Player) # * load_database (Scene_Title) # # This system redefines the following methods: # * passable? (Game_Character) # * move_lower_left (Game_Character) # * move_lower_right (Game_Character) # * move_upper_left (Game_Character) # * move_upper_right (Game_Character) # # This system adds the following methods: # * terrain_tag (Game_Map) # * passage_tag (Game_Map) # * tile_index (Game_Map) # * passable_dir? (Game_Map) # * bh_read (Game_Map) # * map_pass? (Game_Character) - Replaces map_passable? # * new_x (Game_Character) # * new_y (Game_Character) # * tile_debug_popup (Game_Player) # # This system adds the following module: # * RPG::Tileset # # #------------------------------------------------------------------------------ # # CREDITS & THANKS: # First, I like to give thanks to enterbrain (or enterbrainless) for remo- # ving an obviously desirable feature. Without them, I wouldn't have this # fix to offer. ^_^ Like sarcasm? # # Also, I would like to thank the RMXP/VX community, including Syvkal and # KGC who's been dilligant on their own separate tileset systems. # #------------------------------------------------------------------------------ # # TERMS AND CONDITIONS: # # Free to use, even in commercial projects. Just note that I need some form # of due credit... even a mere mention in some end titles. # #============================================================================== #========================================================================== # **** YOUR ONE CONFIGURABLE **** # #========================================================================== # # Identify/set the button used in test mode TILESET_DEBUG_KEY = Input::F8 #============================================================================== # ** RPG::Tileset #------------------------------------------------------------------------------ # Data class for imported tileset information. #============================================================================== class RPG::Tileset #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :passages # 4-Directional Passage Flags attr_accessor :terrain_tags # Terrain Tags #-------------------------------------------------------------------------- # * Object initialization #-------------------------------------------------------------------------- def initialize @passages = Table.new(8192) @terrain_tags = Table.new(8192) end end #============================================================================== # ** Game_Map #------------------------------------------------------------------------------ # This class handles maps. It includes scrolling and passage determination # functions. The instance of this class is referenced by $game_map. #============================================================================== class Game_Map #-------------------------------------------------------------------------- # * Obtain Terrain Tag # x : X Coordinate # y : Y Coordinate #-------------------------------------------------------------------------- def terrain_tag(x, y) for i in [2, 1, 0] tile_id = @map.data[x, y, i] return 0 if tile_id == nil t_tag = $data_tileset.terrain_tags[tile_index(tile_id)] return t_tag if t_tag > 0 end return 0 end #-------------------------------------------------------------------------- # * Obtain 4-Directional Passage flag # x : x coordinate # y : y coordinate # d : direction #-------------------------------------------------------------------------- def passage_tag(x, y, d) for i in [2, 1, 0] tile_id = @map.data[x, y, i] return 0 if tile_id == nil passtag = $data_tileset.passages[tile_index(tile_id)] passtag = bh_read(passtag, d) return 0x00 if passtag == nil return passtag if passtag > 0x00 end return 0x00 end #-------------------------------------------------------------------------- # * Obtain Tile ID Index # tile_id : Tile ID #-------------------------------------------------------------------------- def tile_index(tile_id) # Branch on Tile case tile_id # Multi-tiled ids in Tileset 'A' when 2048..8191 ; return ((tile_id - 2000) / 48) - 1 # Individual tile ids in Tileset 'A' when 1536..1663 ; return(tile_id - 1408) # Tilesets 'B' to 'E' when 0..1023 ; return (tile_id + 256) end return 0 end #-------------------------------------------------------------------------- # * Determine if 4-way Passable # x : x coordinate # y : y coordinate # d : direction #-------------------------------------------------------------------------- def passable_dir?(x, y, d) for i in [2, 1, 0] tile_id = @map.data[x, y, i] return false if tile_id == nil pass = $data_tileset.passages[tile_index(tile_id)] case d when 2 ; return false if pass != 0x00 && bh_read(pass, 1) != 0x01 when 4 ; return false if pass != 0x00 && bh_read(pass, 2) != 0x02 when 6 ; return false if pass != 0x00 && bh_read(pass, 3) != 0x04 when 8 ; return false if pass != 0x00 && bh_read(pass, 4) != 0x08 end end return true end #-------------------------------------------------------------------------- # * Binary Hexcode Reader # original value : hexcode flag being read # direction : direction #-------------------------------------------------------------------------- def bh_read(original_value, direction) case original_value when 0x00 case direction when 1 ; result = 0x00 when 2 ; result = 0x00 when 3 ; result = 0x00 when 4 ; result = 0x00 end when 0x01 case direction when 1 ; result = 0x01 when 2 ; result = 0x00 when 3 ; result = 0x00 when 4 ; result = 0x00 end when 0x02 case direction when 1 ; result = 0x00 when 2 ; result = 0x02 when 3 ; result = 0x00 when 4 ; result = 0x00 end when 0x03 ; case direction when 1 ; result = 0x01 when 2 ; result = 0x02 when 3 ; result = 0x00 when 4 ; result = 0x00 end when 0x04 ; case direction when 1 ; result = 0x00 when 2 ; result = 0x00 when 3 ; result = 0x04 when 4 ; result = 0x00 end when 0x05 ; case direction when 1 ; result = 0x01 when 2 ; result = 0x00 when 3 ; result = 0x04 when 4 ; result = 0x00 end when 0x06 ; case direction when 1 ; result = 0x00 when 2 ; result = 0x02 when 3 ; result = 0x04 when 4 ; result = 0x00 end when 0x07 ; case direction when 1 ; result = 0x01 when 2 ; result = 0x02 when 3 ; result = 0x04 when 4 ; result = 0x00 end when 0x08 ; case direction when 1 ; result = 0x00 when 2 ; result = 0x00 when 3 ; result = 0x00 when 4 ; result = 0x08 end when 0x09 ; case direction when 1 ; result = 0x01 when 2 ; result = 0x00 when 3 ; result = 0x00 when 4 ; result = 0x08 end when 0x0A ; case direction when 1 ; result = 0x00 when 2 ; result = 0x02 when 3 ; result = 0x00 when 4 ; result = 0x08 end when 0x0B ; case direction when 1 ; result = 0x01 when 2 ; result = 0x02 when 3 ; result = 0x00 when 4 ; result = 0x08 end when 0x0C ; case direction when 1 ; result = 0x00 when 2 ; result = 0x00 when 3 ; result = 0x04 when 4 ; result = 0x08 end when 0x0D ; case direction when 1 ; result = 0x01 when 2 ; result = 0x00 when 3 ; result = 0x04 when 4 ; result = 0x08 end when 0x0E ; case direction when 1 ; result = 0x00 when 2 ; result = 0x02 when 3 ; result = 0x04 when 4 ; result = 0x08 end when 0x0F ; case direction when 1 ; result = 0x01 when 2 ; result = 0x02 when 3 ; result = 0x04 when 4 ; result = 0x08 end end return result end end #============================================================================== # ** Game_Character #------------------------------------------------------------------------------ # This class deals with characters. It's used as a superclass of the # Game_Player and Game_Event classes. #============================================================================== class Game_Character #-------------------------------------------------------------------------- # * Alias Listings #-------------------------------------------------------------------------- alias ts_move_down move_down alias ts_move_left move_left alias ts_move_right move_right alias ts_move_up move_up #-------------------------------------------------------------------------- # * Determine if Passable # x : x-coordinate # y : y-coordinate # d : direction #-------------------------------------------------------------------------- def passable?(x, y, d = 10) nx = new_x(x, d) ny = new_y(y, d) nx = $game_map.round_x(nx) ny = $game_map.round_y(ny) return false unless $game_map.valid?(nx, ny) return true if @through or debug_through? return false unless map_pass?(x, y, d) return false unless map_pass?(nx, ny, d) return false if collide_with_characters?(nx, ny) return true end #-------------------------------------------------------------------------- # * Determine if Map is Passable # x : x-coordinate # y : y-coordinate # Gets whether the tile at the designated coordinates is passable. #-------------------------------------------------------------------------- def map_pass?(x, y, d) return $game_map.passable?(x, y) && $game_map.passable_dir?(x, y, d) end #-------------------------------------------------------------------------- # * Obtain the X coordinate after the move # x : X Coordinate. # d : Portable direction #-------------------------------------------------------------------------- def new_x(x, d) return x + (d == 6 ? 1 : d == 4 ? -1 : 0) end #-------------------------------------------------------------------------- # * Obtain the Y coordinate after the move # y : Y Coordinate. # d : Portable direction #-------------------------------------------------------------------------- def new_y(y, d) return y + (d == 2 ? 1 : d == 8 ? -1 : 0) end #-------------------------------------------------------------------------- # * Move Down # turn_ok : Allows change of direction on the spot #-------------------------------------------------------------------------- def move_down(turn_ok = true) if passable?(@x, @y, 2) ts_move_down(turn_ok) else turn_down if turn_ok check_event_trigger_touch(@x, @y+1) @move_failed = true end end #-------------------------------------------------------------------------- # * Move Left # turn_ok : Allows change of direction on the spot #-------------------------------------------------------------------------- def move_left(turn_ok = true) if passable?(@x, @y, 4) ts_move_left(turn_ok) else turn_left if turn_ok check_event_trigger_touch(@x-1, @y) @move_failed = true end end #-------------------------------------------------------------------------- # * Move Right # turn_ok : Allows change of direction on the spot #-------------------------------------------------------------------------- def move_right(turn_ok = true) if passable?(@x, @y, 6) ts_move_right(turn_ok) else turn_right if turn_ok check_event_trigger_touch(@x+1, @y) @move_failed = true end end #-------------------------------------------------------------------------- # * Move Up # turn_ok : Allows change of direction on the spot #-------------------------------------------------------------------------- def move_up(turn_ok = true) if passable?(@x, @y, 8) ts_move_up(turn_ok) else turn_up if turn_ok check_event_trigger_touch(@x, @y-1) @move_failed = true end end #-------------------------------------------------------------------------- # * Move Lower Left #-------------------------------------------------------------------------- def move_lower_left unless @direction_fix @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction) end if (passable?(@x, @y, 2) && passable?(@x, @y+1, 4)) || (passable?(@x, @y, 4) && passable?(@x-1, @y, 2)) @x -= 1 @y += 1 increase_steps @move_failed = false else @move_failed = true end end #-------------------------------------------------------------------------- # * Move Lower Right #-------------------------------------------------------------------------- def move_lower_right unless @direction_fix @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction) end if (passable?(@x, @y, 2) && passable?(@x, @y+1, 6)) || (passable?(@x, @y, 6) && passable?(@x+1, @y, 2)) @x += 1 @y += 1 increase_steps @move_failed = false else @move_failed = true end end #-------------------------------------------------------------------------- # * Move Upper Left #-------------------------------------------------------------------------- def move_upper_left unless @direction_fix @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction) end if (passable?(@x, @y, 8) && passable?(@x, @y-1, 4)) || (passable?(@x, @y, 4) && passable?(@x-1, @y, 8)) @x -= 1 @y -= 1 increase_steps @move_failed = false else @move_failed = true end end #-------------------------------------------------------------------------- # * Move Upper Left #-------------------------------------------------------------------------- def move_upper_right unless @direction_fix @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction) end if (passable?(@x, @y, 8) && passable?(@x, @y-1, 6)) || (passable?(@x, @y, 6) && passable?(@x+1, @y, 8)) @x += 1 @y -= 1 increase_steps @move_failed = false else @move_failed = true end end end #============================================================================== # ** Game_Player #------------------------------------------------------------------------------ # This class handles maps. It includes event starting determinants and map # scrolling functions. The instance of this class is referenced by $game_map. #============================================================================== class Game_Player < Game_Character #-------------------------------------------------------------------------- # * Alias Listings #-------------------------------------------------------------------------- alias ts_map_passable? map_passable? alias ts_update update #-------------------------------------------------------------------------- # * Determine if Map is Passable # x : x-coordinate # y : y-coordinate #-------------------------------------------------------------------------- def map_passable?(x, y) return false unless ts_map_passable?(x, y) return $game_map.passable_dir?(x, y, @direction) end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update # Perform the original call ts_update # If in debug mode and Info Button pressed if $TEST && TILESET_DEBUG_KEY != nil if Input.trigger?(TILESET_DEBUG_KEY) # Show information on tile tile_debug_popup end end end #-------------------------------------------------------------------------- # * Show Information on Tile #-------------------------------------------------------------------------- def tile_debug_popup t_tag = $game_map.terrain_tag(x, y) message = "Terrain Tag: #{t_tag}" message2 = "" for d in 1..4 pass = $game_map.passage_tag(x,y,d) message2 += "V" if pass == 0x01 message2 += "<" if pass == 0x02 message2 += ">" if pass == 0x04 message2 += "¥Ë" if pass == 0x08 end message2 = "(none set)" if message2 == "" message += "\n" message += "4-Dir. Passage: " message += message2 print message end end #============================================================================== # ** Scene_Title #------------------------------------------------------------------------------ # This class performs the title screen processing. #============================================================================== class Scene_Title < Scene_Base #-------------------------------------------------------------------------- # * Alias Listings #-------------------------------------------------------------------------- alias ts_load load_database #-------------------------------------------------------------------------- # * Load Database #-------------------------------------------------------------------------- def load_database # Perform the original call ts_load # Add the tileset data $data_tileset = load_data("Data/Tilesets.rvdata") end end