I've added a piece of code to onUnitKilled
It gives a chance to spawn an undead barbarian unit when a unit is killed.
I need to add 2 things:
- check the unitcombat of the killed unit (no spawning if it is of a specific unitcombat)
- check the attacker and defender tiles, and only spawn if one of them is empty.
Code:
def onUnitKilled(self, argsList):
'Unit Killed'
unit, iAttacker = argsList
player = PyPlayer(unit.getOwner())
attacker = PyPlayer(iAttacker)
## raise undead from barb start
if (not unit.isAnimal()):
iStr = unit.baseCombatStr()
randUnit = CyGame().getSorenRandNum(20, "random undead spawn")
if (randUnit==0):
undead = "UNIT_ZOMBIE"
if (randUnit==1):
undead = "UNIT_SKELETON"
if (iStr >5):
if (randUnit==2):
undead = "UNIT_GHOST"
if (randUnit==3):
undead = "UNIT_SKELETON_LORD"
if (randUnit==4):
undead = "UNIT_LEECH"
barbPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
pUnit = unit.plot()
pNewUnit = barbPlayer.initUnit(gc.getInfoTypeForString(undead), pUnit.getX(), pUnit.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
pNewUnit.finishMoves()
## raise undead from barb end
if (not self.__LOG_UNITKILLED):
return
CvUtil.pyPrint('Player %d Civilization %s Unit %s was killed by Player %d'
%(player.getID(), player.getCivilizationName(), PyInfo.UnitInfo(unit.getUnitType()).getDescription(), attacker.getID()))
It gives a chance to spawn an undead barbarian unit when a unit is killed.
I need to add 2 things:
- check the unitcombat of the killed unit (no spawning if it is of a specific unitcombat)
- check the attacker and defender tiles, and only spawn if one of them is empty.