Fix GetPosition2D call when the entity may be out of the world in unitMotion
As reported by Freagarach followinga7da40ac2f
.32e8ed51aa
introduced a "MoveObstructed" message, that could be sent when the entity ran into obstructions, to stop early. In HandleObstructedMove, my intention, as written in the comment, was that the caller would do its thing (call StopMoving(), move out of the world etc.) and thus ComputeGoal would return early. However, I mistakenly left the `cmpPosition->GetPosition2D()` in between that and ComputeGoal, which would then fail. This fixes that by moving it after the `ComputeGoal` call. Also add a sanity StopMoving() call to a7da40ac2f's move-out-of-world call. Reported by: Freagarach Differential Revision: https://code.wildfiregames.com/D2935 This was SVN commit r23940.
This commit is contained in:
parent
cdefefa617
commit
45d136d57e
@ -1240,8 +1240,11 @@ UnitAI.prototype.UnitFsmSpec = {
|
||||
// a group of unit and does not have a well-defined position,
|
||||
// so move the controller out of the world to enforce that.
|
||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
|
||||
if (cmpPosition)
|
||||
if (cmpPosition && cmpPosition.IsInWorld())
|
||||
{
|
||||
this.StopMoving();
|
||||
cmpPosition.MoveOutOfWorld();
|
||||
}
|
||||
|
||||
this.StartTimer(1000, 1000);
|
||||
return false;
|
||||
|
@ -1075,14 +1075,13 @@ bool CCmpUnitMotion::HandleObstructedMove()
|
||||
// Inform other components - we might be ordered to stop, and computeGoal will then fail and return early.
|
||||
MoveObstructed();
|
||||
|
||||
CFixedVector2D pos = cmpPosition->GetPosition2D();
|
||||
|
||||
// Oops, we hit something (very likely another unit).
|
||||
|
||||
PathGoal goal;
|
||||
if (!ComputeGoal(goal, m_MoveRequest))
|
||||
return false;
|
||||
|
||||
// At this point we have a position in the world since ComputeGoal checked for that.
|
||||
CFixedVector2D pos = cmpPosition->GetPosition2D();
|
||||
|
||||
if (!InShortPathRange(goal, pos))
|
||||
{
|
||||
// If we still have long waypoints, try and compute a short path to our next long waypoint.
|
||||
|
Loading…
Reference in New Issue
Block a user