spring_ai_rs/ai_interface/callback/game_mod/
reclaim.rs

1use std::error::Error;
2
3use crate::get_callback;
4
5#[derive(Debug, Copy, Clone)]
6pub struct GameModReclaim {
7    pub ai_id: i32,
8}
9
10#[derive(Debug, Copy, Clone)]
11pub struct GameModReclaimAll {
12    multi_reclaim: i32,
13    method: ReclaimMethod,
14    unit_method: ReclaimUnitMethod,
15    unit_energy_cost_factor: f32,
16    efficiency: f32,
17    feature_energy_cost_factor: f32,
18    allow_enemies: bool,
19    allow_allies: bool,
20}
21
22#[derive(Debug, Copy, Clone)]
23pub enum ReclaimMethod {
24    Gradual,
25    AtEnd,
26    Chunk(i32),
27}
28
29#[derive(Debug, Copy, Clone)]
30pub enum ReclaimUnitMethod {
31    WireframeGradualReclaim,
32    SubtractHPMetalAtEnd,
33}
34
35impl GameModReclaim {
36    pub fn multi_reclaim(&self) -> Result<i32, Box<dyn Error>> {
37        let get_multi_reclaim = get_callback!(self.ai_id, Mod_getMultiReclaim)?;
38
39        Ok(unsafe { get_multi_reclaim(self.ai_id) })
40    }
41
42    pub fn method(&self) -> Result<ReclaimMethod, Box<dyn Error>> {
43        let get_reclaim_method = get_callback!(self.ai_id, Mod_getReclaimMethod)?;
44
45        let reclaim_method = unsafe { get_reclaim_method(self.ai_id) };
46
47        Ok(match reclaim_method {
48            0 => ReclaimMethod::Gradual,
49            1 => ReclaimMethod::AtEnd,
50            c => ReclaimMethod::Chunk(c),
51        })
52    }
53
54    pub fn unit_method(&self) -> Result<ReclaimUnitMethod, Box<dyn Error>> {
55        let get_reclaim_unit_method = get_callback!(self.ai_id, Mod_getReclaimUnitMethod)?;
56
57        let reclaim_unit_method = unsafe { get_reclaim_unit_method(self.ai_id) };
58
59        Ok(match reclaim_unit_method {
60            0 => ReclaimUnitMethod::WireframeGradualReclaim,
61            _ => ReclaimUnitMethod::SubtractHPMetalAtEnd,
62        })
63    }
64
65    pub fn unit_energy_cost_factor(&self) -> Result<f32, Box<dyn Error>> {
66        let get_reclaim_energy_cost_factor =
67            get_callback!(self.ai_id, Mod_getReclaimUnitEnergyCostFactor)?;
68
69        Ok(unsafe { get_reclaim_energy_cost_factor(self.ai_id) })
70    }
71
72    pub fn efficiency(&self) -> Result<f32, Box<dyn Error>> {
73        let get_reclaim_energy_cost_factor =
74            get_callback!(self.ai_id, Mod_getReclaimUnitEfficiency)?;
75
76        Ok(unsafe { get_reclaim_energy_cost_factor(self.ai_id) })
77    }
78
79    pub fn feature_energy_cost_factor(&self) -> Result<f32, Box<dyn Error>> {
80        let get_reclaim_feature_energy_cost_factor =
81            get_callback!(self.ai_id, Mod_getReclaimFeatureEnergyCostFactor)?;
82
83        Ok(unsafe { get_reclaim_feature_energy_cost_factor(self.ai_id) })
84    }
85
86    pub fn allow_enemies(&self) -> Result<bool, Box<dyn Error>> {
87        let get_reclaim_allow_enemies = get_callback!(self.ai_id, Mod_getReclaimAllowEnemies)?;
88
89        Ok(unsafe { get_reclaim_allow_enemies(self.ai_id) })
90    }
91
92    pub fn allow_allies(&self) -> Result<bool, Box<dyn Error>> {
93        let get_reclaim_allow_allies = get_callback!(self.ai_id, Mod_getReclaimAllowAllies)?;
94
95        Ok(unsafe { get_reclaim_allow_allies(self.ai_id) })
96    }
97
98    pub fn all(&self) -> Result<GameModReclaimAll, Box<dyn Error>> {
99        Ok(GameModReclaimAll {
100            multi_reclaim: self.multi_reclaim()?,
101            method: self.method()?,
102            unit_method: self.unit_method()?,
103            unit_energy_cost_factor: self.unit_energy_cost_factor()?,
104            efficiency: self.efficiency()?,
105            feature_energy_cost_factor: self.feature_energy_cost_factor()?,
106            allow_enemies: self.allow_enemies()?,
107            allow_allies: self.allow_allies()?,
108        })
109    }
110}