Opened 8 years ago
Closed 3 years ago
#4278 closed defect (fixed)
[PATCH] CCmpUnitMotion bug when unit inside obstruction
Reported by: | mimo | Owned by: | wraitii |
---|---|---|---|
Priority: | Must Have | Milestone: | Alpha 22 |
Component: | Core engine | Keywords: | |
Cc: | Patch: |
Description (last modified by )
While trying to understand a case where a unit would not leave a foundation, i've found a bug in MoveToTargetRange of CCmpUnitMotion: the DistanceToSquare of lines 1574 and 1579 should have an additional parameter (countInsideAsZero) true, otherwise all the following logic does not make any sense. Doing such a change fixed the problem in my case. In the case of LeaveFoundation, such a change is definitively needed. But it should be checked that it is also needed in all use case of this MoveToTargetRange function when inside the obstruction.
Attachments (5)
Change History (34)
by , 8 years ago
Attachment: | ticket4278.patch added |
---|
comment:1 by , 8 years ago
Keywords: | review added |
---|---|
Summary: | CCmpUnitMotion bug when unit inside obstruction → [PATCH] CCmpUnitMotion bug when unit inside obstruction |
follow-up: 3 comment:2 by , 8 years ago
It has indeed no sense to not add that boolean. By the way there are not many case in wich we come from the inside of the target.
Perhaps we could/should/must also modify IsInTargetRange
in the same way (it's use in UnitAI too).
I sum up here the different calls of that function (all are in UnitAI.js)
- L398
if (cmpUnitMotion.MoveToTargetRange(this.order.data.target, distance, -1))
for flee order. - L4380
return cmpUnitMotion.MoveToTargetRange(target, 0, 0);
inMoveToTarget
function. - L4394
return cmpUnitMotion.MoveToTargetRange(target, range.min, range.max);
inMoveToTargetRange
function. - L4450
if (cmpUnitMotion.MoveToTargetRange(target, range.min, guessedMaxRange))
inMoveToTargetAttackRange
function. (should be nuked in #4028). - L4454
return cmpUnitMotion.MoveToTargetRange(target, range.min, Math.min(range.max, parabolicMaxRange));
in the same function. - L4463
return cmpUnitMotion.MoveToTargetRange(target, min, max);
inMoveToTargetRangeExplicit
function. - L4477
return cmpUnitMotion.MoveToTargetRange(target, range.min, range.max);
inMoveToGarrisonRange
function.
The UnitAI functions MoveToTargetRange
and MoveToTargetRangeExplicit
are used in many orders and states:
Heal, LeaveFoundation, Guard, Gather, ReturnResource, Repair
FORMATION WalkToTargetRange LeaveFoundation
ESCORTING MoveCompleted
GUARDING Timer
ATTACKING Timer
GATHERING Timer
HEALING Timer
REPAIRING Enter Timer
The UnitAI function MoveToTarget
is used for markets, MoveToGarrisonRange
for garrison, MoveToTargetAttackRange
for attack.
(Btw, at L398 of UnitAI, perhaps we should/could/can/must call directly the UnitAI
function instead of the UnitMotion
one ?)
comment:3 by , 8 years ago
Replying to fatherbushido:
Perhaps we could/should/must also modify
IsInTargetRange
in the same way (it's use in UnitAI too).
You mean the one in CCmpUnitMotion? I would agree, but was not completely sure.
(Btw, at L398 of UnitAI, perhaps we should/could/can/must call directly the
UnitAI
function instead of theUnitMotion
one ?)
Yep, UnitAI would need also such changes, for internal consistency. But these could wait for after A21 is released as the current code is not buggy.
by , 8 years ago
Attachment: | savegame-0481.0adsave added |
---|
I saved this game when i noticed the problem. There are two cavs (ent 7525 and 7526) blocking a wonder foundation and not moving. Fixed when applying the patch.
follow-up: 6 comment:5 by , 8 years ago
Is this possibly related to entities being stuck in "capturing" mode?
comment:6 by , 8 years ago
Replying to wraitii:
Is this possibly related to entities being stuck in "capturing" mode?
I don't believe so, as the bug is only present when units are inside the structure obstruction, and i don't see how capturing could bring units inside.
comment:7 by , 8 years ago
You mean the one in CCmpUnitMotion? I would agree, but was not completely sure.
Yes that one
Yep, UnitAI would need also such changes, for internal consistency. But these could wait for after A21
sure, I mentionned it just to not forget
I fully agree with your patch (looking at the comments, it must be like that) but I have no clue if one of the uses on the list above could do a weird use of that function (It doesn't look like).
(I guess it's only noticeable with big target, low min range argument and obviously the entity in the target shape)
comment:8 by , 8 years ago
Looking back at the code, you were right that we also need to change the DistanceToSquare computation in IsInTargetRange so that both functions stay compatible. There is also such a call in IsInPointRange (line 1476) which i don't know what we should do as i don't know if and when it is used.
In addition, there is a small problem as all points inside obstruction will now have a distance zero, and most minRange are zero, so if we ask a builder to start a construction while the builder is inside the obstruction, he will first try to build where he is, and then leave the foundation because he has received the leaveFoundation order, and then really start building. Not really a problem, but not nice. So we should either explicitely check if we are inside (as in the patch attached) or change the minRange of builders (i think that's the only case where we can have a unit inside obstruction) to a small value (i.e. 0.5)
by , 8 years ago
Attachment: | ticket4278-v2.patch added |
---|
follow-up: 10 comment:9 by , 8 years ago
Indeed the first solution (add the check) is better than changing minRange of builders. While testing the patch in game in weird situation, I 'succeed' to have a bug (see attached savegame). I hope that will help you. ((Btw, when compiling I have warnings (recommandation to add parenthesis, but they are not needed).))
by , 8 years ago
Attachment: | buggy_cav_wonder_foundation.0adsave added |
---|
comment:10 by , 8 years ago
Replying to fatherbushido:
While testing the patch in game in weird situation, I 'succeed' to have a bug (see attached savegame). I hope that will help you.
It has nothing to do with the patch (it happens also with svn). My understanding is that the cav has an order to go to the other side of the foundation, but receices a leaveFoundation, so goes back out of the obstruction, but then retries immediately to cross the foundation to obey to its previous order. And as the cav is fast and the leaveFoundation only push units at 4m, it has time to reenter the obstruction before the builder has started the construction (and thus gives real obstruction to the foundation). To fix it, we can either increase this 4m (at least for cav), or wait a bit before following a previous order after a leaveFoundation, or any other ideas, but this is independent from this patch.
Concerning the last sentence "I hope that will help you", I don't want to take responsability for this patch. I'm only trying to help the release with reporting bugs and giving some wip patches for propositions of a solution, but don't have time to develop and test a final patch.
((Btw, when compiling I have warnings (recommandation to add parenthesis, but they are not needed).))
Yep, I've seen it to. But i think that's our coding convention to not have such parentheses even if gcc seems to have a different convention. I would also prefer to have the parentheses as i think they improve readability.
comment:13 by , 8 years ago
I encounter the bug in a20 today and I had to destroy the units in middle to continue the construction.
by , 8 years ago
Attachment: | obstruction.jpg added |
---|
comment:14 by , 7 years ago
Milestone: | Alpha 21 → Alpha 22 |
---|
wraitii, fatherbushido and Itms recommend the code to be committed, but we don't find the courage to commit it at this stage. Please let us know if you disagree, and thanks for the patch (it is a very old and annoying issue, especially with nomad cc foundations)
comment:15 by , 7 years ago
No problem. I agree that it has to be thoroughly tested (even if code wise, the problem is clear and the fix simple). Let's push it.
comment:16 by , 7 years ago
Keywords: | beta added |
---|
comment:17 by , 7 years ago
You can go ahead with committing this patch. It does indeed fix the logic problem. UnitMotion wants to know if we're too close to the target, but that could fail if we were so inside that we were out of our midrange, which is obviously broken.
You might also want to look at lines 1474/1484: we're in an if block where midrange and maxrange are zero then we do strict comparisons on them: there's something wonky.
comment:19 by , 7 years ago
Thanks wraitii for reviewing the patch. I've commited it but I let the ticket opened as this bug revealed some new problems (maybe some should open a new ticket for them):
- strange lines 1474/1484 mentionned in comment 17
- the infinite trial to reenter inside the obstruction with cav, comments 9 and 10
comment:20 by , 7 years ago
Keywords: | review removed |
---|
comment:23 by , 7 years ago
fatherbushido is correct, they should have been taken into account.
((Btw, when compiling I have warnings (recommandation to add parenthesis, but they are not needed).))
If you state the exact compiler warning, it will probably taken more seriously and they will also know at which place it occurs (if they don't have that warning with their compiler). The parenthesis are not needed, but we also don't want random people complaining about compiler warnings that obscure the compiler output.
comment:25 by , 7 years ago
Milestone: | Alpha 22 → Work In Progress |
---|
Moving to the Work In Progress milestone, since there is a patch asking for feedback, but since it is not strictly bound to a specific release.
comment:26 by , 5 years ago
Description: | modified (diff) |
---|---|
Milestone: | Work In Progress → Alpha 24 |
Owner: | set to |
The problem of cavalry going back in the foundation since it moves so fast still happens. I guess to make sure we should scale the "move away" based on speed of the entity.
Assigning to A24 and to me since that sounds doable enough after the UAI 'feature freeze'.
comment:28 by , 3 years ago
Patch: | Phab:D2199, Phab:D3204 → Phab:D3204 |
---|
comment:29 by , 3 years ago
Cc: | removed |
---|---|
Keywords: | beta removed |
Milestone: | Alpha 24 → Alpha 22 |
Patch: | Phab:D3204 |
Resolution: | → fixed |
Status: | new → closed |
The cavalry issue has been split off to #5901. Closing this as fixed in A22.
I forgot to add the patch