From 017aad988dc3e581823e99ae3f75795ee84f1ae6 Mon Sep 17 00:00:00 2001
From: SkyratBot <59378654+SkyratBot@users.noreply.github.com>
Date: Wed, 24 Mar 2021 15:57:28 +0100
Subject: [PATCH] [MIRROR] Highlander + Summon Guns and Magic now uses signals
to equip new crewmembers (#4358)
* Highlander + Summon Guns and Magic now uses signals to equip new crewmembers (#57817)
* Highlander + Summon Guns and Magic now uses signals to equip new crewmembers
Co-authored-by: tralezab <40974010+tralezab@users.noreply.github.com>
---
code/modules/admin/verbs/highlander_datum.dm | 98 +++++++++++++++++++
code/modules/admin/verbs/onlyone.dm | 51 ----------
.../antagonists/highlander/highlander.dm | 2 +-
.../modules/mob/dead/new_player/new_player.dm | 7 --
.../spells/spell_types/rightandwrong.dm | 88 +++++++++++++----
tgstation.dme | 2 +-
6 files changed, 169 insertions(+), 79 deletions(-)
create mode 100644 code/modules/admin/verbs/highlander_datum.dm
delete mode 100644 code/modules/admin/verbs/onlyone.dm
diff --git a/code/modules/admin/verbs/highlander_datum.dm b/code/modules/admin/verbs/highlander_datum.dm
new file mode 100644
index 00000000000..0cd14dfdac4
--- /dev/null
+++ b/code/modules/admin/verbs/highlander_datum.dm
@@ -0,0 +1,98 @@
+
+GLOBAL_DATUM(highlander_controller, /datum/highlander_controller)
+
+
+/**
+ * The highlander controller handles the admin highlander mode, if enabled.
+ * It is first created when "there can only be one" triggers it, and it can be referenced from GLOB.highlander_controller
+ */
+/datum/highlander_controller
+
+/datum/highlander_controller/New()
+ . = ..()
+ RegisterSignal(SSdcs, COMSIG_GLOB_CREWMEMBER_JOINED, .proc/new_highlander)
+ sound_to_playing_players('sound/misc/highlander.ogg')
+ send_to_playing_players("THERE CAN BE ONLY ONE")
+ for(var/obj/item/disk/nuclear/fukkendisk in GLOB.poi_list)
+ var/datum/component/stationloving/component = fukkendisk.GetComponent(/datum/component/stationloving)
+ component?.relocate() //Gets it out of bags and such
+
+ for(var/mob/living/carbon/human/human in GLOB.player_list)
+ if(human.stat == DEAD)
+ continue
+ human.make_scottish()
+
+ for(var/mob/living/silicon/ai/AI in GLOB.player_list)
+ if(!istype(AI) || AI.stat == DEAD)
+ continue
+ if(AI.deployed_shell)
+ AI.deployed_shell.undeploy()
+ AI.change_mob_type(/mob/living/silicon/robot , null, null)
+ AI.gib()
+
+ for(var/mob/living/silicon/robot/robot in GLOB.player_list)
+ if(!istype(robot) || robot.stat == DEAD)
+ continue
+ if(robot.shell)
+ robot.gib()
+ continue
+ robot.make_scottish()
+ addtimer(CALLBACK(SSshuttle.emergency, /obj/docking_port/mobile/emergency.proc/request, null, 1), 50)
+
+/datum/highlander_controller/Destroy(force, ...)
+ . = ..()
+ UnregisterSignal(SSdcs, COMSIG_GLOB_CREWMEMBER_JOINED)
+
+/**
+ * Triggers at beginning of the game when there is a confirmed list of valid, ready players.
+ * Creates a 100% ready game that has NOT started (no players in bodies)
+ * Followed by start game
+ *
+ * Does the following:
+ * * Picks map, and loads it
+ * * Grabs landmarks if it is the first time it's loading
+ * * Sets up the role list
+ * * Puts players in each role randomly
+ * Arguments:
+ * * setup_list: list of all the datum setups (fancy list of roles) that would work for the game
+ * * ready_players: list of filtered, sane players (so not playing or disconnected) for the game to put into roles
+ */
+/datum/highlander_controller/proc/new_highlander(mob/living/carbon/human/new_crewmember, rank)
+ SIGNAL_HANDLER
+
+ to_chat(new_crewmember, "THERE CAN BE ONLY ONE!!!")
+ new_crewmember.make_scottish()
+
+/**
+ * Gives everyone kilts, berets, claymores, and pinpointers, with the objective to hijack the emergency shuttle.
+ * Uses highlander controller to do so!
+ *
+ * Arguments:
+ * * was_delayed: boolean: whether the option to do a "delayed" highlander was pressed before this was called, changes up the logging a bit.
+
+ */
+/client/proc/only_one(was_delayed = FALSE)
+ if(!SSticker.HasRoundStarted())
+ alert("The game hasn't started yet!")
+ return
+
+ if(was_delayed) //sends more accurate logs
+ message_admins("[key_name_admin(usr)]'s delayed THERE CAN ONLY BE ONE started!")
+ log_admin("[key_name(usr)] delayed THERE CAN ONLY BE ONE started.")
+ else
+ message_admins("[key_name_admin(usr)] used THERE CAN BE ONLY ONE!")
+ log_admin("[key_name(usr)] used THERE CAN BE ONLY ONE.")
+
+ GLOB.highlander_controller = new /datum/highlander_controller
+
+/client/proc/only_one_delayed()
+ send_to_playing_players("Bagpipes begin to blare. You feel Scottish pride coming over you.")
+ message_admins("[key_name_admin(usr)] used (delayed) THERE CAN BE ONLY ONE!")
+ log_admin("[key_name(usr)] used delayed THERE CAN BE ONLY ONE.")
+ addtimer(CALLBACK(src, .proc/only_one, TRUE), 42 SECONDS)
+
+/mob/living/carbon/human/proc/make_scottish()
+ mind.add_antag_datum(/datum/antagonist/highlander)
+
+/mob/living/silicon/robot/proc/make_scottish()
+ mind.add_antag_datum(/datum/antagonist/highlander/robot)
diff --git a/code/modules/admin/verbs/onlyone.dm b/code/modules/admin/verbs/onlyone.dm
deleted file mode 100644
index cbee1b49dbd..00000000000
--- a/code/modules/admin/verbs/onlyone.dm
+++ /dev/null
@@ -1,51 +0,0 @@
-GLOBAL_VAR_INIT(highlander, FALSE)
-/client/proc/only_one() //Gives everyone kilts, berets, claymores, and pinpointers, with the objective to hijack the emergency shuttle.
- if(!SSticker.HasRoundStarted())
- alert("The game hasn't started yet!")
- return
- GLOB.highlander = TRUE
-
- sound_to_playing_players('sound/misc/highlander.ogg')
- send_to_playing_players("THERE CAN BE ONLY ONE")
-
- for(var/obj/item/disk/nuclear/N in GLOB.poi_list)
- var/datum/component/stationloving/component = N.GetComponent(/datum/component/stationloving)
- if (component)
- component.relocate() //Gets it out of bags and such
-
- for(var/mob/living/carbon/human/H in GLOB.player_list)
- if(H.stat == DEAD)
- continue
- H.make_scottish()
-
- for(var/mob/living/silicon/ai/AI in GLOB.player_list)
- if(!istype(AI) || AI.stat == DEAD)
- continue
- if(AI.deployed_shell)
- AI.deployed_shell.undeploy()
- AI.change_mob_type(/mob/living/silicon/robot , null, null)
- AI.gib()
-
- for(var/mob/living/silicon/robot/robot in GLOB.player_list)
- if(!istype(robot) || robot.stat == DEAD)
- continue
- if(robot.shell)
- robot.gib()
- continue
- robot.make_scottish()
-
- message_admins("[key_name_admin(usr)] used THERE CAN BE ONLY ONE!")
- log_admin("[key_name(usr)] used THERE CAN BE ONLY ONE.")
- addtimer(CALLBACK(SSshuttle.emergency, /obj/docking_port/mobile/emergency.proc/request, null, 1), 50)
-
-/client/proc/only_one_delayed()
- send_to_playing_players("Bagpipes begin to blare. You feel Scottish pride coming over you.")
- message_admins("[key_name_admin(usr)] used (delayed) THERE CAN BE ONLY ONE!")
- log_admin("[key_name(usr)] used delayed THERE CAN BE ONLY ONE.")
- addtimer(CALLBACK(src, .proc/only_one), 42 SECONDS)
-
-/mob/living/carbon/human/proc/make_scottish()
- mind.add_antag_datum(/datum/antagonist/highlander)
-
-/mob/living/silicon/robot/proc/make_scottish()
- mind.add_antag_datum(/datum/antagonist/highlander/robot)
diff --git a/code/modules/antagonists/highlander/highlander.dm b/code/modules/antagonists/highlander/highlander.dm
index c1e636e51e3..f083a6a2b32 100644
--- a/code/modules/antagonists/highlander/highlander.dm
+++ b/code/modules/antagonists/highlander/highlander.dm
@@ -70,7 +70,7 @@
H.equip_to_slot_or_del(W, ITEM_SLOT_ID)
sword = new(H)
- if(!GLOB.highlander)
+ if(!GLOB.highlander_controller)
sword.flags_1 |= ADMIN_SPAWNED_1 //To prevent announcing
sword.pickup(H) //For the stun shielding
H.put_in_hands(sword)
diff --git a/code/modules/mob/dead/new_player/new_player.dm b/code/modules/mob/dead/new_player/new_player.dm
index 75801332d6d..15f51f5c34e 100644
--- a/code/modules/mob/dead/new_player/new_player.dm
+++ b/code/modules/mob/dead/new_player/new_player.dm
@@ -391,17 +391,10 @@
else
AnnounceArrival(humanc, rank)
AddEmploymentContract(humanc)
- if(GLOB.highlander)
- to_chat(humanc, "THERE CAN BE ONLY ONE!!!")
- humanc.make_scottish()
humanc.increment_scar_slot()
humanc.load_persistent_scars()
- if(GLOB.summon_guns_triggered)
- give_guns(humanc)
- if(GLOB.summon_magic_triggered)
- give_magic(humanc)
if(GLOB.curse_of_madness_triggered)
give_madness(humanc, GLOB.curse_of_madness_triggered)
diff --git a/code/modules/spells/spell_types/rightandwrong.dm b/code/modules/spells/spell_types/rightandwrong.dm
index 10267598cca..23a766337f9 100644
--- a/code/modules/spells/spell_types/rightandwrong.dm
+++ b/code/modules/spells/spell_types/rightandwrong.dm
@@ -1,4 +1,8 @@
//In this file: Summon Magic/Summon Guns/Summon Events
+//and corresponding datum controller for them
+
+GLOBAL_DATUM(summon_guns, /datum/summon_guns_controller)
+GLOBAL_DATUM(summon_magic, /datum/summon_magic_controller)
// 1 in 50 chance of getting something really special.
#define SPECIALIST_MAGIC_PROB 2
@@ -95,18 +99,14 @@ GLOBAL_LIST_INIT(summoned_magic_objectives, list(
/obj/item/storage/belt/wands/full,
/obj/item/warpwhistle))
-// If true, it's the probability of triggering "survivor" antag.
-GLOBAL_VAR_INIT(summon_guns_triggered, FALSE)
-GLOBAL_VAR_INIT(summon_magic_triggered, FALSE)
-
/proc/give_guns(mob/living/carbon/human/H)
if(H.stat == DEAD || !(H.client))
return
if(H.mind)
if(iswizard(H) || H.mind.has_antag_datum(/datum/antagonist/survivalist/guns))
return
-
- if(prob(GLOB.summon_guns_triggered) && !(H.mind.has_antag_datum(/datum/antagonist)))
+ var/datum/summon_guns_controller/controller = GLOB.summon_guns
+ if(prob(controller.survivor_probability) && !(H.mind.has_antag_datum(/datum/antagonist)))
SSticker.mode.traitors += H.mind
H.mind.add_antag_datum(/datum/antagonist/survivalist/guns)
@@ -128,8 +128,10 @@ GLOBAL_VAR_INIT(summon_magic_triggered, FALSE)
if(H.mind)
if(iswizard(H) || H.mind.has_antag_datum(/datum/antagonist/survivalist/magic))
return
-
- if(prob(GLOB.summon_magic_triggered) && !(H.mind.has_antag_datum(/datum/antagonist)))
+ if(!GLOB.summon_magic)
+ return
+ var/datum/summon_magic_controller/controller = GLOB.summon_magic
+ if(prob(controller.survivor_probability) && !(H.mind.has_antag_datum(/datum/antagonist)))
H.mind.add_antag_datum(/datum/antagonist/survivalist/magic)
H.log_message("was made into a survivalist, and trusts no one!", LOG_ATTACK, color="red")
@@ -156,21 +158,12 @@ GLOBAL_VAR_INIT(summon_magic_triggered, FALSE)
log_game("[key_name(user)] summoned [summon_type]!")
if(summon_type == SUMMON_MAGIC)
- GLOB.summon_magic_triggered = survivor_probability
+ GLOB.summon_magic = new /datum/summon_magic_controller(survivor_probability)
else if(summon_type == SUMMON_GUNS)
- GLOB.summon_guns_triggered = survivor_probability
+ GLOB.summon_guns = new /datum/summon_guns_controller(survivor_probability)
else
CRASH("Bad summon_type given: [summon_type]")
- for(var/mob/living/carbon/human/H in GLOB.player_list)
- var/turf/T = get_turf(H)
- if(T && is_away_level(T.z))
- continue
- if(summon_type == SUMMON_MAGIC)
- give_magic(H)
- else
- give_guns(H)
-
/proc/summonevents()
if(!SSevents.wizardmode)
SSevents.frequency_lower = 600 //1 minute lower bound
@@ -188,3 +181,60 @@ GLOBAL_VAR_INIT(summon_magic_triggered, FALSE)
log_game("Summon Events was increased!")
#undef SPECIALIST_MAGIC_PROB
+
+/**
+ * The magic controller handles the summon magic event.
+ * It is first created when summon magic event is triggered, and it can be referenced from GLOB.summon_magic
+ */
+/datum/summon_magic_controller
+ ///chances someone who is given magic will be an antagonist
+ var/survivor_probability = 0
+
+/datum/summon_magic_controller/New(survivor_probability)
+ . = ..()
+ src.survivor_probability = survivor_probability
+ RegisterSignal(SSdcs, COMSIG_GLOB_CREWMEMBER_JOINED, .proc/magic_up_new_crew)
+
+ for(var/mob/living/carbon/human/unarmed_human in GLOB.player_list)
+ var/turf/turf_check = get_turf(unarmed_human)
+ if(turf_check && is_away_level(turf_check.z))
+ continue
+ give_magic(unarmed_human)
+
+/datum/summon_magic_controller/Destroy(force, ...)
+ . = ..()
+ UnregisterSignal(SSdcs, COMSIG_GLOB_CREWMEMBER_JOINED)
+
+///signal proc to give magic to new crewmembers
+/proc/magic_up_new_crew(mob/living/carbon/human/new_crewmember, rank)
+ SIGNAL_HANDLER
+ INVOKE_ASYNC(GLOB.summon_magic, .proc/give_magic, new_crewmember)
+
+/**
+ * The guns controller handles the summon guns event.
+ * It is first created when summon guns event is triggered, and it can be referenced from GLOB.summon_guns
+ */
+/datum/summon_guns_controller
+ ///chances someone who is given guns will be an antagonist
+ var/survivor_probability = 0
+
+/datum/summon_guns_controller/New(survivor_probability)
+ . = ..()
+ src.survivor_probability = survivor_probability
+ RegisterSignal(SSdcs, COMSIG_GLOB_CREWMEMBER_JOINED, .proc/arm_up_new_crew)
+
+ for(var/mob/living/carbon/human/unarmed_human in GLOB.player_list)
+ var/turf/turf_check = get_turf(unarmed_human)
+ if(turf_check && is_away_level(turf_check.z))
+ continue
+ give_guns(unarmed_human)
+
+/datum/summon_guns_controller/Destroy(force, ...)
+ . = ..()
+ UnregisterSignal(SSdcs, COMSIG_GLOB_CREWMEMBER_JOINED)
+
+///signal proc to give guns to new crewmembers
+/proc/arm_up_new_crew(mob/living/carbon/human/new_crewmember, rank)
+ SIGNAL_HANDLER
+ INVOKE_ASYNC(GLOB.summon_guns, .proc/give_guns, new_crewmember)
+
diff --git a/tgstation.dme b/tgstation.dme
index ca11d9b92f8..fa53f3941cd 100644
--- a/tgstation.dme
+++ b/tgstation.dme
@@ -1560,6 +1560,7 @@
#include "code\modules\admin\verbs\fps.dm"
#include "code\modules\admin\verbs\getlogs.dm"
#include "code\modules\admin\verbs\ghost_pool_protection.dm"
+#include "code\modules\admin\verbs\highlander_datum.dm"
#include "code\modules\admin\verbs\individual_logging.dm"
#include "code\modules\admin\verbs\machine_upgrade.dm"
#include "code\modules\admin\verbs\manipulate_organs.dm"
@@ -1567,7 +1568,6 @@
#include "code\modules\admin\verbs\mapping.dm"
#include "code\modules\admin\verbs\maprotation.dm"
#include "code\modules\admin\verbs\one_click_antag.dm"
-#include "code\modules\admin\verbs\onlyone.dm"
#include "code\modules\admin\verbs\panicbunker.dm"
#include "code\modules\admin\verbs\playsound.dm"
#include "code\modules\admin\verbs\possess.dm"