diff --git a/GameVersion.cpp b/GameVersion.cpp index cf698a33..12660e96 100644 --- a/GameVersion.cpp +++ b/GameVersion.cpp @@ -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 diff --git a/Init.cpp b/Init.cpp index 935361be..2951c8c5 100644 --- a/Init.cpp +++ b/Init.cpp @@ -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 ); diff --git a/Tactical/Disease.cpp b/Tactical/Disease.cpp index 16f121b9..775d5946 100644 --- a/Tactical/Disease.cpp +++ b/Tactical/Disease.cpp @@ -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() diff --git a/Tactical/Food.cpp b/Tactical/Food.cpp index 02fa0eac..4837196d 100644 --- a/Tactical/Food.cpp +++ b/Tactical/Food.cpp @@ -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 ////////////////////// diff --git a/Tactical/Food.h b/Tactical/Food.h index f4bb345d..796b7547 100644 --- a/Tactical/Food.h +++ b/Tactical/Food.h @@ -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 { diff --git a/Tactical/Interface Enhanced.cpp b/Tactical/Interface Enhanced.cpp index 500cb22b..04942292 100644 --- a/Tactical/Interface Enhanced.cpp +++ b/Tactical/Interface Enhanced.cpp @@ -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 ) diff --git a/Tactical/Soldier Control.h b/Tactical/Soldier Control.h index fba0dad0..885a7e11 100644 --- a/Tactical/Soldier Control.h +++ b/Tactical/Soldier Control.h @@ -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 diff --git a/Tactical/Tactical_VS2005.vcproj b/Tactical/Tactical_VS2005.vcproj index 99f065eb..ee2518aa 100644 --- a/Tactical/Tactical_VS2005.vcproj +++ b/Tactical/Tactical_VS2005.vcproj @@ -1128,6 +1128,10 @@ RelativePath=".\XML_Food.cpp" > + + diff --git a/Tactical/Tactical_VS2008.vcproj b/Tactical/Tactical_VS2008.vcproj index fb52a9ee..83c4e6bf 100644 --- a/Tactical/Tactical_VS2008.vcproj +++ b/Tactical/Tactical_VS2008.vcproj @@ -1130,6 +1130,10 @@ RelativePath=".\XML_Food.cpp" > + + diff --git a/Tactical/Tactical_VS2010.vcxproj b/Tactical/Tactical_VS2010.vcxproj index d77237f7..d08150e9 100644 --- a/Tactical/Tactical_VS2010.vcxproj +++ b/Tactical/Tactical_VS2010.vcxproj @@ -219,6 +219,7 @@ + diff --git a/Tactical/Tactical_VS2010.vcxproj.filters b/Tactical/Tactical_VS2010.vcxproj.filters index ef03e050..c27813a7 100644 --- a/Tactical/Tactical_VS2010.vcxproj.filters +++ b/Tactical/Tactical_VS2010.vcxproj.filters @@ -632,7 +632,7 @@ Source Files - + Source Files @@ -686,5 +686,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/Tactical/Tactical_VS2013.vcxproj b/Tactical/Tactical_VS2013.vcxproj index 92464f4f..81d9a728 100644 --- a/Tactical/Tactical_VS2013.vcxproj +++ b/Tactical/Tactical_VS2013.vcxproj @@ -220,6 +220,7 @@ + diff --git a/Tactical/Tactical_VS2013.vcxproj.filters b/Tactical/Tactical_VS2013.vcxproj.filters index 64296322..2c3f49e8 100644 --- a/Tactical/Tactical_VS2013.vcxproj.filters +++ b/Tactical/Tactical_VS2013.vcxproj.filters @@ -644,6 +644,9 @@ Source Files + + Source Files + Source Files diff --git a/Tactical/XML.h b/Tactical/XML.h index 90f3dc8c..ee8dd07b 100644 --- a/Tactical/XML.h +++ b/Tactical/XML.h @@ -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( ); diff --git a/Tactical/XML_Food.cpp b/Tactical/XML_Food.cpp index 8c5f92bb..f2a45336 100644 --- a/Tactical/XML_Food.cpp +++ b/Tactical/XML_Food.cpp @@ -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%d\r\n", Food[cnt].bFoodPoints ); FilePrintf(hFile,"\t\t%d\r\n", Food[cnt].bDrinkPoints ); FilePrintf(hFile,"\t\t%d\r\n", Food[cnt].ubPortionSize ); - FilePrintf(hFile,"\t\t%d\r\n", Food[cnt].bMoraleMod ); FilePrintf(hFile,"\t\t%4.2f\r\n", Food[cnt].usDecayRate ); FilePrintf(hFile,"\t\r\n"); diff --git a/Tactical/XML_FoodOpinions.cpp b/Tactical/XML_FoodOpinions.cpp new file mode 100644 index 00000000..2480267d --- /dev/null +++ b/Tactical/XML_FoodOpinions.cpp @@ -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,"\r\n"); + for(cnt = 0; cnt < FOOD_TYPE_MAX; ++cnt) + { + FilePrintf(hFile,"\t\r\n"); + + FilePrintf(hFile,"\t\t%d\r\n", cnt ); + + FilePrintf(hFile,"\t\r\n"); + } + FilePrintf(hFile,"\r\n"); + } + FileClose( hFile ); + + return( TRUE ); +} diff --git a/Utils/XML_Items.cpp b/Utils/XML_Items.cpp index 9c073b03..95dd03b8 100644 --- a/Utils/XML_Items.cpp +++ b/Utils/XML_Items.cpp @@ -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;