feat(game): implement the Kanto story from Pallet Town through the Pokedex (#127)

* feat(game): implement Kanto story through the Pokedex

* fix(game): stop the rival walking into the player in the pokedex scene

* fix(game): stop oak teleporting to his desk in the starter scene

* fix(game): make a scripted warp arrive the way a walked one does

* fix(game): finish the oaks lab rival scene whether the player wins or loses

* chore(game): tidy the kanto script and item codegen comments

* docs: point the script guides at MapEntryScripts and trainerBattle

* fix(codegen): send item ids in the region whose table matches the decomp
This commit is contained in:
Fiereu authored and GitHub committed 2026-08-09 10:45:24 +02:00
1 parent 70c746fdc6
commit 9215a0862a
35 files changed
+1311 -508

No files matched your search

+6 -2
View File
@@ -85,8 +85,8 @@ Scripts triggered this way get `entityId = -1`.
### Entering a map
`MapScriptService.onMapEnter` runs on every entry, however the player got there:
login, a warp, or walking across a map connection. It builds a list of up to two
scripts and runs them in order:
login, a warp, or walking across a map connection. `MapEntryScripts.onEntry`
builds the list and `MapScriptService` runs it in order:
1. `map.onTransitionScript`, unconditionally.
2. The **first** entry in `map.onFrameScripts` whose story var currently equals
@@ -94,6 +94,10 @@ scripts and runs them in order:
Both go through `ScriptRunner.runAll` on one coroutine, so an on-transition
script and the cutscene it enables share a single dialog lock instead of racing.
A script that warps is the exception: `ctx.warp` runs the destination map's
entry scripts inline on the coroutine it is already on, the way the decomp's
warp continues into the destination's scripts, rather than starting a new one.
The conditional `ON_WARP` table is not wired up yet.
## Why scripts are coroutines
@@ -100,7 +100,7 @@ value it already has, is a no-op and does not dirty the character.
## Reading story state outside a script
`MapScriptService` reads vars directly to pick which `ON_FRAME` script to run on
`MapEntryScripts` reads vars directly to pick which `ON_FRAME` script to run on
map entry, comparing `storyService.getVar(charId, it.varKey)` against each
entry's value. Any other service can do the same: inject `StoryService` and pass
the character id. `ScriptContext` is only a convenience wrapper for the common
+29 -14
View File
@@ -56,9 +56,28 @@ end of your function.
| `goto_if_ne VAR_X, n, Label` | `if (ctx.getVar(HoennVars.VAR_X) != n) { ... }` |
| `applymovement id, M` + `waitmovement 0` | `ctx.moveNpc(LOCALID_X, WALK_UP, ...)` |
| `applymovement OBJ_EVENT_ID_PLAYER, M` + `waitmovement 0` | `ctx.moveSelf(WALK_UP, ...)` |
| Two `applymovement` lines then one `waitmovement 0` | `ctx.moveSelfAndNpcs(selfSteps, LOCALID_X to steps)` |
| `addobject id` | `ctx.showNpc(LOCALID_X)` |
| `setobjectxyperm id, x, y` | `ctx.repositionNpc(LOCALID_X, x, y)` |
| `removeobject id` | `ctx.removeNpc(LOCALID_X)` |
| `msgbox TEXT, MSGBOX_YESNO` + `goto_if_eq VAR_RESULT, YES` | `if (ctx.askYesNo(Map.Text)) { ... }` |
| `givemon SPECIES, level` | `ctx.givePokemon(dexId, level, ...moveIds)` |
| `giveitem`, `additem` / `removeitem` | `ctx.giveItem(Items.X, n)` / `ctx.takeItem(Items.X, n)` |
| `special HealPlayerParty` | `ctx.healParty()` |
| `warp MAP, x, y` | `ctx.warp(region, bank, map, x, y, facing)` |
| `setdynamicwarp ...` | `ctx.setDynamicWarp(region, bank, map, x, y, facing)` |
Item ids come from the generated `Items` object, never a raw number:
`ctx.giveItem(Items.POKE_BALL, 5)`. It is generated from the decomp item header,
so every item the games know about is in it. The client keys an item by
`regionId * 1000 + itemId` and holds one item table per region, so the ids in
`Items` sit in the region whose table matches the decomp numbering. Sending the
same number under another region reaches a different item entirely.
`ctx.warp` continues into the destination map's ON_TRANSITION and ON_FRAME
scripts on the same coroutine, exactly the way the decomp's `warp` does, so a
cutscene that walks the player into a building keeps running on the other side.
`ctx.say` and `ctx.sign` both **wait** for the player to close the box, so
consecutive calls show consecutive boxes with no extra plumbing. `moveNpc` and
`moveSelf` likewise cover `applymovement` *and* its following `waitmovement`, so
@@ -116,22 +135,18 @@ private const val LOCALID_MOM = 3
There is no verb for these. Do not fake them:
- **Choices.** `MSGBOX_YESNO`, `multichoice` and anything reading `VAR_RESULT`
from a prompt. `DialogService` can see a choice packet come back, but
`ScriptContext` has no way to ask a question and branch on the answer.
- **More than two answers.** `multichoice`. Yes/no works, a longer menu does not.
- **Doors.** `opendoor`, `closedoor`, `waitdooranim`.
- **Warping from a script.** `warp`, `warpsilent`, `warphole`. Only
`setDynamicWarp`, which changes where an existing `MAP_DYNAMIC` warp tile
sends the player, exists.
- **Hiding things.** `hideobjectat`, `hideplayer`/`showplayer`. `showNpc` exists,
its inverse does not, beyond ending a movement with `SET_INVISIBLE`.
- **Items, money, party.** `giveitem`, `takeitem`, `checkitemspace`,
`givemon`, `addvar` on money, and so on.
- **Battles.** `trainerbattle` in all its forms.
- **Player identity.** `checkplayergender`, and the `VAR_RESULT` branch that
usually follows it.
- **Shops.** `pokemart` and its item list.
- **Hiding the player.** `hideplayer`/`showplayer`. Npcs can be hidden with
`removeNpc` or by ending a movement with `SET_INVISIBLE`, the player cannot.
- **Money.** Buying and selling.
- **Temporary state.** `VAR_TEMP_*` and `FLAG_TEMP_*` reset when the player
leaves the map in the source game. Story flags and vars here are persistent,
so a script that leans on a temp value needs another way to say the same thing.
- **Presentation.** `playse`, `playfanfare`, `waitfanfare`, `fadescreen`,
`delay`, and `special` calls into engine C code generally.
`delay`, `showmonpic`, emotes like the exclamation mark, and `special` calls
into engine C code generally.
When a script needs one of these, port the part you can and leave a scoped `TODO`
comment naming what is missing, the way the Littleroot intro does:
@@ -74,17 +74,26 @@ Everything goes through `ctx`, the `ScriptContext`:
| Call | What it does |
| --- | --- |
| `ctx.say(line)` | An npc box from the entity the player talked to. Waits. |
| `ctx.sayNpc(localId, line)` | A box from a cutscene npc that the player did not talk to. Waits. |
| `ctx.sign(line)` | A sign or object box, no speaker. Waits. |
| `ctx.askYesNo(line)` / `ctx.askYesNoNpc(localId, line)` | A yes/no box. Waits and returns the answer. |
| `ctx.isFlagSet(f)` / `ctx.setFlag(f)` / `ctx.clearFlag(f)` | Read and write a story flag. |
| `ctx.getVar(k)` / `ctx.setVar(k, n)` | Read and write a story var. |
| `ctx.moveNpc(localId, ...steps)` | Walk a map npc through a path. Waits for it to finish. |
| `ctx.moveSelf(...steps)` | Walk the player's own avatar. Waits. |
| `ctx.showNpc(localId)` | Reveal a normally hidden npc for a cutscene. |
| `ctx.moveSelfAndNpcs(selfSteps, ...paths)` | Walk the player and npcs together. Waits for all of them. |
| `ctx.showNpc(localId)` / `ctx.showNpcAt(localId, x, y)` | Reveal a normally hidden npc for a cutscene. |
| `ctx.repositionNpc(localId, x, y)` / `ctx.removeNpc(localId)` | Move or delete an npc for this player. |
| `ctx.givePokemon(dexId, level, ...moveIds)` / `ctx.healParty()` | Party changes. |
| `ctx.giveItem(itemId, n)` / `ctx.takeItem(itemId, n)` | Bag changes. Ids come from the generated `Items`. |
| `ctx.battle(dexId, level, ...moveIds)` | A story battle against one monster. Waits and returns the result. |
| `ctx.trainerBattle(trainerId)` | A decomp trainer and its whole party, in the region the player is standing in. |
| `ctx.warp(...)` | Move the player to another map, then run that map's entry scripts. |
| `ctx.setDynamicWarp(...)` | Point this player's `MAP_DYNAMIC` warp somewhere. |
| `ctx.entityId` | The npc that was talked to, or `-1` for a sign or map script. |
| `ctx.isFemale` / `ctx.facingDirection` / `ctx.entityId` | The player's gender, their facing, and the npc that was talked to (`-1` for a sign or map script). |
That is the whole api. Plenty of decomp commands have no equivalent in it yet,
choices, doors, giving items, trainer battles,
That is the whole api. Plenty of decomp commands still have no equivalent in it,
doors, shops and sound effects among them,
[which the porting guide lists](../porting-scripts/#commands-with-no-equivalent-yet).
The calls that say "waits" suspend until the player acts, so you can write boxes