Skip to content

Commit

Permalink
Nicer defines
Browse files Browse the repository at this point in the history
  • Loading branch information
JixS4v committed Sep 2, 2024
1 parent 8c77d0a commit 5faa2ae
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 40 deletions.
11 changes: 8 additions & 3 deletions code/__DEFINES/atmospherics/atmos_helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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);\
Expand Down
2 changes: 1 addition & 1 deletion code/datums/atmosphere/_atmosphere.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/effects/effect_system/effects_foam.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/effects/effect_system/effects_smoke.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions code/game/turfs/open/_open.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 21 additions & 21 deletions code/modules/atmospherics/gasmixtures/reactions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/atmospherics/machinery/datum_pipeline.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/events/spacevine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/simple_animal/bot/atmosbot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/mob/living/simple_animal/slime/life.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/power/singularity/collector.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions code/modules/surgery/organs/lungs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5faa2ae

Please sign in to comment.