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] Attach effect when weapon fire #1482

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
11 changes: 10 additions & 1 deletion docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ This page describes all the engine features that are either new and introduced b
- `AttachEffect.InitialDelays` can be used to set the delays before first creating the effects on TechnoType. Defaults to 0 (immediately). Delay matching the position in `AttachTypes` is used for that type, or the last listed delay if not available.
- `AttachEffect.RecreationDelays` is used to determine if the effect can be recreated if it is removed completely (e.g `AttachEffect.RemoveTypes`), and if yes, how long this takes. Defaults to -1, meaning no recreation. Delay matching the position in `AttachTypes` is used for that type, or the last listed delay if not available.

- AttachEffectTypes can be attached to objects via Warheads using `AttachEffect.AttachTypes`.
- AttachEffectTypes can be attached to objects via Warheads or Weapons using `AttachEffect.AttachTypes`. When it is used on a Warhead, it will only be used when the warhead hits the target within the cellspread range. When it is used on a Weapon, it will directly act on the target at the instant after firing.
- `AttachEffect.DurationOverrides` can be used to override the default durations. Duration matching the position in `AttachTypes` is used for that type, or the last listed duration if not available.
- `AttachEffect.CumulativeRefreshAll` if set to true makes it so that trying to attach `Cumulative=true` effect to a target that already has `Cumulative.MaxCount` amount of effects will refresh duration of all attached effects of the same type instead of only the one with shortest remaining duration. If `AttachEffect.CumulativeRefreshAll.OnAttach` is also set to true, this refresh applies even if the target does not have maximum allowed amount of effects of same type.
- `AttachEffect.CumulativeRefreshSameSourceOnly` controls whether or not trying to apply `Cumulative=true` effect on target requires any existing effects of same type to come from same Warhead by same firer for them to be eligible for duration refresh.
Expand Down Expand Up @@ -139,6 +139,15 @@ OpenTopped.UseTransportRangeModifiers=false ; boolean
OpenTopped.CheckTransportDisableWeapons=false ; boolean

[SOMEWEAPON] ; WeaponType
AttachEffect.AttachTypes= ; List of AttachEffectTypes
AttachEffect.CumulativeRefreshAll=false ; boolean
AttachEffect.CumulativeRefreshAll.OnAttach=false ; boolean
AttachEffect.CumulativeRefreshSameSourceOnly=true ; boolean
AttachEffect.RemoveTypes= ; List of AttachEffectTypes
AttachEffect.RemoveGroups= ; comma-separated list of strings (group IDs)
AttachEffect.CumulativeRemoveMinCounts= ; integer - minimum required instance count (comma-separated) for cumulative types in order from first to last.
AttachEffect.CumulativeRemoveMaxCounts= ; integer - maximum removed instance count (comma-separated) for cumulative types in order from first to last.
AttachEffect.DurationOverrides= ; integer - duration overrides (comma-separated) for AttachTypes in order from first to last.
AttachEffect.RequiredTypes= ; List of AttachEffectTypes
AttachEffect.DisallowedTypes= ; List of AttachEffectTypes
AttachEffect.RequiredGroups= ; comma-separated list of strings (group IDs)
Expand Down
18 changes: 17 additions & 1 deletion src/Ext/Techno/Hooks.Firing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,10 @@ DEFINE_HOOK(0x6FCBE6, TechnoClass_CanFire_BridgeAAFix, 0x6)
DEFINE_HOOK(0x6FDDC0, TechnoClass_FireAt_DiscardAEOnFire, 0x6)
{
GET(TechnoClass* const, pThis, ESI);
GET(AbstractClass* const, pTarget, EDI);
GET(WeaponTypeClass* const, pWeapon, EBX);

auto const pExt = TechnoExt::ExtMap.Find(pThis);
const auto pExt = TechnoExt::ExtMap.Find(pThis);

if (pExt->AE.HasOnFireDiscardables)
{
Expand All @@ -426,6 +428,20 @@ DEFINE_HOOK(0x6FDDC0, TechnoClass_FireAt_DiscardAEOnFire, 0x6)
}
}

if (const auto pWeaponExt = WeaponTypeExt::ExtMap.Find(pWeapon))
{
if (pWeaponExt->AttachEffect_Enable)
{
if (const auto pTargetTechno = abstract_cast<TechnoClass*>(pTarget))
{
auto const& info = pWeaponExt->AttachEffects;
AttachEffectClass::Attach(pTargetTechno, pThis->Owner, pThis, pWeapon->Warhead, info);
Starkku marked this conversation as resolved.
Show resolved Hide resolved
AttachEffectClass::Detach(pTargetTechno, info);
AttachEffectClass::DetachByGroups(pTargetTechno, info);
}
}
}

return 0;
}

Expand Down
7 changes: 7 additions & 0 deletions src/Ext/WeaponType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ void WeaponTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->ExtraWarheads_FullDetonation.Read(exINI, pSection, "ExtraWarheads.FullDetonation");
this->AmbientDamage_Warhead.Read<true>(exINI, pSection, "AmbientDamage.Warhead");
this->AmbientDamage_IgnoreTarget.Read(exINI, pSection, "AmbientDamage.IgnoreTarget");

// AttachEffect
this->AttachEffects.LoadFromINI(pINI, pSection);
this->AttachEffect_Enable = (this->AttachEffects.AttachTypes.size() > 0 || this->AttachEffects.RemoveTypes.size() > 0 || this->AttachEffects.RemoveGroups.size() > 0);

this->AttachEffect_RequiredTypes.Read(exINI, pSection, "AttachEffect.RequiredTypes");
this->AttachEffect_DisallowedTypes.Read(exINI, pSection, "AttachEffect.DisallowedTypes");
exINI.ParseStringList(this->AttachEffect_RequiredGroups, pSection, "AttachEffect.RequiredGroups");
Expand Down Expand Up @@ -149,6 +154,8 @@ void WeaponTypeExt::ExtData::Serialize(T& Stm)
.Process(this->ExtraWarheads_FullDetonation)
.Process(this->AmbientDamage_Warhead)
.Process(this->AmbientDamage_IgnoreTarget)
.Process(this->AttachEffects)
.Process(this->AttachEffect_Enable)
.Process(this->AttachEffect_RequiredTypes)
.Process(this->AttachEffect_DisallowedTypes)
.Process(this->AttachEffect_RequiredGroups)
Expand Down
4 changes: 4 additions & 0 deletions src/Ext/WeaponType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class WeaponTypeExt
ValueableVector<bool> ExtraWarheads_FullDetonation;
Nullable<WarheadTypeClass*> AmbientDamage_Warhead;
Valueable<bool> AmbientDamage_IgnoreTarget;
AEAttachInfoTypeClass AttachEffects;
Valueable<bool> AttachEffect_Enable;
ValueableVector<AttachEffectTypeClass*> AttachEffect_RequiredTypes;
ValueableVector<AttachEffectTypeClass*> AttachEffect_DisallowedTypes;
std::vector<std::string> AttachEffect_RequiredGroups;
Expand Down Expand Up @@ -90,6 +92,8 @@ class WeaponTypeExt
, ExtraWarheads_FullDetonation {}
, AmbientDamage_Warhead {}
, AmbientDamage_IgnoreTarget { false }
, AttachEffects {}
, AttachEffect_Enable { false }
, AttachEffect_RequiredTypes {}
, AttachEffect_DisallowedTypes {}
, AttachEffect_RequiredGroups {}
Expand Down
Loading