Skip to content

Commit efe8f20

Browse files
committed
AE modification
1 parent 7ec5e77 commit efe8f20

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

docs/New-or-Enhanced-Logics.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This page describes all the engine features that are either new and introduced b
88

99
- Similar (but not identical) to [Ares' AttachEffect](https://ares-developers.github.io/Ares-docs/new/attacheffect.html), but with some differences and new features. The largest difference is that here attached effects are explicitly defined types.
1010
- `Duration` determines how long the effect lasts for. It can be overriden by `DurationOverrides` on TechnoTypes and Warheads.
11+
- `Duration.ApplyVersus.Warhead` can multiply the duration by the set warhead's versus against the target's armor type if it's not negative. Can't reduce duration to below 0 by a negative versus.
1112
- If `Duration.ApplyFirepowerMult` set to true, the duration will multiply the invoker's firepower multipliers if it's not negative. Can't reduce duration to below 0 by a negative firepower multiplier.
1213
- If `Duration.ApplyArmorMultOnTarget` set to true, the duration will divide the target's armor multipliers if it's not negative. This'll also include `ArmorMultiplier` from its own and ignore `ArmorMultiplier.Allow/DisallowWarheads`. Can't reduce duration to below 0 by a negative armor multiplier.
1314
- `Cumulative`, if set to true, allows the same type of effect to be applied on same object multiple times, up to `Cumulative.MaxCount` number or with no limit if `Cumulative.MaxCount` is a negative number. If the target already has `Cumulative.MaxCount` number of the same effect applied on it, trying to attach another will refresh duration of the attached instance with shortest remaining duration.
@@ -20,6 +21,8 @@ This page describes all the engine features that are either new and introduced b
2021
- `inrange`: Discard if within weapon range from current target. Distance can be overridden via `DiscardOn.RangeOverride`.
2122
- `outofrange`: Discard if outside weapon range from current target. Distance can be overridden via `DiscardOn.RangeOverride`.
2223
- `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.AbovePercent` or `DiscardOn.BelowPercent` is set, the effect is discarded when the object's health percentage is above/below that value.
25+
- If `AffectAbovePercent` or `AffectBelowPercent` is set, the effect can be applied only when the object's health percentage is above/below that value.
2326
- If `PenetratesIronCurtain` is not set to true, the effect is not applied on currently invulnerable objects.
2427
- `PenetratesForceShield` can be used to set this separately for Force Shielded objects, defaults to value of `PenetratesIronCurtain`.
2528
- `Animation` defines animation to play in an indefinite loop for as long as the effect is active on the object it is attached to.
@@ -84,12 +87,17 @@ In `rulesmd.ini`:
8487

8588
[SOMEATTACHEFFECT] ; AttachEffectType
8689
Duration=0 ; integer - game frames or negative value for indefinite duration
90+
Duration.ApplyVersus.Warhead= ; WarheadType
8791
Duration.ApplyFirepowerMult=false ; boolean
8892
Duration.ApplyArmorMultOnTarget=false ; boolean
8993
Cumulative=false ; boolean
9094
Cumulative.MaxCount=-1 ; integer
9195
Powered=false ; boolean
9296
DiscardOn=none ; List of discard condition enumeration (none|entry|move|stationary|drain|inrange|outofrange)
97+
DiscardOn.AbovePercent= ; floating point value, percents or absolute (0.0-1.0)
98+
DiscardOn.BelowPercent= ; floating point value, percents or absolute (0.0-1.0)
99+
AffectAbovePercent= ; floating point value, percents or absolute (0.0-1.0)
100+
AffectBelowPercent= ; floating point value, percents or absolute (0.0-1.0)
93101
DiscardOn.RangeOverride= ; floating point value, distance in cells
94102
PenetratesIronCurtain=false ; boolean
95103
PenetratesForceShield= ; boolean

src/New/Entity/AttachEffectClass.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,20 @@ AttachEffectClass::AttachEffectClass(AttachEffectTypeClass* pType, TechnoClass*
4646

4747
this->Duration = this->DurationOverride != 0 ? this->DurationOverride : this->Type->Duration;
4848

49-
if (this->Type->Duration_ApplyFirepowerMult && this->Duration > 0 && pInvoker)
50-
this->Duration = Math::max(static_cast<int>(this->Duration * pInvoker->FirepowerMultiplier * TechnoExt::ExtMap.Find(pInvoker)->AE.FirepowerMultiplier), 0);
49+
if (this->Duration > 0)
50+
{
51+
if (this->Type->Duration_ApplyVersus_Warhead)
52+
{
53+
auto const pArmor = pTechno->Shield && pTechno->Shield->IsActive() ? pTechno->Shield->GetArmor() : pTechno->GetTechnoType()->Armor;
54+
this->Duration = Math::max(static_cast<int>(this->Duration * GeneralUtils::GetWarheadVersusArmor(this->Type->Duration_ApplyVersus_Warhead, pArmor), 0));
55+
}
56+
57+
if (this->Type->Duration_ApplyFirepowerMult && pInvoker)
58+
this->Duration = Math::max(static_cast<int>(this->Duration * pInvoker->FirepowerMultiplier * TechnoExt::ExtMap.Find(pInvoker)->AE.FirepowerMultiplier), 0);
5159

52-
if (this->Type->Duration_ApplyArmorMultOnTarget && this->Duration > 0) // count its own ArmorMultiplier as well
53-
this->Duration = Math::max(static_cast<int>(this->Duration / pTechno->ArmorMultiplier / TechnoExt::ExtMap.Find(pTechno)->AE.ArmorMultiplier / this->Type->ArmorMultiplier), 0);
60+
if (this->Type->Duration_ApplyArmorMultOnTarget) // count its own ArmorMultiplier as well
61+
this->Duration = Math::max(static_cast<int>(this->Duration / pTechno->ArmorMultiplier / TechnoExt::ExtMap.Find(pTechno)->AE.ArmorMultiplier / this->Type->ArmorMultiplier), 0);
62+
}
5463

5564
AttachEffectClass::Array.emplace_back(this);
5665
}
@@ -388,6 +397,12 @@ void AttachEffectClass::RefreshDuration(int durationOverride)
388397
else
389398
this->Duration = this->DurationOverride ? this->DurationOverride : this->Type->Duration;
390399

400+
if (this->Type->Duration_ApplyVersus_Warhead)
401+
{
402+
auto const pArmor = this->Techno->Shield && this->Techno->Shield->IsActive() ? this->Techno->Shield->GetArmor() : this->Techno->GetTechnoType()->Armor;
403+
this->Duration = Math::max(static_cast<int>(this->Duration * GeneralUtils::GetWarheadVersusArmor(this->Type->Duration_ApplyVersus_Warhead, pArmor), 0));
404+
}
405+
391406
if (this->Type->Duration_ApplyFirepowerMult && this->Duration > 0 && this->Invoker)
392407
this->Duration = Math::max(static_cast<int>(this->Duration * this->Invoker->FirepowerMultiplier * TechnoExt::ExtMap.Find(this->Invoker)->AE.FirepowerMultiplier), 0);
393408

@@ -427,6 +442,15 @@ bool AttachEffectClass::ShouldBeDiscardedNow() const
427442

428443
auto const pTechno = this->Techno;
429444

445+
if (this->Type->DiscardOn_AbovePercent > 0.0 && pTechno->GetHealthPercentage() >= this->Type->DiscardOn_AbovePercent)
446+
return false;
447+
448+
if (this->Type->DiscardOn_BelowPercent > 0.0 && pTechno->GetHealthPercentage() <= this->Type->DiscardOn_BelowPercent)
449+
return false;
450+
451+
if (this->Type->DiscardOn == DiscardCondition::None)
452+
return false;
453+
430454
if (auto const pFoot = abstract_cast<FootClass*>(pTechno))
431455
{
432456
bool isMoving = pFoot->Locomotor->Is_Really_Moving_Now();
@@ -567,6 +591,12 @@ AttachEffectClass* AttachEffectClass::CreateAndAttach(AttachEffectTypeClass* pTy
567591
if (!pType || !pTarget)
568592
return nullptr;
569593

594+
if (pType->AffectAbovePercent > 0.0 && pTarget->GetHealthPercentage() < pType->AffectAbovePercent)
595+
return nullptr;
596+
597+
if (pType->AffectBelowPercent > 0.0 && pTarget->GetHealthPercentage() > pType->AffectBelowPercent)
598+
return nullptr;
599+
570600
if (pTarget->IsIronCurtained())
571601
{
572602
bool penetrates = pTarget->ForceShielded ? pType->PenetratesForceShield.Get(pType->PenetratesIronCurtain) : pType->PenetratesIronCurtain;

src/New/Type/AttachEffectTypeClass.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,18 @@ 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");
99100
this->Duration_ApplyFirepowerMult.Read(exINI, pSection, "Duration.ApplyFirepowerMult");
100101
this->Duration_ApplyArmorMultOnTarget.Read(exINI, pSection, "Duration.ApplyArmorMultOnTarget");
101102
this->Cumulative.Read(exINI, pSection, "Cumulative");
102103
this->Cumulative_MaxCount.Read(exINI, pSection, "Cumulative.MaxCount");
103104
this->Powered.Read(exINI, pSection, "Powered");
104105
this->DiscardOn.Read(exINI, pSection, "DiscardOn");
105106
this->DiscardOn_RangeOverride.Read(exINI, pSection, "DiscardOn.RangeOverride");
107+
this->DiscardOn_AbovePercent.Read(exINI, pSection, "DiscardOn.AbovePercent");
108+
this->DiscardOn_BelowPercent.Read(exINI, pSection, "DiscardOn.BelowPercent");
109+
this->AffectAbovePercent.Read(exINI, pSection, "AffectAbovePercent");
110+
this->AffectBelowPercent.Read(exINI, pSection, "AffectBelowPercent");
106111
this->PenetratesIronCurtain.Read(exINI, pSection, "PenetratesIronCurtain");
107112
this->PenetratesForceShield.Read(exINI, pSection, "PenetratesForceShield");
108113

@@ -168,13 +173,18 @@ void AttachEffectTypeClass::Serialize(T& Stm)
168173
{
169174
Stm
170175
.Process(this->Duration)
176+
.Process(this->Duration_ApplyVersus_Warhead)
171177
.Process(this->Duration_ApplyFirepowerMult)
172178
.Process(this->Duration_ApplyArmorMultOnTarget)
173179
.Process(this->Cumulative)
174180
.Process(this->Cumulative_MaxCount)
175181
.Process(this->Powered)
176182
.Process(this->DiscardOn)
177183
.Process(this->DiscardOn_RangeOverride)
184+
.Process(this->DiscardOn_AbovePercent)
185+
.Process(this->DiscardOn_BelowPercent)
186+
.Process(this->AffectAbovePercent)
187+
.Process(this->AffectBelowPercent)
178188
.Process(this->PenetratesIronCurtain)
179189
.Process(this->PenetratesForceShield)
180190
.Process(this->Animation)

src/New/Type/AttachEffectTypeClass.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ class AttachEffectTypeClass final : public Enumerable<AttachEffectTypeClass>
4141

4242
public:
4343
Valueable<int> Duration;
44+
Valueable<WarheadTypeClass*> Duration_ApplyVersus_Warhead;
4445
Valueable<bool> Duration_ApplyFirepowerMult;
4546
Valueable<bool> Duration_ApplyArmorMultOnTarget;
4647
Valueable<bool> Cumulative;
4748
Valueable<int> Cumulative_MaxCount;
4849
Valueable<bool> Powered;
4950
Valueable<DiscardCondition> DiscardOn;
5051
Nullable<Leptons> DiscardOn_RangeOverride;
52+
Valueable<double> DiscardOn_AbovePercent;
53+
Valueable<double> DiscardOn_BelowPercent;
54+
Valueable<double> AffectAbovePercent;
55+
Valueable<double> AffectBelowPercent;
5156
Valueable<bool> PenetratesIronCurtain;
5257
Nullable<bool> PenetratesForceShield;
5358
Valueable<AnimTypeClass*> Animation;
@@ -97,13 +102,18 @@ class AttachEffectTypeClass final : public Enumerable<AttachEffectTypeClass>
97102

98103
AttachEffectTypeClass(const char* const pTitle) : Enumerable<AttachEffectTypeClass>(pTitle)
99104
, Duration { 0 }
105+
, Duration_ApplyVersus_Warhead {}
100106
, Duration_ApplyFirepowerMult { false }
101107
, Duration_ApplyArmorMultOnTarget { false }
102108
, Cumulative { false }
103109
, Cumulative_MaxCount { -1 }
104110
, Powered { false }
105111
, DiscardOn { DiscardCondition::None }
106112
, DiscardOn_RangeOverride {}
113+
, DiscardOn_AbovePercent { 0.0 }
114+
, DiscardOn_BelowPercent { 0.0 }
115+
, AffectAbovePercent { 0.0 }
116+
, AffectBelowPercent { 0.0 }
107117
, PenetratesIronCurtain { false }
108118
, PenetratesForceShield {}
109119
, Animation {}

0 commit comments

Comments
 (0)