From 937f6356abc50ef3f3a467b3a022b17e1430d184 Mon Sep 17 00:00:00 2001 From: ancientpower Date: Sat, 1 Feb 2020 22:13:40 -0600 Subject: [PATCH 1/9] vgstation drink sliding --- code/__DEFINES/maths.dm | 4 +- code/__HELPERS/vector.dm | 57 ++++++++++++++ code/datums/action.dm | 8 ++ code/modules/food_and_drinks/drinks/drinks.dm | 74 +++++++++++++++++-- .../food_and_drinks/drinks/drinks/bottle.dm | 36 +-------- code/modules/jobs/job_types/bartender.dm | 4 + code/modules/reagents/reagent_containers.dm | 15 ---- tgstation.dme | 1 + 8 files changed, 140 insertions(+), 59 deletions(-) create mode 100644 code/__HELPERS/vector.dm diff --git a/code/__DEFINES/maths.dm b/code/__DEFINES/maths.dm index ad93dd2d54..939f6698cb 100644 --- a/code/__DEFINES/maths.dm +++ b/code/__DEFINES/maths.dm @@ -199,4 +199,6 @@ #define LORENTZ_CUMULATIVE_DISTRIBUTION(x, y, s) ( (1/PI)*TORADIANS(arctan((x-y)/s)) + 1/2 ) #define RULE_OF_THREE(a, b, x) ((a*x)/b) -// ) \ No newline at end of file +// ) + +#define MANHATTAN_DISTANCE(a, b) (abs(a.x - b.x) + abs(a.y - b.y)) \ No newline at end of file diff --git a/code/__HELPERS/vector.dm b/code/__HELPERS/vector.dm new file mode 100644 index 0000000000..b697408a41 --- /dev/null +++ b/code/__HELPERS/vector.dm @@ -0,0 +1,57 @@ +// Basic geometry things. + +/vector/ + var/x = 0 + var/y = 0 + +/vector/New(var/x, var/y) + src.x = x + src.y = y + +/vector/proc/duplicate() + return new /vector(x, y) + +/vector/proc/euclidian_norm() + return sqrt(x*x + y*y) + +/vector/proc/squared_norm() + return x*x + y*y + +/vector/proc/normalize() + var/norm = euclidian_norm() + x = x/norm + y = y/norm + return src + +/vector/proc/chebyshev_norm() + return max(abs(x), abs(y)) + +/vector/proc/chebyshev_normalize() + var/norm = chebyshev_norm() + x = x/norm + y = y/norm + return src + +/vector/proc/is_integer() + return ISINTEGER(x) && ISINTEGER(y) + +/atom/movable/proc/vector_translate(var/vector/V, var/delay) + var/turf/T = get_turf(src) + var/turf/destination = locate(T.x + V.x, T.y + V.y, z) + var/vector/V_norm = V.duplicate() + V_norm.chebyshev_normalize() + if (!V_norm.is_integer()) + return + var/turf/destination_temp + while (destination_temp != destination) + destination_temp = locate(T.x + V_norm.x, T.y + V_norm.y, z) + forceMove(destination_temp) + T = get_turf(src) + sleep(delay + world.tick_lag) // Shortest possible time to sleep + +/atom/proc/get_translated_turf(var/vector/V) + var/turf/T = get_turf(src) + return locate(T.x + V.x, T.y + V.y, z) + +/proc/atoms2vector(var/atom/A, var/atom/B) + return new /vector((B.x - A.x), (B.y - A.y)) // Vector from A -> B \ No newline at end of file diff --git a/code/datums/action.dm b/code/datums/action.dm index 8659a9e7c4..4ed3a1d904 100644 --- a/code/datums/action.dm +++ b/code/datums/action.dm @@ -756,3 +756,11 @@ target.layer = old_layer target.plane = old_plane current_button.appearance_cache = target.appearance + +/proc/get_action_of_type(mob/M, var/action_type) + if(!M.actions || !ispath(action_type, /datum/action)) + return + for(var/datum/action/A in M.actions) + if(istype(A, action_type)) + return A + return \ No newline at end of file diff --git a/code/modules/food_and_drinks/drinks/drinks.dm b/code/modules/food_and_drinks/drinks/drinks.dm index cd5c9d850b..c48a545997 100644 --- a/code/modules/food_and_drinks/drinks/drinks.dm +++ b/code/modules/food_and_drinks/drinks/drinks.dm @@ -107,11 +107,9 @@ smash(hit_atom, throwingdatum?.thrower, TRUE) /obj/item/reagent_containers/food/drinks/proc/smash(atom/target, mob/thrower, ranged = FALSE) - if(!isGlass) + if(!isGlass && !istype(src, /obj/item/reagent_containers/food/drinks/bottle)) //I don't like this but I also don't want to rework drink container hierarchy return - if(QDELING(src) || !target) //Invalid loc - return - if(bartender_check(target) && ranged) + if(QDELING(src) || (ranged && !target)) return var/obj/item/broken_bottle/B = new (loc) B.icon_state = icon_state @@ -126,12 +124,74 @@ B.transform = M B.pixel_x = rand(-12, 12) B.pixel_y = rand(-12, 12) - if(prob(33)) - new/obj/item/shard(drop_location()) + if(isGlass) + if(prob(33)) + new/obj/item/shard(drop_location()) + else + B.force = 0 + B.throwforce = 0 + B.desc = "A carton with the bottom half burst open. Might give you a papercut." playsound(src, "shatter", 70, 1) transfer_fingerprints_to(B) qdel(src) +/obj/item/reagent_containers/food/drinks/MouseDrop(atom/over, atom/src_location, atom/over_location, src_control, over_control, params) + var/mob/user = usr + if (!istype(src_location)) + return + if (!user || user.incapacitated()) + return + // Attempted drink sliding + if (locate(/obj/structure/table) in src_location) + //Are we an expert slider? + var/datum/action/innate/A = get_action_of_type(user, /datum/action/innate/drink_fling) + if(A?.active) + if (!user.Adjacent(src)) + return + var/distance = MANHATTAN_DISTANCE(over_location, src) + if (distance >= 8 || distance == 0) // More than a full screen to go, or trying to slide to the same tile + return ..() + + // Geometrically checking if we're on a straight line. + var/vector/V = atoms2vector(src, over_location) + var/vector/V_norm = V.duplicate() + V_norm.normalize() + if (!V_norm.is_integer()) + return ..() // Only a cardinal vector (north, south, east, west) can pass this test + + // Checks if there's tables on the path. + var/turf/dest = get_translated_turf(V) + var/turf/temp_turf = src_location + + do + temp_turf = temp_turf.get_translated_turf(V_norm) + if (!locate(/obj/structure/table) in temp_turf) + var/vector/V2 = atoms2vector(src, temp_turf) + vector_translate(V2, 0.1 SECONDS) + user.visible_message("\The [user] slides \the [src] down the table... and straight into the ground!", "You slide \the [src] down the table, and straight into the ground!") + smash(over_location, user, FALSE) + return + while (temp_turf != dest) + + vector_translate(V, 0.1 SECONDS) + user.visible_message("\The [user] expertly slides \the [src] down the table.", "You slide \the [src] down the table. What a pro.") + return + else + if (!(locate(/obj/structure/table) in over_location)) + return ..() + if (!user.Adjacent(src) || !src_location.Adjacent(over_location)) // Regular users can only do short slides. + return ..() + if (prob(10)) + user.visible_message("\The [user] tries to slide \the [src] down the table, but fails miserably.", "You fail to slide \the [src] down the table!") + smash(over_location, user, FALSE) + return + user.visible_message("\The [user] slides \the [src] down the table.", "You slide \the [src] down the table!") + forceMove(over_location) + return + return ..() + + + //////////////////////////////////////////////////////////////////////////////// /// Drinks. END //////////////////////////////////////////////////////////////////////////////// @@ -290,8 +350,6 @@ volume = 15 //I figure if you have to craft these it should at least be slightly better than something you can get for free from a watercooler /obj/item/reagent_containers/food/drinks/sillycup/smallcarton/smash(atom/target, mob/thrower, ranged = FALSE) - if(bartender_check(target) && ranged) - return var/obj/item/broken_bottle/B = new (loc) B.icon_state = icon_state var/icon/I = new('icons/obj/drinks.dmi', src.icon_state) diff --git a/code/modules/food_and_drinks/drinks/drinks/bottle.dm b/code/modules/food_and_drinks/drinks/drinks/bottle.dm index 7f2b24ca11..07026e79de 100644 --- a/code/modules/food_and_drinks/drinks/drinks/bottle.dm +++ b/code/modules/food_and_drinks/drinks/drinks/bottle.dm @@ -16,40 +16,6 @@ isGlass = TRUE foodtype = ALCOHOL - -/obj/item/reagent_containers/food/drinks/bottle/smash(mob/living/target, mob/thrower, ranged = FALSE) - //Creates a shattering noise and replaces the bottle with a broken_bottle - if(bartender_check(target) && ranged) - return - var/obj/item/broken_bottle/B = new (loc) - if(!ranged) - thrower.put_in_hands(B) - else - var/matrix/M = matrix(B.transform) - M.Turn(rand(-170, 170)) - B.transform = M - B.pixel_x = rand(-12, 12) - B.pixel_y = rand(-12, 12) - B.icon_state = icon_state - - var/icon/I = new('icons/obj/drinks.dmi', src.icon_state) - I.Blend(B.broken_outline, ICON_OVERLAY, rand(5), 1) - I.SwapColor(rgb(255, 0, 220, 255), rgb(0, 0, 0, 0)) - B.icon = I - - if(isGlass) - if(prob(33)) - new/obj/item/shard(drop_location()) - playsound(src, "shatter", 70, 1) - else - B.force = 0 - B.throwforce = 0 - B.desc = "A carton with the bottom half burst open. Might give you a papercut." - B.name = "broken [name]" - transfer_fingerprints_to(B) - - qdel(src) - /obj/item/reagent_containers/food/drinks/bottle/attack(mob/living/target, mob/living/user) if(!target) @@ -109,7 +75,7 @@ //Keeping this here for now, I'll ask if I should keep it here. /obj/item/broken_bottle name = "broken bottle" - desc = "A bottle with a sharp broken bottom." + desc = "A shattered glass container with sharp edges." icon = 'icons/obj/drinks.dmi' icon_state = "broken_bottle" force = 9 diff --git a/code/modules/jobs/job_types/bartender.dm b/code/modules/jobs/job_types/bartender.dm index 0ace449757..cffeceea9c 100644 --- a/code/modules/jobs/job_types/bartender.dm +++ b/code/modules/jobs/job_types/bartender.dm @@ -28,3 +28,7 @@ backpack_contents = list(/obj/item/storage/box/beanbag=1,/obj/item/book/granter/action/drink_fling=1) shoes = /obj/item/clothing/shoes/laceup +/datum/job/bartender/after_spawn(mob/living/H, mob/M, latejoin = FALSE) + . = ..() + var/datum/action/innate/drink_fling/D = new + D.Grant(H) diff --git a/code/modules/reagents/reagent_containers.dm b/code/modules/reagents/reagent_containers.dm index 23176f8a05..35b3a84e2f 100644 --- a/code/modules/reagents/reagent_containers.dm +++ b/code/modules/reagents/reagent_containers.dm @@ -102,15 +102,6 @@ . = ..() SplashReagents(hit_atom, TRUE) -/obj/item/reagent_containers/proc/bartender_check(atom/target) - . = FALSE - var/turf/T = get_turf(src) - if(!T || target.CanPass(src, T) || !thrownby || !thrownby.actions) - return - for(var/datum/action/innate/drink_fling/D in thrownby.actions) - if(D.active) - return TRUE - /obj/item/reagent_containers/proc/ForceResetRotation() transform = initial(transform) @@ -132,12 +123,6 @@ log_combat(thrownby, M, "splashed", R) reagents.reaction(target, TOUCH) - else if(bartender_check(target) && thrown) - visible_message("[src] lands onto the [target.name] without spilling a single drop.") - transform = initial(transform) - addtimer(CALLBACK(src, .proc/ForceResetRotation), 1) - return - else if(isturf(target) && reagents.reagent_list.len && thrownby) log_combat(thrownby, target, "splashed (thrown) [english_list(reagents.reagent_list)]", "in [AREACOORD(target)]") diff --git a/tgstation.dme b/tgstation.dme index ee457b102e..5832b2b4d6 100755 --- a/tgstation.dme +++ b/tgstation.dme @@ -152,6 +152,7 @@ #include "code\__HELPERS\type2type_vr.dm" #include "code\__HELPERS\typelists.dm" #include "code\__HELPERS\unsorted.dm" +#include "code\__HELPERS\vector.dm" #include "code\__HELPERS\view.dm" #include "code\__HELPERS\sorts\__main.dm" #include "code\__HELPERS\sorts\InsertSort.dm" From 524836c2b2ffc226446f4f47b69ad5c2d390a310 Mon Sep 17 00:00:00 2001 From: ancientpower Date: Tue, 4 Feb 2020 15:48:03 -0600 Subject: [PATCH 2/9] restores drink flinging --- code/datums/action.dm | 10 +++++++++- code/modules/food_and_drinks/drinks/drinks.dm | 2 ++ code/modules/reagents/reagent_containers.dm | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/code/datums/action.dm b/code/datums/action.dm index 4ed3a1d904..a193a89516 100644 --- a/code/datums/action.dm +++ b/code/datums/action.dm @@ -763,4 +763,12 @@ for(var/datum/action/A in M.actions) if(istype(A, action_type)) return A - return \ No newline at end of file + return + +/proc/find_active_innate_action(mob/M, var/action_type) + var/datum/action/innate/A = get_action_of_type(M, action_type) + if(!istype(A)) + return FALSE + if(A.active) + return TRUE + return FALSE \ No newline at end of file diff --git a/code/modules/food_and_drinks/drinks/drinks.dm b/code/modules/food_and_drinks/drinks/drinks.dm index c48a545997..3cbaa01b65 100644 --- a/code/modules/food_and_drinks/drinks/drinks.dm +++ b/code/modules/food_and_drinks/drinks/drinks.dm @@ -111,6 +111,8 @@ return if(QDELING(src) || (ranged && !target)) return + if(ranged && bartender_check(target)) + return var/obj/item/broken_bottle/B = new (loc) B.icon_state = icon_state var/icon/I = new('icons/obj/drinks.dmi', src.icon_state) diff --git a/code/modules/reagents/reagent_containers.dm b/code/modules/reagents/reagent_containers.dm index 35b3a84e2f..0687bd2d95 100644 --- a/code/modules/reagents/reagent_containers.dm +++ b/code/modules/reagents/reagent_containers.dm @@ -102,6 +102,14 @@ . = ..() SplashReagents(hit_atom, TRUE) +/obj/item/reagent_containers/proc/bartender_check(atom/target) + . = FALSE + var/turf/T = get_turf(src) + if(!T || target.CanPass(src, T) || !thrownby || !thrownby.actions) + return + if(find_active_innate_action(thrownby, /datum/action/innate/drink_fling)) + return TRUE + /obj/item/reagent_containers/proc/ForceResetRotation() transform = initial(transform) @@ -123,6 +131,13 @@ log_combat(thrownby, M, "splashed", R) reagents.reaction(target, TOUCH) + else if(bartender_check(target) && thrown) + visible_message("[src] lands onto the [target.name] without spilling a single drop.") + transform = initial(transform) + addtimer(CALLBACK(src, .proc/ForceResetRotation), 1) + return + + else if(isturf(target) && reagents.reagent_list.len && thrownby) log_combat(thrownby, target, "splashed (thrown) [english_list(reagents.reagent_list)]", "in [AREACOORD(target)]") From 9dd411f11be55b9fe648cb2262025f742afef326 Mon Sep 17 00:00:00 2001 From: ancientpower Date: Tue, 4 Feb 2020 16:02:15 -0600 Subject: [PATCH 3/9] fixes the restoration for reals --- code/datums/action.dm | 10 +--------- code/modules/food_and_drinks/drinks/drinks.dm | 4 ++-- code/modules/reagents/reagent_containers.dm | 7 ++++--- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/code/datums/action.dm b/code/datums/action.dm index a193a89516..4ed3a1d904 100644 --- a/code/datums/action.dm +++ b/code/datums/action.dm @@ -763,12 +763,4 @@ for(var/datum/action/A in M.actions) if(istype(A, action_type)) return A - return - -/proc/find_active_innate_action(mob/M, var/action_type) - var/datum/action/innate/A = get_action_of_type(M, action_type) - if(!istype(A)) - return FALSE - if(A.active) - return TRUE - return FALSE \ No newline at end of file + return \ No newline at end of file diff --git a/code/modules/food_and_drinks/drinks/drinks.dm b/code/modules/food_and_drinks/drinks/drinks.dm index 3cbaa01b65..ce1fec334e 100644 --- a/code/modules/food_and_drinks/drinks/drinks.dm +++ b/code/modules/food_and_drinks/drinks/drinks.dm @@ -111,7 +111,7 @@ return if(QDELING(src) || (ranged && !target)) return - if(ranged && bartender_check(target)) + if(bartender_check(target) && ranged) return var/obj/item/broken_bottle/B = new (loc) B.icon_state = icon_state @@ -127,13 +127,13 @@ B.pixel_x = rand(-12, 12) B.pixel_y = rand(-12, 12) if(isGlass) + playsound(src, "shatter", 70, 1) if(prob(33)) new/obj/item/shard(drop_location()) else B.force = 0 B.throwforce = 0 B.desc = "A carton with the bottom half burst open. Might give you a papercut." - playsound(src, "shatter", 70, 1) transfer_fingerprints_to(B) qdel(src) diff --git a/code/modules/reagents/reagent_containers.dm b/code/modules/reagents/reagent_containers.dm index 0687bd2d95..121999cfae 100644 --- a/code/modules/reagents/reagent_containers.dm +++ b/code/modules/reagents/reagent_containers.dm @@ -107,8 +107,9 @@ var/turf/T = get_turf(src) if(!T || target.CanPass(src, T) || !thrownby || !thrownby.actions) return - if(find_active_innate_action(thrownby, /datum/action/innate/drink_fling)) - return TRUE + for(var/datum/action/innate/drink_fling/D in thrownby.actions) + if(D.active) + return TRUE /obj/item/reagent_containers/proc/ForceResetRotation() transform = initial(transform) @@ -130,7 +131,7 @@ if(thrownby) log_combat(thrownby, M, "splashed", R) reagents.reaction(target, TOUCH) - + else if(bartender_check(target) && thrown) visible_message("[src] lands onto the [target.name] without spilling a single drop.") transform = initial(transform) From 63421161681e069b1d099e4afd35bb9affa70703 Mon Sep 17 00:00:00 2001 From: ancientpower Date: Tue, 4 Feb 2020 16:13:28 -0600 Subject: [PATCH 4/9] forgot to remove this bit --- code/modules/food_and_drinks/drinks/drinks.dm | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/code/modules/food_and_drinks/drinks/drinks.dm b/code/modules/food_and_drinks/drinks/drinks.dm index ce1fec334e..6f6683c041 100644 --- a/code/modules/food_and_drinks/drinks/drinks.dm +++ b/code/modules/food_and_drinks/drinks/drinks.dm @@ -351,26 +351,6 @@ icon_state = "juicebox" volume = 15 //I figure if you have to craft these it should at least be slightly better than something you can get for free from a watercooler -/obj/item/reagent_containers/food/drinks/sillycup/smallcarton/smash(atom/target, mob/thrower, ranged = FALSE) - var/obj/item/broken_bottle/B = new (loc) - B.icon_state = icon_state - var/icon/I = new('icons/obj/drinks.dmi', src.icon_state) - I.Blend(B.broken_outline, ICON_OVERLAY, rand(5), 1) - I.SwapColor(rgb(255, 0, 220, 255), rgb(0, 0, 0, 0)) - B.icon = I - B.name = "broken [name]" - B.force = 0 - B.throwforce = 0 - B.desc = "A carton with the bottom half burst open. Might give you a papercut." - if(ranged) - var/matrix/M = matrix(B.transform) - M.Turn(rand(-170, 170)) - B.transform = M - B.pixel_x = rand(-12, 12) - B.pixel_y = rand(-12, 12) - transfer_fingerprints_to(B) - qdel(src) - /obj/item/reagent_containers/food/drinks/sillycup/smallcarton/on_reagent_change(changetype) if (reagents.reagent_list.len) switch(reagents.get_master_reagent_id()) From 0d6ffbc4327d4adfb793826d568fd01d16d2fca6 Mon Sep 17 00:00:00 2001 From: ancientpower Date: Tue, 4 Feb 2020 16:38:20 -0600 Subject: [PATCH 5/9] fixed it for real this time --- code/datums/action.dm | 8 -- code/modules/food_and_drinks/drinks/drinks.dm | 80 +++++++++---------- code/modules/reagents/reagent_containers.dm | 2 +- 3 files changed, 41 insertions(+), 49 deletions(-) diff --git a/code/datums/action.dm b/code/datums/action.dm index 4ed3a1d904..8659a9e7c4 100644 --- a/code/datums/action.dm +++ b/code/datums/action.dm @@ -756,11 +756,3 @@ target.layer = old_layer target.plane = old_plane current_button.appearance_cache = target.appearance - -/proc/get_action_of_type(mob/M, var/action_type) - if(!M.actions || !ispath(action_type, /datum/action)) - return - for(var/datum/action/A in M.actions) - if(istype(A, action_type)) - return A - return \ No newline at end of file diff --git a/code/modules/food_and_drinks/drinks/drinks.dm b/code/modules/food_and_drinks/drinks/drinks.dm index 6f6683c041..fd0fd8a718 100644 --- a/code/modules/food_and_drinks/drinks/drinks.dm +++ b/code/modules/food_and_drinks/drinks/drinks.dm @@ -146,50 +146,50 @@ // Attempted drink sliding if (locate(/obj/structure/table) in src_location) //Are we an expert slider? - var/datum/action/innate/A = get_action_of_type(user, /datum/action/innate/drink_fling) - if(A?.active) - if (!user.Adjacent(src)) + for(var/datum/action/innate/drink_fling/D in user.actions) + if(D.active) + if (!user.Adjacent(src)) + return + var/distance = MANHATTAN_DISTANCE(over_location, src) + if (distance >= 8 || distance == 0) // More than a full screen to go, or trying to slide to the same tile + return ..() + + // Geometrically checking if we're on a straight line. + var/vector/V = atoms2vector(src, over_location) + var/vector/V_norm = V.duplicate() + V_norm.normalize() + if (!V_norm.is_integer()) + return ..() // Only a cardinal vector (north, south, east, west) can pass this test + + // Checks if there's tables on the path. + var/turf/dest = get_translated_turf(V) + var/turf/temp_turf = src_location + + do + temp_turf = temp_turf.get_translated_turf(V_norm) + if (!locate(/obj/structure/table) in temp_turf) + var/vector/V2 = atoms2vector(src, temp_turf) + vector_translate(V2, 0.1 SECONDS) + user.visible_message("\The [user] slides \the [src] down the table... and straight into the ground!", "You slide \the [src] down the table, and straight into the ground!") + smash(over_location, user, FALSE) + return + while (temp_turf != dest) + + vector_translate(V, 0.1 SECONDS) + user.visible_message("\The [user] expertly slides \the [src] down the table.", "You slide \the [src] down the table. What a pro.") return - var/distance = MANHATTAN_DISTANCE(over_location, src) - if (distance >= 8 || distance == 0) // More than a full screen to go, or trying to slide to the same tile - return ..() - - // Geometrically checking if we're on a straight line. - var/vector/V = atoms2vector(src, over_location) - var/vector/V_norm = V.duplicate() - V_norm.normalize() - if (!V_norm.is_integer()) - return ..() // Only a cardinal vector (north, south, east, west) can pass this test - - // Checks if there's tables on the path. - var/turf/dest = get_translated_turf(V) - var/turf/temp_turf = src_location - - do - temp_turf = temp_turf.get_translated_turf(V_norm) - if (!locate(/obj/structure/table) in temp_turf) - var/vector/V2 = atoms2vector(src, temp_turf) - vector_translate(V2, 0.1 SECONDS) - user.visible_message("\The [user] slides \the [src] down the table... and straight into the ground!", "You slide \the [src] down the table, and straight into the ground!") + else + if (!(locate(/obj/structure/table) in over_location)) + return ..() + if (!user.Adjacent(src) || !src_location.Adjacent(over_location)) // Regular users can only do short slides. + return ..() + if (prob(10)) + user.visible_message("\The [user] tries to slide \the [src] down the table, but fails miserably.", "You fail to slide \the [src] down the table!") smash(over_location, user, FALSE) return - while (temp_turf != dest) - - vector_translate(V, 0.1 SECONDS) - user.visible_message("\The [user] expertly slides \the [src] down the table.", "You slide \the [src] down the table. What a pro.") - return - else - if (!(locate(/obj/structure/table) in over_location)) - return ..() - if (!user.Adjacent(src) || !src_location.Adjacent(over_location)) // Regular users can only do short slides. - return ..() - if (prob(10)) - user.visible_message("\The [user] tries to slide \the [src] down the table, but fails miserably.", "You fail to slide \the [src] down the table!") - smash(over_location, user, FALSE) + user.visible_message("\The [user] slides \the [src] down the table.", "You slide \the [src] down the table!") + forceMove(over_location) return - user.visible_message("\The [user] slides \the [src] down the table.", "You slide \the [src] down the table!") - forceMove(over_location) - return return ..() diff --git a/code/modules/reagents/reagent_containers.dm b/code/modules/reagents/reagent_containers.dm index 121999cfae..b254c6298e 100644 --- a/code/modules/reagents/reagent_containers.dm +++ b/code/modules/reagents/reagent_containers.dm @@ -105,7 +105,7 @@ /obj/item/reagent_containers/proc/bartender_check(atom/target) . = FALSE var/turf/T = get_turf(src) - if(!T || target.CanPass(src, T) || !thrownby || !thrownby.actions) + if(!T || !target.CanPass(src, T) || !thrownby || !thrownby.actions) return for(var/datum/action/innate/drink_fling/D in thrownby.actions) if(D.active) From a85f05a628ba6bf91bf92f9ac49e146315d0f6ae Mon Sep 17 00:00:00 2001 From: ancientpower Date: Tue, 4 Feb 2020 16:58:24 -0600 Subject: [PATCH 6/9] requested changes --- code/__HELPERS/vector.dm | 28 +++--- code/datums/action.dm | 8 ++ code/modules/food_and_drinks/drinks/drinks.dm | 87 +++++++++---------- code/modules/reagents/reagent_containers.dm | 6 +- 4 files changed, 68 insertions(+), 61 deletions(-) diff --git a/code/__HELPERS/vector.dm b/code/__HELPERS/vector.dm index b697408a41..dff3cefead 100644 --- a/code/__HELPERS/vector.dm +++ b/code/__HELPERS/vector.dm @@ -1,44 +1,44 @@ // Basic geometry things. -/vector/ +/datum/vector/ var/x = 0 var/y = 0 -/vector/New(var/x, var/y) +/datum/vector/New(var/x, var/y) src.x = x src.y = y -/vector/proc/duplicate() - return new /vector(x, y) +/datum/vector/proc/duplicate() + return new /datum/vector(x, y) -/vector/proc/euclidian_norm() +/datum/vector/proc/euclidian_norm() return sqrt(x*x + y*y) -/vector/proc/squared_norm() +/datum/vector/proc/squared_norm() return x*x + y*y -/vector/proc/normalize() +/datum/vector/proc/normalize() var/norm = euclidian_norm() x = x/norm y = y/norm return src -/vector/proc/chebyshev_norm() +/datum/vector/proc/chebyshev_norm() return max(abs(x), abs(y)) -/vector/proc/chebyshev_normalize() +/datum/vector/proc/chebyshev_normalize() var/norm = chebyshev_norm() x = x/norm y = y/norm return src -/vector/proc/is_integer() +/datum/vector/proc/is_integer() return ISINTEGER(x) && ISINTEGER(y) -/atom/movable/proc/vector_translate(var/vector/V, var/delay) +/atom/movable/proc/datum/vector_translate(var/datum/vector/V, var/delay) var/turf/T = get_turf(src) var/turf/destination = locate(T.x + V.x, T.y + V.y, z) - var/vector/V_norm = V.duplicate() + var/datum/vector/V_norm = V.duplicate() V_norm.chebyshev_normalize() if (!V_norm.is_integer()) return @@ -49,9 +49,9 @@ T = get_turf(src) sleep(delay + world.tick_lag) // Shortest possible time to sleep -/atom/proc/get_translated_turf(var/vector/V) +/atom/proc/get_translated_turf(var/datum/vector/V) var/turf/T = get_turf(src) return locate(T.x + V.x, T.y + V.y, z) /proc/atoms2vector(var/atom/A, var/atom/B) - return new /vector((B.x - A.x), (B.y - A.y)) // Vector from A -> B \ No newline at end of file + return new /datum/vector((B.x - A.x), (B.y - A.y)) // Vector from A -> B \ No newline at end of file diff --git a/code/datums/action.dm b/code/datums/action.dm index 8659a9e7c4..66a2e4b0ec 100644 --- a/code/datums/action.dm +++ b/code/datums/action.dm @@ -756,3 +756,11 @@ target.layer = old_layer target.plane = old_plane current_button.appearance_cache = target.appearance + +/proc/get_action_of_type(mob/M, var/action_type) + if(!M.actions || !ispath(action_type, /datum/action)) + return + for(var/datum/action/A in M.actions) + if(istype(A, action_type)) + return A + return \ No newline at end of file diff --git a/code/modules/food_and_drinks/drinks/drinks.dm b/code/modules/food_and_drinks/drinks/drinks.dm index fd0fd8a718..9ac81b821e 100644 --- a/code/modules/food_and_drinks/drinks/drinks.dm +++ b/code/modules/food_and_drinks/drinks/drinks.dm @@ -139,58 +139,57 @@ /obj/item/reagent_containers/food/drinks/MouseDrop(atom/over, atom/src_location, atom/over_location, src_control, over_control, params) var/mob/user = usr + . = ..() if (!istype(src_location)) return - if (!user || user.incapacitated()) + if (!user || user.incapacitated() || !user.Adjacent(src)) return // Attempted drink sliding - if (locate(/obj/structure/table) in src_location) - //Are we an expert slider? - for(var/datum/action/innate/drink_fling/D in user.actions) - if(D.active) - if (!user.Adjacent(src)) - return - var/distance = MANHATTAN_DISTANCE(over_location, src) - if (distance >= 8 || distance == 0) // More than a full screen to go, or trying to slide to the same tile - return ..() + if (!locate(/obj/structure/table) in src_location) + return + //Are we an expert slider? + var/datum/action/innate/D = get_action_of_type(user, /datum/action/innate/drink_fling) + if(D.active) + var/distance = MANHATTAN_DISTANCE(over_location, src) + if (distance >= 8 || distance == 0) // More than a full screen to go, or trying to slide to the same tile + return - // Geometrically checking if we're on a straight line. - var/vector/V = atoms2vector(src, over_location) - var/vector/V_norm = V.duplicate() - V_norm.normalize() - if (!V_norm.is_integer()) - return ..() // Only a cardinal vector (north, south, east, west) can pass this test + // Geometrically checking if we're on a straight line. + var/datum/vector/V = atoms2vector(src, over_location) + var/datum/vector/V_norm = V.duplicate() + V_norm.normalize() + if (!V_norm.is_integer()) + return // Only a cardinal vector (north, south, east, west) can pass this test - // Checks if there's tables on the path. - var/turf/dest = get_translated_turf(V) - var/turf/temp_turf = src_location + // Checks if there's tables on the path. + var/turf/dest = get_translated_turf(V) + var/turf/temp_turf = src_location - do - temp_turf = temp_turf.get_translated_turf(V_norm) - if (!locate(/obj/structure/table) in temp_turf) - var/vector/V2 = atoms2vector(src, temp_turf) - vector_translate(V2, 0.1 SECONDS) - user.visible_message("\The [user] slides \the [src] down the table... and straight into the ground!", "You slide \the [src] down the table, and straight into the ground!") - smash(over_location, user, FALSE) - return - while (temp_turf != dest) - - vector_translate(V, 0.1 SECONDS) - user.visible_message("\The [user] expertly slides \the [src] down the table.", "You slide \the [src] down the table. What a pro.") + do + temp_turf = temp_turf.get_translated_turf(V_norm) + if (!locate(/obj/structure/table) in temp_turf) + var/datum/vector/V2 = atoms2vector(src, temp_turf) + vector_translate(V2, 0.1 SECONDS) + user.visible_message("\The [user] slides \the [src] down the table... and straight into the ground!", "You slide \the [src] down the table, and straight into the ground!") + smash(over_location, user, FALSE) return - else - if (!(locate(/obj/structure/table) in over_location)) - return ..() - if (!user.Adjacent(src) || !src_location.Adjacent(over_location)) // Regular users can only do short slides. - return ..() - if (prob(10)) - user.visible_message("\The [user] tries to slide \the [src] down the table, but fails miserably.", "You fail to slide \the [src] down the table!") - smash(over_location, user, FALSE) - return - user.visible_message("\The [user] slides \the [src] down the table.", "You slide \the [src] down the table!") - forceMove(over_location) - return - return ..() + while (temp_turf != dest) + + vector_translate(V, 0.1 SECONDS) + user.visible_message("\The [user] expertly slides \the [src] down the table.", "You slide \the [src] down the table. What a pro.") + return + else + if (!(locate(/obj/structure/table) in over_location)) + return + if (!user.Adjacent(src) || !src_location.Adjacent(over_location)) // Regular users can only do short slides. + return + if (prob(10)) + user.visible_message("\The [user] tries to slide \the [src] down the table, but fails miserably.", "You fail to slide \the [src] down the table!") + smash(over_location, user, FALSE) + return + user.visible_message("\The [user] slides \the [src] down the table.", "You slide \the [src] down the table!") + forceMove(over_location) + return diff --git a/code/modules/reagents/reagent_containers.dm b/code/modules/reagents/reagent_containers.dm index b254c6298e..236f2c4a56 100644 --- a/code/modules/reagents/reagent_containers.dm +++ b/code/modules/reagents/reagent_containers.dm @@ -107,9 +107,9 @@ var/turf/T = get_turf(src) if(!T || !target.CanPass(src, T) || !thrownby || !thrownby.actions) return - for(var/datum/action/innate/drink_fling/D in thrownby.actions) - if(D.active) - return TRUE + var/datum/action/innate/D = get_action_of_type(thrownby, /datum/action/innate/drink_fling) + if(D.active) + return TRUE /obj/item/reagent_containers/proc/ForceResetRotation() transform = initial(transform) From 335c28ff2509c48e2ac54c8f3a904e4ba0595bdf Mon Sep 17 00:00:00 2001 From: ancientpower Date: Tue, 4 Feb 2020 17:02:13 -0600 Subject: [PATCH 7/9] fixes for the requested changes --- code/modules/food_and_drinks/drinks/drinks.dm | 58 +++++++++---------- code/modules/reagents/reagent_containers.dm | 2 +- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/code/modules/food_and_drinks/drinks/drinks.dm b/code/modules/food_and_drinks/drinks/drinks.dm index 9ac81b821e..98a36bc0ba 100644 --- a/code/modules/food_and_drinks/drinks/drinks.dm +++ b/code/modules/food_and_drinks/drinks/drinks.dm @@ -149,36 +149,7 @@ return //Are we an expert slider? var/datum/action/innate/D = get_action_of_type(user, /datum/action/innate/drink_fling) - if(D.active) - var/distance = MANHATTAN_DISTANCE(over_location, src) - if (distance >= 8 || distance == 0) // More than a full screen to go, or trying to slide to the same tile - return - - // Geometrically checking if we're on a straight line. - var/datum/vector/V = atoms2vector(src, over_location) - var/datum/vector/V_norm = V.duplicate() - V_norm.normalize() - if (!V_norm.is_integer()) - return // Only a cardinal vector (north, south, east, west) can pass this test - - // Checks if there's tables on the path. - var/turf/dest = get_translated_turf(V) - var/turf/temp_turf = src_location - - do - temp_turf = temp_turf.get_translated_turf(V_norm) - if (!locate(/obj/structure/table) in temp_turf) - var/datum/vector/V2 = atoms2vector(src, temp_turf) - vector_translate(V2, 0.1 SECONDS) - user.visible_message("\The [user] slides \the [src] down the table... and straight into the ground!", "You slide \the [src] down the table, and straight into the ground!") - smash(over_location, user, FALSE) - return - while (temp_turf != dest) - - vector_translate(V, 0.1 SECONDS) - user.visible_message("\The [user] expertly slides \the [src] down the table.", "You slide \the [src] down the table. What a pro.") - return - else + if(!D?.active) if (!(locate(/obj/structure/table) in over_location)) return if (!user.Adjacent(src) || !src_location.Adjacent(over_location)) // Regular users can only do short slides. @@ -190,7 +161,34 @@ user.visible_message("\The [user] slides \the [src] down the table.", "You slide \the [src] down the table!") forceMove(over_location) return + var/distance = MANHATTAN_DISTANCE(over_location, src) + if (distance >= 8 || distance == 0) // More than a full screen to go, or trying to slide to the same tile + return + // Geometrically checking if we're on a straight line. + var/datum/vector/V = atoms2vector(src, over_location) + var/datum/vector/V_norm = V.duplicate() + V_norm.normalize() + if (!V_norm.is_integer()) + return // Only a cardinal vector (north, south, east, west) can pass this test + + // Checks if there's tables on the path. + var/turf/dest = get_translated_turf(V) + var/turf/temp_turf = src_location + + do + temp_turf = temp_turf.get_translated_turf(V_norm) + if (!locate(/obj/structure/table) in temp_turf) + var/datum/vector/V2 = atoms2vector(src, temp_turf) + vector_translate(V2, 0.1 SECONDS) + user.visible_message("\The [user] slides \the [src] down the table... and straight into the ground!", "You slide \the [src] down the table, and straight into the ground!") + smash(over_location, user, FALSE) + return + while (temp_turf != dest) + + vector_translate(V, 0.1 SECONDS) + user.visible_message("\The [user] expertly slides \the [src] down the table.", "You slide \the [src] down the table. What a pro.") + return //////////////////////////////////////////////////////////////////////////////// diff --git a/code/modules/reagents/reagent_containers.dm b/code/modules/reagents/reagent_containers.dm index 236f2c4a56..6d5c546e7e 100644 --- a/code/modules/reagents/reagent_containers.dm +++ b/code/modules/reagents/reagent_containers.dm @@ -108,7 +108,7 @@ if(!T || !target.CanPass(src, T) || !thrownby || !thrownby.actions) return var/datum/action/innate/D = get_action_of_type(thrownby, /datum/action/innate/drink_fling) - if(D.active) + if(D?.active) return TRUE /obj/item/reagent_containers/proc/ForceResetRotation() From 5fb82a2e6b8fe4468ce9d112cae61a00313096b8 Mon Sep 17 00:00:00 2001 From: ancientpower Date: Tue, 4 Feb 2020 17:10:02 -0600 Subject: [PATCH 8/9] fixes for the requested changes' fixes --- code/modules/food_and_drinks/drinks/drinks.dm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/code/modules/food_and_drinks/drinks/drinks.dm b/code/modules/food_and_drinks/drinks/drinks.dm index 98a36bc0ba..90a65831a4 100644 --- a/code/modules/food_and_drinks/drinks/drinks.dm +++ b/code/modules/food_and_drinks/drinks/drinks.dm @@ -140,19 +140,17 @@ /obj/item/reagent_containers/food/drinks/MouseDrop(atom/over, atom/src_location, atom/over_location, src_control, over_control, params) var/mob/user = usr . = ..() - if (!istype(src_location)) + if (!istype(src_location) || !istype(over_location)) return if (!user || user.incapacitated() || !user.Adjacent(src)) return // Attempted drink sliding - if (!locate(/obj/structure/table) in src_location) + if (!(locate(/obj/structure/table) in src_location) || !(locate(/obj/structure/table) in over_location)) return //Are we an expert slider? var/datum/action/innate/D = get_action_of_type(user, /datum/action/innate/drink_fling) if(!D?.active) - if (!(locate(/obj/structure/table) in over_location)) - return - if (!user.Adjacent(src) || !src_location.Adjacent(over_location)) // Regular users can only do short slides. + if (!src_location.Adjacent(over_location)) // Regular users can only do short slides. return if (prob(10)) user.visible_message("\The [user] tries to slide \the [src] down the table, but fails miserably.", "You fail to slide \the [src] down the table!") From dd521ef00905a47db2063e177c50470bfb4d5e1c Mon Sep 17 00:00:00 2001 From: ancientpower Date: Tue, 4 Feb 2020 17:18:13 -0600 Subject: [PATCH 9/9] i swear it compiled locally --- code/__HELPERS/vector.dm | 2 +- code/modules/food_and_drinks/drinks/drinks.dm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/__HELPERS/vector.dm b/code/__HELPERS/vector.dm index dff3cefead..80295bde0e 100644 --- a/code/__HELPERS/vector.dm +++ b/code/__HELPERS/vector.dm @@ -35,7 +35,7 @@ /datum/vector/proc/is_integer() return ISINTEGER(x) && ISINTEGER(y) -/atom/movable/proc/datum/vector_translate(var/datum/vector/V, var/delay) +/atom/movable/proc/vector_translate(var/datum/vector/V, var/delay) var/turf/T = get_turf(src) var/turf/destination = locate(T.x + V.x, T.y + V.y, z) var/datum/vector/V_norm = V.duplicate() diff --git a/code/modules/food_and_drinks/drinks/drinks.dm b/code/modules/food_and_drinks/drinks/drinks.dm index 90a65831a4..19d0162a4c 100644 --- a/code/modules/food_and_drinks/drinks/drinks.dm +++ b/code/modules/food_and_drinks/drinks/drinks.dm @@ -144,9 +144,9 @@ return if (!user || user.incapacitated() || !user.Adjacent(src)) return - // Attempted drink sliding if (!(locate(/obj/structure/table) in src_location) || !(locate(/obj/structure/table) in over_location)) return + //Are we an expert slider? var/datum/action/innate/D = get_action_of_type(user, /datum/action/innate/drink_fling) if(!D?.active)