ID:265257
 
For a long time now I've been wanting to see what the soft code for movement procs would look like. Now I've had the opportunity to look at the movement code, and I have here a translated version of it for all who are interested in something as crazy as redefining movement completely. This is for future reference.
atom/proc/GetDenseObject()
turf/GetDenseObject()
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 = GetDenseObject()
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.GetDenseObject())
return 0
if(area2 && area1 != area2 && isturf(newloc) && !area2.Enter(src))
if(newloc) Bump(newloc.GetDenseObject())
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))
area.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

Lummox JR
Sweet, thanks. I tried to do this myself once, but gave up. =)
This should really help when ever I modify Move() to the point where I can no longer call the parent proc.

Thanks!
I've always wanted to make a "soft-coded hard code" project so people can see how the internal procedures (at least the calculation-based ones) work. So I find this pretty cool.
In response to DarkView
I too find Lummox's post interesting, as I find myself wondering exactly what the default code is like. But as for acting like it now enables you to remake it, as if you could not before, it shows the default procedure in the help file. It does not give every line like that, but it gives enough information to remake the procedure just fine.
Just a note of correction here, in case anyone saved a copy of that code: I forgot the oldloc argument in both Entered() calls, which is now fixed. I tried to fix that before work but the forum crashed at exactly the wrong time.

Lummox JR
As I've said before, I find it silly how (in your example) GetDenseObject() will get called twice if you bump into something, which is redundant.
In response to Garthor
Garthor wrote:
As I've said before, I find it silly how (in your example) GetDenseObject() will get called twice if you bump into something, which is redundant.

It is, nevertheless, the way it's done. (Also, it has to be done that way because the object can be deleted in transit.)

Lummox JR
What does soft code and hard code mean?
In response to Resonating_Light
Hard code is what is built into byond, the soft code is taking that and basicly translating it into DM.
Interesting! Thanks.

That might even make a good addition to the DM Reference entry for Move() -- maybe at the end of the entry, with a warning that it's fairly technical. Or maybe there should be a separate DM Technical Reference! It worked for the Commodore 64...
In response to Scoobert
Speaking of what built BYOND.. What language did they use? I use Bloodshed's C++ compiler and I know that was made with Delphi. It just kinda made me wonder what BYOND was built with.

Resonating Light
In response to Gughunter
I think a technical reference is a much better idea then a Move() reference addition. As it is if someone doesn't understand even a section of a reference entry they disreguard everything else in the entry.
In response to Resonating_Light
Resonating_Light wrote:
Speaking of what built BYOND.. What language did they use? I use Bloodshed's C++ compiler and I know that was made with Delphi. It just kinda made me wonder what BYOND was built with.

BYOND is coded in C++.

Lummox JR
In response to Gughunter
Gughunter wrote:
...maybe there should be a separate DM Technical Reference! It worked for the Commodore 64...

i second that!
Thank you for putting this into code, Lummox. Having done the crazy thing now, redefining movement with this help, I found a couple of things you might want to fix:

if(area1 && area1 != area2 && !isarea(oldloc))
area.Exited(src)

Should be

if(area1 && area1 != area2 && !isarea(oldloc))
area1.Exited(src)


mob/Bump(atom/A)
Should be
atom/movable/Bump(atom/A)



/Gazoot