Advertisement
Zeriab

[RMXP] Zeriab's Anti Event Lag System v1.2c

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