From e349153c54fc1703efb6128f57745d6d4eec5600 Mon Sep 17 00:00:00 2001 From: KasparoVy Date: Fri, 14 Apr 2017 21:55:20 -0400 Subject: [PATCH] OOPs. Trims unnecessary code, some small fixes Cuts down on copypasta code by implementing a param handling proc in code\modules\mob\emote.dm. --- code/modules/mob/emote.dm | 10 + code/modules/mob/living/carbon/human/emote.dm | 316 ++++-------------- code/modules/mob/living/silicon/emote.dm | 79 +---- .../mob/living/simple_animal/bot/emote.dm | 72 +--- 4 files changed, 106 insertions(+), 371 deletions(-) diff --git a/code/modules/mob/emote.dm b/code/modules/mob/emote.dm index be6fa4a6c39..f2f1d7c626b 100644 --- a/code/modules/mob/emote.dm +++ b/code/modules/mob/emote.dm @@ -13,6 +13,16 @@ return 0 // Proceed with emote //--FalseIncarnate +/mob/proc/handle_emote_param(var/target, var/not_self, var/vicinity, var/return_mob) //Only returns not null if the target param is valid. + var/view_vicinity = vicinity ? vicinity : null //not_self means we'll only return if target is valid and not us + if(target) //vicinity is the distance passed to the view proc. + for(var/mob/A in view(view_vicinity, null)) //if set, return_mob will cause this proc to return the mob instead of just its name if the target is valid. + if(target == A.name && (!not_self || (not_self && target != name))) + if(return_mob) + return A + else + return target + // All mobs should have custom emote, really.. /mob/proc/custom_emote(var/m_type=1,var/message = null) diff --git a/code/modules/mob/living/carbon/human/emote.dm b/code/modules/mob/living/carbon/human/emote.dm index 64c028d8037..7b325eeeb8a 100644 --- a/code/modules/mob/living/carbon/human/emote.dm +++ b/code/modules/mob/living/carbon/human/emote.dm @@ -85,144 +85,73 @@ if("me") //OKAY SO RANT TIME, THIS FUCKING HAS TO BE HERE OR A SHITLOAD OF THINGS BREAK return custom_emote(m_type, message) //DO YOU KNOW WHY SHIT BREAKS? BECAUSE SO MUCH OLDCODE CALLS mob.emote("me",1,"whatever_the_fuck_it_wants_to_emote") //WHO THE FUCK THOUGHT THAT WAS A GOOD FUCKING IDEA!?!? - if("ping", "pings") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) //Check to see if the param is valid (mob with the param name is in view). - message = "[src] pings[param ? " at [param]" : ""]." + message = "[src] pings[M ? " at [M]" : ""]." playsound(loc, 'sound/machines/ping.ogg', 50, 0) m_type = 2 if("buzz2") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] emits an irritated buzzing sound[param ? " at [param]" : ""]." + message = "[src] emits an irritated buzzing sound[M ? " at [M]" : ""]." playsound(loc, 'sound/machines/buzz-two.ogg', 50, 0) m_type = 2 if("buzz", "buzzes") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] buzzes[param ? " at [param]" : ""]." + message = "[src] buzzes[M ? " at [M]" : ""]." playsound(loc, 'sound/machines/buzz-sigh.ogg', 50, 0) m_type = 2 if("beep", "beeps") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] beeps[param ? " at [param]" : ""]." + message = "[src] beeps[M ? " at [M]" : ""]." playsound(loc, 'sound/machines/twobeep.ogg', 50, 0) m_type = 2 if("drone", "drones", "hum", "hums", "rumble", "rumbles") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] [param ? "drones at [param]" : "rumbles"]." + message = "[src] [M ? "drones at [M]" : "rumbles"]." playsound(loc, 'sound/voice/DraskTalk.ogg', 50, 0) m_type = 2 if("squish", "squishes") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] squishes[param ? " at [param]" : ""]." + message = "[src] squishes[M ? " at [M]" : ""]." playsound(loc, 'sound/effects/slime_squish.ogg', 50, 0) //Credit to DrMinky (freesound.org) for the sound. m_type = 2 if("clack", "clacks") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] clacks their mandibles[param ? " at [param]" : ""]." + message = "[src] clacks their mandibles[M ? " at [M]" : ""]." playsound(loc, 'sound/effects/Kidanclack.ogg', 50, 0) //Credit to DrMinky (freesound.org) for the sound. m_type = 2 if("click", "clicks") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] clicks their mandibles[param ? " at [param]" : ""]." + message = "[src] clicks their mandibles[M ? " at [M]" : ""]." playsound(loc, 'sound/effects/Kidanclack2.ogg', 50, 0) //Credit to DrMinky (freesound.org) for the sound. m_type = 2 if("yes") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] emits an affirmative blip[param ? " at [param]" : ""]." + message = "[src] emits an affirmative blip[M ? " at [M]" : ""]." playsound(loc, 'sound/machines/synth_yes.ogg', 50, 0) m_type = 2 if("no") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] emits a negative blip[param ? " at [param]" : ""]." + message = "[src] emits a negative blip[M ? " at [M]" : ""]." playsound(loc, 'sound/machines/synth_no.ogg', 50, 0) m_type = 2 @@ -275,30 +204,16 @@ if("bow", "bows") if(!buckled) - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] bows[param ? " to [param]" : ""]." + message = "[src] bows[M ? " to [M]" : ""]." m_type = 1 if("salute", "salutes") if(!buckled) - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] salutes[param ? " to [param]" : ""]." + message = "[src] salutes[M ? " to [M]" : ""]." m_type = 1 if("choke", "chokes") @@ -437,20 +352,15 @@ m_type = 2 if("frown", "frowns") - message = "[src] frowns." + var/M = handle_emote_param(param) + + message = "[src] frowns[M ? " at [M]" : ""]." m_type = 1 if("nod", "nods") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] nods[param ? " at [param]" : ""]." + message = "[src] nods[M ? " at [M]" : ""]." m_type = 1 if("blush", "blushes") @@ -458,16 +368,9 @@ m_type = 1 if("wave", "waves") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] waves[param ? " at [param]" : ""]." + message = "[src] waves[M ? " at [M]" : ""]." m_type = 1 if("quiver", "quivers") @@ -503,47 +406,27 @@ m_type = 2 if("glare", "glares") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] glares[param ? " at [param]" : ""]." + message = "[src] glares[M ? " at [M]" : ""]." m_type = 1 if("stare", "stares") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] stares[param ? " at [param]" : ""]." + message = "[src] stares[M ? " at [M]" : ""]." m_type = 1 if("look", "looks") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break + var/M = handle_emote_param(param) - if(!M) - param = null - - message = "[src] looks[param ? " at [param]" : ""]." + message = "[src] looks[M ? " at [M]" : ""]." m_type = 1 if("grin", "grins") - message = "[src] grins." + var/M = handle_emote_param(param) + + message = "[src] grins[M ? " at [M]" : ""]." m_type = 1 if("cry", "cries") @@ -559,24 +442,26 @@ m_type = 2 if("sigh", "sighs") + var/M = handle_emote_param(param) if(miming) - message = "[src] sighs." + message = "[src] sighs[M ? " at [M]" : ""]." m_type = 1 else if(!muzzled) - message = "[src] sighs." + message = "[src] sighs[M ? " at [M]" : ""]." m_type = 2 else - message = "[src] makes a weak noise." + message = "[src] makes a weak noise" m_type = 2 if("laugh", "laughs") + var/M = handle_emote_param(param) if(miming) - message = "[src] acts out a laugh." + message = "[src] acts out a laugh[M ? " at [M]" : ""]." m_type = 1 else if(!muzzled) - message = "[src] laughs." + message = "[src] laughs[M ? " at [M]" : ""]." m_type = 2 else message = "[src] makes a noise." @@ -589,11 +474,12 @@ m_type = 1 if("grumble", "grumbles") + var/M = handle_emote_param(param) if(miming) - message = "[src] grumbles!" + message = "[src] grumbles[M ? " at [M]" : ""]!" m_type = 1 if(!muzzled) - message = "[src] grumbles!" + message = "[src] grumbles[M ? " at [M]" : ""]!" m_type = 2 else message = "[src] makes a noise." @@ -654,16 +540,9 @@ m_type = 1 if("shake", "shakes") - var/mob/M = null - if(param) - for(var/mob/A in view(1, null)) - if(param == A.name) - M = A - break - if(M == src) - M = null + var/M = handle_emote_param(param, 1) //Check to see if the param is valid (mob with the param name is in view) but exclude ourselves. - message = "[src] shakes \his head[param ? " at [param]" : ""]." + message = "[src] shakes \his head[M ? " at [M]" : ""]." m_type = 1 if("shrug", "shrugs") @@ -681,16 +560,9 @@ m_type = 1 if("smile", "smiles") - var/mob/M = null - if(param) - for(var/mob/A in view(1, null)) - if(param == A.name) - M = A - break - if(M == src) - M = null + var/M = handle_emote_param(param, 1) - message = "[src] smiles[param ? " at [param]" : ""]." + message = "[src] smiles[M ? " at [M]" : ""]." m_type = 1 if("shiver", "shivers") @@ -754,16 +626,9 @@ m_type = 2 if("wink", "winks") - var/mob/M = null - if(param) - for(var/mob/A in view(1, null)) - if(param == A.name) - M = A - break - if(M == src) - M = null + var/M = handle_emote_param(param, 1) - message = "[src] winks[param ? " at [param]" : ""]." + message = "[src] winks[M ? " at [M]" : ""]." m_type = 1 if("yawn", "yawns") @@ -783,14 +648,7 @@ if("hug", "hugs") m_type = 1 if(!restrained()) - var/M = null - if(param) - for(var/mob/A in view(1, null)) - if(param == A.name) - M = A - break - if(M == src) - M = null + var/M = handle_emote_param(param, 1, 1) //Check to see if the param is valid (mob with the param name is in view) but exclude ourselves and only check mobs in our immediate vicinity (1 tile distance). if(M) message = "[src] hugs [M]." @@ -800,14 +658,7 @@ if("handshake") m_type = 1 if(!restrained() && !r_hand) - var/mob/M = null - if(param) - for(var/mob/A in view(1, null)) - if(param == A.name) - M = A - break - if(M == src) - M = null + var/mob/M = handle_emote_param(param, 1, 1, 1) //Check to see if the param is valid (mob with the param name is in view) but exclude ourselves, only check mobs in our immediate vicinity (1 tile distance) and return the whole mob instead of just its name. if(M) if(M.canmove && !M.r_hand && !M.restrained()) @@ -818,12 +669,8 @@ if("dap", "daps") m_type = 1 if(!restrained()) - var/M = null - if(param) - for(var/mob/A in view(1, null)) - if(param == A.name) - M = A - break + var/M = handle_emote_param(param, null, 1) + if(M) message = "[src] gives daps to [M]." else @@ -832,12 +679,8 @@ if("slap", "slaps") m_type = 1 if(!restrained()) - var/M = null - if(param) - for(var/mob/A in view(1, null)) - if(param == A.name) - M = A - break + var/M = handle_emote_param(param, null, 1) + if(M) message = "[src] slaps [M] across the face. Ouch!" else @@ -846,21 +689,13 @@ playsound(loc, 'sound/effects/snap.ogg', 50, 1) if("scream", "screams") + var/M = handle_emote_param(param) if(miming) - message = "[src] acts out a scream!" + message = "[src] acts out a scream[M ? " at [M]" : ""]!" m_type = 1 else - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null - if(!muzzled) - message = "[src] [species.scream_verb][param ? " at [param]" : ""]!" + message = "[src] [species.scream_verb][M ? " at [M]" : ""]!" m_type = 2 if(gender == FEMALE) playsound(loc, "[species.female_scream_sound]", 80, 1, 0, pitch = get_age_pitch()) @@ -868,10 +703,9 @@ playsound(loc, "[species.male_scream_sound]", 80, 1, 0, pitch = get_age_pitch()) //default to male screams if no gender is present. else - message = "[src] makes a very loud noise[param ? " at [param]" : ""]." + message = "[src] makes a very loud noise[M ? " at [M]" : ""]." m_type = 2 - if("snap", "snaps") if(prob(95)) m_type = 2 @@ -889,22 +723,14 @@ to_chat(usr, "You need at least one hand in good working order to snap your fingers.") return - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] snaps \his fingers[param ? " at [param]" : ""]." + message = "[src] snaps \his fingers[M ? " at [M]" : ""]." playsound(loc, 'sound/effects/fingersnap.ogg', 50, 1, -3) else message = "[src] snaps \his fingers right off!" playsound(loc, 'sound/effects/snap.ogg', 50, 1) - // Needed for M_TOXIC_FART if("fart", "farts") if(reagents.has_reagent("simethicone")) @@ -955,11 +781,7 @@ else to_chat(src, "\blue Unusable emote '[act]'. Say *help for a list.") - - - - - if(message) //Humans are special fucking snowflakes and have 1000 lines of emotes, they get to handle their own emotes, not call the parent + if(message) //Humans are special fucking snowflakes and have 800 lines of emotes, they get to handle their own emotes, not call the parent. log_emote("[name]/[key] : [message]") //Hearing gasp and such every five seconds is not good emotes were not global for a reason. diff --git a/code/modules/mob/living/silicon/emote.dm b/code/modules/mob/living/silicon/emote.dm index 5904f0d5ffb..3385c4ce622 100644 --- a/code/modules/mob/living/silicon/emote.dm +++ b/code/modules/mob/living/silicon/emote.dm @@ -26,100 +26,51 @@ switch(act) if("ping","pings") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] pings[param ? " at [param]" : ""]." + message = "[src] pings[M ? " at [M]" : ""]." playsound(src.loc, 'sound/machines/ping.ogg', 50, 0) m_type = 2 if("buzz","buzzs","buzzes") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] buzzes[param ? " at [param]" : ""]." + message = "[src] buzzes[M ? " at [M]" : ""]." playsound(src.loc, 'sound/machines/buzz-sigh.ogg', 50, 0) m_type = 2 if("beep","beeps") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] beeps[param ? " at [param]" : ""]." + message = "[src] beeps[M ? " at [M]" : ""]." playsound(src.loc, 'sound/machines/twobeep.ogg', 50, 0) m_type = 2 if("yes") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] emits an affirmative blip[param ? " at [param]" : ""]." + message = "[src] emits an affirmative blip[M ? " at [M]" : ""]." playsound(src.loc, 'sound/machines/synth_yes.ogg', 50, 0) m_type = 2 if("no") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] emits a negative blip[param ? " at [param]" : ""]." + message = "[src] emits a negative blip[M ? " at [M]" : ""]." playsound(src.loc, 'sound/machines/synth_no.ogg', 50, 0) m_type = 2 if("scream", "screams") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] screams[param ? " at [param]" : ""]!" + message = "[src] screams[M ? " at [M]" : ""]!" playsound(src.loc, 'sound/goonstation/voice/robot_scream.ogg', 80, 0) m_type = 2 if("buzz2") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] emits an irritated buzzing sound[param ? " at [param]" : ""]." + message = "[src] emits an irritated buzzing sound[M ? " at [M]" : ""]." playsound(src.loc, 'sound/machines/buzz-two.ogg', 50, 0) m_type = 2 @@ -127,4 +78,4 @@ if("help") to_chat(src, "yes, no, beep, ping, buzz, scream, buzz2") - ..(act, m_type, message) \ No newline at end of file + ..(act, m_type, message) diff --git a/code/modules/mob/living/simple_animal/bot/emote.dm b/code/modules/mob/living/simple_animal/bot/emote.dm index 8cf07664738..70e27937745 100644 --- a/code/modules/mob/living/simple_animal/bot/emote.dm +++ b/code/modules/mob/living/simple_animal/bot/emote.dm @@ -28,92 +28,44 @@ switch(act) if("ping") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] pings[param ? " at [param]" : ""]." + message = "[src] pings[M ? " at [M]" : ""]." playsound(src.loc, 'sound/machines/ping.ogg', 50, 0) m_type = 2 if("buzz") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - if(param) - message = "[src] buzzes at [param]." - else - message = "[src] buzzes." + message = "[src] buzzes[M ? " at [M]" : ""]." playsound(src.loc, 'sound/machines/buzz-sigh.ogg', 50, 0) m_type = 2 if("beep") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - if(param) - message = "[src] beeps at [param]." - else - message = "[src] beeps." + message = "[src] beeps[M ? " at [M]" : ""]." playsound(src.loc, 'sound/machines/twobeep.ogg', 50, 0) m_type = 2 if("yes") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] emits an affirmative blip[param ? " at [param]" : ""]." + message = "[src] emits an affirmative blip[M ? " at [M]" : ""]." playsound(src.loc, 'sound/machines/synth_yes.ogg', 50, 0) m_type = 2 if("no") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] emits an negative blip[param ? " at [param]" : ""]." + message = "[src] emits an negative blip[M ? " at [M]" : ""]." playsound(src.loc, 'sound/machines/synth_no.ogg', 50, 0) m_type = 2 if("scream", "screams") - var/M = null - if(param) - for(var/mob/A in view(null, null)) - if(param == A.name) - M = A - break - if(!M) - param = null + var/M = handle_emote_param(param) - message = "[src] screams[param ? " at [param]" : ""]!" + message = "[src] screams[M ? " at [M]" : ""]!" playsound(src.loc, 'sound/goonstation/voice/robot_scream.ogg', 80, 0) m_type = 2