From 6e86cc7758986f8f7f9f2b917b93e03bc89c4936 Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Mon, 28 Dec 2020 17:27:16 -0800 Subject: [PATCH 01/10] wew --- code/__DEFINES/dcs/signals.dm | 12 ++++- code/datums/components/orbiter.dm | 2 + code/datums/components/riding.dm | 4 +- code/datums/components/twitch_plays.dm | 74 ++++++++++++++++++++++++++ code/modules/vehicles/cars/clowncar.dm | 17 +++++- tgstation.dme | 1 + 6 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 code/datums/components/twitch_plays.dm diff --git a/code/__DEFINES/dcs/signals.dm b/code/__DEFINES/dcs/signals.dm index 51a5fb3ece..a084f2ae34 100644 --- a/code/__DEFINES/dcs/signals.dm +++ b/code/__DEFINES/dcs/signals.dm @@ -136,11 +136,15 @@ #define COMSIG_ATOM_ATTACK_HAND "atom_attack_hand" //from base of atom/attack_hand(): (mob/user) #define COMSIG_ATOM_ATTACK_PAW "atom_attack_paw" //from base of atom/attack_paw(): (mob/user) #define COMPONENT_NO_ATTACK_HAND 1 //works on all 3. +///////////////// + //This signal return value bitflags can be found in __DEFINES/misc.dm #define COMSIG_ATOM_INTERCEPT_Z_FALL "movable_intercept_z_impact" //called for each movable in a turf contents on /turf/zImpact(): (atom/movable/A, levels) - -///////////////// +/// Called from orbit component: (atom/movable/orbiter, radius, clockwise, rotation_speed, rotation_segments, pre_rotation) +#define COMSIG_ATOM_ORBIT_BEGIN "atom_orbit_begin" +/// Called from orbit component: (atom/movable/orbiter, refreshing) +#define COMSIG_ATOM_ORBIT_END "atom_orbit_end" #define COMSIG_ENTER_AREA "enter_area" //from base of area/Entered(): (/area) #define COMSIG_EXIT_AREA "exit_area" //from base of area/Exited(): (/area) @@ -536,3 +540,7 @@ #define COMSIG_XENO_TURF_CLICK_SHIFT "xeno_turf_click_shift" //from turf ShiftClickOn(): (/mob) #define COMSIG_XENO_TURF_CLICK_CTRL "xeno_turf_click_alt" //from turf AltClickOn(): (/mob) #define COMSIG_XENO_MONKEY_CLICK_CTRL "xeno_monkey_click_ctrl" //from monkey CtrlClickOn(): (/mob) + +// twitch plays +/// Returns direction: (wipe_votes) +#define COMSIG_TWITCH_PLAYS_MOVEMENT_DATA "twitch_plays_movement_data" diff --git a/code/datums/components/orbiter.dm b/code/datums/components/orbiter.dm index 53373de6d7..49b19f767c 100644 --- a/code/datums/components/orbiter.dm +++ b/code/datums/components/orbiter.dm @@ -54,6 +54,7 @@ move_react() /datum/component/orbiter/proc/begin_orbit(atom/movable/orbiter, radius, clockwise, rotation_speed, rotation_segments, pre_rotation) + SEND_SIGNAL(parent, COMSIG_ATOM_ORBIT_BEGIN, orbiter, radius, clockwise, rotation_speed, rotation_segments, pre_rotation) if(orbiter.orbiting) if(orbiter.orbiting == src) orbiter.orbiting.end_orbit(orbiter, TRUE) @@ -87,6 +88,7 @@ /datum/component/orbiter/proc/end_orbit(atom/movable/orbiter, refreshing=FALSE) if(!orbiters[orbiter]) return + SEND_SIGNAL(parent, COMSIG_ATOM_ORBIT_END, orbiter, refreshing) UnregisterSignal(orbiter, COMSIG_MOVABLE_MOVED) orbiter.SpinAnimation(0, 0) if(istype(orbiters[orbiter],/matrix)) //This is ugly. diff --git a/code/datums/components/riding.dm b/code/datums/components/riding.dm index 973ca7463e..03f3820a9b 100644 --- a/code/datums/components/riding.dm +++ b/code/datums/components/riding.dm @@ -133,7 +133,7 @@ //KEYS /datum/component/riding/proc/keycheck(mob/user) - return !keytype || user.is_holding_item_of_type(keytype) + return !keytype || user?.is_holding_item_of_type(keytype) //BUCKLE HOOKS /datum/component/riding/proc/restore_position(mob/living/buckled_mob) @@ -153,7 +153,7 @@ /datum/component/riding/proc/handle_ride(mob/user, direction) var/atom/movable/AM = parent - if(user.incapacitated()) + if(user && user.incapacitated()) Unbuckle(user) return if(world.time < last_vehicle_move + ((last_move_diagonal? 2 : 1) * vehicle_move_delay)) diff --git a/code/datums/components/twitch_plays.dm b/code/datums/components/twitch_plays.dm new file mode 100644 index 0000000000..b25978d276 --- /dev/null +++ b/code/datums/components/twitch_plays.dm @@ -0,0 +1,74 @@ +/** + * Observers voting on things through orbiting + */ +/datum/component/twitch_plays + /// Observers + var/list/mob/players = list() + +/datum/component/twitch_plays/Initialize(...) + . = ..() + if(!isatom(parent)) + return COMPONENT_INCOMPATIBLE + RegisterSignal(parent, COMSIG_ATOM_ORBIT_BEGIN, .proc/on_start_orbit) + RegisterSignal(parent, COMSIG_ATOM_ORBIT_END, .proc/on_stop_orbit) + +/datum/component/twitch_plays/proc/on_start_orbit(datum/source, atom/movable/orbiter) + if(!isobserver(orbiter)) + return + AttachPlayer(orbiter) + +/datum/component/twitch_plays/proc/on_end_orbit(datum/source, atom/movable/orbiter) + if(!(orbiter in players)) + return + DetachPlayer(orbiter) + +/datum/component/twitch_plays/proc/AttachPlayer(mob/dead/observer) + players |= observer + RegisterSignal(observer, COMSIG_PARENT_QDELETING, .proc/on_end_orbit) + +/datum/component/twitch_plays/proc/DetachPlayer(mob/dead/observer) + players -= observer + UnregisterSignal(observer, COMSIG_PARENT_QDELETING) + +/// Simple movement one +/datum/component/twitch_plays/simple_movement + /// Movement votes by observer + var/list/votes = list() + /// Allow diagonals + var/allow_diagonal = FALSE + +/datum/component/twitch_plays/simple_movement/Initialize(...) + . = ..() + if(. & COMPONENT_INCOMPATIBLE) + return + RegisterSignal(parent, COMSIG_TWITCH_PLAYS_MOVEMENT_DATA, .proc/fetch_data) + +/datum/component/twitch_plays/simple_movement/AttachPlayer(mob/dead/observer) + . = ..() + RegisterSignal(observer, COMSIG_MOVABLE_PRE_MOVE, .proc/pre_move) + +/datum/component/twitch_plays/simple_movement/DetachPlayer(mob/dead/observer) + . = ..() + UnregisterSignal(observer, COMSIG_MOVABLE_PRE_MOVE) + +/datum/component/twitch_plays/simple_movement/proc/pre_move(datum/source, turf/newLoc) + if(get_dist(newLoc, parent) > 1) // they're trying to escape orbit + return + . = COMPONENT_MOVABLE_BLOCK_PRE_MOVE + var/dir = get_dir(parent, newLoc) + if(!dir) + return + if(allow_diagonal || !((dir - 1) & dir)) + votes[source] = dir + else // pick one or the other + votes[source] = prob(50) (dir & ~(dir - 1)) : (dir & (dir - 1)) + +/datum/component/twitch_plays/simple_movement/proc/fetch_data(datum/source, wipe_votes) + if(votes.len) + return + var/list/total = list(TEXT_NORTH, TEXT_SOUTH, TEXT_EAST, TEXT_WEST) + for(var/i in votes) + total[num2text(votes[i])] += 1 + . = text2num(pick(total)) + if(wipe_votes) + votes.len = 0 diff --git a/code/modules/vehicles/cars/clowncar.dm b/code/modules/vehicles/cars/clowncar.dm index 7a7886e999..db295ffd12 100644 --- a/code/modules/vehicles/cars/clowncar.dm +++ b/code/modules/vehicles/cars/clowncar.dm @@ -18,14 +18,12 @@ . = ..() initialize_controller_action_type(/datum/action/vehicle/sealed/horn/clowncar, VEHICLE_CONTROL_DRIVE) - /obj/vehicle/sealed/car/clowncar/driver_move(mob/user, direction) //Prevent it from moving onto space if(isspaceturf(get_step(src, direction))) return FALSE else return ..() - /obj/vehicle/sealed/car/clowncar/auto_assign_occupant_flags(mob/M) if(ishuman(M)) var/mob/living/carbon/human/H = M @@ -138,3 +136,18 @@ /obj/vehicle/sealed/car/clowncar/proc/StopDroppingOil() droppingoil = FALSE + +/obj/vehicle/sealed/car/clowncar/twitch_plays/Initialize() + . = ..() + AddComponent(/datum/component/twitch_plays/simple_movement) + START_PROCESSING(SSfastprocess, src) + +/obj/vehicle/sealed/car/clowncar/twitch_plays/Destroy() + . = ..() + STOP_PROCESSING(SSfastprocess, src) + +/obj/vehicle/sealed/car/clowncar/twitch_plays/process() + var/dir = SEND_SIGNAL(src, COMSIG_TWITCH_PLAYS_MOVEMENT_DATA, TRUE) + if(!dir) + return + driver_move(null, dir) diff --git a/tgstation.dme b/tgstation.dme index 07eefc79ef..2b00eb6b98 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -492,6 +492,7 @@ #include "code\datums\components\swarming.dm" #include "code\datums\components\tackle.dm" #include "code\datums\components\thermite.dm" +#include "code\datums\components\twitch_plays.dm" #include "code\datums\components\twohanded.dm" #include "code\datums\components\uplink.dm" #include "code\datums\components\virtual_reality.dm" From a8bc98aa40cd0ad6e02b6d984458628ed66eb525 Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Mon, 28 Dec 2020 17:29:55 -0800 Subject: [PATCH 02/10] ok --- code/datums/components/twitch_plays.dm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/datums/components/twitch_plays.dm b/code/datums/components/twitch_plays.dm index b25978d276..dc753c2fd6 100644 --- a/code/datums/components/twitch_plays.dm +++ b/code/datums/components/twitch_plays.dm @@ -10,7 +10,7 @@ if(!isatom(parent)) return COMPONENT_INCOMPATIBLE RegisterSignal(parent, COMSIG_ATOM_ORBIT_BEGIN, .proc/on_start_orbit) - RegisterSignal(parent, COMSIG_ATOM_ORBIT_END, .proc/on_stop_orbit) + RegisterSignal(parent, COMSIG_ATOM_ORBIT_END, .proc/on_end_orbit) /datum/component/twitch_plays/proc/on_start_orbit(datum/source, atom/movable/orbiter) if(!isobserver(orbiter)) @@ -61,7 +61,7 @@ if(allow_diagonal || !((dir - 1) & dir)) votes[source] = dir else // pick one or the other - votes[source] = prob(50) (dir & ~(dir - 1)) : (dir & (dir - 1)) + votes[source] = prob(50)? (dir & ~(dir - 1)) : (dir & (dir - 1)) /datum/component/twitch_plays/simple_movement/proc/fetch_data(datum/source, wipe_votes) if(votes.len) From abb37896a9d4bf300223725fd4c66fccf2662b72 Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Mon, 28 Dec 2020 17:35:47 -0800 Subject: [PATCH 03/10] please work --- code/modules/mob/dead/observer/observer.dm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/modules/mob/dead/observer/observer.dm b/code/modules/mob/dead/observer/observer.dm index 9493d11792..dc53f9487f 100644 --- a/code/modules/mob/dead/observer/observer.dm +++ b/code/modules/mob/dead/observer/observer.dm @@ -380,6 +380,8 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp /mob/dead/observer/Move(NewLoc, direct) + if (SEND_SIGNAL(src, COMSIG_MOVABLE_PRE_MOVE, NewLoc) & COMPONENT_MOVABLE_BLOCK_PRE_MOVE) + return if(updatedir) setDir(direct)//only update dir if we actually need it, so overlays won't spin on base sprites that don't have directions of their own var/oldloc = loc From ee9cc135f1620d47906bb41f80b3d50013dd371a Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Mon, 28 Dec 2020 17:43:50 -0800 Subject: [PATCH 04/10] fix --- code/datums/components/twitch_plays.dm | 2 +- code/modules/vehicles/cars/clowncar.dm | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/code/datums/components/twitch_plays.dm b/code/datums/components/twitch_plays.dm index dc753c2fd6..7cc3226bd3 100644 --- a/code/datums/components/twitch_plays.dm +++ b/code/datums/components/twitch_plays.dm @@ -64,7 +64,7 @@ votes[source] = prob(50)? (dir & ~(dir - 1)) : (dir & (dir - 1)) /datum/component/twitch_plays/simple_movement/proc/fetch_data(datum/source, wipe_votes) - if(votes.len) + if(!votes.len) return var/list/total = list(TEXT_NORTH, TEXT_SOUTH, TEXT_EAST, TEXT_WEST) for(var/i in votes) diff --git a/code/modules/vehicles/cars/clowncar.dm b/code/modules/vehicles/cars/clowncar.dm index db295ffd12..698c3bf904 100644 --- a/code/modules/vehicles/cars/clowncar.dm +++ b/code/modules/vehicles/cars/clowncar.dm @@ -137,6 +137,9 @@ /obj/vehicle/sealed/car/clowncar/proc/StopDroppingOil() droppingoil = FALSE +/obj/vehicle/sealed/car/clowncar/twitch_plays + key_type = null + /obj/vehicle/sealed/car/clowncar/twitch_plays/Initialize() . = ..() AddComponent(/datum/component/twitch_plays/simple_movement) From 964b60c9ca06b2dd01512e33afa4ee0f3e386825 Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Mon, 28 Dec 2020 17:50:16 -0800 Subject: [PATCH 05/10] ok --- code/datums/components/twitch_plays.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/datums/components/twitch_plays.dm b/code/datums/components/twitch_plays.dm index 7cc3226bd3..cd1168a416 100644 --- a/code/datums/components/twitch_plays.dm +++ b/code/datums/components/twitch_plays.dm @@ -69,6 +69,6 @@ var/list/total = list(TEXT_NORTH, TEXT_SOUTH, TEXT_EAST, TEXT_WEST) for(var/i in votes) total[num2text(votes[i])] += 1 - . = text2num(pick(total)) + . = text2num(pickweight(total, 0)) if(wipe_votes) votes.len = 0 From e76e9ad34c55b491afc1cd83e5dd54bc3c1ed86a Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Mon, 28 Dec 2020 18:02:16 -0800 Subject: [PATCH 06/10] poi --- code/modules/vehicles/cars/clowncar.dm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/modules/vehicles/cars/clowncar.dm b/code/modules/vehicles/cars/clowncar.dm index 698c3bf904..655ca21b93 100644 --- a/code/modules/vehicles/cars/clowncar.dm +++ b/code/modules/vehicles/cars/clowncar.dm @@ -144,10 +144,13 @@ . = ..() AddComponent(/datum/component/twitch_plays/simple_movement) START_PROCESSING(SSfastprocess, src) + GLOB.poi_list |= src + notify_ghosts("Twitch Plays: Clown Car") /obj/vehicle/sealed/car/clowncar/twitch_plays/Destroy() - . = ..() STOP_PROCESSING(SSfastprocess, src) + GLOB.poi_list -= src + return ..() /obj/vehicle/sealed/car/clowncar/twitch_plays/process() var/dir = SEND_SIGNAL(src, COMSIG_TWITCH_PLAYS_MOVEMENT_DATA, TRUE) From d338d7a14b10b29e194bdc0c674a2408887d8953 Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Mon, 28 Dec 2020 21:03:50 -0800 Subject: [PATCH 07/10] auto --- code/datums/components/twitch_plays.dm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/code/datums/components/twitch_plays.dm b/code/datums/components/twitch_plays.dm index cd1168a416..48b54f90a2 100644 --- a/code/datums/components/twitch_plays.dm +++ b/code/datums/components/twitch_plays.dm @@ -72,3 +72,26 @@ . = text2num(pickweight(total, 0)) if(wipe_votes) votes.len = 0 + +/datum/component/twitch_plays/simple_movement/auto + var/move_delay = 2 + var/last_move = 0 + +/datum/component/twitch_plays/simple_movement/auto/Initialize(...) + . = ..() + if(. & COMPONENT_INCOMPATIBLE) + return + START_PROCESSING(SSfastprocess, src) + +/datum/component/twitch_plays/simple_movement/auto/Destroy(force, silent) + STOP_PROCESSING(SSfastprocess, src) + return ..() + +/datum/component/twitch_plays/simple_movement/auto/process() + var/dir = fetch_data(null, TRUE) + if(!dir) + return + if(world.time < (last_move + move_delay)) + return + last_move = world.time + step(parent, dir) From 042c7d9b8b79f14b84050219fc33c92876bf8477 Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Mon, 28 Dec 2020 21:07:55 -0800 Subject: [PATCH 08/10] wew --- code/datums/components/twitch_plays.dm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/code/datums/components/twitch_plays.dm b/code/datums/components/twitch_plays.dm index 48b54f90a2..21521477cf 100644 --- a/code/datums/components/twitch_plays.dm +++ b/code/datums/components/twitch_plays.dm @@ -12,6 +12,11 @@ RegisterSignal(parent, COMSIG_ATOM_ORBIT_BEGIN, .proc/on_start_orbit) RegisterSignal(parent, COMSIG_ATOM_ORBIT_END, .proc/on_end_orbit) +/datum/component/twitch_plays/Destroy(force, silent) + for(var/i in players) + DetachPlayer(i) + return ..() + /datum/component/twitch_plays/proc/on_start_orbit(datum/source, atom/movable/orbiter) if(!isobserver(orbiter)) return From 95c420ccba09a00b6b621647c64063906ae0a8bc Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Tue, 29 Dec 2020 15:55:14 -0700 Subject: [PATCH 09/10] Update twitch_plays.dm --- code/datums/components/twitch_plays.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/datums/components/twitch_plays.dm b/code/datums/components/twitch_plays.dm index 21521477cf..b69764a658 100644 --- a/code/datums/components/twitch_plays.dm +++ b/code/datums/components/twitch_plays.dm @@ -7,7 +7,7 @@ /datum/component/twitch_plays/Initialize(...) . = ..() - if(!isatom(parent)) + if(!ismovable(parent)) return COMPONENT_INCOMPATIBLE RegisterSignal(parent, COMSIG_ATOM_ORBIT_BEGIN, .proc/on_start_orbit) RegisterSignal(parent, COMSIG_ATOM_ORBIT_END, .proc/on_end_orbit) From 97deaf34823e9118003dc1344bc68bb531b7252a Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Tue, 29 Dec 2020 15:56:10 -0700 Subject: [PATCH 10/10] Update twitch_plays.dm --- code/datums/components/twitch_plays.dm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/datums/components/twitch_plays.dm b/code/datums/components/twitch_plays.dm index b69764a658..aadbd58b4b 100644 --- a/code/datums/components/twitch_plays.dm +++ b/code/datums/components/twitch_plays.dm @@ -7,7 +7,7 @@ /datum/component/twitch_plays/Initialize(...) . = ..() - if(!ismovable(parent)) + if(!isatom(parent)) return COMPONENT_INCOMPATIBLE RegisterSignal(parent, COMSIG_ATOM_ORBIT_BEGIN, .proc/on_start_orbit) RegisterSignal(parent, COMSIG_ATOM_ORBIT_END, .proc/on_end_orbit) @@ -83,6 +83,8 @@ var/last_move = 0 /datum/component/twitch_plays/simple_movement/auto/Initialize(...) + if(!ismovable(parent)) + return COMPONENT_INCOMPATIBLE . = ..() if(. & COMPONENT_INCOMPATIBLE) return