mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
Controller with deferrals and SCHECKs to be specific. Won't lag while updating the sun, weather, or temperature. Also moved some vars around. Namely the planet walls are stored on the planet, not in the weather_holder. Planets now have their own turfs, the controller 'gives' them to the planets each cycle if there are any unallocated turfs in the global lists, to avoid iterating over other planets' turfs if you have more than one, then cuts the lists if you were crazy and some turf added some invalid type. This saves us type-checking in the for() loops later to make them crunch faster. The former operation should only happen once at the start of the game (and maybe very rarely when turfs are added/removed from a map during the game). With regards to the temperature updates, rebuilding the zone entirely is an intensive operation. Instead we can use this new cheaty proc to do it from over here. ZAS code outside ZAS oh noooo. Well, the option is to snowflake this case into ZAS which is maybe worse? Only downside to all this is that if you manually set weather and time it might take between 1-60 seconds for the controller to get around to checking if you wanted to update it. That's not that big a deal. If you really want you can now debug that controller and call doWork on it.
67 lines
2.3 KiB
Plaintext
67 lines
2.3 KiB
Plaintext
/datum/weather_holder
|
|
var/datum/planet/our_planet = null
|
|
var/datum/weather/current_weather = null
|
|
var/temperature = T20C
|
|
var/wind_dir = 0
|
|
var/wind_speed = 0
|
|
var/list/allowed_weather_types = list()
|
|
var/list/roundstart_weather_chances = list()
|
|
var/next_weather_shift = null
|
|
|
|
/datum/weather_holder/New(var/source)
|
|
..()
|
|
our_planet = source
|
|
for(var/A in allowed_weather_types)
|
|
var/datum/weather/W = allowed_weather_types[A]
|
|
if(istype(W))
|
|
W.holder = src
|
|
|
|
/datum/weather_holder/proc/change_weather(var/new_weather)
|
|
var/old_light_modifier = null
|
|
if(current_weather)
|
|
old_light_modifier = current_weather.light_modifier // We store the old one, so we can determine if recalculating the sun is needed.
|
|
current_weather = allowed_weather_types[new_weather]
|
|
next_weather_shift = world.time + rand(20, 30) MINUTES
|
|
|
|
update_icon_effects()
|
|
update_temperature()
|
|
if(old_light_modifier && current_weather.light_modifier != old_light_modifier) // Updating the sun should be done sparingly.
|
|
our_planet.update_sun()
|
|
message_admins("[our_planet.name]'s weather is now [new_weather], with a temperature of [temperature]°K ([temperature - T0C]°C | [temperature * 1.8 - 459.67]°F).")
|
|
|
|
/datum/weather_holder/proc/process()
|
|
if(world.time >= next_weather_shift)
|
|
var/new_weather
|
|
if(!current_weather)
|
|
new_weather = pickweight(roundstart_weather_chances)
|
|
else
|
|
new_weather = pickweight(current_weather.transition_chances)
|
|
change_weather(new_weather)
|
|
else
|
|
current_weather.process_effects()
|
|
|
|
/datum/weather_holder/proc/update_icon_effects()
|
|
our_planet.needs_work |= PLANET_PROCESS_WEATHER
|
|
|
|
/datum/weather_holder/proc/update_temperature()
|
|
temperature = Interpolate(current_weather.temp_low, current_weather.temp_high, weight = our_planet.sun_position)
|
|
our_planet.needs_work |= PLANET_PROCESS_TEMP
|
|
|
|
/datum/weather_holder/proc/get_weather_datum(desired_type)
|
|
return allowed_weather_types[desired_type]
|
|
|
|
|
|
/datum/weather
|
|
var/name = "weather base"
|
|
var/icon = 'icons/effects/weather.dmi'
|
|
var/icon_state = null // Icon to apply to turf undergoing weather.
|
|
var/temp_high = T20C
|
|
var/temp_low = T0C
|
|
var/light_modifier = 1.0 // Lower numbers means more darkness.
|
|
var/light_color = null // If set, changes how the day/night light looks.
|
|
var/transition_chances = list() // Assoc list
|
|
var/datum/weather_holder/holder = null
|
|
|
|
/datum/weather/proc/process_effects()
|
|
return
|