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
impl Workforce
Sourcepub fn register(&mut self, entity: usize, profession: usize)
pub fn register(&mut self, entity: usize, profession: usize)
Register entity under profession once.
Original: FUN_14008ea70.
Sourcepub fn unregister(&mut self, entity: usize, profession: usize)
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.
Sourcepub fn set_workplace(
&mut self,
workers: &mut [Worker],
c: usize,
wp: Option<usize>,
)
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.
Sourcepub fn move_worker(&mut self, c: usize, old: Option<usize>, new: Option<usize>)
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.
Sourcepub fn free_workplace(
&mut self,
profession: usize,
rng: &mut Random,
) -> Option<usize>
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.
Sourcepub 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>
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.
Sourcepub fn fire(
&mut self,
workers: &mut [Worker],
laborer: usize,
profession: usize,
) -> Option<usize>
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.
Sourcepub fn counts(&self, workers: &[Worker], professions: usize) -> Vec<i32>
pub fn counts(&self, workers: &[Worker], professions: usize) -> Vec<i32>
Adults per profession.
Original: FUN_14007ba70 (counts).
Sourcepub fn capacity(&self, profession: usize) -> i32
pub fn capacity(&self, profession: usize) -> i32
The most workers of every enabled workplace of a profession.
Original: FUN_14007ba70 (“of N”).
Sourcepub 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,
)
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.
Sourcepub fn set_max_workers(
&mut self,
workers: &mut [Worker],
entity: usize,
max: i32,
search: &mut dyn Search,
)
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.
Sourcepub fn set_enabled(
&mut self,
workers: &mut [Worker],
entity: usize,
enabled: bool,
building: bool,
search: &mut dyn Search,
)
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.
Sourcepub fn find_workplace(
&self,
c: usize,
p: usize,
search: &mut dyn Search,
) -> Option<usize>
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.
Sourcepub fn should_move(
&self,
c: usize,
p: usize,
current: Option<usize>,
search: &mut dyn Search,
) -> bool
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.
Sourcepub fn clear_workers(&mut self, workers: &mut [Worker], entity: usize)
pub fn clear_workers(&mut self, workers: &mut [Worker], entity: usize)
Every worker leaves.
Original: FUN_140134330.
Sourcepub fn apply(
&mut self,
command: Command,
workers: &mut [Worker],
professions: &Professions,
homes: &BTreeMap<usize, Home>,
map: &mut dyn StorageSearchMap,
search: &mut dyn Search,
)
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.