In Freeciv, many game rules are based upon the distances between two entities. Players may wish to know how these distances are calculated.
There is no single answer applying to everything in Freeciv. This is because:
- Map topology - tiles may be hexagonal or square
- "Distance types" - Freeciv uses 3 distinct ways to calculate distance depending on the mechanic involved.
Distances on maps with square tiles[]
On a game with square tiles, there are three possible ways to calculate distance:
- Real distance: least number of moves between tiles
- Manhattan distance: non-diagonal moves between tiles
- Euclidean Distance: the true distance calculated by the Pythagorean Theorem
Real distance[]
How many moves a unit with no limitations (e.g., airplane) takes to go from tile A to tile B.
Real Distance
Manhattan distance[]
Non-diagonal moves between tiles. That is, |x+y|, where x is the east-west distance and y is the north-south distance.
Manhattan Distance
Euclidean Distance[]
This is the true mathematical distance between the center of one tile and the center of another tile, which can be expressed by the Pythagorean theorem. Distance2 = X2 + Y2 or, Distance = √(X2 + Y2).
Euclidean distance
👉🏼 To avoid decimals, Freeciv uses a "shortcut version" of Euclidean Distance called Square Map Distance, which is Distance = (X2 + Y2). It still keeps distances in order (though not with the same geometric relationship), but keeps to integer numbers without needing decimals or square roots.
Which game mechanics use which distance types[]
| element | type |
| Action legality on nearby tiles | Real |
| Paratrooper range | Real |
| City corruption | Real |
| CLASSIC Trade Revenue (distance-based) | Real |
| Migration between cities | Real |
dispersion (game setting)
|
Real |
| Attacks | Real |
| Bombard / Special Attacks | Real |
| Minimum distance for Trade Routes | Manhattan |
| Cost to bribe a Unit | Manhattan |
| Cost to incite a City | Manhattan |
| City Vision, distance | Euclidean |
| City Radius (workable tiles), distance | Euclidean |
| Unit Vision, distance | Euclidean |
| Vision distance for Military Bases | Euclidean |
| Permanent tile ownership distance, cities | Euclidean |
| Border calculations, cities | Euclidean |
| Visibility of Stealth types | Euclidean |
| Visibility of Submarine types | Euclidean |
Hexagonal topology[]
Freeciv was originally designed as a Square Tile topology only. The introduction of hex topology required the conversion of rules, formulas, and mechanics into their nearest simulacra for games played on hex maps:
- REAL DISTANCE remains unchanged, the least number of moves between Tile A and Tile B.
- MANHATTAN DISTANCE and REAL DISTANCE become identical under hex topology.
- EUCLIDEAN DISTANCE remains the true mathematical distance between the centers of Tile A and Tile B.