Map Design - UQdeco2800/2022-studio-3 GitHub Wiki

Introduction

A core aspect of any RTS game is the game map, in which the core gameplay takes place. The map must be able to house a city of a fixed size, while taking up sufficient amount of space in the map to house the core resources of the game. A key challenge in the design was the infancy of the development cycle, which meant that constant gameplay factors such as the city size, enemy numbers and general gameplay loops were largely undetermined. This meant that any solution for the game map had to be adaptable and scalable, to fit the needs of the game as it progressed.

Enter MapGenerator

The solution to the demands of the game map was delivered in the form of the algorithm employed by MapGenerator, which possesses the functionality to generate a game map of a given tile width and height, which contains an island holding a city of set size.

Algorithm

The MapGenerator delivers its functionality by doing the following:

  1. Generate a 2D array of char of the width and height provided - to represent the entirety of the game map
  2. Fill each entry with an Ocean character - as any tile not filled by subsequent functions will be considered ocean
  3. Pick a random point on the map to place the city, such that the city dimensions of width and height will still fit - with a buffer to build the island around
  4. Pick two points on either side of the city, with the distance between them being the specified length of the island
  5. Iterate between each point and place a vertex, or edge of the map, with points being above the city
  6. Iterate between each point and place a vertex of the map, with points being below the city
  7. Interpolate between each pair of vertices and fill in the island

Development Issues

Although it was implemented fairly quickly, the algorithm encountered some key issues when implemented in the game engine

Map filling bug

Initially, the map filling function was encountering an error, as the edges of the map had potentially 3 vertices, instead of the usual two, causing an effect like this (below figure visualised after step 5 and 7 was completed, step 6 not implemented).

Entity placement bug

The game engine's default code comes equipped with placing isometric entities, however, it seemed as though this code was incorrect as entities spawned using the spawnEntityAt() function were being placed at a location slightly offset to their desired location. This behaviour is indicated in the below image:

This was resolved by editing the function which converted a tile point to a world point - which allows entities to be placed correctly on the map.

Testing

The map generation was complex to test, given it will have a different output each run, however several measures were taken to ensure its consistency.

  1. Exceptions were included in the map generation algorithm to informatively demonstrate where and when an issue arose. Issues were defined as any map generated without the desired qualities (i.e. size, island containing a map, etc)
  2. The algorithm was run 10,000 times to test speed, consistency and error rate
  3. Step 2 was repeated, with many bugfixes and algorithm development until no errors were present
  4. To further verify its efficacy, a function to output the map to a text file was written, and used to output the map as it was being built. Each stage of a map being built was confirmed to be built correctly, (i.e. choosing correct position of city, making sure island points are chosen correctly etc..)
  5. Step 4 was repeated over dozens of maps during development, until no errors could be recognised