FIFE's map geometry

From FIFE development wiki
Jump to: navigation, search



Introduction

This article explains how the map geometry that was used in Fallout 1 and Fallout 2 worked for tiles and objects.

Single tile

Fo2 single tile.gif

Single hex

Fo2 single hex.gif

Tile coordinate system

  • 100 * 100 floor tiles for each elevation
  • 100 * 100 roof tiles for each elevation
  • 20.000 tiles total for each elevation
  • 3 possible elevations
  • Maximum of 60.000 tiles per .map file

The following picture illustrates tile id increment direction in Fallout

Fo2 tilecoords.png

FIFE's tile coordinate system

FIFE uses a different coordinate system than Fallout, the root is not the north pole of the map, but the west pole. This image shows how the coordinates are mapped in FIFE's internal coordinate system:

Fallout tile xy coords.jpg

Object / hex coordinate system

  1. 40.000 hex / object coordinates on each floor elevation
  2. Four hex /object coordinates on one floor tile coordinate
  3. No hex coordinates on roof elevations
  4. 3 possible elevations
  5. Maximum of 120.000 hex / object coordinates per .map file

Fo2 hexcoords.png

Hexagonal Implementation Details

Geometries are defined by an interface in engine/map/geometry.h. The two current implementations of this interface are gridgeometry.h and hexgeometry.h. Coordinates are converted between map coordinates and screen coordinates by the functions toScreen and fromScreen. The issue of converting a mouse screen coordinate to a hexagon selection is presented below.

Three properties specific to a particular hex definition are used:

  1. m_offset - offset of origin; this is just a constant added to all values
  2. m_basesize - the height and width of a single hexagon
  3. m_transform - roughly, the x and y distance each tile occupies

On a square grid, m_transform would have the same value as m_basesize. To see why this is not the case for hexagons, consider this image: Fallout Hex Tile.png

The total height of these tiles is 4 + 8 + 4 = 16, and their width is 32. However, when put together, tile 2 overlaps half of tile 1, so in a sense, each tile only occupies m_basesize/2 width. The same phenomena occurs with height, where we observe a 4 pixel overlap.

With these properties defined, we can compute tile coordinates. First, observe a hexagonal grid: FIFE hexcoords.gif

Notice that FIFE coordinates are stored in vector form, unlike the original Fallout data. Also, note the grid's axes are skewed, and that the positive x-axis runs opposite to normal conventions. To compute a tile coordinate from a mouse position p, consider this overlay:

Hex grid overlay.gif

The rectangular grid can be obtained (roughly--see hexgeometry.cpp) by dividing the screen coordinates by m_transform. A simple transformation (see source) can then map these rectangles to hexes.