LuaSurface
A "domain" of the world. Surfaces can only be created and deleted through the API. Surfaces are uniquely identified by their name. Every game contains at least the surface "nauvis".
LuaSurface
Get the pollution for a given position.
Check for collisions with terrain or other entities.
If there exists an entity at the given location that can be fast-replaced with the given entity parameters.
Find a specific entity at a specific position.
Find entities in a given area.
Find all entities of the given type or name in the given area.
Find all tiles of the given name in the given area.
Count entities of given type or name in a given area.
Count tiles of a given name in a given area.
Find a non-colliding position within a given radius.
Find a non-colliding position within a given rectangle.
Spill items on the ground centered at a given location.
Find enemy units (entities with type "unit") of a given force within an area.
Find units (entities with type "unit") of a given force and force condition within a given area.
Find the enemy entity-with-force (military entity) closest to the given position.
Find the enemy entity-with-owner closest to the given position.
Give a command to multiple units.
Create an entity on this surface.
Creates a particle at the given location
Create a new unit group at a given position.
Send a group to build a new base.
Set tiles at specified locations.
Spawn pollution at the given position.
Get an iterator going over every chunk on this surface.
Is a given chunk generated?
Request that the game's map generator generate chunks at the given position for the given radius on this surface.
Blocks and generates all chunks that have been requested using all available threads.
Set generated status of a chunk.
Find the logistic network that covers a given position.
Finds all of the logistics networks whose construction area intersects with the given position.
Place a deconstruction request.
Cancel a deconstruction order.
Place an upgrade request.
Cancel a upgrade order.
The hidden tile name or nil
if there isn't one for the given position.
Set the hidden tile for the specified position.
Gets all tiles of the given types that are connected horizontally or vertically to the given tile position including the given tile position.
Regenerate autoplacement of some entities on this surface.
Regenerate autoplacement of some decoratives on this surface.
Print text to the chat console of all players on this surface.
Removes all decoratives from the given area.
Adds the given decoratives to the surface.
Find decoratives of a given name in a given area.
Clears all pollution on this surface.
Play a sound for every player on this surface.
Gets the resource amount of all resources on this surface
Gets a random generated chunk position or 0,0 if no chunks have been generated on this surface.
Clones the given area.
Clones the given area.
Clones the given entities.
Clears this surface deleting all entities and chunks on it.
Generates a path with the specified constraints (as an array of PathfinderWaypoints) using the unit pathfinding algorithm.
Gets the script areas that match the given name or if no name is given all areas are returned.
Gets the first script area by name or id.
Sets the given script area to the new values.
Adds the given script area.
Removes the given script area.
Gets the script positions that match the given name or if no name is given all positions are returned.
Gets the first script position by name or id.
Sets the given script position to the new values.
Adds the given script position.
Removes the given script position.
Gets the map exchange string for the current map generation settings of this surface.
Gets the starting area radius of this surface.
Gets the closest entity in the list to this position.
Gets train stops matching the given filters.
Gets the total amount of pollution on the surface by iterating over all of the chunks containing pollution.
Returns all the entities with force on this chunk for the given force.
Sets the given area to the checkerboard lab tiles.
The generation settings for this surface.
When set to true, new chunks will be generated with lab tiles, instead of using the surface's map generation settings.
When set to true, the sun will always shine.
Current wind speed.
Current wind direction.
Change in wind orientation per tick.
Is peaceful mode enabled on this surface?
True if daytime is currently frozen.
The number of ticks per day for this surface.
The multiplier of solar power on this surface.
The minimal brightness during the night.
Defines how surface daytime brightness influences each color channel of the current color lookup table (LUT).
If clouds are shown on this surface.
The class name of this object.
get_pollution
(position)
→ double
Get the pollution for a given position.
game.surfaces[1].get_pollution({1,2})
Pollution is stored per chunk, so this will return the same value for all positions in one chunk.
can_place_entity
{name,
position,
direction,
force,
build_check_type,
forced,
inner_name}
→ boolean
Check for collisions with terrain or other entities.
Name of the entity prototype to check.
Where the entity would be placed.
Direction of the placed entity.
The force that would place the entity. If not specified, the enemy force is assumed.
Which type of check should be carried out.
If true
, entities that can be marked for deconstruction are ignored. Only used if build_check_type
is either manual_ghost
, script_ghost
or blueprint_ghost
.
The prototype name of the entity contained in the ghost. Only used if name
is entity-ghost
.
can_fast_replace
{name,
position,
direction,
force}
→ boolean
If there exists an entity at the given location that can be fast-replaced with the given entity parameters.
find_entity
(entity,
position)
→ LuaEntity
find_entities
(area)
→ array[LuaEntity]
Find entities in a given area.
If no area is given all entities on the surface are returned.
Will evaluate to a list of all entities within given area.
game.surfaces["nauvis"].find_entities({{-10, -10}, {10, 10}})
find_entities_filtered
{area,
position,
radius,
name,
type,
ghost_name,
ghost_type,
direction,
collision_mask,
force,
to_be_deconstructed,
to_be_upgraded,
limit,
invert}
→ array[LuaEntity]
Find all entities of the given type or name in the given area.
If no filters (name
, type
, force
, etc.) are given, this returns all entities in the search area. If multiple filters are specified, only entities matching all given filters are returned.
If no area
or position
are given, the entire surface is searched. If position
is given, this returns the entities colliding with that position (i.e the given position is within the entity's collision box). If position
and radius
are given, this returns the entities within the radius of the position. If area
is specified, this returns the entities colliding with that area.
Has precedence over area field.
If given with position, will return all entities within the radius of the position.
If the filters should be inverted. These filters are: name, type, ghost_name, ghost_type, direction, collision_mask, force.
game.surfaces[1].find_entities_filtered{area = {{-10, -10}, {10, 10}}, type = "resource"} -- gets all resources in the rectangle
game.surfaces[1].find_entities_filtered{area = {{-10, -10}, {10, 10}}, name = "iron-ore"} -- gets all iron ores in the rectangle
game.surfaces[1].find_entities_filtered{area = {{-10, -10}, {10, 10}}, name = {"iron-ore", "copper-ore"}} -- gets all iron ore and copper ore in the rectangle
game.surfaces[1].find_entities_filtered{area = {{-10, -10}, {10, 10}}, force = "player"} -- gets player owned entities in the rectangle
game.surfaces[1].find_entities_filtered{area = {{-10, -10}, {10, 10}}, limit = 5} -- gets the first 5 entities in the rectangle
game.surfaces[1].find_entities_filtered{position = {0, 0}, radius = 10} -- gets all entities within 10 tiles of the position [0,0].
find_tiles_filtered
{area,
position,
radius,
name,
limit,
has_hidden_tile,
collision_mask}
→ array[LuaTile]
Find all tiles of the given name in the given area.
If no filters are given, this returns all tiles in the search area.
If no area
or position
and radius
is given, the entire surface is searched. If position
and radius
are given, only tiles within the radius of the position are included.
Ignored if not given with radius.
If given with position, will return all entities within the radius of the position.
count_entities_filtered
{area,
position,
radius,
name,
type,
ghost_name,
ghost_type,
direction,
collision_mask,
force,
to_be_deconstructed,
to_be_upgraded,
limit,
invert}
→ uint
Count entities of given type or name in a given area. Works just like LuaSurface::find_entities_filtered, except this only returns the count. As it doesn't construct all the wrapper objects, this is more efficient if one is only interested in the number of entities.
If no area
or position
are given, the entire surface is searched. If position
is given, this returns the entities colliding with that position (i.e the given position is within the entity's collision box). If position
and radius
are given, this returns entities in the radius of the position. If area
is specified, this returns entities colliding with that area.
If given with position, will count all entities within the radius of the position.
If the filters should be inverted. These filters are: name, type, ghost_name, ghost_type, direction, collision_mask, force.
count_tiles_filtered
{area,
position,
radius,
name,
limit,
has_hidden_tile,
collision_mask}
→ uint
Count tiles of a given name in a given area. Works just like LuaSurface::find_tiles_filtered, except this only returns the count. As it doesn't construct all the wrapper objects, this is more efficient if one is only interested in the number of tiles.
If no area
or position
and radius
is given, the entire surface is searched. If position
and radius
are given, only tiles within the radius of the position are included.
Ignored if not given with radius.
If given with position, will return all entities within the radius of the position.
find_non_colliding_position
(name,
center,
radius,
precision,
force_to_tile_center)
→ Position
Find a non-colliding position within a given radius.
Prototype name of the entity to find a position for. (The bounding box for the collision checking is taken from this prototype.)
Center of the search area.
Max distance from center
to search in. A radius of 0
means an infinitely-large search area.
The step length from the given position as it searches, in tiles. Minimum value is 0.01
.
Will only check tile centers. This can be useful when your intent is to place a building at the resulting position, as they must generally be placed at tile centers. Default false.
The non-colliding position. May be nil
if no suitable position was found.
Special care needs to be taken when using a radius of 0
. The game will not stop searching until it finds a suitable position, so it is important to make sure such a position exists. One particular case where it would not be able to find a solution is running it before any chunks have been generated.
find_non_colliding_position_in_box
(name,
search_space,
precision,
force_to_tile_center)
→ Position
Find a non-colliding position within a given rectangle.
Prototype name of the entity to find a position for. (The bounding box for the collision checking is taken from this prototype.)
The rectangle to search inside.
The step length from the given position as it searches, in tiles. Minimum value is 0.01.
Will only check tile centers. This can be useful when your intent is to place a building at the resulting position, as they must generally be placed at tile centers. Default false.
The non-colliding position. May be nil
if no suitable position was found.
spill_item_stack
(position,
items,
enable_looted,
force,
allow_belts)
→ array[LuaEntity]
Spill items on the ground centered at a given location.
Center of the spillage
Items to spill
When true, each created item will be flagged with the LuaEntity::to_be_looted flag.
When provided (and not nil
) the items will be marked for deconstruction by this force.
Whether items can be spilled onto belts. Defaults to true
.
The created item-on-ground entities.
find_enemy_units
(center,
radius,
force)
→ array[LuaEntity]
Find enemy units (entities with type "unit") of a given force within an area.
Find all units who would be interested to attack the player, within 100-tile area.
local enemies = game.player.surface.find_enemy_units(game.player.position, 100)
This is more efficient than LuaSurface::find_entities.
find_units
{area,
force,
condition}
→ array[LuaEntity]
Find units (entities with type "unit") of a given force and force condition within a given area.
Box to find units within.
Only forces which meet the condition will be included in the search.
Find friendly units to "player" force
local friendly_units = game.player.surface.find_units({area = {{-10, -10},{10, 10}}, force = "player", condition = "friend")
Find units of "player" force
local units = game.player.surface.find_units({area = {{-10, -10},{10, 10}}, force = "player", condition = "same"})
This is more efficient than LuaSurface::find_entities.
find_nearest_enemy
{position,
max_distance,
force}
→ LuaEntity
Find the enemy entity-with-force (military entity) closest to the given position.
The nearest enemy entity-with-force or nil
if no enemy could be found within the given area.
find_nearest_enemy_entity_with_owner
{position,
max_distance,
force}
→ LuaEntity
Find the enemy entity-with-owner closest to the given position.
The nearest enemy entity-with-owner or nil
if no enemy could be found within the given area.
set_multi_command
{command,
unit_count,
force,
unit_search_distance}
→ uint
Give a command to multiple units. This will automatically select suitable units for the task.
Number of units to give the command to.
Force of the units this command is to be given to. If not specified, uses the enemy force.
Radius to search for units. The search area is centered on the destination of the command.
Number of units actually sent. May be less than count
if not enough units were available.
create_entity
{name,
position,
direction,
force,
target,
source,
fast_replace,
player,
spill,
raise_built,
create_build_effect_smoke,
spawn_decorations,
move_stuck_players,
item}
→ LuaEntity
Create an entity on this surface.
The entity prototype name to create.
Where to create the entity.
Desired orientation of the entity after creation.
Force of the entity, default is enemy.
Entity with health for the new entity to target.
Source entity. Used for beams and highlight-boxes.
If true, building will attempt to simulate fast-replace building.
If given set the last_user to this player. If fast_replace is true simulate fast replace using this player.
If false while fast_replace is true and player is nil any items from fast-replacing will be deleted instead of dropped on the ground.
If true; defines.events.script_raised_built will be fired on successful entity creation.
If false, the building effect smoke will not be shown around the new entity.
If true, entity types that have spawn_decorations property will apply triggers defined in the property.
If true, any characters that are in the way of the entity are teleported out of the way.
If provided, the entity will attempt to pull stored values from this item (for example; creating a spidertron from a previously named and mined spidertron)
Other attributes may be specified depending on the type of entity:
assembling-machine
beam
Absolute target position that can be used instead of target entity (entity has precedence if both entity and position are defined).
Absolute source position that can be used instead of source entity (entity has precedence if both entity and position are defined).
If set, beam will be destroyed when distance between source and target is greater than this value.
If set, beam will be destroyed after this value of ticks.
Source position will be offset by this value when rendering the beam.
container
Inventory index where the red limiting bar should be set.
cliff
If not specified, direction
will be used instead.
flying-text
entity-ghost
fire
With how many small flames should the fire on ground be created. Defaults to the initial flame count of the prototype.
inserter
item-entity
The stack of items to create.
item-request-proxy
The target items are to be delivered to.
rolling-stock
The orientation of this rolling stock.
The color of this rolling stock, if it supports colors.
locomotive
Whether the locomotive should snap to an adjacent train stop. Defaults to true.
logistic-container
particle
artillery-flare
projectile
resource
If colliding trees are removed normally for this resource entity based off the prototype tree removal values. Default is true.
If colliding cliffs are removed. Default is true.
If true, the resource entity will be placed to center of a tile as map generator would place it, otherwise standard non-resource grid alignment rules will apply. Default is true.
underground-belt
"output"
or "input"
; default is "input"
.
programmable-speaker
character-corpse
highlight-box
The bounding box defining the highlight box using absolute map coordinates. If specified, the position
parameter is ignored, but needs to be present anyways. If not specified, the game falls back to the source
parameter first, then the target
parameter second. One of these three parameters need to be specified.
Specifies the graphical appearance (color) of the highlight box. Defaults to "electricity"
.
The player to render the highlight box for. If not provided, it will be rendered for all players.
The blink interval for this highlight box. Makes it be shown every blink_interval
ticks. Defaults to 0
(constantly shown).
The amount of time in ticks that the highlight box will exist for. Defaults to existing forever.
speech-bubble
simple-entity-with-owner
simple-entity-with-force
The created entity or nil
if the creation failed.
asm = game.surfaces[1].create_entity{name = "assembling-machine-1", position = {15, 3}, force = game.forces.player, recipe = "iron-stick"}
Creates a filter inserter with circuit conditions and a filter
game.surfaces[1].create_entity{
name = "filter-inserter", position = {20, 15}, force = game.player.force,
conditions = {red = {name = "wood", count = 3, operator = ">"},
green = {name = "iron-ore", count = 1, operator = "<"},
logistics = {name = "wood", count = 3, operator = "="}},
filters = {{index = 1, name = "iron-ore"}}
}
Creates a requester chest already set to request 128 iron plates.
game.surfaces[1].create_entity{
name = "logistic-chest-requester", position = {game.player.position.x+3, game.player.position.y},
force = game.player.force, request_filters = {{index = 1, name = "iron-plate", count = 128}}
}
game.surfaces[1].create_entity{name = "big-biter", position = {15, 3}, force = game.forces.player} -- Friendly biter
game.surfaces[1].create_entity{name = "medium-biter", position = {15, 3}, force = game.forces.enemy} -- Enemy biter
Creates a basic inserter at the player's location facing north
game.surfaces[1].create_entity{name = "inserter", position = game.player.position, direction = defines.direction.north}
create_unit_group
{position,
force}
→ LuaUnitGroup
Create a new unit group at a given position.
Initial position of the new unit group.
Force of the new unit group. Defaults to "enemy"
.
build_enemy_base
(position,
unit_count,
force)
Send a group to build a new base.
The specified force must be AI-controlled; i.e. force.ai_controllable
must be true
.
get_tile
(x,
y)
→ LuaTile
set_tiles
(tiles,
correct_tiles,
remove_colliding_entities,
remove_colliding_decoratives,
raise_event)
Set tiles at specified locations. Can automatically correct the edges around modified tiles.
Placing a mineable tile on top of a non-mineable one will turn the latter into the LuaTile::hidden_tile for that tile. Placing a mineable tile on a mineable one or a non-mineable tile on a non-mineable one will not modify the hidden tile. This restriction can however be circumvented by using LuaSurface::set_hidden_tile.
If false
, the correction logic is not applied to the changed tiles. Defaults to true
.
true
, false
, or abort_on_collision
. Defaults to true
.
true
or false
. Defaults to true
.
true
or false
. Defaults to false
.
It is recommended to call this method once for all the tiles you want to change rather than calling it individually for every tile. As the tile correction is used after every step, calling it one by one could cause the tile correction logic to redo some of the changes. Also, many small API calls are generally more performance intensive than one big one.
get_chunks
()
→ LuaChunkIterator
Get an iterator going over every chunk on this surface.
is_chunk_generated
(position)
→ boolean
force_generate_chunk_requests
()
Blocks and generates all chunks that have been requested using all available threads.
set_chunk_generated_status
(position,
status)
Set generated status of a chunk. Useful when copying chunks.
The chunk's position.
The chunk's new status.
find_logistic_network_by_position
(position,
force)
→ LuaLogisticNetwork
Find the logistic network that covers a given position.
Force the logistic network should belong to.
The found network or nil
if no such network was found.
find_logistic_networks_by_construction_area
(position,
force)
→ array[LuaLogisticNetwork]
Finds all of the logistics networks whose construction area intersects with the given position.
Force the logistic networks should belong to.
deconstruct_area
{area,
force,
player,
skip_fog_of_war,
item}
Place a deconstruction request.
The area to mark for deconstruction.
The force whose bots should perform the deconstruction.
The player to set the last_user to if any.
If chunks covered by fog-of-war are skipped.
The deconstruction item to use if any.
cancel_deconstruct_area
{area,
force,
player,
skip_fog_of_war,
item}
Cancel a deconstruction order.
The area to cancel deconstruction orders in.
The force whose deconstruction orders to cancel.
The player to set the last_user to if any.
If chunks covered by fog-of-war are skipped.
The deconstruction item to use if any.
upgrade_area
{area,
force,
player,
skip_fog_of_war,
item}
Place an upgrade request.
The area to mark for upgrade.
The force whose bots should perform the upgrade.
The player to set the last_user to if any.
If chunks covered by fog-of-war are skipped.
The upgrade item to use.
cancel_upgrade_area
{area,
force,
player,
skip_fog_of_war,
item}
Cancel a upgrade order.
The area to cancel upgrade orders in.
The force whose upgrade orders to cancel.
The player to set the last_user to if any.
If chunks covered by fog-of-war are skipped.
The upgrade item to use if any.
get_connected_tiles
(position,
tiles)
→ array[Position]
Gets all tiles of the given types that are connected horizontally or vertically to the given tile position including the given tile position.
The resulting set of tiles.
This won't find tiles in non-generated chunks.
delete_chunk
(position)
The chunk position to delete
This won't delete the chunk immediately. Chunks are deleted at the end of the current tick.
regenerate_entity
(entities,
chunks)
Regenerate autoplacement of some entities on this surface. This can be used to autoplace newly-added entities.
Prototype names of entity or entities to autoplace. When nil
all entities with an autoplace are used.
The chunk positions to regenerate the entities on. If not given all chunks are regenerated. Note chunks with status < entities are ignored.
All specified entity prototypes must be autoplacable. If nothing is given all entities are generated on all chunks.
regenerate_decorative
(decoratives,
chunks)
Regenerate autoplacement of some decoratives on this surface. This can be used to autoplace newly-added decoratives.
Prototype names of decorative or decoratives to autoplace. When nil
all decoratives with an autoplace are used.
The chunk positions to regenerate the entities on. If not given all chunks are regenerated. Note chunks with status < entities are ignored.
All specified decorative prototypes must be autoplacable. If nothing is given all decoratives are generated on all chunks.
print
(message,
color)
Print text to the chat console of all players on this surface.
Messages that are identical to a message sent in the last 60 ticks are not printed again.
destroy_decoratives
{area,
position,
name,
limit,
invert}
Removes all decoratives from the given area. If no area and no position are given, then the entire surface is searched.
If the filters should be inverted.
create_decoratives
{check_collision,
decoratives}
Adds the given decoratives to the surface.
If collision should be checked against entities/tiles.
This will merge decoratives of the same type that already exist effectively increasing the "amount" field.
find_decoratives_filtered
{area,
position,
name,
limit,
invert}
→ array[DecorativeResult]
Find decoratives of a given name in a given area.
If no filters are given, returns all decoratives in the search area. If multiple filters are specified, returns only decoratives matching every given filter. If no area and no position are given, the entire surface is searched.
If the filters should be inverted.
game.surfaces[1].find_decoratives_filtered{area = {{-10, -10}, {10, 10}}, name = "sand-decal"} -- gets all sand-decals in the rectangle
game.surfaces[1].find_decoratives_filtered{area = {{-10, -10}, {10, 10}}, limit = 5} -- gets the first 5 decoratives in the rectangle
get_trains
(force)
→ array[LuaTrain]
If given only trains matching this force are returned.
play_sound
{path,
position,
volume_modifier,
override_sound_type}
Play a sound for every player on this surface.
The sound to play.
Where the sound should be played. If not given, it's played at the current position of each player.
The volume of the sound to play. Must be between 0 and 1 inclusive.
The volume mixer to play the sound through. Defaults to the default mixer for the given sound type.
get_resource_counts
()
→ dictionary[string → uint]
Gets the resource amount of all resources on this surface
get_random_chunk
()
→ ChunkPosition
Gets a random generated chunk position or 0,0 if no chunks have been generated on this surface.
clone_area
{source_area,
destination_area,
destination_surface,
destination_force,
clone_tiles,
clone_entities,
clone_decoratives,
clear_destination_entities,
clear_destination_decoratives,
expand_map,
create_build_effect_smoke}
Clones the given area.
If tiles should be cloned
If entities should be cloned
If decoratives should be cloned
If the destination entities should be cleared
If the destination decoratives should be cleared
If the destination surface should be expanded when destination_area is outside current bounds. Default false.
If true, the building effect smoke will be shown around the new entities.
defines.events.on_entity_cloned is raised for each entity, and then defines.events.on_area_cloned is raised.
Entities are cloned in an order such that they can always be created, eg rails before trains.
clone_brush
{source_offset,
destination_offset,
source_positions,
destination_surface,
destination_force,
clone_tiles,
clone_entities,
clone_decoratives,
clear_destination_entities,
clear_destination_decoratives,
expand_map,
manual_collision_mode,
create_build_effect_smoke}
Clones the given area.
If tiles should be cloned
If entities should be cloned
If decoratives should be cloned
If the destination entities should be cleared
If the destination decoratives should be cleared
If the destination surface should be expanded when destination_area is outside current bounds. Default false.
If manual-style collision checks should be done.
If true, the building effect smoke will be shown around the new entities.
defines.events.on_entity_cloned is raised for each entity, and then defines.events.on_area_cloned is raised.
Entities are cloned in an order such that they can always be created, eg rails before trains.
clone_entities
{entities,
destination_offset,
destination_surface,
destination_force,
snap_to_grid,
create_build_effect_smoke}
Clones the given entities.
defines.events.on_entity_cloned is raised for each entity.
Entities are cloned in an order such that they can always be created, eg rails before trains.
clear
(ignore_characters)
Clears this surface deleting all entities and chunks on it.
Whether characters on this surface that are connected to or associated with players should be ignored (not destroyed).
This won't clear the surface immediately. It will be cleared at the end of the current tick.
request_path
{bounding_box,
collision_mask,
start,
goal,
force,
radius,
pathfind_flags,
can_open_gates,
path_resolution_modifier,
entity_to_ignore}
→ uint
Generates a path with the specified constraints (as an array of PathfinderWaypoints) using the unit pathfinding algorithm. This path can be used to emulate pathing behavior by script for non-unit entities. If you want to command actual units to move, use the LuaEntity::set_command functionality instead.
The resulting path is ultimately returned asynchronously via on_script_path_request_finished.
The dimensions of the object that's supposed to travel the path.
The list of masks the bounding_box
collides with.
The position from which to start pathfinding.
The position to find a path to.
The force for which to generate the path, determining which gates can be opened for example.
How close the pathfinder needs to get to its goal
(in tiles). Defaults to 1
.
Flags that affect pathfinder behavior.
Whether the path request can open gates. Defaults to false
.
Defines how coarse the pathfinder's grid is. Smaller values mean a coarser grid (negative numbers allowed). Defaults to 0
.
Makes the pathfinder ignore collisions with this entity if it is given.
A unique handle to identify this call when on_script_path_request_finished fires.
get_script_areas
(name)
→ array[ScriptArea]
Gets the script areas that match the given name or if no name is given all areas are returned.
get_script_area
(key)
→ ScriptArea
edit_script_area
(id,
area)
Sets the given script area to the new values.
The area to edit.
add_script_area
(area)
→ uint
remove_script_area
(id)
→ boolean
Removes the given script area.
If the area was actually removed. False when it didn't exist.
get_script_positions
(name)
→ array[ScriptPosition]
Gets the script positions that match the given name or if no name is given all positions are returned.
get_script_position
(key)
→ ScriptPosition
edit_script_position
(id,
area)
add_script_position
(area)
→ uint
Adds the given script position.
The id of the created position.
remove_script_position
(id)
→ boolean
Removes the given script position.
If the position was actually removed. False when it didn't exist.
get_map_exchange_string
()
→ string
Gets the map exchange string for the current map generation settings of this surface.
get_starting_area_radius
()
→ double
Gets the starting area radius of this surface.
get_closest
(position,
entities)
→ LuaEntity
get_train_stops
{name,
force}
→ array[LuaEntity]
Gets train stops matching the given filters.
get_total_pollution
()
→ double
Gets the total amount of pollution on the surface by iterating over all of the chunks containing pollution.
entity_prototype_collides
(prototype,
position,
use_map_generation_bounding_box,
direction)
get_entities_with_force
(position,
force)
→ array[LuaEntity]
Returns all the entities with force on this chunk for the given force.
The chunk's position.
help
()
→ string
All methods and properties that this object supports.
name
:: string
[Read/Write]
The name of this surface. Names are unique among surfaces.
the default surface can't be renamed.
index
:: uint
[Read]
Unique ID associated with this surface.
map_gen_settings
:: MapGenSettings
[Read/Write]
The generation settings for this surface. These can be modified to after surface generation, but note that this will not retroactively update the surface. To manually adjust it, LuaSurface::regenerate_entity, LuaSurface::regenerate_decorative and LuaSurface::delete_chunk can be used.
generate_with_lab_tiles
:: boolean
[Read/Write]
When set to true, new chunks will be generated with lab tiles, instead of using the surface's map generation settings.
always_day
:: boolean
[Read/Write]
When set to true, the sun will always shine.
daytime
:: double
[Read/Write]
Current time of day, as a number in range [0, 1).
darkness
:: float
[Read]
Amount of darkness at the current time.
wind_speed
:: double
[Read/Write]
Current wind speed.
wind_orientation
:: RealOrientation
[Read/Write]
Current wind direction.
wind_orientation_change
:: double
[Read/Write]
Change in wind orientation per tick.
peaceful_mode
:: boolean
[Read/Write]
Is peaceful mode enabled on this surface?
freeze_daytime
:: boolean
[Read/Write]
True if daytime is currently frozen.
ticks_per_day
:: uint
[Read/Write]
The number of ticks per day for this surface.
dusk
:: double
[Read/Write]
The daytime when dusk starts.
dawn
:: double
[Read/Write]
The daytime when dawn starts.
evening
:: double
[Read/Write]
The daytime when evening starts.
morning
:: double
[Read/Write]
The daytime when morning starts.
solar_power_multiplier
:: double
[Read/Write]
The multiplier of solar power on this surface. Cannot be less than 0.
Solar equipment is still limited to its maximum power output.
min_brightness
:: double
[Read/Write]
The minimal brightness during the night. Default is 0.15
. The value has an effect on the game simalution only, it doesn't have any effect on rendering.
brightness_visual_weights
:: ColorModifier
[Read/Write]
Defines how surface daytime brightness influences each color channel of the current color lookup table (LUT).
The LUT is multiplied by ((1 - weight) + brightness * weight)
and result is clamped to range [0, 1].
Default is {0, 0, 0}
, which means no influence.
Makes night on the surface pitch black, assuming LuaSurface::min_brightness being set to default value 0.15
.
game.surfaces[1].brightness_visual_weights = { 1 / 0.85, 1 / 0.85, 1 / 0.85 }
show_clouds
:: boolean
[Read/Write]
If clouds are shown on this surface.
If false, clouds are never shown. If true the player must also have clouds enabled in graphics settings for them to be shown.
valid
:: boolean
[Read]
Is this object valid? This Lua object holds a reference to an object within the game engine. It is possible that the game-engine object is removed whilst a mod still holds the corresponding Lua object. If that happens, the object becomes invalid, i.e. this attribute will be false
. Mods are advised to check for object validity if any change to the game state might have occurred between the creation of the Lua object and its access.
object_name
:: string
[Read]
The class name of this object. Available even when valid
is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.