As a first step toward debugging bugs in message saving, clean up the message saving code. Apart
from dropping support for versions < 36 (unchanged since release 2.1), this change is cosmetic only. git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@10385 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
2b84b0317c
commit
acb1328e56
146
src/game.c
146
src/game.c
|
@ -2208,7 +2208,6 @@ static BOOL loadSaveResearchV(char *pFileData, UDWORD filesize, UDWORD numRecord
|
|||
static BOOL writeResearchFile(char *pFileName);
|
||||
|
||||
static BOOL loadSaveMessage(char *pFileData, UDWORD filesize, SWORD levelType);
|
||||
static BOOL loadSaveMessageV(char *pFileData, UDWORD filesize, UDWORD numMessages, UDWORD version, SWORD levelType);
|
||||
static BOOL loadSaveMessage36(char *pFileData, UDWORD filesize, UDWORD numMessages, UDWORD version, SWORD levelType);
|
||||
static BOOL writeMessageFile(char *pFileName);
|
||||
|
||||
|
@ -10186,11 +10185,9 @@ BOOL loadSaveMessage(char *pFileData, UDWORD filesize, SWORD levelType)
|
|||
/* Check the file version */
|
||||
if(psHeader->version <= VERSION_35)
|
||||
{
|
||||
if (!loadSaveMessageV(pFileData, filesize, psHeader->quantity, psHeader->version, levelType))
|
||||
{
|
||||
debug(LOG_ERROR, "Unsupported message save format %d", (int)psHeader->version);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!loadSaveMessage36(pFileData, filesize, psHeader->quantity, psHeader->version, levelType))
|
||||
|
@ -10201,119 +10198,6 @@ BOOL loadSaveMessage(char *pFileData, UDWORD filesize, SWORD levelType)
|
|||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
BOOL loadSaveMessageV(char *pFileData, UDWORD filesize, UDWORD numMessages, UDWORD version, SWORD levelType)
|
||||
{
|
||||
SAVE_MESSAGE *psSaveMessage;
|
||||
MESSAGE *psMessage;
|
||||
VIEWDATA *psViewData = NULL;
|
||||
UDWORD i, height;
|
||||
|
||||
//clear any messages put in during level loads
|
||||
//freeMessages();
|
||||
|
||||
//only clear the messages if its a mid save game
|
||||
if (gameType == GTYPE_SAVE_MIDMISSION)
|
||||
{
|
||||
freeMessages();
|
||||
}
|
||||
else if (gameType == GTYPE_SAVE_START)
|
||||
{
|
||||
//if we're loading in a CamStart or a CamChange then we're not interested in any saved messages
|
||||
if (levelType == LDS_CAMSTART || levelType == LDS_CAMCHANGE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//check file
|
||||
if ((sizeof(SAVE_MESSAGE) * numMessages + MESSAGE_HEADER_SIZE) >
|
||||
filesize)
|
||||
{
|
||||
debug( LOG_ERROR, "loadSaveMessage: unexpected end of file" );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load the data
|
||||
for (i = 0; i < numMessages; i++, pFileData += sizeof(SAVE_MESSAGE))
|
||||
{
|
||||
psSaveMessage = (SAVE_MESSAGE *) pFileData;
|
||||
|
||||
/* SAVE_MESSAGE */
|
||||
endian_sdword((SDWORD*)&psSaveMessage->type); /* FIXME: enum may not be this type! */
|
||||
endian_udword(&psSaveMessage->objId);
|
||||
endian_udword(&psSaveMessage->player);
|
||||
|
||||
if (psSaveMessage->type == MSG_PROXIMITY)
|
||||
{
|
||||
//only load proximity if a mid-mission save game
|
||||
if (gameType == GTYPE_SAVE_MIDMISSION)
|
||||
{
|
||||
if (psSaveMessage->bObj)
|
||||
{
|
||||
//proximity object so create get the obj from saved idy
|
||||
psMessage = addMessage(psSaveMessage->type, true, psSaveMessage->player);
|
||||
if (psMessage)
|
||||
{
|
||||
psMessage->pViewData = (MSG_VIEWDATA *)getBaseObjFromId(psSaveMessage->objId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//proximity position so get viewdata pointer from the name
|
||||
psMessage = addMessage(psSaveMessage->type, false, psSaveMessage->player);
|
||||
if (psMessage)
|
||||
{
|
||||
psViewData = (VIEWDATA *)getViewData(psSaveMessage->name);
|
||||
if (psViewData == NULL)
|
||||
{
|
||||
//skip this message
|
||||
continue;
|
||||
}
|
||||
psMessage->pViewData = (MSG_VIEWDATA *)psViewData;
|
||||
}
|
||||
//check the z value is at least the height of the terrain
|
||||
height = map_Height(((VIEW_PROXIMITY *)psViewData->pData)->x,
|
||||
((VIEW_PROXIMITY *)psViewData->pData)->y);
|
||||
if (((VIEW_PROXIMITY *)psViewData->pData)->z < height)
|
||||
{
|
||||
((VIEW_PROXIMITY *)psViewData->pData)->z = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//only load Campaign/Mission if a mid-mission save game
|
||||
if (psSaveMessage->type == MSG_CAMPAIGN || psSaveMessage->type == MSG_MISSION)
|
||||
{
|
||||
if (gameType == GTYPE_SAVE_MIDMISSION)
|
||||
{
|
||||
// Research message // Campaign message // Mission Report messages
|
||||
psMessage = addMessage(psSaveMessage->type, false, psSaveMessage->player);
|
||||
if (psMessage)
|
||||
{
|
||||
psMessage->pViewData = (MSG_VIEWDATA *)getViewData(psSaveMessage->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Research message
|
||||
psMessage = addMessage(psSaveMessage->type, false, psSaveMessage->player);
|
||||
if (psMessage)
|
||||
{
|
||||
psMessage->pViewData = (MSG_VIEWDATA *)getViewData(psSaveMessage->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL loadSaveMessage36(char *pFileData, UDWORD filesize, UDWORD numMessages, UDWORD version, SWORD levelType)
|
||||
{
|
||||
SAVE_MESSAGE_36 *psSaveMessage;
|
||||
|
@ -10321,17 +10205,14 @@ BOOL loadSaveMessage36(char *pFileData, UDWORD filesize, UDWORD numMessages, UDW
|
|||
VIEWDATA *psViewData = NULL;
|
||||
UDWORD i, height;
|
||||
|
||||
//clear any messages put in during level loads
|
||||
//freeMessages();
|
||||
|
||||
//only clear the messages if its a mid save game
|
||||
// Only clear the messages if its a mid save game
|
||||
if (gameType == GTYPE_SAVE_MIDMISSION)
|
||||
{
|
||||
freeMessages();
|
||||
}
|
||||
else if (gameType == GTYPE_SAVE_START)
|
||||
{
|
||||
//if we're loading in a CamStart or a CamChange then we're not interested in any saved messages
|
||||
// If we are loading in a CamStart or a CamChange then we are not interested in any saved messages
|
||||
if (levelType == LDS_CAMSTART || levelType == LDS_CAMCHANGE)
|
||||
{
|
||||
return true;
|
||||
|
@ -10340,11 +10221,9 @@ BOOL loadSaveMessage36(char *pFileData, UDWORD filesize, UDWORD numMessages, UDW
|
|||
}
|
||||
|
||||
//check file
|
||||
if ((sizeof(SAVE_MESSAGE_36) * numMessages + MESSAGE_HEADER_SIZE) >
|
||||
filesize)
|
||||
if ((sizeof(SAVE_MESSAGE_36) * numMessages + MESSAGE_HEADER_SIZE) > filesize)
|
||||
{
|
||||
debug( LOG_ERROR, "loadSaveMessage: unexpected end of file" );
|
||||
|
||||
debug(LOG_ERROR, "loadSaveMessage: unexpected end of file");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -10366,7 +10245,7 @@ BOOL loadSaveMessage36(char *pFileData, UDWORD filesize, UDWORD numMessages, UDW
|
|||
{
|
||||
if (psSaveMessage->bObj)
|
||||
{
|
||||
//proximity object so create get the obj from saved idy
|
||||
// Proximity object so create get the obj from saved idy
|
||||
psMessage = addMessage(psSaveMessage->type, true, psSaveMessage->player);
|
||||
if (psMessage)
|
||||
{
|
||||
|
@ -10380,9 +10259,9 @@ BOOL loadSaveMessage36(char *pFileData, UDWORD filesize, UDWORD numMessages, UDW
|
|||
|
||||
if (psMessage)
|
||||
{
|
||||
if(psSaveMessage->dataType == MSG_DATA_BEACON)
|
||||
if (psSaveMessage->dataType == MSG_DATA_BEACON)
|
||||
{
|
||||
UDWORD locX,locY;
|
||||
UDWORD locX, locY;
|
||||
SDWORD sender;
|
||||
|
||||
endian_udword(&psSaveMessage->locX);
|
||||
|
@ -10401,14 +10280,13 @@ BOOL loadSaveMessage36(char *pFileData, UDWORD filesize, UDWORD numMessages, UDW
|
|||
|
||||
if (psViewData == NULL)
|
||||
{
|
||||
//skip this message
|
||||
// Skip this message
|
||||
continue;
|
||||
}
|
||||
psMessage->pViewData = (MSG_VIEWDATA *)psViewData;
|
||||
}
|
||||
//check the z value is at least the height of the terrain
|
||||
height = map_Height(((VIEW_PROXIMITY *)psViewData->pData)->x,
|
||||
((VIEW_PROXIMITY *)psViewData->pData)->y);
|
||||
// Check the z value is at least the height of the terrain
|
||||
height = map_Height(((VIEW_PROXIMITY *)psViewData->pData)->x, ((VIEW_PROXIMITY *)psViewData->pData)->y);
|
||||
if (((VIEW_PROXIMITY *)psViewData->pData)->z < height)
|
||||
{
|
||||
((VIEW_PROXIMITY *)psViewData->pData)->z = height;
|
||||
|
@ -10418,7 +10296,7 @@ BOOL loadSaveMessage36(char *pFileData, UDWORD filesize, UDWORD numMessages, UDW
|
|||
}
|
||||
else
|
||||
{
|
||||
//only load Campaign/Mission if a mid-mission save game
|
||||
// Only load Campaign/Mission if a mid-mission save game
|
||||
if (psSaveMessage->type == MSG_CAMPAIGN || psSaveMessage->type == MSG_MISSION)
|
||||
{
|
||||
if (gameType == GTYPE_SAVE_MIDMISSION)
|
||||
|
|
Loading…
Reference in New Issue