convertSurroundingCities(self, iCiv, plotList, fBarbOnly = False):
iConvertedCitiesCount = 0
iNumHumanCities = 0
cityList = []
self.setSpawnWar(0)
#collect all the cities in the spawn region
for i in range(len(plotList)):
pCurrent = gc.getMap().plot(plotList[i][0], plotList[i][1])
if pCurrent.isCity():
if pCurrent.getPlotCity().getOwner() != iCiv:
if not fBarbOnly or pCurrent.getPlotCity().getOwner() == iBarbarian:
cityList.append(pCurrent.getPlotCity())
#print ("Birth", iCiv)
#print (cityList)
#for each city
if len(cityList):
for i in range(len(cityList)):
loopCity = cityList[i]
loopX = loopCity.getX()
loopY = loopCity.getY()
#print ("cityList", loopCity.getName(), (loopX, loopY))
iHuman = utils.getHumanID()
iOwner = loopCity.getOwner()
iCultureChange = 0 #if 0, no flip; if > 0, flip will occur with the value as variable for utils.CultureManager()
#case 1: barbarian/independent city
if (iOwner >= iNumPlayers):
#utils.debugTextPopup( 'BARB' )
iCultureChange = 100
#case 2: human city
#elif (iOwner == iHuman and not loopCity.isCapital()): #exploitable
elif (iOwner == iHuman and not (loopX == tCapitals[iHuman] and loopY == tCapitals[iHuman]) and not gc.getPlayer(iHuman).getNumCities() <= 1 and not (self.getCheatMode() == True and loopCity.isCapital())):
#utils.debugTextPopup( 'HUMAN' )
## bForeigners = False
## cityPlot = gc.getMap().plot(cityList[i].getX(), cityList[i].getY())
## cityCulture = cityList[i].countTotalCulture()
## iCultureThreshold = 10
## for j in range(iNumPlayers+1):
## if (cityList[i].getCulture(j)*100 / cityCulture >= iCultureThreshold) and (j != iHuman):
## bForeigners = True
## humanCapital = gc.getPlayer(iHuman).getCapitalCity()
## iDistance = gc.getMap().calculatePathDistance(cityPlot, gc.getMap().plot(humanCapital.getX(),humanCapital.getY()))
## if (cityList[i].isOccupation()) or (cityList[i].isDisorder()) or (bForeigners == True) or (not cityPlot.getNumUnits()) or ((not cityList[i].isGovernmentCenter()) and (iDistance >= 8) and (gc.getPlayer(iHuman).getNumCities() >= 5)):
if (iNumHumanCities == 0):
iNumHumanCities += 1
#iConvertedCitiesCount += 1
#self.flipPopup(iCiv, plotList)
#case 3: other
elif (not loopCity.isCapital()): #utils.debugTextPopup( 'OTHER' )
if (iConvertedCitiesCount < 6): #there won't be more than 5 flips in the area
#utils.debugTextPopup( 'iConvertedCities OK' )
iCultureChange = 50
if (gc.getGame().getGameTurn() <= getTurnForYear(tBirth[iCiv]) + 5): #if we're during a birth
rndNum = gc.getGame().getSorenRandNum(100, 'odds')
if (rndNum >= tAIStopBirthThreshold[iOwner]):
print (iOwner, "stops birth", iCiv, "rndNum:", rndNum, "threshold:", tAIStopBirthThreshold[iOwner])
if (not gc.getTeam(gc.getPlayer(iOwner).getTeam()).isAtWar(iCiv)):
gc.getTeam(gc.getPlayer(iOwner).getTeam()).declareWar(iCiv, False, -1)
if (gc.getPlayer(iCiv).getNumCities() > 0): #this check is needed, otherwise game crashes
print ("capital:", gc.getPlayer(iCiv).getCapitalCity().getX(), gc.getPlayer(iCiv).getCapitalCity().getY())
if (gc.getPlayer(iCiv).getCapitalCity().getX() != -1 and gc.getPlayer(iCiv).getCapitalCity().getY() != -1):
self.createAdditionalUnits(iCiv, (gc.getPlayer(iCiv).getCapitalCity().getX(), gc.getPlayer(iCiv).getCapitalCity().getY()))
else:
self.createAdditionalUnits(iCiv, tCapitals[iCiv])
if (iCultureChange > 0):
#print ("flipping ", cityList[i].getName())
utils.cultureManager((loopX, loopY), iCultureChange, iCiv, iOwner, True, False, False)
#gc.getMap().plot(cityList[i].getX(),cityList[i].getY()).setImprovementType(-1)
utils.flipUnitsInCityBefore((loopX, loopY), iCiv, iOwner)
self.setTempFlippingCity((loopX, loopY)) #necessary for the (688379128, 0) bug
utils.flipCity((loopX, loopY), 0, 0, iCiv, [iOwner])
#print ("cityList[i].getXY", cityList[i].getX(), cityList[i].getY())
utils.flipUnitsInCityAfter(self.getTempFlippingCity(), iCiv)
#iEra = gc.getPlayer(iCiv).getCurrentEra()
#if (iEra >= 2): #medieval
# if (loopCity.getPopulation() < iEra):
# loopCity.setPopulation(iEra) #causes an unidentifiable C++ exception
#doesn't work (assigns UBs too)
#for iLoopBuilding in range(iNumBuildingsPlague):
# if (gc.getBuildingInfo(iLoopBuilding).getFreeStartEra() >= 0):
# if (iEra >= gc.getBuildingInfo(iLoopBuilding).getFreeStartEra()):
# print (iEra, iLoopBuilding, gc.getBuildingInfo(iLoopBuilding).getFreeStartEra(), loopCity.canConstruct(iLoopBuilding, False, False, False))
# if (loopCity.canConstruct(iLoopBuilding, False, False, False)):
# if (not loopCity.hasBuilding(iLoopBuilding)):
# loopCity.setHasRealBuilding(iLoopBuilding, True)
#cityList[i].setHasRealBuilding(iPlague, False) #buggy
iConvertedCitiesCount += 1
print ("iConvertedCitiesCount", iConvertedCitiesCount)
if (iConvertedCitiesCount > 0):
if (gc.getPlayer(iCiv).isHuman()):
CyInterface().addMessage(iCiv, True, iDuration, CyTranslator().getText("TXT_KEY_FLIP_TO_US", ()), "", 0, "", ColorTypes(iGreen), -1, -1, True, True)
#print( "converted cities", iConvertedCitiesCount)
return (iConvertedCitiesCount, iNumHumanCities)