From 6ebdfdc73f233d94bcc6c4a2f72d902af868583f Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sun, 19 Feb 2023 01:58:30 +0100 Subject: [PATCH] [MIRROR] Makes Shake() proc work [MDB IGNORE] (#19424) * Makes Shake() proc work (#73480) ## About The Pull Request Fixes #72321 Fixes #70388 The shake proc didn't work and hasn't for ages. I remember it having worked at some point, but it was quite a long time ago. I cannot guarantee that the end result here is the same as it was, the reason here being that I have no idea how this proc ever worked in the first place. My limited understanding of the `animate` proc implies that the previous implementation as written would never have acted as you would expect it to, but clearly at some time in the past it did work. A mystery. As a result of the previous, possibly because the proc never _did_ work as expected and just did something which looked vaguely correct most of the time, both the default values and the values people were passing into this proc were completely ridiculous. Why would anyone ever want to pixel shift an object with a range of _15_ pixels in all directions? That's half a full tile! And why would you want it to do this for 25 seconds? So I also changed the values being passed in, because you really want pretty small numbers passed into here most of the time. Here's a video of everything that vibrates: https://www.youtube.com/watch?v=Q0hoqmaXkKA The exception is the v8 engine. I left this alone because it seems to try and start shaking while in your hands, which doesn't work, and I don't know how to fix that. This has potentially _also_ never worked. ## Why It's Good For The Game Now you can see intended visual indicators for: - Lobstrosities charging. - Beepsky being EMPed. - The Savannah Ivanov preparing to jump. - The DNA infuser putting someone through the spin cycle. - The mystery box admin item I had no previous idea even existed (fun animations on this one). - Anything else which wants to use this proc to create vibrating objects in the future. ## Changelog :cl: fix: Lobstrosities and Tarantulas will once more vibrate to let you know they're about to charge at you. fix: The Savannah Ivanov will once more vibrate to let you know it's about to jump into the air. fix: The DNA infuser will now vibrate to let people know that it's busy blending someone with a dead animal. /:cl: * Makes Shake() proc work --------- Co-authored-by: Jacquerel --- code/__HELPERS/icons.dm | 13 ++++++------- code/datums/actions/mobs/charge.dm | 4 +++- code/game/machinery/dna_infuser/dna_infuser.dm | 2 +- code/game/objects/items/v8_engine.dm | 2 +- code/game/objects/structures/mystery_box.dm | 2 +- code/modules/mob/living/basic/basic_defense.dm | 2 +- .../mob/living/simple_animal/animal_defense.dm | 2 +- .../vehicles/mecha/combat/savannah_ivanov.dm | 6 +++--- 8 files changed, 17 insertions(+), 16 deletions(-) diff --git a/code/__HELPERS/icons.dm b/code/__HELPERS/icons.dm index 12376f06cc5..fd9de80a374 100644 --- a/code/__HELPERS/icons.dm +++ b/code/__HELPERS/icons.dm @@ -1402,15 +1402,14 @@ GLOBAL_LIST_EMPTY(transformation_animation_objects) sleep(duration) cut_overlay(overlay_image) -///Perform a shake on an atom, resets its position afterwards -/atom/proc/Shake(pixelshiftx = 15, pixelshifty = 15, duration = 250) +/// Perform a shake on an atom, resets its position afterwards +/atom/proc/Shake(pixelshiftx = 2, pixelshifty = 2, duration = 2.5 SECONDS, shake_interval = 0.02 SECONDS) var/initialpixelx = pixel_x var/initialpixely = pixel_y - var/shiftx = rand(-pixelshiftx,pixelshiftx) - var/shifty = rand(-pixelshifty,pixelshifty) - animate(src, pixel_x = pixel_x + shiftx, pixel_y = pixel_y + shifty, time = 0.2, loop = duration) - pixel_x = initialpixelx - pixel_y = initialpixely + animate(src, pixel_x = initialpixelx + rand(-pixelshiftx,pixelshiftx), pixel_y = initialpixelx + rand(-pixelshifty,pixelshifty), time = shake_interval, flags = ANIMATION_PARALLEL) + for (var/i in 3 to ((duration / shake_interval))) // Start at 3 because we already applied one, and need another to reset + animate(pixel_x = initialpixelx + rand(-pixelshiftx,pixelshiftx), pixel_y = initialpixely + rand(-pixelshifty,pixelshifty), time = shake_interval) + animate(pixel_x = initialpixelx, pixel_y = initialpixely, time = shake_interval) ///Checks if the given iconstate exists in the given file, caching the result. Setting scream to TRUE will print a stack trace ONCE. /proc/icon_exists(file, state, scream) diff --git a/code/datums/actions/mobs/charge.dm b/code/datums/actions/mobs/charge.dm index 17d5c3600a5..71e145a6720 100644 --- a/code/datums/actions/mobs/charge.dm +++ b/code/datums/actions/mobs/charge.dm @@ -173,8 +173,10 @@ cooldown_time = 6 SECONDS charge_delay = 1.5 SECONDS charge_distance = 4 + /// How long to shake for before charging var/shake_duration = 1 SECONDS - var/shake_pixel_shift = 15 + /// Intensity of shaking animation + var/shake_pixel_shift = 2 /datum/action/cooldown/mob_cooldown/charge/basic_charge/do_charge_indicator(atom/charger, atom/charge_target) charger.Shake(shake_pixel_shift, shake_pixel_shift, shake_duration) diff --git a/code/game/machinery/dna_infuser/dna_infuser.dm b/code/game/machinery/dna_infuser/dna_infuser.dm index bb279178f05..24596e4ea6f 100644 --- a/code/game/machinery/dna_infuser/dna_infuser.dm +++ b/code/game/machinery/dna_infuser/dna_infuser.dm @@ -77,7 +77,7 @@ to_chat(human_occupant, span_danger("Little needles repeatedly prick you!")) human_occupant.take_overall_damage(10) human_occupant.add_mob_memory(/datum/memory/dna_infusion, protagonist = human_occupant, deuteragonist = infusing_from, mutantlike = infusing_into.infusion_desc) - Shake(15, 15, INFUSING_TIME) + Shake(duration = INFUSING_TIME) addtimer(CALLBACK(human_occupant, TYPE_PROC_REF(/mob, emote), "scream"), INFUSING_TIME - 1 SECONDS) addtimer(CALLBACK(src, PROC_REF(end_infuse)), INFUSING_TIME) update_appearance() diff --git a/code/game/objects/items/v8_engine.dm b/code/game/objects/items/v8_engine.dm index 86363e40b21..e143aed2401 100644 --- a/code/game/objects/items/v8_engine.dm +++ b/code/game/objects/items/v8_engine.dm @@ -24,7 +24,7 @@ if (!COOLDOWN_FINISHED(src, engine_sound_cooldown)) return playsound(src, 'sound/items/car_engine_start.ogg', vol = 75, vary = FALSE, extrarange = 3) - Shake(7, 7, ENGINE_COOLDOWN) + Shake(duration = ENGINE_COOLDOWN) to_chat(user, span_notice("Darn thing... it's too old to keep on without retrofitting it! Without modifications, it works like it's junk.")) COOLDOWN_START(src, engine_sound_cooldown, ENGINE_COOLDOWN) diff --git a/code/game/objects/structures/mystery_box.dm b/code/game/objects/structures/mystery_box.dm index f3f8f4f1dc9..817b0f4ba45 100644 --- a/code/game/objects/structures/mystery_box.dm +++ b/code/game/objects/structures/mystery_box.dm @@ -174,7 +174,7 @@ GLOBAL_LIST_INIT(mystery_box_extended, list( SSsounds.free_sound_channel(current_sound_channel) current_sound_channel = null box_state = MYSTERY_BOX_STANDBY - Shake(10, 0, 0.5 SECONDS) + Shake(3, 0, 0.5 SECONDS) /// Someone attacked the box with an empty hand, spawn the shown prize and give it to them, then close the box /obj/structure/mystery_box/proc/grant_weapon(mob/living/user) diff --git a/code/modules/mob/living/basic/basic_defense.dm b/code/modules/mob/living/basic/basic_defense.dm index d22ae01c2d4..7d00dbda288 100644 --- a/code/modules/mob/living/basic/basic_defense.dm +++ b/code/modules/mob/living/basic/basic_defense.dm @@ -194,7 +194,7 @@ if(EMP_LIGHT) visible_message(span_danger("[src] shakes violently, its parts coming loose!")) apply_damage(maxHealth * 0.6) - Shake(5, 5, 1 SECONDS) + Shake(duration = 1 SECONDS) if(EMP_HEAVY) visible_message(span_danger("[src] suddenly bursts apart!")) apply_damage(maxHealth) diff --git a/code/modules/mob/living/simple_animal/animal_defense.dm b/code/modules/mob/living/simple_animal/animal_defense.dm index c51b2c644b9..4f2cd0f19ee 100644 --- a/code/modules/mob/living/simple_animal/animal_defense.dm +++ b/code/modules/mob/living/simple_animal/animal_defense.dm @@ -191,7 +191,7 @@ if (EMP_LIGHT) visible_message(span_danger("[src] shakes violently, its parts coming loose!")) apply_damage(maxHealth * 0.6) - Shake(5, 5, 1 SECONDS) + Shake(duration = 1 SECONDS) if (EMP_HEAVY) visible_message(span_danger("[src] suddenly bursts apart!")) apply_damage(maxHealth) diff --git a/code/modules/vehicles/mecha/combat/savannah_ivanov.dm b/code/modules/vehicles/mecha/combat/savannah_ivanov.dm index a571b2fb261..1ffc40fc10b 100644 --- a/code/modules/vehicles/mecha/combat/savannah_ivanov.dm +++ b/code/modules/vehicles/mecha/combat/savannah_ivanov.dm @@ -111,16 +111,16 @@ playsound(chassis, 'sound/items/rped.ogg', 50, TRUE) if(2) chassis.visible_message(span_warning("[chassis] begins to shake, the sounds of electricity growing louder.")) - chassis.Shake(5, 5, SKYFALL_SINGLE_CHARGE_TIME-1) // -1 gives space between the animates, so they don't interrupt eachother + chassis.Shake(1, 1, SKYFALL_SINGLE_CHARGE_TIME-1) // -1 gives space between the animates, so they don't interrupt eachother if(3) chassis.visible_message(span_warning("[chassis] assumes a pose as it rattles violently.")) - chassis.Shake(7, 7, SKYFALL_SINGLE_CHARGE_TIME-1) // -1 gives space between the animates, so they don't interrupt eachother + chassis.Shake(2, 2, SKYFALL_SINGLE_CHARGE_TIME-1) // -1 gives space between the animates, so they don't interrupt eachother chassis.spark_system.start() chassis.update_appearance(UPDATE_ICON_STATE) if(4) chassis.visible_message(span_warning("[chassis] sparks and shutters as it finalizes preparation.")) playsound(chassis, 'sound/mecha/skyfall_power_up.ogg', 50, TRUE) - chassis.Shake(10, 10, SKYFALL_SINGLE_CHARGE_TIME-1) // -1 gives space between the animates, so they don't interrupt eachother + chassis.Shake(3, 3, SKYFALL_SINGLE_CHARGE_TIME-1) // -1 gives space between the animates, so they don't interrupt eachother chassis.spark_system.start() if(SKYFALL_CHARGELEVEL_LAUNCH) chassis.visible_message(span_danger("[chassis] leaps into the air!"))