ID:167280
 
I was attempting to think of a solution to this:

I am building a sim city remake for BYOND and I was wondering how I could check to make sure an object(power lines) are all connected together and to make sure there isnt a break in them.

Here's an example:

RxxxxxxP

R=House
P=Power Plant
x=Power lines

Since they are all connected everything would have power. But let's say this occurs

Rxxxx xP

Since the x next to the power plant is connected to it, it would have power. However, the 4 x's to the right and the house would not have power.

How would I go around checking each object has power? I guess I could do a world check proc, but it seems that it will be ALOT of code. Any ways I can do this?
Try a modified pathfinding algorithm. Instead of trying to avoid dense locations, avoid any location without a power line in it. If obj1 can't find a path to obj2, it's not connected.

Look up pathfinding algorithms.
In response to Loduwijk
Hmm interesting concept and I found a library on it. Te thing is a wish for the program to find a path without going diagonal, sincee there isnt any diagonal power lines in my game.
In response to Loduwijk
If i understand loduwijk correctly it won't go diagnol as long as none of your powerlines do. Don't know if this is true or not seeing as i know nothing of pathfinding algorithms. Sorry if this was a wasted post.
I would have a "check power" procedure, basically. I'd start with the location being added/removed to the power grid. If it delivered power, or was adjacent to a device which delivers power, I'd add it to a list. I'd then loop through this list to find other devices that could transmit power, or provide power, and continually add them until I either run into something that is already powered, or have nothing else that can be powered. I'd actually be adding my "now powered" devices to another list to have them excluded from being checked again.

This might not be THE most efficient way of doing this on BYOND, but you're probably not talking about anything so large scale that an average computer can't handle it. Besides, it would only check as far as the power NEEDs to extend, and if it doesn't provide power or conduct it, no check would be made anyways.

I know that's very abstract, but I hope it helps.
In response to Tazor07
Then modify it to not go diagonal.