Skip to content

Commit

Permalink
[MIRROR] Refactors fire overlays once again to make it not get stuck …
Browse files Browse the repository at this point in the history
…so often (#1931)

* Refactors fire overlays once again to make it not get stuck so often

* Fix conflict

I went back about 20-30 prs on tg to figure out where we missed something but I am not fully sure when this was last changed apart from 21 months ago which matches up with TG

* Unchanged files, fixed

* Hi yes, I like my robotic XENOS

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: MrMelbert <[email protected]>
Co-authored-by: SomeRandomOwl <[email protected]>
  • Loading branch information
4 people authored Feb 11, 2024
1 parent d46eeb0 commit cf3ab7a
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 134 deletions.
9 changes: 3 additions & 6 deletions code/__DEFINES/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,6 @@
#define ROBOTIC_BRUTE_EXAMINE_TEXT "denting"
#define ROBOTIC_BURN_EXAMINE_TEXT "charring"

// If a mob has a higher threshold than this, the icon shown will be increased to the big fire icon.
#define MOB_BIG_FIRE_STACK_THRESHOLD 3

#define GRAB_PIXEL_SHIFT_PASSIVE 6
#define GRAB_PIXEL_SHIFT_AGGRESSIVE 12
#define GRAB_PIXEL_SHIFT_NECK 16
Expand Down Expand Up @@ -785,8 +782,8 @@ GLOBAL_LIST_INIT(human_heights_to_offsets, list(
#define WOUND_LAYER 3
/// Blood cult ascended halo layer, because there's currently no better solution for adding/removing
#define HALO_LAYER 2
/// Fire layer when you're on fire
#define FIRE_LAYER 1
/// The highest most layer for mob overlays. Unused
#define HIGHEST_LAYER 1

#define UPPER_BODY "upper body"
#define LOWER_BODY "lower body"
Expand Down Expand Up @@ -827,7 +824,7 @@ GLOBAL_LIST_INIT(layers_to_offset, list(
// BODY_BEHIND_LAYER (external organs like wings)
// BODY_FRONT_LAYER (external organs like wings)
// DAMAGE_LAYER (full body)
// FIRE_LAYER (full body)
// HIGHEST_LAYER (full body)
// UNIFORM_LAYER (full body)
// WOUND_LAYER (full body)
))
Expand Down
5 changes: 5 additions & 0 deletions code/__DEFINES/status_effects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
/// If the incapacitated status effect will ignore a mob being agressively grabbed
#define IGNORE_GRAB (1<<2)

/// Maxamounts of fire stacks a mob can get
#define MAX_FIRE_STACKS 20
/// If a mob has a higher threshold than this, the icon shown will be increased to the big fire icon.
#define MOB_BIG_FIRE_STACK_THRESHOLD 3

// Grouped effect sources, see also code/__DEFINES/traits.dm

#define STASIS_MACHINE_EFFECT "stasis_machine"
Expand Down
4 changes: 2 additions & 2 deletions code/__DEFINES/traits/declarations.dm
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ Remember to update _globalvars/traits.dm if you're adding/removing/renaming trai
#define TRAIT_TUMOR_SUPPRESSED "brain_tumor_suppressed"
/// Prevents hallucinations from the hallucination brain trauma (RDS)
#define TRAIT_RDS_SUPPRESSED "rds_suppressed"
/// mobs that have this trait cannot be extinguished
#define TRAIT_PERMANENTLY_ONFIRE "permanently_onfire"
/// Mobs that have this trait cannot be extinguished
#define TRAIT_NO_EXTINGUISH "no_extinguish"
/// Indicates if the mob is currently speaking with sign language
#define TRAIT_SIGN_LANG "sign_language"
/// This mob is able to use sign language over the radio.
Expand Down
2 changes: 1 addition & 1 deletion code/_globalvars/traits/_traits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ GLOBAL_LIST_INIT(traits_by_type, list(
"TRAIT_NO_DEBRAIN_OVERLAY" = TRAIT_NO_DEBRAIN_OVERLAY,
"TRAIT_NO_DNA_COPY" = TRAIT_NO_DNA_COPY,
"TRAIT_NO_DNA_SCRAMBLE" = TRAIT_NO_DNA_SCRAMBLE,
"TRAIT_NO_EXTINGUISH" = TRAIT_NO_EXTINGUISH,
"TRAIT_NO_FLOATING_ANIM" = TRAIT_NO_FLOATING_ANIM,
"TRAIT_NO_GLIDE" = TRAIT_NO_GLIDE,
"TRAIT_NO_PLASMA_TRANSFORM" = TRAIT_NO_PLASMA_TRANSFORM,
Expand Down Expand Up @@ -374,7 +375,6 @@ GLOBAL_LIST_INIT(traits_by_type, list(
"TRAIT_PASSTABLE" = TRAIT_PASSTABLE,
"TRAIT_PERFECT_ATTACKER" = TRAIT_PERFECT_ATTACKER,
"TRAIT_PERMANENTLY_MORTAL" = TRAIT_PERMANENTLY_MORTAL,
"TRAIT_PERMANENTLY_ONFIRE" = TRAIT_PERMANENTLY_ONFIRE,
"TRAIT_PHOTOGRAPHER" = TRAIT_PHOTOGRAPHER,
"TRAIT_PIERCEIMMUNE" = TRAIT_PIERCEIMMUNE,
"TRAIT_PLANT_SAFE" = TRAIT_PLANT_SAFE,
Expand Down
2 changes: 1 addition & 1 deletion code/_globalvars/traits/admin_tooling.dm
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ GLOBAL_LIST_INIT(admin_visible_traits, list(
"TRAIT_NO_AUGMENTS" = TRAIT_NO_AUGMENTS,
"TRAIT_NO_BLOOD_OVERLAY" = TRAIT_NO_BLOOD_OVERLAY,
"TRAIT_NO_DNA_COPY" = TRAIT_NO_DNA_COPY,
"TRAIT_NO_EXTINGUISH" = TRAIT_NO_EXTINGUISH,
"TRAIT_NO_GLIDE" = TRAIT_NO_GLIDE,
"TRAIT_NO_PLASMA_TRANSFORM" = TRAIT_NO_PLASMA_TRANSFORM,
"TRAIT_NO_SLIP_ALL" = TRAIT_NO_SLIP_ALL,
Expand Down Expand Up @@ -162,7 +163,6 @@ GLOBAL_LIST_INIT(admin_visible_traits, list(
"TRAIT_PARALYSIS_R_LEG" = TRAIT_PARALYSIS_R_LEG,
"TRAIT_PASSTABLE" = TRAIT_PASSTABLE,
"TRAIT_PERFECT_ATTACKER" = TRAIT_PERFECT_ATTACKER,
"TRAIT_PERMANENTLY_ONFIRE" = TRAIT_PERMANENTLY_ONFIRE,
"TRAIT_PHOTOGRAPHER" = TRAIT_PHOTOGRAPHER,
"TRAIT_PIERCEIMMUNE" = TRAIT_PIERCEIMMUNE,
"TRAIT_PLANT_SAFE" = TRAIT_PLANT_SAFE,
Expand Down
26 changes: 26 additions & 0 deletions code/datums/elements/permanent_fire_overlay.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// When applied to a mob, they will always have a fire overlay regardless of if they are *actually* on fire.
/datum/element/perma_fire_overlay

/datum/element/perma_fire_overlay/Attach(atom/target)
. = ..()
if(!isliving(target))
return ELEMENT_INCOMPATIBLE

RegisterSignal(target, COMSIG_ATOM_UPDATE_OVERLAYS, PROC_REF(add_fire_overlay))
target.update_appearance(UPDATE_OVERLAYS)
ADD_TRAIT(target, TRAIT_NO_EXTINGUISH, ELEMENT_TRAIT(type))

/datum/element/perma_fire_overlay/Detach(atom/target)
. = ..()
UnregisterSignal(target, COMSIG_ATOM_UPDATE_OVERLAYS)
REMOVE_TRAIT(target, TRAIT_NO_EXTINGUISH, ELEMENT_TRAIT(type))
target.update_appearance(UPDATE_OVERLAYS)

/datum/element/perma_fire_overlay/proc/add_fire_overlay(mob/living/source, list/overlays)
SIGNAL_HANDLER

var/mutable_appearance/created_overlay = source.get_fire_overlay(stacks = MAX_FIRE_STACKS, on_fire = TRUE)
if(isnull(created_overlay))
return

overlays |= created_overlay
40 changes: 19 additions & 21 deletions code/datums/status_effects/debuffs/fire_stacks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// Current amount of stacks we have
var/stacks
/// Maximum of stacks that we could possibly get
var/stack_limit = 20
var/stack_limit = MAX_FIRE_STACKS
/// What status effect types do we remove uppon being applied. These are just deleted without any deduction from our or their stacks when forced.
var/list/enemy_types
/// What status effect types do we merge into if they exist. Ignored when forced.
Expand Down Expand Up @@ -116,12 +116,8 @@
owner.clear_alert(ALERT_FIRE)
else if(!was_on_fire && owner.on_fire)
owner.throw_alert(ALERT_FIRE, /atom/movable/screen/alert/fire)

/**
* Used to update owner's effect overlay
*/

/datum/status_effect/fire_handler/proc/update_overlay()
owner.update_appearance(UPDATE_OVERLAYS)
update_particles()

/datum/status_effect/fire_handler/fire_stacks
id = "fire_stacks" //fire_stacks and wet_stacks should have different IDs or else has_status_effect won't work
Expand All @@ -132,8 +128,6 @@

/// If we're on fire
var/on_fire = FALSE
/// Stores current fire overlay icon state, for optimisation purposes
var/last_icon_state
/// Reference to the mob light emitter itself
var/obj/effect/dummy/lighting_obj/moblight
/// Type of mob light emitter we use when on fire
Expand All @@ -160,8 +154,6 @@
return TRUE

deal_damage(seconds_between_ticks)
update_overlay()
update_particles()

/datum/status_effect/fire_handler/fire_stacks/update_particles()
if(on_fire)
Expand Down Expand Up @@ -239,8 +231,6 @@
moblight = new moblight_type(owner)

cache_stacks()
update_overlay()
update_particles()
SEND_SIGNAL(owner, COMSIG_LIVING_IGNITED, owner)
return TRUE

Expand All @@ -254,25 +244,33 @@
owner.clear_mood_event("on_fire")
SEND_SIGNAL(owner, COMSIG_LIVING_EXTINGUISHED, owner)
cache_stacks()
update_overlay()
update_particles()
for(var/obj/item/equipped in owner.get_equipped_items())
equipped.extinguish()

/datum/status_effect/fire_handler/fire_stacks/on_remove()
if(on_fire)
extinguish()
set_stacks(0)
update_overlay()
update_particles()
UnregisterSignal(owner, COMSIG_ATOM_UPDATE_OVERLAYS)
owner.update_appearance(UPDATE_OVERLAYS)
return ..()

/datum/status_effect/fire_handler/fire_stacks/update_overlay()
last_icon_state = owner.update_fire_overlay(stacks, on_fire, last_icon_state)

/datum/status_effect/fire_handler/fire_stacks/on_apply()
. = ..()
update_overlay()
RegisterSignal(owner, COMSIG_ATOM_UPDATE_OVERLAYS, PROC_REF(add_fire_overlay))
owner.update_appearance(UPDATE_OVERLAYS)

/datum/status_effect/fire_handler/fire_stacks/proc/add_fire_overlay(mob/living/source, list/overlays)
SIGNAL_HANDLER

if(stacks <= 0 || !on_fire)
return

var/mutable_appearance/created_overlay = owner.get_fire_overlay(stacks, on_fire)
if(isnull(created_overlay))
return

overlays |= created_overlay

/obj/effect/dummy/lighting_obj/moblight/fire
name = "fire"
Expand Down
7 changes: 3 additions & 4 deletions code/game/turfs/open/lava.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

/turf/open/lava/Destroy()
for(var/mob/living/leaving_mob in contents)
REMOVE_TRAIT(leaving_mob, TRAIT_PERMANENTLY_ONFIRE, TURF_TRAIT)
leaving_mob.RemoveElement(/datum/element/perma_fire_overlay)
return ..()

/turf/open/lava/update_overlays()
Expand Down Expand Up @@ -144,7 +144,7 @@
/turf/open/lava/Exited(atom/movable/gone, direction)
. = ..()
if(isliving(gone) && !islava(gone.loc))
REMOVE_TRAIT(gone, TRAIT_PERMANENTLY_ONFIRE, TURF_TRAIT)
gone.RemoveElement(/datum/element/perma_fire_overlay)

/turf/open/lava/hitby(atom/movable/AM, skipcatch, hitpush, blocked, datum/thrownthing/throwingdatum)
if(burn_stuff(AM))
Expand Down Expand Up @@ -311,10 +311,9 @@
return

var/mob/living/burn_living = burn_target
ADD_TRAIT(burn_living, TRAIT_PERMANENTLY_ONFIRE, TURF_TRAIT)
burn_living.AddElement(/datum/element/perma_fire_overlay)
burn_living.ignite_mob()
burn_living.adjust_fire_stacks(lava_firestacks * seconds_per_tick)
burn_living.update_fire()
burn_living.adjustFireLoss(lava_damage * seconds_per_tick)

/turf/open/lava/can_cross_safely(atom/movable/crossing)
Expand Down
22 changes: 11 additions & 11 deletions code/modules/mob/living/basic/basic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,17 @@
/mob/living/basic/on_fire_stack(seconds_per_tick, datum/status_effect/fire_handler/fire_stacks/fire_handler)
adjust_bodytemperature((maximum_survivable_temperature + (fire_handler.stacks * 12)) * 0.5 * seconds_per_tick)

/mob/living/basic/update_fire_overlay(stacks, on_fire, last_icon_state, suffix = "")
var/mutable_appearance/fire_overlay = mutable_appearance('icons/mob/effects/onfire.dmi', "generic_fire")
if(on_fire && isnull(last_icon_state))
add_overlay(fire_overlay)
return fire_overlay
else if(!on_fire && !isnull(last_icon_state))
cut_overlay(fire_overlay)
return null
else if(on_fire && !isnull(last_icon_state))
return last_icon_state
return null
/mob/living/basic/get_fire_overlay(stacks, on_fire)
var/fire_icon = "generic_fire"
if(!GLOB.fire_appearances[fire_icon])
GLOB.fire_appearances[fire_icon] = mutable_appearance(
'icons/mob/effects/onfire.dmi',
fire_icon,
-HIGHEST_LAYER,
appearance_flags = RESET_COLOR,
)

return GLOB.fire_appearances[fire_icon]

/mob/living/basic/put_in_hands(obj/item/I, del_on_fail = FALSE, merge_stacks = TRUE, ignore_animation = TRUE)
. = ..()
Expand Down
31 changes: 11 additions & 20 deletions code/modules/mob/living/carbon/carbon_update_icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@
update_held_items()
update_worn_handcuffs()
update_worn_legcuffs()
update_fire()
update_body()
update_appearance(UPDATE_OVERLAYS)

/mob/living/carbon/update_held_items()
. = ..()
Expand Down Expand Up @@ -315,27 +315,18 @@
hands += I.build_worn_icon(default_layer = HANDS_LAYER, default_icon_file = icon_file, isinhands = TRUE)
return hands

/mob/living/carbon/update_fire_overlay(stacks, on_fire, last_icon_state, suffix = "")
var/fire_icon = "[dna?.species.fire_overlay || "human"]_[stacks > MOB_BIG_FIRE_STACK_THRESHOLD ? "big_fire" : "small_fire"][suffix]"
/mob/living/carbon/get_fire_overlay(stacks, on_fire)
var/fire_icon = "[dna?.species.fire_overlay || "human"]_[stacks > MOB_BIG_FIRE_STACK_THRESHOLD ? "big_fire" : "small_fire"]"

if(!GLOB.fire_appearances[fire_icon])
GLOB.fire_appearances[fire_icon] = mutable_appearance('icons/mob/effects/onfire.dmi', fire_icon, -FIRE_LAYER, appearance_flags = RESET_COLOR)

if((stacks > 0 && on_fire) || HAS_TRAIT(src, TRAIT_PERMANENTLY_ONFIRE))
if(fire_icon == last_icon_state)
return last_icon_state

remove_overlay(FIRE_LAYER)
overlays_standing[FIRE_LAYER] = GLOB.fire_appearances[fire_icon]
apply_overlay(FIRE_LAYER)
return fire_icon

if(!last_icon_state)
return last_icon_state

remove_overlay(FIRE_LAYER)
apply_overlay(FIRE_LAYER)
return null
GLOB.fire_appearances[fire_icon] = mutable_appearance(
'icons/mob/effects/onfire.dmi',
fire_icon,
-HIGHEST_LAYER,
appearance_flags = RESET_COLOR,
)

return GLOB.fire_appearances[fire_icon]

/mob/living/carbon/update_damage_overlays()
remove_overlay(DAMAGE_LAYER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
else
internal_fire = FALSE

H.update_fire()
H.update_appearance(UPDATE_OVERLAYS)

/datum/species/plasmaman/handle_fire(mob/living/carbon/human/H, seconds_per_tick, no_protection = FALSE)
if(internal_fire)
Expand Down
12 changes: 0 additions & 12 deletions code/modules/mob/living/carbon/init_signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
RegisterSignal(src, SIGNAL_ADDTRAIT(TRAIT_TOXIMMUNE), PROC_REF(on_toximmune_trait_gain))
RegisterSignal(src, SIGNAL_ADDTRAIT(TRAIT_GENELESS), PROC_REF(on_geneless_trait_gain))


RegisterSignals(src, list(
SIGNAL_ADDTRAIT(TRAIT_PERMANENTLY_ONFIRE),
SIGNAL_REMOVETRAIT(TRAIT_PERMANENTLY_ONFIRE),
), PROC_REF(update_permanently_on_fire))

/**
* On gain of TRAIT_AGENDER
*
Expand Down Expand Up @@ -90,12 +84,6 @@

reagents.end_metabolization(keep_liverless = TRUE)

///On gain of TRAIT_PERMANENTLY_ONFIRE, update the visuals if not on fire
/mob/living/carbon/proc/update_permanently_on_fire(datum/source)
SIGNAL_HANDLER
if(!on_fire)
update_fire()

/**
* On gain of TRAIT_VIRUSIMMUNE
*
Expand Down
Loading

0 comments on commit cf3ab7a

Please sign in to comment.