Fix AI soldiers losing ready stance while deciding next move

Fix LUA crashing when game shuts down (caused by incomplete merge)


git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1541 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Overhaul
2007-10-21 05:43:45 +00:00
parent 13288fd750
commit b0b9d14154
12 changed files with 44 additions and 36 deletions
+4 -4
View File
@@ -5491,7 +5491,7 @@ void MakeSureToolKitIsInHand( SOLDIERTYPE *pSoldier )
{ {
if( Item[pSoldier -> inv[ bPocket ].usItem].toolkit ) if( Item[pSoldier -> inv[ bPocket ].usItem].toolkit )
{ {
SwapObjs( pSoldier, HANDPOS, bPocket ); SwapObjs( pSoldier, HANDPOS, bPocket, TRUE );
break; break;
} }
} }
@@ -5519,7 +5519,7 @@ BOOLEAN MakeSureMedKitIsInHand( SOLDIERTYPE *pSoldier )
if ( Item[pSoldier -> inv[ bPocket ].usItem].medicalkit ) if ( Item[pSoldier -> inv[ bPocket ].usItem].medicalkit )
{ {
fCharacterInfoPanelDirty = TRUE; fCharacterInfoPanelDirty = TRUE;
SwapObjs( pSoldier, HANDPOS, bPocket ); SwapObjs( pSoldier, HANDPOS, bPocket, TRUE );
return(TRUE); return(TRUE);
} }
} }
@@ -5539,14 +5539,14 @@ BOOLEAN MakeSureMedKitIsInHand( SOLDIERTYPE *pSoldier )
if( ( Item[ pSoldier -> inv[ HANDPOS ].usItem ].twohanded ) && ( bPocket >= SMALLPOCK1POS ) ) if( ( Item[ pSoldier -> inv[ HANDPOS ].usItem ].twohanded ) && ( bPocket >= SMALLPOCK1POS ) )
{ {
// first move from hand to second hand // first move from hand to second hand
SwapObjs( pSoldier, HANDPOS, SECONDHANDPOS ); SwapObjs( pSoldier, HANDPOS, SECONDHANDPOS, TRUE );
// dirty mapscreen and squad panels // dirty mapscreen and squad panels
fCharacterInfoPanelDirty = TRUE; fCharacterInfoPanelDirty = TRUE;
fInterfacePanelDirty = DIRTYLEVEL2; fInterfacePanelDirty = DIRTYLEVEL2;
} }
SwapObjs( pSoldier, HANDPOS, bPocket ); SwapObjs( pSoldier, HANDPOS, bPocket, TRUE );
return(TRUE); return(TRUE);
+1 -1
View File
@@ -463,7 +463,7 @@ void AutoBandage( BOOLEAN fStart )
if ( pSoldier->bSlotItemTakenFrom != NO_SLOT ) if ( pSoldier->bSlotItemTakenFrom != NO_SLOT )
{ {
// swap our old hand item back to the main hand // swap our old hand item back to the main hand
SwapObjs( pSoldier, HANDPOS, pSoldier->bSlotItemTakenFrom ); SwapObjs( pSoldier, HANDPOS, pSoldier->bSlotItemTakenFrom, TRUE );
} }
// ATE: Make everyone stand up! // ATE: Make everyone stand up!
+3 -3
View File
@@ -1196,7 +1196,7 @@ BOOLEAN HandleTalkingMenuEscape( BOOLEAN fCanDelete , BOOLEAN fFromEscKey )
void HandleTalkingMenuBackspace( void ) void HandleTalkingMenuBackspace( void )
{ {
FACETYPE *pFace; FACETYPE *pFace;
BOOLEAN fTalking = FALSE; //BOOLEAN fTalking = FALSE;
if ( !gfInTalkPanel ) if ( !gfInTalkPanel )
{ {
@@ -2225,7 +2225,7 @@ void HandleNPCDoAction( UINT8 ubTargetNPC, UINT16 usActionCode, UINT8 ubQuoteNum
bItemIn = FindAIUsableObjClass( pSoldier, IC_GUN ); bItemIn = FindAIUsableObjClass( pSoldier, IC_GUN );
if (bItemIn != NO_SLOT && bItemIn != HANDPOS) if (bItemIn != NO_SLOT && bItemIn != HANDPOS)
{ {
SwapObjs( pSoldier, HANDPOS, bItemIn ); SwapObjs( pSoldier, HANDPOS, bItemIn, TRUE );
sGridNo = pSoldier->sGridNo + DirectionInc( pSoldier->ubDirection ); sGridNo = pSoldier->sGridNo + DirectionInc( pSoldier->ubDirection );
SoldierReadyWeapon( pSoldier, (INT16) (sGridNo % WORLD_COLS), (INT16) (sGridNo / WORLD_COLS), FALSE ); SoldierReadyWeapon( pSoldier, (INT16) (sGridNo % WORLD_COLS), (INT16) (sGridNo / WORLD_COLS), FALSE );
} }
@@ -3114,7 +3114,7 @@ void HandleNPCDoAction( UINT8 ubTargetNPC, UINT16 usActionCode, UINT8 ubQuoteNum
if (bMoneySlot < bEmptySlot) if (bMoneySlot < bEmptySlot)
{ {
// move main stash to later in inventory! // move main stash to later in inventory!
SwapObjs( pSoldier, bEmptySlot, bMoneySlot ); SwapObjs( pSoldier, bEmptySlot, bMoneySlot, TRUE );
SoldierGiveItem( pSoldier, pSoldier2, &(pSoldier->inv[ bMoneySlot ] ), bMoneySlot ); SoldierGiveItem( pSoldier, pSoldier2, &(pSoldier->inv[ bMoneySlot ] ), bMoneySlot );
} }
else else
+21 -15
View File
@@ -2136,7 +2136,7 @@ BOOLEAN ValidItemLaunchable( OBJECTTYPE * pObj, UINT16 usAttachment )
UINT16 GetLauncherFromLaunchable( UINT16 usLaunchable ) UINT16 GetLauncherFromLaunchable( UINT16 usLaunchable )
{ {
INT32 iLoop = 0; INT32 iLoop = 0;
UINT16 usItem = NOTHING; //UINT16 usItem = NOTHING;
// look for the section of the array pertaining to this launchable item... // look for the section of the array pertaining to this launchable item...
while( 1 ) while( 1 )
@@ -2380,22 +2380,28 @@ void SwapObjs( OBJECTTYPE * pObj1, OBJECTTYPE * pObj2 )
//ADB these 2 functions were created because the code calls SwapObjs all over the place //ADB these 2 functions were created because the code calls SwapObjs all over the place
//but never handles the effects of that swap! //but never handles the effects of that swap!
void SwapObjs(SOLDIERTYPE* pSoldier, int leftSlot, int rightSlot) void SwapObjs(SOLDIERTYPE* pSoldier, int leftSlot, int rightSlot, BOOLEAN fPermanent)
{ {
PERFORMANCE_MARKER PERFORMANCE_MARKER
SwapObjs(&pSoldier->inv[ leftSlot ], &pSoldier->inv[ rightSlot ]); SwapObjs(&pSoldier->inv[ leftSlot ], &pSoldier->inv[ rightSlot ]);
//old usItem for the left slot is now stored in the right slot, and vice versa if (fPermanent)
HandleTacticalEffectsOfEquipmentChange(pSoldier, leftSlot, pSoldier->inv[ rightSlot ].usItem, pSoldier->inv[ leftSlot ].usItem); {
HandleTacticalEffectsOfEquipmentChange(pSoldier, rightSlot, pSoldier->inv[ leftSlot ].usItem, pSoldier->inv[ rightSlot ].usItem); //old usItem for the left slot is now stored in the right slot, and vice versa
HandleTacticalEffectsOfEquipmentChange(pSoldier, leftSlot, pSoldier->inv[ rightSlot ].usItem, pSoldier->inv[ leftSlot ].usItem);
HandleTacticalEffectsOfEquipmentChange(pSoldier, rightSlot, pSoldier->inv[ leftSlot ].usItem, pSoldier->inv[ rightSlot ].usItem);
}
} }
void SwapObjs(SOLDIERTYPE* pSoldier, int slot, OBJECTTYPE* pObject) void SwapObjs(SOLDIERTYPE* pSoldier, int slot, OBJECTTYPE* pObject, BOOLEAN fPermanent)
{ {
PERFORMANCE_MARKER PERFORMANCE_MARKER
SwapObjs(&pSoldier->inv[ slot ], pObject); SwapObjs(&pSoldier->inv[ slot ], pObject);
HandleTacticalEffectsOfEquipmentChange(pSoldier, slot, pObject->usItem, pSoldier->inv[ slot ].usItem); if (fPermanent)
{
HandleTacticalEffectsOfEquipmentChange(pSoldier, slot, pObject->usItem, pSoldier->inv[ slot ].usItem);
}
} }
void RemoveObjFrom( OBJECTTYPE * pObj, UINT8 ubRemoveIndex ) void RemoveObjFrom( OBJECTTYPE * pObj, UINT8 ubRemoveIndex )
@@ -3265,7 +3271,7 @@ BOOLEAN AttachObject( SOLDIERTYPE * pSoldier, OBJECTTYPE * pTargetObj, OBJECTTYP
INT32 iCheckResult; INT32 iCheckResult;
INT8 bAttachInfoIndex = -1, bAttachComboMerge; INT8 bAttachInfoIndex = -1, bAttachComboMerge;
BOOLEAN fValidLaunchable = FALSE; BOOLEAN fValidLaunchable = FALSE;
BOOLEAN IsAGLorRL = FALSE; //BOOLEAN IsAGLorRL = FALSE;
if ( pTargetObj->ubNumberOfObjects > 1 ) if ( pTargetObj->ubNumberOfObjects > 1 )
@@ -3942,7 +3948,7 @@ BOOLEAN PlaceObject( SOLDIERTYPE * pSoldier, INT8 bPos, OBJECTTYPE * pObj )
if (pSoldier->inv[SECONDHANDPOS].usItem != 0) if (pSoldier->inv[SECONDHANDPOS].usItem != 0)
{ {
// swap what WAS in the second hand into the cursor // swap what WAS in the second hand into the cursor
SwapObjs( pSoldier, SECONDHANDPOS, pObj); SwapObjs( pSoldier, SECONDHANDPOS, pObj, TRUE);
} }
} }
} }
@@ -3988,7 +3994,7 @@ BOOLEAN PlaceObject( SOLDIERTYPE * pSoldier, INT8 bPos, OBJECTTYPE * pObj )
if (pObj->ubNumberOfObjects <= 1) if (pObj->ubNumberOfObjects <= 1)
{ {
// swapping // swapping
SwapObjs( pSoldier, bPos, pObj ); SwapObjs( pSoldier, bPos, pObj, TRUE);
} }
else else
{ {
@@ -4052,13 +4058,13 @@ BOOLEAN PlaceObject( SOLDIERTYPE * pSoldier, INT8 bPos, OBJECTTYPE * pObj )
} }
else else
{ {
SwapObjs( pSoldier, bPos, pObj ); SwapObjs( pSoldier, bPos, pObj, TRUE );
} }
} }
else if (pObj->ubNumberOfObjects <= __max( ubSlotLimit, 1 ) ) else if (pObj->ubNumberOfObjects <= __max( ubSlotLimit, 1 ) )
{ {
// swapping // swapping
SwapObjs( pSoldier, bPos, pObj ); SwapObjs( pSoldier, bPos, pObj, TRUE );
} }
else else
{ {
@@ -5668,7 +5674,7 @@ void SwapHandItems( SOLDIERTYPE * pSoldier )
if (pSoldier->inv[HANDPOS].usItem == NOTHING || pSoldier->inv[SECONDHANDPOS].usItem == NOTHING) if (pSoldier->inv[HANDPOS].usItem == NOTHING || pSoldier->inv[SECONDHANDPOS].usItem == NOTHING)
{ {
// whatever is in the second hand can be swapped to the main hand! // whatever is in the second hand can be swapped to the main hand!
SwapObjs( pSoldier, HANDPOS, SECONDHANDPOS ); SwapObjs( pSoldier, HANDPOS, SECONDHANDPOS, TRUE );
DirtyMercPanelInterface( pSoldier, DIRTYLEVEL2 ); DirtyMercPanelInterface( pSoldier, DIRTYLEVEL2 );
} }
else else
@@ -5683,7 +5689,7 @@ void SwapHandItems( SOLDIERTYPE * pSoldier )
} }
// the main hand is now empty so a swap is going to work... // the main hand is now empty so a swap is going to work...
} }
SwapObjs( pSoldier, HANDPOS, SECONDHANDPOS ); SwapObjs( pSoldier, HANDPOS, SECONDHANDPOS, TRUE );
DirtyMercPanelInterface( pSoldier, DIRTYLEVEL2 ); DirtyMercPanelInterface( pSoldier, DIRTYLEVEL2 );
} }
} }
@@ -5700,7 +5706,7 @@ void SwapOutHandItem( SOLDIERTYPE * pSoldier )
if (pSoldier->inv[SECONDHANDPOS].usItem == NOTHING) if (pSoldier->inv[SECONDHANDPOS].usItem == NOTHING)
{ {
// just swap the hand item to the second hand // just swap the hand item to the second hand
SwapObjs( pSoldier, HANDPOS, SECONDHANDPOS ); SwapObjs( pSoldier, HANDPOS, SECONDHANDPOS, TRUE );
DirtyMercPanelInterface( pSoldier, DIRTYLEVEL2 ); DirtyMercPanelInterface( pSoldier, DIRTYLEVEL2 );
return; return;
} }
+2 -2
View File
@@ -35,8 +35,8 @@ extern INT8 FindUsableObj( SOLDIERTYPE * pSoldier, UINT16 usItem );
extern void DeleteObj(OBJECTTYPE * pObj ); extern void DeleteObj(OBJECTTYPE * pObj );
extern void CopyObj( OBJECTTYPE * pSourceObj, OBJECTTYPE * pTargetObj ); extern void CopyObj( OBJECTTYPE * pSourceObj, OBJECTTYPE * pTargetObj );
extern void SwapObjs( OBJECTTYPE * pObj1, OBJECTTYPE * pObj2 ); extern void SwapObjs( OBJECTTYPE * pObj1, OBJECTTYPE * pObj2 );
extern void SwapObjs(SOLDIERTYPE* pSoldier, int leftSlot, int rightSlot); extern void SwapObjs(SOLDIERTYPE* pSoldier, int leftSlot, int rightSlot, BOOLEAN fPermanent);
extern void SwapObjs(SOLDIERTYPE* pSoldier, int slot, OBJECTTYPE* pObject); extern void SwapObjs(SOLDIERTYPE* pSoldier, int slot, OBJECTTYPE* pObject, BOOLEAN fPermanent);
extern void SwapWithinObj( OBJECTTYPE * pObj, UINT8 ubIndex1, UINT8 ubIndex2 ); extern void SwapWithinObj( OBJECTTYPE * pObj, UINT8 ubIndex1, UINT8 ubIndex2 );
extern void RemoveObjFrom( OBJECTTYPE * pObj, UINT8 ubRemoveIndex ); extern void RemoveObjFrom( OBJECTTYPE * pObj, UINT8 ubRemoveIndex );
+2 -2
View File
@@ -5279,7 +5279,7 @@ void HandleTeamServices( UINT8 ubTeamNum )
} }
if ( bSlot != NO_SLOT ) if ( bSlot != NO_SLOT )
{ {
SwapObjs( pTeamSoldier, HANDPOS, bSlot ); SwapObjs( pTeamSoldier, HANDPOS, bSlot, TRUE );
} }
else else
{ {
@@ -5366,7 +5366,7 @@ void HandlePlayerServices( SOLDIERTYPE *pTeamSoldier )
if ( bSlot != NO_SLOT ) if ( bSlot != NO_SLOT )
{ {
SwapObjs( pTeamSoldier, HANDPOS, bSlot ); SwapObjs( pTeamSoldier, HANDPOS, bSlot, TRUE );
} }
else else
{ {
+1 -1
View File
@@ -1847,7 +1847,7 @@ void GetBloodFromCorpse( SOLDIERTYPE *pSoldier )
if ( bObjSlot != NO_SLOT ) if ( bObjSlot != NO_SLOT )
{ {
SwapObjs( pSoldier, bObjSlot, &Object ); SwapObjs( pSoldier, bObjSlot, &Object, TRUE );
} }
} }
+1 -1
View File
@@ -1084,7 +1084,7 @@ BOOLEAN RecruitRPC( UINT8 ubCharNum )
} }
} }
// swap item to hand // swap item to hand
SwapObjs( pNewSoldier, bSlot, HANDPOS ); SwapObjs( pNewSoldier, bSlot, HANDPOS, TRUE );
} }
} }
+2 -2
View File
@@ -3110,7 +3110,7 @@ void GetKeyboardInput( UINT32 *puiNewEvent )
} }
else if ( bSlot2 != ITEM_NOT_FOUND ) else if ( bSlot2 != ITEM_NOT_FOUND )
{ {
SwapObjs( pTeamSoldier, bSlot1, bSlot2 ); SwapObjs( pTeamSoldier, bSlot1, bSlot2, TRUE );
} }
break; break;
} }
@@ -3153,7 +3153,7 @@ void GetKeyboardInput( UINT32 *puiNewEvent )
} }
else if ( bSlot2 != ITEM_NOT_FOUND ) else if ( bSlot2 != ITEM_NOT_FOUND )
{ {
SwapObjs( pTeamSoldier, bSlot1, bSlot2 ); SwapObjs( pTeamSoldier, bSlot1, bSlot2, TRUE );
} }
break; break;
} }
+3 -1
View File
@@ -2319,8 +2319,10 @@ void RearrangePocket(SOLDIERTYPE *pSoldier, INT8 bPocket1, INT8 bPocket2, UINT8
{ {
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"RearrangePocket"); DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"RearrangePocket");
// NB there's no such thing as a temporary swap for now... // NB there's no such thing as a temporary swap for now...
// 0verhaul: There is now! If not permanent, don't lose weapon ready status because the
// weapon will be restored after the trial situation is finished.
//SwapObjs( &(pSoldier->inv[bPocket1]), &(pSoldier->inv[bPocket2]) ); //SwapObjs( &(pSoldier->inv[bPocket1]), &(pSoldier->inv[bPocket2]) );
SwapObjs( pSoldier, bPocket1, bPocket2 ); SwapObjs( pSoldier, bPocket1, bPocket2, bPermanent );
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"RearrangePocket done"); DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"RearrangePocket done");
} }
+2 -2
View File
@@ -429,7 +429,7 @@ INT8 DecideAutoBandage( SOLDIERTYPE * pSoldier )
{ {
pSoldier->bSlotItemTakenFrom = bSlot; pSoldier->bSlotItemTakenFrom = bSlot;
SwapObjs( pSoldier, HANDPOS, bSlot ); SwapObjs( pSoldier, HANDPOS, bSlot, TRUE );
/* /*
memset( &TempObj, 0, sizeof( OBJECTTYPE ) ); memset( &TempObj, 0, sizeof( OBJECTTYPE ) );
// move the med kit out to temp obj // move the med kit out to temp obj
@@ -452,7 +452,7 @@ INT8 DecideAutoBandage( SOLDIERTYPE * pSoldier )
{ {
pSoldier->bSlotItemTakenFrom = bSlot; pSoldier->bSlotItemTakenFrom = bSlot;
SwapObjs( pSoldier, HANDPOS, bSlot ); SwapObjs( pSoldier, HANDPOS, bSlot, TRUE );
} }
return( pSoldier->bAction ); return( pSoldier->bAction );
} }
+2 -2
View File
@@ -93,7 +93,7 @@ BOOLEAN InitializeGame(void)
giStartingMemValue = MemGetFree( ); giStartingMemValue = MemGetFree( );
InitializeLua(); //InitializeLua();
ClearAllDebugTopics(); ClearAllDebugTopics();
RegisterJA2DebugTopic( TOPIC_JA2OPPLIST, "Reg" ); RegisterJA2DebugTopic( TOPIC_JA2OPPLIST, "Reg" );
@@ -168,7 +168,7 @@ void ShutdownGame(void)
//Deletes all the Temp files in the Maps\Temp directory //Deletes all the Temp files in the Maps\Temp directory
InitTacticalSave( FALSE ); InitTacticalSave( FALSE );
ShutdownLua( ); //ShutdownLua( );
FreeGameExternalOptions(); FreeGameExternalOptions();
} }