Skip to content

Commit

Permalink
Now working, let's do this
Browse files Browse the repository at this point in the history
  • Loading branch information
coiax committed Jul 1, 2016
1 parent 0f67b84 commit 1ad915b
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 19 deletions.
2 changes: 2 additions & 0 deletions code/__DEFINES/shuttles.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@
#define TRANSIT_REQUEST 1
#define TRANSIT_READY 2
#define TRANSIT_FULL 3

#define SHUTTLE_TRANSIT_BORDER 8
87 changes: 71 additions & 16 deletions code/controllers/subsystem/shuttles.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var/datum/subsystem/shuttle/SSshuttle

var/list/turf/transit_turfs = list()
var/list/transit_requesters = list()
var/clear_transit = FALSE

//emergency shuttle stuff
var/obj/docking_port/mobile/emergency/emergency
Expand Down Expand Up @@ -66,6 +67,7 @@ var/datum/subsystem/shuttle/SSshuttle
var/turf/B = get_turf(transit_markers[2])
for(var/i in block(A, B))
var/turf/T = i
T.ChangeTurf(/turf/open/space)
transit_turfs += T
T.flags |= UNUSED_TRANSIT_TURF
#ifdef HIGHLIGHT_DYNAMIC_TRANSIT
Expand All @@ -75,10 +77,16 @@ var/datum/subsystem/shuttle/SSshuttle
T.color = "#00ffff"
#endif

world.log << "[transit_turfs.len] transit turfs registered"
//world.log << "[transit_turfs.len] transit turfs registered"

/datum/subsystem/shuttle/fire()
if(transit_requesters.len)
if(clear_transit)
transit_requesters.Cut()
for(var/i in transit)
qdel(i, force=TRUE)
setup_transit_zone()
clear_transit = FALSE
else if(transit_requesters.len)
var/requester = popleft(transit_requesters)
var/success = generate_transit_dock(requester)
if(!success) // BACK OF THE QUEUE
Expand Down Expand Up @@ -254,20 +262,25 @@ var/datum/subsystem/shuttle/SSshuttle
// Because of shuttle rotation, the "width" of the shuttle is not
// always x.
var/travel_dir = M.preferred_direction
//var/coords = M.return_coords(0, 0, travel_dir)
var/dock_angle = dir2angle(M.preferred_direction) + M.port_angle + 180
var/dock_dir = angle2dir(dock_angle)

var/transit_width = 14
var/transit_height = 14
var/transit_width = SHUTTLE_TRANSIT_BORDER * 2
var/transit_height = SHUTTLE_TRANSIT_BORDER * 2

// Shuttles travelling on their side have their dimensions swapped
// from our perspective
switch(travel_dir)
switch(dock_dir)
if(NORTH, SOUTH)
transit_width += M.width
transit_height += M.height
if(EAST, WEST)
transit_width += M.height
transit_height += M.width
/*
world << "The attempted transit dock will be [transit_width] width, and \
[transit_height] in height. The travel dir is [travel_dir]."
*/

// Then find a place to put the zone

Expand All @@ -291,33 +304,75 @@ var/datum/subsystem/shuttle/SSshuttle
continue
for(var/j in proposed_zone)
var/turf/T = j
if(!T)
continue base
if(!(T.flags & UNUSED_TRANSIT_TURF))
continue base
break
world << "[COORD(topleft)] and [COORD(bottomright)]"
break base

if((!proposed_zone) || (!proposed_zone.len))
return FALSE

var/turf/topleft = proposed_zone[1]
world << "[COORD(topleft)] is TOPLEFT"
// Then create a transit docking port in the middle
var/mid_x = 7 + M.dwidth + topleft.x
var/mid_y = 7 + M.dheight + topleft.y

var/turf/midpoint = locate(mid_x, mid_y, topleft.z)
var/coords = M.return_coords(0, 0, dock_dir)
world << json_encode(coords)
/* 0------2
| |
| |
| x |
3------1
*/

var/x0 = coords[1]
var/y0 = coords[2]
var/x1 = coords[3]
var/y1 = coords[4]
// Then we want the point closest to -infinity,-infinity
var/x2 = min(x0, x1)
var/y2 = min(y0, y1)
/*
var/lowx = topleft.x + SHUTTLE_TRANSIT_BORDER
var/lowy = topleft.y + SHUTTLE_TRANSIT_BORDER
var/turf/low_point = locate(lowx, lowy, topleft.z)
new /obj/effect/landmark/stationary(low_point)
world << "Starting at the low point, we go [x2],[y2]"
*/
// Then invert the numbers
var/transit_x = topleft.x + SHUTTLE_TRANSIT_BORDER + abs(x2)
var/transit_y = topleft.y + SHUTTLE_TRANSIT_BORDER + abs(y2)

var/transit_path = /turf/open/space/transit
switch(travel_dir)
if(NORTH)
transit_path = /turf/open/space/transit/north
if(SOUTH)
transit_path = /turf/open/space/transit/south
if(EAST)
transit_path = /turf/open/space/transit/east
if(WEST)
transit_path = /turf/open/space/transit/west

//world << "Docking port at [transit_x], [transit_y], [topleft.z]"
var/turf/midpoint = locate(transit_x, transit_y, topleft.z)
if(!midpoint)
return FALSE
//world << "Making transit dock at [COORD(midpoint)]"
var/obj/docking_port/stationary/transit/new_transit_dock = new(midpoint)
new_transit_dock.assigned_turfs = proposed_zone
new_transit_dock.name = "Transit for [M.id]/[M.name]"
new_transit_dock.turf_type = transit_path

var/dock_angle = dir2angle(M.preferred_direction) + M.port_angle + 180
// Add 180, because ports point inwards, rather than outwards
new_transit_dock.setDir(angle2dir(dock_angle))

for(var/i in new_transit_dock.assigned_turfs)
var/turf/open/space/transit/T = i
var/turf/T = i
T.ChangeTurf(transit_path)
T.flags &= ~(UNUSED_TRANSIT_TURF)
T.ChangeTurf(/turf/open/space/transit)
T.setDir(travel_dir)
T.update_icon()

M.assigned_transit = new_transit_dock
return TRUE
Expand Down
23 changes: 23 additions & 0 deletions code/game/objects/effects/landmarks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,26 @@
ruin_landmarks -= src
ruin_template = null
. = ..()

/obj/effect/landmark/stationary
name = "stationary landmark"
desc = "This doesn't seem to move."
invisibility = 0
layer = GHOST_LAYER
var/trueLoc

/obj/effect/landmark/stationary/New(loc)
. = ..()
trueLoc = loc
START_PROCESSING(SSfastprocess, src)

/obj/effect/landmark/stationary/Destroy()
trueLoc = null
STOP_PROCESSING(SSfastprocess, src)

/obj/effect/landmark/stationary/process()
if(loc != trueLoc)
forceMove(trueLoc)

/obj/effect/landmark/stationary/onShuttleMove()
return FALSE
12 changes: 12 additions & 0 deletions code/game/turfs/space/transit.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@
dir = SOUTH
baseturf = /turf/open/space/transit

/turf/open/space/transit/south
dir = SOUTH

/turf/open/space/transit/north
dir = NORTH

/turf/open/space/transit/horizontal
dir = WEST

/turf/open/space/transit/west
dir = WEST

/turf/open/space/transit/east
dir = EAST

/turf/open/space/transit/Entered(atom/movable/AM, atom/OldLoc)
if(!AM)
return
Expand Down
8 changes: 5 additions & 3 deletions code/modules/shuttle/shuttle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
return //we don't rotate with shuttles via this code.
//returns a list(x0,y0, x1,y1) where points 0 and 1 are bounding corners of the projected rectangle
/obj/docking_port/proc/return_coords(_x, _y, _dir)
if(!_dir)
if(_dir == null)
_dir = dir
if(!_x)
if(_x == null)
_x = x
if(!_y)
if(_y == null)
_y = y

//byond's sin and cos functions are inaccurate. This is faster and perfectly accurate
Expand Down Expand Up @@ -136,6 +136,7 @@

var/turf_type = /turf/open/space
var/area_type = /area/space
var/last_dock_time

/obj/docking_port/stationary/New()
..()
Expand Down Expand Up @@ -481,6 +482,7 @@
SSair.add_to_active(T0,1)

check_poddoors()
S1.last_dock_time = world.time

loc = S1.loc
setDir(S1.dir)
Expand Down

0 comments on commit 1ad915b

Please sign in to comment.