Skip to content

Commit 8f37c76

Browse files
committed
Fix WeaponBonusSet for WeaponExtend
1 parent 6ec5806 commit 8f37c76

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ class WeaponBonusSet : public MemoryPoolObject
304304
public:
305305
void appendBonuses(WeaponBonusConditionFlags flags, WeaponBonus& bonus) const;
306306

307+
//Copy bonues from other WeaponBonusSet, needed for WeaponExtend for deep copy
308+
void copyFrom(const WeaponBonusSet& other);
309+
307310
void parseWeaponBonusSet(INI* ini);
308311
static void parseWeaponBonusSet(INI* ini, void *instance, void* /*store*/, const void* /*userData*/);
309312
static void parseWeaponBonusSetPtr(INI* ini, void *instance, void* /*store*/, const void* /*userData*/);

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,17 @@ void WeaponTemplate::copy_from(const WeaponTemplate& other) {
375375

376376
// take all values from other
377377
*this = other;
378+
m_extraBonus = nullptr;
379+
380+
//WeaponBonusSet must be deep copied
381+
if (other.m_extraBonus != nullptr) {
382+
m_extraBonus = newInstance(WeaponBonusSet);
383+
m_extraBonus->copyFrom(*other.m_extraBonus);
384+
}
385+
386+
//just to make sure
387+
this->m_historicDamage.clear();
388+
this->m_historicDamageTriggerId = 0;
378389

379390
this->m_nextTemplate = nextTempl;
380391
this->m_name = name;
@@ -4173,3 +4184,20 @@ void WeaponBonusSet::appendBonuses(WeaponBonusConditionFlags flags, WeaponBonus&
41734184
}
41744185
}
41754186

4187+
//-------------------------------------------------------------------------------------------------
4188+
void WeaponBonusSet::copyFrom(const WeaponBonusSet& other)
4189+
{
4190+
// Prevent self-assignment
4191+
if (this == &other)
4192+
{
4193+
return;
4194+
}
4195+
4196+
// Iterate through and copy each WeaponBonus struct individually.
4197+
// The compiler's default assignment operator for WeaponBonus will safely
4198+
// copy the inner Real m_field[FIELD_COUNT] array.
4199+
for (int i = 0; i < WEAPONBONUSCONDITION_COUNT; ++i)
4200+
{
4201+
this->m_bonus[i] = other.m_bonus[i];
4202+
}
4203+
}

0 commit comments

Comments
 (0)