kyranf / robotarmyfactorio

A mod to add robot troop units and perhaps associated support buildings and items to produce and control them.
MIT License
35 stars 11 forks source link

Squad AI could use some improvements #57

Open jorn86 opened 7 years ago

jorn86 commented 7 years ago

First of all, thanks for making an awesome mod, I like it a lot!

There's a few issues I'm running into with squads deciding how and where to attack, though.

When a squad of 30 goes out to attack something, usually half the squad gets stuck behind some trees for a short while, causing half the squad to engage then die, slowly reinforced by the other half which then suffers the same fate. It would be better if the squad waited for every member to be there (just defend themselves against attackers from the nearby base), and engage all together. This problem gets worse if there are worms in the base, since a small worm kills a battle droid in 2-3 hits. To make it even better, perhaps a squad should hold a "formation" of sorts with the battle droids and/or flamebots up front, and the rocket droids in the back, allowing rockets droids to take out the worms before the droids even get in range of them.

The "squad size hunt" setting works well when deciding when to leave from the spawning point, but once a squad has left it seems to count the distance from itself rather than the spawning point. So, it will just keep going out further and further instead of in a nice circle around the spawning point.

Possibly related, I've never seen a squad return after it suffers some casualties. For example, I have set 'squad size hunt' to 30 and 'return size' to 20. If a squad of 30 goes out, kills some bases and suffers some losses, let's say 15 bots are left, they will happily continue attacking until all droids are dead instead of returning to the spawn point.

Using version 0.2.2

kyranf commented 7 years ago

Parts of the squad getting stuck on obstacles (bodies of water, trees, rocks etc) is just part of the shitty Factorio pathfinding. There's literally nothing I can do about it... They already do "hold formation" which is why their speed is sometimes slow, while they wait for others to catch up, and when moving off to a distance location they will move together into a blob first, and THEN move as a group to the destination. If some members get caught on obstacles though, the group continues on and it goes horribly wrong from then on. Each individual will try to kill trees etc getting in the way, but that's usually too slow/not useful enough to keep the squad together. Fancy formations with proper allocation of droid types in front/mid/back is also beyond the scope of the mod, sorry.

The "squad size hunt" setting works well when deciding when to leave from the spawning point, but once a squad has left it seems to count the distance from itself rather than the spawning point. So, it will just keep going out further and further instead of in a nice circle around the spawning point.

This is intended - squads find targets nearest to THEM, not their spawner. Squad AI is from the squad's perspective, they are spawner-independent. It was simplest for me to implement this, because it makes it more complicated to allow the users to still place droids by hand, which I think is important to keep. I might do an overhaul of how squads are handled and make them assembler-centric which is probably better in the long run.

let's say 15 bots are left, they will happily continue attacking until all droids are dead instead of returning to the spawn point.

This is not intended, perhaps the retreat mechanic broke or perhaps the settings module override is broken (and it just follows the config.lua value instead.) Could you help me test this by changing the retreat setting in the config.lua file to 15 just like you have the setting on the settings module and see if they start retreating properly?

jorn86 commented 7 years ago

Thanks for the reply!

This is not intended, perhaps the retreat mechanic broke or perhaps the settings module override is broken (and it just follows the config.lua value instead.) Could you help me test this by changing the retreat setting in the config.lua file to 15 just like you have the setting on the settings module and see if they start retreating properly?

I tested with squad size 40, retreat size 20 in config.lua and 35 in the settings module. The squad went out. After killing one base, 35 bots were left. Squad continued to the next base. That was a big one, so the squad slowly diminished from 35 to 0, never trying to retreat.

Then I tested the same attack with a squad of 21, retreat at 20 in the config and 10 in the settings module. The squad took 4 casualties clearing the base, but did not retreat until it was done.

Looks to me like the setting from config.lua applies, but only after a squad finishes taking out a base.

kyranf commented 7 years ago

Well yes, the squad doesn't retreat in the middle of battle.. only if the squad gets a break in fighting does it evaluate the squad size and attempt to retreat. If more biters attack them while they are trying to retreat then they will fight back and possibly get killed before they get very far in their retreat. So it may have been working (sort of) for you it's just not something to rely on if they are in dangerous areas. Squads of terminators manage to survive battles more often so will retreat more effectively

jorn86 commented 7 years ago

I'll scale up my squad size to 100 or 150, those might be able to handle my map settings. Thanks!

kyranf commented 7 years ago

I would be very careful of doing that, you might get high CPU load as the hundreds of droids try to keep formation while moving.. certainly try it but there could be performance issues related to pathfinding in squad formations that large.

Also, the squads themselves may get caught up in large forests or on the sides of lakes.

At the small cost in resources is it really worth it trying to rely on the retreat mechanic?

jorn86 commented 7 years ago

It's working okay for me so far. And yes, it's worth it, since a size 20 squad barely makes a dent in a 20+ spawner base with small worms.

kyranf commented 7 years ago

Fair enough. I am also worried about how large the spawn area needs to be to fit 100 droids in the squad before they move to attack. Are you getting spawn zone issues?

jorn86 commented 7 years ago

I did when the spawner was right on the side of my base, but now I've put it ~30 tiles out and it's fine.

kyranf commented 7 years ago

interesting, thanks for your feedback.