Skip to main content

nil_core/infrastructure/
catalog.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4#[doc(hidden)]
5#[macro_export]
6macro_rules! decl_recruit_catalog_entry {
7  ($building:ident) => {
8    paste::paste! {
9      #[derive(Clone, Debug, Deserialize, Serialize)]
10      #[serde(tag = "kind", rename_all = "kebab-case")]
11      pub enum [<$building RecruitCatalogEntry>] {
12        /// Unit is available for recruitment.
13        Available { recipe: Box<[<$building RecruitCatalogRecipe>]> },
14        /// City does not meet the requirements for recruitment.
15        Unmet {
16          requirements: InfrastructureRequirements,
17        },
18      }
19
20      impl [<$building RecruitCatalogEntry>] {
21        fn new(unit: &dyn Unit, infrastructure: &Infrastructure) -> Self {
22          let infra_req = unit.infrastructure_requirements();
23          if !infra_req.has_required_levels(infrastructure) {
24            return Self::Unmet { requirements: infra_req.clone() };
25          }
26
27          let chunk = unit.chunk();
28          let recipe = Box::new([<$building RecruitCatalogRecipe>] {
29            resources: chunk.resources(),
30            maintenance: chunk.maintenance(),
31            workforce: chunk.workforce(),
32            requirements: infra_req.clone(),
33          });
34
35          Self::Available { recipe }
36        }
37      }
38
39      #[derive(Clone, Debug, Deserialize, Serialize)]
40      #[serde(rename_all = "camelCase")]
41      pub struct [<$building RecruitCatalogRecipe>] {
42        resources: Resources,
43        maintenance: Maintenance,
44        workforce: Workforce,
45        requirements: InfrastructureRequirements,
46      }
47    }
48  };
49}