1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-01-31 22:47:25 +00:00

Add Bitflag Macro (#135)

get_random
This commit is contained in:
sidschingis 2020-08-14 19:35:57 +02:00 committed by GitHub
parent 8feab4cf17
commit 12807258be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 26 deletions

View file

@ -129,6 +129,25 @@ macro_rules! to_vec_impl {
}
}
macro_rules! get_random_impl {
($e:ty) => {
pub fn get_random(&self) -> $e {
let options = self.to_vec();
match options.len() {
0 => {
return <$e>::empty();
}
1 => {
return options[0];
}
_ => {
return *random_option(&options);
}
}
}
}
}
// Ledge Option
bitflags! {
pub struct LedgeOption : u32
@ -140,7 +159,7 @@ bitflags! {
}
}
pub unsafe fn random_option<T>(arg: &Vec<T>) -> &T {
pub fn random_option<T>(arg: &Vec<T>) -> &T {
return &arg[get_random_int(arg.len() as i32) as usize];
}
@ -155,6 +174,7 @@ impl LedgeOption {
})
}
to_vec_impl! {LedgeOption}
get_random_impl! {LedgeOption}
}
// Tech options
@ -169,6 +189,7 @@ bitflags! {
impl TechFlags {
to_vec_impl! {TechFlags}
get_random_impl! {TechFlags}
}
/// Mash States

View file

@ -24,20 +24,7 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor
}
let mut status = 0;
let ledge_case: LedgeOption;
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);
}
}
let ledge_case: LedgeOption = MENU.ledge_state.get_random();
if let Some(new_status) = ledge_case.into_status() {
status = new_status;

View file

@ -45,17 +45,7 @@ unsafe fn mod_handle_change_status(
if status_kind_int == FIGHTER_STATUS_KIND_DOWN
|| status_kind_int == FIGHTER_STATUS_KIND_DAMAGE_FLY_REFLECT_D
{
let states = MENU.tech_state.to_vec();
let mut state = if states.is_empty() {
TechFlags::empty()
} else {
states[0]
};
if states.len() > 1 {
let idx = get_random_int(states.len() as i32) as usize;
state = states[idx];
}
let state: TechFlags = MENU.tech_state.get_random();
match state {
TechFlags::IN_PLACE => {