f1_api/packet/
session.rs

1//! Data about the current session
2//!
3//! The F1 games provide information about the current session, for example weather and temperature
4//! as well as settings like the type of safety car in use.
5
6use std::time::Duration;
7
8use derive_new::new;
9use getset::{CopyGetters, Getters};
10
11use crate::packet::header::Header;
12use crate::types::{Flag, VehicleIndex};
13
14/// Types of formula racing supported by the F1 games
15///
16/// The F1 games support different types of formula racing, with newer games typically supporting
17/// more than older games.
18#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
19pub enum Formula {
20    ClassicF1,
21    GenericF1,
22    ModernF1,
23    F2,
24}
25
26impl Default for Formula {
27    fn default() -> Self {
28        Formula::ModernF1
29    }
30}
31
32/// Safety car rules that can be set for a session
33///
34/// The F1 games allow different rules to be configured for the safety car. Sessions can have no
35/// safety car at all, a virtual safety car, or a full safety car.
36#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
37pub enum SafetyCar {
38    None,
39    Full,
40    Virtual,
41}
42
43impl Default for SafetyCar {
44    fn default() -> Self {
45        SafetyCar::Full
46    }
47}
48
49/// Types of sessions
50///
51/// F1 knows many different types of sessions. A typical race weekend consists of free practice,
52/// qualifying and a race, each of which can be divided into multiple sessions (e.g. first or second
53/// free practice).
54#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
55pub enum Session {
56    OneShotQualifying,
57    P1,
58    P2,
59    P3,
60    Q1,
61    Q2,
62    Q3,
63    Race,
64    Race2,
65    ShortPractice,
66    ShortQualifying,
67    TimeTrial,
68    Unknown,
69}
70
71impl Default for Session {
72    fn default() -> Self {
73        Session::Unknown
74    }
75}
76
77/// Race tracks that are in the F1 games
78///
79/// The F1 games feature a long list of race tracks that appear in the games. Not every track is
80/// available in every game.
81#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
82pub enum Track {
83    AbuDhabi,
84    Austria,
85    Azerbaijan,
86    Bahrain,
87    BahrainShort,
88    Brazil,
89    Catalunya,
90    Hockenheim,
91    Hungaroring,
92    Melbourne,
93    Mexico,
94    Monaco,
95    Montreal,
96    Monza,
97    PaulRicard,
98    Shanghai,
99    Silverstone,
100    SilverstoneShort,
101    Singapore,
102    Sochi,
103    Spa,
104    Suzuka,
105    SuzukaShort,
106    Texas,
107    TexasShort,
108    Unknown,
109}
110
111impl Default for Track {
112    fn default() -> Self {
113        Track::Unknown
114    }
115}
116
117/// Weather conditions that can occur in a session
118///
119/// The modern F1 games support changing weather conditions, though not every weather condition is
120/// supported by every game.
121#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
122pub enum Weather {
123    Clear,
124    LightCloud,
125    Overcast,
126    LightRain,
127    HeavyRain,
128    Storm,
129}
130
131impl Default for Weather {
132    fn default() -> Self {
133        Weather::Clear
134    }
135}
136
137/// A marshal zone around the track and its current flags.
138///
139/// A race track is divided into many marshal zones. In each zone, flags can be waved to inform
140/// drivers about hazards on track, faster cars approaching from behind, and other important status
141/// updates. Each zone is represented by a struct containing the fraction of the race track's length
142/// where the zone starts, and any flag that is currently being shown there.
143#[derive(new, Debug, CopyGetters, PartialEq, Copy, Clone, PartialOrd, Default)]
144pub struct MarshalZone {
145    /// Returns the start point of the marshal zone as a fraction of the race track's total length.
146    #[getset(get_copy = "pub")]
147    start: f32,
148
149    /// Returns the flag that is currently being displayed in the marshal zone.
150    #[getset(get_copy = "pub")]
151    flag: Flag,
152}
153
154/// Packet containing data about the current session
155///
156/// The session packet provides information about the current session, for example weather and
157/// temperature as well as settings like the type of safety car in use.
158#[derive(new, Debug, CopyGetters, Getters, PartialEq, Clone, PartialOrd)]
159#[allow(clippy::too_many_arguments)]
160pub struct SessionPacket {
161    /// Returns the packet header prefixing the session packet.
162    #[getset(get = "pub")]
163    header: Header,
164
165    /// Returns the current weather in the session.
166    #[getset(get_copy = "pub")]
167    weather: Weather,
168
169    /// Returns the track temperature in degrees celsius.
170    #[getset(get_copy = "pub")]
171    track_temperature: i8,
172
173    /// Returns the air temperature in degrees celsius.
174    #[getset(get_copy = "pub")]
175    air_temperature: i8,
176
177    /// Returns the total number of laps in this race.
178    #[getset(get_copy = "pub")]
179    total_laps: u8,
180
181    /// Returns the length of the race track in metres.
182    #[getset(get_copy = "pub")]
183    track_length: u16,
184
185    /// Returns the type of the current session.
186    #[getset(get_copy = "pub")]
187    session_type: Session,
188
189    /// Returns the race track of the session.
190    #[getset(get_copy = "pub")]
191    track: Track,
192
193    /// Returns the type of formula racing.
194    #[getset(get_copy = "pub")]
195    formula: Formula,
196
197    /// Returns the time that is left in the session.
198    #[getset(get = "pub")]
199    time_left: Duration,
200
201    /// Returns the duration of the session in seconds.
202    #[getset(get = "pub")]
203    duration: Duration,
204
205    /// Returns the pit speed limit in kilometers per hour.
206    #[getset(get_copy = "pub")]
207    pit_speed_limit: u8,
208
209    /// Returns whether the game is paused right now.
210    #[getset(get_copy = "pub")]
211    game_paused: bool,
212
213    /// Returns whether the player is spectating the session.
214    #[getset(get_copy = "pub")]
215    is_spectating: bool,
216
217    /// Returns the index of the car being spectated.
218    #[getset(get_copy = "pub")]
219    spectator_car_index: VehicleIndex,
220
221    /// Returns whether the support for SLI Pro is active.
222    #[getset(get_copy = "pub")]
223    sli_pro_support: bool,
224
225    /// Returns the marshal zones around the track.
226    #[getset(get = "pub")]
227    marshal_zones: Vec<MarshalZone>,
228
229    /// Returns the type of safety car that is used in the session.
230    #[getset(get_copy = "pub")]
231    safety_car: SafetyCar,
232
233    /// Returns whether the session is a multiplayer session.
234    #[getset(get_copy = "pub")]
235    network_session: bool,
236}