The goal is to create a hex map editor using Lazarus and Free Pascal.
The editor will maintain two representations of the map:
The working copy does not need to resemble the final map particularly closely. Significant liberties can be taken with its visual representation, provided that the underlying hex relationships remain correct.
The exported map will be generated from the working data rather than edited directly.
The initial proposal is to represent the working map using rectangular cells rather than actual hexagons.
The cells are arranged in staggered vertical columns:
This approach offers several advantages:
The logical representation remains a hex grid, even though the editor displays rectangular cells.
The intended hexagon orientation is flat-top.
This means:
This corresponds to the conventional flat-top, staggered-column hexagonal layout.
The working rectangles should be proportioned according to the geometry of the underlying regular hexagons.
The requirements are:
Let:
For a regular flat-top hexagon:
Hexagon width = 2R Hexagon height = sqrt(3) * R
The upper-right diagonal edge, for example, runs between:
(R/2, H/2) (R, 0)
Its midpoint is:
X = 3R/4 Y = H/4
Consequently, the vertical boundaries of the working rectangle should be positioned at X = ±3R/4 relative to the hexagon centre.
This gives the following working rectangle dimensions:
Rectangle width = 3R/2 Rectangle height = sqrt(3) * R
The resulting aspect ratio is:
Width / Height = sqrt(3) / 2
≈ 0.8660254
The working rectangles are therefore slightly narrower than they are tall.
Adjacent columns are vertically offset by half the height of the working rectangle.
ColumnOffsetY = RectangleHeight / 2
= sqrt(3) * R / 2
In other words, if the rectangle height is H:
ColumnOffsetY = H / 2
Alternating columns receive this offset.
For implementation purposes, it is convenient to choose the desired working rectangle height first.
Let H be the working rectangle height.
The remaining dimensions are:
Hexagon radius = H / sqrt(3) Rectangle width = H * sqrt(3) / 2 Rectangle height = H Column vertical offset = H / 2
These formulas provide the geometric relationship between the symbolic working grid and the regular flat-top hexagons used in the exported map.
The working map should be treated as a data structure first and a graphical representation second.
Potential implementation components include:
An important design principle is to prevent the rectangular appearance of the working grid from influencing game logic.
Distance calculations, adjacency, area effects, and pathfinding must all use hexagonal relationships.
The next logical development steps are:
The central architectural decision is to keep the symbolic editing representation independent of the artistic presentation representation.