From 8b8ed96a6be475dedbea5caaf0d64768314ecbe9 Mon Sep 17 00:00:00 2001 From: Lesh Date: Tue, 10 Oct 2006 18:35:00 +0000 Subject: [PATCH] - reworked cities.xml handling section, added new fields git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@598 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Strategic/Strategic Town Loyalty.cpp | 64 ++++---- Strategic/strategicmap.cpp | 222 +++++++++++++-------------- Strategic/strategicmap.h | 2 + 3 files changed, 145 insertions(+), 143 deletions(-) diff --git a/Strategic/Strategic Town Loyalty.cpp b/Strategic/Strategic Town Loyalty.cpp index 74cd637c..46bb6f76 100644 --- a/Strategic/Strategic Town Loyalty.cpp +++ b/Strategic/Strategic Town Loyalty.cpp @@ -129,39 +129,39 @@ UINT32 uiPercentLoyaltyDecreaseForCivMurder[]={ // on a scale of 1-100, this is a measure of how much each town hates the Queen's opression & is willing to stand against it // it primarily controls the RATE of loyalty change in each town: the loyalty effect of the same events depends on it -UINT8 gubTownRebelSentiment[ NUM_TOWNS ] = -{ - 0, // not a town - blank sector index - 90, // OMERTA, - They ARE the rebels!!! - 30, // DRASSEN, - Rebel friendly, makes it pretty easy to get first mine's income going at the start - 12, // ALMA - Military town, high loyalty to Queen, need quests to get 100% - 15, // GRUMM, - Close to Meduna, strong influence - 20, // TIXA, - Not a real town - 15, // CAMBRIA, - Artificially much lower 'cause it's big and central and too easy to get loyalty up there - 20, // SAN_MONA,- Neutral ground, loyalty doesn't vary - 20, // ESTONI, - Not a real town - 20, // ORTA, - Not a real town - 12, // BALIME, - Rich town, high loyalty to Queen - 10, // MEDUNA, - Enemy HQ, for God's sake! - 35, // CHITZENA, - Artificially high 'cause there's not enough fights near it to get the loyalty up otherwise -}; +UINT8 gubTownRebelSentiment[ NUM_TOWNS ]; // = +//{ +// 0, // not a town - blank sector index +// 90, // OMERTA, - They ARE the rebels!!! +// 30, // DRASSEN, - Rebel friendly, makes it pretty easy to get first mine's income going at the start +// 12, // ALMA - Military town, high loyalty to Queen, need quests to get 100% +// 15, // GRUMM, - Close to Meduna, strong influence +// 20, // TIXA, - Not a real town +// 15, // CAMBRIA, - Artificially much lower 'cause it's big and central and too easy to get loyalty up there +// 20, // SAN_MONA,- Neutral ground, loyalty doesn't vary +// 20, // ESTONI, - Not a real town +// 20, // ORTA, - Not a real town +// 12, // BALIME, - Rich town, high loyalty to Queen +// 10, // MEDUNA, - Enemy HQ, for God's sake! +// 35, // CHITZENA, - Artificially high 'cause there's not enough fights near it to get the loyalty up otherwise +//}; -BOOLEAN gfTownUsesLoyalty[ NUM_TOWNS ] = -{ - FALSE, // not a town - blank sector index - TRUE , // OMERTA - TRUE, // DRASSEN - TRUE, // ALMA - TRUE, // GRUMM - FALSE, // TIXA - TRUE, // CAMBRIA - FALSE, // SAN_MONA - FALSE, // ESTONI - FALSE, // ORTA - TRUE, // BALIME - TRUE, // MEDUNA - TRUE, // CHITZENA -}; +BOOLEAN gfTownUsesLoyalty[ NUM_TOWNS ];// = +//{ +// FALSE, // not a town - blank sector index +// TRUE , // OMERTA +// TRUE, // DRASSEN +// TRUE, // ALMA +// TRUE, // GRUMM +// FALSE, // TIXA +// TRUE, // CAMBRIA +// FALSE, // SAN_MONA +// FALSE, // ESTONI +// FALSE, // ORTA +// TRUE, // BALIME +// TRUE, // MEDUNA +// TRUE, // CHITZENA +//}; // location of first enocunter with enemy INT16 sWorldSectorLocationOfFirstBattle = 0; diff --git a/Strategic/strategicmap.cpp b/Strategic/strategicmap.cpp index aa263995..ce45a8d5 100644 --- a/Strategic/strategicmap.cpp +++ b/Strategic/strategicmap.cpp @@ -347,6 +347,9 @@ void CrippledVersionFailureToLoadMapCheck(); #include "tiledat.h" #endif +extern UINT8 gubTownRebelSentiment[ NUM_TOWNS ]; +extern BOOLEAN gfTownUsesLoyalty[ NUM_TOWNS ]; + #define MAX_CHAR_DATA_LENGTH 500 typedef enum @@ -365,6 +368,8 @@ typedef enum CITYTABLE_ELEMENT_TOWNPOINT, CITYTABLE_ELEMENT_TOWNPOINT_X, CITYTABLE_ELEMENT_TOWNPOINT_Y, + CITYTABLE_ELEMENT_USES_LOYALTY, + CITYTABLE_ELEMENT_REBEL_SENTIMENT } CITYTABLE_PARSE_STAGE; typedef struct @@ -373,6 +378,8 @@ typedef struct UINT8 ubBaseX; UINT8 ubBaseY; POINT townPoint; + BOOLEAN townUsesLoyalty; + UINT8 townRebelSentiment; CHAR8 cityName[MAX_TOWN_NAME_LENGHT]; } cityInfo; @@ -427,6 +434,8 @@ citytableStartElementHandle(void *userData, const char *name, const char **atts) memset(sBaseSectorList,0,sizeof(sBaseSectorList)); memset(pTownPoints,0,sizeof(pTownPoints)); + memset(gfTownUsesLoyalty,0,sizeof(gfTownUsesLoyalty)); + memset(gubTownRebelSentiment,0,sizeof(gubTownRebelSentiment)); pData->maxReadDepth++; //we are not skipping this element } @@ -438,7 +447,7 @@ citytableStartElementHandle(void *userData, const char *name, const char **atts) pData->maxReadDepth++; //we are not skipping this element } - else if(strcmp(name, "cityName") == 0 && pData->curElement == CITYTABLE_ELEMENT_CITY) + else if(strcmp(name, "townName") == 0 && pData->curElement == CITYTABLE_ELEMENT_CITY) { pData->curElement = CITYTABLE_ELEMENT_NAME; pData->maxReadDepth++; //we are not skipping this element @@ -448,6 +457,16 @@ citytableStartElementHandle(void *userData, const char *name, const char **atts) pData->curElement = CITYTABLE_ELEMENT_INDEX; pData->maxReadDepth++; //we are not skipping this element } + else if(strcmp(name, "townUsesLoyalty") == 0 && pData->curElement == CITYTABLE_ELEMENT_CITY) + { + pData->curElement = CITYTABLE_ELEMENT_USES_LOYALTY; + pData->maxReadDepth++; //we are not skipping this element + } + else if(strcmp(name, "townRebelSentiment") == 0 && pData->curElement == CITYTABLE_ELEMENT_CITY) + { + pData->curElement = CITYTABLE_ELEMENT_REBEL_SENTIMENT; + pData->maxReadDepth++; //we are not skipping this element + } else if(strcmp(name, "baseSector") == 0 && pData->curElement == CITYTABLE_ELEMENT_CITY) { pData->curElement = CITYTABLE_ELEMENT_BASESECTOR; @@ -538,8 +557,12 @@ citytableEndElementHandle(void *userData, const char *name) { pData->curElement = CITYTABLE_ELEMENT_CITYLIST; - sBaseSectorList[pData->curCityInfo.uiIndex-1] = SECTOR(pData->curCityInfo.ubBaseX,pData->curCityInfo.ubBaseY); - pTownPoints[pData->curCityInfo.uiIndex] = pData->curCityInfo.townPoint; + sBaseSectorList [pData->curCityInfo.uiIndex-1] = SECTOR(pData->curCityInfo.ubBaseX,pData->curCityInfo.ubBaseY); + pTownPoints [pData->curCityInfo.uiIndex ] = pData->curCityInfo.townPoint; + gfTownUsesLoyalty [pData->curCityInfo.uiIndex ] = pData->curCityInfo.townUsesLoyalty; + gubTownRebelSentiment [pData->curCityInfo.uiIndex ] = pData->curCityInfo.townRebelSentiment; + + mbstowcs( pTownNames[pData->curCityInfo.uiIndex], pData->curCityInfo.cityName, MAX_TOWN_NAME_LENGHT); } else if(strcmp(name, "uiIndex") == 0 && pData->curElement == CITYTABLE_ELEMENT_INDEX) { @@ -547,13 +570,31 @@ citytableEndElementHandle(void *userData, const char *name) pData->curCityInfo.uiIndex = atol(pData->szCharData); } - else if(strcmp(name, "cityName") == 0 && pData->curElement == CITYTABLE_ELEMENT_NAME) + else if(strcmp(name, "townName") == 0 && pData->curElement == CITYTABLE_ELEMENT_NAME) { - // Copy this string into the pTownNames array - mbstowcs(pTownNames[pData->curCityInfo.uiIndex], (const char *) pData->szCharData, MAX_TOWN_NAME_LENGHT); - pTownNames[pData->curCityInfo.uiIndex][MAX_TOWN_NAME_LENGHT - 1] = 0; + strncpy(pData->curCityInfo.cityName, (const char *) pData->szCharData, MAX_TOWN_NAME_LENGHT - 1); + pData->curCityInfo.cityName[MAX_TOWN_NAME_LENGHT - 1] = 0; + pData->curElement = CITYTABLE_ELEMENT_CITY; } + else if(strcmp(name, "townUsesLoyalty") == 0 && pData->curElement == CITYTABLE_ELEMENT_USES_LOYALTY ) + { + pData->curElement = CITYTABLE_ELEMENT_CITY; + + pData->curCityInfo.townUsesLoyalty = (BOOLEAN)atol(pData->szCharData); + } + else if(strcmp(name, "townRebelSentiment") == 0 && pData->curElement == CITYTABLE_ELEMENT_REBEL_SENTIMENT ) + { + pData->curElement = CITYTABLE_ELEMENT_CITY; + + pData->curCityInfo.townRebelSentiment = (UINT8)atol(pData->szCharData); + if ( pData->curCityInfo.townRebelSentiment > 100 ) + { + pData->curCityInfo.townRebelSentiment = 100; + } + else if ( !pData->curCityInfo.townRebelSentiment ) + pData->curCityInfo.townRebelSentiment = 1; + } else if(strcmp(name, "baseSector") == 0 && pData->curElement == CITYTABLE_ELEMENT_BASESECTOR) { pData->curElement = CITYTABLE_ELEMENT_CITY; @@ -593,6 +634,69 @@ citytableEndElementHandle(void *userData, const char *name) pData->currentDepth--; } +BOOLEAN WriteInStrategicMapSectorTownNames(STR fileName) +{ + HWFILE hFile; + + hFile = FileOpen( fileName, FILE_ACCESS_WRITE | FILE_CREATE_ALWAYS, FALSE ); + if ( !hFile ) + return( FALSE ); + + { + UINT32 x, y, cnt; + + + FilePrintf(hFile,"\r\n"); + FilePrintf(hFile,"\t\r\n"); + for(cnt = 1; cnt < NUM_TOWNS; cnt++) + { + FilePrintf(hFile,"\t\t\r\n"); + + FilePrintf(hFile,"\t\t\t%d\r\n",cnt); + + FilePrintf(hFile,"\t\t\t%S\r\n", pTownNames[cnt] ); + + FilePrintf(hFile,"\t\t\t%d\r\n", gfTownUsesLoyalty[cnt] ); + + FilePrintf(hFile,"\t\t\t%d\r\n", gubTownRebelSentiment[cnt] ); + + FilePrintf(hFile,"\t\t\t\r\n"); + FilePrintf(hFile,"\t\t\t\t%d\r\n",(sBaseSectorList[cnt-1]%16)+1); + FilePrintf(hFile,"\t\t\t\t%d\r\n",(sBaseSectorList[cnt-1]/16)+1); + FilePrintf(hFile,"\t\t\t\r\n"); + + + FilePrintf(hFile,"\t\t\t\r\n"); + FilePrintf(hFile,"\t\t\t\t%d\r\n",pTownPoints[cnt].x); + FilePrintf(hFile,"\t\t\t\t%d\r\n",pTownPoints[cnt].y); + FilePrintf(hFile,"\t\t\t\r\n"); + + + FilePrintf(hFile,"\t\t\r\n"); + } + FilePrintf(hFile,"\t\r\n"); + + FilePrintf(hFile,"\t\r\n"); + for(y = 0;y < MAP_WORLD_Y;y++) + { + FilePrintf(hFile,"\t\t",y); + for(x = 0;x < MAP_WORLD_X;x++) + { + if(x < MAP_WORLD_X-1) + { + FilePrintf(hFile,"%3d",StrategicMap[x+y*MAP_WORLD_X].bNameId); + } + else + FilePrintf(hFile,"%3d \r\n",StrategicMap[x+y*MAP_WORLD_X].bNameId); + } + } + FilePrintf(hFile,"\t\r\n"); + FilePrintf(hFile,"\r\n"); + } + FileClose( hFile ); + + return TRUE; +} BOOLEAN ReadInStrategicMapSectorTownNames(STR fileName) { @@ -649,110 +753,6 @@ BOOLEAN ReadInStrategicMapSectorTownNames(STR fileName) XML_ParserFree(parser); -#ifdef JA2TESTVERSION - hFile = FileOpen( "TABLEDATA\\~Cities.xml", FILE_ACCESS_WRITE | FILE_CREATE_ALWAYS, FALSE ); - if ( !hFile ) - return( FALSE ); - - { - UINT32 x, y, cnt; - - - FilePrintf(hFile,"\r\n"); - FilePrintf(hFile,"\t\r\n"); - for(cnt = 1;cnt <= 12;cnt++) - { - FilePrintf(hFile,"\t\t\r\n"); - - FilePrintf(hFile,"\t\t\t%d\r\n",cnt); - - switch(cnt) - { - case 1: - FilePrintf(hFile,"\t\t\tOmerta\r\n"); - break; - - case 2: - FilePrintf(hFile,"\t\t\tDrassen\r\n"); - break; - - case 3: - FilePrintf(hFile,"\t\t\tAlma\r\n"); - break; - - case 4: - FilePrintf(hFile,"\t\t\tGrumm\r\n"); - break; - - case 5: - FilePrintf(hFile,"\t\t\tTixa\r\n"); - break; - - case 6: - FilePrintf(hFile,"\t\t\tCambria\r\n"); - break; - - case 7: - FilePrintf(hFile,"\t\t\tSan Mona\r\n"); - break; - - case 8: - FilePrintf(hFile,"\t\t\tEstoni\r\n"); - break; - - case 9: - FilePrintf(hFile,"\t\t\tOrta\r\n"); - break; - - case 10: - FilePrintf(hFile,"\t\t\tBalime\r\n"); - break; - - case 11: - FilePrintf(hFile,"\t\t\tMeduna\r\n"); - break; - - case 12: - FilePrintf(hFile,"\t\t\tChitzena\r\n"); - break; - } - - FilePrintf(hFile,"\t\t\t\r\n"); - FilePrintf(hFile,"\t\t\t\t%d\r\n",(sBaseSectorList[cnt-1]%16)+1); - FilePrintf(hFile,"\t\t\t\t%d\r\n",(sBaseSectorList[cnt-1]/16)+1); - FilePrintf(hFile,"\t\t\t\r\n"); - - - FilePrintf(hFile,"\t\t\t\r\n"); - FilePrintf(hFile,"\t\t\t\t%d\r\n",pTownPoints[cnt].x); - FilePrintf(hFile,"\t\t\t\t%d\r\n",pTownPoints[cnt].y); - FilePrintf(hFile,"\t\t\t\r\n"); - - - FilePrintf(hFile,"\t\t\r\n"); - } - FilePrintf(hFile,"\t\r\n"); - - FilePrintf(hFile,"\t\r\n"); - for(y = 0;y < MAP_WORLD_Y;y++) - { - FilePrintf(hFile,"\t\t",y); - for(x = 0;x < MAP_WORLD_X;x++) - { - if(x < MAP_WORLD_X-1) - { - FilePrintf(hFile,"%3d",StrategicMap[x+y*MAP_WORLD_X].bNameId); - } - else - FilePrintf(hFile,"%3d \r\n",StrategicMap[x+y*MAP_WORLD_X].bNameId); - } - } - FilePrintf(hFile,"\t\r\n"); - FilePrintf(hFile,"\r\n"); - } - FileClose( hFile ); -#endif - return TRUE; } diff --git a/Strategic/strategicmap.h b/Strategic/strategicmap.h index b1c25d01..56f9886c 100644 --- a/Strategic/strategicmap.h +++ b/Strategic/strategicmap.h @@ -81,6 +81,8 @@ void UpdateMercsInSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ ); void UpdateMercInSector( SOLDIERTYPE *pSoldier, INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ ); BOOLEAN ReadInMapStructure(STR fileName); +BOOLEAN ReadInStrategicMapSectorTownNames(STR fileName); +BOOLEAN WriteInStrategicMapSectorTownNames(STR fileName); // get short sector name without town name void GetShortSectorString( INT16 sMapX,INT16 sMapY, STR16 sString );