Change function levFindDataSet:
* Make it return it's result rather than write it in an output pointer (NULL will indicate failure instead of `false`) * Don't use two nested if-statements, use a single if-statement with double conditions using logical and (&&) git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4819 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
29e32010a1
commit
fecc2a50d1
|
@ -4295,7 +4295,8 @@ bool gameLoadV7(PHYSFS_file* fileHandle)
|
|||
return false;
|
||||
}
|
||||
// find the level dataset
|
||||
if (!levFindDataSet(aLevelName, &psNewLevel))
|
||||
psNewLevel = levFindDataSet(aLevelName);
|
||||
if (psNewLevel == NULL)
|
||||
{
|
||||
debug( LOG_ERROR, "gameLoadV7: couldn't find level data" );
|
||||
abort();
|
||||
|
@ -4771,7 +4772,8 @@ bool gameLoadV(PHYSFS_file* fileHandle, unsigned int version)
|
|||
return false;
|
||||
}
|
||||
// find the level dataset
|
||||
/* if (!levFindDataSet(aLevelName, &psNewLevel))
|
||||
/* psNewLevel = levFindDataSet(aLevelName);
|
||||
if (psNewLevel == NULL)
|
||||
{
|
||||
DBERROR(("gameLoadV6: couldn't find level data"));
|
||||
return false;
|
||||
|
@ -11855,7 +11857,7 @@ BOOL plotStructurePreview16(char *backDropSprite, UBYTE scale, UDWORD offX, UDWO
|
|||
LEVEL_DATASET *psLevel;
|
||||
PIELIGHT color = WZCOL_BLACK ;
|
||||
|
||||
levFindDataSet(game.map, &psLevel);
|
||||
psLevel = levFindDataSet(game.map);
|
||||
strcpy(aFileName,psLevel->apDataFiles[0]);
|
||||
aFileName[strlen(aFileName)-4] = '\0';
|
||||
strcat(aFileName, "/struct.bjo");
|
||||
|
|
39
src/levels.c
39
src/levels.c
|
@ -137,24 +137,25 @@ void levError(const char *pError)
|
|||
#endif
|
||||
}
|
||||
|
||||
// find the level dataset
|
||||
BOOL levFindDataSet(const char* name, LEVEL_DATASET **ppsDataSet)
|
||||
/** Find a level dataset with the given name.
|
||||
* @param name the name of the dataset to search for.
|
||||
* @return a dataset with associated with the given @c name, or NULL if none
|
||||
* could be found.
|
||||
*/
|
||||
LEVEL_DATASET* levFindDataSet(const char* name)
|
||||
{
|
||||
LEVEL_DATASET* psNewLevel;
|
||||
|
||||
for (psNewLevel = psLevels; psNewLevel; psNewLevel = psNewLevel->psNext)
|
||||
{
|
||||
if (psNewLevel->pName != NULL)
|
||||
if (psNewLevel->pName != NULL
|
||||
&& strcmp(psNewLevel->pName, name) == 0)
|
||||
{
|
||||
if (strcmp(psNewLevel->pName, name) == 0)
|
||||
{
|
||||
*ppsDataSet = psNewLevel;
|
||||
return true;
|
||||
}
|
||||
return psNewLevel;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// parse a level description data file
|
||||
|
@ -162,13 +163,11 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
|
|||
{
|
||||
SDWORD token, state, currData=0;
|
||||
LEVEL_DATASET *psDataSet = NULL;
|
||||
LEVEL_DATASET *psFoundData;
|
||||
|
||||
levSetInputBuffer(pBuffer, size);
|
||||
|
||||
state = LP_START;
|
||||
token = lev_lex();
|
||||
while (token != 0)
|
||||
for (token = lev_lex(); token != 0; token = lev_lex())
|
||||
{
|
||||
switch (token)
|
||||
{
|
||||
|
@ -343,8 +342,10 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
|
|||
{
|
||||
if (psDataSet->type == LDS_CAMCHANGE)
|
||||
{
|
||||
// campaign change dataset - need to find the full data set
|
||||
if (!levFindDataSet(pLevToken, &psFoundData))
|
||||
// This is a campaign change dataset, we need to find the full data set.
|
||||
LEVEL_DATASET * const psFoundData = levFindDataSet(pLevToken);
|
||||
|
||||
if (psFoundData == NULL)
|
||||
{
|
||||
levError("Cannot find full data set for camchange");
|
||||
return false;
|
||||
|
@ -372,7 +373,9 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
|
|||
else if (state == LP_DATASET)
|
||||
{
|
||||
// find the dataset
|
||||
if (!levFindDataSet(pLevToken, &psDataSet->psBaseData))
|
||||
psDataSet->psBaseData = levFindDataSet(pLevToken);
|
||||
|
||||
if (psDataSet->psBaseData == NULL)
|
||||
{
|
||||
levError("Unknown dataset");
|
||||
return false;
|
||||
|
@ -425,9 +428,6 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
|
|||
levError("Unexpected token");
|
||||
break;
|
||||
}
|
||||
|
||||
// get the next token
|
||||
token = lev_lex();
|
||||
}
|
||||
|
||||
lev_lex_destroy();
|
||||
|
@ -581,7 +581,8 @@ BOOL levLoadData(const char* name, char *pSaveName, SDWORD saveType)
|
|||
levelLoadType = saveType;
|
||||
|
||||
// find the level dataset
|
||||
if (!levFindDataSet(name, &psNewLevel))
|
||||
psNewLevel = levFindDataSet(name);
|
||||
if (psNewLevel == NULL)
|
||||
{
|
||||
debug(LOG_NEVER, "levLoadData: dataset %s not found - trying to load as WRF", name);
|
||||
return levLoadSingleWRF(name);
|
||||
|
|
|
@ -84,7 +84,7 @@ extern BOOL levInitialise(void);
|
|||
extern BOOL levLoadData(const char* name, char *pSaveName, SDWORD saveType);
|
||||
|
||||
// find the level dataset
|
||||
extern BOOL levFindDataSet(const char* name, LEVEL_DATASET **ppsDataSet);
|
||||
extern LEVEL_DATASET* levFindDataSet(const char* name);
|
||||
|
||||
// free the currently loaded dataset
|
||||
extern BOOL levReleaseAll(void);
|
||||
|
|
|
@ -195,7 +195,7 @@ void loadMapPreview(void)
|
|||
}
|
||||
|
||||
// load the terrain types
|
||||
levFindDataSet(game.map, &psLevel);
|
||||
psLevel = levFindDataSet(game.map);
|
||||
rebuildSearchPath(psLevel->dataDir, false);
|
||||
strcpy(aFileName,psLevel->apDataFiles[0]);
|
||||
aFileName[strlen(aFileName)-4] = '\0';
|
||||
|
|
|
@ -3687,7 +3687,8 @@ BOOL scrStartMission(void)
|
|||
strlcpy(aLevelName, pGame, sizeof(aLevelName));
|
||||
|
||||
// find the level dataset
|
||||
if (!levFindDataSet(pGame, &psNewLevel))
|
||||
psNewLevel = levFindDataSet(pGame);
|
||||
if (psNewLevel == NULL)
|
||||
{
|
||||
debug( LOG_ERROR, "scrStartMission: couldn't find level data" );
|
||||
abort();
|
||||
|
|
|
@ -1340,7 +1340,8 @@ BOOL scrValDefLoad(SDWORD version, INTERP_VAL *psVal, char *pBuffer, UDWORD size
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!levFindDataSet(pBuffer, &psLevel))
|
||||
psLevel = levFindDataSet(pBuffer);
|
||||
if (psLevel == NULL)
|
||||
{
|
||||
debug( LOG_ERROR, "scrValDefLoad: couldn't find level dataset %s", pBuffer );
|
||||
abort();
|
||||
|
|
|
@ -638,7 +638,8 @@ var_init: var_entry TYPE var_value
|
|||
YYABORT;
|
||||
}
|
||||
// just check the level exists
|
||||
if (!levFindDataSet($3.pString, &psLevel))
|
||||
psLevel = levFindDataSet($3.pString);
|
||||
if (psLevel == NULL)
|
||||
{
|
||||
scrv_error("Level %s not found", $3.pString);
|
||||
YYABORT;
|
||||
|
|
Loading…
Reference in New Issue