New Feature: Different Mineral Types for Mines (by Jazz & Buggler)

- Instead of only having Gold and Silver for Mines, we can now add more mineral types (-> TableData\Map\Minerals.xml)
- The initialization of the mineral types of the mines is done in LUA (Scripts\initmines.lua)

- Example: https://ja2svn.dyndns.org/source/ja2/trunk/Documents/1.13%20Modding/Modding%20Examples/New%20Minerals-Mines%20Example.zip
o In this example we have a new mineral type (Oil) and the Cambria Mine (H8) becomes a Refinery


git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6584 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Wanne
2013-11-12 09:58:18 +00:00
parent c85471ecd6
commit 010e967948
11 changed files with 254 additions and 10 deletions
+21 -6
View File
@@ -1271,16 +1271,31 @@ if ( ReadXMLEmail == TRUE )
}
#endif
BackupBRandEncyclopedia ( gBriefingRoomData, gBriefingRoomDataBackup, 0);
BackupBRandEncyclopedia ( gBriefingRoomData, gBriefingRoomDataBackup, 0);
#endif //ENABLE_BRIEFINGROOM
UINT8 p;
for(p=0; p<NUM_PROFILES; p++)
{
gAimOldArchives[p].FaceID = -1;
}
// Mine Types (Minerals)
strcpy(fileName, directoryName);
strcat(fileName, MINERALSFILENAME);
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("LoadExternalGameplayData, fileName = %s", fileName));
SGP_THROW_IFFALSE(ReadInMinerals(fileName,FALSE), MINERALSFILENAME);
#ifndef ENGLISH
AddLanguagePrefix(fileName);
if ( FileExists(fileName) )
{
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("LoadExternalGameplayData, fileName = %s", fileName));
SGP_THROW_IFFALSE(ReadInMinerals(fileName,TRUE), fileName);
}
#endif
// Old AIM Archive
UINT8 p;
for(p=0; p<NUM_PROFILES; p++)
{
gAimOldArchives[p].FaceID = -1;
}
strcpy(fileName, directoryName);
strcat(fileName, OLDAIMARCHIVEFILENAME);
+3 -1
View File
@@ -416,6 +416,7 @@ UINT32 guiMapBorderHeliSectors;
// list of map sectors that player isn't allowed to even highlight
BOOLEAN sBadSectorsList[ WORLD_MAP_X ][ WORLD_MAP_X ];
MINERALS_VALUES MineralsName[255];
INT16 sBaseSectorList[ MAX_TOWNS - 1 ];/*={
// NOTE: These co-ordinates must match the top left corner of the 3x3 town tiles cutouts in Interface/MilitiaMaps.sti!
@@ -5068,7 +5069,8 @@ void BlitMineText( INT16 sMapX, INT16 sMapY )
ubMineIndex = GetMineIndexForSector( sMapX, sMapY );
// display associated town name, followed by "mine"
swprintf( wString, L"%s %s", pTownNames[ GetTownAssociatedWithMine( GetMineIndexForSector( sMapX, sMapY ) ) ], pwMineStrings[ 0 ] );
//swprintf( wString, L"%s %s", pTownNames[ GetTownAssociatedWithMine( GetMineIndexForSector( sMapX, sMapY ) ) ], pwMineStrings[ 0 ] );
swprintf( wString, L"%s %s", pTownNames[ GetTownAssociatedWithMine( GetMineIndexForSector( sMapX, sMapY ) ) ], MineralsName[gMineStatus[ubMineIndex].ubMineType].sType );
AdjustXForLeftMapEdge(wString, &sScreenX, MapMineLabelsFont);
mprintf( ( sScreenX - StringPixLength( wString, MapMineLabelsFont ) / 2 ) , sScreenY + ubLineCnt * GetFontHeight( MapMineLabelsFont ) , wString );
ubLineCnt++;
+11
View File
@@ -20,6 +20,17 @@ typedef struct
INT32 IconY;
} ICON_FILE;
typedef struct
{
UINT32 uiIndex;
CHAR16 sType[50];
UINT16 Type;
CHAR16 sMinerals[50];
} MINERALS_VALUES;
extern MINERALS_VALUES MineralsName[255];
extern ICON_FILE gHiddenIcon[ 256 ];
extern UINT32 guiIcon2[256];
@@ -447,7 +447,8 @@ void AddTextToMineBox( void )
ubMineIndex = GetMineIndexForSector( bCurrentTownMineSectorX, bCurrentTownMineSectorY );
// name of town followed by "mine"
swprintf( wString, L"%s %s", pTownNames[ GetTownAssociatedWithMine( ubMineIndex ) ], pwMineStrings[ 0 ] );
//swprintf( wString, L"%s %s", pTownNames[ GetTownAssociatedWithMine( ubMineIndex ) ], pwMineStrings[ 0 ] );
swprintf( wString, L"%s %s", pTownNames[ GetTownAssociatedWithMine( ubMineIndex ) ], MineralsName[gMineStatus[ubMineIndex].ubMineType].sType );
AddMonoString( &hStringHandle, wString );
// blank line
@@ -551,7 +552,8 @@ void AddTextToMineBox( void )
// ore type (silver/gold
swprintf( wString, L"%s:", pwMineStrings[ 11 ]);
AddMonoString( &hStringHandle, wString );
AddSecondColumnMonoString( &hStringHandle, (gMineStatus[ubMineIndex].ubMineType == SILVER_MINE) ? pwMineStrings[ 1 ] : pwMineStrings[ 2 ] );
AddSecondColumnMonoString( &hStringHandle, MineralsName[gMineStatus[ubMineIndex].ubMineType].sMinerals );
//AddSecondColumnMonoString( &hStringHandle, (gMineStatus[ubMineIndex].ubMineType == SILVER_MINE) ? pwMineStrings[ 1 ] : pwMineStrings[ 2 ] );
}
+4
View File
@@ -768,6 +768,10 @@
RelativePath=".\XML_FacilityTypes.cpp"
>
</File>
<File
RelativePath=".\XML_Minerals.cpp"
>
</File>
<File
RelativePath=".\XML_Roaming.cpp"
>
+4
View File
@@ -766,6 +766,10 @@
RelativePath=".\XML_FacilityTypes.cpp"
>
</File>
<File
RelativePath=".\XML_Minerals.cpp"
>
</File>
<File
RelativePath="XML_Roaming.cpp"
>
+1
View File
@@ -131,6 +131,7 @@
<ClCompile Include="XML_ExtraItems.cpp" />
<ClCompile Include="XML_Facilities.cpp" />
<ClCompile Include="XML_FacilityTypes.cpp" />
<ClCompile Include="XML_Minerals.cpp" />
<ClCompile Include="XML_Roaming.cpp" />
<ClCompile Include="XML_SectorNames.cpp" />
<ClCompile Include="XML_SquadNames.cpp" />
@@ -341,5 +341,8 @@
<ClCompile Include="XML_SquadNames.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="XML_Minerals.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
+193
View File
@@ -0,0 +1,193 @@
#ifdef PRECOMPILEDHEADERS
#include "Tactical All.h"
#else
#include "sgp.h"
#include "Debug Control.h"
#include "expat.h"
#include "XML.h"
#include "Interface.h"
#include "Map Screen Interface Map.h"
#endif
struct
{
PARSE_STAGE curElement;
CHAR8 szCharData[MAX_CHAR_DATA_LENGTH+1];
MINERALS_VALUES curMinerals;
MINERALS_VALUES * curArray;
UINT32 maxArraySize;
UINT32 curIndex;
UINT32 currentDepth;
UINT32 maxReadDepth;
}
typedef mineralsParseData;
BOOLEAN Minerals_TextOnly;
static void XMLCALL
mineralsStartElementHandle(void *userData, const XML_Char *name, const XML_Char **atts)
{
mineralsParseData * pData = (mineralsParseData *)userData;
if(pData->currentDepth <= pData->maxReadDepth) //are we reading this element?
{
if(strcmp(name, "MINERALS") == 0 && pData->curElement == ELEMENT_NONE)
{
pData->curElement = ELEMENT_LIST;
pData->maxReadDepth++; //we are not skipping this element
}
else if(strcmp(name, "TYPE") == 0 && pData->curElement == ELEMENT_LIST)
{
pData->curElement = ELEMENT;
pData->maxReadDepth++; //we are not skipping this element
}
else if(pData->curElement == ELEMENT &&
(strcmp(name, "uiIndex") == 0 ||
strcmp(name, "sNameType") == 0 ||
strcmp(name, "sMineral") == 0
))
{
pData->curElement = ELEMENT_PROPERTY;
pData->maxReadDepth++; //we are not skipping this element
}
pData->szCharData[0] = '\0';
}
pData->currentDepth++;
}
static void XMLCALL
mineralsCharacterDataHandle(void *userData, const XML_Char *str, int len)
{
mineralsParseData * pData = (mineralsParseData *)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
mineralsEndElementHandle(void *userData, const XML_Char *name)
{
mineralsParseData * pData = (mineralsParseData *)userData;
if(pData->currentDepth <= pData->maxReadDepth)
{
if(strcmp(name, "MINERALS") == 0)
{
pData->curElement = ELEMENT_NONE;
}
else if(strcmp(name, "TYPE") == 0)
{
pData->curElement = ELEMENT_LIST;
if (!Minerals_TextOnly)
{
wcscpy(MineralsName[pData->curMinerals.uiIndex].sMinerals, pData->curMinerals.sMinerals);
wcscpy(MineralsName[pData->curMinerals.uiIndex].sType, pData->curMinerals.sType);
MineralsName[pData->curMinerals.uiIndex].Type = pData->curMinerals.Type;
}
else
{
wcscpy(MineralsName[pData->curMinerals.uiIndex].sMinerals, pData->curMinerals.sMinerals);
wcscpy(MineralsName[pData->curMinerals.uiIndex].sType, pData->curMinerals.sType);
}
}
else if(strcmp(name, "uiIndex") == 0)
{
pData->curElement = ELEMENT;
pData->curMinerals.uiIndex = (UINT16) atol(pData->szCharData);
}
else if(strcmp(name, "sNameType") == 0 )
{
pData->curElement = ELEMENT;
MultiByteToWideChar( CP_UTF8, 0, pData->szCharData, -1, pData->curMinerals.sType, sizeof(pData->curMinerals.sType)/sizeof(pData->curMinerals.sType[0]) );
pData->curMinerals.sType[sizeof(pData->curMinerals.sType)/sizeof(pData->curMinerals.sType[0]) - 1] = '\0';
}
else if(strcmp(name, "sMineral") == 0 )
{
pData->curElement = ELEMENT;
MultiByteToWideChar( CP_UTF8, 0, pData->szCharData, -1, pData->curMinerals.sMinerals, sizeof(pData->curMinerals.sMinerals)/sizeof(pData->curMinerals.sMinerals[0]) );
pData->curMinerals.sMinerals[sizeof(pData->curMinerals.sMinerals)/sizeof(pData->curMinerals.sMinerals[0]) - 1] = '\0';
}
pData->maxReadDepth--;
}
pData->currentDepth--;
}
BOOLEAN ReadInMinerals(STR fileName, BOOLEAN localizedVersion)
{
HWFILE hFile;
UINT32 uiBytesRead;
UINT32 uiFSize;
CHAR8 * lpcBuffer;
XML_Parser parser = XML_ParserCreate(NULL);
mineralsParseData pData;
DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading Minerals.xml" );
Minerals_TextOnly = localizedVersion;
// Open file
hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE );
if ( !hFile )
return( localizedVersion );
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, mineralsStartElementHandle, mineralsEndElementHandle);
XML_SetCharacterDataHandler(parser, mineralsCharacterDataHandle);
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 Minerals.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 );
}
+8
View File
@@ -3416,6 +3416,7 @@ void GetSectorIDString( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ , STR16 zS
INT8 bTownNameID;
UINT8 ubSectorID = 0;
UINT8 ubLandType = 0;
UINT8 ubMineIndex;
if( sSectorX <= 0 || sSectorY <= 0 || bSectorZ < 0 )
{
@@ -3719,6 +3720,13 @@ void GetSectorIDString( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ , STR16 zS
wcscat( zString, pTownNames[ bTownNameID ] );
if( fDetailed )
{
/*
ubMineIndex = GetMineIndexForSector( sSectorX, sSectorY );
if ( gMineStatus[ubMineIndex].sSectorX == sSectorX && gMineStatus[ubMineIndex].sSectorY == sSectorY )
{
swprintf( zString, L" %s", MineralsName[gMineStatus[ubMineIndex].ubMineType].sType );
}
*/
switch( ubSectorID )
{ //Append the word, "mine" for town sectors containing a mine.
case SEC_B2:
+2 -1
View File
@@ -209,6 +209,7 @@ typedef PARSE_STAGE;
#define LAYOUTMAINMENU "Layout\\LayoutMainMenu.xml"
#define MINERALSFILENAME "Map\\Minerals.xml"
#define AIMAVAILABILITY "AimAvailability.xml"
#define CIVGROUPNAMESFILENAME "CivGroupNames.xml"
@@ -501,9 +502,9 @@ extern BOOLEAN WriteInActionItems( STR fileName);
extern BOOLEAN ReadInEmailMercAvailable(STR fileName, BOOLEAN localizedVersion);
extern BOOLEAN ReadInEmailMercLevelUp(STR fileName, BOOLEAN localizedVersion);
extern BOOLEAN ReadInEmailOther(STR fileName, BOOLEAN localizedVersion);
//extern BOOLEAN ReadInInsurance(STR fileName, BOOLEAN localizedVersion);
extern BOOLEAN ReadInBriefingRoom(STR fileName, BOOLEAN localizedVersion, BRIEFINGROOM_M_DATA *Ency, UINT32 FileType2 );
extern BOOLEAN ReadInMinerals(STR fileName, BOOLEAN localizedVersion);
extern BOOLEAN ReadInNewVehicles(STR fileName, BOOLEAN localizedVersion);
extern BOOLEAN WriteNewVehicles(STR fileName);