Gaius Octavius
Deity
- Joined
- Jul 28, 2006
- Messages
- 4,016
Oops, just noticed my code had returned FALSE. It was originally TRUE but I changed it when I was messing around with CanTrain earlier. Small error. 

I did not miss it; it is simply not useful to me. If I understand the code he added correctly, what it will do is prevent any other unit from being trainable once your city starts work on something. That's not what I want.
I really don't see how a script save of the city production would matter. You can't hide the city from CannotTrain until the production is done because that would foul up the summary of the choices on the menu.
Sorry, I didn't read the name of the function (cannot). I was looking for a way to equate eUnit with the unit's build ID and use that for the comparison function. If equal, have it return false.
In other words, before checking if adequate resources are available, is the city already training this unit? If so, keep training, otherwise, check for resource availability.
Can you explain the last part? I'm not familiar with how these functions behave![]()
I'm guessing that so long as the city continues to build settler it can continue. If the stockpile is insufficient then no other cities can begin construction.
def cannotTrain(self,argsList):
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
bIgnoreCost = argsList[4]
bIgnoreUpgrades = argsList[5]
# QR
maxUnits = QR.getStockpile('CIVILIZATION_0','iStockpile_1')) / 10
producing = gc.getPlayer(pCity.getOwner()).getUnitClassMaking(4))
# This will make sure that the unit that is being asked about is the correct type
if gc.getUnitInfo(eUnit).getUnitClassType() == 4:
# If this unit is being worked on check to see if too many are being made
if bContinue and producing > maxUnits:
return True
elif producing >= maxUnits: # Otherwise return True if we are maxed out
return True
# End QR
return False
elif producing >= maxUnits: # Otherwise return True if we are maxed out
return False
def cannotTrain(self,argsList):
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
bIgnoreCost = argsList[4]
bIgnoreUpgrades = argsList[5]
# QR
maxUnits = QR.getStockpile('CIVILIZATION_0','iStockpile_1') / 10
producing = gc.getPlayer(pCity.getOwner()).getUnitClassMaking(4)
# This will make sure that the unit that is being asked about is the correct type
if gc.getUnitInfo(eUnit).getUnitClassType() == 4:
# If this unit is being worked on check to see if too many are being made
if bContinue and producing > maxUnits:
return True
elif producing >= maxUnits and not bContinue: # Otherwise return True if we are maxed out
return True
# End QR
return False
Actually, I do have one more question. Is it possible to have the game look at how many of a unit type, rather than a unit class, you are making? I looked for a function similar to getUnitClassMaking but couldn't find one.
If this is possible, it would be better since you could specify different costs for units that are technically part of the same class but still unique. For example, a regular spearman costs so much iron or copper to make, but the Mayan Holkan (which replaces the spearmen) requires no special resources at all. Under the getUnitClassMaking system, there would be no distinction, so they'd both have to require resources.
UnitTypes eUnit = (UnitTypes) GC.getCivilizationInfo(getCivilizationType()).getCivilizationUnit(eUnitClass);
Why would you need a different function? Each civ can only build one specific unit of any unitclass anyway. That is to say that if you're playing the Romans and building 'UNITCLASS_SWORDSMAN' you're building a Praetorian as it's the only UNITCLASS_SWORDSMAN you can build.Actually, I do have one more question. Is it possible to have the game look at how many of a unit type, rather than a unit class, you are making? I looked for a function similar to getUnitClassMaking but couldn't find one.
If this is possible, it would be better since you could specify different costs for units that are technically part of the same class but still unique. For example, a regular spearman costs so much iron or copper to make, but the Mayan Holkan (which replaces the spearmen) requires no special resources at all. Under the getUnitClassMaking system, there would be no distinction, so they'd both have to require resources.
Well, what you would do is get the number of the unit class being made and then find the unique unit of that unit class for that civilization.
For example, when you pick a unit to build, you're really picking a unit class... but then you'll see code similar to the following:
UnitTypes eUnit = (UnitTypes) GC.getCivilizationInfo(getCivilizationType()).getCivilizationUnit(eUnitClass);
Why would you need a different function? Each civ can only build one specific unit of any unitclass anyway. That is to say that if you're playing the Romans and building 'UNITCLASS_SWORDSMAN' you're building a Praetorian as it's the only UNITCLASS_SWORDSMAN you can build.
Ah, got it... you just basically use a clever trick.Good idea.
I basically just use the developer's clever trick, but if you really want me to take credit for it...![]()