New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add helper methods to locate actors that can be reached via a path. #20227
Conversation
OpenRA.Mods.Common/Traits/BotModules/Squads/States/GroundStates.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: in my testing everything went perfectly, I just listed the few exceptions I noticed |
b67491b
to
8abcea7
Compare
Hmm - the fact boats will move to attack land at all is actually suspect. That should be prevented by the new checks. That also reveals a wider issues - we might want things like boats to get close to land to attack things on it, but if the checks were working they wouldn't ever try and do this unless they happened to be in autotarget range. So instead of seeing if we can reach the target, we might want to see if we can reach a location close to the target instead. That would be more complicated. Will need to investigate this some more. |
#20239 fixes things so boats now ignore the land units. However it seems like a regression to not allow boats to attack units near the shore - we need to teach the AI that it can attack units it can't reach - they don't need to get to the unit - just close enough to be in weapons range. Plus revalidating the other scenarios @PunkPun reported. |
I think it is ok to ignore the land units, for we also have an Autotarget can get target while the squad attack moving |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did another game (rebased on bleed)
The artillery but happened again (ignore the light tank he's attacking the airfield)
Naval grouping seems to be broken. These submarines attacked a naval yard which was built right next to them and did nothing afterwards. When a new sub was built it went kill the enemy naval yard, after that it also went idle. Not that there were anymore targets in water afterwards
In the end, the winning AI was unable to finish the game. There were 4 other AI's which had only the sub pen / naval yard left as their last structure
Probably unrelated to this PR, but AI nuked its own forces. (nuke was launched by the yellow AI)
8abcea7
to
13bc0d6
Compare
Pushed a commit that attempts to solve the problem where the AI squad can't directly path to the unit, e.g. boats trying to attack a land unit, but can get close enough to attack, e.g. the land units are on the beach. Code is godawful and the overall approach still needs some thinking, but this is a step forward. Marking as a draft because more work is needed here. |
13bc0d6
to
6ff9586
Compare
I would imagine the proper solution would be to generate a circle around the target the size of weapon range and see if all if any of those cells can be reached. |
I think it could be better that split commit "Add helper methods to locate actors that can be reached via a path." into another PR and we merge that first. AI squad control is a really messing thing that will takes much longer time on fixing and testing. |
With only the first commit, AI navy won't attack any land units. This is because they can't path to them. That would probably be worse than the current behaviour of trying to attack land units they can't reach. So we probably do want a solution that finds the balance - navy can attack land units, but only tries to attack land units within range rather than anything. |
I think it is OK, because "current behaviour of trying to attack land units they can't reach" can give us a huge lag while also stuck the navy on the shore. I personally prefer a smoother gameplay on this issue. I remember RA2 also make AI navy can only attack navy, it is possible that it is due to the same reason. |
It is not fine, see my previous comment
|
But I think it is better than when situation happends like MustaphaTR/Romanovs-Vengeance#88, which make the game almost unplayable when there is too many unit trying to attack unreachable. Add: for optimazing this situation I did many works, like only allow leader do the pathfinding to target, kick stuck unit from squad, but it also happen sometimes when units try to attack unreachable units. |
Sounds like two different types of path searches, one to reach a destination, another to try to attack something (that will be) in target range? |
c011959
to
23a0e5b
Compare
Could you please add |
We're reliant on I think something like #20945 is along the right lines anyway. Rather than trying to get clever and working out if placing a building will complete a wall that traps in some units, just enforcing spacing on some/all buildings help reduce the chance of congested AI bases that might trap things in. |
8e234f3
to
02f0311
Compare
I have updated the code to deal with issues noted previously. Here are the scenarios which are now improved. I used the following map for testing these scenarios out. Human player should use spawn 'A'. Enabling cheats and actor tags are useful. IslandsPathfinding.zip Target Units on Same Island
On bleed, the squad will initially target your base - the "Assault, fact XX" in the actor tags tells you the squad target. Once the first barracks is placed, they will target that instead - "tent XX". Once the second barracks is placed, they ignore it as the first is physically closer. With this PR, they won't target the base as it isn't reachable. Same with the first barracks. Once the second barrack is placed, the squad will attack it.
Target Naval Units In Range of Island
On bleed, the AI squad will attack the gunboat. But when it moves out of range, they won't retarget. They won't respond to new units as a result. With the PR they will drop the target when it moves out of range - and can retarget to the new unit immediately. Target Lands Units In Range Of Island
The AI squad will attack these units. On bleed when the units move away the squad won't retarget and will keep trying to attack. With this PR they will go idle and return to base.
AI Units used after squad disbanded
On bleed, the squad stays put - they have retargetted to the unreachable construction yard and will be useless. With this PR the units will go idle. Once the next strucuture is placed a new squad is formed once the AI has enough units and will attack your new structure. Importantly, idle units from the first squad will be included in the force. There existed a bug where an AI squad that disbands doesn't mark those units as available. So the AI never notices they can be assigned into another squad. So the units that returned to base from the first squad would never have been assigned to the new squad without this fix. Finally, I tested a large AI game and didn't notice any performance issues. If you experience any, they are likely to present as lag spikes spaced approx 1 second apart. This is because the AI does some thinking approx every 1 second so it would almost certainly be AI related. If you experience this please include a replay! And if possible some repro steps. |
02f0311
to
4f68acd
Compare
4f68acd
to
b424b29
Compare
Needs a rebase. |
b424b29
to
1733a10
Compare
Previously, the ClosestTo and PositionClosestTo existed to perform a simple distance based check to choose the closest location from a choice of locations to a single other location. For some functions this is sufficient, but for many functions we want to then move between the locations. If the location selected is in fact unreachable (e.g. on another island) then we would not want to consider it. We now introduce ClosestToIgnoringPath for checks where we don't care about a path existing, e.g. weapons hitting nearby targets. When we do care about paths, we introduce ClosestToWithPathFrom and ClosestToWithPathTo which will check that a path exists. The PathFrom check will make sure one of the actors from the list can make it to the single target location. The PathTo check will make sure the single actor can make it to one of the target locations. This difference allows us to specify which actor will be doing the moving. This is important as a path might exists for one actor, but not another. Consider two islands with a hovercraft on one and a tank on the other. The hovercraft can path to the tank, but the tank cannot path to the hovercraft. We also introduce WithPathFrom and WithPathTo. These will perform filtering by checking for valid paths, but won't select the closest location. By employing the new methods that filter for paths, we fix various behaviour that would cause actors to get confused. Imagine an islands map, by checking for paths we ensure logic will locate reachable locations on the island, rather than considering a location on a nearby island that is physically closer but unreachable. This fixes AI squad automation, and other automated behaviours such as rearming.
1733a10
to
23bdc20
Compare
Fixes AI trying to attack units they can't reach, and other automated behaviours will now only consider reachable locations, e.g. if rearming. Fixes #17753
Test scenario:
Start a map with an AI on an island and park some naval units near to their base. Deploy a barracks onto their island but far away from their base and build some units.
On bleed: When the AI creates a squad from the land units it will try and attack the nearest units - the naval units.
This PR: The squad will attack the nearest reachable units - the barracks. The closer naval units are ignored because the land units can't move to them.
Previously, the ClosestTo and PositionClosestTo existed to perform a simple distance based check to choose the closest location from a choice of locations to a single other location. For some functions this is sufficient, but for many functions we want to then move between the locations. If the location selected is in fact unreachable (e.g. on another island) then we would not want to consider it.
We now introduce ClosestToIgnoringPath for checks where we don't care about a path existing, e.g. weapons hitting nearby targets. When we do care about paths, we introduce ClosestToWithPathFrom and ClosestToWithPathTo which will check that a path exists. The PathFrom check will make sure one of the actors from the list can make it to the single target location. The PathTo check will make sure the single actor can make it to one of the target locations. This difference allows us to specify which actor will be doing the moving. This is important as a path might exists for one actor, but not another. Consider two islands with a hovercraft on one and a tank on the other. The hovercraft can path to the tank, but the tank cannot path to the hovercraft.
We also introduce WithPathFrom and WithPathTo. These will perform filtering by checking for valid paths, but won't select the closest location.
By employing the new methods that filter for paths, we fix various behaviour that would cause actors to get confused. Imagine an islands map, by checking for paths we ensure logic will locate reachable locations on the island, rather than considering a location on a nearby island that is physically closer but unreachable. This fixes AI squad automation, and other automated behaviours such as rearming.