I probably overreacted when I posted this, I managed to solve the problem by commenting out segments of the subroutine one at a time. The program stopped crashing after I commented out this debug code:
`DEBUG
for c=1 to array count(Paths(0))
text 10,c*10+200,str$(Paths(c).X)+","+str$(Paths(c).Y)
next c
for c=1 to array count(Sims(0))
text 300,Sims(c).Path_Start*10+200,str$(c)
text 320,Sims(c).Path_End*10+200,"/"+str$(c)
next c
It turns out one of the bits I'd removed was the declaration of the
Paths array, though why this caused a crash at the return command instead of a handy "Array does not exist at line xxx" error is beyond me.
EDIT: Thanks for your help anyway Mobiius, and Kevin

.

Latest progress: Fog of War implemented; frustrated by pathfinding >.>