Skip to main content

GroupFormation

Struct GroupFormation 

Source
pub struct GroupFormation { /* private fields */ }
Expand description

A single formation definition specifying how units should be arranged.

Each formation includes AI usage criteria, unit requirements, and a set of formation blocks that define where different unit types should be positioned.

Implementations§

Source§

impl GroupFormation

Source

pub fn add_container( &mut self, parent_id: Option<u32>, position: (f32, f32), format: GroupFormationsFormat, ) -> Result<u32>

Adds a container with the defaults used by vanilla files at the end of the formation.

§Arguments
  • parent_id - Block to position the container relative to, or None for an absolute container.
  • position - Offset from the parent for relative containers, or position for absolute ones.
  • format - Format of the file, to create a valid entity preference.
§Returns

The id of the new block.

§Errors

Returns an error if the parent doesn’t exist.

Source

pub fn add_span(&mut self, member_ids: &[u32]) -> Result<u32>

Adds a span over the provided blocks at the end of the formation.

§Arguments
  • member_ids - Blocks covered by the span.
§Returns

The id of the new block.

§Errors

Returns an error if any of the members doesn’t exist.

Source

pub fn set_span_members( &mut self, span_id: u32, member_ids: &[u32], ) -> Result<()>

Replaces the members of a span.

§Arguments
  • span_id - The span to edit.
  • member_ids - New blocks covered by the span.
§Errors

Returns an error if a block doesn’t exist, the edited block isn’t a span, or a member depends on the span.

Source

pub fn reparent( &mut self, block_id: u32, parent_id: Option<u32>, params: &LayoutParams, ) -> Result<()>

Changes the parent of a container, keeping its simulated position when possible.

§Arguments
  • block_id - The container to edit.
  • parent_id - The new parent, or None to turn it into an absolute container.
  • params - The simulated deployment used to keep the container in place.
§Errors

Returns an error if a block doesn’t exist, the edited block is a span, or the new parent depends on the edited block.

Source

pub fn move_block( &mut self, block_id: u32, center: (f32, f32), grid_step: f32, params: &LayoutParams, ) -> Result<()>

Moves a container so its simulated center lands on the target, snapping its offset or position to a grid.

§Arguments
  • block_id - The container to move.
  • center - Target position of the container’s center.
  • grid_step - Size of the grid to snap to, or 0 to not snap.
  • params - The simulated deployment used to compute the offset.
§Errors

Returns an error if the block doesn’t exist, is a span, or it or its parent can’t be positioned.

Source

pub fn move_blocks( &mut self, block_ids: &[u32], delta: (f32, f32), grid_step: f32, params: &LayoutParams, ) -> Result<()>

Moves several blocks by the same distance, snapping their offsets or positions to a grid.

Spans are moved by moving their members. Blocks that depend on another moved block already move with it, so they’re left untouched.

§Arguments
  • block_ids - The blocks to move.
  • delta - Distance to move them.
  • grid_step - Size of the grid to snap to, or 0 to not snap.
  • params - The simulated deployment used to compute the offsets.
§Errors

Returns an error if a block doesn’t exist, or a moved block or its parent can’t be positioned.

Source

pub fn delete_blocks( &mut self, block_ids: &[u32], params: &LayoutParams, ) -> Result<()>

Deletes blocks, re-attaching the containers positioned relative to them to their closest surviving ancestor.

Spans left without members are deleted too. Containers left without ancestors become absolute.

§Arguments
  • block_ids - The blocks to delete.
  • params - The simulated deployment used to keep re-attached containers in place.
§Errors

Returns an error if any of the blocks doesn’t exist.

Source

pub fn delete_subtree( &mut self, block_id: u32, params: &LayoutParams, ) -> Result<()>

Deletes a block, all the containers positioned relative to it, recursively, and the spans left without members.

§Arguments
  • block_id - The root of the subtree to delete.
  • params - The simulated deployment used to keep re-attached containers in place.
§Errors

Returns an error if the block doesn’t exist.

Source

pub fn sort_blocks(&mut self)

Reorders the blocks so each one comes after the blocks it depends on.

Blocks keep their current order when possible, and blocks in reference cycles are moved to the end.

Source

pub fn depends_on(&self, block_id: u32, target_id: u32) -> bool

Returns if a block is the target, or depends on it directly or through other blocks.

§Arguments
  • block_id - The block to check.
  • target_id - The block that may be depended on.
§Returns

true if making the target depend on the block would create a reference cycle.

Source§

impl GroupFormation

Source

pub fn layout(&self, params: &LayoutParams) -> HashMap<u32, LayoutRect>

Computes the simulated position and size of every block of the formation.

§Arguments
  • params - The simulated deployment to use.
§Returns

The rect of each block, by block id. Blocks that can’t be placed due to missing references, reference cycles or empty spans are left out.

Source§

impl GroupFormation

Source

pub fn validate(&self) -> Vec<ValidationIssue>

Checks the blocks of this formation for consistency problems.

§Returns

A list of the issues found, in block order.

Source§

impl GroupFormation

Source

pub fn name(&self) -> &String

Name identifier for this formation.

Source

pub fn ai_priority(&self) -> &f32

AI priority value for selecting this formation (higher = more preferred).

Source

pub fn ai_purpose(&self) -> &AIPurpose

Bitflags indicating when this formation should be used (attack, defend, naval, etc.).

Source

pub fn uk_2(&self) -> &u32

Unknown field, present in Troy and later.

Source

pub fn min_unit_category_percentage(&self) -> &Vec<MinUnitCategoryPercentage>

Minimum percentage requirements for unit categories in this formation.

Source

pub fn ai_supported_subcultures(&self) -> &Vec<String>

List of supported subcultures (introduced in Rome 2).

If non-empty, this formation is only available to armies from these subcultures.

Source

pub fn ai_supported_factions(&self) -> &Vec<String>

List of supported factions (introduced in Rome 2).

If non-empty, this formation is only available to armies from these factions.

Source

pub fn group_formation_blocks(&self) -> &Vec<GroupFormationBlock>

Formation blocks defining unit positions and arrangements.

Source§

impl GroupFormation

Source

pub fn name_mut(&mut self) -> &mut String

Name identifier for this formation.

Source

pub fn ai_priority_mut(&mut self) -> &mut f32

AI priority value for selecting this formation (higher = more preferred).

Source

pub fn ai_purpose_mut(&mut self) -> &mut AIPurpose

Bitflags indicating when this formation should be used (attack, defend, naval, etc.).

Source

pub fn uk_2_mut(&mut self) -> &mut u32

Unknown field, present in Troy and later.

Source

pub fn min_unit_category_percentage_mut( &mut self, ) -> &mut Vec<MinUnitCategoryPercentage>

Minimum percentage requirements for unit categories in this formation.

Source

pub fn ai_supported_subcultures_mut(&mut self) -> &mut Vec<String>

List of supported subcultures (introduced in Rome 2).

If non-empty, this formation is only available to armies from these subcultures.

Source

pub fn ai_supported_factions_mut(&mut self) -> &mut Vec<String>

List of supported factions (introduced in Rome 2).

If non-empty, this formation is only available to armies from these factions.

Source

pub fn group_formation_blocks_mut(&mut self) -> &mut Vec<GroupFormationBlock>

Formation blocks defining unit positions and arrangements.

Source§

impl GroupFormation

Source

pub fn set_name(&mut self, val: String) -> &mut Self

Name identifier for this formation.

Source

pub fn set_ai_priority(&mut self, val: f32) -> &mut Self

AI priority value for selecting this formation (higher = more preferred).

Source

pub fn set_ai_purpose(&mut self, val: AIPurpose) -> &mut Self

Bitflags indicating when this formation should be used (attack, defend, naval, etc.).

Source

pub fn set_uk_2(&mut self, val: u32) -> &mut Self

Unknown field, present in Troy and later.

Source

pub fn set_min_unit_category_percentage( &mut self, val: Vec<MinUnitCategoryPercentage>, ) -> &mut Self

Minimum percentage requirements for unit categories in this formation.

Source

pub fn set_ai_supported_subcultures(&mut self, val: Vec<String>) -> &mut Self

List of supported subcultures (introduced in Rome 2).

If non-empty, this formation is only available to armies from these subcultures.

Source

pub fn set_ai_supported_factions(&mut self, val: Vec<String>) -> &mut Self

List of supported factions (introduced in Rome 2).

If non-empty, this formation is only available to armies from these factions.

Source

pub fn set_group_formation_blocks( &mut self, val: Vec<GroupFormationBlock>, ) -> &mut Self

Formation blocks defining unit positions and arrangements.

Source§

impl GroupFormation

Source

pub fn new(name: &str, format: GroupFormationsFormat) -> Self

Creates an empty formation valid for the provided format.

§Arguments
  • name - Name of the new formation.
  • format - Format of the file the formation will belong to.
§Returns

A formation with no blocks and the AI purpose version expected by the format.

Trait Implementations§

Source§

impl Clone for GroupFormation

Source§

fn clone(&self) -> GroupFormation

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 Debug for GroupFormation

Source§

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

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

impl Default for GroupFormation

Source§

fn default() -> GroupFormation

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

impl<'de> Deserialize<'de> for GroupFormation

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for GroupFormation

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for GroupFormation

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for GroupFormation

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.