Skip to main content

subtr_actor/stats/calculators/
samples.rs

1use boxcars;
2
3use crate::*;
4
5#[derive(Debug, Clone)]
6pub struct BallSample {
7    pub rigid_body: boxcars::RigidBody,
8}
9
10impl BallSample {
11    pub fn position(&self) -> glam::Vec3 {
12        vec_to_glam(&self.rigid_body.location)
13    }
14
15    pub fn velocity(&self) -> glam::Vec3 {
16        self.rigid_body
17            .linear_velocity
18            .as_ref()
19            .map(vec_to_glam)
20            .unwrap_or(glam::Vec3::ZERO)
21    }
22}
23
24#[derive(Debug, Clone)]
25pub struct PlayerSample {
26    pub player_id: PlayerId,
27    pub is_team_0: bool,
28    pub rigid_body: Option<boxcars::RigidBody>,
29    pub boost_amount: Option<f32>,
30    pub last_boost_amount: Option<f32>,
31    pub boost_active: bool,
32    pub dodge_active: bool,
33    pub powerslide_active: bool,
34    pub match_goals: Option<i32>,
35    pub match_assists: Option<i32>,
36    pub match_saves: Option<i32>,
37    pub match_shots: Option<i32>,
38    pub match_score: Option<i32>,
39}
40
41impl PlayerSample {
42    pub fn position(&self) -> Option<glam::Vec3> {
43        self.rigid_body.as_ref().map(|rb| vec_to_glam(&rb.location))
44    }
45
46    pub fn velocity(&self) -> Option<glam::Vec3> {
47        self.rigid_body
48            .as_ref()
49            .and_then(|rb| rb.linear_velocity.as_ref().map(vec_to_glam))
50    }
51
52    pub fn speed(&self) -> Option<f32> {
53        self.velocity().map(|velocity| velocity.length())
54    }
55}
56
57#[derive(Debug, Clone, PartialEq, Eq)]
58pub struct DemoEventSample {
59    pub attacker: PlayerId,
60    pub victim: PlayerId,
61}