diff --git a/gameSource/objectMetadata.cpp b/gameSource/objectMetadata.cpp index 506dbdab5..1dd24d87b 100644 --- a/gameSource/objectMetadata.cpp +++ b/gameSource/objectMetadata.cpp @@ -2,6 +2,8 @@ #include "objectBank.h" #include "categoryBank.h" +#include "minorGems/util/SettingsManager.h" + // bottom 17 bits of map database item are object ID // enought for 131071 object static int objectIDMask = 0x0001FFFF; @@ -46,14 +48,17 @@ void setLastMetadataID( int inMetadataID ) { int getNewMetadataID() { - int val = nextMetadataID; + nextMetadataID = SettingsManager::getIntSetting( "nextMetadataID", 0 ); nextMetadataID++; if( nextMetadataID > maxMetadataID ) { // wrap around, reuse old IDs nextMetadataID = 1; } - return val; + + SettingsManager::setSetting( "nextMetadataID", nextMetadataID ); + + return nextMetadataID; } diff --git a/server/map.cpp b/server/map.cpp index 2d8c0c168..f86e33fa8 100644 --- a/server/map.cpp +++ b/server/map.cpp @@ -3833,32 +3833,34 @@ char initMap() { metaDBOpen = true; - DB_Iterator metaIterator; - - DB_Iterator_init( &metaDB, &metaIterator ); - - unsigned char metaKey[4]; - - unsigned char metaValue[MAP_METADATA_LENGTH]; - - int maxMetaID = 0; - int numMetaRecords = 0; - - while( DB_Iterator_next( &metaIterator, metaKey, metaValue ) > 0 ) { - numMetaRecords++; - - int metaID = valueToInt( metaKey ); - - if( metaID > maxMetaID ) { - maxMetaID = metaID; + if( false ) { // old way to determine nextMetadataID + DB_Iterator metaIterator; + + DB_Iterator_init( &metaDB, &metaIterator ); + + unsigned char metaKey[4]; + + unsigned char metaValue[MAP_METADATA_LENGTH]; + + int maxMetaID = 0; + int numMetaRecords = 0; + + while( DB_Iterator_next( &metaIterator, metaKey, metaValue ) > 0 ) { + numMetaRecords++; + + int metaID = valueToInt( metaKey ); + + if( metaID > maxMetaID ) { + maxMetaID = metaID; + } } + + AppLog::infoF( + "MetadataDB: Found %d records with max MetadataID of %d", + numMetaRecords, maxMetaID ); + + setLastMetadataID( maxMetaID ); } - - AppLog::infoF( - "MetadataDB: Found %d records with max MetadataID of %d", - numMetaRecords, maxMetaID ); - - setLastMetadataID( maxMetaID ); @@ -6192,29 +6194,35 @@ void checkDecayContained( int inX, int inY, int inSubCont ) { // Check for containment transitions - checkDecayContained - int inOrout = -1; - TransRecord *contTrans = NULL; - - // in-transitions + + int newContainer = containerID; + + // Check for out-transitions first, then in-transitions + // Think of the decay transition of the contained object as + // taking out the old object (which may change the container) + // and then putting the new object in the potentially new container + + // Check for containment transitions - checkDecayContained - out-transitions if( i == 0 ) { - contTrans = getPTrans( newID, containerID, false, false, 1 ); - if( contTrans == NULL ) contTrans = getPTrans( 0, containerID, false, false, 1 ); + contTrans = getPTrans( newContainer, oldID, false, false, 2 ); + if( contTrans == NULL ) contTrans = getPTrans( newContainer, -1, false, false, 2 ); } else if( i == numSlots - 1 ) { - contTrans = getPTrans( newID, containerID, false, false, 2 ); - if( contTrans == NULL ) contTrans = getPTrans( 0, containerID, false, false, 2 ); + contTrans = getPTrans( newContainer, oldID, false, false, 1 ); + if( contTrans == NULL ) contTrans = getPTrans( newContainer, -1, false, false, 1 ); } if( contTrans == NULL ) { - contTrans = getPTrans( newID, containerID, false, false, 3 ); - if( contTrans == NULL ) contTrans = getPTrans( 0, containerID, false, false, 3 ); + contTrans = getPTrans( newContainer, oldID, false, false, 3 ); + if( contTrans == NULL ) contTrans = getPTrans( newContainer, -1, false, false, 3 ); } if( contTrans == NULL ) { - contTrans = getPTrans( newID, containerID, false, false, 4 ); - if( contTrans == NULL ) contTrans = getPTrans( 0, containerID, false, false, 4 ); + contTrans = getPTrans( newContainer, oldID, false, false, 4 ); + if( contTrans == NULL ) contTrans = getPTrans( newContainer, -1, false, false, 4 ); } + if( contTrans != NULL ) { // Check that the new container can contain all the objects @@ -6231,7 +6239,7 @@ void checkDecayContained( int inX, int inY, int inSubCont ) { while( slotNumber >= 0 && - containmentPermitted( contTrans->newTarget, contID ) ) { + containmentPermitted( contTrans->newActor, contID ) ) { slotNumber--; @@ -6253,30 +6261,50 @@ void checkDecayContained( int inX, int inY, int inSubCont ) { } } - - if( contTrans != NULL ) inOrout = 0; - - // out-transitions - if( contTrans == NULL ) { - if( i == 0 ) { - contTrans = getPTrans( containerID, oldID, false, false, 2 ); - if( contTrans == NULL ) contTrans = getPTrans( containerID, -1, false, false, 2 ); - } else if( i == numSlots - 1 ) { - contTrans = getPTrans( containerID, oldID, false, false, 1 ); - if( contTrans == NULL ) contTrans = getPTrans( containerID, -1, false, false, 1 ); + + if( contTrans != NULL ) { + + // Execute containment transitions - checkDecayContained - out-transitions + + // Don't change the newID here to simplify things... + // So the containment transition only applies to the container + // Otherwise what about the next step + // to check for transition between newID and the container? + + newContainer = contTrans->newActor; + // newID = contTrans->newTarget; + + // Check for 1-second decay of the newContainer + TransRecord *instantDecay = getPTrans( -1, newContainer ); + if( instantDecay != NULL ) newContainer = instantDecay->newTarget; + + if( newContainer != containerID ) { + ObjectRecord *newC = getObject( newContainer ); + if( newC != NULL ) numSlots = newC->numSlots; } + } + + contTrans = NULL; - if( contTrans == NULL ) { - contTrans = getPTrans( containerID, oldID, false, false, 3 ); - if( contTrans == NULL ) contTrans = getPTrans( containerID, -1, false, false, 3 ); + // Check for containment transitions - checkDecayContained - in-transitions + if( i == 0 ) { + contTrans = getPTrans( newID, newContainer, false, false, 1 ); + if( contTrans == NULL ) contTrans = getPTrans( 0, newContainer, false, false, 1 ); + } else if( i == numSlots - 1 ) { + contTrans = getPTrans( newID, newContainer, false, false, 2 ); + if( contTrans == NULL ) contTrans = getPTrans( 0, newContainer, false, false, 2 ); } if( contTrans == NULL ) { - contTrans = getPTrans( containerID, oldID, false, false, 4 ); - if( contTrans == NULL ) contTrans = getPTrans( containerID, -1, false, false, 4 ); + contTrans = getPTrans( newID, newContainer, false, false, 3 ); + if( contTrans == NULL ) contTrans = getPTrans( 0, newContainer, false, false, 3 ); } + if( contTrans == NULL ) { + contTrans = getPTrans( newID, newContainer, false, false, 4 ); + if( contTrans == NULL ) contTrans = getPTrans( 0, newContainer, false, false, 4 ); + } if( contTrans != NULL ) { @@ -6294,7 +6322,7 @@ void checkDecayContained( int inX, int inY, int inSubCont ) { while( slotNumber >= 0 && - containmentPermitted( contTrans->newActor, contID ) ) { + containmentPermitted( contTrans->newTarget, contID ) ) { slotNumber--; @@ -6317,29 +6345,22 @@ void checkDecayContained( int inX, int inY, int inSubCont ) { } - - if( contTrans != NULL && inOrout == -1 ) inOrout = 1; - if( contTrans != NULL ) { - // Execute containment transitions - checkDecayContained + // Execute containment transitions - checkDecayContained - in-transitions - int newContainer = 0; // Don't change the newID here to simplify things... // So the containment transition only applies to the container // Otherwise what about the next step // to check for transition between newID and the container? - if( inOrout == 0 ) { - newContainer = contTrans->newTarget; - // newID = contTrans->newActor; - } else if( inOrout == 1 ) { - newContainer = contTrans->newActor; - // newID = contTrans->newTarget; - } - - if( newContainer != containerID ) setMapObject( inX, inY, newContainer ); + + newContainer = contTrans->newTarget; + // newID = contTrans->newActor; } + + if( newContainer != containerID ) setMapObject( inX, inY, newContainer ); + } diff --git a/server/server.cpp b/server/server.cpp index c23c27936..e4a987640 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -17106,7 +17106,8 @@ int main() { containmentPermitted( targetObj->id, newTarget->id )) || - contTrans->newTarget == 0 ) { + (contTrans != NULL && + contTrans->newTarget == 0) ) { int oldHeld = nextPlayer->holdingID; diff --git a/server/settings/nextMetaID.ini b/server/settings/nextMetaID.ini new file mode 100644 index 000000000..c22708346 --- /dev/null +++ b/server/settings/nextMetaID.ini @@ -0,0 +1 @@ +0 \ No newline at end of file