f1_api/packet/status.rs
1//! Data on the status of each car in the session
2//!
3//! The F1 games provide detailed information about the status of each car in the session. The rate
4//! with which the data is provided can be configured in the in-game settings.
5
6use derive_new::new;
7use getset::{CopyGetters, Getters};
8
9use crate::packet::header::Header;
10use crate::types::{CornerProperty, Flag};
11
12/// Traction control settings
13///
14/// Traction control is a driver assist that does only exist in-game, and not on an actual F1 car.
15/// It can be turned off, or switched between a low and high setting.
16#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
17pub enum TractionControl {
18 /// Traction control is turned off.
19 Off,
20
21 /// Traction control operates at a low setting, and offers only minor assists.
22 Low,
23
24 /// Traction control operates at a high setting, and offers maximum help.
25 High,
26}
27
28impl Default for TractionControl {
29 fn default() -> Self {
30 TractionControl::Off
31 }
32}
33
34/// Fuel mix settings
35///
36/// F1 cars can run on different fuel mixes, and drivers are often required to change the fuel mix
37/// during a race to save fuel or prevent the engine from overheating.
38#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
39pub enum FuelMix {
40 /// The engine runs on a lean fuel mix.
41 Lean,
42
43 /// The engine runs on the standard fuel mix.
44 Standard,
45
46 /// The engine runs on a rich fuel mix.
47 Rich,
48
49 /// The engine runs on the richest fuel mix.
50 Max,
51}
52
53impl Default for FuelMix {
54 fn default() -> Self {
55 FuelMix::Standard
56 }
57}
58
59/// Setting of the Drag Reduction System
60///
61/// The Drag Reduction System, or DRS, can be disabled and enabled during a race. When it is
62/// disabled, drivers cannot activate it.
63#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
64pub enum DrsSetting {
65 /// The DRS setting is unknown, for example because the current formula does not support it.
66 Unknown,
67
68 /// DRS is disabled, and cannot be used by drivers.
69 NotAllowed,
70
71 /// DRS is enabled, and can be used by drivers.
72 Allowed,
73}
74
75impl Default for DrsSetting {
76 fn default() -> Self {
77 DrsSetting::Unknown
78 }
79}
80
81/// Tyre compounds that influence the physical simulation
82///
83/// The latest generations of F1 games started to distinguish between physical and visual tyre
84/// compounds to support Pirelli's system with five tyre compounds from which three are picked for a
85/// race weekend and then labeled soft, medium, and hard. The physical tyre compound describes which
86/// compound is used, while the visual tyre compound indicates if it is a soft, medium, or hard
87/// tyre.
88///
89/// For older games that do not know this distinction yet, the tyre compound is duplicated in both
90/// fields.
91#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
92pub enum PhysicalTyreCompound {
93 ClassicDry,
94 ClassicWet,
95 F1C1,
96 F1C2,
97 F1C3,
98 F1C4,
99 F1C5,
100 F1HyperSoft,
101 F1UltraSoft,
102 F1SuperSoft,
103 F1Soft,
104 F1Medium,
105 F1Hard,
106 F1SuperHard,
107 F1Intermediate,
108 F1Wet,
109 F2SuperSoft,
110 F2Soft,
111 F2Medium,
112 F2Hard,
113 F2Wet,
114}
115
116impl Default for PhysicalTyreCompound {
117 fn default() -> Self {
118 PhysicalTyreCompound::F1C1
119 }
120}
121
122/// Tyre compounds that influence the visual appearance
123///
124/// The latest generations of F1 games started to distinguish between physical and visual tyre
125/// compounds to support Pirelli's system with five tyre compounds from which three are picked for a
126/// race weekend and then labeled soft, medium, and hard. The physical tyre compound describes which
127/// compound is used, while the visual tyre compound indicates if it is a soft, medium, or hard
128/// tyre.
129///
130/// For older games that do not know this distinction yet, the tyre compound is duplicated in both
131/// fields.
132#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
133pub enum VisualTyreCompound {
134 ClassicDry,
135 ClassicWet,
136 F1HyperSoft,
137 F1UltraSoft,
138 F1SuperSoft,
139 F1Soft,
140 F1Medium,
141 F1Hard,
142 F1SuperHard,
143 F1Intermediate,
144 F1Wet,
145 F2SuperSoft,
146 F2Soft,
147 F2Medium,
148 F2Hard,
149 F2Wet,
150}
151
152impl Default for VisualTyreCompound {
153 fn default() -> Self {
154 VisualTyreCompound::F1Soft
155 }
156}
157
158/// Deploy modes for the Energy Recovery System
159///
160/// The Energy Recovery System, or ERS, can be operated in different modes that determine how much
161/// energy is harvested under braking, and how much is used to accelerate the car.
162#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
163pub enum ErsDeployMode {
164 /// The Energy Recovery System is disabled or does not exist in the current car.
165 None,
166
167 /// The Energy Recovery System operates at a low setting, and harvest more energy than it
168 /// consumes.
169 Low,
170
171 /// The Energy Recovery System operates at a medium setting, harvesting and deploying at a
172 /// similar rate.
173 Medium,
174
175 /// The Energy Recovery System operates at a high setting, and deploys more energy than it can
176 /// harvest.
177 High,
178
179 /// The Energy Recovery System operates at a very high level, and deploys far more energy than
180 /// it can harvest.
181 Overtake,
182
183 /// The Energy Recovery System operates at a level optimized for qualifying laps, which aims to
184 /// deplete the batteries by the end of the lap.
185 Hotlap,
186}
187
188impl Default for ErsDeployMode {
189 fn default() -> Self {
190 ErsDeployMode::Low
191 }
192}
193
194/// Data describing the status of a car
195///
196/// The status of each car is a collection of properties that can change over time. It includes data
197/// about the fuel, the engine, the various assistance systems like ABS, DRS, and ERS, and the
198/// damage the car has sustained. In multiplayer sessions, some of this data is restricted and only
199/// shown for the player's own car.
200#[derive(new, Debug, CopyGetters, Getters, PartialEq, Copy, Clone, PartialOrd, Default)]
201#[allow(clippy::too_many_arguments)]
202pub struct CarStatus {
203 /// Returns the traction control setting.
204 #[getset(get_copy = "pub")]
205 traction_control: TractionControl,
206
207 /// Returns whether ABS is enabled.
208 #[getset(get_copy = "pub")]
209 abs: bool,
210
211 /// Returns the fuel mix setting.
212 #[getset(get_copy = "pub")]
213 fuel_mix: FuelMix,
214
215 /// Returns the front brake bias (percentage).
216 #[getset(get_copy = "pub")]
217 brake_bias: u8,
218
219 /// Returns whether the pit speed limiter is engaged.
220 #[getset(get_copy = "pub")]
221 pit_limiter: bool,
222
223 /// Returns the remaining fuel mass in tank.
224 #[getset(get_copy = "pub")]
225 fuel_remaining: f32,
226
227 /// Returns the fuel capacity.
228 #[getset(get_copy = "pub")]
229 fuel_capacity: f32,
230
231 /// Returns the remaining fuel in terms of laps.
232 #[getset(get_copy = "pub")]
233 fuel_remaining_laps: f32,
234
235 /// Returns the car's maximum RPM where the rev limiter kicks in.
236 #[getset(get_copy = "pub")]
237 max_rpm: u16,
238
239 /// Returns the car's idle RPM.
240 #[getset(get_copy = "pub")]
241 idle_rpm: u16,
242
243 /// Returns the car's number of gears.
244 #[getset(get_copy = "pub")]
245 gear_count: u8,
246
247 /// Returns the status of DRS.
248 #[getset(get_copy = "pub")]
249 drs: DrsSetting,
250
251 /// Returns the tyre wear at each corner of the car in percent.
252 #[getset(get = "pub")]
253 tyre_wear: CornerProperty<u8>,
254
255 /// Returns the physical compound of the tyres.
256 #[getset(get_copy = "pub")]
257 physical_tyre_compound: PhysicalTyreCompound,
258
259 /// Returns the visual compound of the tyres.
260 #[getset(get_copy = "pub")]
261 visual_tyre_compound: VisualTyreCompound,
262
263 /// Returns the tyre damage at each corner of the car in percent.
264 #[getset(get = "pub")]
265 tyre_damage: CornerProperty<u8>,
266
267 /// Returns the damage to the left front wing in percent.
268 #[getset(get_copy = "pub")]
269 front_left_wing_damage: u8,
270
271 /// Returns the damage to the right front wing in percent.
272 #[getset(get_copy = "pub")]
273 front_right_wing_damage: u8,
274
275 /// Returns the damage to the rear wing in percent.
276 #[getset(get_copy = "pub")]
277 rear_wing_damage: u8,
278
279 /// Returns the damage to the engine in percent.
280 #[getset(get_copy = "pub")]
281 engine_damage: u8,
282
283 /// Returns the damage to the gear box in percent.
284 #[getset(get_copy = "pub")]
285 gear_box_damage: u8,
286
287 /// Returns the flags that are being shown to the current car.
288 #[getset(get_copy = "pub")]
289 vehicle_flags: Flag,
290
291 /// Returns the ERS energy store in Joules.
292 #[getset(get_copy = "pub")]
293 ers_energy: f32,
294
295 /// Returns the ERS deploy mode.
296 #[getset(get_copy = "pub")]
297 ers_deploy_mode: ErsDeployMode,
298
299 /// Returns the ERS energy harvested this lap by the MGU-K.
300 #[getset(get_copy = "pub")]
301 ers_harvest_mgu_k: f32,
302
303 /// Returns the ERS energy harvested this lap by the MGU-H.
304 #[getset(get_copy = "pub")]
305 ers_harvest_mgu_h: f32,
306
307 /// Returns the ERS energy deployed this lap.
308 #[getset(get_copy = "pub")]
309 ers_deployed: f32,
310}
311
312/// Packet containing the status of each car in the session
313///
314/// The F1 games publish data on the status of each car in the session at a rate that can be
315/// configured in the in-game settings.
316#[derive(new, Debug, Getters, PartialEq, Clone, PartialOrd)]
317pub struct CarStatusPacket {
318 /// Returns the packet header prefixing the car status packet.
319 #[getset(get = "pub")]
320 header: Header,
321
322 /// Returns the status of each car in the session.
323 #[getset(get = "pub")]
324 statuses: Vec<CarStatus>,
325}