Skip to main content

nil_core/world/
stats.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4use crate::infrastructure::stats::InfrastructureStats;
5use crate::market::MarketPriceTable;
6use crate::resources::influence::InfluenceResourceCost;
7use crate::world::config::WorldConfig;
8use serde::{Deserialize, Serialize};
9use std::sync::Arc;
10
11#[derive(Clone, Debug, Deserialize, Serialize)]
12#[serde(rename_all = "camelCase")]
13#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
14pub struct WorldStats {
15  pub(super) infrastructure: Arc<InfrastructureStats>,
16  market_price_table: MarketPriceTable,
17  influence_resource_cost: InfluenceResourceCost,
18}
19
20impl WorldStats {
21  pub fn new(config: &WorldConfig) -> Self {
22    Self {
23      infrastructure: Arc::new(InfrastructureStats::new(config)),
24      market_price_table: MarketPriceTable::new(),
25      influence_resource_cost: InfluenceResourceCost::new(),
26    }
27  }
28
29  #[inline]
30  pub fn infrastructure(&self) -> Arc<InfrastructureStats> {
31    Arc::clone(&self.infrastructure)
32  }
33
34  #[inline]
35  pub fn market_price_table(&self) -> MarketPriceTable {
36    self.market_price_table
37  }
38
39  #[inline]
40  pub fn influence_resource_cost(&self) -> InfluenceResourceCost {
41    self.influence_resource_cost
42  }
43}