 Sam Trenholme's webpage
Support this website or listen to my music

Civ4 Map Script API reference

Part 3: A sample map script

Here is a very simple map script. This makes a tiny 12x12 map where most of the squares are desert; there are only two non-desert squares on the map, as well as two oases near these non-desert squares.

It sets the starting plots for only two players, and can be played as a very simple 2-player game.

Here is the source code:

# How simple can we make a functioning map script
# Placed in the public domain 2012 by Sam Trenholme

from CvPythonExtensions import *
import CvUtil
import CvMapGeneratorUtil

def getNumCustomMapOptions():
return 0
def getCustomMapOptionDefault(x):
return 0
return 0
def getCustomMapOptionName(x):
return ""
def getNumCustomMapOptionValues(x):
return ""
def isRandomCustomMapOption(x):
return False
def getCustomMapOptionDescAt(x):
return ""
def isClimateMap():
return 0
def isSeaLevelMap():
return 0
def beforeInit():
return
def getGridSize(x):
return (3,3) # Tiny 12x12 map
def getTopLatitude():
return 0
def getBottomLatitude():
return 0
def getWrapX():
return False
def getWrapY():
return False
def generatePlotTypes():
out = []
for a in range(12 * 12):
out.append(PlotTypes.PLOT_LAND)
return out
def generateTerrainTypes():
out = []
for a in range(12 * 12):
if a != 27 and a != 116:
out.append(2) # Desert
else:
out.append(0) # Grassland
return out
return
return
gc = CyGlobalContext()
map = gc.getMap()
plot = map.plot(3,1)
plot.setFeatureType(2,0) # Oasis
plot = map.plot(8,10)
plot.setFeatureType(2,0) # Oasis
return
return # Disables huts
def assignStartingPlots():
gc = CyGlobalContext()
map = gc.getMap()
player1 = gc.getPlayer(0)
plot = map.plot(3,3)
player1.setStartingPlot(plot, true)
player2 = gc.getPlayer(1)
plot = map.plot(9,9)
player2.setStartingPlot(plot, true)
return
return
return
return
return