From b621402d87c84f2d40cdfb3bc8915453e34ab88e Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Fri, 29 Mar 2024 16:21:39 -0300 Subject: [PATCH 1/3] add const accessor to Inventory --- Tactical/Soldier Control.cpp | 4 ++++ Tactical/Soldier Control.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index dacb8dfc8a..46a09d69d2 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -378,6 +378,10 @@ unsigned int Inventory::size( ) const { return inv.size( ); } +auto Inventory::get() const -> const std::vector& { + return inv; +} + // Assignment operator Inventory& Inventory::operator=(const Inventory& src) { diff --git a/Tactical/Soldier Control.h b/Tactical/Soldier Control.h index 74c08462e1..7545ce6b53 100644 --- a/Tactical/Soldier Control.h +++ b/Tactical/Soldier Control.h @@ -772,6 +772,9 @@ class Inventory { // How any slots are there in this inventory? unsigned int size() const; + // const-only accessor + auto get() const -> const std::vector&; + //temporarily? public std::vector bNewItemCount; std::vector bNewItemCycleCount; From 25566722ef6fd5302efd3315f73a349341bd651c Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Fri, 29 Mar 2024 16:23:59 -0300 Subject: [PATCH 2/3] make OBJECTTYPE::Exists() const --- Tactical/Item Types.cpp | 2 +- Tactical/Item Types.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tactical/Item Types.cpp b/Tactical/Item Types.cpp index de7478ad36..e8a7c84833 100644 --- a/Tactical/Item Types.cpp +++ b/Tactical/Item Types.cpp @@ -592,7 +592,7 @@ LBENODE* OBJECTTYPE::GetLBEPointer(unsigned int index) } -bool OBJECTTYPE::exists() +bool OBJECTTYPE::exists() const { return(this && ubNumberOfObjects && usItem); } diff --git a/Tactical/Item Types.h b/Tactical/Item Types.h index cdd3d2a19d..4fbfb6504c 100644 --- a/Tactical/Item Types.h +++ b/Tactical/Item Types.h @@ -546,7 +546,7 @@ class OBJECTTYPE bool operator==(OBJECTTYPE& compare); bool operator==(const OBJECTTYPE& compare)const; - bool exists(); + bool exists() const; bool IsActiveLBE(unsigned int index); bool HasAnyActiveLBEs(SOLDIERTYPE * pSoldier = NULL, UINT8 iter = 0); LBENODE* GetLBEPointer(unsigned int index); From d90b4723554c2a1c0288be612cd6da1eba07250d Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Fri, 29 Mar 2024 16:42:25 -0300 Subject: [PATCH 3/3] simplify SOLDIERTYPE::GetDiseaseContactProtection( ) --- Tactical/Soldier Control.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index 46a09d69d2..7ff3970213 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -19938,22 +19938,19 @@ FLOAT SOLDIERTYPE::GetDiseaseContactProtection( ) // if we wear special equipment, lower our chances of being infected FLOAT bestfacegear = 0.0f; FLOAT bestprotectivegear = 0.0f; - INT8 invsize = (INT8)inv.size( ); // remember inventorysize, so we don't call size() repeatedly - for ( INT8 bLoop = 0; bLoop < invsize; ++bLoop ) + for ( const auto &item : inv.get() ) { - if ( inv[bLoop].exists( ) ) + if ( item.exists( ) ) { - OBJECTTYPE* pObj = &(inv[bLoop]); - - if ( pObj && (*pObj)[0]->data.objectStatus >= USABLE ) + if ( item[0]->data.objectStatus >= USABLE ) { - if ( HasItemFlag( pObj->usItem, DISEASEPROTECTION_1 ) ) + if ( HasItemFlag( item.usItem, DISEASEPROTECTION_1 ) ) { - bestfacegear = max( bestfacegear, (FLOAT)((*pObj)[0]->data.objectStatus / 100) ); + bestfacegear = max( bestfacegear, (FLOAT)(item[0]->data.objectStatus / 100) ); } - if ( HasItemFlag( pObj->usItem, DISEASEPROTECTION_2 ) ) + if ( HasItemFlag( item.usItem, DISEASEPROTECTION_2 ) ) { - bestprotectivegear = max( bestprotectivegear, (FLOAT)((*pObj)[0]->data.objectStatus / 100) ); + bestprotectivegear = max( bestprotectivegear, (FLOAT)(item[0]->data.objectStatus / 100) ); } } }