map
parent_type = /turf
path
icon = 'World Map/path.dmi'
set_delay = PATH_DELAY
Click()
var/state = text2num(src.icon_state)
world << "Begin Path Generation ([x], [y])"
// Cycle through possible directions
for(var/path_dir=1, path_dir<16, path_dir*=2)
// Debug outputs
world << "path_dir: [path_dir]"
world << "bitwise: <b>[path_dir&state]</b>"
// end outputs
if(path_dir&state == path_dir)
// Create a new path on the original location
new/map/obj/path (locate(src.x, src.y, 1), path_dir)
// new_step is the next step in the new direction
var/turf/new_step = get_step(src, path_dir)
// Keep spawning paths until there is no more grass in the direction
// ie: since paths are spawned from a /map/path, when they encounter
// a /map/path the generation will halt.
while(istype(new_step, /map/grass))
world << "New Path: ([new_step.x], [new_step.y]) ([path_dir])" // debugging
// Generate a new path object, move to the next step and continue...
new/map/obj/path (locate(new_step.x, new_step.y, 1), path_dir)
new_step = get_step(new_step, path_dir)
world << "End Path Generation ([new_step.x], [new_step.y])"
else
world << "Bitwise Mismatch"
Problem description:
Good morning, BYOND. Long time no chat. I'm working on a hobby project, and it's been awhile since I did any programming in BYOND.
I don't know if my problem is in the bitwise operator or not (debug output to follow), or in where I'm actually generating the paths.
When I spawn the paths from a /map/path facing NORTH it works properly, and the debug output makes sense, however when I work with any other direction (or combination thereof) it doesn't spawn paths.
Here is the debug info from spawning a NORTH facing path:
Begin Path Generation (3, 1)
path_dir: 1
bitwise: 1
New Path: (3, 2) (1)
New Path: (3, 3) (1)
End Path Generation (3, 4)
path_dir: 2
bitwise: 0
Bitwise Mismatch
path_dir: 4
bitwise: 0
Bitwise Mismatch
path_dir: 8
bitwise: 0
Bitwise Mismatch
And the debug info from spawning a SOUTH facing path:
Begin Path Generation (3, 6)
path_dir: 1
bitwise: 0
Bitwise Mismatch
path_dir: 2
bitwise: 2
Bitwise Mismatch
path_dir: 4
bitwise: 0
Bitwise Mismatch
path_dir: 8
bitwise: 0
Bitwise Mismatch
So, why isn't it spawning the SOUTH and other directions? If anyone can shed some light on my conundrum it would be much appreciated.
the type /map is parent_typed to /turf, so spawning multiple paths is creating multiple turfs, which is really peculiar behavior.
Also, creating a new turf on src.x, src.y, src.z will kill the proc execution as src will be nulled out, so it's never going to get past the first path object it tries to create in the current location.
Then there's your use of locate(). locate() is only necessary when you need to grab the turf at a specified location get_step already has returned that. Are you calling this behavior on a different z layer than you are currently clicking on?
Moreover, your binary operations aren't matching up, which indicates that state is never equal to anything but NORTH.