Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#3405 closed defect (fixed)

[PATCH] Animals do not flee anymore when wounded

Reported by: mimo Owned by: mimo
Priority: Should Have Milestone: Alpha 19
Component: Core engine Keywords: pathfinding patch
Cc: Itms Patch:

Description

This seems to be due to the pathFinder changes, and this could be the true cause of #3372. Attached is a simple commands.txt which reproduces the problem.

Attachments (6)

commands.txt (2.4 KB ) - added by mimo 9 years ago.
commands.2.txt (2.8 KB ) - added by mimo 9 years ago.
commands.3.txt (7.5 KB ) - added by elexis 9 years ago.
All deer near the north edge of the map fleeing to the right. (r17078)
commands.4.txt (7.8 KB ) - added by elexis 9 years ago.
ticket3405-fix.diff (3.9 KB ) - added by mimo 9 years ago.
ticket3405-improv.diff (1.6 KB ) - added by mimo 9 years ago.

Download all attachments as: .zip

Change History (23)

by mimo, 9 years ago

Attachment: commands.txt added

comment:1 by leper, 9 years ago

Cc: Itms added
Keywords: pathfinding added

comment:2 by mimo, 9 years ago

As the Flee order seems to work for female, but not for animals, and the main difference (code-wise !) is the FleeDistance, I varied the one for animals. The nominal one is 24, decreasing it to 18 makes the Flee works for animals, while 20 fails.

Adding some printouts in CCmpUnitMotion, the reason is that up to 18, only a short path is done, while at 20, a long path is computed.

One possibility is that the long pathFinder, when you want to go at a given distance from the target while you start at a smaller distance, has some flaws ?

comment:3 by Itms, 9 years ago

Owner: set to Itms
Resolution: fixed
Status: newclosed

In 17013:

Support inverted goals with the long-range pathfinder. This allows units to flee and should fix problems with ranged units too close to their targets. Fixes #3405, refs #3372.

Now that units flee it's necessary to fix the unit chasing: this commit reintroduces some code from r14449 that disappeared with the committing of the new pathfinder. Refs #1537.

Also includes some style improvements to the UnitMotion code.

comment:4 by Itms, 9 years ago

Milestone: BacklogAlpha 19

Please note that in your replay file, the deer now flees in the wrong direction because it is close to the edge of the map, so the long-range pathfinder detects that and makes it flee to the closest reachable out-of-attacker-range point.

Thanks for reporting and for finding out in which part of the code I had to take a look :)

comment:5 by mimo, 9 years ago

Thanks for the fix, but I suspect there is something wrong in the computation of the closest point as, if d is the distance between the hunter and the animal and f its flee distance, the animal is ordered to go to the nearest point on a circle centered on the hunter and with radius d+f by a MoveToPointRange(hunter, d+f). And, even if this circle is truncated because of the edge of the map in the commands.txt, there are clearly better possibility than going towards the hunter. But to make it clearer, I've tried hunting another deer in the middle of the map, and here is a commands.txt with the deer still going towards the hunter. And in my attempts, it seems than even when the deer flees in the right direction, it flees by much less than its flee distance.

Last edited 9 years ago by mimo (previous) (diff)

by mimo, 9 years ago

Attachment: commands.2.txt added

comment:6 by gameboy, 9 years ago

Resolution: fixed
Status: closedreopened

There is a problem, Roman cavalry spear would still not go chasing a deer, he remained in place to repeat the attacks and then to chase deer. Deer had run away at this time.

Last edited 9 years ago by gameboy (previous) (diff)

comment:7 by Stan, 9 years ago

Did you compile ?

comment:8 by gameboy, 9 years ago

@stanislas69: yes,my friend.

@Itms: Roman cavalry spear can't hunt deer. Roman cavalry spear while hunting deer, deer cannot be pursued in a timely manner to, when the deer ran away after he began a slow attack. He should follow, and then to attack the deer, but he doesn't have to follow the deer. Seems to be related to how attacks and damage is calculated, and because of the slow attack speed of spearcav.

Last edited 9 years ago by gameboy (previous) (diff)

by elexis, 9 years ago

Attachment: commands.3.txt added

All deer near the north edge of the map fleeing to the right. (r17078)

by elexis, 9 years ago

Attachment: commands.4.txt added

comment:9 by elexis, 9 years ago

Notice the deer flees the right direction after being hit once and then being chased by the cavalry without attacking it again.

comment:10 by Itms, 9 years ago

Owner: Itms removed
Status: reopenednew

I don't consider this a release blocker, and I probably won't have time at all for that, so if nobody works on it it should be pushed.

comment:11 by mimo, 9 years ago

After the changes during the last 3 weeks, the animals now flee but quite often not in the direction we could expect. Looking at CCmpUnitMotion code, it seems the origin of the problem is that, when going away from an entity, MoveToTargetRange always uses an INVERTED_SQUARE and the directions of the square are fixed u=(1,0) and v=(0,1). I think we should approximate this INVERTED_SQUARE to an INVERTED_CIRCLE when units are involved (as is done when going towards an entity where the SQUARE is replaced by a CIRCLE). Another way to improve the global flee direction would be to take as u the direction between the attacker and the fleeing entity (in principle the direction the attacker is facing at).

by mimo, 9 years ago

Attachment: ticket3405-fix.diff added

by mimo, 9 years ago

Attachment: ticket3405-improv.diff added

comment:12 by mimo, 9 years ago

The problem was in fact in some goal dependent computations in the case of inverted (going to bigger distance) movement. This is fixed in the first patch attached. But still the flee direction keeps track of the square shape and is thus not exactly the one expected. The second patch adds the circle approximation.

comment:13 by Itms, 9 years ago

Ah awesome catch! Sorry for the big mistake.

Be careful of spaces/tabs in this patch, as you can see in the Trac display there is a problem. Lines 49 or 84 of PathGoal.cpp are a good example of how to deal with that. :)

comment:14 by elexis, 9 years ago

Keywords: patch review added
Summary: Animals do not flee anymore when wounded[PATCH] Animals do not flee anymore when wounded

comment:15 by mimo, 9 years ago

Owner: set to mimo
Resolution: fixed
Status: newclosed

In 17142:

fix the INVERTED_CIRCLE and INVERTED_SQUARE PathGoal, fixes #3405

comment:16 by mimo, 9 years ago

In 17143:

do the circle approximation also in INVERTED goals in UnitMotion, refs #3405

comment:17 by mimo, 9 years ago

Keywords: review removed

Thanks Itms for the quick review. And if nobody disagree, i will revert r16973 after a19 is out as animals fleeing foundations was visually better than seeing them walk quietly as we have now.

Note: See TracTickets for help on using tickets.