The next chapter in the XML Saga: Getting the new files to load

TRN2

Chieftain
Joined
Jan 24, 2007
Messages
89
Ok, so not being content with the kiddy pool, I'm jumping in a bit deeper.
Now I have made 3 files, they are - in order...
CIV4FactionsSchema.xml
CIV4Factions.xml
CIV4FactionDiplomacyModifications.xml

I know the sections of SDK I need to look at are CvXMLLoadUtilitySet and CvInfos, but I am looking at CvXMLLoadUtilitySet, and just not knowing the hows or whys or wheres of the file.
Any tips or suggestions would be appreciated, and I thought I might include the schema, just in case it's important...
Code:
<Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes">
	<ElementType name="Description" content="textOnly"/>
	<ElementType name="Civilopedia" content="textOnly"/>
	<ElementType name="LeaderName" content="textOnly"/>
	<ElementType name="bLeaderAvailability" content="textOnly" dt:type="boolean"/>
	<ElementType name="Leaders" content="eltOnly">
		<element type="LeaderName"/>
		<element type="bLeaderAvailability"/>
	</ElementType>
	<ElementType name="FactionInfo" content="eltOnly">
		<element name="Type"/>
		<element name="Description"/>
		<element name="Civilopedia"/>
		<element name="Leaders" minOccurs="0" maxOccurs="*"/>
	</ElementType>
	<ElementType name="iDiplomacyChange" content="textOnly" dt:type="int"/>
	<ElementType name="DiplomancyChange" content="eltOnly">
		<element name="Type"/>
		<element name="iDiplomacyChange"/>
	</ElementType>
	<ElementType name="ChangeToFaction" content="eltOnly">
		<element name="Type" MaxOccurs="1"/>
		<element name="DiplomacyChange" MaxOccurs="*"/>
	</ElementType>
	<ElementType name="FactionInfos" content="eltOnly">
		<element name="FactionInfo" maxOccurs="*"/>
	</ElementType>
	<ElementType name="DiplomacyChanges" content="eltOnly">
		<element name="ChangeToFaction"/>
	</ElementType>
	<ElementType name="Civ4Factions" content="eltOnly">
		<element name="FactionInfos" maxOccurs="1"/>
	</ElementType>
	<ElementType name="Civ4FactionDiplomacyModifications" content="eltOnly">
		<element name="DiplomacyChanges"/>
	</ElementType>
</Schema>
Biggest question I have right now, is where to start :confused:
Another point of interest -><element name="Type"/> - I never see this declared anywhere in any of the other files, so I didn't declare it my own - hope I done right...

Going through the Schema you will see that CIV4Factions.xml now contains TXT_KEY and PEDIA entries, as well as the list of leaders contained in the faction, while CIV4FactionDiplomacyModifications.xml contains the diplomacy changes between leaders of differing factions.
 
A little bit later on, I have added the following code to the CvXMLLoadUtilitySet.cpp
Code:
	cache = gDLL->createLeaderHeadInfoCacheObject("CIV4LeaderHeadInfos.dat");		// cache file name
	if (!gDLL->cacheRead(cache, "xml\\Civilizations\\CIV4LeaderHeadInfos.xml"))	// src data file name
	{
		// load normally
		bLoaded = LoadCivXml(m_pFXml, "Civilizations/CIV4LeaderHeadInfos.xml");
		if (!bLoaded)
		{
			char	szMessage[1024];
			sprintf( szMessage, "LoadXML call failed for Civilizations/CIV4LeaderHeadInfos.xml. \n Current XML file is: &#37;s", GC.getCurrentXMLFile().GetCString());
			gDLL->MessageBox(szMessage, "XML Load Error");
		}

		if (bLoaded)
		{
			SetGlobalClassInfo(&GC.getLeaderHeadInfo(), "Civ4LeaderHeadInfos/LeaderHeadInfos/LeaderHeadInfo", &GC.getNumLeaderHeadInfos());

			// write unit info to cache
			bool bOk = gDLL->cacheWrite(cache);
			if (!bOk)
			{
				char	szMessage[1024];
				sprintf( szMessage, "Failed writing to LeaderHead cache. \n Current XML file is: %s", GC.getCurrentXMLFile().GetCString());
				gDLL->MessageBox(szMessage, "XML Caching Error");
			}
			if (bOk)
			{
				logMsg("Wrote Civ4LeaderHeadInfos to cache");
			}
		}
	}
	else
	{
		logMsg("Read CIV4LeaderHeadInfos from cache");
		bLoaded	= true;
	}
	gDLL->destroyCache(cache);

[B]	////////////////////////////////////////////////
	//Faction Mod Start of Edit
	bLoaded = LoadCivXml(m_pFXml, "Civilizations/CIV4FactionInfos.xml");
	if (!bLoaded)
	{
		char	szMessage[1024];
		sprintf( szMessage, "LoadXML call failed for Civilizations/CIV4FactionInfo.xml. \n Current XML file is: %s", GC.getCurrentXMLFile().GetCString());
		gDLL->MessageBox(szMessage, "XML Load Error");
	}
	if (bLoaded && Validate())
	{
		SetGlobalClassInfo(&GC.getFactionInfo(), "Civ4FactionInfo/FactionInfos/FactionInfo", &GC.getNumFactionInfos());
	}
	//Faction Mod End of Edit
	////////////////////////////////////////////////[/B]

	bLoaded = LoadCivXml(m_pFXml, "Interface/CIV4ColorVals.xml");
	if (!bLoaded)
	{
		char	szMessage[1024];
		sprintf( szMessage, "LoadXML call failed for Interface/CIV4ColorVals.xml. \n Current XML file is: %s", GC.getCurrentXMLFile().GetCString());
		gDLL->MessageBox(szMessage, "XML Load Error");
	}
As well as this to CvGloabls.cpp
Code:
////////////////////////////////////////////////
//Faction Mod Start of Edit
int& CvGlobals::getNumFactionInfos()
{
		return m_iNumFactionInfos;
}

CvFactionInfo*& CvGlobals::getFactionInfo()
{
	return m_paFactionInfo;
}
//Faction Mod End of Edit
////////////////////////////////////////////////
This was added to the Class declrations at the top of CvGlobals.h
Code:
class CvFactionInfo;				//Added for Faction Mod
and a bit futher down I added
Code:
	////////////////////////////////////////////////
	//Faction Mod Start of Edit
	DllExport int& getNumFactionInfos();
	CvFactionInfo*& getFactionInfo();
	//Faction Mod End of Edit
	////////////////////////////////////////////////
and
Code:
	////////////////////////////////////////////////
	//Faction Mod Start of Edit
	CvFactionInfo* m_paFactionInfo;
	int m_iNumFactionInfos;
	//Faction Mod End of Edit
	////////////////////////////////////////////////
In the CvInfos.cpp I added this also...
Code:
//======================================================================================================
//					CvFactionsInfo
//======================================================================================================

//------------------------------------------------------------------------------------------------------
//
//  FUNCTION:   CvFactionInfo()
//
//  PURPOSE :   Default constructor
//
//------------------------------------------------------------------------------------------------------
CvFactionInfo::CvFactionInfo():
m_pbLeaders(NULL)
{
}

//------------------------------------------------------------------------------------------------------
//
//  FUNCTION:   ~CvFactionInfo()
//
//  PURPOSE :   Default destructor
//
//------------------------------------------------------------------------------------------------------
CvFactionInfo::~CvFactionInfo()
{
	SAFE_DELETE_ARRAY(m_pbLeaders);
}

bool CvFactionInfo::read(CvXMLLoadUtility* pXML)
{
	if (!CvInfoBase::read(pXML))
	{
		return false;
	}
	pXML->SetVariableListTagPair(&m_pbLeaders, "Leaders", GC.getLeaderHeadInfo(), sizeof(GC.getLeaderHeadInfo((LeaderHeadTypes)0)), GC.getNumLeaderHeadInfos());
}
and this to the CvInfos.h
Code:
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//  class : CvFactionInfo
//
//  DESC:
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class CvFactionInfo:
	public CvInfoBase
{
public:
	DllExport CvFactionInfo();
	DllExport virtual ~CvFactionInfo();
	DllExport bool read(CvXMLLoadUtility* pXML);
protected:
	bool *m_pbLeaders;
};
It compiles fine, but I am still getting the send info to M$ error I always seem to be getting, my guess is that the order is wrong or something, since that was the case last time.
If anyone spots the error with this, please get back to me, I am still going over it myself.
Link to all files provided here
 
I think that the basic problem is that you're trying to read a boolean array with:

Code:
pXML->SetVariableListTagPair(&m_pbLeaders, "Leaders", GC.getLeaderHeadInfo(), sizeof(GC.getLeaderHeadInfo((LeaderHeadTypes)0)), GC.getNumLeaderHeadInfos());
}

but your data isn't organized in this way. Here's how I rewrote CIV4FactionSchema:

Code:
 <!-- Factions Schema -->
<Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes">
	<ElementType name="Description" content="textOnly"/>
	<ElementType name="Civilopedia" content="textOnly"/>
	<ElementType name="Type" content="textOnly"/>
	
	<ElementType name="LeaderName" content="textOnly"/>
	<ElementType name="bLeaderAvailability" content="textOnly" dt:type="boolean"/>
	<ElementType name="Leader" content="eltOnly">
		<element type="LeaderName"/>
		<element type="bLeaderAvailability"/>
	</ElementType>
	<ElementType name="Leaders" content="eltOnly">
		<element type="Leader" maxOccurs="*"/>
	</ElementType>
	
	<ElementType name="FactionInfo" content="eltOnly">
		<element type="Type"/>
		<element type="Description"/>
		<element type="Civilopedia"/>
		<element type="Leaders"/>
	</ElementType>
	<ElementType name="FactionInfos" content="eltOnly">
		<element type="FactionInfo" maxOccurs="*"/>
	</ElementType>
	<ElementType name="Civ4FactionInfos" content="eltOnly">
		<element type="FactionInfos" minOccurs="0" maxOccurs="*"/>
	</ElementType>
</Schema>

And here's some sample data:

Code:
<!-- Faction Infos -->
<Civ4FactionInfos xmlns="x-schema:CIV4FactionSchema.xml">
	<FactionInfos>
		<FactionInfo>
			<Type>FACTION_GOOD</Type>
			<Description>TXT_KEY_FACTION_GOOD</Description>
			<Civilopedia>TXT_KEY_FACTION_GOOD_PEDIA</Civilopedia>
			<Leaders>
				<Leader>
					<LeaderName>LEADER_CHURCHILL</LeaderName>
					<bLeaderAvailability>1</bLeaderAvailability>
				</Leader>
				<Leader>
					<LeaderName>LEADER_FRANKLIN_ROOSEVELT</LeaderName>
					<bLeaderAvailability>1</bLeaderAvailability>
				</Leader>
			</Leaders>
		</FactionInfo>
		<FactionInfo>
			<Type>FACTION_BAD</Type>
			<Description>TXT_KEY_FACTION_BAD</Description>
			<Civilopedia>TXT_KEY_FACTION_BAD_PEDIA</Civilopedia>
			<Leaders>
				<Leader>
					<LeaderName>LEADER_STALIN</LeaderName>
					<bLeaderAvailability>1</bLeaderAvailability>
				</Leader>
			</Leaders>
		</FactionInfo>	
		<FactionInfo>	
			<Type>FACTION_UGLY</Type>
			<Description>TXT_KEY_FACTION_UGLY</Description>
			<Civilopedia>TXT_KEY_FACTION_UGLY_PEDIA</Civilopedia>
			<Leaders>
				<Leader>
					<LeaderName>LEADER_GENGHIS_KHAN</LeaderName>
					<bLeaderAvailability>1</bLeaderAvailability>
				</Leader>
			</Leaders>
		</FactionInfo>
	</FactionInfos>
</Civ4FactionInfos>

It compiles and runs fine for me. (I don't think that there's any difference between my C++ code and yours, but I didn't check all of yours.)
 
K, well things have come up this weekend, it'll have to wait till Monday or Tuesday before I can check this, ty for your help PeteT, I'll see if I can get it to go when this is all over ;)
 
Top Bottom