ssbm_utils/
lib.rs

1//! # SSBM Utils
2//!
3//! A crate for interacting with data from Super Smash Bros. Melee. Contains enums, helper types,
4//! and various functions to replicate in-game calculations
5//!
6//!
7
8pub mod trackers;
9pub mod types;
10pub mod calc {
11    pub mod on_hit;
12    pub use on_hit::*;
13    mod general;
14    pub use general::*;
15    mod knockback;
16    pub use knockback::*;
17}
18pub mod enums {
19    pub mod attack;
20    pub use attack::Attack;
21
22    mod bitflag_impl;
23    pub use bitflag_impl::BitFlags;
24    pub use bitflag_impl::Buttons;
25    pub mod buttons;
26    pub use buttons::{ControllerInput, EngineInput, StickRegion};
27
28    pub mod character;
29    pub use character::{Character, Costume};
30
31    mod general;
32    pub use general::*;
33
34    mod item;
35    pub use item::*;
36
37    pub mod stage;
38    pub use stage::StageID;
39
40    mod state;
41    pub use state::*;
42}
43pub mod checks;
44pub mod constants {
45    use std::f32::consts::PI;
46
47    /// Damage is scaled by .7 when applied
48    pub const SHIELD_HEALTH_MAX: f32 = 60.0;
49
50    /// Maximum accepted analog trigger value
51    pub const TRIGGER_MAX: f32 = 1.0;
52    /// Minimum accepted analog trigger value
53    pub const TRIGGER_MIN: f32 = 43.0 / 140.0;
54    /// Analog value when holding Z
55    pub const Z_ANALOG: f32 = 49.0 / 140.0;
56
57    /// Shield regen rate **per frame**
58    pub const SHIELD_REGEN_RATE: f32 = 0.07;
59
60    /// The rate at which knockback velocity decays per frame. Can be split into X and Y components
61    /// with a velocity and trig functions.
62    ///
63    /// See also: `ssbm_utils::calc::attack::get_horizontal_decay()` and
64    /// `ssbm_utils::calc::attack::get_vertical_decay()`
65    pub const KB_DECAY: f32 = 0.051;
66
67    /// The minimum value at which knockback will tumble/knock down
68    pub const TUMBLE_THRESHOLD: f32 = 80.0;
69
70    pub const FIRST_FRAME_INDEX: i32 = -123;
71
72    /// The max number of frames that will be present in a tournament match that ends in a time out
73    pub const MAX_TOURNAMENT_GAME_LENGTH: usize = 28924;
74
75    /// The max amount that DI can change a knockback angle by, in degrees
76    pub const DI_MAX_DEGREES: f32 = 18.0;
77
78    // Some of these get a little dumb because floating point functions aren't const =)
79
80    /// The max amount that DI can change a knockback angle by, in radians
81    pub const DI_MAX_RADS: f32 = 18.0 * (PI / 180.0);
82
83    /// The magnitude of the change in position per ASDI
84    pub const ASDI_DIST: f32 = 3.0;
85    /// The magintude of the change in position per SDI input
86    pub const SDI_DIST: f32 = 6.0;
87}
88
89/// Converts a melee frame index (i32 starting at -123) to a real-time frame index (usize starting at 0)
90#[macro_export]
91macro_rules! mf {
92    ($frames:expr) => {
93        TryInto::<usize>::try_into($frames + 123).unwrap()
94    };
95}
96
97pub mod prelude {
98    pub use crate::calc::*;
99    pub use crate::constants::*;
100    pub use crate::enums::*;
101    pub use crate::mf;
102    pub use crate::types::*;
103    pub use crate::pos;
104    pub use crate::vel;
105    pub use crate::stick_pos;
106}