Skip to main content

nil_core/city/
stability.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4use derive_more::{Deref, Into};
5use serde::{Deserialize, Serialize};
6
7/// Political stability of the city.
8#[derive(Clone, Copy, Debug, Deref, Into, Deserialize, Serialize)]
9pub struct Stability(f64);
10
11impl Stability {
12  pub const MIN: Stability = Stability(0.0);
13  pub const MAX: Stability = Stability(1.0);
14
15  #[inline]
16  pub const fn new(value: f64) -> Self {
17    Self(value.clamp(Self::MIN.0, Self::MAX.0))
18  }
19}
20
21impl Default for Stability {
22  fn default() -> Self {
23    Self::MAX
24  }
25}