1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-03-22 14:26:11 +00:00

Extract Shared Condition

This commit is contained in:
sidschingis 2020-06-13 22:33:49 +02:00
parent be16194528
commit ce865a70f2

View file

@ -10,66 +10,57 @@ static mut STICK_DIRECTION: Direction = Direction::None;
pub unsafe fn mod_get_stick_x( pub unsafe fn mod_get_stick_x(
module_accessor: &mut app::BattleObjectModuleAccessor, module_accessor: &mut app::BattleObjectModuleAccessor,
) -> Option<f32> { ) -> Option<f32> {
if !is_training_mode() { let angle: f64 = get_angle(module_accessor);
return None;
}
if !is_operation_cpu(module_accessor) {
return None;
}
let status_kind = StatusModule::status_kind(module_accessor);
if !status_kind == FIGHTER_STATUS_KIND_ESCAPE_AIR {
return None;
}
STICK_DIRECTION = MENU.di_state;
let mut angle: f64 = get_angle(STICK_DIRECTION);
if angle == ANGLE_NONE { if angle == ANGLE_NONE {
return None; return None;
} }
// If facing left, reverse angle
if PostureModule::lr(module_accessor) != FIGHTER_FACING_RIGHT {
angle -= PI;
}
Some(angle.cos() as f32) Some(angle.cos() as f32)
} }
pub unsafe fn mod_get_stick_y( pub unsafe fn mod_get_stick_y(
module_accessor: &mut app::BattleObjectModuleAccessor, module_accessor: &mut app::BattleObjectModuleAccessor,
) -> Option<f32> { ) -> Option<f32> {
if !is_training_mode() { let angle: f64 = get_angle(module_accessor);
return None;
}
if !is_operation_cpu(module_accessor) {
return None;
}
let status_kind = StatusModule::status_kind(module_accessor);
if !status_kind == FIGHTER_STATUS_KIND_ESCAPE_AIR {
return None;
}
STICK_DIRECTION = MENU.di_state;
let mut angle: f64 = get_angle(STICK_DIRECTION);
if angle == ANGLE_NONE { if angle == ANGLE_NONE {
return None; return None;
} }
Some(angle.sin() as f32)
}
unsafe fn get_angle(module_accessor: &mut app::BattleObjectModuleAccessor) -> f64 {
if !is_training_mode() {
return ANGLE_NONE;
}
if !is_operation_cpu(module_accessor) {
return ANGLE_NONE;
}
// Currently used for air dodge//Drift only
if !(is_airborne(module_accessor) && is_in_hitstun(module_accessor)) {
return ANGLE_NONE;
}
STICK_DIRECTION = MENU.di_state;
let mut angle: f64 = pick_angle(STICK_DIRECTION);
if angle == ANGLE_NONE {
return ANGLE_NONE;
}
// If facing left, reverse angle // If facing left, reverse angle
if PostureModule::lr(module_accessor) != FIGHTER_FACING_RIGHT { if PostureModule::lr(module_accessor) != FIGHTER_FACING_RIGHT {
angle -= PI; angle -= PI;
} }
Some(angle.sin() as f32) angle
} }
unsafe fn get_angle(direction: Direction) -> f64 { unsafe fn pick_angle(direction: Direction) -> f64 {
if direction == Direction::Random { if direction == Direction::Random {
let rand_direction = get_random_direction(); let rand_direction = get_random_direction();
return direction_to_angle(rand_direction); return direction_to_angle(rand_direction);