Advertisement
LiTTleDRAgo

[RGSS] Custom Terrain Tags

Mar 19th, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.43 KB | None | 0 0
  1. #==============================================================================
  2. # ** DRG - Custom Terrain Tags
  3. # Version : 1.00
  4. # Author : LiTTleDRAgo
  5. #==============================================================================
  6. #============================================================================
  7. # ** RPG::MapInfo
  8. #----------------------------------------------------------------------------
  9. #  This class handles the map info.
  10. #============================================================================
  11.  
  12. $data_maps = load_data("Data/MapInfos.rxdata")
  13. class RPG::MapInfo
  14.   def name
  15.     v = @name.gsub(/\\[Nn]\[(\d+)\]/) {$game_actors[$1.to_i].nil? ? '' :
  16.       $game_actors[$1.to_i].name}
  17.     return v.gsub(/\[.*\]/) {""}
  18.   end
  19. end
  20. #==============================================================================
  21. # ** Game_Map
  22. #------------------------------------------------------------------------------
  23. #  This class handles the map. It includes scrolling and passable determining
  24. #  functions. Refer to "$game_map" for the instance of this class.
  25. #==============================================================================
  26.  
  27. class Game_Map
  28.   #--------------------------------------------------------------------------
  29.   # * Alias Method
  30.   #--------------------------------------------------------------------------
  31.   alias drg2032013_setup setup
  32.   #--------------------------------------------------------------------------
  33.   # * Setup
  34.   #--------------------------------------------------------------------------
  35.   def setup(map_id)
  36.     setup_custom_terrain_tags(map_id)
  37.     drg2032013_setup(map_id)
  38.   end
  39.   #--------------------------------------------------------------------------
  40.   # * Setup custom_terrain_tags
  41.   #--------------------------------------------------------------------------
  42.   def setup_custom_terrain_tags(map_id = @map_id)
  43.     map_data = $data_maps[map_id]
  44.     @temp_terrain = {}
  45.     return if map_data.nil?
  46.     if map_data.instance_variable_get(:@name)[/<Tags(\d+)>/i]
  47.       load_data = $1.to_i
  48.     end
  49.     if load_data
  50.       @map = load_data(sprintf("Data/Map%03d.rxdata", map_id))
  51.       data = load_data(sprintf("Data/Map%03d.rxdata", load_data))
  52.       if [data.width, data.height] !=  [@map.width, @map.height]
  53.         raise "The map dimension is different"
  54.       end
  55.       data.events.keys.each {|i|
  56.         @temp_terrain[i] = Game_Event.new(load_data, data.events[i])
  57.         s = [@temp_terrain[i].direction,@temp_terrain[i].pattern]
  58.         x = [@temp_terrain[i].x, @temp_terrain[i].y]
  59.         @temp_terrain[x] = case @temp_terrain[i].character_name
  60.         when 'Terrain_Tags01'
  61.           case s[0]
  62.           when 2,4,6,8
  63.             case @temp_terrain[i].pattern
  64.             when 0 then s[0]==2 ? (0) : s[0]==4 ? (4) : s[0]==6 ? (8)  : (12)
  65.             when 1 then s[0]==2 ? (1) : s[0]==4 ? (5) : s[0]==6 ? (9)  : (13)
  66.             when 2 then s[0]==2 ? (2) : s[0]==4 ? (6) : s[0]==6 ? (10) : (14)
  67.             when 3 then s[0]==2 ? (3) : s[0]==4 ? (7) : s[0]==6 ? (11) : (15)
  68.             end
  69.           end
  70.         end  }
  71.     end
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # * Get Terrain Tag
  75.   #--------------------------------------------------------------------------
  76.   alias drg2032013_terrain_tag terrain_tag
  77.   def terrain_tag(x, y)
  78.     result = @temp_terrain[[x,y]] || drg2032013_terrain_tag(x, y)
  79.     return result
  80.   end
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement