Skip to main content

subtr_actor/stats/calculators/
samples.rs

1use boxcars;
2
3use crate::*;
4
5/// A sampled ball state at a frame.
6#[derive(Debug, Clone)]
7pub struct BallSample {
8    pub rigid_body: boxcars::RigidBody,
9}
10
11impl BallSample {
12    pub fn position(&self) -> glam::Vec3 {
13        vec_to_glam(&self.rigid_body.location)
14    }
15
16    pub fn velocity(&self) -> glam::Vec3 {
17        self.rigid_body
18            .linear_velocity
19            .as_ref()
20            .map(vec_to_glam)
21            .unwrap_or(glam::Vec3::ZERO)
22    }
23}
24
25/// A sampled player state at a frame.
26#[derive(Debug, Clone)]
27pub struct PlayerSample {
28    pub player_id: PlayerId,
29    pub is_team_0: bool,
30    pub hitbox: CarHitbox,
31    pub rigid_body: Option<boxcars::RigidBody>,
32    pub boost_amount: Option<f32>,
33    pub last_boost_amount: Option<f32>,
34    pub boost_active: bool,
35    pub dodge_active: bool,
36    /// World-frame dodge torque of the player's most recent dodge, when
37    /// available. This is the flip's rotation axis (a horizontal vector; its
38    /// world-z is ~0), and combined with the travel direction at the dodge it
39    /// recovers the dodge direction (forward/back vs side) the player input. See
40    /// the flick detector's reverse/side classification. `None` on inputs that
41    /// do not replicate dodge torque (e.g. the BakkesMod live path).
42    pub dodge_torque: Option<glam::Vec3>,
43    pub powerslide_active: bool,
44    pub match_goals: Option<i32>,
45    pub match_assists: Option<i32>,
46    pub match_saves: Option<i32>,
47    pub match_shots: Option<i32>,
48    pub match_score: Option<i32>,
49}
50
51impl PlayerSample {
52    pub fn position(&self) -> Option<glam::Vec3> {
53        self.rigid_body.as_ref().map(|rb| vec_to_glam(&rb.location))
54    }
55
56    pub fn velocity(&self) -> Option<glam::Vec3> {
57        self.rigid_body
58            .as_ref()
59            .and_then(|rb| rb.linear_velocity.as_ref().map(vec_to_glam))
60    }
61
62    pub fn speed(&self) -> Option<f32> {
63        self.velocity().map(|velocity| velocity.length())
64    }
65}
66
67/// A sampled demolition event.
68#[derive(Debug, Clone, PartialEq, Eq)]
69pub struct DemoEventSample {
70    pub attacker: PlayerId,
71    pub victim: PlayerId,
72}