state: the battle bag is open only while its box is on screen
wListMenuID keeps ITEMLISTMENU after the list closes, so from a catch to the end of the battle (caught text, Pokedex page, nickname offer, naming screen) the pad read as the bag: BACK and THROW BALL, whose A presses typed the name. The bag now also needs its TextBoxBorder at (4,2)-(19,12). rom_catch: row66 test (THROW BALL dealt after the catch: base 666 frames, branch 0), and both tests retry from idle offsets because one ball misses about two throws in three and frame timing decides which.
This commit is contained in:
parent
9f2345dba7
commit
5269c2f142
3 changed files with 206 additions and 18 deletions
|
|
@ -119,6 +119,10 @@ pub mod poke {
|
||||||
/// four tall, then writes a horizontal run over its top-left corner and a `┘` over (10, 12).
|
/// four tall, then writes a horizontal run over its top-left corner and a `┘` over (10, 12).
|
||||||
/// Values rather than symbols, like `YES_NO_BOX`: this is a figure on screen, not a byte.
|
/// Values rather than symbols, like `YES_NO_BOX`: this is a figure on screen, not a byte.
|
||||||
pub const MOVE_LIST_BOX: (u16, u16, u16, u16) = (4, 12, 19, 17);
|
pub const MOVE_LIST_BOX: (u16, u16, u16, u16) = (4, 12, 19, 17);
|
||||||
|
/// The bag's own box in a battle (row 66): `DisplayListMenuID` draws a `TextBoxBorder` at
|
||||||
|
/// (4, 2), nine rows by fourteen, so its corners are (4, 2) and (19, 12). Surveyed on the
|
||||||
|
/// cartridge: whole on every frame the list is up, gone on the frame it closes.
|
||||||
|
pub const ITEM_LIST_BOX: (u16, u16, u16, u16) = (4, 2, 19, 12);
|
||||||
pub const MOVE_LIST_JOIN: u16 = 10;
|
pub const MOVE_LIST_JOIN: u16 = 10;
|
||||||
/// Where `MoveSelectionMenu` parks the shared cursor: row 12, column 5.
|
/// Where `MoveSelectionMenu` parks the shared cursor: row 12, column 5.
|
||||||
pub const MOVE_LIST_CURSOR_Y: u8 = 12;
|
pub const MOVE_LIST_CURSOR_Y: u8 = 12;
|
||||||
|
|
@ -631,12 +635,19 @@ pub fn battle(memory: &mut dyn MemoryReader) -> Option<Battle> {
|
||||||
BattleMenu::Moves { cursor: slot, count }
|
BattleMenu::Moves { cursor: slot, count }
|
||||||
} else if party_list(memory) {
|
} else if party_list(memory) {
|
||||||
BattleMenu::Party { cursor: cursor.current }
|
BattleMenu::Party { cursor: cursor.current }
|
||||||
} else if read(memory, ram::wListMenuID) == poke::ITEM_LIST_MENU {
|
} else if read(memory, ram::wListMenuID) == poke::ITEM_LIST_MENU && item_list_drawn(memory) {
|
||||||
// The bag, opened from the battle menu's ITEM entry. `DisplayListMenuID` keeps its
|
// The bag, opened from the battle menu's ITEM entry. `DisplayListMenuID` keeps its
|
||||||
// position in the same shared cursor every other menu uses, and the entry count is the
|
// position in the same shared cursor every other menu uses, and the entry count is the
|
||||||
// bag's own, so the scripts that reach into it (`ITEM`, `THROW BALL`) navigate by reading
|
// bag's own, so the scripts that reach into it (`ITEM`, `THROW BALL`) navigate by reading
|
||||||
// rather than by counting presses -- which is what section 4 requires of them and what
|
// rather than by counting presses -- which is what section 4 requires of them and what
|
||||||
// they could not do while this read as no list at all.
|
// they could not do while this read as no list at all.
|
||||||
|
//
|
||||||
|
// **And only while its box is on screen** (row 66), row 50's rule for the move list:
|
||||||
|
// `wListMenuID` is written when the list opens and never cleared, so after a ball was
|
||||||
|
// thrown every frame to the end of the battle -- "All right! WEEDLE was caught!", the
|
||||||
|
// Pokédex page, the nickname offer and the naming screen -- read as an open bag, the pad
|
||||||
|
// was `BACK` and `THROW BALL`, and the ball's A presses typed the nickname: 6,900 frames
|
||||||
|
// from the catch to the end of the battle, under a `THROW BALL` that threw nothing.
|
||||||
let count = bag(memory).len().min(usize::from(poke::BAG_CAPACITY));
|
let count = bag(memory).len().min(usize::from(poke::BAG_CAPACITY));
|
||||||
BattleMenu::Bag { cursor: cursor.current, count: u8::try_from(count).unwrap_or(0) }
|
BattleMenu::Bag { cursor: cursor.current, count: u8::try_from(count).unwrap_or(0) }
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1083,6 +1094,12 @@ fn two_option_box_drawn(memory: &mut dyn MemoryReader, cursor_x: u8, cursor_y: u
|
||||||
/// becomes a horizontal run and (10, 12) becomes the `┘` junction with the PP box above. The
|
/// becomes a horizontal run and (10, 12) becomes the `┘` junction with the PP box above. The
|
||||||
/// mimic and relearn menus draw at row 7 and never reach a battle's own turn. Read whole, like
|
/// mimic and relearn menus draw at row 7 and never reach a battle's own turn. Read whole, like
|
||||||
/// every other box in this module, because a single tile id is an ordinary character.
|
/// every other box in this module, because a single tile id is an ordinary character.
|
||||||
|
/// Whether the battle bag's list box is whole on screen ([`poke::ITEM_LIST_BOX`], row 66).
|
||||||
|
fn item_list_drawn(memory: &mut dyn MemoryReader) -> bool {
|
||||||
|
let (left, top, right, bottom) = poke::ITEM_LIST_BOX;
|
||||||
|
border_drawn(memory, left, top, right, bottom)
|
||||||
|
}
|
||||||
|
|
||||||
fn move_list_drawn(memory: &mut dyn MemoryReader) -> bool {
|
fn move_list_drawn(memory: &mut dyn MemoryReader) -> bool {
|
||||||
let (left, top, right, bottom) = poke::MOVE_LIST_BOX;
|
let (left, top, right, bottom) = poke::MOVE_LIST_BOX;
|
||||||
if screen_tile(memory, left, top) != poke::frame::HORIZONTAL
|
if screen_tile(memory, left, top) != poke::frame::HORIZONTAL
|
||||||
|
|
|
||||||
|
|
@ -382,6 +382,13 @@ fn a_battle_frame_with_a_cursor_accepting_input_is_the_flys_turn() {
|
||||||
let mut wram = Wram::overworld();
|
let mut wram = Wram::overworld();
|
||||||
battler(&mut wram);
|
battler(&mut wram);
|
||||||
wram.bag(&[(crate::pokemon_red::macros::cartridge::item::POTION, 2)]).set(ram::wListMenuID, poke::ITEM_LIST_MENU);
|
wram.bag(&[(crate::pokemon_red::macros::cartridge::item::POTION, 2)]).set(ram::wListMenuID, poke::ITEM_LIST_MENU);
|
||||||
|
// Row 66: the list byte alone is not the bag. It is never cleared, so it outlives the list
|
||||||
|
// into the rest of the battle -- after a ball, the catch, the Pokédex page, the nickname.
|
||||||
|
let fight = battle(&mut wram).unwrap();
|
||||||
|
assert_eq!(fight.menu, BattleMenu::None, "the list byte without the list's box on screen");
|
||||||
|
assert!(!fight.own_turn, "text after the bag closed is nobody's turn");
|
||||||
|
let (left, top, right, bottom) = poke::ITEM_LIST_BOX;
|
||||||
|
wram.draw_box(left, top, right, bottom);
|
||||||
let fight = battle(&mut wram).unwrap();
|
let fight = battle(&mut wram).unwrap();
|
||||||
assert_eq!(fight.menu, BattleMenu::Bag { cursor: 0, count: 1 });
|
assert_eq!(fight.menu, BattleMenu::Bag { cursor: 0, count: 1 });
|
||||||
assert!(fight.own_turn, "the battle bag is a cursor accepting input");
|
assert!(fight.own_turn, "the battle bag is a cursor accepting input");
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,15 @@ const SEED: u32 = 20_260_922;
|
||||||
const HOT: f64 = 16.0;
|
const HOT: f64 = 16.0;
|
||||||
const REST: f64 = 10.0;
|
const REST: f64 = 10.0;
|
||||||
/// `THROW BALL`'s channel (`pokemon_red::macros::palette`).
|
/// `THROW BALL`'s channel (`pokemon_red::macros::palette`).
|
||||||
|
///
|
||||||
|
/// Row 66's note: this is the button's *tag*; its channel is `macro_throw_ball`
|
||||||
|
/// ([`THROW_BALL_CHANNEL`]), so the lean below sets a rate the decoder does not read and the drive
|
||||||
|
/// in a wild battle is the calibrated tie. It is kept as it is because that drive is the one that
|
||||||
|
/// catches from the forest checkpoint (with the real channel hot the checkpoint's one ball misses
|
||||||
|
/// on this frame timing), and the row 66 test reuses it up to the catch.
|
||||||
const BALL: &str = "MB·BALL";
|
const BALL: &str = "MB·BALL";
|
||||||
|
/// `THROW BALL`'s channel as the macro layer binds it.
|
||||||
|
const THROW_BALL_CHANNEL: &str = "macro_throw_ball";
|
||||||
/// Frames the stub leans on one channel before the rotation moves on, the shape of the real
|
/// Frames the stub leans on one channel before the rotation moves on, the shape of the real
|
||||||
/// group's hysteresis-then-fatigue rotation.
|
/// group's hysteresis-then-fatigue rotation.
|
||||||
const BURST_FRAMES: u32 = 24;
|
const BURST_FRAMES: u32 = 24;
|
||||||
|
|
@ -190,9 +198,9 @@ fn a_catch_on_the_cartridge_pays_the_catch_rule_once_with_the_species_in_its_lab
|
||||||
eprintln!("skipped: no FLY_CATCH_CHECKPOINT");
|
eprintln!("skipped: no FLY_CATCH_CHECKPOINT");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let mut run = Run::resume(&rom, &checkpoint);
|
let balls = Run::resume(&rom, &checkpoint).balls();
|
||||||
let balls = run.balls();
|
|
||||||
if balls == 0 {
|
if balls == 0 {
|
||||||
|
let run = Run::resume(&rom, &checkpoint);
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"skipped: the checkpoint's bag holds no ball (map {:#04x}). `BUY BALL` can buy one \
|
"skipped: the checkpoint's bag holds no ball (map {:#04x}). `BUY BALL` can buy one \
|
||||||
inside a mart; point FLY_CATCH_CHECKPOINT at a state that already has one.",
|
inside a mart; point FLY_CATCH_CHECKPOINT at a state that already has one.",
|
||||||
|
|
@ -200,12 +208,29 @@ fn a_catch_on_the_cartridge_pays_the_catch_rule_once_with_the_species_in_its_lab
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
eprintln!("bag holds {balls} balls; map {:#04x}", run.adapter.map_id().unwrap_or(u32::MAX));
|
eprintln!("bag holds {balls} balls");
|
||||||
|
|
||||||
// Twenty brain minutes is generous for a forest checkpoint: the live run threw 28 balls in
|
// Five brain minutes per attempt is generous for a forest checkpoint: the live run threw 28
|
||||||
// its first Viridian Forest session (`pokemon_red::macros::palette`).
|
// balls in its first Viridian Forest session (`pokemon_red::macros::palette`). An attempt
|
||||||
let budget = 20 * 60 * 60;
|
// starts after `5 * attempt` frames with nothing pressed, so each one meets the wild battle,
|
||||||
let mut battles = 0u32;
|
// and the ball meets the random number, on a different frame (row 66): one ball misses about
|
||||||
|
// two throws in three, and which throw a checkpoint's one ball is depends on frame timing
|
||||||
|
// that any change to the pad moves.
|
||||||
|
let budget = 5 * 60 * 60;
|
||||||
|
let mut battles;
|
||||||
|
let mut attempt = 0u32;
|
||||||
|
let mut run = loop {
|
||||||
|
let mut run = Run::resume(&rom, &checkpoint);
|
||||||
|
for _ in 0..attempt * 5 {
|
||||||
|
run.ms += MS_PER_FRAME;
|
||||||
|
run.frame += 1;
|
||||||
|
let evaluated = run
|
||||||
|
.legacy
|
||||||
|
.stub_advance(Some(&mut run.layer), &mut run.gb, &mut run.adapter, run.ms)
|
||||||
|
.expect("a frame should complete");
|
||||||
|
run.payouts.extend(evaluated.rewards);
|
||||||
|
}
|
||||||
|
battles = 0;
|
||||||
let mut was_in_battle = false;
|
let mut was_in_battle = false;
|
||||||
for _ in 0..budget {
|
for _ in 0..budget {
|
||||||
run.step();
|
run.step();
|
||||||
|
|
@ -218,6 +243,12 @@ fn a_catch_on_the_cartridge_pays_the_catch_rule_once_with_the_species_in_its_lab
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !run.catches().is_empty() || attempt == 23 {
|
||||||
|
break run;
|
||||||
|
}
|
||||||
|
eprintln!("attempt {attempt}: no catch ({battles} wild battles, {} balls left)", run.balls());
|
||||||
|
attempt += 1;
|
||||||
|
};
|
||||||
|
|
||||||
let catches = run.catches();
|
let catches = run.catches();
|
||||||
assert!(
|
assert!(
|
||||||
|
|
@ -255,3 +286,136 @@ fn a_catch_on_the_cartridge_pays_the_catch_rule_once_with_the_species_in_its_lab
|
||||||
// sets the bit the `species` rule reads, whether or not it was new to this run.
|
// sets the bit the `species` rule reads, whether or not it was new to this run.
|
||||||
assert!(run.balls() < balls, "a ball was spent");
|
assert!(run.balls() < balls, "a ball was spent");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// What one drive from the checkpoint saw after its catch.
|
||||||
|
struct AfterCatch {
|
||||||
|
caught_at: u32,
|
||||||
|
ended_at: u32,
|
||||||
|
/// Frames between the catch and the battle's end on which `THROW BALL` was on the pad.
|
||||||
|
ball_dealt: u32,
|
||||||
|
/// Every pad the fly could decide on in that stretch.
|
||||||
|
pads: std::collections::BTreeSet<Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One drive: `idle` frames with nothing pressed first (so each attempt reaches the wild battle
|
||||||
|
/// on a different frame, and the ball meets a different random number), then the first test's
|
||||||
|
/// drive up to the catch, then the pad's own buttons in turn. `None` when no ball kept anything
|
||||||
|
/// within the budget: one ball in the bag misses about two throws in three.
|
||||||
|
fn drive_past_a_catch(rom: &[u8], checkpoint: &flysim::store::Checkpoint, idle: u32) -> Option<AfterCatch> {
|
||||||
|
let mut run = Run::resume(rom, checkpoint);
|
||||||
|
for _ in 0..idle {
|
||||||
|
run.ms += MS_PER_FRAME;
|
||||||
|
run.frame += 1;
|
||||||
|
let evaluated = run
|
||||||
|
.legacy
|
||||||
|
.stub_advance(Some(&mut run.layer), &mut run.gb, &mut run.adapter, run.ms)
|
||||||
|
.expect("a frame should complete");
|
||||||
|
run.payouts.extend(evaluated.rewards);
|
||||||
|
}
|
||||||
|
let budget = 5 * 60 * 60;
|
||||||
|
let mut caught_at: Option<u32> = None;
|
||||||
|
let mut ball_dealt = 0u32;
|
||||||
|
let mut pads = std::collections::BTreeSet::new();
|
||||||
|
let mut hold = 0usize;
|
||||||
|
for frame in 0..budget {
|
||||||
|
let bound = run.layer.bound_channels();
|
||||||
|
let hot = if caught_at.is_none() {
|
||||||
|
if run.in_wild_battle() {
|
||||||
|
Some(BALL.to_string())
|
||||||
|
} else {
|
||||||
|
let slot = (run.frame / BURST_FRAMES) as usize % run.channels.len();
|
||||||
|
Some(run.channels[slot].to_string())
|
||||||
|
}
|
||||||
|
} else if bound.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
if frame % BURST_FRAMES == 0 {
|
||||||
|
hold += 1;
|
||||||
|
}
|
||||||
|
Some(bound[hold % bound.len()].clone())
|
||||||
|
};
|
||||||
|
if caught_at.is_some() {
|
||||||
|
if bound.iter().any(|channel| channel == THROW_BALL_CHANNEL) {
|
||||||
|
ball_dealt += 1;
|
||||||
|
}
|
||||||
|
if run.layer.running().is_none() && !bound.is_empty() {
|
||||||
|
pads.insert(bound.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let active = run.decoder.decode_bound(&rates(hot.as_deref()), run.ms, false, None, Some(&bound));
|
||||||
|
run.legacy.execute(Some(&mut run.layer), &active, 0, run.ms, &mut run.gb, &run.adapter);
|
||||||
|
run.ms += MS_PER_FRAME;
|
||||||
|
run.frame += 1;
|
||||||
|
let evaluated = run
|
||||||
|
.legacy
|
||||||
|
.stub_advance(Some(&mut run.layer), &mut run.gb, &mut run.adapter, run.ms)
|
||||||
|
.expect("a frame should complete");
|
||||||
|
run.payouts.extend(evaluated.rewards);
|
||||||
|
if caught_at.is_none() && run.byte(ram::wCapturedMonSpecies) != 0 {
|
||||||
|
caught_at = Some(frame);
|
||||||
|
}
|
||||||
|
if let Some(caught_at) = caught_at
|
||||||
|
&& run.byte(ram::wIsInBattle) == 0
|
||||||
|
{
|
||||||
|
assert!(!run.catches().is_empty(), "the catch pays at the battle's end");
|
||||||
|
return Some(AfterCatch { caught_at, ended_at: frame, ball_dealt, pads });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert!(caught_at.is_none(), "a battle still running {budget} frames after its catch");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Row 66: once a ball has kept a Pokémon, nothing to the end of the battle is the bag.
|
||||||
|
///
|
||||||
|
/// After the throw `wListMenuID` still says `ITEMLISTMENU` -- it is written when a list opens and
|
||||||
|
/// never cleared -- so on v0.6.5 every frame from "All right! … was caught!" through the Pokédex
|
||||||
|
/// page, the nickname offer and the naming screen read as an open battle bag. The pad was `BACK`
|
||||||
|
/// and `THROW BALL`, a `THROW BALL` that threw nothing and whose A presses typed the nickname;
|
||||||
|
/// driven from the rung-8 survey checkpoint the battle took 6,900 frames to end after the catch.
|
||||||
|
///
|
||||||
|
/// The drive after the catch leans on the pad's own buttons in turn (not the whole channel
|
||||||
|
/// list), so what it measures is what the pad offers, not how often a rotation over every channel
|
||||||
|
/// lands on it.
|
||||||
|
#[test]
|
||||||
|
fn row66_after_a_catch_the_pad_is_not_the_bag_and_the_battle_ends() {
|
||||||
|
let Some(rom) = rom() else {
|
||||||
|
eprintln!("skipped: FLY_ROM is not set");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let Some(checkpoint) = checkpoint() else {
|
||||||
|
eprintln!("skipped: no FLY_CATCH_CHECKPOINT");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if Run::resume(&rom, &checkpoint).balls() == 0 {
|
||||||
|
eprintln!("skipped: the checkpoint's bag holds no ball");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let after = (0..24)
|
||||||
|
.find_map(|attempt| {
|
||||||
|
let after = drive_past_a_catch(&rom, &checkpoint, attempt * 5);
|
||||||
|
if after.is_none() {
|
||||||
|
eprintln!("attempt {attempt}: the ball missed");
|
||||||
|
}
|
||||||
|
after
|
||||||
|
})
|
||||||
|
.expect("one of 24 attempts should keep a Pokémon");
|
||||||
|
eprintln!(
|
||||||
|
"caught at f{}, battle over at f{} ({} frames); THROW BALL dealt on {} of them; pads {:?}",
|
||||||
|
after.caught_at,
|
||||||
|
after.ended_at,
|
||||||
|
after.ended_at - after.caught_at,
|
||||||
|
after.ball_dealt,
|
||||||
|
after.pads
|
||||||
|
);
|
||||||
|
assert_eq!(after.ball_dealt, 0, "THROW BALL on the pad after the catch: {:?}", after.pads);
|
||||||
|
assert!(
|
||||||
|
after.pads.iter().all(|pad| !pad.iter().any(|channel| channel == "macro_back")),
|
||||||
|
"BACK on the pad after the catch, with no list up: {:?}",
|
||||||
|
after.pads
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
after.ended_at - after.caught_at < 3_000,
|
||||||
|
"the battle took {} frames to end after the catch",
|
||||||
|
after.ended_at - after.caught_at
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue