I was wondering what the most efficient way to handle cardinally adjacent grouping would be, basically a proc that returns a list of similar atoms that are all cardinally touching one another.
These atoms are not the size of the world's default icon size, so using get_step() won't work exactly.
I was thinking of something using get_step() and then bound_dist()? Not sure as I haven't been messing around with those procs much since they've been added.
Thanks for your help, if you have a question just ask and I'll draw a diagram or a screenshot of the game to help.
May 6 2012, 9:10 am
|
|
Do a breadth-first search (or BFS for short). The Region library uses this. You can look at the region.group() proc in partition.dm for an example, though you'd have to adapt it to work on turfs instead of regions.
|
That's what I planned to do, but the issue was actually being able to find the atoms to compare them to one another. I've ended up taking D4RK3's advice and using an array so we'll see how that works out!
|
It's the same concept even if you have to come up with some different criteria for atoms being cardinally adjacent. For turfs you can easily use locate() to find its neighbors, if you're dealing with movable atoms you can use obounds() or something similar. The Pixel Movement library provides top(), bottom(), left(), right(), etc. procs to get lists of objects on each side of an atom, those might be more useful for finding neighbors.
|