From ef685015c4bece224f1c1db14b5a564c2f6e0e9b Mon Sep 17 00:00:00 2001 From: Metadorius Date: Fri, 27 Sep 2024 23:54:22 +0300 Subject: [PATCH] Warhead activation target health thresholds --- CREDITS.md | 1 + docs/Fixed-or-Improved-Logics.md | 14 ++++++++++++++ docs/New-or-Enhanced-Logics.md | 2 +- docs/Whats-New.md | 1 + src/Ext/WarheadType/Body.cpp | 17 +++++++++++++++++ src/Ext/WarheadType/Body.h | 6 ++++++ 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CREDITS.md b/CREDITS.md index 5fc9e9dd9..28e3b46bc 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -48,6 +48,7 @@ This page lists all the individual contributions to the project by their author. - Ability to disable shadow for debris & meteor animations - Voxel light source position customization - Voxel light source position and tilting fix + - Warhead activation target health thresholds - **Uranusian (Thrifinesma)**: - Mind Control enhancement - Custom warhead splash list diff --git a/docs/Fixed-or-Improved-Logics.md b/docs/Fixed-or-Improved-Logics.md index 69df4313c..587cd3b7c 100644 --- a/docs/Fixed-or-Improved-Logics.md +++ b/docs/Fixed-or-Improved-Logics.md @@ -1222,6 +1222,20 @@ UseWeeds.ReadinessAnimationPercentage=0.9 ; double - when this many weeds ## Warheads +### Customizable Warhead trigger conditions + +- It is now possible to make warheads only trigger when target's HP is above and/or below certain percentage. + - Both conditions need to evaluate to true in order for the warhead to trigger. +- If set to `false`, `EffectsRequireVerses` makes the Phobos-introduced warhead effects trigger even if it can't damage the target because of it's current ArmorType (e.g. 0% in `Verses`). + +In `rulesmd.ini`: +```ini +[SOMEWARHEAD] ; WarheadType +AffectsAbovePercent=0.0 ; floating point value, percents or absolute +AffectsBelowPercent=1.0 ; floating point value, percents or absolute +EffectsRequireVerses=false ; boolean +``` + ### Customizable Warhead animation behaviour - It is possible to make game play random animation from `AnimList` by setting `AnimList.PickRandom` to true. The result is similar to what `EMEffect=true` produces, however it comes with no side-effects (`EMEffect=true` prevents `Inviso=true` projectiles from snapping on targets, making them miss moving targets). diff --git a/docs/New-or-Enhanced-Logics.md b/docs/New-or-Enhanced-Logics.md index 6eb539bd4..44840f8c0 100644 --- a/docs/New-or-Enhanced-Logics.md +++ b/docs/New-or-Enhanced-Logics.md @@ -1306,7 +1306,7 @@ DestroySound= ; Sound All new Warhead effects - Can be used with CellSpread and Ares' GenericWarhead superweapon where applicable. - Cannot be used with `MindControl.Permanent=yes` of Ares. -- Respect `Verses` where applicable unless `EffectsRequireVerses` is set to false. If target has an active shield, its armor type is used instead unless warhead can penetrate the shield. +- Respect `Verses` where applicable unless `EffectsRequireVerses` is set to `false`. If target has an active shield, its armor type is used instead unless warhead can penetrate the shield. ``` ### Break Mind Control on impact diff --git a/docs/Whats-New.md b/docs/Whats-New.md index a7c7b7a9c..5e3393700 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -454,6 +454,7 @@ New: - `FireOnce` infantry sequence reset toggle (by Starkku) - Assign Super Weapon cameo to any sidebar tab (by NetsuNegi) - Customizing effect of level lighting on air units (by Starkku) +- Warhead activation target health thresholds (by Kerbiter) Vanilla fixes: - Allow AI to repair structures built from base nodes/trigger action 125/SW delivery in single player missions (by Trsdy) diff --git a/src/Ext/WarheadType/Body.cpp b/src/Ext/WarheadType/Body.cpp index 281a42af6..33e2274cc 100644 --- a/src/Ext/WarheadType/Body.cpp +++ b/src/Ext/WarheadType/Body.cpp @@ -35,6 +35,14 @@ bool WarheadTypeExt::ExtData::CanAffectTarget(TechnoClass* pTarget, TechnoExt::E if (!pTarget) return false; + auto hp = pTarget->GetHealthPercentage(); + + if (hp < this->AffectsAbovePercent) + return false; + + if (this->AffectsBelowPercent < hp) + return false; + if (!this->EffectsRequireVerses) return true; @@ -266,6 +274,12 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) this->SuppressReflectDamage.Read(exINI, pSection, "SuppressReflectDamage"); this->SuppressReflectDamage_Types.Read(exINI, pSection, "SuppressReflectDamage.Types"); + this->AffectsAbovePercent.Read(exINI, pSection, "AffectsAbovePercent"); + this->AffectsBelowPercent.Read(exINI, pSection, "AffectsBelowPercent"); + + if (this->AffectsAbovePercent > this->AffectsBelowPercent) + Debug::Log("[Developer warning][%s] AffectsAbovePercent is bigger than AffectsBelowPercent, the warhead will never activate!\n", pSection); + // Convert.From & Convert.To TypeConvertGroup::Parse(this->Convert_Pairs, exINI, pSection, AffectedHouse::All); @@ -480,6 +494,9 @@ void WarheadTypeExt::ExtData::Serialize(T& Stm) .Process(this->SuppressReflectDamage) .Process(this->SuppressReflectDamage_Types) + .Process(this->AffectsAbovePercent) + .Process(this->AffectsBelowPercent) + .Process(this->InflictLocomotor) .Process(this->RemoveInflictedLocomotor) diff --git a/src/Ext/WarheadType/Body.h b/src/Ext/WarheadType/Body.h index 90b9968f7..86f9bc433 100644 --- a/src/Ext/WarheadType/Body.h +++ b/src/Ext/WarheadType/Body.h @@ -149,6 +149,9 @@ class WarheadTypeExt Valueable SuppressReflectDamage; ValueableVector SuppressReflectDamage_Types; + Valueable AffectsAbovePercent; + Valueable AffectsBelowPercent; + // Ares tags // http://ares-developers.github.io/Ares-docs/new/warheads/general.html Valueable AffectsEnemies; @@ -300,6 +303,9 @@ class WarheadTypeExt , SuppressReflectDamage { false } , SuppressReflectDamage_Types {} + , AffectsAbovePercent { 0.0 } + , AffectsBelowPercent { 1.0 } + , AffectsEnemies { true } , AffectsOwner {} , EffectsRequireVerses { true }