Skip to main content

Workforce

Struct Workforce 

Source
pub struct Workforce {
    pub workplaces: BTreeMap<usize, WorkPlace>,
    pub registry: BTreeMap<usize, Vec<usize>>,
    pub residences: Vec<usize>,
    pub demolishing: BTreeSet<usize>,
}
Expand description

The town manager’s workplace and residence registries and every WorkPlaceComponent.

Fields§

§workplaces: BTreeMap<usize, WorkPlace>

Entity → WorkPlaceComponent.

§registry: BTreeMap<usize, Vec<usize>>

Profession → workplace entities, in registration order.

Original: FUN_14008ea70.

§residences: Vec<usize>

The residences, in the order they were built.

§demolishing: BTreeSet<usize>

Workplaces being torn down (their state machine in 3 to 5), kept by the sites’ update: the last worker leaving one shows no WorkersUnavailable.

Original: FUN_140123be0.

Implementations§

Source§

impl Workforce

Source

pub fn register(&mut self, entity: usize, profession: usize)

Register entity under profession once.

Original: FUN_14008ea70.

Source

pub fn unregister(&mut self, entity: usize, profession: usize)

Remove a workplace from a profession’s list (every occurrence), keeping the order.

Original: FUN_140002cc0.

Source

pub fn set_workplace( &mut self, workers: &mut [Worker], c: usize, wp: Option<usize>, )

Move citizen c to workplace wp (removing it from its old one, then appending to the new one).

Original: FUN_140134cb0, FUN_140134ef0, FUN_1401173b0.

Source

pub fn move_worker(&mut self, c: usize, old: Option<usize>, new: Option<usize>)

The workplaces’ side of Workforce::set_workplace: c leaves old and joins new (not while it is being torn down). When the last worker leaves, the limit and work icons go, and an enabled workplace of its own profession shows WorkersUnavailable; joining removes that icon. The entity events 2 and 3 (work sounds and smoke) are only for presentation; the app drives them from the workers.

Original: FUN_140123be0; leaving FUN_140134cb0, joining FUN_140134ef0.

Source

pub fn free_workplace( &mut self, profession: usize, rng: &mut Random, ) -> Option<usize>

Shuffle, then the first enabled workplace with a free place.

Original: FUN_1400925d0.

Source

pub fn hire( &mut self, workers: &mut [Worker], laborer: usize, profession: usize, wp: Option<usize>, homes: &BTreeMap<usize, Home>, map: &mut dyn StorageSearchMap, rng: &mut Random, ) -> Option<usize>

Make one laborer take profession at wp. It looks, in this order, for: a laborer who shares a home with someone of that profession, the laborer with a home nearest the workplace, the household with the most laborers, then the first laborer.

Original: FUN_1400918a0 (and the loop body of FUN_14007b890); the searches FUN_1400920c0, FUN_140091ef0, FUN_140091ac0, FUN_140091980.

Source

pub fn fire( &mut self, workers: &mut [Worker], laborer: usize, profession: usize, ) -> Option<usize>

One citizen of profession becomes a laborer: the first without a workplace, else the first worker of the workplace with the most workers, else the first of that profession.

Original: FUN_140096650.

Source

pub fn counts(&self, workers: &[Worker], professions: usize) -> Vec<i32>

Adults per profession.

Original: FUN_14007ba70 (counts).

Source

pub fn capacity(&self, profession: usize) -> i32

The most workers of every enabled workplace of a profession.

Original: FUN_14007ba70 (“of N”).

Source

pub fn set_count( &mut self, workers: &mut [Worker], professions: &Professions, profession: usize, count: i32, homes: &BTreeMap<usize, Home>, map: &mut dyn StorageSearchMap, rng: &mut Random, )

Move the profession’s count toward count, one citizen at a time.

Original: FUN_14007b890.

Source

pub fn set_max_workers( &mut self, workers: &mut [Worker], entity: usize, max: i32, search: &mut dyn Search, )

Set the most workers, then the first workers move to another workplace (Workforce::find_workplace, or none) until they fit.

Original: FUN_140134fd0.

Source

pub fn set_enabled( &mut self, workers: &mut [Worker], entity: usize, enabled: bool, building: bool, search: &mut dyn Search, )

Accept workers or not; a disabled workplace’s workers move to another (Workforce::find_workplace, or none). Switched off it shows BuildPaused while being building (states 0, 1, 8), else WorkDisabled, and neither on; switched off it drops the limit, work and workers icons, on without workers of its own profession it shows WorkersUnavailable.

Original: FUN_1401350d0.

Source

pub fn find_workplace( &self, c: usize, p: usize, search: &mut dyn Search, ) -> Option<usize>

A workplace of citizen c’s profession, enabled, with room and reachable: for a profession that works anywhere, the one whose work comes first (by work priority), else the one with the most room, the first of equals.

Original: FUN_140115940, FUN_140115490, FUN_140115450; the priority sort is FUN_140115800.

Source

pub fn should_move( &self, c: usize, p: usize, current: Option<usize>, search: &mut dyn Search, ) -> bool

Should citizen c look again? A profession that works anywhere when its workplace cannot be reached or another with room has work that comes first; the others when the reachable workplaces’ room differs by more than one.

Original: FUN_140115eb0.

Source

pub fn clear_workers(&mut self, workers: &mut [Worker], entity: usize)

Every worker leaves.

Original: FUN_140134330.

Source

pub fn apply( &mut self, command: Command, workers: &mut [Worker], professions: &Professions, homes: &BTreeMap<usize, Home>, map: &mut dyn StorageSearchMap, search: &mut dyn Search, )

Apply a UI command.

Trait Implementations§

Source§

impl Clone for Workforce

Source§

fn clone(&self) -> Workforce

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 Workforce

Source§

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

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

impl Default for Workforce

Source§

fn default() -> Workforce

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

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.