Wesnjean
Chieftain
Greets,
I want to have the ability to create new units for a player that builds a wonder - similar to the Pact of the Nilhorn from FFH2. I know how to do what was done in there, but how do you allow for UU's if you are using them? I don't see any call in the API that looks like it will return what I am looking for.
Specifically, if I want to create a new UNITCLASS_WARRIOR, I want the code for UNIT_WARRIOR to be used unless there is a UU for the civilization that has built the wonder.
(I currently use the city built event because it is easy to test with new starts, not sure what final implementation will be.)
def onCityBuilt(self, argsList):
'City Built'
city = argsList[0]
playerX = PyPlayer(city.getOwner())
pPlayer = gc.getPlayer(city.getOwner())
playerTraits = playerX.getTraitList()
iUnit = playerX.getBestGarrisonUnit()
'CyInterface().addImmediateMessage(("Best Garrison Unit ID = %d" %(iUnit)), "")'
if (city.getOwner() == CyGame().getActivePlayer()):
self.__eventEditCityNameBegin(city, False)
if gc.getInfoTypeForString('TRAIT_SUPREME') in playerTraits:
cityGarrison = pPlayer.initUnit(iUnit, city.getX(), city.getY(), UnitAITypes.NO_UNITAI)
CvUtil.pyPrint('City Built Event: %s' %(city.getName()))
def getBestGarrisonUnit(self):
eTeam = gc.getTeam(self.player.getTeam())
if eTeam.isHasTech(gc.getInfoTypeForString('TECH_RIFLING')):
return gc.getInfoTypeForString('UNIT_RIFLEMAN')
elif eTeam.isHasTech(gc.getInfoTypeForString('TECH_GUNPOWDER')) and (self.player.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_SULPHUR')) >= 1):
return gc.getInfoTypeForString('UNIT_MUSKETMAN')
elif eTeam.isHasTech(gc.getInfoTypeForString('TECH_FEUDALISM')) and eTeam.isHasTech(gc.getInfoTypeForString('TECH_ARCHERY')):
return gc.getInfoTypeForString('UNIT_LONGBOWMAN')
elif eTeam.isHasTech(gc.getInfoTypeForString('TECH_ARCHERY')):
return gc.getInfoTypeForString('UNIT_ARCHER')
else:
return gc.getInfoTypeForString('UNIT_WARRIOR')
And it looks like I have no idea how to format the code in the spoiler windows so that the indentations are kept.
But ideally, I would like to return either the base unit ID or the UU unit ID from the call to getBestGarrisonUnit. If you can point me at the most useful API calls, that would be great. Worse case, I can probably try to read the civilization info, looking for the specific UNITCLASS and seeing if there is a UNIT entry in there - I think.
Thanks,
Wes
I want to have the ability to create new units for a player that builds a wonder - similar to the Pact of the Nilhorn from FFH2. I know how to do what was done in there, but how do you allow for UU's if you are using them? I don't see any call in the API that looks like it will return what I am looking for.
Specifically, if I want to create a new UNITCLASS_WARRIOR, I want the code for UNIT_WARRIOR to be used unless there is a UU for the civilization that has built the wonder.
(I currently use the city built event because it is easy to test with new starts, not sure what final implementation will be.)
Spoiler :
def onCityBuilt(self, argsList):
'City Built'
city = argsList[0]
playerX = PyPlayer(city.getOwner())
pPlayer = gc.getPlayer(city.getOwner())
playerTraits = playerX.getTraitList()
iUnit = playerX.getBestGarrisonUnit()
'CyInterface().addImmediateMessage(("Best Garrison Unit ID = %d" %(iUnit)), "")'
if (city.getOwner() == CyGame().getActivePlayer()):
self.__eventEditCityNameBegin(city, False)
if gc.getInfoTypeForString('TRAIT_SUPREME') in playerTraits:
cityGarrison = pPlayer.initUnit(iUnit, city.getX(), city.getY(), UnitAITypes.NO_UNITAI)
CvUtil.pyPrint('City Built Event: %s' %(city.getName()))
Spoiler :
def getBestGarrisonUnit(self):
eTeam = gc.getTeam(self.player.getTeam())
if eTeam.isHasTech(gc.getInfoTypeForString('TECH_RIFLING')):
return gc.getInfoTypeForString('UNIT_RIFLEMAN')
elif eTeam.isHasTech(gc.getInfoTypeForString('TECH_GUNPOWDER')) and (self.player.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_SULPHUR')) >= 1):
return gc.getInfoTypeForString('UNIT_MUSKETMAN')
elif eTeam.isHasTech(gc.getInfoTypeForString('TECH_FEUDALISM')) and eTeam.isHasTech(gc.getInfoTypeForString('TECH_ARCHERY')):
return gc.getInfoTypeForString('UNIT_LONGBOWMAN')
elif eTeam.isHasTech(gc.getInfoTypeForString('TECH_ARCHERY')):
return gc.getInfoTypeForString('UNIT_ARCHER')
else:
return gc.getInfoTypeForString('UNIT_WARRIOR')
And it looks like I have no idea how to format the code in the spoiler windows so that the indentations are kept.

But ideally, I would like to return either the base unit ID or the UU unit ID from the call to getBestGarrisonUnit. If you can point me at the most useful API calls, that would be great. Worse case, I can probably try to read the civilization info, looking for the specific UNITCLASS and seeing if there is a UNIT entry in there - I think.
Thanks,
Wes