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.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
Among Us: the Skeld to walk in, with its light, doors, rooms and bots
Mason363a1bf723ae498
diff --git a/games/amongus/.gitignore b/games/amongus/.gitignorenew file mode 100644index 00000000..342d9dda--- /dev/null+++ b/games/amongus/.gitignore@@ -0,0 +1,2 @@+output/+build/diff --git a/games/amongus/Makefile b/games/amongus/Makefilenew file mode 100644index 00000000..a8d5e14d--- /dev/null+++ b/games/amongus/Makefile@@ -0,0 +1,84 @@+# Among Us on the NumWorks calculator (C).+# make output/amongus.nwa+# make check link it like the calculator does (output/amongus.bin): RAM and the app space+# make host build/play: the game on a computer, for tests and screenshots+# make test the game played on a computer (tests/check.py, with the sanitizers)+# make data src/data.bin, src/data.h and src/world.h from the art taken out of the game+# (REF=that folder, Python + Pillow + NumPy)+Q ?= @+# the ARM toolchain on the PATH, or in TOOLCHAIN=<its bin folder>+TOOLCHAIN ?=+BIN = $(if $(TOOLCHAIN),$(TOOLCHAIN)/)+CC = $(BIN)arm-none-eabi-gcc+NWLINK ?= npx --yes -- [email protected]+STRIP ?= $(BIN)arm-none-eabi-strip --strip-unneeded+SIZE = $(BIN)arm-none-eabi-size+BUILD_DIR = output+REF ?=++# the drawing runs every frame at -O2; the rest is small at -Os+HOT = src/gfx.c src/view.c src/ship.c+COLD = $(filter-out $(HOT) src/plat_host.c src/plat_eadk.c,$(wildcard src/*.c))+COLD_OBJ = $(patsubst src/%.c,$(BUILD_DIR)/cold/%.o,$(COLD))+HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h ../common/np_lz.h++CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1 -DDATA_BIN='"src/data.bin"'+CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant+CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal+CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)+LDFLAGS = -Wl,--relocatable -nostartfiles --specs=nano.specs+LDFLAGS += -Wl,-e,main -Wl,-u,eadk_app_name -Wl,-u,eadk_app_icon -Wl,-u,eadk_api_level+LDFLAGS += -Wl,--gc-sections -flinker-output=nolto-rel++.PHONY: build check clean host test data+build: $(BUILD_DIR)/amongus.nwa++# apps get 133652 bytes of RAM on custom builds of Epsilon 25.2 (148928 or more on official ones); installed on its+# own, the app must fit the calculator's space for apps (0x90200000 to 0x903F0000 in its flash)+RAM_LENGTH = 133652+APP_SPACE = 2031616+check: $(BUILD_DIR)/amongus.nwa+ $(Q) $(NWLINK) nwa-bin --ram-length $(RAM_LENGTH) $< $(BUILD_DIR)/amongus.bin+ @n=$$(wc -c < $(BUILD_DIR)/amongus.bin); \+ echo "BIN $(BUILD_DIR)/amongus.bin: $$n bytes, $$(( $(APP_SPACE) - n )) to spare of the app space"; \+ [ $$n -le $(APP_SPACE) ] || { echo "amongus.nwa is bigger than the calculator's app space ($(APP_SPACE) bytes)"; exit 1; }++$(BUILD_DIR)/data.o: src/data.S src/data.bin | $(BUILD_DIR)+ $(Q) $(CC) -c -DDATA_BIN='"src/data.bin"' $< -o $@++$(BUILD_DIR)/cold/%.o: src/%.c $(HEADERS)+ @mkdir -p $(@D)+ $(Q) $(CC) $(CFLAGS) -Os -c $< -o $@++$(BUILD_DIR)/amongus.nwa: $(HOT) src/plat_eadk.c $(COLD_OBJ) $(HEADERS) $(BUILD_DIR)/icon.o $(BUILD_DIR)/data.o+ @echo "LD $@"+ $(Q) $(CC) $(CFLAGS) $(LDFLAGS) $(HOT) src/plat_eadk.c $(COLD_OBJ) $(BUILD_DIR)/data.o $(BUILD_DIR)/icon.o -lm -o $@+ $(Q) $(STRIP) $@+ $(Q) $(SIZE) $@++$(BUILD_DIR)/icon.o: src/icon.png | $(BUILD_DIR)+ @echo "ICON $<"+ $(Q) $(NWLINK) png-icon-o $< $@++$(BUILD_DIR):+ $(Q) mkdir -p $@++# on a computer: tests/play.c plays it with scripted keys and saves screenshots+HOST_FLAGS = -std=gnu11 -O1 -g -Wall -Wextra -Wno-unused-parameter -Isrc -DHOST -DDATA_BIN='"src/data.bin"'+HOST_SAN = -fsanitize=address,undefined -fno-sanitize-recover=undefined+HOST_SRC = $(filter-out src/plat_eadk.c src/main.c,$(wildcard src/*.c))+host: build/play+build/play: $(HOST_SRC) tests/play.c src/data.S src/data.bin $(HEADERS)+ $(Q) mkdir -p $(dir $@)+ $(Q) cc $(HOST_FLAGS) $(HOST_SAN) $(HOST_SRC) tests/play.c src/data.S -lm -o $@+ @echo "HOST $@"++test: build/play+ python3 tests/check.py build/play++data:+ @test -n "$(REF)" || { echo "make data REF=<the art taken out of the game>"; exit 1; }+ python3 -I tools/pack.py $(REF)++clean:+ $(Q) rm -rf $(BUILD_DIR) builddiff --git a/games/amongus/src/art.c b/games/amongus/src/art.cnew file mode 100644index 00000000..e98072f6--- /dev/null+++ b/games/amongus/src/art.c@@ -0,0 +1,137 @@+/* Among Us: the pictures of the screens around the round: stars, the title, players lined up, the meeting's+ * tablet and plates, the kill and report overlays, the ejection. */+#include <math.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include "game.h"+#include "gfx.h"+#include "view.h"++/* the starfield (StarGen): stars drifting by */+void art_stars(float t, float speed) {+ gfx_fill(0, gfx_y0, SCREEN_W, BAND, 0x0000, 256);+ for (int k = 0; k < 90; k++) {+ uint32_t h = (uint32_t)k * 2654435761u;+ h ^= h >> 15;+ int y = (int)(h % SCREEN_H);+ if (y < gfx_y0 || y >= gfx_y0 + BAND) continue;+ float sp = 8 + (h >> 9 & 31);+ int x = (int)fmodf((float)(h >> 3 & 511) + t * sp * speed * 10, 340) - 10;+ if (x < 0 || x >= SCREEN_W) continue;+ uint16_t c = (h >> 20 & 3) ? 0x8C71 : 0xFFFF;+ gfx_band[(y - gfx_y0) * SCREEN_W + x] = c;+ }+}++void art_player(int color, float x, float y, float scale, bool flip, int alpha) {+ const Pic *p = pic(PIC_IDLE);+ float s = scale;+ if (s == 1 && !flip) gfx_spr(p, (int)x, (int)y, false, color_pal[color], alpha);+ else gfx_pic(p, x, y, flip ? -s : s, s, 0, color_pal[color], alpha);+}++void art_title(void) {+ art_stars(g.screen_t, 1);+ gfx_text(FONT_HUGE, 160, 80, "AMONG US", 0xFFFF, 0x0000, 2, 1);+ for (int k = 0; k < 4; k++) art_player(k * 3 % N_COLORS, 70.0f + k * 60, 120, 1.2f, k & 1, 256);+}++/* the team in a row, the player in front (IntroCutscene, EndGameManager) */+void art_lineup(const uint8_t *who, int n, float t) {+ float grow = t < 0.4f ? t / 0.4f : 1;+ /* the light on the floor */+ for (int y = 150; y < 200; y++)+ if (y >= gfx_y0 && y < gfx_y0 + BAND) {+ float w = 140 * grow * (1 - (y - 150) / 80.0f);+ gfx_fill(160 - (int)w, y, (int)(2 * w), 1, 0x2945, 200);+ }+ for (int k = n - 1; k >= 0; k--) {+ int side = (k + 1) / 2 * ((k & 1) ? -1 : 1);+ float sc = 2.6f - 0.25f * (float)abs(side);+ float x = 160 + side * 34.0f * grow, y = 150 - (float)abs(side) * 6;+ art_player(g.p[who[k]].color, x, y, sc, side < 0, 256);+ }+}++/* ---- the meeting's tablet ---- */++void art_meeting_bg(void) {+ gfx_fill(0, gfx_y0, SCREEN_W, BAND, rgb565(0x1B2433), 256);+ gfx_fill(4, 4, 312, 222, rgb565(0x8EA4B8), 256);+ gfx_fill(7, 22, 306, 200, rgb565(0xC6D3DE), 256);+ gfx_text(FONT_BIG, 160, 18, "Who Is The Impostor?", 0xFFFF, 0x0000, 1, 1);+}++void art_plate(int x, int y, int i, bool sel, bool voted, bool dead) {+ const Player *P = &g.p[i];+ uint16_t bg = dead ? rgb565(0x6E7E8C) : rgb565(0xE6EEF4);+ gfx_fill(x, y, 146, 26, sel ? 0xFFE0 : rgb565(0x5A6B7A), 256);+ gfx_fill(x + 2, y + 2, 142, 22, bg, 256);+ art_player(P->color, (float)x + 16, (float)y + 13, 0.7f, false, dead ? 120 : 256);+ bool red = g.p[g.me].imp && P->imp;+ gfx_text(FONT_MID, x + 32, y + 17, COLOR_NAMES[P->color], red ? 0xF800 : 0x0000, 0, 0, 0);+ if (dead) gfx_line((float)x + 6, (float)y + 4, (float)x + 26, (float)y + 22, 3, 0xF800, 256),+ gfx_line((float)x + 26, (float)y + 4, (float)x + 6, (float)y + 22, 3, 0xF800, 256);+ if (voted) {+ gfx_fill(x + 96, y + 6, 44, 14, rgb565(0x2E7D32), 256);+ gfx_text(FONT_SMALL, x + 118, y + 16, "I Voted", 0xFFFF, 0, 0, 1);+ }+}++void art_vote_icon(int x, int y, int color, bool anon) {+ gfx_disc((float)x, (float)y, 5, 0x0000, 256);+ gfx_disc((float)x, (float)y, 4, anon ? rgb565(0x8C8C8C) : rgb565(BODY_COLORS[color]), 256);+}++void art_skip(int x, int y, bool sel) {+ gfx_fill(x, y, 90, 18, sel ? 0xFFE0 : rgb565(0x5A6B7A), 256);+ gfx_fill(x + 2, y + 2, 86, 14, rgb565(0xE6EEF4), 256);+ gfx_text(FONT_MID, x + 45, y + 14, "Skip Vote", 0x0000, 0, 0, 1);+}++/* ---- overlays ---- */++void art_kill(float t) {+ /* the killer over the victim on a red band */+ int h = t < 0.2f ? (int)(t / 0.2f * 60) : 60;+ gfx_fill(0, 120 - h, SCREEN_W, 2 * h, 0x0000, 256);+ gfx_fill(0, 120 - h + 6, SCREEN_W, 2 * h - 12, rgb565(0xB01010), 256);+ if (t > 0.2f) {+ art_player(g.p[g.killer].color, 120, 120, 2.4f, false, 256);+ gfx_pic(pic(PIC_DEAD), 200, 140, 2.4f, 2.4f, 0, color_pal[g.p[g.me].color], 256);+ }+}++void art_report(float t) {+ int h = t < 0.2f ? (int)(t / 0.2f * 50) : 50;+ gfx_fill(0, 120 - h, SCREEN_W, 2 * h, rgb565(0x1D2A3A), 240);+ if (t > 0.2f) {+ bool body = g.reported != NONE;+ gfx_text(FONT_HUGE, 160, 130, body ? "Dead Body Reported" : "Emergency Meeting", 0xFFFF, 0xF800, 2, 1);+ art_player(g.p[g.caller].color, 160, 90, 1.2f, false, 256);+ }+}++void art_eject(float t) {+ art_stars(t, 2);+ char b[64];+ int e = g.ejected;+ if (e != NONE) {+ float x = -30 + t * 60, ang = t * 2.2f;+ gfx_pic(pic(PIC_IDLE), x, 120, 1.4f, 1.4f, ang, color_pal[g.p[e].color], 256);+ }+ if (e == NONE) snprintf(b, sizeof b, "No one was ejected. (%s)", g.tie ? "Tie" : "Skipped");+ else if (!g.opt.confirm) snprintf(b, sizeof b, "%s was ejected.", COLOR_NAMES[g.p[e].color]);+ else snprintf(b, sizeof b, "%s was %sThe Impostor.", COLOR_NAMES[g.p[e].color], g.p[e].imp ? "" : "not ");+ int n = (int)((t - 0.6f) * 22);+ if (n < 0) n = 0;+ char shown[64];+ snprintf(shown, sizeof shown, "%.*s", n, b);+ gfx_text(FONT_BIG, 160, 120, shown, 0xFFFF, 0, 0, 1);+ if (g.opt.confirm && t > 3.5f) {+ int k = living(true);+ snprintf(b, sizeof b, "%d Impostor%s remain%s.", k, k == 1 ? "" : "s", k == 1 ? "s" : "");+ gfx_text(FONT_MID, 160, 142, b, 0xFFFF, 0, 0, 1);+ }+}diff --git a/games/amongus/src/bot.c b/games/amongus/src/bot.cnew file mode 100644index 00000000..decd99b7--- /dev/null+++ b/games/amongus/src/bot.c@@ -0,0 +1,859 @@+/* Among Us: the bots (the game has none: these play as people do). Crewmates walk the ship to their tasks and do+ * them, report the bodies they see and remember who they saw where; impostors fake tasks, kill when nobody else+ * would see, vent, sabotage and join fixes. They know only what they saw. */+#include <math.h>+#include <string.h>+#include "game.h"+#include "world.h"++enum { B_IDLE, B_WALK, B_TASK, B_FIX, B_HUNT, B_VENT, B_WAIT, B_REPORT, B_BUTTON };+/* what a walk is for */+enum { G_NONE, G_TASK, G_FAKE, G_FIX, G_BODY, G_BUTTON, G_WANDER, G_VENT, G_HUNT };++int kill_target(int i);+int console_use(int i, int c);+void walk(int i, V2 dir);++/* ---- the walking grid: Dijkstra from the goal, then down the distances ---- */++#define NCELLS (NAV_W * NAV_H)+static uint16_t ndist[NCELLS];+static uint16_t heap[NCELLS];+static int nheap;++static inline bool nav_ok(int x, int y) {+ return x >= 0 && y >= 0 && x < NAV_W && y < NAV_H && (NAV_BITS[y * ((NAV_W + 7) / 8) + (x >> 3)] >> (x & 7) & 1);+}+static inline V2 cell_pos(int c) {+ return (V2){NAV_X0 + (c % NAV_W + 0.5f) * NAV_CS, NAV_Y0 + (c / NAV_W + 0.5f) * NAV_CS};+}++static int nearest_cell(V2 p) {+ int cx = (int)floorf((p.x - NAV_X0) / NAV_CS), cy = (int)floorf((p.y - NAV_Y0) / NAV_CS);+ int best = -1;+ float bd = 1e9f;+ for (int r = 0; r <= 4 && best < 0; r++)+ for (int y = cy - r; y <= cy + r; y++)+ for (int x = cx - r; x <= cx + r; x++) {+ if (!nav_ok(x, y)) continue;+ V2 q = cell_pos(y * NAV_W + x);+ float d = (q.x - p.x) * (q.x - p.x) + (q.y - p.y) * (q.y - p.y);+ if (d < bd && (r > 2 || !ship_wall_between(p, q))) bd = d, best = y * NAV_W + x;+ }+ return best;+}++static void hpush(int c) {+ int i = nheap++;+ while (i > 0) {+ int p = (i - 1) / 2;+ if (ndist[heap[p]] <= ndist[c]) break;+ heap[i] = heap[p];+ i = p;+ }+ heap[i] = (uint16_t)c;+}+static int hpop(void) {+ int top = heap[0], last = heap[--nheap], i = 0;+ for (;;) {+ int ch = 2 * i + 1;+ if (ch >= nheap) break;+ if (ch + 1 < nheap && ndist[heap[ch + 1]] < ndist[heap[ch]]) ch++;+ if (ndist[heap[ch]] >= ndist[last]) break;+ heap[i] = heap[ch];+ i = ch;+ }+ if (nheap) heap[i] = (uint16_t)last;+ return top;+}++static bool door_blocks(V2 a, V2 b) {+ for (int d = 0; d < N_DOORS; d++) {+ if (!door_closed(d)) continue;+ const DoorRec *D = &DOORS[d];+ if (fabsf(a.x - D->x) > 2.5f || fabsf(a.y - D->y) > 2.5f) continue;+ for (int s = 0; s < 4; s++) {+ const Seg *S = &D->seg[s];+ float d1 = (S->x1 - S->x0) * (a.y - S->y0) - (S->y1 - S->y0) * (a.x - S->x0);+ float d2 = (S->x1 - S->x0) * (b.y - S->y0) - (S->y1 - S->y0) * (b.x - S->x0);+ if ((d1 > 0) == (d2 > 0)) continue;+ float d3 = (b.x - a.x) * (S->y0 - a.y) - (b.y - a.y) * (S->x0 - a.x);+ float d4 = (b.x - a.x) * (S->y1 - a.y) - (b.y - a.y) * (S->x1 - a.x);+ if ((d3 > 0) != (d4 > 0)) return true;+ }+ }+ return false;+}++static void dijkstra(int goal) {+ memset(ndist, 0xFF, sizeof ndist);+ nheap = 0;+ ndist[goal] = 0;+ hpush(goal);+ bool doors = false;+ for (int d = 0; d < N_DOORS; d++) doors |= door_closed(d);+ static const int8_t DX[8] = {1, -1, 0, 0, 1, 1, -1, -1}, DY[8] = {0, 0, 1, -1, 1, -1, 1, -1};+ while (nheap) {+ int c = hpop();+ int x = c % NAV_W, y = c / NAV_W;+ for (int k = 0; k < 8; k++) {+ int nx = x + DX[k], ny = y + DY[k];+ if (!nav_ok(nx, ny)) continue;+ if (k >= 4 && (!nav_ok(nx, y) || !nav_ok(x, ny))) continue;+ int n = ny * NAV_W + nx;+ uint16_t nd = (uint16_t)(ndist[c] + (k >= 4 ? 14 : 10));+ if (nd >= ndist[n]) continue;+ if (doors && door_blocks(cell_pos(c), cell_pos(n))) continue;+ ndist[n] = nd;+ hpush(n);+ }+ }+}++/* is the straight line from a to b walkable (every point on it in a walkable cell, no wall across) */+static bool straight(V2 a, V2 b) {+ float dx = b.x - a.x, dy = b.y - a.y, l = sqrtf(dx * dx + dy * dy);+ int n = (int)(l / 0.2f) + 1;+ for (int k = 1; k < n; k++) {+ float t = (float)k / n;+ int x = (int)floorf((a.x + dx * t - NAV_X0) / NAV_CS), y = (int)floorf((a.y + dy * t - NAV_Y0) / NAV_CS);+ if (!nav_ok(x, y)) return false;+ }+ return !ship_wall_between(a, b) && !door_blocks(a, b);+}++/* a path for bot i to goal (straight lines between corners of the grid's way) */+static bool plan(int i, V2 goal) {+ Player *P = &g.p[i];+ Bot *B = &P->bot;+ B->goal = goal;+ B->plen = B->pi = 0;+ if (!P->alive) return true; /* (ghosts fly straight) */+ int from = nearest_cell(P->pos), to = nearest_cell(goal);+ if (from < 0 || to < 0) return false;+ dijkstra(to);+ if (ndist[from] == 0xFFFF) return false;+ /* down the distances, keeping only the cells a straight walk can't skip */+ uint16_t cells[160];+ int n = 0, c = from;+ cells[n++] = (uint16_t)c;+ static const int8_t DX[8] = {1, -1, 0, 0, 1, 1, -1, -1}, DY[8] = {0, 0, 1, -1, 1, -1, 1, -1};+ while (c != to && n < 160) {+ int x = c % NAV_W, y = c / NAV_W, best = -1;+ for (int k = 0; k < 8; k++) {+ int nx = x + DX[k], ny = y + DY[k];+ if (!nav_ok(nx, ny)) continue;+ int m = ny * NAV_W + nx;+ if (ndist[m] < ndist[c] && (best < 0 || ndist[m] < ndist[best])) best = m;+ }+ if (best < 0) break;+ c = best;+ cells[n++] = (uint16_t)c;+ }+ V2 at = P->pos;+ int k = 0;+ while (k < n - 1 && B->plen < 40) {+ int far = k + 1;+ for (int j = n - 1; j > k + 1; j--)+ if (straight(at, cell_pos(cells[j]))) {+ far = j;+ break;+ }+ B->path[B->plen++] = cells[far];+ at = cell_pos(cells[far]);+ k = far;+ }+ return true;+}++/* ---- perception ---- */++static float dist2(V2 a, V2 b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); }++/* would anyone (but the impostors and the victim) see a kill at p */+static bool witnessed(int imp, int victim, V2 p) {+ for (int j = 0; j < g.nplayers; j++) {+ const Player *Q = &g.p[j];+ if (j == imp || j == victim || !Q->alive || Q->imp || Q->vent != NONE) continue;+ float r = vision_radius(j) + 0.5f;+ if (dist2(Q->pos, p) < r * r && !ship_light_between(Q->pos, p)) return true;+ }+ return false;+}++static void suspect(Bot *B, int who, int by) {+ int v = B->sus[who] + by;+ B->sus[who] = (int8_t)(v > 100 ? 100 : v < -100 ? -100 : v);+}++/* what bot i sees now */+void bot_see(int i) {+ Player *P = &g.p[i];+ Bot *B = &P->bot;+ if (!P->alive) return;+ for (int j = 0; j < g.nplayers; j++) {+ if (j == i) continue;+ Player *Q = &g.p[j];+ bool seen = Q->alive && can_see(i, j);+ if (seen) {+ B->seen_t[j] = g.t;+ B->seen_room[j] = Q->room;+ B->with_t[j] += 0.2f;+ if (B->with_t[j] > 60) B->with_t[j] = 60;+ /* a visual task proves a crewmate */+ if (g.opt.visual && Q->busy && !Q->imp && (Q->bot.task < MAX_TASKS) &&+ TASK_DEFS[Q->tasks[Q->bot.task].def].type == T_SUBMIT_SCAN)+ B->sus[j] = -100, B->scanned = (uint8_t)j;+ if (j == g.me && Q->vent_anim) {+ B->saw_vent = (uint8_t)j, B->saw_vent_room = Q->room;+ suspect(B, j, 100);+ }+ } else if (B->with_t[j] > 0) B->with_t[j] -= 0.05f;+ }+ if (P->imp) return;+ /* bodies */+ for (int b = 0; b < MAXP; b++) {+ const Body *D = &g.bodies[b];+ if (!D->on) continue;+ float r = vision_radius(i);+ if (dist2(P->pos, D->pos) > r * r || ship_light_between(P->pos, D->pos)) continue;+ if (B->state == B_REPORT && B->found_body == b) continue;+ B->found_body = (uint8_t)b;+ B->body_room = (uint8_t)ship_room_at(D->pos);+ /* who was near it */+ B->near_body = NONE;+ float bd = 4.0f * 4.0f;+ for (int j = 0; j < g.nplayers; j++) {+ if (j == i || !g.p[j].alive || g.p[j].vent != NONE) continue;+ float d = dist2(g.p[j].pos, D->pos);+ if (d < bd && can_see(i, j)) bd = d, B->near_body = (uint8_t)j;+ }+ if (B->near_body != NONE) suspect(B, B->near_body, 40);+ B->state = B_REPORT;+ B->target = (uint8_t)b;+ plan(i, D->pos);+ }+}++/* a kill seen as it happens (called by kill_player for each living bot) */+static void saw_kill_check(int i, int killer) {+ Bot *B = &g.p[i].bot;+ if (g.p[i].imp) return;+ if (can_see(i, killer)) {+ B->saw_kill = (uint8_t)killer;+ B->saw_kill_room = g.p[killer].room;+ suspect(B, killer, 100);+ }+}++/* ---- deciding ---- */++static float task_time(const Task *t) {+ switch (TASK_DEFS[t->def].type) {+ case T_SWIPE_CARD: return 3.5f;+ case T_FIX_WIRING: return 4;+ case T_CLEAR_ASTEROIDS: return 16;+ case T_ALIGN_ENGINE: return 3;+ case T_SUBMIT_SCAN: return 10;+ case T_INSPECT_SAMPLE: return 2.5f;+ case T_FUEL_ENGINES: return 3.5f;+ case T_START_REACTOR: return 14;+ case T_EMPTY_CHUTE:+ case T_EMPTY_GARBAGE: return 3.5f;+ case T_UPLOAD_DATA: return 9;+ case T_CALIBRATE: return 6;+ case T_CHART_COURSE: return 4;+ case T_CLEAN_O2: return 6;+ case T_UNLOCK_MANIFOLDS: return 6;+ case T_STABILIZE: return 2.5f;+ case T_PRIME_SHIELDS: return 3;+ case T_DIVERT_POWER: return t->step ? 1.5f : 3;+ default: return 3;+ }+}++static void go(int i, V2 to, int why, int cons) {+ Bot *B = &g.p[i].bot;+ if (!plan(i, to)) {+ B->state = B_WAIT;+ B->t = 1 + rnd_f();+ return;+ }+ B->state = B_WALK;+ B->target = (uint8_t)why;+ B->cons = (uint8_t)cons;+ B->stuck_t = 0;+ B->last = g.p[i].pos;+}++static V2 stand(int c) { return (V2){CONSOLES[c].sx, CONSOLES[c].sy}; }++/* the nearest console of an unfinished task step; its task in *task */+static int next_task(int i, int *task) {+ Player *P = &g.p[i];+ int best = -1;+ float bd = 1e9f;+ for (int k = 0; k < P->ntasks; k++) {+ Task *t = &P->tasks[k];+ if (task_done(t) || t->timer > 0) continue;+ for (int c = 0; c < N_CONSOLES; c++) {+ if (!console_serves(c, t)) continue;+ float d = dist2(P->pos, stand(c));+ if (d < bd) bd = d, best = c, *task = k;+ }+ }+ return best;+}++static int fix_console(int i, int sab, int nth) {+ /* the sabotage's consoles: reactor and oxygen have two */+ int found = 0, last = -1;+ for (int c = 0; c < N_CONSOLES; c++) {+ const ConsoleRec *C = &CONSOLES[c];+ if (C->kind) continue;+ int t = sab == SAB_REACTOR ? T_RESET_REACTOR : sab == SAB_O2 ? T_RESTORE_O2 : sab == SAB_LIGHTS ? T_FIX_LIGHTS+ : T_FIX_COMMS;+ if (!(C->types >> t & 1)) continue;+ if (found == nth) return c;+ found++, last = c;+ }+ (void)i;+ return last;+}++/* how many bots already go to fix console c */+static int fixers(int c, int except) {+ int n = 0;+ for (int j = 0; j < g.nplayers; j++)+ if (j != except && j != g.me && g.p[j].alive && g.p[j].bot.cons == c &&+ (g.p[j].bot.state == B_FIX || (g.p[j].bot.state == B_WALK && g.p[j].bot.target == G_FIX)))+ n++;+ return n;+}++static bool want_fix(int i) {+ Player *P = &g.p[i];+ if (!g.sab || !P->alive) return false;+ if (P->bot.state == B_FIX || (P->bot.state == B_WALK && P->bot.target == G_FIX)) return false;+ if (P->bot.state == B_REPORT) return false;+ /* the closest ones go: two to each of the critical sabotages, one or two to the others */+ int need = (g.sab == SAB_REACTOR || g.sab == SAB_O2) ? 2 : 1;+ for (int k = 0; k < need; k++) {+ int c = fix_console(i, g.sab, k);+ if (c < 0) continue;+ if (fixers(c, i) >= 1) continue;+ /* am I among the closest of those free */+ float my = dist2(P->pos, stand(c));+ int closer = 0;+ for (int j = 0; j < g.nplayers; j++)+ if (j != i && j != g.me && g.p[j].alive && (!g.p[j].imp || g.p[j].bot.with == 1) && dist2(g.p[j].pos, stand(c)) < my)+ closer++;+ if (closer < 2 || (P->imp && rnd_n(4) == 0)) {+ go(i, stand(c), G_FIX, c);+ return true;+ }+ }+ return false;+}++static void wander(int i) {+ /* somewhere else on the ship: a console's spot */+ int c = rnd_n(N_CONSOLES);+ go(i, stand(c), G_WANDER, c);+}++static void decide(int i) {+ Player *P = &g.p[i];+ Bot *B = &P->bot;+ if (want_fix(i)) return;+ if (!P->imp) {+ int t = -1, c = next_task(i, &t);+ if (c >= 0) {+ go(i, stand(c), G_TASK, c);+ B->task = (uint8_t)t;+ return;+ }+ /* all done (or waiting on a sample): call a meeting on a strong suspicion, else walk around */+ if (P->alive && P->emergencies && g.emergency_cd <= 0 && !g.sab) {+ for (int j = 0; j < g.nplayers; j++)+ if (g.p[j].alive && B->sus[j] >= 80 && rnd_n(3) == 0) {+ go(i, stand(N_CONSOLES - 1 >= 0 ? 0 : 0), G_BUTTON, 0);+ for (int c2 = 0; c2 < N_CONSOLES; c2++)+ if (CONSOLES[c2].kind == 2) go(i, stand(c2), G_BUTTON, c2);+ return;+ }+ }+ wander(i);+ return;+ }+ /* an impostor */+ if (!P->alive) {+ if (sabotage_ready() && rnd_n(4) == 0) sabotage(SAB_LIGHTS + rnd_n(2));+ wander(i);+ return;+ }+ if (P->kill_cd < 6 && rnd_n(3)) {+ /* someone alone */+ int best = -1;+ float bs = -1e9f;+ for (int j = 0; j < g.nplayers; j++) {+ const Player *Q = &g.p[j];+ if (!Q->alive || Q->imp) continue;+ int company = 0;+ for (int k = 0; k < g.nplayers; k++)+ if (k != j && g.p[k].alive && !g.p[k].imp && dist2(g.p[k].pos, Q->pos) < 16) company++;+ float s = -company * 10 - sqrtf(dist2(P->pos, Q->pos)) + rnd_f() * 4;+ if (s > bs) bs = s, best = j;+ }+ if (best >= 0) {+ B->state = B_HUNT;+ B->task = (uint8_t)best;+ B->t = 0;+ B->think = 0;+ return;+ }+ }+ /* a task to fake: the console of one of its (fake) tasks, or any */+ int t = -1, c = next_task(i, &t);+ if (c < 0 || rnd_n(3) == 0) c = rnd_n(N_CONSOLES);+ go(i, stand(c), G_FAKE, c);+}++/* ---- each tick ---- */++static void follow(int i) {+ Player *P = &g.p[i];+ Bot *B = &P->bot;+ V2 to = B->pi < B->plen ? cell_pos(B->path[B->pi]) : B->goal;+ if (!P->alive) to = B->goal;+ float dx = to.x - P->pos.x, dy = to.y - P->pos.y, d = sqrtf(dx * dx + dy * dy);+ float step = player_speed(i) * DT;+ if (d < step * 1.5f) {+ if (P->alive && B->pi < B->plen) {+ B->pi++;+ walk(i, (V2){dx, dy});+ return;+ }+ /* there */+ walk(i, (V2){0, 0});+ P->pos = ship_move(P->pos, (V2){to.x - P->pos.x, to.y - P->pos.y}, PLAYER_R);+ B->state = B_IDLE;+ B->plen = 0;+ return;+ }+ walk(i, (V2){dx, dy});+ /* stuck against something: plan again */+ B->stuck_t += DT;+ if (B->stuck_t > 1.0f) {+ if (dist2(P->pos, B->last) < 0.3f * 0.3f) {+ if (!plan(i, B->goal)) B->state = B_IDLE;+ }+ B->stuck_t = 0;+ B->last = P->pos;+ }+}++static void arrive(int i) {+ Player *P = &g.p[i];+ Bot *B = &P->bot;+ int why = B->target;+ switch (why) {+ case G_TASK: {+ Task *t = &P->tasks[B->task];+ if (!console_serves(B->cons, t)) {+ B->state = B_IDLE;+ return;+ }+ B->state = B_TASK;+ B->t = task_time(t) * (0.8f + 0.5f * rnd_f());+ P->busy = 1;+ return;+ }+ case G_FAKE:+ B->state = B_TASK;+ B->task = NONE;+ B->t = 2 + rnd_f() * 6;+ return;+ case G_FIX:+ if (!g.sab) {+ B->state = B_IDLE;+ return;+ }+ B->state = B_FIX;+ B->t = g.sab == SAB_REACTOR ? 99 : g.sab == SAB_O2 ? 4 + rnd_f() * 2 : g.sab == SAB_LIGHTS ? 3 + rnd_f() * 2+ : 4 + rnd_f() * 3;+ return;+ case G_BUTTON:+ if (P->alive && P->emergencies && g.emergency_cd <= 0 && !g.sab && g.screen == S_PLAY) {+ start_meeting(i, NONE);+ return;+ }+ B->state = B_IDLE;+ return;+ case G_WANDER:+ B->state = B_WAIT;+ B->t = 1 + rnd_f() * 4;+ return;+ default:+ B->state = B_IDLE;+ return;+ }+}++static void impostor_tick(int i) {+ Player *P = &g.p[i];+ Bot *B = &P->bot;+ /* kill whoever is in reach when nobody would see */+ if (P->kill_cd <= 0 && P->vent == NONE) {+ int t = kill_target(i);+ if (t >= 0 && !witnessed(i, t, g.p[t].pos) && !witnessed(i, t, P->pos) && rnd_n(4) == 0) {+ kill_player(i, t);+ for (int j = 0; j < g.nplayers; j++)+ if (j != i && g.p[j].alive && j != g.me) saw_kill_check(j, i);+ /* away from the body: a vent close by, else somewhere else */+ int v = nearest_vent(P->pos, 3.5f);+ if (v >= 0 && rnd_n(3)) {+ go(i, (V2){VENTS[v].sx, VENTS[v].sy}, G_VENT, v);+ } else if (rnd_n(8) == 0 && g.screen == S_PLAY) {+ start_meeting(i, t); /* a self report */+ } else+ wander(i);+ return;+ }+ }+ /* sabotage now and then */+ if (sabotage_ready() && P->alive && rnd_n(30 * 25) == 0) {+ int r = rnd_n(100);+ sabotage(r < 35 ? SAB_LIGHTS : r < 55 ? SAB_COMMS : r < 80 ? SAB_REACTOR : SAB_O2);+ }+ if (rnd_n(30 * 40) == 0) {+ static const uint8_t DR[] = {R_CAFETERIA, R_STORAGE, R_ELECTRICAL, R_MEDBAY, R_SECURITY, R_UPPER_ENGINE,+ R_LOWER_ENGINE};+ int r = B->state == B_HUNT ? g.p[B->task].room : DR[rnd_n(7)];+ for (unsigned k = 0; k < sizeof DR; k++)+ if (DR[k] == r) close_doors(r);+ }+}++void bot_init(int i) {+ Bot *B = &g.p[i].bot;+ memset(B, 0, sizeof *B);+ B->state = B_WAIT;+ B->t = 0.5f + rnd_f() * 1.5f;+ B->saw_kill = B->saw_vent = B->near_body = B->found_body = NONE;+ B->task = NONE;+ B->with = NONE;+ B->scanned = NONE;+ B->think = rnd_f() * 0.2f;+}++void bot_tick(int i) {+ Player *P = &g.p[i];+ Bot *B = &P->bot;+ if (P->vent_anim) {+ walk(i, (V2){0, 0});+ return;+ }+ /* look around five times a second */+ B->think -= DT;+ if (B->think <= 0) {+ B->think += 0.2f;+ bot_see(i);+ if (g.screen != S_PLAY) return;+ }+ if (P->imp && P->alive) {+ impostor_tick(i);+ if (g.screen != S_PLAY) return;+ }+ if (!P->imp && P->alive && B->state != B_FIX && B->state != B_REPORT && g.sab) {+ if (rnd_n(30) == 0 && want_fix(i)) return;+ }+ if (P->imp && P->alive && g.sab && rnd_n(200) == 0 && B->state != B_HUNT && B->state != B_VENT) want_fix(i);+ switch (B->state) {+ case B_IDLE:+ walk(i, (V2){0, 0});+ P->busy = 0;+ decide(i);+ break;+ case B_WAIT:+ walk(i, (V2){0, 0});+ B->t -= DT;+ if (B->t <= 0) B->state = B_IDLE;+ break;+ case B_WALK:+ follow(i);+ if (B->state == B_IDLE) {+ if (B->target == G_VENT && P->imp && P->alive) {+ int v = B->cons;+ enter_vent(i, v);+ B->state = B_VENT;+ B->t = 1 + rnd_f() * 2;+ B->plen = (uint8_t)rnd_n(3);+ } else+ arrive(i);+ }+ break;+ case B_REPORT: {+ const Body *D = &g.bodies[B->target];+ if (!D->on) {+ B->state = B_IDLE;+ break;+ }+ if (dist2(P->pos, D->pos) < 2.5f * 2.5f && !ship_wall_between(P->pos, D->pos)) {+ walk(i, (V2){0, 0});+ start_meeting(i, D->who);+ return;+ }+ follow(i);+ if (B->state == B_IDLE) B->state = B_REPORT, plan(i, D->pos);+ break;+ }+ case B_TASK:+ walk(i, (V2){0, 0});+ B->t -= DT;+ if (B->t <= 0) {+ P->busy = 0;+ if (B->task < MAX_TASKS) {+ Task *t = &P->tasks[B->task];+ int type = TASK_DEFS[t->def].type;+ if (type == T_INSPECT_SAMPLE && t->timer < 0) t->timer = 60;+ else if (type == T_CLEAR_ASTEROIDS) {+ while (!task_done(t)) task_step_done(i, B->task);+ } else+ task_step_done(i, B->task);+ }+ B->state = B_IDLE;+ }+ break;+ case B_FIX: {+ walk(i, (V2){0, 0});+ const ConsoleRec *C = &CONSOLES[B->cons];+ if (!g.sab) {+ B->state = B_IDLE;+ break;+ }+ if (g.sab == SAB_REACTOR) {+ g.reactor_hold[C->id & 1] = (uint8_t)i;+ break;+ }+ B->t -= DT;+ if (B->t <= 0) {+ if (g.sab == SAB_O2) g.o2_done |= (uint8_t)(C->room == R_ADMIN ? 1 : 2);+ else if (g.sab == SAB_LIGHTS) g.switches = 0x1F;+ else if (g.sab == SAB_COMMS) fix_sabotage();+ B->state = B_IDLE;+ }+ break;+ }+ case B_HUNT: {+ const Player *Q = &g.p[B->task];+ if (!Q->alive || P->kill_cd > 8) {+ B->state = B_IDLE;+ break;+ }+ B->think -= 0;+ B->t -= DT;+ if (B->t <= 0 || B->pi >= B->plen) {+ B->t = 0.7f;+ if (!plan(i, Q->pos)) {+ B->state = B_IDLE;+ break;+ }+ }+ if (dist2(P->pos, Q->pos) < 0.8f * 0.8f) walk(i, (V2){0, 0});+ else {+ follow(i);+ if (B->state == B_IDLE) B->state = B_HUNT;+ }+ break;+ }+ case B_VENT:+ walk(i, (V2){0, 0});+ B->t -= DT;+ if (B->t <= 0 && P->vent != NONE) {+ if (B->plen) {+ /* to a linked vent */+ int links[3], n = 0;+ for (int k = 0; k < 3; k++)+ if (VENTS[P->vent].link[k] >= 0) links[n++] = VENTS[P->vent].link[k];+ if (n) move_vent(i, links[rnd_n(n)]);+ B->plen--;+ B->t = 0.6f + rnd_f();+ } else {+ /* out when nobody would see */+ if (!witnessed(i, NONE, P->pos) || B->t < -6) {+ exit_vent(i);+ B->state = B_WAIT;+ B->t = 0.6f;+ }+ }+ }+ break;+ default:+ B->state = B_IDLE;+ }+}++/* ---- meetings ---- */++enum {+ L_BODY_IN, L_NEAR_BODY, L_SAW_KILL, L_SAW_VENT, L_WAS_IN, L_WITH, L_SUS, L_WHO, L_WHERE, L_SKIP, L_NOT_ME,+ L_SCANNED, L_BUTTON+};++static void say(int who, int kind, int a, int b) {+ if (g.nlines >= 32) {+ memmove(g.lines, g.lines + 1, sizeof g.lines[0] * 31);+ g.nlines--;+ if (g.line_shown) g.line_shown--;+ }+ g.lines[g.nlines++] = (Line){(uint8_t)who, (uint8_t)kind, (uint8_t)a, (uint8_t)b};+}++/* each bot's lines for this meeting, said one after another in bot_meeting_tick */+static uint8_t queue_who[48], queue_kind[48], queue_a[48], queue_b[48];+static float queue_at[48];+static int nqueue, qnext;++static void queue(int who, int kind, int a, int b, float at) {+ if (nqueue >= 48) return;+ queue_who[nqueue] = (uint8_t)who, queue_kind[nqueue] = (uint8_t)kind, queue_a[nqueue] = (uint8_t)a;+ queue_b[nqueue] = (uint8_t)b, queue_at[nqueue] = at;+ nqueue++;+}++static int top_suspect(int i, int *score) {+ const Bot *B = &g.p[i].bot;+ int best = -1, bs = -1000;+ for (int j = 0; j < g.nplayers; j++) {+ if (j == i || !g.p[j].alive) continue;+ if (g.p[i].imp && g.p[j].imp) continue;+ if (B->sus[j] > bs) bs = B->sus[j], best = j;+ }+ *score = bs;+ return best;+}++void bot_meeting_start(void) {+ nqueue = qnext = 0;+ g.nlines = 0;+ g.line_shown = 0;+ float at = 1.5f;+ /* the caller first */+ int c = g.caller;+ if (c != g.me) {+ Bot *B = &g.p[c].bot;+ if (g.reported != NONE) {+ queue(c, L_BODY_IN, g.reported, g.p[c].imp ? g.p[c].room : B->body_room, at), at += 1.6f;+ if (!g.p[c].imp && B->saw_kill != NONE && g.p[B->saw_kill].alive)+ queue(c, L_SAW_KILL, B->saw_kill, B->saw_kill_room, at), at += 1.6f;+ else if (!g.p[c].imp && B->near_body != NONE && g.p[B->near_body].alive)+ queue(c, L_NEAR_BODY, B->near_body, B->body_room, at), at += 1.6f;+ else if (g.p[c].imp) {+ /* a lie: whoever it last saw */+ int best = -1;+ float bt = -1;+ for (int j = 0; j < g.nplayers; j++)+ if (j != c && g.p[j].alive && !g.p[j].imp && B->seen_t[j] > bt) bt = B->seen_t[j], best = j;+ if (best >= 0 && rnd_n(2)) queue(c, L_NEAR_BODY, best, g.p[c].room, at), at += 1.6f;+ }+ } else {+ int s, w = top_suspect(c, &s);+ if (w >= 0 && s >= 40) queue(c, B->saw_vent == w ? L_SAW_VENT : L_SUS, w, B->saw_vent_room, at), at += 1.6f;+ else queue(c, L_BUTTON, 0, 0, at), at += 1.6f;+ }+ }+ /* the others, in a random order */+ int order[MAXP], n = 0;+ for (int i = 0; i < g.nplayers; i++)+ if (i != g.me && i != c && g.p[i].alive) order[n++] = i;+ for (int k = n - 1; k > 0; k--) {+ int j = rnd_n(k + 1), t = order[k];+ order[k] = order[j], order[j] = t;+ }+ for (int k = 0; k < n; k++) {+ int i = order[k];+ Bot *B = &g.p[i].bot;+ at += 0.6f + rnd_f() * 1.6f;+ if (!g.p[i].imp && B->saw_kill != NONE && g.p[B->saw_kill].alive) {+ queue(i, L_SAW_KILL, B->saw_kill, B->saw_kill_room, at);+ continue;+ }+ if (!g.p[i].imp && B->saw_vent != NONE && g.p[B->saw_vent].alive) {+ queue(i, L_SAW_VENT, B->saw_vent, B->saw_vent_room, at);+ continue;+ }+ int r = rnd_n(10);+ if (!g.p[i].imp && B->scanned != NONE && g.p[B->scanned].alive && r < 3) {+ queue(i, L_SCANNED, B->scanned, 0, at);+ continue;+ }+ if (r < 2) {+ queue(i, g.reported != NONE ? L_WHERE : L_WHO, g.reported, 0, at);+ continue;+ }+ /* an alibi: where it was, with whom (impostors make one up) */+ int with = NONE;+ float wt = 8;+ for (int j = 0; j < g.nplayers; j++)+ if (j != i && g.p[j].alive && B->with_t[j] > wt) wt = B->with_t[j], with = j;+ int room = g.p[i].room;+ if (g.p[i].imp && rnd_n(2)) room = TASK_DEFS[g.p[i].tasks[rnd_n(g.p[i].ntasks)].def].room;+ if (with != NONE && !g.p[i].imp) queue(i, L_WITH, with, room, at);+ else queue(i, L_WAS_IN, room, 0, at);+ int s, w = top_suspect(i, &s);+ if (w >= 0 && (s >= 30 || (g.p[i].imp && rnd_n(3) == 0))) at += 1.2f, queue(i, L_SUS, w, g.p[w].room, at);+ }+}++void bot_meeting_tick(void) {+ while (qnext < nqueue && g.meet_t >= queue_at[qnext]) {+ int who = queue_who[qnext];+ if (g.p[who].alive) say(who, queue_kind[qnext], queue_a[qnext], queue_b[qnext]);+ /* what's said moves the listeners: an accusation weighs by how much the speaker is trusted */+ int k = queue_kind[qnext], a = queue_a[qnext];+ if (k == L_SAW_KILL || k == L_SAW_VENT || k == L_SUS || k == L_NEAR_BODY) {+ for (int i = 0; i < g.nplayers; i++) {+ if (i == who || i == g.me || !g.p[i].alive || g.p[i].imp) continue;+ Bot *B = &g.p[i].bot;+ if (i == a) {+ suspect(B, who, 25); /* being accused */+ continue;+ }+ int trust = B->sus[who] < -30 ? 2 : B->sus[who] > 40 ? 0 : 1;+ int w = (k == L_SAW_KILL ? 45 : k == L_SAW_VENT ? 40 : k == L_NEAR_BODY ? 20 : 12) * trust;+ suspect(B, a, w);+ }+ }+ if (k == L_SCANNED)+ for (int i = 0; i < g.nplayers; i++)+ if (i != g.me && !g.p[i].imp && g.p[i].bot.sus[who] < 30) suspect(&g.p[i].bot, a, -40);+ qnext++;+ }+}++/* the bots' votes (each at its own moment in the voting time) */+void bot_votes(void) {+ for (int i = 0; i < g.nplayers; i++) {+ if (i == g.me || !g.p[i].alive || g.votes[i] != NONE) continue;+ if (g.meet_stage != 1) continue;+ /* decide after a few seconds of voting, or soon after everyone spoke */+ float when = 2.0f + (float)((i * 37 + g.nlines * 11) % 9);+ if (g.meet_t < when) continue;+ Bot *B = &g.p[i].bot;+ int s, w = top_suspect(i, &s);+ if (g.p[i].imp) {+ /* with the crowd against a crewmate, or skip */+ int counts[MAXP + 1] = {0};+ for (int j = 0; j < g.nplayers; j++)+ if (g.votes[j] != NONE) counts[g.votes[j]]++;+ int best = SKIP, bc = 0;+ for (int j = 0; j < g.nplayers; j++)+ if (!g.p[j].imp && g.p[j].alive && counts[j] > bc) bc = counts[j], best = j;+ g.votes[i] = (uint8_t)(bc ? best : (w >= 0 && s > 10 && rnd_n(2)) ? w : SKIP);+ } else {+ g.votes[i] = (uint8_t)(w >= 0 && s >= 35 ? w : SKIP);+ }+ (void)B;+ }+}diff --git a/games/amongus/src/data.S b/games/amongus/src/data.Snew file mode 100644index 00000000..6bd1364d--- /dev/null+++ b/games/amongus/src/data.S@@ -0,0 +1,19 @@+/* data.bin (tools/pack.py) in the app's read-only data */+#ifdef __APPLE__+ .const_data+ .p2align 2+ .globl _au_data+_au_data:+ .incbin DATA_BIN+ .p2align 2+#else+ .section .rodata.au_data,"a"+ .balign 4+ .global au_data+au_data:+ .incbin DATA_BIN+ .balign 4+#endif+#ifdef __ELF__+ .section .note.GNU-stack,"",%progbits+#endifdiff --git a/games/amongus/src/data.bin b/games/amongus/src/data.binnew file mode 100644index 00000000..6fdd6da2Binary files /dev/null and b/games/amongus/src/data.bin differdiff --git a/games/amongus/src/data.h b/games/amongus/src/data.hnew file mode 100644index 00000000..e6e69d37--- /dev/null+++ b/games/amongus/src/data.h@@ -0,0 +1,27 @@+/* Among Us: what's in data.bin (made by tools/pack.py) */+#ifndef AU_DATA_H+#define AU_DATA_H+#define N_PICS 145+#define N_FONTS 4+#define BLOB_SHIP 149+#define BLOB_MIX 150+#define N_MIX 256+enum { FONT_SMALL, FONT_MID, FONT_BIG, FONT_HUGE };+#define SHIP_OX 1117+#define SHIP_OY 274+#define PIC_IDLE 100+#define PIC_WALK 101+#define PIC_GHOST 113+#define N_GHOST 24+#define PIC_DEAD 137+#define PIC_JUMP 138+#define PIC_DOOR_SIDE 58+#define PIC_DOOR_FRONT 70+#define DOOR_CLOSE_FRAMES 4+#define DOOR_OPEN_FRAMES 8+#define PIC_VENT 82+#define N_VENT_FRAMES 18+typedef struct { uint16_t pic; int16_t x, y; float z; } FrontRec;+#define N_FRONT 58+static const FrontRec FRONT[58] = {{0, 1946, 1403, 4.45048e-07f}, {1, 1968, 1474, 4.45048e-07f}, {2, 1950, 1423, 1.01725e-06f}, {3, 1396, 763, 1.40841e-06f}, {4, 1555, 763, 1.40841e-06f}, {5, 1279, 828, -3.88f}, {6, 1432, 946, -0.00820028f}, {7, 1559, 948, -0.00832028f}, {8, 1389, 947, -0.00832028f}, {9, 1454, 946, -0.1282f}, {10, 1153, 754, -1.6f}, {11, 2599, 617, -0.00520021f}, {12, 2543, 519, -0.00292054f}, {13, 2410, 531, -3.88f}, {14, 2523, 752, -0.0060402f}, {15, 2545, 617, -0.00472013f}, {16, 2512, 543, -0.00352021f}, {17, 1868, 50, 0.00187957f}, {18, 1716, 234, 0.00031986f}, {19, 1959, 156, -0.28f}, {20, 1665, 29, -3.64f}, {21, 1746, 1138, -0.52f}, {22, 1711, 1312, -0.0136004f}, {23, 1960, 1127, -0.0107205f}, {24, 1940, 1293, -0.52f}, {25, 2170, 561, -1.6f}, {26, 347, 986, -0.0100005f}, {27, 317, 1051, -0.0101205f}, {28, 398, 845, -1.6f}, {29, -683, 509, -4.0012f}, {30, -737, 571, -0.4012f}, {31, 868, 1220, -0.0126404f}, {32, 1037, 1190, -0.0246404f}, {33, 1040, 1137, -0.0366404f}, {34, 881, 1374, -0.0126524f}, {35, -373, 1123, -0.0112006f}, {36, -360, 1261, -0.0113206f}, {37, -189, 1053, -4.012f}, {38, -189, 1271, -4.012f}, {39, -330, 1134, -4.012f}, {40, -427, 1272, -0.0113206f}, {41, -300, 1247, -0.0113206f}, {42, -188, 1133, -0.0110806f}, {43, 537, 95, -1.48f}, {44, -313, 613, -1.6f}, {45, -375, 147, 0.000799815f}, {46, -362, 285, 0.000679815f}, {47, -191, 78, -4.0f}, {48, -191, 295, -4.0f}, {49, -332, 158, -4.0f}, {50, -429, 296, 0.000679815f}, {51, -302, 271, 0.000679815f}, {52, -190, 157, 0.000919815f}, {53, 1398, 1596, -0.0172001f}, {54, 1409, 1624, -0.0292001f}, {55, 1332, 1428, -4.12f}, {56, 1606, 1526, -0.0162406f}, {57, 1248, 1526, -0.01624f}};+#endifdiff --git a/games/amongus/src/game.c b/games/amongus/src/game.cnew file mode 100644index 00000000..4d3e30fb--- /dev/null+++ b/games/amongus/src/game.c@@ -0,0 +1,647 @@+/* Among Us: the rules (see game.h). Numbers from the game (2021.3.31): PlayerPhysics, PlayerControl, ShipStatus,+ * GameOptionsData; see gamesrc/amongus/spec/rules.md. */+#include <math.h>+#include <string.h>+#include "game.h"+#include "gfx.h"+#include "plat.h"+#include "world.h"++Game g;+bool autopilot; /* (tests: the bots' brain plays the player too) */+uint16_t color_pal[N_COLORS][256];++const uint32_t BODY_COLORS[N_COLORS] = {0xC61111, 0x132ED1, 0x117F2D, 0xED54BA, 0xEF7D0D, 0xF5F557,+ 0x3F474E, 0xD6E0F0, 0x6B2FBB, 0x71491E, 0x38FEDC, 0x50EF39};+const uint32_t SHADOW_COLORS[N_COLORS] = {0x7A0838, 0x09158E, 0x0A4D2E, 0xAB2BAD, 0xB33E15, 0xC38823,+ 0x1E1F26, 0x8394BF, 0x3B177C, 0x5E2615, 0x24A8BE, 0x15A742};+const char *const COLOR_NAMES[N_COLORS] = {"Red", "Blue", "Green", "Pink", "Orange", "Yellow",+ "Black", "White", "Purple", "Brown", "Cyan", "Lime"};+#define VISOR 0x95CADC++/* ShipStatus' CommonTasks, LongTasks, NormalTasks */+const TaskDef TASK_DEFS[] = {+ {T_SWIPE_CARD, R_ADMIN, 1, 0, 0, "Swipe Card"},+ {T_FIX_WIRING, R_ELECTRICAL, 3, 0, 0, "Fix Wiring"},+ {T_CLEAR_ASTEROIDS, R_WEAPONS, 20, 1, 0, "Clear Asteroids"},+ {T_ALIGN_ENGINE, R_UPPER_ENGINE, 2, 1, 0, "Align Engine Output"},+ {T_SUBMIT_SCAN, R_MEDBAY, 1, 1, 0, "Submit Scan"},+ {T_INSPECT_SAMPLE, R_MEDBAY, 1, 1, 0, "Inspect Sample"},+ {T_FUEL_ENGINES, R_STORAGE, 4, 1, 0, "Fuel Engines"},+ {T_START_REACTOR, R_REACTOR, 5, 1, 0, "Start Reactor"},+ {T_EMPTY_CHUTE, R_O2, 2, 1, 0, "Empty Chute"},+ {T_EMPTY_GARBAGE, R_CAFETERIA, 2, 1, 0, "Empty Garbage"},+ {T_UPLOAD_DATA, R_COMMS, 2, 2, 0, "Upload Data"},+ {T_CALIBRATE, R_ELECTRICAL, 1, 2, 0, "Calibrate Distributor"},+ {T_CHART_COURSE, R_NAV, 1, 2, 0, "Chart Course"},+ {T_CLEAN_O2, R_O2, 1, 2, 0, "Clean O2 Filter"},+ {T_UNLOCK_MANIFOLDS, R_REACTOR, 1, 2, 0, "Unlock Manifolds"},+ {T_UPLOAD_DATA, R_ELECTRICAL, 2, 2, 0, "Upload Data"},+ {T_STABILIZE, R_NAV, 1, 2, 0, "Stabilize Steering"},+ {T_UPLOAD_DATA, R_WEAPONS, 2, 2, 0, "Upload Data"},+ {T_PRIME_SHIELDS, R_SHIELDS, 1, 2, 0, "Prime Shields"},+ {T_UPLOAD_DATA, R_CAFETERIA, 2, 2, 0, "Upload Data"},+ {T_UPLOAD_DATA, R_NAV, 2, 2, 0, "Upload Data"},+ {T_DIVERT_POWER, R_ELECTRICAL, 2, 2, R_SHIELDS, "Divert Power to Shields"},+ {T_DIVERT_POWER, R_ELECTRICAL, 2, 2, R_WEAPONS, "Divert Power to Weapons"},+ {T_DIVERT_POWER, R_ELECTRICAL, 2, 2, R_COMMS, "Divert Power to Communications"},+ {T_DIVERT_POWER, R_ELECTRICAL, 2, 2, R_UPPER_ENGINE, "Divert Power to Upper Engine"},+ {T_DIVERT_POWER, R_ELECTRICAL, 2, 2, R_O2, "Divert Power to O2"},+ {T_DIVERT_POWER, R_ELECTRICAL, 2, 2, R_NAV, "Divert Power to Navigation"},+ {T_DIVERT_POWER, R_ELECTRICAL, 2, 2, R_LOWER_ENGINE, "Divert Power to Lower Engine"},+ {T_DIVERT_POWER, R_ELECTRICAL, 2, 2, R_SECURITY, "Divert Power to Security"},+};+const int N_TASK_DEFS = sizeof TASK_DEFS / sizeof TASK_DEFS[0];++uint32_t rnd(void) {+ uint32_t x = g.rng ? g.rng : 0x9E3779B9u;+ x ^= x << 13, x ^= x >> 17, x ^= x << 5;+ g.rng = x;+ return x;+}+float rnd_f(void) { return (float)(rnd() >> 8) / 16777216.0f; }++/* ---- the rules' numbers ---- */++float player_speed(int i) {+ const Player *P = &g.p[i];+ return (P->alive ? 2.5f : 3.0f) * g.opt.speed * 0.25f;+}++float vision_radius(int i) {+ const Player *P = &g.p[i];+ if (!P->alive) return 30;+ if (P->imp) return 5.0f * g.opt.imp_vision * 0.25f;+ return (1.0f + 4.0f * g.light) * g.opt.crew_vision * 0.25f;+}++float kill_distance(void) {+ static const float D[3] = {1.0f, 1.8f, 2.5f};+ return D[g.opt.kill_dist % 3];+}+float kill_cooldown(void) { return g.opt.kill_cd * 0.5f; }++/* ---- tasks ---- */++int task_steps(const Task *t) { return TASK_DEFS[t->def].steps; }+bool task_done(const Task *t) { return t->step >= task_steps(t); }++const char *task_name(const Task *t) {+ const TaskDef *d = &TASK_DEFS[t->def];+ if (d->type == T_UPLOAD_DATA && t->step == 0) return "Download Data";+ if (d->type == T_DIVERT_POWER && t->step == 1) return "Accept Diverted Power";+ return d->name;+}++/* does console c serve task t at its current step */+bool console_serves(int c, const Task *t) {+ const ConsoleRec *C = &CONSOLES[c];+ const TaskDef *d = &TASK_DEFS[t->def];+ if (C->kind != 0 || task_done(t)) return false;+ int s = t->step;+ switch (d->type) {+ case T_FIX_WIRING:+ return (C->types >> T_FIX_WIRING & 1) && C->id == t->data[s];+ case T_ALIGN_ENGINE:+ return (C->types >> T_ALIGN_ENGINE & 1) && C->id == s;+ case T_UPLOAD_DATA:+ if (s == 0) return C->room == d->room && C->valid[0].type == T_UPLOAD_DATA;+ return C->room == R_ADMIN && (C->types >> T_UPLOAD_DATA & 1);+ case T_DIVERT_POWER:+ if (s == 0) return C->types >> T_DIVERT_POWER & 1;+ return C->room == d->target && C->valid[0].type == T_DIVERT_POWER;+ default:+ if (C->types >> d->type & 1) return true;+ for (int k = 0; k < 2; k++)+ if (C->valid[k].type == d->type && s >= C->valid[k].lo && s <= C->valid[k].hi) return true;+ return false;+ }+}++int task_console(const Player *P, const Task *t) {+ (void)P;+ for (int c = 0; c < N_CONSOLES; c++)+ if (console_serves(c, t)) return c;+ return -1;+}++int task_room(const Task *t) {+ int c = task_console(0, t);+ return c >= 0 ? CONSOLES[c].room : TASK_DEFS[t->def].room;+}++void task_step_done(int pl, int ti) {+ Task *t = &g.p[pl].tasks[ti];+ if (task_done(t)) return;+ t->step++;+ if (task_done(t)) {+ if (g.opt.taskbar == 0) g.task_bar = tasks_progress();+ check_win();+ }+}++float tasks_progress(void) {+ int all = 0, done = 0;+ for (int i = 0; i < g.nplayers; i++) {+ if (g.p[i].imp) continue;+ for (int k = 0; k < g.p[i].ntasks; k++) {+ all++;+ done += task_done(&g.p[i].tasks[k]);+ }+ }+ return all ? (float)done / all : 0;+}++/* ShipStatus.Begin: the same common tasks for everyone, then long and short ones, at most one of each type */+static void give_tasks(void) {+ uint8_t common[2];+ int nc = g.opt.common > 2 ? 2 : g.opt.common;+ int order[2] = {0, 1};+ if (rnd() & 1) order[0] = 1, order[1] = 0;+ for (int k = 0; k < nc; k++) common[k] = (uint8_t)order[k];+ uint8_t wires[3];+ {+ /* three of the six wiring panels, in their order */+ uint8_t ids[6] = {0, 1, 2, 3, 4, 5};+ for (int k = 5; k > 0; k--) {+ int j = rnd_n(k + 1);+ uint8_t t = ids[k];+ ids[k] = ids[j], ids[j] = t;+ }+ for (int k = 0; k < 3; k++) wires[k] = ids[k];+ for (int a = 0; a < 3; a++)+ for (int b = a + 1; b < 3; b++)+ if (wires[b] < wires[a]) {+ uint8_t t = wires[a];+ wires[a] = wires[b], wires[b] = t;+ }+ }+ for (int i = 0; i < g.nplayers; i++) {+ Player *P = &g.p[i];+ P->ntasks = 0;+ uint32_t used = 0;+ for (int k = 0; k < nc; k++) {+ Task *t = &P->tasks[P->ntasks++];+ memset(t, 0, sizeof *t);+ t->def = common[k];+ memcpy(t->data, wires, 3);+ used |= 1u << TASK_DEFS[t->def].type;+ }+ for (int kind = 1; kind <= 2; kind++) {+ int want = kind == 1 ? g.opt.longt : g.opt.shortt;+ for (int n = 0; n < want && P->ntasks < MAX_TASKS; n++) {+ int cands[32], nca = 0;+ for (int d = 0; d < N_TASK_DEFS; d++)+ if (TASK_DEFS[d].kind == kind && !(used >> TASK_DEFS[d].type & 1)) cands[nca++] = d;+ if (!nca) break;+ int d = cands[rnd_n(nca)];+ Task *t = &P->tasks[P->ntasks++];+ memset(t, 0, sizeof *t);+ t->def = (uint8_t)d;+ used |= 1u << TASK_DEFS[d].type;+ if (TASK_DEFS[d].type == T_INSPECT_SAMPLE) t->timer = -1;+ }+ }+ }+}++/* ---- the game ---- */++static void spawn_circle(void) {+ /* ShipStatus.SpawnPlayer: on a circle of SpawnRadius around the spawn centre, in player order */+ int n = g.nplayers;+ for (int i = 0; i < n; i++) {+ Player *P = &g.p[i];+ float a = 6.2831853f * i / n - 1.5707963f;+ P->pos = (V2){-0.72f + cosf(a) * 1.6f, 0.62f + sinf(a) * 1.6f - FEET_Y};+ P->vel = (V2){0, 0};+ P->vent = NONE;+ P->vent_anim = 0;+ P->busy = 0;+ P->flip = cosf(a) > 0;+ }+}++void game_new(void) {+ Options *o = &g.opt;+ uint32_t seed = g.rng ^ (plat_millis() * 2654435761u) ^ 0x5bd1e995u;+ Options keep = *o;+ memset(&g, 0, sizeof g);+ g.opt = keep;+ g.rng = seed ? seed : 1;+ g.nplayers = (uint8_t)(1 + o->bots);+ if (g.nplayers < 4) g.nplayers = 4;+ if (g.nplayers > MAXP) g.nplayers = MAXP;+ /* colours: the player's, then the others in the game's order */+ int c = 0;+ for (int i = 0; i < g.nplayers; i++) {+ Player *P = &g.p[i];+ memset(P, 0, sizeof *P);+ if (i == 0) P->color = g.opt.color % N_COLORS;+ else {+ while (c == g.opt.color % N_COLORS) c++;+ P->color = (uint8_t)c++;+ }+ P->alive = 1;+ P->emergencies = g.opt.meetings;+ P->kill_cd = 10; /* the first round's */+ }+ /* impostors: the lobby's count, limited as the game does by the number of players */+ int nimp = g.opt.impostors;+ int maxi = g.nplayers <= 6 ? 1 : g.nplayers <= 8 ? 2 : 3;+ if (nimp > maxi) nimp = maxi;+ if (nimp < 1) nimp = 1;+ int role = g.opt.role;+ if (role == 2) g.p[0].imp = 1, nimp--;+ for (int k = 0; k < nimp; k++) {+ int i;+ do i = rnd_n(g.nplayers);+ while (g.p[i].imp || (i == 0 && role != 0));+ g.p[i].imp = 1;+ }+ give_tasks();+ spawn_circle();+ for (int i = 0; i < 16; i++) g.vent_t[i] = -10;+ g.me = 0;+ g.light = 1;+ g.switches = 0x1F;+ g.sab_cd = 10;+ g.emergency_cd = g.opt.meet_cd;+ g.task_bar = 0;+ g.ejected = NONE;+ g.killer = NONE;+ for (int i = 0; i < g.nplayers; i++) bot_init(i);+ g.cam = g.p[0].pos;+ g.screen = S_INTRO;+ g.screen_t = 0;+}++int living(bool imp) {+ int n = 0;+ for (int i = 0; i < g.nplayers; i++) n += g.p[i].alive && g.p[i].imp == imp;+ return n;+}++static void end_game(int winner, int reason) {+ if (g.screen == S_END) return;+ g.winner = (uint8_t)winner;+ g.end_reason = (uint8_t)reason;+ g.screen = S_END;+ g.screen_t = 0;+ g.overlay = O_NONE;+}++/* reasons: 0 by vote, 1 by kills, 2 tasks, 3 sabotage */+void check_win(void) {+ if (g.screen == S_END || g.screen == S_TITLE || g.screen == S_LOBBY) return;+ int imp = living(true), crew = living(false);+ if (imp == 0) end_game(0, 0);+ else if (imp >= crew) end_game(1, 1);+ else if (tasks_progress() >= 1) end_game(0, 2);+}++/* PhysicsHelpers.AnythingBetween with the ship and its objects */+bool can_see(int a, int b) {+ const Player *A = &g.p[a], *B = &g.p[b];+ if (B->vent != NONE) return false;+ float dx = A->pos.x - B->pos.x, dy = A->pos.y - B->pos.y, r = vision_radius(a);+ if (dx * dx + dy * dy > r * r) return false;+ return !ship_light_between(A->pos, B->pos);+}++void kill_player(int killer, int victim) {+ Player *K = &g.p[killer], *V = &g.p[victim];+ if (!V->alive) return;+ V->alive = 0;+ V->busy = 0;+ for (int b = 0; b < MAXP; b++)+ if (!g.bodies[b].on) {+ g.bodies[b] = (Body){V->pos, (uint8_t)victim, 1, {0, 0}};+ break;+ }+ /* the killer lands where the victim stood */+ K->flip = V->pos.x < K->pos.x;+ K->pos = V->pos;+ K->kill_cd = kill_cooldown();+ if (victim == g.me) {+ g.screen = S_KILLED;+ g.screen_t = 0;+ g.killer = (uint8_t)killer;+ g.kill_anim = (uint8_t)rnd_n(4);+ g.overlay = O_NONE;+ }+ for (int i = 0; i < g.nplayers; i++)+ if (g.p[i].alive && i != killer && i != g.me) bot_see(i);+ check_win();+}++void start_meeting(int caller, int body) {+ if (g.screen == S_END) return;+ g.caller = (uint8_t)caller;+ g.reported = (uint8_t)body; /* the dead player's number, or NONE for the button */+ if (body == NONE) g.p[caller].emergencies--;+ g.screen = S_REPORT;+ g.screen_t = 0;+ g.overlay = O_NONE;+ /* a meeting ends the critical sabotages */+ if (g.sab == SAB_REACTOR || g.sab == SAB_O2) {+ g.sab = SAB_NONE;+ g.sab_cd = 30;+ }+ for (int i = 0; i < g.nplayers; i++) {+ Player *P = &g.p[i];+ if (P->vent != NONE) P->vent = NONE, P->vent_anim = 0;+ P->busy = 0;+ }+}++/* ---- sabotage (SabotageSystemType, ReactorSystemType, LifeSuppSystemType, SwitchSystem, HudOverrideSystemType,+ * DoorsSystemType) ---- */++bool sabotage_ready(void) { return g.sab == SAB_NONE && g.sab_cd <= 0; }++void sabotage(int kind) {+ if (!sabotage_ready()) return;+ g.sab = (uint8_t)kind;+ g.sab_t = 30; /* the Skeld's meltdown and oxygen: 30 seconds */+ g.o2_done = 0;+ g.reactor_hold[0] = g.reactor_hold[1] = NONE;+ if (kind == SAB_O2) {+ g.o2_code = 0;+ for (int k = 0; k < 5; k++) g.o2_code = g.o2_code * 10 + (uint32_t)rnd_n(10);+ }+ if (kind == SAB_LIGHTS) {+ /* some switches flipped, at least one */+ uint8_t s;+ do s = (uint8_t)(rnd() & 0x1F);+ while (s == 0x1F);+ g.switches = s;+ }+ g.sab_fixing = 0;+}++void fix_sabotage(void) {+ g.sab = SAB_NONE;+ g.sab_cd = 30;+ g.switches = 0x1F;+}++void close_doors(int room) {+ if (g.door_cd[room] > 0) return;+ for (int d = 0; d < N_DOORS; d++)+ if (DOORS[d].room == room) {+ g.door_t[d] = 10;+ g.door_anim[d] = 0;+ }+ g.door_cd[room] = 30;+}++bool door_closed(int d) { return g.door_t[d] > 0; }++/* ---- vents (Vent.UsableDistance 0.75) ---- */++int nearest_vent(V2 p, float maxd) {+ int best = -1;+ float bd = maxd * maxd;+ for (int v = 0; v < N_VENTS; v++) {+ float dx = VENTS[v].x - p.x, dy = VENTS[v].y - p.y, d = dx * dx + dy * dy;+ if (d <= bd && !ship_wall_between(p, (V2){VENTS[v].x, VENTS[v].y})) bd = d, best = v;+ }+ return best;+}++void enter_vent(int i, int v) {+ Player *P = &g.p[i];+ P->vent = (uint8_t)v;+ P->vent_anim = 1;+ P->anim_t = 0;+ P->pos = (V2){VENTS[v].x, VENTS[v].y + 0.05f};+ g.vent_t[v] = g.t;+}++void exit_vent(int i) {+ Player *P = &g.p[i];+ if (P->vent == NONE) return;+ g.vent_t[P->vent] = g.t;+ P->vent_anim = 2;+ P->anim_t = 0;+}++void move_vent(int i, int v) {+ Player *P = &g.p[i];+ P->vent = (uint8_t)v;+ P->pos = (V2){VENTS[v].x, VENTS[v].y + 0.05f};+}++/* ---- saves: "AUSG" and a version, then the whole game; settings and wins in their own file ---- */++#define SAVE_GAME "amongus.sav"+#define SAVE_SET "amongus.set"+#define MAGIC_G 0x47535541u+#define MAGIC_S 0x53535541u+#define VERSION 1++typedef struct {+ uint32_t magic;+ uint16_t version, pad;+ uint32_t size;+} SaveHead;++#include "../../common/np_lz.h"+#define COPY_NAME "amongus_saves.py"++/* a copy of both files in a Python script: installing apps from the NumWorks website keeps only scripts */+static const char copy_head[] = "# Among Us' saves: keep this file\n";+static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";++static uint8_t *b64_put(uint8_t *p, const uint8_t *d, uint32_t len) {+ for (uint32_t i = 0; i < len; i += 3, p += 4) {+ uint32_t left = len - i, v = (uint32_t)d[i] << 16 | (left > 1 ? d[i + 1] << 8 : 0) | (left > 2 ? d[i + 2] : 0);+ p[0] = (uint8_t)b64[v >> 18 & 63];+ p[1] = (uint8_t)b64[v >> 12 & 63];+ p[2] = left > 1 ? (uint8_t)b64[v >> 6 & 63] : '=';+ p[3] = left > 2 ? (uint8_t)b64[v & 63] : '=';+ }+ return p;+}++static int b64_value(uint8_t c) {+ for (int i = 0; i < 64; i++)+ if ((uint8_t)b64[i] == c) return i;+ return -1;+}++/* the line "#>name:..." of the copy, decoded into out; its length or -1 */+static int32_t copy_get(const char *name, uint8_t *out, uint32_t cap) {+ uint32_t n, nl = (uint32_t)strlen(name);+ const uint8_t *c = plat_load(COPY_NAME, &n), *l = NULL;+ if (!c) return -1;+ for (uint32_t i = 0; i + nl + 3 <= n && !l; i++)+ if (c[i] == '#' && c[i + 1] == '>' && !memcmp(c + i + 2, name, nl) && c[i + 2 + nl] == ':') l = c + i + 3 + nl;+ if (!l) return -1;+ uint32_t len = 0;+ while (l + len < c + n && l[len] != '\n' && l[len]) len++;+ if (len % 4) return -1;+ uint32_t o = 0;+ for (uint32_t i = 0; i < len; i += 4) {+ int v0 = b64_value(l[i]), v1 = b64_value(l[i + 1]);+ int pad = (l[i + 2] == '=') + (l[i + 3] == '=');+ int v2 = l[i + 2] == '=' ? 0 : b64_value(l[i + 2]), v3 = l[i + 3] == '=' ? 0 : b64_value(l[i + 3]);+ if (v0 < 0 || v1 < 0 || v2 < 0 || v3 < 0) return -1;+ uint32_t w = (uint32_t)(v0 << 18 | v1 << 12 | v2 << 6 | v3);+ for (int k = 0; k < 3 - pad; k++) {+ if (o >= cap) return -1;+ out[o++] = (uint8_t)(w >> (16 - 8 * k));+ }+ }+ return (int32_t)o;+}++/* packed game: the head, then the game LZ-packed */+static uint8_t packed[sizeof(Game) + sizeof(Game) / 8 + 64];++static uint32_t pack_game(void) {+ static uint16_t table[NP_LZ_HASH];+ SaveHead h = {MAGIC_G, VERSION, 0, sizeof(Game)};+ memcpy(packed, &h, sizeof h);+ return sizeof h + np_lz_pack((const uint8_t *)&g, sizeof(Game), packed + sizeof h, table);+}++typedef struct {+ SaveHead h;+ Options opt;+ uint16_t wins_crew, wins_imp, games, pad;+} SetFile;++static void write_copy(uint32_t glen, const SetFile *s) {+ static uint8_t o[1 + sizeof copy_head + 64 + (sizeof packed + 2) / 3 * 4 + (sizeof(SetFile) + 2) / 3 * 4];+ uint8_t *p = o;+ *p++ = 0;+ memcpy(p, copy_head, sizeof copy_head - 1), p += sizeof copy_head - 1;+ memcpy(p, "#>" SAVE_SET ":", 2 + sizeof SAVE_SET), p += 2 + sizeof SAVE_SET;+ p = b64_put(p, (const uint8_t *)s, sizeof *s);+ *p++ = '\n';+ if (glen) {+ memcpy(p, "#>" SAVE_GAME ":", 2 + sizeof SAVE_GAME), p += 2 + sizeof SAVE_GAME;+ p = b64_put(p, packed, glen);+ *p++ = '\n';+ }+ *p++ = 0;+ plat_save(COPY_NAME, o, (uint32_t)(p - o));+}++SetFile set_file;++static void settings_defaults(void) {+ Options *o = &g.opt;+ o->bots = 7, o->impostors = 1, o->role = 0, o->color = 0;+ o->kill_cd = 90, o->kill_dist = 1;+ o->crew_vision = 4, o->imp_vision = 6, o->speed = 4;+ o->common = 1, o->longt = 1, o->shortt = 2;+ o->meetings = 1, o->meet_cd = 15, o->discuss = 15, o->vote = 120 / 5;+ o->confirm = 1, o->anon = 0, o->visual = 1, o->taskbar = 0;+}++static bool options_ok(const Options *o) {+ return o->bots >= 3 && o->bots <= 9 && o->impostors >= 1 && o->impostors <= 3 && o->role <= 2 && o->color < N_COLORS &&+ o->kill_cd >= 20 && o->kill_cd <= 120 && o->kill_dist <= 2 && o->crew_vision >= 1 && o->crew_vision <= 20 &&+ o->imp_vision >= 1 && o->imp_vision <= 20 && o->speed >= 2 && o->speed <= 12 && o->common <= 2 &&+ o->longt <= 3 && o->shortt <= 5 && o->meetings <= 9 && o->meet_cd <= 60 && o->discuss <= 120 &&+ o->vote <= 60 && o->confirm <= 1 && o->anon <= 1 && o->visual <= 1 && o->taskbar <= 2;+}++void settings_save(void) {+ set_file.h = (SaveHead){MAGIC_S, VERSION, 0, sizeof(SetFile)};+ set_file.opt = g.opt;+ plat_save(SAVE_SET, &set_file, sizeof set_file);+ bool live = g.screen != S_TITLE && g.screen != S_LOBBY && g.screen != S_END && g.screen != S_HOWTO;+ write_copy(live ? pack_game() : 0, &set_file);+}++static void settings_load(void) {+ settings_defaults();+ memset(&set_file, 0, sizeof set_file);+ uint32_t n;+ SetFile s;+ const uint8_t *d = plat_load(SAVE_SET, &n);+ if (d && n == sizeof s) memcpy(&s, d, sizeof s);+ else if (copy_get(SAVE_SET, (uint8_t *)&s, sizeof s) != (int32_t)sizeof s) return;+ if (s.h.magic != MAGIC_S || s.h.version != VERSION || s.h.size != sizeof(SetFile) || !options_ok(&s.opt)) return;+ set_file = s;+ g.opt = s.opt;+}++bool game_save(void) {+ uint32_t len = pack_game();+ bool ok = plat_save(SAVE_GAME, packed, len);+ set_file.h = (SaveHead){MAGIC_S, VERSION, 0, sizeof(SetFile)};+ set_file.opt = g.opt;+ plat_save(SAVE_SET, &set_file, sizeof set_file);+ write_copy(len, &set_file);+ return ok;+}++static bool game_sane(const Game *G) {+ if (G->nplayers < 4 || G->nplayers > MAXP || G->screen > S_KILLED || G->overlay > O_EMERGENCY || G->me >= MAXP ||+ !options_ok(&G->opt) || G->sab > SAB_COMMS || G->nlines > 32)+ return false;+ for (int i = 0; i < G->nplayers; i++) {+ const Player *P = &G->p[i];+ if (P->color >= N_COLORS || P->ntasks > MAX_TASKS || (P->vent != NONE && P->vent >= N_VENTS) || P->bot.plen > 40 ||+ P->bot.pi > 40 || !isfinite(P->pos.x) || !isfinite(P->pos.y) || fabsf(P->pos.x) > 40 || fabsf(P->pos.y) > 40)+ return false;+ for (int k = 0; k < P->ntasks; k++) {+ const Task *t = &P->tasks[k];+ if (t->def >= N_TASK_DEFS || t->step > TASK_DEFS[t->def].steps) return false;+ for (int j = 0; j < 3; j++)+ if (t->data[j] > 5) return false;+ }+ for (int k = 0; k < P->bot.plen; k++)+ if (P->bot.path[k] >= NAV_W * NAV_H) return false;+ }+ for (int l = 0; l < G->nlines; l++)+ if (G->lines[l].who >= MAXP) return false;+ return true;+}++bool game_load(void) {+ uint32_t n;+ const uint8_t *d = plat_load(SAVE_GAME, &n);+ static uint8_t buf[sizeof packed];+ if (d && n <= sizeof buf) memcpy(buf, d, n);+ else {+ int32_t m = copy_get(SAVE_GAME, buf, sizeof buf);+ if (m < 0) return false;+ n = (uint32_t)m;+ }+ SaveHead h;+ if (n < sizeof h) return false;+ memcpy(&h, buf, sizeof h);+ if (h.magic != MAGIC_G || h.version != VERSION || h.size != sizeof(Game)) return false;+ static Game tmp;+ if (np_lz_unpack(buf + sizeof h, n - sizeof h, (uint8_t *)&tmp, sizeof tmp) != (int32_t)sizeof tmp) return false;+ if (!game_sane(&tmp)) return false;+ g = tmp;+ return true;+}++void game_forget(void) {+ plat_remove(SAVE_GAME);+ set_file.h = (SaveHead){MAGIC_S, VERSION, 0, sizeof(SetFile)};+ set_file.opt = g.opt;+ write_copy(0, &set_file);+}++void game_init(void) {+ for (int c = 0; c < N_COLORS; c++) gfx_mix_palette(color_pal[c], BODY_COLORS[c], SHADOW_COLORS[c], VISOR);+ ship_init();+ memset(&g, 0, sizeof g);+ settings_load();+ g.rng = 0x12345u ^ plat_millis();+ g.screen = S_TITLE;+ if (game_load()) {+ /* back where the game was left, paused */+ ship_init();+ if (g.screen == S_PLAY || g.screen == S_KILLED) g.back_screen = S_PLAY, g.screen = S_PAUSE, g.sel = 0;+ }+}diff --git a/games/amongus/src/game.h b/games/amongus/src/game.hnew file mode 100644index 00000000..b44ae4a8--- /dev/null+++ b/games/amongus/src/game.h@@ -0,0 +1,202 @@+/* Among Us: the game's state and rules. Everything here is plain data (no pointers), so a game is saved by copying+ * it. Times are in seconds; the logic runs at the game's fixed 30 ticks a second. */+#ifndef AU_GAME_H+#define AU_GAME_H+#include <stdbool.h>+#include <stdint.h>+#include "ship.h"++#define DT (1.0f / 30)+#define MAXP 10+#define MAX_TASKS 10+#define NONE 0xFF+#define SKIP 10 /* a vote to skip */++/* the game's TaskTypes */+enum {+ T_SUBMIT_SCAN, T_PRIME_SHIELDS, T_FUEL_ENGINES, T_CHART_COURSE, T_START_REACTOR, T_SWIPE_CARD, T_CLEAR_ASTEROIDS,+ T_UPLOAD_DATA, T_INSPECT_SAMPLE, T_EMPTY_CHUTE, T_EMPTY_GARBAGE, T_ALIGN_ENGINE, T_FIX_WIRING, T_CALIBRATE,+ T_DIVERT_POWER, T_UNLOCK_MANIFOLDS, T_RESET_REACTOR, T_FIX_LIGHTS, T_CLEAN_O2, T_FIX_COMMS, T_RESTORE_O2,+ T_STABILIZE, N_TASK_TYPES+};+/* the sabotages */+enum { SAB_NONE, SAB_REACTOR, SAB_O2, SAB_LIGHTS, SAB_COMMS };+/* the screens */+enum { S_TITLE, S_LOBBY, S_INTRO, S_PLAY, S_REPORT, S_MEETING, S_EJECT, S_END, S_HOWTO, S_PAUSE, S_KILLED };+/* what the player has open over the ship */+enum { O_NONE, O_TASK, O_MAP, O_SABMAP, O_ADMIN, O_CAMS, O_EMERGENCY };++typedef struct {+ uint8_t def; /* the task in TASK_DEFS */+ uint8_t step;+ uint8_t data[3]; /* wiring: the consoles' ids in order */+ uint8_t pad;+ float timer; /* Inspect Sample's wait */+} Task;++typedef struct {+ uint8_t state, task, cons, target; /* what the bot is doing, and with what */+ uint8_t plen, pi, pad0, pad1;+ uint16_t path[40]; /* nav cells to walk through */+ V2 goal;+ float t, think, stuck_t;+ V2 last;+ /* what the bot knows: when and where it last saw each player, how much it suspects them */+ float seen_t[MAXP];+ uint8_t seen_room[MAXP];+ int8_t sus[MAXP];+ uint8_t saw_kill, saw_vent, saw_vent_room, saw_kill_room; /* who (NONE) */+ uint8_t near_body, body_room, found_body, said; /* who it saw near the body it found */+ uint8_t claim_room, with, scanned, pad2; /* its alibi */+ float with_t[MAXP]; /* time spent with each player lately */+} Bot;++typedef struct {+ V2 pos; /* the feet (the collider's middle) */+ V2 vel;+ float anim_t, kill_cd, busy_t;+ uint8_t color, alive, imp, flip;+ uint8_t vent, vent_anim, room, walking; /* vent: the vent it's in, or NONE */+ uint8_t ntasks, emergencies, busy, pad; /* busy: doing a task (bots) */+ Task tasks[MAX_TASKS];+ Bot bot;+} Player;++typedef struct {+ V2 pos;+ uint8_t who, on, pad[2];+} Body;++typedef struct {+ uint8_t who, kind, a, b; /* a chat line: who says what (LINE_*), about whom and where */+} Line;++/* the game's settings (its lobby options, with the original's defaults) */+typedef struct {+ uint8_t bots, impostors, role, color; /* role: 0 random, 1 crewmate, 2 impostor */+ uint8_t kill_cd; /* seconds, 10-60 by 2.5 halves: stored as tenths? no: seconds x2 */+ uint8_t kill_dist; /* 0 short, 1 medium, 2 long */+ uint8_t crew_vision, imp_vision; /* x0.25 steps: 4 = 1.0x */+ uint8_t speed; /* x0.25: 4 = 1.0x */+ uint8_t common, longt, shortt;+ uint8_t meetings, meet_cd, discuss, vote; /* emergency meetings, cooldown s, discussion s, voting s/5 */+ uint8_t confirm, anon, visual, taskbar; /* taskbar: 0 always, 1 meetings, 2 never */+} Options;++typedef struct {+ uint8_t screen, overlay, back_screen, sel;+ uint8_t nplayers, me, winner, end_reason; /* winner: 0 crew, 1 impostors */+ float t, screen_t;+ uint32_t rng;+ Options opt;+ Player p[MAXP];+ Body bodies[MAXP];+ /* doors: time each stays closed, its animation, and each room's cooldown */+ float door_t[16], door_anim[16];+ float door_cd[N_ROOMS];+ /* sabotage */+ uint8_t sab, switches, o2_done, sab_fixing;+ float sab_t, sab_cd, light;+ uint32_t o2_code;+ uint8_t reactor_hold[2], comms_ok, pad0;+ float reactor_held;+ float emergency_cd;+ /* meeting */+ uint8_t caller, reported, meet_stage, ejected;+ uint8_t votes[MAXP];+ uint8_t voted_me, tie, nlines, line_shown;+ Line lines[32];+ float meet_t, line_t;+ /* vents: when each opened, for its lid */+ float vent_t[16];+ /* the player's view */+ V2 cam;+ uint8_t killer, kill_anim, task_open, mg_cons;+ float kill_t;+ uint8_t room_shown, pad1[3];+ float room_t;+ float task_bar; /* shown (it updates only in meetings when set so) */+ uint8_t mg[512]; /* the open minigame's own state */+} Game;++extern Game g;+extern bool autopilot;++/* the tasks a ship gives (ShipStatus' lists) */+typedef struct {+ uint8_t type, room, steps, kind, target; /* kind 0 common, 1 long, 2 short; target: divert power's room */+ const char *name;+} TaskDef;+extern const TaskDef TASK_DEFS[];+extern const int N_TASK_DEFS;++/* colours (Palette.PlayerColors and ShadowColors) */+#define N_COLORS 12+extern const uint32_t BODY_COLORS[N_COLORS], SHADOW_COLORS[N_COLORS];+extern const char *const COLOR_NAMES[N_COLORS];+extern uint16_t color_pal[N_COLORS][256];++uint32_t rnd(void);+static inline int rnd_n(int n) { return n > 0 ? (int)(rnd() % (uint32_t)n) : 0; }+float rnd_f(void);++void game_init(void);+void game_tick(uint32_t keys);+void game_draw(void);+void game_new(void); /* a new game from the lobby's settings */+bool game_save(void);+bool game_load(void);+void settings_save(void);++/* rules (game.c) */+float player_speed(int i);+float vision_radius(int i);+float kill_distance(void);+float kill_cooldown(void);+bool task_done(const Task *t);+int task_steps(const Task *t);+int task_console(const Player *P, const Task *t); /* the console of its current step (-1: any of a kind) */+bool console_serves(int c, const Task *t);+const char *task_name(const Task *t);+int task_room(const Task *t);+void task_step_done(int pl, int ti);+float tasks_progress(void);+int living(bool imp);+void kill_player(int killer, int victim);+void start_meeting(int caller, int body);+void sabotage(int kind);+void close_doors(int room);+bool sabotage_ready(void);+void fix_sabotage(void);+int nearest_vent(V2 p, float maxd);+bool can_see(int a, int b);+void check_win(void);+void enter_vent(int i, int v);+void exit_vent(int i);+void move_vent(int i, int v);++/* bots (bot.c) */+void bot_init(int i);+void bot_tick(int i);+void bot_meeting_start(void);+void bot_meeting_tick(void);+void bot_votes(void);+void bot_see(int i);++/* the minigames (mg.c) */+void mg_open(int cons, int task);+void mg_tick(uint32_t keys, uint32_t pressed);+void mg_draw(void);+bool mg_blocks_move(void);++/* drawing (view.c, hud.c, screens.c) */+void view_draw(void);+void hud_draw(void);+void screens_tick(uint32_t keys, uint32_t pressed);+void screens_draw(void);+void map_draw(int mode);+void map_tick(uint32_t pressed, int mode);+void meeting_tick(uint32_t keys, uint32_t pressed);+void meeting_draw(void);+const char *line_text(const Line *l, char *buf, int n);+#endifdiff --git a/games/amongus/src/gfx.c b/games/amongus/src/gfx.cnew file mode 100644index 00000000..67bb0e42--- /dev/null+++ b/games/amongus/src/gfx.c@@ -0,0 +1,309 @@+/* Among Us: drawing (see gfx.h). */+#include <math.h>+#include <string.h>+#include "gfx.h"++uint16_t *gfx_band;+int gfx_y0;+const uint8_t *gfx_mix_alpha;++void gfx_init(uint16_t *band) {+ gfx_band = band;+ gfx_mix_alpha = (const uint8_t *)blob(BLOB_MIX) + 3;+}++void gfx_frame(void (*draw)(void)) {+ for (int y = 0; y < SCREEN_H; y += BAND) {+ gfx_y0 = y;+ draw();+ plat_push(0, y, SCREEN_W, BAND, gfx_band);+ }+}++/* the game's player shader: red is the body, green the visor, blue the shadow */+void gfx_mix_palette(uint16_t *pal, uint32_t body, uint32_t shadow, uint32_t visor) {+ const uint8_t *m = (const uint8_t *)blob(BLOB_MIX);+ for (int i = 0; i < N_MIX; i++, m += 4) {+ int c[3];+ for (int k = 0; k < 3; k++) {+ int sh = 16 - 8 * k;+ int v = (m[0] * (int)(body >> sh & 255) + m[1] * (int)(visor >> sh & 255) + m[2] * (int)(shadow >> sh & 255)) / 255;+ c[k] = v > 255 ? 255 : v;+ }+ pal[i] = rgb565((uint32_t)c[0] << 16 | (uint32_t)c[1] << 8 | (uint32_t)c[2]);+ }+}++static inline unsigned px_at(const Pic *p, const uint8_t *px, int x, int y) {+ if (p->flags & P_4BIT) {+ uint8_t b = px[y * ((p->w + 1) >> 1) + (x >> 1)];+ return x & 1 ? b & 15 : b >> 4;+ }+ return px[y * p->w + x];+}++void gfx_spr_clip(const Pic *p, int x, int y, bool flip, const uint16_t *pal, int alpha, int cx0, int cy0, int cx1,+ int cy1) {+ if (!p) return;+ int x0 = x - (flip ? p->w - p->ox : p->ox), y0 = y - p->oy;+ if (cy0 < gfx_y0) cy0 = gfx_y0;+ if (cy1 > gfx_y0 + BAND) cy1 = gfx_y0 + BAND;+ if (cx0 < 0) cx0 = 0;+ if (cx1 > SCREEN_W) cx1 = SCREEN_W;+ int r0 = cy0 - y0, r1 = cy1 - y0, c0 = cx0 - x0, c1 = cx1 - x0;+ if (r0 < 0) r0 = 0;+ if (r1 > p->h) r1 = p->h;+ if (c0 < 0) c0 = 0;+ if (c1 > p->w) c1 = p->w;+ if (r0 >= r1 || c0 >= c1) return;+ const uint8_t *al = p->flags & P_MIX ? gfx_mix_alpha : pic_alpha(p);+ const uint16_t *pl = pal ? pal : pic_pal(p);+ const uint8_t *px = pic_px(p);+ bool four = p->flags & P_4BIT;+ int astep = (p->flags & P_MIX) ? 4 : 1;+ for (int r = r0; r < r1; r++) {+ uint16_t *row = gfx_band + (y0 + r - gfx_y0) * SCREEN_W + x0;+ const uint8_t *src = px + r * (four ? (p->w + 1) >> 1 : p->w);+ for (int c = c0; c < c1; c++) {+ int sc = flip ? p->w - 1 - c : c;+ unsigned i = four ? (sc & 1 ? src[sc >> 1] & 15 : src[sc >> 1] >> 4) : src[sc];+ unsigned a = al[i * astep];+ if (!a) continue;+ if (a >= 250 && alpha >= 256) row[c] = pl[i];+ else row[c] = blend(row[c], pl[i], (int)(a * (unsigned)alpha >> 8));+ }+ }+}++void gfx_spr(const Pic *p, int x, int y, bool flip, const uint16_t *pal, int alpha) {+ gfx_spr_clip(p, x, y, flip, pal, alpha, 0, 0, SCREEN_W, SCREEN_H);+}++void gfx_spr_tint(const Pic *p, int x, int y, uint16_t col, int alpha) {+ if (!p) return;+ int x0 = x - p->ox, y0 = y - p->oy;+ if (!gfx_rows(y0, y0 + p->h)) return;+ const uint8_t *al = p->flags & P_MIX ? gfx_mix_alpha : pic_alpha(p);+ int astep = (p->flags & P_MIX) ? 4 : 1;+ const uint8_t *px = pic_px(p);+ for (int r = 0; r < p->h; r++) {+ int yy = y0 + r;+ if (yy < gfx_y0 || yy >= gfx_y0 + BAND) continue;+ uint16_t *row = gfx_band + (yy - gfx_y0) * SCREEN_W;+ for (int c = 0; c < p->w; c++) {+ int xx = x0 + c;+ if ((unsigned)xx >= SCREEN_W) continue;+ unsigned a = al[px_at(p, px, c, r) * astep];+ if (a > 128) row[xx] = blend(row[xx], col, alpha);+ }+ }+}++void gfx_pic(const Pic *p, float x, float y, float sx, float sy, float angle, const uint16_t *pal, int alpha) {+ if (!p || sx == 0 || sy == 0) return;+ float c = cosf(angle), s = sinf(angle);+ float miny = 1e9f, maxy = -1e9f, minx = 1e9f, maxx = -1e9f;+ float lx[4] = {0, (float)p->w, (float)p->w, 0}, ly[4] = {0, 0, (float)p->h, (float)p->h};+ for (int i = 0; i < 4; i++) {+ float dx = (lx[i] - p->ox) * sx, dy = (ly[i] - p->oy) * sy;+ float X = x + dx * c - dy * s, Y = y + dx * s + dy * c;+ if (Y < miny) miny = Y;+ if (Y > maxy) maxy = Y;+ if (X < minx) minx = X;+ if (X > maxx) maxx = X;+ }+ int ya = (int)floorf(miny), yb = (int)ceilf(maxy);+ if (!gfx_rows(ya, yb)) return;+ if (ya < gfx_y0) ya = gfx_y0;+ if (yb > gfx_y0 + BAND) yb = gfx_y0 + BAND;+ int xa = (int)floorf(minx), xb = (int)ceilf(maxx);+ if (xa < 0) xa = 0;+ if (xb > SCREEN_W) xb = SCREEN_W;+ const uint8_t *al = p->flags & P_MIX ? gfx_mix_alpha : pic_alpha(p);+ int astep = (p->flags & P_MIX) ? 4 : 1;+ const uint16_t *pl = pal ? pal : pic_pal(p);+ const uint8_t *px = pic_px(p);+ /* screen to picture: u = ((X-x) c + (Y-y) s) / sx + ox */+ for (int yy = ya; yy < yb; yy++) {+ uint16_t *row = gfx_band + (yy - gfx_y0) * SCREEN_W;+ float fy = yy + 0.5f - y;+ for (int xx = xa; xx < xb; xx++) {+ float fx = xx + 0.5f - x;+ int u = (int)floorf((fx * c + fy * s) / sx + p->ox), v = (int)floorf((-fx * s + fy * c) / sy + p->oy);+ if ((unsigned)u >= p->w || (unsigned)v >= p->h) continue;+ unsigned i = px_at(p, px, u, v);+ unsigned a = al[i * astep];+ if (!a) continue;+ if (a >= 250 && alpha >= 256) row[xx] = pl[i];+ else row[xx] = blend(row[xx], pl[i], (int)(a * (unsigned)alpha >> 8));+ }+ }+}++void gfx_fill(int x, int y, int w, int h, uint16_t c, int alpha) {+ int y0 = y > gfx_y0 ? y : gfx_y0, y1 = y + h < gfx_y0 + BAND ? y + h : gfx_y0 + BAND;+ if (x < 0) w += x, x = 0;+ if (x + w > SCREEN_W) w = SCREEN_W - x;+ if (w <= 0) return;+ for (int yy = y0; yy < y1; yy++) {+ uint16_t *row = gfx_band + (yy - gfx_y0) * SCREEN_W + x;+ if (alpha >= 256)+ for (int i = 0; i < w; i++) row[i] = c;+ else+ for (int i = 0; i < w; i++) row[i] = blend(row[i], c, alpha);+ }+}++void gfx_rect(int x, int y, int w, int h, int t, uint16_t c) {+ gfx_fill(x, y, w, t, c, 256);+ gfx_fill(x, y + h - t, w, t, c, 256);+ gfx_fill(x, y + t, t, h - 2 * t, c, 256);+ gfx_fill(x + w - t, y + t, t, h - 2 * t, c, 256);+}++int gfx_poly_spans(const float *xy, int n, int y, int16_t *out, int max) {+ float yc = y + 0.5f, xs[32];+ int k = 0;+ for (int i = 0, j = n - 1; i < n; j = i++) {+ float yi = xy[2 * i + 1], yj = xy[2 * j + 1];+ if ((yi > yc) != (yj > yc) && k < 32) xs[k++] = xy[2 * j] + (yc - yj) * (xy[2 * i] - xy[2 * j]) / (yi - yj);+ }+ for (int a = 1; a < k; a++) {+ float v = xs[a];+ int b = a - 1;+ while (b >= 0 && xs[b] > v) xs[b + 1] = xs[b], b--;+ xs[b + 1] = v;+ }+ int ns = 0;+ for (int i = 0; i + 1 < k && ns < max; i += 2) {+ int xa = (int)ceilf(xs[i] - 0.5f), xb = (int)ceilf(xs[i + 1] - 0.5f);+ if (xa < 0) xa = 0;+ if (xb > SCREEN_W) xb = SCREEN_W;+ if (xa < xb) out[2 * ns] = (int16_t)xa, out[2 * ns + 1] = (int16_t)xb, ns++;+ }+ return ns;+}++void gfx_poly(const float *xy, int n, uint16_t c, int alpha) {+ float lo = 1e9f, hi = -1e9f;+ for (int i = 0; i < n; i++) {+ if (xy[2 * i + 1] < lo) lo = xy[2 * i + 1];+ if (xy[2 * i + 1] > hi) hi = xy[2 * i + 1];+ }+ if (!gfx_rows((int)floorf(lo), (int)ceilf(hi) + 1)) return;+ int16_t sp[16];+ for (int r = 0; r < BAND; r++) {+ int y = gfx_y0 + r;+ if (y + 1 < lo || y > hi) continue;+ int k = gfx_poly_spans(xy, n, y, sp, 8);+ uint16_t *row = gfx_band + r * SCREEN_W;+ for (int s = 0; s < k; s++)+ for (int x = sp[2 * s]; x < sp[2 * s + 1]; x++) row[x] = alpha >= 256 ? c : blend(row[x], c, alpha);+ }+}++void gfx_line(float x0, float y0, float x1, float y1, float w, uint16_t c, int alpha) {+ float dx = x1 - x0, dy = y1 - y0, l = sqrtf(dx * dx + dy * dy);+ if (l <= 0) return;+ float nx = -dy / l * w / 2, ny = dx / l * w / 2;+ float q[8] = {x0 + nx, y0 + ny, x1 + nx, y1 + ny, x1 - nx, y1 - ny, x0 - nx, y0 - ny};+ gfx_poly(q, 4, c, alpha);+}++void gfx_disc(float cx, float cy, float r, uint16_t c, int alpha) {+ int ya = (int)floorf(cy - r), yb = (int)ceilf(cy + r);+ if (!gfx_rows(ya, yb)) return;+ for (int y = ya; y < yb; y++) {+ if (y < gfx_y0 || y >= gfx_y0 + BAND) continue;+ float dy = y + 0.5f - cy, w2 = r * r - dy * dy;+ if (w2 <= 0) continue;+ float w = sqrtf(w2);+ int xa = (int)ceilf(cx - w - 0.5f), xb = (int)ceilf(cx + w - 0.5f);+ gfx_fill(xa, y, xb - xa, 1, c, alpha);+ }+}++/* ---- text ---- */++static void glyph(const Font *f, const Glyph *g, int x, int y, uint16_t color) {+ const uint8_t *bits = font_bits(f) + g->off;+ int gx = x + g->x, gy = y + g->y;+ for (int r = 0; r < g->h; r++) {+ int yy = gy + r;+ if (yy < gfx_y0 || yy >= gfx_y0 + BAND) continue;+ uint16_t *row = gfx_band + (yy - gfx_y0) * SCREEN_W;+ for (int c = 0; c < g->w; c++) {+ int xx = gx + c;+ if ((unsigned)xx >= SCREEN_W) continue;+ int i = r * g->w + c;+ int v = i & 1 ? bits[i >> 1] & 15 : bits[i >> 1] >> 4;+ if (!v) continue;+ row[xx] = v == 15 ? color : blend(row[xx], color, v * 17 + 1);+ }+ }+}++int gfx_text_width(int fid, const char *s) {+ const Font *f = font(fid);+ const Glyph *gs = font_glyphs(f);+ int w = 0;+ for (; *s && *s != '\n'; s++) {+ unsigned ch = (uint8_t)*s;+ if (ch < f->first || ch >= f->first + f->count) continue;+ w += gs[ch - f->first].adv;+ }+ return w;+}++int gfx_text(int fid, int x, int y, const char *s, uint16_t color, uint16_t outline, int thick, int align) {+ const Font *f = font(fid);+ const Glyph *gs = font_glyphs(f);+ int w = gfx_text_width(fid, s);+ x -= align == 1 ? w / 2 : align == 2 ? w : 0;+ if (y + thick + 8 < gfx_y0 || y - f->ascent - thick > gfx_y0 + BAND) return w;+ for (int pass = thick ? 0 : 1; pass < 2; pass++) {+ int px = x;+ for (const char *p = s; *p && *p != '\n'; p++) {+ unsigned ch = (uint8_t)*p;+ if (ch < f->first || ch >= f->first + f->count) continue;+ const Glyph *g = &gs[ch - f->first];+ if (g->w) {+ if (pass == 0) {+ for (int oy = -thick; oy <= thick; oy++)+ for (int ox = -thick; ox <= thick; ox++)+ if ((ox || oy) && ox * ox + oy * oy <= thick * thick + 1) glyph(f, g, px + ox, y + oy, outline);+ } else glyph(f, g, px, y, color);+ }+ px += g->adv;+ }+ }+ return w;+}++int gfx_text_wrap(int fid, int x, int y, int w, int lh, const char *s, uint16_t color, uint16_t outline, int thick,+ int align) {+ char line[96];+ int n = 0;+ while (*s) {+ /* the longest run of words that fits */+ int len = 0, fit = 0;+ for (;;) {+ while (s[len] && s[len] != ' ' && s[len] != '\n') len++;+ if (len >= (int)sizeof line) break;+ memcpy(line, s, (size_t)len);+ line[len] = 0;+ if (gfx_text_width(fid, line) > w && fit) break;+ fit = len;+ if (!s[len] || s[len] == '\n') break;+ len++;+ }+ if (!fit) fit = len < (int)sizeof line - 1 ? len : (int)sizeof line - 1;+ memcpy(line, s, (size_t)fit);+ line[fit] = 0;+ gfx_text(fid, x, y + n * lh, line, color, outline, thick, align);+ n++;+ s += fit;+ while (*s == ' ' || *s == '\n') s++;+ }+ return n;+}diff --git a/games/amongus/src/gfx.h b/games/amongus/src/gfx.hnew file mode 100644index 00000000..1b1a6a66--- /dev/null+++ b/games/amongus/src/gfx.h@@ -0,0 +1,56 @@+/* Among Us: drawing. The calculator has no frame buffer for the whole screen, so a frame is drawn a band of rows at+ * a time: the scene is walked once per band and each primitive fills only the band's rows. */+#ifndef AU_GFX_H+#define AU_GFX_H+#include <stdbool.h>+#include <stdint.h>+#include "plat.h"+#include "res.h"++#define BAND 16++static inline uint16_t rgb565(uint32_t rgb) {+ return (uint16_t)(((rgb >> 8) & 0xF800) | ((rgb >> 5) & 0x07E0) | ((rgb >> 3) & 0x001F));+}+static inline uint16_t blend(uint16_t d, uint16_t s, int a) {+ /* a: 0-256 */+ uint32_t dd = (d | ((uint32_t)d << 16)) & 0x07E0F81F, ss = (s | ((uint32_t)s << 16)) & 0x07E0F81F;+ uint32_t r = (dd + (((ss - dd) * (uint32_t)(a >> 3)) >> 5)) & 0x07E0F81F;+ return (uint16_t)(r | (r >> 16));+}++extern uint16_t *gfx_band;+extern int gfx_y0; /* the band's first row */++void gfx_init(uint16_t *band);+/* draws a frame: calls draw() once for each band, then pushes it */+void gfx_frame(void (*draw)(void));+static inline bool gfx_rows(int y0, int y1) { return y1 > gfx_y0 && y0 < gfx_y0 + BAND; }++/* the mix table's alphas (the players' pictures), and a colour's palette for them */+extern const uint8_t *gfx_mix_alpha;+void gfx_mix_palette(uint16_t *pal, uint32_t body, uint32_t shadow, uint32_t visor);++/* a picture with its pivot at (x, y), mirrored, alpha 0-256, inside the clip rectangle; pal: the colours of a P_MIX+ * picture (NULL for the picture's own) */+void gfx_spr(const Pic *p, int x, int y, bool flip, const uint16_t *pal, int alpha);+void gfx_spr_clip(const Pic *p, int x, int y, bool flip, const uint16_t *pal, int alpha, int cx0, int cy0, int cx1,+ int cy1);+/* a picture scaled (and turned) around its pivot at (x, y) */+void gfx_pic(const Pic *p, float x, float y, float sx, float sy, float angle, const uint16_t *pal, int alpha);+/* a picture tinted by c (alpha kept): the outlines of usable consoles */+void gfx_spr_tint(const Pic *p, int x, int y, uint16_t c, int alpha);+void gfx_fill(int x, int y, int w, int h, uint16_t c, int alpha);+void gfx_rect(int x, int y, int w, int h, int t, uint16_t c);+void gfx_line(float x0, float y0, float x1, float y1, float w, uint16_t c, int alpha);+void gfx_disc(float cx, float cy, float r, uint16_t c, int alpha);+void gfx_poly(const float *xy, int n, uint16_t c, int alpha);+/* the polygon's spans on row y (pairs of x, clamped to the screen); returns how many */+int gfx_poly_spans(const float *xy, int n, int y, int16_t *out, int max);+/* text: y is the baseline; align 0 left, 1 centre, 2 right; outline thickness 0 for none; returns its width */+int gfx_text(int font, int x, int y, const char *s, uint16_t color, uint16_t outline, int thick, int align);+int gfx_text_width(int font, const char *s);+/* text wrapped to w pixels; returns the number of lines */+int gfx_text_wrap(int font, int x, int y, int w, int lh, const char *s, uint16_t color, uint16_t outline, int thick,+ int align);+#endifdiff --git a/games/amongus/src/hud.c b/games/amongus/src/hud.cnew file mode 100644index 00000000..3ab396df--- /dev/null+++ b/games/amongus/src/hud.c@@ -0,0 +1,163 @@+/* Among Us: the HUD over the ship: the task bar and list, the room's name, the buttons, the key line. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"+#include "gfx.h"+#include "view.h"+#include "world.h"++int hud_action(int *what);+int kill_target(int i);++#define YELLOW 0xFFE0+#define GREEN 0x07E0++static void task_line(const Task *t, char *buf, int n) {+ int steps = task_steps(t), step = t->step;+ const char *room = ROOM_NAMES[task_room(t)];+ if (TASK_DEFS[t->def].type == T_FUEL_ENGINES) steps = 2, step = t->step / 2;+ if (TASK_DEFS[t->def].type == T_INSPECT_SAMPLE && t->timer > 0 && !task_done(t))+ snprintf(buf, (size_t)n, "%s: %s %ds", room, task_name(t), (int)ceilf(t->timer));+ else if (steps > 1)+ snprintf(buf, (size_t)n, "%s: %s (%d/%d)", room, task_name(t), step, steps);+ else+ snprintf(buf, (size_t)n, "%s: %s", room, task_name(t));+}++static void sab_line(char *buf, int n) {+ switch (g.sab) {+ case SAB_REACTOR: {+ int k = (g.reactor_hold[0] != NONE) + (g.reactor_hold[1] != NONE);+ snprintf(buf, (size_t)n, "Reactor Meltdown in %d (%d/2)", (int)ceilf(g.sab_t), k);+ break;+ }+ case SAB_O2:+ snprintf(buf, (size_t)n, "Oxygen depleted in %d (%d/2)", (int)ceilf(g.sab_t), (g.o2_done & 1) + (g.o2_done >> 1 & 1));+ break;+ case SAB_LIGHTS: {+ int on = 0;+ for (int k = 0; k < 5; k++) on += g.switches >> k & 1;+ snprintf(buf, (size_t)n, "Fix Lights (%d%%)", on * 20);+ break;+ }+ case SAB_COMMS: snprintf(buf, (size_t)n, "Comms Sabotaged"); break;+ default: buf[0] = 0;+ }+}++static void draw_tasks(void) {+ const Player *M = &g.p[g.me];+ /* the bar: TOTAL TASKS COMPLETED */+ if (g.opt.taskbar != 2) {+ gfx_fill(4, 4, 124, 13, 0x0000, 200);+ gfx_fill(5, 5, 122, 11, rgb565(0x2B3A2E), 256);+ float f = g.opt.taskbar == 0 ? tasks_progress() : g.task_bar;+ gfx_fill(5, 5, (int)(122 * f), 11, rgb565(0x44D844), 256);+ gfx_text(FONT_SMALL, 66, 14, "TOTAL TASKS COMPLETED", 0xFFFF, 0, 1, 1);+ }+ char buf[64];+ int y = g.opt.taskbar != 2 ? 22 : 4, lines = 0;+ /* the list */+ const char *L[MAX_TASKS + 3];+ uint16_t C[MAX_TASKS + 3];+ static char store[MAX_TASKS + 3][64];+ if (g.sab) {+ sab_line(store[lines], 64);+ L[lines] = store[lines], C[lines] = ((int)(g.t * 2) & 1) ? 0xF800 : 0xFFFF, lines++;+ }+ if (M->imp) {+ L[lines] = "Sabotage and kill everyone.", C[lines] = 0xF800, lines++;+ L[lines] = "Fake Tasks:", C[lines] = 0xFFFF, lines++;+ } else if (!M->alive) {+ L[lines] = "You're dead, finish your tasks", C[lines] = 0xFFFF, lines++;+ }+ if (g.sab == SAB_COMMS && !M->imp) {+ L[lines] = "Comms Sabotaged", C[lines] = 0xF800, lines++;+ } else+ for (int k = 0; k < M->ntasks && lines < MAX_TASKS + 3; k++) {+ const Task *t = &M->tasks[k];+ task_line(t, store[lines], 64);+ L[lines] = store[lines];+ C[lines] = task_done(t) ? GREEN : (t->step > 0 || t->timer > 0) ? YELLOW : 0xFFFF;+ lines++;+ }+ int w = 0;+ for (int k = 0; k < lines; k++) {+ int tw = gfx_text_width(FONT_SMALL, L[k]);+ if (tw > w) w = tw;+ }+ if (y + lines * 11 + 4 < gfx_y0 || y > gfx_y0 + BAND) return;+ gfx_fill(4, y, w + 8, lines * 11 + 4, 0x0000, 130);+ for (int k = 0; k < lines; k++) gfx_text(FONT_SMALL, 8, y + 11 + k * 11, L[k], C[k], 0, 0, 0);+ (void)buf;+}++/* a round button with its name, and a cooldown number over it */+static void button(int x, int y, const char *name, bool on, int cd) {+ uint16_t c = on ? 0xFFFF : 0x8410;+ gfx_disc((float)x, (float)y, 17, 0x0000, on ? 150 : 90);+ gfx_text(FONT_MID, x, y + 4, name, c, 0x0000, 1, 1);+ if (cd > 0) {+ char b[8];+ snprintf(b, sizeof b, "%d", cd);+ gfx_text(FONT_BIG, x, y - 6, b, 0xFFFF, 0x0000, 1, 1);+ }+}++static const char *act_name(int a) {+ switch (a) {+ case 1: return "USE";+ case 2: return "REPORT";+ case 3: return "VENT";+ case 4: return "USE";+ case 5: return "ADMIN";+ case 6: return "SECURITY";+ default: return "USE";+ }+}++static void draw_keys(const char *s) {+ gfx_fill(0, 228, SCREEN_W, 12, 0x0000, 190);+ gfx_text(FONT_SMALL, 160, 237, s, 0xFFFF, 0, 0, 1);+}++void hud_keys(const char *s) { draw_keys(s); }++void hud_draw(void) {+ const Player *M = &g.p[g.me];+ draw_tasks();+ /* the room's name (RoomTracker), for a while after entering */+ if (g.room_t > 0 && g.room_shown != R_HALLWAY) {+ int a = g.room_t > 0.5f ? 256 : (int)(g.room_t * 512);+ (void)a;+ gfx_text(FONT_BIG, 160, 222, ROOM_NAMES[g.room_shown], 0xFFFF, 0x0000, 1, 1);+ }+ /* the critical sabotage's red flash */+ if ((g.sab == SAB_REACTOR || g.sab == SAB_O2) && fmodf(g.t, 1.2f) < 0.6f) {+ gfx_fill(0, 0, SCREEN_W, 6, 0xF800, 150);+ gfx_fill(0, SCREEN_H - 18, SCREEN_W, 6, 0xF800, 150);+ gfx_fill(0, 6, 6, SCREEN_H - 24, 0xF800, 150);+ gfx_fill(SCREEN_W - 6, 6, 6, SCREEN_H - 24, 0xF800, 150);+ }+ int what = -1, a = hud_action(&what);+ char keys[96];+ const char *act = a ? act_name(a) : NULL;+ if (M->vent != NONE) act = "VENT";+ bool kill_on = M->imp && M->alive;+ if (kill_on) {+ int cd = M->kill_cd > 0 ? (int)ceilf(M->kill_cd) : 0;+ button(290, 196, "KILL", cd == 0 && kill_target(g.me) >= 0, cd);+ }+ button(kill_on ? 248 : 290, 196, act ? act : (M->imp ? "SABOTAGE" : "USE"), act != NULL, 0);+ if (M->vent != NONE)+ snprintf(keys, sizeof keys, "arrows other vents OK leave toolbox sabotage Back pause");+ else if (M->imp && M->alive)+ snprintf(keys, sizeof keys, "OK %s EXE kill toolbox sabotage Back pause", act ? act : "use");+ else+ snprintf(keys, sizeof keys, "arrows walk OK %s toolbox map Back pause", act ? act : "use");+ for (char *p = keys; *p; p++)+ if (*p >= 'A' && *p <= 'Z' && p > keys && p[-1] == ' ' && p[1] >= 'A' && p[1] <= 'Z')+ for (char *q = p; *q && *q != ' '; q++) *q = (char)(*q - 'A' + 'a');+ draw_keys(keys);+}diff --git a/games/amongus/src/icon.png b/games/amongus/src/icon.pngnew file mode 100644index 00000000..0b9c9c33Binary files /dev/null and b/games/amongus/src/icon.png differdiff --git a/games/amongus/src/main.c b/games/amongus/src/main.cnew file mode 100644index 00000000..6e228aa3--- /dev/null+++ b/games/amongus/src/main.c@@ -0,0 +1,47 @@+/* Among Us for the NumWorks calculator.+ *+ * Inspired by Among Us by Innersloth, not affiliated with them.+ * Made by Mason Chen as part of NumPlay. */+#include "game.h"+#include "gfx.h"+#include "plat.h"++#ifndef HOST+const char eadk_app_name[] __attribute__((section(".rodata.eadk_app_name"))) = "Among Us";+const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level"))) = 0;++uint32_t perf_frames __attribute__((used)); /* read by tools/emu.py */+uint32_t perf_max __attribute__((used));+extern bool game_running;++int main(void) {+ /* the band drawn into lives on main's stack */+ uint16_t band[SCREEN_W * BAND];+ gfx_init(band);+ plat_begin();+ game_init();+ /* the game's fixed 30 ticks a second (TimeManager's Fixed Timestep), at most 3 a drawing */+ uint32_t next = plat_millis() * 3; /* in thirds of a millisecond: 100 a tick */+ while (game_running) {+ int n = 0;+ uint32_t now = plat_millis() * 3;+ while ((int32_t)(now - next) >= 0 && n < 3 && game_running) {+ game_tick(plat_keys());+ next += 100;+ n++;+ }+ if (!game_running) break;+ if ((int32_t)(now - next) > 300) next = now; /* far behind: do not rush */+ if (n) {+ uint32_t t0 = plat_millis();+ game_draw();+ uint32_t dt = plat_millis() - t0;+ if (dt > perf_max && perf_frames > 30) perf_max = dt;+ perf_frames++;+ } else {+ plat_sleep(1);+ }+ }+ return plat_end();+}+#endifdiff --git a/games/amongus/src/map.c b/games/amongus/src/map.cnew file mode 100644index 00000000..f6cd71ac--- /dev/null+++ b/games/amongus/src/map.c@@ -0,0 +1,23 @@+/* Among Us: the map (MapBehaviour): where you are and your tasks; for impostors the sabotage map; the admin table's+ * counts of who is in each room. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"+#include "gfx.h"+#include "view.h"+#include "world.h"++void hud_keys(const char *s);++void map_tick(uint32_t pressed, int mode) {+ (void)mode;+ if (pressed & (K_BACK | K_TOOL)) g.overlay = O_NONE;+}++void map_draw(int mode) {+ view_draw();+ gfx_fill(0, 0, SCREEN_W, SCREEN_H, rgb565(0x1B3D6B), 200);+ gfx_text(FONT_BIG, 160, 110, mode == O_SABMAP ? "Sabotage" : mode == O_ADMIN ? "Admin" : "Map", 0xFFFF, 0, 0, 1);+ hud_keys("Back close");+}diff --git a/games/amongus/src/meeting.c b/games/amongus/src/meeting.cnew file mode 100644index 00000000..f31f2ff7--- /dev/null+++ b/games/amongus/src/meeting.c@@ -0,0 +1,198 @@+/* Among Us: the meeting (MeetingHud): discussion, then voting with a skip, the votes shown, then the ejection.+ * The bots talk in short lines, as the game's quick chat does. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"+#include "gfx.h"+#include "world.h"++void hud_keys(const char *s);+void art_player(int color, float x, float y, float scale, bool flip, int alpha);+void art_meeting_bg(void);+void art_plate(int x, int y, int i, bool sel, bool voted, bool dead);+void art_vote_icon(int x, int y, int color, bool anon);+void art_skip(int x, int y, bool sel);++enum {+ L_BODY_IN, L_NEAR_BODY, L_SAW_KILL, L_SAW_VENT, L_WAS_IN, L_WITH, L_SUS, L_WHO, L_WHERE, L_SKIP, L_NOT_ME,+ L_SCANNED, L_BUTTON+};++const char *line_text(const Line *l, char *b, int n) {+ const char *a = l->a < MAXP ? COLOR_NAMES[g.p[l->a].color] : "";+ const char *r = l->b < N_ROOMS ? ROOM_NAMES[l->b] : "";+ switch (l->kind) {+ case L_BODY_IN: snprintf(b, (size_t)n, "%s is dead. Body in %s", a, r); break;+ case L_NEAR_BODY: snprintf(b, (size_t)n, "%s was near the body in %s", a, r); break;+ case L_SAW_KILL: snprintf(b, (size_t)n, "I saw %s kill in %s!", a, r); break;+ case L_SAW_VENT: snprintf(b, (size_t)n, "%s vented in %s!", a, r); break;+ case L_WAS_IN: snprintf(b, (size_t)n, "I was in %s doing tasks", l->a < N_ROOMS ? ROOM_NAMES[l->a] : ""); break;+ case L_WITH: snprintf(b, (size_t)n, "I was with %s in %s", a, r); break;+ case L_SUS: snprintf(b, (size_t)n, "%s is sus", a); break;+ case L_WHO: snprintf(b, (size_t)n, "Who?"); break;+ case L_WHERE: snprintf(b, (size_t)n, "Where?"); break;+ case L_SKIP: snprintf(b, (size_t)n, "Skip"); break;+ case L_NOT_ME: snprintf(b, (size_t)n, "Not me"); break;+ case L_SCANNED: snprintf(b, (size_t)n, "%s scanned, they're safe", a); break;+ case L_BUTTON: snprintf(b, (size_t)n, "I called it. Anyone sus?"); break;+ default: b[0] = 0;+ }+ return b;+}++static void finish_votes(void) {+ int counts[MAXP + 1] = {0};+ for (int i = 0; i < g.nplayers; i++)+ if (g.p[i].alive && g.votes[i] != NONE) counts[g.votes[i]]++;+ int best = -1, bc = 0, tie = 0;+ for (int k = 0; k <= SKIP; k++) {+ if (counts[k] > bc) bc = counts[k], best = k, tie = 0;+ else if (counts[k] == bc && bc) tie = 1;+ }+ g.tie = (uint8_t)tie;+ g.ejected = (best >= 0 && best != SKIP && !tie) ? (uint8_t)best : NONE;+}++static int living_voters(void) {+ int n = 0;+ for (int i = 0; i < g.nplayers; i++) n += g.p[i].alive;+ return n;+}++static void after_meeting(void) {+ /* back in the cafeteria, as after every meeting */+ if (g.ejected != NONE) g.p[g.ejected].alive = 0;+ for (int b = 0; b < MAXP; b++) g.bodies[b].on = 0;+ int n = g.nplayers;+ for (int i = 0; i < n; i++) {+ Player *P = &g.p[i];+ float a = 6.2831853f * i / n - 1.5707963f;+ P->pos = (V2){-0.72f + cosf(a) * 1.6f, 0.62f + sinf(a) * 1.6f - FEET_Y};+ P->vel = (V2){0, 0};+ P->vent = NONE;+ P->vent_anim = 0;+ P->walking = 0;+ P->kill_cd = kill_cooldown();+ P->busy = 0;+ Bot *B = &P->bot;+ B->state = 0;+ B->plen = 0;+ B->near_body = B->found_body = NONE;+ if (B->saw_kill != NONE && !g.p[B->saw_kill].alive) B->saw_kill = NONE;+ if (B->saw_vent != NONE && !g.p[B->saw_vent].alive) B->saw_vent = NONE;+ B->t = 0.5f + rnd_f();+ }+ g.cam = (V2){g.p[g.me].pos.x, g.p[g.me].pos.y + FEET_Y};+ g.emergency_cd = g.opt.meet_cd;+ g.task_bar = tasks_progress();+ g.overlay = O_NONE;+}++void meeting_tick(uint32_t keys, uint32_t pressed) {+ (void)keys;+ g.meet_t += DT;+ bot_meeting_tick();+ Player *M = &g.p[g.me];+ if (g.meet_stage == 0 && g.meet_t >= g.opt.discuss) g.meet_stage = 1, g.meet_t = 0;+ if (g.meet_stage == 1) {+ bot_votes();+ /* the player's vote: the plates (two columns), then Skip */+ if (M->alive && g.votes[g.me] == NONE) {+ int s = g.sel & 15, n = g.nplayers;+ bool confirm = g.sel & 16;+ if (!confirm) {+ if (pressed & K_DOWN) s = s == SKIP ? s : (s + 2 < n ? s + 2 : SKIP);+ if (pressed & K_UP) s = s == SKIP ? n - 1 - ((n - 1) & 1 ? 0 : 0) : (s >= 2 ? s - 2 : s);+ if (pressed & K_LEFT) s = s == SKIP ? s : s & ~1;+ if (pressed & K_RIGHT) s = s == SKIP ? s : (s | 1) < n ? s | 1 : s;+ if (s > SKIP) s = SKIP;+ bool ok = s == SKIP || (s < n && g.p[s].alive);+ if ((pressed & (K_OK | K_EXE)) && ok) confirm = true;+ } else {+ if (pressed & (K_OK | K_EXE)) g.votes[g.me] = (uint8_t)s, confirm = false;+ if (pressed & K_BACK) confirm = false;+ }+ g.sel = (uint8_t)(s | (confirm ? 16 : 0));+ }+ int voted = 0;+ for (int i = 0; i < g.nplayers; i++) voted += g.p[i].alive && g.votes[i] != NONE;+ if (voted >= living_voters() || g.meet_t >= g.opt.vote * 5) {+ finish_votes();+ g.meet_stage = 2;+ g.meet_t = 0;+ }+ } else if (g.meet_stage == 2 && g.meet_t >= 5) {+ after_meeting();+ g.screen = S_EJECT;+ g.screen_t = 0;+ }+ if ((pressed & K_BACK) && !(g.sel & 16) && g.meet_stage != 1) {+ /* (nothing to close: the meeting can't be left) */+ }+ if (pressed & K_TOOL) g.line_shown = g.line_shown ? 0 : 1;+}++static const char *stage_text(char *b, int n) {+ if (g.meet_stage == 0) snprintf(b, (size_t)n, "Voting Begins In: %ds", (int)ceilf(g.opt.discuss - g.meet_t));+ else if (g.meet_stage == 1) snprintf(b, (size_t)n, "Voting Ends In: %ds", (int)ceilf(g.opt.vote * 5 - g.meet_t));+ else snprintf(b, (size_t)n, "Proceeding In: %ds", (int)ceilf(5 - g.meet_t));+ return b;+}++void meeting_draw(void) {+ art_meeting_bg();+ char b[64];+ /* the plates: two columns of five */+ int sel = g.sel & 15;+ bool confirm = g.sel & 16;+ const Player *M = &g.p[g.me];+ bool can_vote = g.meet_stage == 1 && M->alive && g.votes[g.me] == NONE;+ for (int i = 0; i < g.nplayers; i++) {+ int x = 12 + (i & 1) * 150, y = 26 + (i >> 1) * 29;+ art_plate(x, y, i, can_vote && sel == i, g.votes[i] != NONE && g.meet_stage == 1, !g.p[i].alive);+ if (i == g.caller && g.meet_stage < 2) {+ /* the megaphone of who called it */+ gfx_text(FONT_SMALL, x + 138, y + 11, g.reported == NONE ? "!" : "!", 0xFFE0, 0, 1, 2);+ }+ if (g.meet_stage == 2) {+ /* who voted for this one */+ int k = 0;+ for (int v = 0; v < g.nplayers; v++)+ if (g.p[v].alive && g.votes[v] == i) art_vote_icon(x + 40 + 11 * k++, y + 19, g.p[v].color, g.opt.anon);+ }+ if (can_vote && sel == i && confirm) {+ gfx_fill(x + 90, y + 3, 44, 20, 0x0000, 200);+ gfx_text(FONT_MID, x + 112, y + 17, "Vote?", 0xFFE0, 0, 0, 1);+ }+ }+ /* skip, and the clock */+ int ys = 26 + 5 * 29;+ art_skip(12, ys, can_vote && sel == SKIP);+ if (can_vote && sel == SKIP && confirm) gfx_text(FONT_MID, 112, ys + 14, "Skip?", 0xFFE0, 0x0000, 1, 0);+ if (g.meet_stage == 2) {+ int k = 0;+ for (int v = 0; v < g.nplayers; v++)+ if (g.p[v].alive && g.votes[v] == SKIP) art_vote_icon(80 + 11 * k++, ys + 9, g.p[v].color, g.opt.anon);+ }+ gfx_text(FONT_MID, 308, ys + 13, stage_text(b, sizeof b), 0xFFFF, 0x0000, 1, 2);+ /* what the others said: the last two lines (Toolbox: more) */+ int shown = g.line_shown ? 6 : 2;+ int y0 = g.line_shown ? 60 : 196;+ if (g.line_shown) gfx_fill(6, y0 - 12, 308, shown * 15 + 6, 0x0000, 220);+ else gfx_fill(6, y0 - 12, 308, 32, 0x0000, 150);+ int first = g.nlines > shown ? g.nlines - shown : 0;+ for (int k = first; k < g.nlines; k++) {+ const Line *l = &g.lines[k];+ int y = y0 + (k - first) * 15;+ const Player *P = &g.p[l->who];+ art_player(P->color, 16, (float)y + 2, 0.45f, false, 256);+ gfx_text(FONT_MID, 26, y, COLOR_NAMES[P->color], 0xFFFF, 0, 0, 0);+ int w = gfx_text_width(FONT_MID, COLOR_NAMES[P->color]);+ gfx_text(FONT_MID, 30 + w, y, line_text(l, b, sizeof b), 0xD69A, 0, 0, 0);+ }+ if (g.meet_stage == 1 && can_vote)+ hud_keys(confirm ? "OK vote Back cancel" : "arrows choose OK vote toolbox chat");+ else+ hud_keys(g.meet_stage == 0 ? "Discuss! toolbox chat" : "toolbox chat");+}diff --git a/games/amongus/src/mg.c b/games/amongus/src/mg.cnew file mode 100644index 00000000..eb88fd75--- /dev/null+++ b/games/amongus/src/mg.c@@ -0,0 +1,66 @@+/* Among Us: the minigames (each task's and each fix's panel), the emergency button and the cameras. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"+#include "gfx.h"+#include "view.h"+#include "world.h"++void hud_keys(const char *s);++typedef struct {+ uint8_t task, kind, done, pad;+ float t, done_t;+} MgHead;+#define MG ((MgHead *)(void *)g.mg)++void mg_open(int cons, int task) {+ memset(g.mg, 0, sizeof g.mg);+ g.mg_cons = (uint8_t)cons;+ MG->task = (uint8_t)task;+ g.overlay = O_TASK;+}++bool mg_blocks_move(void) { return g.overlay != O_NONE; }++void mg_tick(uint32_t keys, uint32_t pressed) {+ MG->t += DT;+ if (g.overlay == O_EMERGENCY) {+ if (pressed & (K_OK | K_EXE)) {+ g.overlay = O_NONE;+ start_meeting(g.me, NONE);+ }+ if (pressed & K_BACK) g.overlay = O_NONE;+ return;+ }+ if (g.overlay == O_CAMS) {+ if (pressed & K_BACK) g.overlay = O_NONE;+ return;+ }+ if (pressed & K_BACK) {+ g.overlay = O_NONE;+ return;+ }+ (void)keys;+ if (pressed & K_OK) {+ if (MG->task < MAX_TASKS) task_step_done(g.me, MG->task);+ g.overlay = O_NONE;+ }+}++void mg_draw(void) {+ view_draw();+ gfx_fill(0, 0, SCREEN_W, SCREEN_H, 0x0000, 120);+ if (g.overlay == O_CAMS) {+ for (int k = 0; k < N_CAMS; k++) {+ int x = 8 + (k & 1) * 156, y = 8 + (k >> 1) * 108;+ view_camera((V2){CAMS[k].x, CAMS[k].y}, 104.0f / (2 * CAMS[k].size), x, y, 148, 104);+ }+ hud_keys("Back close");+ return;+ }+ gfx_fill(60, 40, 200, 150, rgb565(0x404040), 256);+ gfx_text(FONT_BIG, 160, 110, g.overlay == O_EMERGENCY ? "EMERGENCY" : "Task", 0xFFFF, 0, 0, 1);+ hud_keys("OK do it Back close");+}diff --git a/games/amongus/src/plat.h b/games/amongus/src/plat.hnew file mode 100644index 00000000..cdb97bcf--- /dev/null+++ b/games/amongus/src/plat.h@@ -0,0 +1,38 @@+/* Among Us: the platform (the calculator, or a computer for tests).+ *+ * plat_eadk.c: the calculator's EADK display, keyboard, time and files.+ * plat_host.c: a frame buffer that tests save as images, scripted keys and simulated time (tests/play.c). */+#ifndef AU_PLAT_H+#define AU_PLAT_H+#include <stdbool.h>+#include <stddef.h>+#include <stdint.h>++#define SCREEN_W 320+#define SCREEN_H 240++/* keys held now, as bits */+enum {+ K_LEFT = 1 << 0,+ K_RIGHT = 1 << 1,+ K_UP = 1 << 2,+ K_DOWN = 1 << 3,+ K_OK = 1 << 4, /* OK: use, report, vent (the action button) */+ K_EXE = 1 << 5, /* EXE: kill */+ K_BACK = 1 << 6, /* Back: pause, close */+ K_HOME = 1 << 7, /* Home, On/Off: save and quit */+ K_TOOL = 1 << 8, /* Toolbox: the map (the sabotage map for impostors) */+ K_D0 = 1 << 9, /* digits 0-9: K_D0 << n */+ K_ANY = 1u << 31+};+#define K_DIGITS (0x3FFu << 9)+uint32_t plat_keys(void);+uint32_t plat_millis(void);+void plat_sleep(uint32_t ms);+void plat_push(int x, int y, int w, int h, const uint16_t *px);+bool plat_save(const char *name, const void *data, uint32_t len);+const uint8_t *plat_load(const char *name, uint32_t *len); /* NULL if absent */+bool plat_remove(const char *name);+void plat_begin(void);+int plat_end(void);+#endifdiff --git a/games/amongus/src/plat_eadk.c b/games/amongus/src/plat_eadk.cnew file mode 100644index 00000000..8c71881e--- /dev/null+++ b/games/amongus/src/plat_eadk.c@@ -0,0 +1,38 @@+/* The calculator: EADK display, keyboard, time and files. */+#include <eadk.h>+#include "../../common/epsilon_app.h"+#include "../../common/epsilon_files.h"+#include "plat.h"++#define KEY(k) ((uint64_t)1 << (k))++uint32_t plat_keys(void) {+ uint64_t k = eadk_keyboard_scan();+ uint32_t r = 0;+ if (k & KEY(eadk_key_left)) r |= K_LEFT;+ if (k & KEY(eadk_key_right)) r |= K_RIGHT;+ if (k & KEY(eadk_key_up)) r |= K_UP;+ if (k & KEY(eadk_key_down)) r |= K_DOWN;+ if (k & KEY(eadk_key_ok)) r |= K_OK;+ if (k & KEY(eadk_key_exe)) r |= K_EXE;+ if (k & KEY(eadk_key_back)) r |= K_BACK;+ if (k & (KEY(eadk_key_home) | KEY(eadk_key_on_off))) r |= K_HOME;+ if (k & KEY(eadk_key_toolbox)) r |= K_TOOL;+ static const uint8_t digits[10] = {eadk_key_zero, eadk_key_one, eadk_key_two, eadk_key_three, eadk_key_four,+ eadk_key_five, eadk_key_six, eadk_key_seven, eadk_key_eight, eadk_key_nine};+ for (int i = 0; i < 10; i++)+ if (k & KEY(digits[i])) r |= (uint32_t)K_D0 << i;+ if (k) r |= K_ANY;+ return r;+}++uint32_t plat_millis(void) { return (uint32_t)eadk_timing_millis(); }+void plat_sleep(uint32_t ms) { eadk_timing_msleep(ms); }+void plat_push(int x, int y, int w, int h, const uint16_t *px) {+ eadk_display_push_rect((eadk_rect_t){(uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h}, px);+}+bool plat_save(const char *name, const void *data, uint32_t len) { return ef_write(name, data, len); }+const uint8_t *plat_load(const char *name, uint32_t *len) { return ef_read(name, len); }+bool plat_remove(const char *name) { return ef_remove(name); }+void plat_begin(void) { np_app_begin(); }+int plat_end(void) { return np_app_end(); }diff --git a/games/amongus/src/plat_host.c b/games/amongus/src/plat_host.cnew file mode 100644index 00000000..91a01972--- /dev/null+++ b/games/amongus/src/plat_host.c@@ -0,0 +1,70 @@+/* A computer: the screen goes to a frame buffer that tests save as images,+ * keys come from a script, time is simulated. */+#include <stdio.h>+#include <stdlib.h>+#include "plat.h"++uint16_t host_fb[SCREEN_W * SCREEN_H];+uint32_t host_time; /* ms */+uint32_t host_keys;++uint32_t plat_keys(void) { return host_keys; }+uint32_t plat_millis(void) { return host_time; }+void plat_sleep(uint32_t ms) { host_time += ms; }+void plat_push(int x, int y, int w, int h, const uint16_t *px) {+ for (int r = 0; r < h; r++)+ for (int c = 0; c < w; c++)+ if ((unsigned)(x + c) < SCREEN_W && (unsigned)(y + r) < SCREEN_H) host_fb[(y + r) * SCREEN_W + x + c] = px[r * w + c];+}++static char save_dir[256] = "build/host-saves";+void host_save_dir(const char *d) { snprintf(save_dir, sizeof save_dir, "%s", d); }+bool plat_save(const char *name, const void *data, uint32_t len) {+ char p[512];+ snprintf(p, sizeof p, "%s/%s", save_dir, name);+ FILE *f = fopen(p, "wb");+ if (!f) return false;+ bool ok = fwrite(data, 1, len, f) == len;+ fclose(f);+ return ok;+}+/* (each file read gets its own buffer: callers may hold two at once) */+static uint8_t loaded[4][1 << 16];+static int next_load;+const uint8_t *plat_load(const char *name, uint32_t *len) {+ char p[512];+ snprintf(p, sizeof p, "%s/%s", save_dir, name);+ FILE *f = fopen(p, "rb");+ if (!f) return NULL;+ uint8_t *b = loaded[next_load++ & 3];+ *len = (uint32_t)fread(b, 1, sizeof loaded[0], f);+ fclose(f);+ return b;+}+static uint8_t reserved[1 << 16];+uint8_t *plat_reserve(const char *name, uint32_t len) {+ (void)name;+ return len <= sizeof reserved ? reserved : NULL;+}+void plat_reserved(const char *name, uint32_t len) { plat_save(name, reserved, len); }+bool plat_remove(const char *name) {+ char p[512];+ snprintf(p, sizeof p, "%s/%s", save_dir, name);+ return remove(p) == 0;+}+void plat_begin(void) {}+int plat_end(void) { return 0; }+bool plat_slow(void) { return false; }++/* writes the screen as a PPM image */+void host_shot(const char *path) {+ FILE *f = fopen(path, "wb");+ if (!f) return;+ fprintf(f, "P6\n%d %d\n255\n", SCREEN_W, SCREEN_H);+ for (int i = 0; i < SCREEN_W * SCREEN_H; i++) {+ uint16_t c = host_fb[i];+ uint8_t rgb[3] = {(uint8_t)((c >> 11) * 255 / 31), (uint8_t)(((c >> 5) & 63) * 255 / 63), (uint8_t)((c & 31) * 255 / 31)};+ fwrite(rgb, 1, 3, f);+ }+ fclose(f);+}diff --git a/games/amongus/src/play.c b/games/amongus/src/play.cnew file mode 100644index 00000000..4bd04a44--- /dev/null+++ b/games/amongus/src/play.c@@ -0,0 +1,294 @@+/* Among Us: a round on the ship: the player's keys, everyone's moves, doors, sabotage clocks. */+#include <math.h>+#include <string.h>+#include "game.h"+#include "plat.h"+#include "world.h"++/* ---- what the action button would show (HudManager.UseButton / ReportButton / VentButton) ---- */++enum { ACT_NONE, ACT_USE, ACT_REPORT, ACT_VENT, ACT_EMERGENCY, ACT_ADMIN, ACT_CAMS };++static bool in_reach(const Player *P, int c) {+ const ConsoleRec *C = &CONSOLES[c];+ float dx = P->pos.x - C->x, dy = P->pos.y - C->y;+ if (dx * dx + dy * dy > C->dist * C->dist) return false;+ if (C->below && P->pos.y > C->y) return false;+ return true;+}++/* the sabotage this console fixes (0 none) */+static int fixes(int c) {+ const ConsoleRec *C = &CONSOLES[c];+ if (C->kind) return 0;+ if (C->types >> T_RESET_REACTOR & 1) return SAB_REACTOR;+ if (C->types >> T_RESTORE_O2 & 1) return SAB_O2;+ if (C->types >> T_FIX_LIGHTS & 1) return SAB_LIGHTS;+ if (C->types >> T_FIX_COMMS & 1) return SAB_COMMS;+ return 0;+}++/* can player i use console c now: the task it serves (>= 0), MAX_TASKS for a sabotage or a system, -1 no */+int console_use(int i, int c) {+ const Player *P = &g.p[i];+ const ConsoleRec *C = &CONSOLES[c];+ if (!in_reach(P, c)) return -1;+ if (C->kind == 2) return P->alive && P->emergencies > 0 && g.emergency_cd <= 0 && g.sab != SAB_REACTOR &&+ g.sab != SAB_O2+ ? MAX_TASKS+ : -1;+ if (C->kind) return MAX_TASKS;+ int f = fixes(c);+ if (f) {+ if (!P->alive || g.sab != f) return -1;+ if (f == SAB_O2 && (g.o2_done >> (C->room == R_ADMIN ? 0 : 1) & 1)) return -1;+ return MAX_TASKS;+ }+ if (P->imp) return -1;+ for (int k = 0; k < P->ntasks; k++)+ if (console_serves(c, &P->tasks[k]) && !(P->tasks[k].timer > 0)) return k;+ return -1;+}++static int action(int *what) {+ Player *P = &g.p[g.me];+ if (P->vent != NONE) return ACT_VENT;+ if (P->alive) {+ for (int b = 0; b < MAXP; b++) {+ const Body *B = &g.bodies[b];+ if (!B->on) continue;+ float dx = B->pos.x - P->pos.x, dy = B->pos.y - P->pos.y;+ if (dx * dx + dy * dy <= 9.0f && !ship_wall_between(P->pos, B->pos)) {+ *what = b;+ return ACT_REPORT;+ }+ }+ }+ int best = -1;+ float bd = 99;+ for (int c = 0; c < N_CONSOLES; c++) {+ if (console_use(g.me, c) < 0) continue;+ float dx = CONSOLES[c].x - P->pos.x, dy = CONSOLES[c].y - P->pos.y, d = dx * dx + dy * dy;+ if (d < bd) bd = d, best = c;+ }+ if (P->imp && P->alive) {+ int v = nearest_vent(P->pos, 0.75f);+ if (v >= 0) {+ float dx = VENTS[v].x - P->pos.x, dy = VENTS[v].y - P->pos.y;+ if (best < 0 || dx * dx + dy * dy < bd) {+ *what = v;+ return ACT_VENT;+ }+ }+ }+ if (best < 0) return ACT_NONE;+ *what = best;+ switch (CONSOLES[best].kind) {+ case 1: return ACT_ADMIN;+ case 2: return ACT_EMERGENCY;+ case 3: return ACT_CAMS;+ default: return ACT_USE;+ }+}++int hud_action(int *what) { return action(what); }++/* the crewmate the impostor would kill (PlayerControl.FindClosestTarget) */+int kill_target(int i) {+ const Player *P = &g.p[i];+ if (!P->imp || !P->alive || P->vent != NONE) return -1;+ float r = kill_distance(), bd = r * r;+ int best = -1;+ for (int j = 0; j < g.nplayers; j++) {+ const Player *Q = &g.p[j];+ if (j == i || !Q->alive || Q->imp || Q->vent != NONE) continue;+ float dx = Q->pos.x - P->pos.x, dy = Q->pos.y - P->pos.y, d = dx * dx + dy * dy;+ if (d < bd && !ship_wall_between(P->pos, Q->pos)) bd = d, best = j;+ }+ return best;+}++/* ---- moving ---- */++void walk(int i, V2 dir) {+ Player *P = &g.p[i];+ float l = sqrtf(dir.x * dir.x + dir.y * dir.y);+ if (l < 1e-4f || P->vent != NONE || P->vent_anim) {+ P->vel = (V2){0, 0};+ P->walking = 0;+ return;+ }+ float s = player_speed(i) * DT / l;+ V2 d = {dir.x * s, dir.y * s};+ if (P->alive) P->pos = ship_move(P->pos, d, PLAYER_R);+ else {+ P->pos.x += d.x, P->pos.y += d.y;+ if (P->pos.x < -26) P->pos.x = -26;+ if (P->pos.x > 21) P->pos.x = 21;+ if (P->pos.y < -20) P->pos.y = -20;+ if (P->pos.y > 8) P->pos.y = 8;+ }+ P->vel = d;+ P->walking = 1;+ if (d.x < -1e-4f) P->flip = 1;+ if (d.x > 1e-4f) P->flip = 0;+}++/* ---- the world's clocks ---- */++static void world_tick(void) {+ g.t += DT;+ for (int d = 0; d < N_DOORS; d++) {+ if (g.door_t[d] > 0) {+ g.door_t[d] -= DT;+ if (g.door_t[d] <= 0) g.door_anim[d] = 0;+ }+ g.door_anim[d] += DT;+ }+ for (int r = 0; r < N_ROOMS; r++)+ if (g.door_cd[r] > 0) g.door_cd[r] -= DT;+ if (g.emergency_cd > 0) g.emergency_cd -= DT;+ if (g.sab == SAB_NONE && g.sab_cd > 0) g.sab_cd -= DT;+ /* lights: the switches' value moves the light (SwitchSystem: 255 to 0 over about a second) */+ bool dark = g.sab == SAB_LIGHTS;+ g.light += dark ? -DT : DT;+ if (g.light < 0) g.light = 0;+ if (g.light > 1) g.light = 1;+ if (g.sab == SAB_LIGHTS && g.switches == 0x1F) fix_sabotage();+ if (g.sab == SAB_REACTOR || g.sab == SAB_O2) {+ if (g.sab == SAB_REACTOR && g.reactor_hold[0] != NONE && g.reactor_hold[1] != NONE &&+ g.reactor_hold[0] != g.reactor_hold[1])+ fix_sabotage();+ else if (g.sab == SAB_O2 && g.o2_done == 3)+ fix_sabotage();+ else {+ g.sab_t -= DT;+ if (g.sab_t <= 0) {+ g.winner = 1;+ g.end_reason = 3;+ g.screen = S_END;+ g.screen_t = 0;+ g.overlay = O_NONE;+ return;+ }+ }+ }+ g.reactor_hold[0] = g.reactor_hold[1] = NONE;+ for (int i = 0; i < g.nplayers; i++) {+ Player *P = &g.p[i];+ if (P->imp && P->alive && P->kill_cd > 0) P->kill_cd -= DT;+ for (int k = 0; k < P->ntasks; k++)+ if (P->tasks[k].timer > 0) {+ P->tasks[k].timer -= DT;+ if (P->tasks[k].timer < 0) P->tasks[k].timer = 0;+ }+ /* the vent jump's frames (EnterVent 0.375 s, ExitVent 0.54 s) */+ if (P->vent_anim) {+ P->anim_t += DT;+ if (P->vent_anim == 1 && P->anim_t >= 0.375f) P->vent_anim = 0;+ else if (P->vent_anim == 2 && P->anim_t >= 0.54f) {+ P->vent_anim = 0;+ P->vent = NONE;+ }+ } else if (P->walking) P->anim_t += DT;+ else P->anim_t = 0;+ P->room = (uint8_t)ship_room_at(P->pos);+ }+}++/* ---- the player's turn ---- */++static uint32_t vent_key_dir(uint32_t pressed, int v) {+ /* the arrow nearest the direction to each linked vent */+ float kx = (pressed & K_RIGHT) ? 1 : (pressed & K_LEFT) ? -1 : 0;+ float ky = (pressed & K_UP) ? 1 : (pressed & K_DOWN) ? -1 : 0;+ if (!kx && !ky) return NONE;+ int best = NONE;+ float bd = 0.3f;+ for (int k = 0; k < 3; k++) {+ int w = VENTS[v].link[k];+ if (w < 0) continue;+ float dx = VENTS[w].x - VENTS[v].x, dy = VENTS[w].y - VENTS[v].y, l = sqrtf(dx * dx + dy * dy);+ float dot = (dx * kx + dy * ky) / l / sqrtf(kx * kx + ky * ky);+ if (dot > bd) bd = dot, best = w;+ }+ return (uint32_t)best;+}++static void do_action(void) {+ int what = -1;+ int a = action(&what);+ Player *P = &g.p[g.me];+ switch (a) {+ case ACT_REPORT:+ start_meeting(g.me, g.bodies[what].who);+ break;+ case ACT_VENT:+ if (P->vent != NONE) exit_vent(g.me);+ else enter_vent(g.me, what);+ break;+ case ACT_EMERGENCY:+ g.overlay = O_EMERGENCY;+ g.mg_cons = (uint8_t)what;+ memset(g.mg, 0, sizeof g.mg);+ break;+ case ACT_ADMIN:+ g.overlay = O_ADMIN;+ break;+ case ACT_CAMS:+ g.overlay = O_CAMS;+ memset(g.mg, 0, sizeof g.mg);+ break;+ case ACT_USE:+ mg_open(what, console_use(g.me, what));+ break;+ default:+ break;+ }+}++void play_tick(uint32_t keys, uint32_t pressed) {+ Player *P = &g.p[g.me];+ bool human = g.screen == S_PLAY;+ if (!human) walk(g.me, (V2){0, 0});+ else if (g.overlay == O_NONE) {+ V2 dir = {0, 0};+ if (keys & K_LEFT) dir.x -= 1;+ if (keys & K_RIGHT) dir.x += 1;+ if (keys & K_UP) dir.y += 1;+ if (keys & K_DOWN) dir.y -= 1;+ if (P->vent != NONE && !P->vent_anim) {+ uint32_t w = vent_key_dir(pressed, P->vent);+ if (w != NONE) move_vent(g.me, (int)w);+ dir = (V2){0, 0};+ }+ walk(g.me, dir);+ if (pressed & K_OK) do_action();+ if ((pressed & K_EXE) && P->kill_cd <= 0) {+ int t = kill_target(g.me);+ if (t >= 0) kill_player(g.me, t);+ }+ if (pressed & K_TOOL) {+ g.overlay = P->imp ? O_SABMAP : O_MAP;+ g.sel = 0;+ }+ if (pressed & K_BACK) {+ g.back_screen = S_PLAY;+ g.screen = S_PAUSE;+ g.sel = 0;+ return;+ }+ } else {+ walk(g.me, (V2){0, 0});+ if (g.overlay == O_TASK || g.overlay == O_EMERGENCY || g.overlay == O_CAMS) mg_tick(keys, pressed);+ else map_tick(pressed, g.overlay);+ }+ int screen = g.screen;+ if (screen != S_PLAY && screen != S_KILLED) return;+ for (int i = 0; i < g.nplayers; i++)+ if (i != g.me) bot_tick(i);+ if (g.screen != screen) return;+ world_tick();+ /* bodies a crewmate bot sees */+ check_win();+}diff --git a/games/amongus/src/res.c b/games/amongus/src/res.cnew file mode 100644index 00000000..646e2873--- /dev/null+++ b/games/amongus/src/res.c@@ -0,0 +1,13 @@+/* Among Us: the pictures, fonts and tiles in data.bin: "AUSD", the counts, then where each one starts. */+#include "res.h"++static uint32_t rd32(const uint8_t *p) { return p[0] | p[1] << 8 | p[2] << 16 | (uint32_t)p[3] << 24; }++const void *blob(int id) { return au_data + rd32(au_data + 16 + 4 * id); }++const Pic *pic(int id) {+ if (id < 0 || id >= N_PICS) return 0;+ return (const Pic *)blob(id);+}++const Font *font(int id) { return (const Font *)blob(N_PICS + id); }diff --git a/games/amongus/src/res.h b/games/amongus/src/res.hnew file mode 100644index 00000000..5a1d9a15--- /dev/null+++ b/games/amongus/src/res.h@@ -0,0 +1,55 @@+/* Among Us: the pictures, fonts and the ship's tiles in data.bin (tools/pack.py). */+#ifndef AU_RES_H+#define AU_RES_H+#include <stdint.h>+#include "data.h"++extern const uint8_t au_data[];++/* a picture: its colours (RGB565, then alpha 0-255), then a byte a pixel, or two (P_4BIT, high bits first).+ * P_MIX pictures (the players) have no colours of their own: their bytes index the mix table, coloured per player. */+typedef struct {+ uint16_t w, h;+ int16_t ox, oy; /* its pivot, from the top-left */+ uint8_t ncolors, flags;+ uint16_t pad;+} Pic;+enum { P_4BIT = 1, P_OPAQUE = 2, P_MIX = 4 };++const Pic *pic(int id);+const void *blob(int id);+static inline const uint16_t *pic_pal(const Pic *p) { return (const uint16_t *)(const void *)(p + 1); }+static inline const uint8_t *pic_alpha(const Pic *p) { return (const uint8_t *)(pic_pal(p) + p->ncolors); }+static inline const uint8_t *pic_px(const Pic *p) {+ if (p->flags & P_MIX) return (const uint8_t *)(p + 1);+ int n = p->ncolors ? p->ncolors : 256;+ uintptr_t a = (uintptr_t)((const uint8_t *)(pic_pal(p) + n) + n);+ return (const uint8_t *)((a + 3) & ~(uintptr_t)3);+}+static inline int pic_ncolors(const Pic *p) { return p->ncolors ? p->ncolors : 256; }++typedef struct {+ uint8_t w, h;+ int8_t x, y; /* from the pen; y from the baseline */+ uint8_t adv, pad0;+ uint16_t pad1;+ uint32_t off; /* 4-bit coverage, two pixels a byte */+} Glyph;+typedef struct {+ uint8_t first, count, height, ascent;+} Font;+const Font *font(int id);+static inline const Glyph *font_glyphs(const Font *f) { return (const Glyph *)(const void *)(f + 1); }+static inline const uint8_t *font_bits(const Font *f) { return (const uint8_t *)(font_glyphs(f) + f->count); }++/* the ship's floor: tw x th tiles of 16x16, a tile number each (0xFFFF: space), each tile 16 colours and 4-bit+ * pixels */+typedef struct {+ uint16_t tw, th;+ uint32_t ntiles, tiles_off;+} ShipTiles;+static inline const uint16_t *ship_map(const ShipTiles *s) { return (const uint16_t *)(const void *)(s + 1); }+static inline const uint8_t *ship_tile(const ShipTiles *s, int t) {+ return (const uint8_t *)s + s->tiles_off + (uint32_t)t * 160;+}+#endifdiff --git a/games/amongus/src/screens.c b/games/amongus/src/screens.cnew file mode 100644index 00000000..998bc26a--- /dev/null+++ b/games/amongus/src/screens.c@@ -0,0 +1,408 @@+/* Among Us: the screens around a round: the title, the lobby's settings, the intro, pause, How to Play, the+ * kill, the report, the ejection and the end. And game_tick / game_draw, which hand each screen its turn. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"+#include "gfx.h"+#include "plat.h"+#include "view.h"+#include "world.h"++bool game_running = true;+static uint32_t last_keys;+void play_tick(uint32_t keys, uint32_t pressed);+void hud_keys(const char *s);+void game_forget(void);+void view_prepare(void);+void art_title(void);+void art_kill(float t);+void art_report(float t);+void art_eject(float t);+void art_stars(float t, float speed);+void art_player(int color, float x, float y, float scale, bool flip, int alpha);+void art_lineup(const uint8_t *who, int n, float t);++#define WHITE 0xFFFF+#define CREW_BLUE 0x8EFF+#define IMP_RED 0xF800++/* ---- the lobby's settings (GameOptionsMenu) ---- */++enum {+ OPT_BOTS, OPT_ROLE, OPT_COLOR, OPT_IMPS, OPT_CONFIRM, OPT_MEETINGS, OPT_ANON, OPT_MEETCD, OPT_DISCUSS, OPT_VOTE,+ OPT_SPEED, OPT_CREWV, OPT_IMPV, OPT_KILLCD, OPT_KILLD, OPT_TASKBAR, OPT_VISUAL, OPT_COMMON, OPT_LONG, OPT_SHORT,+ N_OPT+};+static const char *const OPT_NAMES[N_OPT] = {+ "Bots", "Your Role", "Your Color", "# Impostors", "Confirm Ejects",+ "# Emergency Meetings", "Anonymous Votes", "Emergency Cooldown", "Discussion Time", "Voting Time",+ "Player Speed", "Crewmate Vision", "Impostor Vision", "Kill Cooldown", "Kill Distance",+ "Task Bar Updates", "Visual Tasks", "# Common Tasks", "# Long Tasks", "# Short Tasks"};++static void opt_value(int k, char *b, int n) {+ const Options *o = &g.opt;+ switch (k) {+ case OPT_BOTS: snprintf(b, (size_t)n, "%d", o->bots); break;+ case OPT_ROLE: snprintf(b, (size_t)n, "%s", o->role == 0 ? "Random" : o->role == 1 ? "Crewmate" : "Impostor"); break;+ case OPT_COLOR: snprintf(b, (size_t)n, "%s", COLOR_NAMES[o->color]); break;+ case OPT_IMPS: snprintf(b, (size_t)n, "%d", o->impostors); break;+ case OPT_CONFIRM: snprintf(b, (size_t)n, "%s", o->confirm ? "On" : "Off"); break;+ case OPT_MEETINGS: snprintf(b, (size_t)n, "%d", o->meetings); break;+ case OPT_ANON: snprintf(b, (size_t)n, "%s", o->anon ? "On" : "Off"); break;+ case OPT_MEETCD: snprintf(b, (size_t)n, "%ds", o->meet_cd); break;+ case OPT_DISCUSS: snprintf(b, (size_t)n, "%ds", o->discuss); break;+ case OPT_VOTE: snprintf(b, (size_t)n, "%ds", o->vote * 5); break;+ case OPT_SPEED: snprintf(b, (size_t)n, "%d.%02dx", o->speed / 4, o->speed % 4 * 25); break;+ case OPT_CREWV: snprintf(b, (size_t)n, "%d.%02dx", o->crew_vision / 4, o->crew_vision % 4 * 25); break;+ case OPT_IMPV: snprintf(b, (size_t)n, "%d.%02dx", o->imp_vision / 4, o->imp_vision % 4 * 25); break;+ case OPT_KILLCD: snprintf(b, (size_t)n, o->kill_cd & 1 ? "%d.5s" : "%ds", o->kill_cd / 2); break;+ case OPT_KILLD: snprintf(b, (size_t)n, "%s", o->kill_dist == 0 ? "Short" : o->kill_dist == 1 ? "Medium" : "Long"); break;+ case OPT_TASKBAR:+ snprintf(b, (size_t)n, "%s", o->taskbar == 0 ? "Always" : o->taskbar == 1 ? "Meetings" : "Never");+ break;+ case OPT_VISUAL: snprintf(b, (size_t)n, "%s", o->visual ? "On" : "Off"); break;+ case OPT_COMMON: snprintf(b, (size_t)n, "%d", o->common); break;+ case OPT_LONG: snprintf(b, (size_t)n, "%d", o->longt); break;+ case OPT_SHORT: snprintf(b, (size_t)n, "%d", o->shortt); break;+ }+}++static int clampi(int v, int lo, int hi) { return v < lo ? lo : v > hi ? hi : v; }++static void opt_change(int k, int d) {+ Options *o = &g.opt;+ switch (k) {+ case OPT_BOTS: o->bots = (uint8_t)clampi(o->bots + d, 3, 9); break;+ case OPT_ROLE: o->role = (uint8_t)((o->role + 3 + d) % 3); break;+ case OPT_COLOR: o->color = (uint8_t)((o->color + N_COLORS + d) % N_COLORS); break;+ case OPT_IMPS: o->impostors = (uint8_t)clampi(o->impostors + d, 1, 3); break;+ case OPT_CONFIRM: o->confirm ^= 1; break;+ case OPT_MEETINGS: o->meetings = (uint8_t)clampi(o->meetings + d, 0, 9); break;+ case OPT_ANON: o->anon ^= 1; break;+ case OPT_MEETCD: o->meet_cd = (uint8_t)clampi(o->meet_cd + 5 * d, 0, 60); break;+ case OPT_DISCUSS: o->discuss = (uint8_t)clampi(o->discuss + 15 * d, 0, 120); break;+ case OPT_VOTE: o->vote = (uint8_t)clampi(o->vote + 3 * d, 3, 60); break;+ case OPT_SPEED: o->speed = (uint8_t)clampi(o->speed + d, 2, 12); break;+ case OPT_CREWV: o->crew_vision = (uint8_t)clampi(o->crew_vision + d, 1, 20); break;+ case OPT_IMPV: o->imp_vision = (uint8_t)clampi(o->imp_vision + d, 1, 20); break;+ case OPT_KILLCD: o->kill_cd = (uint8_t)clampi(o->kill_cd + 5 * d, 20, 120); break;+ case OPT_KILLD: o->kill_dist = (uint8_t)clampi(o->kill_dist + d, 0, 2); break;+ case OPT_TASKBAR: o->taskbar = (uint8_t)((o->taskbar + 3 + d) % 3); break;+ case OPT_VISUAL: o->visual ^= 1; break;+ case OPT_COMMON: o->common = (uint8_t)clampi(o->common + d, 0, 2); break;+ case OPT_LONG: o->longt = (uint8_t)clampi(o->longt + d, 0, 3); break;+ case OPT_SHORT: o->shortt = (uint8_t)clampi(o->shortt + d, 0, 5); break;+ }+ if (o->common + o->longt + o->shortt == 0) o->shortt = 1;+}++static int lobby_top;++static void lobby_tick(uint32_t pressed) {+ int n = N_OPT + 1; /* the settings, then Start */+ if (pressed & K_UP) g.sel = (uint8_t)((g.sel + n - 1) % n);+ if (pressed & K_DOWN) g.sel = (uint8_t)((g.sel + 1) % n);+ if (g.sel < N_OPT) {+ if (pressed & K_LEFT) opt_change(g.sel, -1);+ if (pressed & K_RIGHT) opt_change(g.sel, 1);+ }+ if ((pressed & (K_OK | K_EXE)) && g.sel == N_OPT) {+ settings_save();+ game_new();+ return;+ }+ if ((pressed & (K_OK | K_EXE)) && g.sel < N_OPT) opt_change(g.sel, 1);+ if (pressed & K_BACK) {+ settings_save();+ g.screen = S_TITLE;+ g.sel = 0;+ }+ if (g.sel < lobby_top) lobby_top = g.sel;+ if (g.sel >= lobby_top + 9) lobby_top = g.sel - 8;+}++static void lobby_draw(void) {+ art_stars(g.screen_t, 0.3f);+ gfx_fill(30, 8, 260, 216, rgb565(0x0E1A2B), 230);+ gfx_rect(30, 8, 260, 216, 2, rgb565(0x9AB3C9));+ gfx_text(FONT_BIG, 160, 28, "Game Settings", WHITE, 0, 0, 1);+ gfx_text(FONT_SMALL, 160, 41, "Map: The Skeld", rgb565(0x9AB3C9), 0, 0, 1);+ char b[24];+ for (int r = 0; r < 9; r++) {+ int k = lobby_top + r;+ int y = 48 + r * 17;+ if (k == N_OPT) {+ bool s = g.sel == N_OPT;+ gfx_fill(110, y + 1, 100, 15, s ? rgb565(0x44D844) : rgb565(0x23452A), 256);+ gfx_rect(110, y + 1, 100, 15, 1, WHITE);+ gfx_text(FONT_MID, 160, y + 13, "Start", WHITE, 0, 0, 1);+ break;+ }+ bool s = g.sel == k;+ if (s) gfx_fill(36, y, 248, 17, rgb565(0x2D4F73), 256);+ gfx_text(FONT_MID, 42, y + 13, OPT_NAMES[k], WHITE, 0, 0, 0);+ opt_value(k, b, sizeof b);+ gfx_fill(206, y + 2, 72, 13, 0x0000, 160);+ gfx_text(FONT_MID, 242, y + 13, b, s ? 0xFFE0 : WHITE, 0, 0, 1);+ if (s) {+ gfx_text(FONT_MID, 199, y + 13, "<", 0xFFE0, 0, 0, 1);+ gfx_text(FONT_MID, 284, y + 13, ">", 0xFFE0, 0, 0, 1);+ }+ }+ hud_keys(g.sel < N_OPT ? "up down choose left right change Back title" : "OK start up down settings Back title");+}++/* ---- the title (MainMenu) ---- */++static void title_tick(uint32_t pressed) {+ if (pressed & K_UP) g.sel = (uint8_t)((g.sel + 1) % 2);+ if (pressed & K_DOWN) g.sel = (uint8_t)((g.sel + 1) % 2);+ if (pressed & (K_OK | K_EXE)) {+ if (g.sel == 0) g.screen = S_LOBBY, g.sel = N_OPT, lobby_top = N_OPT - 8;+ else g.screen = S_HOWTO, g.back_screen = S_TITLE, g.sel = 0;+ g.screen_t = 0;+ }+ if (pressed & K_BACK) game_running = false;+}++static void menu_button(int y, const char *s, bool on) {+ gfx_fill(100, y, 120, 22, on ? WHITE : 0x0000, on ? 256 : 150);+ gfx_rect(100, y, 120, 22, 2, WHITE);+ gfx_text(FONT_BIG, 160, y + 16, s, on ? 0x0000 : WHITE, 0, 0, 1);+}++static void title_draw(void) {+ art_title();+ menu_button(150, "Play", g.sel == 0);+ menu_button(178, "How to Play", g.sel == 1);+ hud_keys("up down choose OK go Back quit");+}++/* ---- How to Play ---- */++static const char *const HOWTO[][6] = {+ {"Crewmates", "Do your tasks around the ship.", "Find the Impostor and vote them out.",+ "The task bar fills as tasks get done.", "Report a body or press the button to meet.", NULL},+ {"Impostors", "Kill the crewmates, one at a time.", "Sabotage the ship and use the vents.",+ "Fake tasks and don't get caught.", "Win when the crew is as few as you.", NULL},+ {"Keys", "Arrows: walk", "OK: use, report, vent", "EXE: kill", "Toolbox: map or sabotage", "Back: pause Home: save and quit"},+};++static void howto_tick(uint32_t pressed) {+ if (pressed & (K_RIGHT | K_OK | K_EXE)) {+ if (g.sel < 2) g.sel++;+ else g.screen = g.back_screen, g.sel = 0;+ }+ if ((pressed & K_LEFT) && g.sel) g.sel--;+ if (pressed & K_BACK) g.screen = g.back_screen, g.sel = 0;+}++static void howto_draw(void) {+ art_stars(g.t + g.screen_t, 0.3f);+ gfx_fill(20, 20, 280, 190, rgb565(0x0E1A2B), 230);+ gfx_rect(20, 20, 280, 190, 2, rgb565(0x9AB3C9));+ const char *const *p = HOWTO[g.sel];+ gfx_text(FONT_HUGE, 160, 56, p[0], g.sel == 1 ? IMP_RED : CREW_BLUE, 0, 0, 1);+ for (int k = 1; k < 6 && p[k]; k++) gfx_text(FONT_MID, 160, 74 + 22 * k, p[k], WHITE, 0, 0, 1);+ char b[16];+ snprintf(b, sizeof b, "%d/3", g.sel + 1);+ gfx_text(FONT_SMALL, 160, 202, b, rgb565(0x9AB3C9), 0, 0, 1);+ hud_keys("OK next left back a page Back close");+}++/* ---- pause ---- */++static void pause_tick(uint32_t pressed) {+ if (g.sel >= 10) {+ /* "Quit the game?" */+ if (pressed & (K_LEFT | K_RIGHT | K_UP | K_DOWN)) g.sel ^= 1;+ if (pressed & (K_OK | K_EXE)) {+ if (g.sel == 10) {+ game_forget();+ g.screen = S_TITLE, g.sel = 0;+ } else+ g.sel = 2;+ }+ if (pressed & K_BACK) g.sel = 2;+ return;+ }+ if (pressed & K_UP) g.sel = (uint8_t)((g.sel + 2) % 3);+ if (pressed & K_DOWN) g.sel = (uint8_t)((g.sel + 1) % 3);+ if (pressed & (K_OK | K_EXE)) {+ if (g.sel == 0) g.screen = g.back_screen;+ else if (g.sel == 1) g.screen = S_HOWTO, g.sel = 0;+ else g.sel = 11;+ }+ if (pressed & K_BACK) g.screen = g.back_screen;+}++static void pause_draw(void) {+ /* the round behind it, darker */+ if (g.back_screen == S_PLAY) {+ view_draw();+ gfx_fill(0, 0, SCREEN_W, SCREEN_H, 0x0000, 150);+ } else art_stars(g.t, 0.3f);+ if (g.sel >= 10) {+ gfx_fill(60, 80, 200, 80, rgb565(0x0E1A2B), 240);+ gfx_rect(60, 80, 200, 80, 2, WHITE);+ gfx_text(FONT_BIG, 160, 108, "Quit the game?", WHITE, 0, 0, 1);+ for (int k = 0; k < 2; k++) {+ bool on = g.sel == 10 + k;+ gfx_fill(80 + k * 90, 122, 70, 22, on ? WHITE : 0x0000, on ? 256 : 150);+ gfx_rect(80 + k * 90, 122, 70, 22, 2, WHITE);+ gfx_text(FONT_BIG, 115 + k * 90, 138, k ? "No" : "Yes", on ? 0x0000 : WHITE, 0, 0, 1);+ }+ hud_keys("left right choose OK confirm Back no");+ return;+ }+ gfx_text(FONT_HUGE, 160, 70, "Paused", WHITE, 0x0000, 1, 1);+ menu_button(92, "Resume", g.sel == 0);+ menu_button(120, "How to Play", g.sel == 1);+ menu_button(148, "Quit game", g.sel == 2);+ hud_keys("up down choose OK go Back resume Home save and quit");+}++/* ---- the round's own screens ---- */++static void intro_draw(void) {+ float t = g.screen_t;+ art_stars(0, 0);+ if (t < 1.6f) {+ /* "Shhhhhh!" */+ gfx_text(FONT_HUGE, 160, 130, "Shhhhhh!", IMP_RED, 0x0000, 2, 1);+ return;+ }+ const Player *M = &g.p[g.me];+ uint8_t who[MAXP];+ int n = 0;+ who[n++] = (uint8_t)g.me;+ for (int i = 0; i < g.nplayers; i++)+ if (i != g.me && (!M->imp || g.p[i].imp)) who[n++] = (uint8_t)i;+ art_lineup(who, n, t - 1.6f);+ if (M->imp) {+ gfx_text(FONT_HUGE, 160, 52, "Impostor", IMP_RED, 0x0000, 2, 1);+ } else {+ gfx_text(FONT_HUGE, 160, 52, "Crewmate", CREW_BLUE, 0x0000, 2, 1);+ int k = 0;+ for (int i = 0; i < g.nplayers; i++) k += g.p[i].imp;+ char b[48];+ snprintf(b, sizeof b, "There %s %d Impostor%s among us", k == 1 ? "is" : "are", k, k == 1 ? "" : "s");+ gfx_text(FONT_MID, 160, 74, b, WHITE, 0x0000, 1, 1);+ }+}++static void end_draw(void) {+ art_stars(0, 0);+ const Player *M = &g.p[g.me];+ bool won = (g.winner == 1) == (M->imp != 0);+ uint8_t who[MAXP];+ int n = 0;+ for (int i = 0; i < g.nplayers; i++)+ if ((g.p[i].imp != 0) == (g.winner == 1)) who[n++] = (uint8_t)i;+ art_lineup(who, n, g.screen_t);+ gfx_text(FONT_HUGE, 160, 52, won ? "Victory" : "Defeat", won ? CREW_BLUE : IMP_RED, 0x0000, 2, 1);+ static const char *const WHY[2][4] = {{"Crewmates voted out the Impostors", "", "Crewmates finished their tasks", ""},+ {"", "Impostors killed the crew", "", "Impostors sabotaged the ship"}};+ const char *why = WHY[g.winner & 1][g.end_reason & 3];+ if (*why) gfx_text(FONT_MID, 160, 74, why, WHITE, 0x0000, 1, 1);+ if (g.screen_t > 2) hud_keys("OK play again Back title");+}++/* ---- the turn and the drawing ---- */++void game_tick(uint32_t keys) {+ uint32_t pressed = keys & ~last_keys;+ last_keys = keys;+ if (pressed & K_HOME) {+ /* save and quit, from anywhere */+ if (g.screen == S_TITLE || g.screen == S_LOBBY || g.screen == S_END || g.screen == S_HOWTO) settings_save();+ else game_save();+ game_running = false;+ return;+ }+ g.screen_t += DT;+ switch (g.screen) {+ case S_TITLE: title_tick(pressed); break;+ case S_LOBBY: lobby_tick(pressed); break;+ case S_HOWTO: howto_tick(pressed); break;+ case S_PAUSE: pause_tick(pressed); break;+ case S_INTRO:+ if (g.screen_t > 6.5f || (g.screen_t > 2 && (pressed & (K_OK | K_EXE)))) g.screen = S_PLAY, g.screen_t = 0;+ break;+ case S_PLAY: {+ int was = g.p[g.me].room;+ play_tick(keys, pressed);+ /* the room's name when entering one */+ if (g.p[g.me].room != was || g.room_t <= -1) g.room_shown = g.p[g.me].room, g.room_t = 2.5f;+ if (g.room_t > 0) g.room_t -= DT;+ /* the camera (FollowerCamera: a lerp at 5 a second) */+ V2 to = {g.p[g.me].pos.x, g.p[g.me].pos.y + FEET_Y};+ g.cam.x += (to.x - g.cam.x) * (5 * DT), g.cam.y += (to.y - g.cam.y) * (5 * DT);+ /* now and then: saved */+ if ((int)(g.t * 30) % (30 * 60) == 0 && g.t > 1) game_save();+ break;+ }+ case S_KILLED:+ /* the round goes on meanwhile */+ play_tick(0, 0);+ if (g.screen == S_KILLED && g.screen_t > 2.6f) g.screen = S_PLAY, g.screen_t = 0;+ break;+ case S_REPORT:+ if (g.screen_t > 2.5f) {+ g.screen = S_MEETING;+ g.screen_t = 0;+ g.meet_stage = 0;+ g.meet_t = 0;+ memset(g.votes, NONE, sizeof g.votes);+ g.sel = 0;+ bot_meeting_start();+ }+ break;+ case S_MEETING: meeting_tick(keys, pressed); break;+ case S_EJECT:+ if (g.screen_t > 7.5f) {+ g.screen = S_PLAY;+ g.screen_t = 0;+ check_win();+ }+ break;+ case S_END:+ if (g.screen_t > 2 && (pressed & (K_OK | K_EXE))) g.screen = S_LOBBY, g.sel = N_OPT, lobby_top = N_OPT - 8, game_forget();+ else if (g.screen_t > 2 && (pressed & K_BACK)) g.screen = S_TITLE, g.sel = 0, game_forget();+ break;+ }+}++static void draw_band(void) {+ switch (g.screen) {+ case S_TITLE: title_draw(); break;+ case S_LOBBY: lobby_draw(); break;+ case S_HOWTO: howto_draw(); break;+ case S_PAUSE: pause_draw(); break;+ case S_INTRO: intro_draw(); break;+ case S_PLAY:+ view_draw();+ if (g.overlay == O_NONE) hud_draw();+ else if (g.overlay == O_TASK || g.overlay == O_EMERGENCY || g.overlay == O_CAMS) mg_draw();+ else map_draw(g.overlay);+ break;+ case S_KILLED:+ view_draw();+ art_kill(g.screen_t);+ break;+ case S_REPORT:+ view_draw();+ art_report(g.screen_t);+ break;+ case S_MEETING: meeting_draw(); break;+ case S_EJECT: art_eject(g.screen_t); break;+ case S_END: end_draw(); break;+ }+}++void game_draw(void) {+ if (g.screen == S_PLAY || g.screen == S_KILLED || g.screen == S_REPORT || (g.screen == S_PAUSE && g.back_screen == S_PLAY))+ view_prepare();+ gfx_frame(draw_band);+}diff --git a/games/amongus/src/ship.c b/games/amongus/src/ship.cnew file mode 100644index 00000000..a9db84f5--- /dev/null+++ b/games/amongus/src/ship.c@@ -0,0 +1,247 @@+/* Among Us: the Skeld's walls, light walls, rooms and the vision polygon (see ship.h). */+#include <math.h>+#include <string.h>+#include "ship.h"+#include "world.h"++const char *const ROOM_NAMES[N_ROOMS] = {"Hallway", "Storage", "Cafeteria", "Reactor", "Upper Engine",+ "Navigation", "Admin", "Electrical", "O2", "Shields",+ "MedBay", "Security", "Weapons", "Lower Engine", "Communications"};++/* segments already looked at in this query (a query number per segment) */+static uint16_t stamp_w[N_WALL], stamp_s[N_SHADOW];+static uint16_t query;++void ship_init(void) {+ memset(stamp_w, 0, sizeof stamp_w);+ memset(stamp_s, 0, sizeof stamp_s);+ query = 0;+}++static void next_query(void) {+ if (++query == 0) {+ memset(stamp_w, 0, sizeof stamp_w);+ memset(stamp_s, 0, sizeof stamp_s);+ query = 1;+ }+}++static inline int cell_of(float x, float y) {+ int cx = (int)floorf(x - GRID_X0), cy = (int)floorf(y - GRID_Y0);+ if (cx < 0 || cy < 0 || cx >= GRID_W || cy >= GRID_H) return -1;+ return cy * GRID_W + cx;+}++static V2 closest(V2 p, const Seg *s) {+ float ax = s->x0, ay = s->y0, bx = s->x1 - ax, by = s->y1 - ay;+ float l = bx * bx + by * by, t = l > 0 ? ((p.x - ax) * bx + (p.y - ay) * by) / l : 0;+ if (t < 0) t = 0;+ if (t > 1) t = 1;+ return (V2){ax + bx * t, ay + by * t};+}++static void push_out(V2 *p, const Seg *s, float r) {+ V2 q = closest(*p, s);+ float dx = p->x - q.x, dy = p->y - q.y, d2 = dx * dx + dy * dy;+ if (d2 >= r * r) return;+ float d = sqrtf(d2);+ if (d < 1e-5f) {+ /* on the line: out along its normal */+ float nx = -(s->y1 - s->y0), ny = s->x1 - s->x0, l = sqrtf(nx * nx + ny * ny);+ if (l < 1e-6f) return;+ p->x += nx / l * r, p->y += ny / l * r;+ return;+ }+ p->x += dx / d * (r - d), p->y += dy / d * (r - d);+}++V2 ship_move(V2 p, V2 d, float r) {+ float len = sqrtf(d.x * d.x + d.y * d.y);+ int steps = (int)(len / (r * 0.5f)) + 1;+ for (int k = 0; k < steps; k++) {+ p.x += d.x / steps, p.y += d.y / steps;+ for (int it = 0; it < 3; it++) {+ int c = cell_of(p.x, p.y);+ if (c >= 0)+ for (int i = WALL_START[c]; i < WALL_START[c + 1]; i++) push_out(&p, &WALL_SEGS[WALL_IDX[i]], r);+ for (int dd = 0; dd < N_DOORS; dd++) {+ if (!door_closed(dd)) continue;+ const DoorRec *D = &DOORS[dd];+ if (fabsf(p.x - D->x) > 2 || fabsf(p.y - D->y) > 2) continue;+ for (int s = 0; s < 4; s++) push_out(&p, &D->seg[s], r);+ }+ }+ }+ return p;+}++static bool cross(V2 a, V2 b, const Seg *s) {+ float d1 = (s->x1 - s->x0) * (a.y - s->y0) - (s->y1 - s->y0) * (a.x - s->x0);+ float d2 = (s->x1 - s->x0) * (b.y - s->y0) - (s->y1 - s->y0) * (b.x - s->x0);+ if ((d1 > 0) == (d2 > 0)) return false;+ float d3 = (b.x - a.x) * (s->y0 - a.y) - (b.y - a.y) * (s->x0 - a.x);+ float d4 = (b.x - a.x) * (s->y1 - a.y) - (b.y - a.y) * (s->x1 - a.x);+ return (d3 > 0) != (d4 > 0);+}++static bool doors_between(V2 a, V2 b) {+ for (int d = 0; d < N_DOORS; d++) {+ if (!door_closed(d)) continue;+ for (int s = 0; s < 4; s++)+ if (cross(a, b, &DOORS[d].seg[s])) return true;+ }+ return false;+}++static bool any_between(V2 a, V2 b, const Seg *segs, const uint16_t *start, const uint16_t *idx, uint16_t *stamp) {+ next_query();+ int x0 = (int)floorf(fminf(a.x, b.x) - GRID_X0), x1 = (int)floorf(fmaxf(a.x, b.x) - GRID_X0);+ int y0 = (int)floorf(fminf(a.y, b.y) - GRID_Y0), y1 = (int)floorf(fmaxf(a.y, b.y) - GRID_Y0);+ if (x0 < 0) x0 = 0;+ if (y0 < 0) y0 = 0;+ if (x1 >= GRID_W) x1 = GRID_W - 1;+ if (y1 >= GRID_H) y1 = GRID_H - 1;+ /* the cells the segment's line passes near */+ float dx = b.x - a.x, dy = b.y - a.y, l = sqrtf(dx * dx + dy * dy) + 1e-6f;+ for (int cy = y0; cy <= y1; cy++)+ for (int cx = x0; cx <= x1; cx++) {+ float mx = GRID_X0 + cx + 0.5f - a.x, my = GRID_Y0 + cy + 0.5f - a.y;+ if (fabsf(mx * dy - my * dx) / l > 0.75f) continue;+ int c = cy * GRID_W + cx;+ for (int i = start[c]; i < start[c + 1]; i++) {+ int s = idx[i];+ if (stamp[s] == query) continue;+ stamp[s] = query;+ if (cross(a, b, &segs[s])) return true;+ }+ }+ return false;+}++bool ship_wall_between(V2 a, V2 b) {+ return any_between(a, b, WALL_SEGS, WALL_START, WALL_IDX, stamp_w) || doors_between(a, b);+}++bool ship_light_between(V2 a, V2 b) {+ return any_between(a, b, SHADOW_SEGS, SHADOW_START, SHADOW_IDX, stamp_s) || doors_between(a, b);+}++int ship_room_at(V2 p) {+ for (int i = 0; i < N_AREAS; i++) {+ const AreaRec *A = &AREAS[i];+ const V2 *v = AREA_PTS + A->first;+ bool in = false;+ for (int k = 0, j = A->n - 1; k < A->n; j = k++)+ if ((v[k].y > p.y) != (v[j].y > p.y) && p.x < v[j].x + (p.y - v[j].y) * (v[k].x - v[j].x) / (v[k].y - v[j].y))+ in = !in;+ if (in && A->room) return A->room;+ }+ return R_HALLWAY;+}++/* ---- the vision polygon: rays to the light walls' ends and around the circle ---- */++#define MAX_NEAR 160+static const Seg *near_segs[MAX_NEAR];+static int nnear;++static float ray(V2 o, float dx, float dy, float r) {+ float best = r;+ for (int i = 0; i < nnear; i++) {+ const Seg *s = near_segs[i];+ float ex = s->x1 - s->x0, ey = s->y1 - s->y0;+ float den = dx * ey - dy * ex;+ if (den > -1e-9f && den < 1e-9f) continue;+ float ax = s->x0 - o.x, ay = s->y0 - o.y;+ float t = (ax * ey - ay * ex) / den, u = (ax * dy - ay * dx) / den;+ if (t > 0 && t < best && u >= 0 && u <= 1) best = t;+ }+ return best;+}++static void add_near(const Seg *s, V2 p, float r) {+ if (nnear >= MAX_NEAR) return;+ /* (only segments that reach the circle) */+ V2 q = closest(p, s);+ float dx = q.x - p.x, dy = q.y - p.y;+ if (dx * dx + dy * dy > r * r) return;+ near_segs[nnear++] = s;+}++#define MAX_ANG 720+static float angs[MAX_ANG];++static void sort_floats(float *a, int n) {+ /* (a heap sort: no recursion, no buffer) */+ for (int start = n / 2 - 1; start >= -0; start--) {+ for (int root = start;;) {+ int ch = 2 * root + 1;+ if (ch >= n) break;+ if (ch + 1 < n && a[ch + 1] > a[ch]) ch++;+ if (a[root] >= a[ch]) break;+ float t = a[root];+ a[root] = a[ch], a[ch] = t, root = ch;+ }+ if (start == 0) break;+ }+ for (int end = n - 1; end > 0; end--) {+ float t = a[0];+ a[0] = a[end], a[end] = t;+ for (int root = 0;;) {+ int ch = 2 * root + 1;+ if (ch >= end) break;+ if (ch + 1 < end && a[ch + 1] > a[ch]) ch++;+ if (a[root] >= a[ch]) break;+ float u = a[root];+ a[root] = a[ch], a[ch] = u, root = ch;+ }+ }+}++int ship_vision(V2 p, float r, float *out, int max) {+ nnear = 0;+ next_query();+ int x0 = (int)floorf(p.x - r - GRID_X0), x1 = (int)floorf(p.x + r - GRID_X0);+ int y0 = (int)floorf(p.y - r - GRID_Y0), y1 = (int)floorf(p.y + r - GRID_Y0);+ if (x0 < 0) x0 = 0;+ if (y0 < 0) y0 = 0;+ if (x1 >= GRID_W) x1 = GRID_W - 1;+ if (y1 >= GRID_H) y1 = GRID_H - 1;+ for (int cy = y0; cy <= y1; cy++)+ for (int cx = x0; cx <= x1; cx++) {+ int c = cy * GRID_W + cx;+ for (int i = SHADOW_START[c]; i < SHADOW_START[c + 1]; i++) {+ int s = SHADOW_IDX[i];+ if (stamp_s[s] == query) continue;+ stamp_s[s] = query;+ add_near(&SHADOW_SEGS[s], p, r);+ }+ }+ for (int d = 0; d < N_DOORS; d++)+ if (door_closed(d))+ for (int s = 0; s < 4; s++) add_near(&DOORS[d].seg[s], p, r);+ int na = 0;+ const int CIRCLE = 72;+ for (int k = 0; k < CIRCLE; k++) angs[na++] = -3.14159265f + 6.2831853f * k / CIRCLE;+ for (int i = 0; i < nnear && na + 6 <= MAX_ANG; i++) {+ const Seg *s = near_segs[i];+ for (int e = 0; e < 2; e++) {+ float ex = (e ? s->x1 : s->x0) - p.x, ey = (e ? s->y1 : s->y0) - p.y;+ if (ex * ex + ey * ey > r * r) continue;+ float a = atan2f(ey, ex);+ angs[na++] = a - 0.0005f, angs[na++] = a, angs[na++] = a + 0.0005f;+ }+ }+ sort_floats(angs, na);+ int n = 0;+ float last = -10;+ for (int k = 0; k < na && n < max; k++) {+ if (angs[k] - last < 0.0001f) continue;+ last = angs[k];+ float dx = cosf(angs[k]), dy = sinf(angs[k]);+ float t = ray(p, dx, dy, r);+ out[2 * n] = p.x + dx * t, out[2 * n + 1] = p.y + dy * t;+ n++;+ }+ return n;+}diff --git a/games/amongus/src/ship.h b/games/amongus/src/ship.hnew file mode 100644index 00000000..1ef61fc5--- /dev/null+++ b/games/amongus/src/ship.h@@ -0,0 +1,61 @@+/* Among Us: the Skeld. Its walls (moving), light walls (seeing), doors, rooms, consoles, vents and cameras come+ * from world.h; positions are in the game's units (y up), as in its ShipStatus. */+#ifndef AU_SHIP_H+#define AU_SHIP_H+#include <stdbool.h>+#include <stdint.h>++typedef struct {+ float x, y;+} V2;+typedef struct {+ float x0, y0, x1, y1;+} Seg;+typedef struct {+ float x, y;+ uint8_t room, front; /* front: a door across a hallway seen from the front (else from the side) */+ Seg seg[4];+} DoorRec;+typedef struct {+ uint8_t room, first, n;+} AreaRec;+typedef struct {+ uint8_t type, lo, hi; /* the console serves this task type at steps lo..hi */+} ValidRec;+/* kind: 0 a task console, 1 the admin map, 2 the emergency button, 3 the cameras */+typedef struct {+ float x, y, dist, sx, sy; /* sx, sy: where a bot stands to use it */+ uint32_t types; /* the task types it serves at any step, as bits */+ uint8_t kind, id, room, below, imp;+ ValidRec valid[2];+} ConsoleRec;+typedef struct {+ float x, y, sx, sy;+ int8_t link[3];+} VentRec;+typedef struct {+ float x, y, size, aspect;+} CamRec;++/* the rooms (the game's SystemTypes) */+enum {+ R_HALLWAY, R_STORAGE, R_CAFETERIA, R_REACTOR, R_UPPER_ENGINE, R_NAV, R_ADMIN, R_ELECTRICAL, R_O2, R_SHIELDS,+ R_MEDBAY, R_SECURITY, R_WEAPONS, R_LOWER_ENGINE, R_COMMS, N_ROOMS+};+extern const char *const ROOM_NAMES[N_ROOMS];++#define PX_PER_UNIT 40+#define FEET_Y 0.2545f /* the player's collider is this far below its picture's middle (0.3636 x 0.7) */+#define PLAYER_R 0.1564f /* the collider's radius (0.2234 x 0.7) */++void ship_init(void);+/* moves a circle of radius r from p by d, sliding along walls and closed doors */+V2 ship_move(V2 p, V2 d, float r);+/* is anything between a and b: walls (and closed doors) for moving, or light walls for seeing */+bool ship_wall_between(V2 a, V2 b);+bool ship_light_between(V2 a, V2 b);+int ship_room_at(V2 p); /* the room (R_*) the point is in, R_HALLWAY if none */+bool door_closed(int d);+/* the vision polygon around p out to radius r: points into out (x, y pairs), returns how many */+int ship_vision(V2 p, float r, float *out, int max);+#endifdiff --git a/games/amongus/src/view.c b/games/amongus/src/view.cnew file mode 100644index 00000000..82fc6f35--- /dev/null+++ b/games/amongus/src/view.c@@ -0,0 +1,319 @@+/* Among Us: the ship around the player: the floor, doors, vents, bodies and players in depth order (objects in+ * front drawn again over whoever is behind them), then the dark outside the player's light. */+#include <math.h>+#include <string.h>+#include "game.h"+#include "gfx.h"+#include "view.h"+#include "world.h"++View view;++/* ---- the camera: the ship's pixels at the screen's top-left ---- */++static inline int sx_of(float x) { return (int)floorf(x * PX_PER_UNIT + SHIP_OX) - view.cx; }+static inline int sy_of(float y) { return (int)floorf(-y * PX_PER_UNIT + SHIP_OY) - view.cy; }++/* ---- the floor ---- */++static void draw_tiles(void) {+ const ShipTiles *S = (const ShipTiles *)blob(BLOB_SHIP);+ const uint16_t *map = ship_map(S);+ int y0 = gfx_y0 + view.cy, y1 = y0 + BAND;+ int ty0 = y0 >> 4, ty1 = (y1 - 1) >> 4;+ int tx0 = view.cx >> 4, tx1 = (view.cx + SCREEN_W - 1) >> 4;+ for (int ty = ty0; ty <= ty1; ty++) {+ int r0 = ty * 16 < y0 ? y0 - ty * 16 : 0, r1 = ty * 16 + 16 > y1 ? y1 - ty * 16 : 16;+ for (int tx = tx0; tx <= tx1; tx++) {+ int sx = tx * 16 - view.cx;+ int c0 = sx < 0 ? -sx : 0, c1 = sx + 16 > SCREEN_W ? SCREEN_W - sx : 16;+ unsigned t = (tx >= 0 && ty >= 0 && tx < S->tw && ty < S->th) ? map[ty * S->tw + tx] : 0xFFFF;+ if (t == 0xFFFF) {+ /* space, and its stars */+ for (int r = r0; r < r1; r++) {+ uint16_t *row = gfx_band + (ty * 16 + r - view.cy - gfx_y0) * SCREEN_W + sx;+ for (int c = c0; c < c1; c++) row[c] = 0;+ }+ uint32_t h = (uint32_t)tx * 73856093u ^ (uint32_t)ty * 19349663u;+ h ^= h >> 13, h *= 0x5bd1e995u, h ^= h >> 15;+ if ((h & 3) == 0) {+ int px = (int)(h >> 8 & 15), py = (int)(h >> 12 & 15);+ if (py >= r0 && py < r1 && px >= c0 && px < c1)+ gfx_band[(ty * 16 + py - view.cy - gfx_y0) * SCREEN_W + sx + px] = (h >> 20 & 1) ? 0xFFFF : 0x8C71;+ }+ continue;+ }+ const uint8_t *tile = ship_tile(S, (int)t);+ const uint16_t *pal = (const uint16_t *)(const void *)tile;+ const uint8_t *px = tile + 32;+ for (int r = r0; r < r1; r++) {+ uint16_t *row = gfx_band + (ty * 16 + r - view.cy - gfx_y0) * SCREEN_W + sx;+ const uint8_t *src = px + r * 8;+ int c = c0;+ if (c & 1) row[c] = pal[src[c >> 1] & 15], c++;+ for (; c + 1 < c1; c += 2) {+ uint8_t b = src[c >> 1];+ row[c] = pal[b >> 4], row[c + 1] = pal[b & 15];+ }+ if (c < c1) row[c] = pal[src[c >> 1] >> 4];+ }+ }+ }+}++/* ---- the things in depth order ---- */++enum { D_PLAYER, D_BODY, D_DOOR, D_FRONT };+typedef struct {+ float z;+ uint8_t kind, i;+ int16_t x, y; /* screen position of its pivot */+ int16_t x0, y0, x1, y1; /* its rectangle */+ const Pic *pic;+ const uint16_t *pal;+ uint8_t flip, alpha;+} Item;+#define MAX_ITEMS (MAXP * 2 + 20)+static Item items[MAX_ITEMS];+static int nitems;+/* front objects near the screen */+static uint8_t fronts[N_FRONT];+static int nfronts;++static void add(int kind, int i, float z, int x, int y, const Pic *p, const uint16_t *pal, bool flip, int alpha) {+ if (!p || nitems >= MAX_ITEMS) return;+ Item *it = &items[nitems];+ int x0 = x - (flip ? p->w - p->ox : p->ox), y0 = y - p->oy;+ if (x0 >= SCREEN_W || y0 >= SCREEN_H || x0 + p->w <= 0 || y0 + p->h <= 0) return;+ *it = (Item){z, (uint8_t)kind, (uint8_t)i, (int16_t)x, (int16_t)y, (int16_t)x0, (int16_t)y0, (int16_t)(x0 + p->w),+ (int16_t)(y0 + p->h), p, pal, flip, (uint8_t)(alpha > 255 ? 255 : alpha)};+ nitems++;+}++const Pic *player_frame(const Player *P, float t) {+ if (!P->alive) return pic(PIC_GHOST + ((int)(t * 12) % N_GHOST));+ if (P->vent_anim == 1) {+ int f = (int)(P->anim_t * 24);+ return f < 7 ? pic(PIC_JUMP + f) : NULL;+ }+ if (P->vent_anim == 2) {+ int f = (int)(P->anim_t * 24) - 1;+ if (f < 0) return NULL;+ return pic(PIC_JUMP + (f < 7 ? 6 - f : 0));+ }+ if (P->walking) return pic(PIC_WALK + ((int)(P->anim_t * 24) % 12));+ return pic(PIC_IDLE);+}++bool player_visible(int j) {+ const Player *M = &g.p[g.me], *Q = &g.p[j];+ if (j == g.me) return Q->vent == NONE || Q->vent_anim;+ if (Q->vent != NONE && !Q->vent_anim) return false;+ if (!M->alive) return true;+ if (!Q->alive) return false;+ float dx = Q->pos.x - M->pos.x, dy = Q->pos.y - M->pos.y, r = view.radius + 0.3f;+ if (dx * dx + dy * dy > r * r) return false;+ return !ship_light_between((V2){M->pos.x, M->pos.y + FEET_Y}, (V2){Q->pos.x, Q->pos.y + FEET_Y});+}++static bool body_visible(const Body *B) {+ const Player *M = &g.p[g.me];+ if (!M->alive) return true;+ float dx = B->pos.x - M->pos.x, dy = B->pos.y - M->pos.y, r = view.radius + 0.3f;+ if (dx * dx + dy * dy > r * r) return false;+ return !ship_light_between((V2){M->pos.x, M->pos.y + FEET_Y}, B->pos);+}++void view_prepare(void) {+ const Player *M = &g.p[g.me];+ view.cx = (int)floorf(g.cam.x * PX_PER_UNIT + SHIP_OX) - SCREEN_W / 2;+ view.cy = (int)floorf(-g.cam.y * PX_PER_UNIT + SHIP_OY) - SCREEN_H / 2;+ view.radius = vision_radius(g.me);+ view.dark = M->alive;+ if (view.dark) {+ V2 c = {M->pos.x, M->pos.y + FEET_Y};+ float pts[2 * VIEW_MAXPTS];+ view.npts = ship_vision(c, view.radius, pts, VIEW_MAXPTS);+ for (int k = 0; k < view.npts; k++) {+ view.pts[2 * k] = pts[2 * k] * PX_PER_UNIT + SHIP_OX - view.cx;+ view.pts[2 * k + 1] = -pts[2 * k + 1] * PX_PER_UNIT + SHIP_OY - view.cy;+ }+ }+ nitems = 0;+ /* doors */+ for (int d = 0; d < N_DOORS; d++) {+ const DoorRec *D = &DOORS[d];+ float a = g.door_anim[d];+ int f;+ if (g.door_t[d] > 0) f = (int)(a * 24) < DOOR_CLOSE_FRAMES ? (int)(a * 24) : DOOR_CLOSE_FRAMES - 1;+ else f = (int)(a * 24) < DOOR_OPEN_FRAMES ? DOOR_CLOSE_FRAMES + (int)(a * 24) : 0;+ add(D_DOOR, d, D->y / 1000.0f, sx_of(D->x), sy_of(D->y), pic((D->front ? PIC_DOOR_FRONT : PIC_DOOR_SIDE) + f), NULL,+ false, 256);+ }+ /* bodies */+ for (int b = 0; b < MAXP; b++) {+ const Body *B = &g.bodies[b];+ if (!B->on || !body_visible(B)) continue;+ add(D_BODY, b, B->pos.y / 1000.0f, sx_of(B->pos.x + 0.04f), sy_of(B->pos.y - 0.016f), pic(PIC_DEAD),+ color_pal[g.p[B->who].color], false, 256);+ }+ /* players: the dead only for the dead, see-through */+ for (int j = 0; j < g.nplayers; j++) {+ const Player *Q = &g.p[j];+ if (!player_visible(j)) continue;+ const Pic *p = player_frame(Q, g.t + j * 0.37f);+ add(D_PLAYER, j, Q->pos.y / 1000.0f, sx_of(Q->pos.x), sy_of(Q->pos.y + FEET_Y), p, color_pal[Q->color], Q->flip,+ Q->alive ? 256 : 160);+ }+ /* back to front (the larger z farther) */+ for (int a = 1; a < nitems; a++) {+ Item v = items[a];+ int b = a - 1;+ while (b >= 0 && items[b].z < v.z) items[b + 1] = items[b], b--;+ items[b + 1] = v;+ }+ nfronts = 0;+ for (int f = 0; f < N_FRONT; f++) {+ const Pic *p = pic(FRONT[f].pic);+ int x = FRONT[f].x - view.cx, y = FRONT[f].y - view.cy;+ if (x < SCREEN_W && y < SCREEN_H && x + p->w > 0 && y + p->h > 0) fronts[nfronts++] = (uint8_t)f;+ }+}++static void draw_items(void) {+ for (int k = 0; k < nitems; k++) {+ const Item *it = &items[k];+ if (!gfx_rows(it->y0, it->y1)) continue;+ gfx_spr(it->pic, it->x, it->y, it->flip, it->pal, it->alpha);+ if (it->kind == D_DOOR) continue;+ /* what stands in front of it, drawn again over it */+ for (int n = 0; n < nfronts; n++) {+ const FrontRec *F = &FRONT[fronts[n]];+ if (F->z >= it->z) continue;+ const Pic *p = pic(F->pic);+ int x = F->x - view.cx, y = F->y - view.cy;+ if (x >= it->x1 || y >= it->y1 || x + p->w <= it->x0 || y + p->h <= it->y0) continue;+ gfx_spr_clip(p, x, y, false, NULL, 256, it->x0, it->y0, it->x1, it->y1);+ }+ /* doors in front of it */+ for (int n = k + 1; n < nitems; n++) {+ const Item *d = &items[n];+ if (d->kind != D_DOOR || d->x0 >= it->x1 || d->y0 >= it->y1 || d->x1 <= it->x0 || d->y1 <= it->y0) continue;+ gfx_spr_clip(d->pic, d->x, d->y, false, NULL, 256, it->x0, it->y0, it->x1, it->y1);+ }+ }+}++/* the vents' lids while someone jumps in or out (enterVent: 18 frames at 24 a second) */+static void draw_vents(void) {+ for (int v = 0; v < N_VENTS; v++) {+ float a = g.t - g.vent_t[v];+ if (a < 0 || a >= N_VENT_FRAMES / 24.0f) continue;+ int f = (int)(a * 24);+ gfx_spr(pic(PIC_VENT + f), sx_of(VENTS[v].x), sy_of(VENTS[v].y), false, NULL, 256);+ }+}++/* outside the light: the ship darker (and nobody there) */+static void draw_dark(void) {+ if (!view.dark) return;+ /* the polygon's edges that reach this band */+ static float e[4 * 256];+ int ne = 0;+ float b0 = (float)gfx_y0, b1 = (float)(gfx_y0 + BAND);+ for (int i = 0, j = view.npts - 1; i < view.npts; j = i++) {+ float yi = view.pts[2 * i + 1], yj = view.pts[2 * j + 1];+ if ((yi < b0 && yj < b0) || (yi > b1 && yj > b1) || yi == yj || ne >= 256) continue;+ e[4 * ne] = view.pts[2 * j], e[4 * ne + 1] = yj, e[4 * ne + 2] = view.pts[2 * i], e[4 * ne + 3] = yi;+ ne++;+ }+ for (int r = 0; r < BAND; r++) {+ float yc = gfx_y0 + r + 0.5f, xs[48];+ int k = 0;+ for (int n = 0; n < ne && k < 48; n++) {+ const float *q = e + 4 * n;+ if ((q[1] > yc) != (q[3] > yc)) xs[k++] = q[0] + (yc - q[1]) * (q[2] - q[0]) / (q[3] - q[1]);+ }+ for (int a = 1; a < k; a++) {+ float v = xs[a];+ int b = a - 1;+ while (b >= 0 && xs[b] > v) xs[b + 1] = xs[b], b--;+ xs[b + 1] = v;+ }+ uint16_t *row = gfx_band + r * SCREEN_W;+ int x = 0;+ for (int s = 0; s + 1 < k; s += 2) {+ int xa = (int)ceilf(xs[s] - 0.5f), xb = (int)ceilf(xs[s + 1] - 0.5f);+ if (xa > SCREEN_W) xa = SCREEN_W;+ if (xb > SCREEN_W) xb = SCREEN_W;+ for (; x < xa; x++) row[x] = (uint16_t)(((row[x] >> 2) & 0x39E7) + ((row[x] >> 3) & 0x18E3));+ if (xb > x) x = xb;+ }+ for (; x < SCREEN_W; x++) row[x] = (uint16_t)(((row[x] >> 2) & 0x39E7) + ((row[x] >> 3) & 0x18E3));+ }+}++static void draw_names(void) {+ const Player *M = &g.p[g.me];+ for (int k = 0; k < nitems; k++) {+ const Item *it = &items[k];+ if (it->kind != D_PLAYER) continue;+ const Player *Q = &g.p[it->i];+ uint16_t c = (M->imp && Q->imp) ? rgb565(0xFF1919) : 0xFFFF;+ gfx_text(FONT_SMALL, it->x, it->y - 19, COLOR_NAMES[Q->color], c, 0, 1, 1);+ }+}++void view_draw(void) {+ draw_tiles();+ draw_vents();+ draw_items();+ draw_dark();+ draw_names();+}++/* the ship seen through a camera (scale px a unit, centred on c, in the rectangle) */+void view_camera(V2 c, float scale, int rx, int ry, int rw, int rh) {+ const ShipTiles *S = (const ShipTiles *)blob(BLOB_SHIP);+ const uint16_t *map = ship_map(S);+ float k = PX_PER_UNIT / scale;+ int y0 = ry > gfx_y0 ? ry : gfx_y0, y1 = ry + rh < gfx_y0 + BAND ? ry + rh : gfx_y0 + BAND;+ float sx0 = c.x * PX_PER_UNIT + SHIP_OX - (rw / 2) * k, sy0 = -c.y * PX_PER_UNIT + SHIP_OY - (rh / 2) * k;+ for (int y = y0; y < y1; y++) {+ uint16_t *row = gfx_band + (y - gfx_y0) * SCREEN_W;+ int py = (int)(sy0 + (y - ry) * k);+ for (int x = rx; x < rx + rw; x++) {+ int px = (int)(sx0 + (x - rx) * k);+ int tx = px >> 4, ty = py >> 4;+ unsigned t = (px >= 0 && py >= 0 && tx < S->tw && ty < S->th) ? map[ty * S->tw + tx] : 0xFFFF;+ if (t == 0xFFFF) {+ row[x] = 0;+ continue;+ }+ const uint8_t *tile = ship_tile(S, (int)t);+ uint8_t b = tile[32 + (py & 15) * 8 + ((px & 15) >> 1)];+ row[x] = ((const uint16_t *)(const void *)tile)[px & 1 ? b & 15 : b >> 4];+ }+ }+ /* who is there */+ for (int j = 0; j < g.nplayers; j++) {+ const Player *Q = &g.p[j];+ if (!Q->alive || (Q->vent != NONE && !Q->vent_anim)) continue;+ float px = rx + rw / 2 + (Q->pos.x - c.x) * scale, py = ry + rh / 2 - (Q->pos.y + FEET_Y - c.y) * scale;+ if (px < rx - 20 || px > rx + rw + 20 || py < ry - 20 || py > ry + rh + 20) continue;+ const Pic *p = player_frame(Q, g.t);+ if (!p) continue;+ float s = scale / PX_PER_UNIT;+ int x0 = (int)px, yy0 = (int)py;+ (void)x0, (void)yy0;+ gfx_pic(p, px, py, Q->flip ? -s : s, s, 0, color_pal[Q->color], 256);+ }+ for (int b = 0; b < MAXP; b++) {+ const Body *B = &g.bodies[b];+ if (!B->on) continue;+ float px = rx + rw / 2 + (B->pos.x - c.x) * scale, py = ry + rh / 2 - (B->pos.y - c.y) * scale;+ if (px < rx - 20 || px > rx + rw + 20 || py < ry - 20 || py > ry + rh + 20) continue;+ float s = scale / PX_PER_UNIT;+ gfx_pic(pic(PIC_DEAD), px, py, s, s, 0, color_pal[g.p[B->who].color], 256);+ }+}diff --git a/games/amongus/src/view.h b/games/amongus/src/view.hnew file mode 100644index 00000000..c5f742ab--- /dev/null+++ b/games/amongus/src/view.h@@ -0,0 +1,21 @@+/* Among Us: drawing the ship around the player (view.c). */+#ifndef AU_VIEW_H+#define AU_VIEW_H+#include "game.h"+#include "res.h"++#define VIEW_MAXPTS 512+typedef struct {+ int cx, cy; /* the ship's pixel at the screen's top-left */+ float radius;+ bool dark;+ int npts;+ float pts[2 * VIEW_MAXPTS]; /* the light's polygon, on the screen */+} View;+extern View view;++void view_prepare(void); /* once a frame, before the bands */+const Pic *player_frame(const Player *P, float t);+bool player_visible(int j);+void view_camera(V2 c, float scale, int rx, int ry, int rw, int rh);+#endifdiff --git a/games/amongus/src/world.h b/games/amongus/src/world.hnew file mode 100644index 00000000..318463df--- /dev/null+++ b/games/amongus/src/world.h@@ -0,0 +1,37 @@+/* Among Us: the Skeld's walls, rooms, consoles, vents, doors and cameras (made by tools/pack.py from the+ * game's ShipStatus prefab) */+#ifndef AU_WORLD_H+#define AU_WORLD_H+#include "ship.h"+#define GRID_X0 -27.0f+#define GRID_Y0 -21.0f+#define GRID_W 50+#define GRID_H 30+#define N_WALL 509+static const Seg WALL_SEGS[509] = {{0.2362f, -7.7261f, 2.014f, -7.7157f}, {2.014f, -7.7157f, 2.0118f, -10.3068f}, {2.0118f, -10.3068f, 6.0829f, -10.3043f}, {6.0829f, -10.3043f, 6.9621f, -9.4352f}, {6.9621f, -9.4352f, 6.9629f, -6.8174f}, {6.9629f, -6.8174f, 6.7068f, -6.6191f}, {6.7068f, -6.6191f, 6.2321f, -6.603f}, {6.2321f, -6.603f, 6.1763f, -6.9385f}, {6.1763f, -6.9385f, 3.0603f, -6.9604f}, {3.0603f, -6.9604f, 3.0119f, -6.6034f}, {3.0119f, -6.6034f, 0.2608f, -6.571f}, {6.1596f, -6.702f, 6.7476f, -6.702f}, {6.7476f, -6.702f, 6.7476f, -6.114f}, {6.7476f, -6.114f, 6.1596f, -6.114f}, {6.1596f, -6.114f, 6.1596f, -6.702f}, {1.098f, -6.7032f, 1.686f, -6.7032f}, {1.686f, -6.7032f, 1.686f, -6.1152f}, {1.686f, -6.1152f, 1.098f, -6.1152f}, {1.098f, -6.1152f, 1.098f, -6.7032f}, {3.33f, -8.2616f, 3.33f, -9.3132f}, {3.33f, -9.3132f, 5.766f, -9.3132f}, {5.766f, -9.3132f, 5.742f, -8.2616f}, {5.742f, -8.2616f, 3.33f, -8.2616f}, {0.8955f, -6.5956f, 0.0841f, -6.7678f}, {0.0841f, -6.7678f, 0.0576f, -4.4522f}, {0.0712f, -8.6359f, 0.0862f, -7.6548f}, {0.0862f, -7.6548f, 0.9666f, -7.738f}, {-1.4604f, -8.6319f, -1.4623f, -4.4836f}, {-7.0084f, 1.5842f, -6.1951f, 1.5767f}, {-6.1951f, 1.5767f, -6.1972f, 4.0082f}, {-6.1972f, 4.0082f, -4.2488f, 5.9339f}, {-4.2488f, 5.9339f, 2.0302f, 5.9522f}, {2.0302f, 5.9522f, 4.9035f, 3.0666f}, {4.9035f, 3.0666f, 4.9134f, 1.5875f}, {4.9134f, 1.5875f, 5.9977f, 1.5834f}, {0.0601f, -5.1427f, 0.0648f, -4.4525f}, {0.0648f, -4.4525f, 2.3572f, -4.4365f}, {2.3572f, -4.4365f, 4.9247f, -1.8786f}, {4.9247f, -1.8786f, 4.9091f, 0.4435f}, {4.9091f, 0.4435f, 6.02f, 0.4536f}, {-7.0415f, 0.4554f, -6.22f, 0.4452f}, {-6.22f, 0.4452f, -6.2078f, -1.9726f}, {-6.2078f, -1.9726f, -3.7123f, -4.4445f}, {-3.7123f, -4.4445f, -1.4524f, -4.4339f}, {-1.4524f, -4.4339f, -1.4511f, -5.5638f}, {-0.2652f, 1.08f, -0.3456f, 1.38f}, {-0.3456f, 1.38f, -0.5652f, 1.5996f}, {-0.5652f, 1.5996f, -0.8652f, 1.68f}, {-0.8652f, 1.68f, -1.1652f, 1.5996f}, {-1.1652f, 1.5996f, -1.3848f, 1.38f}, {-1.3848f, 1.38f, -1.4652f, 1.08f}, {-1.4652f, 1.08f, -1.3848f, 0.78f}, {-1.3848f, 0.78f, -1.1652f, 0.5604f}, {-1.1652f, 0.5604f, -0.8652f, 0.48f}, {-0.8652f, 0.48f, -0.5652f, 0.5604f}, {-0.5652f, 0.5604f, -0.3456f, 0.78f}, {-0.3456f, 0.78f, -0.2652f, 1.08f}, {-2.9107f, 2.349f, -2.1883f, 2.7855f}, {-2.1883f, 2.7855f, -1.9337f, 3.5112f}, {-1.9337f, 3.5112f, -2.0648f, 3.9919f}, {-2.0648f, 3.9919f, -2.6107f, 4.3841f}, {-2.6107f, 4.3841f, -3.3419f, 4.587f}, {-3.3419f, 4.587f, -4.2753f, 4.3753f}, {-4.2753f, 4.3753f, -4.8253f, 3.7954f}, {-4.8253f, 3.7954f, -4.7758f, 2.947f}, {-4.7758f, 2.947f, -4.0587f, 2.3825f}, {-4.0587f, 2.3825f, -2.9107f, 2.349f}, {2.0141f, 2.3718f, 2.7365f, 2.8083f}, {2.7365f, 2.8083f, 2.9911f, 3.534f}, {2.9911f, 3.534f, 2.86f, 4.0147f}, {2.86f, 4.0147f, 2.3141f, 4.4069f}, {2.3141f, 4.4069f, 1.5829f, 4.6098f}, {1.5829f, 4.6098f, 0.6495f, 4.3981f}, {0.6495f, 4.3981f, 0.0995f, 3.8182f}, {0.0995f, 3.8182f, 0.149f, 2.9698f}, {0.149f, 2.9698f, 0.8661f, 2.4053f}, {0.8661f, 2.4053f, 2.0141f, 2.3718f}, {-0.3919f, -0.2814f, 0.3305f, 0.1551f}, {0.3305f, 0.1551f, 0.5851f, 0.8808f}, {0.5851f, 0.8808f, 0.454f, 1.3615f}, {0.454f, 1.3615f, -0.0919f, 1.7537f}, {-0.0919f, 1.7537f, -0.8231f, 1.9566f}, {-0.8231f, 1.9566f, -1.7565f, 1.7449f}, {-1.7565f, 1.7449f, -2.3065f, 1.165f}, {-2.3065f, 1.165f, -2.257f, 0.3166f}, {-2.257f, 0.3166f, -1.5399f, -0.2479f}, {-1.5399f, -0.2479f, -0.3919f, -0.2814f}, {-2.9395f, -2.8302f, -2.2171f, -2.3937f}, {-2.2171f, -2.3937f, -1.9625f, -1.668f}, {-1.9625f, -1.668f, -2.0936f, -1.1873f}, {-2.0936f, -1.1873f, -2.6395f, -0.7951f}, {-2.6395f, -0.7951f, -3.3707f, -0.5922f}, {-3.3707f, -0.5922f, -4.3041f, -0.8039f}, {-4.3041f, -0.8039f, -4.8541f, -1.3838f}, {-4.8541f, -1.3838f, -4.8046f, -2.2322f}, {-4.8046f, -2.2322f, -4.0875f, -2.7967f}, {-4.0875f, -2.7967f, -2.9395f, -2.8302f}, {2.0549f, -2.8302f, 2.7773f, -2.3937f}, {2.7773f, -2.3937f, 3.0319f, -1.668f}, {3.0319f, -1.668f, 2.9008f, -1.1873f}, {2.9008f, -1.1873f, 2.3549f, -0.7951f}, {2.3549f, -0.7951f, 1.6237f, -0.5922f}, {1.6237f, -0.5922f, 0.6903f, -0.8039f}, {0.6903f, -0.8039f, 0.1403f, -1.3838f}, {0.1403f, -1.3838f, 0.1898f, -2.2322f}, {0.1898f, -2.2322f, 0.9069f, -2.7967f}, {0.9069f, -2.7967f, 2.0549f, -2.8302f}, {14.566f, -4.2292f, 15.6495f, -4.2309f}, {15.6495f, -4.2309f, 15.6505f, -2.8368f}, {15.6505f, -2.8368f, 17.519f, -2.8493f}, {17.519f, -2.8493f, 19.1273f, -4.1548f}, {19.1273f, -4.1548f, 19.1322f, -5.4312f}, {19.1322f, -5.4312f, 17.5041f, -6.7565f}, {17.5041f, -6.7565f, 15.6353f, -6.7418f}, {15.6353f, -6.7418f, 15.6465f, -5.3736f}, {15.6465f, -5.3736f, 14.9768f, -5.3678f}, {18.4038f, -3.8945f, 18.364f, -5.1722f}, {18.364f, -5.1722f, 18.5862f, -5.6086f}, {18.5862f, -5.6086f, 19.1275f, -5.1966f}, {19.1275f, -5.1966f, 19.1567f, -3.9894f}, {19.1567f, -3.9894f, 18.4038f, -3.8945f}, {17.5541f, -3.1232f, 18.1921f, -3.7202f}, {18.1921f, -3.7202f, 18.5136f, -3.758f}, {18.5136f, -3.758f, 18.5437f, -3.373f}, {18.5437f, -3.373f, 17.7562f, -2.8014f}, {17.7562f, -2.8014f, 17.5541f, -3.1232f}, {17.8808f, -6.1799f, 17.4579f, -6.3861f}, {17.4579f, -6.3861f, 17.7221f, -6.6433f}, {17.7221f, -6.6433f, 18.1166f, -6.3101f}, {18.1166f, -6.3101f, 17.8808f, -6.1799f}, {18.5098f, -4.4732f, 18.0676f, -4.4674f}, {18.0676f, -4.4674f, 17.7772f, -4.9376f}, {17.7772f, -4.9376f, 18.5714f, -4.9775f}, {18.5714f, -4.9775f, 18.5098f, -4.4732f}, {17.6521f, -3.4124f, 17.2644f, -3.7608f}, {17.2644f, -3.7608f, 17.7267f, -3.9648f}, {17.7267f, -3.9648f, 18.169f, -3.6587f}, {18.169f, -3.6587f, 17.6521f, -3.4124f}, {4.952f, 1.5744f, 6.753f, 1.5857f}, {6.753f, 1.5857f, 7.0339f, 1.4753f}, {7.0339f, 1.4753f, 7.8012f, 1.4806f}, {7.8012f, 1.4806f, 7.9899f, 2.1254f}, {7.9899f, 2.1254f, 8.3668f, 2.5969f}, {8.3668f, 2.5969f, 8.3866f, 3.6422f}, {8.3866f, 3.6422f, 9.4794f, 3.6401f}, {9.4794f, 3.6401f, 11.582f, 1.5832f}, {11.582f, 1.5832f, 10.5041f, 1.5812f}, {10.5041f, 1.5812f, 10.463f, 1.0887f}, {10.463f, 1.0887f, 10.143f, 0.6495f}, {10.143f, 0.6495f, 10.1512f, -1.1035f}, {10.1512f, -1.1035f, 10.2626f, -1.3329f}, {4.9569f, 0.4148f, 7.1011f, 0.4563f}, {7.1011f, 0.4563f, 7.2638f, 0.3892f}, {7.2638f, 0.3892f, 8.3633f, 0.363f}, {8.3633f, 0.363f, 8.8463f, 0.1359f}, {8.8463f, 0.1359f, 8.8202f, -1.1196f}, {8.8202f, -1.1196f, 8.7715f, -1.3119f}, {9.5351f, 1.8015f, 9.218f, 2.1238f}, {9.218f, 2.1238f, 8.6806f, 2.0871f}, {8.6806f, 2.0871f, 8.6909f, 1.5987f}, {8.6909f, 1.5987f, 9.0192f, 1.3229f}, {9.0192f, 1.3229f, 9.5038f, 1.5449f}, {9.5038f, 1.5449f, 9.5351f, 1.8015f}, {8.2223f, -4.0197f, 7.7556f, -4.004f}, {7.7556f, -4.004f, 7.611f, -4.2392f}, {7.611f, -4.2392f, 7.1851f, -4.2387f}, {7.1851f, -4.2387f, 7.0097f, -4.5057f}, {7.0097f, -4.5057f, 7.0194f, -5.1306f}, {7.0194f, -5.1306f, 6.2459f, -5.1378f}, {6.2459f, -5.1378f, 6.2524f, -4.4204f}, {6.2524f, -4.4204f, 6.1216f, -4.2587f}, {6.1216f, -4.2587f, 5.7449f, -4.265f}, {5.7449f, -4.265f, 5.5753f, -4.4187f}, {5.5753f, -4.4187f, 5.5532f, -5.1316f}, {5.5532f, -5.1316f, 4.8409f, -5.1334f}, {4.8409f, -5.1334f, 4.8257f, -4.3788f}, {4.8257f, -4.3788f, 4.4453f, -4.1404f}, {4.4453f, -4.1404f, 5.2009f, -3.392f}, {5.2009f, -3.392f, 5.5703f, -3.3953f}, {5.5703f, -3.3953f, 6.0753f, -2.9815f}, {6.0753f, -2.9815f, 6.9873f, -2.9864f}, {6.9873f, -2.9864f, 7.1938f, -2.8571f}, {7.1938f, -2.8571f, 8.2418f, -2.8805f}, {6.4176f, -3.126f, 7.0056f, -3.126f}, {7.0056f, -3.126f, 7.0056f, -2.538f}, {7.0056f, -2.538f, 6.4176f, -2.538f}, {6.4176f, -2.538f, 6.4176f, -3.126f}, {6.565f, -11.7241f, 6.9876f, -11.7951f}, {6.9876f, -11.7951f, 7.8962f, -11.7941f}, {7.8962f, -11.7941f, 8.1881f, -11.6788f}, {8.1881f, -11.6788f, 8.4557f, -11.4146f}, {8.4557f, -11.4146f, 8.8262f, -11.2036f}, {8.8262f, -11.2036f, 8.8381f, -10.3542f}, {8.8381f, -10.3542f, 8.7287f, -9.9313f}, {6.575f, -12.8721f, 7.9113f, -12.9333f}, {7.9113f, -12.9333f, 8.1292f, -13.3627f}, {8.1292f, -13.3627f, 8.8075f, -13.8746f}, {8.8075f, -13.8746f, 8.8247f, -14.2061f}, {8.8247f, -14.2061f, 7.3589f, -14.2094f}, {7.3589f, -14.2094f, 7.3613f, -14.7417f}, {7.3613f, -14.7417f, 8.7209f, -14.7132f}, {8.7209f, -14.7132f, 8.7176f, -14.9363f}, {8.7176f, -14.9363f, 9.4881f, -14.9308f}, {9.4881f, -14.9308f, 10.1447f, -14.2931f}, {10.1447f, -14.2931f, 10.1264f, -13.5075f}, {10.1264f, -13.5075f, 10.5591f, -12.8954f}, {10.5591f, -12.8954f, 10.5582f, -12.2441f}, {10.5582f, -12.2441f, 10.1406f, -11.524f}, {10.1406f, -11.524f, 10.1454f, -10.8047f}, {10.1454f, -10.8047f, 11.6641f, -10.7979f}, {11.6641f, -10.7979f, 11.6561f, -10.4263f}, {11.6561f, -10.4263f, 10.2656f, -10.4276f}, {10.2656f, -10.4276f, 10.2484f, -9.8642f}, {15.1747f, -4.4195f, 12.6412f, -4.4456f}, {12.6412f, -4.4456f, 12.6391f, -2.9485f}, {12.6391f, -2.9485f, 10.2394f, -3.0921f}, {10.2394f, -3.0921f, 10.2281f, -0.9975f}, {10.2444f, -10.2877f, 10.2575f, -7.1406f}, {10.2575f, -7.1406f, 12.6251f, -7.1553f}, {12.6251f, -7.1553f, 12.6336f, -5.4155f}, {12.6336f, -5.4155f, 15.1851f, -5.4197f}, {8.7461f, -10.2471f, 8.7418f, -6.0482f}, {8.7418f, -6.0482f, 11.1656f, -6.0423f}, {11.1656f, -6.0423f, 11.1656f, -4.0808f}, {11.1656f, -4.0808f, 7.7658f, -4.095f}, {7.7998f, -2.876f, 8.7586f, -2.8862f}, {8.7586f, -2.8862f, 8.773f, -0.9224f}, {14.226f, -4.068f, 14.814f, -4.068f}, {14.814f, -4.068f, 14.814f, -3.48f}, {14.814f, -3.48f, 14.226f, -3.48f}, {14.226f, -3.48f, 14.226f, -4.068f}, {-14.817f, -11.221f, -11.3846f, -11.212f}, {-11.3846f, -11.212f, -11.377f, -14.0606f}, {-11.377f, -14.0606f, -10.2245f, -14.0326f}, {-10.2245f, -14.0326f, -10.2111f, -10.3326f}, {-10.2111f, -10.3326f, -7.6754f, -10.3154f}, {-7.695f, -10.3154f, -7.6959f, -9.4514f}, {-7.6959f, -9.4514f, -10.1151f, -9.4373f}, {-10.1151f, -9.4373f, -10.1374f, -7.768f}, {-10.1374f, -7.768f, -6.895f, -7.8553f}, {-6.895f, -7.8553f, -6.7457f, -7.9904f}, {-6.7457f, -7.9904f, -5.1971f, -7.9456f}, {-5.1971f, -7.9456f, -5.1984f, -8.1488f}, {-5.1984f, -8.1488f, -6.4498f, -9.3212f}, {-6.4498f, -9.3212f, -6.4357f, -11.4571f}, {-6.4357f, -11.4571f, -7.4452f, -12.4088f}, {-7.4452f, -12.4088f, -8.8534f, -12.3688f}, {-8.8534f, -12.3688f, -8.8054f, -14.077f}, {-8.8054f, -14.077f, -5.3746f, -14.0637f}, {-14.8138f, -12.3569f, -12.8863f, -12.3512f}, {-12.8863f, -12.3512f, -12.8858f, -15.1954f}, {-12.8858f, -15.1954f, -5.2703f, -15.1739f}, {-18.9047f, -4.9176f, -19.2173f, -4.9149f}, {-19.2173f, -4.9149f, -19.2512f, -3.4877f}, {-19.2512f, -3.4877f, -20.8006f, -3.4662f}, {-20.8006f, -3.4662f, -20.8251f, -1.7818f}, {-20.8251f, -1.7818f, -21.775f, -1.7814f}, {-21.775f, -1.7814f, -22.1986f, -2.0615f}, {-22.1986f, -2.0615f, -22.1896f, -2.3511f}, {-22.1896f, -2.3511f, -22.9234f, -2.856f}, {-22.9234f, -2.856f, -22.9384f, -3.5689f}, {-22.9384f, -3.5689f, -22.2367f, -3.921f}, {-22.2367f, -3.921f, -21.9141f, -4.7176f}, {-21.9141f, -4.7176f, -21.9093f, -5.2562f}, {-21.9093f, -5.2562f, -21.4874f, -5.425f}, {-21.4874f, -5.425f, -21.4822f, -5.7733f}, {-21.4822f, -5.7733f, -21.6067f, -5.9172f}, {-21.6067f, -5.9172f, -21.9881f, -5.8932f}, {-21.9881f, -5.8932f, -21.9822f, -6.3742f}, {-21.9822f, -6.3742f, -22.2336f, -6.5245f}, {-22.2336f, -6.5245f, -22.5822f, -6.173f}, {-22.5822f, -6.173f, -22.8811f, -6.147f}, {-22.8811f, -6.147f, -22.9231f, -8.2997f}, {-22.9231f, -8.2997f, -21.7796f, -9.0337f}, {-21.7796f, -9.0337f, -20.8073f, -9.0371f}, {-20.8073f, -9.0371f, -20.8274f, -7.3398f}, {-20.8274f, -7.3398f, -19.2368f, -7.3331f}, {-19.2368f, -7.3331f, -19.2312f, -6.0277f}, {-19.2312f, -6.0277f, -18.8798f, -6.0438f}, {1.5144f, -12.8825f, 0.9f, -12.8743f}, {0.9f, -12.8743f, 0.9178f, -17.507f}, {0.9178f, -17.507f, -3.0214f, -17.543f}, {-3.0214f, -17.543f, -5.077f, -15.4641f}, {-5.077f, -15.4641f, -5.0804f, -15.1804f}, {-5.0804f, -15.1804f, -5.7373f, -15.176f}, {0.0292f, -7.8931f, 0.0351f, -9.1296f}, {0.0351f, -9.1296f, 0.9135f, -9.2666f}, {0.9135f, -9.2666f, 0.9189f, -11.7329f}, {0.9189f, -11.7329f, 1.6257f, -11.7288f}, {-5.7095f, -14.0365f, -5.0772f, -14.0213f}, {-5.0772f, -14.0213f, -5.0749f, -11.0007f}, {-5.0749f, -11.0007f, -4.4805f, -10.7059f}, {-4.4805f, -10.7059f, -4.4663f, -10.3222f}, {-4.4663f, -10.3222f, -2.9303f, -9.4987f}, {-2.9303f, -9.4987f, -2.8524f, -9.1178f}, {-2.8524f, -9.1178f, -1.4687f, -9.1329f}, {-1.4687f, -9.1329f, -1.4509f, -8.019f}, {-2.226f, -9.0144f, -1.638f, -9.0144f}, {-1.638f, -9.0144f, -1.638f, -8.4264f}, {-1.638f, -8.4264f, -2.226f, -8.4264f}, {-2.226f, -8.4264f, -2.226f, -9.0144f}, {-0.6782f, -13.5531f, -0.5186f, -13.6502f}, {-0.5186f, -13.6502f, -0.3564f, -13.6637f}, {-0.3564f, -13.6637f, -0.1854f, -13.5728f}, {-0.1854f, -13.5728f, -0.1817f, -13.0921f}, {-0.1817f, -13.0921f, -0.2931f, -12.9438f}, {-3.2464f, -12.2879f, -3.7098f, -12.071f}, {-3.7098f, -12.071f, -4.1002f, -12.4194f}, {-4.1002f, -12.4194f, -4.0867f, -12.9683f}, {-4.0867f, -12.9683f, -3.5314f, -13.1697f}, {-3.5314f, -13.1697f, -3.2348f, -12.8758f}, {-3.2348f, -12.8758f, -3.2384f, -13.6075f}, {-3.2384f, -13.6075f, -2.559f, -13.6069f}, {-2.559f, -13.6069f, -2.5568f, -14.1593f}, {-2.5568f, -14.1593f, -2.2949f, -14.1591f}, {-2.2949f, -14.1591f, -2.2836f, -14.565f}, {-2.2836f, -14.565f, -1.5813f, -14.8352f}, {-1.5813f, -14.8352f, -1.1489f, -14.3995f}, {-1.1489f, -14.3995f, -1.1432f, -14.1683f}, {-1.1432f, -14.1683f, -0.6143f, -14.1739f}, {-0.6143f, -14.1739f, -0.6247f, -13.588f}, {-0.6247f, -13.588f, -0.2764f, -12.9662f}, {-0.2764f, -12.9662f, -0.2837f, -11.1329f}, {-0.2837f, -11.1329f, -1.9278f, -11.1184f}, {-1.9278f, -11.1184f, -1.9252f, -11.3505f}, {-1.9252f, -11.3505f, -3.2451f, -11.3724f}, {-3.2451f, -11.3724f, -3.2463f, -12.2937f}, {-3.108f, -13.493f, -3.1239f, -14.1939f}, {-3.1239f, -14.1939f, -2.535f, -14.2567f}, {-2.535f, -14.2567f, -2.5574f, -13.5314f}, {-2.5574f, -13.5314f, -3.108f, -13.493f}, {-17.6616f, -8.3137f, -17.6667f, -9.5462f}, {-17.6667f, -9.5462f, -19.5133f, -9.5378f}, {-19.5133f, -9.5378f, -19.5133f, -13.055f}, {-19.5133f, -13.055f, -18.3313f, -13.9905f}, {-18.3313f, -13.9905f, -14.8677f, -13.9942f}, {-14.8677f, -13.9942f, -14.8601f, -12.3425f}, {-14.8601f, -12.3425f, -14.4604f, -12.3411f}, {-16.161f, -8.3164f, -16.1636f, -9.572f}, {-16.1636f, -9.572f, -14.8862f, -9.5709f}, {-14.8862f, -9.5709f, -14.8874f, -11.2179f}, {-14.8874f, -11.2179f, -14.3263f, -11.2067f}, {-15.8051f, -11.3903f, -15.9152f, -10.7607f}, {-15.9152f, -10.7607f, -16.072f, -10.5317f}, {-16.072f, -10.5317f, -18.7161f, -10.4536f}, {-18.7161f, -10.4536f, -19.2403f, -10.0996f}, {-19.2403f, -10.0996f, -19.5399f, -10.4893f}, {-19.5399f, -10.4893f, -19.4978f, -13.0238f}, {-19.4978f, -13.0238f, -18.5316f, -13.0281f}, {-18.5316f, -13.0281f, -18.4078f, -12.4345f}, {-18.4078f, -12.4345f, -16.1941f, -12.4535f}, {-16.1941f, -12.4535f, -15.885f, -12.0307f}, {-15.885f, -12.0307f, -15.8051f, -11.3903f}, {-18.057f, -12.2779f, -18.5772f, -12.8808f}, {-18.5772f, -12.8808f, -18.2369f, -12.8871f}, {-18.2369f, -12.8871f, -18.057f, -12.2779f}, {-19.6908f, -13.158f, -18.6108f, -13.158f}, {-18.6108f, -13.158f, -18.6108f, -12.078f}, {-18.6108f, -12.078f, -19.6908f, -12.078f}, {-19.6908f, -12.078f, -19.6908f, -13.158f}, {-16.2295f, -12.4912f, -15.7484f, -12.4953f}, {-15.7484f, -12.4953f, -15.73f, -10.525f}, {-15.73f, -10.525f, -16.2295f, -10.525f}, {0.9796f, -11.7602f, 6.9922f, -11.7485f}, {0.9887f, -12.9119f, 4.3682f, -12.876f}, {4.3682f, -12.876f, 4.359f, -13.9614f}, {5.8649f, -13.43f, 5.8708f, -12.8789f}, {5.8708f, -12.8789f, 6.8978f, -12.8797f}, {-14.691f, 1.5971f, -6.2222f, 1.5758f}, {-14.8505f, 0.4579f, -9.8891f, 0.4485f}, {-9.8891f, 0.4485f, -9.8869f, -0.4351f}, {-8.4185f, -0.648f, -8.42f, 0.435f}, {-8.42f, 0.435f, -6.2362f, 0.4234f}, {-14.6328f, -4.8918f, -16.2453f, -4.8841f}, {-16.2453f, -4.8841f, -16.2499f, -1.6358f}, {-17.5602f, -1.6358f, -17.5364f, -3.6931f}, {-17.5364f, -3.6931f, -17.6563f, -4.6235f}, {-17.6563f, -4.6235f, -17.4596f, -4.7329f}, {-17.4596f, -4.7329f, -17.4608f, -4.9888f}, {-17.4608f, -4.9888f, -19.0296f, -5.0004f}, {-16.1655f, -9.5456f, -16.2009f, -7.6635f}, {-16.2009f, -7.6635f, -16.3339f, -7.5733f}, {-16.3339f, -7.5733f, -16.3162f, -6.9723f}, {-16.3162f, -6.9723f, -16.1596f, -6.0604f}, {-16.1596f, -6.0604f, -14.4969f, -6.0741f}, {-18.9841f, -6.0407f, -17.6504f, -6.0527f}, {-17.6504f, -6.0527f, -17.6702f, -9.5583f}, {-15.8532f, -4.8864f, -15.2652f, -4.8864f}, {-15.2652f, -4.8864f, -15.2652f, -4.2984f}, {-15.2652f, -4.2984f, -15.8532f, -4.2984f}, {-15.8532f, -4.2984f, -15.8532f, -4.8864f}, {-14.5653f, 1.6629f, -14.9061f, 1.6503f}, {-14.9061f, 1.6503f, -14.8867f, 2.8851f}, {-14.8867f, 2.8851f, -18.328f, 2.8948f}, {-18.328f, 2.8948f, -19.529f, 1.8646f}, {-19.529f, 1.8646f, -19.524f, -1.5705f}, {-19.524f, -1.5705f, -17.7138f, -1.5374f}, {-17.7138f, -1.5374f, -17.6855f, -2.0326f}, {-14.5575f, 0.4402f, -14.8576f, 0.4411f}, {-14.8576f, 0.4411f, -14.8337f, -1.5246f}, {-14.8337f, -1.5246f, -16.128f, -1.5918f}, {-16.128f, -1.5918f, -16.1389f, -2.0598f}, {-15.8303f, 0.8088f, -15.9404f, 1.4361f}, {-15.9404f, 1.4361f, -16.0972f, 1.6644f}, {-16.0972f, 1.6644f, -18.7413f, 1.7422f}, {-18.7413f, 1.7422f, -19.2655f, 2.0948f}, {-19.2655f, 2.0948f, -19.5651f, 1.7066f}, {-19.5651f, 1.7066f, -19.523f, -0.8188f}, {-19.523f, -0.8188f, -18.5568f, -0.8231f}, {-18.5568f, -0.8231f, -18.433f, -0.2316f}, {-18.433f, -0.2316f, -16.2193f, -0.2505f}, {-16.2193f, -0.2505f, -15.9102f, 0.1708f}, {-15.9102f, 0.1708f, -15.8303f, 0.8088f}, {-18.0822f, -0.0756f, -18.6024f, -0.6763f}, {-18.6024f, -0.6763f, -18.2621f, -0.6826f}, {-18.2621f, -0.6826f, -18.0822f, -0.0756f}, {-19.716f, -0.9525f, -18.636f, -0.9525f}, {-18.636f, -0.9525f, -18.636f, 0.1236f}, {-18.636f, 0.1236f, -19.716f, 0.1236f}, {-19.716f, 0.1236f, -19.716f, -0.9525f}, {-16.2548f, -0.2881f, -15.7736f, -0.2922f}, {-15.7736f, -0.2922f, -15.7552f, 1.671f}, {-15.7552f, 1.671f, -16.2547f, 1.671f}, {4.3902f, -12.891f, 4.4128f, -14.448f}, {4.4128f, -14.448f, 4.0733f, -14.7472f}, {4.0733f, -14.7472f, 1.5395f, -14.7147f}, {1.5395f, -14.7147f, 1.5465f, -15.853f}, {1.5465f, -15.853f, 2.1548f, -15.8404f}, {2.1548f, -15.8404f, 2.1244f, -16.7585f}, {2.1244f, -16.7585f, 1.7527f, -16.7546f}, {1.7527f, -16.7546f, 2.533f, -17.4641f}, {2.533f, -17.4641f, 2.8869f, -17.468f}, {2.8869f, -17.468f, 2.8839f, -16.9209f}, {2.8839f, -16.9209f, 3.3698f, -17.0816f}, {3.3698f, -17.0816f, 3.6567f, -16.9564f}, {3.6567f, -16.9564f, 4.0017f, -16.7935f}, {4.0017f, -16.7935f, 4.3771f, -16.8287f}, {4.3771f, -16.8287f, 4.4136f, -17.0733f}, {4.4136f, -17.0733f, 4.8744f, -17.0401f}, {4.8744f, -17.0401f, 5.3978f, -16.8904f}, {5.3978f, -16.8904f, 5.4064f, -17.4951f}, {5.4064f, -17.4951f, 5.9984f, -16.9528f}, {5.9984f, -16.9528f, 6.0047f, -15.8547f}, {6.0047f, -15.8547f, 6.4928f, -15.8504f}, {6.4928f, -15.8504f, 6.4934f, -14.4485f}, {6.4934f, -14.4485f, 5.8793f, -14.4732f}, {5.8793f, -14.4732f, 5.8808f, -12.8639f}, {3.2743f, -16.9662f, 3.0958f, -17.5418f}, {3.0958f, -17.5418f, 5.3896f, -17.5403f}, {5.3896f, -17.5403f, 5.223f, -16.8087f}, {5.223f, -16.8087f, 3.2743f, -16.9662f}, {-15.4573f, -4.8825f, -14.4686f, -4.8955f}, {-14.4686f, -4.8955f, -14.471f, -3.8122f}, {-14.471f, -3.8122f, -13.5547f, -2.8776f}, {-13.5547f, -2.8776f, -13.4598f, -3.3577f}, {-13.4598f, -3.3577f, -13.1225f, -3.3534f}, {-13.1225f, -3.3534f, -13.0878f, -2.8932f}, {-13.0878f, -2.8932f, -12.5741f, -2.8679f}, {-12.5741f, -2.8679f, -11.9248f, -3.5024f}, {-11.9248f, -3.5024f, -11.9344f, -4.6859f}, {-11.9344f, -4.6859f, -12.9219f, -4.6789f}, {-12.9219f, -4.6789f, -12.9234f, -5.5554f}, {-12.9234f, -5.5554f, -12.7532f, -5.6881f}, {-12.7532f, -5.6881f, -12.422f, -5.6511f}, {-12.422f, -5.6511f, -12.3807f, -5.9227f}, {-12.3807f, -5.9227f, -11.9442f, -5.9878f}, {-11.9442f, -5.9878f, -11.9195f, -6.435f}, {-11.9195f, -6.435f, -12.0594f, -6.4349f}, {-12.0594f, -6.4349f, -12.0606f, -7.3005f}, {-12.0606f, -7.3005f, -14.3272f, -7.3079f}, {-14.3272f, -7.3079f, -14.3271f, -6.4443f}, {-14.3271f, -6.4443f, -14.4677f, -6.4472f}, {-14.4677f, -6.4472f, -14.4732f, -6.0493f}, {-14.4732f, -6.0493f, -15.3763f, -6.0487f}, {-9.8961f, 0.094f, -9.9065f, -1.015f}, {-9.9065f, -1.015f, -11.16f, -1.0208f}, {-11.16f, -1.0208f, -11.1274f, -4.796f}, {-11.1274f, -4.796f, -10.3347f, -5.7993f}, {-10.3347f, -5.7993f, -5.2283f, -5.7999f}, {-5.2283f, -5.7999f, -5.2208f, -5.351f}, {-5.2208f, -5.351f, -5.8247f, -4.7803f}, {-5.8247f, -4.7803f, -5.4618f, -4.2287f}, {-5.4618f, -4.2287f, -6.3929f, -3.4428f}, {-6.3929f, -3.4428f, -6.6367f, -3.934f}, {-6.6367f, -3.934f, -6.9874f, -3.6136f}, {-6.9874f, -3.6136f, -6.9674f, -1.0191f}, {-6.9674f, -1.0191f, -8.405f, -1.0286f}, {-8.405f, -1.0286f, -8.4082f, 0.2032f}, {-8.067f, -3.379f, -6.957f, -3.379f}, {-6.957f, -3.379f, -6.957f, -2.549f}, {-6.957f, -2.549f, -8.067f, -2.549f}, {-8.067f, -2.549f, -8.067f, -3.379f}, {-11.187f, -3.379f, -10.077f, -3.379f}, {-10.077f, -3.379f, -10.077f, -2.549f}, {-10.077f, -2.549f, -11.187f, -2.549f}, {-11.187f, -2.549f, -11.187f, -3.379f}, {-8.067f, -2.059f, -6.957f, -2.059f}, {-6.957f, -2.059f, -6.957f, -1.229f}, {-6.957f, -1.229f, -8.067f, -1.229f}, {-8.067f, -1.229f, -8.067f, -2.059f}, {-11.187f, -2.059f, -10.077f, -2.059f}, {-10.077f, -2.059f, -10.077f, -1.229f}, {-10.077f, -1.229f, -11.187f, -1.229f}, {-11.187f, -1.229f, -11.187f, -2.059f}, {-5.4965f, -4.2238f, -6.3881f, -3.4728f}, {-6.3881f, -3.4728f, -6.7272f, -4.1509f}, {-6.7272f, -4.1509f, -6.6546f, -4.4649f}, {-6.6546f, -4.4649f, -5.9775f, -4.9921f}, {-5.9775f, -4.9921f, -5.4965f, -4.2238f}};+static const uint16_t WALL_START[1501] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 7, 8, 10, 15, 24, 33, 42, 50, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 53, 54, 55, 56, 56, 56, 57, 63, 71, 78, 86, 94, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 100, 102, 103, 104, 105, 106, 107, 109, 113, 117, 118, 120, 122, 123, 124, 129, 132, 134, 136, 138, 141, 143, 146, 150, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 152, 154, 156, 157, 159, 161, 163, 165, 168, 171, 176, 179, 181, 185, 191, 196, 198, 205, 212, 219, 221, 224, 225, 227, 231, 233, 236, 240, 246, 254, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 258, 264, 273, 278, 279, 281, 283, 284, 285, 287, 289, 293, 295, 296, 298, 301, 305, 313, 323, 328, 338, 346, 349, 350, 351, 354, 357, 361, 367, 372, 378, 382, 382, 382, 382, 382, 382, 382, 382, 382, 382, 382, 382, 382, 382, 382, 382, 382, 382, 382, 385, 392, 402, 407, 412, 420, 423, 425, 427, 428, 429, 432, 434, 436, 437, 438, 443, 450, 454, 454, 458, 468, 474, 476, 478, 482, 486, 493, 501, 506, 508, 511, 511, 511, 511, 511, 511, 511, 511, 511, 511, 511, 511, 511, 511, 511, 511, 511, 511, 511, 513, 517, 521, 523, 528, 538, 543, 545, 546, 548, 549, 550, 550, 551, 553, 555, 560, 564, 569, 572, 574, 579, 582, 583, 584, 585, 586, 589, 594, 599, 604, 608, 610, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 617, 620, 621, 626, 634, 637, 639, 640, 642, 644, 646, 648, 650, 651, 653, 657, 658, 661, 663, 665, 668, 671, 673, 674, 675, 677, 679, 680, 684, 693, 698, 701, 704, 704, 704, 704, 704, 704, 704, 704, 704, 704, 704, 704, 704, 704, 705, 707, 710, 712, 716, 721, 724, 727, 731, 733, 733, 733, 733, 737, 741, 744, 747, 749, 750, 753, 756, 761, 766, 768, 771, 775, 779, 782, 784, 788, 793, 795, 797, 801, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 805, 808, 811, 813, 813, 815, 817, 820, 823, 823, 823, 823, 823, 825, 827, 828, 831, 836, 839, 842, 844, 849, 856, 861, 867, 872, 877, 880, 882, 885, 889, 890, 891, 893, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 896, 898, 901, 903, 905, 909, 911, 916, 921, 923, 925, 927, 929, 931, 933, 934, 937, 941, 944, 947, 947, 947, 949, 955, 963, 970, 978, 982, 984, 990, 999, 1003, 1004, 1007, 1009, 1010, 1012, 1012, 1012, 1014, 1015, 1017, 1018, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1021, 1027, 1035, 1037, 1041, 1046, 1048, 1051, 1055, 1061, 1066, 1074, 1080, 1082, 1084, 1085, 1086, 1087, 1089, 1091, 1091, 1091, 1092, 1095, 1101, 1107, 1113, 1116, 1117, 1123, 1132, 1138, 1140, 1144, 1148, 1151, 1153, 1153, 1153, 1155, 1156, 1162, 1167, 1168, 1168, 1168, 1168, 1168, 1168, 1168, 1170, 1178, 1186, 1186, 1192, 1200, 1205, 1211, 1220, 1228, 1232, 1240, 1246, 1249, 1251, 1252, 1254, 1259, 1265, 1268, 1268, 1268, 1270, 1272, 1276, 1279, 1281, 1281, 1283, 1290, 1296, 1300, 1302, 1304, 1306, 1308, 1310, 1311, 1313, 1316, 1316, 1322, 1334, 1338, 1338, 1338, 1338, 1338, 1338, 1338, 1339, 1343, 1347, 1347, 1350, 1355, 1360, 1365, 1372, 1379, 1382, 1385, 1389, 1391, 1392, 1392, 1396, 1407, 1414, 1417, 1419, 1420, 1423, 1426, 1429, 1430, 1432, 1433, 1438, 1449, 1457, 1464, 1467, 1468, 1470, 1472, 1474, 1477, 1482, 1487, 1490, 1500, 1518, 1523, 1523, 1523, 1523, 1523, 1523, 1523, 1526, 1530, 1535, 1537, 1539, 1542, 1544, 1547, 1551, 1555, 1560, 1565, 1570, 1574, 1576, 1578, 1585, 1597, 1603, 1606, 1610, 1612, 1613, 1614, 1616, 1619, 1622, 1624, 1628, 1637, 1649, 1660, 1666, 1671, 1675, 1678, 1680, 1683, 1688, 1694, 1698, 1708, 1722, 1726, 1726, 1726, 1726, 1726, 1726, 1726, 1728, 1733, 1738, 1740, 1740, 1741, 1743, 1745, 1747, 1748, 1752, 1755, 1761, 1768, 1772, 1776, 1783, 1790, 1794, 1798, 1802, 1806, 1809, 1811, 1814, 1817, 1822, 1826, 1828, 1832, 1840, 1847, 1850, 1854, 1856, 1857, 1859, 1859, 1859, 1861, 1863, 1868, 1872, 1873, 1873, 1873, 1873, 1873, 1873, 1873, 1873, 1876, 1880, 1884, 1890, 1899, 1905, 1908, 1912, 1914, 1914, 1914, 1919, 1926, 1931, 1936, 1942, 1949, 1954, 1959, 1964, 1968, 1971, 1974, 1978, 1982, 1987, 1991, 1993, 1995, 1995, 1995, 1998, 2004, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2010, 2016, 2025, 2029, 2034, 2040, 2041, 2041, 2041, 2045, 2052, 2057, 2062, 2067, 2072, 2074, 2076, 2079, 2084, 2089, 2093, 2097, 2100, 2103, 2105, 2106, 2107, 2107, 2107, 2111, 2118, 2121, 2121, 2121, 2121, 2121, 2121, 2121, 2121, 2121, 2121, 2121, 2121, 2121, 2121, 2121, 2121, 2121, 2121, 2121, 2123, 2127, 2133, 2136, 2142, 2151, 2154, 2155, 2156, 2157, 2160, 2163, 2166, 2168, 2171, 2174, 2174, 2174, 2177, 2186, 2195, 2201, 2201, 2201, 2201, 2204, 2207, 2211, 2214, 2219, 2225, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2228, 2234, 2238, 2240, 2246, 2255, 2258, 2259, 2260, 2261, 2262, 2263, 2264, 2266, 2269, 2272, 2273, 2275, 2280, 2291, 2303, 2311, 2311, 2311, 2311, 2314, 2317, 2321, 2326, 2334, 2342, 2346, 2348, 2348, 2348, 2348, 2348, 2348, 2348, 2348, 2348, 2348, 2348, 2348, 2348, 2348, 2348, 2348, 2348, 2348, 2348, 2354, 2359, 2362, 2367, 2374, 2377, 2377, 2377, 2377, 2377, 2377, 2377, 2377, 2378, 2381, 2384, 2387, 2392, 2399, 2406, 2411, 2415, 2419, 2422, 2424, 2426, 2426, 2428, 2434, 2439, 2440, 2441, 2441, 2441, 2441, 2441, 2441, 2441, 2441, 2441, 2441, 2441, 2441, 2441, 2441, 2441, 2441, 2441, 2441, 2441, 2442, 2444, 2446, 2447, 2449, 2451, 2451, 2451, 2451, 2451, 2451, 2451, 2451, 2453, 2458, 2462, 2466, 2470, 2474, 2477, 2480, 2484, 2489, 2494, 2496, 2498, 2498, 2498, 2500, 2502, 2503, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2504, 2506, 2510, 2514, 2518, 2522, 2524, 2526, 2529, 2533, 2537, 2540, 2541, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2542, 2543, 2544, 2546, 2548, 2549, 2550, 2551, 2552, 2554, 2556, 2557, 2558, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2559, 2560, 2561, 2563, 2565, 2566, 2567, 2568, 2569, 2571, 2573, 2574, 2575, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576, 2576};+static const uint16_t WALL_IDX[2576] = {282, 282, 281, 282, 281, 282, 281, 281, 280, 281, 280, 281, 428, 429, 430, 428, 429, 430, 431, 432, 433, 447, 448, 450, 431, 432, 433, 434, 435, 436, 447, 448, 450, 434, 435, 436, 437, 438, 439, 448, 449, 450, 438, 439, 440, 441, 442, 448, 449, 450, 441, 442, 282, 282, 282, 282, 280, 280, 426, 427, 428, 429, 430, 427, 428, 429, 430, 432, 433, 447, 450, 432, 433, 434, 435, 436, 447, 450, 434, 435, 436, 437, 438, 439, 449, 450, 438, 439, 440, 441, 442, 443, 449, 450, 441, 442, 443, 444, 250, 251, 250, 251, 251, 251, 251, 251, 251, 251, 284, 251, 282, 283, 284, 251, 282, 283, 284, 282, 282, 316, 316, 317, 317, 280, 280, 425, 426, 427, 428, 425, 427, 428, 424, 425, 424, 425, 442, 443, 442, 443, 444, 199, 200, 200, 201, 202, 200, 201, 202, 203, 203, 334, 334, 335, 334, 335, 335, 335, 336, 335, 336, 250, 251, 250, 251, 232, 233, 251, 233, 234, 251, 233, 234, 247, 248, 251, 247, 248, 251, 248, 251, 248, 251, 284, 289, 248, 251, 283, 284, 289, 290, 251, 283, 284, 289, 290, 327, 328, 313, 314, 315, 316, 327, 328, 329, 301, 314, 315, 316, 317, 318, 319, 301, 302, 303, 317, 318, 319, 320, 280, 303, 280, 425, 426, 425, 424, 425, 365, 423, 424, 425, 445, 446, 444, 445, 446, 196, 198, 199, 200, 196, 197, 198, 200, 201, 202, 196, 197, 198, 200, 201, 202, 203, 204, 203, 204, 356, 359, 333, 334, 347, 348, 356, 359, 334, 335, 348, 349, 353, 354, 355, 356, 357, 334, 335, 353, 354, 355, 335, 335, 336, 335, 336, 250, 250, 232, 233, 233, 234, 233, 234, 247, 248, 247, 248, 248, 248, 289, 248, 289, 290, 289, 290, 308, 309, 308, 309, 310, 311, 312, 327, 328, 330, 310, 311, 312, 313, 314, 315, 327, 328, 329, 330, 301, 314, 315, 318, 319, 301, 302, 303, 304, 305, 318, 319, 320, 321, 322, 279, 280, 303, 304, 305, 321, 322, 364, 279, 280, 364, 364, 364, 364, 365, 423, 366, 367, 446, 194, 366, 367, 446, 194, 195, 196, 198, 199, 367, 194, 195, 196, 197, 198, 196, 197, 198, 203, 204, 205, 203, 204, 205, 206, 356, 358, 359, 333, 334, 347, 348, 356, 358, 359, 334, 348, 349, 350, 353, 354, 355, 356, 357, 358, 334, 350, 353, 354, 355, 350, 351, 352, 360, 361, 249, 336, 337, 350, 351, 352, 360, 361, 249, 336, 337, 249, 250, 249, 250, 232, 234, 234, 246, 247, 246, 247, 245, 246, 245, 290, 290, 306, 307, 308, 309, 306, 307, 308, 309, 310, 311, 326, 306, 310, 311, 326, 304, 305, 321, 322, 279, 280, 287, 288, 304, 305, 321, 322, 363, 364, 279, 280, 287, 288, 363, 364, 363, 364, 363, 364, 363, 364, 365, 423, 363, 366, 367, 446, 187, 188, 194, 363, 366, 367, 446, 187, 188, 189, 190, 194, 195, 363, 367, 188, 189, 190, 194, 195, 205, 207, 205, 206, 207, 358, 359, 333, 347, 358, 359, 353, 355, 357, 358, 353, 355, 342, 343, 351, 352, 361, 231, 336, 337, 340, 341, 342, 343, 351, 352, 361, 231, 336, 337, 340, 341, 231, 341, 231, 231, 232, 234, 234, 245, 244, 245, 290, 291, 290, 291, 292, 306, 307, 306, 307, 325, 326, 306, 323, 324, 325, 326, 323, 324, 325, 322, 323, 287, 288, 322, 323, 363, 287, 288, 363, 363, 363, 363, 363, 187, 188, 363, 187, 188, 189, 190, 363, 188, 189, 190, 191, 192, 191, 192, 207, 208, 209, 206, 207, 208, 209, 209, 210, 209, 210, 333, 344, 345, 346, 347, 344, 345, 346, 344, 342, 343, 344, 361, 362, 231, 340, 341, 342, 343, 344, 361, 362, 231, 340, 341, 231, 341, 231, 231, 232, 234, 235, 234, 235, 235, 236, 235, 236, 244, 290, 291, 290, 291, 292, 293, 293, 293, 323, 324, 323, 324, 322, 323, 287, 322, 323, 1, 2, 287, 1, 2, 2, 2, 2, 3, 2, 3, 3, 191, 192, 193, 221, 191, 192, 193, 208, 209, 211, 212, 217, 221, 208, 209, 211, 212, 217, 209, 210, 211, 209, 210, 211, 273, 273, 274, 273, 274, 275, 274, 275, 332, 333, 345, 346, 331, 332, 345, 346, 386, 331, 332, 386, 338, 339, 380, 338, 339, 340, 380, 339, 340, 234, 235, 237, 238, 234, 235, 237, 238, 235, 236, 237, 235, 236, 237, 243, 244, 243, 243, 292, 293, 293, 294, 295, 293, 294, 295, 297, 300, 295, 296, 297, 298, 300, 285, 286, 285, 286, 287, 1, 2, 286, 287, 1, 2, 19, 20, 2, 19, 20, 2, 20, 2, 3, 20, 21, 2, 3, 4, 20, 21, 3, 4, 193, 221, 193, 212, 217, 221, 212, 217, 272, 273, 272, 273, 274, 273, 274, 275, 274, 275, 331, 386, 331, 386, 338, 380, 381, 338, 380, 381, 238, 239, 238, 239, 239, 239, 240, 241, 239, 240, 241, 243, 244, 241, 242, 243, 241, 242, 243, 294, 295, 294, 295, 297, 299, 300, 27, 295, 296, 297, 298, 299, 300, 0, 25, 26, 285, 286, 0, 25, 26, 285, 286, 287, 0, 1, 26, 286, 287, 0, 1, 19, 20, 22, 19, 20, 22, 20, 22, 20, 21, 22, 4, 20, 21, 22, 4, 221, 217, 221, 217, 272, 273, 272, 273, 273, 275, 276, 275, 276, 276, 277, 276, 277, 331, 386, 331, 386, 338, 380, 381, 382, 383, 338, 380, 381, 382, 383, 469, 470, 469, 470, 468, 469, 468, 469, 238, 239, 238, 239, 239, 239, 240, 241, 239, 240, 241, 243, 241, 242, 243, 241, 242, 243, 27, 296, 0, 23, 24, 25, 26, 285, 0, 15, 18, 23, 24, 25, 26, 285, 0, 1, 15, 16, 18, 23, 26, 0, 1, 8, 9, 15, 16, 19, 22, 8, 9, 19, 22, 8, 22, 7, 8, 11, 14, 21, 22, 4, 5, 7, 8, 11, 12, 14, 21, 22, 4, 5, 11, 12, 221, 217, 218, 221, 217, 218, 218, 218, 219, 113, 114, 113, 112, 113, 112, 112, 271, 272, 267, 268, 269, 270, 271, 272, 265, 266, 267, 268, 269, 270, 275, 276, 275, 276, 276, 277, 278, 385, 276, 277, 278, 385, 386, 385, 386, 382, 383, 384, 382, 383, 384, 473, 384, 469, 470, 471, 472, 473, 462, 463, 469, 470, 471, 462, 463, 464, 465, 466, 467, 468, 469, 465, 466, 467, 468, 469, 477, 477, 478, 477, 478, 478, 478, 478, 478, 479, 478, 479, 27, 10, 23, 24, 10, 15, 17, 18, 23, 24, 10, 15, 16, 17, 18, 23, 8, 9, 10, 15, 16, 17, 8, 9, 10, 8, 6, 7, 8, 11, 13, 14, 4, 5, 6, 7, 8, 11, 12, 13, 14, 4, 5, 6, 11, 12, 13, 221, 222, 217, 218, 221, 222, 217, 218, 222, 223, 218, 222, 223, 218, 219, 113, 114, 113, 112, 113, 126, 127, 128, 129, 112, 126, 127, 128, 129, 112, 271, 272, 262, 263, 264, 267, 268, 270, 271, 272, 262, 263, 264, 265, 266, 267, 268, 270, 252, 253, 277, 278, 379, 385, 252, 253, 277, 278, 377, 379, 385, 386, 377, 378, 379, 385, 386, 373, 374, 383, 384, 387, 390, 373, 374, 383, 384, 387, 388, 390, 451, 473, 373, 384, 387, 388, 451, 452, 472, 473, 460, 461, 462, 463, 459, 460, 461, 462, 463, 464, 465, 466, 459, 460, 465, 466, 476, 477, 476, 477, 478, 477, 478, 478, 478, 507, 478, 480, 481, 507, 508, 478, 479, 480, 481, 507, 508, 478, 479, 480, 27, 44, 24, 35, 17, 18, 24, 35, 16, 17, 18, 16, 17, 174, 175, 13, 14, 168, 169, 173, 174, 175, 12, 13, 14, 167, 168, 169, 12, 13, 167, 168, 221, 222, 221, 222, 222, 223, 222, 223, 219, 220, 220, 115, 220, 114, 115, 220, 112, 126, 128, 129, 131, 132, 111, 112, 116, 117, 118, 119, 126, 128, 129, 131, 132, 133, 111, 112, 118, 119, 261, 261, 262, 263, 264, 261, 262, 263, 264, 252, 253, 379, 252, 253, 376, 377, 379, 375, 376, 377, 378, 379, 373, 374, 387, 389, 390, 373, 374, 387, 388, 389, 390, 451, 373, 387, 388, 389, 451, 452, 453, 453, 460, 461, 459, 460, 461, 459, 460, 476, 477, 476, 477, 477, 484, 505, 506, 507, 42, 480, 481, 482, 483, 484, 504, 505, 506, 507, 508, 42, 480, 481, 482, 504, 507, 508, 42, 43, 480, 42, 43, 43, 27, 43, 44, 24, 35, 36, 24, 35, 36, 36, 36, 37, 37, 37, 174, 175, 176, 177, 37, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 165, 166, 167, 168, 169, 170, 171, 172, 163, 164, 165, 166, 167, 168, 224, 163, 164, 224, 224, 223, 224, 223, 224, 213, 214, 213, 227, 230, 107, 213, 227, 228, 230, 107, 108, 213, 227, 228, 108, 134, 135, 110, 121, 122, 130, 131, 132, 134, 135, 136, 137, 110, 111, 116, 117, 118, 119, 120, 121, 122, 123, 130, 131, 132, 133, 134, 135, 136, 137, 110, 111, 118, 119, 120, 259, 260, 261, 259, 260, 261, 262, 254, 255, 259, 261, 262, 254, 255, 253, 254, 253, 254, 376, 375, 376, 374, 389, 390, 374, 388, 389, 390, 388, 389, 452, 453, 453, 454, 455, 456, 457, 455, 456, 457, 458, 459, 458, 459, 476, 492, 495, 476, 492, 493, 495, 492, 493, 488, 491, 484, 485, 488, 489, 491, 505, 506, 42, 481, 482, 483, 484, 485, 488, 489, 504, 505, 506, 508, 42, 95, 481, 482, 504, 508, 42, 95, 96, 42, 87, 95, 96, 87, 96, 87, 105, 105, 106, 97, 105, 106, 37, 97, 106, 37, 97, 37, 176, 177, 178, 37, 170, 171, 172, 176, 177, 178, 179, 180, 165, 166, 170, 171, 172, 179, 180, 181, 182, 183, 184, 186, 163, 164, 165, 166, 180, 181, 182, 183, 184, 224, 225, 163, 164, 182, 224, 225, 226, 215, 216, 224, 225, 226, 215, 216, 223, 224, 215, 223, 224, 214, 215, 227, 229, 230, 107, 227, 228, 229, 230, 107, 108, 109, 227, 228, 229, 108, 109, 134, 135, 109, 110, 121, 122, 124, 125, 134, 135, 136, 137, 110, 111, 116, 119, 120, 121, 122, 123, 124, 125, 134, 135, 136, 137, 110, 111, 119, 120, 259, 260, 256, 257, 258, 259, 260, 255, 256, 257, 258, 259, 255, 256, 397, 375, 397, 374, 401, 374, 401, 453, 453, 454, 456, 457, 456, 457, 458, 458, 476, 494, 495, 500, 503, 476, 493, 494, 495, 500, 501, 503, 493, 494, 500, 501, 490, 491, 496, 499, 485, 489, 490, 491, 496, 497, 499, 41, 42, 485, 489, 490, 496, 497, 41, 42, 94, 95, 42, 94, 95, 96, 42, 87, 95, 96, 87, 88, 89, 96, 87, 88, 89, 104, 105, 104, 105, 106, 97, 105, 106, 37, 97, 98, 99, 106, 37, 97, 98, 99, 37, 38, 37, 38, 179, 180, 179, 180, 181, 182, 183, 184, 185, 186, 180, 181, 182, 183, 184, 185, 225, 182, 225, 226, 215, 216, 225, 226, 215, 216, 215, 214, 215, 108, 109, 108, 109, 109, 110, 121, 124, 125, 110, 121, 124, 125, 110, 256, 257, 258, 255, 256, 257, 258, 255, 256, 416, 419, 395, 396, 407, 408, 416, 419, 396, 397, 408, 409, 413, 414, 415, 416, 417, 375, 396, 397, 413, 414, 415, 374, 400, 401, 374, 399, 400, 401, 399, 400, 475, 476, 500, 502, 503, 474, 475, 476, 500, 501, 502, 503, 474, 475, 500, 501, 502, 486, 487, 496, 498, 499, 485, 486, 496, 497, 498, 499, 41, 42, 485, 486, 496, 497, 498, 41, 42, 93, 94, 95, 42, 92, 93, 94, 95, 42, 91, 92, 93, 95, 88, 89, 90, 91, 88, 89, 90, 103, 104, 105, 102, 103, 104, 105, 101, 102, 103, 105, 37, 98, 99, 100, 101, 37, 98, 99, 100, 37, 38, 37, 38, 155, 156, 226, 149, 150, 155, 156, 216, 226, 149, 150, 216, 416, 418, 419, 395, 407, 408, 416, 418, 419, 408, 409, 410, 413, 414, 415, 416, 417, 418, 410, 413, 414, 415, 410, 411, 412, 420, 421, 399, 410, 411, 412, 420, 421, 399, 475, 476, 502, 503, 370, 474, 475, 476, 501, 502, 503, 370, 474, 475, 501, 502, 371, 486, 487, 498, 499, 485, 486, 497, 498, 499, 41, 485, 486, 497, 498, 41, 93, 92, 93, 91, 92, 93, 84, 85, 89, 90, 91, 84, 85, 86, 89, 90, 77, 78, 86, 103, 77, 78, 102, 103, 101, 102, 103, 99, 100, 101, 99, 100, 38, 38, 154, 155, 156, 226, 149, 150, 154, 155, 156, 216, 226, 149, 150, 216, 418, 419, 395, 407, 418, 419, 409, 410, 413, 415, 417, 418, 410, 413, 415, 402, 410, 411, 412, 420, 421, 369, 398, 399, 402, 410, 411, 412, 420, 421, 369, 398, 399, 369, 369, 369, 369, 370, 474, 369, 370, 474, 371, 372, 487, 40, 372, 40, 41, 372, 40, 41, 372, 83, 84, 85, 50, 51, 52, 53, 54, 83, 84, 85, 86, 45, 52, 53, 54, 55, 56, 77, 78, 86, 45, 55, 56, 77, 78, 79, 38, 39, 151, 38, 39, 151, 39, 151, 152, 153, 151, 152, 153, 153, 154, 155, 160, 161, 148, 149, 154, 155, 160, 161, 147, 148, 149, 394, 395, 404, 405, 406, 407, 394, 404, 405, 406, 394, 404, 402, 403, 404, 412, 421, 422, 368, 391, 392, 402, 403, 404, 412, 421, 422, 368, 391, 392, 368, 368, 368, 368, 368, 368, 28, 368, 28, 29, 368, 28, 29, 368, 66, 57, 66, 57, 66, 82, 83, 84, 47, 48, 49, 50, 51, 52, 57, 81, 82, 83, 84, 45, 46, 47, 48, 49, 52, 55, 56, 78, 80, 81, 82, 45, 46, 55, 56, 78, 79, 80, 81, 33, 34, 138, 33, 34, 138, 34, 138, 139, 140, 138, 139, 140, 141, 142, 140, 141, 142, 157, 158, 159, 160, 161, 145, 148, 157, 158, 159, 160, 161, 162, 145, 146, 147, 148, 145, 146, 394, 395, 404, 405, 406, 407, 393, 394, 404, 405, 406, 393, 394, 404, 393, 403, 404, 421, 422, 391, 392, 393, 403, 404, 421, 422, 391, 392, 393, 29, 29, 64, 65, 64, 65, 66, 57, 65, 66, 57, 58, 66, 82, 83, 47, 48, 57, 58, 81, 82, 83, 47, 48, 74, 75, 80, 81, 82, 74, 75, 76, 80, 81, 32, 67, 75, 76, 32, 67, 68, 76, 32, 67, 68, 32, 33, 32, 33, 141, 142, 141, 142, 143, 157, 158, 159, 145, 157, 158, 159, 162, 145, 145, 394, 393, 394, 393, 394, 393, 392, 393, 392, 393, 29, 30, 29, 30, 63, 64, 65, 30, 63, 64, 65, 30, 57, 63, 65, 57, 58, 59, 60, 57, 58, 59, 60, 73, 74, 75, 73, 74, 75, 32, 67, 70, 75, 32, 67, 68, 69, 70, 32, 67, 68, 69, 70, 32, 33, 32, 33, 143, 144, 144, 145, 145, 145, 29, 30, 29, 30, 63, 64, 30, 62, 63, 64, 30, 61, 62, 63, 59, 60, 61, 62, 59, 60, 73, 74, 72, 73, 74, 32, 70, 71, 72, 32, 69, 70, 71, 32, 69, 70, 32, 32, 30, 30, 30, 31, 30, 31, 31, 31, 31, 31, 31, 32, 31, 32, 32, 32, 32, 30, 30, 30, 31, 30, 31, 31, 31, 31, 31, 31, 32, 31, 32, 32, 32, 32};+#define N_SHADOW 203+static const Seg SHADOW_SEGS[203] = {{0.2109f, -7.8995f, 1.9379f, -7.8953f}, {1.9379f, -7.8953f, 1.7414f, -10.5674f}, {1.7414f, -10.5674f, 6.2607f, -10.5551f}, {6.2607f, -10.5551f, 7.3623f, -9.5519f}, {7.3623f, -9.5519f, 7.2555f, -5.6323f}, {7.2555f, -5.6323f, 0.191f, -5.7375f}, {-1.5993f, -4.5715f, -1.4714f, -8.3671f}, {-6.3559f, 2.339f, -6.4403f, 4.8768f}, {-6.4403f, 4.8768f, -4.3147f, 7.0335f}, {-4.3147f, 7.0335f, 2.1504f, 6.9755f}, {2.1504f, 6.9755f, 5.0755f, 3.9172f}, {5.0755f, 3.9172f, 5.0702f, 2.4606f}, {0.1958f, -4.5999f, 2.4681f, -4.6445f}, {2.4681f, -4.6445f, 5.1164f, -2.0099f}, {5.1164f, -2.0099f, 5.1086f, 0.2582f}, {-6.3689f, 0.4083f, -6.4051f, -2.0917f}, {-6.4051f, -2.0917f, -3.8525f, -4.6289f}, {-3.8525f, -4.6289f, -1.6045f, -4.5801f}, {14.7059f, -3.337f, 15.4529f, -3.3481f}, {15.4529f, -3.3481f, 15.2916f, -1.8835f}, {15.2916f, -1.8835f, 19.4918f, -1.9009f}, {19.4918f, -1.9009f, 19.5752f, -7.0995f}, {19.5752f, -7.0995f, 15.3707f, -7.3377f}, {15.3707f, -7.3377f, 15.4728f, -5.5416f}, {15.4728f, -5.5416f, 14.6651f, -5.5518f}, {5.07f, 2.4686f, 6.9293f, 2.4482f}, {6.9293f, 2.4482f, 6.8622f, 4.5922f}, {6.8622f, 4.5922f, 9.5249f, 4.6f}, {9.5249f, 4.6f, 11.9311f, 2.3816f}, {11.9311f, 2.3816f, 11.9139f, -1.0419f}, {11.9139f, -1.0419f, 10.4175f, -0.978f}, {10.4175f, -0.978f, 10.4123f, -1.9f}, {5.0978f, 0.2696f, 6.9579f, 0.2709f}, {6.9579f, 0.2709f, 6.9622f, 0.0139f}, {6.9622f, 0.0139f, 8.0384f, -1.0426f}, {8.0384f, -1.0426f, 8.5959f, -0.959f}, {8.5959f, -0.959f, 8.5985f, -1.9009f}, {8.1803f, -1.9341f, 7.8225f, -2.0006f}, {7.8225f, -2.0006f, 7.9095f, -1.5057f}, {7.9095f, -1.5057f, 5.4938f, -1.5081f}, {5.4938f, -1.5081f, 3.9237f, -3.5665f}, {3.9237f, -3.5665f, 3.9116f, -5.3476f}, {3.9116f, -5.3476f, 7.987f, -5.3906f}, {7.987f, -5.3906f, 7.9041f, -4.1546f}, {7.9041f, -4.1546f, 8.1511f, -4.2323f}, {6.4397f, -10.767f, 6.9457f, -10.8476f}, {6.9457f, -10.8476f, 6.9149f, -10.5354f}, {6.9149f, -10.5354f, 7.9793f, -9.5041f}, {7.9793f, -9.5041f, 8.5716f, -9.5886f}, {8.5716f, -9.5886f, 8.5593f, -9.1514f}, {6.398f, -13.0719f, 6.9633f, -12.9993f}, {6.9633f, -12.9993f, 6.9294f, -15.1399f}, {6.9294f, -15.1399f, 12.0583f, -15.1509f}, {12.0583f, -15.1509f, 12.0351f, -9.4542f}, {12.0351f, -9.4542f, 10.4329f, -9.5766f}, {10.4329f, -9.5766f, 10.4548f, -9.123f}, {7.9208f, -4.2395f, 10.9975f, -4.23f}, {10.9975f, -4.23f, 11.0005f, -5.1451f}, {11.0005f, -5.1451f, 8.5723f, -5.1147f}, {8.5723f, -5.1147f, 8.5669f, -9.7257f}, {10.412f, -0.9802f, 10.4053f, -2.0559f}, {10.4053f, -2.0559f, 12.808f, -2.0428f}, {12.808f, -2.0428f, 12.805f, -3.3957f}, {12.805f, -3.3957f, 15.1798f, -3.39f}, {10.4188f, -9.7131f, 10.4099f, -7.2923f}, {10.4099f, -7.2923f, 12.7884f, -7.3101f}, {12.7884f, -7.3101f, 12.7855f, -5.5628f}, {12.7855f, -5.5628f, 15.182f, -5.566f}, {8.6019f, -0.9623f, 8.5927f, -2.0387f}, {-14.7295f, -10.2862f, -11.1613f, -10.2694f}, {-11.1613f, -10.2694f, -11.198f, -13.1408f}, {-11.198f, -13.1408f, -10.253f, -13.287f}, {-10.253f, -13.287f, -10.5391f, -6.6938f}, {-10.5391f, -6.6938f, -4.9192f, -6.6989f}, {-4.9192f, -6.6989f, -4.9479f, -8.3032f}, {-4.9479f, -8.3032f, -6.272f, -9.4802f}, {-6.272f, -9.4802f, -6.2386f, -12.6069f}, {-6.2386f, -12.6069f, -8.6718f, -12.5717f}, {-8.6718f, -12.5717f, -8.7933f, -13.2749f}, {-8.7933f, -13.2749f, -5.2043f, -13.1245f}, {-14.7229f, -12.5145f, -13.0384f, -12.4928f}, {-13.0384f, -12.4928f, -13.0202f, -15.349f}, {-13.0202f, -15.349f, -5.2221f, -15.3284f}, {-10.5171f, -9.4487f, -7.7536f, -9.4487f}, {-7.7536f, -9.4487f, -7.7536f, -9.3362f}, {-7.7536f, -9.3362f, -10.5171f, -9.3362f}, {-10.5171f, -9.3362f, -10.5171f, -9.4487f}, {-19.0468f, -6.2116f, -19.0522f, -7.5157f}, {-19.0522f, -7.5157f, -20.6269f, -7.5143f}, {-20.6269f, -7.5143f, -20.5928f, -9.2401f}, {-20.5928f, -9.2401f, -23.7886f, -9.2452f}, {-23.7886f, -9.2452f, -23.7249f, -0.8073f}, {-23.7249f, -0.8073f, -20.6672f, -0.8713f}, {-20.6672f, -0.8713f, -20.6561f, -2.5683f}, {-20.6561f, -2.5683f, -19.0695f, -2.5641f}, {-19.0695f, -2.5641f, -19.0731f, -4.0158f}, {-0.6782f, -13.5531f, -0.5186f, -13.6502f}, {-0.5186f, -13.6502f, -0.3564f, -13.6637f}, {-0.3564f, -13.6637f, -0.1854f, -13.5728f}, {-0.1854f, -13.5728f, -0.1817f, -13.0921f}, {-0.1817f, -13.0921f, -0.2931f, -12.9438f}, {-3.2464f, -12.2879f, -3.7098f, -12.071f}, {-3.7098f, -12.071f, -4.1002f, -12.4194f}, {-4.1002f, -12.4194f, -4.0867f, -12.9683f}, {-4.0867f, -12.9683f, -3.5314f, -13.1697f}, {-3.5314f, -13.1697f, -3.2348f, -12.8758f}, {-3.2348f, -12.8758f, -3.2384f, -13.6075f}, {-3.2384f, -13.6075f, -2.559f, -13.6069f}, {-2.559f, -13.6069f, -2.5568f, -14.1593f}, {-2.5568f, -14.1593f, -2.2949f, -14.1591f}, {-2.2949f, -14.1591f, -2.2836f, -14.565f}, {-2.2836f, -14.565f, -1.5813f, -14.8352f}, {-1.5813f, -14.8352f, -1.1489f, -14.3995f}, {-1.1489f, -14.3995f, -1.1432f, -14.1683f}, {-1.1432f, -14.1683f, -0.6143f, -14.1739f}, {-0.6143f, -14.1739f, -0.6247f, -13.588f}, {-0.6247f, -13.588f, -0.2764f, -12.9662f}, {-0.2764f, -12.9662f, -0.2837f, -11.1329f}, {-0.2837f, -11.1329f, -1.9278f, -11.1184f}, {-1.9278f, -11.1184f, -1.9252f, -11.3505f}, {-1.9252f, -11.3505f, -3.2451f, -11.3724f}, {-3.2451f, -11.3724f, -3.2463f, -12.2937f}, {0.0631f, -8.3424f, 1.0687f, -8.2142f}, {1.0687f, -8.2142f, 1.0752f, -10.8472f}, {-5.2437f, -13.1225f, -5.2478f, -9.7555f}, {-5.2478f, -9.7555f, -3.6652f, -8.1938f}, {-3.6652f, -8.1938f, -1.4853f, -8.3368f}, {-5.2382f, -15.2933f, -5.2305f, -15.5854f}, {-5.2305f, -15.5854f, -3.1111f, -17.7055f}, {-3.1111f, -17.7055f, 1.0935f, -17.6952f}, {1.0935f, -17.6952f, 1.072f, -13.0352f}, {-15.8051f, -11.3903f, -15.9152f, -10.7607f}, {-15.9152f, -10.7607f, -16.072f, -10.5317f}, {-16.072f, -10.5317f, -18.7161f, -10.4536f}, {-18.7161f, -10.4536f, -19.2403f, -10.0996f}, {-19.2403f, -10.0996f, -19.5399f, -10.4893f}, {-19.5399f, -10.4893f, -19.4978f, -13.0238f}, {-19.4978f, -13.0238f, -18.5316f, -13.0281f}, {-18.5316f, -13.0281f, -18.4078f, -12.4345f}, {-18.4078f, -12.4345f, -16.1941f, -12.4535f}, {-16.1941f, -12.4535f, -15.885f, -12.0307f}, {-15.885f, -12.0307f, -15.8051f, -11.3903f}, {-16.137f, -8.7979f, -14.6421f, -8.5867f}, {-14.6421f, -8.5867f, -14.7286f, -10.3118f}, {-17.7096f, -8.7989f, -19.7511f, -8.6039f}, {-19.7511f, -8.6039f, -19.6837f, -14.2505f}, {-19.6837f, -14.2505f, -14.6184f, -14.2422f}, {-14.6184f, -14.2422f, -14.7356f, -12.4975f}, {1.077f, -10.8491f, 6.9843f, -10.8506f}, {1.0875f, -13.0334f, 4.2297f, -13.0214f}, {4.2297f, -13.0214f, 4.2297f, -13.4392f}, {6.0218f, -13.4884f, 6.025f, -13.0115f}, {6.025f, -13.0115f, 6.9579f, -13.0314f}, {-14.6597f, -6.2154f, -16.0132f, -6.2213f}, {-16.0132f, -6.2213f, -16.0065f, -8.6745f}, {-19.035f, -6.2332f, -17.829f, -6.2179f}, {-17.829f, -6.2179f, -17.8463f, -8.6621f}, {-19.0223f, -3.9777f, -17.8269f, -3.9994f}, {-17.8269f, -3.9994f, -17.8263f, -1.7423f}, {-15.9963f, -1.7202f, -16.0058f, -4.0191f}, {-16.0058f, -4.0191f, -14.6452f, -3.9988f}, {-15.8303f, 0.8088f, -15.9404f, 1.4361f}, {-15.9404f, 1.4361f, -16.0972f, 1.6644f}, {-16.0972f, 1.6644f, -18.7413f, 1.7422f}, {-18.7413f, 1.7422f, -19.2655f, 2.0948f}, {-19.2655f, 2.0948f, -19.5651f, 1.7066f}, {-19.5651f, 1.7066f, -19.523f, -0.8188f}, {-19.523f, -0.8188f, -18.5568f, -0.8231f}, {-18.5568f, -0.8231f, -18.433f, -0.2316f}, {-18.433f, -0.2316f, -16.2193f, -0.2505f}, {-16.2193f, -0.2505f, -15.9102f, 0.1708f}, {-15.9102f, 0.1708f, -15.8303f, 0.8088f}, {-16.0059f, -1.7225f, -14.7038f, -1.7604f}, {-14.7038f, -1.7604f, -14.7328f, 0.2832f}, {-17.8525f, -1.7122f, -19.7476f, -1.771f}, {-19.7476f, -1.771f, -19.7168f, 3.8658f}, {-19.7168f, 3.8658f, -14.6959f, 3.9029f}, {-14.6959f, 3.9029f, -14.7155f, 2.5011f}, {4.2149f, -13.0312f, 4.2068f, -13.5657f}, {4.2068f, -13.5657f, 1.3263f, -13.5257f}, {1.3263f, -13.5257f, 1.3528f, -17.7389f}, {1.3528f, -17.7389f, 2.39f, -17.7675f}, {2.39f, -17.7675f, 6.7496f, -17.7396f}, {6.7496f, -17.7396f, 6.6672f, -13.6022f}, {6.6672f, -13.6022f, 6.0439f, -13.5993f}, {6.0439f, -13.5993f, 6.0496f, -13.0342f}, {-15.3719f, -6.2609f, -14.6522f, -6.2062f}, {-14.6522f, -6.2062f, -14.8357f, -7.5442f}, {-14.8357f, -7.5442f, -11.6618f, -7.4897f}, {-11.6618f, -7.4897f, -11.7022f, -2.6422f}, {-11.7022f, -2.6422f, -13.1163f, -1.1313f}, {-13.1163f, -1.1313f, -14.8842f, -2.8257f}, {-14.8842f, -2.8257f, -14.6561f, -3.9976f}, {-14.6561f, -3.9976f, -15.3818f, -3.9817f}, {-9.9177f, 0.4127f, -9.9186f, -0.1904f}, {-9.9186f, -0.1904f, -11.3054f, -0.1122f}, {-11.3054f, -0.1122f, -11.3824f, -6.028f}, {-11.3824f, -6.028f, -4.9567f, -6.0296f}, {-4.9567f, -6.0296f, -5.0008f, -4.4432f}, {-5.0008f, -4.4432f, -6.8204f, -2.769f}, {-6.8204f, -2.769f, -6.8268f, -0.1575f}, {-6.8268f, -0.1575f, -8.3597f, -0.1991f}, {-8.3597f, -0.1991f, -8.38f, 0.4139f}};+static const uint16_t SHADOW_START[1501] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 5, 6, 7, 8, 12, 14, 15, 16, 17, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 21, 22, 22, 22, 22, 22, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 27, 29, 30, 31, 32, 33, 34, 35, 38, 39, 40, 40, 40, 40, 40, 42, 42, 42, 42, 42, 45, 47, 48, 49, 50, 52, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 56, 57, 58, 59, 60, 62, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 68, 72, 74, 74, 76, 76, 76, 76, 76, 78, 79, 79, 79, 79, 80, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 84, 86, 86, 86, 86, 87, 88, 89, 91, 93, 93, 95, 96, 97, 99, 101, 105, 107, 107, 115, 115, 119, 121, 123, 127, 131, 138, 141, 141, 141, 141, 142, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 146, 149, 150, 152, 154, 156, 158, 160, 161, 162, 162, 164, 165, 167, 168, 171, 177, 177, 177, 180, 180, 182, 183, 184, 187, 190, 195, 198, 198, 198, 198, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 202, 202, 202, 203, 206, 206, 206, 206, 207, 208, 208, 208, 208, 209, 210, 210, 212, 213, 216, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 219, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 224, 226, 227, 229, 231, 233, 234, 235, 237, 238, 238, 238, 238, 239, 240, 240, 240, 240, 240, 240, 240, 244, 246, 248, 250, 252, 258, 261, 262, 262, 262, 263, 264, 264, 264, 264, 264, 264, 264, 264, 264, 264, 264, 264, 264, 264, 266, 267, 268, 270, 271, 271, 271, 271, 271, 272, 272, 272, 272, 276, 278, 280, 283, 285, 288, 290, 291, 291, 291, 291, 291, 293, 293, 293, 293, 293, 295, 299, 303, 303, 306, 308, 310, 310, 310, 310, 310, 310, 310, 310, 310, 310, 310, 310, 310, 310, 311, 311, 311, 312, 314, 315, 317, 319, 321, 323, 323, 323, 323, 324, 324, 324, 324, 325, 327, 330, 332, 333, 335, 335, 336, 339, 339, 339, 339, 339, 339, 340, 341, 341, 342, 342, 342, 342, 342, 342, 342, 342, 342, 342, 342, 342, 342, 342, 342, 342, 343, 343, 343, 345, 347, 348, 349, 350, 351, 353, 354, 355, 357, 358, 358, 358, 358, 358, 358, 359, 359, 359, 360, 360, 361, 363, 363, 363, 363, 363, 363, 364, 365, 365, 367, 368, 370, 370, 370, 372, 373, 374, 375, 377, 377, 377, 377, 377, 377, 377, 378, 378, 378, 378, 380, 382, 384, 386, 389, 392, 392, 392, 395, 398, 400, 402, 404, 406, 409, 413, 413, 413, 414, 414, 414, 414, 414, 414, 414, 414, 414, 415, 416, 416, 416, 416, 417, 417, 417, 418, 418, 418, 418, 419, 419, 419, 419, 419, 419, 419, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 423, 424, 425, 426, 427, 428, 430, 432, 432, 432, 433, 433, 434, 435, 436, 439, 441, 443, 445, 449, 453, 454, 456, 458, 460, 461, 463, 466, 466, 466, 466, 467, 467, 467, 467, 467, 467, 467, 468, 468, 468, 468, 470, 471, 473, 475, 478, 481, 481, 481, 483, 483, 483, 483, 483, 485, 488, 491, 493, 494, 496, 496, 497, 498, 500, 502, 503, 504, 504, 507, 510, 511, 513, 515, 515, 515, 515, 515, 515, 515, 515, 516, 516, 516, 516, 516, 516, 516, 517, 517, 517, 517, 519, 520, 522, 524, 527, 530, 530, 530, 532, 532, 532, 532, 532, 534, 536, 538, 539, 539, 539, 539, 539, 539, 540, 543, 545, 547, 547, 547, 547, 547, 547, 547, 549, 550, 552, 555, 555, 555, 555, 556, 556, 556, 556, 556, 556, 556, 557, 557, 557, 559, 561, 561, 562, 563, 564, 566, 568, 569, 572, 572, 572, 572, 572, 576, 578, 580, 581, 581, 581, 581, 581, 581, 582, 584, 586, 589, 589, 591, 593, 593, 595, 596, 598, 598, 598, 599, 599, 599, 599, 600, 600, 600, 600, 600, 600, 600, 601, 601, 601, 602, 604, 605, 607, 609, 611, 614, 616, 617, 619, 619, 619, 619, 619, 621, 621, 621, 621, 621, 621, 621, 621, 621, 622, 624, 626, 630, 632, 637, 642, 642, 646, 649, 651, 651, 651, 653, 654, 655, 656, 658, 658, 658, 658, 658, 658, 658, 660, 661, 662, 664, 667, 670, 671, 673, 674, 675, 675, 675, 677, 678, 680, 682, 683, 686, 686, 686, 686, 686, 686, 686, 686, 686, 686, 686, 686, 687, 689, 692, 696, 696, 699, 701, 701, 701, 701, 701, 701, 701, 701, 701, 701, 701, 701, 701, 701, 701, 701, 701, 701, 701, 703, 703, 703, 704, 707, 708, 708, 708, 708, 708, 709, 710, 710, 711, 711, 711, 711, 711, 711, 711, 711, 711, 711, 711, 711, 713, 716, 719, 720, 720, 720, 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, 725, 727, 728, 730, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 732, 733, 733, 733, 733, 733, 733, 733, 733, 733, 733, 733, 733, 733, 733, 733, 733, 733, 733, 733, 736, 737, 737, 737, 737, 738, 738, 738, 738, 738, 738, 738, 738, 739, 739, 739, 739, 739, 739, 739, 739, 739, 739, 739, 739, 741, 743, 743, 743, 744, 745, 747, 747, 747, 747, 747, 747, 747, 747, 747, 747, 747, 747, 747, 747, 747, 747, 747, 747, 747, 749, 750, 751, 752, 753, 755, 755, 755, 755, 755, 755, 755, 755, 756, 756, 756, 756, 756, 756, 756, 756, 756, 757, 758, 759, 761, 762, 762, 762, 763, 764, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 767, 768, 769, 769, 769, 769, 769, 769, 769, 770, 771, 772, 773, 775, 776, 777, 779, 780, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 782, 783, 784, 784, 784, 784, 784, 784, 784, 785, 786, 787, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 789, 790, 792, 793, 794, 795, 796, 797, 798, 800, 801, 802, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 804, 805, 807, 808, 809, 810, 811, 812, 813, 815, 816, 817, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818, 818};+static const uint16_t SHADOW_IDX[818] = {128, 128, 128, 129, 129, 129, 129, 129, 129, 130, 180, 181, 181, 182, 182, 182, 182, 182, 183, 128, 128, 128, 130, 180, 183, 81, 82, 81, 82, 82, 82, 82, 82, 82, 82, 82, 127, 128, 128, 128, 130, 180, 51, 52, 183, 51, 52, 52, 52, 52, 52, 53, 52, 53, 145, 146, 146, 146, 146, 146, 146, 147, 81, 81, 108, 109, 110, 111, 111, 112, 113, 114, 114, 115, 130, 180, 51, 183, 51, 53, 53, 136, 137, 145, 137, 138, 147, 81, 81, 70, 71, 71, 72, 78, 79, 79, 79, 79, 124, 103, 104, 104, 105, 106, 107, 107, 108, 96, 97, 98, 99, 100, 115, 116, 117, 130, 149, 179, 180, 149, 179, 149, 179, 149, 150, 178, 179, 151, 152, 184, 185, 50, 51, 151, 152, 183, 184, 185, 50, 51, 152, 53, 53, 136, 137, 145, 137, 138, 139, 139, 139, 140, 140, 141, 80, 147, 80, 81, 80, 81, 70, 72, 77, 78, 77, 76, 77, 124, 102, 103, 104, 101, 102, 104, 105, 106, 121, 100, 116, 117, 130, 149, 149, 149, 149, 150, 178, 151, 152, 185, 50, 51, 151, 152, 185, 50, 51, 152, 53, 53, 136, 145, 140, 131, 140, 141, 70, 72, 76, 124, 120, 121, 120, 118, 119, 120, 117, 118, 53, 53, 134, 135, 136, 145, 133, 134, 133, 132, 133, 131, 132, 69, 143, 69, 69, 69, 70, 72, 76, 124, 1, 2, 123, 148, 2, 148, 2, 148, 2, 148, 2, 148, 2, 3, 45, 46, 47, 148, 3, 47, 148, 47, 53, 53, 90, 91, 90, 90, 89, 90, 145, 143, 72, 83, 85, 86, 83, 85, 83, 85, 83, 84, 85, 75, 76, 75, 124, 125, 75, 125, 125, 1, 123, 3, 47, 3, 4, 47, 48, 47, 48, 49, 59, 54, 55, 64, 53, 54, 53, 54, 91, 89, 144, 145, 144, 144, 156, 142, 154, 142, 154, 142, 143, 72, 75, 75, 125, 74, 75, 125, 125, 126, 126, 6, 126, 122, 1, 122, 123, 4, 59, 64, 91, 88, 89, 87, 88, 87, 156, 154, 154, 187, 188, 188, 188, 188, 189, 72, 74, 6, 0, 0, 1, 4, 59, 64, 65, 65, 65, 66, 22, 23, 22, 22, 22, 21, 22, 91, 87, 155, 87, 155, 155, 156, 153, 154, 153, 154, 186, 153, 186, 187, 189, 196, 197, 72, 73, 197, 73, 197, 73, 197, 73, 197, 73, 197, 73, 197, 198, 73, 74, 197, 198, 6, 4, 59, 66, 23, 21, 91, 189, 196, 197, 197, 197, 197, 197, 197, 197, 198, 197, 198, 6, 5, 5, 5, 5, 41, 42, 5, 42, 5, 42, 5, 42, 4, 5, 42, 43, 42, 43, 58, 59, 58, 57, 58, 57, 58, 66, 67, 67, 24, 67, 23, 24, 67, 21, 91, 95, 157, 157, 157, 158, 159, 160, 159, 160, 193, 160, 192, 193, 189, 196, 16, 199, 16, 198, 199, 16, 198, 199, 16, 17, 17, 6, 17, 12, 12, 12, 13, 13, 41, 13, 13, 43, 44, 56, 43, 44, 56, 56, 56, 57, 56, 57, 21, 91, 95, 157, 157, 157, 158, 159, 160, 159, 160, 193, 160, 192, 193, 189, 196, 16, 199, 16, 199, 16, 199, 16, 13, 13, 40, 41, 13, 40, 13, 40, 62, 63, 63, 18, 63, 18, 19, 63, 21, 91, 93, 94, 94, 95, 158, 159, 159, 191, 192, 190, 191, 190, 189, 190, 196, 15, 16, 199, 200, 16, 199, 16, 199, 16, 13, 13, 40, 13, 40, 13, 14, 40, 37, 38, 37, 68, 60, 61, 61, 61, 62, 19, 21, 91, 93, 174, 175, 174, 158, 174, 159, 172, 159, 172, 172, 173, 191, 190, 191, 190, 190, 196, 15, 200, 13, 13, 40, 13, 40, 13, 14, 39, 40, 34, 39, 34, 35, 37, 38, 39, 34, 35, 36, 37, 68, 30, 31, 60, 61, 29, 30, 61, 61, 62, 19, 20, 20, 20, 20, 20, 21, 91, 92, 92, 92, 92, 93, 166, 167, 175, 167, 168, 169, 169, 169, 170, 170, 173, 195, 196, 195, 194, 195, 201, 202, 201, 15, 200, 201, 14, 33, 34, 33, 34, 35, 34, 35, 36, 68, 30, 31, 60, 29, 30, 166, 175, 170, 161, 170, 171, 173, 194, 202, 15, 14, 32, 32, 33, 34, 32, 33, 34, 34, 29, 164, 165, 166, 175, 163, 164, 163, 162, 163, 161, 162, 29, 164, 165, 175, 164, 177, 7, 11, 25, 25, 26, 28, 28, 28, 29, 175, 176, 176, 176, 176, 176, 176, 177, 7, 10, 10, 10, 10, 11, 26, 28, 28, 28, 7, 8, 8, 8, 10, 10, 10, 10, 26, 27, 27, 27, 27, 28, 28, 28, 8, 8, 8, 10, 10, 10, 10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10};+#define N_DOORS 13+static const DoorRec DOORS[13] = {{5.1432f, 1.3356f, 2, 0, {{4.9416f, 0.2202f, 5.3232f, 0.2202f}, {5.3232f, 0.2202f, 5.3232f, 2.451f}, {5.3232f, 2.451f, 4.9416f, 2.451f}, {4.9416f, 2.451f, 4.9416f, 0.2202f}}}, {-0.708f, -4.992f, 2, 1, {{-1.638f, -5.5574f, 0.222f, -5.5574f}, {0.222f, -5.5574f, 0.222f, -5.1f}, {0.222f, -5.1f, -1.638f, -5.1f}, {-1.638f, -5.1f, -1.638f, -5.5574f}}}, {-6.3936f, 1.33848f, 2, 0, {{-6.6027f, 0.2378f, -6.2291f, 0.2378f}, {-6.2291f, 0.2378f, -6.2291f, 2.4392f}, {-6.2291f, 2.4392f, -6.6027f, 2.4392f}, {-6.6027f, 2.4392f, -6.6027f, 0.2378f}}}, {-9.53616f, -13.416f, 7, 1, {{-10.3094f, -13.9814f, -8.7629f, -13.9814f}, {-8.7629f, -13.9814f, -8.7629f, -13.2618f}, {-8.7629f, -13.2618f, -10.3094f, -13.2618f}, {-10.3094f, -13.2618f, -10.3094f, -13.9814f}}}, {1.1316f, -11.9813f, 1, 0, {{0.936f, -13.0596f, 1.31f, -13.0596f}, {1.31f, -13.0596f, 1.31f, -10.8419f}, {1.31f, -10.8419f, 0.936f, -10.8419f}, {0.936f, -10.8419f, 0.936f, -13.0596f}}}, {-0.7092f, -8.5608f, 1, 1, {{-1.4841f, -9.0772f, 0.0902f, -9.0772f}, {0.0902f, -9.0772f, 0.0902f, -8.3505f}, {0.0902f, -8.3505f, -1.4841f, -8.3505f}, {-1.4841f, -8.3505f, -1.4841f, -9.0772f}}}, {-5.268f, -14.2884f, 1, 0, {{-5.508f, -15.3391f, -5.1284f, -15.3391f}, {-5.1284f, -15.3391f, -5.1284f, -13.1523f}, {-5.1284f, -13.1523f, -5.508f, -13.1523f}, {-5.508f, -13.1523f, -5.508f, -15.3391f}}}, {-14.6808f, -11.472f, 13, 0, {{-14.8701f, -12.5079f, -14.5414f, -12.5079f}, {-14.5414f, -12.5079f, -14.5414f, -10.3448f}, {-14.5414f, -10.3448f, -14.8701f, -10.3448f}, {-14.8701f, -10.3448f, -14.8701f, -12.5079f}}}, {-16.9308f, -8.9664f, 13, 1, {{-17.692f, -9.51f, -16.1478f, -9.51f}, {-16.1478f, -9.51f, -16.1478f, -8.799f}, {-16.1478f, -8.799f, -17.692f, -8.799f}, {-17.692f, -8.799f, -17.692f, -9.51f}}}, {-14.676f, 1.34064f, 4, 0, {{-14.916f, 0.2358f, -14.496f, 0.2358f}, {-14.496f, 0.2358f, -14.496f, 2.4455f}, {-14.496f, 2.4455f, -14.916f, 2.4455f}, {-14.916f, 2.4455f, -14.916f, 0.2358f}}}, {-16.9308f, -2.1276f, 4, 1, {{-17.8608f, -2.6629f, -16.0008f, -2.6629f}, {-16.0008f, -2.6629f, -16.0008f, -2.2238f}, {-16.0008f, -2.2238f, -17.8608f, -2.2238f}, {-17.8608f, -2.2238f, -17.8608f, -2.6629f}}}, {-14.7348f, -5.14176f, 11, 0, {{-14.9407f, -6.2414f, -14.5753f, -6.2414f}, {-14.5753f, -6.2414f, -14.5753f, -3.9875f}, {-14.5753f, -3.9875f, -14.9407f, -3.9875f}, {-14.9407f, -3.9875f, -14.9407f, -6.2414f}}}, {-9.1452f, -0.444f, 10, 1, {{-9.9115f, -1.0094f, -8.3652f, -1.0094f}, {-8.3652f, -1.0094f, -8.3652f, -0.1626f}, {-8.3652f, -0.1626f, -9.9115f, -0.1626f}, {-9.9115f, -0.1626f, -9.9115f, -1.0094f}}}};+#define N_AREAS 21+static const AreaRec AREAS[21] = {{6, 0, 5}, {0, 5, 4}, {2, 9, 6}, {0, 15, 4}, {5, 19, 4}, {12, 23, 4}, {8, 27, 6}, {9, 33, 4}, {0, 37, 4}, {7, 41, 5}, {0, 46, 7}, {3, 53, 6}, {1, 59, 5}, {13, 64, 4}, {0, 68, 4}, {0, 72, 4}, {0, 76, 4}, {4, 80, 4}, {14, 84, 4}, {11, 88, 5}, {10, 93, 6}};+static const V2 AREA_PTS[99] = {{7.33981f, -5.52981f}, {1.83637f, -5.52217f}, {1.87055f, -10.5194f}, {6.2072f, -10.6472f}, {7.42841f, -9.53787f}, {-2.01994f, -8.95686f}, {1.81601f, -8.95686f}, {1.81601f, -4.72081f}, {-2.01994f, -4.72081f}, {5.16884f, -2.01832f}, {5.18974f, 7.16227f}, {-6.46386f, 7.22542f}, {-6.50059f, -2.12294f}, {-3.91116f, -4.72433f}, {2.52676f, -4.68751f}, {5.13944f, 0.203987f}, {6.96123f, 0.203987f}, {6.96123f, 1.81909f}, {5.13944f, 1.81909f}, {15.208f, -1.68282f}, {15.2103f, -7.38463f}, {19.8073f, -7.33626f}, {19.7094f, -1.69376f}, {11.726f, 4.05609f}, {6.81336f, 6.00777f}, {6.79972f, -1.07077f}, {12.4322f, -1.1228f}, {7.98115f, -1.42811f}, {5.36796f, -1.39524f}, {5.32339f, -1.94772f}, {3.80621f, -3.51398f}, {3.76177f, -5.3431f}, {7.99226f, -5.40919f}, {6.853f, -10.3482f}, {6.82251f, -15.1502f}, {12.1078f, -15.0825f}, {12.0804f, -10.2842f}, {7.89955f, -10.3293f}, {15.1265f, -10.3293f}, {15.1265f, -1.88751f}, {7.89955f, -1.88751f}, {-10.6805f, -6.60047f}, {-10.786f, -13.6524f}, {-8.11339f, -13.6599f}, {-6.12501f, -11.4697f}, {-4.24271f, -6.67681f}, {-11.0903f, -10.2382f}, {-14.6437f, -10.0585f}, {-14.6691f, -12.6059f}, {-13.068f, -15.4288f}, {-5.29545f, -15.5004f}, {-5.29782f, -13.8192f}, {-11.2707f, -13.8897f}, {-20.6594f, -0.756655f}, {-23.8579f, -0.66386f}, {-23.8553f, -9.3268f}, {-20.6354f, -9.33992f}, {-18.933f, -7.58592f}, {-18.8861f, -2.69512f}, {1.09096f, -8.9858f}, {-4.03558f, -8.98407f}, {-5.26231f, -9.84189f}, {-5.26886f, -17.7805f}, {1.13576f, -17.8144f}, {-19.7234f, -9.24126f}, {-19.6335f, -14.4231f}, {-14.669f, -14.4666f}, {-14.6135f, -9.25161f}, {1.08794f, -13.9973f}, {6.75615f, -13.9973f}, {6.75615f, -11.5634f}, {1.08794f, -11.5634f}, {-14.7531f, -0.744922f}, {-6.36129f, -0.744922f}, {-6.36129f, 1.85205f}, {-14.7531f, 1.85205f}, {-19.056f, -9.25683f}, {-14.7769f, -9.25683f}, {-14.7769f, -1.85211f}, {-19.056f, -1.85211f}, {-20.0286f, 3.83835f}, {-19.8251f, -1.84717f}, {-14.5992f, -1.86504f}, {-14.6239f, 3.86549f}, {1.26985f, -14.0044f}, {1.27223f, -17.8633f}, {6.84502f, -17.8448f}, {6.74415f, -13.9752f}, {-13.1111f, -1.24903f}, {-14.9537f, -2.81172f}, {-14.9682f, -7.50181f}, {-11.7227f, -7.52573f}, {-11.7211f, -2.66445f}, {-11.3976f, -6.1972f}, {-4.91663f, -6.09971f}, {-4.84519f, -4.41465f}, {-6.49557f, -2.65773f}, {-6.66775f, -0.773361f}, {-11.3334f, -0.745196f}};+#define NAV_X0 -26.0f+#define NAV_Y0 -20.0f+#define NAV_CS 0.5f+#define NAV_W 96+#define NAV_H 58+static const uint8_t NAV_BITS[696] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 31, 134, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 31, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 31, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 252, 159, 255, 1, 0, 0, 0, 0, 0, 0, 248, 255, 127, 28, 224, 1, 0, 0, 0, 0, 0, 0, 216, 3, 30, 24, 96, 192, 0, 0, 0, 0, 128, 63, 24, 3, 28, 16, 96, 192, 0, 0, 0, 0, 128, 63, 24, 3, 12, 16, 96, 224, 0, 0, 0, 0, 0, 63, 24, 3, 4, 16, 96, 240, 1, 0, 0, 0, 0, 32, 24, 3, 12, 240, 255, 255, 1, 0, 0, 0, 0, 224, 31, 63, 28, 16, 0, 224, 0, 0, 0, 0, 0, 32, 0, 127, 28, 16, 0, 192, 0, 0, 0, 0, 0, 32, 0, 127, 248, 31, 0, 192, 0, 0, 0, 0, 128, 63, 0, 96, 240, 31, 0, 192, 0, 0, 0, 0, 224, 7, 0, 96, 192, 31, 255, 193, 0, 0, 0, 0, 0, 6, 0, 112, 0, 14, 3, 195, 0, 0, 0, 0, 3, 6, 0, 255, 0, 14, 3, 195, 0, 0, 0, 128, 3, 6, 0, 255, 1, 14, 3, 195, 0, 0, 0, 128, 3, 6, 0, 0, 0, 14, 255, 195, 0, 0, 0, 128, 3, 6, 0, 0, 0, 254, 255, 195, 0, 0, 0, 128, 31, 6, 7, 0, 0, 14, 0, 192, 31, 0, 0, 0, 31, 134, 15, 0, 0, 14, 0, 192, 31, 112, 0, 0, 254, 255, 3, 0, 0, 14, 0, 0, 24, 240, 1, 0, 254, 255, 131, 255, 1, 14, 0, 0, 24, 240, 0, 0, 30, 134, 195, 127, 0, 14, 64, 2, 248, 127, 0, 0, 31, 134, 207, 63, 0, 30, 64, 2, 24, 240, 0, 0, 31, 6, 207, 63, 240, 255, 195, 255, 31, 48, 0, 128, 3, 6, 4, 7, 248, 255, 7, 253, 28, 112, 0, 128, 3, 6, 0, 7, 128, 31, 14, 192, 0, 0, 0, 0, 3, 6, 0, 15, 2, 15, 28, 192, 0, 0, 0, 0, 0, 6, 0, 7, 3, 15, 28, 192, 0, 0, 0, 0, 224, 63, 0, 7, 3, 15, 28, 192, 0, 0, 0, 0, 0, 63, 0, 6, 135, 31, 30, 192, 0, 0, 0, 0, 0, 32, 0, 6, 255, 240, 31, 192, 0, 0, 0, 0, 0, 32, 0, 6, 127, 224, 31, 192, 0, 0, 0, 0, 0, 224, 255, 255, 127, 192, 255, 255, 0, 0, 0, 0, 0, 224, 255, 255, 127, 224, 255, 191, 1, 0, 0, 0, 0, 32, 0, 0, 255, 224, 31, 144, 1, 0, 0, 0, 192, 63, 0, 0, 143, 31, 31, 128, 1, 0, 0, 0, 0, 0, 0, 0, 3, 15, 28, 224, 0, 0, 0, 0, 0, 0, 0, 0, 3, 15, 28, 96, 0, 0, 0, 0, 0, 0, 0, 0, 3, 15, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 15, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 127, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 255, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};+#define N_CONSOLES 49+static const ConsoleRec CONSOLES[49] = {{2.508f, -6.2652f, 1.0f, 2.508f, -6.8152f, 128u, 0, 0, 6, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {6.4536f, -6.408f, 1.0f, 6.4536f, -6.908f, 1048576u, 0, 1, 6, 0, 1, {{255, 0, 0}, {255, 0, 0}}}, {1.392f, -6.4092f, 1.0f, 1.392f, -6.9092f, 4096u, 0, 2, 6, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {5.6352f, -8.6328f, 1.0f, 5.9352f, -8.6328f, 32u, 0, 0, 6, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {3.48f, -8.6244f, 1.0f, 3.13f, -8.6244f, 0u, 1, 0, 0, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {4.4748f, 3.948f, 1.0f, 4.0748f, 3.598f, 0u, 0, 2, 2, 0, 0, {{10, 0, 0}, {255, 0, 0}}}, {-5.2812f, 5.2464f, 1.0f, -4.9812f, 4.9464f, 4096u, 0, 4, 2, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {3.4908f, 4.896f, 1.0f, 3.1408f, 4.546f, 0u, 0, 2, 2, 0, 0, {{7, 0, 0}, {255, 0, 0}}}, {-0.8652f, 1.08f, 1.75f, -1.1152f, 2.08f, 0u, 2, 0, 0, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {18.732f, -4.728f, 1.25f, 18.182f, -5.178f, 2097152u, 0, 0, 5, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {18.0636f, -3.312f, 1.0f, 17.4636f, -3.312f, 0u, 0, 0, 5, 0, 0, {{3, 0, 0}, {255, 0, 0}}}, {17.004f, -2.448f, 1.0f, 17.004f, -3.048f, 0u, 0, 0, 5, 0, 0, {{7, 0, 0}, {255, 0, 0}}}, {16.02f, -2.448f, 1.0f, 16.02f, -3.048f, 0u, 0, 1, 5, 0, 0, {{14, 1, 1}, {255, 0, 0}}}, {9.0876f, 1.812f, 1.2f, 9.4376f, 2.162f, 64u, 0, 0, 12, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {11.448f, 2.076f, 1.0f, 11.098f, 1.776f, 0u, 0, 1, 12, 0, 0, {{14, 1, 1}, {255, 0, 0}}}, {8.664f, 3.936f, 1.0f, 8.664f, 3.436f, 0u, 0, 1, 12, 0, 0, {{7, 0, 0}, {255, 0, 0}}}, {4.896f, -3.276f, 0.9f, 5.246f, -3.626f, 0u, 0, 0, 8, 0, 0, {{9, 0, 0}, {255, 0, 0}}}, {8.376f, -2.484f, 1.0f, 8.376f, -3.084f, 0u, 0, 1, 8, 0, 0, {{14, 1, 1}, {255, 0, 0}}}, {5.7432f, -2.9772f, 0.8f, 5.9432f, -3.3272f, 262144u, 0, 0, 8, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {6.7116f, -2.832f, 1.0f, 6.7116f, -3.332f, 1048576u, 0, 0, 8, 0, 1, {{255, 0, 0}, {255, 0, 0}}}, {10.722f, -10.1376f, 1.0f, 10.072f, -10.3876f, 0u, 0, 1, 9, 0, 0, {{14, 1, 1}, {255, 0, 0}}}, {7.5264f, -13.9812f, 1.0f, 8.0764f, -14.4312f, 2u, 0, 0, 9, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {14.52f, -3.774f, 1.0f, 14.52f, -4.624f, 4096u, 0, 3, 5, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {-9.744f, -7.2936f, 1.0f, -9.744f, -7.9936f, 0u, 0, 0, 7, 0, 0, {{7, 0, 0}, {255, 0, 0}}}, {-5.8644f, -7.4772f, 1.0f, -5.8644f, -8.1772f, 8192u, 0, 0, 7, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {-7.728f, -7.6668f, 1.0f, -7.728f, -8.0168f, 4096u, 0, 0, 7, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {-9.792f, -9.8988f, 1.0f, -9.792f, -10.5488f, 131072u, 0, 0, 7, 1, 1, {{255, 0, 0}, {255, 0, 0}}}, {-9.0f, -7.2936f, 1.0f, -9.0f, -7.9936f, 16384u, 0, 0, 7, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {-22.536f, -2.4996f, 1.0f, -22.436f, -2.7496f, 32768u, 0, 2, 3, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {-21.792f, -5.5728f, 1.0f, -21.592f, -5.1728f, 16u, 0, 2, 3, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {-21.276f, -1.3368f, 1.0f, -21.276f, -1.9868f, 65536u, 0, 0, 3, 0, 1, {{255, 0, 0}, {255, 0, 0}}}, {-21.288f, -9.0168f, 1.0f, -21.288f, -8.8168f, 65536u, 0, 1, 3, 0, 1, {{255, 0, 0}, {255, 0, 0}}}, {0.8292f, -16.692f, 1.0f, 0.7292f, -16.692f, 0u, 0, 0, 1, 0, 0, {{9, 1, 1}, {10, 1, 1}}}, {-1.932f, -8.7204f, 1.0f, -1.932f, -9.3204f, 4096u, 0, 1, 1, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {-2.844f, -13.8924f, 1.0f, -3.344f, -13.8924f, 0u, 0, 0, 1, 0, 0, {{2, 0, 0}, {2, 2, 2}}}, {-17.9988f, -9.2532f, 1.0f, -17.9988f, -9.7532f, 0u, 0, 1, 13, 0, 0, {{14, 1, 1}, {255, 0, 0}}}, {-18.3132f, -12.5388f, 1.8f, -17.9632f, -12.6388f, 0u, 0, 0, 13, 0, 0, {{2, 3, 3}, {255, 0, 0}}}, {-19.1508f, -12.618f, 1.0f, -18.8008f, -13.368f, 2048u, 0, 1, 13, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {-15.5592f, -4.5924f, 1.0f, -15.5592f, -5.0924f, 4096u, 0, 5, 11, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {-18.3384f, -0.335508f, 1.8f, -17.9884f, -0.435508f, 0u, 0, 0, 4, 0, 0, {{2, 1, 1}, {255, 0, 0}}}, {-19.176f, -0.414422f, 1.0f, -19.176f, -1.16442f, 2048u, 0, 0, 4, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {-17.226f, 3.14866f, 1.0f, -17.226f, 2.69866f, 0u, 0, 1, 4, 0, 0, {{14, 1, 1}, {255, 0, 0}}}, {4.2024f, -17.1156f, 1.0f, 4.2024f, -16.6156f, 524288u, 0, 0, 14, 0, 1, {{255, 0, 0}, {255, 0, 0}}}, {6.1704f, -14.0916f, 1.0f, 5.6704f, -14.0916f, 0u, 0, 1, 14, 1, 0, {{14, 1, 1}, {255, 0, 0}}}, {3.8784f, -13.9596f, 1.1f, 4.6284f, -13.9596f, 0u, 0, 1, 14, 1, 0, {{7, 0, 0}, {255, 0, 0}}}, {-13.056f, -2.454f, 1.0f, -12.906f, -3.104f, 0u, 3, 0, 0, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {-12.0816f, -3.054f, 1.0f, -12.3816f, -3.354f, 0u, 0, 1, 11, 0, 0, {{14, 1, 1}, {255, 0, 0}}}, {-6.144f, -4.26f, 1.0f, -6.444f, -4.86f, 256u, 0, 0, 10, 0, 0, {{255, 0, 0}, {255, 0, 0}}}, {-7.3284f, -5.2476f, 1.0f, -7.3284f, -5.2476f, 1u, 0, 0, 10, 0, 0, {{255, 0, 0}, {255, 0, 0}}}};+/* 0 UploadDataConsole, 1 NoOxyConsole, 2 FixWiringConsole, 3 SwipeCardConsole, 4 MapRoomConsole, 5 GarbageConsole, 6 FixWiringConsole, 7 DataConsole, 8 EmergencyConsole, 9 StabilizeSteeringConsole, 10 ChartCourseConsole, 11 UploadDataConsole, 12 DivertPowerConsole, 13 WeaponConsole, 14 DivertPowerConsole, 15 UploadDataConsole, 16 GarbageConsole, 17 DivertPowerConsole, 18 CleanFilterConsole, 19 NoOxyConsole, 20 DivertPowerConsole, 21 ShieldConsole, 22 FixWiringConsole, 23 UploadDataConsole, 24 CalibrateConsole, 25 FixWiringConsole, 26 SwitchConsole, 27 DivertPowerConsole, 28 UnlockManifoldsConsole, 29 StartReactorConsole, 30 UpperHandConsole, 31 LowerHandConsole, 32 AirlockConsole, 33 FixWiringConsole, 34 gasCanConsole, 35 DivertPowerConsole, 36 FuelEngineConsole, 37 AlignEngineConsole, 38 FixWiringConsole, 39 FuelEngineConsole, 40 AlignEngineConsole, 41 DivertPowerConsole, 42 FixCommsConsole, 43 DivertPowerConsole, 44 UploadDataConsole, 45 SurvConsole, 46 DivertPowerConsole, 47 MedBayConsole, 48 MedScanner */+#define N_VENTS 14+static const VentRec VENTS[14] = {{2.544f, -9.9552f, 2.544f, -9.9552f, {2, 1, -1}}, {9.384f, -6.438f, 9.384f, -6.438f, {0, 2, -1}}, {4.2588f, -0.276f, 4.2588f, -0.276f, {0, 1, -1}}, {-9.7764f, -8.034f, -9.7764f, -8.034f, {5, 6, -1}}, {-15.288f, 2.52f, -15.288f, 2.52f, {11, -1, -1}}, {-12.534f, -6.9492f, -12.534f, -6.9492f, {6, 3, -1}}, {-10.608f, -4.176f, -10.608f, -4.176f, {5, 3, -1}}, {8.82f, 3.324f, 8.82f, 3.324f, {-1, 12, -1}}, {-20.796f, -6.9528f, -20.796f, -6.9528f, {9, -1, -1}}, {-15.2508f, -13.656f, -15.2508f, -13.656f, {8, -1, -1}}, {9.5232f, -14.3376f, 9.5232f, -14.3376f, {13, -1, -1}}, {-21.876f, -3.0516f, -21.876f, -3.0516f, {4, -1, -1}}, {16.008f, -3.168f, 16.008f, -3.168f, {-1, 7, -1}}, {16.008f, -6.384f, 16.008f, -6.384f, {-1, 10, -1}}};+/* 0 AdminVent, 1 BigYVent, 2 CafeVent, 3 ElecVent, 4 LEngineVent, 5 LifeSuppVent, 6 MedVent, 7 WeaponsVent, 8 ReactorVent, 9 REngineVent, 10 ShieldsVent, 11 UpperReactorVent, 12 NavVentNorth, 13 NavVentSouth */+#define N_CAMS 4+static const CamRec CAMS[4] = {{0.7144f, -6.072f, 2.35f, 1.0f}, {12.79f, -3.086f, 3.1f, 1.0f}, {-6.8848f, 2.9648f, 1.8f, 2.0f}, {-17.8792f, -4.3176f, 2.0f, 1.0f}};+#endifdiff --git a/games/amongus/tests/play.c b/games/amongus/tests/play.cnew file mode 100644index 00000000..7b6bbae6--- /dev/null+++ b/games/amongus/tests/play.c@@ -0,0 +1,137 @@+/* Plays Among Us on a computer, with scripted keys, and saves frames.+ *+ * play [--frames N] [--keys "10-40:right,50:ok,..."] [--shots 30,60|every:N] [--out DIR] [--saves DIR]+ * [--start crew|imp] [--auto] [--fuzz SEED] [--seed N] [--draw] [--trace N] [--bots N]+ *+ * Keys: left right up down ok exe back home tool 0-9. "a-b:key" holds the key from frame a to b, "a:key" for one+ * frame (a frame is a game tick, 1/30 s). --start begins a game past the menus, as a crewmate or an impostor.+ * --auto lets the bots' brain play the player too (a whole game to its end). --fuzz presses random keys.+ * Screenshots are DIR/shot_<frame>.ppm. At the end: END screen S winner W reason R t T alive A tasks P. */+#include <math.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <sys/stat.h>+#include "../src/game.h"+#include "../src/gfx.h"+#include "../src/plat.h"++extern uint32_t host_keys, host_time;+extern bool game_running, autopilot;+void host_shot(const char *path);+void host_save_dir(const char *d);++typedef struct { int a, b; uint32_t k; } Hold;+static Hold holds[4096];+static int nholds;+static int shots[4096], nshots, every;++static uint32_t key_of(const char *s) {+ static const char *const names[] = {"left", "right", "up", "down", "ok", "exe", "back", "home", "tool"};+ static const uint32_t bits[] = {K_LEFT, K_RIGHT, K_UP, K_DOWN, K_OK, K_EXE, K_BACK, K_HOME, K_TOOL};+ for (int i = 0; i < 9; i++)+ if (!strcmp(s, names[i])) return bits[i];+ if (s[0] >= '0' && s[0] <= '9' && !s[1]) return (uint32_t)K_D0 << (s[0] - '0');+ fprintf(stderr, "unknown key %s\n", s);+ exit(2);+}++static void parse_keys(const char *spec) {+ static char buf[65536];+ snprintf(buf, sizeof buf, "%s", spec);+ for (char *tok = strtok(buf, ","); tok; tok = strtok(NULL, ",")) {+ int a, b;+ char k[16];+ if (sscanf(tok, "%d-%d:%15s", &a, &b, k) == 3) holds[nholds++] = (Hold){a, b, key_of(k)};+ else if (sscanf(tok, "%d:%15s", &a, k) == 2) holds[nholds++] = (Hold){a, a, key_of(k)};+ }+}++static uint32_t frng = 1;+static uint32_t frnd(void) {+ frng ^= frng << 13, frng ^= frng >> 17, frng ^= frng << 5;+ return frng;+}++int main(int argc, char **argv) {+ int frames = 300, trace = 0, start = 0, bots = -1;+ uint32_t seed = 0;+ bool fuzz = false, draw = false;+ const char *out = "build/shots";+ for (int i = 1; i < argc; i++) {+ if (!strcmp(argv[i], "--frames")) frames = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--keys")) parse_keys(argv[++i]);+ else if (!strcmp(argv[i], "--out")) out = argv[++i];+ else if (!strcmp(argv[i], "--saves")) host_save_dir(argv[++i]);+ else if (!strcmp(argv[i], "--start")) start = !strcmp(argv[++i], "imp") ? 2 : 1;+ else if (!strcmp(argv[i], "--auto")) autopilot = true;+ else if (!strcmp(argv[i], "--draw")) draw = true;+ else if (!strcmp(argv[i], "--trace")) trace = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--seed")) seed = (uint32_t)atoi(argv[++i]);+ else if (!strcmp(argv[i], "--bots")) bots = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--fuzz")) fuzz = true, frng = (uint32_t)atoi(argv[++i]) * 2654435761u + 1;+ else if (!strcmp(argv[i], "--shots")) {+ const char *s = argv[++i];+ if (!strncmp(s, "every:", 6)) every = atoi(s + 6);+ else+ for (const char *p = s; *p;) {+ shots[nshots++] = atoi(p);+ p = strchr(p, ',');+ if (!p) break;+ p++;+ }+ }+ }+ mkdir(out, 0755);+ static uint16_t band[SCREEN_W * BAND];+ gfx_init(band);+ host_time = 1000 + seed * 7919;+ game_init();+ if (start) {+ if (bots >= 0) g.opt.bots = (uint8_t)bots;+ g.opt.role = (uint8_t)start;+ g.rng = seed * 2654435761u + 77;+ game_new();+ }+ uint32_t fk = 0;+ static int hist[16];+ for (int f = 0; f < frames && game_running; f++) {+ uint32_t k = 0;+ for (int i = 0; i < nholds; i++)+ if (f >= holds[i].a && f <= holds[i].b) k |= holds[i].k;+ if (fuzz) {+ if (frnd() % 6 == 0) {+ uint32_t r = frnd();+ fk = r & (K_LEFT | K_RIGHT | K_UP | K_DOWN | K_OK | K_EXE | K_TOOL);+ if (frnd() % 12 == 0) fk |= K_BACK;+ if (frnd() % 10 == 0) fk |= (uint32_t)K_D0 << (frnd() % 10);+ }+ k = fk;+ }+ if (autopilot && (g.screen == S_INTRO || g.screen == S_EJECT) && f % 20 == 0) k |= K_OK;+ host_keys = k;+ hist[g.screen & 15]++;+ game_tick(k);+ host_time += 33;+ bool shot = every ? f % every == 0 : false;+ for (int i = 0; i < nshots; i++) shot |= shots[i] == f;+ if (shot || draw) game_draw();+ if (shot) {+ char p[512];+ snprintf(p, sizeof p, "%s/shot_%04d.ppm", out, f);+ host_shot(p);+ }+ if (trace && f % trace == 0)+ printf("t%5d screen %d ov %d me (%.2f %.2f) room %d alive %d imp %d sab %d tasks %.2f\n", f, g.screen, g.overlay,+ g.p[g.me].pos.x, g.p[g.me].pos.y, g.p[g.me].room, g.p[g.me].alive, g.p[g.me].imp, g.sab, tasks_progress());+ if (g.screen == S_END && autopilot && g.screen_t > 1) break;+ }+ if (fuzz)+ printf("SCREENS title %d lobby %d intro %d play %d report %d meeting %d eject %d end %d howto %d pause %d killed %d\n",+ hist[0], hist[1], hist[2], hist[3], hist[4], hist[5], hist[6], hist[7], hist[8], hist[9], hist[10]);+ int alive = 0;+ for (int i = 0; i < g.nplayers; i++) alive += g.p[i].alive;+ printf("END screen %d winner %d reason %d t %.1f alive %d tasks %.2f imp %d\n", g.screen, g.winner, g.end_reason, g.t,+ alive, tasks_progress(), g.p[g.me].imp);+ return 0;+}diff --git a/games/amongus/tools/pack.py b/games/amongus/tools/pack.pynew file mode 100644index 00000000..9237f0ef--- /dev/null+++ b/games/amongus/tools/pack.py@@ -0,0 +1,519 @@+#!/usr/bin/env python3+"""Packs Among Us' src/data.bin, src/data.h and src/world.h from the art taken out of the game (REF), read only:++ python3 -I tools/pack.py REF++REF is the folder the extraction scripts wrote (ship.png, ship.json, ship/, spr/, spr.json, ui/, ui.json, fonts/):+the game's own pictures at 40 px a unit, the Skeld's walls, rooms, consoles, vents, doors and cameras.+Python 3 with Pillow and NumPy."""+import json+import math+import os+import struct+import sys++import numpy as np+from PIL import Image, ImageDraw, ImageFont++HERE = os.path.dirname(os.path.abspath(__file__))+SRC = os.path.join(HERE, "..", "src")+REF = sys.argv[1] if len(sys.argv) > 1 else "."+PPU = 40.0+++def rgb565(r, g, b):+ return ((int(r) >> 3) << 11) | ((int(g) >> 2) << 5) | (int(b) >> 3)+++# ---- colour quantization: median cut, then k-means ----++def quantize(px, n, alpha=True):+ """px: (N, 4) uint8 RGBA. Returns (palette (K, 4) uint8, index (N,) uint8); entry 0 is clear when any pixel is."""+ px = np.asarray(px, dtype=np.uint8).reshape(-1, 4)+ clear = px[:, 3] < 8 if alpha else np.zeros(len(px), bool)+ solid = px[~clear].astype(np.int32)+ has_clear = bool(clear.any())+ k = n - (1 if has_clear else 0)+ if len(solid):+ if not alpha:+ solid[:, 3] = 255+ cols, inv, cnt = np.unique(solid, axis=0, return_inverse=True, return_counts=True)+ inv = inv.reshape(-1)+ if len(cols) <= k:+ centers = cols.astype(np.float64)+ lab = inv+ else:+ w = np.array([1.0, 1.2, 0.8, 1.5])+ pts = cols.astype(np.float64) * w+ boxes = [np.arange(len(cols))]+ while len(boxes) < k:+ best, bi = -1, -1+ for i, b in enumerate(boxes):+ if len(b) < 2:+ continue+ rng = (pts[b].max(0) - pts[b].min(0)).max() * math.sqrt(cnt[b].sum())+ if rng > best:+ best, bi = rng, i+ if bi < 0:+ break+ b = boxes.pop(bi)+ ch = np.argmax(pts[b].max(0) - pts[b].min(0))+ order = b[np.argsort(pts[b, ch], kind="stable")]+ cum = np.cumsum(cnt[order])+ cut = int(np.searchsorted(cum, cum[-1] / 2))+ cut = min(max(cut, 1), len(order) - 1)+ boxes += [order[:cut], order[cut:]]+ centers = np.array([(pts[b] * cnt[b, None]).sum(0) / cnt[b].sum() for b in boxes])+ for _ in range(6):+ d = ((pts[:, None, :] - centers[None, :, :]) ** 2).sum(2) if len(pts) * len(centers) < 4e7 else None+ if d is None:+ break+ lab = d.argmin(1)+ for j in range(len(centers)):+ m = lab == j+ if m.any():+ centers[j] = (pts[m] * cnt[m, None]).sum(0) / cnt[m].sum()+ d = ((pts[:, None, :] - centers[None, :, :]) ** 2).sum(2)+ lab = d.argmin(1)+ centers = centers / w+ pal = np.clip(np.round(centers), 0, 255).astype(np.uint8)+ idx = np.zeros(len(px), np.uint8)+ idx[~clear] = lab[inv] + (1 if has_clear else 0)+ else:+ pal = np.zeros((0, 4), np.uint8)+ idx = np.zeros(len(px), np.uint8)+ if has_clear:+ pal = np.vstack([np.zeros((1, 4), np.uint8), pal])+ return pal, idx+++# ---- pictures: "Pic" {w, h, ox, oy, ncolors, flags}, RGB565 colours, alphas, then pixels ----++P_4BIT, P_OPAQUE, P_MIX = 1, 2, 4+++class Pics:+ def __init__(self):+ self.blobs = []+ self.ids = {}++ def add(self, name, im, pivot=(0, 0), bits=8, opaque=False):+ im = im.convert("RGBA")+ a = np.asarray(im).reshape(-1, 4)+ ncol = 16 if bits == 4 else 256+ pal, idx = quantize(a, ncol, alpha=not opaque)+ flags = (P_4BIT if bits == 4 else 0) | (P_OPAQUE if opaque or (pal[:, 3] == 255).all() else 0)+ self._put(name, im.size, pivot, pal, idx, flags)+ return self.ids[name]++ def _put(self, name, size, pivot, pal, idx, flags):+ w, h = size+ head = struct.pack("<HHhhBBH", w, h, int(round(pivot[0])), int(round(pivot[1])), len(pal) & 255, flags, 0)+ body = b""+ if not flags & P_MIX:+ body += struct.pack("<%dH" % len(pal), *[rgb565(*c[:3]) for c in pal])+ body += bytes(int(c[3]) for c in pal)+ body += b"\0" * (-(len(head) + len(body)) % 4)+ idx = np.asarray(idx, np.uint8).reshape(h, w)+ if flags & P_4BIT:+ if w & 1:+ idx = np.hstack([idx, np.zeros((h, 1), np.uint8)])+ body += ((idx[:, 0::2] << 4) | idx[:, 1::2]).astype(np.uint8).tobytes()+ else:+ body += idx.tobytes()+ blob = head + body+ blob += b"\0" * (-len(blob) % 4)+ assert name not in self.ids, name+ self.ids[name] = len(self.blobs)+ self.blobs.append(blob)+++# ---- fonts: Font {first, count, height, ascent}, Glyph[], 4-bit coverage ----++def make_font(path, size, first=32, last=126, bold=0):+ f = ImageFont.truetype(path, size)+ asc, desc = f.getmetrics()+ glyphs = []+ bits = b""+ for c in range(first, last + 1):+ ch = chr(c)+ bb = f.getbbox(ch, stroke_width=bold)+ adv = round(f.getlength(ch)) + bold+ if bb[2] <= bb[0] or bb[3] <= bb[1] or ch == " ":+ glyphs.append((0, 0, 0, 0, adv, 0))+ continue+ w, h = bb[2] - bb[0], bb[3] - bb[1]+ im = Image.new("L", (w, h), 0)+ ImageDraw.Draw(im).text((-bb[0], -bb[1]), ch, font=f, fill=255, stroke_width=bold, stroke_fill=255)+ data = bytes(v * 15 // 255 for v in im.tobytes())+ packed = bytes((data[i] << 4) | (data[i + 1] if i + 1 < len(data) else 0) for i in range(0, len(data), 2))+ glyphs.append((w, h, bb[0], bb[1] - asc, adv, len(bits)))+ bits += packed+ out = struct.pack("<BBBB", first, last - first + 1, asc + desc, asc)+ for g in glyphs:+ out += struct.pack("<BBbbBBHI", g[0], g[1], g[2], g[3], g[4], 0, 0, g[5])+ out += bits+ out += b"\0" * (-len(out) % 4)+ return out+++# ---- the Skeld's floor: 16x16 tiles of 16 colours each, the same tiles stored once ----++TILE = 16+++def make_ship(im):+ bg = Image.new("RGBA", im.size, (0, 0, 0, 255))+ bg.alpha_composite(im)+ alpha = np.asarray(im)[:, :, 3]+ rgb = np.asarray(bg.convert("RGB"))+ W, H = im.size+ tw, th = (W + TILE - 1) // TILE, (H + TILE - 1) // TILE+ rgb = np.pad(rgb, ((0, th * TILE - H), (0, tw * TILE - W), (0, 0)))+ alpha = np.pad(alpha, ((0, th * TILE - H), (0, tw * TILE - W)))+ tmap = []+ tiles = []+ seen = {}+ err = 0.0+ for ty in range(th):+ for tx in range(tw):+ a = alpha[ty * TILE:(ty + 1) * TILE, tx * TILE:(tx + 1) * TILE]+ if a.max() < 8:+ tmap.append(0xFFFF)+ continue+ t = rgb[ty * TILE:(ty + 1) * TILE, tx * TILE:(tx + 1) * TILE].reshape(-1, 3)+ px = np.hstack([t, np.full((len(t), 1), 255, np.uint8)])+ pal, idx = quantize(px, 16, alpha=False)+ err += float(((pal[idx][:, :3].astype(float) - t) ** 2).sum())+ p = [rgb565(*c[:3]) for c in pal] + [0] * (16 - len(pal))+ idx = idx.reshape(TILE, TILE)+ data = struct.pack("<16H", *p) + ((idx[:, 0::2] << 4) | idx[:, 1::2]).astype(np.uint8).tobytes()+ if data not in seen:+ seen[data] = len(tiles)+ tiles.append(data)+ tmap.append(seen[data])+ assert len(tiles) < 0xFFFF+ head = struct.pack("<HHII", tw, th, len(tiles), 12 + 2 * len(tmap) + (-(2 * len(tmap)) % 4))+ blob = head + struct.pack("<%dH" % len(tmap), *tmap)+ blob += b"\0" * (-len(blob) % 4)+ blob += b"".join(tiles)+ print("ship: %dx%d tiles, %d stored, %d bytes, rms %.1f" % (tw, th, len(tiles), len(blob),+ math.sqrt(err / max(1, len(tiles) * 768))))+ return blob+++# ---- the player's pictures: indices into one table of body/visor/shadow mixes, coloured at run time ----++class Mix:+ """frames of the player (the game colours red as the body, green as the visor, blue as the shadow)"""++ def __init__(self):+ self.frames = [] # (name, im, pivot)++ def add(self, name, im, pivot):+ self.frames.append((name, im.convert("RGBA"), pivot))++ def pack(self, pics):+ allpx = np.vstack([np.asarray(im).reshape(-1, 4) for _, im, _ in self.frames])+ pal, _ = quantize(allpx, 256)+ pf = pal.astype(np.float64)+ for name, im, pivot in self.frames:+ a = np.asarray(im).reshape(-1, 4).astype(np.float64)+ d = ((a[:, None, :] - pf[None, :, :]) ** 2 * np.array([1, 1, 1, 2])).sum(2)+ idx = d.argmin(1).astype(np.uint8)+ idx[a[:, 3] < 8] = 0+ pics._put(name, im.size, pivot, pal, idx, P_MIX)+ table = b"".join(struct.pack("<4B", *[int(v) for v in c]) for c in pal)+ table += b"\0" * (4 * (256 - len(pal)))+ return table, len(pal)+++# ---- the world: walls, light walls, rooms, consoles, vents, doors, cameras, the bots' walking grid ----++def seg_grid(segs, x0, y0, gw, gh, margin):+ cells = [[] for _ in range(gw * gh)]+ for i, s in enumerate(segs):+ ax, ay, bx, by = s+ c0 = max(0, int(math.floor(min(ax, bx) - margin - x0)))+ c1 = min(gw - 1, int(math.floor(max(ax, bx) + margin - x0)))+ r0 = max(0, int(math.floor(min(ay, by) - margin - y0)))+ r1 = min(gh - 1, int(math.floor(max(ay, by) + margin - y0)))+ for r in range(r0, r1 + 1):+ for c in range(c0, c1 + 1):+ cells[r * gw + c].append(i)+ start, idx = [], []+ for c in cells:+ start.append(len(idx))+ idx += c+ start.append(len(idx))+ return start, idx+++def point_seg_dist(px, py, segs):+ """distances from points (N,) to segments (M, 4): (N, M)"""+ a = segs[:, 0:2][None, :, :]+ b = segs[:, 2:4][None, :, :]+ p = np.stack([px, py], 1)[:, None, :]+ ab = b - a+ t = ((p - a) * ab).sum(2) / np.maximum((ab * ab).sum(2), 1e-12)+ t = np.clip(t, 0, 1)+ q = a + ab * t[:, :, None]+ return np.sqrt(((p - q) ** 2).sum(2))+++def seg_cross(p, q, segs):+ """does p-q cross any of the segments"""+ a, b = segs[:, 0:2], segs[:, 2:4]++ def orient(u, v, w):+ return (v[..., 0] - u[..., 0]) * (w[..., 1] - u[..., 1]) - (v[..., 1] - u[..., 1]) * (w[..., 0] - u[..., 0])+ p = np.asarray(p, float)+ q = np.asarray(q, float)+ d1 = orient(a, b, p[None])+ d2 = orient(a, b, q[None])+ d3 = orient(p[None], q[None], a)+ d4 = orient(p[None], q[None], b)+ return bool((((d1 > 0) != (d2 > 0)) & ((d3 > 0) != (d4 > 0))).any())+++def fl(v):+ t = "%.6g" % float(v)+ return (t if ("." in t or "e" in t) else t + ".0") + "f"+++def make_world(m, out):+ walls = np.array(m["walls"], float)+ shadows = np.array(m["shadows"], float)+ doors = m["doors"]+ door_segs = np.array([s for d in doors for s in d["segs"]], float)+ gx0, gy0 = -27.0, -21.0+ gw, gh = 50, 30+ lines = []+ w = lines.append+ w("/* Among Us: the Skeld's walls, rooms, consoles, vents, doors and cameras (made by tools/pack.py from the")+ w(" * game's ShipStatus prefab) */")+ w("#ifndef AU_WORLD_H\n#define AU_WORLD_H\n#include \"ship.h\"")+ w("#define GRID_X0 %s\n#define GRID_Y0 %s\n#define GRID_W %d\n#define GRID_H %d" % (fl(gx0), fl(gy0), gw, gh))+ for name, segs, margin in (("WALL", walls, 0.35), ("SHADOW", shadows, 0.05)):+ start, idx = seg_grid(segs, gx0, gy0, gw, gh, margin)+ w("#define N_%s %d" % (name, len(segs)))+ w("static const Seg %s_SEGS[%d] = {%s};" % (name, len(segs), ", ".join(+ "{%s, %s, %s, %s}" % tuple(fl(v) for v in s) for s in segs)))+ w("static const uint16_t %s_START[%d] = {%s};" % (name, len(start), ", ".join(map(str, start))))+ w("static const uint16_t %s_IDX[%d] = {%s};" % (name, len(idx), ", ".join(map(str, idx))))+ # doors+ w("#define N_DOORS %d" % len(doors))+ w("static const DoorRec DOORS[%d] = {%s};" % (len(doors), ", ".join(+ "{%s, %s, %d, %d, {%s}}" % (fl(d["x"]), fl(d["y"]), d["room"], 1 if d["kind"] == "front" else 0,+ ", ".join("{%s}" % ", ".join(fl(v) for v in s) for s in d["segs"]))+ for d in doors)))+ # rooms (the area colliders, for the room's name and who is where)+ pts = []+ recs = []+ for r in m["rooms"]:+ for poly in r["area"]:+ recs.append((r["id"], len(pts), len(poly), r["name"]))+ pts += poly+ w("#define N_AREAS %d" % len(recs))+ w("static const AreaRec AREAS[%d] = {%s};" % (len(recs), ", ".join("{%d, %d, %d}" % r[:3] for r in recs)))+ w("static const V2 AREA_PTS[%d] = {%s};" % (len(pts), ", ".join("{%s, %s}" % (fl(p[0]), fl(p[1])) for p in pts)))++ # the bots' grid: cells of half a unit a player can stand in, reached from the spawn+ NX0, NY0, CS = -26.0, -20.0, 0.5+ nw, nh = 96, 58+ cx = NX0 + (np.arange(nw) + 0.5) * CS+ cy = NY0 + (np.arange(nh) + 0.5) * CS+ gxx, gyy = np.meshgrid(cx, cy)+ px, py = gxx.reshape(-1), gyy.reshape(-1)+ allw = np.vstack([walls, door_segs])+ dmin = np.full(len(px), 99.0)+ for i in range(0, len(walls), 64):+ dmin = np.minimum(dmin, point_seg_dist(px, py, walls[i:i + 64]).min(1))+ clear = (dmin >= 0.2).reshape(nh, nw)+ # flood from the spawn, through moves that cross no wall+ sx, sy = int((-0.72 - NX0) / CS), int((0.62 - 1.6 - NY0) / CS)+ reach = np.zeros((nh, nw), bool)+ stack = [(sx, sy)]+ assert clear[sy, sx]+ reach[sy, sx] = True+ near = {}+ while stack:+ x, y = stack.pop()+ for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (1, -1), (-1, 1), (-1, -1)):+ nx, ny = x + dx, y + dy+ if not (0 <= nx < nw and 0 <= ny < nh) or reach[ny, nx] or not clear[ny, nx]:+ continue+ if dx and dy and not (clear[y, nx] and clear[ny, x]):+ continue+ p = (cx[x], cy[y])+ q = (cx[nx], cy[ny])+ if seg_cross(p, q, walls):+ continue+ reach[ny, nx] = True+ stack.append((nx, ny))+ walk = reach+ print("nav: %d cells walkable" % walk.sum())+ bitsrow = (nw + 7) // 8+ nav = bytearray(bitsrow * nh)+ for y in range(nh):+ for x in range(nw):+ if walk[y, x]:+ nav[y * bitsrow + x // 8] |= 1 << (x & 7)+ w("#define NAV_X0 %s\n#define NAV_Y0 %s\n#define NAV_CS %s\n#define NAV_W %d\n#define NAV_H %d" % (+ fl(NX0), fl(NY0), fl(CS), nw, nh))+ w("static const uint8_t NAV_BITS[%d] = {%s};" % (len(nav), ", ".join(map(str, nav))))++ def stand_point(x, y, dist, below):+ """where a bot stands to use something at (x, y): clear of walls, in reach, and a straight walk from a+ walkable cell"""+ best = None+ g = np.arange(-dist, dist + 1e-6, 0.05)+ qx, qy = np.meshgrid(x + g, y + g)+ qx, qy = qx.reshape(-1), qy.reshape(-1)+ d = np.hypot(qx - x, qy - y)+ ok = d <= dist * 0.9+ if below:+ ok &= qy <= y+ qx, qy, d = qx[ok], qy[ok], d[ok]+ near = walls[(np.minimum(walls[:, 0], walls[:, 2]) < x + 3) & (np.maximum(walls[:, 0], walls[:, 2]) > x - 3) &+ (np.minimum(walls[:, 1], walls[:, 3]) < y + 3) & (np.maximum(walls[:, 1], walls[:, 3]) > y - 3)]+ cl = point_seg_dist(qx, qy, near).min(1) if len(near) else np.full(len(qx), 9.0)+ cells = [(cx[xx], cy[yy]) for yy in range(nh) for xx in range(nw)+ if walk[yy, xx] and abs(cx[xx] - x) < dist + 1.5 and abs(cy[yy] - y) < dist + 1.5]+ for k in np.argsort(d):+ if cl[k] < 0.18:+ continue+ for c in sorted(cells, key=lambda c: math.hypot(c[0] - qx[k], c[1] - qy[k])):+ if math.hypot(c[0] - qx[k], c[1] - qy[k]) > 1.2:+ break+ if not seg_cross(c, (qx[k], qy[k]), near):+ best = (qx[k], qy[k])+ break+ if best:+ break+ if best is None:+ print("note: nothing to stand on near (%.2f, %.2f)" % (x, y))+ return x, y+ return best++ # consoles+ KIND = {"task": 0, "MapRoomConsole": 1, "EmergencyConsole": 2, "SurvConsole": 3}+ cons = [c for c in m["consoles"] if c["kind"] in KIND]+ rows = []+ for c in cons:+ tmask = 0+ for t in c.get("types", []):+ tmask |= 1 << t+ valid = [(v["taskType"], v["taskStep"]["min"], v["taskStep"]["max"]) for v in c.get("valid", [])]+ valid += [(255, 0, 0)] * (2 - len(valid))+ sx_, sy_ = stand_point(c["x"], c["y"], c["dist"], c["below"])+ rows.append("{%s, %s, %s, %s, %s, %du, %d, %d, %d, %d, %d, {{%d, %d, %d}, {%d, %d, %d}}}" % (+ fl(c["x"]), fl(c["y"]), fl(c["dist"]), fl(sx_), fl(sy_), tmask, KIND[c["kind"]], c.get("id", 0),+ c.get("room", 0), c["below"], c.get("imp", 0), *valid[0], *valid[1]))+ w("#define N_CONSOLES %d" % len(cons))+ w("static const ConsoleRec CONSOLES[%d] = {%s};" % (len(cons), ", ".join(rows)))+ w("/* " + ", ".join("%d %s" % (i, c["name"]) for i, c in enumerate(cons)) + " */")+ # vents+ vents = m["vents"]+ vrows = []+ for v in vents:+ sx_, sy_ = stand_point(v["x"], v["y"], 0.75, 0)+ vrows.append("{%s, %s, %s, %s, {%d, %d, %d}}" % (fl(v["x"]), fl(v["y"]), fl(sx_), fl(sy_), *v["links"]))+ w("#define N_VENTS %d" % len(vents))+ w("static const VentRec VENTS[%d] = {%s};" % (len(vents), ", ".join(vrows)))+ w("/* " + ", ".join("%d %s" % (v["id"], v["name"]) for v in vents) + " */")+ cams = m["cams"]+ w("#define N_CAMS %d" % len(cams))+ w("static const CamRec CAMS[%d] = {%s};" % (len(cams), ", ".join(+ "{%s, %s, %s, %s}" % (fl(c["x"] + c["off"][0]), fl(c["y"] + c["off"][1]), fl(c["size"]), fl(c["aspect"]))+ for c in cams)))+ w("#endif")+ open(out, "w").write("\n".join(lines) + "\n")+++def main():+ pics = Pics()+ named = {}+ # the ship+ sm = json.load(open(os.path.join(REF, "ship.json")))+ ship_blob = make_ship(Image.open(os.path.join(REF, "ship.png")))+ ox, oy = sm["origin"]+ # objects in front of players behind them+ front = []+ for f in sm["front"]:+ im = Image.open(os.path.join(REF, "ship", f["img"] + ".png"))+ pid = pics.add("front_" + f["img"], im, (0, 0), bits=4)+ front.append((pid, f["x"], f["y"], f["z"], f["name"]))+ door_ids = {}+ for kind in ("side", "front"):+ dm = sm["door_" + kind]+ ids = []+ for i, fr in enumerate(dm["frames"]):+ im = Image.open(os.path.join(REF, "ship", "door_%s%02d.png" % (kind, i)))+ ids.append(pics.add("door_%s%02d" % (kind, i), im, (-fr["dx"], -fr["dy"]), bits=4))+ door_ids[kind] = ids+ vent_ids = []+ for i, fr in enumerate(sm["vent_frames"]):+ im = Image.open(os.path.join(REF, "ship", "vent%02d.png" % i))+ vent_ids.append(pics.add("vent%02d" % i, im, (-fr["dx"], -fr["dy"]), bits=4))+ # the player's frames, at 0.7 (the player's scale) x 0.4+ spr = json.load(open(os.path.join(REF, "spr.json")))+ mix = Mix()++ def mixframe(name, scale=0.28):+ im = Image.open(os.path.join(REF, "spr", name + ".png")).convert("RGBA")+ piv = spr[name]["pivot"]+ k = scale * 100.0 / spr[name]["ppu"]+ w, h = max(1, round(im.width * k)), max(1, round(im.height * k))+ mix.add(name, im.resize((w, h), Image.LANCZOS), (piv[0] * w / im.width, piv[1] * h / im.height))+ mixframe("idle")+ for i in range(1, 13):+ mixframe("walkcolor%04d" % i)+ for i in range(1, 49, 2):+ mixframe("ghostbob%04d" % i)+ mixframe("Dead0040")+ for i in range(1, 8):+ mixframe("getinVent%04d" % i)+ mix_table, nmix = mix.pack(pics)+ # fonts+ fdir = os.path.join(REF, "fonts")+ fonts = [make_font(os.path.join(fdir, "LiberationSans-Regular.ttf"), 10),+ make_font(os.path.join(fdir, "LiberationSans-Bold.ttf"), 11),+ make_font(os.path.join(fdir, "LiberationSans-Bold.ttf"), 14),+ make_font(os.path.join(fdir, "LiberationSans-Bold.ttf"), 24)]++ # data.bin: "AUSD", counts, offsets: pictures, fonts, the ship's tiles, the mix table+ blobs = pics.blobs + fonts + [ship_blob, mix_table]+ head = struct.pack("<4sIII", b"AUSD", len(pics.blobs), len(fonts), len(blobs))+ pos = len(head) + 4 * len(blobs)+ offs, body = [], b""+ for b in blobs:+ body += b"\0" * (-(pos + len(body)) % 4)+ offs.append(pos + len(body))+ body += b+ out = head + struct.pack("<%dI" % len(offs), *offs) + body+ open(os.path.join(SRC, "data.bin"), "wb").write(out)+ with open(os.path.join(SRC, "data.h"), "w") as f:+ f.write("/* Among Us: what's in data.bin (made by tools/pack.py) */\n#ifndef AU_DATA_H\n#define AU_DATA_H\n")+ f.write("#define N_PICS %d\n#define N_FONTS %d\n" % (len(pics.blobs), len(fonts)))+ f.write("#define BLOB_SHIP %d\n#define BLOB_MIX %d\n#define N_MIX %d\n" % (len(blobs) - 2, len(blobs) - 1, nmix))+ f.write("enum { FONT_SMALL, FONT_MID, FONT_BIG, FONT_HUGE };\n")+ f.write("#define SHIP_OX %d\n#define SHIP_OY %d\n" % (round(ox), round(oy)))+ f.write("#define PIC_IDLE %d\n#define PIC_WALK %d\n#define PIC_GHOST %d\n#define N_GHOST 24\n#define PIC_DEAD %d\n"+ "#define PIC_JUMP %d\n" % (pics.ids["idle"], pics.ids["walkcolor0001"], pics.ids["ghostbob0001"],+ pics.ids["Dead0040"], pics.ids["getinVent0001"]))+ f.write("#define PIC_DOOR_SIDE %d\n#define PIC_DOOR_FRONT %d\n#define DOOR_CLOSE_FRAMES %d\n"+ "#define DOOR_OPEN_FRAMES %d\n" % (door_ids["side"][0], door_ids["front"][0],+ sm["door_side"]["close"], sm["door_side"]["open"]))+ f.write("#define PIC_VENT %d\n#define N_VENT_FRAMES %d\n" % (vent_ids[0], len(vent_ids)))+ f.write("typedef struct { uint16_t pic; int16_t x, y; float z; } FrontRec;\n")+ f.write("#define N_FRONT %d\nstatic const FrontRec FRONT[%d] = {%s};\n" % (len(front), len(front), ", ".join(+ "{%d, %d, %d, %s}" % (p, x, y, fl(z)) for p, x, y, z, _ in front)))+ f.write("#endif\n")+ make_world(sm, os.path.join(SRC, "world.h"))+ print("data.bin: %d bytes (pictures %d, fonts %d, ship %d)" % (+ len(out), sum(len(b) for b in pics.blobs), sum(len(b) for b in fonts), len(ship_blob)))+++if __name__ == "__main__":+ main()