Skip to content

Commit a7db33e

Browse files
committed
fix
1 parent 05243c2 commit a7db33e

File tree

8 files changed

+42
-28
lines changed

8 files changed

+42
-28
lines changed

docs/New-or-Enhanced-Logics.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This page describes all the engine features that are either new and introduced b
2121
- `inrange`: Discard if within weapon range from current target. Distance can be overridden via `DiscardOn.RangeOverride`.
2222
- `outofrange`: Discard if outside weapon range from current target. Distance can be overridden via `DiscardOn.RangeOverride`.
2323
- `firing`: Discard when firing a weapon. This counts special weapons that are not actually fired such as ones with `Spawner=true` or `DrainWeapon=true`.
24+
- If `DiscardOn.CumulativeCount` is greater than 0, the effect is discarded when it has `Cumulative=yes` and been attached to the object more than this amount of times.
2425
- If `DiscardOn.AbovePercent` or `DiscardOn.BelowPercent` is set, the effect is discarded when the object's health percentage is above/below that value.
2526
- If `AffectAbovePercent` or `AffectBelowPercent` is set, the effect can be applied only when the object's health percentage is above/below that value.
2627
- If `PenetratesIronCurtain` is not set to true, the effect is not applied on currently invulnerable objects.
@@ -117,11 +118,12 @@ Cumulative=false ; boolean
117118
Cumulative.MaxCount=-1 ; integer
118119
Powered=false ; boolean
119120
DiscardOn=none ; List of discard condition enumeration (none|entry|move|stationary|drain|inrange|outofrange)
121+
DiscardOn.RangeOverride= ; floating point value, distance in cells
122+
DiscardOn.CumulativeCount=-1 ; integer
120123
DiscardOn.AbovePercent= ; floating point value, percents or absolute (0.0-1.0)
121124
DiscardOn.BelowPercent= ; floating point value, percents or absolute (0.0-1.0)
122125
AffectAbovePercent= ; floating point value, percents or absolute (0.0-1.0)
123126
AffectBelowPercent= ; floating point value, percents or absolute (0.0-1.0)
124-
DiscardOn.RangeOverride= ; floating point value, distance in cells
125127
PenetratesIronCurtain=false ; boolean
126128
PenetratesForceShield= ; boolean
127129
Animation= ; AnimationType

src/Ext/Bullet/Body.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,29 +151,27 @@ void BulletExt::ExtData::InitializeLaserTrails()
151151
}
152152
}
153153

154-
void BulletExt::ExtData::ApplyExtraWarheads(const std::vector<WarheadTypeClass*>& exWH, const std::vector<int>& exWHDamageOverrides, const std::vector<double>& exWHChances, const std::vector<bool>& exWHFull, const std::vector<bool>& exWHOwner, const CoordStruct& coords, HouseClass* pOwner, TechnoClass* pInvoker)
154+
void BulletExt::ExtData::ApplyExtraWarheads(const std::vector<WarheadTypeClass*>& exWH, const std::vector<int>& exWHOverrides, const std::vector<double>& exWHChances, const std::vector<bool>& exWHFull, const std::vector<bool>& exWHOwner, const CoordStruct& coords, HouseClass* pOwner, TechnoClass* pInvoker)
155155
{
156156
auto const pThis = this->OwnerObject();
157+
auto const pTarget = abstract_cast<TechnoClass*>(pThis->Target);
157158
const int defaultDamage = pThis->WeaponType ? pThis->WeaponType->Damage : 0;
158159

159160
for (size_t i = 0; i < exWH.size(); i++)
160161
{
161162
auto const pWH = exWH[i];
162163
auto const pWHExt = WarheadTypeExt::ExtMap.Find(pWH);
163164

164-
if (auto const pTarget = abstract_cast<TechnoClass*>(pThis->Target))
165-
{
166-
if (!pWHExt->IsHealthInThreshold(pTarget))
167-
continue;
168-
}
165+
if (pTarget && !pWHExt->IsHealthInThreshold(pTarget))
166+
continue;
169167

170168
int damage = defaultDamage;
171-
size_t size = exWHDamageOverrides.size();
169+
size_t size = exWHOverrides.size();
172170

173171
if (size > i)
174-
damage = exWHDamageOverrides[i];
172+
damage = exWHOverrides[i];
175173
else if (size > 0)
176-
damage = exWHDamageOverrides[size - 1];
174+
damage = exWHOverrides[size - 1];
177175

178176
bool detonate = true;
179177
size = exWHChances.size();
@@ -222,7 +220,7 @@ void BulletExt::ExtData::ApplyExtraWarheads(const std::vector<WarheadTypeClass*>
222220
if (isFull)
223221
WarheadTypeExt::DetonateAt(pWH, coords, pFirer, damage, pHouse, pThis->Target);
224222
else
225-
WarheadTypeExt::ExtMap.Find(pWH)->DamageAreaWithTarget(coords, damage, pFirer, pWH, true, pHouse, abstract_cast<TechnoClass*>(pThis->Target));
223+
pWHExt->DamageAreaWithTarget(coords, damage, pFirer, pWH, true, pHouse, pTarget);
226224
}
227225
}
228226

src/Ext/Bullet/Body.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class BulletExt
5454
void InterceptBullet(TechnoClass* pSource, WeaponTypeClass* pWeapon);
5555
void ApplyRadiationToCell(CellStruct cell, int spread, int radLevel);
5656
void InitializeLaserTrails();
57-
void ApplyExtraWarheads(const std::vector<WarheadTypeClass*>& exWH, const std::vector<int>& exWHDamageOverrides, const std::vector<double>& exWHChances, const std::vector<bool>& exWHFull, const std::vector<bool>& exWHOwner, const CoordStruct& coords, HouseClass* pOwner, TechnoClass* pInvoker = nullptr);
57+
void ApplyExtraWarheads(const std::vector<WarheadTypeClass*>& exWH, const std::vector<int>& exWHOverrides, const std::vector<double>& exWHChances, const std::vector<bool>& exWHFull, const std::vector<bool>& exWHOwner, const CoordStruct& coords, HouseClass* pOwner, TechnoClass* pInvoker = nullptr);
5858

5959
private:
6060
template <typename T>

src/Ext/Techno/Body.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,5 @@ class TechnoExt
262262
static void ApplyKillWeapon(TechnoClass* pThis, TechnoClass* pSource, WarheadTypeClass* pWH);
263263
static void ApplyRevengeWeapon(TechnoClass* pThis, TechnoClass* pSource, WarheadTypeClass* pWH);
264264
static bool IsAllowedSplitsTarget(TechnoClass* pSource, HouseClass* pOwner, WeaponTypeClass* pWeapon, TechnoClass* pTarget, bool useWeaponTargeting = true, bool allowZeroDamage = false);
265-
static void RealLaunch(WeaponTypeClass* pWeapon, TechnoClass* pSource, TechnoClass* pTarget, bool applyFirepowerMult = true);
265+
static void RealLaunch(WeaponTypeClass* pWeapon, TechnoClass* pSource, TechnoClass* pTarget, bool applyFirepowerMult = true, TechnoClass* pFirer = nullptr);
266266
};

src/Ext/Techno/WeaponHelpers.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ void TechnoExt::ApplyKillWeapon(TechnoClass* pThis, TechnoClass* pSource, Warhea
254254
if (!pTypeExt->SuppressKillWeapons || (hasFilters && !pTypeExt->SuppressKillWeapons_Types.Contains(pWHExt->KillWeapon_OnFirer)))
255255
{
256256
if (pWHExt->KillWeapon_OnFirer_RealLaunch)
257-
RealLaunch(pWHExt->KillWeapon_OnFirer, pSource, pSource);
257+
RealLaunch(pWHExt->KillWeapon_OnFirer, pSource, pSource, true, pThis);
258258
else
259259
WeaponTypeExt::DetonateAt(pWHExt->KillWeapon_OnFirer, pSource, pSource);
260260
}
@@ -488,7 +488,7 @@ void TechnoExt::ExtData::ApplyAuxWeapon(WeaponTypeClass* pAuxWeapon, AbstractCla
488488
}
489489
}
490490

491-
void TechnoExt::RealLaunch(WeaponTypeClass* pWeapon, TechnoClass* pSource, TechnoClass* pTarget, bool applyFirepowerMult)
491+
void TechnoExt::RealLaunch(WeaponTypeClass* pWeapon, TechnoClass* pSource, TechnoClass* pTarget, bool applyFirepowerMult, TechnoClass* pFirer)
492492
{
493493
int damage = pWeapon->Damage;
494494

@@ -498,7 +498,10 @@ void TechnoExt::RealLaunch(WeaponTypeClass* pWeapon, TechnoClass* pSource, Techn
498498
if (BulletClass* pBullet = pWeapon->Projectile->CreateBullet(pTarget, pSource,
499499
damage, pWeapon->Warhead, pWeapon->Speed, pWeapon->Bright))
500500
{
501-
BulletExt::SimulatedFiringUnlimbo(pBullet, pSource->Owner, pWeapon, pSource->Location, true);
501+
if (!pFirer)
502+
pFirer = pSource;
503+
504+
BulletExt::SimulatedFiringUnlimbo(pBullet, pSource->Owner, pWeapon, pFirer->Location, true);
502505
BulletExt::SimulatedFiringEffects(pBullet, pSource->Owner, nullptr, false, true);
503506
}
504507
}

src/New/Entity/AttachEffectClass.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -513,26 +513,33 @@ bool AttachEffectClass::ShouldBeDiscardedNow()
513513
return true;
514514
}
515515

516-
auto const discardOn = this->Type->DiscardOn;
516+
auto const pType = this->Type;
517+
auto const pTechno = this->Techno;
517518

518-
if (discardOn == DiscardCondition::None)
519+
if (pType->DiscardOn_AbovePercent > 0.0 && pTechno->GetHealthPercentage() >= pType->DiscardOn_AbovePercent)
519520
{
520-
this->LastDiscardCheckValue = false;
521-
return false;
521+
this->LastDiscardCheckValue = true;
522+
return true;
522523
}
523524

524-
auto const pTechno = this->Techno;
525+
if (pType->DiscardOn_BelowPercent > 0.0 && pTechno->GetHealthPercentage() <= pType->DiscardOn_BelowPercent)
526+
{
527+
this->LastDiscardCheckValue = true;
528+
return true;
529+
}
525530

526-
if (this->Type->DiscardOn_AbovePercent > 0.0 && pTechno->GetHealthPercentage() >= this->Type->DiscardOn_AbovePercent)
531+
if (pType->DiscardOn_CumulativeCount > 0 && pType->DiscardOn_CumulativeCount <= pTechno->GetAttachedEffectCumulativeCount(pType))
527532
{
528-
this->LastDiscardCheckValue = false;
533+
this->LastDiscardCheckValue = true;
529534
return true;
530535
}
531536

532-
if (this->Type->DiscardOn_BelowPercent > 0.0 && pTechno->GetHealthPercentage() <= this->Type->DiscardOn_BelowPercent)
537+
auto const discardOn = pType->DiscardOn;
538+
539+
if (discardOn == DiscardCondition::None)
533540
{
534541
this->LastDiscardCheckValue = false;
535-
return true;
542+
return false;
536543
}
537544

538545
if (auto const pFoot = abstract_cast<FootClass*, true>(pTechno))
@@ -567,9 +574,9 @@ bool AttachEffectClass::ShouldBeDiscardedNow()
567574
{
568575
int distance = -1;
569576

570-
if (this->Type->DiscardOn_RangeOverride.isset())
577+
if (pType->DiscardOn_RangeOverride.isset())
571578
{
572-
distance = this->Type->DiscardOn_RangeOverride.Get();
579+
distance = pType->DiscardOn_RangeOverride.Get();
573580
}
574581
else
575582
{

src/New/Type/AttachEffectTypeClass.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void AttachEffectTypeClass::LoadFromINI(CCINIClass* pINI)
9696
INI_EX exINI(pINI);
9797

9898
this->Duration.Read(exINI, pSection, "Duration");
99-
this->Duration_ApplyVersus_Warhead.Read(exINI, pSection, "Duration.ApplyVersusWarhead");
99+
this->Duration_ApplyVersus_Warhead.Read(exINI, pSection, "Duration.ApplyVersus.Warhead");
100100
this->Duration_ApplyFirepowerMult.Read(exINI, pSection, "Duration.ApplyFirepowerMult");
101101
this->Duration_ApplyArmorMultOnTarget.Read(exINI, pSection, "Duration.ApplyArmorMultOnTarget");
102102
this->Cumulative.Read(exINI, pSection, "Cumulative");
@@ -106,6 +106,7 @@ void AttachEffectTypeClass::LoadFromINI(CCINIClass* pINI)
106106
this->DiscardOn_RangeOverride.Read(exINI, pSection, "DiscardOn.RangeOverride");
107107
this->DiscardOn_AbovePercent.Read(exINI, pSection, "DiscardOn.AbovePercent");
108108
this->DiscardOn_BelowPercent.Read(exINI, pSection, "DiscardOn.BelowPercent");
109+
this->DiscardOn_CumulativeCount.Read(exINI, pSection, "DiscardOn.CumulativeCount");
109110
this->AffectAbovePercent.Read(exINI, pSection, "AffectAbovePercent");
110111
this->AffectBelowPercent.Read(exINI, pSection, "AffectBelowPercent");
111112
this->PenetratesIronCurtain.Read(exINI, pSection, "PenetratesIronCurtain");
@@ -208,6 +209,7 @@ void AttachEffectTypeClass::Serialize(T& Stm)
208209
.Process(this->DiscardOn_RangeOverride)
209210
.Process(this->DiscardOn_AbovePercent)
210211
.Process(this->DiscardOn_BelowPercent)
212+
.Process(this->DiscardOn_CumulativeCount)
211213
.Process(this->AffectAbovePercent)
212214
.Process(this->AffectBelowPercent)
213215
.Process(this->PenetratesIronCurtain)

src/New/Type/AttachEffectTypeClass.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class AttachEffectTypeClass final : public Enumerable<AttachEffectTypeClass>
5151
Nullable<Leptons> DiscardOn_RangeOverride;
5252
Valueable<double> DiscardOn_AbovePercent;
5353
Valueable<double> DiscardOn_BelowPercent;
54+
Valueable<int> DiscardOn_CumulativeCount;
5455
Valueable<double> AffectAbovePercent;
5556
Valueable<double> AffectBelowPercent;
5657
Valueable<bool> PenetratesIronCurtain;
@@ -134,6 +135,7 @@ class AttachEffectTypeClass final : public Enumerable<AttachEffectTypeClass>
134135
, DiscardOn_RangeOverride {}
135136
, DiscardOn_AbovePercent { 0.0 }
136137
, DiscardOn_BelowPercent { 0.0 }
138+
, DiscardOn_CumulativeCount { -1 }
137139
, AffectAbovePercent { 0.0 }
138140
, AffectBelowPercent { 0.0 }
139141
, PenetratesIronCurtain { false }

0 commit comments

Comments
 (0)