Brief: //dnl ch75

- More map editor fixes and map inventory pool performance improvement for big maps.
Details:
- Fix not showing expected messagebox on exit (ALT+x) which also throw exception and goes to improper mapeditor exit.
- Fix second annoying sticky message which shouldn't popup during map loading and performing RemoveProhibitedAttachments.
- Fix CTD when delete all enemies or civilians or all of them in map.
- Fix some std exception when reporting for missing optional xml file.
- Fix memory and map corruption in old mapeditors if loaded old map has item with invalid attachment and we try to attach something else.
- As years ago pInventoryPoolList had migrated from WORLDITEM* array to std::vector<WORLDITEM> it was time to do that with gWorldItems too, all necessary functions which need to be adopted to gWorldItems std::vector type are also changed.
- Resize code for gWorldItems is changed hoping will lead into less corruption problems as now could occur in mapeditor and game when code automatically doing attachment changes.
- Change code for handling map inventory which now should be fast enough to support AIMNAS project which will probably deal with thousands of items per map.


git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6554 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Kriplo
2013-11-03 16:26:30 +00:00
parent 0c82c1845f
commit b91bc7b209
24 changed files with 593 additions and 711 deletions
+1 -1
View File
@@ -1680,7 +1680,7 @@ void IndicateSelectedMerc( INT16 sID )
}
}
//if we made it this far, then we have a new merc cursor indicator to draw.
if( gpSelected == NULL || gpSelected->pSoldier )
if( gpSelected && gpSelected->pSoldier )//dnl ch75 261013
gsSelectedMercGridNo = gpSelected->pSoldier->sGridNo;
else
{
+3
View File
@@ -1430,6 +1430,7 @@ void ToggleAttachment( GUI_BUTTON *btn, INT32 reason )
{
INT32 i;
UINT16 usAttachment = 0;
ResizeWorldItems();//dnl ch75 021113 to prevent memory corruption during resize if somehow in created item we manage to put invalid attachment (DRAGUNOV with SNIPERCOPE problem in older mapeditors)
for( i = 0; i < NUM_ATTACHMENT_BUTTONS; i++ )
{ //Loop through and find the button that was just modified
switch( i )
@@ -1469,6 +1470,7 @@ void ToggleCeramicPlates( GUI_BUTTON *btn, INT32 reason )
{
if( reason & MSYS_CALLBACK_REASON_LBUTTON_UP )
{
ResizeWorldItems();//dnl ch75 021113 just precaution to prevent eventual memory corruption during resize if somehow AttachObject find invalid attachment
gfCeramicPlates ^= TRUE;
if( gfCeramicPlates )
{
@@ -1490,6 +1492,7 @@ void ToggleDetonator( GUI_BUTTON *btn, INT32 reason )
{
if( reason & MSYS_CALLBACK_REASON_LBUTTON_UP )
{
ResizeWorldItems();//dnl ch75 021113 just precaution to prevent eventual memory corruption during resize if somehow AttachObject find invalid attachment
if( !gfDetonator )
{
gfDetonator = TRUE;
+6 -2
View File
@@ -2051,7 +2051,6 @@ void HandleKeyboardShortcuts( )
if( gfEditingDoor )
KillDoorEditing();
iCurrentAction = ACTION_QUIT_GAME;
return;
}
break;
case 'z':
@@ -2313,7 +2312,7 @@ UINT32 PerformSelectedAction( void )
break;
case ACTION_QUIT_GAME:
gfProgramIsRunning = FALSE;
//gfProgramIsRunning = FALSE;//dnl ch75 251013 throw exception on exit without showing message box
case ACTION_EXIT_EDITOR:
if( EditModeShutdown( ) )
{
@@ -2741,6 +2740,11 @@ UINT32 ProcessEditscreenMessageBoxResponse()
{
gfConfirmExitFirst = FALSE;
iEditorToolbarState = TBAR_MODE_EXIT_EDIT;
if(iCurrentAction == ACTION_QUIT_GAME)//dnl ch75 251013
{
iEditorToolbarState = TBAR_MODE_QUIT_GAME;
gfProgramIsRunning = FALSE;
}
}
return EDIT_SCREEN;
}
+6 -20
View File
@@ -6105,7 +6105,7 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
CHAR16 wSectorName[ 64 ];
GetShortSectorString( sMapX, sMapY, wSectorName );
WORLDITEM* pWorldItem_Target = NULL;
std::vector<WORLDITEM> pWorldItem_Target;//dnl ch75 271013
// now loop over all sectors from which we take stuff, and move the equipment
std::map<UINT8, UINT8>::iterator itend = sectormercmap.end();
@@ -6136,11 +6136,7 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
UINT32 uiTotalNumberOfRealItems_Target = 0;
// use the new map
if ( pWorldItem_Target )
{
delete[] pWorldItem_Target;
pWorldItem_Target = NULL;
}
pWorldItem_Target.clear();//dnl ch75 021113
if( ( gWorldSectorX == targetX )&&( gWorldSectorY == targetY ) && (gbWorldSectorZ == bZ ) )
{
@@ -6157,8 +6153,8 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
if( uiTotalNumberOfRealItems_Target > 0 )
{
// allocate space for the list
pWorldItem_Target = new WORLDITEM[ uiTotalNumberOfRealItems_Target ];
pWorldItem_Target.resize(uiTotalNumberOfRealItems_Target);//dnl ch75 271013
// now load into mem
LoadWorldItemsFromTempItemFile( targetX, targetY, bZ, pWorldItem_Target );
}
@@ -6236,7 +6232,7 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
WORLDITEM* pWorldItem_tmp = NULL;
if( ( gWorldSectorX != targetX ) || ( gWorldSectorY != targetY ) || (gbWorldSectorZ != bZ ) )
{
pWorldItem_tmp = new WORLDITEM[ uiTotalNumberOfRealItems_Target ];
std::vector<WORLDITEM> pWorldItem_tmp(uiTotalNumberOfRealItems_Target);//dnl ch75 271013
// copy over old inventory
UINT32 newcount = 0;
@@ -6250,11 +6246,7 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
}
// use the new map
if ( pWorldItem_Target )
{
delete[] pWorldItem_Target;
pWorldItem_Target = NULL;
}
pWorldItem_Target.clear();//dnl ch75 021113
pWorldItem_Target = pWorldItem_tmp;
}
@@ -6270,12 +6262,6 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
//Save the Items to the the file
SaveWorldItemsToTempItemFile( targetX, targetY, bZ, uiTotalNumberOfRealItems_Target, pWorldItem_Target );
}
if ( pWorldItem_tmp )
{
delete[] pWorldItem_tmp;
pWorldItem_tmp = NULL;
}
// award a bit of experience to the movers
UINT16 itemsperperson = moveditems / (*it).second;
+2 -2
View File
@@ -457,7 +457,7 @@ void HourlyStealUpdate()
// we loop over this sector's inventory and look for something shiny. We will pick it up if we hae enough space in our inventory
// open sector inv
UINT32 uiTotalNumberOfRealItems = 0;
WORLDITEM* pWorldItem = NULL;
std::vector<WORLDITEM> pWorldItem;//dnl ch75 271013
BOOLEAN fReturn = FALSE;
if( ( gWorldSectorX == pSoldier->sSectorX ) && ( gWorldSectorY == pSoldier->sSectorY ) && (gbWorldSectorZ == pSoldier->bSectorZ ) )
@@ -479,7 +479,7 @@ void HourlyStealUpdate()
if( uiTotalNumberOfRealItems > 0 )
{
// allocate space for the list
pWorldItem = new WORLDITEM[ uiTotalNumberOfRealItems ];
pWorldItem.resize(uiTotalNumberOfRealItems);//dnl ch75 271013
if ( !uiTotalNumberOfRealItems )
continue;
File diff suppressed because it is too large Load Diff
@@ -84,5 +84,5 @@ BOOLEAN SwitchToInventoryPoolQ(UINT8 newidx);
// Flugente: handle various cooldown functions over an array of items in a specific sector.
// if fWithMinutes = true, adjust cooldown for time since sector was last entered
// otherwise its used for a turn-precise cooldown
void HandleSectorCooldownFunctions( INT16 sMapX, INT16 sMapY, INT8 sMapZ, WORLDITEM* pWorldItem, UINT32 size, BOOLEAN fWithMinutes, BOOLEAN fUndo = FALSE);
void HandleItemCooldownFunctions( OBJECTTYPE* itemStack, INT32 deltaSeconds, UINT16 naturalDirt = 100, BOOLEAN isUnderground = FALSE);
void HandleSectorCooldownFunctions( INT16 sMapX, INT16 sMapY, INT8 sMapZ, std::vector<WORLDITEM>& pWorldItem, UINT32 size, BOOLEAN fWithMinutes, BOOLEAN fUndo = FALSE);//dnl ch75 271013
void HandleItemCooldownFunctions( OBJECTTYPE* itemStack, INT32 deltaSeconds, UINT16 naturalDirt = 100, BOOLEAN isUnderground = FALSE);
+7 -6
View File
@@ -2162,6 +2162,7 @@ void EnemyCapturesPlayerSoldier( SOLDIERTYPE *pSoldier )
RemoveCharacterFromSquads( pSoldier );
WORLDITEM WorldItem;
std::vector<WORLDITEM> pWorldItem(1);//dnl ch75 271013
// Is this the first one..?
if ( gubQuest[ QUEST_HELD_IN_ALMA ] == QUESTNOTSTARTED )
@@ -2186,9 +2187,9 @@ void EnemyCapturesPlayerSoldier( SOLDIERTYPE *pSoldier )
WorldItem.bVisible = FALSE;
WorldItem.bRenderZHeightAboveLevel = 0;
pSoldier->inv[ i ].MoveThisObjectTo(WorldItem.object);
AddWorldItemsToUnLoadedSector( gModSettings.ubInitialPOWSectorX, gModSettings.ubInitialPOWSectorY, 0,
gModSettings.iInitialPOWItemGridNo[ gStrategicStatus.ubNumCapturedForRescue ], 1, &WorldItem, FALSE );
//dnl ch75 271013
pWorldItem[0] = WorldItem;
AddWorldItemsToUnLoadedSector( gModSettings.ubInitialPOWSectorX, gModSettings.ubInitialPOWSectorY, 0, gModSettings.iInitialPOWItemGridNo[ gStrategicStatus.ubNumCapturedForRescue ], 1, pWorldItem, FALSE );
}
}
@@ -2219,9 +2220,9 @@ void EnemyCapturesPlayerSoldier( SOLDIERTYPE *pSoldier )
WorldItem.bVisible = FALSE;
WorldItem.bRenderZHeightAboveLevel = 0;
pSoldier->inv[ i ].MoveThisObjectTo(WorldItem.object);
AddWorldItemsToUnLoadedSector( gModSettings.ubMeanwhileInterrogatePOWSectorX, gModSettings.ubMeanwhileInterrogatePOWSectorY, 0,
gModSettings.iMeanwhileInterrogatePOWItemGridNo[ gStrategicStatus.ubNumCapturedForRescue ], 1, &WorldItem, FALSE );
//dnl ch75 271013
pWorldItem[0] = WorldItem;
AddWorldItemsToUnLoadedSector( gModSettings.ubMeanwhileInterrogatePOWSectorX, gModSettings.ubMeanwhileInterrogatePOWSectorY, 0, gModSettings.iMeanwhileInterrogatePOWItemGridNo[ gStrategicStatus.ubNumCapturedForRescue ], 1, pWorldItem, FALSE );
}
}
+2 -16
View File
@@ -423,12 +423,9 @@ void HandleDelayedItemsArrival( UINT32 uiReason )
INT32 sStartGridNo;
UINT32 uiNumWorldItems, uiLoop;
BOOLEAN fOk;
WORLDITEM * pTemp = 0;
std::vector<WORLDITEM> pTemp;//dnl ch75 271013
UINT8 ubLoop;
//#if 0
if (uiReason == NPC_SYSTEM_EVENT_ACTION_PARAM_BONUS + NPC_ACTION_RETURN_STOLEN_SHIPMENT_ITEMS )
{
if ( gMercProfiles[ PABLO ].bMercStatus == MERC_IS_DEAD )
@@ -504,11 +501,7 @@ void HandleDelayedItemsArrival( UINT32 uiReason )
{
return;
}
pTemp = new WORLDITEM[ uiNumWorldItems];
if (!pTemp)
{
return;
}
pTemp.resize(uiNumWorldItems);//dnl ch75 271013
fOk = LoadWorldItemsFromTempItemFile( BOBBYR_SHIPPING_DEST_SECTOR_X, BOBBYR_SHIPPING_DEST_SECTOR_Y, BOBBYR_SHIPPING_DEST_SECTOR_Z, pTemp );
if (fOk)
{
@@ -522,13 +515,6 @@ void HandleDelayedItemsArrival( UINT32 uiReason )
AddWorldItemsToUnLoadedSector( BOBBYR_SHIPPING_DEST_SECTOR_X, BOBBYR_SHIPPING_DEST_SECTOR_Y, BOBBYR_SHIPPING_DEST_SECTOR_Z, 0, uiNumWorldItems, pTemp, TRUE );
}
}
if (pTemp) {
delete [] pTemp;
}
//#endif
}
void AddSecondAirportAttendant( void )
+2 -5
View File
@@ -1111,7 +1111,7 @@ void RemoveRandomItemsInSector( INT16 sSectorX, INT16 sSectorY, INT16 sSectorZ,
{
// remove random items in sector
UINT32 uiNumberOfItems = 0, iCounter = 0;
WORLDITEM *pItemList;
std::vector<WORLDITEM> pItemList;//dnl ch75 271013
UINT32 uiNewTotal = 0;
CHAR16 wSectorName[ 128 ];
@@ -1138,7 +1138,7 @@ void RemoveRandomItemsInSector( INT16 sSectorX, INT16 sSectorY, INT16 sSectorZ,
return;
}
pItemList = new WORLDITEM[ uiNumberOfItems ];
pItemList.resize(uiNumberOfItems);//dnl ch75 271013
// now load items
LoadWorldItemsFromTempItemFile( sSectorX, sSectorY, ( UINT8 )sSectorZ, pItemList );
@@ -1167,9 +1167,6 @@ void RemoveRandomItemsInSector( INT16 sSectorX, INT16 sSectorY, INT16 sSectorZ,
{
AddWorldItemsToUnLoadedSector( sSectorX, sSectorY, ( UINT8 )sSectorZ, 0, uiNumberOfItems, pItemList, TRUE );
}
// mem free
delete[]( pItemList );
}
else // handle a loaded sector
{
+2
View File
@@ -209,6 +209,8 @@ void AddExtraItems(UINT8 x, UINT8 y, UINT8 z, bool sectorIsLoaded)
}
strcat(fileName, ".xml");
if(!FileExists(fileName))//dnl ch75 261013 just to avoid sdd::exception under debug from VFS when file not exist
return;
// Open extra items file
HWFILE hFile;
+41 -2
View File
@@ -7394,8 +7394,29 @@ void GetMapKeyboardInput( UINT32 *puiNewEvent )
case ')':
SelectAllCharactersInSquad( 19 ); // internal squad #s start at 0
break;
case '\''://dnl ch75 021113
#ifdef _DEBUG
// temporary add soldiers to your list for equipment inspection and general testing
for(UINT32 ubLoop=0; ubLoop<guiNumMercSlots&&gGameExternalOptions.fEnableInventoryPoolQ; ubLoop++)
{
if(MercSlots[ubLoop] != NULL && MercSlots[ubLoop]->bTeam == ENEMY_TEAM && MercSlots[ubLoop]->bActive)
{
for(int i=0; i<CODE_MAXIMUM_NUMBER_OF_PLAYER_SLOTS; i++)
{
if(gCharactersList[i].usSolID == MercSlots[ubLoop]->ubID)
break;
if(gCharactersList[i].usSolID == 0 && gCharactersList[i].fValid == FALSE)
{
gCharactersList[i].usSolID = MercSlots[ubLoop]->ubID;
gCharactersList[i].fValid = TRUE;
break;
}
}
}
}
fTeamPanelDirty = TRUE;
#endif
break;
case 'a':
if( fAlt )
{
@@ -7881,6 +7902,24 @@ void GetMapKeyboardInput( UINT32 *puiNewEvent )
}
#endif
break;
case 'Q'://dnl ch75 021113
#ifdef _DEBUG
extern UINT8 gInventoryPoolIndex;
if(fShowMapInventoryPool == TRUE && gInventoryPoolIndex == '0')
{
if(gGameExternalOptions.fEnableInventoryPoolQ)
{
gGameExternalOptions.fEnableInventoryPoolQ = FALSE;
ScreenMsg(FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"InventoryPoolQ disabled.");
}
else
{
gGameExternalOptions.fEnableInventoryPoolQ = TRUE;
ScreenMsg(FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"InventoryPoolQ enabled.");
}
}
#endif
break;
case 'r':
if( gfPreBattleInterfaceActive )
{ //activate autoresolve in prebattle interface.
-22
View File
@@ -6207,28 +6207,6 @@ BOOLEAN ContinuePastBoobyTrapInMapScreen( OBJECTTYPE *pObject, SOLDIERTYPE *pSol
return( TRUE );
}
// Well, clears all item pools
void ClearAllItemPools( )
{
INT32 cnt;
for ( cnt = 0; cnt < WORLD_MAX; cnt++ )
{
RemoveItemPool( cnt, 0 );
RemoveItemPool( cnt, 1 );
}
}
// Refresh item pools
void RefreshItemPools( WORLDITEM * pItemList, INT32 iNumberOfItems )
{
ClearAllItemPools( );
RefreshWorldItemsIntoItemPools( pItemList, iNumberOfItems );
}
INT32 FindNearestAvailableGridNoForItem( INT32 sSweetGridNo, INT8 ubRadius )
{
INT32 sTop, sBottom;
+16 -18
View File
@@ -3671,7 +3671,7 @@ UINT32 ItemFitness_WithAmmo( OBJECTTYPE* pObj, UINT8 idx, UINT32 uiBullets )
}
// retreives the next free slot in pWorldItem (we want to keep it short and not add too many items)
UINT32 GetNextFreeIndex( WORLDITEM* pWorldItem, UINT32 uiMaxCount, UINT32 uiCount )
UINT32 GetNextFreeIndex( std::vector<WORLDITEM>& pWorldItem, UINT32 uiMaxCount, UINT32 uiCount )//dnl ch75 271013
{
for( ; uiCount < uiMaxCount; ++uiCount )
{
@@ -3711,10 +3711,10 @@ struct ItemSearchStruct {
};
// evaluate an object an remember it if it is the best so far
void EvaluateObjForItem( WORLDITEM* pWorldItem, OBJECTTYPE* pObj, UINT32 uiCount, ItemSearchStruct* pSi )
void EvaluateObjForItem( std::vector<WORLDITEM>& pWorldItem, OBJECTTYPE* pObj, UINT32 uiCount, ItemSearchStruct* pSi )//dnl ch75 271013
{
// safety first
if ( !pWorldItem || !pObj || !pSi )
if ( pWorldItem.empty() || !pObj || !pSi )
// THIS SHOULDN'T HAPPEN!
return;
@@ -3732,10 +3732,10 @@ void EvaluateObjForItem( WORLDITEM* pWorldItem, OBJECTTYPE* pObj, UINT32 uiCount
}
// special version of EvaluateObjForItem(): we take the existing ammo count into consideration
void EvaluateObjForItem_WithAmmo( WORLDITEM* pWorldItem, OBJECTTYPE* pObj, UINT32 uiCount, ItemSearchStruct* pSi, UINT32 uiBullets )
void EvaluateObjForItem_WithAmmo( std::vector<WORLDITEM>& pWorldItem, OBJECTTYPE* pObj, UINT32 uiCount, ItemSearchStruct* pSi, UINT32 uiBullets )//dnl ch75 271013
{
// safety first
if ( !pWorldItem || !pObj || !pSi )
if ( pWorldItem.empty() || !pObj || !pSi )
// THIS SHOULDN'T HAPPEN!
return;
@@ -3754,10 +3754,10 @@ void EvaluateObjForItem_WithAmmo( WORLDITEM* pWorldItem, OBJECTTYPE* pObj, UINT3
// forward declaration for default parameter
// if pSi has an entry, move gun from pWorldItem into pp
void SearchItemRetrieval( WORLDITEM* pWorldItem, ItemSearchStruct* pSi, SOLDIERCREATE_STRUCT *pp, UINT8 usTake = 1 );
void SearchItemRetrieval( std::vector<WORLDITEM>& pWorldItem, ItemSearchStruct* pSi, SOLDIERCREATE_STRUCT *pp, UINT8 usTake = 1 );//dnl ch75 271013
// if pSi has an entry, move gun from pWorldItem into pp
void SearchItemRetrieval( WORLDITEM* pWorldItem, ItemSearchStruct* pSi, SOLDIERCREATE_STRUCT *pp, UINT8 usTake )
void SearchItemRetrieval( std::vector<WORLDITEM>& pWorldItem, ItemSearchStruct* pSi, SOLDIERCREATE_STRUCT *pp, UINT8 usTake )//dnl ch75 271013
{
if ( pSi->found && !pSi->done )
{
@@ -3869,7 +3869,7 @@ void MoveOneMilitiaEquipmentSet(INT16 sSourceX, INT16 sSourceY, INT16 sTargetX,
BOOLEAN fReturn = FALSE;
UINT32 uiTotalNumberOfRealItems = 0;
UINT32 uiNumOriginalItems = 0;
WORLDITEM* pWorldItem = NULL;
std::vector<WORLDITEM> pWorldItem;//dnl ch75 271013
SOLDIERCREATE_STRUCT tmp;
UINT32 uiCount = 0;
INT32 dummygridno = NOWHERE;
@@ -3895,8 +3895,8 @@ void MoveOneMilitiaEquipmentSet(INT16 sSourceX, INT16 sSourceY, INT16 sTargetX,
if( uiTotalNumberOfRealItems > 0 )
{
// allocate space for the list
pWorldItem = new WORLDITEM[ uiTotalNumberOfRealItems ];
pWorldItem.resize(uiTotalNumberOfRealItems);//dnl ch75 271013
// now load into mem
LoadWorldItemsFromTempItemFile( sTargetX, sTargetY, 0, pWorldItem );
}
@@ -3939,8 +3939,8 @@ void MoveOneMilitiaEquipmentSet(INT16 sSourceX, INT16 sSourceY, INT16 sTargetX,
UINT32 uiNewInvSize = max(uiTotalNumberOfRealItems, existingitemsfound + numnewitems);
// create a bigger inventory wit big enough size
WORLDITEM* pWorldItem_tmp = new WORLDITEM[ uiNewInvSize ];
std::vector<WORLDITEM> pWorldItem_tmp(uiNewInvSize);//dnl ch75 271013
// copy over old inventory
for( uiCount = 0; uiCount < uiTotalNumberOfRealItems; ++uiCount )
{
@@ -3976,7 +3976,6 @@ void MoveOneMilitiaEquipmentSet(INT16 sSourceX, INT16 sSourceY, INT16 sTargetX,
// use the new map
uiTotalNumberOfRealItems = uiNewInvSize;
delete[] pWorldItem;
pWorldItem = pWorldItem_tmp;
/////////////////////////////// ADD ITEMS FROM STRUCT TO SECTOR /////////////////////////////////////////////////////
@@ -4053,7 +4052,7 @@ void TakeMilitiaEquipmentfromSector( INT16 sMapX, INT16 sMapY, INT8 sMapZ, SOLDI
{
BOOLEAN fReturn = FALSE;
UINT32 uiTotalNumberOfRealItems = 0;
WORLDITEM* pWorldItem = NULL;
std::vector<WORLDITEM> pWorldItem;//dnl ch75 271013
UINT32 uiCount = 0;
INT32 dummygridno = NOWHERE; // this gridno will be the new position of items we create (ammo crates)
BOOLEAN fNightTime = NightTime();
@@ -4105,7 +4104,7 @@ void TakeMilitiaEquipmentfromSector( INT16 sMapX, INT16 sMapY, INT8 sMapZ, SOLDI
if( uiTotalNumberOfRealItems > 0 )
{
// allocate space for the list
pWorldItem = new WORLDITEM[ uiTotalNumberOfRealItems ];
pWorldItem.resize(uiTotalNumberOfRealItems);//dnl ch75 271013
if ( !uiTotalNumberOfRealItems )
return;
@@ -4629,7 +4628,7 @@ void TakeMilitiaEquipmentfromSector( INT16 sMapX, INT16 sMapY, INT8 sMapZ, SOLDI
for(INT16 i = 0; i < pObj->ubNumberOfObjects; ++i)
newammo += (*pObj)[i]->data.ubShotsLeft;
UINT32 addammo = min(usSelectedGunBulletsNeeded - usSelectedGunBulletCount, newammo);
UINT32 addammo = min((UINT32)(usSelectedGunBulletsNeeded - usSelectedGunBulletCount), newammo);//dnl ch75 271013
SpawnFittingAmmo( pp, &(pp->Inv[ HANDPOS ]), ammotype, addammo );
@@ -4726,7 +4725,7 @@ void TakeMilitiaEquipmentfromSector( INT16 sMapX, INT16 sMapY, INT8 sMapZ, SOLDI
UINT32 uiNewInvSize = uiTotalNumberOfRealItems + 1;
// create a bigger inventory wit big enough size
WORLDITEM* pWorldItem_tmp = new WORLDITEM[ uiNewInvSize ];
std::vector<WORLDITEM> pWorldItem_tmp(uiNewInvSize);//dnl ch75 271013
// copy over old inventory
for( uiCount = 0; uiCount < uiTotalNumberOfRealItems; ++uiCount )
@@ -4747,7 +4746,6 @@ void TakeMilitiaEquipmentfromSector( INT16 sMapX, INT16 sMapY, INT8 sMapZ, SOLDI
// use the new map
uiTotalNumberOfRealItems = uiNewInvSize;
delete[] pWorldItem;
pWorldItem = pWorldItem_tmp;
}
///////////////////////////////// 3rd loop afterwork /////////////////////////////////////////////////////////
+5 -1
View File
@@ -483,9 +483,13 @@ LBENODE* OBJECTTYPE::GetLBEPointer(unsigned int index)
bool OBJECTTYPE::exists()
{
#if 0//dnl ch75 011113
if(this == NULL)
return(FALSE);
return (ubNumberOfObjects > 0 && usItem != NOTHING);
#else
return(this && ubNumberOfObjects && usItem);
#endif
}
void OBJECTTYPE::SpliceData(OBJECTTYPE& sourceObject, unsigned int numToSplice, StackedObjects::iterator beginIter)
@@ -1671,7 +1675,7 @@ OBJECTTYPE& OBJECTTYPE::operator=(const OLD_OBJECTTYPE_101& src)
(*this)[x]->attachments.resize(usAttachmentSlotIndexVector.size());
}
}*/
RemoveProhibitedAttachments(NULL, this, this->usItem);
AttachDefaultAttachments(this);//RemoveProhibitedAttachments(NULL, this, this->usItem);//dnl ch75 261013
//just a precaution
//ADB ubWeight has been removed, see comments in OBJECTTYPE
//this->ubWeight = CalculateObjectWeight(this);
+37 -23
View File
@@ -2448,7 +2448,7 @@ BOOLEAN ValidItemAttachment( OBJECTTYPE * pObj, UINT16 usAttachment, BOOLEAN fAt
}
else
{
if ( fAttemptingAttachment && ValidAttachmentClass( usAttachment, pObj->usItem ) )
if ( fAttemptingAttachment && fDisplayMessage && ValidAttachmentClass( usAttachment, pObj->usItem ) )//dnl ch75 251013
{
// well, maybe the player thought he could
CHAR16 zTemp[ 100 ];
@@ -5594,7 +5594,7 @@ IMPORTANT: If you use AttachObject/RemoveAttachment with fRemoveProhibited TRUE
*/
void RemoveProhibitedAttachments(SOLDIERTYPE* pSoldier, OBJECTTYPE* pObj, UINT16 usItem, BOOLEAN fOnlyRemoveWhenSlotsChange)
{
if(!pObj->exists())
if(!pObj->exists() || !(*pObj)[0]->AttachmentListSize())//dnl ch75 261013
return;
if(UsingNewAttachmentSystem()==true){
@@ -5708,20 +5708,26 @@ void RemoveProhibitedAttachments(SOLDIERTYPE* pSoldier, OBJECTTYPE* pObj, UINT16
}
else
{
// put it on the ground
INT32 sGridNo = 1;
if(guiCurrentItemDescriptionScreen == MAP_SCREEN && fShowMapInventoryPool)
// put it on the ground //dnl ch75 281013
INT32 sGridNo = NOWHERE;
UINT8 ubLevel = 0;
for(int i=0; i<guiNumWorldItems; i++)
{
AutoPlaceObjectInInventoryStash(&(*iter), sGridNo);
//AddItemToPool( sGridNo, &(*iter), 1, pathing, WORLD_ITEM_REACHABLE, 0 );
if(gWorldItems[i].fExists && (pObj == &gWorldItems[i].object))
{
sGridNo = gWorldItems[i].sGridNo;
ubLevel = gWorldItems[i].ubLevel;
break;
}
}
else
if(sGridNo != NOWHERE)
{
AddItemToPool( sGridNo, &(*iter), 1, 0, WORLD_ITEM_REACHABLE, 0 );
}
if(guiCurrentItemDescriptionScreen == MAP_SCREEN && fShowMapInventoryPool)
AutoPlaceObjectInInventoryStash(&(*iter), sGridNo);
else
AddItemToPool(sGridNo, &(*iter), 1, ubLevel, WORLD_ITEM_REACHABLE, 0);
}
}
iter = tempAttachList.erase(iter);
}
else
@@ -7860,17 +7866,7 @@ BOOLEAN CreateItem( UINT16 usItem, INT16 bStatus, OBJECTTYPE * pObj )
pObj->AttachObject(NULL,&defaultAttachment, FALSE);
}
#else
if(gGameOptions.ubAttachmentSystem || gfEditMode)
{
for(UINT8 cnt=0; cnt<MAX_DEFAULT_ATTACHMENTS; cnt++)
{
if(Item[usItem].defaultattachments[cnt] == NONE)
break;
OBJECTTYPE defaultAttachment;
CreateItem(Item[usItem].defaultattachments[cnt], (*pObj)[0]->data.gun.bGunStatus, &defaultAttachment);
pObj->AttachObject(NULL, &defaultAttachment, FALSE);
}
}
AttachDefaultAttachments(pObj);//dnl ch75 261013
#endif
}
@@ -15328,4 +15324,22 @@ UINT8 GetInventorySleepModifier( SOLDIERTYPE *pSoldier )
}
return( modifier );
}
void AttachDefaultAttachments(OBJECTTYPE *pObj, BOOLEAN fAllDefaultAttachments)//dnl ch75 261013
{
if(pObj->usItem && gGameOptions.ubAttachmentSystem)
{
RemoveProhibitedAttachments(NULL, pObj, pObj->usItem);
//Madd: ok, so this drives me nuts -- why bother with default attachments if the map isn't going to load them for you?
//this should fix that...
for(UINT8 cnt=0; cnt<MAX_DEFAULT_ATTACHMENTS; cnt++)
{
if(Item[pObj->usItem].defaultattachments[cnt] == NONE || !(gGameOptions.ubAttachmentSystem && Item[Item[pObj->usItem].defaultattachments[cnt]].inseparable || fAllDefaultAttachments))
break;
OBJECTTYPE defaultAttachment;
CreateItem(Item[pObj->usItem].defaultattachments[cnt], (*pObj)[0]->data.gun.bGunStatus, &defaultAttachment);
pObj->AttachObject(NULL, &defaultAttachment, FALSE);
}
}
}
+2
View File
@@ -524,6 +524,8 @@ INT32 GetPercentRangeBonus( OBJECTTYPE * pObj );
// silversurfer: returns the SleepModifier from the characters inventory
UINT8 GetInventorySleepModifier( SOLDIERTYPE *pSoldier );
void AttachDefaultAttachments(OBJECTTYPE *pObj, BOOLEAN fAllDefaultAttachments=TRUE);//dnl ch75 261013
#endif
+1 -1
View File
@@ -2621,7 +2621,7 @@ void CreateDetailedPlacementGivenStaticDetailedPlacementAndBasicPlacementInfo(
{
pp->Inv[ i ] = spp->Inv[ i ];
//WarmSteel - if someone in the map editor placed a wrong attachment on this gun, fix it.
RemoveProhibitedAttachments(NULL, &pp->Inv[i], pp->Inv[i].usItem);
AttachDefaultAttachments(&pp->Inv[i]);//RemoveProhibitedAttachments(NULL, &pp->Inv[i], pp->Inv[i].usItem);//dnl ch75 261013
//return;
}
}
+28 -79
View File
@@ -570,7 +570,7 @@ BOOLEAN LoadMapTempFilesFromSavedGameFile( HWFILE hFile )
BOOLEAN UpdateWorldItemsTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
{
UINT32 uiTotalNumberOfItems=0;
WORLDITEM* pTotalSectorList = NULL;
std::vector<WORLDITEM> pTotalSectorList;//dnl ch75 271013
BOOLEAN fReturn = GetNumberOfWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, &( uiTotalNumberOfItems ), FALSE );
if (fReturn == false)
{
@@ -581,7 +581,7 @@ BOOLEAN UpdateWorldItemsTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
if( uiTotalNumberOfItems > 0 )
{
// allocate space for the list
pTotalSectorList = new WORLDITEM[ uiTotalNumberOfItems ];
pTotalSectorList.resize(uiTotalNumberOfItems);//dnl ch75 271013
LoadWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, pTotalSectorList );
int backup = guiCurrentSaveGameVersion;
@@ -590,15 +590,6 @@ BOOLEAN UpdateWorldItemsTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
guiCurrentSaveGameVersion = backup;
}
// if anything was alloced, then get rid of it
if( pTotalSectorList != NULL )
{
delete[]( pTotalSectorList );
pTotalSectorList = NULL;
}
return TRUE;
}
@@ -626,7 +617,7 @@ BOOLEAN UpdateCIVTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
}
*/
BOOLEAN SaveWorldItemsToTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT32 uiNumberOfItems, WORLDITEM *pData )
BOOLEAN SaveWorldItemsToTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT32 uiNumberOfItems, std::vector<WORLDITEM>& pData, BOOLEAN fUpdateVisibleItems )//dnl ch75 271013
{
HWFILE hFile;
UINT32 uiNumBytesWritten=0;
@@ -668,14 +659,15 @@ BOOLEAN SaveWorldItemsToTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT
SetSectorFlag( sMapX, sMapY, bMapZ, SF_ITEM_TEMP_FILE_EXISTS );
SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems( sMapX, sMapY, bMapZ, FALSE );
if( fUpdateVisibleItems )//dnl ch75 311013
SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems( sMapX, sMapY, bMapZ, FALSE );
return( TRUE );
}
BOOLEAN LoadWorldItemsFromTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, WORLDITEM *pData )
BOOLEAN LoadWorldItemsFromTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, std::vector<WORLDITEM>& pData )//dnl ch75 271013
{
UINT32 uiNumBytesRead=0;
HWFILE hFile;
@@ -817,7 +809,7 @@ BOOLEAN GetNumberOfWorldItemsFromTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bM
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;
WORLDITEM *pWorldItems;
std::vector<WORLDITEM> pWorldItems;//dnl ch75 271013
UINT32 cnt;
UINT32 uiLoop1=0;
@@ -834,18 +826,12 @@ BOOLEAN AddItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT32 sG
}
//Allocate memeory for the item
pWorldItems = new WORLDITEM[uiNumberOfItems];
if( pWorldItems == NULL )
{
//Error Allocating memory for the temp item array
return( FALSE );
}
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
delete[] pWorldItems;
return( FALSE );
}
@@ -876,6 +862,7 @@ BOOLEAN AddItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT32 sG
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 )
@@ -894,6 +881,9 @@ BOOLEAN AddItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT32 sG
//set the spot were the item is to be added
cnt = uiNumberOfItems - 1;
#else
pWorldItems.resize(++uiNumberOfItems);
#endif
}
pWorldItems[ cnt ].fExists = TRUE;
@@ -931,10 +921,6 @@ BOOLEAN AddItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT32 sG
//Save the Items to the the file
SaveWorldItemsToTempItemFile( sMapX, sMapY, bMapZ, uiNumberOfItems, pWorldItems );
//Free the memory used to load in the item array
delete[]( pWorldItems );
return( TRUE );
}
@@ -1497,9 +1483,9 @@ UINT32 GetLastTimePlayerWasInSector(INT16 sMapX, INT16 sMapY, INT8 sMapZ)
BOOLEAN LoadAndAddWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
{
UINT32 uiNumberOfItems=0;
WORLDITEM *pWorldItems = NULL;
std::vector<WORLDITEM> pWorldItems;//dnl ch75 271013
UINT32 cnt;
INT32 sNewGridNo;
INT32 sNewGridNo;
//Get the number of items from the file
if( !GetNumberOfWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, &uiNumberOfItems, TRUE ) )
@@ -1510,12 +1496,7 @@ BOOLEAN LoadAndAddWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
if( uiNumberOfItems )
{
pWorldItems = new WORLDITEM[ uiNumberOfItems ];
if( pWorldItems == NULL )
{
//Error Allocating memory for the temp item array
return( FALSE );
}
pWorldItems.resize(uiNumberOfItems);//dnl ch75 271013
}
else
{
@@ -1540,7 +1521,6 @@ BOOLEAN LoadAndAddWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
//Load the World Items from the file
if( !LoadWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, pWorldItems ) )
{
delete[]( pWorldItems );
return( FALSE );
}
@@ -1593,8 +1573,6 @@ BOOLEAN LoadAndAddWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
}
}
delete[]( pWorldItems );
return( TRUE );
}
@@ -1925,12 +1903,12 @@ 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, WORLDITEM *pWorldItem, BOOLEAN fOverWrite )
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;
WORLDITEM *pWorldItems;
std::vector<WORLDITEM> pWorldItems;//dnl ch75 271013
if( !GetNumberOfWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, &uiNumberOfItems, TRUE ) )
{
@@ -1939,22 +1917,15 @@ BOOLEAN AddWorldItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT
}
//Allocate memory for the item
pWorldItems = new WORLDITEM[ uiNumberOfItems ];
if( pWorldItems == NULL )
{
//Error Allocating memory for the temp item array
return( FALSE );
}
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
delete[] pWorldItems;
return( FALSE );
}
//if we are to replace the entire file
if( fOverWrite )
{
@@ -1983,6 +1954,7 @@ BOOLEAN AddWorldItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT
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];
@@ -1999,6 +1971,9 @@ BOOLEAN AddWorldItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT
//Increment the total number of item in the array
uiNumberOfItems++;
#else
pWorldItems.resize(++uiNumberOfItems);
#endif
}
pWorldItems[ uiLastItemPos ].fExists = TRUE;
@@ -2025,10 +2000,6 @@ BOOLEAN AddWorldItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT
//Save the Items to the the file
SaveWorldItemsToTempItemFile( sMapX, sMapY, bMapZ, uiNumberOfItems, pWorldItems );
//Free the memory used to load in the item array
delete[]( pWorldItems );
#if 0
// The old excruciatingly inefficient code
for( uiLoop=0; uiLoop<uiNumberOfItems; uiLoop++)
@@ -2255,7 +2226,7 @@ void LoadNPCInformationFromProfileStruct()
BOOLEAN GetNumberOfActiveWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, UINT32 *pNumberOfData )
{
UINT32 uiNumberOfItems=0;
WORLDITEM *pWorldItems;
std::vector<WORLDITEM> pWorldItems;//dnl ch75 271013
UINT32 cnt;
UINT32 uiNumberOfActive=0;
BOOLEAN fFileLoaded = FALSE;
@@ -2300,12 +2271,7 @@ BOOLEAN GetNumberOfActiveWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8
//If there items in the data file
if( uiNumberOfItems != 0 )
{
pWorldItems = new WORLDITEM[ uiNumberOfItems ];
if( pWorldItems == NULL )
{
//Error Allocating memory for the temp item array
return( FALSE );
}
pWorldItems.resize(uiNumberOfItems);//dnl ch75 271013
//Load the World Items from the file
if( !LoadWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, pWorldItems ) )
@@ -2317,7 +2283,6 @@ BOOLEAN GetNumberOfActiveWorldItemsFromTempFile( INT16 sMapX, INT16 sMapY, INT8
if( pWorldItems[cnt].fExists )
uiNumberOfActive++;
}
delete[]( pWorldItems );
}
*pNumberOfData = uiNumberOfActive;
}
@@ -2834,7 +2799,7 @@ BOOLEAN GetSectorFlagStatus( INT16 sMapX, INT16 sMapY, UINT8 bMapZ, UINT32 uiFla
BOOLEAN AddDeadSoldierToUnLoadedSector( INT16 sMapX, INT16 sMapY, UINT8 bMapZ, SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT32 uiFlags )
{
UINT32 uiNumberOfItems;
WORLDITEM *pWorldItems=NULL;
std::vector<WORLDITEM> pWorldItems;//dnl ch75 271013
UINT i;
UINT8 bCount=0;
UINT16 uiFlagsForWorldItems=0;
@@ -2903,12 +2868,7 @@ BOOLEAN AddDeadSoldierToUnLoadedSector( INT16 sMapX, INT16 sMapY, UINT8 bMapZ, S
if( uiNumberOfItems )
{
//allocate memory for the world item array
pWorldItems = new WORLDITEM[ uiNumberOfItems ];
if( pWorldItems == NULL )
{
//Error Allocating memory for the temp item array
return( FALSE );
}
pWorldItems.resize(uiNumberOfItems);//dnl ch75 271013
//loop through all the soldiers items and add them to the world item array
bCount = 0;
@@ -2999,10 +2959,6 @@ BOOLEAN AddDeadSoldierToUnLoadedSector( INT16 sMapX, INT16 sMapY, UINT8 bMapZ, S
//Add the rotting corpse info to the sectors unloaded rotting corpse file
AddRottingCorpseToUnloadedSectorsRottingCorpseFile( sMapX, sMapY, bMapZ, &Corpse);
//FRee the memory used for the pWorldItem array
delete[]( pWorldItems );
pWorldItems = NULL;
return( TRUE );
}
@@ -3375,7 +3331,7 @@ void SetNumberOfVisibleWorldItemsInSectorStructureForSector( INT16 sMapX, INT16
void SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems( INT16 sMapX, INT16 sMapY, INT8 bMapZ, BOOLEAN fLoadingGame )
{
UINT32 uiTotalNumberOfItems = 0;//, uiTotalNumberOfRealItems = 0;
WORLDITEM * pTotalSectorList = NULL;
std::vector<WORLDITEM> pTotalSectorList;//dnl ch75 271013
UINT32 uiItemCount = 0;
UINT32 iCounter = 0;
BOOLEAN fReturn;
@@ -3399,7 +3355,7 @@ void SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems( INT16 sMapX, INT
if( uiTotalNumberOfItems > 0 )
{
// allocate space for the list
pTotalSectorList = new WORLDITEM[ uiTotalNumberOfItems ];
pTotalSectorList.resize(uiTotalNumberOfItems);//dnl ch75 271013
// now load into mem
LoadWorldItemsFromTempItemFile( sMapX, sMapY, bMapZ, pTotalSectorList );
@@ -3416,13 +3372,6 @@ void SynchronizeItemTempFileVisbleItemsToSectorInfoVisbleItems( INT16 sMapX, INT
}
}
// if anything was alloced, then get rid of it
if( pTotalSectorList != NULL )
{
delete[]( pTotalSectorList );
pTotalSectorList = NULL;
}
#ifdef JA2BETAVERSION
if( fLoadingGame && guiCurrentSaveGameVersion >= 86 )
{
+3 -3
View File
@@ -47,9 +47,9 @@ BOOLEAN SaveCurrentSectorsInformationToTempItemFile( );
BOOLEAN LoadCurrentSectorsInformationFromTempItemsFile();
// Loads a World Item array from that sectors temp item file
BOOLEAN LoadWorldItemsFromTempItemFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ, WORLDITEM *pData );
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, WORLDITEM *pData );
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 );
@@ -59,7 +59,7 @@ BOOLEAN UpdateWorldItemsTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ );
BOOLEAN AddItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT32 sGridNo, UINT32 uiNumberOfItems, OBJECTTYPE *pObject, UINT8 ubLevel, UINT16 usFlags, INT8 bRenderZHeightAboveLevel, INT8 bVisible, BOOLEAN fReplaceEntireFile );
BOOLEAN AddWorldItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT32 sGridNo, UINT32 uiNumberOfItems, WORLDITEM *pWorldItem, BOOLEAN fOverWrite );
BOOLEAN AddWorldItemsToUnLoadedSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ, INT32 sGridNo, UINT32 uiNumberOfItems, std::vector<WORLDITEM>& pWorldItem, BOOLEAN fOverWrite );//dnl ch75 271013
//Deletes all the Temp files in the Maps\Temp directory
BOOLEAN InitTacticalSave( BOOLEAN fCreateTempDir );
+19 -11
View File
@@ -113,9 +113,9 @@
#include "connect.h"
#include "fresh_header.h"
#include "IMP Skill Trait.h" // added by Flugente
#include "SkillMenu.h" // added by Flugente
#include "Map Screen Interface Map Inventory.h"//dnl ch75 021113
//forward declarations of common classes to eliminate includes
class OBJECTTYPE;
@@ -2368,7 +2368,14 @@ void GetKeyboardInput( UINT32 *puiNewEvent )
ClearDisplayedListOfTacticalStrings( );
}
break;
#if 0//dnl ch75 021113
case '\"':
Testing(1);
break;
case '\'':
Testing(2);
break;
#endif
case '1':
if( fAlt )
@@ -2496,6 +2503,9 @@ void GetKeyboardInput( UINT32 *puiNewEvent )
break;
case '$':
if(fCtrl && gGameExternalOptions.fEnableInventoryPoolQ)//dnl ch75 021113
DisplaySectorItemsInfo();
else
{
// Flugente: trait skill selection menu. Yes, screw squad 13
INT32 usMapPos;
@@ -3416,23 +3426,21 @@ void GetKeyboardInput( UINT32 *puiNewEvent )
}
break;
case 'I':
//CHRISL: This will create a large number of objects for checking overloading
if( fAlt && fCtrl )
//CHRISL: This will create a large number of objects for checking overloading //dnl ch75 251013
if(fAlt && fCtrl)
{
INT32 tempMapPos = usMapPos;
if( CHEATER_CHEAT_LEVEL( ) )
if(CHEATER_CHEAT_LEVEL())
{
for(UINT16 i = 1; i < 1300; i++)
for(UINT16 i=FIRST_WEAPON; i<MAXITEMS; i++)
{
if(i == OWNERSHIP || i == CHALICE)
if(i == 1580 || Item[i].ubWeight == 0 && !(i == 257 || i == 1006 || i == 1026 || i == 1183))//dnl!!! items 257, 1006, 1026, 1183 had weight 0 which need to be changed in xml
continue;
//tempMapPos = sMapPos + (i / 200);
CreateItem(i, 100, &gTempObject);
AddItemToPool( tempMapPos, &gTempObject, VISIBLE , 0, WORLD_ITEM_REACHABLE, 0 );
AddItemToPool(usMapPos, &gTempObject, VISIBLE , 0, WORLD_ITEM_REACHABLE, 0);
}
}
}
break;
case 'i':
if( fAlt )
+28 -40
View File
@@ -30,7 +30,7 @@
#endif
//Global dynamic array of all of the items in a loaded map.
WORLDITEM * gWorldItems = NULL;
std::vector<WORLDITEM> gWorldItems;//dnl ch75 261013
UINT32 guiNumWorldItems = 0;
WORLDBOMB * gWorldBombs = NULL;
@@ -393,43 +393,16 @@ void FindPanicBombsAndTriggers( void )
}
}
INT32 GetFreeWorldItemIndex( void )
UINT32 GetFreeWorldItemIndex(void)//dnl ch75 271013
{
UINT32 uiCount;
WORLDITEM *newWorldItems;
UINT32 uiOldNumWorldItems;
for(uiCount=0; uiCount < guiNumWorldItems; uiCount++)
{
if ( gWorldItems[ uiCount ].fExists == FALSE )
return( (INT32)uiCount );
}
uiOldNumWorldItems = guiNumWorldItems;
// grow by 3/2 as a better strategy, minimum 10
guiNumWorldItems = max(10, guiNumWorldItems * 3 / 2);
//Allocate new table with max+10 items.
newWorldItems = new WORLDITEM [ guiNumWorldItems ];
if (newWorldItems == NULL)
{
return( -1 );
}
if (gWorldItems)
{
for (unsigned int x = 0; x < uiOldNumWorldItems; ++x)
{
newWorldItems[x] = gWorldItems[x];
}
delete[] gWorldItems;
}
gWorldItems = newWorldItems;
// Return uiCount.....
return( uiCount );
for(uiCount=0; uiCount<gWorldItems.size(); uiCount++)
if(gWorldItems[uiCount].fExists == FALSE)
return(uiCount);
ResizeWorldItems();
return(uiCount);
}
UINT32 GetNumUsedWorldItems( void )
{
UINT32 uiCount, uiNumItems;
@@ -446,7 +419,22 @@ UINT32 GetNumUsedWorldItems( void )
return( uiNumItems );
}
void ResizeWorldItems(void)//dnl ch75 271013
{
#ifdef INVFIX_Moa
// grow by 3/2 as a better strategy, minimum 10
guiNumWorldItems = max(10, guiNumWorldItems * 3 / 2);
//Allocate new table with max+10 items.
gWorldItems.resize(guiNumWorldItems);
#else
guiNumWorldItems = gWorldItems.size();
if(guiNumWorldItems - GetNumUsedWorldItems() < 100)
{
gWorldItems.resize(guiNumWorldItems + 100);
guiNumWorldItems = gWorldItems.size();
}
#endif
}
INT32 AddItemToWorld( INT32 sGridNo, OBJECTTYPE *pObject, UINT8 ubLevel, UINT16 usFlags, INT8 bRenderZHeightAboveLevel, INT8 bVisible, INT8 soldierID )
{
@@ -538,7 +526,7 @@ void RemoveItemFromWorld( INT32 iItemIndex )
void TrashWorldItems()
{
UINT32 i;
if( gWorldItems )
if( !gWorldItems.empty() )//dnl ch75 271013
{
for( i = 0; i < guiNumWorldItems; i++ )
{
@@ -547,9 +535,9 @@ void TrashWorldItems()
RemoveItemFromPool( gWorldItems[ i ].sGridNo, i, gWorldItems[ i ].ubLevel );
}
}
delete[] gWorldItems;
gWorldItems = NULL;
guiNumWorldItems = 0;
#ifdef INVFIX_Moa//dnl ch75 311013
gWorldItems.clear();
#endif
}
if ( gWorldBombs )
{
@@ -847,7 +835,7 @@ void DeleteWorldItemsBelongingToQueenIfThere( void )
// Refresh item pools
void RefreshWorldItemsIntoItemPools( WORLDITEM * pItemList, INT32 iNumberOfItems )
void RefreshWorldItemsIntoItemPools( std::vector<WORLDITEM>& pItemList, INT32 iNumberOfItems )//dnl ch75 271013
{
INT32 i;
+4 -3
View File
@@ -102,7 +102,7 @@ public:
#define SIZEOF_WORLDITEM_POD (offsetof(WORLDITEM, endOfPod))
#define _OLD_SIZEOF_WORLDITEM_POD (offsetof(_OLD_WORLDITEM, endOfPod))
extern WORLDITEM *gWorldItems;
extern std::vector<WORLDITEM> gWorldItems;//dnl ch75 261013
extern UINT32 guiNumWorldItems;
INT32 AddItemToWorld( INT32 sGridNo, OBJECTTYPE *pObject, UINT8 ubLevel, UINT16 usFlags, INT8 bRenderZHeightAboveLevel, INT8 bVisible, INT8 soldierID );
@@ -133,7 +133,8 @@ extern INT32 FindWorldItemForBombInGridNo( INT32 sGridNo, INT8 bLevel);
// Flugente: is there a planted tripwire at this gridno? fKnown = TRUE: only return true if we know of that one already
extern INT32 FindWorldItemForTripwireInGridNo( INT32 sGridNo, INT8 bLevel, BOOLEAN fKnown = TRUE );
void RefreshWorldItemsIntoItemPools( WORLDITEM * pItemList, INT32 iNumberOfItems );
void ResizeWorldItems(void);//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
#endif
#endif
+1 -1
View File
@@ -3893,7 +3893,7 @@ void HandleExplosionQueue( void )
uiCurrentTime = GetJA2Clock();
// WDS 07/25/2008 - Avoid error where gWorldItems and/or gWorldBombs is nil
if (gWorldBombs && gWorldItems) {
if (gWorldBombs && !gWorldItems.empty()) {//dnl ch75 271013
for ( uiIndex = 0; uiIndex < gubElementsOnExplosionQueue; uiIndex++ )
{
if ( gExplosionQueue[ uiIndex ].fExists && uiCurrentTime >= gExplosionQueue[ uiIndex ].uiTimeStamp )