Core/Movement: Fix some issues with ConfusedMovementGenerator from recent changes.
- Z position was not set if LOS-check failed, and thereafter causing a crash when trying to move to a uninitialized z-choord. - Also fixes bad coords in water Closes #6124
This commit is contained in:
@@ -59,24 +59,24 @@ void ConfusedMovementGenerator<T>::Initialize(T &unit)
|
|||||||
|
|
||||||
if ((is_water && !is_water_ok) || (!is_water && !is_land_ok))
|
if ((is_water && !is_water_ok) || (!is_water && !is_land_ok))
|
||||||
{
|
{
|
||||||
//! Ignore bad generated path. Use the current or previous position.
|
//! Cannot use coordinates outside our InhabitType. Use the current or previous position.
|
||||||
i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx-1][0] : x;
|
wanderX = idx > 0 ? i_waypoints[idx-1][0] : x;
|
||||||
i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx-1][1] : y;
|
wanderY = idx > 0 ? i_waypoints[idx-1][1] : y;
|
||||||
}
|
}
|
||||||
|
|
||||||
unit.UpdateAllowedPositionZ(wanderX, wanderY, z);
|
|
||||||
|
|
||||||
//! Positions are now fine - apply them to this waypoint
|
|
||||||
i_waypoints[idx][0] = wanderX;
|
|
||||||
i_waypoints[idx][1] = wanderY;
|
|
||||||
i_waypoints[idx][2] = z;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//! Ignore bad generated path. Use the current or previous position.
|
//! Trying to access path outside line of sight. Skip this by using the current or previous position.
|
||||||
i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx-1][0] : x;
|
wanderX = idx > 0 ? i_waypoints[idx-1][0] : x;
|
||||||
i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx-1][1] : y;
|
wanderY = idx > 0 ? i_waypoints[idx-1][1] : y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unit.UpdateAllowedPositionZ(wanderX, wanderY, z);
|
||||||
|
|
||||||
|
//! Positions are fine - apply them to this waypoint
|
||||||
|
i_waypoints[idx][0] = wanderX;
|
||||||
|
i_waypoints[idx][1] = wanderY;
|
||||||
|
i_waypoints[idx][2] = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
unit.StopMoving();
|
unit.StopMoving();
|
||||||
|
|||||||
Reference in New Issue
Block a user