224 lines
9.3 KiB
C
224 lines
9.3 KiB
C
#include "test_support.h"
|
|
|
|
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 <= BEACH; ++room) {
|
|
current_room = (enum Room)room;
|
|
int x, y;
|
|
reset_position(&x, &y);
|
|
if (current_room == ROUTE) { y = 94; reset_follower(x, y); }
|
|
assert(follower_x == x && follower_y == y);
|
|
render_scene(x, y);
|
|
copy_pending_rows(visible);
|
|
for (int frame = 0; frame < 100; ++frame) {
|
|
int old_x = x, old_y = y;
|
|
int old_fx = follower_x, old_fy = follower_y;
|
|
int old_head = trail_head;
|
|
unsigned keys = directions[(frame / 10) % 4];
|
|
player_facing = facing_for_keys(keys, player_facing);
|
|
int nx = x + !!(keys & RIGHT) - !!(keys & LEFT);
|
|
int ny = y + !!(keys & DOWN) - !!(keys & UP);
|
|
if (can_walk(nx, y)) x = nx;
|
|
if (can_walk(x, ny)) y = ny;
|
|
move_follower(old_x, old_y, x, y);
|
|
assert(can_walk(follower_x, follower_y));
|
|
if (old_x == x && old_y == y) assert(trail_head == old_head);
|
|
restore(old_x - 8, old_y - 20, 17, 24);
|
|
restore(old_fx - 8, old_fy - 20, 17, 24);
|
|
actors(x, y, 0);
|
|
location_status(x, y);
|
|
assert(pending_pixels() < 16500);
|
|
copy_pending_rows(visible);
|
|
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
|
memcpy(expected, SCREEN, sizeof(expected));
|
|
render_scene(x, y);
|
|
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
|
copy_pending_rows(visible);
|
|
}
|
|
}
|
|
current_room = OUTSIDE;
|
|
reset_follower(108, 103);
|
|
for (int step = 0; step < 20; ++step) move_follower(108 + step, 103, 109 + step, 103);
|
|
assert(follower_x == 114 && follower_y == 103); /* Exactly 14 steps behind. */
|
|
int head = trail_head;
|
|
move_follower(128, 103, 128, 103);
|
|
assert(trail_head == head);
|
|
int x = 108, y = 131;
|
|
assert(use_map_exit(&x, &y, DOWN));
|
|
assert(follower_x == x && follower_y == y && current_room == ROUTE);
|
|
current_room = OUTSIDE;
|
|
reset_follower(108, 103);
|
|
x = 108;
|
|
y = 103;
|
|
for (int step = 0; step < 20; ++step) {
|
|
move_follower(x, y, x + 1, y);
|
|
++x;
|
|
}
|
|
render_scene(x, y);
|
|
write_preview("build/follower-preview.ppm");
|
|
|
|
partner_owned = 0;
|
|
assert(!begin_battle(182, 113));
|
|
partner_owned = 1;
|
|
current_room = ROUTE;
|
|
assert(!begin_battle(182, 113));
|
|
current_room = OUTSIDE;
|
|
assert(!begin_battle(108, 103));
|
|
assert(!near_golden(162, 113));
|
|
assert(begin_battle(182, 113));
|
|
assert(!begin_battle(182, 113));
|
|
assert(battle.phase == BATTLE_TURN && battle.sprout_hp == SPROUT_HP &&
|
|
battle.enemy_hp == GOLDEN_HP);
|
|
unsigned char saved[sizeof(test_save)];
|
|
memcpy(saved, test_save, sizeof(saved));
|
|
draw_battle();
|
|
write_preview("build/battle-preview.ppm");
|
|
copy_pending_rows(visible);
|
|
assert(!battle_input(0));
|
|
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);
|
|
assert(battle_input(A));
|
|
assert(battle.enemy_hp == 11 && battle.sprout_hp == 19 && battle.turns == 1);
|
|
draw_battle_hud();
|
|
assert(pending_pixels() < 16500);
|
|
copy_pending_rows(visible);
|
|
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
|
memcpy(expected, SCREEN, sizeof(expected));
|
|
draw_battle();
|
|
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
|
copy_pending_rows(visible);
|
|
assert(!battle_input(0)); /* A held key without a new press adds no turn. */
|
|
assert(battle.turns == 1);
|
|
assert(battle_input(A));
|
|
assert(battle.enemy_hp == 4 && battle.sprout_hp == 14);
|
|
assert(battle_input(A));
|
|
assert(battle.phase == BATTLE_WON && battle.enemy_hp == 0 && battle.sprout_hp == 14);
|
|
draw_battle_hud();
|
|
assert(pending_pixels() < 16500);
|
|
write_preview("build/battle-win-preview.ppm");
|
|
assert(!battle_input(RIGHT));
|
|
assert(battle_input(A) && battle.phase == BATTLE_OFF);
|
|
|
|
assert(begin_battle(182, 113));
|
|
assert(battle_input(B) && battle.phase == BATTLE_FLED);
|
|
assert(battle.sprout_hp == SPROUT_HP && battle.enemy_hp == GOLDEN_HP);
|
|
assert(battle_input(B) && battle.phase == BATTLE_OFF);
|
|
assert(begin_battle(182, 113));
|
|
battle.sprout_hp = 1;
|
|
assert(battle_input(A) && battle.phase == BATTLE_LOST);
|
|
assert(battle.sprout_hp == 0);
|
|
assert(battle_input(A) && battle.phase == BATTLE_OFF);
|
|
assert(begin_battle(182, 113));
|
|
assert(battle.sprout_hp == SPROUT_HP); /* Free recovery after each battle. */
|
|
for (int turn = 0; turn < 5; ++turn) assert(battle_input(A));
|
|
assert(battle.phase == BATTLE_WON && battle.sprout_hp == 4 && battle.enemy_hp == 0);
|
|
assert(battle_input(A) && battle.phase == BATTLE_OFF);
|
|
assert(partner_owned && memcmp(saved, test_save, sizeof(saved)) == 0);
|
|
partner_owned = 0;
|
|
follower_ready = 0;
|
|
player_facing = FACING_DOWN;
|
|
}
|
|
|
|
void check_wild_encounters(void)
|
|
{
|
|
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);
|
|
for (int col = 0; col < 24; ++col) {
|
|
char pixel = wild_art[kind].rows[row][col];
|
|
if (pixel == '.') continue;
|
|
assert(pixel >= '1' && pixel <= '8');
|
|
++opaque;
|
|
}
|
|
}
|
|
assert(opaque > (kind == TIDEFIN - FERNFOX ? 100 : 180)); /* Fish has a slimmer silhouette. */
|
|
}
|
|
partner_owned = 1;
|
|
current_room = OUTSIDE;
|
|
assert(!in_tall_grass(48, 70));
|
|
assert(!check_grass_encounter(48, 70, 49, 70));
|
|
current_room = ROUTE;
|
|
assert(in_tall_grass(32, 53) && in_tall_grass(80, 86));
|
|
assert(in_tall_grass(151, 112) && in_tall_grass(207, 132));
|
|
assert(!in_tall_grass(31, 70) && !in_tall_grass(81, 70));
|
|
assert(!in_tall_grass(48, 87) && !in_tall_grass(108, 94));
|
|
partner_owned = 0;
|
|
for (int i = 0; i < 100; ++i) assert(!check_grass_encounter(48, 70, 49, 70));
|
|
assert(grass_steps == 0);
|
|
partner_owned = 1;
|
|
for (int i = 0; i < 100; ++i) assert(!check_grass_encounter(48, 70, 48, 70));
|
|
assert(grass_steps == 0); /* Waiting in the grass never starts a battle. */
|
|
for (int i = 0; i < 100; ++i) assert(!check_grass_encounter(108, 94, 109, 94));
|
|
assert(grass_steps == 0);
|
|
|
|
unsigned seen = 0;
|
|
for (unsigned trial = 1; trial <= 64; ++trial) {
|
|
random_state = trial * 719u;
|
|
grass_steps = 0;
|
|
int steps;
|
|
for (steps = 1; steps <= 64; ++steps) {
|
|
int x = 48 + (steps & 1), old_x = 48 + ((steps + 1) & 1);
|
|
if (check_grass_encounter(old_x, 70, x, 70)) break;
|
|
assert(battle.phase == BATTLE_OFF);
|
|
}
|
|
assert(steps >= 24 && steps <= 64);
|
|
assert(battle.enemy >= FERNFOX && battle.enemy <= PEBBLIT);
|
|
assert(battle.phase == BATTLE_TURN && battle.enemy_hp == species[battle.enemy].hp);
|
|
assert(grass_steps == 0);
|
|
seen |= 1u << battle.enemy;
|
|
assert(!check_grass_encounter(48, 70, 49, 70)); /* No nested battle. */
|
|
assert(battle_input(B) && battle.phase == BATTLE_FLED);
|
|
assert(battle_input(A) && battle.phase == BATTLE_OFF);
|
|
for (int i = 0; i < 23; ++i) assert(!check_grass_encounter(48, 70, 49, 70));
|
|
assert(!check_grass_encounter(80, 70, 81, 70));
|
|
assert(grass_steps == 0); /* Leaving the grass resets the meter. */
|
|
}
|
|
assert(seen == ((1u << FERNFOX) | (1u << EMBERWING) | (1u << PEBBLIT)));
|
|
int right_steps = 0;
|
|
while (++right_steps <= 64)
|
|
if (check_grass_encounter(180, 121, 181, 121)) break;
|
|
assert(right_steps <= 64 && battle.phase == BATTLE_TURN);
|
|
assert(battle_input(B) && battle_input(A));
|
|
assert(battle.phase == BATTLE_OFF);
|
|
unsigned char saved[sizeof(test_save)];
|
|
memcpy(saved, test_save, sizeof(saved));
|
|
static u16 visible[WIDTH * HEIGHT];
|
|
const char *previews[] = {
|
|
"build/wild-fernfox-preview.ppm", "build/wild-emberwing-preview.ppm", "build/wild-pebblit-preview.ppm"
|
|
};
|
|
for (int kind = FERNFOX; kind <= PEBBLIT; ++kind) {
|
|
assert(start_battle((enum Species)kind));
|
|
assert(battle.enemy == (enum Species)kind);
|
|
draw_battle();
|
|
write_preview(previews[kind - FERNFOX]);
|
|
copy_pending_rows(visible);
|
|
assert(battle_input(RIGHT));
|
|
int turns = 0;
|
|
while (battle.phase == BATTLE_TURN && turns < 10) {
|
|
assert(battle_input(A));
|
|
++turns;
|
|
assert(battle.enemy_hp >= 0 && battle.enemy_hp <= species[kind].hp);
|
|
assert(battle.sprout_hp >= 0 && battle.sprout_hp <= SPROUT_HP);
|
|
draw_battle_hud();
|
|
assert(pending_pixels() < 16500);
|
|
copy_pending_rows(visible);
|
|
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
|
}
|
|
assert(battle.phase == BATTLE_WON && battle.sprout_hp > 0);
|
|
assert(battle_input(A) && battle.phase == BATTLE_OFF);
|
|
}
|
|
assert(!start_battle(SPECIES_COUNT));
|
|
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
|
|
random_state = 0;
|
|
assert(next_random() != 0);
|
|
partner_owned = 0;
|
|
grass_steps = 0;
|
|
current_room = OUTSIDE;
|
|
}
|