diff --git a/GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h b/GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h index 3f1f696617..d75be6064b 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h @@ -42,8 +42,14 @@ #undef SPARSEMATCH_DEBUG #endif +typedef UnsignedInt SparseMatchFinderFlags; +enum SparseMatchFinderFlags_ CPP_11(: SparseMatchFinderFlags) +{ + SparseMatchFinderFlags_NoCopy = 1<<0, +}; + //------------------------------------------------------------------------------------------------- -template +template class SparseMatchFinder { private: @@ -185,9 +191,29 @@ class SparseMatchFinder return result; } - //------------------------------------------------------------------------------------------------- public: + + //------------------------------------------------------------------------------------------------- + SparseMatchFinder() {} + SparseMatchFinder(const SparseMatchFinder& other) + { + *this = other; + } + + //------------------------------------------------------------------------------------------------- + SparseMatchFinder& operator=(const SparseMatchFinder& other) + { + if CONSTEXPR ((FLAGS & SparseMatchFinderFlags_NoCopy) == 0) + { + if (this != &other) + { + m_bestMatches = other.m_bestMatches; + } + } + return *this; + } + //------------------------------------------------------------------------------------------------- void clear() { diff --git a/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h index 2764437135..6d8610b98c 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h @@ -698,6 +698,11 @@ class ThingTemplate : public Overridable //Code renderer handles these states now. //AsciiString m_inventoryImage[ INV_IMAGE_NUM_IMAGES ]; ///< portrait inventory pictures + // TheSuperHackers @bugfix Caball009/xezon 06/07/2025 No longer copy SparseMatchFinder to prevent copied instances linking to unrelated data. + // This avoids mismatching in certain maps, for example those that spawn units with veterancy. + typedef SparseMatchFinder WeaponTemplateSetFinder; + typedef SparseMatchFinder ArmorTemplateSetFinder; + // ---- STL-sized things std::vector m_prereqInfo; ///< the unit Prereqs for this tech std::vector m_buildVariations; /**< if we build a unit of this type via script or ui, randomly choose one diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.h index c84618fb05..2302b98071 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.h @@ -97,7 +97,4 @@ class ArmorTemplateSet //------------------------------------------------------------------------------------------------- typedef std::vector ArmorTemplateSetVector; -//------------------------------------------------------------------------------------------------- -typedef SparseMatchFinder ArmorTemplateSetFinder; - #endif // _ArmorSet_H_ diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h index d1313382ce..88fc69a34c 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h @@ -166,9 +166,6 @@ class WeaponTemplateSet //------------------------------------------------------------------------------------------------- typedef std::vector WeaponTemplateSetVector; -//------------------------------------------------------------------------------------------------- -typedef SparseMatchFinder WeaponTemplateSetFinder; - //------------------------------------------------------------------------------------------------- enum WeaponChoiceCriteria CPP_11(: Int) {