#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)
Change History (13)
by , 11 years ago
Attachment: | flee.patch added |
---|
comment:1 by , 11 years ago
Component: | Core engine → UI & Simulation |
---|---|
Milestone: | Backlog → Alpha 13 |
Priority: | Should Have → Nice to Have |
Type: | defect → enhancement |
comment:2 by , 11 years ago
Keywords: | patch review added |
---|
by , 11 years ago
Attachment: | fleedist.patch added |
---|
follow-up: 5 comment:4 by , 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
toANIMALS
and move the special handling there (would also make the normalOrder.Flee
shorter).
comment:5 by , 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
toANIMALS
and move the special handling there (would also make the normalOrder.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 , 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 , 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 , 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 , 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:11 by , 11 years ago
Keywords: | review removed |
---|
I tested this and I think it works out nicely. Thanks for the patch.