def placeNaturalWonders(self):
map = CyMap()
def hasRiverToNorth(pPlot):
y = pPlot.getY()
if y + 1 >= map.getGridHeight(): return False
pNorth = map.plot(pPlot.getX(), y + 1)
return pNorth.isRiverNS() and pNorth.getRiverNSDirection() == CardinalDirectionTypes.CARDINALDIRECTION_SOUTH
def hasRiverToEast(pPlot):
return pPlot.isRiverWOfPlot() and pPlot.getRiverWEDirection() == CardinalDirectionTypes.CARDINALDIRECTION_WEST
def hasRiverToWest(pPlot):
x = pPlot.getX()
if x - 1 < 0: return False
pWest = map.plot(x - 1, pPlot.getY())
return pPlot.isRiverWOfPlot() and pPlot.getRiverWEDirection() == CardinalDirectionTypes.CARDINALDIRECTION_EAST
for iFeature in xrange(gc.getNumFeatureInfos()):
FeatureInfo = gc.getFeatureInfo(iFeature)
sType = FeatureInfo.getType()
if sType.find("FEATURE_PLATY_") == -1: continue
if random.randint(1, 100) >= self.iPlaceChance: continue
# === FEATURE_PLATY_EVEREST ===
if sType == "FEATURE_PLATY_EVEREST":
ValidPeakPlots = []
for i in range(map.numPlots()):
pPlot = map.plotByIndex(i)
if not pPlot.isPeak(): continue
iX, iY = pPlot.getX(), pPlot.getY()
iPeakCount = 0
for dx in range(-2, 3):
for dy in range(-2, 3):
if dx == 0 and dy == 0: continue
pLoop = map.plot(iX + dx, iY + dy)
if not pLoop.isNone() and pLoop.isPeak():
iPeakCount += 1
if iPeakCount >= 5:
ValidPeakPlots.append(pPlot)
if ValidPeakPlots:
iRand = CyGame().getSorenRandNum(len(ValidPeakPlots), "Everest")
ValidPeakPlots[iRand].setFeatureType(iFeature, 0)
continue
# === FEATURE_PLATY_VICTORIA_FALLS ===
elif sType == "FEATURE_PLATY_VICTORIA_FALLS":
for i in xrange(map.numPlots()):
pPlot = map.plotByIndex(i)
if pPlot.isWater() or pPlot.getFeatureType() != FeatureTypes.NO_FEATURE:
continue
if hasRiverToNorth(pPlot) and hasRiverToEast(pPlot):
pPlot.setFeatureType(iFeature, 0)
break
continue
# === FEATURE_PLATY_GRAND_CANYON ===
elif sType == "FEATURE_PLATY_GRAND_CANYON":
for i in xrange(map.numPlots()):
pPlot = map.plotByIndex(i)
if pPlot.isWater() or pPlot.getFeatureType() != FeatureTypes.NO_FEATURE:
continue
if hasRiverToNorth(pPlot) and hasRiverToWest(pPlot):
pPlot.setFeatureType(iFeature, 0)
break
continue
# === Default Wonder Placement ===
WonderPlot = []
for i in xrange(map.numPlots()):
pPlot = map.plotByIndex(i)
if pPlot.getBonusType(-1) > -1: continue
## Nearby Plot Check ##
bUnsuitable = False
iRadius = self.iNoNearbyRadius
bAdjacentPlot = True
if sType in self.lBigWonder:
iRadius += 1
bAdjacentPlot = False
for x in xrange(pPlot.getX() - iRadius, pPlot.getX() + iRadius + 1):
for y in xrange(pPlot.getY() - iRadius, pPlot.getY() + iRadius + 1):
pAdj = map.plot(x, y)
if pAdj.getFeatureType() > -1 and gc.getFeatureInfo(pAdj.getFeatureType()).getType().find("FEATURE_PLATY_") > -1:
bUnsuitable = True
break
if not bAdjacentPlot and pAdj.canHaveFeature(iFeature):
if abs(pAdj.getX() - pPlot.getX()) > 1: continue
if abs(pAdj.getY() - pPlot.getY()) > 1: continue
if pAdj.getBonusType(-1) > -1: continue
bAdjacentPlot = True
if bUnsuitable: break
if bUnsuitable: continue
## Latitude Check ##
if sType in self.lLatitude:
if pPlot.getLatitude() < self.lLatitude[sType][0] or pPlot.getLatitude() > self.lLatitude[sType][1]:
continue
if pPlot.canHaveFeature(iFeature) and bAdjacentPlot:
WonderPlot.append(pPlot)
bWonder = False
while WonderPlot:
iWonderPlot = random.randint(0, len(WonderPlot) - 1)
pPlot = WonderPlot[iWonderPlot]
if sType in self.lBigWonder:
AdjacentPlot = []
for x in xrange(pPlot.getX() - 1, pPlot.getX() + 2):
for y in xrange(pPlot.getY() - 1, pPlot.getY() + 2):
if x == pPlot.getX() and y == pPlot.getY(): continue
pAdj = map.plot(x, y)
if pAdj.getBonusType(-1) > -1: continue
if pAdj.canHaveFeature(iFeature):
AdjacentPlot.append(pAdj)
if not AdjacentPlot:
del WonderPlot[iWonderPlot]
if WonderPlot:
continue
else:
break
pAdj = AdjacentPlot[random.randint(0, len(AdjacentPlot) - 1)]
pAdj.setFeatureType(iFeature, 0)
for yieldType in [YieldTypes.YIELD_FOOD, YieldTypes.YIELD_PRODUCTION, YieldTypes.YIELD_COMMERCE]:
CyGame().setPlotExtraYield(pAdj.getX(), pAdj.getY(), yieldType, random.randint(0, self.iMaxYield))
bWonder = True
break
bWonder = True
break
if bWonder:
pPlot.setFeatureType(iFeature, 0)
for yieldType in [YieldTypes.YIELD_FOOD, YieldTypes.YIELD_PRODUCTION, YieldTypes.YIELD_COMMERCE]:
CyGame().setPlotExtraYield(pPlot.getX(), pPlot.getY(), yieldType, random.randint(0, self.iMaxYield))
sNature = sType[sType.find("_PLATY_") + 7:]
sBuildingType = "BUILDING_" + sNature
iBuilding = gc.getInfoTypeForString(sBuildingType)
if iBuilding == -1: continue
lNaturalCity = self.addSuitableCity(pPlot, -1, [])
if sType in self.lBigWonder:
lNaturalCity = self.addSuitableCity(pAdj, -1, lNaturalCity)
if lNaturalCity:
pLuckyCity = lNaturalCity[random.randint(0, len(lNaturalCity) - 1)]
pLuckyCity.setNumRealBuilding(iBuilding, 1)
return