spring_ai_rs/ai_interface/callback/unit_def/
cloak.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::error::Error;

use serde::{Deserialize, Serialize};

use crate::get_callback;

#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub struct UnitCloak {
    pub ai_id: i32,
    pub def_id: i32,
}

#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub struct UnitCloakAll {
    pub able_to_cloak: bool,
    pub start_cloaked: bool,
    pub cloak_cost: f32,
    pub cloak_cost_moving: f32,
    pub decloak_distance: f32,
    pub decloak_spherical: bool,
    pub decloak_on_fire: bool,
}

impl UnitCloak {
    pub fn able_to_cloak(&self) -> Result<bool, Box<dyn Error>> {
        let get_able_to_cloak_func = get_callback!(self.ai_id, UnitDef_isAbleToCloak)?;
        Ok(unsafe { get_able_to_cloak_func(self.ai_id, self.def_id) })
    }

    pub fn start_cloaked(&self) -> Result<bool, Box<dyn Error>> {
        let get_start_cloaked_func = get_callback!(self.ai_id, UnitDef_isStartCloaked)?;
        Ok(unsafe { get_start_cloaked_func(self.ai_id, self.def_id) })
    }

    pub fn cloak_cost(&self) -> Result<f32, Box<dyn Error>> {
        let get_cloak_cost_func = get_callback!(self.ai_id, UnitDef_getCloakCost)?;
        Ok(unsafe { get_cloak_cost_func(self.ai_id, self.def_id) })
    }

    pub fn cloak_cost_moving(&self) -> Result<f32, Box<dyn Error>> {
        let get_cloak_cost_moving_func = get_callback!(self.ai_id, UnitDef_getCloakCostMoving)?;
        Ok(unsafe { get_cloak_cost_moving_func(self.ai_id, self.def_id) })
    }

    pub fn decloak_distance(&self) -> Result<f32, Box<dyn Error>> {
        let get_decloak_distance_func = get_callback!(self.ai_id, UnitDef_getDecloakDistance)?;
        Ok(unsafe { get_decloak_distance_func(self.ai_id, self.def_id) })
    }

    pub fn decloak_spherical(&self) -> Result<bool, Box<dyn Error>> {
        let get_is_decloak_spherical_func = get_callback!(self.ai_id, UnitDef_isDecloakSpherical)?;
        Ok(unsafe { get_is_decloak_spherical_func(self.ai_id, self.def_id) })
    }

    pub fn decloak_on_fire(&self) -> Result<bool, Box<dyn Error>> {
        let get_is_decloak_on_fire_func = get_callback!(self.ai_id, UnitDef_isDecloakOnFire)?;
        Ok(unsafe { get_is_decloak_on_fire_func(self.ai_id, self.def_id) })
    }

    pub fn all(&self) -> Result<UnitCloakAll, Box<dyn Error>> {
        Ok(UnitCloakAll {
            able_to_cloak: self.able_to_cloak()?,
            start_cloaked: self.start_cloaked()?,
            cloak_cost: self.cloak_cost()?,
            cloak_cost_moving: self.cloak_cost_moving()?,
            decloak_distance: self.decloak_distance()?,
            decloak_spherical: self.decloak_spherical()?,
            decloak_on_fire: self.decloak_on_fire()?,
        })
    }
}