Adding a new trait XML tag via SDK

ripple01

Emperor
Joined
Mar 7, 2006
Messages
1,254
Location
New York City
I posted this in the SDK/Python forum, but wanted to repost it here as well for greater visibility:

Hi all,

First off, I have very newb programming knowledge, so go easy on me.

I am trying to copy some code by Implaer[WrG] and use it in my mod. The code adds a new XML tag in Civ4TraitInfos.XML that increases Military Production by an int.

First, I added the relevant bits to CvInfos.cpp under CvTraitInfo:

Spoiler :
m_iMilitaryProductionModifier(0)


int CvTraitInfo::getMilitaryProductionModifier() const
{
return m_iMilitaryProductionModifier;
}


pXML->GetChildXmlValByName(&m_iMilitaryProductionModifi er, "iMilitaryProductionModifier");


Then do the same in CvInfos.h


Spoiler :

DllExport int getMilitaryProductionModifier() const;


int m_iMilitaryProductionModifier;


And then the following in CvGameText.cpp



Spoiler :
if (GC.getTraitInfo(eTrait).getMilitaryProductionModi fier() != 0)
{
szHelpString.append(NEWLINE);
szHelpString.append(" ");
szHelpString.append(gDLL->getText("TXT_KEY_CIVIC_MILITARY_PRODUCTION", GC.getTraitInfo(eTrait).getMilitaryProductionModif ier()));
}


When I load the mod, the trait effect shows up in the Civ Select Screen and in the Civilopedia. However, it does not seem to work or show up in game. Could anyone tell me if I'm leaving something out or have something incorrect?

Cheers,
ripple01
 
Your work in CvInfo was what was needed to get this data out of the XML and into the DLL so that the game does something with it.

Your work in CvGameText was what is needed to get the data out of the DLL and into the Display so that the player knows something is being done.

What you haven't done yet is to make the DLL actually do something with this thing that you gave it information about. You need to find where it calculates Military Production now and add your new trait to the calculation process. I would search for the UnitInfo tag "bMilitaryProduction". This will lead you to a pXML->........ in CvInfos, which will tell you what the variable is that it is storing this under (probably a function called CvUnit::isMilitaryProduction). Once you find the CvUnit::______ thing, you want to search for that last line everywhere you can, and it will show you were the game consults that tag.

I'm guessing it'll show up in CvPlayer, CvCity or CvUnit, but somewhere it will be quite clearly consulting the production cost of a unit, and it will check to see if the unit "isMilitaryProduction", and then modify the cost based on any Civics which alter Military Production. Add in your new attribute with those lines and you will be done.

EDIT: By the way, I rarely read this section of the forums too much, so if you have further question you are best off posting here and hoping for someone else to respond at random, or sending me a PM (I'd advise both, never know what you'll get either way)
 
Back
Top Bottom