Skip to content

Commit

Permalink
Fixed heal / repair weapons being unable to remove parasites from shi…
Browse files Browse the repository at this point in the history
…elded targets if the parent unit itself could not be healed / repaired
  • Loading branch information
Starkku committed Feb 12, 2024
1 parent 73a64e7 commit 159d5bb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ Phobos fixes:
- Fixed `DetonateOnAllMapObjects` behaving erratically or potentially crashing if it destroys buildings using Ares' advanced rubble (by Starkku)
- Fixed game crashing on loading save games if the saved game state had active radiation sites (by Starkku)
- Fixed a desync error caused by air/top layer sorting (by Starkku)
- Fixed heal / repair weapons being unable to remove parasites from shielded targets if they were unable to heal / repair the parent unit (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
6 changes: 4 additions & 2 deletions src/Ext/Techno/Hooks.Shield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ double __fastcall HealthRatio_Wrapper(TechnoClass* pTechno)
if (pShieldData->IsActive())
{
const auto pWH = EvaluateObjectTemp::PickedWeapon ? EvaluateObjectTemp::PickedWeapon->Warhead : nullptr;
const auto pFoot = abstract_cast<FootClass*>(pTechno);

if (!pShieldData->CanBePenetrated(pWH))
if (!pShieldData->CanBePenetrated(pWH) || ((pFoot && pFoot->ParasiteEatingMe)))
result = pExt->Shield->GetHealthRatio();
}
}
Expand Down Expand Up @@ -271,8 +272,9 @@ class AresScheme
if (pShieldData->IsActive())
{
const auto pWeapon = pThis->GetWeapon(nWeaponIndex)->WeaponType;
const auto pFoot = abstract_cast<FootClass*>(pObj);

if (pWeapon && !pShieldData->CanBePenetrated(pWeapon->Warhead))
if (pWeapon && (!pShieldData->CanBePenetrated(pWeapon->Warhead) || (pFoot && pFoot->ParasiteEatingMe)))
{
const auto shieldRatio = pExt->Shield->GetHealthRatio();

Expand Down
23 changes: 18 additions & 5 deletions src/New/Entity/ShieldClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,32 @@ bool ShieldClass::ShieldIsBrokenTEvent(ObjectClass* pAttached)

int ShieldClass::ReceiveDamage(args_ReceiveDamage* args)
{
const auto pWHExt = WarheadTypeExt::ExtMap.Find(args->WH);
if (!this->HP || this->Temporal || *args->Damage == 0)
return *args->Damage;

if (!this->HP || this->Temporal || *args->Damage == 0 ||
this->Techno->IsIronCurtained() || CanBePenetrated(pWHExt->OwnerObject()) ||
this->Techno->GetTechnoType()->Immune || TechnoExt::IsTypeImmune(this->Techno, args->Attacker))
// Handle a special case where parasite damages shield but not the unit and unit itself cannot be targeted by repair weapons.
if (*args->Damage < 0)
{
return *args->Damage;
if (auto const pFoot = abstract_cast<FootClass*>(this->Techno))
{
if (auto const pParasite = pFoot->ParasiteEatingMe)
{
// Remove parasite.
pParasite->ParasiteImUsing->SuppressionTimer.Start(50);
pParasite->ParasiteImUsing->ExitUnit();
}
}
}

if (this->Techno->IsIronCurtained() || CanBePenetrated(args->WH) || this->Techno->GetTechnoType()->Immune || TechnoExt::IsTypeImmune(this->Techno, args->Attacker))
return *args->Damage;

int nDamage = 0;
int shieldDamage = 0;
int healthDamage = 0;

const auto pWHExt = WarheadTypeExt::ExtMap.Find(args->WH);

if (pWHExt->CanTargetHouse(args->SourceHouse, this->Techno) && !args->WH->Temporal)
{
if (*args->Damage > 0)
Expand Down

0 comments on commit 159d5bb

Please sign in to comment.