KK20

F0's Time/Climate Fix

Jun 23rd, 2014
195
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # Complete Climate and Time System (CCTS)
  3. # Author: ForeverZer0
  4. # Version: 1.2
  5. # Date: 10.10.2010
  6. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  7. #                             VERSION HISTORY      
  8. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  9. # v.1.0   5.12.2010
  10. #   - Original Release
  11. # v.1.1   5.26.2010
  12. #   - Added an attr_reader I mistakenly placed in the debugger that would make
  13. #     the debugger a requirement for the script to work.
  14. #   - Added some commands for message text to display the time, day, month, etc.
  15. # v.1.2   10.10.10
  16. #   - Added the "Good Weather Switch" by popular demand.
  17. #   - Added ability to have game variables set to the current time values.
  18. #   - Fixed bug so that the map refreshes properly when switches change.
  19. #   - Fixed it so that window returns when scene changes and returns.
  20. #   - Cleaned up overall code and added comments to help follow the main flow
  21. #     of the script and understand it better.
  22. #   - Changed the debug. No longer just prints to the standard output, but now
  23. #     displays all the same info on-screen in real-time as it occurs.
  24. #   - Built the Missing Climate Logger into the script. Will create a text file
  25. #     in the directory listing any errors every time the game is play-tested.
  26. #   - Added configurable format for how time is displayed.
  27. #   - Added configuration for the look of the clock's windowskin
  28. #   - Added Analog Clock spriteset.
  29. #   - Consolidated the scripts into one.
  30. # v.1.2.1  10.12.10
  31. #   - Fixed a syntax error (Thanks rim1000 for pointing out)
  32. # v.1.2.2  10.16.10
  33. #   - Actually fixed the bug I should have fixed in 1.2.1
  34. #   - Altered 'calculate_time' method, which would not allow the switches to
  35. #     refresh correctly until the next game hour passed. Switches will not
  36. #     update each game minute as they were intended to.
  37. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  38. #
  39. # Introduction:
  40. #
  41. #   This script will give you TOTAL control of weather and time in your game. It
  42. #   will allow you to set up different climates that use different weather
  43. #   patterns, tints, sounds, and effects. It is also a complete Time System that
  44. #   gives you full control of, and keeps track of, time, with every possible
  45. #   configuration at your disposal. Note this script comes with a preset config
  46. #   that will be suitable for most's needs, but it can be configured to the most
  47. #   extreme level if so desired, which will require more work. It is not
  48. #   neccessary to do this, but the ability is there.
  49. #
  50. # Features:
  51. #
  52. #   - Automatic weather control with defined types, frequency, probabilities,
  53. #     tints, and sounds for any and every map in your game.
  54. #   - Weather tint and BGS will fade in/out smoothly with the weather for a very
  55. #     realistic feel
  56. #   - Configurable screen tints for every climate, month, and hour that will
  57. #     smoothly transition over the course of each hour, not transition to day
  58. #     or night in matter of seconds.
  59. #   - Completely configurable calendar system that can use custom names for days
  60. #     and months, custom month lengths, etc.
  61. #   - Can easily use configurable switches and variables for event conditions
  62. #     based off the hour of the day, the season of the year, or the current
  63. #     weather.
  64. #   - Comes with a clock that can be toggled on/off by the player, with custom
  65. #     location, opacity, and font name/size options.
  66. #   - Also have option to use an analog clock.
  67. #   - Complete control to freeze the time, screen tone, weather, or time speed,
  68. #     seperately or together, with simple script calls.
  69. #   - Comes with error checking and a debugger for easily testing your own
  70. #     customization, and to help understand the system.
  71. #   - Short, simple script calls for easy manipulation
  72. #   - Compatible with Zero Advanced Weather and MAWS (v.1.2 or higher)
  73. #
  74. # Instructions:
  75. #
  76. #   All instructions for configuration are explained below in each section.
  77. #
  78. #   ------------------------------------------------------------------------
  79. #
  80. #   Script Calls:
  81. #
  82. # * time.freeze(true/false)
  83. #     - Will freeze/unfreeze time, tone, and weather.
  84. #
  85. # * time.tone_freeze(true/false)
  86. #     - Will freeze/unfreeze the screen tone from updating automatically. Use
  87. #       before you would like to set a custom screen tone, otherwise the system
  88. #       will override it.
  89. #
  90. # * time.weather_freeze(true/false)
  91. #     - Will freeze/unfreeze the weather from updating. Freeze if you would like
  92. #       to manually set the weather and do not want the system to override it.
  93. #
  94. # * time.speed_freeze(true/false)
  95. #     - Will keep the time speed set at a specific rate, and not change per each
  96. #       map as the system usually does.
  97. #
  98. # * time.change_speed(SPEED)
  99. #     - Will set the time speed to SPEED. Use time.speed_freeze if you would
  100. #       would like to keep it there indefinitely
  101. #
  102. # * time.set(m, h, d, m, y)
  103. #     - Sets the time to time defined in (minute, hour, day, month, year)
  104. #       This will also allow you to 'go back' in time.
  105. #
  106. # * time.advance_minute(NUMBER)
  107. #     - Advances minute by NUMBER
  108. #
  109. # * time.advance_hour(NUMBER)
  110. #     - Advances hour by NUMBER
  111. #
  112. # * time.advance_day(NUMBER)
  113. #     - Advances day by NUMBER
  114. #
  115. # * time.advance_month(NUMBER)
  116. #     - Advances month by NUMBER
  117. #
  118. # * time.advance_year(NUMBER)
  119. #     - Advances year by NUMBER
  120. #
  121. # * time.memorize(INDEX)
  122. #     - Memorizes the current time to an array at INDEX. The INDEX can be any
  123. #       integer you like, it is used to reference later if the time is restored.
  124. #       This will allow for you to memorize as many 'times' as you need. Using
  125. #       an existing INDEX will over-write the old one.
  126. #
  127. # * time.restore(INDEX)
  128. #     - Sets the time to memorized time at INDEX. Does nothing if INDEX does not
  129. #       exist. Obviously, you must have a memorized time before using.
  130. #
  131. # * time.clock(true/false)
  132. #     - Enables/Disables player from toggling clock. Will dispose the clock
  133. #       if disabled when clock is showing.
  134. #
  135. # * time.simple_clock(true/false)
  136. #     - By default, the clock displays the time, day, and date. If this is true,
  137. #       the clock will only display the time, nothing else.
  138. #
  139. # * time.analog_clock(true/false)
  140. #     - Sets Analog Clock flag ON/OFF. If true, analog clock will be used,
  141. #
  142. # * time.clock_face(x, y, opacity, fontname, fontsize)
  143. #     - Changes the clock settings to defined values. Can be called with any
  144. #       number of arguments that you would like to change.
  145. #
  146. # * time.analog_face(filename, handoffset, x, y, opacity)
  147. #     - Changes the settings for the analog clock. Can be called with any number
  148. #       of arguments that you would like to change. (see note below for analog)
  149. #
  150. # * time.show_clock
  151. #     - Forcibly toggles the clock ON. Used for showing the clock when it is
  152. #       unknown if the player will have it ON or OFF at that time. The clock must
  153. #       be enabled for this method to work. (Only during Scene_Map)
  154. #
  155. # * time.change_climate(MAP_ID, CLIMATE_ID)
  156. #     - Will permanently change map with MAP_ID from its current climate to the
  157. #       the one defined by CLIMATE_ID. Will not have an immediate effect on the
  158. #       current map, but will be applied next time the player returns.
  159. #
  160. # * CCTS.debug
  161. #     - Toggles the debug sprite ON/OFF. Shows almost every relevant variable
  162. #       associated with the system and how it changes in real-time. See bottom
  163. #       of script (around line 1500) for more information.
  164. #
  165. #  For scripters:
  166. #
  167. #   If you would like to create any script that is based on time in any way, you
  168. #   can use the method: "$game_system.time.current_time" in another script. It
  169. #   will return this array: [minute, hour, day, month, year].
  170. #   From there you can use/manipulate the data without having to create a bunch
  171. #   of local variables set to the different time values. This can also be used
  172. #   to store in a variable, etc. to be referenced later.
  173. #
  174. #   If you use the debugger, remember that it is a sprite and needs disposed
  175. #   accordingly. I left it independent of any default class so that if it is
  176. #   left in the script for a final version, it is one less thing that an aliased
  177. #   method needs to be checking for. It is self-updating, though, and will
  178. #   dispose automatically if it exists and the scene switches from Scene_Map.
  179. #
  180. #  Analog Clock:
  181. #  
  182. #   Three seperate images are needed for each clock face that you use for the
  183. #   analog clock. They must all start with the same name (ex. 'square'), and
  184. #   end with one of three different suffixes:
  185. #
  186. #     '_hour'  - Suffix for the hour hand image
  187. #     '_min'   - Suffix for the minute hand image
  188. #     '_back'  - Suffix for the back image
  189. #
  190. #   These three files must all be located in the Pictures folder of the game's
  191. #   directory. When you set the ANALOG_FACE, you omit the suffix from the end.
  192. #
  193. #     ex. ANALOG_FACE = ['round', 16, 0, 0, 255]
  194. #       This will search for the following three files:
  195. #         'round_back', 'round_hour', 'round_min'
  196. #
  197. #   The handoffset is used to determine how far the hand overhangs onto the
  198. #   opposite side from which it points.
  199. #
  200. #   When creating the hands, make sure that the images are vertical, and that
  201. #   the pointer side is pointing down.
  202. #
  203. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  204. #                         BEGIN CONFIGURATION
  205. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  206.  
  207. module CCTS
  208.  
  209.   # The names for your days. Use as many as you want.
  210.   DAYS =  ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
  211.            'Saturday', 'Sunday']
  212.            
  213.   # The name for your months. Use as many as you want.        
  214.   MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
  215.             'August', 'September', 'October', 'November', 'December']
  216.            
  217.   # How many days in a month? (Per each index above)
  218.   MONTH_LENGTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  219.            
  220.   # Set up as follows: [Minute, Hour, Day, Month, Year]
  221.   START_DATE = [0, 17, 4, 7, 1776]
  222.  
  223.   # Button used to toggle clock ON/OFF (if enabled). This is the game button,
  224.   # not just the key on your keyboard.
  225.   CLOCK_BUTTON = Input::Z
  226.  
  227.   # Default settings for the clock.
  228.   # Set up using this pattern. [X, Y, OPACITY, FONTNAME, FONTSIZE]
  229.   # All can be changed in-game with a script call at any time.
  230.   CLOCK_FACE =  [0, 0, 160, 'Calibri', 15]
  231.  
  232.   # Default settings for the analog clock.
  233.   # Set up using this pattern: ['FILENAME', HAND_OFFSET, X, Y, OPACITY]
  234.   # Can be changed at any time during the game with a script call.
  235.   ANALOG_FACE = ['square', 16, 0, 0, 255]
  236.  
  237.   # Set the skin for the clock (normal). Configure like one of the following:
  238.   #   Set to nil to not use a skin
  239.   #   Set to 'DEFAULT SKIN' to use whatever the player is using.
  240.   #   Set to 'FILENAME' of the skin. Must be in Windowskins folder of game.
  241.   CLOCK_SKIN = 'DEFAULT SKIN'
  242.  
  243.   # If true, the analog clock will be used by default. Can be changed later.
  244.   ANALOG_CLOCK = false
  245.  
  246.   # Configure how the time will be displayed. Ignore this if you are unsure of
  247.   # how to set this up. Look up "sprintf Format" in the Help File of the game to
  248.   # learn more of how it works.
  249.   TIME_FORMAT = '%2d:%02d'
  250.  
  251.   # The minimun/maximum number of seconds before the system re-calculates what
  252.   # weather pattern will be used. The number will be randomly selected from
  253.   # within the defined range.
  254.   WEATHER_WAIT = [20, 25]#[120, 180]
  255.  
  256.   # This variable will be always be equal to the weather type. Lets you create
  257.   # event conditions based off the weather. (must be raining to do this, etc...)
  258.   # If using Zer0 Advanced Weather, just set to same as "Weather_Type_Variable"
  259.   WEATHER_VARIABLE = 10
  260.  
  261.   # This switch will only be ON during "bad" weather effects (below). Used for
  262.   # event conditions. (Villagers go inside if it is raining, storming, etc...)
  263.   # If using Zer0 Advanced Weather, just set to same as "Adverse_Weather_Switch"
  264.   BAD_WEATHER_SWITCH = 1
  265.   # This switch will always be the opposite of the BAD_WEATHER_SWITCH.
  266.   GOOD_WEATHER_SWITCH = 2
  267.  
  268.   # Include all "bad" weather types in this array. The above switch will only
  269.   # be on when one of them is occurring
  270.   # Same as from Zer0 Advanced Weather, if using.
  271.   BAD_WEATHER_TYPES = [1, 2, 4, 5, 9, 16]
  272.  
  273.   # This variable will be set by the "season" of the year. This can also be used
  274.   # as a condition in events.
  275.   SEASON_VARIABLE = 11
  276.   # 0 = Summer
  277.   # 1 = Autumn
  278.   # 2 = Winter
  279.   # 3 = Spring
  280.   # Define the months for each season.
  281.   SEASON_MONTHS = [ [6, 7, 8],    # Summer
  282.                     [9, 10, 11],  # Autumn
  283.                     [12, 1, 2],   # Winter
  284.                     [3, 4, 5] ]   # Spring
  285.              
  286.   # These switches will be used as conditions for events, etc. They will only
  287.   # be ON during the hours defined below.
  288.   DAY_SWITCH = 2
  289.   NIGHT_SWITCH = 3
  290.  
  291.   # Define the hours that are considered "Day" and "Night". The respective
  292.   # switch above will be ON/OFF depending on the hour of the day.
  293.   DAY_START_HOUR = 6        # (6:00 a.m. - 9:00 p.m.) = Day
  294.   NIGHT_START_HOUR = 21     # (9:00 p.m. - 6:00 a.m.) = Night
  295.  
  296.   # IDs of variables that will be equal to their named value. They can be used
  297.   # for eventing, etc. Set any to nil that you do not want to use.
  298.   MINUTE_VARIABLE = 1
  299.   HOUR_VARIABLE = 2
  300.   DAY_VARIABLE = 3
  301.   MONTH_VARIABLE = 4
  302.   YEAR_VARIABLE = 5
  303.  
  304.   # If true, and $DEBUG, a text file will be created each load in the games
  305.   # directory that lists maps that do not have a climate defined, or those that
  306.   # are defined more than once.
  307.   WRITE_MISSING_DATA = false
  308.  
  309.   #-----------------------------------------------------------------------------
  310.   # Weather Tints
  311.   #   Set the tint influence for each weather type. These are NOT the values
  312.   #   the screen tint will be, rather they are the amount applied to whatever
  313.   #   the current screen tint already is. They will transition in/out at the
  314.   #   same rate of the weather transition.
  315.   #-----------------------------------------------------------------------------
  316.   def self.weather_tint(type)
  317.     case type
  318.   # when WEATHER_TYPE then return [RED, GREEN, BLUE, GRAY]
  319.     when 1, 4
  320.       return [-20, -20, -15, 10]
  321.     when 2, 5, 9
  322.       return [-30, -30, -20, 15]
  323.     when 3, 16
  324.       return [-15, -15, -15, 20]  
  325.     end
  326.     return [0, 0, 0, 0]
  327.   end
  328.   #-----------------------------------------------------------------------------
  329.   # Hourly Tints
  330.   #   Define the target tints for each hour of the day, for each climate.
  331.   #   The month, hour, and climate_id are all passed as arguments so you can
  332.   #   create as in-depth of a configuration as you like. Just create branches
  333.   #   within branches using the climate, month, and hour as conditions to define
  334.   #   the desired screen tone. There will be no tint (0, 0, 0, 0) for anything
  335.   #   left undefined. (see presets below for examples)
  336.   #
  337.   #   Setup: [RED, GREEN, BLUE, GRAY]
  338.   #-----------------------------------------------------------------------------
  339.   def self.time_tint(climate_id, hour, month)
  340.     case climate_id
  341.     #-------------------------------------------------------------------
  342.     when 0    
  343.       # Climate 0 (Normal Outdoors)
  344.       case month
  345.       when 1, 2, 12 # Winter Months (Less daylight hours, overall more gray)
  346.         case hour
  347.         when 17 then return [-20, -20, -20, 10]
  348.         when 18 then return [-30, -30, -30, 20]
  349.         when 0..6, 19..23
  350.           return [-100, -100, -20, 15]
  351.         when 7 then return [-15, -15, -25, 10]
  352.         when 8..18
  353.           return [-10, -10, -10, 10]
  354.         end
  355.       when 6, 7, 8 # Summer Months (More hours of daylight, brighter)
  356.         case hour
  357.         when 18 then return [-25, -25, -10, 5]
  358.         when 19 then return [-50, -50, -15, 10]
  359.         when 20..23, 0..5
  360.           return [-100, -100, -20, 15]
  361.         when 6 then return [10, 10, -10, 0]
  362.         when 7..17
  363.           return [5, 5, -5, 0]
  364.         end
  365.       when 3, 4, 5 # Spring Months (Average)
  366.         case hour
  367.         when 18 then return [0, 0, -15, 5]
  368.         when 19 then return [-15, -15, -30, 10]
  369.         when 20..23, 0..5
  370.           return [-100, -100, -20, 10]
  371.         when 6 then return [-5, -5, -20, 0]
  372.         end
  373.       when 9, 10, 11 # Autumn Months (More 'Orange-Yellow' tinting in evening)
  374.         case hour
  375.         when 18 then return [5, 5, -20, 0]
  376.         when 19 then return [-5, -5, -25, 10]
  377.         when 20..23, 0..5
  378.           return [-100, -100, -20, 10]
  379.         when 6 then return [10, 5, -10, 10]
  380.         end
  381.       end
  382.     #-------------------------------------------------------------------
  383.     when 2
  384.       # Climate 2 (Snow)
  385.       # No month branches. Same tints used year-round
  386.       case hour
  387.       when 17 then return [-20, -20, -20, 10]
  388.       when 18 then return [-30, -30, -30, 20]
  389.       when 0..6, 19..23
  390.         return [-100, -100, -20, 20]
  391.       when 7 then return [-15, -15, -25, 10]
  392.       when 8..18
  393.         return [-10, -10, -10, 10]
  394.       end
  395.     #-------------------------------------------------------------------
  396.     when 3
  397.     # Climate 3 (Desert)
  398.     # No month branches. Same tints used year-round
  399.       case hour
  400.       when 18 then return [-25, -25, -10, 5]
  401.       when 19 then return [-50, -50, -15, 10]
  402.       when 20..23, 0..5
  403.         return [-100, -100, -20, 15]
  404.       when 6 then return [10, 10, -10, 0]
  405.       when 7..17
  406.         return [5, 5, -5, 0]
  407.       end
  408.     #-------------------------------------------------------------------
  409.     when 4
  410.     # Climate 4 (Underground/Cave)
  411.     # Same tint, year-round for every hour
  412.       return [-20, -20, -20, 0]
  413.     #-------------------------------------------------------------------
  414.     end
  415.     # Default return value for undefined time/climate (Don't edit)
  416.     return [0, 0, 0, 0]
  417.   end
  418.   #-----------------------------------------------------------------------------
  419.   # Weather Probability
  420.   #   Define the weather probabilities for each climate. The climate ID and the
  421.   #   month are passed as arguments for branching. This will allow you to make
  422.   #   it snow in the winter, storm in the summer, etc.
  423.   #
  424.   #   Set up like this:
  425.   #
  426.   #   case climate_id
  427.   #   when CLIMATE_ID
  428.   #     case month
  429.   #     when MONTH then return [[TYPE, PROB], [TYPE, PROB], [TYPE, PROB], etc]
  430.   #
  431.   #   If you are using Zer0 Advanced Weather or MAWS (v.1.2 or >) where the
  432.   #   "variation" is used, just add the variation value into the respective
  433.   #   array, like this:
  434.   #                     [TYPE, PROBABILITY, VARIATION]
  435.   #
  436.   #   You need not define a probability for 0, or no weather. It is the default
  437.   #   value used for undefined weather and when the weather probability is not
  438.   #   high enough when the system calculates it.
  439.   #
  440.   #   The actual weather will be chosen randomly from all types that have a  
  441.   #   probability above the randomly chosen 'chance' at each weather update.
  442.   #-----------------------------------------------------------------------------
  443.   def self.weather_prob(climate_id, month)
  444.     case climate_id
  445.     when 0, 1 # Normal Outdoor
  446.       case month
  447.       # Winter
  448.       when 1, 2, 12
  449.         return [[3, 17], [16, 12]]
  450.       # Spring
  451.       when 3, 4, 5
  452.         return [[1, 30], [2, 25], [9, 25]]  
  453.       # Summer  
  454.       when 6, 7, 8
  455.         return [[1, 20], [9, 60], [2, 80]] #!!!
  456.       # Autumn
  457.       when 9, 10, 11
  458.         return [[1, 15], [9, 10], [6, 25, rand(3)],  # random "variation"
  459.                 [7, 25, rand(3)], [8, 25, rand(3)]]
  460.       end
  461.     when 2 # Snow/Arctic (year-round, no month branching)    
  462.       return [[3, 80], [16, 50]]
  463.     when 3 # Desert (year-round, no month branching)
  464.       return [[1, 5]]
  465.     end
  466.   end
  467.   #-----------------------------------------------------------------------------
  468.   # Weather BGS
  469.   #   Define the BGS used for each weather type. They BGS will fade in/out at
  470.   #   the same rate of the weather's transition. Volume will be 50% for maps
  471.   #   that do not have weather, but still have weather sound.
  472.   #-----------------------------------------------------------------------------
  473.   def self.weather_BGS(type)
  474.     case type
  475.   # when WEATHER_TYPE then return ['FILENAME', VOLUME, PITCH]
  476.     when 1 then return ['005-Rain01', 80, 100]    # Rain
  477.     when 2 then return ['006-Rain02', 80, 100]    # Heavy Rain
  478.     when 3 then return ['001-Wind01', 80, 100]    # Snow
  479.     when 4 then return ['005-Rain01', 60, 75]     # Hail
  480.     when 5, 9
  481.       return ['007-Rain03', 80, 100]              # Thunder/Realistic Storm
  482.     when 7 then return ['003-Wind03', 80, 100]    # Blowing Leaves
  483.     when 8, 16
  484.       return ['004-Wind04', 80, 100]              # Swirling Leaves/Blowing Snow
  485.     when 22 then return ['015-Quake01', 100, 125] # Falling Rocks
  486.     end
  487.   end
  488. end
  489.  
  490.   #-----------------------------------------------------------------------------
  491.  
  492. class Climate
  493.  
  494.   attr_accessor :maps
  495.  
  496.   def initialize
  497.     @climate = []
  498.   #-----------------------------------------------------------------------------
  499.   # Initialize New Climates
  500.   #   Simply follow the same pattern for each new climate you create.
  501.   #-----------------------------------------------------------------------------
  502.     @climate[0] = Game_Climate.new(0)
  503.     @climate[1] = Game_Climate.new(1)
  504.     @climate[2] = Game_Climate.new(2)
  505.     @climate[3] = Game_Climate.new(3)
  506.     @climate[4] = Game_Climate.new(4)
  507.   #-----------------------------------------------------------------------------
  508.   # Climate Names
  509.   #   Create names for the different climates.
  510.   #-----------------------------------------------------------------------------
  511.     @climate[0].name = 'Outdoors'
  512.     @climate[1].name = 'Indoors'
  513.     @climate[2].name = 'Snow'
  514.     @climate[3].name = 'Desert'
  515.     @climate[4].name = 'Underground'
  516.   #-----------------------------------------------------------------------------
  517.   # Weather for this Climate?
  518.   #   If false, no weather will be shown for climate, although weather sound and
  519.   #   tinting can still be used if desired.
  520.   #-----------------------------------------------------------------------------
  521.     @climate[0].weather = true
  522.     @climate[1].weather = false
  523.     @climate[2].weather = true
  524.     @climate[3].weather = true
  525.     @climate[4].weather = false
  526.   #-----------------------------------------------------------------------------
  527.   # Weather Tinting?
  528.   #   If true, different weather patterns will influence the screen tint
  529.   #-----------------------------------------------------------------------------
  530.     @climate[0].tinting = true
  531.     @climate[1].tinting = false
  532.     @climate[2].tinting = true
  533.     @climate[3].tinting = true
  534.     @climate[4].tinting = false
  535.   #-----------------------------------------------------------------------------  
  536.   # Weather Sound?
  537.   #   If true, weather BGS will be played automatically for that climate
  538.   #-----------------------------------------------------------------------------
  539.     @climate[0].sound = true
  540.     @climate[1].sound = true
  541.     @climate[2].sound = true
  542.     @climate[3].sound = true
  543.     @climate[4].sound = false
  544.   #-----------------------------------------------------------------------------  
  545.   # Time Speed
  546.   #   This will be the default time speed used for the climate. It can be
  547.   #   overridden with script calls in-game if needed. "1" is real-time, and
  548.   #   any other number is multiples of real-time, so "5" is 5 times as fast as
  549.   #   the real world. (unless you live in a videogame)
  550.   #-----------------------------------------------------------------------------
  551.     @climate[0].speed = 20
  552.     @climate[1].speed = 8
  553.     @climate[2].speed = 5
  554.     @climate[3].speed = 4
  555.     @climate[4].speed = 2
  556.   #-----------------------------------------------------------------------------
  557.   # Maps for each climate
  558.   # Include IDs of maps that use each respective climate.
  559.   #-----------------------------------------------------------------------------
  560.     @climate[0].maps = [1]
  561.     @climate[1].maps = [2]
  562.     @climate[2].maps = []
  563.     @climate[3].maps = []
  564.     @climate[4].maps = [3]
  565.   #-----------------------------------------------------------------------------
  566.   end
  567. #-------------------------------------------------------------------------------
  568.   def map_climate(map_id)
  569.     @climate.each {|climate| return climate if climate.maps.include?(map_id)}
  570.     # Returns a dummy climate with empty settings if not defined.
  571.     return Game_Climate.new(-1, 'DUMMY', false, false, false, 5, [])  
  572.   end
  573. end
  574.  
  575. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  576. #                           END CONFIGURATION  
  577. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  578.  
  579. #            **   EDIT BELOW THIS POINT AT YOUR OWN RISK   **
  580.  
  581. #===============================================================================
  582. # ** Time_System
  583. #===============================================================================
  584.  
  585.   $ccts = 1.22
  586.   # Variable plug-in. Used so CCTS can be recognized by other scripts.
  587.  
  588. class Time_System
  589.  
  590.   attr_reader :minute, :hour, :day, :month, :year, :speed_frozen
  591.    
  592.   def initialize
  593.     # Initialize instance variables used in the system.
  594.     @frame_count, @speed, @memory = 0, 1, []
  595.     # Set time variables to configured start values.
  596.     @minute, @hour = CCTS::START_DATE[0], CCTS::START_DATE[1]
  597.     @day, @month = CCTS::START_DATE[2], CCTS::START_DATE[3]
  598.     @year = CCTS::START_DATE[4]
  599.     # Initialize the "frozen" flags.
  600.     @frozen = @speed_frozen = false
  601.     # Check for any errors in the configuration.
  602.     error_check
  603.     # Evaluate and set a variable to the correct count length.
  604.     @count = count_length
  605.   end
  606. #-------------------------------------------------------------------------------    
  607.   def count_length
  608.     return ((Graphics.frame_rate.to_f / @speed) * 60).round
  609.   end
  610. #-------------------------------------------------------------------------------
  611.   def change_speed(speed)
  612.     # End method if the speed is frozen and attempting to be modified.
  613.     return if @speed_frozen
  614.     # Reset speed variable and reset the count length.
  615.     @speed = speed
  616.     @count = count_length
  617.     # Check for errors and recalibrate the tint rates based on the new speed.
  618.     error_check
  619.     $game_screen.tone_calibrate
  620.   end
  621. #-------------------------------------------------------------------------------  
  622.   def current_time
  623.     # Returns an array of the current time.
  624.     return [@minute, @hour, @day, @month, @year]
  625.   end
  626. #-------------------------------------------------------------------------------  
  627.   def freeze(value = true)
  628.     # Freeze/Unfreeze the time, tone, and weather all in shot.
  629.     @frozen = $game_screen.tone_frozen = $game_screen.weather_frozen = value
  630.     $game_screen.tone_calibrate
  631.     return true
  632.   end
  633. #-------------------------------------------------------------------------------
  634.   def tone_freeze(value = true)
  635.     # Freeze/Unfreeze the tone by itself.
  636.     $game_screen.tone_frozen = value
  637.     $game_screen.tone_calibrate
  638.     return true
  639.   end
  640. #-------------------------------------------------------------------------------  
  641.   def weather_freeze(value = true)
  642.     # Freezes the weather from automatically changing.
  643.     $game_screen.weather_frozen = value
  644.     $game_screen.tone_calibrate
  645.     return true
  646.   end
  647. #-------------------------------------------------------------------------------  
  648.   def speed_freeze(value = true)
  649.     # Freeze the speed from being modified automatically.
  650.     @speed_frozen = value
  651.     return true
  652.   end
  653. #-------------------------------------------------------------------------------  
  654.   def clock(value = true)
  655.     # Flag to let the system know if the clock should be drawn or not.
  656.     $game_system.clock = value
  657.     return true
  658.   end
  659. #-------------------------------------------------------------------------------
  660.   def show_clock
  661.     # Shows the clock on the screen if clock is allowed to be shown.
  662.     return unless $scene.is_a?(Scene_Map) && $scene.clock == nil
  663.     if $game_system.clock
  664.       $scene.clock = $game_system.analog_clock ? Analog_Clock.new : Clock.new
  665.     end
  666.   end
  667. #-------------------------------------------------------------------------------
  668.   def simple_clock(value = true)
  669.     # Flag to let the system know to know how detailed to make the clock.
  670.     $game_system.simple_clock = value
  671.     if $scene.clock != nil
  672.       $scene.clock.dispose
  673.       $scene.clock = $game_system.analog_clock ? Analog_Clock.new : Clock.new
  674.     end
  675.     return true
  676.   end
  677. #-------------------------------------------------------------------------------
  678.    def analog_clock(value)
  679.      # Sets the analog clock flag true/false.
  680.      $game_system.analog_clock = value
  681.      if $scene.clock != nil
  682.       $scene.clock.dispose
  683.       $scene.clock = $game_system.analog_clock ? Analog_Clock.new : Clock.new
  684.     end
  685.     return true
  686.   end
  687. #-------------------------------------------------------------------------------  
  688.   def clock_face(*args)
  689.     # Changes settings for the clock. Fill in any missing arguments.
  690.     args.each_index {|i| $game_system.clock_face[i] = args[i] }
  691.     # Refresh clock with new settings.
  692.     if $scene.clock != nil
  693.       $scene.clock.dispose
  694.       $scene.clock = $game_system.analog_clock ? Analog_Clock.new : Clock.new
  695.     end
  696.   end
  697. #-------------------------------------------------------------------------------
  698.   def analog_face(*args)
  699.     # Store the new settings.
  700.     args.each_index {|i| $game_system.analog_face[i] = args[i] }
  701.     # Dispose the old analog clock if it exists, and refreshes with changes.
  702.     if $scene.clock != nil
  703.       $scene.clock.dispose
  704.       $scene.clock = $game_system.analog_clock ? Analog_Clock.new : Clock.new
  705.     end
  706.   end
  707. #-------------------------------------------------------------------------------    
  708.   def day_name
  709.     # Returns the current day name.
  710.     day = @day
  711.     (0...@month - 1).each {|i| day += CCTS::MONTH_LENGTH[i]}
  712.     return CCTS::DAYS[day % CCTS::DAYS.size]
  713.   end
  714. #-------------------------------------------------------------------------------  
  715.   def advance_minute(minute)
  716.     # Add MINUTE number of minutes to the time, then corrects.
  717.     return unless minute >= 0
  718.     @minute += minute
  719.     if @minute >= 60
  720.       min = @minute
  721.       @minute = @minute % 60
  722.       advance_hour(min / 60)
  723.     else
  724.       time_fix
  725.     end
  726.   end
  727. #-------------------------------------------------------------------------------  
  728.   def advance_hour(hour)
  729.     # Add HOUR number of hours to the time, then corrects.
  730.     return unless hour >= 0
  731.     @hour += hour
  732.     if @hour >= 24
  733.       h = @hour
  734.       @hour = @hour % 24
  735.       advance_day(h / 24)
  736.     else
  737.       time_fix
  738.     end
  739.   end
  740. #-------------------------------------------------------------------------------  
  741.   def advance_day(day)
  742.     # Add DAY number of days to the time, then corrects.
  743.     return unless day >= 0
  744.     @day += day
  745.     while @day > CCTS::MONTH_LENGTH[@month - 1]
  746.       @day -= CCTS::MONTH_LENGTH[@month - 1]
  747.       @month += 1
  748.       if @month > CCTS::MONTHS.size
  749.         @year += 1
  750.         @month = 1
  751.       end
  752.     end
  753.     time_fix
  754.   end
  755. #-------------------------------------------------------------------------------  
  756.   def advance_month(month)
  757.     # Add MONTH number of months to the time, then corrects.
  758.     return unless month >= 0
  759.     @month += month
  760.     if @month > CCTS::MONTHS.size
  761.       @year += (@month / CCTS::MONTHS.size)
  762.       @month = (@month % CCTS::MONTHS.size)
  763.     end
  764.     time_fix
  765.   end
  766. #-------------------------------------------------------------------------------  
  767.   def advance_year(year)
  768.     # Add YEAR many of years to the time. No need to correct.
  769.     return unless (@year + year) >= 0
  770.     @year += year
  771.   end
  772. #-------------------------------------------------------------------------------
  773.   def set(m = @minute, h = @hour, d = @day, mo = @month, y = @year)
  774.     # Set the current time to the defined values. Current time is default values.
  775.     return unless m.between?(0, 59)
  776.     return unless h.between?(0, 23)
  777.     return unless d.between?(1, CCTS::MONTH_LENGTH[month - 1])
  778.     return unless mo.between?(1, CCTS::MONTHS.size)
  779.     return unless y >= 0
  780.     @minute, @hour, @day, @month, @year = m, h, d, mo, y
  781.     # Refresh the switches and recalibrate the tone based on the new time.
  782.     refresh_switches
  783.     $game_screen.tone_calibrate
  784.   end
  785. #-------------------------------------------------------------------------------
  786.   def memorize(index)
  787.     # Saves the "current_time" array to the specified index.
  788.     @memory[index] = current_time
  789.   end
  790. #-------------------------------------------------------------------------------  
  791.   def restore(index)
  792.     # Sets the time to the memorized time at index, if it exist.
  793.     return if @memory[index] == nil
  794.     time = @memory[index]
  795.     set(time[0], time[1], time[2], time[3], time[4])
  796.   end
  797. #-------------------------------------------------------------------------------
  798.   def change_climate(map_id, climate_id)
  799.     # Changes the current climate of MAP_ID to climate with CLIMATE_ID.
  800.     current = $game_map.climates.map_climate(map_id)
  801.     current.maps.delete(map_id)
  802.     $game_map.climates.climate[climate_id].maps.push(map_id)
  803.   end
  804. #-------------------------------------------------------------------------------      
  805.   def calculate_time
  806.     # Very simple method to pass time.
  807.     @hour += 1
  808.     @minute = 0
  809.     if @hour >= 24
  810.       @day += 1
  811.       @hour = 0
  812.       if @day > CCTS::MONTH_LENGTH[@month - 1]
  813.         @month += 1
  814.         @day = 1
  815.         if @month > CCTS::MONTHS.size
  816.           @year += 1
  817.           @month = 1
  818.         end
  819.       end
  820.     end
  821.   end
  822. #-------------------------------------------------------------------------------
  823.   def time_fix
  824.     # Corrects the time for when an out of range value is given for a particular
  825.     # setting, such as "advance_minute(400)"
  826.     $scene.clock.refresh if $scene.clock != nil
  827.     refresh_switches
  828.     error_check
  829.   end
  830. #-------------------------------------------------------------------------------  
  831.   def refresh_switches
  832.     # Set Day/Night switches if time is in configured ranges.
  833.     if @hour.between?(CCTS::DAY_START_HOUR, CCTS::NIGHT_START_HOUR - 1)
  834.       $game_switches[CCTS::DAY_SWITCH] = true
  835.       $game_switches[CCTS::NIGHT_SWITCH] = false
  836.     else
  837.       $game_switches[CCTS::DAY_SWITCH] = false
  838.       $game_switches[CCTS::NIGHT_SWITCH] = true
  839.     end
  840.     # Set Season Variable
  841.     CCTS::SEASON_MONTHS.each_index {|i|
  842.       if CCTS::SEASON_MONTHS[i].include?(@month)
  843.         $game_variables[CCTS::SEASON_VARIABLE] = i
  844.       end
  845.     }
  846.     # Set variables to the current time if configured to do so.
  847.     time = current_time
  848.     ids = [CCTS::MINUTE_VARIABLE, CCTS::HOUR_VARIABLE, CCTS::DAY_VARIABLE,
  849.      CCTS::MONTH_VARIABLE, CCTS::YEAR_VARIABLE]
  850.     ids.each_index {|i| $game_variables[ids[i]] = time[i] if ids[i] != nil }
  851.     # Have $game_map refresh to have events, etc. respond to changed switches.
  852.     $game_map.need_refresh = true
  853.   end
  854. #-------------------------------------------------------------------------------  
  855.   def error_check
  856.     # Checks that required settings are within permissable range. All of these
  857.     # would mess up the system later, or throw an error themselves. This will
  858.     # just give a better explanation, and catch it earlier.
  859.     raise('Time speed must be greater than 0!') unless @speed > 0
  860.     raise('No Days defined!') if CCTS::DAYS.empty?
  861.     raise('No Months defined!') if CCTS::MONTHS.empty?
  862.     if CCTS::WEATHER_WAIT[0] >= CCTS::WEATHER_WAIT[1]
  863.       raise('Minimum WEATHER_WAIT must be less than Maximum WEATHER_WAIT!')
  864.     end
  865.     if CCTS::MONTH_LENGTH.size != CCTS::MONTHS.size
  866.       raise('\'MONTH_LENGTH\' and \'MONTHS\' arrays must be equal size.')
  867.     end
  868.     if @minute > 60 || @hour > 24 ||
  869.         @day > CCTS::MONTH_LENGTH[@month - 1] || @month > CCTS::MONTHS.size ||
  870.         [@minute, @hour, @day, @month, @year].any? {|time| time < 0}
  871.       raise('Time System Error! Time value(s) not within permitted range.')
  872.     end
  873.   end
  874. #-------------------------------------------------------------------------------
  875.   def update
  876.     # Update the frame count as long as the frozen flag is false.
  877.     unless @frozen
  878.       @frame_count += 1
  879.       if @frame_count >= @count
  880.         @minute += 1
  881.         calculate_time if @minute == 60
  882.         refresh_switches
  883.         @frame_count = 0
  884.       end
  885.     end
  886.   end
  887. end
  888.  
  889. #===============================================================================
  890. # ** Game_Climate
  891. #===============================================================================
  892.  
  893.   # Assign a Struct to a constant to organize data of each climate.
  894. Game_Climate = Struct.new(:id, :name, :weather, :tinting, :sound, :speed, :maps)
  895.  
  896.  
  897. #===============================================================================
  898. # ** Game_Map
  899. #===============================================================================
  900.  
  901. class Game_Map
  902.  
  903.   attr_reader   :climate, :old_climate, :map
  904.   attr_accessor :climates
  905.  
  906.   alias zer0_last_map_init initialize
  907.   def initialize
  908.     zer0_last_map_init
  909.     # Initialize the climate variable for game map.
  910.     @climates = Climate.new
  911.     # Set the "last_map", which will be the starting map by default.
  912.     @last_map = $data_system.start_map_id
  913.   end
  914. #-------------------------------------------------------------------------------  
  915.   alias zer0_map_climate_setup setup
  916.   def setup(map_id)
  917.     # Have the setup method also setup the climate for the current map.
  918.     @climate = @climates.map_climate(map_id)
  919.     # Reset the old climate variable
  920.     @old_climate = @climates.map_climate(@last_map)
  921.     # Call the weather control method of Game_Screen to set weather/tone.
  922.     $game_screen.weather_control    
  923.     unless $game_system.time.speed_frozen
  924.       $game_system.time.change_speed(@climate.speed)
  925.     else
  926.       $game_screen.tone_calibrate
  927.     end
  928.     # Call original setup method.
  929.     zer0_map_climate_setup(map_id)
  930.     # Set the @last_map id to the current map ID. Used for the next map.
  931.     @last_map = @map_id
  932.   end
  933. #-------------------------------------------------------------------------------
  934.   alias zer0_weather_bgs_autoplay autoplay
  935.   def autoplay
  936.     # Disable normal BGS if weather sound is occuring.
  937.     $game_system.bgm_play(@map.bgm) if @map.autoplay_bgm
  938.     return if $game_screen.weather_bgs_playing?
  939.     zer0_weather_bgs_autoplay
  940.   end
  941. end
  942.  
  943. #===============================================================================
  944. # ** Game_System
  945. #===============================================================================
  946.  
  947. class Game_System
  948.  
  949.   attr_accessor :time, :clock, :clock_face, :simple_clock
  950.   attr_accessor :analog_clock, :analog_face, :clock_memory
  951.  
  952.   alias zer0_time_system_init initialize
  953.   def initialize
  954.     zer0_time_system_init
  955.     # Initialize the Time_System class.
  956.     @time = Time_System.new
  957.     # Initialize a few other instance variables used by the system.
  958.     @clock, @simple_clock, @bgs_volume_update = true, false, 0
  959.     @clock_memory, @analog_clock = true, CCTS::ANALOG_CLOCK
  960.     # Set starting values for the clock faces.
  961.     @clock_face, @analog_face = CCTS::CLOCK_FACE, CCTS::ANALOG_FACE
  962.   end
  963. #-------------------------------------------------------------------------------
  964.   def change_bgs_volume(volume)
  965.     # Changes the BGS volume to VOLUME. Does not change the BGS name.
  966.     return if @playing_bgs == nil
  967.     bgs = @playing_bgs
  968.     Audio.bgs_play('Audio/BGS/' + bgs.name, volume, bgs.pitch)
  969.   end
  970. #-------------------------------------------------------------------------------
  971.   def bgs_transition(start_vol, target_vol, frames)
  972.     # Transitions BGS volume from START_VOL to TARGET_VOL over the course of
  973.     # FRAMES number of frames.
  974.     range = target_vol - start_vol
  975.     @bgs_volume = start_vol
  976.     @bgs_volume_rate = range / frames.to_f
  977.     @bgs_volume_update = frames
  978.   end
  979. #-------------------------------------------------------------------------------
  980.   alias zer0_time_system_upd update
  981.   def update
  982.     # Updates the time if current scene is Scene_Map or Scene_Battle
  983.     if $scene.is_a?(Scene_Map) || $scene.is_a?(Scene_Battle)
  984.       @time.update
  985.     end
  986.     # Update BGS volume transitions if needed.
  987.     if @bgs_volume_update != 0
  988.       @bgs_volume += @bgs_volume_rate
  989.       change_bgs_volume(@bgs_volume.round)
  990.       @bgs_volume_update -= 1
  991.     end
  992.     # Call normal update method of Game_System.
  993.     zer0_time_system_upd
  994.   end
  995. end
  996.  
  997. #===============================================================================
  998. # ** Game_Screen
  999. #===============================================================================
  1000.  
  1001. class Game_Screen
  1002.  
  1003.   attr_accessor :tone_frozen, :weather_frozen
  1004.  
  1005. #-------------------------------------------------------------------------------
  1006.   alias zer0_screen_control_init initialize
  1007.   def initialize
  1008.     zer0_screen_control_init
  1009.     # Initialize required instance variables.
  1010.     @minute = $game_system.time.minute
  1011.     # Calculate the weather delay based off the current config and climate.
  1012.     @weather_wait = weather_delay
  1013.     @weather_count = 0
  1014.     # Initialize arrays to retain rates of tinting for time and weather.
  1015.     @tint_rate = [0, 0, 0, 0]
  1016.     @weather_tint_rate = [0, 0, 0, 0]
  1017.     # Initialize the "frozen" flags.
  1018.     @tone_frozen = @weather_frozen = false
  1019.   end
  1020. #-------------------------------------------------------------------------------
  1021.   alias zer0_weather_effects weather
  1022.   def weather(type, power, duration, variation = 0)
  1023.     # Alias weather method to call other methods for setting the tint rates,
  1024.     # sound, etc. when the weather is changed.
  1025.     if type != @weather_type
  1026.       # Refresh the tint, and call BGS to transition smoothly if changing.
  1027.       @last_weather = @weather_type_target
  1028.       weather_tint_refresh(@weather_type, type, duration)
  1029.       weather_bgs_control(type, duration, $game_map.climate.weather)
  1030.     end
  1031.     # Reset BGS if climate has changed.
  1032.     if $game_map.climate.id != $game_map.old_climate.id &&
  1033.       $game_map.climate.sound
  1034.       weather_bgs_control(type, duration, $game_map.climate.weather)
  1035.     end
  1036.     # Refresh the switches used for Good/Bad Weather, Type variables, etc.
  1037.     refresh_weather_switches(type)
  1038.     # Set tone change flag if needed.
  1039.     @weather_tone_change = (type != @weather_type)
  1040.     # Call normal method, use fourth argument if Zer0 Adv. Weather or MAWS.
  1041.     if @weather_variation != nil
  1042.       zer0_weather_effects(type, power, duration, variation)
  1043.     else
  1044.       zer0_weather_effects(type, power, duration)
  1045.     end
  1046.   end
  1047. #-------------------------------------------------------------------------------
  1048.   def tint_rate_refresh
  1049.     # Evaluates the tint rate for the time. Uses configuration to find rate for
  1050.     # the next hour. Uses this value, the current, and the time speed to
  1051.     # determine the rate at which it needs to change per frame.
  1052.     @minute = $game_system.time.minute
  1053.     rate = [0, 0, 0, 0]
  1054.     hour = $game_system.time.hour
  1055.     month = $game_system.time.month
  1056.     current = CCTS.time_tint($game_map.climate.id, hour, month)
  1057.     target = CCTS.time_tint($game_map.climate.id, (hour + 1) % 24, month)
  1058.     rate.each_index {|i|
  1059.       rate[i] = current[i].abs - target[i].abs
  1060.       rate[i] /= (60.0 * $game_system.time.count_length)}
  1061.     @tint_rate = rate
  1062.   end
  1063. #-------------------------------------------------------------------------------
  1064.   def weather_tint_refresh(old_type, new_type, duration)
  1065.     # Sets the tint rate, based off the current tone that is, the target tone,
  1066.     # and the number of frames that it has to do so. This rate change is
  1067.     # independent of the normal tint rate for time.
  1068.     old = CCTS.weather_tint(old_type)
  1069.     new = CCTS.weather_tint(new_type)
  1070.     unless $game_map.climate.tinting
  1071.       # End method if the tone cannot from be modified due to freeze status.
  1072.       unless @tone_frozen
  1073.         @tone.red -= old[0]
  1074.         @tone.green -= old[1]
  1075.         @tone.blue -= old[2]
  1076.         @tone.gray -= old[3]
  1077.       end
  1078.       return
  1079.     end
  1080.     # End method if the tones are equal and no change needs done.
  1081.     return if old == new
  1082.     # Instantly set tone if the duration is 0 and end method.
  1083.     if duration == 0 && !@tone_frozen
  1084.       @tone.red = (@tone.red - old[0] + new[0])
  1085.       @tone.green = (@tone.green - old[1] + new[1])
  1086.       @tone.blue = (@tone.blue - old[2] + new[2])
  1087.       @tone.gray = (@tone.gray - old[3] + new[3])
  1088.       return
  1089.     end
  1090.     # Initialize new rate array.
  1091.     rate = [0, 0, 0, 0]
  1092.     rate.each_index {|i|
  1093.       # Evaluates difference in tones and divides by number of frames to change.
  1094.       rate[i] = old[i].abs - new[i].abs
  1095.       rate[i] /= (duration - 1).to_f}
  1096.     @weather_tint_rate = rate
  1097.   end
  1098. #-------------------------------------------------------------------------------
  1099.   def screen_tint_update
  1100.     # Use a clone of the tint rate to avoid actual modification of the rate.
  1101.     rate = @tint_rate.clone
  1102.     # Adds the weather tint to the screen tint for the duration of the weather.
  1103.     if @weather_duration != 0 && @weather_tone_change
  1104.       rate.each_index {|i| rate[i] += @weather_tint_rate[i] }
  1105.     end
  1106.     # Addes total value to each respective value of the current tone.
  1107.     @tone.red += rate[0]
  1108.     @tone.green += rate[1]
  1109.     @tone.blue += rate[2]
  1110.     @tone.gray -= rate[3]
  1111.   end
  1112. #-------------------------------------------------------------------------------
  1113.   def tone_calibrate
  1114.     # Recalibrates the the system and all its rates, timing, etc. since it can
  1115.     # sometimes get slightly off due to frame skips, bad decimal correction, etc.
  1116.     min = $game_system.time.minute
  1117.     hour = $game_system.time.hour
  1118.     month = $game_system.time.month
  1119.     weather = CCTS.weather_tint(@weather_type_target)
  1120.     current = CCTS.time_tint($game_map.climate.id, hour, month)
  1121.     target = CCTS.time_tint($game_map.climate.id, (hour + 1) % 24, month)
  1122.     # Instantly sets weather to its target and sets weather duration to 0.
  1123.     tone, @weather_duration, @weather_max = [], 0, @weather_max_target
  1124.     # Recalculate each tone to more precise values.
  1125.     current.each_index {|i|
  1126.       tone[i] = current[i].abs - target[i].abs
  1127.       tone[i] /= 60.0
  1128.       tone[i] *= min
  1129.       tone[i] += current[i]
  1130.       tone[i] += weather[i]}
  1131.     # Sets tone to recalibrated settings unless the tone is frozen.
  1132.     unless @tone_frozen
  1133.       @tone.red, @tone.green = tone[0], tone[1]
  1134.       @tone.blue, @tone.gray = tone[2], tone[3]
  1135.     end
  1136.     # Refresh rates based off corrected data.
  1137.     tint_rate_refresh
  1138.   end
  1139. #-------------------------------------------------------------------------------
  1140.   def refresh_weather_switches(type)
  1141.     # Sets the switches to required values. Has Game_Map refresh afterwards.
  1142.     $game_variables[CCTS::WEATHER_VARIABLE] = type
  1143.     value = CCTS::BAD_WEATHER_TYPES.include?(type)
  1144.     $game_switches[CCTS::BAD_WEATHER_SWITCH] = value
  1145.     $game_switches[CCTS::GOOD_WEATHER_SWITCH] = !value
  1146.     $game_map.need_refresh = true
  1147.   end
  1148. #-------------------------------------------------------------------------------  
  1149.   def weather_delay
  1150.     # Gets a random number from within the MIN/MAX range of the weather wait.
  1151.     min = CCTS::WEATHER_WAIT[0]
  1152.     max = CCTS::WEATHER_WAIT[1]
  1153.     delay = (min + rand(max - min + 1)) * 40
  1154.     return delay
  1155.   end
  1156. #-------------------------------------------------------------------------------  
  1157.   def weather_control
  1158.     # This is the heart of how weather is controlled. Most calculations of how
  1159.     # the weather is handled are either done here, or called from here.
  1160.     if @weather_count < @weather_wait
  1161.       # Ensures the weather remains consistant through different maps with the
  1162.       # same climate. Also remembers the weather of the last climate.
  1163.       return if $game_map.climate.id == $game_map.old_climate.id
  1164.       if $game_map.climate.weather && @last_weather != nil
  1165.         weather(@last_weather, rand(50) + 1, 0)
  1166.         return
  1167.       end
  1168.     end
  1169.     # Turn the weather off instantly if no weather is allowed for climate.
  1170.     unless $game_map.climate.weather
  1171.       weather(0, 0, 0)
  1172.       @weather_count = 0
  1173.       return
  1174.     end
  1175.     # Reset the weather wait and recalculate a new delay until the next update.
  1176.     @weather_count = 0
  1177.     @weather_wait = weather_delay
  1178.     transition = rand(120) + 160
  1179.     power = rand(50) + 1
  1180.     # Get a random number 1..100 to use for the chance of the weather.
  1181.     chance = rand(100) + 1
  1182.     # Gets the current climate and month to determine weather for the season.
  1183.     climate, month = $game_map.climate.id, $game_system.time.month
  1184.     climate_weather = CCTS.weather_prob(climate, month)
  1185.     # If the climate has no weather defined, turn it off and end method.
  1186.     if climate_weather == nil
  1187.       weather(0, 0, 0)
  1188.       return
  1189.     end
  1190.     type = variation = 0
  1191.     # Trim array down to only types that whose probability is higher than chance
  1192.     climate_weather.reject! {|array| array[1] < chance }
  1193.     unless climate_weather.empty?
  1194.       # Get a random type from all weather types that were greater than chance.
  1195.       r = rand(climate_weather.size)
  1196.       type = climate_weather[r][0]
  1197.       # Get variation if defined.
  1198.       if climate_weather[r][2] != nil
  1199.         variation = climate_weather[r][2]
  1200.       end
  1201.     end
  1202.     # Call weather, using variation if defined.
  1203.     if @weather_variation != nil
  1204.       return if (type == @weather_type) && (variation == @weather_variation)
  1205.       weather(type, power, transition, variation)
  1206.     else
  1207.       return if type == @weather_type
  1208.       weather(type, power, transition)
  1209.     end
  1210.   end
  1211. #-------------------------------------------------------------------------------  
  1212.   def weather_bgs_playing?
  1213.     # Returns true if a BGS is playing for the weather.
  1214.     return false unless $game_map.climate.sound
  1215.     if $game_map.climate.weather
  1216.       return false if CCTS.weather_BGS(@weather_type_target) == nil
  1217.     end
  1218.     if $game_map.climate.sound && !$game_map.climate.weather &&
  1219.       CCTS.weather_BGS(@last_weather) == nil
  1220.       return false
  1221.     end
  1222.     return true
  1223.   end
  1224. #-------------------------------------------------------------------------------  
  1225.   def weather_bgs_control(type, duration, weather)
  1226.     # Turn weather BGS off if climate does not permit it, then end method.
  1227.     unless $game_map.climate.sound
  1228.       if weather_bgs_playing?
  1229.         $game_system.bgs_fade(0)
  1230.         $game_system.bgs_play($game_map.map.bgs) if $game_map.map.autoplay_bgs
  1231.         return
  1232.       end
  1233.     end
  1234.     # Use climate uses weather, set BGS to current weather sound.
  1235.     if weather
  1236.       bgs = CCTS.weather_BGS(type)
  1237.       if bgs != nil
  1238.         if duration > 0
  1239.           $game_system.bgs_play(RPG::AudioFile.new(bgs[0], 0, bgs[2]))
  1240.           $game_system.bgs_transition(0, bgs[1], duration)
  1241.         else
  1242.           $game_system.bgs_play(RPG::AudioFile.new(bgs[0], bgs[1], bgs[2]))
  1243.         end
  1244.       else
  1245.         $game_system.bgs_fade(duration / 25)
  1246.       end
  1247.     # If weather sound, but no weather is defined. Use the BGS from the last map
  1248.     # that used weather. Gives effect that weather is still occuring outside.
  1249.     else
  1250.       bgs = CCTS.weather_BGS(@last_weather)
  1251.       if bgs != nil
  1252.         audio = RPG::AudioFile.new(bgs[0], bgs[1], bgs[2])
  1253.         $game_system.bgs_play(audio)
  1254.         $game_system.change_bgs_volume(bgs[1] / 2)
  1255.       else
  1256.         $game_system.bgs_fade(duration / 25)
  1257.       end
  1258.     end
  1259.   end
  1260. #-------------------------------------------------------------------------------
  1261.   alias zer0_screen_tint_upd update
  1262.   def update
  1263.     # Refresh tint every game minute.
  1264.     tint_rate_refresh if @minute != $game_system.time.minute
  1265.     # Update the current tone, unless it is frozen.
  1266.     screen_tint_update unless @tone_frozen
  1267.     unless @weather_frozen
  1268.       # Add 1 to the current weather count.
  1269.       @weather_count += 1
  1270.       if @weather_count >= @weather_wait
  1271.         # If count duration is reached, call method to re-evaluate the weather.
  1272.         weather_control
  1273.       end
  1274.     end
  1275.     # Call normal update method.
  1276.     zer0_screen_tint_upd  
  1277.   end
  1278. #-------------------------------------------------------------------------------
  1279. end
  1280.  
  1281. #===============================================================================
  1282. # ** Scene_Map
  1283. #===============================================================================
  1284.  
  1285. class Scene_Map
  1286.  
  1287.   attr_accessor :clock  
  1288.  
  1289.   alias zer0_clock_main main
  1290.   def main
  1291.     # Create clock if memory is true.
  1292.     if $game_system.clock_memory
  1293.       @clock = $game_system.analog_clock ? Analog_Clock.new : Clock.new
  1294.     end
  1295.     # Main loop.
  1296.     zer0_clock_main
  1297.     # Dispose clock if it still exists when scene changes.
  1298.     if @clock != nil
  1299.       @clock.dispose
  1300.     end
  1301.   end
  1302.  
  1303.   alias zer0_clock_upd update
  1304.   def update
  1305.     zer0_clock_upd
  1306.     if Input.trigger?(CCTS::CLOCK_BUTTON)
  1307.       # Play SE when button for clock is triggered.
  1308.       if $game_system.clock
  1309.         $game_system.se_play($data_system.decision_se)
  1310.         if @clock == nil
  1311.           @clock = $game_system.analog_clock ? Analog_Clock.new : Clock.new
  1312.         else
  1313.           @clock = @clock.dispose
  1314.         end
  1315.         $game_system.clock_memory = @clock != nil
  1316.       else
  1317.         $game_system.se_play($data_system.buzzer_se)
  1318.       end
  1319.     end
  1320.     # Update clock if it exists.
  1321.     if @clock != nil
  1322.       @clock.update
  1323.     end
  1324.     # Dispose click if turned off by player, or explicitly by script call.
  1325.     if !$game_system.clock && @clock != nil
  1326.       @clock = @clock.dispose
  1327.     end
  1328.   end
  1329. end
  1330.  
  1331. #===============================================================================
  1332. # ** Clock
  1333. #===============================================================================
  1334.  
  1335. class Clock < Window_Base
  1336.  
  1337.   def initialize
  1338.     # Determine dimensions by what type of clock will be created.
  1339.     dim = $game_system.simple_clock ? [100, 47] : [176, 80]
  1340.     super($game_system.clock_face[0], $game_system.clock_face[1], dim[0], dim[1])
  1341.     self.contents = Bitmap.new(width - 32, height - 32)
  1342.     self.back_opacity, self.z = $game_system.clock_face[2], 9998
  1343.     self.contents.font.name = $game_system.clock_face[3]
  1344.     self.contents.font.size = $game_system.clock_face[4]
  1345.     # Determine the skin used for the clock.
  1346.     if CCTS::CLOCK_SKIN == nil
  1347.       self.windowskin = nil
  1348.     elsif CCTS::CLOCK_SKIN == 'DEFAULT SKIN'
  1349.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin_name)
  1350.     else
  1351.       self.windowskin = RPG::Cache.windowskin(CCTS::CLOCK_SKIN)
  1352.     end
  1353.     # Draw the clock.
  1354.     refresh
  1355.   end
  1356.  
  1357.   def refresh
  1358.     # Set a few local variables to current time variables.
  1359.     day, year = $game_system.time.day.to_s, $game_system.time.year.to_s
  1360.     month = CCTS::MONTHS[$game_system.time.month-1]
  1361.     time = sprintf(CCTS::TIME_FORMAT, $game_system.time.hour, $game_system.time.minute)
  1362.     # Clear the current bitmap.
  1363.     self.contents.clear
  1364.     # Set local variables equal to different text widths.
  1365.     tmw = 8 + contents.text_size('Time:').width
  1366.     dyw = 8 + contents.text_size('Day:').width
  1367.     dtw = 8 + contents.text_size('Date:').width
  1368.     self.contents.font.color = system_color
  1369.     # Begin to draw the clock. Only include more details if not Simple Clock.
  1370.     self.contents.draw_text(0, 0, 144, 15, 'Time:')
  1371.     unless $game_system.simple_clock
  1372.       self.contents.draw_text(0, 15, 144, 15, 'Day:')
  1373.       self.contents.draw_text(0, 30, 144, 15, 'Date:')
  1374.       self.contents.font.color = normal_color
  1375.       self.contents.draw_text(dyw, 15, 144, 15, $game_system.time.day_name)
  1376.       self.contents.draw_text(dtw, 30, 144, 15, "#{month} #{day}, #{year}")
  1377.     end
  1378.     self.contents.font.color = normal_color
  1379.     self.contents.draw_text(tmw, 0, 144, 15, time)
  1380.     # Set instance variable. Used to check when to next refresh.
  1381.     @mins = $game_system.time.minute
  1382.   end
  1383.  
  1384.   def update
  1385.     super
  1386.     # Redraw the clock every game minute.
  1387.     refresh if @mins != $game_system.time.minute
  1388.   end
  1389. end
  1390.  
  1391. #===============================================================================
  1392. # ** Analog_Clock
  1393. #===============================================================================
  1394.  
  1395. class Analog_Clock
  1396.  
  1397.   def initialize
  1398.     # Initialize the sprites.
  1399.     @clock_back, @minutehand, @hourhand = Sprite.new, Sprite.new, Sprite.new
  1400.     [@hourhand, @minutehand, @clock_back].each {|sprite| sprite.z = 9998 }
  1401.     # Set instance variable that will be used to determine when to refresh.
  1402.     @min = $game_system.time.minute
  1403.     # Set graphic and coordinates to each sprite.
  1404.     set_graphic
  1405.   end
  1406.  
  1407.   def set_graphic(*args)
  1408.     # Fill in any missing arguments.
  1409.     (0..4).each {|i| args[i] = $game_system.analog_face[i] if args[i] == nil }
  1410.     filename, handoffset, x, y, alpha = args[0], args[1], args[2], args[3], args[4]
  1411.     # Set the bitmaps to the sprites.
  1412.     @minutehand.bitmap = RPG::Cache.picture(filename + '_min')
  1413.     @hourhand.bitmap = RPG::Cache.picture(filename + '_hour')
  1414.     @clock_back.bitmap = RPG::Cache.picture(filename + '_back')
  1415.     # Set the coordinates of the clock hands.
  1416.     @clock_back.x, @clock_back.y = x, y
  1417.     @hourhand.x = @minutehand.x = (@clock_back.bitmap.width / 2) + x
  1418.     @hourhand.y = @minutehand.y = (@clock_back.bitmap.height / 2) + y
  1419.     # Set the origin points of the clock hands.
  1420.     @hourhand.ox = @hourhand.bitmap.width / 2
  1421.     @minutehand.ox = @minutehand.bitmap.width / 2
  1422.     @hourhand.oy = @minutehand.oy = handoffset
  1423.     # Set opacity of each sprite.
  1424.     [@hourhand, @minutehand, @clock_back].each {|sprite| sprite.opacity = alpha }
  1425.     # Call update now to avoid a frame flicker before normal update starts.
  1426.     update
  1427.   end
  1428.  
  1429.   def update
  1430.     # Only run any calculations if minute has changed.
  1431.     if @mins != $game_system.time.minute
  1432.       # Calculate angle for minute hand
  1433.       m_angle = (360 * ($game_system.time.minute / 60.0)).to_i - 180
  1434.       if m_angle != @minutehand.angle
  1435.         @minutehand.angle = -m_angle
  1436.         # Calculate hour hand angle, only if minute hand angle has changed.
  1437.         h_angle = ($game_system.time.hour % 12) * 30
  1438.         h_angle += (($game_system.time.minute / 60.0) * 30).to_i - 180
  1439.         if h_angle.to_i != @hourhand.angle
  1440.           # Set new hour hand angle if it has changed.
  1441.           @hourhand.angle = -h_angle.to_i
  1442.         end
  1443.       end
  1444.       @mins = $game_system.time.minute
  1445.     end
  1446.   end
  1447.  
  1448.   def dispose
  1449.     # Disposes the sprites.
  1450.     [@hourhand, @minutehand, @clock_back].each {|sprite| sprite.dispose }
  1451.     return
  1452.   end
  1453. end
  1454.  
  1455. #===============================================================================
  1456. # ** Window_Message
  1457. #===============================================================================
  1458.  
  1459. class Window_Message < Window_Selectable
  1460.  
  1461.   alias zer0_ccts_message_commands_refresh refresh
  1462.   def refresh
  1463.     if $game_temp.message_text != nil
  1464.       text = $game_temp.message_text
  1465.       begin
  1466.         # Use Regexp to find patterns in the message strings. If found, will
  1467.         # replace them with the proper value.
  1468.         last_text = text.clone
  1469.         hour, minute = $game_system.time.hour, $game_system.time.minute
  1470.         time = sprintf(CCTS::TIME_FORMAT, hour, minute)
  1471.         text.gsub!(/\\[Tt][Ii][Mm][Ee]/) { time }
  1472.         text.gsub!(/\\[Dd][Aa][Yy]/) { $game_system.time.day_name }
  1473.         text.gsub!(/\\[Mm][Oo][Nn]/) { CCTS::MONTHS[$game_system.time.month-1] }
  1474.         text.gsub!(/\\[Yy][Rr]/) { $game_system.time.year.to_s }
  1475.         text.gsub!(/\\[Mm][Oo][Ss]\[([0-9]+)\]/) {
  1476.           CCTS::MONTHS[$1.to_i - 1] != nil ? CCTS::MONTHS[$1.to_i - 1] : ''}
  1477.         text.gsub!(/\\[Dd][Yy]\[([0-9]+)\]/) {
  1478.           CCTS::DAYS[$1.to_i] != nil ? CCTS::DAYS[$1.to_i] : ''}
  1479.       end until text == last_text
  1480.     end
  1481.     # Call normal refresh method for Window_Message.
  1482.     zer0_ccts_message_commands_refresh
  1483.   end
  1484. end
  1485.  
  1486. #===============================================================================
  1487. # ** Interpreter
  1488. #===============================================================================
  1489.  
  1490. class Interpreter
  1491.  
  1492.   def time
  1493.     # Shorten "$game_system.time" to simply "time" for script calls.
  1494.     return $game_system.time
  1495.   end
  1496. end
  1497.  
  1498. #===============================================================================
  1499. # ** CCTS Debug
  1500. #-------------------------------------------------------------------------------
  1501. # Everything below is used solely for the Debug aspect of the system, and not
  1502. # required for the actual script at all. It is safe to erase if it not used.
  1503. #===============================================================================
  1504.  
  1505. #===============================================================================
  1506. # ** CCTS_Debug_Sprite
  1507. #===============================================================================
  1508.  
  1509. class CCTS_Debug < Sprite
  1510.  
  1511.   # Define the colors used to draw the text in, and background color.
  1512.   SYSTEM_COLOR = Color.new(192, 224, 255)
  1513.   NORMAL_COLOR = Color.new(255, 255, 255)
  1514.   CLEAR = Color.new(0, 0, 0, 96)
  1515.  
  1516.   # Defines what types of info will be drawn
  1517.   TIME         = true
  1518.   WEATHER      = true
  1519.   TONE         = true   # <-- This one tends to make the game lag.
  1520.   TINT_RATE    = true
  1521.   WEATHER_TINT = true
  1522.  
  1523.   def initialize
  1524.     viewport = Viewport.new(0, 0, 640, 480)
  1525.     viewport.z = 10000
  1526.     super(viewport)
  1527.     # Initialize the words used for each value.
  1528.     self.bitmap = Bitmap.new(640, 480)
  1529.     self.bitmap.font.name = 'Arial'
  1530.     self.bitmap.font.size = 14
  1531.     self.bitmap.font.bold = true
  1532.     @refresh = [TIME, WEATHER, TONE, TINT_RATE, WEATHER_TINT]
  1533.     @data = []
  1534.     @data[0] = time_info           if @refresh[0]
  1535.     @data[1] = weather_info        if @refresh[1]
  1536.     @data[2] = screen_tone_info    if @refresh[2]
  1537.     @data[3] = tint_info           if @refresh[3]
  1538.     @data[4] = weather_tint_info   if @refresh[4]
  1539.     # Draw all the items.
  1540.     @data.each_index {|i|
  1541.       if @data[i] != nil
  1542.         draw_items(Array.new(@data[i][0].size) {|j| j }, i)
  1543.       end
  1544.     }
  1545.     # Self updating thread.
  1546.     @thread = Thread.new { loop { $ccts_debug.update if $ccts_debug != nil } }
  1547.   end
  1548.  
  1549.   def dispose
  1550.     # Terminate the update thread when the sprite is disposed.
  1551.     @thread.kill
  1552.     @thread = nil
  1553.     super
  1554.   end
  1555.  
  1556.   def get_info(index)
  1557.     return case index
  1558.     when 0 then time_info
  1559.     when 1 then weather_info
  1560.     when 2 then screen_tone_info
  1561.     when 3 then tint_info
  1562.     when 4 then weather_tint_info
  1563.     end
  1564.   end
  1565.  
  1566.   def update
  1567.     # Check for change in values. Re-draws the lines that have changed.
  1568.     @refresh.each_index {|i|  
  1569.       if @refresh[i]
  1570.         info = get_info(i)
  1571.        if @data[i][1] != info[1]
  1572.           draw_items(get_indexes(@data[i][1], info[1]), i)
  1573.           @data[i] = info
  1574.         end
  1575.       end
  1576.     }
  1577.     # Dispose debugger and terminate thread if not Scene_Map
  1578.     unless $scene.is_a?(Scene_Map)
  1579.       $ccts_debug.dispose
  1580.     end
  1581.   end
  1582.  
  1583.   def draw_items(indexes, group)
  1584.     array = case group
  1585.     when 0 then [16, 304, 128]
  1586.     when 1 then [160, 424, 128]
  1587.     else
  1588.       [304+((group-2)*112), 412, 96]
  1589.     end
  1590.     indexes.each {|index|
  1591.       # Create a rect at the specific line.
  1592.       rect = Rect.new(array[0], (index*12)+array[1], array[2], 12)
  1593.       # Draw line number INDEX.
  1594.       self.bitmap.fill_rect(rect, CLEAR)
  1595.       self.bitmap.font.color = SYSTEM_COLOR
  1596.       self.bitmap.draw_text(rect, @data[group][0][index])
  1597.       self.bitmap.font.color = NORMAL_COLOR
  1598.       self.bitmap.draw_text(rect, @data[group][1][index], 2)
  1599.     }
  1600.   end
  1601.  
  1602.   def get_indexes(array1, array2)
  1603.     indexes = []
  1604.     array1.each_index {|i| indexes.push(i) if array1[i] != array2[i] }
  1605.     return indexes
  1606.   end
  1607.  
  1608.   def time_info
  1609.     # Return strings releated to the time.
  1610.     return [
  1611.     ['** TIME INFO', '  Time Frozen:', '  Tone Frozen:', '  Speed Frozen:',
  1612.      '  Weather Frozen:', '  Time Speed:', '  Count:', '  Minute:', '  Hour:',
  1613.      '  Day:', '  Month:', '  Year:', '  Day Name:', '  Month Name:'],
  1614.     ['', $game_system.time.frozen.to_s,
  1615.     $game_screen.tone_frozen.to_s, $game_system.time.speed_frozen.to_s,
  1616.     $game_screen.weather_frozen.to_s, $game_system.time.speed.to_s,
  1617.     $game_system.time.frame_count.to_s + '\\' + $game_system.time.count.to_s,
  1618.     $game_system.time.minute.to_s, $game_system.time.hour.to_s,
  1619.     $game_system.time.day.to_s, $game_system.time.month.to_s,
  1620.     $game_system.time.year.to_s, $game_system.time.day_name.to_s,
  1621.     CCTS::MONTHS[$game_system.time.month-1]]]
  1622.   end
  1623.  
  1624.   def weather_info
  1625.     # Return strings related to the weather.
  1626.     return [
  1627.     ['** WEATHER INFO', '  Duration:', '  Weather Type:', '  Count:'],
  1628.     ['', $game_screen.weather_duration.to_s, $game_screen.weather_type_target.to_s,
  1629.     $game_screen.weather_count.to_s + '\\' + $game_screen.weather_wait.to_s]]
  1630.   end
  1631.  
  1632.   def screen_tone_info
  1633.     # Return strings related to the screen tone.
  1634.     return [
  1635.     ['** SCREEN_TONE:', '  Red:', '  Green:', '  Blue:', '  Gray:'],
  1636.     ['', sprintf("%20.6s", $game_screen.tone.red),
  1637.     sprintf("%20.6s", $game_screen.tone.green),
  1638.     sprintf("%20.6s", $game_screen.tone.blue),
  1639.     sprintf("%20.6s", $game_screen.tone.gray)]]
  1640.   end
  1641.  
  1642.   def tint_info
  1643.     # Return strings related to the tint rate.
  1644.     return [
  1645.     ['** TINT RATE', '  Red:', '  Green:', '  Blue:', '  Gray:'],
  1646.     ['', sprintf("%20.6s", $game_screen.tint_rate[0]),
  1647.     sprintf("%20.6s", $game_screen.tint_rate[1]),
  1648.     sprintf("%20.6s", $game_screen.tint_rate[2]),
  1649.     sprintf("%20.6s", $game_screen.tint_rate[3])]]
  1650.   end
  1651.  
  1652.   def weather_tint_info
  1653.     # Return strings related to the weather tint.
  1654.     return [
  1655.     ['** WEATHER TINT', '  Red:', '  Green:', '  Blue:', '  Gray:'],
  1656.     ['', sprintf("%20.6s", $game_screen.weather_tint_rate[0]),
  1657.     sprintf("%20.6s", $game_screen.weather_tint_rate[1]),
  1658.     sprintf("%20.6s", $game_screen.weather_tint_rate[2]),
  1659.     sprintf("%20.6s", $game_screen.weather_tint_rate[3])]]
  1660.   end
  1661. end
  1662.  
  1663. #-------------------------------------------------------------------------------
  1664. # Make the following instance variables from each of the below classes public.
  1665. #-------------------------------------------------------------------------------
  1666. class Climate
  1667.   attr_reader :climate
  1668. end
  1669. #-------------------------------------------------------------------------------
  1670. class Game_Screen
  1671.   attr_reader :weather_type_target, :weather_duration, :weather_wait
  1672.   attr_reader :weather_count, :weather_tint_rate, :tint_rate
  1673. end
  1674. #-------------------------------------------------------------------------------
  1675. class Time_System
  1676.   attr_reader :count, :frame_count, :speed, :frozen
  1677. end
  1678. #-------------------------------------------------------------------------------
  1679. module CCTS
  1680.  
  1681.   def self.debug
  1682.     if $DEBUG && $scene.is_a?(Scene_Map)
  1683.       $ccts_debug = $ccts_debug == nil ? CCTS_Debug.new : $ccts_debug.dispose
  1684.     end
  1685.   end
  1686.  
  1687.   if $DEBUG && WRITE_MISSING_DATA
  1688.     c_maps, map_ids, multi_clim = [], [], []
  1689.     climate = Climate.new
  1690.     maps = load_data('Data/MapInfos.rxdata')
  1691.     maps.each_key {|i| map_ids.push(i)}
  1692.     climate.climate.each {|c| c.maps.each_index {|i| c_maps.push(c.maps[i])}}
  1693.     [map_ids, c_maps].each {|array| array.sort! }
  1694.     file = File.open('Climate Data.txt', 'wb')
  1695.     if map_ids == c_maps
  1696.       text = 'No climates missing. All maps have climates defined, and are configured correctly.'
  1697.       file.write(text)
  1698.     end
  1699.     no_clim = map_ids - c_maps
  1700.     no_map = c_maps - map_ids
  1701.     c_maps.each_index{|i|
  1702.       if c_maps[i] == c_maps[i + 1]
  1703.         multi_clim.push(c_maps[i]) unless multi_clim.include?(c_maps[i])
  1704.       end
  1705.     }
  1706.     lines = []
  1707.     unless no_clim.empty?
  1708.       lines.push("The following maps do not have a climate defined...\r\n")
  1709.       no_clim.each {|id| lines.push("  ID:#{id} (#{maps[id].name})\r\n") }
  1710.       lines.push("\r\n")
  1711.     end
  1712.     unless no_map.empty?
  1713.       lines.push("The following map IDs have defined climates, but no map exist with ID(s)...\r\n")
  1714.       no_map.each {|id| lines.push("  ID: #{id}\r\n") }
  1715.       lines.push("\r\n")
  1716.     end
  1717.     unless multi_clim.empty?
  1718.       lines.push("The following map IDs are defined more than once...\r\n")
  1719.       multi_clim.sort.each {|id| lines.push("  ID: #{id} (#{maps[id].name})\r\n") }
  1720.     end
  1721.     lines.each {|line| file.write(line) }
  1722.     file.close
  1723.   end
  1724. end
RAW Paste Data