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]
|
||||
skyline = { git = "https://github.com/ultimate-research/skyline-rs.git" }
|
||||
skyline_smash = { git = "https://github.com/ultimate-research/skyline-smash.git" }
|
||||
bitflags = "1.0"
|
||||
# skyline = { path = "../../../../src/skyline-rs" }
|
||||
# skyline_smash = { path = "../../../../src/skyline-smash" }
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 5580043d20bb9c33af1703ece494e77a5f0840f0
|
||||
Subproject commit 2a9f0fc2f398e613efd48a63f0c7146ecfcbf2e4
|
|
@ -1,5 +1,9 @@
|
|||
|
||||
use core::f64::consts::PI;
|
||||
use smash::lib::lua_const::*;
|
||||
use smash::hash40;
|
||||
use smash::app;
|
||||
|
||||
|
||||
/// Hitbox Visualization
|
||||
#[repr(i32)]
|
||||
|
@ -114,70 +118,61 @@ impl From<i32> for Attack {
|
|||
}
|
||||
}
|
||||
|
||||
// Ledge Option
|
||||
#[repr(i32)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub enum LedgeOption {
|
||||
None = 0,
|
||||
Random = 1,
|
||||
Neutral = 2,
|
||||
Roll = 3,
|
||||
Jump = 4,
|
||||
Attack = 5,
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for LedgeOption {
|
||||
fn from(x: i32) -> Self {
|
||||
use LedgeOption::*;
|
||||
// Ledge Option
|
||||
bitflags! {
|
||||
pub struct LedgeOption : u32
|
||||
{
|
||||
const NEUTRAL = 0b1;
|
||||
const ROLL = 0b10;
|
||||
const JUMP = 0b100;
|
||||
const ATTACK = 0b1000;
|
||||
}
|
||||
}
|
||||
|
||||
match x {
|
||||
0 => None,
|
||||
1 => Random,
|
||||
2 => Neutral,
|
||||
3 => Roll,
|
||||
4 => Jump,
|
||||
5 => Attack,
|
||||
_ => panic!("Invalid ledge option {}", x),
|
||||
}
|
||||
}
|
||||
pub unsafe fn random_option<T>(arg : &Vec<T>) -> &T {
|
||||
return &arg[app::sv_math::rand(hash40("fighter"), arg.len() as i32) as usize];
|
||||
}
|
||||
|
||||
impl LedgeOption {
|
||||
pub fn into_status(&self) -> Option<i32> {
|
||||
Some(match self {
|
||||
LedgeOption::Neutral => *FIGHTER_STATUS_KIND_CLIFF_CLIMB,
|
||||
LedgeOption::Roll => *FIGHTER_STATUS_KIND_CLIFF_ESCAPE,
|
||||
LedgeOption::Jump => *FIGHTER_STATUS_KIND_CLIFF_JUMP1,
|
||||
LedgeOption::Attack => *FIGHTER_STATUS_KIND_CLIFF_ATTACK,
|
||||
Some(match *self {
|
||||
LedgeOption::NEUTRAL => *FIGHTER_STATUS_KIND_CLIFF_CLIMB,
|
||||
LedgeOption::ROLL => *FIGHTER_STATUS_KIND_CLIFF_ESCAPE,
|
||||
LedgeOption::JUMP => *FIGHTER_STATUS_KIND_CLIFF_JUMP1,
|
||||
LedgeOption::ATTACK => *FIGHTER_STATUS_KIND_CLIFF_ATTACK,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
to_vec_impl!{LedgeOption}
|
||||
}
|
||||
|
||||
// Tech Option
|
||||
#[repr(i32)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum TechOption {
|
||||
None = 0,
|
||||
Random = 1,
|
||||
InPlace = 2,
|
||||
Roll = 3,
|
||||
Miss = 4,
|
||||
// Tech options
|
||||
bitflags! {
|
||||
pub struct TechFlags : u32 {
|
||||
const NO_TECH = 0b1;
|
||||
const ROLL = 0b10;
|
||||
const IN_PLACE = 0b100;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for TechOption {
|
||||
fn from(x: i32) -> Self {
|
||||
use TechOption::*;
|
||||
|
||||
match x {
|
||||
0 => None,
|
||||
1 => Random,
|
||||
2 => InPlace,
|
||||
3 => Roll,
|
||||
4 => Miss,
|
||||
_ => panic!("Invalid tech option {}", x),
|
||||
}
|
||||
}
|
||||
impl TechFlags {
|
||||
to_vec_impl!{TechFlags}
|
||||
}
|
||||
|
||||
/// Mash States
|
||||
|
@ -344,7 +339,7 @@ pub struct TrainingModpackMenu {
|
|||
pub mash_attack_state: Attack,
|
||||
pub follow_up: Action,
|
||||
pub ledge_state: LedgeOption,
|
||||
pub tech_state: TechOption,
|
||||
pub tech_state: TechFlags,
|
||||
pub mash_state: Mash,
|
||||
pub shield_state: Shield,
|
||||
pub defensive_state: Defensive,
|
||||
|
|
|
@ -10,8 +10,8 @@ pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpac
|
|||
left_stick: Direction::None,
|
||||
mash_attack_state: Attack::Nair,
|
||||
follow_up: Action::Nothing,
|
||||
ledge_state: LedgeOption::Random,
|
||||
tech_state: TechOption::Random,
|
||||
ledge_state: LedgeOption::all(),
|
||||
tech_state: TechFlags::all(),
|
||||
mash_state: Mash::None,
|
||||
shield_state: Shield::None,
|
||||
defensive_state: Defensive::Random,
|
||||
|
|
|
@ -6,6 +6,9 @@ mod common;
|
|||
mod hitbox_visualizer;
|
||||
mod training;
|
||||
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
|
||||
use crate::common::*;
|
||||
use training::combo::FRAME_ADVANTAGE;
|
||||
|
||||
|
|
|
@ -30,10 +30,11 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor
|
|||
let mut status = 0;
|
||||
let ledge_case: LedgeOption;
|
||||
|
||||
if MENU.ledge_state == LedgeOption::Random {
|
||||
ledge_case = (app::sv_math::rand(hash40("fighter"), 4) + 2).into();
|
||||
} else {
|
||||
ledge_case = MENU.ledge_state;
|
||||
let ledge_options = MENU.ledge_state.to_vec();
|
||||
match ledge_options.len() {
|
||||
0 => { ledge_case = LedgeOption::empty(); },
|
||||
1 => { ledge_case = ledge_options[0]; },
|
||||
_ => { ledge_case = *random_option(&ledge_options); }
|
||||
}
|
||||
|
||||
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 {
|
||||
LedgeOption::Jump => {
|
||||
LedgeOption::JUMP => {
|
||||
mash::buffer_menu_mash(module_accessor);
|
||||
}
|
||||
_ => mash::perform_defensive_option(),
|
||||
|
@ -62,7 +63,7 @@ pub unsafe fn get_command_flag_cat(
|
|||
return;
|
||||
}
|
||||
|
||||
if MENU.ledge_state == LedgeOption::None {
|
||||
if MENU.ledge_state == LedgeOption::empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,14 +35,6 @@ unsafe fn mod_handle_change_status(
|
|||
return;
|
||||
}
|
||||
|
||||
if MENU.tech_state == TechOption::None {
|
||||
return;
|
||||
}
|
||||
|
||||
if MENU.tech_state == TechOption::Miss {
|
||||
return;
|
||||
}
|
||||
|
||||
let status_kind_int = status_kind
|
||||
.try_get_int()
|
||||
.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
|
||||
|| status_kind_int == FIGHTER_STATUS_KIND_DAMAGE_FLY_REFLECT_D
|
||||
{
|
||||
match MENU.tech_state {
|
||||
TechOption::Random => {
|
||||
let random_statuses = vec![
|
||||
*FIGHTER_STATUS_KIND_DOWN,
|
||||
*FIGHTER_STATUS_KIND_PASSIVE,
|
||||
*FIGHTER_STATUS_KIND_PASSIVE_FB,
|
||||
];
|
||||
let states = MENU.tech_state.to_vec();
|
||||
let mut state = if states.is_empty() { TechFlags::empty() } else { states[0] };
|
||||
|
||||
let random_status_index =
|
||||
app::sv_math::rand(hash40("fighter"), random_statuses.len() as i32) as usize;
|
||||
if random_statuses[random_status_index] != FIGHTER_STATUS_KIND_DOWN {
|
||||
*status_kind = L2CValue::new_int(random_statuses[random_status_index] as u64);
|
||||
*unk = LUA_TRUE
|
||||
if states.len() > 1 {
|
||||
let idx = app::sv_math::rand(hash40("fighter"), states.len() as i32) as usize;
|
||||
state = states[idx];
|
||||
}
|
||||
}
|
||||
TechOption::InPlace => {
|
||||
|
||||
match state {
|
||||
TechFlags::IN_PLACE => {
|
||||
*status_kind = FIGHTER_STATUS_KIND_PASSIVE.as_lua_int();
|
||||
*unk = LUA_TRUE;
|
||||
}
|
||||
TechOption::Roll => {
|
||||
TechFlags::ROLL => {
|
||||
*status_kind = FIGHTER_STATUS_KIND_PASSIVE_FB.as_lua_int();
|
||||
*unk = LUA_TRUE;
|
||||
}
|
||||
|
@ -113,7 +99,7 @@ pub unsafe fn get_command_flag_cat(
|
|||
return;
|
||||
}
|
||||
|
||||
if MENU.tech_state == TechOption::None {
|
||||
if MENU.tech_state == TechFlags::empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -154,7 +140,7 @@ pub unsafe fn change_motion(
|
|||
return None;
|
||||
}
|
||||
|
||||
if MENU.tech_state == TechOption::None {
|
||||
if MENU.tech_state == TechFlags::empty() || MENU.tech_state == TechFlags::NO_TECH {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue