Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Generals/Code/GameEngine/Include/GameLogic/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,12 @@ struct HistoricWeaponDamageInfo
// The time and location this weapon was fired
UnsignedInt frame;
Coord3D location;
Bool triggered;

HistoricWeaponDamageInfo(UnsignedInt f, const Coord3D& l) :
frame(f), location(l)
{
triggered = false;
}
};

Expand Down Expand Up @@ -460,6 +462,7 @@ class WeaponTemplate : public MemoryPoolObject
// actually deal out the damage.
void dealDamageInternal(ObjectID sourceID, ObjectID victimID, const Coord3D *pos, const WeaponBonus& bonus, Bool isProjectileDetonation) const;
void trimOldHistoricDamage() const;
void processHistoricDamage(const Object* source, const Coord3D* pos) const;

private:

Expand Down
78 changes: 67 additions & 11 deletions Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
}

//-------------------------------------------------------------------------------------------------
#if RETAIL_COMPATIBLE_CRC
void WeaponTemplate::trimOldHistoricDamage() const
{
UnsignedInt expirationDate = TheGameLogic->getFrame() - TheGlobalData->m_historicDamageLimit;
Expand All @@ -1112,6 +1113,21 @@ void WeaponTemplate::trimOldHistoricDamage() const
}
}
}
#else
void WeaponTemplate::trimOldHistoricDamage() const
{
HistoricWeaponDamageList::iterator it = m_historicDamage.begin();

while (it != m_historicDamage.end())
{
UnsignedInt expirationDate = it->frame + m_historicBonusTime;
if (TheGameLogic->getFrame() > expirationDate || it->triggered)
it = m_historicDamage.erase(it);
else
++it;
}
}
#endif

//-------------------------------------------------------------------------------------------------
static Bool is2DDistSquaredLessThan(const Coord3D& a, const Coord3D& b, Real distSqr)
Expand All @@ -1121,27 +1137,20 @@ static Bool is2DDistSquaredLessThan(const Coord3D& a, const Coord3D& b, Real dis
}

//-------------------------------------------------------------------------------------------------
void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, const Coord3D *pos, const WeaponBonus& bonus, Bool isProjectileDetonation) const
#if RETAIL_COMPATIBLE_CRC
void WeaponTemplate::processHistoricDamage(const Object* source, const Coord3D* pos) const
{
if (sourceID == 0) // must have a source
return;

if (victimID == 0 && pos == NULL) // must have some sort of destination
return;

Object *source = TheGameLogic->findObjectByID(sourceID); // might be null...

//
/** @todo We need to rewrite the historic stuff ... if you fire 5 missiles, and the 5th,
// one creates a firestorm ... and then half a second later another volley of 5 missiles
// come in, the second wave of 5 missiles would all do a historic weapon, making 5 more
// firestorms (CBD) */
//

trimOldHistoricDamage();

if( m_historicBonusCount > 0 && m_historicBonusWeapon != this )
{
trimOldHistoricDamage();

Real radSqr = m_historicBonusRadius * m_historicBonusRadius;
Int count = 0;
UnsignedInt frameNow = TheGameLogic->getFrame();
Expand Down Expand Up @@ -1176,6 +1185,53 @@ void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, co
}

}
}
#else
void WeaponTemplate::processHistoricDamage(const Object* source, const Coord3D* pos) const
{
if (m_historicBonusCount > 0 && m_historicBonusWeapon != this)
{
trimOldHistoricDamage();

Real radSqr = m_historicBonusRadius * m_historicBonusRadius;
Int count = 0;
for (HistoricWeaponDamageList::iterator it = m_historicDamage.begin(); it != m_historicDamage.end(); ++it)
{
if (is2DDistSquaredLessThan(*pos, it->location, radSqr))
{
// This one is close enough in time and distance, so count it. This is tracked by template since it applies
// across units, so don't try to clear historicDamage on success in here.
(*it).triggered = true;
++count;
}
}

if (count >= m_historicBonusCount - 1) // minus 1 since we include ourselves implicitly
TheWeaponStore->createAndFireTempWeapon(m_historicBonusWeapon, source, pos);
else
{
for (HistoricWeaponDamageList::iterator it = m_historicDamage.begin(); it != m_historicDamage.end(); ++it)
(*it).triggered = false;

// add AFTER checking for historic stuff
m_historicDamage.push_back(HistoricWeaponDamageInfo(TheGameLogic->getFrame(), *pos));
}
}
}
#endif

//-------------------------------------------------------------------------------------------------
void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, const Coord3D *pos, const WeaponBonus& bonus, Bool isProjectileDetonation) const
{
if (sourceID == 0) // must have a source
return;

if (victimID == 0 && pos == NULL) // must have some sort of destination
return;

Object *source = TheGameLogic->findObjectByID(sourceID); // might be null...

processHistoricDamage(source, pos);

//DEBUG_LOG(("WeaponTemplate::dealDamageInternal: dealing damage %s at frame %d",m_name.str(),TheGameLogic->getFrame()));

Expand Down
3 changes: 3 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,12 @@ struct HistoricWeaponDamageInfo
// The time and location this weapon was fired
UnsignedInt frame;
Coord3D location;
Bool triggered;

HistoricWeaponDamageInfo(UnsignedInt f, const Coord3D& l) :
frame(f), location(l)
{
triggered = false;
}
};

Expand Down Expand Up @@ -480,6 +482,7 @@ class WeaponTemplate : public MemoryPoolObject
// actually deal out the damage.
void dealDamageInternal(ObjectID sourceID, ObjectID victimID, const Coord3D *pos, const WeaponBonus& bonus, Bool isProjectileDetonation) const;
void trimOldHistoricDamage() const;
void processHistoricDamage(const Object* source, const Coord3D* pos) const;

private:

Expand Down
78 changes: 67 additions & 11 deletions GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
}

//-------------------------------------------------------------------------------------------------
#if RETAIL_COMPATIBLE_CRC
void WeaponTemplate::trimOldHistoricDamage() const
{
UnsignedInt expirationDate = TheGameLogic->getFrame() - TheGlobalData->m_historicDamageLimit;
Expand All @@ -1190,6 +1191,21 @@ void WeaponTemplate::trimOldHistoricDamage() const
}
}
}
#else
void WeaponTemplate::trimOldHistoricDamage() const
{
HistoricWeaponDamageList::iterator it = m_historicDamage.begin();

while (it != m_historicDamage.end())
{
UnsignedInt expirationDate = it->frame + m_historicBonusTime;
if (TheGameLogic->getFrame() > expirationDate || it->triggered)
it = m_historicDamage.erase(it);
else
++it;
}
}
#endif

//-------------------------------------------------------------------------------------------------
static Bool is2DDistSquaredLessThan(const Coord3D& a, const Coord3D& b, Real distSqr)
Expand All @@ -1199,27 +1215,20 @@ static Bool is2DDistSquaredLessThan(const Coord3D& a, const Coord3D& b, Real dis
}

//-------------------------------------------------------------------------------------------------
void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, const Coord3D *pos, const WeaponBonus& bonus, Bool isProjectileDetonation) const
#if RETAIL_COMPATIBLE_CRC
void WeaponTemplate::processHistoricDamage(const Object* source, const Coord3D* pos) const
{
if (sourceID == 0) // must have a source
return;

if (victimID == 0 && pos == NULL) // must have some sort of destination
return;

Object *source = TheGameLogic->findObjectByID(sourceID); // might be null...

//
/** @todo We need to rewrite the historic stuff ... if you fire 5 missiles, and the 5th,
// one creates a firestorm ... and then half a second later another volley of 5 missiles
// come in, the second wave of 5 missiles would all do a historic weapon, making 5 more
// firestorms (CBD) */
//

trimOldHistoricDamage();

if( m_historicBonusCount > 0 && m_historicBonusWeapon != this )
{
trimOldHistoricDamage();

Real radSqr = m_historicBonusRadius * m_historicBonusRadius;
Int count = 0;
UnsignedInt frameNow = TheGameLogic->getFrame();
Expand Down Expand Up @@ -1254,6 +1263,53 @@ void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, co
}

}
}
#else
void WeaponTemplate::processHistoricDamage(const Object* source, const Coord3D* pos) const
{
if (m_historicBonusCount > 0 && m_historicBonusWeapon != this)
{
trimOldHistoricDamage();

Real radSqr = m_historicBonusRadius * m_historicBonusRadius;
Int count = 0;
for (HistoricWeaponDamageList::iterator it = m_historicDamage.begin(); it != m_historicDamage.end(); ++it)
{
if (is2DDistSquaredLessThan(*pos, it->location, radSqr))
{
// This one is close enough in time and distance, so count it. This is tracked by template since it applies
// across units, so don't try to clear historicDamage on success in here.
(*it).triggered = true;
++count;
}
}

if (count >= m_historicBonusCount - 1) // minus 1 since we include ourselves implicitly
TheWeaponStore->createAndFireTempWeapon(m_historicBonusWeapon, source, pos);
else
{
for (HistoricWeaponDamageList::iterator it = m_historicDamage.begin(); it != m_historicDamage.end(); ++it)
(*it).triggered = false;

// add AFTER checking for historic stuff
m_historicDamage.push_back(HistoricWeaponDamageInfo(TheGameLogic->getFrame(), *pos));
}
}
}
#endif

//-------------------------------------------------------------------------------------------------
void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, const Coord3D *pos, const WeaponBonus& bonus, Bool isProjectileDetonation) const
{
if (sourceID == 0) // must have a source
return;

if (victimID == 0 && pos == NULL) // must have some sort of destination
return;

Object *source = TheGameLogic->findObjectByID(sourceID); // might be null...

processHistoricDamage(source, pos);

//DEBUG_LOG(("WeaponTemplate::dealDamageInternal: dealing damage %s at frame %d",m_name.str(),TheGameLogic->getFrame()));

Expand Down
Loading