spring_ai_rs/ai_interface/callback/game_mod/
mod.rs

1use std::error::Error;
2
3use crate::{
4    ai_interface::{
5        callback::game_mod::{
6            combat::{GameModCombat, GameModCombatAll},
7            construction_decay::{GameModConstructionDecay, GameModConstructionDecayAll},
8            info::{GameModInfo, GameModInfoAll},
9            mip::{GameModMipLevel, GameModMipLevelAll},
10            reclaim::{GameModReclaim, GameModReclaimAll},
11            transport::{GameModTransport, GameModTransportAll},
12        },
13        AIInterface,
14    },
15    get_callback,
16};
17
18pub mod combat;
19pub mod construction_decay;
20pub mod info;
21pub mod mip;
22pub mod reclaim;
23pub mod transport;
24
25#[derive(Debug, Copy, Clone)]
26pub struct GameMod {
27    pub ai_id: i32,
28}
29
30#[derive(Debug, Clone)]
31pub struct GameModAll {
32    info: GameModInfoAll,
33    // allow_team_colors: bool,
34    construction_decay: GameModConstructionDecayAll,
35    reclaim: GameModReclaimAll,
36    capture_energy_cost_factor: f32,
37    transport: GameModTransportAll,
38    combat: GameModCombatAll,
39    mip_level: GameModMipLevelAll,
40    require_sonar_underwater: bool,
41}
42
43const MAX_TEAM: usize = 32;
44
45impl AIInterface {
46    pub fn game_mod(&self) -> GameMod {
47        GameMod { ai_id: self.ai_id }
48    }
49}
50
51impl GameMod {
52    pub fn info(&self) -> GameModInfo {
53        GameModInfo { ai_id: self.ai_id }
54    }
55
56    // TODO: Was removed by BAR
57    // pub fn allow_team_colors(&self) -> Result<bool, Box<dyn Error>> {
58    //     let get_allow_team_colors = get_callback!(self.ai_id, Mod_getAllowTeamColors)?;
59    //
60    //     Ok(unsafe { get_allow_team_colors(self.ai_id) })
61    // }
62
63    pub fn construction_decay(&self) -> GameModConstructionDecay {
64        GameModConstructionDecay { ai_id: self.ai_id }
65    }
66
67    pub fn reclaim(&self) -> GameModReclaim {
68        GameModReclaim { ai_id: self.ai_id }
69    }
70
71    pub fn capture_energy_cost_factor(&self) -> Result<f32, Box<dyn Error>> {
72        let get_capture_energy_cost_factor =
73            get_callback!(self.ai_id, Mod_getCaptureEnergyCostFactor)?;
74
75        Ok(unsafe { get_capture_energy_cost_factor(self.ai_id) })
76    }
77
78    pub fn transport(&self) -> GameModTransport {
79        GameModTransport { ai_id: self.ai_id }
80    }
81
82    pub fn combat(&self) -> GameModCombat {
83        GameModCombat { ai_id: self.ai_id }
84    }
85
86    pub fn mip_level(&self) -> GameModMipLevel {
87        GameModMipLevel { ai_id: self.ai_id }
88    }
89
90    pub fn require_sonar_underwater(&self) -> Result<bool, Box<dyn Error>> {
91        let get_require_sonar_underwater =
92            get_callback!(self.ai_id, Mod_getRequireSonarUnderWater)?;
93
94        Ok(unsafe { get_require_sonar_underwater(self.ai_id) })
95    }
96
97    pub fn all(&self) -> Result<GameModAll, Box<dyn Error>> {
98        Ok(GameModAll {
99            info: self.info().all()?,
100            // allow_team_colors: self.allow_team_colors()?,
101            construction_decay: self.construction_decay().all()?,
102            reclaim: self.reclaim().all()?,
103            capture_energy_cost_factor: self.capture_energy_cost_factor()?,
104            transport: self.transport().all()?,
105            combat: self.combat().all()?,
106            mip_level: self.mip_level().all()?,
107            require_sonar_underwater: self.require_sonar_underwater()?,
108        })
109    }
110}