Skip to content

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

Among Us: the map, the sabotage map and admin, the game's buttons, kills, reports and meetings

Mason363c689aa2fcb85
diff --git a/games/amongus/src/art.c b/games/amongus/src/art.c
index e98072f6..f0697383 100644
--- a/games/amongus/src/art.c
+++ b/games/amongus/src/art.c
@@ -31,10 +31,16 @@ void art_player(int color, float x, float y, float scale, bool flip, int alpha)
else gfx_pic(p, x, y, flip ? -s : s, s, 0, color_pal[color], alpha);
}
+/* the main menu: the logo over space, crewmates drifting by */
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);
+ float t = g.screen_t;
+ for (int k = 0; k < 3; k++) {
+ float x = fmodf(t * (9 + 4 * k) + k * 140, 420) - 50, y = 126 + 6 * sinf(t * 0.5f + k * 2.1f) + (k - 1) * 3;
+ gfx_pic(pic(PIC_IDLE), x, y, 0.9f - 0.12f * k, 0.9f - 0.12f * k, t * (0.6f + 0.25f * k) + k, color_pal[(k * 5 + 1) % N_COLORS],
+ 256);
+ }
+ gfx_spr(pic(PIC_UI_BANNERLOGO_AMONGUS), 160, 62, false, NULL, 256);
}
/* the team in a row, the player in front (IntroCutscene, EndGameManager) */
@@ -54,62 +60,107 @@ void art_lineup(const uint8_t *who, int n, float t) {
}
}
-/* ---- the meeting's tablet ---- */
+/* ---- the meeting's tablet (MeetingHud): its glass from x 15 to 285, y 20 to 207 ---- */
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);
+ gfx_fill(0, gfx_y0, SCREEN_W, BAND, rgb565(0x10141C), 256);
+ gfx_tiles((const TilePic *)unpacked(BLOB_MEETING, 0), 160, 114);
+ gfx_text(FONT_BIG, 150, 35, "Who Is The Impostor?", 0xFFFF, 0x0000, 1, 1);
}
+/* a player's plate (PlayerVoteArea): the head, the name, I Voted, the megaphone of who called it, the X of the dead */
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);
+ if (sel) gfx_fill(x - 2, y - 2, 134, 28, 0xFFE0, 256);
+ gfx_spr(pic(PIC_UI_VOTEPLAYERBASE), x + 65, y + 12, false, NULL, 256);
+ if (dead) gfx_fill(x, y, 128, 22, rgb565(0x7A8794), 150);
+ gfx_spr_clip(pic(PIC_PLATE_PLAYER), x + 15, y + 10, false, color_pal[P->color], dead ? 140 : 256, x, y, x + 130, y + 22);
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);
- }
+ gfx_text(FONT_MID, x + 31, y + 16, COLOR_NAMES[P->color], red ? 0xF800 : 0xFFFF, 0x0000, 1, 0);
+ if (dead) gfx_spr(pic(PIC_UI_DEADX_BORDER), x + 15, y + 11, false, NULL, 256);
+ if (voted) gfx_spr(pic(PIC_UI_I_VOTED), x + 6, y + 6, false, NULL, 256);
+ if (i == g.caller) gfx_spr(pic(PIC_UI_REPORTED), x + 114, y + 11, false, NULL, 256);
}
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);
+ static uint16_t gray[256];
+ if (anon && !gray[1]) gfx_mix_palette(gray, 0x8C8C8C, 0x505050, 0x95CADC);
+ gfx_spr(pic(PIC_VOTE_ICON), x, y, false, anon ? gray : color_pal[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);
+ if (sel) gfx_fill(x - 2, y - 2, 70, 19, 0xFFE0, 256);
+ gfx_spr(pic(PIC_UI_BUTTON_SKIPVOTE_EDIT), x + 33, y + 7, false, NULL, 256);
}
-/* ---- overlays ---- */
+/* the vote's buttons by a plate: the tick and the cross (the one chosen framed) */
+void art_confirm(int x, int y, bool yes) {
+ gfx_fill(x - 1 + (yes ? 0 : 22), y - 1, 21, 21, 0xFFE0, 256);
+ gfx_spr(pic(PIC_UI_VOTECONFIRM), x + 9, y + 9, false, NULL, 256);
+ gfx_spr(pic(PIC_UI_VOTECANCEL), x + 31, y + 9, false, NULL, 256);
+}
-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;
+/* ---- overlays (KillOverlay) ---- */
+
+/* the flames' band, opening from the middle and closing at the end */
+static void flames(float t, float len) {
+ float k = t < 0.2f ? t / 0.2f : t > len - 0.25f ? (len - t) / 0.25f : 1;
+ if (k < 0) k = 0;
+ int h = (int)(73 * k);
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);
+ const TilePic *bg = (const TilePic *)unpacked(BLOB_KILLBG, 0);
+ if (h > 2) {
+ /* (the band's middle rows, as many as it is open) */
+ int y0 = 120 - h > gfx_y0 ? 120 - h : gfx_y0, y1 = 120 + h < gfx_y0 + BAND ? 120 + h : gfx_y0 + BAND;
+ if (y0 < y1) {
+ int save = gfx_y0;
+ (void)save;
+ for (int y = y0; y < y1; y++) {
+ int sy = 73 + (int)((y - 120) / k);
+ uint16_t *row = gfx_band + (y - gfx_y0) * SCREEN_W;
+ for (int x = 0; x < SCREEN_W; x++) {
+ int c = tile_px(bg, x, sy);
+ if (c >= 0) row[x] = (uint16_t)c;
+ }
+ }
+ }
}
}
+/* the tongue kill (KillAnimation_Tongue): the killer's and the victim's frames over the flames */
+void art_kill(float t) {
+ flames(t, 2.6f);
+ if (t < 0.2f || t > 2.35f) return;
+ static uint16_t kp[2][N_KMIX];
+ static uint8_t kc[2] = {0xFF, 0xFF};
+ int col[2] = {g.p[g.killer].color, g.p[g.me].color};
+ for (int k = 0; k < 2; k++)
+ if (kc[k] != col[k]) {
+ gfx_mix_palette_of(BLOB_KMIX, N_KMIX, kp[k], BODY_COLORS[col[k]], SHADOW_COLORS[col[k]], 0x95CADC);
+ kc[k] = (uint8_t)col[k];
+ }
+ int f = (int)((t - 0.2f) * 15);
+ if (f > 23) f = 23;
+ const uint8_t *keep = gfx_mix_alpha;
+ gfx_mix_alpha = (const uint8_t *)blob(BLOB_KMIX) + 3;
+ gfx_spr((const Pic *)unpacked(PIC_KILL_VICTIM + f, 2), 178, 128, false, kp[1], 256);
+ gfx_spr((const Pic *)unpacked(PIC_KILL_IMP + f, 1), 178, 128, false, kp[0], 256);
+ gfx_mix_alpha = keep;
+}
+
+/* "Dead Body Reported" with the body, or "Emergency Meeting" with who called it */
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);
+ flames(t, 2.5f);
+ if (t < 0.2f || t > 2.3f) return;
+ bool body = g.reported != NONE;
+ float s = t < 0.35f ? (t - 0.2f) / 0.15f : 1;
+ if (body) {
+ gfx_pic(pic(PIC_UI_BEFOREVOTING_DEADBODYTEXT), 104, 120, s, s, 0, NULL, 256);
+ gfx_spr(pic(PIC_DEADBODY_BIG), 236, 132, false, color_pal[g.p[g.reported].color], 256);
+ } else {
+ gfx_pic(pic(PIC_UI_BEFOREVOTING_EMTEXT), 104, 120, s, s, 0, NULL, 256);
+ gfx_spr(pic(PIC_IDLE_BIG), 232, 124, true, color_pal[g.p[g.caller].color], 256);
+ gfx_spr(pic(PIC_UI_REPORTED), 206, 116, true, NULL, 256);
}
}
diff --git a/games/amongus/src/bot.c b/games/amongus/src/bot.c
index decd99b7..f53fb3c6 100644
--- a/games/amongus/src/bot.c
+++ b/games/amongus/src/bot.c
@@ -166,6 +166,17 @@ static bool plan(int i, V2 goal) {
return true;
}
+#ifdef HOST
+/* (tests) is p walled in: no walkable cell within 1.5 units that a straight line reaches */
+bool bot_enclosed(V2 p) {
+ int cx = (int)floorf((p.x - NAV_X0) / NAV_CS), cy = (int)floorf((p.y - NAV_Y0) / NAV_CS);
+ for (int y = cy - 3; y <= cy + 3; y++)
+ for (int x = cx - 3; x <= cx + 3; x++)
+ if (nav_ok(x, y) && !ship_wall_between(p, cell_pos(y * NAV_W + x))) return false;
+ return true;
+}
+#endif
+
/* ---- 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); }
@@ -204,7 +215,7 @@ void bot_see(int i) {
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) {
+ if (Q->vent_anim) {
B->saw_vent = (uint8_t)j, B->saw_vent_room = Q->room;
suspect(B, j, 100);
}
@@ -235,8 +246,8 @@ void bot_see(int i) {
}
}
-/* a kill seen as it happens (called by kill_player for each living bot) */
-static void saw_kill_check(int i, int killer) {
+/* a kill seen as it happens (kill_player asks each living bot) */
+void bot_saw_kill(int i, int killer) {
Bot *B = &g.p[i].bot;
if (g.p[i].imp) return;
if (can_see(i, killer)) {
@@ -248,6 +259,34 @@ static void saw_kill_check(int i, int killer) {
/* ---- deciding ---- */
+/* how many crewmates (but j) are near player j */
+static int company(int j) {
+ int n = 0;
+ for (int k = 0; k < g.nplayers; k++)
+ if (k != j && g.p[k].alive && !g.p[k].imp && g.p[k].vent == NONE && dist2(g.p[k].pos, g.p[j].pos) < 4.5f * 4.5f) n++;
+ return n;
+}
+
+/* an impostor goes after the crewmate most alone (and nearest): false if nobody is worth it */
+static bool start_hunt(int i) {
+ Player *P = &g.p[i];
+ Bot *B = &P->bot;
+ 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 || Q->vent != NONE) continue;
+ float s = -company(j) * 8 - sqrtf(dist2(P->pos, Q->pos)) * 0.6f + rnd_f() * 4;
+ if (s > bs) bs = s, best = j;
+ }
+ if (best < 0 || bs < -30) return false;
+ B->state = B_HUNT;
+ B->task = (uint8_t)best;
+ B->t = 0;
+ B->stuck_t = 0;
+ return true;
+}
+
static float task_time(const Task *t) {
switch (TASK_DEFS[t->def].type) {
case T_SWIPE_CARD: return 3.5f;
@@ -305,55 +344,50 @@ static int next_task(int i, int *task) {
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++) {
+/* the consoles that fix the sabotage and still need someone (reactor and oxygen have two) */
+static int fix_consoles(int *out) {
+ static const uint8_t FIX[] = {0, T_RESET_REACTOR, T_RESTORE_O2, T_FIX_LIGHTS, T_FIX_COMMS};
+ int n = 0;
+ for (int c = 0; c < N_CONSOLES && n < 4; 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;
+ if (C->kind || !(C->types >> FIX[g.sab] & 1)) continue;
+ if (g.sab == SAB_O2 && (g.o2_done >> (C->room == R_ADMIN ? 0 : 1) & 1)) continue;
+ out[n++] = c;
}
- (void)i;
- return last;
+ return n;
}
-/* 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 fixing(int j, int c) {
+ const Bot *B = &g.p[j].bot;
+ return (B->state == B_FIX || (B->state == B_WALK && B->target == G_FIX)) && B->cons == c;
}
-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;
+/* a sabotage: the nearest free crewmate goes to each console that needs someone (after a moment to notice it) */
+void bots_dispatch(void) {
+ if (!g.sab || g.sab_age < 1.5f || (int)(g.t * 30) % 10) return;
+ int cons[4], n = fix_consoles(cons);
+ for (int k = 0; k < n; k++) {
+ int c = cons[k];
+ bool covered = false;
+ for (int j = 0; j < g.nplayers; j++) covered |= is_bot(j) && g.p[j].alive && !g.p[j].imp && fixing(j, c);
+ if (covered) continue;
+ int best = -1;
+ float bd = 1e9f;
+ for (int j = 0; j < g.nplayers; j++) {
+ const Player *Q = &g.p[j];
+ if (!is_bot(j) || !Q->alive || Q->imp || Q->vent != NONE || Q->bot.state == B_REPORT) continue;
+ bool busy = false;
+ for (int m = 0; m < n; m++) busy |= fixing(j, cons[m]);
+ if (busy) continue;
+ float d = dist2(Q->pos, stand(c));
+ /* (lights and comms can wait for a task to be done) */
+ if (Q->bot.state == B_TASK && (g.sab == SAB_LIGHTS || g.sab == SAB_COMMS)) d += 200;
+ if (d < bd) bd = d, best = j;
}
+ if (best < 0) continue;
+ g.p[best].busy = 0;
+ go(best, stand(cons[k]), G_FIX, cons[k]);
}
- return false;
}
static void wander(int i) {
@@ -365,7 +399,6 @@ static void wander(int i) {
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) {
@@ -392,27 +425,7 @@ static void decide(int i) {
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;
- }
- }
+ if (P->kill_cd < 5 && start_hunt(i)) 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);
@@ -465,7 +478,7 @@ static void arrive(int i) {
return;
}
B->state = B_TASK;
- B->t = task_time(t) * (0.8f + 0.5f * rnd_f());
+ B->t = task_time(t) * (0.9f + 0.6f * rnd_f());
P->busy = 1;
return;
}
@@ -503,13 +516,12 @@ static void arrive(int i) {
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)) {
@@ -521,10 +533,18 @@ static void impostor_tick(int 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);
+ /* the kill nearly ready: off to find someone */
+ if (P->kill_cd < 4 && P->vent == NONE && rnd_n(15) == 0 &&
+ (B->state == B_TASK || B->state == B_WAIT || B->state == B_IDLE ||
+ (B->state == B_WALK && (B->target == G_FAKE || B->target == G_WANDER))))
+ start_hunt(i);
+ /* sabotage now and then, and the lights when about to kill */
+ if (sabotage_ready() && P->alive) {
+ if (P->kill_cd < 3 && B->state == B_HUNT && company(B->task) && rnd_n(30 * 4) == 0) sabotage(SAB_LIGHTS);
+ else if (rnd_n(30 * 35) == 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,
@@ -565,10 +585,11 @@ void bot_tick(int i) {
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(400) == 0 && B->state != B_HUNT && B->state != B_VENT) {
+ /* to the sabotage, as if to fix it */
+ int cons[4], n = fix_consoles(cons);
+ if (n) go(i, stand(cons[rnd_n(n)]), G_FAKE, cons[0]);
}
- 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});
@@ -622,7 +643,10 @@ void bot_tick(int i) {
} else
task_step_done(i, B->task);
}
- B->state = B_IDLE;
+ B->state = B_WAIT;
+ B->t = 0.4f + rnd_f() * 1.6f;
+ /* now and then a look around before the next task */
+ if (!P->imp && rnd_n(4) == 0) wander(i);
}
break;
case B_FIX: {
@@ -651,7 +675,12 @@ void bot_tick(int i) {
B->state = B_IDLE;
break;
}
- B->think -= 0;
+ /* in company for a while: someone else */
+ B->stuck_t = company(B->task) > 1 ? B->stuck_t + DT : 0;
+ if (B->stuck_t > 5) {
+ if (!start_hunt(i)) B->state = B_IDLE;
+ break;
+ }
B->t -= DT;
if (B->t <= 0 || B->pi >= B->plen) {
B->t = 0.7f;
@@ -739,9 +768,22 @@ void bot_meeting_start(void) {
g.nlines = 0;
g.line_shown = 0;
float at = 1.5f;
+ /* a body: who each crewmate last saw in its room lately is a little suspect */
+ if (g.reported != NONE) {
+ int room = NONE;
+ for (int b = 0; b < MAXP; b++)
+ if (g.bodies[b].on && g.bodies[b].who == g.reported) room = ship_room_at(g.bodies[b].pos);
+ for (int i = 0; i < g.nplayers; i++) {
+ if (!is_bot(i) || !g.p[i].alive || g.p[i].imp) continue;
+ Bot *B = &g.p[i].bot;
+ for (int j = 0; j < g.nplayers; j++)
+ if (j != i && g.p[j].alive && B->seen_room[j] == room && room != R_HALLWAY && g.t - B->seen_t[j] < 25)
+ suspect(B, j, B->with_t[j] > 20 ? 5 : 15);
+ }
+ }
/* the caller first */
int c = g.caller;
- if (c != g.me) {
+ if (is_bot(c)) {
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;
@@ -766,7 +808,7 @@ void bot_meeting_start(void) {
/* 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;
+ if (is_bot(i) && 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;
@@ -814,7 +856,7 @@ void bot_meeting_tick(void) {
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;
+ if (i == who || !is_bot(i) || !g.p[i].alive || g.p[i].imp) continue;
Bot *B = &g.p[i].bot;
if (i == a) {
suspect(B, who, 25); /* being accused */
@@ -827,7 +869,7 @@ void bot_meeting_tick(void) {
}
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);
+ if (is_bot(i) && !g.p[i].imp && g.p[i].bot.sus[who] < 30) suspect(&g.p[i].bot, a, -40);
qnext++;
}
}
@@ -835,7 +877,7 @@ void bot_meeting_tick(void) {
/* 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 (!is_bot(i) || !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);
@@ -852,8 +894,12 @@ void bot_votes(void) {
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);
+ /* sure enough: that one; half sure: with the crowd if it's the same one */
+ int counts[MAXP + 1] = {0};
+ for (int j = 0; j < g.nplayers; j++)
+ if (g.votes[j] != NONE && g.votes[j] != SKIP) counts[g.votes[j]]++;
+ bool crowd = w >= 0 && counts[w] >= 2 && s >= 15 && B->sus[w] > -30;
+ g.votes[i] = (uint8_t)(w >= 0 && (s >= 30 || crowd) ? w : SKIP);
}
- (void)B;
}
}
diff --git a/games/amongus/src/game.c b/games/amongus/src/game.c
index f4028497..b6f9256b 100644
--- a/games/amongus/src/game.c
+++ b/games/amongus/src/game.c
@@ -208,19 +208,32 @@ static void give_tasks(void) {
/* ---- 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;
+/* ShipStatus.SpawnPlayer: up, turned by the player's number, SpawnRadius out from the spawn centre, then
+ * 0.3636 up (the player's picture over its feet) */
+void spawn_at_table(int i) {
+ Player *P = &g.p[i];
+ float a = 6.2831853f * (i - 1) / g.nplayers + 1.5707963f;
+ V2 p = {-0.72f + cosf(a) * 1.6f, 0.62f + sinf(a) * 1.6f + 0.3636f - FEET_Y};
+ /* (where the circle meets the table, the game's physics pushes the player out: so do we, away from it) */
+ const V2 table = {-0.86f, 0.84f};
+ for (int k = 0; k < 40; k++) {
+ V2 q = ship_move(p, (V2){0, 0}, PLAYER_R + 0.02f);
+ bool inside = !ship_wall_between(table, p);
+ if (!inside && fabsf(q.x - p.x) + fabsf(q.y - p.y) < 1e-4f) break;
+ float dx = p.x - table.x, dy = p.y - table.y, l = sqrtf(dx * dx + dy * dy) + 1e-6f;
+ p.x += dx / l * 0.05f, p.y += dy / l * 0.05f;
}
+ P->pos = p;
+ P->vel = (V2){0, 0};
+ P->vent = NONE;
+ P->vent_anim = 0;
+ P->walking = 0;
+ P->busy = 0;
+ P->flip = cosf(a) > 0.01f;
+}
+
+static void spawn_circle(void) {
+ for (int i = 0; i < g.nplayers; i++) spawn_at_table(i);
}
void game_new(void) {
@@ -332,7 +345,7 @@ void kill_player(int killer, int victim) {
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);
+ if (g.p[i].alive && i != killer && is_bot(i)) bot_saw_kill(i, killer), bot_see(i);
check_win();
}
@@ -364,6 +377,7 @@ 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_age = 0;
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;
diff --git a/games/amongus/src/game.h b/games/amongus/src/game.h
index b44ae4a8..9c7b1c8c 100644
--- a/games/amongus/src/game.h
+++ b/games/amongus/src/game.h
@@ -96,7 +96,7 @@ typedef struct {
float door_cd[N_ROOMS];
/* sabotage */
uint8_t sab, switches, o2_done, sab_fixing;
- float sab_t, sab_cd, light;
+ float sab_t, sab_cd, light, sab_age; /* sab_age: how long the sabotage has been on */
uint32_t o2_code;
uint8_t reactor_hold[2], comms_ok, pad0;
float reactor_held;
@@ -121,6 +121,8 @@ typedef struct {
extern Game g;
extern bool autopilot;
+/* is player i played by the bots' brain (the others, and in tests the player too) */
+static inline bool is_bot(int i) { return i != g.me || autopilot; }
/* the tasks a ship gives (ShipStatus' lists) */
typedef struct {
@@ -144,6 +146,7 @@ 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 */
+void spawn_at_table(int i);
bool game_save(void);
bool game_load(void);
void settings_save(void);
@@ -182,6 +185,8 @@ void bot_meeting_start(void);
void bot_meeting_tick(void);
void bot_votes(void);
void bot_see(int i);
+void bot_saw_kill(int i, int killer);
+void bots_dispatch(void);
/* the minigames (mg.c) */
void mg_open(int cons, int task);
@@ -195,6 +200,7 @@ void hud_draw(void);
void screens_tick(uint32_t keys, uint32_t pressed);
void screens_draw(void);
void map_draw(int mode);
+void map_open(int mode);
void map_tick(uint32_t pressed, int mode);
void meeting_tick(uint32_t keys, uint32_t pressed);
void meeting_draw(void);
diff --git a/games/amongus/src/gfx.c b/games/amongus/src/gfx.c
index a7083b81..ed530837 100644
--- a/games/amongus/src/gfx.c
+++ b/games/amongus/src/gfx.c
@@ -22,8 +22,12 @@ void gfx_frame(void (*draw)(void)) {
/* 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) {
+ gfx_mix_palette_of(BLOB_MIX, N_MIX, pal, body, shadow, visor);
+}
+
+void gfx_mix_palette_of(int table, int n, uint16_t *pal, uint32_t body, uint32_t shadow, uint32_t visor) {
+ const uint8_t *m = (const uint8_t *)blob(table);
+ for (int i = 0; i < n; i++, m += 4) {
int c[3];
for (int k = 0; k < 3; k++) {
int sh = 16 - 8 * k;
diff --git a/games/amongus/src/gfx.h b/games/amongus/src/gfx.h
index d0c2b9f2..49f2ea3a 100644
--- a/games/amongus/src/gfx.h
+++ b/games/amongus/src/gfx.h
@@ -30,6 +30,8 @@ static inline bool gfx_rows(int y0, int y1) { return y1 > gfx_y0 && y0 < gfx_y0
/* 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);
+/* the same from another mix table (the kill's frames) */
+void gfx_mix_palette_of(int table, int n, 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) */
diff --git a/games/amongus/src/hud.c b/games/amongus/src/hud.c
index 3ab396df..7ede7c34 100644
--- a/games/amongus/src/hud.c
+++ b/games/amongus/src/hud.c
@@ -93,27 +93,26 @@ static void draw_tasks(void) {
(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);
+/* a button of the game's (its picture has its name), see-through when it can't be used, a cooldown number over it */
+static void button(int x, int y, int pic_id, bool on, int cd) {
+ gfx_spr(pic(pic_id), x, y, false, NULL, on ? 256 : 96);
if (cd > 0) {
char b[8];
snprintf(b, sizeof b, "%d", cd);
- gfx_text(FONT_BIG, x, y - 6, b, 0xFFFF, 0x0000, 1, 1);
+ gfx_text(FONT_HUGE, x, y + 9, b, 0xFFFF, 0x0000, 2, 1);
}
}
-static const char *act_name(int a) {
+/* the action button's picture and word (for the key line) */
+static int act_pic(int a, bool imp, const char **word) {
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";
+ case 2: *word = "report"; return PIC_UI_REPORTBUTTON;
+ case 3: *word = "vent"; return PIC_UI_VENT;
+ case 5: *word = "admin"; return PIC_UI_MAPADMIN;
+ case 6: *word = "cameras"; return PIC_UI_SECURITY;
+ case 1:
+ case 4: *word = "use"; return PIC_UI_USEBUTTON;
+ default: *word = imp ? "sabotage" : "use"; return imp ? PIC_UI_SABOTAGE : PIC_UI_USEBUTTON;
}
}
@@ -141,23 +140,21 @@ void hud_draw(void) {
gfx_fill(SCREEN_W - 6, 6, 6, SCREEN_H - 24, 0xF800, 150);
}
int what = -1, a = hud_action(&what);
+ if (M->vent != NONE) a = 3;
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) {
+ const char *word;
+ bool imp = M->imp && M->alive;
+ int bp = act_pic(a, M->imp, &word);
+ button(296, 204, bp, a != 0 || M->imp, 0);
+ if (imp) {
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(254, 204, PIC_UI_KILLBUTTON, 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 if (imp)
+ snprintf(keys, sizeof keys, "OK %s EXE kill toolbox sabotage Back pause", word);
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');
+ snprintf(keys, sizeof keys, "arrows walk OK %s toolbox %s Back pause", word, M->imp ? "sabotage" : "map");
draw_keys(keys);
}
diff --git a/games/amongus/src/map.c b/games/amongus/src/map.c
index f6cd71ac..fc336498 100644
--- a/games/amongus/src/map.c
+++ b/games/amongus/src/map.c
@@ -1,5 +1,5 @@
-/* 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. */
+/* Among Us: the map (MapBehaviour): where you are and your tasks; for impostors the sabotage map, its buttons chosen
+ * with the arrows; the admin table's count of who is in each room (MapCountOverlay). */
#include <math.h>
#include <stdio.h>
#include <string.h>
@@ -10,14 +10,271 @@
void hud_keys(const char *s);
+/* the map's picture: 6.96 px a unit, its top-left at the ship's (-23.86, 7.23) */
+#define MAP_X0 8
+#define MAP_Y0 31
+#define MAP_K 6.96f
+static inline float mx(float x) { return MAP_X0 + (x + 23.86f) * MAP_K; }
+static inline float my(float y) { return MAP_Y0 + (7.23f - y) * MAP_K; }
+
+/* each room's middle (its areas' points) */
+static float room_x[N_ROOMS], room_y[N_ROOMS];
+static void rooms_init(void) {
+ if (room_x[R_CAFETERIA] != 0) return;
+ int n[N_ROOMS] = {0};
+ for (int a = 0; a < N_AREAS; a++)
+ for (int k = 0; k < AREAS[a].n; k++) {
+ const V2 *v = &AREA_PTS[AREAS[a].first + k];
+ room_x[AREAS[a].room] += v->x, room_y[AREAS[a].room] += v->y, n[AREAS[a].room]++;
+ }
+ for (int r = 0; r < N_ROOMS; r++)
+ if (n[r]) room_x[r] /= n[r], room_y[r] /= n[r];
+ room_y[R_CAFETERIA] += 1.2f; /* (above the table) */
+}
+
+/* ---- the sabotage map's buttons ---- */
+
+enum { SB_REACTOR, SB_O2, SB_LIGHTS, SB_COMMS, SB_DOORS };
+typedef struct {
+ uint8_t kind, room;
+ int8_t dx, dy; /* from the room's middle, in map pixels */
+} SabButton;
+static const SabButton SAB_BUTTONS[] = {
+ {SB_REACTOR, R_REACTOR, 0, 0}, {SB_O2, R_O2, 0, 0}, {SB_LIGHTS, R_ELECTRICAL, -10, 0},
+ {SB_COMMS, R_COMMS, 0, -3}, {SB_DOORS, R_ELECTRICAL, 12, 0}, {SB_DOORS, R_CAFETERIA, 0, 0},
+ {SB_DOORS, R_STORAGE, 0, 0}, {SB_DOORS, R_MEDBAY, 0, 0}, {SB_DOORS, R_SECURITY, 0, 0},
+ {SB_DOORS, R_UPPER_ENGINE, 0, 0}, {SB_DOORS, R_LOWER_ENGINE, 0, 0},
+};
+#define N_SAB_BUTTONS (int)(sizeof SAB_BUTTONS / sizeof SAB_BUTTONS[0])
+
+static void button_xy(int b, float *x, float *y) {
+ *x = mx(room_x[SAB_BUTTONS[b].room]) + SAB_BUTTONS[b].dx;
+ *y = my(room_y[SAB_BUTTONS[b].room]) + SAB_BUTTONS[b].dy;
+}
+
+/* 1 ready, 0 not now; *cd the cooldown left, 0-1 */
+static int button_ready(int b, float *cd) {
+ const SabButton *B = &SAB_BUTTONS[b];
+ *cd = 0;
+ if (B->kind == SB_DOORS) {
+ if (g.door_cd[B->room] > 0) *cd = g.door_cd[B->room] / 30;
+ return g.door_cd[B->room] <= 0;
+ }
+ if (g.sab == SAB_NONE && g.sab_cd > 0) *cd = g.sab_cd / 30;
+ return sabotage_ready();
+}
+
+static void press(int b) {
+ float cd;
+ if (!button_ready(b, &cd)) return;
+ const SabButton *B = &SAB_BUTTONS[b];
+ switch (B->kind) {
+ case SB_REACTOR: sabotage(SAB_REACTOR); break;
+ case SB_O2: sabotage(SAB_O2); break;
+ case SB_LIGHTS: sabotage(SAB_LIGHTS); break;
+ case SB_COMMS: sabotage(SAB_COMMS); break;
+ default: close_doors(B->room); break;
+ }
+}
+
+/* the button nearest the arrow's way from the selected one */
+static int step(int from, float kx, float ky) {
+ float fx, fy;
+ button_xy(from, &fx, &fy);
+ int best = from;
+ float bs = 1e9f;
+ for (int b = 0; b < N_SAB_BUTTONS; b++) {
+ if (b == from) continue;
+ float x, y;
+ button_xy(b, &x, &y);
+ float dx = x - fx, dy = y - fy, along = dx * kx + dy * ky, across = fabsf(dx * ky - dy * kx);
+ if (along <= 2) continue;
+ float s = along + across * 2.5f;
+ if (s < bs) bs = s, best = b;
+ }
+ return best;
+}
+
+void map_open(int mode) {
+ rooms_init();
+ g.overlay = (uint8_t)mode;
+ g.sel = 0;
+ if (mode == O_SABMAP) {
+ /* the button nearest the player */
+ const Player *P = &g.p[g.me];
+ float px = mx(P->pos.x), py = my(P->pos.y), bd = 1e9f;
+ for (int b = 0; b < N_SAB_BUTTONS; b++) {
+ float x, y;
+ button_xy(b, &x, &y);
+ float d = (x - px) * (x - px) + (y - py) * (y - py);
+ if (d < bd) bd = d, g.sel = (uint8_t)b;
+ }
+ }
+}
+
void map_tick(uint32_t pressed, int mode) {
- (void)mode;
- if (pressed & (K_BACK | K_TOOL)) g.overlay = O_NONE;
+ if (pressed & K_BACK) {
+ g.overlay = O_NONE;
+ return;
+ }
+ if ((pressed & K_TOOL) && mode != O_ADMIN) {
+ g.overlay = O_NONE;
+ return;
+ }
+ if (mode != O_SABMAP) return;
+ if (g.sel >= N_SAB_BUTTONS) g.sel = 0;
+ if (pressed & K_LEFT) g.sel = (uint8_t)step(g.sel, -1, 0);
+ if (pressed & K_RIGHT) g.sel = (uint8_t)step(g.sel, 1, 0);
+ if (pressed & K_UP) g.sel = (uint8_t)step(g.sel, 0, -1);
+ if (pressed & K_DOWN) g.sel = (uint8_t)step(g.sel, 0, 1);
+ if (pressed & (K_OK | K_EXE)) press(g.sel);
+}
+
+/* ---- drawing ---- */
+
+/* the map's picture in a colour: its rooms the colour, its halls lighter (the picture is red, halls pink) */
+static void draw_map_pic(uint32_t base, uint32_t light) {
+ const Pic *p = pic(PIC_UI_MAP);
+ const uint16_t *own = pic_pal(p);
+ uint16_t pal[16];
+ int n = pic_ncolors(p);
+ for (int i = 0; i < n && i < 16; i++) {
+ int gch = (own[i] >> 5) & 63; /* pink halls have green in them, rooms none */
+ pal[i] = blend(rgb565(base), rgb565(light), gch * 256 / 63);
+ }
+ gfx_spr(p, MAP_X0 + p->ox, MAP_Y0 + p->oy, false, pal, 256);
+}
+
+static void draw_names(void) {
+ for (int r = 1; r < N_ROOMS; r++) {
+ const char *s = ROOM_NAMES[r];
+ if (r == R_COMMS) s = "Comms";
+ int x = (int)mx(room_x[r]), y = (int)my(room_y[r]), w = gfx_text_width(FONT_SMALL, s);
+ if (x + w / 2 > SCREEN_W - 3) x = SCREEN_W - 3 - w / 2;
+ gfx_text(FONT_SMALL, x, y + 4, s, 0xFFFF, 0x0000, 1, 1);
+ }
+}
+
+static uint16_t white_pal[256];
+static void white_init(void) {
+ if (white_pal[1]) return;
+ gfx_mix_palette(white_pal, 0xD6E0F0, 0x8394BF, 0x95CADC);
+}
+
+/* the player's own little crewmate (the map's HerePoint) */
+static void here_point(void) {
+ const Player *P = &g.p[g.me];
+ int x = (int)mx(P->pos.x), y = (int)my(P->pos.y + FEET_Y);
+ gfx_spr(pic(PIC_VOTE_ICON), x, y, P->flip, color_pal[P->color], 256);
+}
+
+/* the yellow marks of the player's tasks, the red ones of a sabotage (MapTaskOverlay) */
+static void task_marks(void) {
+ const Player *P = &g.p[g.me];
+ bool blink = fmodf(g.t, 0.8f) < 0.5f;
+ if (g.sab && blink) {
+ static const uint8_t FIX[] = {0, T_RESET_REACTOR, T_RESTORE_O2, T_FIX_LIGHTS, T_FIX_COMMS};
+ for (int c = 0; c < N_CONSOLES; c++)
+ if (!CONSOLES[c].kind && (CONSOLES[c].types >> FIX[g.sab] & 1))
+ gfx_text(FONT_BIG, (int)mx(CONSOLES[c].x), (int)my(CONSOLES[c].y) + 6, "!", 0xF800, 0xFFFF, 1, 1);
+ }
+ if (P->imp || g.sab == SAB_COMMS) return;
+ for (int k = 0; k < P->ntasks; k++) {
+ const 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)) {
+ gfx_text(FONT_BIG, (int)mx(CONSOLES[c].x), (int)my(CONSOLES[c].y) + 6, "!", 0xFFE0, 0x0000, 1, 1);
+ if (TASK_DEFS[T->def].type != T_UPLOAD_DATA || T->step) break;
+ }
+ }
+}
+
+static const int SAB_ICON[] = {PIC_UI_SABOTAGE_REACTOR, PIC_UI_SABOTAGE_O2, PIC_UI_SABOTAGE_ELECTRICITY,
+ PIC_UI_SABOTAGE_COMMS, PIC_UI_SABOTAGE_DOORS};
+
+static void sab_buttons(void) {
+ for (int b = 0; b < N_SAB_BUTTONS; b++) {
+ float x, y, cd;
+ button_xy(b, &x, &y);
+ int ready = button_ready(b, &cd);
+ const Pic *p = pic(SAB_ICON[SAB_BUTTONS[b].kind]);
+ if (b == g.sel) gfx_disc(x, y, 16, 0xFFE0, 256);
+ gfx_spr(p, (int)x, (int)y, false, NULL, ready ? 256 : 110);
+ if (cd > 0) {
+ /* the cooldown: the button red from the bottom, going down */
+ int h = (int)(p->h * (cd > 1 ? 1 : cd));
+ int y1 = (int)y - p->oy + p->h, y0 = y1 - h;
+ if (gfx_rows(y0, y1)) {
+ uint16_t red[256];
+ const uint16_t *own = pic_pal(p);
+ for (int i = 0; i < pic_ncolors(p); i++) red[i] = blend(own[i], 0xF800, 170);
+ gfx_spr_clip(p, (int)x, (int)y, false, red, 200, (int)x - p->ox, y0, (int)x - p->ox + p->w, y1);
+ }
+ }
+ }
+}
+
+static void sab_name(char *b, int n) {
+ float cd;
+ const SabButton *B = &SAB_BUTTONS[g.sel < N_SAB_BUTTONS ? g.sel : 0];
+ int ready = button_ready(g.sel, &cd);
+ static const char *const NAMES[] = {"Reactor Meltdown", "Oxygen", "Lights", "Comms", "Doors"};
+ if (B->kind == SB_DOORS) snprintf(b, (size_t)n, "%s doors", ROOM_NAMES[B->room]);
+ else snprintf(b, (size_t)n, "%s", NAMES[B->kind]);
+ if (!ready && cd > 0)
+ snprintf(b + strlen(b), (size_t)n - strlen(b), " %ds", (int)ceilf(cd * 30));
+}
+
+/* admin: a little white crewmate for each body and living player in a room */
+static void admin_counts(void) {
+ if (g.sab == SAB_COMMS) {
+ if (fmodf(g.t, 1.2f) < 0.8f) gfx_text(FONT_BIG, 160, 122, "Comms Sabotaged", 0xF800, 0x0000, 1, 1);
+ return;
+ }
+ int n[N_ROOMS] = {0};
+ for (int i = 0; i < g.nplayers; i++) {
+ const Player *P = &g.p[i];
+ if (P->alive && P->vent == NONE) n[P->room]++;
+ }
+ for (int b = 0; b < MAXP; b++)
+ if (g.bodies[b].on) n[ship_room_at(g.bodies[b].pos)]++;
+ white_init();
+ const Pic *p = pic(PIC_VOTE_ICON);
+ for (int r = 1; r < N_ROOMS; r++) {
+ if (!n[r]) continue;
+ int per = n[r] > 5 ? 5 : n[r], rows = (n[r] + 4) / 5;
+ for (int k = 0; k < n[r]; k++) {
+ int row = k / 5, col = k % 5, inrow = row == rows - 1 ? n[r] - row * 5 : per;
+ int x = (int)mx(room_x[r]) + (col * 2 - inrow + 1) * 6, y = (int)my(room_y[r]) - 6 + (row * 2 - rows + 1) * 6;
+ gfx_spr(p, x, y, false, white_pal, 256);
+ }
+ }
}
void map_draw(int mode) {
+ rooms_init();
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");
+ gfx_fill(0, gfx_y0, SCREEN_W, BAND, 0x0000, 170);
+ if (mode == O_SABMAP) draw_map_pic(0xC81E1E, 0xF2A3A3);
+ else draw_map_pic(0x2A62C9, 0x9CC2F2);
+ if (mode != O_SABMAP) draw_names();
+ if (mode == O_ADMIN) {
+ admin_counts();
+ hud_keys("Back close");
+ return;
+ }
+ task_marks();
+ if (mode == O_SABMAP) sab_buttons();
+ here_point();
+ if (g.sab == SAB_COMMS && mode == O_MAP && fmodf(g.t, 1.2f) < 0.8f)
+ gfx_text(FONT_BIG, 160, 22, "Comms Sabotaged", 0xF800, 0x0000, 1, 1);
+ if (mode == O_SABMAP) {
+ char b[64], k[96];
+ sab_name(b, sizeof b);
+ gfx_text(FONT_BIG, 160, 22, b, 0xFFFF, 0x0000, 1, 1);
+ snprintf(k, sizeof k, "arrows choose OK sabotage toolbox or Back close");
+ hud_keys(k);
+ } else
+ hud_keys("toolbox or Back close");
}
diff --git a/games/amongus/src/meeting.c b/games/amongus/src/meeting.c
index f31f2ff7..e023a351 100644
--- a/games/amongus/src/meeting.c
+++ b/games/amongus/src/meeting.c
@@ -13,6 +13,7 @@ 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);
+void art_confirm(int x, int y, bool yes);
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,
@@ -27,8 +28,14 @@ const char *line_text(const Line *l, char *b, int n) {
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_WAS_IN:
+ if (l->a == R_HALLWAY) snprintf(b, (size_t)n, "I was doing tasks");
+ else snprintf(b, (size_t)n, "I was in %s doing tasks", l->a < N_ROOMS ? ROOM_NAMES[l->a] : "");
+ break;
+ case L_WITH:
+ if (l->b == R_HALLWAY) snprintf(b, (size_t)n, "I was with %s", a);
+ else 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;
@@ -67,12 +74,7 @@ static void after_meeting(void) {
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;
+ spawn_at_table(i);
P->kill_cd = kill_cooldown();
P->busy = 0;
Bot *B = &P->bot;
@@ -89,29 +91,59 @@ static void after_meeting(void) {
g.overlay = O_NONE;
}
+/* the plates: two columns, then Skip; the arrows move between them */
+#define PLATE_X(i) (18 + ((i) & 1) * 134)
+#define PLATE_Y(i) (41 + ((i) >> 1) * 27)
+#define SKIP_X 18
+#define SKIP_Y 177
+
+static int move_sel(int s, uint32_t pressed) {
+ int n = g.nplayers, rows = (n + 1) / 2;
+ if (s == SKIP) {
+ if (pressed & K_UP) s = (rows - 1) * 2 < n ? (rows - 1) * 2 : n - 1;
+ return s;
+ }
+ int col = s & 1, row = s >> 1;
+ if (pressed & K_LEFT) col = 0;
+ if (pressed & K_RIGHT) col = 1;
+ if (pressed & K_UP) row = row > 0 ? row - 1 : 0;
+ if (pressed & K_DOWN) {
+ if (row + 1 >= rows || row * 2 + 2 + col >= n + (col ? 0 : 1)) return SKIP;
+ row++;
+ }
+ int t = row * 2 + col;
+ if (t >= n) t = n - 1;
+ return t;
+}
+
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 (pressed & K_TOOL) {
+ g.line_shown = g.line_shown ? 0 : 1;
+ return;
+ }
+ if (g.line_shown && (pressed & K_BACK)) {
+ g.line_shown = 0;
+ return;
+ }
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;
+ /* the player's vote: a plate or Skip, then the tick */
+ if (M->alive && g.votes[g.me] == NONE && !g.line_shown) {
+ int s = g.sel & 15;
bool confirm = g.sel & 16;
+ if (s > SKIP) s = 0;
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);
+ s = move_sel(s, pressed);
+ bool ok = s == SKIP || (s < g.nplayers && 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;
+ if (pressed & (K_BACK | K_LEFT | K_RIGHT | K_UP | K_DOWN)) confirm = false;
}
g.sel = (uint8_t)(s | (confirm ? 16 : 0));
}
@@ -121,16 +153,13 @@ void meeting_tick(uint32_t keys, uint32_t pressed) {
finish_votes();
g.meet_stage = 2;
g.meet_t = 0;
+ g.line_shown = 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) {
@@ -140,59 +169,60 @@ static const char *stage_text(char *b, int n) {
return b;
}
+/* a chat line: the speaker's head, name and words */
+static void chat_line(const Line *l, int x, int y, uint16_t text) {
+ char b[64];
+ const Player *P = &g.p[l->who];
+ gfx_spr(pic(PIC_VOTE_ICON), x + 5, y - 4, false, color_pal[P->color], 256);
+ int w = gfx_text(FONT_SMALL, x + 13, y, COLOR_NAMES[P->color], 0xFFFF, 0x0000, 1, 0);
+ gfx_text(FONT_SMALL, x + 17 + w, y, line_text(l, b, sizeof b), text, 0x0000, 1, 0);
+}
+
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;
+ bool can_vote = g.meet_stage == 1 && M->alive && g.votes[g.me] == NONE && !g.line_shown;
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);
- }
+ int x = PLATE_X(i), y = PLATE_Y(i);
+ if (!gfx_rows(y - 2, y + 26)) continue;
+ art_plate(x, y, i, can_vote && sel == i, g.votes[i] != NONE && g.meet_stage >= 1 && g.p[i].alive, !g.p[i].alive);
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);
+ if (g.p[v].alive && g.votes[v] == i) {
+ art_vote_icon(x + 82 + 10 * (k % 5), y + 6 + 10 * (k / 5), g.p[v].color, g.opt.anon);
+ k++;
+ }
}
+ if (can_vote && sel == i && confirm) art_confirm(x + 84, y + 2, true);
}
- /* 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);
+ /* Skip, the clock, the last thing said */
+ art_skip(SKIP_X, SKIP_Y, can_vote && sel == SKIP);
+ if (can_vote && sel == SKIP && confirm) art_confirm(SKIP_X + 72, SKIP_Y - 2, true);
if (g.meet_stage == 2) {
+ gfx_spr(pic(PIC_UI_SKIPPEDVOTINGTALLY), SKIP_X + 20, SKIP_Y + 8, false, NULL, 256);
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);
+ if (g.p[v].alive && g.votes[v] == SKIP) art_vote_icon(SKIP_X + 48 + 10 * k++, SKIP_Y + 8, 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);
+ gfx_text(FONT_MID, 282, SKIP_Y + 12, stage_text(b, sizeof b), 0xFFFF, 0x0000, 1, 2);
+ if (g.nlines && !g.line_shown) chat_line(&g.lines[g.nlines - 1], 18, 202, 0xFFFF);
+ if (g.line_shown) {
+ /* the chat: the last lines said */
+ gfx_fill(15, 20, 270, 187, rgb565(0x0E1A2B), 236);
+ gfx_text(FONT_BIG, 150, 36, "Chat", 0xFFFF, 0x0000, 1, 1);
+ int first = g.nlines > 10 ? g.nlines - 10 : 0;
+ for (int k = first; k < g.nlines; k++) chat_line(&g.lines[k], 20, 56 + (k - first) * 15, 0xDEFB);
+ if (!g.nlines) gfx_text(FONT_MID, 150, 110, "Nobody has said anything yet", 0xBDF7, 0, 0, 1);
+ hud_keys("toolbox or Back close chat");
+ return;
}
- if (g.meet_stage == 1 && can_vote)
+ if (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");
+ hud_keys(g.meet_stage == 0 ? "discussion toolbox chat" : "toolbox chat");
}
diff --git a/games/amongus/src/play.c b/games/amongus/src/play.c
index a38678e0..352d166d 100644
--- a/games/amongus/src/play.c
+++ b/games/amongus/src/play.c
@@ -149,6 +149,7 @@ static void world_tick(void) {
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;
+ if (g.sab) g.sab_age += 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;
@@ -232,21 +233,27 @@ static void do_action(void) {
mg_open(what, MAX_TASKS);
break;
case ACT_ADMIN:
- g.overlay = O_ADMIN;
- g.sel = 0;
+ map_open(O_ADMIN);
break;
case ACT_USE:
mg_open(what, console_use(g.me, what));
break;
default:
+ /* an impostor's button with nothing to use: Sabotage */
+ if (P->imp) map_open(O_SABMAP);
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});
+ int screen = g.screen;
+ if (screen == S_PLAY && autopilot) {
+ /* (tests: the bots' brain plays the player) */
+ g.overlay = O_NONE;
+ bot_tick(g.me);
+ } else if (screen != S_PLAY)
+ walk(g.me, (V2){0, 0});
else if (g.overlay == O_NONE) {
V2 dir = {0, 0};
if (keys & K_LEFT) dir.x -= 1;
@@ -260,15 +267,12 @@ void play_tick(uint32_t keys, uint32_t pressed) {
}
walk(g.me, dir);
if (pressed & K_OK) do_action();
- if ((pressed & K_EXE) && P->kill_cd <= 0) {
+ if ((pressed & K_EXE) && P->kill_cd <= 0 && g.screen == S_PLAY && g.overlay == O_NONE) {
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) {
+ if ((pressed & K_TOOL) && g.screen == S_PLAY && g.overlay == O_NONE) map_open(P->imp ? O_SABMAP : O_MAP);
+ if ((pressed & K_BACK) && g.screen == S_PLAY && g.overlay == O_NONE) {
g.back_screen = S_PLAY;
g.screen = S_PAUSE;
g.sel = 0;
@@ -279,12 +283,11 @@ void play_tick(uint32_t keys, uint32_t pressed) {
if (g.overlay == O_TASK) 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 (g.screen != screen || (screen != S_PLAY && screen != S_KILLED)) return;
+ for (int i = 0; i < g.nplayers && g.screen == screen; i++)
if (i != g.me) bot_tick(i);
if (g.screen != screen) return;
+ bots_dispatch();
world_tick();
- /* bodies a crewmate bot sees */
check_win();
}
diff --git a/games/amongus/src/screens.c b/games/amongus/src/screens.c
index e4fe934f..cc873398 100644
--- a/games/amongus/src/screens.c
+++ b/games/amongus/src/screens.c
@@ -270,7 +270,8 @@ static void intro_draw(void) {
art_stars(0, 0);
if (t < 1.6f) {
/* "Shhhhhh!" */
- gfx_text(FONT_HUGE, 160, 130, "Shhhhhh!", IMP_RED, 0x0000, 2, 1);
+ float k = t < 0.25f ? 0.6f + 1.6f * t : 1;
+ gfx_pic(pic(PIC_UI_NO_SHH), 160, 120, k, k, 0, NULL, 256);
return;
}
const Player *M = &g.p[g.me];
diff --git a/games/amongus/tests/play.c b/games/amongus/tests/play.c
index b77a0fdb..8104146d 100644
--- a/games/amongus/tests/play.c
+++ b/games/amongus/tests/play.c
@@ -94,6 +94,49 @@ static void open_minigame(int kind) {
g.cam = (V2){P->pos.x, P->pos.y + FEET_Y};
}
+/* a scene set up straight away (screenshots): kill, report, emergency, meeting, eject, map, sabmap, admin, reactor,
+ * lights */
+static void scene(const char *name) {
+ Player *P = &g.p[g.me];
+ int other = g.me == 1 ? 2 : 1, imp = -1;
+ for (int i = 0; i < g.nplayers; i++)
+ if (g.p[i].imp && i != g.me) imp = i;
+ g.screen = S_PLAY;
+ g.screen_t = 0;
+ if (!strcmp(name, "kill")) {
+ if (imp >= 0) kill_player(imp, g.me);
+ } else if (!strcmp(name, "report")) {
+ kill_player(imp >= 0 ? imp : other, other);
+ start_meeting(g.me, other);
+ } else if (!strcmp(name, "emergency")) {
+ start_meeting(other, NONE);
+ } else if (!strcmp(name, "meeting") || !strcmp(name, "eject")) {
+ kill_player(imp >= 0 ? imp : other, other);
+ start_meeting(3, other);
+ g.screen = S_REPORT;
+ g.screen_t = 2.6f;
+ game_tick(0);
+ if (!strcmp(name, "eject")) {
+ g.meet_t = 999;
+ g.meet_stage = 1;
+ for (int i = 0; i < g.nplayers; i++) g.votes[i] = (uint8_t)(imp >= 0 ? imp : 4);
+ game_tick(0);
+ g.meet_t = 6;
+ game_tick(0);
+ }
+ } else if (!strcmp(name, "map")) {
+ map_open(O_MAP);
+ } else if (!strcmp(name, "sabmap")) {
+ map_open(O_SABMAP);
+ } else if (!strcmp(name, "admin")) {
+ map_open(O_ADMIN);
+ } else if (!strcmp(name, "reactor") || !strcmp(name, "lights") || !strcmp(name, "o2") || !strcmp(name, "comms")) {
+ g.sab_cd = 0;
+ sabotage(name[0] == 'r' ? SAB_REACTOR : name[0] == 'l' ? SAB_LIGHTS : name[0] == 'o' ? SAB_O2 : SAB_COMMS);
+ }
+ (void)P;
+}
+
static uint32_t frng = 1;
static uint32_t frnd(void) {
frng ^= frng << 13, frng ^= frng >> 17, frng ^= frng << 5;
@@ -101,9 +144,11 @@ static uint32_t frnd(void) {
}
int main(int argc, char **argv) {
- int frames = 300, trace = 0, start = 0, bots = -1, mgkind = -1;
+ int frames = 300, trace = 0, start = 0, bots = -1, mgkind = -1, imps = -1, killcd = -1, walk_frames = 0;
+ const char *scene_name = NULL;
+ float at_x = 1e9f, at_y = 0;
uint32_t seed = 0;
- bool fuzz = false, draw = false;
+ bool fuzz = false, draw = false, shot_end = false, walled = false;
const char *out = "build/shots";
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--frames")) frames = atoi(argv[++i]);
@@ -113,10 +158,17 @@ int main(int argc, char **argv) {
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], "--walled")) walled = 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], "--imps")) imps = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "--killcd")) killcd = atoi(argv[++i]);
else if (!strcmp(argv[i], "--mg")) mgkind = atoi(argv[++i]), start = start ? start : 1;
+ else if (!strcmp(argv[i], "--scene")) scene_name = argv[++i], start = start ? start : 1;
+ else if (!strcmp(argv[i], "--at")) at_x = (float)atof(argv[++i]), at_y = (float)atof(argv[++i]);
+ else if (!strcmp(argv[i], "--walk")) walk_frames = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "--shot-end")) shot_end = true;
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];
@@ -137,12 +189,20 @@ int main(int argc, char **argv) {
game_init();
if (start) {
if (bots >= 0) g.opt.bots = (uint8_t)bots;
+ if (imps >= 0) g.opt.impostors = (uint8_t)imps;
+ if (killcd >= 0) g.opt.kill_cd = (uint8_t)(killcd * 2);
g.opt.role = (uint8_t)start;
g.rng = seed * 2654435761u + 77;
game_new();
+ g.screen = S_PLAY;
+ /* (the round a little under way: the bots spread out) */
+ for (int f = 0; f < walk_frames; f++) game_tick(0), host_time += 33;
+ if (at_x < 1e8f) g.p[g.me].pos = (V2){at_x, at_y}, g.cam = (V2){at_x, at_y + FEET_Y};
if (mgkind >= 0) open_minigame(mgkind);
+ if (scene_name) scene(scene_name);
}
uint32_t fk = 0;
+ int meetings = 0, ejects = 0, wrong = 0, prev_scr = -1;
static int hist[16];
for (int f = 0; f < frames && game_running; f++) {
uint32_t k = 0;
@@ -160,7 +220,18 @@ int main(int argc, char **argv) {
if (autopilot && (g.screen == S_INTRO || g.screen == S_EJECT) && f % 20 == 0) k |= K_OK;
host_keys = k;
hist[g.screen & 15]++;
+ if (g.screen == S_REPORT && prev_scr != S_REPORT) meetings++;
+ if (g.screen == S_EJECT && prev_scr != S_EJECT) ejects += g.ejected != NONE, wrong += g.ejected != NONE && !g.p[g.ejected].imp;
+ prev_scr = g.screen;
game_tick(k);
+ /* nobody walled in (inside a table or a wall) */
+ if (walled && f % 15 == 0)
+ for (int i = 0; i < g.nplayers; i++) {
+ extern bool bot_enclosed(V2 p);
+ static bool told[MAXP];
+ if (g.p[i].alive && g.p[i].vent == NONE && !told[i] && bot_enclosed(g.p[i].pos))
+ told[i] = true, printf("WALLED f%d player %d (%.3f,%.3f)\n", f, i, g.p[i].pos.x, g.p[i].pos.y);
+ }
host_time += 33;
bool shot = every ? f % every == 0 : false;
for (int i = 0; i < nshots; i++) shot |= shots[i] == f;
@@ -173,14 +244,22 @@ int main(int argc, char **argv) {
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 (g.screen == S_END && autopilot && g.screen_t > 3) {
+ if (shot_end) {
+ char p[512];
+ snprintf(p, sizeof p, "%s/end.ppm", out);
+ game_draw();
+ host_shot(p);
+ }
+ 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);
+ printf("END screen %d winner %d reason %d t %.1f alive %d tasks %.2f imp %d meetings %d ejected %d wrong %d\n", g.screen,
+ g.winner, g.end_reason, g.t, alive, tasks_progress(), g.p[g.me].imp, meetings, ejects, wrong);
return 0;
}