Advertisement

Unit groups in a RTS

Started by December 22, 2024 09:13 PM
11 comments, last by Calin 13 hours, 7 minutes ago

In Starcraft when an AI Player is attacking you what you have is a thin constant stream of units arriving at your base. What does it take to build an alternative? In Total Annihilation the AI player waits until a group of units has pilled up and then attacks. If the attack is unsuccesful the remaining attacking units retreat. The Total Annihilation approach probably works the same as Starcraft except the retreat. The maps layout in Starcraft probably causes the units to spread like a stream. How does a typical RTS AI player attack work? Select all combat units, Attack-move selected combat units to the enemy base?

My project`s facebook page is “DreamLand Page”

There have been a lot of variation in games over the decades, so there really isn't a “typical”.

Some games have mini-formations, like a group of 5 soldiers may cluster and move as a group taking a single tile. Some games have included commands to keep a formation, so you could place them in a particular ordering and they'd advance at a uniform speed based on the slowest units, such as creating a line of soldiers and they'd hold the line as they travel or attack or retreat. Some games have included automatically-issued commands causing units to scatter or evade defensively, or standing orders to hold position or not return fire rather than evade or counterattack.

The logic is typically implemented as nested state machines. Logic may be to move toward a target, patrol between points, react to getting attacked taking any of various sub-choices depending on what is attacking, and much more. The limit is usually more about development budget and time than it is about creativity, as designers with unlimited time and money could devise a tremendous number of commands and flows.

There are also hundreds of articles over the decades with all kinds of explanations of grouping behavior, flocking behavior, pathing together vs pathing independently, treating clusters as a single unit for pathfinding instead of a bunch of tiny objects all doing their own search, and much more.

Advertisement

There have been a lot of variation in games over the decades

I see what you're saying. Age of Empires 2 had formations. That's a bit more intricate than just select and move everyone to the enemy base.

My project`s facebook page is “DreamLand Page”

Even that, “select everyone and move to the enemy base”, do you want them to stay together, or do you want some type of strategic organization?

Do you want the fastest moving units to arrive first, before the slowest, or do you want them to arrive as a cohesive whole? There are merits to both.

Do you want new units to arrive and attempt to join the formation as a cohesive whole, or just wherever you clicked?

Do you want newly formed units to replace the ones that were lost in the formations, or to meet at some other waypoint?

All are good ideas, and all require implementation.

Even that, “select everyone and move to the enemy base”, do you want them to stay together, or do you want

If it's the most basic scenario ever there's just one way to do it.

My project`s facebook page is “DreamLand Page”

Calin said:
If it's the most basic scenario ever there's just one way to do it.

That's the grand picture, the simple idea on top, the lower frequencies, the highest level abstraction, or however you call it.

But below that lurk the depths, the details, the complexities, and with it comes the opportunity to add depth to the game.

At least that's how you can think about it. While in reality it's mostly just a pile of unexpected work, i would say.

Anyway, what i try to say is that your quote does not hold - if we take a closer look.
Even if all my units are supposed to just walk to the enemy base, there is never only one way to do it, if there are multiple units.
As the player i will observe their behevior. I will notice how they prevent collisions with each other etc., and i will judge if it looks natural or silly.
Ideally i'll enjoy the observation. In german they call it ‘Wuselfaktor’, meaning to watch hundreds of cute tiny settlers building a village or having some daily routines. It's important players find this satisfying to watch, and i guess the same also applies to other top down genres like RTS.

Your latest video showed good progress on this. The behavior looked much smoother, and no more visible ‘silly computer AI’ corner cases.
But improvement is still possible, and will become necessary once better graphics expose more details.

Now i see two options to continue:
1. Decide about features you want. E.g. if you want clearly defined formations, work on that. E.g. let them form a N x M grid pattern and they should keep that in shape while moving along a common path.
2. Don't implement such features yet, but instead improve the default behavior so it looks more natural and units appear smarter. Eventually you'll have tuning parameters to define the behavior, and simply changing those parameters will affect if they walk in a straight line if they have a commonm goal, or if they form a blob shape. (If you have terrrain, this should also affect those things.)

You said you want to make a generic RTS AI, iirc.
But sooner or later you get down to the depths of all those details no matter what, and at this point it becomes easier to make just one specific game instead some genric default AI supposed to serve any game design.

Advertisement

That's the grand picture, the simple idea on top…

…But below that lurk the depths, the details,

You can have a simple implementation too it's not just about ideas. One thing can have different levels of complexity.

My project`s facebook page is “DreamLand Page”

Calin said:
You can have a simple implementation too it's not just about ideas. One thing can have different levels of complexity.

Well, yes. But it rarely works to keep it simple. People say ‘don't be stupid - keep it simple! :D’.
But the reality is: You start with complex solutions. And only after you became a true master working on those, you become able to replace the complex with a simpler and better solution, where possible.
Simplicity is not something you can just do. It's the result of optimizing former complexity, and creative ideas are often needed to get there.

Ofc. this only applies if the given problem is difficult. If it's a trivial problem, you can google for the common solution und use just that.
Probably complex behavior of many RTS untis is neither trivial nor simple.

It's like in physics. They can predict the trajectories of two stars affecting each other, but adding just one more star destroys the simplicity, causing unpredictable chaos.
Likely you can't avoid the chaos either, and probably you shouldn't anyway, since it is a source of ‘emergent behavior’.
But usually we need to keep the chaos under control somehow, meaning your units behavior should still look reasonable and natural even in unexpected / crowded situations.
It helps to have debug setups to create such exaggerated difficult / impossible situations.

You can have a simple implementation too it's not just about ideas. One thing can have different levels of complexity.

But my purpose here is to learn. I'm not going to start teaching a senior programmer about RTS games.

My project`s facebook page is “DreamLand Page”

JoeJ said:
Well, yes. But it rarely works to keep it simple.

It's buggy, short sighted but it works. )

My project`s facebook page is “DreamLand Page”

Advertisement