Skip to main content

LuaForce

Struct LuaForce 

Source
pub struct LuaForce;
Expand description

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

Implementations§

Source§

impl LuaForce

Source

pub fn ai_controllable(&self) -> bool

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.

Setting this to false does not turn off biters’ AI. They will still move around and attack players who come close.

It is necessary for a force to be AI controllable in order to be able to create unit groups or build bases from scripts.

Source

pub fn artillery_range_modifier(&self) -> f64

Source

pub fn beacon_distribution_modifier(&self) -> f64

Source

pub fn belt_stack_size_bonus(&self) -> u32

Belt stack size bonus.

Source

pub fn bulk_inserter_capacity_bonus(&self) -> u32

Number of items that can be transferred by bulk inserters. When writing to this value, it must be >= 0 and <= 254.

Source

pub fn cargo_landing_pad_limit(&self) -> u32

The maximum cargo landing pads that can be built per surface by this force.

Source

pub fn character_build_distance_bonus(&self) -> u32

Source

pub fn character_health_bonus(&self) -> f64

Source

pub fn character_inventory_slots_bonus(&self) -> u32

The number of additional inventory slots the character main inventory has.

Source

pub fn character_item_drop_distance_bonus(&self) -> u32

Source

pub fn character_item_pickup_distance_bonus(&self) -> f64

Source

pub fn character_logistic_requests(&self) -> bool

true if character requester logistics is enabled.

Source

pub fn character_loot_pickup_distance_bonus(&self) -> f64

Source

pub fn character_reach_distance_bonus(&self) -> u32

Source

pub fn character_resource_reach_distance_bonus(&self) -> f64

Source

pub fn character_running_speed_modifier(&self) -> f64

Modifies the running speed of all characters in this force by the given value as a percentage. Setting the running modifier to 0.5 makes the character run 50% faster. The minimum value of -1 reduces the movement speed by 100%, resulting in a speed of 0.

Source

pub fn character_trash_slot_count(&self) -> f64

Number of character trash slots.

Source

pub fn circuit_network_enabled(&self) -> bool

Source

pub fn cliff_deconstruction_enabled(&self) -> bool

When true, cliffs will be marked for deconstruction when trying to force-build things that collide.

Source

pub fn color(&self) -> Color

Effective color of this force.

Source

pub fn connected_players(&self) -> Vec<LuaPlayer>

The connected players belonging to this force.

This is primarily useful when you want to do some action against all online players of this force.

This does not index using player index. See LuaPlayer::index on each player instance for the player index.

Source

pub fn create_ghost_on_entity_death(&self) -> bool

When an entity dies, a ghost will be placed for automatic reconstruction.

Source

pub fn current_research(&self) -> LuaTechnology

The currently ongoing technology research, if any.

Source

pub fn custom_color(&self) -> Color

Custom color for this force. If specified, will take priority over other sources of the force color. Writing nil clears custom color. Will return nil if it was not specified or if was set to {0,0,0,0}.

Source

pub fn deconstruction_time_to_live(&self) -> u32

The time, in ticks, before a deconstruction order is removed.

Source

pub fn following_robots_lifetime_modifier(&self) -> f64

Additional lifetime for following robots.

Source

pub fn friendly_fire(&self) -> bool

If friendly fire is enabled for this force.

Source

pub fn index(&self) -> u32

This force’s index in LuaGameScript::forces (unique ID). It is assigned when a force is created, and remains so until it is merged (ie. deleted). Indexes of merged forces can be reused.

Source

pub fn inserter_stack_size_bonus(&self) -> f64

The inserter stack size bonus for non stack inserters

Source

pub fn items_launched(&self) -> HashMap<String, u32>

All of the items that have been launched in rockets.

Source

pub fn laboratory_productivity_bonus(&self) -> f64

Source

pub fn laboratory_speed_modifier(&self) -> f64

Source

pub fn logistic_networks(&self) -> HashMap<String, Vec<Box<LuaLogisticNetwork>>>

List of logistic networks, grouped by surface.

Source

pub fn manual_crafting_speed_modifier(&self) -> f64

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

Source

pub fn manual_mining_speed_modifier(&self) -> f64

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

Source

pub fn max_cargo_bay_unloading_distance(&self) -> f64

Maximum distance between cargo bay from its connected cargo landing pad that allows unloading. Only relevant for cargo bays that have both LuaEntityPrototype::allow_unloading and LuaEntityPrototype::use_unloading_distance_limit set to true.

Source

pub fn max_failed_attempts_per_tick_per_construction_queue(&self) -> u32

Source

pub fn max_successful_attempts_per_tick_per_construction_queue(&self) -> u32

Source

pub fn maximum_following_robot_count(&self) -> u32

Maximum number of follower robots.

Source

pub fn mining_drill_productivity_bonus(&self) -> f64

Source

pub fn mining_with_fluid(&self) -> bool

Source

pub fn name(&self) -> &str

Name of the force.

Source

pub fn object_name(&self) -> &str

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.

Source

pub fn platforms(&self) -> LuaAny

The space platforms that belong to this force mapped by their index value.

This will include platforms that are pending deletion.

Source

pub fn players(&self) -> Vec<LuaPlayer>

Players belonging to this force.

Source

pub fn previous_research(&self) -> LuaTechnology

The previous research, if any.

Source

pub fn rail_planner_allow_elevated_rails(&self) -> bool

Source

pub fn rail_support_on_deep_oil_ocean(&self) -> bool

Source

pub fn recipes(&self) -> HashMap<String, Box<LuaRecipe>>

Recipes available to this force, indexed by name.

Source

pub fn research_enabled(&self) -> bool

Whether research is enabled for this force, see LuaForce::enable_research and LuaForce::disable_research.

Source

pub fn research_progress(&self) -> f64

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

Source

pub fn research_queue(&self) -> Vec<LuaAny>

The research queue of this force. The first technology in the array is the currently active one. Reading this attribute gives an array of LuaTechnology.

To write to this, the entire table must be written. Providing an empty table or nil will empty the research queue and cancel the current research. Writing to this when the research queue is disabled will simply set the last research in the table as the current research.

This only allows mods to queue research that this force is able to research in the first place. As an example, an already researched technology or one whose prerequisites are not fulfilled will not be queued, but dropped silently instead.

Source

pub fn rockets_launched(&self) -> u32

The number of rockets launched.

Source

pub fn share_chart(&self) -> bool

If sharing chart data is enabled for this force.

Source

pub fn technologies(&self) -> HashMap<String, Box<LuaTechnology>>

Technologies owned by this force, indexed by name.

Source

pub fn train_braking_force_bonus(&self) -> f64

Source

pub fn unlock_logistic_network(&self) -> bool

When true, a “connect to logistic network” button will become enabled for entities that can connect to a logistic network.

Source

pub fn unlock_travel_to_space_platforms(&self) -> bool

Whether traveling to space platforms via rockets is unlocked.

Source

pub fn valid(&self) -> bool

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.

Source

pub fn vehicle_logistics(&self) -> bool

When true, cars/tanks that support logistics will be able to use them.

Source

pub fn worker_robots_battery_modifier(&self) -> f64

Source

pub fn worker_robots_speed_modifier(&self) -> f64

Source

pub fn worker_robots_storage_bonus(&self) -> f64

Source

pub fn add_alert(&self, entity: LuaEntity, type: &str)

Adds an alert to every connected player on this force.

Source

pub fn add_chart_tag( &self, surface: LuaAny, tag: ChartTagSpec, ) -> Option<LuaCustomChartTag>

Adds a custom chart tag to the given surface and returns the new tag or nil if the given position isn’t valid for a chart tag.

The chunk must be charted for a tag to be valid at that location.

Source

pub fn add_custom_alert( &self, entity: LuaEntity, icon: SignalID, message: &str, show_on_map: bool, )

Adds a custom alert to every connected player on this force.

Source

pub fn add_research(&self, technology: LuaAny) -> bool

Add this technology to the back of the research queue if the queue is enabled. Otherwise, set this technology to be researched now.

Source

pub fn cancel_charting(&self, surface: Option<LuaAny>)

Cancels pending chart requests for the given surface or all surfaces.

Source

pub fn cancel_current_research(&self)

Stop the research currently in progress. This will remove any dependent technologies from the research queue.

Source

pub fn chart(&self, area: BoundingBox, surface: LuaAny)

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.

Source

pub fn chart_all(&self, surface: Option<LuaAny>)

Chart all generated chunks.

Source

pub fn clear_chart(&self, surface: Option<LuaAny>)

Erases chart data for this force.

Source

pub fn copy_chart( &self, destination_surface: LuaAny, source_force: LuaAny, source_surface: LuaAny, )

Copies the given surface’s chart from the given force to this force.

Source

pub fn copy_from(&self, force: LuaAny)

Copies all of the given changeable values (except charts) from the given force to this force.

Source

pub fn create_logistic_group(&self, name: &str, type: Option<&str>)

Creates the given group if it doesn’t already exist.

Source

pub fn create_space_platform( &self, params: LuaForceCreateSpacePlatformParams, ) -> Option<LuaSpacePlatform>

Creates a new space platform on this force.

Source

pub fn delete_logistic_group(&self, name: &str, type: Option<&str>)

Deletes the given logistic group if it exists.

Source

pub fn disable_all_prototypes(&self)

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

Source

pub fn disable_research(&self)

Disable research for this force.

Source

pub fn enable_all_prototypes(&self)

Enables all recipes and technologies. The opposite of LuaForce::disable_all_prototypes.

Source

pub fn enable_all_recipes(&self)

Unlock all recipes.

Source

pub fn enable_all_technologies(&self)

Unlock all technologies.

Source

pub fn enable_research(&self)

Enable research for this force.

Source

pub fn find_chart_tags( &self, area: Option<BoundingBox>, surface: LuaAny, ) -> Vec<LuaCustomChartTag>

Finds all custom chart tags within a given area on the given surface. If no area is given all custom chart tags on the surface are returned.

Source

pub fn find_logistic_network_by_position( &self, position: MapPosition, surface: LuaAny, ) -> Option<LuaLogisticNetwork>

Source

pub fn get_ammo_damage_modifier(&self, ammo: &str) -> f64

Source

pub fn get_cease_fire(&self, other: LuaAny) -> bool

Is other force in this force’s cease fire list?

Source

pub fn get_chunk_chart( &self, chunk_position: ChunkPosition, surface: LuaAny, ) -> Option<&str>

Gets the raw chart data for a given chunk as a binary string.

The pixel data is returned in RGB565 format (2 bytes per pixel).

Returns nil if the chunk has not been charted for this force.

Source

pub fn get_entity_build_count_statistics( &self, surface: LuaAny, ) -> LuaFlowStatistics

The entity build statistics for this force (built and mined) for the given surface.

Source

pub fn get_entity_count(&self, name: LuaAny) -> u32

Count entities of given type.

This function has O(1) time complexity as entity counts are kept and maintained in the game engine.

Source

pub fn get_evolution_factor(&self, surface: Option<LuaAny>) -> f64

Fetches the evolution factor of this force on the given surface.

Source

pub fn get_evolution_factor_by_killing_spawners( &self, surface: Option<LuaAny>, ) -> f64

Fetches the spawner kill part of the evolution factor of this force on the given surface.

Source

pub fn get_evolution_factor_by_pollution(&self, surface: Option<LuaAny>) -> f64

Fetches the pollution part of the evolution factor of this force on the given surface.

Source

pub fn get_evolution_factor_by_time(&self, surface: Option<LuaAny>) -> f64

Fetches the time part of the evolution factor of this force on the given surface.

Source

pub fn get_fluid_production_statistics( &self, surface: LuaAny, ) -> LuaFlowStatistics

The fluid production statistics for this force for the given surface.

Source

pub fn get_friend(&self, other: LuaAny) -> bool

Is other force in this force’s friends list.

Source

pub fn get_gun_speed_modifier(&self, ammo: &str) -> f64

Source

pub fn get_hand_crafting_disabled_for_recipe(&self, recipe: LuaAny) -> bool

Gets if the given recipe is explicitly disabled from being hand crafted.

Source

pub fn get_item_launched(&self, item: LuaAny) -> u32

Gets the count of a given item launched in rockets.

Source

pub fn get_item_production_statistics( &self, surface: LuaAny, ) -> LuaFlowStatistics

The item production statistics for this force for the given surface.

Source

pub fn get_kill_count_statistics(&self, surface: LuaAny) -> LuaFlowStatistics

The kill counter statistics for this force for the given surface.

Source

pub fn get_linked_inventory( &self, link_id: u32, prototype: LuaAny, ) -> Option<LuaInventory>

Gets the linked inventory for the given prototype and link ID if it exists or nil.

Source

pub fn get_logistic_group( &self, name: &str, type: Option<&str>, ) -> Option<LogisticGroup>

Gets the information about the given logistic group.

Source

pub fn get_logistic_groups(&self, type: Option<&str>) -> Vec<&str>

Gets the names of the current logistic groups.

Source

pub fn get_script_visible(&self, unlockable: UnlockableID) -> Option<bool>

Gets the unlockable script state for the given ID.

Source

pub fn get_spawn_position(&self, surface: LuaAny) -> MapPosition

Source

pub fn get_surface_hidden(&self, surface: LuaAny) -> bool

Source

pub fn get_turret_attack_modifier(&self, turret: LuaAny) -> f64

Source

pub fn is_chunk_charted( &self, chunk_position: ChunkPosition, surface: LuaAny, ) -> bool

Has a chunk been charted?

Source

pub fn is_chunk_requested_for_charting( &self, chunk_position: ChunkPosition, surface: LuaAny, ) -> bool

Has a chunk been requested for charting?

Source

pub fn is_chunk_visible( &self, chunk_position: ChunkPosition, surface: LuaAny, ) -> bool

Is the given chunk currently charted and visible (not covered by fog of war) on the map.

Source

pub fn is_enemy(&self, other: LuaAny) -> bool

Is this force an enemy? This differs from get_cease_fire in that it is always false for neutral force. This is equivalent to checking the enemy ForceCondition.

Source

pub fn is_friend(&self, other: LuaAny) -> bool

Is this force a friend? This differs from get_friend in that it is always true for neutral force. This is equivalent to checking the friend ForceCondition.

Source

pub fn is_pathfinder_busy(&self) -> bool

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

Source

pub fn is_quality_unlocked(&self, quality: LuaAny)

Is the specified quality unlocked for this force?

Source

pub fn is_space_location_unlocked(&self, name: LuaAny)

Is the specified planet unlocked for this force?

Source

pub fn is_space_platforms_unlocked(&self) -> bool

Are the space platforms unlocked? This basically just controls the availability of the space platforms button.

Source

pub fn is_visible(&self, unlockable: UnlockableID) -> bool

Is the given unlockable ID visible either through computed technologies or script set state.

Source

pub fn kill_all_units(&self)

Kill all units and flush the pathfinder.

Source

pub fn lock_quality(&self, quality: LuaAny)

Locks the quality to not be accessible to this force.

Source

pub fn lock_space_location(&self, name: LuaAny)

Locks the planet to not be accessible to this force.

Source

pub fn lock_space_platforms(&self)

Locks the space platforms, which disables the space platforms button

Source

pub fn play_music(&self, music_specification: PlayMusicSpecification)

Play a music track for every player in this force.

Source

pub fn play_sound(&self, sound_specification: PlaySoundSpecification)

Play a sound for every player in this force.

The sound is not played if its location is not charted for this force.

Source

pub fn print(&self, message: &str, print_settings: Option<PrintSettings>)

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

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

Source

pub fn rechart(&self, surface: Option<LuaAny>)

Force a rechart of the whole chart.

Source

pub fn remove_alert(&self, filter: AlertFilter)

For every connected player on this force - removes all alerts matching the given filters or if an empty filters table is given all alerts are removed.

Source

pub fn research_all_technologies( &self, include_disabled_prototypes: Option<bool>, )

Research all technologies.

Source

pub fn reset(&self)

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

Source

pub fn reset_evolution(&self)

Resets evolution for this force to zero.

Source

pub fn reset_recipes(&self)

Load the original version of all recipes from the prototypes.

Source

pub fn reset_technologies(&self)

Load the original versions of technologies from prototypes. Preserves research, enabled and visible_when_disabled state of technologies.

Source

pub fn reset_technology_effects(&self)

Reapplies all possible research effects, including unlocked recipes. Any custom changes are lost. Preserves research state of technologies.

Source

pub fn script_trigger_research(&self, technology: LuaAny)

Trigger the “scripted” research trigger of a technology, researching it. Does nothing if the technology does not have a “scripted” research trigger.

Source

pub fn set_ammo_damage_modifier(&self, ammo: &str, modifier: f64)

Source

pub fn set_cease_fire(&self, cease_fire: bool, other: LuaAny)

Add other force to this force’s cease fire list. Forces on the cease fire list won’t be targeted for attack.

Source

pub fn set_evolution_factor(&self, factor: f64, surface: Option<LuaAny>)

Sets the evolution factor of this force on the given surface.

Source

pub fn set_evolution_factor_by_killing_spawners( &self, factor: f64, surface: Option<LuaAny>, )

Sets the spawner kill part of the evolution factor of this force on the given surface.

Source

pub fn set_evolution_factor_by_pollution( &self, factor: f64, surface: Option<LuaAny>, )

Sets the pollution part of the evolution factor of this force on the given surface.

Source

pub fn set_evolution_factor_by_time(&self, factor: f64, surface: Option<LuaAny>)

Sets the time part of the evolution factor of this force on the given surface.

Source

pub fn set_friend(&self, friend: bool, other: LuaAny)

Add other force to this force’s friends list. Friends have unrestricted access to buildings and turrets won’t fire at them.

Source

pub fn set_gun_speed_modifier(&self, ammo: &str, modifier: f64)

Source

pub fn set_hand_crafting_disabled_for_recipe( &self, hand_crafting_disabled: bool, recipe: LuaAny, )

Sets if the given recipe can be hand-crafted. This is used to explicitly disable hand crafting a recipe - it won’t allow hand-crafting otherwise not hand-craftable recipes.

Source

pub fn set_item_launched(&self, count: u32, item: LuaAny)

Sets the count of a given item launched in rockets.

Source

pub fn set_script_visible(&self, unlockable: UnlockableID, value: Option<bool>)

Sets the given unlockable ID state. When set to explicitly hidden or visible the value overrides the state computed through technologies.

Source

pub fn set_spawn_position(&self, position: MapPosition, surface: LuaAny)

Source

pub fn set_surface_hidden(&self, hidden: bool, surface: LuaAny)

Source

pub fn set_turret_attack_modifier(&self, modifier: f64, turret: LuaAny)

Source

pub fn unchart_chunk(&self, chunk_position: ChunkPosition, surface: LuaAny)

Source

pub fn unlock_quality(&self, quality: LuaAny)

Unlocks the quality to be accessible to this force.

Source

pub fn unlock_space_location(&self, name: LuaAny)

Unlocks the planet to be accessible to this force.

Source

pub fn unlock_space_platforms(&self)

Unlocks the space platforms, which enables the space platforms button

Trait Implementations§

Source§

impl Clone for LuaForce

Source§

fn clone(&self) -> LuaForce

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LuaForce

Source§

impl Debug for LuaForce

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LuaForce

Source§

fn default() -> LuaForce

Returns the “default value” for a type. Read more
Source§

impl Eq for LuaForce

Source§

impl From<LuaForce> for LuaAny

Source§

fn from(_: LuaForce) -> Self

Converts to this type from the input type.
Source§

impl LuaObject for LuaForce

Source§

impl PartialEq for LuaForce

Source§

fn eq(&self, other: &LuaForce) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LuaForce

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.