Fix #1833: animals spin around needlessly while roaming.
Patch from mimo. This was SVN commit r13924.
This commit is contained in:
parent
e449364408
commit
9f5635085e
@ -2431,10 +2431,12 @@ var UnitFsmSpec = {
|
|||||||
this.MoveRandomly(+this.template.RoamDistance);
|
this.MoveRandomly(+this.template.RoamDistance);
|
||||||
// Set a random timer to switch to feeding state
|
// Set a random timer to switch to feeding state
|
||||||
this.StartTimer(RandomInt(+this.template.RoamTimeMin, +this.template.RoamTimeMax));
|
this.StartTimer(RandomInt(+this.template.RoamTimeMin, +this.template.RoamTimeMax));
|
||||||
|
this.SetFacePointAfterMove(false);
|
||||||
},
|
},
|
||||||
|
|
||||||
"leave": function() {
|
"leave": function() {
|
||||||
this.StopTimer();
|
this.StopTimer();
|
||||||
|
this.SetFacePointAfterMove(true);
|
||||||
},
|
},
|
||||||
|
|
||||||
"LosRangeUpdate": function(msg) {
|
"LosRangeUpdate": function(msg) {
|
||||||
@ -4583,6 +4585,13 @@ UnitAI.prototype.MoveRandomly = function(distance)
|
|||||||
cmpMotion.MoveToPointRange(tx, tz, distance, distance);
|
cmpMotion.MoveToPointRange(tx, tz, distance, distance);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UnitAI.prototype.SetFacePointAfterMove = function(val)
|
||||||
|
{
|
||||||
|
var cmpMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
|
||||||
|
if (cmpMotion)
|
||||||
|
cmpMotion.SetFacePointAfterMove(val);
|
||||||
|
};
|
||||||
|
|
||||||
UnitAI.prototype.AttackEntitiesByPreference = function(ents)
|
UnitAI.prototype.AttackEntitiesByPreference = function(ents)
|
||||||
{
|
{
|
||||||
var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);
|
var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);
|
||||||
|
@ -129,6 +129,7 @@ public:
|
|||||||
|
|
||||||
entity_pos_t m_Radius;
|
entity_pos_t m_Radius;
|
||||||
bool m_Moving;
|
bool m_Moving;
|
||||||
|
bool m_FacePointAfterMove;
|
||||||
|
|
||||||
enum State
|
enum State
|
||||||
{
|
{
|
||||||
@ -281,6 +282,8 @@ public:
|
|||||||
m_FormationController = paramNode.GetChild("FormationController").ToBool();
|
m_FormationController = paramNode.GetChild("FormationController").ToBool();
|
||||||
|
|
||||||
m_Moving = false;
|
m_Moving = false;
|
||||||
|
m_FacePointAfterMove = true;
|
||||||
|
|
||||||
m_WalkSpeed = paramNode.GetChild("WalkSpeed").ToFixed();
|
m_WalkSpeed = paramNode.GetChild("WalkSpeed").ToFixed();
|
||||||
m_Speed = m_WalkSpeed;
|
m_Speed = m_WalkSpeed;
|
||||||
m_CurSpeed = fixed::Zero();
|
m_CurSpeed = fixed::Zero();
|
||||||
@ -342,6 +345,7 @@ public:
|
|||||||
serialize.NumberFixed_Unbounded("speed", m_Speed);
|
serialize.NumberFixed_Unbounded("speed", m_Speed);
|
||||||
|
|
||||||
serialize.Bool("moving", m_Moving);
|
serialize.Bool("moving", m_Moving);
|
||||||
|
serialize.Bool("facePointAfterMove", m_FacePointAfterMove);
|
||||||
|
|
||||||
SerializeVector<SerializeWaypoint>()(serialize, "long path", m_LongPath.m_Waypoints);
|
SerializeVector<SerializeWaypoint>()(serialize, "long path", m_LongPath.m_Waypoints);
|
||||||
SerializeVector<SerializeWaypoint>()(serialize, "short path", m_ShortPath.m_Waypoints);
|
SerializeVector<SerializeWaypoint>()(serialize, "short path", m_ShortPath.m_Waypoints);
|
||||||
@ -428,6 +432,11 @@ public:
|
|||||||
m_Speed = speed;
|
m_Speed = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void SetFacePointAfterMove(bool facePointAfterMove)
|
||||||
|
{
|
||||||
|
m_FacePointAfterMove = facePointAfterMove;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void SetDebugOverlay(bool enabled)
|
virtual void SetDebugOverlay(bool enabled)
|
||||||
{
|
{
|
||||||
m_DebugOverlayEnabled = enabled;
|
m_DebugOverlayEnabled = enabled;
|
||||||
@ -963,7 +972,9 @@ void CCmpUnitMotion::Move(fixed dt)
|
|||||||
|
|
||||||
StopMoving();
|
StopMoving();
|
||||||
|
|
||||||
FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z);
|
|
||||||
|
if (m_FacePointAfterMove)
|
||||||
|
FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z);
|
||||||
// TODO: if the goal was a square building, we ought to point towards the
|
// TODO: if the goal was a square building, we ought to point towards the
|
||||||
// nearest point on the square, not towards its center
|
// nearest point on the square, not towards its center
|
||||||
}
|
}
|
||||||
@ -1312,7 +1323,8 @@ bool CCmpUnitMotion::MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// We're already in range - no need to move anywhere
|
// We're already in range - no need to move anywhere
|
||||||
FaceTowardsPointFromPos(pos, x, z);
|
if (m_FacePointAfterMove)
|
||||||
|
FaceTowardsPointFromPos(pos, x, z);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1474,7 +1486,8 @@ bool CCmpUnitMotion::MoveToTargetRange(entity_id_t target, entity_pos_t minRange
|
|||||||
else if (maxRange < entity_pos_t::Zero() || distance < maxRange)
|
else if (maxRange < entity_pos_t::Zero() || distance < maxRange)
|
||||||
{
|
{
|
||||||
// We're already in range - no need to move anywhere
|
// We're already in range - no need to move anywhere
|
||||||
FaceTowardsPointFromPos(pos, goal.x, goal.z);
|
if (m_FacePointAfterMove)
|
||||||
|
FaceTowardsPointFromPos(pos, goal.x, goal.z);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1496,7 +1509,8 @@ bool CCmpUnitMotion::MoveToTargetRange(entity_id_t target, entity_pos_t minRange
|
|||||||
if (circleDistance < maxRange)
|
if (circleDistance < maxRange)
|
||||||
{
|
{
|
||||||
// We're already in range - no need to move anywhere
|
// We're already in range - no need to move anywhere
|
||||||
FaceTowardsPointFromPos(pos, goal.x, goal.z);
|
if (m_FacePointAfterMove)
|
||||||
|
FaceTowardsPointFromPos(pos, goal.x, goal.z);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ DEFINE_INTERFACE_METHOD_1("SetSpeed", void, ICmpUnitMotion, SetSpeed, fixed)
|
|||||||
DEFINE_INTERFACE_METHOD_0("IsMoving", bool, ICmpUnitMotion, IsMoving)
|
DEFINE_INTERFACE_METHOD_0("IsMoving", bool, ICmpUnitMotion, IsMoving)
|
||||||
DEFINE_INTERFACE_METHOD_0("GetWalkSpeed", fixed, ICmpUnitMotion, GetWalkSpeed)
|
DEFINE_INTERFACE_METHOD_0("GetWalkSpeed", fixed, ICmpUnitMotion, GetWalkSpeed)
|
||||||
DEFINE_INTERFACE_METHOD_0("GetRunSpeed", fixed, ICmpUnitMotion, GetRunSpeed)
|
DEFINE_INTERFACE_METHOD_0("GetRunSpeed", fixed, ICmpUnitMotion, GetRunSpeed)
|
||||||
|
DEFINE_INTERFACE_METHOD_1("SetFacePointAfterMove", void, ICmpUnitMotion, SetFacePointAfterMove, bool)
|
||||||
DEFINE_INTERFACE_METHOD_1("SetUnitRadius", void, ICmpUnitMotion, SetUnitRadius, fixed)
|
DEFINE_INTERFACE_METHOD_1("SetUnitRadius", void, ICmpUnitMotion, SetUnitRadius, fixed)
|
||||||
DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpUnitMotion, SetDebugOverlay, bool)
|
DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpUnitMotion, SetDebugOverlay, bool)
|
||||||
END_INTERFACE_WRAPPER(UnitMotion)
|
END_INTERFACE_WRAPPER(UnitMotion)
|
||||||
@ -104,6 +105,11 @@ public:
|
|||||||
return m_Script.Call<fixed>("GetRunSpeed");
|
return m_Script.Call<fixed>("GetRunSpeed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void SetFacePointAfterMove(bool facePointAfterMove)
|
||||||
|
{
|
||||||
|
m_Script.CallVoid("SetFacePointAfterMove", facePointAfterMove);
|
||||||
|
}
|
||||||
|
|
||||||
virtual ICmpPathfinder::pass_class_t GetPassabilityClass()
|
virtual ICmpPathfinder::pass_class_t GetPassabilityClass()
|
||||||
{
|
{
|
||||||
return m_Script.Call<ICmpPathfinder::pass_class_t>("GetPassabilityClass");
|
return m_Script.Call<ICmpPathfinder::pass_class_t>("GetPassabilityClass");
|
||||||
|
@ -109,6 +109,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual fixed GetRunSpeed() = 0;
|
virtual fixed GetRunSpeed() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the unit will turn to face the target point after finishing moving.
|
||||||
|
*/
|
||||||
|
virtual void SetFacePointAfterMove(bool facePointAfterMove) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the unit's passability class.
|
* Get the unit's passability class.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user