From 6172b075e82ea73f60ce3d839af9bebc81ee8d96 Mon Sep 17 00:00:00 2001 From: mochi Date: Wed, 15 Jul 2020 13:40:23 +0200 Subject: [PATCH] Add near/vis checks, log on event spawn failure --- code/__HELPERS/game.dm | 24 +++++++++++++++++-- .../gamemodes/miniantags/borer/borer_event.dm | 4 ++++ code/modules/events/alien_infestation.dm | 4 ++++ code/modules/events/blob.dm | 4 ++++ code/modules/events/spider_infestation.dm | 4 ++++ code/modules/events/spider_terror.dm | 24 +++++++------------ 6 files changed, 47 insertions(+), 17 deletions(-) diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index 325dbb7ba62..34d36412229 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -517,14 +517,16 @@ proc/pollCandidates(Question, be_special_type, antag_age_check = FALSE, poll_tim * Returns a list of vents that can be used as a potential spawn if they meet the criteria set by the arguments * * Will not include parent-less vents to the returned list. - * Only returns vents in the main station * Arguments: * * unwelded_only - Whether the list should only include vents that are unwelded + * * exclude_mobs_nearby - Whether to exclude vents that are near living mobs regardless of visibility + * * nearby_mobs_range - The range at which to look for living mobs around the vent for the above argument + * * exclude_visible_by_mobs - Whether to exclude vents that are visible to any living mob * * min_network_size - The minimum length (non-inclusive) of the vent's parent network. A smaller number means vents in small networks (Security, Virology) will appear in the list * * station_levels_only - Whether to only consider vents that are in a Z-level with a STATION_LEVEL trait * * z_level - The Z-level number to look for vents in. Defaults to all */ -/proc/get_valid_vent_spawns(unwelded_only = TRUE, min_network_size = 50, station_levels_only = TRUE, z_level = 0) +/proc/get_valid_vent_spawns(unwelded_only = TRUE, exclude_mobs_nearby = FALSE, nearby_mobs_range = world.view, exclude_visible_by_mobs = FALSE, min_network_size = 50, station_levels_only = TRUE, z_level = 0) ASSERT(min_network_size >= 0) ASSERT(z_level >= 0) @@ -542,6 +544,24 @@ proc/pollCandidates(Question, be_special_type, antag_age_check = FALSE, poll_tim continue if(unwelded_only && vent.welded) continue + if(exclude_mobs_nearby) + var/turf/T = get_turf(vent) + var/mobs_nearby = FALSE + for(var/mob/living/M in orange(nearby_mobs_range, T)) + if(!M.is_dead()) + mobs_nearby = TRUE + break + if(mobs_nearby) + continue + if(exclude_visible_by_mobs) + var/turf/T = get_turf(vent) + var/visible_by_mobs = FALSE + for(var/mob/living/M in viewers(world.view, T)) + if(!M.is_dead()) + visible_by_mobs = TRUE + break + if(visible_by_mobs) + continue if(!vent.parent) // This seems to have been an issue in the past, so this is here until it's definitely fixed log_debug("get_valid_vent_spawns(), vent has no parent: [vent], qdeled: [QDELETED(vent)], loc: [vent.loc]") continue diff --git a/code/game/gamemodes/miniantags/borer/borer_event.dm b/code/game/gamemodes/miniantags/borer/borer_event.dm index dcb01518025..b95559b30e7 100644 --- a/code/game/gamemodes/miniantags/borer/borer_event.dm +++ b/code/game/gamemodes/miniantags/borer/borer_event.dm @@ -13,6 +13,10 @@ /datum/event/borer_infestation/announce() if(successSpawn) GLOB.command_announcement.Announce("Unidentified lifesigns detected coming aboard [station_name()]. Secure any exterior access, including ducting and ventilation.", "Lifesign Alert", new_sound = 'sound/AI/aliens.ogg') + else + var/text = "Warning: Could not spawn any mobs for event Borer Infestation" + message_admins(text) + log_adminwarn(text) /datum/event/borer_infestation/start() var/list/vents = get_valid_vent_spawns() diff --git a/code/modules/events/alien_infestation.dm b/code/modules/events/alien_infestation.dm index 51a1536d75d..398d038bdc0 100644 --- a/code/modules/events/alien_infestation.dm +++ b/code/modules/events/alien_infestation.dm @@ -11,6 +11,10 @@ /datum/event/alien_infestation/announce() if(successSpawn) GLOB.event_announcement.Announce("Unidentified lifesigns detected coming aboard [station_name()]. Secure any exterior access, including ducting and ventilation.", "Lifesign Alert", new_sound = 'sound/AI/aliens.ogg') + else + var/text = "Warning: Could not spawn any mobs for event Alien Infestation" + message_admins(text) + log_adminwarn(text) /datum/event/alien_infestation/start() var/list/vents = get_valid_vent_spawns() diff --git a/code/modules/events/blob.dm b/code/modules/events/blob.dm index 573ec182659..1013c4ba4d3 100644 --- a/code/modules/events/blob.dm +++ b/code/modules/events/blob.dm @@ -6,6 +6,10 @@ /datum/event/blob/announce() if(successSpawn) GLOB.event_announcement.Announce("Confirmed outbreak of level 5 biohazard aboard [station_name()]. All personnel must contain the outbreak.", "Biohazard Alert", 'sound/AI/outbreak5.ogg') + else + var/text = "Warning: Could not spawn any mobs for event Blob" + message_admins(text) + log_adminwarn(text) /datum/event/blob/start() processing = FALSE //so it won't fire again in next tick diff --git a/code/modules/events/spider_infestation.dm b/code/modules/events/spider_infestation.dm index 419a4ce10fc..3968f3e8623 100644 --- a/code/modules/events/spider_infestation.dm +++ b/code/modules/events/spider_infestation.dm @@ -13,6 +13,10 @@ GLOBAL_VAR_INIT(sent_spiders_to_station, 0) /datum/event/spider_infestation/announce() if(successSpawn) GLOB.event_announcement.Announce("Unidentified lifesigns detected coming aboard [station_name()]. Secure any exterior access, including ducting and ventilation.", "Lifesign Alert", new_sound = 'sound/AI/aliens.ogg') + else + var/text = "Warning: Could not spawn any mobs for event Spider Infestation" + message_admins(text) + log_adminwarn(text) /datum/event/spider_infestation/start() var/list/vents = get_valid_vent_spawns() diff --git a/code/modules/events/spider_terror.dm b/code/modules/events/spider_terror.dm index c5db5c5ce9e..8ae9dfa09be 100644 --- a/code/modules/events/spider_terror.dm +++ b/code/modules/events/spider_terror.dm @@ -11,9 +11,13 @@ /datum/event/spider_terror/announce() if(successSpawn) GLOB.command_announcement.Announce("Confirmed outbreak of level 3 biohazard aboard [station_name()]. All personnel must contain the outbreak.", "Biohazard Alert", 'sound/effects/siren-spooky.ogg') + else + var/text = "Warning: Could not spawn any mobs for event Terror Spiders" + message_admins(text) + log_adminwarn(text) /datum/event/spider_terror/start() - var/list/vents = get_valid_vent_spawns() + var/list/vents = get_valid_vent_spawns(exclude_visible_by_mobs = TRUE) var/spider_type var/infestation_type = pick(1, 2, 3, 4, 5) switch(infestation_type) @@ -33,18 +37,8 @@ spider_type = /mob/living/simple_animal/hostile/poison/terror_spider/princess spawncount = 2 while(spawncount && length(vents)) - var/obj/vent = pick(vents) - // If the vent we picked has any living mob nearby, just remove it from the list, loop again, and pick something else. - var/turf/T = get_turf(vent) - var/hostiles_present = FALSE - for(var/mob/living/L in viewers(T)) - if(L.stat != DEAD) - hostiles_present = TRUE - break - - vents -= vent - if(!hostiles_present) - new spider_type(vent.loc) - spawncount-- - successSpawn = TRUE + var/obj/vent = pick_n_take(vents) + new spider_type(vent.loc) + spawncount-- + successSpawn = TRUE