Skip to content

Commit

Permalink
[MIRROR] Tram crossing signal logic fixes [MDB IGNORE] (#2874)
Browse files Browse the repository at this point in the history
* Tram crossing signal logic fixes

* Update transport.dm

---------

Co-authored-by: lessthanthree <[email protected]>
Co-authored-by: SomeRandomOwl <[email protected]>
  • Loading branch information
3 people authored and StealsThePRs committed Jun 7, 2024
1 parent 7acf9e9 commit a867d2d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 48 deletions.
7 changes: 3 additions & 4 deletions code/__DEFINES/transport.dm
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ DEFINE_BITFIELD(request_flags, list(
#define XING_STATE_RED 2
#define XING_STATE_MALF 3

#define AMBER_THRESHOLD_NORMAL 60 // NOVA EDIT CHANGE - RUN/WALK SPEED
#define RED_THRESHOLD_NORMAL 37 // NOVA EDIT CHANGE - RUN/WALK SPEED
#define AMBER_THRESHOLD_DEGRADED 45 // NOVA EDIT CHANGE - RUN/WALK SPEED
#define RED_THRESHOLD_DEGRADED 33 // NOVA EDIT CHANGE - RUN/WALK SPEED
#define XING_THRESHOLD_AMBER 60 // NOVA EDIT CHANGE - RUN/WALK SPEED | Original: #define XING_THRESHOLD_AMBER 45
#define XING_THRESHOLD_RED 37 // NOVA EDIT CHANGE - RUN/WALK SPEED | Original: 27

#define DEFAULT_TRAM_LENGTH 10
#define DEFAULT_TRAM_MIDPOINT 5

// Tram machinery subtype
#define TRANSPORT_SYSTEM_NORMAL 0
Expand Down
4 changes: 2 additions & 2 deletions code/datums/components/energized.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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!
Expand Down
62 changes: 20 additions & 42 deletions code/modules/transport/tram/tram_signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit a867d2d

Please sign in to comment.