Building the tech behind the world generation of Project Empires
haikalizz
March 14, 2018

Hello World!

Firstly, let me introduce myself. My name is Haikal Izzuddin, Lead programmer here at Prototype Studios, a small developer from Malaysia. We’ve been developing Project Empires, a turn-based strategy game for Windows. You can follow the project on our website or on IndieDB.


With Project Empires, we faced many challenges, one is how can we build the game world without designing it from scratch? This is when we turn to procedural generation for it. At first, it was just a flat map, with a heightmap generated from perlin noise.

As you can see from the image above, it was full of small islands, and has a lot of desert tiles. This wasn’t what we needed but we were happy with it for the time being. The tiles were hand-made, with the props already created into a prefab and was instantiated during game initialization.

This was the part of the code responsible in generating the map above. We’ve got hard-coded value range for each biome. With this, a typical map size of around 250×250 tiles can be generated within 50 seconds average. Recently, our team decided to ditch the square tiles for a hex one thus increasing the complexity of the generation.

To achieve this, we’ve generated the mesh using a 13-vert system. Each tile consist of 13 vertices, and is indexed in 0-1-2-3-4-5-6 for the inner ring, and 7-8-9-10-11-12 for the outer ring. All vertices in both inner ring and outer ring are positioned at the same place. The additional vertices on the outer ring are there to provide different UV mapping for different faces, even though this will increase the overall vertex count, but it allow us to paint different texture on the mesh.

The main hexagon surface is made out of 6 triangles, connecting vertices with the index of 0-1-2-0, 0-2-3-0, 0-3-4-0, 0-4-5-0, 0-5-6-0, 0-6-1-0.  Hexagon with 4 triangles is possible, but we need 6 triangles for a hexagon since we have to know which vertex is representing the center of which hexagon.

For example, (0, 0) hexagon start with vertices[0], and (0, 1) starts with vertices[13], by incrementing 13 for each vertex, we can calculate which vertices of the corresponding hexagon should be used to construct the rectangular/vertical face. We then draw the rectangular/vertical faces by knowing which vertices combination on the outer ring is aligning with the opposite edges of the subsequent hexagon.

Take the vertically first two hexagons for example, in order to draw a face connecting the north side of the first hexagon and the south side of the second one, we need to gather vertices with the index of 7, 8, 24 and 23. With all these information, we can draw all the hexagon tiles effortlessly.

 

With biomes, we’ve used simplex noise. Then we cross-reference the valued and see if it’s within range of the each biomes value. For example:-


Finished results

With everything setup in the scene, the system generates a wiremesh map for us as a debugging step.

The screenshot above shows the different biomes we were able to generate using this new system. While we’re still improving the system, we hope that in future iterations, we can also spawn props directly onto the terrain.

Props such as trees, rocks, etc, as to increase the realism of it.

The above screenshot shows the map at a different angle. Achieving height displacement, biome generation, and water generation.


Conclusion

We’vereached the end of our article for today. Hope you guys understand some of the new systems we’ve custom built for Project Empires.

Follow us on Twitter for more updates as we continue developing it.