Dresden
Emperor
- Joined
- Jul 10, 2008
- Messages
- 1,081
The standard SDK upgrade formula is in CvUnit::upgradePrice(UnitTypes eUnit) and it calculates the price the following way:
You can mimic it in Python like so:
Code:
iPrice = GC.getDefineINT("BASE_UNIT_UPGRADE_COST");
iPrice += (std::max(0, (GET_PLAYER(getOwnerINLINE()).getProductionNeeded(eUnit) - GET_PLAYER(getOwnerINLINE()).getProductionNeeded(getUnitType()))) * GC.getDefineINT("UNIT_UPGRADE_COST_PER_PRODUCTION"));
if (!isHuman() && !isBarbarian())
{
iPrice *= GC.getHandicapInfo(GC.getGameINLINE().getHandicapType()).getAIUnitUpgradePercent();
iPrice /= 100;
iPrice *= std::max(0, ((GC.getHandicapInfo(GC.getGameINLINE().getHandicapType()).getAIPerEraModifier() * GET_PLAYER(getOwnerINLINE()).getCurrentEra()) + 100));
iPrice /= 100;
}
iPrice -= (iPrice * getUpgradeDiscount()) / 100;
return iPrice;
You can mimic it in Python like so:
Code:
def getUpgradePriceOverride(self, argsList):
iPlayer, iUnitID, iUnitTypeUpgrade = argsList
pPlayer = gc.getPlayer(iPlayer)
pUnit = pPlayer.getUnit(iUnitID)
iPrice = gc.getDefineINT("BASE_UNIT_UPGRADE_COST")
iPrice += (max(0, (pPlayer.getUnitProductionNeeded(iUnitTypeUpgrade) - pPlayer.getUnitProductionNeeded(pUnit.getUnitType()))) * gc.getDefineINT("UNIT_UPGRADE_COST_PER_PRODUCTION"))
if ((not pPlayer.isHuman()) and (not pPlayer.isBarbarian())):
pHandicapInfo = gc.getHandicapInfo(gc.getGame().getHandicapType())
iPrice = iPrice * pHandicapInfo.getAIUnitUpgradePercent() / 100
iPrice = iPrice * max(0, ((pHandicapInfo.getAIPerEraModifier() * pPlayer.getCurrentEra()) + 100)) / 100
iPrice = iPrice - ((iPrice * pUnit.getUpgradeDiscount()) / 100)
#Now modify the price with Leonardo's and return it
return -1 # Any value 0 or above will be used