Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Minor] Reflect Damage Tweak #1354

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ This page describes all the engine features that are either new and introduced b
- `Crit.AllowWarheads` can be used to list only Warheads that can benefit from this critical hit chance multiplier and `Crit.DisallowWarheads` weapons that are not allowed to, respectively.
- `RevengeWeapon` can be used to temporarily grant the specified weapon as a [revenge weapon](#revenge-weapon) for the attached object.
- `RevengeWeapon.AffectsHouses` customizes which houses can trigger the revenge weapon.
- `ReflectDamage` can be set to true to have any positive damage dealt to the object the effect is attached to be reflected back to the attacker. `ReflectDamage.Warhead` determines which Warhead is used to deal the damage, defaults to `[CombatDamage]`->`C4Warhead`. If `ReflectDamage.Warhead` is set to true, the Warhead is fully detonated instead of used to simply deal damage. `ReflectDamage.Multiplier` is a multiplier to the damage received and then reflected back. Already reflected damage cannot be further reflected back.
- Warheads can prevent reflect damage from occuring by setting `SuppressReflectDamage` to true. `SuppressReflectDamage.Types` can control which AttachEffectTypes' reflect damage is suppressed, if none are listed then all of them are suppressed.
- `ReflectDamage` can be set to true to have any positive damage dealt to the object the effect is attached to be reflected back to the attacker. `ReflectDamage.Warhead` determines which Warhead is used to deal the damage, defaults to `[CombatDamage]`->`C4Warhead`. If `ReflectDamage.Warhead` is set to true, the Warhead is fully detonated instead of used to simply deal damage. `ReflectDamage.Chance` determines the chance of reflection. `ReflectDamage.Multiplier` is a multiplier to the damage received and then reflected back, while `ReflectDamage.Override` directly overrides the damage. Already reflected damage cannot be further reflected back.
- Warheads can prevent reflect damage from occuring by setting `SuppressReflectDamage` to true. `SuppressReflectDamage.Types` can control which AttachEffectTypes' reflect damage is suppressed, if none are listed then all of them are suppressed. `SuppressReflectDamage.Groups` does the same thing but for all AttachEffectTypes in the listed groups.
- `DisableWeapons` can be used to disable ability to fire any and all weapons.
- On TechnoTypes with `OpenTopped=true`, `OpenTopped.CheckTransportDisableWeapons` can be set to true to make passengers not be able to fire out if transport's weapons are disabled by `DisableWeapons`.
- It is possible to set groups for attach effect types by defining strings in `Groups`.
Expand Down Expand Up @@ -117,6 +117,8 @@ ReflectDamage.Warhead= ; WarheadType
ReflectDamage.Warhead.Detonate=false ; WarheadType
ReflectDamage.Multiplier=1.0 ; floating point value, percents or absolute
ReflectDamage.AffectsHouses=all ; list of Affected House Enumeration (none|owner/self|allies/ally|team|enemies/enemy|all)
ReflectDamage.Chance=1.0 ; floating point value
ReflectDamage.Override= ; integer
DisableWeapons=false ; boolean
Groups= ; comma-separated list of strings (group IDs)

Expand Down Expand Up @@ -149,6 +151,7 @@ AttachEffect.CumulativeRemoveMaxCounts= ; integer - maximum removed insta
AttachEffect.DurationOverrides= ; integer - duration overrides (comma-separated) for AttachTypes in order from first to last.
SuppressReflectDamage=false ; boolean
SuppressReflectDamage.Types= ; List of AttachEffectTypes
SuppressReflectDamage.Groups= ; comma-separated list of strings (group IDs)
```

### Custom Radiation Types
Expand Down
10 changes: 7 additions & 3 deletions src/Ext/Techno/Hooks.AttachEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ DEFINE_HOOK(0x701E18, TechnoClass_ReceiveDamage_ReflectDamage, 0x7)
if (pWHExt->Reflected)
return 0;

if (pExt->AE.ReflectDamage && *pDamage > 0 && (!pWHExt->SuppressReflectDamage || pWHExt->SuppressReflectDamage_Types.size() > 0))
if (pExt->AE.ReflectDamage && *pDamage > 0 && (!pWHExt->SuppressReflectDamage ||
pWHExt->SuppressReflectDamage_Types.size() > 0 || pWHExt->SuppressReflectDamage_Groups.size() > 0))
{
for (auto& attachEffect : pExt->AttachedEffects)
{
Expand All @@ -154,11 +155,14 @@ DEFINE_HOOK(0x701E18, TechnoClass_ReceiveDamage_ReflectDamage, 0x7)
if (!pType->ReflectDamage)
continue;

if (pWHExt->SuppressReflectDamage && pWHExt->SuppressReflectDamage_Types.Contains(pType))
if (pType->ReflectDamage_Chance < ScenarioClass::Instance->Random.RandomDouble())
continue;

if (pWHExt->SuppressReflectDamage && (pWHExt->SuppressReflectDamage_Types.Contains(pType) || pType->HasGroups(pWHExt->SuppressReflectDamage_Groups, false)))
continue;

Coronia marked this conversation as resolved.
Show resolved Hide resolved
auto const pWH = pType->ReflectDamage_Warhead.Get(RulesClass::Instance->C4Warhead);
int damage = static_cast<int>(*pDamage * pType->ReflectDamage_Multiplier);
int damage = pType->ReflectDamage_Override.Get(static_cast<int>(*pDamage * pType->ReflectDamage_Multiplier));

if (EnumFunctions::CanTargetHouse(pType->ReflectDamage_AffectsHouses, pThis->Owner, pSourceHouse))
{
Expand Down
2 changes: 2 additions & 0 deletions src/Ext/WarheadType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->SuppressRevengeWeapons_Types.Read(exINI, pSection, "SuppressRevengeWeapons.Types");
this->SuppressReflectDamage.Read(exINI, pSection, "SuppressReflectDamage");
this->SuppressReflectDamage_Types.Read(exINI, pSection, "SuppressReflectDamage.Types");
exINI.ParseStringList(this->SuppressReflectDamage_Groups, pSection, "SuppressReflectDamage.Groups");

// Convert.From & Convert.To
TypeConvertGroup::Parse(this->Convert_Pairs, exINI, pSection, AffectedHouse::All);
Expand Down Expand Up @@ -455,6 +456,7 @@ void WarheadTypeExt::ExtData::Serialize(T& Stm)
.Process(this->SuppressRevengeWeapons_Types)
.Process(this->SuppressReflectDamage)
.Process(this->SuppressReflectDamage_Types)
.Process(this->SuppressReflectDamage_Groups)

.Process(this->InflictLocomotor)
.Process(this->RemoveInflictedLocomotor)
Expand Down
2 changes: 2 additions & 0 deletions src/Ext/WarheadType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class WarheadTypeExt
ValueableVector<WeaponTypeClass*> SuppressRevengeWeapons_Types;
Valueable<bool> SuppressReflectDamage;
ValueableVector<AttachEffectTypeClass*> SuppressReflectDamage_Types;
std::vector<std::string> SuppressReflectDamage_Groups;

// Ares tags
// http://ares-developers.github.io/Ares-docs/new/warheads/general.html
Expand Down Expand Up @@ -282,6 +283,7 @@ class WarheadTypeExt
, SuppressRevengeWeapons_Types {}
, SuppressReflectDamage { false }
, SuppressReflectDamage_Types {}
, SuppressReflectDamage_Groups {}

, AffectsEnemies { true }
, AffectsOwner {}
Expand Down
4 changes: 4 additions & 0 deletions src/New/Type/AttachEffectTypeClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ void AttachEffectTypeClass::LoadFromINI(CCINIClass* pINI)
this->ReflectDamage_Warhead_Detonate.Read(exINI, pSection, "ReflectDamage.Warhead.Detonate");
this->ReflectDamage_Multiplier.Read(exINI, pSection, "ReflectDamage.Multiplier");
this->ReflectDamage_AffectsHouses.Read(exINI, pSection, "ReflectDamage.AffectsHouses");
this->ReflectDamage_Chance.Read(exINI, pSection, "ReflectDamage.Chance");
this->ReflectDamage_Override.Read(exINI, pSection, "ReflectDamage.Override");

this->DisableWeapons.Read(exINI, pSection, "DisableWeapons");

Expand Down Expand Up @@ -200,6 +202,8 @@ void AttachEffectTypeClass::Serialize(T& Stm)
.Process(this->ReflectDamage_Warhead_Detonate)
.Process(this->ReflectDamage_Multiplier)
.Process(this->ReflectDamage_AffectsHouses)
.Process(this->ReflectDamage_Chance)
.Process(this->ReflectDamage_Override)
.Process(this->DisableWeapons)
.Process(this->Groups)
;
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 @@ -55,6 +55,8 @@ class AttachEffectTypeClass final : public Enumerable<AttachEffectTypeClass>
Valueable<bool> ReflectDamage_Warhead_Detonate;
Valueable<double> ReflectDamage_Multiplier;
Valueable<AffectedHouse> ReflectDamage_AffectsHouses;
Valueable<double> ReflectDamage_Chance;
Nullable<int> ReflectDamage_Override;
Valueable<bool> DisableWeapons;

std::vector<std::string> Groups;
Expand Down Expand Up @@ -103,6 +105,8 @@ class AttachEffectTypeClass final : public Enumerable<AttachEffectTypeClass>
, ReflectDamage_Warhead_Detonate { false }
, ReflectDamage_Multiplier { 1.0 }
, ReflectDamage_AffectsHouses { AffectedHouse::All }
, ReflectDamage_Chance { 1.0 }
, ReflectDamage_Override {}
, DisableWeapons { false }
, Groups {}
{};
Expand Down
Loading