Data structure for a map for a Civ-style game

Phlegmak

Deity
Joined
Dec 28, 2005
Messages
10,966
Location
Nowhere
This thread is about the data structure that you would use in a Civ-style game and also about the coordinate system you would use.

1. What I opted for I think is not ideal. If you start up the Civ 2 map editor and display the coordinates of the tiles, you'll see what looks like a Cartesian graph. However, every odd row is pushed 1/2 a tile to the right. That's the exact same coordinate system I used. So, with a coordinate system like that, it's easy and straightforward to use an array to represent the map. Figure 2 in this web page is identical to what I used and what Civ 2 uses:
http://www.gamedev.net/reference/articles/article837.asp

2. Another coordinate system which I've seen is to use coordinates that are a Cartesian graph rotated 45 degrees. Imagine a Civ 1 map. It's all squares. The squares have coordinates just like a cartesian graph, but with 0,0 in the upper left corner and y increases downwards. Now rotate the whole thing 45 degrees, keeping the coordinates you already made. For this coordinate system, both y and x increase to the right and down.

I found a diagram of that sort of coordinate system. It's the image at the top of this web page. However, what I was explaining above is that 0,0 would be an actual tile.
http://www.cs.queensu.ca/home/dalamb/java/doc/other/ca/queensu/cs/dal/tile/Isometric.html



I've been wondering what is the benefit of using the 2nd method.

The benefit of the first is that representing the map with a data structure is straightforward and simple: a 2d array. It's a pain to do other things like compute what is northeast or southeast of your current tile, but it's no big deal.

For the 2nd method, if you had a big square map (like Civ 2 or Civ 3) and those coordinates, then representing it with an array is not straightforward, unless you want to have some wasted space in your array. I read on some game algorithm page that the author was of the opinion that the 2nd method is better than the 1st. I don't remember why. I don't see what's so special about the 2nd method.
 
To calculate the direction to another tile in the 1st method is simple, each tile is prepresnted by a struct or class, and in that you have an array of 8 pointers to each tile surrounding a tile. This can be precomputed before your main loop starts.
 
Back
Top Bottom