Skip to main content

nil_core/world/infrastructure/
mod.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4mod building;
5mod storage;
6
7use crate::city::City;
8use crate::continent::{ContinentKey, Coord};
9use crate::error::Result;
10use crate::infrastructure::Infrastructure;
11use crate::infrastructure::building::BuildingId;
12use crate::world::World;
13
14impl World {
15  #[inline]
16  pub fn infrastructure(&self, key: impl ContinentKey) -> Result<&Infrastructure> {
17    self.city(key).map(City::infrastructure)
18  }
19
20  pub fn toggle_building(&mut self, coord: Coord, id: BuildingId, enabled: bool) -> Result<()> {
21    self
22      .continent
23      .city_mut(coord)?
24      .infrastructure_mut()
25      .building_mut(id)
26      .toggle(enabled);
27
28    self.emit_city_updated(coord);
29
30    Ok(())
31  }
32}