Advertisement
Zeriab

Zeriab's Anti Event Lag System v1.2b

Oct 4th, 2012
1,590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 51.33 KB | None | 0 0
  1. #==============================================================================
  2. # ** Anti Event Lag System
  3. #------------------------------------------------------------------------------
  4. # Zeriab
  5. # Version 1.2b
  6. # 2008-09-12 (Year-Month-Day)
  7. #------------------------------------------------------------------------------
  8. # * Requirements :
  9. #  
  10. #   If you have the SDK : Version 2.0+, Part I, II
  11. #   Does not require the SDK
  12. #------------------------------------------------------------------------------
  13. # * Version History :
  14. #
  15. #   Version 0.8 -------------------------------------------------- (2007-09-03)
  16. #    - First release
  17. #
  18. #   Version 0.81 ------------------------------------------------- (2007-09-05)
  19. #    - Overwrote Game_Map's passable? method for faster collision detection
  20. #
  21. #   Version 0.9 -------------------------------------------------- (2007-09-12)
  22. #    - Support for the Non-SDK patch
  23. #    - Support for defining whether an event will always be updated or never
  24. #      be updated by defining name patterns.
  25. #
  26. #   Version 1.0 -------------------------------------------------- (2007-09-24)
  27. #   - Fixed compatibility issue with Blizzard's Caterpillar script
  28. #   - Overwrote more methods scanning for events on a specific tile
  29. #   - Support for defining whether an event will always be updated or never
  30. #      be updated by specifying the event's id and map_id
  31. #   - Some structural changes.
  32. #   - Integrated the Non-SDK patch into the main script
  33. #
  34. #   Version 1.05 ------------------------------------------------- (2007-11-18)
  35. #   - Fixed bug where sprites might not be disposed when changing scene.
  36. #
  37. #   Version 1.1 -------------------------------------------------- (2008-04-10)
  38. #   - Added declaration to which common events to update
  39. #
  40. #   Version 1.15 ------------------------------------------------- (2008-06-19)
  41. #   - Added automatic detection of which common events to update (optional)
  42. #
  43. #   Version 1.2 -------------------------------------------------- (2008-07-04)
  44. #   - Fixed a case where an event could be registered twice causing transparent
  45. #      events to look less transparent.
  46. #
  47. #   Version 1.2b ------------------------------------------------- (2008-09-12)
  48. #   - Fixed a stack error problem caused when pressing F12.
  49. #------------------------------------------------------------------------------
  50. # * Description :
  51. #
  52. #   This script was designed to reduce lag by changing the data structure of
  53. #   the events in the Game_Map class and update the functionality accordingly
  54. #   A goal of this script is not to change the normal event behavior, so
  55. #   implementing it into a project should not effect previous events. It might
  56. #   effect custom scripts.
  57. #------------------------------------------------------------------------------
  58. # * License :
  59. #
  60. #   Copyright (C) 2007, 2008  Zeriab
  61. #
  62. #   This program is free software: you can redistribute it and/or modify
  63. #   it under the terms of the GNU Lesser Public License as published by
  64. #   the Free Software Foundation, either version 3 of the License, or
  65. #   (at your option) any later version.
  66. #
  67. #   This program is distributed in the hope that it will be useful,
  68. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  69. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  70. #   GNU Lesser Public License for more details.
  71. #
  72. #   For the full license see <http://www.gnu.org/licenses/>
  73. #   The GNU General Public License: http://www.gnu.org/licenses/gpl.txt
  74. #   The GNU Lesser General Public License: http://www.gnu.org/licenses/lgpl.txt
  75. #------------------------------------------------------------------------------
  76. # * Compatibility :
  77. #
  78. #   This is SDK compliant. It is written for SDK version 2.3.
  79. #   It requires SDK 2.0+ if you are using the SDK
  80. #   The Non-SDK patch is integrated so you can run it without the SDK
  81. #  
  82. #   The following methods has been overwritten:
  83. #    * Game_Character.passable?
  84. #    * Game_Map.passable?
  85. #    * Game_Map.update_events
  86. #    * Game_Player.check_event_trigger_here
  87. #    * Game_Player.check_event_trigger_there
  88. #    * Game_Player.check_event_trigger_touch
  89. #    * Spriteset_Map.init_characters
  90. #    * Spriteset_Map.update_character_sprites
  91. #
  92. #   The following methods have been aliased
  93. #    * Game_Event.jump
  94. #    * Game_Event.moveto
  95. #    * Game_Event.move_down
  96. #    * Game_Event.move_left
  97. #    * Game_Event.move_right
  98. #    * Game_Event.move_up
  99. #    * Game_Event.move_lower_left
  100. #    * Game_Event.move_lower_right
  101. #    * Game_Event.move_upper_left
  102. #    * Game_Event.move_upper_right
  103. #    * Game_Map.setup
  104. #------------------------------------------------------------------------------
  105. # * Instructions :
  106. #
  107. #   Place this script just below the SDK if you are using the SDK.
  108. #   Place this script just below the default if using the Non-SDK Patch
  109. #  
  110. #   default scripts
  111. #   (SDK)
  112. #   Zeriab's Anti Event Lag System
  113. #   (custom scripts)
  114. #   main
  115. #
  116. #   ~ Game_Map ~
  117. #   There are 4 constants you can change at will in the top of the
  118. #   Game_Map class: (You don't have to ;))
  119. #  
  120. #   ALWAYS_UPDATE ~ The default is false
  121. #   -------------------------------
  122. #   You can set this to true if you want all events to be update always
  123. #   This a slower option, but events behave like they do without the script.
  124. #   You will still benifit from the faster collision detection and fewer sprites
  125. #   This has higher priority than the event specific features. I.e never_update
  126. #
  127. #   BUFFER_SIZE ~ The default is 2
  128. #   -------------------------
  129. #   You can increase or decrease the buffer size by altering this value.
  130. #   The greater this value the greater area around the visible area is updated
  131. #   at the price of potential more lag.
  132. #   The lower this value the smaller area around the visible area is update
  133. #   with the potential of less lag.
  134. #   Too low a value may get the sprites to sort of 'freeze' in the outskirts
  135. #   of the screen.
  136. #   Bigger sprites requires bigger buffer to prevent this.
  137. #  
  138. #   TILES_VERTICAL ~ The default is 15
  139. #   -----------------------------
  140. #   Specifies how many tiles there are vertical
  141. #   I included the option to change this value if you want to alter
  142. #   the size of the game window.
  143. #   If you for example want 800x600 I suggest changing this value to 20
  144. #
  145. #   TILES_HORIZONTAL ~ The default is 20
  146. #   -------------------------------
  147. #   Specifies how many tiles there are horizontal
  148. #   I included the option to change this value if you want to alter
  149. #   the size of the game window.
  150. #   If you for example want 800x600 I suggest changing this value to 27
  151. #  
  152. #   LIMIT_COMMON_EVENTS - The default is true
  153. #   -----------------------------
  154. #   You can see this to false if you want all common events updated.
  155. #   This constant only has an effect during the upstart of the program. Changing
  156. #   it during the game will have no effect.
  157. #   If it is set to false you can safely ignore the following three constants
  158. #
  159. #   SPECIFY_COMMON_EVENTS_MANUALLY - The default is false
  160. #   -----------------------------
  161. #   Specifies whether you want to enter which common events should be updated
  162. #   manually. If this is set to false you can safely ignore
  163. #   COMMON_EVENTS_TO_UPDATE while COMMON_EVENT_FILEPATH is of importance.
  164. #   Vice-versa is COMMON_EVENTS_TO_UPDATE important and COMMON_EVENT_FILEPATH
  165. #   safe to ignore if SPECIFY_COMMON_EVENTS_MANUALLY is set to true.
  166. #   If this is set to false which common events to update will be atomatically
  167. #   detected.
  168. #   As a general rule of thumb: Only change this to true if you have problems
  169. #   with the automatic detection or you want to prevent certain common events
  170. #   with autorun or parallel process as trigger.
  171. #
  172. #   COMMON_EVENTS_TO_UPDATE
  173. #   -----------------------------
  174. #   This constant is an array of common event ids. Only the common events with
  175. #   the ids specified in the array will be updated. The ids are the numbers
  176. #   shown in the database with any leading 0s removed. In general only common
  177. #   events which have autorun or parallel process needs to be updated.
  178. #   It will have no effect if SPECIFY_COMMON_EVENTS_MANUALLY is false
  179. #   Let's say we want the common events 005, 009 and 020 to be updated. First we
  180. #   will remove the leading 0s and get 5, 9 and 20. Next we will put them in the
  181. #   array and get as end result:
  182. #
  183. #     COMMON_EVENTS_TO_UPDATE = [5, 9, 20]
  184. #
  185. #   If we had put [005, 009, 020] as the array we would have gotten an error
  186. #   when starting the game.
  187. #   If we now want to update common event 045 we would add 45 to the array:
  188. #
  189. #     COMMON_EVENTS_TO_UPDATE = [5, 9, 20, 45]
  190. #
  191. #
  192. #   COMMON_EVENT_FILEPATH - The default is 'Data/CommonEvents.rxdata'
  193. #   -----------------------------
  194. #   Specifies the relative file path (To the directory of where the Game.exe is)
  195. #   to where the common events are stored.
  196. #   Only change this if you have changed the name or place of the
  197. #   CommonEvents.rxdata file.
  198. #   It will have no effect if SPECIFY_COMMON_EVENTS_MANUALLY is true
  199. #
  200. #
  201. #   ~ Game_Event ~
  202. #   Next we come to the Constants in Game_Event. They are given above the
  203. #   Game_Map code. They have been split from the other Game_Event code for
  204. #   Easier access:
  205. #
  206. #   SPECIAL_UPDATE_IDS
  207. #   ------------------
  208. #   This constant contains a hash where you can specify how specific events
  209. #   should be updated. Special update ids has priority over name patterns.
  210. #   The keys are all a 2-elements array. [Map_ID, Event_ID]
  211. #   The value is either an 'A' for always update or 'N' for never update.
  212. #   Here is an example:
  213. #
  214. #     SPECIAL_UPDATE_IDS = {[1,1]=>'A',
  215. #                           [1,2]=>'N'}
  216. #  
  217. #   Notice the first line [1,1]=>'A'
  218. #   It means that the event with id 1 on map 1 will always be updated.
  219. #
  220. #   Notice the first line [1,2]=>'N'
  221. #   It means that the event with id 2 on map 1 will never be updated.
  222. #   Let's say we wanted the event with id 5 on map 3 to always be updated.
  223. #   This can be achieved by adding [5,3]=>'A' to the hash:
  224. #
  225. #     SPECIAL_UPDATE_IDS = {[1,1]=>'A',
  226. #                           [1,2]=>'N',
  227. #                           [5,3]=>'A'}
  228. #
  229. #
  230. #   NEVER_UPDATE_NAME_PATTERNS
  231. #   --------------------------
  232. #   Here you can specify any number of patterns which will be checked when a
  233. #   new map is loaded. Any events which matches at least one of the patterns
  234. #   given here will never be updated.
  235. #   A pattern is assumed to be either a String or a RegExp. In the case of a
  236. #   String name.include?(string) is used. Otherwise the =~ operator is used
  237. #   Note: The never_update feature has higher priority than the always_update.
  238. #   If an event's name matches both a always update pattern and a never_update
  239. #   pattern it will never update.
  240. #
  241. #   ALWAYS_UPDATE_NAME_PATTERNS
  242. #   ---------------------------
  243. #   Here you can specify any number of patterns which will be checked when a
  244. #   new map is loaded. Any events which matches at least one of the patterns
  245. #   given here will always be updated.
  246. #   Note: The always_update feature has lower priority than the never_update.
  247. #   If an event's name matches both a always update pattern and a never_update
  248. #   pattern it will never update.
  249. #==============================================================================
  250.  
  251. if Module.constants.include?('SDK')
  252.   #----------------------------------------------------------------------------
  253.   # * SDK Log Script
  254.   #----------------------------------------------------------------------------
  255.   SDK.log('Anti Event Lag System', 'Zeriab', 1.2, '2008-06-25')
  256.   SDK.check_requirements(2.0)
  257. end
  258.  
  259. #------------------------------------------------------------------------------
  260. # * Begin SDK Enable Test
  261. #------------------------------------------------------------------------------
  262. if !Module.constants.include?('SDK') || SDK.enabled?('Anti Event Lag System')
  263.  
  264. #==============================================================================
  265. # ** Constants for the anti lag script
  266. #==============================================================================
  267.  
  268. class Game_Map
  269.   ALWAYS_UPDATE = false
  270.   BUFFER_SIZE = 2
  271.   TILES_VERTICAL = 15
  272.   TILES_HORIZONTAL = 20
  273.   LIMIT_COMMON_EVENTS = true
  274.   SPECIFY_COMMON_EVENTS_MANUALLY = false
  275.   # If you want to specify which common events to update
  276.   COMMON_EVENTS_TO_UPDATE = []
  277.   # If you want the script to automatically read the common events and find
  278.   # out which to update. Must be the path to the CommonEvents.rxdata
  279.   COMMON_EVENT_FILEPATH = 'Data/CommonEvents.rxdata'
  280. end
  281.  
  282. class Game_Event
  283.   SPECIAL_UPDATE_IDS = {}
  284.   NEVER_UPDATE_NAME_PATTERNS = ['[N]'] # [N] in the event name => not updated
  285.   ALWAYS_UPDATE_NAME_PATTERNS = ['[A]'] # [A] in the event name => always updated
  286. end
  287.  
  288. #==============================================================================
  289. # ** Automatic configuration generation
  290. #==============================================================================
  291. class Game_Map
  292.   if LIMIT_COMMON_EVENTS && !SPECIFY_COMMON_EVENTS_MANUALLY
  293.     # Find the common events which needs to be updated
  294.     COMMON_EVENTS_TO_UPDATE = []
  295.     # Load the common events
  296.     common_events = load_data(COMMON_EVENT_FILEPATH)
  297.     # Go through the common events
  298.     for common_event in common_events.compact
  299.       # Check if there is a need for the common event to update
  300.       if common_event.trigger > 0
  301.         # C
  302.         COMMON_EVENTS_TO_UPDATE << common_event.id
  303.       end
  304.     end
  305.   end
  306. end
  307.  
  308. #==============================================================================
  309. # ** Game_Map
  310. #==============================================================================
  311.  
  312. class Game_Map
  313.   #--------------------------------------------------------------------------
  314.   # * Public Instance Variables
  315.   #--------------------------------------------------------------------------
  316.   attr_reader :event_map
  317.   #--------------------------------------------------------------------------
  318.   # * Alias Listings
  319.   #--------------------------------------------------------------------------
  320.   alias_method :zeriab_antilag_gmmap_setup,   :setup
  321.   #--------------------------------------------------------------------------
  322.   # * Setup
  323.   #--------------------------------------------------------------------------
  324.   def setup(*args)
  325.     # Makes an event map as a hash
  326.     @event_map = {}
  327.     # Original Setup
  328.     zeriab_antilag_gmmap_setup(*args)
  329.     # Go through each event
  330.     for event in @events.values
  331.       # Check how the event should be updated
  332.       event.check_update
  333.     end
  334.   end
  335.  
  336.   #--------------------------------------------------------------------------
  337.   # * Update Events ~ Overwritten to only updating visible and special events
  338.   #--------------------------------------------------------------------------
  339.   def update_events
  340.     # Runs through the events
  341.     for event in @events.values
  342.       # checks if the event is visible or needs to be updated
  343.       if ALWAYS_UPDATE || event.need_update?
  344.         event.update
  345.       end
  346.     end
  347.   end
  348.  
  349.   # Only overwrite this method if common events should be limited
  350.   if LIMIT_COMMON_EVENTS
  351.     #--------------------------------------------------------------------------
  352.     # * Update Common Events ~ Updates only the necessary common events
  353.     #--------------------------------------------------------------------------
  354.     def update_common_events
  355.       for i in COMMON_EVENTS_TO_UPDATE
  356.         @common_events[i].update
  357.       end
  358.     end
  359.   end
  360.    
  361.   #--------------------------------------------------------------------------
  362.   # * Called when an event has been moved with it's old x and y coordinate
  363.   #   Used to update its position in the event_map
  364.   #--------------------------------------------------------------------------
  365.   def move_event(old_x,old_y,event)
  366.     # Checks if the event has moved to a new position.
  367.     return if old_x == event.x && old_y == event.y
  368.     # Removes the event from its old position
  369.     remove_event(old_x, old_y, event)
  370.     # Adds the event to its new position
  371.     add_event(event.x,event.y,event)
  372.     # Gets the spriteset from Scene_Map
  373.     spriteset = $scene.instance_eval('@spriteset')
  374.     # Checks that it actually is a Spriteset_Map.
  375.     if spriteset.is_a?(Spriteset_Map) && spriteset.respond_to?(:update_event)
  376.       # Tells the spriteset to update the event to its new position
  377.       spriteset.update_event(old_x,old_y,event)
  378.     end
  379.   end
  380.  
  381.   #--------------------------------------------------------------------------
  382.   # * Adds an event to the event_map at the given x and y coordinate
  383.   #--------------------------------------------------------------------------
  384.   def add_event(x,y,event)
  385.     # Checks if there are not any events on the specific tile
  386.     if @event_map[[x,y]].nil?
  387.       # Sets the position on the map to be an array containing the given
  388.       # event. (In case there are placed additional events on this tile)
  389.       @event_map[[x,y]] = [event]
  390.     else
  391.       # Adds the event to the array of events on the specific tile
  392.       @event_map[[x,y]] << event
  393.     end
  394.   end
  395.  
  396.   #--------------------------------------------------------------------------
  397.   # * Removes an event from the event_map with the given x and y coordinate
  398.   #--------------------------------------------------------------------------
  399.   def remove_event(x,y,event)
  400.     # Checks if there actually are an event on the given coordinates
  401.     return if @event_map[[x,y]].nil?
  402.     # Checks whether or not there are more events than the given event on
  403.     # with the given coordinates
  404.     if @event_map[[x,y]].size > 1
  405.       # Deletes the events from the array of events
  406.       @event_map[[x,y]].delete(event)
  407.     else
  408.       # Deletes the key along with the corresponding value from the hashmap
  409.       # since there are no other events on the tile.
  410.       @event_map.delete([x,y])
  411.     end
  412.   end
  413.  
  414.   #--------------------------------------------------------------------------
  415.   # * Gets min_x, max_x, min_y and max_y including the buffer-size
  416.   # Returns min_x, max_x, min_y, max_y  (tile-coordinates)
  417.   # Returns a Rect if 'true' is given as the argument
  418.   #--------------------------------------------------------------------------  
  419.   def get_tile_area(rect = false)
  420.     # Gets the upper left x and y tile-coordinate
  421.     x = $game_map.display_x / 128
  422.     y = $game_map.display_y / 128
  423.     # Computes the min and max coordinates when considering the buffer-size
  424.     min_x = x - BUFFER_SIZE
  425.     min_y = y - BUFFER_SIZE
  426.     max_x = x + TILES_HORIZONTAL + BUFFER_SIZE
  427.     max_y = y + TILES_VERTICAL + BUFFER_SIZE
  428.     # Makes sure the min and max coordinates are within the map
  429.     if min_x < 0
  430.       min_x = 0
  431.     end
  432.     if max_x >= $game_map.width
  433.       max_x = $game_map.width - 1
  434.     end
  435.     if min_y < 0
  436.       min_y = 0
  437.     end
  438.     if max_y >= $game_map.height
  439.       max_y = $game_map.height - 1
  440.     end
  441.     # Checks if the return should be a Rect
  442.     if rect
  443.       # Returns the result as a Rect
  444.       return Rect.new(min_x, min_y, max_x - min_x, max_y - min_y)
  445.     else
  446.       # Returns the result as the min and max coordinates
  447.       return min_x, max_x, min_y, max_y
  448.     end
  449.   end
  450.  
  451.   #--------------------------------------------------------------------------
  452.   # * Checks if the tile with the given x and y coordinate is visible.
  453.   #   Takes the buffer size into account.
  454.   #--------------------------------------------------------------------------
  455.   def visible?(x,y)
  456.     min_x = $game_map.display_x / 128
  457.     min_y = $game_map.display_y / 128
  458.     if x >= min_x - BUFFER_SIZE && x <= min_x + BUFFER_SIZE + TILES_HORIZONTAL &&
  459.        y >= min_y - BUFFER_SIZE && y <= min_y + BUFFER_SIZE + TILES_VERTICAL
  460.       return true
  461.     end
  462.     return false
  463.   end
  464.  
  465.   #--------------------------------------------------------------------------
  466.   # * Get Designated Position Event ID
  467.   #     x          : x-coordinate
  468.   #     y          : y-coordinate
  469.   #--------------------------------------------------------------------------
  470.   def check_event(x, y)
  471.     # Retrives the events on the specified tile
  472.     events = event_map[[x,y]]
  473.     unless events.nil?
  474.       # Loop through events on tile
  475.       for event in events
  476.         if event.x == x and event.y == y
  477.           return event.id
  478.         end
  479.       end
  480.     end
  481.   end
  482.  
  483.   #--------------------------------------------------------------------------
  484.   # * Determine if Passable
  485.   #     x          : x-coordinate
  486.   #     y          : y-coordinate
  487.   #     d          : direction (0,2,4,6,8,10)
  488.   #                  *  0,10 = determine if all directions are impassable
  489.   #     self_event : Self (If event is determined passable)
  490.   #--------------------------------------------------------------------------
  491.   def passable?(x, y, d, self_event = nil)
  492.     # If coordinates given are outside of the map
  493.     unless valid?(x, y)
  494.       # impassable
  495.       return false
  496.     end
  497.     # Change direction (0,2,4,6,8,10) to obstacle bit (0,1,2,4,8,0)
  498.     bit = (1 << (d / 2 - 1)) & 0x0f
  499.     # Retrives the events on the specified tile
  500.     events = event_map[[x,y]]
  501.     unless events.nil?
  502.       # Loop through events on tile
  503.       for event in events
  504.         # If tiles other than self are consistent with coordinates
  505.         if event.tile_id >= 0 and event != self_event and not event.through
  506.           # If obstacle bit is set
  507.           if @passages[event.tile_id] & bit != 0
  508.             # impassable
  509.             return false
  510.           # If obstacle bit is set in all directions
  511.           elsif @passages[event.tile_id] & 0x0f == 0x0f
  512.             # impassable
  513.             return false
  514.           # If priorities other than that are 0
  515.           elsif @priorities[event.tile_id] == 0
  516.             # passable
  517.             return true
  518.           end
  519.         end
  520.       end
  521.     end
  522.     # Loop searches in order from top of layer
  523.     for i in [2, 1, 0]
  524.       # Get tile ID
  525.       tile_id = data[x, y, i]
  526.       # Tile ID acquistion failure
  527.       if tile_id == nil
  528.         # impassable
  529.         return false
  530.       # If obstacle bit is set
  531.       elsif @passages[tile_id] & bit != 0
  532.         # impassable
  533.         return false
  534.       # If obstacle bit is set in all directions
  535.       elsif @passages[tile_id] & 0x0f == 0x0f
  536.         # impassable
  537.         return false
  538.       # If priorities other than that are 0
  539.       elsif @priorities[tile_id] == 0
  540.         # passable
  541.         return true
  542.       end
  543.     end
  544.     # passable
  545.     return true
  546.   end
  547. end
  548.  
  549.  
  550. #==============================================================================
  551. # ** Game_Character
  552. #==============================================================================
  553.  
  554. class Game_Character
  555.   #--------------------------------------------------------------------------
  556.   # * Determine if Passable (Overwrite)
  557.   #     x : x-coordinate
  558.   #     y : y-coordinate
  559.   #     d : direction (0,2,4,6,8)
  560.   #         * 0 = Determines if all directions are impassable (for jumping)
  561.   #--------------------------------------------------------------------------
  562.   def passable?(x, y, d)
  563.     # Get new coordinates
  564.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  565.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  566.     # If coordinates are outside of map
  567.     unless $game_map.valid?(new_x, new_y)
  568.       # impassable
  569.       return false
  570.     end
  571.     # If through is ON
  572.     if @through
  573.       # passable
  574.       return true
  575.     end
  576.     # If unable to leave first move tile in designated direction
  577.     unless $game_map.passable?(x, y, d, self)
  578.       # impassable
  579.       return false
  580.     end
  581.     # If unable to enter move tile in designated direction
  582.     unless $game_map.passable?(new_x, new_y, 10 - d)
  583.       # impassable
  584.       return false
  585.     end
  586.     # If player coordinates are consistent with move destination
  587.     if $game_player.x == new_x and $game_player.y == new_y
  588.       # If through is OFF
  589.       unless $game_player.through
  590.         # If your own graphic is the character
  591.         if @character_name != ""
  592.           # impassable
  593.           return false
  594.         end
  595.       end
  596.     end
  597.     # Checks for events on the new position
  598.     events = $game_map.event_map[[new_x,new_y]]
  599.     if events.nil?
  600.       # passable
  601.       return true
  602.     end
  603.     # Loop all events on the tile
  604.     for event in events
  605.       # If event coordinates are consistent with move destination
  606.       if event.x == new_x and event.y == new_y
  607.         # If through is OFF
  608.         unless event.through
  609.           # If self is event
  610.           if self != $game_player
  611.             # impassable
  612.             return false
  613.           end
  614.           # With self as the player and partner graphic as character
  615.           if event.character_name != ""
  616.             # impassable
  617.             return false
  618.           end
  619.         end
  620.       end
  621.     end
  622.     # passable
  623.     return true
  624.   end
  625. end
  626.  
  627. #==============================================================================
  628. # ** Game_Event
  629. #==============================================================================
  630.  
  631. class Game_Event
  632.   # The method to alias and overwrite
  633.   AX = [:jump, :moveto, :move_down, :move_left, :move_right, :move_up,
  634.     :move_lower_left, :move_lower_right, :move_upper_left, :move_upper_right]
  635.   for method in AX
  636.     # Aliases the old method
  637.     new_method_as_string = 'zeriab_antilag_gmtev_' + method.to_s
  638.     new_method = new_method_as_string.to_sym
  639.     next if self.method_defined?(new_method)
  640.     alias_method(new_method, method)
  641.    
  642.     # Overwrites the old method
  643. PROG = <<FIN
  644.     def #{method}(*args)
  645.       old_x = @x
  646.       old_y = @y
  647.       #{new_method}(*args)
  648.       unless old_x == @x && old_y == @y
  649.         $game_map.move_event(old_x, old_y, self)
  650.       end
  651.     end
  652. FIN
  653.     # Evaluates the method definition
  654.     eval(PROG)
  655.   end
  656.  
  657.   #--------------------------------------------------------------------------
  658.   # * Always_update property (is false by default) priority under never_update
  659.   #--------------------------------------------------------------------------
  660.   attr_writer :always_update
  661.   def always_update
  662.     @always_update = false  if @always_update.nil?
  663.     return @always_update
  664.   end
  665.  
  666.   #--------------------------------------------------------------------------
  667.   # * Never_update property (is false by default) priority over always_update
  668.   #--------------------------------------------------------------------------
  669.   attr_writer :never_update
  670.   def never_update
  671.     @never_update = false  if @never_update.nil?
  672.     return @never_update
  673.   end
  674.  
  675.   #--------------------------------------------------------------------------
  676.   # * Need Update method. Fast checks here.
  677.   #--------------------------------------------------------------------------
  678.   def need_update?
  679.     return false if never_update
  680.     return true if always_update
  681.     return true if $game_map.visible?(x, y)
  682.     return true if @move_type == 3
  683.     return @trigger == 3 || @trigger == 4
  684.   end
  685.  
  686.   #--------------------------------------------------------------------------
  687.   # * Checks how the event should be updated.
  688.   #--------------------------------------------------------------------------
  689.   def check_update
  690.     name = @event.name
  691.     # Checks if the event is never to be updated. (For decoration)
  692.     for pattern in NEVER_UPDATE_NAME_PATTERNS
  693.       if (pattern.is_a?(String) && name.include?(pattern)) ||
  694.         !(pattern =~ name).nil?
  695.         self.never_update = true
  696.       end
  697.     end
  698.     # Checks if the event is to be always updated.
  699.     for pattern in ALWAYS_UPDATE_NAME_PATTERNS
  700.       if (pattern.is_a?(String) && name.include?(pattern)) ||
  701.         !(pattern =~ name).nil?
  702.         self.always_update = true
  703.       end
  704.     end
  705.     # Checks for special update for the particular id (overrules the patterns)
  706.     special_update = SPECIAL_UPDATE_IDS[[@map_id,@id]]
  707.     unless special_update.nil?
  708.       # Checks if it never should be updated
  709.       if special_update.downcase == 'n'
  710.         self.never_update = true
  711.         self.always_update = false
  712.       # Checks if it always should be updated
  713.       elsif special_update.downcase == 'a'
  714.         self.always_update = true
  715.         self.never_update = false
  716.       end
  717.     end
  718.   end
  719. end
  720.  
  721. #==============================================================================
  722. # ** Game_Event
  723. #==============================================================================
  724.  
  725. class Game_Player
  726.   #--------------------------------------------------------------------------
  727.   # * Same Position Starting Determinant
  728.   #--------------------------------------------------------------------------
  729.   def check_event_trigger_here(triggers)
  730.     result = false
  731.     # If event is running
  732.     if $game_system.map_interpreter.running?
  733.       return result
  734.     end
  735.     # Retrives the events on the specified tile
  736.     events = $game_map.event_map[[@x,@y]]
  737.     unless events.nil?
  738.       # Loop through events on tile
  739.       for event in events
  740.         # If event triggers are consistent
  741.         if triggers.include?(event.trigger)
  742.           # If starting determinant is same position event (other than jumping)
  743.           if not event.jumping? and event.over_trigger?
  744.             event.start
  745.             result = true
  746.           end
  747.         end
  748.       end
  749.     end
  750.     return result
  751.   end
  752.   #--------------------------------------------------------------------------
  753.   # * Front Event Starting Determinant
  754.   #--------------------------------------------------------------------------
  755.   def check_event_trigger_there(triggers)
  756.     result = false
  757.     # If event is running
  758.     if $game_system.map_interpreter.running?
  759.       return result
  760.     end
  761.     # Calculate front event coordinates
  762.     new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  763.     new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  764.     # Retrives the events on the specified tile
  765.     events = $game_map.event_map[[new_x,new_y]]
  766.     unless events.nil?
  767.       # Loop through events on tile
  768.       for event in events
  769.         # If event triggers are consistent
  770.         if triggers.include?(event.trigger)
  771.           # If starting determinant is front event (other than jumping)
  772.           if not event.jumping? and not event.over_trigger?
  773.             event.start
  774.             result = true
  775.           end
  776.         end
  777.       end
  778.     end
  779.     # If fitting event is not found
  780.     if result == false
  781.       # If front tile is a counter
  782.       if $game_map.counter?(new_x, new_y)
  783.         # Calculate 1 tile inside coordinates
  784.         new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  785.         new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  786.         # Retrives the events on the specified tile
  787.         events = $game_map.event_map[[new_x,new_y]]
  788.         unless events.nil?
  789.           # Loop through events on tile
  790.           for event in events
  791.             # If event triggers are consistent
  792.             if triggers.include?(event.trigger)
  793.               # If starting determinant is front event (other than jumping)
  794.               if not event.jumping? and not event.over_trigger?
  795.                 event.start
  796.                 result = true
  797.               end
  798.             end
  799.           end
  800.         end
  801.       end
  802.     end
  803.     return result
  804.   end
  805.   #--------------------------------------------------------------------------
  806.   # * Touch Event Starting Determinant
  807.   #--------------------------------------------------------------------------
  808.   def check_event_trigger_touch(x, y)
  809.     result = false
  810.     # If event is running
  811.     if $game_system.map_interpreter.running?
  812.       return result
  813.     end
  814.     # Retrives the events on the specified tile
  815.     events = $game_map.event_map[[x,y]]
  816.     unless events.nil?
  817.       # Loop through events on tile
  818.       for event in events
  819.         # If event coordinates and triggers are consistent
  820.         if [1,2].include?(event.trigger)
  821.           # If starting determinant is front event (other than jumping)
  822.           if not event.jumping? and not event.over_trigger?
  823.             event.start
  824.             result = true
  825.           end
  826.         end
  827.       end
  828.     end
  829.     return result
  830.   end
  831. end
  832.  
  833. #==============================================================================
  834. # ** Spriteset_Map
  835. #------------------------------------------------------------------------------
  836. # Overwrites init_characters and update_character_sprites
  837. #==============================================================================
  838.  
  839. class Spriteset_Map
  840.   #--------------------------------------------------------------------------
  841.   # * Initializes Character Sprites (Overwrite)
  842.   #--------------------------------------------------------------------------
  843.   def init_characters
  844.     # Creates the array used for holding the hero sprite.
  845.     # Is here for compatibility reasons.
  846.     @character_sprites = []
  847.     # Refreshes the characters in the spritemap
  848.     refresh_characters
  849.     # Refreshes the character sprites
  850.     refresh_character_sprites
  851.   end
  852.  
  853.   #--------------------------------------------------------------------------
  854.   # * Refreshes the characters.
  855.   #--------------------------------------------------------------------------
  856.   def refresh_characters
  857.     # Make character sprites
  858.     @character_event_sprites = []
  859.     @character_spritemap = {}
  860.     # Gets the tile area to search for events
  861.     min_x, max_x, min_y, max_y = $game_map.get_tile_area
  862.     # Goes through all the visible tiles and adds the sprites on those tiles
  863.     for x in min_x..max_x
  864.       for y in min_y..max_y
  865.         add_sprites(x,y)
  866.       end
  867.     end
  868.   end
  869.  
  870.   #--------------------------------------------------------------------------
  871.   # * Refreshes the character sprites.
  872.   #--------------------------------------------------------------------------
  873.   def refresh_character_sprites
  874.     # Gets the character sprites
  875.     @character_event_sprites = @character_spritemap.values.flatten
  876.     #### Note: I do not think character sprites have to be sorted, but here it
  877.     ####       is if you for some reason need them sorted.
  878.     #@character_event_sprites.sort! {|a,b| a.character.id <=> b.character.id}
  879.     # Updates the last screen x and y to the current x and y
  880.     @last_screen_x = $game_map.display_x / 128
  881.     @last_screen_y = $game_map.display_y / 128
  882.     # The sprites have just been refresh, no need to do this every frame.
  883.     @need_refresh = false
  884.   end
  885.  
  886.   #--------------------------------------------------------------------------
  887.   # * Updates Character Sprites
  888.   #--------------------------------------------------------------------------
  889.   def update_character_sprites
  890.     # Checks if the player has moved
  891.     unless @last_screen_x == $game_map.display_x / 128 &&
  892.            @last_screen_y == $game_map.display_y / 128
  893.       # Gets the difference in the x and y coordinate
  894.       diff_x = @last_screen_x - $game_map.display_x / 128
  895.       diff_y = @last_screen_y - $game_map.display_y / 128
  896.       # Checks if the player has moved more than one tile. (Supports 8-way)
  897.       if diff_x.abs > 1 || diff_y.abs > 1
  898.         # The player has moved more than one tile.
  899.         # This section could be extended if some of the previous visible area
  900.         # still is visible and only update the the the new areas as well as
  901.         # the parts of the old area that is now out of side.
  902.         # For ease and because this should be a rare situation I have decided
  903.         # to simple remove all sprites and start over for the new area.
  904.         @character_event_sprites.each {|sprite| sprite.dispose}
  905.         # Initialized the sprites for the new area
  906.         init_characters
  907.       else
  908.         # Updates the buffer
  909.         update_buffer(diff_x, diff_y)
  910.       end
  911.       # Refresh the character sprites. (To which should be updated)
  912.       refresh_character_sprites
  913.     else
  914.       # Refreshed the character sprites if it is needed
  915.       refresh_character_sprites if @need_refresh
  916.     end
  917.     # Updates the sprites.
  918.     @character_event_sprites.each {|sprite| sprite.update}
  919.     # Updates the hero sprite. Is here to increase compatibility with other
  920.     # scripts using this array. Most caterpillar scripts for example
  921.     @character_sprites.each {|sprite| sprite.update}
  922.   end
  923.  
  924.   #--------------------------------------------------------------------------
  925.   # * Updates Character Sprites
  926.   #--------------------------------------------------------------------------
  927.   def update_buffer(diff_x, diff_y)
  928.     # Gets the tile area to search for events
  929.     min_x, max_x, min_y, max_y = $game_map.get_tile_area
  930.     # For change in x-coordinate
  931.     if diff_x > 0 # Left
  932.       # Removes any sprites outside of the buffer
  933.       unless max_x >= $game_map.width - 1
  934.         for y in min_y..max_y
  935.           dispose_sprites(max_x+1, y)  
  936.         end
  937.       end
  938.       # Adds any new sprites comming into the buffer
  939.       for y in min_y..max_y
  940.         add_sprites(min_x, y)  if @character_spritemap[[min_x,y]].nil?
  941.       end
  942.     elsif diff_x < 0 # Right
  943.       # Removes any sprites outside of the buffer
  944.       unless min_x <= 0
  945.         for y in min_y..max_y
  946.           dispose_sprites(min_x-1, y)  
  947.         end
  948.       end
  949.       # Adds any new sprites comming into the buffer
  950.       for y in min_y..max_y
  951.         add_sprites(max_x, y)  if @character_spritemap[[max_x,y]].nil?
  952.       end
  953.     end
  954.     # For change in y-coordinates
  955.     if diff_y > 0 # Up
  956.       # Removes any sprites outside of the buffer
  957.       unless max_y >= $game_map.height - 1
  958.         for x in min_x..max_x
  959.           dispose_sprites(x, max_y+1)  
  960.         end
  961.       end
  962.       # Adds any new sprites comming into the buffer
  963.       for x in min_x..max_x
  964.         add_sprites(x, min_y)  if @character_spritemap[[x,min_y]].nil?
  965.       end
  966.     elsif diff_y < 0 # Down
  967.       # Removes any sprites outside of the buffer
  968.       unless min_y <= 0
  969.         for x in min_x..max_x
  970.           dispose_sprites(x, min_y-1)  
  971.         end
  972.       end
  973.       # Adds any new sprites comming into the buffer
  974.       for x in min_x..max_x
  975.         add_sprites(x, max_y)  if @character_spritemap[[x,max_y]].nil?
  976.       end
  977.     end
  978.   end
  979.  
  980.   #--------------------------------------------------------------------------
  981.   # * Called when an event has moved
  982.   #--------------------------------------------------------------------------
  983.   def update_event(old_x,old_y,event)
  984.     # Finds the sprites on the event's old position
  985.     sprites = @character_spritemap[[old_x,old_y]]
  986.     # Checks if there are any sprites on the event's old position
  987.     unless sprites.nil?
  988.       # Goes through the sprites to find which one is attached to the given
  989.       # event. Sprite is nil if no sprite on the event's old position is
  990.       # attached to the given event.
  991.       sprite = nil
  992.       for sprite in sprites
  993.         break if sprite.character == event
  994.       end
  995.     end
  996.     # If there is not a sprite attached to the event
  997.     if sprite.nil?
  998.       # Checks if the event has become visible
  999.       if $game_map.visible?(event.x, event.y)
  1000.         # A sprite is create because the event is now visible
  1001.         sprite = Sprite_Character.new(@viewport1, event)
  1002.         # The sprite is added at the event's current position
  1003.         add_sprite(event.x,event.y,sprite)
  1004.         # We need to refresh the character sprites since we added one.
  1005.         @need_refresh = true
  1006.       end
  1007.     else # A sprite is attached to the event
  1008.       # Checks if the event is still visible
  1009.       if $game_map.visible?(event.x, event.y)
  1010.         # The event is still visible and moved from its old coordinate
  1011.         # to its new coordinates.
  1012.         move_event(old_x, old_y, sprite)
  1013.       else
  1014.         # The sprite is not visible anymore and thus removed
  1015.         remove_sprite(old_x,old_y,sprite)
  1016.         # The sprite is disposed since we don't want to wait for Ruby's
  1017.         # garbage cleaner to remove the sprite from view. (For big sprites)
  1018.         sprite.dispose
  1019.         # We need to refresh the character sprites since we removed one.
  1020.         @need_refresh = true
  1021.       end
  1022.     end
  1023.   end
  1024.  
  1025.   ##
  1026.   ## Macros
  1027.   ##
  1028.  
  1029.   #--------------------------------------------------------------------------
  1030.   # * Creates and adds sprites for all the events with the given x and y
  1031.   #   coordinates to the spritemap.
  1032.   #--------------------------------------------------------------------------
  1033.   def add_sprites(x,y)
  1034.     # Returns if there are no events with the given x and y coordinates
  1035.     return if $game_map.event_map[[x,y]].nil?
  1036.     for event in $game_map.event_map[[x,y]]
  1037.       # Creates a sprite for the event
  1038.       sprite = Sprite_Character.new(@viewport1, event)
  1039.       # Adds the sprite to the spritemap
  1040.       add_sprite(x,y,sprite)
  1041.     end
  1042.   end
  1043.  
  1044.   #--------------------------------------------------------------------------
  1045.   # * Disposes all the sprites on given x,y tile
  1046.   #--------------------------------------------------------------------------
  1047.   def dispose_sprites(x,y)
  1048.     # Returns if there are no sprites with the given coordinates
  1049.     return if @character_spritemap[[x,y]].nil?
  1050.     for sprite in @character_spritemap[[x,y]]
  1051.       # Removes the sprite from the datastructure
  1052.       remove_sprite(x,y,sprite)
  1053.       # Disposes the sprite
  1054.       sprite.dispose unless sprite.dispose
  1055.     end
  1056.   end
  1057.  
  1058.   #--------------------------------------------------------------------------
  1059.   # * Moves the sprite from its old coordinates to its new coordinates
  1060.   #--------------------------------------------------------------------------
  1061.   def move_event(old_x,old_y,sprite)
  1062.     # Gets the event attached to the character
  1063.     event = sprite.character
  1064.     # Returns if the sprite have not change position
  1065.     return if old_x == event.x && old_y == event.y
  1066.     # Removes the sprite from its old location
  1067.     remove_sprite(old_x, old_y, sprite)
  1068.     # Adds the sprite to the new location
  1069.     add_sprite(event.x, event.y, sprite)
  1070.   end
  1071.  
  1072.   ##
  1073.   ## Low level methods, alters the datastructure directly
  1074.   ##
  1075.  
  1076.   #--------------------------------------------------------------------------
  1077.   # * Adds the given sprite to the given x and y coordinate to
  1078.   #   @character_spritemap.
  1079.   #--------------------------------------------------------------------------
  1080.   def add_sprite(x,y,sprite)
  1081.     # Checks if there a not any sprite on the given tile already
  1082.     if @character_spritemap[[x,y]].nil?
  1083.       # Adds the sprite to the spriteset as an array containing the sprite
  1084.       @character_spritemap[[x,y]] = [sprite]
  1085.     else
  1086.       # Adds the sprite to the array of sprites with the same x and y
  1087.       # coordinates.
  1088.       @character_spritemap[[x,y]] << sprite
  1089.     end
  1090.   end
  1091.    
  1092.   #--------------------------------------------------------------------------
  1093.   # * Removes the given sprite with the given x and y coordinate from
  1094.   #   @character_spritemap.
  1095.   #--------------------------------------------------------------------------
  1096.   def remove_sprite(x,y,sprite)
  1097.     # Returns if there are no sprites with the given x and y coordinate
  1098.     return  unless !@character_spritemap[[x,y]].nil? &&
  1099.                    @character_spritemap[[x,y]].include?(sprite)
  1100.     # Checks if there are more sprites with the same coordinates
  1101.     if @character_spritemap[[x,y]].size > 1
  1102.       # Removes the sprite from the array of sprites with the given coordinates
  1103.       @character_spritemap[[x,y]].delete(sprite)
  1104.     else
  1105.       # Deletes the key attached to the array since there are no sprites left.
  1106.       @character_spritemap.delete([x,y])
  1107.     end
  1108.   end
  1109. end
  1110.  
  1111. #------------------------------------------------------------------------------
  1112. # * End SDK Enable Test
  1113. #------------------------------------------------------------------------------
  1114. end
  1115.  
  1116. unless Module.constants.include?('SDK')
  1117.   #============================================================================
  1118.   # * Compatibility :
  1119.   #
  1120.   #   This will probably not be compatible with scripts extending or modifying
  1121.   #   the overwritten methods.
  1122.   #  
  1123.   #   The following methods has been overwritten:
  1124.   #    * Game_Map.update
  1125.   #    * Spriteset_Map.initialize
  1126.   #    * Spriteset_Map.update
  1127.   #============================================================================
  1128.  
  1129.   #============================================================================
  1130.   # ** Game_Map
  1131.   #============================================================================
  1132.   class Game_Map
  1133.     #--------------------------------------------------------------------------
  1134.     # * Update Common Events
  1135.     #--------------------------------------------------------------------------
  1136.     def update_common_events
  1137.       for common_event in @common_events.values
  1138.         common_event.update
  1139.       end
  1140.     end
  1141.     #------------------------------------------------------------------------
  1142.     # * Frame Update Overwrite
  1143.     #------------------------------------------------------------------------
  1144.     def update
  1145.       # Refresh map if necessary
  1146.       if $game_map.need_refresh
  1147.         refresh
  1148.       end
  1149.       # If scrolling
  1150.       if @scroll_rest > 0
  1151.         # Change from scroll speed to distance in map coordinates
  1152.         distance = 2 ** @scroll_speed
  1153.         # Execute scrolling
  1154.         case @scroll_direction
  1155.         when 2  # Down
  1156.           scroll_down(distance)
  1157.         when 4  # Left
  1158.           scroll_left(distance)
  1159.         when 6  # Right
  1160.           scroll_right(distance)
  1161.         when 8  # Up
  1162.           scroll_up(distance)
  1163.         end
  1164.         # Subtract distance scrolled
  1165.         @scroll_rest -= distance
  1166.       end
  1167.       # Update map event
  1168.       update_events
  1169.       # Update common event
  1170.       update_common_events
  1171.       # Manage fog scrolling
  1172.       @fog_ox -= @fog_sx / 8.0
  1173.       @fog_oy -= @fog_sy / 8.0
  1174.       # Manage change in fog color tone
  1175.       if @fog_tone_duration >= 1
  1176.         d = @fog_tone_duration
  1177.         target = @fog_tone_target
  1178.         @fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d
  1179.         @fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d
  1180.         @fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d
  1181.         @fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d
  1182.         @fog_tone_duration -= 1
  1183.       end
  1184.       # Manage change in fog opacity level
  1185.       if @fog_opacity_duration >= 1
  1186.         d = @fog_opacity_duration
  1187.         @fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d
  1188.         @fog_opacity_duration -= 1
  1189.       end
  1190.     end
  1191.   end
  1192.  
  1193.   #============================================================================
  1194.   # ** Spriteset_Map
  1195.   #============================================================================
  1196.   class Spriteset_Map
  1197.     #------------------------------------------------------------------------
  1198.     # * Object Initialization Overwrite
  1199.     #------------------------------------------------------------------------
  1200.     def initialize
  1201.       # Make viewports
  1202.       @viewport1 = Viewport.new(0, 0, 640, 480)
  1203.       @viewport2 = Viewport.new(0, 0, 640, 480)
  1204.       @viewport3 = Viewport.new(0, 0, 640, 480)
  1205.       @viewport2.z = 200
  1206.       @viewport3.z = 5000
  1207.       # Make tilemap
  1208.       @tilemap = Tilemap.new(@viewport1)
  1209.       @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
  1210.       for i in 0..6
  1211.         autotile_name = $game_map.autotile_names[i]
  1212.         @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
  1213.       end
  1214.       @tilemap.map_data = $game_map.data
  1215.       @tilemap.priorities = $game_map.priorities
  1216.       # Make panorama plane
  1217.       @panorama = Plane.new(@viewport1)
  1218.       @panorama.z = -1000
  1219.       # Make fog plane
  1220.       @fog = Plane.new(@viewport1)
  1221.       @fog.z = 3000
  1222.       # Make character sprites
  1223.       init_characters
  1224.       # Make hero sprite
  1225.       @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
  1226.       # Make weather
  1227.       @weather = RPG::Weather.new(@viewport1)
  1228.       # Make picture sprites
  1229.       @picture_sprites = []
  1230.       for i in 1..50
  1231.         @picture_sprites.push(Sprite_Picture.new(@viewport2,
  1232.           $game_screen.pictures[i]))
  1233.       end
  1234.       # Make timer sprite
  1235.       @timer_sprite = Sprite_Timer.new
  1236.       # Frame update
  1237.       update
  1238.     end
  1239.       #--------------------------------------------------------------------------
  1240.       # * Dispose
  1241.       #--------------------------------------------------------------------------
  1242.       def dispose
  1243.         # Dispose of tilemap
  1244.         @tilemap.tileset.dispose
  1245.         for i in 0..6
  1246.           @tilemap.autotiles[i].dispose
  1247.         end
  1248.         @tilemap.dispose
  1249.         # Dispose of panorama plane
  1250.         @panorama.dispose
  1251.         # Dispose of fog plane
  1252.         @fog.dispose
  1253.         # Dispose of weather
  1254.         @weather.dispose
  1255.         # Dispose of picture sprites
  1256.         for sprite in @picture_sprites
  1257.           sprite.dispose
  1258.         end
  1259.         # Dispose of character sprites
  1260.         for sprite in @character_event_sprites
  1261.           sprite.dispose unless sprite.disposed?
  1262.         end
  1263.         # Dispose of timer sprite
  1264.         @timer_sprite.dispose
  1265.         # Dispose of viewports
  1266.         @viewport1.dispose
  1267.         @viewport2.dispose
  1268.         @viewport3.dispose
  1269.       end
  1270.     #------------------------------------------------------------------------
  1271.     # * Frame Update Overwrite
  1272.     #------------------------------------------------------------------------
  1273.     def update
  1274.       # If panorama is different from current one
  1275.       if @panorama_name != $game_map.panorama_name or
  1276.          @panorama_hue != $game_map.panorama_hue
  1277.         @panorama_name = $game_map.panorama_name
  1278.         @panorama_hue = $game_map.panorama_hue
  1279.         if @panorama.bitmap != nil
  1280.           @panorama.bitmap.dispose
  1281.           @panorama.bitmap = nil
  1282.         end
  1283.         if @panorama_name != ""
  1284.           @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
  1285.         end
  1286.         Graphics.frame_reset
  1287.       end
  1288.       # If fog is different than current fog
  1289.       if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
  1290.         @fog_name = $game_map.fog_name
  1291.         @fog_hue = $game_map.fog_hue
  1292.         if @fog.bitmap != nil
  1293.           @fog.bitmap.dispose
  1294.           @fog.bitmap = nil
  1295.         end
  1296.         if @fog_name != ""
  1297.           @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
  1298.         end
  1299.         Graphics.frame_reset
  1300.       end
  1301.       # Update tilemap
  1302.       @tilemap.ox = $game_map.display_x / 4
  1303.       @tilemap.oy = $game_map.display_y / 4
  1304.       @tilemap.update
  1305.       # Update panorama plane
  1306.       @panorama.ox = $game_map.display_x / 8
  1307.       @panorama.oy = $game_map.display_y / 8
  1308.       # Update fog plane
  1309.       @fog.zoom_x = $game_map.fog_zoom / 100.0
  1310.       @fog.zoom_y = $game_map.fog_zoom / 100.0
  1311.       @fog.opacity = $game_map.fog_opacity
  1312.       @fog.blend_type = $game_map.fog_blend_type
  1313.       @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
  1314.       @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
  1315.       @fog.tone = $game_map.fog_tone
  1316.       # Update character sprites
  1317.       update_character_sprites
  1318.       # Update weather graphic
  1319.       @weather.type = $game_screen.weather_type
  1320.       @weather.max = $game_screen.weather_max
  1321.       @weather.ox = $game_map.display_x / 4
  1322.       @weather.oy = $game_map.display_y / 4
  1323.       @weather.update
  1324.       # Update picture sprites
  1325.       for sprite in @picture_sprites
  1326.         sprite.update
  1327.       end
  1328.       # Update timer sprite
  1329.       @timer_sprite.update
  1330.       # Set screen color tone and shake position
  1331.       @viewport1.tone = $game_screen.tone
  1332.       @viewport1.ox = $game_screen.shake
  1333.       # Set screen flash color
  1334.       @viewport3.color = $game_screen.flash_color
  1335.       # Update viewports
  1336.       @viewport1.update
  1337.       @viewport3.update
  1338.     end
  1339.   end
  1340. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement