ID:2413234
 
Code:
area
pPath
Exit(atom/movable/O, atom/newloc)
if(istype(O, /mob/Pedestrian/))
var/mob/Pedestrian/P = O
//P.pTurn()
return 0
return 1
mob
Pedestrian
var/pTurned = 0
var/pOldDir
New()
..()
src.pWalk()
Male
name = "Pedestrian"
icon = 'Male.dmi'
density = 1
dir = SOUTH
Female
name = "Pedestrian"
icon = 'Female.dmi'
density = 1
dir = SOUTH

proc
pWalk(atom/OldLoc)
check
step(src, src.dir, 4)
sleep(5)
goto check
/*
start
var
area/newturf = get_step(src, src.dir)
newx = newturf.x
newy = newturf.y
newz = newturf.z
view(src) <<"[newx], [newy], [newz]"
for(var/area/pPath/T in world)
view(src) <<"[T] Found [T.x], [T.y], [T.z]"
if(T.x == newx && T.y == newy && T.z == newz)
step(src, src.dir, 4)
view(src) <<"Go [src.dir]"
else
src.pTurn()
sleep(5)
goto start*/

pTurn(newdir)
if(!newdir)
if(src.pTurned == 1)
src.pTurned = 2
src.dir = turn(src.dir, 180)
else if(src.pTurned == 2)
src.dir = turn(src.pOldDir, 180)
else
src.pOldDir = src.dir
var/random = rand(1,2)
if(random == 1)
src.dir = turn(src.dir, 90)
if(random == 2)
src.dir = turn(src.dir, -90)
src.pTurned = 1
spawn(10)
src.pTurned = 0
else
src.dir = turn(src.dir, newdir)

turf
Walkways
Turn
icon = 'Turfs.dmi'
icon_state = "Sidewalk"
Entered(atom/movable/O, atom/OldLoc)
if(istype(O, /mob/Pedestrian/))
var
mob/Pedestrian/P = O
mob/loc1 = new(); mob/loc2 = new(); mob/loc3 = new(); random
walk(P, 0)
for(var/turf/Walkways/W in oview(1, P))
if(W.loc != OldLoc && W.loc != P.loc)
world << "W[W.x] [W.type]"
if(!loc1.x)
loc1.x = W.x
loc1.y = W.y
loc1.z = W.z
world << "1: [loc1.x], [loc1.y], [loc1.z]"
else if (!loc2.x)
loc2.x = W.x
loc2.y = W.y
loc2.z = W.z
world << "2: [loc2.x], [loc2.y], [loc2.z]"
else if(!loc3.x)
loc3.x = W.x
loc3.y = W.y
loc3.z = W.z
world << "3: [loc3.x], [loc3.y], [loc3.z]"
if(loc1.x && loc2.x && loc3.x)
random = rand (1,3)
if(random == 1)
world << "Step towards 1"
step_towards(P, loc1, 4)
else if(random == 2)
step_towards(P, loc2, 4)
world << "Step towards 2"
else if(random == 3)
step_towards(P, loc3, 4)
world << "Step towards 3"
else if(loc1.x && loc2.x)
random = rand (1,2)
if(random == 1)
world << "Step towards 1"
step_towards(P, loc1, 4)
else if(random == 2)
step_towards(P, loc2, 4)
world << "Step towards 2"
else if(loc1.x)
world << "Step towards 1"
step_towards(P, loc1, 4)
else
world << "Turn 180"
P.pTurn(180)
//P.pWalk()
del loc1
del loc2
del loc3


Problem description:

I am attempting to make my NPCs walk on the Walkways turf only, which I've accomplished using an area. Now I'm trying to make them turn at corners using Entered proc but having little luck.
This is what happens when the NPC reaches an corner where he can only turn left.

W97 /turf/Walkways/Turn
1: 97, 46, 1
W97 /turf/Walkways/Sidewalk
2: 97, 47, 1
W98 /turf/Walkways/Sidewalk
3: 98, 46, 1
Step towards 3

For some reason its applying locations from OldLoc and current loc when I specify not to, he also does not step towards 3, which is correct he should move towards x 98.