Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: Pref viewer & bitflag helpers #6282

Merged
merged 21 commits into from
Jan 5, 2025
6 changes: 4 additions & 2 deletions code/__DEFINES/dcs/signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,10 @@
#define COMSIG_MOB_THROW "mob_throw"
///called when a user is getting new weapon and we want to remove previous weapon to clear hands
#define COMSIG_MOB_WEAPON_APPEARS "mob_weapon_appears"
///from base of /mob/verb/examinate(): (atom/target)
#define COMSIG_MOB_EXAMINATE "mob_examinate"
/// from base of /mob/verb/examinate(): (atom/target)
#define COMSIG_MOB_VERB_EXAMINATE "mob_examinate"
/// from base of /mob/proc/run_examinate(): (atom/target, list/result)
#define COMSIG_MOB_RUN_EXAMINATE "mob_run_examinate"
///from base of /mob/update_sight(): ()
#define COMSIG_MOB_UPDATE_SIGHT "mob_update_sight"
////from /mob/living/say(): ()
Expand Down
7 changes: 7 additions & 0 deletions code/__HELPERS/bitflags.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#define HASBIT(CONTAINER, FLAG) ((CONTAINER) & (FLAG))

#define SETBIT(CONTAINER, FLAG) (CONTAINER |= (FLAG))

#define CLEARBIT(CONTAINER, FLAG) (CONTAINER &= ~(FLAG))

#define TOGGLEBIT(CONTAINER, FLAG) (CONTAINER ^= (FLAG))
41 changes: 41 additions & 0 deletions code/datums/components/pref_viewer.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/datum/component/pref_viewer
var/list/preferences_to_show

/datum/component/pref_viewer/Destroy(force)
LAZYNULL(preferences_to_show)

return ..()

/datum/component/pref_viewer/Initialize(
list/preferences_to_show
)
if(!ismob(parent))
return COMPONENT_INCOMPATIBLE

for(var/datum/preference_info/pref as anything in preferences_to_show)
LAZYADD(src.preferences_to_show, new pref)

/datum/component/pref_viewer/RegisterWithParent()
RegisterSignal(parent, COMSIG_MOB_RUN_EXAMINATE, PROC_REF(on_examine))

/datum/component/pref_viewer/UnregisterFromParent()
UnregisterSignal(parent, COMSIG_MOB_RUN_EXAMINATE)

/datum/component/pref_viewer/proc/on_examine(mob/source, mob/target, list/result)
SIGNAL_HANDLER

if(!istype(target) || !target.client)
return

INVOKE_ASYNC(src, PROC_REF(modify_examine), target, result)

/datum/component/pref_viewer/proc/modify_examine(mob/target, list/result)
for(var/datum/preference_info/pref as anything in preferences_to_show)
var/datum/preference_toggle/toggle = pref.get_preference_toggle()

if(!HASBIT(target.client.prefs.toggles, toggle::preftoggle_bitflag) \
&& !HASBIT(target.client.prefs.toggles2, toggle::preftoggle_bitflag)
)
continue

LAZYADD(result, pref.get_examine_text())
7 changes: 5 additions & 2 deletions code/datums/mind.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2608,8 +2608,11 @@
*/
/datum/mind/proc/remove_antag_datum(datum_type)
var/datum/antagonist/antag = has_antag_datum(datum_type)
if(antag)
qdel(antag)

if(!antag)
return

qdel(antag)


/**
Expand Down
19 changes: 19 additions & 0 deletions code/modules/antagonists/_common/antag_datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,32 @@ GLOBAL_LIST_EMPTY(antagonists)
/datum/antagonist/Destroy(force)
for(var/datum/objective/objective as anything in objectives)
objectives -= objective

if(!objective.team)
qdel(objective)

remove_owner_from_gamemode()
GLOB.antagonists -= src

if(!silent)
farewell()

remove_innate_effects()

antag_memory = null

var/datum/team/team = get_team()
team?.remove_member(owner)

if(owner)
LAZYREMOVE(owner.antag_datums, src)

if(!LAZYLEN(owner.antag_datums)) // that one was the last antag datum.
handle_last_instance_removal()

restore_last_hud_and_role()
owner = null

return ..()


Expand All @@ -92,8 +104,15 @@ GLOBAL_LIST_EMPTY(antagonists)
/datum/antagonist/proc/is_banned(mob/user)
if(!user)
return FALSE

return (jobban_isbanned(user, ROLE_SYNDICATE) || (job_rank && jobban_isbanned(user, job_rank)))

/**
* When our datum was last and became removed.
*/
/datum/antagonist/proc/handle_last_instance_removal()
return


/**
* Attempts to replace the role banned antag with a ghost player.
Expand Down
11 changes: 11 additions & 0 deletions code/modules/antagonists/changeling/changeling_datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ GLOBAL_LIST_INIT(possible_changeling_IDs, list("Alpha","Beta","Gamma","Delta","E
var/obj/item/organ/internal/brain/ling_brain = carbon_user.get_organ_slot(INTERNAL_ORGAN_BRAIN)
ling_brain?.decoy_brain = TRUE

user.AddComponent( \
/datum/component/pref_viewer, \
list(/datum/preference_info/take_out_of_the_round_without_obj), \
)

/datum/antagonist/changeling/on_body_transfer(mob/living/old_body, mob/living/new_body)
. = ..()
qdel(old_body.GetComponent(/datum/component/pref_viewer))

/datum/antagonist/changeling/handle_last_instance_removal()
qdel(owner.current.GetComponent(/datum/component/pref_viewer))

/datum/antagonist/changeling/remove_innate_effects(mob/living/mob_override)
var/mob/living/user = ..()
Expand Down
11 changes: 11 additions & 0 deletions code/modules/antagonists/space_ninja/ninja_datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@
var/mob/living/user = ..()
user.faction = list(ROLE_NINJA)

user.AddComponent( \
/datum/component/pref_viewer, \
list(/datum/preference_info/take_out_of_the_round_without_obj), \
)

/datum/antagonist/ninja/handle_last_instance_removal()
qdel(owner.current.GetComponent(/datum/component/pref_viewer))

/datum/antagonist/ninja/on_body_transfer(mob/living/old_body, mob/living/new_body)
. = ..()
qdel(old_body.GetComponent(/datum/component/pref_viewer))

/datum/antagonist/ninja/proc/change_species(mob/living/mob_to_change = null) // This should be used to fully to remove robo-limbs & change species for lack of sprites
human_ninja = ishuman(mob_to_change) ? mob_to_change : null
Expand Down
12 changes: 12 additions & 0 deletions code/modules/antagonists/traitor/datum_traitor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
datum_owner.AddComponent(/datum/component/codeword_hearing, GLOB.syndicate_code_phrase_regex, "codephrases", src)
datum_owner.AddComponent(/datum/component/codeword_hearing, GLOB.syndicate_code_response_regex, "coderesponses", src)

datum_owner.AddComponent( \
/datum/component/pref_viewer, \
list(/datum/preference_info/take_out_of_the_round_without_obj), \
)

/datum/antagonist/traitor/on_body_transfer(mob/living/old_body, mob/living/new_body)
. = ..()
qdel(old_body.GetComponent(/datum/component/pref_viewer))

/datum/antagonist/traitor/handle_last_instance_removal()
qdel(owner.current.GetComponent(/datum/component/pref_viewer))

/datum/antagonist/traitor/remove_innate_effects(mob/living/mob_override)
. = ..()
var/mob/living/datum_owner = mob_override || owner.current
Expand Down
11 changes: 11 additions & 0 deletions code/modules/antagonists/vampire/vampire_datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@
//slaved.leave_serv_hud(mob_override.mind)
//.mind.som = null

user.AddComponent( \
/datum/component/pref_viewer, \
list(/datum/preference_info/take_out_of_the_round_without_obj), \
)

/datum/antagonist/vampire/on_body_transfer(mob/living/old_body, mob/living/new_body)
. = ..()
qdel(old_body.GetComponent(/datum/component/pref_viewer))

/datum/antagonist/vampire/handle_last_instance_removal()
qdel(owner.current.GetComponent(/datum/component/pref_viewer))

/datum/antagonist/vampire/remove_innate_effects(mob/living/mob_override, transformation = FALSE)
var/mob/living/user = ..()
Expand Down
Loading
Loading