Skip to content

Commit

Permalink
blackbox: Record biohazard pop at intervals. (#26930)
Browse files Browse the repository at this point in the history
* blackbox: Record biohazard pop at intervals.

* associative fine here

* don't use recursive timer callbacks
  • Loading branch information
warriorstar-orion authored Oct 22, 2024
1 parent b066c95 commit f27feae
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
5 changes: 5 additions & 0 deletions code/__DEFINES/antag_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,8 @@ GLOBAL_LIST(contractors)

// Chance that a traitor will receive a 'You are being targeted by another syndicate agent' notification regardless of being an actual target
#define ORG_PROB_PARANOIA 5

/// How often a biohazard's population is recorded after the event fires.
#define BIOHAZARD_POP_INTERVAL 5 MINUTES
/// The string version of the interval for use in blackbox key names.
#define BIOHAZARD_POP_INTERVAL_STR "5min"
41 changes: 35 additions & 6 deletions code/controllers/subsystem/SSticker.dm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ SUBSYSTEM_DEF(ticker)
var/datum/scoreboard/score = null
/// List of ckeys who had antag rolling issues flagged
var/list/flagged_antag_rollers = list()
/// List of biohazards keyed to the last time their population was sampled.
var/list/biohazard_pop_times = list()

/datum/controller/subsystem/ticker/Initialize()
login_music = pick(\
Expand Down Expand Up @@ -112,6 +114,10 @@ SUBSYSTEM_DEF(ticker)
delay_end = FALSE // reset this in case round start was delayed
mode.process()

for(var/biohazard in biohazard_pop_times)
if(world.time - biohazard_pop_times[biohazard] > BIOHAZARD_POP_INTERVAL)
sample_biohazard_population(biohazard)

if(world.time > next_autotransfer)
SSvote.start_vote(new /datum/vote/crew_transfer)
next_autotransfer = world.time + GLOB.configuration.vote.autotransfer_interval_time
Expand Down Expand Up @@ -829,22 +835,45 @@ SUBSYSTEM_DEF(ticker)
continue
.++

/// Return whether or not a given biohazard is an active threat.
/// For blobs, this is simply if there are any overminds left. For terrors and
/// xenomorphs, this is whether they have overwhelming numbers.
/datum/controller/subsystem/ticker/proc/biohazard_active_threat(biohazard)
/datum/controller/subsystem/ticker/proc/sample_biohazard_population(biohazard)
SSblackbox.record_feedback("ledger", "biohazard_pop_[BIOHAZARD_POP_INTERVAL_STR]_interval", biohazard_count(biohazard), biohazard)
biohazard_pop_times[biohazard] = world.time

/// Record the initial time that a biohazard spawned.
/datum/controller/subsystem/ticker/proc/record_biohazard_start(biohazard)
SSblackbox.record_feedback("associative", "biohazard_starts", 1, list("type" = biohazard, "time_ds" = world.time - time_game_started))
sample_biohazard_population(biohazard)

/datum/controller/subsystem/ticker/proc/biohazard_count(biohazard)
switch(biohazard)
if(TS_INFESTATION_GREEN_SPIDER, TS_INFESTATION_WHITE_SPIDER, TS_INFESTATION_PRINCESS_SPIDER, TS_INFESTATION_QUEEN_SPIDER)
var/spiders = 0
for(var/mob/living/simple_animal/hostile/poison/terror_spider/S in GLOB.ts_spiderlist)
if(S.ckey)
spiders++
return spiders >= 5
return spiders
if(TS_INFESTATION_PRINCE_SPIDER)
return length(GLOB.ts_spiderlist)
if(BIOHAZARD_XENO)
return count_xenomorps() > 5
return count_xenomorps()
if(BIOHAZARD_BLOB)
return length(SSticker.mode.blob_overminds)

CRASH("biohazard_count got unexpected [biohazard]")

/// Return whether or not a given biohazard is an active threat.
/// For blobs, this is simply if there are any overminds left. For terrors and
/// xenomorphs, this is whether they have overwhelming numbers.
/datum/controller/subsystem/ticker/proc/biohazard_active_threat(biohazard)
var/count = biohazard_count(biohazard)
switch(biohazard)
if(TS_INFESTATION_GREEN_SPIDER, TS_INFESTATION_WHITE_SPIDER, TS_INFESTATION_PRINCESS_SPIDER, TS_INFESTATION_QUEEN_SPIDER)
return count >= 5
if(TS_INFESTATION_PRINCE_SPIDER)
return count > 0
if(BIOHAZARD_XENO)
return count > 5
if(BIOHAZARD_BLOB)
return count > 0

return FALSE
3 changes: 2 additions & 1 deletion code/modules/events/alien_infestation.dm
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@

spawncount--
successSpawn = TRUE
SSevents.biohazards_this_round += "Xenomorphs"
SSticker.record_biohazard_start(BIOHAZARD_XENO)
SSevents.biohazards_this_round += BIOHAZARD_XENO
2 changes: 1 addition & 1 deletion code/modules/events/blob_spawn.dm
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
to_chat(B, "<span class='motd'>For more information, check the wiki page: ([GLOB.configuration.url.wiki_url]/index.php/Blob)</span>")
notify_ghosts("Infected Mouse has appeared in [get_area(B)].", source = B, action = NOTIFY_FOLLOW)
successSpawn = TRUE
SSevents.biohazards_this_round += "Blob"
SSevents.biohazards_this_round += BIOHAZARD_BLOB
1 change: 1 addition & 0 deletions code/modules/events/spider_terror.dm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
S.give_intro_text()
spawncount--
successSpawn = TRUE
SSticker.record_biohazard_start(infestation_type)
SSevents.biohazards_this_round += infestation_type

#undef TS_HIGHPOP_TRIGGER
2 changes: 2 additions & 0 deletions code/modules/mob/living/simple_animal/friendly/mouse.dm
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@
if(!gibbed)
gib()

SSticker.record_biohazard_start(BIOHAZARD_BLOB)

/mob/living/simple_animal/mouse/blobinfected/get_scooped(mob/living/carbon/grabber)
to_chat(grabber, "<span class='warning'>You try to pick up [src], but they slip out of your grasp!</span>")
to_chat(src, "<span class='warning'>[src] tries to pick you up, but you wriggle free of their grasp!</span>")
Expand Down

0 comments on commit f27feae

Please sign in to comment.