## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005
##
## C2C Terrain Features and special resource placement.
## A post map script so that these will appear in game no matter which map script is used.
##
## by Dancing Hoskuld
##
## Resources
## 1. Place of Sea Lion(Seal) and Walrus resource only on coastal plots in tundra regions.
## 2. Place of Sea Lion(Seal) on some single plot islands.
##
## Terrain Features
## For terrain marsh
## polar regions 75% marsh has peat bog feature
## cool temperate 25% peat bog, 40% sword grass representing the tall grasses you make thatch from eg Fens in the UK
## warm temperate 25% sword grass, 40% swamp
## tropical 50% swamp and 15% papyrus
##
## All this modified with "mangrove swamp" for coastal swamps. If I can get the graphic - I was thinking the ground water one from DuneWars as a place holder
## Polar and cool temperate - no chance
## Warm temperate 50%
## Tropical 90%
##
## For Tundra
## one in ten plots get one of the polar rock formations
##
## For Desert
## one in ten plots get one of
## one of the desert rock formations
## one of the plant features (not dates or coconut)
##
## Modified by coastal deserts getting dates or coconut instead.
##
## For Forest next to a desert
## Replace with savanna
##
## For single plot islands in the warm temperate to tropical
## If no other feature get coconuts.
from CvPythonExtensions import *
import CvUtil
import sys
# globals
gc = CyGlobalContext()
def isNextToFeature(pPlot, iFeature):
iPlotX = pPlot.getX()
iPlotY = pPlot.getY()
iX = iPlotX - 1
while iX < iPlotX + 2:
iY = iPlotY - 1
while iY < iPlotY + 2:
if not ( iX == iPlotX and iY == iPlotY):
testplot = CyMap().plot(iX, iY)
if testplot.getFeatureType() == iFeature:
return True
iY = iY + 1
iX = iX + 1
return False
def isNextToTerain(pPlot, iTerrain):
iPlotX = pPlot.getX()
iPlotY = pPlot.getY()
iX = iPlotX - 1
while iX < iPlotX + 2:
iY = iPlotY - 1
while iY < iPlotY + 2:
if not ( iX == iPlotX and iY == iPlotY):
testplot = CyMap().plot(iX, iY)
if testplot.getTerrainType() == iTerrain:
return True
iY = iY + 1
iX = iX + 1
return False
def isSinglePlotIsland(pPlot):
# check that each plot around this plot is sea/coast
iPlotX = pPlot.getX()
iPlotY = pPlot.getY()
iX = iPlotX - 1
while iX < iPlotX + 2:
iY = iPlotY - 1
while iY < iPlotY + 2:
if not ( iX == iPlotX and iY == iPlotY):
testplot = CyMap().plot(iX, iY)
#~ if testplot.isFlatlands () or testplot.isHills(): # allow peaks for isolated beaches??
if not testplot.isWater ():
return False
iY = iY + 1
iX = iX + 1
return True
def isSeaCoastalLand(pPlot):
# check that at least one plot around this plot is sea/coast
if not pPlot.isCoastalLand():
return False
iPlotX = pPlot.getX()
iPlotY = pPlot.getY()
iX = iPlotX - 1
while iX < iPlotX + 2:
iY = iPlotY - 1
while iY < iPlotY + 2:
if not ( iX == iPlotX and iY == iPlotY):
testplot = CyMap().plot(iX, iY)
if testplot.isWater () and not testplot.isLake():
return True
iY = iY + 1
iX = iX + 1
return False
def placeSealOrWalrus(iPlot, iSeaLion, iWalrus):
if CyGame().getSorenRandNum(3, 'SealionResource') == 0:
iPlot.setBonusType(iWalrus)
else:
iPlot.setBonusType(iSeaLion)
return
def placeMarshFeature(iPlot, featurePeatbog, featureGrass, featureSwamp):
if iPlot.getLatitude() >= 60: # Polar
if CyGame().getSorenRandNum(99, 'TerrainFeature') < 74:
iPlot.setFeatureType(featurePeatbog, 0)
return
elif iPlot.getLatitude() >= 40: # Cool temperate
iChance = CyGame().getSorenRandNum(99, 'TerrainFeature')
if iChance < 24:
iPlot.setFeatureType(featurePeatbog, 0)
if iChance < 64:
iPlot.setFeatureType(featureGrass, 0)
return
elif iPlot.getLatitude() >= 25: # Warm temperate
iChance = CyGame().getSorenRandNum(99, 'TerrainFeature')
#~ if iPlot.isCoastal():
#~ if iChance < 49:
#~ iPlot.setFeatureType() = gc.getInfoTypeForString("FEATURE_MANGROVE")
#~ return
if iChance < 24:
iPlot.setFeatureType(featureGrass, 0)
elif iChance < 64:
iPlot.setFeatureType(featureSwamp, 0)
return
else: # Tropical
iChance = CyGame().getSorenRandNum(99, 'TerrainFeature')
#~ if iPlot.isCoastal():
#~ if iChance < 89:
#~ iPlot.setFeatureType() = gc.getInfoTypeForString("FEATURE_MANGROVE")
#~ return
#~ if iChance < 49:
#~ iPlot.setFeatureType(featureSwamp, 0)
#~ elif iChance < 64:
#~ iPlot.setFeatureType() = gc.getInfoTypeForString("FEATURE_PAPYRUS")
iPlot.setFeatureType(featureSwamp, 0)
return
return
def placePolarRockFeature(iPlot):
if CyGame().getSorenRandNum(99, 'TerrainFeature') < 90: # 10% percent chance of a rock from
return
iFormNumber = CyGame().getSorenRandNum(5, 'TerrainFeature')
if iFormNumber == 0:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_POLAR_ROCK_ARCH"), 0)
elif iFormNumber == 1:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_POLAR_ROCK_ARCH2"), 0)
elif iFormNumber == 2:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_POLAR_ROCK_FORM1"), 0)
elif iFormNumber == 3:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_POLAR_ROCK_FORM2"), 0)
elif iFormNumber == 4:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_POLAR_ROCK_FORM3"), 0)
else: # iFormNumber == 5:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_POLAR_ROCK_FORM4"), 0)
def placeDesertPlantFeature(iPlot):
if CyGame().getSorenRandNum(99, 'TerrainFeature') < 90: # 10% percent chance of a rock from
return
iFormNumber = CyGame().getSorenRandNum(1, 'TerrainFeature')
if iFormNumber == 0:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_BARREL_CACTUS"), 0)
else: # iFormNumber == 1:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_PRICKLY_PEAR"), 0)
def placeDesertRockFeature(iPlot):
if CyGame().getSorenRandNum(99, 'TerrainFeature') < 90: # 10% percent chance of a rock from
return
iFormNumber = CyGame().getSorenRandNum(11, 'TerrainFeature')
if iFormNumber == 0:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_ROCK_ARCH"), 0)
elif iFormNumber == 1:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_ROCK_ARCH2"), 0)
elif iFormNumber == 2:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_ROCK_FORM1"), 0)
elif iFormNumber == 3:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_ROCK_FORM2"), 0)
elif iFormNumber == 4:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_ROCK_FORM3"), 0)
elif iFormNumber == 5:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_ROCK_FORM4"), 0)
elif iFormNumber == 6:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_DARK_ROCK_ARCH"), 0)
elif iFormNumber == 7:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_DARK_ROCK_ARCH2"), 0)
elif iFormNumber == 8:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_DARK_ROCK_FORM1"), 0)
elif iFormNumber == 9:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_DARK_ROCK_FORM2"), 0)
elif iFormNumber == 10:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_DARK_ROCK_FORM3"), 0)
else: # iFormNumber == 11:
iPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_DARK_ROCK_FORM4"), 0)
def onGameStart(argsList):
'Called at the start of the game'
gb_GoodyHuts = True
if CyGame().isOption(GameOptionTypes.GAMEOPTION_NO_GOODY_HUTS):
gb_GoodyHuts = False
iSeaLion = gc.getInfoTypeForString("BONUS_SEA_LIONS")
iWalrus = gc.getInfoTypeForString("BONUS_WALRUS")
terrainCoast = gc.getInfoTypeForString("TERRAIN_COAST")
terrainMarsh = gc.getInfoTypeForString("TERRAIN_MARSH")
terrainTundra = gc.getInfoTypeForString("TERRAIN_TUNDRA")
terrainDesert = gc.getInfoTypeForString("TERRAIN_DESERT")
featureIce = gc.getInfoTypeForString("FEATURE_ICE")
featureReef = gc.getInfoTypeForString("FEATURE_REEF")
featureKelp = gc.getInfoTypeForString("FEATURE_KELP")
featureFossil = gc.getInfoTypeForString("FEATURE_BONES")
featureCrater = gc.getInfoTypeForString("FEATURE_CRATER")
featureTarPit = gc.getInfoTypeForString("FEATURE_TAR_PIT")
featureCoconut = gc.getInfoTypeForString("FEATURE_COCONUT")
featurePeatbog = gc.getInfoTypeForString("FEATURE_PEAT_BOG")
featureGrass = gc.getInfoTypeForString("FEATURE_SWORD_GRASS")
featureSwamp = gc.getInfoTypeForString("FEATURE_SWAMP")
improvementGoodyIsland = gc.getInfoTypeForString("IMPROVEMENT_GOODY_ISLAND")
for i in range(CyMap().numPlots()):
iPlot = CyMap().plotByIndex(i)
iLatitude = iPlot.getLatitude()
iTerrain = iPlot.getTerrainType()
#~ iFeature = iPlot.getFeatureType()
if iPlot.isWater():
if iTerrain == terrainCoast:
if not (iPlot.getFeatureType() == featureIce or iPlot.isLake() ):
if CyGame().getSorenRandNum(99, 'TerrainFeature') < 5:
iPlot.setFeatureType(featureKelp, 0)
elif CyGame().getSorenRandNum(99, 'TerrainFeature') < 5:
iPlot.setFeatureType(featureReef, 0)
if gb_GoodyHuts and CyGame().getSorenRandNum(19, 'IrgendeinTextAusDemDieZahlBerechnetWird') == 0:
iPlot.setImprovementType(improvementGoodyIsland)
else:
if (iTerrain == terrainMarsh):
placeMarshFeature(iPlot, featurePeatbog, featureGrass, featureSwamp)
if iPlot.isFlatlands() and (iPlot.getFeatureType() == -1) and (iPlot.getBonusType(-1) == -1):
if CyGame().getSorenRandNum(99, 'Fossils') == 0:
iPlot.setFeatureType(featureFossil, 0)
elif CyGame().getSorenRandNum(99, 'TarPit') == 0:
iPlot.setFeatureType(featureTarPit, 0)
elif CyGame().getSorenRandNum(990, 'Crater') == 0:
iPlot.setFeatureType(featureCrater, 0)
if (iPlot.getFeatureType() == -1) and (iTerrain == terrainDesert) and not iPlot.isPeak():
placeDesertPlantFeature(iPlot)
if (iPlot.getFeatureType() == -1) and not iPlot.isPeak():
if (iTerrain == terrainTundra):
placePolarRockFeature(iPlot)
if (iTerrain == terrainDesert):
placeDesertRockFeature(iPlot)
if iPlot.isPeak():
continue
elif isSinglePlotIsland(iPlot):
if (iPlot.getBonusType(-1) == -1): # coastal plot without any resources
if (iLatitude < 64):
if CyGame().getSorenRandNum(2, 'SealionResource') == 0:
iPlot.setBonusType(iSeaLion)
else:
placeSealOrWalrus(iPlot, iSeaLion, iWalrus)
if (iPlot.getFeatureType() == -1) and (iLatitude < 25): # No feature in the tropics
iPlot.setFeatureType(featureCoconut, 0)
else:
if isSeaCoastalLand(iPlot) :
if (iPlot.getBonusType(-1) == -1) and (iLatitude >= 65): # coastal plot without any resources
if CyGame().getSorenRandNum(19, 'SealionResource') == 0:
placeSealOrWalrus(iPlot, iSeaLion, iWalrus)
if (iPlot.getFeatureType() == -1) and (iLatitude < 25): # Tropics
if (iTerrain == terrainDesert):
if CyGame().getSorenRandNum(4, 'Coconuts') == 0:
iPlot.setFeatureType(featureCoconut, 0)
else:
if CyGame().getSorenRandNum(2, 'Coconuts') == 0:
iPlot.setFeatureType(featureCoconut, 0)
else:
continue