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

Commit 4f6a3a8

Browse files
committed
Made EstimateDigStrength const all the way down, and made it work better for hdfirearms with no current magazine
1 parent a7c0a01 commit 4f6a3a8

File tree

8 files changed

+19
-38
lines changed

8 files changed

+19
-38
lines changed

Entities/AHuman.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,38 +1163,30 @@ bool AHuman::EquipDiggingTool(bool doEquip)
11631163
return false;
11641164
}
11651165

1166-
1167-
//////////////////////////////////////////////////////////////////////////////////////////
1168-
// Method: EstimateDigStrength
11691166
//////////////////////////////////////////////////////////////////////////////////////////
1170-
// Description: Estimates what material strength this actor can move through.
11711167

1172-
float AHuman::EstimateDigStrength()
1173-
{
1168+
float AHuman::EstimateDigStrength() const {
11741169
float maxPenetration = Actor::EstimateDigStrength();
11751170

11761171
if (!(m_pFGArm && m_pFGArm->IsAttached())) {
11771172
return maxPenetration;
11781173
}
11791174

1180-
if (HDFirearm *heldDeviceAsHDFirearm = dynamic_cast<HDFirearm *>(m_pFGArm->GetHeldDevice()); heldDeviceAsHDFirearm && heldDeviceAsHDFirearm->IsInGroup("Tools - Diggers")) {
1175+
if (const HDFirearm *heldDeviceAsHDFirearm = dynamic_cast<HDFirearm *>(m_pFGArm->GetHeldDevice()); heldDeviceAsHDFirearm && heldDeviceAsHDFirearm->IsInGroup("Tools - Diggers")) {
11811176
maxPenetration = std::max(heldDeviceAsHDFirearm->EstimateDigStrength(), maxPenetration);
11821177
}
11831178

1184-
// Go through the inventory looking for the proper device
1185-
for (std::deque<MovableObject *>::iterator itr = m_Inventory.begin(); itr != m_Inventory.end(); ++itr)
1186-
{
1187-
HDFirearm *pTool = dynamic_cast<HDFirearm *>(*itr);
1188-
// Found proper device to equip, so make the switch!
1189-
if (pTool && pTool->IsInGroup("Tools - Diggers"))
1190-
{
1191-
maxPenetration = std::max(pTool->EstimateDigStrength(), maxPenetration);
1179+
for (const MovableObject *inventoryItem : m_Inventory) {
1180+
if (const HDFirearm *inventoryItemAsFirearm = dynamic_cast<const HDFirearm *>(inventoryItem); inventoryItemAsFirearm && inventoryItemAsFirearm->IsInGroup("Tools - Diggers")) {
1181+
maxPenetration = std::max(inventoryItemAsFirearm->EstimateDigStrength(), maxPenetration);
11921182
}
11931183
}
11941184

11951185
return maxPenetration;
11961186
}
11971187

1188+
//////////////////////////////////////////////////////////////////////////////////////////
1189+
11981190

11991191
//////////////////////////////////////////////////////////////////////////////////////////
12001192
// Virtual Method: EquipShield

Entities/AHuman.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -547,16 +547,11 @@ DefaultPieMenuNameGetter("Default Human Pie Menu");
547547

548548
bool EquipDiggingTool(bool doEquip = true);
549549

550-
551-
//////////////////////////////////////////////////////////////////////////////////////////
552-
// Method: EstimateDigStrength
553-
//////////////////////////////////////////////////////////////////////////////////////////
554-
// Description: Estimates what material strength any digger this actor is carrying
555-
// can penetrate.
556-
// Arguments: None.
557-
// Return value: A default dig strength (what the actor can be expected to just walk through without tools), or the maximum material strength this actor's digger can penetrate.
558-
559-
float EstimateDigStrength() override;
550+
/// <summary>
551+
/// Estimates what material strength any digger this AHuman is carrying can penetrate.
552+
/// </summary>
553+
/// <returns>The maximum material strength this AHuman's digger can penetrate, or a default dig strength if they don't have a digger.</returns>
554+
float EstimateDigStrength() const override;
560555

561556

562557
//////////////////////////////////////////////////////////////////////////////////////////

Entities/Actor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ bool Actor::UpdateMovePath()
12911291

12921292
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12931293

1294-
float Actor::EstimateDigStrength() {
1294+
float Actor::EstimateDigStrength() const {
12951295
return m_AIBaseDigStrength;
12961296
}
12971297

Entities/Actor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ ClassInfoGetters;
11271127
/// Estimates what material strength this actor can penetrate.
11281128
/// </summary>
11291129
/// <returns>The actor's dig strength.</returns>
1130-
virtual float EstimateDigStrength();
1130+
virtual float EstimateDigStrength() const;
11311131

11321132
/// <summary>
11331133
/// Gets this Actor's base dig strength, or the strength of terrain they can expect to walk through without tools.

Entities/HDFirearm.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,13 +1115,8 @@ void HDFirearm::Update()
11151115
//////////////////////////////////////////////////////////////////////////////////////////
11161116
// Description: Estimates what material strength the rounds in the magazine can destroy.
11171117

1118-
float HDFirearm::EstimateDigStrength()
1119-
{
1120-
if (m_pMagazine) {
1121-
return m_pMagazine->EstimateDigStrength();
1122-
}
1123-
1124-
return 1;
1118+
float HDFirearm::EstimateDigStrength() const {
1119+
return m_pMagazine ? m_pMagazine->EstimateDigStrength() : m_pMagazineReference->EstimateDigStrength();
11251120
}
11261121

11271122

Entities/HDFirearm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ AddScriptFunctionNames(HeldDevice, "OnFire", "OnReload");
796796
// Arguments: None.
797797
// Return value: The maximum material strength the regular or the tracer round can destroy.
798798

799-
float EstimateDigStrength();
799+
float EstimateDigStrength() const;
800800

801801

802802
//////////////////////////////////////////////////////////////////////////////////////////

Entities/Magazine.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ Round * Magazine::PopNextRound()
225225
//////////////////////////////////////////////////////////////////////////////////////////
226226
// Description: Estimates what material strength the rounds in the magazine can destroy.
227227

228-
float Magazine::EstimateDigStrength()
229-
{
228+
float Magazine::EstimateDigStrength() const {
230229
float maxPenetration = 1;
231230
if (m_pTracerRound)
232231
{

Entities/Magazine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ ClassInfoGetters;
206206
// Arguments: None.
207207
// Return value: The material strength.
208208

209-
float EstimateDigStrength();
209+
float EstimateDigStrength() const;
210210

211211

212212
//////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)