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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
use serde::{Deserialize, Serialize};
use std::{any::Any, fmt::Debug};

// -----------------------------------------------------------------
//                            Traits
pub trait Message: Debug {
    fn as_any(&self) -> &dyn Any;
}

pub trait MessageIdentity {
    fn id() -> i32;
}

// -----------------------------------------------------------------
//              Error Message (if things went wrong)
#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
pub struct MsgError {
    pub error_code: i32,
}

// -----------------------------------------------------------------
//                            Core
#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
pub struct MsgEmpty {
    pub value: i32, // Dummy value, extern C do not allow empty types
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Default, Clone, Copy)]
pub struct MsgUse {
    pub component_id: i32,
    pub sticky: i32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
pub struct MsgVelocity {
    pub x: f32,
    pub y: f32,
    pub speed: f32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
pub struct MsgAngle {
    pub angle: f32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
pub struct MsgComponentStatusQuery {
    pub component_id: i32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
pub struct RMsgComponentStatus {
    pub component_id: i32,
    pub health: f32,
    pub cooldown: f32,
    pub is_activated: bool,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
pub struct MsgState {
    pub value: i32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct RMsgState {
    pub angle: f32,
    pub vel_x: f32,
    pub vel_y: f32,
    pub health: f32,
    pub buffs: Vec<String>,
}

// -----------------------------------------------------------------
//                           Modules
#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
pub struct MsgModuleStatusQuery {
    pub module_id: i32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
pub struct RMsgModuleStatus {
    pub cooldown: f32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
pub struct MsgTeleport {
    pub x: f32,
    pub y: f32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct MsgRadar {
    pub value: i32, // A dummy value to satisfy extern "C"
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct RMsgRadar {
    pub x: f32,
    pub y: f32,
    pub distance: f32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct MsgLaser {
    pub angle: f32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct RMsgLaser {
    pub tag: String,
    pub kind: String,
    pub distance: f32,
    pub angle: f32,
    pub buffs: Vec<String>,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct MsgForceField {
    pub value: i32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct MsgMine {
    pub value: i32,
}

// -----------------------------------------------------------------
//                        Messages Added Ad-Hoc
// After this point, all of the messages are added ad-hoc This is because the
// message number cannot continue to change and it is dependent on the struct
// definition order.
#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct MsgTime {
    pub value: i32, // Dummy value (for C FFI)
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct RMsgTime {
    pub timestamp: f32, // time in seconds
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct MsgRepair {
    pub component_id: i32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct RMsgRepair {
    pub healed_amount: f32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct MsgThrust {
    pub angle: f32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct MsgScan {
    pub value: i32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct RMsgScanObject {
    pub tag: String,
    pub kind: String,
    pub x: f32,
    pub y: f32,
    pub buffs: Vec<String>,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct RMsgScan {
    pub objects: Vec<RMsgScanObject>,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct MsgGPS {
    pub value: i32,
}

#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct RMsgGPS {
    pub x: f32,
    pub y: f32,
}