Skip to content

Commit

Permalink
Couple of Warhead detonation-related bugfixes
Browse files Browse the repository at this point in the history
- Phobos Warhead effects on zero-CellSpread Warheads no longer apply to target if projectile detonates prematurely, far-away from target
- ExtraWarheads now snaps on target of the original projectile where applicable
  • Loading branch information
Starkku committed Jun 2, 2024
1 parent 993bf93 commit c1736fe
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ Phobos fixes:
- Fixed `Inviso=true` interceptor projectiles applying damage on interceptable, armor type-having projectiles twice (by Starkku)
- Fixed `AutoDeath` causing crashes when used to kill a parasite unit inside an another unit (by Starkku)
- Phobos Warhead effects combined with `CellSpread` now correctly apply to buildings if any of the foundation cells are hit (by Starkku)
- Phobos Warhead effects on zero-`CellSpread` Warheads no longer apply to target if projectile detonates prematurely, far-away from target (by Starkku)
Fixes / interactions with other extensions:
- All forms of type conversion (including Ares') now correctly update `OpenTopped` state of passengers in transport that is converted (by Starkku)
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/Bullet/Hooks.DetonateLogics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ DEFINE_HOOK(0x46A290, BulletClass_Logics_Extras, 0x5)
detonate = pWeaponExt->ExtraWarheads_DetonationChances[size - 1] >= ScenarioClass::Instance->Random.RandomDouble();

if (detonate)
WarheadTypeExt::DetonateAt(pWH, *coords, pThis->Owner, damage, pOwner);
WarheadTypeExt::DetonateAt(pWH, *coords, pThis->Owner, damage, pOwner, pThis->Target);
}
}

Expand Down
13 changes: 3 additions & 10 deletions src/Ext/WarheadType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,16 @@ bool WarheadTypeExt::ExtData::CanAffectTarget(TechnoClass* pTarget, TechnoExt::E
return GeneralUtils::GetWarheadVersusArmor(this->OwnerObject(), armorType) != 0.0;
}

namespace DetonateTemp
{
AbstractClass* pTarget = nullptr;
}

void WarheadTypeExt::DetonateAt(WarheadTypeClass* pThis, AbstractClass* pTarget, TechnoClass* pOwner, int damage, HouseClass* pFiringHouse)
{
DetonateTemp::pTarget = pTarget;
WarheadTypeExt::DetonateAt(pThis, pTarget->GetCoords(), pOwner, damage, pFiringHouse);
DetonateTemp::pTarget = nullptr;
WarheadTypeExt::DetonateAt(pThis, pTarget->GetCoords(), pOwner, damage, pFiringHouse, pTarget);
}

void WarheadTypeExt::DetonateAt(WarheadTypeClass* pThis, const CoordStruct& coords, TechnoClass* pOwner, int damage, HouseClass* pFiringHouse)
void WarheadTypeExt::DetonateAt(WarheadTypeClass* pThis, const CoordStruct& coords, TechnoClass* pOwner, int damage, HouseClass* pFiringHouse, AbstractClass* pTarget)
{
BulletTypeClass* pType = BulletTypeExt::GetDefaultBulletType();

if (BulletClass* pBullet = pType->CreateBullet(DetonateTemp::pTarget, pOwner,
if (BulletClass* pBullet = pType->CreateBullet(pTarget, pOwner,
damage, pThis, 0, pThis->Bright))
{
if (pFiringHouse)
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/WarheadType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,5 @@ class WarheadTypeExt
static bool SaveGlobals(PhobosStreamWriter& Stm);

static void DetonateAt(WarheadTypeClass* pThis, AbstractClass* pTarget, TechnoClass* pOwner, int damage, HouseClass* pFiringHouse = nullptr);
static void DetonateAt(WarheadTypeClass* pThis, const CoordStruct& coords, TechnoClass* pOwner, int damage, HouseClass* pFiringHouse = nullptr);
static void DetonateAt(WarheadTypeClass* pThis, const CoordStruct& coords, TechnoClass* pOwner, int damage, HouseClass* pFiringHouse = nullptr, AbstractClass* pTarget = nullptr);
};
7 changes: 6 additions & 1 deletion src/Ext/WarheadType/Detonate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ void WarheadTypeExt::ExtData::Detonate(TechnoClass* pOwner, HouseClass* pHouse,
else if (pBullet)
{
if (auto pTarget = abstract_cast<TechnoClass*>(pBullet->Target))
this->DetonateOnOneUnit(pHouse, pTarget, pOwner, bulletWasIntercepted);
{
// 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);
}
}
}
}
Expand Down

0 comments on commit c1736fe

Please sign in to comment.