add character override cli flag

This commit is contained in:
Vivian Lim 2021-08-22 12:29:16 -07:00
parent 3e9a0cfc87
commit e65fdb92e2
2 changed files with 25 additions and 279 deletions

View File

@ -6,22 +6,27 @@ use failure::Fallible;
use ferretro_base::prelude::*;
use ferretro_recorder::{driver::{AnalogRequest, AnalogVector, Axes, Command, Driver, MemoryOverwriter}, emulator_runner::RecordedEmulator, inputs::Inputs};
pub fn dk_behavior(emu: Arc<Mutex<Pin<Box<RecordedEmulator<()>>>>>, mut driver: Driver) -> Result<(), SendError<Command>> {
pub fn dk_behavior(emu: Arc<Mutex<Pin<Box<RecordedEmulator<()>>>>>, mut driver: Driver, character_override: Option<u8>) -> Result<(), SendError<Command>> {
// Decide who we'll fight against
// everytthing after 0b is special characters.
// 0c: master hand
// 0d: metal mario
// 0e-19: polygon team
// 1a is giant dk
let mut random_char = rand::random::<u8>() % 0x1b;
if random_char > 0x0d && random_char < 0x1a { // if it picked a polygon, reroll - i want polygons to be a bit less likely than regular ones
random_char = rand::random::<u8>() % 0x1b
}
// let mut random_char = rand::random::<u8>() % 0x0d; // during dev I don't want polygons
let random_char = match character_override {
Some(char) => char,
None => {
// everytthing after 0b is special characters.
// 0c: master hand
// 0d: metal mario
// 0e-19: polygon team
// 1a is giant dk
let mut random_char = rand::random::<u8>() % 0x1b;
if random_char > 0x0d && random_char < 0x1a { // if it picked a polygon, reroll - i want polygons to be a bit less likely than regular ones
random_char = rand::random::<u8>() % 0x1b
}
// let mut random_char = rand::random::<u8>() % 0x0d; // during dev I don't want polygons
// let mut random_char = 0x0c; // force my hand
random_char
}
};
// let mut random_char = 0x0c; // force my hand
let is_master_hand = random_char == 0x0c;
if is_master_hand {

View File

@ -64,269 +64,6 @@ fn stateful_input_callback(emu: &mut RecordedEmulator<DKState>, port: u32, devic
}
}
fn dk_input_callback(emu: &mut RecordedEmulator<DKState>, port: u32, device: InputDeviceId, index: InputIndex) -> i16 {
match emu.emu_frame {
300..=320 => { // push start to get to title screen
match port {
0 => match device {
InputDeviceId::Joypad(button) => match button {
JoypadButton::Start => 1,
_ => 0
},
_ => 0
},
_ => 0
}
},
500..=550 => { // push start to get to menu
match port {
0 => match device {
InputDeviceId::Joypad(button) => match button {
JoypadButton::Start => 1,
_ => 0
},
_ => 0
},
_ => 0
}
},
650..=660 => { // d-pad down to pick VS mode
match port {
0 => match device {
InputDeviceId::Joypad(button) => match button {
JoypadButton::Down => 1,
_ => 0
},
_ => 0
},
_ => 0
}
},
750..=780 => { // a button to pick vs mode
match port {
0 => match device {
InputDeviceId::Joypad(button) => match button {
JoypadButton::B => 1,
_ => 0
},
_ => 0
},
_ => 0
}
},
850..=880 => { // a button for vs start
match port {
0 => match device {
InputDeviceId::Joypad(button) => match button {
JoypadButton::B => 1,
_ => 0
},
_ => 0
},
_ => 0
}
}, // wait about 200 frames for character select to show
1130..=1140 => { // move all control sticks into character select
match port {
0 | 1 => match device {
InputDeviceId::Analog(axis) => match axis {
AnalogAxis::X => 0x7FFF,
AnalogAxis::Y => -0x7FFF,
},
_ => 0
},
_ => 0
}
},
1150..=1170 => { // a button for p1 and p2 to select characters
match port {
0 | 1 => match device {
InputDeviceId::Joypad(button) => match button {
JoypadButton::B => 1,
_ => 0
},
_ => 0
},
_ => 0
}
},
1190..=1200 => { // start to go to stage select
match port {
0 => match device {
InputDeviceId::Joypad(button) => match button {
JoypadButton::Start => 1,
_ => 0
},
_ => 0
},
_ => 0
}
}, // wait ~200 frames for stage select
1400..=1430 => { // right to select sector z
match port {
0 => match device {
InputDeviceId::Joypad(button) => match button {
JoypadButton::Right => 1,
_ => 0
},
_ => 0
},
_ => 0
}
},
1450..=1460 => { // down to select sector z
// poke memory to make us be DK
let mut ram = emu.retro.get_memory(2);
ram[0xa4d28] = 0x02;
// and make the computer be a random character
// everytthing after 0b is special characters.
// 0c: master hand
// 0d: metal mario
// 0e-19: polygon team
// 1a is giant dk
ram[0xa4d9c] = rand::random::<u8>() % 0x1b;
if ram[0xa4d9c] > 0x0b { // if it picked a special character, reroll - i want special characters to be a bit less likely than regular ones
ram[0xa4d9c] = rand::random::<u8>() % 0x1b;
}
match port {
0 => match device {
InputDeviceId::Joypad(button) => match button {
JoypadButton::Down => 1,
_ => 0
},
_ => 0
},
_ => 0
}
},
1480..=1500 => { // confirm stage
match port {
0 => match device {
InputDeviceId::Joypad(button) => match button {
JoypadButton::B => 1,
_ => 0
},
_ => 0
},
_ => 0
}
},
1540..=1550 => { // start record
emu.discard_frames = false;
0
},
2000..=2100 => { // run in opposite directions
match port {
0 => match device {
InputDeviceId::Analog(axis) => match axis {
AnalogAxis::X => -0x7FFF,
AnalogAxis::Y => 0x0000,
},
_ => 0
},
1 => match device {
InputDeviceId::Analog(axis) => match axis {
AnalogAxis::X => 0x7FFF,
AnalogAxis::Y => 0x0000,
},
_ => 0
},
_ => 0
}
},
2130..=2135 => { // face each other
// poke memory to give DK's punch random power
let mut ram = emu.retro.get_memory(2);
ram[0x26bf84] = rand::random::<u8>() / 3;
match port {
0 => match device {
InputDeviceId::Analog(axis) => match axis {
AnalogAxis::X => 0x3000,
AnalogAxis::Y => 0x0000,
},
_ => 0
},
1 => match device {
InputDeviceId::Analog(axis) => match axis {
AnalogAxis::X => -0x3000,
AnalogAxis::Y => 0x0000,
},
_ => 0
},
_ => 0
}
},
2160..=2170 | 2180..=2190 => { // do the punch. tap b twice so we fire the punch immediately instead of charging
match port {
0 => match device {
InputDeviceId::Joypad(button) => match button {
JoypadButton::Y => 1,
_ => 0
},
_ => 0
},
_ => 0
}
},
2400..=2460 => { // taunt or crouch depending on whether it hit
// read opponent %, if it is greater than 0 we hit
let ram = emu.retro.get_memory(2);
let taunt = ram[0x26c024] > 0;
if taunt {
match port {
0 => match device {
InputDeviceId::Joypad(button) => match button {
JoypadButton::L => 1, // taunt
_ => 0
},
_ => 0
},
_ => 0
}
}
else {
emu.state.stay_crouched = true;
match port {
0 => match device {
InputDeviceId::Analog(axis) => match axis {
AnalogAxis::X => 0x0000,
AnalogAxis::Y => 0x6000, // crouch
},
_ => 0
},
1 => match device {
InputDeviceId::Joypad(button) => match button {
JoypadButton::L => 1, // Taunt
_ => 0
},
_ => 0
},
_ => 0
}
}
},
_ => {
if emu.state.stay_crouched {
match port {
0 => match device {
InputDeviceId::Analog(axis) => match axis {
AnalogAxis::X => 0x0000,
AnalogAxis::Y => 0x6000, // crouch
},
_ => 0
},
_ => 0
}
}
else {
0
}
}
}
}
#[derive(StructOpt)]
struct Opt {
/// Core module to use.
@ -344,6 +81,9 @@ struct Opt {
/// System directory, often containing BIOS files
#[structopt(short, long, parse(from_os_str))]
system: Option<PathBuf>,
/// Which character to render a video for
#[structopt(short, long)]
character: Option<u8>,
}
fn main() -> Fallible<()> {
@ -394,8 +134,9 @@ fn main() -> Fallible<()> {
());
let emu2 = emu.clone();
let character_override = opt.character.clone();
let driver_thread = thread::spawn(move || {
behavior::dk_behavior(emu2, driver);
behavior::dk_behavior(emu2, driver, character_override);
});
ferretro_recorder::emulator_runner::run_emulator(emu.clone(), paths, driver_channels).unwrap();
@ -441,7 +182,7 @@ fn main() -> Fallible<()> {
0x18 => "Polygon Jigglypuff",
0x19 => "Polygon Ness",
0x1a => "DK (big)",
_ => "???"
_ => "Master Hand"
}
};