- bug fix: secrets on strategic map and other externalized stuff were not properly initialized, if user loads a saved game before he creates a new game.

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@635 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Lesh
2006-11-18 19:16:58 +00:00
parent 0e8afa6c7a
commit ff814b7fc7
4 changed files with 72 additions and 75 deletions
+6 -4
View File
@@ -413,9 +413,11 @@ POINT pTownPoints[ MAX_TOWNS ];/*={
}; };
*/ */
INT16 gpSamSectorX[ MAX_NUMBER_OF_SAMS ];// = { SAM_1_X, SAM_2_X, SAM_3_X, SAM_4_X }; // coordinates X,Y of sam sites on strategic map
INT16 gpSamSectorY[ MAX_NUMBER_OF_SAMS ];// = { SAM_1_Y, SAM_2_Y, SAM_3_Y, SAM_4_Y }; INT16 gpSamSectorX[ MAX_NUMBER_OF_SAMS ];
INT16 gpSamSectorY[ MAX_NUMBER_OF_SAMS ];
extern BOOLEAN fSamSiteFoundOrig[ MAX_NUMBER_OF_SAMS ];
// WANNE 2 (reinitialization in "DrawMap()") // WANNE 2 (reinitialization in "DrawMap()")
// map region // map region
@@ -7069,11 +7071,11 @@ void InitMapSecrets( void )
fFoundTixa = FALSE; fFoundTixa = FALSE;
fFoundOrta = FALSE; fFoundOrta = FALSE;
// Lesh: commented out for reason: now samsites.xml control sam hidden status
//for( ubSamIndex = 0; ubSamIndex < NUMBER_OF_SAMS; ubSamIndex++ ) //for( ubSamIndex = 0; ubSamIndex < NUMBER_OF_SAMS; ubSamIndex++ )
//{ //{
// fSamSiteFound[ ubSamIndex ] = FALSE; // fSamSiteFound[ ubSamIndex ] = fSamSiteFoundOrig[ ubSamIndex ];
//} //}
memcpy(fSamSiteFound, fSamSiteFoundOrig, sizeof(fSamSiteFound));
} }
+41 -25
View File
@@ -158,17 +158,21 @@ of the group. If the priority of the group is high, they
BOOLEAN gfAutoAIAware = FALSE; BOOLEAN gfAutoAIAware = FALSE;
// original values to start a clean new game
INT32 iOrigGarrisonArraySize;
INT32 iOrigPatrolArraySize;
//Saved vars //Saved vars
INT8 gbPadding2[3] = {0, 0, 0}; //NOT USED INT8 gbPadding2[3] = {0, 0, 0}; //NOT USED
BOOLEAN gfExtraElites = 0; //Set when queen compositions are augmented with bonus elites. BOOLEAN gfExtraElites = 0; //Set when queen compositions are augmented with bonus elites.
INT32 giGarrisonArraySize = 0; INT32 giGarrisonArraySize = 0;
INT32 giPatrolArraySize = 0; INT32 giPatrolArraySize = 0;
INT32 giForcePercentage = 0; //Modifies the starting group sizes relative by percentage INT32 giForcePercentage = 0; //Modifies the starting group sizes relative by percentage
INT32 giArmyAlertness = 0; //The chance the group will spot an adjacent player/militia INT32 giArmyAlertness = 0; //The chance the group will spot an adjacent player/militia
INT32 giArmyAlertnessDecay = 0; //How much the spotting chance decreases when spot check succeeds INT32 giArmyAlertnessDecay = 0; //How much the spotting chance decreases when spot check succeeds
UINT8 gubNumAwareBattles = 0; //When non-zero, this means the queen is very aware and searching for players. Every time UINT8 gubNumAwareBattles = 0; //When non-zero, this means the queen is very aware and searching for players. Every time
//there is an enemy initiated battle, this counter decrements until zero. Until that point, //there is an enemy initiated battle, this counter decrements until zero. Until that point,
//all adjacent sector checks automatically succeed. //all adjacent sector checks automatically succeed.
BOOLEAN gfQueenAIAwake = FALSE; //This flag turns on/off the strategic decisions. If it's off, no reinforcements BOOLEAN gfQueenAIAwake = FALSE; //This flag turns on/off the strategic decisions. If it's off, no reinforcements
//or assaults will happen. //or assaults will happen.
//@@@Alex, this flag is ONLY set by the first meanwhile scene which calls an action. If this //@@@Alex, this flag is ONLY set by the first meanwhile scene which calls an action. If this
@@ -1049,15 +1053,15 @@ void InitStrategicAI()
INT32 iPercentElitesBonus; INT32 iPercentElitesBonus;
INT32 iMaxEnemyGroupSize = gGameExternalOptions.iMaxEnemyGroupSize; INT32 iMaxEnemyGroupSize = gGameExternalOptions.iMaxEnemyGroupSize;
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Strategic3"); DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Strategic3");
//Initialize the basic variables. //Initialize the basic variables.
gbPadding2[0] = 0; gbPadding2[0] = 0;
gbPadding2[1] = 0; gbPadding2[1] = 0;
gbPadding2[2] = 0; gbPadding2[2] = 0;
gfExtraElites = FALSE; gfExtraElites = FALSE;
//giGarrisonArraySize = 0; // Lesh: already counted from xml //giGarrisonArraySize = 0;
//giPatrolArraySize = 0; // Lesh: already counted from xml //giPatrolArraySize = 0;
giForcePercentage = 0; giForcePercentage = 0;
giArmyAlertness = 0; giArmyAlertness = 0;
giArmyAlertnessDecay = 0; giArmyAlertnessDecay = 0;
@@ -1202,29 +1206,38 @@ void InitStrategicAI()
} }
break; break;
} }
//initialize the patrol group definitions //initialize the patrol group definitions
// Lesh: giPatrolArraySize already calculated while reading xml giPatrolArraySize = iOrigPatrolArraySize;
//giPatrolArraySize = sizeof( gOrigPatrolGroup ) / sizeof( PATROL_GROUP ); if( gPatrolGroup )
if( !gPatrolGroup ) {
{ //Allocate it (otherwise, we just overwrite it because the size never changes) MemFree( gPatrolGroup );
gPatrolGroup = (PATROL_GROUP*)MemAlloc( sizeof( gOrigPatrolGroup ) );
Assert( gPatrolGroup );
} }
gPatrolGroup = (PATROL_GROUP*)MemAlloc( sizeof( gOrigPatrolGroup ) );
Assert( gPatrolGroup );
memcpy( gPatrolGroup, gOrigPatrolGroup, sizeof( gOrigPatrolGroup ) ); memcpy( gPatrolGroup, gOrigPatrolGroup, sizeof( gOrigPatrolGroup ) );
if( gubPatrolReinforcementsDenied )
{
MemFree( gubPatrolReinforcementsDenied );
}
gubPatrolReinforcementsDenied = (UINT8*)MemAlloc( giPatrolArraySize ); gubPatrolReinforcementsDenied = (UINT8*)MemAlloc( giPatrolArraySize );
memset( gubPatrolReinforcementsDenied, 0, giPatrolArraySize ); memset( gubPatrolReinforcementsDenied, 0, giPatrolArraySize );
//initialize the garrison group definitions //initialize the garrison group definitions
// Lesh: giGarrisonArraySize already calculated while reading xml giGarrisonArraySize = iOrigGarrisonArraySize;
//giGarrisonArraySize = sizeof( gOrigGarrisonGroup ) / sizeof( GARRISON_GROUP ); if( gGarrisonGroup )
if( !gGarrisonGroup )
{ {
gGarrisonGroup = (GARRISON_GROUP*)MemAlloc( sizeof( gOrigGarrisonGroup ) ); MemFree( gGarrisonGroup );
Assert( gGarrisonGroup );
} }
gGarrisonGroup = (GARRISON_GROUP*)MemAlloc( sizeof( gOrigGarrisonGroup ) );
Assert( gGarrisonGroup );
memcpy( gGarrisonGroup, gOrigGarrisonGroup, sizeof( gOrigGarrisonGroup ) ); memcpy( gGarrisonGroup, gOrigGarrisonGroup, sizeof( gOrigGarrisonGroup ) );
if ( gubGarrisonReinforcementsDenied )
{
MemFree( gubGarrisonReinforcementsDenied );
}
gubGarrisonReinforcementsDenied = (UINT8*)MemAlloc( giGarrisonArraySize ); gubGarrisonReinforcementsDenied = (UINT8*)MemAlloc( giGarrisonArraySize );
memset( gubGarrisonReinforcementsDenied, 0, giGarrisonArraySize ); memset( gubGarrisonReinforcementsDenied, 0, giGarrisonArraySize );
@@ -1255,6 +1268,7 @@ void InitStrategicAI()
} }
} }
//Now, initialize the garrisons based on the initial sizes (all variances are plus or minus 1). //Now, initialize the garrisons based on the initial sizes (all variances are plus or minus 1).
for( i = 0; i < giGarrisonArraySize; i++ ) for( i = 0; i < giGarrisonArraySize; i++ )
{ {
@@ -1363,6 +1377,7 @@ void InitStrategicAI()
//Spread them out so that they process at different times. //Spread them out so that they process at different times.
AddPeriodStrategicEventWithOffset( EVENT_CHECK_ENEMY_CONTROLLED_SECTOR, 140 - 20 * gGameOptions.ubDifficultyLevel + Random( 4 ), 475 + i, gGarrisonGroup[ i ].ubSectorID ); AddPeriodStrategicEventWithOffset( EVENT_CHECK_ENEMY_CONTROLLED_SECTOR, 140 - 20 * gGameOptions.ubDifficultyLevel + Random( 4 ), 475 + i, gGarrisonGroup[ i ].ubSectorID );
} }
//Now, initialize each of the patrol groups //Now, initialize each of the patrol groups
for( i = 0; i < giPatrolArraySize; i++ ) for( i = 0; i < giPatrolArraySize; i++ )
{ // IGNORE COMMENT, FEATURE REMOVED! { // IGNORE COMMENT, FEATURE REMOVED!
@@ -3354,6 +3369,7 @@ BOOLEAN LoadStrategicAI( HWFILE hFile )
FileRead( hFile, gbPadding, SAI_PADDING_BYTES, &uiNumBytesRead ); FileRead( hFile, gbPadding, SAI_PADDING_BYTES, &uiNumBytesRead );
if( uiNumBytesRead != SAI_PADDING_BYTES ) if( uiNumBytesRead != SAI_PADDING_BYTES )
return FALSE; return FALSE;
//Restore the army composition //Restore the army composition
FileRead( hFile, gArmyComp, NUM_ARMY_COMPOSITIONS * sizeof( ARMY_COMPOSITION ), &uiNumBytesRead ); FileRead( hFile, gArmyComp, NUM_ARMY_COMPOSITIONS * sizeof( ARMY_COMPOSITION ), &uiNumBytesRead );
if( uiNumBytesRead != NUM_ARMY_COMPOSITIONS * sizeof( ARMY_COMPOSITION ) ) if( uiNumBytesRead != NUM_ARMY_COMPOSITIONS * sizeof( ARMY_COMPOSITION ) )
@@ -3439,7 +3455,7 @@ BOOLEAN LoadStrategicAI( HWFILE hFile )
{ //Reinitialize the costs since they have changed. { //Reinitialize the costs since they have changed.
//Recreate the compositions //Recreate the compositions
memcpy( gArmyComp, gOrigArmyComp, NUM_ARMY_COMPOSITIONS * sizeof( ARMY_COMPOSITION ) ); memcpy( gArmyComp, gOrigArmyComp, MAX_ARMY_COMPOSITIONS * sizeof( ARMY_COMPOSITION ) );
EvolveQueenPriorityPhase( TRUE ); EvolveQueenPriorityPhase( TRUE );
//Recreate the patrol desired sizes //Recreate the patrol desired sizes
+6 -6
View File
@@ -11,8 +11,8 @@
extern GARRISON_GROUP gOrigGarrisonGroup[ MAX_GARRISON_GROUPS ]; extern GARRISON_GROUP gOrigGarrisonGroup[ MAX_GARRISON_GROUPS ];
extern PATROL_GROUP gOrigPatrolGroup[ MAX_PATROL_GROUPS ]; extern PATROL_GROUP gOrigPatrolGroup[ MAX_PATROL_GROUPS ];
extern ARMY_COMPOSITION gOrigArmyComp[ MAX_ARMY_COMPOSITIONS ]; extern ARMY_COMPOSITION gOrigArmyComp[ MAX_ARMY_COMPOSITIONS ];
extern INT32 giGarrisonArraySize; extern INT32 iOrigGarrisonArraySize;
extern INT32 giPatrolArraySize; extern INT32 iOrigPatrolArraySize;
// Garrison externalization // Garrison externalization
@@ -101,7 +101,7 @@ garrisonEndElementHandle(void *userData, const char *name)
if(strcmp(name, "GARRISON_INFO") == 0 && pData->curElement == GARRISON_ELEMENT_GARRISON_INFO) if(strcmp(name, "GARRISON_INFO") == 0 && pData->curElement == GARRISON_ELEMENT_GARRISON_INFO)
{ {
pData->curElement = GARRISON_ELEMENT_NONE; pData->curElement = GARRISON_ELEMENT_NONE;
giGarrisonArraySize = pData->uiGarrisonCount; iOrigGarrisonArraySize = pData->uiGarrisonCount;
} }
else if(strcmp(name, "GARRISON") == 0 && pData->curElement == GARRISON_ELEMENT_GARRISON) else if(strcmp(name, "GARRISON") == 0 && pData->curElement == GARRISON_ELEMENT_GARRISON)
{ {
@@ -179,7 +179,7 @@ BOOLEAN ReadInGarrisonInfo(STR fileName)
memset(&pData,0,sizeof(pData)); memset(&pData,0,sizeof(pData));
XML_SetUserData(parser, &pData); XML_SetUserData(parser, &pData);
giGarrisonArraySize = 0; iOrigGarrisonArraySize = 0;
if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE))
{ {
@@ -351,7 +351,7 @@ patrolEndElementHandle(void *userData, const char *name)
if(strcmp(name, "PATROL_INFO") == 0 && pData->curElement == PATROL_ELEMENT_PATROL_INFO) if(strcmp(name, "PATROL_INFO") == 0 && pData->curElement == PATROL_ELEMENT_PATROL_INFO)
{ {
pData->curElement = PATROL_ELEMENT_NONE; pData->curElement = PATROL_ELEMENT_NONE;
giPatrolArraySize = pData->uiPatrolCount; iOrigPatrolArraySize = pData->uiPatrolCount;
} }
else if(strcmp(name, "PATROL") == 0 && pData->curElement == PATROL_ELEMENT_PATROL) else if(strcmp(name, "PATROL") == 0 && pData->curElement == PATROL_ELEMENT_PATROL)
{ {
@@ -523,7 +523,7 @@ BOOLEAN ReadInPatrolInfo(STR fileName)
memset(&pData,0,sizeof(pData)); memset(&pData,0,sizeof(pData));
XML_SetUserData(parser, &pData); XML_SetUserData(parser, &pData);
giPatrolArraySize = 0; iOrigPatrolArraySize = 0;
if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE))
{ {
+19 -40
View File
@@ -151,45 +151,24 @@ BOOLEAN gfUseAlternateMap = FALSE;
// whether or not we have found Orta yet // whether or not we have found Orta yet
BOOLEAN fFoundOrta = FALSE; BOOLEAN fFoundOrta = FALSE;
UINT8 NUMBER_OF_SAMS = 4; UINT8 NUMBER_OF_SAMS;
// have any of the sam sites been found // have any of the sam sites been found (actual values, saved to savegames)
BOOLEAN fSamSiteFound[ MAX_NUMBER_OF_SAMS ];//={ BOOLEAN fSamSiteFound[ MAX_NUMBER_OF_SAMS ];
// FALSE,
// FALSE,
// FALSE,
// FALSE,
//};
INT16 pSamList[ MAX_NUMBER_OF_SAMS ];//={ // original of previous for proper initialization of a new game
// SECTOR( SAM_1_X, SAM_1_Y ), BOOLEAN fSamSiteFoundOrig[ MAX_NUMBER_OF_SAMS ];
// SECTOR( SAM_2_X, SAM_2_Y ),
// SECTOR( SAM_3_X, SAM_3_Y ),
// SECTOR( SAM_4_X, SAM_4_Y ),
//};
INT16 pSamGridNoAList[ MAX_NUMBER_OF_SAMS ];//={ // sectors with sam sites
// 10196, INT16 pSamList[ MAX_NUMBER_OF_SAMS ];
// 11295,
// 16080,
// 11913,
//};
INT16 pSamGridNoBList[ MAX_NUMBER_OF_SAMS ];//={ // girdno's of control terminal of sam site
// 10195, INT16 pSamGridNoAList[ MAX_NUMBER_OF_SAMS ];
// 11135, INT16 pSamGridNoBList[ MAX_NUMBER_OF_SAMS ];
// 15920,
// 11912,
//};
// ATE: Update this w/ graphic used // ATE: Update this w/ graphic used
// Use 3 if / orientation, 4 if \ orientation // Use 3 if / orientation, 4 if \ orientation
INT8 gbSAMGraphicList[ MAX_NUMBER_OF_SAMS ];//={ INT8 gbSAMGraphicList[ MAX_NUMBER_OF_SAMS ];
// 4,
// 3,
// 3,
// 3,
//};
INT8 gbMercIsNewInThisSector[ MAX_NUM_SOLDIERS ]; INT8 gbMercIsNewInThisSector[ MAX_NUM_SOLDIERS ];
@@ -436,7 +415,7 @@ samsiteStartElementHandle(void *userData, const char *name, const char **atts)
{ {
pData->curElement = SAMSITE_ELEMENT_SAMLIST; pData->curElement = SAMSITE_ELEMENT_SAMLIST;
memset( fSamSiteFound, 0, sizeof(fSamSiteFound) ); memset( fSamSiteFoundOrig, 0, sizeof(fSamSiteFoundOrig) );
memset( pSamList, 0, sizeof(pSamList) ); memset( pSamList, 0, sizeof(pSamList) );
memset( pSamGridNoAList, 0, sizeof(pSamGridNoAList) ); memset( pSamGridNoAList, 0, sizeof(pSamGridNoAList) );
memset( pSamGridNoBList, 0, sizeof(pSamGridNoBList) ); memset( pSamGridNoBList, 0, sizeof(pSamGridNoBList) );
@@ -558,13 +537,13 @@ samsiteEndElementHandle(void *userData, const char *name)
if ( pData->curSamInfo.uiIndex != INVALID_SAMSITE_INDEX ) if ( pData->curSamInfo.uiIndex != INVALID_SAMSITE_INDEX )
{ {
pData->curSamInfo.uiIndex--; pData->curSamInfo.uiIndex--;
fSamSiteFound [ pData->curSamInfo.uiIndex ] = !pData->curSamInfo.samHidden; fSamSiteFoundOrig[ pData->curSamInfo.uiIndex ] = !pData->curSamInfo.samHidden;
gpSamSectorX [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samSectorX; gpSamSectorX [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samSectorX;
gpSamSectorY [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samSectorY; gpSamSectorY [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samSectorY;
pSamList [ pData->curSamInfo.uiIndex ] = SECTOR(pData->curSamInfo.samSectorX,pData->curSamInfo.samSectorY); pSamList [ pData->curSamInfo.uiIndex ] = SECTOR(pData->curSamInfo.samSectorX,pData->curSamInfo.samSectorY);
gbSAMGraphicList[ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samOrientation; gbSAMGraphicList [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samOrientation;
pSamGridNoAList [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samGridNoA; pSamGridNoAList [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samGridNoA;
pSamGridNoBList [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samGridNoB; pSamGridNoBList [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samGridNoB;
} }
} }
else if(strcmp(name, "samIndex") == 0 && pData->curElement == SAMSITE_ELEMENT_INDEX) else if(strcmp(name, "samIndex") == 0 && pData->curElement == SAMSITE_ELEMENT_INDEX)