diff --git a/docs/design/macros.md b/docs/design/macros.md index 522ed19..ff99941 100644 --- a/docs/design/macros.md +++ b/docs/design/macros.md @@ -1913,6 +1913,64 @@ a door is taken the way the cartridge takes it, and the map graph says what the decoder, the reward catalog, the adapter version, the roles and the compatibility string are untouched. +### 12.30 A counter walked away from is not walked back to, a ball is bought with one button, and a closed bag is not the pad (2026-09-29, row 66) + +The operator restarted the live run from the rung-8 archive (VIRIDIAN CITY) to watch the fly shop, +buy Poké Balls and catch. On v0.6.5, 35 minutes in: `GO SHOP` done 33 times, `TALK` 5, `BUY BALL` +never dealt, `THROW BALL` 0, no catch. Three findings, two of them the pad. + +**`GO SHOP` and the way out were a ring.** Row 62 (12.26) deals a service walk whenever the +cartridge says the service is needed, whatever the ledgers say. When the fly stands at the counter +and does not use it, that is a ring by construction: `GO SHOP` from the street to the Viridian +clerk, `GO OUT` or `GO OBJECTIVE` back out of the door, and `GO SHOP` on the street's pad again, +because the bag still holds no ball. Reproduced with the connectome from a post-parcel checkpoint +of the Viridian mart (`survey-rank8-row66-viridian-mart`, saved by the offers survey): three laps in +eighteen brain seconds. A `GO SHOP` or `GO HEAL` that finishes facing the counter person now +records the building's counter (`TargetKey::Counter`, keyed by the building's map, because the +question is asked from the street, where none of the building's sprite slots means anything). For +the reached window the service walk toward that building is not dealt, from the street or inside. +That is 12.1's ledger doing for the service walk what it does for every other walk: a target +arrived at and faced is not walked to again at once. `TALK` at the counter, `HEAL` in a centre and +`BUY BALL` in a mart are unchanged by it. When the window closes the counter is a service again. + +**A ball is one button (the operator's decision).** Even without the ring the fly did not buy. +A purchase took four choices in a row at the counter: `TALK`, a press at the greeting, `CONFIRM` +on BUY, and `BUY BALL` on the list. With the connectome the fly walked to the clerk every time and +never once chose `TALK` there. So `BUY BALL` is now also the mart's `HEAL`. On the overworld pad +inside a mart, one press walks to the clerk, talks, advances the greeting until BUY / SELL / QUIT +is drawn, buys the first row, answers the price box as 12.26's purchase does, and is `done` when +the wallet drops. It is offered only while it can work: + +- in a mart whose first stock row is a Poké Ball (`geography::BALL_FIRST_MARTS`: Viridian, Pewter, + Cerulean, `data/items/marts.asm`). The script reads the stock once the counter is open and + refuses if the first row is anything else; +- while `service_needed` holds for the mart: no ball in the bag, 200 in the wallet, no Oak's parcel + (while it is carried the Viridian clerk's text table is the parcel's and he sells nothing). In + Viridian it is also not offered before Oak has the parcel (`EVENT_OAK_GOT_PARCEL`); +- with the clerk not in the blocked window. The talked and reached ledgers do not retire him, as + for the nurse. + +The fly still chooses it, as it chooses `HEAL`. The open-counter `BUY BALL` is unchanged. + +**After a catch the pad read the bag.** `wListMenuID` is written when a list opens and never +cleared. After a ball was thrown, every frame to the end of the battle read as an open battle bag: +"All right! WEEDLE was caught!", the Pokédex page, the nickname offer and the naming screen. The pad +was `BACK` and `THROW BALL`, a `THROW BALL` that threw nothing. Its A presses said YES to the +nickname and typed it, 6,900 frames from the catch to the battle's end on a stub survey. The bag +is now the bag only while its box, a `TextBoxBorder` at (4, 2)-(19, 12), is on screen: row 50's rule +for the move list. After the catch the pad is `NEXT`. `NEXT` answers the nickname offer with YES +and names the Pokémon with A's. Offering the offer's two answers inside a battle is a pad change +not made here. + +ROM tests: `row66_a_counter_walked_away_from_is_not_walked_back_to_by_go_shop` and +`row66_buy_ball_from_the_marts_floor_rings_up_a_ball` (`FLY_ROW66_MART_CHECKPOINT`), +`row66_after_a_catch_the_pad_is_not_the_bag_and_the_battle_ends` (`FLY_CATCH_CHECKPOINT`). Survey +numbers are in `infra/docs/macros-traps.md` row 66. + +Nothing ranks a button or presses for the fly. The walk back is withheld for a window, a purchase +is one offer, and the bag is read off the screen. The decoder, the reward catalog, the adapter +version, the roles and the compatibility string are untouched. + ## 13. Shops and Pokémon Centers (the operator, 2026-09-17: "refactor the shop macros. make it a ## priority to visit the shop at least once per area; make shop macros item purchases. same ## for the Pokécenter. heal should be a macro.") diff --git a/infra/docs/macros-traps.md b/infra/docs/macros-traps.md index 11bb093..0512066 100644 --- a/infra/docs/macros-traps.md +++ b/infra/docs/macros-traps.md @@ -3370,3 +3370,63 @@ gives these results: - **65b to 65d**: out, but seed 3 then stands outside the front door with an empty pad for the rest of the window (65e). - **branch**: all six leave with no empty pad, and three win the Cascade Badge. + +## 2026-09-29, row 66: shop, Poké Balls and catching from the rung-8 restart + +### What was found + +The operator restarted the live run from the rung-8 archive (VIRIDIAN CITY) on v0.6.5 to watch +shopping and catching. In the first 35 minutes: `GO SHOP` done 33, `TALK` 5, `BUY BALL` never +dealt, `THROW BALL` 0, no catch. The sequences after `GO SHOP` were `GO SHOP`, `GO OUT`, `GO SHOP`, +`GO OUT` (`docs/design/macros.md` 12.30). + +### Reproduction + +- `survey-rank8-row66-viridian-mart.checkpoint` (`FLY_ROW66_MART_CHECKPOINT`, not committed) was + saved by the offers survey (`FLY_PROBE_SAVE_MART=2a`, `FLY_PROBE_SAVE_AFTER=3000`) from + `survey-rank7-row62` on the frame the fly walked into the Viridian mart after delivering the + parcel: 793 in the wallet, no ball. +- The connectome from it (`trap_hunt`, `FLY_TRAP_LOG_MACROS=1`): `GO SHOP` from the door to the + clerk, `GO OBJECTIVE` out of the door, `GO SHOP` from the street. Three laps in 18 brain seconds. + `TALK` was on the pad at the counter every time and was never chosen. +- A catch on the stub survey (`FLY_PROBE_SCREEN_*` dumps): from "All right! WEEDLE was caught!" + to the end of the battle, 6,900 frames under a pad of `BACK` and `THROW BALL`. `THROW BALL`'s A + said YES to the nickname and typed AAAAAAAAAA. + +| # | trap | trigger | test | fix, or why it is left | +| --- | --- | --- | --- | --- | +| 66 | row 62's service walk is dealt again whenever the service is needed, with no window, so a fly that walks away from the counter is walked straight back | the Viridian mart after the parcel, no ball, money for one | `a_counter_the_fly_walked_away_from_is_not_walked_back_to_for_the_window`, `row66_a_counter_walked_away_from_is_not_walked_back_to_by_go_shop` | **fixed**: a completed `GO SHOP` / `GO HEAL` facing the counter records `TargetKey::Counter` on the building's map. The service walk toward it is withheld for the reached window | +| 66b | a purchase took four choices in a row at the counter (`TALK`, the greeting, `CONFIRM`, `BUY BALL`). The connectome never chose `TALK` there | any mart | `buy_ball_is_offered_from_a_marts_floor_only_while_a_ball_can_be_bought`, `row66_buy_ball_from_the_marts_floor_rings_up_a_ball` | **operator decision, built**: `BUY BALL` is also one button from the mart's floor, like `HEAL`. It walks to the clerk, talks, opens BUY, buys the first row and is done when paid. It is offered only in Viridian (after Oak has the parcel), Pewter and Cerulean, with no ball, 200 in the wallet, no parcel, and the clerk not blocked | +| 66c | `wListMenuID` outlives the battle bag, so every frame after a throw read as an open bag | a catch (the Pokédex page, the nickname, the naming screen) and the text after any throw or potion | `row66_after_a_catch_the_pad_is_not_the_bag_and_the_battle_ends`, the state unit test | **fixed**: the bag is the bag only while its box (4, 2)-(19, 12) is drawn | +| 66d | after a catch, `NEXT` says YES to the nickname offer and names the Pokémon with A's | every catch | -- | **left, named**: offering the box's two answers in a battle is a pad change for the operator | +| 66e | the connectome did not choose `THROW BALL` in any wild battle with a ball (35 decisions over seven battles, three runs) | Viridian Forest with a ball bought by 66b | -- | **left, the fly's**: dealt as designed (12.9). Whether to make throwing likelier is the operator's | +| 66f | whiteouts halve the wallet: 3,175 to 793 to 396 to 0 on one stub run before Pewter | early fights lost | -- | **left**: the cartridge's rule. It is why the restart rung matters | +| 66g | `rom_catch`'s `BALL` is the button's tag (`MB·BALL`), not its channel, so the lean sets a rate nobody reads | the test's drive | -- | **left, documented**: that drive is the one that catches from `FLY_CATCH_CHECKPOINT`. Both tests now retry from idle offsets, because one ball misses about two throws in three | + +### Before and after + +ROM tests (rom-env sourced): + +| test | v0.6.5 | branch | +| --- | --- | --- | +| `row66_a_counter_walked_away_from_is_not_walked_back_to_by_go_shop` (10,000 frames, the drive declines the counter) | 31 street `GO SHOP`s, 31 walks back in. **Fails** | 0 and 0. Passes | +| `row66_buy_ball_from_the_marts_floor_rings_up_a_ball` | `BUY BALL` never dealt on the floor, no ball. **Fails** | dealt, started, done. One ball, 793 to 593, at f491. Passes | +| `row66_after_a_catch_the_pad_is_not_the_bag_and_the_battle_ends` | `THROW BALL` dealt on 666 frames after the catch, pad `BACK`/`THROW BALL`. **Fails** | 0, pad `NEXT`, battle over 1,463 frames after the catch. Passes | + +With the connectome (`trap_hunt`, one sweep thread). `FLY_TRAP_SEED` seeds only the palette, and +three seeds from one checkpoint were byte-identical. So the runs vary the starting state: three +post-parcel Viridian mart entrances saved from stub seeds 1, 3 and 5, and the Pewter gym +(`survey-rank11-row59`, 1,606 in the wallet). A decision is a macro start whose pad held the +button. + +| run | brain min | counter `TALK` dealt / chosen | floor `BUY BALL` dealt / chosen / done | balls bought | `THROW BALL` dealt / chosen | +| --- | ---: | ---: | ---: | ---: | ---: | +| base, Viridian mart (s1 entrance) | 5 | 4 / 0 | -- | 0 | 0 / 0 | +| branch, Viridian mart (s1 entrance) | 5 | 1 / 0 | 2 / 0 / 0 | 0 | 0 / 0 | +| branch, Viridian mart (s3 entrance) | 5 | 3 / 0 | 3 / 1 / 1 | 1 (431 to 231) | 4 / 0 | +| branch, Viridian mart (s5 entrance) | 5 | 3 / 0 | 4 / 1 / 1 | 1 (1,587 to 1,387) | 16 / 0 | +| branch, Pewter gym, then the Pewter mart | 10 | 1 / 0 | 4 / 1 / 1 | 1 (1,606 to 1,406) | 15 / 0 | + +`TALK` at a counter: 0 of 12 decisions on either arm. The floor `BUY BALL`: chosen 3 of 13, and +done (paid) all 3 times. The ring: 4 mart entries in 16 brain seconds on base, one visit on the +branch. diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/cartridge.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/cartridge.rs index 1f98833..15622e2 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/cartridge.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/cartridge.rs @@ -629,6 +629,14 @@ pub trait MacroState: GameState { false } + /// Whether Oak has been given his parcel (`EVENT_OAK_GOT_PARCEL`). Until then the Viridian + /// clerk's text table is the parcel's and his counter sells nothing (row 66: `BUY BALL` from + /// the floor is not offered there before it). Defaulted to true, so a state that cannot read + /// the event flags withholds nothing on its account. + fn parcel_delivered(&mut self) -> bool { + true + } + /// Where the ladder's next unreached rung is, when the adapter's rung catalog knows. /// /// `None` leaves `GO OBJECTIVE` unbound, which is section 9's own fall-through: the plan's diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/palette.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/palette.rs index 31d0282..db0b40f 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/palette.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/palette.rs @@ -1064,7 +1064,8 @@ pub fn heal_goals(state: &mut dyn MacroState) -> Vec { /// /// - in a mart whose first stock row is a Poké Ball ([`geography::BALL_FIRST_MARTS`]); /// - while [`service_needed`] holds for the mart: no ball in the bag, the money for one, and no -/// Oak's parcel (the Viridian clerk's text table while it is carried sells nothing); +/// Oak's parcel (the Viridian clerk's text table while it is carried sells nothing) -- and in +/// Viridian not before Oak has the parcel at all ([`MacroState::parcel_delivered`]); /// - with the clerk reachable: the blocked window is kept, the talked and reached ledgers are not /// (a counter is a service), and the tile already facing him is a goal (no walk at all). /// @@ -1074,6 +1075,11 @@ pub fn floor_ball_goals(state: &mut dyn MacroState) -> Vec { if !geography::BALL_FIRST_MARTS.contains(&here) || !service_needed(state, Amenity::Mart) { return Vec::new(); } + // Before the parcel is even in the bag the Viridian counter is the parcel's too: the clerk's + // script hands it over on the fly's first visit, and sells nothing until Oak has it. + if here == super::super::maps::VIRIDIAN_MART && !state.parcel_delivered() { + return Vec::new(); + } person_aims(state, poke_sprite::CLERK, Ledgers::BlockedOnly, true) } diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/tests.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/tests.rs index b3558cf..4258eae 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/tests.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/tests.rs @@ -182,6 +182,8 @@ struct World { /// A frame at which the cartridge heals the party, which is what a Pokémon Center does while /// its text box is open (`docs/design/macros.md` section 13). heal_at: Option, + /// Oak has not been given the parcel yet (row 66); false in every fixture unless set. + parcel_undelivered: bool, /// Whether a text box is drawn on a scene that is not [`Scene::Dialog`] /// ([`MacroState::text_open`]). /// @@ -303,6 +305,7 @@ impl World { refused_items: BTreeSet::new(), switch: None, heal_at: None, + parcel_undelivered: false, box_open: false, prompt: false, price_after: None, @@ -880,6 +883,10 @@ impl MacroState for World { self.targets.reached(map, TargetKey::Counter) } + fn parcel_delivered(&mut self) -> bool { + !self.parcel_undelivered + } + fn refused_here(&mut self, slot: u8) -> bool { self.targets.refused(self.map, slot, self.player) } @@ -5877,6 +5884,10 @@ fn buy_ball_is_offered_from_a_marts_floor_only_while_a_ball_can_be_bought() { mart.bag = vec![(item::OAKS_PARCEL, 1)]; assert!(!on_the_pad(&mut mart, MacroKind::BuyBall), "carrying the parcel"); mart.bag = Vec::new(); + // ...or before the clerk has even handed it over: nothing to buy until Oak has it. + mart.parcel_undelivered = true; + assert!(!on_the_pad(&mut mart, MacroKind::BuyBall), "before the parcel"); + mart.parcel_undelivered = false; // The talked and reached ledgers do not retire a counter; the blocked window does. mart.talked.insert(TalkTarget::Sprite(1)); diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/state.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/state.rs index 366207a..958ca39 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/state.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/state.rs @@ -2339,6 +2339,12 @@ impl MacroState for PokeState<'_> { self.targets.reached(map, TargetKey::Counter) } + /// `EVENT_OAK_GOT_PARCEL`, bit 56 of `wEventFlags`. + fn parcel_delivered(&mut self) -> bool { + let bit = super::symbols::events::EVENT_OAK_GOT_PARCEL; + read(self.memory, ram::wEventFlags + (bit >> 3)) & (1 << (bit & 7)) != 0 + } + /// Where the ladder's next unreached rung is (`GO OBJECTIVE`). /// /// The adapter's [`crate::adapter::MapPlace`] in the executor's own types, which is the only