World items patch (by Asdow).

Adds timing logs to savegame function, similar to how we already had in loading a save file. 
Uses a global struct for unloaded sectors' inventory instead of using map item temp files every time unloaded inventory is accessed.
From timing loading and saving functions with a save that has dozens of sectors with hundreds of items each, saving is a little bit slower than before, because map item temp files have to be written to disk just before the save, when that wasn't the case before (from ~0.3 s -> ~0.5s). It is offset by a decrease in loading a game (from ~1.1s -> 0.745s), once an older save is saved at least once. Any unloaded sector inventory access during gameplay is considerably faster and for example the autoresolve lag when militia is using sector equipment is completely gone for me.
Preserves save game compatibility

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9277 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Sevenfm
2022-01-26 01:02:30 +00:00
parent be14552e32
commit 0fdaba84f6
13 changed files with 590 additions and 599 deletions
+119 -12
View File
@@ -189,6 +189,7 @@ extern void initMapViewAndBorderCoordinates(void);
UINT32 guiNumberOfMapTempFiles; //Test purposes UINT32 guiNumberOfMapTempFiles; //Test purposes
UINT32 guiSizeOfTempFiles; UINT32 guiSizeOfTempFiles;
CHAR gzNameOfMapTempFile[128]; CHAR gzNameOfMapTempFile[128];
//#define LOADSAVEGAME_LOGTIME 1
#endif #endif
extern SOLDIERTYPE *gpSMCurrentMerc; extern SOLDIERTYPE *gpSMCurrentMerc;
@@ -732,7 +733,6 @@ BOOLEAN LBENODE::Save( HWFILE hFile, bool fSavingMap )
return TRUE; return TRUE;
} }
BOOLEAN LoadArmsDealerInventoryFromSavedGameFile( HWFILE hFile ) BOOLEAN LoadArmsDealerInventoryFromSavedGameFile( HWFILE hFile )
{ {
UINT32 uiNumBytesRead; UINT32 uiNumBytesRead;
@@ -3508,6 +3508,15 @@ BOOLEAN SaveGame( int ubSaveGameID, STR16 pGameDesc )
return( FALSE ); return( FALSE );
alreadySaving = true; alreadySaving = true;
#ifdef LOADSAVEGAME_LOGTIME
// Flugente: log how long this takes
clock_t starttime = clock();
clock_t t0;
clock_t t1 = starttime;
FILE* fp_timelog = fopen("LoadSavedGame_TimeLog.txt", "a");
#endif
//clear out the save game header //clear out the save game header
memset( &SaveGameHeader, 0, sizeof( SAVED_GAME_HEADER ) ); memset( &SaveGameHeader, 0, sizeof( SAVED_GAME_HEADER ) );
@@ -3686,6 +3695,16 @@ BOOLEAN SaveGame( int ubSaveGameID, STR16 pGameDesc )
//Create the name of the file //Create the name of the file
CreateSavedGameFileNameFromNumber( ubSaveGameID, zSaveGameName ); CreateSavedGameFileNameFromNumber( ubSaveGameID, zSaveGameName );
#if LOADSAVEGAME_LOGTIME
if (fp_timelog)
{
fprintf(fp_timelog, "Save savegame: %s\n", zSaveGameName);
t0 = t1;
t1 = clock();
fprintf(fp_timelog, "Shutdown stuff\t\t\t\t\t\t\t\t\t\t\t\t\t: %fs\n", ((float)(t1 - t0) / CLOCKS_PER_SEC));
}
#endif
//if the file already exists, delete it //if the file already exists, delete it
if( FileExists( zSaveGameName ) ) if( FileExists( zSaveGameName ) )
@@ -3820,6 +3839,14 @@ BOOLEAN SaveGame( int ubSaveGameID, STR16 pGameDesc )
#ifdef JA2BETAVERSION #ifdef JA2BETAVERSION
SaveGameFilePosition( FileGetPos( hFile ), "Tactical Status" ); SaveGameFilePosition( FileGetPos( hFile ), "Tactical Status" );
#endif #endif
#if LOADSAVEGAME_LOGTIME
if (fp_timelog)
{
t0 = t1;
t1 = clock();
fprintf(fp_timelog, "SaveTacticalStatusFromSavedGame done\t\t\t\t\t\t\t: %fs\n", ((float)(t1 - t0) / CLOCKS_PER_SEC));
}
#endif
@@ -3859,6 +3886,14 @@ BOOLEAN SaveGame( int ubSaveGameID, STR16 pGameDesc )
#ifdef JA2BETAVERSION #ifdef JA2BETAVERSION
SaveGameFilePosition( FileGetPos( hFile ), "Laptop Info" ); SaveGameFilePosition( FileGetPos( hFile ), "Laptop Info" );
#endif #endif
#if LOADSAVEGAME_LOGTIME
if (fp_timelog)
{
t0 = t1;
t1 = clock();
fprintf(fp_timelog, "SaveLaptopInfoFromSavedGame done\t\t\t\t\t\t\t\t: %fs\n", ((float)(t1 - t0) / CLOCKS_PER_SEC));
}
#endif
// //
// Save the merc profiles // Save the merc profiles
@@ -3888,6 +3923,14 @@ BOOLEAN SaveGame( int ubSaveGameID, STR16 pGameDesc )
#ifdef JA2BETAVERSION #ifdef JA2BETAVERSION
SaveGameFilePosition( FileGetPos( hFile ), "Soldier Structure" ); SaveGameFilePosition( FileGetPos( hFile ), "Soldier Structure" );
#endif #endif
#if LOADSAVEGAME_LOGTIME
if (fp_timelog)
{
t0 = t1;
t1 = clock();
fprintf(fp_timelog, "SaveSoldierStructure done\t\t\t\t\t\t\t\t\t\t: %fs\n", ((float)(t1 - t0) / CLOCKS_PER_SEC));
}
#endif
//Save the Finaces Data file //Save the Finaces Data file
@@ -3948,6 +3991,14 @@ BOOLEAN SaveGame( int ubSaveGameID, STR16 pGameDesc )
#ifdef JA2BETAVERSION #ifdef JA2BETAVERSION
SaveGameFilePosition( FileGetPos( hFile ), "Strategic Information" ); SaveGameFilePosition( FileGetPos( hFile ), "Strategic Information" );
#endif #endif
#if LOADSAVEGAME_LOGTIME
if (fp_timelog)
{
t0 = t1;
t1 = clock();
fprintf(fp_timelog, "SaveStrategicInfoFromSavedFile done\t\t\t\t\t\t\t\t: %fs\n", ((float)(t1 - t0) / CLOCKS_PER_SEC));
}
#endif
/*// Flugente: Save the strategic supply /*// Flugente: Save the strategic supply
if( !SaveStrategicSupplyToSavedFile( hFile ) ) if( !SaveStrategicSupplyToSavedFile( hFile ) )
@@ -3995,6 +4046,14 @@ BOOLEAN SaveGame( int ubSaveGameID, STR16 pGameDesc )
#ifdef JA2BETAVERSION #ifdef JA2BETAVERSION
SaveGameFilePosition( FileGetPos( hFile ), "Strategic Movement Groups" ); SaveGameFilePosition( FileGetPos( hFile ), "Strategic Movement Groups" );
#endif #endif
#if LOADSAVEGAME_LOGTIME
if (fp_timelog)
{
t0 = t1;
t1 = clock();
fprintf(fp_timelog, "SaveStrategicMovementGroupsFromSavedGameFile done\t\t\t\t: %fs\n", ((float)(t1 - t0) / CLOCKS_PER_SEC));
}
#endif
@@ -4009,7 +4068,15 @@ BOOLEAN SaveGame( int ubSaveGameID, STR16 pGameDesc )
#ifdef JA2BETAVERSION #ifdef JA2BETAVERSION
SaveGameFilePosition( FileGetPos( hFile ), "All the Map Temp files" ); SaveGameFilePosition( FileGetPos( hFile ), "All the Map Temp files" );
#endif #endif
#if LOADSAVEGAME_LOGTIME
if (fp_timelog)
{
t0 = t1;
t1 = clock();
fprintf(fp_timelog, "SaveMapTempFilesFromSavedGameFile done\t\t\t\t\t\t\t: %fs\n", ((float)(t1 - t0) / CLOCKS_PER_SEC));
}
#endif
if( !SaveQuestInfoToSavedGameFile( hFile ) ) if( !SaveQuestInfoToSavedGameFile( hFile ) )
{ {
ScreenMsg( FONT_MCOLOR_WHITE, MSG_ERROR, L"ERROR writing quest info"); ScreenMsg( FONT_MCOLOR_WHITE, MSG_ERROR, L"ERROR writing quest info");
@@ -4172,6 +4239,14 @@ BOOLEAN SaveGame( int ubSaveGameID, STR16 pGameDesc )
#ifdef JA2BETAVERSION #ifdef JA2BETAVERSION
SaveGameFilePosition( FileGetPos( hFile ), "Militia Movement" ); SaveGameFilePosition( FileGetPos( hFile ), "Militia Movement" );
#endif #endif
#if LOADSAVEGAME_LOGTIME
if (fp_timelog)
{
t0 = t1;
t1 = clock();
fprintf(fp_timelog, "SaveMilitiaMovementInformationFromSavedGameFile done\t\t\t: %fs\n", ((float)(t1 - t0) / CLOCKS_PER_SEC));
}
#endif
if( !SaveBulletStructureToSaveGameFile( hFile ) ) if( !SaveBulletStructureToSaveGameFile( hFile ) )
{ {
@@ -4409,7 +4484,15 @@ BOOLEAN SaveGame( int ubSaveGameID, STR16 pGameDesc )
#ifdef JA2BETAVERSION #ifdef JA2BETAVERSION
SaveGameFilePosition( FileGetPos( hFile ), "Lua global" ); SaveGameFilePosition( FileGetPos( hFile ), "Lua global" );
#endif #endif
#if LOADSAVEGAME_LOGTIME
if (fp_timelog)
{
t0 = t1;
t1 = clock();
fprintf(fp_timelog, "SaveLuaGlobalFromLoadGameFile done\t\t\t\t\t\t\t\t: %fs\n", ((float)(t1 - t0) / CLOCKS_PER_SEC));
}
#endif
if( !SaveDataSaveToSaveGameFile( hFile ) ) if( !SaveDataSaveToSaveGameFile( hFile ) )
{ {
ScreenMsg( FONT_MCOLOR_WHITE, MSG_ERROR, L"ERROR writing save data"); ScreenMsg( FONT_MCOLOR_WHITE, MSG_ERROR, L"ERROR writing save data");
@@ -4506,6 +4589,14 @@ BOOLEAN SaveGame( int ubSaveGameID, STR16 pGameDesc )
ScreenMsg( FONT_MCOLOR_WHITE, MSG_ERROR, L"ERROR writing rebel command data" ); ScreenMsg( FONT_MCOLOR_WHITE, MSG_ERROR, L"ERROR writing rebel command data" );
goto FAILED_TO_SAVE; goto FAILED_TO_SAVE;
} }
#if LOADSAVEGAME_LOGTIME
if (fp_timelog)
{
t0 = t1;
t1 = clock();
fprintf(fp_timelog, "File read done\t\t\t\t\t\t\t\t\t\t\t\t\t: %fs\n", ((float)(t1 - t0) / CLOCKS_PER_SEC));
}
#endif
//Close the saved game file //Close the saved game file
FileClose( hFile ); FileClose( hFile );
@@ -4584,6 +4675,24 @@ BOOLEAN SaveGame( int ubSaveGameID, STR16 pGameDesc )
alreadySaving = false; alreadySaving = false;
#if LOADSAVEGAME_LOGTIME
if (fp_timelog)
{
t0 = t1;
t1 = clock();
fprintf(fp_timelog, "Update functions\t\t\t\t\t\t\t\t\t\t\t\t: %fs\n", ((float)(t1 - t0) / CLOCKS_PER_SEC));
}
if (fp_timelog)
{
t0 = starttime;
t1 = clock();
fprintf(fp_timelog, "SaveSavedGame total\t\t\t\t\t\t\t\t\t\t\t\t: %fs\n\n", ((float)(t1 - t0) / CLOCKS_PER_SEC));
}
if (fp_timelog)
fclose(fp_timelog);
#endif
return( TRUE ); return( TRUE );
//if there is an error saving the game //if there is an error saving the game
@@ -4636,7 +4745,6 @@ UINT32 guiBrokenSaveGameVersion = 0;
extern int gEnemyPreservedTempFileVersion[256]; extern int gEnemyPreservedTempFileVersion[256];
extern int gCivPreservedTempFileVersion[256]; extern int gCivPreservedTempFileVersion[256];
#define LOADSAVEGAME_LOGTIME 1
#include "time.h" #include "time.h"
@@ -7286,11 +7394,11 @@ BOOLEAN LoadPtrInfo( PTR *pData, UINT32 uiSizeOfObject, HWFILE hFile )
BOOLEAN SaveFilesToSavedGame( STR pSrcFileName, HWFILE hFile ) BOOLEAN SaveFilesToSavedGame( STR pSrcFileName, HWFILE hFile )
{ {
UINT32 uiFileSize; UINT32 uiFileSize=0;
UINT32 uiNumBytesWritten=0; UINT32 uiNumBytesWritten=0;
HWFILE hSrcFile=NULL; HWFILE hSrcFile=NULL;
UINT8 *pData; UINT8 *pData=NULL;
UINT32 uiNumBytesRead; UINT32 uiNumBytesRead=0;
if(FileExists(pSrcFileName)) if(FileExists(pSrcFileName))
{ {
@@ -7366,14 +7474,13 @@ BOOLEAN SaveFilesToSavedGame( STR pSrcFileName, HWFILE hFile )
return( TRUE ); return( TRUE );
} }
BOOLEAN LoadFilesFromSavedGame( STR pSrcFileName, HWFILE hFile ) BOOLEAN LoadFilesFromSavedGame( STR pSrcFileName, HWFILE hFile )
{ {
UINT32 uiFileSize; UINT32 uiFileSize=0;
UINT32 uiNumBytesWritten=0; UINT32 uiNumBytesWritten=0;
HWFILE hSrcFile; HWFILE hSrcFile=0;
UINT8 *pData; UINT8 *pData=NULL;
UINT32 uiNumBytesRead; UINT32 uiNumBytesRead=0;
//If the source file exists, delete it //If the source file exists, delete it
if( FileExists( pSrcFileName ) ) if( FileExists( pSrcFileName ) )
+12 -12
View File
@@ -89,6 +89,7 @@
class OBJECTTYPE; class OBJECTTYPE;
class SOLDIERTYPE; class SOLDIERTYPE;
extern int POP_UP_BOX_X; extern int POP_UP_BOX_X;
extern WorldItems gAllWorldItems;
#include "MilitiaSquads.h" #include "MilitiaSquads.h"
// HEADROCK HAM 3.5: Include Facility data // HEADROCK HAM 3.5: Include Facility data
@@ -8891,17 +8892,17 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
else else
{ {
// not loaded, load // not loaded, load
// get total number, visable and invisible
BOOLEAN fReturn = GetNumberOfWorldItemsFromTempItemFile( targetX, targetY, bZ, &( uiTotalNumberOfRealItems_Target ), FALSE );
Assert( fReturn );
if( uiTotalNumberOfRealItems_Target > 0 )
{ {
// allocate space for the list const auto i = FindWorldItemSector(targetX, targetY, bZ);
pWorldItem_Target.resize(uiTotalNumberOfRealItems_Target);//dnl ch75 271013 if (i != -1)
{
// now load into mem uiTotalNumberOfRealItems_Target = gAllWorldItems.NumItems[i];
LoadWorldItemsFromTempItemFile( targetX, targetY, bZ, pWorldItem_Target ); pWorldItem_Target = gAllWorldItems.Items[i];
}
else
{
uiTotalNumberOfRealItems_Target = 0;
}
} }
} }
@@ -9027,8 +9028,7 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
} }
else else
{ {
//Save the Items to the the file UpdateWorldItems(targetX, targetY, bZ, uiTotalNumberOfRealItems_Target, pWorldItem_Target);
SaveWorldItemsToTempItemFile( targetX, targetY, bZ, uiTotalNumberOfRealItems_Target, pWorldItem_Target );
} }
// award a bit of experience to the movers // award a bit of experience to the movers
+16 -32
View File
@@ -55,6 +55,7 @@ void HourlyFactoryUpdate(); // Flugente: update factories
void HourlySnitchUpdate(); // anv: decreasing cooldown after exposition void HourlySnitchUpdate(); // anv: decreasing cooldown after exposition
extern SECTOR_EXT_DATA SectorExternalData[256][4]; extern SECTOR_EXT_DATA SectorExternalData[256][4];
extern WorldItems gAllWorldItems;
extern INT32 GetCurrentBalance( void ); extern INT32 GetCurrentBalance( void );
extern void PayOffSkyriderDebtIfAny( ); extern void PayOffSkyriderDebtIfAny( );
@@ -841,37 +842,30 @@ void HourlyStealUpdate()
BOOLEAN RemoveItemInSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT16 usItem, UINT32 usNumToRemove ) BOOLEAN RemoveItemInSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT16 usItem, UINT32 usNumToRemove )
{ {
// open sector inv
UINT32 uiTotalNumberOfRealItems = 0; UINT32 uiTotalNumberOfRealItems = 0;
std::vector<WORLDITEM> pWorldItem;//dnl ch75 271013 std::vector<WORLDITEM> pWorldItem;//dnl ch75 271013
BOOLEAN fReturn = FALSE;
// open sector inventory
if ( ( gWorldSectorX == sSectorX ) && ( gWorldSectorY == sSectorY ) && ( gbWorldSectorZ == bSectorZ ) ) if ( ( gWorldSectorX == sSectorX ) && ( gWorldSectorY == sSectorY ) && ( gbWorldSectorZ == bSectorZ ) )
{ {
uiTotalNumberOfRealItems = guiNumWorldItems; uiTotalNumberOfRealItems = guiNumWorldItems;
pWorldItem = gWorldItems; pWorldItem = gWorldItems;
} }
else else
{ {
// not loaded, load // Check for unloaded sector
// get total number, visable and invisible const auto i = FindWorldItemSector( sSectorX, sSectorY, bSectorZ);
fReturn = GetNumberOfWorldItemsFromTempItemFile( sSectorX, sSectorY, bSectorZ, &( uiTotalNumberOfRealItems ), FALSE ); if (i != -1)
Assert( fReturn );
if ( uiTotalNumberOfRealItems > 0 )
{ {
// allocate space for the list uiTotalNumberOfRealItems = gAllWorldItems.NumItems[i];
pWorldItem.resize( uiTotalNumberOfRealItems );//dnl ch75 271013 pWorldItem = gAllWorldItems.Items[i];
// now load into mem
LoadWorldItemsFromTempItemFile( sSectorX, sSectorY, bSectorZ, pWorldItem );
} }
} }
if ( !uiTotalNumberOfRealItems ) if ( !uiTotalNumberOfRealItems )
return FALSE; return FALSE;
BOOLEAN removedsth = FALSE; BOOLEAN removedsth = FALSE;
OBJECTTYPE* pObj = NULL; OBJECTTYPE* pObj = NULL;
for ( UINT32 uiCount = 0; uiCount < uiTotalNumberOfRealItems && usNumToRemove > 0; ++uiCount ) // ... for all items in the world ... for ( UINT32 uiCount = 0; uiCount < uiTotalNumberOfRealItems && usNumToRemove > 0; ++uiCount ) // ... for all items in the world ...
@@ -906,7 +900,6 @@ BOOLEAN RemoveItemInSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT1
if ( removedsth ) if ( removedsth )
{ {
// save the changed inventory // save the changed inventory
// open sector inv
if ( ( gWorldSectorX == sSectorX ) && ( gWorldSectorY == sSectorY ) && ( gbWorldSectorZ == bSectorZ ) ) if ( ( gWorldSectorX == sSectorX ) && ( gWorldSectorY == sSectorY ) && ( gbWorldSectorZ == bSectorZ ) )
{ {
guiNumWorldItems = uiTotalNumberOfRealItems; guiNumWorldItems = uiTotalNumberOfRealItems;
@@ -914,8 +907,7 @@ BOOLEAN RemoveItemInSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT1
} }
else else
{ {
//Save the Items to the the file UpdateWorldItems(sSectorX, sSectorY, bSectorZ, uiTotalNumberOfRealItems, pWorldItem);
SaveWorldItemsToTempItemFile( sSectorX, sSectorY, bSectorZ, uiTotalNumberOfRealItems, pWorldItem );
} }
return TRUE; return TRUE;
@@ -927,35 +919,27 @@ BOOLEAN RemoveItemInSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT1
UINT32 CountAccessibleItemsInSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT16 usItem ) UINT32 CountAccessibleItemsInSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT16 usItem )
{ {
UINT32 numfound = 0; UINT32 numfound = 0;
// open sector inv
UINT32 uiTotalNumberOfRealItems = 0; UINT32 uiTotalNumberOfRealItems = 0;
std::vector<WORLDITEM> pWorldItem;//dnl ch75 271013 std::vector<WORLDITEM> pWorldItem;//dnl ch75 271013
BOOLEAN fReturn = FALSE;
// open sector inv
if ( ( gWorldSectorX == sSectorX ) && ( gWorldSectorY == sSectorY ) && ( gbWorldSectorZ == bSectorZ ) ) if ( ( gWorldSectorX == sSectorX ) && ( gWorldSectorY == sSectorY ) && ( gbWorldSectorZ == bSectorZ ) )
{ {
uiTotalNumberOfRealItems = guiNumWorldItems; uiTotalNumberOfRealItems = guiNumWorldItems;
pWorldItem = gWorldItems; pWorldItem = gWorldItems;
} }
else else
{ {
// not loaded, load // Check for unloaded sector
// get total number, visable and invisible const auto i = FindWorldItemSector(sSectorX, sSectorY, bSectorZ);
fReturn = GetNumberOfWorldItemsFromTempItemFile( sSectorX, sSectorY, bSectorZ, &( uiTotalNumberOfRealItems ), FALSE ); if (i != -1)
Assert( fReturn );
if ( uiTotalNumberOfRealItems > 0 )
{ {
// allocate space for the list uiTotalNumberOfRealItems = gAllWorldItems.NumItems[i];
pWorldItem.resize( uiTotalNumberOfRealItems );//dnl ch75 271013 pWorldItem = gAllWorldItems.Items[i];
// now load into mem
LoadWorldItemsFromTempItemFile( sSectorX, sSectorY, bSectorZ, pWorldItem );
} }
} }
OBJECTTYPE* pObj = NULL; OBJECTTYPE* pObj = NULL;
for ( UINT32 uiCount = 0; uiCount < uiTotalNumberOfRealItems; ++uiCount ) // ... for all items in the world ... for ( UINT32 uiCount = 0; uiCount < uiTotalNumberOfRealItems; ++uiCount ) // ... for all items in the world ...
{ {
+12 -15
View File
@@ -82,6 +82,7 @@ extern UINT8 gubWaitingForAllMercsToExitCode;
extern BOOLEAN gfDoneWithSplashScreen; extern BOOLEAN gfDoneWithSplashScreen;
extern UINT32 iStringToUseLua; extern UINT32 iStringToUseLua;
extern INT8 Test; extern INT8 Test;
extern INT32 GetAmountOfWorldItems(INT16 x, INT16 y, INT16 z);
static int l_HireMerc (lua_State *L); static int l_HireMerc (lua_State *L);
@@ -629,7 +630,7 @@ static int l_AddSameDayStrategicEvent(lua_State *L);
static int l_FunctionCheckForKingpinsMoneyMissing(lua_State *L); static int l_FunctionCheckForKingpinsMoneyMissing(lua_State *L);
static int l_MoveItemPools(lua_State *L); static int l_MoveItemPools(lua_State *L);
static int l_GetNumberOfWorldItemsFromTempItemFile(lua_State *L); static int l_GetNumberOfWorldItems(lua_State *L);
static int l_gubFact(lua_State *L); static int l_gubFact(lua_State *L);
@@ -1276,7 +1277,7 @@ void IniFunction(lua_State *L, BOOLEAN bQuests )
lua_register(L, "GetWorldItemsObjectItem", l_gWorldItemsObjectItem); lua_register(L, "GetWorldItemsObjectItem", l_gWorldItemsObjectItem);
lua_register(L, "GetWorldItemsObjectDataMoney", l_gWorldItemsObjectDataMoney); lua_register(L, "GetWorldItemsObjectDataMoney", l_gWorldItemsObjectDataMoney);
lua_register(L, "MoveItemPools", l_MoveItemPools); lua_register(L, "MoveItemPools", l_MoveItemPools);
lua_register(L, "GetNumberOfWorldItemsFromTempItemFile", l_GetNumberOfWorldItemsFromTempItemFile); lua_register(L, "GetNumberOfWorldItems", l_GetNumberOfWorldItems);
lua_register(L, "ItemExistsAtLocation", l_ItemExistsAtLocation); lua_register(L, "ItemExistsAtLocation", l_ItemExistsAtLocation);
lua_register(L, "AddCreateItemToPool", l_CreateItemToPool); lua_register(L, "AddCreateItemToPool", l_CreateItemToPool);
lua_register(L, "AddCreateItemsToUnLoadedSector", l_CreateToUnLoadedSector); lua_register(L, "AddCreateItemsToUnLoadedSector", l_CreateToUnLoadedSector);
@@ -4934,23 +4935,19 @@ return 0;
} }
static int l_GetNumberOfWorldItemsFromTempItemFile(lua_State *L) static int l_GetNumberOfWorldItems(lua_State *L)
{ {
if ( lua_gettop(L) >= 5 ) if ( lua_gettop(L) >= 3 )
{ {
INT16 sMapX = lua_tointeger(L,1); INT16 sMapX = lua_tointeger(L,1);
INT16 sMapY = lua_tointeger(L,2); INT16 sMapY = lua_tointeger(L,2);
INT8 bMapZ = lua_tointeger(L,3); INT8 bMapZ = lua_tointeger(L,3);
UINT32 puiNumberOfItems = lua_tointeger(L,4);
BOOLEAN fIfEmptyCreate = lua_toboolean(L,5);
BOOLEAN Bool = GetNumberOfWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, &puiNumberOfItems, fIfEmptyCreate );
lua_pushboolean(L, Bool);
}
INT32 NumItems = GetAmountOfWorldItems(sMapX, sMapY, bMapZ);
lua_pushinteger(L, NumItems);
}
return 1; return 1;
} }
@@ -50,6 +50,7 @@
class OBJECTTYPE; class OBJECTTYPE;
class SOLDIERTYPE; class SOLDIERTYPE;
extern UILayout_Map UI_MAP; extern UILayout_Map UI_MAP;
extern WorldItems gAllWorldItems;
// Flugente: external sector data // Flugente: external sector data
extern SECTOR_EXT_DATA SectorExternalData[256][4]; extern SECTOR_EXT_DATA SectorExternalData[256][4];
@@ -1175,8 +1176,7 @@ void SaveSeenAndUnseenItems( void )
} }
else else
{ {
Assert(SaveWorldItemsToTempItemFile(sSelMapX, sSelMapY, iCurrentMapSectorZ, uiNumberOfSeenItems + uiNumberOfUnSeenItems, pInventoryPoolList, FALSE)); UpdateWorldItems(sSelMapX, sSelMapY, iCurrentMapSectorZ, uiNumberOfSeenItems + uiNumberOfUnSeenItems, pInventoryPoolList);
SetNumberOfVisibleWorldItemsInSectorStructureForSector(sSelMapX, sSelMapY, iCurrentMapSectorZ, uiTotalNumberOfVisibleItems);
} }
#endif #endif
} }
@@ -2345,13 +2345,23 @@ void BuildStashForSelectedSector( INT16 sMapX, INT16 sMapY, INT16 sMapZ )
} }
else// if map not loaded, use tempfile to build lists else// if map not loaded, use tempfile to build lists
{ {
Assert(GetNumberOfWorldItemsFromTempItemFile(sMapX, sMapY, (INT8)sMapZ, &uiTotalNumberOfItems, FALSE)); const auto ii = FindWorldItemSector(sMapX, sMapY, (INT8)sMapZ);
if (ii == -1)
{
uiTotalNumberOfItems = 0;
}
else
{
uiTotalNumberOfItems = gAllWorldItems.NumItems[ii];
pInventoryPoolList = gAllWorldItems.Items[ii];
}
uiNumOfSlots = (uiTotalNumberOfItems / MAP_INVENTORY_POOL_SLOT_COUNT + 1) * MAP_INVENTORY_POOL_SLOT_COUNT; uiNumOfSlots = (uiTotalNumberOfItems / MAP_INVENTORY_POOL_SLOT_COUNT + 1) * MAP_INVENTORY_POOL_SLOT_COUNT;
if(pInventoryPoolList.size() < uiNumOfSlots) if(pInventoryPoolList.size() < uiNumOfSlots)
pInventoryPoolList.resize(uiNumOfSlots); pInventoryPoolList.resize(uiNumOfSlots);
if(pUnSeenItems.size() < uiNumOfSlots) if(pUnSeenItems.size() < uiNumOfSlots)
pUnSeenItems.resize(uiNumOfSlots); pUnSeenItems.resize(uiNumOfSlots);
Assert(LoadWorldItemsFromTempItemFile(sMapX, sMapY, (INT8)sMapZ, pInventoryPoolList));
uiNumberOfSeenItems = uiTotalNumberOfItems; uiNumberOfSeenItems = uiTotalNumberOfItems;
uiNumberOfUnSeenItems = 0; uiNumberOfUnSeenItems = 0;
pipl = &pInventoryPoolList.front(); pipl = &pInventoryPoolList.front();
+13 -15
View File
@@ -40,6 +40,7 @@
//forward declarations of common classes to eliminate includes //forward declarations of common classes to eliminate includes
class OBJECTTYPE; class OBJECTTYPE;
class SOLDIERTYPE; class SOLDIERTYPE;
extern WorldItems gAllWorldItems;
#define MEDUNA_ITEM_DROP_OFF_GRIDNO 10959 #define MEDUNA_ITEM_DROP_OFF_GRIDNO 10959
@@ -427,9 +428,6 @@ void HandleDelayedItemsArrival( UINT32 uiReason )
// This function moves all the items that Pablos has stolen // This function moves all the items that Pablos has stolen
// (or items that were delayed) to the arrival location for new shipments, // (or items that were delayed) to the arrival location for new shipments,
INT32 sStartGridNo; INT32 sStartGridNo;
UINT32 uiNumWorldItems, uiLoop;
BOOLEAN fOk;
std::vector<WORLDITEM> pTemp;//dnl ch75 271013
UINT8 ubLoop; UINT8 ubLoop;
if (uiReason == NPC_SYSTEM_EVENT_ACTION_PARAM_BONUS + NPC_ACTION_RETURN_STOLEN_SHIPMENT_ITEMS ) if (uiReason == NPC_SYSTEM_EVENT_ACTION_PARAM_BONUS + NPC_ACTION_RETURN_STOLEN_SHIPMENT_ITEMS )
@@ -502,24 +500,24 @@ void HandleDelayedItemsArrival( UINT32 uiReason )
else else
{ {
// otherwise load the saved items from the item file and change the records of their locations // otherwise load the saved items from the item file and change the records of their locations
fOk = GetNumberOfWorldItemsFromTempItemFile( BOBBYR_SHIPPING_DEST_SECTOR_X, BOBBYR_SHIPPING_DEST_SECTOR_Y, BOBBYR_SHIPPING_DEST_SECTOR_Z, &uiNumWorldItems, FALSE ); std::vector<WORLDITEM> pTemp;
if (!fOk) UINT32 uiNumWorldItems = 0;
const auto ii = FindWorldItemSector(BOBBYR_SHIPPING_DEST_SECTOR_X, BOBBYR_SHIPPING_DEST_SECTOR_Y, BOBBYR_SHIPPING_DEST_SECTOR_Z);
if (ii != -1)
{ {
return; uiNumWorldItems = gAllWorldItems.NumItems[ii];
pTemp = gAllWorldItems.Items[ii];
} }
pTemp.resize(uiNumWorldItems);//dnl ch75 271013
fOk = LoadWorldItemsFromTempItemFile( BOBBYR_SHIPPING_DEST_SECTOR_X, BOBBYR_SHIPPING_DEST_SECTOR_Y, BOBBYR_SHIPPING_DEST_SECTOR_Z, pTemp ); for (UINT32 uiLoop = 0; uiLoop < uiNumWorldItems; uiLoop++)
if (fOk)
{ {
for (uiLoop = 0; uiLoop < uiNumWorldItems; uiLoop++) if (pTemp[uiLoop].sGridNo == PABLOS_STOLEN_DEST_GRIDNO)
{ {
if (pTemp[uiLoop].sGridNo == PABLOS_STOLEN_DEST_GRIDNO) pTemp[uiLoop].sGridNo = BOBBYR_SHIPPING_DEST_GRIDNO;
{
pTemp[uiLoop].sGridNo = BOBBYR_SHIPPING_DEST_GRIDNO;
}
} }
AddWorldItemsToUnLoadedSector( BOBBYR_SHIPPING_DEST_SECTOR_X, BOBBYR_SHIPPING_DEST_SECTOR_Y, BOBBYR_SHIPPING_DEST_SECTOR_Z, 0, uiNumWorldItems, pTemp, TRUE );
} }
AddWorldItemsToUnLoadedSector( BOBBYR_SHIPPING_DEST_SECTOR_X, BOBBYR_SHIPPING_DEST_SECTOR_Y, BOBBYR_SHIPPING_DEST_SECTOR_Z, 0, uiNumWorldItems, pTemp, TRUE );
} }
} }
+7 -5
View File
@@ -46,6 +46,7 @@
#include "Interface.h" #include "Interface.h"
#include "GameInitOptionsScreen.h" #include "GameInitOptionsScreen.h"
extern WorldItems gAllWorldItems;
// loyalty Omerta drops to and maxes out at if the player betrays the rebels // loyalty Omerta drops to and maxes out at if the player betrays the rebels
#define HOSTILE_OMERTA_LOYALTY_RATING 10 #define HOSTILE_OMERTA_LOYALTY_RATING 10
@@ -1128,19 +1129,20 @@ void RemoveRandomItemsInSector( INT16 sSectorX, INT16 sSectorY, INT16 sSectorZ,
if( gWorldSectorX != sSectorX || gWorldSectorY != sSectorY || gbWorldSectorZ != sSectorZ ) if( gWorldSectorX != sSectorX || gWorldSectorY != sSectorY || gbWorldSectorZ != sSectorZ )
{ {
// if the player has never been there, there's no temp file, and 0 items will get returned, preventing any stealing // if the player has never been there, there's no temp file, and 0 items will get returned, preventing any stealing
GetNumberOfWorldItemsFromTempItemFile( sSectorX, sSectorY, ( UINT8 )sSectorZ, &uiNumberOfItems, FALSE ); const auto ii = FindWorldItemSector(sSectorX, sSectorY, (UINT8)sSectorZ);
if (ii != -1)
{
uiNumberOfItems = gAllWorldItems.NumItems[ii];
pItemList = gAllWorldItems.Items[ii];
}
if( uiNumberOfItems == 0 ) if( uiNumberOfItems == 0 )
{ {
return; return;
} }
pItemList.resize(uiNumberOfItems);//dnl ch75 271013
// now load items
LoadWorldItemsFromTempItemFile( sSectorX, sSectorY, ( UINT8 )sSectorZ, pItemList );
uiNewTotal = uiNumberOfItems; uiNewTotal = uiNumberOfItems;
// set up item list ptrs // set up item list ptrs
for( iCounter = 0; iCounter < uiNumberOfItems ; ++iCounter ) for( iCounter = 0; iCounter < uiNumberOfItems ; ++iCounter )
{ {
+1 -2
View File
@@ -3167,8 +3167,7 @@ BOOLEAN EnterSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ )
//Update LastTimePlayerWasInSector //Update LastTimePlayerWasInSector
SetLastTimePlayerWasInSector( ); SetLastTimePlayerWasInSector( );
//Save to tempfile UpdateWorldItems(sSectorX, sSectorY, (INT8)bSectorZ, guiNumWorldItems, gWorldItems);
SaveWorldItemsToTempItemFile( sSectorX, sSectorY, (INT8)bSectorZ, guiNumWorldItems, gWorldItems );
DebugQuestInfo(String("Enter Sector %s%s Level %d", pVertStrings[sSectorY], pHortStrings[sSectorX], bSectorZ)); DebugQuestInfo(String("Enter Sector %s%s Level %d", pVertStrings[sSectorY], pHortStrings[sSectorX], bSectorZ));
+20 -31
View File
@@ -21,6 +21,7 @@
#include "Tactical Save.h" // added by Flugente #include "Tactical Save.h" // added by Flugente
#include "Soldier macros.h" // added by Flugente #include "Soldier macros.h" // added by Flugente
#endif #endif
extern WorldItems gAllWorldItems;
/* /*
#define ENEMYAMMODROPRATE 100 //Madd 50 // % of time enemies drop ammunition #define ENEMYAMMODROPRATE 100 //Madd 50 // % of time enemies drop ammunition
@@ -3766,9 +3767,7 @@ void SpawnFittingAmmo(SOLDIERCREATE_STRUCT *pp, OBJECTTYPE* pObj, UINT8 ammotype
void MoveOneMilitiaEquipmentSet(INT16 sSourceX, INT16 sSourceY, INT16 sTargetX, INT16 sTargetY, INT8 bSoldierClass) void MoveOneMilitiaEquipmentSet(INT16 sSourceX, INT16 sSourceY, INT16 sTargetX, INT16 sTargetY, INT8 bSoldierClass)
{ {
BOOLEAN fReturn = FALSE;
UINT32 uiTotalNumberOfRealItems = 0; UINT32 uiTotalNumberOfRealItems = 0;
UINT32 uiNumOriginalItems = 0;
std::vector<WORLDITEM> pWorldItem;//dnl ch75 271013 std::vector<WORLDITEM> pWorldItem;//dnl ch75 271013
SOLDIERCREATE_STRUCT tmp; SOLDIERCREATE_STRUCT tmp;
UINT32 uiCount = 0; UINT32 uiCount = 0;
@@ -3788,25 +3787,22 @@ void MoveOneMilitiaEquipmentSet(INT16 sSourceX, INT16 sSourceY, INT16 sTargetX,
else else
{ {
// not loaded, load // not loaded, load
// get total number, visable and invisible const auto ii = FindWorldItemSector(sTargetX, sTargetY, 0);
fReturn = GetNumberOfWorldItemsFromTempItemFile( sTargetX, sTargetY, 0, &( uiTotalNumberOfRealItems ), TRUE ); if (ii != -1)
Assert( fReturn );
if( uiTotalNumberOfRealItems > 0 )
{ {
// allocate space for the list uiTotalNumberOfRealItems = gAllWorldItems.NumItems[ii];
pWorldItem.resize(uiTotalNumberOfRealItems);//dnl ch75 271013 pWorldItem = gAllWorldItems.Items[ii];
}
// now load into mem else
LoadWorldItemsFromTempItemFile( sTargetX, sTargetY, 0, pWorldItem ); {
uiTotalNumberOfRealItems = 10;
pWorldItem.resize(uiTotalNumberOfRealItems);
} }
} }
uiNumOriginalItems = uiTotalNumberOfRealItems;
// we note the last item existing in the inventory (but not ammo, as we delete those). We use this to assess how much we really need to increase the inventory // we note the last item existing in the inventory (but not ammo, as we delete those). We use this to assess how much we really need to increase the inventory
UINT32 existingitemsfound = 0; UINT32 existingitemsfound = 0;
for( uiCount = 0; uiCount < uiTotalNumberOfRealItems; ++uiCount ) // ... for all items in the world ... for( uiCount = 0; uiCount < uiTotalNumberOfRealItems; ++uiCount ) // ... for all items in the world ...
{ {
if( pWorldItem[ uiCount ].fExists ) // ... if item exists ... if( pWorldItem[ uiCount ].fExists ) // ... if item exists ...
@@ -3888,8 +3884,7 @@ void MoveOneMilitiaEquipmentSet(INT16 sSourceX, INT16 sSourceY, INT16 sTargetX,
} }
else else
{ {
//Save the Items to the the file UpdateWorldItems(sTargetX, sTargetY, 0, uiTotalNumberOfRealItems, pWorldItem);
SaveWorldItemsToTempItemFile( sTargetX, sTargetY, 0, uiTotalNumberOfRealItems, pWorldItem );
} }
} }
@@ -3999,21 +3994,15 @@ void TakeMilitiaEquipmentfromSector( INT16 sMapX, INT16 sMapY, INT8 sMapZ, SOLDI
} }
else else
{ {
// not loaded, load const auto ii = FindWorldItemSector(sMapX, sMapY, (INT8)(sMapZ));
// get total number, visable and invisible if (ii != -1)
fReturn = GetNumberOfWorldItemsFromTempItemFile( sMapX, sMapY, ( INT8 )( sMapZ ), &( uiTotalNumberOfRealItems ), FALSE );
Assert( fReturn );
if( uiTotalNumberOfRealItems > 0 )
{ {
// allocate space for the list uiTotalNumberOfRealItems = gAllWorldItems.NumItems[ii];
pWorldItem.resize(uiTotalNumberOfRealItems);//dnl ch75 271013 pWorldItem = gAllWorldItems.Items[ii];
}
if ( !uiTotalNumberOfRealItems ) else
return; {
uiTotalNumberOfRealItems = 0;
// now load into mem
LoadWorldItemsFromTempItemFile( sMapX, sMapY, ( INT8 ) ( sMapZ ), pWorldItem );
} }
} }
@@ -4694,7 +4683,7 @@ void TakeMilitiaEquipmentfromSector( INT16 sMapX, INT16 sMapY, INT8 sMapZ, SOLDI
else else
{ {
//Save the Items to the the file //Save the Items to the the file
SaveWorldItemsToTempItemFile( sMapX, sMapY, (INT8)sMapZ, uiTotalNumberOfRealItems, pWorldItem ); UpdateWorldItems(sMapX, sMapY, (INT8)sMapZ, uiTotalNumberOfRealItems, pWorldItem);
} }
///////////////////////////////// Exit ///////////////////////////////////////////////////////// ///////////////////////////////// Exit /////////////////////////////////////////////////////////
+234 -464
View File
@@ -55,6 +55,13 @@ BOOLEAN gfWasInMeanwhile = FALSE;
//forward declarations of common classes to eliminate includes //forward declarations of common classes to eliminate includes
class OBJECTTYPE; class OBJECTTYPE;
class SOLDIERTYPE; class SOLDIERTYPE;
extern WorldItems gAllWorldItems;
void SaveWorldItemsToTempFiles();
void LoadWorldItemsFromTempFiles(INT16 sMapX, INT16 sMapY, INT8 bMapZ);
void ClearAllWorldItems(void);
bool LoadWorldItemsFromSavedGame(HWFILE hFile, INT16 x, INT16 y, INT8 z);
bool SaveWorldItemsToSavedGame(HWFILE hFile, INT16 x, INT16 y, INT8 z);
void PruneWorldItems(void);
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// //
@@ -144,19 +151,14 @@ extern BOOLEAN ValidateSoldierInitLinks( UINT8 ubCode );
#endif #endif
void SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems( INT16 sMapX, INT16 sMapY, INT8 bMapZ, BOOLEAN fLoadingGame );
UINT32 UpdateLoadedSectorsItemInventory( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT32 uiNumberOfItems ); UINT32 UpdateLoadedSectorsItemInventory( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT32 uiNumberOfItems );
//ppp //ppp
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// //
// Functions // Functions
// //
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// SaveMapTempFilesToSavedGameFile() Looks for and opens all Map Modification files. It add each mod file to the save game file. // SaveMapTempFilesToSavedGameFile() Looks for and opens all Map Modification files. It add each mod file to the save game file.
BOOLEAN SaveMapTempFilesToSavedGameFile( HWFILE hFile ) BOOLEAN SaveMapTempFilesToSavedGameFile( HWFILE hFile )
{ {
@@ -164,9 +166,8 @@ BOOLEAN SaveMapTempFilesToSavedGameFile( HWFILE hFile )
INT16 sMapX; INT16 sMapX;
INT16 sMapY; INT16 sMapY;
// Save all the global world items to temp files
//Save the current sectors open temp files to the disk SaveWorldItemsToTempFiles();
// SaveCurrentSectorsItemsToTempItemFile();
// //
//Loop though all the array elements to see if there is a data file to be saved //Loop though all the array elements to see if there is a data file to be saved
@@ -184,7 +185,6 @@ BOOLEAN SaveMapTempFilesToSavedGameFile( HWFILE hFile )
if ( !AddTempFileToSavedGame( hFile, SF_ITEM_TEMP_FILE_EXISTS, sMapX, sMapY, 0 ) ) if ( !AddTempFileToSavedGame( hFile, SF_ITEM_TEMP_FILE_EXISTS, sMapX, sMapY, 0 ) )
return FALSE; return FALSE;
} }
// Save the Rotting Corpse Temp file to the saved game file // Save the Rotting Corpse Temp file to the saved game file
if( SectorInfo[ SECTOR( sMapX,sMapY) ].uiFlags & SF_ROTTING_CORPSE_TEMP_FILE_EXISTS ) if( SectorInfo[ SECTOR( sMapX,sMapY) ].uiFlags & SF_ROTTING_CORPSE_TEMP_FILE_EXISTS )
{ {
@@ -364,6 +364,9 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile )
} }
} }
// Preparation for loading item temp files
ClearAllWorldItems();
// //
//Loop though all the array elements to see if there is a data file to be loaded //Loop though all the array elements to see if there is a data file to be loaded
// //
@@ -377,18 +380,8 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile )
{ {
if ( !RetrieveTempFileFromSavedGame( hFile, SF_ITEM_TEMP_FILE_EXISTS, sMapX, sMapY, 0 ) ) if ( !RetrieveTempFileFromSavedGame( hFile, SF_ITEM_TEMP_FILE_EXISTS, sMapX, sMapY, 0 ) )
return FALSE; return FALSE;
// Load world items from map temp files into global struct
//sync up the temp file data to the sector structure data LoadWorldItemsFromTempFiles(sMapX, sMapY, 0);
SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems( sMapX, sMapY, 0, TRUE );
// 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 ) if( SectorInfo[ SECTOR( sMapX,sMapY) ].uiFlags & SF_ROTTING_CORPSE_TEMP_FILE_EXISTS )
@@ -482,7 +475,7 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile )
return FALSE; return FALSE;
//sync up the temp file data to the sector structure data //sync up the temp file data to the sector structure data
SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems( TempNode->ubSectorX, TempNode->ubSectorY, TempNode->ubSectorZ, TRUE ); LoadWorldItemsFromTempFiles(TempNode->ubSectorX, TempNode->ubSectorY, TempNode->ubSectorZ);
} }
if( TempNode->uiFlags & SF_ROTTING_CORPSE_TEMP_FILE_EXISTS ) if( TempNode->uiFlags & SF_ROTTING_CORPSE_TEMP_FILE_EXISTS )
@@ -560,31 +553,6 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile )
} }
BOOLEAN UpdateWorldItemsTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
{
UINT32 uiTotalNumberOfItems=0;
std::vector<WORLDITEM> pTotalSectorList;//dnl ch75 271013
BOOLEAN fReturn = GetNumberOfWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, &( uiTotalNumberOfItems ), FALSE );
if (fReturn == false)
{
DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("GetNumberOfWorldItemsFromTempItemFile failed" ) );
Assert( fReturn );
}
if( uiTotalNumberOfItems > 0 )
{
// allocate space for the list
pTotalSectorList.resize(uiTotalNumberOfItems);//dnl ch75 271013
LoadWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, pTotalSectorList );
int backup = guiCurrentSaveGameVersion;
guiCurrentSaveGameVersion = SAVE_GAME_VERSION;
SaveWorldItemsToTempItemFile( sMapX, sMapY, bMapZ, uiTotalNumberOfItems, pTotalSectorList);
guiCurrentSaveGameVersion = backup;
}
return TRUE;
}
/* /*
BOOLEAN UpdateENEMYTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ ) BOOLEAN UpdateENEMYTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
@@ -610,7 +578,7 @@ BOOLEAN UpdateCIVTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
} }
*/ */
BOOLEAN SaveWorldItemsToTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT32 uiNumberOfItems, std::vector<WORLDITEM>& pData, BOOLEAN fUpdateVisibleItems )//dnl ch75 271013 BOOLEAN SaveWorldItemsToTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT32 uiNumberOfItems, std::vector<WORLDITEM>& pData)
{ {
HWFILE hFile; HWFILE hFile;
UINT32 uiNumBytesWritten=0; UINT32 uiNumBytesWritten=0;
@@ -652,9 +620,6 @@ BOOLEAN SaveWorldItemsToTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT
SetSectorFlag( sMapX, sMapY, bMapZ, SF_ITEM_TEMP_FILE_EXISTS ); SetSectorFlag( sMapX, sMapY, bMapZ, SF_ITEM_TEMP_FILE_EXISTS );
if( fUpdateVisibleItems )//dnl ch75 311013
SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems( sMapX, sMapY, bMapZ, FALSE );
return( TRUE ); return( TRUE );
} }
@@ -729,7 +694,7 @@ BOOLEAN GetNumberOfWorldItemsFromTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bM
{ {
//ADB: I don't know why we are initing 10 WORLDITEMS then saving them, but that's what the code was. //ADB: I don't know why we are initing 10 WORLDITEMS then saving them, but that's what the code was.
WORLDITEM TempWorldItems[ 10 ]; WORLDITEM TempWorldItems[ 10 ];
UINT32 uiNumberOfItems = 10; uiNumberOfItems = 10;
UINT32 uiNumBytesWritten=0; UINT32 uiNumBytesWritten=0;
//If the file doesnt exists, create a file that has an initial amount of Items //If the file doesnt exists, create a file that has an initial amount of Items
@@ -818,23 +783,20 @@ UINT32 GetNumberOfMovableItems( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
} }
else else
{ {
// not loaded, load const auto ii = FindWorldItemSector(sMapX, sMapY, bMapZ);
// get total number, visable and invisible if (ii != -1)
BOOLEAN fReturn = GetNumberOfWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, &(uiTotalNumberOfRealItems_Target), FALSE );
Assert( fReturn );
if ( uiTotalNumberOfRealItems_Target > 0 )
{ {
// allocate space for the list uiTotalNumberOfRealItems_Target = gAllWorldItems.NumItems[ii];
pWorldItem_Target.resize( uiTotalNumberOfRealItems_Target );//dnl ch75 271013 pWorldItem_Target = gAllWorldItems.Items[ii];
}
// now load into mem else
LoadWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, pWorldItem_Target ); {
uiTotalNumberOfRealItems_Target = 0;
} }
} }
UINT32 validitems = 0;
UINT32 validitems = 0;
for ( UINT32 uiCount = 0; uiCount < uiTotalNumberOfRealItems_Target; ++uiCount ) // ... for all items in the world ... for ( UINT32 uiCount = 0; uiCount < uiTotalNumberOfRealItems_Target; ++uiCount ) // ... for all items in the world ...
{ {
if ( pWorldItem_Target[uiCount].fExists ) // ... if item exists ... if ( pWorldItem_Target[uiCount].fExists ) // ... if item exists ...
@@ -851,131 +813,188 @@ UINT32 GetNumberOfMovableItems( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
} }
} }
} }
return validitems; return validitems;
} }
BOOLEAN AddWorldItemsToUnLoadedSector(INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT32 sGridNo, UINT32 uiNumberOfItemsToAdd, std::vector<WORLDITEM>& pWorldItem, BOOLEAN fOverWrite)
BOOLEAN AddItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT32 sGridNo, UINT32 uiNumberOfItemsToAdd, OBJECTTYPE *pObject, UINT8 ubLevel, UINT16 usFlags, INT8 bRenderZHeightAboveLevel, INT8 bVisible, BOOLEAN fReplaceEntireFile )
{ {
UINT32 uiNumberOfItems=0; UINT32 uiLoop;
UINT32 uiLastItemPos;
UINT32 uiNumberOfItems;
std::vector<WORLDITEM> pWorldItems;//dnl ch75 271013 std::vector<WORLDITEM> pWorldItems;//dnl ch75 271013
UINT32 cnt; if (uiNumberOfItemsToAdd == 0 && fOverWrite == FALSE)
UINT32 uiLoop1=0;
if ( uiNumberOfItemsToAdd == 0 && fReplaceEntireFile == FALSE )
{ {
//Moa: nothing to do, so get out of here! //Moa: nothing to do, so get out of here!
return( TRUE ); return(TRUE);
} }
if( !GetNumberOfWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, &uiNumberOfItems, TRUE ) ) const auto i = FindWorldItemSector(sMapX, sMapY, bMapZ);
if (i == -1)
{ {
//Errror getting the numbers of the items from the sector // Can't find world item sector, add it
return( FALSE ); uiNumberOfItems = uiNumberOfItemsToAdd;
pWorldItems.resize(uiNumberOfItems);
} }
else
//Allocate memeory for the item
pWorldItems.resize(uiNumberOfItems);
//Load in the sectors Item Info
if( !LoadWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, pWorldItems ) )
{ {
//error reading in the items from the Item mod file uiNumberOfItems = gAllWorldItems.NumItems[i];
return( FALSE ); pWorldItems = gAllWorldItems.Items[i];
} }
//if we are to replace the entire file //if we are to replace the entire file
if( fReplaceEntireFile ) if (fOverWrite)
{ {
//first loop through and mark all entries that they dont exists //first loop through and mark all entries that they dont exists
for( cnt=0; cnt<uiNumberOfItems; cnt++) for (UINT32 cnt = 0; cnt < uiNumberOfItems; ++cnt)
pWorldItems[ cnt ].fExists = FALSE; pWorldItems[cnt].fExists = FALSE;
}
//Now delete the item temp file uiLastItemPos = 0;
DeleteTempItemMapFile( sMapX, sMapY, bMapZ );
//loop through all the objects to add
for (uiLoop = 0; uiLoop < uiNumberOfItemsToAdd; ++uiLoop)
{
// Flugente: only add an item if it exists. Otherwise we will happily add items that are supposed to have been deleted
if (!pWorldItem[uiLoop].fExists)
continue;
//Loop through the array to see if there is a free spot to add an item to it
for (; uiLastItemPos < uiNumberOfItems; ++uiLastItemPos)
{
if (pWorldItems[uiLastItemPos].fExists == FALSE)
{
//We have found a free spot, break
break;
}
}
if (uiLastItemPos == (uiNumberOfItems))
{
const auto neededAmount = uiNumberOfItemsToAdd - uiLoop;
uiNumberOfItems += neededAmount;
pWorldItems.resize(uiNumberOfItems);
}
pWorldItems[uiLastItemPos].fExists = TRUE;
pWorldItems[uiLastItemPos].sGridNo = pWorldItem[uiLoop].sGridNo;
pWorldItems[uiLastItemPos].ubLevel = pWorldItem[uiLoop].ubLevel;
pWorldItems[uiLastItemPos].usFlags = pWorldItem[uiLoop].usFlags;
pWorldItems[uiLastItemPos].bVisible = pWorldItem[uiLoop].bVisible;
pWorldItems[uiLastItemPos].bRenderZHeightAboveLevel = pWorldItem[uiLoop].bRenderZHeightAboveLevel;
//Check
if (TileIsOutOfBounds(pWorldItem[uiLoop].sGridNo) && !(pWorldItems[uiLastItemPos].usFlags & WORLD_ITEM_GRIDNO_NOT_SET_USE_ENTRY_POINT))
{
pWorldItems[uiLastItemPos].usFlags |= WORLD_ITEM_GRIDNO_NOT_SET_USE_ENTRY_POINT;
// Display warning.....
ScreenMsg(FONT_MCOLOR_LTYELLOW, MSG_BETAVERSION, L"Error: Trying to add item ( %d: %s ) to invalid gridno in unloaded sector. Please Report.", pWorldItems[uiLoop].object.usItem, ItemNames[pWorldItems[uiLoop].object.usItem]);
}
pWorldItems[uiLastItemPos].object = pWorldItem[uiLoop].object;
}
UpdateWorldItems(sMapX, sMapY, bMapZ, uiNumberOfItems, pWorldItems);
return(TRUE);
}
BOOLEAN AddItemsToUnLoadedSector(INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT32 sGridNo, UINT32 uiNumberOfItemsToAdd, OBJECTTYPE* pObject, UINT8 ubLevel, UINT16 usFlags, INT8 bRenderZHeightAboveLevel, INT8 bVisible, BOOLEAN fReplaceEntireFile)
{
if (uiNumberOfItemsToAdd == 0 && fReplaceEntireFile == FALSE)
{
//Moa: nothing to do, so get out of here!
return(TRUE);
}
std::vector<WORLDITEM> pWorldItems;
UINT32 uiNumberOfItems = 0;
UINT32 cnt;
UINT32 uiLoop1 = 0;
const auto i = FindWorldItemSector(sMapX, sMapY, bMapZ);
if (i == -1)
{
// Can't find world item sector, add it
uiNumberOfItems = uiNumberOfItemsToAdd;
pWorldItems.resize(uiNumberOfItems);
}
else
{
uiNumberOfItems = gAllWorldItems.NumItems[i];
pWorldItems = gAllWorldItems.Items[i];
}
if (fReplaceEntireFile)
{
//first loop through and mark all entries that they dont exists
for (cnt = 0; cnt < uiNumberOfItems; cnt++)
{
pWorldItems[cnt].fExists = FALSE;
}
} }
UINT16 uiLastFoundSpot = 0; UINT16 uiLastFoundSpot = 0;
//loop through all the objects to add //loop through all the objects to add
for( uiLoop1=0; uiLoop1 < uiNumberOfItemsToAdd; uiLoop1++) for (uiLoop1 = 0; uiLoop1 < uiNumberOfItemsToAdd; uiLoop1++)
{ {
//Loop through the array to see if there is a free spot to add an item to it //Loop through the array to see if there is a free spot to add an item to it
for( cnt=uiLastFoundSpot; cnt < uiNumberOfItems; cnt++) for (cnt = uiLastFoundSpot; cnt < uiNumberOfItems; cnt++)
{ {
if( pWorldItems[ cnt ].fExists == FALSE ) if (pWorldItems[cnt].fExists == FALSE)
{ {
// anv: remember first found free spot to not loop through entire inventory again for next added items // anv: remember first found free spot to not loop through entire inventory again for next added items
uiLastFoundSpot = cnt; uiLastFoundSpot = cnt;
//We have found a free spot, break //We have found a free spot, break
break; break;
} }
if( cnt == ( uiNumberOfItems ) )
{
#if 0//dnl ch75 271013
//Error, there wasnt a free spot. Reallocate memory for the array
WORLDITEM* pTemp = new WORLDITEM[uiNumberOfItems + 1];
if( pTemp == NULL )
{
//error realloctin memory
return( FALSE );
} }
for (unsigned int x = 0; x < uiNumberOfItems; ++x) {
pTemp[x] = pWorldItems[x];
}
delete[] pWorldItems;
pWorldItems = pTemp;
//Increment the total number of item in the array
uiNumberOfItems++;
//set the spot were the item is to be added
cnt = uiNumberOfItems - 1;
#else
pWorldItems.resize(++uiNumberOfItems);
#endif
} }
pWorldItems[ cnt ].fExists = TRUE; if (cnt == (uiNumberOfItems))
pWorldItems[ cnt ].sGridNo = sGridNo; {
pWorldItems[ cnt ].ubLevel = ubLevel; const auto neededAmount = uiNumberOfItemsToAdd - uiLoop1;
pWorldItems[ cnt ].usFlags = usFlags; uiNumberOfItems += neededAmount;
pWorldItems[ cnt ].bVisible = bVisible; pWorldItems.resize(uiNumberOfItems);
pWorldItems[ cnt ].bRenderZHeightAboveLevel = bRenderZHeightAboveLevel; }
pWorldItems[cnt].fExists = TRUE;
pWorldItems[cnt].sGridNo = sGridNo;
pWorldItems[cnt].ubLevel = ubLevel;
pWorldItems[cnt].usFlags = usFlags;
pWorldItems[cnt].bVisible = bVisible;
pWorldItems[cnt].bRenderZHeightAboveLevel = bRenderZHeightAboveLevel;
//Check //Check
if(TileIsOutOfBounds(sGridNo) && !( pWorldItems[ cnt ].usFlags & WORLD_ITEM_GRIDNO_NOT_SET_USE_ENTRY_POINT ) ) if (TileIsOutOfBounds(sGridNo) && !(pWorldItems[cnt].usFlags & WORLD_ITEM_GRIDNO_NOT_SET_USE_ENTRY_POINT))
{ {
pWorldItems[ cnt ].usFlags |= WORLD_ITEM_GRIDNO_NOT_SET_USE_ENTRY_POINT; pWorldItems[cnt].usFlags |= WORLD_ITEM_GRIDNO_NOT_SET_USE_ENTRY_POINT;
// Display warning..... // Display warning.....
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_BETAVERSION, L"Error: Trying to add item ( %d: %s ) to invalid gridno in unloaded sector. Please Report.", pWorldItems[ cnt ].object.usItem, ItemNames[pWorldItems[ cnt ].object.usItem] ); ScreenMsg(FONT_MCOLOR_LTYELLOW, MSG_BETAVERSION, L"Error: Trying to add item ( %d: %s ) to invalid gridno in unloaded sector. Please Report.", pWorldItems[cnt].object.usItem, ItemNames[pWorldItems[cnt].object.usItem]);
} }
pWorldItems[ cnt ].object = pObject[uiLoop1]; pWorldItems[cnt].object = pObject[uiLoop1];
if ( (*pObject)[uiLoop1]->data.sObjectFlag & TAKEN_BY_MILITIA_TABOO_GREEN ) if ((*pObject)[uiLoop1]->data.sObjectFlag & TAKEN_BY_MILITIA_TABOO_GREEN)
{ {
(*pObject)[uiLoop1]->data.sObjectFlag &= ~TAKEN_BY_MILITIA_TABOO_GREEN; (*pObject)[uiLoop1]->data.sObjectFlag &= ~TAKEN_BY_MILITIA_TABOO_GREEN;
pWorldItems[ cnt ].usFlags |= WORLD_ITEM_TABOO_FOR_MILITIA_EQ_GREEN; pWorldItems[cnt].usFlags |= WORLD_ITEM_TABOO_FOR_MILITIA_EQ_GREEN;
} }
if ( (*pObject)[uiLoop1]->data.sObjectFlag & TAKEN_BY_MILITIA_TABOO_BLUE ) if ((*pObject)[uiLoop1]->data.sObjectFlag & TAKEN_BY_MILITIA_TABOO_BLUE)
{ {
(*pObject)[uiLoop1]->data.sObjectFlag &= ~TAKEN_BY_MILITIA_TABOO_BLUE; (*pObject)[uiLoop1]->data.sObjectFlag &= ~TAKEN_BY_MILITIA_TABOO_BLUE;
pWorldItems[ cnt ].usFlags |= WORLD_ITEM_TABOO_FOR_MILITIA_EQ_BLUE; pWorldItems[cnt].usFlags |= WORLD_ITEM_TABOO_FOR_MILITIA_EQ_BLUE;
} }
} }
//Save the Items to the the file UpdateWorldItems(sMapX, sMapY, bMapZ, uiNumberOfItems, pWorldItems);
SaveWorldItemsToTempItemFile( sMapX, sMapY, bMapZ, uiNumberOfItems, pWorldItems ); return(TRUE);
return( TRUE );
} }
extern BOOLEAN gfInMeanwhile; extern BOOLEAN gfInMeanwhile;
extern BOOLEAN EnableModifiedFileSetCache(BOOLEAN value); extern BOOLEAN EnableModifiedFileSetCache(BOOLEAN value);
@@ -1012,14 +1031,7 @@ BOOLEAN SaveCurrentSectorsInformationToTempItemFile( )
// handle all reachable before save // handle all reachable before save
HandleAllReachAbleItemsInTheSector( gWorldSectorX, gWorldSectorY, gbWorldSectorZ ); HandleAllReachAbleItemsInTheSector( gWorldSectorX, gWorldSectorY, gbWorldSectorZ );
UpdateWorldItems(gWorldSectorX, gWorldSectorY, gbWorldSectorZ, guiNumWorldItems, gWorldItems);
//Save the Items to the the file
if( !SaveWorldItemsToTempItemFile( gWorldSectorX, gWorldSectorY, gbWorldSectorZ, guiNumWorldItems, gWorldItems ) )
{
DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("SaveCurrentSectorsInformationToTempItemFile: failed in SaveWorldItemsToTempItemFile()" ) );
EnableModifiedFileSetCache(cacheResetValue);
return( FALSE );
}
std::vector<ROTTING_CORPSE_DEFINITION> corpsedefvector; std::vector<ROTTING_CORPSE_DEFINITION> corpsedefvector;
@@ -1281,13 +1293,12 @@ BOOLEAN LoadCurrentSectorsInformationFromTempItemsFile()
// processed! // processed!
if ( GetMeanwhileID() == INTERROGATION ) if ( GetMeanwhileID() == INTERROGATION )
{ {
//If there is a file, load in the Items array //We no longer use item temp files during gameplay, so check for the sector in gAllWorldItems
if( DoesTempFileExistsForMap( SF_ITEM_TEMP_FILE_EXISTS, gWorldSectorX, gWorldSectorY, gbWorldSectorZ ) ) if (SectorIsInWorldItems(gWorldSectorX, gWorldSectorY, gbWorldSectorZ))
{ {
if( !LoadAndAddWorldItemsFromTempFile( gWorldSectorX, gWorldSectorY, gbWorldSectorZ ) ) if (!LoadAndAddWorldItemsFromTempFile(gWorldSectorX, gWorldSectorY, gbWorldSectorZ))
return( FALSE ); return(FALSE);
} }
gfWasInMeanwhile = FALSE; gfWasInMeanwhile = FALSE;
} }
return TRUE; return TRUE;
@@ -1303,12 +1314,12 @@ BOOLEAN LoadCurrentSectorsInformationFromTempItemsFile()
return( FALSE ); return( FALSE );
} }
//If there is a file, load in the Items array //We no longer use item temp files during gameplay, so check for the sector in gAllWorldItems
if( DoesTempFileExistsForMap( SF_ITEM_TEMP_FILE_EXISTS, gWorldSectorX, gWorldSectorY, gbWorldSectorZ ) ) if (SectorIsInWorldItems(gWorldSectorX, gWorldSectorY, gbWorldSectorZ))
{ {
fUsedTempFile = TRUE; if (!LoadAndAddWorldItemsFromTempFile(gWorldSectorX, gWorldSectorY, gbWorldSectorZ))
if( !LoadAndAddWorldItemsFromTempFile( gWorldSectorX, gWorldSectorY, gbWorldSectorZ ) ) return(FALSE);
return( FALSE );
} }
//If there is a rotting corpse temp file, load the data from the temp file //If there is a rotting corpse temp file, load the data from the temp file
@@ -1543,29 +1554,31 @@ UINT32 GetLastTimePlayerWasInSector(INT16 sMapX, INT16 sMapY, INT8 sMapZ)
BOOLEAN LoadAndAddWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ ) BOOLEAN LoadAndAddWorldItemsFromTempFile(INT16 sMapX, INT16 sMapY, INT8 bMapZ)
{ {
UINT32 uiNumberOfItems=0; UINT32 uiNumberOfItems = 0;
std::vector<WORLDITEM> pWorldItems;//dnl ch75 271013 std::vector<WORLDITEM> pWorldItems;
UINT32 cnt;
INT32 sNewGridNo;
//Get the number of items from the file //Get the number of items from the file
if( !GetNumberOfWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, &uiNumberOfItems, TRUE ) ) const auto i = FindWorldItemSector(sMapX, sMapY, bMapZ);
if (i == -1)
{ {
//Error getting the numbers of the items from the sector //Error getting the numbers of the items from the sector. Create placeholder items.
return( FALSE ); //This is what the original code did
} uiNumberOfItems = 10;
pWorldItems.resize(uiNumberOfItems);
if( uiNumberOfItems )
{
pWorldItems.resize(uiNumberOfItems);//dnl ch75 271013
} }
else else
{
uiNumberOfItems = gAllWorldItems.NumItems[i];
pWorldItems= gAllWorldItems.Items[i];
}
if (uiNumberOfItems == 0)
{ {
//if there are no items in the temp, the player might have cleared all of them out, check to see //if there are no items in the temp, the player might have cleared all of them out, check to see
//If we have already been to the sector //If we have already been to the sector
if( GetSectorFlagStatus( sMapX, sMapY, bMapZ, SF_ALREADY_LOADED ) ) if (GetSectorFlagStatus(sMapX, sMapY, bMapZ, SF_ALREADY_LOADED))
{ {
// //
//Completly replace the current sectors item table because all the items SHOULD be in the temp file!! //Completly replace the current sectors item table because all the items SHOULD be in the temp file!!
@@ -1573,23 +1586,15 @@ BOOLEAN LoadAndAddWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
//Destroy the current sectors item table //Destroy the current sectors item table
TrashWorldItems(); TrashWorldItems();
//Add each item to the pool, handle below, outside of the if
} }
//there are no items in the file //there are no items in the file
return( TRUE ); return(TRUE);
}
//Load the World Items from the file
if( !LoadWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, pWorldItems ) )
{
return( FALSE );
} }
//If we have already been to the sector //If we have already been to the sector
if( GetSectorFlagStatus( sMapX, sMapY, bMapZ, SF_ALREADY_LOADED ) ) if (GetSectorFlagStatus(sMapX, sMapY, bMapZ, SF_ALREADY_LOADED))
{ {
// //
//Completly replace the current sectors item table because all the items SHOULD be in the temp file!! //Completly replace the current sectors item table because all the items SHOULD be in the temp file!!
@@ -1606,19 +1611,20 @@ BOOLEAN LoadAndAddWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
// //
//Loop through all the items loaded from the file //Loop through all the items loaded from the file
for( cnt=0; cnt< uiNumberOfItems; cnt++) INT32 sNewGridNo;
for (UINT32 cnt = 0; cnt < uiNumberOfItems; cnt++)
{ {
//If the item in the array is valid //If the item in the array is valid
if( pWorldItems[cnt].fExists ) if (pWorldItems[cnt].fExists)
{ {
//Check the flags to see if we have to find a gridno to place the items at //Check the flags to see if we have to find a gridno to place the items at
if( pWorldItems[cnt].usFlags & WOLRD_ITEM_FIND_SWEETSPOT_FROM_GRIDNO ) if (pWorldItems[cnt].usFlags & WOLRD_ITEM_FIND_SWEETSPOT_FROM_GRIDNO)
{ {
sNewGridNo = FindNearestAvailableGridNoForItem( pWorldItems[cnt].sGridNo, 5 ); sNewGridNo = FindNearestAvailableGridNoForItem(pWorldItems[cnt].sGridNo, 5);
if(TileIsOutOfBounds(sNewGridNo)) if (TileIsOutOfBounds(sNewGridNo))
sNewGridNo = FindNearestAvailableGridNoForItem( pWorldItems[cnt].sGridNo, 15 ); sNewGridNo = FindNearestAvailableGridNoForItem(pWorldItems[cnt].sGridNo, 15);
if (!TileIsOutOfBounds(sNewGridNo)) if (!TileIsOutOfBounds(sNewGridNo))
{ {
pWorldItems[cnt].sGridNo = sNewGridNo; pWorldItems[cnt].sGridNo = sNewGridNo;
@@ -1626,7 +1632,7 @@ BOOLEAN LoadAndAddWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
} }
//If the item has an invalid gridno, use the maps entry point //If the item has an invalid gridno, use the maps entry point
if( pWorldItems[cnt].usFlags & WORLD_ITEM_GRIDNO_NOT_SET_USE_ENTRY_POINT ) if (pWorldItems[cnt].usFlags & WORLD_ITEM_GRIDNO_NOT_SET_USE_ENTRY_POINT)
{ {
pWorldItems[cnt].sGridNo = gMapInformation.sCenterGridNo; pWorldItems[cnt].sGridNo = gMapInformation.sCenterGridNo;
@@ -1635,17 +1641,15 @@ BOOLEAN LoadAndAddWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
} }
//add the item to the world //add the item to the world
AddItemToPool( pWorldItems[cnt].sGridNo, &pWorldItems[cnt].object, pWorldItems[cnt].bVisible, pWorldItems[cnt].ubLevel, pWorldItems[cnt].usFlags, pWorldItems[cnt].bRenderZHeightAboveLevel, pWorldItems[cnt].soldierID ); AddItemToPool(pWorldItems[cnt].sGridNo, &pWorldItems[cnt].object, pWorldItems[cnt].bVisible, pWorldItems[cnt].ubLevel, pWorldItems[cnt].usFlags, pWorldItems[cnt].bRenderZHeightAboveLevel, pWorldItems[cnt].soldierID);
} }
} }
return( TRUE ); return(TRUE);
} }
BOOLEAN AddTempFileToSavedGame( HWFILE hFile, UINT32 uiType, INT16 sMapX, INT16 sMapY, INT8 bMapZ ) BOOLEAN AddTempFileToSavedGame( HWFILE hFile, UINT32 uiType, INT16 sMapX, INT16 sMapY, INT8 bMapZ )
{ {
CHAR8 zMapName[ 128 ]; CHAR8 zMapName[ 128 ];
@@ -1773,18 +1777,7 @@ BOOLEAN SaveRottingCorpsesToTempCorpseFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ
BOOLEAN DeleteTempItemMapFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ ) BOOLEAN DeleteTempItemMapFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
{ {
UINT8 bSectorId = 0;
// CHAR8 zTempName[ 128 ];
CHAR8 zMapName[ 128 ]; CHAR8 zMapName[ 128 ];
// grab the sector id
bSectorId = SECTOR( sMapX, sMapY );
/*
//Convert the current sector location into a file name
GetMapFileName( sMapX,sMapY, bMapZ, zTempName, FALSE );
sprintf( zMapName, "%s\\r_%s", MAPS_DIR, zTempName);
*/
GetMapTempFileName( SF_ITEM_TEMP_FILE_EXISTS, zMapName, sMapX, sMapY, bMapZ ); GetMapTempFileName( SF_ITEM_TEMP_FILE_EXISTS, zMapName, sMapX, sMapY, bMapZ );
//Check to see if the file exists //Check to see if the file exists
@@ -1793,10 +1786,10 @@ BOOLEAN DeleteTempItemMapFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
//If the file doesnt exists, its no problem. //If the file doesnt exists, its no problem.
return( TRUE ); return( TRUE );
} }
FileDelete(zMapName);
// the sector info flag being reset // the sector info flag being reset
ReSetSectorFlag( sMapX, sMapY, bMapZ, SF_ITEM_TEMP_FILE_EXISTS ); ReSetSectorFlag( sMapX, sMapY, bMapZ, SF_ITEM_TEMP_FILE_EXISTS );
return( TRUE ); return( TRUE );
} }
@@ -1935,126 +1928,6 @@ BOOLEAN LoadRottingCorpsesFromTempCorpseFile( INT16 sMapX, INT16 sMapY, INT8 bMa
} }
// Rewritten to load the temp file once, update with the list, and then write it. This was getting insane as items piled up in sectors.
// A few dozen read, update, writes was okay but a few hundred is pushing it.
BOOLEAN AddWorldItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT32 sGridNo, UINT32 uiNumberOfItemsToAdd, std::vector<WORLDITEM>& pWorldItem, BOOLEAN fOverWrite )//dnl ch75 271013
{
UINT32 uiLoop;
UINT32 uiLastItemPos;
UINT32 uiNumberOfItems;
std::vector<WORLDITEM> pWorldItems;//dnl ch75 271013
if( !GetNumberOfWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, &uiNumberOfItems, TRUE ) )
{
//Errror getting the numbers of the items from the sector
return( FALSE );
}
//Allocate memory for the item
pWorldItems.resize(uiNumberOfItems);//dnl ch75 271013
//Load in the sectors Item Info
if( !LoadWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, pWorldItems ) )
{
//error reading in the items from the Item mod file
return( FALSE );
}
//if we are to replace the entire file
if( fOverWrite )
{
//first loop through and mark all entries that they dont exists
for( UINT32 cnt=0; cnt<uiNumberOfItems; ++cnt)
pWorldItems[ cnt ].fExists = FALSE;
//Now delete the item temp file
DeleteTempItemMapFile( sMapX, sMapY, bMapZ );
}
uiLastItemPos = 0;
//loop through all the objects to add
for( uiLoop=0; uiLoop < uiNumberOfItemsToAdd; ++uiLoop)
{
// Flugente: only add an item if it exists. Otherwise we will happily add items that are supposed to have been deleted
if ( !pWorldItem[uiLoop].fExists )
continue;
//Loop through the array to see if there is a free spot to add an item to it
for( ; uiLastItemPos < uiNumberOfItems; ++uiLastItemPos)
{
if( pWorldItems[ uiLastItemPos ].fExists == FALSE )
{
//We have found a free spot, break
break;
}
}
if( uiLastItemPos == ( uiNumberOfItems ) )
{
#if 0//dnl ch75 271013
//Error, there wasnt a free spot. Reallocate memory for the array
WORLDITEM* pTemp;
pTemp = new WORLDITEM [uiNumberOfItems + 1];
if( pTemp == NULL )
{
//error realloctin memory
return( FALSE );
}
for (unsigned int x = 0; x < uiNumberOfItems; ++x) {
pTemp[x] = pWorldItems[x];
}
delete[] pWorldItems;
pWorldItems = pTemp;
//Increment the total number of item in the array
uiNumberOfItems++;
#else
pWorldItems.resize(++uiNumberOfItems);
#endif
}
pWorldItems[ uiLastItemPos ].fExists = TRUE;
pWorldItems[ uiLastItemPos ].sGridNo = pWorldItem[ uiLoop ].sGridNo;
pWorldItems[ uiLastItemPos ].ubLevel = pWorldItem[ uiLoop ].ubLevel;
pWorldItems[ uiLastItemPos ].usFlags = pWorldItem[ uiLoop ].usFlags;
pWorldItems[ uiLastItemPos ].bVisible = pWorldItem[ uiLoop ].bVisible;
pWorldItems[ uiLastItemPos ].bRenderZHeightAboveLevel = pWorldItem[ uiLoop ].bRenderZHeightAboveLevel;
//Check
if(TileIsOutOfBounds(pWorldItem[ uiLoop ].sGridNo) && !( pWorldItems[ uiLastItemPos ].usFlags & WORLD_ITEM_GRIDNO_NOT_SET_USE_ENTRY_POINT ) )
{
pWorldItems[ uiLastItemPos ].usFlags |= WORLD_ITEM_GRIDNO_NOT_SET_USE_ENTRY_POINT;
// Display warning.....
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_BETAVERSION, L"Error: Trying to add item ( %d: %s ) to invalid gridno in unloaded sector. Please Report.", pWorldItems[ uiLoop ].object.usItem, ItemNames[pWorldItems[ uiLoop ].object.usItem] );
}
pWorldItems[ uiLastItemPos ].object = pWorldItem[ uiLoop ].object;
}
//Save the Items to the the file
SaveWorldItemsToTempItemFile( sMapX, sMapY, bMapZ, uiNumberOfItems, pWorldItems );
#if 0
// The old excruciatingly inefficient code
for( uiLoop=0; uiLoop<uiNumberOfItems; uiLoop++)
{
//If the item exists
if( pWorldItem[uiLoop].fExists )
{
AddItemsToUnLoadedSector( sMapX, sMapY, bMapZ, pWorldItem[uiLoop].sGridNo, 1, &pWorldItem[ uiLoop ].object, pWorldItem[ uiLoop ].ubLevel, pWorldItem[ uiLoop ].usFlags, pWorldItem[ uiLoop ].bRenderZHeightAboveLevel, pWorldItem[ uiLoop ].bVisible, fLoop );
fLoop = FALSE;
}
}
#endif
return( TRUE );
}
void SaveNPCInformationToProfileStruct( ) void SaveNPCInformationToProfileStruct( )
{ {
UINT32 cnt; UINT32 cnt;
@@ -2261,76 +2134,6 @@ void LoadNPCInformationFromProfileStruct()
} }
BOOLEAN GetNumberOfActiveWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT32 *pNumberOfData )
{
UINT32 uiNumberOfItems=0;
std::vector<WORLDITEM> pWorldItems;//dnl ch75 271013
UINT32 cnt;
UINT32 uiNumberOfActive=0;
BOOLEAN fFileLoaded = FALSE;
UNDERGROUND_SECTORINFO *TempNode = gpUndergroundSectorInfoHead;
//
// Load in the sectors ITems
//
//If there is a file, load in the Items array
if( bMapZ == 0 )
{
if( SectorInfo[ SECTOR( sMapX,sMapY) ].uiFlags & SF_ITEM_TEMP_FILE_EXISTS )
fFileLoaded = TRUE;
}
else
{
while( TempNode )
{
if( TempNode->ubSectorX == sMapX && TempNode->ubSectorY == sMapY && TempNode->ubSectorZ == bMapZ )
{
if( TempNode->uiFlags & SF_ITEM_TEMP_FILE_EXISTS )
fFileLoaded = TRUE;
break;
}
TempNode = TempNode->next;
}
}
if( fFileLoaded )
{
//Get the number of items from the file
if( !GetNumberOfWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, &uiNumberOfItems, TRUE ) )
{
//Error getting the numbers of the items from the sector
return( FALSE );
}
//If there items in the data file
if( uiNumberOfItems != 0 )
{
pWorldItems.resize(uiNumberOfItems);//dnl ch75 271013
//Load the World Items from the file
if( !LoadWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, pWorldItems ) )
return( FALSE );
uiNumberOfActive = 0;
for( cnt=0; cnt<uiNumberOfItems; cnt++ )
{
if( pWorldItems[cnt].fExists )
uiNumberOfActive++;
}
}
*pNumberOfData = uiNumberOfActive;
}
else
*pNumberOfData = 0;
return( TRUE );
}
BOOLEAN DoesTempFileExistsForMap( UINT32 uiType, INT16 sMapX, INT16 sMapY, INT8 bMapZ ) BOOLEAN DoesTempFileExistsForMap( UINT32 uiType, INT16 sMapX, INT16 sMapY, INT8 bMapZ )
{ {
UNDERGROUND_SECTORINFO *TempNode = gpUndergroundSectorInfoHead; UNDERGROUND_SECTORINFO *TempNode = gpUndergroundSectorInfoHead;
@@ -3341,76 +3144,6 @@ void SetNumberOfVisibleWorldItemsInSectorStructureForSector( INT16 sMapX, INT16
} }
} }
//Moa 09/19/13: changed loop upperbound from uiTotalNumberOfRealItems to uiTotalNumberOfItems,
// this effectivly removes one entire loop in GetNumberOfActiveWorldItemsFromTempFile and 2 file reads.
// also changed type of iCounter from INT32 to UINT32 and for in if-clauses from true to TRUE to get rid of unneccessary casts.
void SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems( INT16 sMapX, INT16 sMapY, INT8 bMapZ, BOOLEAN fLoadingGame )
{
UINT32 uiTotalNumberOfItems = 0;//, uiTotalNumberOfRealItems = 0;
std::vector<WORLDITEM> pTotalSectorList;//dnl ch75 271013
UINT32 uiItemCount = 0;
UINT32 iCounter = 0;
BOOLEAN fReturn;
/*
// get total number, visable and invisible
fReturn = GetNumberOfActiveWorldItemsFromTempFile( sMapX, sMapY, bMapZ, &( uiTotalNumberOfRealItems ) );
if (fReturn == TRUE)
{
DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("GetNumberOfActiveWorldItemsFromTempFile failed" ) );
Assert( fReturn );
}*/
fReturn = GetNumberOfWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, &( uiTotalNumberOfItems ), FALSE );
if (fReturn == TRUE)
{
DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("GetNumberOfWorldItemsFromTempItemFile failed" ) );
Assert( fReturn );
}
if( uiTotalNumberOfItems > 0 )
{
// allocate space for the list
pTotalSectorList.resize(uiTotalNumberOfItems);//dnl ch75 271013
// 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] ) )
{
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
if( fLoadingGame && guiCurrentSaveGameVersion >= 86 )
{
UINT32 uiReported = GetNumberOfVisibleWorldItemsFromSectorStructureForSector( sMapX, sMapY, bMapZ );
if( uiItemCount != uiReported )
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_BETAVERSION, L"SynchronizeItemTempFile() Error! Reported %d, should be %d", uiReported, uiItemCount );
}
#endif
//record the number of items
SetNumberOfVisibleWorldItemsInSectorStructureForSector( sMapX, sMapY, bMapZ, uiItemCount );
}
UINT32 UpdateLoadedSectorsItemInventory( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT32 uiNumberOfItems ) UINT32 UpdateLoadedSectorsItemInventory( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT32 uiNumberOfItems )
{ {
@@ -3441,3 +3174,40 @@ UINT32 UpdateLoadedSectorsItemInventory( INT16 sMapX, INT16 sMapY, INT8 bMapZ, U
//return the number of items //return the number of items
return( uiItemCounter ); return( uiItemCounter );
} }
// We no longer use map item temp files except during loading and saving a game to preserve savegame compatibility.
// LoadWorldItemsFromTempFiles & SaveWorldItemsToTempFiles are used to read and write world items to and from temp files into the global world items struct gAllWorldItems that is used during gameplay
void LoadWorldItemsFromTempFiles(INT16 sMapX, INT16 sMapY, INT8 bMapZ)
{
UINT32 nItems = 0;
std::vector<WORLDITEM> Items;
const BOOLEAN fReturn = GetNumberOfWorldItemsFromTempItemFile(sMapX, sMapY, bMapZ, &(nItems), FALSE);
if (fReturn == FALSE)
{
DebugMsg(TOPIC_JA2, DBG_LEVEL_3, String("GetNumberOfWorldItemsFromTempItemFile failed"));
Assert(fReturn);
}
if (nItems > 0)
{
Items.resize(nItems);
LoadWorldItemsFromTempItemFile(sMapX, sMapY, bMapZ, Items);
UpdateWorldItems(sMapX, sMapY, bMapZ, nItems, Items);
}
}
void SaveWorldItemsToTempFiles()
{
PruneWorldItems();
for (size_t i = 0; i < gAllWorldItems.sectors.size(); i++)
{
const auto x = gAllWorldItems.sectors[i].x;
const auto y = gAllWorldItems.sectors[i].y;
const auto z = gAllWorldItems.sectors[i].z;
const auto nItems = gAllWorldItems.NumItems[i];
auto Items = gAllWorldItems.Items[i];
SaveWorldItemsToTempItemFile(x, y, (INT8)z, nItems, Items);
}
}
-7
View File
@@ -52,10 +52,6 @@ BOOLEAN LoadCurrentSectorsInformationFromTempItemsFile();
// Loads a World Item array from that sectors temp item file // Loads a World Item array from that sectors temp item file
BOOLEAN LoadWorldItemsFromTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, std::vector<WORLDITEM>& pData );//dnl ch75 271013 BOOLEAN LoadWorldItemsFromTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, std::vector<WORLDITEM>& pData );//dnl ch75 271013
BOOLEAN SaveWorldItemsToTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT32 uiNumberOfItems, std::vector<WORLDITEM>& pData, BOOLEAN fUpdateVisibleItems=TRUE );//dnl ch75 271013
//When the savegame version changes, load the temp files, then immediately save them again in the new format
BOOLEAN UpdateWorldItemsTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ );
// Adds an array of Item Objects to the specified location on a unloaded map. // Adds an array of Item Objects to the specified location on a unloaded map.
// If you want to overwrite all the items in the array set fReplaceEntireFile to TRUE. // If you want to overwrite all the items in the array set fReplaceEntireFile to TRUE.
@@ -68,9 +64,6 @@ BOOLEAN AddWorldItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT
BOOLEAN InitTacticalSave( BOOLEAN fCreateTempDir ); BOOLEAN InitTacticalSave( BOOLEAN fCreateTempDir );
//Gets the number of ACTIVE ( Not the TOTAL number ) of World Items from the sectors temp file
BOOLEAN GetNumberOfActiveWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT32 *pNumberOfData );
//Call this function to set the new sector a NPC will travel to //Call this function to set the new sector a NPC will travel to
void ChangeNpcToDifferentSector( UINT8 ubNpcId, INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ ); void ChangeNpcToDifferentSector( UINT8 ubNpcId, INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ );
+124
View File
@@ -35,6 +35,130 @@
//Global dynamic array of all of the items in a loaded map. //Global dynamic array of all of the items in a loaded map.
std::vector<WORLDITEM> gWorldItems;//dnl ch75 261013 std::vector<WORLDITEM> gWorldItems;//dnl ch75 261013
UINT32 guiNumWorldItems = 0; UINT32 guiNumWorldItems = 0;
WorldItems gAllWorldItems; // World items for all unloaded sectors
INT32 FindWorldItemSector(INT16 x, INT16 y, INT16 z)
{
for (size_t i = 0; i < gAllWorldItems.sectors.size(); i++)
{
const auto sector = gAllWorldItems.sectors[i];
if (sector.x == x && sector.y == y && sector.z == z)
{
return i;
}
}
return -1;
}
bool SectorIsInWorldItems(INT16 x, INT16 y, INT16 z)
{
for (size_t i = 0; i < gAllWorldItems.sectors.size(); i++)
{
const auto sector = gAllWorldItems.sectors[i];
if (sector.x == x && sector.y == y && sector.z == z)
{
return true;
}
}
return false;
}
void AddSectorItemsToWorldItems(INT16 x, INT16 y, INT16 z, UINT32 nItems, std::vector<WORLDITEM> &Items)
{
gAllWorldItems.sectors.push_back(SectorCoords{ x, y, z });
gAllWorldItems.NumItems.push_back(nItems);
gAllWorldItems.Items.push_back(Items);
}
void RemoveSectorFromWorldItems(INT16 x, INT16 y, INT16 z)
{
for (size_t i = 0; i < gAllWorldItems.sectors.size(); i++)
{
const auto sector = gAllWorldItems.sectors[i];
if (sector.x == x && sector.y == y && sector.z == z)
{
gAllWorldItems.sectors.erase(gAllWorldItems.sectors.begin() + i);
gAllWorldItems.NumItems.erase(gAllWorldItems.NumItems.begin() + i);
gAllWorldItems.Items.erase(gAllWorldItems.Items.begin() + i);
}
}
}
void UpdateWorldItems(INT16 x, INT16 y, INT16 z, UINT32 nItems, std::vector<WORLDITEM> &Items)
{
if (nItems == 0)
{
RemoveSectorFromWorldItems(x, y, z);
ReSetSectorFlag(x, y, z, SF_ITEM_TEMP_FILE_EXISTS);
}
else if (SectorIsInWorldItems(x, y, z))
{
const auto i = FindWorldItemSector(x, y, z);
gAllWorldItems.NumItems[i] = nItems;
gAllWorldItems.Items[i] = Items;
}
else
{
AddSectorItemsToWorldItems(x, y, z, nItems, Items);
SetSectorFlag(x, y, z, SF_ITEM_TEMP_FILE_EXISTS);
}
UINT32 visibleItemCount = 0;
for (size_t i = 0; i < nItems; ++i)
{
// if visible to player, then state fact
if (IsMapScreenWorldItemVisibleInMapInventory(&Items[i]))
{
visibleItemCount += Items[i].object.ubNumberOfObjects;
}
}
SetNumberOfVisibleWorldItemsInSectorStructureForSector(x, y, z, visibleItemCount);
}
void ClearAllWorldItems(void)
{
gAllWorldItems.sectors.clear();
gAllWorldItems.NumItems.clear();
gAllWorldItems.Items.clear();
}
INT32 GetAmountOfWorldItems(INT16 x, INT16 y, INT16 z)
{
const auto i = FindWorldItemSector(x,y, z);
if (i != -1)
{
return gAllWorldItems.NumItems[i];
}
else
{
return 0;
}
}
void PruneWorldItems(void)
{
for (size_t i = 0; i < gAllWorldItems.Items.size(); i++)
{
std::vector<WORLDITEM>& items = gAllWorldItems.Items[i];
for (INT32 j = items.size()-1; j > 0; j--)
{
if (items[j].fExists == false)
{
items.erase(items.begin()+j);
}
}
if (gAllWorldItems.Items[i].size() > 0)
{
gAllWorldItems.NumItems[i] = gAllWorldItems.Items[i].size();
}
else
{
gAllWorldItems.sectors.erase(gAllWorldItems.sectors.begin() + i);
gAllWorldItems.NumItems.erase(gAllWorldItems.NumItems.begin() + i);
gAllWorldItems.Items.erase(gAllWorldItems.Items.begin() + i);
}
}
}
WORLDBOMB * gWorldBombs = NULL; WORLDBOMB * gWorldBombs = NULL;
UINT32 guiNumWorldBombs = 0; UINT32 guiNumWorldBombs = 0;
+18
View File
@@ -139,4 +139,22 @@ void ResizeWorldItems(void);//dnl ch75 271013
void RefreshWorldItemsIntoItemPools( std::vector<WORLDITEM>& pItemList, INT32 iNumberOfItems );//dnl ch75 271013 void RefreshWorldItemsIntoItemPools( std::vector<WORLDITEM>& pItemList, INT32 iNumberOfItems );//dnl ch75 271013
void CoolDownWorldItems( ); // Flugente: Cool/decay down all items in this sector void CoolDownWorldItems( ); // Flugente: Cool/decay down all items in this sector
struct SectorCoords
{
INT16 x;
INT16 y;
INT16 z;
};
struct WorldItems
{
std::vector<SectorCoords> sectors;
std::vector<UINT32> NumItems;
std::vector<std::vector<WORLDITEM>> Items;
};
void UpdateWorldItems(INT16 x, INT16 y, INT16 z, UINT32 nItems, std::vector<WORLDITEM> &Items);
void AddSectorItemsToWorldItems(INT16 x, INT16 y, INT16 z, UINT32 nItems, std::vector<WORLDITEM> &Items);
INT32 FindWorldItemSector(INT16 x, INT16 y, INT16 z);
bool SectorIsInWorldItems(INT16 x, INT16 y, INT16 z);
#endif #endif