Hi tsentom1,
I am having trouble getting the King Richard's Crusade wonder to work. I have added the Crusade Unit and the Python code to CvEventManager.py. However, the event just never seems to fire. I don't see anything in the logs and the Crusader unit never gets created. Any hints on how I might be mucking this up?
Cheers,
ripple01
Hmm, well the python is less complicated than some of my other wonders as it really only has two sections (technically it only needs 1, but the two function sort of differently)
The first one is on def onBeginPlayerTurn(self, argsList):
Spoiler :
Code:
def onBeginPlayerTurn(self, argsList):
'Called at the beginning of a players turn'
iGameTurn, iPlayer = argsList
## Crusade Start ##
pPlayer = gc.getPlayer(iPlayer)
b_Crusade = gc.getInfoTypeForString("BUILDING_CRUSADE")
obsoleteTech = gc.getBuildingInfo(b_Crusade).getObsoleteTech()
if ( gc.getTeam(pPlayer.getTeam()).isHasTech(obsoleteTech) == false or obsoleteTech == -1 ):
for iCity in range(pPlayer.getNumCities()):
ppCity = pPlayer.getCity(iCity)
if ppCity.getNumActiveBuilding(b_Crusade) == true:
iX = ppCity.getX()
iY = ppCity.getY()
u_crusader = gc.getInfoTypeForString( 'UNIT_CRUSADER' )
estiEnd = CyGame().getEstimateEndTurn()
if ( estiEnd >= 1000 ):
if ( iGameTurn % 12 ) == 0:
for i in range(1):
pNewUnit = pPlayer.initUnit( u_crusader, iX, iY, UnitAITypes.UNITAI_ATTACK_CITY, DirectionTypes.NO_DIRECTION )
elif ( estiEnd >= 700 ):
if ( iGameTurn % 8 ) == 0:
for i in range(1):
pNewUnit = pPlayer.initUnit( u_crusader, iX, iY, UnitAITypes.UNITAI_ATTACK_CITY, DirectionTypes.NO_DIRECTION )
elif ( estiEnd >= 500 ):
if ( iGameTurn % 6 ) == 0:
for i in range(1):
pNewUnit = pPlayer.initUnit( u_crusader, iX, iY, UnitAITypes.UNITAI_ATTACK_CITY, DirectionTypes.NO_DIRECTION )
elif ( estiEnd >= 300 ):
if ( iGameTurn % 4 ) == 0:
for i in range(1):
pNewUnit = pPlayer.initUnit( u_crusader, iX, iY, UnitAITypes.UNITAI_ATTACK_CITY, DirectionTypes.NO_DIRECTION )
else:
if ( iGameTurn % 4 ) == 0:
for i in range(1):
pNewUnit = pPlayer.initUnit( u_crusader, iX, iY, UnitAITypes.UNITAI_ATTACK_CITY, DirectionTypes.NO_DIRECTION )
basechance = 12
estiEnd = CyGame().getEstimateEndTurn()
if ( estiEnd >= 1000 ):
basechance = basechance
elif ( estiEnd >= 700 ):
basechance = 6
elif ( estiEnd >= 500 ):
basechance = 4
elif ( estiEnd >= 300 ):
basechance = 2
else:
basechance = 1
chance = CyGame().getSorenRandNum(basechance, "free state religion spread chance")
if ( chance == 0 ):
lppCityUber5 = []
for iiCity in range(pPlayer.getNumCities()):
ppCity = pPlayer.getCity(iiCity)
if ( not ppCity.isHasReligion(pPlayer.getStateReligion()) ):
lppCityUber5.append(ppCity)
if ( len(lppCityUber5) != 0 ):
chance = CyGame().getSorenRandNum(len(lppCityUber5), "which city")
ppCity = lppCityUber5[chance]
ppCity.setHasReligion(pPlayer.getStateReligion(), true, true, true)
## Crusade End ##
This once controls the unit spawn every X amount of turns depending on game speed (and also the extra state religion spread chance to your cities).
The other one is on def onBuildingBuilt(self, argsList):
Spoiler :
Code:
def onBuildingBuilt(self, argsList):
'Building Completed'
pCity, iBuildingType = argsList
game = gc.getGame()
### Crusade Start ###
if ( iBuildingType == gc.getInfoTypeForString("BUILDING_CRUSADE") ):
pPlayer = gc.getPlayer(pCity.plot().getOwner())
iPID = pPlayer.getID()
iTID = pPlayer.getTeam()
iX = pCity.getX()
iY = pCity.getY()
u_crusader = gc.getInfoTypeForString( 'UNIT_CRUSADER' )
for i in range(1):
pNewUnit = pPlayer.initUnit( u_crusader, iX, iY, UnitAITypes.UNITAI_ATTACK_CITY, DirectionTypes.NO_DIRECTION )
### Crusade End ###
if ((not gc.getGame().isNetworkMultiPlayer()) and (pCity.getOwner() == gc.getGame().getActivePlayer()) and isWorldWonderClass(gc.getBuildingInfo(iBuildingType).getBuildingClassType())):
# If this is a wonder...
popupInfo = CyPopupInfo()
popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
popupInfo.setData1(iBuildingType)
popupInfo.setData2(pCity.getID())
popupInfo.setData3(0)
popupInfo.setText(u"showWonderMovie")
popupInfo.addPopup(pCity.getOwner())
CvAdvisorUtils.buildingBuiltFeats(pCity, iBuildingType)
if (not self.__LOG_BUILDING):
return
CvUtil.pyPrint('%s was finished by Player %d Civilization %s'
%(PyInfo.BuildingInfo(iBuildingType).getDescription(), pCity.getOwner(), gc.getPlayer(pCity.getOwner()).getCivilizationDescription(0)))
So first make sure you have both of those sections.
Now as for the XML. Assuming you've added the unit and building correctly in the unitinfos and unitclass and artdefines, etc. The python calls:
BUILDING_CRUSADE
UNIT_CRUSADER
As the names of the units, so make sure you have both labeled as such in the XML or the python won't find it.
The game won't actually create a log entry in the event logs tab, since then I'd have to connect the python to SDK which makes the mod-comp overly complicated. Instead the unit should just appear on the turns in the city that has the wonder.
If you still can't get it working, you can post your XML and python here and I can take a look at it to see if I can find the problem.
Also, you can try enabling python exceptions and see if an error message comes up on the turns that are supposed to spawn a crusader, which might help us get to the bottom of it.