TC01
Deity
How did the yield bug from trade routes get fixed?
In CvCity::doTurn, at the end, right before some debug-DLL-specific code and the report event command, I added a block looking like this:
Spoiler :
Code:
//Added in Final Frontier: TC01
// Looks at building yield changes, trait yield changes, trait yield changes with trade routes to set city base yield, and trade route yields
// Then, planet-specific yield stuff is done automatically in Python with changeYieldRate, in the callback right after this
// There are potential problems... if a city can't have negative base yield rate (Forge gets -1 in all cities). This has been (hopefully) fixed by "Python override"
// Would PROBABLY be easier to edit this into the functions elsewhere that do building yield changes... not sure how though
CvPlayer& pPlayer = GET_PLAYER(getOwner());
int iYield = 0;
int iBuildingYield = 0;
int iTraitYield = 0;
setFoodOverride(0);
setProductionOverride(0);
setGoldOverride(0);
for (int iYieldLoop = 0; iYieldLoop < NUM_YIELD_TYPES; iYieldLoop++)
{
//Building yields
for (int iBuilding = 0; iBuilding < GC.getNumBuildingInfos(); iBuilding++)
{
BuildingTypes eBuilding = (BuildingTypes)iBuilding;
if (getNumRealBuilding(eBuilding) > 0)
{
iBuildingYield = GC.getBuildingInfo(eBuilding).getYieldChange(iYieldLoop) * getNumRealBuilding(eBuilding);
}
iYield += iBuildingYield;
}
//Trait yields, and traits with trade routes yields
for (int iTrait = 0; iTrait < GC.getNumTraitInfos(); iTrait++)
{
TraitTypes eTrait = (TraitTypes)iTrait;
if (pPlayer.hasTrait(eTrait))
{
iTraitYield = GC.getTraitInfo(eTrait).getYieldChanges(iYieldLoop);
for (int iTradeCity = 0; iTradeCity < getTradeRoutes(); iTradeCity++)
{
CvCity* pTradeCity = getTradeCity(iTradeCity);
if (pTradeCity != NULL)
{
iTraitYield += GC.getTraitInfo(eTrait).getTradeRouteYieldChanges(iYieldLoop);
}
}
iYield += iTraitYield;
}
}
//Trade routes (currently, only Gold is used... bad?)
if (iYieldLoop == 2)
{
iYield += getTradeYield((YieldTypes)2);
}
//Finally, store the value so Python can access it (because I'm too lazy to move all this back to Python)
YieldTypes eYield = (YieldTypes)iYieldLoop;
switch (eYield)
{
case YIELD_FOOD:
{
setFoodOverride(iYield);
break;
}
case YIELD_PRODUCTION:
{
setProductionOverride(iYield);
break;
}
case YIELD_COMMERCE:
{
setGoldOverride(iYield);
break;
}
default:
{
break;
}
}
}
//End of Final Frontier
You want to add an iYield = 0 statement to the start of the primary for loop, so the start of this block looks like this:
Code:
CvPlayer& pPlayer = GET_PLAYER(getOwner());
int iYield = 0;
int iBuildingYield = 0;
int iTraitYield = 0;
setFoodOverride(0);
setProductionOverride(0);
setGoldOverride(0);
for (int iYieldLoop = 0; iYieldLoop < NUM_YIELD_TYPES; iYieldLoop++)
{
[COLOR="Red"]//Reset iYield to 0 on each pass
iYield = 0;[/COLOR]
The problem was that the yield change was not being reset each time, so the production yield change was actually food + production yield change, and the commerce yield change was actually food + production + commerce yield change.