A better fix to bug #11084, last one was buggy.

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3909 4a71c877-e1ca-e34f-864e-861f7616d084
master
Roman C 2008-03-03 22:02:24 +00:00
parent c796c09971
commit c747bbe231
2 changed files with 54 additions and 41 deletions

View File

@ -1056,60 +1056,58 @@ BOOL scrValDefSave(INTERP_VAL *psVal, char *pBuffer, UDWORD *pSize)
}
else
{
members = 0;
members = UNALLOCATED_OBJECT;
}
if (pBuffer != NULL && bObjectDefined)
if (pBuffer)
{
pPos = pBuffer;
psGroup = (DROID_GROUP *)psVal->v.oval;
// store the run data
*((SDWORD *)pPos) = psGroup->sRunData.sPos.x;
endian_sdword((SDWORD*)pPos);
pPos += sizeof(SDWORD);
*((SDWORD *)pPos) = psGroup->sRunData.sPos.y;
endian_sdword((SDWORD*)pPos);
pPos += sizeof(SDWORD);
*((SDWORD *)pPos) = psGroup->sRunData.forceLevel;
endian_sdword((SDWORD*)pPos);
pPos += sizeof(SDWORD);
*((SDWORD *)pPos) = psGroup->sRunData.leadership;
endian_sdword((SDWORD*)pPos);
pPos += sizeof(SDWORD);
*((SDWORD *)pPos) = psGroup->sRunData.healthLevel;
*((SDWORD *)pPos) = members;
endian_sdword((SDWORD*)pPos);
pPos += sizeof(SDWORD);
// now store the droids
for(psCDroid=((DROID_GROUP *)psVal->v.oval)->psList; psCDroid; psCDroid=psCDroid->psGrpNext)
if(bObjectDefined)
{
checkValidId(psCDroid->id);
psGroup = (DROID_GROUP *)psVal->v.oval;
*((UDWORD *)pPos) = psCDroid->id;
endian_udword((UDWORD*)pPos);
// store the run data
*((SDWORD *)pPos) = psGroup->sRunData.sPos.x;
endian_sdword((SDWORD*)pPos);
pPos += sizeof(SDWORD);
*((SDWORD *)pPos) = psGroup->sRunData.sPos.y;
endian_sdword((SDWORD*)pPos);
pPos += sizeof(SDWORD);
*((SDWORD *)pPos) = psGroup->sRunData.forceLevel;
endian_sdword((SDWORD*)pPos);
pPos += sizeof(SDWORD);
*((SDWORD *)pPos) = psGroup->sRunData.leadership;
endian_sdword((SDWORD*)pPos);
pPos += sizeof(SDWORD);
*((SDWORD *)pPos) = psGroup->sRunData.healthLevel;
endian_sdword((SDWORD*)pPos);
pPos += sizeof(SDWORD);
pPos += sizeof(UDWORD);
// now store the droids
for(psCDroid=((DROID_GROUP *)psVal->v.oval)->psList; psCDroid; psCDroid=psCDroid->psGrpNext)
{
checkValidId(psCDroid->id);
*((UDWORD *)pPos) = psCDroid->id;
endian_udword((UDWORD*)pPos);
pPos += sizeof(UDWORD);
}
}
}
if(!bObjectDefined)
{
if(pBuffer) // make sure we are saving
{
pPos = pBuffer;
// Make sure loading routine can handle nullpointers
*((UWORD *)pPos) = UNALLOCATED_OBJECT;
endian_udword((UWORD*)pPos);
pPos += sizeof(UWORD);
}
*pSize = sizeof(UWORD);
*pSize = sizeof(SDWORD);
}
else
{
*pSize = sizeof(UDWORD) * members + sizeof(SDWORD) * 5; // members + runData
*pSize = sizeof(SDWORD) + sizeof(UDWORD) * members + sizeof(SDWORD) * 5; // members + runData
}
break;
case ST_SOUND:
@ -1156,11 +1154,12 @@ BOOL scrValDefLoad(SDWORD version, INTERP_VAL *psVal, char *pBuffer, UDWORD size
{
char *pPos;
DROID *psCDroid;
SDWORD index, members;
SDWORD index, members, savedMembers;
UDWORD id;
LEVEL_DATASET *psLevel;
DROID_GROUP *psGroup = NULL;
const char *pName;
BOOL bObjectDefined;
switch (psVal->type)
{
@ -1366,6 +1365,8 @@ BOOL scrValDefLoad(SDWORD version, INTERP_VAL *psVal, char *pBuffer, UDWORD size
}
break;
case ST_GROUP:
bObjectDefined = TRUE;
if (psVal->v.oval == NULL)
{
if (!grpCreate((DROID_GROUP**)&(psVal->v.oval)))
@ -1377,6 +1378,8 @@ BOOL scrValDefLoad(SDWORD version, INTERP_VAL *psVal, char *pBuffer, UDWORD size
grpJoin((DROID_GROUP*)(psVal->v.oval), NULL);
}
pPos = pBuffer;
switch (version)
{
case 1:
@ -1386,17 +1389,27 @@ BOOL scrValDefLoad(SDWORD version, INTERP_VAL *psVal, char *pBuffer, UDWORD size
members = (size - sizeof(SDWORD)*4) / sizeof(UDWORD);
break;
case 3:
members = (size - sizeof(SDWORD)*5) / sizeof(UDWORD);
members = (size - sizeof(SDWORD)*6) / sizeof(UDWORD);
// get saved group member count/nullpointer flag
endian_sdword((SDWORD*)pPos);
bObjectDefined = ( *((SDWORD *)pPos) != UNALLOCATED_OBJECT );
if(bObjectDefined)
{
savedMembers = *((SDWORD *)pPos); // get number of saved group members
ASSERT(savedMembers == members, "scrValDefLoad: calculated and saved group member count did not match." );
}
pPos += sizeof(SDWORD);
break;
default:
members = 0;
debug( LOG_ERROR, "scrValDefLoad: unsupported version %i", version);
}
pPos = pBuffer;
// make sure group was allocated when it was saved (relevant starting from version 3)
if( (version < 3) || ( *((UWORD*)pPos) != UNALLOCATED_OBJECT ) )
if( version < 3 || bObjectDefined )
{
if (version >= 2)
{

View File

@ -64,7 +64,7 @@ enum _objids
};
// marks a nullpointer for the save-game loading routine
#define UNALLOCATED_OBJECT 0
#define UNALLOCATED_OBJECT (-1)
// id's for group variables
enum _groupids