@@ -1106,61 +1106,37 @@ bool AHuman::EquipThrowable(bool doEquip)
1106
1106
return false ;
1107
1107
}
1108
1108
1109
-
1110
- // ////////////////////////////////////////////////////////////////////////////////////////
1111
- // Virtual Method: EquipDiggingTool
1112
1109
// ////////////////////////////////////////////////////////////////////////////////////////
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.
1116
1110
1117
- bool AHuman::EquipDiggingTool (bool doEquip)
1118
- {
1111
+ bool AHuman::EquipDiggingTool (bool doEquip) {
1119
1112
if (!(m_pFGArm && m_pFGArm->IsAttached ())) {
1120
1113
return false ;
1121
1114
}
1122
1115
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 ;
1125
1123
}
1126
1124
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 ;
1157
1131
}
1132
+ }
1133
+ }
1158
1134
1159
- return true ;
1160
- }
1161
- }
1135
+ if (doEquip && strongestDigger && !strongestDiggerIsHeld) {
1136
+ EquipNamedDevice (strongestDigger-> GetModuleName (), strongestDigger-> GetPresetName (), true );
1137
+ }
1162
1138
1163
- return false ;
1139
+ return strongestDigger != nullptr ;
1164
1140
}
1165
1141
1166
1142
// ////////////////////////////////////////////////////////////////////////////////////////
0 commit comments