ripple01
Emperor
Hello all,
Recently, I wrote my first mini-mini little Python modcomp. I needed an ability for an Enlightened trait that I created to add 1 to the Library and University. I was able to make this work with the following:
This works well, except for 2 issues. I'm hoping someone may be able to point me in the right direction to resolve these.
1) My first issue is that if a civ has a UB that replaces the Library or University, the bonus is not added. I'm sure that this has something to do with me using building instead of buildingclass in my code. Is this as simple as replacing all instances of Building with BuildingClass or is something more involved required?
2) My second issue is that because my code is based on the onBuildingBuilt event, the +1 is not indicated in the build queue when selecting the building to build. Is it possible to move my code to onGameStart and have it run once and be in effect the entire game? As I understand Python, this would be better for performance reasons as well.
Any point in the right direction would be much appreciated. Although the code above is very simple, it was somewhat of a personal victory for me to get it to work.
Recently, I wrote my first mini-mini little Python modcomp. I needed an ability for an Enlightened trait that I created to add 1 to the Library and University. I was able to make this work with the following:
Code:
def onBuildingBuilt(argsList):
'Building Completed'
pCity, iBuildingType = argsList
game = gc.getGame()
## Enlightened Trait Begin ##
pPlayer = gc.getPlayer(pCity.plot().getOwner())
iTrait = gc.getInfoTypeForString('TRAIT_ENLIGHTENED')
if (pPlayer.hasTrait(iTrait)):
if iBuildingType == gc.getInfoTypeForString( 'BUILDING_LIBRARY' ):
pCity.setBuildingCommerceChange (27,1,1)
if iBuildingType == gc.getInfoTypeForString( 'BUILDING_UNIVERSITY' ):
pCity.setBuildingCommerceChange (28,1,1)
## Enlightened Trait End ##
This works well, except for 2 issues. I'm hoping someone may be able to point me in the right direction to resolve these.
1) My first issue is that if a civ has a UB that replaces the Library or University, the bonus is not added. I'm sure that this has something to do with me using building instead of buildingclass in my code. Is this as simple as replacing all instances of Building with BuildingClass or is something more involved required?
2) My second issue is that because my code is based on the onBuildingBuilt event, the +1 is not indicated in the build queue when selecting the building to build. Is it possible to move my code to onGameStart and have it run once and be in effect the entire game? As I understand Python, this would be better for performance reasons as well.
Any point in the right direction would be much appreciated. Although the code above is very simple, it was somewhat of a personal victory for me to get it to work.