Skip to content

Commit ffd2159

Browse files
committed
[ZH] Fix ThingTemplate copies to prevent mismatch with mod map and quickstart
1 parent d8af372 commit ffd2159

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@
4242
#undef SPARSEMATCH_DEBUG
4343
#endif
4444

45+
typedef UnsignedInt SparseMatchFinderFlags;
46+
enum SparseMatchFinderFlags_ CPP_11(: SparseMatchFinderFlags)
47+
{
48+
SparseMatchFinderFlags_NoCopy = 1<<0,
49+
};
50+
4551
//-------------------------------------------------------------------------------------------------
46-
template<class MATCHABLE, class BITSET>
52+
template<class MATCHABLE, class BITSET, SparseMatchFinderFlags FLAGS = 0>
4753
class SparseMatchFinder
4854
{
4955
private:
@@ -185,9 +191,26 @@ class SparseMatchFinder
185191
return result;
186192
}
187193

188-
//-------------------------------------------------------------------------------------------------
189194
public:
190195

196+
197+
//-------------------------------------------------------------------------------------------------
198+
SparseMatchFinder() {}
199+
SparseMatchFinder(const SparseMatchFinder& other)
200+
{
201+
*this = other;
202+
}
203+
204+
//-------------------------------------------------------------------------------------------------
205+
SparseMatchFinder& operator=(const SparseMatchFinder& other)
206+
{
207+
if ((FLAGS & SparseMatchFinderFlags_NoCopy) == 0 && this != &other)
208+
{
209+
m_bestMatches = other.m_bestMatches;
210+
}
211+
return *this;
212+
}
213+
191214
//-------------------------------------------------------------------------------------------------
192215
void clear()
193216
{

GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,11 @@ class ThingTemplate : public Overridable
698698
//Code renderer handles these states now.
699699
//AsciiString m_inventoryImage[ INV_IMAGE_NUM_IMAGES ]; ///< portrait inventory pictures
700700

701+
// TheSuperHackers @bugfix Caball009/xezon 06/07/2025 No longer copy SparseMatchFinder to prevent copied instances linking to unrelated data.
702+
// This avoids mismatching in certain maps, for example those that spawn units with veterancy.
703+
typedef SparseMatchFinder<WeaponTemplateSet, WeaponSetFlags, SparseMatchFinderFlags_NoCopy> WeaponTemplateSetFinder;
704+
typedef SparseMatchFinder<ArmorTemplateSet, ArmorSetFlags, SparseMatchFinderFlags_NoCopy> ArmorTemplateSetFinder;
705+
701706
// ---- STL-sized things
702707
std::vector<ProductionPrerequisite> m_prereqInfo; ///< the unit Prereqs for this tech
703708
std::vector<AsciiString> m_buildVariations; /**< if we build a unit of this type via script or ui, randomly choose one

GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,4 @@ class ArmorTemplateSet
9797
//-------------------------------------------------------------------------------------------------
9898
typedef std::vector<ArmorTemplateSet> ArmorTemplateSetVector;
9999

100-
//-------------------------------------------------------------------------------------------------
101-
typedef SparseMatchFinder<ArmorTemplateSet, ArmorSetFlags> ArmorTemplateSetFinder;
102-
103100
#endif // _ArmorSet_H_

GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ class WeaponTemplateSet
166166
//-------------------------------------------------------------------------------------------------
167167
typedef std::vector<WeaponTemplateSet> WeaponTemplateSetVector;
168168

169-
//-------------------------------------------------------------------------------------------------
170-
typedef SparseMatchFinder<WeaponTemplateSet, WeaponSetFlags> WeaponTemplateSetFinder;
171-
172169
//-------------------------------------------------------------------------------------------------
173170
enum WeaponChoiceCriteria CPP_11(: Int)
174171
{

0 commit comments

Comments
 (0)