mirror of
https://github.com/1dot13/source.git
synced 2026-08-12 14:10:23 +02:00
Fix: if no squad name is provided in xml, fall back on hardcoded name
git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8867 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
@@ -9,21 +9,19 @@
|
||||
#include "XML.h"
|
||||
#endif
|
||||
|
||||
|
||||
struct
|
||||
{
|
||||
PARSE_STAGE curElement;
|
||||
|
||||
CHAR8 szCharData[MAX_CHAR_DATA_LENGTH+1];
|
||||
SQUAD_NAMES curSquadNames;
|
||||
SQUAD_NAMES * curArray;
|
||||
UINT32 maxArraySize;
|
||||
|
||||
UINT32 currentDepth;
|
||||
UINT32 maxReadDepth;
|
||||
}
|
||||
typedef squadnamesParseData;
|
||||
|
||||
std::vector<std::wstring> gSquadNameVector;
|
||||
|
||||
static void XMLCALL
|
||||
squadnamesStartElementHandle(void *userData, const XML_Char *name, const XML_Char **atts)
|
||||
{
|
||||
@@ -34,17 +32,13 @@ squadnamesStartElementHandle(void *userData, const XML_Char *name, const XML_Cha
|
||||
if(strcmp(name, "SQUAD_NAMES") == 0 && pData->curElement == ELEMENT_NONE)
|
||||
{
|
||||
pData->curElement = ELEMENT_LIST;
|
||||
|
||||
memset(pData->curArray,0,sizeof(SQUAD_NAMES)*pData->maxArraySize);
|
||||
|
||||
|
||||
pData->maxReadDepth++; //we are not skipping this element
|
||||
}
|
||||
else if(strcmp(name, "SQUADNAME") == 0 && pData->curElement == ELEMENT_LIST)
|
||||
{
|
||||
pData->curElement = ELEMENT;
|
||||
|
||||
memset(&pData->curSquadNames,0,sizeof(SQUAD_NAMES));
|
||||
|
||||
|
||||
pData->maxReadDepth++; //we are not skipping this element
|
||||
}
|
||||
else if(pData->curElement == ELEMENT &&
|
||||
@@ -58,9 +52,8 @@ squadnamesStartElementHandle(void *userData, const XML_Char *name, const XML_Cha
|
||||
|
||||
pData->szCharData[0] = '\0';
|
||||
}
|
||||
|
||||
|
||||
pData->currentDepth++;
|
||||
|
||||
}
|
||||
|
||||
static void XMLCALL
|
||||
@@ -75,7 +68,6 @@ squadnamesCharacterDataHandle(void *userData, const XML_Char *str, int len)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void XMLCALL
|
||||
squadnamesEndElementHandle(void *userData, const XML_Char *name)
|
||||
{
|
||||
@@ -90,25 +82,22 @@ squadnamesEndElementHandle(void *userData, const XML_Char *name)
|
||||
else if(strcmp(name, "SQUADNAME") == 0)
|
||||
{
|
||||
pData->curElement = ELEMENT_LIST;
|
||||
|
||||
if(pData->curSquadNames.uiIndex < pData->maxArraySize)
|
||||
{
|
||||
pData->curArray[pData->curSquadNames.uiIndex] = pData->curSquadNames; //write the squadnames into the table
|
||||
}
|
||||
}
|
||||
else if(strcmp(name, "uiIndex") == 0)
|
||||
{
|
||||
pData->curElement = ELEMENT;
|
||||
pData->curSquadNames.uiIndex = (UINT32) atol(pData->szCharData);
|
||||
}
|
||||
else if(strcmp(name, "Squad") == 0)
|
||||
{
|
||||
pData->curElement = ELEMENT;
|
||||
|
||||
MultiByteToWideChar( CP_UTF8, 0, pData->szCharData, -1, pData->curSquadNames.squadname, sizeof(pData->curSquadNames.squadname)/sizeof(pData->curSquadNames.squadname[0]) );
|
||||
pData->curSquadNames.squadname[sizeof(pData->curSquadNames.squadname)/sizeof(pData->curSquadNames.squadname[0]) - 1] = '\0';
|
||||
CHAR16 bla[30];
|
||||
|
||||
MultiByteToWideChar( CP_UTF8, 0, pData->szCharData, -1, bla, sizeof( bla ) / sizeof( bla[0] ) );
|
||||
bla[sizeof( bla ) / sizeof( bla[0] ) - 1] = '\0';
|
||||
|
||||
gSquadNameVector.push_back( bla );
|
||||
}
|
||||
|
||||
|
||||
pData->maxReadDepth--;
|
||||
}
|
||||
@@ -116,9 +105,6 @@ squadnamesEndElementHandle(void *userData, const XML_Char *name)
|
||||
pData->currentDepth--;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BOOLEAN ReadInSquadNamesStats(STR fileName)
|
||||
{
|
||||
HWFILE hFile;
|
||||
@@ -149,19 +135,14 @@ BOOLEAN ReadInSquadNamesStats(STR fileName)
|
||||
lpcBuffer[uiFSize] = 0; //add a null terminator
|
||||
|
||||
FileClose( hFile );
|
||||
|
||||
|
||||
|
||||
XML_SetElementHandler(parser, squadnamesStartElementHandle, squadnamesEndElementHandle);
|
||||
XML_SetCharacterDataHandler(parser, squadnamesCharacterDataHandle);
|
||||
|
||||
|
||||
|
||||
memset(&pData,0,sizeof(pData));
|
||||
pData.curArray = SquadNames;
|
||||
pData.maxArraySize = 20;
|
||||
|
||||
XML_SetUserData(parser, &pData);
|
||||
|
||||
|
||||
|
||||
if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE))
|
||||
{
|
||||
CHAR8 errorBuf[511];
|
||||
@@ -174,16 +155,13 @@ BOOLEAN ReadInSquadNamesStats(STR fileName)
|
||||
}
|
||||
|
||||
MemFree(lpcBuffer);
|
||||
|
||||
|
||||
|
||||
XML_ParserFree(parser);
|
||||
|
||||
|
||||
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
BOOLEAN WriteSquadNamesStats()
|
||||
{
|
||||
|
||||
{
|
||||
return( TRUE );
|
||||
}
|
||||
Reference in New Issue
Block a user