LuaForce

class LuaForce
get_entity_count(name) → uint Count entities of given type.
disable_research() Disable research for this force.
enable_research() Enable research for this force.
disable_all_prototypes() Disable all recipes and technologies.
reset_recipes() Load the original version of all recipes from the prototypes.
enable_all_recipes() Unlock all recipes.
enable_all_technologies() Unlock all technologies.
research_all_technologies() Research all technologies.
reset_technologies() Load the original versions of technologies from prototypes.
reset() Reset everything.
chart(surface, area) Chart a portion of the map.
clear_chart() Remove all charted area from the chart.
rechart() Force a rechart of the whole chart.
chart_all() Chart all generated chunks.
is_chunk_charted(surface, position) → boolean Has a chunk been charted?
get_ammo_damage_modifier(ammo) → double
set_ammo_damage_modifier(ammo, modifier)
get_gun_speed_modifier(ammo) → double
set_gun_speed_modifier(ammo, modifier)
get_turret_attack_modifier(turret) → double
set_turret_attack_modifier(turret, modifier)
set_cease_fire(other, cease_fire) Stop attacking members of a given force.
get_cease_fire(other) → boolean Will this force attack members of another force?
is_pathfinder_busy() → boolean Is pathfinder busy?
kill_all_units() Kill all units and flush the pathfinder.
find_logistic_network_by_position(position, surface) → LuaLogisticNetwork
set_kill_count(entity, count)
get_kill_count(entity) → uint How many entities of a given type were killed by this force.
set_spawn_position(position, surface)
get_spawn_position(surface) → Position
valid :: boolean [R] Is this object valid?
name :: string [R] Name of the force.
technologies :: dictionary stringLuaTechnology [R] Technologies owned by this force, indexed by their name.
recipes :: dictionary stringLuaRecipe [R] Recipes available to this force, indexed by their name.
manual_mining_speed_modifier :: double [RW] Multiplier of the manual mining speed.
manual_crafting_speed_modifier :: double [RW] Multiplier of the manual crafting speed.
laboratory_speed_modifier :: double [RW]
logistic_robot_speed_modifier :: double [RW]
logistic_robot_storage_modifier :: double [RW]
current_research :: LuaTechnology or string [RW] The current research in progress.
research_progress :: double [RW] Progress of current research, as a number in range [0, 1].
inserter_stack_size_bonus :: uint [RW] Number of extra items that can be transferred (so 1 + inserter_stack_size_bonus is transfer stack size)
character_logistic_slot_count :: double [RW] Number of character logistic slots.
character_trash_slot_count :: double [RW] Number of character trash slots.
quickbar_count :: uint [RW] Number of character quick bars.
maximum_following_robot_count :: uint [RW] Maximum number of follower robots.
ghost_time_to_live :: uint [RW] The time, in ticks, before a placed ghost disappears.
players :: array of LuaPlayer [R] Players belonging to this force.
ai_controllable :: boolean [RW] Enables some higher-level AI behaviour for this force.
logistic_networks :: dictionary stringarray of LuaLogisticNetwork [R] List of logistic networks, grouped by surface.
kill_counts :: dictionary stringuint [R] For each entity, the number of kills of that entity achieved by this force.

LuaForce encapsulates data local to each "force" or "faction" of the game. Default forces are player, enemy and neutral. Players and mods can create additional forces (up to 64 total).

get_entity_count(name) → uint

Count entities of given type.

Parameters
name :: string: Prototype name of the entity.
Return value
Number of entities of given prototype belonging to this force.
Note: This function has O(1) time complexity as entity counts are kept and maintained in the game engine.
disable_research()

Disable research for this force.

enable_research()

Enable research for this force.

disable_all_prototypes()

Disable all recipes and technologies. Only recipes and technologies enabled explicitly will be useable from this point.

reset_recipes()

Load the original version of all recipes from the prototypes.

enable_all_recipes()

Unlock all recipes.

enable_all_technologies()

Unlock all technologies.

research_all_technologies()

Research all technologies.

reset_technologies()

Load the original versions of technologies from prototypes. Preserves research state of technologies.

reset()

Reset everything. All technologies are set to not researched, all modifiers are set to default values.

chart(surface, area)

Chart a portion of the map. The chart for the given area is refreshed; it creates chart for any parts of the given area that haven't been charted yet.

Parameters
area :: BoundingBox: The area on the given surface to chart.
Example
Charts a 2048x2048 rectangle centered around the origin.
game.local_player.force.chart(game.local_player.surface,
                              {{x = -1024, y = -1024}, {x = 1024, y = 1024}})
clear_chart()

Remove all charted area from the chart.

rechart()

Force a rechart of the whole chart.

chart_all()

Chart all generated chunks.

is_chunk_charted(surface, position) → boolean

Has a chunk been charted?

Parameters
position :: Position: Chunk position. Note that this is in chunk coordinates: I.e. {0, 0} and {1, 0} are one whole chunk away from each other.
get_ammo_damage_modifier(ammo) → double

Parameters
ammo :: string: Ammo category
set_ammo_damage_modifier(ammo, modifier)

Parameters
ammo :: string: Ammo category
modifier :: double
get_gun_speed_modifier(ammo) → double

Parameters
ammo :: string: Ammo category
set_gun_speed_modifier(ammo, modifier)

Parameters
ammo :: string: Ammo category
modifier :: double
get_turret_attack_modifier(turret) → double

Parameters
turret :: string: Turret prototype name
set_turret_attack_modifier(turret, modifier)

Parameters
turret :: string: Turret prototype name
modifier :: double
set_cease_fire(other, cease_fire)

Stop attacking members of a given force.

Parameters
other :: string or LuaForce
cease_fire :: boolean: When true, this force won't attack other; otherwise it will.
get_cease_fire(other) → boolean

Will this force attack members of another force?

Parameters
other :: string: Name of the other force
is_pathfinder_busy() → boolean

Is pathfinder busy? When the pathfinder is busy, it won't accept any more pathfinding requests.

kill_all_units()

Kill all units and flush the pathfinder.

find_logistic_network_by_position(position, surface) → LuaLogisticNetwork

Parameters
position :: Position: Position to find a network for
surface :: SurfaceSpecification: Surface to search on
Return value
The found network or nil.
set_kill_count(entity, count)

Parameters
entity :: string: Entity prototype name to set kill stat for
count :: int: The number of kills to claim this force has claimed
get_kill_count(entity) → uint

How many entities of a given type were killed by this force.

Parameters
entity :: string: Prototype name of requested entity
set_spawn_position(position, surface)

Parameters
position :: Position: The new position on the given surface.
surface :: SurfaceSpecification: Surface to set the spawn position for.
get_spawn_position(surface) → Position

Parameters
valid :: boolean [Read-only]

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.

name :: string [Read-only]

Name of the force.

Example
Prints "player"
game.local_player.print(game.local_player.force.name)
technologies :: dictionary stringLuaTechnology [Read-only]

Technologies owned by this force, indexed by their name.

Example
Researches the technology for the player's force
game.local_player.force.technologies["iron-working"].researched = true
recipes :: dictionary stringLuaRecipe [Read-only]

Recipes available to this force, indexed by their name.

Example
Prints the category of the given recipe
game.local_player.print(game.local_player.force.recipes["basic-transport-belt"].category)
manual_mining_speed_modifier :: double [Read-Write]

Multiplier of the manual mining speed. Default value is 0. The actual mining speed will be multiplied by 1 + manual_mining_speed_modifier.

Example
Double the player's mining speed
game.local_player.force.manual_mining_speed_modifier = 1
manual_crafting_speed_modifier :: double [Read-Write]

Multiplier of the manual crafting speed. Default value is 0. The actual crafting speed will be multiplied by 1 + manual_crafting_speed_modifier.

Example
Double the player's crafting speed
game.local_player.force.manual_crafting_speed_modifier = 1
laboratory_speed_modifier :: double [Read-Write]

logistic_robot_speed_modifier :: double [Read-Write]

logistic_robot_storage_modifier :: double [Read-Write]

current_research :: LuaTechnology or string [Read-Write]

The current research in progress. Reading this attribute gives a LuaTechnology of the current technology in research, or nil if no research is currently ongoing. Writing this attribute expects a string specifying a technology name; writing will start a research of the specified technology.

research_progress :: double [Read-Write]

Progress of current research, as a number in range [0, 1].

inserter_stack_size_bonus :: uint [Read-Write]

Number of extra items that can be transferred (so 1 + inserter_stack_size_bonus is transfer stack size)

character_logistic_slot_count :: double [Read-Write]

Number of character logistic slots.

character_trash_slot_count :: double [Read-Write]

Number of character trash slots.

quickbar_count :: uint [Read-Write]

Number of character quick bars.

maximum_following_robot_count :: uint [Read-Write]

Maximum number of follower robots.

ghost_time_to_live :: uint [Read-Write]

The time, in ticks, before a placed ghost disappears.

players :: array of LuaPlayer [Read-only]

Players belonging to this force.

ai_controllable :: boolean [Read-Write]

Enables some higher-level AI behaviour for this force. When set to true, biters belonging to this force will automatically expand into new territories, build new spawners, and form unit groups. By default, this value is true for the enemy force and false for all others.

Note: Setting this to false does not turn off biters' AI. They will still move around and attack players who come close.
Note: It is necessary for a force to be AI controllable in order to be able to create unit groups or build bases from scripts.
logistic_networks :: dictionary stringarray of LuaLogisticNetwork [Read-only]

List of logistic networks, grouped by surface.

kill_counts :: dictionary stringuint [Read-only]

For each entity, the number of kills of that entity achieved by this force. This dictionary only includes entities that have been killed at least once (i.e. entities that haven't been killed by this force aren't included in this dictionary).