Advertisement
Vlue

Advanced Climate

Aug 14th, 2012
4,958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.53 KB | None | 0 0
  1. #Advanced Climate System v1.1.1b
  2. #----------#
  3. #Features: Provides a more advanced weather system! Yay for random weather.
  4. #          This one has the ability to set multiple climates.
  5. #
  6. #Usage:    Plug and play and customize as needed!
  7. #          Script calls:
  8. #     Climate_Control.climate?    #returns the current climate of the map
  9. #     Climate_Control.inside?     #returns true if in a map marked as inside
  10. #     Climate_Control.change_weather(weather,duration = nil, climate = nil)
  11. #           Weather can be an integer 0-howevermanyweathersintheclimate
  12. #            or a symbol (:none,:rain,:snow,:storm)
  13. #           Duration need not be specified
  14. #           Climate will be the climate of the currentmap if unspecified
  15. #     Climate_Control.current_weather    #returns the current weather as an integer
  16. #     Climate_Control.still(true/false)  #pauses/unpauses weather
  17. #     Climate_Control.season             #returns the name of the current season
  18. #     Climate_Control.change_season(number) #Changes the season to whicher number
  19. #
  20. #
  21. #     Climate maps and details are set in the note field of maps
  22. #        C=#   specifies the climate of the map (i.e. C=0 or C=5)
  23. #    nosound   will cause that map to not have any weather effect sounds
  24. #     inside   will cause weather effects to not show
  25. #
  26. #     Any combination of the above effects can be placed in the map notes
  27. #        
  28. #Examples:
  29. #    Climate_Control.change_weather(:rain,nil,1)
  30. #    Climate_Control.change_weather(:snow)
  31. #    Climate_Control.change_weather(1)
  32. #    Climate_Control.still(true)
  33. #    Climate_Control.change_season(2)
  34. #
  35. #----------#
  36. #-- Script by: V.M of D.T
  37. #
  38. #- Questions or comments can be:
  39. #    given by email: sumptuaryspade@live.ca
  40. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  41. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  42. #
  43. #--- Free to use in any project, commercial or non-commercial, with credit given
  44. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  45.  
  46. #Number of available Climates to be used
  47. AC_CLIMATES = 2
  48. #Hash of weather for each climate, add more for each additional climate, can have
  49. #weathers as you want long as you keep up the format!
  50. #
  51. #Input weathers for each climate as:
  52. #[symbol,power,season,min duration,max duration,chance,sound,inside sound]
  53. #    Symbol can be: :none, :rain, :snow, or :storm
  54. #    Sound and Inside Sound are: ["Filename",volume,pitch]
  55. #    Season is the name of the season, set to nil to affect all seasons
  56. AC_WEATHERS = { 0 => [
  57.       [:none, 0, nil, 6000, 12000, 40, nil, nil],
  58.       [:rain, 5, "Spring", 6000, 12000, 30, ["Rain",100,100], ["Rain",75,100]],
  59.       [:rain, 4, "Summer", 6000, 12000, 30, ["Rain",100,100], ["Rain",75,100]],
  60.       [:rain, 6, "Fall", 6000, 12000, 30, ["Rain",100,100], ["Rain",75,100]],
  61.       [:storm, 6, "Spring", 6000, 12000, 10, ["Storm",100,100], ["Storm",75,100]],
  62.       [:storm, 9, "Summer", 6000, 12000, 10, ["Storm",100,100], ["Storm",75,100]],
  63.       [:snow, 3, "Winter", 6000, 12000, 30, nil, nil],
  64.       [:snow, 9, "Winter", 6000, 12000, 10, nil, nil]
  65.       ],
  66.                 1 => [
  67.       [:none, 0, nil, 6000, 12000, 10, nil, nil],
  68.       [:snow, 3, nil, 6000, 12000, 5, nil, nil],
  69.       [:snow, 9, "Winter", 6000, 12000, 1, nil, nil]
  70.       ]
  71.               }
  72.                  
  73. #Seasons by name
  74. AC_SEASONS = ["Spring","Summer","Fall","Winter"]
  75.  
  76. #Wether weather effects will dim screen or not                  
  77. AC_NODIMNESS = false
  78. #True to have weather effects during battle
  79. AC_BATTLE_WEATHER = true
  80.  
  81. module Climate_Control
  82.  
  83.   def self.init
  84.     $climates = []
  85.     @current_season = 0
  86.     AC_CLIMATES.times {|i| $climates.push(Climate.new(i))}
  87.     @weather_playing = -1
  88.     @still = false
  89.   end
  90.   def self.season
  91.     @current_season = 0 if @current_season == nil
  92.     return AC_SEASONS[@current_season]
  93.   end
  94.   def self.change_season(number)
  95.     @current_season = number
  96.   end
  97.   def self.climate?
  98.     note = $game_map.map_note
  99.     /[C][=](?<climate>\d{1,3})/ =~ note
  100.     return false unless $~
  101.     return $~[1].to_i
  102.   end
  103.   def self.nosound?
  104.     note = $game_map.map_note
  105.     index = note.index("nosound")
  106.     return true unless index.nil?
  107.   end
  108.   def self.inside?
  109.     note = $game_map.map_note
  110.     index = note.index("inside")
  111.     return true unless index.nil?
  112.   end
  113.   def self.update
  114.     return unless SceneManager.scene.is_a?(Scene_Map)
  115.     return if @still
  116.     $climates.each {|climate| climate.update}
  117.     return unless climate?
  118.     return if @weather_playing == $climates[climate?].current_weather
  119.     auto_change_weather
  120.   end
  121.   def self.auto_change_weather(from_map = 120)
  122.     clear unless climate?
  123.     return unless climate?
  124.     @weather_playing = $climates[climate?].current_weather
  125.     play_audio unless nosound?
  126.     clear if inside?
  127.     return if inside?
  128.     play_weather($climates[climate?].symbol,$climates[climate?].power,from_map)
  129.   end
  130.   def self.clear
  131.     play_weather(:none,0,0)
  132.   end
  133.   def self.play_weather(symbol,power,duration = 120)
  134.     $game_map.screen.change_weather(symbol,power,duration)
  135.   end
  136.   def self.play_audio
  137.     audio = $climates[climate?].sound
  138.     audio = $climates[climate?].isound if inside?
  139.     if audio.nil?
  140.       if $game_map.autoplay_bgs
  141.         return $game_map.autoplay
  142.       else
  143.         return Audio.bgs_stop
  144.       end
  145.     end
  146.     Audio.bgs_play('Audio/BGS/' + audio[0], audio[1], audio[2])
  147.   end
  148.   def self.change_weather(weather,duration = nil,climate = nil)
  149.     climate = climate? if climate.nil?
  150.     if weather.is_a?(Integer)
  151.       $climates[climate].current_weather = weather
  152.     elsif weather.is_a?(Symbol)
  153.       type = $climates[climate?].weather
  154.       type.size.times do |i|
  155.         $climates[climate].current_weather = i if weather == type[i].symbol
  156.       end
  157.     end
  158.     $climates[climate?].duration = duration unless duration.nil?
  159.    end
  160.    def self.still(set)
  161.      @still = set
  162.    end
  163.    def self.current_weather
  164.      return @weather_playing
  165.    end
  166.  
  167.    
  168.   class Climate
  169.    
  170.     attr_accessor :weather
  171.     attr_accessor :current_weather
  172.     attr_accessor :duration
  173.    
  174.     def initialize(id)
  175.       @duration = 0
  176.       @current_weather = 0
  177.       @id = id
  178.       @weather = []
  179.       wth = AC_WEATHERS[id]
  180.       wth.size.times do |i|
  181.         @weather.push(Weather.new(wth[i][0],wth[i][1],wth[i][2],wth[i][3],
  182.                                   wth[i][4],wth[i][5],wth[i][6],wth[i][7])) end
  183.                                 end
  184.     def update
  185.       @duration -= 1
  186.       return unless @duration < 1
  187.       new_weather
  188.     end
  189.     def new_weather
  190.       ran = []
  191.       @weather.size.times do |i|
  192.         next if @weather[i].season != nil and @weather[i].season != Climate_Control.season
  193.         @weather[i].chance.times {|q| ran.push(i)} end
  194.       @current_weather = ran[rand(ran.size)]
  195.       dmax = @weather[@current_weather].dmin
  196.       dmin = @weather[@current_weather].dmax
  197.       @duration = rand(dmax - dmin) + dmin
  198.     end
  199.     def symbol
  200.       return @weather[@current_weather].symbol
  201.     end
  202.     def power
  203.       return @weather[@current_weather].power
  204.     end
  205.     def sound
  206.       return @weather[@current_weather].sound
  207.     end
  208.     def isound
  209.       return @weather[@current_weather].isound
  210.     end
  211.   end        
  212.  
  213.   class Weather
  214.    
  215.     attr_accessor   :symbol
  216.     attr_accessor   :season
  217.     attr_accessor   :power
  218.     attr_accessor   :dmin
  219.     attr_accessor   :dmax
  220.     attr_accessor   :chance
  221.     attr_accessor   :sound
  222.     attr_accessor   :isound
  223.    
  224.     def initialize(symbol,power,season,dmin,dmax,chance,sound,isound)
  225.       @symbol = symbol
  226.       @season = season
  227.       @power = power
  228.       @dmin = dmin
  229.       @dmax = dmax
  230.       @chance = chance
  231.       @sound = sound
  232.       @isound = isound
  233.     end
  234.   end
  235.  
  236. end
  237.  
  238. class Game_Map
  239.   def map_note
  240.     return @map.note unless @map.nil?
  241.   end
  242.   def autoplay_bgs
  243.     return @map.autoplay_bgs
  244.   end
  245. end
  246.  
  247. class Scene_Map
  248.   alias climate_update update
  249.   alias climate_post_transfer post_transfer
  250.   def update
  251.     climate_update
  252.     Climate_Control.update
  253.   end
  254.   def post_start
  255.     Climate_Control.init if $climates.nil?
  256.     Climate_Control.auto_change_weather
  257.     super
  258.   end
  259.   def post_transfer
  260.     Climate_Control.auto_change_weather(0)
  261.     climate_post_transfer
  262.   end
  263. end
  264.  
  265. class Scene_Battle
  266.   alias weather_start create_spriteset
  267.   alias weather_update update_basic
  268.   alias weather_dispose terminate
  269.   def create_spriteset
  270.     weather_start
  271.     @weather = Spriteset_Weather.new(@spriteset.viewport3) if AC_BATTLE_WEATHER
  272.   end
  273.   def update_basic
  274.     weather_update
  275.     update_weather unless @weather.nil?
  276.   end
  277.   def update_weather
  278.     @weather.type = $game_map.screen.weather_type
  279.     @weather.power = $game_map.screen.weather_power
  280.     @weather.ox = $game_map.display_x * 32
  281.     @weather.oy = $game_map.display_y * 32
  282.     @weather.update
  283.   end
  284.   def terminate
  285.     weather_dispose
  286.     @weather.dispose unless @weather.nil?
  287.   end
  288. end
  289.  
  290. class Spriteset_Battle
  291.  
  292.   attr_accessor   :viewport3
  293.  
  294. end
  295.  
  296. class Spriteset_Weather
  297.   def dimness
  298.     return 0 if AC_NODIMNESS
  299.     (@power * 6).to_i
  300.   end
  301. end
  302.  
  303. module DataManager
  304.   class << self
  305.   alias climate_msc make_save_contents
  306.   alias climate_esc extract_save_contents
  307.   end
  308.   def self.make_save_contents
  309.     contents = climate_msc
  310.     contents[:climate] = $climates
  311.     contents
  312.   end
  313.   def self.extract_save_contents(contents)
  314.     climate_esc(contents)
  315.     $climates = contents[:climate]
  316.   end
  317. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement