Ultimate Day/Night & Weather System
By: Rinobi
Version History
0.7 Alpha Release [12/24/2015]
Introduction
This script adds a totally customization calendar system complete with day/night cycles, seasonal weather patterns and tilesets.
The goal is to give the developer complete control over how time flows within their projects.
I don't expect to find too many bugs, but keep in mind that this is an alpha release.
This script is still very much in development; I'm hoping your testing will help to speed up the process. Report bugs, request features, suggest alterations.
Happy Holidays!
Features
- Individually adjust the length of seconds, minutes hours, and days.
- Easily set which maps or tilesets are considered indoors.
- Choose screen tints for a range of hours during the day. The script automatically fills in each hour based on your settings.
- Have as many, or as few, days, weeks, and months per year as you desire. Calendar will adjust automatically to your settings.
- Set up your own seasons, when they occur, and how this affects the weather and even tilesets.
- Add any number of weathers, complete with outdoor and indoor sound effects.
- More to come!
Coming soon.
Terms of Use
Wait until its finished...
The Script:
Code:
#==============================================================================# Rinobi: Ultimate Day/Night & Weather System# -----------------------------------------------------------------------------# This script adds a totally customizable calendar system complete with# day/night cycles, seasonal weather patterns and tilesets. The developer# now has complete control over how time flows in their project.#==============================================================================# Version History:# -----------------------------------------------------------------------------# @ 0.6 [12/23/2015] Finished alpha version# @ 0.7 [12/23/2015] Added lightning & thunder effects.#==============================================================================# * Instructions# -----------------------------------------------------------------------------# Plug & Play, adjust default settings to your liking.#==============================================================================# * Script Calls# -----------------------------------------------------------------------------# Maybe later.#==============================================================================# * Compatibility# -----------------------------------------------------------------------------# Modules:# @ TimeSystem < RINOBI# @ TimeDisplay < RINOBI## Alias Methods:# @ initialize in Game_Map# @ setup in Game_Map# @ update_events in Game_Map#==============================================================================# * Notes# -----------------------------------------------------------------------------# 1. Update time_process to account for added and subtracted time.# 2. Add configuration for in-battle time passage.# 3. Weather effects within battles?#==============================================================================module RINOBI module TimeSystem # No Touchie!#==============================================================================# ** Settings Module#------------------------------------------------------------------------------# Adjust the below settings to your liking.#------------------------------------------------------------------------------ # --------------------------------------------------------------------------- # * Start Date # --------------------------------------------------------------------------- # The startup upon beginning a new game. # # Year = Any integer you desire # Month = See 'Months' settings below. # Day = The day within the current month. See 'Months' settings below. # Hour = A number within 'Day_Length' setting below. # Minute = A number within 'Hour_Length' setting below. # Second = A number within 'Minute_Length' setting below. Start_Date = { :Year => 2015, :Month => 2, :Day => 30, :Hour => 19, :Minute => 30, :Second => 0, } # StartDate Start_Weather = 0 # --------------------------------------------------------------------------- # * Timescale # --------------------------------------------------------------------------- Second_Length = 60 # Number of frames in a second. Minute_Length = 10 # Number of seconds in a minute. Hour_Length = 59 # Number of minutes in an hour. Day_Length = 23 # Number of hours in a day. # --------------------------------------------------------------------------- # * Indoor Settings # --------------------------------------------------------------------------- # For maps which should be unaffected or affected differently by # Day/Night screen tints and weather patterens # # Indoor_Maps = An array of map IDs to be considered indoors. # Indoor_Tiles = An array of tileset IDs to be considered indoors. # Indoor_Tint = The Screen tint used for indoor maps Indoor_Maps = [0, 0, 0, 0] # ID, ID, ID, ID Indoor_Tiles = [3, 4, 6, 7] # ID, ID, ID, ID Indoor_Tint = [0, 0, 0, 0] # Red, Green, Blue, Alpha # --------------------------------------------------------------------------- # * Day/Night Cycle # --------------------------------------------------------------------------- # Adjust the outdoor tint levels based on a range of hours below. Each hour # of the day will be filled in automatically. See example below. # # Module settings # 1 => {:Tint => [ -75, -75, 0, 50], :Range => ( 5..8)}, # 2 => {:Tint => [ 0, 0, 0, 0], :Range => ( 9..10)}, # Auto Fill # Hour 5 [ -75, -75, 0, 50] # Hour 6 [ -50, -50, 0, 33] # Hour 7 [ -25, -25, 0, 17] # Hour 8 [ 0, 0, 0, 0] # # Tint = [Red, Green, Blue, Alpha] # Range = (Start_Hour..End_Hour) Day_Cycle = { # Dawn, Morning, Noon, Afternoon, Evening, Night, Midnight 1 => {:Tint => [ -75, -75, 0, 50], :Range => ( 5..8)}, 2 => {:Tint => [ 0, 0, 0, 0], :Range => ( 9..10)}, 3 => {:Tint => [ 45, 45, 0, 0], :Range => (11..15)}, 4 => {:Tint => [ 0, 0, 0, 0], :Range => (16..19)}, 5 => {:Tint => [ -50, -50, 0, 25], :Range => (20..21)}, 6 => {:Tint => [ -75, -100, 0, 75], :Range => (22..23)}, 7 => {:Tint => [-125, -125, 0, 125], :Range => ( 0..4)}, } # Day_Cycle # --------------------------------------------------------------------------- # * Week Days # --------------------------------------------------------------------------- # Adjust the length of one week by adding or removing keys. Set the names of # each week day and the order in which they appear. Days = { 1 => 'Sunday', 2 => 'Monday', 3 => 'Tuesday', 4 => 'Wednesday', 5 => 'Thursday', 6 => 'Friday', 7 => 'Saturday', } # Days # --------------------------------------------------------------------------- # * Month Settings # --------------------------------------------------------------------------- # Adjust the number of months in a year by adding or removing keys. Set the # names of each month and the order in which they appear. Set the number of # days each month has and the season each month appears within. # # Name = A string containing the name of this month. # Days = The number of days within this month. # Season = Which season this month is a part of. Months = { 1 => {:Name => 'January' , :Days => 30, :Season => 4}, 2 => {:Name => 'February' , :Days => 30, :Season => 4}, 3 => {:Name => 'March' , :Days => 30, :Season => 1}, 4 => {:Name => 'April' , :Days => 30, :Season => 1}, 5 => {:Name => 'May' , :Days => 30, :Season => 1}, 6 => {:Name => 'June' , :Days => 30, :Season => 2}, 7 => {:Name => 'July' , :Days => 30, :Season => 2}, 8 => {:Name => 'August' , :Days => 30, :Season => 2}, 9 => {:Name => 'September', :Days => 30, :Season => 3}, 10 => {:Name => 'October' , :Days => 30, :Season => 3}, 11 => {:Name => 'November' , :Days => 30, :Season => 3}, 12 => {:Name => 'December' , :Days => 30, :Season => 4}, } # Months # --------------------------------------------------------------------------- # * Season Settings # --------------------------------------------------------------------------- # Adjust the number of seasons avaliable by adding or removing keys. Set the # names of each season; the order in which they appear within this hash is # unimportant. Set the tileset this season uses and the likelyhood of # pre-specified weather patterns to occur. # --------------------------------------------------------------------------- # Automatically adjust tilesets during seasons? # Set to true or false. Use_Tilesets = false # IDs of seasonal tilesets. Add all tilesets elgible for change # during the seasons here. Season_Tilesets = [5, 8, 9, 10] # --------------------------------------------------------------------------- # Name = A string containing the name of this season. # Tileset = The tileset used while this season is active. # Weathers = The type and likelyhood that this weather will affect the # outdoor maps. See 'Weather Settings' below. Seasons = { 1 => { :Name => 'Spring', :Tileset => 9, :Weathers => { 0 => {:Weight => 4}, # Clear 4/17 1 => {:Weight => 5}, # Light Rain 5/17 2 => {:Weight => 5}, # Normal Rain 5/17 3 => {:Weight => 2}, # Heavy Rain 2/17 4 => {:Weight => 1}, # Storm 1/17 }}, # Spring 2 => { :Name => 'Summer', :Tileset => 5, :Weathers => { 0 => {:Weight => 5}, # Clear 5/15 1 => {:Weight => 1}, # Light Rain 1/15 2 => {:Weight => 2}, # Normal Rain 2/15 3 => {:Weight => 3}, # Heavy Rain 3/15 4 => {:Weight => 4}, # Storm 4/15 }}, # Summer 3 => { :Name => 'Autumn', :Tileset => 8, :Weathers => { 0 => {:Weight => 5}, # Clear 5/12 1 => {:Weight => 1}, # Light Rain 1/12 2 => {:Weight => 1}, # Normal Rain 1/12 5 => {:Weight => 1}, # Snow 1/12 6 => {:Weight => 4}, # Windy 4/12 }}, # Autumn 4 => { :Name => 'Winter', :Tileset => 10, :Weathers => { 0 => {:Weight => 1}, # Clear 1/10 1 => {:Weight => 3}, # Light Rain 3/10 2 => {:Weight => 1}, # Normal Rain 1/10 5 => {:Weight => 5}, # Snow 5/10 }}, # Winter } # Seasons # --------------------------------------------------------------------------- # * Weather Settings # --------------------------------------------------------------------------- # type = :none, :rain, :storm, :snow # power = 1 - 9, or 0 if type is set to :none # duration = frames to fade in/out Weathers = { # Clear, Light Rain, Rain, Heavy Rain, Storm, Snow, Windy 0 => {:Type => :none, :Power => 0, :Duration => 0, :Sound1 => RPG::BGS.new('', 0, 0), :Sound2 => RPG::BGS.new('', 0, 0), }, # Clear Weather / Indoors 1 => {:Type => :rain, :Power => 4, :Duration => 600, :Sound1 => RPG::BGS.new('Rain', 56, 100), :Sound2 => RPG::BGS.new('Rain', 42, 100), }, # Light Rain 2 => {:Type => :rain, :Power => 9, :Duration => 600, :Sound1 => RPG::BGS.new('Rain', 100, 100), :Sound2 => RPG::BGS.new('Rain', 75, 100), }, # Moderate Rain 3 => {:Type => :storm, :Power => 7, :Duration => 600, :Sound1 => RPG::BGS.new('Storm', 70, 100), :Sound2 => RPG::BGS.new('Storm', 53, 100), }, # Heavy Rain / Storm 4 => {:Type => :storm, :Power => 9, :Duration => 600, :Sound1 => RPG::BGS.new('Storm', 100, 100), :Sound2 => RPG::BGS.new('Storm', 75, 100), }, # Thunder Storm 5 => {:Type => :snow, :Power => 9, :Duration => 600, :Sound1 => RPG::BGS.new('', 0, 0), :Sound2 => RPG::BGS.new('', 0, 0), }, # Heavy Snow 6 => {:Type => :none, :Power => 0, :Duration => 600, :Sound1 => RPG::BGS.new('Wind', 100, 100), :Sound2 => RPG::BGS.new('Wind', 75, 100), }, # Very Windy } # Weather # --------------------------------------------------------------------------- # * Lightning & Thunder effects # --------------------------------------------------------------------------- # When :storm is used. # # [Red, Green, Blue, Opacity, Duration] Flash_Lightning = [255, 255, 255, 255, 15] # File = Sound Effect file name as string. # Volume = 0 - 100 # Pitch = 0 - 200, 100 is normal. SE_Thunder = { 1 => {:File => 'Thunder1', :Volume => 100, :Pitch => 100}, 2 => {:File => 'Thunder5', :Volume => 100, :Pitch => 80}, 3 => {:File => 'Thunder7', :Volume => 100, :Pitch => 100}, 4 => {:File => 'Thunder9', :Volume => 100, :Pitch => 100}, } # SE_Thunder#------------------------------------------------------------------------------# ** End of Settings#------------------------------------------------------------------------------# Editing beyond this area may result in unfathomable terror.#==============================================================================$imported = {} if $imported.nil? ; $imported[:RIN_RUDNWS] = trueend end # No Touchie!#===============================================================================# ** Module: Time Display#===============================================================================module RINOBI module TimeDisplay # No Touchie! #-------------------------------------------------------------------------- # New Method: show_time #-------------------------------------------------------------------------- def self.show_time season = $game_map.get_season_name year = $game_map.get_time('year') month_integer = $game_map.get_time('month') month_string = TimeSystem::Months[$game_map.get_time('month')][:Name] day_integer = $game_map.get_time('day') day_string = $game_map.calendar[month_integer][day_integer] hour = $game_map.get_time('hour') minute = sprintf("%02d", $game_map.get_time('minute')) apm = '' ; if hour > 11 then apm = 'PM' else apm = 'AM' end if hour < 1 then hour += 12 end ; if hour > 12 then hour -= 12 end hour = sprintf("%02d", hour) $game_message.background = 1 $game_message.position = 1 ; $game_message.add("") $game_message.add("#{month_string} #{day_integer}, #{year}[#{season}]") $game_message.add("#{day_string}, #{hour}:#{minute}\\C[1]#{apm}\\C[0]") end # show_timeend end # No Touchie!#===============================================================================# ** Class: Game_Battler < Game_BattlerBase#===============================================================================class Game_Battler < Game_BattlerBase alias :rinbattle_end :on_battle_end def on_battle_end $game_map.add_time('minute', $game_troop.turn_count * 10) rinbattle_end end # on_battle_endend # Game_Battler < Game_BattlerBase#===============================================================================# ** Class: Game_Map#===============================================================================class Game_Map #-------------------------------------------------------------------------- # * Attributes: year, month, day, hour, minute, calendar #-------------------------------------------------------------------------- attr_accessor :year attr_accessor :month attr_accessor :day attr_accessor :hour attr_accessor :minute attr_accessor :season attr_accessor :weather attr_accessor :calendar #-------------------------------------------------------------------------- # * Alias Methods: initialize, update_events, setup #-------------------------------------------------------------------------- alias :rin_init :initialize alias :rinupdate_events :update_events alias :rin_setup :setup #-------------------------------------------------------------------------- # * Alias Method: initialize #-------------------------------------------------------------------------- def initialize rin_init ; @speed = 0 start_date = RINOBI::TimeSystem::Start_Date months = RINOBI::TimeSystem::Months days = RINOBI::TimeSystem::Days @weather = RINOBI::TimeSystem::Start_Weather @year = start_date[:Year] @month = start_date[:Month] @day = start_date[:Day] @hour = start_date[:Hour] @minute = start_date[:Minute] @second = start_date[:Second] @season = months[@month][:Season] @week = days.count # Generate calendar days = RINOBI::TimeSystem::Days @calendar = Hash.new ; m_start = 0, m_end = 0 ; month = 1 ; count = 0 while month <= RINOBI::TimeSystem::Months.count cmonth = month while cmonth > 0 m_end += RINOBI::TimeSystem::Months[cmonth][:Days] cmonth -= 1 end # cmonth > 0 m_start = (1 + m_end) - RINOBI::TimeSystem::Months[month][:Days] @calendar[month] = Hash[(m_start..m_end).map {|n|[n, days[count]]}] @calendar[month].count.times do |s| count = 0 unless count < @week count += 1 ; @calendar[month][s+1] = RINOBI::TimeSystem::Days[count] end # @calendar[month]count.times do |s| month += 1 ; m_end = 0 end # month <= RINOBI::TimeSystem::Months.count end # initialize #-------------------------------------------------------------------------- # * New Methods: year, month, day, hour, minute, calendar #-------------------------------------------------------------------------- define_method(:year) {@year} define_method(:month) {@month} define_method(:day) {@day} define_method(:hour) {@hour} define_method(:minute) {@minute} define_method(:second) {@second} define_method(:weather) {@weather} define_method(:calendar) {@calendar} define_method(:total_days) {@total_days} define_method(:season) {@season = RINOBI::TimeSystem::Months[month][:Season]} #-------------------------------------------------------------------------- # * Alias Method: setup #-------------------------------------------------------------------------- def setup(map_id) rin_setup(map_id) ; light_cycle set_weather(@weather, true) return if indoors? return unless RINOBI::TimeSystem::Use_Tilesets return unless RINOBI::TimeSystem::Season_Tilesets.include?(@tileset_id) change_tileset(RINOBI::TimeSystem::Seasons[season][:Tileset]) end # setup #-------------------------------------------------------------------------- # * New Method: set_time #-------------------------------------------------------------------------- def set_time(key, value) return unless instance_variable_defined?(("@" + key).intern) instance_variable_set(("@" + key).intern, value) end # set_time #-------------------------------------------------------------------------- # * New Method: add_time #-------------------------------------------------------------------------- def add_time(key, value) return unless instance_variable_defined?(("@" + key).intern) current = instance_variable_get(("@" + key).intern) instance_variable_set(("@" + key).intern, current + value) end # add_time #-------------------------------------------------------------------------- # * New Method: get_time #-------------------------------------------------------------------------- def get_time(key) return unless instance_variable_defined?(("@" + key).intern) return instance_variable_get(("@" + key).intern) end # get_time #-------------------------------------------------------------------------- # * New Method: get_day #-------------------------------------------------------------------------- def calendar_day return $game_message.add("#{calendar[get_time('month')][get_time('day')]}") end # calendar_day #-------------------------------------------------------------------------- # * New Method: time_process #-------------------------------------------------------------------------- def time_process return unless @speed > RINOBI::TimeSystem::Second_Length @speed = 0 ; add_time("second", 1) return unless second > RINOBI::TimeSystem::Minute_Length set_time("second", 0) ; add_time("minute", 1) return unless minute > RINOBI::TimeSystem::Hour_Length set_time("minute", 0) ; add_time("hour", 1) ; light_cycle return unless hour > RINOBI::TimeSystem::Day_Length set_time("hour", 0) ; add_time("day", 1) ; auto_weather return unless day > RINOBI::TimeSystem::Months[month][:Days] set_time("day", 1) ; add_time("month", 1) return unless month > RINOBI::TimeSystem::Months.count set_time("month", 1) ; add_time("year", 1) end # time_process #-------------------------------------------------------------------------- # * New Method: light_cycle #-------------------------------------------------------------------------- def light_cycle range = RINOBI::TimeSystem::Day_Cycle range.count.times do |r| if range[r+1][:Range].include?(hour) return tint_level(r+1) end end end # light_cycle #-------------------------------------------------------------------------- # * New Method: tint_level #-------------------------------------------------------------------------- def tint_level(value) cycle = RINOBI::TimeSystem::Day_Cycle it = RINOBI::TimeSystem::Indoor_Tint if indoors? return @screen.start_tone_change(Color.new(it[0],it[1],it[2],it[3]),0) end tint1 = RINOBI::TimeSystem::Day_Cycle[value][:Tint] if value == cycle.count then tint2 = RINOBI::TimeSystem::Day_Cycle[1][:Tint] else tint2 = RINOBI::TimeSystem::Day_Cycle[value+1][:Tint] end range = RINOBI::TimeSystem::Day_Cycle[value][:Range].to_a t = [] t << distribute(tint1[0], tint2[0], range.count, true) t << distribute(tint1[1], tint2[1], range.count, true) t << distribute(tint1[2], tint2[2], range.count, true) t << distribute(tint1[3], tint2[3], range.count, true) #$game_message.add("Value[#{value}] Range: #{t[0]}") #$game_message.add("#{distribute(50, 0, 4, true)}") r = range.index(hour) @screen.start_tone_change(Color.new(t[0][r],t[1][r],t[2][r],t[3][r]),0) end # tint_level #-------------------------------------------------------------------------- # * New Method: distribute #-------------------------------------------------------------------------- def distribute(begin_value, end_value, array_size, return_ints = false) diff = 1.0 * (end_value - begin_value) n = [array_size-1, 1].max (0..(array_size-1)).map do |i| v = begin_value + i * diff / n return_ints ? v.round : v end end # distribute #-------------------------------------------------------------------------- # * New Method: auto_weather #-------------------------------------------------------------------------- def auto_weather weather = [] RINOBI::TimeSystem::Seasons[season][:Weathers].keys.each do |s| RINOBI::TimeSystem::Seasons[season][:Weathers][s][:Weight].times do index = RINOBI::TimeSystem::Seasons[season][:Weathers].keys.index(s) weather << RINOBI::TimeSystem::Seasons[season][:Weathers].keys[index] end end set_weather(weather.sample) end # auto_weather #-------------------------------------------------------------------------- # * New Method: set_weather #-------------------------------------------------------------------------- def set_weather(value, fast = false) @weather = value if indoors? RINOBI::TimeSystem::Weathers[value][:Sound2].play type = RINOBI::TimeSystem::Weathers[0][:Type] power = RINOBI::TimeSystem::Weathers[0][:Power] duration = RINOBI::TimeSystem::Weathers[0][:Duration] screen.change_weather(type, power, duration) else RINOBI::TimeSystem::Weathers[value][:Sound1].play type = RINOBI::TimeSystem::Weathers[value][:Type] power = RINOBI::TimeSystem::Weathers[value][:Power] if fast then duration = 0 else duration = RINOBI::TimeSystem::Weathers[value][:Duration] end screen.change_weather(type, power, duration) end end # set_weather #-------------------------------------------------------------------------- # * New Method: get_season_name #-------------------------------------------------------------------------- def get_season_name seasons = RINOBI::TimeSystem::Seasons ; months = RINOBI::TimeSystem::Months return seasons[months[get_time('month')][:Season]][:Name] end # get_season #-------------------------------------------------------------------------- # * New Method: set_date #-------------------------------------------------------------------------- def set_date(value, year, month, day, hour, minute) value = [] value << year value << month value << day value << hour value << minute @set_date[value] = value end # set_date #-------------------------------------------------------------------------- # * New Method: set_date #-------------------------------------------------------------------------- def due_date?(value) false ; array = @set_date[value] return unless year >= array[0] return unless month >= array[1] return unless day >= array[2] return unless hour >= array[3] return unless minute >= array[4] return true end # due_date? #-------------------------------------------------------------------------- # * New Method: indoors? #-------------------------------------------------------------------------- def indoors? return true if RINOBI::TimeSystem::Indoor_Maps.include?(map_id) return true if RINOBI::TimeSystem::Indoor_Tiles.include?(tileset.id) return false end # indoors? #-------------------------------------------------------------------------- # * Alias Method: update_events #-------------------------------------------------------------------------- def update_events rinupdate_events @speed += 1 time_process endend # Game_Map#==============================================================================# ** Class: Spriteset_Weather#==============================================================================class Spriteset_Weather #-------------------------------------------------------------------------- # * Alias Method: Update Sprite [Storm] #-------------------------------------------------------------------------- alias :rinupdate_storm :update_sprite_storm def update_sprite_storm(sprite) rinupdate_storm(sprite) return unless rand(100000 / @power) < 1 total = RINOBI::TimeSystem::SE_Thunder.count selection = 1 + rand(total - 1) red = RINOBI::TimeSystem::Flash_Lightning[0] green = RINOBI::TimeSystem::Flash_Lightning[1] blue = RINOBI::TimeSystem::Flash_Lightning[2] opacity = RINOBI::TimeSystem::Flash_Lightning[3] frames = RINOBI::TimeSystem::Flash_Lightning[4] file = RINOBI::TimeSystem::SE_Thunder[selection][:File] volume = RINOBI::TimeSystem::SE_Thunder[selection][:Volume] pitch = RINOBI::TimeSystem::SE_Thunder[selection][:Pitch] $game_map.screen.start_flash(Color.new(red,green,blue,opacity),frames) RPG::SE.new(file, volume, pitch).play end # update_sprite_stormend # Spriteset_Weather