Add music, beach fishing, catching, and selectable creature partners

This commit is contained in:
rory committed 2026-10-28 22:22:27 +00:00
1 parent 3469f2e6dd
commit cb77683a87
24 files changed
+1307 -104

No files matched your search

+106 -14
View File
@@ -3,6 +3,11 @@
int partner_owned = 0;
TEST_INTERNAL int gift_conversation = 0;
int ball_count = 0, balls_given = 0;
int rod_owned;
static int rod_gift_conversation;
int caught_count;
int active_member;
unsigned char caught_species[CAUGHT_CAPACITY];
TEST_INTERNAL int ball_gift_conversation = 0;
/* mGBA detects this marker and provides cartridge SRAM for the gift record. */
@@ -13,7 +18,10 @@ static const char save_signature[] __attribute__((used)) = "SRAM_V113";
void load_progress(void)
{
partner_owned = ball_count = balls_given = 0;
partner_owned = ball_count = balls_given = caught_count = 0;
rod_owned = 0;
active_member = 0;
for (int i = 0; i < CAUGHT_CAPACITY; ++i) caught_species[i] = 0xff;
if (SAVE_MEMORY[0] != 'F' || SAVE_MEMORY[1] != 'Q' ||
SAVE_MEMORY[2] != 'S' || SAVE_MEMORY[3] != 'P') return;
/* Keep Sprout from the original version-one save format. */
@@ -22,30 +30,95 @@ void load_progress(void)
return;
}
unsigned flags = SAVE_MEMORY[5], count = SAVE_MEMORY[6];
if (SAVE_MEMORY[4] != 2 || flags > 3 || count > 99 ||
(!(flags & 2) && count != 0) || SAVE_MEMORY[8] != 0x5a ||
SAVE_MEMORY[7] != (0xa5 ^ 2 ^ flags ^ count)) return;
unsigned version = SAVE_MEMORY[4];
if (flags > (version == 5 ? 47u : version == 4 ? 7u : 3u) || count > 99 || (!(flags & 2) && count != 0)) return;
if (SAVE_MEMORY[4] == 2) {
if (SAVE_MEMORY[8] != 0x5a || SAVE_MEMORY[7] != (0xa5 ^ 2 ^ flags ^ count)) return;
} else if (version == 3 || version == 4 || version == 5) {
unsigned members = SAVE_MEMORY[7];
if (members > CAUGHT_CAPACITY || (members && !(flags & 1)) || SAVE_MEMORY[14] != 0x5a)
return;
if (version == 5 && ((flags >> 3) > members || ((flags >> 3) && !(flags & 1)))) return;
unsigned checksum = 0xa5 ^ version ^ flags ^ count ^ members;
for (unsigned i = 0; i < CAUGHT_CAPACITY; ++i) {
unsigned kind = SAVE_MEMORY[8 + i];
if (i < members ? kind >= SPECIES_COUNT : kind != 0xff) return;
checksum ^= kind;
}
if (SAVE_MEMORY[13] != checksum) return;
caught_count = (int)members;
for (int i = 0; i < caught_count; ++i) caught_species[i] = SAVE_MEMORY[8 + i];
} else {
return;
}
partner_owned = !!(flags & 1);
balls_given = !!(flags & 2);
rod_owned = !!(flags & 4);
ball_count = (int)count;
active_member = version == 5 ? (int)(flags >> 3) : 0;
}
static void save_progress(void)
int choose_partner(int member)
{
unsigned flags = (partner_owned ? 1u : 0u) | (balls_given ? 2u : 0u);
if (!partner_owned || battle.phase != BATTLE_OFF || member < 0 || member > caught_count)
return 0;
active_member = member;
save_progress();
return 1;
}
const char *partner_name(void)
{
return active_member ? species[caught_species[active_member - 1]].name : "SPROUT";
}
int partner_hp(void)
{
return active_member ? species[caught_species[active_member - 1]].hp : SPROUT_HP;
}
const char *partner_move(void)
{
if (!active_member) return "LEAF TAP";
switch (caught_species[active_member - 1]) {
case GOLDEN: return "BUMP";
case FERNFOX: return "LEAF TAP";
case EMBERWING: return "SPARK";
case PEBBLIT: return "ROLL";
default: return "WATER JET";
}
}
void save_progress(void)
{
unsigned flags = (partner_owned ? 1u : 0u) | (balls_given ? 2u : 0u) | (rod_owned ? 4u : 0u) | ((unsigned)active_member << 3);
unsigned checksum = 0xa5 ^ 5 ^ flags ^ (unsigned)ball_count ^ (unsigned)caught_count;
/* Commit the first magic byte last so an interrupted write is invalid. */
SAVE_MEMORY[0] = 0;
SAVE_MEMORY[1] = 'Q';
SAVE_MEMORY[2] = 'S';
SAVE_MEMORY[3] = 'P';
SAVE_MEMORY[4] = 2;
SAVE_MEMORY[4] = 5;
SAVE_MEMORY[5] = (unsigned char)flags;
SAVE_MEMORY[6] = (unsigned char)ball_count;
SAVE_MEMORY[7] = (unsigned char)(0xa5 ^ 2 ^ flags ^ (unsigned)ball_count);
SAVE_MEMORY[8] = 0x5a;
SAVE_MEMORY[7] = (unsigned char)caught_count;
for (int i = 0; i < CAUGHT_CAPACITY; ++i) {
unsigned kind = i < caught_count ? caught_species[i] : 0xff;
SAVE_MEMORY[8 + i] = (unsigned char)kind;
checksum ^= kind;
}
SAVE_MEMORY[13] = (unsigned char)checksum;
SAVE_MEMORY[14] = 0x5a;
SAVE_MEMORY[0] = 'F';
}
int has_caught(enum Species kind)
{
for (int i = 0; i < caught_count; ++i)
if (caught_species[i] == (unsigned)kind) return 1;
return 0;
}
/* Change these lines to write Mila's conversation! Use CAPITAL letters. */
TEST_INTERNAL const char *const dialogue[][2] = {
{"HELLO I AM MILA", "WELCOME TO OUR VILLAGE"},
@@ -66,15 +139,27 @@ TEST_INTERNAL const char *const professor_followup[DIALOGUE_PAGES][2] = {
};
TEST_INTERNAL const char *const ranger_dialogue[DIALOGUE_PAGES][2] = {
{"HI I AM RANGER FINN", "HERE ARE FIVE POKE BALLS FOR YOU"},
{"YOU RECEIVED FIVE POKE BALLS", "KEEP THEM SAFE FOR YOUR ADVENTURE"}
{"YOU RECEIVED FIVE POKE BALLS", "PRESS SELECT IN BATTLE TO THROW"}
};
TEST_INTERNAL const char *const ranger_followup[DIALOGUE_PAGES][2] = {
{"YOUR POKE BALLS ARE IN YOUR BAG", "OPEN YOUR TEAM WITH SELECT TO LOOK"},
{"ENJOY EXPLORING SUNPETAL TRAIL", "TAKE GOOD CARE OF YOUR PARTNER"}
{"WEAKEN WILD CREATURES FIRST", "LOW HEALTH MAKES CATCHING EASIER"},
{"OPEN YOUR TEAM WITH SELECT", "USE ARROWS TO SEE YOUR NEW FRIENDS"}
};
static const char *const fisher_dialogue[2][2] = {
{"HI I AM FISHER CORAL", "TAKE THIS POKE ROD FOR FISHING"},
{"YOU RECEIVED A POKE ROD", "FACE THE SEA AND PRESS A"}
};
static const char *const fisher_followup[2][2] = {
{"FACE THE SEA AND PRESS A", "BRING SPROUT TO BATTLE TIDEFIN"},
{"WEAKEN IT THEN THROW A BALL", "PRESS SELECT TO CATCH YOUR FISH"}
};
int near_npc(int x, int y)
{
if (current_room == BEACH)
return x >= FISHER_X - 18 && x <= FISHER_X + 18 &&
y >= FISHER_Y - 18 && y <= FISHER_Y + 12;
if (current_room == ROUTE)
return x >= RANGER_X - 24 && x <= RANGER_X + 24 &&
y >= RANGER_Y - 22 && y <= RANGER_Y + 22;
@@ -95,6 +180,7 @@ int begin_conversation(int x, int y)
if (!near_npc(x, y)) return 0;
gift_conversation = current_room == MELLON_HOUSE && !partner_owned;
ball_gift_conversation = current_room == ROUTE && !balls_given;
rod_gift_conversation = current_room == BEACH && !rod_owned;
return 1;
}
@@ -122,6 +208,11 @@ int advance_conversation(int page)
int next = next_dialogue_page(page);
if (next == 1 && gift_conversation) receive_partner();
if (next == 1 && ball_gift_conversation) receive_balls();
if (next == 1 && rod_gift_conversation && current_room == BEACH && !rod_owned) {
rod_owned = 1;
save_progress();
}
if (next < 0) rod_gift_conversation = 0;
if (next < 0) gift_conversation = ball_gift_conversation = 0;
return next;
}
@@ -136,10 +227,11 @@ void dialogue_box(int page)
rectangle(16, 110, 208, 1, RGB(23, 26, 22));
int professor = current_room == MELLON_HOUSE;
int ranger = current_room == ROUTE;
const char *const (*lines)[2] = ranger ?
const char *const (*lines)[2] = current_room == BEACH ?
(rod_gift_conversation ? fisher_dialogue : fisher_followup) : ranger ?
(ball_gift_conversation ? ranger_dialogue : ranger_followup) : professor ?
(gift_conversation ? professor_dialogue : professor_followup) : dialogue;
large_text(16, 102, ranger ? "RANGER FINN" : professor ? "PROF MELLON" : "MILA", RGB(7, 16, 12));
large_text(16, 102, current_room == BEACH ? "FISHER CORAL" : ranger ? "RANGER FINN" : professor ? "PROF MELLON" : "MILA", RGB(7, 16, 12));
text(192, 103, page == DIALOGUE_PAGES - 1 ? "A CLOSE" : "A NEXT", ink);
large_text(16, 115, lines[page][0], ink);
large_text(16, 127, lines[page][1], ink);