Vehem
Modmod Monkey
- Joined
- Nov 22, 2005
- Messages
- 3,219
I'm starting to get to grips with python, but have come up against an odd one. At the moment, my little "can I do it" project is to spawn a special warrior unit on the same square as a player's initial settler onGameStart, grant it a promotion (Combat5 for testing purposes) and rename it (the theory being that I can then create a new unit type to create and appropriate promotions as needed).
All of the above seems to work almost correctly with the following code...
A unit is spawned, with the correct promotion and name, but the unit is a Taoist Missionary instead of a Warrior. Having checked the XML (which is unedited in my test mod), the missionary is defined immediately before the Warrior ("off by one").
I've removed all files from the mod directory except for the CvEventManager, cleared the cache and tried setting the UNITCLASS to actually be TAOIST_MISSIONARY (this spawns a Confuscian missionary instead). Interestingly, it does correctly identify the Settler unit and spawns in the correct place.
I'm going to slog through the unitclasses between Settler and Warrior to see which one is "off" - but not sure how that will help in the long run. Any suggestions welcomed.
All of the above seems to work almost correctly with the following code...
Code:
def onGameStart(self, argsList):
'Called at the start of the game'
if (gc.getGame().getGameTurnYear() == gc.getDefineINT("START_YEAR")):
for iPlayer in range(gc.getMAX_PLAYERS()):
player = gc.getPlayer(iPlayer)
if (player.isAlive() and player.isHuman()):
popupInfo = CyPopupInfo()
popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
popupInfo.setText(u"showDawnOfMan")
popupInfo.addPopup(iPlayer)
py = PyPlayer(iPlayer)
for pUnit in py.getUnitList():
if pUnit.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_SETTLER'):
pPlayer = gc.getPlayer(pUnit.getOwner())
newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNITCLASS_WARRIOR'), pUnit.getX(), pUnit.getY(), UnitAITypes.NO_UNITAI)
newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT5'), true)
newUnit.setName("Mr. King")
A unit is spawned, with the correct promotion and name, but the unit is a Taoist Missionary instead of a Warrior. Having checked the XML (which is unedited in my test mod), the missionary is defined immediately before the Warrior ("off by one").
I've removed all files from the mod directory except for the CvEventManager, cleared the cache and tried setting the UNITCLASS to actually be TAOIST_MISSIONARY (this spawns a Confuscian missionary instead). Interestingly, it does correctly identify the Settler unit and spawns in the correct place.
I'm going to slog through the unitclasses between Settler and Warrior to see which one is "off" - but not sure how that will help in the long run. Any suggestions welcomed.