Skip to main content

nil_core/infrastructure/
requirements.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4use super::Infrastructure;
5use super::building::BuildingLevel;
6use bon::Builder;
7use serde::{Deserialize, Serialize};
8
9#[derive(Builder, Clone, Debug, Default, Deserialize, Serialize)]
10#[serde(rename_all = "camelCase")]
11#[builder(const)]
12pub struct InfrastructureRequirements {
13  #[builder(default = BuildingLevel::ZERO)]
14  pub(super) academy: BuildingLevel,
15
16  #[builder(default = BuildingLevel::ZERO)]
17  pub(super) farm: BuildingLevel,
18
19  #[builder(default = BuildingLevel::ZERO)]
20  pub(super) iron_mine: BuildingLevel,
21
22  #[builder(default = BuildingLevel::ZERO)]
23  pub(super) prefecture: BuildingLevel,
24
25  #[builder(default = BuildingLevel::ZERO)]
26  pub(super) quarry: BuildingLevel,
27
28  #[builder(default = BuildingLevel::ZERO)]
29  pub(super) sawmill: BuildingLevel,
30
31  #[builder(default = BuildingLevel::ZERO)]
32  pub(super) silo: BuildingLevel,
33
34  #[builder(default = BuildingLevel::ZERO)]
35  pub(super) stable: BuildingLevel,
36
37  #[builder(default = BuildingLevel::ZERO)]
38  pub(super) wall: BuildingLevel,
39
40  #[builder(default = BuildingLevel::ZERO)]
41  pub(super) warehouse: BuildingLevel,
42
43  #[builder(default = BuildingLevel::ZERO)]
44  pub(super) workshop: BuildingLevel,
45}
46
47impl InfrastructureRequirements {
48  pub const fn none() -> Self {
49    Self::builder().build()
50  }
51
52  /// Determines whether the city infrastructure meets the requirements.
53  #[inline]
54  pub fn has_required_levels(&self, infrastructure: &Infrastructure) -> bool {
55    infrastructure.has_required_levels(self)
56  }
57}