From 6f24fb89fdc336e8c035d4e843530de255d0e20f Mon Sep 17 00:00:00 2001 From: Flugente Date: Mon, 28 Jun 2021 14:52:12 +0000 Subject: [PATCH] Fix: dragging a structure repaired it and removed all decals git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9120 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Handle Items.cpp | 27 ++++++++++++++++++++++++++- Tactical/Handle Items.h | 3 ++- Tactical/SkillMenu.cpp | 4 +++- Tactical/Soldier Control.cpp | 12 ++++++++++-- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Tactical/Handle Items.cpp b/Tactical/Handle Items.cpp index f11fc5d6..a1f0ec8b 100644 --- a/Tactical/Handle Items.cpp +++ b/Tactical/Handle Items.cpp @@ -7884,7 +7884,7 @@ BOOLEAN CanRemoveFortification( INT32 sGridNo, INT8 sLevel, UINT32 usStructureco return FALSE; } -BOOLEAN IsDragStructurePresent( INT32 sGridNo, INT8 sLevel, UINT32& arusTileType, UINT16& arusStructureNumber ) +BOOLEAN IsDragStructurePresent( INT32 sGridNo, INT8 sLevel, UINT32& arusTileType, UINT16& arusStructureNumber, UINT8& arusHitpoints, UINT8& arusDecalFlags ) { // needs to be a valid location if ( TileIsOutOfBounds( sGridNo ) ) @@ -7902,6 +7902,8 @@ BOOLEAN IsDragStructurePresent( INT32 sGridNo, INT8 sLevel, UINT32& arusTileType if ( GetTileType( pNode->usIndex, &arusTileType ) ) { arusStructureNumber = pStruct->pDBStructureRef->pDBStructure->usStructureNumber; + arusHitpoints = pStruct->ubHitPoints; + arusDecalFlags = pStruct->ubDecalFlag; // if tileset is from the current tileset, check that for ( int i = 0; i < STRUCTURE_MOVEPOSSIBLE_MAX; ++i ) @@ -8027,6 +8029,29 @@ BOOLEAN RemoveStructDrag( INT32 sGridNo, INT8 sLevel, UINT32 uiTileType ) return FALSE; } +void CorrectDragStructData( INT32 sGridNo, INT8 sLevel, UINT8 ausHitpoints, UINT8 ausDecalFlags ) +{ + // needs to be a valid location + if ( TileIsOutOfBounds( sGridNo ) ) + return; + + STRUCTURE* pStruct = GetTallestStructureOnGridnoDrag( sGridNo, sLevel ); + + if ( pStruct != NULL ) + { + pStruct->ubHitPoints = ausHitpoints; + pStruct->ubDecalFlag = ausDecalFlags; + + if ( pStruct->ubHitPoints < pStruct->pDBStructureRef->pDBStructure->ubHitPoints + || pStruct->ubDecalFlag & STRUCTURE_DECALFLAG_BLOOD ) + { + gpWorldLevelData[sGridNo].uiFlags & MAPELEMENT_STRUCTURE_DAMAGED; + + //SetRenderFlags( RENDER_FLAG_FULL ); + } + } +} + BOOLEAN RemoveFortification( INT32 sGridNo, INT8 sLevel, UINT32 usStructureconstructindex ) { // needs to be a valid location diff --git a/Tactical/Handle Items.h b/Tactical/Handle Items.h index 4474bb9d..1710ec93 100644 --- a/Tactical/Handle Items.h +++ b/Tactical/Handle Items.h @@ -290,9 +290,10 @@ BOOLEAN BuildFortification( INT32 sGridNo, INT8 sLevel, UINT8 usIndex, UINT32 us BOOLEAN CanRemoveFortification( INT32 sGridNo, INT8 sLevel, UINT32 usStructureconstructindex ); BOOLEAN RemoveFortification( INT32 sGridNo, INT8 sLevel, UINT32 usStructureconstructindex ); -BOOLEAN IsDragStructurePresent( INT32 sGridNo, INT8 sLevel, UINT32& arusTileType, UINT16& arusStructureNumber ); +BOOLEAN IsDragStructurePresent( INT32 sGridNo, INT8 sLevel, UINT32& arusTileType, UINT16& arusStructureNumber, UINT8& arusHitpoints, UINT8& arusDecalFlags ); void GetDragStructureXmlEntry( UINT32 ausTileType, UINT16 ausStructureNumber, int& arXmlVectorEntry ); BOOLEAN RemoveStructDrag( INT32 sGridNo, INT8 sLevel, UINT32 uiTileType ); +void CorrectDragStructData( INT32 sGridNo, INT8 sLevel, UINT8 ausHitpoints, UINT8 ausDecalFlags ); BOOLEAN BuildStructDrag( INT32 sGridNo, INT8 sLevel, UINT32 uiTileType, UINT8 usIndex, UINT16 usSoldierID ); void UpdateFortificationPossibleAmount(); diff --git a/Tactical/SkillMenu.cpp b/Tactical/SkillMenu.cpp index abb9ffb8..229f4f95 100644 --- a/Tactical/SkillMenu.cpp +++ b/Tactical/SkillMenu.cpp @@ -853,8 +853,10 @@ DragSelection::Setup( UINT32 aVal ) UINT32 tiletype; UINT16 structurenumber; + UINT8 hitpoints; + UINT8 decalflag; if ( pSoldier->CanDragStructure( sTempGridNo ) - && IsDragStructurePresent( sTempGridNo, pSoldier->pathing.bLevel, tiletype, structurenumber ) ) + && IsDragStructurePresent( sTempGridNo, pSoldier->pathing.bLevel, tiletype, structurenumber, hitpoints, decalflag ) ) { int xmlentry; GetDragStructureXmlEntry( tiletype, structurenumber, xmlentry ); diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index a096577d..03651083 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -11864,11 +11864,17 @@ void SOLDIERTYPE::MoveMerc( FLOAT dMovementChange, FLOAT dAngle, BOOLEAN fCheckR bool success = false; UINT32 arusTileType; UINT16 arusStructureNumber; - if ( IsDragStructurePresent( this->sDragGridNo, this->pathing.bLevel, arusTileType, arusStructureNumber ) ) + UINT8 hitpoints; + UINT8 decalflag; + + if ( IsDragStructurePresent( this->sDragGridNo, this->pathing.bLevel, arusTileType, arusStructureNumber, hitpoints, decalflag ) ) { // add if ( BuildStructDrag( sOldGridNo, gsInterfaceLevel, arusTileType, arusStructureNumber, this->ubID ) ) { + // as structures might be damaged/have decals, make sure to keep the old values + CorrectDragStructData( sOldGridNo, (INT8)gsInterfaceLevel, hitpoints, decalflag ); + // remove RemoveStructDrag( this->sDragGridNo, (INT8)gsInterfaceLevel, arusTileType ); @@ -20698,7 +20704,9 @@ BOOLEAN SOLDIERTYPE::CanDragStructure( INT32 sGridNo ) UINT32 tiletype; UINT16 structurenumber; - if ( !IsDragStructurePresent( sGridNo, this->pathing.bLevel, tiletype, structurenumber ) ) + UINT8 hitpoints; + UINT8 decalflag; + if ( !IsDragStructurePresent( sGridNo, this->pathing.bLevel, tiletype, structurenumber, hitpoints, decalflag ) ) return FALSE; // Now we need to check if there is not a wall between the two middle tiles