From c1bddf1c9c01e639fe343eb307383bee733c99d6 Mon Sep 17 00:00:00 2001 From: Lesh Date: Sun, 29 Oct 2006 07:10:44 +0000 Subject: [PATCH] - provided code for: 1) changing max number of slots for towns (hardcoded value). 2) highest town index defines the number of towns on map (user defined value via xml). git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@606 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Strategic/Strategic Town Loyalty.cpp | 24 ++++++------ Strategic/Strategic Town Loyalty.h | 4 +- Strategic/Town Militia.cpp | 2 +- Strategic/mapscreen.h | 6 ++- Strategic/strategicmap.cpp | 56 ++++++++++++++++++++++------ Utils/Text.h | 2 +- Utils/_DutchText.cpp | 2 +- Utils/_EnglishText.cpp | 2 +- Utils/_FrenchText.cpp | 2 +- Utils/_GermanText.cpp | 2 +- Utils/_ItalianText.cpp | 2 +- Utils/_PolishText.cpp | 2 +- Utils/_RussianText.cpp | 2 +- 13 files changed, 73 insertions(+), 35 deletions(-) diff --git a/Strategic/Strategic Town Loyalty.cpp b/Strategic/Strategic Town Loyalty.cpp index 46bb6f762..d07a9c1c3 100644 --- a/Strategic/Strategic Town Loyalty.cpp +++ b/Strategic/Strategic Town Loyalty.cpp @@ -102,14 +102,14 @@ // town loyalty table -TOWN_LOYALTY gTownLoyalty[ NUM_TOWNS ]; +TOWN_LOYALTY gTownLoyalty[ MAX_TOWNS ]; // town name and locations arrays, for town theft and what not INT32 pTownNamesList[ 40 ]; INT32 pTownLocationsList[ 40 ]; -INT32 iTownDistances[ NUM_TOWNS ][ NUM_TOWNS ]; +INT32 iTownDistances[ MAX_TOWNS ][ MAX_TOWNS ]; #define BASIC_COST_FOR_CIV_MURDER (10 * GAIN_PTS_PER_LOYALTY_PT) @@ -129,7 +129,7 @@ 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 ]; // = +UINT8 gubTownRebelSentiment[ MAX_TOWNS ]; // = //{ // 0, // not a town - blank sector index // 90, // OMERTA, - They ARE the rebels!!! @@ -146,7 +146,7 @@ UINT8 gubTownRebelSentiment[ NUM_TOWNS ]; // = // 35, // CHITZENA, - Artificially high 'cause there's not enough fights near it to get the loyalty up otherwise //}; -BOOLEAN gfTownUsesLoyalty[ NUM_TOWNS ];// = +BOOLEAN gfTownUsesLoyalty[ MAX_TOWNS ];// = //{ // FALSE, // not a town - blank sector index // TRUE , // OMERTA @@ -172,7 +172,7 @@ extern UINT32 guiNumWorldItems; // preprocess sector for mercs in it extern BOOLEAN fSectorsWithSoldiers[ MAP_WORLD_X * MAP_WORLD_X ][ 4 ]; -extern CHAR16 pTownNames[NUM_TOWNS][MAX_TOWN_NAME_LENGHT]; +extern CHAR16 pTownNames[MAX_TOWNS][MAX_TOWN_NAME_LENGHT]; @@ -1295,7 +1295,7 @@ void WriteOutDistancesBetweenTowns( void ) hFileHandle = FileOpen( "BinaryData\\TownDistances.dat", FILE_ACCESS_WRITE|FILE_OPEN_ALWAYS, FALSE ); - FileWrite( hFileHandle, &( iTownDistances ), ( sizeof( INT32 ) * NUM_TOWNS * NUM_TOWNS ), NULL ); + FileWrite( hFileHandle, &( iTownDistances ), ( sizeof( INT32 ) * MAX_TOWNS * MAX_TOWNS ), NULL ); // close file FileClose( hFileHandle ); @@ -1360,7 +1360,7 @@ void ReadInDistancesBetweenTowns( void ) hFileHandle = FileOpen( "BinaryData\\TownDistances.dat", FILE_ACCESS_READ, FALSE ); - FileRead( hFileHandle, &( iTownDistances ), ( sizeof( INT32 ) * NUM_TOWNS * NUM_TOWNS ), NULL ); + FileRead( hFileHandle, &( iTownDistances ), ( sizeof( INT32 ) * MAX_TOWNS * MAX_TOWNS ), NULL ); // close file FileClose( hFileHandle ); @@ -1432,8 +1432,8 @@ BOOLEAN SaveStrategicTownLoyaltyToSaveGameFile( HWFILE hFile ) UINT32 uiNumBytesWritten; //Save the Town Loyalty - FileWrite( hFile, gTownLoyalty, sizeof( TOWN_LOYALTY ) * NUM_TOWNS, &uiNumBytesWritten ); - if( uiNumBytesWritten != sizeof( TOWN_LOYALTY ) * NUM_TOWNS ) + FileWrite( hFile, gTownLoyalty, sizeof( TOWN_LOYALTY ) * MAX_TOWNS, &uiNumBytesWritten ); + if( uiNumBytesWritten != sizeof( TOWN_LOYALTY ) * MAX_TOWNS ) { return( FALSE ); } @@ -1446,8 +1446,8 @@ BOOLEAN LoadStrategicTownLoyaltyFromSavedGameFile( HWFILE hFile ) UINT32 uiNumBytesRead; //Restore the Town Loyalty - FileRead( hFile, gTownLoyalty, sizeof( TOWN_LOYALTY ) * NUM_TOWNS, &uiNumBytesRead ); - if( uiNumBytesRead != sizeof( TOWN_LOYALTY ) * NUM_TOWNS ) + FileRead( hFile, gTownLoyalty, sizeof( TOWN_LOYALTY ) * MAX_TOWNS, &uiNumBytesRead ); + if( uiNumBytesRead != sizeof( TOWN_LOYALTY ) * MAX_TOWNS ) { return( FALSE ); } @@ -1678,7 +1678,7 @@ void AffectAllTownsLoyaltyByDistanceFrom( INT32 iLoyaltyChange, INT16 sSectorX, INT8 bTownId; UINT32 uiIndex; INT32 iThisDistance; - INT32 iShortestDistance[NUM_TOWNS]; + INT32 iShortestDistance[MAX_TOWNS]; INT32 iPercentAdjustment; INT32 iDistanceAdjustedLoyalty; diff --git a/Strategic/Strategic Town Loyalty.h b/Strategic/Strategic Town Loyalty.h index e28cb8e83..0e7fbedbf 100644 --- a/Strategic/Strategic Town Loyalty.h +++ b/Strategic/Strategic Town Loyalty.h @@ -81,14 +81,14 @@ typedef struct TOWN_LOYALTY // the loyalty variables for each town -extern TOWN_LOYALTY gTownLoyalty[ NUM_TOWNS ]; +extern TOWN_LOYALTY gTownLoyalty[ MAX_TOWNS ]; // town names list extern INT32 pTownNamesList[]; // town locations list extern INT32 pTownLocationsList[]; // whether town maintains/displays loyalty or not -extern BOOLEAN gfTownUsesLoyalty[ NUM_TOWNS ]; +extern BOOLEAN gfTownUsesLoyalty[ MAX_TOWNS ]; diff --git a/Strategic/Town Militia.cpp b/Strategic/Town Militia.cpp index 0e90941e6..a9070cdcc 100644 --- a/Strategic/Town Militia.cpp +++ b/Strategic/Town Militia.cpp @@ -50,7 +50,7 @@ INT16 gsUnpaidStrategicSector[ MAX_CHARACTER_COUNT ]; extern BOOLEAN fSelectedListOfMercsForMapScreen[ MAX_CHARACTER_COUNT ]; // towns with militia training allowed -BOOLEAN gfMilitiaAllowedInTown[NUM_TOWNS] = +BOOLEAN gfMilitiaAllowedInTown[MAX_TOWNS] = { 0, // blank sector 0, // omerta diff --git a/Strategic/mapscreen.h b/Strategic/mapscreen.h index 38c64d3ad..3d20c50eb 100644 --- a/Strategic/mapscreen.h +++ b/Strategic/mapscreen.h @@ -10,6 +10,8 @@ #define MAX_TOWN_NAME_LENGHT 32 +#define MAX_TOWNS 13 + // Sector name identifiers enum Towns { @@ -27,9 +29,11 @@ enum Towns MEDUNA, CHITZENA, - NUM_TOWNS + //NUM_TOWNS } ; +extern INT8 NUM_TOWNS; + #define FIRST_TOWN OMERTA //#define PALACE NUM_TOWNS diff --git a/Strategic/strategicmap.cpp b/Strategic/strategicmap.cpp index d5fd9fc61..b84ce7e52 100644 --- a/Strategic/strategicmap.cpp +++ b/Strategic/strategicmap.cpp @@ -347,11 +347,14 @@ void CrippledVersionFailureToLoadMapCheck(); #include "tiledat.h" #endif -extern UINT8 gubTownRebelSentiment[ NUM_TOWNS ]; -extern BOOLEAN gfTownUsesLoyalty[ NUM_TOWNS ]; -extern BOOLEAN gfMilitiaAllowedInTown[NUM_TOWNS]; +INT8 NUM_TOWNS; + +extern UINT8 gubTownRebelSentiment[ MAX_TOWNS ]; +extern BOOLEAN gfTownUsesLoyalty[ MAX_TOWNS ]; +extern BOOLEAN gfMilitiaAllowedInTown[MAX_TOWNS]; #define MAX_CHAR_DATA_LENGTH 500 +#define INVALID_TOWN_INDEX -1 typedef enum { @@ -393,6 +396,7 @@ typedef struct INT8 szCharData[MAX_CHAR_DATA_LENGTH+1]; cityInfo curCityInfo; UINT32 uiRowNumber; + UINT32 uiHighestIndex; UINT32 currentDepth; UINT32 maxReadDepth; @@ -439,6 +443,7 @@ citytableStartElementHandle(void *userData, const char *name, const char **atts) memset(pTownPoints,0,sizeof(pTownPoints)); memset(gfTownUsesLoyalty,0,sizeof(gfTownUsesLoyalty)); memset(gubTownRebelSentiment,0,sizeof(gubTownRebelSentiment)); + memset(gfMilitiaAllowedInTown,0,sizeof(gfMilitiaAllowedInTown)); pData->maxReadDepth++; //we are not skipping this element } @@ -526,6 +531,8 @@ citytableCharacterDataHandle(void *userData, const char *str, int len) static void XMLCALL citytableEndElementHandle(void *userData, const char *name) { + FILE *pDebug; + citytableParseData * pData = (citytableParseData *) userData; if(pData->currentDepth <= pData->maxReadDepth) //we're at the end of an element that we've been reading @@ -560,24 +567,49 @@ citytableEndElementHandle(void *userData, const char *name) else if(strcmp(name, "CITYLIST") == 0 && pData->curElement == CITYTABLE_ELEMENT_CITYLIST) { pData->curElement = CITYTABLE_ELEMENT_CITYINFO; + + NUM_TOWNS = pData->uiHighestIndex + 1; + pDebug = fopen("towns.log", "a+t"); + fprintf(pDebug, "NUM_TOWNS = %d\n", NUM_TOWNS); + fclose(pDebug); } else if(strcmp(name, "CITY") == 0 && pData->curElement == CITYTABLE_ELEMENT_CITY) { pData->curElement = CITYTABLE_ELEMENT_CITYLIST; - 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; - gfMilitiaAllowedInTown[pData->curCityInfo.uiIndex ] = pData->curCityInfo.townMilitiaAllowed; - - mbstowcs( pTownNames[pData->curCityInfo.uiIndex], pData->curCityInfo.cityName, MAX_TOWN_NAME_LENGHT); + if ( pData->curCityInfo.uiIndex != INVALID_TOWN_INDEX ) + { + 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; + gfMilitiaAllowedInTown[pData->curCityInfo.uiIndex ] = pData->curCityInfo.townMilitiaAllowed; + mbstowcs( pTownNames[pData->curCityInfo.uiIndex], pData->curCityInfo.cityName, MAX_TOWN_NAME_LENGHT); + } } else if(strcmp(name, "uiIndex") == 0 && pData->curElement == CITYTABLE_ELEMENT_INDEX) { pData->curElement = CITYTABLE_ELEMENT_CITY; pData->curCityInfo.uiIndex = atol(pData->szCharData); + pDebug = fopen("towns.log", "a+t"); + fprintf(pDebug, "Got Index %d\n", pData->curCityInfo.uiIndex ); + fprintf(pDebug, "Highest = %d, Current = %d\n", pData->uiHighestIndex, pData->curCityInfo.uiIndex); + fclose(pDebug); + if ( !pData->curCityInfo.uiIndex || pData->curCityInfo.uiIndex >= MAX_TOWNS ) + { + pData->curCityInfo.uiIndex = INVALID_TOWN_INDEX; + pDebug = fopen("towns.log", "a+t"); + fprintf(pDebug, "Index Discarded\n"); + fclose(pDebug); + } + else if ( pData->curCityInfo.uiIndex > pData->uiHighestIndex ) + { + pData->uiHighestIndex = pData->curCityInfo.uiIndex; + pDebug = fopen("towns.log", "a+t"); + fprintf(pDebug, "Set new Highest = %d\n", pData->uiHighestIndex); + fclose(pDebug); + } } else if(strcmp(name, "townName") == 0 && pData->curElement == CITYTABLE_ELEMENT_NAME) { @@ -658,7 +690,8 @@ BOOLEAN WriteInStrategicMapSectorTownNames(STR fileName) return( FALSE ); { - UINT32 x, y, cnt; + UINT32 x, y; + INT8 cnt; FilePrintf(hFile,"\r\n"); @@ -752,6 +785,7 @@ BOOLEAN ReadInStrategicMapSectorTownNames(STR fileName) memset(&pData,0,sizeof(pData)); + NUM_TOWNS = 0; XML_SetUserData(parser, &pData); diff --git a/Utils/Text.h b/Utils/Text.h index dfd9192e2..0fce6f2be 100644 --- a/Utils/Text.h +++ b/Utils/Text.h @@ -27,7 +27,7 @@ extern STR16 pLongAttributeStrings[]; extern STR16 pContractStrings[]; extern STR16 pAssignmentStrings[]; extern STR16 pConditionStrings[]; -extern CHAR16 pTownNames[NUM_TOWNS][MAX_TOWN_NAME_LENGHT]; // Lesh: look mapscreen.h for definitions +extern CHAR16 pTownNames[MAX_TOWNS][MAX_TOWN_NAME_LENGHT]; // Lesh: look mapscreen.h for definitions extern STR16 pPersonnelScreenStrings[]; extern STR16 pPersonnelTitle[]; extern STR16 pUpperLeftMapScreenStrings[]; diff --git a/Utils/_DutchText.cpp b/Utils/_DutchText.cpp index 34e40961b..e799c8154 100644 --- a/Utils/_DutchText.cpp +++ b/Utils/_DutchText.cpp @@ -290,7 +290,7 @@ UINT16 Message[][STRING_LENGTH] = // the names of the towns in the game -CHAR16 pTownNames[NUM_TOWNS][MAX_TOWN_NAME_LENGHT] = +CHAR16 pTownNames[MAX_TOWNS][MAX_TOWN_NAME_LENGHT] = { L"", L"Omerta", diff --git a/Utils/_EnglishText.cpp b/Utils/_EnglishText.cpp index 7367da614..65007a528 100644 --- a/Utils/_EnglishText.cpp +++ b/Utils/_EnglishText.cpp @@ -305,7 +305,7 @@ UINT16 Message[][STRING_LENGTH] = // the names of the towns in the game -CHAR16 pTownNames[NUM_TOWNS][MAX_TOWN_NAME_LENGHT] = +CHAR16 pTownNames[MAX_TOWNS][MAX_TOWN_NAME_LENGHT] = { L"", L"Omerta", diff --git a/Utils/_FrenchText.cpp b/Utils/_FrenchText.cpp index 6cc11eac2..489df31fd 100644 --- a/Utils/_FrenchText.cpp +++ b/Utils/_FrenchText.cpp @@ -296,7 +296,7 @@ UINT16 Message[][STRING_LENGTH] = // the names of the towns in the game -CHAR16 pTownNames[NUM_TOWNS][MAX_TOWN_NAME_LENGHT] = +CHAR16 pTownNames[MAX_TOWNS][MAX_TOWN_NAME_LENGHT] = { L"", L"Omerta", diff --git a/Utils/_GermanText.cpp b/Utils/_GermanText.cpp index d1bb8cde5..2c592e209 100644 --- a/Utils/_GermanText.cpp +++ b/Utils/_GermanText.cpp @@ -295,7 +295,7 @@ UINT16 Message[][STRING_LENGTH] = L"kein Einzelschuss", }; -CHAR16 pTownNames[NUM_TOWNS][MAX_TOWN_NAME_LENGHT] = +CHAR16 pTownNames[MAX_TOWNS][MAX_TOWN_NAME_LENGHT] = { L"", L"Omerta", diff --git a/Utils/_ItalianText.cpp b/Utils/_ItalianText.cpp index 3cb70e445..24c449283 100644 --- a/Utils/_ItalianText.cpp +++ b/Utils/_ItalianText.cpp @@ -289,7 +289,7 @@ UINT16 Message[][STRING_LENGTH] = // the names of the towns in the game -CHAR16 pTownNames[NUM_TOWNS][MAX_TOWN_NAME_LENGHT] = +CHAR16 pTownNames[MAX_TOWNS][MAX_TOWN_NAME_LENGHT] = { L"", L"Omerta", diff --git a/Utils/_PolishText.cpp b/Utils/_PolishText.cpp index 8ae7c98b1..6a7e565dd 100644 --- a/Utils/_PolishText.cpp +++ b/Utils/_PolishText.cpp @@ -290,7 +290,7 @@ UINT16 Message[][STRING_LENGTH] = // the names of the towns in the game -CHAR16 pTownNames[NUM_TOWNS][MAX_TOWN_NAME_LENGHT] = +CHAR16 pTownNames[MAX_TOWNS][MAX_TOWN_NAME_LENGHT] = { L"", L"Omerta", diff --git a/Utils/_RussianText.cpp b/Utils/_RussianText.cpp index d81580668..fabbce118 100644 --- a/Utils/_RussianText.cpp +++ b/Utils/_RussianText.cpp @@ -297,7 +297,7 @@ UINT16 Message[][STRING_LENGTH] = // the names of the towns in the game -CHAR16 pTownNames[NUM_TOWNS][MAX_TOWN_NAME_LENGHT] = +CHAR16 pTownNames[MAX_TOWNS][MAX_TOWN_NAME_LENGHT] = { L"", L"Îìåðòà",