while(len(promotionList) < g_iMinimumStartingMercenaryPromotionCount):
# Loop until we get a unit that matches the required era
while(prereqTechEra != iEra):
promotionList = []
iCount = iCount+1
# The random type of unit that will be created
iUnitType = gc.getGame().getMapRand().get(gc.getNumUnitInfos(), "Random Unit Info")
# Get the PyUnitInfo for the iUnitType
pUnitInfo = PyInfo.UnitInfo(iUnitType)
# If we can't contract out the unit then continue
if(not self.canContractOutUnit(pUnitInfo.info)):
continue
# Get the list of prereq technologies required for the unit
unitTechPrereqList = self.getUnitPrereqTechs(pUnitInfo)
# If the unitTechPrereqList is empty start from the beginning
if(len(unitTechPrereqList) == 0):
continue
# Get the era from the list of prereq. technologies
prereqTechEra = self.getMaxTechEra(unitTechPrereqList)
# Create the mercenary unit if we have a valid iUnitType value
if(iUnitType != -1):
# Create the mercenary unit
#tmpUnit = barbarianPlayer.initUnit(iUnitType, 0, 0, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
plot = barbarianPlayer.getStartingPlot()
# Create the mercenary unit
tmpUnit = barbarianPlayer.initUnit(iUnitType, plot.getX(), plot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
# The following two statements can be written as:
# promotionList = self.getMercenaryPromotions(self.getUnitPromotionList(tmpUnit, iEra))
# to improve performance. I have provided the code in two lines to improve readability
# of the code.
# Get all of the possible promotions for the mercenary for the give era
promotionList = self.getEraAppropriateUnitPromotionList(tmpUnit, iEra)
# Get a random subset of promotions that the mercenary will have.
promotionList = self.getMercenaryPromotions(promotionList)
# Set the initial level and experience level for the mercenary
self.setInitialMercenaryExperience(tmpUnit, promotionList)
# Create the actual mercenary object, we do not pass in the tmpUnit object itself
# because we do not want to accidentally set it as the CyUnit in the Mercenary class
mercenary = Mercenary(MercenaryNameUtils.getRandomMercenaryName(), gc.getUnitInfo(iUnitType), promotionList, tmpUnit.getExperience(), tmpUnit.experienceNeeded())
# Kill off the tmpUnit since it does not need to exist in the game until someone hires the
# mercenary
tmpUnit.kill(false,PlayerTypes.NO_PLAYER)