Creation of Zergification tech demo: Creating modular walls

Outer wall generation

When starting to develop a complex system I like to start with a list of limitations that the system is going to have. You can use every limitation to your advantage.

Limitation 1: Walls have no T or X junctions.Limitation 2: Walls always for closed loop.Limitation 3: Walls can only placed on the flat surface.

What are the cons of these limitations ?The general shape of the walls lacks variety.Some of the popular patterns that are used in the real world can not be used.

Pros of the limitations?Drastically reduces the number of modular pieces.It is very easy to trace along the wall (it will solve a lot of problems in the future)

Now we can start thinking about modularity of the assets. Every wall piece can be described with 3 properties: top type, front type and side type.

Top typeTop type property describes the shape of the peace from top view. Red part of the wall is always facing outside.

Front typeFront type property describes where the piece is vertically. If the wall is taller than 3 pieces, middle pieces can be duplicated without breaking modularity.

Side typeSide type property describes how tall the wall is on the sides.Some of you might notice that there are no "one lower" condition. I treat it the same way as "same level", because next to it is always a piece with "one higher" condition and i made sure they would connect seamlessly.

So we have 12*3*16=576 variations ... scary number, but we need to remember that not all combinations are valid.Now we have 12(16+4+1)=252 variations ... still kind of scary. But 252 conditions do not mean 252 modular pieces, we can reuse same meshes and simply rotate and/or flip them. With that in mind it brings us down to 3(10+3+1)=42. Still a lot, but at the moment I could not come up with the method to reduce this number. Later I have found some ways to do it and I used that for road generation. I'll explain them when I'll be talking about roads.

Builder_wallThe goal of this class is to take wall array and create a wall out of modular pieces.

Step 1: Randomizing wall heightIn order to create a more interesting silhouette I select random areas of the wall and add some height to them.

Step 2: Calculating "Top type" propertyAt first I take wall array and read it from left to right starting with top left corner. First not empty cell is always L4 type. Then i trace the wall from that point(clockwise), always checking which wall is previous and next cell. This way i can identify type of every piece in the wall. For example I3 type always have previous cell on the left and next on the right.

Step 3: Spawn gateI grab gate position from city_builder, spawn gate into the world, change height of the wall in the place where it connects to the gate, mark cells that overlap with a gate as "created".

Step 4: Spawn special piecesIn the video that I posted this was not implemented, but in the new version I'm replacing some of the areas of the wall with special peaces, like guard towers at the corners. The procedure is identical to spawning gates, except for the location. I get the location for the special peaces by tracing wall and checking for patterns in "top type" property. For example, if I find the sequence I3, I3, L1, I4, I4, I know that it is the corner and I replace it with the guard tower.

Step 5: Spawn generic piecesAnd finally go through the wall array one last time, checking for the cells not marked as "created" and spawn mesh based on 3 properties described earlier.

Step 6: Spawn building builder and send all relevant data to it

Next time I'll talk a bit more about how and where i spawn buildings. Also hopefully by then i'll have new video that will show you some more features.

If you have any questions or you want me to explain something in more detail, don't hesitate to ask.