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::level::BuildingLevel;
6use bon::Builder;
7use serde::{Deserialize, Serialize};
8
9#[derive(Builder, Debug, Deserialize, Serialize)]
10#[derive_const(Clone, Default, PartialEq, Eq)]
11#[serde(rename_all = "camelCase")]
12#[builder(const)]
13#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
14pub struct InfrastructureRequirements {
15  #[builder(default = BuildingLevel::ZERO)]
16  pub(super) academy: BuildingLevel,
17
18  #[builder(default = BuildingLevel::ZERO)]
19  pub(super) farm: BuildingLevel,
20
21  #[builder(default = BuildingLevel::ZERO)]
22  pub(super) iron_mine: BuildingLevel,
23
24  #[builder(default = BuildingLevel::ZERO)]
25  pub(super) prefecture: BuildingLevel,
26
27  #[builder(default = BuildingLevel::ZERO)]
28  pub(super) quarry: BuildingLevel,
29
30  #[builder(default = BuildingLevel::ZERO)]
31  pub(super) sawmill: BuildingLevel,
32
33  #[builder(default = BuildingLevel::ZERO)]
34  pub(super) silo: BuildingLevel,
35
36  #[builder(default = BuildingLevel::ZERO)]
37  pub(super) stable: BuildingLevel,
38
39  #[builder(default = BuildingLevel::ZERO)]
40  pub(super) wall: BuildingLevel,
41
42  #[builder(default = BuildingLevel::ZERO)]
43  pub(super) warehouse: BuildingLevel,
44
45  #[builder(default = BuildingLevel::ZERO)]
46  pub(super) workshop: BuildingLevel,
47}
48
49impl InfrastructureRequirements {
50  pub const fn none() -> Self {
51    Self::builder().build()
52  }
53
54  /// Determines whether the city infrastructure meets the requirements.
55  #[inline]
56  pub fn has_required_levels(&self, infrastructure: &Infrastructure) -> bool {
57    infrastructure.has_required_levels(self)
58  }
59}