Merge main into port/gpu-02
This commit is contained in:
commit
5dad5b3cd7
24 changed files with 1087 additions and 13 deletions
|
|
@ -1077,3 +1077,29 @@ report their cursor (and its `max`) as the entry the same way. The offset is add
|
||||||
list is on screen, because the byte outlives every list. Purchases still use only the first three
|
list is on screen, because the byte outlives every list. Purchases still use only the first three
|
||||||
rows (`MART_CURSOR_ROWS`, section 7).
|
rows (`MART_CURSOR_ROWS`, section 7).
|
||||||
|
|
||||||
|
## 17. The hidden-event tables (2026-10-02, `docs/design/macros.md` 12.35)
|
||||||
|
|
||||||
|
Row 73. Two ROM tables, read through `MemoryReader::read_rom` from the cartridge image the process
|
||||||
|
already holds, never through the bus and never by switching banks. Pinned the way
|
||||||
|
`ItemUsePtrTable` is, and read back from the code that uses them by
|
||||||
|
`row73_the_hidden_event_table_is_the_cartridges_and_bills_pc_is_in_it` (FLY_ROM).
|
||||||
|
|
||||||
|
| name | where | what reads it |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `HiddenEventMaps` | `$11:$6A40` | one map id per byte to a `$ff` (85 maps at the pinned commit); the operand of `CheckForHiddenEvent`'s `ld hl, HiddenEventMaps`, followed by `ld a, [hli] / ld b, a / cp $ff` |
|
||||||
|
| `HiddenEventPointers` | `$11:$6A96` | one little-endian pointer per map of the list above, into the same bank; the operand of the routine's `ld hl, HiddenEventPointers`, followed by `add hl, de` |
|
||||||
|
|
||||||
|
Both are in `SECTION "Hidden Events Core"`, which `layout.link` places in bank `$11`. Each map's
|
||||||
|
list is six bytes an entry to a `$ff` (`hidden_event`): y, x, the routine's argument, and the
|
||||||
|
routine as `dba` (bank, then a little-endian address). The coordinates are in the same tile space as
|
||||||
|
`wXCoord`/`wYCoord`, like a sign's.
|
||||||
|
|
||||||
|
**`state::hidden_events`** answers the current map's entries as `HiddenEvent { x, y, index,
|
||||||
|
facing }`: `index` is the entry's position in the map's list, which is how `wHiddenEventIndex`
|
||||||
|
counts and the talked ledger's key (`TalkTarget::Hidden`); `facing` is the argument when it is a
|
||||||
|
`SPRITE_FACING_*` value (`$00`, `$04`, `$08`, `$0C`), the side a routine such as `BillsHousePC`
|
||||||
|
checks. It answers nothing for a map list with no end within 128 entries or an id above `$f7`, a
|
||||||
|
pointer outside `$4000..$8000`, a list longer than 64 entries (the Game Corner's 48 are the longest), a tile off the loaded map or a
|
||||||
|
routine address at `$8000` or above. Bill's house (`$58`) has one entry: (1, 4), argument `$04`,
|
||||||
|
`BillsHousePC` at `$07:$6B6E`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2155,6 +2155,94 @@ throws),
|
||||||
`row71_a_ball_past_the_bags_window_is_thrown` (`FLY_ROW71_CHECKPOINT`, the live trap) and
|
`row71_a_ball_past_the_bags_window_is_thrown` (`FLY_ROW71_CHECKPOINT`, the live trap) and
|
||||||
`row71_the_list_scroll_offset_is_where_the_cartridge_reads_it` (FLY_ROM).
|
`row71_the_list_scroll_offset_is_where_the_cartridge_reads_it` (FLY_ROM).
|
||||||
|
|
||||||
|
### 12.35 An errand is its people, then its things, and a hidden event is a thing (2026-10-02, row 73)
|
||||||
|
|
||||||
|
Live on v0.7.5, rung 15 (NUGGET BRIDGE), Route 24/25. Scout B3 measured it from the live
|
||||||
|
checkpoint on six seeds (2.8 brain hours): `GO ROUTE` walked the fly into Bill's house, and inside
|
||||||
|
it `GO OBJECTIVE` or `GO OUT` walked it straight back out, 30 to 60 times per ten brain minutes.
|
||||||
|
`GO NPC` was chosen 0 times in about 600 starts in the house, and new tiles stopped (2527 to 2531
|
||||||
|
in 35 minutes). Rung 16 (MET BILL, `EVENT_GOT_SS_TICKET`) was never earned.
|
||||||
|
|
||||||
|
- **The place was the route.** `RUNG_PLACES[16]` was `at(ROUTE_25)`, because the house's id was
|
||||||
|
not derived. A fly on Route 25 was already "there", so inside the house `GO OBJECTIVE` was an
|
||||||
|
exit into the objective's own map, which is the same door as `GO OUT`. That is row 29's lab loop
|
||||||
|
again, one rung later.
|
||||||
|
- **The rung is an errand, not a conversation.** `scripts/BillsHouse.asm`: Bill (a Pokémon, a
|
||||||
|
person sprite) asks for help and walks into the teleporter, the cartridge hides his sprite; the
|
||||||
|
cell separator is started from the PC at (1, 4), pressed facing up; Bill then steps out of the
|
||||||
|
machine as a second sprite and hands over the ticket. Two people and a thing, in that order.
|
||||||
|
- **The PC is a hidden event.** `wNumSigns` is 0 in the house and the only sprite is Bill: the PC
|
||||||
|
is an entry of the cartridge's own hidden-event table (`data/events/hidden_events.asm`), which
|
||||||
|
`CheckForHiddenEvent` searches on every A in the overworld. No macro could aim at it and `TALK`
|
||||||
|
was never dealt in front of it, so even a fly that talked to Bill could not earn the rung.
|
||||||
|
|
||||||
|
What changed, all of it knowledge inside macros:
|
||||||
|
|
||||||
|
- **`PlaceKind::Errand`.** Rung 16's place is `errand(BILLS_HOUSE)` (`$58`, confirmed by Route
|
||||||
|
25's warp table and by the hidden-event map list). An errand's targets are the room's people,
|
||||||
|
drawn or off the screen, and once none is left untalked, its things: objects, signs and hidden
|
||||||
|
events. No step is named anywhere. The cartridge shows and hides the people as the errand moves
|
||||||
|
on, the talked ledger records what has been had, and what is left is the next step. People come
|
||||||
|
first because a thing pressed out of turn is in the talked ledger for the session: Bill's PC
|
||||||
|
pressed before he has asked prints the monitor and does nothing, and a PC recorded as talked to
|
||||||
|
would never be the next step again. Everything 12.5 and 12.22 give a person place applies: the
|
||||||
|
ways out are withheld while a target waits, `GO OBJECTIVE` aims at the four sides, facing a
|
||||||
|
target is the arrival and `TALK` is the press; the blocked ledger is the escape hatch.
|
||||||
|
- **Hidden events are read from the cartridge's table, not written down.** `state::hidden_events`
|
||||||
|
walks `HiddenEventMaps` and `HiddenEventPointers` in ROM bank `$11` through
|
||||||
|
`MemoryReader::read_rom`, the same read the move and item tables use: no WRAM is written and the
|
||||||
|
mapper's bank register is not touched. The two addresses are pinned from the operands of
|
||||||
|
`CheckForHiddenEvent`'s own `ld hl` instructions and checked on the cartridge
|
||||||
|
(`macros-wram.md` section 17); every read checks the table's shape and answers nothing for a
|
||||||
|
table that is not the one the disassembly describes, which narrows and never invents a tile. A
|
||||||
|
hard-coded `(1, 4)` would have been a number nobody can check from the running game; the table is
|
||||||
|
what the cartridge itself consults when the A is pressed.
|
||||||
|
- **A hidden event is only ever the errand's next step.** It is in `objective_targets` for an
|
||||||
|
errand and in `facing_target` (so `TALK` is dealt) only while it is that step. It is not added to
|
||||||
|
`GO ITEM`, `GO NPC` or `TALK` anywhere else. The table holds every PC, poster, trash can,
|
||||||
|
bookshelf and hidden item in Kanto; making them general targets would add a walk to most
|
||||||
|
buildings' pads and an entry to the talked ledger for each, which is a change to what the fly is
|
||||||
|
offered everywhere and not a fix for this trap. The day that is wanted it is one line in
|
||||||
|
`path::interactable_targets`, and it needs its own survey.
|
||||||
|
- **A hidden event's side.** Where the entry's argument is a `SPRITE_FACING_*` value it is the side
|
||||||
|
the routine checks before it does anything (`BillsHousePC` returns unless the player faces up),
|
||||||
|
so the walk's one aim is the tile on that side and only facing it from there is the arrival and
|
||||||
|
`TALK`'s precondition. An argument that is an item or a text id and happens to equal a facing
|
||||||
|
value only narrows the approach.
|
||||||
|
|
||||||
|
The fly still chooses every press: `GO OBJECTIVE` to walk, `TALK` to press A, `YES`, `NO` or
|
||||||
|
`NEXT` in Bill's boxes. Nothing presses for it, no button is added to any pad, and the readout, the
|
||||||
|
catalog, the adapter and the compatibility string are unchanged. What the scene deals inside the
|
||||||
|
house is narrower than before, not wider: the ways out leave the pad while the errand waits.
|
||||||
|
|
||||||
|
**The road after the ticket (the third trap).** With the ticket the objective is rung 17,
|
||||||
|
Vermilion, south through Cerulean. Cerulean's ground is in three pieces, not two: the town's ends at
|
||||||
|
row 28 (the gap at (16, 28) opens onto a wall and the trainer-tips sign), and the south of the map,
|
||||||
|
the road to Route 5 and the east edge onto Route 9 are reached through the trashed house (`$3e`),
|
||||||
|
in by its front door at (27, 11) and out by the hole in its back wall onto (27, 9) in the Rocket's
|
||||||
|
yard. Scout B3 flooded the grid: 378 of the map's 801 walkable tiles are the town's. The house was
|
||||||
|
off the map graph, so `GO OBJECTIVE` aimed at ground the town cannot reach (`blocked` at (17, 28))
|
||||||
|
and the fly rang between the town and its houses (0 of 6 seeds past row 28 in 43 brain minutes
|
||||||
|
each). The house is now on the graph and the south is `SPLIT`'s third piece of Cerulean, so the
|
||||||
|
objective walks into the house and out through the hole. Before the ticket a guard stands on the
|
||||||
|
tile in front of the door (`TOGGLE_CERULEAN_GUARD_2`, (27, 12)), which the ticket's own script hides; the objective only
|
||||||
|
points south after the ticket.
|
||||||
|
|
||||||
|
**Not fixed, predicted:** the road from Route 5 to Vermilion on the graph is Route 5, Saffron,
|
||||||
|
Route 6, as plain map edges. The cartridge's gate houses are guarded until the guard's drink is
|
||||||
|
given, and the way the game means is the Underground Path, whose houses are off the graph. No run
|
||||||
|
has reached Route 5's gate yet; it needs its own checkpoint and row.
|
||||||
|
|
||||||
|
Tests: `an_errand_is_its_people_first_and_the_room_is_not_left_while_one_is_waiting`,
|
||||||
|
`a_hidden_event_is_the_errands_next_step_once_no_person_is_left_and_it_is_faced_from_its_side`,
|
||||||
|
`a_hidden_event_is_nobody_elses_target`, `the_road_south_out_of_cerulean_is_through_the_trashed_house`,
|
||||||
|
and on the cartridge `row73_the_hidden_event_table_is_the_cartridges_and_bills_pc_is_in_it`,
|
||||||
|
`row73_the_fly_earns_the_ss_ticket_from_inside_the_ring_at_bills_door`,
|
||||||
|
`row73_the_cell_separator_pc_is_pressed_and_bill_hands_over_the_ticket`,
|
||||||
|
`row73_the_fly_walks_from_the_live_route_25_checkpoint_to_the_ss_ticket`,
|
||||||
|
`row73_the_objective_south_of_cerulean_is_the_trashed_houses_two_doors` and
|
||||||
|
`row73_the_fly_takes_the_trashed_house_south_to_route_5`.
|
||||||
|
|
||||||
## 13. Shops and Pokémon Centers (the operator, 2026-09-17: "refactor the shop macros. make it a
|
## 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
|
## 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.")
|
## for the Pokécenter. heal should be a macro.")
|
||||||
|
|
|
||||||
|
|
@ -1024,3 +1024,7 @@ median; a two-fly transition near 10 to 12 ms at the median in every execution m
|
||||||
is unchanged until each is switched on with its rollback. Also: the multi-seed behavioural
|
is unchanged until each is switched on with its rollback. Also: the multi-seed behavioural
|
||||||
scorecard (nightly), two stale ROM tests fixed and every ROM suite mapped (row 72), and the
|
scorecard (nightly), two stale ROM tests fixed and every ROM suite mapped (row 72), and the
|
||||||
parity test's idle-header race.
|
parity test's idle-header race.
|
||||||
|
- 2026-10-02 07:13Z: the stream's video feed runs over flybus (`fly-feed bus`, one aux cpu for the
|
||||||
|
bus threads). Over the first 20 minutes the sim's mean work per frame fell from 15.2 to about
|
||||||
|
14.5 ms and its p99 from 46 to about 21 ms (the publisher left the sim's shared cpu); realtime
|
||||||
|
factor unchanged at about 1.0. Rollback: `fly-feed direct`.
|
||||||
|
|
|
||||||
|
|
@ -518,6 +518,12 @@ check() {
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
set -- "${pass[@]}"
|
set -- "${pass[@]}"
|
||||||
|
# Only the legacy loop writes the trace the shadow follows: if the live fly moved to the session
|
||||||
|
# runtime during the window, the verdict no longer covers what would be cut over.
|
||||||
|
if [ -f "$RUNTIME_DROPIN" ]; then
|
||||||
|
echo "cutover refused: flysim.service runs the session runtime, which writes no trace for a shadow to follow (switch the live fly to legacy for the shadow window: fly-runtime legacy)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
# A tripped guard, a shadow that is not running, or a run that no guard watched never allows a
|
# A tripped guard, a shadow that is not running, or a run that no guard watched never allows a
|
||||||
# cutover, whatever the verdict file says: the guard timer must be active and its baseline
|
# cutover, whatever the verdict file says: the guard timer must be active and its baseline
|
||||||
# present (G1-a).
|
# present (G1-a).
|
||||||
|
|
|
||||||
|
|
@ -3736,3 +3736,62 @@ Trap hunt, 10 brain minutes with the real connectome from the trap checkpoint:
|
||||||
The watchdog and the ladder flagged the trap correctly. The restart could not help, because the
|
The watchdog and the ladder flagged the trap correctly. The restart could not help, because the
|
||||||
trap is in the game state and the hot checkpoint is inside it (row 70's lesson again). Only a reset
|
trap is in the game state and the hot checkpoint is inside it (row 70's lesson again). Only a reset
|
||||||
or the fix ends it.
|
or the fix ends it.
|
||||||
|
|
||||||
|
## 2026-10-02, row 73: Route 25 and Bill's house, a PC no macro could press, and Cerulean's south
|
||||||
|
|
||||||
|
### What was live
|
||||||
|
|
||||||
|
v0.7.5, rung 15 (NUGGET BRIDGE), Route 24/25. After row 71's battle trap was fixed the fly kept a
|
||||||
|
busy ring with no progress: `GO ROUTE` into Bill's house (`$58`, door (45, 3)), `GO OBJECTIVE` or
|
||||||
|
`GO OUT` straight back out. Scout B3 measured it from the live checkpoint: on six seeds (2.8
|
||||||
|
brain hours) the pad in the house was always `GO OBJECTIVE, GO OUT, GO NPC, GO FRONTIER`, `GO OUT`
|
||||||
|
16-51 and `GO OBJECTIVE` 16-60 starts per ten brain minutes, `GO NPC` 0 in about 600 starts, and
|
||||||
|
new tiles 2527 to 2531 in 35 minutes. Rung 16 was never earned.
|
||||||
|
|
||||||
|
### Mechanism
|
||||||
|
|
||||||
|
- **Rung 16's place was the route.** `RUNG_PLACES[16]` was `at(ROUTE_25)`. A fly on Route 25 was
|
||||||
|
already there, so in the house `GO OBJECTIVE` was an exit into the objective's map: the same
|
||||||
|
door as `GO OUT`.
|
||||||
|
- **The errand's middle step was unpressable.** The ticket is Bill's errand
|
||||||
|
(`scripts/BillsHouse.asm`): talk to Bill as a Pokémon, press the cell separator's PC at (1, 4)
|
||||||
|
facing up, talk to Bill when he steps out. The PC is a hidden event (`wNumSigns` 0, one sprite),
|
||||||
|
and no macro aimed at hidden events or dealt `TALK` in front of one. Scout B3 confirmed the
|
||||||
|
press on the cartridge by hand.
|
||||||
|
- **After the ticket, the town is two pieces.** Cerulean's town ground ends at row 28; Route 5 is
|
||||||
|
on the ground behind the trashed house (`$3e`), in by its front door and out by the hole in its
|
||||||
|
back wall. The house was off the map graph, so `GO OBJECTIVE` toward Vermilion ended `blocked`
|
||||||
|
at (17, 28) and the fly rang between the town and its houses (scout: 0 of 6 seeds past row 28 in
|
||||||
|
43 brain minutes each, from a carry-forward made by scripted presses).
|
||||||
|
|
||||||
|
| # | trap | trigger | test | fix, or why it is left |
|
||||||
|
| --- | --- | --- | --- | --- |
|
||||||
|
| 73 | rung 16's place was Route 25, so inside Bill's house `GO OBJECTIVE` and `GO OUT` were both the door; the errand's PC is a hidden event no macro could press; after the ticket, Cerulean's south was off the graph | rung 15 on Route 25 (live), and any fly with the ticket in Cerulean | `an_errand_is_its_people_first_and_the_room_is_not_left_while_one_is_waiting`, `a_hidden_event_is_the_errands_next_step_once_no_person_is_left_and_it_is_faced_from_its_side`, `a_hidden_event_is_nobody_elses_target`, `the_road_south_out_of_cerulean_is_through_the_trashed_house`; `row73_*` in `rom_macros_mode.rs` (`FLY_ROW73_DOOR_CHECKPOINT`, `FLY_ROW73_PC_CHECKPOINT`, `FLY_ROW71_CHECKPOINT`, `FLY_ROW73_SOUTH_CHECKPOINT`, `FLY_ROW73_TRASHED_CHECKPOINT`, `FLY_ROW73_TICKET_CHECKPOINT`) | **fixed**: rung 16 is `errand(BILLS_HOUSE)`, people then things; hidden events read from the cartridge's own table (`$11:$6A40`/`$6A96`), only ever as the errand's next step, faced from the side the entry names (`docs/design/macros.md` 12.35, `macros-wram.md` 17); Cerulean's third piece and the trashed house on the graph |
|
||||||
|
| 73a | the road from Route 5 to Vermilion is plain map edges through Saffron, whose gates are guarded until the drink; the Underground Path's houses are off the graph | a fly on Route 5 with rung 17 next | none yet | **left**: predicted, not reached by the scout; the branch hunt's flies reach Route 5's gate (`$46`) and the Underground Path house (`$47`). Needs its own checkpoint and row |
|
||||||
|
|
||||||
|
| test (stub rotation) | 74a3c12 | branch |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `row73_the_fly_earns_the_ss_ticket_from_inside_the_ring_at_bills_door` | no ticket in 36,000 frames, out of the house and the Route 24/25 ring. **Fails** | ticket at 4,743 frames, never out of the house. Passes |
|
||||||
|
| `row73_the_cell_separator_pc_is_pressed_and_bill_hands_over_the_ticket` | no ticket in 36,000 frames. **Fails** | ticket at 2,116 frames. Passes |
|
||||||
|
| `row73_the_fly_walks_from_the_live_route_25_checkpoint_to_the_ss_ticket` | no ticket in 216,000 frames (60 brain minutes), 1,019 times into the house and 1,019 out. **Fails** | ticket at 9,876 frames. Passes |
|
||||||
|
| `row73_the_objective_south_of_cerulean_is_the_trashed_houses_two_doors` | aims at the town's bottom row (unreachable). **Fails** | the house's front door, then the hole in its back wall. Passes |
|
||||||
|
| `row73_the_fly_takes_the_trashed_house_south_to_route_5` | trashed house 54,442; ticket carry-forward not in 48,000 (63,880). **Fails** | 52,081 and 27,067. Passes |
|
||||||
|
| `row73_the_hidden_event_table_is_the_cartridges_and_bills_pc_is_in_it` | does not compile (new seam) | passes |
|
||||||
|
|
||||||
|
Trap hunt, real connectome, 15 brain minutes per seed, six seeds per arm. The palette seed does not
|
||||||
|
make runs differ (row 68), so the seeds are the game run 0, 7, 19, 41, 97 and 211 frames ahead of
|
||||||
|
the brain before the first hold (scout B3's `FLY_TRAP_AHEAD`, a scratch patch, not committed):
|
||||||
|
|
||||||
|
| from | arm | rung 16 | distinct (map, tile) | Bill's-house ring (`GO ROUTE` / `GO OUT` / `GO OBJECTIVE` at net 0) | reached Route 5 |
|
||||||
|
| --- | --- | --- | --- | --- | --- |
|
||||||
|
| live row-71 checkpoint (rung 15, Route 25) | 74a3c12 | 0 of 6 | 83-105 | 36-47 / 18-22 / 18-27 per seed | 0 of 6 |
|
||||||
|
| live row-71 checkpoint | branch | **6 of 6**, at 2.0-2.3 brain minutes | 200-517 | 2-24 / 3-30 / none at net 0 (the walks go somewhere) | 3 of 6 inside the 15 minutes |
|
||||||
|
| ticket carry-forward (rung 16, Bill's house) | 74a3c12 | (has it) | 328-400 | -- | 0 of 6 (ends in the town, the bike shop or the centre) |
|
||||||
|
| ticket carry-forward | branch | (has it) | 273-439 | -- | **5 of 6**; four of them on into Route 5's gate (`$46`) or the Underground Path house (`$47`) |
|
||||||
|
|
||||||
|
The two-minute window flags do not measure this trap: the ring crosses more than four tiles, so
|
||||||
|
the base arm flags only the opening battle text (1 of 53), and the branch arm's flags (28-49 of 53)
|
||||||
|
are `NEXT` runs inside long battles it now reaches -- the Rocket in the yard behind the trashed
|
||||||
|
house and Route 24/5 trainers (one battle 23,954 frames and 462 macros; the base's ticket seed 19
|
||||||
|
has the same 17,235-frame battle). Every one ended; none is a ring. Route 5 is counted from the
|
||||||
|
hunt's text-box maps and its final map, so it is a floor.
|
||||||
|
|
|
||||||
|
|
@ -867,6 +867,23 @@ if command -v python3 >/dev/null 2>&1; then
|
||||||
else
|
else
|
||||||
fail "fly-shadow-run check --bus must pass --require-arm bus/process to fly-shadow check ($(cat "$cb_tmp/args" 2>/dev/null))"
|
fail "fly-shadow-run check --bus must pass --require-arm bus/process to fly-shadow check ($(cat "$cb_tmp/args" 2>/dev/null))"
|
||||||
fi
|
fi
|
||||||
|
# BUS-01 review N1: `check` (plain and --bus) refuses while the live fly runs the session
|
||||||
|
# runtime, which writes no trace for the shadow to follow, and never asks fly-shadow.
|
||||||
|
printf '[Service]\nExecStart=/opt/fly/current/flysim-session\n' > "$cb_tmp/10-runtime.conf"
|
||||||
|
for ck_args in "" "--bus"; do
|
||||||
|
rm -f "$cb_tmp/args"
|
||||||
|
ck_rc=0
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
ck_out="$(PATH="$cb_tmp/bin:$PATH" FLY_SHADOW_DIR="$cb_tmp/shadow" FLY_SHADOW_BIN="$cb_tmp/fly-shadow" \
|
||||||
|
FLY_SHADOW_REMOTE_DROPIN_DIR="$cb_tmp/none.d" FLY_ENV_FILE="$cb_tmp/none.env" \
|
||||||
|
FLY_RUNTIME_DROPIN="$cb_tmp/10-runtime.conf" \
|
||||||
|
"$INFRA_DIR/bin/fly-shadow-run" check $ck_args 2>&1)" || ck_rc=$?
|
||||||
|
if [ "$ck_rc" -ne 0 ] && echo "$ck_out" | grep -q 'runs the session runtime' && [ ! -e "$cb_tmp/args" ]; then
|
||||||
|
pass "fly-shadow-run check${ck_args:+ $ck_args} refuses while the live fly runs the session runtime"
|
||||||
|
else
|
||||||
|
fail "fly-shadow-run check${ck_args:+ $ck_args} must refuse while the session runtime drop-in exists (rc=$ck_rc): $ck_out"
|
||||||
|
fi
|
||||||
|
done
|
||||||
rm -rf "$cb_tmp"
|
rm -rf "$cb_tmp"
|
||||||
fi
|
fi
|
||||||
# SHADOW-02: `check` in remote mode also needs the relay healthy now (relay.json under a minute
|
# SHADOW-02: `check` in remote mode also needs the relay healthy now (relay.json under a minute
|
||||||
|
|
|
||||||
1
services/flysim/Cargo.lock
generated
1
services/flysim/Cargo.lock
generated
|
|
@ -505,6 +505,7 @@ dependencies = [
|
||||||
"flybrain-gb",
|
"flybrain-gb",
|
||||||
"flybus",
|
"flybus",
|
||||||
"flysim-store",
|
"flysim-store",
|
||||||
|
"libc",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,8 @@ flate2 = { workspace = true }
|
||||||
flysim-store = { path = "../flysim-store" }
|
flysim-store = { path = "../flysim-store" }
|
||||||
|
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
# PR_SET_PDEATHSIG for worker processes (a child never outlives its parent, systemd or not).
|
||||||
|
libc = "0.2"
|
||||||
# `rt-multi-thread` is not only for the tests: a worker process and a dedicated-thread
|
# `rt-multi-thread` is not only for the tests: a worker process and a dedicated-thread
|
||||||
# worker each build their own runtime sized to the launcher's thread allocation.
|
# worker each build their own runtime sized to the launcher's thread allocation.
|
||||||
tokio = { version = "1", features = ["rt", "rt-multi-thread", "sync", "time", "macros", "io-util"] }
|
tokio = { version = "1", features = ["rt", "rt-multi-thread", "sync", "time", "macros", "io-util"] }
|
||||||
|
|
|
||||||
|
|
@ -548,6 +548,32 @@ pub fn default_worker_program() -> PathBuf {
|
||||||
PathBuf::from(name)
|
PathBuf::from(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Makes `command`'s child die with its parent (BUS-01 review N2): the kernel sends it SIGKILL when
|
||||||
|
/// the parent *thread* that spawned it exits, so a worker never outlives its coordinator even outside
|
||||||
|
/// systemd's cgroup kill (a hung worker used to survive a killed parent, once for 47 hours).
|
||||||
|
///
|
||||||
|
/// Linux delivers the signal when the spawning thread ends, not the whole process, so spawn from a
|
||||||
|
/// thread that lives as long as the process: a runtime worker or the main thread, never a
|
||||||
|
/// short-lived blocking-pool thread. Setting the signal races a parent that already died; the child
|
||||||
|
/// checks its parent id after setting it and exits if it was already re-parented.
|
||||||
|
pub fn die_with_parent(command: &mut std::process::Command) {
|
||||||
|
use std::os::unix::process::CommandExt;
|
||||||
|
let parent = std::process::id() as libc::pid_t;
|
||||||
|
// SAFETY: the closure runs between fork and exec and calls only async-signal-safe functions
|
||||||
|
// (prctl, getppid, _exit); it allocates nothing and takes no locks.
|
||||||
|
unsafe {
|
||||||
|
command.pre_exec(move || {
|
||||||
|
if libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGKILL as libc::c_ulong, 0, 0, 0) != 0 {
|
||||||
|
return Err(std::io::Error::last_os_error());
|
||||||
|
}
|
||||||
|
if libc::getppid() != parent {
|
||||||
|
libc::_exit(1);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Launcher {
|
impl Launcher {
|
||||||
/// Connects the supervisor and prepares the launcher. Nothing is started yet.
|
/// Connects the supervisor and prepares the launcher. Nothing is started yet.
|
||||||
pub async fn start(
|
pub async fn start(
|
||||||
|
|
@ -1011,6 +1037,7 @@ impl Launcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
command.stdin(std::process::Stdio::null());
|
command.stdin(std::process::Stdio::null());
|
||||||
|
die_with_parent(&mut command);
|
||||||
let child = command.spawn().map_err(|e| {
|
let child = command.spawn().map_err(|e| {
|
||||||
DomainError::new(
|
DomainError::new(
|
||||||
ErrorCode::BackendFailure,
|
ErrorCode::BackendFailure,
|
||||||
|
|
|
||||||
75
services/flysim/crates/fly-session/tests/orphans.rs
Normal file
75
services/flysim/crates/fly-session/tests/orphans.rs
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
//! BUS-01 review N2: a worker process never outlives its parent, outside systemd too.
|
||||||
|
//!
|
||||||
|
//! The test re-executes its own binary as the "parent" (selected by an environment variable),
|
||||||
|
//! which spawns one worker through the launcher's `die_with_parent` and one plain control child,
|
||||||
|
//! then waits. The outer test `kill -9`s the parent and checks the worker is gone within a bound
|
||||||
|
//! while the control child, which has no death signal, survives (so the check can fail).
|
||||||
|
|
||||||
|
use std::io::{BufRead, BufReader};
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
const ROLE: &str = "FLY_TEST_ORPHAN_PARENT";
|
||||||
|
const BOUND: Duration = Duration::from_secs(5);
|
||||||
|
|
||||||
|
/// True while `pid` is a live process (a zombie awaiting its reaper counts as gone).
|
||||||
|
fn alive(pid: u32) -> bool {
|
||||||
|
match std::fs::read_to_string(format!("/proc/{pid}/stat")) {
|
||||||
|
Ok(stat) => {
|
||||||
|
let state = stat.rsplit(')').next().unwrap_or("").trim().chars().next();
|
||||||
|
state != Some('Z') && state != Some('X')
|
||||||
|
}
|
||||||
|
Err(_) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wait_gone(pid: u32) -> bool {
|
||||||
|
let start = Instant::now();
|
||||||
|
while start.elapsed() < BOUND {
|
||||||
|
if !alive(pid) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
std::thread::sleep(Duration::from_millis(50));
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_killed_parent_takes_its_workers_with_it() {
|
||||||
|
if std::env::var_os(ROLE).is_some() {
|
||||||
|
// The parent: spawn a protected worker and an unprotected control, report, then wait.
|
||||||
|
let mut worker = Command::new("sleep");
|
||||||
|
worker.arg("300");
|
||||||
|
fly_session::launcher::die_with_parent(&mut worker);
|
||||||
|
let mut worker = worker.spawn().unwrap();
|
||||||
|
let mut control = Command::new("sleep").arg("300").spawn().unwrap();
|
||||||
|
println!("{} {}", worker.id(), control.id());
|
||||||
|
let _ = worker.wait();
|
||||||
|
let _ = control.wait();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mut parent = Command::new(std::env::current_exe().unwrap())
|
||||||
|
.args(["--exact", "a_killed_parent_takes_its_workers_with_it", "--nocapture", "--test-threads=1"])
|
||||||
|
.env(ROLE, "1")
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
let mut lines = BufReader::new(parent.stdout.take().unwrap()).lines();
|
||||||
|
let (worker, control) = loop {
|
||||||
|
let line = lines.next().expect("the parent reports its children").unwrap();
|
||||||
|
let ids: Vec<u32> = line.split_whitespace().filter_map(|t| t.parse().ok()).collect();
|
||||||
|
if ids.len() == 2 {
|
||||||
|
break (ids[0], ids[1]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert!(alive(worker) && alive(control));
|
||||||
|
// SIGKILL: no cleanup runs in the parent, so only the kernel can take the worker down.
|
||||||
|
unsafe { libc::kill(parent.id() as i32, libc::SIGKILL) };
|
||||||
|
parent.wait().unwrap();
|
||||||
|
let worker_gone = wait_gone(worker);
|
||||||
|
let control_survived = alive(control);
|
||||||
|
unsafe { libc::kill(control as i32, libc::SIGKILL) };
|
||||||
|
unsafe { libc::kill(worker as i32, libc::SIGKILL) };
|
||||||
|
assert!(worker_gone, "the worker outlived its killed parent");
|
||||||
|
assert!(control_survived, "the control child should have survived (the check cannot fail otherwise)");
|
||||||
|
}
|
||||||
|
|
@ -202,6 +202,15 @@ pub enum PlaceKind {
|
||||||
Person,
|
Person,
|
||||||
/// Something to press A at: the starter's Pokéball, an item ball, a sign.
|
/// Something to press A at: the starter's Pokéball, an item ball, a sign.
|
||||||
Object,
|
Object,
|
||||||
|
/// An errand in one room, step by step: its people first, and once none is left to talk to,
|
||||||
|
/// the things in it -- objects, signs, and the cartridge's own hidden events, such as the PC
|
||||||
|
/// a Bill's-house cell separator is started from (row 73, `docs/design/macros.md` 12.35).
|
||||||
|
///
|
||||||
|
/// Not a list of steps, and no step is named: the room's state says which step is next, because
|
||||||
|
/// the cartridge shows and hides the people as the errand moves on. A person who has had their
|
||||||
|
/// conversation is in the talked ledger; a thing pressed is too; and what is left is the next
|
||||||
|
/// step.
|
||||||
|
Errand,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MapPlace {
|
impl MapPlace {
|
||||||
|
|
@ -224,6 +233,11 @@ impl MapPlace {
|
||||||
pub const fn object(map: u8) -> Self {
|
pub const fn object(map: u8) -> Self {
|
||||||
Self { map, tile: None, warp: None, edge: None, target: Some(PlaceKind::Object) }
|
Self { map, tile: None, warp: None, edge: None, target: Some(PlaceKind::Object) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A place that is an errand in one room: its people, then its things ([`PlaceKind::Errand`]).
|
||||||
|
pub const fn errand(map: u8) -> Self {
|
||||||
|
Self { map, tile: None, warp: None, edge: None, target: Some(PlaceKind::Errand) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reasons an adapter refuses a checkpoint.
|
/// Reasons an adapter refuses a checkpoint.
|
||||||
|
|
|
||||||
|
|
@ -286,6 +286,8 @@ pub enum TalkTarget {
|
||||||
Sprite(u8),
|
Sprite(u8),
|
||||||
/// A sign, by its text id.
|
/// A sign, by its text id.
|
||||||
Sign(u8),
|
Sign(u8),
|
||||||
|
/// A hidden event of the cartridge's own table, by its position in this map's list (row 73).
|
||||||
|
Hidden(u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// One thing a macro can be *aimed at*, as the session's target ledgers name it.
|
/// One thing a macro can be *aimed at*, as the session's target ledgers name it.
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,12 @@ const LINKS: &[(u8, u8)] = &[
|
||||||
// which from the back door's arrival is the back door. Which piece each door opens onto is
|
// which from the back door's arrival is the back door. Which piece each door opens onto is
|
||||||
// [`SPLIT`]'s business.
|
// [`SPLIT`]'s business.
|
||||||
(maps::CERULEAN_BADGE_HOUSE, maps::CERULEAN_CITY),
|
(maps::CERULEAN_BADGE_HOUSE, maps::CERULEAN_CITY),
|
||||||
|
// The trashed house (row 73): its front door is the town's, the hole in its back wall the
|
||||||
|
// south's ([`SPLIT`]). It is the only road from the town to Route 5, rung 17's.
|
||||||
|
(maps::CERULEAN_TRASHED_HOUSE, maps::CERULEAN_CITY),
|
||||||
|
// Bill's house, rung 16's room (row 73): Route 25's door at (45, 3), and the house's two
|
||||||
|
// doormats back to the route (`LAST_MAP`).
|
||||||
|
(maps::BILLS_HOUSE, maps::ROUTE_25),
|
||||||
(maps::ROCK_TUNNEL_1F, maps::ROUTE_10),
|
(maps::ROCK_TUNNEL_1F, maps::ROUTE_10),
|
||||||
(maps::INDIGO_PLATEAU_LOBBY, maps::INDIGO_PLATEAU),
|
(maps::INDIGO_PLATEAU_LOBBY, maps::INDIGO_PLATEAU),
|
||||||
];
|
];
|
||||||
|
|
@ -252,6 +258,9 @@ const B2F_SOUTH: u8 = 2;
|
||||||
const CERULEAN_TOWN: u8 = 0;
|
const CERULEAN_TOWN: u8 = 0;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
const CERULEAN_YARD: u8 = 1;
|
const CERULEAN_YARD: u8 = 1;
|
||||||
|
/// [`SPLIT`]'s third piece of Cerulean: the ground behind the trashed house (row 73).
|
||||||
|
#[cfg(test)]
|
||||||
|
const CERULEAN_SOUTH: u8 = 2;
|
||||||
|
|
||||||
/// Every map whose ground is in pieces, with each piece's doors and neighbours.
|
/// Every map whose ground is in pieces, with each piece's doors and neighbours.
|
||||||
///
|
///
|
||||||
|
|
@ -383,21 +392,33 @@ const SPLIT: &[Split] = &[
|
||||||
(3, 30, 19),
|
(3, 30, 19),
|
||||||
(4, 13, 25),
|
(4, 13, 25),
|
||||||
(5, 25, 25),
|
(5, 25, 25),
|
||||||
(7, 27, 9),
|
|
||||||
(8, 9, 11),
|
(8, 9, 11),
|
||||||
],
|
],
|
||||||
next: &[
|
next: &[
|
||||||
Region::whole(maps::ROUTE_24),
|
Region::whole(maps::ROUTE_24),
|
||||||
Region::whole(maps::ROUTE_5),
|
|
||||||
Region::piece(maps::ROUTE_4, EAST_SIDE),
|
Region::piece(maps::ROUTE_4, EAST_SIDE),
|
||||||
Region::whole(maps::ROUTE_9),
|
|
||||||
Region::whole(maps::CERULEAN_POKECENTER),
|
Region::whole(maps::CERULEAN_POKECENTER),
|
||||||
Region::whole(maps::CERULEAN_GYM),
|
Region::whole(maps::CERULEAN_GYM),
|
||||||
Region::whole(maps::CERULEAN_MART),
|
Region::whole(maps::CERULEAN_MART),
|
||||||
Region::whole(maps::CERULEAN_BADGE_HOUSE),
|
Region::whole(maps::CERULEAN_BADGE_HOUSE),
|
||||||
|
Region::whole(maps::CERULEAN_TRASHED_HOUSE),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
Piece { doors: &[(9, 9, 9)], next: &[Region::whole(maps::CERULEAN_BADGE_HOUSE)] },
|
Piece { doors: &[(9, 9, 9)], next: &[Region::whole(maps::CERULEAN_BADGE_HOUSE)] },
|
||||||
|
// Row 73: everything behind the trashed house. The town's own ground ends at row 28 --
|
||||||
|
// the gap at (16, 28) and (17, 28) opens onto a wall and the trainer-tips sign -- and
|
||||||
|
// the south of the map, the road down to Route 5, and the east edge onto Route 9 are
|
||||||
|
// reached through the house: in by the front door at (27, 11), out by the hole in its
|
||||||
|
// back wall, which lands on (27, 9) in the Rocket's yard, and from there east and down
|
||||||
|
// (scout B3 flooded the grid: 378 of the map's 801 walkable tiles are the town's).
|
||||||
|
Piece {
|
||||||
|
doors: &[(7, 27, 9)],
|
||||||
|
next: &[
|
||||||
|
Region::whole(maps::ROUTE_5),
|
||||||
|
Region::whole(maps::ROUTE_9),
|
||||||
|
Region::whole(maps::CERULEAN_TRASHED_HOUSE),
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
@ -977,6 +998,31 @@ mod tests {
|
||||||
assert!(warp_on(west, 1) && !warp_on(west, 2) && !edge_on(west, maps::CERULEAN_CITY));
|
assert!(warp_on(west, 1) && !warp_on(west, 2) && !edge_on(west, maps::CERULEAN_CITY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_road_south_out_of_cerulean_is_through_the_trashed_house() {
|
||||||
|
// Row 73. The town's ground ends at row 28; Route 5 and Route 9 are on the ground behind
|
||||||
|
// the trashed house, reached in by its front door (Cerulean's warp 0) and out by the hole
|
||||||
|
// in its back wall, which lands on (27, 9) (warp 7). Scout B3: 0 of 6 seeds past the
|
||||||
|
// town's south edge in 43 brain minutes each while the house was off the graph.
|
||||||
|
let town = Region::piece(maps::CERULEAN_CITY, CERULEAN_TOWN);
|
||||||
|
let south = Region::piece(maps::CERULEAN_CITY, CERULEAN_SOUTH);
|
||||||
|
let house = Region::whole(maps::CERULEAN_TRASHED_HOUSE);
|
||||||
|
assert_eq!(arrival_by_warp(maps::CERULEAN_CITY, 0), Some(town), "the front door is the town's");
|
||||||
|
assert_eq!(arrival_by_warp(maps::CERULEAN_CITY, 7), Some(south), "the hole lands behind the house");
|
||||||
|
assert_eq!(arrival_by_edge(maps::CERULEAN_CITY, maps::ROUTE_5), Some(south));
|
||||||
|
assert_eq!(arrival_by_edge(maps::CERULEAN_CITY, maps::ROUTE_9), Some(south));
|
||||||
|
assert_eq!(next_step(town, maps::ROUTE_5), Some(house));
|
||||||
|
assert_eq!(next_step(house, maps::ROUTE_5), Some(south));
|
||||||
|
assert_eq!(next_step(south, maps::ROUTE_5), Some(Region::whole(maps::ROUTE_5)));
|
||||||
|
assert_eq!(next_step(house, maps::CERULEAN_GYM), Some(town));
|
||||||
|
assert_eq!(region_at(maps::CERULEAN_CITY, 27, 9), south);
|
||||||
|
assert_eq!(region_at(maps::CERULEAN_CITY, 27, 12), town);
|
||||||
|
assert!(!edge_on(town, maps::ROUTE_5) && edge_on(south, maps::ROUTE_5));
|
||||||
|
assert!(warp_on(south, 7) && !warp_on(town, 7) && !warp_on(south, 0));
|
||||||
|
// Rung 17's road from Bill's house is now one the graph knows end to end.
|
||||||
|
assert!(hops(Region::whole(maps::BILLS_HOUSE), maps::VERMILION_CITY).is_some());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn the_road_from_pewter_to_cerulean_is_through_mt_moon_one_chamber_at_a_time() {
|
fn the_road_from_pewter_to_cerulean_is_through_mt_moon_one_chamber_at_a_time() {
|
||||||
// Row 59. Every step of the road, as the pieces the fly stands in, measured from the
|
// Row 59. Every step of the road, as the pieces the fly stands in, measured from the
|
||||||
|
|
|
||||||
|
|
@ -2021,6 +2021,9 @@ pub fn facing_target(state: &mut dyn MacroState) -> Option<TalkTarget> {
|
||||||
if let Some(target) = path::target_at(state, ahead) {
|
if let Some(target) = path::target_at(state, ahead) {
|
||||||
return Some(target);
|
return Some(target);
|
||||||
}
|
}
|
||||||
|
if let Some(target) = objective_hidden_ahead(state, ahead, player.facing) {
|
||||||
|
return Some(target);
|
||||||
|
}
|
||||||
// **Over a counter**, which is the symmetric half of [`counter_aims`] and was missing from it
|
// **Over a counter**, which is the symmetric half of [`counter_aims`] and was missing from it
|
||||||
// (2026-09-17, measured on the cartridge in the Viridian mart). The game doubles its own
|
// (2026-09-17, measured on the cartridge in the Viridian mart). The game doubles its own
|
||||||
// talking range over the tileset's counter tiles, so a fly standing at a counter facing the
|
// talking range over the tileset's counter tiles, so a fly standing at a counter facing the
|
||||||
|
|
@ -2111,7 +2114,17 @@ pub fn objective_goals(state: &mut dyn MacroState) -> Vec<Aim> {
|
||||||
// to walk to: `GO OBJECTIVE` walked to him, then back to the leader, and `TALK` was
|
// to walk to: `GO OBJECTIVE` walked to him, then back to the leader, and `TALK` was
|
||||||
// the one press it never made room for. A fly facing a person the rung is waiting on
|
// the one press it never made room for. A fly facing a person the rung is waiting on
|
||||||
// has nothing left for a walk to do.
|
// has nothing left for a walk to do.
|
||||||
if targets.iter().any(|(tile, _)| Some(*tile) == ahead) {
|
// A hidden event is faced only from the side it answers (row 73): beside Bill's PC
|
||||||
|
// facing it sideways is not the arrival, and the walk goes on to the tile below it.
|
||||||
|
let mut arrived = false;
|
||||||
|
for (tile, target) in &targets {
|
||||||
|
if Some(*tile) == ahead
|
||||||
|
&& required_facing(state, *target).is_none_or(|need| need == player.facing)
|
||||||
|
{
|
||||||
|
arrived = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if arrived {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
let mut ranked: Vec<(u32, Tile, TalkTarget)> = targets
|
let mut ranked: Vec<(u32, Tile, TalkTarget)> = targets
|
||||||
|
|
@ -2120,8 +2133,12 @@ pub fn objective_goals(state: &mut dyn MacroState) -> Vec<Aim> {
|
||||||
.collect();
|
.collect();
|
||||||
ranked.sort_unstable();
|
ranked.sort_unstable();
|
||||||
let Some((_, tile, target)) = ranked.first().copied() else { return Vec::new() };
|
let Some((_, tile, target)) = ranked.first().copied() else { return Vec::new() };
|
||||||
|
let need = required_facing(state, target);
|
||||||
let mut aims = Vec::with_capacity(4);
|
let mut aims = Vec::with_capacity(4);
|
||||||
for facing in FACINGS {
|
for facing in FACINGS {
|
||||||
|
if need.is_some_and(|need| need != opposite(facing)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let Some(stand) = tile.step(facing) else { continue };
|
let Some(stand) = tile.step(facing) else { continue };
|
||||||
// Not a tile a script pushes the fly off (row 37); `approach` excludes the same.
|
// Not a tile a script pushes the fly off (row 37); `approach` excludes the same.
|
||||||
if state.pushed_tile(stand.x, stand.y) {
|
if state.pushed_tile(stand.x, stand.y) {
|
||||||
|
|
@ -2235,7 +2252,34 @@ pub fn objective_targets(state: &mut dyn MacroState) -> Vec<(Tile, TalkTarget)>
|
||||||
// Not objects: every item ball in the game is a toggleable object, so a ball the run has
|
// Not objects: every item ball in the game is a toggleable object, so a ball the run has
|
||||||
// picked up and one out of sight read alike from outside the window.
|
// picked up and one out of sight read alike from outside the window.
|
||||||
PlaceKind::Object => path::interactable_targets(state),
|
PlaceKind::Object => path::interactable_targets(state),
|
||||||
|
// Row 73: an errand in one room is its people first, and its things -- sprites, signs and
|
||||||
|
// the cartridge's hidden events -- once no person is left to talk to. Bill's house is the
|
||||||
|
// case: Bill (a Pokémon) asks for the cell separator and walks into the machine, the
|
||||||
|
// separator is a PC no sprite or sign stands for, and Bill comes out of the machine to
|
||||||
|
// hand over the ticket. The cartridge hides and shows the people as the errand moves, so
|
||||||
|
// the room's own state says which step is next; nothing here names a step.
|
||||||
|
//
|
||||||
|
// People first, because a thing pressed out of turn is in the talked ledger for the
|
||||||
|
// session: Bill's PC pressed before Bill has asked prints "the monitor" and does nothing,
|
||||||
|
// and a PC recorded as talked to would never be the errand's next step again.
|
||||||
|
PlaceKind::Errand => {
|
||||||
|
let mut people = path::person_targets(state);
|
||||||
|
people.extend(path::offscreen_person_targets(state));
|
||||||
|
let people = open_targets(state, people);
|
||||||
|
if !people.is_empty() {
|
||||||
|
return people;
|
||||||
|
}
|
||||||
|
let mut things = path::interactable_targets(state);
|
||||||
|
things.extend(path::hidden_targets(state).into_iter().map(|(tile, target, _)| (tile, target)));
|
||||||
|
things
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
open_targets(state, targets)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whichever of `targets` the objective is still waiting on: not talked to, and not resting in
|
||||||
|
/// the blocked ledger. [`objective_targets`]' own filter, for each list it builds.
|
||||||
|
fn open_targets(state: &mut dyn MacroState, targets: Vec<(Tile, TalkTarget)>) -> Vec<(Tile, TalkTarget)> {
|
||||||
targets
|
targets
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|(_, target)| {
|
.filter(|(_, target)| {
|
||||||
|
|
@ -2244,6 +2288,37 @@ pub fn objective_targets(state: &mut dyn MacroState) -> Vec<(Tile, TalkTarget)>
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The one side the objective's `target` is pressed from, when the cartridge names one: a hidden
|
||||||
|
/// event whose routine checks the player's facing (row 73, Bill's PC). `None` for every sprite and
|
||||||
|
/// sign, which answer from any side.
|
||||||
|
fn required_facing(state: &mut dyn MacroState, target: TalkTarget) -> Option<Facing> {
|
||||||
|
let TalkTarget::Hidden(_) = target else { return None };
|
||||||
|
path::hidden_targets(state)
|
||||||
|
.into_iter()
|
||||||
|
.find(|(_, hidden, _)| *hidden == target)
|
||||||
|
.and_then(|(_, _, facing)| facing)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The objective's hidden event on the tile ahead, faced from the side it answers (row 73).
|
||||||
|
///
|
||||||
|
/// The half of [`facing_target`] that is not the map's sprites and signs. Only the objective's
|
||||||
|
/// own next step is reported, never any other hidden event: a poster faced on the way past is not
|
||||||
|
/// a reason for `TALK`, and a PC pressed out of turn would retire the errand's own step
|
||||||
|
/// ([`objective_targets`]).
|
||||||
|
fn objective_hidden_ahead(state: &mut dyn MacroState, ahead: Tile, facing: Facing) -> Option<TalkTarget> {
|
||||||
|
// Most tiles of most maps are no hidden event's, and this is asked on every overworld frame.
|
||||||
|
if !path::hidden_targets(state).iter().any(|(tile, _, _)| *tile == ahead) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let (_, target) = objective_targets(state)
|
||||||
|
.into_iter()
|
||||||
|
.find(|(tile, target)| *tile == ahead && matches!(target, TalkTarget::Hidden(_)))?;
|
||||||
|
match required_facing(state, target) {
|
||||||
|
Some(need) if need != facing => None,
|
||||||
|
_ => Some(target),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The exits the ledger has already recorded, for the log line.
|
/// The exits the ledger has already recorded, for the log line.
|
||||||
pub fn visited_exits(state: &mut dyn MacroState) -> Vec<ExitId> {
|
pub fn visited_exits(state: &mut dyn MacroState) -> Vec<ExitId> {
|
||||||
path::exits(state)
|
path::exits(state)
|
||||||
|
|
|
||||||
|
|
@ -366,6 +366,24 @@ pub fn interactable_targets(state: &mut dyn MacroState) -> Vec<(Tile, TalkTarget
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The map's hidden events with the key the talked ledger records them under, and the one side
|
||||||
|
/// each is pressed from when the cartridge names one (row 73).
|
||||||
|
///
|
||||||
|
/// Kept apart from [`interactable_targets`] on purpose, which is `GO ITEM`'s list: a hidden event
|
||||||
|
/// is every PC, poster, trash can and hidden item in Kanto, and a fly sent to each of them is a
|
||||||
|
/// fly reading posters. The one reader is the ladder's own errand list
|
||||||
|
/// ([`super::palette::objective_targets`]), which needs the one the rung is waiting on.
|
||||||
|
pub fn hidden_targets(state: &mut dyn MacroState) -> Vec<(Tile, TalkTarget, Option<Facing>)> {
|
||||||
|
let mut out: Vec<(Tile, TalkTarget, Option<Facing>)> = state
|
||||||
|
.hidden_events()
|
||||||
|
.iter()
|
||||||
|
.map(|event| (Tile::new(event.x, event.y), TalkTarget::Hidden(event.index), event.facing))
|
||||||
|
.collect();
|
||||||
|
out.sort_unstable_by_key(|(tile, target, _)| (*tile, *target));
|
||||||
|
out.dedup_by_key(|(tile, _, _)| *tile);
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
/// Every person on the map with the key the talked ledger records them under.
|
/// Every person on the map with the key the talked ledger records them under.
|
||||||
pub fn person_targets(state: &mut dyn MacroState) -> Vec<(Tile, TalkTarget)> {
|
pub fn person_targets(state: &mut dyn MacroState) -> Vec<(Tile, TalkTarget)> {
|
||||||
let mut out: Vec<(Tile, TalkTarget)> = state
|
let mut out: Vec<(Tile, TalkTarget)> = state
|
||||||
|
|
|
||||||
|
|
@ -413,6 +413,31 @@ pub struct Sign {
|
||||||
pub text_id: u8,
|
pub text_id: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// One hidden event on the current map: a tile the cartridge answers an A press at from its own
|
||||||
|
/// ROM table (`HiddenEventMaps` / `HiddenEventPointers`, `data/events/hidden_events.asm`) rather
|
||||||
|
/// than from a sprite or a sign (row 73, `docs/design/macros.md` 12.35).
|
||||||
|
///
|
||||||
|
/// Bill's cell-separator PC, the Pokémon Center PCs, posters, bookshelves of one room, trash cans
|
||||||
|
/// and hidden items are all this. Nothing about one reaches WRAM until it has been pressed
|
||||||
|
/// (`CheckForHiddenEvent` searches the table on every A in the overworld), so the tile is read from
|
||||||
|
/// the cartridge image and the tile named here is the one to *face*, like a [`Sign`]'s.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub struct HiddenEvent {
|
||||||
|
pub x: u8,
|
||||||
|
pub y: u8,
|
||||||
|
/// The entry's position in this map's list, which is the identity the cartridge gives it
|
||||||
|
/// (`wHiddenEventIndex` counts the same way) and nothing more.
|
||||||
|
pub index: u8,
|
||||||
|
/// The one side the cartridge answers the press from, when the entry names one.
|
||||||
|
///
|
||||||
|
/// The table's third byte is the routine's argument, and where it is a `SPRITE_FACING_*`
|
||||||
|
/// value it is the side the routine checks before it does anything (`BillsHousePC` returns at
|
||||||
|
/// once unless the player faces up). `None` for any other argument -- an item id, a text id,
|
||||||
|
/// `ANY_FACING` -- which leaves all four sides. An argument that is an item or a text id and
|
||||||
|
/// happens to equal a facing value only narrows the approach to one side; it never adds one.
|
||||||
|
pub facing: Option<Facing>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether a tile can be walked onto.
|
/// Whether a tile can be walked onto.
|
||||||
///
|
///
|
||||||
/// `Unknown` is load-bearing: the tile ids a walkability test needs live in the screen buffer, so
|
/// `Unknown` is load-bearing: the tile ids a walkability test needs live in the screen buffer, so
|
||||||
|
|
@ -774,6 +799,14 @@ pub trait GameState {
|
||||||
/// is visible, and not inherit it from here.
|
/// is visible, and not inherit it from here.
|
||||||
fn signs(&mut self) -> Vec<Sign>;
|
fn signs(&mut self) -> Vec<Sign>;
|
||||||
|
|
||||||
|
/// The current map's hidden events, from the cartridge's own table (row 73).
|
||||||
|
///
|
||||||
|
/// Defaulted to none, which narrows: a seam with no cartridge image behind it knows the
|
||||||
|
/// sprites and the signs and nothing more, which is what every reader had before row 73.
|
||||||
|
fn hidden_events(&mut self) -> Vec<HiddenEvent> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether the player could stand on this tile of the current map.
|
/// Whether the player could stand on this tile of the current map.
|
||||||
fn walkable(&mut self, x: u8, y: u8) -> Walkable;
|
fn walkable(&mut self, x: u8, y: u8) -> Walkable;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,8 @@ use super::super::maps;
|
||||||
use super::plan;
|
use super::plan;
|
||||||
use super::state::{
|
use super::state::{
|
||||||
Battle, BattleKind, BattleMenu, Connections, Cursor, EnemyMon, Facing, GameState, MapSize,
|
Battle, BattleKind, BattleMenu, Connections, Cursor, EnemyMon, Facing, GameState, MapSize,
|
||||||
Mon, Move, Naming, Npc, Party, Pc, Player, Scene, Shop, ShopScreen, Sign, StartMenu, Status, TextBox,
|
HiddenEvent, Mon, Move, Naming, Npc, Party, Pc, Player, Scene, Shop, ShopScreen, Sign, StartMenu,
|
||||||
|
Status, TextBox,
|
||||||
Walkable, Warp,
|
Walkable, Warp,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -95,6 +96,8 @@ struct World {
|
||||||
/// Sprites the cartridge is not drawing only because they are off the screen (row 58).
|
/// Sprites the cartridge is not drawing only because they are off the screen (row 58).
|
||||||
offscreen: Vec<Npc>,
|
offscreen: Vec<Npc>,
|
||||||
signs: Vec<Sign>,
|
signs: Vec<Sign>,
|
||||||
|
/// The map's hidden events, as the cartridge's own table lists them (row 73).
|
||||||
|
hidden: Vec<HiddenEvent>,
|
||||||
|
|
||||||
list: List,
|
list: List,
|
||||||
cursor: u8,
|
cursor: u8,
|
||||||
|
|
@ -276,6 +279,7 @@ impl World {
|
||||||
npcs: Vec::new(),
|
npcs: Vec::new(),
|
||||||
offscreen: Vec::new(),
|
offscreen: Vec::new(),
|
||||||
signs: Vec::new(),
|
signs: Vec::new(),
|
||||||
|
hidden: Vec::new(),
|
||||||
list: List::None,
|
list: List::None,
|
||||||
cursor: 0,
|
cursor: 0,
|
||||||
cursor_max: 0,
|
cursor_max: 0,
|
||||||
|
|
@ -791,6 +795,10 @@ impl GameState for World {
|
||||||
self.signs.clone()
|
self.signs.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn hidden_events(&mut self) -> Vec<HiddenEvent> {
|
||||||
|
self.hidden.clone()
|
||||||
|
}
|
||||||
|
|
||||||
fn walkable(&mut self, x: u8, y: u8) -> Walkable {
|
fn walkable(&mut self, x: u8, y: u8) -> Walkable {
|
||||||
let tile = Tile::new(x, y);
|
let tile = Tile::new(x, y);
|
||||||
let offscreen = self.window && {
|
let offscreen = self.window && {
|
||||||
|
|
@ -6615,3 +6623,99 @@ fn row69_confirm_on_a_keyboard_that_does_not_close_is_blocked() {
|
||||||
world.glue_naming = true;
|
world.glue_naming = true;
|
||||||
assert_eq!(run(&mut world, MacroKind::Confirm).unwrap(), MacroAbort::Blocked);
|
assert_eq!(run(&mut world, MacroKind::Confirm).unwrap(), MacroAbort::Blocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Bill's house on the step the live ring never got past (row 73): the fly on the doormat, Bill
|
||||||
|
/// (a Pokémon, a person sprite) at (6, 5), the cell separator's PC a hidden event at (1, 4) that is
|
||||||
|
/// pressed facing up, and rung 16's place the house as an errand.
|
||||||
|
fn bills_house() -> World {
|
||||||
|
let mut world = World::room().at(2, 7);
|
||||||
|
world.map = maps::BILLS_HOUSE;
|
||||||
|
world.size = MapSize { width: 8, height: 8 };
|
||||||
|
world.facing = Facing::Up;
|
||||||
|
// The back wall, the PC's own tile with it.
|
||||||
|
world = world.wall(&[(0, 3), (1, 3), (2, 3), (3, 3), (4, 3), (5, 3), (6, 3), (7, 3), (1, 4)]);
|
||||||
|
world.warps = vec![
|
||||||
|
Warp { x: 2, y: 7, destination_warp: 0, destination_map: LAST_MAP },
|
||||||
|
Warp { x: 3, y: 7, destination_warp: 0, destination_map: LAST_MAP },
|
||||||
|
];
|
||||||
|
world.npcs = vec![Npc { slot: 1, picture: 0x2a, x: 6, y: 5, facing: Facing::Down }];
|
||||||
|
world.hidden = vec![HiddenEvent { x: 1, y: 4, index: 0, facing: Some(Facing::Up) }];
|
||||||
|
world.objective = Some(Objective {
|
||||||
|
map: world.map,
|
||||||
|
tile: None,
|
||||||
|
warp: None,
|
||||||
|
edge: None,
|
||||||
|
target: Some(PlaceKind::Errand),
|
||||||
|
});
|
||||||
|
world
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn an_errand_is_its_people_first_and_the_room_is_not_left_while_one_is_waiting() {
|
||||||
|
// Row 73, live on v0.7.5: rung 16 was `at(ROUTE_25)`, so inside Bill's house `GO OBJECTIVE`
|
||||||
|
// and `GO OUT` were both the door, 30 to 60 times per ten brain minutes. As an errand, Bill is
|
||||||
|
// the target and the ways out are withheld while he is waiting (12.5's rule).
|
||||||
|
let mut world = bills_house();
|
||||||
|
assert_eq!(super::palette::objective_targets(&mut world), vec![(Tile::new(6, 5), TalkTarget::Sprite(1))]);
|
||||||
|
assert!(on_the_pad(&mut world, MacroKind::GoObjective));
|
||||||
|
assert!(!on_the_pad(&mut world, MacroKind::GoOut), "the house is not left while Bill is waiting");
|
||||||
|
|
||||||
|
// The PC is not the errand's step yet: faced out of turn it is not `TALK`'s, because a PC
|
||||||
|
// pressed before Bill has asked prints the monitor and would be in the talked ledger for good.
|
||||||
|
let mut world = bills_house().at(1, 5);
|
||||||
|
world.facing = Facing::Up;
|
||||||
|
assert!(!on_the_pad(&mut world, MacroKind::Talk));
|
||||||
|
assert_eq!(super::palette::facing_target(&mut world), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_hidden_event_is_the_errands_next_step_once_no_person_is_left_and_it_is_faced_from_its_side() {
|
||||||
|
// Bill has asked and walked into the machine: the cartridge has hidden his sprite and nobody
|
||||||
|
// else is in the room. The next step is the cell separator's PC, which no sprite or sign
|
||||||
|
// stands for -- the hidden event the scout pressed by hand on the cartridge (row 73).
|
||||||
|
let mut world = bills_house().at(3, 5);
|
||||||
|
world.npcs.clear();
|
||||||
|
world.talked.insert(TalkTarget::Sprite(1));
|
||||||
|
assert_eq!(super::palette::objective_targets(&mut world), vec![(Tile::new(1, 4), TalkTarget::Hidden(0))]);
|
||||||
|
assert!(!on_the_pad(&mut world, MacroKind::GoOut), "still not left: the PC is waiting");
|
||||||
|
// `BillsHousePC` answers only a player facing up, so the walk's one aim is the tile below it.
|
||||||
|
let aims: Vec<(Tile, Option<Facing>)> =
|
||||||
|
objective_goals(&mut world).iter().map(|aim| (aim.tile, aim.face)).collect();
|
||||||
|
assert_eq!(aims, vec![(Tile::new(1, 5), Some(Facing::Up))]);
|
||||||
|
|
||||||
|
// Beside it, facing it sideways, is not the arrival: nothing would answer the press.
|
||||||
|
let mut beside = bills_house().at(2, 4);
|
||||||
|
beside.npcs.clear();
|
||||||
|
beside.talked.insert(TalkTarget::Sprite(1));
|
||||||
|
beside.facing = Facing::Left;
|
||||||
|
assert!(!on_the_pad(&mut beside, MacroKind::Talk));
|
||||||
|
assert!(on_the_pad(&mut beside, MacroKind::GoObjective));
|
||||||
|
|
||||||
|
// Below it, facing up: `TALK` is the press and the walk is done.
|
||||||
|
let mut below = bills_house().at(1, 5);
|
||||||
|
below.npcs.clear();
|
||||||
|
below.talked.insert(TalkTarget::Sprite(1));
|
||||||
|
below.facing = Facing::Up;
|
||||||
|
assert_eq!(super::palette::facing_target(&mut below), Some(TalkTarget::Hidden(0)));
|
||||||
|
assert!(on_the_pad(&mut below, MacroKind::Talk));
|
||||||
|
assert!(!on_the_pad(&mut below, MacroKind::GoObjective));
|
||||||
|
|
||||||
|
// Pressed: Bill steps out of the machine, and he is the errand's last step.
|
||||||
|
below.talked.insert(TalkTarget::Hidden(0));
|
||||||
|
below.npcs = vec![Npc { slot: 2, picture: 0x13, x: 4, y: 4, facing: Facing::Down }];
|
||||||
|
assert_eq!(super::palette::objective_targets(&mut below), vec![(Tile::new(4, 4), TalkTarget::Sprite(2))]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_hidden_event_is_nobody_elses_target() {
|
||||||
|
// A hidden event is every PC, poster and trash can in Kanto. Outside the errand that names it
|
||||||
|
// no macro aims at one and `TALK` is not dealt in front of one: `GO ITEM` is what it was.
|
||||||
|
let mut world = bills_house().at(1, 5);
|
||||||
|
world.npcs.clear();
|
||||||
|
world.facing = Facing::Up;
|
||||||
|
world.objective = Some(Objective { map: maps::ROUTE_25, tile: None, warp: None, edge: None, target: None });
|
||||||
|
assert!(super::palette::untalked_objects(&mut world).is_empty());
|
||||||
|
assert!(!on_the_pad(&mut world, MacroKind::GoItem));
|
||||||
|
assert!(!on_the_pad(&mut world, MacroKind::Talk));
|
||||||
|
assert_eq!(super::palette::facing_target(&mut world), None);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,12 +84,22 @@ pub const MT_MOON_1F: u8 = 0x3b;
|
||||||
pub const MT_MOON_B1F: u8 = 0x3c;
|
pub const MT_MOON_B1F: u8 = 0x3c;
|
||||||
pub const MT_MOON_B2F: u8 = 0x3d;
|
pub const MT_MOON_B2F: u8 = 0x3d;
|
||||||
pub const CERULEAN_POKECENTER: u8 = 0x40;
|
pub const CERULEAN_POKECENTER: u8 = 0x40;
|
||||||
|
/// The house the Rockets robbed (row 73): the id before `CERULEAN_TRADE_HOUSE` and
|
||||||
|
/// `CERULEAN_POKECENTER` `$40`, and confirmed by the cartridge rather than by counting -- Cerulean
|
||||||
|
/// City's warp table names `$3e` at (27, 11) and at (27, 9), its front door and the hole in its
|
||||||
|
/// back wall.
|
||||||
|
pub const CERULEAN_TRASHED_HOUSE: u8 = 0x3e;
|
||||||
pub const CERULEAN_GYM: u8 = 0x41;
|
pub const CERULEAN_GYM: u8 = 0x41;
|
||||||
pub const CERULEAN_MART: u8 = 0x43;
|
pub const CERULEAN_MART: u8 = 0x43;
|
||||||
/// Route 4's Pokémon Center, the one beside Mt. Moon's mouth: the id straight after
|
/// Route 4's Pokémon Center, the one beside Mt. Moon's mouth: the id straight after
|
||||||
/// `CERULEAN_MART` `$43`, and confirmed by the cartridge rather than by counting -- Route 4's warp
|
/// `CERULEAN_MART` `$43`, and confirmed by the cartridge rather than by counting -- Route 4's warp
|
||||||
/// table names `$44` at (11, 5) (`tests/rom_macros_mode.rs`, row 59's door survey).
|
/// table names `$44` at (11, 5) (`tests/rom_macros_mode.rs`, row 59's door survey).
|
||||||
pub const MT_MOON_POKECENTER: u8 = 0x44;
|
pub const MT_MOON_POKECENTER: u8 = 0x44;
|
||||||
|
/// Bill's house on Route 25, where rung 16 (the S.S. Ticket) is earned (row 73). Confirmed by the
|
||||||
|
/// cartridge rather than by counting: Route 25's warp table names `$58` at (45, 3), and the
|
||||||
|
/// cartridge's own hidden-event map list (`HiddenEventMaps`) carries `$58` at the position the
|
||||||
|
/// disassembly lists `BILLS_HOUSE` in (`tests/rom_macros_mode.rs`, row 73).
|
||||||
|
pub const BILLS_HOUSE: u8 = 0x58;
|
||||||
pub const ROCK_TUNNEL_1F: u8 = 0x52;
|
pub const ROCK_TUNNEL_1F: u8 = 0x52;
|
||||||
pub const INDIGO_PLATEAU_LOBBY: u8 = 0xae;
|
pub const INDIGO_PLATEAU_LOBBY: u8 = 0xae;
|
||||||
/// The house beside Cerulean's west road whose back door is the one way into the closed yard at
|
/// The house beside Cerulean's west road whose back door is the one way into the closed yard at
|
||||||
|
|
|
||||||
|
|
@ -222,6 +222,10 @@ const RUNG_PLACES: [Option<MapPlace>; RANK_LADDER.len()] = {
|
||||||
const fn object(map: u8) -> Option<MapPlace> {
|
const fn object(map: u8) -> Option<MapPlace> {
|
||||||
Some(MapPlace::object(map))
|
Some(MapPlace::object(map))
|
||||||
}
|
}
|
||||||
|
/// A rung earned by an errand in one room: its people, then its things.
|
||||||
|
const fn errand(map: u8) -> Option<MapPlace> {
|
||||||
|
Some(MapPlace::errand(map))
|
||||||
|
}
|
||||||
[
|
[
|
||||||
None, // 0 BOOT: nowhere.
|
None, // 0 BOOT: nowhere.
|
||||||
at(maps::REDS_HOUSE_2F), // 1 BEDROOM
|
at(maps::REDS_HOUSE_2F), // 1 BEDROOM
|
||||||
|
|
@ -244,7 +248,12 @@ const RUNG_PLACES: [Option<MapPlace>; RANK_LADDER.len()] = {
|
||||||
at(maps::CERULEAN_CITY), // 13 CERULEAN CITY
|
at(maps::CERULEAN_CITY), // 13 CERULEAN CITY
|
||||||
person(maps::CERULEAN_GYM), // 14 CASCADE BADGE, likewise
|
person(maps::CERULEAN_GYM), // 14 CASCADE BADGE, likewise
|
||||||
at(maps::ROUTE_24), // 15 NUGGET BRIDGE, north out of Cerulean
|
at(maps::ROUTE_24), // 15 NUGGET BRIDGE, north out of Cerulean
|
||||||
at(maps::ROUTE_25), // 16 MET BILL, whose house is on Route 25
|
// 16 MET BILL: the S.S. Ticket is Bill's thanks for an errand in his house -- talk to
|
||||||
|
// him (he is a Pokémon), press the cell separator's PC (a hidden event, not a sprite),
|
||||||
|
// talk to him again. One room, people then things: an errand (row 73). It was
|
||||||
|
// `at(ROUTE_25)`, and a fly on Route 25 was already "there", so inside the house
|
||||||
|
// `GO OBJECTIVE` was the door out to the route.
|
||||||
|
errand(maps::BILLS_HOUSE),
|
||||||
at(maps::VERMILION_CITY), // 17 VERMILION CITY
|
at(maps::VERMILION_CITY), // 17 VERMILION CITY
|
||||||
at(maps::VERMILION_CITY), // 18 HM CUT, on the S.S. Anne at Vermilion's dock
|
at(maps::VERMILION_CITY), // 18 HM CUT, on the S.S. Anne at Vermilion's dock
|
||||||
None, // 19 THUNDER BADGE: Vermilion Gym, id not derived
|
None, // 19 THUNDER BADGE: Vermilion Gym, id not derived
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ use super::macros::geography::Amenity;
|
||||||
use super::mapgrid::{self, MapGrids};
|
use super::mapgrid::{self, MapGrids};
|
||||||
use super::macros::state::{
|
use super::macros::state::{
|
||||||
BagItem, Battle, BattleKind, BattleMenu, Connections, Cursor, EnemyMon, Facing, GameState,
|
BagItem, Battle, BattleKind, BattleMenu, Connections, Cursor, EnemyMon, Facing, GameState,
|
||||||
MapGrid, MapSize, Mon, Move, Naming, Npc, Party, Pc, Player, Scene, Shop, ShopScreen, Sign, StartMenu,
|
HiddenEvent, MapGrid, MapSize, Mon, Move, Naming, Npc, Party, Pc, Player, Scene, Shop, ShopScreen, Sign, StartMenu,
|
||||||
Status, TextBox, Walkable, Warp,
|
Status, TextBox, Walkable, Warp,
|
||||||
};
|
};
|
||||||
use super::symbols::ram;
|
use super::symbols::ram;
|
||||||
|
|
@ -350,6 +350,31 @@ pub mod poke {
|
||||||
|
|
||||||
/// The cartridge's item-use dispatch and the ids that name its routines (row 63,
|
/// The cartridge's item-use dispatch and the ids that name its routines (row 63,
|
||||||
/// `docs/design/macros.md` 12.27).
|
/// `docs/design/macros.md` 12.27).
|
||||||
|
/// The cartridge's hidden-event tables (row 73, `docs/design/macros.md` 12.35).
|
||||||
|
///
|
||||||
|
/// `engine/overworld/hidden_events.asm`: `CheckForHiddenEvent` walks `HiddenEventMaps`, one
|
||||||
|
/// map id per byte to a `$ff`, and with the index it found there reads a little-endian pointer
|
||||||
|
/// out of `HiddenEventPointers` to that map's list. Both tables and every list are in the
|
||||||
|
/// routine's own `SECTION "Hidden Events Core"`, which `layout.link` places in ROM bank `$11`.
|
||||||
|
/// At the pinned commit the two tables are at `$11:$6A40` and `$11:$6A96`: read from the
|
||||||
|
/// operands of the routine's `ld hl, HiddenEventMaps` and `ld hl, HiddenEventPointers` on the
|
||||||
|
/// cartridge, and pinned by the ROM-gated test that reads them back from there. A list entry is
|
||||||
|
/// six bytes (`hidden_event`): y, x, the routine's argument, and the routine as `dba`.
|
||||||
|
pub mod hidden {
|
||||||
|
pub const TABLE_BANK: u8 = 0x11;
|
||||||
|
pub const MAPS_ADDRESS: u16 = 0x6a40;
|
||||||
|
pub const POINTERS_ADDRESS: u16 = 0x6a96;
|
||||||
|
pub const ENTRY_BYTES: u16 = 6;
|
||||||
|
/// More maps than the table has (85 at the pinned commit), and more entries than any one
|
||||||
|
/// map's list (the Game Corner's 48 slot machines and coins are the longest): a walk that
|
||||||
|
/// runs past either is not walking the table the disassembly describes, and answers
|
||||||
|
/// nothing.
|
||||||
|
pub const MAX_MAPS: u16 = 128;
|
||||||
|
pub const MAX_ENTRIES: u16 = 64;
|
||||||
|
/// `SPRITE_FACING_DOWN`, `_UP`, `_LEFT`, `_RIGHT` (`constants/sprite_data_constants.asm`).
|
||||||
|
pub const FACINGS: [u8; 4] = [0x00, 0x04, 0x08, 0x0c];
|
||||||
|
}
|
||||||
|
|
||||||
pub mod items {
|
pub mod items {
|
||||||
/// `engine/items/item_effects.asm`: `UseItem_` jumps through `ItemUsePtrTable`, one
|
/// `engine/items/item_effects.asm`: `UseItem_` jumps through `ItemUsePtrTable`, one
|
||||||
/// little-endian pointer per item id from `MASTER_BALL` (1) to `MAX_ELIXER` (`$53`), in
|
/// little-endian pointer per item id from `MASTER_BALL` (1) to `MAX_ELIXER` (`$53`), in
|
||||||
|
|
@ -2055,6 +2080,60 @@ pub fn signs(memory: &mut dyn MemoryReader) -> Vec<Sign> {
|
||||||
signs
|
signs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The current map's hidden events, read from the cartridge's own table ([`poke::hidden`]).
|
||||||
|
///
|
||||||
|
/// Empty on a map the table does not list, when the seam has no cartridge image behind it, and
|
||||||
|
/// when the bytes are not the shape the disassembly describes -- a map list with no end, a pointer
|
||||||
|
/// outside the bank's window, a list longer than any map's, a tile off the loaded map. A table
|
||||||
|
/// this module cannot read is not one it reports, so a wrong address narrows (`GO OBJECTIVE` has
|
||||||
|
/// one less thing to aim at) and never invents a tile.
|
||||||
|
pub fn hidden_events(memory: &mut dyn MemoryReader) -> Vec<HiddenEvent> {
|
||||||
|
hidden_events_inner(memory).unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hidden_events_inner(memory: &mut dyn MemoryReader) -> Option<Vec<HiddenEvent>> {
|
||||||
|
use poke::hidden::*;
|
||||||
|
let size = map_size(memory)?;
|
||||||
|
let map = read(memory, ram::wCurMap);
|
||||||
|
let mut index = None;
|
||||||
|
for position in 0..MAX_MAPS {
|
||||||
|
let id = memory.read_rom(TABLE_BANK, MAPS_ADDRESS + position)?;
|
||||||
|
if id == 0xff {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if id > poke::MAX_MAP_ID || position + 1 == MAX_MAPS {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
if id == map && index.is_none() {
|
||||||
|
index = Some(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let Some(position) = index else { return Some(Vec::new()) };
|
||||||
|
let at = POINTERS_ADDRESS + 2 * position;
|
||||||
|
let list = u16::from_le_bytes([memory.read_rom(TABLE_BANK, at)?, memory.read_rom(TABLE_BANK, at + 1)?]);
|
||||||
|
if !(0x4000..0x8000).contains(&list) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let mut out = Vec::new();
|
||||||
|
for entry in 0..MAX_ENTRIES {
|
||||||
|
let base = list.checked_add(entry * ENTRY_BYTES)?;
|
||||||
|
let y = memory.read_rom(TABLE_BANK, base)?;
|
||||||
|
if y == 0xff {
|
||||||
|
return Some(out);
|
||||||
|
}
|
||||||
|
let x = memory.read_rom(TABLE_BANK, base + 1)?;
|
||||||
|
let argument = memory.read_rom(TABLE_BANK, base + 2)?;
|
||||||
|
let routine =
|
||||||
|
u16::from_le_bytes([memory.read_rom(TABLE_BANK, base + 4)?, memory.read_rom(TABLE_BANK, base + 5)?]);
|
||||||
|
if x >= size.width || y >= size.height || routine >= 0x8000 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let facing = FACINGS.contains(&argument).then(|| facing_from(argument));
|
||||||
|
out.push(HiddenEvent { x, y, index: entry as u8, facing });
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/// Which of the current map's edges lead to another map, from `wCurMapConnections`.
|
/// Which of the current map's edges lead to another map, from `wCurMapConnections`.
|
||||||
pub fn connections(memory: &mut dyn MemoryReader) -> Connections {
|
pub fn connections(memory: &mut dyn MemoryReader) -> Connections {
|
||||||
let bits = read(memory, ram::wCurMapConnections);
|
let bits = read(memory, ram::wCurMapConnections);
|
||||||
|
|
@ -2245,6 +2324,10 @@ impl GameState for PokeState<'_> {
|
||||||
signs(self.memory)
|
signs(self.memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn hidden_events(&mut self) -> Vec<HiddenEvent> {
|
||||||
|
hidden_events(self.memory)
|
||||||
|
}
|
||||||
|
|
||||||
fn walkable(&mut self, x: u8, y: u8) -> Walkable {
|
fn walkable(&mut self, x: u8, y: u8) -> Walkable {
|
||||||
walkable(self.memory, x, y)
|
walkable(self.memory, x, y)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1273,6 +1273,8 @@ fn the_objective_is_the_next_unreached_rungs_place_where_the_catalog_knows_one()
|
||||||
assert_eq!(RUNG_PLACES[11].map(|place| place.map), Some(maps::PEWTER_GYM), "BOULDER BADGE");
|
assert_eq!(RUNG_PLACES[11].map(|place| place.map), Some(maps::PEWTER_GYM), "BOULDER BADGE");
|
||||||
assert_eq!(RUNG_PLACES[14].map(|place| place.map), Some(maps::CERULEAN_GYM), "CASCADE BADGE");
|
assert_eq!(RUNG_PLACES[14].map(|place| place.map), Some(maps::CERULEAN_GYM), "CASCADE BADGE");
|
||||||
assert_eq!(RUNG_PLACES[19], None, "THUNDER BADGE: Vermilion Gym's id is not derived");
|
assert_eq!(RUNG_PLACES[19], None, "THUNDER BADGE: Vermilion Gym's id is not derived");
|
||||||
|
// Row 73: the ticket is an errand inside Bill's house, not the route the house is on.
|
||||||
|
assert_eq!(RUNG_PLACES[16], Some(crate::adapter::MapPlace::errand(maps::BILLS_HOUSE)), "MET BILL");
|
||||||
// And past the top of the ladder there is no next rung at all.
|
// And past the top of the ladder there is no next rung at all.
|
||||||
assert_eq!(RUNG_PLACES.len(), RANK_LADDER.len());
|
assert_eq!(RUNG_PLACES.len(), RANK_LADDER.len());
|
||||||
assert_eq!(rung_place(&f.reward.seen, RANK_LADDER.len()), None);
|
assert_eq!(rung_place(&f.reward.seen, RANK_LADDER.len()), None);
|
||||||
|
|
|
||||||
|
|
@ -589,6 +589,72 @@ both_transports!(
|
||||||
hello_reports_the_contract_digest_and_valid_limits,
|
hello_reports_the_contract_digest_and_valid_limits,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
// Review note N3 (BUS-01): the SDK refuses a router whose contract digest is not its own, at
|
||||||
|
// Hello, with the explicit version-mismatch error. The wire change that added `readLocation`
|
||||||
|
// moved the digest, so a client and router built from different sources must not talk.
|
||||||
|
|
||||||
|
/// Serves one Hello on `server` the way the router does, announcing `digest`.
|
||||||
|
async fn answer_hello_with(server: tokio::io::DuplexStream, digest: String) {
|
||||||
|
let (mut rd, mut wr) = tokio::io::split(server);
|
||||||
|
let bytes = read_frame(&mut rd).await.unwrap().expect("a hello frame");
|
||||||
|
let hello = Envelope::decode(&bytes).unwrap();
|
||||||
|
assert_eq!(hello.op, "bus.hello");
|
||||||
|
let value = json!({
|
||||||
|
"routerId": "router-1", "connectionId": "conn-1",
|
||||||
|
"selectedMajor": 1, "selectedMinor": 0,
|
||||||
|
"contractDigest": digest,
|
||||||
|
"limits": Limits::default().to_json(),
|
||||||
|
});
|
||||||
|
let mut body = Map::new();
|
||||||
|
body.insert("ok".into(), json!(true));
|
||||||
|
body.insert("value".into(), value);
|
||||||
|
let mut reply = Envelope::new("bus-1".into(), Kind::Reply, "bus.hello", body);
|
||||||
|
reply.reply_to = Some(hello.id);
|
||||||
|
write_frame(&mut wr, &reply.encode().unwrap()).await.unwrap();
|
||||||
|
// Keep the connection open until the client has decided.
|
||||||
|
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn a_client_refuses_a_router_with_a_different_contract_digest_at_hello() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let wrong = "0".repeat(64);
|
||||||
|
assert_ne!(wrong, contract_digest());
|
||||||
|
let (client_end, server_end) = tokio::io::duplex(64 * 1024);
|
||||||
|
tokio::spawn(answer_hello_with(server_end, wrong));
|
||||||
|
let refused = within(
|
||||||
|
"hello",
|
||||||
|
flybus::Client::connect(
|
||||||
|
flybus::Transport::from_stream(client_end),
|
||||||
|
flybus::ClientConfig::new("digest-client", dir.path()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let Err(err) = refused else {
|
||||||
|
panic!("a mismatched digest must be refused");
|
||||||
|
};
|
||||||
|
assert_eq!(err.code, flybus::ErrorCode::VersionMismatch);
|
||||||
|
assert_eq!(err.message, "router speaks a different contract");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn the_same_fake_router_with_the_right_digest_is_accepted() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let (client_end, server_end) = tokio::io::duplex(64 * 1024);
|
||||||
|
tokio::spawn(answer_hello_with(server_end, contract_digest()));
|
||||||
|
let client = within(
|
||||||
|
"hello",
|
||||||
|
flybus::Client::connect(
|
||||||
|
flybus::Transport::from_stream(client_end),
|
||||||
|
flybus::ClientConfig::new("digest-client", dir.path()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("a matching digest is accepted");
|
||||||
|
assert_eq!(client.info().contract_digest, contract_digest());
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
// bus-v1 §11 acceptance test 1: "In-memory transport must pass the same tests as Unix
|
// bus-v1 §11 acceptance test 1: "In-memory transport must pass the same tests as Unix
|
||||||
// sockets." Every test above already runs on both (that is what `both_transports!` is for);
|
// sockets." Every test above already runs on both (that is what `both_transports!` is for);
|
||||||
|
|
|
||||||
|
|
@ -361,9 +361,10 @@ async fn the_service_streams_takes_sugar_checkpoints_and_resumes_after_being_kil
|
||||||
let feed_hz = (headers.len() - 1) as f64 * 1000.0 / published_span_ms;
|
let feed_hz = (headers.len() - 1) as f64 * 1000.0 / published_span_ms;
|
||||||
let arrival_hz = (headers.len() - 1) as f64 / first_at.elapsed().as_secs_f64();
|
let arrival_hz = (headers.len() - 1) as f64 / first_at.elapsed().as_secs_f64();
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"[timing] {} snapshots published over {:.3} s: {feed_hz:.2} Hz (contract: 30 Hz while\n\
|
"[timing] {} snapshots published over {:.3} s: {feed_hz:.2} Hz (contract: a 30 Hz wall-clock\n\
|
||||||
\x20 running; the ceiling is one snapshot per two 16.74 ms emulator frames,\n\
|
\x20 timer while running; one snapshot per loop pass at most, so the rate is the\n\
|
||||||
\x20 29.86 Hz). Client-side arrival rate {arrival_hz:.2} Hz.",
|
\x20 timer's on an idle box and falls with the box's load). Client-side arrival\n\
|
||||||
|
\x20 rate {arrival_hz:.2} Hz.",
|
||||||
headers.len(),
|
headers.len(),
|
||||||
published_span_ms / 1000.0
|
published_span_ms / 1000.0
|
||||||
);
|
);
|
||||||
|
|
@ -371,12 +372,29 @@ async fn the_service_streams_takes_sugar_checkpoints_and_resumes_after_being_kil
|
||||||
"[timing] first snapshot {:.3} s after connecting",
|
"[timing] first snapshot {:.3} s after connecting",
|
||||||
first_at.duration_since(connected_at).as_secs_f64()
|
first_at.duration_since(connected_at).as_secs_f64()
|
||||||
);
|
);
|
||||||
|
// The publish cadence is a wall-clock timer (`docs/feed-protocol.md`: "30 snapshots per
|
||||||
|
// second wall-clock while running"), so how many emulator frames sit between two snapshots
|
||||||
|
// is not fixed: 2 on an idle box (33.5 ms), but 1 or 3 whenever the timer and the 16.74 ms
|
||||||
|
// frame clock drift against each other, and 1 per snapshot for most of a run when the box is
|
||||||
|
// loaded and the loop is behind real time. Asserting 25..31 Hz here failed ~1 run in 3 with
|
||||||
|
// sibling tests booting sims in parallel (22.5 Hz in the v0.7.6 gate). The wall rate is
|
||||||
|
// therefore only logged, with a bound that tells "running" from the 2 Hz idle path.
|
||||||
assert!(
|
assert!(
|
||||||
(25.0..31.0).contains(&feed_hz),
|
feed_hz > 2.5,
|
||||||
"the feed published at {feed_hz:.2} Hz, which is not the contract's 30 Hz"
|
"the feed published at {feed_hz:.2} Hz, which is the paused/booting cadence, not a running one"
|
||||||
);
|
);
|
||||||
|
// What is deterministic is the structure: contiguous seq, the emulator advancing at least one
|
||||||
|
// frame per snapshot, and the brain clock advancing exactly with the frames it ran (the
|
||||||
|
// 1 ms kernel takes 16 or 17 ticks per 16.74 ms frame, carrying the remainder).
|
||||||
for pair in headers.windows(2) {
|
for pair in headers.windows(2) {
|
||||||
assert_eq!(pair[1].seq, pair[0].seq + 1, "a snapshot was dropped between publishes");
|
assert_eq!(pair[1].seq, pair[0].seq + 1, "a snapshot was dropped between publishes");
|
||||||
|
let frames = pair[1].frame.checked_sub(pair[0].frame).expect("frame went backwards");
|
||||||
|
assert!(frames >= 1, "a running snapshot with no emulator frame behind it");
|
||||||
|
let brain = pair[1].brain_ms - pair[0].brain_ms;
|
||||||
|
assert!(
|
||||||
|
(16.0 * frames as f64 - 0.5..=17.0 * frames as f64 + 0.5).contains(&brain),
|
||||||
|
"{brain} ms of brain time over {frames} frames, expected 16 or 17 ticks each"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
let (_, metrics) = http_blocking(service.control_port, "GET", "/metrics", None).unwrap();
|
let (_, metrics) = http_blocking(service.control_port, "GET", "/metrics", None).unwrap();
|
||||||
for name in ["fly_lag_seconds", "fly_realtime_factor", "fly_feed_clients"] {
|
for name in ["fly_lag_seconds", "fly_realtime_factor", "fly_feed_clients"] {
|
||||||
|
|
@ -620,7 +638,12 @@ async fn the_service_streams_takes_sugar_checkpoints_and_resumes_after_being_kil
|
||||||
.expect("open")
|
.expect("open")
|
||||||
.expect("readable");
|
.expect("readable");
|
||||||
if let Message::Binary(bytes) = message {
|
if let Message::Binary(bytes) = message {
|
||||||
resumed = Some(split(&bytes).0);
|
// `/healthz` can answer while the first thing on the feed is still the 2 Hz boot
|
||||||
|
// header (frame 0, before the restore reaches the loop): wait for a running one.
|
||||||
|
let header = split(&bytes).0;
|
||||||
|
if header.status == flysim::snapshot::FeedStatus::Running {
|
||||||
|
resumed = Some(header);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let resumed = resumed.unwrap();
|
let resumed = resumed.unwrap();
|
||||||
|
|
|
||||||
|
|
@ -5132,3 +5132,287 @@ fn row70_the_list_after_a_faint_is_still_a_forced_switch_and_is_answered() {
|
||||||
assert!(turn_after.is_some(), "the forced switch was never answered: {:?}", drive.starts);
|
assert!(turn_after.is_some(), "the forced switch was never answered: {:?}", drive.starts);
|
||||||
assert_eq!(out, 1, "the Pokémon still standing (the Zubat, slot 1) was sent out");
|
assert_eq!(out, 1, "the Pokémon still standing (the Zubat, slot 1) was sent out");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Route 25, Bill's house on it, and the flag rung 16 is (`constants/map_constants.asm`,
|
||||||
|
/// `constants/event_constants.asm`; `docs/design/ladder.md` verified bit 1372).
|
||||||
|
const ROUTE_25: u32 = 0x24;
|
||||||
|
const BILLS_HOUSE: u32 = 0x58;
|
||||||
|
const EVENT_GOT_SS_TICKET: u16 = 1372;
|
||||||
|
|
||||||
|
/// A row-73 checkpoint named by `var`, or `None` to skip.
|
||||||
|
///
|
||||||
|
/// Scout B3's, from the v0.7.5 tree and the live row-71 checkpoint (rung 15), plus the live one
|
||||||
|
/// itself (`FLY_ROW71_CHECKPOINT`, rom-env's existing name):
|
||||||
|
///
|
||||||
|
/// - `FLY_ROW73_DOOR_CHECKPOINT` (`scout-b3-bills-ring-door`): the same ring, just inside the door.
|
||||||
|
/// - `FLY_ROW73_PC_CHECKPOINT` (`scout-b3-bills-pc-step`): a carry-forward by scripted presses --
|
||||||
|
/// Bill has asked for the cell separator and walked into the machine, and the next step is the
|
||||||
|
/// PC, a hidden event no sprite or sign stands for.
|
||||||
|
fn row73_checkpoint(var: &str) -> Option<flysim::store::Checkpoint> {
|
||||||
|
std::env::var_os(var).map(|path| {
|
||||||
|
flysim::store::load(std::path::Path::new(&path))
|
||||||
|
.expect("the checkpoint should be a FLYSIM01 envelope")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Row 73: the hidden-event table the macros read is the cartridge's own, and Bill's PC is in it.
|
||||||
|
///
|
||||||
|
/// The two addresses are pinned the way `ItemUsePtrTable`'s is: they are the operands of
|
||||||
|
/// `CheckForHiddenEvent`'s own `ld hl, HiddenEventMaps` (followed by its `ld a, [hli] / ld b, a /
|
||||||
|
/// cp $ff`) and `ld hl, HiddenEventPointers` (followed by `add hl, de`), found in the routine's
|
||||||
|
/// bank. Then, standing in Bill's house, the seam reads one hidden event, the PC at (1, 4), pressed
|
||||||
|
/// facing up -- the entry the scout's scripted presses found by hand.
|
||||||
|
#[test]
|
||||||
|
fn row73_the_hidden_event_table_is_the_cartridges_and_bills_pc_is_in_it() {
|
||||||
|
use flybrain_gb::pokemon_red::macros::state::{Facing, HiddenEvent};
|
||||||
|
use flybrain_gb::pokemon_red::state::{self, poke::hidden};
|
||||||
|
let rom = skip_without_rom!();
|
||||||
|
let gb = emulator(&rom);
|
||||||
|
let bank: Vec<u8> = (0x4000u16..0x8000)
|
||||||
|
.map(|address| gb.read_rom_bank(hidden::TABLE_BANK, address).expect("bank $11 is in the image"))
|
||||||
|
.collect();
|
||||||
|
let [maps_low, maps_high] = hidden::MAPS_ADDRESS.to_le_bytes();
|
||||||
|
let [pointers_low, pointers_high] = hidden::POINTERS_ADDRESS.to_le_bytes();
|
||||||
|
let maps_load = [0x21, maps_low, maps_high, 0x2a, 0x47, 0xfe, 0xff];
|
||||||
|
let pointers_load = [0x21, pointers_low, pointers_high, 0x19];
|
||||||
|
let at = |needle: &[u8]| bank.windows(needle.len()).position(|window| window == needle);
|
||||||
|
let maps_at = at(&maps_load).expect("CheckForHiddenEvent loads HiddenEventMaps from the pinned address");
|
||||||
|
let pointers_at =
|
||||||
|
at(&pointers_load).expect("CheckForHiddenEvent loads HiddenEventPointers from the pinned address");
|
||||||
|
assert!(pointers_at > maps_at && pointers_at - maps_at < 32, "one routine: {maps_at:#x} {pointers_at:#x}");
|
||||||
|
// Every map's list ends inside the bounds `state::hidden_events` holds the table to, so no map's
|
||||||
|
// events are refused for being long (the Game Corner's 48 are the longest).
|
||||||
|
let byte = |address: u16| bank[usize::from(address - 0x4000)];
|
||||||
|
let mut maps = 0u16;
|
||||||
|
while byte(hidden::MAPS_ADDRESS + maps) != 0xff {
|
||||||
|
assert!(maps < hidden::MAX_MAPS, "the map list ends");
|
||||||
|
let at = hidden::POINTERS_ADDRESS + 2 * maps;
|
||||||
|
let list = u16::from_le_bytes([byte(at), byte(at + 1)]);
|
||||||
|
let entries = (0..).take_while(|entry| byte(list + entry * hidden::ENTRY_BYTES) != 0xff).count();
|
||||||
|
assert!(entries < usize::from(hidden::MAX_ENTRIES), "map {:#04x}: {entries}", byte(hidden::MAPS_ADDRESS + maps));
|
||||||
|
maps += 1;
|
||||||
|
}
|
||||||
|
assert_eq!(maps, 85, "the pinned commit's 85 maps with hidden events");
|
||||||
|
|
||||||
|
let Some(checkpoint) = row73_checkpoint("FLY_ROW73_DOOR_CHECKPOINT") else {
|
||||||
|
eprintln!("skipped: no FLY_ROW73_DOOR_CHECKPOINT");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint);
|
||||||
|
assert_eq!(run.map(), BILLS_HOUSE, "the checkpoint is inside Bill's house");
|
||||||
|
assert_eq!(
|
||||||
|
state::hidden_events(&mut run.gb),
|
||||||
|
vec![HiddenEvent { x: 1, y: 4, index: 0, facing: Some(Facing::Up) }],
|
||||||
|
"Bill's house has one hidden event, the cell separator's PC"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Row 73, the trap: from inside the ring at Bill's door, macros mode earns rung 16 (the S.S.
|
||||||
|
/// Ticket).
|
||||||
|
///
|
||||||
|
/// **Live on v0.7.5** (scout B3, six seeds, 2.8 brain hours): rung 16's place was `at(ROUTE_25)`,
|
||||||
|
/// so a fly on Route 25 was already "there". `GO ROUTE` walked it into Bill's house, and inside
|
||||||
|
/// `GO OBJECTIVE` -- an exit into the objective's own map is toward it -- and `GO OUT` walked it
|
||||||
|
/// straight back out, 30 to 60 times per ten brain minutes; `GO NPC` was chosen 0 times in about
|
||||||
|
/// 600 starts in the house. Behind that, the errand's middle step is the cell separator's PC, a
|
||||||
|
/// hidden event no macro could press, so even a fly that talked to Bill could not earn the rung.
|
||||||
|
///
|
||||||
|
/// The claims, over the stub rotation (no brain, a readout that never names a macro): the fly
|
||||||
|
/// does not leave the house before the errand is done, and `EVENT_GOT_SS_TICKET` is set within the
|
||||||
|
/// budget. On main the flag is never set.
|
||||||
|
///
|
||||||
|
/// ```sh
|
||||||
|
/// FLY_ROM=/path/to/pokemon-red.gb \
|
||||||
|
/// FLY_ROW73_DOOR_CHECKPOINT=.local/checkpoints/scout-b3-bills-ring-door.checkpoint \
|
||||||
|
/// cargo test --release -p flysim --test rom_macros_mode -- --nocapture row73
|
||||||
|
/// ```
|
||||||
|
#[test]
|
||||||
|
fn row73_the_fly_earns_the_ss_ticket_from_inside_the_ring_at_bills_door() {
|
||||||
|
let rom = skip_without_rom!();
|
||||||
|
let Some(checkpoint) = row73_checkpoint("FLY_ROW73_DOOR_CHECKPOINT") else {
|
||||||
|
eprintln!("skipped: no FLY_ROW73_DOOR_CHECKPOINT");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint);
|
||||||
|
assert_eq!(run.map(), BILLS_HOUSE, "the checkpoint is inside Bill's house");
|
||||||
|
assert!(!run.event(EVENT_GOT_SS_TICKET), "the checkpoint has no ticket");
|
||||||
|
let (_, out) = row73_drive_to_the_ticket(&mut run, 36_000);
|
||||||
|
assert_eq!(out, 0, "the house was left before the errand was done");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Row 73, the whole road: from the live row-71 checkpoint (v0.7.3, rung 15, in a wild battle on
|
||||||
|
/// Route 25) macros mode finishes the battle, walks to Bill's house and earns the ticket. Route
|
||||||
|
/// 25's own warp table is what pins `maps::BILLS_HOUSE`.
|
||||||
|
#[test]
|
||||||
|
fn row73_the_fly_walks_from_the_live_route_25_checkpoint_to_the_ss_ticket() {
|
||||||
|
let rom = skip_without_rom!();
|
||||||
|
let Some(checkpoint) = row73_checkpoint("FLY_ROW71_CHECKPOINT") else {
|
||||||
|
eprintln!("skipped: no FLY_ROW71_CHECKPOINT");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint);
|
||||||
|
assert_eq!(run.gb.read_wram(flybrain_gb::pokemon_red::symbols::ram::wCurMap), ROUTE_25 as u8);
|
||||||
|
assert!(!run.event(EVENT_GOT_SS_TICKET), "the checkpoint has no ticket");
|
||||||
|
let warps = flybrain_gb::pokemon_red::state::warps(&mut run.gb);
|
||||||
|
assert!(
|
||||||
|
warps.iter().any(|warp| (warp.x, warp.y, u32::from(warp.destination_map)) == (45, 3, BILLS_HOUSE)),
|
||||||
|
"Route 25's door at (45, 3) leads to $58: {warps:?}"
|
||||||
|
);
|
||||||
|
row73_drive_to_the_ticket(&mut run, 216_000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Row 73, the hidden event alone: Bill is in the machine, the next step is the PC, and macros mode
|
||||||
|
/// presses it and earns the ticket. On main no button on any pad presses a hidden event.
|
||||||
|
#[test]
|
||||||
|
fn row73_the_cell_separator_pc_is_pressed_and_bill_hands_over_the_ticket() {
|
||||||
|
let rom = skip_without_rom!();
|
||||||
|
let Some(checkpoint) = row73_checkpoint("FLY_ROW73_PC_CHECKPOINT") else {
|
||||||
|
eprintln!("skipped: no FLY_ROW73_PC_CHECKPOINT");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint);
|
||||||
|
assert_eq!(run.map(), BILLS_HOUSE, "the checkpoint is inside Bill's house");
|
||||||
|
assert!(!run.event(EVENT_GOT_SS_TICKET), "the checkpoint has no ticket");
|
||||||
|
row73_drive_to_the_ticket(&mut run, 36_000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Drive the stub rotation until the ticket's flag is set, counting the house's doors on the way:
|
||||||
|
/// `(into, out)`.
|
||||||
|
fn row73_drive_to_the_ticket(run: &mut Run, budget: u32) -> (u32, u32) {
|
||||||
|
let mut previous = run.map();
|
||||||
|
let (mut into, mut out) = (0u32, 0u32);
|
||||||
|
let mut got = None;
|
||||||
|
for frame in 0..budget {
|
||||||
|
run.frame();
|
||||||
|
let map = run.map();
|
||||||
|
if map != previous && map != u32::MAX {
|
||||||
|
into += u32::from(map == BILLS_HOUSE);
|
||||||
|
out += u32::from(previous == BILLS_HOUSE);
|
||||||
|
previous = map;
|
||||||
|
}
|
||||||
|
if run.event(EVENT_GOT_SS_TICKET) {
|
||||||
|
got = Some(frame);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
eprintln!(
|
||||||
|
"ticket at {got:?} ({:.1} brain minutes), into the house {into} times, out {out}, rank {}, \
|
||||||
|
talk on pad by map {:?}, talk starts {:?}, macros {:?}",
|
||||||
|
run.ms / 60_000.0,
|
||||||
|
run.adapter.progress().rank,
|
||||||
|
run.talk_on_pad_by_map,
|
||||||
|
run.talk_starts_by_map,
|
||||||
|
run.started
|
||||||
|
);
|
||||||
|
assert!(got.is_some(), "no S.S. Ticket in {budget} frames: route {:?}, macros {:?}", run.route, run.started);
|
||||||
|
(into, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
const ROUTE_5: u32 = 0x10;
|
||||||
|
const CERULEAN_TRASHED_HOUSE: u32 = 0x3e;
|
||||||
|
|
||||||
|
/// Where `GO OBJECTIVE` aims from here, read through the seam the macros read: the tiles.
|
||||||
|
fn row73_objective_aims(run: &mut Run) -> Vec<(u8, u8)> {
|
||||||
|
let ledger = AdapterLedger(&run.adapter);
|
||||||
|
let mut state = flybrain_gb::pokemon_red::state::PokeState::with_ledger(&mut run.gb, &ledger);
|
||||||
|
flybrain_gb::pokemon_red::macros::palette::objective_goals(&mut state)
|
||||||
|
.iter()
|
||||||
|
.map(|aim| (aim.tile.x, aim.tile.y))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Row 73's third trap, on the seam: after the ticket, `GO OBJECTIVE` in the town aims at the
|
||||||
|
/// trashed house's front door, and inside the house at the hole in its back wall.
|
||||||
|
///
|
||||||
|
/// On main the house is off the graph: in the town the objective toward Vermilion aimed at ground
|
||||||
|
/// the town's piece cannot reach (scout B3: `blocked` at (17, 28)), and inside the house the only
|
||||||
|
/// way toward an outdoor objective was the front door it came in by. From
|
||||||
|
/// `FLY_ROW73_SOUTH_CHECKPOINT` (`scout-b3-cerulean-south-half`, seed 4, 40 brain minutes, standing
|
||||||
|
/// at (10, 26) in the town's south-west) and `FLY_ROW73_TRASHED_CHECKPOINT` (the same run's seed 6,
|
||||||
|
/// going through the house's front door).
|
||||||
|
#[test]
|
||||||
|
fn row73_the_objective_south_of_cerulean_is_the_trashed_houses_two_doors() {
|
||||||
|
let rom = skip_without_rom!();
|
||||||
|
if let Some(checkpoint) = row73_checkpoint("FLY_ROW73_SOUTH_CHECKPOINT") {
|
||||||
|
let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint);
|
||||||
|
assert_eq!(run.map(), CERULEAN_CITY, "the checkpoint is in Cerulean");
|
||||||
|
assert!(run.event(EVENT_GOT_SS_TICKET), "the checkpoint has the ticket");
|
||||||
|
assert_eq!(row73_objective_aims(&mut run), vec![(27, 11)], "the trashed house's front door");
|
||||||
|
} else {
|
||||||
|
eprintln!("skipped: no FLY_ROW73_SOUTH_CHECKPOINT");
|
||||||
|
}
|
||||||
|
let Some(checkpoint) = row73_checkpoint("FLY_ROW73_TRASHED_CHECKPOINT") else {
|
||||||
|
eprintln!("skipped: no FLY_ROW73_TRASHED_CHECKPOINT");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint);
|
||||||
|
// Through the door with no button down: the warp's tear settles inside the house.
|
||||||
|
for _ in 0..240 {
|
||||||
|
run.gb.set_buttons(0);
|
||||||
|
run.gb.run_frame().expect("a frame should complete");
|
||||||
|
run.ms += MS_PER_FRAME;
|
||||||
|
run.adapter.sample(&mut run.gb, run.ms);
|
||||||
|
}
|
||||||
|
assert_eq!(run.map(), CERULEAN_TRASHED_HOUSE, "inside the trashed house");
|
||||||
|
let warps = flybrain_gb::pokemon_red::state::warps(&mut run.gb);
|
||||||
|
assert!(
|
||||||
|
warps.iter().any(|warp| (warp.x, warp.y, warp.destination_warp) == (3, 0, 7)),
|
||||||
|
"the hole in the back wall is the house's warp to Cerulean's (27, 9): {warps:?}"
|
||||||
|
);
|
||||||
|
assert_eq!(row73_objective_aims(&mut run), vec![(3, 0)], "the hole in the back wall");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Row 73's third trap, after the ticket: the road south out of Cerulean is through the trashed
|
||||||
|
/// house, and macros mode takes it to Route 5.
|
||||||
|
///
|
||||||
|
/// **Scout B3** (six seeds, 43 brain minutes each, from the ticket's carry-forward): 0 of 6 past
|
||||||
|
/// row 28 of Cerulean. The town's ground ends there; Route 5 is on the ground behind the trashed
|
||||||
|
/// house, in by its front door and out by the hole in its back wall, and the house was off the map
|
||||||
|
/// graph -- so `GO OBJECTIVE` toward Vermilion ended `blocked` at (17, 28) and the fly rang between
|
||||||
|
/// the town and its houses, 60 to 100 map changes per ten brain minutes.
|
||||||
|
///
|
||||||
|
/// `FLY_ROW73_TRASHED_CHECKPOINT` (`scout-b3-cerulean-trashed-house`): seed 6, 40 brain minutes
|
||||||
|
/// in, going through the house's front door. `FLY_ROW73_TICKET_CHECKPOINT`
|
||||||
|
/// (`scout-b3-post-bill-ticket`): the carry-forward the Cerulean runs started from, in Bill's
|
||||||
|
/// house with the ticket. The claim from each: the fly is on Route 5 within the budget, and from
|
||||||
|
/// Bill's house in under half of what main needs.
|
||||||
|
#[test]
|
||||||
|
fn row73_the_fly_takes_the_trashed_house_south_to_route_5() {
|
||||||
|
let rom = skip_without_rom!();
|
||||||
|
// Deterministic under the stub: on main the two take 54,442 and 63,880 frames, on the branch
|
||||||
|
// 52,081 and 27,067. The rotation does stumble through the house on main -- `GO ROUTE` takes
|
||||||
|
// every door in turn -- so this is the regression guard, and the seam test above is the claim
|
||||||
|
// main fails.
|
||||||
|
for (var, budget) in [("FLY_ROW73_TRASHED_CHECKPOINT", 72_000u32), ("FLY_ROW73_TICKET_CHECKPOINT", 48_000)] {
|
||||||
|
let Some(checkpoint) = row73_checkpoint(var) else {
|
||||||
|
eprintln!("skipped: no {var}");
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint);
|
||||||
|
assert!(run.event(EVENT_GOT_SS_TICKET), "{var}: the checkpoint has the ticket");
|
||||||
|
let mut previous = run.map();
|
||||||
|
let (mut changes, mut into_the_house) = (0u32, 0u32);
|
||||||
|
let mut south = None;
|
||||||
|
for frame in 0..budget {
|
||||||
|
run.frame();
|
||||||
|
let map = run.map();
|
||||||
|
if map != previous && map != u32::MAX {
|
||||||
|
changes += 1;
|
||||||
|
into_the_house += u32::from(map == CERULEAN_TRASHED_HOUSE);
|
||||||
|
previous = map;
|
||||||
|
}
|
||||||
|
if map == ROUTE_5 {
|
||||||
|
south = Some(frame);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let tail: Vec<u32> = run.route.iter().rev().take(24).rev().copied().collect();
|
||||||
|
eprintln!(
|
||||||
|
"{var}: Route 5 at {south:?}, {changes} map changes, into the trashed house \
|
||||||
|
{into_the_house} times, rank {}, last maps {tail:?}, macros {:?}",
|
||||||
|
run.adapter.progress().rank,
|
||||||
|
run.started
|
||||||
|
);
|
||||||
|
assert!(south.is_some(), "{var}: not on Route 5 in {budget} frames: last maps {tail:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue