• entries
5
11
• views
6488

## Creation of Zergification tech demo: Town layout generation

Town generation

Time to explain in depth how I'm actually generating the town. My initial plan was to put all the generation code in the single world_builder class, however, quite soon I realized that it takes a lot of time to compile a class that big and I'll need to recompile it all the time. Because of that I have split the code into five classes:
o Builder_city
o Builder_wall
o Builder_buildings
o Builder_edges

Builder_city
The goal of this class is to create a smart looking town layout, save it to multiple 2d arrays and send it to the next builder class.

Step 1: Randomize grid size
I start by randomizing the size of the grids that i'm going to be using. This by changing variables at this stage I can easily change size and
aspect ratio of the town I want to generate.

Step 2: Create terrain shape
Terrain only exist in the town, so by creating shapes of the terrain we are creating town shape. I do this by drawing 5 rectangles. First one is
created in the middle of the grid and do not touch any of the grid the edges. Another 4 start at the middle square and are touching one of the
grid edges.

When I'm generating bottom square I'm saving its middle point, I'll use it later to create a gate.

Step 3: Generate the height of the terrain
First of all I generate hill shape by cutting terrain horizontally and vertically.

Then I select few random square areas and set their values to the average:

Finally, I take care of the location next to the gate:

Step 4: Create wall array
Creating wall array is really easy. Just copy terrain array and apply this logic for every cell:
If (All surrounding cells empty) -> set cell empty
Else if (None of the surrounding cells are empty) -> set cell empty
Else -> set cell full

I start road creation by adding road seeds. In essence road seed is just a point with direction and length. I add them in the middle of the squares I used to create terrain shape, gate location and a few random areas. Then I create roads out of them, road stops if it reaches a wall or another road.

Then it is time to break large empty areas. If the cell is empty and three cells to the left is empty or three cells down is empty set cell to full.

Next I check for for narrow areas, where is wall is on one side and cliff on the other. Places like that should always be a road. Finally, I check for cells that have different state than non diagonal surrounding cells and share state with at least one diagonal surrounding cells.

Step 6: Create buildings array
Building array is quite simple, it is an inverted road array.

Step 7: Spawn wall builder and send all data to it.

Obviously, no one could live in town with the layout like that, but it does not have to be logical, it just has to look like it. And there are many ways how to make it look logical, even when it is not.

Next time I'm going to write a bit more about wall_builder.

## Creation of Zergification tech demo: Humble beginnings

Hello, my name is Vaidas Okunis, I am studying game design at Staffordshire University. As a final year student I have to create my final year project. I wanted to create something big, ambitious and polished. I knew that I can not create game, that would take to much time, so instead I decided to create technical demonstration of the few game systems. And so Zergification tech demo have born !

What does it actually do ? It have two stages:
o Procedurally generates 3d fantasy town using modular pieces
o Creates a Zerg egg that morphs in to the structure and slowly consumes entire town, turning it in to the giant Zerg structure.

For this project I have decided to use Unreal Engine 4. After 6 weeks and countless curses in multiple languages (generating ramps is special kind of fun), I have a early version of the demo. Here is the progress video.

Now I can generate pretty looking towns, time to start making actual assets for the demo.

Join me next time, where i'm going to talk about some procedural generation tricks that I had to come with to make this work.

## Creation of Zergification tech demo: Fancy new video (again)

First of all, the project is still very much alive.
Second, making assets take a lot of time, so thank you for the patience. So what I'm working on now? I have a system in my framework that creates different districts in the town, only problem is that I don't have enough assets to show it. In a few months I would like to create enough assets so I could create a garden district and palace district. After I'll spend some time just gathering feedback and polishing. In about 4 (?) months I'll FINALLY start working on the actual Zergification. If you have any questions about the project or any of the technical details, just ask, I'll be happy to write an article or tutorial about it.
If you have any kind of feedback, please don't be shy and tell it, I'm always looking for ways to make this better.

## Creation of Zergification tech demo: Fancy new video

Here you go, new video of my project. New assets really help to show what i can do with my framework. New features in this build:
Special wall pieces (towers, gate)
Sand generation (still have some bugs, new assets are WIP)
Locations of the hero pieces (statues, wells and other unique looking stuff)
Different districts (at the moment marked by roof colors)
Micro variation generation system (at the moment only used to create small differences on the walls)

## 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 type
Top type property describes the shape of the peace from top view. Red part of the wall is always facing outside.

Front type
Front 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 type
Side 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_wall
The goal of this class is to take wall array and create a wall out of modular pieces. Step 1: Randomizing wall height
In 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" property
At 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 gate
I 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 pieces
In 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 pieces
And 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.