From b8ea7df8c64e0f9ee617f43569aae06b923a8688 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Mon, 28 Oct 2024 12:26:15 +0100 Subject: [PATCH 1/5] Initial commit - Warheads can now modify ammo of the affected objects. In rulesmd.ini: [SOMEWARHEAD] ; Warhead AmmoModifier=0 ; integer --- CREDITS.md | 1 + docs/New-or-Enhanced-Logics.md | 10 ++++++++++ docs/Whats-New.md | 1 + src/Ext/WarheadType/Body.cpp | 5 +++++ src/Ext/WarheadType/Body.h | 5 +++++ src/Ext/WarheadType/Detonate.cpp | 29 +++++++++++++++++++++++++++++ 6 files changed, 51 insertions(+) diff --git a/CREDITS.md b/CREDITS.md index 84e88ce0fb..0d1f8f6ea7 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -134,6 +134,7 @@ This page lists all the individual contributions to the project by their author. - Customizable FLH when infantry is prone or deployed - Initial strength for cloned infantry - Map Events 604 & 605 for checking if a specific Techno enters in a cell + - Modify Ammo on impact - **Starkku**: - Misc. minor bugfixes & improvements - AI script actions: diff --git a/docs/New-or-Enhanced-Logics.md b/docs/New-or-Enhanced-Logics.md index 54b7b58d3c..d9ce4fc56a 100644 --- a/docs/New-or-Enhanced-Logics.md +++ b/docs/New-or-Enhanced-Logics.md @@ -1579,6 +1579,16 @@ LaunchSW.DisplayMoney.Houses=all ; Affected House Enumeration (none|owner/self| LaunchSW.DisplayMoney.Offset=0,0 ; X,Y, pixels relative to default ``` +### Modify Ammo on impact + +- Warheads can now modify ammo of the affected objects. + +In `rulesmd.ini`: +```ini +[SOMEWARHEAD] ; Warhead +AmmoModifier=0 ; integer +``` + ### Parasite removal - By default if unit takes negative damage from a Warhead (before `Verses` are calculated), any parasites infecting it are removed and deleted. This behaviour can now be customized to disable the removal for negative damage, or enable it for any arbitrary warhead. diff --git a/docs/Whats-New.md b/docs/Whats-New.md index a0265a6137..c23bebba25 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -466,6 +466,7 @@ New: - `Scorch` / `Flamer` fire animation customization (by Starkku) - Warheads parasite removal customization (by Starkku) - Allow infantry to use land sequences in water (by Starkku) +- Modify Ammo on impact (by FS-21) 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 5a5e2febef..e868969c8b 100644 --- a/src/Ext/WarheadType/Body.cpp +++ b/src/Ext/WarheadType/Body.cpp @@ -318,6 +318,7 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) || this->AttachEffects.AttachTypes.size() > 0 || this->AttachEffects.RemoveTypes.size() > 0 || this->AttachEffects.RemoveGroups.size() > 0 + || this->AmmoModifier ); char tempBuffer[32]; @@ -357,6 +358,8 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) else this->SpawnsCrate_Weights.push_back(weight); } + + this->AmmoModifier.Read(exINI, pSection, "AmmoModifier"); } template @@ -499,6 +502,8 @@ void WarheadTypeExt::ExtData::Serialize(T& Stm) .Process(this->PossibleCellSpreadDetonate) .Process(this->Reflected) .Process(this->DamageAreaTarget) + + .Process(this->AmmoModifier) ; } diff --git a/src/Ext/WarheadType/Body.h b/src/Ext/WarheadType/Body.h index b5331a9ada..9b69b444f9 100644 --- a/src/Ext/WarheadType/Body.h +++ b/src/Ext/WarheadType/Body.h @@ -167,6 +167,8 @@ class WarheadTypeExt bool PossibleCellSpreadDetonate; TechnoClass* DamageAreaTarget; + Valueable AmmoModifier; + private: Valueable Shield_Respawn_Rate_InMinutes; Valueable Shield_SelfHealing_Rate_InMinutes; @@ -316,6 +318,8 @@ class WarheadTypeExt , RemainingAnimCreationInterval { 0 } , PossibleCellSpreadDetonate { false } , DamageAreaTarget {} + + , AmmoModifier { 0 } { } void ApplyConvert(HouseClass* pHouse, TechnoClass* pTarget); @@ -350,6 +354,7 @@ class WarheadTypeExt void ApplyShieldModifiers(TechnoClass* pTarget, TechnoExt::ExtData* pTargetExt); void ApplyAttachEffects(TechnoClass* pTarget, HouseClass* pInvokerHouse, TechnoClass* pInvoker); double GetCritChance(TechnoClass* pFirer) const; + void ApplyAmmoModifier(TechnoClass* pTarget, HouseClass* pInvokerHouse, BulletExt::ExtData* pBulletExt = nullptr); }; class ExtContainer final : public Container diff --git a/src/Ext/WarheadType/Detonate.cpp b/src/Ext/WarheadType/Detonate.cpp index b0884359ce..55de9b66f3 100644 --- a/src/Ext/WarheadType/Detonate.cpp +++ b/src/Ext/WarheadType/Detonate.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -164,6 +165,9 @@ void WarheadTypeExt::ExtData::DetonateOnOneUnit(HouseClass* pHouse, TechnoClass* if (this->Crit_CurrentChance > 0.0 && (!this->Crit_SuppressWhenIntercepted || !bulletWasIntercepted)) this->ApplyCrit(pHouse, pTarget, pOwner, pTargetExt); + if (this->AmmoModifier != 0) + ApplyAmmoModifier(pTarget, pHouse, pBulletExt); + if (this->Convert_Pairs.size() > 0) this->ApplyConvert(pHouse, pTarget); @@ -501,3 +505,28 @@ double WarheadTypeExt::ExtData::GetCritChance(TechnoClass* pFirer) const return critChance + extraChance; } + +void WarheadTypeExt::ExtData::ApplyAmmoModifier(TechnoClass* pTarget, HouseClass* pInvokerHouse, BulletExt::ExtData* pBulletExt) +{ + if (!pTarget) + return; + + auto const pWeapon = pBulletExt ? pBulletExt->OwnerObject()->WeaponType : nullptr; + + if (pWeapon) + { + auto const pWeaponExt = WeaponTypeExt::ExtMap.Find(pWeapon); + + if (!EnumFunctions::IsTechnoEligible(pTarget, pWeaponExt->CanTarget) + || (pInvokerHouse && !EnumFunctions::CanTargetHouse(pWeaponExt->CanTargetHouses, pInvokerHouse, pTarget->Owner))) + { + return; + } + } + + int maxAmmo = pTarget->GetTechnoType()->Ammo; + int newCurrentAmmo = this->AmmoModifier + pTarget->Ammo; + + newCurrentAmmo = newCurrentAmmo < 0 ? 0 : newCurrentAmmo; + pTarget->Ammo = newCurrentAmmo > maxAmmo ? maxAmmo : newCurrentAmmo; +} From 8a1b4b1e3b8d118b9aa2cd7b5a57dcc4f2cafa90 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Mon, 28 Oct 2024 23:16:00 +0100 Subject: [PATCH 2/5] Add missing code --- src/Ext/WarheadType/Body.h | 2 +- src/Ext/WarheadType/Detonate.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Ext/WarheadType/Body.h b/src/Ext/WarheadType/Body.h index 9b69b444f9..8be228f7fd 100644 --- a/src/Ext/WarheadType/Body.h +++ b/src/Ext/WarheadType/Body.h @@ -347,7 +347,7 @@ class WarheadTypeExt void InterceptBullets(TechnoClass* pOwner, WeaponTypeClass* pWeapon, CoordStruct coords); DamageAreaResult DamageAreaWithTarget(const CoordStruct& coords, int damage, TechnoClass* pSource, WarheadTypeClass* pWH, bool affectsTiberium, HouseClass* pSourceHouse, TechnoClass* pTarget); private: - void DetonateOnOneUnit(HouseClass* pHouse, TechnoClass* pTarget, TechnoClass* pOwner = nullptr, bool bulletWasIntercepted = false); + void DetonateOnOneUnit(HouseClass* pHouse, TechnoClass* pTarget, TechnoClass* pOwner = nullptr, bool bulletWasIntercepted = false, BulletExt::ExtData* pBulletExt = nullptr); void ApplyRemoveDisguise(HouseClass* pHouse, TechnoClass* pTarget); void ApplyRemoveMindControl(TechnoClass* pTarget); void ApplyCrit(HouseClass* pHouse, TechnoClass* pTarget, TechnoClass* Owner, TechnoExt::ExtData* pTargetExt); diff --git a/src/Ext/WarheadType/Detonate.cpp b/src/Ext/WarheadType/Detonate.cpp index 55de9b66f3..552ffff1d5 100644 --- a/src/Ext/WarheadType/Detonate.cpp +++ b/src/Ext/WarheadType/Detonate.cpp @@ -124,7 +124,7 @@ void WarheadTypeExt::ExtData::Detonate(TechnoClass* pOwner, HouseClass* pHouse, if (cellSpread) { for (auto pTarget : Helpers::Alex::getCellSpreadItems(coords, cellSpread, true)) - this->DetonateOnOneUnit(pHouse, pTarget, pOwner, bulletWasIntercepted); + this->DetonateOnOneUnit(pHouse, pTarget, pOwner, bulletWasIntercepted, pBulletExt); } else if (pBullet) { @@ -133,7 +133,7 @@ void WarheadTypeExt::ExtData::Detonate(TechnoClass* pOwner, HouseClass* pHouse, // Starkku: We should only detonate on the target if the bullet, at the moment of detonation is within acceptable distance of the target. // Ares uses 64 leptons / quarter of a cell as a tolerance, so for sake of consistency we're gonna do the same here. if (pBullet->DistanceFrom(pTarget) < Unsorted::LeptonsPerCell / 4) - this->DetonateOnOneUnit(pHouse, pTarget, pOwner, bulletWasIntercepted); + this->DetonateOnOneUnit(pHouse, pTarget, pOwner, bulletWasIntercepted, pBulletExt); } } else if (this->DamageAreaTarget) @@ -144,7 +144,7 @@ void WarheadTypeExt::ExtData::Detonate(TechnoClass* pOwner, HouseClass* pHouse, } } -void WarheadTypeExt::ExtData::DetonateOnOneUnit(HouseClass* pHouse, TechnoClass* pTarget, TechnoClass* pOwner, bool bulletWasIntercepted) +void WarheadTypeExt::ExtData::DetonateOnOneUnit(HouseClass* pHouse, TechnoClass* pTarget, TechnoClass* pOwner, bool bulletWasIntercepted, BulletExt::ExtData* pBulletExt) { if (!pTarget || pTarget->InLimbo || !pTarget->IsAlive || !pTarget->Health || pTarget->IsSinking) return; From 97bdd8692f3f13a8ee2ebf8843a10e2cb1021546 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Fri, 30 May 2025 11:03:44 +0200 Subject: [PATCH 3/5] Applied feedback --- src/Ext/WarheadType/Detonate.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/Ext/WarheadType/Detonate.cpp b/src/Ext/WarheadType/Detonate.cpp index 47c48ba70d..86341446fd 100644 --- a/src/Ext/WarheadType/Detonate.cpp +++ b/src/Ext/WarheadType/Detonate.cpp @@ -656,22 +656,6 @@ double WarheadTypeExt::ExtData::GetCritChance(TechnoClass* pFirer) const void WarheadTypeExt::ExtData::ApplyAmmoModifier(TechnoClass* pTarget, HouseClass* pInvokerHouse, BulletExt::ExtData* pBulletExt) { - if (!pTarget) - return; - - auto const pWeapon = pBulletExt ? pBulletExt->OwnerObject()->WeaponType : nullptr; - - if (pWeapon) - { - auto const pWeaponExt = WeaponTypeExt::ExtMap.Find(pWeapon); - - if (!EnumFunctions::IsTechnoEligible(pTarget, pWeaponExt->CanTarget) - || (pInvokerHouse && !EnumFunctions::CanTargetHouse(pWeaponExt->CanTargetHouses, pInvokerHouse, pTarget->Owner))) - { - return; - } - } - int maxAmmo = pTarget->GetTechnoType()->Ammo; int newCurrentAmmo = this->AmmoModifier + pTarget->Ammo; From 54cba0dc3c789d0b01c08b923a54f7db646b7992 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Sun, 6 Jul 2025 17:37:18 +0200 Subject: [PATCH 4/5] Applied feedback Made requested changes: - Removed obsolete code not used anymore. - Renamed tag from AmmoModifier to Ammo --- YRpp | 2 +- src/Ext/WarheadType/Body.cpp | 6 +++--- src/Ext/WarheadType/Body.h | 8 ++++---- src/Ext/WarheadType/Detonate.cpp | 15 +++++++-------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/YRpp b/YRpp index 4ce57fba70..3e4db25bb7 160000 --- a/YRpp +++ b/YRpp @@ -1 +1 @@ -Subproject commit 4ce57fba70936c8fbda1d7eeafc53298174615a2 +Subproject commit 3e4db25bb775d44ec896392bcded614628452c2d diff --git a/src/Ext/WarheadType/Body.cpp b/src/Ext/WarheadType/Body.cpp index 56ae9aaa92..cf3a6e8560 100644 --- a/src/Ext/WarheadType/Body.cpp +++ b/src/Ext/WarheadType/Body.cpp @@ -329,7 +329,7 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) || this->AttachEffects.RemoveGroups.size() > 0 || this->BuildingSell || this->BuildingUndeploy - || this->AmmoModifier + || this->Ammo ); char tempBuffer[32]; @@ -370,7 +370,7 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) this->SpawnsCrate_Weights.push_back(weight); } - this->AmmoModifier.Read(exINI, pSection, "AmmoModifier"); + this->Ammo.Read(exINI, pSection, "Ammo"); } template @@ -544,7 +544,7 @@ void WarheadTypeExt::ExtData::Serialize(T& Stm) .Process(this->CanKill) - .Process(this->AmmoModifier) + .Process(this->Ammo) ; } diff --git a/src/Ext/WarheadType/Body.h b/src/Ext/WarheadType/Body.h index 6a8bb9f851..a3eaf99e1b 100644 --- a/src/Ext/WarheadType/Body.h +++ b/src/Ext/WarheadType/Body.h @@ -197,7 +197,7 @@ class WarheadTypeExt Valueable CanKill; - Valueable AmmoModifier; + Valueable Ammo; private: Valueable Shield_Respawn_Rate_InMinutes; @@ -379,7 +379,7 @@ class WarheadTypeExt , KillWeapon_Affects { AffectedTarget::All } , KillWeapon_OnFirer_Affects { AffectedTarget::All } - , AmmoModifier { 0 } + , Ammo { 0 } { } void ApplyConvert(HouseClass* pHouse, TechnoClass* pTarget); @@ -407,7 +407,7 @@ class WarheadTypeExt void InterceptBullets(TechnoClass* pOwner, WeaponTypeClass* pWeapon, CoordStruct coords); DamageAreaResult DamageAreaWithTarget(const CoordStruct& coords, int damage, TechnoClass* pSource, WarheadTypeClass* pWH, bool affectsTiberium, HouseClass* pSourceHouse, TechnoClass* pTarget); private: - void DetonateOnOneUnit(HouseClass* pHouse, TechnoClass* pTarget, TechnoClass* pOwner = nullptr, bool bulletWasIntercepted = false, BulletExt::ExtData* pBulletExt = nullptr); + void DetonateOnOneUnit(HouseClass* pHouse, TechnoClass* pTarget, TechnoClass* pOwner = nullptr, bool bulletWasIntercepted = false); void ApplyRemoveDisguise(HouseClass* pHouse, TechnoClass* pTarget); void ApplyRemoveMindControl(TechnoClass* pTarget); void ApplyCrit(HouseClass* pHouse, TechnoClass* pTarget, TechnoClass* Owner); @@ -415,7 +415,7 @@ class WarheadTypeExt void ApplyAttachEffects(TechnoClass* pTarget, HouseClass* pInvokerHouse, TechnoClass* pInvoker); void ApplyBuildingUndeploy(TechnoClass* pTarget); double GetCritChance(TechnoClass* pFirer) const; - void ApplyAmmoModifier(TechnoClass* pTarget, HouseClass* pInvokerHouse, BulletExt::ExtData* pBulletExt = nullptr); + void ApplyAmmoModifier(TechnoClass* pTarget); }; class ExtContainer final : public Container diff --git a/src/Ext/WarheadType/Detonate.cpp b/src/Ext/WarheadType/Detonate.cpp index 5eb04594fd..e2f7bfa253 100644 --- a/src/Ext/WarheadType/Detonate.cpp +++ b/src/Ext/WarheadType/Detonate.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -173,7 +172,7 @@ void WarheadTypeExt::ExtData::Detonate(TechnoClass* pOwner, HouseClass* pHouse, if (cellSpread) { for (auto pTarget : Helpers::Alex::getCellSpreadItems(coords, cellSpread, true)) - this->DetonateOnOneUnit(pHouse, pTarget, pOwner, bulletWasIntercepted, pBulletExt); + this->DetonateOnOneUnit(pHouse, pTarget, pOwner, bulletWasIntercepted); } else if (pBullet) { @@ -182,7 +181,7 @@ void WarheadTypeExt::ExtData::Detonate(TechnoClass* pOwner, HouseClass* pHouse, // Starkku: We should only detonate on the target if the bullet, at the moment of detonation is within acceptable distance of the target. // Ares uses 64 leptons / quarter of a cell as a tolerance, so for sake of consistency we're gonna do the same here. if (pBullet->DistanceFrom(pTarget) < Unsorted::LeptonsPerCell / 4) - this->DetonateOnOneUnit(pHouse, pTarget, pOwner, bulletWasIntercepted, pBulletExt); + this->DetonateOnOneUnit(pHouse, pTarget, pOwner, bulletWasIntercepted); } } else if (this->DamageAreaTarget) @@ -193,7 +192,7 @@ void WarheadTypeExt::ExtData::Detonate(TechnoClass* pOwner, HouseClass* pHouse, } } -void WarheadTypeExt::ExtData::DetonateOnOneUnit(HouseClass* pHouse, TechnoClass* pTarget, TechnoClass* pOwner, bool bulletWasIntercepted, BulletExt::ExtData* pBulletExt) +void WarheadTypeExt::ExtData::DetonateOnOneUnit(HouseClass* pHouse, TechnoClass* pTarget, TechnoClass* pOwner, bool bulletWasIntercepted) { if (!pTarget || pTarget->InLimbo || !pTarget->IsAlive || !pTarget->Health || pTarget->IsSinking || pTarget->BeingWarpedOut) return; @@ -212,8 +211,8 @@ void WarheadTypeExt::ExtData::DetonateOnOneUnit(HouseClass* pHouse, TechnoClass* if (this->Crit_CurrentChance > 0.0 && (!this->Crit_SuppressWhenIntercepted || !bulletWasIntercepted)) this->ApplyCrit(pHouse, pTarget, pOwner); - if (this->AmmoModifier != 0) - ApplyAmmoModifier(pTarget, pHouse, pBulletExt); + if (this->Ammo != 0) + this->ApplyAmmoModifier(pTarget); if (this->Convert_Pairs.size() > 0) this->ApplyConvert(pHouse, pTarget); @@ -655,10 +654,10 @@ double WarheadTypeExt::ExtData::GetCritChance(TechnoClass* pFirer) const return critChance + extraChance; } -void WarheadTypeExt::ExtData::ApplyAmmoModifier(TechnoClass* pTarget, HouseClass* pInvokerHouse, BulletExt::ExtData* pBulletExt) +void WarheadTypeExt::ExtData::ApplyAmmoModifier(TechnoClass* pTarget) { int maxAmmo = pTarget->GetTechnoType()->Ammo; - int newCurrentAmmo = this->AmmoModifier + pTarget->Ammo; + int newCurrentAmmo = this->Ammo + pTarget->Ammo; newCurrentAmmo = newCurrentAmmo < 0 ? 0 : newCurrentAmmo; pTarget->Ammo = newCurrentAmmo > maxAmmo ? maxAmmo : newCurrentAmmo; From 63b775d7d5c4cd7e37ad2b2846822d64ae692b8f Mon Sep 17 00:00:00 2001 From: FS-21 Date: Sun, 6 Jul 2025 17:42:42 +0200 Subject: [PATCH 5/5] Updated adoc --- docs/New-or-Enhanced-Logics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/New-or-Enhanced-Logics.md b/docs/New-or-Enhanced-Logics.md index 6fe70cf3b3..ce52443a4d 100644 --- a/docs/New-or-Enhanced-Logics.md +++ b/docs/New-or-Enhanced-Logics.md @@ -2132,7 +2132,7 @@ LaunchSW.DisplayMoney.Offset=0,0 ; X,Y, pixels relative to default In `rulesmd.ini`: ```ini [SOMEWARHEAD] ; Warhead -AmmoModifier=0 ; integer +Ammo=0 ; integer ``` ### Parasite removal