From 62d1f4bdfc5cc6abb84996f857cbeb744761db89 Mon Sep 17 00:00:00 2001 From: Spookerton Date: Fri, 28 Jun 2024 22:29:37 +0100 Subject: [PATCH] fix lifts gibbing moving upward, refactoring also --- code/modules/turbolift/turbolift.dm | 208 ++++++++++++++-------------- 1 file changed, 106 insertions(+), 102 deletions(-) diff --git a/code/modules/turbolift/turbolift.dm b/code/modules/turbolift/turbolift.dm index 9c12562c799c7..54d4e2637a6bf 100644 --- a/code/modules/turbolift/turbolift.dm +++ b/code/modules/turbolift/turbolift.dm @@ -1,149 +1,153 @@ -// Lift master datum. One per turbolift. /datum/turbolift - var/datum/turbolift_floor/target_floor // Where are we going? - var/datum/turbolift_floor/current_floor // Where is the lift currently? - var/list/doors = list() // Doors inside the lift structure. - var/list/queued_floors = list() // Where are we moving to next? - var/list/floors = list() // All floors in this system. - var/move_delay = 3 SECONDS // Time between floor changes. - var/floor_wait_delay = 9 SECONDS // Time to wait at floor stops. - var/obj/structure/lift/panel/control_panel_interior // Lift control panel. - var/doors_closing = 0 // Whether doors are in the process of closing - var/moving_upwards - var/busy_state // Used for controller processing. - var/next_process + var/const/LIFT_MOVING = 1 -/datum/turbolift/proc/emergency_stop() - queued_floors.Cut() - target_floor = null - open_doors() + var/const/LIFT_WAITING_A = 2 -/datum/turbolift/proc/doors_are_open(datum/turbolift_floor/use_floor = current_floor) - for(var/obj/machinery/door/airlock/door in (use_floor ? (doors + use_floor.doors) : doors)) - if(!door.density) - return 1 - return 0 + var/const/LIFT_WAITING_B = 3 -/datum/turbolift/proc/open_doors(datum/turbolift_floor/use_floor = current_floor) - for(var/obj/machinery/door/airlock/door in (use_floor ? (doors + use_floor.doors) : doors)) - door.command("open") - return + // One of the LIFT_* states above. Indicates what the lift is currently doing + var/busy_state -/datum/turbolift/proc/close_doors(datum/turbolift_floor/use_floor = current_floor) - for(var/obj/machinery/door/airlock/door in (use_floor ? (doors + use_floor.doors) : doors)) - door.command("close") - return + /// Where are we going? + var/datum/turbolift_floor/target_floor + + /// Where is the lift currently? + var/datum/turbolift_floor/current_floor + + /// Doors inside the lift structure + var/list/doors = list() + + /// Where are we moving to next? + var/list/queued_floors = list() + + /// All floors in this system + var/list/floors = list() + + /// Time between floor changes + var/move_delay = 3 SECONDS + + /// Time to wait at floor stops + var/floor_wait_delay = 9 SECONDS + + /// Lift control panel + var/obj/structure/lift/panel/control_panel_interior + + /// Whether doors are in the process of closing + var/doors_closing = FALSE + + /// ... + var/moving_upwards + + /// ... + var/next_process -#define LIFT_MOVING 1 -#define LIFT_WAITING_A 2 -#define LIFT_WAITING_B 3 /datum/turbolift/Process() - if(world.time < next_process) + if (world.time < next_process) return - switch(busy_state) - if(LIFT_MOVING) - if(!do_move()) + switch (busy_state) + if (LIFT_MOVING) + if (!do_move()) queued_floors.Cut() return PROCESS_KILL - else if(!next_process) + if (!next_process) next_process = world.time + move_delay - if(LIFT_WAITING_A) + if (LIFT_WAITING_A) var/area/turbolift/origin = locate(current_floor.area_ref) control_panel_interior.visible_message("The elevator announces, \"[origin.lift_announce_str]\"") next_process = world.time + floor_wait_delay busy_state = LIFT_WAITING_B - if(LIFT_WAITING_B) - if(length(queued_floors)) - busy_state = LIFT_MOVING - else + if (LIFT_WAITING_B) + if (!length(queued_floors)) busy_state = null return PROCESS_KILL + busy_state = LIFT_MOVING -/datum/turbolift/proc/do_move() - next_process = null - var/current_floor_index = floors.Find(current_floor) +/datum/turbolift/proc/emergency_stop() + queued_floors.Cut() + target_floor = null + open_doors() - if(!target_floor) - if(!queued_floors || !length(queued_floors)) - return 0 - target_floor = queued_floors[1] - queued_floors -= target_floor - if(current_floor_index < floors.Find(target_floor)) - moving_upwards = 1 - else - moving_upwards = 0 - if(doors_are_open()) - if(!doors_closing) - close_doors() - doors_closing = 1 - return 1 - else // We failed to close the doors - probably, someone is blocking them; stop trying to move - doors_closing = 0 - open_doors() - control_panel_interior.audible_message("\The [current_floor.ext_panel] buzzes loudly.") - playsound(control_panel_interior.loc, "sound/machines/buzz-two.ogg", 50, 1) - return 0 +/datum/turbolift/proc/doors_are_open(datum/turbolift_floor/use_floor = current_floor) + for (var/obj/machinery/door/airlock/door in doors + use_floor?.doors) + if (!door.density) + return TRUE + return FALSE - doors_closing = 0 // The doors weren't open, so they are done closing - var/area/turbolift/origin = locate(current_floor.area_ref) +/datum/turbolift/proc/open_doors(datum/turbolift_floor/use_floor = current_floor) + for (var/obj/machinery/door/airlock/door in doors + use_floor?.doors) + door.command("open") - if(target_floor == current_floor) - playsound(control_panel_interior.loc, origin.arrival_sound, 50, 1) +/datum/turbolift/proc/close_doors(datum/turbolift_floor/use_floor = current_floor) + for (var/obj/machinery/door/airlock/door in doors + use_floor?.doors) + door.command("close") + + +/datum/turbolift/proc/do_move() + next_process = null + var/current_floor_index = floors.Find(current_floor) + if (!target_floor) + if (!queued_floors || !length(queued_floors)) + return FALSE + target_floor = queued_floors[1] + queued_floors -= target_floor + moving_upwards = current_floor_index < floors.Find(target_floor) + if (doors_are_open()) + if (!doors_closing) + close_doors() + doors_closing = TRUE + return TRUE + doors_closing = FALSE + open_doors() + control_panel_interior.audible_message("\The [current_floor.ext_panel] buzzes loudly.") + playsound(control_panel_interior, "sound/machines/buzz-two.ogg", 50, TRUE) + return FALSE + doors_closing = FALSE + var/area/turbolift/origin = locate(current_floor.area_ref) + if (target_floor == current_floor) + playsound(control_panel_interior, origin.arrival_sound, 50, TRUE) target_floor.arrived(src) target_floor = null - next_process = world.time + 2 SECONDS busy_state = LIFT_WAITING_A - return 1 - - // Work out where we're headed. + return TRUE var/datum/turbolift_floor/next_floor - if(moving_upwards) - next_floor = floors[current_floor_index+1] + if (moving_upwards) + next_floor = floors[current_floor_index + 1] else - next_floor = floors[current_floor_index-1] - + next_floor = floors[current_floor_index - 1] var/area/turbolift/destination = locate(next_floor.area_ref) - - if(!istype(origin) || !istype(destination) || (origin == destination)) - return 0 - - for(var/turf/T in destination) - for(var/atom/movable/AM in T) - if(istype(AM, /mob/living)) - var/mob/living/M = AM - M.gib() - else if(AM.simulated) - qdel(AM) - + if (!istype(origin) || !istype(destination) || (origin == destination)) + return FALSE + if (!moving_upwards) + for (var/turf/turf in destination) + for (var/atom/movable/movable in turf) + if (istype(movable, /mob/living)) + var/mob/living/living = movable + living.gib() + else if (movable.simulated) + qdel(movable) origin.move_contents_to(destination) - - if((locate(/obj/machinery/power) in destination) || (locate(/obj/structure/cable) in destination)) + if ((locate(/obj/machinery/power) in destination) || (locate(/obj/structure/cable) in destination)) SSmachines.makepowernets() - current_floor = next_floor control_panel_interior.visible_message("The elevator [moving_upwards ? "rises" : "descends"] smoothly.") + return TRUE - return 1 /datum/turbolift/proc/queue_move_to(datum/turbolift_floor/floor) - if(!floor || !(floor in floors) || (floor in queued_floors)) - return // STOP PRESSING THE BUTTON. + if (!floor || !(floor in floors) || (floor in queued_floors)) + return floor.pending_move(src) queued_floors |= floor busy_state = LIFT_MOVING START_PROCESSING(SSprocessing, src) -// TODO: dummy machine ('lift mechanism') in powered area for functionality/blackout checks. -/datum/turbolift/proc/is_functional() - return 1 -#undef LIFT_MOVING -#undef LIFT_WAITING_A -#undef LIFT_WAITING_B +/datum/turbolift/proc/is_functional() + return TRUE