From 5273e9626790e3bf34e601a2bd2447ded06bb80b Mon Sep 17 00:00:00 2001 From: Bobbahbrown Date: Mon, 9 Dec 2019 03:48:45 -0400 Subject: [PATCH] Cleanup of Hailer Masks (#48132) About The Pull Request I noticed that hailer mask code had some weird smells so I refactored some stuff. Please tell me if stuff is still smelly or I did a bad job. primarily: DESTROYED big switch, replaced with datums as recommended by ninja + floyd DESTROYED references to world time and instead used timers and callbacks DESTROYED non-defined use of constants everywhere and made code more legible DESTROYED some uses of 0 for FALSE and 1 for TRUE Why It's Good For The Game fewer smells Changelog cl bobbahbrown refactor: Removed some stinky smells from hailer mask code. /cl --- code/datums/hailer_phrase.dm | 79 +++++++++ code/modules/clothing/masks/hailer.dm | 232 +++++++++++++------------- tgstation.dme | 1 + 3 files changed, 195 insertions(+), 117 deletions(-) create mode 100644 code/datums/hailer_phrase.dm diff --git a/code/datums/hailer_phrase.dm b/code/datums/hailer_phrase.dm new file mode 100644 index 00000000000..a146146d4f0 --- /dev/null +++ b/code/datums/hailer_phrase.dm @@ -0,0 +1,79 @@ +/datum/hailer_phrase + var/phrase_text = null + var/phrase_sound = null + +/datum/hailer_phrase/emag + phrase_text = "FUCK YOUR CUNT YOU SHIT EATING COCKSTORM AND EAT A DONG FUCKING ASS RAMMING SHIT FUCK EAT PENISES IN YOUR FUCK FACE AND SHIT OUT ABORTIONS OF FUCK AND POO AND SHIT IN YOUR ASS YOU COCK FUCK SHIT MONKEY FUCK ASS WANKER FROM THE DEPTHS OF SHIT." + phrase_sound = "emag" + +/datum/hailer_phrase/halt + phrase_text = "HALT! HALT! HALT!" + phrase_sound = "halt" + +/datum/hailer_phrase/bobby + phrase_text = "Stop in the name of the Law." + phrase_sound = "bobby" + +/datum/hailer_phrase/compliance + phrase_text = "Compliance is in your best interest." + phrase_sound = "compliance" + +/datum/hailer_phrase/justice + phrase_text = "Prepare for justice!" + phrase_sound = "justice" + +/datum/hailer_phrase/running + phrase_text = "Running will only increase your sentence." + phrase_sound = "running" + +/datum/hailer_phrase/dontmove + phrase_text = "Don't move, Creep!" + phrase_sound = "dontmove" + +/datum/hailer_phrase/floor + phrase_text = "Down on the floor, Creep!" + phrase_sound = "floor" + +/datum/hailer_phrase/robocop + phrase_text = "Dead or alive you're coming with me." + phrase_sound = "robocop" + +/datum/hailer_phrase/god + phrase_text = "God made today for the crooks we could not catch yesterday." + phrase_sound = "god" + +/datum/hailer_phrase/freeze + phrase_text = "Freeze, Scum Bag!" + phrase_sound = "freeze" + +/datum/hailer_phrase/imperial + phrase_text = "Stop right there, criminal scum!" + phrase_sound = "imperial" + +/datum/hailer_phrase/bash + phrase_text = "Stop or I'll bash you." + phrase_sound = "bash" + +/datum/hailer_phrase/harry + phrase_text = "Go ahead, make my day." + phrase_sound = "harry" + +/datum/hailer_phrase/asshole + phrase_text = "Stop breaking the law, ass hole." + phrase_sound = "asshole" + +/datum/hailer_phrase/stfu + phrase_text = "You have the right to shut the fuck up." + phrase_sound = "stfu" + +/datum/hailer_phrase/shutup + phrase_text = "Shut up crime!" + phrase_sound = "shutup" + +/datum/hailer_phrase/super + phrase_text = "Face the wrath of the golden bolt." + phrase_sound = "super" + +/datum/hailer_phrase/dredd + phrase_text = "I am, the LAW!" + phrase_sound = "dredd" diff --git a/code/modules/clothing/masks/hailer.dm b/code/modules/clothing/masks/hailer.dm index c1c0c0b002b..0a9c5e5b51c 100644 --- a/code/modules/clothing/masks/hailer.dm +++ b/code/modules/clothing/masks/hailer.dm @@ -1,6 +1,47 @@ // **** Security gas mask **** +// Cooldown times +#define PHRASE_COOLDOWN 30 +#define OVERUSE_COOLDOWN 180 + +// Aggression levels +#define AGGR_GOOD_COP 1 +#define AGGR_BAD_COP 2 +#define AGGR_SHIT_COP 3 +#define AGGR_BROKEN 4 + +// Phrase list index markers +#define EMAG_PHRASE 1 // index of emagged phrase +#define GOOD_COP_PHRASES 6 // final index of good cop phrases +#define BAD_COP_PHRASES 12 // final index of bad cop phrases +#define BROKE_PHRASES 13 // starting index of broken phrases +#define ALL_PHRASES 19 // total phrases + +// All possible hailer phrases +// Remember to modify above index markers if changing contents +GLOBAL_LIST_INIT(hailer_phrases, list( + /datum/hailer_phrase/emag, + /datum/hailer_phrase/halt, + /datum/hailer_phrase/bobby, + /datum/hailer_phrase/compliance, + /datum/hailer_phrase/justice, + /datum/hailer_phrase/running, + /datum/hailer_phrase/dontmove, + /datum/hailer_phrase/floor, + /datum/hailer_phrase/robocop, + /datum/hailer_phrase/god, + /datum/hailer_phrase/freeze, + /datum/hailer_phrase/imperial, + /datum/hailer_phrase/bash, + /datum/hailer_phrase/harry, + /datum/hailer_phrase/asshole, + /datum/hailer_phrase/stfu, + /datum/hailer_phrase/shutup, + /datum/hailer_phrase/super, + /datum/hailer_phrase/dredd +)) + /obj/item/clothing/mask/gas/sechailer name = "security gas mask" desc = "A standard issue Security gas mask with integrated 'Compli-o-nator 3000' device. Plays over a dozen pre-recorded compliance phrases designed to get scumbags to stand still whilst you tase them. Do not tamper with the device." @@ -14,10 +55,10 @@ visor_flags_inv = HIDEFACE flags_cover = MASKCOVERSMOUTH | MASKCOVERSEYES | PEPPERPROOF visor_flags_cover = MASKCOVERSMOUTH | MASKCOVERSEYES | PEPPERPROOF - var/aggressiveness = 2 - var/cooldown_special + var/aggressiveness = AGGR_BAD_COP + var/overuse_cooldown = FALSE var/recent_uses = 0 - var/broken_hailer = 0 + var/broken_hailer = FALSE var/safety = TRUE /obj/item/clothing/mask/gas/sechailer/swat @@ -26,8 +67,8 @@ actions_types = list(/datum/action/item_action/halt) icon_state = "swat" item_state = "swat" - aggressiveness = 3 - flags_inv = HIDEFACIALHAIR|HIDEFACE|HIDEEYES|HIDEEARS|HIDEHAIR + aggressiveness = AGGR_SHIT_COP + flags_inv = HIDEFACIALHAIR | HIDEFACE | HIDEEYES | HIDEEARS | HIDEHAIR visor_flags_inv = 0 /obj/item/clothing/mask/gas/sechailer/swat/spacepol @@ -41,32 +82,26 @@ desc = "A set of recognizable pre-recorded messages for cyborgs to use when apprehending criminals." icon = 'icons/obj/device.dmi' icon_state = "taperecorder_idle" - aggressiveness = 1 //Borgs are nicecurity! + aggressiveness = AGGR_GOOD_COP // Borgs are nicecurity! actions_types = list(/datum/action/item_action/halt) /obj/item/clothing/mask/gas/sechailer/screwdriver_act(mob/living/user, obj/item/I) + . = TRUE if(..()) - return TRUE - switch(aggressiveness) - if(1) - to_chat(user, "You set the restrictor to the middle position.") - aggressiveness = 2 - if(2) - to_chat(user, "You set the restrictor to the last position.") - aggressiveness = 3 - if(3) - to_chat(user, "You set the restrictor to the first position.") - aggressiveness = 1 - if(4) - to_chat(user, "You adjust the restrictor but nothing happens, probably because it's broken.") - return TRUE + return + else if (aggressiveness == AGGR_BROKEN) + to_chat(user, "You adjust the restrictor but nothing happens, probably because it's broken.") + return + var/position = aggressiveness == AGGR_GOOD_COP ? "middle" : aggressiveness == AGGR_BAD_COP ? "last" : "first" + to_chat(user, "You set the restrictor to the [position] position.") + aggressiveness = aggressiveness % 3 + 1 // loop AGGR_GOOD_COP -> AGGR_SHIT_COP /obj/item/clothing/mask/gas/sechailer/wirecutter_act(mob/living/user, obj/item/I) + . = TRUE ..() - if(aggressiveness != 4) + if(aggressiveness != AGGR_BROKEN) to_chat(user, "You broke the restrictor!") - aggressiveness = 4 - return TRUE + aggressiveness = AGGR_BROKEN /obj/item/clothing/mask/gas/sechailer/ui_action_click(mob/user, action) if(istype(action, /datum/action/item_action/halt)) @@ -76,117 +111,80 @@ /obj/item/clothing/mask/gas/sechailer/attack_self() halt() + /obj/item/clothing/mask/gas/sechailer/emag_act(mob/user as mob) if(safety) safety = FALSE to_chat(user, "You silently fry [src]'s vocal circuit with the cryptographic sequencer.") - else - return /obj/item/clothing/mask/gas/sechailer/verb/halt() set category = "Object" set name = "HALT" set src in usr - if(!isliving(usr)) - return - if(!can_use(usr)) + if(!isliving(usr) || !can_use(usr) || cooldown) return if(broken_hailer) to_chat(usr, "\The [src]'s hailing system is broken.") return - var/phrase = 0 //selects which phrase to use - var/phrase_text = null - var/phrase_sound = null + // handle recent uses for overuse + recent_uses++ + if(!overuse_cooldown) // check if we can reset recent uses + recent_uses = 0 + overuse_cooldown = TRUE + addtimer(CALLBACK(src, /obj/item/clothing/mask/gas/sechailer/proc/reset_overuse_cooldown), OVERUSE_COOLDOWN) + + switch(recent_uses) + if(3) + to_chat(usr, "\The [src] is starting to heat up.") + if(4) + to_chat(usr, "\The [src] is heating up dangerously from overuse!") + if(5) // overload + broken_hailer = TRUE + to_chat(usr, "\The [src]'s power modulator overloads and breaks.") + return + + // select phrase to play + play_phrase(usr, GLOB.hailer_phrases[select_phrase()]) - if(cooldown < world.time - 30) // A cooldown, to stop people being jerks - recent_uses++ - if(cooldown_special < world.time - 180) //A better cooldown that burns jerks - recent_uses = initial(recent_uses) +/obj/item/clothing/mask/gas/sechailer/proc/select_phrase() + if (!safety) + return EMAG_PHRASE + else + var/upper_limit + switch (aggressiveness) + if (AGGR_GOOD_COP) + upper_limit = GOOD_COP_PHRASES + if (AGGR_BAD_COP) + upper_limit = BAD_COP_PHRASES + else + upper_limit = ALL_PHRASES + return rand(aggressiveness == AGGR_BROKEN ? BROKE_PHRASES : EMAG_PHRASE + 1, upper_limit) - switch(recent_uses) - if(3) - to_chat(usr, "\The [src] is starting to heat up.") - if(4) - to_chat(usr, "\The [src] is heating up dangerously from overuse!") - if(5) //overload - broken_hailer = 1 - to_chat(usr, "\The [src]'s power modulator overloads and breaks.") - return +/obj/item/clothing/mask/gas/sechailer/proc/play_phrase(mob/user, datum/hailer_phrase/phrase) + . = FALSE + if (!cooldown) + usr.audible_message("[usr]'s Compli-o-Nator: [initial(phrase.phrase_text)]") + playsound(src.loc, "sound/voice/complionator/[initial(phrase.phrase_sound)].ogg", 100, FALSE, 4) + cooldown = TRUE + addtimer(CALLBACK(src, /obj/item/clothing/mask/gas/sechailer/proc/reset_cooldown), PHRASE_COOLDOWN) + . = TRUE - switch(aggressiveness) // checks if the user has unlocked the restricted phrases - if(1) - phrase = rand(1,5) // set the upper limit as the phrase above the first 'bad cop' phrase, the mask will only play 'nice' phrases - if(2) - phrase = rand(1,11) // default setting, set upper limit to last 'bad cop' phrase. Mask will play good cop and bad cop phrases - if(3) - phrase = rand(1,18) // user has unlocked all phrases, set upper limit to last phrase. The mask will play all phrases - if(4) - phrase = rand(12,18) // user has broke the restrictor, it will now only play shitcurity phrases +/obj/item/clothing/mask/gas/sechailer/proc/reset_cooldown() + cooldown = FALSE - if(!safety) - phrase_text = "FUCK YOUR CUNT YOU SHIT EATING COCKSTORM AND EAT A DONG FUCKING ASS RAMMING SHIT FUCK EAT PENISES IN YOUR FUCK FACE AND SHIT OUT ABORTIONS OF FUCK AND POO AND SHIT IN YOUR ASS YOU COCK FUCK SHIT MONKEY FUCK ASS WANKER FROM THE DEPTHS OF SHIT." - phrase_sound = "emag" - else +/obj/item/clothing/mask/gas/sechailer/proc/reset_overuse_cooldown() + overuse_cooldown = FALSE - switch(phrase) //sets the properties of the chosen phrase - if(1) // good cop - phrase_text = "HALT! HALT! HALT!" - phrase_sound = "halt" - if(2) - phrase_text = "Stop in the name of the Law." - phrase_sound = "bobby" - if(3) - phrase_text = "Compliance is in your best interest." - phrase_sound = "compliance" - if(4) - phrase_text = "Prepare for justice!" - phrase_sound = "justice" - if(5) - phrase_text = "Running will only increase your sentence." - phrase_sound = "running" - if(6) // bad cop - phrase_text = "Don't move, Creep!" - phrase_sound = "dontmove" - if(7) - phrase_text = "Down on the floor, Creep!" - phrase_sound = "floor" - if(8) - phrase_text = "Dead or alive you're coming with me." - phrase_sound = "robocop" - if(9) - phrase_text = "God made today for the crooks we could not catch yesterday." - phrase_sound = "god" - if(10) - phrase_text = "Freeze, Scum Bag!" - phrase_sound = "freeze" - if(11) - phrase_text = "Stop right there, criminal scum!" - phrase_sound = "imperial" - if(12) // LA-PD - phrase_text = "Stop or I'll bash you." - phrase_sound = "bash" - if(13) - phrase_text = "Go ahead, make my day." - phrase_sound = "harry" - if(14) - phrase_text = "Stop breaking the law, ass hole." - phrase_sound = "asshole" - if(15) - phrase_text = "You have the right to shut the fuck up." - phrase_sound = "stfu" - if(16) - phrase_text = "Shut up crime!" - phrase_sound = "shutup" - if(17) - phrase_text = "Face the wrath of the golden bolt." - phrase_sound = "super" - if(18) - phrase_text = "I am, the LAW!" - phrase_sound = "dredd" - - usr.audible_message("[usr]'s Compli-o-Nator: [phrase_text]") - playsound(src.loc, "sound/voice/complionator/[phrase_sound].ogg", 100, FALSE, 4) - cooldown = world.time - cooldown_special = world.time +#undef PHRASE_COOLDOWN +#undef OVERUSE_COOLDOWN +#undef AGGR_GOOD_COP +#undef AGGR_BAD_COP +#undef AGGR_SHIT_COP +#undef AGGR_BROKEN +#undef EMAG_PHRASE +#undef GOOD_COP_PHRASES +#undef BAD_COP_PHRASES +#undef BROKE_PHRASES +#undef ALL_PHRASES diff --git a/tgstation.dme b/tgstation.dme index bb14fd74b57..78c31cd256e 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -322,6 +322,7 @@ #include "code\datums\ert.dm" #include "code\datums\explosion.dm" #include "code\datums\forced_movement.dm" +#include "code\datums\hailer_phrase.dm" #include "code\datums\holocall.dm" #include "code\datums\hud.dm" #include "code\datums\map_config.dm"