- with option ONLY_REPAIR_GUNS_AND_ARMOUR to TRUE, only guns and armour can be repaired when using the advanced repair system

- Fix: crash when repairing without a repair kit

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@5693 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Flugente
2012-11-19 00:39:23 +00:00
parent 0112384652
commit 023873b787
3 changed files with 53 additions and 33 deletions
+1
View File
@@ -1548,6 +1548,7 @@ void LoadGameExternalOptions()
// Flugente: advanced repair/dirt system // Flugente: advanced repair/dirt system
gGameExternalOptions.fAdvRepairSystem = iniReader.ReadBoolean("Strategic Gameplay Settings","ADVANCED_REPAIR", FALSE); gGameExternalOptions.fAdvRepairSystem = iniReader.ReadBoolean("Strategic Gameplay Settings","ADVANCED_REPAIR", FALSE);
gGameExternalOptions.fOnlyRepairGunsArmour = iniReader.ReadBoolean("Strategic Gameplay Settings","ONLY_REPAIR_GUNS_AND_ARMOUR", FALSE);
gGameExternalOptions.fDirtSystem = iniReader.ReadBoolean("Strategic Gameplay Settings","DIRT_SYSTEM", FALSE); gGameExternalOptions.fDirtSystem = iniReader.ReadBoolean("Strategic Gameplay Settings","DIRT_SYSTEM", FALSE);
gGameExternalOptions.usSectorDirtDivider = iniReader.ReadInteger("Strategic Gameplay Settings","SECTOR_DIRT_DIVIDER", 1000, 1, 100000); gGameExternalOptions.usSectorDirtDivider = iniReader.ReadInteger("Strategic Gameplay Settings","SECTOR_DIRT_DIVIDER", 1000, 1, 100000);
+1
View File
@@ -1147,6 +1147,7 @@ typedef struct
// Flugente: advanced repair/dirt system // Flugente: advanced repair/dirt system
BOOLEAN fAdvRepairSystem; // allow thresholds to repairing BOOLEAN fAdvRepairSystem; // allow thresholds to repairing
BOOLEAN fOnlyRepairGunsArmour; // we can only repair guns and armour
BOOLEAN fDirtSystem; // allow dirt on items increase the chance for weapon jamming BOOLEAN fDirtSystem; // allow dirt on items increase the chance for weapon jamming
UINT32 usSectorDirtDivider; // divide a guns dirt factor by this to get dirt increase for every turn UINT32 usSectorDirtDivider; // divide a guns dirt factor by this to get dirt increase for every turn
+51 -33
View File
@@ -467,7 +467,7 @@ UINT8 GetNumberThatCanBeDoctored( SOLDIERTYPE *pDoctor, BOOLEAN fThisHour, BOOLE
void CheckForAndHandleHospitalPatients( void ); void CheckForAndHandleHospitalPatients( void );
void HealHospitalPatient( SOLDIERTYPE *pPatient, UINT16 usHealingPtsLeft ); void HealHospitalPatient( SOLDIERTYPE *pPatient, UINT16 usHealingPtsLeft );
void MakeSureToolKitIsInHand( SOLDIERTYPE *pSoldier ); BOOLEAN MakeSureToolKitIsInHand( SOLDIERTYPE *pSoldier );
BOOLEAN MakeSureMedKitIsInHand( SOLDIERTYPE *pSoldier ); BOOLEAN MakeSureMedKitIsInHand( SOLDIERTYPE *pSoldier );
void RepositionMouseRegions( void ); void RepositionMouseRegions( void );
@@ -3421,12 +3421,17 @@ void HandleRepairmenInSector( INT16 sX, INT16 sY, INT8 bZ )
{ {
if ( ( pTeamSoldier->bAssignment == REPAIR ) && ( pTeamSoldier->flags.fMercAsleep == FALSE ) ) if ( ( pTeamSoldier->bAssignment == REPAIR ) && ( pTeamSoldier->flags.fMercAsleep == FALSE ) )
{ {
MakeSureToolKitIsInHand( pTeamSoldier ); if ( MakeSureToolKitIsInHand( pTeamSoldier ) )
// character is in sector, check if can repair
if ( CanCharacterRepair( pTeamSoldier ) && ( EnoughTimeOnAssignment( pTeamSoldier ) ) )
{ {
HandleRepairBySoldier( pTeamSoldier ); // character is in sector, check if can repair
if ( CanCharacterRepair( pTeamSoldier ) && ( EnoughTimeOnAssignment( pTeamSoldier ) ) )
{
HandleRepairBySoldier( pTeamSoldier );
}
} }
else
// if we have no toolkit, then we cannot repair anything
AssignmentDone( pTeamSoldier, TRUE, TRUE );
} }
} }
} }
@@ -4133,20 +4138,18 @@ void HandleRepairBySoldier( SOLDIERTYPE *pSoldier )
} }
else // still has stuff to repair else // still has stuff to repair
{ {
// Flugente: observed an instance where toolkit ran out, but assignment was not quitted, resulting in a crash on the next hour - better check here
if ( FindToolkit( pSoldier ) == NO_SLOT )
{
// he could (maybe) repair something, but can't because he doesn't have a tool kit!
AssignmentAborted( pSoldier, NO_MORE_TOOL_KITS );
}
// if nothing got repaired, there's a problem // if nothing got repaired, there's a problem
if ( ubRepairPtsUsed == 0 ) if ( ubRepairPtsUsed == 0 )
{ {
// see if not having a toolkit is the problem // he can't repair anything because he doesn't have enough skill!
if ( FindToolkit( pSoldier ) == NO_SLOT ) AssignmentAborted( pSoldier, INSUF_REPAIR_SKILL );
{
// he could (maybe) repair something, but can't because he doesn't have a tool kit!
AssignmentAborted( pSoldier, NO_MORE_TOOL_KITS );
}
else
{
// he can't repair anything because he doesn't have enough skill!
AssignmentAborted( pSoldier, INSUF_REPAIR_SKILL );
}
} }
} }
@@ -4163,6 +4166,14 @@ BOOLEAN IsItemRepairable( UINT16 usItem, INT16 bStatus, INT16 bThreshold )
{ {
if ( gGameExternalOptions.fAdvRepairSystem ) if ( gGameExternalOptions.fAdvRepairSystem )
{ {
if ( gGameExternalOptions.fOnlyRepairGunsArmour )
{
if ( ((Item[usItem].usItemClass & IC_WEAPON|IC_ARMOUR) != 0) && bStatus < bThreshold )
return ( TRUE );
else
return ( FALSE );
}
if ( ((Item[usItem].usItemClass & IC_WEAPON|IC_ARMOUR) != 0) && bStatus >= bThreshold ) if ( ((Item[usItem].usItemClass & IC_WEAPON|IC_ARMOUR) != 0) && bStatus >= bThreshold )
// nay // nay
return ( FALSE ); return ( FALSE );
@@ -6819,7 +6830,7 @@ void RepairMenuMvtCallback(MOUSE_REGION * pRegion, INT32 iReason )
} }
} }
void MakeSureToolKitIsInHand( SOLDIERTYPE *pSoldier ) BOOLEAN MakeSureToolKitIsInHand( SOLDIERTYPE *pSoldier )
{ {
//JMich_SkillModifiers: added bonus to see which is the maximum, and an extra pocket to store the highest bonus found so far. //JMich_SkillModifiers: added bonus to see which is the maximum, and an extra pocket to store the highest bonus found so far.
INT8 bPocket = 0, bonus = -101, bToolkitPocket = NO_SLOT; INT8 bPocket = 0, bonus = -101, bToolkitPocket = NO_SLOT;
@@ -6830,30 +6841,37 @@ void MakeSureToolKitIsInHand( SOLDIERTYPE *pSoldier )
bonus = Item[pSoldier->inv[ HANDPOS].usItem].RepairModifier; bonus = Item[pSoldier->inv[ HANDPOS].usItem].RepairModifier;
bToolkitPocket = HANDPOS; bToolkitPocket = HANDPOS;
} }
// run through rest of inventory looking for toolkits, swap the first one into hand if found
// CHRISL: Changed to dynamically determine max inventory locations. // run through rest of inventory looking for toolkits, swap the first one into hand if found
for (bPocket = SECONDHANDPOS; bPocket < NUM_INV_SLOTS; bPocket++) // CHRISL: Changed to dynamically determine max inventory locations.
{ for (bPocket = SECONDHANDPOS; bPocket < NUM_INV_SLOTS; bPocket++)
{
if( Item[pSoldier->inv[ bPocket ].usItem].toolkit && Item[pSoldier->inv[ bPocket ].usItem].RepairModifier > bonus) if( Item[pSoldier->inv[ bPocket ].usItem].toolkit && Item[pSoldier->inv[ bPocket ].usItem].RepairModifier > bonus)
{ {
bonus = Item[pSoldier->inv[ bPocket ].usItem].RepairModifier; bonus = Item[pSoldier->inv[ bPocket ].usItem].RepairModifier;
bToolkitPocket = bPocket; bToolkitPocket = bPocket;
} }
} }
// HEADROCK HAM B2.8: These new conditions will create a bias for swapping an item out of
// our hand.
//If the second hand is free, the item will go to the SECONDHANDPOS while the toolkit // Flugente: ehem... shouldn't we actually CHECK wether there IS a toolkit? We should check that beforehand...
// goes into the HANDPOS if ( bToolkitPocket == NO_SLOT )
if( Item[pSoldier->inv[HANDPOS].usItem].usItemClass & (IC_WEAPON | IC_PUNCH) && !pSoldier->inv[SECONDHANDPOS].exists()) return FALSE;
SwapObjs(pSoldier, HANDPOS, SECONDHANDPOS, TRUE);
// Else, if the gun sling slot is free, and the item can go there, it will. // HEADROCK HAM B2.8: These new conditions will create a bias for swapping an item out of our hand.
else if(UsingNewInventorySystem() && !pSoldier->inv[GUNSLINGPOCKPOS].exists() && CanItemFitInPosition(pSoldier, &pSoldier->inv[HANDPOS], GUNSLINGPOCKPOS, FALSE))
SwapObjs(pSoldier, HANDPOS, GUNSLINGPOCKPOS, TRUE); //If the second hand is free, the item will go to the SECONDHANDPOS while the toolkit goes into the HANDPOS
if( Item[pSoldier->inv[HANDPOS].usItem].usItemClass & (IC_WEAPON | IC_PUNCH) && !pSoldier->inv[SECONDHANDPOS].exists())
SwapObjs(pSoldier, HANDPOS, SECONDHANDPOS, TRUE);
// Else, if the gun sling slot is free, and the item can go there, it will.
else if( UsingNewInventorySystem() && !pSoldier->inv[GUNSLINGPOCKPOS].exists() && CanItemFitInPosition(pSoldier, &pSoldier->inv[HANDPOS], GUNSLINGPOCKPOS, FALSE) )
SwapObjs(pSoldier, HANDPOS, GUNSLINGPOCKPOS, TRUE);
else if(!CanItemFitInPosition(pSoldier, &pSoldier->inv[HANDPOS], bToolkitPocket, FALSE)) else if(!CanItemFitInPosition(pSoldier, &pSoldier->inv[HANDPOS], bToolkitPocket, FALSE))
SwapObjs(pSoldier, HANDPOS, SECONDHANDPOS, TRUE); SwapObjs(pSoldier, HANDPOS, SECONDHANDPOS, TRUE);
SwapObjs( pSoldier, HANDPOS, bToolkitPocket, TRUE ); SwapObjs( pSoldier, HANDPOS, bToolkitPocket, TRUE );
}
return TRUE;
}
BOOLEAN MakeSureMedKitIsInHand( SOLDIERTYPE *pSoldier ) BOOLEAN MakeSureMedKitIsInHand( SOLDIERTYPE *pSoldier )