diff --git a/Strategic/Map Screen Interface Map.cpp b/Strategic/Map Screen Interface Map.cpp index c934d058..3ef87b61 100644 --- a/Strategic/Map Screen Interface Map.cpp +++ b/Strategic/Map Screen Interface Map.cpp @@ -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 }; -INT16 gpSamSectorY[ MAX_NUMBER_OF_SAMS ];// = { SAM_1_Y, SAM_2_Y, SAM_3_Y, SAM_4_Y }; +// coordinates X,Y of sam sites on strategic map +INT16 gpSamSectorX[ MAX_NUMBER_OF_SAMS ]; +INT16 gpSamSectorY[ MAX_NUMBER_OF_SAMS ]; +extern BOOLEAN fSamSiteFoundOrig[ MAX_NUMBER_OF_SAMS ]; // WANNE 2 (reinitialization in "DrawMap()") // map region @@ -7069,11 +7071,11 @@ void InitMapSecrets( void ) fFoundTixa = FALSE; fFoundOrta = FALSE; - // Lesh: commented out for reason: now samsites.xml control sam hidden status //for( ubSamIndex = 0; ubSamIndex < NUMBER_OF_SAMS; ubSamIndex++ ) //{ - // fSamSiteFound[ ubSamIndex ] = FALSE; + // fSamSiteFound[ ubSamIndex ] = fSamSiteFoundOrig[ ubSamIndex ]; //} + memcpy(fSamSiteFound, fSamSiteFoundOrig, sizeof(fSamSiteFound)); } diff --git a/Strategic/Strategic AI.cpp b/Strategic/Strategic AI.cpp index eb3b58dc..18f36b26 100644 --- a/Strategic/Strategic AI.cpp +++ b/Strategic/Strategic AI.cpp @@ -158,17 +158,21 @@ of the group. If the priority of the group is high, they BOOLEAN gfAutoAIAware = FALSE; +// original values to start a clean new game +INT32 iOrigGarrisonArraySize; +INT32 iOrigPatrolArraySize; + //Saved vars -INT8 gbPadding2[3] = {0, 0, 0}; //NOT USED -BOOLEAN gfExtraElites = 0; //Set when queen compositions are augmented with bonus elites. -INT32 giGarrisonArraySize = 0; -INT32 giPatrolArraySize = 0; -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 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 - //there is an enemy initiated battle, this counter decrements until zero. Until that point, - //all adjacent sector checks automatically succeed. +INT8 gbPadding2[3] = {0, 0, 0}; //NOT USED +BOOLEAN gfExtraElites = 0; //Set when queen compositions are augmented with bonus elites. +INT32 giGarrisonArraySize = 0; +INT32 giPatrolArraySize = 0; +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 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 + //there is an enemy initiated battle, this counter decrements until zero. Until that point, + //all adjacent sector checks automatically succeed. BOOLEAN gfQueenAIAwake = FALSE; //This flag turns on/off the strategic decisions. If it's off, no reinforcements //or assaults will happen. //@@@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 iMaxEnemyGroupSize = gGameExternalOptions.iMaxEnemyGroupSize; DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Strategic3"); - + //Initialize the basic variables. gbPadding2[0] = 0; gbPadding2[1] = 0; gbPadding2[2] = 0; gfExtraElites = FALSE; - //giGarrisonArraySize = 0; // Lesh: already counted from xml - //giPatrolArraySize = 0; // Lesh: already counted from xml + //giGarrisonArraySize = 0; + //giPatrolArraySize = 0; giForcePercentage = 0; giArmyAlertness = 0; giArmyAlertnessDecay = 0; @@ -1202,29 +1206,38 @@ void InitStrategicAI() } break; } + //initialize the patrol group definitions - // Lesh: giPatrolArraySize already calculated while reading xml - //giPatrolArraySize = sizeof( gOrigPatrolGroup ) / sizeof( PATROL_GROUP ); - if( !gPatrolGroup ) - { //Allocate it (otherwise, we just overwrite it because the size never changes) - gPatrolGroup = (PATROL_GROUP*)MemAlloc( sizeof( gOrigPatrolGroup ) ); - Assert( gPatrolGroup ); + giPatrolArraySize = iOrigPatrolArraySize; + if( gPatrolGroup ) + { + MemFree( gPatrolGroup ); } + gPatrolGroup = (PATROL_GROUP*)MemAlloc( sizeof( gOrigPatrolGroup ) ); + Assert( gPatrolGroup ); memcpy( gPatrolGroup, gOrigPatrolGroup, sizeof( gOrigPatrolGroup ) ); + if( gubPatrolReinforcementsDenied ) + { + MemFree( gubPatrolReinforcementsDenied ); + } gubPatrolReinforcementsDenied = (UINT8*)MemAlloc( giPatrolArraySize ); memset( gubPatrolReinforcementsDenied, 0, giPatrolArraySize ); //initialize the garrison group definitions - // Lesh: giGarrisonArraySize already calculated while reading xml - //giGarrisonArraySize = sizeof( gOrigGarrisonGroup ) / sizeof( GARRISON_GROUP ); - if( !gGarrisonGroup ) + giGarrisonArraySize = iOrigGarrisonArraySize; + if( gGarrisonGroup ) { - gGarrisonGroup = (GARRISON_GROUP*)MemAlloc( sizeof( gOrigGarrisonGroup ) ); - Assert( gGarrisonGroup ); + MemFree( gGarrisonGroup ); } + gGarrisonGroup = (GARRISON_GROUP*)MemAlloc( sizeof( gOrigGarrisonGroup ) ); + Assert( gGarrisonGroup ); memcpy( gGarrisonGroup, gOrigGarrisonGroup, sizeof( gOrigGarrisonGroup ) ); + if ( gubGarrisonReinforcementsDenied ) + { + MemFree( gubGarrisonReinforcementsDenied ); + } gubGarrisonReinforcementsDenied = (UINT8*)MemAlloc( 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). for( i = 0; i < giGarrisonArraySize; i++ ) { @@ -1363,6 +1377,7 @@ void InitStrategicAI() //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 ); } + //Now, initialize each of the patrol groups for( i = 0; i < giPatrolArraySize; i++ ) { // IGNORE COMMENT, FEATURE REMOVED! @@ -3354,6 +3369,7 @@ BOOLEAN LoadStrategicAI( HWFILE hFile ) FileRead( hFile, gbPadding, SAI_PADDING_BYTES, &uiNumBytesRead ); if( uiNumBytesRead != SAI_PADDING_BYTES ) return FALSE; + //Restore the army composition FileRead( hFile, gArmyComp, NUM_ARMY_COMPOSITIONS * sizeof( ARMY_COMPOSITION ), &uiNumBytesRead ); if( uiNumBytesRead != NUM_ARMY_COMPOSITIONS * sizeof( ARMY_COMPOSITION ) ) @@ -3439,7 +3455,7 @@ BOOLEAN LoadStrategicAI( HWFILE hFile ) { //Reinitialize the costs since they have changed. //Recreate the compositions - memcpy( gArmyComp, gOrigArmyComp, NUM_ARMY_COMPOSITIONS * sizeof( ARMY_COMPOSITION ) ); + memcpy( gArmyComp, gOrigArmyComp, MAX_ARMY_COMPOSITIONS * sizeof( ARMY_COMPOSITION ) ); EvolveQueenPriorityPhase( TRUE ); //Recreate the patrol desired sizes diff --git a/Strategic/XML_Army.cpp b/Strategic/XML_Army.cpp index 34c43fc4..ad72411f 100644 --- a/Strategic/XML_Army.cpp +++ b/Strategic/XML_Army.cpp @@ -11,8 +11,8 @@ extern GARRISON_GROUP gOrigGarrisonGroup[ MAX_GARRISON_GROUPS ]; extern PATROL_GROUP gOrigPatrolGroup[ MAX_PATROL_GROUPS ]; extern ARMY_COMPOSITION gOrigArmyComp[ MAX_ARMY_COMPOSITIONS ]; -extern INT32 giGarrisonArraySize; -extern INT32 giPatrolArraySize; +extern INT32 iOrigGarrisonArraySize; +extern INT32 iOrigPatrolArraySize; // Garrison externalization @@ -101,7 +101,7 @@ garrisonEndElementHandle(void *userData, const char *name) if(strcmp(name, "GARRISON_INFO") == 0 && pData->curElement == GARRISON_ELEMENT_GARRISON_INFO) { pData->curElement = GARRISON_ELEMENT_NONE; - giGarrisonArraySize = pData->uiGarrisonCount; + iOrigGarrisonArraySize = pData->uiGarrisonCount; } else if(strcmp(name, "GARRISON") == 0 && pData->curElement == GARRISON_ELEMENT_GARRISON) { @@ -179,7 +179,7 @@ BOOLEAN ReadInGarrisonInfo(STR fileName) memset(&pData,0,sizeof(pData)); XML_SetUserData(parser, &pData); - giGarrisonArraySize = 0; + iOrigGarrisonArraySize = 0; 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) { pData->curElement = PATROL_ELEMENT_NONE; - giPatrolArraySize = pData->uiPatrolCount; + iOrigPatrolArraySize = pData->uiPatrolCount; } else if(strcmp(name, "PATROL") == 0 && pData->curElement == PATROL_ELEMENT_PATROL) { @@ -523,7 +523,7 @@ BOOLEAN ReadInPatrolInfo(STR fileName) memset(&pData,0,sizeof(pData)); XML_SetUserData(parser, &pData); - giPatrolArraySize = 0; + iOrigPatrolArraySize = 0; if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { diff --git a/Strategic/strategicmap.cpp b/Strategic/strategicmap.cpp index 00c807d1..99ea7893 100644 --- a/Strategic/strategicmap.cpp +++ b/Strategic/strategicmap.cpp @@ -151,45 +151,24 @@ BOOLEAN gfUseAlternateMap = FALSE; // whether or not we have found Orta yet BOOLEAN fFoundOrta = FALSE; -UINT8 NUMBER_OF_SAMS = 4; +UINT8 NUMBER_OF_SAMS; -// have any of the sam sites been found -BOOLEAN fSamSiteFound[ MAX_NUMBER_OF_SAMS ];//={ -// FALSE, -// FALSE, -// FALSE, -// FALSE, -//}; +// have any of the sam sites been found (actual values, saved to savegames) +BOOLEAN fSamSiteFound[ MAX_NUMBER_OF_SAMS ]; -INT16 pSamList[ MAX_NUMBER_OF_SAMS ];//={ -// SECTOR( SAM_1_X, SAM_1_Y ), -// SECTOR( SAM_2_X, SAM_2_Y ), -// SECTOR( SAM_3_X, SAM_3_Y ), -// SECTOR( SAM_4_X, SAM_4_Y ), -//}; +// original of previous for proper initialization of a new game +BOOLEAN fSamSiteFoundOrig[ MAX_NUMBER_OF_SAMS ]; -INT16 pSamGridNoAList[ MAX_NUMBER_OF_SAMS ];//={ -// 10196, -// 11295, -// 16080, -// 11913, -//}; +// sectors with sam sites +INT16 pSamList[ MAX_NUMBER_OF_SAMS ]; -INT16 pSamGridNoBList[ MAX_NUMBER_OF_SAMS ];//={ -// 10195, -// 11135, -// 15920, -// 11912, -//}; +// girdno's of control terminal of sam site +INT16 pSamGridNoAList[ MAX_NUMBER_OF_SAMS ]; +INT16 pSamGridNoBList[ MAX_NUMBER_OF_SAMS ]; // ATE: Update this w/ graphic used // Use 3 if / orientation, 4 if \ orientation -INT8 gbSAMGraphicList[ MAX_NUMBER_OF_SAMS ];//={ -// 4, -// 3, -// 3, -// 3, -//}; +INT8 gbSAMGraphicList[ MAX_NUMBER_OF_SAMS ]; INT8 gbMercIsNewInThisSector[ MAX_NUM_SOLDIERS ]; @@ -436,7 +415,7 @@ samsiteStartElementHandle(void *userData, const char *name, const char **atts) { pData->curElement = SAMSITE_ELEMENT_SAMLIST; - memset( fSamSiteFound, 0, sizeof(fSamSiteFound) ); + memset( fSamSiteFoundOrig, 0, sizeof(fSamSiteFoundOrig) ); memset( pSamList, 0, sizeof(pSamList) ); memset( pSamGridNoAList, 0, sizeof(pSamGridNoAList) ); memset( pSamGridNoBList, 0, sizeof(pSamGridNoBList) ); @@ -558,13 +537,13 @@ samsiteEndElementHandle(void *userData, const char *name) if ( pData->curSamInfo.uiIndex != INVALID_SAMSITE_INDEX ) { pData->curSamInfo.uiIndex--; - fSamSiteFound [ pData->curSamInfo.uiIndex ] = !pData->curSamInfo.samHidden; - gpSamSectorX [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samSectorX; - gpSamSectorY [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samSectorY; - pSamList [ pData->curSamInfo.uiIndex ] = SECTOR(pData->curSamInfo.samSectorX,pData->curSamInfo.samSectorY); - gbSAMGraphicList[ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samOrientation; - pSamGridNoAList [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samGridNoA; - pSamGridNoBList [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samGridNoB; + fSamSiteFoundOrig[ pData->curSamInfo.uiIndex ] = !pData->curSamInfo.samHidden; + gpSamSectorX [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samSectorX; + gpSamSectorY [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samSectorY; + pSamList [ pData->curSamInfo.uiIndex ] = SECTOR(pData->curSamInfo.samSectorX,pData->curSamInfo.samSectorY); + gbSAMGraphicList [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samOrientation; + pSamGridNoAList [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samGridNoA; + pSamGridNoBList [ pData->curSamInfo.uiIndex ] = pData->curSamInfo.samGridNoB; } } else if(strcmp(name, "samIndex") == 0 && pData->curElement == SAMSITE_ELEMENT_INDEX)