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
Cookie Clicker: the news ticker, the Pantheon, seasons' cookies
Mason3633c0823cc2d82
diff --git a/games/cookieclicker/src/data.bin b/games/cookieclicker/src/data.binindex b18cfe14..7c19b584 100644Binary files a/games/cookieclicker/src/data.bin and b/games/cookieclicker/src/data.bin differdiff --git a/games/cookieclicker/src/data.h b/games/cookieclicker/src/data.hindex d202df7c..64a16a27 100644--- a/games/cookieclicker/src/data.h+++ b/games/cookieclicker/src/data.h@@ -1622,8 +1622,29 @@#define N_CPS_ACHIEVS 48#define OFF_UNLOCK_AT 1548408#define N_UNLOCK_AT 213-#define OFF_TEXT 1553520-#define OFF_IMAGES 1740172+#define OFF_NEWS 1553520+#define N_NEWS 128+#define NK_GRANDMA 0+#define NK_GRANDMA_THREAT 1+#define NK_GRANDMA_ANGRY 2+#define NK_GRANDMA_RETURN 3+#define NK_SOLD_GRANDMA 4+#define NK_BUILDING 5+#define NK_SEASON 6+#define NK_RARE_ACHIEV 7+#define NK_RARE_UPGRADE 8+#define NK_DUDE_SWEET 9+#define NK_WILL_WRIGHT 10+#define NK_MISC 11+#define NK_BUSINESS 12+#define NK_LORE 13+#define NK_WRATH 14+#define NK_FOOLS 15+#define NK_FOOLS_RARE 16+#define NK_FOOLS_BUILDING 17+#define NK_FOOLS_LORE 18+#define OFF_TEXT 1554544+#define OFF_IMAGES 1782036#define N_IMAGES 1556#define IM_COOKIE 0#define IM_COOKIE_SHADOW 1@@ -1911,6 +1932,6 @@#define IM_FAMILIAR1_1 283#define IM_FAMILIAR1_2 284#define IM_FAMILIAR1_3 285-#define DATA_SIZE 1765068+#define DATA_SIZE 1806932#endifdiff --git a/games/cookieclicker/src/game.c b/games/cookieclicker/src/game.cindex e1c95bd5..a26cae09 100644--- a/games/cookieclicker/src/game.c+++ b/games/cookieclicker/src/game.c@@ -59,6 +59,7 @@ void game_new(void) {S.magic = 0x314B4343u, S.version = 1;S.prefs = (Prefs){.particles = 1, .numbers = 1, .milk = 1, .fancy = 1, .cursors = 1, .wobbly = 1, .notes_on = 0};S.research_t = -1, S.season_t = -1;+ S.swaps = 3;S.bakery_name1 = (uint8_t)rnd_int(256), S.bakery_name2 = (uint8_t)rnd_int(256);for (int i = 0; i < MAX_BUFFS; i++) S.buffs[i].used = 0;for (int i = 0; i < 16; i++) G.effs[i] = 1;diff --git a/games/cookieclicker/src/game.h b/games/cookieclicker/src/game.hindex f4727804..1bcbd511 100644--- a/games/cookieclicker/src/game.h+++ b/games/cookieclicker/src/game.h@@ -120,7 +120,7 @@ typedef struct {uint16_t permanent[5], pad2;double lumps, lumps_total;double lump_t, lump_refill; /* play time (ms) the current lump started, the refill was used */- uint8_t lump_type, pad3[7];+ uint8_t lump_type, fortune_gc, fortune_cps, pad3[5]; /* fortune_*: the ticker's fortunes had this run */double start_date, full_date, play_time; /* play time (ms): this ascension began, the game began, now */Building buildings[NB];uint8_t upgrades_unlocked[UBITS], upgrades_bought[UBITS], upgrades_vaulted[UBITS], achievements[ABITS];diff --git a/games/cookieclicker/src/logic.c b/games/cookieclicker/src/logic.cindex d57571ca..3b28f98e 100644--- a/games/cookieclicker/src/logic.c+++ b/games/cookieclicker/src/logic.c@@ -71,13 +71,15 @@ Buff *find_buff(int type) {bool has_buff(int type) { return find_buff(type) != NULL; }/* the Pantheon and the dragon: their effects, once their parts are in */+extern float dragon_aura_mult(int aura);+float aura_mult(int aura) { return dragon_aura_mult(aura); }int hasgod(int god) {for (int i = 0; i < 3; i++)- if (S.gods[i] == god + 1 && G.s.buildings[B_TEMPLE].level > 0 && S.ascension_mode != 1) return i + 1;+ if (S.gods[i] == god + 1 && G.s.buildings[B_TEMPLE].level > 0 && S.ascension_mode != 1)+ return aura_mult(AURA_SUPREME_INTELLECT) > 0 ? (i > 1 ? i : 1) : i + 1; /* (Supreme Intellect: a slot up) */return 0;}-extern float dragon_aura_mult(int aura);-float aura_mult(int aura) { return dragon_aura_mult(aura); }+/* ------------------------------------------------------------------ prices */static double modify_building_price(int b, double price) {diff --git a/games/cookieclicker/src/minigames.c b/games/cookieclicker/src/minigames.cindex 59611e2d..95f6cfe9 100644--- a/games/cookieclicker/src/minigames.c+++ b/games/cookieclicker/src/minigames.c@@ -54,19 +54,27 @@ double garden_drop_price(int u, double price) {extern void grimoire_draw(void);extern void grimoire_keys(uint32_t pressed);extern int grimoire_tip(int x, int y, int w, bool draw);+extern void pantheon_draw(void);+extern void pantheon_keys(uint32_t pressed);+extern int pantheon_tip(int x, int y, int w, bool draw);-bool minigame_available(int b) { return b == B_WIZARD_TOWER && S.buildings[b].level > 0 && S.ascension_mode != 1; }+bool minigame_available(int b) {+ return (b == B_WIZARD_TOWER || b == B_TEMPLE) && S.buildings[b].level > 0 && S.ascension_mode != 1;+}const char *minigame_name(int b) {return b == B_WIZARD_TOWER ? "Grimoire" : b == B_TEMPLE ? "Pantheon" : b == B_FARM ? "Garden" : "Stock Market";}void draw_minigame(int b) {if (b == B_WIZARD_TOWER) grimoire_draw();+ else if (b == B_TEMPLE) pantheon_draw();}void minigame_keys(int b, uint32_t pressed) {if (b == B_WIZARD_TOWER) grimoire_keys(pressed);+ else if (b == B_TEMPLE) pantheon_keys(pressed);}/* the tooltip of what is chosen in the panel: its height (0: none) */int minigame_tip(int b, int x, int y, int w, bool draw) {if (b == B_WIZARD_TOWER) return grimoire_tip(x, y, w, draw);+ if (b == B_TEMPLE) return pantheon_tip(x, y, w, draw);return 0;}diff --git a/games/cookieclicker/src/news.c b/games/cookieclicker/src/news.cindex fe2106c8..803b8383 100644--- a/games/cookieclicker/src/news.c+++ b/games/cookieclicker/src/news.c@@ -1,40 +1,193 @@-/* The news ticker (the game's getNewTicker): what the bakery's fame has reached, news of the- * buildings, the grandmas' mutterings and the elders' invasion. */+/* The news ticker (the game's getNewTicker): its English lines, as tools/pack.py reads them from the+ * game (NK_* says what brings each up), chosen the way the game chooses; the fortunes of the Fortune+ * cookies heavenly upgrade, which pressing the ticker collects. */#include <math.h>#include <stdio.h>#include <string.h>#include "game.h"-static const char *const lore[][2] = {- {"You feel like making cookies. But nobody wants to eat your cookies.", NULL},- {"Your first batch goes to the trash. The neighborhood raccoon barely touches it.", NULL},- {"Your family agrees to try some of your cookies.", NULL},- {"Your cookies are popular in the neighborhood.", "People are starting to talk about your cookies."},- {"Your cookies are talked about for miles around.", "Your cookies are renowned in the whole town!"},- {"Your cookies bring all the boys to the yard.", "Your cookies now have their own website!"},- {"Your cookies are worth a lot of money.", "Your cookies sell very well in distant countries."},- {"People come from very far away to get a taste of your cookies.",- "Kings and queens from all over the world are enjoying your cookies."},- {"There are now museums dedicated to your cookies.", "A national day has been created in honor of your cookies."},- {"Your cookies have been named a part of the world wonders.",- "History books now include a whole chapter about your cookies."},- {"Your cookies have been placed under government surveillance.", "The whole planet is enjoying your cookies!"},- {"Strange creatures from neighboring planets wish to try your cookies.",- "Elder gods from the whole cosmos have awoken to taste your cookies."},- {"Beings from other dimensions lapse into existence just to get a taste of your cookies.",- "Your cookies have achieved sentience."},- {"The universe has now turned into cookie dough, to the molecular level.",- "Your cookies are rewriting the fundamental laws of the universe."},- {"A local news station runs a 10-minute segment about your cookies. Success! (you win a cookie)",- "it's time to stop playing"},-};+typedef struct {+ uint32_t text;+ uint8_t kind, pad;+ uint16_t arg;+} NewsRec;+_Static_assert(sizeof(NewsRec) == 8, "NewsRec");+static const NewsRec *news_rec(int i) { return RES(NewsRec, OFF_NEWS) + i; }uint32_t ticker_n;+int ticker_effect; /* what pressing the ticker gives: 0 nothing, -1 a golden cookie, -2 an hour of CpS, else+ the fortune upgrade + 1 */+extern void bakery_name_short(char *out, int size);++/* the game's loreProgress: how far the bakery's fame has gone */+static int lore_progress(void) {+ double v = log10(S.cookies_earned / 10) + 1;+ if (!(v > -1e9)) return 0; /* (no cookies yet: -Infinity, 0 in the game) */+ return (int)v; /* (|0: toward zero) */+}++/* a template written out: \x10 choices \x11 ... \x12, \x13 the bakery's name and numbers, \x14n:add; a+ * random number */+static const char *expand(const char *t, char *o, char *end, char **out) {+ while (*t && *t != 0x11 && *t != 0x12) {+ unsigned char c = (unsigned char)*t;+ if (c == 0x10) {+ /* the alternatives at this level */+ int n = 1, depth = 0;+ const char *p = t + 1;+ for (; *p && !(depth == 0 && *p == 0x12); p++) {+ if (*p == 0x10) depth++;+ else if (*p == 0x12) depth--;+ else if (*p == 0x11 && depth == 0) n++;+ }+ int k = rnd_int(n);+ p = t + 1, depth = 0;+ while (k > 0) {+ if (*p == 0x10) depth++;+ else if (*p == 0x12) depth--;+ else if (*p == 0x11 && depth == 0) k--;+ p++;+ }+ p = expand(p, o, end, &o);+ /* past the rest of the alternatives */+ depth = 0;+ while (*p && !(depth == 0 && *p == 0x12)) {+ if (*p == 0x10) depth++;+ else if (*p == 0x12) depth--;+ p++;+ }+ t = *p ? p + 1 : p;+ continue;+ }+ char v[64] = "";+ if (c == 0x13) {+ double y = ceil(S.cookies_earned / 8000000000.0);+ switch (t[1]) {+ case 'B': bakery_name_short(v, sizeof v); break;+ case 'E': beautify(S.cookies_earned, 0, v); break;+ case 'Y': beautify(y, 0, v); break;+ case 'P': snprintf(v, sizeof v, "%s", y == 1 ? "" : "s"); break;+ }+ t += 2;+ } else if (c == 0x14) {+ int n = 0, add = 0;+ t++;+ while (*t >= '0' && *t <= '9') n = n * 10 + (*t++ - '0');+ if (*t == ':') t++;+ while (*t >= '0' && *t <= '9') add = add * 10 + (*t++ - '0');+ if (*t == ';') t++;+ snprintf(v, sizeof v, "%d", rnd_int(n) + add);+ } else {+ if (o < end) *o++ = *t;+ t++;+ continue;+ }+ for (char *q = v; *q && o < end; q++) *o++ = *q;+ }+ *out = o;+ return t;+}++static void write_out(int i, char *out, int size) {+ char *o = out;+ expand(res_text(news_rec(i)->text), out, out + size - 1, &o);+ *o = 0;+}+void news_next(char *out, int size) {+ static uint16_t list[N_NEWS];+ int n = 0, lore = lore_progress();+ bool scary = !S.prefs.not_scary;+ ticker_effect = 0;+#define ADD(kind_test) \+ for (int i = 0; i < N_NEWS; i++) { \+ const NewsRec *r = news_rec(i); \+ if (kind_test) list[n++] = (uint16_t)i; \+ }+ if (ticker_n % 2 == 0 || lore > 14) {+ if (rnd() < 0.75 || S.cookies_earned < 10000) {+ int grandmas = S.buildings[B_GRANDMA].amount;+ bool wrong = has_achiev(A_JUST_WRONG);+ bool sold = wrong && rnd() < 0.05, angry = scary && wrong && rnd() < 0.4;+ ADD((r->kind == NK_GRANDMA && grandmas > 0) || (r->kind == NK_GRANDMA_THREAT && scary && grandmas >= 50) ||+ (r->kind == NK_SOLD_GRANDMA && sold) || (r->kind == NK_GRANDMA_ANGRY && angry) ||+ (r->kind == NK_GRANDMA_RETURN && scary && grandmas >= 1 && S.pledges > 0 && S.elder_wrath == 0) ||+ (r->kind == NK_BUILDING && S.buildings[r->arg].amount > 0) ||+ (r->kind == NK_SEASON && S.season == r->arg && S.cookies_earned >= 1000));+ }+ if (rnd() < 0.05)+ ADD((r->kind == NK_RARE_ACHIEV && has_achiev(r->arg)) || (r->kind == NK_RARE_UPGRADE && has(r->arg)));+ if (has_achiev(A_DUDE_SWEET) && rnd() < 0.2) ADD(r->kind == NK_DUDE_SWEET);+ if (rnd() < 0.001) ADD(r->kind == NK_WILL_WRIGHT);+ if (S.cookies_earned >= 10000) ADD(r->kind == NK_MISC);+ }+ if (n == 0) ADD(r->kind == NK_LORE && r->arg == lore);+ if (S.elder_wrath > 0 && ((S.pledges == 0 && S.resets == 0 && rnd() < 0.3) || rnd() < 0.03)) {+ n = 0;+ ADD(r->kind == NK_WRATH && r->arg == S.elder_wrath);+ }+ if (S.season == SEASON_FOOLS) {+ n = 0;+ bool rare = S.cookies_earned >= 1000 && rnd() < 0.05;+ ADD((r->kind == NK_FOOLS && S.cookies_earned >= 1000) || (r->kind == NK_FOOLS_RARE && rare) ||+ (r->kind == NK_FOOLS_BUILDING && ticker_n % 2 == 0 && S.buildings[r->arg].amount > 0));+ /* (the first of the business lines the fame has reached) */+ int best = -1;+ for (int i = 0; i < N_NEWS; i++) {+ const NewsRec *r = news_rec(i);+ if (r->kind == NK_FOOLS_LORE && lore <= r->arg && (best < 0 || r->arg < news_rec(best)->arg)) best = i;+ }+ if (best >= 0) list[n++] = (uint16_t)best;+ }+#undef ADDticker_n++;- int lore_progress = S.cookies_earned >= 10 ? (int)(log10(S.cookies_earned / 10) + 1) : 0;- if (lore_progress < 0) lore_progress = 0;- if (lore_progress > 14) lore_progress = 14;- const char *const *l = lore[lore_progress];- snprintf(out, size, "%s", l[1] && rnd() < 0.5 ? l[1] : l[0]);+ /* a fortune, now and then */+ if (G.T > FPS * 10 && has(U_FORTUNE_COOKIES) && rnd() < (has_achiev(A_O_FORTUNA) ? 0.04 : 0.02)) {+ int cand[N_FORTUNES + 2], m = 0;+ for (int i = 0; i < N_FORTUNES; i++)+ if (!has_unlocked(LIST(FORTUNES)[i])) cand[m++] = LIST(FORTUNES)[i] + 1;+ if (!S.fortune_gc) cand[m++] = -1;+ if (!S.fortune_cps) cand[m++] = -2;+ if (m) {+ ticker_effect = cand[rnd_int(m)];+ if (ticker_effect == -1) snprintf(out, size, "Today is your lucky day!");+ else if (ticker_effect == -2) {+ uint32_t h = (uint32_t)S.bakery_name1 * 2654435761u ^ (uint32_t)S.bakery_name2 * 40503u ^ S.resets * 977u;+ int k[4];+ for (int i = 0; i < 4; i++) h = h * 1103515245u + 12345u, k[i] = (int)(h >> 16) % 100;+ snprintf(out, size, "Your lucky numbers are: %d %d %d %d", k[0], k[1], k[2], k[3]);+ } else {+ const UpgradeRec *r = upgrade_rec(ticker_effect - 1);+ const char *name = res_text(r->name), *hash = strchr(name, '#');+ snprintf(out, size, "%s: %s", hash ? hash : name, res_text(r->quote));+ }+ return;+ }+ }+ if (!n) {+ out[0] = 0;+ return;+ }+ write_out(list[rnd_int(n)], out, size);+}++/* pressing the ticker: counted (Tabloid addiction), and its fortune collected */+void ticker_click(void) {+ S.ticker_clicks++;+ if (S.ticker_clicks >= 50) win(A_TABLOID_ADDICTION);+ if (ticker_effect == -1) {+ notify("Fortune!", "A golden cookie has appeared.", ICON(10, 32), 0);+ S.fortune_gc = 1;+ Shimmer *m = shimmer_new(SHIMMER_GOLDEN, GC_NONE, false);+ if (m) m->wrath = 0;+ } else if (ticker_effect == -2) {+ notify("Fortune!", "You gain \x01one hour\x02 of your CpS (capped at double your bank).", ICON(10, 32), 0);+ S.fortune_cps = 1;+ earn(G.cookies_ps * 60 * 60 < S.cookies ? G.cookies_ps * 60 * 60 : S.cookies);+ } else if (ticker_effect > 0) {+ int u = ticker_effect - 1;+ notify(res_text(upgrade_rec(u)->name), "You've unlocked a new upgrade.", upgrade_rec(u)->icon, 0);+ unlock(u);+ }+ ticker_effect = 0;}diff --git a/games/cookieclicker/src/pantheon.c b/games/cookieclicker/src/pantheon.cindex a3fbbe7b..cebd4006 100644--- a/games/cookieclicker/src/pantheon.c+++ b/games/cookieclicker/src/pantheon.c@@ -1,13 +1,86 @@-/* The Pantheon (the temple's minigame): three slots, diamond, ruby and jade, for eleven spirits. */+/* The Pantheon (the temples' minigame, minigamePantheon.js): eleven spirits, three slots (diamond,+ * ruby, jade) where they are worshipped, the diamond strongest; worship swaps to move them, which come+ * back with time. Its panel shows in the buildings' view: the slots and their gems, the spirits in the+ * game's frames, the swaps; EXE picks a spirit up and sets it in a slot. */#include <math.h>+#include <stdio.h>#include <string.h>-#include "game.h"+#include "ui.h"++typedef struct {+ const char *name, *before, *desc[3], *after, *quote;+ int16_t icon;+} God;+static const God gods[N_GODS] = {+ {"Holobore, Spirit of Asceticism", NULL, {"+15% base CpS.", "+10% base CpS.", "+5% base CpS."},+ "\x07If a golden cookie is clicked, this spirit is unslotted and all worship swaps will be used up.",+ "An immortal life spent focusing on the inner self, away from the distractions of material wealth.", ICON(21, 18)},+ {"Vomitrax, Spirit of Decadence", NULL,+ {"Golden and wrath cookie effect duration +7%. \x07" "Buildings grant -7% CpS.",+ "Golden and wrath cookie effect duration +5%. \x07" "Buildings grant -5% CpS.",+ "Golden and wrath cookie effect duration +2%. \x07" "Buildings grant -2% CpS."},+ NULL, "This sleazy spirit revels in the lust for quick easy gain and contempt for the value of steady work.",+ ICON(22, 18)},+ {"Godzamok, Spirit of Ruin", "Selling buildings triggers a buff boosted by how many buildings were sold.",+ {"Buff boosts clicks by +1% for every building sold for 10 seconds.",+ "Buff boosts clicks by +0.5% for every building sold for 10 seconds.",+ "Buff boosts clicks by +0.25% for every building sold for 10 seconds."},+ NULL, "The embodiment of natural disasters. An impenetrable motive drives the devastation caused by this spirit.",+ ICON(23, 18)},+ {"Cyclius, Spirit of Ages", "\x08" "CpS bonus fluctuating between +15% and -15% over time.",+ {"\x08" "Effect cycles over 3 hours.", "\x08" "Effect cycles over 12 hours.", "\x08" "Effect cycles over 24 hours."},+ NULL, "This spirit knows about everything you'll ever do, and enjoys dispensing a harsh judgment.", ICON(24, 18)},+ {"Selebrak, Spirit of Festivities", "Some seasonal effects are boosted.",+ {"Large boost. \x07Switching seasons is 100% pricier.", "Medium boost. \x07Switching seasons is 50% pricier.",+ "Small boost. \x07Switching seasons is 25% pricier."},+ NULL, "This is the spirit of merry getaways and regretful Monday mornings.", ICON(25, 18)},+ {"Dotjeiess, Spirit of Creation", NULL,+ {"All buildings are \x01" "7% cheaper\x02. \x07Heavenly chips have 30% less effect.",+ "All buildings are \x01" "5% cheaper\x02. \x07Heavenly chips have 20% less effect.",+ "All buildings are \x01" "2% cheaper\x02. \x07Heavenly chips have 10% less effect."},+ NULL, "All things that be and ever will be were scripted long ago by this spirit's inscrutable tendrils.",+ ICON(26, 18)},+ {"Muridal, Spirit of Labor", NULL,+ {"Clicking is \x01" "15%\x02 more powerful. \x07" "Buildings produce 3% less.",+ "Clicking is \x01" "10%\x02 more powerful. \x07" "Buildings produce 2% less.",+ "Clicking is \x01" "5%\x02 more powerful. \x07" "Buildings produce 1% less."},+ NULL, "This spirit enjoys a good cheese after a day of hard work.", ICON(27, 18)},+ {"Jeremy, Spirit of Industry", NULL,+ {"Buildings produce 10% more. \x07Golden and wrath cookies appear 10% less.",+ "Buildings produce 6% more. \x07Golden and wrath cookies appear 6% less.",+ "Buildings produce 3% more. \x07Golden and wrath cookies appear 3% less."},+ NULL, "While this spirit has many regrets, helping you rule the world through constant industrialization is not one "+ "of them.", ICON(28, 18)},+ {"Mokalsium, Mother Spirit", NULL,+ {"Milk is \x01" "10% more powerful\x02. \x07Golden and wrath cookies appear 15% less.",+ "Milk is \x01" "5% more powerful\x02. \x07Golden and wrath cookies appear 10% less.",+ "Milk is \x01" "3% more powerful\x02. \x07Golden and wrath cookies appear 5% less."},+ NULL, "A caring spirit said to contain itself, inwards infinitely.", ICON(29, 18)},+ {"Skruuia, Spirit of Scorn", "\x07" "All golden cookies are wrath cookies with a greater chance of a negative effect.",+ {"Wrinklers appear 150% faster and digest 15% more cookies.",+ "Wrinklers appear 100% faster and digest 10% more cookies.",+ "Wrinklers appear 50% faster and digest 5% more cookies."},+ NULL, "This spirit enjoys poking foul beasts and watching them squirm, but has no love for its own family.",+ ICON(21, 19)},+ {"Rigidel, Spirit of Order", NULL,+ {"Sugar lumps ripen \x01" "1 hour\x02 sooner.", "Sugar lumps ripen \x01" "40 minutes\x02 sooner.",+ "Sugar lumps ripen \x01" "20 minutes\x02 sooner."},+ "\x07" "Effect is only active when your total amount of buildings ends with 0.",+ "You will find that life gets just a little bit sweeter if you can motivate this spirit with tidy numbers and "+ "properly-filled tax returns.", ICON(22, 19)},+};+static const char *const slot_names[3] = {"Diamond slot", "Ruby slot", "Jade slot"};++/* ------------------------------------------------------------------ the rules */+static int32_t swap_wait(void) { return FPS * 60 * 60 * (S.swaps == 0 ? 16 : S.swaps == 1 ? 4 : 1); }void pantheon_logic(void) {- if (S.swap_t > 0) S.swap_t--;+ if (S.swaps < 3 && ++S.swap_t >= swap_wait()) S.swaps++, S.swap_t = 0;}void pantheon_reset(bool hard) {- if (hard) memset(S.gods, 0, sizeof S.gods), S.swaps = 3, S.swap_t = 0;+ S.swaps = 3, S.swap_t = 0;+ memset(S.gods, 0, sizeof S.gods);+ (void)hard;}/* Holobore leaves its slot when a golden cookie is clicked */bool force_unslot_god(int god) {@@ -19,7 +92,206 @@ bool force_unslot_god(int god) {}return false;}-void use_swap(int32_t t) {- if (S.swaps > 0) S.swaps--;- S.swap_t = t;+void use_swap(int32_t n) {+ S.swaps = (uint8_t)(S.swaps > n ? S.swaps - n : 0);+ S.swap_t = 0;+}+static int slot_of(int god) {+ for (int i = 0; i < 3; i++)+ if (S.gods[i] == god + 1) return i;+ return -1;+}+/* a spirit in a slot (or out of them, slot -1); the one there takes its place */+static void slot_god(int god, int slot) {+ int from = slot_of(god);+ if (slot == from) return;+ if (slot >= 0 && S.gods[slot]) {+ if (from >= 0) S.gods[from] = S.gods[slot];+ } else if (from >= 0)+ S.gods[from] = 0;+ if (slot >= 0) S.gods[slot] = (uint8_t)(god + 1);+ G.recalculate = true, G.store_dirty = true;+}++/* Cyclius' bonus now (the game's clock: here, the time played) */+double cyclius_mult(void) {+ int g = hasgod(GOD_AGES);+ if (!g) return 1;+ double hours = g == 1 ? 3 : g == 2 ? 12 : 24;+ return 1 + 0.15 * sin(S.play_time / 1000 / (60 * 60 * hours) * M_PI * 2);+}++/* ------------------------------------------------------------------ its panel */+#define PX STORE_X+#define PW STORE_W+#define GW 30+#define GH 37+#define RW (GW - 2) /* (frames a pixel narrower each side than the game's: six fit in a row) */+static int sel; /* 0..2 the slots, 3..13 the spirits */+static int held = -1; /* the spirit picked up, -1 none */++static void slot_pos(int i, int *x, int *y) { *x = PX + PW / 2 - RW / 2 - 40 + i * 40, *y = NEWS_H + 42; }+static void god_pos(int g, int *x, int *y) {+ int row = g < 6 ? 0 : 1, n = row ? 5 : 6, k = row ? g - 6 : g;+ *x = PX + (PW - n * RW) / 2 + k * RW, *y = NEWS_H + 98 + row * (GH + 3);+}++static void god_frame(int g, int x, int y, bool chosen, int alpha) {+ int col = (g + 3) % 4;+ gfx_fill_alpha(x + 2, y + 2, RW, GH, BLACK, alpha / 2);+ gfx_image_part(IM_SPELL_BG, col * GW + 1, (chosen ? 1 : 0) * GH, RW, GH, x, y - chosen, alpha);+ gfx_icon(gods[g].icon, x + 2, y + 6 - chosen, alpha);+}+static void gem(int slot, int x, int y) {+ int im = icon_index_image(ICON(23, 15));+ if (im >= 0) gfx_image_part(im, slot == 1 ? 12 : 0, slot == 2 ? 12 : 0, 12, 12, x, y, 256);+}++void pantheon_draw(void) {+ gfx_clip(PX, NEWS_H, PW, SCREEN_H - NEWS_H);+ gfx_pattern(IM_MG_BG_PANTHEON, PX, NEWS_H, PW, SCREEN_H - NEWS_H, 192, 48, PX, NEWS_H, 256);+ gfx_image_scaled_fast(IM_BORDER_SOFT, PX, NEWS_H, PW, SCREEN_H - NEWS_H, 256);+ gfx_text_outline_center(F_KAVOON, PX + PW / 2, NEWS_H + 20, "Pantheon", WHITE, 256);+ for (int i = 0; i < 3; i++) {+ int x, y;+ slot_pos(i, &x, &y);+ gem(i, x + GW / 2 - 6, y - 14);+ gfx_round_rect(x - 1, y - 1, RW + 2, GH + 2, 4, BLACK, 150);+ if (S.gods[i]) god_frame(S.gods[i] - 1, x, y, sel == i, 256);+ if (sel == i) gfx_rect(x - 2, y - 2, RW + 4, GH + 4, held >= 0 ? HEX(0xffcc66) : WHITE, 256);+ }+ for (int g = 0; g < N_GODS; g++) {+ int x, y;+ god_pos(g, &x, &y);+ if (slot_of(g) >= 0 || g == held) { /* (its place in the roster, empty) */+ gfx_round_rect(x + 1, y, RW - 2, GH, 4, BLACK, 70);+ if (g == held) god_frame(g, x, y - 6, true, 200);+ } else+ god_frame(g, x, y, sel == g + 3, 256);+ if (sel == g + 3) gfx_rect(x - 1, y - 2, RW + 2, GH + 4, WHITE, 256);+ }+ /* the worship swaps, the lump refill */+ char t[96], w[48];+ int y = NEWS_H + 190;+ if (S.swaps < 3) {+ say_time(swap_wait() - S.swap_t + FPS, -1, w);+ snprintf(t, sizeof t, "Worship swaps: %d/3 (next in %s)", S.swaps, w);+ } else+ snprintf(t, sizeof t, "Worship swaps: %d/3", S.swaps);+ gfx_text_outline_center(F_SMALL, PX + PW / 2, y, t, S.swaps ? WHITE : RGB(204, 0, 0), 256);+ gfx_text_center(F_SMALL, PX + PW / 2, SCREEN_H - 6, held >= 0 ? "EXE set in a slot Back put back" : "EXE pick up Back close",+ RGB(160, 160, 160), 256);+ gfx_unclip();+}++static void god_tip(int g, int active, int x, int *yy, int w, bool draw) {+ const God *d = &gods[g];+ if (draw) {+ gfx_icon(d->icon, x, *yy, 256);+ gfx_para(&(ParaStyle){F_NAME, F_NAME, F_NAME, WHITE, WHITE, WHITE, 12, 0}, x + 27, *yy + 1, w - 27, d->name, true);+ }+ int nh = gfx_para(&(ParaStyle){F_NAME, F_NAME, F_NAME, WHITE, WHITE, WHITE, 12, 0}, x + 27, 0, w - 27, d->name, false);+ *yy += (nh > 24 ? nh : 24) + 2;+ if (draw) tip_line(x, *yy, w);+ *yy += 4;+ char l[300];+ /* (\x07 starts the part in red, \x08 is neutral; the rest is green) */+ for (int k = -1; k < 4; k++) {+ const char *s = k < 0 ? d->before : k < 3 ? d->desc[k] : d->after;+ if (!s) continue;+ if (k == 3 && g == GOD_AGES && hasgod(GOD_AGES)) continue;+ int lx = x + (k >= 0 && k < 3 ? 14 : 0), lw = w - (lx - x);+ const char *red = strchr(s, 0x07);+ ParaStyle st = PS_SMALL;+ st.color = s[0] == 0x08 ? RGB(204, 204, 204) : s[0] == 0x07 ? RGB(255, 102, 102) : RGB(102, 255, 102);+ if (k == active - 1 && draw) gfx_fill_alpha(x - 2, *yy - 1, w + 4, 2 + gfx_para(&st, lx, 0, lw, s, false), WHITE, 30);+ if (draw && k >= 0 && k < 3) gem(k, x, *yy + 1);+ if (red && red != s) { /* (green, then red) */+ snprintf(l, sizeof l, "%.*s", (int)(red - s), s);+ int h = gfx_para(&st, lx, *yy, lw, l, draw);+ st.color = RGB(255, 102, 102);+ *yy += h;+ *yy += gfx_para(&st, lx, *yy, lw, red + 1, draw) + 2;+ } else+ *yy += gfx_para(&st, lx, *yy, lw, s[0] == 0x07 || s[0] == 0x08 ? s + 1 : s, draw) + 2;+ }+ if (g == GOD_AGES && hasgod(GOD_AGES)) {+ double m = cyclius_mult() - 1;+ char b[32];+ beautify(fabs(m) * 100, 2, b);+ snprintf(l, sizeof l, "Current bonus: %s%s%%", m < 0 ? "-" : "+", b);+ *yy += gfx_para(&PS_SMALL, x, *yy, w, l, draw) + 2;+ }+ if (g == GOD_ORDER && hasgod(GOD_ORDER)) {+ snprintf(l, sizeof l, "Buildings owned: %d\nEffect is %s.", G.buildings_owned,+ G.buildings_owned % 10 == 0 ? "active" : "inactive");+ *yy += gfx_para(&PS_SMALL, x, *yy, w, l, draw) + 2;+ }+ snprintf(l, sizeof l, CH_LQUOTE "%s" CH_RQUOTE, d->quote);+ ParaStyle q = PS_QUOTE;+ q.align = 1;+ *yy += gfx_para(&q, x + 4, *yy + 2, w - 8, l, draw) + 4;+}++int pantheon_tip(int x, int y, int w, bool draw) {+ int yy = y;+ if (sel < 3) {+ if (draw) {+ gem(sel, x + w / 2 - 6, yy);+ gfx_text_outline_center(F_NAME, x + w / 2, yy + 24, slot_names[sel], WHITE, 256);+ }+ yy += 28;+ if (!S.gods[sel]) {+ yy += gfx_para(&PS_SMALL, x, yy + 2, w, held >= 0 ? "Press EXE to set the spirit here." :+ "Pick a spirit up (EXE) to set it in this slot.", draw) + 4;+ return yy - y;+ }+ if (draw) tip_line(x, yy, w);+ yy += 4;+ int slot = sel;+ if (aura_mult(AURA_SUPREME_INTELLECT) > 0 && slot > 0) slot--;+ god_tip(S.gods[sel] - 1, slot + 1, x, &yy, w, draw);+ return yy - y;+ }+ god_tip(sel - 3, 0, x, &yy, w, draw);+ return yy - y;+}++void pantheon_keys(uint32_t p) {+ U.tip_t = FPS * 6;+ if (p & K_LEFT) {+ if (sel > 0 && sel != 3 && sel != 9) sel--;+ }+ if (p & K_RIGHT) {+ if (sel < 2 || (sel >= 3 && sel < 13 && sel != 8)) sel++;+ }+ if (p & K_UP) sel = sel >= 9 ? sel - 6 : sel >= 3 ? (sel - 3) * 3 / 6 : sel;+ if (p & K_DOWN) sel = sel < 3 ? 3 + sel * 2 : sel < 9 ? (sel + 6 < 14 ? sel + 6 : 13) : sel;+ if (p & K_BACK && held >= 0) {+ held = -1;+ return;+ }+ if (!(p & K_EXE)) return;+ if (held >= 0) {+ if (sel < 3) {+ int from = slot_of(held);+ if (from == sel) {+ held = -1;+ return;+ }+ if (S.swaps == 0) {+ popup("No worship swaps left!", LEFT_W / 2, COOKIE_Y - 30);+ return;+ }+ use_swap(1);+ slot_god(held, sel);+ } else+ slot_god(held, -1); /* (back to the roster: free) */+ held = -1;+ return;+ }+ if (sel < 3) {+ if (S.gods[sel]) held = S.gods[sel] - 1;+ } else if (slot_of(sel - 3) < 0)+ held = sel - 3, sel = 0;}diff --git a/games/cookieclicker/src/prestige.c b/games/cookieclicker/src/prestige.cindex b2c62594..b516bcc9 100644--- a/games/cookieclicker/src/prestige.c+++ b/games/cookieclicker/src/prestige.c@@ -185,7 +185,7 @@ void game_reset(bool hard) {S.start_date = S.play_time;S.cookies_sucked = 0, S.wrinklers_popped = 0;memset(S.wrinklers, 0, sizeof S.wrinklers);- S.santa_level = 0, S.reindeer_clicked = 0;+ S.santa_level = 0, S.reindeer_clicked = 0, S.fortune_gc = 0, S.fortune_cps = 0;S.dragon_level = 0, S.dragon_aura = 0, S.dragon_aura2 = 0;S.ticker_clicks = 0;if (!hard && gained_prestige > 0) S.resets++;diff --git a/games/cookieclicker/src/shimmer.c b/games/cookieclicker/src/shimmer.cindex 0324f579..86d93d1b 100644--- a/games/cookieclicker/src/shimmer.c+++ b/games/cookieclicker/src/shimmer.c@@ -209,6 +209,7 @@ Shimmer *shimmer_new(int type, int force, bool no_count) {if (!m) return NULL;memset(m, 0, sizeof *m);m->used = 1, m->type = (uint8_t)type, m->force = (uint8_t)force, m->id = G.shimmers_id++;+ m->pad[1] = (uint8_t)rnd_int(8); /* (the season's picture: which heart, egg or familiar) */m->spawn_lead = 0;if (!no_count) {if (type == SHIMMER_GOLDEN) G.nshimmers_golden++;diff --git a/games/cookieclicker/src/ui.c b/games/cookieclicker/src/ui.cindex 2341fe7d..a05d39fa 100644--- a/games/cookieclicker/src/ui.c+++ b/games/cookieclicker/src/ui.c@@ -154,10 +154,13 @@ void draw_prompt(void) {/* ------------------------------------------------------------------ the news */#define NEWS_X 22void ui_news_next(void) {+ char t[sizeof U.news[0]];+ news_next(t, sizeof t);+ U.news_t = 0;+ if (!t[0]) return; /* (nothing to say: the last news stays) */U.news_cur ^= 1;- news_next(U.news[U.news_cur], sizeof U.news[0]);+ memcpy(U.news[U.news_cur], t, sizeof t);U.news_fade = FPS / 2;- U.news_t = 0;}static int news_lines(const char *s, char lines[2][200], int w) {@@ -211,6 +214,10 @@ void draw_news(void) {news_text(U.news[U.news_cur], (int)((1 - k) * 256), (int)(k * 8));} elsenews_text(U.news[U.news_cur], 256, 0);+ if (U.on_ticker) { /* (chosen: EXE presses it) */+ gfx_rect(NEWS_X - 2, 0, SCREEN_W - NEWS_X + 2, NEWS_H - 2, RGB(255, 238, 200), 200);+ gfx_fill_alpha(NEWS_X - 1, 1, SCREEN_W - NEWS_X, NEWS_H - 4, WHITE, 20);+ }/* the sugar lump */if (can_lumps()) {int icon, icon2;@@ -331,9 +338,20 @@ void ui_keys(uint32_t pressed, uint32_t held) {rows_keys(pressed);return;}+ if (U.on_ticker) { /* the news ticker, above the store */+ if (pressed & K_DOWN) U.on_ticker = false, U.tip_t = TIP_TIME;+ if (pressed & K_EXE) {+ extern void ticker_click(void);+ ticker_click();+ ui_news_next();+ }+ return;+ }if (pressed & (K_LEFT | K_RIGHT | K_UP | K_DOWN)) {+ int sec = U.sec, idx = U.idx;store_move(pressed & K_LEFT ? -1 : pressed & K_RIGHT ? 1 : 0, pressed & K_UP ? -1 : pressed & K_DOWN ? 1 : 0);- U.tip_t = TIP_TIME;+ if (pressed & K_UP && sec == U.sec && idx == U.idx) U.on_ticker = true, U.tip_t = 0; /* (up past the top) */+ else U.tip_t = TIP_TIME;scroll_to_selection();}if (pressed & K_EXE) {@@ -411,7 +429,8 @@ void ui_tick(void) {void ui_frame(void) {ui_store_layout();bool page = U.overlay == OV_OPTIONS || U.overlay == OV_STATS || U.overlay == OV_INFO || U.overlay == OV_KEYS;- bool full = U.dirty > 0 || G.on_ascend || G.ascend_timer > 0 || G.reincarnate_timer > 0 ||+ bool reindeer = G.nshimmers_reindeer > 0; /* (it crosses the whole screen) */+ bool full = U.dirty > 0 || G.on_ascend || G.ascend_timer > 0 || G.reincarnate_timer > 0 || reindeer ||G.draw_t % (page ? 10 : 6) == 0;if (U.dirty > 0) U.dirty--;if (full) gfx_render(0, 0, SCREEN_W, SCREEN_H, draw_all);diff --git a/games/cookieclicker/src/ui.h b/games/cookieclicker/src/ui.hindex 1d63d648..bc45abea 100644--- a/games/cookieclicker/src/ui.h+++ b/games/cookieclicker/src/ui.h@@ -47,6 +47,7 @@ typedef struct {float asc_x, asc_y, asc_tx, asc_ty; /* where the heavens are (and are going) */bool store_dirty;bool news_long; /* the news goes by (too long for two lines) */+ bool on_ticker; /* the news ticker chosen (up from the top of the store) */int dirty; /* frames still to draw whole */} Ui;extern Ui U;diff --git a/games/cookieclicker/src/ui_left.c b/games/cookieclicker/src/ui_left.cindex cac0a815..785ef445 100644--- a/games/cookieclicker/src/ui_left.c+++ b/games/cookieclicker/src/ui_left.c@@ -203,6 +203,10 @@ static const char *const name_b[] = {"Cookie", "Machine", "Robot", "Headbanger","Space Cowboy", "Toast", "Spaghetti", "Turtle", "Cat", "Kitten", "Dog", "Puppy","Cookies", "Fungus", "Stew", "Machete", "Biscuit", "Crumb", "Fruitcake", "Saga","Melon", "Pancake", "Waffle", "Mittens", "Feline", "Nose", "Nugget"};+void bakery_name_short(char *out, int size) {+ int a = S.bakery_name1 % (sizeof name_a / sizeof name_a[0]), b = S.bakery_name2 % (sizeof name_b / sizeof name_b[0]);+ snprintf(out, size, "%s %s", name_a[a], name_b[b]);+}void bakery_name(char *out, int size) {int a = S.bakery_name1 % (sizeof name_a / sizeof name_a[0]), b = S.bakery_name2 % (sizeof name_b / sizeof name_b[0]);snprintf(out, size, "%s %s's bakery", name_a[a], name_b[b]);@@ -296,10 +300,31 @@ void draw_left(void) {}/* golden cookies, wrath cookies, the cookie storm's drops */+/* the golden cookie's picture: the season's (wreaths, hearts, eggs, familiars) */+static int golden_pic(const Shimmer *m) {+ int w = m->wrath, k = m->pad[1];+ switch (S.season) {+ case SEASON_CHRISTMAS: return w ? IM_WRATH_WREATH : IM_GOLD_WREATH;+ case SEASON_VALENTINES: return (w ? IM_HEART1_0 : IM_HEART0_0) + k % 8;+ case SEASON_EASTER: return (w ? IM_BUNNY1_0 : IM_BUNNY0_0) + k % 4;+ case SEASON_HALLOWEEN: return (w ? IM_FAMILIAR1_0 : IM_FAMILIAR0_0) + k % 4;+ default: return w ? IM_WRATH_COOKIE : IM_GOLD_COOKIE;+ }+}+void draw_shimmers(void) {for (int i = 0; i < MAX_SHIMMERS; i++) {const Shimmer *m = &G.shimmers[i];- if (!m->used || m->type != SHIMMER_GOLDEN) continue;+ if (!m->used) continue;+ if (m->type == SHIMMER_REINDEER) { /* across the screen, bouncing */+ float t = (float)m->life / (FPS * m->dur), k = t * 2 - 1;+ float curve = 1 - powf(k, 12);+ float x = m->x + (SCREEN_W + 62) * (1 - t), y = m->y - fabsf(sinf(m->life * 0.1f)) * 128 * 0.37f;+ float sc = m->size_mult * (1 + sinf(m->id * 0.53f) * 0.1f);+ gfx_image_rotated(IM_REINDEER, x + 31, y + 39, 62 * sc, 78 * sc, sinf(m->life * 0.2f + 0.3f) * 10 * (float)M_PI / 180,+ (int)(curve * 256));+ continue;+ }float k = (float)m->life / (FPS * m->dur) * 2 - 1;float curve = 1 - k * k * k * k;int id = m->id;@@ -310,8 +335,7 @@ void draw_shimmers(void) {(1 + (0.06f + sinf(id * 0.41f) * 0.05f) * sinf(G.real_t * (0.25f + sinf(id * 0.73f) * 0.15f) + id));}float s = 36 * scale;- gfx_image_rotated(m->wrath ? IM_WRATH_COOKIE : IM_GOLD_COOKIE, m->x + 18, m->y + 18, s, s,- rot * (float)M_PI / 180, (int)(curve * 256));+ gfx_image_rotated(golden_pic(m), m->x + 18, m->y + 18, s, s, rot * (float)M_PI / 180, (int)(curve * 256));}}diff --git a/games/cookieclicker/tests/play.c b/games/cookieclicker/tests/play.cindex dc4d76fa..16c0081c 100644--- a/games/cookieclicker/tests/play.c+++ b/games/cookieclicker/tests/play.c@@ -6,7 +6,7 @@* Keys: left right up down ok exe back shift home alpha mul div toolbox var del xnt 0-9. "a-b:key" holds the* key from frame a to b, "a:key" for one frame (frames are thirtieths of a second; one is drawn every frame).* Presets set a bakery up before the keys play: start (a new game), early, mid, late, ascend (on the heavens),- * grimoire (the wizard towers' minigame open), golden (a golden cookie on screen), wrath, wrinklers.+ * grimoire and pantheon (the minigames open), golden (a golden cookie on screen), wrath, wrinklers.* --bot plays by itself: it clicks, buys the cheapest of what it can afford, catches golden cookies, and so on;* it prints what the bakery got to. Screenshots are DIR/shot_<frame>.ppm; --raw saves the frames drawn as RGB565* (DIR/frame_<ms>.raw, for NumPlay's tools/record.py --frames). The end prints the game's state. */@@ -112,7 +112,7 @@ static void preset(const char *name) {buy_upgrades(2000);S.cookies = 1400;} else if (!strcmp(name, "mid") || !strcmp(name, "golden") || !strcmp(name, "wrath") || !strcmp(name, "grimoire") ||- !strcmp(name, "wrinklers")) {+ !strcmp(name, "wrinklers") || !strcmp(name, "pantheon")) {S.cookies_earned = 6.2e9, S.cookie_clicks = 5400, S.handmade_cookies = 2.1e7;static const int n[] = {80, 70, 50, 40, 35, 25, 20, 15, 8, 3};for (int b = 0; b < 10; b++) own(b, n[b]);@@ -135,6 +135,12 @@ static void preset(const char *name) {bit_set(S.upgrades_bought, U_ONE_MIND, true), bit_set(S.upgrades_bought, U_COMMUNAL_BRAINSWEEP, true);for (int i = 0; i < 6; i++) S.wrinklers[i].phase = 2, S.wrinklers[i].close = 1, S.wrinklers[i].hp = 2.1f;}+ if (!strcmp(name, "pantheon")) {+ S.buildings[B_TEMPLE].level = 1;+ S.gods[0] = GOD_INDUSTRY + 1, S.gods[2] = GOD_AGES + 1, S.swaps = 2;+ S.on_minigame = B_TEMPLE + 1;+ U.view = VIEW_ROWS;+ }if (!strcmp(name, "grimoire")) {S.buildings[B_WIZARD_TOWER].level = 1;extern void grimoire_reset(bool hard);diff --git a/games/cookieclicker/tools/pack.py b/games/cookieclicker/tools/pack.pyindex 8b251db7..e1d99ffb 100644--- a/games/cookieclicker/tools/pack.py+++ b/games/cookieclicker/tools/pack.py@@ -295,6 +295,344 @@ def cname(s):return s+# ------------------------------------------------------------------ the news ticker+# The game's getNewTicker, read from main.js: each list.push(...) of its English branches becomes a template+# (choices nested in \x10 ... \x11 ... \x12, the bakery's name and numbers as \x13 codes, random numbers as+# \x14<n>:<add>;) with what makes it come up (NEWS_KINDS, read by news.c).+NEWS_KINDS = ["GRANDMA", "GRANDMA_THREAT", "GRANDMA_ANGRY", "GRANDMA_RETURN", "SOLD_GRANDMA", "BUILDING", "SEASON",+ "RARE_ACHIEV", "RARE_UPGRADE", "DUDE_SWEET", "WILL_WRIGHT", "MISC", "BUSINESS", "LORE", "WRATH",+ "FOOLS", "FOOLS_RARE", "FOOLS_BUILDING", "FOOLS_LORE"]+++def js_tokens(src):+ toks = []+ i, n = 0, len(src)+ while i < n:+ c = src[i]+ if c in " \t\r\n":+ i += 1+ elif src.startswith("//", i):+ while i < n and src[i] != "\n":+ i += 1+ elif src.startswith("/*", i):+ i = src.index("*/", i) + 2+ elif c in "'\"":+ j, out = i + 1, []+ while src[j] != c:+ if src[j] == "\\":+ nx = src[j + 1]+ out.append({"n": "\n", "t": "\t"}.get(nx, nx))+ j += 2+ else:+ out.append(src[j])+ j += 1+ toks.append(("s", "".join(out)))+ i = j + 1+ elif c.isalpha() or c == "_":+ j = i+ while j < n and (src[j].isalnum() or src[j] in "_."):+ j += 1+ toks.append(("i", src[i:j]))+ i = j+ elif c.isdigit():+ j = i+ while j < n and (src[j].isdigit() or src[j] == "."):+ j += 1+ toks.append(("n", src[i:j]))+ i = j+ else:+ two = src[i:i + 2]+ if two in ("==", "!=", ">=", "<=", "&&", "||"):+ toks.append(("p", src[i:i + 3] if src[i:i + 3] in ("===", "!==") else two))+ i += 3 if src[i:i + 3] in ("===", "!==") else 2+ else:+ toks.append(("p", c))+ i += 1+ return toks+++class NewsParser:+ """the ticker's expressions: strings, +, choose([...]), loc(...), the few variables it uses"""++ def __init__(self, toks, en_lists, animals):+ self.t, self.i, self.en, self.animals = toks, 0, en_lists, animals++ def peek(self, k=0):+ return self.t[self.i + k] if self.i + k < len(self.t) else ("p", "")++ def take(self, v=None):+ tok = self.t[self.i]+ if v is not None and tok[1] != v:+ raise SystemExit(f"news: expected {v}, got {tok} near {self.t[self.i - 3:self.i + 3]}")+ self.i += 1+ return tok++ def args(self):+ self.take("(")+ out = []+ while self.peek()[1] != ")":+ out.append(self.expr())+ if self.peek()[1] == ",":+ self.take(",")+ self.take(")")+ return out++ def expr(self):+ e = self.add()+ if self.peek()[1] == "?": # (EN ? a : b, or a plural)+ self.take("?")+ a = self.expr()+ self.take(":")+ b = self.expr()+ if e == ("EN",):+ return a+ if e == ("PLURAL1",):+ return ["\x13P"]+ raise SystemExit(f"news: a ? b : c on {e}")+ return e++ def add(self):+ parts = self.prim()+ while self.peek()[1] == "+":+ self.take("+")+ parts = self.cat(parts, self.prim())+ while self.peek()[1] in ("==", "<", ">"): # (a comparison: only the plural's)+ op = self.take()[1]+ rhs = self.prim()+ if parts == ["\x13Y"] and op == "==" and rhs == ["1"]:+ parts = ("PLURAL1",)+ else:+ raise SystemExit(f"news: comparison {parts} {op} {rhs}")+ return parts++ @staticmethod+ def cat(a, b):+ if isinstance(a, tuple) or isinstance(b, tuple):+ raise SystemExit(f"news: can't join {a} and {b}")+ return a + b++ def choice(self, alts):+ return ["\x10" + "\x11".join("".join(x) for x in alts) + "\x12"]++ def prim(self):+ kind, v = self.take()+ if kind == "s": # (a grandma's words: "...", signed)+ return [clean(v.replace("<sig>", " \u2013 ").replace("</sig>", "").replace("<q>", "\u201c")+ .replace("</q>", "\u201d"), False)]+ if kind == "n":+ return [v]+ if v == "(":+ e = self.expr()+ self.take(")")+ return e+ if v == "[":+ items = []+ while self.peek()[1] != "]":+ items.append(self.expr())+ if self.peek()[1] == ",":+ self.take(",")+ self.take("]")+ return ("LIST", items)+ if v == "choose":+ (a,) = self.args()+ if isinstance(a, tuple) and a[0] == "LIST":+ return self.choice(a[1])+ if isinstance(a, tuple) and a[0] == "LOCLIST":+ return self.choice([[x] for x in a[1]])+ if isinstance(a, list) and len(a) == 1 and a[0].startswith("\x10"): # (choose(animals))+ return a+ raise SystemExit(f"news: choose of {a}")+ if v == "loc":+ a = self.args()+ key = "".join(a[0])+ if key in self.en and isinstance(self.en[key], list):+ return ("LOCLIST", [clean(x, False) for x in self.en[key]])+ text = self.en.get(key, key)+ if isinstance(text, list):+ text = text[0]+ if text == "/": # (EN.js: the key itself)+ text = key+ for k, arg in enumerate(a[1:]):+ text = text.replace(f"%{k + 1}", "".join(arg))+ return [clean(text, False)]+ if v == "EN":+ return ("EN",)+ if v == "NEWS":+ return ["News : "]+ if v == "animals":+ return self.choice([[clean(x, False)] for x in self.animals])+ if v == "Game.bakeryName":+ return ["\x13B"]+ if v == "Game.Objects": # (only Game.Objects['Grandma'].single)+ self.take("[")+ self.take()+ self.take("]")+ self.take(".")+ assert self.take()[1] == "single"+ return ["grandma"]+ if v == "Beautify":+ (a,) = self.args()+ return a+ if v == "Game.cookiesEarned":+ return ["\x13E"]+ if v == "Math.ceil": # (Math.ceil(Game.cookiesEarned/8000000000))+ self.take("(")+ assert self.take()[1] == "Game.cookiesEarned" and self.take()[1] == "/" and self.take()[1] == "8000000000"+ self.take(")")+ return ["\x13Y"]+ if v == "Math.floor": # (Math.floor(Math.random()*n+add))+ self.take("(")+ assert self.take()[1] == "Math.random"+ self.take("(")+ self.take(")")+ self.take("*")+ n = self.take()[1]+ self.take("+")+ add = self.take()[1]+ self.take(")")+ return [f"\x14{n}:{add};"]+ raise SystemExit(f"news: unknown {kind} {v}")+++def news_templates(ref):+ """[(kind, arg, template)] of the game's English ticker"""+ src = open(os.path.join(ref, "main.js"), encoding="utf-8").read()+ a = src.index("Game.getNewTicker=function(manual)")+ b = src.index("for (var i=0;i<Game.modHooks['ticker'].length;i++)", a)+ body = src[a:b]+ en_src = open(os.path.join(ref, "loc", "EN.js"), encoding="utf-8").read()+ en = {}+ for m in re.finditer(r'"(Ticker \([^"]*\))":\s*\[(.*?)\]', en_src, re.S):+ en[m.group(1)] = [x for _, x in js_tokens("[" + m.group(2) + "]") if _ == "s"]+ for m in re.finditer(r'^\s*"([^"]+)":\s*"((?:[^"\\]|\\.)*)"', en_src, re.M):+ en.setdefault(m.group(1), m.group(2).replace('\\"', '"'))+ animals = re.search(r"var animals=\[(.*?)\];", body).group(1)+ animals = [v for k, v in js_tokens("[" + animals + "]") if k == "s"]+ toks = js_tokens(body)+ out = []+ # walk the tokens: the blocks the pushes are in (their conditions), and each push's own condition+ stack, pending, cond = [], None, []+ i = 0+ while i < len(toks):+ k, v = toks[i]+ if v == "if":+ # the condition's tokens+ j, depth = i + 1, 0+ while True:+ if toks[j][1] == "(":+ depth += 1+ elif toks[j][1] == ")":+ depth -= 1+ if depth == 0:+ break+ j += 1+ cond = toks[i + 2:j]+ i = j + 1+ if toks[i][1] == "{":+ stack.append(cond)+ cond = []+ i += 1+ continue+ if v == "else":+ i += 1+ if toks[i][1] == "{":+ stack.append([("i", "ELSE")])+ i += 1+ continue+ if v == "{":+ stack.append([])+ i += 1+ continue+ if v == "}":+ stack.pop()+ i += 1+ continue+ if v == "list.push":+ js = lambda ts: "".join("'" + t[1] + "'" if t[0] == "s" else t[1] for t in ts)+ ctx = " ".join(js(c) for c in stack)+ own = js(cond)+ cond = []+ if "!EN" in ctx or own.startswith("!EN"): # (the other languages' lists: past them)+ j, depth = i + 1, 0+ while True:+ if toks[j][0] == "p":+ depth += {"(": 1, ")": -1}.get(toks[j][1], 0)+ j += 1+ if depth == 0:+ break+ i = j+ continue+ p = NewsParser(toks, en, animals)+ p.i = i + 1+ args = p.args()+ i = p.i+ for arg in args:+ if isinstance(arg, tuple) and arg[0] == "LOCLIST":+ arg = p.choice([[x] for x in arg[1]])+ if isinstance(arg, tuple):+ raise SystemExit(f"news: push of {arg}")+ kind, karg = news_kind(ctx, own)+ if kind:+ out.append((kind, karg, "".join(arg)))+ continue+ if v == ";":+ cond = []+ i += 1+ return out+++def news_kind(ctx, own):+ """what makes a push come up: its block (ctx) and its own condition"""+ fools = "Game.season=='fools'" in ctx and "EN&&" in ctx+ m = re.search(r"Game\.Objects\['([^']+)'\]\.amount>0", own)+ if fools:+ if "Game.TickerN%2==0" in ctx and m:+ return "FOOLS_BUILDING", m.group(1)+ lm = re.match(r"loreProgress<=(\d+)$", own)+ if lm:+ return "FOOLS_LORE", int(lm.group(1))+ if own == "Game.cookiesEarned>=1000":+ return "FOOLS", 0+ if own == "Game.cookiesEarned>=1000&&Math.random()<0.05":+ return "FOOLS_RARE", 0+ raise SystemExit(f"news: fools push under {own}")+ if "Game.elderWrath>0" in ctx:+ wm = re.match(r"Game\.elderWrath==(\d)$", own)+ return "WRATH", int(wm.group(1))+ if "list.length==0" in ctx:+ lm = re.match(r"loreProgress<=(\d+)$", own)+ return "LORE", int(lm.group(1))+ if own.startswith("Game.Objects['Grandma'].amount>0"):+ return "GRANDMA", 0+ if own == "!Game.prefs.notScary&&Game.Objects['Grandma'].amount>=50":+ return "GRANDMA_THREAT", 0+ if own == "EN&&Game.HasAchiev('Just wrong')&&Math.random()<0.05":+ return "SOLD_GRANDMA", 0+ if own == "!Game.prefs.notScary&&Game.HasAchiev('Just wrong')&&Math.random()<0.4":+ return "GRANDMA_ANGRY", 0+ if own.startswith("!Game.prefs.notScary&&Game.Objects['Grandma'].amount>=1&&Game.pledges>0"):+ return "GRANDMA_RETURN", 0+ if m:+ return "BUILDING", m.group(1)+ sm = re.match(r"Game\.season=='(\w+)'&&Game\.cookiesEarned>=1000$", own)+ if sm:+ return "SEASON", sm.group(1)+ if "Math.random()<0.05" in ctx:+ am = re.match(r"Game\.HasAchiev\('([^']+)'\)$", own)+ if am:+ return "RARE_ACHIEV", am.group(1)+ um = re.match(r"Game\.Has\('([^']+)'\)$", own)+ if um:+ return "RARE_UPGRADE", um.group(1)+ if own == "Game.HasAchiev('Dude, sweet')&&Math.random()<0.2":+ return "DUDE_SWEET", 0+ if "Math.random()<0.001" in ctx:+ return "WILL_WRIGHT", 0+ if own == "Game.cookiesEarned>=10000":+ return "MISC", 0+ raise SystemExit(f"news: a push under '{ctx}' / '{own}'")++ROW_FRAMES = {"javascriptconsole": 2, "idleverse": 4, "cortex": 4}@@ -581,6 +919,26 @@ def main(ref, game_json):defs.append(f"#define OFF_UNLOCK_AT {P.put(rec, 8)}")defs.append(f"#define N_UNLOCK_AT {len(L['unlockAt'])}")+ # ---- the news ticker: its templates, and what brings each up (news.c)+ news = news_templates(ref)+ objects = [o["name"] for o in G["objects"]]+ ach_by_name = {a["name"]: a["id"] for a in G["achievements"]}+ nrec = bytearray()+ for kind, arg, text in news:+ if kind in ("BUILDING", "FOOLS_BUILDING"):+ arg = objects.index(arg)+ elif kind == "SEASON":+ arg = SEASONS[arg]+ elif kind == "RARE_ACHIEV":+ arg = ach_by_name[arg]+ elif kind == "RARE_UPGRADE":+ arg = up_by_name[arg]+ nrec += struct.pack("<IBBH", T.add(text), NEWS_KINDS.index(kind), 0, arg)+ defs.append(f"#define OFF_NEWS {P.put(bytes(nrec))}")+ defs.append(f"#define N_NEWS {len(news)}")+ for i, k in enumerate(NEWS_KINDS):+ defs.append(f"#define NK_{k} {i}")+# ---- the texts, the pictures' tabletext_off = P.put(bytes(T.blob))defs.append(f"#define OFF_TEXT {text_off}")