Skip to content

Commit f537c54

Browse files
authored
Merge pull request #54 from Andreas-W/ScatterTargetRecenter
Scatter target recenter
2 parents e0a9636 + a25f091 commit f537c54

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ class WeaponTemplate : public MemoryPoolObject
462462
inline Real getLaserGroundUnitTargetHeight() const { return m_laserGroundUnitTargetHeight; }
463463
inline Real getLaserGroundTargetHeight() const { return m_laserGroundTargetHeight; }
464464
inline UnsignedInt getScatterTargetResetTime() const { return m_scatterTargetResetTime; }
465+
inline Bool isScatterTargetResetRecenter() const { return m_scatterTargetResetRecenter; }
465466
inline const std::vector<Coord2D>& getScatterTargetsVector() const { return m_scatterTargets; }
466467
inline const WeaponBonusSet* getExtraBonus() const { return m_extraBonus; }
467468
inline Int getShotsPerBarrel() const { return m_shotsPerBarrel; }
@@ -600,6 +601,7 @@ class WeaponTemplate : public MemoryPoolObject
600601
Bool m_scatterTargetCenteredAtShooter; ///< if the scatter target pattern is centered at the shooter
601602

602603
UnsignedInt m_scatterTargetResetTime; ///< if this much time between shots has passed, we reset the scatter targets
604+
Bool m_scatterTargetResetRecenter; ///< when resetting scatter targets, use indices in the "middle" of the list, to keep the target centered for Line based attacks
603605

604606
mutable HistoricWeaponDamageList m_historicDamage;
605607
};
@@ -838,7 +840,7 @@ class Weapon : public MemoryPoolObject,
838840

839841
void computeBonus(const Object *source, WeaponBonusConditionFlags extraBonusFlags, WeaponBonus& bonus) const;
840842

841-
void rebuildScatterTargets();
843+
void rebuildScatterTargets(Bool recenter = false);
842844

843845

844846
private:

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ const FieldParse WeaponTemplate::TheWeaponTemplateFieldParseTable[] =
245245
{ "ScatterTargetMinScalar", INI::parseReal, NULL, offsetof(WeaponTemplate, m_scatterTargetMinScalar) },
246246
{ "ScatterTargetCenteredAtShooter", INI::parseBool, NULL, offsetof(WeaponTemplate, m_scatterTargetCenteredAtShooter) },
247247
{ "ScatterTargetResetTime", INI::parseDurationUnsignedInt, NULL, offsetof(WeaponTemplate, m_scatterTargetResetTime) },
248+
{ "ScatterTargetResetRecenter", INI::parseBool, NULL, offsetof(WeaponTemplate, m_scatterTargetResetRecenter) },
248249
{ "PreAttackFX", parseAllVetLevelsFXList, NULL, offsetof(WeaponTemplate, m_preAttackFXs) },
249250
{ "VeterancyPreAttackFX", parsePerVetLevelFXList, NULL, offsetof(WeaponTemplate, m_preAttackFXs) },
250251
{ "PreAttackFXDelay", INI::parseDurationUnsignedInt, NULL, offsetof(WeaponTemplate, m_preAttackFXDelay) },
@@ -2017,15 +2018,29 @@ void Weapon::setClipPercentFull(Real percent, Bool allowReduction)
20172018
}
20182019

20192020
//-------------------------------------------------------------------------------------------------
2020-
void Weapon::rebuildScatterTargets()
2021+
void Weapon::rebuildScatterTargets(Bool recenter/* = false*/)
20212022
{
20222023
m_scatterTargetsUnused.clear();
20232024
Int scatterTargetsCount = m_template->getScatterTargetsVector().size();
20242025
if (scatterTargetsCount)
20252026
{
2026-
// When I reload, I need to rebuild the list of ScatterTargets to shoot at.
2027-
for (Int targetIndex = scatterTargetsCount - 1; targetIndex >= 0; targetIndex--)
2028-
m_scatterTargetsUnused.push_back(targetIndex);
2027+
if (recenter && m_ammoInClip > 0 && m_ammoInClip < m_template->getClipSize() && m_template->getClipSize() > 0) {
2028+
// Recenter case is relevant when we have "sweep" target set up in a line around the target.
2029+
// When we reset, we want to keep the next shots around the target, which would be the
2030+
// indices in the center of the list.
2031+
UnsignedInt startIndex = REAL_TO_INT_FLOOR((m_template->getClipSize() - m_ammoInClip) / 2);
2032+
for (Int targetIndex = startIndex + m_ammoInClip - 1; targetIndex >= startIndex; targetIndex--) {
2033+
m_scatterTargetsUnused.push_back(targetIndex);
2034+
}
2035+
// TODO: Crash
2036+
// Is there any need to fill up the rest of the targets?
2037+
}
2038+
else {
2039+
// When I reload, I need to rebuild the list of ScatterTargets to shoot at.
2040+
for (Int targetIndex = scatterTargetsCount - 1; targetIndex >= 0; targetIndex--)
2041+
m_scatterTargetsUnused.push_back(targetIndex);
2042+
}
2043+
20292044

20302045
if (m_template->isScatterTargetRandomAngle()) {
20312046
m_scatterTargetsAngle = GameLogicRandomValueReal(0, PI * 2);
@@ -2805,7 +2820,7 @@ Bool Weapon::privateFireWeapon(
28052820
if (m_template->getScatterTargetResetTime() > 0) {
28062821
UnsignedInt frameNow = TheGameLogic->getFrame();
28072822
if (m_lastFireFrame + m_template->getScatterTargetResetTime() < frameNow) {
2808-
rebuildScatterTargets();
2823+
rebuildScatterTargets(m_template->isScatterTargetResetRecenter());
28092824
}
28102825
}
28112826

0 commit comments

Comments
 (0)