Module City
This library contains functions to access and modify city information, general buildings and roads.
Functions
| addBuildingListener (tbl) | Adds one or multiple event listeners for (specific) buildings in the city. |
| addRoadListener (tbl) | Adds one or multiple event listeners for (specific) roads in the city. |
| alert (actionPlaceType, x, y) | Sets an action marker (or removes the one previously set there). |
| canSpend (amount) | Returns true if the city can spend the specified amount of money. |
| countBuildings ([draft]) | Returns the overall amount of buildings. |
| countBuildingsOfType (type[, level]) | Returns the number of buildings of a specific building type. |
| countCars () | Returns the number of cars currently active. |
| countPipes () | Returns the overall amount of pipes in the city. |
| countRoads ([draft]) | Returns the overall amount of roads. |
| countWires () | Returns the overall amount of wires in the city. |
| countZones ([draft]) | Returns the overall amount of zones. |
| createDraftDrawer (draft[, alsoHidden=false]) | Returns a table with functions to draw the draft and query some information about it. |
| enableDisaster (name[, state]) | Enables or disables the automatic disaster of the given name. |
| execute (cmd, receiver) | Executes a command as if it was entered into the console. |
| exit ([save=false]) | Closes the current city and will go back to region view. |
| getAbsoluteDay () | Returns the current absolute day of the city. |
| getAuthor () | Returns the name of the author that the player entered |
| getBackground () | Returns the current background draft of the city. |
| getBuilding (index[, draft]) | Gets the position of a specific building of a specific draft by its index. |
| getCommercialJobs ([level[, progress=false]]) | Returns the total commercial jobs per level. |
| getCurrency (name) | Returns the available amount of the named currency and its formatted value. |
| getDay () | Returns the current day of the month of the city. |
| getDayPart () | Returns the current part of the day with 0 being the start and 1 being the end. |
| getDisaster () | Returns the name of the currently active disaster or nil if none is active. |
| getFileName () | Returns the name of the file of the city. |
| getFunVar (name[, fallbackValue]) | Returns the value of the classic fun variable of the given name or fallbackValue if no such variable has been defined, yet. |
| getHappiness ([happinessType]) | Returns the average happiness. |
| getHeight () | Height of the city in tiles |
| getId () | Returns the ID of the city. |
| getIncome () | Returns the monthly income of the city. |
| getIndustrialJobs ([level[, progress=false]]) | Returns the total industrial jobs per level. |
| getMoney () | Returns the estate of the city. |
| getMonth () | Returns the current month of the city. |
| getName () | Name of the current city |
| getOwnerId () | Returns the id of the owner of the city if the city is online. |
| getOwnerName () | Returns the name of the owner of the city if the city is online. |
| getPeople ([level]) | Returns the number of people at the specified level (0, 1 or 2), or the total population if no level is specified. |
| getPipe (index) | Returns the x and y coordinates and draft of the pipe at the given index. |
| getPlayTime () | Returns the play time in this city in seconds. |
| getRank () | Returns the current rank draft and the rank index. |
| getRegionId () | Returns the id of the region or nil if the city is not in a region. |
| getRegionName () | Returns the name of the region this city is located in, or nil for individual cities. |
| getResidentialSpace ([level[, progress=false]]) | Returns the residential space (in buildings) per level. |
| getRoad (index[, draft]) | Gets the position and level of a specific road (of a specific draft) by its index. |
| getRotation () | Returns the current rotation of the city. |
| getScale () | Gets the current scaling of the city with 1.0 being no scaling. |
| getSeed () | Returns the seed that was used to generate the city |
| getSpeed () | Returns the current simulation speed of the city. |
| getStorage () | Use this storage table to save things city wide |
| getTax (rci, level) | Returns the current taxes applied to a certain building type and level |
| getTime () | Returns the animation time of the game in milliseconds. |
| getTimeDelta () | Returns the delta animation time in milliseconds. |
| getToolId () | Returns the id of the currently opened tool. |
| getToolName () | Returns the name of the currently opened tool. |
| getView () | Returns the tile position the camera is currently looking at as well as the current scale. |
| getWidth () | Width of the city in tiles |
| getWire (index) | Returns the coordinates, level and draft of the wire at the given index. |
| getXp () | Returns the amount of experience of the city. |
| getYear () | Returns the current year of the city. |
| hash ([x[, y]]) | Returns a pseudo random positive 32bit integer number. |
| isLeftSideTraffic () | Returns true if the current city is using left side traffic. |
| isOnline () | Indicates whether this city is an online city. |
| isReadonly () | Indicates whether this city is readonly. |
| isSandbox () | Determines whether the city is in free or sandbox mode |
| isUber () | Returns true if uber is activated for that city. |
| issueDisaster (name[, x=-1[, y=-1[, radius=20[, radioactive=true]]]]) | Issues the disaster of the given name at the given position x, y. |
| load (path[, overwrite[, private[, target]]]) | Loads a city file provided by the plugin. |
| move (x, y) | Moves the city according to the given screen space coordinates. |
| noise (x, y[, z[, w]]) | Returns a noise value for the specified coordinates. |
| openInfo (infoType) | Opens the city information screen of the given type. |
| playSound (sound, x, y[, volume=1[, loop=false]]) | Plays a sound. |
| rebuildUI () | Rebuilds the UI of the city view including the toolbar. |
| save ([enforce=false]) | Saves the city if the user has autosave enabled. |
| setAuthor (name) | Sets a new author name for the city. |
| setBackground (draft) | Sets a background. |
| setFunVar (name, value) | Sets the value of a classic fun variable called name. |
| setLeftSideTraffic (leftSide) | Sets whether the current city should use left side traffic. |
| setName (newName) | Sets a new city name |
| setRotation (r) | Sets the rotation of the city. |
| setScale (scale) | Sets the scale of the city with 1.0 being no scaling. |
| setSpeed (speed) | Sets the simulation speed of the city. |
| setView (x, y[, scale[, adjustY=true]]) | Sets the view to a specified tile x, y using the provided scale. |
| showNotification (tableOfArguments) | Shows a notification. |
| spendCurrency (name, amount) | Spends amount of the currency named name. |
| spendMoney (amount[, x[, y[, budgetItem]]]) | Spends some money. |
Fields
| ACTIONPLACE_FIRE | Action place for fire alerts. |
| ACTIONPLACE_GARBAGE | Action place for garbage alerts. |
| ACTIONPLACE_MEDIC | Action place for medic alerts. |
| ACTIONPLACE_POLICE | Action place for police alerts. |
| ACTIONPLACE_SWAT | Action place for swat alerts. |
| DISASTER_BLIZZARD | Identifier for blizzard disaster. |
| DISASTER_CRIME | Identifier for crime disaster. |
| DISASTER_EARTHQUAKE | Identifier for earthquake disaster. |
| DISASTER_FIRE | Identifier for fire disaster. |
| DISASTER_FLOODING | Identifier for flooding disaster. |
| DISASTER_GREEN_SLIME | Identifier for green slime disaster. |
| DISASTER_ILLNESS | Identifier for illness disaster. |
| DISASTER_METEOR | Identifier for meteorite disaster. |
| DISASTER_NUKE | Identifier for nuke disaster. |
| DISASTER_PINK_SLIME | Identifier for pink slime disaster. |
| DISASTER_RIOT | Identifier for riot disaster. |
| DISASTER_TORNADO | Identifier for tornado disaster. |
| DISASTER_UFO | Identifier for ufo disaster. |
| HAPPINESS_EDUCATION | Name of education happiness |
| HAPPINESS_ENVIRONMENT | Name of environment happiness |
| HAPPINESS_FIREDEPARTMENT | Name of fire department happiness |
| HAPPINESS_FREETIME | Name of free time happiness |
| HAPPINESS_GENERAL | Name of general happiness |
| HAPPINESS_HEALTH | Name of health happiness |
| HAPPINESS_LEVEL | Name of level happiness. |
| HAPPINESS_PARK | Name of park happiness |
| HAPPINESS_POLICE | Name of police happiness |
| HAPPINESS_RELIGION | Name of religion happiness |
| HAPPINESS_SPORT | Name of sport happiness |
| HAPPINESS_SUPPLY | Name of supply happiness |
| HAPPINESS_TAXES | Name of taxes happiness |
| HAPPINESS_TRANSPORT | Name of transport happiness |
| HAPPINESS_WASTE | Name of waste happiness |
| HAPPINESS_ZONE | Name of zone happiness. |
| INFO_AIRPORT | Identifier for airport city information screen |
| INFO_BUDGET | Identifier for budget city information screen |
| INFO_EDUCATION | Identifier for education city information screen |
| INFO_ENERGY | Identifier for energy city information screen |
| INFO_GENERAL | Identifier for general city information screen |
| INFO_HEALTH | Identifier for health city information screen |
| INFO_LOAN | Identifier for loan city information screen |
| INFO_NEIGHBOR | Identifier for neighbor city information screen |
| INFO_RANK | Identifier for rank city information screen |
| INFO_RATING | Identifier for rating city information screen |
| INFO_RCI | Identifier for rci/demand city information screen |
| INFO_STATISTICS | Identifier for statistics city information screen |
| INFO_WATER | Identifier for water city information screen |
| TAX_COMMERCIAL | Identifier for denoting commercial tax. |
| TAX_INDUSTRIAL | Identifier for denoting industrial tax. |
| TAX_RESIDENTIAL | Identifier for denoting residential tax. |
Functions
- addBuildingListener (tbl)
-
Adds one or multiple event listeners for (specific) buildings in the city.
Listeners will not be persisted so you may want to always register them
in script:enterCity().
Listeners will not be called in any specific order.
Note that the building listener will also be called for buildings that were moved. This call happens immediately after Script.EVENT_PLACED and does not reflect the final properties of the building like upgrades. For that you could use Runtime.postpone to do the check for properties a bit later.
Unstable:
-
This feature is not stable and may be changed or removed in the future.
Parameters:
- tbl table A table that holds named parameters.
Usage:
function script:enterCity() City.addBuildingListener{ draft = Draft.getDraft('$somebuildingdraftid'), -- either a building draft to monitor, or nil to monitor all buildings added = function(data) -- data is a table of { x, y, draft } Debug.toast('Added building at', data.x, data.y) end, finished = function(data) end, -- data is a table of { x, y, draft } upgraded = function(data) end, -- data is a table of { x, y, draft, upgradeDraft } removed = function(data) end -- data is a table of { x, y, draft } } end
- addRoadListener (tbl)
-
Adds one or multiple event listeners for (specific) roads in the city.
Listeners will not be persisted so you may want to always register them
in script:enterCity().
Listeners will not be called in any specific order.
Unstable:
-
This feature is not stable and may be changed or removed in the future.
Parameters:
- tbl table A table that holds named parameters.
Usage:
function script:enterCity() City.addRoadListener{ draft = Draft.getDraft('$someroaddraftid'), -- either a road draft to monitor, or nil to monitor all roads added = function(data) -- data is a table of { x, y, level, draft } Debug.toast('Added road at', data.x, data.y, data.level) end, removed = function(data) end -- data is a table of { x, y, level, draft } } end
- alert (actionPlaceType, x, y)
-
Sets an action marker (or removes the one previously set there).
Parameters:
- actionPlaceType int
- x int
- y int
- canSpend (amount)
-
Returns true if the city can spend the specified amount of money.
Parameters:
- amount int The amount to query whether it can be spent.
- countBuildings ([draft])
-
Returns the overall amount of buildings. Optionally of a specific draft.
This can for example be used to iterate over all buildings of a draft
by using City.getBuilding(index, draft).
Parameters:
- draft draft A building draft. (optional)
Returns:
-
int
Amount of buildings.
- countBuildingsOfType (type[, level])
-
Returns the number of buildings of a specific building type.
Parameters:
- type string The building type to count. Can be one of "residential", "commercial", "industrial", "farm", "harbor ind", "harbor pier", "park", "sport", "public", "religion", "award", "energy", "water", "medic", "police", "swat", "fire brigade", "education", "bus depot", "destroyed", "decoration", "buoy", "railway station", "waste disposal", "body disposal", "military", "airport", "terrain", "landmark" or "building" (this one being a placeholder).
- level int The level the buildings should have. If not specified the level of the buildings is ignored. Level 0 would be first level. (optional)
Returns:
-
int
The number of buildings of the specified type (and level).
- countCars ()
-
Returns the number of cars currently active. This includes operational
cars and trains.
Returns:
-
int
Cars in the city.
- countPipes ()
-
Returns the overall amount of pipes in the city.
Returns:
-
int
The number of pipes.
- countRoads ([draft])
-
Returns the overall amount of roads. Optionally of a specific draft.
This can for example be used to iterate over all roads (of a draft)
by using City.getRoad(index, draft).
Parameters:
- draft draft A road draft. (optional)
Returns:
-
int
Amount of roads.
- countWires ()
-
Returns the overall amount of wires in the city.
Returns:
-
integer
The number of wires.
- countZones ([draft])
-
Returns the overall amount of zones. Optionally of a specific draft.
Parameters:
- draft draft A zone draft. (optional)
Returns:
-
int
Amount of zones of that type in the city.
- createDraftDrawer (draft[, alsoHidden=false])
-
Returns a table with functions to draw the draft and query some information
about it.
The table is only valid as long as the city is open.
This is a costly operation and should only be done rarely.
The main intention for this function is to render drafts in some sort of UI.
Parameters:
- draft draft or string The draft or id of a draft a function table should be created for.
- alsoHidden bool If true this function will also return a table for hidden drafts. (default false)
Returns:
-
table or nil
The table of functions or nil if the draft does not support
the operation
Usage:
The returned table contains the following functions: getWidth() -- Returns the pixel width of the preview getHeight() -- Returns the pixel height of the preview getTitle() -- Returns the title of the draft for rendering getText() -- Returns the text of the draft for rendering getPrice() -- Returns the current price for the draft getMonthlyPrice() -- Returns the current monthly price for the draft getDiamondPrice() -- Returns the current diamond price for the draft isActive() -- Returns true if the draft is considered visible to the player isSelectable() -- Returns true if the select function can be called (ie building can be built) hasFrames() -- Returns true if there is more than one frame available nextFrame() -- Selects the next frame for drawing prevFrame() -- Selects the previous frame for drawing getDraft() -- Returns the underlying draft object select() -- If isSelectable() is true this function starts the associated (build) tool markAsUsed() -- Mark this draft as used so it will not be shown as New draw(x, y, w, h) -- Draws the draft preview into the specified target rect. getHistory() -- Returns an array of draft id strings of the last used drafts
- enableDisaster (name[, state])
-
Enables or disables the automatic disaster of the given name.
Parameters:
- name string
- state bool true by default. (optional)
- execute (cmd, receiver)
-
Executes a command as if it was entered into the console.
Parameters:
- cmd string The command to execute.
- receiver function A function with one parameter that will be called for any feedback.
- exit ([save=false])
-
Closes the current city and will go back to region view.
Unstable:
-
This feature is not stable and may be changed or removed in the future.
Parameters:
- save bool Whether to save the city before exiting it. (default false)
- getAbsoluteDay ()
-
Returns the current absolute day of the city.
Returns:
-
int
- getAuthor ()
-
Returns the name of the author that the player entered
Returns:
-
string
- getBackground ()
-
Returns the current background draft of the city.
Returns:
-
draft
- getBuilding (index[, draft])
-
Gets the position of a specific building of a specific draft by its index.
The index starts with 1 and ranges up to City.countBuildings(draft).
Parameters:
- index int Index of the building, starting with 1.
- draft draft (optional)
Returns:
- int X position of the building.
- int Y position of the building.
- getCommercialJobs ([level[, progress=false]])
-
Returns the total commercial jobs per level.
Parameters:
- level int The level, 0, 1 or 2. If no level is provided the sum of all levels will be used. (optional)
- progress bool If true, buildings that are in building process will be included. (default false)
Returns:
-
int
Amount of total commercial jobs.
- getCurrency (name)
-
Returns the available amount of the named currency and its formatted value.
Returns nil if no currency with that name exists.
E.g. City.getCurrency('bus currency')
Parameters:
- name string The name of the currency.
Returns:
- number or nil The available amount, or nil if the currency does not exist.
- string or nil The localized amount with the currency unit, or nil if not found.
- getDay ()
-
Returns the current day of the month of the city.
The value ranges from 1 to 30.
Returns:
-
int
- getDayPart ()
-
Returns the current part of the day with 0 being the start and 1 being
the end.
Combine it with the current date for a game-speed-dependent time source;
City.getDay() + City.getDayPart() resets at the start of each month.
Returns:
-
float
The fraction of the current day elapsed, from 0 to 1.
- getDisaster ()
-
Returns the name of the currently active disaster or nil if none is active.
Returns:
- getFileName ()
-
Returns the name of the file of the city.
Returns:
-
string
- getFunVar (name[, fallbackValue])
-
Returns the value of the classic fun variable of the given name or
fallbackValue if no such variable has been defined, yet.
fallbackValue is 0 by default.
Note that fun variables can only contain numbers. Use City.getStorage()
or TheoTown.getStorage() to store more fancy stuff.
Global fun variables are indicated by a leading ! in its name.
Parameters:
- name string
- fallbackValue int (optional)
Returns:
-
int
- getHappiness ([happinessType])
-
Returns the average happiness.
Parameters:
- happinessType string Type of a happiness, e.g. City.HAPPINESS_PARK. If not provided the general happiness will be returned. Be cautious, the calculation for a specific type can be time consuming and should not be done every frame. (optional)
Returns:
-
float
0..1 with 1 being happy
Usage:
City.getHappiness(City.HAPPINESS_PARK)
- getHeight ()
-
Height of the city in tiles
Returns:
-
int
- getId ()
-
Returns the ID of the city.
Returns:
-
string
ID of the city.
- getIncome ()
-
Returns the monthly income of the city.
Returns:
-
int
Income of the city in Theons.
- getIndustrialJobs ([level[, progress=false]])
-
Returns the total industrial jobs per level.
Parameters:
- level int The level, 0, 1 or 2. If no level is provided the sum of all levels will be used. (optional)
- progress bool If true, buildings that are in building process will be included. (default false)
Returns:
-
int
Amount of total industrial jobs.
- getMoney ()
-
Returns the estate of the city.
Returns:
-
int The money of the city in Theon.
- getMonth ()
-
Returns the current month of the city.
The value ranges from 1 to 12.
Returns:
-
int
- getName ()
-
Name of the current city
Returns:
-
string
- getOwnerId ()
-
Returns the id of the owner of the city if the city is online.
Returns:
-
string
- getOwnerName ()
-
Returns the name of the owner of the city if the city is online.
Returns:
-
string
- getPeople ([level])
-
Returns the number of people at the specified level (0, 1 or 2), or
the total population if no level is specified.
Parameters:
- level int The population level. (optional)
Returns:
-
int
The number of people.
- getPipe (index)
-
Returns the x and y coordinates and draft of the pipe at the given index.
Can be used to iterate over all pipes of the city by using
City.countPipes() to determine the overall amount of pipes.
Parameters:
- index int Index of the pipe, starting with 1.
Returns:
- int The x coordinate of the pipe.
- int The y coordinate of the pipe.
- draft The pipe draft.
- getPlayTime ()
-
Returns the play time in this city in seconds.
Returns:
-
int
Time in seconds.
- getRank ()
-
Returns the current rank draft and the rank index.
Returns:
- draft The rank draft of the city.
- int Index of the rank, starts with 0 for the first one.
- getRegionId ()
-
Returns the id of the region or nil if the city is not in a region.
The id of a region is (in theory) unique. For online regions it is just
a number.
Returns:
-
string
The id of the region or nil.
- getRegionName ()
-
Returns the name of the region this city is located in, or nil for
individual cities.
Returns:
-
string
Name of the region or nil.
- getResidentialSpace ([level[, progress=false]])
-
Returns the residential space (in buildings) per level.
Parameters:
- level int The level, 0, 1 or 2. If no level is provided the sum of all levels will be used. (optional)
- progress bool If true, buildings that are in building process will be included. (default false)
Returns:
-
int
Amount of residential space (unit is people).
- getRoad (index[, draft])
-
Gets the position and level of a specific road (of a specific draft) by its index.
Parameters:
- index int
- draft draft (optional)
Returns:
- int X location
- int Y location
- int Level
- getRotation ()
-
Returns the current rotation of the city. City rotation is expressed with an
integer number 0 (unrotated), ..., 3
Returns:
-
int {0, 1, 2, 3}
- getScale ()
-
Gets the current scaling of the city with 1.0 being no scaling.
Returns:
-
float
The scale of the city.
- getSeed ()
-
Returns the seed that was used to generate the city
Returns:
-
string
- getSpeed ()
-
Returns the current simulation speed of the city.
Returns:
-
int
The speed value.
See also:
- getStorage ()
-
Use this storage table to save things city wide
Returns:
- getTax (rci, level)
-
Returns the current taxes applied to a certain building type and level
Parameters:
- rci int Must be one of City.TAX_RESIDENTIAL, City.TAX_COMMERCIAL or City.TAX_INDUSTRIAL
- level int Must be an integer number in 1..3.
Returns:
-
number
The tax in percent. Will be in 0..100.
- getTime ()
-
Returns the animation time of the game in milliseconds.
Returns:
-
int
- getTimeDelta ()
-
Returns the delta animation time in milliseconds.
Returns:
-
float
- getToolId ()
-
Returns the id of the currently opened tool.
The default tool (that is selected when no other tool is open)
has an id of "Default".
In contrast to tool name the id does not depend on current
language as it is not visible to the user.
You are encouraged to find out different tool ids on your own using
this function.
Returns:
-
string
The id of the opened tool.
- getToolName ()
-
Returns the name of the currently opened tool.
The default tool (that is selected when no other tool is open)
has a name of "Default".
Returns:
-
string
The name of the opened tool.
- getView ()
-
Returns the tile position the camera is currently looking at as well as
the current scale. Format: x, y, scale
Note that this function does no terrain elevation adjustment unlike
City.setView.
Returns:
- int
- int
- float
- getWidth ()
-
Width of the city in tiles
Returns:
-
int
- getWire (index)
-
Returns the coordinates, level and draft of the wire at the given index.
Can be used to iterate over all wires of the city by using
City.countWires() to determine the overall amount of wires.
Parameters:
- index int Index of the wire, starting with 1.
Returns:
- int The X location and
- int the Y location and
- int The level of the wire at the given index.
- draft The wire draft.
- getXp ()
-
Returns the amount of experience of the city.
Returns:
-
int
- getYear ()
-
Returns the current year of the city.
The value starts at 1.
Returns:
-
int
- hash ([x[, y]])
-
Returns a pseudo random positive 32bit integer number.
The returned number is only dependent on the city and - if specified -
on the provided x,y location.
The returned value can be used to generate pseudo random values that are
fixed per city and location. This can be useful to produce seemingly
random but yet deterministic behavior.
Parameters:
- x int (optional)
- y int (optional)
Returns:
-
int
Positive pseudo random number.
- isLeftSideTraffic ()
-
Returns true if the current city is using left side traffic.
Returns:
-
bool
The left side traffic state.
- isOnline ()
-
Indicates whether this city is an online city.
Returns:
-
bool
True iff the city is online
- isReadonly ()
-
Indicates whether this city is readonly. Cities that are readonly can not
be saved. For example foreign cities in online regions are read only.
Returns:
-
bool
True iff the city is readonly
- isSandbox ()
-
Determines whether the city is in free or sandbox mode
Returns:
-
bool
- isUber ()
-
Returns true if uber is activated for that city.
Returns:
-
bool
Iff city is uber
- issueDisaster (name[, x=-1[, y=-1[, radius=20[, radioactive=true]]]])
-
Issues the disaster of the given name at the given position x, y.
Returns true iff disaster was issued successfully.
Parameters:
- name string The name of a disaster, e.g. City.DISASTER_FIRE
- x int X position. Random by default. (default -1)
- y int Y position. Random by default. (default -1)
- radius int Radius for nuke disaster. (default 20)
- radioactive bool Radioactivity for nuke disaster. (default true)
Returns:
-
bool
Usage:
function script:earlyTap(x, y) City.issueDisaster(City.DISASTER_RIOT, x + 1, y) City.issueDisaster(City.DISASTER_RIOT, x - 1, y) City.issueDisaster(City.DISASTER_RIOT, x, y + 1) City.issueDisaster(City.DISASTER_RIOT, x, y - 1) City.issueDisaster(City.DISASTER_FIRE, x, y) return false -- Prevent further processing of this tap end
- load (path[, overwrite[, private[, target]]])
-
Loads a city file provided by the plugin. path is the file of the city file
(thus it includes the .city file ending).
Prior to loading the city will be copied to maps or private maps folder first
(depending on private value).
If a city of similar file name already exists at that directory it will be
overridden if overwrite flag is set.
The target file name can be changed by specifying a target name.
Parameters:
- move (x, y)
-
Moves the city according to the given screen space coordinates.
Can be used to implement smooth scrolling similar to mouse / key / touch
based one.
Parameters:
- x float
- y float
- noise (x, y[, z[, w]])
-
Returns a noise value for the specified coordinates.
Parameters:
- x int
- y int
- z int (optional)
- w int (optional)
Returns:
-
float
Ranges from -1 to 1
- openInfo (infoType)
-
Opens the city information screen of the given type.
Parameters:
- infoType string Use one of the constants mentioned above, e.g. City.INFO_GENERAL
- playSound (sound, x, y[, volume=1[, loop=false]])
-
Plays a sound.
Parameters:
- sound draft A sound draft or id of a sound draft.
- x int X coordinate of the sound's origin tile.
- y int Y coordinate of the sound's origin tile.
- volume float A value between 0 and 1. (default 1)
- loop bool Whether or not to loop the sound. (default false)
Returns:
-
table
A table that contains functions to control the sound.
- rebuildUI ()
- Rebuilds the UI of the city view including the toolbar.
- save ([enforce=false])
-
Saves the city if the user has autosave enabled. If enforce is set the city
will even be saved if the user has autosave disabled.
Don't call this function e.g. in event functions since they may be called from
outside of the main thread. You can call it from a function passed to
Runtime.postpone to fix that.
Parameters:
- enforce bool Whether to enforce saving. (default false)
- setAuthor (name)
-
Sets a new author name for the city.
Parameters:
- name string Name of the author
- setBackground (draft)
-
Sets a background.
Parameters:
- draft draft An animation draft or its id as a string. Use nil to set default background.
- setFunVar (name, value)
-
Sets the value of a classic fun variable called name.
Note that fun variables can only contain numbers. Use City.getStorage()
or TheoTown.getStorage() to store more fancy stuff.
Global fun variables are indicated by a leading ! in its name.
Parameters:
- name string
- value int
- setLeftSideTraffic (leftSide)
-
Sets whether the current city should use left side traffic.
Returns the old value.
Parameters:
- leftSide bool True to indicate left sided traffic.
Returns:
-
bool
True if left side traffic was active before, false otherwise.
- setName (newName)
-
Sets a new city name
Parameters:
- newName string
- setRotation (r)
-
Sets the rotation of the city.
Parameters:
- r int Rotation (0, 1, 2 or 3).
- setScale (scale)
-
Sets the scale of the city with 1.0 being no scaling.
Parameters:
- scale float The scale to apply.
- setSpeed (speed)
-
Sets the simulation speed of the city. The following values are allowed:
0for paused1for slow2for normal3for fast4for ultra fastParameters:
- speed int One of the values above.
See also:
- setView (x, y[, scale[, adjustY=true]])
-
Sets the view to a specified tile x, y using the provided scale. If no scale
is provided the current scale will be used.
Scale 1 means no scaling, 2 times scaling etc.
Parameters:
- x int
- y int
- scale float (optional)
- adjustY bool Adjust for terrain elevation (1.11.24) (default true)
- showNotification (tableOfArguments)
-
Shows a notification.
See here for an example.
Parameters:
- tableOfArguments table A table that contains all of the arguments that should be used for the notification.
Usage:
City.showNotification{ -- Image for the notification, can be extracted from a draft using :getFrame icon = frameDraft:getFrame(1), -- Text of the notification text = 'hi', -- All of the following attributes are optional... -- Title in case of an immersive notification title = 'Title of the window', -- Whether to draw it with a red background (default: false) important = true, -- Whether to offer yes and no buttons (default: false) question = true, -- Whether to offer an 'ok' button (default: value of question) optionOk = true, -- Whether to offer a close/cancel button (default: true) closeable = true, -- If defined: offer a location button that will jump to that location locationX = 42, locationY = 42, -- If true: shows the notification as a dialog (default: false) immersive = false, -- Will be called if the ok button was pressed onOk = function() Debug.toast('Ok') end, -- Will be called if the cancel button was pressed onCancel = function() Debug.toast('Cancel') end, -- Will be called if the notification was closed without a button press onClose = function() Debug.toast('Closed') end, -- A new feature of version 1.8.78 that allows to add own buttons actions = { { -- Image for the button icon = frameDraft:getFrame(2), -- Will be called when button is pressed onClick = function() Debug.toast('Triangle was clicked') end }, { icon = frameDraft:getFrame(3), onClick = function() Debug.toast('Circle was clicked') end }, { icon = frameDraft:getFrame(4), onClick = function() Debug.toast('Cross was clicked') end } } } - spendCurrency (name, amount)
-
Spends amount of the currency named name.
Parameters:
- name string
- amount int
- spendMoney (amount[, x[, y[, budgetItem]]])
-
Spends some money. If x, y is specified it will show a red price at that
location.
Parameters:
- amount int
- x int (optional)
- y int (optional)
- budgetItem draft (optional)
Fields
- ACTIONPLACE_FIRE
- Action place for fire alerts. Used for action place markers.
- ACTIONPLACE_GARBAGE
- Action place for garbage alerts.
- ACTIONPLACE_MEDIC
- Action place for medic alerts.
- ACTIONPLACE_POLICE
- Action place for police alerts.
- ACTIONPLACE_SWAT
- Action place for swat alerts.
- DISASTER_BLIZZARD
- Identifier for blizzard disaster.
- DISASTER_CRIME
- Identifier for crime disaster.
- DISASTER_EARTHQUAKE
- Identifier for earthquake disaster.
- DISASTER_FIRE
- Identifier for fire disaster. Used by City.getDisaster and City.issueDisaster.
- DISASTER_FLOODING
- Identifier for flooding disaster.
- DISASTER_GREEN_SLIME
- Identifier for green slime disaster.
- DISASTER_ILLNESS
- Identifier for illness disaster.
- DISASTER_METEOR
- Identifier for meteorite disaster.
- DISASTER_NUKE
- Identifier for nuke disaster.
- DISASTER_PINK_SLIME
- Identifier for pink slime disaster.
- DISASTER_RIOT
- Identifier for riot disaster.
- DISASTER_TORNADO
- Identifier for tornado disaster.
- DISASTER_UFO
- Identifier for ufo disaster.
- HAPPINESS_EDUCATION
- Name of education happiness
- HAPPINESS_ENVIRONMENT
- Name of environment happiness
- HAPPINESS_FIREDEPARTMENT
- Name of fire department happiness
- HAPPINESS_FREETIME
- Name of free time happiness
- HAPPINESS_GENERAL
- Name of general happiness
- HAPPINESS_HEALTH
- Name of health happiness
- HAPPINESS_LEVEL
- Name of level happiness. This is a hidden happiness which means that it is used for internal calculations, only.
- HAPPINESS_PARK
- Name of park happiness
- HAPPINESS_POLICE
- Name of police happiness
- HAPPINESS_RELIGION
- Name of religion happiness
- HAPPINESS_SPORT
- Name of sport happiness
- HAPPINESS_SUPPLY
- Name of supply happiness
- HAPPINESS_TAXES
- Name of taxes happiness
- HAPPINESS_TRANSPORT
- Name of transport happiness
- HAPPINESS_WASTE
- Name of waste happiness
- HAPPINESS_ZONE
- Name of zone happiness. This is a hidden happiness which means that it is used for internal calculations, only.
- INFO_AIRPORT
- Identifier for airport city information screen
- INFO_BUDGET
- Identifier for budget city information screen
- INFO_EDUCATION
- Identifier for education city information screen
- INFO_ENERGY
- Identifier for energy city information screen
- INFO_GENERAL
- Identifier for general city information screen
- INFO_HEALTH
- Identifier for health city information screen
- INFO_LOAN
- Identifier for loan city information screen
- INFO_NEIGHBOR
- Identifier for neighbor city information screen
- INFO_RANK
- Identifier for rank city information screen
- INFO_RATING
- Identifier for rating city information screen
- INFO_RCI
- Identifier for rci/demand city information screen
- INFO_STATISTICS
- Identifier for statistics city information screen
- INFO_WATER
- Identifier for water city information screen
- TAX_COMMERCIAL
- Identifier for denoting commercial tax.
- TAX_INDUSTRIAL
- Identifier for denoting industrial tax.
- TAX_RESIDENTIAL
- Identifier for denoting residential tax.