1use crate::city::City;
5use crate::continent::index::ContinentKey;
6use crate::error::Result;
7use crate::ranking::score::Score;
8use crate::ruler::Ruler;
9use crate::world::World;
10
11impl World {
12 #[inline]
13 pub fn city(&self, key: impl ContinentKey) -> Result<&City> {
14 self.continent.city(key)
15 }
16
17 pub(crate) fn city_mut(&mut self, key: impl ContinentKey) -> Result<&mut City> {
18 self.continent.city_mut(key)
19 }
20
21 pub fn count_cities<R>(&self, owner: R) -> u32
22 where
23 R: Into<Ruler>,
24 {
25 self
26 .continent
27 .cities_of(owner)
28 .count()
29 .try_into()
30 .unwrap_or(u32::MAX)
31 }
32
33 pub fn get_city_score(&self, key: impl ContinentKey) -> Result<Score> {
34 let stats = self.stats.infrastructure.as_ref();
35 self.continent.city(key)?.score(stats)
36 }
37
38 pub fn rename_city(&mut self, key: impl ContinentKey, name: &str) -> Result<()> {
39 let coord = key.into_coord(self.continent.size())?;
40 let city = self.continent.city_mut(coord)?;
41 name.clone_into(city.name_mut());
42
43 self.emit_public_city(coord)?;
44
45 Ok(())
46 }
47}