1
0
Fork 0
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:
astraycat 2020-08-09 22:32:49 -07:00 committed by GitHub
parent e7ec867581
commit 0388a08a16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 74 additions and 88 deletions

View file

@ -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

View file

@ -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,72 +118,63 @@ impl From<i32> for Attack {
} }
} }
// Ledge Option // bitflag helper function macro
#[repr(i32)] macro_rules! to_vec_impl {
#[derive(Debug, Copy, Clone, PartialEq)] ($e:ty) => {
pub enum LedgeOption { pub fn to_vec(&self) -> Vec::<$e> {
None = 0, let mut vec = Vec::<$e>::new();
Random = 1, let mut field = <$e>::from_bits_truncate(self.bits);
Neutral = 2, while !field.is_empty() {
Roll = 3, let flag = <$e>::from_bits(1u32 << field.bits.trailing_zeros()).unwrap();
Jump = 4, field -= flag;
Attack = 5, vec.push(flag);
} }
return vec;
impl From<i32> for LedgeOption {
fn from(x: i32) -> Self {
use LedgeOption::*;
match x {
0 => None,
1 => Random,
2 => Neutral,
3 => Roll,
4 => Jump,
5 => Attack,
_ => panic!("Invalid ledge option {}", x),
} }
} }
} }
// Ledge Option
bitflags! {
pub struct LedgeOption : u32
{
const NEUTRAL = 0b1;
const ROLL = 0b10;
const JUMP = 0b100;
const ATTACK = 0b1000;
}
}
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 { 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 {
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 /// Mash States
#[repr(i32)] #[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
@ -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,

View file

@ -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,

View file

@ -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;

View file

@ -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;
} }

View file

@ -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
} match state {
} TechFlags::IN_PLACE => {
TechOption::InPlace => {
*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;
} }