Units' bonus requirements and obsoletion

migck

Señor de la guerra
Joined
Apr 6, 2009
Messages
178
I'm trying to create a little addon of resources used as requirements to build some modern units, but so that when the resource becomes obsolete with a certain tech it is no longer needed to build that unit.
Specifically, I'm trying to implement this for a Rubber resource, used to build some modern units like Tanks and Infantry, but being no longer needed once the player discovers Plastics.
I have identified the function controlling requirements to train units in:
Code:
CvPlot::canTrain(UnitTypes eUnit, bool bContinue, bool bTestVisible) const
I know the best thing would be to create new XML fields defining such behavior, but for such a focused feature, I prefer not to dabble into that yet.
The thing is, I don't know how to add the structure to evaluate the owner of the unit, and whether he has Plastics tech there.
Any help is appreciated.
 
use python canTrain callback then if you dont want to use SDK
 
I do want to modify the SDK, specifically that function in CvPlot.cpp. I just meant I wouldn't want having to add a new XML field, which I don't even know how would it be implemented, to all units and/or bonuses.
 
It might be easier to make a National Wonder that provides 1 Rubber and becomes available with Plastics representing synthetic rubber production (although synthetic rubber doesn't actually replace the need for natural rubber entirely in the real world).
 
Interesting, I figured that industry and science would have already replaced natural rubber completely. But I guess the same happens with fur, whales and ivory, they eventually become obsolete in Civ yet nowadays they are still thriving businesses, which is a bit tragic IMO (and I have also made a Tobacco resource that goes obsolete with Medicine, go figure :lol:)
Anyways, I have managed to implement my idea not just for rubber, but for all obsolete resources required to train units:
Spoiler :
for AND bonuses:
Code:
/**	Tweaked - ignore obsolete bonuses	**/
/**	Original	**
if (GC.getUnitInfo(eUnit).getPrereqAndBonus() != NO_BONUS)
/**	Original END	**/
if (GC.getUnitInfo(eUnit).getPrereqAndBonus() != NO_BONUS && !GET_TEAM(getTeam()).isBonusObsolete((BonusTypes)GC.getUnitInfo(eUnit).getPrereqAndBonus()))
/**	Tweaked END	**/
and for OR resources
Code:
/**	Tweaked - ignore obsolete bonuses	**/
/**	Original	**
if (GC.getUnitInfo(eUnit).getPrereqOrBonuses(iI) != NO_BONUS)
/**	Original END	**/
if (GC.getUnitInfo(eUnit).getPrereqOrBonuses(iI) != NO_BONUS && !GET_TEAM(getTeam()).isBonusObsolete((BonusTypes)GC.getUnitInfo(eUnit).getPrereqOrBonuses(iI)))
/**	Tweaked END	**/
Though the obsolete bonus still appears as a requirement in red in case the unit needs two bonuses and the player is lacking the non-obsolete one.
 
There is actually a rising shortage of natural rubber these days, mainly due to a constantly increasing demand for it for tyre production.
 
Top Bottom