mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-10 07:41:16 +01:00
21b4095dfd
Upstream 04/17/2026 fixes https://github.com/Bubberstation/Bubberstation/issues/5549 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: tgstation-ci[bot] <179393467+tgstation-ci[bot]@users.noreply.github.com> Co-authored-by: ArcaneMusic <41715314+ArcaneMusic@users.noreply.github.com> Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Co-authored-by: Rhials <28870487+Rhials@users.noreply.github.com> Co-authored-by: rageguy505 <54517726+rageguy505@users.noreply.github.com> Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com> Co-authored-by: Aliceee2ch <160794176+Aliceee2ch@users.noreply.github.com> Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com> Co-authored-by: Tsar-Salat <62388554+Tsar-Salat@users.noreply.github.com> Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com> Co-authored-by: Maxipat <108554989+Maxipat112@users.noreply.github.com> Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: SimplyLogan <47579821+loganuk@users.noreply.github.com> Co-authored-by: loganuk <fakeemail123@aol.com> Co-authored-by: Leland Kemble <70413276+lelandkemble@users.noreply.github.com> Co-authored-by: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com> Co-authored-by: Roxy <75404941+TealSeer@users.noreply.github.com> Co-authored-by: Lucy <lucy@absolucy.moe> Co-authored-by: siliconOpossum <138069572+siliconOpossum@users.noreply.github.com> Co-authored-by: Isratosh <Isratosh@hotmail.com> Co-authored-by: TheRyeGuyWhoWillNowDie <70169560+TheRyeGuyWhoWillNowDie@users.noreply.github.com> Co-authored-by: Neocloudy <88008002+Neocloudy@users.noreply.github.com> Co-authored-by: Alexander V. <volas@ya.ru> Co-authored-by: ElGitificador <168473461+ElGitificador@users.noreply.github.com> Co-authored-by: Twaticus <46540570+Twaticus@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com> Co-authored-by: Cameron Lennox <killer65311@gmail.com> Co-authored-by: Tim <timothymtorres@gmail.com> Co-authored-by: Iamgoofball <iamgoofball@gmail.com> Co-authored-by: Layzu666 <121319428+Layzu666@users.noreply.github.com> Co-authored-by: Arturlang <24881678+Arturlang@users.noreply.github.com> Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com> Co-authored-by: mrmanlikesbt <99309552+mrmanlikesbt@users.noreply.github.com> Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> Co-authored-by: John F. Kennedy <54908920+MacaroniCritter@users.noreply.github.com> Co-authored-by: Cursor <102828457+theselfish@users.noreply.github.com> Co-authored-by: Josh <josh.adam.powell@gmail.com> Co-authored-by: Josh Powell <josh.powell@softwire.com> Co-authored-by: Yobrocharlie <Charliemiller5617@gmail.com> Co-authored-by: Hardly3D <66234359+Hardly3D@users.noreply.github.com> Co-authored-by: shayoki <96078776+shayoki@users.noreply.github.com> Co-authored-by: LT3 <83487515+lessthnthree@users.noreply.github.com>
131 lines
5.1 KiB
Plaintext
131 lines
5.1 KiB
Plaintext
/// Used for all kinds of weather, ex. lavaland ash storms.
|
|
SUBSYSTEM_DEF(weather)
|
|
name = "Weather"
|
|
ss_flags = SS_BACKGROUND
|
|
dependencies = list(
|
|
/datum/controller/subsystem/mapping,
|
|
)
|
|
wait = 10
|
|
runlevels = RUNLEVEL_GAME
|
|
var/list/processing = list()
|
|
var/list/eligible_zlevels = list()
|
|
var/list/next_hit_by_zlevel = list() //Used by barometers to know when the next storm is coming
|
|
|
|
/datum/controller/subsystem/weather/fire(resumed = FALSE)
|
|
// process active weather
|
|
for(var/datum/weather/weather_event as anything in processing)
|
|
if(!length(weather_event.subsystem_tasks) || weather_event.stage != MAIN_STAGE)
|
|
continue
|
|
|
|
if(weather_event.subsystem_tasks[weather_event.task_index] == SSWEATHER_MOBS)
|
|
if(!resumed)
|
|
weather_event.current_mobs = GLOB.mob_living_list.Copy()
|
|
var/list/current_mobs_cache = weather_event.current_mobs // cache for performance
|
|
while(current_mobs_cache.len)
|
|
var/mob/living/target = current_mobs_cache[current_mobs_cache.len]
|
|
current_mobs_cache.len--
|
|
if(QDELETED(target))
|
|
continue
|
|
if(weather_event.can_weather_act_mob(target))
|
|
weather_event.weather_act_mob(target)
|
|
if(MC_TICK_CHECK)
|
|
return
|
|
resumed = FALSE
|
|
weather_event.task_index = WRAP_UP(weather_event.task_index, weather_event.subsystem_tasks.len)
|
|
|
|
if(weather_event.subsystem_tasks[weather_event.task_index] == SSWEATHER_TURFS)
|
|
if(!resumed)
|
|
weather_event.turf_iteration = ROUND_PROB(weather_event.weather_turfs_per_tick)
|
|
while(weather_event.turf_iteration)
|
|
weather_event.turf_iteration--
|
|
var/turf/selected_turf = weather_event.pick_turf()
|
|
if(selected_turf && weather_event.can_weather_act_turf(selected_turf))
|
|
weather_event.weather_act_turf(selected_turf)
|
|
if(MC_TICK_CHECK)
|
|
return
|
|
resumed = FALSE
|
|
weather_event.task_index = WRAP_UP(weather_event.task_index, weather_event.subsystem_tasks.len)
|
|
|
|
if(weather_event.subsystem_tasks[weather_event.task_index] == SSWEATHER_THUNDER)
|
|
if(!resumed)
|
|
weather_event.thunder_iteration = ROUND_PROB(weather_event.thunder_turfs_per_tick)
|
|
while(weather_event.thunder_iteration)
|
|
weather_event.thunder_iteration--
|
|
var/turf/selected_turf = weather_event.pick_turf()
|
|
if(selected_turf && weather_event.can_weather_act_turf(selected_turf))
|
|
weather_event.thunder_act_turf(selected_turf)
|
|
if(MC_TICK_CHECK)
|
|
return
|
|
resumed = FALSE
|
|
weather_event.task_index = WRAP_UP(weather_event.task_index, weather_event.subsystem_tasks.len)
|
|
|
|
// start random weather on relevant levels
|
|
for(var/z in eligible_zlevels)
|
|
var/possible_weather = eligible_zlevels[z]
|
|
var/datum/weather/weather_event = pick_weight(possible_weather)
|
|
run_weather(weather_event, list(text2num(z)))
|
|
eligible_zlevels -= z
|
|
var/randTime = rand(5 MINUTES, 10 MINUTES)
|
|
next_hit_by_zlevel["[z]"] = addtimer(CALLBACK(src, PROC_REF(make_eligible), z, possible_weather), randTime + initial(weather_event.weather_duration_upper), TIMER_UNIQUE|TIMER_STOPPABLE)
|
|
|
|
/datum/controller/subsystem/weather/Initialize()
|
|
for(var/V in subtypesof(/datum/weather))
|
|
var/datum/weather/W = V
|
|
var/probability = initial(W.probability)
|
|
var/target_trait = initial(W.target_trait)
|
|
|
|
// any weather with a probability set may occur at random
|
|
if (probability)
|
|
for(var/z in SSmapping.levels_by_trait(target_trait))
|
|
LAZYINITLIST(eligible_zlevels["[z]"])
|
|
eligible_zlevels["[z]"][W] = probability
|
|
return SS_INIT_SUCCESS
|
|
|
|
/datum/controller/subsystem/weather/proc/update_z_level(datum/space_level/level)
|
|
var/z = level.z_value
|
|
for(var/datum/weather/weather as anything in subtypesof(/datum/weather))
|
|
var/probability = initial(weather.probability)
|
|
var/target_trait = initial(weather.target_trait)
|
|
if(probability && level.traits[target_trait])
|
|
LAZYINITLIST(eligible_zlevels["[z]"])
|
|
eligible_zlevels["[z]"][weather] = probability
|
|
|
|
/datum/controller/subsystem/weather/proc/run_weather(datum/weather/weather_datum_type, z_levels, list/weather_data)
|
|
if (istext(weather_datum_type))
|
|
for (var/V in subtypesof(/datum/weather))
|
|
var/datum/weather/W = V
|
|
if (initial(W.name) == weather_datum_type)
|
|
weather_datum_type = V
|
|
break
|
|
if (!ispath(weather_datum_type, /datum/weather))
|
|
CRASH("run_weather called with invalid weather_datum_type: [weather_datum_type || "null"]")
|
|
|
|
if (isnull(z_levels))
|
|
z_levels = SSmapping.levels_by_trait(initial(weather_datum_type.target_trait))
|
|
else if (isnum(z_levels))
|
|
z_levels = list(z_levels)
|
|
else if (!islist(z_levels))
|
|
CRASH("run_weather called with invalid z_levels: [z_levels || "null"]")
|
|
|
|
|
|
var/datum/weather/W = new weather_datum_type(z_levels, weather_data)
|
|
W.telegraph(weather_data)
|
|
return W
|
|
|
|
/datum/controller/subsystem/weather/proc/make_eligible(z, possible_weather)
|
|
eligible_zlevels[z] = possible_weather
|
|
next_hit_by_zlevel["[z]"] = null
|
|
|
|
/datum/controller/subsystem/weather/proc/get_weather(z, area/active_area)
|
|
var/datum/weather/A
|
|
for(var/V in processing)
|
|
var/datum/weather/W = V
|
|
if((z in W.impacted_z_levels) && istype(active_area, W.area_type)) // BUBBER EDIT: This proc was broken, fixed to now use istype.
|
|
A = W
|
|
break
|
|
return A
|
|
|
|
///Returns an active storm by its type
|
|
/datum/controller/subsystem/weather/proc/get_weather_by_type(type)
|
|
return locate(type) in processing
|