Skip to content

Commit b8c6afb

Browse files
authored
Merge pull request #5209 from MistakeNot4892/tweak/reagents
Replacing direct access to /datum/reagents vars with macros.
2 parents 0cdfd81 + 7f780a5 commit b8c6afb

File tree

230 files changed

+1156
-1071
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+1156
-1071
lines changed

code/__defines/chemistry.dm

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,30 @@
7878
#define HANDLE_REACTIONS(_reagents) if(!QDELETED(_reagents)) { SSmaterials.active_holders[_reagents] = TRUE; }
7979
#define UNQUEUE_REACTIONS(_reagents) SSmaterials.active_holders -= _reagents
8080

81-
#define REAGENT_LIST(R) (R.reagents?.get_reagents() || "No reagent holder")
81+
#define REAGENT_LIST(R) ((istype(R, /datum/reagents) && R:get_reagents()) || "No reagent holder")
82+
83+
#define REAGENT_TOTAL_VOLUME(R) (UNLINT((istype(R, /datum/reagents) && R:total_volume) || 0))
84+
#define REAGENT_TOTAL_LIQUID_VOLUME(R) (UNLINT((istype(R, /datum/reagents) && R:total_liquid_volume) || 0))
85+
86+
#define REAGENT_MAXIMUM_VOLUME(R) (UNLINT((istype(R, /datum/reagents) && R:maximum_volume) || 0))
87+
#define REAGENTS_FREE_SPACE(R) (UNLINT(istype(R, /datum/reagents) ? (R.maximum_volume - R.total_volume) : 0))
88+
89+
#define REAGENT_VOLUMES(R) ( (istype(R, /datum/reagents) && UNLINT(R:reagent_volumes)) || null )
90+
#define REAGENT_SOLID_VOLUMES(R) ( (istype(R, /datum/reagents) && UNLINT(R:solid_volumes)) || null )
91+
#define REAGENT_LIQUID_VOLUMES(R) ( (istype(R, /datum/reagents) && UNLINT(R:liquid_volumes)) || null )
92+
#define REAGENT_GET_MAX_VOL(R) ( (istype(R, /datum/reagents) && UNLINT(R:maximum_volume)) || 0 )
93+
#define REAGENT_GET_ATOM(R) ( (istype(R, /datum/reagents) && UNLINT(R:my_atom)) || null )
94+
95+
#define REAGENT_VOLUME(R, M) ( istype(R, /datum/reagents) && UNLINT(R:reagent_volumes && R:reagent_volumes[RESOLVE_TO_DECL(M)]) )
96+
#define LIQUID_VOLUME(R, M) ( istype(R, /datum/reagents) && UNLINT(R:liquid_volumes && R:liquid_volumes[RESOLVE_TO_DECL(M)]) )
97+
#define SOLID_VOLUME(R, M) ( istype(R, /datum/reagents) && UNLINT(R:solid_volumes && R:solid_volumes[RESOLVE_TO_DECL(M)]) )
98+
#define REAGENT_DATA(R, M) ( istype(R, /datum/reagents) && UNLINT(R:reagent_data && R:reagent_data[RESOLVE_TO_DECL(M)]) )
99+
100+
#define REAGENT_SET_MAX_VOL(R, V) if(istype(R, /datum/reagents)) { UNLINT(R:maximum_volume = V) }
101+
#define REAGENT_ADD_MAX_VOL(R, V) if(istype(R, /datum/reagents)) { UNLINT(R:maximum_volume += V) }
102+
#define REAGENT_SET_ATOM(R, A) if(istype(R, /datum/reagents)) { UNLINT(R:my_atom = A) }
103+
#define REAGENT_SET_DATA(R, M, D) if(istype(R, /datum/reagents)) { LAZYSET(UNLINT(R:reagent_data), M, D) }
82104

83-
#define REAGENTS_FREE_SPACE(R) (R?.maximum_volume - R?.total_volume)
84-
#define REAGENT_VOLUME(REAGENT_HOLDER, REAGENT_TYPE) (REAGENT_HOLDER?.reagent_volumes && REAGENT_HOLDER.reagent_volumes[RESOLVE_TO_DECL(REAGENT_TYPE)])
85-
#define LIQUID_VOLUME(REAGENT_HOLDER, REAGENT_TYPE) (REAGENT_HOLDER?.liquid_volumes && REAGENT_HOLDER.liquid_volumes[RESOLVE_TO_DECL(REAGENT_TYPE)])
86-
#define SOLID_VOLUME(REAGENT_HOLDER, REAGENT_TYPE) (REAGENT_HOLDER?.solid_volumes && REAGENT_HOLDER.solid_volumes[RESOLVE_TO_DECL(REAGENT_TYPE)])
87-
#define REAGENT_DATA(REAGENT_HOLDER, REAGENT_TYPE) (REAGENT_HOLDER?.reagent_data && REAGENT_HOLDER.reagent_data[RESOLVE_TO_DECL(REAGENT_TYPE)])
88105

89106
#define CHEM_DOSE(M, R) LAZYACCESS(M._chem_doses, RESOLVE_TO_DECL(R))
90107

code/_helpers/medical_scans.dm

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@
4242
.["immune_system"] = get_immunity()
4343
.["reagents"] = list()
4444

45-
if(reagents?.total_volume)
46-
for(var/decl/material/reagent as anything in reagents.liquid_volumes)
45+
if(REAGENT_TOTAL_VOLUME(reagents))
46+
for(var/decl/material/reagent as anything in REAGENT_LIQUID_VOLUMES(reagents))
4747
var/list/reagent_data = list()
4848
reagent_data["name"] = reagent.get_reagent_name(reagents, MAT_PHASE_LIQUID)
4949
reagent_data["quantity"] = round(REAGENT_VOLUME(reagents, reagent),1)
5050
reagent_data["scannable"] = reagent.scannable
5151
.["reagents"] += list(reagent_data)
52-
53-
for(var/decl/material/reagent as anything in reagents.solid_volumes)
52+
for(var/decl/material/reagent as anything in REAGENT_SOLID_VOLUMES(reagents))
5453
var/list/reagent_data = list()
5554
reagent_data["name"] = reagent.get_reagent_name(reagents, MAT_PHASE_SOLID)
5655
reagent_data["quantity"] = round(REAGENT_VOLUME(reagents, reagent),1)
@@ -98,8 +97,8 @@
9897
.["blood_pressure"] = get_blood_pressure()
9998
.["blood_o2"] = get_blood_oxygenation()
10099
if(vessel)
101-
.["blood_volume"] = vessel.total_volume
102-
.["blood_volume_max"] = vessel.maximum_volume
100+
.["blood_volume"] = REAGENT_TOTAL_VOLUME(vessel)
101+
.["blood_volume_max"] = REAGENT_MAXIMUM_VOLUME(vessel)
103102

104103
/proc/display_medical_data_header(var/list/scan, skill_level = SKILL_DEFAULT)
105104
//In case of problems, abort.

code/controllers/subsystems/fluids.dm

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ SUBSYSTEM_DEF(fluids)
100100
i++
101101
current_fluid_holder = processing_fluids[i]
102102

103-
if(QDELETED(current_fluid_holder) || !current_fluid_holder.reagents?.total_volume)
103+
if(QDELETED(current_fluid_holder) || !REAGENT_TOTAL_VOLUME(current_fluid_holder.reagents))
104104
REMOVE_ACTIVE_FLUID(current_fluid_holder)
105105
continue
106106

@@ -110,7 +110,7 @@ SUBSYSTEM_DEF(fluids)
110110

111111
reagent_holder = current_fluid_holder.reagents
112112
UPDATE_FLUID_BLOCKED_DIRS(current_fluid_holder)
113-
current_depth = reagent_holder?.total_volume || 0
113+
current_depth = REAGENT_TOTAL_VOLUME(reagent_holder)
114114

115115
// How is this happening
116116
if(QDELETED(reagent_holder) || current_depth == -1.#IND || current_depth == 1.#IND)
@@ -123,7 +123,7 @@ SUBSYSTEM_DEF(fluids)
123123
current_depth = current_fluid_holder.get_fluid_depth()
124124

125125
// Mimimum liquid depth for creation of slurries. Do this after evaporation since it may change the total depth.
126-
if(reagent_holder?.total_liquid_volume < FLUID_SLURRY)
126+
if(REAGENT_TOTAL_LIQUID_VOLUME(reagent_holder) < FLUID_SLURRY)
127127
current_fluid_holder.dump_solid_reagents()
128128
current_depth = current_fluid_holder.get_fluid_depth()
129129

@@ -135,7 +135,7 @@ SUBSYSTEM_DEF(fluids)
135135
// Wash our turf.
136136
current_fluid_holder.fluid_act(reagent_holder)
137137

138-
if(isspaceturf(current_fluid_holder) || (istype(current_fluid_holder, /turf/floor) && (current_fluid_holder.turf_flags & TURF_FLAG_ABSORB_LIQUID) && (current_fluid_holder.reagents?.total_volume + current_fluid_holder.get_physical_height()) > 0))
138+
if(isspaceturf(current_fluid_holder) || (istype(current_fluid_holder, /turf/floor) && (current_fluid_holder.turf_flags & TURF_FLAG_ABSORB_LIQUID) && (REAGENT_TOTAL_VOLUME(current_fluid_holder.reagents) + current_fluid_holder.get_physical_height()) > 0))
139139
removing = round(current_depth * 0.5)
140140
if(removing > 0)
141141
current_fluid_holder.remove_fluids(removing, defer_update = TRUE)
@@ -154,8 +154,9 @@ SUBSYSTEM_DEF(fluids)
154154
if(other_fluid_holder)
155155
UPDATE_FLUID_BLOCKED_DIRS(other_fluid_holder)
156156
if(!(other_fluid_holder.fluid_blocked_dirs & UP) && other_fluid_holder.CanFluidPass(UP))
157-
if(!QDELETED(other_fluid_holder) && other_fluid_holder.reagents?.total_volume < FLUID_MAX_DEPTH)
158-
current_fluid_holder.transfer_fluids_to(other_fluid_holder, min(floor(current_depth*0.5), FLUID_MAX_DEPTH - other_fluid_holder.reagents?.total_volume))
157+
var/other_volume = REAGENT_TOTAL_VOLUME(other_fluid_holder.reagents)
158+
if(!QDELETED(other_fluid_holder) && other_volume < FLUID_MAX_DEPTH)
159+
current_fluid_holder.transfer_fluids_to(other_fluid_holder, min(floor(current_depth*0.5), FLUID_MAX_DEPTH - other_volume))
159160
current_depth = current_fluid_holder.get_fluid_depth()
160161

161162
// Flow into the lowest level neighbor.
@@ -173,7 +174,7 @@ SUBSYSTEM_DEF(fluids)
173174
if((neighbor.fluid_blocked_dirs & coming_from) || !neighbor.CanFluidPass(coming_from) || neighbor.is_flooded(absolute = TRUE) || !neighbor.CanFluidPass(global.reverse_dir[spread_dir]))
174175
continue
175176
other_fluid_holder = neighbor
176-
neighbor_depth = (other_fluid_holder?.reagents?.total_volume || 0) + neighbor.get_physical_height()
177+
neighbor_depth = (REAGENT_TOTAL_VOLUME(other_fluid_holder.reagents)) + neighbor.get_physical_height()
177178
flow_amount = round((current_turf_depth - neighbor_depth)*0.5)
178179
// TODO: multiply flow amount or minimum transfer amount by some
179180
// viscosity calculation to allow for piles of jelly vs piles of water.
@@ -235,7 +236,7 @@ SUBSYSTEM_DEF(fluids)
235236
if(current_fluid_holder.last_flow_strength >= 10)
236237
// Catwalks mean items will be above the turf; subtract the turf height from our volume.
237238
// TODO: somehow handle stuff that is on a catwalk or on the turf within the same turf.
238-
var/effective_volume = current_fluid_holder.reagents?.total_volume
239+
var/effective_volume = REAGENT_TOTAL_VOLUME(current_fluid_holder.reagents)
239240
if(current_fluid_holder.get_supporting_platform())
240241
// Depth is negative height, hence +=. TODO: positive heights? No idea how to handle that.
241242
effective_volume += current_fluid_holder.get_physical_height()

code/datums/extensions/milkable/milkable.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
if(critter.stat == DEAD)
7474
return FALSE
7575

76-
if(udder?.total_volume <= 0)
76+
if(REAGENT_TOTAL_VOLUME(udder) <= 0)
7777
to_chat(user, SPAN_WARNING("\The [critter]'s udder is dry. Wait a little longer."))
7878
return TRUE
7979

@@ -108,7 +108,7 @@
108108
if(critter.stat == DEAD)
109109
return FALSE
110110

111-
if(udder?.total_volume <= 0)
111+
if(REAGENT_TOTAL_VOLUME(udder) <= 0)
112112
to_chat(user, SPAN_WARNING("\The [critter]'s udder is dry. Wait a little longer."))
113113
return TRUE
114114

code/datums/inventory_slots/inventory_gripper_subtypes.dm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323

2424
// This means critters can hoover up beakers as a kind of impromptu chem disposal
2525
// technique, so long as they're okay with the reagents reacting inside them.
26-
if(prop.reagents?.total_volume)
27-
prop.reagents.trans_to_mob(src, prop.reagents.total_volume, CHEM_INGEST)
26+
var/prop_reagents = REAGENT_TOTAL_VOLUME(prop.reagents)
27+
if(prop_reagents)
28+
prop.reagents.trans_to_mob(src, prop_reagents, CHEM_INGEST)
2829

2930
// It also means they can do the old school cartoon schtick of eating
3031
// an entire sandwich and spitting up an empty plate. Ptooie.

code/datums/inventory_slots/slots/slot_shoes.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var/blood_color
2424
for(var/foot_tag in list(BP_L_FOOT, BP_R_FOOT))
2525
var/obj/item/organ/external/stomper = GET_EXTERNAL_ORGAN(user, foot_tag)
26-
if(stomper && stomper.coating?.total_volume)
26+
if(REAGENT_TOTAL_VOLUME(stomper?.coating))
2727
blood_color = stomper.coating.get_color()
2828
break
2929
if(blood_color)
@@ -39,7 +39,7 @@
3939
return "[pronouns.He] [pronouns.is] wearing [_holding.get_examine_line()] on [pronouns.his] feet."
4040
for(var/bp in list(BP_L_FOOT, BP_R_FOOT))
4141
var/obj/item/organ/external/E = GET_EXTERNAL_ORGAN(owner, bp)
42-
if(E && E.coating?.total_volume)
42+
if(REAGENT_TOTAL_VOLUME(E?.coating))
4343
if(user == owner)
4444
return "There's <font color='[E.coating.get_color()]'>something on your feet</font>!"
4545
return "There's <font color='[E.coating.get_color()]'>something on [pronouns.his] feet</font>!"

code/datums/storage/_storage.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ var/global/list/_test_storage_items = list()
193193
if(!M.try_unequip(inserting))
194194
return FALSE
195195

196-
if(holder.reagents?.total_volume)
196+
if(REAGENT_TOTAL_VOLUME(holder.reagents))
197197
inserting.fluid_act(holder.reagents)
198198
if(QDELETED(inserting))
199199
return FALSE

code/datums/storage/subtypes_box.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
if(istype(removing, /obj/item/clothing/mask/smokable/cigarette/cigar) && isatom(holder))
5252
var/atom/atom_holder = holder
5353
if(atom_holder.reagents)
54-
atom_holder.reagents.trans_to_obj(removing, (atom_holder.reagents.total_volume/max(1, length(get_contents()))))
54+
atom_holder.reagents.trans_to_obj(removing, (REAGENT_TOTAL_VOLUME(atom_holder.reagents)/max(1, length(get_contents()))))
5555
return ..()
5656

5757
/datum/storage/box/cigarettes
@@ -63,7 +63,7 @@
6363
if(istype(removing, /obj/item/clothing/mask/smokable/cigarette) && isatom(holder))
6464
var/atom/atom_holder = holder
6565
if(atom_holder.reagents)
66-
atom_holder.reagents.trans_to_obj(removing, (atom_holder.reagents.total_volume/max(1, length(get_contents()))))
66+
atom_holder.reagents.trans_to_obj(removing, (REAGENT_TOTAL_VOLUME(atom_holder.reagents)/max(1, length(get_contents()))))
6767
return ..()
6868

6969
/datum/storage/box/cigarettes/cigarello

code/datums/storage/subtypes_misc.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
. = ..()
125125
if(!.)
126126
return
127-
return inserting_item.reagents?.total_volume > 0
127+
return REAGENT_TOTAL_VOLUME(inserting_item.reagents) > 0
128128

129129
/datum/storage/photo_album
130130
storage_slots = DEFAULT_BOX_STORAGE //yes, that's storage_slots. Photos are w_class 1 so this has as many slots equal to the number of photos you could put in a box

code/game/atoms.dm

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164

165165
/atom/proc/on_reagent_change()
166166
SHOULD_CALL_PARENT(TRUE)
167-
if(storage && reagents?.total_volume)
167+
if(storage && REAGENT_TOTAL_VOLUME(reagents))
168168
for(var/obj/item/thing in get_stored_inventory())
169169
thing.fluid_act(reagents)
170170
return TRUE
@@ -445,9 +445,10 @@
445445
* Most useful for calculating worth or deconstructing something along with its contents.
446446
*/
447447
/atom/proc/get_contained_matter(include_reagents = TRUE)
448-
if(include_reagents && length(reagents?.reagent_volumes))
448+
var/list/reagent_volumes = REAGENT_VOLUMES(reagents)
449+
if(include_reagents && length(reagent_volumes))
449450
LAZYINITLIST(.)
450-
for(var/decl/material/reagent as anything in reagents.reagent_volumes)
451+
for(var/decl/material/reagent as anything in reagent_volumes)
451452
.[reagent.type] += floor(REAGENT_VOLUME(reagents, reagent) / REAGENT_UNITS_PER_MATERIAL_UNIT)
452453
for(var/atom/contained_obj as anything in get_contained_external_atoms()) // machines handle component parts separately
453454
. = MERGE_ASSOCS_WITH_NUM_VALUES(., contained_obj.get_contained_matter(include_reagents))
@@ -504,7 +505,7 @@
504505
*/
505506
/atom/proc/try_detonate_reagents(var/severity = 3)
506507
if(reagents)
507-
for(var/decl/material/reagent as anything in reagents.reagent_volumes)
508+
for(var/decl/material/reagent as anything in REAGENT_VOLUMES(reagents))
508509
reagent.explosion_act(src, severity)
509510

510511
/**
@@ -1026,13 +1027,13 @@
10261027
return istype(turf) ? turf.is_outside() : OUTSIDE_UNCERTAIN
10271028

10281029
/atom/proc/can_be_poured_into(atom/source)
1029-
return (reagents?.maximum_volume > 0) && ATOM_IS_OPEN_CONTAINER(src)
1030+
return (REAGENT_MAXIMUM_VOLUME(reagents) > 0) && ATOM_IS_OPEN_CONTAINER(src)
10301031

10311032
/// This is whether it's physically possible to pour from this atom to the target atom, based on context like user intent and src being open, etc.
10321033
/// This should not check things like whether there is actually anything in src to pour.
10331034
/// It should also not check anything controlled by the target atom, because can_be_poured_into() already exists.
10341035
/atom/proc/can_be_poured_from(mob/user, atom/target)
1035-
return (reagents?.maximum_volume > 0) && ATOM_IS_OPEN_CONTAINER(src)
1036+
return (REAGENT_MAXIMUM_VOLUME(reagents) > 0) && ATOM_IS_OPEN_CONTAINER(src)
10361037

10371038
/atom/proc/take_vaporized_reagent(reagent, amount)
10381039
return
@@ -1041,7 +1042,7 @@
10411042
return !ATOM_IS_OPEN_CONTAINER(src)
10421043

10431044
/atom/proc/can_drink_from(mob/user)
1044-
return ATOM_IS_OPEN_CONTAINER(src) && reagents?.total_volume && user.check_has_mouth()
1045+
return ATOM_IS_OPEN_CONTAINER(src) && REAGENT_TOTAL_VOLUME(reagents) && user.check_has_mouth()
10451046

10461047
/atom/proc/adjust_required_attack_dexterity(mob/user, required_dexterity)
10471048
if(storage) // TODO: possibly check can_be_inserted() to avoid being able to shoot mirrors as a drake.

0 commit comments

Comments
 (0)