Generating resources on a 3D RTS map

Hello! I’ve been working on a project with a few others, it’s similar to Age of Empires, Stronghold, and so on. Right now I’m working on randomly generating a map for players to play on. Now, in both of those games above there are no random maps, obviously due to balancing issues… In this game, there is an overworld map (already done), which contains several smaller regions, and each of those regions has its own map (the ones were working on right now), which will only be used by one player each. So again, 2D overworld shows the relations between the 3D regions. Each region only has only player on it.

So far, using Perlin noise generation and terrains, there’s a nice rolling plains look going for the map. The next step of course is to populate that map with trees, grass/plants, and other resources such as iron and gold. The gold and iron will just be textures on the ground with some rocks sticking out, and the trees will be Unity trees. More specifically, these are some things I need help with:

What is the best way to place and keep track of textured resources like gold?

What is the best way to place and keep track of trees?

There is no grid system, so players will be building structures freely. It might also be inefficient to have new buildings check every frame if its a good place to build there or not, so perhaps calculating that somewhere else would be nice too. I’m also planning on just flattening out the terrain below a building, so angles wont matter there, nor will terrains be that harsh.

Currently my best lead is to create a grid system of ints that goes over that map, and says where what resources are where. 0 for empty, 1 for iron, 2 for gold, 9 for obstructed, etc. Check if all of the squares the building is in are 0, if not show that you can build here. Is there a better way to do this? Would this also work for trees?

I used to play age of empires a lot, if I remember correctly the basic format of a map was to position some resources near each of the players positions, and then add some more toward the middle. The closer resources would be used to build up each player’s forces initially, at which point each would make attempts to secure the resources toward the middle which were naturally more exposed to enemy attack due to being further from a stronghold.

At least, that’s the way it seemed to me, and it seems like it would cause a natural progression of gameplay. So I would try to start with something like that.

Thanks for the reply, but the issue of where to place resources isn’t the problem, but more so how do I place them. Do I follow a grid system of resources, or something else?

In that case, I think you’re doing it right. The grid system is going to be by far the easiest way to do it. Just store a huge vector of nxn elements where each element represents a grid point, and then store a vector of int values at each of these elements to represent all the things going on at that point.

No reason to make it more complicated unless you need to.

What exactly do you mean though by asking if it would work for trees? A tree is just another object.

Well, if the grid was very fine, and each grid element represented 1 tree, then you might have overlapping trees. Not only that, but you’d have a very obvious square array of trees. I’d have to make it so trees have a min distance between each other, but then it’d still feel a bit too grid like to me… I want it to look as natural as possible. If I made the grid very fine, and had a tree represent like a circle on it, it might look more natural? But then, making infinitely fine the grid system disappears, and we’re back to something else entirely…

This effectively does just that. and on sale at the moment.

Well this is something you have to work out harmoniously as you go. If your grid is very fine, your tree placement algorithm will have to adjust accordingly.

If you’re not sure how fine your grid should be, and you’re probably going to change it a lot and don’t want to break the tree placement algorithm, it’s probably easier to generate the tree positions on a separate grid and associate them with your game grid later.

So lets say for example you want a minimum distance between trees of dMin and an average of dAverage. Then, for the purpose of generating trees, the grid size would be dAverage and the maximum random offset radius from the center of each grid tile - lets call it maxOffsetRadius - would be equal to dAverage/2 - dMin/2.

So you divide your map into grids of side length dAverage, and generate trees by getting the center of each grid tile and offsetting in a random direction (for example using unity’s Random.insideUnitCircle), clamping the offset vector length (e.g. using Vector2.ClampMagnitude) to maxOffsetRadius.

Now let’s say that the grid system you use in-game is a different size. Then you have to convert the position of each tree you generated above, to your game grid (e.g. (int)(xPos/gameGridSize) would give you the tile index in x, and (int)(yPos/gameGridSize) would give you the tile index in y.

If that still looks too grid-like, it might be worth considering generating tree placement according to a perlin algorithm or lookup texture or something like that, but I’d give it a go a see if it’s enough.