From 413dc66af129c5af2e15653ae4fa30b5475995f5 Mon Sep 17 00:00:00 2001 From: lessthanthree <83487515+lessthnthree@users.noreply.github.com> Date: Thu, 6 Jun 2024 02:17:04 -0700 Subject: [PATCH] Tram crossing signal logic fixes (#83610) ## About The Pull Request Minor fixes to the tram crossing signal logic. Reverts an earlier change I made to the subsystem, which resulted in the signals being wildly off in their timings on a regular basis. Adjusted the red length corresponding to the properly timed signals. Removed define for degraded yellow, as that's now simplified into a check at signal activation time. ## Why It's Good For The Game Tram crossing lights better reflect tram status, staying green when the tram is broken therefore safe to walk. Consistently turn red when tram approaching. ## Changelog :cl: LT3 fix: Fixed timing issue where tram crossing signals would be out of sync with the moving tram fix: Tram crossing signals consistently show green when safe, blue when broken fix: Tram crossing signals show red instead of yellow when degraded /:cl: --- code/__DEFINES/transport.dm | 7 +-- code/datums/components/energized.dm | 4 +- code/modules/transport/tram/tram_signals.dm | 62 +++++++-------------- 3 files changed, 25 insertions(+), 48 deletions(-) diff --git a/code/__DEFINES/transport.dm b/code/__DEFINES/transport.dm index 452ba285354..09d4f39280a 100644 --- a/code/__DEFINES/transport.dm +++ b/code/__DEFINES/transport.dm @@ -99,12 +99,11 @@ DEFINE_BITFIELD(request_flags, list( #define XING_STATE_RED 2 #define XING_STATE_MALF 3 -#define AMBER_THRESHOLD_NORMAL 45 -#define RED_THRESHOLD_NORMAL 20 -#define AMBER_THRESHOLD_DEGRADED 30 -#define RED_THRESHOLD_DEGRADED 15 +#define XING_THRESHOLD_AMBER 45 +#define XING_THRESHOLD_RED 27 #define DEFAULT_TRAM_LENGTH 10 +#define DEFAULT_TRAM_MIDPOINT 5 // Tram machinery subtype #define TRANSPORT_SYSTEM_NORMAL 0 diff --git a/code/datums/components/energized.dm b/code/datums/components/energized.dm index eb45ee66e2b..255970bfd31 100644 --- a/code/datums/components/energized.dm +++ b/code/datums/components/energized.dm @@ -95,7 +95,7 @@ tram_velocity_sign = tram.travel_direction & EAST ? 1 : -1 // How far away are we? negative if already passed. - var/approach_distance = tram_velocity_sign * (plate_pos - (tram_pos + (DEFAULT_TRAM_LENGTH * 0.5))) + var/approach_distance = tram_velocity_sign * (plate_pos - (tram_pos + DEFAULT_TRAM_MIDPOINT)) // Check if our victim is in the active path of the tram. if(!tram.controller_active) @@ -106,7 +106,7 @@ return FALSE if((tram.travel_direction & EAST) && outbound > tram.destination_platform.platform_code) return FALSE - if(approach_distance >= AMBER_THRESHOLD_DEGRADED) + if(approach_distance >= XING_THRESHOLD_AMBER) return FALSE // Finally the interesting part where they ACTUALLY get hit! diff --git a/code/modules/transport/tram/tram_signals.dm b/code/modules/transport/tram/tram_signals.dm index eb648666030..db8aa17ddcb 100644 --- a/code/modules/transport/tram/tram_signals.dm +++ b/code/modules/transport/tram/tram_signals.dm @@ -17,7 +17,7 @@ interaction_flags_machine = INTERACT_MACHINE_OPEN circuit = /obj/item/circuitboard/machine/crossing_signal // pointless if it only takes 2 seconds to cross but updates every 2 seconds - subsystem_type = /datum/controller/subsystem/processing/fastprocess + subsystem_type = /datum/controller/subsystem/processing/transport light_color = LIGHT_COLOR_BABY_BLUE /// green, amber, or red for tram, blue if it's emag, tram missing, etc. var/signal_state = XING_STATE_MALF @@ -40,8 +40,8 @@ * Red: decent chance of getting hit, but if you're quick it's a decent gamble. * Amber: slow people may be in danger. */ - var/amber_distance_threshold = AMBER_THRESHOLD_NORMAL - var/red_distance_threshold = RED_THRESHOLD_NORMAL + var/amber_distance_threshold = XING_THRESHOLD_AMBER + var/red_distance_threshold = XING_THRESHOLD_RED /** Crossing signal subtypes * @@ -203,34 +203,18 @@ sensor_ref = null if(operating_status < TRANSPORT_REMOTE_WARNING) operating_status = TRANSPORT_REMOTE_WARNING - degraded_response() update_appearance() /obj/machinery/transport/crossing_signal/proc/wake_sensor() - if(operating_status > TRANSPORT_REMOTE_WARNING) - degraded_response() - return - var/obj/machinery/transport/guideway_sensor/linked_sensor = sensor_ref?.resolve() if(isnull(linked_sensor)) operating_status = TRANSPORT_REMOTE_WARNING - degraded_response() else if(linked_sensor.trigger_sensor()) operating_status = TRANSPORT_SYSTEM_NORMAL - normal_response() else operating_status = TRANSPORT_REMOTE_WARNING - degraded_response() - -/obj/machinery/transport/crossing_signal/proc/normal_response() - amber_distance_threshold = AMBER_THRESHOLD_NORMAL - red_distance_threshold = RED_THRESHOLD_NORMAL - -/obj/machinery/transport/crossing_signal/proc/degraded_response() - amber_distance_threshold = AMBER_THRESHOLD_DEGRADED - red_distance_threshold = RED_THRESHOLD_DEGRADED /obj/machinery/transport/crossing_signal/proc/clear_uplink() inbound = null @@ -316,20 +300,23 @@ end_processing() /obj/machinery/transport/crossing_signal/process() - + // idle aspect is green or blue depending on the signal status + // degraded signal operating conditions of any type show blue + var/idle_aspect = operating_status == TRANSPORT_SYSTEM_NORMAL ? XING_STATE_GREEN : XING_STATE_MALF var/datum/transport_controller/linear/tram/tram = transport_ref?.resolve() - // Check for stopped states. - if(!tram || !tram.controller_operational || !is_operational || !inbound || !outbound) + // Check for stopped states. Will kill the process since tram starting up will restart process. + if(!tram || !tram.controller_operational || !tram.controller_active || !is_operational || !inbound || !outbound) // Tram missing, we lost power, or something isn't right - // Throw the error message (blue) - set_signal_state(XING_STATE_MALF, force = !is_operational) + // Set idle and stop processing, since the tram won't be moving + set_signal_state(idle_aspect, force = !is_operational) return PROCESS_KILL var/obj/structure/transport/linear/tram_part = tram.return_closest_platform_to(src) + // The structure is gone, so we're done here. if(QDELETED(tram_part)) - set_signal_state(XING_STATE_MALF, force = !is_operational) + set_signal_state(idle_aspect, force = !is_operational) return PROCESS_KILL // Everything will be based on position and travel direction @@ -347,41 +334,32 @@ tram_velocity_sign = tram.travel_direction & EAST ? 1 : -1 // How far away are we? negative if already passed. - var/approach_distance = tram_velocity_sign * (signal_pos - (tram_pos + (DEFAULT_TRAM_LENGTH * 0.5))) - - // Check for stopped state. - // Will kill the process since tram starting up will restart process. - if(!tram.controller_active) - set_signal_state(XING_STATE_GREEN) - return PROCESS_KILL + var/approach_distance = tram_velocity_sign * (signal_pos - (tram_pos + DEFAULT_TRAM_MIDPOINT)) // Check if tram is driving away from us. - if(approach_distance < 0) + if(approach_distance < -abs(DEFAULT_TRAM_MIDPOINT)) // driving away. Green. In fact, in order to reverse, it'll have to stop, so let's go ahead and kill. - set_signal_state(XING_STATE_GREEN) + set_signal_state(idle_aspect) return PROCESS_KILL // Check the tram's terminus station. // INBOUND 1 < 2 < 3 // OUTBOUND 1 > 2 > 3 if(tram.travel_direction & WEST && inbound < tram.destination_platform.platform_code) - set_signal_state(XING_STATE_GREEN) + set_signal_state(idle_aspect) return PROCESS_KILL if(tram.travel_direction & EAST && outbound > tram.destination_platform.platform_code) - set_signal_state(XING_STATE_GREEN) + set_signal_state(idle_aspect) return PROCESS_KILL // Finally the interesting part where it's ACTUALLY approaching if(approach_distance <= red_distance_threshold) - if(operating_status != TRANSPORT_SYSTEM_NORMAL) - set_signal_state(XING_STATE_MALF) - else - set_signal_state(XING_STATE_RED) + set_signal_state(XING_STATE_RED) return - if(approach_distance <= amber_distance_threshold) + if(approach_distance <= amber_distance_threshold && operating_status == TRANSPORT_SYSTEM_NORMAL) set_signal_state(XING_STATE_AMBER) return - set_signal_state(XING_STATE_GREEN) + set_signal_state(idle_aspect) /** * Set the signal state and update appearance.