Skip to content

Commit 69146c7

Browse files
committed
KillWeapon
1 parent 8c1d9d1 commit 69146c7

File tree

5 files changed

+86
-18
lines changed

5 files changed

+86
-18
lines changed

docs/New-or-Enhanced-Logics.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ This page describes all the engine features that are either new and introduced b
6767
- On TechnoTypes with `OpenTopped=true`, `OpenTopped.UseTransportRangeModifiers` can be set to true to make passengers firing out use the transport's active range bonuses instead.
6868
- `Crit.Multiplier` and `Crit.ExtraChance` can be used to multiply the [critical hit](#chance-based-extra-damage-or-warhead-detonation--critical-hits) chance or grant a fixed bonus to it for the object the effect is attached to, respectively.
6969
- `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.
70+
- `KillWeapon` will be fired at the target TechnoType's location once it's killed by the attached object.
71+
- `KillWeapon.OnFirer` will be fired at the attacker's location once the target TechnoType is killed the attached object. If `KillWeapon.OnFirer.RealLaunch` set to true, the weapon will be fired through a real projectile from the TechnoType to the attached object.
72+
- `KillWeapon.AffectsHouses` / `KillWeapon.OnFirer.AffectsHouses` and `KillWeapon.Affects` / `KillWeapon.OnFirer.Affects` can be used to filter which houses targets can belong to and which types of targets are be considered valid for `KillWeapon` and `KillWeapon.OnFirer` respectively.
73+
- If a TechnoType has `SuppressKillWeapons` set to true, it will not trigger `KillWeapon` or `KillWeapon.OnFirer` upon being killed. `SuppressKillWeapons.Types` can be used to list WeaponTypes affected by this, if none are listed all WeaponTypes are affected.
7074
- `RevengeWeapon` can be used to temporarily grant the specified weapon as a [revenge weapon](#revenge-weapon) for the attached object.
7175
- `RevengeWeapon.AffectsHouses` customizes which houses can trigger the revenge weapon.
7276
- If `RevengeWeapon.RealLaunch` set to true, the weapon will be fired through a real projectile from the TechnoType to the killer.

src/Ext/Bullet/Body.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ void BulletExt::ExtData::InitializeLaserTrails()
153153
void BulletExt::ExtData::ApplyExtraWarheads(const std::vector<WarheadTypeClass*>& exWH, const std::vector<int>& exWHOverrides, const std::vector<double>& exWHChances, const std::vector<bool>& exWHFull, const std::vector<bool>& exWHOwner, const CoordStruct& coords, HouseClass* pOwner, TechnoClass* pInvoker)
154154
{
155155
auto const pThis = this->OwnerObject();
156-
auto const pTarget = abstract_cast<TechnoClass*>(pThis->Target);
157156
const int defaultDamage = pThis->WeaponType ? pThis->WeaponType->Damage : 0;
158157

159158
for (size_t i = 0; i < exWH.size(); i++)
160159
{
161160
auto const pWH = exWH[i];
162161
auto const pWHExt = WarheadTypeExt::ExtMap.Find(pWH);
162+
auto const pTarget = abstract_cast<TechnoClass*>(pThis->Target); // must be check in every loop
163163

164164
if (pTarget && !pWHExt->IsHealthInThreshold(pTarget))
165165
continue;

src/Ext/Techno/WeaponHelpers.cpp

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -239,25 +239,60 @@ void TechnoExt::ApplyKillWeapon(TechnoClass* pThis, TechnoClass* pSource, Warhea
239239
auto const pWHExt = WarheadTypeExt::ExtMap.Find(pWH);
240240
const bool hasFilters = pTypeExt->SuppressKillWeapons_Types.size() > 0;
241241

242-
// KillWeapon can be triggered without the source
243-
if (pWHExt->KillWeapon && (!pSource || (EnumFunctions::CanTargetHouse(pWHExt->KillWeapon_AffectsHouses, pSource->Owner, pThis->Owner)
244-
&& EnumFunctions::IsTechnoEligible(pThis, pWHExt->KillWeapon_Affects))))
245-
{
246-
if (!pTypeExt->SuppressKillWeapons || (hasFilters && !pTypeExt->SuppressKillWeapons_Types.Contains(pWHExt->KillWeapon)))
247-
WeaponTypeExt::DetonateAt(pWHExt->KillWeapon, pThis, pSource);
248-
}
249-
250-
// KillWeapon.OnFirer must have a source
251-
if (pWHExt->KillWeapon_OnFirer && pSource && EnumFunctions::CanTargetHouse(pWHExt->KillWeapon_OnFirer_AffectsHouses, pSource->Owner, pThis->Owner)
252-
&& EnumFunctions::IsTechnoEligible(pThis, pWHExt->KillWeapon_OnFirer_Affects))
253-
{
254-
if (!pTypeExt->SuppressKillWeapons || (hasFilters && !pTypeExt->SuppressKillWeapons_Types.Contains(pWHExt->KillWeapon_OnFirer)))
242+
auto tryKillWeapon = [&](auto pWeapon, AffectedHouse affectsHouses, AffectedTarget affects, bool realLaunch, bool onFirer)
255243
{
256-
if (pWHExt->KillWeapon_OnFirer_RealLaunch)
257-
RealLaunch(pWHExt->KillWeapon_OnFirer, pSource, pSource, true, pThis);
244+
if (!pWeapon)
245+
return;
246+
247+
if (onFirer)
248+
{
249+
if (!pSource)
250+
return;
251+
252+
if (!(EnumFunctions::CanTargetHouse(affectsHouses, pSource->Owner, pThis->Owner)
253+
&& EnumFunctions::IsTechnoEligible(pThis, affects)))
254+
{
255+
return;
256+
}
257+
}
258258
else
259-
WeaponTypeExt::DetonateAt(pWHExt->KillWeapon_OnFirer, pSource, pSource);
260-
}
259+
{
260+
if (pSource && !(EnumFunctions::CanTargetHouse(affectsHouses, pSource->Owner, pThis->Owner)
261+
&& EnumFunctions::IsTechnoEligible(pThis, affects)))
262+
{
263+
return;
264+
}
265+
}
266+
267+
if (pTypeExt->SuppressKillWeapons && (!hasFilters || pTypeExt->SuppressKillWeapons_Types.Contains(pWeapon)))
268+
return;
269+
270+
if (onFirer)
271+
{
272+
if (realLaunch)
273+
RealLaunch(pWeapon, pSource, pSource, true, pThis);
274+
else
275+
WeaponTypeExt::DetonateAt(pWeapon, pSource, pSource);
276+
}
277+
else
278+
{
279+
WeaponTypeExt::DetonateAt(pWeapon, pThis, pSource);
280+
}
281+
};
282+
283+
tryKillWeapon(pWHExt->KillWeapon, pWHExt->KillWeapon_AffectsHouses, pWHExt->KillWeapon_Affects, false, false);
284+
tryKillWeapon(pWHExt->KillWeapon_OnFirer, pWHExt->KillWeapon_OnFirer_AffectsHouses, pWHExt->KillWeapon_OnFirer_Affects, pWHExt->KillWeapon_OnFirer_RealLaunch, true);
285+
286+
auto const pExt = TechnoExt::ExtMap.Find(pSource);
287+
288+
for (auto const& attachEffect : pExt->AttachedEffects)
289+
{
290+
if (!attachEffect->IsActive())
291+
continue;
292+
293+
auto const pType = attachEffect->GetType();
294+
tryKillWeapon(pType->KillWeapon, pType->KillWeapon_AffectsHouses, pType->KillWeapon_Affects, false, false);
295+
tryKillWeapon(pType->KillWeapon_OnFirer, pType->KillWeapon_OnFirer_AffectsHouses, pType->KillWeapon_OnFirer_Affects, pType->KillWeapon_OnFirer_RealLaunch, true);
261296
}
262297
}
263298

src/New/Type/AttachEffectTypeClass.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ void AttachEffectTypeClass::LoadFromINI(CCINIClass* pINI)
171171
this->Crit_AllowWarheads.Read(exINI, pSection, "Crit.AllowWarheads");
172172
this->Crit_DisallowWarheads.Read(exINI, pSection, "Crit.DisallowWarheads");
173173

174+
this->KillWeapon.Read(exINI, pSection, "KillWeapon");
175+
this->KillWeapon_OnFirer.Read(exINI, pSection, "KillWeapon.OnFirer");
176+
this->KillWeapon_AffectsHouses.Read(exINI, pSection, "KillWeapon.AffectsHouses");
177+
this->KillWeapon_OnFirer_AffectsHouses.Read(exINI, pSection, "KillWeapon.OnFirer.AffectsHouses");
178+
this->KillWeapon_Affects.Read(exINI, pSection, "KillWeapon.Affects");
179+
this->KillWeapon_OnFirer_Affects.Read(exINI, pSection, "KillWeapon.OnFirer.Affects");
180+
this->KillWeapon_OnFirer_RealLaunch.Read(exINI, pSection, "KillWeapon.OnFirer.RealLaunch");
181+
174182
this->RevengeWeapon.Read<true>(exINI, pSection, "RevengeWeapon");
175183
this->RevengeWeapon_AffectsHouses.Read(exINI, pSection, "RevengeWeapon.AffectsHouses");
176184
this->RevengeWeapon_RealLaunch.Read(exINI, pSection, "RevengeWeapon.RealLaunch");
@@ -264,6 +272,13 @@ void AttachEffectTypeClass::Serialize(T& Stm)
264272
.Process(this->Crit_ExtraChance)
265273
.Process(this->Crit_AllowWarheads)
266274
.Process(this->Crit_DisallowWarheads)
275+
.Process(this->KillWeapon)
276+
.Process(this->KillWeapon_OnFirer)
277+
.Process(this->KillWeapon_AffectsHouses)
278+
.Process(this->KillWeapon_OnFirer_AffectsHouses)
279+
.Process(this->KillWeapon_Affects)
280+
.Process(this->KillWeapon_OnFirer_Affects)
281+
.Process(this->KillWeapon_OnFirer_RealLaunch)
267282
.Process(this->RevengeWeapon)
268283
.Process(this->RevengeWeapon_AffectsHouses)
269284
.Process(this->RevengeWeapon_RealLaunch)

src/New/Type/AttachEffectTypeClass.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ class AttachEffectTypeClass final : public Enumerable<AttachEffectTypeClass>
106106
Valueable<double> Crit_ExtraChance;
107107
ValueableVector<WarheadTypeClass*> Crit_AllowWarheads;
108108
ValueableVector<WarheadTypeClass*> Crit_DisallowWarheads;
109+
Valueable<WeaponTypeClass*> KillWeapon;
110+
Valueable<WeaponTypeClass*> KillWeapon_OnFirer;
111+
Valueable<AffectedHouse> KillWeapon_AffectsHouses;
112+
Valueable<AffectedHouse> KillWeapon_OnFirer_AffectsHouses;
113+
Valueable<AffectedTarget> KillWeapon_Affects;
114+
Valueable<AffectedTarget> KillWeapon_OnFirer_Affects;
115+
Valueable<bool> KillWeapon_OnFirer_RealLaunch;
109116
Valueable<WeaponTypeClass*> RevengeWeapon;
110117
Valueable<AffectedHouse> RevengeWeapon_AffectsHouses;
111118
Valueable<bool> RevengeWeapon_RealLaunch;
@@ -191,6 +198,13 @@ class AttachEffectTypeClass final : public Enumerable<AttachEffectTypeClass>
191198
, Crit_ExtraChance { 0.0 }
192199
, Crit_AllowWarheads {}
193200
, Crit_DisallowWarheads {}
201+
, KillWeapon {}
202+
, KillWeapon_OnFirer {}
203+
, KillWeapon_AffectsHouses { AffectedHouse::All }
204+
, KillWeapon_OnFirer_AffectsHouses { AffectedHouse::All }
205+
, KillWeapon_Affects { AffectedTarget::All }
206+
, KillWeapon_OnFirer_Affects { AffectedTarget::All }
207+
, KillWeapon_OnFirer_RealLaunch { false }
194208
, RevengeWeapon {}
195209
, RevengeWeapon_AffectsHouses { AffectedHouse::All }
196210
, RevengeWeapon_RealLaunch { false }

0 commit comments

Comments
 (0)