Skip to content

Commit

Permalink
Merge pull request #245 from risvh/20316
Browse files Browse the repository at this point in the history
20316
  • Loading branch information
risvh authored Aug 13, 2024
2 parents 2d0f3c3 + 648fa99 commit ae6bdb8
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 71 deletions.
9 changes: 7 additions & 2 deletions gameSource/objectMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}


Expand Down
157 changes: 89 additions & 68 deletions server/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );



Expand Down Expand Up @@ -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
Expand All @@ -6231,7 +6239,7 @@ void checkDecayContained( int inX, int inY, int inSubCont ) {


while( slotNumber >= 0 &&
containmentPermitted( contTrans->newTarget, contID ) ) {
containmentPermitted( contTrans->newActor, contID ) ) {

slotNumber--;

Expand All @@ -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 ) {

Expand All @@ -6294,7 +6322,7 @@ void checkDecayContained( int inX, int inY, int inSubCont ) {


while( slotNumber >= 0 &&
containmentPermitted( contTrans->newActor, contID ) ) {
containmentPermitted( contTrans->newTarget, contID ) ) {

slotNumber--;

Expand All @@ -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 );

}


Expand Down
3 changes: 2 additions & 1 deletion server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17106,7 +17106,8 @@ int main() {
containmentPermitted(
targetObj->id,
newTarget->id )) ||
contTrans->newTarget == 0 ) {
(contTrans != NULL &&
contTrans->newTarget == 0) ) {

int oldHeld =
nextPlayer->holdingID;
Expand Down
1 change: 1 addition & 0 deletions server/settings/nextMetaID.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0

0 comments on commit ae6bdb8

Please sign in to comment.