Opened 8 years ago

Last modified 3 years ago

#4340 new enhancement

[PATCH] Allow units to react when their path is obstructed / Change attack orders to not be forced — at Initial Version

Reported by: wraitii Owned by:
Priority: Should Have Milestone: Backlog
Component: Simulation Keywords: pathfinding patch design
Cc: scythetwirler Patch:

Description

One of the long-standing issues with the pathfinder is that units cannot tell when their path was obstructed, they can only react if the path fails entirely. Having specific behavior for an obstructed path, however, may be desirable (see below).

I implemented a git branch for those changes with 2 commits: https://github.com/wraitii/0ad/commits/MoveObstructedOptim

The first commit is just the back-end ability: send a MessageObstructed message the first time you're obstructed. The second commit is a behavior change in UnitAI.

Currently, when units are ordered to attack an entity, this order is "forced". Units will, unless their stance is violent, always try to attack that entity specifically. If their stance is violent, they will respond to being attacked by counter-attacking. My second commit changes the Attack order to not be forced (and then changes ShouldAbandonChange to use player LOS instead of unit vision, otherwise it reacts weirdly). This helps a little.

More importantly, I also leverage the "MoveObstructed" message. Now if units are going to attack neater entity, and they run in an enemy unit, they will try and attack it even before that enemy unit attacks them.

Those two changes mean that when you order a group of units to attack another, the unit's behavior is now much more natural: they will attack the first entity they run into (kind of like an attack-move). This creates "fronts" of combat, just try it on combat demo huge and you'll see what I mean. Please note: this does not mean you can't order units to attack another specifically. They still do that. Just if they run into an issue along the way, they will change their mind more often.

I also implemented an optimization to FindNewTargets: units will first try the 8 closest units, then if none were acceptable retry with all units. This makes that function generally much faster with a large number of units, and does not change behavior much (if anything, it improves it since units will be biased towards units close to them).

NB: patch has one problem: we should still allow the player to force an attack (for example if you want to destroy rams). One possible behavior I can think of would be double clicking, and/or a shortcut.

Change History (1)

by wraitii, 8 years ago

Graphs of activity, above is SVN, below is patched.

Note: See TracTickets for help on using tickets.