spring_ai_rs/ai_interface/callback/unit_def/
auto_heal.rs1use std::error::Error;
2
3use serde::{Deserialize, Serialize};
4
5use crate::get_callback;
6
7#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
8pub struct UnitAutoHeal {
9 pub ai_id: i32,
10 pub def_id: i32,
11}
12
13#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
14pub struct UnitAutoHealAll {
15 pub normal: f32,
16 pub idle: f32,
17}
18
19impl UnitAutoHeal {
20 pub fn normal(&self) -> Result<f32, Box<dyn Error>> {
21 let get_auto_heal_func = get_callback!(self.ai_id, UnitDef_getAutoHeal)?;
22 Ok(unsafe { get_auto_heal_func(self.ai_id, self.def_id) })
23 }
24
25 pub fn idle(&self) -> Result<f32, Box<dyn Error>> {
26 let get_get_idle_auto_heal_func = get_callback!(self.ai_id, UnitDef_getIdleAutoHeal)?;
27 Ok(unsafe { get_get_idle_auto_heal_func(self.ai_id, self.def_id) })
28 }
29
30 pub fn all(&self) -> Result<UnitAutoHealAll, Box<dyn Error>> {
31 Ok(UnitAutoHealAll {
32 normal: self.normal()?,
33 idle: self.idle()?,
34 })
35 }
36}