Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpUnitMotion.h
Show First 20 Lines • Show All 219 Lines • ▼ Show 20 Lines | public: | ||||
// If this is not INVALID_ENTITY, the unit is a formation member. | // If this is not INVALID_ENTITY, the unit is a formation member. | ||||
entity_id_t m_FormationController = INVALID_ENTITY; | entity_id_t m_FormationController = INVALID_ENTITY; | ||||
// If the entity moves, it will do so at m_WalkSpeed * m_SpeedMultiplier. | // If the entity moves, it will do so at m_WalkSpeed * m_SpeedMultiplier. | ||||
fixed m_SpeedMultiplier; | fixed m_SpeedMultiplier; | ||||
// This caches the resulting speed from m_WalkSpeed * m_SpeedMultiplier for convenience. | // This caches the resulting speed from m_WalkSpeed * m_SpeedMultiplier for convenience. | ||||
fixed m_Speed; | fixed m_Speed; | ||||
// Mean speed over the last turn. | |||||
fixed m_LastTurnSpeed; | |||||
Freagarach: Do note that Last TurnSpeed and LastTurn Speed look similar. | |||||
// The speed achieved at the end of the current turn. | // The speed achieved at the end of the current turn. | ||||
fixed m_CurrentSpeed; | fixed m_CurrentSpeed; | ||||
fixed m_InstantTurnAngle; | fixed m_InstantTurnAngle; | ||||
fixed m_Acceleration; | fixed m_Acceleration; | ||||
// Currently active paths (storing waypoints in reverse order). | // Currently active paths (storing waypoints in reverse order). | ||||
Show All 39 Lines | public: | ||||
virtual void Init(const CParamNode& paramNode) | virtual void Init(const CParamNode& paramNode) | ||||
{ | { | ||||
m_IsFormationController = paramNode.GetChild("FormationController").ToBool(); | m_IsFormationController = paramNode.GetChild("FormationController").ToBool(); | ||||
m_FacePointAfterMove = true; | m_FacePointAfterMove = true; | ||||
m_WalkSpeed = m_TemplateWalkSpeed = m_Speed = paramNode.GetChild("WalkSpeed").ToFixed(); | m_WalkSpeed = m_TemplateWalkSpeed = m_Speed = paramNode.GetChild("WalkSpeed").ToFixed(); | ||||
m_SpeedMultiplier = fixed::FromInt(1); | m_SpeedMultiplier = fixed::FromInt(1); | ||||
m_CurrentSpeed = fixed::Zero(); | m_LastTurnSpeed = m_CurrentSpeed = fixed::Zero(); | ||||
m_RunMultiplier = m_TemplateRunMultiplier = fixed::FromInt(1); | m_RunMultiplier = m_TemplateRunMultiplier = fixed::FromInt(1); | ||||
if (paramNode.GetChild("RunMultiplier").IsOk()) | if (paramNode.GetChild("RunMultiplier").IsOk()) | ||||
m_RunMultiplier = m_TemplateRunMultiplier = paramNode.GetChild("RunMultiplier").ToFixed(); | m_RunMultiplier = m_TemplateRunMultiplier = paramNode.GetChild("RunMultiplier").ToFixed(); | ||||
m_InstantTurnAngle = paramNode.GetChild("InstantTurnAngle").ToFixed(); | m_InstantTurnAngle = paramNode.GetChild("InstantTurnAngle").ToFixed(); | ||||
m_Acceleration = m_TemplateAcceleration = paramNode.GetChild("Acceleration").ToFixed(); | m_Acceleration = m_TemplateAcceleration = paramNode.GetChild("Acceleration").ToFixed(); | ||||
Show All 39 Lines | void SerializeCommon(S& serialize) | ||||
serialize.NumberFixed_Unbounded("target pos y", m_MoveRequest.m_Position.Y); | serialize.NumberFixed_Unbounded("target pos y", m_MoveRequest.m_Position.Y); | ||||
serialize.NumberFixed_Unbounded("target min range", m_MoveRequest.m_MinRange); | serialize.NumberFixed_Unbounded("target min range", m_MoveRequest.m_MinRange); | ||||
serialize.NumberFixed_Unbounded("target max range", m_MoveRequest.m_MaxRange); | serialize.NumberFixed_Unbounded("target max range", m_MoveRequest.m_MaxRange); | ||||
serialize.NumberU32_Unbounded("formation controller", m_FormationController); | serialize.NumberU32_Unbounded("formation controller", m_FormationController); | ||||
serialize.NumberFixed_Unbounded("speed multiplier", m_SpeedMultiplier); | serialize.NumberFixed_Unbounded("speed multiplier", m_SpeedMultiplier); | ||||
serialize.NumberFixed_Unbounded("last turn speed", m_LastTurnSpeed); | |||||
Not Done Inline Actions? Freagarach: ? | |||||
serialize.NumberFixed_Unbounded("current speed", m_CurrentSpeed); | serialize.NumberFixed_Unbounded("current speed", m_CurrentSpeed); | ||||
serialize.NumberFixed_Unbounded("instant turn angle", m_InstantTurnAngle); | serialize.NumberFixed_Unbounded("instant turn angle", m_InstantTurnAngle); | ||||
serialize.NumberFixed_Unbounded("acceleration", m_Acceleration); | serialize.NumberFixed_Unbounded("acceleration", m_Acceleration); | ||||
serialize.Bool("facePointAfterMove", m_FacePointAfterMove); | serialize.Bool("facePointAfterMove", m_FacePointAfterMove); | ||||
serialize.Bool("pushing", m_Pushing); | serialize.Bool("pushing", m_Pushing); | ||||
▲ Show 20 Lines • Show All 669 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
state.ignore = !m_Pushing || !m_BlockMovement; | state.ignore = !m_Pushing || !m_BlockMovement; | ||||
state.wasObstructed = false; | state.wasObstructed = false; | ||||
state.wentStraight = false; | state.wentStraight = false; | ||||
// If we were idle and will still be, no need for an update. | // If we were idle and will still be, no need for an update. | ||||
state.needUpdate = state.cmpPosition->IsInWorld() && | state.needUpdate = state.cmpPosition->IsInWorld() && | ||||
(m_CurrentSpeed != fixed::Zero() || m_MoveRequest.m_Type != MoveRequest::NONE); | (m_CurrentSpeed != fixed::Zero() || m_LastTurnSpeed != fixed::Zero() || m_MoveRequest.m_Type != MoveRequest::NONE); | ||||
if (!m_BlockMovement) | if (!m_BlockMovement) | ||||
return; | return; | ||||
state.controlGroup = IsFormationMember() ? m_FormationController : INVALID_ENTITY; | state.controlGroup = IsFormationMember() ? m_FormationController : INVALID_ENTITY; | ||||
// Update moving flag, this is an internal construct used for pushing, | // Update moving flag, this is an internal construct used for pushing, | ||||
// so it does not really reflect whether the unit is actually moving or not. | // so it does not really reflect whether the unit is actually moving or not. | ||||
▲ Show 20 Lines • Show All 252 Lines • ▼ Show 20 Lines | void CCmpUnitMotion::UpdateMovementState(entity_pos_t speed, entity_pos_t meanSpeed) | ||||
if (cmpVisual) | if (cmpVisual) | ||||
{ | { | ||||
if (meanSpeed == fixed::Zero()) | if (meanSpeed == fixed::Zero()) | ||||
cmpVisual->SelectMovementAnimation("idle", fixed::FromInt(1)); | cmpVisual->SelectMovementAnimation("idle", fixed::FromInt(1)); | ||||
else | else | ||||
cmpVisual->SelectMovementAnimation(meanSpeed > (m_WalkSpeed / 2).Multiply(m_RunMultiplier + fixed::FromInt(1)) ? "run" : "walk", meanSpeed); | cmpVisual->SelectMovementAnimation(meanSpeed > (m_WalkSpeed / 2).Multiply(m_RunMultiplier + fixed::FromInt(1)) ? "run" : "walk", meanSpeed); | ||||
} | } | ||||
m_LastTurnSpeed = meanSpeed; | |||||
m_CurrentSpeed = speed; | m_CurrentSpeed = speed; | ||||
} | } | ||||
bool CCmpUnitMotion::HandleObstructedMove(bool moved) | bool CCmpUnitMotion::HandleObstructedMove(bool moved) | ||||
{ | { | ||||
CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); | CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); | ||||
if (!cmpPosition || !cmpPosition->IsInWorld()) | if (!cmpPosition || !cmpPosition->IsInWorld()) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 577 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Do note that Last TurnSpeed and LastTurn Speed look similar.