RTS: keeping track of air units?

Started by
8 comments, last by ErnieDingo 7 years, 3 months ago

Im doing a 2D grid-based retro rts like dune 2 (using c++). Land units and buildings are referred to by a pointer for each tile: if the tile is not empty, it points to the unit standing there.

So units can quickly find nearby units when scanning for targets (for example)

I just added air units, they move regardless of tiles and can "swarm" like air units in starcraft/starcraft 2.

So many can be "on" the same tile.

What is a good way to handle them? I have all units in the world in a list but looping through them might get slow when the unit count gets very high.

Should i have a airUnitList for each tile and move the unit reference between these lists when the unit is moving?

A lot of lists!

Or maybe lists in a grid covering 10x10 tiles each?

What would you recommend?
Thanks!

Advertisement

based on how you currently have things, i think the easiest solution would be to modify each tile to allow n number of units on it, then make max n some size that seems unreasonably likely to ever actually happen(this well probably also require checks from your aircraft that they can't move onto a tile which is already saturated with units).

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

Or maybe lists in a grid covering 10x10 tiles each?


That sounds like a reasonable idea. I assume the units themselves contain their own position somehow?

If you look at some RTS games, they have flocking behaviour for air units, so that when you have a lot together they keep a reasonable space between each other.

If they 'stack' on the same grid location, it becomes hard to select individual units, which basically creates a UX issue. Something to consider, i guess...

Yes i need flocking (separation) for air units. However I still can have a lot per tile (for example after movement order) so I dont think a hard cap on units allowed is good (how do I disallow air units to travel into a tile without breaking airspeed physics for example?)

If I use lists, do lists covering 10x10 tiles make more sense than individual lists for each tile? And if so, why? Quicker, less RAM? (maps are typically 120x120 tiles)

Why not have two separate grids that overlay each other?

You can have a ground grid for ground unite and an air grid for flying units whose coordinates overlap.

But air units dont move in concrete tiles, they can be "anywhere" (the position is simply float x and float y), so I need lists basically. And place each air unit in the list belonging to the area they are currently hoovering.

Any problem with a list for each tile (instread of a list per 10x10 tiles)? (lets says 120x120 tiles for a map = 14 000 small lists handling the air units, most of them empy, since most tiles will have no air units hoovering them).

That would make other code easier to make (scan for enemies etc) compared to lists for each 10x10 tiles.

Not sure this is any better, but to push you out of the tile-oriented solutions:

Let go of the tiles, and make a list (vector?) of air units, sorted on eg x position.

Searching would then need a range in x, which maps to a range of the above list.

Obviously, you need to check y position of the air units in the range too, before concluding they fly overhead.

I think I'd start with a single list, abstracted so that very few things need to know it's a single list, and then swap it out to something more heavyweight if you start to run into issues. (Either via playtesting or via profiling)

At the moment in my game im using a grid but the move to a hash table with associated list for all units. It seems to be the fastest way. If your units are moving freely then i would do some sort of rounding of the coordinates and use those values to reference the table.

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

This topic is closed to new replies.

Advertisement