code/datums/components/orbiter.dm
ORBIT_LOCK_IN | Code to handle atoms orbiting other atoms, following them as they move. The basic logic is simple. We register a signal, COMSIG_MOVABLE_MOVED onto orbited atoms. When the orbited atom moves, any ghosts orbiting them are moved to their turf. We also register a MOVED signal onto the ghosts to cancel their orbit if they move themselves. Complexities come in for items within other items (such as the NAD in a box in a backpack on an assistant pretending to be the captain), as items in containers do not fire COMSIG_MOVABLE_MOVED when their container moves. |
---|
Define Details
ORBIT_LOCK_IN
Code to handle atoms orbiting other atoms, following them as they move. The basic logic is simple. We register a signal, COMSIG_MOVABLE_MOVED onto orbited atoms. When the orbited atom moves, any ghosts orbiting them are moved to their turf. We also register a MOVED signal onto the ghosts to cancel their orbit if they move themselves. Complexities come in for items within other items (such as the NAD in a box in a backpack on an assistant pretending to be the captain), as items in containers do not fire COMSIG_MOVABLE_MOVED when their container moves.
The signal logic for items in containers is as follows: Assume 1 is some item (for example, the NAD) and 2 is a box. When 1 is added to 2, we register the typical orbit COMSIG_MOVABLE_MOVED onto 2. This in essence makes 2 the "leader", the atom that ghosts follow in movement. As 2 is moved around (say, dragged on the floor) ghosts will follow it. We also register a new intermediate COMSIG_MOVABLE_MOVED signal onto 1 that tracks if 1 is moved. Remember, this will only fire if 1 is moved around containers, since it's impossible for it to actually move on its own. If 1 is moved out of 2, this signal makes 1 the new leader. Lastly, we add a COMSIG_ATOM_EXITED to 2, which tracks if 1 is removed from 2. This EXITED signal cleans up any orbiting signals on and above 2. If 2 is added to another item, (say a backpack, 3) 3 becomes the new leader 2 becomes an intermediate 1 is unchanged (but still carries the orbiter datum)
You may be asking yourself: is this overengineered? In part, yes. However, MOVED signals don't get fired for items in containers, so this is really the next best way. Also, is this really optimal? As much as it can be, I believe. This signal-shuffling will not happen for any item that is just moving from turf to turf, which should apply to 95% of cases (read: ghosts orbiting mobs).