Skip to main content

nil_core/world/cheat/
city.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4use crate::bail_if_cheats_are_not_allowed;
5use crate::city::City;
6use crate::city::stability::Stability;
7use crate::continent::coord::Coord;
8use crate::continent::field::Field;
9use crate::error::{Error, Result};
10use crate::ruler::Ruler;
11use crate::world::World;
12
13impl World {
14  pub fn cheat_set_stability(&mut self, coord: Coord, stability: Stability) -> Result<()> {
15    bail_if_cheats_are_not_allowed!(self);
16    let city = self.city_mut(coord)?;
17    *city.stability_mut() = stability;
18    self.emit_city(coord)?;
19    Ok(())
20  }
21
22  pub fn cheat_spawn_city(&mut self, ruler: Ruler, coord: Coord) -> Result<()> {
23    bail_if_cheats_are_not_allowed!(self);
24    let city = City::builder(coord)
25      .name(<Ruler as AsRef<str>>::as_ref(&ruler))
26      .owner(ruler.clone())
27      .build();
28
29    let field = self.continent.field_mut(coord)?;
30    if field.is_empty() {
31      *field = Field::City { city: Box::new(city) };
32      self.emit_public_city(coord)?;
33
34      if let Some(player) = ruler.player() {
35        self.emit_player(player.clone())?;
36      }
37    } else {
38      return Err(Error::FieldNotEmpty(coord));
39    }
40
41    Ok(())
42  }
43}