-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tweak(following): ghosts can orbit now
- Loading branch information
1 parent
88118f7
commit b005922
Showing
8 changed files
with
233 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
SUBSYSTEM_DEF(orbit) | ||
name = "Orbit" | ||
|
||
priority = SS_PRIORITY_ORBIT | ||
wait = 2 | ||
|
||
flags = SS_NO_INIT | SS_TICKER | ||
|
||
var/list/currentrun = list() | ||
var/list/orbits = list() | ||
|
||
/datum/controller/subsystem/orbit/stat_entry() | ||
..("P:[orbits.len]") | ||
|
||
/datum/controller/subsystem/orbit/fire(resumed = 0) | ||
if(!resumed) | ||
src.currentrun = orbits.Copy() | ||
|
||
//cache for sanic speed (lists are references anyways) | ||
var/list/currentrun = src.currentrun | ||
|
||
while(currentrun.len) | ||
var/datum/orbit/O = currentrun[currentrun.len] | ||
currentrun.len-- | ||
if(!O) | ||
orbits -= O | ||
if(MC_TICK_CHECK) | ||
return | ||
|
||
continue | ||
|
||
if(!O.orbiter) | ||
qdel(O) | ||
if(MC_TICK_CHECK) | ||
return | ||
|
||
continue | ||
|
||
if(O.lastprocess >= world.time) // We already checked recently | ||
if(MC_TICK_CHECK) | ||
return | ||
|
||
continue | ||
|
||
var/targetloc = get_turf(O.orbiting) | ||
if(targetloc != O.lastloc || O.orbiter.loc != targetloc) | ||
O.Check(targetloc) | ||
|
||
if(MC_TICK_CHECK) | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/datum/orbit | ||
var/atom/movable/orbiter | ||
var/atom/orbiting | ||
var/lock = TRUE | ||
var/turf/lastloc | ||
var/lastprocess | ||
|
||
/datum/orbit/New(_orbiter, _orbiting, _lock) | ||
orbiter = _orbiter | ||
orbiting = _orbiting | ||
SSorbit.orbits += src | ||
if(!orbiting.orbiters) | ||
orbiting.orbiters = list() | ||
orbiting.orbiters += src | ||
|
||
if(orbiter.orbiting) | ||
orbiter.stop_orbit() | ||
orbiter.orbiting = src | ||
|
||
if(!Check()) | ||
return | ||
|
||
lock = _lock | ||
|
||
SEND_SIGNAL(orbiter, SIGNAL_ORBIT_BEGIN, orbiting) | ||
|
||
//do not qdel directly, use stop_orbit on the orbiter. (This way the orbiter can bind to the orbit stopping) | ||
/datum/orbit/Destroy() | ||
SEND_SIGNAL(orbiter, SIGNAL_ORBIT_STOP, orbiting) | ||
SSorbit.orbits -= src | ||
|
||
if(orbiter) | ||
orbiter.orbiting = null | ||
orbiter = null | ||
|
||
if(orbiting) | ||
if(orbiting.orbiters) | ||
orbiting.orbiters -= src | ||
if(!orbiting.orbiters.len)//we are the last orbit, delete the list | ||
orbiting.orbiters = null | ||
orbiting = null | ||
|
||
return ..() | ||
|
||
/datum/orbit/proc/Check(turf/targetloc) | ||
if(!orbiter) | ||
qdel_self() | ||
return FALSE | ||
|
||
if(!orbiting) | ||
orbiter.stop_orbit() | ||
return FALSE | ||
|
||
if(!orbiter.orbiting) //admin wants to stop the orbit. | ||
orbiter.orbiting = src //set it back to us first | ||
orbiter.stop_orbit() | ||
|
||
lastprocess = world.time | ||
|
||
if(!targetloc) | ||
targetloc = get_turf(orbiting) | ||
|
||
if(!targetloc || (!lock && orbiter.loc != lastloc && orbiter.loc != targetloc)) | ||
orbiter.stop_orbit() | ||
return FALSE | ||
|
||
orbiter.loc = targetloc | ||
lastloc = orbiter.loc | ||
return TRUE | ||
|
||
|
||
/atom/movable/var/datum/orbit/orbiting = null | ||
/atom/var/list/orbiters = null | ||
|
||
/atom/movable/var/cached_transform = null | ||
//A: atom to orbit | ||
//radius: range to orbit at, radius of the circle formed by orbiting (in pixels) | ||
//clockwise: whether you orbit clockwise or anti clockwise | ||
//rotation_speed: how fast to rotate (how many ds should it take for a rotation to complete) | ||
//rotation_segments: the resolution of the orbit circle, less = a more block circle, this can be used to produce hexagons (6 segments) triangles (3 segments), and so on, 36 is the best default. | ||
//pre_rotation: Chooses to rotate src 90 degress towards the orbit dir (clockwise/anticlockwise), useful for things to go "head first" like ghosts | ||
//lockinorbit: Forces src to always be on A's turf, otherwise the orbit cancels when src gets too far away (eg: ghosts) | ||
|
||
/atom/movable/proc/orbit(atom/A, radius = 10, clockwise = FALSE, rotation_speed = 20, rotation_segments = 36, pre_rotation = TRUE, lockinorbit = FALSE) | ||
if(!istype(A)) | ||
return | ||
|
||
new/datum/orbit(src, A, lockinorbit) | ||
|
||
if(!orbiting) //something failed, and our orbit datum deleted itself | ||
return | ||
|
||
var/matrix/initial_transform = matrix(transform) | ||
cached_transform = initial_transform | ||
|
||
//Head first! | ||
if(pre_rotation) | ||
var/matrix/M = matrix(transform) | ||
var/pre_rot = 90 | ||
if(!clockwise) | ||
pre_rot = -90 | ||
M.Turn(pre_rot) | ||
transform = M | ||
|
||
var/matrix/shift = matrix(transform) | ||
shift.Translate(0,radius) | ||
transform = shift | ||
|
||
SpinAnimation(rotation_speed, -1, clockwise, rotation_segments) | ||
|
||
/atom/movable/proc/stop_orbit() | ||
SpinAnimation(0, 0) | ||
qdel(orbiting) | ||
transform = cached_transform | ||
|
||
/atom/Destroy() | ||
. = ..() | ||
if(orbiters) | ||
for(var/thing in orbiters) | ||
var/datum/orbit/O = thing | ||
if(O.orbiter) | ||
O.orbiter.stop_orbit() | ||
|
||
/atom/movable/Destroy() | ||
. = ..() | ||
if(orbiting) | ||
stop_orbit() |