More antag datum cleanup / code QoL improvements (#17517)

* on-removal-purge

* this does break malf AI

* rebase and fix conflicts
This commit is contained in:
SteelSlayer
2022-05-09 12:44:42 +01:00
committed by GitHub
parent 3961ede300
commit c35ac9149d
8 changed files with 141 additions and 150 deletions
+36 -47
View File
@@ -11,8 +11,8 @@ GLOBAL_LIST_EMPTY(antagonists)
var/datum/mind/owner
/// Should the owner mob get a greeting text? Determines whether or not the `greet()` proc is called.
var/silent = FALSE
/// List of antagonist datums that this type can't coexist with.
var/list/typecache_datum_blacklist
/// List of other antag datum types that this type can't coexist with.
var/list/antag_datum_blacklist
/// Should this datum be deleted when the owner's mind is deleted.
var/delete_on_mind_deletion = TRUE
/// Used to determine if the player jobbanned from this role. Things like `SPECIAL_ROLE_TRAITOR` should go here to determine the role.
@@ -44,13 +44,19 @@ GLOBAL_LIST_EMPTY(antagonists)
GLOB.antagonists += src
objectives = list()
assigned_targets = list()
typecache_datum_blacklist = typecacheof(typecache_datum_blacklist)
/datum/antagonist/Destroy()
/datum/antagonist/Destroy(force, ...)
QDEL_LIST(objectives)
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)
restore_last_hud_and_role()
owner = null
return ..()
@@ -65,18 +71,10 @@ GLOBAL_LIST_EMPTY(antagonists)
return FALSE
for(var/i in tested.antag_datums)
var/datum/antagonist/A = i
if(is_type_in_typecache(src, A.typecache_datum_blacklist))
if(LAZYIN(A.antag_datum_blacklist, type))
return FALSE
return TRUE
/**
* This will be called in `add_antag_datum` before owner assignment.
*
* Should return antagonist datum without owner.
*/
/datum/antagonist/proc/specialization(datum/mind/new_owner)
return src
/**
* Removes antagonist datum effects from the old body and applies it to the new one.
*
@@ -97,14 +95,16 @@ GLOBAL_LIST_EMPTY(antagonists)
* If they're a clown, removes their clumsy mutataion.
*
* Arguments:
* * new_body - the new body that the antag mob is transferring into.
* * mob/living/mob_override - a mob to apply effects to. Can be null.
*/
/datum/antagonist/proc/apply_innate_effects(mob/living/new_body)
var/mob/living/L = new_body || owner.current
/datum/antagonist/proc/apply_innate_effects(mob/living/mob_override)
SHOULD_CALL_PARENT(TRUE)
var/mob/living/L = mob_override || owner.current
if(antag_hud_type && antag_hud_name)
add_antag_hud(L)
// If `new_body` exists it means we're only transferring this datum, we don't need to show the clown any text.
handle_clown_mutation(L, new_body ? null : clown_gain_text, TRUE)
// If `mob_override` exists it means we're only transferring this datum, we don't need to show the clown any text.
handle_clown_mutation(L, mob_override ? null : clown_gain_text, TRUE)
return L
/**
* This handles the removal of antag huds/special abilities.
@@ -113,14 +113,16 @@ GLOBAL_LIST_EMPTY(antagonists)
* If they're a clown, gives them back their clumsy mutataion.
*
* Arguments:
* * old_body - the old body the antag is leaving behind.
* * mob/living/mob_override - a mob to remove effects from. Can be null.
*/
/datum/antagonist/proc/remove_innate_effects(mob/living/old_body)
var/mob/living/L = old_body || owner.current
/datum/antagonist/proc/remove_innate_effects(mob/living/mob_override)
SHOULD_CALL_PARENT(TRUE)
var/mob/living/L = mob_override || owner.current
if(antag_hud_type && antag_hud_name)
remove_antag_hud(L)
// If `old_body` exists it means we're only transferring this datum, we don't need to show the clown any text.
handle_clown_mutation(L, old_body ? null : clown_removal_text)
// If `mob_override` exists it means we're only transferring this datum, we don't need to show the clown any text.
handle_clown_mutation(L, mob_override ? null : clown_removal_text)
return L
/**
* Adds this datum's antag hud to `antag_mob`.
@@ -184,8 +186,6 @@ GLOBAL_LIST_EMPTY(antagonists)
/datum/antagonist/proc/give_objectives()
return
#define NO_TARGET_OBJECTIVES list(/datum/objective/escape, /datum/objective/hijack, /datum/objective/survive, /datum/objective/block, /datum/objective/die)
/**
* Create and add an objective of the given type.
*
@@ -194,13 +194,20 @@ GLOBAL_LIST_EMPTY(antagonists)
*
* Arguments:
* * objective_type - A type path of an objective, for example: /datum/objective/steal
* * explanation_text - the explanation text that will be passed into the objective's `New()` proc
* * mob/target_override - a target for the objective
*/
/datum/antagonist/proc/add_objective(objective_type)
var/datum/objective/O = new objective_type
/datum/antagonist/proc/add_objective(objective_type, explanation_text = "", mob/target_override = null)
var/datum/objective/O = new objective_type(explanation_text)
O.owner = owner
if(is_type_in_list(O, NO_TARGET_OBJECTIVES))
objectives += O // No need to find a target, just add the objective and return.
if(target_override)
O.target = target_override
objectives += O
return
if(!O.needs_target)
objectives += O
return
O.find_target()
@@ -230,8 +237,6 @@ GLOBAL_LIST_EMPTY(antagonists)
objectives += O
#undef NO_TARGET_OBJECTIVES
/**
* Announces all objectives of this datum, and only this datum.
*/
@@ -263,22 +268,6 @@ GLOBAL_LIST_EMPTY(antagonists)
INVOKE_ASYNC(src, .proc/replace_banned_player)
return TRUE
/**
* Called when `remove_antag_datum()` is called on the owner's mind.
*
* Removes all effects this datum granted and deletes itself afterwards.
*/
/datum/antagonist/proc/on_removal()
if(!silent)
farewell()
remove_innate_effects()
antag_memory = null
var/datum/team/team = get_team()
team?.remove_member(owner)
LAZYREMOVE(owner.antag_datums, src)
restore_last_hud_and_role()
qdel(src)
/**
* Re-sets the antag hud and `special_role` of the owner to that of the previous antag datum they had before this one was added.
*
@@ -1,41 +1,26 @@
/datum/antagonist/survivalist
name = "Survivalist"
special_role = "Survivalist"
var/greet_message = ""
/datum/antagonist/survivalist/proc/forge_objectives()
var/datum/objective/survive/survive = new
survive.owner = owner
objectives += survive
owner.objectives |= objectives
/datum/antagonist/survivalist/on_gain()
owner.special_role = "survivalist"
forge_objectives()
. = ..()
/datum/antagonist/survivalist/give_objectives()
add_objective(/datum/objective/survive)
/datum/antagonist/survivalist/greet()
to_chat(owner.current, "<B>You are the survivalist! [greet_message]</B>")
owner.announce_objectives()
..()
to_chat(owner.current, "<span class='notice'>[greet_message]</span>")
/datum/antagonist/survivalist/guns
greet_message = "Your own safety matters above all else, and the only way to ensure your safety is to stockpile weapons! Grab as many guns as possible, by any means necessary. Kill anyone who gets in your way."
/datum/antagonist/survivalist/guns/forge_objectives()
var/datum/objective/steal_five_of_type/summon_guns/guns = new
guns.owner = owner
objectives += guns
/datum/antagonist/survivalist/guns/give_objectives()
add_objective(/datum/objective/steal_five_of_type/summon_guns)
..()
/datum/antagonist/survivalist/magic
name = "Amateur Magician"
greet_message = "Grow your newfound talent! Grab as many magical artefacts as possible, by any means necessary. Kill anyone who gets in your way."
greet_message = "Grow your newfound talent! Grab as many magical artefacts as possible, by any means necessary. Kill anyone who gets in your way. As a wonderful magician, you should remember that spellbooks don't mean anything if they are used up."
/datum/antagonist/survivalist/magic/greet()
..()
to_chat(owner.current, "<span class='notice'>As a wonderful magician, you should remember that spellbooks don't mean anything if they are used up.</span>")
/datum/antagonist/survivalist/magic/forge_objectives()
var/datum/objective/steal_five_of_type/summon_magic/magic = new
magic.owner = owner
objectives += magic
/datum/antagonist/survivalist/magic/give_objectives()
add_objective(/datum/objective/steal_five_of_type/summon_magic)
..()
@@ -21,10 +21,15 @@
return
master = _master
greet_text = _greet_text
return ..()
..()
/datum/antagonist/mindslave/Destroy()
/datum/antagonist/mindslave/Destroy(force, ...)
if(owner.som)
owner.som.serv -= owner
owner.som.leave_serv_hud(owner)
master = null
SSticker.mode.implanted[owner] = null
SSticker.mode.implanted -= owner
return ..()
/datum/antagonist/mindslave/on_gain()
@@ -42,22 +47,11 @@
hud.join_hud(master.current)
set_antag_hud(master.current, "hudmaster")
slaved.add_serv_hud(master, "master")
// Add an obey and protect objective.
var/datum/objective/protect/serve_objective = new
serve_objective.target = master
serve_objective.owner = owner
var/role = master.assigned_role ? master.assigned_role : master.special_role
serve_objective.explanation_text = "Obey every order from and protect [master.current.real_name], the [role]."
objectives += serve_objective
return ..()
/datum/antagonist/mindslave/on_removal()
if(owner.som)
var/datum/mindslaves/slaved = owner.som
slaved.serv -= owner
slaved.leave_serv_hud(owner)
return ..()
/datum/antagonist/mindslave/give_objectives()
var/explanation_text = "Obey every order from and protect [master.current.real_name], the [master.assigned_role ? master.assigned_role : master.special_role]."
add_objective(/datum/objective/protect/mindslave, explanation_text, master)
/datum/antagonist/mindslave/greet()
var/mob/living/carbon/human/mindslave = owner.current
@@ -23,9 +23,9 @@
owner.som.masters += owner
SSticker.mode.traitors |= owner
return ..()
..()
/datum/antagonist/traitor/on_removal()
/datum/antagonist/traitor/Destroy(force, ...)
// Remove all associated malf AI abilities.
if(isAI(owner.current))
var/mob/living/silicon/ai/A = owner.current
@@ -46,7 +46,6 @@
owner.som = null
owner.current.client.chatOutput?.clear_syndicate_codes()
assigned_targets.Cut()
SSticker.mode.traitors -= owner
return ..()
+14 -17
View File
@@ -36,9 +36,9 @@
SSticker.mode.vampire_enthralled += owner
..()
/datum/antagonist/mindslave/thrall/on_removal()
/datum/antagonist/mindslave/thrall/Destroy(force, ...)
SSticker.mode.vampire_enthralled -= owner
..()
return ..()
/datum/antagonist/mindslave/thrall/apply_innate_effects(mob/living/new_body)
..()
@@ -51,6 +51,8 @@
M.RemoveSpell(/obj/effect/proc_holder/spell/vampire/thrall_commune)
/datum/antagonist/vampire/Destroy(force, ...)
SSticker.mode.vampires -= owner
owner.current.create_log(CONVERSION_LOG, "De-vampired")
draining = null
QDEL_NULL(subclass)
QDEL_LIST(powers)
@@ -88,18 +90,17 @@
qdel(ability)
owner.current.update_sight() // Life updates conditionally, so we need to update sight here in case the vamp loses his vision based powers. Maybe one day refactor to be more OOP and on the vampire's ability datum.
/datum/antagonist/vampire/remove_innate_effects(mob/living/old_body)
var/mob/living/L = old_body || owner.current
/datum/antagonist/vampire/remove_innate_effects(mob/living/mob_override)
mob_override = ..()
for(var/P in powers)
remove_ability(P)
var/datum/hud/hud = L.hud_used
var/datum/hud/hud = mob_override.hud_used
if(hud?.vampire_blood_display)
hud.remove_vampire_hud()
L.dna.species.hunger_type = initial(L.dna.species.hunger_type)
L.dna.species.hunger_icon = initial(L.dna.species.hunger_icon)
mob_override.dna.species.hunger_type = initial(mob_override.dna.species.hunger_type)
mob_override.dna.species.hunger_icon = initial(mob_override.dna.species.hunger_icon)
owner.current.alpha = 255
REMOVE_TRAITS_IN(owner.current, "vampire")
return ..()
#define BLOOD_GAINED_MODIFIER 0.5
@@ -188,10 +189,6 @@
var/datum/vampire_passive/power = p
to_chat(owner.current, "<span class='boldnotice'>[power.gain_desc]</span>")
/datum/antagonist/vampire/on_removal()
SSticker.mode.vampires -= owner
owner.current.create_log(CONVERSION_LOG, "De-vampired")
..()
/datum/antagonist/vampire/on_gain()
SSticker.mode.vampires += owner
@@ -321,14 +318,14 @@
You are weak to holy things, starlight and fire. Don't go into space and avoid the Chaplain, the chapel and especially Holy Water."}
to_chat(owner.current, dat)
/datum/antagonist/vampire/apply_innate_effects(mob/living/new_body)
. = ..()
/datum/antagonist/vampire/apply_innate_effects(mob/living/mob_override)
mob_override = ..()
if(!owner.som) //thralls and mindslaves
owner.som = new()
owner.som.masters += owner
var/mob/living/L = new_body || owner.current
L.dna.species.hunger_type = "vampire"
L.dna.species.hunger_icon = 'icons/mob/screen_hunger_vampire.dmi'
mob_override.dna.species.hunger_type = "vampire"
mob_override.dna.species.hunger_icon = 'icons/mob/screen_hunger_vampire.dmi'
check_vampire_upgrade(FALSE)
/datum/hud/proc/remove_vampire_hud()
@@ -1,24 +1,16 @@
/datum/antagonist/wishgranter
name = "Wishgranter Avatar"
special_role = "Avatar of the Wish Granter"
/datum/antagonist/wishgranter/proc/forge_objectives()
var/datum/objective/hijack/hijack = new
hijack.owner = owner
objectives += hijack
owner.objectives |= objectives
/datum/antagonist/wishgranter/on_gain()
owner.special_role = "Avatar of the Wish Granter"
forge_objectives()
. = ..()
give_powers()
/datum/antagonist/wishgranter/give_objectives()
add_objective(/datum/objective/hijack)
/datum/antagonist/wishgranter/greet()
to_chat(owner.current, "<B>Your inhibitions are swept away, the bonds of loyalty broken, you are free to murder as you please!</B>")
owner.announce_objectives()
..()
to_chat(owner.current, "<span class='notice'>Your inhibitions are swept away, the bonds of loyalty broken, you are free to murder as you please!</span>")
/datum/antagonist/wishgranter/proc/give_powers()
var/mob/living/carbon/human/H = owner.current
/datum/antagonist/wishgranter/apply_innate_effects(mob/living/mob_override)
var/mob/living/carbon/human/H = ..()
if(!istype(H))
return
H.ignore_gene_stability = TRUE