From 44577ee16421c3c8048d6572ee3147779518ee2e Mon Sep 17 00:00:00 2001 From: Flugente Date: Sun, 29 Jan 2017 14:00:18 +0000 Subject: [PATCH] - Fix: delayed explosions not possible in roofs - Fix: delayed explosions warnings not correctly drawn depending on height level - improved delayed explosion warning calculations git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8382 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Interface Control.cpp | 32 ++++++++++++++++++++++++++------ TileEngine/Explosion Control.cpp | 4 ++-- TileEngine/physics.cpp | 8 ++++---- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Tactical/Interface Control.cpp b/Tactical/Interface Control.cpp index 2e4971b4..906475e1 100644 --- a/Tactical/Interface Control.cpp +++ b/Tactical/Interface Control.cpp @@ -606,7 +606,7 @@ void DrawExplosionWarning( INT32 sGridno, INT8 usLevel, INT8 usDelay ) // ATE: If we are on a higher interface level, substract.... if ( usLevel == 1 ) sScreenY -= 50; - + if ( (GetJA2Clock( ) - uiTimeOfLastUpdate) > 30 ) { uiTimeOfLastUpdate = GetJA2Clock( ); @@ -622,6 +622,13 @@ void DrawExplosionWarning( INT32 sGridno, INT8 usLevel, INT8 usDelay ) INT16 numcircles = max( 1, 4 - usDelay); + // we determine the biggest rectangle we have to reserve + INT32 best_xl = 99999; + INT32 best_xr = 0; + INT32 best_yl = 99999; + INT32 best_yr = 0; + BOOLEAN sthdrawn = FALSE; + for ( int i = 0; i < numcircles; ++i ) { INT32 radiusvar = (updatecounter + i * periods / numcircles) % periods; @@ -636,29 +643,42 @@ void DrawExplosionWarning( INT32 sGridno, INT8 usLevel, INT8 usDelay ) INT32 xl = max( 0, sScreenX - radius_outer ); INT32 xr = min( gsVIEWPORT_END_X, sScreenX + radius_outer ); INT32 yl = max( 0, sScreenY - radius_outer ); - INT32 yh = min( gsVIEWPORT_WINDOW_END_Y, sScreenY + radius_outer ); + INT32 yr = min( gsVIEWPORT_WINDOW_END_Y, sScreenY + radius_outer ); + + best_xl = min( best_xl, xl ); + best_xr = max( best_xr, xr ); + best_yl = min( best_yl, yl ); + best_yr = max( best_yr, yr ); for ( INT32 x = xl; x <= xr; ++x ) { - for ( INT32 y = yl; y <= yh; ++y ) + FLOAT xdiffsquared = (FLOAT)((sScreenX - x) * (sScreenX - x)); + + for ( INT32 y = yl; y <= yr; ++y ) { - FLOAT diff = sqrt( (FLOAT)((sScreenX - x) * (sScreenX - x) + 2 * (sScreenY - y) * (sScreenY - y)) ); + FLOAT diff = sqrt( (FLOAT)(xdiffsquared + 2 * (sScreenY - y) * (sScreenY - y)) ); if ( radius_inner <= diff && diff <= radius_outer ) { PixelDraw( FALSE, x, y, usLineColor, pDestBuf ); + + sthdrawn = TRUE; } } } + } - iBack = RegisterBackgroundRect( BGND_FLAG_SINGLE, NULL, xl, yl, (INT16)(xr + 1), (INT16)(yh + 1) ); + // only do this once + if ( sthdrawn ) + { + iBack = RegisterBackgroundRect( BGND_FLAG_SINGLE, NULL, best_xl, best_yl, (INT16)(best_xr + 1), (INT16)(best_yr + 1) ); if ( iBack != -1 ) { SetBackgroundRectFilled( iBack ); } } - + UnLockVideoSurface( FRAME_BUFFER ); } diff --git a/TileEngine/Explosion Control.cpp b/TileEngine/Explosion Control.cpp index 25f8996b..d826a0bc 100644 --- a/TileEngine/Explosion Control.cpp +++ b/TileEngine/Explosion Control.cpp @@ -4254,7 +4254,7 @@ void HandleExplosionWarningAnimations( ) if ( (*pObj)[0]->data.misc.bDetonatorType == BOMB_TIMED && !((*pObj).fFlags & OBJECT_DISABLED_BOMB) && (*pObj)[0]->data.misc.bDelay ) { - DrawExplosionWarning( gWorldItems[gWorldBombs[uiWorldBombIndex].iItemIndex].sGridNo, gsInterfaceLevel, ( *pObj )[0]->data.misc.bDelay ); + DrawExplosionWarning( gWorldItems[gWorldBombs[uiWorldBombIndex].iItemIndex].sGridNo, gWorldItems[gWorldBombs[uiWorldBombIndex].iItemIndex].ubLevel, (*pObj)[0]->data.misc.bDelay ); } } } @@ -4279,7 +4279,7 @@ void HandleExplosionWarningAnimations( ) if ( (*pObj)[0]->data.misc.bDetonatorType == BOMB_TIMED && (*pObj)[0]->data.misc.bDelay ) { - DrawExplosionWarning( pSoldier->sGridNo, gsInterfaceLevel, ( *pObj )[0]->data.misc.bDelay ); + DrawExplosionWarning( pSoldier->sGridNo, pSoldier->pathing.bLevel, (*pObj)[0]->data.misc.bDelay ); break; } diff --git a/TileEngine/physics.cpp b/TileEngine/physics.cpp index a10576a6..cba16167 100644 --- a/TileEngine/physics.cpp +++ b/TileEngine/physics.cpp @@ -2643,11 +2643,11 @@ void HandleArmedObjectImpact( REAL_OBJECT *pObject ) } else { + // Flugente: explosions on the roof do work... // If we landed on anything other than the floor, always! go off... - if( sZ != 0 || - pObject->fInWater || - !fCanDelayExplosion || - fGoodStatus && !gGameExternalOptions.fDelayedGrenadeExplosion && !fDelayedExplosion ) + if ( pObject->fInWater || + !fCanDelayExplosion || + fGoodStatus && !gGameExternalOptions.fDelayedGrenadeExplosion && !fDelayedExplosion ) { fDoImpact = TRUE; fIsDud = false;