Advertisement
LiTTleDRAgo

[RGSS3] XP Map Loader

Aug 6th, 2013
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 92.58 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # [VX-A] XP Map Loader
  3. # Version: 1.16
  4. # Author : LiTTleDRAgo
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  6. ($imported ||= {})[:drg_xp_map_loader] = 1.16
  7. #==============================================================================
  8. # ** Game_Map
  9. #------------------------------------------------------------------------------
  10. #  This class handles maps. It includes scrolling and passage determination
  11. # functions. The instance of this class is referenced by $game_map.
  12. #==============================================================================
  13. class Game_Map
  14.   #--------------------------------------------------------------------------
  15.   # * Public Instance Variables
  16.   #--------------------------------------------------------------------------  
  17.   attr_accessor :tileset_name             # tileset file name
  18.   attr_accessor :autotile_names           # autotile file name
  19.   attr_accessor :panorama_name            # panorama file name
  20.   attr_accessor :panorama_hue             # panorama hue
  21.   attr_accessor :fog_name                 # fog file name
  22.   attr_accessor :fog_hue                  # fog hue
  23.   attr_accessor :fog_opacity              # fog opacity level
  24.   attr_accessor :fog_blend_type           # fog blending method
  25.   attr_accessor :fog_zoom                 # fog zoom rate
  26.   attr_accessor :fog_sx                   # fog sx
  27.   attr_accessor :fog_sy                   # fog sy
  28.   attr_accessor :battleback_name          # battleback file name
  29.   attr_reader   :tileset_id               # tileset id
  30.   attr_reader   :passages                 # passage table
  31.   attr_reader   :priorities               # priority table
  32.   attr_reader   :terrain_tags             # terrain tag table
  33.   attr_reader   :fog_ox                   # fog x-coordinate starting point
  34.   attr_reader   :fog_oy                   # fog y-coordinate starting point
  35.   attr_reader   :fog_tone                 # fog color tone
  36.   attr_reader   :map_type
  37.   #--------------------------------------------------------------------------
  38.   # * Constant
  39.   #--------------------------------------------------------------------------  
  40.   VXA = defined?(Window_BattleActor)
  41.   #--------------------------------------------------------------------------
  42.   # * Alias Method
  43.   #--------------------------------------------------------------------------
  44.   alias game_map_vxaxp_update            update
  45.   alias game_map_vxaxp_passable          passable?
  46.   alias game_map_vxaxp_bush              bush?
  47.   alias game_map_vxaxp_counter           counter?
  48.   alias game_map_vxaxp_refresh_vehicles  referesh_vehicles
  49.   alias game_map_vxaxp_terrain_tag terrain_tag if method_defined?(:terrain_tag)
  50.   #--------------------------------------------------------------------------
  51.   # * Aliased Method : referesh_vehicles
  52.   #--------------------------------------------------------------------------
  53.   def referesh_vehicles
  54.     decide_map_type
  55.     decide_map_layer
  56.     game_map_vxaxp_refresh_vehicles
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # * New Method : decide_xpvx_map
  60.   #--------------------------------------------------------------------------
  61.   def decide_map_type
  62.     map = sprintf("Map%03d", @map_id)
  63.     ext = VXA ? 'rvdata2' : 'rvdata'
  64.     if File.exist?("Data/#{map}.#{:rxdata}")
  65.       $data_tilesets_xp = load_data("Data/Tilesets.#{:rxdata}")
  66.       @map        = load_map_data(@map_id)
  67.       @mapxp_data = load_map_data(@map_id,:rxdata)
  68.       @map_type   = 'XP'
  69.       mapsize     = [@map,@mapxp_data].collect {|m| [m.width,m.height]}
  70.       if mapsize.uniq.size > 1
  71.         raise "The dimension on #{map}.rxdata #{mapsize[0].inspect} \n"+
  72.               "and #{map}.#{ext} #{mapsize[1].inspect} is not same"
  73.       end
  74.       @tilesetxp_id    = @mapxp_data.tileset_id
  75.       @tileset_name    = tileset_xp.tileset_name
  76.       @autotile_names  = tileset_xp.autotile_names
  77.       @panorama_name   = tileset_xp.panorama_name
  78.       @panorama_hue    = tileset_xp.panorama_hue
  79.       @fog_name        = tileset_xp.fog_name
  80.       @fog_hue         = tileset_xp.fog_hue
  81.       @fog_opacity     = tileset_xp.fog_opacity
  82.       @fog_blend_type  = tileset_xp.fog_blend_type
  83.       @fog_zoom        = tileset_xp.fog_zoom
  84.       @fog_sx          = tileset_xp.fog_sx
  85.       @fog_sy          = tileset_xp.fog_sy
  86.       @battleback_name = tileset_xp.battleback_name
  87.       @passages        = tileset_xp.passages
  88.       @priorities      = tileset_xp.priorities
  89.       @terrain_tags    = tileset_xp.terrain_tags
  90.       if ext == 'rvdata2'
  91.         tileset_xp.tileset_names = tileset.tileset_names
  92.         tileset_xp.flags         = tileset.flags
  93.         tileset_xp.mode          = tileset.mode
  94.         tileset_xp.note          = tileset.note
  95.       end
  96.     else
  97.       @map             = load_map_data(@map_id)
  98.       @mapxp_data      = @map
  99.       @map_type        = 'VX'
  100.       @tileset_name    = ''
  101.       @autotile_names  = ['']*7
  102.       @battleback_name = ''
  103.       @passages        = Table.new(384)  if ext == 'rvdata2'
  104.       @priorities      = Table.new(384)
  105.       @terrain_tags    = Table.new(384)
  106.       clear_panorama
  107.       clear_fog
  108.     end
  109.     reset_fog_variable
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # * New Method : decide_map_layer
  113.   #--------------------------------------------------------------------------
  114.   def decide_map_layer(*args)
  115.     return if ($imported[:drg_core_engine]||0) < 1.16
  116.     map_name = mapInfo[$game_map.map_id].name
  117.     child_ids.each do |submap_id|
  118.       map_info = mapInfo[submap_id]
  119.       unless map_info.nil?
  120.         if map_info.parent_id == map_id &&
  121.           map_info.name.include?("[" + 'join' + "]")
  122.         then
  123.           ext = VXA ? 'rvdata2' : 'rvdata'
  124.           map = sprintf("Data/Map%03d.rxdata", submap_id) if @map_type == 'XP'
  125.           map = sprintf("Data/Map%03d.#{ext}", submap_id) if @map_type == 'VX'
  126.           unless File.exist?("#{map}")
  127.             msgbox "File #{map} doesn't exist"
  128.             next
  129.           end
  130.           submap = load_data(map)
  131.           old_zsize = data.zsize
  132.           data.resize(data.xsize, data.ysize, old_zsize + 3)
  133.           for x in 0...data.xsize
  134.             for y in 0...data.ysize
  135.               data[x, y, old_zsize]     = submap.data[x, y, 0]
  136.               data[x, y, old_zsize + 1] = submap.data[x, y, 1]
  137.               data[x, y, old_zsize + 2] = submap.data[x, y, 2]
  138.             end
  139.           end
  140.         end
  141.       end
  142.     end
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # * Aliased Method : passable?
  146.   #--------------------------------------------------------------------------
  147.   def passable?(x, y, d, self_event = nil)
  148.     return game_map_vxaxp_passable(x,y,d) if @map_type == 'VX'
  149.     return false unless valid?(x, y)
  150.     bit = (1 << (d / 2 - 1)) & 0x0f
  151.     tile = tile_events_xy(x, y).select {|e| e != self_event }
  152.     tile.collect {|ev| ev.tile_id }.each do |tile_id|
  153.       flag = tileset.flags[tile_id]
  154.       if flag & bit != 0
  155.         return false
  156.       elsif flag & 0x0f == 0x0f
  157.         return false
  158.       elsif @priorities[tile_id] == 0
  159.         return true
  160.       end
  161.     end
  162.     z_data.each do |i|
  163.       tile_id = data[x, y, i]  
  164.       if tile_id == nil
  165.         return false
  166.       elsif @passages[tile_id] & bit != 0
  167.         return false
  168.       elsif @passages[tile_id] & 0x0f == 0x0f
  169.         return false
  170.       elsif @priorities[tile_id] == 0
  171.         return true
  172.       end
  173.     end
  174.     return true
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # * Aliased Method : bush?
  178.   #--------------------------------------------------------------------------
  179.   def bush?(x, y)
  180.     return game_map_vxaxp_bush(x,y) if @map_type == 'VX'
  181.     if @map_id != 0
  182.       for i in z_data
  183.         tile_id = data[x, y, i]
  184.         if tile_id == nil || @passages.nil?
  185.           return false
  186.         elsif @passages[tile_id] & 0x40 == 0x40
  187.           return true
  188.         end
  189.       end
  190.     end
  191.     return false
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # * Aliased Method : counter?
  195.   #--------------------------------------------------------------------------
  196.   def counter?(x, y)
  197.     return game_map_vxaxp_counter(x,y) if @map_type == 'VX'
  198.     if @map_id != 0
  199.       for i in z_data
  200.         tile_id = data[x, y, i]
  201.         if tile_id == nil || @passages.nil?
  202.           return false
  203.         elsif @passages[tile_id] & 0x80 == 0x80
  204.           return true
  205.         end
  206.       end
  207.     end
  208.     return false
  209.   end
  210.   #--------------------------------------------------------------------------
  211.   # * Aliased Method : terrain_tag
  212.   #--------------------------------------------------------------------------
  213.   def terrain_tag(x, y)
  214.     return game_map_vxaxp_terrain_tag(x,y) if @map_type == 'VX'
  215.     if @map_id != 0
  216.       for i in z_data
  217.         tile_id = data[x, y, i]
  218.         if tile_id == nil || @terrain_tags.nil?
  219.           return 0
  220.         elsif @terrain_tags[tile_id] > 0
  221.           return @terrain_tags[tile_id]
  222.         end
  223.       end
  224.     end
  225.     return 0
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # * Overwriten Method : data
  229.   #--------------------------------------------------------------------------
  230.   def data
  231.     if @map_type == 'VX'
  232.       @map.data
  233.     else
  234.       @mapxp_data.data
  235.     end
  236.   end
  237.   #--------------------------------------------------------------------------
  238.   # * Overwriten Method : layered_tiles
  239.   #--------------------------------------------------------------------------
  240.   def layered_tiles(x, y)
  241.     #msgbox z_data
  242.     _z_data = z_data.reject {|s| s == 3 }
  243.     _z_data.collect {|z| tile_id(x, y, z) }
  244.   end
  245.   #--------------------------------------------------------------------------
  246.   # * Overwriten Method : change_tileset
  247.   #--------------------------------------------------------------------------
  248.   def change_tileset(tileset_id)
  249.     if @map_type == 'VX'
  250.       @tileset_id     = tileset_id
  251.     elsif @map_type == 'XP'
  252.       @tilesetxp_id   = tileset_id
  253.       @tileset_name   = tileset.tileset_name
  254.       @autotile_names = tileset.autotile_names
  255.     end
  256.     refresh
  257.   end
  258.   #--------------------------------------------------------------------------
  259.   # ● New method: load_map_data
  260.   #--------------------------------------------------------------------------
  261.   unless method_defined?(:load_map_data)
  262.     def load_map_data(mapid, ext = nil)
  263.       if ext.nil? || ext.empty?
  264.         ext = :rxdata  
  265.         ext = :rvdata  if LiTTleDRAgo::VX
  266.         ext = :rvdata2 if LiTTleDRAgo::VXA
  267.       end
  268.       map = sprintf("Data/Map%03d.#{ext}", mapid)
  269.       load_data(map)
  270.     end
  271.   end
  272.   #--------------------------------------------------------------------------
  273.   # * New Method : z_data
  274.   #--------------------------------------------------------------------------
  275.   unless method_defined?(:z_data)
  276.     def z_data
  277.       (0...data.zsize).to_a.reverse
  278.     end
  279.   end
  280.   #--------------------------------------------------------------------------
  281.   # * Aliased Method : update
  282.   #--------------------------------------------------------------------------
  283.   def update(*args)
  284.     game_map_vxaxp_update(*args)
  285.     update_fog
  286.   end
  287.   #--------------------------------------------------------------------------
  288.   # * Get Array of Tile-Handling Events at Designated Coordinates
  289.   #   (Except Pass-Through)
  290.   #--------------------------------------------------------------------------
  291.   unless method_defined?(:tile_events_xy)
  292.     def tile_events_xy(x, y)
  293.       tile_event = @events.values.select {|event| event.tile? }
  294.       tile_event.select {|event| event.pos_nt?(x, y) }
  295.     end
  296.   end
  297.   #--------------------------------------------------------------------------
  298.   # * New Method : tileset_xp
  299.   #--------------------------------------------------------------------------
  300.   def tileset_xp
  301.     decide_map_type if @tilesetxp_id.nil? || $data_tilesets_xp.nil?
  302.     $data_tilesets_xp[@tilesetxp_id]
  303.   end
  304.   #--------------------------------------------------------------------------
  305.   # * New Method : decide_xpvx_map
  306.   #--------------------------------------------------------------------------
  307.   def decide_map_type
  308.     map = sprintf("Map%03d", @map_id)
  309.     ext = VXA ? 'rvdata2' : 'rvdata'
  310.     if File.exist?("Data/#{map}.rxdata")
  311.       $data_tilesets_xp = load_data("Data/Tilesets.rxdata")
  312.       @map        = load_data("Data/#{map}.#{ext}")
  313.       @mapxp_data = load_data("Data/#{map}.rxdata")
  314.       @map_type   = 'XP'
  315.       mapsize     = [@map,@mapxp_data].collect {|m| [m.width,m.height]}
  316.       if mapsize.uniq.size > 1
  317.         raise "The dimension on #{map}.rxdata #{mapsize[0].inspect} \n"+
  318.            "and #{map}.#{ext} #{mapsize[1].inspect} is not same"
  319.       end
  320.       @tilesetxp_id    = @mapxp_data.tileset_id
  321.       @tileset_name    = tileset_xp.tileset_name
  322.       @autotile_names  = tileset_xp.autotile_names
  323.       @panorama_name   = tileset_xp.panorama_name
  324.       @panorama_hue    = tileset_xp.panorama_hue
  325.       @fog_name        = tileset_xp.fog_name
  326.       @fog_hue         = tileset_xp.fog_hue
  327.       @fog_opacity     = tileset_xp.fog_opacity
  328.       @fog_blend_type  = tileset_xp.fog_blend_type
  329.       @fog_zoom        = tileset_xp.fog_zoom
  330.       @fog_sx          = tileset_xp.fog_sx
  331.       @fog_sy          = tileset_xp.fog_sy
  332.       @battleback_name = tileset_xp.battleback_name
  333.       @passages        = tileset_xp.passages
  334.       @priorities      = tileset_xp.priorities
  335.       @terrain_tags    = tileset_xp.terrain_tags
  336.       if ext == 'rvdata2'
  337.         tileset_xp.tileset_names = tileset.tileset_names
  338.         tileset_xp.flags         = tileset.flags
  339.         tileset_xp.mode          = tileset.mode
  340.         tileset_xp.note          = tileset.note
  341.       end
  342.     else
  343.       @map             = load_data("Data/#{map}.#{ext}")
  344.       @mapxp_data      = @map
  345.       @map_type        = 'VX'
  346.       @tileset_name    = ''
  347.       @autotile_names  = ['']*7
  348.       @battleback_name = ''
  349.       @passages        = Table.new(384)  if ext == 'rvdata2'
  350.       @priorities      = Table.new(384)
  351.       @terrain_tags    = Table.new(384)
  352.       clear_panorama
  353.       clear_fog
  354.     end
  355.     reset_fog_variable
  356.   end
  357.   #--------------------------------------------------------------------------
  358.   # * New Method : reset_fog_variable
  359.   #--------------------------------------------------------------------------
  360.   def reset_fog_variable
  361.     @fog_ox               = 0
  362.     @fog_oy               = 0
  363.     @fog_tone             = Tone.new(0, 0, 0, 0)
  364.     @fog_tone_target      = Tone.new(0, 0, 0, 0)
  365.     @fog_tone_duration    = 0
  366.     @fog_opacity_duration = 0
  367.     @fog_opacity_target   = 0
  368.   end
  369.   #--------------------------------------------------------------------------
  370.   # * New Method : start_fog_tone_change
  371.   #--------------------------------------------------------------------------
  372.   def start_fog_tone_change(tone, duration)
  373.     @fog_tone_target = tone.clone
  374.     @fog_tone_duration = duration
  375.     if @fog_tone_duration == 0
  376.       @fog_tone = @fog_tone_target.clone
  377.     end
  378.   end
  379.   #--------------------------------------------------------------------------
  380.   # * New Method : start_fog_opacity_chang
  381.   #--------------------------------------------------------------------------
  382.   def start_fog_opacity_change(opacity, duration)
  383.     @fog_opacity_target = opacity * 1.0
  384.     @fog_opacity_duration = duration
  385.     if @fog_opacity_duration == 0
  386.       @fog_opacity = @fog_opacity_target
  387.     end
  388.   end
  389.   #--------------------------------------------------------------------------
  390.   # * New Method : change_panorama
  391.   #--------------------------------------------------------------------------
  392.   def change_panorama(panorama_name = '',panorama_hue = 0)
  393.     @panorama_name = panorama_name
  394.     @panorama_hue  = panorama_hue
  395.   end
  396.   #--------------------------------------------------------------------------
  397.   # * New Method : clear_panorama
  398.   #--------------------------------------------------------------------------
  399.   def clear_panorama(*args)
  400.     change_panorama
  401.   end
  402.   #--------------------------------------------------------------------------
  403.   # * New Method : change_fog
  404.   #--------------------------------------------------------------------------
  405.   def change_fog(fog_name = '',fog_hue = 0,fog_opacity = 60,
  406.        fog_blend_type = 0,fog_zoom = 1.0,fog_sx = 0,fog_sy = 0)
  407.     @fog_name       = fog_name
  408.     @fog_hue        = fog_hue
  409.     @fog_opacity    = fog_opacity
  410.     @fog_blend_type = fog_blend_type
  411.     @fog_zoom       = fog_zoom
  412.     @fog_sx         = fog_sx
  413.     @fog_sy         = fog_sy
  414.   end
  415.   #--------------------------------------------------------------------------
  416.   # * New Method : clear_fog
  417.   #--------------------------------------------------------------------------
  418.   def clear_fog(*args)
  419.     change_fog
  420.   end
  421.   #--------------------------------------------------------------------------
  422.   # * New Method : update_fog
  423.   #--------------------------------------------------------------------------
  424.   def update_fog
  425.     return reset_fog_variable if @fog_ox.nil?
  426.     @fog_ox -= @fog_sx / 8.0
  427.     @fog_oy -= @fog_sy / 8.0
  428.     if @fog_tone_duration >= 1
  429.       d = @fog_tone_duration
  430.       target = @fog_tone_target
  431.       @fog_tone.red   = (@fog_tone.red * (d - 1) + target.red) / d
  432.       @fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d
  433.       @fog_tone.blue  = (@fog_tone.blue * (d - 1) + target.blue) / d
  434.       @fog_tone.gray  = (@fog_tone.gray * (d - 1) + target.gray) / d
  435.       @fog_tone_duration -= 1
  436.     end
  437.     if @fog_opacity_duration >= 1
  438.       d = @fog_opacity_duration
  439.       @fog_opacity  = (@fog_opacity * (d - 1) + @fog_opacity_target) / d
  440.       @fog_opacity_duration -= 1
  441.     end
  442.   end
  443. end
  444. #==============================================================================
  445. # ** Game_Character
  446. #------------------------------------------------------------------------------
  447. #  A character class with mainly movement route and other such processing
  448. # added. It is used as a super class of Game_Player, Game_Follower,
  449. # GameVehicle, and Game_Event.
  450. #==============================================================================
  451.  
  452. class Game_Character
  453.   #--------------------------------------------------------------------------
  454.   # * Overwriten Method : map_passable?
  455.   #--------------------------------------------------------------------------
  456.   def map_passable?(*args)
  457.     args << 0 if args.size == 2 && $game_map.map_type == 'XP'
  458.     test = $game_map.passable?(*args)
  459.   end
  460.   #--------------------------------------------------------------------------
  461.   # * Determine Tile
  462.   #--------------------------------------------------------------------------
  463.   unless method_defined?(:tile?)
  464.     def tile?
  465.       @tile_id > 0 && @priority_type == 0
  466.     end
  467.   end
  468.   #--------------------------------------------------------------------------
  469.   # * Aliased Method: screen_z
  470.   #--------------------------------------------------------------------------
  471.   alias map_xp_screen_z screen_z
  472.   def screen_z
  473.     result = map_xp_screen_z
  474.     # result += 156 if $game_map.map_type == 'XP'
  475.     return result
  476.   end
  477. end
  478. #==============================================================================
  479. # ** Game_Player
  480. #------------------------------------------------------------------------------
  481. #  This class handles the player. It includes event starting determinants and
  482. # map scrolling functions. The instance of this class is referenced by
  483. # $game_player.
  484. #==============================================================================
  485.  
  486. class Game_Player < Game_Character
  487.   #--------------------------------------------------------------------------
  488.   # * Alias Method
  489.   #--------------------------------------------------------------------------
  490.   alias xploader_map_passable map_passable?
  491.   #--------------------------------------------------------------------------
  492.   # * Determine if Map is Passable
  493.   #     d:  Direction (2,4,6,8)
  494.   #--------------------------------------------------------------------------
  495.   def map_passable?(*args)
  496.     if !Game_Map::VXA && $game_map.map_type == 'XP' &&
  497.       ![0,1,2].include?(@vehicle_type)
  498.       return super(*args)
  499.     end
  500.     xploader_map_passable(*args)
  501.   end
  502. end
  503.  
  504. #==============================================================================
  505. # ** Spriteset_Map
  506. #------------------------------------------------------------------------------
  507. #  This class brings together map screen sprites, tilemaps, etc. It's used
  508. # within the Scene_Map class.
  509. #==============================================================================
  510. class Spriteset_Map
  511.   #--------------------------------------------------------------------------
  512.   # * Public Instance Variables
  513.   #--------------------------------------------------------------------------
  514.   attr_reader :tilemap, :viewport1
  515.   #--------------------------------------------------------------------------
  516.   # * Constant Variables
  517.   #--------------------------------------------------------------------------
  518.   @@ltileset_exist = method_defined?(:load_tileset)
  519.   #--------------------------------------------------------------------------
  520.   # * Alias Method
  521.   #--------------------------------------------------------------------------
  522.   alias spriteset_map_vxaxp_create_tilemap    create_tilemap
  523.   alias spriteset_map_vxaxp_dispose_tilemap   dispose_tilemap
  524.   alias spriteset_map_vxaxp_dispose_viewports dispose_viewports
  525.   alias spriteset_map_vxaxp_update_tilemap    update_tilemap
  526.   alias spriteset_map_vxaxp_update_tileset    update_tileset if @@ltileset_exist
  527.   alias spriteset_map_vxaxp_load_tileset      load_tileset   if @@ltileset_exist
  528.   #--------------------------------------------------------------------------
  529.   # * Aliased Method : create_tilemap
  530.   #--------------------------------------------------------------------------
  531.   def create_tilemap
  532.     @map_type = $game_map.map_type
  533.     if @map_type == 'VX'
  534.       spriteset_map_vxaxp_create_tilemap
  535.     else
  536.       if $game_temp.tilemap == nil  
  537.         load_tileset
  538.       else
  539.         @tilemap = $game_temp.tilemap.clone
  540.         @viewport1.dispose if !@viewport1.nil?
  541.         @viewport1 = @tilemap.viewport
  542.         $game_temp.tilemap = nil
  543.       end
  544.     end
  545.   end  
  546.   #--------------------------------------------------------------------------
  547.   # * Aliased Method : load_tileset
  548.   #--------------------------------------------------------------------------
  549.   def load_tileset
  550.     if @map_type == 'VX'
  551.       spriteset_map_vxaxp_load_tileset if @@ltileset_exist
  552.     else
  553.       @tilemap.dispose if @tilemap
  554.       autotiles = []
  555.       for i in 0..6
  556.         autotile_name = $game_map.autotile_names[i].dup
  557.         autotiles << Cache.autotile(autotile_name)
  558.       end
  559.       tileset = Cache.tileset($game_map.tileset_name)
  560.       @tilemap = Tilemap_New.new(@viewport1,tileset,autotiles)
  561.       update_tilemap_position
  562.       @tilemap.update_all
  563.     end
  564.   end
  565.   #--------------------------------------------------------------------------
  566.   # * Aliased Method : dispose_tilemap
  567.   #--------------------------------------------------------------------------
  568.   def dispose_tilemap
  569.     if @map_type == 'VX'
  570.       spriteset_map_vxaxp_dispose_tilemap
  571.     else
  572.       @tilemap.tileset.dispose
  573.       @tilemap.autotiles.compact.each {|autotile| autotile.dispose }
  574.       if $game_temp.store_tilemap == true
  575.         $game_temp.tilemap = @tilemap.clone
  576.         $game_temp.store_tilemap = false
  577.       else
  578.         @tilemap.dispose
  579.         @viewport1.dispose
  580.       end
  581.     end
  582.     dispose_fog
  583.     dispose_panorama
  584.   end
  585.   #--------------------------------------------------------------------------
  586.   # * Aliased Method : dispose_viewports
  587.   #--------------------------------------------------------------------------
  588.   def dispose_viewports
  589.     if @map_type == 'VX'
  590.       spriteset_map_vxaxp_dispose_viewports
  591.     else
  592.       @viewport2.dispose
  593.       @viewport3.dispose
  594.     end
  595.   end
  596.   #--------------------------------------------------------------------------
  597.   # * Aliased Method : update_tileset
  598.   #--------------------------------------------------------------------------
  599.   def update_tileset
  600.     if @map_type == 'VX'
  601.       spriteset_map_vxaxp_update_tileset
  602.     elsif @map_id != $game_map.map_id
  603.       @map_id = $game_map.map_id
  604.       load_tileset
  605.       refresh_characters
  606.     end
  607.   end
  608.   #--------------------------------------------------------------------------
  609.   # * Aliased Method : update_tilemap
  610.   #--------------------------------------------------------------------------
  611.   def update_tilemap
  612.     if @map_type == 'VX'
  613.       spriteset_map_vxaxp_update_tilemap
  614.     end
  615.     if @map_type != 'VX'
  616.       update_tilemap_position
  617.       @tilemap.update
  618.     end
  619.     update_panorama
  620.     update_fog    
  621.   end
  622.   #--------------------------------------------------------------------------
  623.   # * New Method : update_tilemap_position
  624.   #--------------------------------------------------------------------------
  625.   def update_tilemap_position
  626.     @tilemap.ox = $game_map.display_x / 4
  627.     @tilemap.oy = $game_map.display_y / 4
  628.     @tilemap.ox = $game_map.display_x / 8
  629.     @tilemap.oy = $game_map.display_y / 8
  630.     @tilemap.ox = $game_map.display_x * 32 if Game_Map::VXA
  631.     @tilemap.oy = $game_map.display_y * 32 if Game_Map::VXA
  632.   end
  633.   #--------------------------------------------------------------------------
  634.   # * New Method : create_fog
  635.   #--------------------------------------------------------------------------
  636.   def create_fog
  637.     @fog = Plane.new(@viewport1)
  638.     @fog.z = 3000
  639.   end
  640.   #--------------------------------------------------------------------------
  641.   # * New Method : create_panorama
  642.   #--------------------------------------------------------------------------
  643.   def create_panorama
  644.     @panorama = Plane.new(@viewport1)
  645.     @panorama.z = -1000
  646.   end
  647.   #--------------------------------------------------------------------------
  648.   # * New Method : dispose_fog
  649.   #--------------------------------------------------------------------------
  650.   def dispose_fog
  651.     @fog.dispose if !@fog.nil? && !@fog.disposed?
  652.   end
  653.   #--------------------------------------------------------------------------
  654.   # * New Method : dispose_panorama
  655.   #--------------------------------------------------------------------------
  656.   def dispose_panorama
  657.     @panorama.dispose if !@panorama.nil? && !@panorama.disposed?
  658.   end
  659.   #--------------------------------------------------------------------------
  660.   # * New Method : update_panorama
  661.   #--------------------------------------------------------------------------
  662.   def update_panorama
  663.     if @panorama_name != $game_map.panorama_name or
  664.        @panorama_hue != $game_map.panorama_hue or @panorama.nil?
  665.       @panorama_name = $game_map.panorama_name
  666.       @panorama_hue = $game_map.panorama_hue
  667.       dispose_panorama
  668.       create_panorama
  669.       if @panorama_name != ""
  670.         @panorama.bitmap = Cache.panorama(@panorama_name, @panorama_hue)
  671.       end
  672.       Graphics.frame_reset
  673.     end
  674.     return if @panorama_name == ''
  675.     disp_x       = $game_map.display_x / 4
  676.     disp_y       = $game_map.display_y / 4
  677.     disp_x       = $game_map.display_x / 8
  678.     disp_y       = $game_map.display_y / 8
  679.     disp_x       = $game_map.display_x * 32 if Game_Map::VXA
  680.     disp_y       = $game_map.display_y * 32 if Game_Map::VXA
  681.     @panorama.ox = $game_map.display_x / 8
  682.     @panorama.oy = $game_map.display_y / 8
  683.   end
  684.   #--------------------------------------------------------------------------
  685.   # * New Method : update_fog
  686.   #--------------------------------------------------------------------------
  687.   def update_fog
  688.     if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue or
  689.       @fog.nil?
  690.       @fog_name = $game_map.fog_name
  691.       @fog_hue = $game_map.fog_hue
  692.       dispose_fog
  693.       create_fog
  694.       if @fog_name != ""
  695.         @fog.bitmap = Cache.fog(@fog_name, @fog_hue)
  696.       end
  697.       Graphics.frame_reset
  698.     end
  699.     return if @fog_name == ''
  700.     zoom            = $game_map.fog_zoom
  701.     zoom           /= 100 if zoom.is_a?(Integer)
  702.     @fog.zoom_x     = zoom
  703.     @fog.zoom_y     = zoom
  704.     @fog.opacity    = $game_map.fog_opacity
  705.     @fog.blend_type = $game_map.fog_blend_type
  706.     disp_x          = $game_map.display_x / 4
  707.     disp_y          = $game_map.display_y / 4
  708.     disp_x          = $game_map.display_x / 8
  709.     disp_y          = $game_map.display_y / 8
  710.     disp_x          = $game_map.display_x * 32 if Game_Map::VXA
  711.     disp_y          = $game_map.display_y * 32 if Game_Map::VXA
  712.     @fog.ox         = disp_x + $game_map.fog_ox
  713.     @fog.oy         = disp_y + $game_map.fog_oy
  714.     @fog.tone       = $game_map.fog_tone
  715.   end
  716. end
  717.  
  718. #==============================================================================
  719. # ** Game_Temp EDIT
  720. #------------------------------------------------------------------------------
  721. #  Addon for saving the tilemap upon switching scene.
  722. #==============================================================================
  723.  
  724. class Game_Temp
  725.   #--------------------------------------------------------------------------
  726.   # * Public Instance Variable
  727.   #--------------------------------------------------------------------------
  728.   attr_accessor :store_tilemap
  729.   attr_accessor :tilemap
  730.   #--------------------------------------------------------------------------
  731.   # * Alias Initialize EDIT (flag & slot for temporarily storing the tilemap)
  732.   #--------------------------------------------------------------------------
  733.   alias init_later initialize
  734.   #--------------------------------------------------------------------------
  735.   # * Initialize
  736.   #--------------------------------------------------------------------------
  737.   def initialize
  738.     init_later
  739.     setup_map_type_change
  740.   end
  741.   #--------------------------------------------------------------------------
  742.   # * setup_map_type_change
  743.   #--------------------------------------------------------------------------
  744.   def setup_map_type_change
  745.     @store_tilemap = false # Storage flag
  746.     @tilemap       = nil # Storage slot
  747.   end
  748. end
  749. #==============================================================================
  750. # ** Game_Map EDIT (extra)
  751. #------------------------------------------------------------------------------
  752. #  Enhances the class Game_Map in order to presort tiles by priority; used for
  753. #  tilemap tone.
  754. #==============================================================================
  755.  
  756. class Game_Map
  757.   #--------------------------------------------------------------------------
  758.   # * Public Instance Variables
  759.   #--------------------------------------------------------------------------
  760.   attr_reader   :map                 # Map-Daten
  761.   attr_reader   :tone                # Color-Tone
  762.   attr_accessor :need_redraw
  763.   #--------------------------------------------------------------------------
  764.   # * Alias Method
  765.   #--------------------------------------------------------------------------
  766.   alias init_later initialize
  767.   alias setup_later setup
  768.   alias upd_later update
  769.   #--------------------------------------------------------------------------
  770.   # * Aliased Method : initialize
  771.   #--------------------------------------------------------------------------
  772.   def initialize
  773.     init_later
  774.     @tone          = Tone.new(0,0,0,0) # Tilemap-tone
  775.     @tone_duration = 0                 # Tone-duration
  776.     @need_redraw   = false
  777.   end
  778.   #--------------------------------------------------------------------------
  779.   # * Aliased Method : setup
  780.   #--------------------------------------------------------------------------
  781.   def setup(map_id)
  782.     setup_later(map_id)
  783.     sort_priority        # Sort tiles after setup
  784.   end
  785.   #--------------------------------------------------------------------------
  786.   # * Aliased Method : update (executes tone change)
  787.   #--------------------------------------------------------------------------
  788.   def update(*args)
  789.     update_tone_change
  790.     upd_later(*args)
  791.     update_need_redraw
  792.   end
  793.   #--------------------------------------------------------------------------
  794.   # * New Method : update_tone_change
  795.   #--------------------------------------------------------------------------
  796.   def update_tone_change
  797.     if @tone_duration && @tone_duration >= 1
  798.       d = @tone_duration
  799.       @tone.red = (@tone.red * (d - 1) + @tone_target.red) / d
  800.       @tone.green = (@tone.green * (d - 1) + @tone_target.green) / d
  801.       @tone.blue = (@tone.blue * (d - 1) + @tone_target.blue) / d
  802.       @tone.gray = (@tone.gray * (d - 1) + @tone_target.gray) / d
  803.       @tone_duration -= 1
  804.     end
  805.   end
  806.   #--------------------------------------------------------------------------
  807.   # * New Method : update_need_redraw
  808.   #--------------------------------------------------------------------------
  809.   def update_need_redraw
  810.     if @need_redraw && SceneManager.scene.is_a?(Scene_Map)
  811.       sort_priority
  812.       SceneManager.scene.load_tileset
  813.       @need_redraw = false
  814.     end
  815.   end
  816.   #--------------------------------------------------------------------------
  817.   # * New Method : sort_priority
  818.   #--------------------------------------------------------------------------
  819.   def sort_priority
  820.     # One hash for every priority
  821.     @priority0 = {}
  822.     @priority1 = {}
  823.     @priority2 = {}
  824.     @priority3 = {}
  825.     @priority4 = {}
  826.     @priority5 = {}
  827.     # Iterate through tiles on x-axis
  828.     for x in 0...width
  829.       # Iterate through tiles on y-axis
  830.       for y in 0...height
  831.         # Check layers from map editor top->bottom
  832.         for z in $game_map.z_data#[2,1,0]
  833.           # Tile ID
  834.           tile = data[x,y,z] || 0
  835.           # If tile is not empty
  836.           if tile != 0
  837.             # Get & check priority for tile, set in according hash
  838.             case @priorities[tile]
  839.             when 0
  840.               @priority0[y] = {} if @priority0[y] == nil
  841.               @priority0[y][x] = {} if @priority0[y][x] == nil
  842.               @priority0[y][x][z] = tile
  843.             when 1
  844.               @priority1[y] = {} if @priority1[y] == nil
  845.               @priority1[y][x] = {} if @priority1[y][x] == nil
  846.               @priority1[y][x][z] = tile
  847.             when 2
  848.               @priority2[y] = {} if @priority2[y] == nil
  849.               @priority2[y][x] = {} if @priority2[y][x] == nil
  850.               @priority2[y][x][z] = tile
  851.             when 3
  852.               @priority3[y] = {} if @priority3[y] == nil
  853.               @priority3[y][x] = {} if @priority3[y][x] == nil
  854.               @priority3[y][x][z] = tile
  855.             when 4
  856.               @priority4[y] = {} if @priority4[y] == nil
  857.               @priority4[y][x] = {} if @priority4[y][x] == nil
  858.               @priority4[y][x][z] = tile
  859.             when 5
  860.               @priority5[y] = {} if @priority5[y] == nil
  861.               @priority5[y][x] = {} if @priority5[y][x] == nil
  862.               @priority5[y][x][z] = tile
  863.             end
  864.           end
  865.         end
  866.       end
  867.     end
  868.   end
  869.   #--------------------------------------------------------------------------
  870.   # * New Method : priority_data
  871.   #--------------------------------------------------------------------------  
  872.   def priority_data(priority)
  873.     # Check priority and return appropriate sorted hash
  874.     case priority
  875.     when 0
  876.       return @priority0
  877.     when 1
  878.       return @priority1
  879.     when 2
  880.       return @priority2
  881.     when 3
  882.       return @priority3
  883.     when 4
  884.       return @priority4
  885.     when 5
  886.       return @priority5
  887.     else
  888.       # Invalid priority: return hash 0
  889.       return @priority0
  890.     end
  891.   end
  892.   #--------------------------------------------------------------------------
  893.   # * New Method : start_tone_change
  894.   #--------------------------------------------------------------------------  
  895.   def start_tone_change(tone, duration)
  896.     @tone_target = tone.clone
  897.     @tone_duration = duration
  898.     if @tone_duration == 0
  899.       @tone = @tone_target.clone
  900.     end
  901.   end
  902.   #--------------------------------------------------------------------------
  903.   # * New Method : change_tile
  904.   #--------------------------------------------------------------------------
  905.   def change_tile(x,y,i,new_tile)
  906.     return if data[x,y,i] == new_tile
  907.     data[x,y,i] = new_tile
  908.     @need_redraw = true
  909.   end
  910. end
  911.  
  912. #==============================================================================
  913. # ** Scene_Map
  914. #------------------------------------------------------------------------------
  915. #  This class performs the map screen processing.
  916. #==============================================================================
  917. class Scene_Map < Scene_Base
  918.   #--------------------------------------------------------------------------
  919.   # * Constant
  920.   #--------------------------------------------------------------------------
  921.   @@post_transfer = method_defined?(:post_transfer)
  922.   #--------------------------------------------------------------------------
  923.   # * Alias Method
  924.   #--------------------------------------------------------------------------
  925.   alias spriteset_switch_terminate terminate
  926.   alias spriteset_switch_post_transfer post_transfer if @@post_transfer        
  927.   alias spriteset_switch_pre_transfer pre_transfer   if @@post_transfer  
  928.   alias spriteset_switch_pre_transfer update_transfer_player if !@@post_transfer
  929.   #--------------------------------------------------------------------------
  930.   # * Aliased Method : update_transfer_player
  931.   #--------------------------------------------------------------------------
  932.   if !@@post_transfer
  933.     def update_transfer_player
  934.       return unless $game_player.transfer?
  935.       pre_transfer
  936.     end
  937.   end
  938.   #--------------------------------------------------------------------------
  939.   # * Aliased Method : terminate
  940.   #--------------------------------------------------------------------------
  941.   def terminate
  942.     $game_temp.store_tilemap = true
  943.     spriteset_switch_terminate
  944.   end
  945.   #--------------------------------------------------------------------------
  946.   # * Aliased Method : pre_transfer
  947.   #--------------------------------------------------------------------------
  948.   def pre_transfer
  949.     if @new_map_id == $game_map.map_id
  950.       $game_temp.store_tilemap = true
  951.     end
  952.     @map_type = $game_map.map_type
  953.     spriteset_switch_pre_transfer
  954.   end
  955.   #--------------------------------------------------------------------------
  956.   # * Aliased Method : post_transfer
  957.   #--------------------------------------------------------------------------
  958.   def post_transfer
  959.     if @map_type != $game_map.map_type
  960.       dispose_spriteset
  961.       create_spriteset
  962.       @map_type = $game_map.map_type
  963.     end
  964.     spriteset_switch_post_transfer
  965.   end
  966.   #--------------------------------------------------------------------------
  967.   # * New Method : load_tileset
  968.   #--------------------------------------------------------------------------
  969.   def load_tileset
  970.     @spriteset.load_tileset
  971.   end
  972. end
  973.  
  974. #============================================================================
  975. # ** Tilemap Enchance v.0.75 (RGSS3 Version)
  976. #============================================================================
  977. #  
  978. #  HEAVILY EDITED !!!!!
  979. #
  980. #
  981. # This script serves as a complete standard tilemap class replacement and
  982. # enables you to access single layers. It's got some new special features
  983. # as well.
  984. # Basically the script works flawlessly, something that can't be said of most
  985. # other tilemap rewrites.
  986. #
  987. # 1. Installation
  988. #
  989. # Paste the script above main but below the standard scripts.
  990. #
  991. # 2. Functional Principle
  992. #
  993. # Upon entering a map the script loads the new class Tilemap_New instead of Tilemap.
  994. # A sprite with bitmap is created for every row of the map in y (from 0 to the
  995. # bottom). There's an additional distinction between the single priority settings and
  996. # tiles/autotiles. So the tiles are pre-cached and not drawn new during the game.
  997. # This requires lots of RAM and increases the maps' load times slightly but improves
  998. # performance as well!
  999. #
  1000. # 3. Benefit
  1001. #
  1002. # You can directly modify the display process of tiles now, or modify the tile
  1003. # graphics themselves. Three built-in features are:
  1004. # Blend types for autotiles (normal, add, sub; useful for certain water/light effects)
  1005. # Changeable animation speed of autotiles as well as a color tone for the tilemap alone.
  1006. # Other purposes would be a screen size script. My tilemap class is especially suited
  1007. # for those due to the performance not diminishing at higher resolutions, or just
  1008. # marginally.
  1009. #
  1010. # 4. Usage
  1011. #
  1012. # The script is automatically used after inserting it, however special
  1013. # features need to be activated seperately:
  1014. #
  1015. # - Autotile blend_type/speed:
  1016. # Configuration via the module Autotile below this introduction.
  1017. # Possible values for blend_type are 0 (normal), 1 (add), 2 (sub), for
  1018. # speed every integer can be used. Small numbers mean faster animation
  1019. # (0 = each frame).
  1020. # Configuration like so: MAP_ID=>{AUTOTILE_ID=>BLEND_TYPE/BLEND_SPEED} in the
  1021. # respective section BLEND_TYPE respectively SPEED. Examples are given.
  1022. # ID goes from 0 to 6 (left to right in the tileset).
  1023. #
  1024. # DEFAULT_SPEED is the speed used in case SPEED doesn't contain a value for a map
  1025. # or an autotile.
  1026. #
  1027. # - Tilemap-Tone:
  1028. # Can be accessed via Call Script or in a script. Use this command:
  1029. #
  1030. # $game_map.start_tone_change(tone,duration)
  1031. #
  1032. # Whereas tone = Tone.new(r,g,b,gr). This tone affects tiles and autotiles only,
  1033. # screen color tone can still be added seperately.
  1034. #
  1035. # 5. Restrictions
  1036. #
  1037. # - Post hoc changes of tile data in the script doesn't have an effect
  1038. # in this version yet (e.g. via $game_map.data)
  1039. #
  1040. # - High memory consumption. Depending on the map size and usage of autotiles
  1041. # the memory needed can add up to 800 MB. (200*200 map, 1 layer filled with
  1042. # normal tiles, 1 layer filled with 4 frames autotile)
  1043. # Realistic footprint accounts to 500 MB max, 512 MB RAM recommended for maps
  1044. # bigger than 100*100!
  1045. #
  1046. # - Increased loading time. Depending on the map size and usage of autotiles
  1047. # loading time ranges from 0 to 6 seconds. Small maps (30*30) are loaded
  1048. # instantly, 60*60 with autotiles ca. 1 second, 100*100 with autotiles 2 seconds,
  1049. # 200*200 map, 1 layer filled with normal tiles, 1 layer filled with 4 frames
  1050. # autotiles 6 seconds.
  1051. #
  1052. # - A teleport to the current map leads to a graphical glitch.
  1053. #
  1054. # 6. Pros
  1055. #
  1056. # - Full access to all sprites on a map
  1057. # - Autotile Blend_types and variable speed
  1058. # - Autotile-Blend_types und variable Geschwindigkeit
  1059. # - Great performance at memory's cost
  1060. # - Full functionality (see Restrictions for exceptions)
  1061. # - Lag doesn't increase when using higher resolutions
  1062. #
  1063. #
  1064. # 7. Credits
  1065. #
  1066. # Credits to GodLike for the Cache extension
  1067. # English translation by Terv (that's me!)
  1068. # Feel free to use and modify as you like, however be sure to give credit.
  1069. #
  1070. # 8. Changelog
  1071. #
  1072. # V 0.75:
  1073. #
  1074. # - Compatibility for RGSS3 added
  1075. # - Load time slightly decreased
  1076. # - General performance improved
  1077. # - Small display errors caused by specific autotile combinations fixed
  1078. #
  1079. # 9. Contact
  1080. #
  1081. # Questions, ideas, bug reports? Please drop me an email: admin@envile-media.at
  1082. #
  1083. #
  1084. #============================================================================
  1085. #==============================================================================
  1086. # ** Module Autotile
  1087. #------------------------------------------------------------------------------
  1088. #  
  1089. #  This module contains autotile configurations.
  1090. #  
  1091. #==============================================================================
  1092. module AUTOTILE
  1093.  
  1094.   # MAP_ID => { AUTOTILE_ID => BLEND_TYPE,.. }
  1095.   BLEND_TYPE = {
  1096.                 4=>{5=>1,6=>2},
  1097.                }
  1098.  
  1099.   # MAP_ID => { AUTOTILE_ID => SPEED,.. }
  1100.   SPEED = {
  1101.             4=>{4=>2},
  1102.           }
  1103.  
  1104.   # DEFAULT_SPEED
  1105.   DEFAULT_SPEED = 4
  1106.  
  1107. end
  1108.  
  1109. #==============================================================================
  1110. # ** Sprite_Auto NEW
  1111. #------------------------------------------------------------------------------
  1112. #
  1113. #  This class manages autotiles layers. Every layer contains multiple sprites,
  1114. #  one for each autotile column. Furthermore generates respective bitmaps for
  1115. #  the layer.
  1116. #
  1117. #==============================================================================
  1118. class Sprite_Auto
  1119.   #--------------------------------------------------------------------------
  1120.   # * Public Instance Variables
  1121.   #--------------------------------------------------------------------------
  1122.   attr_reader :cache2
  1123.   #--------------------------------------------------------------------------
  1124.   # * Initialize (read tiles, create sprites & bitmaps)
  1125.   #--------------------------------------------------------------------------
  1126.   def initialize(viewport,tiles,speed,autotile_frames,priority,blend_type)
  1127.     # Store autotile data
  1128.     @tiles = tiles
  1129.     @tileset_id = $game_map.tileset_id
  1130.     @tileset = Cache.tileset($game_map.tileset_name)
  1131.     @speed = speed
  1132.     @priority = priority
  1133.     @autotile_frames = autotile_frames
  1134.     @frames = autotile_frames[tiles[0]]
  1135.     @priorities = $game_map.priorities
  1136.     @blend_type = blend_type
  1137.     @viewport = viewport
  1138.     # Animation variables
  1139.     @time = 0
  1140.     @state = -1
  1141.     # Get number of tiles on x/y axis
  1142.     @width = $game_map.width
  1143.     @height = $game_map.height
  1144.     # Set layer border variables to l<->r and u<->d (changed max/min values)
  1145.     @border_lx = @width
  1146.     @border_ty = @height
  1147.     @border_rx = 0
  1148.     @border_by = 0
  1149.     # Set row borders
  1150.     @border_lx_row = @width
  1151.     @border_rx_row = 0
  1152.     # Create table for row borders
  1153.     @rows = Table.new(@height,2)
  1154.     # Hash for sprites & cache
  1155.     @sprites = {}
  1156.     @cache = {}
  1157.     @cache2 =  {}
  1158.     # If special blend_type
  1159.     if @blend_type != 0
  1160.       # Setup tiles accordingly
  1161.       setup_tiles_blend
  1162.     # Else: normal blendig
  1163.     else
  1164.       # Setup tiles
  1165.       setup_tiles
  1166.     end
  1167.     # Return if not valid
  1168.     return if !valid?
  1169.     # Otherwise, create sprites & bitmaps
  1170.     create_sprites
  1171.     # If special blend_type
  1172.     if @blend_type != 0
  1173.       # Draw blended tiles
  1174.       draw_tiles_blend
  1175.     else
  1176.       # Draw tiles
  1177.       draw_tiles
  1178.     end
  1179.     @tileset = nil
  1180.   end
  1181.   #--------------------------------------------------------------------------
  1182.   # * Valid? (checks whether found in tiles for this layer)
  1183.   #--------------------------------------------------------------------------
  1184.   def valid?
  1185.     # If right border greater or equal to left border and
  1186.     # top border greater or equal to bottom border then true
  1187.     return @border_rx >= @border_lx && @border_by >= @border_ty
  1188.   end
  1189.   #--------------------------------------------------------------------------
  1190.   # * Row_valid? (checks whether found in tiles in column y)
  1191.   #--------------------------------------------------------------------------
  1192.   def row_valid?(y)
  1193.     # If right border of row equal or greater to left border of row
  1194.     # then true
  1195.     return @rows[y,1] > @rows[y,0]
  1196.   end
  1197.   #--------------------------------------------------------------------------
  1198.   # * Setup_tiles_blend (reads tiles for this layer and defines the borders.
  1199.   # Makes use of special rules for reading)
  1200.   #--------------------------------------------------------------------------
  1201.   def setup_tiles_blend
  1202.     # Get pre-sorted tile data with priority of the layer
  1203.     @data_link = $game_map.priority_data(@priority)
  1204.     # Clone hashs, needed for functionally interation while deleting stuff
  1205.     # from the data
  1206.     @data = @data_link.dup
  1207.     @data_link.each_pair do |dx,data_x|
  1208.       dat_x = @data[dx]
  1209.       dat_x = data_x.dup
  1210.       data_x.each_pair do |dz,data_z|
  1211.         dat_x[dz] = data_z.dup
  1212.       end
  1213.     end
  1214.     tiles_found = false
  1215.     layer = 0
  1216.     # Iterate through sorted tiles on y-axis
  1217.     @data.each_pair do |y,data_y|
  1218.       # Iterate through sorted tiles on x-axis
  1219.       data_y.each_pair do |x,data_x|
  1220.         # Iterate through map editor layers downwards
  1221.         data_x.each_pair do |z,t|
  1222.           # Get Tile ID
  1223.           # Skip to next if there no tile
  1224.           next if t == nil
  1225.           # If tile fits properties of layer, only true if t is a autotile
  1226.           if @tiles.include?(t/48-1)
  1227.             # Add tile id to cache
  1228.             @cache[y] = {} if @cache[y] == nil
  1229.             @cache[y][x] = {} if @cache[y][x] == nil
  1230.             @cache[y][x][z] = t
  1231.             # Extend borders
  1232.             border(x,y)
  1233.             # Delete from map data list
  1234.             @data_link[y][x].delete(z)
  1235.             @data_link[y].delete(x) if @data_link[y][x].size == 0
  1236.             @data_link.delete(y) if @data_link[y].size == 0
  1237.             tiles_found = true
  1238.             layer = z
  1239.           end
  1240.         end
  1241.         if tiles_found == true
  1242.           if layer == 0
  1243.             for z in [1,2]
  1244.               t = data_x[z]
  1245.               next if t == nil || t < 384 || @priorities[t] != @priority
  1246.               @cache2[y] = {} if @cache2[y] == nil
  1247.               @cache2[y][x] = {} if @cache2[y][x] == nil
  1248.               @cache2[y][x][z] = t
  1249.               @data_link[y][x].delete(z)
  1250.               @data_link[y].delete(x) if @data_link[y][x].size == 0
  1251.               @data_link.delete(y) if @data_link[y].size == 0
  1252.             end
  1253.           elsif layer == 1
  1254.             t = data_x[2]
  1255.             next if t == nil || t < 384 || @priorities[t] != @priority
  1256.             @cache2[y] = {} if @cache2[y] == nil
  1257.             @cache2[y][x] = {} if @cache2[y][x] == nil
  1258.             @cache2[y][x][z] = t
  1259.             @data_link[y][x].delete(z)
  1260.             @data_link[y].delete(x) if @data_link[y][x].size == 0
  1261.             @data_link.delete(y) if @data_link[y].size == 0
  1262.           end
  1263.         end
  1264.       end
  1265.       # Set row borders
  1266.       @rows[y,0] = @border_lx_row
  1267.       @rows[y,1] = @border_rx_row
  1268.       # Re-Initialize row border temporaries for next iteraton
  1269.       @border_lx_row = @width/32
  1270.       @border_rx_row = 0
  1271.     end
  1272.   end
  1273.   #--------------------------------------------------------------------------
  1274.   # * Setup_tiles (reads tiles for this layer and defines the borders.
  1275.   # Makes use of special rules for reading)
  1276.   #--------------------------------------------------------------------------
  1277.   def setup_tiles
  1278.     # Get pre-sorted tile data with priority of the layer
  1279.     @data_link = $game_map.priority_data(@priority)
  1280.     # Clone hashs, needed for functionally interation while deleting stuff
  1281.     # from the data
  1282.     @data = @data_link.dup
  1283.     @data_link.each_pair do |dx,data_x|
  1284.       dat_x = @data[dx]
  1285.       dat_x = data_x.dup
  1286.       data_x.each_pair do |dz,data_z|
  1287.         dat_x[dz] = data_z.dup
  1288.       end
  1289.     end
  1290.     # Iterate through sorted tiles on y-axis
  1291.     @data.each_pair do |y,data_y|
  1292.       # Iterate through sorted tiles on x-axis
  1293.       data_y.each_pair do |x,data_x|
  1294.         # Initialize autotile found flag to false
  1295.         autotile_found = false
  1296.         # Iterate through map editor layers downwards
  1297.         data_x.each_pair do |z,t|
  1298.         # Iterate through map editor layers
  1299.           # Get tile id
  1300.           # Store whether tile fits layer properties or not
  1301.           # only true if t is a autotile
  1302.           tiles_include = @tiles.include?(t/48-1)
  1303.           # If tile is included or tile is from tileset or tile is autotile
  1304.           # with 1 frame
  1305.           if tiles_include || (t >= 384 || @autotile_frames[t/48-1] <= 1)
  1306.             # Store in cache
  1307.             @cache[y] = {} if @cache[y] == nil
  1308.             @cache[y][x] = {} if @cache[y][x] == nil
  1309.             @cache[y][x][z] = t
  1310.             # If tile is a autotile and is included
  1311.             if t < 384 && tiles_include
  1312.               # Delete from map data list
  1313.               @data_link[y][x].delete(z)
  1314.               @data_link[y].delete(x) if @data_link[y][x].size == 0
  1315.               @data_link.delete(y) if @data_link[y].size == 0
  1316.               # Extend borders
  1317.               border(x,y)
  1318.               # Set autotile found flag to true
  1319.               autotile_found = true
  1320.             end
  1321.           end
  1322.         end
  1323.         # If no autotile was found & row at y is not empty and x-position is not empty
  1324.         if autotile_found == false && @cache[y] != nil && @cache[y][x] != nil
  1325.           # Delete all tiles on x-position from cache
  1326.           @cache[y].delete(x)
  1327.           @cache.delete(y) if @data_link[y].size == 0  
  1328.         end
  1329.       end
  1330.       # Set row borders
  1331.       @rows[y,0] = @border_lx_row
  1332.       @rows[y,1] = @border_rx_row
  1333.       # Re-Initialize row border temporaries for next iteration
  1334.       @border_lx_row = @width/32
  1335.       @border_rx_row = 0
  1336.     end
  1337.   end
  1338.   #--------------------------------------------------------------------------
  1339.   # * Create_Sprites (creates sprites & mitmaps for every row)
  1340.   #--------------------------------------------------------------------------
  1341.   def create_sprites
  1342.     # Iterate through tiles on y-axis
  1343.     for y in @cache.keys
  1344.       # If row is not valid
  1345.       if !row_valid?(y)
  1346.         # skip to next
  1347.         next
  1348.       end
  1349.       # Calculate row width
  1350.       distx = @rows[y,1] - @rows[y,0]
  1351.       # Create sprite
  1352.       sprite = Sprite.new(@viewport)
  1353.       # Create bitmap with row-width*count of frames
  1354.       sprite.bitmap = Bitmap.new(distx*32*@frames,32)
  1355.       sprite.x = @rows[y,0]*32-$game_map.display_x/4
  1356.       sprite.y = y*32-$game_map.display_y/4
  1357.       # Set source rect to frame 0
  1358.       sprite.src_rect = Rect.new(0,0,distx*32,32)
  1359.       sprite.blend_type = @blend_type
  1360.       # If priority equals 0
  1361.       if @priority == 0
  1362.         # Set z to 0, always beyond later created layers
  1363.         sprite.z = 0
  1364.       else
  1365.         # Set z to base + priority + dosition - display-Position
  1366.         sprite.z = 32 + 32*@priority + 32*y - $game_map.display_y/4
  1367.        
  1368.       end
  1369.       # Add sprite to hash
  1370.       @sprites[y] = sprite
  1371.     end
  1372.   end
  1373.   #--------------------------------------------------------------------------
  1374.   # * Border (enhances the borders of the layer and the current row)
  1375.   #--------------------------------------------------------------------------
  1376.   def border(x,y)
  1377.     # If X is outside left border
  1378.     if x < @border_lx
  1379.       # Extend left border to x
  1380.       @border_lx = x
  1381.     end
  1382.     # If X is outside right border
  1383.     if x > @border_rx
  1384.       # Extend right border to x+1
  1385.       @border_rx = x+1
  1386.     end
  1387.     # If Y is outside top border
  1388.     if y < @border_ty
  1389.       # Extend top border to y
  1390.       @border_ty = y
  1391.     end
  1392.     # If Y is outside bottom border
  1393.     if y > @border_by
  1394.       # Extend bottom_border to y
  1395.       @border_by = y
  1396.     end
  1397.     # If X is outside left row border
  1398.     if x < @border_lx_row
  1399.       # Extend left row border to x
  1400.       @border_lx_row = x
  1401.     end
  1402.     # If X is outside right row border
  1403.     if x+1 > @border_rx_row
  1404.       # Extend right row border to y
  1405.       @border_rx_row = x+1
  1406.     end
  1407.   end
  1408.   #--------------------------------------------------------------------------
  1409.   # * Update (updates row's position in the image as well as animations)
  1410.   #--------------------------------------------------------------------------
  1411.   def update(ox,oy)
  1412.     # Get first and last row 1 outside screen
  1413.     dy = oy/32.0
  1414.     l = [dy.to_i-1,@border_ty].max
  1415.     r = [dy.to_i+17,@border_by].min
  1416.     # If time exceedes speed
  1417.     if @time > @speed
  1418.       # Reinit time, advance state
  1419.       @time = 0
  1420.       @state += 1
  1421.       # Iterate through every row on screen
  1422.       for i in l..r
  1423.         # Skip to next If row has no sprite
  1424.         sprite = @sprites[i]
  1425.         next if sprite == nil || sprite.disposed? || !$game_map.tone
  1426.         # Set sprite properties
  1427.         sprite.tone = $game_map.tone# if @blend_type == 0
  1428.         sprite.x = @rows[i,0]*32-ox
  1429.         sprite.y = i*32-oy
  1430.         # If priority equals 0
  1431.         if @priority == 0
  1432.           # Set Z to 0, always beyond later created tiles
  1433.           sprite.z = 0
  1434.         else
  1435.           # Set Z to Base + Priority + Position - Tilemap position
  1436.           sprite.z = 32 + 32*@priority + i*32 - oy
  1437.          
  1438.         end
  1439.         # Get row width
  1440.         lx = @rows[i,0]
  1441.         w = @rows[i,1] - lx
  1442.         # Set animation frame
  1443.         sprite.src_rect = Rect.new(@state*w*32,0,w*32,32)
  1444.       end
  1445.       # If state exceeded frame count
  1446.       if @state >= @frames-1
  1447.         # Reset state
  1448.         @state = -1
  1449.       end
  1450.     # Else: just update position
  1451.     else
  1452.       # Iterate through every row on screen
  1453.       for i in l..r
  1454.         # Skip to next if row has no sprite
  1455.         sprite = @sprites[i]
  1456.         next if sprite == nil || sprite.disposed? || !$game_map.tone
  1457.           # Set sprite properties
  1458.         sprite.tone = $game_map.tone# if @blend_type == 0
  1459.         sprite.x = @rows[i,0]*32-ox
  1460.         sprite.y = i*32-oy
  1461.         # If priority equals 0
  1462.         if @priority == 0
  1463.           # Set Z to 0, always beyond later created tiles
  1464.           sprite.z = 0
  1465.         else
  1466.           # Set Z to Base + Priority + Position - Tilemap position
  1467.           sprite.z = 32 + 32*@priority + i*32 - oy
  1468.          
  1469.         end
  1470.       end
  1471.     end
  1472.     # Advance time
  1473.     @time += 1
  1474.   end
  1475.   #--------------------------------------------------------------------------
  1476.   # * Update All (updates row's position in the image as well as animations)
  1477.   #--------------------------------------------------------------------------
  1478.   def update_all(ox,oy)
  1479.     # Get first and last row 1 outside screen
  1480.     dy = oy/32.0
  1481.     l = [dy.to_i-1,@border_ty].max
  1482.     r = [dy.to_i+17,@border_by].min
  1483.     # If time exceedes speed
  1484.     if @time > @speed
  1485.       # Reinit time, advance state
  1486.       @time = 0
  1487.       @state += 1
  1488.       # Iterate through every row on screen
  1489.       @sprites.each_key do |i|
  1490.         # Skip to next If row has no sprite
  1491.         sprite = @sprites[i]
  1492.         next if sprite == nil || sprite.disposed? || !$game_map.tone
  1493.         # Set sprite properties
  1494.         sprite.tone = $game_map.tone# if @blend_type == 0
  1495.         sprite.x = @rows[i,0]*32-ox
  1496.         sprite.y = i*32-oy
  1497.         # If priority equals 0
  1498.         if @priority == 0
  1499.           # Set Z to 0, always beyond later created tiles
  1500.           sprite.z = 0
  1501.         else
  1502.           # Set Z to Base + Priority + Position - Tilemap position
  1503.           sprite.z = 32 + 32*@priority + i*32 - oy
  1504.          
  1505.         end
  1506.         # Get row width
  1507.         lx = @rows[i,0]
  1508.         w = @rows[i,1] - lx
  1509.         # Set animation frame
  1510.         sprite.src_rect = Rect.new(@state*w*32,0,w*32,32)
  1511.       end
  1512.       # If state exceeded frame count
  1513.       if @state >= @frames-1
  1514.         # Reset state
  1515.         @state = -1
  1516.       end
  1517.     # Else: just update position
  1518.     else
  1519.       # Iterate through every row on screen
  1520.       @sprites.each_key do |i|
  1521.         # Skip to next if row has no sprite
  1522.         sprite = @sprites[i]
  1523.         next if sprite == nil || sprite.disposed? || !$game_map.tone
  1524.           # Set sprite properties
  1525.         sprite.tone = $game_map.tone# if @blend_type == 0
  1526.         sprite.x = @rows[i,0]*32-ox
  1527.         sprite.y = i*32-oy
  1528.         # If priority equals 0
  1529.         if @priority == 0
  1530.           # Set Z to 0, always beyond later created tiles
  1531.           sprite.z = 0
  1532.         else
  1533.           # Set Z to Base + Priority + Position - Tilemap position
  1534.           sprite.z = 32 + 32*@priority + i*32 - oy
  1535.         end
  1536.       end
  1537.     end
  1538.     # Advance time
  1539.     @time += 1
  1540.   end
  1541.   #--------------------------------------------------------------------------
  1542.   # * Refresh (refreshes all row's properties)
  1543.   #--------------------------------------------------------------------------
  1544.   def refresh
  1545.     # Iterate through all sprites
  1546.     for y in @cache.keys
  1547.       # Skip if sprite doesn't exist
  1548.       sprite = @sprites[y]
  1549.       next if sprite == nil
  1550.       sprite.tone = $game_map.tone
  1551.       # If priority equals 0
  1552.       sprite.x = @rows[y,0]*32-$game_map.display_x/4
  1553.       sprite.y = y*32-$game_map.display_y/4
  1554.       if @priority == 0
  1555.         # Set z to 0, always beyond
  1556.         sprite.z = 0
  1557.       else
  1558.         # Set Z to Base + Priority + Position - Screen Position
  1559.         sprite.z = 32+32*@priority+y*32-$game_map.display_y/4
  1560.        
  1561.       end
  1562.     end
  1563.   end
  1564.   #--------------------------------------------------------------------------
  1565.   # * Draw_tiles_blend (draws the complete layer in the single rows. Makes
  1566.   #  use of special rules for 1/2-blended autotiles)
  1567.   #--------------------------------------------------------------------------
  1568.   def draw_tiles_blend
  1569.     # Iterate through cached tiles on y axis
  1570.     @cache.each_pair do |y,cache_y|
  1571.       sprite = @sprites[y]
  1572.       next if cache_y == nil
  1573.       lx = @rows[y,0]
  1574.       w = @rows[y,1]-lx
  1575.       cache_y.each_pair do |x,cache_x|
  1576.         values_x = LiTTleDRAgo::RGSS3 ? cache_x.values.reverse : cache_x.values
  1577.         #cache_x.values.each do |t|
  1578.         #cache_x.values.reverse.each do |t| #RGSS3
  1579.         values_x.each do |t| #RGSS3
  1580.           file = (t / 48) - 1
  1581.           a = t - (file+1)*48
  1582.           for f in 0...@frames
  1583.             autotile = Cache.atile($game_map.autotile_names[file],a,f)
  1584.             sprite.bitmap.blt(-lx*32+x*32+f*w*32,0,autotile,autotile.rect)
  1585.           end
  1586.         end
  1587.       end
  1588.     end
  1589.     Cache.clear_auto
  1590.   end
  1591.   #--------------------------------------------------------------------------
  1592.   # * Draw Tiles
  1593.   #--------------------------------------------------------------------------
  1594.   def draw_tiles
  1595.     @cache.each_pair do |y,cache_y|
  1596.       sprite = @sprites[y]
  1597.       lx = @rows[y,0]
  1598.       w = @rows[y,1]-lx
  1599.       cache_y.each_pair do |x,cache_x|
  1600.         values_x = LiTTleDRAgo::RGSS3 ? cache_x.keys.reverse : cache_x.keys
  1601.         #cache_x.keys.each do |z|
  1602.         #cache_x.keys.reverse.each do |z| #RGSS3
  1603.         values_x.each do |z| #RGSS3
  1604.           t = cache_x[z]
  1605.           if t < 384
  1606.             file = (t / 48) - 1
  1607.             a = t - (file+1)*48
  1608.             for f in 0...@frames
  1609.               autotile = Cache.atile($game_map.autotile_names[file],a,f)
  1610.               sprite.bitmap.blt(-lx*32+x*32+f*w*32,0,autotile,autotile.rect)
  1611.             end
  1612.             if @autotile_frames[file] <= 1
  1613.               @data_link[y][x].delete(z)
  1614.               @data_link[y].delete(x) if @data_link[y][x].size == 0
  1615.               @data_link.delete(y) if @data_link[y].size == 0
  1616.             end
  1617.           else
  1618.             t -=384
  1619.             xt = t%8
  1620.             yt = t/8
  1621.             r = Rect.new(xt*32,yt*32,32,32)
  1622.             for f in 0...@frames
  1623.               sprite.bitmap.blt(-lx*32+x*32+f*w*32,0,@tileset,r)
  1624.             end
  1625.             @data_link[y][x].delete(z)
  1626.             @data_link[y].delete(x) if @data_link[y][x].size == 0
  1627.             @data_link.delete(y) if @data_link[y].size == 0
  1628.           end
  1629.         end
  1630.       end
  1631.     end
  1632.     Cache.clear_auto
  1633.   end
  1634.   #--------------------------------------------------------------------------
  1635.   # * Dispose Frame
  1636.   #--------------------------------------------------------------------------
  1637.   def dispose
  1638.     for sprite in @sprites.values
  1639.       sprite.dispose
  1640.     end
  1641.   end
  1642. end
  1643. #==============================================================================
  1644. # ** Cache
  1645. #------------------------------------------------------------------------------
  1646. #  This module loads graphics, creates bitmap objects, and retains them.
  1647. # To speed up load times and conserve memory, this module holds the
  1648. # created bitmap object in the internal hash, allowing the program to
  1649. # return preexisting objects when the same bitmap is requested again.
  1650. #==============================================================================
  1651. module Cache
  1652.   #--------------------------------------------------------------------------
  1653.   # * Constant
  1654.   #--------------------------------------------------------------------------
  1655.   @auto_cache = {}
  1656.     [[27,28,33,34],[5,28,33,34] ,[27,6,33,34] ,[5,6,33,34]  ,
  1657.     [27,28,33,12] ,[5,28,33,12] ,[27,6,33,12] ,[5,6,33,12]  ,[27,28,11,34],
  1658.     [5,28,11,34]  ,[27,6,11,34] ,[5,6,11,34]  ,[27,28,11,12],[5,28,11,12] ,
  1659.     [27,6,11,12]  ,[5,6,11,12]  ,[25,26,31,32],[25,6,31,32] ,[25,26,31,12],
  1660.     [25,6,31,12]  ,[15,16,21,22],[15,16,21,12],[15,16,11,22],[15,16,11,12],
  1661.     [29,30,35,36] ,[29,30,11,36],[5,30,35,36] ,[5,30,11,36] ,[39,40,45,46],
  1662.     [5,40,45,46]  ,[39,6,45,46] ,[5,6,45,46]  ,[25,30,31,36],[15,16,45,46],
  1663.     [13,14,19,20] ,[13,14,19,12],[17,18,23,24],[17,18,11,24],[41,42,47,48],
  1664.     [5,42,47,48]  ,[37,38,43,44],[37,6,43,44] ,[13,18,19,24],[13,14,43,44],
  1665.     [37,42,43,48] ,[17,18,47,48],[13,18,43,48],[13,18,43,48]]
  1666.  
  1667.   AUTOTILES = [26, 27, 32, 33,  4, 27, 32, 33, # 1
  1668.                           26, 5, 32, 33,  4,  5, 32, 33, # 3
  1669.                          26, 27, 32, 11,  4, 27, 32, 11, # 5
  1670.                          26,  5, 32, 11,  4,  5, 32, 11, # 7
  1671.                          26, 27, 10, 33,  4, 27, 10, 33, # 9
  1672.                          26,  5, 10, 33,  4,  5, 10, 33, # 11
  1673.                          26, 27, 10, 11,  4, 27, 10, 11, # 13
  1674.                          26,  5, 10, 11,  4,  5, 10, 11, # 15
  1675.                          24, 25, 30, 31, 24,  5, 30, 31, # 17
  1676.                          24, 25, 30, 11, 24,  5, 30, 11, # 19
  1677.                          14, 15, 20, 21, 14, 15, 20, 11, # 21
  1678.                          14, 15, 10, 21, 14, 15, 10, 11, # 23
  1679.                          28, 29, 34, 35, 28, 29, 10, 35, # 25
  1680.                            4, 29, 34, 35,  4, 29, 10, 35, # 27
  1681.                          38, 39, 44, 45,  4, 39, 44, 45, # 29
  1682.                          38,  5, 44, 45,  4,  5, 44, 45, # 31
  1683.                          24, 29, 30, 35, 14, 15, 44, 45, # 33
  1684.                          12, 13, 18, 19, 12, 13, 18, 11, # 35
  1685.                          16, 17, 22, 23, 16, 17, 10, 23, # 37
  1686.                          40, 41, 46, 47, 4, 41, 46, 47, # 39
  1687.                          36, 37, 42, 43, 36,  5, 42, 43, # 41
  1688.                          12, 17, 18, 23, 12, 13, 42, 43, # 43
  1689.                          36, 41, 42, 47, 16, 17, 46, 47, # 45
  1690.                          12, 17, 42, 47, 0,  1,  6,  7] # 47
  1691.   module_function
  1692.   #--------------------------------------------------------------------------
  1693.   # * Get Automatic Tile
  1694.   #--------------------------------------------------------------------------
  1695.   def atile(file, id , offset)
  1696.     if @auto_cache[[file,id,offset]] == nil
  1697.       autotile_bitmap = Bitmap.new(32, 32)
  1698.       autotiles_bitmap = autotile(file)
  1699.       if autotiles_bitmap.height == 32
  1700.         if offset*32 >= autotiles_bitmap.width
  1701.           autotile_bitmap.blt(0,0,autotiles_bitmap,Rect.new(0,0,32,32))
  1702.         else
  1703.           autotile_bitmap.blt(0,0,autotiles_bitmap,Rect.new(offset*32,0,32,32))
  1704.         end
  1705.         @auto_cache[[file,id,offset]] = autotile_bitmap
  1706.         return autotile_bitmap
  1707.       end
  1708.       real_id = id*4
  1709.       off = offset*96
  1710.       if off>=autotiles_bitmap.width
  1711.         off = 0
  1712.       end
  1713.       auto1 = AUTOTILES[real_id + 0]
  1714.       auto2 = AUTOTILES[real_id + 1]
  1715.       auto3 = AUTOTILES[real_id + 2]
  1716.       auto4 = AUTOTILES[real_id + 3]
  1717.       rect1 = Rect.new(auto1 % 6 * 16 + off, auto1 / 6 * 16, 16, 16)
  1718.       rect2 = Rect.new(auto2 % 6 * 16 + off, auto2 / 6 * 16, 16, 16)
  1719.       rect3 = Rect.new(auto3 % 6 * 16 + off, auto3 / 6 * 16, 16, 16)
  1720.       rect4 = Rect.new(auto4 % 6 * 16 + off, auto4 / 6 * 16, 16, 16)
  1721.       autotile_bitmap.blt(0, 0, autotiles_bitmap, rect1)
  1722.       autotile_bitmap.blt(16, 0, autotiles_bitmap, rect2)
  1723.       autotile_bitmap.blt(0, 16, autotiles_bitmap, rect3)
  1724.       autotile_bitmap.blt(16, 16, autotiles_bitmap, rect4)
  1725.       @auto_cache[[file,id,offset]] = autotile_bitmap
  1726.       return autotile_bitmap
  1727.     else
  1728.       return @auto_cache[[file,id,offset]]
  1729.     end
  1730.   end
  1731.   #--------------------------------------------------------------------------
  1732.   # * Get Autotile Graphic
  1733.   #--------------------------------------------------------------------------
  1734.   def self.autotile(filename)
  1735.     self.load_bitmap("Graphics/Autotiles/", filename)
  1736.   end
  1737.   #--------------------------------------------------------------------------
  1738.   # * Get Fog Graphic
  1739.   #--------------------------------------------------------------------------
  1740.   def self.fog(filename, hue = 0)
  1741.     self.load_bitmap("Graphics/Fogs/", filename, hue)
  1742.   end
  1743.   #--------------------------------------------------------------------------
  1744.   # * Get Panorama Graphic
  1745.   #--------------------------------------------------------------------------
  1746.   def self.panorama(filename, hue = 0)
  1747.     self.load_bitmap("Graphics/Panoramas/", filename, hue)
  1748.   end
  1749.   #--------------------------------------------------------------------------
  1750.   # * Get Tileset Graphic
  1751.   #--------------------------------------------------------------------------
  1752.   def self.tileset(filename)
  1753.     self.load_bitmap("Graphics/Tilesets/", filename)
  1754.   end
  1755.   #--------------------------------------------------------------------------
  1756.   # * Get Tile Graphic
  1757.   #--------------------------------------------------------------------------
  1758.   def self.tile(filename, tile_id, hue)
  1759.     key = [filename, tile_id, hue]
  1760.     if not @cache.include?(key) or @cache[key].disposed?
  1761.       @cache[key] = Bitmap.new(32, 32)
  1762.       x = (tile_id - 384) % 8 * 32
  1763.       y = (tile_id - 384) / 8 * 32
  1764.       rect = Rect.new(x, y, 32, 32)
  1765.       @cache[key].blt(0, 0, self.tileset(filename), rect)
  1766.       @cache[key].hue_change(hue)
  1767.     end
  1768.     @cache[key]
  1769.   end
  1770.   #--------------------------------------------------------------------------
  1771.   # * Clear auto
  1772.   #--------------------------------------------------------------------------
  1773.   def clear_auto
  1774.     @auto_cache.values.each {|bitmap|  bitmap.dispose}
  1775.     @auto_cache.clear
  1776.     #GC.start
  1777.   end
  1778. end
  1779.  
  1780.  
  1781. module RPG
  1782.   class Map
  1783.     attr_accessor :tileset_id
  1784.   end
  1785.   class Tileset
  1786.     alias init_tileset initialize
  1787.     def initialize
  1788.       init_tileset
  1789.       @tileset_name = ""
  1790.       @autotile_names = [""]*7
  1791.       @panorama_name = ""
  1792.       @panorama_hue = 0
  1793.       @fog_name = ""
  1794.       @fog_hue = 0
  1795.       @fog_opacity = 64
  1796.       @fog_blend_type = 0
  1797.       @fog_zoom = 200
  1798.       @fog_sx = 0
  1799.       @fog_sy = 0
  1800.       @battleback_name = ""
  1801.       @passages = Table.new(384)
  1802.       @priorities = Table.new(384)
  1803.       @priorities[0] = 5
  1804.       @terrain_tags = Table.new(384)
  1805.     end
  1806.     attr_accessor :tileset_name, :autotile_names, :panorama_name, :panorama_hue,
  1807.       :fog_name, :fog_hue, :fog_opacity, :fog_blend_type, :fog_zoom,
  1808.       :fog_sx, :fog_sy, :battleback_name, :passages, :priorities, :terrain_tags
  1809.   end
  1810. end
  1811. #==============================================================================
  1812. # ** Sprite_Layer NEW
  1813. #------------------------------------------------------------------------------
  1814. #  This class manages tile layers. Every layer contains multipe sprites, one
  1815. #  for each tile row. Furthermore creates the respective bitmaps for the layer.
  1816. #==============================================================================
  1817. class Sprite_Layer
  1818.   #--------------------------------------------------------------------------
  1819.   # * Initialize (read tiles, create sprites & bitmaps)
  1820.   #--------------------------------------------------------------------------
  1821.   def initialize(viewport,priority,autotile_frames,cache=nil)
  1822.     # Get Tileset ID
  1823.     @tileset_id = $game_map.map.tileset_id
  1824.     # Class variables
  1825.     @priority = priority
  1826.     @autotile_frames = autotile_frames
  1827.     @viewport = viewport
  1828.     # Calculate number of tiles on x and y axis
  1829.     @width = $game_map.width
  1830.     @height = $game_map.height
  1831.     # Cache for the tiles
  1832.     if cache == nil
  1833.       @cache = {}
  1834.     else
  1835.       @cache = cache
  1836.     end
  1837.     # Set layer border variables to l<->r and u<->d (changed max/min values)
  1838.     @border_lx = @width
  1839.     @border_ty = @height
  1840.     @border_rx = 0
  1841.     @border_by = 0
  1842.     # Row border
  1843.     @border_lx_row = @width
  1844.     @border_rx_row = 0
  1845.     # Table to store left and right border of every row
  1846.     @rows = Table.new(@height,2)
  1847.     # Hash for the sprites
  1848.     @sprites = {}
  1849.     # Setup tiles
  1850.     if @cache.size == 0
  1851.       setup_tiles
  1852.     else
  1853.       setup_tiles_cache
  1854.     end
  1855.     # If not valid, return
  1856.     return if !valid?
  1857.     # Otherwise, create sprites
  1858.     create_sprites
  1859.     # Get tileset graphic
  1860.     @tileset = Cache.tileset($game_map.tileset_name)
  1861.     # Draw tiles
  1862.     draw_tiles
  1863.     @tileset = nil
  1864.   end
  1865.   #--------------------------------------------------------------------------
  1866.   # * Valid? (checks whether found in tiles for this layer)
  1867.   #--------------------------------------------------------------------------
  1868.   def valid?
  1869.     # If right border greater or equal to left border and
  1870.     # top border greater or equal to bottom border then true
  1871.     return @border_rx >= @border_lx && @border_by >= @border_ty
  1872.   end
  1873.   #--------------------------------------------------------------------------
  1874.   # * Row_valid? (checks whether found in tiles in row y)
  1875.   #--------------------------------------------------------------------------
  1876.   def row_valid?(y)
  1877.     # If right row border is greater than left row border true
  1878.     return @rows[y,1]>@rows[y,0]
  1879.   end
  1880.   #--------------------------------------------------------------------------
  1881.   # * Setup_tiles (reads tiles for this layer and defines the borders)
  1882.   #--------------------------------------------------------------------------
  1883.   def setup_tiles
  1884.     # Get pre-sorted Tile data with priority of the layer
  1885.     @data_link = $game_map.priority_data(@priority)
  1886.     # Clone hashs, needed for functionally interation while deleting stuff
  1887.     # from the data
  1888.     @data = @data_link.clone
  1889.     @data_link.each_pair do |dx,data_x|
  1890.       dat_x = @data[dx]
  1891.       dat_x = data_x.dup
  1892.       data_x.each_pair do |dz,data_z|
  1893.         dat_x[dz] = data_z.dup
  1894.       end
  1895.     end
  1896.     # Iterate through sorted tiles on y-axis
  1897.     @data.each_pair do |y,data_y|
  1898.       # Iterate through sorted tiles on x-axis
  1899.       data_y.each_pair do |x,data_x|
  1900.         # Iterate through map editor layers downwards
  1901.         data_x.each_pair do |z,t|
  1902.           # Get Tile ID
  1903.           # If tile is from tileset or autotile with 1 frame
  1904.           if t >= 384 || @autotile_frames[t/48-1] <= 1
  1905.             # Store in cache
  1906.             @cache[y] = {} if @cache[y] == nil
  1907.             @cache[y][x] = {} if @cache[y][x] == nil
  1908.             @cache[y][x][z] = t
  1909.             # Extend border
  1910.             border(x,y)
  1911.             # Delete from sorted tile list
  1912.             #@data_link[y][x].delete(z)
  1913.             #@data_link[y].delete(x) if @data_link[y][x].size == 0
  1914.             #@data_link.delete(y) if @data_link[y].size == 0
  1915.           end
  1916.         end
  1917.       end
  1918.       # Set row borders
  1919.       @rows[y,0] = @border_lx_row
  1920.       @rows[y,1] = @border_rx_row
  1921.       # Re-Initialize row borders for next iteration
  1922.       @border_lx_row = @width/32
  1923.       @border_rx_row = 0
  1924.     end
  1925.   end
  1926.   #--------------------------------------------------------------------------
  1927.   # * Setup_tiles_cache
  1928.   #--------------------------------------------------------------------------
  1929.   def setup_tiles_cache
  1930.     # Get pre-sorted Tile data with priority of the layer
  1931.     @data_link = $game_map.priority_data(@priority)
  1932.     # Clone hashs, needed for functionally interation while deleting stuff
  1933.     # from the data
  1934.     @data = @data_link.clone
  1935.     @data_link.each_pair do |dx,data_x|
  1936.       dat_x = @data[dx]
  1937.       dat_x = data_x.dup
  1938.       data_x.each_pair do |dz,data_z|
  1939.         dat_x[dz] = data_z.dup
  1940.       end
  1941.     end
  1942.     # Iterate through sorted tiles on y-axis
  1943.     @cache.each_pair do |y,cache_y|
  1944.       # Iterate through sorted tiles on x-axis
  1945.       cache_y.each_pair do |x,cache_x|
  1946.         # Iterate through map editor layers
  1947.         border(x,y) if cache_x.size > 0
  1948.       end
  1949.       # Set row borders
  1950.       @rows[y,0] = @border_lx_row
  1951.       @rows[y,1] = @border_rx_row
  1952.       # Re-Initialize row borders for next iteration
  1953.       @border_lx_row = @width/32
  1954.       @border_rx_row = 0
  1955.     end
  1956.   end
  1957.   #--------------------------------------------------------------------------
  1958.   # * Create_Sprites (creates sprites & bitmaps for each row)
  1959.   #--------------------------------------------------------------------------
  1960.   def create_sprites
  1961.     # Iterate from upper border to lower border
  1962.     for y in @border_ty..@border_by
  1963.       # If row is not valid
  1964.       if !row_valid?(y)
  1965.         # Skip to next
  1966.         next
  1967.       end
  1968.       # Otherwise, calculate distance from left to right border
  1969.       distx = @rows[y,1] - @rows[y,0]
  1970.       # Create sprite
  1971.       sprite = Sprite.new(@viewport)
  1972.       # Create bitmap in row-size
  1973.       sprite.bitmap = Bitmap.new(distx*32,32)
  1974.       # Set x-coordinate to left border
  1975.       sprite.x = @rows[y,0]*32-$game_map.display_x/4
  1976.       # Set y-coordinate to row y
  1977.       sprite.y = y*32-$game_map.display_y/4
  1978.       sprite.blend_type = 0
  1979.       # If priority equals 0
  1980.       if @priority == 0
  1981.         # Set Z to 0, Sprite always beyond later created
  1982.         sprite.z = 0
  1983.       else
  1984.         # Set Z to Base + Priority + Position - Screen Position
  1985.         sprite.z = 32 + 32*@priority + y*32 - $game_map.display_y/4
  1986.        
  1987.       end
  1988.       # Add sprite to hash
  1989.       @sprites[y] = sprite
  1990.     end
  1991.   end
  1992.   #--------------------------------------------------------------------------
  1993.   # * Border (enhances borders of layer and current row)
  1994.   #--------------------------------------------------------------------------
  1995.   def border(x,y)
  1996.     # If X is outside left border
  1997.     if x < @border_lx
  1998.       # Extend left border to x
  1999.       @border_lx = x
  2000.     end
  2001.     # If X is outside right border
  2002.     if x > @border_rx
  2003.       # Extend right border to x+1
  2004.       @border_rx = x+1
  2005.     end
  2006.     # If Y is outside top border
  2007.     if y < @border_ty
  2008.       # Extend top border to y
  2009.       @border_ty = y
  2010.     end
  2011.     # If Y is outside bottom border
  2012.     if y > @border_by
  2013.       # Extend bottom_border to y
  2014.       @border_by = y
  2015.     end
  2016.     # If X is outside left row border
  2017.     if x < @border_lx_row
  2018.       # Extend left row border to x
  2019.       @border_lx_row = x
  2020.     end
  2021.     # If X is outside right row border
  2022.     if x+1 > @border_rx_row
  2023.       # Extend right row border to y
  2024.       @border_rx_row = x+1
  2025.     end
  2026.   end
  2027.   #--------------------------------------------------------------------------
  2028.   # * Update (updates position of image's rows)
  2029.   #--------------------------------------------------------------------------
  2030.   def update(ox,oy)
  2031.     # Get uppermost row 1 block outside of screen
  2032.     y = [((oy*4-224)/128).to_i,@border_ty].max
  2033.     # Get lowermost row 1 block outside of screen
  2034.     y2 = [y+17,@border_by].min
  2035.     # Iterate from uppermost to lowermost row
  2036.     for i in y..y2
  2037.       # Skip if row has no sprite
  2038.       sprite = @sprites[i]
  2039.       next if sprite == nil || sprite.disposed? || !$game_map.tone
  2040.       sprite.tone = $game_map.tone
  2041.       # If priority equals 0
  2042.       sprite.x = @rows[i,0]*32-ox
  2043.       sprite.y = i*32-oy
  2044.       if @priority == 0
  2045.         # Set z to 0, always beyond
  2046.         sprite.z = 0
  2047.       else
  2048.         # Set Z to Base + Priority + Position - Screen Position
  2049.         sprite.z = 32+32*@priority+i*32-oy
  2050.        
  2051.       end
  2052.     end
  2053.   end
  2054.   #--------------------------------------------------------------------------
  2055.   # * Update All (updates position of image's rows)
  2056.   #--------------------------------------------------------------------------
  2057.   def update_all(ox,oy)
  2058.     # Get uppermost row 1 block outside of screen
  2059.     y = [((oy*4-224)/128).to_i,@border_ty].max
  2060.     # Get lowermost row 1 block outside of screen
  2061.     y2 = [y+17,@border_by].min
  2062.     # Iterate from uppermost to lowermost row
  2063.     @sprites.each_key do |i|
  2064.       # Skip if row has no sprite
  2065.       sprite = @sprites[i]
  2066.       next if sprite == nil || sprite.disposed? || !$game_map.tone
  2067.       sprite.tone = $game_map.tone
  2068.       # If priority equals 0
  2069.       sprite.x = @rows[i,0]*32-ox
  2070.       sprite.y = i*32-oy
  2071.       if @priority == 0
  2072.         # Set z to 0, always beyond
  2073.         sprite.z = 0
  2074.       else
  2075.         # Set Z to Base + Priority + Position - Screen Position
  2076.         sprite.z = 32+32*@priority+i*32-oy
  2077.        
  2078.       end
  2079.     end
  2080.   end
  2081.   #--------------------------------------------------------------------------
  2082.   # * Refresh (refreshes all sprites' properties)
  2083.   #--------------------------------------------------------------------------
  2084.   def refresh
  2085.     # Iterate through all sprites
  2086.     for y in @cache.keys
  2087.       sprite = @sprites[y]
  2088.       # Skip if sprite doesn't exist
  2089.       next if sprite == nil
  2090.       sprite.tone = $game_map.tone
  2091.       # If priority equals 0
  2092.       sprite.x = @rows[y,0]*32-$game_map.display_x/4
  2093.       sprite.y = y*32-$game_map.display_y/4
  2094.       if @priority == 0
  2095.         # Set z to 0, always beyond
  2096.         sprite.z = 0
  2097.       else
  2098.         # Set Z to Base + Priority + Position - Screen Position
  2099.         sprite.z = 32+32*@priority+y*32-$game_map.display_y/4
  2100.        
  2101.       end
  2102.     end
  2103.   end
  2104.   #--------------------------------------------------------------------------
  2105.   # * Draw_tiles (draws the complete layer into the single rows)
  2106.   #--------------------------------------------------------------------------
  2107.   def draw_tiles
  2108.     # Iterate through all cached tiles on y-axis
  2109.     @cache.each_pair do |y,cache_y|
  2110.       # Iterate through all cached tiles on x-axis
  2111.       sprite = @sprites[y]
  2112.       cache_y.each_pair do |x,cache_x|
  2113.         # Iterate through all cached tile layers (map-editor)
  2114.         # ! Lowest z first !
  2115.         values_x = LiTTleDRAgo::RGSS3 ? cache_x.values.reverse : cache_x.values
  2116.         #cache_x.values.each do |t|
  2117.         #cache_x.values.reverse.each do |t| #RGSS3
  2118.         values_x.each do |t| #RGSS3
  2119.           # Get tile ID from cache
  2120.           # Get left border of row
  2121.           lx = @rows[y,0]
  2122.           # If tile is from tileset
  2123.           if t >= 384
  2124.             # Calculate x/y-position on tileset
  2125.             t -= 384
  2126.             xt = t%8
  2127.             yt = t/8
  2128.             # Source rect
  2129.             r = Rect.new(xt*32,yt*32,32,32)
  2130.             # Blt tile from tileset to row on -border+x
  2131.             sprite.bitmap.blt(-lx*32+x*32,0,@tileset,r)
  2132.           # Else: Tile is an autotile (with 1 frame)
  2133.           else
  2134.             # Calculate file id and autotile id
  2135.             file = (t / 48) - 1
  2136.             a = t - (file+1)*48
  2137.             # Get autotile bitmap from Cache
  2138.             autotile = Cache.atile($game_map.autotile_names[file],a,0)
  2139.             # Blt autotile to row on -border+x
  2140.             sprite.bitmap.blt(-lx*32+x*32,0,autotile,autotile.rect)
  2141.           end
  2142.         end
  2143.       end
  2144.     end
  2145.     # Clear autotile cache
  2146.     Cache.clear_auto
  2147.   end
  2148.   #--------------------------------------------------------------------------
  2149.   # * Dispose (delete row sprites)
  2150.   #--------------------------------------------------------------------------
  2151.   def dispose
  2152.     # Dispose every sprite
  2153.     for sprite in @sprites.values
  2154.       sprite.dispose
  2155.     end
  2156.   end
  2157. end
  2158. #==============================================================================
  2159. # ** Tilemap_New NEW
  2160. #------------------------------------------------------------------------------
  2161. #  This is the script's core, the new tilemap class. Currently contains methods
  2162. #  for updating and deleting, mostly self-managing.
  2163. #  Creates up to 5 layers and 6 autotile layers. Layers are created depending
  2164. #  on priority and mapping, autotile layer depending on properties of autotiles
  2165. #  (speed,frames,blend mode).
  2166. #==============================================================================
  2167. class Tilemap_New
  2168.   #--------------------------------------------------------------------------
  2169.   # * Public Instance Variable
  2170.   #--------------------------------------------------------------------------
  2171.   attr_accessor :tileset,:autotiles,:viewport
  2172.   attr_reader :autotile_frames
  2173.   #--------------------------------------------------------------------------
  2174.   # * Initialize (create layer)
  2175.   #--------------------------------------------------------------------------
  2176.   def initialize(viewport,tileset,autiles)
  2177.     # Save tileset & autotiles
  2178.     @viewport = viewport
  2179.     @tileset = tileset
  2180.     @autotiles = autiles
  2181.     # Get number of frames per autotile
  2182.     @autotile_frames = []
  2183.     for autotile in @autotiles
  2184.       # If autotiles height exceeds 32
  2185.       if autotile.height > 32
  2186.         @autotile_frames << autotile.width/96
  2187.       # Else: autotiles in X*32 format
  2188.       else
  2189.         @autotile_frames << autotile.width/32
  2190.       end
  2191.     end
  2192.     # Tileset ID
  2193.     id = $game_map.tileset_id
  2194.     # Temporaries
  2195.     autotiles = []
  2196.     done = []
  2197.     autotiles_later = {}
  2198.     # Class variables
  2199.     @autotile_layers = []
  2200.     @layers = []
  2201.     @ox = 0
  2202.     @oy = 0
  2203.     # Iterate through autotiles
  2204.     for i in 0..6
  2205.       # Get frames
  2206.       frames = @autotile_frames[i]
  2207.       # If only one frame => static, skip
  2208.       next if frames <= 1 || done.include?(i)
  2209.       # Get properties
  2210.       speed = AUTOTILE::SPEED[id][i] if AUTOTILE::SPEED[id] != nil
  2211.       speed = AUTOTILE::DEFAULT_SPEED if speed == nil
  2212.       blend_type = AUTOTILE::BLEND_TYPE[id][i] if AUTOTILE::BLEND_TYPE[id] != nil
  2213.       blend_type = 0 if blend_type == nil
  2214.       priority = $game_map.priorities[(i+1)*48]
  2215.       # Iterate through all autotiles >= current one
  2216.       # Batches similar autotiles in the same layer -> less memody/lag
  2217.       for j in i..6
  2218.         # Get 2nd autotile properties
  2219.         speed2 = AUTOTILE::SPEED[id][j] if AUTOTILE::SPEED[id] != nil
  2220.         speed2 = AUTOTILE::DEFAULT_SPEED if speed2 == nil
  2221.         frames2 = @autotile_frames[j]
  2222.         blend_type2 = AUTOTILE::BLEND_TYPE[id][j] if AUTOTILE::BLEND_TYPE[id] != nil
  2223.         blend_type2 = 0 if blend_type2 == nil
  2224.         priority2 = $game_map.priorities[(j+1)*48]
  2225.         # If properties of both autotiles match
  2226.         if speed2 == speed && frames2 == frames && blend_type2 == blend_type &&
  2227.           priority2 == priority
  2228.           # Store autotile id
  2229.           autotiles << j
  2230.           # Store properties
  2231.           speed3 = speed
  2232.           frames3 = frames
  2233.           priority3 = priority
  2234.           blend_type3 = blend_type
  2235.           # Autotile id is done
  2236.           done << j
  2237.         end
  2238.       end
  2239.       # If special blended autotiles
  2240.       if blend_type3 >= 1
  2241.         # Store autotile ids & properties for later creation (z-priority)
  2242.         autotiles_later[priority3] = [] if autotiles_later[priority3] == nil
  2243.         autotiles_later[priority3] << Command_Autotile.new(autotiles,speed3,@autotile_frames,priority3,blend_type3)
  2244.       # Else : Normal blended tile
  2245.       else
  2246.         # Create autotile-Layer
  2247.         @autotile_layers << Sprite_Auto.new(@viewport,autotiles,speed3,@autotile_frames,priority3,blend_type3)
  2248.         # Delete if not valid
  2249.         @autotile_layers.delete_at(@autotile_layers.size-1) if !@autotile_layers[@autotile_layers.size-1].valid?
  2250.       end
  2251.       autotiles.clear
  2252.     end
  2253.     # Iterate through all priority layers
  2254.     for i in 0..5
  2255.       # Create layer sprite
  2256.       sprite = Sprite_Layer.new(@viewport,i,@autotile_frames)
  2257.       # Keep sprite onty if valid?
  2258.       @layers << sprite if sprite.valid?
  2259.       # If blended autotile waits for creation at current priority
  2260.       if autotiles_later[i] != nil
  2261.         # Iterate through autotile commands
  2262.         for c in autotiles_later[i]
  2263.           # Create autotile-layer
  2264.           @autotile_layers << Sprite_Auto.new(@viewport,c.autotiles,c.speed,c.frames,c.priority,c.blend_type)
  2265.           # Delete if not valid
  2266.           @autotile_layers.delete_at(@autotile_layers.size-1) if !@autotile_layers[@autotile_layers.size-1].valid?
  2267.         end
  2268.         # Delete command layer
  2269.         autotiles_later.delete(i)
  2270.       end
  2271.     end
  2272.   end
  2273.   #--------------------------------------------------------------------------
  2274.   # * Ox (returns tilemap x-position)
  2275.   #--------------------------------------------------------------------------
  2276.   def ox
  2277.     return @ox
  2278.   end
  2279.   #--------------------------------------------------------------------------
  2280.   # * Oy (returns tilemap y-position)
  2281.   #--------------------------------------------------------------------------
  2282.   def oy
  2283.     return @oy
  2284.   end
  2285.   #--------------------------------------------------------------------------
  2286.   # * Ox= (sets tilemap x-position)
  2287.   #--------------------------------------------------------------------------
  2288.   def ox=(ox)
  2289.     # Return if position is equal to new position
  2290.     #return if @ox == ox
  2291.     @ox = ox
  2292.   end
  2293.   #--------------------------------------------------------------------------
  2294.   # * Oy= (sets tilemap y-position)
  2295.   #--------------------------------------------------------------------------
  2296.   def oy=(oy)
  2297.     # Return if position is equal to new position
  2298.     #return if @oy == oy
  2299.     @oy = oy
  2300.   end
  2301.   #--------------------------------------------------------------------------
  2302.   # * Frame Update
  2303.   #--------------------------------------------------------------------------
  2304.   def update
  2305.     # Update viewport. Corrupts standard x/y positions of fog,characters,weather,
  2306.     # panorama, corrected in the corresponding method
  2307.     #@viewport.ox = $game_map.display_x/4
  2308.     #@viewport.oy = $game_map.display_y/4
  2309.     # Update autotile_layers
  2310.     @autotile_layers.each {|layer| layer.update(@ox,@oy)}
  2311.     # Update_layers
  2312.     @layers.each {|layer| layer.update(@ox,@oy)}
  2313.   end
  2314.   #--------------------------------------------------------------------------
  2315.   # * Update_all
  2316.   #--------------------------------------------------------------------------
  2317.   def update_all
  2318.     # Update viewport. Corrupts standard x/y positions of fog,characters,weather,
  2319.     # panorama, corrected in the corresponding method
  2320.     #@viewport.ox = $game_map.display_x/4
  2321.     #@viewport.oy = $game_map.display_y/4
  2322.     # Update autotile_layers
  2323.     @autotile_layers.each {|layer| layer.update_all(@ox,@oy)}
  2324.     # Update_layers
  2325.     @layers.each {|layer| layer.update_all(@ox,@oy)}
  2326.   end
  2327.   #--------------------------------------------------------------------------
  2328.   # * Dispose (delete layer & autotile layer)
  2329.   #--------------------------------------------------------------------------
  2330.   def dispose
  2331.     # Dispose autotile layers
  2332.     @autotile_layers.each {|layer|   layer.dispose }
  2333.     @autotile_layers = []
  2334.     # Dispose layers
  2335.     @layers.each {|layer|   layer.dispose }
  2336.     @layers = []
  2337.   end
  2338.   #--------------------------------------------------------------------------
  2339.   # * Initialize (updates all rows of all layers)
  2340.   #--------------------------------------------------------------------------
  2341.   def refresh
  2342.     @autotile_layers.each {|layer|   layer.refresh }
  2343.     @layers.each          {|layer|   layer.refresh }
  2344.   end
  2345. end
  2346.  
  2347. #==============================================================================
  2348. # ** Command_Autotile NEW
  2349. #------------------------------------------------------------------------------
  2350. #  This class saves all autotile data. Used in order to create autotiles with
  2351. #  blend-mode 1/2 after normal tile layer.
  2352. #==============================================================================
  2353. class Command_Autotile
  2354.   #--------------------------------------------------------------------------
  2355.   # * Public Instance Variable
  2356.   #--------------------------------------------------------------------------
  2357.   attr_reader :autotiles,:speed,:frames,:blend_type,:priority
  2358.   #--------------------------------------------------------------------------
  2359.   # * Initialize
  2360.   #--------------------------------------------------------------------------
  2361.   def initialize(autotiles,speed,frames,priority,blend_type)
  2362.     @autotiles = autotiles.clone #Autotile list
  2363.     @speed = speed               #Animation speed
  2364.     @frames = frames             #Nr. of frames
  2365.     @blend_type = blend_type     #Blend type
  2366.     @priority = priority         #Priority
  2367.   end
  2368. end
  2369.  
  2370. #==============================================================================
  2371. # ** Graphics
  2372. #------------------------------------------------------------------------------
  2373. #  This module handles all Graphics
  2374. #==============================================================================
  2375. module Graphics
  2376.   #--------------------------------------------------------------------------
  2377.   # ● class << self
  2378.   #--------------------------------------------------------------------------
  2379.   class << self
  2380.     #--------------------------------------------------------------------------
  2381.     # ● Alias Method
  2382.     #--------------------------------------------------------------------------
  2383.     unless self.method_defined?(:atilemap_update)
  2384.       alias_method(:atilemap_update, :update)
  2385.       #-------------------------------------------------------------------------
  2386.       # ● Update
  2387.       #-------------------------------------------------------------------------
  2388.       def update
  2389.         atilemap_update
  2390.         scene = ($imported[:drg_core_engine]||0) >= 1.19 ?
  2391.                 LiTTleDRAgo.scene : SceneManager.scene
  2392.         return if scene.is_a?(Scene_Map)
  2393.         spriteset = scene.instance_variables.any? {|var|
  2394.           scene.instance_variable_get(var).is_a?(Spriteset_Map)}
  2395.         $game_temp.instance_variable_set(:@store_tilemap,true) if spriteset
  2396.       end
  2397.     end
  2398.   end
  2399. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement