City building game

HEY i was wondering how i would make power lines/pylons in a city building game, so that you can place one then place another anywhere and the wires would join to the first one and so on. I would also like to see how this could possibly work on roads too. Any help would be appreciated! :slight_smile:

So u are trying to build a Sim city style game?

yeah kind of! and i wanted to have power stations that you can connect power lines to, to give power to houses and other buildings :slight_smile:

I’m not really sure, but I would be interested to hear too if somebody knows the standard solution!

(There must be a proper term for this technique, but I don’t know what it is)
I call it Binary Neighbor Indexing, because it sounds smart.

Each road tile is given an integer property called Index, which will correspond to which mesh to use for that tile, based on its neighbors (adjacent road tiles).
-If a road is to the north, add 1 to Index
-If a road is to the east, add 2 to Index
-if a road is to the south, add 4 to Index
-if a road is to the west, add 8 to Index

On a hidden layer, create the 16 possible road pieces as individual meshes, and call them something like ‘Road0’, Road1, Road2, etc

Road0 will be a ‘four-way dead-end’ with no neighboring tiles.
Road1 is dead-ends in all directions but north
Road2 is dead-ends in all directions but east
Road3 is a corner leading north and east (north=1 + east=2)

Road5 is a straight-away leading north/south (north=1 + south=4)
Road10 is a straight-away leading east/west (east=2, west=8)

The trick then, is to check for neighbors, tally up Index, then set that road’s mesh to ‘Road+str(Index)’!

I think nines is on to something there.
Maybe if you have each grid stored as a multidimensional array, if python supports that. I’m not sure if it does.

So GameGrid[0][0] (X,Y)

starting at grid[x][y]
if grid[x+1][y] = powerline:
grid[x+1][y].powered = true
Do the same for the other directions
Run again for each tile that is now powered = true. Encapsule the checking in a function so you’re not writing it.

Starting at the power station, it triggers adjacent tiles that they are powered. Each of one of those tiles (if they are a powerline or building) then tell the tiles next to it that they are powered and so on. Then it filters to you houses that are joined.

EDIT: I don’t think you would need to check the whole grid every frame.
I think, every frame, check current tiles, set whatever ones to true, and then on the next frame check all that are now true for the same. This will gradually filter out to end points and they will stay true. When the power stops they will filter back again.

This is an operation on your game model. How you do it is your choice (Python, 3D mesh, mix …).

Remember that all have to work in a visisble 3D grid
so you have to make the code work also whith a grid in the plane

pretty much , you have to do your >PATHFINDER<
strongly suggested to each one that want do something of complex with lists and dictionaries :slight_smile: