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

Commit f14ff85

Browse files
committed
Added a few handy Lua functions for AHuman + mild refactor in weapon switching logic
1 parent 79d58e7 commit f14ff85

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

CHANGELOG.md

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

261261
- New `Attachable` Lua (R) property `JointPos`, which gets the position of the object's joint in scene coordinates.
262262

263+
- New `AHuman` Lua (R) Property `IsClimbing`, which indicates whether the actor is currently climbing using either of the arms.
264+
265+
- New `AHuman` Lua functions `UnequipFGArm()` and `UnequipArms()` which unequip the currently held item(s) and put them into the actor's inventory.
266+
263267
</details>
264268

265269
<details><summary><b>Changed</b></summary>

Entities/AHuman.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,7 @@ bool AHuman::UnequipFGArm() {
14161416
if (m_pFGArm && m_pFGArm->HoldsSomething()) {
14171417
m_pFGArm->GetHeldDevice()->Deactivate();
14181418
m_Inventory.push_back(m_pFGArm->ReleaseHeldMO());
1419+
m_pFGArm->SetHandPos(m_Pos + RotateOffset(m_HolsterOffset));
14191420
return true;
14201421
}
14211422
return false;
@@ -1427,6 +1428,7 @@ bool AHuman::UnequipBGArm() {
14271428
if (m_pBGArm && m_pBGArm->HoldsSomething()) {
14281429
m_pBGArm->GetHeldDevice()->Deactivate();
14291430
m_Inventory.push_back(m_pBGArm->ReleaseHeldMO());
1431+
m_pBGArm->SetHandPos(m_Pos + RotateOffset(m_HolsterOffset));
14301432
return true;
14311433
}
14321434
return false;
@@ -3258,20 +3260,20 @@ void AHuman::Update()
32583260
bool changeNext = m_Controller.IsState(WEAPON_CHANGE_NEXT);
32593261
bool changePrev = m_Controller.IsState(WEAPON_CHANGE_PREV);
32603262
HDFirearm * pFireArm = dynamic_cast<HDFirearm *>(m_pFGArm->GetHeldMO());
3261-
if ((changeNext || changePrev) && (!m_Inventory.empty() || UnequipBGArm())) {
3263+
if (changeNext || changePrev) {
32623264
if (changeNext && changePrev) {
3263-
UnequipFGArm();
3264-
} else {
3265+
UnequipArms();
3266+
} else if (!m_Inventory.empty() || UnequipBGArm()) {
32653267
if (pFireArm) { pFireArm->StopActivationSound(); }
32663268
if (changeNext) {
32673269
m_pFGArm->SetHeldMO(SwapNextInventory(m_pFGArm->ReleaseHeldMO()));
32683270
} else {
32693271
m_pFGArm->SetHeldMO(SwapPrevInventory(m_pFGArm->ReleaseHeldMO()));
32703272
}
32713273
EquipShieldInBGArm();
3274+
m_pFGArm->SetHandPos(m_Pos + RotateOffset(m_HolsterOffset));
32723275
}
32733276
m_EquipHUDTimer.Reset();
3274-
m_pFGArm->SetHandPos(m_Pos + m_HolsterOffset.GetXFlipped(m_HFlipped));
32753277
m_PieNeedsUpdate = true;
32763278
m_SharpAimProgress = 0;
32773279
}

Entities/AHuman.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,11 @@ ClassInfoGetters;
591591
/// <returns>Whether there was anything to unequip.</returns>
592592
bool UnequipBGArm();
593593

594+
/// <summary>
595+
/// Unequips whatever is in either of the arms and puts them into the inventory.
596+
/// </summary>
597+
void UnequipArms() { UnequipFGArm(); UnequipBGArm(); }
598+
594599

595600
//////////////////////////////////////////////////////////////////////////////////////////
596601
// Method: GetEquippedItem
@@ -791,6 +796,12 @@ ClassInfoGetters;
791796
/// <param name="angle">The angle to set.</param>
792797
void SetWalkAngle(AHuman::Layer whichLayer, float angle) { m_WalkAngle[whichLayer] = Matrix(angle); }
793798

799+
/// <summary>
800+
/// Gets whether this AHuman is currently attempting to climb something, using arms.
801+
/// </summary>
802+
/// <returns>Whether this AHuman is currently climbing or not.</returns>
803+
bool IsClimbing() const { return m_ArmClimbing[FGROUND] || m_ArmClimbing[BGROUND]; }
804+
794805

795806
//////////////////////////////////////////////////////////////////////////////////////////
796807
// Virtual method: UpdateAI

Lua/LuaBindingsEntities.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ namespace RTE {
424424
.property("FirearmIsSemiAuto", &AHuman::FirearmIsSemiAuto)
425425
.property("FirearmActivationDelay", &AHuman::FirearmActivationDelay)
426426
.property("LimbPathPushForce", &AHuman::GetLimbPathPushForce, &AHuman::SetLimbPathPushForce)
427+
.property("IsClimbing", &AHuman::IsClimbing)
427428
.property("ArmSwingRate", &AHuman::GetArmSwingRate, &AHuman::SetArmSwingRate)
428429

429430
.def("EquipFirearm", &AHuman::EquipFirearm)
@@ -434,7 +435,9 @@ namespace RTE {
434435
.def("EquipDeviceInGroup", &AHuman::EquipDeviceInGroup)
435436
.def("EquipNamedDevice", &AHuman::EquipNamedDevice)
436437
.def("EquipLoadedFirearmInGroup", &AHuman::EquipLoadedFirearmInGroup)
438+
.def("UnequipFGArm", &AHuman::UnequipFGArm)
437439
.def("UnequipBGArm", &AHuman::UnequipBGArm)
440+
.def("UnequipArms", &AHuman::UnequipArms)
438441
.def("ReloadFirearms", &AHuman::ReloadFirearms)
439442
.def("IsWithinRange", &AHuman::IsWithinRange)
440443
.def("Look", &AHuman::Look)

0 commit comments

Comments
 (0)