From 1d8bbb79ef251b28ca527fed85a13e3de8e14b94 Mon Sep 17 00:00:00 2001
From: John Willard <53777086+JohnFulpWillard@users.noreply.github.com>
Date: Sat, 19 Feb 2022 02:14:04 -0500
Subject: [PATCH] greentext code improvement (#64941)
---
code/__HELPERS/roundend.dm | 5 +-
code/game/objects/items.dm | 2 +-
code/game/objects/objs.dm | 2 +-
.../antagonists/greentext/greentext.dm | 8 +--
code/modules/events/wizard/greentext.dm | 71 ++++++++++---------
5 files changed, 44 insertions(+), 44 deletions(-)
diff --git a/code/__HELPERS/roundend.dm b/code/__HELPERS/roundend.dm
index dab964915bd..21dd707cbd2 100644
--- a/code/__HELPERS/roundend.dm
+++ b/code/__HELPERS/roundend.dm
@@ -207,9 +207,8 @@
to_chat(world, "
The round has ended.")
log_game("The round has ended.")
- for(var/I in round_end_events)
- var/datum/callback/cb = I
- cb.InvokeAsync()
+ for(var/datum/callback/roundend_callbacks as anything in round_end_events)
+ roundend_callbacks.InvokeAsync()
LAZYCLEARLIST(round_end_events)
var/speed_round = FALSE
diff --git a/code/game/objects/items.dm b/code/game/objects/items.dm
index 499db82b3aa..6b44b678af7 100644
--- a/code/game/objects/items.dm
+++ b/code/game/objects/items.dm
@@ -242,7 +242,7 @@ GLOBAL_DATUM_INIT(fire_overlay, /mutable_appearance, mutable_appearance('icons/e
if(mapload)
add_stealing_item_objective()
-/obj/item/Destroy()
+/obj/item/Destroy(force)
// This var exists as a weird proxy "owner" ref
// It's used in a few places. Stop using it, and optimially replace all uses please
master = null
diff --git a/code/game/objects/objs.dm b/code/game/objects/objs.dm
index 63c9e4719db..30b92379f5b 100644
--- a/code/game/objects/objs.dm
+++ b/code/game/objects/objs.dm
@@ -76,7 +76,7 @@
/// Needs to run before as ComponentInitialize runs after this statement...why do we have ComponentInitialize again?
-/obj/Destroy(force=FALSE)
+/obj/Destroy(force)
if(!ismachinery(src))
STOP_PROCESSING(SSobj, src) // TODO: Have a processing bitflag to reduce on unnecessary loops through the processing lists
SStgui.close_uis(src)
diff --git a/code/modules/antagonists/greentext/greentext.dm b/code/modules/antagonists/greentext/greentext.dm
index 07b2c8f61a4..97bd5c9e482 100644
--- a/code/modules/antagonists/greentext/greentext.dm
+++ b/code/modules/antagonists/greentext/greentext.dm
@@ -5,10 +5,10 @@
suicide_cry = "FOR THE GREENTEXT!!" // This can never actually show up, but not including it is a missed opportunity
/datum/antagonist/greentext/proc/forge_objectives()
- var/datum/objective/O = new /datum/objective("Succeed")
- O.completed = TRUE //YES!
- O.owner = owner
- objectives += O
+ var/datum/objective/succeed_objective = new /datum/objective("Succeed")
+ succeed_objective.completed = TRUE //YES!
+ succeed_objective.owner = owner
+ objectives += succeed_objective
/datum/antagonist/greentext/on_gain()
forge_objectives()
diff --git a/code/modules/events/wizard/greentext.dm b/code/modules/events/wizard/greentext.dm
index b88792b58bd..9c35aceedb2 100644
--- a/code/modules/events/wizard/greentext.dm
+++ b/code/modules/events/wizard/greentext.dm
@@ -25,21 +25,30 @@
w_class = WEIGHT_CLASS_BULKY
icon = 'icons/obj/wizard.dmi'
icon_state = "greentext"
+ resistance_flags = FIRE_PROOF | ACID_PROOF | INDESTRUCTIBLE
+ ///The last person to touch the greentext, used for failures.
var/mob/living/last_holder
+ ///The current holder of the greentext.
var/mob/living/new_holder
+ ///Every person who has touched the greentext, having their colors changed by it.
var/list/color_altered_mobs = list()
+ ///The callback at the end of a round to check if the greentext has been completed.
var/datum/callback/roundend_callback
- resistance_flags = FIRE_PROOF | ACID_PROOF
+ ///Boolean on whether to announce the greentext's destruction to all mobs.
var/quiet = FALSE
+/obj/item/greentext/quiet
+ quiet = TRUE
+
/obj/item/greentext/Initialize(mapload)
. = ..()
SSpoints_of_interest.make_point_of_interest(src)
- roundend_callback = CALLBACK(src,.proc/check_winner)
+ roundend_callback = CALLBACK(src, .proc/check_winner)
SSticker.OnRoundend(roundend_callback)
-/obj/item/greentext/equipped(mob/living/user as mob)
- to_chat(user, "So long as you leave this place with greentext in hand you know will be happy...")
+/obj/item/greentext/equipped(mob/user, slot, initial = FALSE)
+ . = ..()
+ to_chat(user, span_green("So long as you leave this place with greentext in hand you know will be happy..."))
var/list/other_objectives = user.mind.get_all_objectives()
if(user.mind && other_objectives.len > 0)
to_chat(user, span_warning("... so long as you still perform your other objectives that is!"))
@@ -47,31 +56,18 @@
if(!last_holder)
last_holder = user
if(!(user in color_altered_mobs))
- color_altered_mobs += user
+ color_altered_mobs |= user
user.add_atom_colour("#00FF00", ADMIN_COLOUR_PRIORITY)
START_PROCESSING(SSobj, src)
- ..()
-/obj/item/greentext/dropped(mob/living/user as mob)
+/obj/item/greentext/dropped(mob/user, silent = FALSE)
if(user in color_altered_mobs)
to_chat(user, span_warning("A sudden wave of failure washes over you..."))
user.add_atom_colour("#FF0000", ADMIN_COLOUR_PRIORITY) //ya blew it
+ STOP_PROCESSING(SSobj, src)
last_holder = null
new_holder = null
- STOP_PROCESSING(SSobj, src)
- ..()
-
-/obj/item/greentext/proc/check_winner()
- if(!new_holder)
- return
-
- if(is_centcom_level(new_holder.z))//you're winner!
- to_chat(new_holder, "At last it feels like victory is assured!")
- new_holder.mind.add_antag_datum(/datum/antagonist/greentext)
- new_holder.log_message("won with greentext!!!", LOG_ATTACK, color="green")
- color_altered_mobs -= new_holder
- resistance_flags |= ON_FIRE
- qdel(src)
+ return ..()
/obj/item/greentext/process()
if(last_holder && last_holder != new_holder) //Somehow it was swiped without ever getting dropped
@@ -80,23 +76,28 @@
last_holder = new_holder //long live the king
/obj/item/greentext/Destroy(force)
- if(!(resistance_flags & ON_FIRE) && !force)
- return QDEL_HINT_LETMELIVE
-
LAZYREMOVE(SSticker.round_end_events, roundend_callback)
- roundend_callback = null //This ought to free the callback datum, and prevent us from harddeling
- for(var/i in GLOB.player_list)
- var/mob/M = i
+ QDEL_NULL(roundend_callback) //This ought to free the callback datum, and prevent us from harddeling
+ for(var/mob/all_player_mobs as anything in GLOB.player_list)
var/message = "A dark temptation has passed from this world"
- if(M in color_altered_mobs)
+ if(all_player_mobs in color_altered_mobs)
message += " and you're finally able to forgive yourself"
- if(M.color == "#FF0000" || M.color == "#00FF00")
- M.remove_atom_colour(ADMIN_COLOUR_PRIORITY)
+ if(all_player_mobs.color == "#FF0000" || all_player_mobs.color == "#00FF00")
+ all_player_mobs.remove_atom_colour(ADMIN_COLOUR_PRIORITY)
message += "..."
- // can't skip the mob check as it also does the decolouring
if(!quiet)
- to_chat(M, message)
- . = ..()
+ to_chat(all_player_mobs, message)
+ return ..()
-/obj/item/greentext/quiet
- quiet = TRUE
+/obj/item/greentext/proc/check_winner()
+ if(!new_holder)
+ return
+ if(!is_centcom_level(new_holder.z)) //you're winner!
+ return
+
+ to_chat(new_holder, "At last it feels like victory is assured!")
+ new_holder.mind.add_antag_datum(/datum/antagonist/greentext)
+ new_holder.log_message("won with greentext!!!", LOG_ATTACK, color = "green")
+ color_altered_mobs -= new_holder
+ resistance_flags |= ON_FIRE
+ qdel(src)