(Original)Terrain Analysis in Computer Games

download

of 22

  • date post

    02-Mar-2015
  • Category

    Documents
  • view

    178
  • download

    2

Embed Size (px)

transcript

TERRAIN ANALYSIS IN COMPUTER GAMES

Coord. Prof. Dr. Lect. Vlad Radulescu

Asavei Florin, ISS1 Cristian Catalin Mihai, ISS2

1

Summary

Introduction 1. Terrain representation 1.1. Tiles 1.2. Quadtrees 1.3. Waypoints 2. Pathfinding algorithms 2.1. Trial and Error 2.2. Contour Tracing 2.3. Collision Avoidance Tracks 2.4. Waypoint Pathfinding 3. Real Pathfinding 3.1. Breadth-First Search 3.2. Bidirectional Breadth-First Search 3.3. Depth-First Search 3.4. A* 3.5. Quadtree Search 4. Dynamic Caching for Path Planning 5. Dynamic Terrain Analysis 6. Influence Mapping References

... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...

3 4 4 5 6 7 7 8 9 9 11 12 12 13 13 16 17 18 19 22

2

IntroductionThe purpose of this work is to illustrate the importance of terrain analysis in computer games. There are a number of methods employed in order to perform such analysis or a combination of them. Each of them are particularly suitable for a certain kind of game, or where a certain genre characteristic is more predominant. Terrain analysis has a direct impact over the way that CPU AI is taking action, the decisions that the AI part of the game takes are based mostly on the data regarding the game environment. The entire game environment, no matter the complexity form or shape, has some notion of a terrain. Every active or inactive part of the environment, including the player controlled objects, and the computer controlled ones, are subject to a relative position on the terrain, and to one another. Knowing were is some object in the environment or at what position from a different object it is placed influences the way the game it is played, that kind of knowledge it is achieved trough terrain analysis. Another part that has a direct connection with terrain analysis is influence mapping, knowing which areas from the game environment to avoid or to pass trough, to find a weak spot in someones defense, or to know the vantage points, such as high ground for a certain type of playing units or the areas that contain a certain amount of a certain resource. Terrain analysis is influenced by the type of the terrain that it is applied upon, aspects like material and height are influencing the computation of an alternative route to some destination, or taking the decision to attack someone or not to. Path finding is directly connected to terrain analysis because computations regarding the path to follow towards a certain destination and the cost implied in order to achieve that spot are used in influence mapping, also, influence mapping can alter the path that a unit can take, for example if an area on the map has a high rate of conflict, a worker unit, that has no attack ability will avoid that area, taking a longer and safer path. These are some of the situations and notions that will be explained in the following sections, and also ways to implement them, compromises that were needed to be made in real games to balance the performance and fun factors. The main thing is that there is no AI without terrain analysis, these two are tightly connected since the AI part cannot take any decisions if it is not aware about the surrounding environment. Terrain analysis does that for the AI, and figuring out where you are in the game takes a lot of computation time because of calculations has to be made at every iteration, because parts of the game can move or be altered, position of some objects can change (opponent players for example), path obstruction, or creation of some new access routes just to name a few. This paper uses fragments from the works listed under the bibliography, the purpose was to gather all of the scattered information into one place and structure it in order to give the potential reader a kick start overview over what terrain analysis involves. There was no intention to break the intellectual property of any of the sources used here, it's just an academic research paper that tries to shed some light into the more difficult and challenging aspects of game programming.

3

1. Terrain representationWhen talking about terrain analysis firstly we must consider the ways in which the terrain is represented. There are more approaches to this problem although any combination of them can be used. The approach in which the terrain is represented must allow the appliance of path finding algorithms, and the ability to create areas or better said mark some portions of the terrain. When referring to the terrain it is usually aliased with the term of a map, this is not a comprehensive term, since the map is a representation of an terrain, and the terrain has multiple particularities such as composition, humidity, height, etc. opposed to a map that in the classic term is nothing more than a piece of paper. Since we are talking about a game world and not about the real world, we can consider the map and the terrain one and the same thing, since both in computer games are a representation of the game space, the differences between the notions, if applicable will be pointed out where necessary. The main logic structures used to give meaning to some regions of the game map, on which a path finding algorithm can be successfully applied are tiles, quad trees and way points.

1.1. TilesA tile-based video game is a type of video or computer game where the playing area consists of small rectangular, square, or hexagonal graphic images, referred to as tiles. The complete set of tiles available for use in a playing area is called a tileset. Tiles are laid out adjacent to one another in a grid; usually, some tiles are allowed to overlap, for example, when a tile representing a unit is overlaid onto a tile representing terrain. Tile-based games usually simulate a top-down or "2.5D" view of the playing area, and are almost always two-dimensional. Tile-based games are not a distinct game genre; rather, the term refers to the technology a game engine uses for its visual representation. The map is probably the single most important data structure in a game of this type. The map serves as the central repository of nearly all game data and is the primary source of information used by the game logic. The various units, "fog of war", unit AI, and so on, all rely extensively on the map. The most basic structure of the map is the map cell. A map cell is simply a single map location. The information you store in a map cell depends on the game you're creating, but there are a few common elements. Such common elements include an indicator of the type of map cell (for instance, the terrain), the structure (or structure segment) built on the cell, and a pointer to the first mobile unit on the map. Once you have your map cell defined, you have to decide how you want to structure the entire map. Here we have to refer back to your game design concept and how you want the finished game to look. There are 3 primary "looks" that are popular: straight overhead, angled isometric, and layered isometric. The straight overhead map and angled isometric map have the simplest possible scenario: a two4

dimensional array of map cells. The layered isometric map can also use a two-dimensional array, but there are several complexities. The biggest difference concerns adjacencies in the map.

Isometric grid adjacencies Layered isometric maps, however, are significantly more complex. This is because, while the map is still a two dimensional array, the adjacencies work differently because of their on-screen representation. How adjacency is calculated varies according to whether the map cell is on an evennumbered row or an odd-numered row.

1.2. QuadtreesA quadtree is a tree data structure in which each internal node has exactly four children. Quadtrees are most often used to partition a two dimensional space by recursively subdividing it into four quadrants or regions. The regions may be square or rectangular, or may have arbitrary shapes. All forms of Quadtrees share some common features: They decompose space into adaptable cells ; Each cell (or bucket) has a maximum capacity. When maximum capacity is reached, the bucket splits ; The tree directory follows the spatial decomposition of the Quadtree. Quadtrees may be classified according to the type of data they represent, including areas, points, lines and curves. Quadtrees may also be classified by whether the shape of the tree is independent of the order data is processed. The region quadtree represents a partition of space in two dimensions by decomposing the region into four equal quadrants, subquadrants, and so on with each leaf node containing data corresponding to a specific subregion. Each node in the tree either has exactly four children, or has no children (a leaf node). The region quadtree is not strictly a 'tree' - as the positions of subdivisions are independent of the data. They are more precisely called 'tries'. 5

The point quadtree is an adaptation of a binary tree used to represent two dimensional point data. It shares the features of all quadtrees but is a true tree as the center of a subdivision is always on a point. The tree shape depends on the order data is processed. Edge quadtree are specifically used to store lines rather than points. Curves are approximated by subdividing cells to a very fine resolution. This can result in extremely unbalanced trees which may defeat the purpose of indexing.

1.3. WaypointsAny of the form of representation presented earlier can be a fundament for this one. This is nothing more than an augmentation of the above by annotating the terrain with hand-selected places that movable entities can be i