SimCity 2K Power

BlitzMax Forums/BlitzMax Programming/SimCity 2K Power

z80jim(Posted 2006) [#1]
I'm playing around with a SimCity 2K clone and am trying to find an elegant way of implementing the power network. Essentially a cell has power if it can trace a path, through adjoining powered cells to a power source.

While it is true that if a neighboring cell has power then every cell next to it will be powered, the problem is propagating changes when a power line is broken.

I know the real SimCity 2K used cellular automata heavily but I don't see how it can really work here.

I want to avoid doing an algorithm that keeps checking for an actual path from each cell to a source. Seems way to cumbersome. There must be a more efficient way to do it.

I would appreciate any thoughts or ideas.


Dreamora(Posted 2006) [#2]
Don't see a problem with an algorithm:

1. The algorithm will be recursive (you know that there can only be some power if there is a "deliverying" field around it that delivers power)
2. The algorithm will prefer power lines to "line free" as power lines transport electricity, free fields only spread it.
3. The algorithm is only executed if something changes (power plant created / exploded / destroy - power line built / destroyed - power consumption raised / dropped)

There is no reason to keep checking. If nothing happens (only the above events are influencing the power source), there is no reason to recheck the whole thing.


kfprimm(Posted 2006) [#3]
Take a look at the AStar Demo in the sample programs, might work.


z80jim(Posted 2006) [#4]
Thanks Dreamora. I really like your point 3 about it only needing to run when certain events occur. That should take a bit of the sting out of it.

Unless I am missing something, when it does need to run, it would still need to check each developed cell to see if it still has power ( in the case of a broken power line for example ).


Dreamora(Posted 2006) [#5]
Yes it would reach each cell in power range once (if it isn't connected to any power then the cell won't be reached)

There is not much possibility around that as asking for the power level in a given cell implies that you go and look :-)