diff --git a/code/__DEFINES/atmospherics/atmos_helpers.dm b/code/__DEFINES/atmospherics/atmos_helpers.dm index 480dcbf5ee200..0eddefe55fd5e 100644 --- a/code/__DEFINES/atmospherics/atmos_helpers.dm +++ b/code/__DEFINES/atmospherics/atmos_helpers.dm @@ -80,16 +80,21 @@ GLOBAL_LIST_INIT(atmos_adjacent_savings, list(0,0)) ///Gets the moles of a specific gas in a gas mixture. #define GET_MOLES(gas, gas_mixture) (gas_mixture.gases[gas] ? gas_mixture.gases[gas][MOLES] : 0) -///Adjusts the moles of a specific gas in the mixture. Doesn't check if it goes under 0. -#define ADJUST_MOLES(gas, gas_mixture, moles)\ +///Adds moles to a specific gas in a gas mixture. +#define ADD_MOLES(gas, gas_mixture, moles)\ ASSERT_GAS(gas, gas_mixture);\ gas_mixture.gases[gas][MOLES] += moles; ///Removes moles while making sure it doesn't go under 0. -#define SAFE_REMOVE_MOLES(gas, gas_mixture, moles)\ +#define REMOVE_MOLES(gas, gas_mixture, moles)\ ASSERT_GAS(gas, gas_mixture);\ gas_mixture.gases[gas][MOLES] -= max(moles, 0); +/// Basically REMOVE_MOLES but with the thing sign flipped. Use this when sign is unknown +#define ADJUST_MOLES(gas, gas_mixture, moles)\ + ASSERT_GAS(gas, gas_mixture);\ + gas_mixture.gases[gas][MOLES] += max(moles, 0); + ///Sets the moles of a specific gas in a gas mixture, asserts the gas is present. #define SET_MOLES(gas, gas_mixture, moles)\ ASSERT_GAS(gas, gas_mixture);\ diff --git a/code/datums/atmosphere/_atmosphere.dm b/code/datums/atmosphere/_atmosphere.dm index 754e13507887d..521e5a74ff2c3 100644 --- a/code/datums/atmosphere/_atmosphere.dm +++ b/code/datums/atmosphere/_atmosphere.dm @@ -45,7 +45,7 @@ amount *= pressure_scalar // If we pick a really small target pressure we want roughly the same mix but less of it all amount = CEILING(amount, 0.1) - ADJUST_MOLES(gastype, gasmix, amount) + ADD_MOLES(gastype, gasmix, amount) // That last one put us over the limit, remove some of it while(gasmix.return_pressure() > target_pressure) diff --git a/code/game/objects/effects/effect_system/effects_foam.dm b/code/game/objects/effects/effect_system/effects_foam.dm index 223b5219b7cf6..58cfb9ad0ddb8 100644 --- a/code/game/objects/effects/effect_system/effects_foam.dm +++ b/code/game/objects/effects/effect_system/effects_foam.dm @@ -45,7 +45,7 @@ qdel(hotspot) var/datum/gas_mixture/G = T.air var/plas_amt = min(30,GET_MOLES(/datum/gas/plasma, G)) //Absorb some plasma - SAFE_REMOVE_MOLES(/datum/gas/plasma, G, plas_amt) + REMOVE_MOLES(/datum/gas/plasma, G, plas_amt) absorbed_plasma += plas_amt if(G.temperature > T20C) G.temperature = max(G.return_temperature()/2,T20C) diff --git a/code/game/objects/effects/effect_system/effects_smoke.dm b/code/game/objects/effects/effect_system/effects_smoke.dm index 4aaa1fc31b6e5..bef1f6710853c 100644 --- a/code/game/objects/effects/effect_system/effects_smoke.dm +++ b/code/game/objects/effects/effect_system/effects_smoke.dm @@ -180,7 +180,7 @@ for(var/obj/effect/hotspot/H in T) qdel(H) if(G.gases[/datum/gas/plasma][MOLES]) - ADJUST_MOLES(/datum/gas/nitrogen, G, G.gases[/datum/gas/plasma][MOLES]) + ADD_MOLES(/datum/gas/nitrogen, G, G.gases[/datum/gas/plasma][MOLES]) G.gases[/datum/gas/plasma][MOLES] = 0 if (weldvents) diff --git a/code/game/turfs/open/_open.dm b/code/game/turfs/open/_open.dm index 185c61dea24f5..338a421a1bcf7 100644 --- a/code/game/turfs/open/_open.dm +++ b/code/game/turfs/open/_open.dm @@ -284,9 +284,9 @@ . = ..() if (air.gases[/datum/gas/carbon_dioxide] && air.gases[/datum/gas/oxygen]) pulse_strength = min(pulse_strength,air.gases[/datum/gas/carbon_dioxide][MOLES]*1000,air.gases[/datum/gas/oxygen][MOLES]*2000) //Ensures matter is conserved properly - ADJUST_MOLES(/datum/gas/carbon_dioxide, air, (pulse_strength/1000)-air.gases[/datum/gas/carbon_dioxide][MOLES]) - ADJUST_MOLES(/datum/gas/oxygen, air, (pulse_strength/2000)-air.gases[/datum/gas/oxygen][MOLES]) - ADJUST_MOLES(/datum/gas/pluoxium, air, pulse_strength/4000) + ADD_MOLES(/datum/gas/carbon_dioxide, air, (pulse_strength/1000)-air.gases[/datum/gas/carbon_dioxide][MOLES]) + ADD_MOLES(/datum/gas/oxygen, air, (pulse_strength/2000)-air.gases[/datum/gas/oxygen][MOLES]) + ADD_MOLES(/datum/gas/pluoxium, air, pulse_strength/4000) /turf/open/proc/break_tile(force, allow_base) LAZYINITLIST(damage_overlays) diff --git a/code/modules/atmospherics/gasmixtures/reactions.dm b/code/modules/atmospherics/gasmixtures/reactions.dm index f5420d91e8436..48736e346cf10 100644 --- a/code/modules/atmospherics/gasmixtures/reactions.dm +++ b/code/modules/atmospherics/gasmixtures/reactions.dm @@ -125,8 +125,8 @@ if(burned_fuel) energy_released += (N2O_DECOMPOSITION_ENERGY_RELEASED * burned_fuel) - ADJUST_MOLES(/datum/gas/oxygen, air, burned_fuel * 0.5) - ADJUST_MOLES(/datum/gas/nitrogen, air, burned_fuel) + ADD_MOLES(/datum/gas/oxygen, air, burned_fuel * 0.5) + ADD_MOLES(/datum/gas/nitrogen, air, burned_fuel) var/new_heat_capacity = air.heat_capacity() if(new_heat_capacity > MINIMUM_HEAT_CAPACITY) @@ -162,7 +162,7 @@ burned_fuel = cached_gases[/datum/gas/oxygen][MOLES] / TRITIUM_BURN_OXY_FACTOR cached_gases[/datum/gas/tritium][MOLES] -= burned_fuel - ADJUST_MOLES(/datum/gas/water_vapor, air, burned_fuel/TRITIUM_BURN_OXY_FACTOR) + ADD_MOLES(/datum/gas/water_vapor, air, burned_fuel/TRITIUM_BURN_OXY_FACTOR) energy_released += (FIRE_HYDROGEN_ENERGY_RELEASED * burned_fuel) cached_results["fire"] += burned_fuel @@ -173,7 +173,7 @@ cached_gases[/datum/gas/tritium][MOLES] -= burned_fuel / TRITIUM_BURN_TRIT_FACTOR cached_gases[/datum/gas/oxygen][MOLES] -= burned_fuel - ADJUST_MOLES(/datum/gas/water_vapor, air, burned_fuel/TRITIUM_BURN_OXY_FACTOR) + ADD_MOLES(/datum/gas/water_vapor, air, burned_fuel/TRITIUM_BURN_OXY_FACTOR) energy_released += (FIRE_HYDROGEN_ENERGY_RELEASED * burned_fuel) cached_results["fire"] += burned_fuel * 10 @@ -253,10 +253,10 @@ cached_gases[/datum/gas/plasma][MOLES] = QUANTIZE(cached_gases[/datum/gas/plasma][MOLES] - plasma_burn_rate) cached_gases[/datum/gas/oxygen][MOLES] = QUANTIZE(cached_gases[/datum/gas/oxygen][MOLES] - (plasma_burn_rate * oxygen_burn_rate)) if (super_saturation) - ADJUST_MOLES(/datum/gas/tritium, air, plasma_burn_rate) + ADD_MOLES(/datum/gas/tritium, air, plasma_burn_rate) else - ADJUST_MOLES(/datum/gas/carbon_dioxide, air, plasma_burn_rate*0.75) - ADJUST_MOLES(/datum/gas/water_vapor, air, plasma_burn_rate*0.25) + ADD_MOLES(/datum/gas/carbon_dioxide, air, plasma_burn_rate*0.75) + ADD_MOLES(/datum/gas/water_vapor, air, plasma_burn_rate*0.25) energy_released += FIRE_PLASMA_ENERGY_RELEASED * (plasma_burn_rate) @@ -350,15 +350,15 @@ thermal_energy = middle_energy * 10 ** log(FUSION_ENERGY_TRANSLATION_EXPONENT, (thermal_energy + bowdlerized_reaction_energy) / middle_energy) //The reason why you should set up a tritium production line. - ADJUST_MOLES(/datum/gas/tritium, air, -FUSION_TRITIUM_MOLES_USED) + REMOVE_MOLES(/datum/gas/tritium, air, FUSION_TRITIUM_MOLES_USED) //The decay of the tritium and the reaction's energy produces waste gases, different ones depending on whether the reaction is endo or exothermic var/standard_waste_gas_output = scale_factor * (FUSION_TRITIUM_CONVERSION_COEFFICIENT*FUSION_TRITIUM_MOLES_USED) if(delta_plasma > 0) - ADJUST_MOLES(/datum/gas/water_vapor, air, standard_waste_gas_output) + ADD_MOLES(/datum/gas/water_vapor, air, standard_waste_gas_output) else - ADJUST_MOLES(/datum/gas/bz, air, standard_waste_gas_output) - ADJUST_MOLES(/datum/gas/oxygen, air, standard_waste_gas_output) //Oxygen is a bit touchy subject + ADD_MOLES(/datum/gas/bz, air, standard_waste_gas_output) + ADD_MOLES(/datum/gas/oxygen, air, standard_waste_gas_output) //Oxygen is a bit touchy subject if(reaction_energy) if(location) @@ -404,7 +404,7 @@ cached_gases[/datum/gas/oxygen][MOLES] -= heat_efficiency cached_gases[/datum/gas/nitrogen][MOLES] -= heat_efficiency cached_gases[/datum/gas/bz][MOLES] -= heat_efficiency * 0.05 //bz gets consumed to balance the nitryl production and not make it too common and/or easy - ADJUST_MOLES(/datum/gas/nitryl, air, heat_efficiency) + ADD_MOLES(/datum/gas/nitryl, air, heat_efficiency) if(energy_used > 0) var/new_heat_capacity = air.heat_capacity() @@ -433,10 +433,10 @@ if ((cached_gases[/datum/gas/nitrous_oxide][MOLES] - reaction_efficency < 0 )|| (cached_gases[/datum/gas/plasma][MOLES] - (2 * reaction_efficency) < 0) || energy_released <= 0) //Shouldn't produce gas from nothing. return NO_REACTION - ADJUST_MOLES(/datum/gas/bz, air, reaction_efficency * 2.5) + ADD_MOLES(/datum/gas/bz, air, reaction_efficency * 2.5) if(reaction_efficency == cached_gases[/datum/gas/nitrous_oxide][MOLES]) - cached_gases[/datum/gas/bz][MOLES] -= min(pressure, 0.5) - ADJUST_MOLES(/datum/gas/oxygen, air, min(pressure, 0.5)) + REMOVE_MOLES(/datum/gas/bz, air, min(pressure, 0.5)) + ADD_MOLES(/datum/gas/oxygen, air, min(pressure, 0.5)) cached_gases[/datum/gas/nitrous_oxide][MOLES] -= reaction_efficency cached_gases[/datum/gas/plasma][MOLES] -= 2 * reaction_efficency @@ -468,7 +468,7 @@ return NO_REACTION cached_gases[/datum/gas/tritium][MOLES] -= heat_scale cached_gases[/datum/gas/nitryl][MOLES] -= heat_scale - ADJUST_MOLES(/datum/gas/stimulum, air, heat_scale*0.75) + ADD_MOLES(/datum/gas/stimulum, air, heat_scale*0.75) if(stim_energy_change) var/new_heat_capacity = air.heat_capacity() @@ -535,11 +535,11 @@ var/pluox_used = min(STIM_BALL_GAS_AMOUNT/GET_MOLES(/datum/gas/plasma, air),GET_MOLES(/datum/gas/pluoxium, air)) var/energy_released = stim_used*STIMULUM_HEAT_SCALE//Stimulum has a lot of stored energy, and breaking it up releases some of it location.fire_nuclear_particle(ball_shot_angle) - ADJUST_MOLES(/datum/gas/carbon_dioxide, air, 4*pluox_used) - ADJUST_MOLES(/datum/gas/nitrogen, air, 8*stim_used) - ADJUST_MOLES(/datum/gas/pluoxium, air, -pluox_used) - ADJUST_MOLES(/datum/gas/stimulum, air, -stim_used) - ADJUST_MOLES(/datum/gas/plasma, air, -min(GET_MOLES(/datum/gas/plasma, air)/2,30)) + ADD_MOLES(/datum/gas/carbon_dioxide, air, 4*pluox_used) + ADD_MOLES(/datum/gas/nitrogen, air, 8*stim_used) + REMOVE_MOLES(/datum/gas/pluoxium, air, pluox_used) + REMOVE_MOLES(/datum/gas/stimulum, air, stim_used) + REMOVE_MOLES(/datum/gas/plasma, air, min(GET_MOLES(/datum/gas/plasma, air)/2,30)) if(energy_released) var/new_heat_capacity = air.heat_capacity() if(new_heat_capacity > MINIMUM_HEAT_CAPACITY) diff --git a/code/modules/atmospherics/machinery/datum_pipeline.dm b/code/modules/atmospherics/machinery/datum_pipeline.dm index c6691a56f9cb8..6a287b3ab859b 100644 --- a/code/modules/atmospherics/machinery/datum_pipeline.dm +++ b/code/modules/atmospherics/machinery/datum_pipeline.dm @@ -281,7 +281,7 @@ //gas transfer for(var/giver_id in giver_gases) var/giver_gas_data = giver_gases[giver_id] - ADJUST_MOLES(giver_id, total_gas_mixture, giver_gas_data[MOLES]) + ADD_MOLES(giver_id, total_gas_mixture, giver_gas_data[MOLES]) total_heat_capacity += giver_gas_data[MOLES] * giver_gas_data[GAS_META][META_GAS_SPECIFIC_HEAT] total_thermal_energy += THERMAL_ENERGY(gas_mixture) diff --git a/code/modules/events/spacevine.dm b/code/modules/events/spacevine.dm index 4db4dd687ac2c..0f0f0e18fc1b9 100644 --- a/code/modules/events/spacevine.dm +++ b/code/modules/events/spacevine.dm @@ -241,7 +241,7 @@ var/turf/open/floor/T = holder.loc if(istype(T)) var/datum/gas_mixture/GM = T.air - ADJUST_MOLES(/datum/gas/carbon_dioxide, GM, GET_MOLES(/datum/gas/carbon_dioxide, GM) - severity * holder.energy) + REMOVE_MOLES(/datum/gas/carbon_dioxide, GM, severity * holder.energy - GET_MOLES(/datum/gas/carbon_dioxide, GM)) /datum/spacevine_mutation/plasma_eater name = "toxins consuming" diff --git a/code/modules/mob/living/simple_animal/bot/atmosbot.dm b/code/modules/mob/living/simple_animal/bot/atmosbot.dm index 7b5e4529bf5c5..6afcf1fb5cd0b 100644 --- a/code/modules/mob/living/simple_animal/bot/atmosbot.dm +++ b/code/modules/mob/living/simple_animal/bot/atmosbot.dm @@ -230,7 +230,7 @@ for(var/G in gasses) if(gasses[G]) var/moles_in_atmos = GET_MOLES(G, environment) - ADJUST_MOLES(G, environment, -min(moles_in_atmos, ATMOSBOT_MAX_SCRUB_CHANGE)) + REMOVE_MOLES(G, environment, min(moles_in_atmos, ATMOSBOT_MAX_SCRUB_CHANGE)) /mob/living/simple_animal/bot/atmosbot/proc/deploy_holobarrier() if(deployed_holobarrier) diff --git a/code/modules/mob/living/simple_animal/slime/life.dm b/code/modules/mob/living/simple_animal/slime/life.dm index ee9e1e35d71b5..80599f13d597d 100644 --- a/code/modules/mob/living/simple_animal/slime/life.dm +++ b/code/modules/mob/living/simple_animal/slime/life.dm @@ -100,8 +100,8 @@ if(transformeffects & SLIME_EFFECT_DARK_PURPLE) var/amt = is_adult ? 30 : 15 var/plas_amt = min(amt,GET_MOLES(/datum/gas/plasma, environment)) - ADJUST_MOLES(/datum/gas/plasma, environment, -plas_amt) - ADJUST_MOLES(/datum/gas/oxygen, environment, plas_amt) + REMOVE_MOLES(/datum/gas/plasma, environment, plas_amt) + ADD_MOLES(/datum/gas/oxygen, environment, plas_amt) adjustBruteLoss(plas_amt ? -2 : 0) switch(stat) diff --git a/code/modules/power/singularity/collector.dm b/code/modules/power/singularity/collector.dm index 3d1324670f89e..b483f923b6897 100644 --- a/code/modules/power/singularity/collector.dm +++ b/code/modules/power/singularity/collector.dm @@ -59,8 +59,8 @@ eject() else var/gasdrained = min(powerproduction_drain*drainratio*delta_time,GET_MOLES(/datum/gas/plasma, loaded_tank.air_contents)) - ADJUST_MOLES(/datum/gas/plasma, loaded_tank.air_contents, -gasdrained) - ADJUST_MOLES(/datum/gas/tritium, loaded_tank.air_contents, gasdrained) + REMOVE_MOLES(/datum/gas/plasma, loaded_tank.air_contents, gasdrained) + ADD_MOLES(/datum/gas/tritium, loaded_tank.air_contents, gasdrained) var/power_produced = RAD_COLLECTOR_OUTPUT add_avail(power_produced) stored_energy-=power_produced diff --git a/code/modules/research/xenobiology/crossbreeding/_structures.dm b/code/modules/research/xenobiology/crossbreeding/_structures.dm index 1e02629c418aa..2ddb3e7931dc7 100644 --- a/code/modules/research/xenobiology/crossbreeding/_structures.dm +++ b/code/modules/research/xenobiology/crossbreeding/_structures.dm @@ -237,7 +237,7 @@ GLOBAL_LIST_EMPTY(bluespace_slime_crystals) var/datum/gas_mixture/air = open_turf.return_air() if(GET_MOLES(/datum/gas/plasma, air) > 15) - ADJUST_MOLES(/datum/gas/plasma, air, -15) + REMOVE_MOLES(/datum/gas/plasma, air, 15) new /obj/item/stack/sheet/mineral/plasma(open_turf) /obj/structure/slime_crystal/darkpurple/Destroy() diff --git a/code/modules/surgery/organs/lungs.dm b/code/modules/surgery/organs/lungs.dm index c5d09c8a8e11b..2a4c4c2e118d5 100644 --- a/code/modules/surgery/organs/lungs.dm +++ b/code/modules/surgery/organs/lungs.dm @@ -291,14 +291,14 @@ if (gas_breathed > gas_stimulation_min) H.reagents.add_reagent(/datum/reagent/nitryl,1) - SAFE_REMOVE_MOLES(/datum/gas/nitryl, breath, gas_breathed) + REMOVE_MOLES(/datum/gas/nitryl, breath, gas_breathed) // Stimulum gas_breathed = PP(breath,/datum/gas/stimulum) if (gas_breathed > gas_stimulation_min) var/existing = H.reagents.get_reagent_amount(/datum/reagent/stimulum) H.reagents.add_reagent(/datum/reagent/stimulum, max(0, 5 - existing)) - SAFE_REMOVE_MOLES(/datum/gas/stimulum, breath, gas_breathed) + REMOVE_MOLES(/datum/gas/stimulum, breath, gas_breathed) handle_breath_temperature(breath, H) return TRUE