[MIRROR] Fix gas overlays (#10944)

Co-authored-by: ShadowLarkens <shadowlarkens@gmail.com>
Co-authored-by: Cameron Lennox <killer65311@gmail.com>
This commit is contained in:
CHOMPStation2StaffMirrorBot
2025-05-24 18:42:45 -07:00
committed by GitHub
parent 1cd6e9fb41
commit 49f8cf7b8b
19 changed files with 69 additions and 110 deletions

View File

@@ -1,4 +1,4 @@
/var/datum/xgm_gas_data/gas_data
GLOBAL_DATUM_INIT(gas_data, /datum/xgm_gas_data, new())
/datum/xgm_gas_data
//Simple list of all the gas IDs.
@@ -16,6 +16,28 @@
//Flags.
var/list/flags = list()
/datum/xgm_gas_data/New()
. = ..()
for(var/p in subtypesof(/decl/xgm_gas))
var/decl/xgm_gas/gas = new p //avoid initial() because of potential New() actions
if(gas.id in gases)
error("Duplicate gas id `[gas.id]` in `[p]`")
gases += gas.id
name[gas.id] = gas.name
specific_heat[gas.id] = gas.specific_heat
molar_mass[gas.id] = gas.molar_mass
if(gas.tile_overlay)
var/atom/movable/gas_visuals/GV = new(null)
GV.icon_state = gas.tile_overlay
tile_overlay[gas.id] = GV
if(gas.overlay_limit)
overlay_limit[gas.id] = gas.overlay_limit
flags[gas.id] = gas.flags
return 1
/decl/xgm_gas
var/id = ""
var/name = "Unnamed Gas"
@@ -27,40 +49,7 @@
var/flags = 0
/hook/startup/proc/generateGasData()
gas_data = new
for(var/p in subtypesof(/decl/xgm_gas))
var/decl/xgm_gas/gas = new p //avoid initial() because of potential New() actions
if(gas.id in gas_data.gases)
error("Duplicate gas id `[gas.id]` in `[p]`")
gas_data.gases += gas.id
gas_data.name[gas.id] = gas.name
gas_data.specific_heat[gas.id] = gas.specific_heat
gas_data.molar_mass[gas.id] = gas.molar_mass
if(gas.tile_overlay)
gas_data.tile_overlay[gas.id] = gas.tile_overlay // CHOMPEdit
if(gas.overlay_limit)
gas_data.overlay_limit[gas.id] = gas.overlay_limit
gas_data.flags[gas.id] = gas.flags
return 1
// CHOMPEdit Start
/obj/effect/gas_overlay
name = "gas"
desc = "You shouldn't be clicking this."
/atom/movable/gas_visuals
icon = 'icons/effects/tile_effects.dmi'
icon_state = "generic"
layer = GASFIRE_LAYER
appearance_flags = PIXEL_SCALE | RESET_COLOR
mouse_opacity = 0
var/gas_id
/obj/effect/gas_overlay/Initialize(mapload, gas)
. = ..()
gas_id = gas
if(gas_data.tile_overlay[gas_id])
icon_state = gas_data.tile_overlay[gas_id]
// CHOMPEdit End
plane = ABOVE_MOB_PLANE

View File

@@ -13,9 +13,7 @@
var/group_multiplier = 1
//List of active tile overlays for this gas_mixture. Updated by check_tile_graphic()
var/list/graphic = list() // CHOMPAdd
var/list/tile_overlay_cache // COMPAdd
var/list/graphic
/datum/gas_mixture/New(vol = CELL_VOLUME)
volume = vol
@@ -42,7 +40,7 @@
if(moles > 0 && abs(temperature - temp) > MINIMUM_TEMPERATURE_DELTA_TO_CONSIDER)
var/self_heat_capacity = heat_capacity()
var/giver_heat_capacity = gas_data.specific_heat[gasid] * moles
var/giver_heat_capacity = GLOB.gas_data.specific_heat[gasid] * moles
var/combined_heat_capacity = giver_heat_capacity + self_heat_capacity
if(combined_heat_capacity != 0)
temperature = (temp * giver_heat_capacity + temperature * self_heat_capacity) / combined_heat_capacity
@@ -129,7 +127,7 @@
/datum/gas_mixture/proc/heat_capacity()
. = 0
for(var/g in gas)
. += gas_data.specific_heat[g] * gas[g]
. += GLOB.gas_data.specific_heat[g] * gas[g]
. *= group_multiplier
@@ -184,8 +182,8 @@
return SPECIFIC_ENTROPY_VACUUM //that gas isn't here
//group_multiplier gets divided out in volume/gas[gasid] - also, V/(m*T) = R/(partial pressure)
var/molar_mass = gas_data.molar_mass[gasid]
var/specific_heat = gas_data.specific_heat[gasid]
var/molar_mass = GLOB.gas_data.molar_mass[gasid]
var/specific_heat = GLOB.gas_data.specific_heat[gasid]
return R_IDEAL_GAS_EQUATION * ( log( (IDEAL_GAS_ENTROPY_CONSTANT*volume/(gas[gasid] * temperature)) * (molar_mass*specific_heat*temperature)**(2/3) + 1 ) + 15 )
//alternative, simpler equation
@@ -265,13 +263,13 @@
var/sum = 0
for(var/g in gas)
if(gas_data.flags[g] & flag)
if(GLOB.gas_data.flags[g] & flag)
sum += gas[g]
var/datum/gas_mixture/removed = new
for(var/g in gas)
if(gas_data.flags[g] & flag)
if(GLOB.gas_data.flags[g] & flag)
removed.gas[g] = QUANTIZE((gas[g] / sum) * amount)
gas[g] -= removed.gas[g] / group_multiplier
@@ -285,7 +283,7 @@
/datum/gas_mixture/proc/get_by_flag(flag)
. = 0
for(var/g in gas)
if(gas_data.flags[g] & flag)
if(GLOB.gas_data.flags[g] & flag)
. += gas[g]
//Copies gas and temperature from another gas_mixture.
@@ -337,34 +335,20 @@
zburn(null, force_burn=0, no_check=0) //could probably just call zburn() here with no args but I like being explicit.
// CHOMPEdit Start
//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)
// var/list/cur_graphic = graphic // Cache for sanic speed
for(var/obj/effect/gas_overlay/O in graphic)
if(gas[O.gas_id] <= gas_data.overlay_limit[O.gas_id])
LAZYADD(graphic_remove, O)
for(var/g in gas_data.overlay_limit)
/*
if(cur_graphic && cur_graphic.Find(gas_data.tile_overlay[g]))
var/list/cur_graphic = graphic // Cache for sanic speed
for(var/g in GLOB.gas_data.overlay_limit)
if(cur_graphic && cur_graphic.Find(GLOB.gas_data.tile_overlay[g]))
//Overlay is already applied for this gas, check if it's still valid.
if(gas[g] <= gas_data.overlay_limit[g])
LAZYADD(graphic_remove, gas_data.tile_overlay[g])
if(gas[g] <= GLOB.gas_data.overlay_limit[g])
LAZYADD(graphic_remove, GLOB.gas_data.tile_overlay[g])
else
//Overlay isn't applied for this gas, check if it's valid and needs to be added.
if(gas[g] > gas_data.overlay_limit[g])
LAZYADD(graphic_add, gas_data.tile_overlay[g])
*/
if(gas[g] > gas_data.overlay_limit[g])
var/tile_overlay = get_tile_overlay(g)
if(!(tile_overlay in graphic))
LAZYADD(graphic_add, tile_overlay)
if(gas[g] > GLOB.gas_data.overlay_limit[g])
LAZYADD(graphic_add, GLOB.gas_data.tile_overlay[g])
. = FALSE
/*
. = 0
//Apply changes
if(LAZYLEN(graphic_add))
@@ -373,14 +357,7 @@
if(LAZYLEN(graphic_remove))
LAZYREMOVE(graphic, graphic_remove)
. = 1
*/
if(graphic_add && graphic_add.len)
graphic |= graphic_add
. = TRUE
if(graphic_remove && graphic_remove.len)
graphic -= graphic_remove
. = TRUE
// CHOMPEdit End
//Simpler version of merge(), adjusts gas amounts directly and doesn't account for temperature or group_multiplier.
/datum/gas_mixture/proc/add(datum/gas_mixture/right_side)
@@ -399,12 +376,6 @@
update_values()
return 1
// Gets the gas overlay for a given gas, and returns the appropriate overlay. Caches. - CHOMPADD
/datum/gas_mixture/proc/get_tile_overlay(gas_id)
if(!LAZYACCESS(tile_overlay_cache, gas_id))
LAZYSET(tile_overlay_cache, gas_id, new/obj/effect/gas_overlay(null, gas_id))
return tile_overlay_cache[gas_id]
//Multiply all gas amounts by a factor.
/datum/gas_mixture/proc/multiply(factor)
@@ -518,4 +489,4 @@
/datum/gas_mixture/proc/get_mass()
for(var/g in gas)
. += gas[g] * gas_data.molar_mass[g] * group_multiplier
. += gas[g] * GLOB.gas_data.molar_mass[g] * group_multiplier