Bonus# per Improvement

vincentz

Programmer
Joined
Feb 4, 2009
Messages
3,614
Location
Denmark
Anyone knows where the bonus is "harvested by the improvements?
I want to double it up (perhaps later add a [iNumberOfBonus] for the ImprovementInfos.xml, so f.ex. a camp harvests 1 Banana, a Plantation gives 2 Bananas and a Modern Plantation gives 3).

TIA
Vincentz :D
 
Wouldn't it be as simple as adding the number of bonuses to ImprovementInfos.xml

Then in CvPlot::updatePlotGroupBonus():
Code:
if (isCity(true, getTeam()) ||
	((getImprovementType() != NO_IMPROVEMENT) && GC.getImprovementInfo(getImprovementType()).isImprovementBonusTrade(eNonObsoleteBonus)))
	{
		if ((pPlotGroup != NULL) && isBonusNetwork(getTeam()))
		{
			[B][COLOR="Red"]int iNumBonuses = getImprovementType() == NO_IMPROVEMENT ? 1 : GC.getImprovementInfo(getImprovementType()).getNumBonuses();[/COLOR][/B]
			pPlotGroup->changeNumBonuses(eNonObsoleteBonus, ((bAdd) ? [B][COLOR="red"]iNumBonuses[/COLOR][/B] : -iNumBonuses[B][COLOR="red"][/COLOR][/B]));
		}
	}
CvImprovementInfo::getNumBonuses() is then the new function to get the new XML value.

My guess is that this would be enough to get this working. Do remember the default value for iNumBonuses should be 1, not 0. Trivial, but easy to forget in the XML reading code as the 3rd argument is often skipped (and that way 0).
 
Thanks :goodjob:
I replaced it with 2 and its working as far as I can tell.
pPlotGroup->changeNumBonuses(eNonObsoleteBonus, ((bAdd) ? 2 : -2));
Spoiler :
FoxsXpX.jpg


Is there a good guide for adding XML tags? If there isn't then its ok. Its pretty much working as intended (though I havent really thought it through with x2 resources, might reverse the change later, but thought it would be good for early game trade)
 
Is there a good guide for adding XML tags?
Not that I know of, but as it feels like I'm doing nothing else these days I can give a few tips.

In the XML schema, you can add the tag like
Code:
<element type="iNumBonuses" [B]minOccurs="0"[/B]/>
The bold part mean you can skip adding this tag to the actual XML file, in which case the default value will be used. That is useful if most existing improvements will stay at the default.. However it confuses Civ4 XML editor, which assumes all lines to be present.
In CvInfos.cpp:
Code:
pXML->GetChildXmlValByName(&m_iNumBonuses, "iNumBonuses", [B]1[/B]);
Make use of the 3rd argument, which is the default value in case the tag isn't present in the XML file. It's easily overlooked as most vanilla read lines use just two arguments and use the default 0 as default.

Add the variable to the "savegame" in CvInfos.cpp. I'm not entirely sure what it is used for, but I suspect it's either scenarios or savegames with locked assets. Either way regular savegames will not use it.

The rest should be simple enough. Add m_iNumBonuses to CvImprovementInfo and add getNumBonuses() to read it.
 
Its.... its ALIVE!!!!

:D

I added Numbonus to 5 places in CvInfos.cpp and 2 places in CvInfos.h, 1 place in CyInfoInterface2.cpp as well as 2 places in CIV4TerrainSchema.xml

Spoiler :

Code:
m_iHappiness(0),
// Vincentz Improvement Number of Bonus
m_iNumBonuses(0),
// Vincentz Improvement Number of Bonus
m_iPillageGold(0),
Code:
int CvImprovementInfo::getHappiness() const
{
	return m_iHappiness; 
}

// Vincentz Improvement Number of Bonus
int CvImprovementInfo::getNumBonuses() const
{
	return m_iNumBonuses; 
}
// Vincentz Improvement Number of Bonus

int CvImprovementInfo::getPillageGold() const
{
	return m_iPillageGold; 
}
Code:
	stream->Read(&m_iHappiness);
	// Vincentz Improvement Number of Bonus
	stream->Read(&m_iNumBonuses);
	// Vincentz Improvement Number of Bonus
	stream->Read(&m_iPillageGold);
Code:
	stream->Write(m_iHappiness);
	// Vincentz Improvement Number of Bonus
	stream->Write(m_iNumBonuses);
	// Vincentz Improvement Number of Bonus
	stream->Write(m_iPillageGold);
Code:
	pXML->GetChildXmlValByName(&m_iHappiness, "iHappiness");
	// Vincentz Improvement Number of Bonus
	pXML->GetChildXmlValByName(&m_iNumBonuses, "iNumBonuses", 2);
	// Vincentz Improvement Number of Bonus
	pXML->GetChildXmlValByName(&m_iPillageGold, "iPillageGold");
-----------------
Code:
	int getHappiness() const;				// Exposed to Python
// Vincentz Improvement Number of Bonus
	int getNumBonuses() const;				// Exposed to Python
// Vincentz Improvement Number of Bonus
	int getPillageGold() const;				// Exposed to Python
Code:
	int m_iHappiness;
// Vincentz Improvement Number of Bonus
	int m_iNumBonuses;
// Vincentz Improvement Number of Bonus
	int m_iPillageGold;
------------------
Code:
		.def("getHappiness", &CvImprovementInfo::getDefenseModifier, "int ()")
// Vincentz Improvement Number of Bonus
		.def("getNumBonuses", &CvImprovementInfo::getNumBonuses, "int ()")
// Vincentz Improvement Number of Bonus
		.def("getPillageGold", &CvImprovementInfo::getPillageGold, "int ()")

-------------------
Code:
	<ElementType name="iDefenseModifier" content="textOnly" dt:type="int"/>
<!--Vincentz Improvement Number of Bonus -->
	<ElementType name="iNumBonuses" content="textOnly" dt:type="int"/>
<!--Vincentz Improvement Number of Bonus -->
	<ElementType name="iPillageGold" content="textOnly" dt:type="int"/>
Code:
		<element type="iHappiness"/>
<!--Vincentz Improvement Number of Bonus -->
		<element type="iNumBonuses" minOccurs="0"/>
<!--Vincentz Improvement Number of Bonus -->
		<element type="iPillageGold"/>



I set default to 2 and camp to 5 :
Spoiler :
mw5RUfP.jpg


Thanks alot :thumbsup:
 
Back
Top Bottom