Files

164 lines
5.6 KiB
C

#include "game.h"
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;
int choose_partner(int member)
{
if (!partner_owned || battle.phase != BATTLE_OFF || member < 0 || member > caught_count)
return 0;
active_member = member;
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";
}
}
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"},
{"THAT GOLDEN CREATURE IS FRIENDLY", "WALK OVER AND SAY HELLO"}
};
enum { STORY_DIALOGUE_PAGES = sizeof(dialogue) / sizeof(dialogue[0]) };
#ifdef GAME_TEST
const int DIALOGUE_PAGES = STORY_DIALOGUE_PAGES;
#endif
#define DIALOGUE_PAGES STORY_DIALOGUE_PAGES
TEST_INTERNAL const char *const professor_dialogue[DIALOGUE_PAGES][2] = {
{"I HAVE A PARTNER FOR YOU", "MEET SPROUT A GRASS TYPE"},
{"YOU RECEIVED SPROUT", "TAKE GOOD CARE OF YOUR NEW FRIEND"}
};
TEST_INTERNAL const char *const professor_followup[DIALOGUE_PAGES][2] = {
{"HOW IS SPROUT DOING", "OPEN YOUR TEAM WITH SELECT"},
{"EXPLORE SUNPETAL TRAIL TOGETHER", "I AM GLAD YOU ARE FRIENDS"}
};
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", "PRESS SELECT IN BATTLE TO THROW"}
};
TEST_INTERNAL const char *const ranger_followup[DIALOGUE_PAGES][2] = {
{"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;
if (current_room == MELLON_HOUSE)
return x >= PROF_X - 24 && x <= PROF_X + 24 &&
y >= PROF_Y - 22 && y <= PROF_Y + 22;
return current_room == OUTSIDE && x >= NPC_X - 24 && x <= NPC_X + 24 &&
y >= NPC_Y - 20 && y <= NPC_Y + 20;
}
TEST_INTERNAL int next_dialogue_page(int page)
{
return page + 1 < DIALOGUE_PAGES ? page + 1 : -1;
}
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;
}
TEST_INTERNAL int receive_partner(void)
{
if (current_room != MELLON_HOUSE || !gift_conversation || partner_owned) return 0;
partner_owned = 1;
reset_follower(PROF_X, PROF_Y + 22);
return 1;
}
TEST_INTERNAL int receive_balls(void)
{
if (current_room != ROUTE || !ball_gift_conversation || balls_given) return 0;
ball_count += 5;
if (ball_count > 99) ball_count = 99;
balls_given = 1;
return 1;
}
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;
}
if (next < 0) rod_gift_conversation = 0;
if (next < 0) gift_conversation = ball_gift_conversation = 0;
return next;
}
void dialogue_box(int page)
{
u16 ink = RGB(5, 8, 11);
rectangle(DIALOGUE_X, DIALOGUE_Y, DIALOGUE_W, DIALOGUE_H, ink);
rectangle(9, 97, 222, 42, RGB(15, 20, 21));
rectangle(11, 99, 218, 38, RGB(30, 30, 26));
rectangle(12, 100, 216, 1, RGB(31, 31, 30));
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] = 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, 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);
}