Hey, emoaeden.
I have to start by seconding chrisinfinger's sentiment. Very cool looking game.
I can't be sure, but the problem you're running into might have two parts.
Firstly, while you are checking each power line segment, you may not be checking them in an order that propagates power the way you want.
Secondly, determining connectivity, or a lack of connectivity, may not be possible by making a single top-to-bottom left-to-right pass over all the tiles.
Tile checking order:
To illustrate what I mean through the power of ASCII art,
Suppose we have a power plant (represented by "#"), and a chain of power line segments (represented by 0 or 1 depending on powered state.)
From here on, I'll call the power plant a "plant" and each power line segment a "seg".
Plant on left, with five powered segs.
#11111
Now I may be interpreting the capx events wrong, but it looks like there's a nested XY loop that checks every cell, starting from the top-left, moving top to bottom in columns, and moving left to right from column to column. As the loop runs, for each cell, if that cell is powered, then power is propagated to the cardinally adjacent cells.
I think this may mean that power will propagate asymmetrically, moving much faster from top to bottom than from bottom to top.
Consider the following 1-dimentional example in which we loop through segs from left to right. The act of running a loop, until all loop iterations are complete, I will refer to as a single "pass".
Start: #00000 (6 tiles so we will do 6 steps inside each pass.)
---- Pass 1:
index 0: #10000
index 1: #11000
index 2: #11100
index 3: #11110
index 4: #11111
index 5: #11111
---- Done in 1 pass.
Now, consider a case where the plant is on the right instead of the left. Note that the loop still steps from left to right:
Start: 00000# (6 tiles so we will do 6 steps inside each pass.)
---- Pass 1:
index 0: 00000#
index 1: 00000#
index 2: 00000#
index 3: 00000#
index 4: 00000#
index 5: 00001#
---- Pass 2:
index 0: 00001#
index 1: 00001#
index 2: 00001#
index 3: 00001#
index 4: 00011#
index 5: 00011#
---- Pass 3:
index 0: 00011#
index 1: 00011#
index 2: 00011#
index 3: 00111#
index 4: 00111#
index 5: 00111#
...
---- Pass 4:
...
---- Pass 5:
...
index 5: 11111#
Done in 5 passes.
So it takes much longer to propagate power against the direction the loop is stepping. In the above cases, if you do a pass every 5 seconds, then it will take 5 seconds to propagate power from left-to-right, and it will take 25 seconds to propagate power right-to-left, over the same distance. If the power line was 20 segments long then it would still take 5 seconds to propagate moving right, and 100 seconds to propagate moving left.
This might be part of the strange behavior you're seeing.
Connectivity checking issue:
So the other issue is determining connectivity.
The problem here is that I don't think you can determine connectivity in a single top-to-bottom left-to-right pass. In the example above, when the power is advancing against the loop stepping direction, a single pass only advances powered status by a single tile, and it takes multiple subsequent passes to complete the propagation. (Again, a pass is not a single loop step, it's the processing of all tiles once.)
In theory, every time a seg was destroyed, you could set every tile to un-powered, and then immediately run a number of full passes equal to the number of power line segs in the game, and while that would mark all power lines correctly when it finally completed, it would be prohibitively time consuming.
Assuming I'm thinking about this right, (and I may not be) below is an example of why we can't solve connectivity in a single pass.
Suppose you destroy a seg in the middle of a chain of powered segs,
going from this
#11111
to this
#_1111 (with the underscore "_" representing the bulldozed seg.)
You now have 4 isolated segs in a chain, all marked as being powered.
The problem is, when making a pass over all the tiles, how do you know if a seg should be un-powered?
That is, suppose you're in the loop, stepping through tiles,
index 0: #_1111
index 1: #_1111
index 2: #_1111 (we arrive at the left end of the isolated chain)
and you come to the left end seg of that chain of 4 segs. It's marked as powered. How would you be able to tell if it shouldn't be? Well, it's not connected to a plant, but it *is* connected to another powered seg. Inside the loop, you can't tell whether the chain is powered from the other end, so you can't tell whether it should be powered or un-powered.
That is, you could be dealing with this case,
index 2: #_1111#
With a plant on the right-hand end that seg could have a legitimate reason for being powered. There's no way to know inside the loop, because we can only check the neighboring segs.
As an interesting aside, Minecraft has a very similar problem. Leaf blocks are "powered" by log blocks. A leaf block is only immune to decay if it was connected to a log block, or if it is connected through a chain of leaf blocks to a log block. In this sense it is exactly what you're trying to solve, but in a 3D grid instead of a 2D grid. Verifying that a leaf block is connected to a log block through a chain of leaf blocks involves path finding through neighboring leaf blocks to see if a path exists. Minecraft also has a max radius from log blocks (4), beyond which it doesn't bother doing any path finding, and instead a too-distant leaf block is simply doomed to decay.
Connectivity checking - possible solution:
In order to quickly determine connectivity, you might be able to use a "backtracking" algorithm.
It would work kind of like this:
Set all segs to un-powered.
For each power plant:
Start walking along a chain of segs coming out of it, marking each segment "powered" as you go.
Every time you come to a branch (e.g. T-intersection) you put the "hub" tile's coords on a stack. Now you pick one of its un-powered branching tiles and start walking along that chain.
If you reach a dead end, then pop the last "hub" tile off the stack (if one exists) and jump ("backtrack") directly back to that tile, and continue walking along the next un-powered branch. (Note: If it doesn't have an un-powered branch then treat it just like a dead end.)
Eventually you'll have hit every dead end, and followed every branch, and there will be nothing left to pop off the stack.
If you check every power plant, this way, when you're done, the only power line segs that will be un-powered will be those with no connectivity to a plant.
If two power plants are connected to each other by a chain of segs, then the first power plant check will leave all those segs marked "powered" so the second power plant check will end instantly in a dead end, which is good, because you don't have to re-check any segs.
Okay, sorry for the lengthy post. The more I started thinking about it the more I realized it's a pretty interesting problem.
Hope that helps at all.