From 22557cab7d5bdbb5e1a85f5266025b98d4dfea0d Mon Sep 17 00:00:00 2001
From: fernerr <35879136+fernerr@users.noreply.github.com>
Date: Fri, 13 Sep 2019 21:01:35 +0200
Subject: [PATCH] Makes the janitor cart pushable (#6956)
Makes the janitor cart pushable by shamelessly copying from wheelchair code.
As suggested here https://forums.aurorastation.org/topic/12726-push-the-janicart/
---
code/game/machinery/doors/door.dm | 8 ++
code/game/objects/structures/janicart.dm | 79 ++++++++++++++++++-
code/modules/mob/mob_movement.dm | 2 +-
.../Ferner-190906-coding_janitorcart.yml | 41 ++++++++++
4 files changed, 128 insertions(+), 2 deletions(-)
create mode 100644 html/changelogs/Ferner-190906-coding_janitorcart.yml
diff --git a/code/game/machinery/doors/door.dm b/code/game/machinery/doors/door.dm
index 4311b7f5c58..8b1355a65f8 100644
--- a/code/game/machinery/doors/door.dm
+++ b/code/game/machinery/doors/door.dm
@@ -178,6 +178,14 @@
else
do_animate("deny")
return
+ if(istype(AM, /obj/structure/janitorialcart))
+ var/obj/structure/janitorialcart/cart = AM
+ if(density)
+ if(cart.pulling && (src.allowed(cart.pulling)))
+ open()
+ else
+ do_animate("deny")
+ return
return
diff --git a/code/game/objects/structures/janicart.dm b/code/game/objects/structures/janicart.dm
index e5d24084f24..5e3221503af 100644
--- a/code/game/objects/structures/janicart.dm
+++ b/code/game/objects/structures/janicart.dm
@@ -21,6 +21,8 @@
var/signs = 0 //maximum capacity hardcoded below
var/has_items = 0//This is set true whenever the cart has anything loaded/mounted on it
var/dismantled = 0//This is set true after the object has been dismantled to avoid an infintie loop
+ var/driving
+ var/mob/living/pulling
/obj/structure/janitorialcart/New()
..()
@@ -302,4 +304,79 @@
has_items = 1
if(signs)
add_overlay("cart_sign[signs]")
- has_items = 1
\ No newline at end of file
+ has_items = 1
+
+//Shamelessly copied from wheelchair code
+/obj/structure/janitorialcart/relaymove(mob/user, direction)
+ if(user.stat || user.stunned || user.weakened || user.paralysis || user.lying || user.restrained())
+ if(user==pulling)
+ pulling = null
+ user.pulledby = null
+ to_chat(user, "You lost your grip!")
+ return
+ if(user.pulling && (user == pulling))
+ pulling = null
+ user.pulledby = null
+ return
+ if(pulling && (get_dist(src, pulling) > 1))
+ pulling = null
+ user.pulledby = null
+ if(user==pulling)
+ return
+ if(pulling && (get_dir(src.loc, pulling.loc) == direction))
+ to_chat(user, "You cannot go there.")
+ return
+
+ driving = 1
+ var/turf/T = null
+ if(pulling)
+ T = pulling.loc
+ if(get_dist(src, pulling) >= 1)
+ step(pulling, get_dir(pulling.loc, src.loc))
+ step(src, direction)
+ set_dir(direction)
+ if(pulling)
+ if(pulling.loc == src.loc)
+ pulling.forceMove(T)
+ else
+ spawn(0)
+ if(get_dist(src, pulling) > 1)
+ pulling = null
+ user.pulledby = null
+ pulling.set_dir(get_dir(pulling, src))
+ driving = 0
+
+/obj/structure/janitorialcart/Move()
+ . = ..()
+ if (pulling && (get_dist(src, pulling) > 1))
+ pulling.pulledby = null
+ to_chat(pulling, "You lost your grip!")
+ pulling = null
+
+/obj/structure/janitorialcart/CtrlClick(var/mob/user)
+ if(in_range(src, user))
+ if(!ishuman(user)) return
+ if(!pulling)
+ pulling = user
+ user.pulledby = src
+ if(user.pulling)
+ user.stop_pulling()
+ user.set_dir(get_dir(user, src))
+ to_chat(user, "You grip \the [name]'s handles.")
+ else
+ to_chat(usr, "You let go of \the [name]'s handles.")
+ pulling.pulledby = null
+ pulling = null
+ return
+
+/obj/structure/janitorialcart/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
+ if(air_group || (height==0)) return 1
+ if(istype(mover) && mover.checkpass(PASSTABLE))
+ return 1
+ if(istype(mover, /mob/living) && mover == pulling)
+ return 1
+ else
+ if(istype(mover, /obj/item/projectile))
+ return prob(30)
+ else
+ return !density
\ No newline at end of file
diff --git a/code/modules/mob/mob_movement.dm b/code/modules/mob/mob_movement.dm
index 74d9bf7cbd4..9924746d670 100644
--- a/code/modules/mob/mob_movement.dm
+++ b/code/modules/mob/mob_movement.dm
@@ -319,7 +319,7 @@
//Wheelchair pushing goes here for now.
//TODO: Fuck wheelchairs.
- if(istype(mob.pulledby, /obj/structure/bed/chair/wheelchair))
+ if(istype(mob.pulledby, /obj/structure/bed/chair/wheelchair) || istype(mob.pulledby, /obj/structure/janitorialcart))
move_delay += 1
return mob.pulledby.relaymove(mob, direct)
diff --git a/html/changelogs/Ferner-190906-coding_janitorcart.yml b/html/changelogs/Ferner-190906-coding_janitorcart.yml
new file mode 100644
index 00000000000..252799c9c6e
--- /dev/null
+++ b/html/changelogs/Ferner-190906-coding_janitorcart.yml
@@ -0,0 +1,41 @@
+################################
+# Example Changelog File
+#
+# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb.
+#
+# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.)
+# When it is, any changes listed below will disappear.
+#
+# Valid Prefixes:
+# bugfix
+# wip (For works in progress)
+# tweak
+# soundadd
+# sounddel
+# rscadd (general adding of nice things)
+# rscdel (general deleting of nice things)
+# imageadd
+# imagedel
+# maptweak
+# spellcheck (typo fixes)
+# experiment
+# balance
+# admin
+# backend
+# security
+# refactor
+#################################
+
+# Your name.
+author: Ferner
+
+# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again.
+delete-after: True
+
+# Any changes you've made. See valid prefix list above.
+# INDENT WITH TWO SPACES. NOT TABS. SPACES.
+# SCREW THIS UP AND IT WON'T WORK.
+# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries.
+# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog.
+changes:
+ - rscadd: "Janitor carts can now be pushed like wheelchairs via Ctrl Click."