How to store hexagonical grid

Started by
2 comments, last by SuperVGA 10 years, 7 months ago

I am making a settlers clone and I am wondering how to store the map. I need to store at least a object for each tile and a way to store roads and villages. Anyone have any idea on how this should be done?

My CVMy money management app: ELFSHMy game about shooting triangles: Lazer of Death
Advertisement

I haven't thought about it very carefully, but I think I would have three 1-dimensional arrays: hexagons, edges and vertices. Each element should know what other elements it's adjacent to (so a hexagon knows which roads and vertices surround it, an edge knows what hexagons and what vertices it touches...). They should also know their coordinates on the map, but that's only used for representation.

Think of what kinds of operations you will be performing very often. For instance, if a player rolls a 9, you'll want to loop over all the hexagons labelled "9", so I would sort the array of hexagons by this number and make a little array indicating the breakpoints between numbers. If you can think of some operation that wouldn't be made fast by the structure I suggested, perhaps it needs tweaking.

You can find some good information on hexagonal grids linked from this page. In particular, this is an excellent guide which contains a brief section on map storage. As to the technical details of storing objects, you can just add some value (at the simplest just an integer with values representing object types) with each tile.

- Jason Astle-Adams

It can still be stored as a 2D array, with every second column (or row) shifted by half a tile's "lower width".

This topic is closed to new replies.

Advertisement