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

Commit 39d769d

Browse files
committed
Made AHuman::EquipDiggingTool always equip the strongest digging tool they have, since that's what's used for pathfinding calculations
This will mean actors with a shovel and a heavy digger will use the heavy digger instead of flailing ineffectually with the shovel
1 parent 4f6a3a8 commit 39d769d

File tree

2 files changed

+25
-55
lines changed

2 files changed

+25
-55
lines changed

Entities/AHuman.cpp

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,61 +1106,37 @@ bool AHuman::EquipThrowable(bool doEquip)
11061106
return false;
11071107
}
11081108

1109-
1110-
//////////////////////////////////////////////////////////////////////////////////////////
1111-
// Virtual Method: EquipDiggingTool
11121109
//////////////////////////////////////////////////////////////////////////////////////////
1113-
// Description: Switches the currently held device (if any) to the first found digging
1114-
// tool in the inventory. If the held device already is a digging tool,
1115-
// or no digging tool is in inventory, nothing happens.
11161110

1117-
bool AHuman::EquipDiggingTool(bool doEquip)
1118-
{
1111+
bool AHuman::EquipDiggingTool(bool doEquip) {
11191112
if (!(m_pFGArm && m_pFGArm->IsAttached())) {
11201113
return false;
11211114
}
11221115

1123-
if (HDFirearm *heldDeviceAsFirearm = dynamic_cast<HDFirearm *>(m_pFGArm->GetHeldDevice()); heldDeviceAsFirearm && heldDeviceAsFirearm->IsInGroup("Tools - Diggers")) {
1124-
return true;
1116+
const HDFirearm *strongestDigger = nullptr;
1117+
float strongestDiggerDigStrength = 0;
1118+
bool strongestDiggerIsHeld = false;
1119+
if (const HDFirearm *heldDeviceAsFirearm = dynamic_cast<HDFirearm *>(m_pFGArm->GetHeldDevice()); heldDeviceAsFirearm && heldDeviceAsFirearm->IsInGroup("Tools - Diggers")) {
1120+
strongestDigger = heldDeviceAsFirearm;
1121+
strongestDiggerDigStrength = heldDeviceAsFirearm->EstimateDigStrength();
1122+
strongestDiggerIsHeld = true;
11251123
}
11261124

1127-
// Go through the inventory looking for the proper device
1128-
for (std::deque<MovableObject *>::iterator itr = m_Inventory.begin(); itr != m_Inventory.end(); ++itr)
1129-
{
1130-
HDFirearm *pTool = dynamic_cast<HDFirearm *>(*itr);
1131-
// Found proper device to equip, so make the switch!
1132-
if (pTool && pTool->IsInGroup("Tools - Diggers"))
1133-
{
1134-
if (doEquip)
1135-
{
1136-
// Erase the inventory entry containing the device we now have switched to
1137-
*itr = 0;
1138-
m_Inventory.erase(itr);
1139-
1140-
// Put back into the inventory what we had in our hands, if anything
1141-
if (HeldDevice *heldDevice = m_pFGArm->GetHeldDevice())
1142-
{
1143-
heldDevice->Deactivate();
1144-
AddToInventoryBack(m_pFGArm->RemoveAttachable(heldDevice));
1145-
}
1146-
1147-
// Now put the device we were looking for and found into the hand
1148-
m_pFGArm->SetHeldDevice(pTool);
1149-
// Move the hand to a poisition so it looks like the new device was drawn from inventory
1150-
m_pFGArm->SetHandPos(m_Pos + m_HolsterOffset.GetXFlipped(m_HFlipped));
1151-
1152-
// Equip shield in BG arm is applicable
1153-
EquipShieldInBGArm();
1154-
1155-
// Play the device switching sound
1156-
if (m_DeviceSwitchSound) { m_DeviceSwitchSound->Play(m_Pos); }
1125+
if (doEquip || !strongestDigger) {
1126+
for (MovableObject *inventoryItem : m_Inventory) {
1127+
if (const HDFirearm *inventoryItemAsFirearm = dynamic_cast<HDFirearm *>(inventoryItem); inventoryItemAsFirearm && inventoryItemAsFirearm->IsInGroup("Tools - Diggers") && inventoryItemAsFirearm->EstimateDigStrength() > strongestDiggerDigStrength) {
1128+
strongestDigger = inventoryItemAsFirearm;
1129+
strongestDiggerDigStrength = inventoryItemAsFirearm->EstimateDigStrength();
1130+
strongestDiggerIsHeld = false;
11571131
}
1132+
}
1133+
}
11581134

1159-
return true;
1160-
}
1161-
}
1135+
if (doEquip && strongestDigger && !strongestDiggerIsHeld) {
1136+
EquipNamedDevice(strongestDigger->GetModuleName(), strongestDigger->GetPresetName(), true);
1137+
}
11621138

1163-
return false;
1139+
return strongestDigger != nullptr;
11641140
}
11651141

11661142
//////////////////////////////////////////////////////////////////////////////////////////

Entities/AHuman.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -534,17 +534,11 @@ DefaultPieMenuNameGetter("Default Human Pie Menu");
534534

535535
bool EquipThrowable(bool doEquip = true);
536536

537-
538-
//////////////////////////////////////////////////////////////////////////////////////////
539-
// Virtual Method: EquipDiggingTool
540-
//////////////////////////////////////////////////////////////////////////////////////////
541-
// Description: Switches the currently held device (if any) to the first found digging
542-
// tool in the inventory. If the held device already is a digging tool,
543-
// or no digging tool is in inventory, nothing happens.
544-
// Arguments: Whether to actually equip any matching item found in the inventory,
545-
// or just report that it's there or not.
546-
// Return value: Whether a digging tool was successfully switched to.
547-
537+
/// <summary>
538+
/// Switches the currently held device (if any) to the strongest digging tool in the inventory.
539+
/// </summary>
540+
/// <param name="doEquip">Whether to actually equip the strongest digging tool, or just report whether a digging tool was found.</param>
541+
/// <returns>Whether or not the strongest digging tool was successfully equipped.</returns>
548542
bool EquipDiggingTool(bool doEquip = true);
549543

550544
/// <summary>

0 commit comments

Comments
 (0)