1
0
forked from 0ad/0ad

Fix #1833: animals spin around needlessly while roaming.

Patch from mimo.

This was SVN commit r13924.
This commit is contained in:
Ykkrosh 2013-09-30 23:52:22 +00:00
parent e449364408
commit 9f5635085e
4 changed files with 38 additions and 4 deletions

View File

@ -2431,10 +2431,12 @@ var UnitFsmSpec = {
this.MoveRandomly(+this.template.RoamDistance);
// Set a random timer to switch to feeding state
this.StartTimer(RandomInt(+this.template.RoamTimeMin, +this.template.RoamTimeMax));
this.SetFacePointAfterMove(false);
},
"leave": function() {
this.StopTimer();
this.SetFacePointAfterMove(true);
},
"LosRangeUpdate": function(msg) {
@ -4583,6 +4585,13 @@ UnitAI.prototype.MoveRandomly = function(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)
{
var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);

View File

@ -129,6 +129,7 @@ public:
entity_pos_t m_Radius;
bool m_Moving;
bool m_FacePointAfterMove;
enum State
{
@ -281,6 +282,8 @@ public:
m_FormationController = paramNode.GetChild("FormationController").ToBool();
m_Moving = false;
m_FacePointAfterMove = true;
m_WalkSpeed = paramNode.GetChild("WalkSpeed").ToFixed();
m_Speed = m_WalkSpeed;
m_CurSpeed = fixed::Zero();
@ -342,6 +345,7 @@ public:
serialize.NumberFixed_Unbounded("speed", m_Speed);
serialize.Bool("moving", m_Moving);
serialize.Bool("facePointAfterMove", m_FacePointAfterMove);
SerializeVector<SerializeWaypoint>()(serialize, "long path", m_LongPath.m_Waypoints);
SerializeVector<SerializeWaypoint>()(serialize, "short path", m_ShortPath.m_Waypoints);
@ -428,6 +432,11 @@ public:
m_Speed = speed;
}
virtual void SetFacePointAfterMove(bool facePointAfterMove)
{
m_FacePointAfterMove = facePointAfterMove;
}
virtual void SetDebugOverlay(bool enabled)
{
m_DebugOverlayEnabled = enabled;
@ -963,7 +972,9 @@ void CCmpUnitMotion::Move(fixed dt)
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
// 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
{
// We're already in range - no need to move anywhere
FaceTowardsPointFromPos(pos, x, z);
if (m_FacePointAfterMove)
FaceTowardsPointFromPos(pos, x, z);
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)
{
// 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;
}
else
@ -1496,7 +1509,8 @@ bool CCmpUnitMotion::MoveToTargetRange(entity_id_t target, entity_pos_t minRange
if (circleDistance < maxRange)
{
// 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;
}

View File

@ -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("GetWalkSpeed", fixed, ICmpUnitMotion, GetWalkSpeed)
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("SetDebugOverlay", void, ICmpUnitMotion, SetDebugOverlay, bool)
END_INTERFACE_WRAPPER(UnitMotion)
@ -104,6 +105,11 @@ public:
return m_Script.Call<fixed>("GetRunSpeed");
}
virtual void SetFacePointAfterMove(bool facePointAfterMove)
{
m_Script.CallVoid("SetFacePointAfterMove", facePointAfterMove);
}
virtual ICmpPathfinder::pass_class_t GetPassabilityClass()
{
return m_Script.Call<ICmpPathfinder::pass_class_t>("GetPassabilityClass");

View File

@ -109,6 +109,11 @@ public:
*/
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.
*/