From 672360c48b3e2cb8b8fb1fddd1648c2a04626239 Mon Sep 17 00:00:00 2001 From: Leshana Date: Thu, 9 Mar 2017 19:53:03 -0500 Subject: [PATCH] New Event: Canister Leak Somewhere on the station, a gas canister is faulty and ruptures, releasing its contents (no explosion). * Added as an event_manger event. This version is nice on low severity and picks a canister with nobody nearby. * Also added as a gamemaster event. * Added helper method to check area occupancy. --- code/_helpers/game.dm | 12 ++++++++ code/modules/events/canister_leak.dm | 30 +++++++++++++++++++ .../gamemaster/actions/canister_leak.dm | 24 +++++++++++++++ vorestation.dme | 2 ++ 4 files changed, 68 insertions(+) create mode 100644 code/modules/events/canister_leak.dm create mode 100644 code/modules/gamemaster/actions/canister_leak.dm diff --git a/code/_helpers/game.dm b/code/_helpers/game.dm index 6f6f4f9f0a2..1531a67d5b4 100644 --- a/code/_helpers/game.dm +++ b/code/_helpers/game.dm @@ -43,6 +43,18 @@ if (isarea(A)) return A + +/** Checks if any living humans are in a given area. */ +/proc/area_is_occupied(var/area/myarea) + // Testing suggests looping over human_mob_list is quicker than looping over area contents + for(var/mob/living/carbon/human/H in human_mob_list) + if(H.stat >= DEAD) //Conditions for exclusion here, like if disconnected people start blocking it. + continue + var/area/A = get_area(H) + if(A == myarea) //The loc of a turf is the area it is in. + return 1 + return 0 + /proc/in_range(source, user) if(get_dist(source, user) <= 1) return 1 diff --git a/code/modules/events/canister_leak.dm b/code/modules/events/canister_leak.dm new file mode 100644 index 00000000000..956d8a09404 --- /dev/null +++ b/code/modules/events/canister_leak.dm @@ -0,0 +1,30 @@ +// +// This event chooses a random canister on player levels and breaks it, releasing its contents! +// On severity EVENT_LEVEL_MUNDANE or below it checks to make sure nobody is in the area, otherwise... good luck. +// + +/datum/event/canister_leak/start() + // List of all non-destroyed canisters on station levels + var/list/all_canisters = list() + for(var/obj/machinery/portable_atmospherics/canister/C in machines) + if(!C.destroyed && (C.z in using_map.station_levels)) + all_canisters += C + + for(var/i in 1 to 10) + var/obj/machinery/portable_atmospherics/canister/C = pick(all_canisters) + if(severity <= EVENT_LEVEL_MUNDANE && area_is_occupied(get_area(C))) + log_debug("canister_leak event: Rejecting canister [C] ([C.x],[C.y],[C.z]) because area is occupied") + continue + // Okay lets break it + break_canister(C) + return + + // If we got to here we failed to find it + log_debug("canister_leak event: Giving up after too many failures to pick target canister") + kill() + return + +/datum/event/canister_leak/proc/break_canister(var/obj/machinery/portable_atmospherics/canister/C) + log_debug("canister_leak event: Canister [C] ([C.x],[C.y],[C.z]) destroyed.") + C.health = 0 + C.healthcheck() diff --git a/code/modules/gamemaster/actions/canister_leak.dm b/code/modules/gamemaster/actions/canister_leak.dm new file mode 100644 index 00000000000..ed55c0cded3 --- /dev/null +++ b/code/modules/gamemaster/actions/canister_leak.dm @@ -0,0 +1,24 @@ +// +// This event chooses a random canister on player levels and breaks it, releasing its contents! +// + +/datum/gm_action/canister_leak + name = "Canister Leak" + departments = list(ROLE_ENGINEERING) + chaotic = 20 + +/datum/gm_action/canister_leak/get_weight() + return metric.count_people_in_department(ROLE_ENGINEERING) * 30 + +/datum/gm_action/canister_leak/start() + ..() + // List of all non-destroyed canisters on station levels + var/list/all_canisters = list() + for(var/obj/machinery/portable_atmospherics/canister/C in machines) + if(!C.destroyed && (C.z in using_map.station_levels)) + all_canisters += C + var/obj/machinery/portable_atmospherics/canister/C = pick(all_canisters) + log_debug("canister_leak event: Canister [C] ([C.x],[C.y],[C.z]) destroyed.") + C.health = 0 + C.healthcheck() + return diff --git a/vorestation.dme b/vorestation.dme index a3378dab18c..fbb2c50eb51 100644 --- a/vorestation.dme +++ b/vorestation.dme @@ -1395,6 +1395,7 @@ #include "code\modules\events\blob.dm" #include "code\modules\events\brand_intelligence.dm" #include "code\modules\events\camera_damage.dm" +#include "code\modules\events\canister_leak.dm" #include "code\modules\events\carp_migration.dm" #include "code\modules\events\comms_blackout.dm" #include "code\modules\events\communications_blackout.dm" @@ -1454,6 +1455,7 @@ #include "code\modules\gamemaster\game_master.dm" #include "code\modules\gamemaster\helpers.dm" #include "code\modules\gamemaster\actions\action.dm" +#include "code\modules\gamemaster\actions\canister_leak.dm" #include "code\modules\gamemaster\actions\carp_migration.dm" #include "code\modules\gamemaster\actions\comms_blackout.dm" #include "code\modules\gamemaster\actions\dust.dm"