Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

Tomb of the Mask: tests, docs and NumPlay's wiring

Mason36367df3f926210
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index d098705a..0602184c 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -75,6 +75,7 @@ jobs:
make -C games/donkeykong host test
make -C games/dune host test
make -C games/monkeymart host test
+ make -C games/tombofthemask host test
make -C games/invaders host test
make -C games/sudoku host test
make -C games/uttt host test
diff --git a/.github/workflows/tombofthemask.yml b/.github/workflows/tombofthemask.yml
deleted file mode 100644
index 62cdbf80..00000000
--- a/.github/workflows/tombofthemask.yml
+++ /dev/null
@@ -1,52 +0,0 @@
-name: Tomb of the Mask
-
-on:
- pull_request:
- paths:
- - 'games/tombofthemask/**'
- - 'games/common/**'
- - 'tools/emu.py'
- - 'Makefile'
- - '.github/workflows/tombofthemask.yml'
- push:
- branches: [main]
- paths:
- - 'games/tombofthemask/**'
- - 'games/common/**'
- - '.github/workflows/tombofthemask.yml'
- workflow_dispatch:
-
-permissions:
- contents: read
-
-jobs:
- game:
- runs-on: ubuntu-24.04
- steps:
- - uses: actions/checkout@v4
- - name: ARM toolchain
- run: |
- v=15.2.1-1.1
- curl -fsSL "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v$v/xpack-arm-none-eabi-gcc-$v-linux-x64.tar.gz" | tar -xz -C "$RUNNER_TEMP"
- echo "$RUNNER_TEMP/xpack-arm-none-eabi-gcc-$v/bin" >> "$GITHUB_PATH"
- - uses: actions/setup-node@v4
- with:
- node-version: 20
- - uses: actions/setup-python@v5
- with:
- python-version: '3.12'
- - name: Tools
- run: |
- npm install -g [email protected]
- pip install pillow numpy pyelftools unicorn==2.1.4
- - name: Build and test Tomb of the Mask
- run: |
- make build/data/apps/TombOfTheMask.nwa NWLINK=nwlink
- make -C games/tombofthemask check test NWLINK=nwlink
- make -C games/tombofthemask test-assets
- - name: ARM profiles, saves and safe exit
- run: python3 games/tombofthemask/tests/test_arm.py --nwlink nwlink
- - uses: actions/upload-artifact@v4
- with:
- name: Tomb of the Mask
- path: build/data/apps/TombOfTheMask.nwa
diff --git a/Makefile b/Makefile
index 9220872b..c683fb0e 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ PY ?= python3
CARGO ?= cargo
B = build/data
# Conventional games honor a configurable output directory; special layouts are kept local.
-GAMES_REDIRECT = balatro blockblast breakout buckshot celeste championisland chess connectfour cookieclicker coreball dinorun donkeykong doodlejump doom dune finalearth2 flappybird flappydunk fnaf g2048 hillclimb hollowknight invaders isaac jetpackjoyride leveldevil minesweeper monkeymart numblocks numpowder numvisuals pacman portal pvz snake sokoban solitaire sonic stickmanhook subway sudoku suika towerblock twoplayer undertale uttt
+GAMES_REDIRECT = balatro blockblast breakout buckshot celeste championisland chess connectfour cookieclicker coreball dinorun donkeykong doodlejump doom dune finalearth2 flappybird flappydunk fnaf g2048 hillclimb hollowknight invaders isaac jetpackjoyride leveldevil minesweeper monkeymart numblocks numpowder numvisuals pacman portal pvz snake sokoban solitaire sonic stickmanhook subway sudoku suika tombofthemask towerblock twoplayer undertale uttt
GAMES_OUT = dinorun
GAME_REDIRECT_ARG = $(if $(filter $(1),$(GAMES_OUT)),OUT=../../$(B)/games/$(1),BUILD_DIR=../../$(B)/games/$(1))
# the RAM the oldest calculator software that runs apps gives them (23.2: 148928 bytes; 25.2 gives 153676).
@@ -320,7 +320,7 @@ APP_stickmanhook = $(B)/games/stickmanhook/stickmanhook.nwa:StickmanHook.nwa
APP_donkeykong = $(B)/games/donkeykong/donkeykong.nwa:DonkeyKong.nwa
APP_dune = $(B)/games/dune/dune.nwa:Dune.nwa
APP_monkeymart = $(B)/games/monkeymart/monkeymart.nwa:MonkeyMart.nwa
-APP_tombofthemask = games/tombofthemask/output/tombofthemask.nwa:TombOfTheMask.nwa
+APP_tombofthemask = $(B)/games/tombofthemask/tombofthemask.nwa:TombOfTheMask.nwa
# the big games' modules are made from these (the kit)
$(foreach g,$(XL_GAMES),$(eval MOD_$(g) = $$(word 1,$$(subst :, ,$$(APP_$(g))))))
@@ -353,6 +353,7 @@ apps: | $(B)
$(MAKE) -C games/donkeykong build NWLINK="$(NWLINK)" BUILD_DIR=../../$(B)/games/donkeykong
$(MAKE) -C games/dune build NWLINK="$(NWLINK)" BUILD_DIR=../../$(B)/games/dune
$(MAKE) -C games/monkeymart build NWLINK="$(NWLINK)" BUILD_DIR=../../$(B)/games/monkeymart
+ $(MAKE) -C games/tombofthemask build NWLINK="$(NWLINK)" BUILD_DIR=../../$(B)/games/tombofthemask
cd games/tetris/tetris && NWLINK="$(NWLINK)" $(CARGO) build --release --quiet
cp $(word 1,$(subst :, ,$(APP_numdash))) $(B)/apps/$(word 2,$(subst :, ,$(APP_numdash)))
cp $(word 1,$(subst :, ,$(APP_crossyroad))) $(B)/apps/$(word 2,$(subst :, ,$(APP_crossyroad)))
@@ -383,15 +384,9 @@ apps: | $(B)
cp $(word 1,$(subst :, ,$(APP_donkeykong))) $(B)/apps/$(word 2,$(subst :, ,$(APP_donkeykong)))
cp $(word 1,$(subst :, ,$(APP_dune))) $(B)/apps/$(word 2,$(subst :, ,$(APP_dune)))
cp $(word 1,$(subst :, ,$(APP_monkeymart))) $(B)/apps/$(word 2,$(subst :, ,$(APP_monkeymart)))
+ cp $(word 1,$(subst :, ,$(APP_tombofthemask))) $(B)/apps/$(word 2,$(subst :, ,$(APP_tombofthemask)))
arm-none-eabi-strip --strip-unneeded $(B)/apps/Tetris.nwa
-# Tomb of the Mask installs separately, outside the launcher game list.
-apps: $(B)/apps/TombOfTheMask.nwa
-$(B)/apps/TombOfTheMask.nwa: FORCE | $(B)
- $(MAKE) --no-print-directory -C games/tombofthemask build NWLINK="$(NWLINK)" PYTHON="$(PY)"
- mkdir -p $(B)/apps
- cp games/tombofthemask/output/tombofthemask.nwa $@
-
STD_APPS = $(foreach g,$(STD_GAMES),$(B)/apps/$(NWA_$(g)))
apps: $(STD_APPS)
$(STD_APPS): $(B)/apps/%.nwa: FORCE | $(B)
diff --git a/README.md b/README.md
index 480d5fad..6c7e68e2 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
<p align="center">
<b>29 free games for your NumWorks calculator, in one app.</b><br>
- Plus 21 big games that install on their own. For the N0110, N0115 and N0120, in English, French and Chinese.
+ Plus 20 big games that install on their own. For the N0110, N0115 and N0120, in English, French and Chinese.
</p>
<p align="center">
@@ -131,7 +131,6 @@ These are too big to fit next to NumPlay, so each one is its own app. Install it
</tr>
<tr>
<td align="center"><a href="https://github.com/Mason363/NumWorks-Super-Mario-Bros"><b>Super Mario Bros.</b></a><br><sub>All 32 stages, in a repository of its own: NumWorks-Super-Mario-Bros</sub></td>
- <td align="center"><a href="games/tombofthemask/README.md"><img src="games/tombofthemask/docs/title.png" width="200" alt="Tomb of the Mask"><br><b>Tomb of the Mask</b></a><br><sub>Dash through 200 original stages, or climb in arcade mode. By Bobydeluxe.</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/TombOfTheMask.nwa">Download</a></td>
<td align="center"><a href="#roadmap"><b>More on the way</b></a><br><sub>Minecraft 1.18.2 and more: see the roadmap</sub></td>
</tr>
</table>
@@ -302,8 +301,6 @@ Read **[Make your own NumWorks game](docs/make-a-game.md)** to go from there, an
## Credits
-- **Tomb of the Mask** by **Happymagenta / Playgendary**: original stage layouts, sprites and fonts from the supplied web build. Native NumWorks adaptation by **[Bobydeluxe](https://github.com/Bobydeluxe)**, installed separately as **TombOfTheMask.nwa**. See [asset credits](games/tombofthemask/ASSETS.md). Not affiliated with the original makers.
-
NumPlay is a fan project, made out of love for these games and for the NumWorks calculator. If you enjoy a game here, go play the original and support the people who made it. NumWorks also has a great community of people making games by hand: try [Numcraft](https://github.com/yannis300307/NumcraftRust), [Celeste Classic](https://github.com/BenchatonDev/Celeste-Numworks), [Tatone26's All the Apps](https://github.com/Tatone26/Numworks-games), the apps on [Nwagyu](https://nwagyu.org/guide/) and [yannis300307's list](https://gist.github.com/yannis300307/9123136f90877107ec0d49ba96b303e5).
- **[Tatone26](https://github.com/Tatone26/Numworks-games)**'s **All the Apps** inspired NumPlay's list of classics. Flappy Bird, Pac-Man, Snake, Connect Four, Solitaire and 2048 are written in C for NumPlay and keep its options, with no code copied from it. Tetris is Tatone26's own, which they released into the public domain, adapted for NumPlay.
diff --git a/docs/media/tombofthemask.gif b/docs/media/tombofthemask.gif
new file mode 100644
index 00000000..2399afa0
Binary files /dev/null and b/docs/media/tombofthemask.gif differ
diff --git a/games/games.json b/games/games.json
index 427d2865..a8a86cfb 100644
--- a/games/games.json
+++ b/games/games.json
@@ -677,7 +677,7 @@
},
{
"id": "championisland",
- "rank": 17,
+ "rank": 18,
"title": "Champion Island",
"tagline": "Seven sports, one island",
"credit": "Based on Google's Champion Island Games",
@@ -699,7 +699,7 @@
},
{
"id": "finalearth2",
- "rank": 18,
+ "rank": 19,
"title": "The Final Earth 2",
"tagline": "Build a city in space",
"credit": "Based on the game by Florian van Strien",
@@ -721,7 +721,7 @@
},
{
"id": "numpowder",
- "rank": 13,
+ "rank": 14,
"title": "NumPowder",
"tagline": "Sand, water, fire and more",
"credit": "Inspired by The Powder Toy",
@@ -775,7 +775,7 @@
},
{
"id": "fnaf",
- "rank": 11,
+ "rank": 12,
"title": "Five Nights at Freddy's",
"tagline": "Survive five nights",
"credit": "Based on the game by Scott Cawthon",
@@ -797,7 +797,7 @@
},
{
"id": "doom",
- "rank": 10,
+ "rank": 11,
"title": "Doom",
"tagline": "Rip and tear",
"credit": "Based on Doom by id Software",
@@ -836,7 +836,7 @@
},
{
"id": "isaac",
- "rank": 15,
+ "rank": 16,
"title": "The Binding of Isaac",
"tagline": "Cry through the basement",
"credit": "Based on the game by Edmund McMillen",
@@ -858,7 +858,7 @@
},
{
"id": "hillclimb",
- "rank": 16,
+ "rank": 17,
"title": "Hill Climb Racing",
"tagline": "Drive up, don't flip",
"credit": "Based on Hill Climb Racing by Fingersoft",
@@ -902,7 +902,7 @@
},
{
"id": "sonic",
- "rank": 14,
+ "rank": 15,
"title": "Sonic the Hedgehog",
"tagline": "Run through six zones",
"credit": "Based on the game by Sonic Team",
@@ -923,7 +923,7 @@
},
{
"id": "cookieclicker",
- "rank": 20,
+ "rank": 21,
"title": "Cookie Clicker",
"tagline": "Bake billions of cookies",
"credit": "Based on Cookie Clicker by Orteil",
@@ -944,7 +944,7 @@
},
{
"id": "leveldevil",
- "rank": 19,
+ "rank": 20,
"title": "Level Devil",
"tagline": "Run to the door",
"credit": "Based on Level Devil by Unept",
@@ -986,7 +986,7 @@
},
{
"id": "stickmanhook",
- "rank": 8,
+ "rank": 9,
"title": "Stickman Hook",
"tagline": "Swing from hook to hook",
"credit": "Based on Stickman Hook by Madbox",
@@ -1007,7 +1007,7 @@
},
{
"id": "donkeykong",
- "rank": 12,
+ "rank": 13,
"title": "Donkey Kong",
"tagline": "Climb the girders and save Pauline",
"credit": "Based on Donkey Kong by Nintendo",
@@ -1028,7 +1028,7 @@
},
{
"id": "dune",
- "rank": 9,
+ "rank": 10,
"title": "Dune",
"tagline": "Roll down the dunes and fly over the line",
"credit": "Based on Dune! by Team Lava",
@@ -1067,5 +1067,26 @@
"repo": "https://github.com/Mason363/NumPlay/tree/main/games/monkeymart",
"default": false,
"xl": true
+ },
+ {
+ "id": "tombofthemask",
+ "rank": 8,
+ "title": "Tomb of the Mask",
+ "tagline": "Dash through the tomb ahead of the lava",
+ "credit": "Based on Tomb of the Mask by Playgendary",
+ "top": "0x3A1A78",
+ "bottom": "0x0C0620",
+ "accent": "0xFFF600",
+ "colors": 16,
+ "records": [
+ "tombofthemask.sav",
+ "tombofthemask_saves.py"
+ ],
+ "shots": [
+ "docs/title.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/tombofthemask",
+ "default": false,
+ "xl": true
}
]
diff --git a/games/tombofthemask/README.md b/games/tombofthemask/README.md
index 55536017..a3b46af7 100644
--- a/games/tombofthemask/README.md
+++ b/games/tombofthemask/README.md
@@ -1,102 +1,84 @@
-# Tomb of the Mask
+> **Tomb of the Mask is a [NumPlay](../../README.md) game that comes on its own.** It is too big to fit next to NumPlay on the calculator. Get `TombOfTheMask.nwa` from the [latest release](https://github.com/Mason363/NumPlay/releases/latest).
+
+<p align="center">
+ <img src="src/icon.png" width="84" alt="Tomb of the Mask icon">
+</p>
+
+<h1 align="center">Tomb of the Mask</h1>
+
+<p align="center">
+ <b>Dash through a tomb full of traps, on the NumWorks calculator.</b><br>
+ The endless arcade climb ahead of the lava, and all 200 stages.
+</p>
+
+<p align="center">
+ <a href="https://github.com/Mason363/NumPlay/releases/latest/download/TombOfTheMask.nwa"><b>Download TombOfTheMask.nwa</b></a>
+ &nbsp;·&nbsp; <a href="#controls">Controls</a>
+</p>
+
+<p align="center">
+ <img src="../../docs/media/tombofthemask.gif" width="640" alt="Tomb of the Mask: the player dashes from wall to wall up the tomb, picking up dots and coins">
+</p>
+
+## Highlights
+
+* **The arcade:** an endless climb built as the original builds it, from its 517 sections: zones that grow longer, new wall styles and colours at each zone's end, and bonus zones (the run up a shaft, and the pipes).
+* **All 200 stages:** each with its exit, three stars and the dots to collect, unlocked one after the other. The lava rises in the stages that have it.
+* **Every trap:** spikes, trap spikes, bats, cannons, puffer fish, snakes, monkeys throwing rocks, light balls, rotors, moving platforms, timer walls, close bricks, ice, portals and tramplins, at the original's speeds and timings.
+* **Powerups:** coin addict, freeze, magnet and score booster turn up as you climb, and shields from the shop take a hit.
+* **Masks, upgrades, missions and the chest:** 16 masks with their powers, opened by your level and bought with coins, the four powerups' upgrades, three missions at a time, and the chest's wheel.
+* **The game's look:** its own pictures, characters, walls and pixel font, with the colours it gives each zone.
+* **Saved as you go:** Home saves and quits, from anywhere. Your progress is also copied into `tombofthemask_saves.py`, so installing the app again doesn't erase it.
+
+<table>
+ <tr>
+ <td align="center"><img src="docs/shot.png" width="390" alt="The arcade"><br><sub>The arcade: dots, coins and spikes</sub></td>
+ <td align="center"><img src="docs/stage.png" width="390" alt="A stage"><br><sub>Stage 5, with a star to take</sub></td>
+ </tr>
+ <tr>
+ <td align="center"><img src="docs/lava.png" width="390" alt="The lava"><br><sub>The lava, close behind</sub></td>
+ <td align="center"><img src="docs/bonus.png" width="390" alt="A bonus zone"><br><sub>A bonus zone: the run up the shaft</sub></td>
+ </tr>
+ <tr>
+ <td align="center"><img src="docs/stages.png" width="390" alt="The stages"><br><sub>The stages and their stars</sub></td>
+ <td align="center"><img src="docs/masks.png" width="390" alt="The masks"><br><sub>The masks and their powers</sub></td>
+ </tr>
+ <tr>
+ <td align="center"><img src="docs/chest.png" width="390" alt="The chest's wheel"><br><sub>The chest's wheel</sub></td>
+ <td align="center"><img src="docs/title.png" width="390" alt="The title screen"><br><sub>The title screen</sub></td>
+ </tr>
+</table>
+
+## How to play
+
+Press an arrow and you dash that way until a wall stops you; then dash again. You cannot dash into the wall you are standing against. Dots score points, coins pay for shields, upgrades, masks and spins of the wheel. Spikes, enemies and the lava end the run, unless a shield takes the hit; after that you can come back where you last landed for 200 coins (three times in the arcade, once in a stage).
+
+In the arcade the lava wakes up with your first dash and rises faster and faster: keep climbing. Each zone ends at a shaft in its ceiling that takes you to the next one. A door in the wall leads to a bonus zone, full of coins. In a stage, find the exit; the three stars and every dot are there to take on the way.
+
+## Controls
+
+| Key | What it does |
+| --- | --- |
+| Arrows | Dash, or move the selection in menus |
+| OK | Use a shield; choose, buy or claim in menus |
+| Back | Pause (Resume, Restart, How to play, Quit game), or go back in menus |
+| Home | Save and quit |
-Native NumWorks adaptation by **Bobydeluxe**, based on the supplied Unity web
-version of Happymagenta and Playgendary's Tomb of the Mask.
+## Good to know
-Includes the **200 original stage layouts**, **517 arcade sections**, original
-monochrome sprites, logo, pixel font and colour palettes, and **16 masks**.
-The original default tables supply mask unlock levels and prices, experience
-thresholds, upgrade prices, power-up effects, mask advantages and mission goals.
+* **On its own:** Tomb of the Mask is too big to fit next to NumPlay. Installing it from the NumWorks website swaps out NumPlay and the other apps, and installing NumPlay again swaps it back out.
+* **The web version's content:** its arcade, its 200 stages, masks, upgrades, missions and chest. The free chest comes back after four hours of play rather than four hours of the clock, since the calculator keeps no time.
+* **Left out:** the ads and what they gave (video revives, doubled rewards and coins), and music and sound (the calculator has no speaker).
-![Title](docs/title.png) ![Gameplay](docs/gameplay.png)
+## Credits
-## Play
+Inspired by [Tomb of the Mask](https://www.playgendary.com) by Playgendary, not affiliated with them. Go play the original: it's free on Android and iOS, with music, sound and the newer modes.
-| Key | Action |
-| --- | --- |
-| Arrows | Dash to the next wall; choose menus |
-| OK / EXE | Confirm; use an owned shield during play |
-| BACK | Pause; return from menus |
-| HOME / Power | Save and exit |
-| 0 on the title screen | Controls |
-| 1 on the title screen | Missions |
-| 2 on the title screen | Chest and reward wheel |
-
-**Map** selects a stage. Collect stars and dots, avoid the traps and reach the
-green exit. Completing a stage unlocks the next one. Getting every dot earns
-the original 25-coin bonus. Best star ratings and all-dot completions are saved.
-
-**Arcade** joins original sections into an endless climb. Keep ahead of the
-rising tide. New sections replace the bottom of a fixed-size window, so a long
-run does not increase RAM use. The best score is saved.
-
-**Masks** displays each mask's original level requirement, price and benefits.
-**Shop** sells shields and the nine upgrades of each power-up. Coins, experience,
-owned masks, upgrades, mission progress and chest rewards persist between launches.
-The eight mission categories use the reference's goals and reward tables.
-
-## Calculator adaptations
-
-This is a native C reimplementation, rather than Unity running on a calculator.
-The original stage tile data is preserved exactly, including the four stars in
-stages 90 and 117. Dash timing uses the original 5-unit movement speed and
-0.12-unit tile size, with a fixed 60 Hz simulation. Bounded grid collision,
-enemy movement and arcade section selection are native implementations; their
-results are not claimed to be bit-for-bit identical to Unity's physics or RNG.
-
-Menus fit the 320 × 240 display and use calculator keys. All text is English.
-Sprites use their original pixel dimensions; their monochrome colours and
-transparency are packed separately. The small font's missing punctuation comes
-from fonts embedded in the supplied game.
-
-There is no sound, advertising, online purchase, subscription or notification
-service. Retries do not consume mobile energy. The reward wheel uses in-game
-coins only. Its first chest is free; the original four-hour free-chest cooldown
-counts active playing time because the app does not require an online clock.
-The next free chest and mission progress survive closing the app.
-
-`tombmask.sav` uses **320 bytes**, with a version and CRC. Full storage offers
-retry, return to the menu, and exit without saving; it does not delete other
-files. An unfinished stage restarts when launched again. Completed progression
-and rewards remain saved.
-
-## Build
-
-Requires ARM GCC, Python with Pillow, Node.js and nwlink. All converted assets
-are checked in; ordinary builds need neither Unity nor a network download.
-
-```sh
-python build.py --arm-bin /path/to/arm/bin --nwlink /path/to/nwlink
-```
-
-This produces `output/tombofthemask.nwa` and copies it to
-`../../build/apps/TombOfTheMask.nwa`. The same app targets N0110, N0115 and N0120,
-and is checked against Upsilon's smaller RAM allocation.
-
-```sh
-make build check
-make test
-make test-assets
-make test-arm
-```
-
-`HOST_CC`, `PYTHON` and `NWLINK` can override tools. ARM tests require Unicorn,
-pyelftools and Pillow. Run the build and host tests before the ARM tests.
-See [VALIDATION.md](VALIDATION.md) for measurements and test coverage.
-
-Tomb of the Mask installs separately from the launcher and is excluded from
-`games/games.json`. From the repository root, build it with
-`make build/data/apps/TombOfTheMask.nwa` or
-`python tools/build.py --game tombofthemask`. Release tooling lists
-`TombOfTheMask.nwa` among the individual large games.
+* The pictures (the characters and masks, the walls, traps, enemies, powerups and icons) and the pixel font come from the game's own web build, read by [tools/art.py](tools/art.py) into [src/art.c](src/art.c). The arcade's sections and the stages come from its own maps, read by [tools/data.py](tools/data.py) into [src/data.c](src/data.c). Its rules and numbers follow the game's own code.
+* The calculator adaptation is by **[Bobydeluxe](https://github.com/Bobydeluxe)**, who brought it to NumPlay.
-## Credits
+Made by Mason Chen as part of NumPlay.
-- Original Tomb of the Mask and artwork: **Happymagenta / Playgendary**.
-- Fonts from the supplied build: **hm_pxl_01 / ArcadeClassic**, with **Roboto Bold**
- for missing punctuation.
-- Native calculator adaptation: **Bobydeluxe**. In-game credit: **By Bobydeluxe**.
-- [Pinned reference build](https://github.com/Gr4ys0n/Gr4ys0n.github.io/tree/29006b0f11904704c390b457f7055c9fa1e53484/public/assets/games/tomb-of-the-mask).
-- [Asset conversion and provenance](ASSETS.md).
+## License
-Unofficial adaptation, not affiliated with Happymagenta or Playgendary.
+The game's code is licensed under the GNU General Public License v3.0: see the `LICENSE` file at the root of the repository. The game's pictures, maps and font keep their own terms (see Credits).
diff --git a/games/tombofthemask/docs/bonus.png b/games/tombofthemask/docs/bonus.png
new file mode 100644
index 00000000..2ac33b21
Binary files /dev/null and b/games/tombofthemask/docs/bonus.png differ
diff --git a/games/tombofthemask/docs/chest.png b/games/tombofthemask/docs/chest.png
index 6ee834e2..32f94419 100644
Binary files a/games/tombofthemask/docs/chest.png and b/games/tombofthemask/docs/chest.png differ
diff --git a/games/tombofthemask/docs/gameplay.png b/games/tombofthemask/docs/gameplay.png
deleted file mode 100644
index 00b39d3e..00000000
Binary files a/games/tombofthemask/docs/gameplay.png and /dev/null differ
diff --git a/games/tombofthemask/docs/lava.png b/games/tombofthemask/docs/lava.png
new file mode 100644
index 00000000..1f20334e
Binary files /dev/null and b/games/tombofthemask/docs/lava.png differ
diff --git a/games/tombofthemask/docs/map.png b/games/tombofthemask/docs/map.png
deleted file mode 100644
index 14ba0c88..00000000
Binary files a/games/tombofthemask/docs/map.png and /dev/null differ
diff --git a/games/tombofthemask/docs/masks.png b/games/tombofthemask/docs/masks.png
index 0d7d9caa..0975ae26 100644
Binary files a/games/tombofthemask/docs/masks.png and b/games/tombofthemask/docs/masks.png differ
diff --git a/games/tombofthemask/docs/missions.png b/games/tombofthemask/docs/missions.png
deleted file mode 100644
index 2eaa35ff..00000000
Binary files a/games/tombofthemask/docs/missions.png and /dev/null differ
diff --git a/games/tombofthemask/docs/shop.png b/games/tombofthemask/docs/shop.png
deleted file mode 100644
index 66a39b2e..00000000
Binary files a/games/tombofthemask/docs/shop.png and /dev/null differ
diff --git a/games/tombofthemask/docs/shot.png b/games/tombofthemask/docs/shot.png
new file mode 100644
index 00000000..613fc7a1
Binary files /dev/null and b/games/tombofthemask/docs/shot.png differ
diff --git a/games/tombofthemask/docs/stage-clear.png b/games/tombofthemask/docs/stage-clear.png
deleted file mode 100644
index bbb76683..00000000
Binary files a/games/tombofthemask/docs/stage-clear.png and /dev/null differ
diff --git a/games/tombofthemask/docs/stage.png b/games/tombofthemask/docs/stage.png
new file mode 100644
index 00000000..791da33b
Binary files /dev/null and b/games/tombofthemask/docs/stage.png differ
diff --git a/games/tombofthemask/docs/stages.png b/games/tombofthemask/docs/stages.png
new file mode 100644
index 00000000..c396748e
Binary files /dev/null and b/games/tombofthemask/docs/stages.png differ
diff --git a/games/tombofthemask/docs/title.png b/games/tombofthemask/docs/title.png
index e142bb42..b7ec637d 100644
Binary files a/games/tombofthemask/docs/title.png and b/games/tombofthemask/docs/title.png differ
diff --git a/games/tombofthemask/tests/bot.h b/games/tombofthemask/tests/bot.h
new file mode 100644
index 00000000..a613cd2b
--- /dev/null
+++ b/games/tombofthemask/tests/bot.h
@@ -0,0 +1,150 @@
+/* A player for the tests. A stage: breadth first over the places the player can stand (every dash, and waiting
+ * a third of a second, tried on copies of the game with the real rules, hazards and lava included) until a way
+ * reaches the exit; the game is deterministic, so that way, replayed, clears the stage. The arcade: the same
+ * search a few moves deep, taking the way that climbs highest without dying. */
+#ifndef TM_BOT_H
+#define TM_BOT_H
+#include <stdlib.h>
+#include <string.h>
+#include "game.h"
+
+#define BOT_WAIT 21 /* a wait: steps (6 of them: the rotors' 2.1 s) */
+
+#define BOT_WAITS 12 /* waits in a row at one place, at most */
+#define BOT_PHASES 6 /* the search tells apart arrivals at a place by the time, in waits */
+
+typedef struct {
+ tm_game g;
+ int parent, move; /* move: 0..3 a dash, 4 a wait */
+ int waits; /* waits in a row up to here */
+} bot_node;
+
+static bot_node *bot_q;
+static int bot_cap;
+
+/* one move from a standing player: a dash until it stands again (or dies, or wins), or a short wait */
+static bool bot_move(tm_game *g, int m) {
+ if (m == 4) {
+ for (int i = 0; i < BOT_WAIT && g->alive && !g->ev_won; i++) tm_step(g, -1, false);
+ return g->alive && (tm_standing(g) || g->ev_won);
+ }
+ int32_t x = g->x, y = g->y;
+ int face = g->face;
+ tm_step(g, m, false);
+ if (tm_standing(g) && g->x == x && g->y == y && g->face == face) return false; /* it could not go that way */
+ for (int i = 0; i < 900 && g->alive && !g->ev_won && !tm_standing(g); i++) tm_step(g, -1, false);
+ return g->alive && (tm_standing(g) || g->ev_won);
+}
+
+static void bot_room(int n) {
+ if (bot_cap < n) bot_q = realloc(bot_q, sizeof(bot_node) * (size_t)n), bot_cap = n;
+}
+
+/* where and when a standing player is, and what moves round it (timer walls, platforms, rotors, things
+ * awake), for the search's "seen" marks: a 64-bit hash */
+static uint64_t bot_mix(uint64_t h, uint64_t v) { return (h ^ v) * 0x100000001B3ull; }
+static uint64_t bot_key(const tm_game *g) {
+ uint64_t h = 0xCBF29CE484222325ull;
+ h = bot_mix(h, (uint64_t)(tm_cell(g->x) & 0xFFFF) << 24 | (uint64_t)(tm_cell(g->y) & 0xFFFF) << 4 | g->face);
+ h = bot_mix(h, g->tick / BOT_WAIT % BOT_PHASES);
+ for (int i = 0; i < TM_TIMER_WALLS; i++)
+ if (g->tw[i].left > 0) h = bot_mix(h, (uint64_t)(g->tw[i].x * 977 + g->tw[i].y) << 8 | (unsigned)(g->tw[i].left / BOT_WAIT));
+ for (int i = 0; i < TM_PLATFORMS; i++)
+ if (g->plat[i].active) h = bot_mix(h, (uint64_t)(tm_cell(g->plat[i].x) * 977 + tm_cell(g->plat[i].y)) << 4 | (unsigned)(g->plat[i].dx + 2) << 2 | (unsigned)(g->plat[i].dy + 2));
+ for (int i = 0; i < TM_ROTORS; i++)
+ if (g->rotor[i].active) h = bot_mix(h, (uint64_t)(uint8_t)g->rotor[i].px[0] << 8 | (uint8_t)g->rotor[i].py[0]);
+ for (int i = 0; i < TM_SNAKES; i++) h = bot_mix(h, g->snake[i].active);
+ for (int i = 0; i < TM_BALLS; i++) h = bot_mix(h, g->ball[i].awake);
+ h = bot_mix(h, g->ride);
+ return h ? h : 1;
+}
+
+/* the seen marks: an open-addressed set of keys */
+#define BOT_SEEN (1 << 20)
+static uint64_t *bot_seen;
+static void bot_seen_clear(void) {
+ if (!bot_seen) bot_seen = malloc(sizeof(uint64_t) * BOT_SEEN);
+ memset(bot_seen, 0, sizeof(uint64_t) * BOT_SEEN);
+}
+static bool bot_seen_add(uint64_t k) { /* false: already there */
+ for (uint32_t i = (uint32_t)(k >> 40) & (BOT_SEEN - 1);; i = (i + 1) & (BOT_SEEN - 1)) {
+ if (bot_seen[i] == k) return false;
+ if (!bot_seen[i]) return bot_seen[i] = k, true;
+ }
+}
+
+/* the moves to the exit from g (written to moves, at most max), or -1 when none is found within nodes */
+static int bot_route(const tm_game *g, int nodes, int *moves, int max) {
+ bot_seen_clear();
+ bot_room(nodes);
+ int head = 0, tail = 0;
+ bot_q[tail].g = *g, bot_q[tail].parent = -1, bot_q[tail].move = -1, bot_q[tail].waits = 0, tail++;
+ bot_seen_add(bot_key(g));
+ while (head < tail) {
+ int at = head++;
+ for (int m = 0; m < 5 && tail < nodes; m++) {
+ if (m == 4 && bot_q[at].waits >= BOT_WAITS) continue;
+ bot_node *c = &bot_q[tail];
+ c->g = bot_q[at].g;
+ if (!bot_move(&c->g, m)) continue;
+ c->parent = at, c->move = m, c->waits = m == 4 ? bot_q[at].waits + 1 : 0;
+ if (c->g.ev_won) {
+ int n = 0;
+ for (int k = tail; bot_q[k].parent >= 0; k = bot_q[k].parent) n++;
+ if (n > max) return -1;
+ int i = n;
+ for (int k = tail; bot_q[k].parent >= 0; k = bot_q[k].parent) moves[--i] = bot_q[k].move;
+ return n;
+ }
+ if (!bot_seen_add(bot_key(&c->g))) continue;
+ tail++;
+ }
+ }
+ return -1;
+}
+
+/* plays moves from a standing player (a dash runs until it stands again) */
+static void bot_play(tm_game *g, const int *moves, int n) {
+ for (int i = 0; i < n && g->alive && !g->ev_won; i++) bot_move(g, moves[i]);
+}
+
+/* a stage cleared by the bot: true when its way reaches the exit */
+static bool bot_play_stage(tm_game *g, int stage, uint32_t seed, int nodes) {
+ static int moves[512];
+ tm_start(g, stage, seed);
+ int n = bot_route(g, nodes, moves, 512);
+ if (n < 0) return false;
+ bot_play(g, moves, n);
+ return g->ev_won;
+}
+
+/* the arcade: the next move of the way that ends highest a few moves on (or -1: every way dies) */
+static int bot_arcade_move(const tm_game *g, int nodes) {
+ bot_seen_clear();
+ bot_room(nodes);
+ int head = 0, tail = 0, best = -1;
+ int32_t best_y = -0x7FFFFFFF;
+ bot_q[tail].g = *g, bot_q[tail].parent = -1, bot_q[tail].move = -1, bot_q[tail].waits = 0, tail++;
+ while (head < tail) {
+ int at = head++;
+ for (int m = 0; m < 5 && tail < nodes; m++) {
+ if (m == 4 && bot_q[at].waits >= 2) continue;
+ bot_node *c = &bot_q[tail];
+ c->g = bot_q[at].g;
+ if (!bot_move(&c->g, m)) continue;
+ c->parent = at, c->move = m, c->waits = m == 4 ? bot_q[at].waits + 1 : 0;
+ if (!bot_seen_add(bot_key(&c->g))) continue;
+ /* the height, less a little for each move (the shortest way up), and the lava's distance */
+ int32_t score = c->g.y - (c->g.y - c->g.lava_y < 6 * TT ? 8 * TT : 0);
+ if (score > best_y) {
+ best_y = score;
+ int k = tail;
+ while (bot_q[k].parent > 0) k = bot_q[k].parent;
+ best = bot_q[k].move;
+ }
+ tail++;
+ }
+ }
+ return best;
+}
+#endif
diff --git a/games/tombofthemask/tests/first-stage-route.json b/games/tombofthemask/tests/first-stage-route.json
deleted file mode 100644
index 297dc064..00000000
--- a/games/tombofthemask/tests/first-stage-route.json
+++ /dev/null
@@ -1 +0,0 @@
-["right", "up", "left", "down", "left", "up", "left", "down", "right", "up", "right", "down", "right", "up", "left", "down", "right", "up", "left", "up", "right", "up"]
diff --git a/games/tombofthemask/tests/play.c b/games/tombofthemask/tests/play.c
new file mode 100644
index 00000000..8f8ba0a4
--- /dev/null
+++ b/games/tombofthemask/tests/play.c
@@ -0,0 +1,664 @@
+/* Tomb of the Mask on a computer, for tests and pictures (make host, make test).
+ *
+ * play test DIR the rules against the original's numbers (the spec kept with the reference), a bot that
+ * clears the stages and climbs the arcade, the same run twice (and its hash, the same on
+ * every computer), a few hundred sessions of the whole app with random keys (quitting with
+ * Home each time), saves written and read back exactly, damaged saves refused; with
+ * TOTM_REF=DIR (the web game taken apart: DIR/text/stages__*, sections__*), the packed maps
+ * against the game's own files
+ * play shots DIR pictures of the screens (DIR/<name>.ppm)
+ * play film DIR N N frames of the bot in the arcade, every other step (DIR/f_<ms>.raw)
+ */
+#define main tm_app_main
+#include "../src/main.c"
+#undef main
+#include <dirent.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "inner.h"
+#include "data.h"
+#include "bot.h"
+#include "../../common/np_lz.h"
+
+/* ---------------------------------------------------------------- the calculator, on a computer */
+static uint16_t fb[240][320];
+void plat_push(int x, int y, int w, int h, const uint16_t *px) {
+ for (int j = 0; j < h; j++)
+ for (int i = 0; i < w; i++) fb[y + j][x + i] = px[j * w + i];
+}
+static double clock_ms;
+static uint32_t (*script)(uint32_t frame);
+static uint32_t frame_no, quit_at;
+uint32_t plat_keys(void) {
+ clock_ms += 10;
+ frame_no++;
+ if (frame_no >= quit_at) return K_HOME;
+ return script ? script(frame_no) : 0;
+}
+uint32_t plat_millis(void) { return (uint32_t)clock_ms; }
+void plat_sleep(uint32_t ms) { clock_ms += ms; }
+uint32_t plat_random(void) { return 0x9E3779B9u ^ frame_no; }
+void plat_begin(void) {}
+int plat_end(void) { return 0; }
+
+static struct { char name[32]; uint8_t data[4096]; uint32_t len; bool on; } files[4];
+static bool storage_full;
+bool plat_save(const char *name, const void *data, uint32_t len) {
+ if (storage_full) return false;
+ int k = -1;
+ for (int i = 0; i < 4; i++)
+ if (files[i].on && !strcmp(files[i].name, name)) k = i;
+ for (int i = 0; i < 4 && k < 0; i++)
+ if (!files[i].on) k = i;
+ if (k < 0 || len > sizeof files[k].data) return false;
+ strcpy(files[k].name, name), memcpy(files[k].data, data, len), files[k].len = len, files[k].on = true;
+ return true;
+}
+const uint8_t *plat_load(const char *name, uint32_t *len) {
+ for (int i = 0; i < 4; i++)
+ if (files[i].on && !strcmp(files[i].name, name)) return *len = files[i].len, files[i].data;
+ return 0;
+}
+static void forget(const char *name) {
+ for (int i = 0; i < 4; i++)
+ if (files[i].on && !strcmp(files[i].name, name)) files[i].on = false;
+}
+static uint8_t *file_data(const char *name, uint32_t *len) {
+ for (int i = 0; i < 4; i++)
+ if (files[i].on && !strcmp(files[i].name, name)) return *len = files[i].len, files[i].data;
+ return 0;
+}
+
+static void shot(const char *path) {
+ FILE *f = fopen(path, "wb");
+ if (!f) exit(2);
+ fprintf(f, "P6 320 240 255\n");
+ for (int y = 0; y < 240; y++)
+ for (int x = 0; x < 320; x++) {
+ uint16_t c = fb[y][x];
+ fputc((c >> 11) * 255 / 31, f), fputc((c >> 5 & 63) * 255 / 63, f), fputc((c & 31) * 255 / 31, f);
+ }
+ fclose(f);
+}
+
+static int fails;
+#define CHECK(c, ...) do { if (!(c)) { fails++; printf("FAIL %s:%d: ", __FILE__, __LINE__); printf(__VA_ARGS__); printf("\n"); } } while (0)
+
+static tm_game U, B;
+
+/* a stage with the player alone in it: a free row and column round (7, 7) in a 15 x 15 box of walls */
+static void room(tm_game *t) {
+ tm_new_progress(&t->p);
+ tm_start(t, 0, 7);
+ memset(t->tile, 0, sizeof t->tile);
+ memset(t->look, 0, sizeof t->look);
+ memset(t->a, 0, sizeof t->a);
+ memset(t->plat, 0, sizeof t->plat);
+ memset(t->rotor, 0, sizeof t->rotor);
+ memset(t->ball, 0, sizeof t->ball);
+ memset(t->snake, 0, sizeof t->snake);
+ t->w = 15, t->h = 15;
+ for (int y = 0; y < 15; y++)
+ for (int x = 0; x < 15; x++) t->tile[y * 15 + x] = (x == 0 || y == 0 || x == 14 || y == 14) ? T_WALL : T_EMPTY;
+ t->x = 7 * TT, t->y = 7 * TT, t->face = 0, t->dx = t->dy = 0;
+ t->pstate = ST_IDLE;
+ t->lava_max = 0;
+ t->dots = t->dots_all = 0, t->score = 0;
+ tm_save_prev(t);
+}
+static void steps(tm_game *t, int n, int dir) {
+ for (int i = 0; i < n; i++) tm_step(t, i == 0 ? dir : -1, false);
+}
+
+/* ---------------------------------------------------------------- the rules against the spec */
+static void units(void) {
+ /* settings (RSettings.InitDefaults) */
+ CHECK(tm_level_xp[1] == 1000 && tm_level_xp[19] == 7645579 && tm_level(0) == 1 && tm_level(999) == 1 &&
+ tm_level(1000) == 2 && tm_level(8000000) == 20, "levels");
+ CHECK(tm_upgrade_cost[0] == 200 && tm_upgrade_cost[8] == 5000, "upgrade costs");
+ CHECK(tm_powerup_secs[0][0] == 10 && tm_powerup_secs[0][9] == 40 && tm_powerup_secs[1][9] == 14 &&
+ tm_powerup_secs[2][2] == 8 && tm_powerup_secs[3][9] == 20, "powerup effects");
+ CHECK(tm_mask_cost[1] == 200 && tm_mask_cost[2] == 500 && tm_mask_cost[9] == 5000 && tm_mask_cost[15] == 5000 &&
+ tm_mask_level[15] == 20 && tm_mask_level[8] == 8, "masks");
+ CHECK(tm_mission_goal[0][6] == 49 && tm_mission_goal[2][6] == 10000 && tm_mission_levels[3] == 6 &&
+ tm_mission_levels[5] == 5 && tm_mission_reward[6] == 100, "missions");
+ /* the data: 200 stages, 517 sections by type (Begin 5, Easy 106 ...), the lava stages */
+ static const uint8_t count[15] = {5, 106, 70, 69, 60, 18, 22, 16, 60, 17, 26, 10, 10, 1, 27};
+ for (int t = 0; t < 15; t++) CHECK(tm_section_count[t] == count[t], "sections of type %d: %u", t, tm_section_count[t]);
+ int lava = 0;
+ for (int s = 0; s < 200; s++) {
+ CHECK(tm_stages[s].w * tm_stages[s].h <= TM_CELLS, "stage %d too big", s);
+ if (tm_stages[s].extra) lava++;
+ }
+ CHECK(lava == 7 && tm_stages[3].extra == 13 && tm_stages[186].extra == 20 && tm_stages[92].extra == 10, "lava stages");
+ for (int i = 0; i < 517; i++) CHECK(tm_sections[i].w == 13 && tm_sections[i].h >= 4 && tm_sections[i].h <= 15, "section %d", i);
+
+ /* the dash: 5 units a second (25600/9 units a step), until a wall; the stop is the cell before it */
+ room(&U);
+ tm_step(&U, 1, false);
+ CHECK(U.dx == 1 && U.x == 7 * TT + 25600 / 9, "a step of a dash: %d", U.x - 7 * TT);
+ steps(&U, 20, -1);
+ CHECK(tm_standing(&U) && U.x == 13 * TT && U.face == 1, "stops beside the wall: %d face %d", U.x, U.face);
+ /* not into the wall it stands against; any other way */
+ tm_step(&U, 1, false);
+ CHECK(tm_standing(&U), "dashed into its own wall");
+ tm_step(&U, 2, false);
+ CHECK(U.dy == 1, "no dash up");
+ steps(&U, 20, -1);
+ CHECK(U.y == 13 * TT && U.face == 2, "up to the ceiling");
+ /* a dash pressed in the last 0.1 s of a dash is taken on landing (6 steps), not an earlier one */
+ room(&U);
+ tm_step(&U, 0, false); /* 6 tiles to the wall: 9 steps */
+ steps(&U, 1, -1);
+ tm_step(&U, 2, false); /* pressed too early */
+ steps(&U, 12, -1);
+ CHECK(tm_standing(&U) && U.x == TT && U.y == 7 * TT, "an early press was kept");
+ room(&U);
+ tm_step(&U, 0, false);
+ steps(&U, 6, -1);
+ tm_step(&U, 2, false); /* within 0.1 s of the landing */
+ steps(&U, 2, -1);
+ CHECK(U.dy == 1 && U.x == TT, "a late press was lost");
+
+ /* dots score the multiplier (the level), coins one more coin; ice 1 + the multiplier */
+ room(&U);
+ U.tile[7 * 15 + 9] = T_DOT, U.tile[7 * 15 + 11] = T_COIN, U.tile[7 * 15 + 12] = T_ICE;
+ uint32_t c0 = U.p.coins;
+ tm_step(&U, 1, false), steps(&U, 20, -1);
+ CHECK(U.score == 1 + 1 + 2 && U.p.coins == c0 + 1 && U.dots == 2 && U.x == 13 * TT, "dot, coin and ice: %u", U.score);
+ U.p.xp = 1000, U.mult = (uint8_t)tm_level(U.p.xp);
+ U.tile[7 * 15 + 9] = T_DOT;
+ tm_step(&U, 0, false), steps(&U, 20, -1);
+ CHECK(U.score == 4 + 2, "a level 2 dot: %u", U.score);
+ /* spikes kill a dash into them; a shield takes it and the player goes back to its last landing */
+ room(&U);
+ U.tile[7 * 15 + 11] = T_SPIKES;
+ tm_step(&U, 1, false), steps(&U, 10, -1);
+ CHECK(!U.alive && U.ev_dead, "spikes");
+ room(&U);
+ U.tile[7 * 15 + 11] = T_SPIKES;
+ U.p.shields = 1;
+ tm_step(&U, -1, true);
+ CHECK(U.pw_time[PW_SHIELD] == SEC(30) - 1 && U.p.shields == 0, "the shield: 30 s");
+ tm_step(&U, 1, false), steps(&U, 20, -1);
+ CHECK(U.alive && U.pw_time[PW_SHIELD] == 0 && U.x == 7 * TT && tm_standing(&U), "a shield hit: back at %d", U.x / TT);
+
+ /* the things' speeds (prefab values): bats 0.56 units a second, bullets 2.22, platforms 3.33, snakes 1.67 */
+ room(&U);
+ tm_actor *bat = tm_spawn(&U, A_BAT, 3 * TT, 3 * TT, 1, 0);
+ int32_t bx = bat->x;
+ steps(&U, 60, -1);
+ CHECK(bat->x - bx == UNITS(0.56f) || iabs(bat->x - bx - UNITS(0.56f)) <= 1, "bat: %d a second", bat->x - bx);
+ room(&U);
+ tm_actor *bul = tm_spawn(&U, A_BULLET, 2 * TT, 3 * TT, 1, 0);
+ steps(&U, 2, -1);
+ CHECK(bul->x == 2 * TT + 1263, "bullet: skips a step, then 2.22 units a second (%d)", bul->x - 2 * TT);
+ CHECK(UNITS(1.67f) / 60 == 950 && UNITS(3.33f) / 60 == 1894, "snake and platform speeds");
+ /* rocks: from 0.36 units a second, +3 each second: 1.86 units in the first second */
+ room(&U);
+ U.y = 100 * TT;
+ tm_actor *rock = tm_spawn(&U, A_ROCK, 7 * TT, 90 * TT, 0, -1);
+ rock->v = 23593;
+ for (int i = 0; i < 60; i++) U.y = 100 * TT, tm_step(&U, -1, false);
+ CHECK(iabs(90 * TT - rock->y - UNITS(1.86f)) < UNITS(0.05f), "a rock's first second: %d", 90 * TT - rock->y);
+ /* the cannons fire every 1.1 s once the lava is on, the fishes every 2.1 s, the rotors turn every 2.1 s */
+ room(&U);
+ U.tile[3 * 15 + 1] = T_CANNON_R;
+ int shots = 0;
+ for (int i = 0; i < 660; i++) {
+ tm_step(&U, -1, false);
+ for (int k = 0; k < TM_ACTORS; k++)
+ if (U.a[k].type == A_BULLET && U.a[k].x == 2 * TT && !U.a[k].timer && U.a[k].wait == 0) shots++, U.a[k].wait = 1;
+ }
+ CHECK(shots == 0, "cannons before the first dash: %d", shots);
+ U.lava_on = 1;
+ for (int i = 0; i < 660; i++) {
+ tm_step(&U, -1, false);
+ for (int k = 0; k < TM_ACTORS; k++)
+ if (U.a[k].type == A_BULLET && U.a[k].x == 2 * TT && !U.a[k].timer && U.a[k].wait == 0) shots++, U.a[k].wait = 1;
+ }
+ CHECK(shots == 10, "a cannon in 11 s: %d shots", shots);
+ /* timer walls close for 2 s behind the player */
+ room(&U);
+ U.tile[7 * 15 + 9] = T_TIMER_WALL;
+ tm_step(&U, 1, false), steps(&U, 20, -1);
+ CHECK(tm_timer_wall_on(&U, 9, 7), "timer wall closed");
+ tm_step(&U, 0, false), steps(&U, 20, -1);
+ CHECK(U.x == 10 * TT, "stopped by the closed timer wall: %d", U.x / TT);
+ steps(&U, 150, -1);
+ CHECK(tm_timer_wall_on(&U, 9, 7), "the timer wall stays closed while the player stands against it");
+ tm_step(&U, 1, false), steps(&U, 120, -1);
+ CHECK(!tm_timer_wall_on(&U, 9, 7), "timer wall open 2 s later");
+
+ /* the arcade: the lava waits for the first dash, starts 10.5 tiles down at 0.19 units a second, speeds up to
+ * 0.38 (in about 48 s), half as fast within 3 tiles, never more than 17 tiles behind */
+ tm_new_progress(&U.p);
+ tm_start(&U, -1, 11);
+ CHECK(U.lava_y == -LAVA_BELOW && U.x == 6 * TT && U.y == 0 && U.zone == 0 && U.zone_len == 10, "the arcade's start");
+ steps(&U, 60, -1);
+ CHECK(U.lava_y == -LAVA_BELOW && !U.lava_on, "lava before the first dash");
+ room(&U);
+ U.lava_speed = (int32_t)(0.19 * (1 << 24)), U.lava_max = (int32_t)(0.38 * (1 << 24)), U.lava_on = 1;
+ tm_step(&U, -1, false);
+ CHECK(U.lava_y == -10 * TT, "pulled up to 17 tiles behind: %d", U.lava_y);
+ int32_t l0 = U.lava_y;
+ steps(&U, 60, -1);
+ CHECK(U.lava_y - l0 >= UNITS(0.19f) && U.lava_y - l0 <= UNITS(0.2f), "a second of lava: %d", U.lava_y - l0);
+ CHECK(U.lava_speed > (int32_t)(0.19 * (1 << 24)) && U.lava_speed < (int32_t)(0.21 * (1 << 24)), "lava speed after 1 s");
+ for (int i = 0; i < 60 * 46; i++) U.y = U.lava_y + 10 * TT, tm_step(&U, -1, false); /* (the player kept away) */
+ CHECK(U.lava_speed < U.lava_max, "not yet at top speed");
+ for (int i = 0; i < 60 * 3; i++) U.y = U.lava_y + 10 * TT, tm_step(&U, -1, false);
+ CHECK(U.lava_speed == U.lava_max, "top speed after about 48 s");
+ U.y = 7 * TT;
+ U.lava_y = U.y - 2 * TT, U.lava_sub = 0, l0 = U.lava_y;
+ tm_step(&U, -1, false);
+ int64_t full = (int64_t)U.lava_max * 5 / 576, got = ((int64_t)U.lava_y - l0) * 256 + U.lava_sub;
+ CHECK(got * 6 >= full * 5 - 256 && got * 6 <= full * 5 + 256, "2 tiles below: 5/6 of the speed (%lld of %lld)", (long long)got, (long long)full);
+ /* the zones: 10 + 2z sections; touching the zone exit makes the next zone */
+ tm_new_progress(&U.p);
+ tm_start(&U, -1, 12);
+ CHECK(U.style == 0 && U.colors == 0, "zone 0's look");
+ tm_change_zone(&U);
+ CHECK(U.zone == 1 && U.style >= 1 && U.style <= 4 && U.zone_changed && U.color_wait == 18, "zone change");
+
+ /* masks: Cyclop's 20% more coins; Dog: no snakes */
+ tm_new_progress(&U.p);
+ U.p.mask = 1, U.p.masks |= 2;
+ tm_start(&U, -1, 1);
+ CHECK(U.coin_chance == 3277 * 120 / 100 && U.bonus_coin_chance == 19661 * 120 / 100, "Cyclop's coins");
+ U.p.mask = 3, U.p.masks |= 8;
+ tm_start(&U, -1, 1);
+ CHECK(U.no_snakes && !U.no_monkeys, "Dog: no snakes");
+ /* the shop and masks */
+ tm_progress p;
+ tm_new_progress(&p);
+ p.coins = 1000;
+ CHECK(tm_buy_shield(&p) && p.shields == 1 && p.coins == 800, "a shield costs 200");
+ CHECK(tm_buy_upgrade(&p, 0) && tm_buy_upgrade(&p, 0) && p.upgrades[0] == 2 && p.coins == 200, "upgrades 200 then 400");
+ CHECK(!tm_buy_mask(&p, 1), "Cyclop needs level 2");
+ p.xp = 1000;
+ CHECK(tm_buy_mask(&p, 1) && p.coins == 0 && p.mask == 1, "Cyclop: 200 coins at level 2");
+ CHECK(tm_progress_ok(&p), "progress");
+ /* missions: complete stage N is exact, points in one run at least, the reward and a new one */
+ tm_new_progress(&p);
+ tm_mission_add(&p, 0, 1);
+ CHECK(!tm_mission_ready(&p, 0), "stage 1 is not stage 2");
+ tm_mission_new_run(&p);
+ tm_mission_add(&p, 0, 2);
+ CHECK(tm_mission_ready(&p, 0), "stage 2 done");
+ uint32_t r = 5, coins = p.coins;
+ CHECK(tm_claim_mission(&p, 0, &r) && p.coins == coins + 25 && p.missions_done[0] == 1, "the reward");
+ CHECK(p.mission_type[0] != 1 && p.mission_type[0] != 2 && p.mission_index[0] == 0, "a new mission");
+ CHECK(tm_progress_ok(&p), "progress after a mission");
+ /* revives: 200 coins, one in a stage, three in the arcade */
+ room(&U);
+ U.p.coins = 1000;
+ U.tile[7 * 15 + 11] = T_SPIKES;
+ tm_step(&U, 1, false), steps(&U, 10, -1);
+ CHECK(tm_revives_left(&U) == 1 && tm_revive(&U) && U.p.coins == 800 && tm_revives_left(&U) == 0, "a stage's revive");
+ steps(&U, 2, -1);
+ CHECK(U.alive && U.x == 7 * TT, "revived at the last landing");
+ /* the wheel: the first spin is free, then 200 coins (or a free one every 4 hours of play) */
+ tm_new_progress(&p);
+ tm_wheel w;
+ r = 9;
+ CHECK(tm_wheel_start(&p, &w, &r) && p.coins == 0 && p.chest_wait == TM_CHEST_WAIT, "the free spin");
+ for (int i = 0; i < 2000 && w.spinning; i++) tm_wheel_step(&p, &w, &r);
+ CHECK(w.done && w.sector < 8 && (p.coins > 0 || p.shields > 0 || p.mask), "the wheel stopped on %d", w.sector);
+ CHECK(!tm_wheel_start(&p, &w, &r) || p.coins >= 0, "no spin without coins");
+}
+
+/* ---------------------------------------------------------------- the reference (optional) */
+static int refcheck(void) {
+ const char *ref = getenv("TOTM_REF");
+ if (!ref) return 0;
+ char dir[600], path[900];
+ snprintf(dir, sizeof dir, "%s/text", ref);
+ DIR *d = opendir(dir);
+ if (!d) return 0;
+ char stages[300] = "", sections[300] = "";
+ struct dirent *e;
+ while ((e = readdir(d))) {
+ if (!strncmp(e->d_name, "stages__", 8)) snprintf(stages, sizeof stages, "%s", e->d_name);
+ if (!strncmp(e->d_name, "sections__", 10)) snprintf(sections, sizeof sections, "%s", e->d_name);
+ }
+ closedir(d);
+ if (!stages[0] || !sections[0]) return 0;
+ static uint8_t buf[1 << 20], cells[TM_CELLS];
+ snprintf(path, sizeof path, "%s/%s", dir, stages);
+ FILE *f = fopen(path, "rb");
+ size_t n = f ? fread(buf, 1, sizeof buf, f) : 0;
+ if (f) fclose(f);
+ size_t at = 0;
+ for (int s = 0; s < 200; s++) {
+ CHECK(at + 3 <= n, "reference stages cut short");
+ if (at + 3 > n) return 1;
+ int lava = buf[at], w = buf[at + 1], h = buf[at + 2];
+ np_lz_unpack(tm_maps + tm_stages[s].at, tm_stages[s].size, cells, TM_CELLS);
+ CHECK(lava == tm_stages[s].extra && w == tm_stages[s].w && h == tm_stages[s].h && !memcmp(cells, buf + at + 3, (size_t)(w * h)), "stage %d differs from the reference", s);
+ at += 3 + (size_t)(w * h);
+ }
+ snprintf(path, sizeof path, "%s/%s", dir, sections);
+ f = fopen(path, "rb");
+ n = f ? fread(buf, 1, sizeof buf, f) : 0;
+ if (f) fclose(f);
+ at = 0;
+ /* the sections, by type in the original's order */
+ int seen[15] = {0};
+ for (int i = 0; i < 517 && at + 2 <= n; i++) {
+ int t = buf[at], len = buf[at + 1];
+ int k = tm_section_first[t] + seen[t]++;
+ np_lz_unpack(tm_maps + tm_sections[k].at, tm_sections[k].size, cells, TM_CELLS);
+ CHECK(tm_sections[k].h * 13 == len && !memcmp(cells, buf + at + 2, (size_t)len), "section %d differs from the reference", i);
+ at += 2 + (size_t)len;
+ }
+ return 1;
+}
+
+/* ---------------------------------------------------------------- the bot */
+/* a hash of the game: the same run gives the same hash, here and in the CI */
+static uint32_t state_hash(const tm_game *t) {
+ uint32_t h = tm_sum(t->tile, sizeof t->tile);
+ h = (h ^ (uint32_t)t->x) * 16777619u, h = (h ^ (uint32_t)t->y) * 16777619u;
+ h = (h ^ t->score) * 16777619u, h = (h ^ (uint32_t)t->lava_y) * 16777619u;
+ for (int i = 0; i < TM_ACTORS; i++) h = (h ^ (uint32_t)t->a[i].x) * 16777619u, h = (h ^ (uint32_t)t->a[i].y) * 16777619u;
+ return (h ^ t->rng ^ t->tick) * 16777619u;
+}
+
+/* the arcade with the bot for a few minutes of the game: how high it got */
+static uint32_t arcade_run(uint32_t seed, int seconds, int *zone, int *bonus) {
+ tm_new_progress(&B.p);
+ tm_start(&B, -1, seed);
+ int t = 0;
+ uint8_t lastb = 0;
+ *bonus = 0;
+ while (B.alive && t < 60 * seconds) {
+ if (tm_standing(&B)) {
+ int m = bot_arcade_move(&B, 150);
+ if (m == 4) {
+ for (int i = 0; i < BOT_WAIT && B.alive; i++) tm_step(&B, -1, false), t++;
+ continue;
+ }
+ tm_step(&B, m < 0 ? 2 : m, false), t++;
+ } else {
+ tm_step(&B, -1, false), t++;
+ }
+ if (B.bonus && !lastb) ++*bonus;
+ lastb = B.bonus;
+ CHECK(B.ring_top - tm_cell(B.y) <= TM_H && B.lava_y < B.y + TT, "arcade seed %u: the world at %d", seed, tm_cell(B.y));
+ }
+ *zone = B.zone;
+ return state_hash(&B);
+}
+
+/* stages the search cannot clear in its node budget (big ones with long timed routes) */
+static const int16_t bot_misses[] = {41, 50, 87, 88, 93, 99, 106, 126, 137, 140, 142, 143, 144, 147, 167, 168, 181, 188};
+
+static void bot_stages(void) {
+ int cleared = 0;
+ for (int s = 0; s < 200; s++) {
+ bool known = false;
+ for (size_t k = 0; k < sizeof bot_misses / sizeof *bot_misses; k++) known |= bot_misses[k] == s;
+ tm_new_progress(&B.p);
+ bool won = bot_play_stage(&B, s, 1000 + (uint32_t)s, 20000);
+ if (won) {
+ cleared++;
+ CHECK(B.ev_won && B.alive, "stage %d", s);
+ } else {
+ CHECK(known, "the bot no longer clears stage %d", s);
+ }
+ }
+ printf("the bot cleared %d of the 200 stages\n", cleared);
+}
+
+/* ---------------------------------------------------------------- saves */
+static tm_progress saved[3];
+static void saves(void) {
+ memset(files, 0, sizeof files);
+ tm_progress a, b;
+ tm_new_progress(&a);
+ a.coins = 12345, a.best = 678, a.xp = 99999, a.reached = 57, a.stars[3] = 3, a.shields = 4, a.upgrades[2] = 5;
+ a.masks |= 1 << 6, a.mask = 6, a.mission_progress[1] = 3, a.missions_done[7] = 3, a.guide = 3;
+ CHECK(tm_progress_ok(&a), "a good progress");
+ CHECK(save_write(&a), "written");
+ CHECK(save_load(&b) && !memcmp(&a, &b, sizeof a), "read back exactly");
+ saved[0] = a;
+ /* damaged: one byte changed, cut short, a wrong version, a bad value: a fresh start (the copy is gone too) */
+ uint32_t n;
+ uint8_t *d = file_data(TM_SAVE_NAME, &n);
+ forget(TM_COPY_NAME);
+ d[20] ^= 0x40;
+ CHECK(!save_load(&b) && b.coins == 0 && b.masks == 1, "a damaged save is refused");
+ save_write(&a), forget(TM_COPY_NAME);
+ d = file_data(TM_SAVE_NAME, &n);
+ files[0].len = n - 5;
+ for (int i = 0; i < 4; i++)
+ if (files[i].on && !strcmp(files[i].name, TM_SAVE_NAME)) files[i].len = n - 5;
+ CHECK(!save_load(&b) && b.coins == 0, "a short save is refused");
+ save_write(&a), forget(TM_COPY_NAME);
+ d = file_data(TM_SAVE_NAME, &n);
+ tm_file *fl = (tm_file *)d;
+ fl->version++;
+ fl->sum = tm_sum(fl, offsetof(tm_file, sum));
+ CHECK(!save_load(&b), "another version is refused");
+ tm_progress bad = a;
+ bad.mask = 9; /* not bought */
+ save_write(&bad), forget(TM_COPY_NAME);
+ CHECK(!save_load(&b), "a mask not bought is refused");
+ /* the copy in the Python script brings it back */
+ save_write(&a);
+ forget(TM_SAVE_NAME);
+ CHECK(save_load(&b) && !memcmp(&a, &b, sizeof a) && file_data(TM_SAVE_NAME, &n), "the copy brings the save back");
+ tm_new_progress(&saved[1]);
+ saved[2] = a, saved[2].coins = 0, saved[2].reached = 199, saved[2].xp = 9000000, saved[2].shields = 10;
+ saved[2].masks = 0xFFFF, saved[2].mask = 15, saved[2].best = 4000000000u;
+ for (int i = 0; i < 200; i++) saved[2].stars[i] = 3;
+}
+
+/* ---------------------------------------------------------------- the whole app with random keys */
+static uint32_t fz, fz_until, fz_held;
+static uint32_t fz_r(void) { return fz = fz * 1103515245u + 12345u, fz >> 8; }
+static uint32_t fuzz_keys(uint32_t frame) {
+ if (frame >= fz_until) {
+ static const uint32_t k[] = {K_OK, K_BACK, K_UP, K_DOWN, K_LEFT, K_RIGHT, K_OK, K_UP, K_LEFT, K_RIGHT, 0, 0};
+ fz_held = k[fz_r() % (sizeof k / sizeof k[0])];
+ fz_until = frame + 1 + fz_r() % 30;
+ }
+ return fz_held;
+}
+static void fuzz(unsigned sessions) {
+ memset(files, 0, sizeof files);
+ fz = 2024;
+ for (unsigned s = 0; s < sessions; s++) {
+ if (s % 50 == 0) memset(files, 0, sizeof files);
+ if (s % 50 == 10) save_write(&saved[0]);
+ if (s % 50 == 30) save_write(&saved[2]);
+ memset(&g, 0, sizeof g), memset(&ui, 0, sizeof ui);
+ script = fuzz_keys, frame_no = 0, fz_until = 0, quit_at = 300 + fz_r() % 3000;
+ storage_full = s % 97 == 13;
+ tm_clipped = 0;
+ tm_app_main();
+ storage_full = false;
+ tm_progress p;
+ uint32_t n;
+ bool any = file_data(TM_SAVE_NAME, &n) != 0;
+ CHECK(!any || save_load(&p), "session %u left a bad save", s);
+ CHECK(!tm_clipped, "session %u: text off the screen: %s", s, tm_clipped_text);
+ }
+ script = 0;
+}
+
+/* every screen with each kept progress: no text off the screen */
+static void screens(void) {
+ static const uint8_t all[] = {V_TITLE, V_STAGES, V_PLAY, V_PAUSE, V_QUIT, V_HELP, V_REVIVE, V_RESULTS, V_SHOP,
+ V_MASKS, V_MISSIONS, V_CHEST};
+ for (int k = 0; k < 3; k++)
+ for (int mode = -1; mode <= 0; mode++) {
+ B.p = saved[k];
+ tm_start(&B, mode < 0 ? -1 : 5, 3);
+ for (unsigned i = 0; i < sizeof all; i++)
+ for (int sel = 0; sel < 16; sel++) {
+ tm_ui u;
+ memset(&u, 0, sizeof u);
+ u.screen = all[i], u.under = V_PAUSE, u.sel = (uint8_t)(sel % 4), u.page = (uint8_t)(sel % TM_HELP_PAGES);
+ u.mask_sel = (uint8_t)sel, u.shop_sel = (uint8_t)(sel % 5), u.mission_sel = (uint8_t)(sel % 3), u.stage_sel = (uint8_t)(sel * 13);
+ u.revive_left = 3000;
+ tm_clipped = 0;
+ tm_draw(&B, &u, plat_push);
+ CHECK(!tm_clipped, "screen %u (save %d, choice %d): text off the screen: %s", all[i], k, sel, tm_clipped_text);
+ }
+ }
+}
+
+static void test(void) {
+ units();
+ if (refcheck()) printf("the maps match the reference\n");
+ else printf("(no reference: TOTM_REF not set)\n");
+ bot_stages();
+ int z1, z2, b1, b2;
+ uint32_t h1 = arcade_run(21, 150, &z1, &b1), h2 = arcade_run(21, 150, &z2, &b2);
+ CHECK(h1 == h2, "the arcade run is not the same twice: %08x %08x", h1, h2);
+ CHECK(z1 >= 4, "the bot only reached zone %d", z1);
+ printf("the bot's arcade run: zone %d, %d bonus zones, %08x\n", z1, b1, h1);
+ CHECK(h1 == 0x93b0be5cu, "the arcade run's hash changed: %08x (the rules changed, or are not the same here)", h1);
+ saves();
+ screens();
+ fuzz(300);
+ printf("%s\n", fails ? "FAILED" : "all good");
+}
+
+/* ---------------------------------------------------------------- pictures */
+static char outdir[256];
+static void save_shot(const char *name) {
+ char p[300];
+ snprintf(p, sizeof p, "%s/%s.ppm", outdir, name);
+ shot(p);
+}
+static void draw_ui(const tm_game *t, uint8_t screen) {
+ tm_ui u;
+ memset(&u, 0, sizeof u);
+ u.screen = screen;
+ tm_draw(t, &u, plat_push);
+}
+/* how much is on the screen round the player */
+static int busy(const tm_game *t) {
+ int n = 0;
+ for (int y = tm_cell(t->cam_y) - 8; y <= tm_cell(t->cam_y) + 8; y++)
+ for (int x = tm_cell(t->cam_x) - 7; x <= tm_cell(t->cam_x) + 7; x++) {
+ uint8_t c = tm_tile(t, x, y);
+ n += c == T_DOT || c == T_COIN ? 1 : c != T_EMPTY && !tm_wallish(c) ? 3 : 0;
+ }
+ for (int i = 0; i < TM_ACTORS; i++) n += t->a[i].type && iabs(t->a[i].y - t->cam_y) < 8 * TT ? 4 : 0;
+ return n + (t->pw_time[PW_SHIELD] > 0) * 5;
+}
+static void arcade_until(tm_game *t, int seconds, bool (*want)(const tm_game *), tm_game *best) {
+ int bs = -1;
+ for (int k = 0; k < 60 * seconds && t->alive; k++) {
+ if (tm_standing(t)) {
+ int m = bot_arcade_move(t, 150);
+ if (m == 4) m = -1;
+ tm_step(t, m < 0 ? -1 : m, false);
+ } else {
+ tm_step(t, -1, false);
+ }
+ if (best && t->tick % 10 == 0 && t->alive && !tm_standing(t) && (!want || want(t))) {
+ int b = busy(t);
+ if (b > bs) bs = b, *best = *t;
+ }
+ }
+}
+static void shots(void) {
+ static tm_game best;
+ tm_ui u;
+ memset(&u, 0, sizeof u);
+ tm_new_progress(&B.p);
+ B.p.coins = 1460, B.p.xp = 40000, B.p.shields = 3, B.p.best = 2410, B.p.reached = 23;
+ for (int i = 0; i < 23; i++) B.p.stars[i] = (uint8_t)(1 + (i * 7) % 3);
+ B.p.masks = 0x2F, B.p.mask = 0;
+ tm_start(&B, -1, 77);
+ draw_ui(&B, V_TITLE), save_shot("title");
+ /* the arcade a minute in, at its busiest */
+ B.p.shields = 3;
+ arcade_until(&B, 60, NULL, &best);
+ draw_ui(&best, V_PLAY), save_shot("shot");
+ arcade_until(&B, 40, NULL, &best);
+ best.lava_y = best.y - 5 * TT; /* (the bot keeps well ahead of it) */
+ draw_ui(&best, V_PLAY), save_shot("lava");
+ u.screen = V_PAUSE, u.sel = 0;
+ tm_draw(&best, &u, plat_push), save_shot("pause");
+ /* a bonus zone (the bot finds one sooner with the bonus zones' cooldown short) */
+ for (uint32_t seed = 3; seed < 40; seed++) {
+ tm_new_progress(&U.p);
+ U.p.shields = 3;
+ tm_start(&U, -1, seed);
+ U.bonus_cool = U.bonus_cool_var = U.cd_bonus = 60;
+ int k = 0;
+ while (U.alive && !U.bonus && k++ < 60 * 240) {
+ int m = tm_standing(&U) ? bot_arcade_move(&U, 150) : -1;
+ tm_step(&U, m == 4 ? -1 : m, false);
+ }
+ if (!U.bonus) continue;
+ for (k = 0; k < 150 && U.alive; k++) {
+ int m = tm_standing(&U) ? bot_arcade_move(&U, 150) : -1;
+ tm_step(&U, m == 4 ? -1 : m, false);
+ }
+ draw_ui(&U, V_PLAY), save_shot("bonus");
+ break;
+ }
+ /* a stage */
+ tm_start(&B, 4, 5);
+ for (int i = 0; i < 40; i++) tm_step(&B, -1, false);
+ draw_ui(&B, V_PLAY), save_shot("stage");
+ u.screen = V_STAGES, u.stage_sel = 23;
+ tm_draw(&B, &u, plat_push), save_shot("stages");
+ u.screen = V_SHOP, u.shop_sel = 2;
+ tm_draw(&B, &u, plat_push), save_shot("shop");
+ u.screen = V_MASKS, u.mask_sel = 5;
+ tm_draw(&B, &u, plat_push), save_shot("masks");
+ B.p.mission_progress[1] = 1;
+ u.screen = V_MISSIONS, u.mission_sel = 1;
+ tm_draw(&B, &u, plat_push), save_shot("missions");
+ u.screen = V_CHEST;
+ uint32_t r = 3;
+ B.p.chest_free = 1;
+ tm_wheel_start(&B.p, &u.wheel, &r);
+ for (int i = 0; i < 40; i++) tm_wheel_step(&B.p, &u.wheel, &r);
+ tm_draw(&B, &u, plat_push), save_shot("chest");
+ u.screen = V_HELP, u.under = V_TITLE, u.page = 0, u.first_run = 1;
+ tm_draw(&B, &u, plat_push), save_shot("help");
+}
+
+/* frames of the bot in the arcade, for the GIF (tools/record.py --frames) */
+static void film(int n) {
+ tm_new_progress(&B.p);
+ B.p.shields = 2;
+ tm_start(&B, -1, 77);
+ arcade_until(&B, 26, NULL, NULL);
+ for (int f = 0; f < n && B.alive; f++) {
+ for (int k = 0; k < 2; k++) {
+ int m = -1;
+ if (tm_standing(&B)) {
+ m = bot_arcade_move(&B, 150);
+ if (m == 4) m = -1;
+ }
+ tm_step(&B, m, false);
+ }
+ draw_ui(&B, V_PLAY);
+ char p[300];
+ snprintf(p, sizeof p, "%s/f_%06d.raw", outdir, f * 1000 / 30);
+ FILE *o = fopen(p, "wb");
+ if (!o) exit(2);
+ fwrite(fb, 2, 320 * 240, o);
+ fclose(o);
+ }
+}
+
+int main(int argc, char **argv) {
+ if (argc < 3) return 2;
+ snprintf(outdir, sizeof outdir, "%s", argv[2]);
+ if (!strcmp(argv[1], "test")) test();
+ else if (!strcmp(argv[1], "shots")) shots();
+ else if (!strcmp(argv[1], "film") && argc > 3) film(atoi(argv[3]));
+ return fails ? 1 : 0;
+}
diff --git a/games/tombofthemask/tests/test.c b/games/tombofthemask/tests/test.c
deleted file mode 100644
index 36824e21..00000000
--- a/games/tombofthemask/tests/test.c
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "game.h"
-#include "render.h"
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stddef.h>
-static Game g;
-static uint16_t screen[320*240];
-static void push(int x,int y,int w,int h,const uint16_t*p){assert(x>=0&&y>=0&&x+w<=320&&y+h<=240);for(int j=0;j<h;j++)memcpy(screen+(y+j)*320+x,p+j*w,w*2);}
-static void capture(const char*name,unsigned view,unsigned selected){render_invalidate();render(&g,view,selected,false,push);char path[100];snprintf(path,sizeof(path),"%s.ppm",name);FILE*f=fopen(path,"wb");assert(f);fprintf(f,"P6\n320 240\n255\n");for(unsigned i=0;i<320*240;i++){unsigned c=screen[i];unsigned char rgb[3]={(c>>11)*255/31,((c>>5)&63)*255/63,(c&31)*255/31};fwrite(rgb,1,3,f);}fclose(f);}
-static void fixture(unsigned tile){game_start(&g,0,false);g.width=g.height=9;memset(g.tiles,3,sizeof(g.tiles));memset(g.actors,0,sizeof(g.actors));for(int y=1;y<8;y++)for(int x=1;x<8;x++)g.tiles[y*9+x]=0;g.x=4*Q;g.y=4*Q;g.tiles[4*9+6]=tile;}
-static void settle(int dir,unsigned ticks){game_step(&g,dir,false);for(unsigned i=1;i<ticks;i++)game_step(&g,-1,false);}
-int main(void){game_new(&g,1234);assert(g.p.unlocked==1);capture("title",TITLE,0);capture("map",STAGES,0);game_start(&g,0,false);capture("stage1",PLAY,0);printf("Start %d %d dimensions %u %u\n",g.x/Q,g.y/Q,g.width,g.height);assert(g.x==15*Q&&g.y==33*Q);settle(1,100);assert(g.x==18*Q&&g.y==33*Q&&!g.dx&&!g.dy);settle(2,100);assert(g.y==28*Q);assert(g.stars==0);settle(0,100);assert(g.stars==1);capture("stage1-star",PLAY,0);
- fixture(0);settle(1,60);assert(g.x==7*Q&&g.y==4*Q&&!g.dx);fixture(8);settle(1,60);assert(g.dead);fixture(8);g.p.shields=1;game_step(&g,1,true);settle(-1,60);assert(!g.dead&&!g.p.shields&&g.invincible);
- fixture(98);g.tiles[4*9+4]=98;settle(-1,100);assert(g.dead);
- fixture(7);settle(1,60);assert(g.tiles[4*9+6]==0&&!g.dead);fixture(121);settle(1,200);assert(g.tiles[4*9+6]==121);
- fixture(4);settle(1,60);assert(g.stars==1);fixture(2);settle(1,60);assert(g.won);g.total_dots=g.dots;game_finish(&g);unsigned coins=g.p.coins;game_finish(&g);assert(g.p.coins==coins);
- fixture(49);g.tiles[2*9+2]=61;settle(1,10);assert(g.portal_cooldown&&g.dx==0&&g.dy);
- fixture(145);settle(1,60);assert(g.bonus);fixture(146);settle(1,60);assert(g.freeze);fixture(147);settle(1,60);assert(g.magnet);fixture(148);settle(1,60);assert(g.boost);
- uint8_t save[SAVE_BYTES],bad[SAVE_BYTES];Progress p;save_encode(&g.p,save);assert(save_decode(&p,save,sizeof(save)));assert(!memcmp(&p,&g.p,sizeof(p)));for(unsigned i=0;i<SAVE_BYTES;i++){memcpy(bad,save,sizeof(bad));bad[i]^=0x40;assert(!save_decode(&p,bad,sizeof(bad)));}assert(!save_decode(&p,NULL,0));assert(!save_decode(&p,save,SAVE_BYTES-1));
- g.p.coins=100000;assert(game_shop(&g,0));for(unsigned i=1;i<=4;i++)for(unsigned j=0;j<9;j++)assert(game_shop(&g,i));for(unsigned i=1;i<=4;i++)assert(!game_shop(&g,i));assert(!game_shop(&g,99));assert(!game_mask(&g,15));g.p.xp=20000000;assert(game_mask(&g,15));
- for(unsigned type=0;type<8;type++){g.p.mission_counts[type]=mission_goals[type][0];unsigned before=g.p.coins;assert(game_mission_claim(&g,type));assert(g.p.coins==before+mission_rewards[0]);assert(!game_mission_claim(&g,type));}assert(!game_mission_claim(&g,8));
- g.p.coins=10000;assert(game_chest(&g));assert(!g.p.free_chest&&g.p.next_chest==g.p.playtime+14400);for(unsigned i=0;i<10;i++)assert(game_chest(&g));g.p.playtime=g.p.next_chest;g.p.coins=0;assert(game_chest(&g));save_encode(&g.p,save);assert(save_decode(&p,save,sizeof(save))&&!memcmp(&p,&g.p,sizeof(p)));capture("missions",MISSIONS,2);g.combo=0;capture("chest",CHEST,0);
- unsigned maps_ok=0,stages_ok=0;uint8_t cells[CELLS];for(unsigned m=0;m<717;m++){int n=map_decode(m,cells,sizeof(cells));assert(n==maps[m].w*maps[m].h);++maps_ok;if(m<200){assert(game_start(&g,m,false));unsigned start=0,exit=0,stars=0;for(int i=0;i<n;i++){start+=cells[i]==1;exit+=cells[i]==2;stars+=cells[i]==4;}assert(start==1&&exit==1&&stars>=3);++stages_ok;}}
- unsigned random=123,ticks=0;for(unsigned m=0;m<200;m++){game_start(&g,m,false);g.shield=65000;for(unsigned t=0;t<1500;t++){++ticks;random=random*1664525+1013904223;game_step(&g,(t%25==0)?(int)((random>>28)%4):-1,false);assert(g.x>=0&&g.y>=0&&g.x<g.width*Q&&g.y<g.height*Q);if(g.dead||g.won)break;}}
- game_start(&g,0,true);g.invincible=65000;for(unsigned t=0;t<12000;t++){if(t%70==0){g.y=30*Q;g.x=6*Q;}game_step(&g,t%20==0?(int)((t/20)%4):-1,false);assert(g.height==128&&g.width==13);}capture("arcade",PLAY,0);assert(g.height_score>0);
- game_start(&g,29,false);capture("stage30",PLAY,0);game_start(&g,99,false);capture("stage100",PLAY,0);capture("pause",PAUSE,0);capture("masks",MASKS,15);capture("shop",SHOP,2);capture("help",HELP,0);capture("save-error",SAVE_ERROR,0);
- Progress pf=g.p;pf.unlocked=190;pf.shields=10;save_encode(&pf,save);FILE*f=fopen("stage190.sav","wb");assert(f);fwrite(save,1,sizeof(save),f);fclose(f);
- f=fopen("host-report.json","w");assert(f);fprintf(f,"{\"game_bytes\":%zu,\"progress_bytes\":%zu,\"x_offset\":%zu,\"y_offset\":%zu,\"tick_offset\":%zu,\"maps\":%u,\"stages\":%u,\"random_ticks\":%u}",sizeof(Game),sizeof(Progress),offsetof(Game,x),offsetof(Game,y),offsetof(Game,tick),maps_ok,stages_ok,ticks);fclose(f);printf("PASS: %u maps, %u complete stage layouts, movement, traps, pickups, shop, save corruption and random-input soak. Game=%zu Progress=%zu\n",maps_ok,stages_ok,sizeof(Game),sizeof(Progress));}
diff --git a/games/tombofthemask/tests/test_arm.py b/games/tombofthemask/tests/test_arm.py
deleted file mode 100644
index 08d0e164..00000000
--- a/games/tombofthemask/tests/test_arm.py
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/usr/bin/env python3
-"""Actual ARM .nwa tests: three calculator profiles, physics, save/reload and safe exit.
-Requires the repository emulator's dependencies (Unicorn, pyelftools, Pillow).
-"""
-import argparse
-import io
-import json
-import os
-from pathlib import Path
-import re
-import shlex
-import struct
-import tempfile
-import types
-
-ROOT = Path(__file__).resolve().parents[1]
-REPO = ROOT.parents[1]
-emu_path = REPO/'tools/emu.py'
-emu = types.ModuleType('arcade_emu');emu.__file__=str(emu_path);emu.io=io
-source = emu_path.read_text().replace('ELFFile(open(elf, "rb"))','ELFFile(io.BytesIO(open(elf, "rb").read()))')
-source = source.replace('cmd = [nwlink, "nwa-elf",','cmd = nwlink + ["nwa-elf",')
-source = source.replace('chunk = CPU_HZ // 1000','chunk = CPU_HZ // 10000')
-source = source.replace('self.now_ms += 1\n','self.now_ms += 0.1\n')
-source = source.replace(' next_frame = self.now_ms if frame_ms else None',
- ' self.checkpoint = until_ms\n next_frame = self.now_ms if frame_ms else None')
-source = source.replace(' self.slept_ms += r0\n',
- ' self.slept_ms += r0\n if self.now_ms >= self.checkpoint: uc.emu_stop()\n')
-exec(compile(source,str(emu_path),'exec'),emu.__dict__)
-
-def presses(*items):
- return [(t,t+d,emu.KEYS[k]) for t,k,d in items]
-
-def storage(path,items):
- data=bytearray(emu.STORAGE_SIZE);offset=0
- for name,value in items:
- record=name.encode()+b'\0'+value;size=2+len(record)
- struct.pack_into('<H',data,offset,size);data[offset+2:offset+size]=record;offset+=size
- assert offset+2<=len(data)
- path.write_bytes(data)
-
-def records(data):
- result={};offset=0
- while offset+2<=len(data):
- n=struct.unpack_from('<H',data,offset)[0]
- if not n:break
- assert n>=3 and offset+n<=len(data)
- name,value=data[offset+2:offset+n].split(b'\0',1);result[name.decode()]=value;offset+=n
- return result
-
-def check_exit(c,upsilon=False):
- assert c.exited,'App did not exit'
- assert not c.violations,sorted(set(c.violations))
- assert not c.firmware_ram_changes(),'Firmware RAM changed'
- assert c.app_ram_clean(),'App RAM not cleared'
- assert c.locks==0 and c.max_locks==(0 if upsilon else 1)
- assert c.stack_used()<4096,c.stack_used()
-
-def uint(c,name):
- return struct.unpack('<I',bytes(c.uc.mem_read(c.symbols[name],4)))[0]
-
-def main():
- ap=argparse.ArgumentParser(description=__doc__);ap.add_argument('--nwlink',default='nwlink');a=ap.parse_args()
- nw=['node',a.nwlink]if Path(a.nwlink).is_file()and not a.nwlink.endswith(('.exe','.cmd'))else shlex.split(a.nwlink)
- out=ROOT/'output/arm';out.mkdir(parents=True,exist_ok=True);tempfile.tempdir=str(out)
- host=json.loads((ROOT/'output/host-report.json').read_text());nwa=str(ROOT/'output/tombofthemask-debug.nwa');report=[];sentinel=b'print(42)\n'
- for profile,model,system,ram in [('n0120','n0120','epsilon',153676),('n0110','n0110','epsilon',148928),('n0115','n0110','epsilon',133652),('upsilon','n0110','upsilon',107674)]:
- emu.configure(model,system,ram);st=out/(profile+'.bin');storage(st,[('keep.py',sentinel)])
- c=emu.Calculator(nwa,storage_file=str(st),nwlink=nw);c.enable_checks();c.keys=presses((400,'ok',80),(650,'ok',80),(900,'right',80),(1250,'up',80),(1700,'left',80),(2200,'back',80),(2700,'back',80),(3200,'home',120))
- c.run(300);c.save_png(str(out/(profile+'-title.png')));c.run(2050);assert uint(c,'current_view')==2
- c.save_png(str(out/(profile+'-play.png')));c.run(2350);assert uint(c,'current_view')==3
- before=bytes(c.uc.mem_read(c.symbols['game'],host['game_bytes']));c.run(2550);assert before==bytes(c.uc.mem_read(c.symbols['game'],host['game_bytes']))
- c.run(3000);draw=uint(c,'perf_max');frames=uint(c,'perf_frames');c.run(3800);check_exit(c,system=='upsilon')
- saved=records(st.read_bytes());assert saved['keep.py']==sentinel and len(saved['tombmask.sav'])==320
- d=emu.Calculator(nwa,storage_file=str(st),nwlink=nw);d.enable_checks();d.keys=presses((500,'onoff',150));d.run(1000);check_exit(d,system=='upsilon')
- assert records(st.read_bytes())['keep.py']==sentinel
- report.append(dict(profile=profile,move_pause_save_reload_exit='pass',frames=frames,slowest_draw_ms=draw,stack_bytes=max(c.stack_used(),d.stack_used())));print(report[-1],flush=True)
- emu.configure();c=emu.Calculator(nwa,nwlink=nw);c.enable_checks();c.keys=presses((0,'ok',1000),(1300,'home',120));c.run(500);assert uint(c,'current_view')==0;c.run(1900);check_exit(c)
- # Visit every secondary menu using only real calculator key events.
- c=emu.Calculator(nwa,nwlink=nw);c.enable_checks();c.keys=presses((300,'0',80),(700,'back',80),(1000,'down',80),(1300,'ok',80),(1650,'right',80),(1900,'back',80),(2200,'right',80),(2500,'ok',80),(2800,'back',80),(3200,'home',120))
- c.run(500);assert uint(c,'current_view')==8;c.save_png(str(out/'help.png'));c.run(1500);assert uint(c,'current_view')==7;c.save_png(str(out/'masks.png'));c.run(2700);assert uint(c,'current_view')==6;c.save_png(str(out/'shop.png'));c.run(3800);check_exit(c)
- # Arcade starts from the same menu and uses its own rising hazard.
- c=emu.Calculator(nwa,nwlink=nw);c.enable_checks();c.keys=presses((300,'right',80),(550,'ok',80),(900,'up',80),(1600,'right',80),(2300,'up',80),(5000,'home',120));c.run(4500);c.save_png(str(out/'arcade.png'));c.run(5700);check_exit(c)
- st=out/'full.bin';filler=b'x'*(emu.STORAGE_SIZE-24);storage(st,[('full.py',filler)])
- c=emu.Calculator(nwa,storage_file=str(st),nwlink=nw);c.enable_checks();c.keys=presses((400,'home',100),(1000,'ok',80),(1400,'1',80),(1800,'home',80),(2300,'back',80));c.run(700);assert uint(c,'current_view')==10;c.run(1200);assert uint(c,'current_view')==10;c.run(1600);assert uint(c,'current_view')==0;c.run(2900);check_exit(c);assert records(st.read_bytes())['full.py']==filler
- report.append(dict(launch_held_keys='pass',menus='pass',arcade='pass',full_storage_retry_continue_exit='pass'))
- # Complete stage 1 with all three stars, through real key events, then check the saved unlock.
- st=out/'complete-stage.bin';storage(st,[('keep.py',sentinel)]);route=json.loads((ROOT/'tests/first-stage-route.json').read_text())
- events=[(300,'ok',70),(550,'ok',70)]+[(900+i*600,k,70)for i,k in enumerate(route)]
- finish=900+len(route)*600;c=emu.Calculator(nwa,storage_file=str(st),nwlink=nw);c.enable_checks();c.keys=presses(*events,(finish+500,'home',120));c.run(finish)
- assert uint(c,'current_view')==4,'The complete stage route did not reach the results screen';c.save_png(str(out/'stage-clear.png'));c.run(finish+1100);check_exit(c)
- p=records(st.read_bytes())['tombmask.sav'];assert p[24]==2 and p[32]==3;report.append(dict(real_keys_stage_clear='Stage 1: all three stars, exit reached, stage 2 unlocked and saved'))
- st=out/'meta.bin';storage(st,[('keep.py',sentinel)]);c=emu.Calculator(nwa,storage_file=str(st),nwlink=nw);c.enable_checks();c.keys=presses((300,'1',80),(700,'right',80),(950,'back',80),(1250,'2',80),(1500,'ok',80),(3500,'back',80),(3800,'home',100));c.run(500);assert uint(c,'current_view')==11;c.save_png(str(out/'missions.png'));c.run(1450);assert uint(c,'current_view')==12;c.run(3300);c.save_png(str(out/'chest.png'));c.run(4400);check_exit(c);p=records(st.read_bytes())['tombmask.sav'];assert p[310]==0 and p[308]==1;report.append(dict(missions_chest_reward_save='pass'))
- for profile,model,ram in [('n0120','n0120',153676),('n0110','n0110',148928)]:
- emu.configure(model,'epsilon',ram);st=out/(profile+'-large-stage.bin');storage(st,[('keep.py',sentinel),('tombmask.sav',(ROOT/'output/stage190.sav').read_bytes())]);c=emu.Calculator(nwa,storage_file=str(st),nwlink=nw);c.enable_checks();c.keys=presses((300,'ok',70),(550,'ok',70),(800,'ok',70),(1100,'left',70),(1700,'up',70),(2300,'right',70),(2900,'down',70),(6500,'home',100));c.run(6000);r=dict(profile=profile,largest_stage=190,slowest_draw_ms=uint(c,'perf_max'),frames=uint(c,'perf_frames'),frames_over_33ms=uint(c,'perf_slow'));c.save_png(str(out/(profile+'-stage190.png')));c.run(7200);check_exit(c);r['stack_bytes']=c.stack_used();report.append(r);print(r,flush=True)
- (out/'report.json').write_text(json.dumps(report,indent=2)+'\n');print('ARM tests passed',flush=True)
-if __name__=='__main__':main()
diff --git a/games/tombofthemask/tests/test_assets.py b/games/tombofthemask/tests/test_assets.py
deleted file mode 100644
index af320a22..00000000
--- a/games/tombofthemask/tests/test_assets.py
+++ /dev/null
@@ -1,42 +0,0 @@
-"""Audit the lossless level conversion and generated asset reproducibility."""
-from pathlib import Path
-import hashlib,json,subprocess,sys
-from PIL import Image
-ROOT=Path(__file__).resolve().parents[1]
-COMMON=[3,19,0,8,98,4,7,1,2,31,121,73,74,97,85]
-def decode(m,stream):
- data=stream[m['offset']:m['offset']+m['size']];out=bytearray();i=0
- if m.get('format'):
- while i<len(data):
- flags=data[i];i+=1
- for bit in range(8):
- if i>=len(data):break
- if flags&(1<<bit):out.append(data[i]);i+=1
- else:
- distance=(data[i]|((data[i+1]&15)<<8))+1;n=(data[i+1]>>4)+3;i+=2
- assert distance<=len(out)
- for _ in range(n):out.append(out[-distance])
- else:
- while i<len(data):
- tag=data[i];i+=1;v=tag&15
- if v==15:v=data[i];i+=1
- else:v=COMMON[v]
- out.extend([v]*((tag>>4)+1))
- assert len(out)==m['w']*m['h']
- return out
-def main():
- a=ROOT/'assets';maps=json.loads((a/'maps.json').read_text());stream=(a/'maps.bin').read_bytes();assert len(maps)==717
- assert [m['name']for m in maps[:200]]==list(map(str,range(1,201)))
- for m in maps:assert hashlib.sha256(decode(m,stream)).hexdigest()==m['sha256']
- assert sum('_'in m['name']for m in maps)==517
- ref=json.loads((a/'reference.json').read_text());assert ref['commit']=='29006b0f11904704c390b457f7055c9fa1e53484';assert len(ref['masks'])==16
- provenance=json.loads((a/'provenance.json').read_text());assert provenance['stage_cache_comparisons_passed']==200
- for name,digest in provenance['converted_sha256'].items():assert hashlib.sha256((a/name).read_bytes()).hexdigest()==digest
- rules=json.loads((a/'rules.json').read_text());assert rules['PlayerSpeed']==5 and rules['ShieldCost']==200 and rules['ShieldDuration']==30
- assert len(rules['LevelsTargets'].split())==20 and len(rules['UpgradeFreezeCost'].split())==9
- sheet=Image.open(a/'sprites.png');sprites=json.loads((a/'sprites.json').read_text());assert len(sprites)==706
- assert sum(s['name'].startswith('0_Char_')for s in sprites)==29
- for s in sprites:assert s['x']+s['w']<=sheet.width and s['y']+s['h']<=sheet.height
- paths=[ROOT/'src'/n for n in ['assets.c','data.c','sprite-ids.h']];before=[p.read_bytes()for p in paths];subprocess.run([sys.executable,str(ROOT/'tools/assets.py')],check=True);assert before==[p.read_bytes()for p in paths]
- print('PASS: all 200 stages and 517 arcade sections match the original tile hashes; 16 masks, 706 sprites, reproducible packing')
-if __name__=='__main__':main()
diff --git a/tests/test_games.py b/tests/test_games.py
index 71fa2cc9..8c397437 100644
--- a/tests/test_games.py
+++ b/tests/test_games.py
@@ -241,6 +241,11 @@ GAMES = {
# the copy, the next level for 100 coins
"monkeymart": ("MonkeyMart.nwa", "monkeymart.sav", presses((1500, "ok"), (2500, "ok"), (3200, "ok"), (3900, "back")),
5000, presses((1500, "ok"), (2500, "ok"), (3200, "ok"), (3900, "back")), 5000),
+ # the title, Arcade, the guide (the first time), then the climb: two dashes, paused (that saves); Home keeps the
+ # run. Next time, from the copy, Arcade starts at once: a dash, paused, quit with On/Off
+ "tombofthemask": ("TombOfTheMask.nwa", "tombofthemask.sav",
+ presses((1500, "ok"), (2500, "ok"), (3200, "up"), (3800, "left"), (4400, "back")), 5500,
+ presses((1500, "ok"), (2500, "up"), (3200, "back")), 4500),
# a level, its message, then play; then back to the level select
"portal": ("PortalReturns.nwa", "portal.sav",
presses((1500, "ok"), (2500, "ok"), (3500, "ok")) + every(4000, 7000, 400, "right", 300), 8000,
@@ -305,7 +310,8 @@ COPIES = {"championisland": "champion_saves.py", "numblocks": "numblocks_saves.p
"hillclimb": "hillclimb_saves.py", "pvz": "pvz_saves.py", "sonic": "sonic_saves.py",
"cookieclicker": "cookieclicker_saves.py", "leveldevil": "leveldevil_saves.py",
"jetpackjoyride": "jetpackjoyride_saves.py", "stickmanhook": "stickmanhook_saves.py",
- "donkeykong": "donkeykong_saves.py", "dune": "dune_saves.py", "monkeymart": "monkeymart_saves.py"}
+ "donkeykong": "donkeykong_saves.py", "dune": "dune_saves.py", "monkeymart": "monkeymart_saves.py",
+ "tombofthemask": "tombofthemask_saves.py"}
def dk_frames(v):
@@ -446,6 +452,10 @@ CHECKS = {
# for 100 coins
"monkeymart": (lambda v: len(v) == 364 and v[:4] == b"MMMT" and v[287] == 2 and struct.unpack_from("<I", v, 8)[0] >= 500,
lambda v: len(v) == 364 and v[:4] == b"MMMT" and v[287] == 3 and struct.unpack_from("<I", v, 8)[0] >= 400),
+ # "TOTM", version 1, its size (296): the guide read (guide at 288) and the arcade played once (the mission's
+ # progress at 268); after the reinstall, from the copy, twice
+ "tombofthemask": (lambda v: len(v) == 296 and v[:4] == b"TOTM" and v[288] & 1 and struct.unpack_from("<I", v, 268)[0] == 1,
+ lambda v: len(v) == 296 and v[:4] == b"TOTM" and struct.unpack_from("<I", v, 268)[0] == 2),
"breakout": (lambda v: len(v) == 12 and v[:2] == b"B\2" and v[4] == 1 and struct.unpack_from("<I", v, 8)[0] >= 10,
lambda v: v[4] == 0 and struct.unpack_from("<I", v, 8)[0] >= 1), # best kept, shake off
# Air Hockey and the easy computer chosen; then the normal computer and Tanks, the tallies kept
diff --git a/tools/release.py b/tools/release.py
index 33273eab..f054f180 100644
--- a/tools/release.py
+++ b/tools/release.py
@@ -26,7 +26,6 @@ REPO = "https://github.com/Mason363/NumPlay"
EXTRAS = set()
# games too big to fit next to NumPlay on the calculator: only on their own, in a section of their own
ALONE = {
- "tombofthemask": ("Tomb of the Mask", "dash through 200 original stages or climb in arcade mode, with 16 masks; adapted by Bobydeluxe"),
"celeste": ("Celeste", "the whole climb up Celeste Mountain"),
"hollowknight": ("Hollow Knight", "from King's Pass to Hornet in Greenpath"),
"undertale": ("Undertale", "the whole Underground, to the barrier and the neutral ending"),
@@ -48,6 +47,7 @@ ALONE = {
"donkeykong": ("Donkey Kong", "the 1981 arcade game: barrels, pies, elevators and rivets, up to Pauline"),
"dune": ("Dune", "roll down the dunes and fly over the line, with the shop's 26 balls and 7 landscapes"),
"monkeymart": ("Monkey Mart", "run a grocery mart as a monkey, both marts: crops, animals, machines and workers"),
+ "tombofthemask": ("Tomb of the Mask", "dash through the tomb: the endless arcade climb and all 200 stages, with the 16 masks"),
}
VARIANTS = [
("NumPlay-Invisible.nwa", "The same app, hidden: a blank icon with no name"),