Skip to content

bugfix: Prevent building crash damage from dealing damage to other objects#2723

Open
Stubbjax wants to merge 3 commits into
TheSuperHackers:mainfrom
Stubbjax:fix-dead-unit-building-crash-damage
Open

bugfix: Prevent building crash damage from dealing damage to other objects#2723
Stubbjax wants to merge 3 commits into
TheSuperHackers:mainfrom
Stubbjax:fix-dead-unit-building-crash-damage

Conversation

@Stubbjax
Copy link
Copy Markdown

This change prevents collateral damage caused by VehicleCrashesIntoBuildingWeapon when a dead vehicle collides with a building. This fix is supplemental to #2204.

Before

The Tank Hunters receive damage if the dead Helix collides with the Bunker

INJURED.mp4

After

The Tank Hunters no longer receive damage if the dead Helix collides with the Bunker

HEALTHY.mp4

@Stubbjax Stubbjax self-assigned this May 17, 2026
@Stubbjax Stubbjax added Bug Something is not working right, typically is user facing Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour NoRetail This fix or change is not applicable with Retail game compatibility labels May 17, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 17, 2026

Greptile Summary

This PR fixes collateral damage caused by VehicleCrashesIntoBuildingWeapon when a dead vehicle collides with a building, supplementing the earlier fix in #2204. Under RETAIL_COMPATIBLE_CRC the original createAndFireTempWeapon path (which fires an AoE explosion affecting nearby units) is preserved; outside retail mode a targeted DamageInfo is built and applied directly to the building only.

  • The new DamageInfo construction mirrors the pattern in Weapon.cpp::dealDamageInternal, setting m_damageType, m_deathType, m_sourceID, m_sourcePlayerMask, and m_amount — all required fields.
  • The null guard if (weaponTemplate != nullptr) addresses the previously flagged crash risk when the template is absent; FXList::doFXObj is a null-safe static wrapper so a missing FireFX is also safe.
  • Both the Generals/ and GeneralsMD/ copies receive identical changes, as expected for a parity fix.

Confidence Score: 5/5

Safe to merge — the change is narrow, correctly guards against a null weapon template, and applies damage only to the building using the same DamageInfo pattern used throughout the engine.

The fix is self-contained: it replaces an AoE weapon fire with a direct single-target damage call, uses the standard DamageInfo field set that matches Weapon.cpp, includes the null guard for the weapon template, and relies on the null-safe FXList::doFXObj static wrapper. No regressions are introduced in the retail path, which is left unchanged.

No files require special attention.

Important Files Changed

Filename Overview
Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp Adds non-retail path that applies crash damage directly to the struck building via DamageInfo rather than firing an AoE weapon; null guard and FX call are both safe.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp Zero Hour counterpart receives the identical change; no issues found.

Sequence Diagram

sequenceDiagram
    participant Physics as PhysicsBehavior::onCollide
    participant WT as WeaponTemplate
    participant WS as WeaponStore
    participant Bldg as Building (other)
    participant FX as FXList

    Note over Physics: Vehicle falls into structure

    alt RETAIL_COMPATIBLE_CRC
        Physics->>WS: createAndFireTempWeapon(template, obj, pos)
        WS->>Bldg: AoE explosion — damages building AND nearby units
    else Non-retail (this PR)
        Physics->>WT: getDamageType / getDeathType / getPrimaryDamage
        WT-->>Physics: damage values
        Note over Physics: weaponTemplate nullptr check
        Physics->>Bldg: attemptDamage(DamageInfo) — building only
        Physics->>FX: doFXObj(getFireFX, obj) — visual effect only
    end

    Physics->>Physics: destroyObject(obj)
Loading

Reviews (3): Last reviewed commit: "tweak: Assign source player mask" | Re-trigger Greptile

damageInfo.in.m_amount = weaponTemplate->getPrimaryDamage(nullBonus);

other->attemptDamage(&damageInfo);
FXList::doFXObj(weaponTemplate->getFireFX(obj->getVeterancyLevel()), obj);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #2204 it does not do this FX. Is that correct? Should not be consistent?

Copy link
Copy Markdown
Author

@Stubbjax Stubbjax May 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no effect on the non-building weapon, but I suppose I could check whether there is and fire it if so fire it there too.

#else
// TheSuperHackers @bugfix Stubbjax 17/05/2026 Prevent building collisions from dealing collateral damage to other objects.
const WeaponTemplate* weaponTemplate = getPhysicsBehaviorModuleData()->m_vehicleCrashesIntoBuildingWeaponTemplate;
if (weaponTemplate != nullptr)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #2204 it does not test the template for null. Is that correct? Should not be consistent?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll consolidate the logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working right, typically is user facing Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker NoRetail This fix or change is not applicable with Retail game compatibility ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants