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

Civ4 Map Script API reference

Part 1: Setting options

This is based on looking at the source code to Totestra.

getNumHiddenCustomMapOptions() Not in Totestra (optional)

getNumCustomMapOptions(): Input: None. Output: Int, number of parameters (besides size, climate, and sea level) that can be adjusted by the user

getCustomMapOptionDefault(): Input: Array. One element: The option number. Output: Int, the default value for this option

isAdvancedMap(): Input: None. Output 0 if this map is "not" an "advanced" map (a map which needs "custom game" to be seen) Make this 0; some mods don't work with "custom game".

getCustomMapOptionName(): Input: Array, one element. One element: The option number. The output is the name for this option. Keep in mind that in "quick game", this is preceded by the string "Select a" so it should ideally be a grammatically singular noun.

getNumCustomMapOptionValues(): Input: Array, one element. Element 0: The option number. Output: The number of possible values this option can have.

isRandomCustomMapOption(): Input: Array, one element. Element 0: The option number. Output: False if this option's value should be randomly chosen, True if it should be random.

getCustomMapOptionDescAt(): Input: Array, two elements. Element 0: The option number. Element 1: The choice for this option. Output: A string describing a given choice for a given option.

isClimateMap(): Input: None. Output: 0 if we are not allowed to select the climate for this map; 1 if we are allowed the select the climate for this map (Temperate, Arid, Cold, Rocky, and Tropical, but not in that order).

isSeaLevelMap(): Input: None. Output: 0 if we are not allowed to select the sea level for this map; 1 if we are

beforeInit(): Input: None. Output: None. Used by the map script to store the options selected by the user. To get options, start by having CyGlobalContext() create an object. Use the method getMap() in the CyGlobalContext()-created object to get map information. For example: foo = CyGlobalContext() ; bar = foo.getMap(). This second "getMap()" object has the following methods of interest for getting map script options:

  • getClimate() Get the "climate" option. Input: None. Output: 0: Temperate, 1: Tropical, 2: Arid, 3: Rocky, 4: Cold
  • getSeaLevel() Get the "sea level" option. Input: None. Output: 0: Low 1: Medium (normal) 2: High
  • getCustomMapOption() Get any other option. Input: Integer (the option in question). Output: Integer (the value for this option)
getGridSize(): Input: Array; one element. Array element: Integer with map size (0: Dual, 1: Tiny, 2: Small, 3: Standard, 4: Large, 5: huge). Presumably mods with even larger maps will give this function values like 6, 7, 8, etc. Output: If this element has the value -1, the Python script must return an empty array. Otherwise, return a tuple in the form (width, height), where width is the width of the map to be generated (in a unit which represents 4 squares), and height is the height divided by 4.

In other words, if this returns (36,24), that means Civilization 4 should generate a 144x96 map (144 squares wide, 96 squares high). Note that the "multiply by 4" rule was removed in the Colonization total conversion.

Support

Support for this reference is available here:
http://forums.civfanatics.com/showthread.php?p=11624647

See also