diff --git a/Init.cpp b/Init.cpp index d0530587..9676cf6d 100644 --- a/Init.cpp +++ b/Init.cpp @@ -573,8 +573,42 @@ BOOLEAN LoadExternalGameplayData(STR directoryName) strcpy(fileName, directoryName); strcat(fileName, SHIPPINGDESTINATIONSFILENAME); DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("LoadExternalGameplayData, fileName = %s", fileName)); - if(!ReadInShippingDestinations(fileName)) + if(!ReadInShippingDestinations(fileName, FALSE)) return FALSE; + +#ifdef GERMAN + AddLanguagePrefix( fileName, GERMAN_PREFIX); +#endif +#ifdef RUSSIAN + AddLanguagePrefix( fileName, RUSSIAN_PREFIX); +#endif +#ifdef DUTCH + AddLanguagePrefix( fileName, DUTCH_PREFIX); +#endif +#ifdef POLISH + AddLanguagePrefix( fileName, POLISH_PREFIX); +#endif +#ifdef FRENCH + AddLanguagePrefix( fileName, FRENCH_PREFIX); +#endif +#ifdef ITALIAN + AddLanguagePrefix( fileName, ITALIAN_PREFIX); +#endif +#ifdef TAIWANESE + AddLanguagePrefix( fileName, TAIWANESE_PREFIX); +#endif +#ifdef CHINESE + AddLanguagePrefix( fileName, CHINESE_PREFIX); +#endif +#ifndef ENGLISH + if ( FileExists(fileName) ) + { + DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("LoadExternalGameplayData, fileName = %s", fileName)); + if(!ReadInShippingDestinations(fileName, TRUE)) + return FALSE; + } +#endif + strcpy(fileName, directoryName); strcat(fileName, DELIVERYMETHODSFILENAME); DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("LoadExternalGameplayData, fileName = %s", fileName)); diff --git a/Laptop/XML_ShippingDestinations.cpp b/Laptop/XML_ShippingDestinations.cpp index 73b6d3b2..2cfafafd 100644 --- a/Laptop/XML_ShippingDestinations.cpp +++ b/Laptop/XML_ShippingDestinations.cpp @@ -37,6 +37,8 @@ struct } typedef destinationParseData; +BOOLEAN ShippingDestinations_TextOnly; + static void XMLCALL destinationStartElementHandle(void *userData, const XML_Char *name, const XML_Char **atts) { @@ -104,7 +106,34 @@ destinationEndElementHandle(void *userData, const XML_Char *name) { pData->curElement = ELEMENT_LIST; - gPostalService.AddDestination(pData->tempDest.uiIndex, pData->tempDest.ubMapX, pData->tempDest.ubMapY, pData->tempDest.ubMapZ, pData->tempDest.sGridNo, pData->tempDest.szName); + if( !ShippingDestinations_TextOnly ) + { + // We are reading the base data in the first pass of the file + gPostalService.AddDestination(pData->tempDest.uiIndex, pData->tempDest.ubMapX, pData->tempDest.ubMapY, pData->tempDest.ubMapZ, pData->tempDest.sGridNo, pData->tempDest.szName); + } + else + { + // We are in second pass, during the loadup of the localization file. + // We should have legitimate data for the and elements. + // using uiIndex, iterate thru gPostalService::_Destinations till we find the correct + // DestinationStruct, and change its wstrName + + RefToDestinationListIterator dli = gPostalService.LookupDestinationList().begin(); + + while(DESTINATION(dli).uiIndex != pData->tempDest.uiIndex) + { + dli++; + if(dli == gPostalService.LookupDestinationList().end() ) + { + // this doesnt really work, displays a message but then exits imediately, + // but at least it doesnt generate a software exception.. which would prolly actually make this string readable + AssertMsg( 0, "Loading invalid uiIndex inside ShippingDestinations.xml." ); + } + + } + DESTINATION(dli).wstrName = pData->tempDest.szName; + + } } else if(strcmp(name, "name") == 0) { @@ -146,7 +175,7 @@ destinationEndElementHandle(void *userData, const XML_Char *name) pData->currentDepth--; } -BOOLEAN ReadInShippingDestinations(STR fileName) +BOOLEAN ReadInShippingDestinations(STR fileName, BOOLEAN localizedVersion) { HWFILE hFile; UINT32 uiBytesRead; @@ -156,34 +185,41 @@ BOOLEAN ReadInShippingDestinations(STR fileName) destinationParseData pData; + ShippingDestinations_TextOnly = localizedVersion; DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading ShippingDestinations.xml" ); + // Open ShippingDestinations.xml hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE ); if ( !hFile ) return( FALSE ); - + + // Get ShippingDestinations.xml file size and alloc buffer uiFSize = FileGetSize(hFile); lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1); - + + //Read in ShippingDestinations.xml to the buffer if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) ) { MemFree(lpcBuffer); return( FALSE ); } - lpcBuffer[uiFSize] = 0; + lpcBuffer[uiFSize] = 0; // terminator for buffer array - FileClose( hFile ); + FileClose( hFile ); // done with ShippingDestinations.xml + // setup Interpreter Callback functions XML_SetElementHandler(parser, destinationStartElementHandle, destinationEndElementHandle); XML_SetCharacterDataHandler(parser, destinationCharacterDataHandle); + // Initialize Data container memset(&pData,0,sizeof(pData)); pData.maxArraySize = sizeof(UINT16); pData.curIndex = -1; - XML_SetUserData(parser, &pData); + XML_SetUserData(parser, &pData); // establish address of data container for Interpreter callbacks + // Parse the buffer, if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; diff --git a/Tactical/XML.h b/Tactical/XML.h index e5ec6cf8..90d1ba8b 100644 --- a/Tactical/XML.h +++ b/Tactical/XML.h @@ -231,7 +231,7 @@ extern BOOLEAN WriteInArmyCompositionInfo(STR fileName); extern BOOLEAN ReadInRoamingInfo(STR filename); // Dealtar: New shipping system XMLs -extern BOOLEAN ReadInShippingDestinations(STR fileName); +extern BOOLEAN ReadInShippingDestinations(STR fileName, BOOLEAN localizedVersion); extern BOOLEAN ReadInDeliveryMethods(STR fileName); //Gotthard: Laptop Florist Text extern BOOLEAN ReadInFloristText(STR fileName);