Advertisement
ForeverZer0

[RMXP] Complete Climate & Time System (CCTS) 1.2.2

May 21st, 2011
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 68.12 KB | None | 0 0
  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.     time_fix
  720.   end
  721. #-------------------------------------------------------------------------------  
  722.   def advance_hour(hour)
  723.     # Add HOUR number of hours to the time, then corrects.
  724.     return unless hour >= 0
  725.     @hour += hour
  726.     time_fix
  727.   end
  728. #-------------------------------------------------------------------------------  
  729.   def advance_day(day)
  730.     # Add DAY number of days to the time, then corrects.
  731.     return unless day >= 0
  732.     @day += day
  733.     time_fix
  734.   end
  735. #-------------------------------------------------------------------------------  
  736.   def advance_month(month)
  737.     # Add MONTH number of months to the time, then corrects.
  738.     return unless month >= 0
  739.     @month += month
  740.     time_fix
  741.   end
  742. #-------------------------------------------------------------------------------  
  743.   def advance_year(year)
  744.     # Add YEAR many of years to the time. No need to correct.
  745.     return unless (@year + year) >= 0
  746.     @year += year
  747.   end
  748. #-------------------------------------------------------------------------------
  749.   def set(min = @minute, hr = @hour, day = @day, mos = @month, yr = @year)
  750.     # Set the current time to the defined values. Current time is default values.
  751.     return unless min.between?(0, 59)
  752.     return unless hour.between?(0, 23)
  753.     return unless day.between?(1, CCTS::MONTH_LENGTH[month - 1])
  754.     return unless month.between?(1, CCTS::MONTHS.size)
  755.     return unless year >= 0
  756.     @minute, @hour, @day, @month, @year = min, hr, day, mos, yr
  757.     # Refresh the switches and recalibrate the tone based on the new time.
  758.     refresh_switches
  759.     $game_screen.tone_calibrate
  760.   end
  761. #-------------------------------------------------------------------------------
  762.   def memorize(index)
  763.     # Saves the "current_time" array to the specified index.
  764.     @memory[index] = current_time
  765.   end
  766. #-------------------------------------------------------------------------------  
  767.   def restore(index)
  768.     # Sets the time to the memorized time at index, if it exist.
  769.     return if @memory[index] == nil
  770.     time = @memory[index]
  771.     set(time[0], time[1], time[2], time[3], time[4])
  772.   end
  773. #-------------------------------------------------------------------------------
  774.   def change_climate(map_id, climate_id)
  775.     # Changes the current climate of MAP_ID to climate with CLIMATE_ID.
  776.     current = $game_map.climates.map_climate(map_id)
  777.     current.maps.delete(map_id)
  778.     $game_map.climates.climate[climate_id].maps.push(map_id)
  779.   end
  780. #-------------------------------------------------------------------------------      
  781.   def calculate_time
  782.     # Very simple method to pass time.
  783.     @hour += 1
  784.     @minute = 0
  785.     if @hour >= 24
  786.       @day += 1
  787.       @hour = 0
  788.       if @day > CCTS::MONTH_LENGTH[@month - 1]
  789.         @month += 1
  790.         @day = 1
  791.         if @month > CCTS::MONTHS.size
  792.           @year += 1
  793.           @month = 1
  794.         end
  795.       end
  796.     end
  797.   end
  798. #-------------------------------------------------------------------------------
  799.   def time_fix
  800.     # Corrects the time for when an out of range value is given for a particular
  801.     # setting, such as "advance_minute(400)"
  802.     if @minute >= 60
  803.       @hour += (@minute / 60)
  804.       @minute = @minute % 60
  805.     end
  806.     if @hour >= 24
  807.       @day += (@hour / 24)
  808.       @hour = @hour % 24
  809.     end
  810.     if @day > CCTS::MONTH_LENGTH[@month - 1]
  811.       @month += 1
  812.       @day = (@day % CCTS::MONTH_LENGTH[@month - 1]) + 1
  813.     end
  814.     if @month > CCTS::MONTHS.size + 1
  815.       @year += 1
  816.       @month = (@month % CCTS::MONTHS.size) + 1
  817.     end
  818.     $scene.clock.refresh if $scene.clock != nil
  819.     refresh_switches
  820.     error_check
  821.   end
  822. #-------------------------------------------------------------------------------  
  823.   def refresh_switches
  824.     # Set Day/Night switches if time is in configured ranges.
  825.     if @hour.between?(CCTS::DAY_START_HOUR, CCTS::NIGHT_START_HOUR - 1)
  826.       $game_switches[CCTS::DAY_SWITCH] = true
  827.       $game_switches[CCTS::NIGHT_SWITCH] = false
  828.     else
  829.       $game_switches[CCTS::DAY_SWITCH] = false
  830.       $game_switches[CCTS::NIGHT_SWITCH] = true
  831.     end
  832.     # Set Season Variable
  833.     CCTS::SEASON_MONTHS.each_index {|i|
  834.       if CCTS::SEASON_MONTHS[i].include?(@month)
  835.         $game_variables[CCTS::SEASON_VARIABLE] = i
  836.       end
  837.     }
  838.     # Set variables to the current time if configured to do so.
  839.     time = current_time
  840.     ids = [CCTS::MINUTE_VARIABLE, CCTS::HOUR_VARIABLE, CCTS::DAY_VARIABLE,
  841.      CCTS::MONTH_VARIABLE, CCTS::YEAR_VARIABLE]
  842.     ids.each_index {|i| $game_variables[ids[i]] = time[i] if ids[i] != nil }
  843.     # Have $game_map refresh to have events, etc. respond to changed switches.
  844.     $game_map.need_refresh = true
  845.   end
  846. #-------------------------------------------------------------------------------  
  847.   def error_check
  848.     # Checks that required settings are within permissable range. All of these
  849.     # would mess up the system later, or throw an error themselves. This will
  850.     # just give a better explanation, and catch it earlier.
  851.     raise('Time speed must be greater than 0!') unless @speed > 0
  852.     raise('No Days defined!') if CCTS::DAYS.empty?
  853.     raise('No Months defined!') if CCTS::MONTHS.empty?
  854.     if CCTS::WEATHER_WAIT[0] >= CCTS::WEATHER_WAIT[1]
  855.       raise('Minimum WEATHER_WAIT must be less than Maximum WEATHER_WAIT!')
  856.     end
  857.     if CCTS::MONTH_LENGTH.size != CCTS::MONTHS.size
  858.       raise('\'MONTH_LENGTH\' and \'MONTHS\' arrays must be equal size.')
  859.     end
  860.     if @minute > 60 || @hour > 24 ||
  861.         @day > CCTS::MONTH_LENGTH[@month - 1] || @month > CCTS::MONTHS.size ||
  862.         [@minute, @hour, @day, @month, @year].any? {|time| time < 0}
  863.       raise('Time System Error! Time value(s) not within permitted range.')
  864.     end
  865.   end
  866. #-------------------------------------------------------------------------------
  867.   def update
  868.     # Update the frame count as long as the frozen flag is false.
  869.     unless @frozen
  870.       @frame_count += 1
  871.       if @frame_count >= @count
  872.         @minute += 1
  873.         calculate_time if @minute == 60
  874.         refresh_switches
  875.         @frame_count = 0
  876.       end
  877.     end
  878.   end
  879. end
  880.  
  881. #===============================================================================
  882. # ** Game_Climate
  883. #===============================================================================
  884.  
  885.   # Assign a Struct to a constant to organize data of each climate.
  886. Game_Climate = Struct.new(:id, :name, :weather, :tinting, :sound, :speed, :maps)
  887.  
  888.  
  889. #===============================================================================
  890. # ** Game_Map
  891. #===============================================================================
  892.  
  893. class Game_Map
  894.  
  895.   attr_reader   :climate, :old_climate, :map
  896.   attr_accessor :climates
  897.  
  898.   alias zer0_last_map_init initialize
  899.   def initialize
  900.     zer0_last_map_init
  901.     # Initialize the climate variable for game map.
  902.     @climates = Climate.new
  903.     # Set the "last_map", which will be the starting map by default.
  904.     @last_map = $data_system.start_map_id
  905.   end
  906. #-------------------------------------------------------------------------------  
  907.   alias zer0_map_climate_setup setup
  908.   def setup(map_id)
  909.     # Have the setup method also setup the climate for the current map.
  910.     @climate = @climates.map_climate(map_id)
  911.     # Reset the old climate variable
  912.     @old_climate = @climates.map_climate(@last_map)
  913.     # Call the weather control method of Game_Screen to set weather/tone.
  914.     $game_screen.weather_control    
  915.     unless $game_system.time.speed_frozen
  916.       $game_system.time.change_speed(@climate.speed)
  917.     else
  918.       $game_screen.tone_calibrate
  919.     end
  920.     # Call original setup method.
  921.     zer0_map_climate_setup(map_id)
  922.     # Set the @last_map id to the current map ID. Used for the next map.
  923.     @last_map = @map_id
  924.   end
  925. #-------------------------------------------------------------------------------
  926.   alias zer0_weather_bgs_autoplay autoplay
  927.   def autoplay
  928.     # Disable normal BGS if weather sound is occuring.
  929.     $game_system.bgm_play(@map.bgm) if @map.autoplay_bgm
  930.     return if $game_screen.weather_bgs_playing?
  931.     zer0_weather_bgs_autoplay
  932.   end
  933. end
  934.  
  935. #===============================================================================
  936. # ** Game_System
  937. #===============================================================================
  938.  
  939. class Game_System
  940.  
  941.   attr_accessor :time, :clock, :clock_face, :simple_clock
  942.   attr_accessor :analog_clock, :analog_face, :clock_memory
  943.  
  944.   alias zer0_time_system_init initialize
  945.   def initialize
  946.     zer0_time_system_init
  947.     # Initialize the Time_System class.
  948.     @time = Time_System.new
  949.     # Initialize a few other instance variables used by the system.
  950.     @clock, @simple_clock, @bgs_volume_update = true, false, 0
  951.     @clock_memory, @analog_clock = true, CCTS::ANALOG_CLOCK
  952.     # Set starting values for the clock faces.
  953.     @clock_face, @analog_face = CCTS::CLOCK_FACE, CCTS::ANALOG_FACE
  954.   end
  955. #-------------------------------------------------------------------------------
  956.   def change_bgs_volume(volume)
  957.     # Changes the BGS volume to VOLUME. Does not change the BGS name.
  958.     return if @playing_bgs == nil
  959.     bgs = @playing_bgs
  960.     Audio.bgs_play('Audio/BGS/' + bgs.name, volume, bgs.pitch)
  961.   end
  962. #-------------------------------------------------------------------------------
  963.   def bgs_transition(start_vol, target_vol, frames)
  964.     # Transitions BGS volume from START_VOL to TARGET_VOL over the course of
  965.     # FRAMES number of frames.
  966.     range = target_vol - start_vol
  967.     @bgs_volume = start_vol
  968.     @bgs_volume_rate = range / frames.to_f
  969.     @bgs_volume_update = frames
  970.   end
  971. #-------------------------------------------------------------------------------
  972.   alias zer0_time_system_upd update
  973.   def update
  974.     # Updates the time if current scene is Scene_Map or Scene_Battle
  975.     if $scene.is_a?(Scene_Map) || $scene.is_a?(Scene_Battle)
  976.       @time.update
  977.     end
  978.     # Update BGS volume transitions if needed.
  979.     if @bgs_volume_update != 0
  980.       @bgs_volume += @bgs_volume_rate
  981.       change_bgs_volume(@bgs_volume.round)
  982.       @bgs_volume_update -= 1
  983.     end
  984.     # Call normal update method of Game_System.
  985.     zer0_time_system_upd
  986.   end
  987. end
  988.  
  989. #===============================================================================
  990. # ** Game_Screen
  991. #===============================================================================
  992.  
  993. class Game_Screen
  994.  
  995.   attr_accessor :tone_frozen, :weather_frozen
  996.  
  997. #-------------------------------------------------------------------------------
  998.   alias zer0_screen_control_init initialize
  999.   def initialize
  1000.     zer0_screen_control_init
  1001.     # Initialize required instance variables.
  1002.     @minute = $game_system.time.minute
  1003.     # Calculate the weather delay based off the current config and climate.
  1004.     @weather_wait = weather_delay
  1005.     @weather_count = 0
  1006.     # Initialize arrays to retain rates of tinting for time and weather.
  1007.     @tint_rate = [0, 0, 0, 0]
  1008.     @weather_tint_rate = [0, 0, 0, 0]
  1009.     # Initialize the "frozen" flags.
  1010.     @tone_frozen = @weather_frozen = false
  1011.   end
  1012. #-------------------------------------------------------------------------------
  1013.   alias zer0_weather_effects weather
  1014.   def weather(type, power, duration, variation = 0)
  1015.     # Alias weather method to call other methods for setting the tint rates,
  1016.     # sound, etc. when the weather is changed.
  1017.     if type != @weather_type
  1018.       # Refresh the tint, and call BGS to transition smoothly if changing.
  1019.       @last_weather = @weather_type_target
  1020.       weather_tint_refresh(@weather_type, type, duration)
  1021.       weather_bgs_control(type, duration, $game_map.climate.weather)
  1022.     end
  1023.     # Reset BGS if climate has changed.
  1024.     if $game_map.climate.id != $game_map.old_climate.id &&
  1025.       $game_map.climate.sound
  1026.       weather_bgs_control(type, duration, $game_map.climate.weather)
  1027.     end
  1028.     # Refresh the switches used for Good/Bad Weather, Type variables, etc.
  1029.     refresh_weather_switches(type)
  1030.     # Set tone change flag if needed.
  1031.     @weather_tone_change = (type != @weather_type)
  1032.     # Call normal method, use fourth argument if Zer0 Adv. Weather or MAWS.
  1033.     if @weather_variation != nil
  1034.       zer0_weather_effects(type, power, duration, variation)
  1035.     else
  1036.       zer0_weather_effects(type, power, duration)
  1037.     end
  1038.   end
  1039. #-------------------------------------------------------------------------------
  1040.   def tint_rate_refresh
  1041.     # Evaluates the tint rate for the time. Uses configuration to find rate for
  1042.     # the next hour. Uses this value, the current, and the time speed to
  1043.     # determine the rate at which it needs to change per frame.
  1044.     @minute = $game_system.time.minute
  1045.     rate = [0, 0, 0, 0]
  1046.     hour = $game_system.time.hour
  1047.     month = $game_system.time.month
  1048.     current = CCTS.time_tint($game_map.climate.id, hour, month)
  1049.     target = CCTS.time_tint($game_map.climate.id, (hour + 1) % 24, month)
  1050.     rate.each_index {|i|
  1051.       rate[i] = current[i].abs - target[i].abs
  1052.       rate[i] /= (60.0 * $game_system.time.count_length)}
  1053.     @tint_rate = rate
  1054.   end
  1055. #-------------------------------------------------------------------------------
  1056.   def weather_tint_refresh(old_type, new_type, duration)
  1057.     # Sets the tint rate, based off the current tone that is, the target tone,
  1058.     # and the number of frames that it has to do so. This rate change is
  1059.     # independent of the normal tint rate for time.
  1060.     old = CCTS.weather_tint(old_type)
  1061.     new = CCTS.weather_tint(new_type)
  1062.     unless $game_map.climate.tinting
  1063.       # End method if the tone cannot from be modified due to freeze status.
  1064.       unless @tone_frozen
  1065.         @tone.red -= old[0]
  1066.         @tone.green -= old[1]
  1067.         @tone.blue -= old[2]
  1068.         @tone.gray -= old[3]
  1069.       end
  1070.       return
  1071.     end
  1072.     # End method if the tones are equal and no change needs done.
  1073.     return if old == new
  1074.     # Instantly set tone if the duration is 0 and end method.
  1075.     if duration == 0 && !@tone_frozen
  1076.       @tone.red = (@tone.red - old[0] + new[0])
  1077.       @tone.green = (@tone.green - old[1] + new[1])
  1078.       @tone.blue = (@tone.blue - old[2] + new[2])
  1079.       @tone.gray = (@tone.gray - old[3] + new[3])
  1080.       return
  1081.     end
  1082.     # Initialize new rate array.
  1083.     rate = [0, 0, 0, 0]
  1084.     rate.each_index {|i|
  1085.       # Evaluates difference in tones and divides by number of frames to change.
  1086.       rate[i] = old[i].abs - new[i].abs
  1087.       rate[i] /= (duration - 1).to_f}
  1088.     @weather_tint_rate = rate
  1089.   end
  1090. #-------------------------------------------------------------------------------
  1091.   def screen_tint_update
  1092.     # Use a clone of the tint rate to avoid actual modification of the rate.
  1093.     rate = @tint_rate.clone
  1094.     # Adds the weather tint to the screen tint for the duration of the weather.
  1095.     if @weather_duration != 0 && @weather_tone_change
  1096.       rate.each_index {|i| rate[i] += @weather_tint_rate[i] }
  1097.     end
  1098.     # Addes total value to each respective value of the current tone.
  1099.     @tone.red += rate[0]
  1100.     @tone.green += rate[1]
  1101.     @tone.blue += rate[2]
  1102.     @tone.gray -= rate[3]
  1103.   end
  1104. #-------------------------------------------------------------------------------
  1105.   def tone_calibrate
  1106.     # Recalibrates the the system and all its rates, timing, etc. since it can
  1107.     # sometimes get slightly off due to frame skips, bad decimal correction, etc.
  1108.     min = $game_system.time.minute
  1109.     hour = $game_system.time.hour
  1110.     month = $game_system.time.month
  1111.     weather = CCTS.weather_tint(@weather_type_target)
  1112.     current = CCTS.time_tint($game_map.climate.id, hour, month)
  1113.     target = CCTS.time_tint($game_map.climate.id, (hour + 1) % 24, month)
  1114.     # Instantly sets weather to its target and sets weather duration to 0.
  1115.     tone, @weather_duration, @weather_max = [], 0, @weather_max_target
  1116.     # Recalculate each tone to more precise values.
  1117.     current.each_index {|i|
  1118.       tone[i] = current[i].abs - target[i].abs
  1119.       tone[i] /= 60.0
  1120.       tone[i] *= min
  1121.       tone[i] += current[i]
  1122.       tone[i] += weather[i]}
  1123.     # Sets tone to recalibrated settings unless the tone is frozen.
  1124.     unless @tone_frozen
  1125.       @tone.red, @tone.green = tone[0], tone[1]
  1126.       @tone.blue, @tone.gray = tone[2], tone[3]
  1127.     end
  1128.     # Refresh rates based off corrected data.
  1129.     tint_rate_refresh
  1130.   end
  1131. #-------------------------------------------------------------------------------
  1132.   def refresh_weather_switches(type)
  1133.     # Sets the switches to required values. Has Game_Map refresh afterwards.
  1134.     $game_variables[CCTS::WEATHER_VARIABLE] = type
  1135.     value = CCTS::BAD_WEATHER_TYPES.include?(type)
  1136.     $game_switches[CCTS::BAD_WEATHER_SWITCH] = value
  1137.     $game_switches[CCTS::GOOD_WEATHER_SWITCH] = !value
  1138.     $game_map.need_refresh = true
  1139.   end
  1140. #-------------------------------------------------------------------------------  
  1141.   def weather_delay
  1142.     # Gets a random number from within the MIN/MAX range of the weather wait.
  1143.     min = CCTS::WEATHER_WAIT[0]
  1144.     max = CCTS::WEATHER_WAIT[1]
  1145.     delay = (min + rand(max - min + 1)) * 40
  1146.     return delay
  1147.   end
  1148. #-------------------------------------------------------------------------------  
  1149.   def weather_control
  1150.     # This is the heart of how weather is controlled. Most calculations of how
  1151.     # the weather is handled are either done here, or called from here.
  1152.     if @weather_count < @weather_wait
  1153.       # Ensures the weather remains consistant through different maps with the
  1154.       # same climate. Also remembers the weather of the last climate.
  1155.       return if $game_map.climate.id == $game_map.old_climate.id
  1156.       if $game_map.climate.weather && @last_weather != nil
  1157.         weather(@last_weather, rand(50) + 1, 0)
  1158.         return
  1159.       end
  1160.     end
  1161.     # Turn the weather off instantly if no weather is allowed for climate.
  1162.     unless $game_map.climate.weather
  1163.       weather(0, 0, 0)
  1164.       @weather_count = 0
  1165.       return
  1166.     end
  1167.     # Reset the weather wait and recalculate a new delay until the next update.
  1168.     @weather_count = 0
  1169.     @weather_wait = weather_delay
  1170.     transition = rand(120) + 160
  1171.     power = rand(50) + 1
  1172.     # Get a random number 1..100 to use for the chance of the weather.
  1173.     chance = rand(100) + 1
  1174.     # Gets the current climate and month to determine weather for the season.
  1175.     climate, month = $game_map.climate.id, $game_system.time.month
  1176.     climate_weather = CCTS.weather_prob(climate, month)
  1177.     # If the climate has no weather defined, turn it off and end method.
  1178.     if climate_weather == nil
  1179.       weather(0, 0, 0)
  1180.       return
  1181.     end
  1182.     type = variation = 0
  1183.     # Trim array down to only types that whose probability is higher than chance
  1184.     climate_weather.reject! {|array| array[1] < chance }
  1185.     unless climate_weather.empty?
  1186.       # Get a random type from all weather types that were greater than chance.
  1187.       r = rand(climate_weather.size)
  1188.       type = climate_weather[r][0]
  1189.       # Get variation if defined.
  1190.       if climate_weather[r][2] != nil
  1191.         variation = climate_weather[r][2]
  1192.       end
  1193.     end
  1194.     # Call weather, using variation if defined.
  1195.     if @weather_variation != nil
  1196.       return if (type == @weather_type) && (variation == @weather_variation)
  1197.       weather(type, power, transition, variation)
  1198.     else
  1199.       return if type == @weather_type
  1200.       weather(type, power, transition)
  1201.     end
  1202.   end
  1203. #-------------------------------------------------------------------------------  
  1204.   def weather_bgs_playing?
  1205.     # Returns true if a BGS is playing for the weather.
  1206.     return false unless $game_map.climate.sound
  1207.     if $game_map.climate.weather
  1208.       return false if CCTS.weather_BGS(@weather_type_target) == nil
  1209.     end
  1210.     if $game_map.climate.sound && !$game_map.climate.weather &&
  1211.       CCTS.weather_BGS(@last_weather) == nil
  1212.       return false
  1213.     end
  1214.     return true
  1215.   end
  1216. #-------------------------------------------------------------------------------  
  1217.   def weather_bgs_control(type, duration, weather)
  1218.     # Turn weather BGS off if climate does not permit it, then end method.
  1219.     unless $game_map.climate.sound
  1220.       if weather_bgs_playing?
  1221.         $game_system.bgs_fade(0)
  1222.         $game_system.bgs_play($game_map.map.bgs) if $game_map.map.autoplay_bgs
  1223.         return
  1224.       end
  1225.     end
  1226.     # Use climate uses weather, set BGS to current weather sound.
  1227.     if weather
  1228.       bgs = CCTS.weather_BGS(type)
  1229.       if bgs != nil
  1230.         if duration > 0
  1231.           $game_system.bgs_play(RPG::AudioFile.new(bgs[0], 0, bgs[2]))
  1232.           $game_system.bgs_transition(0, bgs[1], duration)
  1233.         else
  1234.           $game_system.bgs_play(RPG::AudioFile.new(bgs[0], bgs[1], bgs[2]))
  1235.         end
  1236.       else
  1237.         $game_system.bgs_fade(duration / 25)
  1238.       end
  1239.     # If weather sound, but no weather is defined. Use the BGS from the last map
  1240.     # that used weather. Gives effect that weather is still occuring outside.
  1241.     else
  1242.       bgs = CCTS.weather_BGS(@last_weather)
  1243.       if bgs != nil
  1244.         audio = RPG::AudioFile.new(bgs[0], bgs[1], bgs[2])
  1245.         $game_system.bgs_play(audio)
  1246.         $game_system.change_bgs_volume(bgs[1] / 2)
  1247.       else
  1248.         $game_system.bgs_fade(duration / 25)
  1249.       end
  1250.     end
  1251.   end
  1252. #-------------------------------------------------------------------------------
  1253.   alias zer0_screen_tint_upd update
  1254.   def update
  1255.     # Refresh tint every game minute.
  1256.     tint_rate_refresh if @minute != $game_system.time.minute
  1257.     # Update the current tone, unless it is frozen.
  1258.     screen_tint_update unless @tone_frozen
  1259.     unless @weather_frozen
  1260.       # Add 1 to the current weather count.
  1261.       @weather_count += 1
  1262.       if @weather_count >= @weather_wait
  1263.         # If count duration is reached, call method to re-evaluate the weather.
  1264.         weather_control
  1265.       end
  1266.     end
  1267.     # Call normal update method.
  1268.     zer0_screen_tint_upd  
  1269.   end
  1270. #-------------------------------------------------------------------------------
  1271. end
  1272.  
  1273. #===============================================================================
  1274. # ** Scene_Map
  1275. #===============================================================================
  1276.  
  1277. class Scene_Map
  1278.  
  1279.   attr_accessor :clock  
  1280.  
  1281.   alias zer0_clock_main main
  1282.   def main
  1283.     # Create clock if memory is true.
  1284.     if $game_system.clock_memory
  1285.       @clock = $game_system.analog_clock ? Analog_Clock.new : Clock.new
  1286.     end
  1287.     # Main loop.
  1288.     zer0_clock_main
  1289.     # Dispose clock if it still exists when scene changes.
  1290.     if @clock != nil
  1291.       @clock.dispose
  1292.     end
  1293.   end
  1294.  
  1295.   alias zer0_clock_upd update
  1296.   def update
  1297.     zer0_clock_upd
  1298.     if Input.trigger?(CCTS::CLOCK_BUTTON)
  1299.       # Play SE when button for clock is triggered.
  1300.       if $game_system.clock
  1301.         $game_system.se_play($data_system.decision_se)
  1302.         if @clock == nil
  1303.           @clock = $game_system.analog_clock ? Analog_Clock.new : Clock.new
  1304.         else
  1305.           @clock = @clock.dispose
  1306.         end
  1307.         $game_system.clock_memory = @clock != nil
  1308.       else
  1309.         $game_system.se_play($data_system.buzzer_se)
  1310.       end
  1311.     end
  1312.     # Update clock if it exists.
  1313.     if @clock != nil
  1314.       @clock.update
  1315.     end
  1316.     # Dispose click if turned off by player, or explicitly by script call.
  1317.     if !$game_system.clock && @clock != nil
  1318.       @clock = @clock.dispose
  1319.     end
  1320.   end
  1321. end
  1322.  
  1323. #===============================================================================
  1324. # ** Clock
  1325. #===============================================================================
  1326.  
  1327. class Clock < Window_Base
  1328.  
  1329.   def initialize
  1330.     # Determine dimensions by what type of clock will be created.
  1331.     dim = $game_system.simple_clock ? [100, 47] : [176, 80]
  1332.     super($game_system.clock_face[0], $game_system.clock_face[1], dim[0], dim[1])
  1333.     self.contents = Bitmap.new(width - 32, height - 32)
  1334.     self.back_opacity, self.z = $game_system.clock_face[2], 9998
  1335.     self.contents.font.name = $game_system.clock_face[3]
  1336.     self.contents.font.size = $game_system.clock_face[4]
  1337.     # Determine the skin used for the clock.
  1338.     if CCTS::CLOCK_SKIN == nil
  1339.       self.windowskin = nil
  1340.     elsif CCTS::CLOCK_SKIN == 'DEFAULT SKIN'
  1341.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin_name)
  1342.     else
  1343.       self.windowskin = RPG::Cache.windowskin(CCTS::CLOCK_SKIN)
  1344.     end
  1345.     # Draw the clock.
  1346.     refresh
  1347.   end
  1348.  
  1349.   def refresh
  1350.     # Set a few local variables to current time variables.
  1351.     day, year = $game_system.time.day.to_s, $game_system.time.year.to_s
  1352.     month = CCTS::MONTHS[$game_system.time.month-1]
  1353.     time = sprintf(CCTS::TIME_FORMAT, $game_system.time.hour, $game_system.time.minute)
  1354.     # Clear the current bitmap.
  1355.     self.contents.clear
  1356.     # Set local variables equal to different text widths.
  1357.     tmw = 8 + contents.text_size('Time:').width
  1358.     dyw = 8 + contents.text_size('Day:').width
  1359.     dtw = 8 + contents.text_size('Date:').width
  1360.     self.contents.font.color = system_color
  1361.     # Begin to draw the clock. Only include more details if not Simple Clock.
  1362.     self.contents.draw_text(0, 0, 144, 15, 'Time:')
  1363.     unless $game_system.simple_clock
  1364.       self.contents.draw_text(0, 15, 144, 15, 'Day:')
  1365.       self.contents.draw_text(0, 30, 144, 15, 'Date:')
  1366.       self.contents.font.color = normal_color
  1367.       self.contents.draw_text(dyw, 15, 144, 15, $game_system.time.day_name)
  1368.       self.contents.draw_text(dtw, 30, 144, 15, "#{month} #{day}, #{year}")
  1369.     end
  1370.     self.contents.font.color = normal_color
  1371.     self.contents.draw_text(tmw, 0, 144, 15, time)
  1372.     # Set instance variable. Used to check when to next refresh.
  1373.     @mins = $game_system.time.minute
  1374.   end
  1375.  
  1376.   def update
  1377.     super
  1378.     # Redraw the clock every game minute.
  1379.     refresh if @mins != $game_system.time.minute
  1380.   end
  1381. end
  1382.  
  1383. #===============================================================================
  1384. # ** Analog_Clock
  1385. #===============================================================================
  1386.  
  1387. class Analog_Clock
  1388.  
  1389.   def initialize
  1390.     # Initialize the sprites.
  1391.     @clock_back, @minutehand, @hourhand = Sprite.new, Sprite.new, Sprite.new
  1392.     [@hourhand, @minutehand, @clock_back].each {|sprite| sprite.z = 9998 }
  1393.     # Set instance variable that will be used to determine when to refresh.
  1394.     @min = $game_system.time.minute
  1395.     # Set graphic and coordinates to each sprite.
  1396.     set_graphic
  1397.   end
  1398.  
  1399.   def set_graphic(*args)
  1400.     # Fill in any missing arguments.
  1401.     (0..4).each {|i| args[i] = $game_system.analog_face[i] if args[i] == nil }
  1402.     filename, handoffset, x, y, alpha = args[0], args[1], args[2], args[3], args[4]
  1403.     # Set the bitmaps to the sprites.
  1404.     @minutehand.bitmap = RPG::Cache.picture(filename + '_min')
  1405.     @hourhand.bitmap = RPG::Cache.picture(filename + '_hour')
  1406.     @clock_back.bitmap = RPG::Cache.picture(filename + '_back')
  1407.     # Set the coordinates of the clock hands.
  1408.     @clock_back.x, @clock_back.y = x, y
  1409.     @hourhand.x = @minutehand.x = (@clock_back.bitmap.width / 2) + x
  1410.     @hourhand.y = @minutehand.y = (@clock_back.bitmap.height / 2) + y
  1411.     # Set the origin points of the clock hands.
  1412.     @hourhand.ox = @hourhand.bitmap.width / 2
  1413.     @minutehand.ox = @minutehand.bitmap.width / 2
  1414.     @hourhand.oy = @minutehand.oy = handoffset
  1415.     # Set opacity of each sprite.
  1416.     [@hourhand, @minutehand, @clock_back].each {|sprite| sprite.opacity = alpha }
  1417.     # Call update now to avoid a frame flicker before normal update starts.
  1418.     update
  1419.   end
  1420.  
  1421.   def update
  1422.     # Only run any calculations if minute has changed.
  1423.     if @mins != $game_system.time.minute
  1424.       # Calculate angle for minute hand
  1425.       m_angle = (360 * ($game_system.time.minute / 60.0)).to_i - 180
  1426.       if m_angle != @minutehand.angle
  1427.         @minutehand.angle = -m_angle
  1428.         # Calculate hour hand angle, only if minute hand angle has changed.
  1429.         h_angle = ($game_system.time.hour % 12) * 30
  1430.         h_angle += (($game_system.time.minute / 60.0) * 30).to_i - 180
  1431.         if h_angle.to_i != @hourhand.angle
  1432.           # Set new hour hand angle if it has changed.
  1433.           @hourhand.angle = -h_angle.to_i
  1434.         end
  1435.       end
  1436.       @mins = $game_system.time.minute
  1437.     end
  1438.   end
  1439.  
  1440.   def dispose
  1441.     # Disposes the sprites.
  1442.     [@hourhand, @minutehand, @clock_back].each {|sprite| sprite.dispose }
  1443.     return
  1444.   end
  1445. end
  1446.  
  1447. #===============================================================================
  1448. # ** Window_Message
  1449. #===============================================================================
  1450.  
  1451. class Window_Message < Window_Selectable
  1452.  
  1453.   alias zer0_ccts_message_commands_refresh refresh
  1454.   def refresh
  1455.     if $game_temp.message_text != nil
  1456.       text = $game_temp.message_text
  1457.       begin
  1458.         # Use Regexp to find patterns in the message strings. If found, will
  1459.         # replace them with the proper value.
  1460.         last_text = text.clone
  1461.         hour, minute = $game_system.time.hour, $game_system.time.minute
  1462.         time = sprintf(CCTS::TIME_FORMAT, hour, minute)
  1463.         text.gsub!(/\\[Tt][Ii][Mm][Ee]/) { time }
  1464.         text.gsub!(/\\[Dd][Aa][Yy]/) { $game_system.time.day_name }
  1465.         text.gsub!(/\\[Mm][Oo][Nn]/) { CCTS::MONTHS[$game_system.time.month-1] }
  1466.         text.gsub!(/\\[Yy][Rr]/) { $game_system.time.year.to_s }
  1467.         text.gsub!(/\\[Mm][Oo][Ss]\[([0-9]+)\]/) {
  1468.           CCTS::MONTHS[$1.to_i - 1] != nil ? CCTS::MONTHS[$1.to_i - 1] : ''}
  1469.         text.gsub!(/\\[Dd][Yy]\[([0-9]+)\]/) {
  1470.           CCTS::DAYS[$1.to_i] != nil ? CCTS::DAYS[$1.to_i] : ''}
  1471.       end until text == last_text
  1472.     end
  1473.     # Call normal refresh method for Window_Message.
  1474.     zer0_ccts_message_commands_refresh
  1475.   end
  1476. end
  1477.  
  1478. #===============================================================================
  1479. # ** Interpreter
  1480. #===============================================================================
  1481.  
  1482. class Interpreter
  1483.  
  1484.   def time
  1485.     # Shorten "$game_system.time" to simply "time" for script calls.
  1486.     return $game_system.time
  1487.   end
  1488. end
  1489.  
  1490. #===============================================================================
  1491. # ** CCTS Debug
  1492. #-------------------------------------------------------------------------------
  1493. # Everything below is used solely for the Debug aspect of the system, and not
  1494. # required for the actual script at all. It is safe to erase if it not used.
  1495. #===============================================================================
  1496.  
  1497. #===============================================================================
  1498. # ** CCTS_Debug_Sprite
  1499. #===============================================================================
  1500.  
  1501. class CCTS_Debug < Sprite
  1502.  
  1503.   # Define the colors used to draw the text in, and background color.
  1504.   SYSTEM_COLOR = Color.new(192, 224, 255)
  1505.   NORMAL_COLOR = Color.new(255, 255, 255)
  1506.   CLEAR = Color.new(0, 0, 0, 96)
  1507.  
  1508.   # Defines what types of info will be drawn
  1509.   TIME         = true
  1510.   WEATHER      = true
  1511.   TONE         = true   # <-- This one tends to make the game lag.
  1512.   TINT_RATE    = true
  1513.   WEATHER_TINT = true
  1514.  
  1515.   def initialize
  1516.     viewport = Viewport.new(0, 0, 640, 480)
  1517.     viewport.z = 10000
  1518.     super(viewport)
  1519.     # Initialize the words used for each value.
  1520.     self.bitmap = Bitmap.new(640, 480)
  1521.     self.bitmap.font.name = 'Arial'
  1522.     self.bitmap.font.size = 14
  1523.     self.bitmap.font.bold = true
  1524.     @refresh = [TIME, WEATHER, TONE, TINT_RATE, WEATHER_TINT]
  1525.     @data = []
  1526.     @data[0] = time_info           if @refresh[0]
  1527.     @data[1] = weather_info        if @refresh[1]
  1528.     @data[2] = screen_tone_info    if @refresh[2]
  1529.     @data[3] = tint_info           if @refresh[3]
  1530.     @data[4] = weather_tint_info   if @refresh[4]
  1531.     # Draw all the items.
  1532.     @data.each_index {|i|
  1533.       if @data[i] != nil
  1534.         draw_items(Array.new(@data[i][0].size) {|j| j }, i)
  1535.       end
  1536.     }
  1537.     # Self updating thread.
  1538.     @thread = Thread.new { loop { $ccts_debug.update if $ccts_debug != nil } }
  1539.   end
  1540.  
  1541.   def dispose
  1542.     # Terminate the update thread when the sprite is disposed.
  1543.     @thread.kill
  1544.     @thread = nil
  1545.     super
  1546.   end
  1547.  
  1548.   def get_info(index)
  1549.     return case index
  1550.     when 0 then time_info
  1551.     when 1 then weather_info
  1552.     when 2 then screen_tone_info
  1553.     when 3 then tint_info
  1554.     when 4 then weather_tint_info
  1555.     end
  1556.   end
  1557.  
  1558.   def update
  1559.     # Check for change in values. Re-draws the lines that have changed.
  1560.     @refresh.each_index {|i|  
  1561.       if @refresh[i]
  1562.         info = get_info(i)
  1563.        if @data[i][1] != info[1]
  1564.           draw_items(get_indexes(@data[i][1], info[1]), i)
  1565.           @data[i] = info
  1566.         end
  1567.       end
  1568.     }
  1569.     # Dispose debugger and terminate thread if not Scene_Map
  1570.     unless $scene.is_a?(Scene_Map)
  1571.       $ccts_debug.dispose
  1572.     end
  1573.   end
  1574.  
  1575.   def draw_items(indexes, group)
  1576.     array = case group
  1577.     when 0 then [16, 304, 128]
  1578.     when 1 then [160, 424, 128]
  1579.     else
  1580.       [304+((group-2)*112), 412, 96]
  1581.     end
  1582.     indexes.each {|index|
  1583.       # Create a rect at the specific line.
  1584.       rect = Rect.new(array[0], (index*12)+array[1], array[2], 12)
  1585.       # Draw line number INDEX.
  1586.       self.bitmap.fill_rect(rect, CLEAR)
  1587.       self.bitmap.font.color = SYSTEM_COLOR
  1588.       self.bitmap.draw_text(rect, @data[group][0][index])
  1589.       self.bitmap.font.color = NORMAL_COLOR
  1590.       self.bitmap.draw_text(rect, @data[group][1][index], 2)
  1591.     }
  1592.   end
  1593.  
  1594.   def get_indexes(array1, array2)
  1595.     indexes = []
  1596.     array1.each_index {|i| indexes.push(i) if array1[i] != array2[i] }
  1597.     return indexes
  1598.   end
  1599.  
  1600.   def time_info
  1601.     # Return strings releated to the time.
  1602.     return [
  1603.     ['** TIME INFO', '  Time Frozen:', '  Tone Frozen:', '  Speed Frozen:',
  1604.      '  Weather Frozen:', '  Time Speed:', '  Count:', '  Minute:', '  Hour:',
  1605.      '  Day:', '  Month:', '  Year:', '  Day Name:', '  Month Name:'],
  1606.     ['', $game_system.time.frozen.to_s,
  1607.     $game_screen.tone_frozen.to_s, $game_system.time.speed_frozen.to_s,
  1608.     $game_screen.weather_frozen.to_s, $game_system.time.speed.to_s,
  1609.     $game_system.time.frame_count.to_s + '\\' + $game_system.time.count.to_s,
  1610.     $game_system.time.minute.to_s, $game_system.time.hour.to_s,
  1611.     $game_system.time.day.to_s, $game_system.time.month.to_s,
  1612.     $game_system.time.year.to_s, $game_system.time.day_name.to_s,
  1613.     CCTS::MONTHS[$game_system.time.month-1]]]
  1614.   end
  1615.  
  1616.   def weather_info
  1617.     # Return strings related to the weather.
  1618.     return [
  1619.     ['** WEATHER INFO', '  Duration:', '  Weather Type:', '  Count:'],
  1620.     ['', $game_screen.weather_duration.to_s, $game_screen.weather_type_target.to_s,
  1621.     $game_screen.weather_count.to_s + '\\' + $game_screen.weather_wait.to_s]]
  1622.   end
  1623.  
  1624.   def screen_tone_info
  1625.     # Return strings related to the screen tone.
  1626.     return [
  1627.     ['** SCREEN_TONE:', '  Red:', '  Green:', '  Blue:', '  Gray:'],
  1628.     ['', sprintf("%20.6s", $game_screen.tone.red),
  1629.     sprintf("%20.6s", $game_screen.tone.green),
  1630.     sprintf("%20.6s", $game_screen.tone.blue),
  1631.     sprintf("%20.6s", $game_screen.tone.gray)]]
  1632.   end
  1633.  
  1634.   def tint_info
  1635.     # Return strings related to the tint rate.
  1636.     return [
  1637.     ['** TINT RATE', '  Red:', '  Green:', '  Blue:', '  Gray:'],
  1638.     ['', sprintf("%20.6s", $game_screen.tint_rate[0]),
  1639.     sprintf("%20.6s", $game_screen.tint_rate[1]),
  1640.     sprintf("%20.6s", $game_screen.tint_rate[2]),
  1641.     sprintf("%20.6s", $game_screen.tint_rate[3])]]
  1642.   end
  1643.  
  1644.   def weather_tint_info
  1645.     # Return strings related to the weather tint.
  1646.     return [
  1647.     ['** WEATHER TINT', '  Red:', '  Green:', '  Blue:', '  Gray:'],
  1648.     ['', sprintf("%20.6s", $game_screen.weather_tint_rate[0]),
  1649.     sprintf("%20.6s", $game_screen.weather_tint_rate[1]),
  1650.     sprintf("%20.6s", $game_screen.weather_tint_rate[2]),
  1651.     sprintf("%20.6s", $game_screen.weather_tint_rate[3])]]
  1652.   end
  1653. end
  1654.  
  1655. #-------------------------------------------------------------------------------
  1656. # Make the following instance variables from each of the below classes public.
  1657. #-------------------------------------------------------------------------------
  1658. class Climate
  1659.   attr_reader :climate
  1660. end
  1661. #-------------------------------------------------------------------------------
  1662. class Game_Screen
  1663.   attr_reader :weather_type_target, :weather_duration, :weather_wait
  1664.   attr_reader :weather_count, :weather_tint_rate, :tint_rate
  1665. end
  1666. #-------------------------------------------------------------------------------
  1667. class Time_System
  1668.   attr_reader :count, :frame_count, :speed, :frozen
  1669. end
  1670. #-------------------------------------------------------------------------------
  1671. module CCTS
  1672.  
  1673.   def self.debug
  1674.     if $DEBUG && $scene.is_a?(Scene_Map)
  1675.       $ccts_debug = $ccts_debug == nil ? CCTS_Debug.new : $ccts_debug.dispose
  1676.     end
  1677.   end
  1678.  
  1679.   if $DEBUG && WRITE_MISSING_DATA
  1680.     c_maps, map_ids, multi_clim = [], [], []
  1681.     climate = Climate.new
  1682.     maps = load_data('Data/MapInfos.rxdata')
  1683.     maps.each_key {|i| map_ids.push(i)}
  1684.     climate.climate.each {|c| c.maps.each_index {|i| c_maps.push(c.maps[i])}}
  1685.     [map_ids, c_maps].each {|array| array.sort! }
  1686.     file = File.open('Climate Data.txt', 'wb')
  1687.     if map_ids == c_maps
  1688.       text = 'No climates missing. All maps have climates defined, and are configured correctly.'
  1689.       file.write(text)
  1690.     end
  1691.     no_clim = map_ids - c_maps
  1692.     no_map = c_maps - map_ids
  1693.     c_maps.each_index{|i|
  1694.       if c_maps[i] == c_maps[i + 1]
  1695.         multi_clim.push(c_maps[i]) unless multi_clim.include?(c_maps[i])
  1696.       end
  1697.     }
  1698.     lines = []
  1699.     unless no_clim.empty?
  1700.       lines.push("The following maps do not have a climate defined...\r\n")
  1701.       no_clim.each {|id| lines.push("  ID:#{id} (#{maps[id].name})\r\n") }
  1702.       lines.push("\r\n")
  1703.     end
  1704.     unless no_map.empty?
  1705.       lines.push("The following map IDs have defined climates, but no map exist with ID(s)...\r\n")
  1706.       no_map.each {|id| lines.push("  ID: #{id}\r\n") }
  1707.       lines.push("\r\n")
  1708.     end
  1709.     unless multi_clim.empty?
  1710.       lines.push("The following map IDs are defined more than once...\r\n")
  1711.       multi_clim.sort.each {|id| lines.push("  ID: #{id} (#{maps[id].name})\r\n") }
  1712.     end
  1713.     lines.each {|line| file.write(line) }
  1714.     file.close
  1715.   end
  1716. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement