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

🆑 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
/🆑
This commit is contained in:
lessthanthree
2024-06-06 10:17:04 +01:00
committed by GitHub
parent ac1afe332d
commit 413dc66af1
3 changed files with 25 additions and 48 deletions
+20 -42
View File
@@ -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.