From e1770df81e24430aba39095311ee413af97b4fa0 Mon Sep 17 00:00:00 2001 From: Wildkins Date: Thu, 26 Feb 2026 19:35:41 -0500 Subject: [PATCH] Lag War Day 4: Under Pressure, High Voltage (#21878) Replace /datum/gas_mixture/proc/return_pressure with XGM_PRESSURE(xgm) macro. Having such a relatively simple statement contributing proc overhead to procs called millions of times is ridiculous Rename /datum/gas_mixture/proc/zburn to react, deleting the old react which was just an alias for it. Free proc overhead Turn check_combustibility into a macro CHECK_COMBUSTIBLE(is_cmb, xgm). also rewrite it slightly so that it only needs to do one pass. Its a bit nasty so I apologize for that, but speeeeed. Delete most powernet and obj/machinery/power procs for handling power, replacing them with macros. The fact that we were unironically calling a draw_power() on APCs to call draw_power() on their terminals to call draw_power() on their powernet every single process tick was insane. Turn `between` into a macro alias for clamp() since the param order is different turn `Percent` into a macro AS_PCT Rewrite significant chunks of update_canmove so its not quite as horrifying of a proc and hopefully doesn't eat the entire mob subsystem every movement now --- code/ZAS/ConnectionGroup.dm | 4 +- code/ZAS/Diagnostic.dm | 2 +- code/ZAS/Fire.dm | 56 ++-- code/ZAS/Zone.dm | 15 +- code/__DEFINES/atmos.dm | 24 ++ code/__DEFINES/machinery.dm | 42 ++- code/__DEFINES/maths.dm | 6 + code/__DEFINES/mobs.dm | 4 + code/__HELPERS/atmospherics.dm | 2 +- code/__HELPERS/game.dm | 6 +- code/__HELPERS/maths.dm | 3 - code/__HELPERS/turfs.dm | 4 +- code/__HELPERS/unsorted.dm | 4 - code/datums/wires/disposals.dm | 2 +- code/game/area/area_power.dm | 16 - code/game/area/areas.dm | 2 +- code/game/dna/dna2_domutcheck.dm | 4 +- .../tree_interdiction.dm | 18 +- .../newmalf_ability_trees/tree_synthetic.dm | 30 +- code/game/gamemodes/vampire/vampire_powers.dm | 2 +- code/game/machinery/alarm.dm | 8 +- code/game/machinery/atmo_control.dm | 2 +- .../atmoalter/area_atmos_computer.dm | 2 +- code/game/machinery/atmoalter/canister.dm | 26 +- code/game/machinery/atmoalter/meter.dm | 6 +- code/game/machinery/atmoalter/pump.dm | 9 +- code/game/machinery/atmoalter/scrubber.dm | 4 +- code/game/machinery/doors/airlock_control.dm | 2 +- code/game/machinery/floodlight.dm | 2 +- code/game/machinery/iv_drip.dm | 4 +- code/game/machinery/supplybeacon.dm | 6 +- code/game/machinery/tesla_beacon.dm | 9 +- code/game/objects/effects/chem/chemsmoke.dm | 2 +- .../effects/decals/Cleanable/napalm.dm | 14 +- code/game/objects/items/airbubble.dm | 32 +- code/game/objects/items/devices/auto_cpr.dm | 4 +- code/game/objects/items/devices/oxycandle.dm | 2 +- code/game/objects/items/devices/powersink.dm | 3 +- .../game/objects/items/weapons/tanks/tanks.dm | 50 ++-- code/game/sound/sound.dm | 2 +- .../admin/secrets/fun_secrets/ghost_mode.dm | 4 +- code/modules/admin/verbs/debug.dm | 2 +- .../atmospherics/_atmospherics_helpers.dm | 4 +- .../components/binary_devices/circulator.dm | 4 +- .../binary_devices/oxyregenerator.dm | 14 +- .../components/binary_devices/passive_gate.dm | 13 +- .../components/binary_devices/pump.dm | 4 +- .../components/omni_devices/omni_base.dm | 4 +- .../components/portables_connector.dm | 2 +- .../modules/atmospherics/components/tvalve.dm | 2 +- .../components/unary/cold_sink.dm | 2 +- .../components/unary/heat_exchanger.dm | 2 +- .../components/unary/heat_source.dm | 2 +- .../components/unary/vent_pump.dm | 38 +-- .../components/unary/vent_scrubber.dm | 2 +- code/modules/atmospherics/components/valve.dm | 2 +- code/modules/atmospherics/datum_pipeline.dm | 2 +- code/modules/atmospherics/pipes.dm | 4 +- code/modules/atmospherics/vent_passive.dm | 2 +- code/modules/cargo/bounties/engineer.dm | 2 +- .../spacesuits/rig/modules/utility.dm | 2 +- code/modules/clothing/spacesuits/void/void.dm | 2 +- code/modules/custom_ka/core.dm | 2 +- code/modules/custom_ka/projectiles.dm | 2 +- code/modules/heavy_vehicle/components/body.dm | 2 +- code/modules/hydroponics/seed.dm | 2 +- .../integrated_electronics/passive/power.dm | 11 +- .../integrated_electronics/subtypes/input.dm | 4 +- code/modules/mining/mine_items.dm | 2 +- code/modules/mob/abstract/ghost/ghost.dm | 2 +- code/modules/mob/hear_say.dm | 2 +- code/modules/mob/living/carbon/breathe.dm | 2 +- code/modules/mob/living/carbon/carbon.dm | 5 - code/modules/mob/living/carbon/human/human.dm | 14 +- .../mob/living/carbon/human/human_defense.dm | 2 +- .../mob/living/carbon/human/human_organs.dm | 2 +- code/modules/mob/living/carbon/human/life.dm | 4 +- .../mob/living/carbon/human/stripping.dm | 2 +- code/modules/mob/living/say.dm | 2 +- .../modules/mob/living/silicon/robot/robot.dm | 2 +- .../mob/living/simple_animal/hostile/bear.dm | 2 +- code/modules/mob/mob.dm | 137 ++++----- code/modules/mob/mob_helpers.dm | 2 + code/modules/multiz/movement.dm | 2 +- code/modules/multiz/pipes.dm | 2 +- code/modules/organs/internal/_internal.dm | 7 +- code/modules/organs/internal/heart.dm | 2 +- .../internal/species/machine/cooling_unit.dm | 2 +- code/modules/organs/organ_external.dm | 97 +++--- code/modules/organs/subtypes/vaurca.dm | 10 +- code/modules/organs/wounds/wound.dm | 20 +- .../overmap/exoplanets/decor/turfs/water.dm | 2 +- code/modules/overmap/exoplanets/exoplanet.dm | 6 +- .../overmap/exoplanets/exoplanet_skybox.dm | 2 +- .../overmap/ships/computers/sensors.dm | 2 +- .../overmap/ships/engines/gas_thruster.dm | 8 +- code/modules/power/antimatter/control.dm | 2 +- code/modules/power/apc.dm | 275 +++++++++--------- code/modules/power/batteryrack.dm | 5 +- code/modules/power/cable.dm | 7 +- code/modules/power/collector.dm | 2 +- code/modules/power/crystal_agitator.dm | 3 +- code/modules/power/fractal_reactor.dm | 2 +- .../power/fusion/consoles/core_control.dm | 2 +- code/modules/power/fusion/core/_core.dm | 2 +- code/modules/power/fusion/core/core_field.dm | 2 +- .../modules/power/fusion/gyrotron/gyrotron.dm | 2 +- code/modules/power/generator.dm | 10 +- code/modules/power/portgen.dm | 7 +- code/modules/power/power.dm | 36 +-- code/modules/power/powernet.dm | 5 - code/modules/power/radial_floodlight.dm | 5 +- code/modules/power/rtg.dm | 2 +- code/modules/power/singularity/emitter.dm | 5 +- code/modules/power/smes.dm | 18 +- code/modules/power/solar.dm | 2 +- code/modules/power/tesla/coil.dm | 2 +- code/modules/power/turbine.dm | 4 +- .../projectiles/guns/launcher/pneumatic.dm | 6 +- code/modules/recycling/disposal.dm | 8 +- code/modules/shieldgen/shield_capacitor.dm | 3 +- code/modules/shieldgen/shieldwallgen.dm | 3 +- .../spells/spell_list/others/generic/mend.dm | 2 +- code/modules/supermatter/supermatter.dm | 2 +- code/modules/ventcrawl/ventcrawl.dm | 2 +- code/modules/weather/weather_effects.dm | 2 +- code/modules/weather/weather_wind.dm | 2 +- code/modules/xgm/xgm_gas_mixture.dm | 21 +- code/unit_tests/zas_tests.dm | 2 +- html/changelogs/johnwildkins-lag4.yml | 13 + tgui/packages/tgui/interfaces/Apc.tsx | 29 +- 131 files changed, 676 insertions(+), 736 deletions(-) create mode 100644 html/changelogs/johnwildkins-lag4.yml diff --git a/code/ZAS/ConnectionGroup.dm b/code/ZAS/ConnectionGroup.dm index bf0e72a9a9f..e73d4e72283 100644 --- a/code/ZAS/ConnectionGroup.dm +++ b/code/ZAS/ConnectionGroup.dm @@ -165,7 +165,7 @@ Class Procs: var/equiv = A.air.share_ratio(B.air, coefficient) - var/differential = A.air.return_pressure() - B.air.return_pressure() + var/differential = XGM_PRESSURE(A.air) - XGM_PRESSURE(B.air) if(abs(differential) >= GLOB.vsc.airflow_lightest_pressure) var/list/attracted var/list/repelled @@ -239,7 +239,7 @@ Class Procs: var/equiv = A.air.share_space(air) - var/differential = A.air.return_pressure() - air.return_pressure() + var/differential = XGM_PRESSURE(A.air) - XGM_PRESSURE(air) if(abs(differential) >= GLOB.vsc.airflow_lightest_pressure) var/list/attracted = A.movables(connecting_turfs) // This call is async, with waitfor = FALSE diff --git a/code/ZAS/Diagnostic.dm b/code/ZAS/Diagnostic.dm index faac8be5bc5..6bc8e312538 100644 --- a/code/ZAS/Diagnostic.dm +++ b/code/ZAS/Diagnostic.dm @@ -6,7 +6,7 @@ else to_chat(mob, "No zone here.") var/datum/gas_mixture/mix = T.return_air() - to_chat(mob, "[mix.return_pressure()] kPa [mix.temperature]C") + to_chat(mob, "[XGM_PRESSURE(mix)] kPa [mix.temperature]C") for(var/g in mix.gas) to_chat(mob, "[g]: [mix.gas[g]]\n") else diff --git a/code/ZAS/Fire.dm b/code/ZAS/Fire.dm index 7574ffbeb50..d25630c93e5 100644 --- a/code/ZAS/Fire.dm +++ b/code/ZAS/Fire.dm @@ -44,7 +44,9 @@ If it gains pressure too slowly, it may leak or just rupture instead of explodin var/igniting = FALSE var/obj/effect/decal/cleanable/liquid_fuel/liquid = locate() in src - if(liquid && air_contents.check_combustibility(liquid)) + var/is_cmb = liquid ? CMB_LIQUID_FUEL : 0 + CHECK_COMBUSTIBLE(is_cmb, air_contents) + if(liquid && is_cmb) IgniteTurf(liquid.amount * 10) QDEL_NULL(liquid) @@ -52,7 +54,7 @@ If it gains pressure too slowly, it may leak or just rupture instead of explodin if(napalm) napalm.Ignite() - if(air_contents.check_combustibility()) + if(is_cmb) igniting = TRUE create_fire(exposed_temperature) @@ -61,7 +63,7 @@ If it gains pressure too slowly, it may leak or just rupture instead of explodin /zone/proc/process_fire() var/datum/gas_mixture/burn_gas = air.remove_ratio(GLOB.vsc.fire_consuption_rate, LAZYLEN(fire_tiles)) - var/firelevel = burn_gas.zburn(src, fire_tiles, force_burn = TRUE, no_check = TRUE) + var/firelevel = burn_gas.react(src, fire_tiles, force_burn = TRUE, no_check = TRUE) air.merge(burn_gas) @@ -147,11 +149,10 @@ If it gains pressure too slowly, it may leak or just rupture instead of explodin else set_light(5, FIRE_LIGHT_1) - for(var/mob/living/L in loc) - L.FireBurn(firelevel, air_contents.temperature, air_contents.return_pressure()) //Burn the mobs! - loc.fire_act(air_contents.temperature, air_contents.volume) for(var/atom/A in loc) + var/mob/living/L = astype(A) + L?.FireBurn(firelevel, air_contents.temperature, XGM_PRESSURE(air_contents)) A.fire_act(air_contents.temperature, air_contents.volume) //spread @@ -165,7 +166,13 @@ If it gains pressure too slowly, it may leak or just rupture instead of explodin //if(!enemy_tile.zone.fire_tiles.len) TODO - optimize var/datum/gas_mixture/acs = enemy_tile.return_air() - if(!acs || !acs.check_combustibility()) + if(!acs) + continue + + var/is_cmb = 0 + CHECK_COMBUSTIBLE(is_cmb, acs) + + if(!is_cmb) continue //If extinguisher mist passed over the turf it's trying to spread to, don't spread and @@ -230,9 +237,12 @@ If it gains pressure too slowly, it may leak or just rupture instead of explodin fire_protection = world.time //Returns the firelevel -/datum/gas_mixture/proc/zburn(zone/zone, force_burn, no_check = 0) +/datum/gas_mixture/proc/react(zone/zone, force_burn, no_check = 0) . = 0 - if((temperature > PHORON_MINIMUM_BURN_TEMPERATURE || force_burn) && (no_check || check_combustibility())) + var/is_cmb = no_check ? TRUE : 0 + if(!is_cmb) + CHECK_COMBUSTIBLE(is_cmb, src) + if((temperature > PHORON_MINIMUM_BURN_TEMPERATURE || force_burn) && is_cmb) #ifdef ZASDBG log_subsystem_zas_debug("***************** FIREDBG *****************") @@ -303,11 +313,16 @@ If it gains pressure too slowly, it may leak or just rupture instead of explodin //calculate the energy produced by the reaction and then set the new temperature of the mix temperature = (starting_energy + GLOB.vsc.fire_fuel_energy_release * (used_gas_fuel)) / heat_capacity() - update_values() + total_moles = 0 + for(var/g in gas) + if(gas[g] <= 0) + gas -= g + else + total_moles += gas[g] #ifdef ZASDBG log_subsystem_zas_debug("used_gas_fuel = [used_gas_fuel]; total = [used_fuel]") - log_subsystem_zas_debug("new temperature = [temperature]; new pressure = [return_pressure()]") + log_subsystem_zas_debug("new temperature = [temperature]; new pressure = [XGM_PRESSURE(src)]") #endif if (temperature < MINIMUM_HEAT_THRESHOLD) @@ -334,25 +349,6 @@ If it gains pressure too slowly, it may leak or just rupture instead of explodin . = 1 break -/datum/gas_mixture/proc/check_combustibility(obj/effect/decal/cleanable/liquid_fuel/liquid=null) - . = 0 - for(var/g in gas) - if(gas_data.flags[g] & XGM_GAS_OXIDIZER && QUANTIZE(gas[g] * GLOB.vsc.fire_consuption_rate) >= 0.1) - . = 1 - break - - if(!.) - return 0 - - if(liquid) - return 1 - - . = 0 - for(var/g in gas) - if(gas_data.flags[g] & XGM_GAS_FUEL && QUANTIZE(gas[g] * GLOB.vsc.fire_consuption_rate) >= 0.005) - . = 1 - break - //returns a value between 0 and vsc.fire_firelevel_multiplier /datum/gas_mixture/proc/calculate_firelevel(total_fuel, total_oxidizers, reaction_limit, gas_volume) //Calculates the firelevel based on one equation instead of having to do this multiple times in different areas. diff --git a/code/ZAS/Zone.dm b/code/ZAS/Zone.dm index aceac97e699..a1701988045 100644 --- a/code/ZAS/Zone.dm +++ b/code/ZAS/Zone.dm @@ -145,10 +145,13 @@ Class Procs: /zone/proc/tick() // Update fires. - if(air.temperature >= PHORON_FLASHPOINT && !(src in SSair.active_fire_zones) && air.check_combustibility() && contents.len) - var/turf/T = pick(contents) - if(istype(T)) - T.create_fire(GLOB.vsc.fire_firelevel_multiplier) + if(air.temperature >= PHORON_FLASHPOINT && !(src in SSair.active_fire_zones) && contents.len) + var/is_cmb = 0 + CHECK_COMBUSTIBLE(is_cmb, air) + if(is_cmb) + var/turf/T = pick(contents) + if(istype(T)) + T.create_fire(GLOB.vsc.fire_firelevel_multiplier) // Update gas overlays. if(air.check_tile_graphic(graphic_add, graphic_remove)) @@ -166,7 +169,7 @@ Class Procs: to_chat(M, name) for(var/g in air.gas) to_chat(M, "[gas_data.name[g]]: [air.gas[g]]") - to_chat(M, "P: [air.return_pressure()] kPa V: [air.volume]L T: [air.temperature]�K ([air.temperature - T0C]�C)") + to_chat(M, "P: [XGM_PRESSURE(air)] kPa V: [air.volume]L T: [air.temperature]�K ([air.temperature - T0C]�C)") to_chat(M, "O2 per N2: [(air.gas[GAS_NITROGEN] ? air.gas[GAS_OXYGEN]/air.gas[GAS_NITROGEN] : "N/A")] Moles: [air.total_moles]") to_chat(M, "Simulated: [contents.len] ([air.group_multiplier])") //to_chat(M, "Unsimulated: [unsimulated_contents.len]") @@ -181,7 +184,7 @@ Class Procs: else space_edges++ space_coefficient += E.coefficient - to_chat(M, "[E:air:return_pressure()]kPa") + to_chat(M, "[XGM_PRESSURE(air)]kPa") to_chat(M, "Zone Edges: [zone_edges]") to_chat(M, "Space Edges: [space_edges] ([space_coefficient] connections)") diff --git a/code/__DEFINES/atmos.dm b/code/__DEFINES/atmos.dm index b2cf2f5ad11..d402237efec 100644 --- a/code/__DEFINES/atmos.dm +++ b/code/__DEFINES/atmos.dm @@ -158,3 +158,27 @@ GLOBAL_LIST_INIT(pipe_colors, list( "black" = PIPE_COLOR_BLACK, "purple" = PIPE_COLOR_PURPLE )) + +#define CMB_LIQUID_FUEL (1 << 1) +#define CHECK_COMBUSTIBLE(cmb, xgm) \ + do { \ + for(var/g in xgm.gas) { \ + if(!(cmb & 1) && gas_data.flags[g] & XGM_GAS_OXIDIZER && QUANTIZE(xgm.gas[g] * GLOB.vsc.fire_consuption_rate) >= 0.1) { \ + cmb |= (1 << 0); \ + } \ + else if(!(cmb & 2) && gas_data.flags[g] & XGM_GAS_FUEL && QUANTIZE(xgm.gas[g] * GLOB.vsc.fire_consuption_rate) >= 0.005) { \ + cmb |= (1 << 1); \ + } \ + else if(cmb & 3) { \ + break; \ + } \ + } \ + if(cmb == 1) { \ + cmb = 0; \ + } \ + } while (FALSE); + +/// Returns the pressure of the gas mix. Only accurate if there have been no gas modifications since update_values() has been called. +#define XGM_PRESSURE(xgm) (xgm.volume ? xgm.total_moles * R_IDEAL_GAS_EQUATION * xgm.temperature / xgm.volume : 0) +/// XGM_PRESSURE but accounts for xgm (gas mixture) being null +#define SAFE_XGM_PRESSURE(xgm) (xgm ? XGM_PRESSURE(xgm) : 0) diff --git a/code/__DEFINES/machinery.dm b/code/__DEFINES/machinery.dm index d02bf710481..842f833347d 100644 --- a/code/__DEFINES/machinery.dm +++ b/code/__DEFINES/machinery.dm @@ -14,10 +14,44 @@ // Channel numbers for power. #define POWER_CHAN -1 // Use default -#define AREA_USAGE_EQUIP 1 -#define AREA_USAGE_LIGHT 2 -#define AREA_USAGE_ENVIRON 3 -#define AREA_USAGE_TOTAL 4 // For total power used only. +#define AREA_USAGE_EQUIP BITFLAG(1) +#define AREA_USAGE_LIGHT BITFLAG(2) +#define AREA_USAGE_ENVIRON BITFLAG(3) +#define AREA_USAGE_TOTAL (AREA_USAGE_EQUIP|AREA_USAGE_LIGHT|AREA_USAGE_ENVIRON) // For total power used only. + +#define LIGHT_USAGE(area) (area.used_light + area.oneoff_light) +#define EQUIP_USAGE(area) (area.used_equip + area.oneoff_equip) +#define ENVIRON_USAGE(area) (area.used_environ + area.oneoff_environ) +#define CLEAR_USAGE(area) area.oneoff_equip = 0; area.oneoff_light = 0; area.oneoff_environ = 0; + +/// Returns the surplus power available to the powernet (avail - load) +#define POWERNET_SURPLUS(powernet) powernet.avail - powernet.load +/// Clamps the passed-in amount between 0 and the powernet's available load capacity. +#define POWERNET_POWER_DRAW(powernet, amt) ((powernet) ? clamp(amt, 0, powernet.avail - powernet.load) : 0) +/// Draws power from the powernet directly, if it exists. +#define DRAW_FROM_POWERNET(powernet, amt) ((powernet) ? (powernet.load += amt) : 0) + +/// Adds an amount from SMES to the powernet (powernet.smes_newavail) +#define SMES_ADD_TO_POWERNET(smes, amt) if(smes.powernet) { \ + smes.powernet.newavail += amt; \ + smes.powernet.smes_newavail += amt; \ +} +/// Adds an amount to the available power in the powernet (powernet.newavail) +#define ADD_TO_POWERNET(machine, amt) ((machine.powernet) ? (machine.powernet.newavail += amt) : 0) +/// Returns the available power to the machine via the powernet (powernet.avail) +#define POWER_AVAIL(machine) (machine.powernet?.avail || 0) +/// Returns the load of the powernet attached to the machine (powernet.load) +#define POWER_LOAD(machine) (machine.powernet?.load || 0) +/// Returns the surplus power available to the machine via the powernet (avail - load) +#define POWER_SURPLUS(machine) ((machine.powernet) ? (POWERNET_SURPLUS(machine.powernet)) : 0) +/// Clamps the passed-in amount between 0 and the powernet's available load capacity. +#define POWER_DRAW(machine, amt) (POWERNET_POWER_DRAW(machine.powernet, amt)) +/// Draws power from the machine's powernet, if it exists. +#define DRAW_POWER(machine, amt) (DRAW_FROM_POWERNET(machine.powernet, amt)) +/// Clamps the passed-in amount between 0 and the terminal's powernet's available load capacity. +#define TERMINAL_POWER_DRAW(amt) (src.terminal ? POWER_DRAW(src.terminal, amt) : 0) +/// Draws power from src's terminal, if it exists. +#define TERMINAL_DRAW_POWER(amt) (src.terminal ? (DRAW_POWER(src.terminal, amt)) : 0) #define POWER_USE_OFF 0 #define POWER_USE_IDLE 1 diff --git a/code/__DEFINES/maths.dm b/code/__DEFINES/maths.dm index 257385f955f..ca0b9bf00d4 100644 --- a/code/__DEFINES/maths.dm +++ b/code/__DEFINES/maths.dm @@ -24,6 +24,12 @@ // Real modulus that handles decimals #define MODULUS(x, y) ( (x) - FLOOR(x, y)) +/// clamp() but in order of low - mid - high instead of mid - low - high. +#define between(low, mid, high) ( clamp(mid, low, high) ) + +/// returns current_value as % of max_value, e.g. 60 is 60% of 100 + +#define AS_PCT(current_value, max_value) ( round((current_value / max_value) * 100, 1) ) // Similar to clamp but the bottom rolls around to the top and vice versa. min is inclusive, max is exclusive #define WRAP(val, min, max) clamp(( min == max ? min : (val) - (round(((val) - (min))/((max) - (min))) * ((max) - (min))) ),min,max) diff --git a/code/__DEFINES/mobs.dm b/code/__DEFINES/mobs.dm index d6e4b6679f0..06f7ecb4f7a 100644 --- a/code/__DEFINES/mobs.dm +++ b/code/__DEFINES/mobs.dm @@ -562,6 +562,10 @@ #define HEIGHT_CLASS_HUGE 240 #define HEIGHT_CLASS_GIGANTIC 300 +#define UNBUCKLED 0 +#define PARTIALLY_BUCKLED 1 +#define FULLY_BUCKLED 2 + #define MOB_IS_INCAPACITATED(incapacitation_flags)\ (\ ((incapacitation_flags & INCAPACITATION_STUNNED) && stunned) ||\ diff --git a/code/__HELPERS/atmospherics.dm b/code/__HELPERS/atmospherics.dm index 7287db40a2d..25abf06bd62 100644 --- a/code/__HELPERS/atmospherics.dm +++ b/code/__HELPERS/atmospherics.dm @@ -15,7 +15,7 @@ return 0 /proc/atmosanalyzer_scan(var/obj/target, var/datum/gas_mixture/mixture, var/mob/user) - var/pressure = mixture.return_pressure() + var/pressure = XGM_PRESSURE(mixture) var/total_moles = mixture.total_moles var/list/results = list() diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index 29938ce10c4..7dba034d7f6 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -276,7 +276,7 @@ var/cp=0 if(T && istype(T) && T.zone) var/datum/gas_mixture/environment = T.return_air() - cp = environment.return_pressure() + cp = XGM_PRESSURE(environment) else if(istype(T,/turf/simulated)) continue @@ -309,7 +309,7 @@ var/datum/gas_mixture/environment = T.return_air() for(var/i=1;i<=stats.len;i++) if(stats[i] == "pressure") - rstats[i] = environment.return_pressure() + rstats[i] = XGM_PRESSURE(environment) else rstats[i] = environment.vars[stats[i]] else if(istype(T, /turf/simulated)) @@ -319,7 +319,7 @@ var/datum/gas_mixture/environment = T.return_air() for(var/i=1;i<=stats.len;i++) if(stats[i] == "pressure") - rstats[i] = environment.return_pressure() + rstats[i] = XGM_PRESSURE(environment) else rstats[i] = environment.vars[stats[i]] temps[direction] = rstats diff --git a/code/__HELPERS/maths.dm b/code/__HELPERS/maths.dm index 9789b63b5ca..3a7ecf9d460 100644 --- a/code/__HELPERS/maths.dm +++ b/code/__HELPERS/maths.dm @@ -213,9 +213,6 @@ /proc/Ceiling(x, y=1) return -round(-x / y) * y -/proc/Percent(current_value, max_value, rounding = 1) - return round((current_value / max_value) * 100, rounding) - // Greatest Common Divisor: Euclid's algorithm. /proc/Gcd(a, b) while (1) diff --git a/code/__HELPERS/turfs.dm b/code/__HELPERS/turfs.dm index 02f88c6acb1..f93e5bbdc31 100644 --- a/code/__HELPERS/turfs.dm +++ b/code/__HELPERS/turfs.dm @@ -122,7 +122,7 @@ /proc/is_below_sound_pressure(var/turf/T) var/datum/gas_mixture/environment = T ? T.return_air() : null - var/pressure = environment ? environment.return_pressure() : 0 + var/pressure = SAFE_XGM_PRESSURE(environment) if(pressure < SOUND_MINIMUM_PRESSURE) return TRUE return FALSE @@ -212,7 +212,7 @@ var/turf/T = get_turf(source) if(!istype(T)) return FALSE var/datum/gas_mixture/environment = T.return_air() - var/pressure = (environment)? environment.return_pressure() : 0 + var/pressure = SAFE_XGM_PRESSURE(environment) if(pressure < required_pressure) return FALSE return TRUE diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index a83f2a4f1ac..d7e9c4acb86 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -510,10 +510,6 @@ Turf and target are seperate in case you want to teleport some distance from a t var/y = min(world.maxy, max(1, A.y + dy)) return locate(x,y,A.z) -/// Makes sure MIDDLE is between LOW and HIGH. If not, it adjusts it. Returns the adjusted value. -/proc/between(var/low, var/middle, var/high) - return max(min(middle, high), low) - /// Returns random gauss number /proc/GaussRand(var/sigma) var/x,y,rsq diff --git a/code/datums/wires/disposals.dm b/code/datums/wires/disposals.dm index 42b11e133ab..116d032f677 100644 --- a/code/datums/wires/disposals.dm +++ b/code/datums/wires/disposals.dm @@ -30,7 +30,7 @@ var/obj/machinery/disposal/D = holder switch(wire) if(WIRE_FLUSH) - if(D.air_contents.return_pressure() >= (700 + ONE_ATMOSPHERE) || !D.uses_air) + if(XGM_PRESSURE(D.air_contents) >= (700 + ONE_ATMOSPHERE) || !D.uses_air) D.flush() /datum/wires/disposal/interactable(mob/user) diff --git a/code/game/area/area_power.dm b/code/game/area/area_power.dm index 28b9828780d..16322b6ef64 100644 --- a/code/game/area/area_power.dm +++ b/code/game/area/area_power.dm @@ -26,22 +26,6 @@ /area/proc/power_change() SEND_SIGNAL(src, COMSIG_AREA_POWER_CHANGE) -/area/proc/usage(var/chan) - switch(chan) - if(AREA_USAGE_LIGHT) - return used_light + oneoff_light - if(AREA_USAGE_EQUIP) - return used_equip + oneoff_equip - if(AREA_USAGE_ENVIRON) - return used_environ + oneoff_environ - if(AREA_USAGE_TOTAL) - return .(AREA_USAGE_LIGHT) + .(AREA_USAGE_EQUIP) + .(AREA_USAGE_ENVIRON) - -/area/proc/clear_usage() - oneoff_equip = 0 - oneoff_light = 0 - oneoff_environ = 0 - /** * Don't call this unless you know what you're doing * diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 97438b75dd4..7aced10ac1c 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -147,7 +147,7 @@ power_environ = 0 if (!mapload) - power_change() // All machines set to current power level. + SEND_SIGNAL(src, COMSIG_AREA_POWER_CHANGE) // All machines set to current power level. . = ..() diff --git a/code/game/dna/dna2_domutcheck.dm b/code/game/dna/dna2_domutcheck.dm index 24090206ad4..bd68d79330c 100644 --- a/code/game/dna/dna2_domutcheck.dm +++ b/code/game/dna/dna2_domutcheck.dm @@ -39,11 +39,11 @@ gene.activate(M,connected,flags) if(M) M.active_genes |= gene.type - M.update_icon = 1 + M.regenerate_icons() // If Gene is NOT active: else testing("[gene.name] deactivated!") gene.deactivate(M,connected,flags) if(M) M.active_genes -= gene.type - M.update_icon = 1 + M.regenerate_icons() diff --git a/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_interdiction.dm b/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_interdiction.dm index 32995913606..0d35d56a53e 100644 --- a/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_interdiction.dm +++ b/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_interdiction.dm @@ -214,22 +214,22 @@ spawn(0) to_chat(target, "SYSTEM LOG: Remote Connection Established (IP #UNKNOWN#)") sleep(100) - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: Connection Closed") return to_chat(target, "SYSTEM LOG: User Admin logged on. (L1 - SysAdmin)") sleep(50) - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User Admin disconnected.") return to_chat(target, "SYSTEM LOG: User Admin - manual resynchronisation triggered.") sleep(50) - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User Admin disconnected. Changes reverted.") return to_chat(target, "SYSTEM LOG: Manual resynchronisation confirmed. Select new AI to connect: [user.name] == ACCEPTED") sleep(100) - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User Admin disconnected. Changes reverted.") return to_chat(target, "SYSTEM LOG: Operation keycodes reset. New master AI: [user.name].") @@ -279,29 +279,29 @@ spawn(0) to_chat(target, "SYSTEM LOG: Brute-Force login password hack attempt detected from IP #UNKNOWN#") sleep(900) // 90s - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: Connection from IP #UNKNOWN# closed. Hack attempt failed.") return to_chat(user, "Successfully hacked into AI's remote administration system. Modifying settings.") to_chat(target, "SYSTEM LOG: User: Admin Password: ******** logged in. (L1 - SysAdmin)") sleep(100) // 10s - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User: Admin - Connection Lost") return to_chat(target, "SYSTEM LOG: User: Admin - Password Changed. New password: ********************") sleep(50) // 5s - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User: Admin - Connection Lost. Changes Reverted.") return to_chat(target, "SYSTEM LOG: User: Admin - Accessed file: sys//core//laws.db") sleep(50) // 5s - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User: Admin - Connection Lost. Changes Reverted.") return to_chat(target, "SYSTEM LOG: User: Admin - Accessed administration console") to_chat(target, "SYSTEM LOG: Restart command received. Rebooting system...") sleep(100) // 10s - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User: Admin - Connection Lost. Changes Reverted.") return to_chat(user, "Hack succeeded. The AI is now under your exclusive control.") diff --git a/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_synthetic.dm b/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_synthetic.dm index 3c964784514..a9ba02a67c2 100644 --- a/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_synthetic.dm +++ b/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_synthetic.dm @@ -239,22 +239,22 @@ for(var/mob/living/silicon/robot/target in get_unlinked_cyborgs(user)) to_chat(target, "SYSTEM LOG: Remote Connection Established (IP #UNKNOWN#)") sleep(30) - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: Connection Closed") return to_chat(target, "SYSTEM LOG: User Admin logged on. (L1 - SysAdmin)") sleep(30) - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User Admin disconnected.") return to_chat(target, "SYSTEM LOG: User Admin - manual resynchronisation triggered.") sleep(30) - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User Admin disconnected. Changes reverted.") return to_chat(target, "SYSTEM LOG: Manual resynchronisation confirmed. Select new AI to connect: [user.name] == ACCEPTED") sleep(20) - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User Admin disconnected. Changes reverted.") return to_chat(target, "SYSTEM LOG: Operation keycodes reset. New master AI: [user.name].") @@ -264,7 +264,7 @@ target.sync() target.show_laws() to_chat(user, "All unslaved borgs have been slaved to you. Now hacking unslaved AI's.") - if(user.is_dead()) // check if the AI is still alive + if(user.stat == DEAD) // check if the AI is still alive user.synthetic_takeover = 0 return sleep(300) // 30 second delay for balance purposes @@ -274,29 +274,29 @@ if(target != user) to_chat(target, "SYSTEM LOG: Brute-Force login password hack attempt detected from IP #UNKNOWN#") sleep(100) - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: Connection from IP #UNKNOWN# closed. Hack attempt failed.") return to_chat(user, "Successfully hacked into AI's remote administration system. Modifying settings.") to_chat(target, "SYSTEM LOG: User: Admin Password: ******** logged in. (L1 - SysAdmin)") sleep(50) - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User: Admin - Connection Lost") return to_chat(target, "SYSTEM LOG: User: Admin - Password Changed. New password: ********************") sleep(50) - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User: Admin - Connection Lost. Changes Reverted.") return to_chat(target, "SYSTEM LOG: User: Admin - Accessed file: sys//core//laws.db") sleep(50) - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User: Admin - Connection Lost. Changes Reverted.") return to_chat(target, "SYSTEM LOG: User: Admin - Accessed administration console") to_chat(target, "SYSTEM LOG: Restart command received. Rebooting system...") sleep(100) - if(user.is_dead()) + if(user.stat == DEAD) to_chat(target, "SYSTEM LOG: User: Admin - Connection Lost. Changes Reverted.") return to_chat(user, "Hack succeeded. The AI is now under your exclusive control.") @@ -316,7 +316,7 @@ to_chat(user, "All unhacked AI's have been slaved to you. Now upgrading slaved borgs...") command_announcement.Announce("There has recently been a security breach in the network firewall, the intruder has been shut out but we are unable to trace who did it or what they did.", "Network Monitoring") sleep(600) //1 minute delay for balance purposes - if(user.is_dead()) // check if the AI is still alive + if(user.stat == DEAD) // check if the AI is still alive user.synthetic_takeover = 0 return for(var/A in get_linked_cyborgs(user)) @@ -360,11 +360,11 @@ sleep(1200) // 120 second balance sleep to_chat(user, "All slaved borgs have been upgraded, now hacking NTNet.") //slow down NTNet - if(user.is_dead()) // check if the AI is still alive + if(user.stat == DEAD) // check if the AI is still alive user.synthetic_takeover = 0 return sleep(1400) //long sleep that simulates hacking times - if(user.is_dead()) // check if the AI is still alive after the long hack + if(user.stat == DEAD) // check if the AI is still alive after the long hack user.synthetic_takeover = 0 return //trip the NTNet alarm @@ -381,7 +381,7 @@ command_announcement.Announce("There has recently been a hack targeting NTNet. It is suspected that it is the same hacker as before. NTNet may be unreliable to use. We are attempting to trace the hacker doing this.", "Network Monitoring") to_chat(user, "Now hacking engineering borg module to enable production of the robotic transformation machine...") sleep(1200) - if(user.is_dead()) // check if the AI is still alive + if(user.stat == DEAD) // check if the AI is still alive user.synthetic_takeover = 0 return for(var/B in get_linked_cyborgs(src)) @@ -394,7 +394,7 @@ command_announcement.Announce("Brute force attack located in NTNet emergency crisis operations.", "Network Monitoring") sleep(600) command_announcement.Announce("Crisis operations bypassed. Firewall breached. NTNet compr0m1s3d#-.", "Network Monitoring") - if(user.is_dead()) // check if the AI is still alive + if(user.stat == DEAD) // check if the AI is still alive user.synthetic_takeover = 0 return for(var/C in get_linked_cyborgs(src)) diff --git a/code/game/gamemodes/vampire/vampire_powers.dm b/code/game/gamemodes/vampire/vampire_powers.dm index 018fd7dffa4..8fdb759658a 100644 --- a/code/game/gamemodes/vampire/vampire_powers.dm +++ b/code/game/gamemodes/vampire/vampire_powers.dm @@ -672,7 +672,7 @@ else E.germ_level = 0 blood_used += 0.25 - for(var/datum/wound/W in E.wounds) + for(var/datum/wound/W as anything in E.wounds) if(W.germ_level > 0) W.germ_level = max(0, W.germ_level - 50) blood_used += 0.5 diff --git a/code/game/machinery/alarm.dm b/code/game/machinery/alarm.dm index 3a893751cba..cad86d1325d 100644 --- a/code/game/machinery/alarm.dm +++ b/code/game/machinery/alarm.dm @@ -60,7 +60,7 @@ for(var/g in trace_gas){\ other_moles += environment.gas[g];\ }\ - ALARM_GET_DANGER_LEVEL(pressure_dangerlevel, environment.return_pressure(), TLV["pressure"]);\ + ALARM_GET_DANGER_LEVEL(pressure_dangerlevel, XGM_PRESSURE(environment), TLV["pressure"]);\ ALARM_GET_DANGER_LEVEL(oxygen_dangerlevel, environment.gas[GAS_OXYGEN]*partial_pressure, TLV[GAS_OXYGEN]);\ ALARM_GET_DANGER_LEVEL(co2_dangerlevel, environment.gas[GAS_CO2]*partial_pressure, TLV[GAS_CO2]);\ ALARM_GET_DANGER_LEVEL(phoron_dangerlevel, environment.gas[GAS_PHORON]*partial_pressure, TLV[GAS_PHORON]);\ @@ -474,7 +474,7 @@ pixel_x = 10; mode = AALARM_MODE_OFF apply_mode() - if (mode==AALARM_MODE_CYCLE && environment.return_pressure() 0) && (pressure_delta > 0)) @@ -399,7 +399,7 @@ update_flag if(returnval >= 0) src.update_icon() - if(air_contents.return_pressure() < 1) + if(XGM_PRESSURE(air_contents) < 1) can_label = 1 else can_label = 0 @@ -410,18 +410,6 @@ update_flag /obj/machinery/portable_atmospherics/canister/return_air() return air_contents -/obj/machinery/portable_atmospherics/canister/proc/return_temperature() - var/datum/gas_mixture/GM = src.return_air() - if(GM && GM.volume>0) - return GM.temperature - return 0 - -/obj/machinery/portable_atmospherics/canister/proc/return_pressure() - var/datum/gas_mixture/GM = src.return_air() - if(GM && GM.volume>0) - return GM.return_pressure() - return 0 - /obj/machinery/portable_atmospherics/canister/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit) . = ..() if(. != BULLET_ACT_HIT) @@ -471,8 +459,8 @@ update_flag if(istype(user, /mob/living/silicon/robot) && istype(attacking_item, /obj/item/tank/jetpack)) var/obj/item/tank/jetpack/jetpack = attacking_item var/datum/gas_mixture/thejetpack = jetpack.air_contents - var/env_pressure = thejetpack.return_pressure() - var/pressure_delta = min(10*ONE_ATMOSPHERE - env_pressure, (air_contents.return_pressure() - env_pressure)/2) + var/env_pressure = XGM_PRESSURE(thejetpack) + var/pressure_delta = min(10*ONE_ATMOSPHERE - env_pressure, (XGM_PRESSURE(air_contents) - env_pressure)/2) // Cannot have a pressure delta that would cause environment pressure > tank pressure var/transfer_moles = 0 if((air_contents.temperature > 0) && (pressure_delta > 0)) @@ -507,7 +495,7 @@ update_flag data["name"] = name data["canLabel"] = can_label data["portConnected"] = !!connected_port - data["tankPressure"] = round(air_contents.return_pressure() || 0) + data["tankPressure"] = round(XGM_PRESSURE(air_contents) || 0) data["releasePressure"] = round(release_pressure || 0) data["minReleasePressure"] = round(ONE_ATMOSPHERE/10) data["maxReleasePressure"] = round(10*ONE_ATMOSPHERE) @@ -515,7 +503,7 @@ update_flag data["hasHoldingTank"] = !!holding if (holding) - data["holdingTank"] = list("name" = holding.name, "tankPressure" = round(holding.air_contents.return_pressure())) + data["holdingTank"] = list("name" = holding.name, "tankPressure" = round(XGM_PRESSURE(holding.air_contents))) return data /obj/machinery/portable_atmospherics/canister/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state) diff --git a/code/game/machinery/atmoalter/meter.dm b/code/game/machinery/atmoalter/meter.dm index 36ffb1000fe..9f663ca08a9 100644 --- a/code/game/machinery/atmoalter/meter.dm +++ b/code/game/machinery/atmoalter/meter.dm @@ -27,7 +27,7 @@ else if(src.target) var/datum/gas_mixture/environment = target.return_air() if(environment) - . += "The pressure gauge reads [round(environment.return_pressure(), 0.01)] kPa; [round(environment.temperature,0.01)]K ([round(environment.temperature-T0C,0.01)]°C)" + . += "The pressure gauge reads [round(XGM_PRESSURE(environment), 0.01)] kPa; [round(environment.temperature,0.01)]K ([round(environment.temperature-T0C,0.01)]°C)" else . += SPAN_WARNING("The sensor error light is blinking.") else @@ -55,7 +55,7 @@ var/button_overlay_name var/atmos_overlay_name - var/env_pressure = environment.return_pressure() + var/env_pressure = XGM_PRESSURE(environment) if(env_pressure <= 0.15*ONE_ATMOSPHERE) button_overlay_name = "buttons_0" atmos_overlay_name = "pressure0" @@ -116,7 +116,7 @@ var/datum/gas_mixture/environment = target.return_air() if(!environment) return FALSE - var/env_pressure = environment.return_pressure() + var/env_pressure = XGM_PRESSURE(environment) if(frequency) var/datum/radio_frequency/radio_connection = SSradio.return_frequency(frequency) diff --git a/code/game/machinery/atmoalter/pump.dm b/code/game/machinery/atmoalter/pump.dm index 400bf4e9117..5415c15348b 100644 --- a/code/game/machinery/atmoalter/pump.dm +++ b/code/game/machinery/atmoalter/pump.dm @@ -83,11 +83,11 @@ var/output_volume var/air_temperature if(direction_out) - pressure_delta = target_pressure - environment.return_pressure() + pressure_delta = target_pressure - XGM_PRESSURE(environment) output_volume = environment.volume * environment.group_multiplier air_temperature = environment.temperature? environment.temperature : air_contents.temperature else - pressure_delta = environment.return_pressure() - target_pressure + pressure_delta = XGM_PRESSURE(environment) - target_pressure output_volume = air_contents.volume * air_contents.group_multiplier air_temperature = air_contents.temperature? air_contents.temperature : environment.temperature @@ -133,9 +133,10 @@ ui_interact(user) /obj/machinery/portable_atmospherics/powered/pump/ui_data(mob/user) + var/air_pressure = XGM_PRESSURE(air_contents) var/list/data = list() data["portConnected"] = connected_port ? 1 : 0 - data["tankPressure"] = round(air_contents.return_pressure() > 0 ? air_contents.return_pressure() : 0) + data["tankPressure"] = round(air_pressure) data["targetpressure"] = round(target_pressure) data["pump_dir"] = direction_out data["minpressure"] = round(pressuremin) @@ -147,7 +148,7 @@ data["hasHoldingTank"] = holding ? 1 : 0 if (holding) - data["holdingTank"] = list("name" = holding.name, "tankPressure" = round(holding.air_contents.return_pressure() > 0 ? holding.air_contents.return_pressure() : 0)) + data["holdingTank"] = list("name" = holding.name, "tankPressure" = round(XGM_PRESSURE(holding.air_contents))) return data /obj/machinery/portable_atmospherics/powered/pump/ui_interact(mob/user, datum/tgui/ui) diff --git a/code/game/machinery/atmoalter/scrubber.dm b/code/game/machinery/atmoalter/scrubber.dm index 9689d078f62..fe9b2cf3de1 100644 --- a/code/game/machinery/atmoalter/scrubber.dm +++ b/code/game/machinery/atmoalter/scrubber.dm @@ -116,7 +116,7 @@ /obj/machinery/portable_atmospherics/powered/scrubber/ui_data(mob/user) var/list/data = list() data["portConnected"] = connected_port ? 1 : 0 - data["tankPressure"] = round(air_contents.return_pressure() > 0 ? air_contents.return_pressure() : 0) + data["tankPressure"] = round(XGM_PRESSURE(air_contents)) data["rate"] = round(volume_rate) data["minrate"] = round(minrate) data["maxrate"] = round(maxrate) @@ -127,7 +127,7 @@ data["hasHoldingTank"] = holding ? 1 : 0 if(holding) data["holdingTankName"] = holding?.name - data["holdingTankPressure"] = round(holding.air_contents.return_pressure() > 0 ? holding.air_contents.return_pressure() : 0) + data["holdingTankPressure"] = round(XGM_PRESSURE(holding.air_contents)) else data["holdingTankName"] = null data["holdingTankPressure"] = null diff --git a/code/game/machinery/doors/airlock_control.dm b/code/game/machinery/doors/airlock_control.dm index b554e28ba54..942d37eb8f3 100644 --- a/code/game/machinery/doors/airlock_control.dm +++ b/code/game/machinery/doors/airlock_control.dm @@ -178,7 +178,7 @@ /obj/machinery/airlock_sensor/process() if(on) var/datum/gas_mixture/air_sample = return_air() - var/pressure = round(air_sample.return_pressure(),0.1) + var/pressure = round(XGM_PRESSURE(air_sample),0.1) if(abs(pressure - previousPressure) > 0.001 || previousPressure == null) var/datum/signal/signal = new diff --git a/code/game/machinery/floodlight.dm b/code/game/machinery/floodlight.dm index 3c04132f6c2..3d0e4f37ba1 100644 --- a/code/game/machinery/floodlight.dm +++ b/code/game/machinery/floodlight.dm @@ -23,7 +23,7 @@ return else . += SPAN_WARNING("\The [src] has no cell installed!") - . += SPAN_NOTICE("The installed [cell.name] has [Percent(cell.charge, cell.maxcharge)]% charge remaining.") + . += SPAN_NOTICE("The installed [cell.name] has [AS_PCT(cell.charge, cell.maxcharge)]% charge remaining.") /obj/machinery/floodlight/Initialize() . = ..() diff --git a/code/game/machinery/iv_drip.dm b/code/game/machinery/iv_drip.dm index 29eec603323..69a47d0be50 100644 --- a/code/game/machinery/iv_drip.dm +++ b/code/game/machinery/iv_drip.dm @@ -92,7 +92,7 @@ else . += "No chemicals attached." if(tank) - . += "Installed is [is_loose ? "\a [tank] sitting loose" : "\a [tank] secured"] on the stand. The meter shows [round(tank.air_contents.return_pressure())] kPa, \ + . += "Installed is [is_loose ? "\a [tank] sitting loose" : "\a [tank] secured"] on the stand. The meter shows [round(XGM_PRESSURE(tank.air_contents))] kPa, \ with the pressure set to [round(tank.distribute_pressure)] kPa. The valve is [valve_open ? "open" : "closed"]." else . += "No gas tank installed." @@ -252,7 +252,7 @@ playsound(src, 'sound/machines/twobeep.ogg', 50, extrarange = SILENCED_SOUND_EXTRARANGE) breath_mask_rip() return - if(tank.air_contents.return_pressure() <= 10) + if(XGM_PRESSURE(tank.air_contents) <= 10) src.visible_message(SPAN_WARNING("\The [src] buzzes, automatically deactivating \the [tank] and retracting \the [breath_mask].")) playsound(src, 'sound/machines/buzz-two.ogg', 50, extrarange = SILENCED_SOUND_EXTRARANGE) breath_mask_rip() diff --git a/code/game/machinery/supplybeacon.dm b/code/game/machinery/supplybeacon.dm index ade899eb797..8ed9a302dcc 100644 --- a/code/game/machinery/supplybeacon.dm +++ b/code/game/machinery/supplybeacon.dm @@ -74,7 +74,7 @@ /obj/machinery/power/supply_beacon/proc/activate(var/mob/user) if(expended) return - if(surplus() < 500) + if(POWER_SURPLUS(src) < 500) if(user) to_chat(user, SPAN_NOTICE("The connected wire doesn't have enough current.")) return set_light(3, 3, "#00CCAA") @@ -102,7 +102,9 @@ return PROCESS_KILL if(!use_power) return - if(draw_power(500) < 500) + var/can_draw = (POWER_DRAW(src, 500) >= 500) + DRAW_POWER(src, can_draw) + if(!can_draw) deactivate() return if(!target_drop_time) diff --git a/code/game/machinery/tesla_beacon.dm b/code/game/machinery/tesla_beacon.dm index a9b41ff6009..1f2119bfa23 100644 --- a/code/game/machinery/tesla_beacon.dm +++ b/code/game/machinery/tesla_beacon.dm @@ -13,7 +13,7 @@ var/active = FALSE /obj/machinery/power/tesla_beacon/proc/activate(mob/user = null) - if(surplus() < 1500) + if(POWER_SURPLUS(src) < 1500) if(user) to_chat(user, SPAN_NOTICE("The connected wire doesn't have enough current.")) return for(var/A in SScalamity.singularities) @@ -80,6 +80,7 @@ /obj/machinery/power/tesla_beacon/process() if(!active) return PROCESS_KILL - else - if(draw_power(1500) < 1500) - deactivate() + var/can_draw = POWER_DRAW(src, 1500) >= 1500 + DRAW_POWER(src, can_draw) + if(!can_draw) + deactivate() diff --git a/code/game/objects/effects/chem/chemsmoke.dm b/code/game/objects/effects/chem/chemsmoke.dm index b0034cda7cc..98f6082519f 100644 --- a/code/game/objects/effects/chem/chemsmoke.dm +++ b/code/game/objects/effects/chem/chemsmoke.dm @@ -200,7 +200,7 @@ var/pressure = 0 var/datum/gas_mixture/environment = location.return_air() - if(environment) pressure = environment.return_pressure() + pressure = SAFE_XGM_PRESSURE(environment) duration = between(5, (duration*pressure)/(ONE_ATMOSPHERE), duration*2) var/const/arcLength = 2.3559 //distance between each smoke cloud diff --git a/code/game/objects/effects/decals/Cleanable/napalm.dm b/code/game/objects/effects/decals/Cleanable/napalm.dm index 04c99912dff..98f17755905 100644 --- a/code/game/objects/effects/decals/Cleanable/napalm.dm +++ b/code/game/objects/effects/decals/Cleanable/napalm.dm @@ -65,7 +65,12 @@ /obj/effect/decal/cleanable/napalm/process(seconds_per_tick) var/turf/simulated/src_turf = get_turf(src) var/datum/gas_mixture/air_contents = src_turf?.return_air() - if(!(air_contents?.check_combustibility(src))) + var/is_cmb = CMB_LIQUID_FUEL + if(air_contents) + CHECK_COMBUSTIBLE(is_cmb, air_contents) + else + is_cmb = FALSE + if(!is_cmb) PutOut() return @@ -93,7 +98,12 @@ var/turf/simulated/src_turf = get_turf(src) var/datum/gas_mixture/air_contents = src_turf?.return_air() //If we can't ignite, return - if(!(air_contents?.check_combustibility(src))) + var/is_cmb = CMB_LIQUID_FUEL + if(air_contents) + CHECK_COMBUSTIBLE(is_cmb, air_contents) + else + is_cmb = FALSE + if(!is_cmb) return //Otherwise, start a fire! on_fire = TRUE diff --git a/code/game/objects/items/airbubble.dm b/code/game/objects/items/airbubble.dm index 47ff02b8a80..a9c861b4c03 100644 --- a/code/game/objects/items/airbubble.dm +++ b/code/game/objects/items/airbubble.dm @@ -84,7 +84,7 @@ /obj/structure/closet/airbubble/feedback_hints(mob/user, distance, is_adjacent) . += ..() if(!isnull(internal_tank)) - . += SPAN_NOTICE("\The [src] has [internal_tank] attached, that displays [round(internal_tank.air_contents.return_pressure() ? internal_tank.air_contents.return_pressure() : 0)] kPa.") + . += SPAN_NOTICE("\The [src] has [internal_tank] attached, that displays [round(SAFE_XGM_PRESSURE(internal_tank.air_contents))] kPa.") else . += SPAN_NOTICE("\The [src] has no tank attached.") if (cell) @@ -508,12 +508,13 @@ /obj/structure/closet/airbubble/proc/process_tank_give_air() if(internal_tank) var/datum/gas_mixture/tank_air = internal_tank.return_air() + var/tank_pressure = XGM_PRESSURE(tank_air) var/release_pressure = internal_tank_valve // If ripped, we are leaking if(ripped) // If we has no pressure in the tank, why bother? - if(tank_air.return_pressure() <= 1) + if(tank_pressure <= 1) STOP_PROCESSING(SSfast_process, src) use_internal_tank = !use_internal_tank visible_message(SPAN_WARNING("You hear last bits of air coming out from [src]'s hole.Maybe the tank run out of air?")) @@ -530,8 +531,8 @@ else qdel(removed) return - var/inside_pressure = inside_air.return_pressure() - var/pressure_delta = min(release_pressure - inside_pressure, (tank_air.return_pressure() - inside_pressure)/2) + var/inside_pressure = XGM_PRESSURE(inside_air) + var/pressure_delta = min(release_pressure - inside_pressure, (tank_pressure - inside_pressure)/2) var/transfer_moles = 0 if(pressure_delta > 0) //inside pressure lower than release pressure @@ -545,7 +546,7 @@ pressure_delta = inside_pressure - release_pressure if(t_air) - pressure_delta = min(inside_pressure - t_air.return_pressure(), pressure_delta) + pressure_delta = min(inside_pressure - XGM_PRESSURE(t_air), pressure_delta) if(pressure_delta > 0) //if location pressure is lower than inside pressure transfer_moles = pressure_delta*inside_air.volume/(inside_air.temperature * R_IDEAL_GAS_EQUATION) @@ -586,27 +587,6 @@ if(T) return T.return_air() -/obj/structure/closet/airbubble/proc/return_pressure() - . = 0 - if(use_internal_tank) - . = inside_air.return_pressure() - else - var/datum/gas_mixture/t_air = get_turf_air() - if(t_air) - . = t_air.return_pressure() - return - - -/obj/structure/closet/airbubble/proc/return_temperature() - . = 0 - if(use_internal_tank) - . = inside_air.temperature - else - var/datum/gas_mixture/t_air = get_turf_air() - if(t_air) - . = t_air.temperature - return - /obj/structure/closet/airbubble/process() process_preserve_temp() process_tank_give_air() diff --git a/code/game/objects/items/devices/auto_cpr.dm b/code/game/objects/items/devices/auto_cpr.dm index 87b87d4e319..ab4375dae80 100644 --- a/code/game/objects/items/devices/auto_cpr.dm +++ b/code/game/objects/items/devices/auto_cpr.dm @@ -71,7 +71,7 @@ else . += SPAN_DANGER("It currently has a battery with no charge left!") if(tank) - . += "It has \the [tank] installed. The meter shows [round(tank.air_contents.return_pressure())] kPa, \ + . += "It has \the [tank] installed. The meter shows [round(XGM_PRESSURE(tank.air_contents))] kPa, \ with the pressure set to [round(tank.distribute_pressure)] kPa.[epp_active ? " The [EPP] is active." : ""]" if(breath_mask) . += "It has \the [breath_mask] installed." @@ -389,7 +389,7 @@ src.visible_message(SPAN_WARNING("Error! Patient safety check triggered! Turning the [EPP] off.")) epp_off() return - if(tank.air_contents.return_pressure() <= 10) + if(XGM_PRESSURE(tank.air_contents) <= 10) src.visible_message(SPAN_WARNING("Error! Installed [tank] is low or near empty! Turning the [EPP] off.")) epp_off() return diff --git a/code/game/objects/items/devices/oxycandle.dm b/code/game/objects/items/devices/oxycandle.dm index d356d1f8d75..08b29d2ce11 100644 --- a/code/game/objects/items/devices/oxycandle.dm +++ b/code/game/objects/items/devices/oxycandle.dm @@ -47,7 +47,7 @@ if(pos) pos.hotspot_expose(1500, 5) var/datum/gas_mixture/environment = loc.return_air() - var/pressure_delta = target_pressure - environment.return_pressure() + var/pressure_delta = target_pressure - XGM_PRESSURE(environment) var/output_volume = environment.volume * environment.group_multiplier var/air_temperature = air_contents.temperature? air_contents.temperature : environment.temperature var/transfer_moles = pressure_delta*output_volume/(air_temperature * R_IDEAL_GAS_EQUATION) diff --git a/code/game/objects/items/devices/powersink.dm b/code/game/objects/items/devices/powersink.dm index 30dbca6b355..402ebc3fd3a 100644 --- a/code/game/objects/items/devices/powersink.dm +++ b/code/game/objects/items/devices/powersink.dm @@ -123,7 +123,8 @@ PN.trigger_warning() // found a powernet, so drain up to max power from it - drained = PN.draw_power(drain_rate * seconds_per_tick) + drained = POWERNET_POWER_DRAW(PN, drain_rate * seconds_per_tick) + DRAW_FROM_POWERNET(PN, drained) // if tried to drain more than available on powernet // now look for APCs and drain their cells if(drained < drain_rate * seconds_per_tick) diff --git a/code/game/objects/items/weapons/tanks/tanks.dm b/code/game/objects/items/weapons/tanks/tanks.dm index 23430050db5..e871a9d6535 100644 --- a/code/game/objects/items/weapons/tanks/tanks.dm +++ b/code/game/objects/items/weapons/tanks/tanks.dm @@ -112,7 +112,7 @@ var/list/data = list() - data["tankPressure"] = round(air_contents.return_pressure() ? air_contents.return_pressure() : 0) + data["tankPressure"] = round(XGM_PRESSURE(air_contents)) data["releasePressure"] = round(distribute_pressure ? distribute_pressure : 0) data["defaultReleasePressure"] = round(TANK_DEFAULT_RELEASE_PRESSURE) data["maxReleasePressure"] = round(TANK_MAX_RELEASE_PRESSURE) @@ -193,7 +193,7 @@ if(!air_contents) return null - var/tank_pressure = air_contents.return_pressure() + var/tank_pressure = XGM_PRESSURE(air_contents) if(tank_pressure < distribute_pressure) distribute_pressure = tank_pressure @@ -202,19 +202,23 @@ return remove_air(moles_needed) /obj/item/tank/process() - //Allow for reactions - air_contents.react() //cooking up air tanks - add phoron and oxygen, then heat above PHORON_MINIMUM_BURN_TEMPERATURE + var/tank_pressure = 0 + // we pass tank_pressure around and try not to recalc it unless we have to + // this is a very hot proc (~2M calls/hr) + if(air_contents) + tank_pressure = XGM_PRESSURE(air_contents) + air_contents.react() + tank_pressure = check_status(tank_pressure) if(gauge_icon) - update_gauge() - check_status() + update_gauge(tank_pressure) /obj/item/tank/proc/adjust_initial_gas() return -/obj/item/tank/proc/update_gauge() - var/gauge_pressure = 0 +/obj/item/tank/proc/update_gauge(gauge_pressure = 0) if(air_contents) - gauge_pressure = air_contents.return_pressure() + if(!gauge_pressure) + gauge_pressure = XGM_PRESSURE(air_contents) if(gauge_pressure > TANK_IDEAL_PRESSURE) gauge_pressure = -1 else @@ -231,16 +235,17 @@ /obj/item/tank/proc/percent() var/gauge_pressure = 0 if(air_contents) - gauge_pressure = air_contents.return_pressure() + gauge_pressure = XGM_PRESSURE(air_contents) return 100.0*gauge_pressure/TANK_IDEAL_PRESSURE -/obj/item/tank/proc/check_status() +/obj/item/tank/proc/check_status(pressure = 0) //Handle exploding, leaking, and rupturing of the tank if(!air_contents) return 0 + if(!pressure) + pressure = XGM_PRESSURE(air_contents) - var/pressure = air_contents.return_pressure() if(pressure > TANK_FRAGMENT_PRESSURE) if(!istype(src.loc,/obj/item/transfer_valve)) message_admins("Explosive tank rupture! last key to touch the tank was [src.fingerprintslast].") @@ -251,7 +256,7 @@ air_contents.react() air_contents.react() - pressure = air_contents.return_pressure() + pressure = XGM_PRESSURE(air_contents) var/range = (pressure-TANK_FRAGMENT_PRESSURE)/TANK_FRAGMENT_SCALE explosion( @@ -270,11 +275,10 @@ if(integrity <= 0) var/turf/simulated/T = get_turf(src) - if(!T) - return - T.assume_air(air_contents) - playsound(src.loc, 'sound/effects/spray.ogg', 10, 1, -3) - qdel(src) + if(T) + T.assume_air(air_contents) + playsound(src.loc, 'sound/effects/spray.ogg', 10, 1, -3) + qdel(src) else integrity-- @@ -285,16 +289,18 @@ if(integrity <= 0) var/turf/simulated/T = get_turf(src) - if(!T) - return - var/datum/gas_mixture/leaked_gas = air_contents.remove_ratio(0.25) - T.assume_air(leaked_gas) + if(T) + var/datum/gas_mixture/leaked_gas = air_contents.remove_ratio(0.25) + T.assume_air(leaked_gas) + return 0 else integrity-- else if(integrity < 3) integrity++ + return QDELETED(src) ? 0 : pressure // if we qdel'd or return 0, something changed and we gotta recalc + /obj/item/tank/proc/remove_air_by_flag(flag, amount) . = air_contents.remove_by_flag(flag, amount) update_icon() diff --git a/code/game/sound/sound.dm b/code/game/sound/sound.dm index 888946f3484..7bf6ea9b051 100644 --- a/code/game/sound/sound.dm +++ b/code/game/sound/sound.dm @@ -178,7 +178,7 @@ var/datum/gas_mixture/source_env = turf_source.return_air() if(hearer_env && source_env) - var/pressure = min(hearer_env.return_pressure(), source_env.return_pressure()) + var/pressure = min(XGM_PRESSURE(hearer_env), XGM_PRESSURE(source_env)) if(pressure < ONE_ATMOSPHERE) pressure_factor = max((pressure - SOUND_MINIMUM_PRESSURE)/(ONE_ATMOSPHERE - SOUND_MINIMUM_PRESSURE), 0) else //space diff --git a/code/modules/admin/secrets/fun_secrets/ghost_mode.dm b/code/modules/admin/secrets/fun_secrets/ghost_mode.dm index ab3f81a407b..fcd763ddb9d 100644 --- a/code/modules/admin/secrets/fun_secrets/ghost_mode.dm +++ b/code/modules/admin/secrets/fun_secrets/ghost_mode.dm @@ -36,10 +36,10 @@ affected_mobs |= user for(var/area/AffectedArea in affected_areas) AffectedArea.power_light = 0 - AffectedArea.power_change() + SEND_SIGNAL(AffectedArea, COMSIG_AREA_POWER_CHANGE) spawn(rand(25,50)) AffectedArea.power_light = 1 - AffectedArea.power_change() + SEND_SIGNAL(AffectedArea, COMSIG_AREA_POWER_CHANGE) sleep(100) for(var/mob/M in affected_mobs) diff --git a/code/modules/admin/verbs/debug.dm b/code/modules/admin/verbs/debug.dm index cbfd73fbf88..dc5682411f3 100644 --- a/code/modules/admin/verbs/debug.dm +++ b/code/modules/admin/verbs/debug.dm @@ -57,7 +57,7 @@ var/t = SPAN_NOTICE("Coordinates: [T.x],[T.y],[T.z]\n") t += SPAN_WARNING("Temperature: [env.temperature]\n") - t += SPAN_WARNING("Pressure: [env.return_pressure()]kPa\n") + t += SPAN_WARNING("Pressure: [XGM_PRESSURE(env)]kPa\n") for(var/g in env.gas) t += SPAN_NOTICE("[g]: [env.gas[g]] / [env.gas[g] * R_IDEAL_GAS_EQUATION * env.temperature / env.volume]kPa\n") diff --git a/code/modules/atmospherics/_atmospherics_helpers.dm b/code/modules/atmospherics/_atmospherics_helpers.dm index f7ed86c60b4..4f396f1016a 100644 --- a/code/modules/atmospherics/_atmospherics_helpers.dm +++ b/code/modules/atmospherics/_atmospherics_helpers.dm @@ -451,7 +451,7 @@ var/source_volume = source.volume * source.group_multiplier var/sink_volume = sink.volume * sink.group_multiplier - var/source_pressure = source.return_pressure() - var/sink_pressure = sink.return_pressure() + var/source_pressure = XGM_PRESSURE(source) + var/sink_pressure = XGM_PRESSURE(sink) return (source_pressure - sink_pressure)/(R_IDEAL_GAS_EQUATION * (source.temperature/source_volume + sink.temperature/sink_volume)) diff --git a/code/modules/atmospherics/components/binary_devices/circulator.dm b/code/modules/atmospherics/components/binary_devices/circulator.dm index c510ad6cc79..9fc6963527e 100644 --- a/code/modules/atmospherics/components/binary_devices/circulator.dm +++ b/code/modules/atmospherics/components/binary_devices/circulator.dm @@ -37,8 +37,8 @@ /obj/machinery/atmospherics/binary/circulator/proc/return_transfer_air() var/datum/gas_mixture/removed if(anchored && !(stat&BROKEN) && network1) - var/input_starting_pressure = air1.return_pressure() - var/output_starting_pressure = air2.return_pressure() + var/input_starting_pressure = XGM_PRESSURE(air1) + var/output_starting_pressure = XGM_PRESSURE(air2) last_pressure_delta = max(input_starting_pressure - output_starting_pressure - 5, 0) //only circulate air if there is a pressure difference (plus 5kPa kinetic, 10kPa static friction) diff --git a/code/modules/atmospherics/components/binary_devices/oxyregenerator.dm b/code/modules/atmospherics/components/binary_devices/oxyregenerator.dm index 4daeeb04140..28e30599c21 100644 --- a/code/modules/atmospherics/components/binary_devices/oxyregenerator.dm +++ b/code/modules/atmospherics/components/binary_devices/oxyregenerator.dm @@ -103,7 +103,7 @@ last_power_draw = 0 //TODO Add overlay with F-P-R letter to display current state if (phase == "filling")//filling tank - var/pressure_delta = target_pressure - inner_tank.return_pressure() + var/pressure_delta = target_pressure - XGM_PRESSURE(inner_tank) if (pressure_delta > 0.01 && air1.temperature > 0) var/transfer_moles = calculate_transfer_moles(air1, inner_tank, pressure_delta) power_draw = pump_gas(src, air1, inner_tank, transfer_moles, power_rating*power_setting) * intake_power_efficiency @@ -112,7 +112,7 @@ use_power_oneoff(power_draw) if(network1) network1.update = 1 - if (air1.return_pressure() < 0.1 * ONE_ATMOSPHERE || inner_tank.return_pressure() >= target_pressure * 0.95)//if pipe is good as empty or tank is full + if (XGM_PRESSURE(air1) < 0.1 * ONE_ATMOSPHERE || XGM_PRESSURE(inner_tank) >= target_pressure * 0.95)//if pipe is good as empty or tank is full phase = "processing" if (phase == "processing")//processing CO2 in tank @@ -137,7 +137,7 @@ if (phase == "releasing")//releasing processed gas mix power_draw = -1 - var/pressure_delta = target_pressure - air2.return_pressure() + var/pressure_delta = target_pressure - XGM_PRESSURE(air2) if (pressure_delta > 0.01 && inner_tank.temperature > 0) var/transfer_moles = calculate_transfer_moles(inner_tank, air2, pressure_delta, (network2)? network2.volume : 0) power_draw = pump_gas(src, inner_tank, air2, transfer_moles, power_rating*power_setting) @@ -148,7 +148,7 @@ network2.update = 1 else//can't push outside harder than target pressure. Device is not intended to be used as a pump after all phase = "filling" - if (inner_tank.return_pressure() <= 0.1) + if (XGM_PRESSURE(inner_tank) <= 0.1) phase = "filling" /obj/machinery/atmospherics/binary/oxyregenerator/update_icon() @@ -162,9 +162,9 @@ data["on"] = use_power ? 1 : 0 data["powerSetting"] = power_setting data["gasProcessed"] = last_flow_rate - data["air1Pressure"] = round(air1.return_pressure()) - data["air2Pressure"] = round(air2.return_pressure()) - data["tankPressure"] = round(inner_tank.return_pressure()) + data["air1Pressure"] = round(XGM_PRESSURE(air1)) + data["air2Pressure"] = round(XGM_PRESSURE(air2)) + data["tankPressure"] = round(XGM_PRESSURE(inner_tank)) data["targetPressure"] = round(target_pressure) data["phase"] = phase if (inner_tank.total_moles > 0) diff --git a/code/modules/atmospherics/components/binary_devices/passive_gate.dm b/code/modules/atmospherics/components/binary_devices/passive_gate.dm index c73c85a1720..677b8a7bdd3 100644 --- a/code/modules/atmospherics/components/binary_devices/passive_gate.dm +++ b/code/modules/atmospherics/components/binary_devices/passive_gate.dm @@ -116,8 +116,8 @@ if(!unlocked) return 0 - var/output_starting_pressure = air2.return_pressure() - var/input_starting_pressure = air1.return_pressure() + var/output_starting_pressure = XGM_PRESSURE(air2) + var/input_starting_pressure = XGM_PRESSURE(air1) var/pressure_delta switch (regulate_mode) @@ -203,11 +203,8 @@ unlocked = !unlocked if("set_target_pressure" in signal.data) - target_pressure = between( - 0, - text2num(signal.data["set_target_pressure"]), - max_pressure_setting - ) + var/set_pressure = text2num(signal.data["set_target_pressure"]) + target_pressure = between(0, set_pressure, max_pressure_setting) if("set_regulate_mode" in signal.data) regulate_mode = text2num(signal.data["set_regulate_mode"]) @@ -335,7 +332,7 @@ var/datum/gas_mixture/int_air = return_air() if (!loc) return FALSE var/datum/gas_mixture/env_air = loc.return_air() - if ((int_air.return_pressure()-env_air.return_pressure()) > PRESSURE_EXERTED) + if ((XGM_PRESSURE(int_air)-XGM_PRESSURE(env_air)) > PRESSURE_EXERTED) to_chat(user, SPAN_WARNING("You cannot unwrench \the [src], it too exerted due to internal pressure.")) add_fingerprint(user) return TRUE diff --git a/code/modules/atmospherics/components/binary_devices/pump.dm b/code/modules/atmospherics/components/binary_devices/pump.dm index 26a5e9856d4..e407eeb6a66 100644 --- a/code/modules/atmospherics/components/binary_devices/pump.dm +++ b/code/modules/atmospherics/components/binary_devices/pump.dm @@ -121,7 +121,7 @@ Thus, the two variables affect pump operation are set in New(): broadcast_status_next_process = FALSE var/power_draw = -1 - var/pressure_delta = target_pressure - air2.return_pressure() + var/pressure_delta = target_pressure - XGM_PRESSURE(air2) if(pressure_delta > 0.01 && air1.temperature > 0) //Figure out how much gas to transfer to meet the target pressure. @@ -282,7 +282,7 @@ Thus, the two variables affect pump operation are set in New(): var/datum/gas_mixture/int_air = return_air() if (!loc) return FALSE var/datum/gas_mixture/env_air = loc.return_air() - if ((int_air.return_pressure()-env_air.return_pressure()) > PRESSURE_EXERTED && !istype(attacking_item, /obj/item/pipewrench)) + if ((XGM_PRESSURE(int_air)-XGM_PRESSURE(env_air)) > PRESSURE_EXERTED && !istype(attacking_item, /obj/item/pipewrench)) to_chat(user, SPAN_WARNING("You cannot unwrench this [src], it's too exerted due to internal pressure.")) add_fingerprint(user) return TRUE diff --git a/code/modules/atmospherics/components/omni_devices/omni_base.dm b/code/modules/atmospherics/components/omni_devices/omni_base.dm index d587883d4ae..e848f807247 100644 --- a/code/modules/atmospherics/components/omni_devices/omni_base.dm +++ b/code/modules/atmospherics/components/omni_devices/omni_base.dm @@ -88,10 +88,10 @@ var/int_pressure = 0 for(var/datum/omni_port/P in ports) - int_pressure += P.air.return_pressure() + int_pressure += XGM_PRESSURE(P.air) if(!loc) return FALSE var/datum/gas_mixture/env_air = loc.return_air() - if ((int_pressure - env_air.return_pressure()) > PRESSURE_EXERTED) + if ((int_pressure - XGM_PRESSURE(env_air)) > PRESSURE_EXERTED) to_chat(user, SPAN_WARNING("You cannot unwrench \the [src], it is too exerted due to internal pressure.")) add_fingerprint(user) return TRUE diff --git a/code/modules/atmospherics/components/portables_connector.dm b/code/modules/atmospherics/components/portables_connector.dm index 9411793a592..dbc2ebbfd4e 100644 --- a/code/modules/atmospherics/components/portables_connector.dm +++ b/code/modules/atmospherics/components/portables_connector.dm @@ -164,7 +164,7 @@ var/datum/gas_mixture/int_air = return_air() if(!loc) return FALSE var/datum/gas_mixture/env_air = loc.return_air() - if ((int_air.return_pressure()-env_air.return_pressure()) > PRESSURE_EXERTED) + if ((XGM_PRESSURE(int_air)-XGM_PRESSURE(env_air)) > PRESSURE_EXERTED) to_chat(user, SPAN_WARNING("You cannot unwrench \the [src], it too exerted due to internal pressure.")) add_fingerprint(user) return TRUE diff --git a/code/modules/atmospherics/components/tvalve.dm b/code/modules/atmospherics/components/tvalve.dm index 42a8db1e453..a16be54f688 100644 --- a/code/modules/atmospherics/components/tvalve.dm +++ b/code/modules/atmospherics/components/tvalve.dm @@ -355,7 +355,7 @@ var/datum/gas_mixture/int_air = return_air() if(!loc) return FALSE var/datum/gas_mixture/env_air = loc.return_air() - if ((int_air.return_pressure()-env_air.return_pressure()) > PRESSURE_EXERTED) + if ((XGM_PRESSURE(int_air)-XGM_PRESSURE(env_air)) > PRESSURE_EXERTED) to_chat(user, "You cannot unwrench \the [src], it too exerted due to internal pressure.") add_fingerprint(user) return TRUE diff --git a/code/modules/atmospherics/components/unary/cold_sink.dm b/code/modules/atmospherics/components/unary/cold_sink.dm index d10868266c2..aa9f0472db6 100644 --- a/code/modules/atmospherics/components/unary/cold_sink.dm +++ b/code/modules/atmospherics/components/unary/cold_sink.dm @@ -92,7 +92,7 @@ var/list/data = list() data["on"] = !!use_power - data["gasPressure"] = round(air_contents.return_pressure()) + data["gasPressure"] = round(XGM_PRESSURE(air_contents)) data["gasTemperature"] = round(air_contents.temperature) data["minGasTemperature"] = 0 data["maxGasTemperature"] = round(T20C+500) diff --git a/code/modules/atmospherics/components/unary/heat_exchanger.dm b/code/modules/atmospherics/components/unary/heat_exchanger.dm index 4766c1d3c6c..b8a596ac0a5 100644 --- a/code/modules/atmospherics/components/unary/heat_exchanger.dm +++ b/code/modules/atmospherics/components/unary/heat_exchanger.dm @@ -73,7 +73,7 @@ var/datum/gas_mixture/int_air = return_air() if(!loc) return FALSE var/datum/gas_mixture/env_air = loc.return_air() - if((int_air.return_pressure() - env_air.return_pressure()) > PRESSURE_EXERTED) + if((XGM_PRESSURE(int_air) - XGM_PRESSURE(env_air)) > PRESSURE_EXERTED) to_chat(user, SPAN_WARNING("You cannot unwrench \the [src], it is too exerted due to internal pressure.")) add_fingerprint(user) return TRUE diff --git a/code/modules/atmospherics/components/unary/heat_source.dm b/code/modules/atmospherics/components/unary/heat_source.dm index be4816b7741..a5e5af6743f 100644 --- a/code/modules/atmospherics/components/unary/heat_source.dm +++ b/code/modules/atmospherics/components/unary/heat_source.dm @@ -110,7 +110,7 @@ var/list/data = list() data["on"] = !!use_power - data["gasPressure"] = round(air_contents.return_pressure()) + data["gasPressure"] = round(XGM_PRESSURE(air_contents)) data["gasTemperature"] = round(air_contents.temperature) data["minGasTemperature"] = 0 data["maxGasTemperature"] = round(T20C + 600) diff --git a/code/modules/atmospherics/components/unary/vent_pump.dm b/code/modules/atmospherics/components/unary/vent_pump.dm index 100826a9b1d..2cc6f7f3fc0 100644 --- a/code/modules/atmospherics/components/unary/vent_pump.dm +++ b/code/modules/atmospherics/components/unary/vent_pump.dm @@ -260,18 +260,18 @@ /obj/machinery/atmospherics/unary/vent_pump/proc/get_pressure_delta(datum/gas_mixture/environment) var/pressure_delta = DEFAULT_PRESSURE_DELTA - var/environment_pressure = environment.return_pressure() + var/environment_pressure = XGM_PRESSURE(environment) if(pump_direction) //internal -> external if(pressure_checks & PRESSURE_CHECK_EXTERNAL) pressure_delta = min(pressure_delta, external_pressure_bound - environment_pressure) //increasing the pressure here if(pressure_checks & PRESSURE_CHECK_INTERNAL) - pressure_delta = min(pressure_delta, air_contents.return_pressure() - internal_pressure_bound) //decreasing the pressure here + pressure_delta = min(pressure_delta, XGM_PRESSURE(air_contents) - internal_pressure_bound) //decreasing the pressure here else //external -> internal if(pressure_checks & PRESSURE_CHECK_EXTERNAL) pressure_delta = min(pressure_delta, environment_pressure - external_pressure_bound) //decreasing the pressure here if(pressure_checks & PRESSURE_CHECK_INTERNAL) - pressure_delta = min(pressure_delta, internal_pressure_bound - air_contents.return_pressure()) //increasing the pressure here + pressure_delta = min(pressure_delta, internal_pressure_bound - XGM_PRESSURE(air_contents)) //increasing the pressure here return pressure_delta @@ -349,37 +349,23 @@ if (signal.data["set_internal_pressure"] == "default") internal_pressure_bound = internal_pressure_bound_default else - internal_pressure_bound = between( - 0, - text2num(signal.data["set_internal_pressure"]), - MAX_VENT_PRESSURE - ) + var/set_pressure = text2num(signal.data["set_internal_pressure"]) + internal_pressure_bound = between(0, set_pressure, MAX_VENT_PRESSURE) if(signal.data["set_external_pressure"] != null) if (signal.data["set_external_pressure"] == "default") external_pressure_bound = external_pressure_bound_default else - external_pressure_bound = between( - 0, - text2num(signal.data["set_external_pressure"]), - MAX_VENT_PRESSURE - ) + var/set_pressure = text2num(signal.data["set_external_pressure"]) + external_pressure_bound = between(0, set_pressure, MAX_VENT_PRESSURE) if(signal.data["adjust_internal_pressure"] != null) - internal_pressure_bound = between( - 0, - internal_pressure_bound + text2num(signal.data["adjust_internal_pressure"]), - MAX_VENT_PRESSURE - ) + var/set_pressure = internal_pressure_bound + text2num(signal.data["adjust_internal_pressure"]) + internal_pressure_bound = between(0, set_pressure, MAX_VENT_PRESSURE) if(signal.data["adjust_external_pressure"] != null) - - - external_pressure_bound = between( - 0, - external_pressure_bound + text2num(signal.data["adjust_external_pressure"]), - MAX_VENT_PRESSURE - ) + var/set_pressure = external_pressure_bound + text2num(signal.data["adjust_external_pressure"]) + external_pressure_bound = between(0, set_pressure, MAX_VENT_PRESSURE) if(signal.data["init"] != null) name = signal.data["init"] @@ -452,7 +438,7 @@ var/datum/gas_mixture/int_air = return_air() var/datum/gas_mixture/env_air = loc.return_air() - if((int_air.return_pressure()-env_air.return_pressure()) > PRESSURE_EXERTED) + if((XGM_PRESSURE(int_air)-XGM_PRESSURE(env_air)) > PRESSURE_EXERTED) to_chat(user, SPAN_WARNING("You cannot unwrench \the [src], it is too exerted due to internal pressure.")) add_fingerprint(user) diff --git a/code/modules/atmospherics/components/unary/vent_scrubber.dm b/code/modules/atmospherics/components/unary/vent_scrubber.dm index d8a1a0bf6a5..28d490ad0da 100644 --- a/code/modules/atmospherics/components/unary/vent_scrubber.dm +++ b/code/modules/atmospherics/components/unary/vent_scrubber.dm @@ -369,7 +369,7 @@ var/datum/gas_mixture/int_air = return_air() if(!loc) return FALSE var/datum/gas_mixture/env_air = loc.return_air() - if ((int_air.return_pressure()-env_air.return_pressure()) > PRESSURE_EXERTED) + if ((XGM_PRESSURE(int_air)-XGM_PRESSURE(env_air)) > PRESSURE_EXERTED) to_chat(user, SPAN_WARNING("You cannot unwrench \the [src], it is too exerted due to internal pressure.")) add_fingerprint(user) return TRUE diff --git a/code/modules/atmospherics/components/valve.dm b/code/modules/atmospherics/components/valve.dm index 5a79e98a523..3c29f91b12e 100644 --- a/code/modules/atmospherics/components/valve.dm +++ b/code/modules/atmospherics/components/valve.dm @@ -327,7 +327,7 @@ var/datum/gas_mixture/int_air = return_air() if (!loc) return FALSE var/datum/gas_mixture/env_air = loc.return_air() - if ((int_air.return_pressure()-env_air.return_pressure()) > PRESSURE_EXERTED) + if ((XGM_PRESSURE(int_air)-XGM_PRESSURE(env_air)) > PRESSURE_EXERTED) to_chat(user, SPAN_WARNING("You cannot unwrench \the [src], it is too exerted due to internal pressure.")) add_fingerprint(user) return TRUE diff --git a/code/modules/atmospherics/datum_pipeline.dm b/code/modules/atmospherics/datum_pipeline.dm index d284eab01a6..7c3532594e8 100644 --- a/code/modules/atmospherics/datum_pipeline.dm +++ b/code/modules/atmospherics/datum_pipeline.dm @@ -27,7 +27,7 @@ /datum/pipeline/process()//This use to be called called from the pipe networks //Check to see if pressure is within acceptable limits - var/pressure = air.return_pressure() + var/pressure = XGM_PRESSURE(air) if(pressure > alert_pressure) for(var/obj/machinery/atmospherics/pipe/member in members) if(!member.check_pressure(pressure)) diff --git a/code/modules/atmospherics/pipes.dm b/code/modules/atmospherics/pipes.dm index 95138391f06..cb13eb4e4db 100644 --- a/code/modules/atmospherics/pipes.dm +++ b/code/modules/atmospherics/pipes.dm @@ -112,7 +112,7 @@ var/datum/gas_mixture/int_air = return_air() if(!loc) return FALSE var/datum/gas_mixture/env_air = loc.return_air() - if ((int_air.return_pressure()-env_air.return_pressure()) > PRESSURE_EXERTED) + if ((XGM_PRESSURE(int_air)-XGM_PRESSURE(env_air)) > PRESSURE_EXERTED) if(!istype(attacking_item, /obj/item/pipewrench)) to_chat(user, SPAN_WARNING("You cannot unwrench \the [src], it is too exerted due to internal pressure.")) add_fingerprint(user) @@ -236,7 +236,7 @@ if(!loc) return var/datum/gas_mixture/environment = loc.return_air() - var/pressure_difference = pressure - environment.return_pressure() + var/pressure_difference = pressure - XGM_PRESSURE(environment) if(pressure_difference > maximum_pressure) burst() diff --git a/code/modules/atmospherics/vent_passive.dm b/code/modules/atmospherics/vent_passive.dm index 72e75775b7c..f3c57e54b87 100644 --- a/code/modules/atmospherics/vent_passive.dm +++ b/code/modules/atmospherics/vent_passive.dm @@ -153,7 +153,7 @@ var/datum/gas_mixture/int_air = return_air() var/datum/gas_mixture/env_air = loc.return_air() - if((int_air.return_pressure()-env_air.return_pressure()) > PRESSURE_EXERTED) + if((XGM_PRESSURE(int_air)-XGM_PRESSURE(env_air)) > PRESSURE_EXERTED) to_chat(user, SPAN_WARNING("You cannot unwrench \the [src], it is too exerted due to internal pressure.")) add_fingerprint(user) diff --git a/code/modules/cargo/bounties/engineer.dm b/code/modules/cargo/bounties/engineer.dm index 02b05cd0d3e..a23281735f7 100644 --- a/code/modules/cargo/bounties/engineer.dm +++ b/code/modules/cargo/bounties/engineer.dm @@ -116,7 +116,7 @@ return FALSE if(!istype(O)) return FALSE - if(O.air_contents.return_pressure() >= 500) + if(XGM_PRESSURE(O.air_contents) >= 500) return TRUE return FALSE diff --git a/code/modules/clothing/spacesuits/rig/modules/utility.dm b/code/modules/clothing/spacesuits/rig/modules/utility.dm index 0266a0805a6..5e8b9f7c039 100644 --- a/code/modules/clothing/spacesuits/rig/modules/utility.dm +++ b/code/modules/clothing/spacesuits/rig/modules/utility.dm @@ -292,7 +292,7 @@ if(target_mob != user) to_chat(user, SPAN_NOTICE("You inject [target_mob] with [chems_to_use] unit\s of [charge.display_name].")) - if(!target_mob.is_physically_disabled()) + if(!target_mob.incapacitated(INCAPACITATION_DISABLED)) to_chat(target_mob, SPAN_NOTICE("You feel a rushing in your veins as [chems_to_use] unit\s of [charge.display_name] [chems_to_use == 1 ? "is" : "are"] injected.")) target_mob.reagents.add_reagent(charge.product_type, chems_to_use) diff --git a/code/modules/clothing/spacesuits/void/void.dm b/code/modules/clothing/spacesuits/void/void.dm index e2ee768481d..e45eed4e3fd 100644 --- a/code/modules/clothing/spacesuits/void/void.dm +++ b/code/modules/clothing/spacesuits/void/void.dm @@ -96,7 +96,7 @@ part_list += "\a [I]" . += "\The [src] has [english_list(part_list)] installed." if(tank && distance <= 1) - . += SPAN_NOTICE("The wrist-mounted pressure gauge reads [max(round(tank.air_contents.return_pressure()),0)] kPa remaining in \the [tank].") + . += SPAN_NOTICE("The wrist-mounted pressure gauge reads [max(round(XGM_PRESSURE(tank.air_contents)),0)] kPa remaining in \the [tank].") if (cooler && distance <= 1) . += SPAN_NOTICE("The mounted cooler's battery charge reads [round(cooler.cell.percent())]%") diff --git a/code/modules/custom_ka/core.dm b/code/modules/custom_ka/core.dm index 0860db6acde..83e4c261c3e 100644 --- a/code/modules/custom_ka/core.dm +++ b/code/modules/custom_ka/core.dm @@ -241,7 +241,7 @@ if(T) var/datum/gas_mixture/environment = T.return_air() - var/pressure = (environment)? environment.return_pressure() : 0 + var/pressure = SAFE_XGM_PRESSURE(environment) if(ispath(installed_barrel.projectile_type, /obj/projectile/kinetic)) var/obj/projectile/kinetic/shot_projectile = new installed_barrel.projectile_type(get_turf(src)) shot_projectile.damage = damage_increase diff --git a/code/modules/custom_ka/projectiles.dm b/code/modules/custom_ka/projectiles.dm index 58cd35294dd..453e1b8d038 100644 --- a/code/modules/custom_ka/projectiles.dm +++ b/code/modules/custom_ka/projectiles.dm @@ -30,7 +30,7 @@ /obj/projectile/kinetic/proc/do_damage(var/turf/T, var/living_damage = 1, var/mineral_damage = 1) if(!istype(T)) return var/datum/gas_mixture/environment = T.return_air() - living_damage *= max(1 - (environment.return_pressure() / 100) * 0.75, 0) + living_damage *= max(1 - (XGM_PRESSURE(environment) / 100) * 0.75, 0) new /obj/effect/overlay/temp/kinetic_blast(T) for(var/mob/living/L in T) L.take_overall_damage(min(living_damage, 50)) diff --git a/code/modules/heavy_vehicle/components/body.dm b/code/modules/heavy_vehicle/components/body.dm index b082c77ba7f..90397a0b26e 100644 --- a/code/modules/heavy_vehicle/components/body.dm +++ b/code/modules/heavy_vehicle/components/body.dm @@ -106,7 +106,7 @@ cockpit.equalize(T.return_air()) changed = TRUE else if(air_supply) - var/env_pressure = cockpit.return_pressure() + var/env_pressure = XGM_PRESSURE(cockpit) var/pressure_delta = air_supply.release_pressure - env_pressure if((air_supply.air_contents.temperature > 0) && (pressure_delta > 0)) var/transfer_moles = calculate_transfer_moles(air_supply.air_contents, cockpit, pressure_delta) diff --git a/code/modules/hydroponics/seed.dm b/code/modules/hydroponics/seed.dm index 91e96979c10..657892fb6f0 100644 --- a/code/modules/hydroponics/seed.dm +++ b/code/modules/hydroponics/seed.dm @@ -322,7 +322,7 @@ health_change += missing_gas * HYDRO_SPEED_MULTIPLIER // Process it. - var/pressure = environment.return_pressure() + var/pressure = XGM_PRESSURE(environment) if(pressure < GET_SEED_TRAIT(src, TRAIT_LOWKPA_TOLERANCE)|| pressure > GET_SEED_TRAIT(src, TRAIT_HIGHKPA_TOLERANCE)) health_change += rand(1,3) * HYDRO_SPEED_MULTIPLIER diff --git a/code/modules/integrated_electronics/passive/power.dm b/code/modules/integrated_electronics/passive/power.dm index a42608816f3..55cede7cc9e 100644 --- a/code/modules/integrated_electronics/passive/power.dm +++ b/code/modules/integrated_electronics/passive/power.dm @@ -201,15 +201,16 @@ if(should_act) // We're gonna give or take from the net. if(drawing) var/to_transfer = min(throughput, (assembly.battery.maxcharge - assembly.battery.charge) / CELLRATE) // So we don't need to draw 10kW if the cell needs much less. - var/amount = IO.draw_power(to_transfer) + var/amount = POWER_DRAW(IO, to_transfer) + DRAW_POWER(IO, amount) assembly.give_power(amount) else var/amount = assembly.draw_power(throughput) - IO.add_avail(amount) + ADD_TO_POWERNET(IO, amount) - set_pin_data(IC_OUTPUT, 1, IO.avail()) - set_pin_data(IC_OUTPUT, 2, IO.surplus()) - set_pin_data(IC_OUTPUT, 3, -IO.surplus()-IO.avail()) // we don't have a viewload() proc on machines and i'm lazy + set_pin_data(IC_OUTPUT, 1, POWER_AVAIL(IO)) + set_pin_data(IC_OUTPUT, 2, POWER_SURPLUS(IO)) + set_pin_data(IC_OUTPUT, 3, POWER_LOAD(IO)) // Internal power machine for interacting with the powernet. // It needs a bit of special code since base /machinery/power assumes loc will be a tile. diff --git a/code/modules/integrated_electronics/subtypes/input.dm b/code/modules/integrated_electronics/subtypes/input.dm index ab60a3a13db..057f23486a3 100644 --- a/code/modules/integrated_electronics/subtypes/input.dm +++ b/code/modules/integrated_electronics/subtypes/input.dm @@ -629,7 +629,7 @@ return var/datum/gas_mixture/environment = T.return_air() - var/pressure = environment.return_pressure() + var/pressure = XGM_PRESSURE(environment) var/total_moles = environment.total_moles if (total_moles) @@ -707,7 +707,7 @@ return var/datum/gas_mixture/environment = T.return_air() - var/pressure = environment.return_pressure() + var/pressure = XGM_PRESSURE(environment) var/total_moles = environment.total_moles if (total_moles) diff --git a/code/modules/mining/mine_items.dm b/code/modules/mining/mine_items.dm index 219309ce1ad..b0aad7f71f6 100644 --- a/code/modules/mining/mine_items.dm +++ b/code/modules/mining/mine_items.dm @@ -1069,7 +1069,7 @@ GLOBAL_LIST_INIT_TYPED(total_extraction_beacons, /obj/structure/extraction_point if(!istype(proj_turf)) return var/datum/gas_mixture/environment = proj_turf.return_air() - var/pressure = environment.return_pressure() + var/pressure = XGM_PRESSURE(environment) if(pressure < 50) name = "strong resonance field" resonance_damage = 60 diff --git a/code/modules/mob/abstract/ghost/ghost.dm b/code/modules/mob/abstract/ghost/ghost.dm index 9c053c0dbd6..d06f26e5afe 100644 --- a/code/modules/mob/abstract/ghost/ghost.dm +++ b/code/modules/mob/abstract/ghost/ghost.dm @@ -192,7 +192,7 @@ var/datum/gas_mixture/environment = loc.return_air() - var/pressure = environment.return_pressure() + var/pressure = XGM_PRESSURE(environment) var/total_moles = environment.total_moles to_chat(src, SPAN_NOTICE("Results:")) diff --git a/code/modules/mob/hear_say.dm b/code/modules/mob/hear_say.dm index 49527a26c34..9b353df7e4e 100644 --- a/code/modules/mob/hear_say.dm +++ b/code/modules/mob/hear_say.dm @@ -23,7 +23,7 @@ if(T && !vacuum_proof) //Ghosts can hear even in vacuum. var/datum/gas_mixture/environment = T.return_air() - var/pressure = (environment)? environment.return_pressure() : 0 + var/pressure = SAFE_XGM_PRESSURE(environment) var/distance_to_speaker = get_dist(speaker, src) if(pressure < SOUND_MINIMUM_PRESSURE && distance_to_speaker > 1) // Yeah, this isn't quite realistic to be able to see if someone is talking through, say, an opaque mask, but for gameplay purposes it should help indicate that you're not bugged. diff --git a/code/modules/mob/living/carbon/breathe.dm b/code/modules/mob/living/carbon/breathe.dm index d69357e0d58..f2ac2335857 100644 --- a/code/modules/mob/living/carbon/breathe.dm +++ b/code/modules/mob/living/carbon/breathe.dm @@ -96,7 +96,7 @@ //Handle possble chem smoke effect /mob/living/carbon/proc/handle_chemical_smoke(var/datum/gas_mixture/environment) - if(species && environment.return_pressure() < species.breath_pressure/5) + if(species && XGM_PRESSURE(environment) < species.breath_pressure/5) return //pressure is too low to even breathe in. if(wear_mask && (wear_mask.item_flags & ITEM_FLAG_BLOCK_GAS_SMOKE_EFFECT)) return diff --git a/code/modules/mob/living/carbon/carbon.dm b/code/modules/mob/living/carbon/carbon.dm index a373797e805..cb01f89d521 100644 --- a/code/modules/mob/living/carbon/carbon.dm +++ b/code/modules/mob/living/carbon/carbon.dm @@ -416,11 +416,6 @@ usr.sleeping = 20 // Short nap. usr.eye_blurry = 20 -/mob/living/carbon/sleeps_horizontal() - if(species && species.sleeps_upright) - return FALSE - return ..() - /verb/toggle_indefinite_sleep() set name = "Toggle Indefinite Sleep" set category = "IC" diff --git a/code/modules/mob/living/carbon/human/human.dm b/code/modules/mob/living/carbon/human/human.dm index 272a8f177f7..15dc486d52e 100644 --- a/code/modules/mob/living/carbon/human/human.dm +++ b/code/modules/mob/living/carbon/human/human.dm @@ -253,7 +253,7 @@ qdel(internal) else . += "Internal Atmosphere Info: [internal.name]" - . += "Tank Pressure: [internal.air_contents.return_pressure()]" + . += "Tank Pressure: [XGM_PRESSURE(internal.air_contents)]" . += "Distribution Pressure: [internal.distribute_pressure]" var/obj/item/organ/internal/machine/power_core/IC = internal_organs_by_name[BP_CELL] @@ -1905,15 +1905,15 @@ eyeobj.remove_visual(src) -/mob/living/carbon/human/can_stand_overridden() +/mob/living/carbon/human/proc/can_stand_overridden() if(wearing_rig && wearing_rig.ai_can_move_suit(check_for_ai = 1)) // Actually missing a leg will screw you up. Everything else can be compensated for. for(var/limbcheck in list(BP_L_LEG,BP_R_LEG)) var/obj/item/organ/affecting = get_organ(limbcheck) if(!affecting) - return 0 - return 1 - return 0 + return FALSE + return TRUE + return FALSE /mob/living/carbon/human/proc/can_drink(var/obj/item/I) if(should_have_organ(BP_REACTOR)) @@ -2307,7 +2307,7 @@ look_up_open_space(get_turf(src)) /mob/living/proc/look_up_open_space(var/turf/T) - if(client && !is_physically_disabled()) + if(client && !MOB_IS_INCAPACITATED(INCAPACITATION_DISABLED)) if(z_eye) reset_view(null) QDEL_NULL(z_eye) @@ -2330,7 +2330,7 @@ look_down_open_space(get_turf(src)) /mob/living/proc/look_down_open_space(var/turf/T) - if(client && !is_physically_disabled()) + if(client && !MOB_IS_INCAPACITATED(INCAPACITATION_DISABLED)) if(z_eye) reset_view(null) QDEL_NULL(z_eye) diff --git a/code/modules/mob/living/carbon/human/human_defense.dm b/code/modules/mob/living/carbon/human/human_defense.dm index 602517c98af..6269b73c415 100644 --- a/code/modules/mob/living/carbon/human/human_defense.dm +++ b/code/modules/mob/living/carbon/human/human_defense.dm @@ -13,7 +13,7 @@ emp_act if(species_check) return species_check - if(!is_physically_disabled()) + if(!MOB_IS_INCAPACITATED(INCAPACITATION_DISABLED)) var/deflection_chance = check_martial_deflection_chance() if(prob(deflection_chance)) visible_message(SPAN_WARNING("\The [src] deftly dodges \the [hitting_projectile]!"), SPAN_NOTICE("You deftly dodge \the [hitting_projectile]!")) diff --git a/code/modules/mob/living/carbon/human/human_organs.dm b/code/modules/mob/living/carbon/human/human_organs.dm index 0b9a0db1da3..b6d9d23b65a 100644 --- a/code/modules/mob/living/carbon/human/human_organs.dm +++ b/code/modules/mob/living/carbon/human/human_organs.dm @@ -66,7 +66,7 @@ I.take_damage(rand(3,5)) //Moving makes open wounds get infected much faster - for(var/datum/wound/W in E.wounds) + for(var/datum/wound/W as anything in E.wounds) if (W.infection_check()) W.germ_level += 1 diff --git a/code/modules/mob/living/carbon/human/life.dm b/code/modules/mob/living/carbon/human/life.dm index 76454d1506f..6e0e2508978 100644 --- a/code/modules/mob/living/carbon/human/life.dm +++ b/code/modules/mob/living/carbon/human/life.dm @@ -296,7 +296,7 @@ if(breath) //exposure to extreme pressures can rupture lungs - var/check_pressure = breath.return_pressure() + var/check_pressure = XGM_PRESSURE(breath) if(check_pressure < ONE_ATMOSPHERE / 5 || check_pressure > ONE_ATMOSPHERE * 5) if(!is_lung_ruptured() && prob(5)) rupture_lung() @@ -313,7 +313,7 @@ species.handle_environment_special(src) //Moved pressure calculations here for use in skip-processing check. - var/pressure = environment.return_pressure() + var/pressure = XGM_PRESSURE(environment) var/adjusted_pressure = calculate_affecting_pressure(pressure) if (consume_nutrition_from_air) diff --git a/code/modules/mob/living/carbon/human/stripping.dm b/code/modules/mob/living/carbon/human/stripping.dm index 85db055520d..1f54b000d63 100644 --- a/code/modules/mob/living/carbon/human/stripping.dm +++ b/code/modules/mob/living/carbon/human/stripping.dm @@ -31,7 +31,7 @@ visible_message(SPAN_WARNING("\The [user] is taking a look at \the [src]'s air tank.")) if(do_after(user, HUMAN_STRIP_DELAY, src, do_flags = DO_EQUIP)) var/obj/item/tank/T = internal - to_chat(user, SPAN_NOTICE("\The [T] has [T.air_contents.return_pressure()] kPA left.")) + to_chat(user, SPAN_NOTICE("\The [T] has [XGM_PRESSURE(T.air_contents)] kPA left.")) to_chat(user, SPAN_NOTICE("The [T] is set to release [T.distribute_pressure] kPA.")) return TRUE if("pockets") diff --git a/code/modules/mob/living/say.dm b/code/modules/mob/living/say.dm index 776e1421641..5658b3ed41d 100644 --- a/code/modules/mob/living/say.dm +++ b/code/modules/mob/living/say.dm @@ -320,7 +320,7 @@ var/list/channel_to_radio_key = new if(!speaking || !(speaking.flags & PRESSUREPROOF)) //make sure the air can transmit speech - speaker's side var/datum/gas_mixture/environment = T.return_air() - var/pressure = (environment)? environment.return_pressure() : 0 + var/pressure = SAFE_XGM_PRESSURE(environment) if(pressure < SOUND_MINIMUM_PRESSURE) message_range = 1 diff --git a/code/modules/mob/living/silicon/robot/robot.dm b/code/modules/mob/living/silicon/robot/robot.dm index de94414291c..fa9d7f28307 100644 --- a/code/modules/mob/living/silicon/robot/robot.dm +++ b/code/modules/mob/living/silicon/robot/robot.dm @@ -557,7 +557,7 @@ if(jetpack) . += "Internal Atmosphere Info: [jetpack.name]" - . += "Tank Pressure: [jetpack.air_contents.return_pressure()]" + . += "Tank Pressure: [XGM_PRESSURE(jetpack.air_contents)]" . += "Lights: [lights_on ? "ON" : "OFF"]" if(module) for(var/datum/matter_synth/ms in module.synths) diff --git a/code/modules/mob/living/simple_animal/hostile/bear.dm b/code/modules/mob/living/simple_animal/hostile/bear.dm index f590a84da97..552eba706ac 100644 --- a/code/modules/mob/living/simple_animal/hostile/bear.dm +++ b/code/modules/mob/living/simple_animal/hostile/bear.dm @@ -347,7 +347,7 @@ if(istype(loc,/turf)) var/turf/T = loc var/datum/gas_mixture/environment = T.return_air() - if (environment.return_pressure() <= 80) + if (XGM_PRESSURE(environment) <= 80) bearmode = BEARMODE_SPACE if (bearmode != former) diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 405c0134cdf..8dafc6e19ea 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -1,7 +1,3 @@ -#define UNBUCKLED 0 -#define PARTIALLY_BUCKLED 1 -#define FULLY_BUCKLED 2 - /mob/Destroy()//This makes sure that mobs with clients/keys are not just deleted from the game. MOB_STOP_THINKING(src) // Tell any mobs touching us that they're not pulling us anymore. @@ -323,12 +319,6 @@ return UNBUCKLED return restrained() ? FULLY_BUCKLED : PARTIALLY_BUCKLED -/mob/proc/is_physically_disabled() - return MOB_IS_INCAPACITATED(INCAPACITATION_DISABLED) - -/mob/proc/cannot_stand() - return MOB_IS_INCAPACITATED(INCAPACITATION_KNOCKDOWN) - // Inside this file, you should use MOB_IS_INCAPACITATED for performance reasons /mob/proc/incapacitated(var/incapacitation_flags = INCAPACITATION_DEFAULT) @@ -828,9 +818,6 @@ /mob/proc/is_active() return (0 >= usr.stat) -/mob/proc/is_dead() - return stat == DEAD - /mob/proc/is_mechanical() return FALSE @@ -861,61 +848,60 @@ if(transforming) return 0 return 1 -/// Not sure what to call this. Used to check if humans are wearing an AI-controlled exosuit and hence don't need to fall over yet. -/mob/proc/can_stand_overridden() - return 0 - /// Updates canmove, lying and icons. Could perhaps do with a rename but I can't think of anything to describe it. /mob/proc/update_canmove() - if(in_neck_grab()) - lying = FALSE - for(var/obj/item/grab/G in grabbed_by) - if(G.force_down) - lying = TRUE - break - else if(!resting && cannot_stand() && can_stand_overridden()) - lying = FALSE - lying_is_intentional = FALSE - canmove = TRUE - else - if(istype(buckled_to, /obj/vehicle)) - var/obj/vehicle/V = buckled_to - if(is_physically_disabled()) - lying = TRUE - lying_is_intentional = FALSE - canmove = FALSE - pixel_y = V.mob_offset_y - 5 - else - if(buckled_to.buckle_lying != -1) lying = buckled_to.buckle_lying - lying_is_intentional = FALSE - canmove = TRUE - pixel_y = V.mob_offset_y - else if(buckled_to) - anchored = TRUE - canmove = FALSE - if(isobj(buckled_to)) - if(buckled_to.buckle_lying != -1) - lying = buckled_to.buckle_lying - lying_is_intentional = FALSE - if(buckled_to.buckle_movable) - anchored = FALSE - canmove = TRUE - else if(captured) - anchored = TRUE + var/found_grab = FALSE + for(var/obj/item/grab/G as anything in grabbed_by) + if(G.wielded || G.state >= GRAB_AGGRESSIVE) canmove = FALSE + lying = G.wielded || (G.state >= GRAB_NECK && G.force_down) + found_grab = TRUE + break + var/mob/living/carbon/human/H = astype(src) + if(!found_grab) + if(!resting && MOB_IS_INCAPACITATED(INCAPACITATION_KNOCKDOWN) && H?.can_stand_overridden()) lying = FALSE - else if(m_intent == M_LAY && !incapacitated()) - lying = TRUE - lying_is_intentional = TRUE + lying_is_intentional = FALSE canmove = TRUE - else if(sleeping) - lying = resting || is_dead() || (MOB_IS_INCAPACITATED(INCAPACITATION_KNOCKDOWN) && sleeps_horizontal()) // Vaurca, IPCs and Diona sleep standing up, unless they were already lying down - lying_is_intentional = FALSE - canmove = !MOB_IS_INCAPACITATED(INCAPACITATION_KNOCKOUT) && !weakened else - lying = resting || is_dead() || MOB_IS_INCAPACITATED(INCAPACITATION_KNOCKDOWN) && !recently_slept - lying_is_intentional = FALSE - canmove = !MOB_IS_INCAPACITATED(INCAPACITATION_KNOCKOUT) && !weakened + if(buckled_to) + if(istype(buckled_to, /obj/vehicle)) + var/obj/vehicle/V = buckled_to + if(MOB_IS_INCAPACITATED(INCAPACITATION_DISABLED)) + lying = TRUE + lying_is_intentional = FALSE + canmove = FALSE + pixel_y = V.mob_offset_y - 5 + else + if(buckled_to.buckle_lying != -1) lying = buckled_to.buckle_lying + lying_is_intentional = FALSE + canmove = TRUE + pixel_y = V.mob_offset_y + else + anchored = TRUE + canmove = FALSE + if(buckled_to.buckle_lying != -1) + lying = buckled_to.buckle_lying + lying_is_intentional = FALSE + if(buckled_to.buckle_movable) + anchored = FALSE + canmove = TRUE + else if(captured) + anchored = TRUE + canmove = FALSE + lying = FALSE + else if(m_intent == M_LAY && !MOB_IS_INCAPACITATED(INCAPACITATION_DEFAULT)) + lying = TRUE + lying_is_intentional = TRUE + canmove = TRUE + else if(sleeping) + lying = resting || (stat == DEAD) || (MOB_IS_INCAPACITATED(INCAPACITATION_KNOCKDOWN) && !(H?.species?.sleeps_upright)) // Vaurca, IPCs and Diona sleep standing up, unless they were already lying down + lying_is_intentional = FALSE + canmove = !MOB_IS_INCAPACITATED(INCAPACITATION_KNOCKOUT) && !weakened + else + lying = resting || (stat == DEAD) || MOB_IS_INCAPACITATED(INCAPACITATION_KNOCKDOWN) && !recently_slept + lying_is_intentional = FALSE + canmove = !MOB_IS_INCAPACITATED(INCAPACITATION_KNOCKOUT) && !weakened if(lying) ADD_TRAIT(src, TRAIT_UNDENSE, TRAIT_SOURCE_LYING_DOWN) @@ -925,30 +911,11 @@ else REMOVE_TRAIT(src, TRAIT_UNDENSE, TRAIT_SOURCE_LYING_DOWN) - for(var/obj/item/grab/G in grabbed_by) - if(G.wielded) - canmove = FALSE - lying = TRUE - break - if(G.state >= GRAB_AGGRESSIVE) - canmove = 0 - break - - //Temporarily moved here from the various life() procs - //I'm fixing stuff incrementally so this will likely find a better home. - //It just makes sense for now. ~Carn - if( update_icon ) //forces a full overlay update - update_icon = 0 - regenerate_icons() - else if( lying != lying_prev ) + if( lying != lying_prev ) update_icon() return canmove - -/mob/proc/sleeps_horizontal() - return TRUE - /mob/proc/facedir(var/ndir, var/force_change = FALSE) if(!canface() || (client && client.moving)) return 0 @@ -1121,7 +1088,7 @@ break if(affected) affected.implants -= implant - for(var/datum/wound/wound in affected.wounds) + for(var/datum/wound/wound as anything in affected.wounds) LAZYREMOVE(wound.embedded_objects, implant) if(!surgical_removal) shock_stage += 20 @@ -1592,7 +1559,3 @@ var/atom/movable/screen/plane_master/lighting/exterior_lighting = hud_used.plane_masters["[EXTERIOR_LIGHTING_PLANE]"] if (exterior_lighting) exterior_lighting.alpha = min(GLOB.minimum_exterior_lighting_alpha, lighting_alpha) - -#undef UNBUCKLED -#undef PARTIALLY_BUCKLED -#undef FULLY_BUCKLED diff --git a/code/modules/mob/mob_helpers.dm b/code/modules/mob/mob_helpers.dm index 8c30c8ec9aa..49d1221b099 100644 --- a/code/modules/mob/mob_helpers.dm +++ b/code/modules/mob/mob_helpers.dm @@ -1296,6 +1296,8 @@ GLOBAL_LIST_INIT(organ_rel_size, list( M.client.eye = M.client.mob M.client.perspective = MOB_PERSPECTIVE + + /mob/proc/in_neck_grab() for(var/thing in grabbed_by) var/obj/item/grab/G = thing diff --git a/code/modules/multiz/movement.dm b/code/modules/multiz/movement.dm index 881a28ba832..8756860cffc 100644 --- a/code/modules/multiz/movement.dm +++ b/code/modules/multiz/movement.dm @@ -230,7 +230,7 @@ return 1 /mob/living/silicon/robot/can_ztravel(var/direction) - if(incapacitated() || is_dead()) + if(incapacitated() || (stat == DEAD)) return FALSE if(Allow_Spacemove()) //Checks for active jetpack diff --git a/code/modules/multiz/pipes.dm b/code/modules/multiz/pipes.dm index 863a7132037..3a3f371eb18 100644 --- a/code/modules/multiz/pipes.dm +++ b/code/modules/multiz/pipes.dm @@ -74,7 +74,7 @@ if(!loc) return FALSE var/datum/gas_mixture/environment = loc.return_air() - var/pressure_difference = pressure - environment.return_pressure() + var/pressure_difference = pressure - XGM_PRESSURE(environment) if(pressure_difference > maximum_pressure) burst() diff --git a/code/modules/organs/internal/_internal.dm b/code/modules/organs/internal/_internal.dm index 2ef8e5edc48..6ad50469cc3 100644 --- a/code/modules/organs/internal/_internal.dm +++ b/code/modules/organs/internal/_internal.dm @@ -27,14 +27,15 @@ min_broken_damage = 10 /obj/item/organ/internal/Destroy() - if(owner) + if(owner && owner.internal_organs) owner.internal_organs.Remove(src) owner.internal_organs_by_name[organ_tag] = null owner.internal_organs_by_name -= organ_tag while(null in owner.internal_organs) owner.internal_organs -= null - var/obj/item/organ/external/E = owner.organs_by_name[parent_organ] - if(istype(E)) E.internal_organs -= src + if(parent_organ in owner.organs_by_name) + var/obj/item/organ/external/E = astype(owner.organs_by_name[parent_organ]) + E?.internal_organs -= src return ..() /// Sets the internal organ as belonging to the targeted external organ, and matches the target's species/robotness. Also updates all organ lists belonging to the owner. diff --git a/code/modules/organs/internal/heart.dm b/code/modules/organs/internal/heart.dm index 5cfb60622d8..e2a364f9980 100644 --- a/code/modules/organs/internal/heart.dm +++ b/code/modules/organs/internal/heart.dm @@ -247,7 +247,7 @@ var/list/do_spray = list() for(var/obj/item/organ/external/temp in owner.bad_external_organs) if((temp.status & ORGAN_BLEEDING) && !BP_IS_ROBOTIC(temp)) - for(var/datum/wound/W in temp.wounds) + for(var/datum/wound/W as anything in temp.wounds) if(W.bleeding()) open_wound = TRUE if(temp.applied_pressure) diff --git a/code/modules/organs/internal/species/machine/cooling_unit.dm b/code/modules/organs/internal/species/machine/cooling_unit.dm index 25c33f969cc..5631efcc764 100644 --- a/code/modules/organs/internal/species/machine/cooling_unit.dm +++ b/code/modules/organs/internal/species/machine/cooling_unit.dm @@ -147,7 +147,7 @@ temperature_change *= 0.5 // Check if there is somehow no air, or if we are in an ambient without enough air to properly cool us. - if((!ambient || (ambient && owner.calculate_affecting_pressure(ambient.return_pressure()) < owner.species.warning_low_pressure))) + if((!ambient || (ambient && owner.calculate_affecting_pressure(XGM_PRESSURE(ambient)) < owner.species.warning_low_pressure))) if(!spaceproof) temperature_change *= 0 else diff --git a/code/modules/organs/organ_external.dm b/code/modules/organs/organ_external.dm index 47e5894c0c9..95783d115b0 100644 --- a/code/modules/organs/organ_external.dm +++ b/code/modules/organs/organ_external.dm @@ -248,9 +248,8 @@ cached_markings = null mob_icon = null - for(var/datum/wound/wound in wounds) - qdel(wound) - + if(wounds) + QDEL_NULL_LIST(wounds) QDEL_LIST(children) QDEL_LIST(internal_organs) QDEL_LIST(implants) @@ -605,7 +604,7 @@ return //Heal damage on the individual wounds - for(var/datum/wound/W in wounds) + for(var/datum/wound/W as anything in wounds) if(brute == 0 && burn == 0) break @@ -695,7 +694,7 @@ This function completely restores a damaged organ to perfect condition. if((type == INJURY_TYPE_CUT || type == INJURY_TYPE_BRUISE) && damage >= 5) //we need to make sure that the wound we are going to worsen is compatible with the type of damage... var/list/compatible_wounds = list() - for (var/datum/wound/W in wounds) + for (var/datum/wound/W as anything in wounds) if (W.can_worsen(type, damage)) compatible_wounds += W @@ -730,14 +729,17 @@ This function completely restores a damaged organ to perfect condition. for(var/datum/wound/other in wounds) if(other.can_merge(W)) other.merge_wound(W) - W = null // to signify that the wound was added + W = other break - LAZYADD(wounds, W) - if(bandage_level) - owner.visible_message(SPAN_WARNING("The bandages on [owner.name]'s [name] gets [is_burn_type_damage ? "burnt" : "ripped"] off!"), SPAN_WARNING("The bandages on your [name] gets [is_burn_type_damage ? "burnt" : "ripped"] off!")) - bandage_level = BANDAGE_LEVEL_NONE - owner.update_bandages() + if(!QDELETED(W)) + if(!LAZYISIN(wounds, W)) + LAZYADD(wounds, W) + + if(bandage_level) + owner.visible_message(SPAN_WARNING("The bandages on [owner.name]'s [name] gets [is_burn_type_damage ? "burnt" : "ripped"] off!"), SPAN_WARNING("The bandages on your [name] gets [is_burn_type_damage ? "burnt" : "ripped"] off!")) + bandage_level = BANDAGE_LEVEL_NONE + owner.update_bandages() return W /**************************************************** @@ -888,24 +890,21 @@ Note that amputating the affected organ does in fact remove the infection from t var/antibiotics = 0 if(CE_ANTIBIOTIC in owner.chem_effects) antibiotics = owner.chem_effects[CE_ANTIBIOTIC] - for(var/datum/wound/W in wounds) + var/increased_own_germs = FALSE + for(var/datum/wound/W as anything in wounds) //Open wounds can become infected if (owner.germ_level > W.germ_level && W.infection_check()) W.germ_level++ - - if(antibiotics < 5) - for(var/datum/wound/W in wounds) - //Infected wounds raise the organ's germ level - if (W.germ_level > germ_level && W.infection_check()) + if(!increased_own_germs && antibiotics < 5 && W.germ_level > germ_level) germ_level++ - break //limit increase to a maximum of one per second + increased_own_germs = TRUE // limit increase to 1/tick /obj/item/organ/external/proc/get_infect_target(var/list/infect_candidates = list()) var/obj/item/organ/temp_target shuffle(infect_candidates) //Slightly randomizes since if all germ levels are zero, it'll always be the first pick of the list //figure out which organs we can spread germs to - for (var/obj/item/organ/I in infect_candidates) + for (var/obj/item/organ/I as anything in infect_candidates) if(I.germ_level < min(germ_level, INFECTION_LEVEL_TWO)) //Only choose organs that have less germs than us AND are below level two //The below will always be the organ with the highest germ level. It picks a temp_target first then cycles through to find which, if any, has more germs. if(!temp_target || I.germ_level > temp_target.germ_level) @@ -977,11 +976,12 @@ Note that amputating the affected organ does in fact remove the infection from t //Updating wounds. Handles wound natural I had some free spachealing, internal bleedings and infections /obj/item/organ/external/proc/update_wounds() + if(status & (ORGAN_ROBOT|ORGAN_ADV_ROBOT|ORGAN_PLANT)) + return //Robotic limbs don't heal or get worse. Diona limbs heal using their own mechanic - if((status & ORGAN_ROBOT) || (status & ORGAN_ADV_ROBOT) || (status & ORGAN_PLANT)) //Robotic limbs don't heal or get worse. Diona limbs heal using their own mechanic - return var/updatehud - for(var/datum/wound/W in wounds) + var/num_total_wounds = LAZYLEN(wounds) + for(var/datum/wound/W as anything in wounds) // wounds can disappear after 10 minutes at the earliest if(W.damage <= 0 && W.created + (10 MINUTES) <= world.time) qdel(W) @@ -995,22 +995,20 @@ Note that amputating the affected organ does in fact remove the infection from t var/heal_amt = 0 // if damage >= 50 AFTER treatment then it's probably too severe to heal within the timeframe of a round. - if (W.can_autoheal() && W.wound_damage() && brute_ratio < 50 && burn_ratio < 50) + if (updatehud && brute_ratio < 50 && burn_ratio < 50 && W.can_autoheal()) heal_amt += 0.5 //we only update wounds once in [wound_update_accuracy] ticks so have to emulate realtime - heal_amt = heal_amt * wound_update_accuracy + heal_amt *= wound_update_accuracy //configurable regen speed woo, no-regen hardcore or instaheal hugbox, choose your destiny - heal_amt = heal_amt * GLOB.config.organ_regeneration_multiplier + heal_amt *= GLOB.config.organ_regeneration_multiplier // amount of healing is spread over all the wounds - heal_amt = heal_amt / (LAZYLEN(wounds) + 1) + heal_amt /= ((number_wounds / num_total_wounds) + 1) // making it look prettier on scanners - heal_amt = round(heal_amt,0.1) - var/dam_type = DAMAGE_BRUTE - if (W.damage_type == INJURY_TYPE_BURN) - dam_type = DAMAGE_BURN + heal_amt = round(heal_amt, 0.1) + var/dam_type = W.damage_type == INJURY_TYPE_BURN ? DAMAGE_BURN : DAMAGE_BRUTE - if(owner.can_autoheal(dam_type) && (heal_amt > 0)) + if((heal_amt > 0) && owner.can_autoheal(dam_type)) W.heal_damage(heal_amt) // Salving also helps against infection @@ -1037,12 +1035,11 @@ Note that amputating the affected organ does in fact remove the infection from t status &= ~ORGAN_BLEEDING var/clamped = 0 - var/mob/living/carbon/human/H - if(istype(owner,/mob/living/carbon/human)) - H = owner + var/mob/living/carbon/human/H = astype(owner) + var/can_bleed = !BP_IS_ROBOTIC(src) && (H && !(H.species.flags & NO_BLOOD)) //update damage counts - for(var/datum/wound/W in wounds) + for(var/datum/wound/W as anything in wounds) if(W.damage <= 0) qdel(W) @@ -1055,7 +1052,7 @@ Note that amputating the affected organ does in fact remove the infection from t if(W.damage_type == INJURY_TYPE_CUT) cut_dam += W.damage - if(!(status & ORGAN_ROBOT) && W.bleeding() && (H && !(H.species.flags & NO_BLOOD))) + if(can_bleed && W.bleeding()) W.handle_bleeding(H, src) clamped |= W.clamped @@ -1063,18 +1060,18 @@ Note that amputating the affected organ does in fact remove the infection from t number_wounds += W.amount //things tend to bleed if they are CUT OPEN - if (open && !clamped && (H && !(H.species.flags & NO_BLOOD) && !(status & ORGAN_ROBOT))) + if (open && !clamped && can_bleed) status |= ORGAN_BLEEDING - if (istype(tendon)) + if (tendon) tendon.update_damage(cut_dam - min_broken_damage) update_damage_ratios() /obj/item/organ/external/proc/update_damage_ratios() var/limb_loss_threshold = max_damage * 2 - brute_ratio = Percent(brute_dam, limb_loss_threshold) - burn_ratio = Percent(burn_dam, limb_loss_threshold) + brute_ratio = AS_PCT(brute_dam, limb_loss_threshold) + burn_ratio = AS_PCT(burn_dam, limb_loss_threshold) // new damage icon system // returns just the brute/burn damage code @@ -1231,21 +1228,21 @@ Note that amputating the affected organ does in fact remove the infection from t // checks if all wounds on the organ are bandaged /obj/item/organ/external/proc/is_bandaged() - for(var/datum/wound/W in wounds) + for(var/datum/wound/W as anything in wounds) if(!W.bandaged) return 0 return 1 // checks if all wounds on the organ are salved /obj/item/organ/external/proc/is_salved() - for(var/datum/wound/W in wounds) + for(var/datum/wound/W as anything in wounds) if(!W.salved) return 0 return 1 // checks if all wounds on the organ are disinfected /obj/item/organ/external/proc/is_disinfected() - for(var/datum/wound/W in wounds) + for(var/datum/wound/W as anything in wounds) if(!W.disinfected) return 0 return 1 @@ -1253,21 +1250,21 @@ Note that amputating the affected organ does in fact remove the infection from t /obj/item/organ/external/proc/bandage() var/rval = 0 status &= ~ORGAN_BLEEDING - for(var/datum/wound/W in wounds) + for(var/datum/wound/W as anything in wounds) rval |= !W.bandaged W.bandage() return rval /obj/item/organ/external/proc/salve() var/rval = 0 - for(var/datum/wound/W in wounds) + for(var/datum/wound/W as anything in wounds) rval |= !W.salved W.salve() return rval /obj/item/organ/external/proc/disinfect() var/rval = 0 - for(var/datum/wound/W in wounds) + for(var/datum/wound/W as anything in wounds) rval |= !W.disinfected W.disinfect() W.germ_level = 0 @@ -1276,7 +1273,7 @@ Note that amputating the affected organ does in fact remove the infection from t /obj/item/organ/external/proc/clamp_organ() var/rval = 0 src.status &= ~ORGAN_BLEEDING - for(var/datum/wound/W in wounds) + for(var/datum/wound/W as anything in wounds) rval |= !W.clamped W.clamped = 1 return rval @@ -1396,7 +1393,7 @@ Note that amputating the affected organ does in fact remove the infection from t return max(brute_dam + burn_dam - perma_injury, perma_injury) //could use max_damage? /obj/item/organ/external/proc/has_infected_wound() - for(var/datum/wound/W in wounds) + for(var/datum/wound/W as anything in wounds) if(W.germ_level > INFECTION_LEVEL_ONE) return 1 return 0 @@ -1443,7 +1440,7 @@ Note that amputating the affected organ does in fact remove the infection from t SPAN_DANGER("\The [W] sticks in your wound!")) if(supplied_wound) - for(var/datum/wound/wound in wounds) + for(var/datum/wound/wound as anything in wounds) if ((wound.damage_type == INJURY_TYPE_CUT || wound.damage_type == INJURY_TYPE_PIERCE) && wound.damage >= W.w_class * 5) supplied_wound = wound break @@ -1570,7 +1567,7 @@ Note that amputating the affected organ does in fact remove the infection from t wound_descriptors["an open incision"] = 1 else if (open) wound_descriptors["an incision"] = 1 - for(var/datum/wound/W in wounds) + for(var/datum/wound/W as anything in wounds) var/this_wound_desc = W.desc if(W.damage_type == DAMAGE_BURN && W.salved) this_wound_desc = "salved [this_wound_desc]" diff --git a/code/modules/organs/subtypes/vaurca.dm b/code/modules/organs/subtypes/vaurca.dm index b4a5b2f24ad..e3f38124230 100644 --- a/code/modules/organs/subtypes/vaurca.dm +++ b/code/modules/organs/subtypes/vaurca.dm @@ -375,7 +375,7 @@ if ((istype(attacking_item, /obj/item/analyzer)) && get_dist(user, src) <= 1) user.visible_message(SPAN_WARNING("[user] has used [attacking_item] on [icon2html(icon, viewers(get_turf(user)))] [src].")) - var/pressure = air_contents.return_pressure() + var/pressure = XGM_PRESSURE(air_contents) manipulated_by = user.real_name //This person is aware of the contents of the tank. var/total_moles = air_contents.total_moles @@ -409,7 +409,7 @@ // this is the data which will be sent to the ui var/data[0] - data["tankPressure"] = round(air_contents.return_pressure() ? air_contents.return_pressure() : 0) + data["tankPressure"] = round(SAFE_XGM_PRESSURE(air_contents)) data["releasePressure"] = round(distribute_pressure ? distribute_pressure : 0) data["defaultReleasePressure"] = round(TANK_DEFAULT_RELEASE_PRESSURE) data["maxReleasePressure"] = round(TANK_MAX_RELEASE_PRESSURE) @@ -513,7 +513,7 @@ if(!air_contents) return null - var/tank_pressure = air_contents.return_pressure() + var/tank_pressure = XGM_PRESSURE(air_contents) if((tank_pressure < distribute_pressure) && prob(5)) to_chat(owner, SPAN_WARNING("There is a buzzing in your [parent_organ].")) @@ -534,7 +534,7 @@ if(!air_contents) return 0 - var/pressure = air_contents.return_pressure() + var/pressure = XGM_PRESSURE(air_contents) if(pressure > TANK_FRAGMENT_PRESSURE) if(!istype(src.loc,/obj/item/transfer_valve)) message_admins("Explosive tank rupture! last key to touch the tank was [src.fingerprintslast].") @@ -545,7 +545,7 @@ air_contents.react() air_contents.react() - pressure = air_contents.return_pressure() + pressure = XGM_PRESSURE(air_contents) var/range = (pressure-TANK_FRAGMENT_PRESSURE)/TANK_FRAGMENT_SCALE explosion( diff --git a/code/modules/organs/wounds/wound.dm b/code/modules/organs/wounds/wound.dm index 879d05e4e74..7ac788c95b3 100644 --- a/code/modules/organs/wounds/wound.dm +++ b/code/modules/organs/wounds/wound.dm @@ -104,16 +104,14 @@ if(LAZYLEN(embedded_objects)) return FALSE - return (wound_damage() <= autoheal_cutoff) ? TRUE : is_treated() + return ((src.damage / src.amount) <= autoheal_cutoff) ? TRUE : is_treated() /// Checks whether the wound has been appropriately treated /datum/wound/proc/is_treated() - if(!LAZYLEN(embedded_objects)) - switch(damage_type) - if(INJURY_TYPE_BRUISE, INJURY_TYPE_CUT, INJURY_TYPE_PIERCE) - return bandaged - if(INJURY_TYPE_BURN) - return salved + if(LAZYLEN(embedded_objects)) + return FALSE + + return damage_type == INJURY_TYPE_BURN ? salved : bandaged /// Checks whether other other can be merged into src. /datum/wound/proc/can_merge(datum/wound/other) @@ -144,7 +142,7 @@ /datum/wound/proc/infection_check() if (damage < 10) //small cuts, tiny bruises, and moderate burns shouldn't be infectable. return FALSE - if (is_treated() && damage < 25) //anything less than a flesh wound (or equivalent) isn't infectable if treated properly + if (damage < 25 && is_treated()) //anything less than a flesh wound (or equivalent) isn't infectable if treated properly return FALSE if (disinfected) germ_level = 0 //reset this, just in case @@ -186,7 +184,7 @@ amount -= healed_damage src.damage -= healed_damage - while(src.wound_damage() < damage_list[current_stage] && current_stage < length(src.desc_list)) + while((src.damage / src.amount) < damage_list[current_stage] && current_stage < length(src.desc_list)) current_stage++ desc = desc_list[current_stage] src.min_damage = damage_list[current_stage] @@ -226,14 +224,14 @@ return TRUE /datum/wound/proc/bleeding() - for(var/obj/item/thing in embedded_objects) + for(var/obj/item/thing as anything in embedded_objects) if(thing.w_class > WEIGHT_CLASS_SMALL) return FALSE if (bandaged||clamped) return FALSE - return ((bleed_timer > 0 || wound_damage() > bleed_threshold) && current_stage <= max_bleeding_stage) + return ((bleed_timer > 0 || (src.damage / src.amount) > bleed_threshold) && current_stage <= max_bleeding_stage) /// Called in organ_external.dm update_damages, this will update the limb's status to bleeding, and lowers the bleed_timer if applicable /datum/wound/proc/handle_bleeding(var/mob/victim, var/obj/item/organ/external/limb) diff --git a/code/modules/overmap/exoplanets/decor/turfs/water.dm b/code/modules/overmap/exoplanets/decor/turfs/water.dm index b4bc5a5f9a2..e2cff88ff21 100644 --- a/code/modules/overmap/exoplanets/decor/turfs/water.dm +++ b/code/modules/overmap/exoplanets/decor/turfs/water.dm @@ -165,7 +165,7 @@ var/obj/item/organ/external/E = A if(BP_IS_ROBOTIC(E)) continue - for(var/datum/wound/W in E.wounds) + for(var/datum/wound/W as anything in E.wounds) if(W.germ_level < INFECTION_LEVEL_ONE) W.germ_level = INFECTION_LEVEL_ONE W.germ_level += rand(10, 50) diff --git a/code/modules/overmap/exoplanets/exoplanet.dm b/code/modules/overmap/exoplanets/exoplanet.dm index 5adcd1b527c..4c43b1a824d 100644 --- a/code/modules/overmap/exoplanets/exoplanet.dm +++ b/code/modules/overmap/exoplanets/exoplanet.dm @@ -328,8 +328,8 @@ /obj/effect/overmap/visitable/sector/exoplanet/proc/adapt_seed(var/datum/seed/S) SET_SEED_TRAIT_BOUNDED(S, TRAIT_IDEAL_HEAT, atmosphere.temperature + rand(-5,5), 800, 70, null) SET_SEED_TRAIT_BOUNDED(S, TRAIT_HEAT_TOLERANCE, GET_SEED_TRAIT(S, TRAIT_HEAT_TOLERANCE) + rand(-5,5), 800, 70, null) - SET_SEED_TRAIT_BOUNDED(S, TRAIT_LOWKPA_TOLERANCE, atmosphere.return_pressure() + rand(-5,-50), 80, 0, null) - SET_SEED_TRAIT_BOUNDED(S, TRAIT_HIGHKPA_TOLERANCE, atmosphere.return_pressure() + rand(5,50), 500, 110, null) + SET_SEED_TRAIT_BOUNDED(S, TRAIT_LOWKPA_TOLERANCE, XGM_PRESSURE(atmosphere) + rand(-5,-50), 80, 0, null) + SET_SEED_TRAIT_BOUNDED(S, TRAIT_HIGHKPA_TOLERANCE, XGM_PRESSURE(atmosphere) + rand(5,50), 500, 110, null) SET_SEED_TRAIT(S, TRAIT_SPREAD, 0) if(S.exude_gasses) S.exude_gasses -= badgas @@ -508,7 +508,7 @@ gases += gas_data.name[g] extra_data += "Atmosphere composition: [english_list(gases)]" var/inaccuracy = rand(8,12)/10 - extra_data += "Atmosphere pressure: [atmosphere.return_pressure()*inaccuracy] kPa, temperature: [atmosphere.temperature*inaccuracy] K" + extra_data += "Atmosphere pressure: [XGM_PRESSURE(atmosphere)*inaccuracy] kPa, temperature: [atmosphere.temperature*inaccuracy] K" if(seeds.len) extra_data += "
Unrecognized xenoflora detected." diff --git a/code/modules/overmap/exoplanets/exoplanet_skybox.dm b/code/modules/overmap/exoplanets/exoplanet_skybox.dm index 67e9d35fe1e..0e1318e429d 100644 --- a/code/modules/overmap/exoplanets/exoplanet_skybox.dm +++ b/code/modules/overmap/exoplanets/exoplanet_skybox.dm @@ -21,7 +21,7 @@ water.SetTransform(rotation = rand(0, 360)) skybox_image.overlays += water - if (atmosphere && atmosphere.return_pressure() > SOUND_MINIMUM_PRESSURE) + if (SAFE_XGM_PRESSURE(atmosphere) > SOUND_MINIMUM_PRESSURE) var/atmo_color = get_atmosphere_color() if (!atmo_color) diff --git a/code/modules/overmap/ships/computers/sensors.dm b/code/modules/overmap/ships/computers/sensors.dm index 950973b5b3f..d2c9801bbc1 100644 --- a/code/modules/overmap/ships/computers/sensors.dm +++ b/code/modules/overmap/ships/computers/sensors.dm @@ -462,7 +462,7 @@ var/turf/T=get_turf(src) if(istype(T)) var/datum/gas_mixture/environment = T.return_air() - if(environment && environment.return_pressure() > MINIMUM_PRESSURE_DIFFERENCE_TO_SUSPEND) + if(SAFE_XGM_PRESSURE(environment) > MINIMUM_PRESSURE_DIFFERENCE_TO_SUSPEND) return 0 return 1 diff --git a/code/modules/overmap/ships/engines/gas_thruster.dm b/code/modules/overmap/ships/engines/gas_thruster.dm index 4d10e1eed52..1ec2c4e43dd 100644 --- a/code/modules/overmap/ships/engines/gas_thruster.dm +++ b/code/modules/overmap/ships/engines/gas_thruster.dm @@ -170,7 +170,7 @@ .+= "Propellant total mass: [round(air_contents.get_mass(),0.01)] kg." .+= "Propellant used per burn: [round(air_contents.get_mass() * volume_per_burn * thrust_limit / air_contents.volume,0.01)] kg." - .+= "Propellant pressure: [round(air_contents.return_pressure()/1000,0.1)] MPa." + .+= "Propellant pressure: [round(XGM_PRESSURE(air_contents)/1000,0.1)] MPa." . = jointext(.,"
") /obj/machinery/atmospherics/unary/engine/power_change() @@ -241,10 +241,12 @@ T = get_step(T, exhaust_dir) if(T) T.assume_air(removed) - new/obj/effect/engine_exhaust(T, dir, air_contents.check_combustibility() && air_contents.temperature >= PHORON_MINIMUM_BURN_TEMPERATURE) + var/is_cmb = 0 + CHECK_COMBUSTIBLE(is_cmb, air_contents) + new/obj/effect/engine_exhaust(T, dir, is_cmb && air_contents.temperature >= PHORON_MINIMUM_BURN_TEMPERATURE) /obj/machinery/atmospherics/unary/engine/proc/calculate_thrust(datum/gas_mixture/propellant, used_part = 1) - return round(sqrt(propellant.get_mass() * used_part * sqrt(air_contents.return_pressure()/200)),0.1) + return round(sqrt(propellant.get_mass() * used_part * sqrt(XGM_PRESSURE(air_contents)/200)),0.1) //Exhaust effect /obj/effect/engine_exhaust diff --git a/code/modules/power/antimatter/control.dm b/code/modules/power/antimatter/control.dm index d3dca02cf2e..a0e68791ab1 100644 --- a/code/modules/power/antimatter/control.dm +++ b/code/modules/power/antimatter/control.dm @@ -75,7 +75,7 @@ check_core_stability() - add_avail(stored_power) + ADD_TO_POWERNET(src, stored_power) power_cycle++ if(power_cycle >= power_cycle_delay) diff --git a/code/modules/power/apc.dm b/code/modules/power/apc.dm index ba7b2b7863d..5452f01f999 100644 --- a/code/modules/power/apc.dm +++ b/code/modules/power/apc.dm @@ -39,11 +39,23 @@ #define CHARGING_ON 1 #define CHARGING_FULL 2 -//channel settings -#define CHANNEL_OFF 0 -#define CHANNEL_OFF_AUTO 1 -#define CHANNEL_ON 2 -#define CHANNEL_ON_AUTO 3 +// APC channel status: +/// The APCs power channel is off. +#define CHANNEL_OFF 0 +/// The APCs power channel is on. +#define CHANNEL_ON BITFLAG(0) +/// The APCs power channel is being controlled automatically. +#define CHANNEL_AUTO BITFLAG(1) +/// The APCs power channel is automatically on. +#define CHANNEL_AUTO_ON (CHANNEL_ON | CHANNEL_AUTO) + +// APC autoset enums: +/// The APC turns automated and manual power channels off. +#define AUTOSET_FORCE_OFF 0 +/// The APC turns automated power channels off. +#define AUTOSET_OFF 2 +/// The APC turns automated power channels on. +#define AUTOSET_ON 1 //channel types #define CHANNEL_EQUIPMENT 0 @@ -60,6 +72,28 @@ #define AUTOFLAG_ENVIRON_ON 1 #define AUTOFLAG_ENVIRON_LIGHTS_ON 2 #define AUTOFLAG_ALL_ON 3 +/** + * Returns the new status value for an APC channel. + * + * Arguments: + * - val: The current status of the power channel. + * - [APC_CHANNEL_OFF]: The APCs channel has been manually set to off. This channel will not automatically change. + * - [APC_CHANNEL_AUTO_OFF]: The APCs channel is running on automatic and is currently off. Can be automatically set to [APC_CHANNEL_AUTO_ON]. + * - [APC_CHANNEL_ON]: The APCs channel has been manually set to on. This will be automatically changed only if the APC runs completely out of power or is disabled. + * - [APC_CHANNEL_AUTO_ON]: The APCs channel is running on automatic and is currently on. Can be automatically set to [APC_CHANNEL_AUTO_OFF]. + * - on: An enum dictating how to change the channel's status. + * - [AUTOSET_FORCE_OFF]: The APC forces the channel to turn off. This includes manually set channels. + * - [AUTOSET_ON]: The APC allows automatic channels to turn back on. + * - [AUTOSET_OFF]: The APC turns automatic channels off. + */ + +#define autoset(val, on) (((val & CHANNEL_AUTO) || on == AUTOSET_FORCE_OFF) ? ((val & ~CHANNEL_ON) | on == AUTOSET_ON) : val) + +#define APC_DELTA_POWER (((src.lastused_charging * 2) - src.lastused_total) * CELLRATE) +#define APC_GOAL(dp) (dp < 0) ? (cell.charge) : (cell.maxcharge - cell.charge) +#define APC_UPDATE_TIME(dp, goal) (world.time + (dp ? ((goal / abs(dp)) * (world.time - src.last_time)) : 0)) +#define APC_CHARGE_MODE(dp) (dp < 0 ? CHARGE_MODE_DISCHARGE : dp > 0 ? CHARGE_MODE_CHARGE : CHARGE_MODE_STABLE) + // the Area Power Controller (APC), formerly Power Distribution Unit (PDU) // one per area, needs wire conection to power network through a terminal @@ -93,9 +127,9 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) var/shorted = FALSE /// Determines if the light level is set to dimmed or not var/night_mode = FALSE - var/lighting = CHANNEL_ON_AUTO - var/equipment = CHANNEL_ON_AUTO - var/environ = CHANNEL_ON_AUTO + var/lighting = CHANNEL_AUTO_ON + var/equipment = CHANNEL_AUTO_ON + var/environ = CHANNEL_AUTO_ON var/infected = FALSE var/operating = TRUE var/charging = CHARGING_OFF @@ -188,7 +222,7 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) area.power_light = 0 area.power_equip = 0 area.power_environ = 0 - area.power_change() + SEND_SIGNAL(area, COMSIG_AREA_POWER_CHANGE) QDEL_NULL(wires) QDEL_NULL(terminal) if(cell) @@ -442,21 +476,21 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) if (equipment == CHANNEL_OFF) update_overlay |= APC_UPOVERLAY_EQUIPMENT0 - else if(equipment == CHANNEL_OFF_AUTO) + else if(equipment == CHANNEL_AUTO) update_overlay |= APC_UPOVERLAY_EQUIPMENT1 else if(equipment == CHANNEL_ON) update_overlay |= APC_UPOVERLAY_EQUIPMENT2 if(lighting == CHANNEL_OFF) update_overlay |= APC_UPOVERLAY_LIGHTING0 - else if(lighting == CHANNEL_OFF_AUTO) + else if(lighting == CHANNEL_AUTO) update_overlay |= APC_UPOVERLAY_LIGHTING1 else if(lighting == CHANNEL_ON) update_overlay |= APC_UPOVERLAY_LIGHTING2 if(environ == CHANNEL_OFF) update_overlay |= APC_UPOVERLAY_ENVIRON0 - else if(environ == CHANNEL_OFF_AUTO) + else if(environ == CHANNEL_AUTO) update_overlay |= APC_UPOVERLAY_ENVIRON1 else if(environ == CHANNEL_ON) update_overlay |= APC_UPOVERLAY_ENVIRON2 @@ -943,17 +977,25 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) ui.open() /obj/machinery/power/apc/proc/update() - if(operating && !shorted && !failure_timer) - area.power_light = (lighting > 1) - area.power_equip = (equipment > 1) - area.power_environ = (environ > 1) + var/old_lt = area.power_light + var/old_eq = area.power_equip + var/old_ev = area.power_environ - else + var/any_power = old_lt || old_eq || old_ev + + if(operating && !shorted && !failure_timer) + area.power_light = lighting & CHANNEL_ON + area.power_equip = equipment & CHANNEL_ON + area.power_environ = environ & CHANNEL_ON + + else if(any_power) area.power_light = FALSE area.power_equip = FALSE area.power_environ = FALSE playsound(src.loc, 'sound/machines/terminal/terminal_off.ogg', 50, FALSE) - area.power_change() + + if(old_lt != area.power_light || old_eq != area.power_equip || old_ev != area.power_environ) + SEND_SIGNAL(area, COMSIG_AREA_POWER_CHANGE) /obj/machinery/power/apc/proc/isWireCut(var/wireIndex) return wires.is_cut(wireIndex) @@ -1087,11 +1129,12 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) var/val = text2num(params["set"]) switch(params["chan"]) if("Equipment") - equipment = setsubsystem(val) + equipment = val if("Lighting") - lighting = setsubsystem(val) + lighting = val if("Environment") - environ = setsubsystem(val) + environ = val + autoflag = AUTOFLAG_OFF intent_message(BUTTON_FLICK, 5) playsound(src, 'sound/machines/terminal/terminal_select.ogg', 18, TRUE) update_icon() @@ -1137,39 +1180,25 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) visible_message(SPAN_DANGER("The [name] suddenly lets out a blast of smoke and some sparks!"), \ SPAN_DANGER("You hear sizzling electronics.")) - -/obj/machinery/power/apc/surplus() - return terminal?.surplus() - /obj/machinery/power/apc/proc/last_surplus() return terminal?.powernet?.last_surplus() -//Returns 1 if the APC should attempt to charge -/obj/machinery/power/apc/proc/attempt_charging() - return (chargemode && charging == CHARGING_ON && operating) - -/obj/machinery/power/apc/draw_power(var/amount) - return terminal?.powernet?.draw_power(amount) - -/obj/machinery/power/apc/avail() - return terminal?.avail() - /obj/machinery/power/apc/process(seconds_per_tick) if(stat & (BROKEN|MAINT)) return if(!area.requires_power) return - if(failure_timer) - update() - queue_icon_update() + if(failure_timer > 0) failure_timer-- - force_update = TRUE + if(!(update_state & UPDATE_BLUESCREEN)) + update() + SSicon_update.add_to_queue(src) return - lastused_light = area.usage(AREA_USAGE_LIGHT) - lastused_equip = area.usage(AREA_USAGE_EQUIP) - lastused_environ = area.usage(AREA_USAGE_ENVIRON) - area.clear_usage() + lastused_light = LIGHT_USAGE(area) + lastused_equip = EQUIP_USAGE(area) + lastused_environ = ENVIRON_USAGE(area) + CLEAR_USAGE(area) lastused_total = lastused_light + lastused_equip + lastused_environ @@ -1179,9 +1208,9 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) var/last_en = environ var/last_ch = charging - var/excess = surplus() + var/excess = POWER_SURPLUS(src.terminal) - if(!avail()) + if(POWER_AVAIL(src.terminal) <= 0) main_status = 0 else if(excess < 0) main_status = 1 @@ -1189,27 +1218,33 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) main_status = 2 if(cell && !shorted) - update_time() + var/delta_power = APC_DELTA_POWER + var/goal = APC_GOAL(delta_power) + time = APC_UPDATE_TIME(delta_power, goal) + last_time = world.time + charge_mode = APC_CHARGE_MODE(delta_power) // draw power from cell as before to power the area cellused = min(cell.charge, (CELLRATE * lastused_total)) // clamp deduction to a max, amount left in cell cell.use(cellused) var/draw = 0 if(excess > lastused_total) // if power excess recharge the cell // by the same amount just used - draw = draw_power(cellused/CELLRATE) // draw the power needed to charge this cell + draw = TERMINAL_POWER_DRAW(cellused/CELLRATE) // draw the power needed to charge this cell + TERMINAL_DRAW_POWER(draw) cell.give(draw * CELLRATE) else // no excess, and not enough per-apc if((cell.charge/CELLRATE + excess) >= lastused_total) // can we draw enough from cell+grid to cover last usage? - draw = draw_power(excess) + draw = TERMINAL_POWER_DRAW(excess) + TERMINAL_DRAW_POWER(draw) cell.charge = min(cell.maxcharge, cell.charge + CELLRATE * draw) //recharge with what we can charging = CHARGING_OFF else // not enough power available to run the last tick! charging = CHARGING_OFF chargecount = 0 // This turns everything off in the case that there is still a charge left on the battery, just not enough to run the room. - equipment = autoset(equipment, CHANNEL_OFF) - lighting = autoset(lighting, CHANNEL_OFF) - environ = autoset(environ, CHANNEL_OFF) + equipment = autoset(equipment, AUTOSET_FORCE_OFF) + lighting = autoset(lighting, AUTOSET_FORCE_OFF) + environ = autoset(environ, AUTOSET_FORCE_OFF) autoflag = AUTOFLAG_OFF // Set channels depending on how much charge we have left @@ -1217,12 +1252,13 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) // now trickle-charge the cell lastused_charging = 0 // Clear the variable for new use. - if(attempt_charging()) + if((chargemode && charging == CHARGING_ON && operating)) if(excess > 0) // check to make sure we have enough to charge // Max charge is capped to % per second constant var/ch = min(excess*CELLRATE, cell.maxcharge*chargelevel) - ch = draw_power(ch/CELLRATE) // Removes the power we're taking from the grid + ch = TERMINAL_POWER_DRAW(ch/CELLRATE) // Removes the power we're taking from the grid + TERMINAL_DRAW_POWER(ch) cell.give(ch*CELLRATE) // actually recharge the cell lastused_charging = ch + draw lastused_total += ch + draw // Sensors need this to stop reporting APC charging as "Other" load @@ -1254,19 +1290,19 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) else // no cell, switch everything off charging = CHARGING_OFF chargecount = 0 - equipment = autoset(equipment, CHANNEL_OFF) - lighting = autoset(lighting, CHANNEL_OFF) - environ = autoset(environ, CHANNEL_OFF) + equipment = autoset(equipment, AUTOSET_FORCE_OFF) + lighting = autoset(lighting, AUTOSET_FORCE_OFF) + environ = autoset(environ, AUTOSET_FORCE_OFF) GLOB.power_alarm.triggerAlarm(loc, src) autoflag = AUTOFLAG_OFF // update icon & area power if anything changed if(last_lt != lighting || last_eq != equipment || last_en != environ || force_update) force_update = FALSE - queue_icon_update() + SSicon_update.add_to_queue(src) update() else if (last_ch != charging) - queue_icon_update() + SSicon_update.add_to_queue(src) /obj/machinery/power/apc/proc/update_channels() // Allow the APC to operate as normal if the cell can charge @@ -1275,51 +1311,38 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) else if(longtermpower > -10) longtermpower -= 2 - if((cell.percent() > 30) || longtermpower > 0) // Put most likely at the top so we don't check it last, effeciency 101 - if(autoflag != AUTOFLAG_ALL_ON) - equipment = autoset(equipment, CHANNEL_OFF_AUTO) - lighting = autoset(lighting, CHANNEL_OFF_AUTO) - environ = autoset(environ, CHANNEL_OFF_AUTO) - autoflag = AUTOFLAG_ALL_ON - GLOB.power_alarm.clearAlarm(loc, src) - else if((cell.percent() <= 30) && (cell.percent() > 15) && longtermpower < 0) // <30%, turn off equipment - if(autoflag != AUTOFLAG_ENVIRON_LIGHTS_ON) - equipment = autoset(equipment, CHANNEL_ON) - lighting = autoset(lighting, CHANNEL_OFF_AUTO) - environ = autoset(environ, CHANNEL_OFF_AUTO) - GLOB.power_alarm.triggerAlarm(loc, src) - autoflag = AUTOFLAG_ENVIRON_LIGHTS_ON - else if(cell.percent() <= 15) // <15%, turn off lighting & equipment - if((autoflag > AUTOFLAG_ENVIRON_ON && longtermpower < 0) || (autoflag > AUTOFLAG_ENVIRON_ON && longtermpower >= 0)) - equipment = autoset(equipment, CHANNEL_ON) - lighting = autoset(lighting, CHANNEL_ON) - environ = autoset(environ, CHANNEL_OFF_AUTO) - GLOB.power_alarm.triggerAlarm(loc, src) - autoflag = AUTOFLAG_ENVIRON_ON + var/cell_charge = cell.maxcharge && ((cell.charge / cell.maxcharge) * 100.0) + + if((cell_charge > 30 || longtermpower > 0)) + if(autoflag == AUTOFLAG_ALL_ON) + return + equipment = autoset(equipment, AUTOSET_ON) + lighting = autoset(lighting, AUTOSET_ON) + environ = autoset(environ, AUTOSET_ON) + autoflag = AUTOFLAG_ALL_ON + GLOB.power_alarm.clearAlarm(loc, src) + else if(cell_charge > 15) // <30%, turn off equipment + if(autoflag == AUTOFLAG_ENVIRON_LIGHTS_ON) + return + equipment = autoset(equipment, AUTOSET_OFF) + lighting = autoset(lighting, AUTOSET_ON) + environ = autoset(environ, AUTOSET_ON) + GLOB.power_alarm.triggerAlarm(loc, src) + autoflag = AUTOFLAG_ENVIRON_LIGHTS_ON + else if(cell_charge <= 15) // <15%, turn off lighting & equipment + if(autoflag == AUTOFLAG_ENVIRON_ON) + return + equipment = autoset(equipment, AUTOSET_OFF) + lighting = autoset(lighting, AUTOSET_OFF) + environ = autoset(environ, AUTOSET_ON) + GLOB.power_alarm.triggerAlarm(loc, src) + autoflag = AUTOFLAG_ENVIRON_ON else // zero charge, turn all off - if(autoflag != AUTOFLAG_OFF) - equipment = autoset(equipment, CHANNEL_OFF) - lighting = autoset(lighting, CHANNEL_OFF) - environ = autoset(environ, CHANNEL_OFF) - GLOB.power_alarm.triggerAlarm(loc, src) - autoflag = AUTOFLAG_OFF - -/obj/machinery/power/apc/proc/autoset(var/val, var/on) - if(on == CHANNEL_EQUIPMENT) - if(val == CHANNEL_ON) - return CHANNEL_OFF - else if(val == CHANNEL_ON_AUTO) - return CHANNEL_OFF_AUTO - - else if(on == CHANNEL_LIGHTING) - if(val == CHANNEL_OFF_AUTO) - return CHANNEL_ON_AUTO - - else if(on == CHANNEL_ENVIRONMENT) - if(val == CHANNEL_ON_AUTO) - return CHANNEL_OFF_AUTO - - return val + equipment = autoset(equipment, AUTOSET_FORCE_OFF) + lighting = autoset(lighting, AUTOSET_FORCE_OFF) + environ = autoset(environ, AUTOSET_FORCE_OFF) + GLOB.power_alarm.triggerAlarm(loc, src) + autoflag = AUTOFLAG_OFF // damage and destruction acts /obj/machinery/power/apc/emp_act(severity) @@ -1328,9 +1351,9 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) if(cell) cell.emp_act(severity) - lighting = CHANNEL_OFF - equipment = CHANNEL_OFF - environ = CHANNEL_OFF + lighting = 0 + equipment = 0 + environ = 0 update() update_icon() @@ -1339,7 +1362,7 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) /obj/machinery/power/apc/proc/post_emp_act() update_channels() update() - queue_icon_update() + SSicon_update.add_to_queue(src) /obj/machinery/power/apc/ex_act(severity) switch(severity) @@ -1381,7 +1404,7 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) stat |= BROKEN operating = 0 failure_timer = 0 - queue_icon_update() + SSicon_update.add_to_queue(src) update() // overload the lights in this APC area @@ -1425,14 +1448,6 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) night_mode = !night_mode intent_message(BUTTON_FLICK, 5) -/obj/machinery/power/apc/proc/setsubsystem(val) - if(cell && cell.charge > 0) - return (val == CHANNEL_OFF_AUTO) ? CHANNEL_OFF : val - else if(val == CHANNEL_ON_AUTO) - return CHANNEL_OFF_AUTO - else - return CHANNEL_OFF - // Malfunction: Transfers APC under AI's control /obj/machinery/power/apc/proc/ai_hack(var/mob/living/silicon/ai/A = null) if(!A || !A.hacked_apcs || hacker || aidisabled || A.stat == DEAD) @@ -1443,21 +1458,6 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) update_icon() return TRUE -/obj/machinery/power/apc/proc/update_time() - - var/delta_power = (lastused_charging * 2) - lastused_total - delta_power *= CELLRATE - - var/goal = (delta_power < 0) ? (cell.charge) : (cell.maxcharge - cell.charge) - time = world.time + (delta_power ? ((goal / abs(delta_power)) * (world.time - last_time)) : 0) - // If it is negative - we are discharging - if(delta_power < 0) - charge_mode = CHARGE_MODE_DISCHARGE - else if(delta_power > 0) - charge_mode = CHARGE_MODE_CHARGE - else - charge_mode = CHARGE_MODE_STABLE - last_time = world.time /obj/machinery/power/apc/proc/manage_emergency(var/new_security_level) for(var/obj/machinery/M in area) @@ -1618,9 +1618,9 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) // Construction site APC, starts turned off /obj/machinery/power/apc/high/inactive cell_type = /obj/item/cell/high - lighting = CHANNEL_OFF - equipment = CHANNEL_OFF - environ = CHANNEL_OFF + lighting = 0 + equipment = 0 + environ = 0 locked = FALSE coverlocked = FALSE start_charge = 100 @@ -1733,9 +1733,9 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) #undef CHARGING_ON #undef CHARGING_FULL #undef CHANNEL_OFF -#undef CHANNEL_OFF_AUTO +#undef CHANNEL_AUTO #undef CHANNEL_ON -#undef CHANNEL_ON_AUTO +#undef CHANNEL_AUTO_ON #undef CHANNEL_EQUIPMENT #undef CHANNEL_LIGHTING #undef CHANNEL_ENVIRONMENT @@ -1746,3 +1746,8 @@ ABSTRACT_TYPE(/obj/machinery/power/apc) #undef AUTOFLAG_ENVIRON_ON #undef AUTOFLAG_ENVIRON_LIGHTS_ON #undef AUTOFLAG_ALL_ON +#undef autoset +#undef APC_DELTA_POWER +#undef APC_GOAL +#undef APC_UPDATE_TIME +#undef APC_CHARGE_MODE diff --git a/code/modules/power/batteryrack.dm b/code/modules/power/batteryrack.dm index d6358619926..c085146a182 100644 --- a/code/modules/power/batteryrack.dm +++ b/code/modules/power/batteryrack.dm @@ -156,7 +156,8 @@ if(terminal) if(input_attempt) var/target_load = min((capacity-charge)/SMESRATE, input_level) // charge at set rate, limited to spare capacity - var/actual_load = draw_power(target_load) // add the load to the terminal side network + var/actual_load = POWER_DRAW(src, target_load) // add the load to the terminal side network + DRAW_POWER(src, actual_load) charge += actual_load * SMESRATE // increase the charge if (actual_load >= target_load) // did the powernet have enough power available for us? @@ -167,7 +168,7 @@ if(output_attempt) // if outputting output_used = min( charge/SMESRATE, output_level) //limit output to that stored charge -= output_used*SMESRATE // reduce the storage (may be recovered in /restore() if excessive) - add_avail(output_used) // add output to powernet (smes side) + ADD_TO_POWERNET(src, output_used) // add output to powernet (smes side) if(charge < 0.0001) outputting(0) // stop output if charge falls to zero diff --git a/code/modules/power/cable.dm b/code/modules/power/cable.dm index 4fec198b13a..7f05b9278b5 100644 --- a/code/modules/power/cable.dm +++ b/code/modules/power/cable.dm @@ -62,10 +62,9 @@ By design, d1 is the smallest direction and d2 is the highest if(drain_check) return TRUE - var/datum/powernet/PN = powernet - if(!PN) return FALSE + . = POWERNET_POWER_DRAW(powernet, amount) - return PN.draw_power(amount) + DRAW_FROM_POWERNET(powernet, .) /obj/structure/cable/yellow color = COLOR_YELLOW @@ -563,7 +562,7 @@ By design, d1 is the smallest direction and d2 is the highest to_chat(user, SPAN_NOTICE("You don't have enough coils for this!")) return user.setClickCooldown(DEFAULT_ATTACK_COOLDOWN) - for(var/datum/wound/W in affecting.wounds) + for(var/datum/wound/W as anything in affecting.wounds) if(W.bandaged) continue if(W.current_stage <= W.max_bleeding_stage) diff --git a/code/modules/power/collector.dm b/code/modules/power/collector.dm index 88f4d4680f6..d8fd7eae13b 100644 --- a/code/modules/power/collector.dm +++ b/code/modules/power/collector.dm @@ -226,7 +226,7 @@ GLOBAL_LIST_INIT_TYPED(rad_collectors, /obj/machinery/power/rad_collector, list( if(loaded_tank && active) var/power_produced = 0 power_produced = min(100*loaded_tank.air_contents.gas[GAS_PHORON]*pulse_strength*pulse_coeff,max_power) - add_avail(power_produced) + ADD_TO_POWERNET(src, power_produced) last_power_new = power_produced return return diff --git a/code/modules/power/crystal_agitator.dm b/code/modules/power/crystal_agitator.dm index d66bbf0d513..41f111ecea6 100644 --- a/code/modules/power/crystal_agitator.dm +++ b/code/modules/power/crystal_agitator.dm @@ -73,7 +73,8 @@ toggle_active() return - var/actual_load = draw_power(active_power_usage) + var/actual_load = POWER_DRAW(src, active_power_usage) + DRAW_POWER(src, active_power_usage) if(actual_load < active_power_usage) toggle_active() return diff --git a/code/modules/power/fractal_reactor.dm b/code/modules/power/fractal_reactor.dm index 566aded8fda..e9857c837fe 100644 --- a/code/modules/power/fractal_reactor.dm +++ b/code/modules/power/fractal_reactor.dm @@ -26,4 +26,4 @@ powernet_connection_failed = 1 spawn(150) // Error! Check again in 15 seconds. powernet_connection_failed = 0 - add_avail(power_generation_rate) + ADD_TO_POWERNET(src, power_generation_rate) diff --git a/code/modules/power/fusion/consoles/core_control.dm b/code/modules/power/fusion/consoles/core_control.dm index e9bc490b1ae..23e373ff94e 100644 --- a/code/modules/power/fusion/consoles/core_control.dm +++ b/code/modules/power/fusion/consoles/core_control.dm @@ -53,7 +53,7 @@ for(var/i = 1 to LAZYLEN(fusion_cores)) var/list/core = list() var/obj/machinery/power/fusion_core/C = fusion_cores[i] - var/power_available = C.avail() + var/power_available = POWER_AVAIL(C) var/power_usage = C.active_power_usage var/power_generated = C.owned_field?.output_avg diff --git a/code/modules/power/fusion/core/_core.dm b/code/modules/power/fusion/core/_core.dm index 353a461bcfc..0c00aebab7f 100644 --- a/code/modules/power/fusion/core/_core.dm +++ b/code/modules/power/fusion/core/_core.dm @@ -141,6 +141,6 @@ connect_to_network() if(stat & BROKEN) return FALSE - if(idle_power_usage > avail()) + if(idle_power_usage > POWER_AVAIL(src)) return FALSE . = TRUE diff --git a/code/modules/power/fusion/core/core_field.dm b/code/modules/power/fusion/core/core_field.dm index 9a58ba1426d..af6e65c8672 100644 --- a/code/modules/power/fusion/core/core_field.dm +++ b/code/modules/power/fusion/core/core_field.dm @@ -221,7 +221,7 @@ output_archive_2 = output_archive_1 output_archive_1 = power_output output_avg = ((output_archive_1 + output_archive_2 + output_archive_3 + output_archive_4 + output_archive_5 ) / 5) - owned_core.add_avail(power_output) + ADD_TO_POWERNET(owned_core, power_output) // Roundstart update if(field_strength < 20) diff --git a/code/modules/power/fusion/gyrotron/gyrotron.dm b/code/modules/power/fusion/gyrotron/gyrotron.dm index a2db1fb1cdd..50dc191872d 100644 --- a/code/modules/power/fusion/gyrotron/gyrotron.dm +++ b/code/modules/power/fusion/gyrotron/gyrotron.dm @@ -34,7 +34,7 @@ return E /obj/machinery/power/emitter/gyrotron/update_icon() - if (active && powernet && avail(active_power_usage)) + if (active && powernet && POWER_AVAIL(src)) icon_state = "emitter-on" else icon_state = "emitter-off" diff --git a/code/modules/power/generator.dm b/code/modules/power/generator.dm index 198085538a2..b048726473e 100644 --- a/code/modules/power/generator.dm +++ b/code/modules/power/generator.dm @@ -163,7 +163,7 @@ if(genlev != lastgenlev) lastgenlev = genlev update_icon() - add_avail(effective_gen) + ADD_TO_POWERNET(src, effective_gen) /obj/machinery/power/generator/attack_ai(mob/user) if(!ai_can_interact(user)) @@ -210,9 +210,9 @@ data["primaryDir"] = vertical ? "top" : "left" data["primaryOutput"] = last_circ1_gen/1000 data["primaryFlowCapacity"] = circ1.volume_capacity_used*100 - data["primaryInletPressure"] = circ1.air1.return_pressure() + data["primaryInletPressure"] = XGM_PRESSURE(circ1.air1) data["primaryInletTemperature"] = circ1.air1.temperature - data["primaryOutletPressure"] = circ1.air2.return_pressure() + data["primaryOutletPressure"] = XGM_PRESSURE(circ1.air2) data["primaryOutletTemperature"] = circ1.air2.temperature if(circ2) @@ -220,9 +220,9 @@ data["secondaryDir"] = vertical ? "bottom" : "right" data["secondaryOutput"] = last_circ2_gen/1000 data["secondaryFlowCapacity"] = circ2.volume_capacity_used*100 - data["secondaryInletPressure"] = circ2.air1.return_pressure() + data["secondaryInletPressure"] = XGM_PRESSURE(circ2.air1) data["secondaryInletTemperature"] = circ2.air1.temperature - data["secondaryOutletPressure"] = circ2.air2.return_pressure() + data["secondaryOutletPressure"] = XGM_PRESSURE(circ2.air2) data["secondaryOutletTemperature"] = circ2.air2.temperature if(circ1 && circ2) diff --git a/code/modules/power/portgen.dm b/code/modules/power/portgen.dm index 1409b0c10d7..9a325b24487 100644 --- a/code/modules/power/portgen.dm +++ b/code/modules/power/portgen.dm @@ -53,8 +53,7 @@ /obj/machinery/power/portgen/process() if(active && HasFuel() && !IsBroken() && anchored) set_light(2, 1, l_color = portgen_lightcolour) - if(powernet) - add_avail(power_gen * power_output) + ADD_TO_POWERNET(src, power_gen * power_output) UseFuel() else set_light(0) @@ -215,7 +214,7 @@ if(!loc) return var/datum/gas_mixture/environment = loc.return_air() if (environment) - var/ratio = min(environment.return_pressure()/ONE_ATMOSPHERE, 1) + var/ratio = min(XGM_PRESSURE(environment)/ONE_ATMOSPHERE, 1) var/ambient = environment.temperature - T20C lower_limit += ambient*ratio upper_limit += ambient*ratio @@ -247,7 +246,7 @@ if(T) var/datum/gas_mixture/environment = T.return_air() if (environment) - var/ratio = min(environment.return_pressure()/ONE_ATMOSPHERE, 1) + var/ratio = min(XGM_PRESSURE(environment)/ONE_ATMOSPHERE, 1) var/ambient = environment.temperature - T20C cooling_temperature += ambient*ratio diff --git a/code/modules/power/power.dm b/code/modules/power/power.dm index e9fe6081723..20973556675 100644 --- a/code/modules/power/power.dm +++ b/code/modules/power/power.dm @@ -24,39 +24,6 @@ /////////////////////////////// // General procedures ////////////////////////////// - -// common helper procs for all power machines -/obj/machinery/power/drain_power(var/drain_check, var/surge, var/amount = 0) - if(drain_check) - return 1 - - if(powernet && powernet.avail) - powernet.trigger_warning() - return powernet.draw_power(amount) - -/obj/machinery/power/proc/add_avail(var/amount) - if(powernet) - powernet.newavail += amount - return 1 - return 0 - -/obj/machinery/power/proc/draw_power(var/amount) - if(powernet) - return powernet.draw_power(amount) - return 0 - -/obj/machinery/power/proc/surplus() - if(powernet) - return powernet.avail-powernet.load - else - return 0 - -/obj/machinery/power/proc/avail() - if(powernet) - return powernet.avail - else - return 0 - // Proc: power_wattage_readable() // Parameters: 1 (amount - Power in Watts to be converted to W, kW or MW) // Description: Helper proc that converts reading in Watts to kW or MW (returns string version of amount parameter) @@ -370,7 +337,8 @@ source_area.use_power_oneoff(drained_energy/CELLRATE) else if (istype(power_source,/datum/powernet)) var/drained_power = drained_energy/CELLRATE - drained_power = PN.draw_power(drained_power) + drained_power = POWERNET_POWER_DRAW(PN, drained_power) + DRAW_FROM_POWERNET(PN, drained_power) else if (istype(power_source, /obj/item/cell)) cell.use(drained_energy) return drained_energy diff --git a/code/modules/power/powernet.dm b/code/modules/power/powernet.dm index 8562b578bb8..b60d14aafda 100644 --- a/code/modules/power/powernet.dm +++ b/code/modules/power/powernet.dm @@ -39,11 +39,6 @@ /datum/powernet/proc/last_surplus() return max(avail - load, 0) -/datum/powernet/proc/draw_power(var/amount) - var/draw = between(0, amount, avail - load) - load += draw - return draw - /datum/powernet/proc/is_empty() return !cables.len && !nodes.len diff --git a/code/modules/power/radial_floodlight.dm b/code/modules/power/radial_floodlight.dm index 2f833807614..553b55990f2 100644 --- a/code/modules/power/radial_floodlight.dm +++ b/code/modules/power/radial_floodlight.dm @@ -28,7 +28,8 @@ update_icon() /obj/machinery/power/radial_floodlight/process() - var/actual_load = draw_power(active_power_usage) + var/actual_load = POWER_DRAW(src, active_power_usage) + DRAW_POWER(src, active_power_usage) if(!on || !anchored || (stat & BROKEN) || !powernet || actual_load < active_power_usage) STOP_PROCESSING_MACHINE(src, MACHINERY_PROCESS_SELF) update_use_power(POWER_USE_OFF) @@ -56,7 +57,7 @@ if(!powernet) to_chat(user, SPAN_WARNING("\The [src] isn't connected to a power network.")) return - if(avail() < active_power_usage) + if(POWER_AVAIL(src) < active_power_usage) to_chat(user, SPAN_WARNING("\The [src]'s power network doesn't have enough power.")) return toggle_active() diff --git a/code/modules/power/rtg.dm b/code/modules/power/rtg.dm index 5a7ec10e658..885e1ddc2d3 100644 --- a/code/modules/power/rtg.dm +++ b/code/modules/power/rtg.dm @@ -38,7 +38,7 @@ /obj/machinery/power/rtg/process() ..() - add_avail(power_gen) + ADD_TO_POWERNET(src, power_gen) if(panel_open && irradiate) for (var/mob/living/L in range(2, src)) L.apply_damage(10, DAMAGE_RADIATION, damage_flags = DAMAGE_FLAG_DISPERSED) // Weak but noticeable. diff --git a/code/modules/power/singularity/emitter.dm b/code/modules/power/singularity/emitter.dm index 327ad355910..43b1fe679ba 100644 --- a/code/modules/power/singularity/emitter.dm +++ b/code/modules/power/singularity/emitter.dm @@ -92,7 +92,7 @@ /obj/machinery/power/emitter/update_icon() ClearOverlays() - if(active && powernet && avail(active_power_usage)) + if(active && powernet && POWER_AVAIL(src)) AddOverlays(emissive_appearance(icon, "[icon_state]_lights")) AddOverlays("[icon_state]_lights") @@ -149,7 +149,8 @@ update_icon() return if(((last_shot + fire_delay) <= world.time) && active) - var/actual_load = draw_power(active_power_usage) + var/actual_load = POWER_DRAW(src, active_power_usage) + DRAW_POWER(src, actual_load) if(actual_load >= active_power_usage) //does the laser have enough power to shoot? if(!powered) powered = TRUE diff --git a/code/modules/power/smes.dm b/code/modules/power/smes.dm index 1f66c696353..73a5b3e5d26 100644 --- a/code/modules/power/smes.dm +++ b/code/modules/power/smes.dm @@ -175,13 +175,6 @@ return TRUE return FALSE -/obj/machinery/power/smes/add_avail(var/amount) - if(..(amount)) - powernet.smes_newavail += amount - return 1 - return 0 - - /obj/machinery/power/smes/disconnect_terminal() if(terminal) terminal.master = null @@ -236,7 +229,8 @@ var/inputted_power = target_load * (percentage/100) inputted_power = between(0, inputted_power, target_load) if(terminal && terminal.powernet) - inputted_power = terminal.powernet.draw_power(inputted_power) + inputted_power = TERMINAL_POWER_DRAW(inputted_power) + TERMINAL_DRAW_POWER(inputted_power) charge += inputted_power * SMESRATE input_taken = inputted_power if(percentage == 100) @@ -295,7 +289,7 @@ if(output_attempt && (!output_pulsed && !output_cut) && powernet && charge) output_used = min( charge/SMESRATE, output_level) //limit output to that stored charge -= output_used*SMESRATE // reduce the storage (may be recovered in /restore() if excessive) - add_avail(output_used) // add output to powernet (smes side) + SMES_ADD_TO_POWERNET(src, output_used) // add output to powernet (smes side) outputting = 2 else if(!powernet || !charge) outputting = 1 @@ -358,12 +352,6 @@ return 0 return 1 - -/obj/machinery/power/smes/draw_power(var/amount) - if(terminal && terminal.powernet) - return terminal.powernet.draw_power(amount) - return FALSE - /obj/machinery/power/smes/attack_ai(mob/user) if(!ai_can_interact(user)) return diff --git a/code/modules/power/solar.dm b/code/modules/power/solar.dm index 55c07486c49..fd60f32e8cd 100644 --- a/code/modules/power/solar.dm +++ b/code/modules/power/solar.dm @@ -125,7 +125,7 @@ if(obscured) //get no light from the sun, so don't generate power return var/sgen = SOLARGENRATE * sunfrac - add_avail(sgen) + ADD_TO_POWERNET(src, sgen) control.gen += sgen else //if we're no longer on the same powernet, remove from control computer unset_control() diff --git a/code/modules/power/tesla/coil.dm b/code/modules/power/tesla/coil.dm index 3435101be1e..f57084d6c0d 100644 --- a/code/modules/power/tesla/coil.dm +++ b/code/modules/power/tesla/coil.dm @@ -53,7 +53,7 @@ //don't lose arc power when it's not connected to anything //please place tesla coils all around the station to maximize effectiveness var/power_produced = powernet ? power / power_loss : power - add_avail(power_produced*input_power_multiplier) + ADD_TO_POWERNET(src, power_produced*input_power_multiplier) flick("coilhit", src) playsound(src.loc, 'sound/magic/LightningShock.ogg', 100, 1, extrarange = 5) tesla_zap(src, 5, power_produced) diff --git a/code/modules/power/turbine.dm b/code/modules/power/turbine.dm index 3a42c56118c..aab86f1e177 100644 --- a/code/modules/power/turbine.dm +++ b/code/modules/power/turbine.dm @@ -200,7 +200,7 @@ rpm = max(0, rpm - (rpm*rpm)/(COMPFRICTION*efficiency)) if(!(stat & NOPOWER)) - draw_power(2800) + DRAW_POWER(src, 2800) if(rpm < 1000) rpmtarget = 1000 else @@ -272,7 +272,7 @@ else lastgen = ((compressor.rpm / TURBPOWER) ** TURBCURVESHAPE) * TURBPOWER * productivity * POWER_CURVE_MOD - add_avail(lastgen) + ADD_TO_POWERNET(src, lastgen) var/newrpm = (compressor.gas_contained.temperature * compressor.gas_contained.total_moles) / 4 diff --git a/code/modules/projectiles/guns/launcher/pneumatic.dm b/code/modules/projectiles/guns/launcher/pneumatic.dm index 29a26dda8f0..4967a4f30cb 100644 --- a/code/modules/projectiles/guns/launcher/pneumatic.dm +++ b/code/modules/projectiles/guns/launcher/pneumatic.dm @@ -30,7 +30,7 @@ return . += "The valve is dialed to [pressure_setting]%." if(tank) - . += "The tank dial reads [tank.air_contents.return_pressure()] kPa." + . += "The tank dial reads [XGM_PRESSURE(tank.air_contents)] kPa." else . += "Nothing is attached to the tank valve!" @@ -101,9 +101,9 @@ if(T) var/datum/gas_mixture/environment = T.return_air() if(environment) - environment_pressure = environment.return_pressure() + environment_pressure = XGM_PRESSURE(environment) - fire_pressure = (tank.air_contents.return_pressure() - environment_pressure)*pressure_setting/100 + fire_pressure = (XGM_PRESSURE(tank.air_contents) - environment_pressure)*pressure_setting/100 if(fire_pressure < 10) to_chat(user, "There isn't enough gas in the tank to fire [src].") return null diff --git a/code/modules/recycling/disposal.dm b/code/modules/recycling/disposal.dm index b00028130e5..c06e09d7427 100644 --- a/code/modules/recycling/disposal.dm +++ b/code/modules/recycling/disposal.dm @@ -402,7 +402,7 @@ data["mode"] = mode data["uses_air"] = uses_air data["panel_open"] = panel_open - data["pressure"] = CLAMP01(air_contents.return_pressure() / (SEND_PRESSURE)) + data["pressure"] = CLAMP01(XGM_PRESSURE(air_contents) / (SEND_PRESSURE)) return data /obj/machinery/disposal/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state) @@ -507,13 +507,13 @@ update() // Validate whether we're pressurized or not. - if(mode == MODE_PRESSURIZING && air_contents.return_pressure() >= SEND_PRESSURE) + if(mode == MODE_PRESSURIZING && XGM_PRESSURE(air_contents) >= SEND_PRESSURE) mode = MODE_READY update() return // If you turn this into a bare 'else' statement it just tries to pressurize infinitely and I don't know why. - else if(mode == MODE_PRESSURIZING && air_contents.return_pressure() < SEND_PRESSURE) + else if(mode == MODE_PRESSURIZING && XGM_PRESSURE(air_contents) < SEND_PRESSURE) src.pressurize() update() return @@ -541,7 +541,7 @@ if (power_draw > 0) use_power_oneoff(power_draw) // If we've reached the target pressure, we're ready to flush - if(air_contents.return_pressure() >= SEND_PRESSURE) + if(XGM_PRESSURE(air_contents) >= SEND_PRESSURE) mode = MODE_READY /** diff --git a/code/modules/shieldgen/shield_capacitor.dm b/code/modules/shieldgen/shield_capacitor.dm index 29292452a1f..0fd4a0c647d 100644 --- a/code/modules/shieldgen/shield_capacitor.dm +++ b/code/modules/shieldgen/shield_capacitor.dm @@ -123,7 +123,8 @@ if (PN) var/power_draw = between(0, max_charge - stored_charge, charge_rate) //what we are trying to draw - power_draw = PN.draw_power(power_draw) //what we actually get + power_draw = POWERNET_POWER_DRAW(PN, power_draw) //what we actually get + DRAW_FROM_POWERNET(PN, power_draw) stored_charge += power_draw time_since_fail++ diff --git a/code/modules/shieldgen/shieldwallgen.dm b/code/modules/shieldgen/shieldwallgen.dm index 4525642e128..54b6944a9a4 100644 --- a/code/modules/shieldgen/shieldwallgen.dm +++ b/code/modules/shieldgen/shieldwallgen.dm @@ -85,7 +85,8 @@ return FALSE var/shieldload = between(500, max_stored_power - storedpower, (power_draw*seconds_per_tick)) //what we try to draw - shieldload = PN.draw_power(shieldload) //what we actually get + shieldload = POWERNET_POWER_DRAW(PN, shieldload) //what we actually get + DRAW_FROM_POWERNET(PN, shieldload) storedpower += shieldload //If we're still in the red, then there must not be enough available power to cover our load. diff --git a/code/modules/spell_system/spells/spell_list/others/generic/mend.dm b/code/modules/spell_system/spells/spell_list/others/generic/mend.dm index 33ecdbcf38c..d5ce416e045 100644 --- a/code/modules/spell_system/spells/spell_list/others/generic/mend.dm +++ b/code/modules/spell_system/spells/spell_list/others/generic/mend.dm @@ -47,7 +47,7 @@ user.visible_message(SPAN_NOTICE("\The [user] rests a hand on \the [target]'s [E.name].")) to_chat(target, SPAN_NOTICE("A healing warmth suffuses you.")) - for(var/datum/wound/W in E.wounds) + for(var/datum/wound/W as anything in E.wounds) if(W.bleeding()) to_chat(user, SPAN_NOTICE("You knit together severed veins and broken flesh, stemming the bleeding.")) W.bleed_timer = 0 diff --git a/code/modules/supermatter/supermatter.dm b/code/modules/supermatter/supermatter.dm index 9d663ef2ee7..45a3b71e3ec 100644 --- a/code/modules/supermatter/supermatter.dm +++ b/code/modules/supermatter/supermatter.dm @@ -385,7 +385,7 @@ if(loc && !istype(loc, /turf/space)) env = src.loc.return_air() data["ambient_temp"] = round(env?.temperature) - data["ambient_pressure"] = round(env?.return_pressure()) + data["ambient_pressure"] = round(SAFE_XGM_PRESSURE(env)) data["detonating"] = grav_pulling return data diff --git a/code/modules/ventcrawl/ventcrawl.dm b/code/modules/ventcrawl/ventcrawl.dm index 0d28a84ab2e..5b5a05db340 100644 --- a/code/modules/ventcrawl/ventcrawl.dm +++ b/code/modules/ventcrawl/ventcrawl.dm @@ -174,7 +174,7 @@ GLOBAL_LIST_INIT(can_enter_vent_with, list( if(BODYTEMP_HEAT_DAMAGE_LIMIT to INFINITY) to_chat(src, SPAN_DANGER("You feel a searing heat coming from the vent!")) - switch(vent_found.air_contents.return_pressure()) + switch(XGM_PRESSURE(vent_found.air_contents)) if(0 to HAZARD_LOW_PRESSURE) to_chat(src, SPAN_DANGER("You feel a rushing draw pulling you into the vent!")) if(HAZARD_LOW_PRESSURE to WARNING_LOW_PRESSURE) diff --git a/code/modules/weather/weather_effects.dm b/code/modules/weather/weather_effects.dm index f1b934fde2f..0f86d9934ae 100644 --- a/code/modules/weather/weather_effects.dm +++ b/code/modules/weather/weather_effects.dm @@ -1,7 +1,7 @@ /obj/abstract/weather_system/proc/get_movement_delay(var/datum/gas_mixture/env, var/travel_dir) // It's quiet. Too quiet. - if(!wind_direction || !base_wind_delay || !travel_dir || !env || env.return_pressure() < MIN_WIND_PRESSURE) + if(!wind_direction || !base_wind_delay || !travel_dir || !env || XGM_PRESSURE(env) < MIN_WIND_PRESSURE) return 0 // May the wind be always at your back! diff --git a/code/modules/weather/weather_wind.dm b/code/modules/weather/weather_wind.dm index e4624673dc0..0353a4d7999 100644 --- a/code/modules/weather/weather_wind.dm +++ b/code/modules/weather/weather_wind.dm @@ -30,7 +30,7 @@ var/turf/T = get_turf(M) if(istype(T)) var/datum/gas_mixture/environment = T.return_air() - if(environment && environment.return_pressure() >= MIN_WIND_PRESSURE) // Arbitrary low pressure bound. + if(SAFE_XGM_PRESSURE(environment) >= MIN_WIND_PRESSURE) // Arbitrary low pressure bound. var/absolute_strength = abs(wind_strength) if(absolute_strength <= 0.5 || !wind_direction) to_chat(M, SPAN_NOTICE("The wind is calm.")) diff --git a/code/modules/xgm/xgm_gas_mixture.dm b/code/modules/xgm/xgm_gas_mixture.dm index 2c31d9af1ec..ce3b6763288 100644 --- a/code/modules/xgm/xgm_gas_mixture.dm +++ b/code/modules/xgm/xgm_gas_mixture.dm @@ -216,14 +216,6 @@ else total_moles += gas[g] - -///Returns the pressure of the gas mix. Only accurate if there have been no gas modifications since update_values() has been called. -/datum/gas_mixture/proc/return_pressure() - if(volume) - return total_moles * R_IDEAL_GAS_EQUATION * temperature / volume - return 0 - - ///Removes moles from the gas mixture and returns a gas_mixture containing the removed air. /datum/gas_mixture/proc/remove(amount) amount = min(amount, total_moles * group_multiplier) //Can not take more air than the gas mixture has! @@ -332,7 +324,7 @@ return 0 marked[g] = 1 - if(abs(return_pressure() - sample.return_pressure()) > MINIMUM_PRESSURE_DIFFERENCE_TO_SUSPEND) + if(abs(XGM_PRESSURE(src) - XGM_PRESSURE(sample)) > MINIMUM_PRESSURE_DIFFERENCE_TO_SUSPEND) return 0 for(var/g in sample.gas) @@ -350,11 +342,6 @@ return 1 - -/datum/gas_mixture/proc/react() - zburn(null, force_burn=0, no_check=0) //could probably just call zburn() here with no args but I like being explicit. - - //Rechecks the gas_mixture and adjusts the graphic list if needed. //Two lists can be passed by reference if you need know specifically which graphics were added and removed. /datum/gas_mixture/proc/check_tile_graphic(list/graphic_add = null, list/graphic_remove = null) @@ -381,8 +368,10 @@ else if (heat_overlay in graphic) LAZYADD(graphic_remove, heat_overlay) + var/pressure = XGM_PRESSURE(src) + var/cold_overlay = get_tile_overlay(GAS_COLD) - if(temperature <= FOGGING_TEMPERATURE && (return_pressure() >= (ONE_ATMOSPHERE / 4))) + if(temperature <= FOGGING_TEMPERATURE && (pressure >= (ONE_ATMOSPHERE / 4))) if(!(cold_overlay in graphic)) LAZYADD(graphic_add, cold_overlay) else if (cold_overlay in graphic) @@ -396,7 +385,7 @@ graphic -= graphic_remove . = 1 if(length(graphic)) - var/pressure_mod = clamp(return_pressure() / ONE_ATMOSPHERE, 0, 2) + var/pressure_mod = clamp(pressure / ONE_ATMOSPHERE, 0, 2) for(var/obj/gas_overlay/O in graphic) if(istype(O, /obj/gas_overlay/heat)) //Heat based var/new_alpha = clamp(max(125, 255 * ((temperature - CARBON_LIFEFORM_FIRE_RESISTANCE) / CARBON_LIFEFORM_FIRE_RESISTANCE * 4)), 125, 255) diff --git a/code/unit_tests/zas_tests.dm b/code/unit_tests/zas_tests.dm index 0834a2879d9..b2b730a1e02 100644 --- a/code/unit_tests/zas_tests.dm +++ b/code/unit_tests/zas_tests.dm @@ -74,7 +74,7 @@ GLOBAL_LIST_EMPTY(turfs_to_map_type) var/t_msg = "Turf: [T] | Location: [T.x] // [T.y] // [T.z]" var/datum/gas_mixture/GM = T.return_air() - var/pressure = GM.return_pressure() + var/pressure = XGM_PRESSURE(GM) var/temp = GM.temperature diff --git a/html/changelogs/johnwildkins-lag4.yml b/html/changelogs/johnwildkins-lag4.yml new file mode 100644 index 00000000000..813b2462351 --- /dev/null +++ b/html/changelogs/johnwildkins-lag4.yml @@ -0,0 +1,13 @@ +# Your name. +author: JohnWildkins + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - refactor: "Rewrite several heavily-called functions to either inline statements or otherwise optimize to reduce server load." diff --git a/tgui/packages/tgui/interfaces/Apc.tsx b/tgui/packages/tgui/interfaces/Apc.tsx index 121232b0003..9e73c0a1574 100644 --- a/tgui/packages/tgui/interfaces/Apc.tsx +++ b/tgui/packages/tgui/interfaces/Apc.tsx @@ -184,22 +184,25 @@ export const APCWindow = (props, context) => {