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); diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index dacb8dfc8a..7ff3970213 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) { @@ -19934,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) ); } } } 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;