Automatically select team with least players
This commit is contained in:
parent
05bf6401e0
commit
f3a5a18400
@ -326,6 +326,28 @@ impl Game {
|
||||
character: None,
|
||||
});
|
||||
self.run_deferred(move |s| s.signals().on_new_player().emit(id));
|
||||
|
||||
let team_with_least = self
|
||||
.get_teams()
|
||||
.iter_shared()
|
||||
.enumerate()
|
||||
.min_by(|(team_idx_a, _), (team_idx_b, _)| {
|
||||
let a = self
|
||||
.players
|
||||
.iter()
|
||||
.filter(|p| p.data.team == *team_idx_a as u8)
|
||||
.count();
|
||||
let b = self
|
||||
.players
|
||||
.iter()
|
||||
.filter(|p| p.data.team == *team_idx_b as u8)
|
||||
.count();
|
||||
a.cmp(&b)
|
||||
})
|
||||
.map(|(team_idx, _)| team_idx)
|
||||
.unwrap_or(0);
|
||||
|
||||
self.try_set_player_team(id, team_with_least as u8, true);
|
||||
id
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user