Skip to content

Commit

Permalink
Orbiting weakref
Browse files Browse the repository at this point in the history
  • Loading branch information
Filatelele committed Dec 14, 2023
1 parent b005922 commit e373c84
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
5 changes: 3 additions & 2 deletions code/modules/mob/mob_movement.dm
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@
var/datum/orbit/O = thing
O.Check()

if(orbiting)
orbiting.Check()
var/datum/orbit/orbit = orbiting?.resolve()
if(istype(orbit))
orbit.Check()

SEND_SIGNAL(src, SIGNAL_MOVED, src, old_loc, loc)

Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/observer/ghost/ghost.dm
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp
orbitsize = world.icon_size
orbitsize -= (orbitsize / world.icon_size) * (world.icon_size * 0.25)

if(orbiting && orbiting.orbiting != target)
if(weakref(orbiting) && weakref(orbiting).orbiting != target)
to_chat(src, "<span class='notice'>Now following \the [target].</span>")

forceMove(target)
Expand Down
16 changes: 5 additions & 11 deletions code/modules/orbit/orbit.dm
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,12 @@
lastloc = orbiter.loc
return TRUE

/atom/movable
var/weakref/orbiting = null
var/cached_transform = null

/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
var/list/orbiters = null

/atom/movable/proc/orbit(atom/A, radius = 10, clockwise = FALSE, rotation_speed = 20, rotation_segments = 36, pre_rotation = TRUE, lockinorbit = FALSE)
if(!istype(A))
Expand Down

0 comments on commit e373c84

Please sign in to comment.