Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#1723 closed enhancement (fixed)

[PATCH] flee distance too small

Reported by: mimo Owned by: leper
Priority: Nice to Have Milestone: Alpha 13
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description

There is a problem in the flee order in UnitAI.js : the minimum distance from the attacker is computed using the fleeDistance of the unit being attacked. But when the attacker is a range unit, this distance can be smaller than the range of the attacker, and thus the unit wait quietly to be killed. A simple fix is to take as minimum distance the sum of the present distance (between the attacker and the unit being attacked) and the fleeDistance. This is done in the attached patch.

Attachments (2)

flee.patch (799 bytes ) - added by mimo 11 years ago.
fleedist.patch (1.1 KB ) - added by mimo 11 years ago.

Download all attachments as: .zip

Change History (13)

by mimo, 11 years ago

Attachment: flee.patch added

comment:1 by Kieran P, 11 years ago

Component: Core engineUI & Simulation
Milestone: BacklogAlpha 13
Priority: Should HaveNice to Have
Type: defectenhancement

comment:2 by historic_bruno, 11 years ago

Keywords: patch review added

by mimo, 11 years ago

Attachment: fleedist.patch added

comment:3 by mimo, 11 years ago

If you would review the code, here is a modified version I use now. This is because the FleeDistance of animals is quite big and hunting can lead you quicky very far from your starting point. So now for animals, I use an effective flee distance which decreases when the distance between the hunter and the animal increases, which I think is also more realistic as an animal will flee less far when he is already far from his attacker.

comment:4 by leper, 11 years ago

I think the second patch may be more realistic but it also adds some clutter.

Some comments:

  • I would change the flee distance in the unit templates (template_unit_fauna.xml) if it is too big.
  • Add Order.Flee to ANIMALS and move the special handling there (would also make the normal Order.Flee shorter).

in reply to:  4 comment:5 by mimo, 11 years ago

Replying to leper:

I think the second patch may be more realistic but it also adds some clutter.

Some comments:

  • I would change the flee distance in the unit templates (template_unit_fauna.xml) if it is too big.
  • Add Order.Flee to ANIMALS and move the special handling there (would also make the normal Order.Flee shorter).

Yes, I was afraid to miss the "good" reason to have this big flee distance for animals. But if there are no special reason, decreasing it to 24 (presently standard units have 12 and fauna ones 32) would be fine with the first version of the patch. Otherwise, I can provide a new patch with the Order.Flee moved to ANIMAL as suggested. Both solutions look ok to me.

comment:6 by leper, 11 years ago

After some discussion on IRC (see the log starting at 21:34, with the results somewhere at 22:05) I think we'll go with something like

var distance = Math.ceil(DistanceBetweenEntities(this.entity, this.order.data.target) ^0.6) + (+this.template.FleeDistance); 

Maybe this works out for animals too, otherwise we should add a special case as noted before. (It would be great if you could test how this works out compared to the other approaches)

comment:7 by Kieran P, 11 years ago

mimo: the power of 0.6 was a random guess at what might be appropriate, and the concept of using powers may or may not actually work at all, so you'll need to investigate if this gives realistic results.

comment:8 by mimo, 11 years ago

I don't see how such a power can work. Take the case where the distance is d=30 (range attack). Units (other than animal) have flee distance of f=12, so the new distance would be d' = d0.6 + f = 20 < d and the unit would move closer to his attacker !! If you want to have something in one line, I would rather take something like d' = d + f/(1+a*d), such that we have always : d' > d (we want to flee)

For humans, a value of a=0 would seem logical

For animals, if we want to flee less when we are far, a value around a = 0.03 should work (we would flee by fleeDistance when d=0 and by half of fleeDistance when d=33).

comment:9 by leper, 11 years ago

Hm, I'll commit the first version with the template change. If that doesn't work nicely we can still fix it with some more complex logic for animals.

comment:10 by leper, 11 years ago

Owner: set to leper
Resolution: fixed
Status: newclosed

In 13077:

Take distance between attacker and target into account when fleeing. Patch by mimo. Fixes #1723.

comment:11 by leper, 11 years ago

Keywords: review removed

I tested this and I think it works out nicely. Thanks for the patch.

Note: See TracTickets for help on using tickets.