From 2b7f79db94d428968f719396259bd075d5c1fdc5 Mon Sep 17 00:00:00 2001 From: Wanne Date: Sun, 29 May 2011 16:08:27 +0000 Subject: [PATCH] - Fixed problems with merc faces when doing certain actions. This bug was introduced in revision: 4396 o Fixes endless loop when clicking on items with explosives and merc starts to talk o Fixes hidden merc faces o Fixes wrong merc faces (merc face instead of skull) when merc is dead git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@4456 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- SaveLoadGame.cpp | 10 ++++++--- Tactical/Faces.cpp | 16 ++++++++++++- Tactical/Interface Panels.cpp | 42 ++++++++++++++++++++++++++++++++--- Tactical/Items.cpp | 10 ++++++--- Tactical/faces.h | 2 +- 5 files changed, 69 insertions(+), 11 deletions(-) diff --git a/SaveLoadGame.cpp b/SaveLoadGame.cpp index 400296ae8..4b8af925a 100644 --- a/SaveLoadGame.cpp +++ b/SaveLoadGame.cpp @@ -5001,9 +5001,13 @@ BOOLEAN LoadSavedGame( int ubSavedGameID ) { if(MercPtrs[cnt]->ubID == cnt) { - SetCamoFace( MercPtrs[cnt] ); - DeleteSoldierFace( MercPtrs[cnt] );// remove face - MercPtrs[cnt]->iFaceIndex = InitSoldierFace( MercPtrs[cnt] );// create new face + // WANNE: We should only delete the face, if there was a camo we applied. + // This should fix the bug and crashes with missing faces + if (SetCamoFace( MercPtrs[cnt] )) + { + DeleteSoldierFace( MercPtrs[cnt] );// remove face + MercPtrs[cnt]->iFaceIndex = InitSoldierFace( MercPtrs[cnt] );// create new face + } } } diff --git a/Tactical/Faces.cpp b/Tactical/Faces.cpp index 2ba76bc30..aaff7ca34 100644 --- a/Tactical/Faces.cpp +++ b/Tactical/Faces.cpp @@ -724,7 +724,8 @@ void SetAutoFaceInActive(INT32 iFaceIndex ) pFace->fDisabled = TRUE; } -void SetCamoFace(SOLDIERTYPE * pSoldier) + +BOOLEAN SetCamoFace(SOLDIERTYPE * pSoldier) { INT8 worn = -1; INT8 applied = -1; @@ -754,8 +755,13 @@ void SetCamoFace(SOLDIERTYPE * pSoldier) applied = loop; } + + BOOLEAN isCamoFace = FALSE; + if(applied != -1 && worn != -1) { + isCamoFace = TRUE; + if(appliedCamo[applied] >= wornCamo[worn]) { if(applied == 0) @@ -766,9 +772,13 @@ void SetCamoFace(SOLDIERTYPE * pSoldier) gCamoFace[pSoldier->ubProfile].gDesertCamoface = TRUE; if(applied == 3) gCamoFace[pSoldier->ubProfile].gSnowCamoface = TRUE; + + return TRUE; } else { + isCamoFace = TRUE; + if(worn == 0) gCamoFace[pSoldier->ubProfile].gCamoface = TRUE; if(worn == 1) @@ -781,6 +791,8 @@ void SetCamoFace(SOLDIERTYPE * pSoldier) } else if(applied != -1 || worn != -1) { + isCamoFace = TRUE; + if(applied == 0 || worn == 0) gCamoFace[pSoldier->ubProfile].gCamoface = TRUE; if(applied == 1 || worn == 1) @@ -790,6 +802,8 @@ void SetCamoFace(SOLDIERTYPE * pSoldier) if(applied == 3 || worn == 3) gCamoFace[pSoldier->ubProfile].gSnowCamoface = TRUE; } + + return isCamoFace; } void SetAllAutoFacesInactive( ) diff --git a/Tactical/Interface Panels.cpp b/Tactical/Interface Panels.cpp index ac462d0c2..81164e60a 100644 --- a/Tactical/Interface Panels.cpp +++ b/Tactical/Interface Panels.cpp @@ -3166,12 +3166,48 @@ void SMInvClickCamoCallback( MOUSE_REGION * pRegion, INT32 iReason ) { if ( fGoodAPs ) { + // WANNE: Old method for applying camo + /* if (gGameExternalOptions.fShowCamouflageFaces == TRUE ) { - SetCamoFace( gpSMCurrentMerc ); - DeleteSoldierFace( gpSMCurrentMerc );// remove face - gpSMCurrentMerc->iFaceIndex = InitSoldierFace( gpSMCurrentMerc );// create new face + if ( gpSMCurrentMerc->bCamo > 0 ) + { + gCamoFace[gpSMCurrentMerc->ubProfile].gCamoface = TRUE; + DeleteSoldierFace( gpSMCurrentMerc );// remove face + gpSMCurrentMerc->iFaceIndex = InitSoldierFace( gpSMCurrentMerc );// create new face + } + if ( gpSMCurrentMerc->urbanCamo > 0 ) + { + gCamoFace[gpSMCurrentMerc->ubProfile].gUrbanCamoface = TRUE; + DeleteSoldierFace( gpSMCurrentMerc );// remove face + gpSMCurrentMerc->iFaceIndex = InitSoldierFace( gpSMCurrentMerc );// create new face + } + if ( gpSMCurrentMerc->desertCamo > 0) + { + gCamoFace[gpSMCurrentMerc->ubProfile].gDesertCamoface = TRUE; + DeleteSoldierFace( gpSMCurrentMerc );// remove face + gpSMCurrentMerc->iFaceIndex = InitSoldierFace( gpSMCurrentMerc );// create new face + } + if ( gpSMCurrentMerc->snowCamo > 0) + { + gCamoFace[gpSMCurrentMerc->ubProfile].gSnowCamoface = TRUE; + DeleteSoldierFace( gpSMCurrentMerc );// remove face + gpSMCurrentMerc->iFaceIndex = InitSoldierFace( gpSMCurrentMerc );// create new face + } } + */ + + // WANNE: We should only delete the face, if there was a camo we applied. + // This should fix the bug and crashes with missing faces + if (gGameExternalOptions.fShowCamouflageFaces == TRUE ) + { + if (SetCamoFace( gpSMCurrentMerc )) + { + DeleteSoldierFace( gpSMCurrentMerc );// remove face + gpSMCurrentMerc->iFaceIndex = InitSoldierFace( gpSMCurrentMerc );// create new face + } + } + // Dirty fInterfacePanelDirty = DIRTYLEVEL2; diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index 22220dab5..c51b19f46 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -10990,9 +10990,13 @@ void ApplyEquipmentBonuses(SOLDIERTYPE * pSoldier) //if ( pSoldier->bInSector) // pSoldier->CreateSoldierPalettes( ); - SetCamoFace( pSoldier ); - DeleteSoldierFace( pSoldier );// remove face - pSoldier->iFaceIndex = InitSoldierFace( pSoldier );// create new face + // WANNE: We should only delete the face, if there was a camo we applied. + // This should fix the bug and crashes with missing faces + if (SetCamoFace( pSoldier )) + { + DeleteSoldierFace( pSoldier );// remove face + pSoldier->iFaceIndex = InitSoldierFace( pSoldier );// create new face + } fInterfacePanelDirty = DIRTYLEVEL2; } diff --git a/Tactical/faces.h b/Tactical/faces.h index 09a36ea96..94632e029 100644 --- a/Tactical/faces.h +++ b/Tactical/faces.h @@ -252,7 +252,7 @@ void InternalShutupaYoFace( INT32 iFaceIndex, BOOLEAN fForce ); // If you still want the face in moemory but want to stop if from being displayed, or handled call void SetAutoFaceInActive( INT32 iFaceIndex ); -void SetCamoFace(SOLDIERTYPE * pSoldier); +BOOLEAN SetCamoFace(SOLDIERTYPE * pSoldier); // To set all currently allocated faces to either active or incactive, call these void SetAllAutoFacesInactive( );