Skip to content

Commit

Permalink
Splits atoms flags that limit reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
NataKilar authored and comma committed Oct 11, 2023
1 parent 36d6af6 commit e28f150
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 50 deletions.
2 changes: 2 additions & 0 deletions code/__defines/flags.dm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ The latter will result in a linter warning and will not work correctly.
#define ATOM_FLAG_NO_PHASE_CHANGE BITFLAG(11) // Bypasses heating and cooling product reactions in the container.
#define ATOM_FLAG_BLOCK_DIAGONAL_FACING BITFLAG(12) // Atom cannot face non-cardinal directions.

#define ATOM_FLAG_NO_CHEM_CHANGE (ATOM_FLAG_NO_REACT | ATOM_FLAG_NO_DISSOLVE | ATOM_FLAG_NO_PHASE_CHANGE)

#define ATOM_IS_OPEN_CONTAINER(A) (A.atom_flags & ATOM_FLAG_OPEN_CONTAINER)

// Movable-level flags (/atom/movable/movable_flags)
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/kitchen/icecream.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
icon_state = "icecream_vat"
density = TRUE
anchored = FALSE
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_NO_REACT | ATOM_FLAG_OPEN_CONTAINER
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_NO_CHEM_CHANGE | ATOM_FLAG_OPEN_CONTAINER
idle_power_usage = 100

var/list/product_types = list()
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/kitchen/microwave.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
anchored = TRUE
idle_power_usage = 5
active_power_usage = 100
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_NO_REACT | ATOM_FLAG_OPEN_CONTAINER
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_NO_CHEM_CHANGE | ATOM_FLAG_OPEN_CONTAINER
construct_state = /decl/machine_construction/default/panel_closed
uncreated_component_parts = null
stat_immune = 0
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/kitchen/smartfridge.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
anchored = TRUE
idle_power_usage = 5
active_power_usage = 100
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_NO_REACT
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_NO_CHEM_CHANGE
obj_flags = OBJ_FLAG_ANCHORABLE | OBJ_FLAG_ROTATABLE
atmos_canpass = CANPASS_NEVER
required_interaction_dexterity = DEXTERITY_SIMPLE_MACHINES
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/weapons/storage/fancy.dm
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
slot_flags = SLOT_LOWER_BODY
material = /decl/material/solid/cardboard
key_type = /obj/item/clothing/mask/smokable/cigarette
atom_flags = ATOM_FLAG_NO_REACT | ATOM_FLAG_OPEN_CONTAINER | ATOM_FLAG_NO_TEMP_CHANGE
atom_flags = ATOM_FLAG_NO_CHEM_CHANGE | ATOM_FLAG_OPEN_CONTAINER | ATOM_FLAG_NO_TEMP_CHANGE

/obj/item/storage/fancy/cigarettes/WillContain()
return list(/obj/item/clothing/mask/smokable/cigarette = 6)
Expand Down Expand Up @@ -306,7 +306,7 @@
storage_slots = 7
material = /decl/material/solid/wood/mahogany
key_type = /obj/item/clothing/mask/smokable/cigarette/cigar
atom_flags = ATOM_FLAG_NO_REACT | ATOM_FLAG_NO_TEMP_CHANGE
atom_flags = ATOM_FLAG_NO_CHEM_CHANGE | ATOM_FLAG_NO_TEMP_CHANGE

/obj/item/storage/fancy/cigar/Initialize(ml, material_key)
. = ..()
Expand Down
2 changes: 1 addition & 1 deletion code/modules/atmospherics/pipes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
build_icon_state = "simple"
build_icon = 'icons/obj/pipe-item.dmi'
pipe_class = PIPE_CLASS_BINARY
atom_flags = ATOM_FLAG_CAN_BE_PAINTED | ATOM_FLAG_NO_REACT
atom_flags = ATOM_FLAG_CAN_BE_PAINTED | ATOM_FLAG_NO_CHEM_CHANGE
obj_flags = OBJ_FLAG_MOVES_UNSUPPORTED

frame_type = /obj/item/pipe
Expand Down
2 changes: 1 addition & 1 deletion code/modules/clothing/masks/chewable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/obj/item/clothing/mask/chewable/Initialize()
. = ..()
atom_flags |= ATOM_FLAG_NO_REACT // so it doesn't react until you light it
atom_flags |= ATOM_FLAG_NO_CHEM_CHANGE // so it doesn't react until you light it
initialize_reagents()

/obj/item/clothing/mask/chewable/initialize_reagents(populate = TRUE)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/clothing/masks/smokable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

/obj/item/clothing/mask/smokable/Initialize()
. = ..()
atom_flags |= ATOM_FLAG_NO_REACT // so it doesn't react until you light it
atom_flags |= ATOM_FLAG_NO_CHEM_CHANGE // so it doesn't react until you light it
create_reagents(chem_volume) // making the cigarrete a chemical holder with a maximum volume of 15

/obj/item/clothing/mask/smokable/Destroy()
Expand Down Expand Up @@ -139,7 +139,7 @@
e.start()
qdel(src)
return
atom_flags &= ~ATOM_FLAG_NO_REACT // allowing reagents to react after being lit
atom_flags &= ~ATOM_FLAG_NO_CHEM_CHANGE // allowing reagents to react after being lit
HANDLE_REACTIONS(reagents)
update_icon()
if(flavor_text)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/hydroponics/trays/tray.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
construct_state = /decl/machine_construction/default/panel_closed
uncreated_component_parts = null
stat_immune = 0
atom_flags = ATOM_FLAG_OPEN_CONTAINER | ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_CLIMBABLE | ATOM_FLAG_NO_REACT
atom_flags = ATOM_FLAG_OPEN_CONTAINER | ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_CLIMBABLE | ATOM_FLAG_NO_CHEM_CHANGE

var/mechanical = 1 // Set to 0 to stop it from drawing the alert lights.
var/base_name = "tray"
Expand Down
2 changes: 1 addition & 1 deletion code/modules/integrated_electronics/subtypes/reagents.dm
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
icon_state = "reagent_storage_cryo"
extended_desc = "This is effectively an internal cryo beaker."

atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_OPEN_CONTAINER | ATOM_FLAG_NO_REACT
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_OPEN_CONTAINER | ATOM_FLAG_NO_CHEM_CHANGE
complexity = 8
spawn_flags = IC_SPAWN_RESEARCH

Expand Down
2 changes: 1 addition & 1 deletion code/modules/mining/machinery/material_extractor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
icon = 'icons/obj/machines/mining_machines.dmi'
icon_state = "extractor"
use_ui_template = "material_processing_extractor.tmpl"
atom_flags = ATOM_FLAG_CLIMBABLE
atom_flags = ATOM_FLAG_CLIMBABLE | ATOM_FLAG_NO_REACT | ATOM_FLAG_NO_DISSOLVE

var/static/list/eating_whitelist = list(/obj/item/stack/material)

Expand Down
69 changes: 35 additions & 34 deletions code/modules/reagents/Chemistry-Holder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var/global/obj/temp_reagents_holder = new
var/atom/location = get_reaction_loc()
var/check_flags = location?.atom_flags || 0

if(check_flags & ATOM_FLAG_NO_REACT)
if((check_flags & ATOM_FLAG_NO_REACT) && (check_flags & ATOM_FLAG_NO_PHASE_CHANGE) && (check_flags & ATOM_FLAG_NO_DISSOLVE))
return 0

var/reaction_occured = FALSE
Expand Down Expand Up @@ -128,41 +128,42 @@ var/global/obj/temp_reagents_holder = new
if(replace_sound)
playsound(location, replace_sound, 80, 1)

else // Otherwise, collect all possible reactions.
else if(!(check_flags & ATOM_FLAG_NO_REACT)) // Otherwise, collect all possible reactions.
eligible_reactions |= SSmaterials.chemical_reactions_by_id[R.type]

var/list/active_reactions = list()

for(var/decl/chemical_reaction/C in eligible_reactions)
if(C.can_happen(src))
active_reactions[C] = 1 // The number is going to be 1/(fraction of remaining reagents we are allowed to use), computed below
reaction_occured = 1

var/list/used_reagents = list()
// if two reactions share a reagent, each is allocated half of it, so we compute this here
for(var/decl/chemical_reaction/C in active_reactions)
var/list/adding = C.get_used_reagents()
for(var/R in adding)
LAZYADD(used_reagents[R], C)

for(var/R in used_reagents)
var/counter = length(used_reagents[R])
if(counter <= 1)
continue // Only used by one reaction, so nothing we need to do.
for(var/decl/chemical_reaction/C in used_reagents[R])
active_reactions[C] = max(counter, active_reactions[C])
counter-- //so the next reaction we execute uses more of the remaining reagents
// Note: this is not guaranteed to maximize the size of the reactions we do (if one reaction is limited by reagent A, we may be over-allocating reagent B to it)
// However, we are guaranteed to fully use up the most profligate reagent if possible.
// Further reactions may occur on the next tick, when this runs again.

for(var/thing in active_reactions)
var/decl/chemical_reaction/C = thing
C.process(src, active_reactions[C])

for(var/thing in active_reactions)
var/decl/chemical_reaction/C = thing
C.post_reaction(src)
if(!(check_flags & ATOM_FLAG_NO_REACT))
var/list/active_reactions = list()

for(var/decl/chemical_reaction/C in eligible_reactions)
if(C.can_happen(src))
active_reactions[C] = 1 // The number is going to be 1/(fraction of remaining reagents we are allowed to use), computed below
reaction_occured = 1

var/list/used_reagents = list()
// if two reactions share a reagent, each is allocated half of it, so we compute this here
for(var/decl/chemical_reaction/C in active_reactions)
var/list/adding = C.get_used_reagents()
for(var/R in adding)
LAZYADD(used_reagents[R], C)

for(var/R in used_reagents)
var/counter = length(used_reagents[R])
if(counter <= 1)
continue // Only used by one reaction, so nothing we need to do.
for(var/decl/chemical_reaction/C in used_reagents[R])
active_reactions[C] = max(counter, active_reactions[C])
counter-- //so the next reaction we execute uses more of the remaining reagents
// Note: this is not guaranteed to maximize the size of the reactions we do (if one reaction is limited by reagent A, we may be over-allocating reagent B to it)
// However, we are guaranteed to fully use up the most profligate reagent if possible.
// Further reactions may occur on the next tick, when this runs again.

for(var/thing in active_reactions)
var/decl/chemical_reaction/C = thing
C.process(src, active_reactions[C])

for(var/thing in active_reactions)
var/decl/chemical_reaction/C = thing
C.post_reaction(src)

update_total()

Expand Down
2 changes: 1 addition & 1 deletion code/modules/reagents/reagent_containers/beaker.dm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
center_of_mass = @"{'x':16,'y':8}"
volume = 60
amount_per_transfer_from_this = 10
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_OPEN_CONTAINER | ATOM_FLAG_NO_REACT
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_OPEN_CONTAINER | ATOM_FLAG_NO_CHEM_CHANGE
presentation_flags = PRESENTATION_FLAG_NAME
material = /decl/material/solid/metal/steel
material_alteration = MAT_FLAG_ALTERATION_NONE
Expand Down
2 changes: 1 addition & 1 deletion code/modules/reagents/reagent_containers/syringes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
name = "cryostasis syringe"
desc = "An advanced syringe that stops reagents inside from reacting. It can hold up to 20 units."
volume = 20
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_NO_REACT
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_NO_CHEM_CHANGE
icon_state = "cs"
material = /decl/material/solid/glass
matter = list(
Expand Down
2 changes: 1 addition & 1 deletion mods/mobs/dionaea/mob/_nymph.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

holder_type = /obj/item/holder/diona
possession_candidate = 1
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_NO_REACT
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_NO_CHEM_CHANGE
hud_type = /datum/hud/diona_nymph

ai = /datum/ai/nymph
Expand Down
2 changes: 1 addition & 1 deletion mods/species/ascent/mobs/nymph/_nymph.dm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

holder_type = /obj/item/holder/ascent_nymph
possession_candidate = 1
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_NO_REACT
atom_flags = ATOM_FLAG_NO_TEMP_CHANGE | ATOM_FLAG_NO_CHEM_CHANGE
hud_type = /datum/hud/ascent_nymph

var/obj/item/holding_item
Expand Down

0 comments on commit e28f150

Please sign in to comment.