mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2024-11-20 00:46:34 +00:00
Tech and Ledge options as bitflags (#127)
* Change TechOptions to TechFlags * update gitmodules * shouldn't have pushed that * change ledge options as well incorp change from review
This commit is contained in:
parent
e7ec867581
commit
0388a08a16
7 changed files with 74 additions and 88 deletions
|
@ -10,6 +10,7 @@ crate-type = ["cdylib"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
skyline = { git = "https://github.com/ultimate-research/skyline-rs.git" }
|
skyline = { git = "https://github.com/ultimate-research/skyline-rs.git" }
|
||||||
skyline_smash = { git = "https://github.com/ultimate-research/skyline-smash.git" }
|
skyline_smash = { git = "https://github.com/ultimate-research/skyline-smash.git" }
|
||||||
|
bitflags = "1.0"
|
||||||
# skyline = { path = "../../../../src/skyline-rs" }
|
# skyline = { path = "../../../../src/skyline-rs" }
|
||||||
# skyline_smash = { path = "../../../../src/skyline-smash" }
|
# skyline_smash = { path = "../../../../src/skyline-smash" }
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5580043d20bb9c33af1703ece494e77a5f0840f0
|
Subproject commit 2a9f0fc2f398e613efd48a63f0c7146ecfcbf2e4
|
|
@ -1,5 +1,9 @@
|
||||||
|
|
||||||
use core::f64::consts::PI;
|
use core::f64::consts::PI;
|
||||||
use smash::lib::lua_const::*;
|
use smash::lib::lua_const::*;
|
||||||
|
use smash::hash40;
|
||||||
|
use smash::app;
|
||||||
|
|
||||||
|
|
||||||
/// Hitbox Visualization
|
/// Hitbox Visualization
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
|
@ -114,70 +118,61 @@ impl From<i32> for Attack {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bitflag helper function macro
|
||||||
|
macro_rules! to_vec_impl {
|
||||||
|
($e:ty) => {
|
||||||
|
pub fn to_vec(&self) -> Vec::<$e> {
|
||||||
|
let mut vec = Vec::<$e>::new();
|
||||||
|
let mut field = <$e>::from_bits_truncate(self.bits);
|
||||||
|
while !field.is_empty() {
|
||||||
|
let flag = <$e>::from_bits(1u32 << field.bits.trailing_zeros()).unwrap();
|
||||||
|
field -= flag;
|
||||||
|
vec.push(flag);
|
||||||
|
}
|
||||||
|
return vec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ledge Option
|
// Ledge Option
|
||||||
#[repr(i32)]
|
bitflags! {
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
pub struct LedgeOption : u32
|
||||||
pub enum LedgeOption {
|
{
|
||||||
None = 0,
|
const NEUTRAL = 0b1;
|
||||||
Random = 1,
|
const ROLL = 0b10;
|
||||||
Neutral = 2,
|
const JUMP = 0b100;
|
||||||
Roll = 3,
|
const ATTACK = 0b1000;
|
||||||
Jump = 4,
|
}
|
||||||
Attack = 5,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<i32> for LedgeOption {
|
pub unsafe fn random_option<T>(arg : &Vec<T>) -> &T {
|
||||||
fn from(x: i32) -> Self {
|
return &arg[app::sv_math::rand(hash40("fighter"), arg.len() as i32) as usize];
|
||||||
use LedgeOption::*;
|
|
||||||
|
|
||||||
match x {
|
|
||||||
0 => None,
|
|
||||||
1 => Random,
|
|
||||||
2 => Neutral,
|
|
||||||
3 => Roll,
|
|
||||||
4 => Jump,
|
|
||||||
5 => Attack,
|
|
||||||
_ => panic!("Invalid ledge option {}", x),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LedgeOption {
|
impl LedgeOption {
|
||||||
pub fn into_status(&self) -> Option<i32> {
|
pub fn into_status(&self) -> Option<i32> {
|
||||||
Some(match self {
|
Some(match *self {
|
||||||
LedgeOption::Neutral => *FIGHTER_STATUS_KIND_CLIFF_CLIMB,
|
LedgeOption::NEUTRAL => *FIGHTER_STATUS_KIND_CLIFF_CLIMB,
|
||||||
LedgeOption::Roll => *FIGHTER_STATUS_KIND_CLIFF_ESCAPE,
|
LedgeOption::ROLL => *FIGHTER_STATUS_KIND_CLIFF_ESCAPE,
|
||||||
LedgeOption::Jump => *FIGHTER_STATUS_KIND_CLIFF_JUMP1,
|
LedgeOption::JUMP => *FIGHTER_STATUS_KIND_CLIFF_JUMP1,
|
||||||
LedgeOption::Attack => *FIGHTER_STATUS_KIND_CLIFF_ATTACK,
|
LedgeOption::ATTACK => *FIGHTER_STATUS_KIND_CLIFF_ATTACK,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
to_vec_impl!{LedgeOption}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tech Option
|
// Tech options
|
||||||
#[repr(i32)]
|
bitflags! {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
pub struct TechFlags : u32 {
|
||||||
pub enum TechOption {
|
const NO_TECH = 0b1;
|
||||||
None = 0,
|
const ROLL = 0b10;
|
||||||
Random = 1,
|
const IN_PLACE = 0b100;
|
||||||
InPlace = 2,
|
}
|
||||||
Roll = 3,
|
|
||||||
Miss = 4,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<i32> for TechOption {
|
impl TechFlags {
|
||||||
fn from(x: i32) -> Self {
|
to_vec_impl!{TechFlags}
|
||||||
use TechOption::*;
|
|
||||||
|
|
||||||
match x {
|
|
||||||
0 => None,
|
|
||||||
1 => Random,
|
|
||||||
2 => InPlace,
|
|
||||||
3 => Roll,
|
|
||||||
4 => Miss,
|
|
||||||
_ => panic!("Invalid tech option {}", x),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mash States
|
/// Mash States
|
||||||
|
@ -344,7 +339,7 @@ pub struct TrainingModpackMenu {
|
||||||
pub mash_attack_state: Attack,
|
pub mash_attack_state: Attack,
|
||||||
pub follow_up: Action,
|
pub follow_up: Action,
|
||||||
pub ledge_state: LedgeOption,
|
pub ledge_state: LedgeOption,
|
||||||
pub tech_state: TechOption,
|
pub tech_state: TechFlags,
|
||||||
pub mash_state: Mash,
|
pub mash_state: Mash,
|
||||||
pub shield_state: Shield,
|
pub shield_state: Shield,
|
||||||
pub defensive_state: Defensive,
|
pub defensive_state: Defensive,
|
||||||
|
|
|
@ -10,8 +10,8 @@ pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpac
|
||||||
left_stick: Direction::None,
|
left_stick: Direction::None,
|
||||||
mash_attack_state: Attack::Nair,
|
mash_attack_state: Attack::Nair,
|
||||||
follow_up: Action::Nothing,
|
follow_up: Action::Nothing,
|
||||||
ledge_state: LedgeOption::Random,
|
ledge_state: LedgeOption::all(),
|
||||||
tech_state: TechOption::Random,
|
tech_state: TechFlags::all(),
|
||||||
mash_state: Mash::None,
|
mash_state: Mash::None,
|
||||||
shield_state: Shield::None,
|
shield_state: Shield::None,
|
||||||
defensive_state: Defensive::Random,
|
defensive_state: Defensive::Random,
|
||||||
|
|
|
@ -6,6 +6,9 @@ mod common;
|
||||||
mod hitbox_visualizer;
|
mod hitbox_visualizer;
|
||||||
mod training;
|
mod training;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate bitflags;
|
||||||
|
|
||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
use training::combo::FRAME_ADVANTAGE;
|
use training::combo::FRAME_ADVANTAGE;
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,11 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor
|
||||||
let mut status = 0;
|
let mut status = 0;
|
||||||
let ledge_case: LedgeOption;
|
let ledge_case: LedgeOption;
|
||||||
|
|
||||||
if MENU.ledge_state == LedgeOption::Random {
|
let ledge_options = MENU.ledge_state.to_vec();
|
||||||
ledge_case = (app::sv_math::rand(hash40("fighter"), 4) + 2).into();
|
match ledge_options.len() {
|
||||||
} else {
|
0 => { ledge_case = LedgeOption::empty(); },
|
||||||
ledge_case = MENU.ledge_state;
|
1 => { ledge_case = ledge_options[0]; },
|
||||||
|
_ => { ledge_case = *random_option(&ledge_options); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(new_status) = ledge_case.into_status() {
|
if let Some(new_status) = ledge_case.into_status() {
|
||||||
|
@ -41,7 +42,7 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor
|
||||||
}
|
}
|
||||||
|
|
||||||
match ledge_case {
|
match ledge_case {
|
||||||
LedgeOption::Jump => {
|
LedgeOption::JUMP => {
|
||||||
mash::buffer_menu_mash(module_accessor);
|
mash::buffer_menu_mash(module_accessor);
|
||||||
}
|
}
|
||||||
_ => mash::perform_defensive_option(),
|
_ => mash::perform_defensive_option(),
|
||||||
|
@ -62,7 +63,7 @@ pub unsafe fn get_command_flag_cat(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if MENU.ledge_state == LedgeOption::None {
|
if MENU.ledge_state == LedgeOption::empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,14 +35,6 @@ unsafe fn mod_handle_change_status(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if MENU.tech_state == TechOption::None {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if MENU.tech_state == TechOption::Miss {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let status_kind_int = status_kind
|
let status_kind_int = status_kind
|
||||||
.try_get_int()
|
.try_get_int()
|
||||||
.unwrap_or(*FIGHTER_STATUS_KIND_WAIT as u64) as i32;
|
.unwrap_or(*FIGHTER_STATUS_KIND_WAIT as u64) as i32;
|
||||||
|
@ -51,26 +43,20 @@ unsafe fn mod_handle_change_status(
|
||||||
if status_kind_int == FIGHTER_STATUS_KIND_DOWN
|
if status_kind_int == FIGHTER_STATUS_KIND_DOWN
|
||||||
|| status_kind_int == FIGHTER_STATUS_KIND_DAMAGE_FLY_REFLECT_D
|
|| status_kind_int == FIGHTER_STATUS_KIND_DAMAGE_FLY_REFLECT_D
|
||||||
{
|
{
|
||||||
match MENU.tech_state {
|
let states = MENU.tech_state.to_vec();
|
||||||
TechOption::Random => {
|
let mut state = if states.is_empty() { TechFlags::empty() } else { states[0] };
|
||||||
let random_statuses = vec![
|
|
||||||
*FIGHTER_STATUS_KIND_DOWN,
|
|
||||||
*FIGHTER_STATUS_KIND_PASSIVE,
|
|
||||||
*FIGHTER_STATUS_KIND_PASSIVE_FB,
|
|
||||||
];
|
|
||||||
|
|
||||||
let random_status_index =
|
if states.len() > 1 {
|
||||||
app::sv_math::rand(hash40("fighter"), random_statuses.len() as i32) as usize;
|
let idx = app::sv_math::rand(hash40("fighter"), states.len() as i32) as usize;
|
||||||
if random_statuses[random_status_index] != FIGHTER_STATUS_KIND_DOWN {
|
state = states[idx];
|
||||||
*status_kind = L2CValue::new_int(random_statuses[random_status_index] as u64);
|
|
||||||
*unk = LUA_TRUE
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
TechOption::InPlace => {
|
match state {
|
||||||
|
TechFlags::IN_PLACE => {
|
||||||
*status_kind = FIGHTER_STATUS_KIND_PASSIVE.as_lua_int();
|
*status_kind = FIGHTER_STATUS_KIND_PASSIVE.as_lua_int();
|
||||||
*unk = LUA_TRUE;
|
*unk = LUA_TRUE;
|
||||||
}
|
}
|
||||||
TechOption::Roll => {
|
TechFlags::ROLL => {
|
||||||
*status_kind = FIGHTER_STATUS_KIND_PASSIVE_FB.as_lua_int();
|
*status_kind = FIGHTER_STATUS_KIND_PASSIVE_FB.as_lua_int();
|
||||||
*unk = LUA_TRUE;
|
*unk = LUA_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +99,7 @@ pub unsafe fn get_command_flag_cat(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if MENU.tech_state == TechOption::None {
|
if MENU.tech_state == TechFlags::empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +140,7 @@ pub unsafe fn change_motion(
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if MENU.tech_state == TechOption::None {
|
if MENU.tech_state == TechFlags::empty() || MENU.tech_state == TechFlags::NO_TECH {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue