From 748ea0a98f385af807ca791c8d20faf0dc81f65f Mon Sep 17 00:00:00 2001 From: Leshana Date: Thu, 12 Mar 2020 10:30:18 -0400 Subject: [PATCH] Fixes and additional mapping convenience for landmark shuttles. - Improvement to web-shuttle: Don't update docking controller until jump() is completed. - It is now consistent with autodock behavior (for better or worse) - Add shuttle process_state to enable processing of web shuttle autopilot. - Convert Arrivals shuttles to be a subtype of /datum/shuttle/autodock/ferry - Default shuttle landmarks flags to SLANDMARK_FLAG_AUTOSET - Made this safe and backwards compatible by having SLANDMARK_FLAG_AUTOSET not overwrite already specified base_turf or base_area --- code/__defines/misc.dm | 1 + code/modules/shuttles/landmarks.dm | 13 +++++-- code/modules/shuttles/shuttle_arrivals.dm | 47 ++++++++++++++--------- code/modules/shuttles/shuttle_autodock.dm | 2 +- code/modules/shuttles/shuttles_web.dm | 9 ++++- code/modules/shuttles/upgrade_guide.md | 2 +- 6 files changed, 48 insertions(+), 26 deletions(-) diff --git a/code/__defines/misc.dm b/code/__defines/misc.dm index ceaeda8c48..b96c2cca84 100644 --- a/code/__defines/misc.dm +++ b/code/__defines/misc.dm @@ -106,6 +106,7 @@ #define FORCE_LAUNCH 2 #define WAIT_ARRIVE 3 #define WAIT_FINISH 4 +#define DO_AUTOPILOT 5 // Setting this much higher than 1024 could allow spammers to DOS the server easily. #define MAX_MESSAGE_LEN 1024 diff --git a/code/modules/shuttles/landmarks.dm b/code/modules/shuttles/landmarks.dm index b02c5813ba..99761dfe25 100644 --- a/code/modules/shuttles/landmarks.dm +++ b/code/modules/shuttles/landmarks.dm @@ -7,6 +7,7 @@ unacidable = 1 simulated = 0 invisibility = 101 + flags = SLANDMARK_FLAG_AUTOSET // We generally want to use current area/turf as base. //ID of the landmark var/landmark_tag @@ -22,17 +23,23 @@ var/turf/base_turf //Name of the shuttle, null for generic waypoint var/shuttle_restricted - // var/flags = 0 - Already defined on /atom ? Is it being used for anything? Can we reuse it safely? /obj/effect/shuttle_landmark/Initialize() . = ..() if(docking_controller) . = INITIALIZE_HINT_LATELOAD + // Even if this flag is set, hardcoded values take precedence. if(flags & SLANDMARK_FLAG_AUTOSET) - base_area = get_area(src) + if(ispath(base_area)) + var/area/A = locate(base_area) + if(!istype(A)) + CRASH("Shuttle landmark \"[landmark_tag]\" couldn't locate area [base_area].") + base_area = A + else + base_area = get_area(src) var/turf/T = get_turf(src) - if(T) + if(T && !base_turf) base_turf = T.type else base_area = locate(base_area || world.area) diff --git a/code/modules/shuttles/shuttle_arrivals.dm b/code/modules/shuttles/shuttle_arrivals.dm index 115d4476d2..a2d71c3fcc 100644 --- a/code/modules/shuttles/shuttle_arrivals.dm +++ b/code/modules/shuttles/shuttle_arrivals.dm @@ -1,15 +1,18 @@ // The new arrivals shuttle. -/datum/shuttle/ferry/arrivals +/datum/shuttle/autodock/ferry/arrivals + category = /datum/shuttle/autodock/ferry/arrivals + name = "Arrivals" - location = 1 + location = FERRY_LOCATION_OFFSITE warmup_time = 25 // Warmup takes 5 seconds, so 30 total. always_process = TRUE var/launch_delay = 3 - area_offsite = /area/shuttle/arrival/pre_game // not really 'pre game' but this area is already defined and unused - area_station = /area/shuttle/arrival/station - docking_controller_tag = "arrivals_shuttle" - dock_target_station = "arrivals_dock" + // Maps must implement their own subtype for their arrivals shuttle, and define at least: + // shuttle_area + // landmark_station (Which should define its dock target) + // landmark_offsite + // docking_controller_tag // For debugging. /obj/machinery/computer/shuttle_control/arrivals @@ -18,36 +21,42 @@ shuttle_tag = "Arrivals" // Unlike most shuttles, the arrivals shuttle is completely automated, so we need to put some additional code here. - +// Process the arrivals shuttle even when idle. +/obj/machinery/computer/shuttle_control/arrivals/process() + var/datum/shuttle/autodock/ferry/arrivals/shuttle = SSshuttles.shuttles[shuttle_tag] + if(shuttle && shuttle.process_state == IDLE_STATE) + shuttle.process() + ..() // This proc checks if anyone is on the shuttle. -/datum/shuttle/ferry/arrivals/proc/check_for_passengers(area/A) - for(var/mob/living/L in A) - return TRUE +/datum/shuttle/autodock/ferry/arrivals/proc/check_for_passengers() + for(var/area/A in shuttle_area) + for(var/mob/living/L in A) + return TRUE return FALSE // This is to stop the shuttle if someone tries to stow away when its leaving. -/datum/shuttle/ferry/arrivals/post_warmup_checks() +/datum/shuttle/autodock/ferry/arrivals/post_warmup_checks() if(!location) // If we're at station. - if(check_for_passengers(area_station)) + if(check_for_passengers()) return FALSE return TRUE -/datum/shuttle/ferry/arrivals/process() +/datum/shuttle/autodock/ferry/arrivals/process() if(process_state == IDLE_STATE) if(location) // If we're off-station (space). - if(check_for_passengers(area_offsite)) // No point arriving with an empty shuttle. + if(check_for_passengers()) // No point arriving with an empty shuttle. warmup_time = initial(warmup_time) launch() - message_passengers(area_offsite, "Arriving at [using_map.station_name] in thirty seconds...") + message_passengers("Arriving at [using_map.station_name] in thirty seconds...") spawn(10 SECONDS) - message_passengers(area_offsite, "Arriving at [using_map.station_name] in twenty seconds.") + message_passengers("Arriving at [using_map.station_name] in twenty seconds.") spawn(10 SECONDS) - message_passengers(area_offsite, "Arriving at [using_map.station_name] in ten seconds. Please buckle up.") + message_passengers("Arriving at [using_map.station_name] in ten seconds. Please buckle up.") else // We are at the station. - if(!check_for_passengers(area_station)) // Don't leave with anyone. + if(!check_for_passengers()) // Don't leave with anyone. if(launch_delay) // Give some time to get on the docks so people don't get trapped inbetween the dock airlocks. launch_delay-- else @@ -58,7 +67,7 @@ ..() // Do everything else /* -/datum/shuttle/ferry/arrivals/current_dock_target() +/datum/shuttle/autodock/ferry/arrivals/current_dock_target() if(location) // If we're off station. return null // Nothing to dock to in space. return ..() diff --git a/code/modules/shuttles/shuttle_autodock.dm b/code/modules/shuttles/shuttle_autodock.dm index d8ebc9c020..b9b1801205 100644 --- a/code/modules/shuttles/shuttle_autodock.dm +++ b/code/modules/shuttles/shuttle_autodock.dm @@ -217,4 +217,4 @@ return //do nothing for now /obj/effect/shuttle_landmark/transit - flags = SLANDMARK_FLAG_ZERO_G + flags = SLANDMARK_FLAG_ZERO_G|SLANDMARK_FLAG_AUTOSET diff --git a/code/modules/shuttles/shuttles_web.dm b/code/modules/shuttles/shuttles_web.dm index 6698584270..968911ee5c 100644 --- a/code/modules/shuttles/shuttles_web.dm +++ b/code/modules/shuttles/shuttles_web.dm @@ -22,6 +22,7 @@ build_destinations() if(autopilot) flags |= SHUTTLE_FLAGS_PROCESS + process_state = DO_AUTOPILOT if(autopilot_first_delay) autopilot_delay = autopilot_first_delay if(!visible_name) @@ -43,8 +44,6 @@ /datum/shuttle/autodock/web_shuttle/perform_shuttle_move() ..() last_move = world.time - active_docking_controller = current_location.docking_controller - update_docking_target(current_location) /datum/shuttle/autodock/web_shuttle/short_jump() . = ..() @@ -61,6 +60,8 @@ /datum/shuttle/autodock/web_shuttle/on_shuttle_arrival() . = ..() + active_docking_controller = current_location.docking_controller + update_docking_target(current_location) web_master.on_shuttle_arrival() update_helmets() @@ -131,11 +132,15 @@ autopilot = TRUE autopilot_delay = initial(autopilot_delay) shuttle_controller.process_shuttles |= src + if(process_state == IDLE_STATE) + process_state = DO_AUTOPILOT else if(!autopilot) return autopilot = FALSE shuttle_controller.process_shuttles -= src + if (process_state == DO_AUTOPILOT) + process_state = initial(process_state) /datum/shuttle/autodock/web_shuttle/proc/autopilot_say(message) // Makes the autopilot 'talk' to the passengers. var/padded_message = "shuttle autopilot states, \"[message]\"" diff --git a/code/modules/shuttles/upgrade_guide.md b/code/modules/shuttles/upgrade_guide.md index 01326e5f21..7c2c73f422 100644 --- a/code/modules/shuttles/upgrade_guide.md +++ b/code/modules/shuttles/upgrade_guide.md @@ -20,7 +20,7 @@ Shuttle destinations are represented by `/obj/effect/shuttle_landmark` objects o * `base_area` - Type path of the `/area` that should be here when a shuttle is *not* present. * `base_turf` - Type path of the `/turf` that should be here when a shuttle is *not* present. * `shuttle_restricted` - If not null, only the named shuttle is allowed to use this landmark. (TODO: Overmap functionality) -* `flags` - Bitfield - defaults to zero, can be any combination of: +* `flags` - Bitfield - defaults to `SLANDMARK_FLAG_AUTOSET`, can be any combination of: * `SLANDMARK_FLAG_AUTOSET` (1) - If set, will initialize base_area and base_turf to same as where it was spawned at. * `SLANDMARK_FLAG_ZERO_G` (2) - If set, Zero-G shuttles moved here will lose gravity unless the area has ambient gravity. * `special_dock_targets` - Used to configure shuttles with multiple docking controllers on the shuttle. Map of shuttle `name` -> `id_tag` of the docking controller it should use for this landmark. (Think of a shuttle with airlocks on both sides, each with their own controller. This would tell it which side to use.)