Jump to content
  • Advertisement
Sign in to follow this  
suliman

RTS: keeping track of air units?

This topic is 690 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

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!

Share this post


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

Edited by slicer4ever

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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)

Share this post


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

Share this post


Link to post
Share on other sites

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.

Edited by suliman

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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)

Share this post


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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!