//Title: Soft-Coded BYOND Movement Procs
//Credit to: Lummox JR
//Contributed by: Jtgibson
/*
This is a soft-code implementation of BYOND's standard movement routines, to let
you know exactly what's going on behind the scenes.
Implementing this in your own code will almost certainly slow things down a bit,
but if you ever need to add in hooks somewhere (GetObstructed() in particular)
this is the way to do it!
--Jtgibson
*/
atom/proc/GetObstructed()
turf/GetObstructed()
if(density) return src
if(loc.density) return loc
for(var/obj/O in src) if(O.density) return O
for(var/mob/M in src) if(M.density) return M
atom/Enter() return 1
atom/Exit() return 1
turf/Enter(atom/movable/A)
if(!A) return 0
if(!A.density) return 1
var/atom/D = GetObstructed()
return (!D || D == A) ? 1 : 0
atom/movable/Move(atom/newloc, newdir)
if(newdir) dir = newdir
// Move() ignores null destinations so bumping into edge of map has no effect
if(!newloc) return 0
var/atom/oldloc = loc
if(loc && newloc && !newdir) dir = get_dir(loc, newloc)
if(oldloc && !oldloc.Exit(src)) return 0
var/area/area1 = oldloc
var/area/area2 = newloc
while(area1 && !isarea(area1)) area1 = area1.loc
while(area2 && !isarea(area2)) area2 = area2.loc
if(area1 && area1 != area2 && isturf(oldloc) && !area1.Exit(src)) return 0
if(newloc && !newloc.Enter(src))
if(newloc) Bump(newloc.GetObstructed())
return 0
if(area2 && area1 != area2 && isturf(newloc) && !area2.Enter(src))
if(newloc) Bump(newloc.GetObstructed())
return 0
// if something else moved us already, abort
if(loc != oldloc) return 0
loc = newloc
if(oldloc) oldloc.Exited(src)
if(area1 && area1 != area2 && !isarea(oldloc))
area1.Exited(src)
if(loc) loc.Entered(src, oldloc)
if(area2 && area1 != area2 && !isarea(loc))
area2.Entered(src, oldloc)
return 1
// end of atom/movable/Move()
mob/Bump(atom/A)
if(ismob(A))
var/mob/M = A
if(src in M.group)
var/swap = loc
loc = M.loc
M.loc = swap
ID:195088
![]() Nov 23 2006, 8:54 pm
|
|