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 game's pictures, rules, store and heavens
Mason363b036d83acb10
diff --git a/games/cookieclicker/Makefile b/games/cookieclicker/Makefileindex 9047511a..5baa75e1 100644--- a/games/cookieclicker/Makefile+++ b/games/cookieclicker/Makefile@@ -1,56 +1,57 @@-# Cookie Clicker — click the big cookie, buy buildings and upgrades, catch golden cookies.-# make build output/cookieclicker.nwa-# make check link the app like the calculator does (output/cookieclicker.bin)-# make data src/data.h from tools/data.py (the names, news and pictures; needs zopfli)-#-# In NumPlay the game draws with the launcher's strips, shapes and fonts, unpacks its texts with its-# DEFLATE decoder and saves through its file functions (module.o leaves them to the launcher); on its-# own it brings them along.+# Cookie Clicker on the NumWorks calculator.+# make output/cookieclicker.nwa+# make check link it like the calculator does (output/cookieclicker.bin)+# make host build/play: the game on a computer, for tests and screenshots+# make test the game played on a computer (tests/check.py, with the sanitizers)+# make data src/data.bin and src/data.h from the public material tools/fetch.py gathers+# (REF=its folder; Node runs the game's script for its numbers and texts, then Python with+# Pillow and NumPy packs them)Q ?= @-CC = arm-none-eabi-gcc+# the ARM toolchain on the PATH, or in TOOLCHAIN=<its bin folder>+TOOLCHAIN ?=+BIN = $(if $(TOOLCHAIN),$(TOOLCHAIN)/)+CC = $(BIN)arm-none-eabi-gccNWLINK ?= npx --yes -- [email protected]+STRIP ?= $(BIN)arm-none-eabi-strip --strip-unneeded+SIZE = $(BIN)arm-none-eabi-sizeBUILD_DIR = output-SRC = src/main.c-HEADERS = src/data.h ../common/epsilon_app.h ../common/epsilon_files.h ../common/np_text.h \- ../../launcher/src/gfx.h ../../launcher/src/np.h ../../launcher/src/font.h ../../launcher/src/inflate.h+REF ?=-# (its numbers are doubles, written exactly: no -fsingle-precision-constant, except for the launcher's drawing)-CFLAGS = -std=c11 $(shell $(NWLINK) eadk-cflags-device)-CFLAGS += -Os -Wall -Wextra -Wno-unused-parameter -fno-math-errno+# the drawing runs every frame at -O2; the rest is small at -Os+HOT = src/gfx.c+COLD = $(filter-out $(HOT) src/plat_host.c src/plat_eadk.c,$(wildcard src/*.c))+COLD_OBJ = $(patsubst %.c,$(BUILD_DIR)/cold/%.o,$(notdir $(COLD)))+HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h++# (its numbers are doubles, as the game's: no -fsingle-precision-constant)+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DDATA_BIN='"src/data.bin"'+CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errnoCFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal-LIBFLAGS = $(CFLAGS) -fsingle-precision-constant+CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)LDFLAGS = -Wl,--relocatable -nostartfiles --specs=nano.specsLDFLAGS += -Wl,-e,main -Wl,-u,eadk_app_name -Wl,-u,eadk_app_icon -Wl,-u,eadk_api_levelLDFLAGS += -Wl,--gc-sections -flinker-output=nolto-rel-.PHONY: build check clean data+.PHONY: build check clean host test databuild: $(BUILD_DIR)/cookieclicker.nwa+# apps get 133652 bytes of RAM on custom builds of Epsilon 25.2 (148928 or more on official ones)check: $(BUILD_DIR)/cookieclicker.nwa- $(Q) $(NWLINK) nwa-bin $< $(BUILD_DIR)/cookieclicker.bin+ $(Q) $(NWLINK) nwa-bin --ram-length 133652 $< $(BUILD_DIR)/cookieclicker.bin@echo "BIN $(BUILD_DIR)/cookieclicker.bin: $$(wc -c < $(BUILD_DIR)/cookieclicker.bin) bytes"-data:- python3 tools/data.py+$(BUILD_DIR)/data.o: src/data.S src/data.bin | $(BUILD_DIR)+ $(Q) $(CC) -c -DDATA_BIN='"src/data.bin"' $< -o $@-# compiled, then linked (the link options would upset the compiler)-$(BUILD_DIR)/main.o: $(SRC) $(HEADERS) | $(BUILD_DIR)- @echo "CC $<"- $(Q) $(CC) $(CFLAGS) -c $(SRC) -o $@-$(BUILD_DIR)/gfx.o: ../../launcher/src/gfx.c $(HEADERS) | $(BUILD_DIR)- $(Q) $(CC) $(LIBFLAGS) -c $< -o $@-$(BUILD_DIR)/font_data.o: ../../launcher/src/font_data.c ../../launcher/src/font.h | $(BUILD_DIR)- $(Q) $(CC) $(LIBFLAGS) -c $< -o $@-$(BUILD_DIR)/xfont.o: ../../launcher/src/xfont.c ../../launcher/src/np_xfont.h $(HEADERS) | $(BUILD_DIR)- $(Q) $(CC) $(LIBFLAGS) -c $< -o $@-$(BUILD_DIR)/inflate.o: ../../launcher/src/inflate.c ../../launcher/src/inflate.h | $(BUILD_DIR)- $(Q) $(CC) $(LIBFLAGS) -c $< -o $@+$(BUILD_DIR)/cold/%.o: src/%.c $(HEADERS)+ @mkdir -p $(@D)+ $(Q) $(CC) $(CFLAGS) -Os -c $< -o $@-$(BUILD_DIR)/cookieclicker.nwa: $(BUILD_DIR)/main.o $(BUILD_DIR)/gfx.o $(BUILD_DIR)/font_data.o $(BUILD_DIR)/xfont.o \- $(BUILD_DIR)/inflate.o $(BUILD_DIR)/icon.o+$(BUILD_DIR)/cookieclicker.nwa: $(HOT) src/plat_eadk.c $(COLD_OBJ) $(HEADERS) $(BUILD_DIR)/icon.o $(BUILD_DIR)/data.o@echo "LD $@"- $(Q) $(CC) $(CFLAGS) $(LDFLAGS) $^ -lm -o $@- $(Q) arm-none-eabi-strip --strip-unneeded $@+ $(Q) $(CC) $(CFLAGS) $(LDFLAGS) $(HOT) src/plat_eadk.c $(COLD_OBJ) $(BUILD_DIR)/data.o $(BUILD_DIR)/icon.o -lm -o $@+ $(Q) $(STRIP) $@+ $(Q) $(SIZE) $@$(BUILD_DIR)/icon.o: src/icon.png | $(BUILD_DIR)@echo "ICON $<"@@ -59,21 +60,23 @@ $(BUILD_DIR)/icon.o: src/icon.png | $(BUILD_DIR)$(BUILD_DIR):$(Q) mkdir -p $@-clean:- $(Q) rm -rf $(BUILD_DIR)+# on a computer: tests/play.c plays it with scripted keys and saves screenshots+HOST_FLAGS = -std=gnu11 -O1 -g -Wall -Wextra -Wno-unused-parameter -Isrc -DHOST -DDATA_BIN='"src/data.bin"'+HOST_SAN = -fsanitize=address,undefined -fno-sanitize-recover=undefined+HOST_SRC = $(filter-out src/plat_eadk.c,$(wildcard src/*.c))+host: build/play+build/play: $(HOST_SRC) tests/play.c src/data.S src/data.bin $(HEADERS)+ $(Q) mkdir -p $(dir $@)+ $(Q) cc $(HOST_FLAGS) $(HOST_SAN) $(HOST_SRC) tests/play.c src/data.S -lm -o $@+ @echo "HOST $@"-# NumPlay launcher: the app as a module (see ../../tools/npmodule.py) for the-# calculator, and as a relocatable object for the simulator build.-.PHONY: module sim-module-module: $(BUILD_DIR)/module.o-$(BUILD_DIR)/module-main.o: $(SRC) $(HEADERS) | $(BUILD_DIR)- $(Q) $(CC) $(CFLAGS) -DNP_MODULE=1 -c $(SRC) -o $@-$(BUILD_DIR)/module.o: $(BUILD_DIR)/module-main.o- $(Q) $(CC) $(CFLAGS) -Wl,--relocatable -nostartfiles -nostdlib -Wl,-e,main -flinker-output=nolto-rel $< -o $@+test: build/play+ python3 tests/check.py build/play-sim-module: $(BUILD_DIR)/sim-module.o-$(BUILD_DIR)/sim-module.o: $(SRC) $(HEADERS) | $(BUILD_DIR)- $(Q) mkdir -p $(BUILD_DIR)/sim- $(Q) cc -std=c11 -O2 -fPIC $(shell $(NWLINK) eadk-cflags-simulator) -DNP_MODULE=1 -Dmain=np_cookieclicker_main \- -c $(SRC) -o $(BUILD_DIR)/sim/main.o- $(Q) ld -r $(BUILD_DIR)/sim/main.o -exported_symbol _np_cookieclicker_main -o $@+data:+ @test -n "$(REF)" || { echo "make data REF=<the folder tools/fetch.py filled>"; exit 1; }+ node tools/extract.js $(REF) $(REF)/game.json+ python3 -I tools/pack.py $(REF) $(REF)/game.json++clean:+ $(Q) rm -rf $(BUILD_DIR) builddiff --git a/games/cookieclicker/lang/fr.txt b/games/cookieclicker/lang/fr.txtdeleted file mode 100644index 947dfb19..00000000--- a/games/cookieclicker/lang/fr.txt+++ /dev/null@@ -1,86 +0,0 @@-# Cookie Clicker in French: the English text as in the source, a tab, the translation (see tools/lang.py).-# The names come from the game's own French version; the upgrades', achievements' and news' stay English.-Cursor Curseur-Grandma Grand-mère-Farm Ferme-Mine Mine-Factory Usine-Bank Banque-Temple Temple-Wizard tower Tour de mage-Shipment Cargaison-Alchemy lab Labo d'alchimie-Portal Portail-Time machine Machine temporelle-Antimatter condenser Condenseur d'antimatière-Prism Prisme-Chancemaker Porte-bonheur-Fractal engine Moteur fractal-Javascript console Console javascript-Idleverse Veillevers-Cortex baker Cortex pâtissier-You Toi-# numbers, in the French long scale- million million- billion milliard- trillion billion- quadrillion billiard- quintillion trillion- sextillion trilliard- septillion quadrillion- octillion quadrilliard- nonillion quintillion- decillion quintilliard- undecillion sextillion- duodecillion sextilliard-The mouse and cursors are twice as efficient. La souris et les curseurs sont deux fois plus efficaces.-The mouse and cursors gain +0.1 cookies for each other building. La souris et les curseurs gagnent +0,1 cookie par autre bâtiment.-Thousand fingers x Mille doigts x-Clicking gains +1% of your CpS. Tes clics rapportent +1 % de ton CpS.-More CpS the more milk you have. Plus de CpS avec plus de lait.-Golden cookies come twice as often, stay twice as long. Les cookies dorés viennent deux fois plus souvent, restent deux fois plus longtemps.-Golden cookie effects last twice as long. Les effets des cookies dorés durent deux fois plus longtemps.-Cookie production + Production de cookies +-: twice as efficient. : deux fois plus efficace.-Bake Prépare-Make Fais-Have Possède-Click Clique-Own Possède-Purchase Achète- cookies. cookies.- cookies per second. cookies par seconde.- cookies from clicking. cookies en cliquant.- golden cookies. cookies dorés.- buildings. bâtiments.- upgrades. améliorations.-Lucky! + Quelle chance ! +-cookies cookies-per second: par seconde :-Click frenzy x777: Frénésie de clics x777 :-Frenzy x7: Frénésie x7 :-Achievement unlocked Trophée débloqué-Upgrades Bonus-Buildings Bâtiments-Stats Stats-Buy x Acheter x- achievements trophées-Each makes Chacun fait- make font-Resume Reprendre-How to play Comment jouer-Quit game Quitter le jeu-click the cookie cliquer le cookie-catch a golden cookie attraper un cookie doré-Arrows Flèches-choose, change tabs choisir, changer d'onglet-buy acheter-buy 1, 10 or 100 acheter 1, 10 ou 100-Back Retour-menu menu-Quit the game? Quitter le jeu ?-Your bakery only bakes while the game is open. Ta boulangerie ne cuit que quand le jeu est ouvert.-Play Jouer-No Non-Yes Oui-Your bakery is saved. Ta boulangerie est sauvegardée.diff --git a/games/cookieclicker/lang/zh.txt b/games/cookieclicker/lang/zh.txtdeleted file mode 100644index 0a41fe0f..00000000--- a/games/cookieclicker/lang/zh.txt+++ /dev/null@@ -1,86 +0,0 @@-# Cookie Clicker in Chinese: the English text as in the source, a tab, the translation (see tools/lang.py).-# The names come from the game's own Chinese version; the upgrades', achievements' and news' stay English.-Cursor 指针-Grandma 老太婆-Farm 农场-Mine 矿坑-Factory 工厂-Bank 银行-Temple 神庙-Wizard tower 巫师塔-Shipment 装运飞船-Alchemy lab 炼金术实验室-Portal 传送门-Time machine 时光机-Antimatter condenser 反物质聚光镜-Prism 棱镜-Chancemaker 机会制造器-Fractal engine 分形引擎-Javascript console Javascript 控制台-Idleverse 空闲宇宙-Cortex baker 脑皮层面包师-You 你-# numbers, in Chinese units- million 百万- billion 十亿- trillion 万亿- quadrillion 千万亿- quintillion 百京- sextillion 十垓- septillion 秭- octillion 千秭- nonillion 百穰- decillion 十沟- undecillion 涧- duodecillion 千涧-The mouse and cursors are twice as efficient. 鼠标点击和指针的生产率翻倍。-The mouse and cursors gain +0.1 cookies for each other building. 每拥有一座其他建筑,鼠标点击和指针 +0.1 块饼干。-Thousand fingers x 千手指 x-Clicking gains +1% of your CpS. 点击获得 +1% 的 CpS。-More CpS the more milk you have. 牛奶越多,CpS 越高。-Golden cookies come twice as often, stay twice as long. 黄金饼干出现的频率翻倍,存在时间翻倍。-Golden cookie effects last twice as long. 黄金饼干效果的持续时间翻倍。-Cookie production + 饼干产量 +-: twice as efficient. :生产率翻倍。-Bake 烘焙-Make 点击制作-Have 拥有-Click 点击-Own 拥有-Purchase 购买- cookies. 块饼干。- cookies per second. 块饼干/秒。- cookies from clicking. 块饼干。- golden cookies. 块黄金饼干。- buildings. 座建筑。- upgrades. 项升级。-Lucky! + 好运气!+-cookies 块饼干-per second: 每秒:-Click frenzy x777: 点击狂热 x777:-Frenzy x7: 狂热 x7:-Achievement unlocked 已解锁成就-Upgrades 升级-Buildings 建筑-Stats 统计-Buy x 购买 x- achievements 项成就-Each makes 每座- make 座共-Resume 继续-How to play 玩法-Quit game 退出游戏-click the cookie 点击饼干-catch a golden cookie 抓住黄金饼干-Arrows 方向键-choose, change tabs 选择、切换页面-buy 购买-buy 1, 10 or 100 一次买 1、10 或 100 个-Back 返回-menu 菜单-Quit the game? 退出游戏?-Your bakery only bakes while the game is open. 只有游戏打开时,你的面包房才会烘焙。-Play 开始-No 否-Yes 是-Your bakery is saved. 你的面包房已保存。diff --git a/games/cookieclicker/src/ascend.c b/games/cookieclicker/src/ascend.cnew file mode 100644index 00000000..9f859c4c--- /dev/null+++ b/games/cookieclicker/src/ascend.c@@ -0,0 +1,288 @@+/* Ascending, as the game shows it: the big cookie shakes, bursts into crumbs in a flash of light;+ * then the heavens, stars and nebulae, with the heavenly upgrades' tree to buy from with heavenly+ * chips (half the game's size), the permanent upgrade slots, the challenge mode, and Reincarnate. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "ui.h"++#define MAP_SCALE 0.5f+#define ASCEND_DURATION (FPS * 5)+#define ASCEND_BREAKPOINT (ASCEND_DURATION / 2)+extern bool heavenly_can_be_purchased(int u);+extern bool heavenly_ghosted(int u);+extern int permanent_slot_of(int u);+extern bool can_be_permanent(int u);++/* ------------------------------------------------------------------ the crumbling cookie */+void draw_ascend_cookie(float cx, float cy) {+ float sc = 0.37f;+ float tb = (float)(G.ascend_timer - ASCEND_BREAKPOINT) / (ASCEND_DURATION - ASCEND_BREAKPOINT);+ if (tb < 0) tb = 0;+ float t = sqrtf(tb);+ float shake = G.ascend_timer < ASCEND_BREAKPOINT ? (float)G.ascend_timer / ASCEND_BREAKPOINT : 0;+ float x = cx + (float)(rnd() * 2 - 1) * 10 * shake * sc, y = cy + (float)(rnd() * 2 - 1) * 10 * shake * sc;+ gfx_fill(0, NEWS_H, LEFT_W, SCREEN_H - NEWS_H, BLACK);+ if (tb > 0) {+ gfx_blend(BLEND_ADD);+ float s = 0.5f + powf(tb, 0.6f), s2 = 600 * s * sc;+ gfx_image_rotated(IM_HEAVEN_RING1, x, y, s2, s2, G.real_t * 0.007f, (int)((1 - sqrtf(t)) * 256));+ s = 0.5f + powf(1 - tb, 0.4f), s2 = 600 * s * sc;+ gfx_image_rotated(IM_HEAVEN_RING2, x, y, s2, s2, G.real_t * 0.005f, (int)((1 - sqrtf(t)) * 256));+ gfx_blend(BLEND_NORMAL);+ }+ static const int chunks[10] = {7, 6, 3, 2, 8, 1, 9, 5, 0, 4};+ float s = 256 * (t / 2 + 1) * sc, rot = t * -0.1f * 2 * (float)M_PI;+ for (int i = 0; i < 10; i++) {+ float d = t * (80 + ((i + 2) % 3) * 40) * sc;+ float a = -(float)((chunks[i] + 4) % 10) / 10 * 2 * (float)M_PI;+ float lx = sinf(a) * d + (float)(rnd() * 2 - 1) * 5 * shake * sc, ly = cosf(a) * d + (float)(rnd() * 2 - 1) * 5 * shake * sc;+ float px = x + lx * cosf(rot) - ly * sinf(rot), py = y + lx * sinf(rot) + ly * cosf(rot);+ gfx_image_rotated(IM_BROKEN_COOKIE0 + chunks[i], px, py, s, s, rot, (int)((1 - t) * 256));+ }+ float halo = 1 - (t / (1.f / 3) < 1.f / 3 ? t / (1.f / 3) : 1.f / 3) * 3;+ if (G.ascend_timer < ASCEND_BREAKPOINT) halo = (float)G.ascend_timer / ASCEND_BREAKPOINT;+ gfx_image_rotated(IM_BROKEN_HALO, x, y, s * 1.5f, s * 1.5f, rot, (int)(halo * 256));+ /* the light's spokes before it bursts */+ if (G.ascend_timer < ASCEND_BREAKPOINT) {+ float k = (float)G.ascend_timer / ASCEND_BREAKPOINT;+ for (int i = 0; i < 9; i++) {+ float v = k / 3 * 9 * 3 + i * 2.7f;+ if ((int)floorf(v) % 2 == 0) continue;+ float t2 = powf(fmodf(v, 1), 1.5f);+ float sw = (1 - t2 * 0.5f) * 96 * sc, sh = (0.5f + t2 * 1.5f) * 96 * sc;+ float ang = i * 2 * (float)M_PI / 9, dist = (sh / 2 + 32 * sc + (1 - t2) * 256 * sc);+ gfx_image_rotated(IM_SHINE_SPOKE, x + sinf(ang) * dist, y - cosf(ang) * dist, sw, sh, ang,+ (int)((1 - k) * (G.draw_t % 2 ? 128 : 256)));+ }+ }+ if (tb < 0.1f && tb > 0) gfx_fill_alpha(0, NEWS_H, LEFT_W, SCREEN_H - NEWS_H, WHITE, (int)((1 - tb / 0.1f) * 256));+ if (tb > 0.8f) gfx_fill_alpha(0, NEWS_H, LEFT_W, SCREEN_H - NEWS_H, BLACK, (int)((tb - 0.8f) / 0.2f * 256));+}++/* ------------------------------------------------------------------ the heavens */+static int visible[N_HEAVENLY], nvisible;+static bool ghost[N_HEAVENLY];+static void build(void) {+ nvisible = 0;+ for (int i = 0; i < N_HEAVENLY; i++) {+ int u = LIST(HEAVENLY)[i];+ bool can = heavenly_can_be_purchased(u), gh = !can && heavenly_ghosted(u);+ if (can || gh) ghost[nvisible] = gh, visible[nvisible++] = u;+ }+}+static float map_x(int u) { return (upgrade_rec(u)->posx + 24) * MAP_SCALE; }+static float map_y(int u) { return (upgrade_rec(u)->posy + 24) * MAP_SCALE; }+static int sel_u = -1;+static double chips_shown;++static void focus(void) {+ if (sel_u < 0) return;+ U.asc_tx = SCREEN_W / 2 - map_x(sel_u), U.asc_ty = (SCREEN_H + 28) / 2 - map_y(sel_u);+}++void ascend_enter(void) {+ build();+ sel_u = U_LEGACY;+ if (!bit_get(S.upgrades_bought, sel_u) && nvisible) sel_u = visible[0];+ focus();+ U.asc_x = U.asc_tx, U.asc_y = U.asc_ty;+ chips_shown = S.heavenly_chips;+ U.asc_mode = 0;+}++static void draw_link(int a, int b, int alpha) {+ float x0 = map_x(a) + U.asc_x, y0 = map_y(a) + U.asc_y, x1 = map_x(b) + U.asc_x, y1 = map_y(b) + U.asc_y;+ int minx = (int)fminf(x0, x1), miny = (int)fminf(y0, y1);+ if (!gfx_visible(minx - 2, miny - 2, (int)fabsf(x1 - x0) + 4, (int)fabsf(y1 - y0) + 4)) return;+ /* the pulse along the link */+ gfx_line(x0, y0, x1, y1, HEX(0xbfe9ff), alpha / 2);+ float k = fmodf(G.real_t * 0.03f, 1);+ gfx_disc(x0 + (x1 - x0) * k, y0 + (y1 - y0) * k, 1.5f, WHITE, alpha);+}++static void draw_heavens(void) {+ gfx_fill(0, 0, SCREEN_W, SCREEN_H, BLACK);+ float s = 1 + cosf(G.real_t * 0.0027f) * 0.05f;+ gfx_pattern(IM_STARS, 0, 0, SCREEN_W, SCREEN_H, 384 * s, 384 * s, SCREEN_W / 2 + U.asc_x * 0.25f * s,+ SCREEN_H / 2 + U.asc_y * 0.25f * s, 128);+ if (S.prefs.fancy) {+ s = 2 * (1 + sinf(G.real_t * 0.002f) * 0.07f);+ gfx_pattern(IM_STARS, 0, 0, SCREEN_W, SCREEN_H, 384 * s, 384 * s, SCREEN_W / 2 + U.asc_x * 0.25f * s,+ SCREEN_H / 2 + U.asc_y * 0.25f * s, (int)(128 * (0.5f + sinf(G.real_t * 0.02f) * 0.3f)));+ gfx_blend(BLEND_ADD);+ float cx = U.asc_x, cy = U.asc_y;+ float r1 = (600 + 150 * sinf(G.real_t * 0.007f)) * MAP_SCALE, r2 = (600 + 150 * sinf(G.real_t * 0.0037f)) * MAP_SCALE;+ gfx_image_rotated(IM_HEAVEN_RING1, cx, cy, r1, r1, G.real_t * 0.001f, 128);+ gfx_image_rotated(IM_HEAVEN_RING2, cx, cy, r2, r2, -G.real_t * 0.0007f, 128);+ gfx_blend(BLEND_NORMAL);+ }+ /* the links, then the upgrades */+ for (int i = 0; i < nvisible; i++) {+ const UpgradeRec *r = upgrade_rec(visible[i]);+ for (int k = 0; k < 6 && r->parents[k] != NONE; k++) draw_link(r->parents[k], visible[i], ghost[i] ? 26 : 128);+ }+ for (int i = 0; i < nvisible; i++) {+ int u = visible[i];+ int x = (int)(map_x(u) + U.asc_x), y = (int)(map_y(u) + U.asc_y);+ if (!gfx_visible(x - 20, y - 20, 40, 40)) continue;+ if (ghost[i]) {+ gfx_icon(upgrade_rec(u)->icon, x - 12, y - 12, 51);+ continue;+ }+ bool bought = bit_get(S.upgrades_bought, u);+ int frame = u == sel_u ? 1 : bought ? 0 : 2;+ gfx_image(IM_ASCEND_SLOT0 + frame, x - 20, y - 20, 256);+ gfx_icon(upgrade_rec(u)->icon, x - 12, y - 12 - (u == sel_u), bought ? 256 : 205);+ int slot = permanent_slot_of(u);+ if (slot >= 0 && bought && S.permanent[slot]) gfx_icon_scaled(upgrade_rec(S.permanent[slot] - 1)->icon, x + 2, y + 2, 12, 256);+ }+ gfx_image_scaled(IM_BORDER_SOFT, 0, 0, SCREEN_W, SCREEN_H, 256);+ /* the top: prestige, the chips, Reincarnate */+ char a[48], t[64];+ beautify(S.prestige, 0, a);+ gfx_text_outline(F_SMALL, 6, 11, "Prestige level:", WHITE, 256);+ gfx_text_outline(F_NAME, 6, 24, a, WHITE, 256);+ beautify(round(chips_shown), 0, a);+ gfx_text_outline_center(F_SMALL, SCREEN_W - 50, 11, "Heavenly chips:", WHITE, 256);+ gfx_image(IM_HEAVENLY_MONEY, SCREEN_W - 50 - gfx_text_width(F_NAME, a) / 2 - 12, 15, 256);+ gfx_text_outline_center(F_NAME, SCREEN_W - 50 + 6, 24, a, HEX(0x99dfff), 256);+ gfx_round_rect(SCREEN_W / 2 - 46, 3, 92, 18, 9, BLACK, 128);+ gfx_text_outline_center(F_NAME, SCREEN_W / 2, 16, "Reincarnate", WHITE, 256);+ if (S.prestige > 0) {+ snprintf(t, sizeof t, "Challenge mode: %s", U.asc_mode == 1 ? "Born again" : "None");+ gfx_text_outline_center(F_SMALL, SCREEN_W / 2, 32, t, U.asc_mode ? HEX(0xffcc66) : RGB(200, 200, 200), 256);+ }+ gfx_text_outline_center(F_SMALL, SCREEN_W / 2, SCREEN_H - 5,+ S.prestige > 0 ? "EXE buy Back reincarnate shift challenge mode" : "EXE buy Back reincarnate",+ RGB(170, 170, 170), 256);+ /* the tooltip of the upgrade chosen */+ if (sel_u >= 0) {+ int w = 200, pad = 5;+ int h = crate_tip(0, sel_u, CTX_ASCEND, 0, 0, w - 2 * pad, false) + 2 * pad;+ int slot = permanent_slot_of(sel_u);+ char extra[96] = "";+ if (slot >= 0 && bit_get(S.upgrades_bought, sel_u)) {+ snprintf(extra, sizeof extra, "Press EXE to choose an upgrade for this slot (%s).",+ S.permanent[slot] ? res_text(upgrade_rec(S.permanent[slot] - 1)->name) : "empty");+ h += gfx_para(&PS_SMALL, 0, 0, w - 2 * pad, extra, false) + 4;+ }+ int x = (int)(map_x(sel_u) + U.asc_x), y = (int)(map_y(sel_u) + U.asc_y);+ int ty = y + 22;+ if (ty + h > SCREEN_H - 12) ty = y - 22 - h;+ if (ty < 36) ty = 36;+ int tx = x - w / 2;+ if (tx < 4) tx = 4;+ if (tx + w > SCREEN_W - 4) tx = SCREEN_W - 4 - w;+ if (gfx_visible(tx, ty, w, h)) {+ draw_frame_box(tx, ty, w, h);+ int hh = crate_tip(0, sel_u, CTX_ASCEND, tx + pad, ty + pad, w - 2 * pad, true);+ if (extra[0]) gfx_para(&PS_SMALL, tx + pad, ty + pad + hh + 2, w - 2 * pad, extra, true);+ }+ }+}++/* ------------------------------------------------------------------ the permanent upgrade slots */+static uint16_t cands[N_UPGRADES];+static int ncands;+static void cands_build(void) {+ ncands = 0;+ for (int u = 0; u < N_UPGRADES; u++)+ if (can_be_permanent(u)) cands[ncands++] = (uint16_t)u;+}+#define PCOLS 10+static void draw_permanent(void) {+ cands_build();+ int w = 300, x = (SCREEN_W - w) / 2, top = 30;+ gfx_fill_alpha(0, 0, SCREEN_W, SCREEN_H, BLACK, 140);+ draw_frame_box(x, top, w, SCREEN_H - top - 8);+ int slot = U.perm_slot;+ char t[96];+ snprintf(t, sizeof t, "Permanent upgrade slot %s", (const char *[]){"I", "II", "III", "IV", "V"}[slot]);+ gfx_text_outline_center(F_TITLE, SCREEN_W / 2, top + 16, t, WHITE, 256);+ ParaStyle st = PS_SMALL;+ st.align = 1;+ int y = top + 20;+ y += gfx_para(&st, x + 8, y, w - 16,+ "Choose an upgrade you bought in your last run: it will be yours from the start of every run.", true);+ if (!ncands) {+ gfx_para(&st, x + 8, y + 20, w - 16, "You don't have any upgrades that can be made permanent.", true);+ return;+ }+ int gx = x + (w - PCOLS * CRATE) / 2, rows_shown = (SCREEN_H - 8 - y - 60) / CRATE;+ int row_sel = U.perm_sel / PCOLS, first = row_sel - rows_shown + 1 > 0 ? row_sel - rows_shown + 1 : 0;+ for (int i = first * PCOLS; i < ncands && i < (first + rows_shown) * PCOLS; i++) {+ int cx = gx + (i % PCOLS) * CRATE, cy = y + 4 + (i / PCOLS - first) * CRATE;+ bool cur = S.permanent[slot] == cands[i] + 1;+ draw_crate(upgrade_rec(cands[i])->icon, cx, cy, U.perm_sel == i ? 1 : cur ? 0 : 0, false);+ if (cur) gfx_rect(cx + 1, cy + 1, CRATE - 2, CRATE - 2, HEX(0xffcc66), 256);+ }+ int sel = U.perm_sel < ncands ? cands[U.perm_sel] : -1;+ if (sel >= 0) {+ int ty = y + 8 + rows_shown * CRATE;+ tip_line(x + 8, ty, w - 16);+ gfx_text_outline_center(F_NAME, SCREEN_W / 2, ty + 14, res_text(upgrade_rec(sel)->name), WHITE, 256);+ gfx_text_center(F_SMALL, SCREEN_W / 2, ty + 28, "EXE choose Back cancel", RGB(170, 170, 170), 256);+ }+}+static void permanent_keys(uint32_t p) {+ cands_build();+ if (p & K_BACK) {+ U.overlay = OV_NONE;+ return;+ }+ if (!ncands) return;+ if (p & K_LEFT && U.perm_sel > 0) U.perm_sel--;+ if (p & K_RIGHT && U.perm_sel < ncands - 1) U.perm_sel++;+ if (p & K_UP && U.perm_sel >= PCOLS) U.perm_sel -= PCOLS;+ if (p & K_DOWN && U.perm_sel + PCOLS < ncands) U.perm_sel += PCOLS;+ if (p & (K_OK | K_EXE)) {+ S.permanent[U.perm_slot] = (uint16_t)(cands[U.perm_sel] + 1);+ U.overlay = OV_NONE;+ }+}++/* ------------------------------------------------------------------ the frames and keys */+void draw_ascend(void) {+ draw_heavens();+ if (U.overlay == OV_PERMANENT) draw_permanent();+}++void ascend_tick(void) {+ U.asc_x += (U.asc_tx - U.asc_x) * 0.5f;+ U.asc_y += (U.asc_ty - U.asc_y) * 0.5f;+ chips_shown += (S.heavenly_chips - chips_shown) * 0.4;+}++void ascend_keys(uint32_t p) {+ if (U.overlay == OV_PERMANENT) {+ permanent_keys(p);+ return;+ }+ build();+ if (sel_u < 0 && nvisible) sel_u = visible[0];+ if (p & (K_LEFT | K_RIGHT | K_UP | K_DOWN)) {+ float dx = p & K_LEFT ? -1 : p & K_RIGHT ? 1 : 0, dy = p & K_UP ? -1 : p & K_DOWN ? 1 : 0;+ float x0 = map_x(sel_u), y0 = map_y(sel_u), best = 1e9f;+ int found = -1;+ for (int i = 0; i < nvisible; i++) {+ int u = visible[i];+ if (u == sel_u || ghost[i]) continue;+ float vx = map_x(u) - x0, vy = map_y(u) - y0, d = sqrtf(vx * vx + vy * vy);+ float along = (vx * dx + vy * dy) / d;+ if (along < 0.5f) continue; /* (within 60 degrees of the arrow) */+ float score = d * (2 - along);+ if (score < best) best = score, found = u;+ }+ if (found >= 0) sel_u = found, focus();+ }+ if (p & K_SHIFT && S.prestige > 0) U.asc_mode ^= 1;+ if (p & (K_EXE | K_OK) && sel_u >= 0) {+ if (!bit_get(S.upgrades_bought, sel_u)) {+ if (heavenly_can_be_purchased(sel_u) && upgrade_buy(sel_u, true)) build();+ } else if (permanent_slot_of(sel_u) >= 0) {+ U.perm_slot = permanent_slot_of(sel_u), U.perm_sel = 0, U.overlay = OV_PERMANENT;+ }+ }+ if (p & K_BACK) prompt_open(PROMPT_REINCARNATE, U.asc_mode);+}diff --git a/games/cookieclicker/src/data.S b/games/cookieclicker/src/data.Snew file mode 100644index 00000000..bdea871f--- /dev/null+++ b/games/cookieclicker/src/data.S@@ -0,0 +1,19 @@+/* data.bin (tools/pack.py) in the app's read-only data */+#ifdef __APPLE__+ .const_data+ .p2align 3+ .globl _cc_data+_cc_data:+ .incbin DATA_BIN+ .p2align 2+#else+ .section .rodata.cc_data,"a"+ .balign 8+ .global cc_data+cc_data:+ .incbin DATA_BIN+ .balign 4+#endif+#ifdef __ELF__+ .section .note.GNU-stack,"",%progbits+#endifdiff --git a/games/cookieclicker/src/data.bin b/games/cookieclicker/src/data.binnew file mode 100644index 00000000..87ffbfa6Binary files /dev/null and b/games/cookieclicker/src/data.bin differdiff --git a/games/cookieclicker/src/data.h b/games/cookieclicker/src/data.hindex 979eb1b9..875699a4 100644--- a/games/cookieclicker/src/data.h+++ b/games/cookieclicker/src/data.h@@ -1,118 +1,1884 @@-/* Made by tools/data.py: Cookie Clicker's names, news and the store's pictures. */-#define TIER_N 3-#define ACH_TIERS 1-/* the upgrades, in the order of the save */-#define N_CURSOR 8-#define U_MOUSE N_CURSOR-#define N_MOUSE 6-#define U_KITTEN (U_MOUSE + N_MOUSE)-#define N_KITTEN 3-#define U_GOLD (U_KITTEN + N_KITTEN)-#define U_COOKIE (U_GOLD + 3)-#define N_COOKIE 8-#define U_TIER (U_COOKIE + N_COOKIE)-#define N_UP (U_TIER + 19 * TIER_N)-/* the achievements, in the order of the save */-#define N_BANK 13-#define A_CPS N_BANK-#define N_CPS 10-#define A_CLICK (A_CPS + N_CPS)-#define N_CLICK 6-#define A_BUILD (A_CLICK + N_CLICK) /* the cursor's, then ACH_TIERS for each other building */-#define N_CURSOR_ACH 3-#define A_GOLDEN (A_BUILD + N_CURSOR_ACH + 19 * ACH_TIERS)-#define N_GOLDEN 4-#define A_OWNED (A_GOLDEN + N_GOLDEN)-#define A_UPGRADED (A_OWNED + 2)-#define A_MISC (A_UPGRADED + 2)-#define N_ACH (A_MISC + 0)-/* the texts: the upgrades' names, the achievements', the news, the other achievements'- descriptions, the milks; then the pictures, 18 bytes each (12 x 12 bits, the first lowest) */-#define X_ACH N_UP-#define X_NEWS (X_ACH + N_ACH)-#define N_LORE 9-#define X_MDESC (X_NEWS + N_LORE)-#define X_MILK (X_MDESC + 0)-#define N_MILK 3-#define N_TEXT 156-#define ICONS_AT 2820-#define TEXT_SIZE 3216-static const uint8_t cookie_up[N_COOKIE] = {33, 49, 34, 82, 67, 83, 67, 84};-enum { IC_CURSOR, IC_GRANDMA, IC_FARM, IC_MINE, IC_FACTORY, IC_BANK, IC_TEMPLE, IC_WIZARD, IC_SHIPMENT, IC_ALCHEMY, IC_PORTAL, IC_TIME, IC_ANTIMATTER, IC_PRISM, IC_CHANCE, IC_FRACTAL, IC_CONSOLE, IC_IDLEVERSE, IC_CORTEX, IC_YOU, IC_MOUSE, IC_KITTEN };-static const uint8_t text_z[1783] = {- 108, 86, 135, 150, 228, 58, 10, 245, 167, 176, 57, 231, 124, 242, 228, 151, 95, 239, 235, 153, 13, 39, 99, 9,- 219, 156, 146, 192, 15, 161, 174, 241, 126, 253, 154, 83, 174, 234, 201, 157, 64, 8, 9, 184, 247, 170, 190, 35,- 150, 73, 45, 81, 6, 150, 76, 111, 97, 98, 153, 201, 134, 103, 104, 43, 22, 240, 46, 66, 5, 86, 163, 7,- 18, 103, 21, 72, 70, 88, 135, 39, 117, 228, 61, 218, 77, 123, 27, 94, 47, 251, 79, 148, 124, 236, 109, 195,- 215, 92, 74, 196, 94, 237, 167, 31, 216, 175, 237, 3, 199, 63, 59, 230, 15, 125, 119, 5, 155, 115, 130, 186,- 39, 167, 225, 115, 83, 57, 254, 124, 205, 142, 194, 189, 30, 230, 147, 140, 21, 197, 31, 29, 111, 68, 71, 71,- 126, 39, 228, 69, 233, 249, 209, 250, 146, 221, 73, 96, 161, 178, 198, 57, 135, 121, 86, 59, 189, 99, 146, 204,- 44, 20, 142, 175, 122, 58, 109, 144, 113, 27, 238, 201, 72, 50, 175, 236, 219, 240, 138, 28, 74, 172, 196, 61,- 89, 32, 169, 158, 152, 218, 112, 223, 103, 180, 155, 245, 45, 122, 37, 44, 96, 200, 237, 157, 160, 59, 66, 233,- 14, 99, 119, 167, 199, 224, 103, 154, 52, 220, 87, 251, 223, 11, 59, 65, 90, 118, 119, 65, 167, 155, 255, 107,- 76, 152, 177, 50, 194, 187, 209, 207, 181, 143, 133, 126, 147, 22, 94, 111, 190, 151, 106, 103, 180, 220, 96, 50,- 173, 48, 27, 74, 174, 56, 220, 59, 81, 249, 205, 26, 57, 51, 152, 150, 194, 50, 195, 202, 18, 165, 142, 198,- 9, 195, 159, 73, 188, 91, 220, 106, 33, 92, 97, 209, 72, 71, 230, 92, 248, 127, 1, 143, 56, 129, 192, 141,- 110, 53, 207, 184, 95, 141, 230, 203, 32, 135, 55, 197, 237, 248, 243, 222, 187, 101, 166, 40, 84, 30, 104, 83,- 131, 145, 138, 71, 102, 46, 25, 10, 142, 106, 195, 253, 153, 208, 219, 162, 235, 240, 26, 75, 33, 3, 167, 248,- 181, 231, 78, 220, 154, 218, 111, 140, 26, 55, 71, 241, 0, 96, 230, 253, 87, 20, 54, 60, 73, 156, 127, 179,- 154, 234, 4, 15, 216, 35, 235, 43, 45, 153, 4, 56, 107, 217, 119, 99, 50, 158, 56, 69, 127, 168, 112, 98,- 237, 13, 198, 66, 173, 177, 204, 195, 157, 178, 120, 92, 108, 65, 223, 65, 74, 104, 185, 132, 57, 210, 37, 183,- 36, 38, 113, 152, 141, 171, 114, 244, 226, 95, 40, 92, 10, 130, 208, 216, 11, 210, 240, 111, 181, 186, 104, 137,- 214, 24, 125, 223, 35, 120, 42, 27, 217, 190, 213, 185, 170, 108, 195, 139, 214, 72, 18, 129, 78, 144, 181, 207,- 203, 14, 253, 254, 206, 76, 111, 103, 56, 142, 133, 124, 248, 92, 26, 10, 129, 162, 199, 80, 110, 152, 188, 215,- 94, 96, 84, 201, 195, 203, 210, 223, 66, 194, 21, 19, 187, 6, 147, 184, 18, 172, 104, 152, 245, 45, 24, 53,- 45, 15, 100, 65, 39, 241, 94, 33, 240, 36, 217, 122, 61, 70, 52, 106, 83, 217, 211, 185, 69, 118, 95, 72,- 109, 27, 190, 66, 155, 9, 42, 38, 180, 160, 119, 224, 33, 147, 237, 0, 175, 176, 106, 225, 182, 12, 255, 240,- 37, 252, 186, 143, 253, 6, 198, 194, 243, 226, 195, 127, 181, 219, 133, 6, 7, 230, 134, 31, 62, 41, 5, 158,- 146, 55, 120, 98, 4, 223, 78, 211, 15, 161, 226, 204, 105, 95, 103, 25, 254, 205, 34, 113, 116, 209, 64, 254,- 6, 206, 233, 68, 190, 195, 198, 113, 196, 19, 217, 5, 222, 146, 169, 140, 166, 103, 129, 22, 215, 222, 155, 139,- 201, 149, 115, 40, 13, 193, 23, 248, 128, 247, 201, 120, 245, 168, 175, 105, 33, 152, 212, 32, 247, 90, 99, 251,- 95, 255, 60, 178, 3, 154, 225, 22, 149, 98, 58, 129, 62, 144, 77, 69, 207, 145, 154, 39, 106, 14, 153, 154,- 179, 108, 145, 15, 106, 47, 206, 123, 68, 35, 96, 1, 12, 82, 181, 133, 74, 25, 246, 74, 126, 147, 84, 98,- 137, 85, 134, 59, 99, 73, 188, 22, 202, 32, 212, 13, 11, 180, 101, 207, 94, 130, 230, 35, 109, 195, 19, 104,- 171, 177, 236, 142, 152, 54, 155, 97, 232, 37, 150, 80, 139, 103, 69, 163, 110, 120, 8, 160, 189, 16, 178, 121,- 103, 81, 142, 163, 44, 198, 31, 23, 237, 226, 144, 131, 195, 193, 124, 60, 17, 132, 160, 70, 83, 246, 91, 159,- 98, 111, 211, 74, 7, 136, 238, 53, 86, 130, 189, 49, 5, 16, 61, 239, 192, 160, 60, 151, 136, 139, 21, 219,- 175, 51, 77, 37, 16, 121, 216, 129, 213, 146, 127, 51, 97, 104, 224, 213, 247, 76, 91, 229, 116, 181, 94, 97,- 193, 228, 143, 246, 27, 225, 168, 29, 203, 213, 17, 96, 11, 238, 92, 237, 207, 101, 98, 97, 167, 155, 93, 171,- 154, 63, 198, 63, 87, 249, 153, 67, 115, 93, 161, 18, 196, 45, 159, 97, 235, 151, 245, 224, 223, 103, 104, 57,- 169, 209, 97, 135, 48, 97, 222, 192, 177, 249, 6, 205, 141, 176, 94, 133, 166, 170, 52, 39, 219, 123, 209, 26,- 172, 166, 185, 167, 71, 21, 122, 80, 115, 122, 123, 181, 214, 94, 26, 222, 214, 190, 239, 24, 214, 183, 11, 44,- 180, 253, 26, 54, 237, 63, 51, 130, 230, 92, 202, 238, 49, 26, 190, 34, 255, 89, 3, 161, 135, 32, 62, 70,- 223, 103, 100, 217, 39, 182, 67, 51, 110, 194, 233, 242, 55, 250, 82, 244, 240, 107, 217, 234, 202, 169, 29, 150,- 97, 197, 35, 168, 213, 91, 252, 76, 57, 95, 55, 220, 212, 185, 132, 241, 117, 60, 67, 112, 94, 136, 202, 240,- 234, 34, 202, 63, 107, 55, 209, 126, 26, 35, 246, 96, 39, 76, 104, 53, 56, 6, 39, 209, 51, 132, 231, 162,- 168, 119, 22, 13, 184, 60, 199, 11, 114, 96, 147, 220, 55, 88, 73, 100, 187, 144, 210, 67, 24, 92, 161, 45,- 198, 66, 187, 184, 157, 217, 211, 66, 121, 120, 241, 118, 165, 204, 177, 119, 215, 34, 148, 86, 187, 163, 135, 245,- 100, 191, 81, 144, 73, 232, 28, 194, 83, 242, 69, 92, 206, 104, 107, 232, 25, 143, 232, 49, 129, 175, 84, 8,- 214, 69, 93, 37, 158, 198, 64, 161, 118, 31, 238, 169, 76, 193, 22, 71, 22, 218, 117, 234, 15, 127, 12, 114,- 109, 63, 43, 229, 232, 109, 148, 176, 159, 128, 14, 11, 59, 252, 140, 234, 240, 121, 52, 126, 228, 25, 70, 67,- 150, 184, 241, 142, 245, 13, 130, 247, 169, 168, 208, 33, 229, 71, 99, 142, 119, 248, 48, 158, 4, 62, 244, 68,- 65, 181, 208, 159, 120, 234, 188, 71, 161, 157, 75, 14, 5, 182, 180, 176, 83, 242, 157, 110, 11, 74, 10, 87,- 159, 43, 73, 212, 16, 45, 157, 136, 10, 20, 222, 83, 212, 11, 191, 142, 254, 255, 22, 158, 246, 160, 212, 168,- 121, 131, 51, 138, 183, 104, 35, 161, 7, 118, 236, 22, 117, 233, 242, 196, 214, 130, 97, 158, 22, 152, 149, 34,- 20, 98, 76, 110, 216, 150, 223, 66, 200, 139, 16, 207, 203, 168, 182, 168, 102, 48, 76, 73, 85, 96, 68, 163,- 178, 129, 107, 79, 11, 53, 96, 191, 230, 195, 202, 187, 31, 103, 163, 35, 153, 109, 23, 226, 235, 244, 169, 243,- 15, 11, 208, 8, 86, 93, 123, 65, 131, 104, 229, 7, 231, 126, 34, 218, 177, 196, 232, 112, 212, 238, 16, 250,- 89, 185, 80, 44, 105, 151, 15, 227, 71, 139, 254, 96, 41, 16, 137, 71, 221, 110, 117, 110, 104, 159, 72, 30,- 240, 241, 5, 48, 100, 62, 46, 94, 85, 104, 251, 237, 112, 71, 186, 22, 218, 3, 43, 93, 62, 144, 60, 144,- 109, 129, 113, 192, 51, 110, 145, 114, 38, 7, 132, 96, 221, 39, 10, 126, 29, 116, 133, 72, 31, 72, 170, 189,- 81, 175, 13, 50, 229, 227, 19, 139, 235, 7, 27, 46, 31, 204, 42, 151, 211, 227, 187, 117, 49, 191, 195, 182,- 142, 100, 255, 239, 121, 24, 96, 228, 10, 162, 111, 141, 218, 238, 122, 227, 218, 90, 69, 141, 182, 177, 179, 181,- 221, 160, 158, 249, 85, 156, 218, 70, 172, 13, 234, 179, 125, 241, 217, 246, 28, 87, 127, 231, 221, 252, 61, 60,- 27, 98, 123, 202, 85, 109, 2, 3, 3, 11, 211, 16, 182, 192, 18, 214, 108, 6, 61, 163, 22, 126, 234, 240,- 187, 19, 39, 213, 206, 160, 246, 158, 229, 67, 27, 57, 76, 151, 203, 142, 160, 124, 127, 249, 225, 172, 29, 81,- 149, 254, 48, 67, 185, 141, 28, 91, 251, 232, 48, 232, 103, 41, 165, 236, 59, 218, 246, 98, 230, 64, 29, 71,- 1, 135, 197, 156, 8, 194, 225, 186, 95, 23, 234, 126, 205, 3, 37, 2, 11, 158, 80, 75, 52, 219, 243, 161,- 237, 134, 72, 225, 2, 200, 130, 249, 205, 170, 21, 97, 201, 83, 157, 123, 73, 142, 32, 55, 128, 168, 97, 116,- 213, 27, 73, 41, 227, 191, 155, 158, 26, 77, 44, 53, 255, 9, 93, 168, 253, 22, 74, 214, 101, 38, 251, 72,- 52, 123, 211, 201, 29, 197, 166, 183, 79, 4, 61, 63, 127, 114, 238, 125, 11, 110, 244, 234, 11, 60, 81, 213,- 2, 81, 118, 252, 91, 72, 12, 23, 167, 62, 251, 113, 232, 252, 181, 161, 72, 197, 14, 179, 235, 224, 121, 141,- 50, 132, 193, 130, 55, 210, 170, 185, 185, 155, 244, 39, 15, 35, 226, 135, 182, 91, 188, 208, 243, 25, 217, 2,- 140, 137, 143, 26, 11, 119, 77, 93, 56, 55, 119, 247, 179, 118, 162, 185, 221, 108, 138, 33, 90, 168, 238, 13,- 93, 244, 134, 234, 86, 166, 169, 162, 8, 0, 44, 203, 195, 187, 8, 46, 0, 28, 34, 162, 157, 1, 84, 103,- 121, 126, 69, 6, 18, 137, 9, 94, 184, 254, 48, 232, 149, 26, 241, 166, 100, 97, 0, 98, 44, 10, 88, 32,- 34, 203, 143, 251, 221, 114, 192, 170, 245, 91, 181, 247, 22, 50, 0, 213, 174, 44, 3, 71, 244, 84, 142, 202,- 248, 121, 136, 200, 26, 152, 4,-};+/* Written by tools/pack.py: what data.bin holds. */+#ifndef CC_DATA_H+#define CC_DATA_H++#define MILK_TILE 178+#define ICON_COLS 36+#define ICON_ROWS 37+#define OFF_ICONS 1397016+#define F_TITLE 0+#define F_NAME 1+#define F_NAME_SMALL 2+#define F_OWNED 3+#define F_BODY 4+#define F_BOLD 5+#define F_ITALIC 6+#define F_SMALL 7+#define F_KAVOON 8+#define OFF_FONTS 1447600+#define OFF_BUILDINGS 1447640+#define N_BUILDINGS 20+#define B_CURSOR 0+#define B_GRANDMA 1+#define B_FARM 2+#define B_MINE 3+#define B_FACTORY 4+#define B_BANK 5+#define B_TEMPLE 6+#define B_WIZARD_TOWER 7+#define B_SHIPMENT 8+#define B_ALCHEMY_LAB 9+#define B_PORTAL 10+#define B_TIME_MACHINE 11+#define B_ANTIMATTER_CONDENSER 12+#define B_PRISM 13+#define B_CHANCEMAKER 14+#define B_FRACTAL_ENGINE 15+#define B_JAVASCRIPT_CONSOLE 16+#define B_IDLEVERSE 17+#define B_CORTEX_BAKER 18+#define B_YOU 19+#define OFF_TIERS 1448760+#define N_TIERS 18+#define TIER__1 0+#define TIER__2 1+#define TIER__3 2+#define TIER__4 3+#define TIER__5 4+#define TIER__6 5+#define TIER__7 6+#define TIER__8 7+#define TIER__9 8+#define TIER__10 9+#define TIER__11 10+#define TIER__12 11+#define TIER__13 12+#define TIER__14 13+#define TIER__15 14+#define TIER_SYNERGY1 15+#define TIER_SYNERGY2 16+#define TIER_FORTUNE 17+#define OFF_UPGRADES 1449192+#define N_UPGRADES 876+#define U_REINFORCED_INDEX_FINGER 0+#define U_CARPAL_TUNNEL_PREVENTION_CREAM 1+#define U_AMBIDEXTROUS 2+#define U_THOUSAND_FINGERS 3+#define U_MILLION_FINGERS 4+#define U_BILLION_FINGERS 5+#define U_TRILLION_FINGERS 6+#define U_FORWARDS_FROM_GRANDMA 7+#define U_STEEL_PLATED_ROLLING_PINS 8+#define U_LUBRICATED_DENTURES 9+#define U_CHEAP_HOES 10+#define U_FERTILIZER 11+#define U_COOKIE_TREES 12+#define U_STURDIER_CONVEYOR_BELTS 13+#define U_CHILD_LABOR 14+#define U_SWEATSHOP 15+#define U_SUGAR_GAS 16+#define U_MEGADRILL 17+#define U_ULTRADRILL 18+#define U_VANILLA_NEBULAE 19+#define U_WORMHOLES 20+#define U_FREQUENT_FLYER 21+#define U_ANTIMONY 22+#define U_ESSENCE_OF_DOUGH 23+#define U_TRUE_CHOCOLATE 24+#define U_ANCIENT_TABLET 25+#define U_INSANE_OATLING_WORKERS 26+#define U_SOUL_BOND 27+#define U_FLUX_CAPACITORS 28+#define U_TIME_PARADOX_RESOLVER 29+#define U_QUANTUM_CONUNDRUM 30+#define U_KITTEN_HELPERS 31+#define U_KITTEN_WORKERS 32+#define U_PLAIN_COOKIES 33+#define U_SUGAR_COOKIES 34+#define U_OATMEAL_RAISIN_COOKIES 35+#define U_PEANUT_BUTTER_COOKIES 36+#define U_COCONUT_COOKIES 37+#define U_WHITE_CHOCOLATE_COOKIES 38+#define U_MACADAMIA_NUT_COOKIES 39+#define U_DOUBLE_CHIP_COOKIES 40+#define U_WHITE_CHOCOLATE_MACADAMIA_NUT_COOKIES 41+#define U_ALL_CHOCOLATE_COOKIES 42+#define U_QUADRILLION_FINGERS 43+#define U_PRUNE_JUICE 44+#define U_GENETICALLY_MODIFIED_COOKIES 45+#define U_RADIUM_REACTORS 46+#define U_ULTIMADRILL 47+#define U_WARP_DRIVE 48+#define U_AMBROSIA 49+#define U_SANITY_DANCE 50+#define U_CAUSALITY_ENFORCER 51+#define U_LUCKY_DAY 52+#define U_SERENDIPITY 53+#define U_KITTEN_ENGINEERS 54+#define U_DARK_CHOCOLATE_COATED_COOKIES 55+#define U_WHITE_CHOCOLATE_COATED_COOKIES 56+#define U_FARMER_GRANDMAS 57+#define U_MINER_GRANDMAS 58+#define U_WORKER_GRANDMAS 59+#define U_COSMIC_GRANDMAS 60+#define U_TRANSMUTED_GRANDMAS 61+#define U_ALTERED_GRANDMAS 62+#define U_GRANDMAS_GRANDMAS 63+#define U_BINGO_CENTER_RESEARCH_FACILITY 64+#define U_SPECIALIZED_CHOCOLATE_CHIPS 65+#define U_DESIGNER_COCOA_BEANS 66+#define U_RITUAL_ROLLING_PINS 67+#define U_UNDERWORLD_OVENS 68+#define U_ONE_MIND 69+#define U_EXOTIC_NUTS 70+#define U_COMMUNAL_BRAINSWEEP 71+#define U_ARCANE_SUGAR 72+#define U_ELDER_PACT 73+#define U_ELDER_PLEDGE 74+#define U_PLASTIC_MOUSE 75+#define U_IRON_MOUSE 76+#define U_TITANIUM_MOUSE 77+#define U_ADAMANTIUM_MOUSE 78+#define U_ULTRASCIENCE 79+#define U_ECLIPSE_COOKIES 80+#define U_ZEBRA_COOKIES 81+#define U_QUINTILLION_FINGERS 82+#define U_GOLD_HOARD 83+#define U_ELDER_COVENANT 84+#define U_REVOKE_ELDER_COVENANT 85+#define U_GET_LUCKY 86+#define U_SACRIFICIAL_ROLLING_PINS 87+#define U_SNICKERDOODLES 88+#define U_STROOPWAFELS 89+#define U_MACAROONS 90+#define U_NEUROMANCY 91+#define U_EMPIRE_BISCUITS 92+#define U_BRITISH_TEA_BISCUITS 93+#define U_CHOCOLATE_BRITISH_TEA_BISCUITS 94+#define U_ROUND_BRITISH_TEA_BISCUITS 95+#define U_ROUND_CHOCOLATE_BRITISH_TEA_BISCUITS 96+#define U_ROUND_BRITISH_TEA_BISCUITS_WITH_HEART_MOTIF 97+#define U_ROUND_CHOCOLATE_BRITISH_TEA_BISCUITS_WITH_HEART_MOTIF 98+#define U_SUGAR_BOSONS 99+#define U_STRING_THEORY 100+#define U_LARGE_MACARON_COLLIDER 101+#define U_BIG_BANG_BAKE 102+#define U_ANTIGRANDMAS 103+#define U_MADELEINES 104+#define U_PALMIERS 105+#define U_PALETS 106+#define U_SABLANDEACUTE_S 107+#define U_KITTEN_OVERSEERS 108+#define U_SEXTILLION_FINGERS 109+#define U_DOUBLE_THICK_GLASSES 110+#define U_GINGERBREAD_SCARECROWS 111+#define U_RECOMBOBULATORS 112+#define U_H_BOMB_MINING 113+#define U_CHOCOLATE_MONOLITHS 114+#define U_AQUA_CRUSTULAE 115+#define U_BRANE_TRANSPLANT 116+#define U_YESTERMORROW_COMPARATORS 117+#define U_REVERSE_CYCLOTRONS 118+#define U_UNOBTAINIUM_MOUSE 119+#define U_CARAMOAS 120+#define U_SAGALONGS 121+#define U_SHORTFOILS 122+#define U_WIN_MINTS 123+#define U_PERFECT_IDLING 124+#define U_FIG_GLUTTONS 125+#define U_LOREOLS 126+#define U_JAFFA_CAKES 127+#define U_GREASES_CUPS 128+#define U_HEAVENLY_CHIP_SECRET 129+#define U_HEAVENLY_COOKIE_STAND 130+#define U_HEAVENLY_BAKERY 131+#define U_HEAVENLY_CONFECTIONERY 132+#define U_HEAVENLY_KEY 133+#define U_SKULL_COOKIES 134+#define U_GHOST_COOKIES 135+#define U_BAT_COOKIES 136+#define U_SLIME_COOKIES 137+#define U_PUMPKIN_COOKIES 138+#define U_EYEBALL_COOKIES 139+#define U_SPIDER_COOKIES 140+#define U_PERSISTENT_MEMORY 141+#define U_WRINKLER_DOORMAT 142+#define U_CHRISTMAS_TREE_BISCUITS 143+#define U_SNOWFLAKE_BISCUITS 144+#define U_SNOWMAN_BISCUITS 145+#define U_HOLLY_BISCUITS 146+#define U_CANDY_CANE_BISCUITS 147+#define U_BELL_BISCUITS 148+#define U_PRESENT_BISCUITS 149+#define U_GINGERBREAD_MEN 150+#define U_GINGERBREAD_TREES 151+#define U_A_FESTIVE_HAT 152+#define U_INCREASED_MERRINESS 153+#define U_IMPROVED_JOLLINESS 154+#define U_A_LUMP_OF_COAL 155+#define U_AN_ITCHY_SWEATER 156+#define U_REINDEER_BAKING_GROUNDS 157+#define U_WEIGHTED_SLEIGHS 158+#define U_HO_HO_HO_FLAVORED_FROSTING 159+#define U_SEASON_SAVINGS 160+#define U_TOY_WORKSHOP 161+#define U_NAUGHTY_LIST 162+#define U_SANTAS_BOTTOMLESS_BAG 163+#define U_SANTAS_HELPERS 164+#define U_SANTAS_LEGACY 165+#define U_SANTAS_MILK_AND_COOKIES 166+#define U_REINDEER_SEASON 167+#define U_SANTAS_DOMINION 168+#define U_PURE_HEART_BISCUITS 169+#define U_ARDENT_HEART_BISCUITS 170+#define U_SOUR_HEART_BISCUITS 171+#define U_WEEPING_HEART_BISCUITS 172+#define U_GOLDEN_HEART_BISCUITS 173+#define U_ETERNAL_HEART_BISCUITS 174+#define U_GEM_POLISH 175+#define U__9TH_COLOR 176+#define U_CHOCOLATE_LIGHT 177+#define U_GRAINBOW 178+#define U_PURE_COSMIC_LIGHT 179+#define U_RAINBOW_GRANDMAS 180+#define U_SEASON_SWITCHER 181+#define U_FESTIVE_BISCUIT 182+#define U_GHOSTLY_BISCUIT 183+#define U_LOVESICK_BISCUIT 184+#define U_FOOLS_BISCUIT 185+#define U_ETERNAL_SEASONS 186+#define U_KITTEN_MANAGERS 187+#define U_SEPTILLION_FINGERS 188+#define U_OCTILLION_FINGERS 189+#define U_ELUDIUM_MOUSE 190+#define U_WISHALLOY_MOUSE 191+#define U_AGING_AGENTS 192+#define U_PULSAR_SPRINKLERS 193+#define U_DEEP_BAKE_PROCESS 194+#define U_COREFORGE 195+#define U_GENERATION_SHIP 196+#define U_ORIGIN_CRUCIBLE 197+#define U_DEITY_SIZED_PORTALS 198+#define U_FAR_FUTURE_ENACTMENT 199+#define U_NANOCOSMICS 200+#define U_GLOW_IN_THE_DARK 201+#define U_ROSE_MACARONS 202+#define U_LEMON_MACARONS 203+#define U_CHOCOLATE_MACARONS 204+#define U_PISTACHIO_MACARONS 205+#define U_HAZELNUT_MACARONS 206+#define U_VIOLET_MACARONS 207+#define U_MAGIC_SHENANIGANS 208+#define U_BUNNY_BISCUIT 209+#define U_CHICKEN_EGG 210+#define U_DUCK_EGG 211+#define U_TURKEY_EGG 212+#define U_QUAIL_EGG 213+#define U_ROBIN_EGG 214+#define U_OSTRICH_EGG 215+#define U_CASSOWARY_EGG 216+#define U_SALMON_ROE 217+#define U_FROGSPAWN 218+#define U_SHARK_EGG 219+#define U_TURTLE_EGG 220+#define U_ANT_LARVA 221+#define U_GOLDEN_GOOSE_EGG 222+#define U_FABERGE_EGG 223+#define U_WRINKLERSPAWN 224+#define U_COOKIE_EGG 225+#define U_OMELETTE 226+#define U_CHOCOLATE_EGG 227+#define U_CENTURY_EGG 228+#define U_EGG 229+#define U_CARAMEL_MACARONS 230+#define U_LICORICE_MACARONS 231+#define U_TALLER_TELLERS 232+#define U_SCISSOR_RESISTANT_CREDIT_CARDS 233+#define U_ACID_PROOF_VAULTS 234+#define U_CHOCOLATE_COINS 235+#define U_EXPONENTIAL_INTEREST_RATES 236+#define U_FINANCIAL_ZEN 237+#define U_GOLDEN_IDOLS 238+#define U_SACRIFICES 239+#define U_DELICIOUS_BLESSING 240+#define U_SUN_FESTIVAL 241+#define U_ENLARGED_PANTHEON 242+#define U_GREAT_BAKER_IN_THE_SKY 243+#define U_POINTIER_HATS 244+#define U_BEARDLIER_BEARDS 245+#define U_ANCIENT_GRIMOIRES 246+#define U_KITCHEN_CURSES 247+#define U_SCHOOL_OF_SORCERY 248+#define U_DARK_FORMULAS 249+#define U_BANKER_GRANDMAS 250+#define U_PRIESTESS_GRANDMAS 251+#define U_WITCH_GRANDMAS 252+#define U_TIN_OF_BRITISH_TEA_BISCUITS 253+#define U_BOX_OF_MACARONS 254+#define U_BOX_OF_BRAND_BISCUITS 255+#define U_PURE_BLACK_CHOCOLATE_COOKIES 256+#define U_PURE_WHITE_CHOCOLATE_COOKIES 257+#define U_LADYFINGERS 258+#define U_TUILES 259+#define U_CHOCOLATE_STUFFED_BISCUITS 260+#define U_CHECKER_COOKIES 261+#define U_BUTTER_COOKIES 262+#define U_CREAM_COOKIES 263+#define U_PERMANENT_UPGRADE_SLOT_I 264+#define U_PERMANENT_UPGRADE_SLOT_II 265+#define U_PERMANENT_UPGRADE_SLOT_III 266+#define U_PERMANENT_UPGRADE_SLOT_IV 267+#define U_PERMANENT_UPGRADE_SLOT_V 268+#define U_STARSPAWN 269+#define U_STARSNOW 270+#define U_STARTERROR 271+#define U_STARLOVE 272+#define U_STARTRADE 273+#define U_ANGELS 274+#define U_ARCHANGELS 275+#define U_VIRTUES 276+#define U_DOMINIONS 277+#define U_CHERUBIM 278+#define U_SERAPHIM 279+#define U_GOD 280+#define U_TWIN_GATES_OF_TRANSCENDENCE 281+#define U_HEAVENLY_LUCK 282+#define U_LASTING_FORTUNE 283+#define U_DECISIVE_FATE 284+#define U_DIVINE_DISCOUNT 285+#define U_DIVINE_SALES 286+#define U_DIVINE_BAKERIES 287+#define U_STARTER_KIT 288+#define U_STARTER_KITCHEN 289+#define U_HALO_GLOVES 290+#define U_KITTEN_ANGELS 291+#define U_UNHOLY_BAIT 292+#define U_SACRILEGIOUS_CORRUPTION 293+#define U_XTREME_WALKERS 294+#define U_FUDGE_FUNGUS 295+#define U_PLANETSPLITTERS 296+#define U_CYBORG_WORKFORCE 297+#define U_WAY_OF_THE_WALLET 298+#define U_CREATION_MYTH 299+#define U_COOKIEMANCY 300+#define U_DYSON_SPHERE 301+#define U_THEORY_OF_ATOMIC_FLUIDITY 302+#define U_END_OF_TIMES_BACK_UP_PLAN 303+#define U_GREAT_LOOP_HYPOTHESIS 304+#define U_THE_PULSE 305+#define U_LUX_SANCTORUM 306+#define U_THE_UNBRIDLING 307+#define U_WHEAT_TRIFFIDS 308+#define U_CANOLA_OIL_WELLS 309+#define U__78_HOUR_DAYS 310+#define U_THE_STUFF_RATIONALE 311+#define U_THEOCRACY 312+#define U_RABBIT_TRICK 313+#define U_THE_FINAL_FRONTIER 314+#define U_BEIGE_GOO 315+#define U_MADDENING_CHANTS 316+#define U_COOKIETOPIAN_MOMENTS_OF_MAYBE 317+#define U_SOME_OTHER_SUPER_TINY_FUNDAMENTAL_PARTICLE_PROBABLY 318+#define U_REVERSE_SHADOWS 319+#define U_KITTEN_ACCOUNTANTS 320+#define U_KITTEN_SPECIALISTS 321+#define U_KITTEN_EXPERTS 322+#define U_HOW_TO_BAKE_YOUR_DRAGON 323+#define U_A_CRUMBLY_EGG 324+#define U_CHIMERA 325+#define U_TIN_OF_BUTTER_COOKIES 326+#define U_GOLDEN_SWITCH 327+#define U_CLASSIC_DAIRY_SELECTION 328+#define U_FANCIFUL_DAIRY_SELECTION 329+#define U_DRAGON_COOKIE 330+#define U_GOLDEN_SWITCH_OFF 331+#define U_GOLDEN_SWITCH_ON 332+#define U_MILK_SELECTOR 333+#define U_MILK_CHOCOLATE_BUTTER_BISCUIT 334+#define U_DARK_CHOCOLATE_BUTTER_BISCUIT 335+#define U_WHITE_CHOCOLATE_BUTTER_BISCUIT 336+#define U_RUBY_CHOCOLATE_BUTTER_BISCUIT 337+#define U_GINGERSNAPS 338+#define U_CINNAMON_COOKIES 339+#define U_VANITY_COOKIES 340+#define U_CIGARS 341+#define U_PINWHEEL_COOKIES 342+#define U_FUDGE_SQUARES 343+#define U_DIGITS 344+#define U_BUTTER_HORSESHOES 345+#define U_BUTTER_PUCKS 346+#define U_BUTTER_KNOTS 347+#define U_BUTTER_SLABS 348+#define U_BUTTER_SWIRLS 349+#define U_SHORTBREAD_BISCUITS 350+#define U_MILLIONAIRES_SHORTBREADS 351+#define U_CARAMEL_COOKIES 352+#define U_BELPHEGOR 353+#define U_MAMMON 354+#define U_ABADDON 355+#define U_SATAN 356+#define U_ASMODEUS 357+#define U_BEELZEBUB 358+#define U_LUCIFER 359+#define U_GOLDEN_COOKIE_ALERT_SOUND 360+#define U_GOLDEN_COOKIE_SOUND_SELECTOR 361+#define U_BASIC_WALLPAPER_ASSORTMENT 362+#define U_LEGACY 363+#define U_ELDER_SPICE 364+#define U_RESIDUAL_LUCK 365+#define U_FANTASTEEL_MOUSE 366+#define U_NEVERCRACK_MOUSE 367+#define U_FIVE_FINGER_DISCOUNT 368+#define U_FUTURE_ALMANACS 369+#define U_RAIN_PRAYER 370+#define U_SEISMIC_MAGIC 371+#define U_ASTEROID_MINING 372+#define U_QUANTUM_ELECTRONICS 373+#define U_TEMPORAL_OVERCLOCKING 374+#define U_CONTRACTS_FROM_BEYOND 375+#define U_PRINTING_PRESSES 376+#define U_PAGANISM 377+#define U_GOD_PARTICLE 378+#define U_ARCANE_KNOWLEDGE 379+#define U_MAGICAL_BOTANY 380+#define U_FOSSIL_FUELS 381+#define U_SHIPYARDS 382+#define U_PRIMORDIAL_ORES 383+#define U_GOLD_FUND 384+#define U_INFERNAL_CROPS 385+#define U_ABYSMAL_GLIMMER 386+#define U_RELATIVISTIC_PARSEC_SKIPPING 387+#define U_PRIMEVAL_GLOW 388+#define U_EXTRA_PHYSICS_FUNDING 389+#define U_CHEMICAL_PROFICIENCY 390+#define U_LIGHT_MAGIC 391+#define U_MYSTICAL_ENERGIES 392+#define U_SYNERGIES_VOL_I 393+#define U_SYNERGIES_VOL_II 394+#define U_HEAVENLY_COOKIES 395+#define U_WRINKLY_COOKIES 396+#define U_DISTILLED_ESSENCE_OF_REDOUBLED_LUCK 397+#define U_OCCULT_OBSTRUCTION 398+#define U_GLUCOSE_CHARGED_AIR 399+#define U_LAVENDER_CHOCOLATE_BUTTER_BISCUIT 400+#define U_LOMBARDIA_COOKIES 401+#define U_BASTENAKEN_COOKIES 402+#define U_PECAN_SANDIES 403+#define U_MORAVIAN_SPICE_COOKIES 404+#define U_ANZAC_BISCUITS 405+#define U_BUTTERCAKES 406+#define U_ICE_CREAM_SANDWICHES 407+#define U_STEVIA_CAELESTIS 408+#define U_DIABETICA_DAEMONICUS 409+#define U_SUCRALOSIA_INUTILIS 410+#define U_LUCKY_DIGIT 411+#define U_LUCKY_NUMBER 412+#define U_LUCKY_PAYOUT 413+#define U_BACKGROUND_SELECTOR 414+#define U_LUCKY_GRANDMAS 415+#define U_YOUR_LUCKY_COOKIE 416+#define U_ALL_BETS_ARE_OFF_MAGIC_COIN 417+#define U_WINNING_LOTTERY_TICKET 418+#define U_FOUR_LEAF_CLOVER_FIELD 419+#define U_A_RECIPE_BOOK_ABOUT_BOOKS 420+#define U_LEPRECHAUN_VILLAGE 421+#define U_IMPROBABILITY_DRIVE 422+#define U_ANTISUPERSTISTRONICS 423+#define U_GEMMED_TALISMANS 424+#define U_KITTEN_CONSULTANTS 425+#define U_BIRTHDAY_COOKIE 426+#define U_ARMYTHRIL_MOUSE 427+#define U_REVERSE_DEMENTIA 428+#define U_HUMANE_PESTICIDES 429+#define U_MOLE_PEOPLE 430+#define U_MACHINE_LEARNING 431+#define U_EDIBLE_MONEY 432+#define U_SICK_RAP_PRAYERS 433+#define U_DELUXE_TAILORED_WANDS 434+#define U_AUTOPILOT 435+#define U_THE_ADVENT_OF_CHEMISTRY 436+#define U_THE_REAL_WORLD 437+#define U_SECOND_SECONDS 438+#define U_QUANTUM_COMB 439+#define U_CRYSTAL_MIRRORS 440+#define U_BUNNYPEDES 441+#define U_KITTEN_ASSISTANTS_TO_THE_REGIONAL_MANAGER 442+#define U_CHARM_QUARKS 443+#define U_PINK_BISCUITS 444+#define U_WHOLE_GRAIN_COOKIES 445+#define U_CANDY_COOKIES 446+#define U_BIG_CHIP_COOKIES 447+#define U_ONE_CHIP_COOKIES 448+#define U_SUGAR_BAKING 449+#define U_SUGAR_CRAVING 450+#define U_SUGAR_AGING_PROCESS 451+#define U_SUGAR_FRENZY 452+#define U_SPRINKLES_COOKIES 453+#define U_PEANUT_BUTTER_BLOSSOMS 454+#define U_NO_BAKE_COOKIES 455+#define U_FLORENTINES 456+#define U_CHOCOLATE_CRINKLES 457+#define U_MAPLE_COOKIES 458+#define U_TURBO_CHARGED_SOIL 459+#define U_TECHNOBSIDIAN_MOUSE 460+#define U_PLASMARBLE_MOUSE 461+#define U_KITTEN_MARKETEERS 462+#define U_FESTIVITY_LOOPS 463+#define U_PERSIAN_RICE_COOKIES 464+#define U_NORWEGIAN_COOKIES 465+#define U_CRISPY_RICE_COOKIES 466+#define U_UBE_COOKIES 467+#define U_BUTTERSCOTCH_COOKIES 468+#define U_SPECULAAS 469+#define U_ELDERWORT_BISCUITS 470+#define U_BAKEBERRY_COOKIES 471+#define U_DUKETATER_COOKIES 472+#define U_GREEN_YEAST_DIGESTIVES 473+#define U_FERN_TEA 474+#define U_ICHOR_SYRUP 475+#define U_WHEAT_SLIMS 476+#define U_SYNTHETIC_CHOCOLATE_GREEN_HONEY_BUTTER_BISCUIT 477+#define U_ROYAL_RASPBERRY_CHOCOLATE_BUTTER_BISCUIT 478+#define U_ULTRA_CONCENTRATED_HIGH_ENERGY_CHOCOLATE_BUTTER_BISCUIT 479+#define U_TIMEPROOF_HAIR_DYES 480+#define U_BARNSTARS 481+#define U_MINE_CANARIES 482+#define U_BROWNIE_POINT_SYSTEM 483+#define U_GRAND_SUPERCYCLES 484+#define U_PSALM_READING 485+#define U_IMMOBILE_SPELLCASTING 486+#define U_RESTAURANTS_AT_THE_END_OF_THE_UNIVERSE 487+#define U_ON_SECOND_THOUGHT 488+#define U_DIMENSIONAL_GARBAGE_GULPER 489+#define U_ADDITIONAL_CLOCK_HANDS 490+#define U_BAKING_NOBEL_PRIZE 491+#define U_REVERSE_THEORY_OF_LIGHT 492+#define U_REVISED_PROBABILISTICS 493+#define U_KITTEN_ANALYSTS 494+#define U_EYE_OF_THE_WRINKLER 495+#define U_INSPIRED_CHECKLIST 496+#define U_PURE_PITCH_BLACK_CHOCOLATE_BUTTER_BISCUIT 497+#define U_CHOCOLATE_OATMEAL_COOKIES 498+#define U_MOLASSES_COOKIES 499+#define U_BISCOTTI 500+#define U_WAFFLE_COOKIES 501+#define U_ALMOND_COOKIES 502+#define U_HAZELNUT_COOKIES 503+#define U_WALNUT_COOKIES 504+#define U_LABEL_PRINTER 505+#define U_GOOD_MANNERS 506+#define U_LINDWORMS 507+#define U_BORE_AGAIN 508+#define U_VOLUNTEER_INTERNS 509+#define U_RULES_OF_ACQUISITION 510+#define U_WAR_OF_THE_GODS 511+#define U_ELECTRICITY 512+#define U_UNIVERSAL_ALPHABET 513+#define U_PUBLIC_BETTERMENT 514+#define U_EMBEDDED_MICROPORTALS 515+#define U_NOSTALGIA 516+#define U_THE_DEFINITE_MOLECULE 517+#define U_LIGHT_CAPTURE_MEASURES 518+#define U__0_SIDED_DICE 519+#define U_HERALDS 520+#define U_METAGRANDMAS 521+#define U_METABAKERIES 522+#define U_MANDELBROWN_SUGAR 523+#define U_FRACTOIDS 524+#define U_NESTED_UNIVERSE_THEORY 525+#define U_MENGER_SPONGE_CAKE 526+#define U_ONE_PARTICULARLY_GOOD_HUMORED_COW 527+#define U_CHOCOLATE_OUROBOROS 528+#define U_NESTED 529+#define U_SPACE_FILLING_FIBERS 530+#define U_ENDLESS_BOOK_OF_PROSE 531+#define U_THE_SET_OF_ALL_SETS 532+#define U_RECURSIVE_MIRRORS 533+#define U_MICE_CLICKING_MICE 534+#define U_CUSTARD_CREAMS 535+#define U_BOURBON_BISCUITS 536+#define U_KEEPSAKES 537+#define U_MINI_COOKIES 538+#define U_SUGAR_CRYSTAL_COOKIES 539+#define U_BOX_OF_MAYBE_COOKIES 540+#define U_BOX_OF_NOT_COOKIES 541+#define U_BOX_OF_PASTRIES 542+#define U_PROFITEROLES 543+#define U_JELLY_DONUT 544+#define U_GLAZED_DONUT 545+#define U_CHOCOLATE_CAKE 546+#define U_STRAWBERRY_CAKE 547+#define U_APPLE_PIE 548+#define U_LEMON_MERINGUE_PIE 549+#define U_BUTTER_CROISSANT 550+#define U_COOKIE_DOUGH 551+#define U_BURNT_COOKIE 552+#define U_A_CHOCOLATE_CHIP_COOKIE_BUT_WITH_THE_CHIPS_PICKED_OFF_FOR_SOME_REASON 553+#define U_FLAVOR_TEXT_COOKIE 554+#define U_HIGH_DEFINITION_COOKIE 555+#define U_TOAST 556+#define U_PEANUT_BUTTER_AND_JELLY 557+#define U_WOOKIES 558+#define U_CHEESEBURGER 559+#define U_ONE_LONE_CHOCOLATE_CHIP 560+#define U_GENIUS_ACCOUNTING 561+#define U_SHIMMERING_VEIL 562+#define U_SHIMMERING_VEIL_OFF 563+#define U_SHIMMERING_VEIL_ON 564+#define U_WHOOPIE_PIES 565+#define U_CARAMEL_WAFER_BISCUITS 566+#define U_CHOCOLATE_CHIP_MOCHA_COOKIES 567+#define U_EARL_GREY_COOKIES 568+#define U_CORN_SYRUP_COOKIES 569+#define U_ICEBOX_COOKIES 570+#define U_GRAHAM_CRACKERS 571+#define U_HARDTACK 572+#define U_CORNFLAKE_COOKIES 573+#define U_TOFU_COOKIES 574+#define U_GLUTEN_FREE_COOKIES 575+#define U_RUSSIAN_BREAD_COOKIES 576+#define U_LEBKUCHEN 577+#define U_AACHENER_PRINTEN 578+#define U_CANISTRELLI 579+#define U_NICE_BISCUITS 580+#define U_FRENCH_PURE_BUTTER_COOKIES 581+#define U_PETIT_BEURRE 582+#define U_NANAIMO_BARS 583+#define U_BERGER_COOKIES 584+#define U_CHINSUKO 585+#define U_PANDA_KOALA_BISCUITS 586+#define U_PUTRI_SALJU 587+#define U_MILK_COOKIES 588+#define U_COOKIE_CRUMBS 589+#define U_CHOCOLATE_CHIP_COOKIE 590+#define U_COSMIC_BEGINNERS_LUCK 591+#define U_REINFORCED_MEMBRANE 592+#define U_BINARY_GRANDMAS 593+#define U_THE_JAVASCRIPT_CONSOLE_FOR_DUMMIES 594+#define U__64BIT_ARRAYS 595+#define U_STACK_OVERFLOW 596+#define U_ENTERPRISE_COMPILER 597+#define U_SYNTACTIC_SUGAR 598+#define U_A_NICE_CUP_OF_COFFEE 599+#define U_JUST_IN_TIME_BAKING 600+#define U_COOKIES 601+#define U_SOFTWARE_UPDATES 602+#define U_GAME_LOOP 603+#define U_EVAL 604+#define U_SCRIPT_GRANNIES 605+#define U_TOMBOLA_COMPUTING 606+#define U_KRUIDNOTEN 607+#define U_MARIE_BISCUITS 608+#define U_MERINGUE_COOKIES 609+#define U_PIZZA 610+#define U_CRACKERS 611+#define U_HAVABREAKS 612+#define U_KITTEN_EXECUTIVES 613+#define U_CHAI_TEA_COOKIES 614+#define U_YOGURT_COOKIES 615+#define U_THUMBPRINT_COOKIES 616+#define U_PIZZELLE 617+#define U_ZILLA_WAFERS 618+#define U_DIM_DAMS 619+#define U_CANDY 620+#define U_FORTUNE_001 621+#define U_FORTUNE_002 622+#define U_FORTUNE_003 623+#define U_FORTUNE_004 624+#define U_FORTUNE_005 625+#define U_FORTUNE_006 626+#define U_FORTUNE_007 627+#define U_FORTUNE_008 628+#define U_FORTUNE_009 629+#define U_FORTUNE_010 630+#define U_FORTUNE_011 631+#define U_FORTUNE_012 632+#define U_FORTUNE_013 633+#define U_FORTUNE_014 634+#define U_FORTUNE_015 635+#define U_FORTUNE_016 636+#define U_FORTUNE_017 637+#define U_FORTUNE_100 638+#define U_FORTUNE_101 639+#define U_FORTUNE_102 640+#define U_FORTUNE_103 641+#define U_FORTUNE_104 642+#define U_FORTUNE_COOKIES 643+#define U_A_REALLY_GOOD_GUIDE_BOOK 644+#define U_PRISM_HEART_BISCUITS 645+#define U_KITTEN_WAGES 646+#define U_PET_THE_DRAGON 647+#define U_DRAGON_SCALE 648+#define U_DRAGON_CLAW 649+#define U_DRAGON_FANG 650+#define U_DRAGON_TEDDY_BEAR 651+#define U_GRANOLA_COOKIES 652+#define U_RICOTTA_COOKIES 653+#define U_ROZE_KOEKEN 654+#define U_PEANUT_BUTTER_CUP_COOKIES 655+#define U_SESAME_COOKIES 656+#define U_TAIYAKI 657+#define U_VANILLEKIPFERL 658+#define U_COSMIC_CHOCOLATE_BUTTER_BISCUIT 659+#define U_NONILLION_FINGERS 660+#define U_MIRACULITE_MOUSE 661+#define U_GENERATION_DEGENERATION 662+#define U_GLOBAL_SEED_VAULT 663+#define U_AIR_MINING 664+#define U_BEHAVIORAL_REFRAMING 665+#define U_ALTRUISTIC_LOOP 666+#define U_A_NOVEL_IDEA 667+#define U_SPELLING_BEES 668+#define U_TOROID_UNIVERSE 669+#define U_HERMETIC_RECONCILIATION 670+#define U_HIS_ADVENT 671+#define U_SPLIT_SECONDS 672+#define U_FLAVOR_ITSELF 673+#define U_LIGHT_SPEED_LIMIT 674+#define U_A_TOUCH_OF_DETERMINISM 675+#define U_THIS_UPGRADE 676+#define U_YOUR_BIGGEST_FANS 677+#define U_BATTENBERG_BISCUITS 678+#define U_ROSETTE_COOKIES 679+#define U_GANGMAKERS 680+#define U_WELSH_COOKIES 681+#define U_RASPBERRY_CHEESECAKE_COOKIES 682+#define U_ALTERNATE_GRANDMAS 683+#define U_MANIFEST_DESTINY 684+#define U_THE_MULTIVERSE_IN_A_NUTSHELL 685+#define U_ALL_CONVERSION 686+#define U_MULTIVERSE_AGENTS 687+#define U_ESCAPE_PLAN 688+#define U_GAME_DESIGN 689+#define U_SANDBOX_UNIVERSES 690+#define U_MULTIVERSE_WARS 691+#define U_MOBILE_PORTS 692+#define U_ENCAPSULATED_REALITIES 693+#define U_EXTRINSIC_CLICKING 694+#define U_UNIVERSAL_IDLING 695+#define U_PERFORATED_MILLE_FEUILLE_COSMOS 696+#define U_INFRAVERSES_AND_SUPERVERSES 697+#define U_FORTUNE_018 698+#define U_BUTTER_BISCUIT_WITH_BUTTER 699+#define U_VISITS 700+#define U_REVERSE_VEGANISM 701+#define U_CARAMEL_ALLOYS 702+#define U_THE_INFINITY_ENGINE 703+#define U_DIMINISHING_TAX_RETURNS 704+#define U_APPARITIONS 705+#define U_WIZARD_BASEMENTS 706+#define U_PRIME_DIRECTIVE 707+#define U_CHROMATIC_CYCLING 708+#define U_DOMESTIC_RIFTS 709+#define U_PATIENCE_ABOLISHED 710+#define U_DELICIOUS_PULL 711+#define U_OCCAMS_LASER 712+#define U_ON_A_STREAK 713+#define U_A_BOX 714+#define U_HACKER_SHADES 715+#define U_BREAK_THE_FIFTH_WALL 716+#define U_CAT_LADIES 717+#define U_MILKHELPANDREG_LACTOSE_INTOLERANCE_RELIEF_TABLETS 718+#define U_AURA_GLOVES 719+#define U_LUMINOUS_GLOVES 720+#define U_BOKKENPOOTJES 721+#define U_FAT_RASCALS 722+#define U_ISCHLER_COOKIES 723+#define U_MATCHA_COOKIES 724+#define U_EARL_GREY_MACARONS 725+#define U_POKEY 726+#define U_CASHEW_COOKIES 727+#define U_MILK_CHOCOLATE_COOKIES 728+#define U_BRAINY_GRANDMAS 729+#define U_PRINCIPLED_NEURAL_SHACKLES 730+#define U_OBEY 731+#define U_A_SPRINKLE_OF_IRRATIONALITY 732+#define U_FRONT_AND_BACK_HEMISPHERES 733+#define U_NEURAL_NETWORKING 734+#define U_COSMIC_BRAINSTORMS 735+#define U_MEGATHERAPY 736+#define U_SYNAPTIC_LUBRICANT 737+#define U_PSYCHOKINESIS 738+#define U_SPINES 739+#define U_NEURAFORMING 740+#define U_EPISTEMOLOGICAL_TRICKERY 741+#define U_EVERY_POSSIBLE_IDEA 742+#define U_KITCHEN_CABINETS 743+#define U_COOKIE_MULCH 744+#define U_DELICIOUS_MINERALOGY 745+#define U_N_DIMENSIONAL_ASSEMBLY_LINES 746+#define U_COOKIE_POINTS 747+#define U_NEGATHEISM 748+#define U_MAGICAL_REALISM 749+#define U_COSMIC_FOREGROUND_RADIATION 750+#define U_ARCANIZED_GLASSWARE 751+#define U_PORTAL_GUNS 752+#define U_TIMEPROOF_UPHOLSTERY 753+#define U_EMPLOYEE_MINIFICATION 754+#define U_HYPERBLACK_PAINT 755+#define U_SILVER_LINING_MAXIMIZATION 756+#define U_MULTISCALE_PROFILING 757+#define U_PHP_CONTAINMENT_VATS 758+#define U_OPPOSITE_UNIVERSE 759+#define U_THE_LAND_OF_DREAMS 760+#define U_THOUGHTS_AND_PRAYERS 761+#define U_FERTILE_MINDS 762+#define U_FORTUNE_019 763+#define U_DECILLION_FINGERS 764+#define U_AETHERICE_MOUSE 765+#define U_KITTEN_ADMINS 766+#define U_EVERYBUTTER_BISCUIT 767+#define U_UNSHACKLED_CURSORS 768+#define U_UNSHACKLED_GRANDMAS 769+#define U_UNSHACKLED_FARMS 770+#define U_UNSHACKLED_MINES 771+#define U_UNSHACKLED_FACTORIES 772+#define U_UNSHACKLED_BANKS 773+#define U_UNSHACKLED_TEMPLES 774+#define U_UNSHACKLED_WIZARD_TOWERS 775+#define U_UNSHACKLED_SHIPMENTS 776+#define U_UNSHACKLED_ALCHEMY_LABS 777+#define U_UNSHACKLED_PORTALS 778+#define U_UNSHACKLED_TIME_MACHINES 779+#define U_UNSHACKLED_ANTIMATTER_CONDENSERS 780+#define U_UNSHACKLED_PRISMS 781+#define U_UNSHACKLED_CHANCEMAKERS 782+#define U_UNSHACKLED_FRACTAL_ENGINES 783+#define U_UNSHACKLED_JAVASCRIPT_CONSOLES 784+#define U_UNSHACKLED_IDLEVERSES 785+#define U_UNSHACKLED_CORTEX_BAKERS 786+#define U_UNSHACKLED_FLAVOR 787+#define U_UNSHACKLED_BERRYLIUM 788+#define U_UNSHACKLED_BLUEBERRYLIUM 789+#define U_UNSHACKLED_CHALCEDHONEY 790+#define U_UNSHACKLED_BUTTERGOLD 791+#define U_UNSHACKLED_SUGARMUCK 792+#define U_UNSHACKLED_JETMINT 793+#define U_UNSHACKLED_CHERRYSILVER 794+#define U_UNSHACKLED_HAZELRALD 795+#define U_UNSHACKLED_MOONCANDY 796+#define U_UNSHACKLED_ASTROFUDGE 797+#define U_UNSHACKLED_ALABASCREAM 798+#define U_UNSHACKLED_IRIDYUM 799+#define U_UNSHACKLED_GLUCOSMIUM 800+#define U_DELICATE_TOUCH 801+#define U_STEADFAST_MURMUR 802+#define U_GLITTERING_EDGE 803+#define U_DISTINGUISHED_WALLPAPER_ASSORTMENT 804+#define U_SOUND_TEST 805+#define U_JUKEBOX 806+#define U_DALGONA_COOKIES 807+#define U_SPICY_COOKIES 808+#define U_SMILE_COOKIES 809+#define U_KOLACHY_COOKIES 810+#define U_GOMMA_COOKIES 811+#define U_VEGAN_COOKIES 812+#define U_COYOTAS 813+#define U_FROSTED_SUGAR_COOKIES 814+#define U_MARSHMALLOW_SANDWICH_COOKIES 815+#define U_WEB_COOKIES 816+#define U_STEAMED_COOKIES 817+#define U_DEEP_FRIED_COOKIE_DOUGH 818+#define U_WRAPPING_PAPER 819+#define U_HAVREFLARN 820+#define U_ALFAJORES 821+#define U_GAUFRETTES 822+#define U_COOKIE_BARS 823+#define U_NINES 824+#define U_CLONE_GRANDMAS 825+#define U_CLONING_VATS 826+#define U_ENERGIZED_NUTRIENTS 827+#define U_STUNT_DOUBLES 828+#define U_CLONE_RECYCLING_PLANT 829+#define U_FREE_RANGE_CLONES 830+#define U_GENETIC_TAILORING 831+#define U_POWER_IN_DIVERSITY 832+#define U_SELF_BETTERMENT 833+#define U_SOURCE_CONTROL 834+#define U_UNITED_WORKFORCE 835+#define U_SAFETY_PATROLS 836+#define U_CLONE_RIGHTS 837+#define U_ONE_BIG_FAMILY 838+#define U_FINE_TUNED_BODY_PLANS 839+#define U_FOAM_TIPPED_CANES 840+#define U_SELF_DRIVING_TRACTORS 841+#define U_MINESHAFT_SUPPORTS 842+#define U_UNIVERSAL_AUTOMATION 843+#define U_THE_BIG_SHORTCAKE 844+#define U_TEMPLE_TRAPS 845+#define U_POLYMORPHISM 846+#define U_AT_YOUR_DOORSTEP_IN_30_MINUTES_OR_YOUR_MONEY_BACK 847+#define U_THE_DOSE_MAKES_THE_POISON 848+#define U_A_WAY_HOME 849+#define U_RECTIFYING_A_MISTAKE 850+#define U_CANDIED_ATOMS 851+#define U_LAB_GOGGLES_BUT_LIKE_COOL_SHADES 852+#define U_GAMBLERS_FALLACY_FALLACY 853+#define U_THE_MORE_THEY_STAY_THE_SAME 854+#define U_SIMULATION_FAILSAFES 855+#define U_THE_OTHER_ROUTES_TO_ROME 856+#define U_INTELLECTUAL_PROPERTY_THEFT 857+#define U_READING_YOUR_CLONES_BEDTIME_STORIES 858+#define U_ACCELERATED_DEVELOPMENT 859+#define U_PEER_REVIEW 860+#define U_FORTUNE_020 861+#define U_PERSONAL_BISCUIT 862+#define U_UNSHACKLED_GLIMMERINGUE 863+#define U_UNSHACKLED_YOU 864+#define U_KITTEN_STRATEGISTS 865+#define U_BAKLAVAS 866+#define U_SNOWBALL_COOKIES 867+#define U_SEQUILHOS 868+#define U_HAZELNUT_SWIRLIES 869+#define U_SPRITZ_COOKIES 870+#define U_MBATATA_COOKIES 871+#define U_SPRINGERLES 872+#define U_UNDECILLION_FINGERS 873+#define U_OMNIPLAST_MOUSE 874+#define U_WRINKLER_AMBERGRIS 875+#define OFF_ACHIEVS 1505256+#define N_ACHIEVS 643+#define A_WAKE_AND_BAKE 0+#define A_MAKING_SOME_DOUGH 1+#define A_SO_BAKED_RIGHT_NOW 2+#define A_FLEDGLING_BAKERY 3+#define A_AFFLUENT_BAKERY 4+#define A_WORLD_FAMOUS_BAKERY 5+#define A_COSMIC_BAKERY 6+#define A_GALACTIC_BAKERY 7+#define A_UNIVERSAL_BAKERY 8+#define A_TIMELESS_BAKERY 9+#define A_INFINITE_BAKERY 10+#define A_IMMORTAL_BAKERY 11+#define A_DONT_STOP_ME_NOW 12+#define A_YOU_CAN_STOP_NOW 13+#define A_COOKIES_ALL_THE_WAY_DOWN 14+#define A_OVERDOSE 15+#define A_CASUAL_BAKING 16+#define A_HARDCORE_BAKING 17+#define A_STEADY_TASTY_STREAM 18+#define A_COOKIE_MONSTER 19+#define A_MASS_PRODUCER 20+#define A_COOKIE_VORTEX 21+#define A_COOKIE_PULSAR 22+#define A_COOKIE_QUASAR 23+#define A_OH_HEY_YOURE_STILL_HERE 24+#define A_LETS_NEVER_BAKE_AGAIN 25+#define A_SACRIFICE 26+#define A_OBLIVION 27+#define A_FROM_SCRATCH 28+#define A_NEVERCLICK 29+#define A_CLICKTASTIC 30+#define A_CLICKATHLON 31+#define A_CLICKOLYMPICS 32+#define A_CLICKORAMA 33+#define A_CLICK 34+#define A_DOUBLE_CLICK 35+#define A_MOUSE_WHEEL 36+#define A_OF_MICE_AND_MEN 37+#define A_THE_DIGITAL 38+#define A_JUST_WRONG 39+#define A_GRANDMAS_COOKIES 40+#define A_SLOPPY_KISSES 41+#define A_RETIREMENT_HOME 42+#define A_BOUGHT_THE_FARM 43+#define A_REAP_WHAT_YOU_SOW 44+#define A_FARM_ILL 45+#define A_PRODUCTION_CHAIN 46+#define A_INDUSTRIAL_REVOLUTION 47+#define A_GLOBAL_WARMING 48+#define A_YOU_KNOW_THE_DRILL 49+#define A_EXCAVATION_SITE 50+#define A_HOLLOW_THE_PLANET 51+#define A_EXPEDITION 52+#define A_GALACTIC_HIGHWAY 53+#define A_FAR_FAR_AWAY 54+#define A_TRANSMUTATION 55+#define A_TRANSMOGRIFICATION 56+#define A_GOLD_MEMBER 57+#define A_A_WHOLE_NEW_WORLD 58+#define A_NOW_YOURE_THINKING 59+#define A_DIMENSIONAL_SHIFT 60+#define A_TIME_WARP 61+#define A_ALTERNATE_TIMELINE 62+#define A_REWRITING_HISTORY 63+#define A_ONE_WITH_EVERYTHING 64+#define A_MATHEMATICIAN 65+#define A_BASE_10 66+#define A_GOLDEN_COOKIE 67+#define A_LUCKY_COOKIE 68+#define A_A_STROKE_OF_LUCK 69+#define A_CHEATED_COOKIES_TASTE_AWFUL 70+#define A_UNCANNY_CLICKER 71+#define A_BUILDER 72+#define A_ARCHITECT 73+#define A_ENHANCER 74+#define A_AUGMENTER 75+#define A_COOKIE_DUNKER 76+#define A_FORTUNE 77+#define A_TRUE_NEVERCLICK 78+#define A_ELDER_NAP 79+#define A_ELDER_SLUMBER 80+#define A_ELDER 81+#define A_ELDER_CALM 82+#define A_ENGINEER 83+#define A_LEPRECHAUN 84+#define A_BLACK_CATS_PAW 85+#define A_NIHILISM 86+#define A_ANTIBATTER 87+#define A_QUIRKY_QUARKS 88+#define A_IT_DOES_MATTER 89+#define A_UPGRADER 90+#define A_CENTENNIAL 91+#define A_HARDCORE 92+#define A_SPEED_BAKING_I 93+#define A_SPEED_BAKING_II 94+#define A_SPEED_BAKING_III 95+#define A_GETTING_EVEN_WITH_THE_OVEN 96+#define A_NOW_THIS_IS_POD_SMASHING 97+#define A_CHIRPED_OUT 98+#define A_FOLLOW_THE_WHITE_RABBIT 99+#define A_CLICKASMIC 100+#define A_FRIEND_OF_THE_ANCIENTS 101+#define A_RULER_OF_THE_ANCIENTS 102+#define A_WHOLESOME 103+#define A_JUST_PLAIN_LUCKY 104+#define A_ITCHSCRATCHER 105+#define A_WRINKLESQUISHER 106+#define A_MOISTBURSTER 107+#define A_SPOOKY_COOKIES 108+#define A_COMING_TO_TOWN 109+#define A_ALL_HAIL_SANTA 110+#define A_LET_IT_SNOW 111+#define A_OH_DEER 112+#define A_SLEIGH_OF_HAND 113+#define A_REINDEER_SLEIGHER 114+#define A_PERFECTED_AGRICULTURE 115+#define A_ULTIMATE_AUTOMATION 116+#define A_CAN_YOU_DIG_IT 117+#define A_TYPE_II_CIVILIZATION 118+#define A_GILD_WARS 119+#define A_BRAIN_SPLIT 120+#define A_TIME_DUKE 121+#define A_MOLECULAR_MAESTRO 122+#define A_LONE_PHOTON 123+#define A_DAZZLING_GLIMMER 124+#define A_BLINDING_FLASH 125+#define A_UNENDING_GLOW 126+#define A_LORD_OF_CONSTRUCTS 127+#define A_LORD_OF_PROGRESS 128+#define A_BICENTENNIAL 129+#define A_LOVELY_COOKIES 130+#define A_CENTENNIAL_AND_A_HALF 131+#define A_TINY_COOKIE 132+#define A_YOU_WIN_A_COOKIE 133+#define A_CLICK_DELEGATOR 134+#define A_GUSHING_GRANNIES 135+#define A_I_HATE_MANURE 136+#define A_NEVER_DIG_DOWN 137+#define A_THE_INCREDIBLE_MACHINE 138+#define A_AND_BEYOND 139+#define A_MAGNUM_OPUS 140+#define A_WITH_STRANGE_EONS 141+#define A_SPACETIME_JIGAMAROO 142+#define A_SUPERMASSIVE 143+#define A_PRAISE_THE_SUN 144+#define A_CLICKAGEDDON 145+#define A_CLICKNAROK 146+#define A_EXTREME_POLYDACTYLY 147+#define A_DR_T 148+#define A_THE_OLD_NEVER_BOTHERED_ME_ANYWAY 149+#define A_HOMEGROWN 150+#define A_TECHNOCRACY 151+#define A_THE_CENTER_OF_THE_EARTH 152+#define A_WE_COME_IN_PEACE 153+#define A_THE_SECRETS_OF_THE_UNIVERSE 154+#define A_REALM_OF_THE_MAD_GOD 155+#define A_FOREVER_AND_EVER 156+#define A_WALK_THE_PLANCK 157+#define A_RISE_AND_SHINE 158+#define A_GOD_COMPLEX 159+#define A_THIRD_PARTY 160+#define A_DEMATERIALIZE 161+#define A_NIL_ZERO_ZILCH 162+#define A_TRANSCENDENCE 163+#define A_OBLITERATE 164+#define A_NEGATIVE_VOID 165+#define A_THE_HUNT_IS_ON 166+#define A_EGGING_ON 167+#define A_MASS_EASTERIA 168+#define A_HIDE_AND_SEEK_CHAMPION 169+#define A_WHATS_IN_A_NAME 170+#define A_PRETTY_PENNY 171+#define A_FIT_THE_BILL 172+#define A_A_LOAN_IN_THE_DARK 173+#define A_NEED_FOR_GREED 174+#define A_ITS_THE_ECONOMY_STUPID 175+#define A_YOUR_TIME_TO_SHRINE 176+#define A_SHADY_SECT 177+#define A_NEW_AGE_CULT 178+#define A_ORGANIZED_RELIGION 179+#define A_FANATICISM 180+#define A_BEWITCHED 181+#define A_THE_SORCERERS_APPRENTICE 182+#define A_CHARMS_AND_ENCHANTMENTS 183+#define A_CURSES_AND_MALEDICTIONS 184+#define A_MAGIC_KINGDOM 185+#define A_VESTED_INTEREST 186+#define A_NEW_WORLD_ORDER 187+#define A_HOCUS_POCUS 188+#define A_FINGER_CLICKIN_GOOD 189+#define A_PANIC_AT_THE_BINGO 190+#define A_RAKE_IN_THE_DOUGH 191+#define A_QUARRY_ON 192+#define A_YES_I_LOVE_TECHNOLOGY 193+#define A_PAID_IN_FULL 194+#define A_CHURCH_OF_COOKIOLOGY 195+#define A_TOO_MANY_RABBITS_NOT_ENOUGH_HATS 196+#define A_THE_MOST_PRECIOUS_CARGO 197+#define A_THE_AUREATE 198+#define A_EVER_MORE_HIDEOUS 199+#define A_BE_KIND_REWIND 200+#define A_INFINITESIMAL 201+#define A_A_STILL_MORE_GLORIOUS_DAWN 202+#define A_REBIRTH 203+#define A_HERE_YOU_GO 204+#define A_RESURRECTION 205+#define A_REINCARNATION 206+#define A_ENDLESS_CYCLE 207+#define A_THE_AGEMASTER 208+#define A_TO_OLDLY_GO 209+#define A_GARDENER_EXTRAORDINAIRE 210+#define A_TECTONIC_AMBASSADOR 211+#define A_RISE_OF_THE_MACHINES 212+#define A_ACQUIRE_CURRENCY 213+#define A_ZEALOTRY 214+#define A_THE_WIZARDING_WORLD 215+#define A_PARSEC_MASHER 216+#define A_THE_WORK_OF_A_LIFETIME 217+#define A_A_PLACE_LOST_IN_TIME 218+#define A_HEAT_DEATH 219+#define A_MICROCOSM 220+#define A_BRIGHT_FUTURE 221+#define A_HERE_BE_DRAGON 222+#define A_HOW 223+#define A_THE_LAND_OF_MILK_AND_COOKIES 224+#define A_HE_WHO_CONTROLS_THE_COOKIES_CONTROLS_THE_UNIVERSE 225+#define A_TONIGHT_ON_HOARDERS 226+#define A_ARE_YOU_GONNA_EAT_ALL_THAT 227+#define A_WERE_GONNA_NEED_A_BIGGER_BAKERY 228+#define A_IN_THE_MOUTH_OF_MADNESS 229+#define A_BROUGHT_TO_YOU_BY_THE_LETTER_DIV_STYLE_DISPLAY_INLINE_BLOCK_BACKGROUND_URL_IMG_MONEY_PNG_WIDTH_16PX_HEIGHT_16PX_DIV 230+#define A_A_WORLD_FILLED_WITH_COOKIES 231+#define A_WHEN_THIS_BABY_HITS_36_QUADRILLION_COOKIES_PER_HOUR 232+#define A_FAST_AND_DELICIOUS 233+#define A_COOKIEHERTZ_A_REALLY_REALLY_TASTY_HERTZ 234+#define A_WOOPS_YOU_SOLVED_WORLD_HUNGER 235+#define A_TURBOPUNS 236+#define A_FASTER_MENNER 237+#define A_AND_YET_YOURE_STILL_HUNGRY 238+#define A_THE_ABAKENING 239+#define A_THERES_REALLY_NO_HARD_LIMIT_TO_HOW_LONG_THESE_ACHIEVEMENT_NAMES_CAN_BE_AND_TO_BE_QUITE_HONEST_IM_RATHER_CURIOUS_TO_SEE_HOW_FAR_WE_CAN_GO_BR_ADOLPHUS_W_GREEN_1844_1917_STARTED_AS_THE_PRINCIPAL_OF_THE_GROTON_SCHOOL_IN_1864_BY_1865_HE_BECAME_SECOND_ASSISTANT_LIBRARIAN_AT_THE_NEW_YORK_MERCANTILE_LIBRARY_FROM_1867_TO_1869_HE_WAS_PROMOTED_TO_FULL_LIBRARIAN_FROM_1869_TO_1873_HE_WORKED_FOR_EVARTS_SOUTHMAYD_AND_CHOATE_A_LAW_FIRM_CO_FOUNDED_BY_WILLIAM_M_EVARTS_CHARLES_FERDINAND_SOUTHMAYD_AND_JOSEPH_HODGES_CHOATE_HE_WAS_ADMITTED_TO_THE_NEW_YORK_STATE_BAR_ASSOCIATION_IN_1873_BR_ANYWAY_HOWS_YOUR_DAY_BEEN 240+#define A_FAST 241+#define A_BICENTENNIAL_AND_A_HALF 242+#define A_TABLOID_ADDICTION 243+#define A_CLICKASTROPHE 244+#define A_CLICKATACLYSM 245+#define A_THUMBS_PHALANGES_METACARPALS 246+#define A_POLYMATH 247+#define A_THE_ELDER_SCROLLS 248+#define A_TO_CRUMBS_YOU_SAY 249+#define A_SEEDY_BUSINESS 250+#define A_FREAK_FRACKING 251+#define A_MODERN_TIMES 252+#define A_THE_NERVE_OF_WAR 253+#define A_WOLOLO 254+#define A_AND_NOW_FOR_MY_NEXT_TRICK_ILL_NEED_A_VOLUNTEER_FROM_THE_AUDIENCE 255+#define A_ITS_NOT_DELIVERY 256+#define A_GOLD_JERRY_GOLD 257+#define A_FORBIDDEN_ZONE 258+#define A_COOKIE_CLICKER_FOREVER_AND_FOREVER_A_HUNDRED_YEARS_COOKIE_CLICKER_ALL_DAY_LONG_FOREVER_FOREVER_A_HUNDRED_TIMES_OVER_AND_OVER_COOKIE_CLICKER_ADVENTURES_DOT_COM 259+#define A_SCIENTISTS_BAFFLED_EVERYWHERE 260+#define A_HARMONY_OF_THE_SPHERES 261+#define A_LAST_CHANCE_TO_SEE 262+#define A_EARLY_BIRD 263+#define A_FADING_LUCK 264+#define A_ELDEER 265+#define A_DUDE_SWEET 266+#define A_SUGAR_RUSH 267+#define A_YEARS_WORTH_OF_CAVITIES 268+#define A_HAND_PICKED 269+#define A_SUGAR_SUGAR 270+#define A_ALL_NATURAL_CANE_SUGAR 271+#define A_SWEETMEATS 272+#define A_TRICENTENNIAL 273+#define A_KNEAD_FOR_SPEED 274+#define A_WELL_THE_COOKIES_START_COMING_AND_THEY_DONT_STOP_COMING 275+#define A_I_DONT_KNOW_IF_YOUVE_NOTICED_BUT_ALL_THESE_ICONS_ARE_VERY_SLIGHTLY_OFF_CENTER 276+#define A_THE_PROOF_OF_THE_COOKIE_IS_IN_THE_BAKING 277+#define A_IF_ITS_WORTH_DOING_ITS_WORTH_OVERDOING 278+#define A_THE_DREAMS_IN_WHICH_IM_BAKING_ARE_THE_BEST_IVE_EVER_HAD 279+#define A_SET_FOR_LIFE 280+#define A_YOU_AND_THE_BEANSTALK 281+#define A_ROMANCING_THE_STONE 282+#define A_EX_MACHINA 283+#define A_AND_I_NEED_IT_NOW 284+#define A_PRAY_ON_THE_WEAK 285+#define A_ITS_A_KIND_OF_MAGIC 286+#define A_MAKE_IT_SO 287+#define A_ALL_THAT_GLITTERS_IS_GOLD 288+#define A_H_E_C_O_M_E_S 289+#define A_WAY_BACK_THEN 290+#define A_EXOTIC_MATTER 291+#define A_AT_THE_END_OF_THE_TUNNEL 292+#define A_CLICK_STARRING_ADAM_SANDLER 293+#define A_FRANTIQUITIES 294+#define A_OVERGROWTH 295+#define A_SEDIMENTALISM 296+#define A_LABOR_OF_LOVE 297+#define A_REVERSE_FUNNEL_SYSTEM 298+#define A_THUS_SPOKE_YOU 299+#define A_MANAFEST_DESTINY 300+#define A_NEITHER_SNOW_NOR_RAIN_NOR_HEAT_NOR_GLOOM_OF_NIGHT 301+#define A_IVE_GOT_THE_MIDAS_TOUCH 302+#define A_WHICH_ETERNAL_LIE 303+#define A_DANDEACUTE_JANDAGRAVE_VU 304+#define A_POWERS_OF_TEN 305+#define A_NOW_THE_DARK_DAYS_ARE_GONE 306+#define A_FREAKY_JAZZ_HANDS 307+#define A_METHUSELAH 308+#define A_HUGE_TRACTS_OF_LAND 309+#define A_D_D_D_D_DEEPER 310+#define A_PATENTLY_GENIUS 311+#define A_A_CAPITAL_IDEA 312+#define A_IT_BELONGS_IN_A_BAKERY 313+#define A_MOTORMOUTH 314+#define A_BEEN_THERE_DONE_THAT 315+#define A_PHLOGISTICATED_SUBSTANCES 316+#define A_BIZARRO_WORLD 317+#define A_THE_LONG_NOW 318+#define A_CHUBBY_HADRONS 319+#define A_PALETTABLE 320+#define A_BIBBIDI_BOBBIDI_BOO 321+#define A_IM_THE_WIZ 322+#define A_A_WIZARD_IS_YOU 323+#define A_FOUR_LEAF_COOKIE 324+#define A_LUCKED_OUT 325+#define A_WHAT_ARE_THE_ODDS 326+#define A_GRANDMA_NEEDS_A_NEW_PAIR_OF_SHOES 327+#define A_MILLION_TO_ONE_SHOT_DOC 328+#define A_AS_LUCK_WOULD_HAVE_IT 329+#define A_EVER_IN_YOUR_FAVOR 330+#define A_BE_A_LADY 331+#define A_DICEY_BUSINESS 332+#define A_FINGERS_CROSSED 333+#define A_JUST_A_STATISTIC 334+#define A_MURPHYS_WILD_GUESS 335+#define A_LETS_LEAF_IT_AT_THAT 336+#define A_THE_ULTIMATE_CLICKDOWN 337+#define A_AGED_WELL 338+#define A__101ST_BIRTHDAY 339+#define A_BUT_WAIT_TIL_YOU_GET_OLDER 340+#define A_HARVEST_MOON 341+#define A_MINE 342+#define A_IN_FULL_GEAR 343+#define A_TREACLE_TART_ECONOMICS 344+#define A_HOLY_COOKIES_GRANDMA 345+#define A_THE_PRESTIGE 346+#define A_THATS_JUST_PEANUTS_TO_SPACE 347+#define A_WORTH_ITS_WEIGHT_IN_LEAD 348+#define A_WHAT_HAPPENS_IN_THE_VORTEX_STAYS_IN_THE_VORTEX 349+#define A_INVITED_TO_YESTERDAYS_PARTY 350+#define A_DOWNSIZING 351+#define A_MY_EYES 352+#define A_MAYBE_A_CHANCE_IN_HELL_ACTUALLY 353+#define A_MAKE_LIKE_A_TREE 354+#define A_CAVE_STORY 355+#define A_IN_COG_NEATO 356+#define A_SAVE_YOUR_BREATH_BECAUSE_THATS_ALL_YOUVE_GOT_LEFT 357+#define A_VENGEFUL_AND_ALMIGHTY 358+#define A_SPELL_IT_OUT_FOR_YOU 359+#define A_SPACE_SPACE_SPACE_SPACE_SPACE 360+#define A_DONT_GET_USED_TO_YOURSELF_YOURE_GONNA_HAVE_TO_CHANGE 361+#define A_OBJECTS_IN_THE_MIRROR_DIMENSION_ARE_CLOSER_THAN_THEY_APPEAR 362+#define A_GROUNDHOG_DAY 363+#define A_A_MATTER_OF_PERSPECTIVE 364+#define A_OPTICAL_ILLUSION 365+#define A_JACKPOT 366+#define A_SO_MUCH_TO_DO_SO_MUCH_TO_SEE 367+#define A_RUNNING_WITH_SCISSORS 368+#define A_RAREFIED_AIR 369+#define A_PUSH_IT_TO_THE_LIMIT 370+#define A_GREEN_COOKIES_SLEEP_FURIOUSLY 371+#define A_PANIC_AT_NABISCO 372+#define A_BURSTING_AT_THE_SEAMS 373+#define A_JUST_ABOUT_FULL 374+#define A_HUNGRY_FOR_MORE 375+#define A_ALL_THE_OTHER_KIDS_WITH_THE_PUMPED_UP_CLICKS 376+#define A_ONE_MORE_CLICK 377+#define A_BOTANY_ENTHUSIAST 378+#define A_GREEN_ACHING_THUMB 379+#define A_IN_THE_GARDEN_OF_EDEN_BABY 380+#define A_KEEPER_OF_THE_CONSERVATORY 381+#define A_SEEDLESS_TO_NAY 382+#define A_YOU_GET_NOTHING 383+#define A_HUMBLE_REBEGINNINGS 384+#define A_THE_END_OF_THE_WORLD 385+#define A_OH_YOURE_BACK 386+#define A_LAZARUS 387+#define A_LEISURELY_PACE 388+#define A_HYPERSONIC 389+#define A_FEED_ME_ORTEIL 390+#define A_AND_THEN_WHAT 391+#define A_TRICENTENNIAL_AND_A_HALF 392+#define A_QUADRICENTENNIAL 393+#define A_QUADRICENTENNIAL_AND_A_HALF 394+#define A_QUINCENTENNIAL 395+#define A_MAILLARD_REACTION 396+#define A_WHEN_THE_COOKIES_ASCEND_JUST_RIGHT 397+#define A_WITH_HER_FINGER_AND_HER_THUMB 398+#define A_DEFENSE_OF_THE_ANCIENTS 399+#define A_SHARPEST_TOOL_IN_THE_SHED 400+#define A_HEY_NOW_YOURE_A_ROCK 401+#define A_BREAK_THE_MOLD 402+#define A_GET_THE_SHOW_ON_GET_PAID 403+#define A_MY_WORLDS_ON_FIRE_HOW_ABOUT_YOURS 404+#define A_THE_METEOR_MEN_BEG_TO_DIFFER 405+#define A_ONLY_SHOOTING_STARS 406+#define A_WE_COULD_ALL_USE_A_LITTLE_CHANGE 407+#define A_YOUR_BRAIN_GETS_SMART_BUT_YOUR_HEAD_GETS_DUMB 408+#define A_THE_YEARS_START_COMING 409+#define A_WHAT_A_CONCEPT 410+#define A_YOULL_NEVER_SHINE_IF_YOU_DONT_GLOW 411+#define A_YOULL_NEVER_KNOW_IF_YOU_DONT_GO 412+#define A_SELF_CONTAINED 413+#define A_THREW_YOU_FOR_A_LOOP 414+#define A_THE_SUM_OF_ITS_PARTS 415+#define A_BEARS_REPEATING 416+#define A_MORE_OF_THE_SAME 417+#define A_LAST_RECURSE 418+#define A_OUT_OF_ONE_MANY 419+#define A_AN_EXAMPLE_OF_RECURSION 420+#define A_FOR_MORE_INFORMATION_ON_THIS_ACHIEVEMENT_PLEASE_REFER_TO_ITS_TITLE 421+#define A_IM_SO_META_EVEN_THIS_ACHIEVEMENT 422+#define A_NEVER_GET_BORED 423+#define A_THE_NEEDS_OF_THE_MANY 424+#define A_EATING_ITS_OWN 425+#define A_WE_MUST_GO_DEEPER 426+#define A_SIERPINSKI_RHOMBOIDS 427+#define A_GOTTA_GO_FAST 428+#define A_I_THINK_ITS_SAFE_TO_SAY_YOUVE_GOT_IT_MADE 429+#define A_RENAISSANCE_BAKER 430+#define A_VETERAN 431+#define A_THICK_SKINNED 432+#define A_F12 433+#define A_VARIABLE_SUCCESS 434+#define A_NO_COMMENTS 435+#define A_UP_TO_CODE 436+#define A_WORKS_ON_MY_MACHINE 437+#define A_TECHNICAL_DEBT 438+#define A_MIND_YOUR_LANGUAGE 439+#define A_INCONSOLABLE 440+#define A_CLOSURE 441+#define A_DUDE_WHAT_IF_WERE_ALL_LIVING_IN_A_SIMULATION_LIKE_WHAT_IF_WERE_ALL_JUST_CODE_ON_A_COMPUTER_SOMEWHERE 442+#define A_TAKING_THE_BACK_STREETS 443+#define A_INHERITED_PROTOTYPE 444+#define A_A_MODEL_OF_DOCUMENT_OBJECT 445+#define A_FIRST_CLASS_CITIZEN 446+#define A_ALEXANDRIA 447+#define A_BAKE_HIM_AWAY_TOYS 448+#define A_YOURE_1_SO_WHY_TRY_HARDER 449+#define A_HAVENT_EVEN_BEGUN_TO_PEAK 450+#define A_A_SOMETIMES_FOOD 451+#define A_NOT_ENOUGH_OF_A_GOOD_THING 452+#define A_HORN_OF_PLENTY 453+#define A_SMURF_ACCOUNT 454+#define A_IF_AT_FIRST_YOU_DONT_SUCCEED 455+#define A_O_FORTUNA 456+#define A_INITIAL_PUBLIC_OFFERING 457+#define A_ROOKIE_NUMBERS 458+#define A_NO_NOBILITY_IN_POVERTY 459+#define A_FULL_WAREHOUSES 460+#define A_MAKE_MY_DAY 461+#define A_BUY_BUY_BUY 462+#define A_GASEOUS_ASSETS 463+#define A_PYRAMID_SCHEME 464+#define A_JELLICLES 465+#define A_QUINCENTENNIAL_AND_A_HALF 466+#define A_WHAT_DID_WE_EVEN_EAT_BEFORE_THESE 467+#define A_HEAVY_FLOW 468+#define A_MORE_YOU_SAY 469+#define A_LARGE_AND_IN_CHARGE 470+#define A_ABSOLUTELY_STUFFED 471+#define A_ITS_ONLY_WAFER_THIN 472+#define A_CLICKETY_SPLIT 473+#define A_GOTTA_HAND_IT_TO_YOU 474+#define A_OKAY_BOOMER 475+#define A_OVERRIPE 476+#define A_ROCK_ON 477+#define A_SELF_MANMADE_MAN 478+#define A_CHECKS_OUT 479+#define A_LIVING_ON_A_PRAYER 480+#define A_HIGITUS_FIGITUS_MIGITUS_MUM 481+#define A_THE_INCREDIBLE_JOURNEY 482+#define A_JUST_A_PHASE 483+#define A_DONT_LET_ME_LEAVE_MURPH 484+#define A_CAVEMAN_TO_COSMOS 485+#define A_PARTICULAR_TASTES 486+#define A_A_LIGHT_SNACK 487+#define A_TEMPTING_FATE 488+#define A_TAUTOLOGICAL 489+#define A_CURLY_BRACES 490+#define A_SEVEN_HORSESHOES 491+#define A_OLDEN_DAYS 492+#define A_THE_DEVILS_WORKSHOP 493+#define A_IN_THE_GREEN 494+#define A_MOUNTAIN_OUT_OF_A_MOLEHILL_BUT_LIKE_IN_A_GOOD_WAY 495+#define A_THE_WHEELS_OF_PROGRESS 496+#define A_THATS_RICH 497+#define A_PREACHES_AND_CREAM 498+#define A_MAGIC_THINKING 499+#define A_IS_THERE_LIFE_ON_MARS 500+#define A_BAD_CHEMISTRY 501+#define A_REDUCED_TO_GIBBERING_HEAPS 502+#define A_BACK_ALREADY 503+#define A_NUCLEAR_THRONE 504+#define A_MAKING_LIGHT_OF_THE_SITUATION 505+#define A_FLIP_A_COOKIE_CHIPS_I_WIN_CRUST_YOU_LOSE 506+#define A_IN_AND_OF_ITSELF 507+#define A_DUCK_TYPING 508+#define A_THEYLL_NEVER_KNOW_WHAT_HIT_EM 509+#define A_WELL_VERSED 510+#define A_RIPE_FOR_THE_PICKING 511+#define A_UNREAL 512+#define A_ONCE_YOUVE_SEEN_ONE 513+#define A_SPOILS_AND_PLUNDER 514+#define A_NOBODY_EXISTS_ON_PURPOSE_NOBODY_BELONGS_ANYWHERE 515+#define A_HYPERSPACE_EXPRESSWAY 516+#define A_VERSATILE 517+#define A_YOU_ARE_INEVITABLE 518+#define A_AWAY_FROM_THIS_PLACE 519+#define A_EVERYWHERE_AT_ONCE 520+#define A_REJECT_REALITY_SUBSTITUTE_YOUR_OWN 521+#define A_FRINGE 522+#define A_COHERENCE 523+#define A_EARTH_616 524+#define A_STRANGE_TOPOLOGIES 525+#define A_GRAND_DESIGN 526+#define A_ECUMENOPOLIS 527+#define A_THE_FULL_PICTURE 528+#define A_WHEN_THERES_NOTHING_LEFT_TO_ADD 529+#define A_SEXCENTENNIAL 530+#define A_KEEP_GOING_UNTIL_I_SAY_STOP 531+#define A_BUT_I_DIDNT_SAY_STOP_DID_I 532+#define A_WITH_UNRIVALED_FERVOR 533+#define A_THINK_BIG 534+#define A_HYPERSIZE_ME 535+#define A_MAX_CAPACITY 536+#define A_LIQUID_ASSETS 537+#define A_STIFLING_THE_PRESS 538+#define A_ITS_BIG_BRAIN_TIME 539+#define A_JUST_MY_IMAGINATION 540+#define A_NOW_THERES_AN_IDEA 541+#define A_THE_ORGAN_THAT_NAMED_ITSELF 542+#define A_GYRIFICATION 543+#define A_A_TRADEMARKED_PORTMANTEAU_OF_IMAGINATION_AND_ENGINEERING 544+#define A_MINDFULNESS 545+#define A_THE_10_MYTH 546+#define A_DONT_THINK_ABOUT_IT_TOO_HARD 547+#define A_THOUGH_FOOLS_SELDOM_DIFFER 548+#define A_LOOKING_KIND_OF_DUMB 549+#define A_A_BEAUTIFUL_MIND 550+#define A_CARDINAL_SYNAPSES 551+#define A_POSITIVE_THINKING 552+#define A_THE_THOUGHT_THAT_COUNTS 553+#define A_UNTHINKABLE 554+#define A_GIFTED 555+#define A_THEY_MOISTLY_COME_AT_NIGHT 556+#define A_ITS_GROWN_ON_YOU 557+#define A_DONT_LET_THE_WALLS_CAVE_IN_ON_YOU 558+#define A_REPLACED_BY_ROBOTS 559+#define A_FINANCIAL_PRODIGY 560+#define A_AND_I_WILL_PRAY_TO_A_BIG_GOD 561+#define A_SHOSPLE_COLUPIS 562+#define A_FALSE_VACUUM 563+#define A_METALLIC_TASTE 564+#define A_SWISS_CHEESE 565+#define A_BUT_THE_FUTURE_REFUSED_TO_CHANGE 566+#define A_WHATS_THE_DARK_MATTER_WITH_YOU 567+#define A_ENLIGHTENMENT 568+#define A_NEVER_TELL_ME_THE_ODDS 569+#define A_BLOWING_AN_APOLLONIAN_GASKET 570+#define A_GET_WITH_THE_PROGRAM 571+#define A_LOST_YOUR_COSMIC_MARBLES 572+#define A_BY_WILL_ALONE_I_SET_MY_MIND_IN_MOTION 573+#define A_AINT_THAT_A_CLICK_IN_THE_HEAD 574+#define A_SEXCENTENNIAL_AND_A_HALF 575+#define A_I_AM_SPEED 576+#define A_AND_ON_AND_ON 577+#define A_FAKE_IT_TILL_YOU_BAKE_IT 578+#define A_HISTORY_IN_THE_BAKING 579+#define A_BABY_ITS_OLD_OUTSIDE 580+#define A_MYRIAD 581+#define A_KAIZEN 582+#define A_BEYOND_QUALITY 583+#define A_EVERYTHING_HAPPENS_SO_MUCH 584+#define A_ILL_REST_WHEN_IM_DEAD 585+#define A_WHAT_DO_YOU_GET_FOR_THE_BAKER_WHO_HAS_EVERYTHING 586+#define A_BOTTOMLESS_PIT 587+#define A_ALL_THE_STARS_IN_HEAVEN 588+#define A_NO_TIME_LIKE_THE_PRESENT 589+#define A_CAN_WE_GET_MUCH_HIGHER 590+#define A_SPEEDS_THE_NAME_OF_THE_GAME_NO_ITS_NOT_ITS_CALLED_COOKIE_CLICKER 591+#define A_RAINY_DAY_FUND 592+#define A_AND_A_LITTLE_EXTRA 593+#define A_GRANDMAPOCALYPSE 594+#define A_WRATH_COOKIE 595+#define A_NO_MORE_ROOM_IN_HELL 596+#define A_IN_HER_LIKENESS 597+#define A_WRINKLER_POKER 598+#define A_SEPTCENTENNIAL 599+#define A_MY_OWN_CLONE 600+#define A_MULTIPLICITY 601+#define A_BORN_FOR_THIS_JOB 602+#define A_EPISODE_II 603+#define A_COPY_THAT 604+#define A_LIFE_FINDS_A_WAY 605+#define A_OVERCROWDING 606+#define A_STRENGTH_IN_NUMBERS 607+#define A_ARMY_OF_ME 608+#define A_KNOW_THYSELF 609+#define A_DIDNT_MAKE_SENSE_NOT_TO_LIVE 610+#define A_GENETIC_BOTTLENECK 611+#define A_DESPITE_EVERYTHING_ITS_STILL_YOU 612+#define A_EVERYONE_EVERYWHERE_ALL_AT_ONCE 613+#define A_SELF_MADE 614+#define A_REPRODUCIBLE_RESULTS 615+#define A_THATS_ALL_YOU 616+#define A_SELF_IMPROVEMENT 617+#define A_AND_NOW_YOURE_EVEN_OLDER 618+#define A_AU_NATUREL 619+#define A_DIRT_RICH 620+#define A_BOTS_BUILD_BOTS 621+#define A_GETTING_THAT_BAG 622+#define A_THE_LEADER_IS_GOOD_THE_LEADER_IS_GREAT 623+#define A_YOU_DONT_THINK_THEY_COULDVE_USED_IT_COULDNT_HAVE_BEEN_MA 624+#define A_SIGNED_SEALED_DELIVERED 625+#define A_SUGAR_SPICE_AND_EVERYTHING_NICE 626+#define A_NOT_EVEN_REMOTELY_CLOSE_TO_KANSAS_ANYMORE 627+#define A_I_ONLY_MEANT_TO_STAY_A_WHILE 628+#define A_NOT_20_YEARS_AWAY_FOREVER 629+#define A_BRIGHT_SIDE_OF_THE_MOON 630+#define A_RIDING_THE_MERSENNE_TWISTER 631+#define A_DIVIDE_AND_CONQUER 632+#define A_PEBCAKES 633+#define A_GREENER_ON_THE_OTHER_SIDES 634+#define A_WHERE_IS_MY_MIND 635+#define A_INTROSPECTION 636+#define A_DEBT_EVASION 637+#define A_OFT_WE_MAR_WHATS_WELL 638+#define A_COOKIE_CLICKER 639+#define A_WHATS_NOT_CLICKING 640+#define A_ALL_ON_DECK 641+#define A_A_ROUND_OF_APPLAUSE 642+#define N_MILKS 25+#define OFF_MILKS 1518116+#define OFF_BUILDING_LINKS 1518320+#define OFF_TIER_UNSHACKLE 1520880+#define N_TIER_UNSHACKLE 18+#define OFF_COOKIE_UPGRADES 1520916+#define N_COOKIE_UPGRADES 248+#define OFF_GRANDMA_SYNERGIES 1521412+#define N_GRANDMA_SYNERGIES 18+#define OFF_KITTENS 1521448+#define N_KITTENS 18+#define OFF_GOLDEN_UPGRADES 1521484+#define N_GOLDEN_UPGRADES 10+#define OFF_LASTING 1521504+#define N_LASTING 8+#define OFF_NO_PERM 1521520+#define N_NO_PERM 6+#define OFF_HEAVENLY 1521532+#define N_HEAVENLY 129+#define OFF_EASTER_EGGS 1521792+#define N_EASTER_EGGS 20+#define OFF_HALLOWEEN_DROPS 1521832+#define N_HALLOWEEN_DROPS 7+#define OFF_HEART_DROPS 1521848+#define N_HEART_DROPS 7+#define OFF_SANTA_DROPS 1521864+#define N_SANTA_DROPS 14+#define OFF_REINDEER_DROPS 1521892+#define N_REINDEER_DROPS 7+#define OFF_FORTUNES 1521908+#define N_FORTUNES 25+#define OFF_SHOW_IF 1521960+#define N_SHOW_IF 3+#define OFF_CONFIRM 1521968+#define N_CONFIRM 6+#define OFF_BANK_ACHIEVS 1521984+#define N_BANK_ACHIEVS 48+#define OFF_CPS_ACHIEVS 1522752+#define N_CPS_ACHIEVS 48+#define OFF_UNLOCK_AT 1523520+#define N_UNLOCK_AT 213+#define OFF_TEXT 1528632+#define OFF_IMAGES 1715284+#define N_IMAGES 1524+#define IM_COOKIE 0+#define IM_COOKIE_SHADOW 1+#define IM_FLARE 2+#define IM_FLARE_GOLD 3+#define IM_FLARE_RED 4+#define IM_GLINT 5+#define IM_BG_BLUE 6+#define IM_BG_GRANDMAS1 7+#define IM_BG_GRANDMAS2 8+#define IM_BG_GRANDMAS3 9+#define IM_BORDER_SOFT 10+#define IM_BORDER_GOLD 11+#define IM_BORDER_RED 12+#define IM_SHOWER1 13+#define IM_SHOWER2 14+#define IM_SHOWER3 15+#define IM_SMALL_COOKIE0 16+#define IM_SMALL_COOKIE1 17+#define IM_SMALL_COOKIE2 18+#define IM_SMALL_COOKIE3 19+#define IM_SMALL_COOKIE4 20+#define IM_SMALL_COOKIE5 21+#define IM_SMALL_COOKIE6 22+#define IM_SMALL_COOKIE7 23+#define IM_CURSOR 24+#define IM_GOLD_COOKIE 25+#define IM_WRATH_COOKIE 26+#define IM_MILK_PLAIN 27+#define IM_MILK_CHOCOLATE 28+#define IM_MILK_RASPBERRY 29+#define IM_MILK_ORANGE 30+#define IM_MILK_CARAMEL 31+#define IM_MILK_BANANA 32+#define IM_MILK_LIME 33+#define IM_MILK_BLUEBERRY 34+#define IM_MILK_STRAWBERRY 35+#define IM_MILK_VANILLA 36+#define IM_MILK_HONEY 37+#define IM_MILK_COFFEE 38+#define IM_MILK_TEA 39+#define IM_MILK_COCONUT 40+#define IM_MILK_CHERRY 41+#define IM_MILK_SPICED 42+#define IM_MILK_MAPLE 43+#define IM_MILK_MINT 44+#define IM_MILK_LICORICE 45+#define IM_MILK_ROSE 46+#define IM_MILK_DRAGONFRUIT 47+#define IM_MILK_MELON 48+#define IM_MILK_BLACKCURRANT 49+#define IM_MILK_PEACH 50+#define IM_MILK_HAZELNUT 51+#define IM_WRINKLER 52+#define IM_SHINY_WRINKLER 53+#define IM_SHIMMERING_VEIL 54+#define IM_DRAGON_BG 55+#define IM_BROKEN_COOKIE0 56+#define IM_BROKEN_COOKIE1 57+#define IM_BROKEN_COOKIE2 58+#define IM_BROKEN_COOKIE3 59+#define IM_BROKEN_COOKIE4 60+#define IM_BROKEN_COOKIE5 61+#define IM_BROKEN_COOKIE6 62+#define IM_BROKEN_COOKIE7 63+#define IM_BROKEN_COOKIE8 64+#define IM_BROKEN_COOKIE9 65+#define IM_BROKEN_HALO 66+#define IM_SHINE_SPOKE 67+#define IM_HEAVEN_RING1 68+#define IM_HEAVEN_RING2 69+#define IM_STARS 70+#define IM_STORE_TILE0 71+#define IM_STORE_TILE1 72+#define IM_STORE_TILE2 73+#define IM_STORE_TILE3 74+#define IM_UPGRADE_FRAME 75+#define IM_MONEY 76+#define IM_HEAVENLY_MONEY 77+#define IM_LUMP_MONEY 78+#define IM_PANEL_V 79+#define IM_PANEL_H 80+#define IM_DARK_NOISE 81+#define IM_BUILD_CURSOR 82+#define IM_BUILD_CURSOR_OFF 83+#define IM_BUILD_GRANDMA 84+#define IM_BUILD_GRANDMA_OFF 85+#define IM_BUILD_FARM 86+#define IM_BUILD_FARM_OFF 87+#define IM_BUILD_MINE 88+#define IM_BUILD_MINE_OFF 89+#define IM_BUILD_FACTORY 90+#define IM_BUILD_FACTORY_OFF 91+#define IM_BUILD_BANK 92+#define IM_BUILD_BANK_OFF 93+#define IM_BUILD_TEMPLE 94+#define IM_BUILD_TEMPLE_OFF 95+#define IM_BUILD_WIZARD_TOWER 96+#define IM_BUILD_WIZARD_TOWER_OFF 97+#define IM_BUILD_SHIPMENT 98+#define IM_BUILD_SHIPMENT_OFF 99+#define IM_BUILD_ALCHEMY_LAB 100+#define IM_BUILD_ALCHEMY_LAB_OFF 101+#define IM_BUILD_PORTAL 102+#define IM_BUILD_PORTAL_OFF 103+#define IM_BUILD_TIME_MACHINE 104+#define IM_BUILD_TIME_MACHINE_OFF 105+#define IM_BUILD_ANTIMATTER_CONDENSER 106+#define IM_BUILD_ANTIMATTER_CONDENSER_OFF 107+#define IM_BUILD_PRISM 108+#define IM_BUILD_PRISM_OFF 109+#define IM_BUILD_CHANCEMAKER 110+#define IM_BUILD_CHANCEMAKER_OFF 111+#define IM_BUILD_FRACTAL_ENGINE 112+#define IM_BUILD_FRACTAL_ENGINE_OFF 113+#define IM_BUILD_JAVASCRIPT_CONSOLE 114+#define IM_BUILD_JAVASCRIPT_CONSOLE_OFF 115+#define IM_BUILD_IDLEVERSE 116+#define IM_BUILD_IDLEVERSE_OFF 117+#define IM_BUILD_CORTEX_BAKER 118+#define IM_BUILD_CORTEX_BAKER_OFF 119+#define IM_BUILD_YOU 120+#define IM_BUILD_YOU_OFF 121+#define IM_ROW_BG_GRANDMA 122+#define IM_ROW_GRANDMA 123+#define IM_ROW_BG_FARM 124+#define IM_ROW_FARM 125+#define IM_ROW_BG_MINE 126+#define IM_ROW_MINE 127+#define IM_ROW_BG_FACTORY 128+#define IM_ROW_FACTORY 129+#define IM_ROW_BG_BANK 130+#define IM_ROW_BANK 131+#define IM_ROW_BG_TEMPLE 132+#define IM_ROW_TEMPLE 133+#define IM_ROW_BG_WIZARDTOWER 134+#define IM_ROW_WIZARDTOWER 135+#define IM_ROW_BG_SHIPMENT 136+#define IM_ROW_SHIPMENT 137+#define IM_ROW_BG_ALCHEMYLAB 138+#define IM_ROW_ALCHEMYLAB 139+#define IM_ROW_BG_PORTAL 140+#define IM_ROW_PORTAL 141+#define IM_ROW_BG_TIMEMACHINE 142+#define IM_ROW_TIMEMACHINE 143+#define IM_ROW_BG_ANTIMATTERCONDENSER 144+#define IM_ROW_ANTIMATTERCONDENSER 145+#define IM_ROW_BG_PRISM 146+#define IM_ROW_PRISM 147+#define IM_ROW_BG_CHANCEMAKER 148+#define IM_ROW_CHANCEMAKER 149+#define IM_ROW_BG_FRACTALENGINE 150+#define IM_ROW_FRACTALENGINE 151+#define IM_ROW_BG_JAVASCRIPTCONSOLE 152+#define IM_ROW_JAVASCRIPTCONSOLE0 153+#define IM_ROW_JAVASCRIPTCONSOLE1 154+#define IM_ROW_BG_IDLEVERSE 155+#define IM_ROW_IDLEVERSE0 156+#define IM_ROW_IDLEVERSE1 157+#define IM_ROW_IDLEVERSE2 158+#define IM_ROW_IDLEVERSE3 159+#define IM_ROW_BG_CORTEX 160+#define IM_ROW_CORTEX0 161+#define IM_ROW_CORTEX1 162+#define IM_ROW_CORTEX2 163+#define IM_ROW_CORTEX3 164+#define IM_ROW_BG_YOU 165+#define IM_ROW_YOU 166+#define IM_ROW_FARMERGRANDMA 167+#define IM_ROW_WORKERGRANDMA 168+#define IM_ROW_MINERGRANDMA 169+#define IM_ROW_COSMICGRANDMA 170+#define IM_ROW_TRANSMUTEDGRANDMA 171+#define IM_ROW_ALTEREDGRANDMA 172+#define IM_ROW_GRANDMASGRANDMA 173+#define IM_ROW_ANTIGRANDMA 174+#define IM_ROW_RAINBOWGRANDMA 175+#define IM_ROW_BANKGRANDMA 176+#define IM_ROW_TEMPLEGRANDMA 177+#define IM_ROW_WITCHGRANDMA 178+#define IM_ROW_LUCKYGRANDMA 179+#define IM_ROW_METAGRANDMA 180+#define IM_ROW_SCRIPTGRANDMA 181+#define IM_ROW_ALTERNATEGRANDMA 182+#define IM_ROW_BRAINYGRANDMA 183+#define IM_ROW_CLONEGRANDMA 184+#define IM_ROW_ELFGRANDMA 185+#define IM_ROW_BUNNYGRANDMA 186+#define IM_MG_BG_GRIMOIRE 187+#define IM_MG_BG_PANTHEON 188+#define IM_MG_BG_GARDEN 189+#define IM_MG_BG_MARKET 190+#define IM_DRAGON0 191+#define IM_DRAGON1 192+#define IM_DRAGON2 193+#define IM_DRAGON3 194+#define IM_DRAGON4 195+#define IM_DRAGON5 196+#define IM_DRAGON6 197+#define IM_DRAGON7 198+#define IM_DRAGON8 199+#define IM_SANTA0 200+#define IM_SANTA1 201+#define IM_SANTA2 202+#define IM_SANTA3 203+#define IM_SANTA4 204+#define IM_SANTA5 205+#define IM_SANTA6 206+#define IM_SANTA7 207+#define IM_SANTA8 208+#define IM_SANTA9 209+#define IM_SANTA10 210+#define IM_SANTA11 211+#define IM_SANTA12 212+#define IM_SANTA13 213+#define IM_SANTA14 214+#define IM_SPELL_BG 215+#define IM_ASCEND_SLOT0 216+#define IM_ASCEND_SLOT1 217+#define IM_ASCEND_SLOT2 218+#define IM_REINDEER 219+#define IM_GOLD_WREATH 220+#define IM_WRATH_WREATH 221+#define IM_HEART0_0 222+#define IM_HEART0_1 223+#define IM_HEART0_2 224+#define IM_HEART0_3 225+#define IM_HEART0_4 226+#define IM_HEART0_5 227+#define IM_HEART0_6 228+#define IM_HEART0_7 229+#define IM_HEART1_0 230+#define IM_HEART1_1 231+#define IM_HEART1_2 232+#define IM_HEART1_3 233+#define IM_HEART1_4 234+#define IM_HEART1_5 235+#define IM_HEART1_6 236+#define IM_HEART1_7 237+#define IM_BUNNY0_0 238+#define IM_BUNNY0_1 239+#define IM_BUNNY0_2 240+#define IM_BUNNY0_3 241+#define IM_BUNNY1_0 242+#define IM_BUNNY1_1 243+#define IM_BUNNY1_2 244+#define IM_BUNNY1_3 245+#define IM_FAMILIAR0_0 246+#define IM_FAMILIAR0_1 247+#define IM_FAMILIAR0_2 248+#define IM_FAMILIAR0_3 249+#define IM_FAMILIAR1_0 250+#define IM_FAMILIAR1_1 251+#define IM_FAMILIAR1_2 252+#define IM_FAMILIAR1_3 253+#define DATA_SIZE 1739668++#endifdiff --git a/games/cookieclicker/src/elder.c b/games/cookieclicker/src/elder.cnew file mode 100644index 00000000..b2703369--- /dev/null+++ b/games/cookieclicker/src/elder.c@@ -0,0 +1,183 @@+/* The grandmapocalypse and its wrinklers (the game's UpdateGrandmapocalypse, UpdateWrinklers): the+ * elders' wrath grows with the research, the pledge holds it back for a while, the covenant for good;+ * wrinklers come to the big cookie and eat a twentieth of its production each, and give it back,+ * and more, when popped. Var hits them (three times to pop one), the fullest first. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"++#define WRINKLER_HP 2.1f+#define WRINKLER_LIMIT 14+float elder_wrath_d = 1;++int wrinklers_max(void) {+ int n = 10;+ if (has(U_ELDER_SPICE)) n += 2;+ n += (int)roundf(aura_mult(AURA_DRAGON_GUTS) * 2);+ return n < WRINKLER_LIMIT ? n : WRINKLER_LIMIT;+}+void collect_wrinklers(void) {+ for (int i = 0; i < MAX_WRINKLERS; i++) S.wrinklers[i].hp = 0;+}+float wrinkler_eat_eff(void) {+ extern float minigame_eff(int which);+ return minigame_eff(1);+}++void update_grandmapocalypse(void) {+ if (has(U_ELDER_COVENANT) || S.buildings[B_GRANDMA].amount == 0) S.elder_wrath = 0;+ else if (S.pledge_t > 0) {+ S.pledge_t--;+ if (S.pledge_t == 0) lock(U_ELDER_PLEDGE), unlock(U_ELDER_PLEDGE), S.elder_wrath = 1;+ } else {+ if (has(U_ONE_MIND) && S.elder_wrath == 0) S.elder_wrath = 1;+ if (rnd() < 0.001 && S.elder_wrath < has(U_ONE_MIND) + has(U_COMMUNAL_BRAINSWEEP) + has(U_ELDER_PACT)) S.elder_wrath++;+ if (has(U_ELDER_PACT) && !has_unlocked(U_ELDER_PLEDGE)) lock(U_ELDER_PLEDGE), unlock(U_ELDER_PLEDGE);+ }+ static int old = -1;+ elder_wrath_d += ((S.elder_wrath + 1) - elder_wrath_d) * 0.001f;+ if (S.elder_wrath != old) G.store_dirty = true;+ old = S.elder_wrath;+}++static void spawn(Wrinkler *w) {+ w->phase = 1, w->hp = WRINKLER_HP, w->type = 0, w->clicks = 0;+ if (rnd() < 0.0001) w->type = 1; /* a shiny one */+}++/* the Grimoire's Resurrect Abomination, and its backfire */+bool spawn_wrinkler(void) {+ int max = wrinklers_max(), n = 0;+ for (int i = 0; i < MAX_WRINKLERS; i++) n += S.wrinklers[i].phase > 0;+ for (int i = 0; i < MAX_WRINKLERS && i < max; i++)+ if (S.wrinklers[i].phase == 0 && S.elder_wrath > 0 && n < max) {+ spawn(&S.wrinklers[i]);+ return true;+ }+ return false;+}+bool pop_random_wrinkler(void) {+ Wrinkler *list[MAX_WRINKLERS];+ int n = 0;+ for (int i = 0; i < MAX_WRINKLERS; i++)+ if (S.wrinklers[i].phase > 0 && S.wrinklers[i].hp > 0) list[n++] = &S.wrinklers[i];+ if (!n) return false;+ list[rnd_int(n)]->hp = -10;+ return true;+}++/* var: a click on the wrinkler that ate the most */+void wrinkler_hit(void) {+ Wrinkler *best = NULL;+ for (int i = 0; i < MAX_WRINKLERS; i++) {+ Wrinkler *w = &S.wrinklers[i];+ if (w->phase > 0 && w->hp > 0 && (!best || w->sucked > best->sucked)) best = w;+ }+ if (!best) return;+ best->clicks++;+ if (best->clicks >= 50) win(A_WRINKLER_POKER);+ best->hurt = 1;+ best->hp -= 0.75f;+ for (int i = 0; i < MAX_WRINKLERS; i++) S.wrinklers[i].selected = &S.wrinklers[i] == best;+}++static void pop(Wrinkler *w) {+ S.wrinklers_popped++;+ G.recalculate = true;+ w->phase = 0, w->close = 0, w->hurt = 0;+ w->hp = WRINKLER_HP * (w->type == 1 ? 3 : 1);+ double to_suck = 1.1;+ if (has(U_SACRILEGIOUS_CORRUPTION)) to_suck *= 1.05;+ to_suck *= 1 + aura_mult(AURA_DRAGON_GUTS) * 0.2;+ if (w->type == 1) to_suck *= 3;+ w->sucked *= to_suck;+ if (has(U_WRINKLERSPAWN)) w->sucked *= 1.05;+ static const float scorn[4] = {1, 1.15f, 1.1f, 1.05f};+ w->sucked *= scorn[hasgod(GOD_SCORN)];+ if (w->sucked > 0.5) {+ char t[48], d[96];+ cookies_str(w->sucked, 0, t);+ snprintf(d, sizeof d, "Found \x01%s\x02!", t);+ notify(w->type == 1 ? "Exploded a shiny wrinkler" : "Exploded a wrinkler", d, ICON(19, 8), 6);+ snprintf(d, sizeof d, "+%s!", t);+ popup(d, w->x, w->y);+ if (!has_unlocked(U_WRINKLER_AMBERGRIS) && rnd() < 1.0 / (w->type == 1 ? 1000 : 10000)) {+ unlock(U_WRINKLER_AMBERGRIS);+ snprintf(d, sizeof d, "You also found \x01%s\x02!", res_text(upgrade_rec(U_WRINKLER_AMBERGRIS)->name));+ notify(res_text(upgrade_rec(U_WRINKLER_AMBERGRIS)->name), d, upgrade_rec(U_WRINKLER_AMBERGRIS)->icon, 0);+ }+ if (S.season == SEASON_HALLOWEEN) {+ double fail = 0.95;+ if (has_achiev(A_SPOOKY_COOKIES)) fail *= 0.8;+ if (has(U_STARTERROR)) fail *= 0.9;+ static const float sg[4] = {1, 0.9f, 0.95f, 0.97f};+ fail *= sg[hasgod(GOD_SEASONS)];+ if (w->type == 1) fail *= 0.9;+ fail = pow(fail, drop_rate_mult());+ if (rnd() > fail) {+ static const uint16_t c[7] = {U_SKULL_COOKIES, U_GHOST_COOKIES, U_BAT_COOKIES, U_SLIME_COOKIES,+ U_PUMPKIN_COOKIES, U_EYEBALL_COOKIES, U_SPIDER_COOKIES};+ int u = c[rnd_int(7)];+ if (!has_unlocked(u) && !has(u)) {+ unlock(u);+ snprintf(d, sizeof d, "You also found \x01%s\x02!", res_text(upgrade_rec(u)->name));+ notify(res_text(upgrade_rec(u)->name), d, upgrade_rec(u)->icon, 0);+ }+ }+ }+ extern void drop_egg(double failrate);+ drop_egg(0.98);+ }+ if (w->type == 1) win(A_LAST_CHANCE_TO_SEE);+ earn(w->sucked);+ if (S.prefs.particles && w->sucked > 0)+ for (int k = 0; k < 5; k++)+ particle_add(w->x, w->y, (float)(rnd() * 4 - 2), (float)(rnd() * -2 - 2), (float)(rnd() * 0.5 + 0.75), 1, 2);+ w->sucked = 0;+}++void wrinklers_update(void) {+ float T = G.real_t;+ int max = wrinklers_max(), n = 0;+ for (int i = 0; i < MAX_WRINKLERS; i++) n += S.wrinklers[i].phase > 0;+ for (int i = 0; i < MAX_WRINKLERS; i++) {+ Wrinkler *w = &S.wrinklers[i];+ if (w->phase == 0 && S.elder_wrath > 0 && n < max && i < max) {+ double chance = 0.00001 * S.elder_wrath;+ extern float minigame_eff(int which);+ chance *= minigame_eff(2);+ if (has(U_UNHOLY_BAIT)) chance *= 5;+ static const float scorn[4] = {1, 2.5f, 2, 1.5f};+ chance *= scorn[hasgod(GOD_SCORN)];+ if (has(U_WRINKLER_DOORMAT)) chance = 0.1;+ if (rnd() < chance) spawn(w), n++;+ }+ if (w->phase > 0) {+ if (w->close < 1) w->close += 1.f / FPS / 10;+ if (w->close > 1) w->close = 1;+ if (i >= max) w->hp = 0;+ } else+ w->close = 0;+ if (w->close == 1 && w->phase == 1) w->phase = 2, G.recalculate = true;+ if (w->phase == 2) w->sucked += G.cookies_ps / FPS * G.cps_sucked;+ if (w->phase > 0) {+ float top = WRINKLER_HP * (w->type == 1 ? 3 : 1);+ if (w->hp < top) w->hp += 0.04f;+ if (w->hp > top) w->hp = top;+ float d = 128 * 0.37f * (2 - w->close);+ if (S.prefs.fancy) d += cosf(T * 0.05f + i) * 4 * 0.37f;+ w->r = (float)i / max * 360;+ if (S.prefs.fancy) w->r += sinf(T * 0.05f + i) * 4;+ w->x = COOKIE_X + sinf(w->r * (float)M_PI / 180) * d;+ w->y = COOKIE_Y + cosf(w->r * (float)M_PI / 180) * d;+ if (S.prefs.fancy) w->r += sinf(T * 0.09f + i) * 4;+ if (rnd() < 0.01 && !S.prefs.not_scary) w->hurt = w->hurt > (float)rnd() ? w->hurt : (float)rnd();+ }+ if (w->hurt > 0) {+ w->hurt -= 5.f / FPS;+ w->r += sinf(T) * w->hurt * 18;+ }+ if (w->hp <= 0.5f && w->phase > 0) pop(w);+ }+}diff --git a/games/cookieclicker/src/game.c b/games/cookieclicker/src/game.cnew file mode 100644index 00000000..e1c95bd5--- /dev/null+++ b/games/cookieclicker/src/game.c@@ -0,0 +1,348 @@+/* The game's frame (Game.Logic) and its checks every 5 seconds, the buildings' buyFunctions, a new+ * game. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"++#define SPECIAL_GRANDMA_UNLOCK 15++static void unlock_tiered(int b) {+ const BuildingLinks *l = building_links(b);+ int amount = S.buildings[b].amount;+ for (int t = 0; t < N_TIERS; t++) {+ const TierRec *tr = tier_rec(t);+ if (l->tiered[t] != NONE && tr->unlock != -1 && amount >= tr->unlock) unlock(l->tiered[t]);+ if (l->tiered_ach[t] != NONE && amount >= tr->achiev_unlock) win(l->tiered_ach[t]);+ }+ for (int i = 0; i < 6 && l->synergies[i] != NONE; i++) {+ const UpgradeRec *s = upgrade_rec(l->synergies[i]);+ const TierRec *tr = tier_rec(s->tier);+ if (tr->req != NONE && has(tr->req) && S.buildings[s->building].amount >= tr->unlock &&+ S.buildings[s->building2].amount >= tr->unlock)+ unlock(l->synergies[i]);+ }+}++void building_bought(int b) {+ unlock_tiered(b);+ int n = S.buildings[b].amount;+ if (b == B_CURSOR) {+ static const struct { int16_t at; uint16_t u; } ups[] = {+ {1, U_REINFORCED_INDEX_FINGER}, {1, U_CARPAL_TUNNEL_PREVENTION_CREAM}, {10, U_AMBIDEXTROUS},+ {25, U_THOUSAND_FINGERS}, {50, U_MILLION_FINGERS}, {100, U_BILLION_FINGERS}, {150, U_TRILLION_FINGERS},+ {200, U_QUADRILLION_FINGERS}, {250, U_QUINTILLION_FINGERS}, {300, U_SEXTILLION_FINGERS},+ {350, U_SEPTILLION_FINGERS}, {400, U_OCTILLION_FINGERS}, {450, U_NONILLION_FINGERS},+ {500, U_DECILLION_FINGERS}, {550, U_UNDECILLION_FINGERS}};+ for (unsigned i = 0; i < sizeof ups / sizeof ups[0]; i++)+ if (n >= ups[i].at) unlock(ups[i].u);+ static const struct { int16_t at; uint16_t a; } wins[] = {+ {1, A_CLICK}, {2, A_DOUBLE_CLICK}, {50, A_MOUSE_WHEEL}, {100, A_OF_MICE_AND_MEN}, {200, A_THE_DIGITAL},+ {300, A_EXTREME_POLYDACTYLY}, {400, A_DR_T}, {500, A_THUMBS_PHALANGES_METACARPALS},+ {600, A_WITH_HER_FINGER_AND_HER_THUMB}, {700, A_GOTTA_HAND_IT_TO_YOU}, {800, A_THE_DEVILS_WORKSHOP},+ {900, A_ALL_ON_DECK}, {1000, A_A_ROUND_OF_APPLAUSE}};+ for (unsigned i = 0; i < sizeof wins / sizeof wins[0]; i++)+ if (n >= wins[i].at) win(wins[i].a);+ } else if (b != B_GRANDMA) {+ uint16_t g = building_links(b)->grandma;+ if (n >= SPECIAL_GRANDMA_UNLOCK && S.buildings[B_GRANDMA].amount > 0 && g != NONE) unlock(g);+ }+}++/* ------------------------------------------------------------------ a new game */+extern void shimmers_reset(void);+extern void lumps_new(void);+void game_new(void) {+ uint32_t seed = G.seed;+ memset(&G, 0, sizeof G);+ G.seed = seed ? seed : 0x2545F491u;+ 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.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;+ shimmers_reset();+ lumps_new();+ G.buy_mode = 1, G.buy_bulk = 1;+ G.recalculate = true, G.upgrades_dirty = true, G.store_dirty = true;+ G.big_size = 1, G.big_size_t = 1;+ for (int i = 0; i < MAX_PARTICLES; i++) G.particles[i].life = -1;+ for (int i = 0; i < MAX_TEXT_PARTICLES; i++) G.texts[i].life = -1;+}++/* the counts kept from the saved bits */+void game_recount(void) {+ G.achievements_owned = G.upgrades_owned = G.buildings_owned = 0;+ for (int a = 0; a < N_ACHIEVS; a++)+ if (has_achiev(a) && achiev_rec(a)->pool == APOOL_NORMAL) G.achievements_owned++;+ for (int u = 0; u < N_UPGRADES; u++)+ if (bit_get(S.upgrades_bought, u) && counts_as_upgrade_owned(u)) G.upgrades_owned++;+ for (int b = 0; b < NB; b++) G.buildings_owned += S.buildings[b].amount;+ G.milk_progress = G.achievements_owned / 25.f;+}++/* ------------------------------------------------------------------ the checks every 5 seconds */+void game_check(void) {+ if (isnan(S.cookies)) S.cookies = 0, S.cookies_earned = 0, G.recalculate = true;+ double time_played = S.play_time - S.start_date;+ if (S.play_time - S.full_date >= 365.0 * 24 * 60 * 60 * 1000) win(A_SO_MUCH_TO_DO_SO_MUCH_TO_SEE);+ if (S.cookies_earned >= 1000000 && (S.ascension_mode == 1 || S.resets == 0)) {+ if (time_played <= 1000 * 60 * 35) win(A_SPEED_BAKING_I);+ if (time_played <= 1000 * 60 * 25) win(A_SPEED_BAKING_II);+ if (time_played <= 1000 * 60 * 15) win(A_SPEED_BAKING_III);+ if (S.cookie_clicks <= 15) win(A_NEVERCLICK);+ if (S.cookie_clicks <= 0) win(A_TRUE_NEVERCLICK);+ if (S.cookies_earned >= 1000000000 && G.upgrades_owned == 0) win(A_HARDCORE);+ }+ for (int i = 0; i < N_UNLOCK_AT; i++) {+ const UnlockAtRec *u = unlock_at(i);+ if (S.cookies_earned < u->cookies) continue;+ if (u->require_up != NONE && !has(u->require_up)) continue;+ if (u->require_ach != NONE && !has_achiev(u->require_ach)) continue;+ if (u->season && S.season != u->season) continue;+ if (u->up != NONE) unlock(u->up);+ if (u->ach != NONE) win(u->ach);+ }+ if (has(U_GOLDEN_SWITCH)) unlock(U_GOLDEN_SWITCH_OFF);+ if (has(U_SHIMMERING_VEIL) && !has(U_SHIMMERING_VEIL_OFF) && !has(U_SHIMMERING_VEIL_ON))+ unlock(U_SHIMMERING_VEIL_ON), earn_upgrade(U_SHIMMERING_VEIL_OFF);+ if (has(U_SUGAR_CRAVING)) unlock(U_SUGAR_FRENZY);+ if (has(U_CLASSIC_DAIRY_SELECTION)) unlock(U_MILK_SELECTOR);+ if (has(U_BASIC_WALLPAPER_ASSORTMENT)) unlock(U_BACKGROUND_SELECTOR);+ if (has(U_PRISM_HEART_BISCUITS)) win(A_LOVELY_COOKIES);+ if (S.season == SEASON_EASTER) {+ int eggs = 0;+ for (int i = 0; i < N_EASTER_EGGS; i++) eggs += has_unlocked(LIST(EASTER_EGGS)[i]);+ if (eggs >= 1) win(A_THE_HUNT_IS_ON);+ if (eggs >= 7) win(A_EGGING_ON);+ if (eggs >= 14) win(A_MASS_EASTERIA);+ if (eggs >= N_EASTER_EGGS) win(A_HIDE_AND_SEEK_CHAMPION);+ }+ if (has(U_FORTUNE_COOKIES)) {+ int f = 0;+ for (int i = 0; i < N_FORTUNES; i++) f += has(LIST(FORTUNES)[i]);+ if (f >= N_FORTUNES) win(A_O_FORTUNA);+ }+ if (has(U_LEGACY) && S.ascension_mode != 1) {+ unlock(U_HEAVENLY_CHIP_SECRET);+ if (has(U_HEAVENLY_CHIP_SECRET)) unlock(U_HEAVENLY_COOKIE_STAND);+ if (has(U_HEAVENLY_COOKIE_STAND)) unlock(U_HEAVENLY_BAKERY);+ if (has(U_HEAVENLY_BAKERY)) unlock(U_HEAVENLY_CONFECTIONERY);+ if (has(U_HEAVENLY_CONFECTIONERY)) unlock(U_HEAVENLY_KEY);+ if (has(U_HEAVENLY_KEY)) win(A_WHOLESOME);+ }+ for (int i = 0; i < N_BANK_ACHIEVS; i++)+ if (S.cookies_earned >= bank_achiev(i)->threshold) win(bank_achiev(i)->id);+ if (S.elder_wrath >= 3) win(A_GRANDMAPOCALYPSE);++ int owned = 0, min_amount = 100000;+ bool mathematician = true, base10 = true;+ for (int b = 0; b < NB; b++) {+ int a = S.buildings[b].amount;+ owned += a;+ if (a < min_amount) min_amount = a;+ int need = 1 << (NB - b - 1);+ if (a < (need < 128 ? need : 128)) mathematician = false;+ if (a < (NB - b) * 10) base10 = false;+ }+ if (min_amount >= 1) win(A_ONE_WITH_EVERYTHING);+ if (mathematician) win(A_MATHEMATICIAN);+ if (base10) win(A_BASE_10);+ static const struct { int16_t at; uint16_t a, u; } centennials[] = {+ {100, A_CENTENNIAL, U_MILK_CHOCOLATE_BUTTER_BISCUIT},+ {150, A_CENTENNIAL_AND_A_HALF, U_DARK_CHOCOLATE_BUTTER_BISCUIT},+ {200, A_BICENTENNIAL, U_WHITE_CHOCOLATE_BUTTER_BISCUIT},+ {250, A_BICENTENNIAL_AND_A_HALF, U_RUBY_CHOCOLATE_BUTTER_BISCUIT},+ {300, A_TRICENTENNIAL, U_LAVENDER_CHOCOLATE_BUTTER_BISCUIT},+ {350, A_TRICENTENNIAL_AND_A_HALF, U_SYNTHETIC_CHOCOLATE_GREEN_HONEY_BUTTER_BISCUIT},+ {400, A_QUADRICENTENNIAL, U_ROYAL_RASPBERRY_CHOCOLATE_BUTTER_BISCUIT},+ {450, A_QUADRICENTENNIAL_AND_A_HALF, U_ULTRA_CONCENTRATED_HIGH_ENERGY_CHOCOLATE_BUTTER_BISCUIT},+ {500, A_QUINCENTENNIAL, U_PURE_PITCH_BLACK_CHOCOLATE_BUTTER_BISCUIT},+ {550, A_QUINCENTENNIAL_AND_A_HALF, U_COSMIC_CHOCOLATE_BUTTER_BISCUIT},+ {600, A_SEXCENTENNIAL, U_BUTTER_BISCUIT_WITH_BUTTER}, {650, A_SEXCENTENNIAL_AND_A_HALF, U_EVERYBUTTER_BISCUIT},+ {700, A_SEPTCENTENNIAL, U_PERSONAL_BISCUIT}};+ for (unsigned i = 0; i < sizeof centennials / sizeof centennials[0]; i++)+ if (min_amount >= centennials[i].at) win(centennials[i].a), unlock(centennials[i].u);+ static const struct { double at; uint16_t a, u; } clicks[] = {+ {1e3, A_CLICKTASTIC, U_PLASTIC_MOUSE}, {1e5, A_CLICKATHLON, U_IRON_MOUSE}, {1e7, A_CLICKOLYMPICS, U_TITANIUM_MOUSE},+ {1e9, A_CLICKORAMA, U_ADAMANTIUM_MOUSE}, {1e11, A_CLICKASMIC, U_UNOBTAINIUM_MOUSE},+ {1e13, A_CLICKAGEDDON, U_ELUDIUM_MOUSE}, {1e15, A_CLICKNAROK, U_WISHALLOY_MOUSE},+ {1e17, A_CLICKASTROPHE, U_FANTASTEEL_MOUSE}, {1e19, A_CLICKATACLYSM, U_NEVERCRACK_MOUSE},+ {1e21, A_THE_ULTIMATE_CLICKDOWN, U_ARMYTHRIL_MOUSE},+ {1e23, A_ALL_THE_OTHER_KIDS_WITH_THE_PUMPED_UP_CLICKS, U_TECHNOBSIDIAN_MOUSE},+ {1e25, A_ONE_MORE_CLICK, U_PLASMARBLE_MOUSE}, {1e27, A_CLICKETY_SPLIT, U_MIRACULITE_MOUSE},+ {1e29, A_AINT_THAT_A_CLICK_IN_THE_HEAD, U_AETHERICE_MOUSE}, {1e31, A_WHATS_NOT_CLICKING, U_OMNIPLAST_MOUSE}};+ for (unsigned i = 0; i < sizeof clicks / sizeof clicks[0]; i++)+ if (S.handmade_cookies >= clicks[i].at) win(clicks[i].a), unlock(clicks[i].u);+ if (S.cookies_earned < S.cookies) win(A_CHEATED_COOKIES_TASTE_AWFUL);+ if (has(U_SKULL_COOKIES) && has(U_GHOST_COOKIES) && has(U_BAT_COOKIES) && has(U_SLIME_COOKIES) &&+ has(U_PUMPKIN_COOKIES) && has(U_EYEBALL_COOKIES) && has(U_SPIDER_COOKIES))+ win(A_SPOOKY_COOKIES);+ if (S.wrinklers_popped >= 1) win(A_ITCHSCRATCHER);+ if (S.wrinklers_popped >= 50) win(A_WRINKLESQUISHER);+ if (S.wrinklers_popped >= 200) win(A_MOISTBURSTER);+ if (S.cookies_earned >= 1000000 && has(U_HOW_TO_BAKE_YOUR_DRAGON)) unlock(U_A_CRUMBLY_EGG);+ if (S.cookies_earned >= 25 && S.season == SEASON_CHRISTMAS) unlock(U_A_FESTIVE_HAT);+ if (has(U_CHRISTMAS_TREE_BISCUITS) && has(U_SNOWFLAKE_BISCUITS) && has(U_SNOWMAN_BISCUITS) &&+ has(U_HOLLY_BISCUITS) && has(U_CANDY_CANE_BISCUITS) && has(U_BELL_BISCUITS) && has(U_PRESENT_BISCUITS))+ win(A_LET_IT_SNOW);+ if (S.reindeer_clicked >= 1) win(A_OH_DEER);+ if (S.reindeer_clicked >= 50) win(A_SLEIGH_OF_HAND);+ if (S.reindeer_clicked >= 200) win(A_REINDEER_SLEIGHER);+ static const struct { int16_t at; uint16_t a; } builds[] = {+ {100, A_BUILDER}, {500, A_ARCHITECT}, {1000, A_ENGINEER}, {2500, A_LORD_OF_CONSTRUCTS}, {5000, A_GRAND_DESIGN},+ {7500, A_ECUMENOPOLIS}, {10000, A_MYRIAD}};+ for (unsigned i = 0; i < sizeof builds / sizeof builds[0]; i++)+ if (owned >= builds[i].at) win(builds[i].a);+ static const struct { int16_t at; uint16_t a; } ups[] = {+ {20, A_ENHANCER}, {50, A_AUGMENTER}, {100, A_UPGRADER}, {200, A_LORD_OF_PROGRESS}, {300, A_THE_FULL_PICTURE},+ {400, A_WHEN_THERES_NOTHING_LEFT_TO_ADD}, {500, A_KAIZEN}, {600, A_BEYOND_QUALITY},+ {700, A_OFT_WE_MAR_WHATS_WELL}};+ for (unsigned i = 0; i < sizeof ups / sizeof ups[0]; i++)+ if (G.upgrades_owned >= ups[i].at) win(ups[i].a);+ if (owned >= 4000 && G.upgrades_owned >= 300) win(A_POLYMATH);+ if (owned >= 8000 && G.upgrades_owned >= 400) win(A_RENAISSANCE_BAKER);+ if (!has_achiev(A_JELLICLES)) {+ int k = 0;+ for (int i = 0; i < N_KITTENS; i++) k += has(LIST(KITTENS)[i]);+ if (k >= 10) win(A_JELLICLES);+ }+ if (S.cookies_earned >= 1e14 && !has_achiev(A_YOU_WIN_A_COOKIE)) win(A_YOU_WIN_A_COOKIE), earn(1);+ if (G.nshimmers_golden >= 4) win(A_FOUR_LEAF_COOKIE);+ int grandmas = 0;+ for (int i = 0; i < N_GRANDMA_SYNERGIES; i++) grandmas += has(LIST(GRANDMA_SYNERGIES)[i]);+ if (!has_achiev(A_ELDER) && grandmas >= 7) win(A_ELDER);+ if (!has_achiev(A_VETERAN) && grandmas >= 14) win(A_VETERAN);+ if (S.buildings[B_GRANDMA].amount >= 6 && !has(U_BINGO_CENTER_RESEARCH_FACILITY) && has_achiev(A_ELDER))+ unlock(U_BINGO_CENTER_RESEARCH_FACILITY);+ if (S.pledges > 0) win(A_ELDER_NAP);+ if (S.pledges >= 5) win(A_ELDER_SLUMBER);+ if (S.pledges >= 10) unlock(U_SACRIFICIAL_ROLLING_PINS);+ if (S.buildings[B_CURSOR].amount + S.buildings[B_GRANDMA].amount >= 777) win(A_THE_ELDER_SCROLLS);+ for (int b = 0; b < NB; b++) {+ const BuildingLinks *l = building_links(b);+ for (int i = 0; i < 3; i++)+ if (l->prod_ach[i] != NONE && S.buildings[b].total_cookies >= l->prod_pow[i]) win(l->prod_ach[i]);+ }+ /* the big cookie dips into the milk */+ float panel = SCREEN_H - NEWS_H;+ if (!has_achiev(A_COOKIE_DUNKER) && G.milk_progress > 0.1f &&+ panel * 0.4f + 256 * 0.37f / 2 - 16 * 0.37f > (1 - G.milk_hd) * panel)+ win(A_COOKIE_DUNKER);+}++/* ------------------------------------------------------------------ a frame */+extern void update_grandmapocalypse(void);+extern void update_special(void);+extern void do_lumps(void);+extern void minigames_logic(void);+extern void wrinklers_update(void);+extern void season_logic(void);+extern void ascend_logic(void);++void game_logic(void) {+ if (G.on_ascend || G.ascend_timer > 0) {+ ascend_logic();+ G.T++;+ G.real_t += 1;+ return;+ }+ update_special();+ update_grandmapocalypse();++ /* the big cookie's size: it wobbles when clicked */+ if (S.prefs.wobbly) {+ G.big_size_t = G.big_state == 1 ? 0.98f : G.big_state == 2 ? 1.05f : 1;+ G.big_size_d += (G.big_size_t - G.big_size) * 0.75f;+ G.big_size_d *= 0.75f;+ G.big_size += G.big_size_d;+ if (G.big_size < 0.1f) G.big_size = 0.1f;+ } else+ G.big_size += ((G.big_state == 1 ? 0.98f : G.big_state == 2 ? 1.05f : 1) - G.big_size) * 0.5f;++ /* particles */+ for (int i = 0; i < MAX_PARTICLES; i++) {+ Particle *p = &G.particles[i];+ if (p->life < 0) continue;+ p->yd += 0.25f * 0.37f;+ p->x += p->xd, p->y += p->yd;+ if (++p->life >= FPS * p->dur) p->life = -1;+ }+ for (int i = 0; i < MAX_TEXT_PARTICLES; i++) {+ TextParticle *t = &G.texts[i];+ if (t->life < 0) continue;+ t->y += t->yd;+ if (++t->life >= t->dur) t->life = -1;+ }+ for (int i = 0; i < MAX_POPUPS; i++)+ if (G.popups[i].life > 0) G.popups[i].life--;++ /* milk */+ G.milk_progress = G.achievements_owned / 25.f;+ static const uint16_t kittens[] = {U_KITTEN_HELPERS, U_KITTEN_WORKERS, U_KITTEN_ENGINEERS, U_KITTEN_OVERSEERS,+ U_KITTEN_MANAGERS, U_KITTEN_ACCOUNTANTS, U_KITTEN_SPECIALISTS, U_KITTEN_EXPERTS,+ U_KITTEN_CONSULTANTS, U_KITTEN_ASSISTANTS_TO_THE_REGIONAL_MANAGER,+ U_KITTEN_MARKETEERS, U_KITTEN_ANALYSTS, U_KITTEN_EXECUTIVES, U_KITTEN_ADMINS,+ U_KITTEN_STRATEGISTS};+ if (G.milk_progress >= 0.5f) unlock(kittens[0]);+ for (int i = 1; i < 15; i++)+ if (G.milk_progress >= i) unlock(kittens[i]);+ G.milk_h = (G.milk_progress < 1 ? G.milk_progress : 1) * 0.35f;+ G.milk_hd += (G.milk_h - G.milk_hd) * 0.02f;++ /* research */+ if (S.research_t > 0) S.research_t--;+ if (S.research_t == 0 && S.next_research) {+ if (!has(S.next_research)) {+ unlock(S.next_research);+ char d[96];+ snprintf(d, sizeof d, "You have discovered: \x01%s\x02.", res_text(upgrade_rec(S.next_research)->name));+ notify("Research complete", d, upgrade_rec(S.next_research)->icon, 0);+ }+ S.next_research = 0, S.research_t = -1, G.recalculate = true;+ }+ season_logic();++ /* cookies */+ if (G.recalculate) calculate_gains();+ earn(G.cookies_ps / FPS);+ do_lumps();+ minigames_logic();+ if (G.cps_sucked > 0) {+ double d = G.cookies_ps / FPS * G.cps_sucked;+ dissolve(d);+ S.cookies_sucked += d;+ }+ for (int b = 0; b < NB; b++) S.buildings[b].total_cookies += S.buildings[b].stored_total_cps * G.global_cps_mult / FPS;+ /* the cookies that fall behind the big one */+ if (S.prefs.particles && S.cookies > 0) {+ double c = G.cookies_ps < 10 ? G.cookies_ps : 10;+ if (c > 0 && G.T % (uint32_t)ceil(FPS / c) == 0) particle_add(0, 0, 0, 0, 1, 2, 0);+ }+ if (G.T % (FPS * 10) == 0) G.recalculate = true;++ if (G.T % FPS == 0 && rnd() < 1.0 / 1000000) win(A_JUST_PLAIN_LUCKY);+ if (G.T % (FPS * 5) == 0) game_check();++ if (isnan(G.cookies_d)) G.cookies_d = 0;+ if (G.cookies_d == G.cookies_d + (S.cookies - G.cookies_d) * 0.3) G.cookies_d = S.cookies;+ else G.cookies_d += (S.cookies - G.cookies_d) * 0.3;++ if (G.upgrades_dirty) game_rebuild_upgrades();+ shimmers_update();+ buffs_update();+ wrinklers_update();++ /* notes that go away by themselves */+ for (int i = 0; i < MAX_NOTES; i++) {+ Note *n = &G.notes[i];+ if (!n->title[0]) continue;+ n->age++;+ if (n->life > 0 && --n->life == 0) n->title[0] = 0;+ }+ G.click_t++;+ G.T++;+ G.real_t += 1;+ S.play_time += 1000.0 / FPS;+}diff --git a/games/cookieclicker/src/game.h b/games/cookieclicker/src/game.hnew file mode 100644index 00000000..f4727804--- /dev/null+++ b/games/cookieclicker/src/game.h@@ -0,0 +1,258 @@+/* Cookie Clicker: the game's state and rules (logic.c and the files beside it), as the game's own+ * main.js has them (version 2.058). Times are in frames of 1/30 of a second, as the game counts. */+#ifndef CC_GAME_H+#define CC_GAME_H+#include <stdbool.h>+#include <stdint.h>+#include "plat.h"+#include "res.h"++#define FPS 30+#define NB N_BUILDINGS+#define MAX_SHIMMERS 48+#define MAX_BUFFS 12+#define MAX_PARTICLES 48+#define MAX_TEXT_PARTICLES 12+#define MAX_NOTES 4+#define MAX_POPUPS 4+#define MAX_WRINKLERS 14+#define UBITS ((N_UPGRADES + 7) / 8)+#define ABITS ((N_ACHIEVS + 7) / 8)++/* the dragon's auras and the Pantheon's gods, in the game's order */+enum {+ AURA_NONE, AURA_BREATH_OF_MILK, AURA_DRAGON_CURSOR, AURA_ELDER_BATTALION, AURA_REAPER_OF_FIELDS,+ AURA_EARTH_SHATTERER, AURA_MASTER_OF_THE_ARMORY, AURA_FIERCE_HOARDER, AURA_DRAGON_GOD, AURA_ARCANE_AURA,+ AURA_DRAGONFLIGHT, AURA_ANCESTRAL_METAMORPHOSIS, AURA_UNHOLY_DOMINION, AURA_EPOCH_MANIPULATOR,+ AURA_MIND_OVER_MATTER, AURA_RADIANT_APPETITE, AURA_DRAGONS_FORTUNE, AURA_DRAGONS_CURVE, AURA_REALITY_BENDING,+ AURA_DRAGON_ORBS, AURA_SUPREME_INTELLECT, AURA_DRAGON_GUTS, N_AURAS+};+enum {+ GOD_ASCETICISM, GOD_DECADENCE, GOD_RUIN, GOD_AGES, GOD_SEASONS, GOD_CREATION, GOD_LABOR, GOD_INDUSTRY,+ GOD_MOTHER, GOD_SCORN, GOD_ORDER, N_GODS+};++/* the buffs golden cookies, spells and the rest give (the game's buffTypes) */+enum {+ BUFF_FRENZY, BUFF_ELDER_FRENZY, BUFF_CLOT, BUFF_DRAGON_HARVEST, BUFF_EVERYTHING_MUST_GO, BUFF_CURSED_FINGER,+ BUFF_CLICK_FRENZY, BUFF_DRAGONFLIGHT, BUFF_COOKIE_STORM, BUFF_BUILDING_BUFF, BUFF_BUILDING_DEBUFF,+ BUFF_SUGAR_BLESSING, BUFF_HAGGLER_LUCK, BUFF_HAGGLER_MISERY, BUFF_PIXIE_LUCK, BUFF_PIXIE_MISERY, BUFF_MAGIC_ADEPT,+ BUFF_MAGIC_INEPT, BUFF_DEVASTATION, BUFF_SUGAR_FRENZY, BUFF_LOAN1, BUFF_LOAN1_INTEREST, BUFF_LOAN2,+ BUFF_LOAN2_INTEREST, BUFF_LOAN3, BUFF_LOAN3_INTEREST, N_BUFF_TYPES+};+typedef struct {+ uint8_t type, building, used, pad;+ int32_t time, max_time;+ float arg1;+ double power, mult_cps, mult_click; /* (1 when the buff has none) */+} Buff;++/* the golden cookie's effects, and its forced kinds */+enum {+ GC_NONE, GC_FRENZY, GC_LUCKY, GC_RUIN, GC_BLOOD_FRENZY, GC_CLOT, GC_CLICK_FRENZY, GC_CURSED_FINGER, GC_CHAIN,+ GC_STORM, GC_BUILDING_SPECIAL, GC_DRAGON_HARVEST, GC_DRAGONFLIGHT, GC_SUGAR_LUMP, GC_BLAB, GC_STORM_DROP,+ GC_EVERYTHING_MUST_GO, N_GC+};+enum { SHIMMER_GOLDEN, SHIMMER_REINDEER };+typedef struct {+ uint8_t type, wrath, spawn_lead, force, used, pad[3];+ int32_t id, life, max_life;+ float x, y, dur, size_mult;+} Shimmer;++typedef struct {+ int amount, bought, highest, free, level, muted; /* (int: 32 bits, here and on computers) */+ double total_cookies;+ /* computed */+ double stored_cps, stored_total_cps;+ bool locked;+} Building;++typedef struct {+ float x, y, xd, yd, r, size;+ int16_t life, dur, pic, kind;+} Particle;+typedef struct {+ float x, y, yd;+ int16_t life, dur;+ char text[24];+} TextParticle;++/* the game's notes (bottom of the screen) and popups (texts that float up) */+typedef struct {+ char title[48];+ char desc[96];+ int16_t icon; /* ICON(x, y), or -1 */+ int32_t life; /* frames left, or -1 to stay until closed */+ int32_t age;+} Note;+typedef struct {+ char text[64];+ float x, y;+ int32_t life;+} Popup;++typedef struct {+ uint8_t phase, type, selected, pad; /* phase: 0 none, 1 coming, 2 eating; type: 1 shiny */+ uint16_t clicks, pad2;+ float close, hp, hurt, r, x, y; /* how near the cookie it is (0..1), where (computed) */+ double sucked; /* the cookies it ate */+} Wrinkler;++/* the preferences (Options) */+typedef struct {+ uint8_t particles, numbers, milk, fancy, cursors, wobbly, not_scary, format_long, monospace, notes_on;+ uint8_t short_numbers, extra_buttons, focus, warn, pad[2];+} Prefs;++/* everything that is saved */+typedef struct {+ uint32_t magic, version;+ double cookies, cookies_earned, cookies_reset, cookies_sucked, handmade_cookies, cookie_clicks;+ double prestige, heavenly_chips, heavenly_chips_spent, cookies_ps_raw_highest;+ unsigned golden_clicks, golden_clicks_local, missed_golden_clicks, reindeer_clicked, wrinklers_popped, resets;+ unsigned ticker_clicks, season_uses, pledges, spells_cast, spells_cast_total;+ int32_t elder_wrath, pledge_t, research_t, next_research, season_t, golden_time, golden_min, golden_max;+ int32_t reindeer_time, reindeer_min, reindeer_max, golden_chain;+ double golden_chain_total;+ uint8_t season, ascension_mode, dragon_level, dragon_aura, dragon_aura2, santa_level, golden_last, golden_spawned;+ uint8_t reindeer_spawned, milk_type, bg_type, bakery_name1, bakery_name2, seen_keys, seen_ascend, on_ascend;+ 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];+ 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];+ Buff buffs[MAX_BUFFS];+ Wrinkler wrinklers[MAX_WRINKLERS];+ Prefs prefs;+ /* the minigames */+ float grimoire_magic;+ uint8_t on_minigame, pad5[3]; /* the minigame shown (its building + 1), 0 none */+ uint8_t gods[3], swaps;+ int32_t swap_t;+ uint8_t garden[6][6][2], garden_soil, garden_freeze;+ uint16_t garden_seeds[3];+ double garden_next_step, garden_next_soil;+ uint32_t garden_harvests, garden_harvests_total;+} SaveState;++typedef struct {+ SaveState s;+ /* the rest is computed, or lives only while the game runs */+ double cookies_ps, global_cps_mult, computed_mouse_cps, unbuffed_cps, building_cps, cookies_ps_raw;+ double cps_sucked, cookies_d; /* the cookies shown, catching up with the real ones */+ float milk_progress, milk_h, milk_hd;+ int achievements_owned, upgrades_owned, buildings_owned;+ uint32_t T, draw_t; /* logic frames, drawn frames */+ float real_t;+ bool recalculate, store_dirty, upgrades_dirty;+ /* the store's upgrades, sorted as the game sorts them */+ uint16_t store[N_UPGRADES];+ int nstore, nstore_toggle, nstore_tech;+ int buy_mode, buy_bulk; /* 1 buy / -1 sell; 1, 10, 100, -1 all */+ /* the big cookie */+ int big_state; /* 0 normal, 1 pressed, 2 released */+ float big_size, big_size_d, big_size_t;+ int32_t click_t; /* frames since the last click */+ Shimmer shimmers[MAX_SHIMMERS];+ int nshimmers_golden, nshimmers_reindeer;+ int32_t shimmers_id;+ Particle particles[MAX_PARTICLES];+ TextParticle texts[MAX_TEXT_PARTICLES];+ Note notes[MAX_NOTES];+ Popup popups[MAX_POPUPS];+ float effs[16]; /* the minigames' effects (EFF_*) */+ /* ascending */+ bool on_ascend;+ int32_t ascend_timer, reincarnate_timer;+ uint32_t seed;+} GameState;+extern GameState G;+#define S (G.s)++enum { EFF_CPS, EFF_CLICK, EFF_GRANDMA_CPS, EFF_CURSOR_CPS, EFF_MILK, EFF_GOLDEN_FREQ, EFF_GOLDEN_DUR, EFF_GOLDEN_EFF_DUR,+ EFF_GOLDEN_GAIN, EFF_WRATH_FREQ, EFF_WRATH_DUR, EFF_WRATH_EFF_DUR, EFF_WRATH_GAIN, EFF_BUILDING_COST,+ EFF_UPGRADE_COST, EFF_ITEM_DROPS };+static inline float eff(int i) { return G.effs[i]; }++/* the game's random numbers */+double rnd(void); /* 0 <= x < 1 */+int rnd_int(int n);++/* upgrades and achievements */+static inline bool bit_get(const uint8_t *b, int i) { return b[i >> 3] >> (i & 7) & 1; }+static inline void bit_set(uint8_t *b, int i, bool v) {+ if (v) b[i >> 3] |= (uint8_t)(1 << (i & 7));+ else b[i >> 3] &= (uint8_t)~(1 << (i & 7));+}+bool has(int u); /* bought (Game.Has) */+static inline bool has_unlocked(int u) { return bit_get(S.upgrades_unlocked, u); }+static inline bool has_achiev(int a) { return bit_get(S.achievements, a); }+void unlock(int u);+void lock(int u);+void win(int a);+void earn_upgrade(int u); /* bought without spending */+double upgrade_price(int u);+bool upgrade_can_buy(int u);+bool upgrade_buy(int u, bool confirmed); /* false: not bought */+bool upgrade_needs_confirm(int u);+bool counts_as_upgrade_owned(int u);++/* buildings */+double building_price(int b); /* the next one */+double building_sum_price(int b, int n); /* n more */+double building_reverse_sum_price(int b, int n);+void building_buy(int b, int n);+void building_sell(int b, int n);+void building_bulk(int b, double *price, int *n); /* what the store's mode would buy or sell, and for how much */++/* cookies */+void earn(double v);+void spend(double v);+void dissolve(double v);+void click_cookie(void);+void calculate_gains(void);+double tiered_cps_mult(int b);+int hasgod(int god); /* the Pantheon: 0, or the slot (1..3) a god is in */+float aura_mult(int aura);+bool has_buff(int type);+Buff *find_buff(int type);+Buff *gain_buff(int type, float time, double pow, int building);+void kill_buff(int type);+double drop_rate_mult(void);++/* the game */+void game_new(void);+void game_logic(void); /* a frame */+void game_rebuild_upgrades(void);+void game_check(void); /* the checks the game makes every 5 seconds */+void notify(const char *title, const char *desc, int icon, int seconds);+void popup(const char *text, float x, float y);+void particle_add(float x, float y, float xd, float yd, float size, int dur, int kind);+void text_particle_add(float x, float y, const char *text);++/* shimmers (shimmer.c) */+void shimmers_reset(void);+void shimmers_update(void);+Shimmer *shimmer_new(int type, int force, bool no_count);+void shimmer_pop(Shimmer *m);+int shimmer_next(void); /* the one shift pops (the oldest), -1 none */+int32_t golden_min_time(void), golden_max_time(void);+void buffs_update(void);++/* numbers, as the game writes them */+void beautify(double v, int floats, char *out);+void say_time(double frames, int detail, char *out);+/* "%1 cookie(s)" */+void cookies_str(double v, int floats, char *out);++/* where things are on the screen (ui.c) */+#define NEWS_H 20+#define LEFT_W 142+#define STORE_X 146+#define STORE_W (SCREEN_W - STORE_X)+#define COOKIE_X 71+#define COOKIE_Y 116+#endifdiff --git a/games/cookieclicker/src/garden.c b/games/cookieclicker/src/garden.cnew file mode 100644index 00000000..d0b7324e--- /dev/null+++ b/games/cookieclicker/src/garden.c@@ -0,0 +1,8 @@+/* The Garden (the farm's minigame). */+#include <math.h>+#include <string.h>+#include "game.h"++void garden_logic(void) {}+void garden_reset(bool hard) { (void)hard; }+void garden_effs(float *effs, float *wrinkler) { (void)effs, (void)wrinkler; }diff --git a/games/cookieclicker/src/gfx.c b/games/cookieclicker/src/gfx.cnew file mode 100644index 00000000..b5220b8f--- /dev/null+++ b/games/cookieclicker/src/gfx.c@@ -0,0 +1,510 @@+/* Drawing (gfx.h): RGB565 bands, pictures with palettes and opacity, scaled, rotated and tiled+ * with bilinear sampling, 4-bit fonts and the game's markup. */+#include <math.h>+#include <string.h>+#include "gfx.h"+#include "res.h"++static uint16_t *band_mem;+static uint16_t *band; /* the band: g_bw x (g_by1 - g_by0) */+static int g_bx, g_by, g_bw; /* its top-left on screen and width */+int g_x0, g_y0, g_x1, g_y1;+#define CLIP_DEPTH 8+static int clip_save[CLIP_DEPTH][4], clip_depth;+static int blend_mode;++void gfx_set_band_memory(uint16_t *m) { band_mem = m; }++void gfx_render(int x, int y, int w, int h, void (*draw)(void)) {+ if (x < 0) w += x, x = 0;+ if (y < 0) h += y, y = 0;+ if (x + w > SCREEN_W) w = SCREEN_W - x;+ if (y + h > SCREEN_H) h = SCREEN_H - y;+ if (w <= 0 || h <= 0) return;+ int rows = SCREEN_W * GFX_BAND / w;+ if (rows > h) rows = h;+ for (int by = y; by < y + h; by += rows) {+ int bh = by + rows > y + h ? y + h - by : rows;+ band = band_mem;+ g_bx = x, g_by = by, g_bw = w;+ g_x0 = x, g_x1 = x + w, g_y0 = by, g_y1 = by + bh;+ blend_mode = BLEND_NORMAL;+ clip_depth = 0;+ draw();+ plat_push(x, by, w, bh, band);+ }+}++void gfx_clip(int x, int y, int w, int h) {+ int *c = clip_save[clip_depth < CLIP_DEPTH ? clip_depth++ : CLIP_DEPTH - 1];+ c[0] = g_x0, c[1] = g_y0, c[2] = g_x1, c[3] = g_y1;+ if (x > g_x0) g_x0 = x;+ if (y > g_y0) g_y0 = y;+ if (x + w < g_x1) g_x1 = x + w;+ if (y + h < g_y1) g_y1 = y + h;+ if (g_x1 < g_x0) g_x1 = g_x0;+ if (g_y1 < g_y0) g_y1 = g_y0;+}+void gfx_unclip(void) {+ if (clip_depth > 0) clip_depth--;+ int *c = clip_save[clip_depth];+ g_x0 = c[0], g_y0 = c[1], g_x1 = c[2], g_y1 = c[3];+}+void gfx_blend(int mode) { blend_mode = mode; }++static inline uint16_t *at(int x, int y) { return band + (y - g_by) * g_bw + (x - g_bx); }++/* a over d with opacity a (0..256) */+static inline uint16_t blend(uint16_t d, uint16_t s, int a) {+ if (a >= 256) return s;+ uint32_t dd = (d | (uint32_t)d << 16) & 0x07E0F81Fu;+ uint32_t ss = (s | (uint32_t)s << 16) & 0x07E0F81Fu;+ uint32_t r = ((((ss - dd) * (uint32_t)(a >> 3)) >> 5) + dd) & 0x07E0F81Fu;+ return (uint16_t)(r | r >> 16);+}+static inline uint16_t add(uint16_t d, uint16_t s, int a) {+ int r = (d >> 11) + (((s >> 11) * a) >> 8), g = ((d >> 5) & 63) + ((((s >> 5) & 63) * a) >> 8);+ int b = (d & 31) + (((s & 31) * a) >> 8);+ if (r > 31) r = 31;+ if (g > 63) g = 63;+ if (b > 31) b = 31;+ return (uint16_t)(r << 11 | g << 5 | b);+}+static inline void put(uint16_t *p, uint16_t c, int a) {+ if (a <= 0) return;+ *p = blend_mode == BLEND_ADD ? add(*p, c, a) : blend(*p, c, a);+}+uint16_t gfx_mix(uint16_t a, uint16_t b, int t) { return blend(a, b, t); }++/* ------------------------------------------------------------------ shapes */+static bool clipr(int *x, int *y, int *w, int *h) {+ int x0 = *x < g_x0 ? g_x0 : *x, y0 = *y < g_y0 ? g_y0 : *y;+ int x1 = *x + *w > g_x1 ? g_x1 : *x + *w, y1 = *y + *h > g_y1 ? g_y1 : *y + *h;+ if (x1 <= x0 || y1 <= y0) return false;+ *x = x0, *y = y0, *w = x1 - x0, *h = y1 - y0;+ return true;+}+void gfx_fill(int x, int y, int w, int h, uint16_t c) {+ if (!clipr(&x, &y, &w, &h)) return;+ for (int r = 0; r < h; r++) {+ uint16_t *p = at(x, y + r);+ for (int i = 0; i < w; i++) p[i] = c;+ }+}+void gfx_fill_alpha(int x, int y, int w, int h, uint16_t c, int alpha) {+ if (alpha >= 256 && blend_mode == BLEND_NORMAL) {+ gfx_fill(x, y, w, h, c);+ return;+ }+ if (alpha <= 0 || !clipr(&x, &y, &w, &h)) return;+ for (int r = 0; r < h; r++) {+ uint16_t *p = at(x, y + r);+ for (int i = 0; i < w; i++) put(p + i, c, alpha);+ }+}+void gfx_hgrad(int x, int y, int w, int h, uint16_t c, int a0, int a1) {+ int ox = x, ow = w;+ if (ow <= 0 || !clipr(&x, &y, &w, &h)) return;+ for (int i = 0; i < w; i++) {+ int a = a0 + (a1 - a0) * (x + i - ox) / (ow > 1 ? ow - 1 : 1);+ for (int r = 0; r < h; r++) put(at(x + i, y + r), c, a);+ }+}+void gfx_vgrad(int x, int y, int w, int h, uint16_t c, int a0, int a1) {+ int oy = y, oh = h;+ if (oh <= 0 || !clipr(&x, &y, &w, &h)) return;+ for (int r = 0; r < h; r++) {+ int a = a0 + (a1 - a0) * (y + r - oy) / (oh > 1 ? oh - 1 : 1);+ uint16_t *p = at(x, y + r);+ for (int i = 0; i < w; i++) put(p + i, c, a);+ }+}+void gfx_rect(int x, int y, int w, int h, uint16_t c, int alpha) {+ gfx_fill_alpha(x, y, w, 1, c, alpha);+ gfx_fill_alpha(x, y + h - 1, w, 1, c, alpha);+ gfx_fill_alpha(x, y + 1, 1, h - 2, c, alpha);+ gfx_fill_alpha(x + w - 1, y + 1, 1, h - 2, c, alpha);+}+void gfx_round_rect(int x, int y, int w, int h, int r, uint16_t c, int alpha) {+ if (!gfx_visible(x, y, w, h)) return;+ for (int row = 0; row < h; row++) {+ int yy = y + row;+ if (yy < g_y0 || yy >= g_y1) continue;+ int d = 0;+ if (row < r || row >= h - r) {+ float dy = row < r ? r - row - 0.5f : row - (h - r) + 0.5f;+ float dx = r - sqrtf((float)(r * r) - dy * dy);+ d = (int)(dx + 0.5f);+ }+ gfx_fill_alpha(x + d, yy, w - 2 * d, 1, c, alpha);+ }+}+void gfx_line(float x0, float y0, float x1, float y1, uint16_t c, int alpha) {+ float dx = x1 - x0, dy = y1 - y0;+ int n = (int)(fabsf(dx) > fabsf(dy) ? fabsf(dx) : fabsf(dy)) + 1;+ for (int i = 0; i <= n; i++) {+ int x = (int)(x0 + dx * i / n + 0.5f), y = (int)(y0 + dy * i / n + 0.5f);+ if (x >= g_x0 && x < g_x1 && y >= g_y0 && y < g_y1) put(at(x, y), c, alpha);+ }+}+void gfx_disc(float cx, float cy, float r, uint16_t c, int alpha) {+ int y0 = (int)floorf(cy - r), y1 = (int)ceilf(cy + r);+ if (y0 < g_y0) y0 = g_y0;+ if (y1 > g_y1) y1 = g_y1;+ for (int y = y0; y < y1; y++) {+ float dy = y + 0.5f - cy;+ float h2 = r * r - dy * dy;+ if (h2 <= 0) continue;+ float hw = sqrtf(h2);+ float xa = cx - hw, xb = cx + hw;+ int x0 = (int)floorf(xa), x1 = (int)ceilf(xb);+ if (x0 < g_x0) x0 = g_x0;+ if (x1 > g_x1) x1 = g_x1;+ for (int x = x0; x < x1; x++) {+ float cov = 1;+ if (x < xa) cov -= xa - x;+ if (x + 1 > xb) cov -= x + 1 - xb;+ if (cov > 0) put(at(x, y), c, (int)(alpha * cov));+ }+ }+}++/* ------------------------------------------------------------------ pictures */+typedef struct {+ const uint8_t *px;+ const uint16_t *col;+ const uint8_t *opa;+ int w, h, fmt;+} Img;++static Img img(int im) {+ const ImageRec *r = image_rec(im);+ Img m;+ m.w = r->w, m.h = r->h, m.fmt = r->fmt;+ m.px = cc_data + r->px;+ if (r->fmt == FMT_RGB) {+ m.col = (const uint16_t *)(const void *)m.px, m.opa = NULL;+ } else {+ m.col = (const uint16_t *)(const void *)(cc_data + r->pal);+ m.opa = cc_data + r->pal + 2 * (r->ncolors_1 + 1);+ }+ return m;+}+int gfx_image_w(int im) { return image_rec(im)->w; }+int gfx_image_h(int im) { return image_rec(im)->h; }++/* the colour and opacity (0..255) of pixel (x, y) */+static inline uint16_t texel(const Img *m, int x, int y, int *a) {+ if (m->fmt == FMT_RGB) {+ *a = 255;+ return m->col[y * m->w + x];+ }+ int i;+ if (m->fmt == FMT_P8)+ i = m->px[y * m->w + x];+ else {+ uint8_t b = m->px[y * ((m->w + 1) >> 1) + (x >> 1)];+ i = x & 1 ? b >> 4 : b & 15;+ }+ *a = m->opa[i];+ return m->col[i];+}++void gfx_image_part(int im, int sx, int sy, int sw, int sh, int x, int y, int alpha) {+ Img m = img(im);+ int dx = x, dy = y, w = sw, h = sh;+ if (alpha <= 0 || !clipr(&dx, &dy, &w, &h)) return;+ sx += dx - x, sy += dy - y;+ for (int r = 0; r < h; r++) {+ uint16_t *p = at(dx, dy + r);+ for (int i = 0; i < w; i++) {+ int a;+ uint16_t c = texel(&m, sx + i, sy + r, &a);+ if (a) put(p + i, c, (a + (a >> 7)) * alpha >> 8);+ }+ }+}+void gfx_image(int im, int x, int y, int alpha) { gfx_image_part(im, 0, 0, gfx_image_w(im), gfx_image_h(im), x, y, alpha); }++void gfx_image_dark(int im, int x, int y, int alpha) {+ Img m = img(im);+ int dx = x, dy = y, w = m.w, h = m.h;+ if (alpha <= 0 || !clipr(&dx, &dy, &w, &h)) return;+ for (int r = 0; r < h; r++) {+ uint16_t *p = at(dx, dy + r);+ for (int i = 0; i < w; i++) {+ int a;+ texel(&m, dx - x + i, dy - y + r, &a);+ if (a) put(p + i, BLACK, (a + (a >> 7)) * alpha >> 8);+ }+ }+}++/* the colour at (u, v), in 1/256ths of a pixel of the picture, between its four nearest pixels;+ * opacity 0..255. wrap: tiled, else clear outside */+static uint16_t bilinear(const Img *m, int u, int v, bool wrap, int *a_out) {+ u -= 128, v -= 128;+ int x0 = u >> 8, y0 = v >> 8, fx = u & 255, fy = v & 255;+ uint32_t R = 0, G = 0, B = 0, A = 0;+ for (int k = 0; k < 4; k++) {+ int x = x0 + (k & 1), y = y0 + (k >> 1);+ int w = (k & 1 ? fx : 256 - fx) * (k >> 1 ? fy : 256 - fy); /* 0..65536 */+ if (!w) continue;+ if (wrap) {+ x %= m->w, y %= m->h;+ if (x < 0) x += m->w;+ if (y < 0) y += m->h;+ } else if ((unsigned)x >= (unsigned)m->w || (unsigned)y >= (unsigned)m->h)+ continue;+ int a;+ uint16_t c = texel(m, x, y, &a);+ if (!a) continue;+ uint32_t wa = (uint32_t)(w >> 8) * (uint32_t)a; /* 0..65280 */+ R += (c >> 11) * wa, G += ((c >> 5) & 63) * wa, B += (c & 31) * wa, A += wa;+ }+ *a_out = (int)(A >> 8);+ if (!A) return 0;+ return (uint16_t)((R / A) << 11 | (G / A) << 5 | (B / A));+}++void gfx_image_scaled(int im, float x, float y, float w, float h, int alpha) {+ if (w < 0.5f || h < 0.5f || alpha <= 0) return;+ int x0 = (int)floorf(x), y0 = (int)floorf(y), x1 = (int)ceilf(x + w), y1 = (int)ceilf(y + h);+ if (x0 < g_x0) x0 = g_x0;+ if (y0 < g_y0) y0 = g_y0;+ if (x1 > g_x1) x1 = g_x1;+ if (y1 > g_y1) y1 = g_y1;+ if (x1 <= x0 || y1 <= y0) return;+ Img m = img(im);+ float su = m.w / w * 256, sv = m.h / h * 256;+ for (int py = y0; py < y1; py++) {+ int v = (int)((py + 0.5f - y) * sv);+ uint16_t *p = at(x0, py);+ for (int px = x0; px < x1; px++, p++) {+ int u = (int)((px + 0.5f - x) * su), a;+ uint16_t c = bilinear(&m, u, v, false, &a);+ if (a) put(p, c, (a + (a >> 7)) * alpha >> 8);+ }+ }+}++void gfx_image_rotated(int im, float cx, float cy, float w, float h, float angle, int alpha) {+ if (w < 0.5f || h < 0.5f || alpha <= 0) return;+ float c = cosf(angle), s = sinf(angle);+ float ex = (fabsf(c) * w + fabsf(s) * h) / 2, ey = (fabsf(s) * w + fabsf(c) * h) / 2;+ int x0 = (int)floorf(cx - ex), y0 = (int)floorf(cy - ey), x1 = (int)ceilf(cx + ex), y1 = (int)ceilf(cy + ey);+ if (x0 < g_x0) x0 = g_x0;+ if (y0 < g_y0) y0 = g_y0;+ if (x1 > g_x1) x1 = g_x1;+ if (y1 > g_y1) y1 = g_y1;+ if (x1 <= x0 || y1 <= y0) return;+ Img m = img(im);+ float ku = m.w / w * 256, kv = m.h / h * 256;+ /* screen (dx, dy) from the centre -> picture: turned back by angle */+ float uxs = c * ku, uys = s * ku, vxs = -s * kv, vys = c * kv;+ float hu = m.w * 128.f, hv = m.h * 128.f;+ for (int py = y0; py < y1; py++) {+ float dy = py + 0.5f - cy, dx = x0 + 0.5f - cx;+ float u = hu + dx * uxs + dy * uys, v = hv + dx * vxs + dy * vys;+ uint16_t *p = at(x0, py);+ for (int px = x0; px < x1; px++, p++, u += uxs, v += vxs) {+ if (u < -256 || v < -256 || u >= (m.w + 1) * 256.f || v >= (m.h + 1) * 256.f) continue;+ int a;+ uint16_t col = bilinear(&m, (int)u, (int)v, false, &a);+ if (a) put(p, col, (a + (a >> 7)) * alpha >> 8);+ }+ }+}++void gfx_pattern(int im, int x, int y, int w, int h, float tw, float th, float ox, float oy, int alpha) {+ if (alpha <= 0 || !clipr(&x, &y, &w, &h)) return;+ Img m = img(im);+ bool same = fabsf(tw - m.w) < 0.01f && fabsf(th - m.h) < 0.01f;+ float su = m.w / tw * 256, sv = m.h / th * 256;+ for (int r = 0; r < h; r++) {+ uint16_t *p = at(x, y + r);+ float fy = y + r + 0.5f - oy;+ if (same) {+ int ty = (int)floorf(fy) % m.h;+ if (ty < 0) ty += m.h;+ int tx = (int)floorf(x + 0.5f - ox) % m.w;+ if (tx < 0) tx += m.w;+ for (int i = 0; i < w; i++, p++) {+ int a;+ uint16_t c = texel(&m, tx, ty, &a);+ if (a) put(p, c, (a + (a >> 7)) * alpha >> 8);+ if (++tx == m.w) tx = 0;+ }+ continue;+ }+ int v = (int)(fy * sv);+ for (int i = 0; i < w; i++, p++) {+ int a;+ uint16_t c = bilinear(&m, (int)((x + i + 0.5f - ox) * su), v, true, &a);+ if (a) put(p, c, (a + (a >> 7)) * alpha >> 8);+ }+ }+}++void gfx_icon(int index, int x, int y, int alpha) {+ int im = icon_index_image(index);+ if (im >= 0) gfx_image(im, x, y, alpha);+}+void gfx_icon_scaled(int index, float x, float y, float size, int alpha) {+ int im = icon_index_image(index);+ if (im < 0) return;+ if (fabsf(size - 24) < 0.01f) gfx_image(im, (int)x, (int)y, alpha);+ else gfx_image_scaled(im, x, y, size, size, alpha);+}++/* ------------------------------------------------------------------ text */+typedef struct {+ uint8_t first, count, ascent, line;+} FontHead;+typedef struct {+ uint8_t w, h;+ int8_t x, y;+ uint8_t adv, pad;+ uint16_t off;+} Glyph;++static const uint8_t *font_at(int f) { return cc_data + RES(uint32_t, OFF_FONTS)[f]; }+static const Glyph *glyph(int f, unsigned char ch, const uint8_t **data) {+ const uint8_t *p = font_at(f);+ const FontHead *hd = (const FontHead *)(const void *)p;+ int i = ch < 127 ? ch - 32 : ch >= 0x80 ? ch - 0x80 + 96 : -1;+ if (i < 0 || i >= hd->count) return NULL;+ const Glyph *g = (const Glyph *)(const void *)(p + 4) + i;+ *data = p + 4 + 8 * hd->count + g->off;+ return g;+}+int gfx_font_ascent(int f) { return ((const FontHead *)(const void *)font_at(f))->ascent; }+int gfx_font_line(int f) { return ((const FontHead *)(const void *)font_at(f))->line; }++static int draw_char(int f, int x, int y, unsigned char ch, uint16_t c, int alpha) {+ const uint8_t *d;+ const Glyph *g = glyph(f, ch, &d);+ if (!g) return x;+ int gx = x + g->x, gy = y + g->y;+ if (g->w && gfx_visible(gx, gy, g->w, g->h)) {+ int stride = (g->w + 1) >> 1;+ for (int r = 0; r < g->h; r++) {+ int yy = gy + r;+ if (yy < g_y0 || yy >= g_y1) continue;+ for (int i = 0; i < g->w; i++) {+ int xx = gx + i;+ if (xx < g_x0 || xx >= g_x1) continue;+ uint8_t b = d[r * stride + (i >> 1)];+ int cov = i & 1 ? b >> 4 : b & 15;+ if (cov) put(at(xx, yy), c, cov * alpha / 15);+ }+ }+ }+ return x + g->adv;+}+static int char_width(int f, unsigned char ch) {+ const uint8_t *d;+ const Glyph *g = glyph(f, ch, &d);+ return g ? g->adv : 0;+}+int gfx_text(int f, int x, int y, const char *s, uint16_t c, int alpha) {+ for (; *s; s++)+ if ((unsigned char)*s >= 32) x = draw_char(f, x, y, (unsigned char)*s, c, alpha);+ return x;+}+int gfx_text_n_width(int f, const char *s, int n) {+ int w = 0;+ for (int i = 0; i < n && s[i]; i++)+ if ((unsigned char)s[i] >= 32) w += char_width(f, (unsigned char)s[i]);+ return w;+}+int gfx_text_width(int f, const char *s) { return gfx_text_n_width(f, s, 1 << 30); }+int gfx_text_center(int f, int cx, int y, const char *s, uint16_t c, int alpha) {+ return gfx_text(f, cx - gfx_text_width(f, s) / 2, y, s, c, alpha);+}+int gfx_text_right(int f, int rx, int y, const char *s, uint16_t c, int alpha) {+ return gfx_text(f, rx - gfx_text_width(f, s), y, s, c, alpha);+}+void gfx_text_outline(int f, int x, int y, const char *s, uint16_t c, int alpha) {+ static const int8_t d[8][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, -1}, {1, -1}, {-1, 1}, {1, 1}};+ for (int i = 0; i < 8; i++) gfx_text(f, x + d[i][0], y + d[i][1], s, BLACK, i < 4 ? alpha : alpha / 3);+ gfx_text(f, x, y + 2, s, BLACK, alpha / 3);+ gfx_text(f, x, y, s, c, alpha);+}+void gfx_text_outline_center(int f, int cx, int y, const char *s, uint16_t c, int alpha) {+ gfx_text_outline(f, cx - gfx_text_width(f, s) / 2, y, s, c, alpha);+}++/* ------------------------------------------------------------------ paragraphs */+typedef struct {+ const ParaStyle *st;+ bool bold, italic;+} Pen;+static int pen_font(const Pen *p) { return p->bold ? p->st->bold : p->italic ? p->st->italic : p->st->font; }+static uint16_t pen_color(const Pen *p) {+ return p->bold ? p->st->bold_color : p->italic ? p->st->italic_color : p->st->color;+}+static void pen_code(Pen *p, unsigned char c) {+ if (c == 1) p->bold = true;+ if (c == 2) p->bold = false;+ if (c == 3) p->italic = true;+ if (c == 4) p->italic = false;+}++int gfx_para(const ParaStyle *st, int x, int y, int w, const char *s, bool draw) {+ Pen pen = {st, false, false};+ int top = y, base = y + gfx_font_ascent(st->font);+ const unsigned char *p = (const unsigned char *)s;+ while (*p) {+ if (*p == 5) { /* a line across */+ if (draw) {+ gfx_hgrad(x, base - gfx_font_ascent(st->font) + 3, w / 2, 1, BLACK, 0, 120);+ gfx_hgrad(x + w / 2, base - gfx_font_ascent(st->font) + 3, w - w / 2, 1, BLACK, 120, 0);+ gfx_hgrad(x, base - gfx_font_ascent(st->font) + 4, w / 2, 1, WHITE, 0, 40);+ gfx_hgrad(x + w / 2, base - gfx_font_ascent(st->font) + 4, w - w / 2, 1, WHITE, 40, 0);+ }+ base += 7, p++;+ if (*p == '\n') p++;+ continue;+ }+ /* the words that fit on this line */+ const unsigned char *start = p, *end = p, *q = p;+ Pen at_start = pen, scan = pen;+ int width = 0, fit_width = 0;+ while (*q && *q != '\n' && *q != 5) {+ int ww = 0;+ const unsigned char *word = q;+ Pen wp = scan;+ while (*q == ' ') ww += char_width(pen_font(&wp), ' '), q++;+ while (*q && *q != ' ' && *q != '\n' && *q != 5) {+ if (*q < 32) pen_code(&wp, *q);+ else ww += char_width(pen_font(&wp), *q);+ q++;+ }+ if (width + ww > w && end != start) {+ q = word;+ break;+ }+ width += ww, scan = wp, end = q, fit_width = width;+ }+ if (end == start && *q && *q != '\n' && *q != 5) end = q; /* (a word longer than the line) */+ if (draw) {+ int xx = x + (st->align ? (w - fit_width) / 2 : 0);+ Pen dp = at_start;+ for (const unsigned char *c = start; c < end; c++) {+ if (*c < 32) pen_code(&dp, *c);+ else if (base - gfx_font_ascent(st->font) < g_y1 && base + 4 > g_y0)+ xx = draw_char(pen_font(&dp), xx, base, *c, pen_color(&dp), 256);+ else+ xx += char_width(pen_font(&dp), *c);+ }+ }+ for (const unsigned char *c = start; c < end; c++)+ if (*c < 32) pen_code(&pen, *c);+ p = end;+ while (*p == ' ') p++;+ if (*p == '\n') p++;+ base += st->line;+ }+ return base - gfx_font_ascent(st->font) - top;+}diff --git a/games/cookieclicker/src/gfx.h b/games/cookieclicker/src/gfx.hnew file mode 100644index 00000000..d53abc04--- /dev/null+++ b/games/cookieclicker/src/gfx.h@@ -0,0 +1,78 @@+/* Cookie Clicker: drawing, a band of the screen at a time.+ *+ * gfx_render(x, y, w, h, draw) has draw() paint the rectangle a band of GFX_BAND rows at a+ * time, then sends each band to the screen: everything below is drawn in the screen's+ * coordinates, clipped to the band (g_x0..g_x1, g_y0..g_y1). Colours are RGB565; opacities+ * 0 to 256. Pictures are data.bin's (IM_*), drawn as they are, scaled, rotated or tiled. */+#ifndef CC_GFX_H+#define CC_GFX_H+#include <stdbool.h>+#include <stdint.h>+#include "plat.h"++#define GFX_BAND 16+#define RGB(r, g, b) ((uint16_t)(((r) >> 3) << 11 | ((g) >> 2) << 5 | (b) >> 3))+#define HEX(c) RGB(((c) >> 16) & 255, ((c) >> 8) & 255, (c) & 255)+#define WHITE 0xFFFF+#define BLACK 0x0000++void gfx_set_band_memory(uint16_t *band); /* SCREEN_W * GFX_BAND colours */+void gfx_render(int x, int y, int w, int h, void (*draw)(void));+extern int g_x0, g_y0, g_x1, g_y1; /* the band being drawn (clip), in screen coordinates */+static inline bool gfx_visible(int x, int y, int w, int h) { return x < g_x1 && y < g_y1 && x + w > g_x0 && y + h > g_y0; }+/* narrows the clip (within the band) until gfx_unclip */+void gfx_clip(int x, int y, int w, int h);+void gfx_unclip(void);++/* blending: normal, or added light (the game's "lighter") */+enum { BLEND_NORMAL, BLEND_ADD };+void gfx_blend(int mode);++uint16_t gfx_mix(uint16_t a, uint16_t b, int t); /* a to b, t from 0 to 256 */+void gfx_fill(int x, int y, int w, int h, uint16_t c);+void gfx_fill_alpha(int x, int y, int w, int h, uint16_t c, int alpha);+void gfx_hgrad(int x, int y, int w, int h, uint16_t c, int alpha0, int alpha1); /* opacity left to right */+void gfx_vgrad(int x, int y, int w, int h, uint16_t c, int alpha0, int alpha1); /* top to bottom */+void gfx_rect(int x, int y, int w, int h, uint16_t c, int alpha); /* an outline */+void gfx_round_rect(int x, int y, int w, int h, int r, uint16_t c, int alpha);+void gfx_line(float x0, float y0, float x1, float y1, uint16_t c, int alpha);+void gfx_disc(float cx, float cy, float r, uint16_t c, int alpha);++int gfx_image_w(int im);+int gfx_image_h(int im);+void gfx_image(int im, int x, int y, int alpha);+void gfx_image_part(int im, int sx, int sy, int sw, int sh, int x, int y, int alpha);+/* scaled to w x h at (x, y), smoothly */+void gfx_image_scaled(int im, float x, float y, float w, float h, int alpha);+/* centred on (cx, cy), w x h, turned by angle (radians, clockwise on screen) */+void gfx_image_rotated(int im, float cx, float cy, float w, float h, float angle, int alpha);+/* the rectangle tiled with the picture at tw x th, the tiles shifted by (ox, oy) */+void gfx_pattern(int im, int x, int y, int w, int h, float tw, float th, float ox, float oy, int alpha);+/* an icon of the game's sheet (its index: y * ICON_COLS + x), 24 pixels, or scaled to size */+void gfx_icon(int index, int x, int y, int alpha);+void gfx_icon_scaled(int index, float x, float y, float size, int alpha);+/* the picture as a dark silhouette (the store's buildings not yet seen) */+void gfx_image_dark(int im, int x, int y, int alpha);++/* text: y is the baseline; returns the x after it */+int gfx_text(int font, int x, int y, const char *s, uint16_t c, int alpha);+int gfx_text_width(int font, const char *s);+int gfx_text_n_width(int font, const char *s, int n);+int gfx_text_center(int font, int cx, int y, const char *s, uint16_t c, int alpha);+int gfx_text_right(int font, int rx, int y, const char *s, uint16_t c, int alpha);+/* outlined in black, as the game writes its titles and numbers */+void gfx_text_outline(int font, int x, int y, const char *s, uint16_t c, int alpha);+void gfx_text_outline_center(int font, int cx, int y, const char *s, uint16_t c, int alpha);+int gfx_font_ascent(int font);+int gfx_font_line(int font);++/* a paragraph of the game's markup (0x01 bold, 0x02 plain, 0x03 italic, 0x04 back, 0x05 a line across,+ * \n), wrapped to w pixels from (x, y: the top); returns its height. With draw false, only measures. */+typedef struct {+ int font, bold, italic; /* the fonts for plain, bold and italic text */+ uint16_t color, bold_color, italic_color;+ int line; /* line height */+ int align; /* 0 left, 1 centred */+} ParaStyle;+int gfx_para(const ParaStyle *st, int x, int y, int w, const char *s, bool draw);+#endifdiff --git a/games/cookieclicker/src/grimoire.c b/games/cookieclicker/src/grimoire.cnew file mode 100644index 00000000..6a8abcba--- /dev/null+++ b/games/cookieclicker/src/grimoire.c@@ -0,0 +1,457 @@+/* The Grimoire (the wizard towers' minigame, minigameGrimoire.js): magic that refills by itself, the+ * slower the emptier it is, and nine spells to spend it on; each may backfire. Its panel shows in+ * the buildings' view: the spells in the game's frames, the magic meter, the spells cast. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "ui.h"++enum { SP_CONJURE, SP_FATE, SP_STRETCH, SP_EDIFICE, SP_HAGGLER, SP_PIXIES, SP_GAMBLER, SP_RESURRECT, SP_DIMINISH, N_SPELLS };+typedef struct {+ const char *name, *desc, *fail_desc;+ int16_t icon;+ uint8_t cost_min;+ float cost_percent;+} Spell;+static const Spell spells[N_SPELLS] = {+ {"Conjure Baked Goods", "Summon half an hour worth of your CpS, capped at 15% of your cookies owned.",+ "Trigger a 15-minute clot and lose 15 minutes of CpS.", ICON(21, 11), 2, 0.4f},+ {"Force the Hand of Fate",+ "Summon a random golden cookie. Each existing golden cookie makes this spell +15% more likely to backfire.",+ "Summon an unlucky wrath cookie.", ICON(22, 11), 10, 0.6f},+ {"Stretch Time", "All active buffs gain 10% more time (up to 5 more minutes).",+ "All active buffs are shortened by 20% (up to 10 minutes shorter).", ICON(23, 11), 8, 0.2f},+ {"Spontaneous Edifice",+ "The spell picks a random building you could afford if you had twice your current cookies, and gives it to you "+ "for free. The building selected must be under 400, and cannot be your most-built one (unless it is your only "+ "one).",+ "Lose a random building.", ICON(24, 11), 20, 0.75f},+ {"Haggler's Charm", "Upgrades are 2% cheaper for 1 minute.", "Upgrades are 2% more expensive for an hour.\x03What's "+ "that spell? Loadsamoney!\x04", ICON(25, 11), 10, 0.1f},+ {"Summon Crafty Pixies", "Buildings are 2% cheaper for 1 minute.", "Buildings are 2% more expensive for an hour.",+ ICON(26, 11), 10, 0.2f},+ {"Gambler's Fever Dream", "Cast a random spell at half the magic cost, with twice the chance of backfiring.", NULL,+ ICON(27, 11), 3, 0.05f},+ {"Resurrect Abomination", "Instantly summon a wrinkler if conditions are fulfilled.", "Pop one of your wrinklers.",+ ICON(28, 11), 20, 0.1f},+ {"Diminish Ineptitude", "Spells backfire 10 times less for the next 5 minutes.",+ "Spells backfire 5 times more for the next 10 minutes.", ICON(29, 11), 5, 0.2f},+};++static float magic_max, magic_ps;+static int sel; /* the spell chosen; N_SPELLS: the lump refill */+static int pending = -1, pending_t; /* the Gambler's Fever Dream: the spell it casts in a second */+static float pending_cost, pending_self;+extern bool refill_lump(int n);+extern bool can_refill_lump(void);+extern bool can_lumps(void);+extern bool spawn_wrinkler(void);+extern bool pop_random_wrinkler(void);++static void compute_magic_max(void) {+ const Building *t = &S.buildings[B_WIZARD_TOWER];+ double towers = t->amount > 1 ? t->amount : 1, lvl = t->level > 1 ? t->level : 1;+ magic_max = (float)floor(4 + pow(towers, 0.6) + log((towers + (lvl - 1) * 10) / 15 + 1) * 15);+ if (S.grimoire_magic > magic_max) S.grimoire_magic = magic_max;+}++static int spell_cost(int s) {+ double out = spells[s].cost_min + magic_max * spells[s].cost_percent;+ out *= 1 - 0.1 * aura_mult(AURA_SUPREME_INTELLECT);+ return (int)floor(out);+}++static double fail_chance(int s) {+ double f = 0.15;+ if (has_buff(BUFF_MAGIC_ADEPT)) f *= 0.1;+ if (has_buff(BUFF_MAGIC_INEPT)) f *= 5;+ f *= 1 + 0.1 * aura_mult(AURA_SUPREME_INTELLECT);+ if (s == SP_FATE) f += 0.15 * G.nshimmers_golden;+ return f;+}++static void say(const char *s) { popup(s, LEFT_W / 2, COOKIE_Y - 30); }++static Shimmer *golden(int force, int wrath) {+ Shimmer *m = shimmer_new(SHIMMER_GOLDEN, force, false);+ if (m) m->wrath = (uint8_t)wrath;+ return m;+}++/* a spell's effect: true if it took (false: nothing to do, no magic spent) */+static bool spell_win(int s) {+ char t[96], c[48];+ switch (s) {+ case SP_CONJURE: {+ double v = S.cookies * 0.15 < G.cookies_ps * 60 * 30 ? S.cookies * 0.15 : G.cookies_ps * 60 * 30;+ if (v < 7) v = 7;+ earn(v);+ cookies_str(v, 0, c);+ snprintf(t, sizeof t, "You magic \x01%s\x02 out of thin air.", c);+ notify("Conjure Baked Goods!", t, ICON(21, 11), 6);+ snprintf(t, sizeof t, "+%s!", c);+ say(t);+ return true;+ }+ case SP_FATE: {+ int choices[8], n = 0;+ choices[n++] = GC_FRENZY, choices[n++] = GC_LUCKY;+ if (!has_buff(BUFF_DRAGONFLIGHT)) choices[n++] = GC_CLICK_FRENZY;+ if (rnd() < 0.1) choices[n++] = GC_STORM, choices[n++] = GC_STORM, choices[n++] = GC_BLAB;+ if (G.buildings_owned >= 10 && rnd() < 0.25) choices[n++] = GC_BUILDING_SPECIAL;+ if (rnd() < 0.15) n = 0, choices[n++] = GC_STORM_DROP;+ if (rnd() < 0.0001) choices[n++] = GC_SUGAR_LUMP;+ Shimmer *m = golden(choices[rnd_int(n)], 0);+ if (m && m->force == GC_STORM_DROP) m->size_mult = (float)(rnd() * 0.75 + 0.25);+ say("Promising fate!");+ return true;+ }+ case SP_STRETCH: {+ int changed = 0;+ for (int i = 0; i < MAX_BUFFS; i++) {+ Buff *b = &S.buffs[i];+ if (!b->used) continue;+ int32_t gain = b->max_time / 10 < FPS * 60 * 5 ? b->max_time / 10 : FPS * 60 * 5;+ b->max_time += gain, b->time += gain, changed++;+ }+ if (!changed) {+ say("No buffs to alter!");+ return false;+ }+ say("Zap! Buffs lengthened.");+ return true;+ }+ case SP_EDIFICE: {+ int max = 0, owned = 0, cand[NB], n = 0;+ for (int b = 0; b < NB; b++) {+ if (S.buildings[b].amount > max) max = S.buildings[b].amount;+ if (S.buildings[b].amount > 0) owned++;+ }+ for (int b = 0; b < NB; b++)+ if ((S.buildings[b].amount < max || owned == 1) && building_price(b) <= S.cookies * 2 && S.buildings[b].amount < 400)+ cand[n++] = b;+ if (!n) {+ say("No buildings to improve!");+ return false;+ }+ int b = cand[rnd_int(n)];+ Building *m = &S.buildings[b];+ m->amount++, m->bought++, G.buildings_owned++;+ if (m->amount > m->highest) m->highest = m->amount;+ extern void building_bought(int b);+ building_bought(b);+ G.recalculate = true, G.store_dirty = true;+ snprintf(t, sizeof t, "A new %s\nbursts out of the ground.", res_text(building_rec(b)->single));+ say(t);+ return true;+ }+ case SP_HAGGLER:+ kill_buff(BUFF_HAGGLER_MISERY);+ gain_buff(BUFF_HAGGLER_LUCK, 60, 2, 0);+ say("Upgrades are cheaper!");+ return true;+ case SP_PIXIES:+ kill_buff(BUFF_PIXIE_MISERY);+ gain_buff(BUFF_PIXIE_LUCK, 60, 2, 0);+ say("Crafty pixies\nBuildings are cheaper!");+ return true;+ case SP_GAMBLER: {+ int self = spell_cost(SP_GAMBLER), cand[N_SPELLS], n = 0;+ for (int k = 0; k < N_SPELLS; k++)+ if (k != SP_GAMBLER && S.grimoire_magic - self >= spell_cost(k) * 0.5f) cand[n++] = k;+ if (!n) {+ say("No eligible spells!");+ return false;+ }+ pending = cand[rnd_int(n)];+ pending_cost = spell_cost(pending) * 0.5f, pending_self = (float)self, pending_t = FPS;+ char cs[32];+ beautify(pending_cost, 0, cs);+ snprintf(t, sizeof t, "Casting %s\nfor %s magic...", spells[pending].name, cs);+ say(t);+ return true;+ }+ case SP_RESURRECT:+ if (!spawn_wrinkler()) {+ say("Unable to spawn a wrinkler!");+ return false;+ }+ say("Rise, my precious!");+ return true;+ case SP_DIMINISH:+ kill_buff(BUFF_MAGIC_INEPT);+ gain_buff(BUFF_MAGIC_ADEPT, 5 * 60, 10, 0);+ say("Ineptitude diminished!");+ return true;+ }+ return false;+}++static bool spell_fail(int s) {+ char t[96], c[48];+ switch (s) {+ case SP_CONJURE: {+ Buff *b = gain_buff(BUFF_CLOT, 60 * 15, 0.5, 0);+ double v = (S.cookies * 0.15 < G.cookies_ps * 60 * 15 ? S.cookies * 0.15 : G.cookies_ps * 60 * 15) + 13;+ if (v > S.cookies) v = S.cookies;+ spend(v);+ extern void buff_desc(const Buff *b, char *out, int size);+ char d[96];+ buff_desc(b, d, sizeof d);+ notify("Clot", d, ICON(15, 5), 6);+ cookies_str(v, 0, c);+ snprintf(t, sizeof t, "Backfire!\nSummoning failed! Lost %s!", c);+ say(t);+ return true;+ }+ case SP_FATE: {+ int choices[6], n = 0;+ choices[n++] = GC_CLOT, choices[n++] = GC_RUIN;+ if (rnd() < 0.1) choices[n++] = GC_CURSED_FINGER, choices[n++] = GC_BLOOD_FRENZY;+ if (rnd() < 0.003) choices[n++] = GC_SUGAR_LUMP;+ if (rnd() < 0.1) n = 0, choices[n++] = GC_BLAB;+ golden(choices[rnd_int(n)], 1);+ say("Backfire!\nSinister fate!");+ return true;+ }+ case SP_STRETCH: {+ int changed = 0;+ for (int i = 0; i < MAX_BUFFS; i++) {+ Buff *b = &S.buffs[i];+ if (!b->used) continue;+ int32_t loss = b->time / 5 < FPS * 60 * 10 ? b->time / 5 : FPS * 60 * 10;+ b->time -= loss;+ if (b->time < 0) b->time = 0;+ changed++;+ }+ if (!changed) {+ say("No buffs to alter!");+ return false;+ }+ say("Backfire!\nFizz! Buffs shortened.");+ return true;+ }+ case SP_EDIFICE: {+ if (G.buildings_owned == 0) {+ say("Backfired, but no buildings to destroy!");+ return false;+ }+ int cand[NB], n = 0;+ for (int b = 0; b < NB; b++)+ if (S.buildings[b].amount > 0) cand[n++] = b;+ int b = cand[rnd_int(n)];+ S.buildings[b].amount--, G.buildings_owned--;+ G.recalculate = true, G.store_dirty = true;+ snprintf(t, sizeof t, "Backfire!\nOne of your %s\ndisappears in a puff of smoke.", res_text(building_rec(b)->plural));+ say(t);+ return true;+ }+ case SP_HAGGLER:+ kill_buff(BUFF_HAGGLER_LUCK);+ gain_buff(BUFF_HAGGLER_MISERY, 60 * 60, 2, 0);+ say("Backfire!\nUpgrades are pricier!");+ return true;+ case SP_PIXIES:+ kill_buff(BUFF_PIXIE_LUCK);+ gain_buff(BUFF_PIXIE_MISERY, 60 * 60, 2, 0);+ say("Backfire!\nNasty goblins\nBuildings are pricier!");+ return true;+ case SP_RESURRECT:+ if (!pop_random_wrinkler()) {+ say("Backfire!\nBut no wrinkler was harmed.");+ return false;+ }+ say("Backfire!\nSo long, ugly...");+ return true;+ case SP_DIMINISH:+ kill_buff(BUFF_MAGIC_ADEPT);+ gain_buff(BUFF_MAGIC_INEPT, 10 * 60, 5, 0);+ say("Backfire!\nIneptitude magnified!");+ return true;+ }+ return false;+}++/* casts a spell (cost < 0: its usual cost); false if there isn't the magic, or it did nothing */+static bool cast(int s, float cost, double fail_max, bool passthrough) {+ if (cost < 0) cost = (float)spell_cost(s);+ if (S.grimoire_magic < cost) return false;+ double fail = fail_chance(s);+ if (fail_max > 0 && fail < fail_max) fail = fail_max;+ /* (the game seeds its random with the spells cast: the same cast has the same outcome) */+ uint32_t keep = G.seed;+ G.seed = 0x9E3779B9u * (S.spells_cast_total + 1) ^ (uint32_t)S.bakery_name1 << 8 ^ S.bakery_name2 ^ 0x5bd1e995u;+ if (!G.seed) G.seed = 1;+ bool failed = spells[s].fail_desc && rnd() >= 1 - fail;+ bool out = failed ? spell_fail(s) : spell_win(s);+ G.seed = keep;+ if (!out) return false;+ if (!passthrough) {+ S.spells_cast++, S.spells_cast_total++;+ if (S.spells_cast_total >= 9) win(A_BIBBIDI_BOBBIDI_BOO);+ if (S.spells_cast_total >= 99) win(A_IM_THE_WIZ);+ if (S.spells_cast_total >= 999) win(A_A_WIZARD_IS_YOU);+ }+ S.grimoire_magic -= cost;+ if (S.grimoire_magic < 0) S.grimoire_magic = 0;+ return true;+}++/* ------------------------------------------------------------------ the frames */+void grimoire_logic(void) {+ if (S.buildings[B_WIZARD_TOWER].level < 1) return;+ if (G.T % 5 == 0 || magic_max == 0) compute_magic_max();+ double m = S.grimoire_magic / (magic_max > 100 ? magic_max : 100);+ magic_ps = (float)((sqrt(m) > 0.002 ? sqrt(m) : 0.002) * 0.002);+ S.grimoire_magic += magic_ps;+ if (S.grimoire_magic > magic_max) S.grimoire_magic = magic_max;+ if (pending >= 0 && --pending_t <= 0) {+ int s = pending;+ pending = -1;+ if (!cast(s, pending_cost, 0.5, true)) {+ S.grimoire_magic += pending_self;+ say("That's too bad!\nMagic refunded.");+ }+ }+}+void grimoire_reset(bool hard) {+ compute_magic_max();+ S.grimoire_magic = magic_max;+ S.spells_cast = 0;+ if (hard) S.spells_cast_total = 0;+ pending = -1;+}+/* its first level: the meter starts full */+void grimoire_on_level(void) {+ compute_magic_max();+ if (S.buildings[B_WIZARD_TOWER].level == 1) S.grimoire_magic = magic_max;+}++/* ------------------------------------------------------------------ its panel */+#define GX STORE_X+#define GW STORE_W+#define SPELL_W 30+#define SPELL_H 37+static void spell_pos(int s, int *x, int *y) {+ int row = s < 5 ? 0 : 1, n = row ? 4 : 5, k = row ? s - 5 : s;+ int gap = 3, total = n * SPELL_W + (n - 1) * gap;+ *x = GX + (GW - total) / 2 + k * (SPELL_W + gap);+ *y = NEWS_H + 28 + row * (SPELL_H + 4);+}++void grimoire_draw(void) {+ gfx_clip(GX, NEWS_H, GW, SCREEN_H - NEWS_H);+ gfx_pattern(IM_MG_BG_GRIMOIRE, GX, NEWS_H, GW, SCREEN_H - NEWS_H, 192, 48, GX, NEWS_H, 256);+ gfx_image_scaled(IM_BORDER_SOFT, GX, NEWS_H, GW, SCREEN_H - NEWS_H, 256);+ gfx_text_outline_center(F_KAVOON, GX + GW / 2, NEWS_H + 20, "Grimoire", WHITE, 256);+ for (int s = 0; s < N_SPELLS; s++) {+ int x, y;+ spell_pos(s, &x, &y);+ bool ready = S.grimoire_magic >= spell_cost(s);+ int col = (s + 3) % 4; /* (the game's frames: nth-child(4n+1) ... ) */+ int row = sel == s ? 1 : 0;+ gfx_fill_alpha(x + 2, y + 2, SPELL_W, SPELL_H, BLACK, 110);+ gfx_image_part(IM_SPELL_BG, col * SPELL_W, row * SPELL_H, SPELL_W, SPELL_H, x, y - (sel == s), ready ? 256 : 205);+ gfx_icon(spells[s].icon, x + 3, y + 2 - (sel == s && ready ? (int)(fabsf(sinf(G.real_t * 0.2f)) * 2) : 0),+ ready ? 256 : 205);+ char t[16];+ snprintf(t, sizeof t, "%d", spell_cost(s));+ gfx_text_outline_center(F_NAME_SMALL, x + SPELL_W / 2, y + SPELL_H - 3, t,+ ready ? sel == s ? WHITE : RGB(220, 220, 220) : RGB(255, 51, 51), 256);+ }+ /* the magic meter, its lump refill at its left */+ int bw = (int)(magic_max * 1.5f), bx, by = NEWS_H + 118;+ if (bw > GW - 40) bw = GW - 40;+ if (bw < 20) bw = 20;+ bx = GX + (GW - bw) / 2 + 10;+ gfx_icon_scaled(ICON(29, 14), bx - 22, by - 3, 18, can_lumps() ? 256 : 120);+ if (sel == N_SPELLS) gfx_rect(bx - 23, by - 4, 20, 20, WHITE, 256);+ gfx_fill_alpha(bx - 1, by - 1, bw + 2, 12, BLACK, 200);+ int fw = magic_max > 0 ? (int)(bw * S.grimoire_magic / magic_max) : 0;+ for (int i = 0; i < fw; i++) {+ float k = fmodf(i + G.real_t * 0.5f, 32) / 32;+ gfx_vgrad(bx + i, by, 1, 10, gfx_mix(HEX(0x7a3fd1), HEX(0xc58fff), (int)(k * 256)), 256, 200);+ }+ gfx_rect(bx - 2, by - 2, bw + 4, 14, HEX(0xece2b6), 200);+ char t[96], a[24], b[24];+ beautify(S.grimoire_magic, 0, a);+ beautify(floor(magic_max), 0, b);+ if (S.grimoire_magic < magic_max) {+ char ps[24];+ double r = magic_ps * FPS > 0.01 ? magic_ps * FPS : 0.01;+ beautify(r, 2, ps);+ snprintf(t, sizeof t, "%s/%s (+%s/s)", a, b, ps);+ } else+ snprintf(t, sizeof t, "%s/%s", a, b);+ gfx_text_outline_center(F_SMALL, bx + bw / 2, by + 9, t, WHITE, 256);+ snprintf(t, sizeof t, "Spells cast: %u (total: %u)", S.spells_cast, S.spells_cast_total);+ gfx_text_outline_center(F_SMALL, GX + GW / 2, by + 26, t, RGB(200, 200, 200), 256);+ if (aura_mult(AURA_SUPREME_INTELLECT) > 0)+ gfx_text_outline_center(F_SMALL, GX + GW / 2, by + 38, "Supreme Intellect: 10% cheaper, 10% more fails",+ RGB(200, 180, 255), 256);+ gfx_text_center(F_SMALL, GX + GW / 2, SCREEN_H - 6, "EXE cast Back close", RGB(160, 160, 160), 256);+ gfx_unclip();+}++/* the spell's tooltip (over the left column, as the store's) */+int grimoire_tip(int x, int y, int w, bool draw) {+ char l[400], c[32];+ int yy = y;+ if (sel == N_SPELLS) {+ extern double lump_refill_remaining(void);+ snprintf(l, sizeof l, "Press EXE to refill \x01" "100 units\x02 of your magic meter for \x01" "1 sugar lump\x02.\n%s",+ can_refill_lump() ? "(can be done once every 15 minutes)" : "(usable again later)");+ return gfx_para(&PS_SMALL, x, y, w, l, draw);+ }+ const Spell *s = &spells[sel];+ if (draw) gfx_icon(s->icon, x, yy, 256);+ if (draw) gfx_text_outline(F_NAME, x + 27, yy + 11, s->name, WHITE, 256);+ int cost = spell_cost(sel);+ snprintf(c, sizeof c, "%d", cost);+ char cb[64] = "";+ if (s->cost_percent) snprintf(cb, sizeof cb, " (%d magic +%d%% of max magic)", s->cost_min, (int)ceilf(s->cost_percent * 100));+ if (draw) {+ int tx = x + 27;+ tx = gfx_text(F_SMALL, tx, yy + 22, "Magic cost: ", RGB(204, 204, 204), 256);+ tx = gfx_text(F_BOLD, tx, yy + 22, c, cost <= S.grimoire_magic ? RGB(102, 255, 102) : RGB(255, 102, 102), 256);+ gfx_text(F_SMALL, tx, yy + 22, cb, RGB(170, 170, 170), 256);+ }+ yy += 26;+ if (s->fail_desc) {+ snprintf(l, sizeof l, "Chance to backfire: %d%%", (int)ceil(100 * fail_chance(sel)));+ if (draw) gfx_text(F_SMALL, x + 27, yy + 6, l, RGB(255, 102, 102), 256);+ yy += 10;+ }+ if (draw) tip_line(x, yy + 2, w);+ yy += 6;+ ParaStyle green = PS_TIP;+ green.color = RGB(102, 255, 102);+ snprintf(l, sizeof l, "\x01" "Effect:\x02 %s", s->desc);+ yy += gfx_para(&green, x, yy, w, l, draw) + 4;+ if (s->fail_desc) {+ ParaStyle red = PS_TIP;+ red.color = RGB(255, 102, 102);+ snprintf(l, sizeof l, "\x01" "Backfire:\x02 %s", s->fail_desc);+ yy += gfx_para(&red, x, yy, w, l, draw) + 2;+ }+ return yy - y;+}++void grimoire_keys(uint32_t p) {+ if (p & K_LEFT && sel > 0) sel--;+ if (p & K_RIGHT && sel < N_SPELLS) sel++;+ if (p & K_DOWN) sel = sel < 5 ? (sel + 5 < N_SPELLS ? sel + 5 : N_SPELLS - 1) : N_SPELLS;+ if (p & K_UP) sel = sel == N_SPELLS ? 5 : sel >= 5 ? sel - 5 : sel;+ U.tip_t = FPS * 6;+ for (int d = 1; d <= 9; d++)+ if (p & K_DIGIT(d)) sel = d - 1, p |= K_EXE;+ if (!(p & K_EXE)) return;+ if (sel == N_SPELLS) {+ if (S.grimoire_magic < magic_max && refill_lump(1)) {+ S.grimoire_magic += 100;+ if (S.grimoire_magic > magic_max) S.grimoire_magic = magic_max;+ }+ return;+ }+ cast(sel, -1, 0, false);+}diff --git a/games/cookieclicker/src/logic.c b/games/cookieclicker/src/logic.cnew file mode 100644index 00000000..d57571ca--- /dev/null+++ b/games/cookieclicker/src/logic.c@@ -0,0 +1,671 @@+/* Cookie Clicker's rules: cookies, buildings, upgrades, achievements, the store, as the game's+ * main.js (2.058) has them: its Game.CalculateGains, Game.mouseCps, the buildings' cps+ * functions, Game.Upgrade's prices and purchases, Game.RebuildUpgrades, Game.Logic and its+ * checks every 5 seconds. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"++GameState G;++/* ------------------------------------------------------------------ random numbers */+double rnd(void) {+ G.seed ^= G.seed << 13;+ G.seed ^= G.seed >> 17;+ G.seed ^= G.seed << 5;+ return (G.seed >> 8) / 16777216.0;+}+int rnd_int(int n) { return n > 0 ? (int)(rnd() * n) : 0; }++/* ------------------------------------------------------------------ upgrades and achievements */+bool counts_as_upgrade_owned(int u) {+ int p = upgrade_rec(u)->pool;+ return p == POOL_NORMAL || p == POOL_COOKIE || p == POOL_TECH;+}+bool has(int u) {+ if ((unsigned)u >= N_UPGRADES) return false;+ if (S.ascension_mode == 1) {+ const UpgradeRec *r = upgrade_rec(u);+ if (r->pool == POOL_PRESTIGE || r->tier == TIER_FORTUNE) return false;+ }+ return bit_get(S.upgrades_bought, u);+}+void unlock(int u) {+ if ((unsigned)u >= N_UPGRADES || has_unlocked(u)) return;+ bit_set(S.upgrades_unlocked, u, true);+ G.upgrades_dirty = true, G.recalculate = true;+}+void lock(int u) {+ if ((unsigned)u >= N_UPGRADES) return;+ bit_set(S.upgrades_unlocked, u, false);+ G.upgrades_dirty = true;+ if (bit_get(S.upgrades_bought, u) && counts_as_upgrade_owned(u)) G.upgrades_owned--;+ bit_set(S.upgrades_bought, u, false);+ G.recalculate = true;+}+static void upgrade_bought_effects(int u);+void earn_upgrade(int u) {+ bit_set(S.upgrades_unlocked, u, true);+ if (bit_get(S.upgrades_bought, u)) return;+ bit_set(S.upgrades_bought, u, true);+ upgrade_bought_effects(u);+ G.upgrades_dirty = true, G.recalculate = true;+ if (counts_as_upgrade_owned(u)) G.upgrades_owned++;+}+void win(int a) {+ if ((unsigned)a >= N_ACHIEVS || has_achiev(a)) return;+ bit_set(S.achievements, a, true);+ const AchievRec *r = achiev_rec(a);+ notify("Achievement unlocked", res_text(r->name), r->icon, 0);+ if (r->pool == APOOL_NORMAL) G.achievements_owned++;+ G.recalculate = true;+}++/* ------------------------------------------------------------------ buffs (the buffs' effects on prices etc.) */+Buff *find_buff(int type) {+ for (int i = 0; i < MAX_BUFFS; i++)+ if (S.buffs[i].used && S.buffs[i].type == type && S.buffs[i].time > 0) return &S.buffs[i];+ return NULL;+}+bool has_buff(int type) { return find_buff(type) != NULL; }++/* the Pantheon and the dragon: their effects, once their parts are in */+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;+ 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) {+ if (has(U_SEASON_SAVINGS)) price *= 0.99;+ if (has(U_SANTAS_DOMINION)) price *= 0.99;+ if (has(U_FABERGE_EGG)) price *= 0.99;+ if (has(U_DIVINE_DISCOUNT)) price *= 0.99;+ if (has(U_FORTUNE_100)) price *= 0.99;+ price *= 1 - aura_mult(AURA_FIERCE_HOARDER) * 0.02;+ if (has_buff(BUFF_EVERYTHING_MUST_GO)) price *= 0.95;+ if (has_buff(BUFF_PIXIE_LUCK)) price *= 0.98;+ if (has_buff(BUFF_PIXIE_MISERY)) price *= 1.02;+ uint16_t f = building_links(b)->fortune;+ if (f != NONE && has(f)) price *= 0.93;+ price *= eff(EFF_BUILDING_COST);+ int god = hasgod(GOD_CREATION);+ if (god == 1) price *= 0.93;+ else if (god == 2) price *= 0.95;+ else if (god == 3) price *= 0.98;+ return price;+}+double building_price(int b) {+ const Building *m = &S.buildings[b];+ int n = m->amount - m->free;+ double price = building_rec(b)->price * pow(1.15, n > 0 ? n : 0);+ return ceil(modify_building_price(b, price));+}+double building_sum_price(int b, int amount) {+ const Building *m = &S.buildings[b];+ double price = 0, base = building_rec(b)->price;+ int from = m->amount > 0 ? m->amount : 0;+ for (int i = from; i < from + amount; i++) price += base * pow(1.15, i - m->free > 0 ? i - m->free : 0);+ return ceil(modify_building_price(b, price));+}+static double sell_multiplier(void) { return 0.25 * (1 + aura_mult(AURA_EARTH_SHATTERER)); }+double building_reverse_sum_price(int b, int amount) {+ const Building *m = &S.buildings[b];+ double price = 0, base = building_rec(b)->price;+ int from = m->amount - amount > 0 ? m->amount - amount : 0;+ for (int i = from; i < (m->amount > 0 ? m->amount : 0); i++) price += base * pow(1.15, i - m->free > 0 ? i - m->free : 0);+ price = modify_building_price(b, price) * sell_multiplier();+ return ceil(price);+}+void building_bulk(int b, double *price, int *n) {+ int bulk = G.buy_bulk;+ if (G.buy_mode == 1) {+ if (bulk < 1) bulk = 1;+ *n = bulk, *price = building_sum_price(b, bulk);+ } else {+ int have = S.buildings[b].amount;+ int k = bulk == -1 ? have : bulk < have ? bulk : have;+ *n = k, *price = building_reverse_sum_price(b, k);+ }+}++double upgrade_price(int u) {+ const UpgradeRec *r = upgrade_rec(u);+ double price = r->price;+ switch (u) { /* the upgrades whose price the game works out */+ case U_ELDER_PLEDGE: price = pow(8, S.pledges + 2 < 14 ? S.pledges + 2 : 14); break;+ case U_GOLDEN_SWITCH_OFF: case U_GOLDEN_SWITCH_ON: price = G.cookies_ps * 60 * 60; break;+ case U_SHIMMERING_VEIL_OFF: price = G.unbuffed_cps * 60 * 60 * 24; break;+ default: break;+ }+ if (r->tier == TIER_SYNERGY1 || r->tier == TIER_SYNERGY2)+ price = (building_rec(r->building)->price * 10 + building_rec(r->building2)->price) * tier_rec(r->tier)->price *+ (has(U_CHIMERA) ? 0.98 : 1);+ extern double special_upgrade_price(int u, double price);+ price = special_upgrade_price(u, price);+ if (price == 0) return 0;+ if (r->pool != POOL_PRESTIGE) {+ if (has(U_TOY_WORKSHOP)) price *= 0.95;+ if (has(U_FIVE_FINGER_DISCOUNT)) price *= pow(0.99, S.buildings[B_CURSOR].amount / 100.0);+ if (has(U_SANTAS_DOMINION)) price *= 0.98;+ if (has(U_FABERGE_EGG)) price *= 0.99;+ if (has(U_DIVINE_SALES)) price *= 0.99;+ if (has(U_FORTUNE_100)) price *= 0.99;+ if (has(U_WRINKLER_AMBERGRIS)) price *= 0.99;+ if (r->kitten && has(U_KITTEN_WAGES)) price *= 0.9;+ if (has_buff(BUFF_HAGGLER_LUCK)) price *= 0.98;+ if (has_buff(BUFF_HAGGLER_MISERY)) price *= 1.02;+ price *= 1 - aura_mult(AURA_MASTER_OF_THE_ARMORY) * 0.02;+ price *= eff(EFF_UPGRADE_COST);+ if (r->pool == POOL_COOKIE && has(U_DIVINE_BAKERIES)) price /= 5;+ }+ return ceil(price);+}+static int upgrade_price_lumps(int u) {+ extern int upgrade_lumps(int u);+ return upgrade_lumps(u);+}+bool upgrade_can_buy(int u) {+ extern int upgrade_can_buy_special(int u); /* -1: the usual rule */+ int s = upgrade_can_buy_special(u);+ if (s >= 0) return s;+ int lumps = upgrade_price_lumps(u);+ if (lumps > 0) return S.lumps >= lumps;+ return S.cookies >= upgrade_price(u);+}+bool upgrade_needs_confirm(int u) {+ for (int i = 0; i < N_CONFIRM; i++)+ if (LIST(CONFIRM)[i] == u) return true;+ return false;+}++/* what buying an upgrade does besides having it (the upgrades' buyFunctions) */+extern void upgrade_buy_function(int u);+static void upgrade_bought_effects(int u) { upgrade_buy_function(u); }++bool upgrade_buy(int u, bool confirmed) {+ const UpgradeRec *r = upgrade_rec(u);+ if (bit_get(S.upgrades_bought, u)) {+ extern bool season_cancel(int u);+ return season_cancel(u);+ }+ if (!confirmed && upgrade_needs_confirm(u)) return false;+ if (r->pool == POOL_PRESTIGE) {+ double price = upgrade_price(u);+ if (S.heavenly_chips < price) return false;+ S.heavenly_chips -= price, S.heavenly_chips_spent += price;+ bit_set(S.upgrades_unlocked, u, true);+ bit_set(S.upgrades_bought, u, true);+ upgrade_bought_effects(u);+ return true;+ }+ if (!upgrade_can_buy(u)) return false;+ int lumps = upgrade_price_lumps(u);+ if (lumps > 0) S.lumps -= lumps;+ else spend(upgrade_price(u));+ bit_set(S.upgrades_bought, u, true);+ upgrade_bought_effects(u);+ extern int upgrade_toggle_into(int u);+ int into = upgrade_toggle_into(u);+ if (into >= 0) lock(into), unlock(into);+ G.upgrades_dirty = true, G.recalculate = true;+ if (counts_as_upgrade_owned(u)) G.upgrades_owned++;+ return true;+}++/* ------------------------------------------------------------------ cookies */+void earn(double v) {+ if (G.on_ascend) return;+ S.cookies += v, S.cookies_earned += v;+}+void spend(double v) {+ if (G.on_ascend) return;+ S.cookies -= v;+}+void dissolve(double v) {+ if (G.on_ascend) return;+ S.cookies -= v, S.cookies_earned -= v;+ if (S.cookies < 0) S.cookies = 0;+ if (S.cookies_earned < 0) S.cookies_earned = 0;+}++static double compute_cps(double base, int mult, double bonus) { return base * pow(2, mult) + bonus; }++/* the cursor's thousand fingers and their multipliers */+static double fingers(void) {+ static const struct { uint16_t u; float m; } f[] = {+ {U_MILLION_FINGERS, 5}, {U_BILLION_FINGERS, 10}, {U_TRILLION_FINGERS, 20}, {U_QUADRILLION_FINGERS, 20},+ {U_QUINTILLION_FINGERS, 20}, {U_SEXTILLION_FINGERS, 20}, {U_SEPTILLION_FINGERS, 20}, {U_OCTILLION_FINGERS, 20},+ {U_NONILLION_FINGERS, 20}, {U_DECILLION_FINGERS, 20}, {U_UNDECILLION_FINGERS, 20}, {U_UNSHACKLED_CURSORS, 25}};+ double add = 0;+ if (has(U_THOUSAND_FINGERS)) add += 0.1;+ for (unsigned i = 0; i < sizeof f / sizeof f[0]; i++)+ if (has(f[i].u)) add *= f[i].m;+ return add;+}++double tiered_cps_mult(int b) {+ const BuildingLinks *l = building_links(b);+ double mult = 1;+ uint16_t unshackle = l->unshackle;+ for (int t = 0; t < N_TIERS; t++) {+ uint16_t u = l->tiered[t];+ if (u == NONE || tier_rec(t)->special || !has(u)) continue;+ double tm = 2;+ uint16_t tu = LIST(TIER_UNSHACKLE)[t];+ if (S.ascension_mode != 1 && unshackle != NONE && has(unshackle) && tu != NONE && has(tu))+ tm += b == 1 ? 0.5 : (20 - b) * 0.1;+ mult *= tm;+ }+ for (int i = 0; i < 6 && l->synergies[i] != NONE; i++) {+ const UpgradeRec *s = upgrade_rec(l->synergies[i]);+ if (!has(l->synergies[i])) continue;+ if (s->building == b) mult *= 1 + 0.05 * S.buildings[s->building2].amount;+ else if (s->building2 == b) mult *= 1 + 0.001 * S.buildings[s->building].amount;+ }+ if (l->fortune != NONE && has(l->fortune)) mult *= 1.07;+ if (l->grandma != NONE && has(l->grandma)) mult *= 1 + S.buildings[B_GRANDMA].amount * 0.01 * (1.0 / (b - 1));+ return mult;+}++static double building_cps(int b) {+ const BuildingRec *r = building_rec(b);+ if (b == B_CURSOR) {+ double add = fingers();+ int num = 0;+ for (int i = 0; i < NB; i++)+ if (i != B_CURSOR) num += S.buildings[i].amount;+ add *= num;+ double mult = tiered_cps_mult(b);+ mult *= eff(EFF_CURSOR_CPS);+ return compute_cps(0.1, has(U_REINFORCED_INDEX_FINGER) + has(U_CARPAL_TUNNEL_PREVENTION_CREAM) + has(U_AMBIDEXTROUS),+ add) * mult;+ }+ if (b == B_GRANDMA) {+ double mult = 1;+ for (int i = 0; i < N_GRANDMA_SYNERGIES; i++)+ if (has(LIST(GRANDMA_SYNERGIES)[i])) mult *= 2;+ if (has(U_BINGO_CENTER_RESEARCH_FACILITY)) mult *= 4;+ if (has(U_RITUAL_ROLLING_PINS)) mult *= 2;+ if (has(U_NAUGHTY_LIST)) mult *= 2;+ if (has(U_ELDERWORT_BISCUITS)) mult *= 1.02;+ mult *= eff(EFF_GRANDMA_CPS);+ if (has(U_CAT_LADIES))+ for (int i = 0; i < N_KITTENS; i++)+ if (has(LIST(KITTENS)[i])) mult *= 1.29;+ mult *= tiered_cps_mult(b);+ double add = 0;+ if (has(U_ONE_MIND)) add += S.buildings[B_GRANDMA].amount * 0.02;+ if (has(U_COMMUNAL_BRAINSWEEP)) add += S.buildings[B_GRANDMA].amount * 0.02;+ if (has(U_ELDER_PACT)) add += S.buildings[B_PORTAL].amount * 0.05;+ int num = 0;+ for (int i = 0; i < NB; i++)+ if (i != B_GRANDMA) num += S.buildings[i].amount;+ mult *= 1 + aura_mult(AURA_ELDER_BATTALION) * 0.01 * num;+ return (r->cps + add) * mult;+ }+ return r->cps * tiered_cps_mult(b);+}++double mouse_cps(void) {+ double add = fingers();+ int num = 0;+ for (int i = 0; i < NB; i++) num += S.buildings[i].amount;+ num -= S.buildings[B_CURSOR].amount;+ add *= num;+ static const uint16_t mice[] = {U_PLASTIC_MOUSE, U_IRON_MOUSE, U_TITANIUM_MOUSE, U_ADAMANTIUM_MOUSE,+ U_UNOBTAINIUM_MOUSE, U_ELUDIUM_MOUSE, U_WISHALLOY_MOUSE, U_FANTASTEEL_MOUSE,+ U_NEVERCRACK_MOUSE, U_ARMYTHRIL_MOUSE, U_TECHNOBSIDIAN_MOUSE, U_PLASMARBLE_MOUSE,+ U_MIRACULITE_MOUSE, U_AETHERICE_MOUSE, U_OMNIPLAST_MOUSE, U_FORTUNE_104};+ for (unsigned i = 0; i < sizeof mice / sizeof mice[0]; i++)+ if (has(mice[i])) add += G.cookies_ps * 0.01;+ double mult = 1;+ if (has(U_SANTAS_HELPERS)) mult *= 1.1;+ if (has(U_COOKIE_EGG)) mult *= 1.1;+ if (has(U_HALO_GLOVES)) mult *= 1.1;+ if (has(U_DRAGON_CLAW)) mult *= 1.03;+ if (has(U_AURA_GLOVES)) {+ int lv = S.buildings[B_CURSOR].level, cap = has(U_LUMINOUS_GLOVES) ? 20 : 10;+ mult *= 1 + 0.05 * (lv < cap ? lv : cap);+ }+ mult *= eff(EFF_CLICK);+ int god = hasgod(GOD_LABOR);+ if (god == 1) mult *= 1.15;+ else if (god == 2) mult *= 1.1;+ else if (god == 3) mult *= 1.05;+ for (int i = 0; i < MAX_BUFFS; i++)+ if (S.buffs[i].used && S.buffs[i].time > 0) mult *= S.buffs[i].mult_click;+ mult *= 1 + aura_mult(AURA_DRAGON_CURSOR) * 0.05;+ double out = mult * compute_cps(1, has(U_REINFORCED_INDEX_FINGER) + has(U_CARPAL_TUNNEL_PREVENTION_CREAM) ++ has(U_AMBIDEXTROUS), add);+ Buff *cf = find_buff(BUFF_CURSED_FINGER);+ if (cf) out = cf->power;+ return out;+}++extern double heavenly_multiplier(void);+extern double veil_boost(void);+extern double cookie_upgrade_power(int u);+extern void minigame_effs(void);+extern void compute_lump_times(void);++void calculate_gains(void) {+ double cps = 0, mult = 1;+ minigame_effs();+ if (S.ascension_mode != 1) mult += S.prestige * 0.01 * heavenly_multiplier();+ mult *= eff(EFF_CPS);+ /* (Heralds: the players with the game's support page open; none here) */+ for (int i = 0; i < N_COOKIE_UPGRADES; i++) {+ int u = LIST(COOKIE_UPGRADES)[i];+ if (has(u)) mult *= 1 + cookie_upgrade_power(u) * 0.01;+ }+ if (has(U_SPECIALIZED_CHOCOLATE_CHIPS)) mult *= 1.01;+ if (has(U_DESIGNER_COCOA_BEANS)) mult *= 1.02;+ if (has(U_UNDERWORLD_OVENS)) mult *= 1.03;+ if (has(U_EXOTIC_NUTS)) mult *= 1.04;+ if (has(U_ARCANE_SUGAR)) mult *= 1.05;+ if (has(U_INCREASED_MERRINESS)) mult *= 1.15;+ if (has(U_IMPROVED_JOLLINESS)) mult *= 1.15;+ if (has(U_A_LUMP_OF_COAL)) mult *= 1.01;+ if (has(U_AN_ITCHY_SWEATER)) mult *= 1.01;+ if (has(U_SANTAS_DOMINION)) mult *= 1.2;+ if (has(U_FORTUNE_100)) mult *= 1.01;+ if (has(U_FORTUNE_101)) mult *= 1.07;+ if (has(U_DRAGON_SCALE)) mult *= 1.03;+ if (has(U_WRINKLER_AMBERGRIS)) mult *= 1.06;+ double build_mult = 1;+ int god = hasgod(GOD_ASCETICISM);+ if (god == 1) mult *= 1.15;+ else if (god == 2) mult *= 1.1;+ else if (god == 3) mult *= 1.05;+ god = hasgod(GOD_AGES);+ if (god) { /* (the game's real-time cycles: here the calculator's time played) */+ double period = god == 1 ? 3 : god == 2 ? 12 : 24;+ mult *= 1 + 0.15 * sin(S.play_time / 1000 / (60 * 60 * period) * M_PI * 2);+ }+ god = hasgod(GOD_DECADENCE);+ if (god == 1) build_mult *= 0.93;+ else if (god == 2) build_mult *= 0.95;+ else if (god == 3) build_mult *= 0.98;+ god = hasgod(GOD_INDUSTRY);+ if (god == 1) build_mult *= 1.1;+ else if (god == 2) build_mult *= 1.06;+ else if (god == 3) build_mult *= 1.03;+ god = hasgod(GOD_LABOR);+ if (god == 1) build_mult *= 0.97;+ else if (god == 2) build_mult *= 0.98;+ else if (god == 3) build_mult *= 0.99;+ if (has(U_SANTAS_LEGACY)) mult *= 1 + (S.santa_level + 1) * 0.03;++ G.milk_progress = G.achievements_owned / 25.f;+ double milk_mult = 1;+ if (has(U_SANTAS_MILK_AND_COOKIES)) milk_mult *= 1.05;+ milk_mult *= 1 + aura_mult(AURA_BREATH_OF_MILK) * 0.05;+ god = hasgod(GOD_MOTHER);+ if (god == 1) milk_mult *= 1.1;+ else if (god == 2) milk_mult *= 1.05;+ else if (god == 3) milk_mult *= 1.03;+ milk_mult *= eff(EFF_MILK);+ static const struct { uint16_t u; float k; } kittens[] = {+ {U_KITTEN_HELPERS, 0.1}, {U_KITTEN_WORKERS, 0.125}, {U_KITTEN_ENGINEERS, 0.15}, {U_KITTEN_OVERSEERS, 0.175},+ {U_KITTEN_MANAGERS, 0.2}, {U_KITTEN_ACCOUNTANTS, 0.2}, {U_KITTEN_SPECIALISTS, 0.2}, {U_KITTEN_EXPERTS, 0.2},+ {U_KITTEN_CONSULTANTS, 0.2}, {U_KITTEN_ASSISTANTS_TO_THE_REGIONAL_MANAGER, 0.175},+ {U_KITTEN_MARKETEERS, 0.15}, {U_KITTEN_ANALYSTS, 0.125}, {U_KITTEN_EXECUTIVES, 0.115},+ {U_KITTEN_ADMINS, 0.11}, {U_KITTEN_STRATEGISTS, 0.105}, {U_KITTEN_ANGELS, 0.1}, {U_FORTUNE_103, 0.05}};+ double cat_mult = 1;+ for (unsigned i = 0; i < sizeof kittens / sizeof kittens[0]; i++)+ if (has(kittens[i].u)) cat_mult *= 1 + G.milk_progress * kittens[i].k * milk_mult;++ for (int b = 0; b < NB; b++) {+ Building *m = &S.buildings[b];+ m->stored_cps = building_cps(b);+ if (S.ascension_mode != 1) m->stored_cps *= (1 + m->level * 0.01) * build_mult;+ if (b == B_GRANDMA && has(U_MILKHELPANDREG_LACTOSE_INTOLERANCE_RELIEF_TABLETS))+ m->stored_cps *= 1 + 0.05 * G.milk_progress * milk_mult;+ m->stored_total_cps = m->amount * m->stored_cps;+ cps += m->stored_total_cps;+ }+ G.building_cps = cps;+ if (has(U_EGG)) cps += 9;+ mult *= cat_mult;++ static const uint16_t eggs[] = {U_CHICKEN_EGG, U_DUCK_EGG, U_TURKEY_EGG, U_QUAIL_EGG, U_ROBIN_EGG, U_OSTRICH_EGG,+ U_CASSOWARY_EGG, U_SALMON_ROE, U_FROGSPAWN, U_SHARK_EGG, U_TURTLE_EGG, U_ANT_LARVA};+ double egg_mult = 1;+ for (unsigned i = 0; i < sizeof eggs / sizeof eggs[0]; i++)+ if (has(eggs[i])) egg_mult *= 1.01;+ if (has(U_CENTURY_EGG)) { /* +10% at most, over 100 days of this ascension */+ double day = floor((S.play_time - S.start_date) / 1000 / 10) * 10 / 60 / 60 / 24;+ if (day < 0) day = 0;+ if (day > 100) day = 100;+ egg_mult *= 1 + (1 - pow(1 - day / 100, 3)) * 0.1;+ }+ mult *= egg_mult;+ if (has(U_SUGAR_BAKING)) mult *= 1 + (S.lumps < 100 ? S.lumps : 100) * 0.01;+ mult *= 1 + aura_mult(AURA_RADIANT_APPETITE);++ double raw = cps * mult;+ for (int i = 0; i < N_CPS_ACHIEVS; i++)+ if (raw >= cps_achiev(i)->threshold) win(cps_achiev(i)->id);+ G.cookies_ps_raw = raw;+ if (raw > S.cookies_ps_raw_highest) S.cookies_ps_raw_highest = raw;++ double fortune = aura_mult(AURA_DRAGONS_FORTUNE);+ for (int i = 0; i < G.nshimmers_golden; i++) mult *= 1 + fortune * 1.23;++ int sucking = 0;+ for (int i = 0; i < MAX_WRINKLERS; i++)+ if (S.wrinklers[i].phase == 2) sucking++;+ double suck = 1.0 / 20;+ extern float wrinkler_eat_eff(void);+ suck *= wrinkler_eat_eff();+ suck *= 1 + aura_mult(AURA_DRAGON_GUTS) * 0.2;+ G.cps_sucked = sucking * suck < 1 ? sucking * suck : 1;++ if (has(U_ELDER_COVENANT)) mult *= 0.95;+ if (has(U_GOLDEN_SWITCH_OFF)) {+ double gs = 1.5;+ if (has(U_RESIDUAL_LUCK))+ for (int i = 0; i < N_GOLDEN_UPGRADES; i++)+ if (has(LIST(GOLDEN_UPGRADES)[i])) gs += 0.1;+ mult *= gs;+ }+ if (has(U_SHIMMERING_VEIL_OFF)) mult *= 1 + veil_boost();+ if (has(U_MAGIC_SHENANIGANS)) mult *= 1000;+ if (has(U_OCCULT_OBSTRUCTION)) mult *= 0;++ G.unbuffed_cps = cps * mult;+ for (int i = 0; i < MAX_BUFFS; i++)+ if (S.buffs[i].used && S.buffs[i].time > 0) mult *= S.buffs[i].mult_cps;+ G.global_cps_mult = mult;+ G.cookies_ps = cps * mult;+ G.computed_mouse_cps = mouse_cps();+ compute_lump_times();+ G.recalculate = false;+}++double drop_rate_mult(void) {+ double rate = 1;+ if (has(U_GREEN_YEAST_DIGESTIVES)) rate *= 1.03;+ if (has(U_DRAGON_TEDDY_BEAR)) rate *= 1.03;+ rate *= eff(EFF_ITEM_DROPS);+ rate *= 1 + aura_mult(AURA_MIND_OVER_MATTER) * 0.25;+ if (has(U_SANTAS_BOTTOMLESS_BAG)) rate *= 1.1;+ if (has(U_COSMIC_BEGINNERS_LUCK) && !has(U_HEAVENLY_CHIP_SECRET)) rate *= 5;+ return rate;+}++/* ------------------------------------------------------------------ buildings */+extern void building_bought(int b); /* the buildings' buyFunctions: unlocks, achievements */+void building_buy(int b, int amount) {+ if (G.buy_mode == -1) {+ building_sell(b, G.buy_bulk);+ return;+ }+ Building *m = &S.buildings[b];+ if (amount == -1) amount = 1000;+ bool any = false;+ for (int i = 0; i < amount; i++) {+ double price = building_price(b);+ if (S.cookies < price) break;+ spend(price);+ m->amount++, m->bought++;+ building_bought(b);+ G.recalculate = true;+ if (m->amount > m->highest) m->highest = m->amount;+ G.buildings_owned++;+ any = true;+ }+ if (any) G.store_dirty = true;+}+extern void building_sold(int b, int n); /* the Pantheon's Ruin, the dragon's orbs */+void building_sell(int b, int amount) {+ Building *m = &S.buildings[b];+ if (amount == -1) amount = m->amount;+ if (!amount) amount = 1;+ int sold = 0;+ for (int i = 0; i < amount; i++) {+ if (m->amount <= 0) break;+ double price = floor(building_price(b) * sell_multiplier());+ sold++;+ S.cookies += price;+ if (S.cookies > S.cookies_earned) S.cookies_earned = S.cookies;+ m->amount--;+ G.recalculate = true;+ G.buildings_owned--;+ }+ if (sold) building_sold(b, sold), G.store_dirty = true;+}++/* ------------------------------------------------------------------ the big cookie */+void click_cookie(void) {+ if (G.on_ascend || G.ascend_timer > 0 || G.T < 3) return;+ extern void lose_shimmering_veil(int why);+ lose_shimmering_veil(0);+ double amount = G.computed_mouse_cps;+ earn(amount);+ S.handmade_cookies += amount;+ if (S.prefs.particles) {+ particle_add(0, 0, 0, 0, 1, 2, 0);+ particle_add(COOKIE_X + (float)(rnd() * 40 - 20), COOKIE_Y + (float)(rnd() * 40 - 20), (float)(rnd() * 4 - 2),+ (float)(rnd() * -2 - 2), (float)(rnd() * 0.5 + 0.75), 1, 2);+ }+ if (S.prefs.numbers) {+ char t[24] = "+";+ beautify(amount, 1, t + 1);+ text_particle_add(COOKIE_X + (float)(rnd() * 24 - 12), COOKIE_Y - 10 + (float)(rnd() * 8 - 4), t);+ }+ S.cookie_clicks++;+ G.click_t = 0;+}++/* ------------------------------------------------------------------ the store's upgrades */+static uint16_t sort_key_u[N_UPGRADES];+static double sort_key_p[N_UPGRADES];+void game_rebuild_upgrades(void) {+ G.upgrades_dirty = false;+ int n = 0;+ for (int u = 0; u < N_UPGRADES; u++) {+ const UpgradeRec *r = upgrade_rec(u);+ if (r->pool == POOL_DEBUG || r->pool == POOL_PRESTIGE) continue;+ bool bought = bit_get(S.upgrades_bought, u);+ extern bool upgrade_display_when_owned(int u);+ if (!bought) {+ if (S.ascension_mode == 1) {+ bool lasting = false;+ for (int i = 0; i < N_LASTING; i++)+ if (LIST(LASTING)[i] == u) lasting = true;+ if (lasting || r->tier == TIER_FORTUNE) continue;+ }+ if (!has_unlocked(u)) continue;+ } else if (!upgrade_display_when_owned(u))+ continue;+ sort_key_u[n] = (uint16_t)u;+ sort_key_p[n] = r->pool == POOL_TOGGLE ? r->order : upgrade_price(u);+ n++;+ }+ /* (insertion sort: stable, as the game's sort is in practice) */+ for (int i = 1; i < n; i++) {+ uint16_t u = sort_key_u[i];+ double p = sort_key_p[i];+ int j = i;+ while (j > 0 && sort_key_p[j - 1] > p) sort_key_u[j] = sort_key_u[j - 1], sort_key_p[j] = sort_key_p[j - 1], j--;+ sort_key_u[j] = u, sort_key_p[j] = p;+ }+ /* the store: upgrades, then switches, then research */+ G.nstore = G.nstore_toggle = G.nstore_tech = 0;+ for (int pass = 0; pass < 3; pass++)+ for (int i = 0; i < n; i++) {+ int pool = upgrade_rec(sort_key_u[i])->pool;+ int want = pool == POOL_TOGGLE ? 1 : pool == POOL_TECH ? 2 : 0;+ if (want != pass) continue;+ G.store[G.nstore + G.nstore_toggle + G.nstore_tech] = sort_key_u[i];+ if (pass == 0) G.nstore++;+ else if (pass == 1) G.nstore_toggle++;+ else G.nstore_tech++;+ }+ G.store_dirty = true;+}++/* ------------------------------------------------------------------ notes, popups, particles */+void notify(const char *title, const char *desc, int icon, int seconds) {+ for (int i = MAX_NOTES - 1; i > 0; i--) G.notes[i] = G.notes[i - 1];+ Note *n = &G.notes[0];+ snprintf(n->title, sizeof n->title, "%s", title);+ snprintf(n->desc, sizeof n->desc, "%s", desc ? desc : "");+ n->icon = (int16_t)(icon == NONE ? -1 : icon);+ if (S.prefs.notes_on) seconds = seconds > 0 && seconds < 6 ? seconds : 6; /* (Fast notes) */+ n->life = seconds > 0 ? seconds * FPS : -1;+ n->age = 0;+}+void popup(const char *text, float x, float y) {+ int k = 0;+ for (int i = 0; i < MAX_POPUPS; i++)+ if (G.popups[i].life <= 0 || G.popups[i].life < G.popups[k].life) k = i;+ Popup *p = &G.popups[k];+ snprintf(p->text, sizeof p->text, "%s", text);+ p->x = x, p->y = y, p->life = FPS * 4;+}+void particle_add(float x, float y, float xd, float yd, float size, int dur, int kind) {+ int k = 0, oldest = -1;+ for (int i = 0; i < MAX_PARTICLES; i++) {+ if (G.particles[i].life < 0) {+ k = i;+ oldest = -2;+ break;+ }+ if (G.particles[i].life > oldest) oldest = G.particles[i].life, k = i;+ }+ Particle *p = &G.particles[k];+ bool auto_ = x != 0;+ p->life = 0;+ p->x = auto_ ? x : (float)(rnd() * LEFT_W);+ p->y = auto_ ? y : NEWS_H - 24;+ p->xd = auto_ ? xd : (float)(rnd() * 2 - 1) * 0.37f;+ p->yd = auto_ ? yd : (float)(4 + rnd() * 2) * 0.37f;+ if (auto_) p->xd *= 0.37f, p->yd *= 0.37f;+ p->size = size;+ p->dur = (int16_t)dur;+ p->kind = (int16_t)kind;+ p->r = (float)(rnd() * 360);+ /* a cookie the bakery has (its icon), or the plain one */+ extern int particle_icon(void);+ p->pic = (int16_t)particle_icon();+}+void text_particle_add(float x, float y, const char *text) {+ int k = 0;+ for (int i = 0; i < MAX_TEXT_PARTICLES; i++) {+ if (G.texts[i].life < 0) {+ k = i;+ break;+ }+ if (G.texts[i].life > G.texts[k].life) k = i;+ }+ TextParticle *t = &G.texts[k];+ t->x = x, t->y = y, t->yd = -0.75f, t->life = 0, t->dur = FPS;+ snprintf(t->text, sizeof t->text, "%s", text);+}diff --git a/games/cookieclicker/src/lumps.c b/games/cookieclicker/src/lumps.cnew file mode 100644index 00000000..4660702e--- /dev/null+++ b/games/cookieclicker/src/lumps.c@@ -0,0 +1,195 @@+/* Sugar lumps (the game's computeLumpTimes, doLumps, harvestLumps, computeLumpType): once a billion+ * cookies are baked in all, a lump grows; it matures after 20 hours, ripens after 23 and falls after 24,+ * and may be bifurcated, golden, meaty or caramelized. Lumps level up buildings (a building's level+ * costs that many lumps and gives +1% of its production; level 1 of the farm, bank, temple and wizard+ * tower opens their minigames).+ *+ * The calculator can't tell how long it was off, so lumps grow while the game is open, 24 times as+ * fast as the game's clock (an hour of play for a day). */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"++#define LUMP_SPEED 24.0+#define HOUR (1000.0 * 60 * 60)+double lump_mature_age = HOUR * 20, lump_ripe_age = HOUR * 23, lump_overripe_age = HOUR * 24;++static double lump_now(void) { return S.play_time * LUMP_SPEED; }+double lump_age(void) { return lump_now() - S.lump_t; }++bool can_lumps(void) {+ return S.lumps_total > -1 || (S.ascension_mode != 1 && S.cookies_earned + S.cookies_reset >= 1000000000);+}++void compute_lump_times(void) {+ lump_mature_age = HOUR * 20, lump_ripe_age = HOUR * 23;+ if (has(U_STEVIA_CAELESTIS)) lump_ripe_age -= HOUR;+ if (has(U_DIABETICA_DAEMONICUS)) lump_mature_age -= HOUR;+ if (has(U_ICHOR_SYRUP)) lump_mature_age -= 1000 * 60 * 7;+ if (has(U_SUGAR_AGING_PROCESS)) {+ int g = S.buildings[B_GRANDMA].amount;+ lump_ripe_age -= 6000.0 * (g < 600 ? g : 600);+ }+ if (G.buildings_owned % 10 == 0) {+ int god = hasgod(GOD_ORDER);+ if (god == 1) lump_ripe_age -= HOUR;+ else if (god == 2) lump_ripe_age -= HOUR / 3 * 2;+ else if (god == 3) lump_ripe_age -= HOUR / 3;+ }+ double curve = 1 + aura_mult(AURA_DRAGONS_CURVE) * 0.05;+ lump_mature_age /= curve, lump_ripe_age /= curve;+ lump_overripe_age = lump_ripe_age + HOUR;+ if (has(U_GLUCOSE_CHARGED_AIR)) lump_mature_age /= 2000, lump_ripe_age /= 2000, lump_overripe_age /= 2000;+}++void gain_lumps(int total) {+ if (S.lumps_total == -1) S.lumps_total = 0, S.lumps = 0;+ S.lumps += total, S.lumps_total += total;+ if (S.lumps_total >= 7) win(A_DUDE_SWEET);+ if (S.lumps_total >= 30) win(A_SUGAR_RUSH);+ if (S.lumps_total >= 365) win(A_YEARS_WORTH_OF_CAVITIES);+}++static void compute_lump_type(void) {+ int types[1 + 4 * 3], n = 0;+ types[n++] = 0;+ double loop = 1 + aura_mult(AURA_DRAGONS_CURVE);+ int l = (int)floor(loop);+ if (rnd() < loop - l) l++;+ for (int i = 0; i < l; i++) {+ if (rnd() < (has(U_SUCRALOSIA_INUTILIS) ? 0.15 : 0.1)) types[n++] = 1;+ if (rnd() < 3.0 / 1000) types[n++] = 2;+ if (rnd() < 0.1 * S.elder_wrath) types[n++] = 3;+ if (rnd() < 1.0 / 50) types[n++] = 4;+ }+ S.lump_type = (uint8_t)types[rnd_int(n)];+}++void harvest_lumps(int amount, bool silent) {+ if (!can_lumps()) return;+ S.lump_t = lump_now();+ double total = amount;+ static const int k1[2] = {1, 2}, k2[6] = {2, 3, 4, 5, 6, 7}, k3[5] = {0, 0, 1, 2, 2}, k4[3] = {1, 2, 3};+ if (S.lump_type == 1 && has(U_SUCRALOSIA_INUTILIS) && rnd() < 0.05) total *= 2;+ else if (S.lump_type == 1) total *= k1[rnd_int(2)];+ else if (S.lump_type == 2) {+ total *= k2[rnd_int(6)];+ gain_buff(BUFF_SUGAR_BLESSING, 24 * 60 * 60, 1, 0);+ double a = G.cookies_ps * 60 * 60 * 24, b = S.cookies;+ earn(a < b ? a : b);+ notify("Sugar blessing activated!", "Your cookies have been doubled.\n+10% golden cookies for the next 24 hours.",+ ICON(29, 16), 0);+ } else if (S.lump_type == 3)+ total *= k3[rnd_int(5)];+ else if (S.lump_type == 4) {+ total *= k4[rnd_int(3)];+ S.lump_refill = 0;+ notify("Sugar lump cooldowns cleared!", "", ICON(29, 27), 0);+ }+ int t = (int)floor(total);+ gain_lumps(t);+ if (S.lump_type == 1) win(A_SUGAR_SUGAR);+ else if (S.lump_type == 2) win(A_ALL_NATURAL_CANE_SUGAR);+ else if (S.lump_type == 3) win(A_SWEETMEATS);+ else if (S.lump_type == 4) win(A_MAILLARD_REACTION);+ if (!silent) {+ char d[48];+ if (t > 0) snprintf(d, sizeof d, "+%d sugar lump%s", t, t == 1 ? "" : "s");+ else snprintf(d, sizeof d, "Botched harvest!");+ popup(d, LEFT_W / 2, NEWS_H + 30);+ }+ compute_lump_times();+}++/* harvesting by hand: a mature lump has one chance in two to give something, a ripe one gives */+void click_lump(void) {+ if (!can_lumps()) return;+ double age = lump_age();+ if (age < lump_mature_age) return;+ if (age < lump_ripe_age) {+ int a = rnd_int(2);+ if (a) win(A_HAND_PICKED);+ harvest_lumps(a, false);+ compute_lump_type();+ } else if (age < lump_overripe_age) {+ harvest_lumps(1, false);+ compute_lump_type();+ }+}++void lumps_new(void) {+ S.lumps = -1, S.lumps_total = -1, S.lump_t = 0, S.lump_refill = 0, S.lump_type = 0;+}+void lumps_reset(bool hard) {+ if (hard) lumps_new();+}++void do_lumps(void) {+ if (S.lump_refill > 0) S.lump_refill--;+ if (!can_lumps()) return;+ if (S.lumps_total == -1) {+ S.lump_t = lump_now(), S.lumps_total = 0, S.lumps = 0;+ compute_lump_type();+ notify("Sugar lumps!",+ "Because you've baked a \x01billion cookies\x02 in total, you are now attracting \x01sugar lumps\x02. "+ "They coalesce quietly near the top of your screen.\nYou will be able to harvest them when they're "+ "ripe, after which you may spend them on all sorts of things!",+ ICON(23, 14), 0);+ }+ if (lump_age() > lump_overripe_age) {+ harvest_lumps(1, false);+ compute_lump_type();+ }+}++/* the lump's icon and the next stage's, and how far between them (0..1) */+void lump_icons(int *icon, int *icon2, float *opacity) {+ double age = lump_age();+ int phase = (int)floor(age / lump_overripe_age * 7), phase2 = phase + 1;+ if (phase > 6) phase = 6;+ if (phase2 > 6) phase2 = 6;+ int row = 14, row2 = 14, type = S.lump_type;+ if (type == 1) {+ if (phase2 >= 6) row2 = 15;+ } else if (type == 2) {+ if (phase >= 4) row = 16;+ if (phase2 >= 4) row2 = 16;+ } else if (type == 3) {+ if (phase >= 4) row = 17;+ if (phase2 >= 4) row2 = 17;+ } else if (type == 4) {+ if (phase >= 4) row = 27;+ if (phase2 >= 4) row2 = 27;+ }+ *icon = ICON(23 + (phase < 5 ? phase : 5), row);+ *icon2 = ICON(23 + phase2, row2);+ double o = age / lump_overripe_age * 7;+ if (o > 6) o = 6;+ *opacity = (float)(o - floor(o));+ if (phase >= 6) *opacity = 1;+}++/* the lump refill (minigames): 15 minutes between uses */+#define LUMP_REFILL_MAX (FPS * 60 * 15)+bool can_refill_lump(void) { return S.lump_refill <= 0; }+bool refill_lump(int n) {+ if (S.lumps < n || !can_refill_lump()) return false;+ S.lumps -= n;+ S.lump_refill = LUMP_REFILL_MAX;+ G.recalculate = true;+ return true;+}++/* a building's level: level + 1 lumps */+bool level_up(int b) {+ Building *m = &S.buildings[b];+ if (!can_lumps() || S.ascension_mode == 1 || S.lumps < m->level + 1) return false;+ S.lumps -= m->level + 1;+ m->level++;+ if (m->level >= 10 && building_links(b)->level10 != NONE) win(building_links(b)->level10);+ extern void building_levelled(int b);+ building_levelled(b);+ G.recalculate = true, G.store_dirty = true;+ return true;+}diff --git a/games/cookieclicker/src/main.c b/games/cookieclicker/src/main.cindex eb602eea..711a803b 100644--- a/games/cookieclicker/src/main.c+++ b/games/cookieclicker/src/main.c@@ -1,614 +1,72 @@-/* Cookie Clicker: Orteil's idle game, for the NumWorks calculator.+/* Cookie Clicker for the NumWorks calculator.*- * Click the big cookie, buy buildings that bake for you, then upgrades that make them bake more,- * and catch the golden cookies. The numbers are the game's own (version 2.05): its 20 buildings- * with their prices and cookies per second, each one 15% dearer than the last, the tiered- * upgrades that double a building, the cursor's thousand fingers, the mice, flavored cookies,- * kittens that turn milk (achievements) into cookies, and golden cookies with Frenzy, Lucky and- * Click frenzy.- *- * The bank is counted in doubles, as the game does; prices and rates in floats, whose 7 digits- * are more than the game shows (1.234 million). Inside NumPlay it draws with the launcher's- * strips, shapes and fonts and unpacks its names and news with the launcher's DEFLATE decoder;- * on its own (CookieClicker.nwa) it brings them along. */-#include <eadk.h>-#include "../../../launcher/src/gfx.h"-#include "../../../launcher/src/inflate.h"-#include "../../common/np_text.h"--#if NP_MODULE /* (np_file_read and np_file_write: NumPlay's, launcher/src/np.h) */-#define np_app_begin()-#define np_app_end() 0-#else-#include "../../common/epsilon_app.h"-#include "../../common/epsilon_files.h"-#define np_file_read ef_read-#define np_file_write ef_write+ * Cookie Clicker is by Orteil and Opti (DashNet): its pictures, texts, numbers and rules come from+ * the game itself (version 2.058, from its public mirror; see tools/fetch.py). Not affiliated with+ * DashNet. Made by Mason Chen as part of NumPlay. */+#include "game.h"+#include "gfx.h"+#include "plat.h"+#include "ui.h"++bool g_quit;+extern bool game_load(void);+extern bool game_save(void);++/* the game: loaded or new, its frames, its saves every minute */+void cc_begin(void) {+ G.seed = plat_random() | 1;+ game_new();+ if (!game_load()) {+ S.start_date = S.full_date = S.play_time = 0;+ calculate_gains();+ }+ game_rebuild_upgrades();+ ui_init();+}++void cc_frame(uint32_t pressed, uint32_t held) {+ ui_keys(pressed, held);+ game_logic();+ ui_tick();+ if (G.T % (FPS * 60) == 0 && G.T > FPS * 10 && !G.on_ascend && G.ascend_timer == 0) game_save();+}++#ifndef HOSTconst char eadk_app_name[] __attribute__((section(".rodata.eadk_app_name"))) = "Cookie Clicker";const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level"))) = 0;-void np_push(int x, int y, int w, int h, const color_t *px) {- eadk_display_push_rect((eadk_rect_t){(uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h}, px);-}-#endif-#include "data.h"--/* the keys, in 32 bits: those from 36 on come down 23 */-#define K(k) (1u << ((k) < 32 ? (k) : (k) - 23))-static uint32_t keys(void) {- uint64_t s = eadk_keyboard_scan();- return ((uint32_t)s & 0x80001FFFu) | ((uint32_t)(s >> 32) & 0x1FFFF0u) << 9;-}-#define WHITE 0xFFFF-#define CREAM HEX(0xEDE3D3)-#define GOLD HEX(0xFFD966)-#define WOOD HEX(0x3A2716)-#define DARK HEX(0x24170C)-#define NB 20-#define LW 144 /* the left panel, the cookie's; the store is right of it */-#define SX (LW + 2)-#define CX 72 /* the big cookie */-#define CY 128-#define INFO 190 /* what the selected thing does */--static const char *const bname[NB] = {- T("Cursor"), T("Grandma"), T("Farm"), T("Mine"), T("Factory"), T("Bank"), T("Temple"), T("Wizard tower"),- T("Shipment"), T("Alchemy lab"), T("Portal"), T("Time machine"), T("Antimatter condenser"), T("Prism"),- T("Chancemaker"), T("Fractal engine"), T("Javascript console"), T("Idleverse"), T("Cortex baker"), T("You")};-/* each building's price and cookies per second, as two digits and a power of ten */-static const int8_t bdata[NB][4] = {- {15, 0, 10, -2}, {10, 1, 10, -1}, {11, 2, 80, -1}, {12, 3, 47, 0}, {13, 4, 26, 1}, {14, 5, 14, 2},- {20, 6, 78, 2}, {33, 7, 44, 3}, {51, 8, 26, 4}, {75, 9, 16, 5}, {10, 11, 10, 6}, {14, 12, 65, 6},- {17, 13, 43, 7}, {21, 14, 29, 8}, {26, 15, 21, 9}, {31, 16, 15, 10}, {71, 18, 11, 11}, {12, 21, 83, 11},- {19, 23, 64, 12}, {54, 25, 51, 13}};-/* the upgrade tiers' colours (Plain, Berrylium, Blueberrylium...), the milks' */-static const uint32_t tier_rgb[10] = {0xCCB3AC, 0xFF89E7, 0x00DEFF, 0xFFCC2F, 0xE9D673,- 0xA8BF91, 0x60FF50, 0xF01700, 0x9AB834, 0x7E7AB9};-static const uint32_t milk_rgb[N_MILK] = {0xF4F1EA, 0x8B5A33, 0xF06C93};--/* ------------------------------------------------------------ the bakery (cookieclicker.sav) */-static struct {- uint8_t magic, version, flags, mode; /* flags: 1 the guide was read; mode: buy 1, 10 or 100 (0-2) */- uint16_t amount[NB];- uint32_t clicks, golden;- uint32_t gc_t, frenzy, cfrenzy; /* ms since the last golden cookie; what is left of each effect */- double cookies, earned, handmade;- uint8_t up[(N_UP + 7) / 8], unl[(N_UP + 7) / 8], ach[(N_ACH + 7) / 8];-} sv;-#define SAVE_NAME "cookieclicker.sav"--static union { /* the inflater's tables while the texts are unpacked, the strip after */- color_t strip[SCREEN_W * STRIP_H];- uint8_t tables[3400];-} ram;-static char text[TEXT_SIZE], buf[160], pop[48];-static uint16_t text_at[N_TEXT];-static uint8_t list[N_UP];-static float cps, raw_cps, cpc, each[NB], milk;-static int nach, nup, owned, nlist, tab = 1, sel[3], top[3], ov, osel, toast = -1, gc_x, gc_y, news_x, news_w;-static uint32_t now, seed, toast_t, news_n, gc_life, gc_dur, pop_t, bounce_t;-static struct {- int16_t x, y;- uint32_t t;- char s[32];-} rises[4];--static uint32_t rnd(void) {- seed ^= seed << 13;- seed ^= seed >> 17;- return seed ^= seed << 5;-}-static bool has(const uint8_t *bits, int i) { return bits[i >> 3] >> (i & 7) & 1; }-static void set(uint8_t *bits, int i) { bits[i >> 3] |= (uint8_t)(1 << (i & 7)); }-static const char *txt(int i) { return text + text_at[i]; }-static float powi(float x, int n) {- float r = 1;- for (; n; n >>= 1, x *= x)- if (n & 1) r *= x;- return r;-}-static float p10(int e) { return e < 0 ? 1 / powi(10, -e) : powi(10, e); }-static float base_price(int b) { return bdata[b][0] * p10(bdata[b][1]); }-static int many(void) { return sv.mode == 2 ? 100 : sv.mode == 1 ? 10 : 1; }-/* the price of n more buildings b: 15% more for each one owned, rounded up */-static float price(int b, int n) {- float p = base_price(b) * powi(1.15f, sv.amount[b]);- return __builtin_ceilf((n > 1 ? p * (powi(1.15f, n) - 1) / 0.15f : p) * 0.999999f);-}--/* ------------------------------------------------------------ numbers, as the game writes them */-static const char *const units[12] = {- T(" million"), T(" billion"), T(" trillion"), T(" quadrillion"), T(" quintillion"), T(" sextillion"),- T(" septillion"), T(" octillion"), T(" nonillion"), T(" decillion"), T(" undecillion"), T(" duodecillion")};-static char *cpy(char *o, const char *s) {- while ((*o = *s++)) o++;- return o;-}-static char *num(char *o, uint32_t v) { /* with commas: 1,234,567 */- char t[14];- int n = 0;- do {- if (n % 4 == 3) t[n++] = ',';- t[n++] = (char)('0' + v % 10);- } while (v /= 10);- while (n) *o++ = t[--n];- *o = 0;- return o;-}-/* 0.1 and 12.3 (a decimal when there is one, below 1,000), 123,456, then 1.234 million, 12.5 billion... */-static char *big(char *o, double v) {- int u = 0;- if (v < 1e6) {- uint32_t t = (uint32_t)(v * 10 + .5);- if (v >= 1000 || t % 10 == 0) return num(o, v >= 1000 ? (uint32_t)v : t / 10);- o = num(o, t / 10);- *o++ = '.', *o++ = (char)('0' + t % 10), *o = 0;- return o;- }- for (v /= 1e6; v >= 999.9995 && u < 11; u++) v /= 1000;- uint32_t m = (uint32_t)(v * 1000 + .5);- o = num(o, m / 1000);- if ((m %= 1000)) {- *o++ = '.';- for (int d = 100; m; d /= 10) *o++ = (char)('0' + m / d), m %= d;- }- return cpy(o, units[u]);-}-static char *cat(char *o, const char *a, double v, const char *b) { return cpy(big(cpy(o, a), v), b); }--/* ------------------------------------------------------------ cookies per second */-static int bought(int from, int n) {- int k = 0;- while (n--) k += has(sv.up, from++);- return k;-}-/* the cursor's thousand fingers: what each building that isn't a cursor adds to it and to a click */-static float fingers(void) {- float add = has(sv.up, 3) ? 0.1f : 0;- for (int t = 4; t < N_CURSOR; t++)- if (has(sv.up, t)) add *= t == 4 ? 5 : t == 5 ? 10 : 20;- return add * (float)(owned - sv.amount[0]);-}-static void compute(void) {- owned = 0, nup = bought(0, N_UP), nach = 0;- for (int b = 0; b < NB; b++) owned += sv.amount[b];- for (int i = 0; i < N_ACH; i++) nach += has(sv.ach, i);- milk = (float)nach / 25;- float mult = 1, total = 0, clicks = (float)(1 << bought(0, 3)), frenzy = sv.frenzy ? 7 : 1;- for (int i = 0; i < N_COOKIE; i++)- if (has(sv.up, U_COOKIE + i)) mult *= 1 + (float)(cookie_up[i] >> 5) / 100;- for (int i = 0; i < N_KITTEN; i++) /* +10%, 12.5%, 15% of the milk */- if (has(sv.up, U_KITTEN + i)) mult *= 1 + milk * (float)(4 + i) / 40;- for (int b = 0; b < NB; b++) {- float c = bdata[b][2] * p10(bdata[b][3]);- if (b == 0) c = c * clicks + fingers();- else c *= (float)(1 << bought(U_TIER + (b - 1) * TIER_N, TIER_N));- each[b] = c * mult * frenzy;- total += sv.amount[b] * c;- }- raw_cps = total * mult, cps = raw_cps * frenzy;- cpc = (clicks + fingers() + (float)bought(U_MOUSE, N_MOUSE) * cps / 100) * (sv.cfrenzy ? 777 : 1);-}--/* ------------------------------------------------------------ upgrades */-static const uint8_t cursor_at[N_CURSOR] = {1, 1, 10, 25, 50, 100, 150, 200};-static const uint8_t cursor_e[N_CURSOR] = {2, 2, 4, 5, 7, 8, 9, 10}, kitten_e[3] = {6, 9, 13};-static const uint8_t tier_e[TIER_N] = {1, 1, 2}, tier_at[TIER_N] = {1, 5, 25}, golden_at[3] = {7, 27, 77};--static float up_price(int u) {- if (u < U_MOUSE) return (u == 1 ? 5 : 1) * p10(cursor_e[u]);- if (u < U_KITTEN) return 5 * p10(4 + 2 * (u - U_MOUSE));- if (u < U_GOLD) return 9 * p10(kitten_e[u - U_KITTEN]);- if (u < U_COOKIE) return 7 * (p10(9 + 2 * (u - U_GOLD) + (u == U_GOLD + 2)) - 1) / 9; /* 777,777,777... */- if (u < U_TIER) { /* 999,999 or 4,999,995... */- int c = cookie_up[u - U_COOKIE];- return (p10((c & 15) + 5) - 1) * (c & 16 ? 5 : 1);- }- int t = (u - U_TIER) % TIER_N; /* 10, 50, 500, 50,000... times its building's price */- return base_price(1 + (u - U_TIER) / TIER_N) * p10(tier_e[t]) * (t ? 5 : 1);-}-static bool up_ready(int u) { /* unlocked by what the bakery has done */- if (u < U_MOUSE) return sv.amount[0] >= cursor_at[u];- if (u < U_KITTEN) return sv.handmade >= p10(3 + 2 * (u - U_MOUSE));- if (u < U_GOLD) return milk >= (u == U_KITTEN ? 0.5f : (float)(u - U_KITTEN));- if (u < U_COOKIE) return sv.golden >= golden_at[u - U_GOLD];- if (u < U_TIER) return sv.earned * 20 >= up_price(u);- return sv.amount[1 + (u - U_TIER) / TIER_N] >= tier_at[(u - U_TIER) % TIER_N];-}-static void up_desc(int u) { /* what it does, in buf */- if (u < 3) cpy(buf, T("The mouse and cursors are twice as efficient."));- else if (u == 3) cpy(buf, T("The mouse and cursors gain +0.1 cookies for each other building."));- else if (u < U_MOUSE) cat(buf, T("Thousand fingers x"), u == 4 ? 5 : u == 5 ? 10 : 20, "");- else if (u < U_KITTEN) cpy(buf, T("Clicking gains +1% of your CpS."));- else if (u < U_GOLD) cpy(buf, T("More CpS the more milk you have."));- else if (u < U_COOKIE) cpy(buf, u < U_GOLD + 2 ? T("Golden cookies come twice as often, stay twice as long.")- : T("Golden cookie effects last twice as long."));- else if (u < U_TIER) cat(buf, T("Cookie production +"), cookie_up[u - U_COOKIE] >> 5, "%");- else cpy(cpy(buf, bname[1 + (u - U_TIER) / TIER_N]), T(": twice as efficient."));-}-static void sort_list(void) { /* the store's upgrades: unlocked, not bought yet, cheapest first */- nlist = 0;- for (int u = 0; u < N_UP; u++) {- if (!has(sv.unl, u) || has(sv.up, u)) continue;- int i = nlist++;- float p = up_price(u);- while (i && up_price(list[i - 1]) > p) list[i] = list[i - 1], i--;- list[i] = (uint8_t)u;- }-}-/* ------------------------------------------------------------ achievements */-/* their kind: baked, per second, from clicking, buildings, golden cookies, owned, upgrades; where each- kind starts; the counts they ask for */-static const uint8_t kinds[6] = {A_CPS, A_CLICK, A_BUILD, A_GOLDEN, A_OWNED, A_UPGRADED};-static const uint16_t counts[] = {1, 2, 50, 1, 7, 27, 77, 100, 500, 20, 50};-static int threshold(int a, float *v) {- static const uint8_t first[7] = {0, 0, 0, 0, 3, 7, 9}; /* (in counts) */- int k = 0, i;- while (k < 6 && a >= kinds[k]) k++;- i = a - (k ? kinds[k - 1] : 0);- *v = k == 0 ? (a ? p10(3 * a / 2 + 2) : 1) : k == 1 ? p10(6 * i / 5) : k == 2 ? p10(3 + 2 * i)- : k == 3 ? counts[i < N_CURSOR_ACH ? i : 0] : counts[first[k] + i];- return k;-}-static int ach_building(int a) { return a - A_BUILD < N_CURSOR_ACH ? 0 : a - A_BUILD - N_CURSOR_ACH + 1; }-static bool ach_won(int a) {- float v;- int k = threshold(a, &v);- return (k == 0 ? sv.earned : k == 2 ? sv.handmade : k == 1 ? raw_cps : k == 3 ? sv.amount[ach_building(a)]- : k == 4 ? (double)sv.golden : k == 5 ? owned : nup) >= v;-}-static void win(int a) {- if (has(sv.ach, a)) return;- set(sv.ach, a);- toast = a, toast_t = now;-}-static void ach_desc(int a) { /* what it takes, in buf */- static const char *const pre[7] = {T("Bake "), T("Bake "), T("Make "), T("Have "), T("Click "), T("Own "), T("Purchase ")};- static const char *const post[7] = {T(" cookies."), T(" cookies per second."),- T(" cookies from clicking."), " x ", T(" golden cookies."), T(" buildings."),- T(" upgrades.")};- float v;- int k = threshold(a, &v);- cpy(cat(buf, pre[k], v, post[k]), k == 3 ? bname[ach_building(a)] : "");- if (v == 1) /* 1 cookie, 1 golden cookie: the plural s goes (none of the verbs ends in one) */- for (char *s = buf, *d = buf; (*d = *s); s++) d += !(*s == 's' && (s[1] == ' ' || s[1] == '.'));-}--static void check(void) { /* once a second, and after a purchase: what unlocks, what is won */- compute();- for (int a = 0; a < N_ACH; a++)- if (ach_won(a)) win(a);- compute();- for (int u = 0; u < N_UP; u++)- if (!has(sv.unl, u) && up_ready(u)) set(sv.unl, u), nlist = -1;- if (nlist < 0) sort_list();-}-static void save(void) {- sv.magic = 'C', sv.version = 1;- np_file_write(SAVE_NAME, &sv, sizeof sv);-}--/* ------------------------------------------------------------ playing */-static void earn(double v) { sv.cookies += v, sv.earned += v; }-static void click(void) {- int i = sv.clicks++ & 3;- earn(cpc);- sv.handmade += cpc, bounce_t = now;- rises[i].x = (int16_t)(CX - 30 + rnd() % 60), rises[i].y = (int16_t)(CY - 24 - rnd() % 24), rises[i].t = now;- big(cpy(rises[i].s, "+"), cpc);-}-static void buy(void) {- int s = sel[tab];- float p = tab ? price(s, many()) : up_price(list[s]);- if (sv.cookies < p) return;- sv.cookies -= p;- if (tab) sv.amount[s] = (uint16_t)(sv.amount[s] + many());- else set(sv.up, list[s]), sort_list();- check();- save();-}--/* the golden cookie: once 5 to 15 minutes have gone by (half that with Lucky day, half again with- Serendipity), it shows for 13 seconds (twice as long with each); then Frenzy or Lucky, sometimes- Click frenzy */-static int luck(void) { return has(sv.up, U_GOLD) + has(sv.up, U_GOLD + 1); }-static void golden_pop(void) {- uint32_t dur = has(sv.up, U_GOLD + 2) + 1, e = rnd() % 30;- sv.golden++, gc_life = 0;- if (e == 0) sv.cfrenzy = 13000 * dur;- else if (e < 16) sv.frenzy = 77000 * dur;- else {- double v = sv.cookies * 0.15 < cps * 900.0 ? sv.cookies * 0.15 : cps * 900.0;- earn(v + 13);- cat(pop, T("Lucky! +"), v + 13, "");- }- pop_t = now;- check();- save();-}--/* ------------------------------------------------------------ drawing */-#define VIS(y, h) ((y) < gfx_y1 && (y) + (h) > gfx_y0)-static void say(const np_font_t *f, int x, int y, const char *s, color_t c) { gfx_text(f, x, y, s, c, 256); }-static void mid(const np_font_t *f, int x, int y, const char *s, color_t c) { gfx_text_center(f, x, y, s, c, 256); }-static int para(int y, const char *s, color_t c) { return gfx_paragraph(&np_font_small, SX + 87, y, 166, 12, s, c, 256); }-/* a cookie, r pixels round: golden or not */-static void cookie(int x, int y, int r, bool gold) {- static const int8_t chips[9][3] = {{-22, -24, 9}, {14, -30, 7}, {30, -2, 9}, {-34, 6, 7}, {-8, 4, 10},- {18, 22, 8}, {-16, 30, 8}, {2, -12, 5}, {34, 24, 5}};- if (!VIS(y - r, 2 * r)) return;- gfx_circle(x, y, r, gold ? HEX(0xC48A1C) : HEX(0x9C5B26), 256);- gfx_circle(x, y, r - 1 - r / 16, gold ? HEX(0xF2C33C) : HEX(0xD9A25E), 256);- gfx_circle(x - r / 4, y - r / 4, r / 2, WHITE, 40);- for (int i = 0; i < 9; i++) {- int cx = x + chips[i][0] * r / 52, cy = y + chips[i][1] * r / 52, cr = chips[i][2] * r / 52 + 1;- gfx_circle(cx, cy, cr, gold ? HEX(0xB07A12) : HEX(0x4B2611), 256);- gfx_circle(cx - cr / 3, cy - cr / 3, cr / 3, WHITE, 50);- }-}--static void left(void) {- gfx_fill(0, 16, LW, SCREEN_H - 16, HEX(0x22406A));- gfx_circle(CX, CY, 70, WHITE, 24); /* the light behind the big cookie */- uint32_t b = now - bounce_t; /* a little smaller for a moment when clicked */- cookie(CX, CY, b < 240 ? 48 + (int)b / 60 : 52, false);- /* the milk, which rises with the achievements and changes flavor every 25 */- int h = 10 + (int)((milk > 1 ? 1 : milk) * 20), rank = nach / 25; /* (59 achievements: 3 milks) */- for (int x = 0; x < LW; x++) {- int w = (int)(now / 40 + x) % 48;- gfx_fill(x, SCREEN_H - h + (w < 24 ? w : 48 - w) / 6, 1, h + 8, gfx_rgb(milk_rgb[rank]));- }- /* the cookies: "1.234 million", the number on its own line, "million cookies" under it; per second */- if (VIS(16, 56)) {- char *name = NULL, *line2 = buf + 80;- big(buf, sv.cookies < 1e6 ? (double)(uint32_t)sv.cookies : sv.cookies); /* (whole cookies) */- for (char *s = buf; *s && !name; s++)- if (*s == ' ') *s = 0, name = s + 1;- mid(&np_font_title, CX, 40, buf, WHITE);- cpy(name ? cpy(cpy(line2, name), " ") : line2, T("cookies"));- mid(&np_font_body, CX, 54, line2, WHITE);- cat(buf, T("per second: "), cps, "");- mid(&np_font_small, CX, 67, buf, CREAM);- }- /* what the golden cookie did, and for how long still; +1 rising from the cookie */- uint32_t ms = sv.cfrenzy ? sv.cfrenzy : sv.frenzy;- if (ms) num(cpy(buf, sv.cfrenzy ? T("Click frenzy x777: ") : T("Frenzy x7: ")), (ms + 999) / 1000);- if (ms || now - pop_t < 2500) mid(&np_font_small, CX, 196, ms ? buf : pop, GOLD);- for (int i = 0; i < 4; i++) {- uint32_t t = now - rises[i].t;- if (rises[i].t && t < 900)- gfx_text_center(&np_font_body, rises[i].x, rises[i].y - (int)t / 20, rises[i].s, WHITE, 256 - (int)t * 2 / 7);- }- if (gc_life) { /* the golden cookie, fading in and out */- float k = (float)gc_life / (float)gc_dur * 2 - 1;- int a = (int)((1 - k * k * k * k) * 256);- gfx_circle(gc_x, gc_y, 20, HEX(0xFFE680), a / 3);- cookie(gc_x, gc_y, 14, true);- gfx_text_center(&np_font_small, gc_x, gc_y + 26, "shift", WHITE, a);- }- if (toast >= 0 && now - toast_t < 3500) {- gfx_rrect(4, 206, LW - 8, 30, 6, DARK, 230);- mid(&np_font_small, CX, 218, T("Achievement unlocked"), HEX(0xC9B79C));- mid(&np_font_small, CX, 231, txt(X_ACH + toast), WHITE);- }-}--/* ------------------------------------------------------------ the store */-static void fit(const np_font_t *f, const char *s, int w) { /* s in buf, cut to w pixels */- char *e = cpy(buf, s);- while (gfx_text_width(f, buf) > w && e > buf + 4) cpy(--e, "...");-}-/* a picture: a building's (or a mouse, a kitten, a cookie) on its tier's colour */-static void picture(int u, int x, int y) {- int t = u, k = IC_CURSOR;- if (u >= U_MOUSE) t = u - U_MOUSE, k = IC_MOUSE;- if (u >= U_KITTEN) t = u - U_KITTEN, k = IC_KITTEN;- if (u >= U_TIER) t = (u - U_TIER) % TIER_N, k = 1 + (u - U_TIER) / TIER_N;- if (u < 0) t = 3, k = -1 - u; /* (a building) */- gfx_rrect(x, y, 18, 18, 4, gfx_rgb(tier_rgb[t]), 256);- if (u >= U_GOLD && u < U_TIER) cookie(x + 9, y + 9, 7, u < U_COOKIE);- else- for (int i = 0; i < 144; i++)- if ((uint8_t)text[ICONS_AT + 18 * k + (i >> 3)] >> (i & 7) & 1) gfx_fill(x + 3 + i % 12, y + 3 + i / 12, 1, 1, DARK);-}-static bool locked(int b) { return !sv.amount[b] && sv.earned < base_price(b); }-static int rows(void) {- int n = 2;- for (int b = 0; b < NB; b++)- if (!locked(b)) n = b + 3; /* the next two buildings show as ??? */- return tab == 0 ? nlist : tab == 1 ? (n < NB ? n : NB) : N_ACH;-}--static void store(void) {- static const char *const tabs[3] = {T("Upgrades"), T("Buildings"), T("Stats")};- gfx_fill(LW, 16, SCREEN_W - LW, SCREEN_H - 16, WOOD);- /* the tabs; how many are bought at once, how many achievements are won */- if (VIS(16, 30)) {- for (int i = 0; i < 3; i++) {- if (i == tab) gfx_rrect(SX + 1 + i * 58, 18, 56, 14, 5, HEX(0x8A6238), 256);- mid(&np_font_small, SX + 29 + i * 58, 29, tabs[i], i == tab ? WHITE : HEX(0xB79C7C));- }- *buf = 0;- if (tab == 1) num(cpy(buf, T("Buy x")), (uint32_t)many());- if (tab == 2) cpy(num(cpy(num(buf, (uint32_t)nach), " / "), N_ACH), T(" achievements"));- mid(&np_font_small, SX + 87, 42, buf, HEX(0x9CF29C));- }- /* the list */- int n = rows(), h = tab == 2 ? 12 : 24, s = sel[tab];- for (int r = 0; r < 144 / h && top[tab] + r < n; r++) {- int i = top[tab] + r, y = 46 + r * h;- if (!VIS(y, h)) continue;- gfx_fill(SX, y, SCREEN_W - SX, h - 1, i == s ? HEX(0x6E4D2E) : tab == 2 ? WOOD : HEX(0x4C331E));- if (tab == 2) {- fit(&np_font_small, txt(X_ACH + i), 166);- say(&np_font_small, SX + 4, y + 9, buf, has(sv.ach, i) ? WHITE : HEX(0x8C7A66));- continue;- }- float p;- if (tab == 1) {- if (sv.amount[i]) num(buf, sv.amount[i]), gfx_text_right(&np_font_title, SCREEN_W - 4, y + 20, buf, WHITE, 70);- if (!locked(i)) picture(-1 - i, SX + 3, y + 3);- cpy(buf, locked(i) ? "???" : bname[i]);- p = price(i, many());- } else {- picture(list[i], SX + 3, y + 3);- fit(&np_font_body, txt(list[i]), SCREEN_W - SX - 30);- p = up_price(list[i]);- }- say(&np_font_body, SX + 25, y + 11, buf, WHITE);- big(buf, p);- say(&np_font_small, SX + 25, y + 21, buf, sv.cookies >= p ? HEX(0x6CF26C) : HEX(0xFF6B6B));- }- /* what the selected one does */- if (!VIS(INFO, SCREEN_H - INFO)) return;- gfx_fill(SX, INFO, SCREEN_W - SX, SCREEN_H - INFO, DARK);- int y = INFO + 14;- *buf = 0;- if (s >= n || (tab == 1 && locked(s))) return;- if (tab == 1)- cat(num(cpy(cat(buf, T("Each makes "), each[s], T(" cookies per second.")), "\n"), sv.amount[s]), T(" make "),- each[s] * sv.amount[s], "");- else if (tab == 0) y = para(y, txt(list[s]), GOLD), up_desc(list[s]);- else y = para(y, txt(X_ACH + s), GOLD), ach_desc(s);- para(y, buf, CREAM);-}--/* ------------------------------------------------------------ the news, and the menus */-static void next_news(void) { /* how far the bakery's fame has gone: the digits of a tenth of all it baked */- int l = 0;- while (l < N_LORE - 1 && sv.earned >= 10 * p10(l)) l++;- news_n = (uint32_t)(X_NEWS + l);- news_x = SCREEN_W, news_w = gfx_text_width(&np_font_small, txt(news_n));-}--enum { OV_NONE, OV_MENU, OV_HELP, OV_QUIT };-static const char *const menu_items[3] = {T("Resume"), T("How to play"), T("Quit game")};-static const char *const help_keys[12] = {- "OK", T("click the cookie"), "shift", T("catch a golden cookie"), T("Arrows"), T("choose, change tabs"),- "EXE", T("buy"), "x", T("buy 1, 10 or 100"), T("Back"), T("menu")};-static void button(int y, const char *s, bool on) {- gfx_rrect(98, y, 124, 24, 12, on ? GOLD : HEX(0x6B4A2C), 256);- mid(&np_font_body, 160, y + 17, s, on ? WOOD : WHITE);-}-static void overlay(void) {- static const char *const titles[4] = {0, "Cookie Clicker", T("How to play"), T("Quit the game?")};- gfx_fill_alpha(0, 0, SCREEN_W, SCREEN_H, 0, 130);- gfx_rrect(40, 22, 240, 204, 14, WOOD, 256);-- mid(&np_font_title, 160, 52, titles[ov], WHITE);- if (ov == OV_HELP) {- for (int i = 0; i < 6; i++) {- gfx_text_right(&np_font_small, 128, 76 + 16 * i, help_keys[2 * i], GOLD, 256);- say(&np_font_small, 136, 76 + 16 * i, help_keys[2 * i + 1], WHITE);- }- mid(&np_font_small, 160, 182, T("Your bakery only bakes while the game is open."), HEX(0xC9B79C));- button(192, T("Play"), true);- return;- }- int n = ov == OV_MENU ? 3 : 2;- for (int i = 0; i < n; i++) button(196 - 32 * (n - i), ov == OV_MENU ? menu_items[i] : i ? T("No") : T("Yes"), osel == i);- if (ov == OV_QUIT) mid(&np_font_small, 160, 96, T("Your bakery is saved."), WHITE);-}--static void scene(void *ctx) {- if (VIS(0, 16)) { /* the news */- gfx_fill(0, 0, SCREEN_W, 16, HEX(0x150D06));- say(&np_font_small, news_x, 12, txt(news_n), HEX(0xE8DCC8));- }- left();- store();- if (ov) overlay();-}--/* ------------------------------------------------------------ the game */-static void load(void) {- uint32_t len = 0;- const uint8_t *d = np_file_read(SAVE_NAME, &len);- if (d && len == sizeof sv && d[0] == 'C' && d[1] == 1) /* (or a new bakery: sv starts as zeros) */- for (uint32_t i = 0; i < sizeof sv; i++) ((uint8_t *)&sv)[i] = d[i];- /* whatever it holds, a bakery this game could have saved */- for (double *v = &sv.cookies; v <= &sv.handmade; v++)- if (!(*v >= 0 && *v < 1e300)) *v = 0;-}-static void move(int d) {- int n = rows(), shown = tab == 2 ? 12 : 6, *s = &sel[tab], *t = &top[tab];- *s += d;- if (*s >= n) *s = n - 1;- if (*s < 0) *s = 0;- if (*s < *t) *t = *s;- if (*s >= *t + shown) *t = *s - shown + 1;-}+uint32_t perf_frames __attribute__((used)); /* read by tools/emu.py */+uint32_t perf_updates __attribute__((used));int main(void) {- np_app_begin();- /* the names and the news, unpacked once */- if (np_inflate_tables_size() <= sizeof ram.tables)- np_inflate((uint8_t *)text, TEXT_SIZE, text_z, sizeof text_z, (np_inflate_tables_t *)(void *)ram.tables);- for (int i = 0, at = 0; i < N_TEXT; i++) {- text_at[i] = (uint16_t)at;- while (at < TEXT_SIZE - 1 && text[at]) at++;- at++;- }- color_t *their_strip = gfx_buf;- gfx_buf = ram.strip;- now = (uint32_t)eadk_timing_millis();- seed = eadk_random() | 1;- load();- sort_list();- check();- next_news();- if (!(sv.flags & 1)) ov = OV_HELP, sv.flags |= 1;- uint32_t held = keys(), stale = held; /* keys still down from the launcher wait to be let go */- uint32_t repeat_at = 0, last = now, second = now, saved = now;- for (;;) {- now = (uint32_t)eadk_timing_millis();- uint32_t dt = now - last > 250 ? 250 : now - last, k = keys(), hit = k & ~held;- const uint32_t ud = K(eadk_key_up) | K(eadk_key_down) | K(eadk_key_eight) | K(eadk_key_two);- last = now, stale &= k;- if (hit & ud) repeat_at = now + 300;- else if ((k & ud & ~stale) && (int32_t)(now - repeat_at) >= 0) hit |= k & ud & ~stale, repeat_at = now + 60;- held = k;- if (k & (K(eadk_key_home) | K(eadk_key_on_off))) break;- bool ok = hit & (K(eadk_key_ok) | K(eadk_key_five)), exe = hit & K(eadk_key_exe);- int dx = !!(hit & (K(eadk_key_right) | K(eadk_key_six))) - !!(hit & (K(eadk_key_left) | K(eadk_key_four)));- int dy = !!(hit & (K(eadk_key_down) | K(eadk_key_two))) - !!(hit & (K(eadk_key_up) | K(eadk_key_eight)));- if (ov) {- int n = ov == OV_MENU ? 3 : 2, was = ov, c = osel = (osel + dy + n) % n;- if (hit & K(eadk_key_back)) ov = OV_NONE;- else if (ok || exe) { /* (Quit game asks first, No chosen) */- ov = was == OV_MENU && c ? OV_MENU + c : OV_NONE, osel = 1;- if (was == OV_QUIT && !c) break;- }- } else {- if (ok) click();- if ((hit & K(eadk_key_shift)) && gc_life) golden_pop();- if (hit & K(eadk_key_back)) ov = OV_MENU, osel = 0, save();- if (hit & K(eadk_key_multiplication)) sv.mode = (uint8_t)((sv.mode + 1) % 3);- tab = (tab + dx + 3) % 3;- move(dy);- if (exe && tab < 2 && sel[tab] < rows()) buy();+ uint16_t band[SCREEN_W * GFX_BAND]; /* (here: on the stack, out of the RAM apps get) */+ gfx_set_band_memory(band);+ plat_begin();+ cc_begin();+ uint32_t next = plat_millis(), prev = 0;+ int sub = 0;+ /* the game's frames are thirtieths of a second; drawn when caught up, at most 4 frames a drawing */+ while (!g_quit) {+ int n = 0;+ uint32_t now = plat_millis();+ while ((int32_t)(now - next) >= 0 && n < 4 && !g_quit) {+ uint32_t held = plat_keys();+ if (held & K_HOME) g_quit = true;+ cc_frame(held & ~prev, held);+ prev = held;+ perf_updates++;+ next += 33 + (++sub % 3 == 0); /* (33, 33, 34: a thirtieth of a second) */+ n++;}- /* time goes by: baking, the golden cookie and its effects */- earn((double)cps * dt / 1000);- for (uint32_t *t = &sv.frenzy; t <= &sv.cfrenzy; t++)- if (*t && !(*t = *t > dt ? *t - dt : 0)) compute();- if (gc_life) gc_life = gc_life > dt ? gc_life - dt : 0;- else if ((sv.gc_t += dt) >= 300000u >> luck()) {- uint32_t lo = 300000u >> luck();- float f = (float)(sv.gc_t - lo) / (float)(2 * lo);- if (f > 1 || (float)(rnd() & 0xFFFF) < f * f * f * f * f * 65536)- sv.gc_t = 0, gc_dur = gc_life = 13000u << luck(), gc_x = 20 + (int)(rnd() % (LW - 40)), gc_y = 84 + (int)(rnd() % 100);- }- if (now - second >= 1000) second = now, check();- if (now - saved >= 10000) saved = now, save();- news_x -= (int)(dt * 45 / 1000) + 1;- if (news_x < -news_w) next_news();- eadk_display_wait_for_vblank();- gfx_render(scene, 0, 0, SCREEN_H);- uint32_t spent = (uint32_t)eadk_timing_millis() - now;- if (spent < 30) eadk_timing_msleep(30 - spent);+ if (g_quit) break;+ if ((int32_t)(now - next) > 300) next = now; /* far behind: slower, rather than rushing */+ if (n) {+ ui_frame();+ perf_frames++;+ } else+ plat_sleep(1);}- save();- gfx_buf = their_strip;- return np_app_end();+ game_save();+ return plat_end();}+#endifdiff --git a/games/cookieclicker/src/menus.c b/games/cookieclicker/src/menus.cnew file mode 100644index 00000000..a6abce75--- /dev/null+++ b/games/cookieclicker/src/menus.c@@ -0,0 +1,754 @@+/* The menus over the game: the menu (Back), Options, Statistics (the general ones, then the+ * upgrades and achievements as the game's crates, with their tooltips), Info, the keys, and the+ * special tabs: Santa's progress and Krumblor the cookie dragon (with its auras). */+#include <math.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include "ui.h"++extern bool game_save(void);+extern bool can_lumps(void);+extern void bakery_name(char *out, int size);+extern double heavenly_multiplier(void);+extern double how_much_prestige(double cookies);+extern const char *const santa_levels[15];+extern const char *const aura_names[N_AURAS];+extern const char *const aura_descs[N_AURAS];+extern const int16_t aura_icons[N_AURAS];+extern const char *dragon_name(void);+extern int dragon_frame(void);+extern void dragon_action(char *action, int asize, char *cost, int csize, bool *can);+extern void upgrade_dragon(void);+extern void set_dragon_aura(int slot, int aura);+extern void pet_dragon(void);+extern void upgrade_santa(void);+extern bool g_quit;++#define PANEL_Y NEWS_H+#define PANEL_H (SCREEN_H - NEWS_H)+#define PAD 10++static void panel(const char *title) {+ gfx_pattern(IM_DARK_NOISE, 0, PANEL_Y, SCREEN_W, PANEL_H, 128, 128, 0, 0, 256);+ gfx_image_scaled(IM_BORDER_SOFT, 0, PANEL_Y, SCREEN_W, PANEL_H, 256);+ for (int x = 0; x < SCREEN_W; x += 128) gfx_image(IM_PANEL_H, x, PANEL_Y, 256);+ if (title) gfx_text_outline_center(F_KAVOON, SCREEN_W / 2, PANEL_Y + 20, title, WHITE, 256);+}++/* a button of the game's menus (".option"), selected or not */+static void button(int x, int y, int w, const char *s, bool sel, bool on) {+ gfx_fill_alpha(x, y, w, 15, on ? RGB(255, 255, 255) : BLACK, on ? 40 : 110);+ gfx_rect(x, y, w, 15, sel ? WHITE : on ? RGB(200, 200, 200) : RGB(110, 110, 110), 256);+ if (sel) gfx_rect(x - 1, y - 1, w + 2, 17, RGB(255, 238, 200), 140);+ gfx_text_center(F_NAME_SMALL, x + w / 2, y + 11, s, sel ? WHITE : on ? RGB(230, 230, 230) : RGB(170, 170, 170), 256);+}++/* ------------------------------------------------------------------ the menu */+enum { M_OPTIONS, M_STATS, M_INFO, M_LEGACY, M_SANTA, M_DRAGON, M_KEYS, M_SAVE, M_QUIT, N_M };+static int menu_items[N_M], nmenu;+static void menu_build(void) {+ nmenu = 0;+ menu_items[nmenu++] = M_OPTIONS;+ menu_items[nmenu++] = M_STATS;+ menu_items[nmenu++] = M_INFO;+ if (S.resets > 0 || how_much_prestige(S.cookies_reset + S.cookies_earned) >= 1) menu_items[nmenu++] = M_LEGACY;+ if (has(U_A_FESTIVE_HAT)) menu_items[nmenu++] = M_SANTA;+ if (has(U_A_CRUMBLY_EGG)) menu_items[nmenu++] = M_DRAGON;+ menu_items[nmenu++] = M_KEYS;+ menu_items[nmenu++] = M_SAVE;+ menu_items[nmenu++] = M_QUIT;+}+static const char *const menu_names[N_M] = {"Options", "Statistics", "Info", "Legacy", "Santa's progress",+ "Krumblor", "Keys", "Save", "Save & Quit"};++static void draw_menu(void) {+ menu_build();+ char t[64];+ bakery_name(t, sizeof t);+ int w = 150, h = 34 + nmenu * 18 + 6, x = (SCREEN_W - w) / 2, y = PANEL_Y + (PANEL_H - h) / 2;+ gfx_fill_alpha(0, PANEL_Y, SCREEN_W, PANEL_H, BLACK, 110);+ draw_frame_box(x, y, w, h);+ gfx_text_outline_center(F_KAVOON, SCREEN_W / 2, y + 19, "Menu", WHITE, 256);+ gfx_text_center(F_SMALL, SCREEN_W / 2, y + 30, t, RGB(204, 204, 204), 256);+ for (int i = 0; i < nmenu; i++) button(x + 12, y + 36 + i * 18, w - 24, menu_names[menu_items[i]], U.menu_sel == i, true);+}++static void menu_choose(int item) {+ switch (item) {+ case M_OPTIONS: U.overlay = OV_OPTIONS, U.list_sel = 0, U.list_top = 0; break;+ case M_STATS: U.overlay = OV_STATS, U.list_sel = 0, U.list_top = 0, U.stats_tab = 0; break;+ case M_INFO: U.overlay = OV_INFO, U.list_top = 0; break;+ case M_LEGACY: prompt_open(PROMPT_ASCEND, 0); break;+ case M_SANTA: U.overlay = OV_SPECIAL, U.special = 0, U.list_sel = 0; break;+ case M_DRAGON: U.overlay = OV_SPECIAL, U.special = 1, U.list_sel = 0; break;+ case M_KEYS: U.overlay = OV_KEYS; break;+ case M_SAVE:+ game_save();+ notify("Game saved", "", -1, 1);+ U.overlay = OV_NONE;+ break;+ case M_QUIT: g_quit = true; break;+ }+}++/* ------------------------------------------------------------------ options */+typedef struct { const char *name, *label; uint8_t *pref; bool invert; } Opt;+enum { O_SAVE, O_WIPE, O_FIRST_PREF };+static Opt opts[] = {+ {"Save", "save manually (the game autosaves every 60 seconds)", NULL, false},+ {"Wipe save", "delete all your progress, including your achievements", NULL, false},+ {"Fancy graphics", "visual improvements; disabling may improve performance", &S.prefs.fancy, false},+ {"Particles", "cookies falling down, etc; disabling may improve performance", &S.prefs.particles, false},+ {"Numbers", "numbers that pop up when clicking the cookie", &S.prefs.numbers, false},+ {"Milk", "only appears with enough achievements", &S.prefs.milk, false},+ {"Cursors", "visual display of your cursors", &S.prefs.cursors, false},+ {"Wobbly cookie", "your cookie will react when you click it", &S.prefs.wobbly, false},+ {"Short numbers", "shorten big numbers", &S.prefs.format_long, true},+ {"Fast notes", "notifications disappear much faster", &S.prefs.notes_on, false},+ {"Scary stuff", NULL, &S.prefs.not_scary, true},+};+#define N_OPTS (int)(sizeof opts / sizeof opts[0])++static void draw_options(void) {+ panel("Options");+ int y = PANEL_Y + 30 - U.list_top;+ gfx_clip(0, PANEL_Y + 26, SCREEN_W, PANEL_H - 28);+ gfx_text_outline(F_NAME, PAD, y + 10, "General", RGB(246, 218, 184), 256);+ y += 16;+ for (int i = 0; i < N_OPTS; i++) {+ if (i == O_FIRST_PREF) {+ y += 4;+ gfx_text_outline(F_NAME, PAD, y + 10, "Settings", RGB(246, 218, 184), 256);+ y += 16;+ }+ char t[64];+ bool on = true;+ if (opts[i].pref) {+ on = (*opts[i].pref != 0) != opts[i].invert;+ snprintf(t, sizeof t, "%s %s", opts[i].name, on ? "ON" : "OFF");+ } else+ snprintf(t, sizeof t, "%s", opts[i].name);+ int bw = gfx_text_width(F_NAME_SMALL, t) + 14;+ if (gfx_visible(0, y - 2, SCREEN_W, 20)) {+ button(PAD, y, bw, t, U.list_sel == i, on);+ if (opts[i].label) {+ char l[96];+ snprintf(l, sizeof l, "(%s)", opts[i].label);+ int lx = PAD + bw + 6;+ if (gfx_text_width(F_SMALL, l) > SCREEN_W - lx - 4) gfx_para(&PS_SMALL, lx, y - 3, SCREEN_W - lx - 4, l, true);+ else gfx_text(F_SMALL, lx, y + 11, l, RGB(180, 180, 180), 256);+ }+ }+ y += 19;+ }+ gfx_unclip();+}++static int options_y(int i) { return 46 + i * 19 + (i >= O_FIRST_PREF ? 20 : 0); }++static void options_keys(uint32_t p) {+ if (p & K_UP && U.list_sel > 0) U.list_sel--;+ if (p & K_DOWN && U.list_sel < N_OPTS - 1) U.list_sel++;+ int y = options_y(U.list_sel), view = PANEL_H - 30;+ if (y - U.list_top > view - 20) U.list_top = y - view + 20;+ if (y - U.list_top < 30) U.list_top = y - 30 < 0 ? 0 : y - 30;+ if (p & (K_OK | K_EXE)) {+ Opt *o = &opts[U.list_sel];+ if (U.list_sel == O_SAVE) {+ game_save();+ notify("Game saved", "", -1, 1);+ } else if (U.list_sel == O_WIPE)+ prompt_open(PROMPT_WIPE, 0);+ else if (o->pref) {+ *o->pref = !*o->pref;+ G.store_dirty = true;+ }+ }+}++/* ------------------------------------------------------------------ statistics */+/* the tabs: General, Upgrades, Achievements */+enum { TAB_GENERAL, TAB_UPGRADES, TAB_ACHIEVS, N_TABS };+static const char *const tab_names[N_TABS] = {"General", "Upgrades", "Achievements"};+#define GRID_COLS 10+#define GRID_X ((SCREEN_W - GRID_COLS * CRATE) / 2)++/* the crates the tabs show, as the game lists them (sorted by their order) */+static uint16_t grid[N_UPGRADES > N_ACHIEVS ? N_UPGRADES : N_ACHIEVS];+static int ngrid, grid_break[3]; /* where the cookies / prestige (upgrades) or shadow (achievements) start */++static void sort_by_order(uint16_t *ids, int n, bool achiev) {+ for (int i = 1; i < n; i++) {+ uint16_t v = ids[i];+ float o = achiev ? achiev_rec(v)->order : upgrade_rec(v)->order;+ int j = i - 1;+ while (j >= 0 && (achiev ? achiev_rec(ids[j])->order : upgrade_rec(ids[j])->order) > o) ids[j + 1] = ids[j], j--;+ ids[j + 1] = v;+ }+}++static void grid_build(int tab) {+ ngrid = 0;+ if (tab == TAB_UPGRADES) {+ /* prestige, then the regular ones, then cookies: those bought */+ for (int pass = 0; pass < 3; pass++) {+ grid_break[pass] = ngrid;+ int start = ngrid;+ for (int u = 0; u < N_UPGRADES; u++) {+ const UpgradeRec *r = upgrade_rec(u);+ if (!bit_get(S.upgrades_bought, u) || r->pool == POOL_DEBUG) continue;+ int want = r->pool == POOL_PRESTIGE ? 0 : r->pool == POOL_COOKIE ? 2 : 1;+ if (want != pass) continue;+ grid[ngrid++] = (uint16_t)u;+ }+ sort_by_order(grid + start, ngrid - start, false);+ }+ } else if (tab == TAB_ACHIEVS) {+ for (int pass = 0; pass < 2; pass++) {+ grid_break[pass] = ngrid;+ int start = ngrid;+ for (int a = 0; a < N_ACHIEVS; a++) {+ const AchievRec *r = achiev_rec(a);+ if (r->pool == APOOL_DUNGEON) continue;+ if ((r->pool == APOOL_SHADOW) != (pass == 1)) continue;+ if (r->pool == APOOL_SHADOW && !has_achiev(a)) continue;+ grid[ngrid++] = (uint16_t)a;+ }+ sort_by_order(grid + start, ngrid - start, true);+ }+ grid_break[2] = ngrid;+ }+}++static void stat_line(int *y, const char *s, bool draw) {+ *y += gfx_para(&PS_TIP, PAD, *y, SCREEN_W - 2 * PAD, s, draw) + 2;+}+static void stat_title(int *y, const char *s, bool draw) {+ *y += 4;+ if (draw) {+ gfx_text_outline(F_KAVOON, PAD, *y + 14, s, WHITE, 256);+ tip_line(PAD, *y + 18, SCREEN_W - 2 * PAD);+ }+ *y += 22;+}++static int general(int y0, bool draw) {+ char a[64], b[64], c[64], l[300];+ int y = y0;+ stat_title(&y, "General", draw);+ beautify(S.cookies, 0, a);+ snprintf(l, sizeof l, "\x01" "Cookies in bank:\x02 %s", a), stat_line(&y, l, draw);+ beautify(S.cookies_earned, 0, a);+ snprintf(l, sizeof l, "\x01" "Cookies baked (this ascension):\x02 %s", a), stat_line(&y, l, draw);+ beautify(S.cookies_earned + S.cookies_reset, 0, a);+ snprintf(l, sizeof l, "\x01" "Cookies baked (all time):\x02 %s", a), stat_line(&y, l, draw);+ if (S.cookies_reset > 0) {+ beautify(S.cookies_reset, 0, a);+ snprintf(l, sizeof l, "\x01" "Cookies forfeited by ascending:\x02 %s", a), stat_line(&y, l, draw);+ }+ if (S.resets) {+ say_time((S.play_time - S.full_date) / 1000 * FPS, -1, a);+ snprintf(l, sizeof l, "\x01Legacy started:\x02 %s%s, with %u ascension%s", a[0] ? a : "just now", a[0] ? " ago" : "",+ S.resets, S.resets == 1 ? "" : "s");+ stat_line(&y, l, draw);+ }+ say_time((S.play_time - S.start_date) / 1000 * FPS, -1, a);+ snprintf(l, sizeof l, "\x01Run started:\x02 %s%s", a[0] ? a : "just now", a[0] ? " ago" : "");+ stat_line(&y, l, draw);+ snprintf(l, sizeof l, "\x01" "Buildings owned:\x02 %d", G.buildings_owned), stat_line(&y, l, draw);+ beautify(G.cookies_ps, 1, a);+ beautify(round(G.global_cps_mult * 100), 1, b);+ beautify(round(G.cps_sucked * 100), 1, c);+ snprintf(l, sizeof l, "\x01" "Cookies per second:\x02 %s (multiplier: %s%%)%s%s%s", a, b, G.cps_sucked > 0 ? " (withered: " : "",+ G.cps_sucked > 0 ? c : "", G.cps_sucked > 0 ? "%)" : "");+ stat_line(&y, l, draw);+ beautify(G.cookies_ps_raw, 1, a);+ beautify(S.cookies_ps_raw_highest, 1, b);+ snprintf(l, sizeof l, "\x01Raw cookies per second:\x02 %s (highest this ascension: %s)", a, b), stat_line(&y, l, draw);+ beautify(G.computed_mouse_cps, 1, a);+ snprintf(l, sizeof l, "\x01" "Cookies per click:\x02 %s", a), stat_line(&y, l, draw);+ beautify(S.cookie_clicks, 0, a);+ snprintf(l, sizeof l, "\x01" "Cookie clicks:\x02 %s", a), stat_line(&y, l, draw);+ beautify(S.handmade_cookies, 0, a);+ snprintf(l, sizeof l, "\x01Hand-made cookies:\x02 %s", a), stat_line(&y, l, draw);+ snprintf(l, sizeof l, "\x01Golden cookie clicks:\x02 %u (all time: %u)", S.golden_clicks_local, S.golden_clicks);+ stat_line(&y, l, draw);+ double drop = drop_rate_mult();+ if (drop != 1) {+ beautify(drop, 2, a);+ snprintf(l, sizeof l, "\x01Random drop multiplier:\x02 x%s", a), stat_line(&y, l, draw);+ }+ stat_line(&y, "\x01Running version:\x02 2.058", draw);++ /* special */+ static const char *const season_names[6] = {"", "Christmas", "Halloween", "Valentine's day", "Business day",+ "Easter"};+ const char *wrath = S.elder_wrath == 1 ? "awoken" : S.elder_wrath == 2 ? "displeased" : S.elder_wrath == 3 ? "angered"+ : S.pledges > 0 ? "appeased" : NULL;+ if (S.resets > 0 || S.season || S.research_t > 0 || wrath || S.pledge_t > 0 || can_lumps() || S.wrinklers_popped ||+ S.reindeer_clicked || has(U_A_FESTIVE_HAT) || has(U_A_CRUMBLY_EGG)) {+ stat_title(&y, "Special", draw);+ if (S.resets > 0) {+ snprintf(l, sizeof l, "\x01" "Challenge mode:\x02 %s", S.ascension_mode == 1 ? "Born again" : "None");+ stat_line(&y, l, draw);+ }+ if (S.season) {+ say_time(S.season_t, -1, a);+ int sn = S.season == SEASON_CHRISTMAS ? 1 : S.season == SEASON_HALLOWEEN ? 2 : S.season == SEASON_VALENTINES ? 3+ : S.season == SEASON_FOOLS ? 4 : 5;+ snprintf(l, sizeof l, "\x01Seasonal event:\x02 %s%s%s%s", season_names[sn], a[0] ? " (" : "", a,+ a[0] ? " remaining)" : "");+ stat_line(&y, l, draw);+ }+ if (S.research_t > 0) {+ say_time(S.research_t, -1, a);+ snprintf(l, sizeof l, "\x01Research:\x02 %s remaining", a), stat_line(&y, l, draw);+ }+ if (wrath) snprintf(l, sizeof l, "\x01Grandmatriarchs status:\x02 %s", wrath), stat_line(&y, l, draw);+ if (S.pledge_t > 0) {+ say_time(S.pledge_t, -1, a);+ snprintf(l, sizeof l, "\x01Pledge:\x02 %s remaining", a), stat_line(&y, l, draw);+ }+ if (S.wrinklers_popped) snprintf(l, sizeof l, "\x01Wrinklers popped:\x02 %u", S.wrinklers_popped), stat_line(&y, l, draw);+ if (can_lumps() && S.lumps_total > -1) {+ beautify(S.lumps_total, 0, a);+ snprintf(l, sizeof l, "\x01Sugar lumps harvested:\x02 %s", a), stat_line(&y, l, draw);+ }+ if (S.reindeer_clicked) snprintf(l, sizeof l, "\x01Reindeer found:\x02 %u", S.reindeer_clicked), stat_line(&y, l, draw);+ if (has(U_A_FESTIVE_HAT)) {+ snprintf(l, sizeof l, "\x01Santa stages unlocked:\x02 %d/15 (%s)", S.santa_level + 1, santa_levels[S.santa_level]);+ stat_line(&y, l, draw);+ }+ if (has(U_A_CRUMBLY_EGG)) snprintf(l, sizeof l, "\x01" "Dragon training:\x02 %s", dragon_name()), stat_line(&y, l, draw);+ }+ if (S.prestige > 0) {+ stat_title(&y, "Prestige", draw);+ double hm = heavenly_multiplier();+ beautify(S.prestige, 0, a);+ beautify(hm * 100, 1, b);+ beautify(S.prestige * hm, 1, c);+ if (draw) gfx_icon(ICON(19, 7), PAD, y, 256);+ snprintf(l, sizeof l, "\x01Prestige level: %s\x02 at %s%% of its potential \x01(+%s%% CpS)\x02", a, b, c);+ int h = gfx_para(&PS_TIP, PAD + 28, y, SCREEN_W - 2 * PAD - 28, l, draw);+ beautify(S.heavenly_chips, 0, a);+ snprintf(l, sizeof l, "Heavenly chips: \x01%s\x02", a);+ h += gfx_para(&PS_TIP, PAD + 28, y + h, SCREEN_W - 2 * PAD - 28, l, draw);+ y += (h > 26 ? h : 26) + 2;+ }+ return y - y0;+}++static int achiev_count(int *other) {+ int n = 0;+ *other = 0;+ for (int a = 0; a < N_ACHIEVS; a++)+ if (has_achiev(a)) {+ if (achiev_rec(a)->pool == APOOL_NORMAL) n++;+ else (*other)++;+ }+ return n;+}++static const ParaStyle PS_HEAD = {F_BODY, F_BOLD, F_ITALIC, 0xCE79, WHITE, WHITE, 12, 0};+static int grid_head(int tab, int y, bool draw) {+ char l[200];+ int h = 0;+ if (tab == TAB_UPGRADES) {+ int total = 0, owned = 0;+ for (int u = 0; u < N_UPGRADES; u++) {+ const UpgradeRec *r = upgrade_rec(u);+ if (r->pool == POOL_PRESTIGE || r->pool == POOL_DEBUG || r->pool == POOL_TOGGLE) continue;+ total++;+ if (bit_get(S.upgrades_bought, u)) owned++;+ }+ snprintf(l, sizeof l, "\x01Upgrades unlocked:\x02 %d/%d (%d%%)", owned, total, total ? owned * 100 / total : 0);+ } else {+ int other, n = achiev_count(&other), total = 0;+ for (int a = 0; a < N_ACHIEVS; a++) total += achiev_rec(a)->pool == APOOL_NORMAL;+ int rank = (int)floorf(G.milk_progress);+ if (rank > N_MILKS - 1) rank = N_MILKS - 1;+ char o[32] = "";+ if (other) snprintf(o, sizeof o, " (+%d)", other);+ snprintf(l, sizeof l, "\x01" "Achievements unlocked:\x02 %d/%d (%d%%)%s\n\x01Milk:\x02 %s", n, total,+ total ? n * 100 / total : 0, o, res_text(milk_rec(rank)->name));+ }+ h = gfx_para(&PS_HEAD, PAD, y, SCREEN_W - 2 * PAD, l, draw);+ return h + 4;+}++/* where crate i of the grid is (y in the tab's content) */+static int grid_top(void) { return 30; }+static void crate_pos(int tab, int i, int head, int *x, int *y) {+ int sec = 0;+ for (int k = 1; k < 3; k++)+ if (i >= grid_break[k] && grid_break[k] > grid_break[k - 1]) sec = k;+ /* each section starts on a new row, with a gap */+ int yy = grid_top() + head, row0 = 0;+ for (int k = 0; k < sec; k++) {+ int n = grid_break[k + 1] - grid_break[k];+ if (tab == TAB_ACHIEVS && k == 1) n = ngrid - grid_break[1];+ if (n > 0) yy += ((n + GRID_COLS - 1) / GRID_COLS) * CRATE + 14;+ }+ row0 = grid_break[sec];+ int j = i - row0;+ *x = GRID_X + (j % GRID_COLS) * CRATE;+ *y = yy + 12 + (j / GRID_COLS) * CRATE;+}++static void draw_grid(int tab) {+ int head = grid_head(tab, 0, false);+ int y0 = PANEL_Y - U.list_top;+ grid_head(tab, y0 + grid_top(), true);+ static const char *const up_secs[3] = {"Prestige", "Upgrades", "Cookies"};+ int last_sec = -1;+ for (int i = 0; i < ngrid; i++) {+ int x, y;+ crate_pos(tab, i, head, &x, &y);+ int sec = 0;+ for (int k = 1; k < 3; k++)+ if (i >= grid_break[k]) sec = k;+ if (sec != last_sec) {+ last_sec = sec;+ const char *t = tab == TAB_UPGRADES ? up_secs[sec] : sec == 1 ? "Shadow achievements" : NULL;+ if (t && gfx_visible(0, y0 + y - 13, SCREEN_W, 13))+ gfx_text_outline(F_BOLD, GRID_X, y0 + y - 3, t, WHITE, 256);+ }+ if (!gfx_visible(x, y0 + y, CRATE, CRATE)) continue;+ bool sel = U.list_sel == i;+ if (tab == TAB_UPGRADES) {+ const UpgradeRec *r = upgrade_rec(grid[i]);+ draw_crate(r->icon, x, y0 + y, sel ? 1 : 0, false);+ } else {+ int a = grid[i];+ bool won = has_achiev(a);+ draw_crate(won ? achiev_rec(a)->icon : ICON(0, 7), x, y0 + y, sel ? 1 : won ? 0 : 2, false);+ }+ }+}++static void draw_stats(void) {+ panel(NULL);+ /* the tabs */+ int x = PAD;+ for (int t = 0; t < N_TABS; t++) {+ int w = gfx_text_width(F_NAME, tab_names[t]) + 12;+ bool on = U.stats_tab == t;+ gfx_round_rect(x, PANEL_Y + 6, w, 16, 3, on ? RGB(255, 255, 255) : BLACK, on ? 50 : 100);+ gfx_text_outline(F_NAME, x + 6, PANEL_Y + 18, tab_names[t], on ? WHITE : RGB(150, 150, 150), 256);+ x += w + 4;+ }+ gfx_text_right(F_SMALL, SCREEN_W - PAD, PANEL_Y + 17, "< >", RGB(150, 150, 150), 256);+ gfx_clip(0, PANEL_Y + 26, SCREEN_W, PANEL_H - 26);+ if (U.stats_tab == TAB_GENERAL) general(PANEL_Y + 26 - U.list_top, true);+ else {+ grid_build(U.stats_tab);+ draw_grid(U.stats_tab);+ }+ gfx_unclip();+ /* the tooltip of the crate chosen */+ if (U.stats_tab != TAB_GENERAL && ngrid > 0 && U.list_sel < ngrid) {+ int w = 220, pad = 5, type = U.stats_tab == TAB_UPGRADES ? 0 : 1;+ int h = crate_tip(type, grid[U.list_sel], CTX_STATS, 0, 0, w - 2 * pad, false) + 2 * pad;+ int head = grid_head(U.stats_tab, 0, false), cx, cy;+ crate_pos(U.stats_tab, U.list_sel, head, &cx, &cy);+ cy += PANEL_Y - U.list_top;+ int ty = cy + CRATE + 2;+ if (ty + h > SCREEN_H - 2) ty = cy - h - 2;+ if (ty < NEWS_H + 2) ty = NEWS_H + 2;+ int tx = cx + CRATE / 2 - w / 2;+ if (tx < 2) tx = 2;+ if (tx + w > SCREEN_W - 2) tx = SCREEN_W - 2 - w;+ if (gfx_visible(tx, ty, w, h)) {+ draw_frame_box(tx, ty, w, h);+ crate_tip(type, grid[U.list_sel], CTX_STATS, tx + pad, ty + pad, w - 2 * pad, true);+ }+ }+}++static void stats_keys(uint32_t p) {+ if (p & (K_LEFT | K_RIGHT) && (U.stats_tab == TAB_GENERAL || p & K_SHIFT)) {+ U.stats_tab = (U.stats_tab + (p & K_LEFT ? N_TABS - 1 : 1)) % N_TABS;+ U.list_sel = 0, U.list_top = 0;+ return;+ }+ if (U.stats_tab == TAB_GENERAL) {+ int h = general(0, false) + 30, view = PANEL_H - 26;+ if (p & K_DOWN) U.list_top += 24;+ if (p & K_UP) U.list_top -= 24;+ if (U.list_top > h - view) U.list_top = h - view;+ if (U.list_top < 0) U.list_top = 0;+ return;+ }+ grid_build(U.stats_tab);+ if (!ngrid) {+ if (p & (K_LEFT | K_RIGHT)) U.stats_tab = (U.stats_tab + (p & K_LEFT ? N_TABS - 1 : 1)) % N_TABS, U.list_sel = 0;+ return;+ }+ int i = U.list_sel;+ int head = grid_head(U.stats_tab, 0, false), x, y;+ crate_pos(U.stats_tab, i, head, &x, &y);+ if (p & K_LEFT) {+ if (i > 0) i--;+ else U.stats_tab = (U.stats_tab + N_TABS - 1) % N_TABS, U.list_sel = 0, U.list_top = 0;+ }+ if (p & K_RIGHT) {+ if (i < ngrid - 1) i++;+ else U.stats_tab = (U.stats_tab + 1) % N_TABS, U.list_sel = 0, U.list_top = 0;+ }+ if (U.list_sel != 0 || i != 0 || !(p & (K_LEFT | K_RIGHT))) {+ if (p & (K_UP | K_DOWN)) {+ /* the crate above or below: the nearest in x */+ int best = -1, bd = 1 << 30;+ for (int k = 0; k < ngrid; k++) {+ int kx, ky;+ crate_pos(U.stats_tab, k, head, &kx, &ky);+ if (p & K_UP ? ky >= y : ky <= y) continue;+ int d = abs(ky - y) * 4 + abs(kx - x);+ if (d < bd) bd = d, best = k;+ }+ if (best >= 0) i = best;+ }+ U.list_sel = i;+ }+ crate_pos(U.stats_tab, U.list_sel, head, &x, &y);+ int view = PANEL_H;+ if (y - U.list_top < 30) U.list_top = y - 30;+ if (y + CRATE - U.list_top > view - 4) U.list_top = y + CRATE - view + 4;+ if (U.list_sel < GRID_COLS) U.list_top = 0;+ if (U.list_top < 0) U.list_top = 0;+}++/* ------------------------------------------------------------------ info, keys */+static const char info_text[] =+ "\x01" "Cookie Clicker\x02 by Orteil and Opti (DashNet), version 2.058, on the NumWorks calculator. Its pictures, "+ "texts and numbers are the game's own (from its public mirror), as are its rules; the fonts are Merriweather, "+ "Kavoon and Noto Sans (SIL Open Font License). Not affiliated with DashNet.\x05"+ "\x01What's different here:\x02 the game counts its time while it runs (the calculator has no clock), so it "+ "doesn't bake while closed, and sugar lumps grow 24 times faster to make up for it. There is no sound. The "+ "golden cookies come to the left column.\x05"+ "Made by Mason Chen as part of NumPlay.";++static const char keys_text[] =+ "\x01OK\x02 click the big cookie\n"+ "\x01" "Arrows\x02 choose in the store\n"+ "\x01" "EXE\x02 buy (or sell) what is chosen\n"+ "\x01" "÷\x02 buy / sell \x01" "×\x02 1, 10, 100 (all)\n"+ "\x01shift\x02 click a golden cookie (or a reindeer)\n"+ "\x01var\x02 pop a wrinkler \x01x,n,t\x02 harvest the sugar lump\n"+ "\x01" "alpha\x02 the buildings and their minigames\n"+ "\x01toolbox\x02 statistics \x01" "delete\x02 close a note\n"+ "\x01" "Back\x02 the menu \x01Home\x02 save and quit";++static void text_page(const char *title, const char *s) {+ panel(title);+ char buf[1400];+ extern void text_beautify(const char *src, char *dst, int size);+ /* (× and ÷ as the fonts have them) */+ int o = 0;+ for (const unsigned char *c = (const unsigned char *)s; *c && o < (int)sizeof buf - 1; c++) {+ if (c[0] == 0xC3 && c[1] == 0x97) buf[o++] = (char)(0x80 + 18), c++;+ else if (c[0] == 0xC3 && c[1] == 0xB7) buf[o++] = (char)(0x80 + 19), c++;+ else buf[o++] = (char)*c;+ }+ buf[o] = 0;+ gfx_clip(0, PANEL_Y + 26, SCREEN_W, PANEL_H - 28);+ gfx_para(&PS_TIP, PAD + 4, PANEL_Y + 32 - U.list_top, SCREEN_W - 2 * PAD - 8, buf, true);+ gfx_unclip();+}++/* ------------------------------------------------------------------ Santa, the dragon */+static void draw_special(void) {+ int w = 236, x = (SCREEN_W - w) / 2, pad = 8;+ char l[400], a[200], c[64];+ int h;+ gfx_fill_alpha(0, PANEL_Y, SCREEN_W, PANEL_H, BLACK, 110);+ if (U.special == 0) {+ double cost = pow(S.santa_level + 1, S.santa_level + 1);+ beautify(cost, 0, a);+ bool can = S.cookies > cost && S.santa_level < 14;+ h = 150;+ int y = PANEL_Y + (PANEL_H - h) / 2;+ draw_frame_box(x, y, w, h);+ gfx_image(IM_SANTA0 + S.santa_level, x + w / 2 - 24, y + 8, 256);+ gfx_text_outline_center(F_TITLE, SCREEN_W / 2, y + 72, santa_levels[S.santa_level], WHITE, 256);+ tip_line(x + pad, y + 78, w - 2 * pad);+ if (S.santa_level < 14) {+ snprintf(l, sizeof l, "Evolve\n\x01" "cost:\x02 %s cookie%s", a, cost == 1 ? "" : "s");+ ParaStyle st = PS_TIP;+ st.align = 1;+ gfx_para(&st, x + pad, y + 84, w - 2 * pad, l, true);+ button(x + w / 2 - 50, y + h - 26, 100, "Evolve", U.list_sel == 0, can);+ } else {+ ParaStyle st = PS_TIP;+ st.align = 1;+ gfx_para(&st, x + pad, y + 86, w - 2 * pad, "Santa is fully grown!", true);+ }+ return;+ }+ /* the dragon */+ bool can;+ dragon_action(a, sizeof a, c, sizeof c, &can);+ int y = PANEL_Y + 6;+ h = PANEL_H - 12;+ draw_frame_box(x, y, w, h);+ float bob = sinf(G.real_t * 0.1f) * 2;+ gfx_image(IM_DRAGON0 + dragon_frame(), x + w / 2 - 24, y + 4 + (int)bob, 256);+ gfx_text_outline_center(F_TITLE, SCREEN_W / 2, y + 64, dragon_name(), WHITE, 256);+ tip_line(x + pad, y + 70, w - 2 * pad);+ ParaStyle st = PS_SMALL;+ st.align = 1;+ int yy = y + 74;+ if (c[0]) snprintf(l, sizeof l, "%s\n\x01" "Cost:\x02 %s", a, c);+ else snprintf(l, sizeof l, "%s", a);+ yy += gfx_para(&st, x + pad, yy, w - 2 * pad, l, true) + 4;+ int sel = 0;+ if (S.dragon_level < 27) button(x + w / 2 - 50, yy, 100, "Train", U.list_sel == sel, can), yy += 19;+ sel++;+ if (S.dragon_level >= 5) {+ for (int slot = 0; slot < (S.dragon_level >= 27 ? 2 : 1); slot++) {+ int aura = slot ? S.dragon_aura2 : S.dragon_aura;+ snprintf(l, sizeof l, "%s: %s", slot ? "Secondary aura" : "Dragon aura", aura_names[aura]);+ gfx_icon(aura_icons[aura], x + pad, yy - 4, 256);+ button(x + pad + 28, yy, w - 2 * pad - 28, l, U.list_sel == sel, true);+ yy += 23, sel++;+ }+ }+ if (S.dragon_level >= 4 && has(U_PET_THE_DRAGON)) button(x + w / 2 - 50, yy, 100, "Pet", U.list_sel == sel, true);+}++static int special_items(void) {+ if (U.special == 0) return 1;+ return 1 + (S.dragon_level >= 5 ? (S.dragon_level >= 27 ? 2 : 1) : 0) + (S.dragon_level >= 4 && has(U_PET_THE_DRAGON));+}++static void special_keys(uint32_t p) {+ int n = special_items();+ if (p & K_UP && U.list_sel > 0) U.list_sel--;+ if (p & K_DOWN && U.list_sel < n - 1) U.list_sel++;+ if (!(p & (K_OK | K_EXE))) return;+ if (U.special == 0) {+ upgrade_santa();+ return;+ }+ int auras = S.dragon_level >= 5 ? (S.dragon_level >= 27 ? 2 : 1) : 0;+ if (U.list_sel == 0) upgrade_dragon();+ else if (U.list_sel <= auras) {+ U.aura_slot = U.list_sel - 1;+ U.aura_sel = U.aura_slot ? S.dragon_aura2 : S.dragon_aura;+ U.overlay = OV_AURA;+ } else+ pet_dragon();+}++/* choosing an aura: those the dragon knows (one per level from 5) */+static int auras_known(void) {+ int n = S.dragon_level - 4;+ if (n > N_AURAS - 1) n = N_AURAS - 1;+ return n < 0 ? 0 : n;+}+static void draw_aura(void) {+ int n = auras_known() + 1;+ int w = 300, x = (SCREEN_W - w) / 2, pad = 8;+ int cols = 11, rows = (n + cols - 1) / cols;+ int h = 28 + rows * 26 + 74;+ int y = PANEL_Y + (PANEL_H - h) / 2;+ gfx_fill_alpha(0, PANEL_Y, SCREEN_W, PANEL_H, BLACK, 110);+ draw_frame_box(x, y, w, h);+ gfx_text_outline_center(F_TITLE, SCREEN_W / 2, y + 17, U.aura_slot ? "Set your secondary aura" : "Set your dragon's aura",+ WHITE, 256);+ for (int i = 0; i < n; i++) {+ int cx = x + pad + (i % cols) * 26, cy = y + 24 + (i / cols) * 26;+ gfx_icon(aura_icons[i], cx, cy, (U.aura_slot ? S.dragon_aura == i : S.dragon_aura2 == i) && i ? 90 : 256);+ if (U.aura_sel == i) gfx_rect(cx - 1, cy - 1, 26, 26, WHITE, 256);+ }+ int yy = y + 28 + rows * 26;+ tip_line(x + pad, yy - 2, w - 2 * pad);+ gfx_text_outline_center(F_NAME, SCREEN_W / 2, yy + 10, aura_names[U.aura_sel], WHITE, 256);+ ParaStyle st = PS_SMALL;+ st.align = 1;+ char l[400];+ int highest = -1;+ for (int b = 0; b < NB; b++)+ if (S.buildings[b].amount > 0) highest = b;+ snprintf(l, sizeof l, "%s\n%s", aura_descs[U.aura_sel],+ highest >= 0 ? "Switching auras costs \x01one of your most expensive buildings\x02." : "");+ for (char *c = l; *c; c++)+ if (*c == '\n' && !c[1]) *c = 0;+ if (highest >= 0) {+ char t[96];+ snprintf(t, sizeof t, " (%s)", res_text(building_rec(highest)->single));+ strncat(l, t, sizeof l - strlen(l) - 1);+ }+ gfx_para(&st, x + pad, yy + 14, w - 2 * pad, l, true);+}+static void aura_keys(uint32_t p) {+ int n = auras_known() + 1;+ if (p & K_LEFT && U.aura_sel > 0) U.aura_sel--;+ if (p & K_RIGHT && U.aura_sel < n - 1) U.aura_sel++;+ if (p & K_UP && U.aura_sel >= 11) U.aura_sel -= 11;+ if (p & K_DOWN && U.aura_sel + 11 < n) U.aura_sel += 11;+ if (p & (K_OK | K_EXE)) {+ int other = U.aura_slot ? S.dragon_aura : S.dragon_aura2;+ if (U.aura_sel == 0 || U.aura_sel != other) set_dragon_aura(U.aura_slot, U.aura_sel);+ U.overlay = OV_SPECIAL;+ }+}++/* ------------------------------------------------------------------ dispatch */+void draw_overlay(void) {+ switch (U.overlay) {+ case OV_MENU: draw_menu(); break;+ case OV_OPTIONS: draw_options(); break;+ case OV_STATS: draw_stats(); break;+ case OV_INFO: text_page("Info", info_text); break;+ case OV_KEYS: text_page("Keys", keys_text); break;+ case OV_SPECIAL: draw_special(); break;+ case OV_AURA: draw_aura(); break;+ case OV_ROWMENU: {+ extern void draw_row_menu(void);+ draw_row_menu();+ break;+ }+ default: break;+ }+}++void menus_keys(uint32_t p) {+ if (p & K_BACK) {+ switch (U.overlay) {+ case OV_KEYS: S.seen_keys = 1, U.overlay = U.from_menu ? OV_MENU : OV_NONE; break;+ case OV_AURA: U.overlay = OV_SPECIAL; break;+ case OV_MENU: case OV_ROWMENU: U.overlay = OV_NONE; break;+ default: U.overlay = U.from_menu ? OV_MENU : OV_NONE;+ }+ return;+ }+ switch (U.overlay) {+ case OV_MENU:+ menu_build();+ if (p & K_UP) U.menu_sel = (U.menu_sel + nmenu - 1) % nmenu;+ if (p & K_DOWN) U.menu_sel = (U.menu_sel + 1) % nmenu;+ if (U.menu_sel >= nmenu) U.menu_sel = nmenu - 1;+ if (p & (K_OK | K_EXE)) U.from_menu = true, menu_choose(menu_items[U.menu_sel]);+ break;+ case OV_OPTIONS: options_keys(p); break;+ case OV_STATS: stats_keys(p); break;+ case OV_INFO:+ case OV_KEYS:+ if (p & K_DOWN) U.list_top += 24;+ if (p & K_UP) U.list_top -= 24;+ if (U.list_top < 0) U.list_top = 0;+ if (U.list_top > 120) U.list_top = 120;+ if (p & (K_OK | K_EXE) && U.overlay == OV_KEYS && !S.seen_keys) S.seen_keys = 1, U.overlay = OV_NONE;+ break;+ case OV_SPECIAL: special_keys(p); break;+ case OV_AURA: aura_keys(p); break;+ case OV_ROWMENU: {+ extern void row_menu_keys(uint32_t p);+ row_menu_keys(p);+ break;+ }+ default: U.overlay = OV_NONE;+ }+}diff --git a/games/cookieclicker/src/minigames.c b/games/cookieclicker/src/minigames.cnew file mode 100644index 00000000..59611e2d--- /dev/null+++ b/games/cookieclicker/src/minigames.c@@ -0,0 +1,72 @@+/* The minigames' shared parts: their effects on the rest of the game (Game.effs), their frames,+ * their resets; and the hooks the rest of the game calls. */+#include <math.h>+#include <string.h>+#include "game.h"++/* effects the wrinklers read: 1 how much they eat, 2 how often they come */+static float wrinkler_effs[3] = {1, 1, 1};+float minigame_eff(int which) { return wrinkler_effs[which]; }++void minigame_effs(void) {+ for (int i = 0; i < 16; i++) G.effs[i] = 1;+ wrinkler_effs[1] = wrinkler_effs[2] = 1;+ extern void garden_effs(float *effs, float *wrinkler);+ garden_effs(G.effs, wrinkler_effs);+}++void minigames_logic(void) {+ if (S.ascension_mode == 1) return;+ extern void grimoire_logic(void);+ extern void pantheon_logic(void);+ extern void garden_logic(void);+ if (S.buildings[B_WIZARD_TOWER].level > 0) grimoire_logic();+ if (S.buildings[B_TEMPLE].level > 0) pantheon_logic();+ if (S.buildings[B_FARM].level > 0) garden_logic();+}++void reset_minigames(bool hard) {+ extern void grimoire_reset(bool hard);+ extern void pantheon_reset(bool hard);+ extern void garden_reset(bool hard);+ grimoire_reset(hard);+ pantheon_reset(hard);+ garden_reset(hard);+}++void building_levelled(int b) {+ extern void grimoire_on_level(void);+ if (b == B_WIZARD_TOWER) grimoire_on_level();+}++void buff_died(Buff *b) { (void)b; }++/* the cookies the garden's plants drop: their price scales with production (that many minutes of it) */+double garden_drop_price(int u, double price) {+ static const uint16_t drops[] = {U_ELDERWORT_BISCUITS, U_BAKEBERRY_COOKIES, U_DUKETATER_COOKIES,+ U_GREEN_YEAST_DIGESTIVES, U_FERN_TEA, U_ICHOR_SYRUP, U_WHEAT_SLIMS};+ for (unsigned i = 0; i < sizeof drops / sizeof drops[0]; i++)+ if (drops[i] == u) return price * G.cookies_ps * 60;+ return price;+}++/* ------------------------------------------------------------------ their panels */+extern void grimoire_draw(void);+extern void grimoire_keys(uint32_t pressed);+extern int grimoire_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; }+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();+}+void minigame_keys(int b, uint32_t pressed) {+ if (b == B_WIZARD_TOWER) grimoire_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);+ return 0;+}diff --git a/games/cookieclicker/src/news.c b/games/cookieclicker/src/news.cnew file mode 100644index 00000000..fe2106c8--- /dev/null+++ b/games/cookieclicker/src/news.c@@ -0,0 +1,40 @@+/* 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. */+#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"},+};++uint32_t ticker_n;+void news_next(char *out, int size) {+ ticker_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]);+}diff --git a/games/cookieclicker/src/numbers.c b/games/cookieclicker/src/numbers.cnew file mode 100644index 00000000..eecd5513--- /dev/null+++ b/games/cookieclicker/src/numbers.c@@ -0,0 +1,149 @@+/* Numbers as the game writes them (its Beautify, formatEveryThirdPower, sayTime): 123,456, then+ * 1.234 million ... up to the novemnonagintillions; with short numbers off, every digit with commas. */+#include <math.h>+#include <string.h>+#include "game.h"++static const char *const small_names[10] = {" thousand", " million", " billion", " trillion", " quadrillion",+ " quintillion", " sextillion", " septillion", " octillion", " nonillion"};+static const char *const prefixes[10] = {"", "un", "duo", "tre", "quattuor", "quin", "sex", "septen", "octo", "novem"};+static const char *const suffixes[9] = {"decillion", "vigintillion", "trigintillion", "quadragintillion",+ "quinquagintillion", "sexagintillion", "septuagintillion", "octogintillion",+ "nonagintillion"};++static char *cpy(char *o, const char *s) {+ while ((*o = *s++)) o++;+ return o;+}+static char *notation(char *o, int base) {+ if (base < 10) return cpy(o, small_names[base]);+ base -= 10;+ *o++ = ' ';+ return cpy(cpy(o, prefixes[base % 10]), suffixes[base / 10]);+}+/* an integer below 2^53 with commas */+static char *integer(char *o, double v, bool commas) {+ char t[40];+ int n = 0, digits = 0;+ v = floor(v + 0.5);+ do {+ if (commas && digits && digits % 3 == 0) t[n++] = ',';+ double q = floor(v / 10);+ t[n++] = (char)('0' + (int)(v - q * 10));+ v = q, digits++;+ } while (v >= 1 && n < 38);+ while (n) *o++ = t[--n];+ *o = 0;+ return o;+}+/* JavaScript's Math.round(v * 1000) / 1000, written as it writes numbers */+static char *round3(char *o, double v) {+ double r = floor(v * 1000 + 0.5);+ double ip = floor(r / 1000);+ int frac = (int)(r - ip * 1000);+ o = integer(o, ip, false);+ if (frac) {+ *o++ = '.';+ int d = 100;+ while (frac) *o++ = (char)('0' + frac / d), frac %= d, d /= 10;+ *o = 0;+ }+ return o;+}++void beautify(double val, int floats, char *out) {+ char *o = out;+ bool negative = val < 0;+ double a = fabs(val);+ char decimal[8] = "";+ if (isinf(a) || isnan(a)) {+ strcpy(out, "Infinity");+ return;+ }+ if (floats > 0) {+ double p = pow(10, floats);+ double fixed = floor(a * p + 0.5) / p;+ if (a < 1000 && floor(fixed) != fixed) {+ int f = (int)floor((fixed - floor(fixed)) * p + 0.5);+ decimal[0] = '.';+ for (int i = floats - 1; i >= 0; i--) decimal[1 + i] = (char)('0' + f % 10), f /= 10;+ decimal[1 + floats] = 0;+ }+ double fl = floor(a);+ if (fixed == fl + 1) a = fl + 1;+ else a = fl;+ } else+ a = floor(a);+ if (a == 0) negative = false;+ if (negative) *o++ = '-';+ if (S.prefs.format_long) { /* short numbers off */+ if (a >= 1e21) {+ int e = (int)floor(log10(a));+ double m = a / pow(10, e);+ if (m >= 9.995) m /= 10, e++;+ int c = (int)floor(m * 100 + 0.5);+ *o++ = (char)('0' + c / 100), *o++ = '.', *o++ = (char)('0' + c / 10 % 10), *o++ = (char)('0' + c % 10);+ *o++ = 'e', *o++ = '+';+ o = integer(o, e, false);+ } else+ o = integer(o, a, true);+ } else if (a >= 1000000) {+ double v = a / 1000;+ int base = 0;+ while (floor(v + 0.5) >= 1000) v /= 1000, base++;+ if (base >= 100) {+ strcpy(out, negative ? "-Infinity" : "Infinity");+ return;+ }+ o = notation(round3(o, v), base);+ } else+ o = integer(o, a, true);+ strcpy(o, decimal);+}++void cookies_str(double v, int floats, char *out) {+ beautify(v, floats, out);+ bool one = floats > 0 ? fabs(v - 1) < 1e-9 : floor(fabs(v)) == 1;+ strcat(out, one ? " cookie" : " cookies");+}++static char *unit(char *o, long n, const char *name) {+ char t[32];+ beautify((double)n, 0, t);+ o = cpy(cpy(o, t), " ");+ o = cpy(o, name);+ if (n != 1) *o++ = 's', *o = 0;+ return o;+}++void say_time(double time, int detail, char *out) {+ out[0] = 0;+ if (time <= 0) return;+ long t = (long)floor(time);+ const long D = (long)FPS * 60 * 60 * 24, H = (long)FPS * 60 * 60, M = (long)FPS * 60;+ char *o = out;+ if (detail == -1) {+ long days = t >= D ? t / D : 0, hours = t >= H ? t / H : 0, minutes = t >= M ? t / M : 0;+ long seconds = t >= FPS ? t / FPS : 0;+ hours -= days * 24;+ minutes -= hours * 60 + days * 24 * 60;+ seconds -= minutes * 60 + hours * 60 * 60 + days * 24 * 60 * 60;+ if (days > 10) hours = 0;+ if (days) minutes = 0, seconds = 0;+ if (hours) seconds = 0;+ const long v[4] = {days, hours, minutes, seconds};+ static const char *const names[4] = {"day", "hour", "minute", "second"};+ for (int i = 0; i < 4; i++) {+ if (v[i] <= 0) continue;+ if (o != out) o = cpy(o, ", ");+ o = unit(o, v[i], names[i]);+ }+ if (o == out) strcpy(out, "less than 1 second");+ return;+ }+ if (t >= D && detail < 2) unit(o, t / D, "day");+ else if (t >= H && detail < 3) unit(o, t / H, "hour");+ else if (t >= M && detail < 4) unit(o, t / M, "minute");+ else if (t >= FPS && detail < 5) unit(o, t / FPS, "second");+ else strcpy(out, "less than 1 second");+}diff --git a/games/cookieclicker/src/pantheon.c b/games/cookieclicker/src/pantheon.cnew file mode 100644index 00000000..a3fbbe7b--- /dev/null+++ b/games/cookieclicker/src/pantheon.c@@ -0,0 +1,25 @@+/* The Pantheon (the temple's minigame): three slots, diamond, ruby and jade, for eleven spirits. */+#include <math.h>+#include <string.h>+#include "game.h"++void pantheon_logic(void) {+ if (S.swap_t > 0) S.swap_t--;+}+void pantheon_reset(bool hard) {+ if (hard) memset(S.gods, 0, sizeof S.gods), S.swaps = 3, S.swap_t = 0;+}+/* Holobore leaves its slot when a golden cookie is clicked */+bool force_unslot_god(int god) {+ for (int i = 0; i < 3; i++)+ if (S.gods[i] == god + 1 && hasgod(god)) {+ S.gods[i] = 0;+ G.recalculate = true;+ return true;+ }+ return false;+}+void use_swap(int32_t t) {+ if (S.swaps > 0) S.swaps--;+ S.swap_t = t;+}diff --git a/games/cookieclicker/src/plat.h b/games/cookieclicker/src/plat.hnew file mode 100644index 00000000..1b7a4c29--- /dev/null+++ b/games/cookieclicker/src/plat.h@@ -0,0 +1,51 @@+/* Cookie Clicker: the platform (the calculator, or a computer for tests).+ *+ * plat_eadk.c: the calculator's EADK display, keyboard, time and files.+ * plat_host.c: a frame buffer that tests save as images, scripted keys and+ * simulated time (tests/play.c). */+#ifndef CC_PLAT_H+#define CC_PLAT_H+#include <stdbool.h>+#include <stddef.h>+#include <stdint.h>++#define SCREEN_W 320+#define SCREEN_H 240++/* keys held now, as bits */+enum {+ K_LEFT = 1 << 0, K_RIGHT = 1 << 1, K_UP = 1 << 2, K_DOWN = 1 << 3,+ K_OK = 1 << 4, /* OK: click the big cookie, or choose */+ K_EXE = 1 << 5, /* EXE: buy (or sell) what is chosen in the store */+ K_BACK = 1 << 6, /* Back: the menu, or back */+ K_SHIFT = 1 << 7, /* shift: click the golden cookie (or another shimmer) */+ K_HOME = 1 << 8, /* Home, On/Off: save and quit */+ K_ALPHA = 1 << 9, /* alpha: the buildings' rows, and their minigames */+ K_MUL = 1 << 10, /* x: buy 1, 10 or 100 at a time */+ K_DIV = 1 << 11, /* the division key: buy or sell */+ K_TOOLBOX = 1 << 12, /* the toolbox key: the statistics */+ K_VAR = 1 << 13, /* var: pop the wrinklers */+ K_DEL = 1 << 14, /* the delete key: close the notes */+ K_D1 = 1 << 15, /* the digits 1 to 9, then 0: K_D1 << (n - 1), 0 is the tenth */+ K_XNT = 1 << 25, /* x,n,t: harvest the sugar lump */+ K_ANY = 1u << 31+};+#define K_DIGIT(n) (K_D1 << ((n) - 1))+#define K_DIGITS (0x3FF * K_D1)+uint32_t plat_keys(void);+uint32_t plat_millis(void);+void plat_sleep(uint32_t ms);+void plat_push(int x, int y, int w, int h, const uint16_t *px);+bool plat_save(const char *name, const void *data, uint32_t len);+const uint8_t *plat_load(const char *name, uint32_t *len); /* NULL if absent */+/* a file of len bytes to write in place (the calculator's storage is RAM): plat_reserve gives its+ * bytes, plat_reserved says they are written; NULL if there is no room */+uint8_t *plat_reserve(const char *name, uint32_t len);+void plat_reserved(const char *name, uint32_t len);+bool plat_remove(const char *name);+uint32_t plat_random(void);+void plat_begin(void);+int plat_end(void);+/* an N0110 or N0115 (216 MHz, the N0120 has 550) */+bool plat_slow(void);+#endifdiff --git a/games/cookieclicker/src/plat_eadk.c b/games/cookieclicker/src/plat_eadk.cnew file mode 100644index 00000000..7b7fdb07--- /dev/null+++ b/games/cookieclicker/src/plat_eadk.c@@ -0,0 +1,52 @@+/* The calculator: EADK display, keyboard, time and files. */+#include <eadk.h>+#include "../../common/epsilon_app.h"+#include "../../common/epsilon_files.h"+#include "plat.h"++#define KEY(k) ((uint64_t)1 << (k))++uint32_t plat_keys(void) {+ static const uint8_t digits[10] = {eadk_key_one, eadk_key_two, eadk_key_three, eadk_key_four, eadk_key_five,+ eadk_key_six, eadk_key_seven, eadk_key_eight, eadk_key_nine, eadk_key_zero};+ uint64_t k = eadk_keyboard_scan();+ uint32_t r = 0;+ if (k & KEY(eadk_key_left)) r |= K_LEFT;+ if (k & KEY(eadk_key_right)) r |= K_RIGHT;+ if (k & KEY(eadk_key_up)) r |= K_UP;+ if (k & KEY(eadk_key_down)) r |= K_DOWN;+ if (k & KEY(eadk_key_ok)) r |= K_OK;+ if (k & KEY(eadk_key_exe)) r |= K_EXE;+ if (k & KEY(eadk_key_back)) r |= K_BACK;+ if (k & KEY(eadk_key_shift)) r |= K_SHIFT;+ if (k & (KEY(eadk_key_home) | KEY(eadk_key_on_off))) r |= K_HOME;+ if (k & KEY(eadk_key_alpha)) r |= K_ALPHA;+ if (k & KEY(eadk_key_multiplication)) r |= K_MUL;+ if (k & KEY(eadk_key_division)) r |= K_DIV;+ if (k & KEY(eadk_key_toolbox)) r |= K_TOOLBOX;+ if (k & KEY(eadk_key_var)) r |= K_VAR;+ if (k & KEY(eadk_key_backspace)) r |= K_DEL;+ if (k & KEY(eadk_key_xnt)) r |= K_XNT;+ for (int i = 0; i < 10; i++)+ if (k & KEY(digits[i])) r |= K_D1 << i;+ if (k) r |= K_ANY;+ return r;+}++uint32_t plat_millis(void) { return (uint32_t)eadk_timing_millis(); }+void plat_sleep(uint32_t ms) { eadk_timing_msleep(ms); }+void plat_push(int x, int y, int w, int h, const uint16_t *px) {+ eadk_display_push_rect((eadk_rect_t){(uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h}, px);+}+bool plat_save(const char *name, const void *data, uint32_t len) { return ef_write(name, data, len); }+const uint8_t *plat_load(const char *name, uint32_t *len) { return ef_read(name, len); }+uint8_t *plat_reserve(const char *name, uint32_t len) {+ uint32_t n;+ return ef_write(name, NULL, len) ? (uint8_t *)(uintptr_t)ef_read(name, &n) : NULL; /* (the storage is RAM) */+}+void plat_reserved(const char *name, uint32_t len) { (void)name, (void)len; }+bool plat_remove(const char *name) { return ef_remove(name); }+uint32_t plat_random(void) { return eadk_random(); }+void plat_begin(void) { np_app_begin(); }+int plat_end(void) { return np_app_end(); }+bool plat_slow(void) { return epsilon_slow_model(); }diff --git a/games/cookieclicker/src/plat_host.c b/games/cookieclicker/src/plat_host.cnew file mode 100644index 00000000..948c2aa2--- /dev/null+++ b/games/cookieclicker/src/plat_host.c@@ -0,0 +1,76 @@+/* A computer: the screen goes to a frame buffer that tests save as images,+ * keys come from a script, time is simulated. */+#include <stdio.h>+#include <stdlib.h>+#include "plat.h"++uint16_t host_fb[SCREEN_W * SCREEN_H];+uint32_t host_time; /* ms */+uint32_t host_keys;+uint32_t host_seed = 12345;++uint32_t plat_keys(void) { return host_keys; }+uint32_t plat_millis(void) { return host_time; }+void plat_sleep(uint32_t ms) { host_time += ms; }+void plat_push(int x, int y, int w, int h, const uint16_t *px) {+ for (int r = 0; r < h; r++)+ for (int c = 0; c < w; c++)+ if ((unsigned)(x + c) < SCREEN_W && (unsigned)(y + r) < SCREEN_H) host_fb[(y + r) * SCREEN_W + x + c] = px[r * w + c];+}++static char save_dir[256] = "build/host-saves";+void host_save_dir(const char *d) { snprintf(save_dir, sizeof save_dir, "%s", d); }+bool plat_save(const char *name, const void *data, uint32_t len) {+ char p[512];+ snprintf(p, sizeof p, "%s/%s", save_dir, name);+ FILE *f = fopen(p, "wb");+ if (!f) return false;+ bool ok = fwrite(data, 1, len, f) == len;+ fclose(f);+ return ok;+}+/* (each file read gets its own buffer: callers may hold two at once) */+static uint8_t loaded[4][1 << 16];+static int next_load;+const uint8_t *plat_load(const char *name, uint32_t *len) {+ char p[512];+ snprintf(p, sizeof p, "%s/%s", save_dir, name);+ FILE *f = fopen(p, "rb");+ if (!f) return NULL;+ uint8_t *b = loaded[next_load++ & 3];+ *len = (uint32_t)fread(b, 1, sizeof loaded[0], f);+ fclose(f);+ return b;+}+static uint8_t reserved[1 << 16];+bool host_storage_full; /* tests: no room for any file */+uint8_t *plat_reserve(const char *name, uint32_t len) {+ (void)name;+ return len <= sizeof reserved && !host_storage_full ? reserved : NULL;+}+void plat_reserved(const char *name, uint32_t len) { plat_save(name, reserved, len); }+bool plat_remove(const char *name) {+ char p[512];+ snprintf(p, sizeof p, "%s/%s", save_dir, name);+ return remove(p) == 0;+}+uint32_t plat_random(void) {+ host_seed = host_seed * 1103515245u + 12345u;+ return host_seed ^ host_seed >> 16;+}+void plat_begin(void) {}+int plat_end(void) { return 0; }+bool plat_slow(void) { return false; }++/* writes the screen as a PPM image */+void host_shot(const char *path) {+ FILE *f = fopen(path, "wb");+ if (!f) return;+ fprintf(f, "P6\n%d %d\n255\n", SCREEN_W, SCREEN_H);+ for (int i = 0; i < SCREEN_W * SCREEN_H; i++) {+ uint16_t c = host_fb[i];+ uint8_t rgb[3] = {(uint8_t)((c >> 11) * 255 / 31), (uint8_t)(((c >> 5) & 63) * 255 / 63), (uint8_t)((c & 31) * 255 / 31)};+ fwrite(rgb, 1, 3, f);+ }+ fclose(f);+}diff --git a/games/cookieclicker/src/prestige.c b/games/cookieclicker/src/prestige.cnew file mode 100644index 00000000..b2c62594--- /dev/null+++ b/games/cookieclicker/src/prestige.c@@ -0,0 +1,280 @@+/* Ascension: prestige levels and heavenly chips (the game's HowMuchPrestige: a level for every+ * trillion cookies, cubed), the ascension and its crumbling cookie, the heavenly upgrades' tree,+ * permanent upgrade slots, the challenge mode Born again, and reincarnating (Game.Reset); the+ * shimmering veil. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"++#define HC_FACTOR 3+#define ASCEND_DURATION (FPS * 5)+#define ASCEND_BREAKPOINT (ASCEND_DURATION / 2)+#define REINCARNATE_DURATION (FPS * 1)++double how_much_prestige(double cookies) { return pow(cookies / 1e12, 1.0 / HC_FACTOR); }+double how_many_cookies_reset(double chips) { return pow(chips, HC_FACTOR) * 1e12; }++double heavenly_multiplier(void) {+ double m = 0;+ if (has(U_HEAVENLY_CHIP_SECRET)) m += 0.05;+ if (has(U_HEAVENLY_COOKIE_STAND)) m += 0.20;+ if (has(U_HEAVENLY_BAKERY)) m += 0.25;+ if (has(U_HEAVENLY_CONFECTIONERY)) m += 0.25;+ if (has(U_HEAVENLY_KEY)) m += 0.25;+ m *= 1 + aura_mult(AURA_DRAGON_GOD) * 0.05;+ if (has(U_LUCKY_DIGIT)) m *= 1.01;+ if (has(U_LUCKY_NUMBER)) m *= 1.01;+ if (has(U_LUCKY_PAYOUT)) m *= 1.01;+ static const float creation[4] = {1, 0.7f, 0.8f, 0.9f};+ m *= creation[hasgod(GOD_CREATION)];+ return m;+}++/* ------------------------------------------------------------------ the shimmering veil */+static double veil_defense(void) {+ double n = 0;+ if (has(U_REINFORCED_MEMBRANE)) n += 0.1;+ if (has(U_DELICATE_TOUCH)) n += 0.1;+ if (has(U_STEADFAST_MURMUR)) n += 0.1;+ if (has(U_GLITTERING_EDGE)) n += 0.1;+ return n;+}+double veil_boost(void) {+ double n = 0.5;+ if (has(U_REINFORCED_MEMBRANE)) n += 0.1;+ if (has(U_DELICATE_TOUCH)) n += 0.05;+ if (has(U_STEADFAST_MURMUR)) n += 0.05;+ if (has(U_GLITTERING_EDGE)) n += 0.05;+ return n;+}+void lose_shimmering_veil(int why) {+ (void)why;+ if (!has(U_SHIMMERING_VEIL)) return;+ if (!has(U_SHIMMERING_VEIL_OFF) && has(U_SHIMMERING_VEIL_ON)) return;+ if (has(U_REINFORCED_MEMBRANE) && rnd() < veil_defense()) {+ notify("The reinforced membrane protects the shimmering veil.", "", ICON(7, 10), 0);+ win(A_THICK_SKINNED);+ return;+ }+ bit_set(S.upgrades_bought, U_SHIMMERING_VEIL_ON, true);+ lock(U_SHIMMERING_VEIL_OFF), unlock(U_SHIMMERING_VEIL_OFF);+ notify("The shimmering veil disappears...", "", ICON(9, 10), 0);+ G.upgrades_dirty = true, G.recalculate = true;+}++/* ------------------------------------------------------------------ the heavenly upgrades */+/* how many 7s the prestige level is written with (Lucky digit, number, payout) */+static int sevens(void) {+ double p = S.prestige;+ int n = 0;+ char t[40];+ snprintf(t, sizeof t, "%.0f", p);+ for (char *c = t; *c; c++) n += *c == '7';+ return n;+}+bool heavenly_show_if(int u) {+ if (u == U_LUCKY_DIGIT) return sevens() >= 1;+ if (u == U_LUCKY_NUMBER) return sevens() >= 2;+ if (u == U_LUCKY_PAYOUT) return sevens() >= 4;+ return true;+}+/* a heavenly upgrade can be bought once all its parents are */+bool heavenly_can_be_purchased(int u) {+ if (bit_get(S.upgrades_bought, u)) return true;+ if (!heavenly_show_if(u)) return false;+ const UpgradeRec *r = upgrade_rec(u);+ for (int i = 0; i < 6 && r->parents[i] != NONE; i++)+ if (!bit_get(S.upgrades_bought, r->parents[i])) return false;+ return true;+}+/* shown dimmed: one of its parents can be bought */+bool heavenly_ghosted(int u) {+ if (heavenly_can_be_purchased(u) || !heavenly_show_if(u)) return false;+ const UpgradeRec *r = upgrade_rec(u);+ for (int i = 0; i < 6 && r->parents[i] != NONE; i++)+ if (heavenly_can_be_purchased(r->parents[i])) return true;+ return false;+}+int permanent_slot_of(int u) { /* which permanent upgrade slot (0..4) a heavenly upgrade is, or -1 */+ static const uint16_t slots[5] = {U_PERMANENT_UPGRADE_SLOT_I, U_PERMANENT_UPGRADE_SLOT_II,+ U_PERMANENT_UPGRADE_SLOT_III, U_PERMANENT_UPGRADE_SLOT_IV,+ U_PERMANENT_UPGRADE_SLOT_V};+ for (int i = 0; i < 5; i++)+ if (slots[i] == u) return i;+ return -1;+}+/* the upgrades a permanent slot can hold: bought last run, of the regular kind, not in another slot */+bool can_be_permanent(int u) {+ const UpgradeRec *r = upgrade_rec(u);+ if (!bit_get(S.upgrades_bought, u) || !has_unlocked(u)) return false;+ if (r->pool != POOL_NORMAL && r->pool != POOL_COOKIE) return false;+ for (int i = 0; i < N_NO_PERM; i++)+ if (LIST(NO_PERM)[i] == u) return false;+ for (int i = 0; i < 5; i++)+ if (S.permanent[i] == u + 1) return false;+ return true;+}++/* ------------------------------------------------------------------ ascending */+void earn_heavenly_chips(double forfeited, bool silent) {+ double p = floor(how_much_prestige(S.cookies_reset + forfeited));+ if (p < 0) p = 0;+ if (p != S.prestige) {+ double diff = p - S.prestige;+ extern double gained_prestige;+ gained_prestige = diff;+ S.heavenly_chips += diff;+ S.prestige = p;+ if (!silent && diff > 0) {+ char a[48], b[48], t[96], d[96];+ cookies_str(forfeited, 0, a);+ beautify(diff, 0, b);+ snprintf(t, sizeof t, "You forfeit your %s.", a);+ snprintf(d, sizeof d, "You gain \x01%s prestige level%s\x02!", b, diff == 1 ? "" : "s");+ notify(t, d, ICON(19, 7), 0);+ }+ }+}+double gained_prestige;++extern void reset_minigames(bool hard);+extern void lumps_reset(bool hard);+static bool in_list(const uint16_t *l, int n, int u) {+ for (int i = 0; i < n; i++)+ if (l[i] == u) return true;+ return false;+}++/* the game's Reset: a new run (hard: everything goes) */+void game_reset(bool hard) {+ G.T = 0, G.real_t = 0;+ double forfeited = S.cookies_earned;+ if (!hard) {+ static const struct { double at; uint16_t a; } wins[] = {+ {1e6, A_SACRIFICE}, {1e9, A_OBLIVION}, {1e12, A_FROM_SCRATCH}, {1e15, A_NIHILISM}, {1e18, A_DEMATERIALIZE},+ {1e21, A_NIL_ZERO_ZILCH}, {1e24, A_TRANSCENDENCE}, {1e27, A_OBLITERATE}, {1e30, A_NEGATIVE_VOID},+ {1e33, A_TO_CRUMBS_YOU_SAY}, {1e36, A_YOU_GET_NOTHING}, {1e39, A_HUMBLE_REBEGINNINGS},+ {1e42, A_THE_END_OF_THE_WORLD}, {1e45, A_OH_YOURE_BACK}, {1e48, A_LAZARUS}, {1e51, A_SMURF_ACCOUNT},+ {1e54, A_IF_AT_FIRST_YOU_DONT_SUCCEED}, {1e57, A_NO_MORE_ROOM_IN_HELL}};+ for (unsigned i = 0; i < sizeof wins / sizeof wins[0]; i++)+ if (forfeited >= wins[i].at) win(wins[i].a);+ if (round(S.cookies) == 1e12) win(A_WHEN_THE_COOKIES_ASCEND_JUST_RIGHT);+ if (has_buff(BUFF_LOAN1) || has_buff(BUFF_LOAN2) || has_buff(BUFF_LOAN3)) win(A_DEBT_EVASION);+ }+ for (int i = 0; i < MAX_BUFFS; i++) S.buffs[i].used = 0;+ S.cookies_reset += S.cookies_earned;+ S.cookies = 0, S.cookies_earned = 0, S.cookie_clicks = 0, S.golden_clicks_local = 0, S.handmade_cookies = 0;+ S.cookies_ps_raw_highest = 0;+ if (hard) {+ S.bg_type = 0, S.milk_type = 0;+ memset(S.upgrades_vaulted, 0, sizeof S.upgrades_vaulted);+ S.golden_clicks = 0, S.missed_golden_clicks = 0, S.resets = 0;+ S.full_date = S.play_time;+ S.cookies_reset = 0, S.prestige = 0, gained_prestige = 0;+ S.heavenly_chips = 0, S.heavenly_chips_spent = 0;+ memset(S.permanent, 0, sizeof S.permanent);+ S.ascension_mode = 0;+ lumps_reset(true);+ }+ S.pledges = 0, S.pledge_t = 0, S.elder_wrath = 0;+ extern float elder_wrath_d;+ elder_wrath_d = 0;+ S.next_research = 0, S.research_t = 0;+ S.season_t = 0, S.season_uses = 0, S.season = 0;+ 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.dragon_level = 0, S.dragon_aura = 0, S.dragon_aura2 = 0;+ S.ticker_clicks = 0;+ if (!hard && gained_prestige > 0) S.resets++;+ gained_prestige = 0;+ for (int b = 0; b < NB; b++) {+ Building *m = &S.buildings[b];+ m->amount = m->bought = m->highest = m->free = 0;+ m->total_cookies = 0;+ if (hard) m->muted = 0, m->level = 0;+ }+ for (int u = 0; u < N_UPGRADES; u++) {+ const UpgradeRec *r = upgrade_rec(u);+ bool lasting = in_list(LIST(LASTING), N_LASTING, u);+ if (hard || r->pool != POOL_PRESTIGE) bit_set(S.upgrades_bought, u, false);+ if (hard) bit_set(S.upgrades_unlocked, u, false);+ if (r->pool != POOL_PRESTIGE && !lasting) {+ bool keep = false;+ if (has(U_KEEPSAKES) && (in_list(LIST(HEART_DROPS), N_HEART_DROPS, u) ||+ in_list(LIST(HALLOWEEN_DROPS), N_HALLOWEEN_DROPS, u) ||+ in_list(LIST(EASTER_EGGS), N_EASTER_EGGS, u) ||+ in_list(LIST(SANTA_DROPS), N_SANTA_DROPS, u) ||+ in_list(LIST(REINDEER_DROPS), N_REINDEER_DROPS, u)) && rnd() < 1.0 / 5)+ keep = true;+ else if (S.ascension_mode == 1 && has_achiev(A_O_FORTUNA) && r->tier == TIER_FORTUNE)+ keep = true;+ else if (has_achiev(A_O_FORTUNA) && r->tier == TIER_FORTUNE && rnd() < 0.4)+ keep = true;+ if (!keep) bit_set(S.upgrades_unlocked, u, false);+ }+ }+ extern void game_recount(void);+ game_recount();+ if (!hard && S.ascension_mode != 1) {+ for (int i = 0; i < 5; i++)+ if (S.permanent[i]) earn_upgrade(S.permanent[i] - 1);+ if (has(U_SEASON_SWITCHER))+ unlock(U_FESTIVE_BISCUIT), unlock(U_GHOSTLY_BISCUIT), unlock(U_LOVESICK_BISCUIT), unlock(U_FOOLS_BISCUIT),+ unlock(U_BUNNY_BISCUIT);+ if (has(U_STARTER_KIT)) S.buildings[B_CURSOR].amount += 10, S.buildings[B_CURSOR].bought += 10,+ S.buildings[B_CURSOR].free += 10, S.buildings[B_CURSOR].highest = 10;+ if (has(U_STARTER_KITCHEN)) S.buildings[B_GRANDMA].amount += 5, S.buildings[B_GRANDMA].bought += 5,+ S.buildings[B_GRANDMA].free += 5, S.buildings[B_GRANDMA].highest = 5;+ }+ game_recount();+ G.recalculate = true, G.store_dirty = true, G.upgrades_dirty = true;+ shimmers_reset();+ G.buy_bulk = 1, G.buy_mode = 1;+ reset_minigames(hard);+ game_rebuild_upgrades();+}++void ascend_start(void) {+ notify("Ascending", "So long, cookies.", ICON(20, 7), 4);+ G.on_ascend = false;+ G.ascend_timer = 1;+ for (int i = 0; i < MAX_SHIMMERS; i++) G.shimmers[i].used = 0;+ shimmers_reset();+}++/* the animation: the cookie shakes, bursts, and the sky of heavenly upgrades opens */+void ascend_logic(void) {+ if (G.ascend_timer > 0) {+ G.ascend_timer++;+ if (G.ascend_timer > ASCEND_DURATION) {+ earn_heavenly_chips(S.cookies_earned, false);+ G.ascend_timer = 0;+ G.on_ascend = true;+ S.ascension_mode = 0;+ }+ }+}++/* back to the mortal world, in the challenge mode chosen (0 none, 1 Born again) */+void reincarnate(int mode) {+ S.ascension_mode = (uint8_t)mode;+ game_reset(false);+ if (has_achiev(A_REBIRTH)) notify("Reincarnated", "Hello, cookies!", ICON(10, 0), 4);+ if (S.resets >= 1000) win(A_ENDLESS_CYCLE);+ if (S.resets >= 100) win(A_REINCARNATION);+ if (S.resets >= 10) win(A_RESURRECTION);+ if (S.resets >= 1) win(A_REBIRTH);+ int owned = 0;+ for (int u = 0; u < N_UPGRADES; u++)+ if (bit_get(S.upgrades_bought, u) && upgrade_rec(u)->pool == POOL_PRESTIGE) owned++;+ if (owned >= 100) win(A_ALL_THE_STARS_IN_HEAVEN);+ G.on_ascend = false;+ G.reincarnate_timer = 1;+ G.big_size = 0;+}+void reincarnate_logic(void) {+ if (G.reincarnate_timer > 0 && ++G.reincarnate_timer > REINCARNATE_DURATION) G.reincarnate_timer = 0;+}diff --git a/games/cookieclicker/src/res.h b/games/cookieclicker/src/res.hnew file mode 100644index 00000000..d7188079--- /dev/null+++ b/games/cookieclicker/src/res.h@@ -0,0 +1,122 @@+/* Cookie Clicker: data.bin (tools/pack.py), read where it lies in flash.+ *+ * Pictures (IM_*) are a byte or half a byte a pixel with a palette of colours and+ * opacities, or RGB565; the icons are the game's icon sheet at 24 pixels; fonts (F_*)+ * are 4-bit glyphs; texts are the game's own, in a small markup (see text.c); and+ * the game's tables: buildings, tiers, upgrades, achievements, milks. */+#ifndef CC_RES_H+#define CC_RES_H+#include <stdbool.h>+#include <stdint.h>+#include "data.h"++extern const uint8_t cc_data[];++typedef struct {+ uint16_t w, h;+ uint8_t fmt, ncolors_1; /* fmt: 0 RGB565, 1 a byte a pixel, 2 half a byte a pixel; colours - 1 */+ uint16_t pad;+ uint32_t px, pal; /* offsets: the pixels, the palette (colours RGB565, then their opacities) */+} ImageRec;+enum { FMT_RGB, FMT_P8, FMT_P4 };++typedef struct {+ double price, cps;+ uint32_t name, single, plural, action, extra, extras, desc, pad;+ int16_t icon, column, pad1;+ uint16_t pad2;+} BuildingRec;++typedef struct {+ double price;+ uint32_t name;+ int16_t unlock, achiev_unlock, icon_row, special;+ uint16_t color, req;+} TierRec;++enum { POOL_NORMAL, POOL_COOKIE, POOL_PRESTIGE, POOL_TOGGLE, POOL_TECH, POOL_DEBUG };+enum { SEASON_NONE, SEASON_CHRISTMAS, SEASON_HALLOWEEN, SEASON_VALENTINES, SEASON_EASTER, SEASON_FOOLS };+typedef struct {+ double price;+ float order;+ uint32_t name, desc, quote;+ uint16_t icon;+ uint8_t pool, tier;+ int8_t building, building2;+ uint8_t kitten, flags; /* flags: the season it belongs to, 0x80 vanilla */+ float power;+ uint16_t require;+ uint16_t parents[6];+ int16_t posx, posy;+ uint16_t pad;+ double unlock_cookies;+} UpgradeRec;++enum { APOOL_NORMAL, APOOL_SHADOW, APOOL_DUNGEON };+typedef struct {+ uint32_t name, desc, quote;+ float order;+ uint16_t icon;+ uint8_t pool;+ int8_t building;+} AchievRec;++typedef struct {+ uint32_t name;+ uint16_t icon, pad;+} MilkRec;++/* what ties a building to its upgrades and achievements (by tier: data.h's TIER_*; 0xFFFF none) */+#define NONE 0xFFFF+typedef struct {+ uint16_t tiered[N_TIERS], tiered_ach[N_TIERS];+ uint16_t synergies[6];+ uint16_t fortune, grandma, unshackle, level10; /* level10: the achievement for its level 10 */+ uint16_t prod_ach[4];+ uint16_t pad2[2];+ double prod_pow[3];+} BuildingLinks;+typedef struct {+ double threshold;+ uint16_t id, pad;+ uint32_t pad2;+} Threshold;+typedef struct {+ double cookies;+ uint16_t up, ach, require_up, require_ach;+ uint8_t season, pad[7];+} UnlockAtRec;++_Static_assert(sizeof(BuildingLinks) == 128, "BuildingLinks");+_Static_assert(sizeof(Threshold) == 16, "Threshold");+_Static_assert(sizeof(UnlockAtRec) == 24, "UnlockAtRec");+_Static_assert(sizeof(ImageRec) == 16, "ImageRec");+_Static_assert(sizeof(BuildingRec) == 56, "BuildingRec");+_Static_assert(sizeof(TierRec) == 24, "TierRec");+_Static_assert(sizeof(UpgradeRec) == 64, "UpgradeRec");+_Static_assert(sizeof(AchievRec) == 20, "AchievRec");+_Static_assert(sizeof(MilkRec) == 8, "MilkRec");++#define RES(type, off) ((const type *)(const void *)(cc_data + (off)))+static inline const ImageRec *image_rec(int i) { return RES(ImageRec, OFF_IMAGES) + i; }+static inline const BuildingRec *building_rec(int i) { return RES(BuildingRec, OFF_BUILDINGS) + i; }+static inline const TierRec *tier_rec(int i) { return RES(TierRec, OFF_TIERS) + i; }+static inline const UpgradeRec *upgrade_rec(int i) { return RES(UpgradeRec, OFF_UPGRADES) + i; }+static inline const AchievRec *achiev_rec(int i) { return RES(AchievRec, OFF_ACHIEVS) + i; }+static inline const MilkRec *milk_rec(int i) { return RES(MilkRec, OFF_MILKS) + i; }+static inline const BuildingLinks *building_links(int i) { return RES(BuildingLinks, OFF_BUILDING_LINKS) + i; }+/* a list of ids (LIST(COOKIE_UPGRADES)[i], i < N_COOKIE_UPGRADES) */+#define LIST(name) RES(uint16_t, OFF_##name)+static inline const Threshold *bank_achiev(int i) { return RES(Threshold, OFF_BANK_ACHIEVS) + i; }+static inline const Threshold *cps_achiev(int i) { return RES(Threshold, OFF_CPS_ACHIEVS) + i; }+static inline const UnlockAtRec *unlock_at(int i) { return RES(UnlockAtRec, OFF_UNLOCK_AT) + i; }+static inline const char *res_text(uint32_t off) { return (const char *)cc_data + OFF_TEXT + off; }+/* the picture of icon (x, y) of the game's sheet, -1 if it is empty */+static inline int icon_image(int x, int y) {+ if ((unsigned)x >= ICON_COLS || (unsigned)y >= ICON_ROWS) return -1;+ uint16_t i = RES(uint16_t, OFF_ICONS)[y * ICON_COLS + x];+ return i == 0xFFFF ? -1 : i;+}+static inline int icon_index_image(int index) { return index == 0xFFFF ? -1 : icon_image(index % ICON_COLS, index / ICON_COLS); }+#define ICON(x, y) ((y) * ICON_COLS + (x))+#endifdiff --git a/games/cookieclicker/src/rows.c b/games/cookieclicker/src/rows.cnew file mode 100644index 00000000..0ef0b6c7--- /dev/null+++ b/games/cookieclicker/src/rows.c@@ -0,0 +1,278 @@+/* The buildings' rows (the middle of the game's screen), shown with alpha in place of the store:+ * each building owned on its background, as many of its pictures as fit, set the game's way (rows,+ * random shifts, grandmas of every type they have become); its level; and the minigames. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "ui.h"++#define ROW_H 48+#define ROW_GAP 4+#define ROWS_X STORE_X+#define ROWS_W STORE_W+#define SC 0.375f+extern bool can_lumps(void);+extern void draw_minigame(int b);+extern void minigame_keys(int b, uint32_t pressed);+extern bool minigame_available(int b);+extern const char *minigame_name(int b);+extern bool level_up(int b);++/* the art of each building's row: random shifts, spacing, rows, offsets, frames (the game's) */+typedef struct { int8_t xv, yv, w, rows, x, y, frames; } Art;+static const Art arts[NB] = {+ {0, 0, 0, 0, 0, 0, 0}, {8, 8, 32, 3, 0, 16, 1}, {8, 8, 64, 2, 0, 16, 1}, {16, 16, 64, 2, 0, 24, 1},+ {8, 0, 64, 1, 0, -22, 1}, {8, 4, 56, 1, 0, 13, 1}, {8, 4, 72, 2, 0, -5, 1}, {16, 16, 48, 2, 0, 20, 1},+ {16, 16, 64, 1, 0, 0, 1}, {16, 16, 64, 2, 0, 16, 1}, {32, 32, 64, 2, 0, 0, 1}, {32, 32, 64, 1, 0, 0, 1},+ {0, 64, 64, 1, 0, 0, 1}, {16, 4, 64, 1, 0, 20, 1}, {8, 64, 64, 2, 0, 0, 1}, {8, 64, 64, 1, 0, 0, 1},+ {8, 64, 14, 1, 8, -32, 2}, {8, 96, 48, 2, 0, 0, 4}, {8, 96, 48, 1, 0, 0, 4}, {0, 0, 64, 2, 0, 0, 1},+};+static const int16_t row_bg[NB] = {-1, IM_ROW_BG_GRANDMA, IM_ROW_BG_FARM, IM_ROW_BG_MINE, IM_ROW_BG_FACTORY,+ IM_ROW_BG_BANK, IM_ROW_BG_TEMPLE, IM_ROW_BG_WIZARDTOWER, IM_ROW_BG_SHIPMENT,+ IM_ROW_BG_ALCHEMYLAB, IM_ROW_BG_PORTAL, IM_ROW_BG_TIMEMACHINE,+ IM_ROW_BG_ANTIMATTERCONDENSER, IM_ROW_BG_PRISM, IM_ROW_BG_CHANCEMAKER,+ IM_ROW_BG_FRACTALENGINE, IM_ROW_BG_JAVASCRIPTCONSOLE, IM_ROW_BG_IDLEVERSE,+ IM_ROW_BG_CORTEX, IM_ROW_BG_YOU};+static const int16_t row_pic[NB] = {-1, IM_ROW_GRANDMA, IM_ROW_FARM, IM_ROW_MINE, IM_ROW_FACTORY, IM_ROW_BANK,+ IM_ROW_TEMPLE, IM_ROW_WIZARDTOWER, IM_ROW_SHIPMENT, IM_ROW_ALCHEMYLAB,+ IM_ROW_PORTAL, IM_ROW_TIMEMACHINE, IM_ROW_ANTIMATTERCONDENSER, IM_ROW_PRISM,+ IM_ROW_CHANCEMAKER, IM_ROW_FRACTALENGINE, IM_ROW_JAVASCRIPTCONSOLE0,+ IM_ROW_IDLEVERSE0, IM_ROW_CORTEX0, IM_ROW_YOU};+/* the grandmas' types, in the order of their pictures (IM_ROW_FARMERGRANDMA...) */+static const uint16_t grandma_types[18] = {+ U_FARMER_GRANDMAS, U_WORKER_GRANDMAS, U_MINER_GRANDMAS, U_COSMIC_GRANDMAS, U_TRANSMUTED_GRANDMAS,+ U_ALTERED_GRANDMAS, U_GRANDMAS_GRANDMAS, U_ANTIGRANDMAS, U_RAINBOW_GRANDMAS, U_BANKER_GRANDMAS,+ U_PRIESTESS_GRANDMAS, U_WITCH_GRANDMAS, U_LUCKY_GRANDMAS, U_METAGRANDMAS, U_SCRIPT_GRANNIES,+ U_ALTERNATE_GRANDMAS, U_BRAINY_GRANDMAS, U_CLONE_GRANDMAS};+static const char *const grandma_names[] = {+ "Granny", "Gusher", "Ethel", "Edna", "Doris", "Maud", "Hilda", "Gladys", "Michelle", "Michele", "Phyllis",+ "Millicent", "Muriel", "Myrtle", "Mildred", "Mavis", "Helen", "Gloria", "Sheila", "Betty", "Gertrude", "Agatha",+ "Beryl", "Agnes", "Pearl", "Precious", "Ruby", "Vera", "Bonnie", "Ada", "Bunny", "Cookie", "Darling", "Gaga",+ "GamGam", "Memaw", "Mimsy", "Peanut", "Nana", "Nan", "Tootsie", "Warty", "Stinky", "Heinous"};++/* the same numbers each time for the same picture (the game seeds its random with it) */+static uint32_t hash3(uint32_t a, uint32_t b, uint32_t c) {+ uint32_t h = a * 0x9E3779B1u ^ b * 0x85EBCA77u ^ c * 0xC2B2AE3Du;+ h ^= h >> 15, h *= 0x2C1B3C6Du, h ^= h >> 12, h *= 0x297A2D39u, h ^= h >> 15;+ return h;+}+static float hrand(uint32_t *h) {+ *h = *h * 1664525u + 1013904223u;+ return (float)(*h >> 8) / 16777216.f;+}++/* the rows shown: buildings owned past the cursor */+static int rows[NB], nrows;+static void rows_list(void) {+ nrows = 0;+ for (int b = 1; b < NB; b++)+ if (S.buildings[b].amount > 0) rows[nrows++] = b;+ if (U.rows_sel >= nrows) U.rows_sel = nrows ? nrows - 1 : 0;+}++static int grandma_pic(uint32_t *h) {+ int list[21], n = 0;+ list[n++] = IM_ROW_GRANDMA;+ for (int i = 0; i < 18; i++)+ if (has(grandma_types[i])) list[n++] = IM_ROW_FARMERGRANDMA + i;+ if (S.season == SEASON_CHRISTMAS) list[n++] = IM_ROW_ELFGRANDMA;+ if (S.season == SEASON_EASTER) list[n++] = IM_ROW_BUNNYGRANDMA;+ return list[(int)(hrand(h) * n) % n];+}++static void draw_row(int b, int y, bool sel) {+ const Art *a = &arts[b];+ gfx_clip(ROWS_X, y, ROWS_W, ROW_H);+ gfx_pattern(row_bg[b], ROWS_X, y, ROWS_W, ROW_H, ROW_H, ROW_H, ROWS_X, y, 256);+ /* the pictures: at the game's places (in a 128-pixel row), drawn at 0.375 */+ int w = a->w ? a->w : 48, nrow = a->rows ? a->rows : 1;+ int max_i = (int)(ROWS_W / SC / ((float)w / nrow)) + 1;+ int amount = S.buildings[b].amount < max_i ? S.buildings[b].amount : max_i;+ int prev = 0;+ /* drawn from the back (smaller y) to the front */+ static int16_t px[64], py[64], pp[64];+ int n = 0;+ for (int i = 0; i < amount && n < 64; i++) {+ uint32_t h = hash3(G.seed, (uint32_t)b, (uint32_t)i);+ float x, yy;+ if (nrow != 1) {+ x = floorf((float)(i / nrow)) * w + ((float)(i % nrow) / nrow) * w + floorf((hrand(&h) - 0.5f) * a->xv) + a->x;+ yy = 32 + floorf((hrand(&h) - 0.5f) * a->yv) + ((-nrow / 2.f) * 32 / 2 + (i % nrow) * 32 / 2.f) + a->y;+ } else {+ x = (float)i * w + floorf((hrand(&h) - 0.5f) * a->xv) + a->x;+ yy = 32 + floorf((hrand(&h) - 0.5f) * a->yv) + a->y;+ }+ int pic = row_pic[b];+ if (b == B_GRANDMA) pic = grandma_pic(&h);+ if (a->frames > 1) {+ int f = (prev + (int)(hrand(&h) * (a->frames - 1)) + 1) % a->frames;+ prev = f;+ pic += f;+ }+ px[n] = (int16_t)(ROWS_X + x * SC), py[n] = (int16_t)(y + yy * SC), pp[n] = (int16_t)pic;+ n++;+ }+ for (int k = 0; k < n; k++) { /* (sorted by y, as the game sorts its sprites) */+ int best = k;+ for (int j = k + 1; j < n; j++)+ if (py[j] < py[best]) best = j;+ int16_t t;+ t = px[k], px[k] = px[best], px[best] = t;+ t = py[k], py[k] = py[best], py[best] = t;+ t = pp[k], pp[k] = pp[best], pp[best] = t;+ if (gfx_visible(px[k], py[k], 24, 48)) gfx_image(pp[k], px[k], py[k], 256);+ }+ /* a grandma's name when their row is chosen */+ if (sel && b == B_GRANDMA && n > 0) {+ int k = (int)(G.real_t / (FPS * 3)) % n;+ uint32_t h = hash3(G.seed, 77, (uint32_t)k + (uint32_t)(G.real_t / (FPS * 3)) * 31);+ char t[48];+ snprintf(t, sizeof t, "%s, age %d", grandma_names[(int)(hrand(&h) * 44) % 44],+ (int)(70 + hrand(&h) * 30 + 13 + S.buildings[b].level));+ int tw = gfx_text_width(F_NAME_SMALL, t) + 8;+ int tx = px[k] + 12 - tw / 2;+ if (tx < ROWS_X) tx = ROWS_X;+ if (tx + tw > SCREEN_W) tx = SCREEN_W - tw;+ gfx_line(px[k] + 12, py[k] + 12, tx + tw / 2, y + 12, BLACK, 190);+ gfx_fill_alpha(tx, y + 2, tw, 11, BLACK, 190);+ gfx_text(F_NAME_SMALL, tx + 4, y + 10, t, RGB(200, 200, 200), 256);+ }+ /* its level and minigame */+ char t[64];+ int ly = y + ROW_H - 4;+ if (can_lumps() || S.buildings[b].level > 0) {+ snprintf(t, sizeof t, "lvl %d", S.buildings[b].level);+ gfx_fill_alpha(ROWS_X, ly - 9, gfx_text_width(F_SMALL, t) + 16, 11, BLACK, 140);+ gfx_icon_scaled(ICON(29, 14), ROWS_X + 1, ly - 9, 11, 256);+ gfx_text_outline(F_SMALL, ROWS_X + 13, ly, t, WHITE, 256);+ }+ if (minigame_available(b)) {+ snprintf(t, sizeof t, "%s %s", S.on_minigame == b + 1 ? "Close" : "View", minigame_name(b));+ int tw = gfx_text_width(F_SMALL, t) + 6;+ gfx_round_rect(SCREEN_W - tw - 2, ly - 9, tw, 11, 2, BLACK, 150);+ gfx_text_outline(F_SMALL, SCREEN_W - tw + 1, ly, t, RGB(255, 238, 200), 256);+ }+ if (S.buildings[b].muted) gfx_fill_alpha(ROWS_X, y, ROWS_W, ROW_H, BLACK, 150);+ if (sel)+ for (int k = 0; k < 3; k++) gfx_rect(ROWS_X + k, y + k, ROWS_W - 2 * k, ROW_H - 2 * k, RGB(255, 238, 221), 160 - k * 50);+ gfx_unclip();+}++void draw_rows(void) {+ if (!gfx_visible(LEFT_W, NEWS_H, SCREEN_W - LEFT_W, SCREEN_H - NEWS_H)) return;+ for (int y = NEWS_H; y < SCREEN_H; y += 128) gfx_image(IM_PANEL_V, LEFT_W, y, 256);+ if (S.on_minigame) {+ draw_minigame(S.on_minigame - 1);+ return;+ }+ rows_list();+ gfx_clip(ROWS_X, NEWS_H, ROWS_W, SCREEN_H - NEWS_H);+ gfx_pattern(IM_DARK_NOISE, ROWS_X, NEWS_H, ROWS_W, SCREEN_H - NEWS_H, 128, 128, 0, 0, 256);+ if (!nrows) {+ ParaStyle st = PS_TIP;+ st.align = 1;+ gfx_para(&st, ROWS_X + 8, NEWS_H + 80, ROWS_W - 16, "Your buildings show here once you have some.\n"+ "\x01" "alpha\x02: back to the store", true);+ }+ int top = (int)U.rows_scroll;+ for (int i = 0; i < nrows; i++) {+ int y = NEWS_H + i * (ROW_H + ROW_GAP) - top;+ if (!gfx_visible(ROWS_X, y, ROWS_W, ROW_H + ROW_GAP)) continue;+ draw_row(rows[i], y, i == U.rows_sel);+ for (int x = ROWS_X; x < SCREEN_W; x += 128) gfx_image(IM_PANEL_H, x, y + ROW_H, 256);+ }+ gfx_unclip();+}++/* ------------------------------------------------------------------ the row's actions */+enum { RA_MINIGAME, RA_LEVEL, RA_MUTE };+static int actions[3], nactions;+static void row_actions(int b) {+ nactions = 0;+ if (minigame_available(b)) actions[nactions++] = RA_MINIGAME;+ if (can_lumps()) actions[nactions++] = RA_LEVEL;+ actions[nactions++] = RA_MUTE;+}++void draw_row_menu(void) {+ rows_list();+ if (!nrows) return;+ int b = rows[U.rows_sel];+ row_actions(b);+ const BuildingRec *r = building_rec(b);+ int w = 200, x = (SCREEN_W - w) / 2, h = 36 + nactions * 18 + 30;+ int y = (SCREEN_H - h) / 2;+ gfx_fill_alpha(0, 0, SCREEN_W, SCREEN_H, BLACK, 100);+ draw_frame_box(x, y, w, h);+ gfx_icon(ICON(r->column, 0), x + 6, y + 6, 256);+ gfx_text_outline(F_TITLE, x + 34, y + 18, res_text(r->plural), WHITE, 256);+ char t[200];+ const char *extra = res_text(S.buildings[b].level == 1 ? r->extra : r->extras);+ char e[96];+ snprintf(e, sizeof e, "%s", extra);+ char *xp = strstr(e, "[X]");+ if (xp) {+ char rest[96];+ snprintf(rest, sizeof rest, "%s", xp + 3);+ snprintf(xp, sizeof e - (size_t)(xp - e), "%d%s", S.buildings[b].level, rest);+ }+ if (S.buildings[b].level > 0) snprintf(t, sizeof t, "Level %d: %s (+%d%% CpS)", S.buildings[b].level, e, S.buildings[b].level);+ else snprintf(t, sizeof t, "Level 0");+ ParaStyle st = PS_SMALL;+ st.align = 1;+ gfx_para(&st, x + 6, y + 30, w - 12, t, true);+ for (int i = 0; i < nactions; i++) {+ int by = y + 52 + i * 18, bw = w - 40, bx = x + 20;+ if (actions[i] == RA_MINIGAME) snprintf(t, sizeof t, "%s %s", S.on_minigame == b + 1 ? "Close" : "View", minigame_name(b));+ else if (actions[i] == RA_LEVEL) snprintf(t, sizeof t, "Level up for %d sugar lump%s", S.buildings[b].level + 1,+ S.buildings[b].level ? "s" : "");+ else snprintf(t, sizeof t, "%s", S.buildings[b].muted ? "Unmute" : "Mute");+ bool on = U.list_sel == i;+ bool can = actions[i] != RA_LEVEL || S.lumps >= S.buildings[b].level + 1;+ gfx_fill_alpha(bx, by, bw, 15, on ? WHITE : BLACK, on ? 40 : 110);+ gfx_rect(bx, by, bw, 15, on ? WHITE : RGB(110, 110, 110), 256);+ gfx_text_center(F_NAME_SMALL, bx + bw / 2, by + 11, t, can ? on ? WHITE : RGB(220, 220, 220) : RGB(255, 102, 102), 256);+ }+}++void row_menu_keys(uint32_t p) {+ rows_list();+ if (!nrows) {+ U.overlay = OV_NONE;+ return;+ }+ int b = rows[U.rows_sel];+ row_actions(b);+ if (p & K_UP && U.list_sel > 0) U.list_sel--;+ if (p & K_DOWN && U.list_sel < nactions - 1) U.list_sel++;+ if (p & K_BACK) U.overlay = OV_NONE;+ if (!(p & (K_OK | K_EXE))) return;+ U.overlay = OV_NONE;+ switch (actions[U.list_sel]) {+ case RA_MINIGAME: S.on_minigame = S.on_minigame == b + 1 ? 0 : (uint8_t)(b + 1); break;+ case RA_LEVEL:+ if (S.lumps >= S.buildings[b].level + 1) prompt_open(PROMPT_LEVEL, b);+ break;+ case RA_MUTE: S.buildings[b].muted = !S.buildings[b].muted; break;+ }+}++void rows_keys(uint32_t p) {+ if (S.on_minigame) {+ if (p & K_BACK) {+ S.on_minigame = 0;+ return;+ }+ minigame_keys(S.on_minigame - 1, p);+ return;+ }+ rows_list();+ if (p & K_UP && U.rows_sel > 0) U.rows_sel--;+ if (p & K_DOWN && U.rows_sel < nrows - 1) U.rows_sel++;+ int view = SCREEN_H - NEWS_H, y = U.rows_sel * (ROW_H + ROW_GAP);+ if (y - U.rows_scroll < 0) U.rows_scroll = (float)y;+ if (y + ROW_H - U.rows_scroll > view) U.rows_scroll = (float)(y + ROW_H - view);+ if (p & K_EXE && nrows) {+ U.overlay = OV_ROWMENU, U.list_sel = 0;+ }+}diff --git a/games/cookieclicker/src/save.c b/games/cookieclicker/src/save.cnew file mode 100644index 00000000..20b322cb--- /dev/null+++ b/games/cookieclicker/src/save.c@@ -0,0 +1,135 @@+/* Saves: the game in cookieclicker.sav, written every minute (as the game saves itself) and when it+ * quits. Its copy is cookieclicker_saves.py, a comment line "#>name:base64" (the way NumPlay and its+ * big games keep theirs: installing apps erases every file but Python scripts). */+#include <stddef.h>+#include <string.h>+#include "game.h"++#define SAVE_NAME "cookieclicker.sav"+#define COPY_NAME "cookieclicker_saves.py"+#define MAGIC 0x314B4343u /* "CCK1" */++static const char copy_head[] =+ "# Cookie Clicker keeps a copy of your bakery here, so that\n"+ "# reinstalling it doesn't erase it. If you delete this file,\n"+ "# the game writes it again: your bakery stays.\n";+static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";++static void copy_write(void) {+ uint32_t len;+ const uint8_t *d = plat_load(SAVE_NAME, &len);+ plat_remove(COPY_NAME);+ if (!d || !len) return;+ uint32_t nl = (uint32_t)strlen(SAVE_NAME);+ uint32_t total = 1 + (sizeof copy_head - 1) + 2 + nl + 1 + (len + 2) / 3 * 4 + 1 + 1;+ uint8_t *o = plat_reserve(COPY_NAME, total), *p = o;+ if (!o) return;+ d = plat_load(SAVE_NAME, &len); /* (the reservation may have moved the files) */+ if (!d) return;+ *p++ = 0; /* (the script's status byte: not imported) */+ memcpy(p, copy_head, sizeof copy_head - 1), p += sizeof copy_head - 1;+ *p++ = '#', *p++ = '>';+ memcpy(p, SAVE_NAME, nl), p += nl;+ *p++ = ':';+ for (uint32_t i = 0; i < len; i += 3, p += 4) {+ /* (written out: GCC 15.2 for the calculator got a loop over the four wrong, see NumPlay's+ * launcher/src/storage.c) */+ uint32_t left = len - i, v = (uint32_t)d[i] << 16 | (left > 1 ? d[i + 1] << 8 : 0) | (left > 2 ? d[i + 2] : 0);+ p[0] = (uint8_t)b64[v >> 18 & 63];+ p[1] = (uint8_t)b64[v >> 12 & 63];+ p[2] = left > 1 ? (uint8_t)b64[v >> 6 & 63] : '=';+ p[3] = left > 2 ? (uint8_t)b64[v & 63] : '=';+ }+ *p++ = '\n';+ *p++ = 0;+ plat_reserved(COPY_NAME, (uint32_t)(p - o));+}++static int b64_value(uint8_t c) {+ for (int i = 0; i < 64; i++)+ if ((uint8_t)b64[i] == c) return i;+ return -1;+}++static const uint8_t *copy_line(uint32_t *len) {+ uint32_t n, nl = (uint32_t)strlen(SAVE_NAME);+ const uint8_t *c = plat_load(COPY_NAME, &n);+ if (!c) return NULL;+ for (uint32_t i = 0; i + nl + 3 <= n; i++)+ if (c[i] == '#' && c[i + 1] == '>' && !memcmp(c + i + 2, SAVE_NAME, nl) && c[i + 2 + nl] == ':') {+ const uint8_t *l = c + i + 3 + nl;+ uint32_t m = 0;+ while (l + m < c + n && l[m] != '\n' && l[m]) m++;+ *len = m;+ return l;+ }+ return NULL;+}++/* the save from its copy, when the save is gone (apps were installed again) */+void save_restore_copy(void) {+ uint32_t have, len;+ if (plat_load(SAVE_NAME, &have)) return;+ const uint8_t *l = copy_line(&len);+ if (!l || !len || len % 4) return;+ uint32_t size = len / 4 * 3 - (l[len - 1] == '=') - (l[len - 2] == '=');+ uint8_t *out = plat_reserve(SAVE_NAME, size);+ if (!out) return;+ l = copy_line(&len);+ bool ok = l != NULL && len / 4 * 3 - (l[len - 1] == '=') - (l[len - 2] == '=') == size;+ uint32_t o = 0;+ for (uint32_t i = 0; ok && i < len; i += 4) {+ int v0 = l[i] == '=' ? 0 : b64_value(l[i]), v1 = l[i + 1] == '=' ? 0 : b64_value(l[i + 1]);+ int v2 = l[i + 2] == '=' ? 0 : b64_value(l[i + 2]), v3 = l[i + 3] == '=' ? 0 : b64_value(l[i + 3]);+ if (v0 < 0 || v1 < 0 || v2 < 0 || v3 < 0) ok = false;+ uint32_t wd = (uint32_t)(v0 << 18 | v1 << 12 | v2 << 6 | v3);+ if (o < size) out[o++] = (uint8_t)(wd >> 16);+ if (o < size) out[o++] = (uint8_t)(wd >> 8);+ if (o < size) out[o++] = (uint8_t)wd;+ }+ if (ok && o == size) plat_reserved(SAVE_NAME, size);+ else plat_remove(SAVE_NAME);+}++/* ------------------------------------------------------------------ the game */+extern void game_recount(void);+extern void ui_init(void);++bool game_load(void) {+ save_restore_copy();+ uint32_t len;+ const uint8_t *d = plat_load(SAVE_NAME, &len);+ if (!d || len != sizeof(SaveState)) return false;+ uint32_t m;+ memcpy(&m, d, 4);+ if (m != MAGIC) return false;+ memcpy(&S, d, sizeof(SaveState));+ game_recount();+ if (S.on_ascend) { /* (quit while ascending: back to the heavens) */+ extern void earn_heavenly_chips(double forfeited, bool silent);+ earn_heavenly_chips(S.cookies_earned, true);+ G.on_ascend = true;+ }+ G.recalculate = true, G.upgrades_dirty = true, G.store_dirty = true;+ calculate_gains();+ G.cookies_d = S.cookies;+ return true;+}++bool game_save(void) {+ S.magic = MAGIC;+ S.on_ascend = G.on_ascend || G.ascend_timer > 0;+ bool ok = plat_save(SAVE_NAME, &S, sizeof(SaveState));+ copy_write();+ return ok;+}++/* the Options' "Wipe save" */+void game_wipe(void) {+ plat_remove(SAVE_NAME);+ plat_remove(COPY_NAME);+ game_new();+ calculate_gains();+ ui_init();+ S.seen_keys = 1;+}diff --git a/games/cookieclicker/src/season.c b/games/cookieclicker/src/season.cnew file mode 100644index 00000000..b38241ac--- /dev/null+++ b/games/cookieclicker/src/season.c@@ -0,0 +1,98 @@+/* Seasons (the Season switcher's biscuits: Christmas, Halloween, Valentine's day, Business day,+ * Easter), their drops: eggs, Santa's gifts. The game's own calendar seasons need a date the+ * calculator doesn't have: here a season is one the switcher triggers, for 24 hours of play. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"++#define SEASON_TRIGGER_BASE_PRICE 1000000000.0+static const struct { uint16_t trigger; const char *name, *start, *over; } seasons[6] = {+ {0, "", "", ""},+ {U_FESTIVE_BISCUIT, "Christmas", "Christmas season has started!", "Christmas season is over."},+ {U_GHOSTLY_BISCUIT, "Halloween", "Halloween has started!", "Halloween is over."},+ {U_LOVESICK_BISCUIT, "Valentine's day", "Valentine's day has started!", "Valentine's day is over."},+ {U_BUNNY_BISCUIT, "Easter", "Easter season has started!", "Easter season is over."},+ {U_FOOLS_BISCUIT, "Business day", "Business day has started!", "Business day is over."},+};+const char *season_name(int s) { return seasons[s].name; }+static int season_of_trigger(int u) {+ for (int s = 1; s < 6; s++)+ if (seasons[s].trigger == u) return s;+ return 0;+}+static int32_t season_duration(void) { return FPS * 60 * 60 * 24; }++double season_price(int u) {+ (void)u;+ static const float m[4] = {1, 2, 1.5f, 1.25f};+ return SEASON_TRIGGER_BASE_PRICE + G.unbuffed_cps * 60 * pow(1.5, S.season_uses) * m[hasgod(GOD_SEASONS)];+}++void season_trigger(int u) {+ int s = season_of_trigger(u);+ S.season_uses++;+ for (int k = 1; k < 6; k++)+ if (seasons[k].trigger != u) lock(seasons[k].trigger), unlock(seasons[k].trigger);+ if (S.season && S.season != s) notify(seasons[S.season].over, "", upgrade_rec(seasons[S.season].trigger)->icon, 4);+ S.season = (uint8_t)s;+ S.season_t = season_duration();+ G.store_dirty = true, G.upgrades_dirty = true;+ notify(seasons[s].start, "", upgrade_rec(u)->icon, 4);+}+/* a season's biscuit, bought again: the season stops */+bool season_cancel(int u) {+ int s = season_of_trigger(u);+ if (!s || !bit_get(S.upgrades_bought, u) || S.season != s) return false;+ lock(u);+ notify(seasons[s].over, "", upgrade_rec(u)->icon, 0);+ if (has(U_SEASON_SWITCHER)) unlock(u), bit_set(S.upgrades_bought, u, false);+ G.upgrades_dirty = true, G.recalculate = true;+ S.season = 0, S.season_t = -1;+ return true;+}++void season_logic(void) {+ if (S.season_t > 0) S.season_t--;+ if (S.season_t <= 0 && S.season && !has(U_ETERNAL_SEASONS)) {+ int u = seasons[S.season].trigger;+ notify(seasons[S.season].over, "", upgrade_rec(u)->icon, 0);+ if (has(U_SEASON_SWITCHER)) unlock(u), bit_set(S.upgrades_bought, u, false);+ S.season = 0, S.season_t = -1;+ G.upgrades_dirty = true;+ }+}++/* ------------------------------------------------------------------ Easter */+int how_many_eggs(void) {+ int n = 0;+ for (int i = 0; i < N_EASTER_EGGS; i++) n += has(LIST(EASTER_EGGS)[i]);+ return n;+}+void drop_egg(double fail) {+ if (S.season != SEASON_EASTER) return;+ if (has_achiev(A_HIDE_AND_SEEK_CHAMPION)) fail *= 0.8;+ if (has(U_OMELETTE)) fail *= 0.9;+ if (has(U_STARSPAWN)) fail *= 0.9;+ static const float sg[4] = {1, 0.9f, 0.95f, 0.97f};+ fail *= sg[hasgod(GOD_SEASONS)];+ fail = pow(fail, drop_rate_mult());+ if (rnd() <= fail) return;+ /* the first 12 eggs are the common ones, the last 8 the rare ones */+ int drop = rnd() < 0.1 ? LIST(EASTER_EGGS)[12 + rnd_int(8)] : LIST(EASTER_EGGS)[rnd_int(12)];+ if (has(drop) || has_unlocked(drop)) drop = rnd() < 0.1 ? LIST(EASTER_EGGS)[12 + rnd_int(8)] : LIST(EASTER_EGGS)[rnd_int(12)];+ if (has(drop) || has_unlocked(drop)) return;+ unlock(drop);+ char d[64];+ snprintf(d, sizeof d, "\x01%s\x02", res_text(upgrade_rec(drop)->name));+ notify("You found an egg!", d, upgrade_rec(drop)->icon, 0);+}++/* ------------------------------------------------------------------ Christmas: Santa's gifts */+void santa_drop(void) {+ int drop = LIST(SANTA_DROPS)[rnd_int(N_SANTA_DROPS)];+ unlock(drop);+ char d[96];+ snprintf(d, sizeof d, "a festive test tube\nand \x01%s\x02.", res_text(upgrade_rec(drop)->name));+ notify("In the festive hat, you find...", d, upgrade_rec(drop)->icon, 0);+}diff --git a/games/cookieclicker/src/shimmer.c b/games/cookieclicker/src/shimmer.cnew file mode 100644index 00000000..0324f579--- /dev/null+++ b/games/cookieclicker/src/shimmer.c@@ -0,0 +1,562 @@+/* Shimmers (golden and wrath cookies, reindeer) and buffs: the game's Game.shimmerTypes, its golden+ * cookie effects, and Game.gainBuff and its buff types. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"++#define GC_SIZE 36 /* a golden cookie: 96 pixels in the game */+extern void gain_lumps(int n);+extern bool can_lumps(void);+extern void drop_egg(double failrate);+extern void lose_shimmering_veil(int why);+extern bool force_unslot_god(int god);+extern void use_swap(int32_t t);++static const char *const building_buffs[NB][2] = {+ {"High-five", "Slap to the face"}, {"Congregation", "Senility"}, {"Luxuriant harvest", "Locusts"},+ {"Ore vein", "Cave-in"}, {"Oiled-up", "Jammed machinery"}, {"Juicy profits", "Recession"},+ {"Fervent adoration", "Crisis of faith"}, {"Manabloom", "Magivores"}, {"Delicious lifeforms", "Black holes"},+ {"Breakthrough", "Lab disaster"}, {"Righteous cataclysm", "Dimensional calamity"}, {"Golden ages", "Time jam"},+ {"Extra cycles", "Predictable tragedy"}, {"Solar flare", "Eclipse"}, {"Winning streak", "Dry spell"},+ {"Macrocosm", "Microcosm"}, {"Refactoring", "Antipattern"}, {"Cosmic nursery", "Big crunch"},+ {"Brainstorm", "Brain freeze"}, {"Deduplication", "Clone strike"}};++/* ------------------------------------------------------------------ buffs */+typedef struct {+ const char *name;+ int16_t icon;+ uint8_t mode; /* 0 set, 1 add, 2 max */+ uint8_t aura; /* 1 good, 2 bad */+} BuffType;+static const BuffType buff_types[N_BUFF_TYPES] = {+ [BUFF_FRENZY] = {"Frenzy", ICON(10, 14), 1, 1}, [BUFF_ELDER_FRENZY] = {"Elder frenzy", ICON(29, 6), 1, 1},+ [BUFF_CLOT] = {"Clot", ICON(15, 5), 1, 2}, [BUFF_DRAGON_HARVEST] = {"Dragon Harvest", ICON(10, 25), 1, 1},+ [BUFF_EVERYTHING_MUST_GO] = {"Everything must go", ICON(17, 6), 1, 1},+ [BUFF_CURSED_FINGER] = {"Cursed finger", ICON(12, 17), 1, 1},+ [BUFF_CLICK_FRENZY] = {"Click frenzy", ICON(0, 14), 1, 1}, [BUFF_DRAGONFLIGHT] = {"Dragonflight", ICON(0, 25), 1, 1},+ [BUFF_COOKIE_STORM] = {"Cookie storm", ICON(22, 6), 1, 1}, [BUFF_BUILDING_BUFF] = {"", 0, 1, 1},+ [BUFF_BUILDING_DEBUFF] = {"", 0, 1, 2}, [BUFF_SUGAR_BLESSING] = {"Sugar blessing", ICON(29, 16), 0, 0},+ [BUFF_HAGGLER_LUCK] = {"Haggler's luck", ICON(25, 11), 2, 0},+ [BUFF_HAGGLER_MISERY] = {"Haggler's misery", ICON(25, 11), 2, 0},+ [BUFF_PIXIE_LUCK] = {"Crafty pixies", ICON(26, 11), 2, 0}, [BUFF_PIXIE_MISERY] = {"Nasty goblins", ICON(26, 11), 2, 0},+ [BUFF_MAGIC_ADEPT] = {"Magic adept", ICON(29, 11), 2, 0}, [BUFF_MAGIC_INEPT] = {"Magic inept", ICON(29, 11), 2, 0},+ [BUFF_DEVASTATION] = {"Devastation", ICON(23, 18), 2, 1}, [BUFF_SUGAR_FRENZY] = {"Sugar frenzy", ICON(29, 14), 1, 0},+ [BUFF_LOAN1] = {"Loan 1", ICON(1, 33), 2, 0}, [BUFF_LOAN1_INTEREST] = {"Loan 1 (interest)", ICON(1, 33), 2, 0},+ [BUFF_LOAN2] = {"Loan 2", ICON(1, 33), 2, 0}, [BUFF_LOAN2_INTEREST] = {"Loan 2 (interest)", ICON(1, 33), 2, 0},+ [BUFF_LOAN3] = {"Loan 3", ICON(1, 33), 2, 0}, [BUFF_LOAN3_INTEREST] = {"Loan 3 (interest)", ICON(1, 33), 2, 0},+};+const char *buff_name(const Buff *b) {+ if (b->type == BUFF_BUILDING_BUFF) return building_buffs[b->building][0];+ if (b->type == BUFF_BUILDING_DEBUFF) return building_buffs[b->building][1];+ return buff_types[b->type].name;+}+int buff_icon(const Buff *b) {+ if (b->type == BUFF_BUILDING_BUFF) return ICON(building_rec(b->building)->column, 14);+ if (b->type == BUFF_BUILDING_DEBUFF) return ICON(building_rec(b->building)->column, 15);+ return buff_types[b->type].icon;+}+int buff_aura(const Buff *b) { return buff_types[b->type].aura; }++/* what a buff says it does */+void buff_desc(const Buff *b, char *out, int size) {+ char t[64], n[32];+ say_time(b->max_time, -1, t);+ switch (b->type) {+ case BUFF_FRENZY: case BUFF_ELDER_FRENZY: case BUFF_DRAGON_HARVEST: case BUFF_SUGAR_FRENZY:+ case BUFF_LOAN1: case BUFF_LOAN1_INTEREST: case BUFF_LOAN2: case BUFF_LOAN2_INTEREST: case BUFF_LOAN3:+ case BUFF_LOAN3_INTEREST:+ beautify(b->mult_cps, 2, n);+ snprintf(out, size, "Cookie production x%s for %s!", n, t);+ break;+ case BUFF_CLOT: snprintf(out, size, "Cookie production halved for %s!", t); break;+ case BUFF_EVERYTHING_MUST_GO: snprintf(out, size, "All buildings are %d%% cheaper for %s!", (int)b->power, t); break;+ case BUFF_CURSED_FINGER:+ snprintf(out, size, "Cookie production halted for %s,\nbut each click is worth %s of CpS.", t, t);+ break;+ case BUFF_CLICK_FRENZY: case BUFF_DRAGONFLIGHT:+ beautify(b->mult_click, 0, n);+ snprintf(out, size, "Clicking power x%s for %s!", n, t);+ break;+ case BUFF_COOKIE_STORM: snprintf(out, size, "Cookies everywhere!"); break;+ case BUFF_BUILDING_BUFF: case BUFF_BUILDING_DEBUFF: {+ const BuildingRec *r = building_rec(b->building);+ char amt[32], pct[32];+ beautify(S.buildings[b->building].amount, 0, amt);+ double m = b->type == BUFF_BUILDING_BUFF ? b->mult_cps : 1 / b->mult_cps;+ beautify(ceil(m * 100 - 100), 0, pct);+ snprintf(out, size, "Your %s %s are %s your CpS!\nCookie production %s%s%% %sfor %s!", amt, res_text(r->plural),+ b->type == BUFF_BUILDING_BUFF ? "boosting" : "rusting", b->type == BUFF_BUILDING_BUFF ? "+" : "", pct,+ b->type == BUFF_BUILDING_BUFF ? "" : "slower ", t);+ break;+ }+ case BUFF_SUGAR_BLESSING: snprintf(out, size, "You find 10%% more golden cookies for the next %s.", t); break;+ case BUFF_HAGGLER_LUCK: snprintf(out, size, "All upgrades are %d%% cheaper for %s!", (int)b->power, t); break;+ case BUFF_HAGGLER_MISERY: snprintf(out, size, "All upgrades are %d%% pricier for %s!", (int)b->power, t); break;+ case BUFF_PIXIE_LUCK: snprintf(out, size, "All buildings are %d%% cheaper for %s!", (int)b->power, t); break;+ case BUFF_PIXIE_MISERY: snprintf(out, size, "All buildings are %d%% pricier for %s!", (int)b->power, t); break;+ case BUFF_MAGIC_ADEPT: snprintf(out, size, "Spells backfire %d times less for %s.", (int)b->power, t); break;+ case BUFF_MAGIC_INEPT: snprintf(out, size, "Spells backfire %d times more for %s.", (int)b->power, t); break;+ case BUFF_DEVASTATION:+ snprintf(out, size, "Clicking power +%d%% for %s!", (int)floor(b->mult_click * 100 - 100), t);+ break;+ default: out[0] = 0;+ }+}++Buff *gain_buff(int type, float time, double pow_, int building) {+ if ((type == BUFF_DRAGON_HARVEST || type == BUFF_DRAGONFLIGHT) && has(U_DRAGON_FANG)) pow_ = ceil(pow_ * 1.1);+ int32_t frames = (int32_t)(time * FPS);+ Buff *b = NULL;+ for (int i = 0; i < MAX_BUFFS; i++)+ if (S.buffs[i].used && S.buffs[i].type == type &&+ (type != BUFF_BUILDING_BUFF && type != BUFF_BUILDING_DEBUFF ? true : S.buffs[i].building == building))+ b = &S.buffs[i];+ const BuffType *t = &buff_types[type];+ if (b) {+ if (t->mode == 2) b->time = frames > b->time ? frames : b->time;+ else if (t->mode == 1) b->time += frames;+ else b->time = frames;+ b->max_time = b->time;+ } else {+ for (int i = 0; i < MAX_BUFFS && !b; i++)+ if (!S.buffs[i].used) b = &S.buffs[i];+ if (!b) b = &S.buffs[0];+ memset(b, 0, sizeof *b);+ b->used = 1, b->type = (uint8_t)type, b->building = (uint8_t)building;+ b->time = b->max_time = frames;+ b->mult_cps = 1, b->mult_click = 1, b->power = pow_, b->arg1 = (float)pow_;+ switch (type) {+ case BUFF_FRENZY: case BUFF_ELDER_FRENZY: case BUFF_CLOT: case BUFF_DRAGON_HARVEST: case BUFF_SUGAR_FRENZY:+ case BUFF_BUILDING_BUFF: case BUFF_LOAN1: case BUFF_LOAN1_INTEREST: case BUFF_LOAN2: case BUFF_LOAN2_INTEREST:+ case BUFF_LOAN3: case BUFF_LOAN3_INTEREST: b->mult_cps = pow_; break;+ case BUFF_BUILDING_DEBUFF: b->mult_cps = 1 / pow_; break;+ case BUFF_CURSED_FINGER: b->mult_cps = 0; break;+ case BUFF_CLICK_FRENZY: case BUFF_DRAGONFLIGHT: case BUFF_DEVASTATION: b->mult_click = pow_; break;+ default: break;+ }+ }+ G.recalculate = true, G.store_dirty = true;+ return b;+}+void kill_buff(int type) {+ Buff *b = find_buff(type);+ if (b) b->time = 0;+}+extern void buff_died(Buff *b);+void buffs_update(void) {+ for (int i = 0; i < MAX_BUFFS; i++) {+ Buff *b = &S.buffs[i];+ if (!b->used) continue;+ b->time--;+ if (b->time <= 0) {+ buff_died(b);+ b->used = 0;+ G.recalculate = true, G.store_dirty = true;+ }+ }+}++/* ------------------------------------------------------------------ the golden cookie's timer */+static int32_t time_mod(bool wrath, double m) {+ if (has(U_LUCKY_DAY)) m /= 2;+ if (has(U_SERENDIPITY)) m /= 2;+ if (has(U_GOLDEN_GOOSE_EGG)) m *= 0.95;+ if (has(U_HEAVENLY_LUCK)) m *= 0.95;+ if (has(U_GREEN_YEAST_DIGESTIVES)) m *= 0.99;+ m *= 1 - aura_mult(AURA_ARCANE_AURA) * 0.05;+ if (has_buff(BUFF_SUGAR_BLESSING)) m *= 0.9;+ if (S.season == SEASON_EASTER && has(U_STARSPAWN)) m *= 0.98;+ else if (S.season == SEASON_HALLOWEEN && has(U_STARTERROR)) m *= 0.98;+ else if (S.season == SEASON_VALENTINES && has(U_STARLOVE)) m *= 0.98;+ else if (S.season == SEASON_FOOLS && has(U_STARTRADE)) m *= 0.95;+ m *= 1 / eff(wrath ? EFF_WRATH_FREQ : EFF_GOLDEN_FREQ);+ static const float industry[4] = {1, 1.1f, 1.06f, 1.03f}, mother[4] = {1, 1.15f, 1.1f, 1.05f};+ m *= industry[hasgod(GOD_INDUSTRY)] * mother[hasgod(GOD_MOTHER)];+ if (S.season) {+ int god = hasgod(GOD_SEASONS);+ static const float s[4] = {1, 0.97f, 0.98f, 0.99f}, f[4] = {1, 0.955f, 0.97f, 0.985f};+ m *= S.season == SEASON_FOOLS ? f[god] : s[god];+ }+ if (S.golden_chain > 0) m = 0.05;+ if (has(U_GOLD_HOARD)) m = 0.01;+ return (int32_t)ceil(FPS * 60 * m);+}+int32_t golden_min_time(void) { return time_mod(false, 5); }+int32_t golden_max_time(void) { return time_mod(false, 15); }+static int32_t reindeer_mod(double m) {+ if (has(U_REINDEER_BAKING_GROUNDS)) m /= 2;+ if (has(U_STARSNOW)) m *= 0.95;+ static const float s[4] = {1, 0.9f, 0.95f, 0.97f};+ m *= s[hasgod(GOD_SEASONS)];+ if (has(U_REINDEER_SEASON)) m = 0.01;+ return (int32_t)ceil(FPS * 60 * m);+}++void shimmers_reset(void) {+ memset(G.shimmers, 0, sizeof G.shimmers);+ G.nshimmers_golden = G.nshimmers_reindeer = 0;+ S.golden_time = 0, S.golden_spawned = 0, S.golden_chain = 0, S.golden_chain_total = 0, S.golden_last = 0;+ S.golden_min = golden_min_time(), S.golden_max = golden_max_time();+ S.reindeer_time = 0, S.reindeer_spawned = 0, S.reindeer_min = reindeer_mod(3), S.reindeer_max = reindeer_mod(6);+}++/* ------------------------------------------------------------------ a shimmer appears */+Shimmer *shimmer_new(int type, int force, bool no_count) {+ Shimmer *m = NULL;+ for (int i = 0; i < MAX_SHIMMERS && !m; i++)+ if (!G.shimmers[i].used) m = &G.shimmers[i];+ 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->spawn_lead = 0;+ if (!no_count) {+ if (type == SHIMMER_GOLDEN) G.nshimmers_golden++;+ else G.nshimmers_reindeer++;+ G.recalculate = true;+ } else+ m->pad[0] = 1; /* (not counted) */+ if (type == SHIMMER_GOLDEN) {+ int wr = 0;+ if (S.elder_wrath == 1 && rnd() < 1.0 / 3) wr = 1;+ if (S.elder_wrath == 2 && rnd() < 2.0 / 3) wr = 1;+ if (S.elder_wrath == 3 || hasgod(GOD_SCORN)) wr = 1;+ if (force == GC_STORM_DROP) wr = 0;+ m->wrath = (uint8_t)wr;+ m->x = (float)(rnd() * (LEFT_W - GC_SIZE - 8) + 4);+ m->y = (float)(rnd() * (SCREEN_H - NEWS_H - GC_SIZE - 8) + NEWS_H + 4);+ double dur = 13;+ if (has(U_LUCKY_DAY)) dur *= 2;+ if (has(U_SERENDIPITY)) dur *= 2;+ if (has(U_DECISIVE_FATE)) dur *= 1.05;+ if (has(U_LUCKY_DIGIT)) dur *= 1.01;+ if (has(U_LUCKY_NUMBER)) dur *= 1.01;+ if (has(U_LUCKY_PAYOUT)) dur *= 1.01;+ dur *= eff(wr ? EFF_WRATH_DUR : EFF_GOLDEN_DUR);+ dur *= pow(0.95, G.nshimmers_golden - 1);+ if (S.golden_chain > 0) dur = 10.0 / S.golden_chain > 2 ? 10.0 / S.golden_chain : 2;+ m->dur = (float)dur;+ m->life = m->max_life = (int32_t)ceil(FPS * dur);+ m->size_mult = 1;+ } else {+ m->x = -40;+ m->y = (float)(rnd() * (SCREEN_H - NEWS_H - 90) + NEWS_H + 40);+ double dur = 4;+ if (has(U_WEIGHTED_SLEIGHS)) dur *= 2;+ m->dur = (float)dur;+ m->life = m->max_life = (int32_t)ceil(FPS * dur);+ m->size_mult = 1;+ }+ return m;+}++static void shimmer_die(Shimmer *m) {+ if (m->spawn_lead) {+ if (m->type == SHIMMER_GOLDEN) {+ S.golden_time = 0, S.golden_spawned = 0;+ S.golden_min = golden_min_time(), S.golden_max = golden_max_time();+ } else {+ S.reindeer_time = 0, S.reindeer_spawned = 0;+ S.reindeer_min = reindeer_mod(3), S.reindeer_max = reindeer_mod(6);+ }+ }+ if (!m->pad[0]) {+ if (m->type == SHIMMER_GOLDEN && G.nshimmers_golden > 0) G.nshimmers_golden--;+ if (m->type == SHIMMER_REINDEER && G.nshimmers_reindeer > 0) G.nshimmers_reindeer--;+ G.recalculate = true;+ }+ m->used = 0;+}++static void golden_missed(Shimmer *m) {+ if (S.golden_chain > 0 && S.golden_chain_total > 0) {+ char t[64], d[96];+ cookies_str(S.golden_chain_total, 0, t);+ snprintf(d, sizeof d, "Cookie chain broken.\nYou made %s.", t);+ popup(d, m->x + GC_SIZE / 2, m->y);+ S.golden_chain = 0, S.golden_chain_total = 0;+ }+ if (m->spawn_lead) S.missed_golden_clicks++;+}++void shimmers_update(void) {+ for (int i = 0; i < MAX_SHIMMERS; i++) {+ Shimmer *m = &G.shimmers[i];+ if (!m->used) continue;+ m->life--;+ if (m->life <= 0) {+ if (m->type == SHIMMER_GOLDEN) golden_missed(m);+ shimmer_die(m);+ }+ }+ if (has_buff(BUFF_COOKIE_STORM) && rnd() < 0.5) {+ Shimmer *m = shimmer_new(SHIMMER_GOLDEN, GC_STORM_DROP, true);+ if (m) {+ m->dur = (float)ceil(rnd() * 4 + 1);+ m->life = m->max_life = (int32_t)ceil(FPS * m->dur);+ m->size_mult = (float)(rnd() * 0.75 + 0.25);+ }+ }+ /* the golden cookie: once its time has come, more likely each frame (the fifth power of how far between+ * the shortest and the longest wait) */+ if (!has(U_GOLDEN_SWITCH_OFF) && !S.golden_spawned) {+ S.golden_time++;+ double k = (double)(S.golden_time - S.golden_min) / (S.golden_max - S.golden_min);+ if (k < 0) k = 0;+ if (rnd() < pow(k, 5)) {+ Shimmer *m = shimmer_new(SHIMMER_GOLDEN, GC_NONE, false);+ if (m) m->spawn_lead = 1;+ if (has(U_DISTILLED_ESSENCE_OF_REDOUBLED_LUCK) && rnd() < 0.01) shimmer_new(SHIMMER_GOLDEN, GC_NONE, false);+ S.golden_spawned = 1;+ }+ }+ if (S.season == SEASON_CHRISTMAS && !S.reindeer_spawned) {+ S.reindeer_time++;+ double k = (double)(S.reindeer_time - S.reindeer_min) / (S.reindeer_max - S.reindeer_min);+ if (k < 0) k = 0;+ if (rnd() < pow(k, 5)) {+ Shimmer *m = shimmer_new(SHIMMER_REINDEER, GC_NONE, false);+ if (m) m->spawn_lead = 1;+ S.reindeer_spawned = 1;+ }+ }+}++int shimmer_next(void) {+ int best = -1;+ for (int i = 0; i < MAX_SHIMMERS; i++)+ if (G.shimmers[i].used && (best < 0 || G.shimmers[i].id < G.shimmers[best].id)) best = i;+ return best;+}++/* ------------------------------------------------------------------ a golden cookie is clicked */+static void golden_pop(Shimmer *m) {+ if (m->spawn_lead) {+ S.golden_clicks++, S.golden_clicks_local++;+ static const struct { uint32_t at; uint16_t a; } wins[] = {+ {1, A_GOLDEN_COOKIE}, {7, A_LUCKY_COOKIE}, {27, A_A_STROKE_OF_LUCK}, {77, A_FORTUNE}, {777, A_LEPRECHAUN},+ {7777, A_BLACK_CATS_PAW}, {27777, A_SEVEN_HORSESHOES}};+ for (unsigned i = 0; i < sizeof wins / sizeof wins[0]; i++)+ if (S.golden_clicks >= wins[i].at) win(wins[i].a);+ if (S.golden_clicks >= 7) unlock(U_LUCKY_DAY);+ if (S.golden_clicks >= 27) unlock(U_SERENDIPITY);+ if (S.golden_clicks >= 77) unlock(U_GET_LUCKY);+ if (m->life / (float)FPS > m->dur - 1) win(A_EARLY_BIRD);+ if (m->life < FPS) win(A_FADING_LUCK);+ if (m->wrath) win(A_WRATH_COOKIE);+ }+ if (force_unslot_god(GOD_ASCETICISM)) use_swap(1000000);++ int list[24], n = 0;+#define PUSH(c) (list[n++] = (c))+ if (m->wrath) PUSH(GC_CLOT), PUSH(GC_LUCKY), PUSH(GC_RUIN);+ else PUSH(GC_FRENZY), PUSH(GC_LUCKY);+ if (m->wrath && hasgod(GOD_SCORN)) PUSH(GC_CLOT), PUSH(GC_RUIN), PUSH(GC_CLOT), PUSH(GC_RUIN);+ if (m->wrath && rnd() < 0.3) PUSH(GC_BLOOD_FRENZY), PUSH(GC_CHAIN), PUSH(GC_STORM);+ else if (rnd() < 0.03 && S.cookies_earned >= 100000) PUSH(GC_CHAIN), PUSH(GC_STORM);+ if (rnd() < 0.05 && S.season == SEASON_FOOLS) PUSH(GC_EVERYTHING_MUST_GO);+ if (rnd() < 0.1 && (rnd() < 0.05 || !has_buff(BUFF_DRAGONFLIGHT))) PUSH(GC_CLICK_FRENZY);+ if (m->wrath && rnd() < 0.1) PUSH(GC_CURSED_FINGER);+ if (G.buildings_owned >= 10 && rnd() < 0.25) PUSH(GC_BUILDING_SPECIAL);+ if (can_lumps() && rnd() < 0.0005) PUSH(GC_SUGAR_LUMP);+ if ((!m->wrath && rnd() < 0.15) || rnd() < 0.05) {+ if (rnd() < aura_mult(AURA_REAPER_OF_FIELDS)) PUSH(GC_DRAGON_HARVEST);+ if (rnd() < aura_mult(AURA_DRAGONFLIGHT)) PUSH(GC_DRAGONFLIGHT);+ }+ if (S.golden_last && rnd() < 0.8) { /* 80%: another than last time */+ bool there = false;+ for (int i = 0; i < n; i++) there |= list[i] == S.golden_last;+ if (there) {+ int k = 0;+ for (int i = 0; i < n; i++)+ if (list[i] != S.golden_last) list[k++] = list[i];+ n = k;+ }+ }+ if (rnd() < 0.0001) PUSH(GC_BLAB);+#undef PUSH+ int choice = n ? list[rnd_int(n)] : GC_FRENZY;+ if (S.golden_chain > 0) choice = GC_CHAIN;+ if (m->force) S.golden_chain = 0, choice = m->force;+ if (choice != GC_CHAIN) S.golden_chain = 0;+ S.golden_last = (uint8_t)choice;++ double dur_mod = 1;+ if (has(U_GET_LUCKY)) dur_mod *= 2;+ if (has(U_LASTING_FORTUNE)) dur_mod *= 1.1;+ if (has(U_LUCKY_DIGIT)) dur_mod *= 1.01;+ if (has(U_LUCKY_NUMBER)) dur_mod *= 1.01;+ if (has(U_GREEN_YEAST_DIGESTIVES)) dur_mod *= 1.01;+ if (has(U_LUCKY_PAYOUT)) dur_mod *= 1.01;+ dur_mod *= 1 + aura_mult(AURA_EPOCH_MANIPULATOR) * 0.05;+ dur_mod *= eff(m->wrath ? EFF_WRATH_EFF_DUR : EFF_GOLDEN_EFF_DUR);+ static const float decadence[4] = {1, 1.07f, 1.05f, 1.02f};+ dur_mod *= decadence[hasgod(GOD_DECADENCE)];+ double mult = 1;+ if (m->wrath) mult *= 1 + aura_mult(AURA_UNHOLY_DOMINION) * 0.1;+ else mult *= 1 + aura_mult(AURA_ANCESTRAL_METAMORPHOSIS) * 0.1;+ if (has(U_GREEN_YEAST_DIGESTIVES)) mult *= 1.01;+ if (has(U_DRAGON_FANG)) mult *= 1.03;+ mult *= eff(m->wrath ? EFF_WRATH_GAIN : EFF_GOLDEN_GAIN);++ char pop[160] = "", t[48];+ Buff *buff = NULL;+ if (choice == GC_BUILDING_SPECIAL) {+ int cand[NB], k = 0;+ for (int b = 0; b < NB; b++)+ if (S.buildings[b].amount >= 10) cand[k++] = b;+ if (!k) choice = GC_FRENZY;+ else {+ int b = cand[rnd_int(k)];+ double p = S.buildings[b].amount / 10.0 + 1;+ float time = (float)ceil(30 * dur_mod);+ buff = gain_buff(m->wrath && rnd() < 0.3 ? BUFF_BUILDING_DEBUFF : BUFF_BUILDING_BUFF, time, p, b);+ }+ }+ switch (choice) {+ case GC_SUGAR_LUMP:+ gain_lumps(1);+ snprintf(pop, sizeof pop, "Sweet!\nFound 1 sugar lump!");+ break;+ case GC_FRENZY: buff = gain_buff(BUFF_FRENZY, (float)ceil(77 * dur_mod), 7, 0); break;+ case GC_DRAGON_HARVEST: buff = gain_buff(BUFF_DRAGON_HARVEST, (float)ceil(60 * dur_mod), 15, 0); break;+ case GC_EVERYTHING_MUST_GO: buff = gain_buff(BUFF_EVERYTHING_MUST_GO, (float)ceil(8 * dur_mod), 5, 0); break;+ case GC_LUCKY: {+ double a = S.cookies * 0.15, b = G.cookies_ps * 60 * 15;+ double moni = mult * (a < b ? a : b) + 13;+ earn(moni);+ cookies_str(moni, 0, t);+ snprintf(pop, sizeof pop, "Lucky!\n+%s!", t);+ break;+ }+ case GC_RUIN: {+ double a = S.cookies * 0.05, b = G.cookies_ps * 60 * 10;+ double moni = (a < b ? a : b) + 13;+ if (moni > S.cookies) moni = S.cookies;+ spend(moni);+ cookies_str(moni, 0, t);+ snprintf(pop, sizeof pop, "Ruin!\nLost %s!", t);+ break;+ }+ case GC_BLOOD_FRENZY: buff = gain_buff(BUFF_ELDER_FRENZY, (float)ceil(6 * dur_mod), 666, 0); break;+ case GC_CLOT: buff = gain_buff(BUFF_CLOT, (float)ceil(66 * dur_mod), 0.5, 0); break;+ case GC_CURSED_FINGER: {+ double time = ceil(10 * dur_mod);+ buff = gain_buff(BUFF_CURSED_FINGER, (float)time, G.cookies_ps * time, 0);+ break;+ }+ case GC_CLICK_FRENZY: buff = gain_buff(BUFF_CLICK_FRENZY, (float)ceil(13 * dur_mod), 777, 0); break;+ case GC_DRAGONFLIGHT:+ buff = gain_buff(BUFF_DRAGONFLIGHT, (float)ceil(10 * dur_mod), 1111, 0);+ if (rnd() < 0.8) kill_buff(BUFF_CLICK_FRENZY);+ break;+ case GC_CHAIN: {+ if (S.golden_chain == 0) S.golden_chain_total = 0;+ S.golden_chain++;+ int digit = m->wrath ? 6 : 7;+ if (S.golden_chain == 1) {+ int extra = (int)ceil(log10(S.cookies > 0 ? S.cookies : 1)) - 10;+ if (extra > 0) S.golden_chain += extra;+ }+ double a = G.cookies_ps * 60 * 60 * 6, b = S.cookies * 0.5;+ double max_payout = (a < b ? a : b) * mult;+ double v = floor(1.0 / 9 * pow(10, S.golden_chain) * digit * mult);+ double moni = v < max_payout ? v : max_payout;+ if (moni < digit) moni = digit;+ double v2 = floor(1.0 / 9 * pow(10, S.golden_chain + 1) * digit * mult);+ double next = v2 < max_payout ? v2 : max_payout;+ if (next < digit) next = digit;+ S.golden_chain_total += moni;+ cookies_str(moni, 0, t);+ if (rnd() < 0.01 || next >= max_payout) {+ char t2[48];+ S.golden_chain = 0;+ cookies_str(S.golden_chain_total, 0, t2);+ snprintf(pop, sizeof pop, "Cookie chain\n+%s!\nCookie chain over. You made %s.", t, t2);+ } else+ snprintf(pop, sizeof pop, "Cookie chain\n+%s!", t);+ earn(moni);+ break;+ }+ case GC_STORM: buff = gain_buff(BUFF_COOKIE_STORM, (float)ceil(7 * dur_mod), 7, 0); break;+ case GC_STORM_DROP: {+ double a = mult * (G.cookies_ps * 60 * floor(rnd() * 7 + 1)), b = floor(rnd() * 7 + 1);+ double moni = a > b ? a : b;+ earn(moni);+ cookies_str(moni, 0, t);+ snprintf(pop, sizeof pop, "+%s!", t);+ break;+ }+ case GC_BLAB: {+ static const char *const blab[] = {+ "Cookie crumbliness x3 for 60 seconds!", "Chocolatiness x7 for 77 seconds!",+ "Dough elasticity halved for 66 seconds!", "Golden cookie shininess doubled for 3 seconds!",+ "World economy halved for 30 seconds!", "Grandma kisses 23% stingier for 45 seconds!", "Thanks for clicking!",+ "Fooled you! This one was just a test.", "Golden cookies clicked +1!",+ "Your click has been registered. Thank you for your cooperation.", "Thanks! That hit the spot!",+ "Thank you. A team has been dispatched.", "They know.",+ "Oops. This was just a chocolate cookie with shiny aluminium foil.", "Eschaton immanentized!",+ "Oh, that tickled!", "Again.", "You've made a grave mistake.", "Chocolate chips reshuffled!",+ "Randomized chance card outcome!", "Mouse acceleration +0.03%!", "Ascension bonuses x5,000 for 0.1 seconds!",+ "Gained 1 extra!", "Sorry, better luck next time!", "I felt that.", "Nice try, but no.",+ "Wait, sorry, I wasn't ready yet.", "Yippee!", "Bones removed.", "Organs added.", "Did you just click that?",+ "Huh? Oh, there was nothing there.", "You saw nothing.", "It seems you hallucinated that golden cookie.",+ "This golden cookie was a complete fabrication.",+ "In theory there's no wrong way to click a golden cookie, but you just did that, somehow.",+ "All cookies multiplied by 999!\nAll cookies divided by 999!", "Why?"};+ snprintf(pop, sizeof pop, "%s", blab[rnd_int(sizeof blab / sizeof blab[0])]);+ break;+ }+ default: break;+ }+ if (!pop[0] && buff) snprintf(pop, sizeof pop, "%s", buff_name(buff));+ if (pop[0]) popup(pop, m->x + GC_SIZE / 2, m->y);+ drop_egg(0.9);+ shimmer_die(m);+}++static void reindeer_pop(Shimmer *m) {+ if (m->spawn_lead) S.reindeer_clicked++;+ double val = G.cookies_ps * 60;+ if (has_buff(BUFF_ELDER_FRENZY)) val *= 0.5;+ if (has_buff(BUFF_FRENZY)) val *= 0.75;+ double moni = val > 25 ? val : 25;+ if (has(U_HO_HO_HO_FLAVORED_FROSTING)) moni *= 2;+ earn(moni);+ if (has_buff(BUFF_ELDER_FRENZY)) win(A_ELDEER);+ int cookie = -1;+ double fail = 0.8;+ if (has_achiev(A_LET_IT_SNOW)) fail *= 0.8;+ if (has(U_STARSNOW)) fail *= 0.95;+ static const float sg[4] = {1, 0.9f, 0.95f, 0.97f};+ fail *= sg[hasgod(GOD_SEASONS)];+ fail = pow(fail, drop_rate_mult());+ if (rnd() > fail) {+ static const uint16_t cookies[7] = {U_CHRISTMAS_TREE_BISCUITS, U_SNOWFLAKE_BISCUITS, U_SNOWMAN_BISCUITS,+ U_HOLLY_BISCUITS, U_CANDY_CANE_BISCUITS, U_BELL_BISCUITS,+ U_PRESENT_BISCUITS};+ int c = cookies[rnd_int(7)];+ if (!has_unlocked(c) && !has(c)) unlock(c), cookie = c;+ }+ static const char *const names[] = {"Dasher", "Dancer", "Prancer", "Vixen", "Comet", "Cupid", "Donner", "Blitzen",+ "Rudolph"};+ char title[48], t[48], d[200];+ snprintf(title, sizeof title, "You found %s!", names[rnd_int(9)]);+ cookies_str(moni, 0, t);+ if (cookie >= 0)+ snprintf(d, sizeof d, "The reindeer gives you %s.\nYou are also rewarded with %s!", t,+ res_text(upgrade_rec(cookie)->name));+ else+ snprintf(d, sizeof d, "The reindeer gives you %s.", t);+ notify(title, d, ICON(12, 9), 6);+ snprintf(d, sizeof d, "+%s!", t);+ popup(d, m->x + 30, m->y);+ shimmer_die(m);+}++void shimmer_pop(Shimmer *m) {+ if (!m->used) return;+ lose_shimmering_veil(1);+ if (m->type == SHIMMER_GOLDEN) golden_pop(m);+ else reindeer_pop(m);+}diff --git a/games/cookieclicker/src/special.c b/games/cookieclicker/src/special.cnew file mode 100644index 00000000..4895e163--- /dev/null+++ b/games/cookieclicker/src/special.c@@ -0,0 +1,200 @@+/* Santa and Krumblor, the cookie dragon (the game's special tabs): Santa evolves through 15 levels+ * for cookies; the dragon's egg hatches, then trains auras for buildings sacrificed; its auras. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"++const char *const santa_levels[15] = {"Festive test tube", "Festive ornament", "Festive wreath", "Festive tree",+ "Festive present", "Festive elf fetus", "Elf toddler", "Elfling", "Young elf",+ "Bulky elf", "Nick", "Santa Claus", "Elder Santa", "True Santa", "Final Claus"};+const char *const aura_names[N_AURAS] = {+ "No aura", "Breath of Milk", "Dragon Cursor", "Elder Battalion", "Reaper of Fields", "Earth Shatterer",+ "Master of the Armory", "Fierce Hoarder", "Dragon God", "Arcane Aura", "Dragonflight", "Ancestral Metamorphosis",+ "Unholy Dominion", "Epoch Manipulator", "Mind Over Matter", "Radiant Appetite", "Dragon's Fortune", "Dragon's Curve",+ "Reality Bending", "Dragon Orbs", "Supreme Intellect", "Dragon Guts"};+const char *const aura_descs[N_AURAS] = {+ "Select an aura from those your dragon knows.", "Kittens are \x01" "5%\x02 more effective.",+ "Clicking is \x01" "5%\x02 more powerful.", "Grandmas gain \x01+1% CpS\x02 for each non-grandma building.",+ "Golden cookies may trigger a \x01" "Dragon Harvest\x02.", "Buildings sell back for \x01" "50%\x02 instead of 25%.",+ "All upgrades are \x01" "2% cheaper\x02.", "All buildings are \x01" "2% cheaper\x02.",+ "\x01+5%\x02 prestige level effect on CpS.", "Golden cookies appear \x01" "5%\x02 more often.",+ "Golden cookies may trigger a \x01" "Dragonflight\x02.", "Golden cookies give \x01" "10%\x02 more cookies.",+ "Wrath cookies give \x01" "10%\x02 more cookies.", "Golden cookie effects last \x01" "5%\x02 longer.",+ "Random drops are \x01" "25% more common\x02.", "All cookie production \x01multiplied by 2\x02.",+ "\x01+123% CpS\x02 per golden cookie on-screen, multiplicative.",+ "\x01+5%\x02 sugar lump growth. Sugar lumps are \x01twice as likely\x02 to be unusual.",+ "\x01One tenth\x02 of every other dragon aura, \x01" "combined\x02.",+ "With no buffs and no golden cookies on screen, selling your most powerful building has \x01" "10% chance to "+ "summon one\x02.",+ "Confers various powers to your minigames while active.\nSee the bottom of each minigame for more details.",+ "You can attract \x01" "2 more wrinklers\x02.\nWrinklers digest \x01" "20% more cookies\x02.\nWrinklers explode into "+ "\x01" "20% more cookies\x02."};+const int16_t aura_icons[N_AURAS] = {ICON(0, 7), ICON(18, 25), ICON(0, 25), ICON(1, 25), ICON(2, 25), ICON(3, 25),+ ICON(4, 25), ICON(15, 25), ICON(16, 25), ICON(17, 25), ICON(5, 25), ICON(6, 25),+ ICON(7, 25), ICON(8, 25), ICON(13, 25), ICON(14, 25), ICON(19, 25), ICON(20, 25),+ ICON(32, 25), ICON(33, 25), ICON(34, 25), ICON(35, 25)};+#define DRAGON_LEVELS 28+int dragon_level_count(void) { return DRAGON_LEVELS; }++float dragon_aura_mult(int aura) {+ float n = 0;+ if (S.dragon_aura == aura || S.dragon_aura2 == aura) n = 1;+ if ((S.dragon_aura == AURA_REALITY_BENDING || S.dragon_aura2 == AURA_REALITY_BENDING) && S.dragon_level >= aura + 4)+ n += 0.1f;+ return n;+}++/* the dragon's name and its pictures' frame at each level */+const char *dragon_name(void) {+ int l = S.dragon_level;+ return l < 3 ? "Dragon egg" : l == 3 ? "Shivering dragon egg" : l < 8 ? "Krumblor, cookie hatchling"+ : "Krumblor, cookie dragon";+}+int dragon_frame(void) {+ int l = S.dragon_level;+ return l < 4 ? l : l < 8 ? 4 : l < 25 ? 5 : l == 25 ? 6 : l == 26 ? 7 : 8;+}+/* what the next level does and costs; whether it can be paid */+void dragon_action(char *action, int asize, char *cost, int csize, bool *can) {+ int l = S.dragon_level;+ *can = false;+ cost[0] = 0;+ if (l < 4) {+ double c = 1000000.0 * (1 << l);+ snprintf(action, asize, l < 3 ? "Chip it" : "Hatch it");+ cookies_str(c, 0, cost);+ *can = S.cookies >= c;+ } else if (l < 25) {+ snprintf(action, asize, "Train %s\nAura: %s", aura_names[l - 3], aura_descs[l - 3]);+ if (l == 4) {+ cookies_str(16000000, 0, cost);+ *can = S.cookies >= 16000000;+ } else {+ int b = l - 5;+ snprintf(cost, csize, "100 %s", res_text(building_rec(b)->plural));+ *can = S.buildings[b].amount >= 100;+ }+ } else if (l == 25) {+ snprintf(action, asize, "Bake dragon cookie\nDelicious!");+ snprintf(cost, csize, "50 of every building");+ *can = true;+ for (int b = 0; b < NB; b++)+ if (S.buildings[b].amount < 50) *can = false;+ } else if (l == 26) {+ snprintf(action, asize, "Train secondary aura\nLets you use two dragon auras simultaneously");+ snprintf(cost, csize, "200 of every building");+ *can = true;+ for (int b = 0; b < NB; b++)+ if (S.buildings[b].amount < 200) *can = false;+ } else+ snprintf(action, asize, "Your dragon is fully trained.");+}++static void sacrifice(int b, int n) {+ Building *m = &S.buildings[b];+ for (int i = 0; i < n && m->amount > 0; i++) m->amount--, G.buildings_owned--;+ G.recalculate = true, G.store_dirty = true;+}++void upgrade_dragon(void) {+ char a[200], c[64];+ bool can;+ dragon_action(a, sizeof a, c, sizeof c, &can);+ int l = S.dragon_level;+ if (l >= DRAGON_LEVELS - 1 || !can) return;+ if (l < 5) spend(1000000.0 * (1 << l));+ else if (l < 25) sacrifice(l - 5, 100);+ else if (l == 25) {+ for (int b = 0; b < NB; b++) sacrifice(b, 50);+ unlock(U_DRAGON_COOKIE);+ } else if (l == 26)+ for (int b = 0; b < NB; b++) sacrifice(b, 200);+ S.dragon_level = (uint8_t)((l + 1) % DRAGON_LEVELS);+ if (S.dragon_level >= DRAGON_LEVELS - 1) win(A_HERE_BE_DRAGON);+ G.recalculate = true, G.upgrades_dirty = true;+}++/* choosing an aura: free with no buildings, else the most expensive building owned goes */+void set_dragon_aura(int slot, int aura) {+ int current = slot ? S.dragon_aura2 : S.dragon_aura;+ if (aura == current) return;+ int highest = -1;+ for (int b = 0; b < NB; b++)+ if (S.buildings[b].amount > 0) highest = b;+ if (highest >= 0) sacrifice(highest, 1);+ if (slot) S.dragon_aura2 = (uint8_t)aura;+ else S.dragon_aura = (uint8_t)aura;+ G.recalculate = true;+}++/* petting the dragon (Pet the dragon): at level 8 and up, one chance in 20 of a drop, the one for the+ * time (here: for the play time's minute) */+void pet_dragon(void) {+ if (S.dragon_level < 4 || !has(U_PET_THE_DRAGON)) return;+ if (S.dragon_level >= 8 && rnd() < 1.0 / 20) {+ static const uint16_t drops[4] = {U_DRAGON_SCALE, U_DRAGON_CLAW, U_DRAGON_FANG, U_DRAGON_TEDDY_BEAR};+ int minute = (int)(S.play_time / 60000) % 60;+ int d = drops[(minute * 4 / 60 + S.bakery_name1) % 4];+ if (!has(d) && !has_unlocked(d)) {+ unlock(d);+ notify(res_text(upgrade_rec(d)->name), "\x01Your dragon dropped something!\x02", upgrade_rec(d)->icon, 0);+ }+ }+}++/* Santa evolves */+void upgrade_santa(void) {+ double moni = pow(S.santa_level + 1, S.santa_level + 1);+ if (S.cookies <= moni || S.santa_level >= 14) return;+ spend(moni);+ S.santa_level = (uint8_t)((S.santa_level + 1) % 15);+ if (S.santa_level == 14) {+ unlock(U_SANTAS_DOMINION);+ char t[96];+ snprintf(t, sizeof t, "You are granted %s.", res_text(upgrade_rec(U_SANTAS_DOMINION)->name));+ notify(t, "", upgrade_rec(U_SANTAS_DOMINION)->icon, 0);+ }+ int cand[N_SANTA_DROPS], n = 0;+ for (int i = 0; i < N_SANTA_DROPS; i++)+ if (!has_unlocked(LIST(SANTA_DROPS)[i])) cand[n++] = LIST(SANTA_DROPS)[i];+ if (n) {+ int d = cand[rnd_int(n)];+ unlock(d);+ char t[96];+ snprintf(t, sizeof t, "You find a present which contains...\n\x01%s\x02!", res_text(upgrade_rec(d)->name));+ notify("Found a present!", t, upgrade_rec(d)->icon, 0);+ }+ if (S.santa_level >= 6) win(A_COMING_TO_TOWN);+ if (S.santa_level >= 14) win(A_ALL_HAIL_SANTA);+ G.recalculate = true, G.upgrades_dirty = true;+}++void update_special(void) {+ extern void reincarnate_logic(void);+ reincarnate_logic();+}++/* selling: Godzamok's Devastation, the Dragon Orbs */+void building_sold(int b, int sold) {+ int god = hasgod(GOD_RUIN);+ if (god) {+ static const float k[4] = {0, 0.01f, 0.005f, 0.0025f};+ Buff *old = find_buff(BUFF_DEVASTATION);+ if (old) old->mult_click += sold * k[god];+ else gain_buff(BUFF_DEVASTATION, 10, 1 + sold * k[god], 0);+ }+ if (G.nshimmers_golden <= 0 && aura_mult(AURA_DRAGON_ORBS) > 0) {+ int highest = -1;+ for (int i = 0; i < NB; i++)+ if (S.buildings[i].amount > 0) highest = i;+ if ((highest < 0 || highest <= b) && rnd() < aura_mult(AURA_DRAGON_ORBS) * 0.1) {+ int buffs = 0;+ for (int i = 0; i < MAX_BUFFS; i++) buffs += S.buffs[i].used;+ if (!buffs) {+ shimmer_new(SHIMMER_GOLDEN, GC_NONE, false);+ notify("Dragon Orbs!", "Wish granted. Golden cookie spawned.", ICON(33, 25), 0);+ }+ }+ }+}diff --git a/games/cookieclicker/src/text.c b/games/cookieclicker/src/text.cnew file mode 100644index 00000000..d5febc24--- /dev/null+++ b/games/cookieclicker/src/text.c@@ -0,0 +1,56 @@+/* The game's texts as they are shown: every number in them written again the way numbers are+ * (the game's BeautifyInText), and the store's descriptions put together. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"++/* src to dst (size bytes), each run of digits (and commas) written by beautify() */+void text_beautify(const char *src, char *dst, int size) {+ int o = 0;+ while (*src && o < size - 1) {+ if (*src >= '0' && *src <= '9') {+ double v = 0;+ while ((*src >= '0' && *src <= '9') || *src == ',') {+ if (*src != ',') v = v * 10 + (*src - '0');+ src++;+ }+ char t[64];+ beautify(v, 0, t);+ for (char *c = t; *c && o < size - 1; c++) dst[o++] = *c;+ } else if (*src == 6) /* (keeps two numbers apart: 0.0<span></span>2) */+ src++;+ else+ dst[o++] = *src++;+ }+ dst[o] = 0;+}++/* an upgrade's description as the store's tooltip shows it (with what some of them add) */+void upgrade_description(int u, char *out, int size) {+ char raw[1024];+ int n = 0;+ raw[0] = 0;+ if (u == U_ELDER_PLEDGE) {+ if (S.pledges == 0) n += snprintf(raw + n, sizeof raw - n, "You haven't pledged to the elders yet.\x05");+ else n += snprintf(raw + n, sizeof raw - n, "You've pledged to the elders \x01%u times\x02.\x05", S.pledges);+ }+ const UpgradeRec *r = upgrade_rec(u);+ if (r->tier < N_TIERS && r->building >= 0 && r->tier != TIER_FORTUNE && r->tier != TIER_SYNERGY1 &&+ r->tier != TIER_SYNERGY2 && S.ascension_mode != 1) {+ uint16_t un = building_links(r->building)->unshackle, tu = LIST(TIER_UNSHACKLE)[r->tier];+ if (un != NONE && has(un) && tu != NONE && has(tu))+ n += snprintf(raw + n, sizeof raw - n, "Unshackled! \x01+%d%%\x02 extra production.\x05",+ (int)round((r->building == 1 ? 0.5 : (20 - r->building) * 0.1) * 100));+ }+ if (u == U_CENTURY_EGG) {+ double day = floor((S.play_time - S.start_date) / 1000 / 10) * 10 / 60 / 60 / 24;+ if (day > 100) day = 100;+ double k = (1 - pow(1 - day / 100, 3)) * 0.1;+ char t[32];+ beautify(k * 100, 1, t);+ n += snprintf(raw + n, sizeof raw - n, "Current boost: \x01+%s%%\x02\x05", t);+ }+ snprintf(raw + n, sizeof raw - n, "%s", res_text(r->desc));+ text_beautify(raw, out, size);+}diff --git a/games/cookieclicker/src/tooltip.c b/games/cookieclicker/src/tooltip.cnew file mode 100644index 00000000..97a13399--- /dev/null+++ b/games/cookieclicker/src/tooltip.c@@ -0,0 +1,118 @@+/* The game's crate tooltips (Game.crateTooltip): an upgrade's or an achievement's icon, price, name+ * and tags, then its description and its quote. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "ui.h"++extern void upgrade_description(int u, char *out, int size);+extern void text_beautify(const char *src, char *dst, int size);+extern int upgrade_lumps(int u);++void tip_line(int x, int y, int w) {+ gfx_hgrad(x, y, w / 2, 1, BLACK, 0, 110);+ gfx_hgrad(x + w / 2, y, w - w / 2, 1, BLACK, 110, 0);+ gfx_hgrad(x, y + 1, w / 2, 1, WHITE, 0, 26);+ gfx_hgrad(x + w / 2, y + 1, w - w / 2, 1, WHITE, 26, 0);+}++int tip_tag(int x, int y, const char *s, uint16_t bg) {+ int w = gfx_text_width(F_SMALL, s) + 6;+ gfx_round_rect(x, y, w, 10, 2, bg, 220);+ gfx_text(F_SMALL, x + 3, y + 8, s, BLACK, 256);+ return w + 2;+}++static const ParaStyle PS_NAME = {F_NAME, F_NAME, F_NAME, WHITE, WHITE, WHITE, 12, 0};++int crate_tip(int type, int id, int context, int x, int y, int w, bool draw) {+ char buf[1400];+ int yy = y;+ const char *tags[4];+ uint16_t colors[4];+ int ntags = 0;+ bool mysterious = false;+ int icon;+ const char *name, *quote;+ int price_w = 0;+ if (type == 0) {+ const UpgradeRec *r = upgrade_rec(id);+ bool bought = bit_get(S.upgrades_bought, id);+ icon = r->icon, name = res_text(r->name), quote = res_text(r->quote);+ if (r->pool == POOL_PRESTIGE) tags[ntags] = "Heavenly", colors[ntags++] = HEX(0xefa438);+ else if (r->pool == POOL_TECH) tags[ntags] = "Tech", colors[ntags++] = HEX(0x36a4ff);+ else if (r->pool == POOL_COOKIE) tags[ntags] = "Cookie", colors[ntags++] = WHITE;+ else if (r->pool == POOL_TOGGLE) tags[ntags] = "Switch", colors[ntags++] = WHITE;+ else tags[ntags] = "Upgrade", colors[ntags++] = WHITE;+ if (bit_get(S.upgrades_vaulted, id)) tags[ntags] = "Vaulted", colors[ntags++] = HEX(0x4e7566);+ if (bought) tags[ntags] = r->pool == POOL_TECH ? "Researched" : r->kitten ? "Purrchased" : "Purchased",+ colors[ntags++] = WHITE;+ /* the price */+ int lumps = upgrade_lumps(id);+ double cost = r->pool == POOL_PRESTIGE ? r->price : upgrade_price(id);+ if (!(bought && context == CTX_STORE) && (lumps || cost > 0)) {+ char t[48];+ if (lumps) snprintf(t, sizeof t, "%d", lumps);+ else beautify(round(cost), 0, t);+ bool can = r->pool == POOL_PRESTIGE ? bought || S.heavenly_chips >= cost+ : context == CTX_STORE ? upgrade_can_buy(id)+ : true;+ price_w = gfx_text_width(F_SMALL, t) + 12;+ if (draw) {+ int im = lumps ? IM_LUMP_MONEY : r->pool == POOL_PRESTIGE ? IM_HEAVENLY_MONEY : IM_MONEY;+ gfx_image(im, x + w - price_w, yy, 256);+ gfx_text_outline(F_SMALL, x + w - price_w + 12, yy + 8, t,+ can ? r->pool == POOL_PRESTIGE ? HEX(0x99dfff) : RGB(102, 255, 102) : RGB(255, 102, 102), 256);+ }+ }+ upgrade_description(id, buf, sizeof buf);+ } else {+ const AchievRec *r = achiev_rec(id);+ bool won = has_achiev(id);+ icon = r->icon, name = res_text(r->name), quote = res_text(r->quote);+ if (r->pool == APOOL_SHADOW) tags[ntags] = "Shadow Achievement", colors[ntags++] = HEX(0x9700cf);+ else tags[ntags] = "Achievement", colors[ntags++] = WHITE;+ tags[ntags] = won ? "Unlocked" : "Locked", colors[ntags++] = WHITE;+ mysterious = !won;+ text_beautify(res_text(r->desc), buf, sizeof buf);+ }+ if (mysterious) icon = ICON(0, 7), name = "???", quote = "", snprintf(buf, sizeof buf, "???");+ if (draw) gfx_icon(icon, x, yy, 256);+ int nw = w - 27 - price_w - 2;+ int nh = gfx_para(&PS_NAME, x + 27, yy, nw, name, false);+ if (draw) gfx_para(&PS_NAME, x + 27, yy, nw, name, true);+ int ty = yy + (nh > 12 ? nh : 12) + 1;+ if (draw) {+ int tx = x + 27;+ for (int i = 0; i < ntags; i++) tx += tip_tag(tx, ty, tags[i], colors[i]);+ }+ yy = ty + 12;+ if (yy < y + 26) yy = y + 26;+ if (draw) tip_line(x, yy, w);+ yy += 4;+ yy += gfx_para(&PS_TIP, x, yy, w, buf, draw) + 2;+ if (type == 0 && id == U_ELDER_PLEDGE && bit_get(S.upgrades_bought, id) && context == CTX_STORE) {+ char t[64], line[128];+ say_time(S.pledge_t, -1, t);+ snprintf(line, sizeof line, "Time remaining until pledge runs out:\n\x01%s\x02", t);+ yy += gfx_para(&PS_TIP, x, yy + 2, w, line, draw) + 4;+ }+ if (quote[0]) {+ char q[600];+ snprintf(q, sizeof q, CH_LQUOTE "%s" CH_RQUOTE, quote);+ ParaStyle qs = PS_QUOTE;+ qs.align = 1;+ yy += gfx_para(&qs, x + 6, yy + 3, w - 12, q, draw) + 5;+ }+ if (context == CTX_STORE && type == 0) {+ const UpgradeRec *r = upgrade_rec(id);+ const char *tip = r->pool == POOL_TOGGLE ? "Press EXE to toggle." : r->pool == POOL_TECH ? "Press EXE to research."+ : r->kitten ? "Press EXE to purrchase." : "Press EXE to purchase.";+ if (draw) {+ tip_line(x, yy, w);+ gfx_text_center(F_SMALL, x + w / 2, yy + 11, tip, HEX(0x999999), 256);+ }+ yy += 14;+ }+ return yy - y;+}diff --git a/games/cookieclicker/src/ui.c b/games/cookieclicker/src/ui.cnew file mode 100644index 00000000..d6834184--- /dev/null+++ b/games/cookieclicker/src/ui.c@@ -0,0 +1,409 @@+/* The screen and the keys: what each key does where, the store's scrolling and its tooltip, the+ * news ticker at the top (with the sugar lump at its left, as the game has it), and the prompts+ * (the game's "are you sure?" boxes). */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "ui.h"++Ui U;+extern void click_lump(void);+extern bool can_lumps(void);+extern void lump_icons(int *icon, int *icon2, float *opacity);+extern void wrinkler_hit(void);+extern void news_next(char *out, int size);+extern void menus_keys(uint32_t pressed);+extern void rows_keys(uint32_t pressed);+extern void ascend_keys(uint32_t pressed);+extern bool level_up(int b);+extern void ascend_start(void);+extern void game_save(void);++#define TIP_TIME (FPS * 6)++void ui_init(void) {+ memset(&U, 0, sizeof U);+ U.view = VIEW_STORE;+ U.sec = SEC_BUILDINGS;+ U.prompt_sel = 0;+ news_next(U.news[0], sizeof U.news[0]);+ U.news_t = FPS * 2;+ if (!S.seen_keys) U.overlay = OV_KEYS;+ ui_store_layout();+}++/* ------------------------------------------------------------------ prompts */+void prompt_open(int kind, int arg) {+ U.prompt_kind = kind, U.prompt_arg = arg, U.prompt_sel = 0;+ U.overlay = OV_PROMPT;+}++static void prompt_answer(bool yes) {+ int kind = U.prompt_kind, arg = U.prompt_arg;+ U.overlay = OV_NONE;+ if (!yes) return;+ if (kind == PROMPT_UPGRADE) upgrade_buy(arg, true);+ else if (kind == PROMPT_ASCEND) ascend_start();+ else if (kind == PROMPT_LEVEL) level_up(arg);+ else if (kind == PROMPT_SELL_ALL) building_sell(arg, -1);+ else if (kind == PROMPT_WIPE) {+ extern void game_wipe(void);+ game_wipe();+ } else if (kind == PROMPT_REINCARNATE) {+ extern void reincarnate(int mode);+ reincarnate(arg);+ }+ G.store_dirty = true;+}++/* what a prompt says, its title, and its two answers */+void prompt_text(char *title, int ts, char *body, int bs, const char **yes, const char **no) {+ int arg = U.prompt_arg;+ *yes = "Yes", *no = "No";+ switch (U.prompt_kind) {+ case PROMPT_UPGRADE: {+ const UpgradeRec *r = upgrade_rec(arg);+ snprintf(title, ts, "%s", res_text(r->name));+ if (arg == U_ELDER_COVENANT || arg == U_REVOKE_ELDER_COVENANT || arg == U_ELDER_PLEDGE)+ snprintf(body, bs, "Are you sure you want to buy this?");+ else if (arg == U_ONE_MIND)+ snprintf(body, bs, "\x01Warning:\x02 purchasing this will have unexpected, and potentially undesirable "+ "results!\nIt's all downhill from here. You have been warned!\nPurchase anyway?");+ else if (arg == U_COMMUNAL_BRAINSWEEP || arg == U_ELDER_PACT)+ snprintf(body, bs, "\x01Warning:\x02 this will awaken the elders further.\nPurchase anyway?");+ else+ snprintf(body, bs, "Are you sure you want to buy this?");+ *yes = "Purchase";+ break;+ }+ case PROMPT_ASCEND: {+ extern double how_much_prestige(double cookies);+ char a[48];+ double gain = floor(how_much_prestige(S.cookies_reset + S.cookies_earned)) - S.prestige;+ beautify(gain > 0 ? gain : 0, 0, a);+ snprintf(title, ts, "Ascend");+ snprintf(body, bs,+ "Do you REALLY want to ascend?\nYou will lose your progress and start over from scratch.\nAll your "+ "cookies will be converted into prestige and heavenly chips.\nYou will keep your achievements.\x05"+ "Ascending now gives \x01%s prestige level%s\x02.",+ a, gain == 1 ? "" : "s");+ *yes = "Ascend";+ break;+ }+ case PROMPT_LEVEL: {+ const BuildingRec *r = building_rec(arg);+ int lvl = S.buildings[arg].level;+ snprintf(title, ts, "Level up %s", res_text(r->plural));+ snprintf(body, bs, "Level up your %s for \x01%d sugar lump%s\x02?\nEach level gives \x01+1%% CpS\x02 to them%s.",+ res_text(r->plural), lvl + 1, lvl ? "s" : "",+ arg == B_FARM || arg == B_TEMPLE || arg == B_WIZARD_TOWER || arg == B_BANK+ ? ", and the first unlocks their minigame" : "");+ *yes = "Level up";+ break;+ }+ case PROMPT_SELL_ALL:+ snprintf(title, ts, "Sell all");+ snprintf(body, bs, "Do you really want to sell your %d %s?", S.buildings[arg].amount,+ res_text(building_rec(arg)->plural));+ *yes = "Sell";+ break;+ case PROMPT_WIPE:+ snprintf(title, ts, "Wipe save");+ snprintf(body, bs, "Do you REALLY want to wipe your save?\nYou will lose your progress, your achievements, "+ "and your heavenly chips!");+ *yes = "Wipe";+ break;+ case PROMPT_REINCARNATE:+ snprintf(title, ts, "Reincarnate");+ snprintf(body, bs, arg == 1 ? "Are you ready to return to the mortal world?\nYou will be \x01Born again\x02: "+ "your heavenly upgrades and prestige will not count this run."+ : "Are you ready to return to the mortal world?");+ *yes = "Reincarnate";+ break;+ default:+ title[0] = body[0] = 0;+ }+}++void draw_prompt(void) {+ char title[96], body[600];+ const char *yes, *no;+ prompt_text(title, sizeof title, body, sizeof body, &yes, &no);+ int w = 236, x = (SCREEN_W - w) / 2, pad = 8;+ ParaStyle st = PS_TIP;+ st.align = 1;+ int bh = gfx_para(&st, x + pad, 0, w - 2 * pad, body, false);+ int h = pad + 18 + bh + 8 + 18 + pad;+ int y = (SCREEN_H - h) / 2;+ if (!gfx_visible(x, y, w, h)) return;+ gfx_fill_alpha(0, 0, SCREEN_W, SCREEN_H, BLACK, 100);+ draw_frame_box(x, y, w, h);+ gfx_text_outline_center(F_TITLE, SCREEN_W / 2, y + pad + 11, title, WHITE, 256);+ gfx_para(&st, x + pad, y + pad + 18, w - 2 * pad, body, true);+ int by = y + h - pad - 16;+ const char *opts[2] = {yes, no};+ for (int i = 0; i < 2; i++) {+ int bw = 80, bx = SCREEN_W / 2 + (i ? 6 : -6 - bw);+ bool on = U.prompt_sel == i;+ gfx_round_rect(bx, by, bw, 16, 3, on ? RGB(255, 255, 255) : BLACK, on ? 60 : 120);+ gfx_rect(bx, by, bw, 16, on ? WHITE : RGB(120, 120, 120), on ? 256 : 160);+ gfx_text_center(F_NAME_SMALL, bx + bw / 2, by + 12, opts[i], on ? WHITE : RGB(200, 200, 200), 256);+ }+}++/* ------------------------------------------------------------------ the news */+#define NEWS_X 22+void ui_news_next(void) {+ U.news_cur ^= 1;+ news_next(U.news[U.news_cur], sizeof U.news[0]);+ U.news_fade = FPS / 2;+ U.news_t = 0;+}++static int news_lines(const char *s, char lines[2][200], int w) {+ /* wrapped in two lines at most; 0 if it doesn't fit */+ int n = (int)strlen(s), start = 0, k = 0;+ while (start < n) {+ if (k == 2) return 0;+ int end = start, last_space = -1;+ while (end < n && gfx_text_n_width(F_SMALL, s + start, end - start + 1) <= w) {+ if (s[end] == ' ') last_space = end;+ end++;+ }+ if (end < n && last_space > start) end = last_space;+ memcpy(lines[k], s + start, (size_t)(end - start));+ lines[k][end - start] = 0;+ k++;+ start = end;+ while (start < n && s[start] == ' ') start++;+ }+ return k;+}++static void news_text(const char *s, int alpha, int dy) {+ char lines[2][200];+ int w = SCREEN_W - NEWS_X - 6;+ int n = news_lines(s, lines, w);+ uint16_t c = RGB(255, 255, 255);+ if (n == 1) gfx_text_outline_center(F_SMALL, NEWS_X + w / 2 + 2, 13 + dy, lines[0], c, alpha);+ else if (n == 2) {+ gfx_text_outline_center(F_SMALL, NEWS_X + w / 2 + 2, 9 + dy, lines[0], c, alpha);+ gfx_text_outline_center(F_SMALL, NEWS_X + w / 2 + 2, 18 + dy, lines[1], c, alpha);+ } else { /* too long: it goes by */+ int tw = gfx_text_width(F_SMALL, s);+ int x = SCREEN_W - (int)(U.news_t * 1.2f) % (tw + SCREEN_W - NEWS_X);+ gfx_clip(NEWS_X, 0, SCREEN_W - NEWS_X, NEWS_H);+ gfx_text_outline(F_SMALL, x, 13 + dy, s, c, alpha);+ gfx_unclip();+ }+}++void draw_news(void) {+ if (!gfx_visible(0, 0, SCREEN_W, NEWS_H)) return;+ gfx_pattern(IM_DARK_NOISE, 0, 0, SCREEN_W, NEWS_H, 128, 128, 0, 0, 256);+ gfx_vgrad(0, 0, SCREEN_W, NEWS_H, BLACK, 140, 60);+ for (int x = 0; x < SCREEN_W; x += 128) gfx_image(IM_PANEL_H, x, NEWS_H - 3, 256);+ if (U.news_fade > 0) {+ float k = (float)U.news_fade / (FPS / 2);+ news_text(U.news[U.news_cur ^ 1], (int)(k * 256), (int)((1 - k) * -8));+ news_text(U.news[U.news_cur], (int)((1 - k) * 256), (int)(k * 8));+ } else+ news_text(U.news[U.news_cur], 256, 0);+ /* the sugar lump */+ if (can_lumps()) {+ int icon, icon2;+ float o;+ lump_icons(&icon, &icon2, &o);+ gfx_icon_scaled(icon, 1, 0, 18, 256);+ if (o > 0 && o < 1) gfx_icon_scaled(icon2, 1, 0, 18, (int)(o * 256));+ char t[16];+ snprintf(t, sizeof t, "%.0f", S.lumps);+ gfx_text_outline_center(F_SMALL, 10, NEWS_H - 2, t, WHITE, 256);+ }+}++/* ------------------------------------------------------------------ the keys */+static uint32_t repeat_held;+static int repeat_t;++static void store_buy(void) {+ int u = store_selected_upgrade(), b = store_selected_building();+ if (u >= 0) {+ if (bit_get(S.upgrades_bought, u) && upgrade_rec(u)->pool != POOL_TOGGLE) return;+ if (upgrade_needs_confirm(u) && upgrade_can_buy(u)) prompt_open(PROMPT_UPGRADE, u);+ else upgrade_buy(u, false);+ } else if (b >= 0) {+ if (G.buy_mode == 1) building_buy(b, G.buy_bulk);+ else if (G.buy_bulk == -1 && S.buildings[b].amount > 0) prompt_open(PROMPT_SELL_ALL, b);+ else building_sell(b, G.buy_bulk);+ }+ G.store_dirty = true;+}++static void scroll_to_selection(void) {+ extern int store_selected_y(int *h);+ int h, y = store_selected_y(&h);+ extern int store_content_h(void);+ int view = SCREEN_H - STORE_TOP;+ float t = U.scroll_t;+ if (y - 4 < t) t = (float)(y - 4);+ if (y + h + 4 > t + view) t = (float)(y + h + 4 - view);+ if (U.sec == SEC_BUILDINGS && U.idx == 0) {+ /* the upgrades above stay in sight while the first buildings are chosen */+ extern int store_buildings_top(void);+ if (store_buildings_top() < view - PRODUCT_H * 2) t = 0;+ }+ int max = store_content_h() - view;+ if (t > max) t = (float)max;+ if (t < 0) t = 0;+ U.scroll_t = t;+}++void ui_keys(uint32_t pressed, uint32_t held) {+ /* the arrows repeat while held */+ uint32_t arrows = held & (K_LEFT | K_RIGHT | K_UP | K_DOWN);+ if (arrows && arrows == repeat_held) {+ if (++repeat_t >= 9 && (repeat_t - 9) % 3 == 0) pressed |= arrows;+ } else+ repeat_t = 0;+ repeat_held = arrows;++ if (U.overlay == OV_PROMPT) {+ if (pressed & (K_LEFT | K_RIGHT | K_UP | K_DOWN)) U.prompt_sel ^= 1;+ if (pressed & (K_OK | K_EXE)) prompt_answer(U.prompt_sel == 0);+ else if (pressed & K_BACK) prompt_answer(false);+ return;+ }+ if (G.on_ascend || G.ascend_timer > 0) {+ if (G.on_ascend) ascend_keys(pressed);+ return;+ }+ if (U.overlay != OV_NONE) {+ menus_keys(pressed);+ return;+ }+ /* the big cookie, whatever else is shown */+ if (pressed & K_OK) {+ click_cookie();+ U.tip_t = 0;+ }+ G.big_state = (held & K_OK) ? 1 : G.click_t < FPS / 3 ? 2 : 0;+ if (pressed & K_SHIFT) {+ int i = shimmer_next();+ if (i >= 0) shimmer_pop(&G.shimmers[i]);+ }+ if (pressed & K_VAR) wrinkler_hit();+ if (pressed & K_XNT) click_lump();+ if (pressed & K_DEL) { /* the notes, oldest first */+ for (int i = MAX_NOTES - 1; i >= 0; i--)+ if (G.notes[i].title[0]) {+ G.notes[i].title[0] = 0;+ break;+ }+ }+ if (pressed & K_BACK && !(U.view == VIEW_ROWS && S.on_minigame)) {+ U.overlay = OV_MENU, U.menu_sel = 0, U.from_menu = false;+ return;+ }+ if (pressed & K_TOOLBOX) {+ U.overlay = OV_STATS, U.list_sel = 0, U.list_top = 0, U.from_menu = false;+ return;+ }+ if (pressed & K_ALPHA) {+ U.view = U.view == VIEW_STORE ? VIEW_ROWS : VIEW_STORE;+ if (U.view == VIEW_STORE) S.on_minigame = 0;+ U.tip_t = 0;+ return;+ }+ if (pressed & K_DIV) {+ G.buy_mode = -G.buy_mode;+ if (G.buy_mode == 1 && G.buy_bulk == -1) G.buy_bulk = 100;+ G.store_dirty = true;+ }+ if (pressed & K_MUL) {+ G.buy_bulk = G.buy_bulk == 1 ? 10 : G.buy_bulk == 10 ? 100 : G.buy_bulk == 100 && G.buy_mode == -1 ? -1 : 1;+ G.store_dirty = true;+ }+ if (U.view == VIEW_ROWS) {+ rows_keys(pressed);+ return;+ }+ if (pressed & (K_LEFT | K_RIGHT | K_UP | K_DOWN)) {+ 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;+ scroll_to_selection();+ }+ if (pressed & K_EXE) {+ store_buy();+ U.tip_t = TIP_TIME;+ ui_store_layout();+ scroll_to_selection();+ }+}++/* ------------------------------------------------------------------ a frame */+extern int minigame_tip(int b, int x, int y, int w, bool draw);+/* the tooltip of what the minigame's panel has chosen, over the left column */+static void draw_minigame_tip(void) {+ if (U.view != VIEW_ROWS || !S.on_minigame || U.tip_t <= 0 || U.overlay) return;+ int b = S.on_minigame - 1, w = LEFT_W + 6, x = 1, pad = 5;+ int h = minigame_tip(b, x + pad, 0, w - 2 * pad, false);+ if (h <= 0) return;+ h += 2 * pad;+ int y = NEWS_H + 30;+ if (y + h > SCREEN_H - 2) y = SCREEN_H - 2 - h;+ if (!gfx_visible(x, y, w, h)) return;+ draw_frame_box(x, y, w, h);+ minigame_tip(b, x + pad, y + pad, w - 2 * pad, true);+}++static void draw_all(void) {+ if (G.on_ascend) {+ draw_ascend();+ if (U.overlay == OV_PROMPT) draw_prompt();+ return;+ }+ draw_news();+ draw_left();+ if (U.view == VIEW_STORE) draw_store();+ else draw_rows();+ if (G.ascend_timer > 0) { /* (all but the cookie fades to black) */+ int a = G.ascend_timer * 256 / FPS;+ a = a > 256 ? 256 : a;+ gfx_fill_alpha(LEFT_W, NEWS_H, SCREEN_W - LEFT_W, SCREEN_H - NEWS_H, BLACK, a);+ gfx_fill_alpha(0, 0, SCREEN_W, NEWS_H, BLACK, a);+ draw_notes();+ return;+ }+ draw_shimmers();+ draw_buffs();+ draw_popups();+ draw_notes();+ draw_tooltip();+ draw_minigame_tip();+ if (U.overlay == OV_PROMPT) draw_prompt();+ else if (U.overlay != OV_NONE) draw_overlay();+}++/* the screen's side of a logic frame: scrolling, the tooltip's time, the news */+void ui_tick(void) {+ extern void ascend_enter(void);+ extern void ascend_tick(void);+ static bool was_on_ascend;+ if (G.on_ascend && !was_on_ascend) ascend_enter(), U.overlay = OV_NONE;+ was_on_ascend = G.on_ascend;+ if (G.on_ascend) ascend_tick();+ if (G.store_dirty) ui_store_layout(), G.store_dirty = false;+ U.scroll += (U.scroll_t - U.scroll) * 0.4f;+ if (fabsf(U.scroll_t - U.scroll) < 0.5f) U.scroll = U.scroll_t;+ if (U.tip_t > 0) U.tip_t--;+ U.news_t++;+ if (U.news_fade > 0) U.news_fade--;+ if (U.news_t > FPS * 10) ui_news_next();+}++void ui_frame(void) {+ ui_store_layout();+ gfx_render(0, 0, SCREEN_W, SCREEN_H, draw_all);+ G.draw_t++;+}diff --git a/games/cookieclicker/src/ui.h b/games/cookieclicker/src/ui.hnew file mode 100644index 00000000..8e1bf30e--- /dev/null+++ b/games/cookieclicker/src/ui.h@@ -0,0 +1,94 @@+/* Cookie Clicker's screen: the left column (the big cookie), the store, the buildings' rows and the+ * minigames, the menus, ascension; and the keys. */+#ifndef CC_UI_H+#define CC_UI_H+#include <stdbool.h>+#include <stdint.h>+#include "game.h"+#include "gfx.h"++/* the fonts' characters past ASCII (tools/pack.py's CHARS) */+#define CH_BULLET "\x95"+#define CH_LQUOTE "\x99"+#define CH_RQUOTE "\x9a"+#define CH_TIMES "\x92"++/* what the right of the screen shows */+enum { VIEW_STORE, VIEW_ROWS };+/* the screens over the game */+enum { OV_NONE, OV_MENU, OV_STATS, OV_OPTIONS, OV_INFO, OV_PROMPT, OV_SPECIAL, OV_AURA, OV_PERMANENT, OV_KEYS,+ OV_ROWMENU };++/* the store's sections, for the choice of what is selected */+enum { SEC_UPGRADES, SEC_SWITCHES, SEC_RESEARCH, SEC_BUILDINGS, N_SEC };+#define CRATE 29 /* an upgrade's crate in the store */+#define CRATES_PER_ROW 6+#define PRODUCT_H 32 /* a building's row in the store */+#define STORE_TOP (NEWS_H + 14)++typedef struct {+ int view, overlay;+ int sec, idx; /* the store's selection */+ float scroll, scroll_t; /* the store's scroll (pixels) and where it heads */+ int32_t tip_t; /* frames the tooltip still shows */+ int menu_sel, prompt_sel, list_sel, list_top, stats_tab;+ bool from_menu; /* the page was opened from the menu (Back goes back to it) */+ int prompt_kind, prompt_arg;+ int rows_sel; /* the buildings' rows: the one chosen */+ float rows_scroll;+ int special; /* 0 santa, 1 dragon */+ int aura_slot, aura_sel;+ int perm_slot, perm_sel;+ /* the news */+ char news[2][200];+ int news_cur;+ int32_t news_t, news_fade;+ int asc_mode; /* ascension: the challenge mode chosen */+ float asc_x, asc_y, asc_tx, asc_ty; /* where the heavens are (and are going) */+ bool store_dirty;+} Ui;+extern Ui U;++/* the prompts */+enum { PROMPT_UPGRADE = 1, PROMPT_ASCEND, PROMPT_LEVEL, PROMPT_SELL_ALL, PROMPT_WIPE, PROMPT_REINCARNATE };+void prompt_open(int kind, int arg);+void draw_prompt(void);++void ui_init(void);+void ui_tick(void); /* a logic frame */+void ui_keys(uint32_t pressed, uint32_t held);+void ui_frame(void); /* draws the screen */+void ui_store_layout(void);+void ui_news_next(void);++/* drawing parts */+void draw_left(void);+void draw_shimmers(void);+void draw_buffs(void);+void draw_notes(void);+void draw_popups(void);+void draw_store(void);+void draw_tooltip(void);+void draw_news(void);+void draw_rows(void);+void draw_overlay(void);+void draw_ascend(void);+void draw_frame_box(int x, int y, int w, int h); /* the game's framed box */+void draw_crate(int icon, int x, int y, int state, bool shadow); /* state: 0 can buy, 1 selected, 2 can't */+void draw_price(int x, int y, double price, bool can, int money_im);+void store_move(int dx, int dy);+int store_selected_y(int *h); /* where the selection is in the store's content */+int store_content_h(void);+int store_buildings_top(void);+int store_selected_upgrade(void); /* -1 if the selection is a building */+int store_selected_building(void);++extern const ParaStyle PS_TIP, PS_QUOTE, PS_SMALL;++/* an upgrade's (type 0) or achievement's (type 1) tooltip, as the store, the statistics or the+ * ascension show it: measured (draw false) or drawn at (x, y) w wide; returns its height */+enum { CTX_STORE, CTX_STATS, CTX_ASCEND };+int crate_tip(int type, int id, int context, int x, int y, int w, bool draw);+void tip_line(int x, int y, int w); /* the game's faded line across */+int tip_tag(int x, int y, const char *s, uint16_t bg); /* returns its width */+#endifdiff --git a/games/cookieclicker/src/ui_left.c b/games/cookieclicker/src/ui_left.cnew file mode 100644index 00000000..60f8a9d7--- /dev/null+++ b/games/cookieclicker/src/ui_left.c@@ -0,0 +1,411 @@+/* The left column, as the game's DrawBackground draws it at 0.37 of its size: the blue background+ * (the grandmas' when the elders are angry), falling cookies, the big cookie's two turning flares,+ * its shadow, the cookie and its wobble, the cursors around it, the milk, the wrinklers, the+ * shaded borders (golden in a frenzy); then the cookies' count, golden cookies, buffs, popups,+ * notes. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "ui.h"++#define SC 0.37f+#define PANEL_H (SCREEN_H - NEWS_H)+extern float elder_wrath_d;+extern const char *buff_name(const Buff *b);+extern int buff_icon(const Buff *b);+extern int buff_aura(const Buff *b);++int milk_image(int i) { return IM_MILK_PLAIN + i; }+int santa_image(void) { return IM_SANTA0 + S.santa_level; }++static bool good_buff, bad_buff;+static void auras(void) {+ good_buff = bad_buff = false;+ for (int i = 0; i < MAX_BUFFS; i++) {+ const Buff *b = &S.buffs[i];+ if (!b->used || b->time <= 0) continue;+ if (buff_aura(b) == 1) good_buff = true;+ if (buff_aura(b) == 2) bad_buff = true;+ }+}++static void background(void) {+ float d = S.prefs.not_scary ? 0 : elder_wrath_d;+ int bg = IM_BG_BLUE, fade = -1;+ float r = 0;+ if (d >= 1 && d < 2) r = d - 1, fade = IM_BG_GRANDMAS1;+ else if (d >= 2 && d < 3) r = d - 2, bg = IM_BG_GRANDMAS1, fade = IM_BG_GRANDMAS2;+ else if (d >= 3) r = d - 3 > 1 ? 1 : d - 3, bg = IM_BG_GRANDMAS2, fade = IM_BG_GRANDMAS3;+ float tile = 512 * SC;+ gfx_pattern(bg, 0, NEWS_H, LEFT_W, PANEL_H, tile, tile, 0, NEWS_H, 256);+ if (fade >= 0 && r > 0) gfx_pattern(fade, 0, NEWS_H, LEFT_W, PANEL_H, tile, tile, 0, NEWS_H, (int)(r * 256));+}++static void shower(void) {+ if (!S.prefs.particles) return;+ float d = elder_wrath_d;+ int pic = -1;+ if (d <= 1.5f || S.prefs.not_scary) {+ if (G.cookies_ps >= 1000) pic = IM_SHOWER3;+ else if (G.cookies_ps >= 500) pic = IM_SHOWER2;+ else if (G.cookies_ps >= 50) pic = IM_SHOWER1;+ }+ if (pic < 0) return;+ float opacity = 1;+ if (d >= 1 && !S.prefs.not_scary) opacity = 1 - ((d < 1.5f ? d : 1.5f) - 1) / 0.5f;+ float y = fmodf(floorf(G.real_t * 2), 512) * SC;+ gfx_pattern(pic, 0, NEWS_H, LEFT_W, PANEL_H, 512 * SC, 512 * SC, 0, NEWS_H + y, (int)(opacity * 256));+}++static void particles(int kind) {+ for (int i = 0; i < MAX_PARTICLES; i++) {+ const Particle *p = &G.particles[i];+ if (p->life < 0 || p->kind != kind) continue;+ float o = sqrtf(1 - (float)p->life / (FPS * p->dur));+ int im = icon_index_image(p->pic);+ if (im < 0) continue;+ float s = 48 * p->size * SC;+ gfx_image_rotated(im, p->x, p->y, s, s, p->r * (float)M_PI / 180, (int)(o * 256));+ }+}++static void flares(float cx, float cy) {+ float alpha_mult = 1;+ int pic = IM_FLARE;+ bool inv = false;+ if (good_buff) pic = IM_FLARE_GOLD;+ else if (bad_buff) pic = IM_FLARE_RED, inv = true;+ float r1 = fmodf(G.real_t / FPS / 4, 1), r2 = fmodf(G.real_t / FPS / 4 + 0.5f, 1);+ if (inv) r1 = 1 - r1, r2 = 1 - r2;+ float rot = fmodf(G.real_t * 0.5f, 360) / 360 * 2 * (float)M_PI;+ float s1 = 512 * SC * (0.5f + sqrtf(r1)), s2 = 512 * SC * (0.5f + sqrtf(r2));+ gfx_blend(BLEND_NORMAL);+ gfx_image_rotated(pic, cx, cy, s1, s1, rot, (int)(sinf(r1 * (float)M_PI) * alpha_mult * 256));+ gfx_image_rotated(pic, cx, cy, s2, s2, rot + (float)M_PI, (int)(sinf(r2 * (float)M_PI) * alpha_mult * 256));+}++static void cursors(float cx, float cy) {+ if (!S.prefs.cursors) return;+ int amount = S.buildings[B_CURSOR].amount;+ bool fancy = S.prefs.fancy;+ bool dragon = has_buff(BUFF_DRAGONFLIGHT) || has_buff(BUFF_DRAGON_HARVEST);+ float rot = 0;+ for (int i = 0; i < amount && i < 1000; i++) {+ int n = i / 50;+ float w = 0;+ if (fancy) w = sinf(G.real_t * 0.025f + (float)((i + n * 12.45f) - 25 * floorf((i + n * 12.45f) / 25)) / 25 * 2 * (float)M_PI);+ if (w > 0.997f) w = 1.5f;+ else if (w > 0.994f) w = 0.5f;+ else w = 0;+ w *= -4;+ if (fancy) w += sinf((n + G.real_t * 0.01f) * (float)M_PI / 2) * 4;+ float y = (140 + n * 16 + w) - 16;+ float r = 7.2f;+ if (i == 0 && fancy) r -= G.real_t * 0.1f;+ if (i % 50 == 0) r += 7.2f / 2;+ rot += r / 360 * 2 * (float)M_PI;+ /* the cursor drawn at (0, y) in a frame turned by rot: its centre */+ float lx = 16, ly = y + 16;+ float sx = cx + (lx * cosf(rot) - ly * sinf(rot)) * SC, sy = cy + (lx * sinf(rot) + ly * cosf(rot)) * SC;+ if (!gfx_visible((int)sx - 7, (int)sy - 7, 14, 14)) continue;+ gfx_image_rotated(IM_CURSOR, sx, sy, 32 * SC, 32 * SC, rot, dragon ? 64 : 256);+ }+}++static void milk(void) {+ if (!S.prefs.milk) return;+ float h = PANEL_H;+ float x = fmodf(floorf(G.real_t * 2 - (G.milk_h - G.milk_hd) * 2000 + 480 * 2), 480) * SC;+ float y = G.milk_hd * h;+ float a = 1;+ if (G.ascend_timer > 0) {+ float k = (float)G.ascend_timer / (FPS * 5 / 2);+ y *= 1 - k * k * 2, a *= 1 - k * k * 2;+ } else if (G.reincarnate_timer > 0) {+ float k = 1 - (float)G.reincarnate_timer / FPS;+ y *= 1 - k * k * 2, a *= 1 - k * k * 2;+ }+ if (y <= 0 || a <= 0) return;+ int rank = (int)floorf(G.milk_progress);+ if (rank > N_MILKS - 1) rank = N_MILKS - 1;+ if (S.milk_type > 0 && S.ascension_mode != 1) rank = S.milk_type - 1;+ extern int milk_image(int i);+ float top = SCREEN_H - y;+ float tw = MILK_TILE, th = gfx_image_h(milk_image(rank)) * MILK_TILE / (float)gfx_image_w(milk_image(rank));+ gfx_pattern(milk_image(rank), 0, (int)top, LEFT_W, (int)ceilf(y), tw, th, x, top, (int)(0.95f * a * 256));+}++static void wrinklers(void) {+ for (int i = 0; i < MAX_WRINKLERS; i++) {+ const Wrinkler *w = &S.wrinklers[i];+ if (w->phase == 0) continue;+ float sw = (100 + 2 * sinf(G.real_t * 0.2f + i * 3)) * SC, sh = (200 + 5 * sinf(G.real_t * 0.2f - 2 + i * 3)) * SC;+ float ang = -w->r * (float)M_PI / 180;+ /* drawn from (-sw/2, -10) in a frame turned by -r at the wrinkler: its centre */+ float lx = 0, ly = -10 * SC + sh / 2;+ float cx = w->x + lx * cosf(ang) - ly * sinf(ang), cy = w->y + lx * sinf(ang) + ly * cosf(ang);+ gfx_image_rotated(w->type == 1 ? IM_SHINY_WRINKLER : IM_WRINKLER, cx, cy, sw, sh, ang, (int)(w->close * 256));+ }+}++/* the cookies' count: "1.234 million" on its line, "cookies" under it, then per second */+static void counter(void) {+ char num[64], line[96];+ double c = round(G.cookies_d);+ beautify(c, 0, num);+ if (G.cookies_d >= 1000000) { /* (the game pads to 3 decimals) */+ char *sp = strchr(num, ' '), *dot = strchr(num, '.');+ if (sp) {+ char pad[8] = "";+ if (!dot || dot > sp) strcpy(pad, ".000");+ else if (sp - dot == 2) strcpy(pad, "00");+ else if (sp - dot == 3) strcpy(pad, "0");+ char rest[48];+ strcpy(rest, sp);+ strcpy(sp, pad);+ strcat(num, rest);+ }+ }+ snprintf(line, sizeof line, "%s %s", num, c == 1 ? "cookie" : "cookies");+ char *l1 = line, *l2 = NULL;+ if (strlen(line) > 14) {+ char *sp = strchr(line, ' ');+ if (sp) *sp = 0, l2 = sp + 1;+ }+ int y = NEWS_H + (int)(PANEL_H * 0.1f);+ int h = l2 ? 39 : 27;+ gfx_fill_alpha(0, y, LEFT_W, h, BLACK, 102);+ gfx_text_outline_center(F_TITLE, LEFT_W / 2, y + 13, l1, WHITE, 256);+ if (l2) gfx_text_outline_center(F_NAME, LEFT_W / 2, y + 25, l2, WHITE, 256);+ char ps[64], t[48];+ beautify(G.cookies_ps * (1 - G.cps_sucked), 1, t);+ snprintf(ps, sizeof ps, "per second: %s", t);+ gfx_text_outline_center(F_SMALL, LEFT_W / 2, y + h - 4, ps, G.cps_sucked > 0 ? RGB(255, 0, 0) : WHITE, 256);+}++static const char *const name_a[] = {"Magic", "Fantastic", "Fancy", "Sassy", "Snazzy", "Pretty", "Cute", "Pirate",+ "Ninja", "Zombie", "Robot", "Radical", "Urban", "Cool", "Hella", "Sweet",+ "Awful", "Double", "Triple", "Turbo", "Techno", "Disco", "Electro", "Dancing",+ "Wonder", "Mutant", "Space", "Science", "Medieval", "Future", "Captain", "Bearded",+ "Lovely", "Tiny", "Big", "Fire", "Water", "Frozen", "Metal", "Plastic", "Solid",+ "Liquid", "Moldy", "Shiny", "Happy", "Happy Little", "Slimy", "Tasty",+ "Delicious", "Hungry", "Greedy", "Lethal", "Professor", "Doctor", "Power",+ "Chocolate", "Crumbly", "Choklit", "Righteous", "Glorious", "Mnemonic", "Psychic",+ "Frenetic", "Hectic", "Crazy", "Royal", "El", "Von"};+static const char *const name_b[] = {"Cookie", "Machine", "Robot", "Headbanger", "Bandit", "Castle", "Brain", "Kitchen",+ "Hamster", "Pug", "Bunny", "Monster", "Alligator", "Bowling", "Neutron",+ "Mustache", "Cowboy", "Princess", "Lord", "Tyrant", "Dragon", "Ghost", "Raptor",+ "Warlock", "Wizard", "Magician", "Pastry", "Bakery", "Baker", "Chef", "Cake",+ "Muffin", "Thing", "Chocolate", "Avalanche", "Fudge", "Kingdom", "Overlord",+ "Platypus", "Badger", "Squirrel", "Possum", "Raccoon", "Gunslinger", "Gnome",+ "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(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]);+}++static void bakery_box(void) {+ char t[64];+ bakery_name(t, sizeof t);+ int y = NEWS_H + (int)(PANEL_H * 0.1f) - 13;+ int w = LEFT_W * 3 / 4;+ gfx_round_rect((LEFT_W - w) / 2, y, w, 12, 5, BLACK, 102);+ gfx_text_center(F_NAME_SMALL, LEFT_W / 2, y + 9, t, RGB(204, 204, 204), 256);+}++/* what the special tabs (Santa, the dragon) show at the bottom left */+static void special_tabs(void) {+ int n = (has(U_A_FESTIVE_HAT) ? 1 : 0) + (has(U_A_CRUMBLY_EGG) ? 1 : 0);+ if (!n) return;+ float y = SCREEN_H - 24 * SC * 2 - 48 * SC * 2 * n + 10;+ int k = 0;+ if (has(U_A_FESTIVE_HAT)) {+ extern int santa_image(void);+ int im = santa_image();+ if (im >= 0) gfx_image_scaled(im, 4, y - 9 + sinf(G.real_t * 0.2f) * 1, 18, 18, 256);+ y += 20, k++;+ }+ if (has(U_A_CRUMBLY_EGG)) {+ extern int dragon_frame(void);+ float bob = fabsf(cosf(G.real_t * 0.2f + k)) * 2;+ gfx_image_scaled(IM_DRAGON0 + dragon_frame(), 4, y - 9 - bob, 18, 18, 256);+ }+}++void draw_left(void) {+ auras();+ float cx = COOKIE_X, cy = COOKIE_Y;+ if (!gfx_visible(0, NEWS_H, LEFT_W, PANEL_H)) return;+ gfx_clip(0, NEWS_H, LEFT_W, PANEL_H);+ background();+ if (G.ascend_timer == 0) {+ shower();+ particles(0);+ flares(cx, cy);+ if (G.reincarnate_timer > 0)+ gfx_fill_alpha(0, NEWS_H, LEFT_W, PANEL_H, BLACK, (int)((1 - (float)G.reincarnate_timer / FPS) * 256));+ if (has_buff(BUFF_DRAGONFLIGHT) || has_buff(BUFF_DRAGON_HARVEST)) {+ float s = 300 * 2 * (1 + sinf(G.real_t * 0.013f) * 0.1f) * SC;+ gfx_image_scaled(IM_DRAGON_BG, cx - s / 2, cy - s / (1.4f + 0.2f * sinf(G.real_t * 0.01f)), s, s, 256);+ }+ float s = 256 * G.big_size * SC;+ if (S.prefs.fancy) gfx_image_scaled(IM_COOKIE_SHADOW, cx - s / 2, cy - s / 2 + 20 * SC, s, s, 256);+ gfx_image_scaled(IM_COOKIE, cx - s / 2, cy - s / 2, s, s, 256);+ if (good_buff && S.prefs.particles) {+ gfx_blend(BLEND_ADD);+ float size = (float)(rnd() * 30 + 5) * SC, a = (float)(rnd() * 2 * M_PI), dd = s * 0.9f * (float)rnd() / 2;+ gfx_image_scaled(IM_GLINT, cx - size / 2 + sinf(a) * dd, cy - size / 2 + cosf(a) * dd, size, size,+ (int)((rnd() * 0.65 + 0.1) * 256));+ gfx_blend(BLEND_NORMAL);+ }+ cursors(cx, cy);+ } else {+ extern void draw_ascend_cookie(float cx, float cy);+ draw_ascend_cookie(cx, cy);+ }+ milk();+ if (G.ascend_timer == 0) {+ wrinklers();+ if (has(U_SHIMMERING_VEIL_OFF)) {+ gfx_blend(BLEND_ADD);+ float s = (300 + sinf(G.real_t * 0.037f) * 20) * SC;+ gfx_image_rotated(IM_SHIMMERING_VEIL, cx, cy, s, s, -G.real_t * 0.01f, 256);+ gfx_blend(BLEND_NORMAL);+ }+ special_tabs();+ particles(2);+ for (int i = 0; i < MAX_TEXT_PARTICLES; i++) {+ const TextParticle *t = &G.texts[i];+ if (t->life < 0) continue;+ float o = sqrtf(1 - (float)t->life / t->dur);+ gfx_text_outline_center(F_NAME, (int)t->x, (int)t->y, t->text, WHITE, (int)(o * 256));+ }+ int border = good_buff ? IM_BORDER_GOLD : bad_buff ? IM_BORDER_RED : IM_BORDER_SOFT;+ if (good_buff && S.prefs.fancy) gfx_blend(BLEND_ADD);+ gfx_image_scaled(border, 0, NEWS_H, LEFT_W, PANEL_H, 256);+ gfx_blend(BLEND_NORMAL);+ bakery_box();+ counter();+ } else+ gfx_image_scaled(IM_BORDER_SOFT, 0, NEWS_H, LEFT_W, PANEL_H, 256);+ gfx_unclip();+}++/* golden cookies, wrath cookies, the cookie storm's drops */+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;+ float k = (float)m->life / (FPS * m->dur) * 2 - 1;+ float curve = 1 - k * k * k * k;+ int id = m->id;+ float rot = 0, scale = m->size_mult * curve;+ if (S.prefs.fancy) {+ rot = sinf(id * 0.69f) * 24 + sinf(G.real_t * (0.35f + sinf(id * 0.97f) * 0.15f) + id) * (3 + sinf(id * 0.36f) * 2);+ scale = m->size_mult * (1 + sinf(id * 0.53f) * 0.2f) * curve *+ (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));+ }+}++/* the buffs in effect, at the top right of the left column, with the time they have left */+void draw_buffs(void) {+ int y = NEWS_H + 2;+ for (int i = 0; i < MAX_BUFFS; i++) {+ const Buff *b = &S.buffs[i];+ if (!b->used || b->time <= 0) continue;+ int x = LEFT_W - 22;+ gfx_round_rect(x - 1, y - 1, 22, 22, 3, BLACK, 90);+ gfx_icon_scaled(buff_icon(b), x, y, 20, 256);+ /* the time gone, as a darkening that sweeps around */+ float t = 1 - (float)b->time / b->max_time;+ for (int yy = 0; yy < 20; yy++)+ for (int xx = 0; xx < 20; xx++) {+ float a = atan2f(xx - 9.5f, -(yy - 9.5f));+ if (a < 0) a += 2 * (float)M_PI;+ if (a < t * 2 * (float)M_PI) gfx_fill_alpha(x + xx, y + yy, 1, 1, BLACK, 110);+ }+ y += 23;+ }+}++/* texts that float up (Lucky!, Frenzy...) */+void draw_popups(void) {+ for (int i = 0; i < MAX_POPUPS; i++) {+ const Popup *p = &G.popups[i];+ if (p->life <= 0) continue;+ float t = 1 - (float)p->life / (FPS * 4);+ float dy = t < 0.2f ? t / 0.2f * 32 * 0.5f : 32 * 0.5f;+ float o = t < 0.2f ? 1 : 1 - (t - 0.2f) / 0.8f;+ char lines[4][64];+ int n = 0;+ const char *s = p->text;+ while (*s && n < 4) {+ int k = 0;+ while (*s && *s != '\n' && k < 63) lines[n][k++] = *s++;+ lines[n][k] = 0;+ n++;+ if (*s == '\n') s++;+ }+ int w = 0;+ for (int k = 0; k < n; k++) {+ int lw = gfx_text_width(k ? F_SMALL : F_NAME, lines[k]);+ if (lw > w) w = lw;+ }+ int x = (int)p->x, y = (int)(p->y - dy);+ if (x - w / 2 < 4) x = 4 + w / 2;+ if (x + w / 2 > SCREEN_W - 4) x = SCREEN_W - 4 - w / 2;+ int h = 13 + (n - 1) * 11;+ gfx_round_rect(x - w / 2 - 6, y - 4, w + 12, h + 6, 6, BLACK, (int)(o * 128));+ for (int k = 0; k < n; k++)+ gfx_text_outline_center(k ? F_SMALL : F_NAME, x, y + 9 + (k ? 2 + k * 11 : 0), lines[k], WHITE, (int)(o * 256));+ }+}++/* the notes at the bottom of the screen: the newest two, and how many more there are */+void draw_notes(void) {+ int y = SCREEN_H - 2, shown = 0, more = 0;+ static const ParaStyle PS_NOTE_TITLE = {F_BOLD, F_BOLD, F_BOLD, WHITE, WHITE, WHITE, 11, 0};+ for (int i = 0; i < MAX_NOTES; i++) {+ const Note *n = &G.notes[i];+ if (!n->title[0]) continue;+ if (shown == 2) {+ more++;+ continue;+ }+ int w = 190, x = (SCREEN_W - w) / 2;+ int tx = x + 6 + (n->icon >= 0 ? 26 : 0), tw = w - 12 - (n->icon >= 0 ? 26 : 0);+ char desc[256];+ extern void text_beautify(const char *src, char *dst, int size);+ text_beautify(n->desc, desc, sizeof desc);+ int th = gfx_para(&PS_NOTE_TITLE, tx, 0, tw, n->title, false);+ int dh = desc[0] ? gfx_para(&PS_SMALL, tx, 0, tw, desc, false) : 0;+ int h = 6 + th + (desc[0] ? 3 + dh : 0) + 2;+ if (h < 30 && n->icon >= 0) h = 30;+ y -= h;+ if (gfx_visible(x, y, w, h)) {+ draw_frame_box(x, y, w, h);+ if (n->icon >= 0) gfx_icon(n->icon, x + 4, y + (h - 24) / 2, 256);+ int yy = y + 3 + (h - (6 + th + (desc[0] ? 3 + dh : 0) + 2)) / 2;+ yy += gfx_para(&PS_NOTE_TITLE, tx, yy, tw, n->title, true);+ if (desc[0]) {+ tip_line(tx, yy + 1, tw);+ gfx_para(&PS_SMALL, tx, yy + 3, tw, desc, true);+ }+ }+ y -= 2;+ shown++;+ }+ if (more) {+ char t[48];+ snprintf(t, sizeof t, "+%d more (delete: close)", more);+ int tw = gfx_text_width(F_SMALL, t) + 10;+ gfx_round_rect((SCREEN_W - tw) / 2, y - 12, tw, 12, 4, BLACK, 170);+ gfx_text_center(F_SMALL, SCREEN_W / 2, y - 3, t, RGB(200, 200, 200), 256);+ }+}diff --git a/games/cookieclicker/src/ui_store.c b/games/cookieclicker/src/ui_store.cnew file mode 100644index 00000000..740e1e73--- /dev/null+++ b/games/cookieclicker/src/ui_store.c@@ -0,0 +1,386 @@+/* The store, as the game's: its title and buy / sell, 1 / 10 / 100 buttons; upgrades as icons in+ * their frames (all of them shown while one is chosen, a row otherwise), switches and research;+ * then the buildings on their wooden tiles, with their picture, name, price and how many are owned.+ * The tooltip of what is chosen shows over the left column, as the game's does beside the store. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "ui.h"++#define SECTION_GAP 5+extern void text_beautify(const char *src, char *dst, int size);+extern void upgrade_description(int u, char *out, int size);+extern bool can_lumps(void);++typedef struct {+ int sec, idx, id; /* idx: within its section; id: the upgrade or building */+ int x, y, w, h; /* (y in the store's content, before scrolling) */+} Item;+static Item items[N_UPGRADES + NB + 8];+static int nitems, content_h;+static int sec_first[N_SEC], sec_count[N_SEC], sec_top[N_SEC], sec_h[N_SEC];+static int buildings_shown;++/* the buildings the store lists: those unlocked, and the next two (as ???) */+static int building_state(int b) { /* 0 hidden, 1 ???, 2 shown */+ int last_locked = 0;+ for (int i = 0; i <= b; i++) {+ bool unlocked = S.cookies_earned >= building_rec(i)->price || S.buildings[i].bought > 0;+ if (unlocked) last_locked = 0;+ else last_locked++;+ if (i == B_YOU && unlocked) win(A_COOKIE_CLICKER);+ }+ return last_locked == 0 ? 2 : last_locked <= 2 ? 1 : 0;+}++void ui_store_layout(void) {+ nitems = 0;+ int y = 0;+ int counts[3] = {G.nstore, G.nstore_toggle, G.nstore_tech};+ int base = 0;+ for (int s = 0; s < 3; s++) {+ sec_first[s] = nitems, sec_count[s] = counts[s], sec_top[s] = y;+ if (!counts[s]) {+ sec_h[s] = 0;+ base += counts[s];+ continue;+ }+ bool open = U.sec == s || s > 0;+ int rows = (counts[s] + CRATES_PER_ROW - 1) / CRATES_PER_ROW;+ if (!open) rows = 1;+ int top = y + 3;+ for (int i = 0; i < counts[s]; i++) {+ int r = i / CRATES_PER_ROW;+ Item *it = &items[nitems++];+ it->sec = s, it->idx = i, it->id = G.store[base + i];+ it->x = STORE_X + (i % CRATES_PER_ROW) * CRATE, it->y = top + r * CRATE, it->w = CRATE, it->h = CRATE;+ if (r >= rows) it->h = 0; /* (folded away) */+ }+ y = top + rows * CRATE + 2;+ sec_h[s] = y - sec_top[s];+ y += SECTION_GAP;+ base += counts[s];+ }+ sec_first[SEC_BUILDINGS] = nitems, sec_top[SEC_BUILDINGS] = y;+ int n = 0;+ for (int b = 0; b < NB; b++) {+ if (!building_state(b)) break;+ Item *it = &items[nitems++];+ it->sec = SEC_BUILDINGS, it->idx = n++, it->id = b;+ it->x = STORE_X, it->y = y, it->w = STORE_W, it->h = PRODUCT_H;+ y += PRODUCT_H;+ }+ sec_count[SEC_BUILDINGS] = n, sec_h[SEC_BUILDINGS] = y - sec_top[SEC_BUILDINGS];+ buildings_shown = n;+ content_h = y;+ /* keep the selection on something that is there */+ if (U.sec < SEC_BUILDINGS && sec_count[U.sec] == 0) U.sec = SEC_BUILDINGS, U.idx = 0;+ if (U.idx >= sec_count[U.sec]) U.idx = sec_count[U.sec] - 1;+ if (U.idx < 0) U.idx = 0;+}++static Item *selected_item(void) {+ if (sec_count[U.sec] == 0) return NULL;+ return &items[sec_first[U.sec] + U.idx];+}+int store_selected_upgrade(void) {+ Item *it = selected_item();+ return it && it->sec < SEC_BUILDINGS ? it->id : -1;+}+int store_selected_building(void) {+ Item *it = selected_item();+ return it && it->sec == SEC_BUILDINGS ? it->id : -1;+}++int store_selected_y(int *h) {+ Item *it = selected_item();+ *h = it ? it->h : 0;+ return it ? it->y : 0;+}+int store_content_h(void) { return content_h; }+int store_buildings_top(void) { return sec_top[SEC_BUILDINGS]; }++/* the arrows in the store */+static void move(int dx, int dy) {+ ui_store_layout();+ if (dy) {+ if (U.sec < SEC_BUILDINGS && sec_count[U.sec]) {+ int col = U.idx % CRATES_PER_ROW, row = U.idx / CRATES_PER_ROW;+ int rows = (sec_count[U.sec] + CRATES_PER_ROW - 1) / CRATES_PER_ROW;+ if (row + dy >= 0 && row + dy < rows) {+ int ni = (row + dy) * CRATES_PER_ROW + col;+ U.idx = ni < sec_count[U.sec] ? ni : sec_count[U.sec] - 1;+ ui_store_layout();+ return;+ }+ int s = U.sec + dy;+ while (s >= 0 && s < N_SEC && sec_count[s] == 0) s += dy;+ if (s < 0 || s >= N_SEC) return;+ U.sec = s;+ if (s == SEC_BUILDINGS) U.idx = dy > 0 ? 0 : sec_count[s] - 1;+ else {+ int r2 = dy > 0 ? 0 : (sec_count[s] - 1) / CRATES_PER_ROW;+ int ni = r2 * CRATES_PER_ROW + col;+ U.idx = ni < sec_count[s] ? ni : sec_count[s] - 1;+ }+ return;+ }+ int ni = U.idx + dy;+ if (ni >= 0 && ni < sec_count[SEC_BUILDINGS]) {+ U.idx = ni;+ return;+ }+ if (ni < 0) {+ int s = SEC_BUILDINGS - 1;+ while (s >= 0 && sec_count[s] == 0) s--;+ if (s < 0) return;+ U.sec = s;+ int rows = (sec_count[s] + CRATES_PER_ROW - 1) / CRATES_PER_ROW;+ U.idx = (rows - 1) * CRATES_PER_ROW;+ }+ return;+ }+ if (dx && U.sec < SEC_BUILDINGS) {+ int ni = U.idx + dx;+ if (ni >= 0 && ni < sec_count[U.sec]) U.idx = ni;+ }+}++void store_move(int dx, int dy) {+ move(dx, dy);+ ui_store_layout(); /* (the upgrades open while one is chosen) */+}++/* ------------------------------------------------------------------ drawing */+void draw_crate(int icon, int x, int y, int state, bool shadow) {+ gfx_fill_alpha(x + 3, y + 3, CRATE - 6, CRATE - 6, BLACK, 64);+ gfx_icon(icon, x + 2, y + 2, 256);+ gfx_image_part(IM_UPGRADE_FRAME, state * 29, shadow ? 29 : 0, 29, 29, x, y, 256);+}++void draw_price(int x, int y, double price, bool can, int money_im) {+ char t[48];+ beautify(round(price), 0, t);+ gfx_image(money_im, x, y - 8, 256);+ gfx_text_outline(F_SMALL, x + 12, y, t, can ? RGB(102, 255, 102) : RGB(255, 102, 102), 256);+}++static void draw_product(const Item *it, int y, bool sel) {+ int b = it->id, state = building_state(b);+ const BuildingRec *r = building_rec(b);+ int tile = it->idx % 4 == 0 ? 1 : it->idx % 4 == 1 ? 2 : it->idx % 4 == 2 ? 3 : 0;+ gfx_image(IM_STORE_TILE0 + tile, STORE_X, y, 256);+ double price;+ int n;+ building_bulk(b, &price, &n);+ bool enabled = G.buy_mode == 1 ? S.cookies >= price : S.buildings[b].amount > 0;+ bool unlocked = state == 2;+ int icon = IM_BUILD_CURSOR + 2 * b; /* (each building: its picture, then its silhouette) */+ if (unlocked) gfx_image(icon, STORE_X, y, 256);+ else gfx_image(icon + 1, STORE_X, y, 256);+ const char *name = unlocked ? res_text(r->name) : "???";+ int font = gfx_text_width(F_NAME, name) > STORE_W - 70 ? F_NAME_SMALL : F_NAME;+ gfx_text_outline(F_NAME == font ? F_NAME : F_NAME_SMALL, STORE_X + 34, y + 13, name, WHITE, 256);+ draw_price(STORE_X + 34, y + 27, price, enabled, IM_MONEY);+ if (G.buy_mode == -1 || G.buy_bulk != 1) {+ char t[16];+ snprintf(t, sizeof t, "x%d", n);+ int px = STORE_X + 34 + 12 + gfx_text_width(F_SMALL, "0") + 4;+ char pt[48];+ beautify(round(price), 0, pt);+ px = STORE_X + 34 + 12 + gfx_text_width(F_SMALL, pt) + 4;+ gfx_text_outline(F_SMALL, px, y + 27, t, RGB(255, 255, 204), 256);+ }+ if (unlocked && S.buildings[b].amount > 0) {+ char t[24];+ beautify(S.buildings[b].amount, 0, t);+ int x = STORE_X + STORE_W - 5;+ gfx_text_right(F_OWNED, x, y + 26, t, WHITE, 40);+ gfx_text_right(F_OWNED, x, y + 25, t, BLACK, 70);+ }+ if (unlocked && S.buildings[b].level > 0) {+ char t[16];+ snprintf(t, sizeof t, "lvl %d", S.buildings[b].level);+ gfx_text_outline(F_SMALL, STORE_X + STORE_W - 4 - gfx_text_width(F_SMALL, t), y + 9, t, RGB(255, 255, 204), 200);+ }+ if (!(unlocked && enabled)) gfx_fill_alpha(STORE_X, y, STORE_W, PRODUCT_H, BLACK, 102);+ if (G.buy_mode == -1) {+ gfx_hgrad(STORE_X, y, 8, PRODUCT_H, RGB(204, 0, 0), 150, 0);+ gfx_hgrad(STORE_X + STORE_W - 8, y, 8, PRODUCT_H, RGB(204, 0, 0), 0, 150);+ }+ if (sel) { /* the game's hover: a warm glow inside, brighter */+ gfx_fill_alpha(STORE_X, y, STORE_W, PRODUCT_H, WHITE, 26);+ for (int k = 0; k < 6; k++) gfx_rect(STORE_X + k, y + k, STORE_W - 2 * k, PRODUCT_H - 2 * k, RGB(255, 238, 221), 110 - k * 18);+ }+}++void draw_store(void) {+ if (!gfx_visible(STORE_X - 4, NEWS_H, STORE_W + 4, SCREEN_H - NEWS_H)) return;+ /* the dark column between the cookie and the store */+ for (int y = NEWS_H; y < SCREEN_H; y += 128) gfx_image(IM_PANEL_V, LEFT_W, y, 256);+ gfx_clip(STORE_X, NEWS_H, STORE_W, SCREEN_H - NEWS_H);+ gfx_pattern(IM_DARK_NOISE, STORE_X, NEWS_H, STORE_W, SCREEN_H - NEWS_H, 128, 128, 0, 0, 256);+ gfx_fill_alpha(STORE_X, NEWS_H, STORE_W, SCREEN_H - NEWS_H, BLACK, 128);+ int scroll = (int)U.scroll;+ int base = STORE_TOP - scroll;+ gfx_clip(STORE_X, STORE_TOP, STORE_W, SCREEN_H - STORE_TOP);+ for (int s = 1; s < 3; s++) { /* (switches and research: under a line, as the game has them) */+ if (!sec_count[s]) continue;+ int y = base + sec_top[s];+ for (int x = STORE_X; x < SCREEN_W; x += 128) gfx_image(IM_PANEL_H, x, y - 2, 256);+ }+ for (int i = 0; i < nitems; i++) {+ const Item *it = &items[i];+ if (it->h == 0) continue;+ int y = base + it->y;+ if (!gfx_visible(it->x, y, it->w, it->h)) continue;+ bool sel = it->sec == U.sec && it->idx == U.idx;+ if (it->sec < SEC_BUILDINGS) {+ bool can = upgrade_can_buy(it->id) || bit_get(S.upgrades_bought, it->id);+ draw_crate(upgrade_rec(it->id)->icon, it->x, y, sel ? 1 : can ? 0 : 2, false);+ if (bit_get(S.upgrades_bought, it->id)) gfx_fill_alpha(it->x + 2, y + 2, 25, 25, RGB(255, 255, 255), 30);+ } else+ draw_product(it, y, sel);+ }+ if (sec_count[SEC_BUILDINGS])+ for (int x = STORE_X; x < SCREEN_W; x += 128) gfx_image(IM_PANEL_H, x, base + sec_top[SEC_BUILDINGS] - 3, 256);+ gfx_unclip();+ /* the title: Store, buy / sell, 1 / 10 / 100 */+ gfx_pattern(IM_DARK_NOISE, STORE_X, NEWS_H, STORE_W, 14, 128, 128, 0, 0, 256);+ gfx_vgrad(STORE_X, NEWS_H, STORE_W, 14, BLACK, 60, 160);+ gfx_text_outline(F_NAME, STORE_X + 3, NEWS_H + 11, "Store", WHITE, 256);+ const char *opts[5] = {"Buy", "Sell", "1", "10", "100"};+ int x = SCREEN_W - 3;+ for (int i = 4; i >= 0; i--) {+ bool on = i == 0 ? G.buy_mode == 1 : i == 1 ? G.buy_mode == -1+ : (G.buy_bulk == (i == 2 ? 1 : i == 3 ? 10 : 100)) ||+ (i == 4 && G.buy_bulk == -1);+ if (i == 4 && G.buy_mode == -1 && G.buy_bulk == -1) opts[4] = "all";+ int w = gfx_text_width(F_SMALL, opts[i]);+ x -= w + 4;+ if (on) gfx_round_rect(x - 2, NEWS_H + 2, w + 4, 11, 3, RGB(255, 255, 255), 40);+ gfx_text(F_SMALL, x, NEWS_H + 10, opts[i], on ? WHITE : RGB(140, 140, 140), 256);+ if (i == 2) x -= 5;+ }+ gfx_unclip();+}++/* ------------------------------------------------------------------ the tooltip */+const ParaStyle PS_TIP = {F_BODY, F_BOLD, F_ITALIC, 0xCE79 /* #ccc */, WHITE, WHITE, 12, 0};+const ParaStyle PS_QUOTE = {F_ITALIC, F_ITALIC, F_ITALIC, 0x8410, 0x8410, 0x8410, 12, 0};+const ParaStyle PS_SMALL = {F_BODY, F_BOLD, F_ITALIC, 0xCE79, WHITE, WHITE, 11, 0};++void draw_frame_box(int x, int y, int w, int h) {+ gfx_pattern(IM_DARK_NOISE, x, y, w, h, 128, 128, 0, 0, 256);+ gfx_image_scaled(IM_BORDER_SOFT, (float)x, (float)y, (float)w, (float)h, 256);+ /* the gold frame (frameBorder.png's colours) */+ gfx_rect(x, y, w, h, 0xEF16 /* #ece2b6 */, 256);+ gfx_fill(x + 1, y + h - 2, w - 2, 1, 0x7144);+ gfx_fill(x + w - 2, y + 1, 1, h - 2, 0x8AA4);+ gfx_fill(x + 1, y + 1, w - 2, 1, 0xDDF3);+ gfx_fill(x + 1, y + 1, 1, h - 2, 0xDDF3);+ gfx_rect(x + 2, y + 2, w - 4, h - 4, BLACK, 160);+}++/* what a tooltip holds, measured (draw false) or drawn */+static int tooltip_body(int x, int y, int w, bool draw) {+ int u = store_selected_upgrade(), b = store_selected_building();+ char buf[1400], line[200];+ int yy = y;+ if (u >= 0) return crate_tip(0, u, CTX_STORE, x, y, w, draw);+ if (b >= 0) {+ const BuildingRec *r = building_rec(b);+ bool locked = S.cookies_earned < r->price && S.buildings[b].bought == 0;+ const Building *m = &S.buildings[b];+ double price;+ int n;+ building_bulk(b, &price, &n);+ bool can = G.buy_mode == 1 ? S.cookies >= price : m->amount > 0;+ if (draw) {+ if (locked) gfx_icon(ICON(0, 7), x, yy, 256);+ else gfx_icon(ICON(r->column, 0), x, yy, 256);+ char t[48];+ beautify(round(price), 0, t);+ int pw = gfx_text_width(F_SMALL, t) + 12;+ gfx_image(IM_MONEY, x + w - pw, yy, 256);+ gfx_text_outline(F_SMALL, x + w - pw + 12, yy + 8, t, can ? RGB(102, 255, 102) : RGB(255, 102, 102), 256);+ }+ const char *name = locked ? "???" : res_text(r->name);+ if (draw) {+ gfx_text_outline(F_NAME, x + 27, yy + 11, name, WHITE, 256);+ char tag[32];+ snprintf(tag, sizeof tag, "owned: %d", m->amount);+ int tw = gfx_text_width(F_SMALL, tag) + 6;+ gfx_round_rect(x + 27, yy + 14, tw, 10, 2, RGB(204, 204, 204), 210);+ gfx_text(F_SMALL, x + 30, yy + 22, tag, BLACK, 256);+ if (m->free > 0) {+ snprintf(tag, sizeof tag, "free: %d!", m->free);+ int tw2 = gfx_text_width(F_SMALL, tag) + 6;+ gfx_round_rect(x + 29 + tw, yy + 14, tw2, 10, 2, RGB(204, 204, 204), 210);+ gfx_text(F_SMALL, x + 32 + tw, yy + 22, tag, BLACK, 256);+ }+ }+ yy += 27;+ if (draw) {+ gfx_hgrad(x, yy, w / 2, 1, BLACK, 0, 110);+ gfx_hgrad(x + w / 2, yy, w - w / 2, 1, BLACK, 110, 0);+ }+ yy += 4;+ snprintf(buf, sizeof buf, CH_LQUOTE "%s" CH_RQUOTE, locked ? "???" : res_text(r->desc));+ ParaStyle qs = PS_QUOTE;+ yy += gfx_para(&qs, x, yy, w, buf, draw) + 3;+ if (m->total_cookies > 0) {+ if (draw) {+ gfx_hgrad(x, yy, w / 2, 1, BLACK, 0, 110);+ gfx_hgrad(x + w / 2, yy, w - w / 2, 1, BLACK, 110, 0);+ }+ yy += 3;+ char a[48], c[48], d[48];+ if (m->amount > 0) {+ cookies_str(m->stored_total_cps / m->amount * G.global_cps_mult, 1, a);+ snprintf(line, sizeof line, CH_BULLET " each %s produces \x01%s\x02 per second", res_text(r->single), a);+ yy += gfx_para(&PS_SMALL, x, yy, w, line, draw) + 2;+ }+ beautify(m->amount, 0, a);+ cookies_str(m->stored_total_cps * G.global_cps_mult, 1, c);+ double pct = G.cookies_ps > 0 && m->amount > 0 ? m->stored_total_cps * G.global_cps_mult / G.cookies_ps * 100 : 0;+ beautify(pct, 1, d);+ snprintf(line, sizeof line, CH_BULLET " %s %s producing \x01%s\x02 per second (\x01%s%%\x02 of total CpS)", a,+ m->amount == 1 ? res_text(r->single) : res_text(r->plural), c, d);+ yy += gfx_para(&PS_SMALL, x, yy, w, line, draw) + 2;+ beautify(m->total_cookies, 0, a);+ snprintf(line, sizeof line, CH_BULLET " \x01%s\x02 %s %s so far", a,+ floor(m->total_cookies) == 1 ? "cookie" : "cookies", res_text(r->action));+ yy += gfx_para(&PS_SMALL, x, yy, w, line, draw) + 2;+ }+ {+ if (can_lumps()) {+ if (draw) {+ gfx_hgrad(x, yy, w / 2, 1, BLACK, 0, 110);+ gfx_hgrad(x + w / 2, yy, w - w / 2, 1, BLACK, 110, 0);+ }+ yy += 3;+ snprintf(line, sizeof line, "\x01Level %d %s\x02 (+%d%% CpS). [toolbox] levels up for %d sugar lump%s.",+ m->level, res_text(r->plural), m->level, m->level + 1, m->level ? "s" : "");+ yy += gfx_para(&PS_SMALL, x, yy, w, line, draw) + 2;+ }+ }+ return yy - y;+ }+ return 0;+}++void draw_tooltip(void) {+ if (U.tip_t <= 0 || U.overlay || U.view != VIEW_STORE) return;+ Item *it = selected_item();+ if (!it) return;+ int w = LEFT_W + 6, x = 1, pad = 5;+ int h = tooltip_body(x + pad, 0, w - 2 * pad, false) + 2 * pad;+ int iy = STORE_TOP - (int)U.scroll + it->y;+ int y = iy + it->h / 2 - h / 2;+ if (y < NEWS_H + 2) y = NEWS_H + 2;+ if (y + h > SCREEN_H - 2) y = SCREEN_H - 2 - h;+ if (!gfx_visible(x, y, w, h)) return;+ draw_frame_box(x, y, w, h);+ tooltip_body(x + pad, y + pad, w - 2 * pad, true);+}diff --git a/games/cookieclicker/src/upgrades.c b/games/cookieclicker/src/upgrades.cnew file mode 100644index 00000000..34ce1032--- /dev/null+++ b/games/cookieclicker/src/upgrades.c@@ -0,0 +1,161 @@+/* The upgrades that do more than be had: their buyFunctions, the prices the game works out, the+ * switches, research, the elder pledge and covenant, the seasons' biscuits, and the cookies'+ * powers. */+#include <math.h>+#include <stdio.h>+#include <string.h>+#include "game.h"++static bool in_list(const uint16_t *l, int n, int u) {+ for (int i = 0; i < n; i++)+ if (l[i] == u) return true;+ return false;+}++/* research: the bingo center finds the next upgrade in 30 minutes (3 with Persistent memory, 5 seconds+ * with Ultrascience) */+#define BASE_RESEARCH_TIME (FPS * 60 * 30)+void set_research(int u) {+ if (has(u)) return;+ S.research_t = BASE_RESEARCH_TIME;+ if (has(U_PERSISTENT_MEMORY)) S.research_t = (BASE_RESEARCH_TIME + 9) / 10;+ if (has(U_ULTRASCIENCE)) S.research_t = FPS * 5;+ S.next_research = u;+ notify("Research has begun", "Your bingo center/research facility is conducting experiments.", ICON(9, 0), 0);+}+int32_t pledge_duration(void) { return FPS * 60 * (has(U_SACRIFICIAL_ROLLING_PINS) ? 60 : 30); }+extern void collect_wrinklers(void);+extern void season_trigger(int u);+extern void santa_drop(void);++void upgrade_buy_function(int u) {+ switch (u) {+ case U_BINGO_CENTER_RESEARCH_FACILITY: set_research(U_SPECIALIZED_CHOCOLATE_CHIPS); break;+ case U_SPECIALIZED_CHOCOLATE_CHIPS: set_research(U_DESIGNER_COCOA_BEANS); break;+ case U_DESIGNER_COCOA_BEANS: set_research(U_RITUAL_ROLLING_PINS); break;+ case U_RITUAL_ROLLING_PINS: set_research(U_UNDERWORLD_OVENS); break;+ case U_UNDERWORLD_OVENS: set_research(U_ONE_MIND); break;+ case U_ONE_MIND: S.elder_wrath = 1, set_research(U_EXOTIC_NUTS), G.store_dirty = true; break;+ case U_EXOTIC_NUTS: set_research(U_COMMUNAL_BRAINSWEEP); break;+ case U_COMMUNAL_BRAINSWEEP: S.elder_wrath = 2, set_research(U_ARCANE_SUGAR), G.store_dirty = true; break;+ case U_ARCANE_SUGAR: set_research(U_ELDER_PACT); break;+ case U_ELDER_PACT: S.elder_wrath = 3, G.store_dirty = true; break;+ case U_ELDER_PLEDGE:+ S.elder_wrath = 0, S.pledges++, S.pledge_t = pledge_duration();+ unlock(U_ELDER_COVENANT);+ collect_wrinklers();+ G.store_dirty = true;+ break;+ case U_ELDER_COVENANT:+ S.pledge_t = 0;+ lock(U_REVOKE_ELDER_COVENANT), unlock(U_REVOKE_ELDER_COVENANT), lock(U_ELDER_PLEDGE);+ win(A_ELDER_CALM);+ collect_wrinklers();+ G.store_dirty = true;+ break;+ case U_REVOKE_ELDER_COVENANT: lock(U_ELDER_COVENANT), unlock(U_ELDER_COVENANT); break;+ case U_A_FESTIVE_HAT: santa_drop(); break;+ case U_SEASON_SWITCHER:+ unlock(U_FESTIVE_BISCUIT), unlock(U_GHOSTLY_BISCUIT), unlock(U_LOVESICK_BISCUIT), unlock(U_FOOLS_BISCUIT),+ unlock(U_BUNNY_BISCUIT);+ break;+ case U_FESTIVE_BISCUIT: case U_GHOSTLY_BISCUIT: case U_LOVESICK_BISCUIT: case U_FOOLS_BISCUIT:+ case U_BUNNY_BISCUIT: season_trigger(u); break;+ case U_CHOCOLATE_EGG: {+ double c = S.cookies * 0.05;+ char t[64], d[96];+ beautify(c, 0, t);+ snprintf(d, sizeof d, "The egg bursts into \x01%s\x02 cookies!", t);+ notify("Chocolate egg", d, upgrade_rec(U_CHOCOLATE_EGG)->icon, 0);+ earn(c);+ break;+ }+ case U_SUGAR_FRENZY:+ gain_buff(BUFF_SUGAR_FRENZY, 60 * 60, 3, 0);+ notify("Sugar frenzy!", "CpS x3 for 1 hour!", ICON(29, 14), 0);+ break;+ case U_TOY_WORKSHOP: case U_FIVE_FINGER_DISCOUNT: case U_WRINKLER_AMBERGRIS: G.upgrades_dirty = true; break;+ default: break;+ }+}++/* switches: one turns into the other */+int upgrade_toggle_into(int u) {+ switch (u) {+ case U_GOLDEN_SWITCH_OFF: return U_GOLDEN_SWITCH_ON;+ case U_GOLDEN_SWITCH_ON: return U_GOLDEN_SWITCH_OFF;+ case U_SHIMMERING_VEIL_OFF: return U_SHIMMERING_VEIL_ON;+ case U_SHIMMERING_VEIL_ON: return U_SHIMMERING_VEIL_OFF;+ default: return -1;+ }+}++/* the store shows these even once had: the pledge running out, the selectors */+bool upgrade_display_when_owned(int u) {+ return u == U_ELDER_PLEDGE || u == U_FESTIVE_BISCUIT || u == U_GHOSTLY_BISCUIT || u == U_LOVESICK_BISCUIT ||+ u == U_FOOLS_BISCUIT || u == U_BUNNY_BISCUIT;+}++int upgrade_lumps(int u) { return u == U_SUGAR_FRENZY ? 1 : 0; }+int upgrade_can_buy_special(int u) {+ (void)u;+ return -1;+}++extern int how_many_eggs(void);+extern double season_price(int u);+extern int dragon_level_count(void);+double special_upgrade_price(int u, double price) {+ const UpgradeRec *r = upgrade_rec(u);+ switch (u) {+ case U_INCREASED_MERRINESS: case U_IMPROVED_JOLLINESS: case U_A_LUMP_OF_COAL: case U_AN_ITCHY_SWEATER:+ case U_REINDEER_BAKING_GROUNDS: case U_WEIGHTED_SLEIGHS: case U_HO_HO_HO_FLAVORED_FROSTING:+ case U_SEASON_SAVINGS: case U_TOY_WORKSHOP: case U_NAUGHTY_LIST: case U_SANTAS_BOTTOMLESS_BAG:+ case U_SANTAS_HELPERS: case U_SANTAS_LEGACY: case U_SANTAS_MILK_AND_COOKIES:+ return pow(3, S.santa_level) * 2525;+ case U_CHICKEN_EGG: case U_DUCK_EGG: case U_TURKEY_EGG: case U_QUAIL_EGG: case U_ROBIN_EGG: case U_OSTRICH_EGG:+ case U_CASSOWARY_EGG: case U_SALMON_ROE: case U_FROGSPAWN: case U_SHARK_EGG: case U_TURTLE_EGG: case U_ANT_LARVA:+ return pow(2, how_many_eggs()) * 999;+ case U_GOLDEN_GOOSE_EGG: case U_FABERGE_EGG: case U_WRINKLERSPAWN: case U_COOKIE_EGG: case U_OMELETTE:+ case U_CHOCOLATE_EGG: case U_CENTURY_EGG: case U_EGG:+ return pow(3, how_many_eggs()) * 999;+ case U_FORTUNE_100: case U_FORTUNE_101: case U_FORTUNE_102: case U_FORTUNE_103: case U_FORTUNE_104: {+ double c = G.unbuffed_cps * 60 * 60 * 24;+ return r->price < c ? r->price : c;+ }+ case U_DRAGON_SCALE: case U_DRAGON_CLAW: case U_DRAGON_FANG: case U_DRAGON_TEDDY_BEAR:+ return G.unbuffed_cps * 60 * 30 * (S.dragon_level < dragon_level_count() - 1 ? 1 : 0.1);+ case U_FESTIVE_BISCUIT: case U_GHOSTLY_BISCUIT: case U_LOVESICK_BISCUIT: case U_FOOLS_BISCUIT:+ case U_BUNNY_BISCUIT: return season_price(u);+ default: break;+ }+ extern double garden_drop_price(int u, double price);+ return garden_drop_price(u, price);+}++/* a cookie upgrade's production bonus (%); the heart biscuits' grows with Starlove and the Pantheon */+double cookie_upgrade_power(int u) {+ if (in_list(LIST(HEART_DROPS), N_HEART_DROPS, u)) {+ double pow_ = 2;+ if (has(U_STARLOVE)) pow_ = 3;+ if (S.season == SEASON_VALENTINES) {+ int god = hasgod(GOD_SEASONS);+ if (god == 1) pow_ *= 1.3;+ else if (god == 2) pow_ *= 1.2;+ else if (god == 3) pow_ *= 1.1;+ }+ return pow_;+ }+ return upgrade_rec(u)->power;+}++/* what particles fall as: a cookie the bakery has, or the plain one */+int particle_icon(void) {+ if (rnd() < 1.0 / 10000) return ICON(17, 5);+ int n = 1;+ for (int i = 0; i < N_COOKIE_UPGRADES; i++) n += has(LIST(COOKIE_UPGRADES)[i]);+ int k = rnd_int(n);+ for (int i = 0; i < N_COOKIE_UPGRADES && k; i++)+ if (has(LIST(COOKIE_UPGRADES)[i]) && --k == 0) return upgrade_rec(LIST(COOKIE_UPGRADES)[i])->icon;+ return ICON(10, 0);+}diff --git a/games/cookieclicker/tests/play.c b/games/cookieclicker/tests/play.cnew file mode 100644index 00000000..57c0f0b4--- /dev/null+++ b/games/cookieclicker/tests/play.c@@ -0,0 +1,266 @@+/* Plays Cookie Clicker on a computer, and saves frames.+ *+ * play [--frames N] [--keys "10-40:ok,50:exe,..."] [--shots 30,60|every:N] [--out DIR] [--saves DIR]+ * [--preset NAME] [--seed S] [--raw DIR --raw-from T --raw-to T] [--quiet] [--bot]+ *+ * 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.+ * --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. */+#include <math.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <sys/stat.h>+#include "../src/game.h"+#include "../src/gfx.h"+#include "../src/ui.h"++extern uint32_t host_keys, host_time, host_seed;+extern uint16_t host_fb[SCREEN_W * SCREEN_H];+void host_shot(const char *path);+void host_save_dir(const char *d);+extern bool g_quit;+extern bool game_save(void);+void cc_begin(void);+void cc_frame(uint32_t pressed, uint32_t held);+extern void game_recount(void);++typedef struct { int a, b; uint32_t k; } Hold;+static Hold holds[8192];+static int nholds;++static uint32_t key_named(const char *s) {+ static const struct { const char *n; uint32_t k; } t[] = {+ {"left", K_LEFT}, {"right", K_RIGHT}, {"up", K_UP}, {"down", K_DOWN}, {"ok", K_OK}, {"exe", K_EXE},+ {"back", K_BACK}, {"shift", K_SHIFT}, {"home", K_HOME}, {"alpha", K_ALPHA}, {"mul", K_MUL}, {"div", K_DIV},+ {"toolbox", K_TOOLBOX}, {"var", K_VAR}, {"del", K_DEL}, {"xnt", K_XNT},+ };+ for (unsigned i = 0; i < sizeof t / sizeof t[0]; i++)+ if (!strcmp(s, t[i].n)) return t[i].k;+ if (s[0] >= '0' && s[0] <= '9' && !s[1]) return K_DIGIT(s[0] == '0' ? 10 : s[0] - '0');+ fprintf(stderr, "unknown key %s\n", s);+ exit(2);+}++static void parse_keys(const char *spec) {+ static char buf[1 << 17];+ snprintf(buf, sizeof buf, "%s", spec);+ for (char *tok = strtok(buf, ","); tok; tok = strtok(NULL, ",")) {+ char *colon = strchr(tok, ':');+ if (!colon) continue;+ *colon = 0;+ int a, b;+ if (sscanf(tok, "%d-%d", &a, &b) != 2) b = a = atoi(tok);+ holds[nholds].a = a, holds[nholds].b = b, holds[nholds].k = key_named(colon + 1);+ if (nholds < 8191) nholds++;+ }+}++static int shots[1024], nshots_at, every;+static const char *raw_dir;+static int raw_from, raw_to = -1;+static void parse_shots(const char *s) {+ if (!strncmp(s, "every:", 6)) {+ every = atoi(s + 6);+ return;+ }+ char buf[8192];+ snprintf(buf, sizeof buf, "%s", s);+ for (char *t = strtok(buf, ","); t && nshots_at < 1024; t = strtok(NULL, ",")) shots[nshots_at++] = atoi(t);+}+static bool shot_now(int t) {+ if (every && t % every == 0) return true;+ for (int i = 0; i < nshots_at; i++)+ if (shots[i] == t) return true;+ return false;+}++/* ------------------------------------------------------------------ presets */+static void own(int b, int n) {+ for (int i = 0; i < n; i++) {+ S.buildings[b].amount++, S.buildings[b].bought++;+ if (S.buildings[b].amount > S.buildings[b].highest) S.buildings[b].highest = S.buildings[b].amount;+ extern void building_bought(int b);+ building_bought(b);+ }+}+/* every upgrade in the store whose price is under max, bought */+static void buy_upgrades(double max) {+ for (int pass = 0; pass < 6; pass++) {+ game_rebuild_upgrades();+ calculate_gains();+ for (int i = 0; i < G.nstore; i++) {+ int u = G.store[i];+ if (upgrade_price(u) <= max && !upgrade_needs_confirm(u)) {+ S.cookies += upgrade_price(u) + 1;+ upgrade_buy(u, true);+ }+ }+ }+}+static void preset(const char *name) {+ if (!strcmp(name, "start")) return;+ S.seen_keys = 1;+ U.overlay = OV_NONE;+ if (!strcmp(name, "early")) {+ S.cookies = 1400, S.cookies_earned = 3200, S.cookie_clicks = 420, S.handmade_cookies = 640;+ own(B_CURSOR, 12), own(B_GRANDMA, 6), own(B_FARM, 2);+ buy_upgrades(2000);+ S.cookies = 1400;+ } else if (!strcmp(name, "mid") || !strcmp(name, "golden") || !strcmp(name, "wrath") || !strcmp(name, "grimoire") ||+ !strcmp(name, "wrinklers")) {+ 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]);+ buy_upgrades(4e9);+ S.cookies = 3.4e8;+ S.lumps = 7, S.lumps_total = 9, S.lump_t = S.play_time - 1000;+ for (int a = 0; a < 60; a++) win(a);+ game_recount();+ if (!strcmp(name, "golden")) shimmer_new(SHIMMER_GOLDEN, GC_NONE, false);+ if (!strcmp(name, "wrath")) {+ Shimmer *m = shimmer_new(SHIMMER_GOLDEN, GC_NONE, false);+ if (m) m->wrath = 1;+ S.elder_wrath = 3;+ }+ if (!strcmp(name, "wrinklers")) {+ S.elder_wrath = 2;+ 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, "grimoire")) {+ S.buildings[B_WIZARD_TOWER].level = 1;+ extern void grimoire_reset(bool hard);+ grimoire_reset(true);+ S.on_minigame = B_WIZARD_TOWER + 1;+ U.view = VIEW_ROWS;+ }+ } else if (!strcmp(name, "late") || !strcmp(name, "ascend")) {+ S.cookies_earned = 4.4e21, S.cookie_clicks = 21000, S.handmade_cookies = 5e17;+ S.cookies_reset = 2e19, S.resets = 3, S.prestige = floor(pow(S.cookies_reset / 1e12, 1.0 / 3));+ S.heavenly_chips = 40;+ for (int b = 0; b < NB; b++) own(b, b < 14 ? 300 - b * 15 : 40 - (b - 14) * 5);+ for (int i = 0; i < N_HEAVENLY; i++) {+ int u = LIST(HEAVENLY)[i];+ if (upgrade_rec(u)->price < 1e7) bit_set(S.upgrades_bought, u, true), bit_set(S.upgrades_unlocked, u, true);+ }+ buy_upgrades(1e21);+ S.cookies = 7.7e20;+ S.lumps = 41, S.lumps_total = 60;+ for (int a = 0; a < 300; a++) win(a);+ game_recount();+ if (!strcmp(name, "ascend")) {+ G.on_ascend = true;+ extern void earn_heavenly_chips(double forfeited, bool silent);+ S.heavenly_chips = 2.4e6;+ }+ } else {+ fprintf(stderr, "unknown preset %s\n", name);+ exit(2);+ }+ for (int i = 0; i < MAX_NOTES; i++) G.notes[i].title[0] = 0;+ G.recalculate = true, G.upgrades_dirty = true, G.store_dirty = true;+ calculate_gains();+ game_rebuild_upgrades();+ G.cookies_d = S.cookies;+ ui_news_next();+ U.news_fade = 0;+}++/* ------------------------------------------------------------------ the bot */+static uint32_t bot_keys(int t) {+ /* clicks every other frame; catches shimmers; buys what the store has chosen when it can, else looks for the+ * cheapest it can afford */+ uint32_t k = 0;+ if (t % 2 == 0) k |= K_OK;+ for (int i = 0; i < MAX_SHIMMERS; i++)+ if (G.shimmers[i].used && t % 7 == 0) k |= K_SHIFT;+ if (t % 30 == 15) {+ int best = -1;+ double bp = 1e300;+ for (int i = 0; i < G.nstore; i++) {+ int u = G.store[i];+ if (upgrade_can_buy(u) && !upgrade_needs_confirm(u) && upgrade_price(u) < bp) bp = upgrade_price(u), best = u;+ }+ if (best >= 0) upgrade_buy(best, false);+ int bb = -1;+ double bbp = 1e300;+ for (int b = 0; b < NB; b++) {+ double p = building_price(b);+ if (p <= S.cookies && p < bbp * 0.6) bbp = p, bb = b;+ }+ if (bb >= 0) building_buy(bb, 1);+ }+ return k;+}++int main(int argc, char **argv) {+ int frames = 300;+ const char *out = "build/shots", *saves = "build/host-saves", *pre = NULL;+ bool quiet = false, bot = false;+ for (int i = 1; i < argc; i++) {+ if (!strcmp(argv[i], "--frames") && i + 1 < argc) frames = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--keys") && i + 1 < argc) parse_keys(argv[++i]);+ else if (!strcmp(argv[i], "--shots") && i + 1 < argc) parse_shots(argv[++i]);+ else if (!strcmp(argv[i], "--out") && i + 1 < argc) out = argv[++i];+ else if (!strcmp(argv[i], "--saves") && i + 1 < argc) saves = argv[++i];+ else if (!strcmp(argv[i], "--preset") && i + 1 < argc) pre = argv[++i];+ else if (!strcmp(argv[i], "--seed") && i + 1 < argc) host_seed = (uint32_t)atol(argv[++i]);+ else if (!strcmp(argv[i], "--raw") && i + 1 < argc) raw_dir = argv[++i];+ else if (!strcmp(argv[i], "--raw-from") && i + 1 < argc) raw_from = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--raw-to") && i + 1 < argc) raw_to = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--quiet")) quiet = true;+ else if (!strcmp(argv[i], "--bot")) bot = true;+ else {+ fprintf(stderr, "unknown option %s\n", argv[i]);+ return 2;+ }+ }+ mkdir(out, 0755);+ mkdir(saves, 0755);+ host_save_dir(saves);+ static uint16_t band[SCREEN_W * GFX_BAND];+ gfx_set_band_memory(band);+ cc_begin();+ if (pre) preset(pre);+ uint32_t prev = 0;+ int t;+ for (t = 0; t < frames && !g_quit; t++) {+ host_keys = 0;+ for (int i = 0; i < nholds; i++)+ if (t >= holds[i].a && t <= holds[i].b) host_keys |= holds[i].k;+ if (bot) host_keys |= bot_keys(t);+ if (host_keys) host_keys |= K_ANY;+ if (host_keys & K_HOME) g_quit = true;+ if (g_quit) break;+ cc_frame(host_keys & ~prev, host_keys);+ prev = host_keys;+ host_time += 33;+ bool raw = raw_dir && t >= raw_from && t <= raw_to;+ if (shot_now(t) || raw || t % 7 == 0) ui_frame(); /* (drawn now and then anyway: the drawing is tested too) */+ if (shot_now(t)) {+ char p[512];+ snprintf(p, sizeof p, "%s/shot_%05d.ppm", out, t);+ host_shot(p);+ if (!quiet) printf("shot %s\n", p);+ }+ if (raw) {+ char p[512];+ snprintf(p, sizeof p, "%s/frame_%06d.raw", raw_dir, (int)((t - raw_from) * 1000 / 30));+ FILE *f = fopen(p, "wb");+ if (f) fwrite(host_fb, 2, SCREEN_W * SCREEN_H, f), fclose(f);+ }+ }+ if (g_quit) game_save();+ int owned = 0;+ for (int b = 0; b < NB; b++) owned += S.buildings[b].amount;+ printf("frames %d cookies %.0f earned %.0f cps %.1f clicks %.0f buildings %d upgrades %d achievements %d "+ "prestige %.0f chips %.0f golden %u ascending %d running %d\n",+ t, S.cookies, S.cookies_earned, G.cookies_ps, S.cookie_clicks, owned, G.upgrades_owned, G.achievements_owned,+ S.prestige, S.heavenly_chips, S.golden_clicks, G.on_ascend ? 1 : G.ascend_timer > 0 ? 2 : 0, !g_quit);+ return 0;+}diff --git a/games/cookieclicker/tools/data.py b/games/cookieclicker/tools/data.pydeleted file mode 100644index ff4c4ba5..00000000--- a/games/cookieclicker/tools/data.py+++ /dev/null@@ -1,594 +0,0 @@-#!/usr/bin/env python3-"""Cookie Clicker's data for the calculator: src/data.h.--The names of the upgrades, the achievements and the news are Orteil's, as the game has them-(version 2.05). They go into one block of text packed with DEFLATE (zopfli), which the game-unpacks once when it starts (NumPlay's own decoder, launcher/src/inflate.c), so they take about-half their size in flash. The pictures of the store are 12 x 12 masks drawn below.--Usage: data.py [OUT] (src/data.h by default; needs the zopfli module)-"""-import os-import sys--import zopfli.zlib--HERE = os.path.dirname(os.path.abspath(__file__))-OUT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(HERE, "..", "src", "data.h")--TIER_N = 3 # tiered upgrades for each building (the game has 15)-ACH_TIERS = 1 # building achievements for each (have 1)--# ------------------------------------------------------------------ upgrades, in the order of the save-CURSOR = ["Reinforced index finger", "Carpal tunnel prevention cream", "Ambidextrous", "Thousand fingers"] + \- [n + " fingers" for n in ["Million", "Billion", "Trillion", "Quadrillion", "Quintillion", "Sextillion", "Septillion",- "Octillion", "Nonillion", "Decillion", "Undecillion"]]-MOUSE = [n + " mouse" for n in ["Plastic", "Iron", "Titanium", "Adamantium", "Unobtainium", "Eludium", "Wishalloy",- "Fantasteel", "Nevercrack", "Armythril", "Technobsidian", "Plasmarble", "Miraculite",- "Aetherice", "Omniplast"]]-KITTEN = ["Kitten " + n for n in ["helpers", "workers", "engineers", "overseers", "managers", "accountants"]]-GOLD = ["Lucky day", "Serendipity", "Get lucky"]-GRANDMA = ["Farmer grandmas", "Miner grandmas", "Worker grandmas", "Banker grandmas", "Priestess grandmas",- "Witch grandmas", "Cosmic grandmas", "Transmuted grandmas", "Altered grandmas", "Grandmas' grandmas",- "Antigrandmas", "Rainbow grandmas", "Lucky grandmas", "Metagrandmas", "Binary grandmas", "Alternate grandmas",- "Brainy grandmas", "Clone grandmas"]-# (name, % more CpS, price: so many nines, times 5 or not)-COOKIES = [- ("Plain cookies", 1, 6, 0), ("Sugar cookies", 1, 6, 1), ("Oatmeal raisin cookies", 1, 7, 0),- ("Peanut butter cookies", 2, 7, 1), ("Coconut cookies", 2, 8, 0), ("White chocolate cookies", 2, 8, 1),- ("Macadamia nut cookies", 2, 8, 0), ("Double-chip cookies", 2, 9, 1),- ("White chocolate macadamia nut cookies", 2, 10, 0), ("All-chocolate cookies", 2, 10, 1),- ("Dark chocolate-coated cookies", 5, 11, 0), ("White chocolate-coated cookies", 5, 11, 0),- ("Eclipse cookies", 2, 11, 1), ("Zebra cookies", 2, 12, 0), ("Snickerdoodles", 2, 12, 1),- ("Stroopwafels", 2, 13, 0), ("Macaroons", 2, 13, 1), ("Empire biscuits", 2, 14, 0),- ("British tea biscuits", 2, 14, 0), ("Madeleines", 2, 14, 1), ("Palmiers", 2, 14, 1), ("Palets", 2, 15, 0),- ("Sables", 2, 15, 0), ("Caramoas", 3, 16, 0), ("Sagalongs", 3, 16, 0), ("Shortfoils", 3, 16, 0),- ("Win mints", 3, 16, 0), ("Gingerbread men", 2, 16, 0), ("Gingerbread trees", 2, 16, 0),- ("Pure black chocolate cookies", 5, 16, 1), ("Pure white chocolate cookies", 5, 16, 1),- ("Ladyfingers", 3, 17, 0), ("Tuiles", 3, 17, 1), ("Chocolate-stuffed biscuits", 3, 18, 0),- ("Checker cookies", 3, 18, 1), ("Butter cookies", 3, 19, 0), ("Cream cookies", 3, 19, 1),-]-TIERED = { # each building's upgrades, tier 1 first- "Grandma": ["Forwards from grandma", "Steel-plated rolling pins", "Lubricated dentures", "Prune juice",- "Double-thick glasses", "Aging agents", "Xtreme walkers", "The Unbridling", "Reverse dementia",- "Timeproof hair dyes"],- "Farm": ["Cheap hoes", "Fertilizer", "Cookie trees", "Genetically-modified cookies", "Gingerbread scarecrows",- "Pulsar sprinklers", "Fudge fungus", "Wheat triffids", "Humane pesticides", "Barnstars"],- "Mine": ["Sugar gas", "Megadrill", "Ultradrill", "Ultimadrill", "H-bomb mining", "Coreforge", "Planetsplitters",- "Canola oil wells", "Mole people", "Mine canaries"],- "Factory": ["Sturdier conveyor belts", "Child labor", "Sweatshop", "Radium reactors", "Recombobulators",- "Deep-bake process", "Cyborg workforce", "78-hour days", "Machine learning", "Brownie point system"],- "Bank": ["Taller tellers", "Scissor-resistant credit cards", "Acid-proof vaults", "Chocolate coins",- "Exponential interest rates", "Financial zen", "Way of the wallet", "The stuff rationale", "Edible money",- "Grand supercycles"],- "Temple": ["Golden idols", "Sacrifices", "Delicious blessing", "Sun festival", "Enlarged pantheon",- "Great Baker in the sky", "Creation myth", "Theocracy", "Sick rap prayers", "Psalm-reading"],- "Wizard tower": ["Pointier hats", "Beardlier beards", "Ancient grimoires", "Kitchen curses", "School of sorcery",- "Dark formulas", "Cookiemancy", "Rabbit trick", "Deluxe tailored wands", "Immobile spellcasting"],- "Shipment": ["Vanilla nebulae", "Wormholes", "Frequent flyer", "Warp drive", "Chocolate monoliths",- "Generation ship", "Dyson sphere", "The final frontier", "Autopilot",- "Restaurants at the end of the universe"],- "Alchemy lab": ["Antimony", "Essence of dough", "True chocolate", "Ambrosia", "Aqua crustulae", "Origin crucible",- "Theory of atomic fluidity", "Beige goo", "The advent of chemistry", "On second thought"],- "Portal": ["Ancient tablet", "Insane oatling workers", "Soul bond", "Sanity dance", "Brane transplant",- "Deity-sized portals", "End of times back-up plan", "Maddening chants", "The real world",- "Dimensional garbage gulper"],- "Time machine": ["Flux capacitors", "Time paradox resolver", "Quantum conundrum", "Causality enforcer",- "Yestermorrow comparators", "Far future enactment", "Great loop hypothesis",- "Cookietopian moments of maybe", "Second seconds", "Additional clock hands"],- "Antimatter condenser": ["Sugar bosons", "String theory", "Large macaron collider", "Big bang bake",- "Reverse cyclotrons", "Nanocosmics", "The Pulse",- "Some other super-tiny fundamental particle? Probably?", "Quantum comb",- "Baking Nobel prize"],- "Prism": ["Gem polish", "9th color", "Chocolate light", "Grainbow", "Pure cosmic light", "Glow-in-the-dark",- "Lux sanctorum", "Reverse shadows", "Crystal mirrors", "Reverse theory of light"],- "Chancemaker": ["Your lucky cookie", "\"All Bets Are Off\" magic coin", "Winning lottery ticket",- "Four-leaf clover field", "A recipe book about books", "Leprechaun village", "Improbability drive",- "Antisuperstistronics", "Bunnypedes", "Revised probabilistics"],- "Fractal engine": ["Metabakeries", "Mandelbrown sugar", "Fractoids", "Nested universe theory",- "Menger sponge cake", "One particularly good-humored cow", "Chocolate ouroboros", "Nested",- "Space-filling fibers", "Endless book of prose"],- "Javascript console": ["The JavaScript console for dummies", "64bit arrays", "Stack overflow",- "Enterprise compiler", "Syntactic sugar", "A nice cup of coffee", "Just-in-time baking",- "cookies++", "Software updates", "Game.Loop"],- "Idleverse": ["Manifest destiny", "The multiverse in a nutshell", "All-conversion", "Multiverse agents",- "Escape plan", "Game design", "Sandbox universes", "Multiverse wars", "Mobile ports",- "Encapsulated realities"],- "Cortex baker": ["Principled neural shackles", "Obey", "A sprinkle of irrationality", "Front and back hemispheres",- "Neural networking", "Cosmic brainstorms", "Megatherapy", "Synaptic lubricant", "Psychokinesis",- "Spines"],- "You": ["Cloning vats", "Energized nutrients", "Stunt doubles", "Clone recycling plant", "Free-range clones",- "Genetic tailoring", "Power in diversity", "Self-betterment", "Source control", "United workforce"],-}-BUILDINGS = ["Cursor", "Grandma", "Farm", "Mine", "Factory", "Bank", "Temple", "Wizard tower", "Shipment",- "Alchemy lab", "Portal", "Time machine", "Antimatter condenser", "Prism", "Chancemaker", "Fractal engine",- "Javascript console", "Idleverse", "Cortex baker", "You"]-# the golden cookie's building special, for each building-SPECIAL = ["High-five", "Congregation", "Luxuriant harvest", "Ore vein", "Oiled-up", "Juicy profits",- "Fervent adoration", "Manabloom", "Delicious lifeforms", "Breakthrough", "Righteous cataclysm",- "Golden ages", "Extra cycles", "Solar flare", "Winning streak", "Macrocosm", "Refactoring",- "Cosmic nursery", "Brainstorm", "Deduplication"]--# ------------------------------------------------------------------ achievements, in the order of the save-BANK = ["Wake and bake", "Making some dough", "So baked right now", "Fledgling bakery", "Affluent bakery",- "World-famous bakery", "Cosmic bakery", "Galactic bakery", "Universal bakery", "Timeless bakery",- "Infinite bakery", "Immortal bakery", "Don't stop me now", "You can stop now", "Cookies all the way down",- "Overdose", "How?", "The land of milk and cookies", "He who controls the cookies controls the universe",- "Tonight on Hoarders", "Are you gonna eat all that?", "We're gonna need a bigger bakery",- "In the mouth of madness"]-CPS = ["Casual baking", "Hardcore baking", "Steady tasty stream", "Cookie monster", "Mass producer", "Cookie vortex",- "Cookie pulsar", "Cookie quasar", "Oh hey, you're still here", "Let's never bake again",- "A world filled with cookies", "When this baby hits 36 quadrillion cookies per hour", "Fast and delicious",- "Cookiehertz : a really, really tasty hertz", "Woops, you solved world hunger", "Turbopuns", "Faster menner",- "And yet you're still hungry", "The Abakening"]-CLICK = ["Clicktastic", "Clickathlon", "Clickolympics", "Clickorama", "Clickasmic", "Clickageddon", "Clicknarok",- "Clickastrophe", "Clickataclysm", "The ultimate clickdown"]-CURSOR_ACH = ["Click", "Double-click", "Mouse wheel", "Of Mice and Men", "The Digital"]-BUILDING_ACH = {- "Grandma": ["Grandma's cookies", "Sloppy kisses", "Retirement home"],- "Farm": ["Bought the farm", "Reap what you sow", "Farm ill"],- "Mine": ["You know the drill", "Excavation site", "Hollow the planet"],- "Factory": ["Production chain", "Industrial revolution", "Global warming"],- "Bank": ["Pretty penny", "Fit the bill", "A loan in the dark"],- "Temple": ["Your time to shrine", "Shady sect", "New-age cult"],- "Wizard tower": ["Bewitched", "The sorcerer's apprentice", "Charms and enchantments"],- "Shipment": ["Expedition", "Galactic highway", "Far far away"],- "Alchemy lab": ["Transmutation", "Transmogrification", "Gold member"],- "Portal": ["A whole new world", "Now you're thinking", "Dimensional shift"],- "Time machine": ["Time warp", "Alternate timeline", "Rewriting history"],- "Antimatter condenser": ["Antibatter", "Quirky quarks", "It does matter!"],- "Prism": ["Lone photon", "Dazzling glimmer", "Blinding flash"],- "Chancemaker": ["Lucked out", "What are the odds", "Grandma needs a new pair of shoes"],- "Fractal engine": ["Self-contained", "Threw you for a loop", "The sum of its parts"],- "Javascript console": ["F12", "Variable success", "No comments"],- "Idleverse": ["They'll never know what hit 'em", "Well-versed", "Ripe for the picking"],- "Cortex baker": ["It's big brain time", "Just my imagination", "Now there's an idea"],- "You": ["My own clone", "Multiplicity", "Born for this job"],-}-GOLDEN = ["Golden cookie", "Lucky cookie", "A stroke of luck", "Fortune", "Leprechaun", "Black cat's paw"]-OWNED = ["Builder", "Architect", "Engineer", "Lord of Constructs"]-UPGRADED = ["Enhancer", "Augmenter", "Upgrader", "Lord of Progress"]-# (their conditions are in the game, in this order)-MISC = ["One with everything", "Centennial", "Just wrong", "Neverclick", "True Neverclick", "Uncanny clicker",- "Early bird", "Fading luck", "Elder", "Rebirth", "Sacrifice", "Oblivion", "From scratch", "You win a cookie"]-MISC_DESC = ["Have at least 1 of every building.", "Have at least 100 of everything.", "Sell a grandma.",- "Make 1 million cookies by only having clicked 15 times.",- "Make 1 million cookies with no cookie clicks.", "Click really, really fast.",- "Click a golden cookie less than 1 second after it spawns.",- "Click a golden cookie less than 1 second before it dies.", "Own at least 7 grandma types.",- "Ascend at least once.", "Ascend with 1 million cookies baked.", "Ascend with 1 billion cookies baked.",- "Ascend with 1 trillion cookies baked.",- "This is for baking 100 trillion cookies and making it on the local news."]-MILK = ["Plain milk", "Chocolate milk", "Raspberry milk", "Orange milk", "Caramel milk", "Banana milk", "Lime milk"]--# ------------------------------------------------------------------ the news-LORE = [ # as the bakery grows: two for each power of ten from 1,000 cookies on- "You feel like making cookies. But nobody wants to eat your cookies.",- "Your first batch goes to the trash. The neighborhood raccoon barely touches it.",- "Your family agrees to try some of your cookies.",- "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",-]-GRANNY = ["\"Moist cookies.\" - grandma", "\"We're nice grandmas.\" - grandma", "\"Indentured servitude.\" - grandma",- "\"Come give grandma a kiss.\" - grandma", "\"Why don't you visit more often?\" - grandma",- "\"Call me...\" - grandma"]-BUILDING_NEWS = { # one for each building from the farm on- "Farm": "News : cookie farms suspected of employing undeclared elderly workforce!",- "Mine": "News : chocolate mines found to cause earthquakes and sinkholes!",- "Factory": "News : cookie factories linked to global warming!",- "Bank": "News : cookie loans on the rise as people can no longer afford them with regular money.",- "Temple": "News : theists of the world discover new cookie religion - \"Oh boy, guess we were wrong all along!\"",- "Wizard tower": "News : get your new charms and curses at the yearly National Spellcrafting Fair! Exclusive prices "- "on runes and spellbooks.",- "Shipment": "News : new chocolate planet found, becomes target of cookie-trading spaceships!",- "Alchemy lab": "News : national gold reserves dwindle as more and more of the precious mineral is turned to "- "cookies!",- "Portal": "News : nation worried as more and more unsettling creatures emerge from dimensional portals!",- "Time machine": "News : time machines involved in history-rewriting scandal! Or are they?",- "Antimatter condenser": "News : first antimatter condenser successfully turned on, doesn't rip apart reality!",- "Prism": "News : cookies now being baked at the literal speed of light thanks to new prismatic contraptions.",- "Chancemaker": "News : strange statistical anomalies continue as weather forecast proves accurate an "- "unprecedented 3 days in a row!",- "Fractal engine": "News : local man sails around the world to find himself - right where he left it.",- "Javascript console": "News : nation holds breath as nested ifs about to hatch.",- "Idleverse": "News : is another you living out their dreams in an alternate universe? Probably, you lazy bum!",- "Cortex baker": "News : are you smarter than a cortex baker? New game show deemed \"unfair\" by contestants.",- "You": "News : the person of the year is, this year again, you! How unexpected!",-}-MISC_NEWS = [ # once the bakery has made 10,000 cookies- "News : man robs bank, buys cookies.",- "News : doctors recommend twice-daily consumption of fresh cookies.",- "News : \"all-you-can-eat\" cookie restaurant opens in big city; waiters trampled in minutes.",- "News : cookie shortage strikes town, people forced to eat cupcakes; \"just not the same\", concedes mayor.",- "News : \"Ook\", says interviewed orangutan.",- "News : new cookie-based religion sweeps the nation.",- "News : what do golden cookies taste like? Study reveals a flavor \"somewhere between spearmint and liquorice\".",- "News : 97-year-old baker still makes cookies the old-fashioned way!",-]-KITTEN_NEWS = "News : faint meowing heard around local cookie facilities; suggests new ingredient being tested."--# ------------------------------------------------------------------ the store's pictures, 12 x 12-ICONS = {- "cursor": """-X...........-XX..........-XXX.........-XXXX........-XXXXX.......-XXXXXX......-XXXXXXX.....-XXXXXXXX....-XXXXX.......-XX.XXX......-X...XX......-.....XX.....""",- "grandma": """-....XXXX....-...XXXXXX...-.XXXXXXXXXX.-.XX......XX.-.X.XX..XX.X.-.XX..XX..XX.-.X........X.-.X..XXXX..X.-..X......X..-...XXXXXX...-..XXX..XXX..-.XXXXXXXXXX.""",- "farm": """-.....XX.....-...X.XX.X...-..XXXXXXXX..-.X..XXXX..X.-..XXXXXXXX..-...X.XX.X...-.....XX.....-..XX.XX.XX..-...XXXXXX...-.....XX.....-.....XX.....-XXXXXXXXXXXX""",- "mine": """-..XXXXXXXX..-.XXXXXXXXXX.-XX...XX...XX-X....XX....X-.....XX.....-.....XX.....-.....XX.....-.....XX.....-.....XX.....-.....XX.....-.....XX.....-.....XX.....""",- "factory": """-.XX.........-.XX.........-.XX.........-.XX..X...X..-.XX.XX..XX..-.XXXXX.XXX..-XXXXXXXXXXXX-XX.XX.XX.XXX-XX.XX.XX.XXX-XXXXXXXXXXXX-XXXXXXXXXXXX-XXXXXXXXXXXX""",- "bank": """-.....XX.....-...XXXXXX...-.XXXXXXXXXX.-XXXXXXXXXXXX-............-.XX.XX.XX.XX-.XX.XX.XX.XX-.XX.XX.XX.XX-.XX.XX.XX.XX-............-XXXXXXXXXXXX-XXXXXXXXXXXX""",- "temple": """-.....XX.....-....XXXX....-....X..X....-...XXXXXX...-...XXXXXX...-..XXXXXXXX..-..XXX..XXX..-.XXXX..XXXX.-.XXXXXXXXXX.-XXXXXXXXXXXX-XXXXXXXXXXXX-............""",- "wizard": """-......XX....-.....XXX....-.....XXXX...-....XXX.X...-....XX.XX...-...XXXXXXX..-...XX.XXXX..-..XXXXXX.XX.-..XXXXXXXXX.-XXXXXXXXXXXX-.XXXXXXXXXX.-............""",- "shipment": """-.....XX.....-....XXXX....-....XXXX....-...XX..XX...-...XX..XX...-...XXXXXX...-...XXXXXX...-..XXXXXXXX..-.XXXXXXXXXX.-XX.XXXXXX.XX-X...X..X...X-....X..X....""",- "alchemy": """-....XXXX....-.....XX.....-.....XX.....-.....XX.....-....X..X....-...X....X...-..X......X..-.X.XXXXXX.X.-X.XXXXXXXX.X-X.XXXXXXXX.X-X.XXXXXXXX.X-.XXXXXXXXXX.""",- "portal": """-...XXXXXX...-..XX....XX..-.XX..XX..XX.-XX..X..X..XX-X..X....X..X-X..X....X..X-X..X....X..X-X..X....X..X-XX..X..X..XX-.XX..XX..XX.-..XX....XX..-...XXXXXX...""",- "time": """-XXXXXXXXXXXX-.X........X.-.XX......XX.-..XXXXXXXX..-...XXXXXX...-....XXXX....-....X..X....-...X....X...-..X..XX..X..-.X.XXXXXX.X.-.XXXXXXXXXX.-XXXXXXXXXXXX""",- "antimatter": """-.....XX.....-..XX.XX.XX..-.X..X..X..X.-.X.X....X.X.-..XX.XX.XX..-XXX.XXXX.XXX-XXX.XXXX.XXX-..XX.XX.XX..-.X.X....X.X.-.X..X..X..X.-..XX.XX.XX..-.....XX.....""",- "prism": """-.....XX.....-.....XX.....-....XXXX....-....XXXX....-...XX..XX...-...XX..XX...-..XX....XX..-..XX....XX..-.XX......XX.-.XX......XX.-XXXXXXXXXXXX-XXXXXXXXXXXX""",- "chance": """-..XXX..XXX..-.XXXXX.XXXX.-.XXXXXXXXXX.-..XXXXXXXX..-XXXXX..XXXXX-XXXX....XXXX-XXXX....XXXX-XXXXX..XXXXX-..XXXXXXXX..-.XXXXXXXXXX.-.XXXX.XXXXX.-..XX...XXX..""",- "fractal": """-.....XX.....-....XXXX....-....X..X....-...XXXXXX...-..XX....XX..-..XXX..XXX..-.X..X..X..X.-.XXXXXXXXXX.-XX........XX-XXX......XXX-X..X....X..X-XXXXXXXXXXXX""",- "console": """-XXXXXXXXXXXX-X..........X-X.X........X-X..X.......X-X...X......X-X..X.......X-X.X........X-X.....XXXX.X-X..........X-XXXXXXXXXXXX-............-............""",- "idleverse": """-....XXXX....-..XXXXXXXX..-.XXXXXXXXXX.-.XXXXXXXXXX.-XXXXXXXXXXXX-............-XXXXXXXXXXXX-.XXXXXXXXXX.-.XXXXXXXXXX.-..XXXXXXXX..-....XXXX....-............""",- "cortex": """-...XX.XX....-..XXXXXXXX..-.XX.XX.XXXX.-XXXXX.XX.XXX-XX.XXXXXXX.X-XXXX.XX.XXXX-.XXXXXXXXXX.-..XX.XXXX...-.....XX.....-.....XX.....-............-............""",- "you": """-....XXXX....-...XXXXXX...-...XXXXXX...-...XXXXXX...-....XXXX....-............-..XXXXXXXX..-.XXXXXXXXXX.-XXXXXXXXXXXX-XXXXXXXXXXXX-XXXXXXXXXXXX-............""",- "mouse": """-....XXXX....-...X.XX.X...-..X..XX..X..-..X..XX..X..-..XXXXXXXX..-..X......X..-..X......X..-..X......X..-..X......X..-...X....X...-....XXXX....-............""",- "kitten": """-X..........X-XX........XX-XXX......XXX-XXXXXXXXXXXX-XXXXXXXXXXXX-XX..XXXX..XX-XX..XXXX..XX-XXXXXXXXXXXX-XXXXX..XXXXX-.XXXXXXXXXX.-..XXXXXXXX..-............""",-}---def icon_bytes(art):- rows = art.strip().split("\n")- assert len(rows) == 12 and all(len(r) == 12 for r in rows), art- bits = [c == "X" for r in rows for c in r]- out = []- for i in range(0, 144, 8): # lowest bit first- out.append(sum(1 << k for k in range(8) if bits[i + k]))- return out---# How much of the game fits in NumPlay (13 KB): the upgrades, achievements and news that come first, so-# far that milk (an achievement is 4%) takes the kittens to the engineers-N = dict(cursor=8, mouse=6, kitten=3, cookie=8, bank=13, cps=10, click=6, cursor_ach=3, golden=4, owned=2,- upgraded=2, milk=3, lore=9)-MISC_KEPT = []---def main():- order = [b for b in BUILDINGS[1:]]- cookies = COOKIES[:N["cookie"]]- misc = [MISC[i] for i in MISC_KEPT]- ups = CURSOR[:N["cursor"]] + MOUSE[:N["mouse"]] + KITTEN[:N["kitten"]] + GOLD + [c[0] for c in cookies]- for b in order:- ups += TIERED[b][:TIER_N]- achs = BANK[:N["bank"]] + CPS[:N["cps"]] + CLICK[:N["click"]] + CURSOR_ACH[:N["cursor_ach"]]- for b in order:- achs += BUILDING_ACH[b][:ACH_TIERS]- achs += GOLDEN[:N["golden"]] + OWNED[:N["owned"]] + UPGRADED[:N["upgraded"]] + misc- # a line for each power of ten of the bakery's fame- news = [LORE[i] for i in [0, 1, 2] + list(range(3, 27, 2))][:N["lore"]]- assert len(MISC_DESC) == len(MISC)- strings = ups + achs + news + [MISC_DESC[i] for i in MISC_KEPT] + MILK[:N["milk"]]- names = list(ICONS)- data = [b for n in names for b in icon_bytes(ICONS[n])]- text = "\0".join(strings).encode("ascii") + b"\0"- icons_at = len(text)- text += bytes(data) # the pictures, packed with them- z = zopfli.zlib.compress(text, numiterations=100)[2:-4]- raw = len(text)- L = ["/* Made by tools/data.py: Cookie Clicker's names, news and the store's pictures. */",- "#define TIER_N %d" % TIER_N, "#define ACH_TIERS %d" % ACH_TIERS,- "/* the upgrades, in the order of the save */",- "#define N_CURSOR %d" % N["cursor"], "#define U_MOUSE N_CURSOR", "#define N_MOUSE %d" % N["mouse"],- "#define U_KITTEN (U_MOUSE + N_MOUSE)", "#define N_KITTEN %d" % N["kitten"],- "#define U_GOLD (U_KITTEN + N_KITTEN)",- "#define U_COOKIE (U_GOLD + 3)", "#define N_COOKIE %d" % len(cookies),- "#define U_TIER (U_COOKIE + N_COOKIE)", "#define N_UP (U_TIER + 19 * TIER_N)",- "/* the achievements, in the order of the save */",- "#define N_BANK %d" % N["bank"], "#define A_CPS N_BANK", "#define N_CPS %d" % N["cps"],- "#define A_CLICK (A_CPS + N_CPS)", "#define N_CLICK %d" % N["click"],- "#define A_BUILD (A_CLICK + N_CLICK) /* the cursor's, then ACH_TIERS for each other building */",- "#define N_CURSOR_ACH %d" % N["cursor_ach"],- "#define A_GOLDEN (A_BUILD + N_CURSOR_ACH + 19 * ACH_TIERS)", "#define N_GOLDEN %d" % N["golden"],- "#define A_OWNED (A_GOLDEN + N_GOLDEN)", "#define A_UPGRADED (A_OWNED + %d)" % N["owned"],- "#define A_MISC (A_UPGRADED + %d)" % N["upgraded"], "#define N_ACH (A_MISC + %d)" % len(misc),- "/* the texts: the upgrades' names, the achievements', the news, the other achievements'",- " descriptions, the milks; then the pictures, 18 bytes each (12 x 12 bits, the first lowest) */",- "#define X_ACH N_UP", "#define X_NEWS (X_ACH + N_ACH)",- "#define N_LORE %d" % len(news),- "#define X_MDESC (X_NEWS + N_LORE)", "#define X_MILK (X_MDESC + %d)" % len(misc),- "#define N_MILK %d" % N["milk"], "#define N_TEXT %d" % len(strings), "#define ICONS_AT %d" % icons_at,- "#define TEXT_SIZE %d" % raw]- COOKIES[:] = cookies- # a cookie upgrade: its % in the top 3 bits, then 5 if it is so many nines times 5, then the nines- L.append("static const uint8_t cookie_up[N_COOKIE] = {%s};" %- ", ".join(str(p << 5 | x5 << 4 | (n - 5)) for _, p, n, x5 in COOKIES))- assert all(1 <= p <= 7 and 5 <= n < 21 for _, p, n, _ in COOKIES)- L.append("enum { %s };" % ", ".join("IC_" + n.upper() for n in names))- L.append("static const uint8_t text_z[%d] = {" % len(z))- for i in range(0, len(z), 24):- L.append(" " + ", ".join(str(b) for b in z[i:i + 24]) + ",")- L.append("};")- open(OUT, "w").write("\n".join(L) + "\n")- print(f"data.h: {len(ups)} upgrades, {len(achs)} achievements, {len(news)} news; "- f"text {raw} bytes, packed {len(z)}; icons {len(data)} bytes")---if __name__ == "__main__":- main()diff --git a/games/cookieclicker/tools/extract.js b/games/cookieclicker/tools/extract.jsnew file mode 100644index 00000000..1b7f24d4--- /dev/null+++ b/games/cookieclicker/tools/extract.js@@ -0,0 +1,138 @@+#!/usr/bin/env node+// Runs the game's own main.js (and its English texts) with a pretend web page, then writes what it+// defines as JSON: the buildings, upgrades, achievements, tiers, the heavenly upgrades' tree, the+// golden cookie effects, the dragon's auras, the minigames' spells, gods and plants.+//+// node tools/extract.js REF OUT.json (REF: the folder tools/fetch.py filled)+'use strict';+const fs = require('fs');+const path = require('path');+const vm = require('vm');++const ref = process.argv[2], out = process.argv[3];+if (!ref || !out) { console.error('node tools/extract.js REF OUT.json'); process.exit(1); }++// a page where every element, style, canvas and event exists and does nothing+function any(name) {+ const f = function () { return any(name + '()'); };+ return new Proxy(f, {+ get(t, k) {+ if (k === Symbol.toPrimitive) return () => '';+ if (k === 'toString' || k === 'valueOf') return () => '';+ if (k === 'length') return 0;+ if (k === 'then') return undefined;+ if (k in t) return t[k];+ t[k] = any(name + '.' + String(k));+ return t[k];+ },+ set(t, k, v) { t[k] = v; return true; },+ apply() { return any(name + '()'); },+ construct() { return any('new ' + name); },+ });+}+const store = {};+const ctx = {+ console, // (the built-ins are the context's own: an array the game makes must be its Array)+ setTimeout: () => 0, setInterval: () => 0, clearTimeout: () => 0, clearInterval: () => 0,+ requestAnimationFrame: () => 0,+ localStorage: { getItem: k => store[k] || null, setItem: (k, v) => { store[k] = String(v); }, removeItem: () => 0 },+ navigator: { userAgent: 'node', language: 'en' },+ location: { href: 'https://orteil.dashnet.org/cookieclicker/', pathname: '/cookieclicker/', hostname: 'x' },+ document: any('document'), Image: function () { return any('img'); }, Audio: function () { return any('audio'); },+ btoa: s => Buffer.from(s, 'binary').toString('base64'), atob: s => Buffer.from(s, 'base64').toString('binary'),+ URL, URLSearchParams, XMLHttpRequest: function () { return any('xhr'); }, performance: { now: () => 0 },+ App: 0, PRESETMODS: [], VERSION: 2.058, BETA: 0, SAVESUFFIX: "", DEV: 0, LOCAL: false, Steam: undefined, greenworks: undefined,+};+for (const k of ['Element', 'HTMLElement', 'HTMLCanvasElement', 'CanvasRenderingContext2D', 'Event', 'Node'])+ ctx[k] = function () {};+for (const k of ['addEventListener', 'removeEventListener', 'scrollTo', 'getComputedStyle', 'matchMedia', 'open',+ 'alert', 'confirm', 'prompt', 'focus', 'blur', 'postMessage', 'dispatchEvent'])+ ctx[k] = () => any(k + '()');+Object.assign(ctx, { innerWidth: 1280, innerHeight: 720, devicePixelRatio: 1, screen: { width: 1280, height: 720 } });+ctx.window = ctx;+ctx.top = ctx;+ctx.self = ctx;+ctx.document.getElementById = () => any('el');+vm.createContext(ctx);+const run = (file) => vm.runInContext(fs.readFileSync(path.join(ref, file), 'utf8'), ctx, { filename: file });+run('main.js');+run('loc/EN.js');+vm.runInContext('locStringsFallback=locStrings;EN=true;Game.mods={};Game.sortedMods=[];Game.brokenMods=[];' ++ 'Game.modSaveData={};Game.modHooks={};for (var i=0;i<Game.modHooksNames.length;i++)Game.modHooks[Game.modHooksNames[i]]=[];' ++ 'Game.Launch();Game.Loader=new Loader();Game.Init();', ctx);+for (const m of ['Grimoire', 'Garden', 'Pantheon', 'Market']) run('minigame' + m + '.js');++const G = ctx.Game;+const fn = (f) => (typeof f === 'function' ? String(f) : undefined);+const num = (v) => (typeof v === 'number' ? v : undefined);+const vals = (o) => (Array.isArray(o) ? o : Object.values(o));+const data = {};+data.objects = vals(G.ObjectsById).map(o => ({+ id: o.id, name: o.name, single: o.single, plural: o.plural, actionName: o.actionName, extraName: o.extraName,+ extraPlural: o.extraPlural, desc: o.desc, basePrice: o.basePrice, baseCps: o.baseCps, icon: o.icon,+ iconColumn: o.iconColumn, art: o.art ? { base: o.art.base, xV: o.art.xV, yV: o.art.yV, w: o.art.w, rows: o.art.rows,+ x: o.art.x, y: o.art.y, pic: typeof o.art.pic === 'string' ? o.art.pic : fn(o.art.pic), bg: o.art.bg,+ frames: o.art.frames } : null,+ minigameUrl: o.minigameUrl, minigameName: o.minigameName, tieredUpgrades: Object.keys(o.tieredUpgrades || {}),+ synergies: (o.synergies || []).map(u => u.name), fortune: o.fortune ? o.fortune.name : null,+ grandma: o.grandma ? o.grandma.name : null, cps: fn(o.cps), buyFunction: fn(o.buyFunction),+}));+data.upgrades = vals(G.UpgradesById).map(u => ({+ id: u.id, name: u.name, dname: u.dname, desc: u.desc, ddesc: u.ddesc, basePrice: u.basePrice,+ priceFunc: fn(u.priceFunc), icon: u.icon, iconFunction: fn(u.iconFunction), pool: u.pool, order: u.order,+ tier: u.tier, buildingTie: u.buildingTie ? u.buildingTie.name : null, buildingTie1: u.buildingTie1 ? u.buildingTie1.name : null,+ buildingTie2: u.buildingTie2 ? u.buildingTie2.name : null, power: typeof u.power === 'function' ? fn(u.power) : u.power,+ kitten: u.kitten, unlockAt: u.unlockAt ? { cookies: u.unlockAt.cookies, require: u.unlockAt.require, season: u.unlockAt.season,+ name: u.unlockAt.name } : null, season: u.season, parents: (u.parents || []).map(p => p.name), posX: u.posX, posY: u.posY,+ showIf: fn(u.showIf), choicesFunction: fn(u.choicesFunction), buyFunction: fn(u.buyFunction), lasting: u.lasting,+ descFunc: fn(u.descFunc), displayFuncWhenOwned: fn(u.displayFuncWhenOwned), timerDisplay: fn(u.timerDisplay),+ activateFunction: fn(u.activateFunction), vanilla: u.vanilla, hide: u.hide, isVaulted: undefined,+ require: typeof u.require === 'string' ? u.require : (u.require && u.require.name) || undefined,+}));+data.achievements = vals(G.AchievementsById).map(a => ({+ id: a.id, name: a.name, dname: a.dname, desc: a.desc, ddesc: a.ddesc, icon: a.icon, pool: a.pool, order: a.order,+ tier: a.tier, buildingTie: a.buildingTie ? a.buildingTie.name : null, vanilla: a.vanilla,+}));+data.tiers = Object.fromEntries(Object.entries(G.Tiers).map(([k, t]) => [k, { name: t.name, unlock: t.unlock,+ achievUnlock: t.achievUnlock, iconRow: t.iconRow, color: t.color, price: t.price, special: t.special, req: t.req }]));+data.goldenChoices = fn(G.shimmerTypes.golden.popFunc);+data.buffTypes = Object.keys(G.buffTypesByName || {});+data.dragonLevels = (G.dragonLevels || []).map(l => ({ name: l.name, action: l.action, pic: l.pic, cost: fn(l.cost),+ buy: fn(l.buy), costStr: fn(l.costStr) }));+data.dragonAuras = Object.values(G.dragonAuras || {}).map(a => ({ name: a.name, desc: a.desc, pic: a.pic }));+data.milks = (G.Milks || []).map(m => ({ name: m.name, bname: m.bname, pic: m.pic, icon: m.icon }));+// what ties the tables together: by id+const uid = (u) => (u ? (typeof u === 'string' ? (G.Upgrades[u] ? G.Upgrades[u].id : -1) : u.id) : -1);+const aid = (a) => (a ? (typeof a === 'string' ? (G.Achievements[a] ? G.Achievements[a].id : -1) : a.id) : -1);+data.links = {+ objects: vals(G.ObjectsById).map(o => ({+ tieredUpgrades: Object.fromEntries(Object.entries(o.tieredUpgrades || {}).map(([t, u]) => [t, u.id])),+ tieredAchievs: Object.fromEntries(Object.entries(o.tieredAchievs || {}).map(([t, a]) => [t, a.id])),+ synergies: (o.synergies || []).map(u => u.id), fortune: uid(o.fortune), grandma: uid(o.grandma),+ unshackle: uid(o.unshackleUpgrade), level10: aid(o.levelAchiev10), production: (o.productionAchievs || []).map(p => [p.pow, p.achiev.id]),+ })),+ tierUnshackle: Object.fromEntries(Object.entries(G.Tiers).map(([k, t]) => [k, uid(t.unshackleUpgrade)])),+ cookieUpgrades: (G.cookieUpgrades || []).map(u => u.id),+ bank: (G.BankAchievements || []).map(a => [a.threshold, a.id]),+ cps: (G.CpsAchievements || []).map(a => [a.threshold, a.id]),+ unlockAt: (G.UnlockAt || []).map(u => ({ cookies: u.cookies, up: uid(u.name), ach: aid(u.name),+ requireUp: uid(u.require), requireAch: aid(u.require), season: u.season || null })),+ grandmaSynergies: (G.GrandmaSynergies || []).map(uid),+ kittens: ((G.UpgradesByPool || {}).kitten || []).map(u => u.id),+ goldenCookieUpgrades: (G.goldenCookieUpgrades || []).map(uid),+ lasting: vals(G.UpgradesById).filter(u => u.lasting).map(u => u.id),+ noPerm: vals(G.UpgradesById).filter(u => u.noPerm).map(u => u.id),+ priceLumps: vals(G.UpgradesById).filter(u => u.priceLumps).map(u => [u.id, u.priceLumps]),+ toggleInto: vals(G.UpgradesById).filter(u => u.toggleInto).map(u => [u.id, uid(u.toggleInto)]),+ showIf: vals(G.UpgradesById).filter(u => u.showIf).map(u => u.id),+ requiresConfirmation: vals(G.UpgradesById).filter(u => u.clickFunction).map(u => u.id),+ heavenly: (G.PrestigeUpgrades || []).map(u => u.id),+ easterEggs: (G.easterEggs || []).map(uid), halloweenDrops: (G.halloweenDrops || []).map(uid),+ heartDrops: (G.heartDrops || []).map(uid), santaDrops: (G.santaDrops || []).map(uid),+ reindeerDrops: (G.reindeerDrops || []).map(uid), seasons: Object.fromEntries(Object.entries(G.seasons || {}).map(+ ([k, s]) => [k, { name: s.name, start: s.start, over: s.over, trigger: uid(s.trigger) }])),+ fortuneTier: (G.Tiers.fortune.upgrades || []).map(u => u.id),+};+fs.writeFileSync(out, JSON.stringify(data, null, 1));+console.log(`extract: ${data.objects.length} buildings, ${data.upgrades.length} upgrades, ` ++ `${data.achievements.length} achievements, ${Object.keys(data.tiers).length} tiers, ${data.milks.length} milks`);diff --git a/games/cookieclicker/tools/fetch.py b/games/cookieclicker/tools/fetch.pynew file mode 100644index 00000000..31552d6b--- /dev/null+++ b/games/cookieclicker/tools/fetch.py@@ -0,0 +1,97 @@+#!/usr/bin/env python3+"""Gathers the public material the pack is made from, into REF (not committed):++ python3 -I tools/fetch.py REF++- REF/main.js, REF/minigame*.js, REF/loc/EN.js, REF/style.css: the game itself (version 2.058), as the mirror+ github.com/ozh/cookieclicker keeps it at the commit below; tools/extract.js runs it for its numbers and texts+- REF/img/...: its pictures: the big cookie and its shine, the backgrounds, milks, buildings, icons, golden and+ wrath cookies, wrinklers, sugar lumps, the dragon, the heavenly upgrades' sky, the minigames' backgrounds+- REF/fonts/: Merriweather, Kavoon and Noto Sans (SIL Open Font License), from Google Fonts++Files already there are kept: run it again to fetch only what is missing."""+import os+import sys+import time+import urllib.request++GAME = "https://raw.githubusercontent.com/ozh/cookieclicker/c77f00c51854a667da35a3135120797a579c2d72/"+FONTS = {+ "Merriweather.ttf": "https://raw.githubusercontent.com/google/fonts/main/ofl/merriweather/"+ "Merriweather%5Bopsz%2Cwdth%2Cwght%5D.ttf",+ "Kavoon.ttf": "https://raw.githubusercontent.com/google/fonts/main/ofl/kavoon/Kavoon-Regular.ttf",+ "NotoSans.ttf": "https://raw.githubusercontent.com/google/fonts/main/ofl/notosans/NotoSans%5Bwdth%2Cwght%5D.ttf",+ "NotoSans-Italic.ttf": "https://raw.githubusercontent.com/google/fonts/main/ofl/notosans/"+ "NotoSans-Italic%5Bwdth%2Cwght%5D.ttf",+}+SCRIPTS = ["main.js", "minigameGrimoire.js", "minigameGarden.js", "minigamePantheon.js", "minigameMarket.js",+ "loc/EN.js", "style.css"]+BUILDINGS = ["grandma", "farm", "mine", "factory", "bank", "temple", "wizardtower", "shipment", "alchemylab", "portal",+ "timemachine", "antimattercondenser", "prism", "chancemaker", "fractalEngine", "javascriptconsole",+ "idleverse", "cortex", "you"]+GRANDMAS = ["farmerGrandma", "workerGrandma", "minerGrandma", "cosmicGrandma", "transmutedGrandma", "alteredGrandma",+ "grandmasGrandma", "antiGrandma", "rainbowGrandma", "bankGrandma", "templeGrandma", "witchGrandma",+ "luckyGrandma", "metaGrandma", "scriptGrandma", "alternateGrandma", "brainyGrandma", "cloneGrandma",+ "elfGrandma", "bunnyGrandma"]+MILKS = ["Plain", "Chocolate", "Raspberry", "Orange", "Caramel", "Banana", "Lime", "Blueberry", "Strawberry",+ "Vanilla", "Honey", "Coffee", "Tea", "Coconut", "Cherry", "Spiced", "Maple", "Mint", "Licorice", "Rose",+ "Dragonfruit", "Melon", "Blackcurrant", "Peach", "Hazelnut"]+IMAGES = [+ "perfectCookie.png", "cookieShadow.png", "flare.png", "flareGold.png", "flareSuckRed.png", "shine.png",+ "shineSpoke.png", "glint.png", "bgBlue.jpg", "grandmas1.jpg", "grandmas2.jpg", "grandmas3.jpg", "darkNoise.jpg",+ "shadedBordersSoft.png", "shadedBordersGold.png", "shadedBordersRed.png", "cookieShower1.png",+ "cookieShower2.png", "cookieShower3.png", "smallCookies.png", "cursor.png", "goldCookie.png", "wrathCookie.png",+ "buildings.png", "icons.png", "storeTile.jpg", "money.png", "upgradeFrame.png", "panelVertical.png",+ "panelHorizontal.png", "brokenCookie.png", "brokenCookieHalo.png", "heavenRing1.jpg", "heavenRing2.jpg",+ "starbg.jpg", "heavenlyMoney.png", "wrinkler.png", "shinyWrinkler.png", "wrinklerBits.png",+ "shinyWrinklerBits.png", "wrinklerShadow.png", "wrinklerBlink.png", "wrinklerGooglies.png", "sugarLump.png",+ "dragon.png", "dragonBG2.png", "shimmeringVeil.png", "BGgrimoire.jpg", "BGpantheon.jpg", "BGgarden.jpg",+ "BGmarket.jpg", "gardenPlants.png", "gardenPlots.png", "spellBG.png", "spinnyBig.png", "spinnySmall.png",+ "levelUp.png", "imperfectCookie.png", "youBackground.png", "elfGrandma.png", "frameBorder.png", "santa.png",+ "frostedReindeer.png", "goldCookieWreath.png", "wrathCookieWreath.png", "hearts.png", "bunnies.png",+ "spookyCookie.png", "contract.png", "wrathContract.png", "familiars.png",+ "ascendSlot.png",+] + [b + ".png" for b in BUILDINGS] + [b + "Background.png" for b in BUILDINGS if b != "you"] + [+ g + ".png" for g in GRANDMAS] + ["milk" + m + ".png" for m in MILKS]+++def get(url, tries=4):+ for t in range(tries):+ try:+ with urllib.request.urlopen(url, timeout=120) as r:+ return r.read()+ except urllib.error.HTTPError as e:+ if e.code == 404:+ return None+ if t == tries - 1:+ raise SystemExit(f"fetch: {url}: {e}")+ except Exception as e:+ if t == tries - 1:+ raise SystemExit(f"fetch: {url}: {e}")+ time.sleep(2 << t)+++def main(ref):+ jobs = [(GAME + p, os.path.join(ref, p)) for p in SCRIPTS]+ jobs += [(GAME + "img/" + p, os.path.join(ref, "img", p)) for p in dict.fromkeys(IMAGES)]+ jobs += [(url, os.path.join(ref, "fonts", name)) for name, url in FONTS.items()]+ missing = []+ for url, dst in jobs:+ if os.path.exists(dst) and os.path.getsize(dst):+ continue+ os.makedirs(os.path.dirname(dst), exist_ok=True)+ data = get(url)+ if data is None:+ missing.append(url)+ continue+ with open(dst, "wb") as f:+ f.write(data)+ print(f"{len(data):9d} {dst}")+ for url in missing:+ print("not found:", url)+++if __name__ == "__main__":+ if len(sys.argv) != 2:+ raise SystemExit(__doc__)+ main(sys.argv[1])diff --git a/games/cookieclicker/tools/icon.py b/games/cookieclicker/tools/icon.pydeleted file mode 100644index e3badbcd..00000000--- a/games/cookieclicker/tools/icon.py+++ /dev/null@@ -1,30 +0,0 @@-#!/usr/bin/env python3-"""src/icon.png: the big cookie on Cookie Clicker's blue, as the calculator's home screen shows apps."""-import os--from PIL import Image, ImageDraw--S = 8 # drawn 8 times larger, then scaled down smoothly-W, H = 55, 56-img = Image.new("RGBA", (W * S, H * S), (0, 0, 0, 0))-d = ImageDraw.Draw(img)-d.rounded_rectangle([0, 0, W * S - 1, H * S - 1], radius=12 * S, fill=(38, 74, 116, 255))-d.rounded_rectangle([0, 0, W * S - 1, H * S // 2], radius=12 * S, fill=(52, 96, 146, 255))-d.rectangle([0, H * S // 4, W * S - 1, H * S // 2], fill=(52, 96, 146, 255))-cx, cy, r = 27.5 * S, 28 * S, 22 * S---def disc(x, y, rr, fill):- d.ellipse([x - rr, y - rr, x + rr, y + rr], fill=fill)---disc(cx, cy + 1.5 * S, r, (60, 32, 12, 120)) # its shadow-disc(cx, cy, r, (156, 91, 38, 255))-disc(cx - 0.5 * S, cy - 0.5 * S, r - 1.6 * S, (217, 162, 94, 255))-disc(cx - 5 * S, cy - 5 * S, r * 0.5, (232, 186, 124, 255))-for x, y, rr in [(-10, -11, 4.2), (6, -14, 3.2), (14, -1, 4.2), (-15, 3, 3.2), (-3, 2, 4.6), (8, 10, 3.6),- (-7, 13, 3.6), (1, -6, 2.4)]:- disc(cx + x * S, cy + y * S, rr * S, (75, 38, 17, 255))- disc(cx + (x - rr / 3) * S, cy + (y - rr / 3) * S, rr * S / 3, (120, 72, 40, 255))-img = img.resize((W, H), Image.LANCZOS)-img.save(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "src", "icon.png"))diff --git a/games/cookieclicker/tools/pack.py b/games/cookieclicker/tools/pack.pynew file mode 100644index 00000000..54b5e856--- /dev/null+++ b/games/cookieclicker/tools/pack.py@@ -0,0 +1,604 @@+#!/usr/bin/env python3+"""Cookie Clicker's numbers, texts, pictures and fonts -> src/data.bin + src/data.h.++ node tools/extract.js REF build/game.json+ python3 -I tools/pack.py REF build/game.json (REF: the folder tools/fetch.py filled)++The game's left column (about 384 pixels wide in a browser) is drawn at 0.37 of its size, its store at about half.++data.bin, read where it lies in flash (offsets from its start; data.h names them):+- IMAGES: 16 bytes each (IM_*): w, h (u16), format (u8: 0 RGB565, 1 a byte a pixel, 2 half a byte a pixel, the+ first pixel lowest), colours - 1 (u8), 0 (u16), the pixels' offset, the palette's (u32): its colours (RGB565),+ then their opacities (u8 each)+- ICONS: the game's icon sheet (icons.png, 36 x 37 icons of 48 pixels) at 24 pixels: an image index (u16, 0xFFFF+ none) for each icon, row by row+- FONTS: the offset (u32) of each (F_*): first character, count, ascent, line height (u8 x 4), then 8 bytes a glyph+ (w, h, x, y from the baseline, advance (u8, u8, s8, s8, u8), 0, its data's offset from the glyphs' end (u16)):+ 4-bit coverage, 2 pixels a byte, rows padded to a byte+- TEXT: the texts, one byte a character (ASCII, and the few others they use from 0x80: see CHARS), each ending+ with 0. In them: 0x01 bold, 0x02 back to plain, 0x03 italic, 0x04 back, 0x05 a line across, \\n a new line,+ 0x06 nothing (it keeps two numbers apart when the game rewrites numbers: src/text.c)+- the tables of the game's buildings, upgrades, achievements and tiers (their C structures are in data.h)+"""+import html+import json+import math+import os+import re+import struct+import sys++import numpy as np+from PIL import Image, ImageFont++HERE = os.path.dirname(os.path.abspath(__file__))+OUT_BIN = os.path.join(HERE, "..", "src", "data.bin")+OUT_H = os.path.join(HERE, "..", "src", "data.h")+S = 0.37 # the left column's pictures (the big cookie: 256 -> 95 pixels)++# the characters past ASCII the texts and fonts have, from 0x80 on+CHARS = "éèêëàâäïîôöûüùçñÉÀ×÷°•…’‘“”–—½¼¾²³™©®♥"+++# ------------------------------------------------------------------ pictures+def rgb565(r, g, b):+ return (int(r) >> 3) << 11 | (int(g) >> 2) << 5 | int(b) >> 3+++def premul_resize(img, size, box=None):+ """an RGBA picture resized without dark fringes (its colours weighted by their opacity)"""+ img = img.convert("RGBA")+ if box:+ img = img.crop(box)+ a = np.asarray(img).astype(np.float32) / 255+ a[..., :3] *= a[..., 3:4]+ pm = Image.fromarray((a * 255 + 0.5).astype(np.uint8), "RGBA").resize(size, Image.LANCZOS)+ b = np.asarray(pm).astype(np.float32) / 255+ al = b[..., 3:4]+ b[..., :3] = np.where(al > 0, b[..., :3] / np.maximum(al, 1e-6), 0)+ return Image.fromarray((np.clip(b, 0, 1) * 255 + 0.5).astype(np.uint8), "RGBA")+++def quantize(img, n):+ """palette (RGBA tuples) and indices, at most n colours; the fully clear pixels all at index 0"""+ arr = np.asarray(img.convert("RGBA"))+ clear = arr[..., 3] < 8+ if clear.all():+ return [(0, 0, 0, 0)], np.zeros(arr.shape[:2], np.uint8)+ q = img.convert("RGBA").quantize(n - (1 if clear.any() else 0), method=Image.Quantize.FASTOCTREE)+ pal = q.getpalette("RGBA")+ if pal is None: # (Pillow keeps the alpha in the palette of an RGBA quantize)+ raise SystemExit("pack: no RGBA palette")+ idx = np.asarray(q).astype(np.int32)+ used = sorted(set(idx[~clear].ravel().tolist()))+ remap = {}+ out_pal = [(0, 0, 0, 0)] if clear.any() else []+ for u in used:+ remap[u] = len(out_pal)+ out_pal.append(tuple(pal[4 * u:4 * u + 4]))+ out = np.zeros(idx.shape, np.uint8)+ for u, v in remap.items():+ out[idx == u] = v+ out[clear] = 0+ return out_pal, out+++class Pack:+ def __init__(self):+ self.blob = bytearray(b"CCK1")+ self.images = [] # (name, w, h, fmt, ncolors, px_off, pal_off)+ self.names = {}+ self.defines = []+ self.sizes = {} # bytes by group of pictures, for the report++ def align(self, n=4):+ while len(self.blob) % n:+ self.blob.append(0)++ def put(self, data, align=4):+ self.align(align)+ off = len(self.blob)+ self.blob += data+ return off++ def image(self, name, img, fmt="p8", ncolors=256):+ """adds a picture; returns its index"""+ w, h = img.size+ start = len(self.blob)+ if fmt == "rgb":+ arr = np.asarray(img.convert("RGB")).astype(np.uint16)+ px = ((arr[..., 0] >> 3) << 11 | (arr[..., 1] >> 2) << 5 | arr[..., 2] >> 3).astype("<u2")+ off = self.put(px.tobytes())+ rec = (name, w, h, 0, 1, off, 0)+ else:+ n = 16 if fmt == "p4" else ncolors+ pal, idx = quantize(img, n)+ pal_bytes = b"".join(struct.pack("<H", rgb565(*c[:3])) for c in pal) + bytes(c[3] for c in pal)+ pal_off = self.put(pal_bytes)+ if fmt == "p4":+ if w % 2:+ idx = np.concatenate([idx, np.zeros((h, 1), np.uint8)], 1)+ packed = (idx[:, 0::2] | idx[:, 1::2] << 4).astype(np.uint8)+ off = self.put(packed.tobytes())+ rec = (name, w, h, 2, len(pal), off, pal_off)+ else:+ off = self.put(idx.astype(np.uint8).tobytes())+ rec = (name, w, h, 1, len(pal), off, pal_off)+ if name:+ if name in self.names:+ raise SystemExit(f"pack: two pictures named {name}")+ self.names[name] = len(self.images)+ group = re.sub(r"(_.*|\d+)$", "", name) if name else "ICONS"+ self.sizes[group] = self.sizes.get(group, 0) + len(self.blob) - start+ self.images.append(rec)+ return len(self.images) - 1+++def load(ref, rel):+ return Image.open(os.path.join(ref, "img", rel)).convert("RGBA")+++def scaled(ref, rel, size, box=None):+ return premul_resize(load(ref, rel), size, box)+++def opaque(ref, rel, size, box=None):+ img = Image.open(os.path.join(ref, "img", rel)).convert("RGB")+ if box:+ img = img.crop(box)+ return img.resize(size, Image.LANCZOS)+++# ------------------------------------------------------------------ fonts+def load_font(path, size, axes=None):+ f = ImageFont.truetype(path, size)+ if axes:+ f.set_variation_by_axes(axes)+ return f+++def font_bytes(f, chars, line=None):+ """first character 32, all of CHARS mapped from 0x80 on"""+ asc, desc = f.getmetrics()+ glyphs, data = [], bytearray()+ for ch in chars:+ if ch is None:+ glyphs.append((0, 0, 0, 0, 0, len(data)))+ continue+ adv = int(round(f.getlength(ch)))+ mask, off = f.getmask2(ch, mode="L", anchor="ls")+ w, h = mask.size+ if w == 0 or h == 0:+ glyphs.append((0, 0, 0, 0, adv, len(data)))+ continue+ a = np.asarray(Image.frombytes("L", (w, h), bytes(mask))).astype(np.int32)+ a4 = (a * 15 + 127) // 255+ ys, xs = np.nonzero(a4)+ if len(xs) == 0:+ glyphs.append((0, 0, 0, 0, adv, len(data)))+ continue+ x0, x1, y0, y1 = xs.min(), xs.max() + 1, ys.min(), ys.max() + 1+ a4 = a4[y0:y1, x0:x1]+ gw, gh = x1 - x0, y1 - y0+ if gw % 2:+ a4 = np.concatenate([a4, np.zeros((gh, 1), np.int32)], 1)+ packed = (a4[:, 0::2] | a4[:, 1::2] << 4).astype(np.uint8)+ glyphs.append((gw, gh, off[0] + x0, off[1] + y0, adv, len(data)))+ data += packed.tobytes()+ if len(data) > 0xFFFF:+ raise SystemExit("pack: a font's glyphs past 64 KB")+ out = bytearray(struct.pack("<BBBB", 32, len(chars), asc, line or (asc + desc)))+ for gw, gh, gx, gy, adv, o in glyphs:+ out += struct.pack("<BBbbBBH", gw, gh, gx, gy, adv, 0, o)+ return out + data+++FONT_CHARS = [chr(c) for c in range(32, 127)] + [None] + list(CHARS)+++def char_code(c):+ if 32 <= ord(c) < 127 or c == "\n":+ return ord(c)+ i = CHARS.find(c)+ return 0x80 + i if i >= 0 else None+++# ------------------------------------------------------------------ texts+ENTITIES = {"•": "•", " ": " ", "é": "é", "°": "°", "®": "®", "à": "à"}+UNKNOWN = {}+++def beautify_int(n):+ return f"{n:,}"+++def beautify_in_text(s):+ # the game's BeautifyInText: every run of digits (and commas) written again with commas+ return re.sub(r"(([\d]+[,]*)+)", lambda m: beautify_int(int(m.group(0).replace(",", "") or 0))+ if m.group(0).replace(",", "").isdigit() else m.group(0), s)+++def clean(s, numbers=True):+ """the game's HTML as the calculator's markup (see the TEXT table)"""+ if s is None:+ return ""+ s = s.replace("\r", "").replace("\t", "")+ s = s.replace("<span></span>", "\x06") # (keeps two numbers apart: see text.c)+ s = re.sub(r"<div class=\"line\"></div>", "\x05", s)+ s = re.sub(r"<br\s*/?>", "\n", s)+ s = re.sub(r"</?(b|strong)>", lambda m: "\x02" if m.group(0).startswith("</") else "\x01", s)+ s = re.sub(r"</?(i|q|em)>", lambda m: "\x04" if m.group(0).startswith("</") else "\x03", s)+ s = re.sub(r"<div[^>]*>", "\n", s)+ s = re.sub(r"</div>", "\n", s)+ s = re.sub(r"<[^>]*>", "", s)+ for k, v in ENTITIES.items():+ s = s.replace(k, v)+ s = html.unescape(s)+ out = []+ for c in s:+ if c in "\x01\x02\x03\x04\x05\x06":+ out.append(c)+ continue+ if unicodedata_combining(c):+ continue+ code = char_code(c)+ if code is None:+ UNKNOWN[c] = UNKNOWN.get(c, 0) + 1+ out.append("?")+ else:+ out.append(chr(code))+ s = "".join(out)+ s = re.sub(r"\n{2,}", "\n", s).strip("\n")+ return s+++def unicodedata_combining(c):+ import unicodedata+ return unicodedata.combining(c) != 0+++def split_quote(s):+ """a description and its quote (the game's <q>, said in italics)"""+ if s is None:+ return "", ""+ m = re.search(r"<q>(.*)</q>\s*$", s, re.S)+ if m:+ return s[:m.start()], m.group(1)+ return s, ""+++class Texts:+ def __init__(self):+ self.blob = bytearray()+ self.index = {}++ def add(self, s):+ if s in self.index:+ return self.index[s]+ off = len(self.blob)+ self.blob += s.encode("latin-1") + b"\0"+ self.index[s] = off+ return off+++# ------------------------------------------------------------------ the game's tables+POOLS = {"": 0, "cookie": 1, "prestige": 2, "toggle": 3, "tech": 4, "debug": 5}+ACH_POOLS = {"normal": 0, "shadow": 1, "dungeon": 2}+SEASONS = {None: 0, "christmas": 1, "halloween": 2, "valentines": 3, "easter": 4, "fools": 5}+++def cname(s):+ s = s.upper().replace("'", "").replace("&", "AND")+ s = re.sub(r"[^A-Z0-9]+", "_", s).strip("_")+ if s and s[0].isdigit():+ s = "_" + s+ return s+++ROW_FRAMES = {"javascriptconsole": 2, "idleverse": 4, "cortex": 4}+++def main(ref, game_json):+ G = json.load(open(game_json))+ P = Pack()+ T = Texts()+ T.add("")+ defs = []++ # ---- the left column+ L = lambda name, rel, size, fmt="p8", box=None, n=256: P.image(name, scaled(ref, rel, size, box), fmt, n)+ L("COOKIE", "perfectCookie.png", (104, 104))+ L("COOKIE_SHADOW", "cookieShadow.png", (40, 40))+ L("FLARE", "flare.png", (112, 112))+ L("FLARE_GOLD", "flareGold.png", (112, 112))+ L("FLARE_RED", "flareSuckRed.png", (112, 112))+ L("GLINT", "glint.png", (16, 16))+ tile = round(512 * S)+ P.image("BG_BLUE", opaque(ref, "bgBlue.jpg", (tile, tile)), "p8")+ for i in (1, 2, 3):+ P.image(f"BG_GRANDMAS{i}", opaque(ref, f"grandmas{i}.jpg", (128, 128)), "p8") # (drawn at tile)+ for k, f in (("SOFT", "shadedBordersSoft.png"), ("GOLD", "shadedBordersGold.png"), ("RED", "shadedBordersRed.png")):+ L("BORDER_" + k, f, (64, 64))+ for i in (1, 2, 3):+ L(f"SHOWER{i}", f"cookieShower{i}.png", (tile, tile))+ for i in range(8):+ L(f"SMALL_COOKIE{i}", "smallCookies.png", (24, 24), box=(64 * i, 0, 64 * i + 64, 64))+ L("CURSOR", "cursor.png", (32, 32), box=(0, 0, 32, 32))+ L("GOLD_COOKIE", "goldCookie.png", (48, 48))+ L("WRATH_COOKIE", "wrathCookie.png", (48, 48))+ # the milks: the game draws its 240-pixel pictures at 480; here at 120, drawn at 178 (480 x S): the top of+ # them that the milk shows, at most 0.35 of the column+ milk_tile = round(480 * S)+ milk_w, milk_h = 120, math.ceil((0.35 * 220 + 2) * 120 / milk_tile)+ defs.append(f"#define MILK_TILE {milk_tile}")+ for m in G["milks"]:+ rows = round(milk_h / milk_w * 240)+ L("MILK_" + cname(m["name"].replace(" milk", "")), m["pic"], (milk_w, milk_h), box=(0, 0, 240, rows))+ L("WRINKLER", "wrinkler.png", (38, 76))+ L("SHINY_WRINKLER", "shinyWrinkler.png", (38, 76))+ L("SHIMMERING_VEIL", "shimmeringVeil.png", (64, 64))+ L("DRAGON_BG", "dragonBG2.png", (112, 112))+ for i in range(10):+ L(f"BROKEN_COOKIE{i}", "brokenCookie.png", (64, 64), box=(256 * i, 0, 256 * i + 256, 256))+ L("BROKEN_HALO", "brokenCookieHalo.png", (72, 72))+ L("SHINE_SPOKE", "shineSpoke.png", (48, 48))+ P.image("HEAVEN_RING1", opaque(ref, "heavenRing1.jpg", (64, 64)), "p8")+ P.image("HEAVEN_RING2", opaque(ref, "heavenRing2.jpg", (64, 64)), "p8")+ P.image("STARS", opaque(ref, "starbg.jpg", (192, 192)), "p8")++ # ---- the store+ for i in range(4):+ P.image(f"STORE_TILE{i}", opaque(ref, "storeTile.jpg", (174, 32), (0, 64 * i, 300, 64 * i + 64)), "rgb")+ L("UPGRADE_FRAME", "upgradeFrame.png", (87, 58))+ L("MONEY", "money.png", (10, 10))+ L("HEAVENLY_MONEY", "heavenlyMoney.png", (10, 10))+ L("LUMP_MONEY", "sugarLump.png", (10, 10))+ P.image("PANEL_V", opaque(ref, "panelVertical.png", (4, 128), (0, 0, 16, 512)), "rgb")+ P.image("PANEL_H", opaque(ref, "panelHorizontal.png", (128, 4), (0, 0, 512, 16)), "rgb")+ P.image("DARK_NOISE", opaque(ref, "darkNoise.jpg", (128, 128)), "p8")+ for b in G["objects"]:+ r = b["icon"]+ for col, tag in ((0, ""), (1, "_OFF")):+ L(f"BUILD_{cname(b['name'])}{tag}", "buildings.png", (32, 32), box=(64 * col, 64 * r, 64 * col + 64, 64 * r + 64))++ # ---- the buildings' rows (the middle column), at 0.375: rows 48 pixels high+ pics = ["grandma", "farm", "mine", "factory", "bank", "temple", "wizardtower", "shipment", "alchemylab", "portal",+ "timemachine", "antimattercondenser", "prism", "chancemaker", "fractalEngine", "javascriptconsole",+ "idleverse", "cortex", "you"]+ for p in pics:+ if p != "you":+ L("ROW_BG_" + cname(p), p + "Background.png", (48, 48))+ else:+ L("ROW_BG_YOU", "youBackground.png", (48, 48))+ src = load(ref, p + ".png")+ frames = ROW_FRAMES.get(p, 1)+ if frames == 1:+ L("ROW_" + cname(p), p + ".png", (24, 24))+ else: # (slices side by side, as the game cuts them)+ fw, fh = src.size[0] // frames, src.size[1]+ for k in range(frames):+ L(f"ROW_{cname(p)}{k}", p + ".png", (max(1, round(fw * 0.375)), round(fh * 0.375)),+ box=(fw * k, 0, fw * k + fw, fh))+ grandmas = ["farmerGrandma", "workerGrandma", "minerGrandma", "cosmicGrandma", "transmutedGrandma",+ "alteredGrandma", "grandmasGrandma", "antiGrandma", "rainbowGrandma", "bankGrandma", "templeGrandma",+ "witchGrandma", "luckyGrandma", "metaGrandma", "scriptGrandma", "alternateGrandma", "brainyGrandma",+ "cloneGrandma", "elfGrandma", "bunnyGrandma"]+ for g in grandmas:+ L("ROW_" + cname(g), g + ".png", (24, 24))+ for k, f in (("GRIMOIRE", "BGgrimoire.jpg"), ("PANTHEON", "BGpantheon.jpg"), ("GARDEN", "BGgarden.jpg"),+ ("MARKET", "BGmarket.jpg")):+ P.image("MG_BG_" + k, opaque(ref, f, (192, 48)), "p8")+ for i in range(9):+ L(f"DRAGON{i}", "dragon.png", (48, 48), box=(96 * i, 0, 96 * i + 96, 96))+ for i in range(15):+ L(f"SANTA{i}", "santa.png", (48, 48), box=(96 * i, 0, 96 * i + 96, 96))+ L("SPELL_BG", "spellBG.png", (120, 111))+ for i in range(3): # (the heavenly upgrades' slots: bought, chosen, not bought)+ L(f"ASCEND_SLOT{i}", "ascendSlot.png", (40, 40), box=(88 * i, 0, 88 * i + 88, 88))++ # ---- the seasons' shimmers: reindeer, and golden cookies as wreaths, hearts, eggs, familiars+ L("REINDEER", "frostedReindeer.png", (62, 78))+ L("GOLD_WREATH", "goldCookieWreath.png", (48, 48))+ L("WRATH_WREATH", "wrathCookieWreath.png", (48, 48))+ for name, f, n in (("HEART", "hearts.png", 8), ("BUNNY", "bunnies.png", 4), ("FAMILIAR", "familiars.png", 4)):+ for row in range(2):+ for k in range(n):+ L(f"{name}{row}_{k}", f, (48, 48), box=(96 * k, 96 * row, 96 * k + 96, 96 * row + 96))++ # ---- the icons: 36 x 37 of 48 pixels, at 24+ sheet = load(ref, "icons.png")+ cols, rows = sheet.size[0] // 48, sheet.size[1] // 48+ icon_index = []+ for y in range(rows):+ for x in range(cols):+ cell = sheet.crop((48 * x, 48 * y, 48 * x + 48, 48 * y + 48))+ if np.asarray(cell)[..., 3].max() < 8:+ icon_index.append(0xFFFF)+ continue+ icon_index.append(P.image(None, premul_resize(cell, (24, 24)), "p4"))+ icons_off = P.put(struct.pack(f"<{len(icon_index)}H", *icon_index))+ defs += [f"#define ICON_COLS {cols}", f"#define ICON_ROWS {rows}", f"#define OFF_ICONS {icons_off}"]++ # ---- fonts+ F = os.path.join(ref, "fonts")+ mw = os.path.join(F, "Merriweather.ttf")+ ns = os.path.join(F, "NotoSans.ttf")+ nsi = os.path.join(F, "NotoSans-Italic.ttf")+ fonts = [+ ("TITLE", load_font(mw, 13, [900, 100, 18]), None),+ ("NAME", load_font(mw, 11, [900, 100, 18]), None),+ ("NAME_SMALL", load_font(mw, 9, [900, 100, 18]), None),+ ("OWNED", load_font(mw, 19, [900, 100, 18]), None),+ ("BODY", load_font(ns, 10, [500, 100]), 12),+ ("BOLD", load_font(ns, 10, [800, 100]), 12),+ ("ITALIC", load_font(nsi, 10, [500, 100]), 12),+ ("SMALL", load_font(ns, 9, [700, 100]), 11),+ ("KAVOON", load_font(os.path.join(F, "Kavoon.ttf"), 14), None),+ ]+ font_offs = []+ for name, f, line in fonts:+ font_offs.append(P.put(font_bytes(f, FONT_CHARS, line)))+ defs.append(f"#define F_{name} {len(font_offs) - 1}")+ fonts_off = P.put(struct.pack(f"<{len(font_offs)}I", *font_offs))+ defs.append(f"#define OFF_FONTS {fonts_off}")++ # ---- the game: buildings, tiers, upgrades, achievements+ up_by_name = {u["name"]: u["id"] for u in G["upgrades"]}+ obj_by_name = {o["name"]: o["id"] for o in G["objects"]}+ tier_keys = list(G["tiers"].keys())++ def icon_of(ic):+ if not ic:+ return 0xFFFF+ return ic[1] * cols + ic[0]++ # buildings: 56 bytes each+ brec = bytearray()+ for o in G["objects"]:+ brec += struct.pack("<ddIIIIIIIIhhhH", o["basePrice"], o.get("baseCps") or 0.1, T.add(clean(o["name"], False)),+ T.add(clean(o["single"], False)), T.add(clean(o["plural"], False)),+ T.add(clean(o["actionName"], False)), T.add(clean(o["extraName"] or "", False)),+ T.add(clean(o["extraPlural"] or "", False)), T.add(clean(o["desc"])),+ 0, o["icon"], o["iconColumn"], 0, 0)+ assert len(brec) == 56 * len(G["objects"])+ defs.append(f"#define OFF_BUILDINGS {P.put(bytes(brec), 8)}")+ defs.append(f"#define N_BUILDINGS {len(G['objects'])}")+ for o in G["objects"]:+ defs.append(f"#define B_{cname(o['name'])} {o['id']}")++ # tiers: 24 bytes each+ trec = bytearray()+ for k in tier_keys:+ t = G["tiers"][k]+ c = int(t["color"][1:], 16)+ trec += struct.pack("<dIhhhhHH", float(t["price"]), T.add(clean(t["name"], False)), t["unlock"],+ t.get("achievUnlock", -1), t["iconRow"], 1 if t.get("special") else 0,+ rgb565(c >> 16, c >> 8 & 255, c & 255),+ up_by_name.get(t.get("req"), 0xFFFF) if t.get("req") else 0xFFFF)+ assert len(trec) == 24 * len(tier_keys)+ defs.append(f"#define OFF_TIERS {P.put(bytes(trec), 8)}")+ defs.append(f"#define N_TIERS {len(tier_keys)}")+ for i, k in enumerate(tier_keys):+ defs.append(f"#define TIER_{cname(k)} {i}")++ # upgrades: 56 bytes each+ urec = bytearray()+ for u in G["upgrades"]:+ desc, quote = split_quote(u["desc"])+ tier = tier_keys.index(str(u["tier"])) if str(u.get("tier", 0)) in tier_keys else 0xFF+ power = u["power"] if isinstance(u.get("power"), (int, float)) else 0+ ua = u.get("unlockAt") or {}+ req = up_by_name.get(ua.get("require"), 0xFFFF) if ua.get("require") else 0xFFFF+ parents = [up_by_name[p] for p in u.get("parents", [])][:6] + [0xFFFF] * 6+ urec += struct.pack("<dfIIIHBBbbBBfH6HhhHd", float(u["basePrice"] or 0), float(u["order"] or 0),+ T.add(clean(u["name"], False)), T.add(clean(desc)), T.add(clean(quote)),+ icon_of(u["icon"]), POOLS[u["pool"]], tier,+ obj_by_name.get(u.get("buildingTie1") or u.get("buildingTie"), -1),+ obj_by_name.get(u.get("buildingTie2"), -1), 1 if u.get("kitten") else 0,+ SEASONS.get(u.get("season"), 0) | (0x80 if u.get("vanilla") else 0), float(power),+ req, *parents[:6], int(u.get("posX") or 0), int(u.get("posY") or 0), 0,+ float(ua.get("cookies") or 0))+ assert len(urec) == 64 * len(G["upgrades"]), len(urec) / len(G["upgrades"])+ defs.append(f"#define OFF_UPGRADES {P.put(bytes(urec), 8)}")+ defs.append(f"#define N_UPGRADES {len(G['upgrades'])}")+ seen = {}+ for u in G["upgrades"]:+ n = cname(u["name"])+ if n in seen:+ n = f"{n}_{u['id']}"+ seen[n] = 1+ defs.append(f"#define U_{n} {u['id']}")++ # achievements: 20 bytes each+ arec = bytearray()+ for a in G["achievements"]:+ desc, quote = split_quote(a["desc"])+ arec += struct.pack("<IIIfHBb", T.add(clean(a["name"], False)), T.add(clean(desc)), T.add(clean(quote)),+ float(a["order"] or 0), icon_of(a["icon"]), ACH_POOLS[a["pool"]],+ obj_by_name.get(a.get("buildingTie"), -1))+ assert len(arec) == 20 * len(G["achievements"])+ defs.append(f"#define OFF_ACHIEVS {P.put(bytes(arec), 4)}")+ defs.append(f"#define N_ACHIEVS {len(G['achievements'])}")+ seen = {}+ for a in G["achievements"]:+ n = cname(a["name"])+ if n in seen:+ n = f"{n}_{a['id']}"+ seen[n] = 1+ defs.append(f"#define A_{n} {a['id']}")++ # milks+ defs.append(f"#define N_MILKS {len(G['milks'])}")+ mrec = b"".join(struct.pack("<IH", T.add(clean(m["name"], False)), icon_of(m["icon"])) + b"\0\0"+ for m in G["milks"])+ defs.append(f"#define OFF_MILKS {P.put(mrec)}")++ # ---- what ties them together (res.h's BuildingLinks; lists of ids; thresholds)+ L = G["links"]+ NONE = 0xFFFF+ u16 = lambda v: NONE if v is None or v < 0 else v+ lrec = bytearray()+ for o in L["objects"]:+ tiered = [u16(o["tieredUpgrades"].get(k, -1)) for k in tier_keys]+ tach = [u16(o["tieredAchievs"].get(k, -1)) for k in tier_keys]+ syn = (o["synergies"] + [-1] * 6)[:6]+ prod = (o["production"] + [[0, -1]] * 4)[:3]+ lrec += struct.pack(f"<{len(tier_keys)}H{len(tier_keys)}H6HHHHH4HHH3d", *tiered, *tach, *map(u16, syn),+ u16(o["fortune"]), u16(o["grandma"]), u16(o["unshackle"]), u16(o["level10"]),+ *[u16(p[1]) for p in prod], NONE, 0, 0, *[float(p[0]) for p in prod])+ assert len(lrec) == 128 * len(L["objects"]), len(lrec)+ defs.append(f"#define OFF_BUILDING_LINKS {P.put(bytes(lrec), 8)}")++ def id_list(name, ids):+ defs.append(f"#define OFF_{name} {P.put(struct.pack(f'<{len(ids)}H', *map(u16, ids)) if ids else b'')}")+ defs.append(f"#define N_{name} {len(ids)}")++ id_list("TIER_UNSHACKLE", [L["tierUnshackle"].get(k, -1) for k in tier_keys])+ for name, key in (("COOKIE_UPGRADES", "cookieUpgrades"), ("GRANDMA_SYNERGIES", "grandmaSynergies"),+ ("KITTENS", "kittens"), ("GOLDEN_UPGRADES", "goldenCookieUpgrades"), ("LASTING", "lasting"),+ ("NO_PERM", "noPerm"), ("HEAVENLY", "heavenly"), ("EASTER_EGGS", "easterEggs"),+ ("HALLOWEEN_DROPS", "halloweenDrops"), ("HEART_DROPS", "heartDrops"),+ ("SANTA_DROPS", "santaDrops"), ("REINDEER_DROPS", "reindeerDrops"), ("FORTUNES", "fortuneTier"),+ ("SHOW_IF", "showIf"), ("CONFIRM", "requiresConfirmation")):+ id_list(name, L[key])+ for name, key in (("BANK_ACHIEVS", "bank"), ("CPS_ACHIEVS", "cps")):+ rec = b"".join(struct.pack("<dHHI", float(t), u16(i), 0, 0) for t, i in L[key])+ defs.append(f"#define OFF_{name} {P.put(rec, 8)}")+ defs.append(f"#define N_{name} {len(L[key])}")+ rec = b"".join(struct.pack("<dHHHHB7x", float(u["cookies"]), u16(u["up"]), u16(u["ach"]), u16(u["requireUp"]),+ u16(u["requireAch"]), SEASONS.get(u["season"], 0)) for u in L["unlockAt"])+ defs.append(f"#define OFF_UNLOCK_AT {P.put(rec, 8)}")+ defs.append(f"#define N_UNLOCK_AT {len(L['unlockAt'])}")++ # ---- the texts, the pictures' table+ text_off = P.put(bytes(T.blob))+ defs.append(f"#define OFF_TEXT {text_off}")+ P.align(4)+ table = bytearray()+ for name, w, h, fmt, n, px, pal in P.images:+ table += struct.pack("<HHBBHII", w, h, fmt, n - 1, 0, px, pal)+ img_off = P.put(bytes(table))+ defs.append(f"#define OFF_IMAGES {img_off}")+ defs.append(f"#define N_IMAGES {len(P.images)}")+ for name, i in P.names.items():+ defs.append(f"#define IM_{name} {i}")+ defs.append(f"#define DATA_SIZE {len(P.blob)}")++ with open(OUT_BIN, "wb") as f:+ f.write(P.blob)+ lines = ["/* Written by tools/pack.py: what data.bin holds. */", "#ifndef CC_DATA_H", "#define CC_DATA_H", ""]+ lines += defs+ lines += ["", "#endif", ""]+ with open(OUT_H, "w") as f:+ f.write("\n".join(lines))+ if UNKNOWN:+ print("pack: characters left out:", "".join(sorted(UNKNOWN)))+ sizes = {}+ print(f"data.bin: {len(P.blob)} bytes, {len(P.images)} pictures, texts {len(T.blob)}")+ print(" " + ", ".join(f"{k} {v // 1024} KB" for k, v in sorted(P.sizes.items(), key=lambda kv: -kv[1])))+++if __name__ == "__main__":+ if len(sys.argv) != 3:+ raise SystemExit(__doc__)+ main(sys.argv[1], sys.argv[2])