Skip to content

Commit

Permalink
[MIRROR] Heretic Influences use alt appearances (so ghosts can now se…
Browse files Browse the repository at this point in the history
…e them (semi-transparent)) (Skyrat-SS13#29646)

Heretic Influences use alt appearances (so ghosts can now see them (semi-transparent)) (#85932)

## About The Pull Request

Removes the rather overcomplicated system behind heretic influences and
makes them use alt appearances

Fixes a few bugs involving alt appearances that I noticed in making them

I made this PR 7 months ago and forgot to Pr it

## Why It's Good For The Game

Less complex codes and lets observers get a cut in on the action.

Should fix #77530

## Changelog

:cl: Melbert
refactor: Refactored heretic influences a tiny bit, now ghosts can see
them! Report any oddities.
/:cl:

Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
  • Loading branch information
SkyratBot and MrMelbert committed Sep 6, 2024
1 parent d63fb38 commit c84fc82
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 150 deletions.
3 changes: 3 additions & 0 deletions code/__DEFINES/dcs/signals/signals_mind.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@

/// Called on the mind when an antagonist is being removed, after the antagonist list has updated (datum/antagonist/antagonist)
#define COMSIG_ANTAGONIST_REMOVED "antagonist_removed"

/// Called on the mob when losing an antagonist datum (datum/antagonist/antagonist)
#define COMSIG_MOB_ANTAGONIST_REMOVED "mob_antagonist_removed"
56 changes: 56 additions & 0 deletions code/datums/elements/block_turf_fingerprints.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* ## block_turf_fingerprints
*
* Attach to a movable, prevents mobs from leaving fingerprints on the turf below it
*/
/datum/element/block_turf_fingerprints
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY

/datum/element/block_turf_fingerprints/Attach(datum/target)
. = ..()
if(!ismovable(target))
return ELEMENT_INCOMPATIBLE

var/atom/movable/target_movable = target
if(isturf(target_movable.loc))
apply_to_turf(target_movable.loc)

RegisterSignal(target, COMSIG_MOVABLE_MOVED, PROC_REF(move_turf))

/datum/element/block_turf_fingerprints/Detach(atom/movable/target)
. = ..()
if(isturf(target.loc))
remove_from_turf(target.loc)

UnregisterSignal(target, COMSIG_MOVABLE_MOVED)

/datum/element/block_turf_fingerprints/proc/apply_to_turf(turf/the_turf)
// It's possible two things with this element could be on the same turf, so let's avoid double-applying
if(the_turf.interaction_flags_atom & INTERACT_ATOM_NO_FINGERPRINT_ATTACK_HAND)
// But what if the turf has this flag by default? We still need to override register a signal.
// Otherwise we may run into a very niche bug:
// - A turf as this flag by default
// - A movable with this element is placed on the turf
// - It does not gain the flag nor register a signal
// - The turf changes, and the new turf does not gain the flag
if(initial(the_turf.interaction_flags_atom) & INTERACT_ATOM_NO_FINGERPRINT_ATTACK_HAND)
RegisterSignal(the_turf, COMSIG_TURF_CHANGE, PROC_REF(replace_our_turf), override = TRUE)
return

the_turf.interaction_flags_atom |= INTERACT_ATOM_NO_FINGERPRINT_ATTACK_HAND
RegisterSignal(the_turf, COMSIG_TURF_CHANGE, PROC_REF(replace_our_turf))

/datum/element/block_turf_fingerprints/proc/remove_from_turf(turf/the_turf)
the_turf.interaction_flags_atom &= ~INTERACT_ATOM_NO_FINGERPRINT_ATTACK_HAND
UnregisterSignal(the_turf, COMSIG_TURF_CHANGE)

/datum/element/block_turf_fingerprints/proc/move_turf(atom/movable/source, atom/old_loc)
SIGNAL_HANDLER
if(isturf(old_loc))
remove_from_turf(old_loc)
if(isturf(source.loc))
apply_to_turf(source.loc)

/datum/element/block_turf_fingerprints/proc/replace_our_turf(datum/source, path, new_baseturfs, flags, post_change_callbacks)
SIGNAL_HANDLER
post_change_callbacks += CALLBACK(src, PROC_REF(apply_to_turf))
69 changes: 55 additions & 14 deletions code/game/atom/alternate_appearance.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,51 @@ GLOBAL_LIST_EMPTY(active_alternate_appearances)
GLOB.active_alternate_appearances += src

for(var/mob in GLOB.player_list)
if(mobShouldSee(mob))
show_to(mob)
apply_to_new_mob(mob)

/datum/atom_hud/alternate_appearance/Destroy()
GLOB.active_alternate_appearances -= src
return ..()

/datum/atom_hud/alternate_appearance/proc/onNewMob(mob/M)
if(mobShouldSee(M))
show_to(M)
/// Wrapper for applying this alt hud to the passed mob (if they should see it)
/datum/atom_hud/alternate_appearance/proc/apply_to_new_mob(mob/applying_to)
if(mobShouldSee(applying_to))
if(!hud_users_all_z_levels[applying_to])
show_to(applying_to)
return TRUE
return FALSE

/// Checks if the passed mob should be seeing this hud
/datum/atom_hud/alternate_appearance/proc/mobShouldSee(mob/M)
return FALSE

/datum/atom_hud/alternate_appearance/show_to(mob/new_viewer)
. = ..()
if(!new_viewer)
return
track_mob(new_viewer)

/// Registers some signals to track the mob's state to determine if they should be seeing the hud still
/datum/atom_hud/alternate_appearance/proc/track_mob(mob/new_viewer)
return

/datum/atom_hud/alternate_appearance/hide_from(mob/former_viewer, absolute)
. = ..()
if(!former_viewer || hud_atoms_all_z_levels[former_viewer] >= 1)
return
untrack_mob(former_viewer)

/// Unregisters the signals that were tracking the mob's state
/datum/atom_hud/alternate_appearance/proc/untrack_mob(mob/former_viewer)
return

/datum/atom_hud/alternate_appearance/proc/check_hud(mob/source)
SIGNAL_HANDLER
// Attempt to re-apply the hud entirely
if(!apply_to_new_mob(source))
// If that failed, probably shouldn't be seeing it at all, so nuke it
hide_from(source, absolute = TRUE)

/datum/atom_hud/alternate_appearance/add_atom_to_hud(atom/A, image/I)
. = ..()
if(.)
Expand Down Expand Up @@ -99,6 +130,22 @@ GLOBAL_LIST_EMPTY(active_alternate_appearances)
if(ghost_appearance)
QDEL_NULL(ghost_appearance)

/datum/atom_hud/alternate_appearance/basic/track_mob(mob/new_viewer)
RegisterSignals(new_viewer, list(
COMSIG_MOB_ANTAGONIST_REMOVED,
COMSIG_MOB_GHOSTIZED,
COMSIG_MOB_MIND_TRANSFERRED_INTO,
COMSIG_MOB_MIND_TRANSFERRED_OUT_OF,
), PROC_REF(check_hud), override = TRUE)

/datum/atom_hud/alternate_appearance/basic/untrack_mob(mob/former_viewer)
UnregisterSignal(former_viewer, list(
COMSIG_MOB_ANTAGONIST_REMOVED,
COMSIG_MOB_GHOSTIZED,
COMSIG_MOB_MIND_TRANSFERRED_INTO,
COMSIG_MOB_MIND_TRANSFERRED_OUT_OF,
))

/datum/atom_hud/alternate_appearance/basic/add_atom_to_hud(atom/A)
LAZYINITLIST(A.hud_list)
A.hud_list[appearance_key] = image
Expand Down Expand Up @@ -136,16 +183,10 @@ GLOBAL_LIST_EMPTY(active_alternate_appearances)
/datum/atom_hud/alternate_appearance/basic/noncult

/datum/atom_hud/alternate_appearance/basic/noncult/mobShouldSee(mob/M)
if(!IS_CULTIST(M))
return TRUE
return FALSE

/datum/atom_hud/alternate_appearance/basic/cult
return !IS_CULTIST(M)

/datum/atom_hud/alternate_appearance/basic/cult/mobShouldSee(mob/M)
if(IS_CULTIST(M))
return TRUE
return FALSE
/datum/atom_hud/alternate_appearance/basic/has_antagonist/cult
antag_datum_type = /datum/antagonist/cult

/datum/atom_hud/alternate_appearance/basic/blessed_aware

Expand Down
15 changes: 6 additions & 9 deletions code/modules/antagonists/_common/antag_datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ GLOBAL_LIST_EMPTY(antagonists)
if(count_against_dynamic_roll_chance && owner.current.stat != DEAD && owner.current.client)
owner.current.add_to_current_living_antags()

for (var/datum/atom_hud/alternate_appearance/basic/antag_hud as anything in GLOB.active_alternate_appearances)
antag_hud.apply_to_new_mob(owner.current)

SEND_SIGNAL(owner, COMSIG_ANTAGONIST_GAINED, src)

/**
Expand Down Expand Up @@ -328,13 +331,8 @@ GLOBAL_LIST_EMPTY(antagonists)
if(team)
team.remove_member(owner)
SEND_SIGNAL(owner, COMSIG_ANTAGONIST_REMOVED, src)

// Remove HUDs that they should no longer see
var/mob/living/current = owner.current
for (var/datum/atom_hud/alternate_appearance/basic/has_antagonist/antag_hud as anything in GLOB.has_antagonist_huds)
if (!antag_hud.mobShouldSee(current))
antag_hud.hide_from(current)

if(owner.current)
SEND_SIGNAL(owner.current, COMSIG_MOB_ANTAGONIST_REMOVED, src)
qdel(src)
// SKYRAT EDIT START
owner?.handle_exploitables() //Inefficient here, but on_removal() is called in multiple locations
Expand Down Expand Up @@ -534,8 +532,7 @@ GLOBAL_LIST_EMPTY(antagonists)

// Add HUDs that they couldn't see before
for (var/datum/atom_hud/alternate_appearance/basic/has_antagonist/antag_hud as anything in GLOB.has_antagonist_huds)
if (antag_hud.mobShouldSee(owner.current))
antag_hud.show_to(owner.current)
antag_hud.apply_to_new_mob(owner.current)

/// Takes a location, returns an image drawing "on" it that matches this antag datum's hud icon
/datum/antagonist/proc/hud_image_on(mob/hud_loc)
Expand Down
7 changes: 5 additions & 2 deletions code/modules/antagonists/_common/antag_hud.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ GLOBAL_LIST_EMPTY_TYPED(has_antagonist_huds, /datum/atom_hud/alternate_appearanc
var/datum/weakref/team_ref

/datum/atom_hud/alternate_appearance/basic/has_antagonist/New(key, image/I, antag_datum_type, datum/weakref/team)
src.antag_datum_type = antag_datum_type
team_ref = team
if(antag_datum_type)
src.antag_datum_type = antag_datum_type
src.team_ref = team
GLOB.has_antagonist_huds += src
return ..(key, I, NONE)

Expand All @@ -18,6 +19,8 @@ GLOBAL_LIST_EMPTY_TYPED(has_antagonist_huds, /datum/atom_hud/alternate_appearanc
return ..()

/datum/atom_hud/alternate_appearance/basic/has_antagonist/mobShouldSee(mob/M)
if(add_ghost_version && isobserver(M))
return FALSE // use the ghost version instead
var/datum/team/antag_team = team_ref?.resolve()
if(!isnull(antag_team))
return !!(M.mind in antag_team.members)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/antagonists/cult/blood_magic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
SEND_SOUND(caller, sound('sound/effects/ghost.ogg', FALSE, TRUE, 50))

var/image/sparkle_image = image('icons/effects/cult.dmi', clicked_on, "bloodsparkles", ABOVE_MOB_LAYER)
clicked_on.add_alt_appearance(/datum/atom_hud/alternate_appearance/basic/cult, "cult_apoc", sparkle_image, NONE)
clicked_on.add_alt_appearance(/datum/atom_hud/alternate_appearance/basic/has_antagonist/cult, "cult_apoc", sparkle_image, NONE)

addtimer(CALLBACK(clicked_on, TYPE_PROC_REF(/atom/, remove_alt_appearance), "cult_apoc", TRUE), 4 MINUTES, TIMER_OVERRIDE|TIMER_UNIQUE)
to_chat(caller, span_cult_bold("[clicked_on] has been cursed with living nightmares!"))
Expand Down
4 changes: 2 additions & 2 deletions code/modules/antagonists/cult/runes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1160,8 +1160,8 @@ GLOBAL_VAR_INIT(narsie_summon_count, 0)
images += B
if(!IS_CULTIST(M))
if(M.client)
var/image/C = image('icons/effects/cult.dmi',M,"bloodsparkles", ABOVE_MOB_LAYER)
add_alt_appearance(/datum/atom_hud/alternate_appearance/basic/cult, "cult_apoc", C, NONE)
var/image/C = image('icons/effects/cult.dmi', M, "bloodsparkles", ABOVE_MOB_LAYER)
add_alt_appearance(/datum/atom_hud/alternate_appearance/basic/has_antagonist/cult, "cult_apoc", C, NONE)
addtimer(CALLBACK(M, TYPE_PROC_REF(/atom/, remove_alt_appearance),"cult_apoc",TRUE), duration)
images += C
else
Expand Down
16 changes: 1 addition & 15 deletions code/modules/antagonists/heretic/heretic_antag.dm
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@
RegisterSignal(our_mob, COMSIG_LIVING_CULT_SACRIFICED, PROC_REF(on_cult_sacrificed))
RegisterSignals(our_mob, list(COMSIG_MOB_BEFORE_SPELL_CAST, COMSIG_MOB_SPELL_ACTIVATED), PROC_REF(on_spell_cast))
RegisterSignal(our_mob, COMSIG_USER_ITEM_INTERACTION, PROC_REF(on_item_use))
RegisterSignal(our_mob, COMSIG_MOB_LOGIN, PROC_REF(fix_influence_network))
RegisterSignal(our_mob, COMSIG_LIVING_POST_FULLY_HEAL, PROC_REF(after_fully_healed))

/datum/antagonist/heretic/remove_innate_effects(mob/living/mob_override)
Expand All @@ -329,7 +328,6 @@
COMSIG_MOB_BEFORE_SPELL_CAST,
COMSIG_MOB_SPELL_ACTIVATED,
COMSIG_USER_ITEM_INTERACTION,
COMSIG_MOB_LOGIN,
COMSIG_LIVING_POST_FULLY_HEAL,
COMSIG_LIVING_CULT_SACRIFICED,
))
Expand Down Expand Up @@ -457,18 +455,6 @@
var/obj/item/offhand = user.get_inactive_held_item()
return !QDELETED(offhand) && istype(offhand, /obj/item/melee/touch_attack/mansus_fist)

/*
* Signal proc for [COMSIG_MOB_LOGIN].
*
* Calls rework_network() on our reality smash tracker
* whenever a login / client change happens, to ensure
* influence client visibility is fixed.
*/
/datum/antagonist/heretic/proc/fix_influence_network(mob/source)
SIGNAL_HANDLER

GLOB.reality_smash_track.rework_network()

/// Signal proc for [COMSIG_LIVING_POST_FULLY_HEAL],
/// Gives the heretic aliving heart on aheal or organ refresh
/datum/antagonist/heretic/proc/after_fully_healed(mob/living/source, heal_flags)
Expand Down Expand Up @@ -656,7 +642,7 @@
/datum/antagonist/heretic/proc/passive_influence_gain()
knowledge_points++
if(owner.current.stat <= SOFT_CRIT)
to_chat(owner.current, "[span_hear("You hear a whisper...")] [span_hypnophrase(pick(strings(HERETIC_INFLUENCE_FILE, "drain_message")))]")
to_chat(owner.current, "[span_hear("You hear a whisper...")] [span_hypnophrase(pick_list(HERETIC_INFLUENCE_FILE, "drain_message"))]")
addtimer(CALLBACK(src, PROC_REF(passive_influence_gain)), passive_gain_timer)

/datum/antagonist/heretic/roundend_report()
Expand Down
3 changes: 1 addition & 2 deletions code/modules/antagonists/heretic/heretic_knowledge.dm
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,8 @@
our_heretic.knowledge_points += KNOWLEDGE_RITUAL_POINTS
was_completed = TRUE

var/drain_message = pick(strings(HERETIC_INFLUENCE_FILE, "drain_message"))
to_chat(user, span_boldnotice("[name] completed!"))
to_chat(user, span_hypnophrase(span_big("[drain_message]")))
to_chat(user, span_hypnophrase(span_big("[pick_list(HERETIC_INFLUENCE_FILE, "drain_message")]")))
desc += " (Completed!)"
log_heretic_knowledge("[key_name(user)] completed a [name] at [worldtime2text()].")
user.add_mob_memory(/datum/memory/heretic_knowledge_ritual)
Expand Down
Loading

0 comments on commit c84fc82

Please sign in to comment.