module CCTS
Climates = 10 # The quantity of climates. Count them correctly or expect errors.
def self.child_of(climate_id)
# Define here which climates are linked to the parent ones.
# For example, climate "Snow Indoor" have the same weather as "Snow Outdoor".
# This is to make the BGS change when the player travels from indoor of one climate to another.
# Pattern: when CHILD_CLIMATE then return PARENT_CLIMATE
# The index of CHILD_CLIMATE must be HIGHER than PARENT_CLIMATE.
case climate_id
when 1 then return 0 # Normal Indoor (1) is a child of Normal Outdoor (0)
when 7 then return 2 # Snow Indoor (7) is a child of Snow Outdoor (2)
when 8 then return 3 # Desert Indoor (8) is a child of Desert Outdoor (3)
when 9 then return 0 # No-Tint Indoor (9) is a child of Normal Outdoor
end
return -1 # When the climate has no parent.
end
def self.weather_prob(climate_id, month)
# This is the module from the CCTS config. Works same as there. You can delete this part of Config
# in your client scripts since the script won't be using it anymore.
# If a climate has a parent one (see above), you don't have to include its number here.
case climate_id
when 0 # Normal Outdoor
case month
# Winter
when 1, 2, 12
return [[3, 17], [16, 12]]
# Spring
when 3, 4, 5
return [[1, 30], [2, 25], [4, 5], [5, 25], [9, 10]]
# Summer
when 6, 7, 8
return [[1, 15], [2, 7], [5, 11], [9, 10]]
# Autumn
when 9, 10, 11
return [[1, 15], [5, 10], [9, 10]]
end
when 2 # Snow/Arctic (year-round, no month branching)
return [[3, 80], [16, 50]]
when 3 # Desert (year-round, no month branching)
return [[1, 5]]
when 6 # Forest (when there are trees, you can see the "leaf" weather)
case month
when 1, 2, 12
return [[3, 13], [16, 9]]
when 3, 4, 5
return [[1, 30], [2, 25], [4, 5], [5, 25], [9, 10]]
when 6, 7, 8
return [[1, 15], [2, 7], [5, 11], [6, 15], [7, 15], [8, 15], [9, 10]]
when 9, 10, 11
return [[1, 15], [5, 10], [6, 25, rand(2)+1], [7, 25, rand(2)+1], [8, 25, rand(2)+1]]
end
end
end
end
module RMXOS
def self.load_current_extension
return GlobalWeather
end
end
#======================================================================
# module GlobalWeather
#======================================================================
module GlobalWeather
VERSION = 0.90
RMXOS_VERSION = 1.13
SERVER_THREAD = true
# START Configuration
WEATHER_MIN = 120 # the minimum time after which the weather is updated
WEATHER_MAX = 360 # the maximum time.
SERVER_MESSAGES = 3
# 0 - no messages
# 1 - informing about weather update,
# 2 - informing about the update and sending to clients
# 3 - informing about the update, the updated weather value and sending to clients
# END Configuration
def self.initialize
@client_times = {}
@climate_update = 0
@climate_weather = []
@weather_interval = 240 # starting value.
end
def self.main
while RMXOS.server.running
self.server_update
sleep(0.1)
end
end
def self.server_update
time = Time.now
if (time - @climate_update).to_i > @weather_interval
print("\nWeather update initialized...\n") if SERVER_MESSAGES > 0
for i in 0...CCTS::Climates
self.update_weather(i)
end
@weather_interval = WEATHER_MIN + rand(WEATHER_MAX - WEATHER_MIN)
@climate_update = Time.now
client.sender.send_to_all("WEC")
end
end
def self.client_update(client)
case client.message
when /\AWER(.+)/ # WEather Request. Not a rocket science.
self.send_weather(client,$1.to_i)
end
return false
end
def self.send_weather(client, climate)
begin
weather = @climate_weather[climate]
client.send("WEA\t#{weather[0]}\t#{weather[1]}\t#{weather[2]}\t#{weather[3]}")
print ("Sent weather #{weather} to client #{client.player.username}\n") if SERVER_MESSAGES > 1
@client_times[client] = time
rescue
@client_times.delete(client)
end
end
def self.update_weather(climate_id)
parent = CCTS.child_of(climate_id)
if parent != (-1)
@climate_weather[climate_id] = @climate_weather[parent]
return
end
time = Time.now
chance = rand(100) + 1
month = time.month
climate_weather = CCTS.weather_prob(climate_id, month)
type, power, transition, variation = 0, 0, 0, 0
return if climate_weather == nil
climate_weather.each_index {|i|
climate_weather[i] = nil unless chance <= climate_weather[i][1]}
climate_weather.compact!
unless climate_weather.empty?
r = rand(climate_weather.size)
type = climate_weather[r][0]
if climate_weather[r][2] != nil
variation = climate_weather[r][2]
end
end
power = rand(50) + 1
transition = rand(120) + 160
@climate_weather[climate_id] = [type, power, transition, variation]
print("Updated climate #{climate_id} weather to #{@climate_weather[climate_id]}.\n") if SERVER_MESSAGES > 2
end
end