Permalink
Browse files

make Spring.ClearUnitGoal cancel raw movement by default

1 parent 8ae858d commit d34ef2f2a0f81f6b5617bb20b32b1a3ec46b874b rtri committed Feb 18, 2017
@@ -2409,7 +2409,7 @@ int LuaSyncedCtrl::ClearUnitGoal(lua_State* L)
if (unit == nullptr)
return 0;
- unit->moveType->StopMoving();
+ unit->moveType->StopMoving(false, false, luaL_optboolean(L, 2, true));
return 0;
}
@@ -346,9 +346,7 @@ void CGroundMoveType::SlowUpdate()
if (numIdlingUpdates > (SHORTINT_MAXVALUE / turnRate)) {
// case A: we have a path but are not moving
- LOG_L(L_DEBUG,
- "SlowUpdate: unit %i has pathID %i but %i ETA failures",
- owner->id, pathID, numIdlingUpdates);
+ LOG_L(L_DEBUG, "SlowUpdate: unit %i has pathID %i but %i ETA failures", owner->id, pathID, numIdlingUpdates);
if (numIdlingSlowUpdates < MAX_IDLING_SLOWUPDATES) {
ReRequestPath(true);
@@ -417,6 +415,7 @@ void CGroundMoveType::StartMoving(float3 moveGoalPos, float moveGoalRadius) {
useMainHeading = false;
useRawMovement = false;
+
progressState = Active;
numIdlingUpdates = 0;
@@ -442,7 +441,7 @@ void CGroundMoveType::StartMoving(float3 moveGoalPos, float moveGoalRadius) {
}
}
-void CGroundMoveType::StopMoving(bool callScript, bool hardStop) {
+void CGroundMoveType::StopMoving(bool callScript, bool hardStop, bool cancelRaw) {
#ifdef TRACE_SYNC
tracefile << "[" << __FUNCTION__ << "] ";
tracefile << owner->pos.x << " " << owner->pos.y << " " << owner->pos.z << " " << owner->id << "\n";
@@ -461,8 +460,9 @@ void CGroundMoveType::StopMoving(bool callScript, bool hardStop) {
StopEngine(callScript, hardStop);
useMainHeading = false;
- // only a new StartMoving call can reset this
- // useRawMovement = false;
+ // only a new StartMoving call can normally reset this
+ useRawMovement &= (!cancelRaw);
+
progressState = Done;
}
@@ -27,7 +27,7 @@ class CGroundMoveType : public AMoveType
void StartMovingRaw(const float3 moveGoalPos, float moveGoalRadius) override;
void StartMoving(float3 pos, float goalRadius) override;
void StartMoving(float3 pos, float goalRadius, float speed) override { StartMoving(pos, goalRadius); }
- void StopMoving(bool callScript = false, bool hardStop = false) override;
+ void StopMoving(bool callScript = false, bool hardStop = false, bool cancelRaw = false) override;
bool IsMovingTowards(const float3& pos, float radius, bool checkProgress) const override {
return (goalPos == pos * XZVector && goalRadius == radius && (!checkProgress || progressState == Active));
}
@@ -319,7 +319,7 @@ void CHoverAirMoveType::ExecuteStop()
}
}
-void CHoverAirMoveType::StopMoving(bool callScript, bool hardStop)
+void CHoverAirMoveType::StopMoving(bool callScript, bool hardStop, bool)
{
// transports switch to landed state (via SetState which calls
// us) during pickup but must *not* be allowed to change their
@@ -14,17 +14,18 @@ class CHoverAirMoveType: public AAirMoveType
CHoverAirMoveType(CUnit* owner);
// MoveType interface
- bool Update();
- void SlowUpdate();
- void StartMoving(float3 pos, float goalRadius);
- void StartMoving(float3 pos, float goalRadius, float speed);
- void KeepPointingTo(float3 pos, float distance, bool aggressive);
- void StopMoving(bool callScript = false, bool hardStop = false);
+ bool Update() override;
+ void SlowUpdate() override;
+
+ void StartMoving(float3 pos, float goalRadius) override;
+ void StartMoving(float3 pos, float goalRadius, float speed) override;
+ void KeepPointingTo(float3 pos, float distance, bool aggressive) override;
+ void StopMoving(bool callScript = false, bool hardStop = false, bool cancelRaw = false) override;
bool SetMemberValue(unsigned int memberHash, void* memberValue);
void ForceHeading(short h);
- void SetGoal(const float3& pos, float distance = 0.0f);
+ void SetGoal(const float3& pos, float distance = 0.0f) override;
void SetState(AircraftState newState);
void SetAllowLanding(bool b);
@@ -22,7 +22,7 @@ class AMoveType : public CObject
virtual void StartMoving(float3 pos, float goalRadius, float speed) = 0;
virtual void KeepPointingTo(float3 pos, float distance, bool aggressive) = 0;
virtual void KeepPointingTo(CUnit* unit, float distance, bool aggressive);
- virtual void StopMoving(bool callScript = false, bool hardStop = false) = 0;
+ virtual void StopMoving(bool callScript = false, bool hardStop = false, bool cancelRaw = false) = 0;
virtual bool CanApplyImpulse(const float3&) { return false; }
virtual void LeaveTransport() {}
@@ -14,7 +14,7 @@ class CScriptMoveType : public AMoveType
virtual ~CScriptMoveType();
public:
- bool Update();
+ bool Update() override;
void ForceUpdates();
void SetPhysics(const float3& pos, const float3& vel, const float3& rot);
@@ -27,16 +27,16 @@ class CScriptMoveType : public AMoveType
void SetNoBlocking(bool state);
public: // null'ed virtuals
- void StartMoving(float3, float goalRadius) {}
- void StartMoving(float3, float goalRadius, float speed) {}
- void KeepPointingTo(float3, float distance, bool aggressive) {}
- void KeepPointingTo(CUnit* unit, float distance, bool aggressive) {}
- void StopMoving(bool callScript = false, bool hardStop = false) {}
-
- void SetGoal(const float3& pos, float distance = 0.0f) {}
- void SetMaxSpeed(float speed) {}
- void SetWantedMaxSpeed(float speed) {}
- void LeaveTransport() {}
+ void StartMoving(float3, float goalRadius) override {}
+ void StartMoving(float3, float goalRadius, float speed) override {}
+ void KeepPointingTo(float3, float distance, bool aggressive) override {}
+ void KeepPointingTo(CUnit* unit, float distance, bool aggressive) override {}
+ void StopMoving(bool callScript = false, bool hardStop = false, bool cancelRaw = false) override {}
+
+ void SetGoal(const float3& pos, float distance = 0.0f) override {}
+ void SetMaxSpeed(float speed) override {}
+ void SetWantedMaxSpeed(float speed) override {}
+ void LeaveTransport() override {}
protected:
void CheckLimits();
@@ -11,15 +11,16 @@ class CStaticMoveType : public AMoveType
public:
CStaticMoveType(CUnit* unit) : AMoveType(unit) {}
- void StartMoving(float3 pos, float goalRadius) {}
- void StartMoving(float3 pos, float goalRadius, float speed) {}
- void StopMoving(bool callScript = false, bool hardStop = false) {}
- void SetMaxSpeed(float speed) { /* override AMoveType (our maxSpeed IS allowed to be 0) */ }
- void KeepPointingTo(float3 pos, float distance, bool aggressive) {}
+ void StartMoving(float3 pos, float goalRadius) override {}
+ void StartMoving(float3 pos, float goalRadius, float speed) override {}
+ void StopMoving(bool callScript = false, bool hardStop = false, bool cancelRaw = false) override {}
- bool Update() { return false; }
- void SlowUpdate();
+ void SetMaxSpeed(float speed) override { /* override AMoveType (our maxSpeed IS allowed to be 0) */ }
+ void KeepPointingTo(float3 pos, float distance, bool aggressive) override {}
+
+ bool Update() override { return false; }
+ void SlowUpdate() override;
};
#endif // STATICMOVETYPE_H
@@ -1297,7 +1297,7 @@ void CStrafeAirMoveType::StartMoving(float3 pos, float goalRadius, float speed)
SetGoal(pos);
}
-void CStrafeAirMoveType::StopMoving(bool callScript, bool hardStop)
+void CStrafeAirMoveType::StopMoving(bool callScript, bool hardStop, bool)
{
SetGoal(owner->pos);
ClearLandingPos();
@@ -50,7 +50,7 @@ class CStrafeAirMoveType: public AAirMoveType
void KeepPointingTo(float3 pos, float distance, bool aggressive) override {}
void StartMoving(float3 pos, float goalRadius) override;
void StartMoving(float3 pos, float goalRadius, float speed) override;
- void StopMoving(bool callScript = false, bool hardStop = false) override;
+ void StopMoving(bool callScript = false, bool hardStop = false, bool cancelRaw = false) override;
void Takeoff() override;

0 comments on commit d34ef2f

Please sign in to comment.