Skip to content

Commit

Permalink
Allow restricting whether AE ArmorMultiplier is applied to damage dea…
Browse files Browse the repository at this point in the history
…lt by specific Warhead(s)
  • Loading branch information
Starkku committed Nov 6, 2024
1 parent f21e471 commit a5fbfe7
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 7 deletions.
5 changes: 4 additions & 1 deletion docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ This page describes all the engine features that are either new and introduced b
- `Tint.Color` & `Tint.Intensity` can be used to set a color tint effect and additive lighting increase/decrease on the object the effect is attached to, respectively.
- `Tint.VisibleToHouses` can be used to control which houses can see the tint effect.
- `FirepowerMultiplier`, `ArmorMultiplier`, `SpeedMultiplier` and `ROFMultiplier` can be used to modify the object's firepower, armor strength, movement speed and weapon reload rate, respectively.
- If `ROFMultiplier.ApplyOnCurrentTimer` is set to true, `ROFMultiplier` is applied on currently running reload timer (if any) when the effect is first applied.
- `ArmorMultiplier.AllowWarheads` and `ArmorMultiplier.DisallowWarheads` can be used to restrict which Warheads the armor multiplier is applied to when dealing damage.
- If `ROFMultiplier.ApplyOnCurrentTimer` is set to true, `ROFMultiplier` is applied on currently running reload timer (if any) when the effect is first applied.
- If `Cloakable` is set to true, the object the effect is attached to is granted ability to cloak itself for duration of the effect.
- `ForceDecloak`, if set to true, will uncloak and make the object the effect is attached to unable to cloak itself for duration of the effect.
- `WeaponRange.Multiplier` and `WeaponRange.ExtraRange` can be used to multiply the weapon firing range of the object the effect is attached to, or give it an increase / decrease (measured in cells), respectively. `ExtraRange` is cumulatively applied from all attached effects after all `Multiplier` values have been applied.
Expand Down Expand Up @@ -103,6 +104,8 @@ Tint.Intensity= ; floating point value
Tint.VisibleToHouses=all ; list of Affected House Enumeration (none|owner/self|allies/ally|team|enemies/enemy|all)
FirepowerMultiplier=1.0 ; floating point value
ArmorMultiplier=1.0 ; floating point value
ArmorMultiplier.AllowWarheads= ; list of WarheadTypes
ArmorMultiplier.DisallowWarheads= ; list of WarheadTypes
SpeedMultiplier=1.0 ; floating point value
ROFMultiplier=1.0 ; floating point value
ROFMultiplier.ApplyOnCurrentTimer=true ; boolean
Expand Down
3 changes: 3 additions & 0 deletions src/Ext/Techno/Body.Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ void TechnoExt::ExtData::RecalculateStatMultipliers()
bool hasTint = false;
bool reflectsDamage = false;
bool hasOnFireDiscardables = false;
bool hasRestrictedArmorMultipliers = false;

for (const auto& attachEffect : this->AttachedEffects)
{
Expand All @@ -1001,6 +1002,7 @@ void TechnoExt::ExtData::RecalculateStatMultipliers()
hasTint |= type->HasTint();
reflectsDamage |= type->ReflectDamage;
hasOnFireDiscardables |= (type->DiscardOn & DiscardCondition::Firing) != DiscardCondition::None;
hasRestrictedArmorMultipliers |= (type->ArmorMultiplier != 1.0 && (type->ArmorMultiplier_AllowWarheads.size() > 0 || type->ArmorMultiplier_DisallowWarheads.size() > 0));
}

this->AE.FirepowerMultiplier = firepower;
Expand All @@ -1014,6 +1016,7 @@ void TechnoExt::ExtData::RecalculateStatMultipliers()
this->AE.HasTint = hasTint;
this->AE.ReflectDamage = reflectsDamage;
this->AE.HasOnFireDiscardables = hasOnFireDiscardables;
this->AE.HasRestrictedArmorMultipliers = hasRestrictedArmorMultipliers;

if (forceDecloak && pThis->CloakState == CloakState::Cloaked)
pThis->Uncloak(true);
Expand Down
48 changes: 42 additions & 6 deletions src/Ext/Techno/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,51 @@ DEFINE_HOOK(0x4DB218, FootClass_GetMovementSpeed_SpeedMultiplier, 0x6)
return 0;
}

DEFINE_HOOK_AGAIN(0x6FDC87, TechnoClass_ArmorMultiplier, 0x6) // TechnoClass_AdjustDamage
DEFINE_HOOK(0x701966, TechnoClass_ArmorMultiplier, 0x6) // TechnoClass_ReceiveDamage
static int CalculateArmorMultipliers(TechnoClass* pThis, int damage, WarheadTypeClass* pWarhead)
{
TechnoClass* pThis = R->Origin() == 0x701966 ? R->ESI<TechnoClass*>() : R->EDI<TechnoClass*>();
auto const pExt = TechnoExt::ExtMap.Find(pThis);
double mult = pExt->AE.ArmorMultiplier;

if (pExt->AE.HasRestrictedArmorMultipliers)
{
for (auto const& attachEffect : pExt->AttachedEffects)
{
if (!attachEffect->IsActive())
continue;

auto const type = attachEffect->GetType();

if (type->ArmorMultiplier_DisallowWarheads.Contains(pWarhead))
continue;

if (type->ArmorMultiplier_AllowWarheads.size() > 0 && !type->ArmorMultiplier_AllowWarheads.Contains(pWarhead))
continue;

mult *= type->ArmorMultiplier;
}
}

return static_cast<int>(damage / mult);
}

DEFINE_HOOK(0x6FDC87, TechnoClass_AdjustDamage_ArmorMultiplier, 0x6)
{
GET(TechnoClass*, pTarget, EDI);
GET(int, damage, EAX);
GET_STACK(WeaponTypeClass*, pWeapon, STACK_OFFSET(0x18, 0x8));

auto const pExt = TechnoExt::ExtMap.Find(pThis);
damage = static_cast<int>(damage / pExt->AE.ArmorMultiplier);
R->EAX(damage);
R->EAX(CalculateArmorMultipliers(pTarget, damage, pWeapon->Warhead));

return 0;
}

DEFINE_HOOK(0x701966, TechnoClass_ReceiveDamage_ArmorMultiplier, 0x6)
{
GET(TechnoClass*, pThis, ESI);
GET(int, damage, EAX);
GET_STACK(WarheadTypeClass*, pWarhead, STACK_OFFSET(0xC4, 0xC));

R->EAX(CalculateArmorMultipliers(pThis, damage, pWarhead));

return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/New/Entity/AttachEffectClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ struct AttachEffectTechnoProperties
bool HasTint;
bool ReflectDamage;
bool HasOnFireDiscardables;
bool HasRestrictedArmorMultipliers;

AttachEffectTechnoProperties() :
FirepowerMultiplier { 1.0 }
Expand All @@ -107,5 +108,6 @@ struct AttachEffectTechnoProperties
, HasTint { false }
, ReflectDamage { false }
, HasOnFireDiscardables { false }
, HasRestrictedArmorMultipliers { false }
{ }
};
4 changes: 4 additions & 0 deletions src/New/Type/AttachEffectTypeClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ void AttachEffectTypeClass::LoadFromINI(CCINIClass* pINI)

this->FirepowerMultiplier.Read(exINI, pSection, "FirepowerMultiplier");
this->ArmorMultiplier.Read(exINI, pSection, "ArmorMultiplier");
this->ArmorMultiplier_AllowWarheads.Read(exINI, pSection, "ArmorMultiplier.AllowWarheads");
this->ArmorMultiplier_DisallowWarheads.Read(exINI, pSection, "ArmorMultiplier.DisallowWarheads");
this->SpeedMultiplier.Read(exINI, pSection, "SpeedMultiplier");
this->ROFMultiplier.Read(exINI, pSection, "ROFMultiplier");
this->ROFMultiplier_ApplyOnCurrentTimer.Read(exINI, pSection, "ROFMultiplier.ApplyOnCurrentTimer");
Expand Down Expand Up @@ -184,6 +186,8 @@ void AttachEffectTypeClass::Serialize(T& Stm)
.Process(this->Tint_VisibleToHouses)
.Process(this->FirepowerMultiplier)
.Process(this->ArmorMultiplier)
.Process(this->ArmorMultiplier_AllowWarheads)
.Process(this->ArmorMultiplier_DisallowWarheads)
.Process(this->SpeedMultiplier)
.Process(this->ROFMultiplier)
.Process(this->ROFMultiplier_ApplyOnCurrentTimer)
Expand Down
4 changes: 4 additions & 0 deletions src/New/Type/AttachEffectTypeClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class AttachEffectTypeClass final : public Enumerable<AttachEffectTypeClass>
Valueable<AffectedHouse> Tint_VisibleToHouses;
Valueable<double> FirepowerMultiplier;
Valueable<double> ArmorMultiplier;
ValueableVector<WarheadTypeClass*> ArmorMultiplier_AllowWarheads;
ValueableVector<WarheadTypeClass*> ArmorMultiplier_DisallowWarheads;
Valueable<double> SpeedMultiplier;
Valueable<double> ROFMultiplier;
Valueable<bool> ROFMultiplier_ApplyOnCurrentTimer;
Expand Down Expand Up @@ -113,6 +115,8 @@ class AttachEffectTypeClass final : public Enumerable<AttachEffectTypeClass>
, Tint_VisibleToHouses { AffectedHouse::All }
, FirepowerMultiplier { 1.0 }
, ArmorMultiplier { 1.0 }
, ArmorMultiplier_AllowWarheads {}
, ArmorMultiplier_DisallowWarheads {}
, SpeedMultiplier { 1.0 }
, ROFMultiplier { 1.0 }
, ROFMultiplier_ApplyOnCurrentTimer { true }
Expand Down

0 comments on commit a5fbfe7

Please sign in to comment.