Shuttle console refactoring

Also adjusted the way undocking signals were used.
This commit is contained in:
mwerezak
2014-06-11 19:42:59 -04:00
parent acec01fb14
commit 232e50e415
7 changed files with 216 additions and 176 deletions
+25 -54
View File
@@ -8,23 +8,16 @@
var/global/list/shuttles
/datum/shuttle
var/location = 0 //0 = at area_station, 1 = at area_offsite
var/warmup_time = 0
var/moving_status = SHUTTLE_IDLE //prevents people from doing things they shouldn't when the shuttle is in transit
var/in_use = 0 //this mutex ensures that only one console can be doing things with the shuttle at a time.
var/area_station
var/area_offsite
var/docking_controller_tag //tag of the controller used to coordinate docking
var/datum/computer/file/embedded_program/docking/docking_controller //the controller itself
//TODO: change location to a string and use a mapping for area and dock targets.
var/dock_target_station
var/dock_target_offsite
/datum/shuttle/proc/short_jump(var/datum/shuttle/shuttle,var/area/origin,var/area/destination)
/datum/shuttle/proc/short_jump(var/area/origin,var/area/destination)
if(moving_status != SHUTTLE_IDLE) return
//it would be cool to play a sound here
moving_status = SHUTTLE_WARMUP
spawn(warmup_time*10)
if (moving_status == SHUTTLE_IDLE)
@@ -33,11 +26,11 @@ var/global/list/shuttles
move(origin, destination)
moving_status = SHUTTLE_IDLE
/datum/shuttle/proc/long_jump(var/shuttle_tag,var/area/departing,var/area/destination,var/area/interim,var/travel_time)
/datum/shuttle/proc/long_jump(var/area/departing,var/area/destination,var/area/interim,var/travel_time)
if(moving_status != SHUTTLE_IDLE) return
//it would be cool to play a sound here
moving_status = SHUTTLE_WARMUP
spawn(warmup_time*10)
if (moving_status == SHUTTLE_IDLE)
return //someone cancelled the launch
@@ -68,40 +61,22 @@ var/global/list/shuttles
docking_controller.initiate_undocking()
/datum/shuttle/proc/current_dock_target()
var/dock_target
if (!location) //station
dock_target = dock_target_station
else
dock_target = dock_target_offsite
return dock_target
return null
/datum/shuttle/proc/skip_docking_checks()
if (!docking_controller || !current_dock_target())
return 1 //shuttles without docking controllers or at locations without docking ports act like old-style shuttles
return 0
//just moves the shuttle from A to B, if it can be moved
/datum/shuttle/proc/move(var/area/origin,var/area/destination)
//world << "move_shuttle() called for [shuttle_tag] leaving [origin] en route to [destination]."
if(isnull(location))
return
var/area/area_going_to
if(destination)
//world << "Using supplied destination [destination]."
area_going_to = destination
else
//world << "Using controller value [(cur_location[shuttle_tag] == 1 ? areas_station[shuttle_tag] : areas_offsite[shuttle_tag])]."
area_going_to = (location == 1 ? area_station : area_offsite)
var/area/area_coming_from
if(origin)
//world << "Using supplied origin [origin]."
area_coming_from = origin
else
//world << "Using controller value [(cur_location[shuttle_tag] == 1 ? areas_offsite[shuttle_tag] : areas_station[shuttle_tag])]."
area_coming_from = (location == 1 ? area_offsite : area_station)
//world << "area_coming_from: [area_coming_from]"
//world << "area_going_to: [area_going_to]"
//world << "destination: [destination]"
if(area_coming_from == area_going_to)
if(origin == destination)
//world << "cancelling move, shuttle will overlap."
return
@@ -110,7 +85,7 @@ var/global/list/shuttles
var/list/dstturfs = list()
var/throwy = world.maxy
for(var/turf/T in area_going_to)
for(var/turf/T in destination)
dstturfs += T
if(T.y < throwy)
throwy = T.y
@@ -122,17 +97,15 @@ var/global/list/shuttles
if(istype(T, /turf/simulated))
del(T)
for(var/mob/living/carbon/bug in area_going_to)
for(var/mob/living/carbon/bug in destination)
bug.gib()
for(var/mob/living/simple_animal/pest in area_going_to)
for(var/mob/living/simple_animal/pest in destination)
pest.gib()
area_coming_from.move_contents_to(area_going_to)
origin.move_contents_to(destination)
location = !location //this needs to change.
for(var/mob/M in area_going_to)
for(var/mob/M in destination)
if(M.client)
spawn(0)
if(M.buckled)
@@ -152,48 +125,48 @@ var/global/list/shuttles
/proc/setup_shuttles()
shuttles = list()
var/datum/shuttle/shuttle
var/datum/shuttle/ferry/shuttle
//Supply and escape shuttles.
shuttle = new/datum/shuttle()
shuttle = new()
shuttle.location = 1
shuttle.area_offsite = locate(/area/supply/dock)
shuttle.area_station = locate(/area/supply/station)
shuttles["Supply"] = shuttle
// Admin shuttles.
shuttle = new/datum/shuttle()
shuttle = new()
shuttle.location = 1
shuttle.area_offsite = locate(/area/shuttle/transport1/centcom)
shuttle.area_station = locate(/area/shuttle/transport1/station)
shuttles["Centcom"] = shuttle
shuttle = new/datum/shuttle()
shuttle = new()
shuttle.location = 1
shuttle.area_offsite = locate(/area/shuttle/administration/centcom)
shuttle.area_station = locate(/area/shuttle/administration/station)
shuttles["Administration"] = shuttle
shuttle = new/datum/shuttle()
shuttle = new()
shuttle.area_offsite = locate(/area/shuttle/alien/base)
shuttle.area_station = locate(/area/shuttle/alien/mine)
shuttles["Alien"] = shuttle
// Public shuttles
shuttle = new/datum/shuttle()
shuttle = new()
shuttle.location = 1
shuttle.warmup_time = 10
shuttle.area_offsite = locate(/area/shuttle/constructionsite/site)
shuttle.area_station = locate(/area/shuttle/constructionsite/station)
shuttles["Engineering"] = shuttle
shuttle = new/datum/shuttle()
shuttle = new()
shuttle.warmup_time = 10
shuttle.area_offsite = locate(/area/shuttle/mining/outpost)
shuttle.area_station = locate(/area/shuttle/mining/station)
shuttles["Mining"] = shuttle
shuttle = new/datum/shuttle()
shuttle = new()
shuttle.warmup_time = 10
shuttle.area_offsite = locate(/area/shuttle/research/outpost)
shuttle.area_station = locate(/area/shuttle/research/station)
@@ -219,7 +192,6 @@ var/global/list/shuttles
VS.departure_message = "Your guests are pulling away, Exodus - moving too fast for us to draw a bead on them. Looks like they're heading out of the system at a rapid clip."
VS.interim = /area/vox_station/transit
VS.location = 1
VS.warmup_time = 10
shuttles["Vox Skipjack"] = VS
@@ -243,7 +215,6 @@ var/global/list/shuttles
MS.departure_message = "Your visitors are on their way out of the system, Exodus, burning delta-v like it's nothing. Good riddance."
MS.interim = /area/syndicate_station/transit
MS.location = 1
MS.warmup_time = 10
shuttles["Syndicate"] = MS
+154 -82
View File
@@ -4,6 +4,132 @@
#define WAIT_FINISH 3
/datum/shuttle/ferry
var/location = 0 //0 = at area_station, 1 = at area_offsite
var/process_state = IDLE_STATE
//this mutex ensures that only one console is processing the shuttle's controls at a time
var/obj/machinery/computer/shuttle_control/in_use = null
var/area_station
var/area_offsite
//TODO: change location to a string and use a mapping for area and dock targets.
var/dock_target_station
var/dock_target_offsite
/datum/shuttle/ferry/short_jump(var/area/origin,var/area/destination)
if(isnull(location))
return
if(!destination)
destination = (location == 1 ? area_station : area_offsite)
if(!origin)
origin = (location == 1 ? area_offsite : area_station)
if (docking_controller)
docking_controller.force_undock()
..(origin, destination)
/datum/shuttle/ferry/long_jump(var/area/departing,var/area/destination,var/area/interim,var/travel_time)
if(isnull(location))
return
if(!destination)
destination = (location == 1 ? area_station : area_offsite)
if(!departing)
departing = (location == 1 ? area_offsite : area_station)
if (docking_controller)
docking_controller.force_undock()
..(departing, destination, interim, travel_time)
/datum/shuttle/ferry/move(var/area/origin,var/area/destination)
..(origin, destination)
location = !location
/datum/shuttle/ferry/proc/process_shuttle()
switch(process_state)
if (WAIT_LAUNCH)
if (skip_docking_checks() || docking_controller.can_launch())
//once you have a transition area, making ferry shuttles have a transition would merely requre replacing this with
//if (transition_area) long_jump(...)
//else short_jump ()
short_jump()
process_state = WAIT_ARRIVE
if (WAIT_ARRIVE)
if (moving_status == SHUTTLE_IDLE)
dock()
process_state = WAIT_FINISH
if (WAIT_FINISH)
if (skip_docking_checks() || docking_controller.docked())
process_state = IDLE_STATE
in_use = null //release lock
/datum/shuttle/ferry/current_dock_target()
var/dock_target
if (!location) //station
dock_target = dock_target_station
else
dock_target = dock_target_offsite
return dock_target
/datum/shuttle/ferry/proc/launch(var/obj/machinery/computer/shuttle_control/user)
if (!can_launch()) return
in_use = user //obtain an exclusive lock on the shuttle
process_state = WAIT_LAUNCH
undock()
/datum/shuttle/ferry/proc/force_launch(var/obj/machinery/computer/shuttle_control/user)
if (!can_force()) return
in_use = user //obtain an exclusive lock on the shuttle
short_jump()
process_state = WAIT_ARRIVE
/datum/shuttle/ferry/proc/cancel_launch()
if (!can_cancel()) return
moving_status = SHUTTLE_IDLE
process_state = WAIT_FINISH
if (docking_controller && !docking_controller.undocked())
docking_controller.force_undock()
spawn(10)
dock()
return
/datum/shuttle/ferry/proc/can_launch()
if (moving_status != SHUTTLE_IDLE)
return 0
if (in_use && !skip_docking_checks())
return 0
return 1
/datum/shuttle/ferry/proc/can_force()
if (moving_status != SHUTTLE_IDLE && process_state == WAIT_LAUNCH)
return 0
return 1
/datum/shuttle/ferry/proc/can_cancel()
if (moving_status == SHUTTLE_WARMUP || process_state == WAIT_LAUNCH)
return 1
return 0
/*
I dont really like how much this manipulates shuttle it's docking controller, as it makes this code
depend a lot on their current implementation, and also having var/datum/shuttle/shuttle = shuttles[shuttle_tag]
@@ -19,90 +145,29 @@
var/shuttle_tag // Used to coordinate data in shuttle controller.
var/hacked = 0 // Has been emagged, no access restrictions.
var/process_state = IDLE_STATE
var/launch_override = 0
/obj/machinery/computer/shuttle_control/proc/launch_shuttle()
if (!can_launch()) return
var/datum/shuttle/shuttle = shuttles[shuttle_tag]
shuttle.in_use = 1 //obtain an exclusive lock on the shuttle
process_state = WAIT_LAUNCH
shuttle.undock()
/obj/machinery/computer/shuttle_control/proc/cancel_launch()
if (!can_cancel()) return
var/datum/shuttle/shuttle = shuttles[shuttle_tag]
shuttle.moving_status = SHUTTLE_IDLE
process_state = WAIT_FINISH
if (shuttle.docking_controller && !shuttle.docking_controller.undocked())
shuttle.docking_controller.force_undock()
shuttle.dock()
shuttle.in_use = 0
return
/obj/machinery/computer/shuttle_control/proc/can_launch()
var/datum/shuttle/shuttle = shuttles[shuttle_tag]
if (shuttle.moving_status != SHUTTLE_IDLE)
return 0
if (shuttle.in_use && !skip_checks())
return 0
return 1
/obj/machinery/computer/shuttle_control/proc/can_cancel()
var/datum/shuttle/shuttle = shuttles[shuttle_tag]
if (shuttle.moving_status == SHUTTLE_WARMUP || process_state == WAIT_LAUNCH)
return 1
return 0
//TODO move this stuff into the shuttle datum itself, instead of manipulating the shuttle's members
/obj/machinery/computer/shuttle_control/process()
if (!shuttles || !(shuttle_tag in shuttles))
return
var/datum/shuttle/shuttle = shuttles[shuttle_tag]
switch(process_state)
if (WAIT_LAUNCH)
if (skip_checks() || shuttle.docking_controller.can_launch())
shuttle.short_jump()
if (shuttle.docking_controller && !shuttle.docking_controller.undocked())
shuttle.docking_controller.force_undock()
process_state = WAIT_ARRIVE
if (WAIT_ARRIVE)
if (shuttle.moving_status == SHUTTLE_IDLE)
shuttle.dock()
process_state = WAIT_FINISH
if (WAIT_FINISH)
if (skip_checks() || shuttle.docking_controller.docked())
process_state = IDLE_STATE
shuttle.in_use = 0 //release lock
/obj/machinery/computer/shuttle_control/proc/skip_checks()
var/datum/shuttle/shuttle = shuttles[shuttle_tag]
if (!shuttle.docking_controller || !shuttle.current_dock_target())
return 1 //shuttles without docking controllers or at locations without docking ports act like old-style shuttles
return 0
var/datum/shuttle/ferry/shuttle = shuttles[shuttle_tag]
if (!istype(shuttle))
return
if (shuttle.in_use == src)
shuttle.process_shuttle()
/obj/machinery/computer/shuttle_control/Del()
var/datum/shuttle/shuttle = shuttles[shuttle_tag]
var/datum/shuttle/ferry/shuttle = shuttles[shuttle_tag]
if (!istype(shuttle))
return
if (process_state != IDLE_STATE)
shuttle.in_use = 0 //shuttle may not dock properly if this gets deleted while in transit, but its not a big deal
if (shuttle.in_use == src)
shuttle.in_use = null //shuttle may not dock properly if this gets deleted while in transit, but its not a big deal
/obj/machinery/computer/shuttle_control/attack_hand(user as mob)
if(..(user))
@@ -113,7 +178,9 @@
/obj/machinery/computer/shuttle_control/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null)
var/data[0]
var/datum/shuttle/shuttle = shuttles[shuttle_tag]
var/datum/shuttle/ferry/shuttle = shuttles[shuttle_tag]
if (!istype(shuttle))
return
var/shuttle_state
switch(shuttle.moving_status)
@@ -122,7 +189,7 @@
if(SHUTTLE_INTRANSIT) shuttle_state = "in_transit"
var/shuttle_status
switch (process_state)
switch (shuttle.process_state)
if(IDLE_STATE)
if (shuttle.in_use)
shuttle_status = "Busy."
@@ -142,10 +209,10 @@
"shuttle_state" = shuttle_state,
"has_docking" = shuttle.docking_controller? 1 : 0,
"docking_status" = shuttle.docking_controller? shuttle.docking_controller.get_docking_status() : null,
"override_enabled" = shuttle.docking_controller? shuttle.docking_controller.override_enabled : null,
"can_launch" = can_launch(),
"can_cancel" = can_cancel(),
"can_override" = can_override(),
"docking_override" = shuttle.docking_controller? shuttle.docking_controller.override_enabled : null,
"can_launch" = shuttle.can_launch(),
"can_cancel" = shuttle.can_cancel(),
"can_force" = shuttle.can_force(),
)
ui = nanomanager.try_update_ui(user, src, ui_key, ui, data)
@@ -164,11 +231,16 @@
usr.set_machine(src)
src.add_fingerprint(usr)
var/datum/shuttle/ferry/shuttle = shuttles[shuttle_tag]
if (!istype(shuttle))
return
if(href_list["move"])
launch_shuttle()
shuttle.launch(src)
if(href_list["force"])
shuttle.force_launch(src)
else if(href_list["cancel"])
cancel_launch()
shuttle.cancel_launch()
/obj/machinery/computer/shuttle_control/attackby(obj/item/weapon/W as obj, mob/user as mob)