How to handle units getting stuck?

How to handle units getting stuck?

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
ljd
Posts: 7
Joined: 20 Aug 2011, 20:21

How to handle units getting stuck?

Post by ljd »

I created a Skirmish AI that plays BA for my thesis. I'm pretty much done and quite happy with it except for one issue. Every few games or so the commander will get stuck on a solar panel flap and just keeping 'bouncing' into it forever. This kills the game. I need to run several hundred games to collect data for my experiments, so preventing the commander from getting stuck would really help.

There are many other situations of units getting stuck (for example, in wreckage), and I'd love to fix the problem. But I understand it is pathing related and likely the only way I'll find a good solution is to rewrite the pathinding myself or wait for the new QTPFS to be finished.

But I need to graduate in June, so rewritting the pathing is not an option. I would be happy just to add some code to my agent to detect when the commander is stuck and adjust. I only give the commander 2 commands. Build and guard (specifically, guard a factory to help construct units faster).

For the 'build' commands, I can track the commanders position, the frame the build command was given, and if the commander started building yet (via unit_created event). During update events, I can check (say every 120 frames--4 seconds) if the commander hasn't started building yet, did he at least make some progress in moving from the previous position? If not, issue a new command.

For the 'guard' commands, I'm not sure what to do. I can track the commanders position, and every 120 frames, see if he make movement progress from the last update, but obviously, he will stop when he gets close enough to the factory to use his nano spray. I don't know how to detect when the commander is actually 'helping' the factory to construct units (in other words, that he is stationary because he arrived close enough to the factory and not because he is stuck on a solar panel).

What do you think is the best way to detect when the commander is really stuck? Also, is there a setting in spring to disable wreckage?

Thanks for your help!
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: How to handle units getting stuck?

Post by Kloot »

The development build of Spring has a fix for the infinite-bouncing bug.
Also, is there a setting in spring to disable wreckage?
That's mod-controlled, but you can always edit mod files for local testing.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: How to handle units getting stuck?

Post by knorke »

Also, is there a setting in spring to disable wreckage?
if the game is BA, there is a modoption for that.
key = "mo_nowrecks",
name = "No Unit Wrecks",
desc = "Removes all unit wrecks from the game",
I don't know how to detect when the commander is actually 'helping' the factory to construct units
Can you detect if the commander is using metal? If yes, he is building something.
User avatar
NeonStorm
Posts: 173
Joined: 23 May 2012, 18:36

Re: How to handle units getting stuck?

Post by NeonStorm »

Can you detect if the commander is using metal? If yes, he is building something.
This solution is not perfect - you may have a worker (not neccessarily the com) which is stockpiling projectiles but not building.

Can you not check if the commander proceeds in his last task?
This would solve any stuck issues and can easily be extended.


An unfinished example which requires a history about the actions

Code: Select all

function isStuck( unit )
  local task = unit.getCurrentTask()
  local type = task.getType()
  if type = "move" then
    local position1 = unit.getLastPosition() or { -1, -1, -1 }
    local position2 = unit.getCurrentPosition()
    if notTheExpectedDifference( position1, position2 ) then return true end
    unit.setLastPosition( position2 )
  end
  if type = "build" then
     local hp1 = unit.getLastHP() or -1
     local hp2 = unit.getCurrentHP()
     if hp1 = hp2 then return true end
     unit.setLastHP( hp2 )
  end
end
Another idea is to manually check if a unit is inside a collision volume of a feature on a given position.
slogic
AI Developer
Posts: 626
Joined: 17 Mar 2008, 19:03

Re: How to handle units getting stuck?

Post by slogic »

If unit can't do smth it gets idle. Catch the event.
Post Reply

Return to “AI”