From ff3076203f6c375a7f6c42902b385b7839ffad65 Mon Sep 17 00:00:00 2001 From: Flugente Date: Sun, 13 Jun 2021 17:23:55 +0000 Subject: [PATCH] Fix: antimateriel bullet damage to structures often isn't properly applied git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9080 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Weapons.cpp | 3 ++- TileEngine/structure.cpp | 30 ++++++++++++++++-------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Tactical/Weapons.cpp b/Tactical/Weapons.cpp index 9a36853f..5aa7f48b 100644 --- a/Tactical/Weapons.cpp +++ b/Tactical/Weapons.cpp @@ -5633,7 +5633,8 @@ void StructureHit( INT32 iBullet, UINT16 usWeaponIndex, INT16 bWeaponStatus, UIN // Get Structure pointer and damage it! if ( usStructureID != INVALID_STRUCTURE_ID ) { - pStructure = FindStructureByID( sGridNo, usStructureID ); + // Flugente: if possible, take the gridno of the bullet. Otherwise we often get the issue that the calculated gridno is not the one where the structure is, leading to the structure being undamaged + pStructure = FindStructureByID( pBullet ? pBullet->sGridNo : sGridNo, usStructureID ); DamageStructure( pStructure, (UINT8)iImpact, STRUCTURE_DAMAGE_GUNFIRE, sGridNo, sXPos, sYPos, ubAttackerID, pBullet->usFlags & BULLET_FLAG_ANTIMATERIEL ? pBullet->iImpact - pBullet->iImpactReduction : 0 ); } diff --git a/TileEngine/structure.cpp b/TileEngine/structure.cpp index 2e4377c7..172f9707 100644 --- a/TileEngine/structure.cpp +++ b/TileEngine/structure.cpp @@ -1834,12 +1834,7 @@ BOOLEAN DamageStructure( STRUCTURE * pStructure, UINT8 ubDamage, UINT8 ubReason, { ubDamage = 0; } - - // Flugente: is there a wall at the loation we are damaging? - BOOLEAN fWallHere = FALSE; - if ( FindStructure( sGridNo, STRUCTURE_WALL ) ) - fWallHere = TRUE; - + // OK, Let's check our reason if ( ubReason == STRUCTURE_DAMAGE_GUNFIRE || ubReason == STRUCTURE_DAMAGE_VEHICLE_TRAUMA ) { @@ -1883,6 +1878,13 @@ BOOLEAN DamageStructure( STRUCTURE * pStructure, UINT8 ubDamage, UINT8 ubReason, } } + // Flugente: is there a wall at the loation we are damaging? + BOOLEAN fWallHere = FALSE; + if ( pStructure->fFlags & STRUCTURE_WALL ) + fWallHere = TRUE; + else if ( FindStructure( sGridNo, STRUCTURE_WALL ) ) + fWallHere = TRUE; + // Flugente: anti-material rifles can damage and even destroy structures, but some structures remain indestructible (otherwise the player might gain access to inaccessible spots) // the impact must be damaging enough, otherwise this won't have an effect if ( ubBaseArmour < 75 && ubBaseArmour > 0 && sAntiMaterialImpact > ubBaseArmour * 5 / 12 ) @@ -1894,20 +1896,20 @@ BOOLEAN DamageStructure( STRUCTURE * pStructure, UINT8 ubDamage, UINT8 ubReason, damage += max(1, 2 * sAntiMaterialImpact / ubBaseArmour); BOOLEAN recompile = FALSE; - ExplosiveDamageGridNo( sGridNo, damage, 10, &recompile, FALSE, -1, FALSE, ubOwner, 0 ); + ExplosiveDamageGridNo( pStructure->sGridNo, damage, 10, &recompile, FALSE, -1, FALSE, ubOwner, 0 ); //Since the structure is being damaged, set the map element that a structure is damaged - gpWorldLevelData[ sGridNo ].uiFlags |= MAPELEMENT_STRUCTURE_DAMAGED; + gpWorldLevelData[ pStructure->sGridNo ].uiFlags |= MAPELEMENT_STRUCTURE_DAMAGED; // if we destroyed something, the roof might get damaged too - // recompile = TRUE means that we destroyed soemthing + // recompile = TRUE means that we destroyed something if ( fWallHere && recompile ) { - HandleRoofDestruction( sGridNo, damage * 0.75f ); - HandleRoofDestruction( NewGridNo( sGridNo, DirectionInc( NORTH ) ), damage * 0.75f ); - HandleRoofDestruction( NewGridNo( sGridNo, DirectionInc( EAST ) ), damage * 0.75f ); - HandleRoofDestruction( NewGridNo( sGridNo, DirectionInc( WEST ) ), damage * 0.75f ); - HandleRoofDestruction( NewGridNo( sGridNo, DirectionInc( SOUTH ) ), damage * 0.75f ); + HandleRoofDestruction( pStructure->sGridNo, damage * 0.75f ); + HandleRoofDestruction( NewGridNo( pStructure->sGridNo, DirectionInc( NORTH ) ), damage * 0.75f ); + HandleRoofDestruction( NewGridNo( pStructure->sGridNo, DirectionInc( EAST ) ), damage * 0.75f ); + HandleRoofDestruction( NewGridNo( pStructure->sGridNo, DirectionInc( WEST ) ), damage * 0.75f ); + HandleRoofDestruction( NewGridNo( pStructure->sGridNo, DirectionInc( SOUTH ) ), damage * 0.75f ); } }