Guest User

In-Depth Maps 2.1

a guest
Jun 16th, 2013
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.09 KB | None | 0 0
  1. #×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
  2. # In-Depth Maps v2.1
  3. # FenixFyreX
  4. # RPG Maker VxAce
  5. #×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
  6. # This script allows the player to define two regions:
  7. # overhead ceilings, and blocking tiles.
  8. # When the system finds the overhead ceilings region on top of a tile, it will
  9. # move that tile to the highest layer in the tilemap, and put the tile above
  10. # that tile (y - 1) in it's place on the 'ground', this allows the player to pass
  11. # underneath the tile.
  12. # To turn the system OFF, simply turn the switch defined below ON. To turn it
  13. # on, flip the switch OFF. This allows the user to traverse the 'ceilings' when
  14. # on top of them, but go behind them when on the ground.
  15. #
  16. #×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
  17.  
  18. module Fyx
  19.   module MapDepth
  20.    
  21.     # This is the switch to turn ON to turn the overhead system OFF.
  22.     # Remember, all switches are OFF by default, so the system is ON at startup.
  23.     Switch = 1
  24.    
  25.     # Does the script turn on the switch automatically when each map loads?
  26.     AutoSwitch = true
  27.    
  28.     # This is the region defining tiles that need to be above the player.
  29.     Overhead_Region = 1
  30.    
  31.     # This is the region defining tiles that need to be unpassable no matter
  32.     # what.
  33.     Block_Region = 2
  34.    
  35.     # This is the region to use when defining 'secret passages'. This region
  36.     # ensures that the tiles below it are ALWAYS above and passable.
  37.     Secret_Region = 3
  38.    
  39.     # This is the user defined fall-back for when the system can't obtain a
  40.     # tile to place under overhead tiles.
  41.     Default_Ground_Tile = 2816
  42.   end
  43. end
  44.  
  45. #×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
  46. # Don't edit below unless you know what it means.
  47. #×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
  48.  
  49. class Game_Map
  50.   Pass = { down: 0x0001, left: 0x0002, right: 0x0004, up: 0x0008,
  51.            norm: 0x0010, ladder: 0x0020, bush: 0x0040, counter: 0x0080,
  52.            floor: 0x0100, boat: 0x0200, ship: 0x0400, airship: 0x0800,
  53.            terrain: 0xF000 }
  54.            
  55.   CeilPass = [:down, :left, :right, :up, :bush, :floor, :terrain]
  56.            
  57.   alias setup_no_ceilings setup
  58.   def setup(*argv, &argb)
  59.     setup_no_ceilings(*argv, &argb)
  60.     setup_ceiling_data
  61.   end
  62.  
  63.   def setup_ceiling_data
  64.     $game_switches[ohead_switch] = false if Fyx::MapDepth::AutoSwitch
  65.     @ohead_switch = ohead_sys_is_on?
  66.     define_ceilings if @ohead_switch
  67.   end
  68.  
  69.   def ohead_sys_is_on?
  70.     return false if $game_switches[ohead_switch]
  71.     return true
  72.   end
  73.  
  74.   def ohead_switch
  75.     Fyx::MapDepth::Switch
  76.   end
  77.  
  78.   def ohead_region
  79.     Fyx::MapDepth::Overhead_Region
  80.   end
  81.  
  82.   def block_region
  83.     Fyx::MapDepth::Block_Region
  84.   end
  85.  
  86.   def secret_region
  87.     Fyx::MapDepth::Secret_Region
  88.   end
  89.  
  90.   def default_ground_tile
  91.     Fyx::MapDepth::Default_Ground_Tile
  92.   end
  93.  
  94.   def ceiling_ground_tile(x, y)
  95.     return valid?(x, y - 1) ? @map.data[x, y - 1, 0] : default_ground_tile
  96.   end
  97.  
  98.   alias passable_no_ceilings? passable?
  99.   def passable?(*argv, &argb)
  100.     return false if (ceiling_block?(*argv, &argb) && ohead_sys_is_on?)
  101.     passable_no_ceilings?(*argv, &argb)
  102.   end
  103.  
  104.   def ceiling?(x, y)
  105.     region_id(x, y) == ohead_region
  106.   end
  107.  
  108.   def secret_passage?(x, y)
  109.     region_id(x, y) == secret_region
  110.   end
  111.  
  112.   def ceiling_block?(*argv, &argb)
  113.     x, y = *argv[0...2]
  114.     region_id(x, y) == block_region
  115.   end
  116.  
  117.   def reset_ceilings
  118.     @ceilings, @ceiling_blocks, @pass_ceilings = [], [], []
  119.     @map.data = load_data(sprintf("Data/Map%03d.rvdata2", @map_id)).data
  120.     tileset.flags = load_data("Data/Tilesets.rvdata2")[@map.tileset_id].flags
  121.   end
  122.  
  123.   def get_ceil_xys
  124.     reset_ceilings
  125.     height.times do |y|
  126.       width.times do |x|
  127.         @ceilings << [x, y] if ceiling?(x, y)
  128.         @pass_ceilings << [x, y] if secret_passage?(x, y)
  129.         @ceiling_blocks << [x, y] if ceiling_block?(x, y)
  130.       end
  131.     end
  132.   end
  133.  
  134.   def define_ceilings
  135.     get_ceil_xys
  136.     $game_switches[ohead_switch] = true
  137.     @ceilings.each do |x, y|
  138.       tid = @map.data[x, y, 0]
  139.       bit = 0x10
  140.       CeilPass.each do |sym|
  141.         bit = (bit | Pass[sym]) if tileset.flags[tid] & Pass[sym] == Pass[sym]
  142.       end
  143.       tileset.flags[tid] = bit
  144.       @map.data[x, y, 2] = tid
  145.       $game_map.data[x, y, 0] = ceiling_ground_tile(x, y)
  146.     end
  147.     @pass_ceilings.each do |x, y|
  148.       tid = @map.data[x, y, 0]
  149.       bit = 0x10
  150.       CeilPass.each do |sym|
  151.         bit = (bit | Pass[sym]) if tileset.flags[tid] & Pass[sym] == Pass[sym]
  152.       end
  153.       tileset.flags[tid] = bit
  154.       @map.data[x, y, 2] = tid
  155.       @map.data[x, y, 0] = default_ground_tile
  156.     end
  157.     $game_switches[ohead_switch] = false
  158.   end
  159.  
  160.   alias update_no_ceilings update
  161.   def update(*argv, &argb)
  162.     if @ohead_switch != ohead_sys_is_on?
  163.       @ohead_switch = ohead_sys_is_on?
  164.       ohead_sys_is_on? ? define_ceilings : reset_ceilings
  165.     end
  166.     update_no_ceilings(*argv, &argb)
  167.   end
  168. end
  169.  
  170. module DataManager
  171.   class << self
  172.     alias reload_map_if_reset_ohead reload_map_if_updated
  173.     def reload_map_if_updated(*argv, &argb)
  174.       $game_map.setup_ceiling_data
  175.       reload_map_if_reset_ohead(*argv, &argb)
  176.     end
  177.   end
  178. end
  179. #×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
  180. # ×END OF SCRIPT×
  181. #×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
Advertisement
Add Comment
Please, Sign In to add comment