1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-24 10:54:16 +00:00

Move defensive_state from grouped constants to an enum

This commit is contained in:
jam1garner 2020-05-16 01:56:58 -04:00
parent eb03831d3c
commit cb3d829e03
4 changed files with 35 additions and 13 deletions

View file

@ -127,11 +127,33 @@ pub enum Shield {
// pub const std::vector<std::string> shield_items{"None", "Infinite", "Hold"}; // pub const std::vector<std::string> shield_items{"None", "Infinite", "Hold"};
// Defensive States // Defensive States
pub const RANDOM_DEFENSIVE: i32 = 1; #[repr(i32)]
pub const DEFENSIVE_SPOTDODGE: i32 = 2; #[derive(Debug, Clone, Copy, PartialEq)]
pub const DEFENSIVE_ROLL: i32 = 3; pub enum Defensive {
pub const DEFENSIVE_JAB: i32 = 4; None = 0,
pub const DEFENSIVE_SHIELD: i32 = 5; Random = 1,
Spotdodge = 2,
Roll = 3,
Jab = 4,
Shield = 5,
}
impl From<i32> for Defensive {
fn from(x: i32) -> Self {
use Defensive::*;
match x {
0 => None,
1 => Random,
2 => Spotdodge,
3 => Roll,
4 => Jab,
5 => Shield,
_ => panic!("Invalid mash state {}", x)
}
}
}
// pub const std::vector<std::string> defensive_items{"None", "Random", "Spotdodge", "Roll", "Jab", "Flash Shield"}; // pub const std::vector<std::string> defensive_items{"None", "Random", "Spotdodge", "Roll", "Jab", "Flash Shield"};
#[repr(C)] #[repr(C)]
@ -143,5 +165,5 @@ pub struct TrainingModpackMenu {
pub tech_state: i32, pub tech_state: i32,
pub mash_state: Mash, pub mash_state: Mash,
pub shield_state: Shield, pub shield_state: Shield,
pub defensive_state: i32, pub defensive_state: Defensive,
} }

View file

@ -13,7 +13,7 @@ pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpac
tech_state: RANDOM_TECH, tech_state: RANDOM_TECH,
mash_state: Mash::None, mash_state: Mash::None,
shield_state: Shield::None, shield_state: Shield::None,
defensive_state: RANDOM_DEFENSIVE, defensive_state: Defensive::Random,
}; };
pub static MENU: &'static mut consts::TrainingModpackMenu = unsafe { &mut MENU_STRUCT }; pub static MENU: &'static mut consts::TrainingModpackMenu = unsafe { &mut MENU_STRUCT };
@ -77,7 +77,7 @@ pub unsafe fn perform_defensive_option(
flag: &mut i32, flag: &mut i32,
) { ) {
match MENU.defensive_state { match MENU.defensive_state {
RANDOM_DEFENSIVE => { Defensive::Random => {
let random_cmds = vec![ let random_cmds = vec![
*FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE, *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE,
*FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE_F, *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE_F,
@ -89,15 +89,15 @@ pub unsafe fn perform_defensive_option(
app::sv_math::rand(hash40("fighter"), random_cmds.len() as i32) as usize; app::sv_math::rand(hash40("fighter"), random_cmds.len() as i32) as usize;
*flag |= random_cmds[random_cmd_index]; *flag |= random_cmds[random_cmd_index];
} }
DEFENSIVE_ROLL => { Defensive::Roll => {
if app::sv_math::rand(hash40("fighter"), 2) == 0 { if app::sv_math::rand(hash40("fighter"), 2) == 0 {
*flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE_F; *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE_F;
} else { } else {
*flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE_B; *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE_B;
} }
} }
DEFENSIVE_SPOTDODGE => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE, Defensive::Spotdodge => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE,
DEFENSIVE_JAB => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_N, Defensive::Jab => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_N,
_ => (), _ => (),
} }
} }

View file

@ -88,7 +88,7 @@ pub unsafe fn check_button_on(
if is_training_mode() && is_operation_cpu(module_accessor) { if is_training_mode() && is_operation_cpu(module_accessor) {
let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32; let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32;
let status = StatusModule::status_kind(module_accessor) as i32; let status = StatusModule::status_kind(module_accessor) as i32;
if MENU.defensive_state == DEFENSIVE_SHIELD if MENU.defensive_state == Defensive::Shield
&& should_perform_defensive_option(module_accessor, prev_status, status) && should_perform_defensive_option(module_accessor, prev_status, status)
{ {
return Some(true); return Some(true);

View file

@ -125,7 +125,7 @@ pub unsafe fn check_button_on(
if is_training_mode() && is_operation_cpu(module_accessor) { if is_training_mode() && is_operation_cpu(module_accessor) {
let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32; let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32;
let status = StatusModule::status_kind(module_accessor) as i32; let status = StatusModule::status_kind(module_accessor) as i32;
if MENU.defensive_state == DEFENSIVE_SHIELD if MENU.defensive_state == Defensive::Shield
&& should_perform_defensive_option(module_accessor, prev_status, status) && should_perform_defensive_option(module_accessor, prev_status, status)
{ {
return Some(true); return Some(true);