Jump to content

  • Log In with Google      Sign In   
  • Create Account

How to store hexagonical grid


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1   Members   

2520
Like
0Likes
Like

Posted 12 September 2013 - 07:39 AM

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?


never mind my signature, I haven't updated it since 2016


#2   Members   

20266
Like
1Likes
Like

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.


#3   Senior Staff   

24740
Like
1Likes
Like

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.



#4   Members   

1132
Like
1Likes
Like

Posted 12 September 2013 - 08:46 AM

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




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.