Home

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".

Attributes

name

The name of this surface. Names are unique among surfaces.

The default surface can't be renamed.

index

This surface's index in LuaGameScript::surfaces (unique ID). It is assigned when a surface is created, and remains so until it is deleted. Indexes of deleted surfaces can be reused.

map_gen_settings

The generation settings for this surface. These can be modified after surface generation, but note that this will not retroactively update the surface. To manually regenerate it, LuaSurface::regenerate_entity, LuaSurface::regenerate_decorative, and LuaSurface::delete_chunk can be used.

generate_with_lab_tiles

When set to true, new chunks will be generated with lab tiles, instead of using the surface's map generation settings.

always_day

When set to true, the sun will always shine.

daytime

Current time of day, as a number in range [0, 1).

darkness

Amount of darkness at the current time, as a number in range [0, 1].

wind_speed

Current wind speed in tiles per tick.

wind_orientation

Current wind direction.

wind_orientation_change

Change in wind orientation per tick.

peaceful_mode

Is peaceful mode enabled on this surface?

no_enemies_mode

Is no-enemies mode enabled on this surface?

freeze_daytime

True if daytime is currently frozen.

ticks_per_day

The number of ticks per day for this surface.

dusk

The daytime when dusk starts.

dawn

The daytime when dawn starts.

evening

The daytime when evening starts.

morning

The daytime when morning starts.

daytime_parameters

Parameters of daytime. Equivalent as reading dusk, evening, morning and dawn at the same time.

In order for a write to take place, a new table needs to be written in one go: changing individual members of the returned table has no effect as those are value copies.

solar_power_multiplier

The multiplier of solar power on this surface. Cannot be less than 0.

min_brightness

The minimal brightness during the night. Defaults to 0.15. This has an effect on both rendering and game mechanics such as biter spawns and solar power.

brightness_visual_weights

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.

show_clouds

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.

has_global_electric_network

Whether this surface currently has a global electric network.

platform

planet

The planet associated with this surface, if there is one.

Use LuaPlanet::associate_surface to create a new association with a planet.

deletable

If this surface can be deleted.

global_effect

Surface-wide effects applied to entities with effect receivers. nil if this surface is not using surface-wide effect source.

pollutant_type

The type of pollutant enabled on the surface, or nil if no pollutant is enabled.

localised_name

Localised name of this surface. When set, will replace the internal surface name in places where a player sees surface name.

Value may be ignored if a surface has a SpacePlatform or Planet object attached to it, which take the precedence.

ignore_surface_conditions

If surface condition checks should not be performed on this surface.

pollution_statistics

The pollution statistics for this surface.

global_electric_network_statistics

The global electric network statistics for this surface.

valid

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

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.

Methods

get_pollution

LuaSurface.get_pollution(position: MapPosition) -> double

Call As

surface.get_pollution(position)

Call Convention

Get the pollution for a given position.

Pollution is stored per chunk, so this will return the same value for all positions in one chunk.

Parameters

Returns

set_pollution

LuaSurface.set_pollution(position: MapPosition, amount: double)

Call As

surface.set_pollution(position, amount)

Call Convention

Set the pollution for a given position.

Pollution changes by this are not included in pollution statistics and do not affect evolution factors (as opposed to LuaSurface::pollute).

Parameters

can_place_entity

LuaSurface.can_place_entity{ name: EntityID, position: MapPosition, direction?: defines.direction, force?: ForceID, build_check_type?: defines.build_check_type, forced?: boolean, inner_name?: string } -> boolean

Call As

surface.can_place_entity{ name="name", position=position }

Call Convention

Check for collisions with terrain or other entities.

Parameters

Returns

can_fast_replace

LuaSurface.can_fast_replace{ name: EntityID, position: MapPosition, direction?: defines.direction, force?: ForceID } -> boolean

Call As

surface.can_fast_replace{ name="name", position=position }

Call Convention

If there exists an entity at the given location that can be fast-replaced with the given entity parameters.

Parameters

Returns

find_entity

LuaSurface.find_entity(entity: EntityWithQualityID, position: MapPosition) -> LuaEntity?

Call As

surface.find_entity(entity, position)

Call Convention

Find an entity of the given name at the given position. This checks both the exact position and the bounding box of the entity.

Parameters

Returns

find_entities

LuaSurface.find_entities(area?: BoundingBox) -> Array<LuaEntity>

Call As

surface.find_entities()

Call Convention

Find entities in a given area.

If no area is given all entities on the surface are returned.

Parameters

Returns

find_entities_filtered

LuaSurface.find_entities_filtered(filter: EntitySearchFilters) -> Array<LuaEntity>

Call As

surface.find_entities_filtered(filter)

Call Convention

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.

Parameters

Returns

find_tiles_filtered

LuaSurface.find_tiles_filtered(filter: TileSearchFilters) -> Array<LuaTile>

Call As

surface.find_tiles_filtered(filter)

Call Convention

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.

Parameters

Returns

count_entities_filtered

LuaSurface.count_entities_filtered(filter: EntitySearchFilters) -> uint32

Call As

surface.count_entities_filtered(filter)

Call Convention

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.

Parameters

Returns

count_tiles_filtered

LuaSurface.count_tiles_filtered(filter: TileSearchFilters) -> uint32

Call As

surface.count_tiles_filtered(filter)

Call Convention

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.

Parameters

Returns

find_non_colliding_position

LuaSurface.find_non_colliding_position(name: EntityID, center: MapPosition, radius: double, precision: double, force_to_tile_center?: boolean) -> MapPosition?

Call As

surface.find_non_colliding_position("name", center, radius, precision)

Call Convention

Find a non-colliding position within a given radius.

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.

Parameters

Returns

find_non_colliding_position_in_box

LuaSurface.find_non_colliding_position_in_box(name: EntityID, search_space: BoundingBox, precision: double, force_to_tile_center?: boolean) -> MapPosition?

Call As

surface.find_non_colliding_position_in_box("name", search_space, precision)

Call Convention

Find a non-colliding position within a given rectangle.

Parameters

Returns

spill_item_stack

LuaSurface.spill_item_stack{ position: MapPosition, stack: ItemStackIdentification, enable_looted?: boolean, force?: ForceID, allow_belts?: boolean, max_radius?: double, use_start_position_on_failure?: boolean, drop_full_stack?: boolean } -> Array<LuaEntity>

Call As

surface.spill_item_stack{ position=position, stack=stack }

Call Convention

Spill items on the ground centered at a given location.

Parameters

Returns

spill_inventory

LuaSurface.spill_inventory{ position: MapPosition, inventory: LuaInventory, enable_looted?: boolean, force?: ForceID, allow_belts?: boolean, max_radius?: double, use_start_position_on_failure?: boolean, drop_full_stack?: boolean } -> Array<LuaEntity>

Call As

surface.spill_inventory{ position=position, inventory=inventory }

Call Convention

Spill inventory on the ground centered at a given location.

Parameters

Returns

find_enemy_units

LuaSurface.find_enemy_units(center: MapPosition, radius: double, force?: ForceID) -> Array<LuaEntity>

Call As

surface.find_enemy_units(center, radius, force)

Call Convention

Find enemy units (entities with type "unit") of a given force within an area.

This is more efficient than LuaSurface::find_entities.

Parameters

Returns

find_units

LuaSurface.find_units{ area: BoundingBox, force: ForceID, condition: ForceCondition } -> Array<LuaEntity>

Call As

surface.find_units{ area=area, force=force, condition=condition }

Call Convention

Find units (entities with type "unit") of a given force and force condition within a given area.

This is more efficient than LuaSurface::find_entities.

Parameters

Returns

find_nearest_enemy

LuaSurface.find_nearest_enemy{ position: MapPosition, max_distance: double, force?: ForceID } -> LuaEntity?

Call As

surface.find_nearest_enemy{ position=position, max_distance=max_distance }

Call Convention

Find the enemy military target (military entity) closest to the given position.

Parameters

Returns

find_nearest_enemy_entity_with_owner

LuaSurface.find_nearest_enemy_entity_with_owner{ position: MapPosition, max_distance: double, force?: ForceID } -> LuaEntity

Call As

surface.find_nearest_enemy_entity_with_owner{ position=position, max_distance=max_distance }

Call Convention

Find the enemy entity-with-owner closest to the given position.

Parameters

Returns

set_multi_command

LuaSurface.set_multi_command{ command: Command, unit_count: uint32, force?: ForceID, unit_search_distance?: uint32 } -> uint32

Call As

surface.set_multi_command{ command=command, unit_count=unit_count }

Call Convention

Give a command to multiple units. This will automatically select suitable units for the task.

Parameters

Returns

create_entity

LuaSurface.create_entity{ name: EntityID, position: MapPosition, direction?: defines.direction, quality?: QualityID, force?: ForceID, target?: LuaEntity | MapPosition, source?: LuaEntity | MapPosition, cause?: LuaEntity | ForceID, snap_to_grid?: boolean, fast_replace?: boolean, undo_index?: uint32, player?: PlayerIdentification, character?: LuaEntity, spill?: boolean, raise_built?: boolean, create_build_effect_smoke?: boolean, spawn_decorations?: boolean, move_stuck_players?: boolean, item?: LuaItemStack, preserve_ghosts_and_corpses?: boolean, register_plant?: boolean, burner_fuel_inventory?: BlueprintInventoryWithFilters } -> LuaEntity?

Call As

surface.create_entity{ name="name", position=position }

Call Convention

Create an entity on this surface.

Parameters

Returns

create_segmented_unit

LuaSurface.create_segmented_unit{ name: EntityID, quality?: QualityID, force?: ForceID, territory?: LuaTerritory } -> LuaSegmentedUnit?

Call As

surface.create_segmented_unit{ name="name" }

Call Convention

Create a segmented unit on the surface. This differs from creating an entity with type "segmented-unit" in that this method can create the entity in non-generated chunks and with any arbitrary body shape and pre-assigned to a territory.

Parameters

Returns

create_territory

LuaSurface.create_territory{ chunks: Array<ChunkPosition>, patrol_path?: Array<MapPosition> } -> LuaTerritory?

Call As

surface.create_territory{ chunks=chunks }

Call Convention

Create a territory on the surface.

Parameters

Returns

create_trivial_smoke

LuaSurface.create_trivial_smoke{ name: TrivialSmokeID, position: MapPosition }

Call As

surface.create_trivial_smoke{ name="name", position=position }

Call Convention

Parameters

create_particle

LuaSurface.create_particle{ name: ParticleID, position: MapPosition, movement: Vector, height: float, vertical_speed: float, frame_speed: float }

Call As

surface.create_particle{ name="name", position=position, movement=movement, height=height, vertical_speed=vertical_speed, frame_speed=frame_speed }

Call Convention

Creates a particle at the given location

Parameters

create_unit_group

LuaSurface.create_unit_group{ position: MapPosition, force?: ForceID } -> LuaCommandable

Call As

surface.create_unit_group{ position=position }

Call Convention

Create a new unit group at a given position.

Parameters

Returns

build_enemy_base

LuaSurface.build_enemy_base(position: MapPosition, unit_count: uint32, force?: ForceID)

Call As

surface.build_enemy_base(position, unit_count, force)

Call Convention

Send a group to build a new base.

The specified force must be AI-controlled; i.e. force.ai_controllable must be true.

Parameters

get_tile

LuaSurface.get_tile(x: int32, y: int32) -> LuaTile

Call As

surface.get_tile(x, y)

Call Convention

Get the tile at a given position. An alternative call signature for this method is passing it a single TilePosition.

Non-integer values will result in them being rounded down.

Parameters

Returns

set_tiles

LuaSurface.set_tiles(tiles: Array<Tile>, correct_tiles?: boolean, remove_colliding_entities?: boolean | "abort_on_collision", remove_colliding_decoratives?: boolean, raise_event?: boolean, player?: PlayerIdentification, undo_index?: uint32)

Call As

surface.set_tiles(tiles, true)

Call Convention

Set tiles at specified locations. Can automatically correct the edges around modified tiles.

Placing a mineable tile on top of a non-mineable or foundation one will turn the latter into the LuaTile::hidden_tile for that tile. Placing a mineable non-foundation tile on a mineable non-foundation one or a mineable foundation tile on a mineable foundation one will not modify the hidden tile. This restriction can however be circumvented by using LuaSurface::set_hidden_tile. Placing a non-foundation tile on top of a foundation one when there already exists a hidden tile will push hidden tile to double hidden, and foundation tile will turn into hidden. Placing a mineable foundation tile over a mineable non-foundation tile with hidden mineable foundation tile, the hidden tile will be replaced by previously double hidden tile and double hidden tile will be erased. Placing a non-mineable tile will erase hidden and double hidden tiles.

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.

Parameters

pollute

LuaSurface.pollute(source: MapPosition, amount: double, prototype?: EntityID)

Call As

surface.pollute(source, amount, prototype)

Call Convention

Spawn pollution at the given position.

Parameters

get_chunks

LuaSurface.get_chunks() -> LuaChunkIterator

Call As

surface.get_chunks()

Call Convention

Get an iterator going over every chunk on this surface.

Chunks may or may not be generated; use LuaSurface::is_chunk_generated to check a chunk's state before accessing it.

Returns

is_chunk_generated

LuaSurface.is_chunk_generated(chunk_position: ChunkPosition) -> boolean

Call As

surface.is_chunk_generated(chunk_position)

Call Convention

Is a given chunk generated?

Parameters

Returns

request_to_generate_chunks

LuaSurface.request_to_generate_chunks(position: MapPosition, radius?: uint32)

Call As

surface.request_to_generate_chunks(position, radius)

Call Convention

Request that the game's map generator generate chunks at the given position for the given radius on this surface. If the radius is 0, then only the chunk at the given position is generated.

Parameters

force_generate_chunk_requests

LuaSurface.force_generate_chunk_requests()

Call As

surface.force_generate_chunk_requests()

Call Convention

Blocks and generates all chunks that have been requested using all available threads.

set_chunk_generated_status

LuaSurface.set_chunk_generated_status(chunk_position: ChunkPosition, status: defines.chunk_generated_status)

Call As

surface.set_chunk_generated_status(chunk_position, status)

Call Convention

Set generated status of a chunk. Useful when copying chunks.

Parameters

get_territories

LuaSurface.get_territories() -> Array<LuaTerritory>

Call As

surface.get_territories()

Call Convention

Get all territories on the surface.

Returns

get_territory_for_chunk

LuaSurface.get_territory_for_chunk(chunk_position: ChunkPosition) -> LuaTerritory?

Call As

surface.get_territory_for_chunk(chunk_position)

Call Convention

Get the territory that the given chunk is assigned to. If the chunk is not part of any territory or the territory for the chunk has not yet been generated, then this returns nil.

Parameters

Returns

set_territory_for_chunks

LuaSurface.set_territory_for_chunks(chunk_positions: Array<ChunkPosition>, territory?: LuaTerritory)

Call As

surface.set_territory_for_chunks(chunk_positions, territory)

Call Convention

Removes the given chunks from their current territories and adds them to the given territory if provided.

This does not affect the LuaTerritory::get_patrol_path. It is your responsibility to update the patrol path if needed.

It's recommended that territory chunks are connected to each other, but this is not required.

Territories that do not contain at least one generated chunk as a result of calling this method will be automatically deleted.

Parameters

clear_territory_for_chunks

LuaSurface.clear_territory_for_chunks(chunk_positions: Array<ChunkPosition>)

Call As

surface.clear_territory_for_chunks(chunk_positions)

Call Convention

Removes the chunk from the territory it is associated with (if any) and allows the map generator to potentially generate a new territory for the chunk in the future. To prevent the game from generating a new territory for the chunk, use LuaSurface::set_chunk_territory to set the chunk's territory to nil.

Territories that do not contain at least one generated chunk as a result of calling this method will be automatically deleted.

Parameters

get_segmented_units

LuaSurface.get_segmented_units() -> Array<LuaSegmentedUnit>

Call As

surface.get_segmented_units()

Call Convention

Get all segmented units that exist on the surface.

Returns

find_logistic_network_by_position

LuaSurface.find_logistic_network_by_position(position: MapPosition, force: ForceID) -> LuaLogisticNetwork?

Call As

surface.find_logistic_network_by_position(position, force)

Call Convention

Find the logistic network that covers a given position.

Parameters

Returns

find_closest_logistic_network_by_position

LuaSurface.find_closest_logistic_network_by_position(position: MapPosition, force: ForceID) -> LuaLogisticNetwork?

Call As

surface.find_closest_logistic_network_by_position(position, force)

Call Convention

Find the logistic network with a cell closest to a given position.

Parameters

Returns

find_logistic_networks_by_construction_area

LuaSurface.find_logistic_networks_by_construction_area(position: MapPosition, force: ForceID) -> Array<LuaLogisticNetwork>

Call As

surface.find_logistic_networks_by_construction_area(position, force)

Call Convention

Finds all of the logistics networks whose construction area intersects with the given position.

Parameters

Returns

deconstruct_area

LuaSurface.deconstruct_area{ area: BoundingBox, force: ForceID, player?: PlayerIdentification, skip_fog_of_war?: boolean, item?: LuaItemStack, super_forced?: boolean }

Call As

surface.deconstruct_area{ area=area, force=force }

Call Convention

Place a deconstruction request.

Parameters

cancel_deconstruct_area

LuaSurface.cancel_deconstruct_area{ area: BoundingBox, force: ForceID, player?: PlayerIdentification, skip_fog_of_war?: boolean, item?: LuaItemStack, undo_index?: uint32, super_forced?: boolean }

Call As

surface.cancel_deconstruct_area{ area=area, force=force }

Call Convention

Cancel a deconstruction order.

Parameters

upgrade_area

LuaSurface.upgrade_area{ area: BoundingBox, force: ForceID, player?: PlayerIdentification, skip_fog_of_war?: boolean, item: LuaItemStack }

Call As

surface.upgrade_area{ area=area, force=force, item=item }

Call Convention

Place an upgrade request.

Parameters

cancel_upgrade_area

LuaSurface.cancel_upgrade_area{ area: BoundingBox, force: ForceID, player?: PlayerIdentification, skip_fog_of_war?: boolean, item: LuaItemStack }

Call As

surface.cancel_upgrade_area{ area=area, force=force, item=item }

Call Convention

Cancel a upgrade order.

Parameters

get_hidden_tile

LuaSurface.get_hidden_tile(position: TilePosition) -> string?

Call As

surface.get_hidden_tile(position)

Call Convention

The hidden tile name.

Parameters

Returns

get_double_hidden_tile

LuaSurface.get_double_hidden_tile(position: TilePosition) -> string

Call As

surface.get_double_hidden_tile(position)

Call Convention

The double hidden tile name or nil if there isn't one for the given position.

Parameters

Returns

set_hidden_tile

LuaSurface.set_hidden_tile(position: TilePosition, tile?: TileID)

Call As

surface.set_hidden_tile(position, tile)

Call Convention

Set the hidden tile for the specified position. While during normal gameplay only non-mineable or foundation tiles can become hidden, this method allows any kind of tile to be set as the hidden one.

Parameters

set_double_hidden_tile

LuaSurface.set_double_hidden_tile(position: TilePosition, tile?: TileID)

Call As

surface.set_double_hidden_tile(position, tile)

Call Convention

Set double hidden tile for the specified position. During normal gameplay, only non-mineable tiles can become double hidden.

Does nothing if hidden tile at specified position does not exist.

Parameters

get_connected_tiles

LuaSurface.get_connected_tiles(position: TilePosition, tiles: Array<TileID>, include_diagonal?: boolean, area?: BoundingBox) -> Array<TilePosition>

Call As

surface.get_connected_tiles(position, tiles, true)

Call Convention

Gets all tiles of the given types that are connected horizontally or vertically to the given tile position including the given tile position.

This won't find tiles in non-generated chunks.

Parameters

Returns

delete_chunk

LuaSurface.delete_chunk(chunk_position: ChunkPosition)

Call As

surface.delete_chunk(chunk_position)

Call Convention

Parameters

regenerate_entity

LuaSurface.regenerate_entity(entities?: string | Array<string>, chunks?: Array<ChunkPosition>)

Call As

surface.regenerate_entity()

Call Convention

Regenerate autoplacement of some entities on this surface. This can be used to autoplace newly-added entities.

All specified entity prototypes must be autoplacable. If nothing is given all entities are generated on all chunks.

Parameters

regenerate_decorative

LuaSurface.regenerate_decorative(decoratives?: string | Array<string>, chunks?: Array<ChunkPosition>)

Call As

surface.regenerate_decorative()

Call Convention

Regenerate autoplacement of some decoratives on this surface. This can be used to autoplace newly-added decoratives.

All specified decorative prototypes must be autoplacable. If nothing is given all decoratives are generated on all chunks.

Parameters

print

LuaSurface.print(message: LocalisedString, print_settings?: PrintSettings)

Call As

surface.print(message, print_settings)

Call Convention

Print text to the chat console of all players on this surface.

By default, messages that are identical to a message sent in the last 60 ticks are not printed again.

Parameters

destroy_decoratives

LuaSurface.destroy_decoratives{ area?: BoundingBox, position?: TilePosition, name?: DecorativeID | Array<DecorativeID>, collision_mask?: CollisionLayerID | Array<CollisionLayerID> | Dict<CollisionLayerID, true>, from_layer?: string, to_layer?: string, exclude_soft?: boolean, limit?: uint32, invert?: boolean }

Call As

surface.destroy_decoratives{ area=area }

Call Convention

Removes all decoratives from the given area. If no area and no position are given, then the entire surface is searched.

Parameters

create_decoratives

LuaSurface.create_decoratives{ check_collision?: boolean, decoratives: Array<Decorative> }

Call As

surface.create_decoratives{ decoratives=decoratives }

Call Convention

Adds the given decoratives to the surface.

This will merge decoratives of the same type that already exist effectively increasing the "amount" field.

Parameters

find_decoratives_filtered

LuaSurface.find_decoratives_filtered{ area?: BoundingBox, position?: TilePosition, name?: DecorativeID | Array<DecorativeID>, collision_mask?: CollisionLayerID | Array<CollisionLayerID> | Dict<CollisionLayerID, true>, from_layer?: string, to_layer?: string, exclude_soft?: boolean, limit?: uint32, invert?: boolean } -> Array<DecorativeResult>

Call As

surface.find_decoratives_filtered{ area=area }

Call Convention

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.

Parameters

Returns

clear_pollution

LuaSurface.clear_pollution()

Call As

surface.clear_pollution()

Call Convention

Clears all pollution on this surface.

play_sound

LuaSurface.play_sound(sound_specification: PlaySoundSpecification)

Call As

surface.play_sound(sound_specification)

Call Convention

Play a sound for every player on this surface.

The sound is not played if its location is not charted for that player.

Parameters

get_resource_counts

LuaSurface.get_resource_counts() -> Dict<string, uint32>

Call As

surface.get_resource_counts()

Call Convention

Gets the resource amount of all resources on this surface

Returns

get_random_chunk

LuaSurface.get_random_chunk() -> ChunkPosition

Call As

surface.get_random_chunk()

Call Convention

Gets a random generated chunk position or 0,0 if no chunks have been generated on this surface.

Returns

clone_area

LuaSurface.clone_area{ source_area: BoundingBox, destination_area: BoundingBox, destination_surface?: SurfaceIdentification, destination_force?: ForceID, clone_tiles?: boolean, clone_entities?: boolean, clone_decoratives?: boolean, clear_destination_entities?: boolean, clear_destination_decoratives?: boolean, expand_map?: boolean, create_build_effect_smoke?: boolean }

Call As

surface.clone_area{ source_area=source_area, destination_area=destination_area }

Call Convention

Clones the given area.

Entities are cloned in an order such that they can always be created, eg rails before trains.

Parameters

clone_brush

LuaSurface.clone_brush{ source_offset: TilePosition, destination_offset: TilePosition, source_positions: Array<TilePosition>, destination_surface?: SurfaceIdentification, destination_force?: LuaForce | string, clone_tiles?: boolean, clone_entities?: boolean, clone_decoratives?: boolean, clear_destination_entities?: boolean, clear_destination_decoratives?: boolean, expand_map?: boolean, manual_collision_mode?: boolean, create_build_effect_smoke?: boolean }

Call As

surface.clone_brush{ source_offset=source_offset, destination_offset=destination_offset, source_positions=source_positions }

Call Convention

Clones the given area.

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.

Parameters

clone_entities

LuaSurface.clone_entities{ entities: Array<LuaEntity>, destination_offset: Vector, destination_surface?: SurfaceIdentification, destination_force?: ForceID, snap_to_grid?: boolean, create_build_effect_smoke?: boolean }

Call As

surface.clone_entities{ entities=entities, destination_offset=destination_offset }

Call Convention

Clones the given entities.

Entities are cloned in an order such that they can always be created, eg rails before trains.

Parameters

clear

LuaSurface.clear(ignore_characters?: boolean)

Call As

surface.clear()

Call Convention

Clears this surface deleting all entities and chunks on it.

Parameters

request_path

LuaSurface.request_path{ bounding_box: BoundingBox, collision_mask: CollisionMask, start: MapPosition, goal: MapPosition, force: ForceID, radius?: double, pathfind_flags?: PathfinderFlags, can_open_gates?: boolean, path_resolution_modifier?: int32, max_gap_size?: int32, max_attack_distance?: double, entity_to_ignore?: LuaEntity } -> uint32

Call As

surface.request_path{ bounding_box=bounding_box, collision_mask=collision_mask, start=start, goal=goal, force=force }

Call Convention

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, such as vehicles. If you want to command actual units (such as biters or spitters) to move, use LuaCommandable::set_command via LuaEntity::commandable instead.

The resulting path is ultimately returned asynchronously via on_script_path_request_finished.

Parameters

Returns

get_script_areas

LuaSurface.get_script_areas(name?: string) -> Array<ScriptArea>

Call As

surface.get_script_areas()

Call Convention

Gets the script areas that match the given name or if no name is given all areas are returned.

Parameters

Returns

get_script_area

LuaSurface.get_script_area(key?: string | uint32) -> ScriptArea?

Call As

surface.get_script_area()

Call Convention

Gets the first script area by name or id.

Parameters

Returns

edit_script_area

LuaSurface.edit_script_area(id: uint32, area: ScriptArea)

Call As

surface.edit_script_area(id, area)

Call Convention

Sets the given script area to the new values.

Parameters

add_script_area

LuaSurface.add_script_area(area: ScriptArea) -> uint32

Call As

surface.add_script_area(area)

Call Convention

Adds the given script area.

Parameters

Returns

remove_script_area

LuaSurface.remove_script_area(id: uint32) -> boolean

Call As

surface.remove_script_area(id)

Call Convention

Removes the given script area.

Parameters

Returns

get_script_positions

LuaSurface.get_script_positions(name?: string) -> Array<ScriptPosition>

Call As

surface.get_script_positions()

Call Convention

Gets the script positions that match the given name or if no name is given all positions are returned.

Parameters

Returns

get_script_position

LuaSurface.get_script_position(key?: string | uint32) -> ScriptPosition?

Call As

surface.get_script_position()

Call Convention

Gets the first script position by name or id.

Parameters

Returns

edit_script_position

LuaSurface.edit_script_position(id: uint32, position: ScriptPosition)

Call As

surface.edit_script_position(id, position)

Call Convention

Sets the given script position to the new values.

Parameters

add_script_position

LuaSurface.add_script_position(position: ScriptPosition) -> uint32

Call As

surface.add_script_position(position)

Call Convention

Adds the given script position.

Parameters

Returns

remove_script_position

LuaSurface.remove_script_position(id: uint32) -> boolean

Call As

surface.remove_script_position(id)

Call Convention

Removes the given script position.

Parameters

Returns

get_map_exchange_string

LuaSurface.get_map_exchange_string() -> string

Call As

surface.get_map_exchange_string()

Call Convention

Gets the map exchange string for the current map generation settings of this surface.

Returns

get_starting_area_radius

LuaSurface.get_starting_area_radius() -> double

Call As

surface.get_starting_area_radius()

Call Convention

Gets the starting area radius of this surface.

Returns

get_closest

LuaSurface.get_closest(position: MapPosition, entities: Array<LuaEntity>) -> LuaEntity?

Call As

surface.get_closest(position, entities)

Call Convention

Gets the closest entity in the list to this position.

Parameters

Returns

get_total_pollution

LuaSurface.get_total_pollution() -> double

Call As

surface.get_total_pollution()

Call Convention

Gets the total amount of pollution on the surface by iterating over all the chunks containing pollution.

Returns

entity_prototype_collides

LuaSurface.entity_prototype_collides(prototype: EntityID, position: MapPosition, use_map_generation_bounding_box: boolean, direction?: defines.direction) -> boolean

Call As

surface.entity_prototype_collides(prototype, position, true)

Call Convention

Whether the given entity prototype collides at the given position and direction.

Parameters

Returns

decorative_prototype_collides

LuaSurface.decorative_prototype_collides(prototype: DecorativeID, position: MapPosition) -> boolean

Call As

surface.decorative_prototype_collides(prototype, position)

Call Convention

Whether the given decorative prototype collides at the given position and direction.

Parameters

Returns

calculate_tile_properties

LuaSurface.calculate_tile_properties(property_names: Array<string>, positions: Array<MapPosition>) -> Dict<string, Array<double>>

Call As

surface.calculate_tile_properties(property_names, positions)

Call Convention

Calculate values for a list of tile properties at a list of positions. Requests for unrecognized properties will be ignored, so this can also be used to test whether those properties exist.

Parameters

Returns

get_entities_with_force

LuaSurface.get_entities_with_force(chunk_position: ChunkPosition, force: ForceID) -> Array<LuaEntity>

Call As

surface.get_entities_with_force(chunk_position, force)

Call Convention

Returns all the military targets (entities with force) on this chunk for the given force.

Parameters

Returns

create_entities_from_blueprint_string

LuaSurface.create_entities_from_blueprint_string{ string: string, position: MapPosition, force?: ForceID, direction?: defines.direction, flip_horizontal?: boolean, flip_vertical?: boolean, by_player?: PlayerIdentification } -> int32?

Call As

surface.create_entities_from_blueprint_string{ string=string, position=position }

Call Convention

This method only works when used in simulations.

Places entities via the given blueprint string. These entities are force-built.

Parameters

Returns

build_checkerboard

LuaSurface.build_checkerboard(area: BoundingBox)

Call As

surface.build_checkerboard(area)

Call Convention

Sets the given area to the checkerboard lab tiles.

Parameters

get_property

LuaSurface.get_property(property: SurfacePropertyID) -> double

Call As

surface.get_property(property)

Call Convention

Gets the value of surface property on this surface.

Parameters

Returns

set_property

LuaSurface.set_property(property: SurfacePropertyID, value: double)

Call As

surface.set_property(property, value)

Call Convention

Sets the value of surface property on this surface.

Parameters

create_global_electric_network

LuaSurface.create_global_electric_network()

Call As

surface.create_global_electric_network()

Call Convention

Creates a global electric network for this surface, if one doesn't exist already.

destroy_global_electric_network

LuaSurface.destroy_global_electric_network()

Call As

surface.destroy_global_electric_network()

Call Convention

Destroys the global electric network for this surface, if it exists.

execute_lightning

LuaSurface.execute_lightning{ name: EntityID, position: MapPosition }

Call As

surface.execute_lightning{ name="name", position=position }

Call Convention

Creates lightning. If other entities which can be lightning targets are nearby, the final position will be adjusted.

Parameters

clear_hidden_tiles

LuaSurface.clear_hidden_tiles()

Call As

surface.clear_hidden_tiles()

Call Convention

Completely removes hidden and double hidden tiles data on this surface.

get_default_cover_tile

LuaSurface.get_default_cover_tile(force: ForceID, tile: TileID) -> LuaTilePrototype?

Call As

surface.get_default_cover_tile(force, tile)

Call Convention

Gets the cover tile for the given force and tile on this surface if one is set.

Parameters

Returns

set_default_cover_tile

LuaSurface.set_default_cover_tile(force: ForceID, from_tile: TileID, to_tile: TileID | nil)

Call As

surface.set_default_cover_tile(force, from_tile, to_tile)

Call Convention

Sets the cover tile for the given force and tile on this surface.

Parameters