spring_ai_rs/ai_interface/callback/command/command_data/
send.rs

1use std::ffi::CString;
2
3use spring_ai_sys::{
4    SSendResourcesCommand, SSendStartPosCommand, SSendTextMessageCommand, SSendUnitsCommand,
5};
6
7use crate::ai_interface::callback::command::command_data::{CData, CommandData};
8
9// Send resources data
10pub struct SendResourcesCommandData {
11    pub resource_id: i32,
12    pub amount: f32,
13    pub receiving_team_id: i32,
14}
15
16impl CommandData for SendResourcesCommandData {
17    type CDataType = SSendResourcesCommand;
18
19    fn c_data(&mut self) -> Self::CDataType {
20        SSendResourcesCommand {
21            resourceId: self.resource_id,
22            amount: self.amount,
23            receivingTeamId: self.receiving_team_id,
24            ret_isExecuted: false,
25        }
26    }
27}
28
29impl CData for SSendResourcesCommand {}
30
31// Send start position data
32pub struct SendStartPosCommandData {
33    pub ready: bool,
34    pub position: [f32; 3],
35}
36
37impl CommandData for SendStartPosCommandData {
38    type CDataType = SSendStartPosCommand;
39
40    fn c_data(&mut self) -> Self::CDataType {
41        SSendStartPosCommand {
42            ready: self.ready,
43            pos_posF3: self.position.as_mut_ptr(),
44        }
45    }
46}
47
48impl CData for SSendStartPosCommand {}
49
50// Send text message data
51pub struct SendTextMessageCommandData {
52    pub text: CString,
53    pub zone: i32,
54}
55
56impl CommandData for SendTextMessageCommandData {
57    type CDataType = SSendTextMessageCommand;
58
59    fn c_data(&mut self) -> Self::CDataType {
60        SSendTextMessageCommand {
61            text: self.text.as_ptr(),
62            zone: self.zone,
63        }
64    }
65}
66
67impl CData for SSendTextMessageCommand {}
68
69// Send units data
70pub struct SendUnitsCommandData {
71    pub unit_ids: Vec<i32>,
72    pub receiving_team_id: i32,
73}
74
75impl CommandData for SendUnitsCommandData {
76    type CDataType = SSendUnitsCommand;
77
78    fn c_data(&mut self) -> Self::CDataType {
79        SSendUnitsCommand {
80            unitIds: self.unit_ids.as_mut_ptr(),
81            unitIds_size: self.unit_ids.len() as i32,
82            receivingTeamId: self.receiving_team_id,
83            ret_sentUnits: 0,
84        }
85    }
86}
87
88impl CData for SSendUnitsCommand {}