Skip to content

Commit

Permalink
Adding null checking to reagents checks due to /datum/reagents/Destro…
Browse files Browse the repository at this point in the history
…y() now calling on_reagent_change().
  • Loading branch information
MistakeNot4892 authored and comma committed Feb 19, 2024
1 parent a962f4d commit 8e4e2a5
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 50 deletions.
38 changes: 25 additions & 13 deletions code/game/objects/effects/fluids.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/atom/movable/fluid_overlay
name = ""
icon = 'icons/effects/liquids.dmi'
icon_state = "puddle"
icon_state = ""
anchored = TRUE
simulated = FALSE
opacity = FALSE
Expand All @@ -12,33 +12,45 @@
is_spawnable_type = FALSE

/atom/movable/fluid_overlay/on_update_icon()

var/datum/reagents/loc_reagents = loc?.reagents
var/reagent_volume = loc_reagents?.total_volume

// Update layer.
var/new_layer
if(reagent_volume > FLUID_OVER_MOB_HEAD)
layer = DEEP_FLUID_LAYER
new_layer = DEEP_FLUID_LAYER
else
layer = SHALLOW_FLUID_LAYER
new_layer = SHALLOW_FLUID_LAYER
if(layer != new_layer)
layer = new_layer

// Update colour.
var/new_color = loc_reagents?.get_color()
if(color != new_color)
color = new_color

// Update alpha.
var/decl/material/main_reagent = loc_reagents?.get_primary_reagent_decl()
var/new_alpha
if(main_reagent) // TODO: weighted alpha from all reagents, not just primary
alpha = clamp(CEILING(255*(reagent_volume/FLUID_DEEP)) * main_reagent.opacity, main_reagent.min_fluid_opacity, main_reagent.max_fluid_opacity)
new_alpha = clamp(CEILING(255*(reagent_volume/FLUID_DEEP)) * main_reagent.opacity, main_reagent.min_fluid_opacity, main_reagent.max_fluid_opacity)
else
alpha = FLUID_MIN_ALPHA
var/new_icon_state
new_alpha = FLUID_MIN_ALPHA
if(new_alpha != alpha)
alpha = new_alpha

// Update icon state. We use overlays so flick() can work on the base fluid overlay.
if(reagent_volume <= FLUID_PUDDLE)
new_icon_state = "puddle"
set_overlays("puddle")
else if(reagent_volume <= FLUID_SHALLOW)
new_icon_state = "shallow_still"
set_overlays("shallow_still")
else if(reagent_volume < FLUID_DEEP)
new_icon_state = "mid_still"
set_overlays("mid_still")
else if(reagent_volume < (FLUID_DEEP*2))
new_icon_state = "deep_still"
set_overlays("deep_still")
else
new_icon_state = "ocean"
if(new_icon_state != icon_state)
icon_state = new_icon_state
set_overlays("ocean")

// Map helper.
/obj/abstract/fluid_mapped
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/weapons/paint.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var/global/list/cached_icons = list()

/obj/item/chems/glass/paint/on_update_icon()
. = ..()
if(reagents.total_volume)
if(reagents?.total_volume)
add_overlay(overlay_image('icons/obj/reagentfillings.dmi', "paintbucket", reagents.get_color()))

/obj/item/chems/glass/paint/red
Expand Down
8 changes: 3 additions & 5 deletions code/game/turfs/turf_fluids.dm
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@

/turf/proc/show_bubbles()
set waitfor = FALSE
if(flooded)
return
var/atom/movable/fluid_overlay/fluid = locate() in src
if(istype(fluid))
flick("bubbles", fluid)
// TODO: make flooding show bubbles.
if(!flooded && fluid_overlay)
flick("bubbles", fluid_overlay)

/turf/fluid_update(var/ignore_neighbors)
fluid_blocked_dirs = null
Expand Down
2 changes: 1 addition & 1 deletion code/modules/integrated_electronics/passive/power.dm
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@

/obj/item/integrated_circuit/passive/power/chemical_cell/on_reagent_change(changetype)
..()
set_pin_data(IC_OUTPUT, 1, reagents.total_volume)
set_pin_data(IC_OUTPUT, 1, reagents?.total_volume || 0)
push_data()

/obj/item/integrated_circuit/passive/power/chemical_cell/make_energy()
Expand Down
16 changes: 2 additions & 14 deletions code/modules/integrated_electronics/subtypes/reagents.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
push_vol()

/obj/item/integrated_circuit/reagent/proc/push_vol()
set_pin_data(IC_OUTPUT, 1, reagents.total_volume)
set_pin_data(IC_OUTPUT, 1, reagents?.total_volume || 0)
push_data()

/obj/item/integrated_circuit/reagent/smoke
Expand Down Expand Up @@ -49,7 +49,7 @@
var/smoke_radius = 5
var/notified = FALSE

/obj/item/integrated_circuit/reagent/smoke/on_reagent_change()
/obj/item/integrated_circuit/reagent/on_reagent_change()
..()
push_vol()

Expand Down Expand Up @@ -109,10 +109,6 @@
var/transfer_amount = 10
var/busy = FALSE

/obj/item/integrated_circuit/reagent/injector/on_reagent_change(changetype)
..()
push_vol()

/obj/item/integrated_circuit/reagent/injector/on_data_written()
var/new_amount = get_pin_data(IC_INPUT, 2)
if(new_amount < 0)
Expand Down Expand Up @@ -324,10 +320,6 @@
set_pin_data(IC_OUTPUT, 2, weakref(src))
push_data()

/obj/item/integrated_circuit/reagent/storage/on_reagent_change(changetype)
..()
push_vol()

/obj/item/integrated_circuit/reagent/storage/big
name = "big reagent storage"
icon_state = "reagent_storage_big"
Expand Down Expand Up @@ -600,10 +592,6 @@
set_pin_data(IC_OUTPUT, 4, weakref(src))
push_data()

/obj/item/integrated_circuit/reagent/temp/on_reagent_change()
..()
push_vol()

/obj/item/integrated_circuit/reagent/temp/power_fail()
active = 0

Expand Down
3 changes: 2 additions & 1 deletion code/modules/reagents/Chemistry-Holder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var/global/obj/temp_reagents_holder = new
if(my_atom)
if(my_atom.reagents == src)
my_atom.reagents = null
my_atom.on_reagent_change()
if(total_volume > 0) // we can assume 0 reagents and null reagents are broadly identical for the purposes of atom logic
my_atom.on_reagent_change()
my_atom = null

/datum/reagents/GetCloneArgs()
Expand Down
6 changes: 3 additions & 3 deletions code/modules/reagents/reagent_containers/blood_pack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@

/obj/item/chems/ivbag/on_reagent_change()
..()
if(reagents.total_volume > volume/2)
if(reagents?.total_volume > volume/2)
w_class = ITEM_SIZE_SMALL
else
w_class = ITEM_SIZE_TINY

/obj/item/chems/ivbag/on_update_icon()
. = ..()
var/percent = round(reagents.total_volume / volume * 100)
if(reagents.total_volume)
var/percent = round(reagents?.total_volume / volume * 100)
if(percent)
add_overlay(overlay_image(icon, "[round(percent,25)]", reagents.get_color()))
add_overlay(attached? "dongle" : "top")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,15 @@ var/global/const/DRINK_ICON_NOISY = "noise"
. = custom_desc || ..()

/obj/item/chems/drinks/glass2/on_reagent_change()
temperature_coefficient = 4 / max(1, reagents.total_volume)
temperature_coefficient = 4 / max(1, reagents?.total_volume)
..()

/obj/item/chems/drinks/glass2/proc/can_add_extra(obj/item/glass_extra/GE)
if(!("[overlay_base_icon]_[GE.glass_addition]left" in icon_states(icon)))
return 0
return FALSE
if(!("[overlay_base_icon]_[GE.glass_addition]right" in icon_states(icon)))
return 0

return 1
return FALSE
return TRUE

/obj/item/chems/drinks/glass2/examine(mob/user, distance)
. = ..()
Expand Down
5 changes: 2 additions & 3 deletions code/modules/reagents/reagent_containers/drinks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@

/obj/item/chems/drinks/on_update_icon()
. = ..()
if(LAZYLEN(reagents.reagent_volumes))
if(filling_states)
add_overlay(overlay_image(icon, "[base_icon][get_filling_state()]", reagents.get_color()))
if(LAZYLEN(reagents?.reagent_volumes) && filling_states)
add_overlay(overlay_image(icon, "[base_icon][get_filling_state()]", reagents.get_color()))


////////////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 3 additions & 3 deletions code/modules/reagents/reagent_containers/dropper.dm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
return
else
trans = reagents.splash(target, amount_per_transfer_from_this, max_spill=0) //sprinkling reagents on generic non-mobs. Droppers are very precise
to_chat(user, SPAN_NOTICE("You transfer [trans] units of the solution."))
to_chat(user, SPAN_NOTICE("You transfer [trans] unit\s of the solution."))

else // Taking from something

Expand All @@ -76,7 +76,7 @@

var/trans = target.reagents.trans_to_obj(src, amount_per_transfer_from_this)

to_chat(user, SPAN_NOTICE("You fill the dropper with [trans] units of the solution."))
to_chat(user, SPAN_NOTICE("You fill the dropper with [trans] unit\s of the solution."))

/obj/item/chems/dropper/update_container_name()
return
Expand All @@ -86,7 +86,7 @@

/obj/item/chems/dropper/on_update_icon()
. = ..()
if(reagents.total_volume)
if(reagents?.total_volume)
icon_state = "dropper1"
else
icon_state = "dropper0"
Expand Down
2 changes: 1 addition & 1 deletion code/modules/reagents/reagent_containers/pill.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/obj/item/chems/pill/on_update_icon()
. = ..()
if(icon_state in colorizable_icon_states)
color = reagents.get_color()
color = reagents?.get_color()
alpha = 255 // above probably reset our alpha
else
color = null
Expand Down

0 comments on commit 8e4e2a5

Please sign in to comment.