Add music, beach fishing, catching, and selectable creature partners
This commit is contained in:
1 parent
3469f2e6dd
commit
cb77683a87
24 files changed
+1307
-104
No files matched your search
@@ -0,0 +1,145 @@
|
||||
#include "test_support.h"
|
||||
#include "../source/audio.h"
|
||||
|
||||
static unsigned step_time(enum MusicTrack track, unsigned step)
|
||||
{
|
||||
unsigned numerator = step * MOVEMENT_CLOCK_HZ * 60u;
|
||||
unsigned denominator = music_songs[track].bpm * 4u;
|
||||
return (numerator + denominator - 1) / denominator;
|
||||
}
|
||||
|
||||
static void assert_sound_ranges(void)
|
||||
{
|
||||
assert(music_state.step >= 0 && music_state.step < 64);
|
||||
assert((music_registers[SOUND_LEAD_FREQ] & 0x7fff) < 2048);
|
||||
assert((music_registers[SOUND_BASS_FREQ] & 0x7fff) < 2048);
|
||||
assert((music_registers[SOUND_LEAD_ENV] >> 12) <= 6);
|
||||
assert((music_registers[SOUND_BASS_ENV] >> 12) <= 3);
|
||||
assert((music_registers[SOUND_NOISE_ENV] >> 12) <= 2);
|
||||
}
|
||||
|
||||
void check_music(void)
|
||||
{
|
||||
for (unsigned note = 48; note <= 84; ++note) {
|
||||
assert(music_frequency(note) > 0 && music_frequency(note) < 2048);
|
||||
if (note > 48) assert(music_frequency(note) > music_frequency(note - 1));
|
||||
}
|
||||
assert(music_frequency(0) == 0 && music_frequency(255) == 0);
|
||||
for (int track = MUSIC_VILLAGE; track < MUSIC_TRACK_COUNT; ++track) {
|
||||
const struct MusicSong *song = &music_songs[track];
|
||||
assert(song->bpm >= 60 && song->bpm <= 180);
|
||||
for (int step = 0; step < 64; ++step) {
|
||||
unsigned note = song->lead[step];
|
||||
assert(note == 0 || note == 255 || (note >= 48 && note <= 84));
|
||||
}
|
||||
for (int step = 0; step < 16; ++step)
|
||||
assert(song->bass[step] >= 48 && song->bass[step] <= 84);
|
||||
}
|
||||
assert(music_choose_track(OUTSIDE, BATTLE_OFF) == MUSIC_VILLAGE);
|
||||
assert(music_choose_track(MELLON_GARDEN, BATTLE_OFF) == MUSIC_VILLAGE);
|
||||
assert(music_choose_track(ROUTE, BATTLE_OFF) == MUSIC_TRAIL);
|
||||
assert(music_choose_track(COTTAGE, BATTLE_OFF) == MUSIC_TRAIL);
|
||||
assert(music_choose_track(MELLON_HOUSE, BATTLE_OFF) == MUSIC_TRAIL);
|
||||
assert(music_choose_track(BEACH, BATTLE_OFF) == MUSIC_TRAIL);
|
||||
for (int phase = BATTLE_TURN; phase <= BATTLE_CAUGHT; ++phase)
|
||||
assert(music_choose_track(ROUTE, (enum BattlePhase)phase) == MUSIC_BATTLE);
|
||||
|
||||
current_room = OUTSIDE;
|
||||
battle.phase = BATTLE_OFF;
|
||||
music_init(0);
|
||||
assert(music_registers[SOUND_MASTER] == 0x80);
|
||||
assert(music_registers[SOUND_MIX] == 0xbb77 && music_registers[SOUND_RATIO] == 1);
|
||||
assert(music_registers[SOUND_SWEEP] == 8);
|
||||
assert(music_state.track == MUSIC_VILLAGE && !music_state.muted);
|
||||
unsigned writes = music_write_count;
|
||||
music_update(0);
|
||||
music_update(step_time(MUSIC_VILLAGE, 1) - 1);
|
||||
assert(music_state.step == 0 && music_write_count == writes);
|
||||
music_update(step_time(MUSIC_VILLAGE, 1));
|
||||
assert(music_state.step == 1 && music_write_count == writes); /* Tie: no retrigger. */
|
||||
u16 first_pitch = music_registers[SOUND_LEAD_FREQ];
|
||||
music_update(step_time(MUSIC_VILLAGE, 2));
|
||||
assert(music_state.step == 2 && music_registers[SOUND_LEAD_FREQ] != first_pitch);
|
||||
|
||||
/* Songs keep the same tempo at different rendering/update frequencies. */
|
||||
const int rates[] = {15, 30, 60, 120};
|
||||
for (int track = MUSIC_VILLAGE; track < MUSIC_TRACK_COUNT; ++track) {
|
||||
current_room = track == MUSIC_TRAIL ? ROUTE : OUTSIDE;
|
||||
battle.phase = track == MUSIC_BATTLE ? BATTLE_TURN : BATTLE_OFF;
|
||||
for (unsigned rate = 0; rate < sizeof(rates) / sizeof(rates[0]); ++rate) {
|
||||
music_init(0);
|
||||
for (int frame = 1; frame <= rates[rate] * 12; ++frame) {
|
||||
music_update((unsigned)(frame * MOVEMENT_CLOCK_HZ / rates[rate]));
|
||||
assert_sound_ranges();
|
||||
}
|
||||
unsigned steps = 12 * music_songs[track].bpm * 4u / 60u;
|
||||
unsigned remainder = (12 * MOVEMENT_CLOCK_HZ * music_songs[track].bpm * 4u) %
|
||||
(MOVEMENT_CLOCK_HZ * 60u);
|
||||
assert(music_state.track == (enum MusicTrack)track);
|
||||
assert(music_state.step == (int)(steps % 64) && music_state.phase == remainder);
|
||||
}
|
||||
}
|
||||
|
||||
/* Scene changes select a tune; overlays and same-theme maps keep the phrase. */
|
||||
current_room = OUTSIDE;
|
||||
battle.phase = BATTLE_OFF;
|
||||
music_init(0);
|
||||
music_update(step_time(MUSIC_VILLAGE, 5));
|
||||
int step = music_state.step;
|
||||
current_room = MELLON_GARDEN;
|
||||
music_update(music_state.last);
|
||||
assert(music_state.track == MUSIC_VILLAGE && music_state.step == step);
|
||||
current_room = ROUTE;
|
||||
music_update(music_state.last);
|
||||
assert(music_state.track == MUSIC_TRAIL && music_state.step == 0);
|
||||
battle.phase = BATTLE_TURN;
|
||||
music_update(music_state.last);
|
||||
assert(music_state.track == MUSIC_BATTLE && music_state.step == 0);
|
||||
battle.phase = BATTLE_WON;
|
||||
music_update(music_state.last);
|
||||
assert(music_state.track == MUSIC_BATTLE);
|
||||
battle.phase = BATTLE_OFF;
|
||||
music_update(music_state.last);
|
||||
assert(music_state.track == MUSIC_TRAIL && music_state.step == 0);
|
||||
|
||||
/* Muting stops all voices, stays muted across maps, and resumes on ties. */
|
||||
music_toggle_mute();
|
||||
assert(music_state.muted && music_registers[SOUND_MIX] == 0);
|
||||
assert(music_registers[SOUND_LEAD_ENV] == 0 && music_registers[SOUND_BASS_ENV] == 0);
|
||||
assert(music_registers[SOUND_NOISE_ENV] == 0);
|
||||
writes = music_write_count;
|
||||
current_room = OUTSIDE;
|
||||
music_update(music_state.last);
|
||||
unsigned start = music_state.last;
|
||||
music_update(start + step_time(MUSIC_VILLAGE, 1));
|
||||
assert(music_state.step == 1 && music_write_count == writes);
|
||||
music_toggle_mute();
|
||||
assert(!music_state.muted && music_registers[SOUND_MIX] == 0xbb77);
|
||||
assert(music_registers[SOUND_LEAD_ENV] != 0 && music_registers[SOUND_BASS_ENV] != 0);
|
||||
assert((music_registers[SOUND_LEAD_FREQ] & 2047) == music_frequency(72));
|
||||
|
||||
music_init(0);
|
||||
for (unsigned index = 1; index <= 63; ++index) music_update(step_time(MUSIC_VILLAGE, index));
|
||||
assert(music_state.step == 63 && music_registers[SOUND_LEAD_ENV] == 0); /* Rest. */
|
||||
music_update(step_time(MUSIC_VILLAGE, 64));
|
||||
assert(music_state.step == 0 && music_registers[SOUND_LEAD_ENV] != 0); /* Loop. */
|
||||
music_init(0xffffff00u);
|
||||
music_update(0x00001000u);
|
||||
assert(music_state.step == 1); /* 32-bit hardware-clock rollover. */
|
||||
writes = music_write_count;
|
||||
music_update(music_state.last + MOVEMENT_CLOCK_HZ * 60u);
|
||||
assert(music_write_count - writes <= 6); /* No missed-note replay loop. */
|
||||
assert_sound_ranges();
|
||||
|
||||
/* The sequencer does not consume movement time or change game/save state. */
|
||||
pause_movement_at(0);
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
music_update(music_state.last + 100);
|
||||
assert(movement_ticks_at(MOVEMENT_CLOCK_HZ) == MAX_MOVEMENT_TICKS);
|
||||
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
|
||||
current_room = OUTSIDE;
|
||||
battle.phase = BATTLE_OFF;
|
||||
music_init(0);
|
||||
puts("Music: 3 original tunes, stable tempo, scene switching, mute, ties, loops, and clock checks passed");
|
||||
}
|
||||
+4
-4
@@ -5,7 +5,7 @@ void check_following_and_battle(void)
|
||||
static u16 expected[WIDTH * HEIGHT], visible[WIDTH * HEIGHT];
|
||||
static const unsigned directions[] = {RIGHT, DOWN, LEFT, UP};
|
||||
partner_owned = 1;
|
||||
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
|
||||
for (int room = OUTSIDE; room <= BEACH; ++room) {
|
||||
current_room = (enum Room)room;
|
||||
int x, y;
|
||||
reset_position(&x, &y);
|
||||
@@ -78,7 +78,7 @@ void check_following_and_battle(void)
|
||||
write_preview("build/battle-preview.ppm");
|
||||
copy_pending_rows(visible);
|
||||
assert(!battle_input(0));
|
||||
assert(!battle_input(SELECT));
|
||||
assert(battle_input(SELECT) && battle.notice == NOTICE_NO_BALLS);
|
||||
assert(battle.turns == 0);
|
||||
assert(battle_input(RIGHT));
|
||||
assert(battle.move == 1 && battle.enemy_hp == GOLDEN_HP);
|
||||
@@ -126,7 +126,7 @@ void check_following_and_battle(void)
|
||||
|
||||
void check_wild_encounters(void)
|
||||
{
|
||||
for (int kind = 0; kind < 3; ++kind) {
|
||||
for (int kind = 0; kind < 4; ++kind) {
|
||||
int opaque = 0;
|
||||
for (int row = 0; row < 24; ++row) {
|
||||
assert(strlen(wild_art[kind].rows[row]) == 24);
|
||||
@@ -137,7 +137,7 @@ void check_wild_encounters(void)
|
||||
++opaque;
|
||||
}
|
||||
}
|
||||
assert(opaque > 180); /* Full original sprites, not palette swaps. */
|
||||
assert(opaque > (kind == TIDEFIN - FERNFOX ? 100 : 180)); /* Fish has a slimmer silhouette. */
|
||||
}
|
||||
partner_owned = 1;
|
||||
current_room = OUTSIDE;
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
#include "test_support.h"
|
||||
|
||||
void check_partner_selection(void)
|
||||
{
|
||||
static u16 expected[WIDTH * HEIGHT], visible[WIDTH * HEIGHT];
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
load_progress();
|
||||
battle.phase = BATTLE_OFF;
|
||||
assert(!choose_partner(0));
|
||||
partner_owned = balls_given = rod_owned = 1;
|
||||
ball_count = 5;
|
||||
caught_count = CAUGHT_CAPACITY;
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i) caught_species[i] = (unsigned char)i;
|
||||
assert(!choose_partner(-1) && !choose_partner(6));
|
||||
for (int member = 0; member <= caught_count; ++member) {
|
||||
assert(choose_partner(member));
|
||||
load_progress();
|
||||
assert(active_member == member && rod_owned && ball_count == 5);
|
||||
assert(strcmp(partner_name(), member ? species[member - 1].name : "SPROUT") == 0);
|
||||
assert(partner_hp() == (member ? species[member - 1].hp : SPROUT_HP));
|
||||
for (int room = OUTSIDE; room <= BEACH; ++room) {
|
||||
current_room = (enum Room)room;
|
||||
int x, y;
|
||||
reset_position(&x, &y);
|
||||
if (current_room == ROUTE) { y = 94; reset_follower(x, y); }
|
||||
for (int step = 0; step < 20; ++step) {
|
||||
render_scene(x, y);
|
||||
copy_pending_rows(visible);
|
||||
int old_x = x, old_y = y, fx = follower_x, fy = follower_y;
|
||||
walk_movement(RIGHT, &x, &y, 1);
|
||||
restore(old_x - 8, old_y - 20, 17, 24);
|
||||
restore(fx - 8, fy - 20, 17, 24);
|
||||
actors(x, y, 0);
|
||||
location_status(x, y);
|
||||
copy_pending_rows(visible);
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
render_scene(x, y);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
}
|
||||
}
|
||||
assert(start_battle(TIDEFIN));
|
||||
assert(battle.sprout_hp == partner_hp());
|
||||
assert(!choose_partner(0)); /* No changing partners mid-turn. */
|
||||
draw_battle();
|
||||
if (member == 3) write_preview("build/emberwing-partner-preview.ppm");
|
||||
assert(battle_input(RIGHT));
|
||||
assert(battle_input(A) && battle.enemy_hp < species[TIDEFIN].hp);
|
||||
assert(battle.sprout_hp == partner_hp() - species[TIDEFIN].attack);
|
||||
assert(battle_input(B) && battle_input(A));
|
||||
assert(start_battle(GOLDEN) && battle.sprout_hp == partner_hp());
|
||||
assert(battle_input(B) && battle_input(A));
|
||||
}
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
/* Reject an out-of-range selection even with a correct checksum. */
|
||||
test_save[5] ^= (5 ^ 6) << 3;
|
||||
test_save[13] ^= (5 ^ 6) << 3;
|
||||
load_progress();
|
||||
assert(!partner_owned && active_member == 0);
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
test_save[4] = 4;
|
||||
test_save[5] &= 7;
|
||||
test_save[13] ^= 5 ^ 4 ^ (5 << 3);
|
||||
load_progress();
|
||||
assert(partner_owned && rod_owned && caught_count == 5 && active_member == 0);
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
load_progress();
|
||||
current_room = OUTSIDE;
|
||||
follower_ready = 0;
|
||||
puts("Partners: selection, saving, old saves, follower redraws, moves and battle recovery passed");
|
||||
}
|
||||
|
||||
void check_fishing(void)
|
||||
{
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
load_progress();
|
||||
battle.phase = BATTLE_OFF;
|
||||
current_room = BEACH;
|
||||
player_facing = FACING_DOWN;
|
||||
int x = 120, y = beach_shoreline(120) - 5;
|
||||
assert(near_water(x, y) && !cast_rod(x, y));
|
||||
assert(!begin_conversation(x, y));
|
||||
assert(begin_conversation(FISHER_X - 14, FISHER_Y));
|
||||
assert(!rod_owned);
|
||||
assert(advance_conversation(0) == 1 && rod_owned);
|
||||
assert(test_save[4] == 5);
|
||||
dialogue_box(1);
|
||||
write_preview("build/rod-gift-preview.ppm");
|
||||
assert(advance_conversation(1) == -1);
|
||||
load_progress();
|
||||
assert(rod_owned && !partner_owned);
|
||||
assert(!cast_rod(x, y));
|
||||
assert(begin_conversation(FISHER_X, FISHER_Y));
|
||||
unsigned char before[sizeof(test_save)];
|
||||
memcpy(before, test_save, sizeof(before));
|
||||
assert(advance_conversation(0) == 1 && advance_conversation(1) == -1);
|
||||
assert(memcmp(before, test_save, sizeof(before)) == 0);
|
||||
partner_owned = balls_given = 1;
|
||||
ball_count = 5;
|
||||
for (int facing = FACING_UP; facing <= FACING_RIGHT; ++facing) {
|
||||
player_facing = (enum Facing)facing;
|
||||
assert(!cast_rod(x, y));
|
||||
}
|
||||
player_facing = FACING_DOWN;
|
||||
assert(!cast_rod(x, 75));
|
||||
current_room = ROUTE;
|
||||
assert(!cast_rod(x, y));
|
||||
current_room = BEACH;
|
||||
assert(cast_rod(x, y) && battle.enemy == TIDEFIN);
|
||||
assert(!cast_rod(x, y));
|
||||
draw_battle();
|
||||
write_preview("build/fishing-battle-preview.ppm");
|
||||
battle.enemy_hp = 1;
|
||||
assert(battle_input(SELECT) && battle.phase == BATTLE_CAUGHT);
|
||||
assert(ball_count == 4 && has_caught(TIDEFIN));
|
||||
assert(battle_input(A));
|
||||
load_progress();
|
||||
assert(rod_owned && has_caught(TIDEFIN) && ball_count == 4);
|
||||
draw_team_member(1);
|
||||
write_preview("build/tidefin-team-preview.ppm");
|
||||
assert(cast_rod(x, y));
|
||||
assert(battle_input(B) && battle_input(A));
|
||||
/* An old save keeps catches and balls without granting a rod. */
|
||||
test_save[4] = 3;
|
||||
test_save[5] &= (unsigned char)~4;
|
||||
test_save[13] ^= 5 ^ 3 ^ 4;
|
||||
load_progress();
|
||||
assert(!rod_owned && has_caught(TIDEFIN) && ball_count == 4);
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
load_progress();
|
||||
current_room = OUTSIDE;
|
||||
follower_ready = 0;
|
||||
puts("Fishing: rod gift, save migration, shoreline use, water battles and catches passed");
|
||||
}
|
||||
|
||||
void check_catching(void)
|
||||
{
|
||||
const unsigned char old_save[] = {'F','Q','S','P',2,3,5,0xa1,0x5a};
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
memcpy(test_save, old_save, sizeof(old_save));
|
||||
load_progress();
|
||||
assert(partner_owned && balls_given && ball_count == 5 && caught_count == 0);
|
||||
assert(test_save[4] == 2); /* Preserve an existing save until an action writes it. */
|
||||
current_room = ROUTE;
|
||||
assert(start_battle(FERNFOX));
|
||||
ball_count = 0;
|
||||
unsigned rng = random_state;
|
||||
unsigned char before[sizeof(test_save)];
|
||||
memcpy(before, test_save, sizeof(before));
|
||||
assert(battle_input(SELECT) && battle.notice == NOTICE_NO_BALLS);
|
||||
assert(battle.phase == BATTLE_TURN && battle.turns == 0 && battle.sprout_hp == SPROUT_HP);
|
||||
assert(random_state == rng && memcmp(before, test_save, sizeof(before)) == 0);
|
||||
|
||||
ball_count = 5;
|
||||
random_state = 1; /* Full-health roll 69 fails the 35% catch chance. */
|
||||
draw_battle();
|
||||
static u16 visible[WIDTH * HEIGHT], expected[WIDTH * HEIGHT];
|
||||
copy_pending_rows(visible);
|
||||
assert(battle_input(SELECT));
|
||||
assert(ball_count == 4 && caught_count == 0 && battle.turns == 1);
|
||||
assert(battle.notice == NOTICE_BROKE_FREE && battle.sprout_hp == 20);
|
||||
assert(test_save[4] == 5 && test_save[6] == 4);
|
||||
assert(!battle_input(0) && ball_count == 4); /* Holding Select cannot throw twice. */
|
||||
draw_battle_hud();
|
||||
assert(pending_pixels() < 16500);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
write_preview("build/catch-failed-preview.ppm");
|
||||
load_progress();
|
||||
assert(partner_owned && ball_count == 4 && caught_count == 0);
|
||||
|
||||
assert(battle_input(RIGHT));
|
||||
assert(battle_input(A) && battle.enemy_hp == 11);
|
||||
assert(battle_input(A) && battle.enemy_hp == 4);
|
||||
int hp = battle.sprout_hp;
|
||||
draw_battle_hud();
|
||||
copy_pending_rows(visible);
|
||||
assert(battle_input(SELECT)); /* Quarter health is a guaranteed catch. */
|
||||
assert(battle.phase == BATTLE_CAUGHT && battle.sprout_hp == hp);
|
||||
assert(ball_count == 3 && caught_count == 1 && caught_species[0] == FERNFOX);
|
||||
assert(has_caught(FERNFOX) && !has_caught(GOLDEN));
|
||||
draw_battle_hud();
|
||||
assert(pending_pixels() < 16500);
|
||||
copy_pending_rows(visible);
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
draw_battle();
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
write_preview("build/caught-preview.ppm");
|
||||
assert(!battle_input(SELECT) && ball_count == 3 && caught_count == 1);
|
||||
load_progress();
|
||||
assert(ball_count == 3 && caught_count == 1 && caught_species[0] == FERNFOX);
|
||||
assert(battle_input(A) && battle.phase == BATTLE_OFF);
|
||||
draw_team_member(1);
|
||||
write_preview("build/caught-team-preview.ppm");
|
||||
|
||||
/* The village's single golden creature leaves the map after being caught. */
|
||||
current_room = OUTSIDE;
|
||||
assert(begin_battle(182, 113));
|
||||
battle.enemy_hp = 1;
|
||||
assert(battle_input(SELECT) && battle.phase == BATTLE_CAUGHT);
|
||||
assert(ball_count == 2 && caught_count == 2 && caught_species[1] == GOLDEN);
|
||||
assert(!near_golden(182, 113));
|
||||
assert(battle_input(A));
|
||||
assert(!begin_battle(182, 113));
|
||||
reset_follower(108, 103);
|
||||
render_scene(108, 103);
|
||||
assert(SCREEN[95 * WIDTH + 181] == scenery(181, 95));
|
||||
load_progress();
|
||||
assert(has_caught(GOLDEN) && !near_golden(182, 113));
|
||||
|
||||
/* Fill a six-member team, including duplicate wild species. */
|
||||
current_room = ROUTE;
|
||||
ball_count = 5;
|
||||
const enum Species additions[] = {EMBERWING, PEBBLIT, FERNFOX};
|
||||
for (unsigned i = 0; i < sizeof(additions) / sizeof(additions[0]); ++i) {
|
||||
assert(start_battle(additions[i]));
|
||||
battle.enemy_hp = 1;
|
||||
assert(battle_input(SELECT) && battle.phase == BATTLE_CAUGHT);
|
||||
assert(battle_input(A));
|
||||
}
|
||||
assert(caught_count == CAUGHT_CAPACITY && ball_count == 2);
|
||||
memcpy(before, test_save, sizeof(before));
|
||||
assert(start_battle(FERNFOX));
|
||||
rng = random_state;
|
||||
assert(battle_input(SELECT) && battle.notice == NOTICE_TEAM_FULL);
|
||||
assert(ball_count == 2 && battle.turns == 0 && battle.sprout_hp == SPROUT_HP);
|
||||
assert(random_state == rng && memcmp(before, test_save, sizeof(before)) == 0);
|
||||
assert(battle_input(B) && battle_input(A));
|
||||
for (int member = 0; member <= caught_count; ++member) draw_team_member(member);
|
||||
draw_team();
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
draw_team_member(99);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
load_progress();
|
||||
assert(caught_count == 5 && ball_count == 2 && partner_owned);
|
||||
for (int i = SAVE_RECORD_SIZE; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
|
||||
|
||||
for (int byte = 0; byte < SAVE_RECORD_SIZE; ++byte) {
|
||||
memcpy(test_save, before, sizeof(before));
|
||||
test_save[byte] ^= 1;
|
||||
load_progress();
|
||||
assert(!partner_owned && !balls_given && ball_count == 0 && caught_count == 0);
|
||||
}
|
||||
memcpy(test_save, before, sizeof(before));
|
||||
test_save[7] = 6;
|
||||
test_save[13] ^= 5 ^ 6; /* Valid checksum, invalid party length. */
|
||||
load_progress();
|
||||
assert(!partner_owned && caught_count == 0);
|
||||
memcpy(test_save, before, sizeof(before));
|
||||
test_save[8] = SPECIES_COUNT;
|
||||
test_save[13] ^= FERNFOX ^ SPECIES_COUNT;
|
||||
load_progress();
|
||||
assert(!partner_owned && caught_count == 0);
|
||||
memcpy(test_save, before, sizeof(before));
|
||||
test_save[5] &= (unsigned char)~1;
|
||||
test_save[13] ^= 1;
|
||||
load_progress();
|
||||
assert(!partner_owned && caught_count == 0); /* No captured team without Sprout. */
|
||||
|
||||
/* A failed attempt can end a battle, and the used ball still stays spent. */
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
load_progress();
|
||||
partner_owned = balls_given = 1;
|
||||
ball_count = 1;
|
||||
assert(start_battle(EMBERWING));
|
||||
battle.sprout_hp = 1;
|
||||
random_state = 1;
|
||||
assert(battle_input(SELECT) && battle.phase == BATTLE_LOST && ball_count == 0);
|
||||
load_progress();
|
||||
assert(partner_owned && balls_given && ball_count == 0 && caught_count == 0);
|
||||
assert(battle_input(A));
|
||||
ball_count = 1;
|
||||
assert(start_battle(PEBBLIT));
|
||||
battle.enemy_hp = 1;
|
||||
assert(battle_input(A) && battle.phase == BATTLE_WON);
|
||||
assert(!battle_input(SELECT) && ball_count == 1); /* Cannot catch a fainted creature. */
|
||||
assert(battle_input(A));
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
load_progress();
|
||||
current_room = OUTSIDE;
|
||||
follower_ready = 0;
|
||||
puts("Catching: ball use, failed/successful catches, team limits, browsing, and save migration passed");
|
||||
}
|
||||
+26
-1
@@ -43,6 +43,9 @@ int main(void)
|
||||
check_art(person_art, 20, 11);
|
||||
check_art(person_back_art, 20, 13);
|
||||
check_art(person_side_art, 20, 13);
|
||||
check_art(girl_art, 20, 13);
|
||||
check_art(girl_back_art, 20, 13);
|
||||
check_art(girl_side_art, 20, 13);
|
||||
check_art(creature_art, 16, 8);
|
||||
assert(facing_for_keys(UP, FACING_DOWN) == FACING_UP);
|
||||
assert(facing_for_keys(DOWN, FACING_UP) == FACING_DOWN);
|
||||
@@ -76,7 +79,7 @@ int main(void)
|
||||
actors(x, y, 0);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
}
|
||||
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
|
||||
for (int room = OUTSIDE; room <= BEACH; ++room) {
|
||||
current_room = (enum Room)room;
|
||||
reset_position(&x, &y);
|
||||
if (current_room == OUTSIDE) x = 130;
|
||||
@@ -103,6 +106,23 @@ int main(void)
|
||||
person(85, 116, 1, shirt, RGB(28, 8, 9), FACING_LEFT);
|
||||
person(130, 126, 0, shirt, RGB(28, 8, 9), FACING_RIGHT);
|
||||
write_preview("build/directions-preview.ppm");
|
||||
for (int facing = FACING_DOWN; facing <= FACING_RIGHT; ++facing) {
|
||||
int gx = 45 + facing * 45;
|
||||
styled_person(gx, 75, facing & 1, RGB(4, 21, 13), RGB(12, 7, 4),
|
||||
(enum Facing)facing, GIRL_STYLE);
|
||||
styled_person(gx, 125, facing & 1, RGB(29, 30, 27), RGB(20, 21, 19),
|
||||
(enum Facing)facing, GIRL_STYLE);
|
||||
}
|
||||
write_preview("build/girl-directions-preview.ppm");
|
||||
current_room = MELLON_HOUSE;
|
||||
render_scene(108, 119);
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
/* Replacing the professor with the girl style must leave identical pixels. */
|
||||
restore(PROF_X - 8, PROF_Y - 20, 17, 24);
|
||||
styled_person(PROF_X, PROF_Y, 0, RGB(29, 30, 27), RGB(20, 21, 19),
|
||||
FACING_DOWN, GIRL_STYLE);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
current_room = OUTSIDE;
|
||||
assert(test_pixels[0] == 0xbeef);
|
||||
assert(test_pixels[WIDTH * HEIGHT + 1] == 0xbeef);
|
||||
render_scene(108, 103);
|
||||
@@ -177,6 +197,7 @@ int main(void)
|
||||
check_buffered_walking();
|
||||
check_route_travel();
|
||||
check_mellon_visit();
|
||||
check_beach_travel();
|
||||
check_starter_gift();
|
||||
check_following_and_battle();
|
||||
check_wild_encounters();
|
||||
@@ -184,6 +205,10 @@ int main(void)
|
||||
check_background_cache();
|
||||
check_sprite_rows();
|
||||
check_movement_clock_and_speed();
|
||||
check_music();
|
||||
check_catching();
|
||||
check_fishing();
|
||||
check_partner_selection();
|
||||
assert(test_pixels[0] == 0xbeef);
|
||||
assert(test_pixels[WIDTH * HEIGHT + 1] == 0xbeef);
|
||||
puts("Ball gift/inventory/save migration, wild encounters, battles, following, and map checks passed");
|
||||
|
||||
+68
-1
@@ -15,7 +15,7 @@ void check_buffered_walking(void)
|
||||
mark_dirty(240, 160, 4, 4);
|
||||
assert(pending_pixels() == 0);
|
||||
|
||||
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
|
||||
for (int room = OUTSIDE; room <= BEACH; ++room) {
|
||||
current_room = (enum Room)room;
|
||||
player_facing = FACING_DOWN;
|
||||
int x, y;
|
||||
@@ -219,3 +219,70 @@ void check_mellon_visit(void)
|
||||
current_room = OUTSIDE;
|
||||
player_facing = FACING_DOWN;
|
||||
}
|
||||
|
||||
void check_beach_travel(void)
|
||||
{
|
||||
static u16 expected[WIDTH * HEIGHT], visible[WIDTH * HEIGHT];
|
||||
current_room = MELLON_GARDEN;
|
||||
partner_owned = 1;
|
||||
assert(reachable(31, 113, 108, 131));
|
||||
int x = 80, y = 131;
|
||||
assert(!use_map_exit(&x, &y, DOWN));
|
||||
x = 108;
|
||||
assert(!use_map_exit(&x, &y, UP));
|
||||
for (int trip = 0; trip < 5; ++trip) {
|
||||
x = 108;
|
||||
y = 129;
|
||||
assert(walk_movement(DOWN, &x, &y, 1) == WALK_MAP_CHANGED);
|
||||
assert(current_room == BEACH && x == 108 && y == 60);
|
||||
assert(can_walk(x, y) && player_facing == FACING_DOWN);
|
||||
assert(follower_x == x && follower_y == y);
|
||||
assert(!use_map_exit(&x, &y, DOWN));
|
||||
assert(!near_npc(RANGER_X, RANGER_Y) && !near_door(177, 83));
|
||||
assert(!in_tall_grass(48, 70));
|
||||
assert(!check_grass_encounter(80, 80, 81, 80));
|
||||
assert(!can_walk(55, 85)); /* Umbrella. */
|
||||
assert(!can_walk(28, 60) && !can_walk(210, 60)); /* Palms. */
|
||||
assert(reachable(x, y, 178, 97));
|
||||
assert(reachable(x, y, 30, 99));
|
||||
assert(reachable(x, y, 108, 47));
|
||||
for (int col = 17; col <= 222; ++col)
|
||||
assert(!can_walk(col, beach_shoreline(col) - 4));
|
||||
assert(!can_walk(108, 115) && !can_walk(108, 140));
|
||||
render_scene(x, y);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
write_preview("build/beach-preview.ppm");
|
||||
|
||||
const int positions[][2] = {{108, 47}, {178, 97}, {30, 99}, {90, 82}};
|
||||
for (unsigned i = 0; i < sizeof(positions) / sizeof(positions[0]); ++i) {
|
||||
int nx = positions[i][0], ny = positions[i][1];
|
||||
assert(can_walk(nx, ny));
|
||||
render_scene(nx, ny);
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
render_scene(x, y);
|
||||
restore(x - 8, y - 20, 17, 24);
|
||||
actors(nx, ny, 0);
|
||||
location_status(nx, ny);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
}
|
||||
x = 108;
|
||||
y = beach_shoreline(x) - 6;
|
||||
assert(walk_movement(DOWN, &x, &y, MAX_MOVEMENT_TICKS) == WALK_NORMAL);
|
||||
assert(y == beach_shoreline(x) - 5); /* Even catch-up frames cannot enter the sea. */
|
||||
reset_position(&x, &y);
|
||||
assert(current_room == BEACH && x == 108 && y == 60);
|
||||
assert(follower_x == x && follower_y == y);
|
||||
y = 48;
|
||||
assert(walk_movement(UP, &x, &y, 1) == WALK_MAP_CHANGED);
|
||||
assert(current_room == MELLON_GARDEN && x == 108 && y == 125);
|
||||
assert(player_facing == FACING_UP && follower_x == x && follower_y == y);
|
||||
assert(!use_map_exit(&x, &y, UP));
|
||||
assert(reachable(x, y, 177, 83)); /* Professor's door remains accessible. */
|
||||
assert(reachable(x, y, 17, 113)); /* Town exit remains accessible. */
|
||||
}
|
||||
current_room = OUTSIDE;
|
||||
partner_owned = follower_ready = 0;
|
||||
player_facing = FACING_DOWN;
|
||||
puts("Beach: garden connection, return path, shore collisions, following, and redraw checks passed");
|
||||
}
|
||||
@@ -98,7 +98,7 @@ void check_movement_clock_and_speed(void)
|
||||
static u16 snapshot[WIDTH * HEIGHT];
|
||||
const unsigned directions[] = {RIGHT, DOWN, LEFT, UP};
|
||||
const int tick_counts[] = {1, 2, 1, 3, 0};
|
||||
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
|
||||
for (int room = OUTSIDE; room <= BEACH; ++room) {
|
||||
current_room = (enum Room)room;
|
||||
reset_position(&x, &y);
|
||||
if (current_room == OUTSIDE) { x = 40; y = 125; }
|
||||
|
||||
@@ -10,7 +10,7 @@ void check_background_cache(void)
|
||||
restore(240, 160, 4, 4);
|
||||
assert(!background_valid && scenery_samples == 0 && pending_pixels() == 0);
|
||||
|
||||
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
|
||||
for (int room = OUTSIDE; room <= BEACH; ++room) {
|
||||
current_room = (enum Room)room;
|
||||
door_open = 0;
|
||||
unsigned before = scenery_samples;
|
||||
@@ -87,7 +87,7 @@ void check_background_cache(void)
|
||||
assert(SCREEN[y * WIDTH + x] == expected);
|
||||
}
|
||||
assert(test_pixels[0] == 0xbeef && test_pixels[WIDTH * HEIGHT + 1] == 0xbeef);
|
||||
puts("Background cache: 5 maps match reference; warm restores use 0 scenery evaluations (was 408 each)");
|
||||
puts("Background cache: 6 maps match reference; warm restores use 0 scenery evaluations (was 408 each)");
|
||||
}
|
||||
|
||||
/* Reference implementation of the previous per-pixel rectangle renderer. */
|
||||
@@ -116,8 +116,9 @@ void check_sprite_rows(void)
|
||||
static const char *const zero_art[] = {"0A..B1..", "..1.....", "........"};
|
||||
const struct { const char *const *art; int width, rows; } images[] = {
|
||||
{person_art, 16, 20}, {person_back_art, 16, 20}, {person_side_art, 16, 20},
|
||||
{girl_art, 16, 20}, {girl_back_art, 16, 20}, {girl_side_art, 16, 20},
|
||||
{creature_art, 16, 16}, {fernfox_art, 24, 24}, {emberwing_art, 24, 24},
|
||||
{pebblit_art, 24, 24}, {zero_art, 8, 3}
|
||||
{pebblit_art, 24, 24}, {tidefin_art, 24, 24}, {zero_art, 8, 3}
|
||||
};
|
||||
const int positions[][2] = {
|
||||
{70, 60}, {-8, 40}, {232, 40}, {80, -12}, {80, 155},
|
||||
|
||||
+6
-6
@@ -42,7 +42,7 @@ void check_starter_gift(void)
|
||||
assert(advance_conversation(0) == 1);
|
||||
assert(advance_conversation(1) == -1);
|
||||
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
|
||||
for (int i = 9; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
|
||||
for (int i = SAVE_RECORD_SIZE; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
|
||||
|
||||
/* Ownership survives map changes, position reset, and loading SRAM. */
|
||||
x = 120;
|
||||
@@ -68,7 +68,7 @@ void check_starter_gift(void)
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
|
||||
/* Reject damaged, incomplete, or unknown-version save records. */
|
||||
for (int byte = 0; byte < 9; ++byte) {
|
||||
for (int byte = 0; byte < SAVE_RECORD_SIZE; ++byte) {
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
test_save[byte] ^= 1;
|
||||
load_progress();
|
||||
@@ -132,7 +132,7 @@ void check_ball_gift(void)
|
||||
restore(DIALOGUE_X, DIALOGUE_Y, DIALOGUE_W, DIALOGUE_H);
|
||||
actors(99, 97, 0);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
assert(test_save[4] == 2);
|
||||
assert(test_save[4] == 5);
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
for (int visit = 0; visit < 10; ++visit) {
|
||||
@@ -146,7 +146,7 @@ void check_ball_gift(void)
|
||||
assert(partner_owned && balls_given && ball_count == 5);
|
||||
draw_team();
|
||||
write_preview("build/poke-balls-preview.ppm");
|
||||
for (int i = 9; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
|
||||
for (int i = SAVE_RECORD_SIZE; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
|
||||
int x = 108, y = 47;
|
||||
assert(use_map_exit(&x, &y, UP));
|
||||
assert(ball_count == 5 && balls_given);
|
||||
@@ -165,7 +165,7 @@ void check_ball_gift(void)
|
||||
load_progress();
|
||||
assert(partner_owned && balls_given && ball_count == 5);
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
for (int byte = 0; byte < 9; ++byte) {
|
||||
for (int byte = 0; byte < SAVE_RECORD_SIZE; ++byte) {
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
test_save[byte] ^= 1;
|
||||
load_progress();
|
||||
@@ -173,7 +173,7 @@ void check_ball_gift(void)
|
||||
}
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
test_save[6] = 100;
|
||||
test_save[7] = (unsigned char)(0xa5 ^ 2 ^ test_save[5] ^ test_save[6]);
|
||||
test_save[13] ^= (unsigned char)(5 ^ 100); /* Keep checksum valid; count itself is invalid. */
|
||||
load_progress();
|
||||
assert(!partner_owned && !balls_given && ball_count == 0);
|
||||
for (int page = 0; page < DIALOGUE_PAGES; ++page)
|
||||
|
||||
@@ -15,6 +15,7 @@ void copy_pending_rows(u16 *visible);
|
||||
void check_buffered_walking(void);
|
||||
void check_route_travel(void);
|
||||
void check_mellon_visit(void);
|
||||
void check_beach_travel(void);
|
||||
void check_starter_gift(void);
|
||||
void check_ball_gift(void);
|
||||
void check_following_and_battle(void);
|
||||
@@ -22,5 +23,9 @@ void check_wild_encounters(void);
|
||||
void check_background_cache(void);
|
||||
void check_sprite_rows(void);
|
||||
void check_movement_clock_and_speed(void);
|
||||
void check_music(void);
|
||||
void check_catching(void);
|
||||
void check_fishing(void);
|
||||
void check_partner_selection(void);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user