- New xml: FoodOpinion.xml allows individual opinions on individual food items for each merc, the <bMoraleMod>-tag in Food.xml was removed.

- Maximum number of food items was increased to 500 (was 128).

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@7454 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Flugente
2014-08-28 20:12:06 +00:00
parent d8cdfc927c
commit a37cf0f8f1
17 changed files with 303 additions and 106 deletions
+9 -9
View File
@@ -15,9 +15,9 @@
#ifdef JA2EDITOR
#ifdef JA2UB
CHAR16 zVersionLabel[256] = { L"Unfinished Business - Map Editor v1.13.7384 (Development Build)" };
CHAR16 zVersionLabel[256] = { L"Unfinished Business - Map Editor v1.13.7454 (Development Build)" };
#else
CHAR16 zVersionLabel[256] = { L"Map Editor v1.13.7384 (Development Build)" };
CHAR16 zVersionLabel[256] = { L"Map Editor v1.13.7454 (Development Build)" };
#endif
// ------------------------------
@@ -27,11 +27,11 @@
//DEBUG BUILD VERSION
#ifdef JA2UB
CHAR16 zVersionLabel[256] = { L"Debug: Unfinished Business - v1.13.7384 (Development Build)" };
CHAR16 zVersionLabel[256] = { L"Debug: Unfinished Business - v1.13.7454 (Development Build)" };
#elif defined (JA113DEMO)
CHAR16 zVersionLabel[256] = { L"Debug: JA2 Demo - v1.13.7384 (Development Build)" };
CHAR16 zVersionLabel[256] = { L"Debug: JA2 Demo - v1.13.7454 (Development Build)" };
#else
CHAR16 zVersionLabel[256] = { L"Debug: v1.13.7384 (Development Build)" };
CHAR16 zVersionLabel[256] = { L"Debug: v1.13.7454 (Development Build)" };
#endif
#elif defined CRIPPLED_VERSION
@@ -46,16 +46,16 @@
//RELEASE BUILD VERSION
#ifdef JA2UB
CHAR16 zVersionLabel[256] = { L"Release Unfinished Business - v1.13.7384 (Development Build)" };
CHAR16 zVersionLabel[256] = { L"Release Unfinished Business - v1.13.7454 (Development Build)" };
#elif defined (JA113DEMO)
CHAR16 zVersionLabel[256] = { L"Release JA2 Demo - v1.13.7384 (Development Build)" };
CHAR16 zVersionLabel[256] = { L"Release JA2 Demo - v1.13.7454 (Development Build)" };
#else
CHAR16 zVersionLabel[256] = { L"Release v1.13.7384 (Development Build)" };
CHAR16 zVersionLabel[256] = { L"Release v1.13.7454 (Development Build)" };
#endif
#endif
CHAR8 czVersionNumber[16] = { "Build 14.08.10" }; //YY.MM.DD
CHAR8 czVersionNumber[16] = { "Build 14.08.28" }; //YY.MM.DD
CHAR16 zTrackingNumber[16] = { L"Z" };
// SAVE_GAME_VERSION is defined in header, change it there
+4
View File
@@ -365,6 +365,10 @@ BOOLEAN LoadExternalGameplayData(STR directoryName)
strcat(fileName, FOODFILENAME);
SGP_THROW_IFFALSE(ReadInFoodStats(fileName),FOODFILENAME);
strcpy(fileName, directoryName);
strcat(fileName, FOODOPINIONFILENAME);
SGP_THROW_IFFALSE(ReadInFoodOpinionStats(fileName),FOODOPINIONFILENAME);
strcpy( fileName, directoryName );
strcat( fileName, DISEASEFILENAME );
SGP_THROW_IFFALSE( ReadInDiseaseStats( fileName ), DISEASEFILENAME );
+1 -1
View File
@@ -55,7 +55,7 @@ FLOAT GetSectorDiseaseOverFlowThreshold( )
if ( Disease[0].sInfectionPtsGainPerHour > 0 )
return GetCivPopulationDoctorRate( ) * GetPopulationDoctorPoints( ) / (FLOAT)Disease[0].sInfectionPtsGainPerHour;
return 0.3;
return 0.3f;
}
void HandleDisease()
+18 -17
View File
@@ -32,6 +32,8 @@
class OBJECTTYPE;
class SOLDIERTYPE;
FOODOPINIONS FoodOpinions[NUM_PROFILES];
extern MoraleEvent gbMoraleEvent[NUM_MORALE_EVENTS];
extern BOOLEAN GetSectorFlagStatus( INT16 sMapX, INT16 sMapY, UINT8 bMapZ, UINT32 uiFlagToSet );
@@ -40,7 +42,6 @@ extern BOOLEAN IsVehicle(SOLDIERTYPE *pSoldier);
extern SECTOR_EXT_DATA SectorExternalData[256][4];
#define FOOD_BAD_THRESHOLD 0.5f // must be > 0 !!!!!
#define FOOD_BAD_THRESHOLD_INVERSE 1.0f/FOOD_BAD_THRESHOLD
#define FOOD_MORALE_DRINK_TO_FOOD_RATIO 1.0f
#define FOOD_FACILITY_WATER_FACTOR 3.0f // in a facility that serves food, only the food value is specified in the xml. drink value is food value multiplied by this
@@ -196,41 +197,41 @@ BOOLEAN ApplyFood( SOLDIERTYPE *pSoldier, OBJECTTYPE *pObject, BOOLEAN fForce, B
AddFoodpoints(pSoldier->bDrinkLevel, drinkpts);
/////////////////// MORALE //////////////////////
INT8 moralemod = Food[foodtype].bMoraleMod;
// morale can now be defined for each profile and food individually - default value is always 0
INT8 moralemod = 0;
if ( pSoldier->ubProfile != NO_PROFILE )
moralemod = FoodOpinions[pSoldier->ubProfile].sFoodOpinion[foodtype];
// if food is rotting, we get a morale penalty
if ( foodcondition < FOOD_BAD_THRESHOLD )
moralemod -= (FOOD_BAD_THRESHOLD - foodcondition) * 10;
if ( moralemod > 0 )
// morale is lower if food is rotten, can even become negative
moralemod = (INT8) ( moralemod * (FOOD_BAD_THRESHOLD_INVERSE*foodcondition - 1.0f) );
else
// if we hate the food anyway, give even lower morale if its rotten
moralemod = (INT8) ( moralemod * (2.0f - foodcondition) );
if ( moralemod > 0 )
{
while ( moralemod > 0 && moralemod >= gMoraleSettings.bValues[MORALE_GOOD_FOOD] )//gbMoraleEvent[MORALE_GOOD_FOOD].bChange )
while ( moralemod > 0 && moralemod >= gMoraleSettings.bValues[MORALE_GOOD_FOOD] )
{
HandleMoraleEvent( pSoldier, MORALE_GOOD_FOOD, pSoldier->sSectorX, pSoldier->sSectorY, pSoldier->bSectorZ );
moralemod -= gMoraleSettings.bValues[MORALE_GOOD_FOOD];//gbMoraleEvent[MORALE_GOOD_FOOD].bChange;
moralemod -= gMoraleSettings.bValues[MORALE_GOOD_FOOD];
}
while ( moralemod > 0 && moralemod >= gMoraleSettings.bValues[MORALE_FOOD] )//gbMoraleEvent[MORALE_FOOD].bChange )
while ( moralemod > 0 && moralemod >= gMoraleSettings.bValues[MORALE_FOOD] )
{
HandleMoraleEvent( pSoldier, MORALE_FOOD, pSoldier->sSectorX, pSoldier->sSectorY, pSoldier->bSectorZ );
moralemod -= gMoraleSettings.bValues[MORALE_FOOD];//gbMoraleEvent[MORALE_FOOD].bChange;
moralemod -= gMoraleSettings.bValues[MORALE_FOOD];
}
}
else if ( moralemod < 0 )
{
while ( moralemod < 0 && moralemod <= gMoraleSettings.bValues[MORALE_LOATHSOME_FOOD] )//gbMoraleEvent[MORALE_LOATHSOME_FOOD].bChange )
while ( moralemod < 0 && moralemod <= gMoraleSettings.bValues[MORALE_LOATHSOME_FOOD] )
{
HandleMoraleEvent( pSoldier, MORALE_LOATHSOME_FOOD, pSoldier->sSectorX, pSoldier->sSectorY, pSoldier->bSectorZ );
moralemod -= gMoraleSettings.bValues[MORALE_LOATHSOME_FOOD];//gbMoraleEvent[MORALE_LOATHSOME_FOOD].bChange;
moralemod -= gMoraleSettings.bValues[MORALE_LOATHSOME_FOOD];
}
while ( moralemod < 0 && moralemod <= gMoraleSettings.bValues[MORALE_BAD_FOOD] )//gbMoraleEvent[MORALE_BAD_FOOD].bChange )
while ( moralemod < 0 && moralemod <= gMoraleSettings.bValues[MORALE_BAD_FOOD] )
{
HandleMoraleEvent( pSoldier, MORALE_BAD_FOOD, pSoldier->sSectorX, pSoldier->sSectorY, pSoldier->bSectorZ );
moralemod -= gMoraleSettings.bValues[MORALE_BAD_FOOD];//gbMoraleEvent[MORALE_BAD_FOOD].bChange;
moralemod -= gMoraleSettings.bValues[MORALE_BAD_FOOD];
}
}
/////////////////// MORALE //////////////////////
+10 -2
View File
@@ -1,7 +1,8 @@
#ifndef __FOOD_H
#define __FOOD_H
#include "soldier control.h"
#include "Soldier Control.h"
#include "soldier profile type.h"
#define FOOD_MIN - 20000
#define FOOD_MAX 20000
@@ -52,13 +53,20 @@ typedef struct
INT32 bFoodPoints; // points that will be added to our drink level
INT32 bDrinkPoints; // points that will be added to our drink level
UINT16 ubPortionSize; // how much is 'eaten' as a portion (percentage)
INT8 bMoraleMod; // morale modificator for eating this
FLOAT usDecayRate; // rate at which food decays
} FOODTYPE;
//GLOBALS
extern FOODTYPE Food[FOOD_TYPE_MAX];
// mercs can have different opinions on food
typedef struct
{
INT8 sFoodOpinion[FOOD_TYPE_MAX];
} FOODOPINIONS;
extern FOODOPINIONS FoodOpinions[NUM_PROFILES];
// for determining the type of water source a sector has
typedef enum
{
+3 -67
View File
@@ -4148,17 +4148,7 @@ void InternalInitEDBTooltipRegion( OBJECTTYPE * gpItemDescObject, UINT32 guiCurr
}
cnt++;
}
////////////////////// MORALE MODIFIER
if ( Food[foodtype].bMoraleMod != 0 )
{
if (cnt >= sFirstLine && cnt < sLastLine)
{
swprintf( pStr, L"%s%s", szUDBAdvStatsTooltipText[ 62 ], szUDBAdvStatsExplanationsTooltipText[ 62 ]);
SetRegionFastHelpText( &(gUDBFasthelpRegions[ iFirstDataRegion + (cnt-sFirstLine) ]), pStr );
MSYS_EnableRegion( &gUDBFasthelpRegions[ iFirstDataRegion + (cnt-sFirstLine) ] );
}
cnt++;
}
////////////////////// DECAY RATE
if ( Food[foodtype].usDecayRate != 0 )
{
@@ -5875,16 +5865,7 @@ void DrawAdvancedStats( OBJECTTYPE * gpItemDescObject )
}
cnt++;
}
if ( ( Food[Item[gpItemDescObject->usItem].foodtype].bMoraleMod > 0 ) ||
( fComparisonMode && Food[Item[gpComparedItemDescObject->usItem].foodtype].bMoraleMod > 0 ) )
{
//////////////////// MORALE MODIFICATOR
if (cnt >= sFirstLine && cnt < sLastLine)
{
BltVideoObjectFromIndex( guiSAVEBUFFER, guiItemInfoAdvancedIcon, 60, gItemDescAdvRegions[cnt-sFirstLine][0].sLeft + sOffsetX, gItemDescAdvRegions[cnt-sFirstLine][0].sTop + sOffsetY, VO_BLT_SRCTRANSPARENCY, NULL );
}
cnt++;
}
if ( ( Food[Item[gpItemDescObject->usItem].foodtype].usDecayRate > 0 ) ||
( fComparisonMode && Food[Item[gpComparedItemDescObject->usItem].foodtype].usDecayRate > 0 ) )
{
@@ -14250,52 +14231,7 @@ void DrawAdvancedValues( OBJECTTYPE *gpItemDescObject )
}
cnt++;
}
////////////////////////// MORALE MODIFIER
iModifier[0] = Food[fFoodtype].bMoraleMod;
if( fComparisonMode )
{
iComparedModifier[0] = Food[fComparedFoodtype].bMoraleMod;
iModifier[0] = iComparedModifier[0] - iModifier[0];
}
sTop = gItemDescAdvRegions[cnt-sFirstLine][1].sTop;
sHeight = gItemDescAdvRegions[cnt-sFirstLine][1].sBottom - sTop;
if ( iModifier[0] != 0 || ( fComparisonMode && iComparedModifier[0] != 0 ) )
{
if (cnt >= sFirstLine && cnt < sLastLine)
{
if( fComparisonMode )
{
if ( iModifier[0] < 0 )
SetFontForeground( ITEMDESC_FONTPOSITIVE );
else if ( iModifier[0] > 0 )
SetFontForeground( ITEMDESC_FONTNEGATIVE );
else
SetFontForeground( 5 );
}
else if ( iModifier[0] > 0 )
SetFontForeground( ITEMDESC_FONTPOSITIVE );
else
SetFontForeground( ITEMDESC_FONTNEGATIVE );
for ( UINT8 cnt2 = 0; cnt2 < 3; cnt2++ )
{
sLeft = gItemDescAdvRegions[cnt-sFirstLine][cnt2+1].sLeft;
sWidth = gItemDescAdvRegions[cnt-sFirstLine][cnt2+1].sRight - sLeft;
if ( fComparisonMode && iModifier[0] > 0 )
swprintf( pStr, L"+%d", iModifier[0] );
else if ( fComparisonMode && iModifier[0] < 0 )
swprintf( pStr, L"%d", iModifier[0] );
else if ( fComparisonMode )
swprintf( pStr, L"=" );
else
swprintf( pStr, L"%d", iModifier[0] );
FindFontCenterCoordinates( sLeft, sTop, sWidth, sHeight, pStr, BLOCKFONT2, &usX, &usY );
mprintf( usX, usY, pStr );
}
}
cnt++;
}
////////////////////////// DECAY RATE
iFloatModifier[0] = Food[fFoodtype].usDecayRate;
if( fComparisonMode )
+1 -1
View File
@@ -27,7 +27,7 @@
#define PTR_PRONE (gAnimControl[ pSoldier->usAnimState ].ubHeight == ANIM_PRONE)
#define DRUG_TYPE_MAX 32
#define FOOD_TYPE_MAX 128
#define FOOD_TYPE_MAX 500
// TEMP VALUES FOR NAMES
#define MAXCIVLASTNAMES 30
+4
View File
@@ -1128,6 +1128,10 @@
RelativePath=".\XML_Food.cpp"
>
</File>
<File
RelativePath=".\XML_FoodOpinions.cpp"
>
</File>
<File
RelativePath=".\XML_HiddenNames.cpp"
>
+4
View File
@@ -1130,6 +1130,10 @@
RelativePath=".\XML_Food.cpp"
>
</File>
<File
RelativePath=".\XML_FoodOpinions.cpp"
>
</File>
<File
RelativePath=".\XML_HiddenNames.cpp"
>
+1
View File
@@ -219,6 +219,7 @@
<ClCompile Include="XML_EnemyWeaponDrops.cpp" />
<ClCompile Include="XML_Explosive.cpp" />
<ClCompile Include="XML_Food.cpp" />
<ClCompile Include="XML_FoodOpinions.cpp" />
<ClCompile Include="XML_HiddenNames.cpp" />
<ClCompile Include="XML_IMPItemChoices.cpp" />
<ClCompile Include="XML_IncompatibleAttachments.cpp" />
+4 -1
View File
@@ -632,7 +632,7 @@
<ClCompile Include="XML_ItemAdjustments.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="XML_Disease.cpp">
<ClCompile Include="XML_Disease.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="XML_Drugs.cpp">
@@ -686,5 +686,8 @@
<ClCompile Include="DynamicDialogue.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="XML_FoodOpinions.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
+1
View File
@@ -220,6 +220,7 @@
<ClCompile Include="XML_EnemyWeaponDrops.cpp" />
<ClCompile Include="XML_Explosive.cpp" />
<ClCompile Include="XML_Food.cpp" />
<ClCompile Include="XML_FoodOpinions.cpp" />
<ClCompile Include="XML_HiddenNames.cpp" />
<ClCompile Include="XML_IMPItemChoices.cpp" />
<ClCompile Include="XML_IncompatibleAttachments.cpp" />
+3
View File
@@ -644,6 +644,9 @@
<ClCompile Include="XML_Food.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="XML_FoodOpinions.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="XML_Clothes.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+5
View File
@@ -65,6 +65,7 @@ typedef PARSE_STAGE;
#define EXPLOSIVESFILENAME "Items\\Explosives.xml"
#define DRUGSFILENAME "Items\\Drugs.xml"
#define FOODFILENAME "Items\\Food.xml"
#define FOODOPINIONFILENAME "Items\\FoodOpinion.xml"
#define CLOTHESFILENAME "Items\\Clothes.xml"
#define RANDOMITEMFILENAME "Items\\RandomItem.xml"
#define AMMOFILENAME "Items\\AmmoStrings.xml"
@@ -315,6 +316,10 @@ extern BOOLEAN WriteDrugsStats();
extern BOOLEAN ReadInFoodStats(STR fileName);
extern BOOLEAN WriteFoodStats();
// Flugente: merc opinions on food
extern BOOLEAN ReadInFoodOpinionStats(STR fileName);
extern BOOLEAN WriteFoodOpinionStats();
// Flugente: disease
extern BOOLEAN ReadInDiseaseStats( STR fileName );
extern BOOLEAN WriteDiseaseStats( );
-7
View File
@@ -52,7 +52,6 @@ foodStartElementHandle(void *userData, const XML_Char *name, const XML_Char **at
strcmp(name, "bFoodPoints") == 0 ||
strcmp(name, "bDrinkPoints") == 0 ||
strcmp(name, "ubPortionSize") == 0 ||
strcmp(name, "bMoraleMod") == 0 ||
strcmp(name, "usDecayRate") == 0 ))
{
pData->curElement = ELEMENT_PROPERTY;
@@ -126,11 +125,6 @@ foodEndElementHandle(void *userData, const XML_Char *name)
pData->curElement = ELEMENT;
pData->curFood.ubPortionSize = (UINT16) atol(pData->szCharData);
}
else if(strcmp(name, "bMoraleMod") == 0)
{
pData->curElement = ELEMENT;
pData->curFood.bMoraleMod = (UINT8) atol(pData->szCharData);
}
else if(strcmp(name, "usDecayRate") == 0)
{
pData->curElement = ELEMENT;
@@ -232,7 +226,6 @@ BOOLEAN WriteFoodStats()
FilePrintf(hFile,"\t\t<bFoodPoints>%d</bFoodPoints>\r\n", Food[cnt].bFoodPoints );
FilePrintf(hFile,"\t\t<bDrinkPoints>%d</bDrinkPoints>\r\n", Food[cnt].bDrinkPoints );
FilePrintf(hFile,"\t\t<ubPortionSize>%d</ubPortionSize>\r\n", Food[cnt].ubPortionSize );
FilePrintf(hFile,"\t\t<bMoraleMod>%d</bMoraleMod>\r\n", Food[cnt].bMoraleMod );
FilePrintf(hFile,"\t\t<usDecayRate>%4.2f</usDecayRate>\r\n", Food[cnt].usDecayRate );
FilePrintf(hFile,"\t</FOOD>\r\n");
+234
View File
@@ -0,0 +1,234 @@
#ifdef PRECOMPILEDHEADERS
#include "Tactical All.h"
#else
#include "sgp.h"
#include "overhead.h"
#include "Food.h"
#include "Debug Control.h"
#include "expat.h"
#include "XML.h"
#endif
struct
{
PARSE_STAGE curElement;
CHAR8 szCharData[MAX_CHAR_DATA_LENGTH+1];
FOODOPINIONS curFood;
FOODOPINIONS * curArray;
UINT16 usIndex;
UINT32 maxArraySize;
UINT32 currentDepth;
UINT32 maxReadDepth;
}
typedef foodopinionParseData;
// haxxor
UINT16 usCurrentItem = 0;
static void XMLCALL
foodopinionStartElementHandle(void *userData, const XML_Char *name, const XML_Char **atts)
{
foodopinionParseData * pData = (foodopinionParseData *)userData;
if(pData->currentDepth <= pData->maxReadDepth) //are we reading this element?
{
if(strcmp(name, "FOODOPINIONSLIST") == 0 && pData->curElement == ELEMENT_NONE)
{
pData->curElement = ELEMENT_LIST;
memset(pData->curArray,0,sizeof(FOODTYPE)*pData->maxArraySize);
pData->maxReadDepth++; //we are not skipping this element
}
else if(strcmp(name, "FOODOPINION") == 0 && pData->curElement == ELEMENT_LIST)
{
pData->curElement = ELEMENT;
memset(&pData->curFood,0,sizeof(FOODTYPE));
pData->maxReadDepth++; //we are not skipping this element
}
else if(pData->curElement == ELEMENT &&
(strcmp(name, "uProfile") == 0 ))
{
pData->curElement = ELEMENT_PROPERTY;
pData->maxReadDepth++; //we are not skipping this element
}
else if(pData->curElement == ELEMENT &&
(strcmp(name, "PROFILE_OPINION") == 0 ))
{
pData->curElement = ELEMENT_SUBLIST;
++pData->maxReadDepth;
}
else if(pData->curElement == ELEMENT_SUBLIST &&
(strcmp(name, "FoodNumber") == 0 ||
strcmp(name, "MoraleMod") == 0 ))
{
pData->curElement = ELEMENT_SUBLIST_PROPERTY;
pData->maxReadDepth++; //we are not skipping this element
}
pData->szCharData[0] = '\0';
}
pData->currentDepth++;
}
static void XMLCALL
foodopinionCharacterDataHandle(void *userData, const XML_Char *str, int len)
{
foodopinionParseData * pData = (foodopinionParseData *)userData;
if( (pData->currentDepth <= pData->maxReadDepth) &&
(strlen(pData->szCharData) < MAX_CHAR_DATA_LENGTH)
){
strncat(pData->szCharData,str,__min((unsigned int)len,MAX_CHAR_DATA_LENGTH-strlen(pData->szCharData)));
}
}
static void XMLCALL
foodopinionEndElementHandle(void *userData, const XML_Char *name)
{
foodopinionParseData * pData = (foodopinionParseData *)userData;
if(pData->currentDepth <= pData->maxReadDepth) //we're at the end of an element that we've been reading
{
if(strcmp(name, "FOODOPINIONSLIST") == 0)
{
pData->curElement = ELEMENT_NONE;
}
else if(strcmp(name, "FOODOPINION") == 0)
{
pData->curElement = ELEMENT_LIST;
// we do NOT want to read the first entry -> move stuff by 1
if ( pData->usIndex < pData->maxArraySize )
{
pData->curArray[pData->usIndex] = pData->curFood; //write the food into the table
}
}
else if(strcmp(name, "uProfile") == 0)
{
pData->curElement = ELEMENT;
pData->usIndex = (UINT8)atol( pData->szCharData );
}
else if(strcmp(name, "PROFILE_OPINION") == 0 )
{
pData->curElement = ELEMENT;
}
else if(strcmp(name, "FoodNumber") == 0)
{
pData->curElement = ELEMENT_SUBLIST;
usCurrentItem = (UINT16) atol(pData->szCharData);
}
else if(strcmp(name, "MoraleMod") == 0)
{
pData->curElement = ELEMENT_SUBLIST;
pData->curFood.sFoodOpinion[usCurrentItem] = (INT8) atol(pData->szCharData);
}
pData->maxReadDepth--;
}
pData->currentDepth--;
}
BOOLEAN ReadInFoodOpinionStats(STR fileName)
{
HWFILE hFile;
UINT32 uiBytesRead;
UINT32 uiFSize;
CHAR8 * lpcBuffer;
XML_Parser parser = XML_ParserCreate(NULL);
foodopinionParseData pData;
DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading FoodOpinion.xml" );
// Open file
hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE );
// if the file does not exist, exit
// Flugente: no need to quit the game if the xml does not exist - this data just won't be there, but the game will still work
if ( !hFile )
return( TRUE );
uiFSize = FileGetSize(hFile);
lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1);
//Read in block
if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) )
{
MemFree(lpcBuffer);
return( FALSE );
}
lpcBuffer[uiFSize] = 0; //add a null terminator
FileClose( hFile );
XML_SetElementHandler(parser, foodopinionStartElementHandle, foodopinionEndElementHandle);
XML_SetCharacterDataHandler(parser, foodopinionCharacterDataHandle);
memset(&pData,0,sizeof(pData));
pData.curArray = FoodOpinions;
pData.maxArraySize = NUM_PROFILES;
XML_SetUserData(parser, &pData);
if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE))
{
CHAR8 errorBuf[511];
sprintf(errorBuf, "XML Parser Error in FoodOpinion.xml: %s at line %d", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser));
LiveMessage(errorBuf);
MemFree(lpcBuffer);
return FALSE;
}
MemFree(lpcBuffer);
XML_ParserFree(parser);
return( TRUE );
}
BOOLEAN WriteFoodOpinionStats()
{
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"writefoodsstats");
HWFILE hFile;
//Debug code; make sure that what we got from the file is the same as what's there
// Open a new file
hFile = FileOpen( "TABLEDATA\\FoodOpinion out.xml", FILE_ACCESS_WRITE | FILE_CREATE_ALWAYS, FALSE );
if ( !hFile )
return( FALSE );
{
UINT32 cnt;
FilePrintf(hFile,"<FOODOPINIONSLIST>\r\n");
for(cnt = 0; cnt < FOOD_TYPE_MAX; ++cnt)
{
FilePrintf(hFile,"\t<FOODOPINIONS>\r\n");
FilePrintf(hFile,"\t\t<uProfile>%d</uProfile>\r\n", cnt );
FilePrintf(hFile,"\t</FOODOPINIONS>\r\n");
}
FilePrintf(hFile,"</FOODOPINIONSLIST>\r\n");
}
FileClose( hFile );
return( TRUE );
}
+1 -1
View File
@@ -1292,7 +1292,7 @@ itemEndElementHandle(void *userData, const XML_Char *name)
pData->curElement = ELEMENT;
}
// Flugente FTW 1.2
// Flugente
else if(strcmp(name, "barrel") == 0)
{
pData->curElement = ELEMENT;