def giftUnit(self, iUnit, iCivilization, iXP, pFromPlot, iFromPlayer):
iAngel = gc.getInfoTypeForString('UNIT_ANGEL')
iManes = gc.getInfoTypeForString('UNIT_MANES')
if (iUnit == iAngel or iUnit == iManes):
iChance = 100 - (CyGame().countCivPlayersAlive() * 3)
iChance = iChance + iXP
if iChance < 5:
iChance = 5
if iChance > 95:
iChance = 95
if CyGame().getSorenRandNum(100, "Gift Unit") > iChance:
iUnit = -1
if iUnit != -1:
bValid = False
for iPlayer in range(gc.getMAX_PLAYERS()):
pPlayer = gc.getPlayer(iPlayer)
if (pPlayer.isAlive()):
if pPlayer.getCivilizationType() == iCivilization:
py = PyPlayer(iPlayer)
if pPlayer.getNumCities() > 0:
iRnd = CyGame().getSorenRandNum(py.getNumCities(), "Gift Unit")
pCity = py.getCityList()[iRnd]
pPlot = pCity.plot()
newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
newUnit.changeExperience(iXP, -1, false, false, false)
newUnit.setWeapons()
if (pFromPlot != -1 and gc.getPlayer(iFromPlayer).isHuman()):
bValid = True
if pPlayer.isHuman():
if iUnit == iManes:
CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ADD_MANES",()),'AS2D_UNIT_FALLS',1,'Art/Interface/Buttons/Promotions/Demon.dds',ColorTypes(7),pPlot.getX(),pPlot.getY(),True,True)
if iUnit == iAngel:
CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ADD_ANGEL",()),'AS2D_UNIT_FALLS',1,'Art/Interface/Buttons/Promotions/Angel.dds',ColorTypes(7),pPlot.getX(),pPlot.getY(),True,True)
if (pPlayer.isHuman() == False and iUnit == iManes and pCity != -1):
if CyGame().getSorenRandNum(100, "Manes") < (100 - (pCity.getPopulation() * 5)):
pCity.changePopulation(1)
newUnit.kill(True, PlayerTypes.NO_PLAYER)
if bValid:
if iUnit == iManes:
CyInterface().addMessage(iFromPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_UNIT_FALLS",()),'AS2D_UNIT_FALLS',1,'Art/Interface/Buttons/Promotions/Demon.dds',ColorTypes(7),pFromPlot.getX(),pFromPlot.getY(),True,True)
if iUnit == iAngel:
CyInterface().addMessage(iFromPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_UNIT_RISES",()),'AS2D_UNIT_FALLS',1,'Art/Interface/Buttons/Promotions/Angel.dds',ColorTypes(7),pFromPlot.getX(),pFromPlot.getY(),True,True)