From 881ff0f5c23b1a0d1e99d6685b358ea62b862783 Mon Sep 17 00:00:00 2001 From: Lesh Date: Sat, 30 Sep 2006 12:27:38 +0000 Subject: [PATCH] - xml-files migration - added Judge's movement costs externalization with minor tweaks git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@583 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Init.cpp | 9 +- Strategic/Campaign Init.cpp | 2 +- Strategic/Strategic Movement Costs.cpp | 738 +++++++++++++++++++++++-- Strategic/Strategic Movement.h | 2 +- Tactical/XML.h | 57 +- 5 files changed, 724 insertions(+), 84 deletions(-) diff --git a/Init.cpp b/Init.cpp index 36c7a273..3ae9d6be 100644 --- a/Init.cpp +++ b/Init.cpp @@ -352,6 +352,10 @@ BOOLEAN LoadExternalGameplayData(STR directoryName) if(!ReadInMapStructure(fileName)) return FALSE; + // Lesh: Strategic movement costs will be read in Strategic\Strategic Movement Costs.cpp, + // function BOOLEAN InitStrategicMovementCosts(); + // It is called several times from various places and acts after clearing SectorInfo array + strcpy(fileName, directoryName); strcat(fileName, EXPLOSIONDATAFILENAME); if(!ReadInExplosionDataStats(fileName)) @@ -409,7 +413,10 @@ UINT32 InitializeJA2(void) } //needs to be called here to init the SectorInfo struct - InitStrategicMovementCosts( ); + if ( !InitStrategicMovementCosts( ) ) + { + return( ERROR_SCREEN ); + } // Init tactical engine if ( !InitTacticalEngine( ) ) diff --git a/Strategic/Campaign Init.cpp b/Strategic/Campaign Init.cpp index e9bf4490..a4f8026e 100644 --- a/Strategic/Campaign Init.cpp +++ b/Strategic/Campaign Init.cpp @@ -14,7 +14,7 @@ #include "Strategic AI.h" #endif -extern void InitStrategicMovementCosts(); +extern BOOLEAN InitStrategicMovementCosts(); void InitKnowFacilitiesFlags( ); UNDERGROUND_SECTORINFO* gpUndergroundSectorInfoTail = NULL; diff --git a/Strategic/Strategic Movement Costs.cpp b/Strategic/Strategic Movement Costs.cpp index ca539e2e..87b78f36 100644 --- a/Strategic/Strategic Movement Costs.cpp +++ b/Strategic/Strategic Movement Costs.cpp @@ -1,11 +1,663 @@ #ifdef PRECOMPILEDHEADERS #include "Strategic All.h" + #include "XML.h" #else #include "Campaign Types.h" #include "Queen Command.h" #include "Strategic Movement.h" + #include "XML.h" #endif +typedef enum +{ + SMCTABLE_ELEMENT_NONE = 0, + SMCTABLE_ELEMENT_STRATEGICMOVEMENTCOSTS, + SMCTABLE_ELEMENT_SECTORTRAVERSAL, + SMCTABLE_ELEMENT_SECTOR, + SMCTABLE_ELEMENT_TRAVELRATING, + SMCTABLE_ELEMENT_TRAVELTYPE, + SMCTABLE_ELEMENT_SHORTNAME, +} SMCTABLE_PARSE_STAGE; + +typedef struct +{ + SMCTABLE_PARSE_STAGE curElement; + INT8 szCharData[MAX_CHAR_DATA_LENGTH+1]; + UINT32 currentDepth; + UINT32 maxReadDepth; + + //INT8 szCustomShortname[MAX_SECTORNAME_LENGTH+1]; + UINT32 uiRowNumber; + UINT32 uiColNumber; + UINT32 travRating; + UINT32 travNorth; + UINT32 travEast; + UINT32 travSouth; + UINT32 travWest; + UINT32 travHere; + +} smctableParseData; + +/** Process the opening tag in this expat callback. + */ +static void XMLCALL +smctableStartElementHandle(void *userData, const char *name, const char **atts) +{ + smctableParseData * pData = (smctableParseData *) userData; + //FILE *outfile = fopen("smc.log", "at"); + + if(pData->currentDepth <= pData->maxReadDepth) //are we reading this element? + { + if(strcmp(name, "StrategicMovementCosts") == 0 && pData->curElement == SMCTABLE_ELEMENT_NONE) + { + // Enter + pData->curElement = SMCTABLE_ELEMENT_STRATEGICMOVEMENTCOSTS; + pData->maxReadDepth++; //we are not skipping this element + //fprintf (outfile, "Entering Strategic Movement Costs\n"); + } + else if(strcmp(name, "SectorTraversal") == 0 && pData->curElement == SMCTABLE_ELEMENT_STRATEGICMOVEMENTCOSTS) + { + pData->curElement = SMCTABLE_ELEMENT_SECTORTRAVERSAL; + pData->maxReadDepth++; //we are not skipping this element + //fprintf (outfile, "Exiting Sector Traversal\n"); + } + else if(strcmp(name, "Sector") == 0 && pData->curElement == SMCTABLE_ELEMENT_SECTORTRAVERSAL) + { + UINT32 uiAttrIndex; + pData->curElement = SMCTABLE_ELEMENT_SECTOR; + // Extract the x and y attributes to use as the sector co-ordinate + for(uiAttrIndex = 0;atts[uiAttrIndex] != NULL;uiAttrIndex += 2) + { + if(strcmp(atts[uiAttrIndex], "y") == 0) + { + if ( isalpha(atts[uiAttrIndex+1][0]) ) + { + pData->uiRowNumber = (UINT32)(atts[uiAttrIndex+1][0] - 0x40); + } + else + { + pData->uiRowNumber = atol(atts[uiAttrIndex+1]); + } + } + else if(strcmp(atts[uiAttrIndex], "x") == 0) + { + pData->uiColNumber = atol(atts[uiAttrIndex+1]); + } + } + //fprintf(outfile, "Extracted sector co-ordinates: [x=%d, y=%d]\n", pData->uiColNumber, pData->uiRowNumber); + // A simple test to try and stop bogus entries + if(pData->uiRowNumber <= 16 && pData->uiColNumber <= 16) + { + pData->maxReadDepth++; //we are not skipping this element + //fprintf (outfile, "Entering Sector\n"); + } + } + else if(strcmp(name, "TravelRating") == 0 && pData->curElement == SMCTABLE_ELEMENT_SECTOR) + { + pData->curElement = SMCTABLE_ELEMENT_TRAVELRATING; + pData->maxReadDepth++; //we are not skipping this element + //fprintf (outfile, "Entering Traversal Rating\n"); + } + else if((strcmp(name, "North") == 0 || strcmp(name, "East") == 0 || strcmp(name, "South") == 0 || strcmp(name, "West") == 0 || strcmp(name, "Here") == 0) + && pData->curElement == SMCTABLE_ELEMENT_SECTOR) + { + pData->curElement = SMCTABLE_ELEMENT_TRAVELTYPE; + pData->maxReadDepth++; //we are not skipping this element + //fprintf (outfile, "Entering Traversal Type\n"); + } + else if(strcmp(name, "Shortname") == 0 && pData->curElement == SMCTABLE_ELEMENT_SECTOR) + { + pData->curElement = SMCTABLE_ELEMENT_SHORTNAME; + pData->maxReadDepth++; //we are not skipping this element + //fprintf (outfile, "Entering Traversal Rating\n"); + } + pData->szCharData[0] = '\0'; + } + pData->currentDepth++; + //fclose(outfile); +} + +/** Process any text content in this callback. + */ +static void XMLCALL +smctableCharacterDataHandle(void *userData, const char *str, int len) +{ + smctableParseData * pData = (smctableParseData *) 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))); +} + +/** Process the closing tag in this expat callback. + */ +static void XMLCALL +smctableEndElementHandle(void *userData, const char *name) +{ + smctableParseData * pData = (smctableParseData *) userData; + + //FILE *outfile = fopen("C:/JA2/debug.log", "a"); + //fprintf (outfile, "TOWN INDEX: %d\n", TOWN); + //fprintf (outfile, "Encountered Close Tag: %s\n", name); + + if(pData->currentDepth <= pData->maxReadDepth) //we're at the end of an element that we've been reading + { + if(strcmp(name, "StrategicMovementCosts") == 0 && pData->curElement == SMCTABLE_ELEMENT_STRATEGICMOVEMENTCOSTS) + { + //fprintf (outfile, "Exiting Strategic Movement Costs\n"); + pData->curElement = SMCTABLE_ELEMENT_NONE; + } + else if(strcmp(name, "SectorTraversal") == 0 && pData->curElement == SMCTABLE_ELEMENT_SECTORTRAVERSAL) + { + //fprintf (outfile, "Exiting Sector Traversal\n"); + pData->curElement = SMCTABLE_ELEMENT_STRATEGICMOVEMENTCOSTS; + } + else if(strcmp(name, "Sector") == 0 && pData->curElement == SMCTABLE_ELEMENT_SECTOR) + { + // We've read in a complete section. Process the contents of pData into the + // SectionInfo array + SECTORINFO *pSector; + UINT32 sec_index = ((pData->uiRowNumber - 1) * 16) + (pData->uiColNumber - 1); + pSector = &SectorInfo[ ((pData->uiRowNumber - 1) * 16) + (pData->uiColNumber - 1) ]; + pSector->ubTravelRating = pData->travRating; + pSector->ubTraversability[ NORTH_STRATEGIC_MOVE ] = pData->travNorth; + pSector->ubTraversability[ EAST_STRATEGIC_MOVE ] = pData->travEast; + pSector->ubTraversability[ SOUTH_STRATEGIC_MOVE ] = pData->travSouth; + pSector->ubTraversability[ WEST_STRATEGIC_MOVE ] = pData->travWest; + pSector->ubTraversability[ THROUGH_STRATEGIC_MOVE ] = pData->travHere; + //strncpy(pSector->szCustomShortname, pData->szCustomShortname, MAX_SECTORNAME_LENGTH); + //fprintf (outfile, "Added SectorInfo #%d: y %d, x %d, name: %s, tr %d, n %d, e %d, s %d, w %d, h %d\n", + // sec_index, pData->uiRowNumber, pData->uiColNumber, pData->szCustomShortname, + // pSector->ubTravelRating, pSector->ubTraversability[ NORTH_STRATEGIC_MOVE ], + // pSector->ubTraversability[ EAST_STRATEGIC_MOVE ], + // pSector->ubTraversability[ SOUTH_STRATEGIC_MOVE ], + // pSector->ubTraversability[ WEST_STRATEGIC_MOVE ], + // pSector->ubTraversability[ THROUGH_STRATEGIC_MOVE ]); + + // And finish the sector. + //fprintf (outfile, "Exiting Sector\n"); + //pData->szCustomShortname[0] = '\0'; + pData->curElement = SMCTABLE_ELEMENT_SECTORTRAVERSAL; + } + else if(strcmp(name, "TravelRating") == 0 && pData->curElement == SMCTABLE_ELEMENT_TRAVELRATING) + { + // Convert the travel rating to an integer + pData->travRating = atol(pData->szCharData); + // Done, done, and I'm on to the next one. + //fprintf (outfile, "Extracted traversal rating: %d\n", pData->travRating); + //fprintf (outfile, "Exiting Traversal Rating\n"); + pData->curElement = SMCTABLE_ELEMENT_SECTOR; + } + else if(pData->curElement == SMCTABLE_ELEMENT_TRAVELTYPE) + { + // Determine the traversal type from the string in pData + UINT32 trav_type; + //fprintf (outfile, "Extracted terrain type: %s\n", pData->szCharData); + if(strcmp(pData->szCharData, "TOWN") == 0) + { + trav_type = TOWN; + } + else if(strcmp(pData->szCharData, "ROAD") == 0) + { + trav_type = ROAD; + } + else if(strcmp(pData->szCharData, "PLAINS") == 0) + { + trav_type = PLAINS; + } + else if(strcmp(pData->szCharData, "SAND") == 0) + { + trav_type = SAND; + } + else if(strcmp(pData->szCharData, "SPARSE") == 0) + { + trav_type = SPARSE; + } + else if(strcmp(pData->szCharData, "DENSE") == 0) + { + trav_type = DENSE; + } + else if(strcmp(pData->szCharData, "SWAMP") == 0) + { + trav_type = SWAMP; + } + else if(strcmp(pData->szCharData, "WATER") == 0) + { + trav_type = WATER; + } + else if(strcmp(pData->szCharData, "HILLS") == 0) + { + trav_type = HILLS; + } + else if(strcmp(pData->szCharData, "NS_RIVER") == 0) + { + trav_type = NS_RIVER; + } + else if(strcmp(pData->szCharData, "EW_RIVER") == 0) + { + trav_type = EW_RIVER; + } + else if(strcmp(pData->szCharData, "EDGEOFWORLD") == 0) + { + trav_type = EDGEOFWORLD; + } + else if(strcmp(pData->szCharData, "TROPICS") == 0) + { + trav_type = TROPICS; + } + else if(strcmp(pData->szCharData, "FARMLAND") == 0) + { + trav_type = FARMLAND; + } + else if(strcmp(pData->szCharData, "PLAINS_ROAD") == 0) + { + trav_type = PLAINS_ROAD; + } + else if(strcmp(pData->szCharData, "SPARSE_ROAD") == 0) + { + trav_type = SPARSE; + } + else if(strcmp(pData->szCharData, "FARMLAND_ROAD") == 0) + { + trav_type = FARMLAND_ROAD; + } + else if(strcmp(pData->szCharData, "TROPICS_ROAD") == 0) + { + trav_type = TROPICS_ROAD; + } + else if(strcmp(pData->szCharData, "DENSE_ROAD") == 0) + { + trav_type = DENSE_ROAD; + } + else if(strcmp(pData->szCharData, "COASTAL") == 0) + { + trav_type = COASTAL; + } + else if(strcmp(pData->szCharData, "HILLS_ROAD") == 0) + { + trav_type = HILLS_ROAD; + } + else if(strcmp(pData->szCharData, "COASTAL_ROAD") == 0) + { + trav_type = COASTAL_ROAD; + } + else if(strcmp(pData->szCharData, "SAND_ROAD") == 0) + { + trav_type = SAND_ROAD; + } + else if(strcmp(pData->szCharData, "SWAMP_ROAD") == 0) + { + trav_type = SWAMP_ROAD; + } + else + { + trav_type = GROUNDBARRIER; + } + // Now assign it to the correct directory using the close tag as a guide + if(strcmp(name, "North") == 0) + { + pData->travNorth = trav_type; + } + else if(strcmp(name, "East") == 0) + { + pData->travEast = trav_type; + } + else if(strcmp(name, "South") == 0) + { + pData->travSouth = trav_type; + } + else if(strcmp(name, "West") == 0) + { + pData->travWest = trav_type; + } + else if(strcmp(name, "Here") == 0) + { + pData->travHere = trav_type; + } + else + { + // Bogus Traversal Reference + Assert(FALSE); + } + //fprintf (outfile, "Extracted %s traversal: %d\n", name, trav_type); + //fprintf (outfile, "Exiting Traversal Type\n"); + pData->curElement = SMCTABLE_ELEMENT_SECTOR; + } + //else if(strcmp(name, "Shortname") == 0 && pData->curElement == SMCTABLE_ELEMENT_SHORTNAME) + //{ + // // Copy this string into the pTownNames array + // //fprintf(outfile, "Element data: %s\n", pData->szCharData); + // strncpy(pData->szCustomShortname, pData->szCharData, MAX_SECTORNAME_LENGTH); + // //fprintf(outfile, "Shortname extracted: %s\n", pData->szCustomShortname); + // pData->curElement = SMCTABLE_ELEMENT_SECTOR; + // //fprintf(outfile, "Exiting Shortname\n"); + //} + + pData->maxReadDepth--; + } + pData->currentDepth--; + + //fclose (outfile); +} + + +BOOLEAN ReadInStrategicMovementCosts(STR fileName) +{ + HWFILE hFile; + UINT32 uiBytesRead; + UINT32 uiFSize; + CHAR8 * lpcBuffer; + XML_Parser parser = XML_ParserCreate(NULL); + + smctableParseData pData; + + // Open weapons file + hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE ); + if ( !hFile ) + { + return( FALSE ); + } + + 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 ); + + // Setup expat callbacks + XML_SetElementHandler(parser, smctableStartElementHandle, smctableEndElementHandle); + XML_SetCharacterDataHandler(parser, smctableCharacterDataHandle); + + memset(&pData,0,sizeof(pData)); + XML_SetUserData(parser, &pData); + + if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) + { + CHAR8 errorBuf[511]; + + sprintf(errorBuf, "XML Parser Error in StrategicMovementCosts.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 WriteInStrategicMovementCosts(STR fileName) +{ + // Lets output the current Strategic map format using the XML structure I've devised. + FILE *outfile = fopen(fileName, "wt"); + + UINT32 x, y, dir_type, trav_type; + SECTORINFO *pSector; + + fprintf (outfile, "\n"); + fprintf (outfile, "\t\n"); + for(y = 1;y <= 16;y++) + { + for(x = 1;x <= 16; x++) + { + pSector = &SectorInfo[ ((y - 1) * 16) + (x - 1) ]; + fprintf (outfile, "\t\t\n",(y+0x40),x); + //if(pSector->szCustomShortname != NULL) + //{ + // fprintf (outfile, "\t\t\t%s\n",pSector->szCustomShortname); + //} + fprintf (outfile, "\t\t\t%d\n",pSector->ubTravelRating); + // Direction Types: + // 0. NORTH + // 1. EAST + // 2. SOUTH + // 3. WEST + // 4. THROUGH + for(dir_type = 0; dir_type < 5; dir_type++) + { + trav_type = pSector->ubTraversability[ dir_type ]; + + // Output the traverse direction as the XML tag + switch(dir_type) + { + case NORTH_STRATEGIC_MOVE: + fprintf (outfile, "\t\t\t"); + break; + case EAST_STRATEGIC_MOVE: + fprintf (outfile, "\t\t\t"); + break; + case SOUTH_STRATEGIC_MOVE: + fprintf (outfile, "\t\t\t"); + break; + case WEST_STRATEGIC_MOVE: + fprintf (outfile, "\t\t\t"); + break; + default: + fprintf (outfile, "\t\t\t"); + } + // Output the traversal type + switch(trav_type) + { + case TOWN: + fprintf (outfile, "TOWN"); + break; + case ROAD: + fprintf (outfile, "ROAD"); + break; + case PLAINS: + fprintf (outfile, "PLAINS"); + break; + case SAND: + fprintf (outfile, "SAND"); + break; + case SPARSE: + fprintf (outfile, "SPARSE"); + break; + case DENSE: + fprintf (outfile, "DENSE"); + break; + case SWAMP: + fprintf (outfile, "SWAMP"); + break; + case WATER: + fprintf (outfile, "WATER"); + break; + case HILLS: + fprintf (outfile, "HILLS"); + break; + case GROUNDBARRIER: + fprintf (outfile, "GROUNDBARRIER"); + break; + case NS_RIVER: + fprintf (outfile, "NS_RIVER"); + break; + case EW_RIVER: + fprintf (outfile, "EW_RIVER"); + break; + case EDGEOFWORLD: + fprintf (outfile, "EDGEOFWORLD"); + break; + case TROPICS: + fprintf (outfile, "TROPICS"); + break; + case FARMLAND: + fprintf (outfile, "FARMLAND"); + break; + case PLAINS_ROAD: + fprintf (outfile, "PLAINS_ROAD"); + break; + case SPARSE_ROAD: + fprintf (outfile, "SPARSE_ROAD"); + break; + case FARMLAND_ROAD: + fprintf (outfile, "FARMLAND_ROAD"); + break; + case TROPICS_ROAD: + fprintf (outfile, "TROPICS_ROAD"); + break; + case DENSE_ROAD: + fprintf (outfile, "DENSE_ROAD"); + break; + case COASTAL: + fprintf (outfile, "COASTAL"); + break; + case HILLS_ROAD: + fprintf (outfile, "HILLS_ROAD"); + break; + case COASTAL_ROAD: + fprintf (outfile, "COASTAL_ROAD"); + break; + case SAND_ROAD: + fprintf (outfile, "SAND_ROAD"); + break; + case SWAMP_ROAD: + fprintf (outfile, "SWAMP_ROAD"); + break; + default: + fprintf (outfile, "%d", trav_type); + } + // Output the traverse direction as the closing tag + switch(dir_type) + { + case NORTH_STRATEGIC_MOVE: + fprintf (outfile, "\n"); + break; + case EAST_STRATEGIC_MOVE: + fprintf (outfile, "\n"); + break; + case SOUTH_STRATEGIC_MOVE: + fprintf (outfile, "\n"); + break; + case WEST_STRATEGIC_MOVE: + fprintf (outfile, "\n"); + break; + default: + fprintf (outfile, "\n"); + } + } + fprintf (outfile, "\t\t\n"); + } + } + fprintf (outfile, "\t\n"); + fprintf (outfile, "\n"); + + fclose(outfile); + + return (TRUE); +} + +//void InitStrategicMovementCosts() +//{ +// // Init Traversal Data +// +// // Testing Externalization +// //#ifdef JA2TESTVERSION +// //FILE *outfile = fopen("C:/JA2/debug.log", "a"); +// { //Simply make sure all shared borders between sectors match. +// INT32 x,y; +// OutputDebugString( "STRATEGIC MOVE COSTS: Testing validity of data (okay if no following debug msgs)...\n"); +// for( y = 1; y <= 16; y++ ) for( x = 1; x <= 16; x++ ) +// { +// if( y > 1 ) +// { +// if( SectorInfo[ SECTOR(x,y) ].ubTraversability[ NORTH_STRATEGIC_MOVE ] != +// SectorInfo[ SECTOR(x,y-1) ].ubTraversability[ SOUTH_STRATEGIC_MOVE ] ) +// { //north +// OutputDebugString( (LPCSTR)String( "STRATEGIC MOVE COSTS: North mismatch for sector %c%d\n", y+'A'-1, x ) ); +// //fprintf(outfile, "STRATEGIC MOVE COSTS: North mismatch for sector %c%d\n", y+'A'-1, x); +// } +// if( y == 16 && SectorInfo[ SECTOR(x,y) ].ubTraversability[ SOUTH_STRATEGIC_MOVE ] != EDGEOFWORLD ) +// { +// OutputDebugString( (LPCSTR)String( "STRATEGIC MOVE COSTS: South should be EDGEOFWORLD for sector %c%d\n", y+'A'-1, x ) ); +// //fprintf(outfile, "STRATEGIC MOVE COSTS: South should be EDGEOFWORLD for sector %c%d\n", y+'A'-1, x ); +// } +// } +// else +// { +// if( SectorInfo[ SECTOR(x,y) ].ubTraversability[ SOUTH_STRATEGIC_MOVE ] != +// SectorInfo[ SECTOR(x,y+1) ].ubTraversability[ NORTH_STRATEGIC_MOVE ] ) +// { //south +// OutputDebugString( (LPCSTR)String( "STRATEGIC MOVE COSTS: South mismatch for sector %c%d\n", y+'A'-1, x ) ); +// //fprintf(outfile, "STRATEGIC MOVE COSTS: South mismatch for sector %c%d\n", y+'A'-1, x); +// } +// if( SectorInfo[ SECTOR(x,y) ].ubTraversability[ NORTH_STRATEGIC_MOVE ] != EDGEOFWORLD ) +// OutputDebugString( (LPCSTR)String( "STRATEGIC MOVE COSTS: North should be EDGEOFWORLD for sector %c%d\n", y+'A'-1, x ) ); +// } +// if( x < 16 ) +// { +// if( SectorInfo[ SECTOR(x,y) ].ubTraversability[ EAST_STRATEGIC_MOVE ] != +// SectorInfo[ SECTOR(x+1,y) ].ubTraversability[ WEST_STRATEGIC_MOVE ] ) +// { //east +// OutputDebugString( (LPCSTR)String( "STRATEGIC MOVE COSTS: East mismatch for sector %c%d\n", y+'A'-1, x ) ); +// //fprintf(outfile, "STRATEGIC MOVE COSTS: East mismatch for sector %c%d\n", y+'A'-1, x); +// } +// if( x == 1 && SectorInfo[ SECTOR(x,y) ].ubTraversability[ WEST_STRATEGIC_MOVE ] != EDGEOFWORLD ) +// OutputDebugString( (LPCSTR)String( "STRATEGIC MOVE COSTS: West should be EDGEOFWORLD for sector %c%d\n", y+'A'-1, x ) ); +// } +// else +// { +// if( SectorInfo[ SECTOR(x,y) ].ubTraversability[ WEST_STRATEGIC_MOVE ] != +// SectorInfo[ SECTOR(x-1,y) ].ubTraversability[ EAST_STRATEGIC_MOVE ] ) +// { //west +// OutputDebugString( (LPCSTR)String( "STRATEGIC MOVE COSTS: West mismatch for sector %c%d\n", y+'A'-1, x ) ); +// //fprintf(outfile, "STRATEGIC MOVE COSTS: West mismatch for sector %c%d\n", y+'A'-1, x); +// } +// if( SectorInfo[ SECTOR(x,y) ].ubTraversability[ EAST_STRATEGIC_MOVE ] != EDGEOFWORLD ) +// OutputDebugString( (LPCSTR)String( "STRATEGIC MOVE COSTS: East should be EDGEOFWORLD for sector %c%d\n", y+'A'-1, x ) ); +// } +// } +// } +// //fclose(outfile); +// //#endif +//} +// +UINT8 GetTraversability( INT16 sStartSector, INT16 sEndSector ) +{ + UINT8 ubDirection = 0; + INT16 sDifference = 0; + + // given start and end sectors + sDifference = sEndSector - sStartSector; + + + if( sDifference == -1 ) + { + ubDirection = WEST_STRATEGIC_MOVE; + } + else if( sDifference == 1 ) + { + ubDirection = EAST_STRATEGIC_MOVE; + } + else if( sDifference == 16 ) + { + ubDirection = SOUTH_STRATEGIC_MOVE; + } + else + { + ubDirection = NORTH_STRATEGIC_MOVE; + } + + + return( SectorInfo[ sStartSector ].ubTraversability[ ubDirection ] ); +} + +BOOLEAN SectorIsImpassable( INT16 sSector ) +{ + // returns true if the sector is impassable in all directions + return( SectorInfo[ sSector ].ubTraversability[ THROUGH_STRATEGIC_MOVE ] == GROUNDBARRIER || + SectorInfo[ sSector ].ubTraversability[ THROUGH_STRATEGIC_MOVE ] == EDGEOFWORLD ); +} + UINT8 gubEncryptionArray3[ BASE_NUMBER_OF_ROTATION_ARRAYS * 3 ][ NEW_ROTATION_ARRAY_SIZE ] = { { @@ -579,6 +1231,7 @@ UINT8 gubEncryptionArray3[ BASE_NUMBER_OF_ROTATION_ARRAYS * 3 ][ NEW_ROTATION_AR }, }; +/* void InitStrategicRowA() { SECTORINFO *pSector; @@ -2707,25 +3360,37 @@ void InitStrategicRowP() pSector->ubTraversability[ WEST_STRATEGIC_MOVE ] = EDGEOFWORLD; pSector->ubTraversability[ THROUGH_STRATEGIC_MOVE ] = EDGEOFWORLD; } - -void InitStrategicMovementCosts() +*/ +BOOLEAN InitStrategicMovementCosts() { - InitStrategicRowA(); - InitStrategicRowB(); - InitStrategicRowC(); - InitStrategicRowD(); - InitStrategicRowE(); - InitStrategicRowF(); - InitStrategicRowG(); - InitStrategicRowH(); - InitStrategicRowI(); - InitStrategicRowJ(); - InitStrategicRowK(); - InitStrategicRowL(); - InitStrategicRowM(); - InitStrategicRowN(); - InitStrategicRowO(); - InitStrategicRowP(); + char fileName[MAX_PATH]; + + // need to be here + strcpy(fileName, TABLEDATA_DIRECTORY); + strcat(fileName, MOVEMENTCOSTFILENAME); + if(!ReadInStrategicMovementCosts(fileName)) + return FALSE; + + //InitStrategicRowA(); + //InitStrategicRowB(); + //InitStrategicRowC(); + //InitStrategicRowD(); + //InitStrategicRowE(); + //InitStrategicRowF(); + //InitStrategicRowG(); + //InitStrategicRowH(); + //InitStrategicRowI(); + //InitStrategicRowJ(); + //InitStrategicRowK(); + //InitStrategicRowL(); + //InitStrategicRowM(); + //InitStrategicRowN(); + //InitStrategicRowO(); + //InitStrategicRowP(); + + //WriteInStrategicMovementCosts("TABLEDATA\\~MovementCosts.xml"); + + #ifdef JA2TESTVERSION { //Simply make sure all shared borders between sectors match. INT32 x,y; @@ -2775,41 +3440,6 @@ void InitStrategicMovementCosts() } } #endif -} -UINT8 GetTraversability( INT16 sStartSector, INT16 sEndSector ) -{ - UINT8 ubDirection = 0; - INT16 sDifference = 0; - - // given start and end sectors - sDifference = sEndSector - sStartSector; - - - if( sDifference == -1 ) - { - ubDirection = WEST_STRATEGIC_MOVE; - } - else if( sDifference == 1 ) - { - ubDirection = EAST_STRATEGIC_MOVE; - } - else if( sDifference == 16 ) - { - ubDirection = SOUTH_STRATEGIC_MOVE; - } - else - { - ubDirection = NORTH_STRATEGIC_MOVE; - } - - - return( SectorInfo[ sStartSector ].ubTraversability[ ubDirection ] ); -} - -BOOLEAN SectorIsImpassable( INT16 sSector ) -{ - // returns true if the sector is impassable in all directions - return( SectorInfo[ sSector ].ubTraversability[ THROUGH_STRATEGIC_MOVE ] == GROUNDBARRIER || - SectorInfo[ sSector ].ubTraversability[ THROUGH_STRATEGIC_MOVE ] == EDGEOFWORLD ); + return( TRUE ); } \ No newline at end of file diff --git a/Strategic/Strategic Movement.h b/Strategic/Strategic Movement.h index 20ed2f4b..2eb02a2c 100644 --- a/Strategic/Strategic Movement.h +++ b/Strategic/Strategic Movement.h @@ -291,7 +291,7 @@ void ReportVehicleOutOfGas( INT32 iVehicleID, UINT8 ubSectorX, UINT8 ubSectorY ) void RandomizePatrolGroupLocation( GROUP *pGroup ); -void InitStrategicMovementCosts(); +BOOLEAN InitStrategicMovementCosts(); void PlaceGroupInSector( UINT8 ubGroupID, INT16 sPrevX, INT16 sPrevY, INT16 sNextX, INT16 sNextY, INT8 bZ, BOOLEAN fCheckForBattle ); diff --git a/Tactical/XML.h b/Tactical/XML.h index f2c87253..6b1e5593 100644 --- a/Tactical/XML.h +++ b/Tactical/XML.h @@ -38,34 +38,35 @@ typedef PARSE_STAGE; #define ENEMYITEMCHOICESFILENAME "EnemyItemChoices.xml" #define IMPITEMCHOICESFILENAME "IMPItemChoices.xml" -#define TONYINVENTORYFILENAME "TonyInventory.xml" -#define DEVININVENTORYFILENAME "DevinInventory.xml" -#define FRANZINVENTORYFILENAME "FranzInventory.xml" -#define KEITHINVENTORYFILENAME "KeithInventory.xml" -#define SAMINVENTORYFILENAME "SamInventory.xml" -#define JAKEINVENTORYFILENAME "JakeInventory.xml" -#define HOWARDINVENTORYFILENAME "HowardInventory.xml" -#define GABBYINVENTORYFILENAME "GabbyInventory.xml" -#define FRANKINVENTORYFILENAME "FrankInventory.xml" -#define ELGININVENTORYFILENAME "ElginInventory.xml" -#define MANNYINVENTORYFILENAME "MannyInventory.xml" -#define HERVEINVENTORYFILENAME "HerveInventory.xml" -#define PETERINVENTORYFILENAME "PeterInventory.xml" -#define ALBERTOINVENTORYFILENAME "AlbertoInventory.xml" -#define CARLOINVENTORYFILENAME "CarloInventory.xml" -#define MICKEYINVENTORYFILENAME "MickeyInventory.xml" -#define ARNIEINVENTORYFILENAME "ArnieInventory.xml" -#define PERKOINVENTORYFILENAME "PerkoInventory.xml" -#define FREDOINVENTORYFILENAME "FredoInventory.xml" +#define TONYINVENTORYFILENAME "NPCInventory\\TonyInventory.xml" +#define DEVININVENTORYFILENAME "NPCInventory\\DevinInventory.xml" +#define FRANZINVENTORYFILENAME "NPCInventory\\FranzInventory.xml" +#define KEITHINVENTORYFILENAME "NPCInventory\\KeithInventory.xml" +#define SAMINVENTORYFILENAME "NPCInventory\\SamInventory.xml" +#define JAKEINVENTORYFILENAME "NPCInventory\\JakeInventory.xml" +#define HOWARDINVENTORYFILENAME "NPCInventory\\HowardInventory.xml" +#define GABBYINVENTORYFILENAME "NPCInventory\\GabbyInventory.xml" +#define FRANKINVENTORYFILENAME "NPCInventory\\FrankInventory.xml" +#define ELGININVENTORYFILENAME "NPCInventory\\ElginInventory.xml" +#define MANNYINVENTORYFILENAME "NPCInventory\\MannyInventory.xml" +#define HERVEINVENTORYFILENAME "NPCInventory\\HerveInventory.xml" +#define PETERINVENTORYFILENAME "NPCInventory\\PeterInventory.xml" +#define ALBERTOINVENTORYFILENAME "NPCInventory\\AlbertoInventory.xml" +#define CARLOINVENTORYFILENAME "NPCInventory\\CarloInventory.xml" +#define MICKEYINVENTORYFILENAME "NPCInventory\\MickeyInventory.xml" +#define ARNIEINVENTORYFILENAME "NPCInventory\\ArnieInventory.xml" +#define PERKOINVENTORYFILENAME "NPCInventory\\PerkoInventory.xml" +#define FREDOINVENTORYFILENAME "NPCInventory\\FredoInventory.xml" #define BOBBYRAYSTRINGSFILENAME "BobbyRayStrings.xml" #define AMMOCALIBERSTRINGSFILENAME "AmmoCaliberStrings.xml" -#define SOUNDSFILENAME "Sounds.xml" -#define BURSTSOUNDSFILENAME "BurstSounds.xml" -// Lesh: filename definition +#define SOUNDSFILENAME "Sounds\\Sounds.xml" +#define BURSTSOUNDSFILENAME "Sounds\\BurstSounds.xml" + #define EXPLOSIONDATAFILENAME "ExplosionData.xml" -#define CITYTABLEFILENAME "Cities.xml" +#define CITYTABLEFILENAME "Map\\Cities.xml" +#define MOVEMENTCOSTFILENAME "Map\\MovementCosts.xml" // WANNE: drops filename #define ENEMYWEAPONDROPSFILENAME "EnemyWeaponDrops.xml" @@ -144,12 +145,14 @@ extern BOOLEAN WriteEnemyArmourDropsStats(ARMOUR_DROPS *pEnemyArmourDrops, STR f extern BOOLEAN ReadInEnemyMiscDropsStats(MISC_DROPS *pEnemyMiscDrops, STR fileName); extern BOOLEAN WriteEnemyMiscDropsStats(MISC_DROPS *pEnemyMiscDrops, STR fileName); -// Lesh: 2 lines added +// Lesh: burst sounds and explosion info extern BOOLEAN ReadInBurstSoundArray(STR fileName); extern BOOLEAN WriteBurstSoundArray(); -// Lesh: over -// Lesh: 2 new lines added for explosion data extern BOOLEAN ReadInExplosionDataStats(STR fileName); extern BOOLEAN WriteExplosionDataStats(); -// Lesh: over + +//Lesh: strategic movement costs +extern BOOLEAN ReadInStrategicMovementCosts(STR fileName); +extern BOOLEAN WriteInStrategicMovementCosts(STR fileName); + #endif \ No newline at end of file