mirror of
https://github.com/1dot13/source.git
synced 2026-09-09 14:46:05 +02:00
Fix: during strategic AI evaluation, player strength isn't properly evaluated and possibly given bogus values. As a result, the AI is stopped from attacking sectors it should normally attack.
git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@7822 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
+37
-16
@@ -2163,9 +2163,13 @@ BOOLEAN ReinforcementsApproved( INT32 iGarrisonID, UINT16 *pusDefencePoints )
|
|||||||
|
|
||||||
if ( PlayerForceTooStrong( gGarrisonGroup[iGarrisonID].ubSectorID, usOffensePoints, &usDefencePoints ) )
|
if ( PlayerForceTooStrong( gGarrisonGroup[iGarrisonID].ubSectorID, usOffensePoints, &usDefencePoints ) )
|
||||||
{
|
{
|
||||||
|
*pusDefencePoints = usDefencePoints;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*pusDefencePoints = usDefencePoints;
|
||||||
|
|
||||||
//Before returning false, determine if reinforcements have been denied repeatedly. If so, then
|
//Before returning false, determine if reinforcements have been denied repeatedly. If so, then
|
||||||
//we might send an augmented force to take it back.
|
//we might send an augmented force to take it back.
|
||||||
if ( gubGarrisonReinforcementsDenied[iGarrisonID] + usOffensePoints > usDefencePoints )
|
if ( gubGarrisonReinforcementsDenied[iGarrisonID] + usOffensePoints > usDefencePoints )
|
||||||
@@ -3056,7 +3060,8 @@ void SendReinforcementsForGarrison( INT32 iDstGarrisonID, UINT16 usDefencePoints
|
|||||||
ubDstSectorY = (UINT8)SECTORY( gGarrisonGroup[ iDstGarrisonID ].ubSectorID );
|
ubDstSectorY = (UINT8)SECTORY( gGarrisonGroup[ iDstGarrisonID ].ubSectorID );
|
||||||
|
|
||||||
if( pOptionalGroup && *pOptionalGroup )
|
if( pOptionalGroup && *pOptionalGroup )
|
||||||
{ //This group will provide the reinforcements
|
{
|
||||||
|
//This group will provide the reinforcements
|
||||||
pGroup = *pOptionalGroup;
|
pGroup = *pOptionalGroup;
|
||||||
|
|
||||||
#ifdef JA2BETAVERSION
|
#ifdef JA2BETAVERSION
|
||||||
@@ -3087,16 +3092,17 @@ void SendReinforcementsForGarrison( INT32 iDstGarrisonID, UINT16 usDefencePoints
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( !giReinforcementPool )
|
if( !giReinforcementPool )
|
||||||
{
|
{
|
||||||
ValidateWeights( 11 );
|
ValidateWeights( 11 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
iReinforcementsApproved = min( iReinforcementsRequested, giReinforcementPool );
|
iReinforcementsApproved = min( iReinforcementsRequested, giReinforcementPool );
|
||||||
|
|
||||||
if( iReinforcementsApproved * 3 < usDefencePoints )
|
if( iReinforcementsApproved * 3 < usDefencePoints )
|
||||||
{ //The enemy force that would be sent would likely be decimated by the player forces.
|
{
|
||||||
|
//The enemy force that would be sent would likely be decimated by the player forces.
|
||||||
gubGarrisonReinforcementsDenied[ iDstGarrisonID ] += (UINT8)(gArmyComp[ gGarrisonGroup[ iDstGarrisonID ].ubComposition ].bPriority / 2);
|
gubGarrisonReinforcementsDenied[ iDstGarrisonID ] += (UINT8)(gArmyComp[ gGarrisonGroup[ iDstGarrisonID ].ubComposition ].bPriority / 2);
|
||||||
ValidateWeights( 12 );
|
ValidateWeights( 12 );
|
||||||
return;
|
return;
|
||||||
@@ -3150,6 +3156,7 @@ void SendReinforcementsForGarrison( INT32 iDstGarrisonID, UINT16 usDefencePoints
|
|||||||
|
|
||||||
MoveSAIGroupToSector( &pGroup, gGarrisonGroup[ iDstGarrisonID ].ubSectorID, STAGE, REINFORCEMENTS );
|
MoveSAIGroupToSector( &pGroup, gGarrisonGroup[ iDstGarrisonID ].ubSectorID, STAGE, REINFORCEMENTS );
|
||||||
}
|
}
|
||||||
|
|
||||||
ValidateWeights( 14 );
|
ValidateWeights( 14 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3167,7 +3174,8 @@ void SendReinforcementsForGarrison( INT32 iDstGarrisonID, UINT16 usDefencePoints
|
|||||||
ubSrcSectorX = (gGarrisonGroup[ iSrcGarrisonID ].ubSectorID % 16) + 1;
|
ubSrcSectorX = (gGarrisonGroup[ iSrcGarrisonID ].ubSectorID % 16) + 1;
|
||||||
ubSrcSectorY = (gGarrisonGroup[ iSrcGarrisonID ].ubSectorID / 16) + 1;
|
ubSrcSectorY = (gGarrisonGroup[ iSrcGarrisonID ].ubSectorID / 16) + 1;
|
||||||
if( ubSrcSectorX != gWorldSectorX || ubSrcSectorY != gWorldSectorY || gbWorldSectorZ > 0 )
|
if( ubSrcSectorX != gWorldSectorX || ubSrcSectorY != gWorldSectorY || gbWorldSectorZ > 0 )
|
||||||
{ //The reinforcements aren't coming from the currently loaded sector!
|
{
|
||||||
|
//The reinforcements aren't coming from the currently loaded sector!
|
||||||
iReinforcementsAvailable = ReinforcementsAvailable( iSrcGarrisonID );
|
iReinforcementsAvailable = ReinforcementsAvailable( iSrcGarrisonID );
|
||||||
if( iReinforcementsAvailable <= 0)
|
if( iReinforcementsAvailable <= 0)
|
||||||
{
|
{
|
||||||
@@ -3183,7 +3191,8 @@ void SendReinforcementsForGarrison( INT32 iDstGarrisonID, UINT16 usDefencePoints
|
|||||||
iReinforcementsApproved = iMaxReinforcementsAllowed - ubNumExtraReinforcements;
|
iReinforcementsApproved = iMaxReinforcementsAllowed - ubNumExtraReinforcements;
|
||||||
}
|
}
|
||||||
else if( (iReinforcementsApproved + ubNumExtraReinforcements) * 3 < usDefencePoints )
|
else if( (iReinforcementsApproved + ubNumExtraReinforcements) * 3 < usDefencePoints )
|
||||||
{ //The enemy force that would be sent would likely be decimated by the player forces.
|
{
|
||||||
|
//The enemy force that would be sent would likely be decimated by the player forces.
|
||||||
gubGarrisonReinforcementsDenied[ iDstGarrisonID ] += (UINT8)(gArmyComp[ gGarrisonGroup[ iDstGarrisonID ].ubComposition ].bPriority / 2);
|
gubGarrisonReinforcementsDenied[ iDstGarrisonID ] += (UINT8)(gArmyComp[ gGarrisonGroup[ iDstGarrisonID ].ubComposition ].bPriority / 2);
|
||||||
ValidateWeights( 17 );
|
ValidateWeights( 17 );
|
||||||
return;
|
return;
|
||||||
@@ -3244,6 +3253,7 @@ void SendReinforcementsForGarrison( INT32 iDstGarrisonID, UINT16 usDefencePoints
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ValidateWeights( 20 );
|
ValidateWeights( 20 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3267,7 +3277,8 @@ void SendReinforcementsForPatrol( INT32 iPatrolID, GROUP **pOptionalGroup )
|
|||||||
ubDstSectorY = (gPatrolGroup[ iPatrolID ].ubSectorID[1] / 16) + 1;
|
ubDstSectorY = (gPatrolGroup[ iPatrolID ].ubSectorID[1] / 16) + 1;
|
||||||
|
|
||||||
if( pOptionalGroup && *pOptionalGroup )
|
if( pOptionalGroup && *pOptionalGroup )
|
||||||
{ //This group will provide the reinforcements
|
{
|
||||||
|
//This group will provide the reinforcements
|
||||||
pGroup = *pOptionalGroup;
|
pGroup = *pOptionalGroup;
|
||||||
|
|
||||||
gPatrolGroup[ iPatrolID ].ubPendingGroupID = pGroup->ubGroupID;
|
gPatrolGroup[ iPatrolID ].ubPendingGroupID = pGroup->ubGroupID;
|
||||||
@@ -3284,9 +3295,12 @@ void SendReinforcementsForPatrol( INT32 iPatrolID, GROUP **pOptionalGroup )
|
|||||||
ValidateWeights( 22 );
|
ValidateWeights( 22 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
iRandom = Random( giReinforcementPoints + giReinforcementPool );
|
iRandom = Random( giReinforcementPoints + giReinforcementPool );
|
||||||
|
|
||||||
if( iRandom < giReinforcementPool )
|
if( iRandom < giReinforcementPool )
|
||||||
{ //use the pool and send the requested amount from SECTOR P3 (queen's palace)
|
{
|
||||||
|
//use the pool and send the requested amount from SECTOR P3 (queen's palace)
|
||||||
iReinforcementsApproved = min( iReinforcementsRequested, giReinforcementPool );
|
iReinforcementsApproved = min( iReinforcementsRequested, giReinforcementPool );
|
||||||
pGroup = CreateNewEnemyGroupDepartingFromSector( SECTOR( gModSettings.ubSAISpawnSectorX, gModSettings.ubSAISpawnSectorY ), 0, (UINT8)iReinforcementsApproved, 0, 0 );
|
pGroup = CreateNewEnemyGroupDepartingFromSector( SECTOR( gModSettings.ubSAISpawnSectorX, gModSettings.ubSAISpawnSectorY ), 0, (UINT8)iReinforcementsApproved, 0, 0 );
|
||||||
pGroup->ubOriginalSector = (UINT8)SECTOR( ubDstSectorX, ubDstSectorY );
|
pGroup->ubOriginalSector = (UINT8)SECTOR( ubDstSectorX, ubDstSectorY );
|
||||||
@@ -3350,6 +3364,7 @@ void SendReinforcementsForPatrol( INT32 iPatrolID, GROUP **pOptionalGroup )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ValidateWeights( 25 );
|
ValidateWeights( 25 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3360,7 +3375,7 @@ void EvaluateQueenSituation()
|
|||||||
INT32 i, iRandom;
|
INT32 i, iRandom;
|
||||||
INT32 iWeight;
|
INT32 iWeight;
|
||||||
UINT32 uiOffset;
|
UINT32 uiOffset;
|
||||||
UINT16 usDefencePoints;
|
UINT16 usDefencePoints = 0;
|
||||||
INT32 iOrigRequestPoints;
|
INT32 iOrigRequestPoints;
|
||||||
INT32 iSumOfAllWeights = 0;
|
INT32 iSumOfAllWeights = 0;
|
||||||
|
|
||||||
@@ -6459,7 +6474,7 @@ void ReassignAIGroup( GROUP **pGroup )
|
|||||||
{
|
{
|
||||||
INT32 i, iRandom;
|
INT32 i, iRandom;
|
||||||
INT32 iWeight;
|
INT32 iWeight;
|
||||||
UINT16 usDefencePoints;
|
UINT16 usDefencePoints = 0;
|
||||||
INT32 iReloopLastIndex = -1;
|
INT32 iReloopLastIndex = -1;
|
||||||
UINT8 ubSectorID;
|
UINT8 ubSectorID;
|
||||||
|
|
||||||
@@ -6498,13 +6513,15 @@ void ReassignAIGroup( GROUP **pGroup )
|
|||||||
if( !gGarrisonGroup[ i ].ubPendingGroupID &&
|
if( !gGarrisonGroup[ i ].ubPendingGroupID &&
|
||||||
EnemyPermittedToAttackSector( NULL, gGarrisonGroup[ i ].ubSectorID ) &&
|
EnemyPermittedToAttackSector( NULL, gGarrisonGroup[ i ].ubSectorID ) &&
|
||||||
GarrisonRequestingMinimumReinforcements( i ) )
|
GarrisonRequestingMinimumReinforcements( i ) )
|
||||||
{ //This is the group that gets the reinforcements!
|
{
|
||||||
|
//This is the group that gets the reinforcements!
|
||||||
if( ReinforcementsApproved( i, &usDefencePoints ) )
|
if( ReinforcementsApproved( i, &usDefencePoints ) )
|
||||||
{
|
{
|
||||||
SendReinforcementsForGarrison( i, usDefencePoints, pGroup );
|
SendReinforcementsForGarrison( i, usDefencePoints, pGroup );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( iReloopLastIndex == -1 )
|
if( iReloopLastIndex == -1 )
|
||||||
{ //go to the next garrison and clear the iRandom value so it attempts to use all subsequent groups.
|
{ //go to the next garrison and clear the iRandom value so it attempts to use all subsequent groups.
|
||||||
iReloopLastIndex = i - 1;
|
iReloopLastIndex = i - 1;
|
||||||
@@ -6517,18 +6534,21 @@ void ReassignAIGroup( GROUP **pGroup )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( iReloopLastIndex >= 0 )
|
if( iReloopLastIndex >= 0 )
|
||||||
{ //Process the loop again to the point where the original random slot started considering, and consider
|
{
|
||||||
|
//Process the loop again to the point where the original random slot started considering, and consider
|
||||||
//all of the garrisons. If this fails, all patrol groups will be considered next.
|
//all of the garrisons. If this fails, all patrol groups will be considered next.
|
||||||
for( i = 0; i <= iReloopLastIndex; i++ )
|
for( i = 0; i <= iReloopLastIndex; ++i )
|
||||||
{
|
{
|
||||||
RecalculateGarrisonWeight( i );
|
RecalculateGarrisonWeight( i );
|
||||||
iWeight = gGarrisonGroup[ i ].bWeight;
|
iWeight = gGarrisonGroup[ i ].bWeight;
|
||||||
if( iWeight > 0 )
|
if( iWeight > 0 )
|
||||||
{ //if group is requesting reinforcements.
|
{
|
||||||
|
//if group is requesting reinforcements.
|
||||||
if( !gGarrisonGroup[ i ].ubPendingGroupID &&
|
if( !gGarrisonGroup[ i ].ubPendingGroupID &&
|
||||||
EnemyPermittedToAttackSector( NULL, gGarrisonGroup[ i ].ubSectorID ) &&
|
EnemyPermittedToAttackSector( NULL, gGarrisonGroup[ i ].ubSectorID ) &&
|
||||||
GarrisonRequestingMinimumReinforcements( i ) )
|
GarrisonRequestingMinimumReinforcements( i ) )
|
||||||
{ //This is the group that gets the reinforcements!
|
{
|
||||||
|
//This is the group that gets the reinforcements!
|
||||||
if( ReinforcementsApproved( i, &usDefencePoints ) )
|
if( ReinforcementsApproved( i, &usDefencePoints ) )
|
||||||
{
|
{
|
||||||
SendReinforcementsForGarrison( i, usDefencePoints, pGroup );
|
SendReinforcementsForGarrison( i, usDefencePoints, pGroup );
|
||||||
@@ -6538,10 +6558,11 @@ void ReassignAIGroup( GROUP **pGroup )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( iReloopLastIndex == -1 )
|
if( iReloopLastIndex == -1 )
|
||||||
{
|
{
|
||||||
//go through the patrol groups
|
//go through the patrol groups
|
||||||
for( i = 0; i < giPatrolArraySize; i++ )
|
for( i = 0; i < giPatrolArraySize; ++i )
|
||||||
{
|
{
|
||||||
RecalculatePatrolWeight( i );
|
RecalculatePatrolWeight( i );
|
||||||
iWeight = gPatrolGroup[ i ].bWeight;
|
iWeight = gPatrolGroup[ i ].bWeight;
|
||||||
@@ -6569,7 +6590,7 @@ void ReassignAIGroup( GROUP **pGroup )
|
|||||||
iReloopLastIndex = giPatrolArraySize - 1;
|
iReloopLastIndex = giPatrolArraySize - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i = 0; i <= iReloopLastIndex; i++ )
|
for( i = 0; i <= iReloopLastIndex; ++i )
|
||||||
{
|
{
|
||||||
RecalculatePatrolWeight( i );
|
RecalculatePatrolWeight( i );
|
||||||
iWeight = gPatrolGroup[ i ].bWeight;
|
iWeight = gPatrolGroup[ i ].bWeight;
|
||||||
|
|||||||
Reference in New Issue
Block a user