Simcity clone - powering the city

Started by
9 comments, last by RobotechII 18 years, 1 month ago
Quote:Original post by jhoward
I've been developing a SimCity clone for java based phones:


The problem I am having is the design of the power system, and how a building knows if it is powered properly. This is the algorithm that I originally thought up:

for(every tile in the map)
{
powered = false
if(tile is power source) then powered = true
else if(neighbouring tile is powered) then powered = true
}

This is fine for starting off, but a problem becomes apparent when disconnecting a power line, or the power source is destroyed. Buildings that should not be powered remain powered. This is because buildings next to each other effectively power each other.
The only other idea of mine is to keep a table of power sources, and then every now and again branch from each power source and power buildings.
Any other ideas?


Your problem is that you need to go through all the tiles and assign all of them to powered=false first. Then work your way recursively from the powerplant(s) to check to see if the tile is power source or neighbor tiles is powered.

You may be already be doing this but if not I think it would be cool to limit the power a powerplant can supply. Let's say you assign a number to each power plant based on how much power it can generate(ie. a nuclear reactor would have more power than a coal plant) and each connected building will subtract from that number so that when you have too many buildings connected you have a brownout.

Screeny looks nice BTW.

This topic is closed to new replies.

Advertisement