The civ library: Difference between revisions

From Scenario League Wiki
Jump to navigationJump to search
(Changed the names of the linked to pages, so that they are the full command (for clarity and to prevent conflicts))
m (Added to category lua resources)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
[[Category:Lua Resources]]
Back to [[TOTPP Functions]]
Back to [[TOTPP Functions]]
----
----


Line 8: Line 8:
[[civ.addImprovement|addImprovement]]
[[civ.addImprovement|addImprovement]]


civ.addImprovement(city, improvement)
<code>civ.addImprovement(city, improvement)</code>


Adds city improvement `improvement` to city `city`.
Adds city improvement `improvement` to city `city`.
Line 15: Line 15:
[[civ.canEnter|canEnter]]
[[civ.canEnter|canEnter]]


civ.canEnter(unittype, tile) -> boolean
<code>civ.canEnter(unittype, tile) -> boolean</code>


Returns `true` if the given unittype can enter tile `tile`, `false` otherwise.
Returns `true` if the given unittype can enter tile `tile`, `false` otherwise.
Line 22: Line 22:
[[civ.captureCity|captureCity]]
[[civ.captureCity|captureCity]]


civ.captureCity(city, tribe)
<code>civ.captureCity(city, tribe)</code>


Captures city `city` for tribe `tribe`.
Captures city `city` for tribe `tribe`.
Line 29: Line 29:
[[civ.createCity|createCity]]
[[civ.createCity|createCity]]


civ.createCity(tribe, tile) -> city
<code>civ.createCity(tribe, tile) -> city</code>


Creates a city owned by `tribe` at the location given by `tile`. Returns `nil` if a city could not be created.
Creates a city owned by `tribe` at the location given by `tile`. Returns `nil` if a city could not be created.
Line 36: Line 36:
[[civ.createUnit|createUnit]]
[[civ.createUnit|createUnit]]


civ.createUnit(unittype, tribe, tile) -> unit
<code>civ.createUnit(unittype, tribe, tile) -> unit</code>


Creates a unit of type `unittype`, owned by `tribe`, at the location given by `tile`.
Creates a unit of type `unittype`, owned by `tribe`, at the location given by `tile`.
Line 43: Line 43:
[[civ.deleteCity|deleteCity]]
[[civ.deleteCity|deleteCity]]


civ.deleteCity(city)
<code>civ.deleteCity(city)</code>


Deletes city `city` from the game.
Deletes city `city` from the game.
Line 50: Line 50:
[[civ.deleteUnit|deleteUnit]]
[[civ.deleteUnit|deleteUnit]]


civ.deleteUnit(unit)
<code>civ.deleteUnit(unit)</code>


Deletes unit `unit` from the game.
Deletes unit `unit` from the game.
Line 57: Line 57:
[[civ.destroyWonder|destroyWonder]]
[[civ.destroyWonder|destroyWonder]]


civ.destroyWonder(wonder)
<code>civ.destroyWonder(wonder)</code>


Destroys wonder `wonder`, removing it from the game, and marking it as 'lost'.
Destroys wonder `wonder`, removing it from the game, and marking it as 'lost'.
Line 64: Line 64:
[[civ.enableTechGroup|enableTechGroup]]
[[civ.enableTechGroup|enableTechGroup]]


civ.enableTechGroup(tribe, techgroup, value)
<code>civ.enableTechGroup(tribe, techgroup, value)</code>


Sets the value of tech group `techgroup` (0-7) to value `value` (0-2, 0 = can research, can own, 1 = can't research, can own, 2 = can't research, can't own) for tribe `tribe`.
Sets the value of tech group `techgroup` (0-7) to value `value` (0-2, 0 = can research, can own, 1 = can't research, can own, 2 = can't research, can't own) for tribe `tribe`.
Line 71: Line 71:
[[civ.endGame|endGame]]
[[civ.endGame|endGame]]


civ.endGame(endscreens=false)
<code>civ.endGame(endscreens=false)</code>


Ends the game. `endscreens` is a boolean that determines whether to show the powergraph and related screens.
Ends the game. `endscreens` is a boolean that determines whether to show the powergraph and related screens.
Line 78: Line 78:
[[civ.getActiveUnit|getActiveUnit]]
[[civ.getActiveUnit|getActiveUnit]]


civ.getActiveUnit() -> unit
<code>civ.getActiveUnit() -> unit</code>


Returns the currently active unit.
Returns the currently active unit.
Line 85: Line 85:
[[civ.getCity|getCity]]
[[civ.getCity|getCity]]


civ.getCity(id) -> city
<code>civ.getCity(id) -> city</code>


Returns the city with id `id`, or `nil` if it doesn't exist.
Returns the city with id `id`, or `nil` if it doesn't exist.
Line 92: Line 92:
[[civ.getCurrentTile|getCurrentTile]]
[[civ.getCurrentTile|getCurrentTile]]


civ.getCurrentTile() -> tile
<code>civ.getCurrentTile() -> tile</code>


Returns the currently selected tile.
Returns the currently selected tile.
Line 99: Line 99:
[[civ.getCurrentTribe|getCurrentTribe]]
[[civ.getCurrentTribe|getCurrentTribe]]


civ.getCurrentTribe() -> tribe
<code>civ.getCurrentTribe() -> tribe</code>


Returns the currently active tribe.
Returns the currently active tribe.
Line 106: Line 106:
[[civ.getGameYear|getGameYear]]
[[civ.getGameYear|getGameYear]]


civ.getGameYear() -> integer
<code>civ.getGameYear() -> integer</code>


Returns the current game year.
Returns the current game year.
Line 113: Line 113:
[[civ.getImprovement|getImprovement]]
[[civ.getImprovement|getImprovement]]


civ.getImprovement(id) -> improvement
<code>civ.getImprovement(id) -> improvement</code>


Returns the improvement with id `id` (0-39), or `nil` if it doesn't exist.
Returns the improvement with id `id` (0-39), or `nil` if it doesn't exist.
Line 120: Line 120:
[[civ.getMapDimensions|getMapDimensions]]
[[civ.getMapDimensions|getMapDimensions]]


civ.getMapDimensions() -> width, height, number_of_maps
<code>civ.getMapDimensions() -> width, height, number_of_maps</code>


Returns three integers, the width and height of the map and the number of maps.
Returns three integers, the width and height of the map and the number of maps.
Line 127: Line 127:
[[civ.getPlayerTribe|getPlayerTribe]]
[[civ.getPlayerTribe|getPlayerTribe]]


civ.getPlayerTribe() -> tribe
<code>civ.getPlayerTribe() -> tribe</code>


Returns the player's tribe.
Returns the player's tribe.
Line 134: Line 134:
[[civ.getTech|getTech]]
[[civ.getTech|getTech]]


civ.getTech(id) -> tech
<code>civ.getTech(id) -> tech</code>


Returns the tech with id `id` (0-99), or `nil` if it doesn't exist.
Returns the tech with id `id` (0-99), or `nil` if it doesn't exist.
Line 141: Line 141:
[[civ.getTile|getTile]]
[[civ.getTile|getTile]]


civ.getTile(x, y, z) -> tile
<code>civ.getTile(x, y, z) -> tile</code>


Returns the tile with coordinates `x`, `y`, `z`, or `nil` if it doesn't exist.
Returns the tile with coordinates `x`, `y`, `z`, or `nil` if it doesn't exist.
Line 148: Line 148:
[[civ.getToTDir|getToTDir]]
[[civ.getToTDir|getToTDir]]


civ.getToTDir() -> string
<code>civ.getToTDir() -> string</code>


Returns the absolute path of the ToT installation directory.
Returns the absolute path of the ToT installation directory.
Line 155: Line 155:
[[civ.getTribe|getTribe]]
[[civ.getTribe|getTribe]]


civ.getTribe(id) -> tribe
<code>civ.getTribe(id) -> tribe</code>


Returns the tech with id `id` (0-7), or `nil` if it doesn't exist.
Returns the tech with id `id` (0-7), or `nil` if it doesn't exist.
Line 162: Line 162:
[[civ.getTurn|getTurn]]
[[civ.getTurn|getTurn]]


civ.getTurn() -> integer
<code>civ.getTurn() -> integer</code>


Returns the current turn number.
Returns the current turn number.
Line 169: Line 169:
[[civ.getUnit|getUnit]]
[[civ.getUnit|getUnit]]


civ.getUnit(id) -> integer
<code>civ.getUnit(id) -> integer</code>


Returns the unit with id `id`, or `nil` if it doesn't exist.
Returns the unit with id `id`, or `nil` if it doesn't exist.
Line 176: Line 176:
[[civ.getUnitType|getUnitType]]
[[civ.getUnitType|getUnitType]]


civ.getUnitType(id) -> unittype
<code>civ.getUnitType(id) -> unittype</code>


Returns the unit type with id `id`, or `nil` if it doesn't exist.
Returns the unit type with id `id`, or `nil` if it doesn't exist.
Line 183: Line 183:
[[civ.getWonder|getWonder]]
[[civ.getWonder|getWonder]]


civ.getWonder(id) -> wonder
<code>civ.getWonder(id) -> wonder</code>


Returns the wonder with id `id` (0-27), or `nil` if it doesn't exist.
Returns the wonder with id `id` (0-27), or `nil` if it doesn't exist.
Line 190: Line 190:
[[civ.giveTech|giveTech]]
[[civ.giveTech|giveTech]]


civ.giveTech(tribe, tech)
<code>civ.giveTech(tribe, tech)</code>


Gives tech `tech` to tribe `tribe`.
Gives tech `tech` to tribe `tribe`.
Line 197: Line 197:
[[civ.hasImprovement|hasImprovement]]
[[civ.hasImprovement|hasImprovement]]


civ.hasImprovement(city, improvement)
<code>civ.hasImprovement(city, improvement)</code>


Returns `true` if city `city` has improvement `improvement`, `false` otherwise.
Returns `true` if city `city` has improvement `improvement`, `false` otherwise.
Line 204: Line 204:
[[civ.hasTech|hasTech]]
[[civ.hasTech|hasTech]]


civ.hasTech(tribe, tech) -> boolean
<code>civ.hasTech(tribe, tech) -> boolean</code>


Returns `true` if tribe `tribe` has tech `tech`, `false` otherwise.
Returns `true` if tribe `tribe` has tech `tech`, `false` otherwise.
Line 211: Line 211:
[[civ.isCity|isCity]]
[[civ.isCity|isCity]]


civ.isCity(object) -> boolean
<code>civ.isCity(object) -> boolean</code>


Returns `true` if `object` is a city, `false` otherwise.
Returns `true` if `object` is a city, `false` otherwise.
Line 218: Line 218:
[[civ.isImprovement|isImprovement]]
[[civ.isImprovement|isImprovement]]


civ.isImprovement(object) -> boolean
<code>civ.isImprovement(object) -> boolean</code>


Returns `true` if `object` is a city improvement, `false` otherwise.
Returns `true` if `object` is a city improvement, `false` otherwise.
Line 225: Line 225:
[[civ.isLeader|isLeader]]
[[civ.isLeader|isLeader]]


civ.isLeader(object) -> boolean
<code>civ.isLeader(object) -> boolean</code>


Returns `true` if `object` is a leader, `false` otherwise.
Returns `true` if `object` is a leader, `false` otherwise.
Line 232: Line 232:
[[civ.isTech|isTech]]
[[civ.isTech|isTech]]


civ.isTech(object) -> boolean
<code>civ.isTech(object) -> boolean</code>


Returns `true` if `object` is a tech, `false` otherwise.
Returns `true` if `object` is a tech, `false` otherwise.
Line 239: Line 239:
[[civ.isTile|isTile]]
[[civ.isTile|isTile]]


civ.isTile(object) -> boolean
<code>civ.isTile(object) -> boolean</code>


Returns `true` if `object` is a tile, `false` otherwise.
Returns `true` if `object` is a tile, `false` otherwise.
Line 246: Line 246:
[[civ.isTribe|isTribe]]
[[civ.isTribe|isTribe]]


civ.isTribe(object) -> boolean
<code>civ.isTribe(object) -> boolean</code>


Returns `true` if `object` is a tribe, `false` otherwise.
Returns `true` if `object` is a tribe, `false` otherwise.
Line 253: Line 253:
[[civ.isUnit|isUnit]]
[[civ.isUnit|isUnit]]


civ.isUnit(object) -> boolean
<code>civ.isUnit(object) -> boolean</code>


Returns `true` if `object` is a unit, `false` otherwise.
Returns `true` if `object` is a unit, `false` otherwise.
Line 260: Line 260:
[[civ.isUnitType|isUnitType]]
[[civ.isUnitType|isUnitType]]


civ.isUnitType(object) -> boolean
<code>civ.isUnitType(object) -> boolean</code>


Returns `true` if `object` is a unit type, `false` otherwise.
Returns `true` if `object` is a unit type, `false` otherwise.
Line 267: Line 267:
[[civ.isWonder|isWonder]]
[[civ.isWonder|isWonder]]


civ.isWonder(object) -> boolean
<code>civ.isWonder(object) -> boolean</code>


Returns `true` if `object` is a wonder, `false` otherwise.
Returns `true` if `object` is a wonder, `false` otherwise.
Line 274: Line 274:
[[civ.iterateCities|iterateCities]]
[[civ.iterateCities|iterateCities]]


civ.iterateCities() -> iterator
<code>civ.iterateCities() -> iterator</code>


Returns an iterator yielding all cities in the game.
Returns an iterator yielding all cities in the game.
Line 281: Line 281:
[[civ.iterateUnits|iterateUnits]]
[[civ.iterateUnits|iterateUnits]]


civ.iterateUnits() -> iterator
<code>civ.iterateUnits() -> iterator</code>


Returns an iterator yielding all units in the game.
Returns an iterator yielding all units in the game.
Line 288: Line 288:
[[civ.killTribe|killTribe]]
[[civ.killTribe|killTribe]]


civ.killTribe(tribe)
<code>civ.killTribe(tribe)</code>


Removes tribe `tribe` from the game. All its cities and units are removed.
Removes tribe `tribe` from the game. All its cities and units are removed.
Line 295: Line 295:
[[civ.makeAggression|makeAggression]]
[[civ.makeAggression|makeAggression]]


civ.makeAggression(who, whom)
<code>civ.makeAggression(who, whom)</code>


Cancels any peace treaties between tribe `who` and tribe `whom`, and make `who` declare war on `whom`.
Cancels any peace treaties between tribe `who` and tribe `whom`, and make `who` declare war on `whom`.
Line 302: Line 302:
[[civ.playMusic|playMusic]]
[[civ.playMusic|playMusic]]


civ.playMusic(trackNo or filename)
<code>civ.playMusic(trackNo or filename)</code>


Plays CD track `trackNo`, or with the DirectShow music patch enabled, play the file given by `filename`, where `filename` is relative to the 'Music' directory.
Plays CD track `trackNo`, or with the DirectShow music patch enabled, play the file given by `filename`, where `filename` is relative to the 'Music' directory.
Line 309: Line 309:
[[civ.playSound|playSound]]
[[civ.playSound|playSound]]


civ.playSound(filename)
<code>civ.playSound(filename)</code>


Plays the sound file given by `filename`.
Plays the sound file given by `filename`.
Line 316: Line 316:
[[civ.playVideo|playVideo]]
[[civ.playVideo|playVideo]]


civ.playVideo(filename)
<code>civ.playVideo(filename)</code>


Plays the video file given by `filename`.
Plays the video file given by `filename`.
Line 323: Line 323:
[[civ.removeImprovement|removeImprovement]]
[[civ.removeImprovement|removeImprovement]]


civ.removeImprovement(city, improvement)
<code>civ.removeImprovement(city, improvement)</code>


Removes city improvement `improvement` from city `city`.
Removes city improvement `improvement` from city `city`.
Line 330: Line 330:
[[civ.sleep|sleep]]
[[civ.sleep|sleep]]


civ.sleep(milliseconds)
<code>civ.sleep(milliseconds)</code>


Sleeps for the given number of milliseconds.
Sleeps for the given number of milliseconds.
Line 337: Line 337:
[[civ.takeTech|takeTech]]
[[civ.takeTech|takeTech]]


civ.takeTech(tribe, tech, collapse=false)
<code>civ.takeTech(tribe, tech, collapse=false)</code>


Takes away tech `tech` from tribe `tribe`, the optional `collapse` parameter determines whether to take away all techs that have `tech` as a prerequisite somewhere up the tree.
Takes away tech `tech` from tribe `tribe`, the optional `collapse` parameter determines whether to take away all techs that have `tech` as a prerequisite somewhere up the tree.
Line 344: Line 344:
[[civ.teleportUnit|teleportUnit]]
[[civ.teleportUnit|teleportUnit]]


civ.teleportUnit(unit, tile)
<code>civ.teleportUnit(unit, tile)</code>


Teleports (i.e. moves at no cost) unit `unit` to tile `tile`. The unit is moved regardless of whether it is a valid location for the unit. To check this, see `civ.canEnter` and `civlua.isValidUnitLocation`.
Teleports (i.e. moves at no cost) unit `unit` to tile `tile`. The unit is moved regardless of whether it is a valid location for the unit. To check this, see `civ.canEnter` and `civlua.isValidUnitLocation`.

Latest revision as of 20:08, 26 January 2019

Back to TOTPP Functions


Follow the link in the function name for additional information about that function, if it is available.


addImprovement

civ.addImprovement(city, improvement)

Adds city improvement `improvement` to city `city`.


canEnter

civ.canEnter(unittype, tile) -> boolean

Returns `true` if the given unittype can enter tile `tile`, `false` otherwise.


captureCity

civ.captureCity(city, tribe)

Captures city `city` for tribe `tribe`.


createCity

civ.createCity(tribe, tile) -> city

Creates a city owned by `tribe` at the location given by `tile`. Returns `nil` if a city could not be created.


createUnit

civ.createUnit(unittype, tribe, tile) -> unit

Creates a unit of type `unittype`, owned by `tribe`, at the location given by `tile`.


deleteCity

civ.deleteCity(city)

Deletes city `city` from the game.


deleteUnit

civ.deleteUnit(unit)

Deletes unit `unit` from the game.


destroyWonder

civ.destroyWonder(wonder)

Destroys wonder `wonder`, removing it from the game, and marking it as 'lost'.


enableTechGroup

civ.enableTechGroup(tribe, techgroup, value)

Sets the value of tech group `techgroup` (0-7) to value `value` (0-2, 0 = can research, can own, 1 = can't research, can own, 2 = can't research, can't own) for tribe `tribe`.


endGame

civ.endGame(endscreens=false)

Ends the game. `endscreens` is a boolean that determines whether to show the powergraph and related screens.


getActiveUnit

civ.getActiveUnit() -> unit

Returns the currently active unit.


getCity

civ.getCity(id) -> city

Returns the city with id `id`, or `nil` if it doesn't exist.


getCurrentTile

civ.getCurrentTile() -> tile

Returns the currently selected tile.


getCurrentTribe

civ.getCurrentTribe() -> tribe

Returns the currently active tribe.


getGameYear

civ.getGameYear() -> integer

Returns the current game year.


getImprovement

civ.getImprovement(id) -> improvement

Returns the improvement with id `id` (0-39), or `nil` if it doesn't exist.


getMapDimensions

civ.getMapDimensions() -> width, height, number_of_maps

Returns three integers, the width and height of the map and the number of maps.


getPlayerTribe

civ.getPlayerTribe() -> tribe

Returns the player's tribe.


getTech

civ.getTech(id) -> tech

Returns the tech with id `id` (0-99), or `nil` if it doesn't exist.


getTile

civ.getTile(x, y, z) -> tile

Returns the tile with coordinates `x`, `y`, `z`, or `nil` if it doesn't exist.


getToTDir

civ.getToTDir() -> string

Returns the absolute path of the ToT installation directory.


getTribe

civ.getTribe(id) -> tribe

Returns the tech with id `id` (0-7), or `nil` if it doesn't exist.


getTurn

civ.getTurn() -> integer

Returns the current turn number.


getUnit

civ.getUnit(id) -> integer

Returns the unit with id `id`, or `nil` if it doesn't exist.


getUnitType

civ.getUnitType(id) -> unittype

Returns the unit type with id `id`, or `nil` if it doesn't exist.


getWonder

civ.getWonder(id) -> wonder

Returns the wonder with id `id` (0-27), or `nil` if it doesn't exist.


giveTech

civ.giveTech(tribe, tech)

Gives tech `tech` to tribe `tribe`.


hasImprovement

civ.hasImprovement(city, improvement)

Returns `true` if city `city` has improvement `improvement`, `false` otherwise.


hasTech

civ.hasTech(tribe, tech) -> boolean

Returns `true` if tribe `tribe` has tech `tech`, `false` otherwise.


isCity

civ.isCity(object) -> boolean

Returns `true` if `object` is a city, `false` otherwise.


isImprovement

civ.isImprovement(object) -> boolean

Returns `true` if `object` is a city improvement, `false` otherwise.


isLeader

civ.isLeader(object) -> boolean

Returns `true` if `object` is a leader, `false` otherwise.


isTech

civ.isTech(object) -> boolean

Returns `true` if `object` is a tech, `false` otherwise.


isTile

civ.isTile(object) -> boolean

Returns `true` if `object` is a tile, `false` otherwise.


isTribe

civ.isTribe(object) -> boolean

Returns `true` if `object` is a tribe, `false` otherwise.


isUnit

civ.isUnit(object) -> boolean

Returns `true` if `object` is a unit, `false` otherwise.


isUnitType

civ.isUnitType(object) -> boolean

Returns `true` if `object` is a unit type, `false` otherwise.


isWonder

civ.isWonder(object) -> boolean

Returns `true` if `object` is a wonder, `false` otherwise.


iterateCities

civ.iterateCities() -> iterator

Returns an iterator yielding all cities in the game.


iterateUnits

civ.iterateUnits() -> iterator

Returns an iterator yielding all units in the game.


killTribe

civ.killTribe(tribe)

Removes tribe `tribe` from the game. All its cities and units are removed.


makeAggression

civ.makeAggression(who, whom)

Cancels any peace treaties between tribe `who` and tribe `whom`, and make `who` declare war on `whom`.


playMusic

civ.playMusic(trackNo or filename)

Plays CD track `trackNo`, or with the DirectShow music patch enabled, play the file given by `filename`, where `filename` is relative to the 'Music' directory.


playSound

civ.playSound(filename)

Plays the sound file given by `filename`.


playVideo

civ.playVideo(filename)

Plays the video file given by `filename`.


removeImprovement

civ.removeImprovement(city, improvement)

Removes city improvement `improvement` from city `city`.


sleep

civ.sleep(milliseconds)

Sleeps for the given number of milliseconds.


takeTech

civ.takeTech(tribe, tech, collapse=false)

Takes away tech `tech` from tribe `tribe`, the optional `collapse` parameter determines whether to take away all techs that have `tech` as a prerequisite somewhere up the tree.


teleportUnit

civ.teleportUnit(unit, tile)

Teleports (i.e. moves at no cost) unit `unit` to tile `tile`. The unit is moved regardless of whether it is a valid location for the unit. To check this, see `civ.canEnter` and `civlua.isValidUnitLocation`.