From 6924849609e3f22f0ece0bcb5111aa8def3d3272 Mon Sep 17 00:00:00 2001 From: CRITAWAKETS Date: Mon, 31 Jan 2022 18:21:35 -0500 Subject: [PATCH] Turns the gas analyzer's environment scanning into a component. (#64264) Componentizes the gas analyzer's environmental scanning behavior into a component registered on to COMSIG_ITEM_ATTACK_SELF. --- code/datums/components/atmospheric_scanner.dm | 58 +++++++++++++++++++ code/game/objects/items/devices/scanners.dm | 46 ++------------- tgstation.dme | 1 + 3 files changed, 63 insertions(+), 42 deletions(-) create mode 100644 code/datums/components/atmospheric_scanner.dm diff --git a/code/datums/components/atmospheric_scanner.dm b/code/datums/components/atmospheric_scanner.dm new file mode 100644 index 00000000000..f33a941e8bf --- /dev/null +++ b/code/datums/components/atmospheric_scanner.dm @@ -0,0 +1,58 @@ +///Items with this component can scan the surrounding atmospherics. +/datum/component/atmospheric_scanner + /// Controls if the analyzer requires being able to see it in order to obtain the results. The value is set in AddComponent. + var/requires_sight = TRUE + +/datum/component/atmospheric_scanner/Initialize(requires_sight) + if(!isitem(parent)) + return COMPONENT_INCOMPATIBLE + if(!isnull(requires_sight)) + src.requires_sight = requires_sight + +/datum/component/atmospheric_scanner/RegisterWithParent() + RegisterSignal(parent, COMSIG_ITEM_ATTACK_SELF, .proc/analyzer_scan) + +/datum/component/atmospheric_scanner/UnregisterFromParent() + UnregisterSignal(parent, COMSIG_ITEM_ATTACK_SELF) + +/datum/component/atmospheric_scanner/proc/analyzer_scan(datum/source, mob/user) + SIGNAL_HANDLER + if (requires_sight && (user.stat != CONSCIOUS || user.is_blind())) //check if it requires visibility and if the user is you know, blind. + to_chat(user, span_warning("You're unable to see [parent]'s results!")) + return + + var/turf/location = user.loc + if(!istype(location)) + return + + var/render_list = list() + var/datum/gas_mixture/environment = location.return_air() + var/pressure = environment.return_pressure() + var/total_moles = environment.total_moles() + + render_list += "[span_info("Results:")]\ + \nPressure: [round(pressure, 0.01)] kPa\n" + if(total_moles) + var/list/env_gases = environment.gases + + environment.assert_gases(arglist(GLOB.hardcoded_gases)) + var/o2_concentration = env_gases[/datum/gas/oxygen][MOLES]/total_moles + var/n2_concentration = env_gases[/datum/gas/nitrogen][MOLES]/total_moles + var/co2_concentration = env_gases[/datum/gas/carbon_dioxide][MOLES]/total_moles + var/plasma_concentration = env_gases[/datum/gas/plasma][MOLES]/total_moles + + render_list += "Nitrogen: [round(n2_concentration*100, 0.01)] % ([round(env_gases[/datum/gas/nitrogen][MOLES], 0.01)] mol)\ + \nOxygen: [round(o2_concentration*100, 0.01)] % ([round(env_gases[/datum/gas/oxygen][MOLES], 0.01)] mol)\ + \nCO2: [round(co2_concentration*100, 0.01)] % ([round(env_gases[/datum/gas/carbon_dioxide][MOLES], 0.01)] mol)\ + \nPlasma: [round(plasma_concentration*100, 0.01)] % ([round(env_gases[/datum/gas/plasma][MOLES], 0.01)] mol)\n" + + environment.garbage_collect() + + for(var/id in env_gases) + if(id in GLOB.hardcoded_gases) + continue + var/gas_concentration = env_gases[id][MOLES]/total_moles + render_list += "[span_alert("[env_gases[id][GAS_META][META_GAS_NAME]]: [round(gas_concentration*100, 0.01)] % ([round(env_gases[id][MOLES], 0.01)] mol)")]\n" + render_list += "[span_info("Temperature: [round(environment.temperature-T0C, 0.01)] °C ([round(environment.temperature, 0.01)] K)")]\n" + // we handled the last
so we don't need handholding + to_chat(user, jointext(render_list, ""), trailing_newline = FALSE, type = MESSAGE_TYPE_INFO) diff --git a/code/game/objects/items/devices/scanners.dm b/code/game/objects/items/devices/scanners.dm index 463a2f120b5..38fbd268587 100644 --- a/code/game/objects/items/devices/scanners.dm +++ b/code/game/objects/items/devices/scanners.dm @@ -577,6 +577,10 @@ GENE SCANNER var/cooldown_time = 250 var/accuracy // 0 is the best accuracy. +/obj/item/analyzer/Initialize(mapload) + . = ..() + AddComponent(/datum/component/atmospheric_scanner, requires_sight = TRUE) + /obj/item/analyzer/examine(mob/user) . = ..() . += span_notice("Alt-click [src] to activate the barometer function.") @@ -585,48 +589,6 @@ GENE SCANNER user.visible_message(span_suicide("[user] begins to analyze [user.p_them()]self with [src]! The display shows that [user.p_theyre()] dead!")) return BRUTELOSS -/obj/item/analyzer/attack_self(mob/user) - add_fingerprint(user) - - if (user.stat || user.is_blind()) - return - - var/turf/location = user.loc - if(!istype(location)) - return - - var/render_list = list() - var/datum/gas_mixture/environment = location.return_air() - var/pressure = environment.return_pressure() - var/total_moles = environment.total_moles() - - render_list += "[span_info("Results:")]\ - \nPressure: [round(pressure, 0.01)] kPa\n" - if(total_moles) - var/list/env_gases = environment.gases - - environment.assert_gases(arglist(GLOB.hardcoded_gases)) - var/o2_concentration = env_gases[/datum/gas/oxygen][MOLES]/total_moles - var/n2_concentration = env_gases[/datum/gas/nitrogen][MOLES]/total_moles - var/co2_concentration = env_gases[/datum/gas/carbon_dioxide][MOLES]/total_moles - var/plasma_concentration = env_gases[/datum/gas/plasma][MOLES]/total_moles - - render_list += "Nitrogen: [round(n2_concentration*100, 0.01)] % ([round(env_gases[/datum/gas/nitrogen][MOLES], 0.01)] mol)\ - \nOxygen: [round(o2_concentration*100, 0.01)] % ([round(env_gases[/datum/gas/oxygen][MOLES], 0.01)] mol)\ - \nCO2: [round(co2_concentration*100, 0.01)] % ([round(env_gases[/datum/gas/carbon_dioxide][MOLES], 0.01)] mol)\ - \nPlasma: [round(plasma_concentration*100, 0.01)] % ([round(env_gases[/datum/gas/plasma][MOLES], 0.01)] mol)\n" - - environment.garbage_collect() - - for(var/id in env_gases) - if(id in GLOB.hardcoded_gases) - continue - var/gas_concentration = env_gases[id][MOLES]/total_moles - render_list += "[span_alert("[env_gases[id][GAS_META][META_GAS_NAME]]: [round(gas_concentration*100, 0.01)] % ([round(env_gases[id][MOLES], 0.01)] mol)")]\n" - render_list += "[span_info("Temperature: [round(environment.temperature-T0C, 0.01)] °C ([round(environment.temperature, 0.01)] K)")]\n" - // we handled the last
so we don't need handholding - to_chat(user, jointext(render_list, ""), trailing_newline = FALSE, type = MESSAGE_TYPE_INFO) - /obj/item/analyzer/AltClick(mob/user) //Barometer output for measuring when the next storm happens ..() diff --git a/tgstation.dme b/tgstation.dme index 1f45bf7de61..18a0dbe48f4 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -655,6 +655,7 @@ #include "code\datums\components\area_sound_manager.dm" #include "code\datums\components\areabound.dm" #include "code\datums\components\armor_plate.dm" +#include "code\datums\components\atmospheric_scanner.dm" #include "code\datums\components\aura_healing.dm" #include "code\datums\components\bakeable.dm" #include "code\datums\components\beetlejuice.dm"