aboutsummaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/entity/ctf_minigame.rs36
1 files changed, 16 insertions, 20 deletions
diff --git a/server/src/entity/ctf_minigame.rs b/server/src/entity/ctf_minigame.rs
index 18473fa5..842081dc 100644
--- a/server/src/entity/ctf_minigame.rs
+++ b/server/src/entity/ctf_minigame.rs
@@ -58,17 +58,6 @@ impl TeamData {
}
Ok(())
}
- fn return_players(&mut self, c: &mut EntityContext) -> Result<(), TrError> {
- for pid in self.players.iter() {
- c.game
- .players
- .get_mut(&pid)
- .ok_or(TrError::Plain("Player is missing".to_string()))?
- .movement
- .position = self.spawn.as_vec2();
- }
- Ok(())
- }
}
impl CtfMinigame {
@@ -124,18 +113,18 @@ impl CtfMinigame {
}
for (item, team) in self.teams.iter_mut() {
team.clear_hands(c)?;
- team.return_players(c)?;
c.game.set_item(team.spawn, Some(*item));
}
Ok(())
}
- fn get_team_mut(&mut self, pid: PlayerID) -> Result<(&ItemIndex, &mut TeamData), TrError> {
- Ok(self
+ fn get_team(&mut self, pid: PlayerID) -> Result<ItemIndex, TrError> {
+ Ok(*self
.teams
.iter_mut()
.find(|(_, d)| d.players.get(&pid).is_some())
- .ok_or(TrError::Plain("Player is not in any team".to_string()))?)
+ .ok_or(TrError::Plain("Player is not in any team".to_string()))?
+ .0)
}
fn return_flag(&mut self, c: &mut EntityContext, team_idx: ItemIndex) -> Result<(), TrError> {
@@ -194,6 +183,8 @@ impl CtfMinigame {
for (_, (_, team)) in ti.clone() {
if let Some(p) = team.get(i).and_then(|&i| c.game.players.get(i)) {
write!(o, "{:<20}|", p.name).unwrap();
+ } else {
+ write!(o, "{:<20}|", "").unwrap();
}
}
writeln!(o, "").unwrap();
@@ -205,6 +196,7 @@ impl CtfMinigame {
Ok(())
}
}
+
impl Entity for CtfMinigame {
fn tick(&mut self, mut c: EntityContext) -> Result<(), TrError> {
if !self.ready {
@@ -235,7 +227,7 @@ impl Entity for CtfMinigame {
.find(|(_, d)| d.spawn == pos)
.map(|a| *a.0)
{
- let (&from_team_idx, from_team) = self.get_team_mut(from)?;
+ let from_team_idx = self.get_team(from)?;
if to_team_idx != from_team_idx {
Ok(false)
@@ -255,7 +247,7 @@ impl Entity for CtfMinigame {
.and_then(|a| a.item.as_ref().map(|a| a.kind))
.is_some_and(|a| a == from_team_idx)
{
- from_team.score += 10;
+ self.teams.get_mut(&from_team_idx).unwrap().score += 10;
self.send_table(&mut c)?;
self.new_round(&mut c)?;
}
@@ -266,8 +258,8 @@ impl Entity for CtfMinigame {
}
}
ItemLocation::Player(to, _) => {
- let (&from_team_idx, _) = self.get_team_mut(from)?;
- let (&to_team_idx, to_team) = self.get_team_mut(to)?;
+ let from_team_idx = self.get_team(from)?;
+ let to_team_idx = self.get_team(to)?;
if from_team_idx != to_team_idx {
if c.game
.players
@@ -279,8 +271,12 @@ impl Entity for CtfMinigame {
.find(|i| i.kind == from_team_idx)
.is_some()
{
- to_team.clear_hands(&mut c)?;
+ self.teams
+ .get_mut(&to_team_idx)
+ .unwrap()
+ .clear_hands(&mut c)?;
self.return_flag(&mut c, from_team_idx)?;
+ self.teams.get_mut(&from_team_idx).unwrap().score += 3;
}
self.return_player(&mut c, to)?;
Ok(true)