def reqShapeShift(pCaster, eSpell=-1):
iTeam = pCaster.getTeam()
lAnimal = [gc.getInfoTypeForString('UNITCOMBAT_ANIMAL'), gc.getInfoTypeForString('UNITCOMBAT_BEAST')]
iCaster = pCaster.getUnitType()
iX = pCaster.getX()
iY = pCaster.getY()
for iiX in xrange(iX-1, iX+2, 1):
for iiY in xrange(iY-1, iY+2, 1):
pPlot = CyMap().plot(iiX, iiY)
if pPlot.isNone():continue
for i in xrange(pPlot.getNumUnits()):
pUnit = pPlot.getUnit(i)
if pUnit.getTeam() == iTeam:
continue
if pUnit.isOnlyDefensive():
continue
if not pUnit.isAlive():
continue
if pUnit.isImmuneToMagic():
continue
if pUnit.isAvatarOfCivLeader():
continue
if pUnit.getUnitCombatType() in lAnimal:
continue
iUnit = pUnit.getUnitType()
info = gc.getUnitInfo(iUnit)
if info.isAbandon():#It would be wasteful to change into a unit that would prompty abandon you
continue
if info.isObject():#Should not duplicate equipment
continue
if iUnit == iCaster:#No use shape shifting if it will have no real effect
for iProm in xrange(gc.getNumPromotionInfos()):
if pUnit.isHasPromotion(iProm) and not pCaster.isHasPromotion(iProm):
infoP = gc.getPromotionInfo(iProm)
if infoP.isGraphicalOnly():
continue
if infoP.isEquipment():
continue
## if infoP.isRace():
## continue
if infoP.getAIWeight() > -1:
return True
## else:
## continue
elif pCaster.isHuman():
return True
elif pCaster.baseCombatStr() < pUnit.baseCombatStr():
return True
elif pCaster.baseCombatStrDefense() < pUnit.baseCombatStrDefense():
return True
return False
def spellShapeShift(pCaster, eSpell=-1):
lPermanent = [ gc.getInfoTypeForString('PROMOTION_CHANGELING'),
gc.getInfoTypeForString('PROMOTION_MIMIC'),
gc.getInfoTypeForString('PROMOTION_HERO'),
gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE'),
gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE2'),
gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH'),
gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH2')
]
pPlot = pCaster.plot()
sName = pCaster.getNameNoDesc()
if len(sName) == 0:
sName = pCaster.getName()
lAnimal = [gc.getInfoTypeForString('UNITCOMBAT_ANIMAL'), gc.getInfoTypeForString('UNITCOMBAT_BEAST')]
iX = pCaster.getX()
iY = pCaster.getY()
pPlayer = gc.getPlayer(pCaster.getOwner())
iCaster = pCaster.getUnitType()
iResistMax = 95
iBestValue = -1000000000000
pBestUnit = -1
if not pPlayer.isHuman():
iResistMax = 20
iTeam = pPlayer.getTeam()
eTeam = gc.getTeam(iTeam)
for iiX in xrange(iX-1, iX+2, 1):
for iiY in xrange(iY-1, iY+2, 1):
pPlot = CyMap().plot(iiX, iiY)
if pPlot.isNone():continue
for i in xrange(pPlot.getNumUnits()):
pUnit = pPlot.getUnit(i)
iValue = 0
if pUnit.getTeam() == iTeam:
continue
if pUnit.isOnlyDefensive():
continue
if not pUnit.isAlive():
continue
if pUnit.isImmuneToMagic():
continue
if pUnit.isAvatarOfCivLeader():
continue
if pUnit.getUnitCombatType() in lAnimal:
continue
iUnit = pUnit.getUnitType()
info = gc.getUnitInfo(iUnit)
if info.isAbandon():#It would be wasteful to change into a unit that would prompty abandon you
continue
if info.isObject():#Should not duplicate equipment
continue
if iUnit != iCaster:#No use shape shifting if it will have no real effect
iValue += pUnit.baseCombatStr() * 10
iValue += pUnit.baseCombatStrDefense() * 10
iValue += pUnit.getMoves() * 10
iValue += pUnit.getLevel() * 10#Presumably, higher levels units would tend to have better promotions
iValue += info.getAIWeight()
for iProm in xrange(gc.getNumPromotionInfos()):
if pCaster.isHasPromotion(iProm):continue
if pUnit.isHasPromotion(iProm):
infoP = gc.getPromotionInfo(iProm)
if infoP.isGraphicalOnly():
continue
if infoP.isEquipment():
continue
## if infoP.isRace():
## continue
iValue += infoP.getAIWeight()
if iValue > iBestValue:
iBestValue = iValue
pBestUnit = pUnit
if pBestUnit != -1:
iUnit = pCaster.getScenarioCounter()
if not -1 < iUnit < gc.getNumUnitInfos():
iUnit = pCaster.getUnitType()
pCaster.setScenarioCounter(iUnit)
iReligion = pCaster.getReligion()
newUnit = pPlayer.initUnit(pBestUnit.getUnitType(), iX, iY, UnitAITypes.UNITAI_ATTACK, DirectionTypes.NO_DIRECTION)
for iProm in xrange(gc.getNumPromotionInfos()):
if gc.getPromotionInfo(iProm).isEquipment():
newUnit.setHasPromotion(iProm, False)
elif pBestUnit.isHasPromotion(iProm):
newUnit.setHasPromotion(iProm, True)
cf.makeMortal(newUnit)
#I'm not sure why I have to make both of these units illusions in order to prevent Sluagh creation, but I do
pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION'), True)
newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION'), True)
newUnit.setScenarioCounter(iUnit)
info = gc.getUnitInfo(pCaster.getUnitType())
info2 = gc.getUnitInfo(pBestUnit.getUnitType())
for iProm in xrange(gc.getNumPromotionInfos()):
if pCaster.isHasPromotion(iProm):
if iProm in lPermanent:continue
if info.getFreePromotions(iProm) and not info2.getFreePromotions(iProm):
pCaster.setHasPromotion(iProm,False)
newUnit.convert(pCaster)
newUnit.setReligion(iReligion)
newUnit.setName(sName)
iArt = pBestUnit.getUnitArtStyleType()
if iArt != -1:
newUnit.setUnitArtStyleType(iArt)
CyInterface().addMessage(pCaster.getOwner(), True, 25, CyTranslator().getText("TXT_KEY_MESSAGE_SHAPE_SHIFT", (pCaster.getNameNoDesc(),)), 'AS2D_FEATUREGROWTH', 1, 'Art/Interface/Buttons/Units/Gibbon.dds', ColorTypes(8), iX, iY, True, True)
newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION'), False)
## gc.getGame().decrementUnitClassCreatedCount(newUnit.getUnitClassType())
## gc.getGame().decrementUnitCreatedCount(iUnit)
def helpShapeShift(lpUnits, eSpell=-1):
lPermanent = [ gc.getInfoTypeForString('PROMOTION_CHANGELING'),
gc.getInfoTypeForString('PROMOTION_MIMIC'),
gc.getInfoTypeForString('PROMOTION_HERO'),
gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE'),
gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE2'),
gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH'),
gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH2')
]
iHN = gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')
szBuffer = ''
pCaster = lpUnits[0]
pPlot = pCaster.plot()
lAnimal = [gc.getInfoTypeForString('UNITCOMBAT_ANIMAL'), gc.getInfoTypeForString('UNITCOMBAT_BEAST')]
iX = pCaster.getX()
iY = pCaster.getY()
pPlayer = gc.getPlayer(pCaster.getOwner())
iTeam = pPlayer.getTeam()
eTeam = gc.getTeam(iTeam)
iResistMax = 95
if not pPlayer.isHuman():
iResistMax = 20
for pCaster in lpUnits:
if pCaster.canCast(eSpell, True):
iBestValue = -1000000000000
pBestUnit = -1
iCaster = pCaster.getUnitType()
sName = pCaster.getNameNoDesc()
if len(sName) == 0:
sName = pCaster.getName()
for iiX in xrange(iX-1, iX+2, 1):
for iiY in xrange(iY-1, iY+2, 1):
pPlot = CyMap().plot(iiX, iiY)
if pPlot.isNone():continue
for i in xrange(pPlot.getNumUnits()):
pUnit = pPlot.getUnit(i)
iValue = 0
if not pUnit.isAlive():
continue
if pUnit.getTeam() == iTeam:
continue
if pUnit.isOnlyDefensive():
continue
if pUnit.isImmuneToMagic():
continue
if pUnit.isAvatarOfCivLeader():
continue
if pUnit.getUnitCombatType() in lAnimal:
continue
iUnit = pUnit.getUnitType()
info = gc.getUnitInfo(iUnit)
if info.isAbandon():#It would be wasteful to change into a unit that would prompty abandon you
continue
if info.isObject():#Should not duplicate equipment
continue
if iUnit != iCaster:#No use shape shifting if it will have no real effect
iValue += pUnit.baseCombatStr() * 10
iValue += pUnit.baseCombatStrDefense() * 10
iValue += pUnit.getMoves() * 10
iValue += pUnit.getLevel() * 10#Presumably, higher levels units would tend to have better promotions
iValue += info.getAIWeight()
for iProm in xrange(gc.getNumPromotionInfos()):
if pCaster.isHasPromotion(iProm):continue
if pUnit.isHasPromotion(iProm):
infoP = gc.getPromotionInfo(iProm)
if infoP.isGraphicalOnly():
continue
if infoP.isEquipment():
continue
## if infoP.isRace():
## continue
iValue += infoP.getAIWeight()
if iValue > iBestValue:
iBestValue = iValue
pBestUnit = pUnit
if pBestUnit != -1:
szBuffer += CyTranslator().getText("TXT_KEY_HELP_SPELL_CHANGE_A_TO_B", (sName, pBestUnit.getName(), ))
info = gc.getUnitInfo(pBestUnit.getUnitType())
info2 = gc.getUnitInfo(pCaster.getUnitType())
lAddPromotions = []
lRemovePromotions = []
for iProm in xrange(gc.getNumPromotionInfos()):
if iProm in lPermanent:continue
if pCaster.isHasPromotion(iProm):
if info2.getFreePromotions(iProm):
lRemovePromotions.append(iProm)
elif pBestUnit.isHasPromotion(iProm):
infoP = gc.getPromotionInfo(iProm)
if not (infoP.isGraphicalOnly() or infoP.isEquipment() or infoP.isRace() or infoP.getAIWeight() < 0):
lAddPromotions.append(iProm)
if not pCaster.isHasPromotion(iHN):
lAddPromotions.append(iHN)
lAddPromotions = list(set(lAddPromotions))
lRemovePromotions = list(set(lRemovePromotions))
for iProm in lAddPromotions:
if iProm in lRemovePromotions:
lAddPromotions.remove(iProm)
lRemovePromotions.remove(iProm)
iCount = len(lAddPromotions)
if iCount > 0:
sList = ''
while len(lAddPromotions) > 0:
iProm = lAddPromotions.pop(0)
infoProm = gc.getPromotionInfo(iProm)
sList += infoProm.getDescription()
if len(lAddPromotions) > 0:
if len(lAddPromotions) == 1:
sList += " and "
else:
sList += ", "
szBuffer += CyTranslator().getText("TXT_KEY_HELP_SPELL_ADDS", ( )) + sList
iCount = len(lRemovePromotions)
if iCount > 0:
sList = ''
while len(lRemovePromotions) > 0:
iProm = lRemovePromotions.pop(0)
infoProm = gc.getPromotionInfo(iProm)
sList += infoProm.getDescription()
if len(lRemovePromotions) > 0:
if len(lRemovePromotions) == 1:
sList += " and "
else:
sList += ", "
szBuffer += CyTranslator().getText("TXT_KEY_HELP_SPELL_REMOVES", ( )) + sList
return szBuffer