diff --git a/SaveLoadGame.cpp b/SaveLoadGame.cpp index 9939cf7b..555c26d5 100644 --- a/SaveLoadGame.cpp +++ b/SaveLoadGame.cpp @@ -740,7 +740,8 @@ BOOLEAN LoadArmsDealerInventoryFromSavedGameFile( HWFILE hFile ) //Free all the dealers special inventory arrays ShutDownArmsDealers(); - if (guiCurrentSaveGameVersion >= NIV_SAVEGAME_DATATYPE_CHANGE) { + if (guiCurrentSaveGameVersion >= NIV_SAVEGAME_DATATYPE_CHANGE) + { int dealers; if (!FileRead( hFile, &dealers, sizeof( int ), &uiNumBytesRead )) { @@ -754,32 +755,38 @@ BOOLEAN LoadArmsDealerInventoryFromSavedGameFile( HWFILE hFile ) } //loop through all the dealers inventories - for( ubArmsDealer=0; ubArmsDealerLoad(hFile) ) { + DealerItemList::iterator iterend = gArmsDealersInventory[ubArmsDealer].end( ); + for (DealerItemList::iterator iter = gArmsDealersInventory[ubArmsDealer].begin(); iter != iterend; ++iter ) + { + if (! iter->Load(hFile) ) + { return FALSE; } + //CHRISL: Because of the "100rnd" bug that Tony is experiencing, lets look at each item as we create it. If the // item is ammo, reset the bItemCondition value to equal the number of rounds. Hopefully this will be unneccessary // but for the time being, it may help to alleviate the "100rnd" bug. if(Item[iter->object.usItem].usItemClass == IC_AMMO) { + // Flugente: this condition is unnecessary, as we afterwards make sure that iter->bItemCondition = iter->object[0]->data.ubShotsLeft anyway //This condition should catch any dealer ammo items that have both invalid bItemCondition and ubShotsLeft values. // We'll only make bItemCondition valid at this point. Let the next condition correct ubShotsLeft. - if(iter->bItemCondition > Magazine[Item[iter->object.usItem].ubClassIndex].ubMagSize) + /*if( iter->bItemCondition > Magazine[Item[iter->object.usItem].ubClassIndex].ubMagSize) { iter->bItemCondition = Magazine[Item[iter->object.usItem].ubClassIndex].ubMagSize; - } + }*/ + //This condition should catch any dealer ammo items that have an invalid bItemCondition assuming ubShotsLeft is valid if(iter->bItemCondition != iter->object[0]->data.ubShotsLeft) { @@ -789,7 +796,8 @@ BOOLEAN LoadArmsDealerInventoryFromSavedGameFile( HWFILE hFile ) } } } - else { + else + { //the format has changed and needs to be updated OLD_ARMS_DEALER_STATUS_101 gOldArmsDealerStatus[NUM_ARMS_DEALERS]; //OLD_DEALER_ITEM_HEADER_101 gOldArmsDealersInventory[NUM_ARMS_DEALERS][MAXITEMS]; @@ -4470,11 +4478,11 @@ BOOLEAN LoadSavedGame( int ubSavedGameID ) //If there is someone talking, stop them StopAnyCurrentlyTalkingSpeech( ); - + ZeroAnimSurfaceCounts( ); ShutdownNPCQuotes(); - + SetFastForwardMode(FALSE); // FF can sometimes be active if quick-load during AI turn transition SetClockSpeedPercent(gGameExternalOptions.fClockSpeedPercent); // sevenfm: set default clock speed @@ -5914,7 +5922,7 @@ BOOLEAN LoadSavedGame( int ubSavedGameID ) #endif } - + if( guiCurrentSaveGameVersion > ENCYCLOPEDIA_SAVEGAME_CHANGE) { uiRelEndPerc += 1; @@ -6275,19 +6283,18 @@ BOOLEAN LoadSavedGame( int ubSavedGameID ) } } } - - if ( guiCurrentSaveGameVersion < 68 ) - { - // correct bVehicleUnderRepairID for all mercs - UINT8 ubID; - for( ubID = 0; ubID < MAXMERCS; ubID++ ) - { - Menptr[ ubID ].bVehicleUnderRepairID = -1; - } - } - + if ( guiCurrentSaveGameVersion < 73 ) { + if ( guiCurrentSaveGameVersion < 68 ) + { + // correct bVehicleUnderRepairID for all mercs + for ( UINT16 ubID = 0; ubID < MAXMERCS; ++ubID ) + { + Menptr[ubID].bVehicleUnderRepairID = -1; + } + } + if( LaptopSaveInfo.fMercSiteHasGoneDownYet ) LaptopSaveInfo.fFirstVisitSinceServerWentDown = 2; } @@ -6575,13 +6582,13 @@ BOOLEAN LoadSoldierStructure( HWFILE hFile ) SOLDIERTYPE SavedSoldierInfo; //Loop through all the soldier and delete them all - for( cnt=0; cnt< TOTAL_SOLDIERS; cnt++) + for( cnt=0; cnt< TOTAL_SOLDIERS; ++cnt) { TacticalRemoveSoldier( cnt ); } //Loop through all the soldier structs to load - for( cnt=0; cnt< TOTAL_SOLDIERS; cnt++) + for( cnt=0; cnt< TOTAL_SOLDIERS; ++cnt) { //update the progress bar uiPercentage = (cnt * 100) / (TOTAL_SOLDIERS-1); @@ -6594,14 +6601,8 @@ BOOLEAN LoadSoldierStructure( HWFILE hFile ) return(FALSE); } - // if the soldier is not active, continue - if( !ubActive ) - { - continue; - } - - // else if there is a soldier - else + // only continue if the soldier is active + if( ubActive ) { //Read in the saved soldier info into a Temp structure if ( !SavedSoldierInfo.Load(hFile) ) @@ -6626,13 +6627,7 @@ BOOLEAN LoadSoldierStructure( HWFILE hFile ) SavedSoldierInfo.pForcedShade = NULL; SavedSoldierInfo.pMercPath = NULL; memset( SavedSoldierInfo.pEffectShades, 0, sizeof( UINT16* ) * NUM_SOLDIER_EFFECTSHADES ); - - - //if the soldier wasnt active, dont add them now. Advance to the next merc - //if( !SavedSoldierInfo.bActive ) - // continue; - - + //Create the new merc SOLDIERCREATE_STRUCT CreateStruct; CreateStruct.bTeam = SavedSoldierInfo.bTeam; @@ -6643,7 +6638,6 @@ BOOLEAN LoadSoldierStructure( HWFILE hFile ) if( !TacticalCreateSoldier( &CreateStruct, &ubId ) ) return( FALSE ); - // Load the pMercPath if( !LoadMercPathToSoldierStruct( hFile, ubId ) ) return( FALSE ); @@ -6693,53 +6687,50 @@ BOOLEAN LoadSoldierStructure( HWFILE hFile ) // ResetIMPCharactersEyesAndMouthOffsets( Menptr[ cnt ].ubProfile ); //} - //if the saved game version is before x, calculate the amount of money paid to mercs - if( guiCurrentSaveGameVersion < 83 ) - { - //if the soldier is someone - if( Menptr[ cnt ].ubProfile != NO_PROFILE ) - { - if( Menptr[cnt].ubWhatKindOfMercAmI == MERC_TYPE__MERC ) - { - gMercProfiles[ Menptr[ cnt ].ubProfile ].uiTotalCostToDate = gMercProfiles[ Menptr[ cnt ].ubProfile ].sSalary * gMercProfiles[ Menptr[ cnt ].ubProfile ].iMercMercContractLength; - } - else - { - gMercProfiles[ Menptr[ cnt ].ubProfile ].uiTotalCostToDate = gMercProfiles[ Menptr[ cnt ].ubProfile ].sSalary * Menptr[ cnt ].iTotalContractLength; - } - } - } - -#ifdef GERMAN - // Fix neutral flags - if ( guiCurrentSaveGameVersion < 94 ) - { - if ( Menptr[ cnt].bTeam == OUR_TEAM && Menptr[ cnt ].aiData.bNeutral && Menptr[ cnt ].bAssignment != ASSIGNMENT_POW ) - { - // turn off neutral flag - Menptr[ cnt].aiData.bNeutral = FALSE; - } - } -#endif - //#ifdef JA2UB - //if the soldier has the NON weapon version of the merc knofe or merc umbrella - //ConvertWeapons( &Menptr[ cnt ] ); - //#endif - - // JA2Gold: fix next-to-previous attacker value if ( guiCurrentSaveGameVersion < 99 ) { - Menptr[ cnt ].ubNextToPreviousAttackerID = NOBODY; - } + //if the saved game version is before x, calculate the amount of money paid to mercs + if( guiCurrentSaveGameVersion < 83 ) + { + //if the soldier is someone + if( Menptr[ cnt ].ubProfile != NO_PROFILE ) + { + if( Menptr[cnt].ubWhatKindOfMercAmI == MERC_TYPE__MERC ) + { + gMercProfiles[ Menptr[ cnt ].ubProfile ].uiTotalCostToDate = gMercProfiles[ Menptr[ cnt ].ubProfile ].sSalary * gMercProfiles[ Menptr[ cnt ].ubProfile ].iMercMercContractLength; + } + else + { + gMercProfiles[ Menptr[ cnt ].ubProfile ].uiTotalCostToDate = gMercProfiles[ Menptr[ cnt ].ubProfile ].sSalary * Menptr[ cnt ].iTotalContractLength; + } + } + } +#ifdef GERMAN + // Fix neutral flags + if ( guiCurrentSaveGameVersion < 94 ) + { + if ( Menptr[ cnt].bTeam == OUR_TEAM && Menptr[ cnt ].aiData.bNeutral && Menptr[ cnt ].bAssignment != ASSIGNMENT_POW ) + { + // turn off neutral flag + Menptr[ cnt].aiData.bNeutral = FALSE; + } + } +#endif + //#ifdef JA2UB + //if the soldier has the NON weapon version of the merc knofe or merc umbrella + //ConvertWeapons( &Menptr[ cnt ] ); + //#endif + + // JA2Gold: fix next-to-previous attacker value + Menptr[cnt].ubNextToPreviousAttackerID = NOBODY; + } } } // Fix robot if ( guiCurrentSaveGameVersion <= 87 ) { - SOLDIERTYPE * pSoldier; - if ( gMercProfiles[ ROBOT ].inv[ VESTPOS ] == SPECTRA_VEST ) { // update this @@ -6747,7 +6738,8 @@ BOOLEAN LoadSoldierStructure( HWFILE hFile ) gMercProfiles[ ROBOT ].inv[ HELMETPOS ] = SPECTRA_HELMET_18; gMercProfiles[ ROBOT ].inv[ LEGPOS ] = SPECTRA_LEGGINGS_18; gMercProfiles[ ROBOT ].bAgility = 50; - pSoldier = FindSoldierByProfileID( ROBOT, FALSE ); + + SOLDIERTYPE* pSoldier = FindSoldierByProfileID( ROBOT, FALSE ); if ( pSoldier ) { pSoldier->inv[ VESTPOS ].usItem = SPECTRA_VEST_18; diff --git a/Strategic/Map Screen Interface Map Inventory.cpp b/Strategic/Map Screen Interface Map Inventory.cpp index c949e1c5..b4bbc54c 100644 --- a/Strategic/Map Screen Interface Map Inventory.cpp +++ b/Strategic/Map Screen Interface Map Inventory.cpp @@ -3499,9 +3499,8 @@ void HandleMouseInCompatableItemForMapSectorInventory( INT32 iCurrentSlot ) fMapPanelDirty = TRUE; #endif } - fChangedInventorySlots = FALSE; - return; + fChangedInventorySlots = FALSE; } void ResetMapSectorInventoryPoolHighLights( void ) @@ -3509,15 +3508,13 @@ void ResetMapSectorInventoryPoolHighLights( void ) INT32 iCounter = 0; // now reset the highlight list for the map sector inventory - for ( iCounter = 0; iCounter < MAP_INVENTORY_POOL_SLOT_COUNT; iCounter++ ) + for ( iCounter = 0; iCounter < MAP_INVENTORY_POOL_SLOT_COUNT; ++iCounter ) { if ( fMapInventoryItemCompatable[ iCounter ] ) { fMapInventoryItemCompatable[ iCounter ] = FALSE; } } - - return; } void HandleMapSectorInventory( void ) { @@ -3527,8 +3524,6 @@ void HandleMapSectorInventory( void ) { HandleMouseInCompatableItemForMapSectorInventory( iCurrentlyHighLightedItem ); } - - return; } @@ -3548,10 +3543,6 @@ BOOLEAN IsMapScreenWorldItemVisibleInMapInventory( WORLDITEM *pWorldItem ) { return ( TRUE ); } - else - { - return( FALSE ); - } } return( FALSE ); @@ -3577,8 +3568,7 @@ void CheckGridNoOfItemsInMapScreenMapInventory() UINT32 uiNumFlagsNotSet = 0; INT32 iTotalNumberItems = GetTotalNumberOfItems( ); - - for( iCnt=0; iCntfInfectionSeverity ); + swprintf( sString, L"%4.1f%%", 100 * pSectorInfo->fInfectionSeverity ); FindFontCenterCoordinates( sXCorner, sYCorner, MAP_GRID_X, MAP_GRID_Y, sString, MapItemsFont, &usXPos, &usYPos ); diff --git a/Tactical/Tactical Save.cpp b/Tactical/Tactical Save.cpp index 04209eec..2c914466 100644 --- a/Tactical/Tactical Save.cpp +++ b/Tactical/Tactical Save.cpp @@ -336,14 +336,11 @@ extern int gCivPreservedTempFileVersion[256]; BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile ) { UNDERGROUND_SECTORINFO *TempNode = gpUndergroundSectorInfoHead; - INT16 sMapX; - INT16 sMapY; UINT32 uiPercentage; - UINT32 iCounter = 0; - + UINT32 iCounter = 0; // HACK FOR GABBY - if ( (gTacticalStatus.uiFlags & LOADING_SAVED_GAME) && guiCurrentSaveGameVersion < 81 ) + if ( guiCurrentSaveGameVersion < 81 && (gTacticalStatus.uiFlags & LOADING_SAVED_GAME) ) { if ( gMercProfiles[ GABBY ].bMercStatus != MERC_IS_DEAD ) { @@ -372,9 +369,9 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile ) // //First look through the above ground sectors - for( sMapY=1; sMapY<=16; sMapY++ ) + for ( INT16 sMapY = 1; sMapY < MAP_WORLD_Y - 1; ++sMapY ) { - for( sMapX=1; sMapX<=16; sMapX++ ) + for ( INT16 sMapX = 1; sMapX < MAP_WORLD_X - 1; ++sMapX ) { if( SectorInfo[ SECTOR( sMapX,sMapY) ].uiFlags & SF_ITEM_TEMP_FILE_EXISTS ) { @@ -384,13 +381,14 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile ) //sync up the temp file data to the sector structure data SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems( sMapX, sMapY, 0, TRUE ); - if (guiCurrentSaveGameVersion != SAVE_GAME_VERSION) + // Flugente: commented out, as the update now happens in SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems, which will save us one loading routine per inventory + /*if (guiCurrentSaveGameVersion != SAVE_GAME_VERSION) { for (int z = 0; z < 4; ++z) { UpdateWorldItemsTempFile(sMapX, sMapY, z); } - } + }*/ } if( SectorInfo[ SECTOR( sMapX,sMapY) ].uiFlags & SF_ROTTING_CORPSE_TEMP_FILE_EXISTS ) @@ -437,7 +435,7 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile ) if ( !RetrieveTempFileFromSavedGame( hFile, SF_CIV_PRESERVED_TEMP_FILE_EXISTS, sMapX, sMapY, 0 ) ) return FALSE; - if ( (gTacticalStatus.uiFlags & LOADING_SAVED_GAME) && guiCurrentSaveGameVersion < 78 ) + if ( guiCurrentSaveGameVersion < 78 && (gTacticalStatus.uiFlags & LOADING_SAVED_GAME) ) { CHAR8 pMapName[ 128 ]; @@ -447,7 +445,6 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile ) // turn off the flag SectorInfo[ SECTOR( sMapX,sMapY) ].uiFlags &= (~SF_CIV_PRESERVED_TEMP_FILE_EXISTS); - } gCivPreservedTempFileVersion[SECTOR( sMapX,sMapY)] = guiCurrentSaveGameVersion; @@ -464,11 +461,10 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile ) if ( !RetrieveTempFileFromSavedGame( hFile, SF_LIGHTING_EFFECTS_TEMP_FILE_EXISTS, sMapX, sMapY, 0 ) ) return FALSE; } - - + //if any other file is to be saved - iCounter++; + ++iCounter; //update the progress bar uiPercentage = (iCounter * 100) / (255); @@ -476,8 +472,7 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile ) RenderProgressBar( 0, uiPercentage ); } } - - + //then look throught all the underground sectors while( TempNode ) { @@ -496,7 +491,6 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile ) return FALSE; } - if( TempNode->uiFlags & SF_MAP_MODIFICATIONS_TEMP_FILE_EXISTS ) { if ( !RetrieveTempFileFromSavedGame( hFile, SF_MAP_MODIFICATIONS_TEMP_FILE_EXISTS, TempNode->ubSectorX, TempNode->ubSectorY, TempNode->ubSectorZ ) ) @@ -533,7 +527,8 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile ) { if ( !RetrieveTempFileFromSavedGame( hFile, SF_CIV_PRESERVED_TEMP_FILE_EXISTS, TempNode->ubSectorX, TempNode->ubSectorY, TempNode->ubSectorZ ) ) return FALSE; - if ( (gTacticalStatus.uiFlags & LOADING_SAVED_GAME) && guiCurrentSaveGameVersion < 78 ) + + if ( guiCurrentSaveGameVersion < 78 && (gTacticalStatus.uiFlags & LOADING_SAVED_GAME) ) { CHAR8 pMapName[ 128 ]; @@ -543,9 +538,7 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile ) // turn off the flag TempNode->uiFlags &= (~SF_CIV_PRESERVED_TEMP_FILE_EXISTS); - } - } if( TempNode->uiFlags & SF_SMOKE_EFFECTS_TEMP_FILE_EXISTS ) @@ -3312,17 +3305,13 @@ UINT32 GetNumberOfVisibleWorldItemsFromSectorStructureForSector( INT16 sMapX, IN void SetNumberOfVisibleWorldItemsInSectorStructureForSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT32 uiNumberOfItems ) { - UNDERGROUND_SECTORINFO *pSector=NULL; - //if the sector is above ground if( bMapZ == 0 ) { - SectorInfo[ SECTOR( sMapX, sMapY ) ].uiNumberOfWorldItemsInTempFileThatCanBeSeenByPlayer = uiNumberOfItems; - } else { //find the underground sector - pSector = FindUnderGroundSector( sMapX, sMapY, bMapZ ); + UNDERGROUND_SECTORINFO* pSector = FindUnderGroundSector( sMapX, sMapY, bMapZ ); if( pSector != NULL ) { //get the number of items @@ -3365,20 +3354,30 @@ void SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems( INT16 sMapX, INT // now load into mem LoadWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, pTotalSectorList ); - } - // now run through list and - //for( iCounter = 0; ( UINT32 )( iCounter )< uiTotalNumberOfRealItems; iCounter++ ) - for( iCounter = 0; iCounter < uiTotalNumberOfItems; iCounter++ ) - { - // if visible to player, then state fact - if( IsMapScreenWorldItemVisibleInMapInventory( &pTotalSectorList[ iCounter ] ) ) + // now run through list and + //for( iCounter = 0; ( UINT32 )( iCounter )< uiTotalNumberOfRealItems; iCounter++ ) + for ( iCounter = 0; iCounter < uiTotalNumberOfItems; ++iCounter ) { - uiItemCount += pTotalSectorList[ iCounter ].object.ubNumberOfObjects; + // if visible to player, then state fact + if ( IsMapScreenWorldItemVisibleInMapInventory( &pTotalSectorList[iCounter] ) ) + { + uiItemCount += pTotalSectorList[iCounter].object.ubNumberOfObjects; + } + } + + // Flugente: if we load a game, we would save the data again in UpdateWorldItemsTempFile. + // But that function simply loads the data again and writes it. If we do the saving here, we can at least save the entire 'load it again' part + if ( fLoadingGame && guiCurrentSaveGameVersion != SAVE_GAME_VERSION ) + { + int backup = guiCurrentSaveGameVersion; + guiCurrentSaveGameVersion = SAVE_GAME_VERSION; + SaveWorldItemsToTempItemFile( sMapX, sMapY, bMapZ, uiTotalNumberOfItems, pTotalSectorList ); + guiCurrentSaveGameVersion = backup; } } - - #ifdef JA2BETAVERSION + +#ifdef JA2BETAVERSION if( fLoadingGame && guiCurrentSaveGameVersion >= 86 ) { UINT32 uiReported = GetNumberOfVisibleWorldItemsFromSectorStructureForSector( sMapX, sMapY, bMapZ ); @@ -3386,7 +3385,7 @@ void SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems( INT16 sMapX, INT if( uiItemCount != uiReported ) ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_BETAVERSION, L"SynchronizeItemTempFile() Error! Reported %d, should be %d", uiReported, uiItemCount ); } - #endif +#endif //record the number of items SetNumberOfVisibleWorldItemsInSectorStructureForSector( sMapX, sMapY, bMapZ, uiItemCount );