def processPlague(self, iPlayer):
		
		# collect cities with and without plague
		lInfectedCities = [city for city in utils.getCityList(iPlayer) if city.isHasRealBuilding(iPlague)]
		lUninfectedCities = [city for city in utils.getCityList(iPlayer) if not city.isHasRealBuilding(iPlague)]
			
		for city in lInfectedCities:
			
			# let plague affect city
			self.losePopulation(city)
			
			# let plague spread to vassals
			if city.isCapital():
				self.spreadToVassals(iPlayer)
				
			# let plague affect surrounding area
			self.spreadToSurroundings(city)
			
			# let plague damage nearby units
			self.damageNearbyUnits(city)
			
			# let plague spread through trade routes
			self.spreadAlongTradeRoutes(city)
			
		# spread within the civilization
		self.spreadBetweenCities(iPlayer, lInfectedCities, lUninfectedCities)
예제 #2
0
    def processPlague(self, iPlayer):

        # collect cities with and without plague
        lInfectedCities = [
            city for city in utils.getCityList(iPlayer)
            if city.isHasRealBuilding(iPlague)
        ]
        lUninfectedCities = [
            city for city in utils.getCityList(iPlayer)
            if not city.isHasRealBuilding(iPlague)
        ]

        for city in lInfectedCities:

            # let plague affect city
            self.losePopulation(city)

            # let plague spread to vassals
            if city.isCapital():
                self.spreadToVassals(iPlayer)

            # let plague affect surrounding area
            self.spreadToSurroundings(city)

            # let plague damage nearby units
            self.damageNearbyUnits(city)

            # let plague spread through trade routes
            self.spreadAlongTradeRoutes(city)

        # spread within the civilization
        self.spreadBetweenCities(iPlayer, lInfectedCities, lUninfectedCities)
예제 #3
0
 def onChangeWar(self, bWar, iTeam, iOtherTeam):
     # reset Mongol UP flags when peace is made
     if not bWar:
         if iTeam == iMongolia:
             for city in utils.getCityList(iOtherTeam):
                 city.setMongolUP(False)
         elif iOtherTeam == iMongolia:
             for city in utils.getCityList(iTeam):
                 city.setMongolUP(False)
	def onChangeWar(self, bWar, iTeam, iOtherTeam):
	
		# reset Mongol UP flags when peace is made
		if not bWar:
			if iTeam == iMongolia:
				for city in utils.getCityList(iOtherTeam):
					city.setMongolUP(False)
			elif iOtherTeam == iMongolia:
				for city in utils.getCityList(iTeam):
					city.setMongolUP(False)
	def greekConquestUP(self, iEnemy, iNumTargets=1): # Unused
		lEnemyCities = []
		
		print "Getting closest city."
		for city in utils.getCityList(iEnemy):
			iDist = utils.calculateDistance(pCity.getX(), pCity.getY(), pGreece.getCapitalCity().getX(), pGreece.getCapitalCity().getY())
			lEnemyCities.append((iDist, pCity))
			
		lEnemyCities.sort()
		
		for i in range(iNumTargets):
			if len(lEnemyCities) > 0:
				pTargetCity = lEnemyCities.pop(0)[1]
				tPlot = utils.findNearestLandPlot((pTargetCity.getX(), pTargetCity.getY()), iGreece)
				
				iExtra = 0
				if utils.getHumanID() not in [iGreece, iEnemy]: 
					iExtra = 1
					if iEnemy == iPersia: iExtra = 2
				
				utils.makeUnitAI(iGreekHoplite, iGreece, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 2+iExtra*2)
				utils.makeUnitAI(iCatapult, iGreece, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 1+iExtra*2)
				utils.makeUnitAI(iGreekHetairoi, iGreece, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 1+iExtra*2)
				
		CyInterface().addMessage(iEnemy, False, iDuration, CyTranslator().getText("TXT_KEY_UP_GREEK_CONQUESTS_TARGET", ()), "", 0, "", ColorTypes(iWhite), -1, -1, True, True)
예제 #6
0
    def tamilConquestUP(self, iEnemy, iNumTargets=1):  # Unused
        lEnemyCities = []

        print "Getting closest city."
        for pCity in utils.getCityList(iEnemy):
            iDist = utils.calculateDistance(pCity.getX(), pCity.getY(),
                                            pTamils.getCapitalCity().getX(),
                                            pTamils.getCapitalCity().getY())
            lEnemyCities.append((iDist, pCity))

        lEnemyCities.sort()

        for i in range(iNumTargets):
            if lEnemyCities:
                pTargetCity = lEnemyCities.pop(0)[1]
                tPlot = utils.findNearestLandPlot(
                    (pTargetCity.getX(), pTargetCity.getY()), iTamils)

                utils.makeUnitAI(iSwordsman, iTamils, tPlot,
                                 UnitAITypes.UNITAI_ATTACK_CITY, 2)
                utils.makeUnitAI(iWarElephant, iTamils, tPlot,
                                 UnitAITypes.UNITAI_ATTACK_CITY, 1)
                utils.makeUnitAI(iCatapult, iTamils, tPlot,
                                 UnitAITypes.UNITAI_ATTACK_CITY, 1)

        CyInterface().addMessage(
            iEnemy, False, iDuration,
            CyTranslator().getText("TXT_KEY_UP_TAMIL_CONQUESTS_TARGET", ()),
            "", 0, "", ColorTypes(iWhite), -1, -1, True, True)
	def reformationno(self, iCiv): # Unused
		cityList = utils.getCityList(iCiv)
		for city in cityList:
			if city.isHasReligion(iCatholicism):
				rndnum = gc.getGame().getSorenRandNum(100, 'ReformationAnyway')
				if rndnum >= lReformationMatrix[iCiv]:
					city.setHasReligion(iProtestantism, True, False, False)
예제 #8
0
	def romanConquestUP(self, iEnemy, iNumTargets=1, lPreferredTargetRegions=[]): # Unused
		lEnemyCities = []
		lPreferredCities = []
		
		print "Getting closest city."
		for city in utils.getCityList(iEnemy):
			iDist = utils.calculateDistance(pCity.getX(), pCity.getY(), pRome.getCapitalCity().getX(), pRome.getCapitalCity().getY())
			lEnemyCities.append((iDist, pCity))
			if pCity.getRegionID() in lPreferredTargetRegions:
				lPreferredCities.append((iDist, pCity))
				
		if lPreferredCities:
			lEnemyCities = lPreferredCities
			
		lEnemyCities.sort()
		
		for i in range(iNumTargets):
			if lEnemyCities:
				pTargetCity = lEnemyCities.pop(0)[1]
				tPlot = utils.findNearestLandPlot((pTargetCity.getX(), pTargetCity.getY()), iRome)
				
				iExtra = 0
				if utils.getHumanID() != iRome and utils.getHumanID() != iEnemy: iExtra = 1
				
				utils.makeUnitAI(iLegion, iRome, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 2+iExtra)
				utils.makeUnitAI(iCatapult, iRome, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 1+iExtra*2)
				
		#utils.debugTextPopup("Roman conquerors against "+CyTranslator().getText(str(gc.getPlayer(iEnemy).getCivilizationShortDescriptionKey()), ()))

		CyInterface().addMessage(iRome, False, iDuration, CyTranslator().getText("TXT_KEY_UP_ROMAN_CONQUESTS",(gc.getPlayer(iEnemy).getCivilizationShortDescriptionKey(),)), "", 0, "", ColorTypes(iWhite), -1, -1, True, True)
		CyInterface().addMessage(iEnemy, False, iDuration, CyTranslator().getText("TXT_KEY_UP_ROMAN_CONQUESTS_TARGET", ()), "", 0, "", ColorTypes(iWhite), -1, -1, True, True)
		print ("Message displayed.")
예제 #9
0
	def reformationno(self, iCiv): # Unused
		cityList = utils.getCityList(iCiv)
		for city in cityList:
			if city.isHasReligion(iCatholicism):
				rndnum = gc.getGame().getSorenRandNum(100, 'ReformationAnyway')
				if rndnum >= lReformationMatrix[iCiv]:
					city.setHasReligion(iProtestantism, True, False, False)
	def romanConquestUP(self, iEnemy, iNumTargets=1, lPreferredTargetRegions=[]): # Unused
		lEnemyCities = []
		lPreferredCities = []
		
		print "Getting closest city."
		for city in utils.getCityList(iEnemy):
			iDist = utils.calculateDistance(pCity.getX(), pCity.getY(), pRome.getCapitalCity().getX(), pRome.getCapitalCity().getY())
			lEnemyCities.append((iDist, pCity))
			if pCity.getRegionID() in lPreferredTargetRegions:
				lPreferredCities.append((iDist, pCity))
				
		if lPreferredCities:
			lEnemyCities = lPreferredCities
			
		lEnemyCities.sort()
		
		for i in range(iNumTargets):
			if lEnemyCities:
				pTargetCity = lEnemyCities.pop(0)[1]
				tPlot = utils.findNearestLandPlot((pTargetCity.getX(), pTargetCity.getY()), iRome)
				
				iExtra = 0
				if utils.getHumanID() != iRome and utils.getHumanID() != iEnemy: iExtra = 1
				
				utils.makeUnitAI(iRomanLegion, iRome, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 2+iExtra)
				utils.makeUnitAI(iCatapult, iRome, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 1+iExtra*2)
				
		#utils.debugTextPopup("Roman conquerors against "+CyTranslator().getText(str(gc.getPlayer(iEnemy).getCivilizationShortDescriptionKey()), ()))

		CyInterface().addMessage(iRome, False, iDuration, CyTranslator().getText("TXT_KEY_UP_ROMAN_CONQUESTS",(gc.getPlayer(iEnemy).getCivilizationShortDescriptionKey(),)), "", 0, "", ColorTypes(iWhite), -1, -1, True, True)
		CyInterface().addMessage(iEnemy, False, iDuration, CyTranslator().getText("TXT_KEY_UP_ROMAN_CONQUESTS_TARGET", ()), "", 0, "", ColorTypes(iWhite), -1, -1, True, True)
		print ("Message displayed.")
예제 #11
0
    def greekConquestUP(self, iEnemy, iNumTargets=1):  # Unused
        lEnemyCities = []

        print "Getting closest city."
        for city in utils.getCityList(iEnemy):
            iDist = utils.calculateDistance(pCity.getX(), pCity.getY(),
                                            pGreece.getCapitalCity().getX(),
                                            pGreece.getCapitalCity().getY())
            lEnemyCities.append((iDist, pCity))

        lEnemyCities.sort()

        for i in range(iNumTargets):
            if len(lEnemyCities) > 0:
                pTargetCity = lEnemyCities.pop(0)[1]
                tPlot = utils.findNearestLandPlot(
                    (pTargetCity.getX(), pTargetCity.getY()), iGreece)

                iExtra = 0
                if utils.getHumanID() not in [iGreece, iEnemy]:
                    iExtra = 1
                    if iEnemy == iPersia: iExtra = 2

                utils.makeUnitAI(iHoplite, iGreece, tPlot,
                                 UnitAITypes.UNITAI_ATTACK_CITY,
                                 20 + iExtra * 2)
                utils.makeUnitAI(iCatapult, iGreece, tPlot,
                                 UnitAITypes.UNITAI_ATTACK_CITY,
                                 10 + iExtra * 2)

        CyInterface().addMessage(
            iEnemy, False, iDuration,
            CyTranslator().getText("TXT_KEY_UP_GREEK_CONQUESTS_TARGET", ()),
            "", 0, "", ColorTypes(iWhite), -1, -1, True, True)
	def stopPlague(self, iPlayer):
		data.players[iPlayer].iPlagueCountdown = -utils.getTurns(iImmunity)
		if data.players[iPlayer].bFirstContactPlague:
			data.players[iPlayer].iPlagueCountdown = -utils.getTurns(iImmunity-30)
		data.players[iPlayer].bFirstContactPlague = False
		for city in utils.getCityList(iPlayer):
			city.setHasRealBuilding(iPlague, False)
    def checkChristianity(self, iGameTurn):
        if not gc.getGame().isReligionFounded(iJudaism): return
        if gc.getGame().isReligionFounded(iOrthodoxy): return

        iOffset = utils.getTurns(data.iSeed % 15)

        if iGameTurn == getTurnForYear(0) + iOffset:
            pHolyCity = gc.getGame().getHolyCity(iJudaism)

            if pHolyCity.getOwner() != utils.getHumanID() and gc.getGame(
            ).getSorenRandNum(2, "Holy city?") == 0:
                pChristianCity = pHolyCity
                self.foundReligion(
                    (pChristianCity.getX(), pChristianCity.getY()), iOrthodoxy)
                return

            lJewishCities = []
            for iPlayer in range(iNumTotalPlayersB):
                lJewishCities.extend([
                    city for city in utils.getCityList(iPlayer)
                    if city.isHasReligion(iJudaism)
                    and city.getOwner() != utils.getHumanID()
                ])

            if lJewishCities:
                pChristianCity = utils.getRandomEntry(lJewishCities)
                self.foundReligion(
                    (pChristianCity.getX(), pChristianCity.getY()), iOrthodoxy)
 def infectCitiesNear(self, iPlayer, startingX, startingY):
     for city in utils.getCityList(iPlayer):
         if utils.calculateDistance(city.getX(), city.getY(), startingX,
                                    startingY) <= 3:
             self.infectCity(city)
             if (gc.getDefineINT("PYTHON_LOG_ON_MAIN_PLAGUE") == 1):
                 utils.logwithid(iPlayer, ' is infecting near city')
             self.announceForeignPlagueSpread(city)
예제 #15
0
 def stopPlague(self, iPlayer):
     data.players[iPlayer].iPlagueCountdown = -utils.getTurns(iImmunity)
     if data.players[iPlayer].bFirstContactPlague:
         data.players[iPlayer].iPlagueCountdown = -utils.getTurns(
             iImmunity - 30)
     data.players[iPlayer].bFirstContactPlague = False
     for city in utils.getCityList(iPlayer):
         city.setHasRealBuilding(iPlague, False)
	def preStopPlague(self, iPlayer):
		cityList = [city for city in utils.getCityList(iPlayer) if city.hasBuilding(iPlague)]
		if cityList:
			iModifier = 0
			for city in cityList:
				if gc.getGame().getSorenRandNum(100, 'roll') > 30 - 5*city.healthRate(False, 0) + iModifier:
					city.setHasRealBuilding(iPlague, False)
					iModifier += 5 #not every city should quit
	def onBuildingBuilt(self, argsList):
		city, iBuildingType = argsList
		iOwner = city.getOwner()
		tCity = (city.getX(), city.getY())
		
		vic.onBuildingBuilt(iOwner, iBuildingType)
		self.rel.onBuildingBuilt(city, iOwner, iBuildingType)
		
		if iOwner < iNumPlayers:
			self.com.onBuildingBuilt(iOwner, iBuildingType, city)
		
		if isWorldWonderClass(gc.getBuildingInfo(iBuildingType).getBuildingClassType()):
			sta.onWonderBuilt(iOwner, iBuildingType)
			
		if iBuildingType == iPalace:
			sta.onPalaceMoved(iOwner)
			dc.onPalaceMoved(iOwner)
			
			if city.isHasRealBuilding(iAdministrativeCenter): city.setHasRealBuilding(iAdministrativeCenter, False)
			
			# Leoreth: in case human Phoenicia moves palace to Carthage
			if iOwner == iCarthage and tCity == (58, 39):
				utils.setReborn(iCarthage, True)

		# Leoreth: update trade routes when Porcelain Tower is built to start its effect
		if iBuildingType == iPorcelainTower:
			gc.getPlayer(iOwner).updateTradeRoutes()

		# Leoreth/Voyhkah: Empire State Building
		if iBuildingType == iEmpireStateBuilding:
			iPop = city.getPopulation()
			city.setBuildingCommerceChange(gc.getInfoTypeForString("BUILDINGCLASS_EMPIRE_STATE_BUILDING"), 0, iPop)
			
		# Leoreth: Machu Picchu
		if iBuildingType == iMachuPicchu:
			iNumPeaks = 0
			for i in range(21):
				if city.getCityIndexPlot(i).isPeak():
					iNumPeaks += 1
			city.setBuildingCommerceChange(gc.getInfoTypeForString("BUILDINGCLASS_MACHU_PICCHU"), 0, iNumPeaks * 2)
			
		# Leoreth: Great Wall
		if iBuildingType == iGreatWall:
			for iPlot in range(gc.getMap().numPlots()):
				plot = gc.getMap().plotByIndex(iPlot)
				if plot.getOwner() == iOwner and not plot.isWater():
					plot.setWithinGreatWall(True)
					
		# Leoreth: La Mezquita
		if iBuildingType == iMezquita:
			lGPList = [0, 0, 0, 0, 0, 0, 0]
			for city in utils.getCityList(iOwner):
				for i in range(7):
					iSpecialistUnit = utils.getUniqueUnit(iOwner, iGreatProphet + i)
					lGPList[i] += city.getGreatPeopleUnitProgress(iSpecialistUnit)
			iGPType = utils.getUniqueUnit(iOwner, iGreatProphet + utils.getHighestIndex(lGPList))
			utils.makeUnit(iGPType, iOwner, tCity, 1)
			CyInterface().addMessage(iOwner, False, iDuration, CyTranslator().getText("TXT_KEY_MEZQUITA_FREE_GP", (gc.getUnitInfo(iGPType).getText(), city.getName())), "", InterfaceMessageTypes.MESSAGE_TYPE_MINOR_EVENT, gc.getUnitInfo(iGPType).getButton(), ColorTypes(iWhite), city.getX(), city.getY(), True, True)
예제 #18
0
	def counterReformation(self, iCiv):
		for city in utils.getCityList(iCiv):
			if city.isHasReligion(iCatholicism):
				if self.chooseProtestantism(iCiv):
					if city.getPopulation() >= 8:
						city.spreadReligion(iProtestantism)
		
		if iCiv < iNumPlayers:
			data.players[iCiv].iReformationDecision = 2
예제 #19
0
 def selectRandomCitySourceCiv(self, iCiv):  # Unused
     if gc.getPlayer(iCiv).isAlive():
         cityList = [
             city for city in utils.getCityList(iCiv)
             if city.getPopulation() > 1
         ]
         if cityList:
             return utils.getRandomEntry(cityList)
     return False
	def selectRandomCityTargetCiv(self, iCiv): # Unused
		if gc.getPlayer(iCiv).isAlive():
			lCities = []
			for city in utils.getCityList(iCiv):
				if not city.isDisorder() and city.foodDifference(False) > 0:
					lCities.append(city)
			if lCities:
				return utils.getRandomEntry(lCities)
		return False
예제 #21
0
 def selectRandomCityTargetCiv(self, iCiv):  # Unused
     if gc.getPlayer(iCiv).isAlive():
         lCities = []
         for city in utils.getCityList(iCiv):
             if not city.isDisorder() and city.foodDifference(False) > 0:
                 lCities.append(city)
         if lCities:
             return utils.getRandomEntry(lCities)
     return False
	def counterReformation(self, iCiv):
		for city in utils.getCityList(iCiv):
			if city.isHasReligion(iCatholicism):
				if self.chooseProtestantism(iCiv):
					if city.getPopulation() > 6:
						city.setHasReligion(iProtestantism, True, False, False)
		
		if iCiv < iNumPlayers:
			data.players[iCiv].iReformationDecision = 2
def isHasLegendaryCity(self, iPlayer):
    """Checks whether iPlayer has a city with Legendary culture."""
    # apCityList = PyPlayer(iPlayer).getCityList
    apCityList = utils.getCityList(iPlayer)
    for pCity in apCityList:
        if pCity.GetCy().getCultureTimes100(iPlayer) >= utils.getTurns(
                2500000):
            return True
    return False
	def tolerateReformation(self, iCiv):
		for city in utils.getCityList(iCiv):
			if city.isHasReligion(iCatholicism):
				if self.isProtestantAnyway(iCiv):
					if city.getPopulation() <= 9 and not city.isHolyCityByType(iCatholicism):
						city.setHasReligion(iCatholicism, False, False, False)
					city.setHasReligion(iProtestantism, True, False, False)
		
		if iCiv < iNumPlayers:
			data.players[iCiv].iReformationDecision = 1
예제 #25
0
    def getNewWorldCities(self):  # Unused
        lCityList = []

        for iPlayer in range(iNumPlayers):
            pPlayer = gc.getPlayer(iPlayer)
            if pPlayer.getCapitalCity().getRegionID() in lNewWorld:
                for city in utils.getCityList(iPlayer):
                    if city.getRegionID() in lNewWorld:
                        lCityList.append(city)

        return lCityList
	def selectRandomCityReligion(self, iReligion): # Unused
		if gc.getGame().isReligionFounded(iReligion):
			cityList = []
			for iPlayer in range(iNumPlayers):
				for city in utils.getCityList(iPlayer):
					if city.isHasReligion(iReligion):
						cityList.append(city)
			if cityList:
				iCity = utils.getRandomEntry(cityList)
				return (city.getX(), city.getY())
		return False
	def getNewWorldCities(self): # Unused
		lCityList = []
		
		for iPlayer in range(iNumPlayers):
			pPlayer = gc.getPlayer(iPlayer)
			if pPlayer.getCapitalCity().getRegionID() in lNewWorld:
				for city in utils.getCityList(iPlayer):
					if city.getRegionID() in lNewWorld:
						lCityList.append(city)
						
		return lCityList
	def onCityRazed(self, city, iNewOwner):
		if city.hasBuilding(iPlague):
			if data.players[iNewOwner].iPlagueCountdown > 0:
				iNumCitiesInfected = 0
				for otherCity in utils.getCityList(iNewOwner):
					if (otherCity.getX(), otherCity.getY()) != (city.getX(), city.getY()): #because the city razed still has the plague
						if otherCity.hasBuilding(iPlague):
							iNumCitiesInfected += 1
				print ("iNumCitiesInfected", iNumCitiesInfected)
				if iNumCitiesInfected == 0:
					data.players[iNewOwner].iPlagueCountdown = 0 #undo spreadPlague called in onCityAcquired()
예제 #29
0
	def tolerateReformation(self, iCiv):
		for city in utils.getCityList(iCiv):
			if city.isHasReligion(iCatholicism):
				if self.isProtestantAnyway(iCiv):
					if city.getPopulation() <= 8 and not city.isHolyCityByType(iCatholicism):
						city.replaceReligion(iCatholicism, iProtestantism)
					else:
						city.spreadReligion(iProtestantism)

		if iCiv < iNumPlayers:
			data.players[iCiv].iReformationDecision = 1
	def onReleasedPlayer(self, argsList):
		iPlayer, iReleasedPlayer = argsList
		
		lCities = []
		for city in utils.getCityList(iPlayer):
			if city.plot().isCore(iReleasedPlayer) and not city.plot().isCore(iPlayer) and not city.isCapital():
				lCities.append(city)
				
		sta.doResurrection(iReleasedPlayer, lCities, False)
		
		gc.getPlayer(iReleasedPlayer).AI_changeAttitudeExtra(iPlayer, 2)
예제 #31
0
	def selectRandomCityReligion(self, iReligion): # Unused
		if gc.getGame().isReligionFounded(iReligion):
			cityList = []
			for iPlayer in range(iNumPlayers):
				for city in utils.getCityList(iPlayer):
					if city.isHasReligion(iReligion):
						cityList.append(city)
			if cityList:
				iCity = utils.getRandomEntry(cityList)
				return (city.getX(), city.getY())
		return False
예제 #32
0
	def checkCompany(self, iCompany, iGameTurn):
		if (iCompany == iSilkRoute and iGameTurn > getTurnForYear(1500)) or (iCompany == iTradingCompany and iGameTurn > getTurnForYear(1800)) or (iCompany == iTextileIndustry and iGameTurn > getTurnForYear(1920)):
			iMaxCompanies = 0
		else:
			iMaxCompanies = tCompaniesLimit[iCompany]
			
		# count the number of companies
		iCompanyCount = 0
		for iLoopPlayer in range(iNumPlayers):
			if gc.getPlayer(iLoopPlayer).isAlive():
				iCompanyCount += gc.getPlayer(iLoopPlayer).countCorporations(iCompany)
				
		# return if gameturn is beyond company fall date and removed from all cities
		if iMaxCompanies == 0 and iCompanyCount == 0:
			return
			
		# loop through all cities, check the company value for each and add the good ones to a list of tuples (city, value)
		cityValueList = []
		for iPlayer in range(iNumPlayers):
			if gc.getTeam(gc.getPlayer(iPlayer).getTeam()).isHasTech(tCompanyTechs[iCompany]) and (gc.getTeam(gc.getPlayer(iPlayer).getTeam()).isHasTech(iEconomics) or iCompany <= iTradingCompany):
				for city in utils.getCityList(iPlayer):
					iValue = self.getCityValue(city, iCompany)
					if iValue > 0: 
						cityValueList.append((city, iValue * 10 + gc.getGame().getSorenRandNum(10, 'random bonus')))
					elif city.isHasCorporation(iCompany): # quick check to remove companies
						city.setHasCorporation(iCompany, False, True, True)
						
		# sort cities from highest to lowest value
		cityValueList.sort(key=itemgetter(1), reverse=True)
		
		#debugText = 'ID: %d, ' %(iCompany)
		# spread the company
		for i in range(len(cityValueList)):
			city = cityValueList[i][0]
			if city.isHasCorporation(iCompany):
				#debugText += '%s:%d(skip), ' %(city.getName(), cityValueList[i][1])
				continue
			if iMaxCompanies == 0:
				break
			if iCompanyCount >= iMaxCompanies and i >= iMaxCompanies: # don't spread to weak cities if the limit was reached
				#debugText += 'limit reached'
				break
			city.setHasCorporation(iCompany, True, True, True)
			#debugText += '%s(OK!), ' %(city.getName())
			break
		#print debugText
		
		# if the limit was exceeded, remove company from the worst city
		if iCompanyCount > iMaxCompanies:
			for i in range(len(cityValueList)-1, 0, -1):
				city = cityValueList[i][0]
				if city.isHasCorporation(iCompany):
					city.setHasCorporation(iCompany, False, True, True)
					break
예제 #33
0
    def onReleasedPlayer(self, argsList):
        iPlayer, iReleasedPlayer = argsList

        lCities = []
        for city in utils.getCityList(iPlayer):
            if city.plot().isCore(iReleasedPlayer) and not city.plot().isCore(
                    iPlayer) and not city.isCapital():
                lCities.append(city)

        sta.doResurrection(iReleasedPlayer, lCities, False)

        gc.getPlayer(iReleasedPlayer).AI_changeAttitudeExtra(iPlayer, 2)
예제 #34
0
def calculateTopCities_FOOD():
    lCities = []
    for iLoopPlayer in range(iNumPlayers):
        for city in utils.getCityList(iLoopPlayer):
            if (1 == 1):
                iValue = city.getYieldRate(YieldTypes.YIELD_FOOD)
            else:
                iValue = ((city.getCulture(iLoopPlayer) / 5) + (city.getYieldRate(YieldTypes.YIELD_FOOD) + city.getYieldRate(YieldTypes.YIELD_PRODUCTION) \
                                                                + city.getYieldRate(YieldTypes.YIELD_COMMERCE))) * city.getPopulation()
            lCities.append((city, iValue))
    lCities.sort(key=lambda x: -x[1])
    lCities = lCities
    return lCities
	def reformationyes(self, iCiv): # Unused
		for city in utils.getCityList(iCiv):
			city.replaceReligion(iCatholicism, iProtestantism)
			
			if city.getPopulation() > 7:
				iRand = gc.getGame().getSorenRandNum(100, "Reformation residual")
				if iRand <= lReformationMatrix[iCiv]:
					city.setHasReligion(iCatholicism, True, False, False)

		pPlayer = gc.getPlayer(iCiv)
		pPlayer.changeGold(500)
		if pPlayer.getStateReligion() == iCatholicism:
			pPlayer.setLastStateReligion(0)
예제 #36
0
 def preStopPlague(self, iPlayer):
     cityList = [
         city for city in utils.getCityList(iPlayer)
         if city.hasBuilding(iPlague)
     ]
     if cityList:
         iModifier = 0
         for city in cityList:
             if gc.getGame().getSorenRandNum(
                     100, 'roll'
             ) > 30 - 5 * city.healthRate(False, 0) + iModifier:
                 city.setHasRealBuilding(iPlague, False)
                 iModifier += 5  #not every city should quit
예제 #37
0
	def reformationyes(self, iCiv): # Unused
		for city in utils.getCityList(iCiv):
			city.replaceReligion(iCatholicism, iProtestantism)
			
			if city.getPopulation() > 7:
				iRand = gc.getGame().getSorenRandNum(100, "Reformation residual")
				if iRand <= lReformationMatrix[iCiv]:
					city.setHasReligion(iCatholicism, True, False, False)

		pPlayer = gc.getPlayer(iCiv)
		pPlayer.changeGold(500)
		if pPlayer.getStateReligion() == iCatholicism:
			pPlayer.setLastStateReligion(0)
예제 #38
0
	def reformation(self):				
		for iPlayer in range(iNumPlayers):
			if [city for city in utils.getCityList(iPlayer) if city.getOwner() == iPlayer]:
				self.reformationChoice(iPlayer)
				
		for iPlayer in range(iNumPlayers):
			if data.players[iPlayer].iReformationDecision == 2:
				for iTargetPlayer in range(iNumPlayers):
					if data.players[iTargetPlayer].iReformationDecision == 0 and utils.getHumanID() != iTargetPlayer and iTargetPlayer != iNetherlands and not utils.isAVassal(iTargetPlayer):
						gc.getTeam(iPlayer).declareWar(iTargetPlayer, True, WarPlanTypes.WARPLAN_DOGPILE)
						
		pHolyCity = gc.getGame().getHolyCity(iProtestantism)
		if data.players[pHolyCity.getOwner()].iReformationDecision == 0:
			pHolyCity.setNumRealBuilding(iProtestantShrine, 1)
	def reformation(self):				
		for iPlayer in range(iNumPlayers):
			if [city for city in utils.getCityList(iPlayer) if city.getOwner() == iPlayer]:
				self.reformationChoice(iPlayer)
				
		for iPlayer in range(iNumPlayers):
			if data.players[iPlayer].iReformationDecision == 2:
				for iTargetPlayer in range(iNumPlayers):
					if data.players[iTargetPlayer].iReformationDecision == 0 and utils.getHumanID() != iTargetPlayer and iTargetPlayer != iNetherlands and not utils.isAVassal(iTargetPlayer):
						gc.getTeam(iPlayer).declareWar(iTargetPlayer, True, WarPlanTypes.WARPLAN_DOGPILE)
						
		pHolyCity = gc.getGame().getHolyCity(iProtestantism)
		if data.players[pHolyCity.getOwner()].iReformationDecision == 0:
			pHolyCity.setNumRealBuilding(iProtestantShrine, 1)
예제 #40
0
 def onCityRazed(self, city, iNewOwner):
     if city.hasBuilding(iPlague):
         if data.players[iNewOwner].iPlagueCountdown > 0:
             iNumCitiesInfected = 0
             for otherCity in utils.getCityList(iNewOwner):
                 if (otherCity.getX(),
                         otherCity.getY()) != (city.getX(), city.getY(
                         )):  #because the city razed still has the plague
                     if otherCity.hasBuilding(iPlague):
                         iNumCitiesInfected += 1
             print("iNumCitiesInfected", iNumCitiesInfected)
             if iNumCitiesInfected == 0:
                 data.players[
                     iNewOwner].iPlagueCountdown = 0  #undo spreadPlague called in onCityAcquired()
예제 #41
0
	def checkSchism(self, iGameTurn):
		if not gc.getGame().isReligionFounded(iOrthodoxy): return
		if gc.getGame().isReligionFounded(iCatholicism): return
		
		if gc.getGame().countReligionLevels(iOrthodoxy) < 10: return
		
		lStateReligionCities = []
		lNoStateReligionCities = []
		lDifferentStateReligionCities = []
		lMinorCities = []
		
		for iPlayer in range(iNumTotalPlayersB):
			iStateReligion = gc.getPlayer(iPlayer).getStateReligion()
			lCities = [city for city in utils.getCityList(iPlayer) if city.isHasReligion(iOrthodoxy)]
			if iStateReligion == iOrthodoxy: lStateReligionCities.extend(lCities)
			elif gc.getPlayer(iPlayer).isMinorCiv() or gc.getPlayer(iPlayer).isBarbarian(): lMinorCities.extend(lCities)
			elif iStateReligion == -1: lNoStateReligionCities.extend(lCities)
			else: lDifferentStateReligionCities.extend(lCities)
			
		if not lStateReligionCities: return
		if not lNoStateReligionCities and not lMinorCities: return
		
		if len(lStateReligionCities) >= len(lNoStateReligionCities) + len(lMinorCities): return
		
		lOrthodoxCapitals = [city for city in lStateReligionCities if city.isCapital()]
		
		if lOrthodoxCapitals:
			pOrthodoxCapital = utils.getHighestEntry(lOrthodoxCapitals, lambda city: gc.getPlayer(city.getOwner()).getScoreHistory(iGameTurn))
		else:
			pOrthodoxCapital = gc.getGame().getHolyCity(iOrthodoxy)
		
		lCatholicCities = []
		lCatholicCities.extend(lNoStateReligionCities)
		lCatholicCities.extend(lMinorCities)
		pCatholicCapital = utils.getHighestEntry([city for city in lCatholicCities if city.plot().getSpreadFactor(iCatholicism) >= 3 and city != pOrthodoxCapital], lambda city: city.getPopulation())
		
		if not pCatholicCapital:
			pCatholicCapital = utils.getHighestEntry(lCatholicCities, lambda city: city.getPopulation())
		
		self.foundReligion((pCatholicCapital.getX(), pCatholicCapital.getY()), iCatholicism)
		
		lIndependentCities = []
		lIndependentCities.extend(lDifferentStateReligionCities)
		lIndependentCities.extend(lMinorCities)
				
		self.schism(pOrthodoxCapital, pCatholicCapital, lNoStateReligionCities, lIndependentCities)
예제 #42
0
    def onCityCaptureGold(self, argsList):
        city, iPlayer, iGold = argsList

        if iGold > 0:
            if gc.getPlayer(iPlayer).isHasBuildingEffect(iGurEAmir):
                for loopCity in utils.getCityList(iPlayer):
                    if loopCity.isHasRealBuilding(iGurEAmir):
                        CyInterface().addMessage(
                            iPlayer, False, iDuration,
                            CyTranslator().getText(
                                "TXT_KEY_BUILDING_GUR_E_AMIR_EFFECT",
                                (iGold, city.getName(), loopCity.getName())),
                            "", 0, "", ColorTypes(iWhite), -1, -1, True, True)
                        loopCity.changeCulture(iPlayer, iGold, True)
                        break

        if iPlayer == iVikings and iGold > 0:
            vic.onCityCaptureGold(iPlayer, iGold)
	def checkSchism(self, iGameTurn):
		if not gc.getGame().isReligionFounded(iOrthodoxy): return
		if gc.getGame().isReligionFounded(iCatholicism): return
		
		lStateReligionCities = []
		lNoStateReligionCities = []
		lDifferentStateReligionCities = []
		lMinorCities = []
		
		for iPlayer in range(iNumTotalPlayersB):
			iStateReligion = gc.getPlayer(iPlayer).getStateReligion()
			lCities = [city for city in utils.getCityList(iPlayer) if city.isHasReligion(iOrthodoxy)]
			if iStateReligion == iOrthodoxy: lStateReligionCities.extend(lCities)
			elif gc.getPlayer(iPlayer).isMinorCiv() or gc.getPlayer(iPlayer).isBarbarian(): lMinorCities.extend(lCities)
			elif iStateReligion == -1: lNoStateReligionCities.extend(lCities)
			else: lDifferentStateReligionCities.extend(lCities)
			
		if not lStateReligionCities: return
		if not lNoStateReligionCities and not lMinorCities: return
		
		if len(lStateReligionCities) >= len(lNoStateReligionCities) + len(lMinorCities): return
		
		lOrthodoxCapitals = [city for city in lStateReligionCities if city.isCapital()]
		
		if lOrthodoxCapitals:
			pOrthodoxCapital = utils.getHighestEntry(lOrthodoxCapitals, lambda city: gc.getPlayer(city.getOwner()).getScoreHistory(iGameTurn))
		else:
			pOrthodoxCapital = gc.getGame().getHolyCity(iOrthodoxy)
		
		lCatholicCities = []
		lCatholicCities.extend(lNoStateReligionCities)
		lCatholicCities.extend(lMinorCities)
		pCatholicCapital = utils.getHighestEntry([city for city in lCatholicCities if city.plot().getSpreadFactor(iCatholicism) >= 3 and city != pOrthodoxCapital], lambda city: city.getPopulation())
		
		if not pCatholicCapital:
			pCatholicCapital = utils.getHighestEntry(lCatholicCities, lambda city: city.getPopulation())
		
		self.foundReligion((pCatholicCapital.getX(), pCatholicCapital.getY()), iCatholicism)
		
		lIndependentCities = []
		lIndependentCities.extend(lDifferentStateReligionCities)
		lIndependentCities.extend(lMinorCities)
				
		self.schism(pOrthodoxCapital, pCatholicCapital, lNoStateReligionCities, lIndependentCities)
예제 #44
0
    def doRomanWar(self, iCiv):  # Unused

        if iCiv in [iCarthage, iPersia, iCeltia, iEgypt]:
            iNumTargets = 2
            self.romanConquestUP(iCiv, iNumTargets)
        elif iCiv == iGreece and utils.getHumanID() != iGreece:
            bEgypt = False
            for city in utils.getCityList(iGreece):
                if city.getRegionID() == rEgypt:
                    bEgypt = True
                    break

            if bEgypt:
                iNumTargets = 2
                self.romanConquestUP(iCiv, iNumTargets, [rEgypt])
            else:
                iNumTargets = 3

            self.romanConquestUP(iCiv, iNumTargets)
예제 #45
0
	def embraceReformation(self, iCiv):
		iNumCatholicCities = 0
		for city in utils.getCityList(iCiv):
			if city.isHasReligion(iCatholicism):
				iNumCatholicCities += 1
				
				if city.getPopulation() >= 8 and not self.chooseProtestantism(iCiv):
					city.spreadReligion(iProtestantism)
				else:
					city.replaceReligion(iCatholicism, iProtestantism)
				
		pPlayer = gc.getPlayer(iCiv)
		pPlayer.changeGold(iNumCatholicCities * utils.getTurns(100))
		
		pPlayer.setLastStateReligion(iProtestantism)
		pPlayer.setConversionTimer(10)
		
		if iCiv < iNumPlayers:
			data.players[iCiv].iReformationDecision = 0
	def doRomanWar(self, iCiv): # Unused
	
		if iCiv in [iCarthage, iPersia, iCeltia, iEgypt]:
			iNumTargets = 2
			self.romanConquestUP(iCiv, iNumTargets)
		elif iCiv == iGreece and utils.getHumanID() != iGreece:
			bEgypt = False
			for city in utils.getCityList(iGreece):
				if city.getRegionID() == rEgypt:
					bEgypt = True
					break
					
			if bEgypt:
				iNumTargets = 2
				self.romanConquestUP(iCiv, iNumTargets, [rEgypt])
			else:
				iNumTargets = 3
			
			self.romanConquestUP(iCiv, iNumTargets)
	def onBuildingBuilt(self, city, iPlayer, iBuilding):
		if iBuilding == iSaintSophia:
			for city in utils.getCityList(iPlayer):
				if city.plot().getSpreadFactor(iOrthodoxy) in [RegionSpreadTypes.REGION_SPREAD_CORE, RegionSpreadTypes.REGION_SPREAD_HISTORICAL]:
					city.spreadReligion(iOrthodoxy)
					
		if iBuilding == iHinduTemple:
			if gc.getGame().isReligionFounded(iBuddhism): return
			self.foundBuddhism(city)
			
		if iBuilding == iOrthodoxCathedral:
			if gc.getGame().isReligionFounded(iCatholicism): return
		
			pOrthodoxHolyCity = gc.getGame().getHolyCity(iOrthodoxy)
		
			if pOrthodoxHolyCity.getOwner() != iPlayer:
				self.foundReligion((city.getX(), city.getY()), iCatholicism)
				pCatholicHolyCity = gc.getGame().getHolyCity(iCatholicism)
				self.schism(pOrthodoxHolyCity, pCatholicHolyCity, [], [city for city in utils.getAllCities() if city.isHasReligion(iOrthodoxy) and city.getOwner() != pOrthodoxHolyCity.getOwner()])
	def tamilConquestUP(self, iEnemy, iNumTargets=1): # Unused
		lEnemyCities = []
		
		print "Getting closest city."
		for pCity in utils.getCityList(iEnemy):
			iDist = utils.calculateDistance(pCity.getX(), pCity.getY(), pTamils.getCapitalCity().getX(), pTamils.getCapitalCity().getY())
			lEnemyCities.append((iDist, pCity))
			
		lEnemyCities.sort()
		
		for i in range(iNumTargets):
			if lEnemyCities:
				pTargetCity = lEnemyCities.pop(0)[1]
				tPlot = utils.findNearestLandPlot((pTargetCity.getX(), pTargetCity.getY()), iTamils)
				
				utils.makeUnitAI(iSwordsman, iTamils, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 2)
				utils.makeUnitAI(iWarElephant, iTamils, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 1)
				utils.makeUnitAI(iCatapult, iTamils, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 1)
				
		CyInterface().addMessage(iEnemy, False, iDuration, CyTranslator().getText("TXT_KEY_UP_TAMIL_CONQUESTS_TARGET", ()), "", 0, "", ColorTypes(iWhite), -1, -1, True, True)
	def embraceReformation(self, iCiv):
		iNumCatholicCities = 0
		for city in utils.getCityList(iCiv):
			if city.isHasReligion(iCatholicism):
				iNumCatholicCities += 1
				
				city.replaceReligion(iCatholicism, iProtestantism)
				
				if city.getPopulation() > 7:
					if not self.chooseProtestantism(iCiv):
						city.setHasReligion(iCatholicism, True, False, False)
				
		pPlayer = gc.getPlayer(iCiv)
		pPlayer.changeGold(iNumCatholicCities*100)
		
		pPlayer.setLastStateReligion(iProtestantism)
		pPlayer.setConversionTimer(10)
		
		if iCiv < iNumPlayers:
			data.players[iCiv].iReformationDecision = 0
예제 #50
0
    def computeAliyahBonus(self):
        capital = gc.getPlayer(iIsrael).getCapitalCity()

        #count all cities with Judaism in civs who have open borders with Israel
        openjewishcities = 0
        for iPlayer in range(iNumPlayers):
            if gc.getTeam(iPlayer).isOpenBorders(iIsrael):
                openjewishcities += len([
                    city for city in utils.getCityList(iPlayer)
                    if city.isHasReligion(iJudaism)
                ])

        capital.setBuildingYieldChange(
            gc.getBuildingInfo(iPalace).getBuildingClassType(), 0,
            openjewishcities)
        capital.setBuildingYieldChange(
            gc.getBuildingInfo(iPalace).getBuildingClassType(), 1,
            openjewishcities)
        capital.setBuildingYieldChange(
            gc.getBuildingInfo(iPalace).getBuildingClassType(), 2,
            openjewishcities)
	def checkChristianity(self, iGameTurn):
		if not gc.getGame().isReligionFounded(iJudaism): return
		if gc.getGame().isReligionFounded(iOrthodoxy): return
		
		iEthiopiaOffset = 0
		if utils.getHumanID() == iEthiopia: iEthiopiaOffset = utils.getTurns(10 + data.iSeed % 5)
		iOffset = utils.getTurns(data.iSeed % 15)
		
		if iGameTurn == getTurnForYear(0) + iOffset + iEthiopiaOffset:
			pHolyCity = gc.getGame().getHolyCity(iJudaism)
			
			if pHolyCity.getOwner() != utils.getHumanID() and gc.getGame().getSorenRandNum(2, "Holy city?") == 0:
				pChristianCity = pHolyCity
				self.foundReligion((pChristianCity.getX(), pChristianCity.getY()), iOrthodoxy)
				return

			lJewishCities = []
			for iPlayer in range(iNumTotalPlayersB):
				lJewishCities.extend([city for city in utils.getCityList(iPlayer) if city.isHasReligion(iJudaism) and city.getOwner() != utils.getHumanID()])
							
			if lJewishCities:
				pChristianCity = utils.getRandomEntry(lJewishCities)
				self.foundReligion((pChristianCity.getX(), pChristianCity.getY()), iOrthodoxy)
예제 #52
0
	def selectClaims(self, iPlayer):
		pPlayer = gc.getPlayer(iPlayer)
		iGameTurn = gc.getGame().getGameTurn()
		iNumPlayersAlive = gc.getGame().countCivPlayersAlive()
		lPlots = []
		
		for iLoopPlayer in range(iNumTotalPlayers+1):
			if iLoopPlayer == iPlayer: continue
			if not gc.getPlayer(iLoopPlayer).isAlive(): continue
			
			# after a war: winners can only claim from losers and vice versa
			if self.bPostWar:
				if iPlayer in self.lWinners and iLoopPlayer not in self.lLosers: continue
				if iPlayer in self.lLosers and iLoopPlayer not in self.lWinners: continue
				
			# AI civs: cannot claim cities from friends
			if utils.getHumanID() != iPlayer and pPlayer.AI_getAttitude(iLoopPlayer) >= AttitudeTypes.ATTITUDE_FRIENDLY: continue
			
			# recently born
			if iGameTurn < getTurnForYear(tBirth[iLoopPlayer]) + utils.getTurns(20): continue
			
			# recently resurrected
			if iGameTurn < pPlayer.getLatestRebellionTurn() + utils.getTurns(20): continue
			
			# recently reborn
			if utils.isReborn(iLoopPlayer) and tRebirth != -1 and iGameTurn < getTurnForYear(tRebirth[iLoopPlayer]) + utils.getTurns(20): continue
			
			# exclude master/vassal relationships
			if gc.getTeam(iPlayer).isVassal(iLoopPlayer): continue
			if gc.getTeam(iLoopPlayer).isVassal(iPlayer): continue
			
			# cannot demand cities while at war
			if gc.getTeam(iPlayer).isAtWar(iLoopPlayer): continue
			
			for city in utils.getCityList(iLoopPlayer):
				x, y = city.getX(), city.getY()
				plot = gc.getMap().plot(x, y)
				iSettlerMapValue = plot.getSettlerValue(iPlayer)
				iValue = 0
				
				if not plot.isRevealed(iPlayer, False): continue
				if city.isCapital(): continue
				
				# after a war: losers can only claim previously owned cities
				if self.bPostWar and iPlayer in self.lLosers:
					if city.getGameTurnPlayerLost(iPlayer) < gc.getGame().getGameTurn() - utils.getTurns(25): continue
				
				# city culture
				iTotalCulture = city.countTotalCultureTimes100()
				if iTotalCulture > 0:
					iCultureRatio = city.getCultureTimes100(iPlayer) * 100 / iTotalCulture
					if iCultureRatio > 20:
						if iLoopPlayer != iAmerica:
							iValue += iCultureRatio / 20
							
				# ever owned
				if city.isEverOwned(iPlayer):
					iValue += 3
						
				# own core
				if plot.isCore(iPlayer):
					iValue += 5
							
				# colonies
				if iPlayer in lCivGroups[0]:
					if iLoopPlayer >= iNumPlayers or (iLoopPlayer not in lCivGroups[0] and utils.getStabilityLevel(iLoopPlayer) < iStabilityShaky) or (iLoopPlayer in lCivGroups[0] and utils.getHumanID() != iLoopPlayer and pPlayer.AI_getAttitude(iLoopPlayer) < AttitudeTypes.ATTITUDE_PLEASED):
						if plot.getRegionID() not in lEurope and plot.getRegionID() not in lMiddleEast:
							if iSettlerMapValue > 90:
								iValue += max(1, iSettlerMapValue / 100)
									
				# weaker and collapsing empires
				if iLoopPlayer < iNumPlayers:
					if gc.getGame().getPlayerRank(iLoopPlayer) > iNumPlayersAlive / 2 and gc.getGame().getPlayerRank(iLoopPlayer) < iNumPlayersAlive / 2:
						if data.players[iLoopPlayer].iStabilityLevel == iStabilityCollapsing:
							if iSettlerMapValue >= 90:
								iValue += max(1, iSettlerMapValue / 100)
									
				# close to own empire
				closestCity = gc.getMap().findCity(x, y, iPlayer, TeamTypes.NO_TEAM, False, False, TeamTypes.NO_TEAM, DirectionTypes.NO_DIRECTION, city)
				iDistance = stepDistance(x, y, closestCity.getX(), closestCity.getY())
				if iDistance < 5:
					iValue += 5-iDistance
					
				# after war: war targets
				if self.bPostWar:
					iValue += plot.getWarValue(iPlayer) / 2
					
				# AI America receives extra value for claims in the west
				if iPlayer == iAmerica and utils.getHumanID() != iPlayer:
					if utils.isPlotInArea((x, y), tAmericanClaimsTL, tAmericanClaimsBR):
						iValue += 5
						
				# help AI Australia gain Australia
				if iPlayer == iAustralia and utils.getHumanID() != iPlayer:
					if utils.isPlotInArea((x, y), tAustraliaTL, tAustraliaBR):
						iValue += 5
						
				# help Canada gain Labrador and Newfoundland
				if iPlayer == iCanada:
					if utils.isPlotInArea((x, y), tNewfoundlandTL, tNewfoundlandBR):
						iValue += 5
					
				if iValue > 0:
					lPlots.append((x, y, iValue))
		
		# extra spots for colonial civs -> will be settled
		# not available after wars because these congresses are supposed to reassign cities
		if iPlayer in lCivGroups[0] and not self.bPostWar:
			for (x, y) in utils.getWorldPlotsList():
				if utils.getHumanID() == iPlayer and not plot.isRevealed(iPlayer, False): continue
				plot = gc.getMap().plot(x, y)
				if not plot.isCity() and not plot.isPeak() and not plot.isWater() and pPlayer.canFound(x, y):
					if plot.getRegionID() in [rWestAfrica, rSouthAfrica, rEthiopia] or (plot.getRegionID() == [rAustralia, rOceania] and gc.getGame().getGameTurn() < tBirth[iAustralia]) or (plot.getRegionID() == rSouthAfrica and gc.getGame().getGameTurn() < tBirth[iBoers]):
						iSettlerMapValue = plot.getSettlerValue(iPlayer)
						if iSettlerMapValue >= 90 and cnm.getFoundName(iPlayer, (x, y)):
							closestCity = gc.getMap().findCity(x, y, PlayerTypes.NO_PLAYER, TeamTypes.NO_TEAM, False, False, TeamTypes.NO_TEAM, DirectionTypes.NO_DIRECTION, CyCity())
							if stepDistance(x, y, closestCity.getX(), closestCity.getY()) > 2:
								lPlots.append((x, y, max(1, iSettlerMapValue / 100 - 1)))
						
		lPlots = utils.getSortedList(lPlots, lambda x: x[2] + gc.getGame().getSorenRandNum(3, 'Randomize city value'), True)
		return lPlots[:10]
	def doImmigration(self):
	
		# get available migration and immigration cities
		lSourceCities = []
		lTargetCities = []
		
		for iPlayer in range(iNumPlayers):
			if iPlayer in lCivBioNewWorld and not utils.isReborn(iPlayer): continue # no immigration to natives
			pPlayer = gc.getPlayer(iPlayer)
			lCities = []
			bNewWorld = pPlayer.getCapitalCity().getRegionID() in lNewWorld
			for city in utils.getCityList(iPlayer):
				iFoodDifference = city.foodDifference(False)
				iHappinessDifference = city.happyLevel() - city.unhappyLevel(0)
				if city.getRegionID() in lNewWorld and bNewWorld:
					if iFoodDifference <= 0 or iHappinessDifference <= 0: continue
					iNorthAmericaBonus = 0
					if city.getRegionID() in [rCanada, rUnitedStates]: iNorthAmericaBonus = 5
					lCities.append((city, iHappinessDifference + iFoodDifference / 2 + city.getPopulation() / 2 + iNorthAmericaBonus))
				elif city.getRegionID() not in lNewWorld and not bNewWorld:
					iValue = 0
					if iFoodDifference < 0:
						iValue -= iFoodDifference / 2
					if iHappinessDifference < 0:
						iValue -= iHappinessDifference
					if iValue > 0:
						lCities.append((city, iValue))
			
			if lCities:
				lCities.sort(key=itemgetter(1), reverse=True)
			
				if bNewWorld:
					lTargetCities.append(lCities[0])
				else:
					lSourceCities.append(lCities[0])
				
		# sort highest to lowest for happiness/unhappiness
		lSourceCities.sort(key=itemgetter(1), reverse=True)
		lTargetCities.sort(key=itemgetter(1), reverse=True)
		
		#utils.debugTextPopup(str([(x.getName(), y) for (x,y) in lTargetCities]))
		#utils.debugTextPopup("Target city: "+targetCity.getName())
		#utils.debugTextPopup("Source city: "+sourceCity.getName())
		
		iNumMigrations = min(len(lSourceCities) / 4, len(lTargetCities))
		
		for iMigration in range(iNumMigrations):
			sourceCity = lSourceCities[iMigration][0]
			targetCity = lTargetCities[iMigration][0]
		
			sourceCity.changePopulation(-1)
			targetCity.changePopulation(1)
			
			if sourceCity.getPopulation() >= 9:
				sourceCity.changePopulation(-1)
				targetCity.changePopulation(1)
				
			# extra cottage growth for target city's vicinity
			x = targetCity.getX()
			y = targetCity.getY()
			for (i, j) in utils.surroundingPlots((x, y), 2):
				pCurrent = gc.getMap().plot(i, j)
				if pCurrent.getWorkingCity() == targetCity:
					pCurrent.changeUpgradeProgress(utils.getTurns(10))
						
			# migration brings culture
			targetPlot = gc.getMap().plot(x, y)
			iTargetPlayer = targetCity.getOwner()
			iSourcePlayer = sourceCity.getOwner()
			iCultureChange = targetPlot.getCulture(iTargetPlayer) / targetCity.getPopulation()
			targetPlot.setCulture(iSourcePlayer, iCultureChange, False)
			
			# chance to spread state religion if in source city
			if gc.getPlayer(iSourcePlayer).isStateReligion():
				iReligion = gc.getPlayer(iSourcePlayer).getStateReligion()
				if sourceCity.isHasReligion(iReligion) and not targetCity.isHasReligion(iReligion):
					iRandom = gc.getGame().getSorenRandNum(3, 'random religion spread')
					if iRandom == 0:
						targetCity.setHasReligion(iReligion, True, True, True)
						
			# notify affected players
			if utils.getHumanID() == iSourcePlayer:
				CyInterface().addMessage(iSourcePlayer, False, iDuration, CyTranslator().getText("TXT_KEY_UP_EMIGRATION", (sourceCity.getName(),)), "", InterfaceMessageTypes.MESSAGE_TYPE_MINOR_EVENT, gc.getUnitInfo(iSettler).getButton(), ColorTypes(iYellow), sourceCity.getX(), sourceCity.getY(), True, True)
			elif utils.getHumanID() == iTargetPlayer:
				CyInterface().addMessage(iTargetPlayer, False, iDuration, CyTranslator().getText("TXT_KEY_UP_IMMIGRATION", (targetCity.getName(),)), "", InterfaceMessageTypes.MESSAGE_TYPE_MINOR_EVENT, gc.getUnitInfo(iSettler).getButton(), ColorTypes(iYellow), x, y, True, True)
	
			if iTargetPlayer == iCanada:
				self.canadianUP(targetCity)
	def selectRandomCityCiv(self, iCiv): # Unused
		if gc.getPlayer(iCiv).isAlive():
			city = utils.getRandomEntry(utils.getCityList(iCiv))
			if city:
				return (city.getX(), city.getY())
		return False
	def getReligionCities(self, iReligion): # Unused
		lCities = []
		for iPlayer in range(iNumTotalPlayersB):
			lCities.extend(utils.getCityList(iPlayer))
			
		return [city for city in lCities if city.isHasReligion(iReligion)]
	def selectClaims(self, iPlayer):
		pPlayer = gc.getPlayer(iPlayer)
		iGameTurn = gc.getGame().getGameTurn()
		iNumPlayersAlive = gc.getGame().countCivPlayersAlive()
		lPlots = []
		
		for iLoopPlayer in range(iNumTotalPlayers+1):
			if iLoopPlayer == iPlayer: continue
			if not gc.getPlayer(iLoopPlayer).isAlive(): continue
			
			# after a war: winners can only claim from losers and vice versa
			if self.bPostWar:
				if iPlayer in self.lWinners and iLoopPlayer not in self.lLosers: continue
				if iPlayer in self.lLosers and iLoopPlayer not in self.lWinners: continue
				
			# AI civs: cannot claim cities from friends
			if utils.getHumanID() != iPlayer and pPlayer.AI_getAttitude(iLoopPlayer) >= AttitudeTypes.ATTITUDE_FRIENDLY: continue
			
			# recently born
			if iGameTurn < getTurnForYear(tBirth[iLoopPlayer]) + utils.getTurns(20): continue
			
			# recently resurrected
			if iGameTurn < pPlayer.getLatestRebellionTurn() + utils.getTurns(20): continue
			
			# recently reborn
			if utils.isReborn(iLoopPlayer) and tRebirth != -1 and iGameTurn < getTurnForYear(tRebirth[iLoopPlayer]) + utils.getTurns(20): continue
			
			# exclude master/vassal relationships
			if gc.getTeam(iPlayer).isVassal(iLoopPlayer): continue
			if gc.getTeam(iLoopPlayer).isVassal(iPlayer): continue
			
			# cannot demand cities while at war
			if gc.getTeam(iPlayer).isAtWar(iLoopPlayer): continue
			
			for city in utils.getCityList(iLoopPlayer):
				x, y = city.getX(), city.getY()
				plot = gc.getMap().plot(x, y)
				iSettlerMapValue = plot.getSettlerValue(iPlayer)
				iValue = 0
				
				if not plot.isRevealed(iPlayer, False): continue
				if city.isCapital(): continue
				
				# after a war: losers can only claim previously owned cities
				if self.bPostWar and iPlayer in self.lLosers:
					if city.getGameTurnPlayerLost(iPlayer) < gc.getGame().getGameTurn() - utils.getTurns(25): continue
				
				# city culture
				iTotalCulture = city.countTotalCultureTimes100()
				if iTotalCulture > 0:
					iCultureRatio = city.getCultureTimes100(iPlayer) * 100 / iTotalCulture
					if iCultureRatio > 20:
						if iLoopPlayer != iAmerica:
							iValue += iCultureRatio / 20
							
				# ever owned
				if city.isEverOwned(iPlayer):
					iValue += 3
						
				# own core
				if plot.isCore(iPlayer):
					iValue += 5
							
				# colonies
				if iPlayer in lCivGroups[0]:
					if iLoopPlayer >= iNumPlayers or (iLoopPlayer not in lCivGroups[0] and utils.getStabilityLevel(iLoopPlayer) < iStabilityShaky) or (iLoopPlayer in lCivGroups[0] and utils.getHumanID() != iLoopPlayer and pPlayer.AI_getAttitude(iLoopPlayer) < AttitudeTypes.ATTITUDE_PLEASED):
						if plot.getRegionID() not in lEurope and plot.getRegionID() not in lMiddleEast:
							if iSettlerMapValue > 90:
								iValue += max(1, iSettlerMapValue / 100)
									
				# weaker and collapsing empires
				if iLoopPlayer < iNumPlayers:
					if gc.getGame().getPlayerRank(iLoopPlayer) > iNumPlayersAlive / 2 and gc.getGame().getPlayerRank(iLoopPlayer) < iNumPlayersAlive / 2:
						if data.players[iLoopPlayer].iStabilityLevel == iStabilityCollapsing:
							if iSettlerMapValue >= 90:
								iValue += max(1, iSettlerMapValue / 100)
									
				# close to own empire
				closestCity = gc.getMap().findCity(x, y, iPlayer, TeamTypes.NO_TEAM, False, False, TeamTypes.NO_TEAM, DirectionTypes.NO_DIRECTION, city)
				iDistance = stepDistance(x, y, closestCity.getX(), closestCity.getY())
				if iDistance < 5:
					iValue += 5-iDistance
					
				# after war: war targets
				if self.bPostWar:
					iValue += plot.getWarValue(iPlayer) / 2
					
				# AI America receives extra value for claims in the west
				if iPlayer == iAmerica and utils.getHumanID() != iPlayer:
					if utils.isPlotInArea((x, y), tAmericanClaimsTL, tAmericanClaimsBR):
						iValue += 5
						
				# help Canada gain Labrador and Newfoundland
				if iPlayer == iCanada:
					if utils.isPlotInArea((x, y), tNewfoundlandTL, tNewfoundlandBR):
						iValue += 5
					
				if iValue > 0:
					lPlots.append((x, y, iValue))
		
		# extra spots for colonial civs -> will be settled
		# not available after wars because these congresses are supposed to reassign cities
		if iPlayer in lCivGroups[0] and not self.bPostWar:
			for (x, y) in utils.getWorldPlotsList():
				if utils.getHumanID() == iPlayer and not plot.isRevealed(iPlayer, False): continue
				plot = gc.getMap().plot(x, y)
				if not plot.isCity() and not plot.isPeak() and not plot.isWater() and pPlayer.canFound(x, y):
					if plot.getRegionID() in [rWestAfrica, rSouthAfrica, rEthiopia, rAustralia, rOceania]:
						iSettlerMapValue = plot.getSettlerValue(iPlayer)
						if iSettlerMapValue >= 90 and cnm.getFoundName(iPlayer, (x, y)):
							closestCity = gc.getMap().findCity(x, y, PlayerTypes.NO_PLAYER, TeamTypes.NO_TEAM, False, False, TeamTypes.NO_TEAM, DirectionTypes.NO_DIRECTION, CyCity())
							if stepDistance(x, y, closestCity.getX(), closestCity.getY()) > 2:
								lPlots.append((x, y, max(1, iSettlerMapValue / 100 - 1)))
						
		lPlots = utils.getSortedList(lPlots, lambda x: x[2] + gc.getGame().getSorenRandNum(3, 'Randomize city value'), True)
		return lPlots[:10]
	def selectRandomCitySourceCiv(self, iCiv): # Unused
		if gc.getPlayer(iCiv).isAlive():
			cityList = [city for city in utils.getCityList(iCiv) if city.getPopulation() > 1]
			if cityList:
				return getRandomEntry(cityList)
		return False
	def onTechAcquired(self, argsList):
		iTech, iTeam, iPlayer, bAnnounce = argsList

		iHuman = utils.getHumanID()
		
		iEra = gc.getTechInfo(iTech).getEra()
		
		if utils.getScenario() == i600AD and gc.getGame().getGameTurn() == getTurnForYear(600): #late start condition
			return
			
		if utils.getScenario() == i1700AD and gc.getGame().getGameTurn() == getTurnForYear(1700):
			return
			
		sta.onTechAcquired(iPlayer, iTech)
		AIParameters.onTechAcquired(iPlayer, iTech)
		
		if gc.getGame().getGameTurn() > getTurnForYear(tBirth[iPlayer]):
			vic.onTechAcquired(iPlayer, iTech)
			cnm.onTechAcquired(argsList[2])

		if gc.getPlayer(iPlayer).isAlive() and gc.getGame().getGameTurn() > getTurnForYear(tBirth[iPlayer]) and iPlayer < iNumPlayers:
			self.rel.onTechAcquired(argsList[0], argsList[2])
			if (gc.getGame().getGameTurn() > getTurnForYear(1700)):
				self.aiw.forgetMemory(argsList[0], argsList[2])

		if iTech == iAstronomy:
			if iPlayer in [iSpain, iFrance, iEngland, iGermany, iVikings, iNetherlands, iPortugal]:
				data.players[iPlayer].iAstronomyTurn = gc.getGame().getGameTurn()
				
		elif iTech == iCompass:
			if iPlayer == iVikings:
				gc.getMap().plot(49, 62).setTerrainType(iCoast, True, True)
				
		elif iTech == iMedicine:
			self.pla.onTechAcquired(argsList[0], argsList[2])

		elif iTech == iRailroad:
			self.rnf.onRailroadDiscovered(argsList[2])
			
		if iTech in [iAstronomy, iGunpowder]:
			teamPlayer = gc.getTeam(iPlayer)
			if teamPlayer.isHasTech(iAstronomy) and teamPlayer.isHasTech(iGunpowder):
				self.rnf.earlyTradingCompany(iPlayer)
			
		if iTech in [iEconomics, iRifling]:
			teamPlayer = gc.getTeam(iPlayer)
			if teamPlayer.isHasTech(iEconomics) and teamPlayer.isHasTech(iRifling):
				self.rnf.lateTradingCompany(iPlayer)
	
		if utils.getHumanID() != iPlayer:
			if iPlayer == iJapan and iEra == iIndustrial:
				utils.moveCapital(iPlayer, (116, 47)) # Toukyou
			elif iPlayer == iItaly and iEra == iIndustrial:
				utils.moveCapital(iPlayer, (60, 44)) # Roma
			elif iPlayer == iVikings and iEra == iRenaissance:
				utils.moveCapital(iPlayer, (63, 59)) # Stockholm
			elif iPlayer == iHolyRome and iEra == iRenaissance:
				utils.moveCapital(iPlayer, (62, 49)) # Wien
				
		# Spain's core extends when reaching the Renaissance and there are no Moors in Iberia
		# at the same time, the Moorish core relocates to Africa
		if iPlayer == iSpain and iEra == iRenaissance and not utils.isReborn(iSpain):
			bNoMoors = True
			if gc.getPlayer(iMoors).isAlive():
				for city in utils.getCityList(iMoors):
					if city.plot().getRegionID() == rIberia:
						bNoMoors = False
			if bNoMoors:
				utils.setReborn(iSpain, True)
				utils.setReborn(iMoors, True)
				
		# Italy's core extends when reaching the Industrial era
		if iPlayer == iItaly and iEra == iIndustrial:
			utils.setReborn(iItaly, True)
			
		# Arabia's core moves to Iraq when Philosophy is discovered
		if iPlayer == iArabia and iTech == iPhilosophy:
			utils.setReborn(iArabia, True)
			
		# Japan's core extends when reaching the Industrial era
		if iPlayer == iJapan and iEra == iIndustrial:
			utils.setReborn(iJapan, True)
			
		# Germany's core shrinks when reaching the Modern era
		if iPlayer == iGermany and iEra == iModern:
			utils.setReborn(iGermany, True)
	def infectCitiesNear(self, iPlayer, startingX, startingY):
		for city in utils.getCityList(iPlayer):
			if utils.calculateDistance(city.getX(), city.getY(), startingX, startingY) <= 3:
				self.infectCity(city)
				self.announceForeignPlagueSpread(city)