spring_ai_rs/ai_interface/callback/game_mod/
combat.rs

1use std::error::Error;
2
3use crate::{ai_interface::callback::unit_def::flanking::FlankingMode, get_callback};
4
5#[derive(Debug, Copy, Clone)]
6pub struct GameModCombat {
7    pub ai_id: i32,
8}
9
10#[derive(Debug, Copy, Clone)]
11pub struct GameModCombatAll {
12    fire_at_killed: bool,
13    fire_at_crashing: bool,
14    flanking_bonus_mode_default: FlankingMode,
15}
16
17impl GameModCombat {
18    pub fn fire_at_killed(&self) -> Result<bool, Box<dyn Error>> {
19        let get_fire_at_killed = get_callback!(self.ai_id, Mod_getFireAtKilled)?;
20
21        Ok(unsafe { get_fire_at_killed(self.ai_id) } == 1)
22    }
23
24    pub fn fire_at_crashing(&self) -> Result<bool, Box<dyn Error>> {
25        let get_fire_at_crashing = get_callback!(self.ai_id, Mod_getFireAtCrashing)?;
26
27        Ok(unsafe { get_fire_at_crashing(self.ai_id) } == 1)
28    }
29
30    pub fn flanking_bonus_mode_default(&self) -> Result<FlankingMode, Box<dyn Error>> {
31        let get_fire_at_crashing = get_callback!(self.ai_id, Mod_getFireAtCrashing)?;
32
33        Ok(FlankingMode::from(unsafe {
34            get_fire_at_crashing(self.ai_id)
35        }))
36    }
37
38    pub fn all(&self) -> Result<GameModCombatAll, Box<dyn Error>> {
39        Ok(GameModCombatAll {
40            fire_at_killed: self.fire_at_killed()?,
41            fire_at_crashing: self.fire_at_crashing()?,
42            flanking_bonus_mode_default: self.flanking_bonus_mode_default()?,
43        })
44    }
45}