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?
How to store hexagonical grid
Crossbones+ - Reputation: 16555
Posted 12 September 2013 - 07:59 AM
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.
Edited by Álvaro, 12 September 2013 - 08:12 AM.
Senior Staff - Reputation: 23519
Posted 12 September 2013 - 08:00 AM
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.