Skip to content

Commit 74ea024

Browse files
committed
bugfix: Triggered historic damage no longer resets all instances for the same weapon template
1 parent bc50362 commit 74ea024

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,12 @@ struct HistoricWeaponDamageInfo
320320
// The time and location this weapon was fired
321321
UnsignedInt frame;
322322
Coord3D location;
323+
Bool triggered;
323324

324325
HistoricWeaponDamageInfo(UnsignedInt f, const Coord3D& l) :
325326
frame(f), location(l)
326327
{
328+
triggered = false;
327329
}
328330
};
329331

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
10931093
}
10941094

10951095
//-------------------------------------------------------------------------------------------------
1096+
#if RETAIL_COMPATIBLE_CRC
10961097
void WeaponTemplate::trimOldHistoricDamage() const
10971098
{
10981099
UnsignedInt expirationDate = TheGameLogic->getFrame() - TheGlobalData->m_historicDamageLimit;
@@ -1112,6 +1113,21 @@ void WeaponTemplate::trimOldHistoricDamage() const
11121113
}
11131114
}
11141115
}
1116+
#else
1117+
void WeaponTemplate::trimOldHistoricDamage() const
1118+
{
1119+
HistoricWeaponDamageList::iterator it = m_historicDamage.begin();
1120+
1121+
while (it != m_historicDamage.end())
1122+
{
1123+
UnsignedInt expirationDate = it->frame + m_historicBonusTime;
1124+
if (TheGameLogic->getFrame() > expirationDate || it->triggered)
1125+
it = m_historicDamage.erase(it);
1126+
else
1127+
++it;
1128+
}
1129+
}
1130+
#endif
11151131

11161132
//-------------------------------------------------------------------------------------------------
11171133
static Bool is2DDistSquaredLessThan(const Coord3D& a, const Coord3D& b, Real distSqr)
@@ -1121,6 +1137,7 @@ static Bool is2DDistSquaredLessThan(const Coord3D& a, const Coord3D& b, Real dis
11211137
}
11221138

11231139
//-------------------------------------------------------------------------------------------------
1140+
#if RETAIL_COMPATIBLE_CRC
11241141
void WeaponTemplate::processHistoricDamage(const Object* source, const Coord3D* pos) const
11251142
{
11261143
//
@@ -1169,6 +1186,39 @@ void WeaponTemplate::processHistoricDamage(const Object* source, const Coord3D*
11691186

11701187
}
11711188
}
1189+
#else
1190+
void WeaponTemplate::processHistoricDamage(const Object* source, const Coord3D* pos) const
1191+
{
1192+
if (m_historicBonusCount > 0 && m_historicBonusWeapon != this)
1193+
{
1194+
trimOldHistoricDamage();
1195+
1196+
Real radSqr = m_historicBonusRadius * m_historicBonusRadius;
1197+
Int count = 0;
1198+
for (HistoricWeaponDamageList::iterator it = m_historicDamage.begin(); it != m_historicDamage.end(); ++it)
1199+
{
1200+
if (is2DDistSquaredLessThan(*pos, it->location, radSqr))
1201+
{
1202+
// This one is close enough in time and distance, so count it. This is tracked by template since it applies
1203+
// across units, so don't try to clear historicDamage on success in here.
1204+
(*it).triggered = true;
1205+
++count;
1206+
}
1207+
}
1208+
1209+
if (count >= m_historicBonusCount - 1) // minus 1 since we include ourselves implicitly
1210+
TheWeaponStore->createAndFireTempWeapon(m_historicBonusWeapon, source, pos);
1211+
else
1212+
{
1213+
for (HistoricWeaponDamageList::iterator it = m_historicDamage.begin(); it != m_historicDamage.end(); ++it)
1214+
(*it).triggered = false;
1215+
1216+
// add AFTER checking for historic stuff
1217+
m_historicDamage.push_back(HistoricWeaponDamageInfo(TheGameLogic->getFrame(), *pos));
1218+
}
1219+
}
1220+
}
1221+
#endif
11721222

11731223
//-------------------------------------------------------------------------------------------------
11741224
void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, const Coord3D *pos, const WeaponBonus& bonus, Bool isProjectileDetonation) const

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,12 @@ struct HistoricWeaponDamageInfo
331331
// The time and location this weapon was fired
332332
UnsignedInt frame;
333333
Coord3D location;
334+
Bool triggered;
334335

335336
HistoricWeaponDamageInfo(UnsignedInt f, const Coord3D& l) :
336337
frame(f), location(l)
337338
{
339+
triggered = false;
338340
}
339341
};
340342

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
11711171
}
11721172

11731173
//-------------------------------------------------------------------------------------------------
1174+
#if RETAIL_COMPATIBLE_CRC
11741175
void WeaponTemplate::trimOldHistoricDamage() const
11751176
{
11761177
UnsignedInt expirationDate = TheGameLogic->getFrame() - TheGlobalData->m_historicDamageLimit;
@@ -1190,6 +1191,21 @@ void WeaponTemplate::trimOldHistoricDamage() const
11901191
}
11911192
}
11921193
}
1194+
#else
1195+
void WeaponTemplate::trimOldHistoricDamage() const
1196+
{
1197+
HistoricWeaponDamageList::iterator it = m_historicDamage.begin();
1198+
1199+
while (it != m_historicDamage.end())
1200+
{
1201+
UnsignedInt expirationDate = it->frame + m_historicBonusTime;
1202+
if (TheGameLogic->getFrame() > expirationDate || it->triggered)
1203+
it = m_historicDamage.erase(it);
1204+
else
1205+
++it;
1206+
}
1207+
}
1208+
#endif
11931209

11941210
//-------------------------------------------------------------------------------------------------
11951211
static Bool is2DDistSquaredLessThan(const Coord3D& a, const Coord3D& b, Real distSqr)
@@ -1199,6 +1215,7 @@ static Bool is2DDistSquaredLessThan(const Coord3D& a, const Coord3D& b, Real dis
11991215
}
12001216

12011217
//-------------------------------------------------------------------------------------------------
1218+
#if RETAIL_COMPATIBLE_CRC
12021219
void WeaponTemplate::processHistoricDamage(const Object* source, const Coord3D* pos) const
12031220
{
12041221
//
@@ -1247,6 +1264,39 @@ void WeaponTemplate::processHistoricDamage(const Object* source, const Coord3D*
12471264

12481265
}
12491266
}
1267+
#else
1268+
void WeaponTemplate::processHistoricDamage(const Object* source, const Coord3D* pos) const
1269+
{
1270+
if (m_historicBonusCount > 0 && m_historicBonusWeapon != this)
1271+
{
1272+
trimOldHistoricDamage();
1273+
1274+
Real radSqr = m_historicBonusRadius * m_historicBonusRadius;
1275+
Int count = 0;
1276+
for (HistoricWeaponDamageList::iterator it = m_historicDamage.begin(); it != m_historicDamage.end(); ++it)
1277+
{
1278+
if (is2DDistSquaredLessThan(*pos, it->location, radSqr))
1279+
{
1280+
// This one is close enough in time and distance, so count it. This is tracked by template since it applies
1281+
// across units, so don't try to clear historicDamage on success in here.
1282+
(*it).triggered = true;
1283+
++count;
1284+
}
1285+
}
1286+
1287+
if (count >= m_historicBonusCount - 1) // minus 1 since we include ourselves implicitly
1288+
TheWeaponStore->createAndFireTempWeapon(m_historicBonusWeapon, source, pos);
1289+
else
1290+
{
1291+
for (HistoricWeaponDamageList::iterator it = m_historicDamage.begin(); it != m_historicDamage.end(); ++it)
1292+
(*it).triggered = false;
1293+
1294+
// add AFTER checking for historic stuff
1295+
m_historicDamage.push_back(HistoricWeaponDamageInfo(TheGameLogic->getFrame(), *pos));
1296+
}
1297+
}
1298+
}
1299+
#endif
12501300

12511301
//-------------------------------------------------------------------------------------------------
12521302
void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, const Coord3D *pos, const WeaponBonus& bonus, Bool isProjectileDetonation) const

0 commit comments

Comments
 (0)