• Advertisement
Sign in to follow this  

How to store hexagonical grid

This topic is 1594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Edited by Álvaro

Share this post


Link to post
Share on other sites

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.

Share this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement