Skip to content

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

Undertale: the whole Ruins, from the golden flowers to the door out

Mason Chen69b1699427c2
diff --git a/games/undertale/src/battle.c b/games/undertale/src/battle.c
index e6118f21..9fe32d25 100644
--- a/games/undertale/src/battle.c
+++ b/games/undertale/src/battle.c
@@ -23,7 +23,7 @@ static int prev_mode;
enum {
P_INTRO, P_MENU, P_TARGET, P_ACTS, P_ITEMS, P_MERCY, P_BAR, P_STRIKE, P_RESULT, P_TALK, P_BOX_IN, P_ATTACK,
- P_BOX_OUT, P_WON, P_FLEE, P_DEATH, P_END
+ P_BOX_OUT, P_WON, P_FLEE, P_DEATH, P_END, P_GLARE
};
enum { B_FIGHT, B_ACT, B_ITEM, B_MERCY };
@@ -117,6 +117,17 @@ void battle_start(int form) {
bool battle_over(void) { return over; }
int battle_result(void) { return bt.result; }
+int battle_ui(void) {
+ switch (bt.phase) {
+ case P_MENU: return BUI_MENU;
+ case P_TARGET: return BUI_TARGET;
+ case P_ACTS: return BUI_ACTS;
+ case P_ITEMS: return BUI_ITEMS;
+ case P_MERCY: return BUI_MERCY;
+ case P_BAR: return BUI_BAR;
+ default: return BUI_NONE;
+ }
+}
static void battle_end(int result) {
bt.result = result;
@@ -174,6 +185,13 @@ static void strike_land(void) {
/* ---------------------------------------------------------------- the turns */
static void begin_menu(void) {
+ /* the first Froggit: Toriel comes and glares at it, and it leaves */
+ if (bt.form == FORM_FROGGIT_FIRST && bt.turn >= 1 && count_alive()) {
+ bt.phase = P_GLARE, bt.t = 0;
+ box_menu();
+ say("");
+ return;
+ }
bt.phase = P_MENU;
box_menu();
say(flavor_text());
@@ -286,8 +304,6 @@ static void do_spare(void) {
static void do_flee(void) {
bool can = !bt.no_flee;
bt.last_action = 4;
- for (int i = 0; i < bt.nmon; i++)
- if (bt.mon[i].alive && !bt.mon[i].gone && (bt.mon[i].def->flags & MF_BOSS)) can = false;
if (!can) {
after_player_turn();
return;
@@ -521,6 +537,10 @@ void battle_update(uint32_t keys, uint32_t pressed) {
case P_DEATH:
if (bt.t >= 70) battle_end(BR_DIED);
break;
+ case P_GLARE:
+ if (bt.t == 40) bt.mon[0].gone = true, bt.mon[0].fade = 1;
+ if (bt.t >= 80) win();
+ break;
}
}
@@ -710,6 +730,8 @@ void battle_draw(void) {
}
gfx_sprite(SPR_BATTLEBG, 0, 0, 0, 0, 255);
for (int i = 0; i < bt.nmon; i++) draw_monster(&bt.mon[i], i);
+ if (bt.phase == P_GLARE || (bt.form == FORM_FROGGIT_FIRST && bt.phase == P_WON))
+ gfx_sprite(SPR_TORIEL_B, 0, 330 - min_i(bt.phase == P_GLARE ? bt.t : 30, 30) * 2, 120, 0, 255);
/* the box */
gfx_rect(bt.x0, bt.y0, bt.x1 - bt.x0, bt.y1 - bt.y0, C_WHITE, 255);
gfx_rect(bt.x0 + 2, bt.y0 + 2, bt.x1 - bt.x0 - 4, bt.y1 - bt.y0 - 4, C_BLACK, 255);
diff --git a/games/undertale/src/battle.h b/games/undertale/src/battle.h
index f9f5f29c..ce537418 100644
--- a/games/undertale/src/battle.h
+++ b/games/undertale/src/battle.h
@@ -139,6 +139,9 @@ extern Bullet bullets[MAX_BULLETS];
void battle_start(int form);
bool battle_over(void);
int battle_result(void);
+/* what the battle waits for (for the tests): a button, a target, an ACT, an item, MERCY's choice or nothing */
+enum { BUI_NONE, BUI_MENU, BUI_TARGET, BUI_ACTS, BUI_ITEMS, BUI_MERCY, BUI_BAR };
+int battle_ui(void);
void battle_update(uint32_t keys, uint32_t pressed);
void battle_draw(void);
diff --git a/games/undertale/src/data.bin b/games/undertale/src/data.bin
new file mode 100644
index 00000000..b89314e3
Binary files /dev/null and b/games/undertale/src/data.bin differ
diff --git a/games/undertale/src/data.h b/games/undertale/src/data.h
index 6d246b80..a8898290 100644
--- a/games/undertale/src/data.h
+++ b/games/undertale/src/data.h
@@ -70,46 +70,102 @@
#define SPR_TORIEL_AWAY 57
#define SPR_TORIEL_FIGHT 58
#define SPR_TORIEL_DEAD 59
-#define SPR_INTROIMAGE 60
-#define SPR_INTROLAST 61
-#define SPR_UNDERTALETITLE 62
-#define SPR_GAMEOVERBG 63
-#define SPR_FACE_TORIELTALK 64
-#define SPR_FACE_TORIELTALKSIDE 65
-#define SPR_FACE_TORIELHAPPYTALK 66
-#define SPR_FACE_TORIELWHAT 67
-#define SPR_FACE_TORIELWHATSIDE 68
-#define SPR_FACE_TORIELMAD 69
-#define SPR_FACE_TORIELCOLD 70
-#define SPR_FACE_TORIELSURPRISED 71
-#define SPR_FACE_TORIELEMBARRASSED 72
-#define SPR_FACE_TORIELGLASSES 73
-#define SPR_FACE_TORIELREVENGETALK 74
-#define SPR_FACE_TORIELSCARED 75
-#define SPR_FACE_TORIELBLINK 76
-#define SPR_FACE_TORIELHAPPYBLINK 77
-#define SPR_FACE_TORIELBODY 78
-#define SPR_FACE_SANS 79
-#define SPR_FACE_SANSCHUCKLE 80
-#define SPR_FACE_SANSWINK 81
-#define SPR_FACE_PAPYRUS 82
-#define SPR_FACE_PAPYRUSEVIL 83
-#define SPR_FACE_PAPYRUSLAUGH 84
-#define SPR_FACE_PAPYRUSMAD 85
-#define SPR_FACE_PAPYRUSSIDE 86
-#define SPR_FLOWEYNICE 87
-#define SPR_FLOWEYNICESIDE 88
-#define SPR_FLOWEYSASSY 89
-#define SPR_FLOWEYEVIL 90
-#define SPR_FLOWEYGRIN 91
-#define SPR_FLOWEYPLAIN 92
-#define SPR_FLOWEYPISSED 93
-#define SPR_FLOWEYWINK 94
-#define SPR_FLOWEYLAUGH 95
-#define SPR_FLOWEYHURT 96
-#define SPR_FLOWEYTORIEL 97
-#define SPR_FLOWEYTORIEL2 98
-#define SPR_FLOWEYSIDESHOCK 99
+#define SPR_O_RUINSDOOR1 60
+#define SPR_O_SWITCH 61
+#define SPR_O_GROUNDSWITCH1 62
+#define SPR_O_SPIKETILE 63
+#define SPR_O_ROCK 64
+#define SPR_O_COLORSWITCH 65
+#define SPR_O_FACESWITCH 66
+#define SPR_O_DUMMY 67
+#define SPR_O_EXC 68
+#define SPR_O_FLOWEYGROW 69
+#define SPR_O_FLOWEYSHRINK 70
+#define SPR_O_FLOWEYSINK 71
+#define SPR_O_FLOWEYLAUGHOVERWORLD 72
+#define SPR_O_TORIEL_HANDHOLD_D 73
+#define SPR_O_TORIEL_HANDHOLD_U 74
+#define SPR_O_TORIEL_HANDHOLD_L 75
+#define SPR_O_TORIEL_HANDHOLD_R 76
+#define SPR_O_HOLE 77
+#define SPR_O_SMALLWEB 78
+#define SPR_O_BIGWEB 79
+#define SPR_O_NAPSTABLOOK_GR 80
+#define SPR_O_NAPSTABLOOK_GRSM 81
+#define SPR_O_NAPSTABLOOK_L 82
+#define SPR_O_CHAIREMPTY 83
+#define SPR_O_CHAIRIEL 84
+#define SPR_O_CHAIRIELGETUP 85
+#define SPR_O_CANDYDISH 86
+#define SPR_O_CANDYDISH2 87
+#define SPR_O_CANDYDISH_BAD 88
+#define SPR_O_CHEESETABLE 89
+#define SPR_O_MOUSEHOLE 90
+#define SPR_O_NPC_D 91
+#define SPR_O_NPC_U 92
+#define SPR_O_NPC_L 93
+#define SPR_O_NPC_R 94
+#define SPR_O_PILLAR 95
+#define SPR_O_PIESLICE 96
+#define SPR_O_BIGPIE 97
+#define SPR_O_VEGETABLEOUTSIDE 98
+#define SPR_O_SMALLFROG 99
+#define SPR_O_RIBBON 100
+#define SPR_O_GROUNDKNIFE 101
+#define SPR_O_TORIELFLAME 102
+#define SPR_O_WINKSTAR 103
+#define SPR_O_TORNOTE 104
+#define SPR_O_DININGTABLE 105
+#define SPR_O_NASTYTREE 106
+#define SPR_O_TORIEL_D_PHONE 107
+#define SPR_O_TORIEL_DT 108
+#define SPR_O_TORIEL_UT 109
+#define SPR_O_TORIEL_LT 110
+#define SPR_O_TORIEL_RT 111
+#define SPR_O_TORIEL_HUG 112
+#define SPR_O_TORIEL_RUFFLE 113
+#define SPR_FROG_OW 114
+#define SPR_NAPSTA_OW 115
+#define SPR_INTROIMAGE 116
+#define SPR_INTROLAST 117
+#define SPR_UNDERTALETITLE 118
+#define SPR_GAMEOVERBG 119
+#define SPR_FACE_TORIELTALK 120
+#define SPR_FACE_TORIELTALKSIDE 121
+#define SPR_FACE_TORIELHAPPYTALK 122
+#define SPR_FACE_TORIELWHAT 123
+#define SPR_FACE_TORIELWHATSIDE 124
+#define SPR_FACE_TORIELMAD 125
+#define SPR_FACE_TORIELCOLD 126
+#define SPR_FACE_TORIELSURPRISED 127
+#define SPR_FACE_TORIELEMBARRASSED 128
+#define SPR_FACE_TORIELGLASSES 129
+#define SPR_FACE_TORIELREVENGETALK 130
+#define SPR_FACE_TORIELSCARED 131
+#define SPR_FACE_TORIELBLINK 132
+#define SPR_FACE_TORIELHAPPYBLINK 133
+#define SPR_FACE_TORIELBODY 134
+#define SPR_FACE_SANS 135
+#define SPR_FACE_SANSCHUCKLE 136
+#define SPR_FACE_SANSWINK 137
+#define SPR_FACE_PAPYRUS 138
+#define SPR_FACE_PAPYRUSEVIL 139
+#define SPR_FACE_PAPYRUSLAUGH 140
+#define SPR_FACE_PAPYRUSMAD 141
+#define SPR_FACE_PAPYRUSSIDE 142
+#define SPR_FLOWEYNICE 143
+#define SPR_FLOWEYNICESIDE 144
+#define SPR_FLOWEYSASSY 145
+#define SPR_FLOWEYEVIL 146
+#define SPR_FLOWEYGRIN 147
+#define SPR_FLOWEYPLAIN 148
+#define SPR_FLOWEYPISSED 149
+#define SPR_FLOWEYWINK 150
+#define SPR_FLOWEYLAUGH 151
+#define SPR_FLOWEYHURT 152
+#define SPR_FLOWEYTORIEL 153
+#define SPR_FLOWEYTORIEL2 154
+#define SPR_FLOWEYSIDESHOCK 155
#define AREA_RUINS 0
#define ROOM_AREA1 0
#define ROOM_AREA1_2 1
@@ -160,7 +216,7 @@
#define FONT_MAIN 0
#define FONT_MENU 1
#define FONT_SMALL 2
-#define NUM_SPRITES 100
+#define NUM_SPRITES 156
#define NUM_ROOMS 46
#define NUM_FONTS 3
#endif
diff --git a/games/undertale/src/event.c b/games/undertale/src/event.c
index 646a97e6..f5cf6c3e 100644
--- a/games/undertale/src/event.c
+++ b/games/undertale/src/event.c
@@ -1,6 +1,7 @@
/* The event that runs now (event.h), and Frisk walking for a cutscene. */
#include <string.h>
#include "event.h"
+#include "events.h"
#include "game.h"
static Ev cur;
@@ -11,10 +12,15 @@ void event_start(int id, Obj *self) {
memset(&cur, 0, sizeof cur);
cur.id = id, cur.self = self;
running = true;
- event_update(); /* (it starts this frame: a talk opens at once) */
+ if (id != EV_ENCOUNTER) event_update(); /* (it starts this frame: a talk opens at once) */
}
bool event_running(void) { return running; }
+bool event_blocking(void) { return running && !cur.free; }
+
+void event_cancel(void) { running = false; }
+void event_cur_arg(int v) { cur.v[0] = v; }
+int g_exclaim;
void event_update(void) {
if (!running) return;
diff --git a/games/undertale/src/event.h b/games/undertale/src/event.h
index a850806b..b408f2f4 100644
--- a/games/undertale/src/event.h
+++ b/games/undertale/src/event.h
@@ -2,9 +2,10 @@
*
* An event is a C function called once a frame until it says it is done;
* the macros below make it read like the game's scripts (each SAY waits for
- * its text, each WAIT for its frames). Its locals don't last over a wait:
- * what has to is kept in c->v. One event runs at a time; while it does,
- * Frisk doesn't move unless it lets him. */
+ * its text, each WAIT for its frames). They are protothreads on GCC's labels
+ * as values (a wait can be anywhere, in a switch too). The function's locals
+ * don't last over a wait: what has to is kept in c->v. One event runs at a
+ * time; while it does, Frisk doesn't move unless it lets him. */
#ifndef UT_EVENT_H
#define UT_EVENT_H
#include <stdbool.h>
@@ -12,20 +13,30 @@
#include "world.h"
typedef struct Ev {
- int id, line, t;
+ int id, t;
+ void *at; /* where it waits (NULL: from the start) */
+ bool free; /* Frisk walks while it runs (FREE()), the others stop him */
int v[6];
Obj *self;
} Ev;
-#define EV_BEGIN switch (c->line) { case 0:
+#define EV_CAT2(a, b) a##b
+#define EV_CAT(a, b) EV_CAT2(a, b)
+#define EV_BEGIN do { if (c->at) goto *c->at; } while (0); {
#define EV_END } return 1
-#define EV_YIELD do { c->line = __LINE__; return 0; case __LINE__:; } while (0)
-#define WAIT_UNTIL(cond) do { c->line = __LINE__; case __LINE__: if (!(cond)) return 0; } while (0)
-#define WAIT(n) do { c->t = (n); c->line = __LINE__; case __LINE__: if (c->t-- > 0) return 0; } while (0)
+#define EV_FALL __attribute__((fallthrough))
+#define EV_WAIT_(cond, n) do { c->at = &&EV_CAT(ev_at_, n); EV_CAT(ev_at_, n): if (!(cond)) return 0; } while (0)
+#define WAIT_UNTIL(cond) EV_WAIT_(cond, __COUNTER__)
+#define EV_WAITN_(N, n) do { c->t = (N); c->at = &&EV_CAT(ev_at_, n); EV_CAT(ev_at_, n): if (c->t-- > 0) return 0; } while (0)
+#define WAIT(N) EV_WAITN_(N, __COUNTER__)
#define SAY(face, s) do { text_open(face, s); WAIT_UNTIL(!text_active()); } while (0)
#define SAYF(face, ...) do { text_openf(face, __VA_ARGS__); WAIT_UNTIL(!text_active()); } while (0)
#define NARRATE(s) SAY(FACE_NONE, s)
#define CHOICE() text_choice()
+#define FREE(b) (c->free = (b))
+/* a list to choose from in the dialogue box (the phone's): CHOOSE waits, CHOSEN() is -1 for Back */
+#define CHOOSE(opts, n) do { text_open_menu(opts, n); WAIT_UNTIL(!text_active()); } while (0)
+#define CHOSEN() text_choice()
/* an object walks to (x, y) at sp pixels a frame; WALK waits for it */
#define WALK_TO(o, X, Y, SP) do { (o)->tx = (int16_t)(X), (o)->ty = (int16_t)(Y), (o)->speed = (uint8_t)(SP), (o)->walking = 1; } while (0)
#define WALK(o, X, Y, SP) do { WALK_TO(o, X, Y, SP); WAIT_UNTIL(!(o)->walking); } while (0)
@@ -36,7 +47,11 @@ typedef struct Ev {
void event_start(int id, Obj *self);
bool event_running(void);
+bool event_blocking(void); /* running, and Frisk can't walk */
void event_update(void);
+void event_cancel(void);
+void event_cur_arg(int v); /* the event just started: its v[0] */
+extern int g_exclaim; /* frames of the "!" over Frisk (an encounter) */
int event_run(Ev *c); /* events.c: the events, by id */
void pl_walk_to(int x, int y, int sp);
bool pl_walking(void);
diff --git a/games/undertale/src/events.c b/games/undertale/src/events.c
index 8dadaf7a..c8ba2d84 100644
--- a/games/undertale/src/events.c
+++ b/games/undertale/src/events.c
@@ -1,10 +1,101 @@
-/* The events (event.h). */
+/* The events (event.h): the common ones (signs, SAVE Points, the phone), then each area's. */
+#include <stdio.h>
+#include <string.h>
#include "event.h"
#include "events.h"
+#include "battle.h"
#include "game.h"
+#include "menu.h"
+#include "ruins.h"
+
+static int ev_sign(Ev *c) {
+ EV_BEGIN;
+ if (c->self && c->self->text) SAY(FACE_NONE, c->self->text);
+ EV_END;
+}
+
+void say_on_entry(const char *text) {
+ static Obj note;
+ note.text = text;
+ event_start(EV_SIGN, &note);
+}
+
+static char save_text[200];
+static int ev_save(Ev *c) {
+ EV_BEGIN;
+ /* its words, the HP restored, then SAVE */
+ if (sv.hp < sv.maxhp) snprintf(save_text, sizeof save_text, "%s|* (HP fully restored.)", c->self ? c->self->text : "");
+ else snprintf(save_text, sizeof save_text, "%s", c->self ? c->self->text : "");
+ sv.hp = sv.maxhp;
+ SAY(FACE_NONE, save_text);
+ menu_save_open();
+ WAIT_UNTIL(g_mode == MODE_WORLD);
+ EV_END;
+}
+
+static int ev_phone(Ev *c) {
+ static const char *const opts[] = {"Say Hello", "Puzzle Help", "About Yourself", "Call Her \"Mom\"", "Flirt"};
+ EV_BEGIN;
+ NARRATE("* Dialing...");
+ CHOOSE(opts, 5);
+ switch (CHOSEN()) {
+ case 0:
+ set_flag(F_CALL_HELLO, flag(F_CALL_HELLO) + 1);
+ if (flag(F_CALL_HELLO) == 1)
+ SAY(FACE_TORIEL, "`0* This is TORIEL.|* You only wanted to say\n hello...?\n* Well then.|`2* 'Hello!'|`0* I hope that suffices.\n* Hee hee.");
+ else if (flag(F_CALL_HELLO) == 2)
+ SAY(FACE_TORIEL, "`0* This is TORIEL.|* You want to say hello again?|`2* 'Salutations!'|`0* Is that enough?");
+ else if (flag(F_CALL_HELLO) == 3)
+ SAY(FACE_TORIEL, "`0* This is TORIEL.|`1* Are you bored?\n* I should have given a book\n to you.|* My apologies.|`0* Why not use your imagination\n to divert yourself?|* Pretend you are...\n* A monarch!|`2* Rule over the leaf pile with\n a fist of iron.|`0* Can you do that for me?");
+ else
+ SAY(FACE_TORIEL, "`0* This is TORIEL.|* Hello, my child.|`1* Sorry, I do not have much to\n say.|`0* It was nice to hear your\n voice, though.");
+ break;
+ case 1:
+ SAY(FACE_TORIEL, "`0* This is TORIEL.|* Help with a puzzle...?|`1* Um, you have not left the\n room, have you?|`0* Wait patiently for me and we\n can solve it together!");
+ break;
+ case 2:
+ SAY(FACE_TORIEL, "`0* This is TORIEL.|* You want to know more about\n me?|`1* Well, I am afraid there is\n not much to say.|`2* I am just a silly little lady\n who worries too much!");
+ break;
+ case 3:
+ set_flag(F_CALL_MOM, 1);
+ SAY(FACE_TORIEL, "`0* This is TORIEL.|`3* Huh? Did you just call me...\n \"Mom\"?|`8* Well... I suppose...|* Would that make you happy?|* To call me... \"Mother?\"|`2* Well then, call me whatever\n you like!");
+ break;
+ case 4:
+ set_flag(F_CALL_FLIRT, flag(F_CALL_FLIRT) + 1);
+ if (flag(F_CALL_FLIRT) == 1)
+ SAY(FACE_TORIEL, "`3* ... huh???|`8* Oh, heh.. heh...\n* Ha ha ha!|`2* How adorable...\n* I could pinch your cheek!|`0* You can certainly find better\n than an old woman like me.");
+ else if (flag(F_CALL_MOM))
+ SAY(FACE_TORIEL, "`3* Oh dear, are you serious...?|* And after you said you want\n to call me \"mother...\"|`1* You are an... ...\n \"interesting\" child.");
+ else
+ SAY(FACE_TORIEL, "`3* Oh dear, are you serious...?|`1* I do not know if this is\n pathetic, or endearing.");
+ break;
+ default:
+ break;
+ }
+ EV_END;
+}
+
+static int ev_encounter(Ev *c) {
+ EV_BEGIN;
+ g_exclaim = 18;
+ WAIT(18);
+ g_exclaim = 0;
+ BATTLE(c->v[0]);
+ EV_END;
+}
int event_run(Ev *c) {
switch (c->id) {
- default: return 1;
+ case EV_ENCOUNTER: return ev_encounter(c);
+ case EV_SIGN: return ev_sign(c);
+ case EV_SAVE: return ev_save(c);
+ case EV_PHONE_MENU: return ev_phone(c);
}
+ int r = ruins1_event(c);
+ if (r >= 0) return r;
+ r = ruins2_event(c);
+ if (r >= 0) return r;
+ r = ruins3_event(c);
+ if (r >= 0) return r;
+ return 1;
}
diff --git a/games/undertale/src/events.h b/games/undertale/src/events.h
index 99abfcf6..82a1ac7e 100644
--- a/games/undertale/src/events.h
+++ b/games/undertale/src/events.h
@@ -1,11 +1,31 @@
/* Undertale: the events, by id. */
#ifndef UT_EVENTS_H
#define UT_EVENTS_H
+/* who is who in a room (Obj.name), for the events to find */
+enum {
+ ACTOR_NONE, ACTOR_TORIEL, ACTOR_FLOWEY, ACTOR_DUMMY, ACTOR_DOOR, ACTOR_SPIKES, ACTOR_SPIKES2, ACTOR_FROGGIT,
+ ACTOR_PILLAR, ACTOR_NAPSTA, ACTOR_ROCK, ACTOR_ROCK2, ACTOR_ROCK3, ACTOR_SWITCH, ACTOR_SWITCH2, ACTOR_SWITCH3,
+ ACTOR_CANDY, ACTOR_TRIGGER, ACTOR_TRIGGER2, ACTOR_ITEM, ACTOR_CHAIR, ACTOR_PIE, ACTOR_ANY
+};
+
enum {
EV_NONE,
EV_SIGN, /* a sign or anything that only says its text (self->arg: the text, in events.c) */
EV_PHONE_MENU, /* CELL: calling Toriel */
EV_SAVE, /* a SAVE Point */
+ EV_ENCOUNTER, /* a random encounter: v[0] its formation */
+ EV_FLOWEY_MEET, EV_RUINS1_TORIEL, EV_RUINS2_TORIEL, EV_RUINS3_TORIEL, EV_RUINS3_SWITCH, EV_RUINS4_TORIEL,
+ EV_RUINS4_DUMMY, EV_RUINS5_TORIEL, EV_RUINS6_TORIEL, EV_RUINS6_PILLAR, EV_RUINS6_REVEAL, EV_RUINS7_CALL,
+ EV_RUINS7_FROGGIT,
+ /* ruins2.c */
+ EV_FALLING, EV_COLOR_SWITCH, EV_CANDY, EV_CALL, EV_ROCK_TALK, EV_ROCK_OFF, EV_NAPSTA_SLEEP, EV_NAPSTA_LIE, EV_WEB,
+ EV_FROGGIT, EV_ITEM, EV_ONE_SWITCH, EV_VEGGIE, EV_TORIEL_TREE,
+ /* ruins3.c */
+ EV_HOME_TOUR, EV_TORIEL_CHAIR, EV_BED, EV_STAIRS, EV_BASEMENT_TALK, EV_TORIEL_DOOR, EV_FLOWEY_END, EV_RUINS_DOOR,
EV_COUNT
};
+/* Toriel's calls on the way (EV_CALL's v[0]) */
+enum { CALL_FLAVOR, CALL_FLAVOR2, CALL_ALLERGY, CALL_ITEMS };
+/* a text when Frisk comes in (a room's setup) */
+void say_on_entry(const char *text);
#endif
diff --git a/games/undertale/src/flags.h b/games/undertale/src/flags.h
index 46305f19..8a925eb1 100644
--- a/games/undertale/src/flags.h
+++ b/games/undertale/src/flags.h
@@ -50,6 +50,11 @@ enum {
F_FIRST_FROGGIT,
F_TORIEL_SNAIL,
F_WHIMSUN_TALK,
+ F_CALL_HELLO, F_CALL_MOM, F_CALL_FLIRT,
+ F_NAPSTA_LIE, /* Napstablook went away from the room under the one switch puzzle */
+ F_HOME_TOUR, /* Toriel showed Frisk the house */
+ F_SNAIL_TALK,
+ F_BED_SLEPT, /* 1 slept; 2 the pie taken */
FLAG_COUNT = 256
};
#endif
diff --git a/games/undertale/src/flowey.c b/games/undertale/src/flowey.c
index a46156a0..e19fa64c 100644
--- a/games/undertale/src/flowey.c
+++ b/games/undertale/src/flowey.c
@@ -176,7 +176,6 @@ void flowey_battle_update(uint32_t keys, uint32_t pressed) {
void flowey_battle_draw(void) {
int st = bt.state[0];
- gfx_sprite(SPR_BATTLEBG, 0, 0, 0, 0, 255);
int fx = 160 + bt.state[3];
if (st <= F_FIREBALL) {
int e = bt.state[2];
diff --git a/games/undertale/src/game.c b/games/undertale/src/game.c
index 79e84ba1..87489290 100644
--- a/games/undertale/src/game.c
+++ b/games/undertale/src/game.c
@@ -1,4 +1,5 @@
/* The game's state, its modes and its frame (game.h). */
+#include <stdio.h>
#include <string.h>
#include "battle.h"
#include "event.h"
@@ -68,8 +69,10 @@ int item_count(void) {
/* ---------------------------------------------------------------- a new game */
void game_new(const char *name) {
+ char n[sizeof sv.name];
+ snprintf(n, sizeof n, "%s", name); /* (it can be sv.name) */
memset(&sv, 0, sizeof sv);
- strncpy(sv.name, name, sizeof sv.name - 1);
+ memcpy(sv.name, n, sizeof n);
memcpy(g_name, sv.name, sizeof g_name);
sv.lv = 1, sv.maxhp = sv.hp = 20, sv.at = (uint8_t)lv_at(1), sv.df = (uint8_t)lv_df(1);
sv.weapon = ITEM_STICK, sv.armor = ITEM_BANDAGE;
diff --git a/games/undertale/src/icon.png b/games/undertale/src/icon.png
new file mode 100644
index 00000000..608fe4b0
Binary files /dev/null and b/games/undertale/src/icon.png differ
diff --git a/games/undertale/src/menu.c b/games/undertale/src/menu.c
index b4e9cb80..83da5f51 100644
--- a/games/undertale/src/menu.c
+++ b/games/undertale/src/menu.c
@@ -358,6 +358,14 @@ void menu_gameover_open(void) {
w.speed = 2;
}
+/* ---------------------------------------------------------------- the end of what there is */
+void menu_end_open(void) {
+ g_mode = MODE_END;
+ t = 0;
+ writer_start(&w, "The RUINS are behind you.|The rest of the underground\nis still to come...", 52, 100, FONT_MAIN);
+ w.speed = 2;
+}
+
/* ---------------------------------------------------------------- the frame */
void menu_update(uint32_t keys, uint32_t pressed) {
(void)keys;
@@ -398,8 +406,8 @@ void menu_update(uint32_t keys, uint32_t pressed) {
if (pressed & K_Z) {
if (sel == 0) st = S_NAME;
else {
- if (same_lower(name, "frisk")) set_flag(F_HARDMODE, 1);
game_new(name);
+ if (same_lower(name, "frisk")) set_flag(F_HARDMODE, 1);
st = S_FADEIN;
}
}
@@ -422,6 +430,9 @@ void menu_update(uint32_t keys, uint32_t pressed) {
if (!save_load()) game_new(sv.name);
}
break;
+ case MODE_END:
+ if (t > 30 && !writer_update(&w, pressed)) menu_title_open();
+ break;
}
}
@@ -496,5 +507,8 @@ void menu_draw(void) {
gfx_sprite(SPR_GAMEOVERBG, 0, 0, 0, 0, (uint8_t)min_i(255, t * 6));
if (t > 40) writer_draw(&w, C_WHITE);
break;
+ case MODE_END:
+ if (t > 30) writer_draw(&w, C_WHITE);
+ break;
}
}
diff --git a/games/undertale/src/menu.h b/games/undertale/src/menu.h
index bc4589ab..ff41316b 100644
--- a/games/undertale/src/menu.h
+++ b/games/undertale/src/menu.h
@@ -6,6 +6,7 @@ void menu_title_open(void);
void menu_open(void);
void menu_save_open(void);
void menu_gameover_open(void);
+void menu_end_open(void); /* the Ruins' door: what comes next isn't made yet */
void menu_update(uint32_t keys, uint32_t pressed);
void menu_draw(void);
void game_new(const char *name);
diff --git a/games/undertale/src/monsters.c b/games/undertale/src/monsters.c
index 153e35dd..2f7f1867 100644
--- a/games/undertale/src/monsters.c
+++ b/games/undertale/src/monsters.c
@@ -320,7 +320,8 @@ int form_setup(int form, Battle *b) {
m->def = mon_def(f->mon[i]);
m->x = (int16_t)(xs[f->n - 1][i] + m->def->dx), m->y = (int16_t)(120 + m->def->dy);
}
- if (form == FORM_NAPSTABLOOK || form == FORM_TORIEL || form == FORM_FLOWEY) b->no_flee = form == FORM_FLOWEY;
+ /* Toriel and Flowey can't be fled from; Napstablook can */
+ if (form == FORM_TORIEL || form == FORM_FLOWEY) b->no_flee = true;
return 0;
}
const char *form_text(int form) { return forms[form].text; }
diff --git a/games/undertale/src/rooms.c b/games/undertale/src/rooms.c
index 20063886..fe113eaa 100644
--- a/games/undertale/src/rooms.c
+++ b/games/undertale/src/rooms.c
@@ -1,14 +1,55 @@
/* The rooms' objects and their random encounters. */
+#include <stddef.h>
+#include "battle.h"
#include "event.h"
#include "events.h"
#include "game.h"
+#include "monsters.h"
+#include "ruins.h"
#include "world.h"
void room_setup(int room, int from) {
- (void)from;
- switch (room) {
- default: break;
- }
+ ruins1_setup(room, from);
+ ruins2_setup(room, from);
+ ruins3_setup(room, from);
}
-void encounter_step(void) {}
+/* each frame Frisk can walk: what a room watches (a rock on its switch, a cracked floor) */
+void room_update(void) {
+ ruins2_update();
+}
+
+/* random encounters: a room's formations and how many steps between them (the game counts its steps,
+ * then a "!" shows over Frisk) */
+typedef struct {
+ uint8_t room;
+ uint8_t forms[6];
+ uint8_t n;
+} Encounters;
+static const Encounters enc[] = {
+ {ROOM_RUINS7, {FORM_FROGGIT, FORM_WHIMSUN}, 2},
+ {ROOM_RUINS8, {FORM_FROGGIT, FORM_WHIMSUN}, 2},
+ {ROOM_RUINS9, {FORM_FROGGIT, FORM_WHIMSUN}, 2},
+ {ROOM_RUINS10, {FORM_FROGGIT, FORM_WHIMSUN, FORM_FROGGIT_WHIMSUN, FORM_FROGGIT2, FORM_MOLDSMAL}, 5},
+ {ROOM_RUINS11, {FORM_FROGGIT_WHIMSUN, FORM_FROGGIT2, FORM_MOLDSMAL, FORM_MOLDSMAL2, FORM_MOLDSMAL3}, 5},
+ {ROOM_RUINS15, {FORM_LOOX, FORM_VEGETOID, FORM_LOOX_VEG_MIGOSP, FORM_VEGETOID_MIGOSP, FORM_MOLDSMAL_MIGOSP, FORM_LOOX2}, 6},
+ {ROOM_RUINS16, {FORM_LOOX, FORM_VEGETOID, FORM_MOLDSMAL_MIGOSP, FORM_VEGETOID2}, 4},
+ {ROOM_RUINS17A, {FORM_LOOX, FORM_VEGETOID, FORM_MOLDSMAL_MIGOSP}, 3},
+ {ROOM_RUINS17B, {FORM_LOOX, FORM_VEGETOID, FORM_MOLDSMAL_MIGOSP}, 3},
+ {ROOM_RUINS17C, {FORM_LOOX, FORM_VEGETOID, FORM_MOLDSMAL_MIGOSP}, 3},
+ {ROOM_RUINS17D, {FORM_LOOX, FORM_VEGETOID, FORM_MOLDSMAL_MIGOSP}, 3},
+};
+static int steps_left = 120;
+bool g_no_encounters; /* (the tests' --noenc) */
+
+void encounter_step(void) {
+ if (!pl.moving || g_no_encounters) return;
+ const Encounters *e = NULL;
+ for (unsigned i = 0; i < sizeof enc / sizeof enc[0]; i++)
+ if (enc[i].room == g_room) e = &enc[i];
+ if (!e) return;
+ if (--steps_left > 0) return;
+ steps_left = 100 + rnd_n(200);
+ event_start(EV_ENCOUNTER, NULL);
+ event_cur_arg(e->forms[rnd_n(e->n)]);
+}
diff --git a/games/undertale/src/ruins.h b/games/undertale/src/ruins.h
new file mode 100644
index 00000000..ed5d85f3
--- /dev/null
+++ b/games/undertale/src/ruins.h
@@ -0,0 +1,12 @@
+/* Undertale: the Ruins' rooms and events (ruins1.c, ruins2.c, ruins3.c). */
+#ifndef UT_RUINS_H
+#define UT_RUINS_H
+#include "event.h"
+void ruins1_setup(int room, int from);
+int ruins1_event(Ev *c); /* -1: not one of its */
+void ruins2_setup(int room, int from);
+int ruins2_event(Ev *c);
+void ruins2_update(void);
+void ruins3_setup(int room, int from);
+int ruins3_event(Ev *c);
+#endif
diff --git a/games/undertale/src/ruins1.c b/games/undertale/src/ruins1.c
new file mode 100644
index 00000000..c32bc2e9
--- /dev/null
+++ b/games/undertale/src/ruins1.c
@@ -0,0 +1,393 @@
+/* The Ruins, from the bed of golden flowers to the leaf pile: Flowey, then Toriel guiding the fallen human
+ * through her puzzles, the Dummy, the spikes, the independence test. Texts are the game's. */
+#include <stdio.h>
+#include <string.h>
+#include "battle.h"
+#include "event.h"
+#include "events.h"
+#include "game.h"
+#include "menu.h"
+#include "monsters.h"
+#include "ruins.h"
+#include "save.h"
+#include "world.h"
+
+/* ---------------------------------------------------------------- the rooms' things */
+void ruins1_setup(int room, int from) {
+ (void)from;
+ switch (room) {
+ case ROOM_AREA1:
+ if (flag(F_FLOWEY_MET)) obj_sign(120, 6015, 60, 40, "* (Golden flowers.)\n* (They must have broken your\n fall.)");
+ break;
+ case ROOM_AREA1_2:
+ if (!flag(F_FLOWEY_MET)) {
+ static const uint16_t s[4] = {SPR_FLOWEY};
+ Obj *f = obj_npc(ACTOR_FLOWEY, s, 508, 5768, DIR_DOWN, 0);
+ if (f) f->flags = OF_SOLID, obj_set_box(f, 4, 16, 17, 8);
+ obj_trigger(430, 5800, 180, 40, EV_FLOWEY_MEET, ACTOR_TRIGGER);
+ }
+ break;
+ case ROOM_RUINS1:
+ obj_save(510, 5275, "* (The shadow of the ruins\n looms above, filling you with\n determination.)");
+ if (flag(F_TORIEL_MET) && !flag(F_RUINS1_DONE)) {
+ obj_toriel(504, 5330, DIR_DOWN);
+ obj_trigger(380, 5380, 280, 180, EV_RUINS1_TORIEL, ACTOR_TRIGGER);
+ }
+ break;
+ case ROOM_RUINS2:
+ obj_sign(440, 4880, 20, 20, "* \"Only the fearless may\n proceed.\"|* \"Brave ones, foolish ones.\"|* \"Both walk not the middle\n road.\"");
+ for (int k = 0; k < 6; k++) {
+ static const int16_t px[6] = {540, 580, 560, 540, 580, 560}, py[6] = {4938, 4938, 4958, 4978, 4978, 4998};
+ Obj *p = obj_deco(SPR_O_GROUNDSWITCH1, px[k], py[k], false);
+ if (p) p->flags |= OF_BACK, p->frame = flag(F_RUINS2_DONE) && (k == 0 || k == 1 || k == 3 || k == 4) ? 1 : 0, p->arg = (int16_t)k;
+ }
+ {
+ Obj *lever = obj_deco(SPR_O_SWITCH, 560, 4888, false);
+ if (lever) lever->flags |= OF_BACK, lever->frame = flag(F_RUINS2_DONE) ? 1 : 0, lever->name = ACTOR_SWITCH;
+ }
+ if (!flag(F_RUINS2_DONE)) {
+ Obj *d = obj_deco(SPR_O_RUINSDOOR1, 480, 4860, true);
+ if (d) d->name = ACTOR_DOOR, obj_set_box(d, 0, 30, 40, 30);
+ obj_toriel(500, 4952, DIR_DOWN);
+ obj_trigger(400, 4920, 240, 140, EV_RUINS2_TORIEL, ACTOR_TRIGGER);
+ }
+ break;
+ case ROOM_RUINS3: {
+ obj_sign(488, 4724, 20, 18, "* \"Stay on the path.\"");
+ static const int16_t sx[3] = {742, 942, 980};
+ for (int k = 0; k < 3; k++) {
+ Obj *s = obj_deco(SPR_O_SWITCH, sx[k], 4650, false);
+ if (!s) continue;
+ s->name = (uint8_t)(ACTOR_SWITCH + k), s->flags = OF_TALK | OF_BACK, s->event = EV_RUINS3_SWITCH;
+ obj_set_box(s, 0, 0, 20, 34);
+ s->frame = flag(F_RUINS3_SW1 + k) ? 1 : 0;
+ }
+ obj_spikes(1060, 4740, 1, 2, !flag(F_RUINS3_DONE), ACTOR_SPIKES);
+ if (!flag(F_RUINS3_DONE)) {
+ obj_toriel(470, 4716, DIR_DOWN);
+ if (!flag(F_RUINS3_SW1) && !flag(F_RUINS3_SW2)) obj_trigger(440, 4760, 120, 70, EV_RUINS3_TORIEL, ACTOR_TRIGGER);
+ }
+ break;
+ }
+ case ROOM_RUINS4: {
+ Obj *d = obj_deco(SPR_O_DUMMY, 1300, 4690, true);
+ if (d) d->name = ACTOR_DUMMY, d->flags |= OF_TALK, d->event = EV_RUINS4_DUMMY, obj_set_box(d, 2, 14, 16, 18);
+ if (!flag(F_DUMMY)) {
+ obj_toriel(1236, 4690, DIR_RIGHT);
+ obj_trigger(1080, 4680, 120, 140, EV_RUINS4_TORIEL, ACTOR_TRIGGER);
+ }
+ break;
+ }
+ case ROOM_RUINS5:
+ obj_sign(1680, 4478, 20, 20, "* \"The western room is the\n eastern room's blueprint.\"");
+ if (!flag(F_RUINS5_DONE)) {
+ obj_toriel(1250, 4470, DIR_DOWN);
+ obj_trigger(1230, 4500, 90, 100, EV_RUINS5_TORIEL, ACTOR_TRIGGER);
+ }
+ break;
+ case ROOM_RUINS6: {
+ Obj *p = obj_deco(SPR_O_PILLAR, 4602, 4400, true);
+ if (p) p->name = ACTOR_PILLAR, p->flags |= OF_TALK, p->event = EV_RUINS6_PILLAR, obj_set_box(p, 4, 44, 32, 16);
+ if (!flag(F_RUINS6_DONE)) {
+ obj_toriel(2330, 4466, DIR_RIGHT);
+ obj_trigger(2280, 4440, 120, 110, EV_RUINS6_TORIEL, ACTOR_TRIGGER);
+ }
+ break;
+ }
+ case ROOM_RUINS7: {
+ obj_save(5010, 4500, "* (Playfully crinkling through\n the leaves fills you with\n determination.)");
+ static const uint16_t fs[4] = {SPR_O_SMALLFROG};
+ if (!sv.kills) obj_npc(ACTOR_FROGGIT, fs, 4901, 4440, DIR_DOWN, EV_RUINS7_FROGGIT);
+ if (flag(F_PHONE) && !flag(F_LEAFPILE_CALL)) event_start(EV_RUINS7_CALL, NULL);
+ break;
+ }
+ }
+}
+
+/* ---------------------------------------------------------------- the events */
+static const char flowey_hi[] =
+ "`0* Howdy!^2 I'm #YFLOWEY#X.^2\n* #YFLOWEY#X the #YFLOWER#X!|"
+ "`1* Hmmm...|"
+ "`0* You're new to the\n UNDERGROUND, aren'tcha?|"
+ "`1* Golly, you must be so\n confused.|"
+ "`0* Someone ought to teach you\n how things work around here!|"
+ "`0* I guess little old me will\n have to do.|"
+ "`7* Ready?^2 Here we go!";
+
+static int ev_flowey_meet(Ev *c) {
+ Obj *f, *t;
+ EV_BEGIN;
+ if (c->self) c->self->kind = OBJ_NONE;
+ SAY(FACE_FLOWEY, flowey_hi);
+ BATTLE(FORM_FLOWEY);
+ /* Toriel stands where Flowey was */
+ f = obj_find(ACTOR_FLOWEY);
+ if (f) f->kind = OBJ_NONE;
+ obj_toriel(500, 5742, DIR_DOWN);
+ set_flag(F_FLOWEY_MET, 1);
+ set_flag(F_TORIEL_MET, 1);
+ WAIT(10);
+ SAY(FACE_TORIEL, "`0* This way.");
+ t = obj_find(ACTOR_TORIEL);
+ if (t) WALK_TO(t, 504, 5580, 2);
+ WAIT_UNTIL(!(t = obj_find(ACTOR_TORIEL)) || !t->walking);
+ if ((t = obj_find(ACTOR_TORIEL))) t->kind = OBJ_NONE;
+ EV_END;
+}
+
+static int ev_ruins1_toriel(Ev *c) {
+ Obj *t = obj_find(ACTOR_TORIEL);
+ EV_BEGIN;
+ if (c->self) c->self->kind = OBJ_NONE;
+ c->v[0] = 0;
+ /* she goes up the stairs, then through the door */
+ if (!t) return 1;
+ WALK(t, 580, 5300, 2);
+ WALK(t, 606, 5250, 2);
+ WALK(t, 606, 5160, 2);
+ WALK(t, 504, 5150, 2);
+ WALK(t, 504, 5100, 2);
+ t->kind = OBJ_NONE;
+ set_flag(F_RUINS1_DONE, 1);
+ EV_END;
+}
+
+static int ev_ruins2_toriel(Ev *c) {
+ Obj *t = obj_find(ACTOR_TORIEL);
+ EV_BEGIN;
+ if (c->self) c->self->kind = OBJ_NONE;
+ if (!t) return 1;
+ t->dir = DIR_DOWN;
+ SAY(FACE_TORIEL, "`0* Welcome to your new\n home, innocent one.|* Allow me to educate you in\n the operation of the RUINS.");
+ /* over the switches, not the middle road */
+ WALK(t, 534, 4952, 2);
+ WALK(t, 534, 4898, 2);
+ c->v[0] = 0;
+ for (c->v[1] = 0; c->v[1] < MAX_OBJS; c->v[1]++)
+ if (objs[c->v[1]].kind == OBJ_DECO && objs[c->v[1]].spr[0] == SPR_O_GROUNDSWITCH1 && objs[c->v[1]].arg == 0) objs[c->v[1]].frame = 1;
+ WALK(t, 574, 4898, 2);
+ for (c->v[1] = 0; c->v[1] < MAX_OBJS; c->v[1]++)
+ if (objs[c->v[1]].kind == OBJ_DECO && objs[c->v[1]].spr[0] == SPR_O_GROUNDSWITCH1 && objs[c->v[1]].arg == 1) objs[c->v[1]].frame = 1;
+ WALK(t, 574, 4938, 2);
+ for (c->v[1] = 0; c->v[1] < MAX_OBJS; c->v[1]++)
+ if (objs[c->v[1]].kind == OBJ_DECO && objs[c->v[1]].spr[0] == SPR_O_GROUNDSWITCH1 && objs[c->v[1]].arg == 4) objs[c->v[1]].frame = 1;
+ WALK(t, 534, 4938, 2);
+ for (c->v[1] = 0; c->v[1] < MAX_OBJS; c->v[1]++)
+ if (objs[c->v[1]].kind == OBJ_DECO && objs[c->v[1]].spr[0] == SPR_O_GROUNDSWITCH1 && objs[c->v[1]].arg == 3) objs[c->v[1]].frame = 1;
+ WALK(t, 544, 4880, 2);
+ t->dir = DIR_UP;
+ WAIT(12);
+ {
+ Obj *l = obj_find(ACTOR_SWITCH), *d = obj_find(ACTOR_DOOR);
+ if (l) l->frame = 1;
+ if (d) d->kind = OBJ_NONE;
+ }
+ WAIT(15);
+ t->dir = DIR_DOWN;
+ SAY(FACE_TORIEL, "`0* The RUINS are full of\n puzzles.|* Ancient fusions between\n diversions and doorkeys.|* One must solve them to move\n from room to room.|* Please adjust yourself to\n the sight of them.");
+ set_flag(F_RUINS2_DONE, 1);
+ WALK(t, 484, 4900, 2);
+ WALK(t, 484, 4840, 2);
+ t->kind = OBJ_NONE;
+ EV_END;
+}
+
+static int ev_ruins3_toriel(Ev *c) {
+ Obj *t = obj_find(ACTOR_TORIEL);
+ EV_BEGIN;
+ if (c->self) c->self->kind = OBJ_NONE;
+ if (!t) return 1;
+ SAY(FACE_TORIEL, "`0* To make progress here, you\n will need to trigger several\n switches.|* Do not worry, I have\n labelled the ones that you\n need to flip.");
+ WALK(t, 560, 4716, 3);
+ WALK(t, 990, 4716, 3);
+ t->dir = DIR_LEFT;
+ EV_END;
+}
+
+static int ev_ruins3_switch(Ev *c) {
+ int k = c->self ? c->self->name - ACTOR_SWITCH : 0;
+ EV_BEGIN;
+ if (flag(F_RUINS3_SW1 + k)) {
+ NARRATE("* (The switch is already\n flipped.)");
+ return 1;
+ }
+ if (k == 2 && !flag(F_RUINS3_DONE) && obj_find(ACTOR_TORIEL)) {
+ SAY(FACE_TORIEL, "`3* Oh? That switch is not\n one of the ones I labelled.|`0* Please, my child,\n flip only the switches\n I marked for you.");
+ return 1;
+ }
+ set_flag(F_RUINS3_SW1 + k, 1);
+ c->self->frame = 1;
+ NARRATE("* (You flipped the switch.)");
+ if (flag(F_RUINS3_SW1) && flag(F_RUINS3_SW2) && !flag(F_RUINS3_DONE)) {
+ set_flag(F_RUINS3_DONE, 1);
+ {
+ Obj *s = obj_find(ACTOR_SPIKES);
+ if (s) s->frame = 1, s->flags &= (uint16_t)~OF_SOLID;
+ }
+ WAIT(10);
+ if (obj_find(ACTOR_TORIEL)) {
+ SAY(FACE_TORIEL, "`2* Splendid!\n* I am proud of you, little\n one.|`0* Let us move to the next\n room.");
+ WALK(obj_get(ACTOR_TORIEL), 1040, 4730, 3);
+ WALK(obj_get(ACTOR_TORIEL), 1100, 4730, 3);
+ obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;
+ }
+ }
+ EV_END;
+}
+
+static int ev_ruins4_toriel(Ev *c) {
+ EV_BEGIN;
+ if (c->self) c->self->kind = OBJ_NONE;
+ SAY(FACE_TORIEL, "`0* As a human living in the\n UNDERGROUND, monsters may\n attack you.|* You will need to be prepared\n for this situation.|`2* However, worry not!\n* The process is simple.|`0* When you encounter a\n monster, you will enter a\n FIGHT.|* While you are in a FIGHT,\n strike up a friendly\n conversation.|* Stall for time.\n* I will come to resolve the\n conflict.|* Practice talking to the\n dummy.");
+ EV_END;
+}
+
+static int ev_ruins4_dummy(Ev *c) {
+ EV_BEGIN;
+ if (flag(F_DUMMY)) {
+ NARRATE("* (A cotton dummy.)");
+ return 1;
+ }
+ BATTLE(FORM_DUMMY);
+ if (battle_result() == BR_FLED) {
+ set_flag(F_DUMMY, 3);
+ SAY(FACE_TORIEL, "`3* ...ah, you ran away...|`0* Truthfully, that was not a\n poor choice.|* It is better to avoid\n conflict whenever possible.|* That, however, is only a\n dummy.|* It cannot harm you.|* It is made of cotton.|* It has no desire for\n revenge...|* Nevertheless, there is no\n harm in practicing.|* Come now.");
+ } else if (bt.mon[0].killed) {
+ set_flag(F_DUMMY, 2);
+ if (c->self) c->self->kind = OBJ_NONE;
+ SAY(FACE_TORIEL, "`3* Ah, the dummies are not for\n fighting!\n* They are for talking!|`1* We do not want to hurt\n anybody, do we...?|`0* Come now.");
+ } else if (bt.turn >= 5 && !flag(F_DUMMY)) {
+ set_flag(F_DUMMY, 4);
+ SAY(FACE_TORIEL, "`3* ...you stared so intently\n at that dummy that it got\n bored of you.|`0* I am sure there is a lesson\n in that somewhere...|* Come now, let us continue.");
+ } else {
+ set_flag(F_DUMMY, 1);
+ SAY(FACE_TORIEL, "`2* Ah, very good!\n* You are very good.");
+ }
+ if (obj_find(ACTOR_TORIEL)) {
+ WALK(obj_get(ACTOR_TORIEL), 1244, 4640, 2);
+ WALK(obj_get(ACTOR_TORIEL), 1244, 4560, 2);
+ obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;
+ }
+ EV_END;
+}
+
+/* the spikes' safe way: the cells of the blueprint (tools/rooms.py has the same) */
+static const int16_t spike_path[][2] = {
+ {1916, 4497}, {2000, 4497}, {2000, 4458}, {2060, 4458}, {2060, 4497}, {2160, 4497}, {2160, 4458}, {2236, 4458}};
+
+static int ev_ruins5_toriel(Ev *c) {
+ Obj *t = obj_find(ACTOR_TORIEL);
+ EV_BEGIN;
+ if (c->self) c->self->kind = OBJ_NONE;
+ if (!t) return 1;
+ /* she goes ahead; halfway, a Froggit */
+ FREE(true);
+ WALK(t, 1500, 4470, 3);
+ WALK(obj_get(ACTOR_TORIEL), 1820, 4480, 3);
+ obj_get(ACTOR_TORIEL)->dir = DIR_LEFT;
+ WAIT_UNTIL(pl.x > 1500);
+ FREE(false);
+ BATTLE(FORM_FROGGIT_FIRST);
+ FREE(true);
+ WAIT_UNTIL(pl.x > 1740);
+ FREE(false);
+ t = obj_find(ACTOR_TORIEL);
+ t->dir = DIR_LEFT;
+ SAY(FACE_TORIEL, "`0* This is the puzzle,\n but...|* Here, take my hand for a\n moment.");
+ /* hand in hand over the spikes */
+ PL_WALK(t->x - 14, t->y + 10, 3);
+ for (c->v[0] = 0; c->v[0] < (int)(sizeof spike_path / sizeof spike_path[0]); c->v[0]++) {
+ WALK_TO(obj_get(ACTOR_TORIEL), spike_path[c->v[0]][0] + 6, spike_path[c->v[0]][1] - 30, 2);
+ pl_walk_to(spike_path[c->v[0]][0] - 16 > pl.x ? spike_path[c->v[0]][0] - 16 : pl.x, spike_path[c->v[0]][1] - 20, 2);
+ WAIT_UNTIL(!obj_get(ACTOR_TORIEL)->walking && !pl_walking());
+ }
+ pl_walk_to(2240, 4444, 2);
+ WAIT_UNTIL(!pl_walking());
+ obj_get(ACTOR_TORIEL)->dir = DIR_LEFT;
+ SAY(FACE_TORIEL, "`0* Puzzles seem too dangerous\n for now.");
+ set_flag(F_RUINS5_DONE, 1);
+ WALK(obj_get(ACTOR_TORIEL), 2320, 4440, 3);
+ obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;
+ EV_END;
+}
+
+static int ev_ruins6_toriel(Ev *c) {
+ Obj *t = obj_find(ACTOR_TORIEL);
+ EV_BEGIN;
+ if (c->self) c->self->kind = OBJ_NONE;
+ if (!t) return 1;
+ t->dir = DIR_LEFT;
+ SAY(FACE_TORIEL, "`0* You have done excellently\n thus far, my child.|`1* However...^2 I have a\n difficult request to ask of\n you.|* ...|`0* I would like you to walk to\n the end of the room by\n yourself.|`1* Forgive me for this.");
+ /* she hurries off, and hides behind the pillar */
+ FREE(true);
+ WALK(obj_get(ACTOR_TORIEL), 4560, 4466, 6);
+ WALK(obj_get(ACTOR_TORIEL), 4606, 4392, 3);
+ obj_get(ACTOR_TORIEL)->dir = DIR_DOWN;
+ obj_get(ACTOR_TORIEL)->flags &= (uint16_t)~OF_SOLID;
+ obj_trigger(4470, 4430, 16, 130, EV_RUINS6_REVEAL, ACTOR_TRIGGER2);
+ EV_END;
+}
+
+static int ev_ruins6_pillar(Ev *c) {
+ Obj *t = obj_find(ACTOR_TORIEL);
+ EV_BEGIN;
+ if (!t || flag(F_RUINS6_DONE)) {
+ NARRATE("* (A pillar.)");
+ return 1;
+ }
+ SAY(FACE_TORIEL, "`0* ...");
+ EV_END;
+}
+
+static int ev_ruins6_reveal(Ev *c) {
+ Obj *t = obj_find(ACTOR_TORIEL);
+ EV_BEGIN;
+ if (!t) return 1;
+ if (c->self) c->self->kind = OBJ_NONE;
+ WALK(t, 4570, 4440, 2);
+ t->dir = DIR_LEFT;
+ SAY(FACE_TORIEL, "`0* Greetings, my child.|* Do not worry, I did not\n leave you.|* I was merely behind this\n pillar the whole time.|`2* Thank you for trusting me.|`0* However, there was an\n important reason for this\n exercise.|* ...^2 to test your\n independence.|`1* I must attend to some\n business, and you must stay\n alone for a while.|`0* Please remain here.|* It's dangerous to explore\n by yourself.|`2* I have an idea.|* I will give you a CELL\n PHONE.|`0* If you have a need for\n anything, just call.|* Be good, alright?");
+ set_flag(F_PHONE, 1);
+ WALK(obj_get(ACTOR_TORIEL), 4700, 4470, 3);
+ WALK(obj_get(ACTOR_TORIEL), 4860, 4470, 3);
+ obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;
+ set_flag(F_RUINS6_DONE, 1);
+ /* (the game saves here when she leaves) */
+ sv.room = (int16_t)g_room, sv.x = pl.x, sv.y = pl.y;
+ save_write_auto();
+ EV_END;
+}
+
+static int ev_ruins7_call(Ev *c) {
+ EV_BEGIN;
+ WAIT_UNTIL(!world_fading());
+ set_flag(F_LEAFPILE_CALL, 1);
+ NARRATE("* Ring...");
+ SAY(FACE_TORIEL, "`0* Hello?\n* This is TORIEL.|* You have not left the room,\n have you?|* There are a few puzzles\n ahead that I have yet to\n explain.|* It would be dangerous to\n try to solve them yourself.|* Be good, alright?");
+ EV_END;
+}
+
+static int ev_ruins7_froggit(Ev *c) {
+ EV_BEGIN;
+ NARRATE("* Ribbit, ribbit.|* (Excuse me, human.)|* (You look like you're going to\n be fighting a lot of\n monsters.)|* (Let me give you some\n advice.)|* (If you ACT a certain way or\n FIGHT until you almost defeat\n them...)|* (They might not want to\n battle you anymore.)|* (If a monster does not want\n to fight you, please...)|* (Use some MERCY, human.)\n* Ribbit.");
+ EV_END;
+}
+
+int ruins1_event(Ev *c) {
+ switch (c->id) {
+ case EV_FLOWEY_MEET: return ev_flowey_meet(c);
+ case EV_RUINS1_TORIEL: return ev_ruins1_toriel(c);
+ case EV_RUINS2_TORIEL: return ev_ruins2_toriel(c);
+ case EV_RUINS3_TORIEL: return ev_ruins3_toriel(c);
+ case EV_RUINS3_SWITCH: return ev_ruins3_switch(c);
+ case EV_RUINS4_TORIEL: return ev_ruins4_toriel(c);
+ case EV_RUINS4_DUMMY: return ev_ruins4_dummy(c);
+ case EV_RUINS5_TORIEL: return ev_ruins5_toriel(c);
+ case EV_RUINS6_TORIEL: return ev_ruins6_toriel(c);
+ case EV_RUINS6_PILLAR: return ev_ruins6_pillar(c);
+ case EV_RUINS6_REVEAL: return ev_ruins6_reveal(c);
+ case EV_RUINS7_CALL: return ev_ruins7_call(c);
+ case EV_RUINS7_FROGGIT: return ev_ruins7_froggit(c);
+ }
+ return -1;
+}
diff --git a/games/undertale/src/ruins2.c b/games/undertale/src/ruins2.c
new file mode 100644
index 00000000..38ad625b
--- /dev/null
+++ b/games/undertale/src/ruins2.c
@@ -0,0 +1,574 @@
+/* The Ruins, from the Monster Candy to Toriel's tree: the cracked floors, the rocks, Napstablook, the Spider
+ * Bake Sale, the Froggits' hall, the one switch, the rotating rooms, the balcony over Home. Toriel calls on
+ * the way. Texts are the game's (the Undertale Wiki's records of them) where known. */
+#include <stdio.h>
+#include <string.h>
+#include "battle.h"
+#include "event.h"
+#include "events.h"
+#include "game.h"
+#include "items.h"
+#include "menu.h"
+#include "monsters.h"
+#include "ruins.h"
+#include "save.h"
+#include "world.h"
+
+/* ---------------------------------------------------------------- falling through a cracked floor */
+/* where each fall lands: the room under, Frisk's top-left there (x -1: where he was; y -1: 400 under) */
+typedef struct {
+ uint8_t room;
+ int16_t x, y;
+} Fall;
+enum { FALL_RUINS8, FALL_LEAVES, FALL_ONE_A, FALL_ROTATE = FALL_ONE_A + 6 };
+static const Fall falls[] = {
+ [FALL_RUINS8] = {ROOM_RUINS8B, 5258, 5132},
+ [FALL_LEAVES] = {ROOM_RUINS10B, -1, -1},
+ [FALL_ONE_A] = {ROOM_RUINS16A, 8340, 4945}, {ROOM_RUINS16B, 8460, 4945}, {ROOM_RUINS16C, 8580, 4945},
+ {ROOM_RUINS16D, 8340, 5065}, {ROOM_RUINS16E, 8460, 5065}, {ROOM_RUINS16F, 8580, 5065},
+ [FALL_ROTATE] = {ROOM_RUINS17X, 9270, 4570},
+};
+
+static Obj *crack(int x, int y, int w, int h, int fall) {
+ Obj *o = obj_trigger(x, y, w, h, EV_FALLING, ACTOR_NONE);
+ if (o) o->arg = (int16_t)fall;
+ return o;
+}
+
+static int ev_fall(Ev *c) {
+ EV_BEGIN;
+ {
+ const Fall *f = &falls[c->self ? c->self->arg : c->v[4]];
+ c->v[0] = f->room;
+ c->v[1] = f->x < 0 ? pl.x : f->x;
+ c->v[2] = f->y < 0 ? pl.y + 400 : f->y;
+ }
+ if (g_room == ROOM_RUINS10) set_flag(F_FALL_LEAVES, flag(F_FALL_LEAVES) + 1);
+ pl.hidden = true;
+ WAIT(6);
+ FADE_TO(c->v[0], c->v[1], c->v[2] - 60, DIR_DOWN);
+ pl.hidden = false;
+ /* down onto the leaves */
+ for (c->v[3] = 0; c->v[3] < 12; c->v[3]++) {
+ pl.y = (int16_t)(pl.y + 5);
+ world_camera();
+ WAIT(0);
+ }
+ WAIT(10);
+ EV_END;
+}
+
+/* the leaf puzzle: the tiles that give way (under them, the leaves) */
+static const int16_t leaf_holes[][4] = {
+ {6160, 4740, 80, 160}, {6280, 4780, 20, 100}, {6340, 4840, 20, 60}, {6400, 4780, 60, 40}, {6400, 4820, 40, 60}};
+/* the one switch puzzle: its six cracks */
+static const int16_t one_cracks[6][2] = {{8342, 4582}, {8462, 4582}, {8582, 4582}, {8342, 4702}, {8462, 4702}, {8582, 4702}};
+
+/* ---------------------------------------------------------------- the rotating rooms */
+/* each room's three switches: x, y, colour (0 red, 1 blue, 2 green), right? A hidden one is under a pillar
+ * (its box the pillar's) */
+typedef struct {
+ int16_t x, y, w, h;
+ uint8_t color, right, hidden;
+} CSwitch;
+static const CSwitch cswitch[4][3] = {
+ {{9020, 4780, 20, 20, 0, 0, 0}, {8800, 4680, 20, 20, 1, 0, 0}, {8970, 4620, 20, 20, 2, 0, 0}},
+ {{8830, 4397, 20, 20, 0, 0, 0}, {8916, 4156, 48, 78, 1, 1, 1}, {8990, 4320, 20, 20, 2, 0, 0}},
+ {{8400, 4200, 20, 20, 0, 1, 0}, {8620, 4300, 20, 20, 1, 0, 0}, {8460, 4360, 20, 20, 2, 0, 0}},
+ {{8576, 3676, 48, 78, 0, 0, 1}, {8490, 3920, 20, 20, 1, 0, 0}, {8416, 3716, 48, 78, 2, 1, 1}},
+};
+static int rotate_fails;
+
+static int rotate_index(int room) {
+ switch (room) {
+ case ROOM_RUINS17A: return 0;
+ case ROOM_RUINS17B: return 1;
+ case ROOM_RUINS17C: return 2;
+ case ROOM_RUINS17D: return 3;
+ default: return -1;
+ }
+}
+
+static void rotate_setup(int k) {
+ for (int i = 0; i < 3; i++) {
+ const CSwitch *s = &cswitch[k][i];
+ Obj *o = obj_sign(s->x, s->y, s->w, s->h, NULL);
+ if (o) o->event = EV_COLOR_SWITCH, o->arg = (int16_t)(k * 3 + i), o->name = (uint8_t)(ACTOR_SWITCH + i);
+ if (o && !s->hidden) obj_set_box(o, 2, 6, 16, 14);
+ }
+ static const char *const plaque[4] = {
+ "* \"The far door is not an\n exit.\"|* \"It simply marks a rotation\n in perspective.\"",
+ "* \"If you can read this,\n press the blue switch.\"",
+ "* \"If you can read this,\n press the red switch.\"",
+ "* \"If you can read this,\n press the green switch.\""};
+ static const int16_t px[4][2] = {{8800, 4536}, {8800, 4238}, {8622, 4238}, {8502, 3656}};
+ obj_sign(px[k][0], px[k][1], 40, 20, plaque[k]);
+ /* the doors' spikes: where Frisk came in, down; the far door's, up until the right switch */
+ switch (k) {
+ case 0:
+ obj_spikes(8760, 4620, 1, 2, false, ACTOR_NONE);
+ obj_spikes(8960, 4840, 2, 1, false, ACTOR_NONE);
+ break;
+ case 1:
+ obj_spikes(8960, 4140, 2, 1, false, ACTOR_NONE);
+ obj_spikes(8760, 4340, 1, 2, !flag(F_ROTATE2), ACTOR_SPIKES);
+ break;
+ case 2:
+ obj_spikes(8660, 4340, 1, 2, false, ACTOR_NONE);
+ obj_spikes(8440, 4140, 2, 1, !flag(F_ROTATE3), ACTOR_SPIKES);
+ break;
+ case 3:
+ obj_spikes(8440, 3960, 2, 1, false, ACTOR_NONE);
+ obj_spikes(8660, 3740, 1, 2, !flag(F_ROTATE4), ACTOR_SPIKES);
+ break;
+ }
+}
+
+static int ev_color_switch(Ev *c) {
+ EV_BEGIN;
+ {
+ int k = c->self ? c->self->arg : 0;
+ const CSwitch *s = &cswitch[k / 3][k % 3];
+ if (flag(F_ROTATE1 + k / 3) && s->right) {
+ NARRATE("* (The switch is already\n pressed.)");
+ return 1;
+ }
+ c->v[0] = k;
+ }
+ if (cswitch[c->v[0] / 3][c->v[0] % 3].hidden) NARRATE("* (You found a switch hidden\n behind the pillar.)");
+ NARRATE("* (You pressed the switch.)");
+ if (cswitch[c->v[0] / 3][c->v[0] % 3].right) {
+ set_flag(F_ROTATE1 + c->v[0] / 3, 1);
+ obj_spikes_set(obj_find(ACTOR_SPIKES), false);
+ return 1;
+ }
+ rotate_fails++;
+ /* the floor gives way */
+ c->self = NULL, c->v[4] = FALL_ROTATE;
+ c->at = NULL, c->id = EV_FALLING;
+ return ev_fall(c);
+ EV_END;
+}
+
+/* ---------------------------------------------------------------- the rooms' things */
+static const uint16_t frog_spr[4] = {SPR_O_SMALLFROG};
+
+static Obj *item_here(uint16_t spr, int x, int y, int item, int f) {
+ if (flag(f)) return NULL;
+ Obj *o = obj_deco(spr, x, y, false);
+ if (o) o->flags |= OF_TALK | OF_BACK, o->event = EV_ITEM, o->arg = (int16_t)item, o->arg2 = (int16_t)f;
+ return o;
+}
+
+/* the second rock puzzle's talking rock, by how far it has been asked */
+static void rock3_place(Obj *r) {
+ int s = flag(F_RUINS11_ROCK);
+ static const int16_t at[6][2] = {{6720, 4875}, {6740, 4875}, {6740, 4855}, {6780, 4875}, {6740, 4875}, {6780, 4875}};
+ r->x = at[s][0], r->y = at[s][1];
+}
+
+void ruins2_setup(int room, int from) {
+ (void)from;
+ int k = rotate_index(room);
+ if (k >= 0) rotate_setup(k);
+ switch (room) {
+ case ROOM_RUINS7A: {
+ static const uint16_t dish[3] = {SPR_O_CANDYDISH, SPR_O_CANDYDISH2, SPR_O_CANDYDISH_BAD};
+ Obj *d = obj_deco(dish[flag(F_CANDY_SPILT) ? 2 : 0], 4950, 4215, true);
+ if (d) d->flags |= OF_TALK, d->event = EV_CANDY, d->name = ACTOR_CANDY;
+ break;
+ }
+ case ROOM_RUINS8:
+ crack(5244, 4683, 72, 79, FALL_RUINS8);
+ break;
+ case ROOM_RUINS9: {
+ obj_sign(5600, 4640, 20, 20, "* \"Three out of four gray rocks\n recommend you push them.\"");
+ Obj *r = obj_rock(5620, 4735, ACTOR_ROCK, 0);
+ if (r && flag(F_RUINS9_ROCK)) r->x = 5680;
+ obj_spikes(5740, 4680, 1, 6, !flag(F_RUINS9_ROCK), ACTOR_SPIKES);
+ if (!flag(F_FLAVOR_CALL)) event_start(EV_CALL, NULL), event_cur_arg(CALL_FLAVOR);
+ break;
+ }
+ case ROOM_RUINS10:
+ obj_sign(6380, 4740, 20, 20, "* \"Didn't you read the sign\n downstairs?\"");
+ if (flag(F_FALL_LEAVES) < 10)
+ for (unsigned i = 0; i < sizeof leaf_holes / sizeof leaf_holes[0]; i++)
+ crack(leaf_holes[i][0] + 2, leaf_holes[i][1] + 2, leaf_holes[i][2] - 4, leaf_holes[i][3] - 4, FALL_LEAVES);
+ if (flag(F_FLAVOR_CALL) == 1) event_start(EV_CALL, NULL), event_cur_arg(CALL_FLAVOR2);
+ break;
+ case ROOM_RUINS10B:
+ obj_sign(6380, 5140, 20, 20, "* \"Please don't step on the\n leaves.\"");
+ break;
+ case ROOM_RUINS11: {
+ obj_rock(6700, 4795, ACTOR_ROCK, 0);
+ obj_rock(6680, 4835, ACTOR_ROCK2, 0);
+ Obj *r = obj_rock(6720, 4875, ACTOR_ROCK3, EV_ROCK_TALK);
+ if (r) rock3_place(r);
+ int s = flag(F_RUINS11_ROCK);
+ obj_spikes(6880, 4820, 2, 3, s != 3 && s != 5, ACTOR_SPIKES);
+ if (s == 3) obj_trigger(6830, 4800, 30, 100, EV_ROCK_OFF, ACTOR_TRIGGER);
+ if (flag(F_FLAVOR_CALL) == 2) event_start(EV_CALL, NULL), event_cur_arg(CALL_ALLERGY);
+ break;
+ }
+ case ROOM_RUINS12:
+ obj_save(7170, 4860, "* (Knowing the mouse might one\n day leave its hole and get\n the cheese...)|* (It fills you with\n determination.)");
+ obj_sign(7240, 4860, 30, 20, "* (The cheese has been stuck\n to the table for so long...)|* (...it's crystallized.)");
+ obj_sign(7164, 4798, 14, 12, "* (Squeak!)");
+ break;
+ case ROOM_RUINS13:
+ if (!flag(F_NAPSTA)) {
+ Obj *n = obj_deco(SPR_O_NAPSTABLOOK_GR, 7525, 4832, true);
+ if (n) n->name = ACTOR_NAPSTA, n->flags |= OF_TALK, n->event = EV_NAPSTA_SLEEP, obj_set_box(n, -7, -14, 44, 44);
+ obj_trigger(7496, 4818, 20, 44, EV_NAPSTA_SLEEP, ACTOR_TRIGGER);
+ }
+ break;
+ case ROOM_RUINS14: {
+ obj_sign(7834, 4818, 22, 20, "* \"Spider Bake Sale\"|* \"All proceeds go to real\n spiders.\"");
+ Obj *w = obj_sign(7788, 4782, 30, 30, NULL);
+ if (w) w->event = EV_WEB, w->arg = 0;
+ w = obj_sign(7850, 4758, 48, 50, NULL);
+ if (w) w->event = EV_WEB, w->arg = 1;
+ break;
+ }
+ case ROOM_RUINS15: {
+ static const int16_t fx[3] = {7660, 7780, 7900};
+ for (int i = 0; i < 3; i++) {
+ if (i == 0 && flag(F_SKIPS) > 5) continue;
+ Obj *f = obj_npc(ACTOR_FROGGIT, frog_spr, fx[i], 4540, DIR_DOWN, EV_FROGGIT);
+ if (f) f->arg = (int16_t)i, f->flags |= OF_ANIM, f->anim_speed = 20;
+ }
+ if (!flag(F_ITEM_CALL)) {
+ Obj *t = obj_trigger(7960, 4540, 40, 80, EV_CALL, ACTOR_TRIGGER);
+ if (t) t->arg = CALL_ITEMS;
+ }
+ break;
+ }
+ case ROOM_RUINS16:
+ obj_sign(8180, 4520, 20, 20, "* \"There is just one switch.\"");
+ for (int i = 0; i < 6; i++) crack(one_cracks[i][0], one_cracks[i][1], 16, 17, FALL_ONE_A + i);
+ obj_spikes(8680, 4620, 1, 2, !flag(F_ONESWITCH), ACTOR_SPIKES);
+ break;
+ case ROOM_RUINS16A:
+ case ROOM_RUINS16F: {
+ Obj *v = obj_deco(SPR_O_VEGETABLEOUTSIDE, room == ROOM_RUINS16A ? 8300 : 8660, room == ROOM_RUINS16A ? 4980 : 5117, true);
+ if (v) v->flags |= OF_TALK, v->event = EV_VEGGIE;
+ break;
+ }
+ case ROOM_RUINS16B: {
+ Obj *s = obj_deco(SPR_O_SWITCH, 8460, 4935, false);
+ if (s) s->flags |= OF_TALK | OF_BACK, s->event = EV_ONE_SWITCH, s->frame = flag(F_ONESWITCH) ? 1 : 0, obj_set_box(s, 0, 0, 20, 30);
+ break;
+ }
+ case ROOM_RUINS16D:
+ item_here(SPR_O_RIBBON, 8260, 5120, ITEM_FADED_RIBBON, F_RIBBON);
+ break;
+ case ROOM_RUINS16E:
+ if (flag(F_NAPSTA) == 1 && !flag(F_NAPSTA_LIE)) {
+ Obj *n = obj_deco(SPR_O_NAPSTABLOOK_GR, 8495, 5117, true);
+ if (n) n->name = ACTOR_NAPSTA, n->flags |= OF_TALK, n->event = EV_NAPSTA_LIE;
+ }
+ break;
+ case ROOM_RUINS17B:
+ if (rotate_fails >= 2 && !flag(F_ROTATE2)) say_on_entry("* (You notice a switch hidden\n behind the pillar.)");
+ break;
+ case ROOM_RUINS19: {
+ Obj *f = obj_npc(ACTOR_FROGGIT, frog_spr, 9400, 3700, DIR_DOWN, EV_FROGGIT);
+ if (f) f->arg = 3, f->flags |= OF_ANIM, f->anim_speed = 20;
+ break;
+ }
+ case ROOM_RUINS20:
+ item_here(SPR_O_GROUNDKNIFE, 9364, 3566, ITEM_TOY_KNIFE, F_TOYKNIFE);
+ break;
+ case ROOM_RUINS21:
+ obj_save(8940, 3120, "* (Seeing such a cute, tidy\n house in the RUINS gives\n you determination.)");
+ obj_sign(9004, 3290, 34, 30, "* (Every time this old tree\n grows any leaves, they fall\n right off.)");
+ if (!flag(F_TORIEL_HOME)) {
+ Obj *t = obj_toriel(8996, 3240, DIR_DOWN);
+ if (t) t->spr[0] = SPR_O_TORIEL_D_PHONE, t->flags &= (uint16_t)~OF_WALKANIM;
+ obj_trigger(8880, 3330, 280, 40, EV_TORIEL_TREE, ACTOR_TRIGGER);
+ }
+ break;
+ }
+}
+
+/* each frame: the rocks on their switches */
+void ruins2_update(void) {
+ if (g_room == ROOM_RUINS9 && !flag(F_RUINS9_ROCK)) {
+ Obj *r = obj_find(ACTOR_ROCK);
+ if (r && r->x >= 5676 && r->x <= 5684) {
+ set_flag(F_RUINS9_ROCK, 1);
+ r->x = 5680;
+ r->flags &= (uint16_t)~OF_SOLID; /* it stays */
+ obj_spikes_set(obj_find(ACTOR_SPIKES), false);
+ }
+ }
+}
+
+/* ---------------------------------------------------------------- the events */
+static int ev_candy(Ev *c) {
+ EV_BEGIN;
+ if (flag(F_CANDY_SPILT)) {
+ NARRATE("* Look at what you've done.");
+ return 1;
+ }
+ if (item_count() >= NUM_ITEMS) {
+ NARRATE("* You tried to take a piece of\n candy, but you didn't have\n any room.");
+ return 1;
+ }
+ set_flag(F_CANDY_TAKEN, flag(F_CANDY_TAKEN) + 1);
+ if (flag(F_CANDY_TAKEN) >= (flag(F_HARDMODE) ? 3 : 4)) {
+ set_flag(F_CANDY_SPILT, 1);
+ if (c->self) c->self->spr[0] = SPR_O_CANDYDISH_BAD;
+ NARRATE("* You took too much too fast.\n* The candy spills onto the\n floor.");
+ return 1;
+ }
+ item_add(ITEM_MONSTER_CANDY);
+ if (flag(F_CANDY_TAKEN) == 1) NARRATE("* You took a piece of candy.\n* (Press [TOOLBOX] to open\n the menu.)");
+ else if (flag(F_CANDY_TAKEN) == 2) NARRATE("* You took more candy.\n* How disgusting...");
+ else if (flag(F_HARDMODE)) NARRATE("* In this hellish world, you\n can only take 3 pieces of\n candy...");
+ else NARRATE("* You take another piece.\n* You feel like the scum of\n the earth...");
+ EV_END;
+}
+
+static const char call_hello[] = "* Ring...|`0* Hello?\n* This is TORIEL.|";
+
+static int ev_call(Ev *c) {
+ EV_BEGIN;
+ if (c->self) c->v[0] = c->self->arg, c->self->kind = OBJ_NONE;
+ WAIT_UNTIL(!world_fading());
+ WAIT(15);
+ switch (c->v[0]) {
+ case CALL_FLAVOR:
+ set_flag(F_FLAVOR_CALL, 1);
+ SAY(FACE_TORIEL, "* Ring...|`0* Hello?\n* This is TORIEL.|* For no reason in\n particular...|* Which do you prefer?|* Cinnamon or butterscotch?@Cinnamon@Bscotch");
+ set_flag(F_FLAVOR, CHOICE() ? 2 : 1);
+ SAY(FACE_TORIEL, "`0* Oh, I see.\n* Thank you very much!");
+ break;
+ case CALL_FLAVOR2:
+ set_flag(F_FLAVOR_CALL, 2);
+ SAYF(FACE_TORIEL, "%s* You do not DISLIKE\n %s, do you?|* I know what your preference\n is, but...|* Would you turn up your nose\n if you found it on your\n plate?|* Right, right, I understand.|* Thank you for being\n patient, by the way.",
+ call_hello, flag(F_FLAVOR) == 2 ? "cinnamon" : "butterscotch");
+ break;
+ case CALL_ALLERGY:
+ set_flag(F_FLAVOR_CALL, 3), set_flag(F_ALLERGY_CALL, 1);
+ SAY(FACE_TORIEL, "* Ring...|`0* Hello?|* You do not have any\n allergies, do you?|`1* Huh? Why am I asking?|`0* No reason...\n* No reason at all.");
+ break;
+ case CALL_ITEMS:
+ set_flag(F_ITEM_CALL, 1);
+ SAY(FACE_TORIEL, "* Ring...|`0* Hello?|* I just realized that it has\n been a while since I have\n cleaned up.|* I was not expecting to have\n company so soon.|* There are probably a lot of\n things lying about here and\n there.|* You can pick them up, but do\n not carry more than you\n need.|* Someday you might see\n something you really like.|* You will want to leave room\n in your pockets for that.");
+ break;
+ }
+ EV_END;
+}
+
+static int ev_rock_talk(Ev *c) {
+ Obj *r = obj_find(ACTOR_ROCK3);
+ EV_BEGIN;
+ if (!r) return 1;
+ switch (flag(F_RUINS11_ROCK)) {
+ case 0:
+ SAY(FACE_NONE, "* WHOA there, pardner!\n* Who said you could push me\n around?|* ...|* Huh? You want me to move?\n* Well, why didn't ya just\n say so?");
+ set_flag(F_RUINS11_ROCK, 1);
+ WALK(obj_get(ACTOR_ROCK3), 6740, 4875, 1);
+ NARRATE("* (The rock moved a little,\n and stopped.)");
+ break;
+ case 1:
+ SAY(FACE_NONE, "* Huh? Not far enough?\n* Alright, alright.");
+ set_flag(F_RUINS11_ROCK, 2);
+ WALK(obj_get(ACTOR_ROCK3), 6740, 4855, 1);
+ break;
+ case 2:
+ NARRATE("* (You tell the rock it's\n going the wrong way.)");
+ SAY(FACE_NONE, "* Oh! Why didn't ya say so,\n pardner?");
+ set_flag(F_RUINS11_ROCK, 3);
+ WALK(obj_get(ACTOR_ROCK3), 6740, 4875, 1);
+ WALK(obj_get(ACTOR_ROCK3), 6780, 4875, 1);
+ obj_spikes_set(obj_find(ACTOR_SPIKES), false);
+ obj_trigger(6830, 4800, 30, 100, EV_ROCK_OFF, ACTOR_TRIGGER);
+ break;
+ case 3:
+ case 5:
+ SAY(FACE_NONE, "* Well, here I am, pardner.");
+ break;
+ case 4:
+ NARRATE("* (You ask the rock to stay\n on the switch.)");
+ SAY(FACE_NONE, "* Huh? You want me to stay\n put?|* Well, alright.\n* It's easier when you just\n ask, you know.");
+ set_flag(F_RUINS11_ROCK, 5);
+ WALK(obj_get(ACTOR_ROCK3), 6780, 4875, 1);
+ obj_spikes_set(obj_find(ACTOR_SPIKES), false);
+ break;
+ }
+ EV_END;
+}
+
+static int ev_rock_off(Ev *c) {
+ EV_BEGIN;
+ if (c->self) c->self->kind = OBJ_NONE;
+ if (flag(F_RUINS11_ROCK) != 3) return 1;
+ set_flag(F_RUINS11_ROCK, 4);
+ WALK(obj_get(ACTOR_ROCK3), 6740, 4875, 1);
+ obj_spikes_set(obj_find(ACTOR_SPIKES), true);
+ NARRATE("* (The rock rolled off the\n switch.)");
+ EV_END;
+}
+
+static int ev_napsta_sleep(Ev *c) {
+ EV_BEGIN;
+ if (flag(F_NAPSTA)) return 1;
+ NARRATE("* (This ghost keeps saying 'z'\n out loud repeatedly,\n pretending to sleep.)|* Move it with force?@Yes@No");
+ if (CHOICE() != 0) {
+ /* he steps back out of its way */
+ PL_WALK(pl.x - 12, pl.y, 2);
+ return 1;
+ }
+ BATTLE(FORM_NAPSTABLOOK);
+ if (!flag(F_NAPSTA)) set_flag(F_NAPSTA, battle_result() == BR_FLED ? 3 : 1);
+ obj_get(ACTOR_NAPSTA)->kind = OBJ_NONE;
+ {
+ Obj *t = obj_find(ACTOR_TRIGGER);
+ if (t) t->kind = OBJ_NONE;
+ }
+ EV_END;
+}
+
+static int ev_napsta_lie(Ev *c) {
+ EV_BEGIN;
+ SAY(FACE_NONE, "* oh...^2 it's you...|* i was just lying here...|* ...^2 i'll get out of your\n way...");
+ for (c->v[0] = 255; c->v[0] > 0; c->v[0] -= 15) {
+ obj_get(ACTOR_NAPSTA)->alpha = (uint8_t)c->v[0];
+ WAIT(1);
+ }
+ obj_get(ACTOR_NAPSTA)->kind = OBJ_NONE;
+ set_flag(F_NAPSTA_LIE, 1);
+ EV_END;
+}
+
+static int ev_web(Ev *c) {
+ EV_BEGIN;
+ c->v[0] = c->self ? c->self->arg : 0;
+ if (c->v[0] == 0) NARRATE("* (There's a note on the web.)\n* \"Spider Donut: 7G\"|* Leave 7G in the web?@Yes@No");
+ else NARRATE("* (There's a note on the web.)\n* \"Spider Cider: 18G\"|* Leave 18G in the web?@Yes@No");
+ if (CHOICE() != 0) return 1;
+ {
+ int cost = c->v[0] ? 18 : 7;
+ if (sv.gold < cost) {
+ NARRATE("* You didn't have enough gold.");
+ return 1;
+ }
+ if (item_count() >= NUM_ITEMS) {
+ NARRATE("* You are carrying too many\n items.");
+ return 1;
+ }
+ sv.gold = (uint16_t)(sv.gold - cost);
+ item_add(c->v[0] ? ITEM_SPIDER_CIDER : ITEM_SPIDER_DONUT);
+ set_flag(c->v[0] ? F_CIDER_BOUGHT : F_DONUT_BOUGHT, 1);
+ }
+ if (c->v[0] == 0) NARRATE("* Some spiders crawled down\n and gave you a donut.");
+ else NARRATE("* Some spiders crawled down\n and gave you a jug.");
+ EV_END;
+}
+
+static int ev_froggit(Ev *c) {
+ EV_BEGIN;
+ c->v[0] = c->self ? c->self->arg : 0;
+ switch (c->v[0]) {
+ case 0:
+ NARRATE("* Ribbit, ribbit.|* (Excuse me, human.)|* (Did you know you can press\n [BACK] to read text faster?)|* (Some say it's rude, but\n the words won't mind.)");
+ break;
+ case 1:
+ NARRATE("* Ribbit, ribbit.|* (Hey, human.)|* (Have you seen the key with\n a 4 on your calculator?)|* (I'm told 4 means \"four\n frogs.\")|* (But I only see three frogs\n in this room...)");
+ break;
+ case 2:
+ if (!flag(F_FROGGIT_YELLOW))
+ NARRATE("* Ribbit, ribbit.|* (When a monster's name is\n #YYELLOW#X, you can SPARE it.)|* (Some think that makes\n things too easy.)|* (Shall I tell everyone to\n stop using yellow names?)@Yes@No");
+ else if (flag(F_FROGGIT_YELLOW) == 1)
+ NARRATE("* Ribbit, ribbit.|* (Since I told everyone not\n to use yellow names, everyone\n threw theirs out.)|* (Shall I ask them to use\n #PPINK#X names instead?)@Yes@No");
+ else
+ NARRATE("* Ribbit, ribbit.|* (Pink names...^2 Or should\n everyone go back to\n #YYELLOW#X?)@Yellow@Pink");
+ if (flag(F_FROGGIT_YELLOW) == 2) set_flag(F_FROGGIT_YELLOW, CHOICE() == 0 ? 0 : 2);
+ else if (CHOICE() == 0) set_flag(F_FROGGIT_YELLOW, flag(F_FROGGIT_YELLOW) + 1);
+ NARRATE("* Ribbit.");
+ break;
+ case 3:
+ NARRATE("* Ribbit, ribbit.|* (I saw #BTORIEL#X come out of\n here just a little while\n ago.)|* (She was carrying some\n groceries.)|* (I didn't ask what they were\n for...)|* (We're all too intimidated\n to talk to her.)");
+ break;
+ }
+ EV_END;
+}
+
+static int ev_item(Ev *c) {
+ EV_BEGIN;
+ if (!c->self) return 1;
+ if (item_count() >= NUM_ITEMS) {
+ NARRATE("* (You're carrying too much.)");
+ return 1;
+ }
+ item_add(c->self->arg);
+ set_flag(c->self->arg2, 1);
+ c->v[0] = c->self->arg;
+ c->self->kind = OBJ_NONE;
+ SAYF(FACE_NONE, "* (You got the %s.)", item_info(c->v[0])->name);
+ EV_END;
+}
+
+static int ev_one_switch(Ev *c) {
+ EV_BEGIN;
+ if (flag(F_ONESWITCH)) {
+ NARRATE("* (The switch is already\n flipped.)");
+ return 1;
+ }
+ set_flag(F_ONESWITCH, 1);
+ if (c->self) c->self->frame = 1;
+ NARRATE("* (You flipped the switch.)\n* (Somewhere, spikes lowered.)");
+ EV_END;
+}
+
+static int ev_veggie(Ev *c) {
+ EV_BEGIN;
+ NARRATE("* (It's a vegetable.)|* (...it looks back at you.)");
+ BATTLE(FORM_VEGETOID);
+ if (c->self) c->self->kind = OBJ_NONE;
+ EV_END;
+}
+
+static int ev_toriel_tree(Ev *c) {
+ Obj *t = obj_find(ACTOR_TORIEL);
+ EV_BEGIN;
+ if (c->self) c->self->kind = OBJ_NONE;
+ if (!t) return 1;
+ SAY(FACE_TORIEL, "`0* Hello?\n* This is TORIEL.|`7* ...!");
+ t = obj_get(ACTOR_TORIEL);
+ t->spr[0] = SPR_TORIEL_D;
+ t->flags |= OF_WALKANIM;
+ WALK(t, 8996, pl.y - 52, 3);
+ SAY(FACE_TORIEL, "`7* How did you get here, my\n child?|`3* Are you hurt?");
+ if (sv.hp >= sv.maxhp) SAY(FACE_TORIEL, "`0* Not a scratch...\n* Impressive!|`1* But still...");
+ else if (sv.hp > 2) SAY(FACE_TORIEL, "`0* There, there, I will heal\n you.");
+ else SAY(FACE_TORIEL, "`5* Who did this to you?\n* You will get an apology.");
+ sv.hp = sv.maxhp;
+ SAY(FACE_TORIEL, "`1* I should not have left you\n alone for so long.|* It was irresponsible to try\n to surprise you like this.|* Err...|`0* Well, I suppose I cannot\n hide it any longer.|`2* Come, small one!");
+ set_flag(F_TORIEL_HOME, 1);
+ WALK(obj_get(ACTOR_TORIEL), 9006, 3070, 3);
+ obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;
+ EV_END;
+}
+
+int ruins2_event(Ev *c) {
+ switch (c->id) {
+ case EV_FALLING: return ev_fall(c);
+ case EV_COLOR_SWITCH: return ev_color_switch(c);
+ case EV_CANDY: return ev_candy(c);
+ case EV_CALL: return ev_call(c);
+ case EV_ROCK_TALK: return ev_rock_talk(c);
+ case EV_ROCK_OFF: return ev_rock_off(c);
+ case EV_NAPSTA_SLEEP: return ev_napsta_sleep(c);
+ case EV_NAPSTA_LIE: return ev_napsta_lie(c);
+ case EV_WEB: return ev_web(c);
+ case EV_FROGGIT: return ev_froggit(c);
+ case EV_ITEM: return ev_item(c);
+ case EV_ONE_SWITCH: return ev_one_switch(c);
+ case EV_VEGGIE: return ev_veggie(c);
+ case EV_TORIEL_TREE: return ev_toriel_tree(c);
+ }
+ return -1;
+}
diff --git a/games/undertale/src/ruins3.c b/games/undertale/src/ruins3.c
new file mode 100644
index 00000000..e2ccb720
--- /dev/null
+++ b/games/undertale/src/ruins3.c
@@ -0,0 +1,319 @@
+/* The end of the Ruins: Toriel's home, the basement where she goes to destroy the exit, her fight, and Flowey
+ * waiting past the door. Texts are the game's (the Undertale Wiki's records of them) where known. */
+#include <stdio.h>
+#include <string.h>
+#include "battle.h"
+#include "event.h"
+#include "events.h"
+#include "game.h"
+#include "items.h"
+#include "menu.h"
+#include "monsters.h"
+#include "ruins.h"
+#include "save.h"
+#include "world.h"
+
+/* ---------------------------------------------------------------- the rooms' things */
+void ruins3_setup(int room, int from) {
+ (void)from;
+ switch (room) {
+ case ROOM_TORHOUSE1:
+ obj_sign(8880, 2740, 24, 22, "* (Inside is an old calendar\n from the beginning of 201X.)");
+ obj_sign(9100, 2728, 44, 24, "* (It's a bookshelf.)\n* (The books are worn out.)");
+ if (flag(F_TORIEL_HOME) && !flag(F_HOME_TOUR)) {
+ obj_toriel(8996, 2800, DIR_DOWN);
+ event_start(EV_HOME_TOUR, NULL);
+ }
+ if (!flag(F_TORIEL_BASEMENT)) obj_trigger(9078, 2734, 12, 28, EV_STAIRS, ACTOR_TRIGGER);
+ break;
+ case ROOM_TORHOUSE2: {
+ bool reading = flag(F_HOME_TOUR) && !flag(F_TORIEL_BASEMENT);
+ Obj *ch = obj_deco(reading ? SPR_O_CHAIRIEL : SPR_O_CHAIREMPTY, 8640, 2723, true);
+ if (ch) ch->name = ACTOR_CHAIR, ch->flags |= OF_TALK, ch->event = EV_TORIEL_CHAIR, obj_set_box(ch, 10, 36, 44, 24);
+ obj_sign(8673, 2690, 68, 66, flag(F_TORIEL_FIGHT) == 2 ? "* (The fire has gone out.)"
+ : "* (The fire isn't burning\n hot...)\n* (Just pleasantly warm.)|* (You could put your hand\n inside.)");
+ obj_sign(8753, 2692, 60, 60, "* (It's a history book.)|* \"Trapped behind the barrier\n and fearful of further human\n attacks, we retreated.\"|* \"Far, far into the earth we\n walked, until we reached the\n cavern's end.\"|* \"This was our new home, which\n we named...\"|* \"Home.\"|* \"As great as our king is, he\n is pretty lousy at names.\"");
+ break;
+ }
+ case ROOM_TORKITCHEN:
+ obj_sign(8560, 2540, 38, 62, "* (For some reason, there is a\n brand-name chocolate bar in\n the fridge.)");
+ obj_sign(8603, 2560, 22, 40, "* (There's a clump of white\n fur stuck in the drain.)");
+ obj_sign(8630, 2580, 22, 22, "* (Inside the cupboard are\n cookie cutters for\n gingerbread monsters.)");
+ obj_sign(8654, 2560, 30, 40, flag(F_BED_SLEPT) ? "* (It's a butterscotch-\n cinnamon pie.)\n* (Its size intimidates you.)"
+ : "* (It's a butterscotch-\n cinnamon pie.)|* (It smells nice, but it's\n too hot to eat.)");
+ obj_sign(8687, 2560, 32, 40, flag(F_TORIEL_FIGHT) == 2 ? "* (No one will use this\n anymore...)"
+ : "* (The stovetop is very\n clean.)\n* (Toriel must use fire magic\n instead.)");
+ break;
+ case ROOM_TORHOUSE3:
+ obj_sign(9404, 2750, 24, 54, "* (You have seen this type of\n plant before but do not know\n its name.)");
+ obj_sign(9492, 2750, 24, 54, "* (You have seen this type of\n plant before but do not know\n its name.)");
+ obj_sign(9746, 2775, 30, 47, "* (Room under renovations.)");
+ obj_sign(9810, 2770, 60, 52, "* (It's you!)");
+ if (flag(F_TORIEL_HOME) && !flag(F_HOME_TOUR)) obj_toriel(9370, 2780, DIR_DOWN);
+ break;
+ case ROOM_ASRIELROOM:
+ {
+ Obj *b = obj_sign(9368, 2522, 52, 70, NULL);
+ if (b) b->event = EV_BED;
+ }
+ obj_sign(9260, 2498, 62, 34, "* (Toys you aren't interested\n in.)|* (An empty photo frame.)");
+ obj_sign(9335, 2498, 32, 48, "* (A box of shoes in many\n different sizes.)");
+ if (flag(F_BED_SLEPT) == 1) {
+ Obj *p = obj_deco(SPR_O_PIESLICE, 9322, 2572, false);
+ if (p) p->flags |= OF_TALK | OF_BACK, p->event = EV_ITEM, p->arg = flag(F_HARDMODE) ? ITEM_SNAIL_PIE : ITEM_BUTTERSCOTCH_PIE,
+ p->arg2 = F_PIE;
+ }
+ break;
+ case ROOM_TORIELROOM:
+ obj_sign(9540, 2520, 74, 92, "* (It's bigger than a\n twin-sized bed.)");
+ obj_sign(9592, 2598, 26, 30, "* (Toriel's small chair.)\n* (Its name is Chairiel.)");
+ obj_sign(9690, 2528, 62, 36, "* (It's Toriel's diary.)|* (You read the passage...)|* \"Why did the skeleton want a\n friend?\"|* \"Because she was feeling\n BONELY...\"");
+ obj_sign(9632, 2478, 58, 54, "* (You peek inside...)\n* (Scandalous!)|* (It's TORIEL's sock drawer.)");
+ break;
+ case ROOM_BASEMENT1:
+ if (flag(F_TORIEL_BASEMENT) && !flag(F_TORIEL_FIGHT)) {
+ static const int16_t tx[2] = {9030, 9560};
+ int k = flag(F_BASEMENT_TALK);
+ if (k < 2) {
+ obj_toriel(tx[k], 2300, DIR_RIGHT);
+ obj_trigger(tx[k] - 70, 2300, 16, 80, EV_BASEMENT_TALK, ACTOR_TRIGGER);
+ }
+ }
+ break;
+ case ROOM_BASEMENT2:
+ if (flag(F_TORIEL_BASEMENT) && !flag(F_TORIEL_FIGHT)) {
+ if (flag(F_BASEMENT_TALK) < 3) {
+ obj_toriel(10004, 2110, DIR_UP);
+ obj_trigger(9960, 2170, 140, 14, EV_BASEMENT_TALK, ACTOR_TRIGGER);
+ } else {
+ obj_toriel(10004, 1984, DIR_DOWN);
+ obj_trigger(9960, 2060, 140, 14, EV_TORIEL_DOOR, ACTOR_TRIGGER2);
+ }
+ }
+ break;
+ case ROOM_RUINSEXIT:
+ if (!flag(F_FLOWEY_END)) {
+ static const uint16_t s[4] = {SPR_FLOWEY};
+ Obj *f = obj_npc(ACTOR_FLOWEY, s, 10008, 205, DIR_DOWN, 0);
+ if (f) f->flags = OF_HIDDEN, obj_set_box(f, 4, 16, 17, 8);
+ obj_trigger(9980, 250, 80, 20, EV_FLOWEY_END, ACTOR_TRIGGER);
+ }
+ obj_trigger(9990, 70, 60, 14, EV_RUINS_DOOR, ACTOR_TRIGGER2);
+ break;
+ }
+}
+
+/* ---------------------------------------------------------------- the events */
+static int ev_home_tour(Ev *c) {
+ EV_BEGIN;
+ WAIT_UNTIL(!world_fading());
+ SAY(FACE_TORIEL, "`0* Do you smell that?|`2* Surprise!|* It is a butterscotch-\n cinnamon pie.|`0* I thought we might\n celebrate your arrival.|* I want you to have a nice\n time living here.|* So I will hold off on snail\n pie for tonight.|`2* Here, I have another\n surprise for you.");
+ WALK(obj_get(ACTOR_TORIEL), 8996, 2840, 3);
+ WALK(obj_get(ACTOR_TORIEL), 9200, 2840, 3);
+ obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;
+ PL_WALK(pl.x + 40, pl.y, 3);
+ FADE_TO(ROOM_TORHOUSE3, 9196, 2836, DIR_RIGHT);
+ PL_WALK(9330, 2836, 3);
+ pl.dir = DIR_UP;
+ SAY(FACE_TORIEL, "`2* A room of your own.|* I hope you like it!");
+ WAIT(20);
+ SAY(FACE_TORIEL, "`7* ...!|`3* Is something burning...?|`0* Um, make yourself at home!");
+ WALK(obj_get(ACTOR_TORIEL), 9370, 2840, 4);
+ WALK(obj_get(ACTOR_TORIEL), 9180, 2840, 5);
+ obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;
+ set_flag(F_HOME_TOUR, 1);
+ EV_END;
+}
+
+static const char *const chair_opts[2] = {"When can I go home?", "How to exit the RUINS"};
+
+static int ev_toriel_chair(Ev *c) {
+ EV_BEGIN;
+ if (!flag(F_HOME_TOUR) || flag(F_TORIEL_BASEMENT)) {
+ NARRATE("* (Seems like the right size\n for Toriel.)");
+ return 1;
+ }
+ SAY(FACE_TORIEL, "`0* What is it?");
+ CHOOSE(chair_opts, 2);
+ if (CHOSEN() < 0) return 1;
+ if (CHOSEN() == 0) {
+ SAY(FACE_TORIEL, "`3* What?|`1* This...^2 this IS your home\n now.|`0* Um...^2 would you like to hear\n about this book I am reading?|* It is called \"72 Uses for\n Snails.\"|* How about it?@Yes@No");
+ if (CHOICE() == 0) SAY(FACE_TORIEL, "`2* Here is an exciting snail\n fact.|`0* Did you know that snails\n have a chainsaw-like tongue\n called a radula?");
+ else SAY(FACE_TORIEL, "`0* Oh...^2 Alright.");
+ return 1;
+ }
+ SAY(FACE_TORIEL, "`1* ...|* Um...^2 I have to do\n something.|* Stay here.");
+ set_flag(F_TORIEL_BASEMENT, 1);
+ if (c->self) c->self->spr[0] = SPR_O_CHAIRIELGETUP;
+ for (c->v[0] = 0; c->v[0] < 6; c->v[0]++) {
+ obj_get(ACTOR_CHAIR)->frame = (uint8_t)c->v[0];
+ WAIT(4);
+ }
+ obj_get(ACTOR_CHAIR)->frame = 0;
+ if (c->self) c->self->spr[0] = SPR_O_CHAIREMPTY;
+ {
+ Obj *t = obj_toriel(8660, 2760, DIR_RIGHT);
+ if (t) t->flags &= (uint16_t)~OF_SOLID;
+ }
+ WALK(obj_get(ACTOR_TORIEL), 8800, 2780, 4);
+ WALK(obj_get(ACTOR_TORIEL), 8860, 2780, 4);
+ obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;
+ EV_END;
+}
+
+static int ev_stairs(Ev *c) {
+ EV_BEGIN;
+ if (flag(F_TORIEL_BASEMENT)) {
+ if (c->self) c->self->kind = OBJ_NONE;
+ return 1;
+ }
+ if (!flag(F_HOME_TOUR)) return 1;
+ SAY(FACE_TORIEL, "`1* Oh, my child...|`0* There is nothing down there\n for you.|* Come, let us go upstairs.");
+ PL_WALK(pl.x + 14, pl.y + 14, 2);
+ EV_END;
+}
+
+static int ev_bed(Ev *c) {
+ EV_BEGIN;
+ NARRATE("* (You lie down on the bed.)");
+ if (!flag(F_BED_SLEPT) && !flag(F_TORIEL_BASEMENT)) set_flag(F_BED_SLEPT, 1);
+ sv.hp = sv.maxhp;
+ world_fade_hold(g_room, 9376, 2590, DIR_DOWN, 90);
+ WAIT_UNTIL(!world_fading());
+ EV_END;
+}
+
+static int ev_basement_talk(Ev *c) {
+ EV_BEGIN;
+ if (c->self) c->self->kind = OBJ_NONE;
+ obj_get(ACTOR_TORIEL)->dir = DIR_LEFT;
+ switch (flag(F_BASEMENT_TALK)) {
+ case 0:
+ SAY(FACE_TORIEL, "`0* You wish to know how to\n return \"home,\" do you not?|* Ahead of us lies the end of\n the RUINS.|* A one-way exit to the rest\n of the underground.|`6* I am going to destroy it.|* No one will ever be able to\n leave again.|`0* Now be a good child and go\n upstairs.");
+ break;
+ case 1:
+ SAY(FACE_TORIEL, "`6* Every human that falls down\n here meets the same fate.|* I have seen it again and\n again.|* They come.|* They leave.|* They die.|* You naive child...|* If you leave the RUINS...|* They...^2 #RASGORE#X...^2 will kill\n you.|* I am only protecting you,\n do you understand?|* ...^2 Go to your room.");
+ break;
+ default:
+ obj_get(ACTOR_TORIEL)->dir = DIR_DOWN;
+ SAY(FACE_TORIEL, "`6* Do not try to stop me.|* This is your final warning.");
+ break;
+ }
+ set_flag(F_BASEMENT_TALK, flag(F_BASEMENT_TALK) + 1);
+ if (g_room == ROOM_BASEMENT1 && flag(F_BASEMENT_TALK) == 1) {
+ /* on ahead, to wait further down */
+ obj_get(ACTOR_TORIEL)->dir = DIR_RIGHT;
+ WALK(obj_get(ACTOR_TORIEL), 9560, 2300, 4);
+ obj_get(ACTOR_TORIEL)->dir = DIR_RIGHT;
+ obj_trigger(9490, 2300, 16, 80, EV_BASEMENT_TALK, ACTOR_TRIGGER);
+ return 1;
+ }
+ if (g_room == ROOM_BASEMENT1) {
+ WALK(obj_get(ACTOR_TORIEL), 10120, 2300, 5);
+ } else {
+ WALK(obj_get(ACTOR_TORIEL), 10004, 1984, 4);
+ obj_get(ACTOR_TORIEL)->dir = DIR_DOWN;
+ obj_trigger(9960, 2060, 140, 14, EV_TORIEL_DOOR, ACTOR_TRIGGER2);
+ return 1;
+ }
+ obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;
+ EV_END;
+}
+
+static int ev_toriel_door(Ev *c) {
+ EV_BEGIN;
+ if (c->self) c->self->kind = OBJ_NONE;
+ SAY(FACE_TORIEL, "`6* You want to leave so\n badly?|* Hmph.|* You are just like the\n others.|* There is only one solution\n to this.|* Prove yourself...|* Prove to me you are strong\n enough to survive.");
+ BATTLE(FORM_TORIEL);
+ if (flag(F_TORIEL_FIGHT) != 1) {
+ obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;
+ if (!flag(F_TORIEL_FIGHT)) set_flag(F_TORIEL_FIGHT, battle_result() == BR_FLED ? 1 : 2);
+ return 1;
+ }
+ SAY(FACE_TORIEL, "`1* ...|* I understand.|* You would just be unhappy\n trapped down here.|* The RUINS are very small\n once you get used to them.|* It would not be right for\n you to grow up in a place\n like this.|* My expectations...|* My loneliness...|* My fear...|`0* For you, my child...|* I will put them aside.");
+ /* she holds Frisk */
+ PL_WALK(10010, 2040, 2);
+ pl.hidden = true;
+ obj_get(ACTOR_TORIEL)->spr[0] = SPR_O_TORIEL_HUG, obj_get(ACTOR_TORIEL)->dir = DIR_DOWN;
+ obj_get(ACTOR_TORIEL)->y = 2000;
+ WAIT(70);
+ pl.hidden = false;
+ obj_get(ACTOR_TORIEL)->spr[0] = SPR_TORIEL_D, obj_get(ACTOR_TORIEL)->y = 1984;
+ SAY(FACE_TORIEL, "`1* If you truly wish to leave\n the RUINS...|* I will not stop you.|* However, when you leave...|* Please do not come back.|`0* I hope you understand.");
+ WAIT(20);
+ SAY(FACE_TORIEL, "`0* Goodbye, my child.");
+ obj_get(ACTOR_TORIEL)->flags &= (uint16_t)~OF_SOLID;
+ WALK(obj_get(ACTOR_TORIEL), 10040, 2050, 2);
+ WALK(obj_get(ACTOR_TORIEL), 10040, 2240, 2);
+ obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;
+ EV_END;
+}
+
+static const char flowey_spared[] =
+ "`1* Clever.^2 Verrrryy clever.|* You think you're really\n smart, don't you?|"
+ "`0* In this world, it's KILL\n or BE killed.|* So you were able to play by\n your own rules.|"
+ "* You spared the life of a\n single person.|`2* Hee hee hee...|* I bet you feel really\n great.|"
+ "`1* You didn't kill anybody\n this time.|* But what will you do if you\n meet a relentless killer?|"
+ "`3* You'll die and you'll die\n and you'll die.|* Until you tire of trying.|* What will you do then?|"
+ "* Will you kill out of\n frustration?|* Or will you give up\n entirely, and let ME take\n your place?|";
+static const char flowey_killed[] =
+ "`1* Clever.^2 Verrrryy clever.|* You think you're really\n smart, don't you?|"
+ "`0* In this world, it's KILL\n or BE killed.|`2* So you did kill her.|* Hee hee hee...|"
+ "`3* You really are a quick\n learner.|";
+static const char flowey_others[] =
+ "`1* Clever.^2 Verrrryy clever.|* You think you're really\n smart, don't you?|"
+ "`0* In this world, it's KILL\n or BE killed.|* You spared her...|"
+ "`2* ...but you killed everyone\n else on the way.|* Hee hee hee...|";
+static const char flowey_last[] =
+ "`8* I am the prince of this\n world's future.|`1* Don't worry, my little\n monkey...|"
+ "* I won't interfere with your\n little quest.|`2* Have fun?^4 Have fun...|`8* Ha ha ha...";
+
+static int ev_flowey_end(Ev *c) {
+ EV_BEGIN;
+ if (c->self) c->self->kind = OBJ_NONE;
+ {
+ Obj *f = obj_get(ACTOR_FLOWEY);
+ f->flags &= (uint16_t)~OF_HIDDEN, f->spr[0] = SPR_O_FLOWEYGROW, f->frame = 0;
+ }
+ for (c->v[0] = 0; c->v[0] < 9; c->v[0]++) {
+ obj_get(ACTOR_FLOWEY)->frame = (uint8_t)c->v[0];
+ WAIT(3);
+ }
+ obj_get(ACTOR_FLOWEY)->spr[0] = SPR_FLOWEY, obj_get(ACTOR_FLOWEY)->frame = 0;
+ if (flag(F_TORIEL_FIGHT) == 2) SAY(FACE_FLOWEY, flowey_killed);
+ else if (sv.kills) SAY(FACE_FLOWEY, flowey_others);
+ else SAY(FACE_FLOWEY, flowey_spared);
+ SAY(FACE_FLOWEY, flowey_last);
+ obj_get(ACTOR_FLOWEY)->spr[0] = SPR_O_FLOWEYSINK;
+ for (c->v[0] = 0; c->v[0] < 6; c->v[0]++) {
+ obj_get(ACTOR_FLOWEY)->frame = (uint8_t)c->v[0];
+ WAIT(3);
+ }
+ obj_get(ACTOR_FLOWEY)->kind = OBJ_NONE;
+ set_flag(F_FLOWEY_END, 1);
+ EV_END;
+}
+
+/* the door out of the Ruins: the rest of the underground is still to come */
+static int ev_ruins_door(Ev *c) {
+ EV_BEGIN;
+ set_flag(F_RUINS_EXIT, 1);
+ sv.room = (int16_t)g_room, sv.x = pl.x, sv.y = (int16_t)(pl.y + 30);
+ save_write_auto();
+ menu_end_open();
+ EV_END;
+}
+
+int ruins3_event(Ev *c) {
+ switch (c->id) {
+ case EV_HOME_TOUR: return ev_home_tour(c);
+ case EV_TORIEL_CHAIR: return ev_toriel_chair(c);
+ case EV_STAIRS: return ev_stairs(c);
+ case EV_BED: return ev_bed(c);
+ case EV_BASEMENT_TALK: return ev_basement_talk(c);
+ case EV_TORIEL_DOOR: return ev_toriel_door(c);
+ case EV_FLOWEY_END: return ev_flowey_end(c);
+ case EV_RUINS_DOOR: return ev_ruins_door(c);
+ }
+ return -1;
+}
diff --git a/games/undertale/src/save.c b/games/undertale/src/save.c
index 46a9d62d..d6396bd4 100644
--- a/games/undertale/src/save.c
+++ b/games/undertale/src/save.c
@@ -130,6 +130,7 @@ static bool read_file(const char *name, Save *s) {
}
bool save_write(void) { return write_file(SAVE_NAME, &sv); }
+bool save_write_auto(void) { return write_file(SAVE_NAME, &sv); }
bool save_exists(void) {
Save s;
return read_file(SAVE_NAME, &s);
diff --git a/games/undertale/src/save.h b/games/undertale/src/save.h
index fc9b6aec..d40fc1cd 100644
--- a/games/undertale/src/save.h
+++ b/games/undertale/src/save.h
@@ -5,6 +5,7 @@
#include "game.h"
void save_restore_copy(void);
bool save_write(void);
+bool save_write_auto(void); /* the game's own SAVE at certain moments (sv's room and place set) */
bool save_exists(void);
bool save_load(void);
bool save_peek(Save *s); /* the SAVE's facts, without loading it */
diff --git a/games/undertale/src/text.c b/games/undertale/src/text.c
index 1117eca6..d636eea4 100644
--- a/games/undertale/src/text.c
+++ b/games/undertale/src/text.c
@@ -257,8 +257,8 @@ void text_set_top(int top) { box_top = top; }
void text_open(int face, const char *s) {
box_face = face;
- int tx = face ? 76 : 22;
- wrap_width = face ? 300 - tx - 6 : 300 - tx - 8;
+ int tx = face ? 68 : 22;
+ wrap_width = face ? 301 - tx : 300 - tx - 8;
box_at_top = box_top >= 0 ? box_top : (pl.y + 15 - cam_y > 130);
writer_start(&box, s, tx, (box_at_top ? 5 : 160) + 11, FONT_MAIN);
box_open = true;
@@ -272,11 +272,36 @@ void text_openf(int face, const char *fmt, ...) {
text_open(face, fmt_buf);
}
+static const char *const *menu_opts;
+static int menu_n, menu_sel, menu_cols; /* long options: one a row */
+void text_open_menu(const char *const *opts, int n) {
+ menu_opts = opts, menu_n = n, menu_sel = 0, menu_cols = 2;
+ for (int i = 0; i < n; i++)
+ if (strlen(opts[i]) > 15) menu_cols = 1;
+ box_face = FACE_NONE;
+ box_at_top = box_top >= 0 ? box_top : (pl.y + 15 - cam_y > 130);
+ box_open = true;
+ box.finished = true;
+}
+
bool text_active(void) { return box_open; }
int text_choice(void) { return last_choice; }
+int text_menu_sel(void) { return box_open && menu_opts ? menu_sel : box_open && box.choices && box.done ? 100 + box.choice : -1; }
void text_update(uint32_t pressed) {
if (!box_open) return;
+ if (menu_opts) {
+ int k = menu_cols;
+ if (pressed & K_UP && menu_sel >= k) menu_sel -= k;
+ if (pressed & K_DOWN && menu_sel + k < menu_n) menu_sel += k;
+ if (k == 2 && pressed & K_LEFT && menu_sel % 2) menu_sel--;
+ if (k == 2 && pressed & K_RIGHT && !(menu_sel % 2) && menu_sel + 1 < menu_n) menu_sel++;
+ if (pressed & (K_Z | K_X)) {
+ last_choice = pressed & K_Z ? menu_sel : -1;
+ menu_opts = NULL, box_open = false;
+ }
+ return;
+ }
int ch = box.choice;
bool had = box.choices && box.done;
if (!writer_update(&box, pressed)) {
@@ -294,8 +319,16 @@ void text_draw(void) {
int e = box.face_expr < faces[box_face].n ? box.face_expr : 0;
const Expr *x = &faces[box_face].e[e];
int fr = writer_talking(&box) ? (box.shown / 2) & 1 : 0;
- if (box_face == FACE_TORIEL) gfx_sprite(SPR_FACE_TORIELBODY, 0, 26, y + 13 + 32, 0, 255);
- gfx_sprite(x->spr, fr, 26 + x->x, y + 13 + x->y, 0, 255);
+ if (box_face == FACE_TORIEL) gfx_sprite(SPR_FACE_TORIELBODY, 0, 22, y + 13 + 32, 0, 255);
+ gfx_sprite(x->spr, fr, 22 + x->x, y + 13 + x->y, 0, 255);
+ }
+ if (menu_opts) {
+ for (int i = 0; i < menu_n; i++) {
+ int x = 46 + (i % menu_cols) * 136, ty = y + 12 + (i / menu_cols) * 18;
+ gfx_text(FONT_MAIN, x, ty, menu_opts[i], C_WHITE, 255);
+ if (i == menu_sel) gfx_sprite(SPR_HEART, 0, x - 12, ty + 6, 0, 255);
+ }
+ return;
}
writer_draw(&box, C_WHITE);
}
diff --git a/games/undertale/src/text.h b/games/undertale/src/text.h
index 6a1cf139..a566b0d7 100644
--- a/games/undertale/src/text.h
+++ b/games/undertale/src/text.h
@@ -50,7 +50,9 @@ void text_openf(int face, const char *fmt, ...);
bool text_active(void);
void text_update(uint32_t pressed);
void text_draw(void);
-int text_choice(void); /* 0 or 1: the last choice made */
-void text_set_top(int top); /* -1: by where Frisk is (the game's way), 0 bottom, 1 top */
+int text_choice(void); /* 0 or 1: the last choice made (a list's: its index, -1 Back) */
+void text_open_menu(const char *const *opts, int n); /* a list of options in the box */
+void text_set_top(int top);
+int text_menu_sel(void); /* (the tests) a list's selection, 100 + a page's choice, -1 neither open */ /* -1: by where Frisk is (the game's way), 0 bottom, 1 top */
extern char g_name[8]; /* the fallen human's name */
#endif
diff --git a/games/undertale/src/toriel.c b/games/undertale/src/toriel.c
index 932acdd1..79ca143f 100644
--- a/games/undertale/src/toriel.c
+++ b/games/undertale/src/toriel.c
@@ -236,6 +236,12 @@ static void tor_falter(int t) {
}
void toriel_attack(int atk, int t) {
+ /* a SOUL down to 2 HP: she stops at once */
+ if (atk != ATK_TOR_FALTER && sv.hp <= 2) {
+ bullets_clear();
+ bt.atk_t = bt.atk_len;
+ return;
+ }
switch (atk) {
case ATK_TOR_HANDS: tor_hands(t); break;
case ATK_TOR_WAVES: tor_waves(t); break;
diff --git a/games/undertale/src/world.c b/games/undertale/src/world.c
index 3edcf3d9..fa2a7d98 100644
--- a/games/undertale/src/world.c
+++ b/games/undertale/src/world.c
@@ -6,8 +6,10 @@
#include "res.h"
#include "text.h"
#include "world.h"
+#include "events.h"
void pl_walk_step(void); /* event.c */
+void room_update(void); /* rooms.c */
Obj objs[MAX_OBJS];
Player pl;
@@ -94,6 +96,13 @@ Obj *obj_find(int name) {
if (objs[i].kind != OBJ_NONE && objs[i].name == name) return &objs[i];
return NULL;
}
+Obj *obj_get(int name) {
+ static Obj spare;
+ Obj *o = obj_find(name);
+ if (o) return o;
+ memset(&spare, 0, sizeof spare);
+ return &spare;
+}
void obj_clear_all(void) { memset(objs, 0, sizeof objs); }
void world_camera(void) {
@@ -117,6 +126,17 @@ void world_enter(int r, int x, int y, int dir) {
obj_clear_all();
ndoors = room_doors(r, doors, 16);
cam_locked = false;
+ /* a door's spot a little off the floor: the nearest that isn't */
+ if (!player_free(pl.x, pl.y))
+ for (int d = 1; d <= 24; d++) {
+ static const int8_t dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
+ int k;
+ for (k = 0; k < 4 && !player_free(pl.x + dx[k] * d, pl.y + dy[k] * d); k++) {}
+ if (k < 4) {
+ pl.x = (int16_t)(pl.x + dx[k] * d), pl.y = (int16_t)(pl.y + dy[k] * d);
+ break;
+ }
+ }
room_setup(r, from);
world_camera();
}
@@ -125,19 +145,36 @@ void world_enter(int r, int x, int y, int dir) {
static struct {
int room, x, y, dir;
int phase, t; /* 1: going black, 2: coming back */
+ int hold; /* frames it stays black (Frisk sleeps) */
+ bool walked; /* Frisk walked out: what was happening in the room stops */
} fade;
#define FADE_FRAMES 4
void world_fade_to(int r, int x, int y, int dir) {
fade.room = r, fade.x = x, fade.y = y, fade.dir = dir;
- fade.phase = 1, fade.t = 0;
+ fade.phase = 1, fade.t = 0, fade.walked = false, fade.hold = 0;
+}
+void world_fade_hold(int r, int x, int y, int dir, int hold) {
+ world_fade_to(r, x, y, dir);
+ fade.hold = hold;
}
bool world_fading(void) { return fade.phase != 0; }
static void fade_step(void) {
if (fade.phase == 1) {
+ if (fade.t >= FADE_FRAMES) { /* in the new room, still black */
+ g_fade = 255;
+ if (fade.hold > 0) fade.hold--;
+ else fade.phase = 2, fade.t = 0;
+ return;
+ }
if (++fade.t >= FADE_FRAMES) {
+ if (fade.walked) event_cancel();
world_enter(fade.room, fade.x, fade.y, fade.dir);
+ if (fade.hold > 0) {
+ g_fade = 255;
+ return;
+ }
fade.phase = 2, fade.t = 0;
}
g_fade = (uint8_t)(255 * fade.t / FADE_FRAMES);
@@ -165,9 +202,31 @@ static void face_from_keys(uint32_t keys, uint32_t pressed) {
}
}
+/* walking into a rock pushes it, a pixel a frame, if there's floor for it (a rock with an event talks back
+ * instead) */
+static uint32_t pushed_at;
+static bool push_rock(int sx, int sy) {
+ int fx = pl.x + PBX + sx, fy = pl.y + PBY + sy;
+ for (int i = 0; i < MAX_OBJS; i++) {
+ Obj *o = &objs[i];
+ if (o->kind != OBJ_ROCK || !(o->flags & OF_SOLID)) continue;
+ if (!boxes_meet(fx, fy, PBW, PBH, o->x + o->bx, o->y + o->by, o->bw, o->bh)) continue;
+ if (o->event) {
+ if (!event_running()) event_start(o->event, o);
+ return false;
+ }
+ if (pushed_at == g_frame || o->walking) return false;
+ if (!world_walkable(o->x + o->bx + sx, o->y + o->by + sy, o->bw, o->bh, i)) return false;
+ pushed_at = g_frame;
+ o->x = (int16_t)(o->x + sx), o->y = (int16_t)(o->y + sy);
+ return player_free(pl.x + sx, pl.y + sy);
+ }
+ return false;
+}
+
/* one pixel along an axis, sliding past a corner (diagonal walls are steps of cells) */
static bool step(int sx, int sy, bool slide) {
- if (player_free(pl.x + sx, pl.y + sy)) {
+ if (player_free(pl.x + sx, pl.y + sy) || push_rock(sx, sy)) {
pl.x = (int16_t)(pl.x + sx), pl.y = (int16_t)(pl.y + sy);
return true;
}
@@ -270,7 +329,7 @@ void world_update(uint32_t keys, uint32_t pressed) {
fade_step();
if (fade.phase == 1) return;
objs_update();
- bool busy = event_running() || text_active() || fade.phase;
+ bool busy = event_blocking() || text_active() || fade.phase;
if (!busy && !pl.frozen) {
player_move(keys, pressed);
/* out of the room's rectangle: into the room that holds his feet */
@@ -278,18 +337,23 @@ void world_update(uint32_t keys, uint32_t pressed) {
int r = room_at(fx, fy);
if (r >= 0 && r != g_room) {
world_fade_to(r, pl.x, pl.y, pl.dir);
+ fade.walked = true;
return;
}
/* a door */
for (int i = 0; i < ndoors; i++)
if (boxes_meet(pl.x + PBX, pl.y + PBY, PBW, PBH, doors[i].x, doors[i].y, doors[i].w, doors[i].h)) {
world_fade_to(doors[i].room, doors[i].tx, doors[i].ty, doors[i].dir);
+ fade.walked = true;
return;
}
- if (pressed & K_Z) interact();
- else touches();
- if (!event_running() && (pressed & K_C)) game_open_menu();
- if (!event_running()) encounter_step();
+ room_update();
+ if (!event_running()) {
+ if (pressed & K_Z) interact();
+ else touches();
+ if (!event_running() && (pressed & K_C)) game_open_menu();
+ if (!event_running()) encounter_step();
+ }
} else {
pl_walk_step();
}
@@ -304,6 +368,87 @@ typedef struct {
static uint16_t obj_sprite(const Obj *o) { return o->spr[o->spr[o->dir] ? o->dir : 0]; }
+/* ---------------------------------------------------------------- the room's things */
+Obj *obj_npc(int name, const uint16_t spr[4], int x, int y, int dir, int event) {
+ Obj *o = obj_new(OBJ_NPC, x, y);
+ if (!o) return NULL;
+ for (int i = 0; i < 4; i++) o->spr[i] = spr[i];
+ Frame f;
+ frame_get(spr[0], 0, &f);
+ o->name = (uint8_t)name, o->dir = (uint8_t)dir, o->event = (uint16_t)event;
+ o->bx = (int16_t)(f.w / 5), o->bw = (int16_t)(f.w - 2 * (f.w / 5)), o->bh = (int16_t)(f.h / 4 < 8 ? 8 : f.h / 4);
+ o->by = (int16_t)(f.h - o->bh);
+ o->flags = OF_SOLID | (event ? OF_TALK : 0) | OF_WALKANIM;
+ return o;
+}
+Obj *obj_toriel(int x, int y, int dir) {
+ static const uint16_t s[4] = {SPR_TORIEL_D, SPR_TORIEL_U, SPR_TORIEL_L, SPR_TORIEL_R};
+ Obj *o = obj_npc(ACTOR_TORIEL, s, x, y, dir, 0);
+ if (o) obj_set_box(o, 6, 44, 20, 12), o->anim_speed = 6;
+ return o;
+}
+Obj *obj_sign(int x, int y, int w, int h, const char *text) {
+ Obj *o = obj_new(OBJ_SIGN, x, y);
+ if (!o) return NULL;
+ o->bw = (int16_t)w, o->bh = (int16_t)h, o->flags = OF_TALK, o->event = EV_SIGN, o->text = text;
+ return o;
+}
+Obj *obj_save(int x, int y, const char *text) {
+ Obj *o = obj_new(OBJ_SAVE, x, y);
+ if (!o) return NULL;
+ o->spr[0] = SPR_SAVEPOINT, o->flags = OF_TALK | OF_SOLID | OF_ANIM, o->anim_speed = 6;
+ o->bx = 2, o->by = 4, o->bw = 16, o->bh = 14;
+ o->event = EV_SAVE, o->text = text;
+ return o;
+}
+Obj *obj_deco(uint16_t spr, int x, int y, bool solid) {
+ Obj *o = obj_new(OBJ_DECO, x, y);
+ if (!o) return NULL;
+ Frame f;
+ frame_get(spr, 0, &f);
+ o->spr[0] = spr;
+ o->bx = 0, o->bw = (int16_t)f.w, o->bh = (int16_t)(f.h < 10 ? f.h : 10), o->by = (int16_t)(f.h - o->bh);
+ if (solid) o->flags |= OF_SOLID;
+ return o;
+}
+Obj *obj_trigger(int x, int y, int w, int h, int event, int name) {
+ Obj *o = obj_new(OBJ_TRIGGER, x, y);
+ if (!o) return NULL;
+ o->bw = (int16_t)w, o->bh = (int16_t)h, o->flags = OF_TOUCH, o->event = (uint16_t)event, o->name = (uint8_t)name;
+ return o;
+}
+Obj *obj_rock(int x, int y, int name, int event) {
+ Obj *o = obj_new(OBJ_ROCK, x, y);
+ if (!o) return NULL;
+ o->spr[0] = SPR_O_ROCK, o->name = (uint8_t)name, o->event = (uint16_t)event;
+ o->flags = OF_SOLID | (event ? OF_TALK : 0);
+ obj_set_box(o, 1, 8, 18, 12);
+ return o;
+}
+void obj_spikes_set(Obj *o, bool raised) {
+ if (!o) return;
+ o->frame = raised ? 0 : 1;
+ if (raised) o->flags |= OF_SOLID;
+ else o->flags &= (uint16_t)~OF_SOLID;
+}
+Obj *obj_spikes(int x, int y, int cols, int rows, bool raised, int name) {
+ Obj *o = obj_new(OBJ_SPIKES, x, y);
+ if (!o) return NULL;
+ o->spr[0] = SPR_O_SPIKETILE, o->arg = (int16_t)cols, o->arg2 = (int16_t)rows, o->name = (uint8_t)name;
+ o->bw = (int16_t)(cols * 20), o->bh = (int16_t)(rows * 20);
+ o->frame = raised ? 0 : 1;
+ o->flags = (raised ? OF_SOLID : 0) | OF_BACK;
+ return o;
+}
+void obj_set_box(Obj *o, int bx, int by, int bw, int bh) {
+ o->bx = (int16_t)bx, o->by = (int16_t)by, o->bw = (int16_t)bw, o->bh = (int16_t)bh;
+}
+bool near_frisk(const Obj *o, int d) {
+ int ox = o->x + o->bx + o->bw / 2, oy = o->y + o->by + o->bh / 2;
+ int px = pl.x + PBX + PBW / 2, py = pl.y + PBY + PBH / 2;
+ return abs_i(ox - px) <= d && abs_i(oy - py) <= d;
+}
+
void world_draw(void) {
gfx_tiles(cam_x, cam_y);
/* the room's objects and Frisk, the lower ones in front */
@@ -324,11 +469,17 @@ void world_draw(void) {
order[j] = order[j - 1], order[j - 1] = t;
}
static const uint16_t frisk[4] = {SPR_FRISK_D, SPR_FRISK_U, SPR_FRISK_L, SPR_FRISK_R};
+ if (g_exclaim) gfx_sprite(SPR_O_EXC, 0, pl.x - cam_x, pl.y - 12 - cam_y, 0, 255);
for (int i = 0; i < n; i++) {
if (order[i].who < 0) {
gfx_sprite(frisk[pl.dir], pl.frame, pl.x - cam_x, pl.y - cam_y, 0, 255);
} else {
const Obj *o = &objs[order[i].who];
+ if (o->kind == OBJ_SPIKES) {
+ for (int r = 0; r < o->arg2; r++)
+ for (int k = 0; k < o->arg; k++) gfx_sprite(o->spr[0], o->frame, o->x + k * 20 - cam_x, o->y + r * 20 - cam_y, 0, 255);
+ continue;
+ }
gfx_sprite(obj_sprite(o), o->frame, o->x - cam_x, o->y - cam_y, 0, o->alpha);
}
}
diff --git a/games/undertale/src/world.h b/games/undertale/src/world.h
index c8a5f137..150a7314 100644
--- a/games/undertale/src/world.h
+++ b/games/undertale/src/world.h
@@ -42,6 +42,7 @@ typedef struct {
uint8_t alpha;
uint8_t name; /* an ACTOR_* (scripts find it by it) */
int16_t fx, fy; /* fractions (1/16 pixel) for slow walks */
+ const char *text; /* what a sign or a plain thing says */
} Obj;
extern Obj objs[MAX_OBJS];
@@ -66,9 +67,23 @@ bool world_walkable(int x, int y, int w, int h, int ignore); /* a box on the m
void world_camera(void); /* follows Frisk, inside the room */
Obj *obj_new(int kind, int x, int y);
Obj *obj_find(int name);
+Obj *obj_get(int name); /* obj_find, or a spare object when there is none (events can't crash on it) */
void obj_clear_all(void);
+/* the room's things, made by rooms.c */
+Obj *obj_npc(int name, const uint16_t spr[4], int x, int y, int dir, int event);
+Obj *obj_toriel(int x, int y, int dir);
+Obj *obj_sign(int x, int y, int w, int h, const char *text);
+Obj *obj_save(int x, int y, const char *text);
+Obj *obj_deco(uint16_t spr, int x, int y, bool solid);
+Obj *obj_trigger(int x, int y, int w, int h, int event, int name);
+Obj *obj_spikes(int x, int y, int cols, int rows, bool raised, int name);
+void obj_spikes_set(Obj *o, bool raised);
+Obj *obj_rock(int x, int y, int name, int event); /* pushed by walking into it; with an event, it talks */
+void obj_set_box(Obj *o, int bx, int by, int bw, int bh);
+bool near_frisk(const Obj *o, int d); /* within d pixels (their feet) */
/* the room fades out, then in: room changes in the middle */
void world_fade_to(int room, int x, int y, int dir);
+void world_fade_hold(int room, int x, int y, int dir, int hold); /* black for `hold` frames in the middle */
bool world_fading(void);
extern uint8_t g_fade; /* 0 clear, 255 black: drawn over the room */
#endif
diff --git a/games/undertale/tests/check.py b/games/undertale/tests/check.py
new file mode 100644
index 00000000..1c81bf1f
--- /dev/null
+++ b/games/undertale/tests/check.py
@@ -0,0 +1,115 @@
+#!/usr/bin/env python3
+"""Checks of Undertale on a computer (make test): the host build, with
+AddressSanitizer and UBSan, through the menus, every battle, the saves and
+the whole Ruins.
+
+ python3 tests/check.py build/play [--quick]
+
+--quick skips playing the whole Ruins (the longest part)."""
+import os
+import re
+import shutil
+import subprocess
+import sys
+import tempfile
+
+PLAY = sys.argv[1] if len(sys.argv) > 1 else "build/play"
+HERE = os.path.dirname(os.path.abspath(__file__))
+QUICK = "--quick" in sys.argv
+failures = []
+ENV = dict(os.environ, ASAN_OPTIONS="detect_leaks=0", UBSAN_OPTIONS="halt_on_error=1:print_stacktrace=1")
+
+# the flags the checks look at (src/flags.h)
+FLAGS = {}
+src = open(os.path.join(HERE, "..", "src", "flags.h")).read()
+body = re.sub(r"/\*.*?\*/", "", src[src.index("enum {") + 6:src.rindex("FLAG_COUNT")], flags=re.S)
+for i, n in enumerate(n.strip() for n in body.split(",") if n.strip()):
+ FLAGS[n] = i
+
+MODE_WORLD, MODE_BATTLE, MODE_END = 2, 3, 8
+
+
+def run(args, frames, saves=None, what=""):
+ """Plays (in a save folder, a new one if None); returns the end state: mode, room, flags, items..."""
+ own = saves is None
+ if own:
+ saves = tempfile.mkdtemp(prefix="undertale_check_")
+ p = subprocess.run([PLAY, "--saves", saves, "--frames", str(frames)] + args, capture_output=True, text=True,
+ env=ENV, timeout=900)
+ if own:
+ shutil.rmtree(saves, ignore_errors=True)
+ if p.returncode or "runtime error" in p.stderr or "AddressSanitizer" in p.stderr:
+ failures.append(f"{what or args}: crashed or a sanitizer error\n{p.stderr[-2000:]}")
+ return None
+ m = re.search(r"END mode (\d+) room (-?\d+) at (-?\d+),(-?\d+) hp (-?\d+) lv (\d+) gold (\d+) kills (\d+) path (\w+)",
+ p.stdout)
+ if not m:
+ failures.append(f"{what}: no end state\n{p.stdout[-500:]}")
+ return None
+ s = dict(zip(("mode", "room", "x", "y", "hp", "lv", "gold", "kills"), map(int, m.groups()[:8])))
+ s["path"] = m.group(9)
+ fl = re.search(r"FLAGS(.*)", p.stdout).group(1).split()
+ s["flags"] = {int(a): int(b) for a, b in (f.split("=") for f in fl)}
+ s["items"] = [int(v) for v in re.search(r"ITEMS(.*)", p.stdout).group(1).split()]
+ return s
+
+
+def flag(s, name):
+ return s["flags"].get(FLAGS["F_" + name], 0)
+
+
+def check(cond, msg):
+ if not cond:
+ failures.append(msg)
+
+
+# the intro, the title, the instructions, naming the fallen human "A", Done, Yes: the flowers
+keys = "30:z,60:z,90:z,120:z," + ",".join("%d:down" % (150 + 10 * i) for i in range(8)) + \
+ ",230:right,240:right,250:z,290:right,300:z"
+s = run(["--keys", keys], 700, what="the menus to a new game")
+check(s and s["mode"] == MODE_WORLD and s["room"] == 0 and s["hp"] == 20, f"the menus did not start a game: {s}")
+
+# every battle of the Ruins, fled from (Toriel's can't be: she is spared) and fought to the end
+for form in range(18):
+ s = run(["--god", "--battle", str(form), "--path", "flee"], 1500, what=f"battle {form}, fleeing")
+ if form == 17:
+ continue
+ check(s and s["mode"] == MODE_WORLD, f"battle {form}: fleeing did not end it: {s}")
+for form in (2, 3, 6, 10, 12):
+ s = run(["--god", "--battle", str(form), "--path", "fight"], 3000, what=f"battle {form}, fighting")
+ check(s and s["mode"] == MODE_WORLD and s["kills"] >= 1, f"battle {form}: FIGHT did not win it: {s}")
+s = run(["--god", "--battle", "16", "--path", "act:3"], 6000, what="Napstablook, cheered up")
+check(s and s["mode"] == MODE_WORLD and s["kills"] == 0, f"Napstablook was not spared by cheering: {s}")
+
+# the leaf pile's SAVE, then Continue from the title
+d = tempfile.mkdtemp(prefix="undertale_check_")
+s = run(["--name", "Frisk", "--noenc", "--room", "8", "--at", "5012,4498", "--path", "u;z;w20;z;w30;x"], 300, saves=d,
+ what="saving at the leaf pile")
+check(os.path.exists(d + "/undertale.sav") and os.path.exists(d + "/undertale_saves.py"), "the SAVE Point did not save")
+s = run(["--keys", "30:z,60:z,90:z,120:z"], 300, saves=d, what="Continue")
+check(s and s["mode"] == MODE_WORLD and s["room"] == 8, f"Continue did not go back to the leaf pile: {s}")
+# Home keeps the moment; the next start is back there
+s = run(["--keys", "30:z,60:z,90:z,120:z,130-170:right,200:home"], 300, saves=d, what="Home")
+s = run([], 30, saves=d, what="back after Home")
+check(s and s["mode"] == MODE_WORLD and s["room"] == 8 and s["x"] > 5000, f"Home did not bring the game back: {s}")
+shutil.rmtree(d, ignore_errors=True)
+
+# the whole Ruins, the friendly way: Flowey, Toriel's puzzles, the candy, the rocks, Napstablook, the switches,
+# Toriel's home, her fight spared, Flowey's judgement, the door out
+if not QUICK:
+ s = run(["--name", "Frisk", "--noenc", "--god", "--path-file", os.path.join(HERE, "ruins.path")], 40000,
+ what="the Ruins")
+ check(s and s["mode"] == MODE_END, f"the Ruins did not end at their door: {s}")
+ if s:
+ for name, v in (("FLOWEY_MET", 1), ("DUMMY", 1), ("RUINS5_DONE", 1), ("RUINS6_DONE", 1), ("PHONE", 1),
+ ("RUINS9_ROCK", 1), ("RUINS11_ROCK", 5), ("NAPSTA", 1), ("ONESWITCH", 1), ("ROTATE4", 1),
+ ("TORIEL_HOME", 1), ("HOME_TOUR", 1), ("TORIEL_BASEMENT", 1), ("BASEMENT_TALK", 3),
+ ("TORIEL_FIGHT", 1), ("FLOWEY_END", 1), ("RUINS_EXIT", 1)):
+ check(flag(s, name) == v, f"the Ruins: F_{name} is {flag(s, name)}, not {v}")
+ check(s["kills"] == 0, f"the Ruins: {s['kills']} killed on the friendly way")
+ check(s["items"].count(1) == 2, f"the Ruins: not the two pieces of Monster Candy: {s['items']}")
+
+if failures:
+ print("\n".join("FAIL " + f for f in failures))
+ sys.exit(1)
+print("all checks passed")
diff --git a/games/undertale/tests/play.c b/games/undertale/tests/play.c
index 2e339f4f..1f369196 100644
--- a/games/undertale/tests/play.c
+++ b/games/undertale/tests/play.c
@@ -33,12 +33,125 @@ static int nholds;
#include "../src/event.h"
#include "../src/text.h"
static char path_buf[65536];
+extern bool g_no_encounters;
static char *path_at;
static int path_wait, path_stuck, path_last_x, path_last_y, path_room = -1;
+/* ---------------------------------------------------------------- "go:x,y": a way there (Frisk's top-left
+ * on a 4-pixel grid, over the floor and around the solid things), found once, then walked */
+#define GO_R 400 /* cells each way: 1600 pixels */
+#define GO_N (2 * GO_R + 1)
+static int16_t go_wp[512][2];
+static int go_n, go_i;
+static bool go_free(int x, int y) { return world_walkable(x + 3, y + 20, 14, 9, -1); }
+static bool go_plan(int tx, int ty) {
+ static int16_t prev[GO_N * GO_N];
+ static int queue[GO_N * GO_N];
+ int ox = pl.x, oy = pl.y;
+ for (int i = 0; i < GO_N * GO_N; i++) prev[i] = -2;
+ int s = GO_R * GO_N + GO_R, qh = 0, qt = 0, best = s, bestd = 1 << 30;
+ prev[s] = -1, queue[qt++] = s;
+ while (qh < qt) {
+ int c = queue[qh++], cx = c % GO_N - GO_R, cy = c / GO_N - GO_R;
+ int d = abs(ox + cx * 4 - tx) + abs(oy + cy * 4 - ty);
+ if (d < bestd) bestd = d, best = c;
+ if (d <= 3) break;
+ static const int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
+ for (int k = 0; k < 4; k++) {
+ int nx = cx + dx[k], ny = cy + dy[k];
+ if (nx < -GO_R || nx > GO_R || ny < -GO_R || ny > GO_R) continue;
+ int n = (ny + GO_R) * GO_N + nx + GO_R;
+ if (prev[n] != -2 || !go_free(ox + nx * 4, oy + ny * 4)) continue;
+ prev[n] = (int16_t)k, queue[qt++] = n;
+ }
+ }
+ /* back from the end, a waypoint where the way turns */
+ int16_t rev[GO_N * 2][2];
+ int nr = 0, c = best, last = -1;
+ while (prev[c] >= 0 && nr < GO_N * 2) {
+ int k = prev[c], cx = c % GO_N - GO_R, cy = c / GO_N - GO_R;
+ if (k != last) rev[nr][0] = (int16_t)(ox + cx * 4), rev[nr][1] = (int16_t)(oy + cy * 4), nr++, last = k;
+ static const int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
+ c = (cy - dy[k] + GO_R) * GO_N + cx - dx[k] + GO_R;
+ }
+ go_n = 0;
+ for (int i = nr - 1; i >= 0 && go_n < 512; i--) go_wp[go_n][0] = rev[i][0], go_wp[go_n][1] = rev[i][1], go_n++;
+ if (nr && go_n < 512) {
+ /* (the last turn's waypoint is where the turn starts: the end too) */
+ int ex = ox + (best % GO_N - GO_R) * 4, ey = oy + (best / GO_N - GO_R) * 4;
+ go_wp[go_n][0] = (int16_t)ex, go_wp[go_n][1] = (int16_t)ey, go_n++;
+ }
+ go_i = 0;
+ if (bestd > 3) fprintf(stderr, "go: no way to %d,%d, as near as %d px\n", tx, ty, bestd);
+ if (getenv("GO_DEBUG"))
+ for (int i = 0; i < go_n; i++) fprintf(stderr, "go %d: %d,%d\n", i, go_wp[i][0], go_wp[i][1]);
+ return go_n > 0;
+}
+
/* the keys the path holds this frame (0: it's done or waiting) */
static uint32_t path_keys(int f) {
if (!path_at || !*path_at) return 0;
+ /* a battle or a choice that came on the way to a point: the step after it is for it, if it says so */
+ {
+ char *e = strchr(path_at, ';');
+ if (e) {
+ const char *n = e + 1;
+ bool nb = !strncmp(n, "fight", 5) || !strncmp(n, "spare", 5) || !strncmp(n, "bt", 2) || !strncmp(n, "act:", 4) ||
+ !strncmp(n, "flee", 4);
+ bool hb = !strncmp(path_at, "fight", 5) || !strncmp(path_at, "spare", 5) || !strncmp(path_at, "bt", 2) ||
+ !strncmp(path_at, "act:", 4) || !strncmp(path_at, "flee", 4) || !strncmp(path_at, "pick:", 5);
+ if (!hb && ((g_mode == MODE_BATTLE && nb) || (g_mode == MODE_WORLD && text_menu_sel() >= 0 && !strncmp(n, "pick:", 5))))
+ path_at = e + 1;
+ }
+ }
+ /* "pick:N": the option N of the next list or choice */
+ if (!strncmp(path_at, "pick:", 5) && g_mode == MODE_WORLD) {
+ int n = atoi(path_at + 5), sel = text_menu_sel();
+ if (f & 1) return 0;
+ if (sel < 0) return text_active() ? K_Z : 0;
+ if (sel >= 100) sel -= 100;
+ if (sel == n) {
+ char *e = strchr(path_at, ';');
+ path_at = e ? e + 1 : path_at + strlen(path_at);
+ return K_Z;
+ }
+ return sel < n ? (text_menu_sel() >= 100 ? K_RIGHT : K_DOWN) : (text_menu_sel() >= 100 ? K_LEFT : K_UP);
+ }
+ /* a text in the way: read on (Z every other frame) */
+ if (g_mode == MODE_WORLD && text_active()) return (f & 1) ? K_Z : 0;
+ /* in a battle: "fight" FIGHTs, "spare" spares, "act:N" picks the ACT N (1: the first after Check) each turn,
+ * "bt" (a scripted battle) reads on; Z on whatever else comes (the bar, the texts). A battle the path didn't
+ * expect: Frisk flees it */
+ bool btok = !strncmp(path_at, "fight", 5) || !strncmp(path_at, "spare", 5) || !strncmp(path_at, "bt", 2) ||
+ !strncmp(path_at, "act:", 4) || !strncmp(path_at, "flee", 4);
+ static int idle;
+ if (g_mode == MODE_BATTLE) {
+ idle = 0;
+ if (battle_over()) return 0;
+ if (f & 1) return 0;
+ if (bt.scripted) return K_Z; /* (Flowey's: read on) */
+ int want = !btok || !strncmp(path_at, "flee", 4) || !strncmp(path_at, "spare", 5) ? 3 : !strncmp(path_at, "act:", 4) ? 1 : 0;
+ int mercy = (!btok || !strncmp(path_at, "flee", 4)) && !bt.no_flee ? 1 : 0;
+ switch (battle_ui()) {
+ case BUI_MENU: return bt.button < want ? K_RIGHT : bt.button > want ? K_LEFT : K_Z;
+ case BUI_ACTS: {
+ int n = atoi(path_at + 4);
+ return bt.act + 2 <= n ? K_DOWN : bt.act < n ? K_RIGHT : bt.act - 2 >= n ? K_UP : bt.act > n ? K_LEFT : K_Z;
+ }
+ case BUI_MERCY: return bt.mercy < mercy ? K_DOWN : bt.mercy > mercy ? K_UP : K_Z;
+ case BUI_BAR: return abs(bt.bar_x / FX - 140) < 8 ? K_Z : 0; /* (the middle: the best hit) */
+ default: return K_Z;
+ }
+ }
+ if (btok) {
+ /* (it waits for the battle: done when the world has been quiet a while) */
+ if (g_mode == MODE_WORLD && !event_blocking() && !text_active() && ++idle > 30) {
+ char *e = strchr(path_at, ';');
+ path_at = e ? e + 1 : path_at + strlen(path_at);
+ idle = 0;
+ }
+ return (f & 1) ? K_Z : 0;
+ }
if (path_wait > 0) {
path_wait--;
return 0;
@@ -53,25 +166,65 @@ static uint32_t path_keys(int f) {
path_wait = 1;
return tok[0] == 'z' ? K_Z : tok[0] == 'x' ? K_X : K_C;
}
+ /* u d l r: a key's press (to face something) */
+ if (!tok[1] && strchr("udlr", tok[0])) {
+ path_at = next;
+ path_wait = 1;
+ return tok[0] == 'u' ? K_UP : tok[0] == 'd' ? K_DOWN : tok[0] == 'l' ? K_LEFT : K_RIGHT;
+ }
if (tok[0] == 'w') {
path_wait = atoi(tok + 1);
path_at = next;
return 0;
}
if (!strcmp(tok, "talk")) {
- if (!text_active() && !event_running() && g_mode == MODE_WORLD && !world_fading()) {
+ if (!text_active() && !event_blocking() && g_mode == MODE_WORLD && !world_fading()) {
path_at = next;
return 0;
}
return (f & 1) ? K_Z : 0;
}
+ if (!strncmp(tok, "go:", 3)) {
+ static char *planned;
+ if (g_mode != MODE_WORLD || text_active() || event_blocking() || world_fading()) return 0;
+ int gx, gy;
+ sscanf(tok + 3, "%d,%d", &gx, &gy);
+ static int planned_room;
+ if (planned != path_at || planned_room != g_room) {
+ planned = path_at, planned_room = g_room;
+ if (!go_plan(gx, gy)) {
+ path_at = next, planned = NULL;
+ return 0;
+ }
+ }
+ while (go_i < go_n && abs(go_wp[go_i][0] - pl.x) <= 1 && abs(go_wp[go_i][1] - pl.y) <= 1) go_i++;
+ /* (a waypoint on the axis it's walking: it may step over it by a pixel or two) */
+ if (go_i >= go_n) {
+ path_at = next, planned = NULL;
+ return 0;
+ }
+ if (pl.x == path_last_x && pl.y == path_last_y) {
+ if (++path_stuck > 30) {
+ planned = NULL, path_stuck = 0; /* (something moved in the way: plan again) */
+ return 0;
+ }
+ } else
+ path_stuck = 0;
+ path_last_x = pl.x, path_last_y = pl.y;
+ /* one axis at a time, as the way was found */
+ int ddx = go_wp[go_i][0] - pl.x, ddy = go_wp[go_i][1] - pl.y;
+ if (abs(ddx) > 1) return ddx > 0 ? K_RIGHT : K_LEFT;
+ return ddy > 0 ? K_DOWN : K_UP;
+ }
int x, y;
if (sscanf(tok, "%d,%d", &x, &y) != 2) {
path_at = next;
return 0;
}
- if (g_mode != MODE_WORLD || text_active() || event_running() || world_fading()) return 0;
- /* a door took him to another room: that point is reached */
+ if (g_mode != MODE_WORLD || text_active() || event_blocking() || world_fading()) return 0;
+ /* a door took him to another room on the way to this point: it is reached */
+ static char *room_step;
+ if (room_step != path_at) room_step = path_at, path_room = g_room;
if (path_room >= 0 && g_room != path_room) {
path_room = g_room;
path_at = next;
@@ -127,11 +280,29 @@ int main(int argc, char **argv) {
int frames = 120, room = -1, ax = 0, ay = 0, battle = -1;
const char *name = NULL;
int nflags = 0, fl[64][2];
- bool trace = false, coll = false;
+ bool trace = false, coll = false, god = 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], "--path") && i + 1 < argc) snprintf(path_buf, sizeof path_buf, "%s", argv[++i]), path_at = path_buf;
+ else if (!strcmp(argv[i], "--path-file") && i + 1 < argc) {
+ /* a path one step a line; # starts a comment */
+ FILE *pf = fopen(argv[++i], "r");
+ if (!pf) fprintf(stderr, "no %s\n", argv[i]), exit(2);
+ char line[256];
+ size_t n = 0;
+ while (fgets(line, sizeof line, pf)) {
+ char *h = strchr(line, '#');
+ if (h) *h = 0;
+ char *a = line, *e = line + strlen(line);
+ while (*a == ' ' || *a == '\t') a++;
+ while (e > a && (e[-1] == '\n' || e[-1] == '\r' || e[-1] == ' ' || e[-1] == '\t')) *--e = 0;
+ if (!*a) continue;
+ n += (size_t)snprintf(path_buf + n, sizeof path_buf - n, "%s%s", n ? ";" : "", a);
+ }
+ fclose(pf);
+ path_at = path_buf;
+ }
else if (!strcmp(argv[i], "--shots") && i + 1 < argc) 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];
@@ -143,6 +314,8 @@ int main(int argc, char **argv) {
sscanf(argv[++i], "%d=%d", &fl[nflags][0], &fl[nflags][1]);
nflags++;
} else if (!strcmp(argv[i], "--trace")) trace = true;
+ else if (!strcmp(argv[i], "--noenc")) g_no_encounters = true;
+ else if (!strcmp(argv[i], "--god")) god = true;
else if (!strcmp(argv[i], "--coll")) coll = true;
else fprintf(stderr, "unknown option %s\n", argv[i]), exit(2);
}
@@ -154,8 +327,10 @@ int main(int argc, char **argv) {
host_save_dir(saves);
ut_bin = ut_data;
game_init();
- if (room >= 0 || name) {
+ if (room >= 0 || name || battle >= 0) {
game_new(name ? name : "Frisk");
+ for (int i = 0; i < nflags; i++) set_flag(fl[i][0], fl[i][1]); /* (before the room is set up) */
+ if (room < 0 && battle >= 0) room = 0; /* (a battle comes back to a room) */
if (room >= 0) {
if (!ax && !ay) {
RoomInfo ri;
@@ -174,10 +349,11 @@ int main(int argc, char **argv) {
if (f >= holds[i].a && f <= holds[i].b) k |= holds[i].k;
if (!k) k = path_keys(f);
host_keys = k;
+ if (god && g_mode == MODE_BATTLE && sv.hp < sv.maxhp) sv.hp = sv.maxhp; /* (--god: the SOUL can't be hurt) */
host_time += 33;
game_frame(k);
game_draw();
- if (trace) printf("%d mode %d room %d frisk %d,%d cam %d,%d hp %d\n", f, g_mode, g_room, pl.x, pl.y, cam_x, cam_y, sv.hp);
+ if (trace) printf("%d mode %d room %d frisk %d,%d cam %d,%d hp %d ui %d btn %d keys %x path %.12s\n", f, g_mode, g_room, pl.x, pl.y, cam_x, cam_y, sv.hp, battle_ui(), bt.button, k, path_at ? path_at : "");
char want[16];
snprintf(want, sizeof want, "%d", f);
bool shoot = all;
@@ -211,5 +387,12 @@ int main(int argc, char **argv) {
}
}
if (gfx_dropped) printf("dropped %d draw commands\n", gfx_dropped);
+ printf("END mode %d room %d at %d,%d hp %d lv %d gold %d kills %d path %s\nFLAGS", g_mode, g_room, pl.x, pl.y, sv.hp,
+ sv.lv, sv.gold, sv.kills, path_at && *path_at ? "left" : "done");
+ for (int i = 0; i < FLAG_COUNT; i++)
+ if (sv.flags[i]) printf(" %d=%d", i, sv.flags[i]);
+ printf("\nITEMS");
+ for (int i = 0; i < NUM_ITEMS; i++) printf(" %d", sv.items[i]);
+ printf("\n");
return 0;
}
diff --git a/games/undertale/tests/ruins.path b/games/undertale/tests/ruins.path
new file mode 100644
index 00000000..e23a6e78
--- /dev/null
+++ b/games/undertale/tests/ruins.path
@@ -0,0 +1,241 @@
+# The Ruins from the bed of golden flowers to the door out, the friendly way (tests/check.py plays it with
+# --name Frisk --noenc --god: no random encounters, the SOUL not hurt). One step a line: x,y walk there;
+# go:x,y find the way there; u d l r z x c a key; talk read on; pick:N an option; wN wait;
+# fight / spare / flee / act:N / bt how the next battle goes.
+
+# the flowers, then Flowey
+go:608,6036
+608,6020
+go:510,5800
+bt
+w40
+talk
+go:510,5590
+510,5560
+# the entrance: Toriel by the stairs
+go:600,5300
+talk
+go:520,5190
+520,5160
+w20
+# the middle road: Toriel's puzzle
+go:500,4960
+talk
+w30
+go:494,4900
+494,4840
+w20
+# the switches
+talk
+go:748,4666
+u
+z
+talk
+go:948,4666
+u
+z
+talk
+w40
+talk
+go:1100,4732
+# the Dummy: talk to it
+talk
+go:1278,4700
+r
+z
+act:1
+w30
+talk
+w40
+go:1252,4686
+1252,4650
+w20
+# the blueprint: Toriel goes ahead, a Froggit, then hand in hand over the spikes
+go:1520,4480
+w200
+talk
+go:1780,4480
+w20
+talk
+w60
+talk
+w40
+go:2320,4470
+# the long hall: alone, then the pillar
+talk
+w60
+go:4470,4470
+w20
+talk
+w60
+talk
+go:4790,4470
+# the leaf pile: Toriel calls; the Froggit's advice; the candy room above
+talk
+go:4901,4448
+u
+z
+talk
+go:4960,4446
+4960,4420
+w20
+go:4960,4226
+u
+z
+talk
+z
+talk
+go:4960,4352
+4960,4380
+w20
+# the cracked floor: down through it, out by the right chute
+go:5040,4600
+go:5300,4692
+w60
+go:5352,5090
+5352,5060
+w30
+# the first rock: Toriel calls about pie
+talk
+go:5590,4728
+5700,4728
+w20
+# the leaf puzzle: the second call, then the way through the cracks
+talk
+go:6250,4700
+6250,4868
+6310,4868
+6310,4790
+6370,4790
+6370,4868
+6430,4868
+6450,4868
+6450,4810
+6520,4810
+# the second rock: the third call, then ask the rock (four times), walking into it
+talk
+go:6704,4870
+r
+r
+talk
+go:6724,4870
+r
+r
+talk
+go:6724,4850
+r
+r
+talk
+go:6860,4840
+w30
+talk
+go:6724,4870
+r
+r
+talk
+go:7000,4840
+# the mouse hole: SAVE
+go:7172,4882
+u
+z
+w20
+z
+w30
+x
+w20
+# Napstablook: move it with force, then cheer them up
+go:7490,4830
+pick:0
+act:3
+w40
+talk
+# north to the Froggits' hall
+go:7597,4790
+7597,4730
+w30
+go:7900,4542
+u
+z
+pick:0
+talk
+go:8000,4590
+talk
+w30
+# the one switch: down the middle crack (between the others), the switch, back up the chute
+go:8100,4640
+8460,4640
+8460,4570
+w60
+u
+z
+talk
+go:8505,4960
+8505,4930
+w30
+# the rotating rooms: blue behind the pillar, red, green behind the pillar
+go:8970,4880
+8970,4900
+w30
+go:8962,4190
+l
+z
+talk
+go:8640,4340
+go:8400,4206
+u
+z
+talk
+go:8455,4130
+8455,4100
+w30
+go:8466,3765
+l
+z
+talk
+go:8720,3740
+# the crossroads, up to Toriel's tree; then her house
+go:9006,3546
+9006,3510
+w30
+go:9006,3380
+talk
+w30
+go:9012,3080
+9012,3060
+w30
+talk
+w60
+talk
+w30
+# the living room: ask her how to leave
+go:9190,2840
+go:8840,2860
+go:8664,2764
+u
+z
+pick:1
+talk
+w100
+# the basement: her three talks, then the door
+go:9090,2760
+go:9070,2736
+w30
+go:9990,2316
+talk
+go:10010,2150
+talk
+go:10010,2080
+spare
+w30
+talk
+w100
+go:10010,2040
+10010,2010
+w30
+# past the door: Flowey, then the way out
+go:10010,300
+go:10010,236
+talk
+w60
+go:10010,50
+w60
diff --git a/games/undertale/tools/pack.py b/games/undertale/tools/pack.py
index d941607b..3da1cbd7 100644
--- a/games/undertale/tools/pack.py
+++ b/games/undertale/tools/pack.py
@@ -22,6 +22,7 @@ import struct
import sys
import numpy as np
+from scipy import ndimage
from PIL import Image, ImageDraw, ImageFont, ImageSequence
HERE = os.path.dirname(os.path.abspath(__file__))
@@ -260,13 +261,27 @@ class Area:
def patch(self, p):
"""changes to the map, before rooms are cut from it: ('fill', x, y, w, h, (r, g, b)),
- ('copy', sx, sy, w, h, dx, dy) or ('mirror', ...) the same, flipped left to right"""
+ ('copy', sx, sy, w, h, dx, dy) or ('mirror', ...) the same, flipped left to right, or ('erase', x, y, w, h,
+ [colours]): what isn't one of the colours takes the colour of the nearest pixel that is (a monster painted
+ on the floor)"""
if p[0] == "fill":
_, x, y, w, h, c = p
self.idx[y:y + h, x:x + w] = self.color_index(c)
elif p[0] == "copy":
_, sx, sy, w, h, dx, dy = p
self.idx[dy:dy + h, dx:dx + w] = self.idx[sy:sy + h, sx:sx + w].copy()
+ elif p[0] == "erase":
+ # the nearest pixel of the colours, looking a little around the rectangle (only it changes)
+ _, x, y, w, h, cols = p
+ m = 4
+ x0, y0 = max(0, x - m), max(0, y - m)
+ win = self.idx[y0:y + h + m, x0:x + w + m]
+ keep = np.isin(win, [i for i, k in enumerate(self.rgb) if k in [tuple(c) for c in cols]])
+ if not keep.any():
+ raise ValueError("erase %s: none of its colours there" % (p,))
+ _, (iy, ix) = ndimage.distance_transform_edt(~keep, return_indices=True)
+ filled = win[iy, ix]
+ self.idx[y:y + h, x:x + w] = filled[y - y0:y - y0 + h, x - x0:x - x0 + w]
elif p[0] == "mirror":
_, sx, sy, w, h, dx, dy = p
self.idx[dy:dy + h, dx:dx + w] = self.idx[sy:sy + h, sx:sx + w][:, ::-1].copy()
@@ -294,6 +309,47 @@ def room_pixels(area, r):
return out, sub, (xs0 - x, ys0 - y)
+def floor_mask(area, r, x0, y0, x1, y1):
+ """the pixels of a rectangle of the map in the room's floor colours"""
+ walk_idx = [i for c in area.spec["floor"] + r.get("floor_colors", []) for i, k in enumerate(area.rgb)
+ if k == tuple(c) and i != area.transparent]
+ return np.isin(area.idx[y0:y1, x0:x1], walk_idx)
+
+
+def apply_links(area, rooms):
+ """the links between rooms one above the other through a dark doorway, ("v", lower, upper, x, w, y): a door
+ each way between the lower room's floor under the doorway (x .. x + w, y in it) and the upper's above it, the
+ floor made walkable up to them. ("up", lower, x, w, y, to, (tx, ty)): a one-way door, up a chute"""
+ for link in R.LINKS:
+ lo = rooms.get(link[1])
+ if lo is None or lo["area"] != area.spec["name"]:
+ continue
+ x, w, yd = link[3:6] if link[0] == "v" else link[2:5]
+ cx = x + w // 2
+ lx, ly, lw, lh = lo["rect"]
+ col = floor_mask(area, lo, cx, yd, cx + 1, ly + lh)[:, 0]
+ if not col.any():
+ sys.exit("link %s: no floor under the doorway" % (link,))
+ ya = yd + int(np.argmax(col)) # the lower room's floor, where the doorway ends
+ if link[0] == "up":
+ # a chute is narrow: a little room either side to walk into it
+ to, (tx, ty) = link[5:7]
+ lo.setdefault("fix", []).append(("walk", x - 4, ya - 8, w + 8, 12))
+ lo.setdefault("doors", []).append(((x - 2, ya - 6, w + 4, 4), to, (tx, ty), "down"))
+ continue
+ lo.setdefault("fix", []).append(("walk", x, ya - 8, w, 12))
+ up = rooms[link[2]]
+ ux, uy, uw, uh = up["rect"]
+ col = floor_mask(area, up, cx, uy, cx + 1, min(uy + uh, yd))[:, 0]
+ if not col.any():
+ sys.exit("link %s: no floor above the doorway" % (link,))
+ yb = uy + len(col) - int(np.argmax(col[::-1])) # the upper room's floor, where the doorway starts
+ up.setdefault("fix", []).append(("walk", x, yb - 4, w, 4))
+ lo.setdefault("doors", []).append(((x, ya - 6, w, 4), link[2], (cx - 10, yb - 34), "up"))
+ up.setdefault("doors", []).append(((x, yb - 2, w, 2), link[1], (cx - 10, ya - 12), "down"))
+ print("link: %s floor at %d, %s at %d" % (link[1], ya, link[2], yb))
+
+
def collision(area, r):
"""4-pixel cells over the room: walkable where the floor's colours fill at least half the cell and
inside one of its floor rectangles (all of it if it has none), then its own fixes"""
@@ -305,22 +361,36 @@ def collision(area, r):
for i, k in enumerate(area.rgb):
if k == tuple(c) and i != area.transparent:
walk_idx.add(i)
- sub = np.zeros((ch * 4, cw * 4), bool)
- xs0, ys0, xs1, ys1 = max(x, 0), max(y, 0), min(x + w, W), min(y + h, H)
- m = np.isin(area.idx[ys0:ys1, xs0:xs1], list(walk_idx))
- sub[ys0 - y:ys1 - y, xs0 - x:xs1 - x] = m
+ # the map's pixels over the cells, and `margin` more around (what's beyond the room's edge counts too)
+ margin = r.get("margin", area.spec.get("margin", 0))
+ X0, Y0, X1, Y1 = x - margin, y - margin, x + cw * 4 + margin, y + ch * 4 + margin
+ big = np.zeros((Y1 - Y0, X1 - X0), bool)
+ xs0, ys0, xs1, ys1 = max(X0, 0), max(Y0, 0), min(X1, W), min(Y1, H)
+ big[ys0 - Y0:ys1 - Y0, xs0 - X0:xs1 - X0] = np.isin(area.idx[ys0:ys1, xs0:xs1], list(walk_idx))
+ sub = big[margin:margin + ch * 4, margin:margin + cw * 4]
cells = sub.reshape(ch, 4, cw, 4).mean(axis=(1, 3)) >= 0.5
+ # piles of leaves are floor, outline and all
+ soft = area.spec.get("piles")
+ pile_big = np.zeros_like(big)
+ if soft:
+ win = np.zeros(big.shape, area.idx.dtype)
+ win[ys0 - Y0:ys1 - Y0, xs0 - X0:xs1 - X0] = area.idx[ys0:ys1, xs0:xs1]
+ pile = np.isin(win, [i for i, k in enumerate(area.rgb) if k in [tuple(c) for c in soft]])
+ lab, n = ndimage.label(ndimage.binary_dilation(pile, iterations=3))
+ for sl in ndimage.find_objects(lab):
+ if (sl[0].stop - sl[0].start) * (sl[1].stop - sl[1].start) >= 16:
+ pile_big[sl] = True
# walls drawn in the floor's colours give themselves away by their lines: a cell is floor only with no
- # other colour within `margin` pixels of it
- margin = r.get("margin", area.spec.get("margin", 0))
+ # other colour within `margin` pixels of it (a pile's leaves don't count)
if margin:
- other = ~sub
- pad = np.pad(other, margin, constant_values=False)
- near = np.zeros_like(other)
+ other = ~big & ~pile_big
+ near = np.zeros_like(sub)
for dy in range(2 * margin + 1):
for dx in range(2 * margin + 1):
- near |= pad[dy:dy + other.shape[0], dx:dx + other.shape[1]]
+ near |= other[dy:dy + sub.shape[0], dx:dx + sub.shape[1]]
cells &= ~near.reshape(ch, 4, cw, 4).any(axis=(1, 3))
+ piles = pile_big[margin:margin + ch * 4, margin:margin + cw * 4]
+ cells |= piles.reshape(ch, 4, cw, 4).mean(axis=(1, 3)) >= 0.5
if r.get("floor_rects"):
keep = np.zeros_like(cells)
for fx, fy, fw, fh in r["floor_rects"]:
@@ -440,6 +510,7 @@ def main():
for ai, aspec in enumerate(R.AREAS):
area = Area(ref, aspec)
defines.append(("AREA_" + aspec["name"].upper(), ai))
+ apply_links(area, {r["name"]: r for r in R.ROOMS})
for r in R.ROOMS:
if r["area"] != aspec["name"]:
continue
diff --git a/games/undertale/tools/rooms.py b/games/undertale/tools/rooms.py
index 69eaf4a1..4ebfb97b 100644
--- a/games/undertale/tools/rooms.py
+++ b/games/undertale/tools/rooms.py
@@ -9,6 +9,15 @@ taken out: the game draws them).
Rooms are named as the game names them (room_ruins1 is ruins1)."""
+# Toriel's home: wood, the rugs, the kitchen's tiles, the hallway's, the bedrooms' floors
+HOUSE_FLOOR = [(245, 215, 158), (246, 231, 189), (194, 133, 78), (255, 186, 95), (151, 97, 26), (187, 106, 52),
+ (238, 203, 131), (230, 245, 120), (186, 133, 4), (235, 186, 67), (233, 77, 42), (255, 213, 166),
+ (166, 189, 255), (74, 151, 201)]
+BASEMENT_FLOOR = [(132, 53, 125)]
+# the darker floor: cracks, the rocks' tracks
+CRACKED = [(132, 53, 125)]
+LEAVES = [(128, 17, 17), (232, 35, 19)]
+RUINS_PLAIN = [(163, 73, 164), (185, 98, 185)]
RUINS_FLOOR = [
(163, 73, 164), (185, 98, 185), # the floor and its paths
(128, 17, 17), (232, 35, 19), (233, 77, 42), (123, 24, 19), (121, 18, 0), (64, 0, 0), (157, 32, 0), # red leaves
@@ -18,9 +27,34 @@ RUINS_FLOOR = [
]
AREAS = [
- dict(name="ruins", map="Ruins_map.png", floor=RUINS_FLOOR, margin=3, patches=[
+ dict(name="ruins", map="Ruins_map.png", floor=RUINS_FLOOR, margin=3, piles=LEAVES, patches=[
("mirror", 95, 5988, 27, 60, 178, 5988), # Toriel tending the flowers (the game's last pages)
("fill", 509, 5768, 23, 12, (0, 0, 0)), ("fill", 509, 5780, 23, 11, (34, 177, 76)), # Flowey
+ # what the game draws itself: the switch room's spikes, the Dummy, the pillar Toriel hides behind, the
+ # leaf pile's Froggit, the SAVE stars
+ ("erase", 1058, 4738, 26, 44, RUINS_PLAIN), ("erase", 1296, 4688, 26, 36, RUINS_PLAIN),
+ ("copy", 4521, 4380, 38, 61, 4601, 4380), ("erase", 4598, 4441, 44, 21, RUINS_PLAIN),
+ ("erase", 4898, 4441, 28, 23, RUINS_PLAIN),
+ ("copy", 531, 5274, 20, 22, 511, 5274), ("copy", 5010, 4480, 22, 20, 5010, 4500),
+ ("erase", 7168, 4856, 26, 26, RUINS_PLAIN), ("copy", 8902, 3116, 22, 26, 8942, 3116),
+ # the spikes the game raises and lowers (not the blueprint room's: those stay)
+ ] + [("erase", x, y, 20, 20, RUINS_PLAIN) for x, y in [
+ (5740, 4680), (5740, 4700), (5740, 4720), (5740, 4740), (5740, 4760), (5740, 4780),
+ (6880, 4820), (6880, 4840), (6880, 4860), (6900, 4820), (6900, 4840), (6900, 4860),
+ (8680, 4620), (8680, 4640), (8760, 4620), (8760, 4640), (8960, 4840), (8980, 4840),
+ (8960, 4140), (8980, 4140), (8760, 4340), (8760, 4360), (8660, 4340), (8660, 4360),
+ (8440, 4140), (8460, 4140), (8440, 3960), (8460, 3960), (8660, 3740), (8660, 3760)]] + [
+ # the rocks, the Froggits, the candy, what lies in the one switch puzzle's rooms, the Toy Knife
+ ("erase", 5620, 4735, 20, 20, RUINS_PLAIN), ("erase", 6700, 4795, 20, 20, RUINS_PLAIN),
+ ("erase", 6680, 4835, 20, 20, RUINS_PLAIN), ("erase", 6720, 4875, 20, 20, RUINS_PLAIN),
+ ("erase", 9400, 3700, 20, 20, RUINS_PLAIN), ("erase", 7660, 4540, 20, 20, RUINS_PLAIN),
+ ("erase", 7780, 4540, 20, 20, RUINS_PLAIN), ("erase", 7900, 4540, 20, 20, RUINS_PLAIN),
+ ("erase", 4950, 4215, 40, 29, RUINS_PLAIN), ("erase", 8300, 4980, 20, 20, RUINS_PLAIN),
+ ("erase", 8660, 5117, 20, 20, RUINS_PLAIN), ("erase", 8260, 5120, 15, 15, RUINS_PLAIN),
+ ("erase", 8493, 5115, 35, 19, RUINS_PLAIN), ("erase", 9364, 3566, 15, 15, RUINS_PLAIN),
+ # Napstablook on the leaves; Toriel at the door; Flowey in the last room's light
+ ("erase", 7524, 4832, 34, 19, LEAVES), ("erase", 10003, 2011, 28, 53, BASEMENT_FLOOR + [(97, 44, 97)]),
+ ("erase", 10007, 204, 27, 27, [(0, 0, 0), (200, 194, 226), (95, 94, 119), (58, 57, 72), (34, 177, 76)]),
]),
]
@@ -32,33 +66,47 @@ ROOMS = [
# Flowey's patch of grass in the dark (the floor is black: all of it is walked on), the purple arch north
dict(name="area1_2", area="ruins", rect=(360, 5560, 320, 340), title="Ruins", margin=0,
floor_colors=[(0, 0, 0)], floor_rects=[(420, 5640, 200, 260), (500, 5560, 40, 80)],
+ fix=[("walk", 500, 5560, 40, 80)], # under the arch
doors=[((420, 5894, 200, 6), "area1", (608, 6030), "down")]),
# the entrance: two staircases, the red leaves, the first SAVE Point
- dict(name="ruins1", area="ruins", rect=(360, 5080, 320, 480), title="Ruins - Entrance"),
+ dict(name="ruins1", area="ruins", rect=(360, 5080, 320, 480), title="Ruins - Entrance", margin=0,
+ floor_rects=[(380, 5280, 280, 280), (480, 5240, 80, 40), (400, 5200, 240, 22), (400, 5222, 80, 80),
+ (560, 5222, 80, 80)],
+ fix=[("walk", 420, 5276, 40, 28), ("walk", 580, 5276, 40, 28)]),
# the middle road puzzle: six switches on the floor and a lever
- dict(name="ruins2", area="ruins", rect=(360, 4840, 320, 240), title="Ruins"),
+ dict(name="ruins2", area="ruins", rect=(360, 4840, 320, 240), title="Ruins",
+ fix=[("walk", 482, 4840, 36, 86)]),
# the switch room, with Toriel's labels; spikes at its end
- dict(name="ruins3", area="ruins", rect=(360, 4600, 720, 240), title="Ruins"),
+ dict(name="ruins3", area="ruins", rect=(360, 4600, 720, 240), title="Ruins", fix=[("walk", 482, 4820, 36, 20)]),
# the training dummy
dict(name="ruins4", area="ruins", rect=(1080, 4600, 320, 240), title="Ruins"),
# the blueprint and the spikes over the water
- dict(name="ruins5", area="ruins", rect=(1100, 4340, 1180, 260), title="Ruins"),
+ dict(name="ruins5", area="ruins", rect=(1100, 4340, 1180, 260), title="Ruins",
+ fix=[("wall", 1940, 4460, 280, 80), ("walk", 2216, 4460, 12, 40), ("walk", 1932, 4500, 12, 40)] + [
+ ("walk", 1940 + 20 * c, 4460 + 20 * r, 20, 20)
+ for r, row in enumerate(["..#####...####", "..#####...####", "####.#######..", "####.#######.."])
+ for c, v in enumerate(row) if v == "#"]),
# the long hallway: the independence test
- dict(name="ruins6", area="ruins", rect=(2280, 4340, 2560, 240), title="Ruins"),
+ dict(name="ruins6", area="ruins", rect=(2280, 4340, 2520, 240), title="Ruins"),
# the leaf pile, its SAVE Point, the first Froggit to talk
- dict(name="ruins7", area="ruins", rect=(4840, 4360, 240, 440), title="Ruins - Leaf Pile"),
+ dict(name="ruins7", area="ruins", rect=(4800, 4360, 280, 440), title="Ruins - Leaf Pile"),
# the Monster Candy
dict(name="ruins7a", area="ruins", rect=(4860, 4100, 200, 260), title="Ruins"),
# the cracked floor and the room under it
- dict(name="ruins8", area="ruins", rect=(5080, 4600, 410, 220), title="Ruins"),
+ dict(name="ruins8", area="ruins", floor_colors=CRACKED, rect=(5080, 4600, 410, 220), title="Ruins",
+ fix=[("walk", 5244, 4704, 72, 56)]),
dict(name="ruins8b", area="ruins", rect=(5140, 5020, 280, 200), title="Ruins"),
# the first rock puzzle
- dict(name="ruins9", area="ruins", rect=(5490, 4600, 420, 220), title="Ruins"),
+ dict(name="ruins9", area="ruins", floor_colors=CRACKED, rect=(5490, 4600, 420, 220), title="Ruins",
+ fix=[("walk", 5676, 4736, 28, 28)]),
# the leaf puzzle: cracked floor above, the way through in leaves below
- dict(name="ruins10", area="ruins", rect=(5910, 4600, 580, 320), title="Ruins"),
+ dict(name="ruins10", area="ruins", floor_colors=CRACKED, rect=(5910, 4600, 580, 320), title="Ruins",
+ fix=[("walk", 6152, 4736, 128, 164), ("walk", 6280, 4778, 188, 122), ("wall", 6280, 4700, 190, 78),
+ ("wall", 5910, 4600, 380, 98)]),
dict(name="ruins10b", area="ruins", rect=(5940, 5020, 540, 300), title="Ruins"),
# the second rock puzzle: the rock that won't move
- dict(name="ruins11", area="ruins", rect=(6490, 4680, 560, 260), title="Ruins"),
+ dict(name="ruins11", area="ruins", floor_colors=CRACKED, rect=(6490, 4680, 560, 260), title="Ruins",
+ fix=[("walk", 6776, y, 28, 28) for y in (4796, 4836, 4876)]),
# the mouse hole, its SAVE Point, the cheese
dict(name="ruins12", area="ruins", rect=(7050, 4720, 380, 200), title="Ruins - Mouse Hole"),
# Napstablook, pretending to sleep
@@ -68,7 +116,8 @@ ROOMS = [
# the Froggits' hall
dict(name="ruins15", area="ruins", rect=(7520, 4400, 540, 300), title="Ruins"),
# the one switch puzzle, and its six rooms under it
- dict(name="ruins16", area="ruins", rect=(8060, 4480, 640, 280), title="Ruins"),
+ dict(name="ruins16", area="ruins", floor_colors=CRACKED, rect=(8060, 4480, 640, 280), title="Ruins",
+ fix=[("walk", x, y, 60, 60) for x in (8320, 8440, 8560) for y in (4560, 4680)]),
dict(name="ruins16a", area="ruins", rect=(8230, 4915, 160, 125), title="Ruins"),
dict(name="ruins16b", area="ruins", rect=(8410, 4915, 140, 125), title="Ruins"),
dict(name="ruins16c", area="ruins", rect=(8550, 4915, 140, 125), title="Ruins"),
@@ -76,27 +125,78 @@ ROOMS = [
dict(name="ruins16e", area="ruins", rect=(8410, 5040, 140, 120), title="Ruins"),
dict(name="ruins16f", area="ruins", rect=(8550, 5040, 140, 120), title="Ruins"),
# the rotating rooms: the same room, turned; and the one a wrong switch drops Frisk in
- dict(name="ruins17a", area="ruins", rect=(8700, 4500, 360, 400), title="Ruins"),
- dict(name="ruins17b", area="ruins", rect=(8720, 4060, 340, 380), title="Ruins"),
- dict(name="ruins17c", area="ruins", rect=(8380, 4000, 340, 440), title="Ruins"),
- dict(name="ruins17d", area="ruins", rect=(8380, 3610, 320, 390), title="Ruins"),
- dict(name="ruins17x", area="ruins", rect=(9140, 4540, 280, 160), title="Ruins"),
+ dict(name="ruins17a", area="ruins", rect=(8700, 4500, 360, 400), title="Ruins",
+ fix=[("walk", 8752, 4620, 36, 40), ("walk", 8960, 4832, 40, 36)],
+ doors=[((8960, 4894, 40, 6), "ruins17b", (8970, 4124), "down")]),
+ dict(name="ruins17b", area="ruins", rect=(8720, 4060, 340, 380), title="Ruins",
+ fix=[("walk", 8962, 4126, 36, 14), ("walk", 8960, 4132, 40, 36)],
+ doors=[((8960, 4126, 40, 6), "ruins17a", (8970, 4858), "up")]),
+ dict(name="ruins17c", area="ruins", rect=(8380, 4000, 340, 440), title="Ruins",
+ fix=[("walk", 8652, 4340, 36, 40)]),
+ dict(name="ruins17d", area="ruins", rect=(8380, 3610, 320, 390), title="Ruins",
+ fix=[("walk", 8440, 3952, 40, 36)]),
+ dict(name="ruins17x", area="ruins", rect=(9140, 4480, 280, 220), title="Ruins"),
# the crossroads, the Froggit who saw Toriel, the balcony over Home
- dict(name="ruins18", area="ruins", rect=(8700, 3460, 590, 370), title="Ruins"),
+ dict(name="ruins18", area="ruins", rect=(8700, 3460, 590, 370), title="Ruins",
+ fix=[("walk", 8846, 3720, 48, 80), ("walk", 9166, 3720, 48, 80)]), # vines on the floor
dict(name="ruins19", area="ruins", rect=(9290, 3620, 250, 200), title="Ruins"),
dict(name="ruins20", area="ruins", rect=(9300, 3360, 360, 260), title="Ruins"),
# Toriel's tree and her door
dict(name="ruins21", area="ruins", rect=(8860, 2920, 320, 540), title="Ruins - Home"),
# Toriel's home
- dict(name="torhouse1", area="ruins", rect=(8860, 2660, 320, 260), title="Home"),
- dict(name="torhouse2", area="ruins", rect=(8540, 2670, 320, 250), title="Home"),
- dict(name="torkitchen", area="ruins", rect=(8540, 2500, 200, 170), title="Home"),
- dict(name="torhouse3", area="ruins", rect=(9180, 2700, 760, 220), title="Home"),
- dict(name="asrielroom", area="ruins", rect=(9200, 2460, 260, 230), title="Home"),
- dict(name="torielroom", area="ruins", rect=(9510, 2430, 280, 260), title="Home"),
+ dict(name="torhouse1", area="ruins", floor_colors=HOUSE_FLOOR, margin=0, rect=(8860, 2660, 320, 260), title="Home",
+ floor_rects=[(8860, 2815, 320, 75), (8900, 2760, 25, 60), (9085, 2740, 80, 80), (8995, 2890, 45, 30)],
+ fix=[("walk", 9062, 2742, 24, 16), ("wall", 9100, 2736, 46, 18)], doors=[((9062, 2742, 14, 16), "basement1", (8952, 2316), "right")]),
+ dict(name="torhouse2", area="ruins", floor_colors=HOUSE_FLOOR, margin=0, rect=(8540, 2670, 320, 250), title="Home",
+ floor_rects=[(8560, 2735, 280, 150), (8585, 2670, 42, 65), (8840, 2800, 20, 85)],
+ fix=[("wall", 8655, 2680, 90, 82), ("wall", 8753, 2690, 60, 62), ("wall", 8815, 2705, 22, 47),
+ ("wall", 8592, 2822, 108, 50), ("wall", 8578, 2830, 16, 24), ("wall", 8700, 2830, 16, 24)]),
+ dict(name="torkitchen", area="ruins", floor_colors=HOUSE_FLOOR, margin=0, rect=(8540, 2500, 200, 170), title="Home",
+ floor_rects=[(8562, 2600, 156, 62), (8587, 2660, 40, 12)]),
+ dict(name="torhouse3", area="ruins", floor_colors=HOUSE_FLOOR, margin=0, rect=(9180, 2700, 760, 220), title="Home",
+ floor_rects=[(9180, 2820, 720, 60)],
+ doors=[((9326, 2814, 28, 8), "asrielroom", (9377, 2630), "up"),
+ ((9536, 2814, 28, 8), "torielroom", (9607, 2630), "up")]),
+ dict(name="asrielroom", area="ruins", floor_colors=HOUSE_FLOOR, margin=0, rect=(9200, 2460, 260, 230), title="Home",
+ floor_rects=[(9240, 2540, 180, 120), (9366, 2655, 42, 30)],
+ fix=[("wall", 9368, 2536, 40, 46), ("wall", 9405, 2540, 16, 40), ("wall", 9394, 2578, 24, 14)],
+ doors=[((9366, 2676, 42, 8), "torhouse3", (9330, 2826), "down")]),
+ dict(name="torielroom", area="ruins", floor_colors=HOUSE_FLOOR, margin=0, rect=(9510, 2430, 280, 260), title="Home",
+ floor_rects=[(9530, 2540, 240, 120), (9597, 2655, 42, 35)],
+ fix=[("wall", 9530, 2536, 66, 56), ("wall", 9540, 2592, 48, 44), ("wall", 9575, 2580, 26, 30),
+ ("wall", 9695, 2605, 28, 36)],
+ doors=[((9597, 2676, 41, 8), "torhouse3", (9540, 2826), "down")]),
# the basement, to the end of the Ruins
- dict(name="basement1", area="ruins", rect=(8860, 2220, 1260, 180), title="Ruins"),
- dict(name="basement2", area="ruins", rect=(9930, 1960, 220, 260), title="Ruins"),
- dict(name="basement3", area="ruins", rect=(9940, 300, 180, 1660), title="Ruins"),
- dict(name="ruinsexit", area="ruins", rect=(9940, 0, 200, 300), title="Ruins - Exit"),
+ dict(name="basement1", area="ruins", floor_colors=BASEMENT_FLOOR, margin=0, rect=(8860, 2220, 1260, 180), title="Ruins",
+ fix=[("walk", 8930, 2320, 20, 40)], doors=[((8930, 2320, 8, 40), "torhouse1", (9084, 2764), "down")]),
+ dict(name="basement2", area="ruins", floor_colors=BASEMENT_FLOOR, margin=0, rect=(9930, 1960, 220, 260), title="Ruins",
+ fix=[("walk", 10000, 2024, 40, 10)], doors=[((10000, 2026, 40, 6), "basement3", (10010, 1914), "up")]),
+ dict(name="basement3", area="ruins", floor_colors=[(97, 44, 97), (132, 53, 125), (0, 0, 0)], margin=0,
+ rect=(9940, 300, 180, 1660), floor_rects=[(9980, 300, 80, 1660)], title="Ruins",
+ fix=[("walk", 10000, 1950, 40, 10)], doors=[((10000, 1956, 40, 4), "basement2", (10010, 2034), "down")]),
+ dict(name="ruinsexit", area="ruins", floor_colors=[(0, 0, 0), (97, 44, 97)], margin=0, rect=(9940, 0, 200, 300),
+ floor_rects=[(9980, 70, 80, 230)], title="Ruins - Exit"),
+]
+
+# rooms one above the other through a dark doorway (tools/pack.py: apply_links)
+LINKS = [
+ ("v", "ruins1", "ruins2", 506, 28, 5175),
+ ("v", "ruins4", "ruins5", 1244, 32, 4640),
+ ("v", "ruins7", "ruins7a", 4946, 28, 4400),
+ ("v", "ruins13", "ruins15", 7580, 34, 4740),
+ ("v", "ruins18", "ruins21", 9006, 30, 3500),
+ ("v", "ruins19", "ruins20", 9468, 24, 3670),
+ ("v", "ruins21", "torhouse1", 9006, 26, 3070),
+ ("v", "ruins17c", "ruins17d", 8444, 32, 4080),
+ # the chutes up from the rooms under the cracked floors
+ ("up", "ruins8b", 5190, 30, 5070, "ruins8", (5167, 4684)),
+ ("up", "ruins8b", 5350, 30, 5070, "ruins8", (5407, 4684)),
+ ("up", "ruins10b", 6066, 30, 5070, "ruins10", (6066, 4690)),
+ ("up", "ruins16a", 8263, 12, 4945, "ruins16", (8200, 4546)),
+ ("up", "ruins16b", 8503, 12, 4945, "ruins16", (8440, 4546)),
+ ("up", "ruins16c", 8643, 12, 4945, "ruins16", (8580, 4546)),
+ ("up", "ruins16d", 8263, 12, 5065, "ruins16", (8200, 4546)),
+ ("up", "ruins16e", 8503, 12, 5065, "ruins16", (8440, 4546)),
+ ("up", "ruins16f", 8643, 12, 5065, "ruins16", (8580, 4546)),
+ ("up", "ruins17x", 9268, 26, 4510, "ruins17a", (8790, 4606)),
]
diff --git a/games/undertale/tools/sprites.py b/games/undertale/tools/sprites.py
index 78e27a63..56f5de8c 100644
--- a/games/undertale/tools/sprites.py
+++ b/games/undertale/tools/sprites.py
@@ -58,6 +58,22 @@ SPRITES = [
("toriel_away", "wiki:Toriel_battle_shocked.png", {"feet": True}),
("toriel_fight", "wiki:Toriel_battle_in_fight.png", {"feet": True}),
("toriel_dead", "wiki:Toriel_battle_fatal_Neutral.png", {"feet": True}),
+] + [
+ # the Ruins' things, from the demo (their top-left at their origin, as the game places them)
+ (n.replace("spr_", "o_"), "demo:" + n, {"keep": True}) for n in [
+ "spr_ruinsdoor1", "spr_switch", "spr_groundswitch1", "spr_spiketile", "spr_rock", "spr_colorswitch",
+ "spr_faceswitch", "spr_dummy", "spr_exc", "spr_floweygrow", "spr_floweyshrink", "spr_floweysink",
+ "spr_floweylaughoverworld", "spr_toriel_handhold_d", "spr_toriel_handhold_u", "spr_toriel_handhold_l",
+ "spr_toriel_handhold_r", "spr_hole", "spr_smallweb", "spr_bigweb", "spr_napstablook_gr", "spr_napstablook_grsm",
+ "spr_napstablook_l", "spr_chairempty", "spr_chairiel", "spr_chairielgetup", "spr_candydish", "spr_candydish2",
+ "spr_candydish_bad", "spr_cheesetable", "spr_mousehole", "spr_npc_d", "spr_npc_u", "spr_npc_l", "spr_npc_r",
+ "spr_pillar", "spr_pieslice", "spr_bigpie", "spr_vegetableoutside", "spr_smallfrog", "spr_ribbon",
+ "spr_groundknife", "spr_torielflame", "spr_winkstar", "spr_tornote", "spr_diningtable", "spr_nastytree",
+ "spr_toriel_d_phone", "spr_toriel_dt", "spr_toriel_ut", "spr_toriel_lt", "spr_toriel_rt", "spr_toriel_hug",
+ "spr_toriel_ruffle"]
+] + [
+ ("frog_ow", "wiki:Froggit_overworld.png", {"keep": True}),
+ ("napsta_ow", "wiki:Napstablook_overworld.png", {"keep": True}),
] + [
# the intro's pictures, the title, GAME OVER
("introimage", "demo:spr_introimage", {"keep": True, "clear_black": True}),