TradeYieldChange (like in Civ5) - or: simply +1 [yield] on each trade route

Cybah

Emperor
Joined
Jun 22, 2007
Messages
1,481
I'd like to add a trait which is adding some yield bonus to each trade route like

+1food
+2production
+3commerce

no matter of the value of the trade route and without any % modifiers.

Any ideas?
 
I've just copied some source code (tradeyieldchange in traitinfos) from star trek mod but I got stuck with this:

I've tried to change calculateTradeYield from

PHP:
int CvCity::calculateTradeYield(YieldTypes eIndex, int iTradeProfit) const 
{ 
    if ((iTradeProfit > 0) && (GET_PLAYER(getOwnerINLINE()).getTradeYieldModifier(eIndex) > 0)) 
    { 
        return ((iTradeProfit * GET_PLAYER(getOwnerINLINE()).getTradeYieldModifier(eIndex)) / 100); 
    } 
    else 
    { 
        return 0; 
    } 
}

to

PHP:
int CvCity::calculateTradeYield(YieldTypes eIndex, int iTradeProfit) const 
{ 
    if ((iTradeProfit > 0) && ((GET_PLAYER(getOwnerINLINE()).getTradeYieldModifier(eIndex) > 0) || (GET_PLAYER(getOwnerINLINE()).getTradeYieldChange(eIndex) > 0))) 
    { 
        return ((iTradeProfit * GET_PLAYER(getOwnerINLINE()).getTradeYieldModifier(eIndex)) / 100 + GET_PLAYER(getOwnerINLINE()).getTradeYieldChange(eIndex)); 
    } 
    else 
    { 
        return 0; 
    } 
}

But now I get the compiling error:

PHP:
1>CvCity.cpp(9239) : error C2039: 'getTradeYieldChange' : is not a member of 'CvPlayerAI'

Why is this calling CvPlayerAI? It's just a new trait object like

PHP:
GC.getTraitInfo(eTrait).getTradeRouteYieldChanges(iYieldLoop)
 
I believe GET_PLAYER() returns a CvPlayerAI object.
 
And apparently you have not declared getTradeYieldChange in the CvPlayer header.
(CvPlayerAI is a CvPlayer with additional functionality)
 
When I do that, I'm getting unresolved external symbol errors. Is there something I need to add to CvPlayer.cpp too?

edit: all the "getTradeYieldChange" above is "getTradeRouteYieldChanges" of cause.
 
Assuming there's a separation between the header file which contains declarations and the source file which contains the implementation, as it does in Civ, then when you add a method to a class you need to add a declaration in the class declaration in the header file like this:
Code:
class CvPlayer
{
    ...
    [B]int getTradeRouteYieldChanges(YieldTypes eIndex);[/B]
    ...
};
This is to announce to the world that the class CvPlayer has a method called getTradeRouteYieldChanges, and what its parameters are and what it returns.

In addition, you need to write the implementation in the .cpp file, like that:

Code:
int [B]CvPlayer::[/B]getTradeRouteYieldChanges(YieldTypes eIndex)
{
    int result;
    ...
    return result;
}
 
ty, got it compiled now but now im getting python traceback errors cause of BUG's fractal trade route management. grrrrrrr!

is there any other way to change the trade yield by this trait-traderouteyieldchanges? looks like i may not alter calculateTradeYield.
 
YEEEEEEEEEES! I've got it! :D

I've now altered updateTradeRoutes():

PHP:
// Cybah - BASE: TradeRouteYieldChange START
	int iTraitYield = 0;
	for (iI = 0; iI < NUM_YIELD_TYPES; iI++)
	{
		//Trait yields, and traits with trade routes yields
		for (int iTrait = 0; iTrait < GC.getNumTraitInfos(); iTrait++)
		{
			TraitTypes eTrait = (TraitTypes)iTrait;
			if (GET_PLAYER(getOwnerINLINE()).hasTrait(eTrait))
			{
				for (int iTradeCity = 0; iTradeCity < getTradeRoutes(); iTradeCity++)
				{
					CvCity* pTradeCity = getTradeCity(iTradeCity);
					if (pTradeCity != NULL)
					{
						iTraitYield += GC.getTraitInfo(eTrait).getTradeRouteYieldChanges(iI);
					}
				}
			}
		}

		setTradeYield( ((YieldTypes)iI), (calculateTradeYield(((YieldTypes)iI), iTradeProfit) + iTraitYield) ); // XXX could take this out if handled when CvPlotGroup changes...
// Cybah - BASE: TradeRouteYieldChange END


Works. :)
 
Back
Top Bottom