Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit f232693

Browse files
authored
Merge pull request #397 from cortex-command-community/4zk-content-source
`AHuman` walking improvement
2 parents 69f956d + 23f8dab commit f232693

File tree

8 files changed

+173
-118
lines changed

8 files changed

+173
-118
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
250250

251251
- New `SoundContainer` INI and Lua (R/W) property `PitchVariation`, which can be used to randomize the pitch of the sounds being played.
252252

253+
- New `AHuman` and `ACrab` INI and Lua (R/W) property `JetReplenishRate`, which determines how fast jump time (i.e. jetpack fuel) is replenished during downtime.
254+
253255
- Added `Entity` Lua function `entity:RemoveFromGroup(groupToRemoveFrom)` which removes the given group from the `Entity`. The reverse of `AddToGroup`.
254256

257+
- New `AHuman` Lua functions `GetWalkAngle(layer)` and `SetWalkAngle(layer, angle)`, which can be used to read and override walk path rotation of both Legs/Layers respectively. Note that the walk path rotation is automatically updated on each step to match the curvature of the terrain, so this value resets every update.
258+
255259
</details>
256260

257261
<details><summary><b>Changed</b></summary>

Entities/ACrab.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void ACrab::Clear()
5959
m_pJetpack = 0;
6060
m_JetTimeTotal = 0.0;
6161
m_JetTimeLeft = 0.0;
62+
m_JetReplenishRate = 1.0F;
6263
m_JetAngleRange = 0.25F;
6364
m_MoveState = STAND;
6465
for (int side = 0; side < SIDECOUNT; ++side)
@@ -188,6 +189,7 @@ int ACrab::Create(const ACrab &reference) {
188189

189190
m_JetTimeTotal = reference.m_JetTimeTotal;
190191
m_JetTimeLeft = reference.m_JetTimeLeft;
192+
m_JetReplenishRate = reference.m_JetReplenishRate;
191193
m_JetAngleRange = reference.m_JetAngleRange;
192194

193195
m_pLFGFootGroup = dynamic_cast<AtomGroup *>(reference.m_pLFGFootGroup->Clone());
@@ -254,10 +256,12 @@ int ACrab::ReadProperty(const std::string_view &propName, Reader &reader)
254256
SetTurret(dynamic_cast<Turret *>(g_PresetMan.ReadReflectedPreset(reader)));
255257
} else if (propName == "Jetpack") {
256258
SetJetpack(dynamic_cast<AEmitter *>(g_PresetMan.ReadReflectedPreset(reader)));
257-
} else if (propName == "JumpTime") {
259+
} else if (propName == "JumpTime" || propName == "JetTime") {
258260
reader >> m_JetTimeTotal;
259261
m_JetTimeTotal *= 1000;
260-
} else if (propName == "JumpAngleRange") {
262+
} else if (propName == "JumpReplenishRate" || propName == "JetReplenishRate") {
263+
reader >> m_JetReplenishRate;
264+
} else if (propName == "JumpAngleRange" || propName == "JetAngleRange") {
261265
reader >> m_JetAngleRange;
262266
} else if (propName == "LFGLeg" || propName == "LeftFGLeg") {
263267
SetLeftFGLeg(dynamic_cast<Leg *>(g_PresetMan.ReadReflectedPreset(reader)));
@@ -335,6 +339,8 @@ int ACrab::Save(Writer &writer) const
335339
writer.NewProperty("JumpTime");
336340
// Convert to seconds
337341
writer << m_JetTimeTotal / 1000;
342+
writer.NewProperty("JumpReplenishRate");
343+
writer << m_JetReplenishRate;
338344
writer.NewProperty("JumpAngleRange");
339345
writer << m_JetAngleRange;
340346
writer.NewProperty("LFGLeg");
@@ -2156,8 +2162,7 @@ void ACrab::Update()
21562162
m_pJetpack->EnableEmission(false);
21572163
if (m_MoveState == JUMP) { m_MoveState = STAND; }
21582164

2159-
// Replenish the jetpack time, twice as fast
2160-
m_JetTimeLeft = std::min(m_JetTimeLeft + g_TimerMan.GetDeltaTimeMS() * 2.0F, m_JetTimeTotal);
2165+
m_JetTimeLeft = std::min(m_JetTimeLeft + g_TimerMan.GetDeltaTimeMS() * 2.0F * m_JetReplenishRate, m_JetTimeTotal);
21612166
}
21622167

21632168
float maxAngle = c_HalfPI * m_JetAngleRange;

Entities/ACrab.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@ class ACrab :
258258
float GetJetTimeLeft() const { return m_JetTimeLeft; }
259259

260260

261+
/// <summary>
262+
/// Gets the rate at which this ACrab's jetpack is replenished during downtime.
263+
/// </summary>
264+
/// <returns>The rate at which the jetpack is replenished.</returns>
265+
float GetJetReplenishRate() const { return m_JetReplenishRate; }
266+
267+
/// <summary>
268+
/// Sets the rate at which this ACrab's jetpack is replenished during downtime.
269+
/// </summary>
270+
/// <param name="newValue">The rate at which the jetpack is replenished.</param>
271+
void SetJetReplenishRate(float newValue) { m_JetReplenishRate = newValue; }
272+
261273
/// <summary>
262274
/// Gets the scalar ratio at which this jetpack's thrust angle follows the aim angle of the user.
263275
/// </summary>
@@ -585,6 +597,7 @@ int FirearmActivationDelay() const;
585597
float m_JetTimeTotal;
586598
// How much time left the jetpack can go, in ms
587599
float m_JetTimeLeft;
600+
float m_JetReplenishRate; //!< A multiplier affecting how fast the jetpack fuel will replenish when not in use. 1 means that jet time replenishes at 2x speed in relation to depletion.
588601
// Ratio at which the jetpack angle follows aim angle
589602
float m_JetAngleRange;
590603
// Blink timer

Entities/AHuman.cpp

Lines changed: 104 additions & 112 deletions
Large diffs are not rendered by default.

Entities/AHuman.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,20 @@ ClassInfoGetters;
373373

374374
void SetJetTimeLeft(float newValue) { m_JetTimeLeft = newValue < m_JetTimeTotal ? newValue : m_JetTimeTotal; }
375375

376+
/// <summary>
377+
/// Gets the rate at which this AHuman's jetpack is replenished during downtime.
378+
/// </summary>
379+
/// <returns>The rate at which the jetpack is replenished.</returns>
380+
float GetJetReplenishRate() const { return m_JetReplenishRate; }
381+
382+
383+
/// <summary>
384+
/// Sets the rate at which this AHuman's jetpack is replenished during downtime.
385+
/// </summary>
386+
/// <param name="newValue">The rate at which the jetpack is replenished.</param>
387+
void SetJetReplenishRate(float newValue) { m_JetReplenishRate = newValue; }
388+
389+
376390
/// <summary>
377391
/// Gets the scalar ratio at which this jetpack's thrust angle follows the aim angle of the user.
378392
/// </summary>
@@ -759,6 +773,27 @@ ClassInfoGetters;
759773
bool UpdateMovePath() override;
760774

761775

776+
/// <summary>
777+
/// Detects slopes in terrain and updates the walk path rotation for the corresponding Layer accordingly.
778+
/// </summary>
779+
/// <param name="whichLayer">The Layer in question.</param>
780+
void UpdateWalkAngle(AHuman::Layer whichLayer);
781+
782+
/// <summary>
783+
/// Gets the walk path rotation for the specified Layer.
784+
/// </summary>
785+
/// <param name="whichLayer">The Layer in question.</param>
786+
/// <returns>The walk angle in radians.</returns>
787+
float GetWalkAngle(AHuman::Layer whichLayer) const { return m_WalkAngle[whichLayer].GetRadAngle(); }
788+
789+
/// <summary>
790+
/// Sets the walk path rotation for the specified Layer.
791+
/// </summary>
792+
/// <param name="whichLayer">The Layer in question.</param>
793+
/// <param name="angle">The angle to set.</param>
794+
void SetWalkAngle(AHuman::Layer whichLayer, float angle) { m_WalkAngle[whichLayer] = Matrix(angle); }
795+
796+
762797
//////////////////////////////////////////////////////////////////////////////////////////
763798
// Virtual method: UpdateAI
764799
//////////////////////////////////////////////////////////////////////////////////////////
@@ -959,6 +994,7 @@ ClassInfoGetters;
959994
float m_JetTimeTotal;
960995
// How much time left the jetpack can go, in ms
961996
float m_JetTimeLeft;
997+
float m_JetReplenishRate; //!< A multiplier affecting how fast the jetpack fuel will replenish when not in use. 1 means that jet time replenishes at 2x speed in relation to depletion.
962998
// Ratio at which the jetpack angle follows aim angle
963999
float m_JetAngleRange;
9641000
// Blink timer
@@ -995,6 +1031,7 @@ ClassInfoGetters;
9951031
float m_FGArmFlailScalar; //!< The rate at which this AHuman's FG Arm follows the the bodily rotation. Best to keep this at 0 so it doesn't complicate aiming.
9961032
float m_BGArmFlailScalar; //!< The rate at which this AHuman's BG Arm follows the the bodily rotation. Set to a negative value for a "counterweight" effect.
9971033
Timer m_EquipHUDTimer; //!< Timer for showing the name of any newly equipped Device.
1034+
std::array<Matrix, 2> m_WalkAngle; //!< An array of rot angle targets for different movement states.
9981035

9991036
////////////////
10001037
// AI States

Entities/HeldDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,4 +611,4 @@ void HeldDevice::DrawHUD(BITMAP *pTargetBitmap, const Vector &targetPos, int whi
611611
}
612612
}
613613

614-
} // namespace RTE
614+
} // namespace RTE

Entities/LimbPath.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ Vector LimbPath::GetCurrentVel(const Vector &limbPos)
300300
{
301301
Vector returnVel;
302302
Vector distVect = g_SceneMan.ShortestDistance(limbPos, GetCurrentSegTarget());
303-
float adjustedTravelSpeed = m_TravelSpeed[m_WhichSpeed] / (1.0F + m_JointVel.GetMagnitude() * 0.1F);
303+
float adjustedTravelSpeed = m_TravelSpeed[m_WhichSpeed] / (1.0F + std::abs(m_JointVel.GetY()) * 0.1F);
304304

305305
if (IsStaticPoint())
306306
{

Lua/LuaBindingsEntities.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ namespace RTE {
6161
.property("StrideSound", &ACrab::GetStrideSound, &ACrabSetStrideSound)
6262
.property("JetTimeTotal", &ACrab::GetJetTimeTotal, &ACrab::SetJetTimeTotal)
6363
.property("JetTimeLeft", &ACrab::GetJetTimeLeft)
64+
.property("JetReplenishRate", &ACrab::GetJetReplenishRate, &ACrab::SetJetReplenishRate)
6465
.property("EquippedItem", &ACrab::GetEquippedItem)
6566
.property("FirearmIsReady", &ACrab::FirearmIsReady)
6667
.property("FirearmIsEmpty", &ACrab::FirearmIsEmpty)
@@ -410,6 +411,7 @@ namespace RTE {
410411
.property("StrideSound", &AHuman::GetStrideSound, &AHumanSetStrideSound)
411412
.property("JetTimeTotal", &AHuman::GetJetTimeTotal, &AHuman::SetJetTimeTotal)
412413
.property("JetTimeLeft", &AHuman::GetJetTimeLeft, &AHuman::SetJetTimeLeft)
414+
.property("JetReplenishRate", &AHuman::GetJetReplenishRate, &AHuman::SetJetReplenishRate)
413415
.property("JetAngleRange", &AHuman::GetJetAngleRange, &AHuman::SetJetAngleRange)
414416
.property("ThrowPrepTime", &AHuman::GetThrowPrepTime, &AHuman::SetThrowPrepTime)
415417
.property("ThrowProgress", &AHuman::GetThrowProgress)
@@ -443,6 +445,8 @@ namespace RTE {
443445
.def("SetLimbPathSpeed", &AHuman::SetLimbPathSpeed)
444446
.def("GetRotAngleTarget", &AHuman::GetRotAngleTarget)
445447
.def("SetRotAngleTarget", &AHuman::SetRotAngleTarget)
448+
.def("GetWalkAngle", &AHuman::GetWalkAngle)
449+
.def("SetWalkAngle", &AHuman::SetWalkAngle)
446450

447451
.enum_("UpperBodyState")[
448452
luabind::value("WEAPON_READY", AHuman::UpperBodyState::WEAPON_READY),

0 commit comments

Comments
 (0)