Skip to content

Commit 1316bec

Browse files
committed
Added the ability to press shift key to start running
1 parent 12ae72d commit 1316bec

File tree

10 files changed

+113
-44
lines changed

10 files changed

+113
-44
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1616
New `Actor` Lua property `JumpHeight` (R) to estimate the jump height of the actor (in metres), based on the actor's jetpack and weight. Actors without a jetpack return 0.
1717
The new function `GetPathFindingFlyingJumpHeight()` can be used to get a jumpHeight that allows flying (i.e infinite jump height). This is also the value that `ACRocket`s and `ACDropships` return for `JumpHeight`.
1818

19+
- Added running.
20+
Players on PC can enable running by holding the shift key. TBD add other platforms
21+
When running, you cannot sharpaim or shoot your weapon.
22+
Added new `MovementState` type `RUN` for script.
23+
1924
- New music system, including a dynamic horizontal sequencing system, under the new music manager `MusicMan`.
2025
`PlayDynamicSong(string songName, string songSectionName, bool playImmediately, bool playTransition, bool smoothFade)` to play a new DynamicSong.
2126
`SetNextDynamicSongSection(string songSectionName, bool playImmediately, bool playTransition, bool smoothFade)` to queue a new DynamicSongSection for the currently playing song.

Source/Entities/AHuman.cpp

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,15 @@ int AHuman::Create(const AHuman& reference) {
229229
m_RotAngleTargets[i] = reference.m_RotAngleTargets[i];
230230
}
231231

232+
// Default the run walkpath to be the same as the walk one, if it doesn't exist
233+
if (m_Paths[FGROUND][RUN].GetSegCount() == 0) {
234+
const LimbPath& walkLimbPath = reference.m_Paths[FGROUND][WALK];
235+
float speedIncrease = walkLimbPath.GetSpeed(Speed::FAST) / walkLimbPath.GetSpeed(Speed::NORMAL);
236+
m_Paths[FGROUND][RUN].Create(walkLimbPath);
237+
m_Paths[FGROUND][RUN].SetBaseSpeedMultiplier(speedIncrease);
238+
m_RotAngleTargets[RUN] = reference.m_RotAngleTargets[RUN];
239+
}
240+
232241
m_DeviceState = reference.m_DeviceState;
233242
m_SweepState = reference.m_SweepState;
234243
m_DigState = reference.m_DigState;
@@ -293,15 +302,18 @@ int AHuman::ReadProperty(const std::string_view& propName, Reader& reader) {
293302
MatchProperty("StandLimbPath", { reader >> m_Paths[FGROUND][STAND]; });
294303
MatchProperty("StandLimbPathBG", { reader >> m_Paths[BGROUND][STAND]; });
295304
MatchProperty("WalkLimbPath", { reader >> m_Paths[FGROUND][WALK]; });
305+
MatchProperty("RunLimbPath", { reader >> m_Paths[FGROUND][RUN]; });
296306
MatchProperty("CrouchLimbPath", { reader >> m_Paths[FGROUND][CROUCH]; });
297307
MatchProperty("CrouchLimbPathBG", { reader >> m_Paths[BGROUND][CROUCH]; });
298308
MatchProperty("CrawlLimbPath", { reader >> m_Paths[FGROUND][CRAWL]; });
299309
MatchProperty("ArmCrawlLimbPath", { reader >> m_Paths[FGROUND][ARMCRAWL]; });
300310
MatchProperty("ClimbLimbPath", { reader >> m_Paths[FGROUND][CLIMB]; });
301311
MatchProperty("JumpLimbPath", { reader >> m_Paths[FGROUND][JUMP]; });
302312
MatchProperty("DislodgeLimbPath", { reader >> m_Paths[FGROUND][DISLODGE]; });
313+
303314
MatchProperty("StandRotAngleTarget", { reader >> m_RotAngleTargets[STAND]; });
304315
MatchProperty("WalkRotAngleTarget", { reader >> m_RotAngleTargets[WALK]; });
316+
MatchProperty("RunRotAngleTarget", { reader >> m_RotAngleTargets[RUN]; });
305317
MatchProperty("CrouchRotAngleTarget", { reader >> m_RotAngleTargets[CROUCH]; });
306318
MatchProperty("JumpRotAngleTarget", { reader >> m_RotAngleTargets[JUMP]; });
307319

@@ -353,6 +365,8 @@ int AHuman::Save(Writer& writer) const {
353365
writer << m_Paths[BGROUND][STAND];
354366
writer.NewProperty("WalkLimbPath");
355367
writer << m_Paths[FGROUND][WALK];
368+
writer.NewProperty("RunLimbPath");
369+
writer << m_Paths[FGROUND][RUN];
356370
writer.NewProperty("CrouchLimbPath");
357371
writer << m_Paths[FGROUND][CROUCH];
358372
writer.NewProperty("CrawlLimbPath");
@@ -366,6 +380,12 @@ int AHuman::Save(Writer& writer) const {
366380
writer.NewProperty("DislodgeLimbPath");
367381
writer << m_Paths[FGROUND][DISLODGE];
368382

383+
writer.NewPropertyWithValue("StandRotAngleTarget", m_RotAngleTargets[STAND]);
384+
writer.NewPropertyWithValue("WalkRotAngleTarget", m_RotAngleTargets[WALK]);
385+
writer.NewPropertyWithValue("RunRotAngleTarget", m_RotAngleTargets[RUN]);
386+
writer.NewPropertyWithValue("CrouchRotAngleTarget", m_RotAngleTargets[CROUCH]);
387+
writer.NewPropertyWithValue("JumpRotAngleTarget", m_RotAngleTargets[JUMP]);
388+
369389
return 0;
370390
}
371391

@@ -1428,7 +1448,7 @@ void AHuman::UpdateLimbPathSpeed() {
14281448
m_Paths[FGROUND][m_MoveState].SetTravelSpeedMultiplier(1.0F);
14291449
m_Paths[BGROUND][m_MoveState].SetTravelSpeedMultiplier(1.0F);
14301450

1431-
if (m_MoveState == WALK || m_MoveState == CRAWL) {
1451+
if (m_MoveState == WALK || m_MoveState == RUN || m_MoveState == CRAWL) {
14321452
// If crouching, move at reduced speed
14331453
const float crouchSpeedMultiplier = 0.5F;
14341454
float travelSpeedMultiplier = Lerp(0.0F, m_MaxWalkPathCrouchShift, 1.0F, crouchSpeedMultiplier, -m_WalkPathOffset.m_Y);
@@ -1496,22 +1516,26 @@ void AHuman::PreControllerUpdate() {
14961516
}
14971517
// Only if not jumping, OR if jumping, and apparently stuck on something - then help out with the limbs.
14981518
if (m_MoveState != JUMP || isStill) {
1519+
MovementState oldMoveState = m_MoveState;
1520+
if (crouching) {
1521+
m_MoveState = CRAWL;
1522+
} else if (m_Controller.IsState(MOVE_FAST)) {
1523+
m_MoveState = RUN;
1524+
} else {
1525+
m_MoveState = WALK;
1526+
}
1527+
14991528
// Restart the stride if we're just starting to walk or crawl.
1500-
if ((m_MoveState != WALK && !crouching) || (m_MoveState != CRAWL && crouching)) {
1529+
if (m_MoveState != oldMoveState) {
15011530
m_StrideStart = true;
15021531
MoveOutOfTerrain(g_MaterialGrass);
15031532
}
15041533

1505-
m_MoveState = crouching ? CRAWL : WALK;
1506-
15071534
// Engage prone state, this makes the body's rotational spring pull it horizontal instead of upright.
15081535
if (m_MoveState == CRAWL && m_ProneState == NOTPRONE) {
15091536
m_ProneState = GOPRONE;
15101537
m_ProneTimer.Reset();
15111538
}
1512-
1513-
m_Paths[FGROUND][m_MoveState].SetSpeed(m_Controller.IsState(MOVE_FAST) ? FAST : NORMAL);
1514-
m_Paths[BGROUND][m_MoveState].SetSpeed(m_Controller.IsState(MOVE_FAST) ? FAST : NORMAL);
15151539
}
15161540

15171541
// Walk backwards if the aiming is already focused in the opposite direction of travel.
@@ -1978,14 +2002,13 @@ void AHuman::PreControllerUpdate() {
19782002
UpdateLimbPathSpeed();
19792003

19802004
// WALKING, OR WE ARE JETPACKING AND STUCK
1981-
if (m_MoveState == WALK || (m_MoveState == JUMP && isStill)) {
2005+
if (m_MoveState == WALK || m_MoveState == RUN || (m_MoveState == JUMP && isStill)) {
19822006
m_Paths[FGROUND][STAND].Terminate();
19832007
m_Paths[BGROUND][STAND].Terminate();
19842008

1985-
// float FGLegProg = MAX(m_Paths[FGROUND][WALK].GetRegularProgress(), m_Paths[FGROUND][WALK].GetTotalTimeProgress());
1986-
// float BGLegProg = MAX(m_Paths[BGROUND][WALK].GetRegularProgress(), m_Paths[BGROUND][WALK].GetTotalTimeProgress());
1987-
float FGLegProg = m_Paths[FGROUND][WALK].GetRegularProgress();
1988-
float BGLegProg = m_Paths[BGROUND][WALK].GetRegularProgress();
2009+
MovementState movementPath = m_MoveState == RUN ? RUN : WALK;
2010+
float FGLegProg = m_Paths[FGROUND][movementPath].GetRegularProgress();
2011+
float BGLegProg = m_Paths[BGROUND][movementPath].GetRegularProgress();
19892012

19902013
bool restarted = false;
19912014

@@ -1994,24 +2017,24 @@ void AHuman::PreControllerUpdate() {
19942017
m_StrideStart = true;
19952018
}
19962019

1997-
if (m_pFGLeg && (!m_pBGLeg || !(m_Paths[FGROUND][WALK].PathEnded() && BGLegProg < 0.5F) || m_StrideStart)) {
2020+
if (m_pFGLeg && (!m_pBGLeg || !(m_Paths[FGROUND][movementPath].PathEnded() && BGLegProg < 0.5F) || m_StrideStart)) {
19982021
// Reset the stride timer if the path is about to restart.
1999-
if (m_Paths[FGROUND][WALK].PathEnded() || m_Paths[FGROUND][WALK].PathIsAtStart()) {
2022+
if (m_Paths[FGROUND][movementPath].PathEnded() || m_Paths[FGROUND][movementPath].PathIsAtStart()) {
20002023
m_StrideTimer.Reset();
20012024
}
20022025
Vector jointPos = m_Pos + RotateOffset(m_pFGLeg->GetParentOffset());
2003-
m_ArmClimbing[BGROUND] = !m_pFGFootGroup->PushAsLimb(jointPos, m_Vel, m_WalkAngle[FGROUND], m_Paths[FGROUND][WALK], deltaTime, &restarted, false, Vector(0.0F, m_Paths[FGROUND][WALK].GetLowestY()), m_WalkPathOffset);
2026+
m_ArmClimbing[BGROUND] = !m_pFGFootGroup->PushAsLimb(jointPos, m_Vel, m_WalkAngle[FGROUND], m_Paths[FGROUND][movementPath], deltaTime, &restarted, false, Vector(0.0F, m_Paths[FGROUND][movementPath].GetLowestY()), m_WalkPathOffset);
20042027
} else {
20052028
m_ArmClimbing[BGROUND] = false;
20062029
}
2007-
if (m_pBGLeg && (!m_pFGLeg || !(m_Paths[BGROUND][WALK].PathEnded() && FGLegProg < 0.5F))) {
2030+
if (m_pBGLeg && (!m_pFGLeg || !(m_Paths[BGROUND][movementPath].PathEnded() && FGLegProg < 0.5F))) {
20082031
m_StrideStart = false;
20092032
// Reset the stride timer if the path is about to restart.
2010-
if (m_Paths[BGROUND][WALK].PathEnded() || m_Paths[BGROUND][WALK].PathIsAtStart()) {
2033+
if (m_Paths[BGROUND][movementPath].PathEnded() || m_Paths[BGROUND][movementPath].PathIsAtStart()) {
20112034
m_StrideTimer.Reset();
20122035
}
20132036
Vector jointPos = m_Pos + RotateOffset(m_pBGLeg->GetParentOffset());
2014-
m_ArmClimbing[FGROUND] = !m_pBGFootGroup->PushAsLimb(jointPos, m_Vel, m_WalkAngle[BGROUND], m_Paths[BGROUND][WALK], deltaTime, &restarted, false, Vector(0.0F, m_Paths[BGROUND][WALK].GetLowestY()), m_WalkPathOffset);
2037+
m_ArmClimbing[FGROUND] = !m_pBGFootGroup->PushAsLimb(jointPos, m_Vel, m_WalkAngle[BGROUND], m_Paths[BGROUND][movementPath], deltaTime, &restarted, false, Vector(0.0F, m_Paths[BGROUND][movementPath].GetLowestY()), m_WalkPathOffset);
20152038
} else {
20162039
if (m_pBGLeg) {
20172040
m_pBGFootGroup->FlailAsLimb(m_Pos, RotateOffset(m_pBGLeg->GetParentOffset()), m_pBGLeg->GetMaxLength(), m_PrevVel, m_AngularVel, m_pBGLeg->GetMass(), deltaTime);
@@ -2054,7 +2077,7 @@ void AHuman::PreControllerUpdate() {
20542077
if (climbing) {
20552078
if (m_pFGArm && !m_pFGArm->GetHeldDevice() && !(m_Paths[FGROUND][CLIMB].PathEnded() && BGArmProg > 0.1F)) { // < 0.5F
20562079
m_ArmClimbing[FGROUND] = true;
2057-
m_Paths[FGROUND][WALK].Terminate();
2080+
m_Paths[FGROUND][movementPath].Terminate();
20582081
m_StrideStart = true;
20592082
// Reset the stride timer if the path is about to restart.
20602083
if (m_Paths[FGROUND][CLIMB].PathEnded() || m_Paths[FGROUND][CLIMB].PathIsAtStart()) {
@@ -2067,7 +2090,7 @@ void AHuman::PreControllerUpdate() {
20672090
}
20682091
if (m_pBGArm) {
20692092
m_ArmClimbing[BGROUND] = true;
2070-
m_Paths[BGROUND][WALK].Terminate();
2093+
m_Paths[BGROUND][movementPath].Terminate();
20712094
m_StrideStart = true;
20722095
// Reset the stride timer if the path is about to restart.
20732096
if (m_Paths[BGROUND][CLIMB].PathEnded() || m_Paths[BGROUND][CLIMB].PathIsAtStart()) {
@@ -2085,11 +2108,11 @@ void AHuman::PreControllerUpdate() {
20852108
m_StrideStart = true;
20862109
m_Paths[FGROUND][CLIMB].Terminate();
20872110
m_Paths[BGROUND][CLIMB].Terminate();
2088-
} else if (m_StrideTimer.IsPastSimMS(static_cast<double>(m_Paths[FGROUND][WALK].GetTotalPathTime() * 1.1F))) {
2111+
} else if (m_StrideTimer.IsPastSimMS(static_cast<double>(m_Paths[FGROUND][movementPath].GetTotalPathTime() * 1.1F))) {
20892112
// Reset the walking stride if it's taking longer than it should.
20902113
m_StrideStart = true;
2091-
m_Paths[FGROUND][WALK].Terminate();
2092-
m_Paths[BGROUND][WALK].Terminate();
2114+
m_Paths[FGROUND][movementPath].Terminate();
2115+
m_Paths[BGROUND][movementPath].Terminate();
20932116
}
20942117
} else if (m_MoveState == CRAWL) {
20952118
// Start crawling only once we are fully prone.
@@ -2345,7 +2368,7 @@ void AHuman::Update() {
23452368

23462369
if (HeldDevice* heldDevice = GetEquippedItem()) {
23472370
float maxLength = heldDevice->GetSharpLength();
2348-
if (maxLength == 0) {
2371+
if (maxLength == 0.0F || m_MoveState == RUN) {
23492372
m_SharpAimProgress = 0;
23502373
m_SharpAimMaxedOut = true;
23512374
} else if (m_MoveState == WALK) {

Source/Entities/Actor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace RTE {
4141
NOMOVE = 0,
4242
STAND,
4343
WALK,
44+
RUN,
4445
JUMP,
4546
DISLODGE,
4647
CROUCH,

Source/Entities/LimbPath.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ namespace RTE {
142142
return 0;
143143
}
144144

145+
/// Sets the base travel speed multiplier.
146+
/// @param newValue The new travel speed multiplier.
147+
void SetBaseSpeedMultiplier(float newValue) { m_BaseTravelSpeedMultiplier = newValue; }
148+
145149
/// Sets the current travel speed multiplier.
146150
/// @param newValue The new travel speed multiplier.
147151
void SetTravelSpeedMultiplier(float newValue) { m_CurrentTravelSpeedMultiplier = newValue; }

Source/Lua/LuaBindingsEntities.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, Actor) {
268268
.enum_("MovementState")[luabind::value("NOMOVE", Actor::MovementState::NOMOVE),
269269
luabind::value("STAND", Actor::MovementState::STAND),
270270
luabind::value("WALK", Actor::MovementState::WALK),
271+
luabind::value("RUN", Actor::MovementState::RUN),
271272
luabind::value("JUMP", Actor::MovementState::JUMP),
272273
luabind::value("DISLODGE", Actor::MovementState::DISLODGE),
273274
luabind::value("CROUCH", Actor::MovementState::CROUCH),

Source/Lua/LuaBindingsInput.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ LuaBindingRegisterFunctionDefinitionForType(InputLuaBindings, InputElements) {
2727
luabind::value("INPUT_L_DOWN", InputElements::INPUT_L_DOWN),
2828
luabind::value("INPUT_L_LEFT", InputElements::INPUT_L_LEFT),
2929
luabind::value("INPUT_L_RIGHT", InputElements::INPUT_L_RIGHT),
30+
luabind::value("INPUT_MOVE_FAST", InputElements::INPUT_MOVE_FAST),
3031
luabind::value("INPUT_R_UP", InputElements::INPUT_R_UP),
3132
luabind::value("INPUT_R_DOWN", InputElements::INPUT_R_DOWN),
3233
luabind::value("INPUT_R_LEFT", InputElements::INPUT_R_LEFT),

0 commit comments

Comments
 (0)