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
This commit is contained in:
Bobbahbrown
2019-12-09 20:48:45 +13:00
committed by oranges
parent 32f2a844bf
commit 5273e96267
3 changed files with 195 additions and 117 deletions
+115 -117
View File
@@ -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, "<span class='notice'>You set the restrictor to the middle position.</span>")
aggressiveness = 2
if(2)
to_chat(user, "<span class='notice'>You set the restrictor to the last position.</span>")
aggressiveness = 3
if(3)
to_chat(user, "<span class='notice'>You set the restrictor to the first position.</span>")
aggressiveness = 1
if(4)
to_chat(user, "<span class='danger'>You adjust the restrictor but nothing happens, probably because it's broken.</span>")
return TRUE
return
else if (aggressiveness == AGGR_BROKEN)
to_chat(user, "<span class='danger'>You adjust the restrictor but nothing happens, probably because it's broken.</span>")
return
var/position = aggressiveness == AGGR_GOOD_COP ? "middle" : aggressiveness == AGGR_BAD_COP ? "last" : "first"
to_chat(user, "<span class='notice'>You set the restrictor to the [position] position.</span>")
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, "<span class='danger'>You broke the restrictor!</span>")
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, "<span class='warning'>You silently fry [src]'s vocal circuit with the cryptographic sequencer.</span>")
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, "<span class='warning'>\The [src]'s hailing system is broken.</span>")
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, "<span class='warning'>\The [src] is starting to heat up.</span>")
if(4)
to_chat(usr, "<span class='userdanger'>\The [src] is heating up dangerously from overuse!</span>")
if(5) // overload
broken_hailer = TRUE
to_chat(usr, "<span class='userdanger'>\The [src]'s power modulator overloads and breaks.</span>")
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, "<span class='warning'>\The [src] is starting to heat up.</span>")
if(4)
to_chat(usr, "<span class='userdanger'>\The [src] is heating up dangerously from overuse!</span>")
if(5) //overload
broken_hailer = 1
to_chat(usr, "<span class='userdanger'>\The [src]'s power modulator overloads and breaks.</span>")
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: <font color='red' size='4'><b>[initial(phrase.phrase_text)]</b></font>")
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: <font color='red' size='4'><b>[phrase_text]</b></font>")
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