spring_ai_rs/ai_interface/callback/unit_def/
combat.rs1use std::error::Error;
2
3use serde::{Deserialize, Serialize};
4
5use crate::get_callback;
6
7#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
8pub struct UnitCombat {
9 pub ai_id: i32,
10 pub def_id: i32,
11}
12
13#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
14pub struct UnitCombatAll {
15 pub strafe_to_attack: bool,
16 pub max_weapon_range: f32,
17 pub armoured_multiple: f32,
18 pub armour_type: i32,
19 pub able_to_attack: bool,
20 pub able_to_patrol: bool,
21 pub able_to_fight: bool,
22 pub able_to_guard: bool,
23 pub able_to_fire_control: bool,
24 pub fire_state: i32,
25 pub hover_attack: bool,
26 pub air_strafe: bool,
27 pub targeting_facility: bool,
28 pub manual_fire: bool,
29 pub able_to_kamikaze: bool,
30 pub kamikaze_dist: f32,
31}
32
33impl UnitCombat {
34 pub fn strafe_to_attack(&self) -> Result<bool, Box<dyn Error>> {
35 let get_is_strafe_to_attack_func = get_callback!(self.ai_id, UnitDef_isStrafeToAttack)?;
36 Ok(unsafe { get_is_strafe_to_attack_func(self.ai_id, self.def_id) })
37 }
38
39 pub fn max_weapon_range(&self) -> Result<f32, Box<dyn Error>> {
40 let get_max_weapon_range_func = get_callback!(self.ai_id, UnitDef_getMaxWeaponRange)?;
41 Ok(unsafe { get_max_weapon_range_func(self.ai_id, self.def_id) })
42 }
43
44 pub fn armoured_multiple(&self) -> Result<f32, Box<dyn Error>> {
45 let get_armored_multiple_func = get_callback!(self.ai_id, UnitDef_getArmoredMultiple)?;
46 Ok(unsafe { get_armored_multiple_func(self.ai_id, self.def_id) })
47 }
48
49 pub fn armour_type(&self) -> Result<i32, Box<dyn Error>> {
50 let get_armor_type_func = get_callback!(self.ai_id, UnitDef_getArmorType)?;
51 Ok(unsafe { get_armor_type_func(self.ai_id, self.def_id) })
52 }
53
54 pub fn able_to_attack(&self) -> Result<bool, Box<dyn Error>> {
55 let able_to_attack_func = get_callback!(self.ai_id, UnitDef_isAbleToAttack)?;
56 Ok(unsafe { able_to_attack_func(self.ai_id, self.def_id) })
57 }
58
59 pub fn able_to_patrol(&self) -> Result<bool, Box<dyn Error>> {
60 let able_to_patrol_func = get_callback!(self.ai_id, UnitDef_isAbleToPatrol)?;
61 Ok(unsafe { able_to_patrol_func(self.ai_id, self.def_id) })
62 }
63
64 pub fn able_to_fight(&self) -> Result<bool, Box<dyn Error>> {
65 let able_to_fight_func = get_callback!(self.ai_id, UnitDef_isAbleToFight)?;
66 Ok(unsafe { able_to_fight_func(self.ai_id, self.def_id) })
67 }
68
69 pub fn able_to_guard(&self) -> Result<bool, Box<dyn Error>> {
70 let able_to_guard_func = get_callback!(self.ai_id, UnitDef_isAbleToGuard)?;
71 Ok(unsafe { able_to_guard_func(self.ai_id, self.def_id) })
72 }
73
74 pub fn able_to_fire_control(&self) -> Result<bool, Box<dyn Error>> {
75 let able_to_fire_control_func = get_callback!(self.ai_id, UnitDef_isAbleToFireControl)?;
76 Ok(unsafe { able_to_fire_control_func(self.ai_id, self.def_id) })
77 }
78
79 pub fn fire_state(&self) -> Result<i32, Box<dyn Error>> {
80 let get_fire_state_func = get_callback!(self.ai_id, UnitDef_getFireState)?;
81 Ok(unsafe { get_fire_state_func(self.ai_id, self.def_id) })
82 }
83
84 pub fn hover_attack(&self) -> Result<bool, Box<dyn Error>> {
85 let get_is_able_to_self_d_func = get_callback!(self.ai_id, UnitDef_isHoverAttack)?;
86 Ok(unsafe { get_is_able_to_self_d_func(self.ai_id, self.def_id) })
87 }
88
89 pub fn air_strafe(&self) -> Result<bool, Box<dyn Error>> {
90 let get_air_strafe_func = get_callback!(self.ai_id, UnitDef_isAirStrafe)?;
91 Ok(unsafe { get_air_strafe_func(self.ai_id, self.def_id) })
92 }
93
94 pub fn targeting_facility(&self) -> Result<bool, Box<dyn Error>> {
95 let get_is_targeting_facility_func =
96 get_callback!(self.ai_id, UnitDef_isTargetingFacility)?;
97 Ok(unsafe { get_is_targeting_facility_func(self.ai_id, self.def_id) })
98 }
99
100 pub fn manual_fire(&self) -> Result<bool, Box<dyn Error>> {
101 let get_is_manual_fire_func = get_callback!(self.ai_id, UnitDef_canManualFire)?;
102 Ok(unsafe { get_is_manual_fire_func(self.ai_id, self.def_id) })
103 }
104
105 pub fn able_to_kamikaze(&self) -> Result<bool, Box<dyn Error>> {
106 let get_is_able_to_kamikaze_func = get_callback!(self.ai_id, UnitDef_isAbleToKamikaze)?;
107 Ok(unsafe { get_is_able_to_kamikaze_func(self.ai_id, self.def_id) })
108 }
109
110 pub fn kamikaze_distance(&self) -> Result<f32, Box<dyn Error>> {
111 let get_kamikaze_dist_func = get_callback!(self.ai_id, UnitDef_getKamikazeDist)?;
112 Ok(unsafe { get_kamikaze_dist_func(self.ai_id, self.def_id) })
113 }
114
115 pub fn all(&self) -> Result<UnitCombatAll, Box<dyn Error>> {
116 Ok(UnitCombatAll {
117 strafe_to_attack: self.strafe_to_attack()?,
118 max_weapon_range: self.max_weapon_range()?,
119 armoured_multiple: self.armoured_multiple()?,
120 armour_type: self.armour_type()?,
121 able_to_attack: self.able_to_attack()?,
122 able_to_patrol: self.able_to_patrol()?,
123 able_to_fight: self.able_to_fight()?,
124 able_to_guard: self.able_to_guard()?,
125 able_to_fire_control: self.able_to_fire_control()?,
126 fire_state: self.fire_state()?,
127 hover_attack: self.hover_attack()?,
128 air_strafe: self.air_strafe()?,
129 targeting_facility: self.targeting_facility()?,
130 manual_fire: self.manual_fire()?,
131 able_to_kamikaze: self.able_to_kamikaze()?,
132 kamikaze_dist: self.kamikaze_distance()?,
133 })
134 }
135}