Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#include "Inference/PokemonBDSP_DialogDetector.h"
#include "Inference/PokemonBDSP_MenuDetector.h"
#include "Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.h"
#include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FrozenTrainer_Tests.h"
#include "Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.h"
#include "Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.h"
#include "Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.h"
#include "Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.h"
#include "Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h"
#include "Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h"
#include "Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h"
#include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.h"
Expand Down Expand Up @@ -39,12 +41,14 @@ void add_tests(UnitTestDatabase& database){
add_tests_AutoStory_RoutePlanner(database);
add_tests_AutoStory_RouteBench(database);
add_tests_AutoStory_StoryMaps(database);
add_tests_AutoStory_Segment00(database);
add_tests_AutoStory_StoryData(database);
add_tests_AutoStory_StoryTable(database);
add_tests_AutoStory_Walk(database);
add_tests_AutoStory_WildBattlePolicy(database);
add_tests_AutoStory_PlannedRoute(database);
add_tests_AutoStory_SimulatedRoute(database);
add_tests_AutoStory_FrozenTrainer(database);
add_tests_AutoStory_WallBattleSim(database);
add_tests_AutoStory_StoryActions(database);
add_tests_StarterRng(database);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/* BDSP AutoStory - Segment 00's walked lines
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <utility>
#include "PokemonBDSP_AutoStory_Maps.h"
#include "PokemonBDSP_AutoStory_StoryMaps.h"
#include "PokemonBDSP_AutoStory_Segment00Lines.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{
namespace Segment00Lines{

using Pokemon::TilePos;




// Offsets are the decomp's world coordinates of each map's tile (0, 0):
// the Sinnoh matrix's cells are 32 tiles square, the Lakefront is cell
// (column 2, row 26), Route 201 cells (3..4, 26), Twinleaf (3, 27) and
// Sandgem (5, 26). The Route201 map leaves off the cell's seven wall rows
// at the top, so it starts 7 rows lower; story_map("SandgemTown") is its whole
// cell.
const StoryWorld& segment00_maps(){
static const StoryWorld maps = []{
StoryWorld world;
world.add(MAP_TWINLEAF_TOWN, story_map("TwinleafTown"), {96, 864});
world.add(MAP_ROUTE_201, story_map("Route201"), {96, 839});
world.add(MAP_VERITY_LAKEFRONT, story_map("VerityLakefront"), {64, 832});
world.add(MAP_SANDGEM_TOWN, story_map("SandgemTown"), {160, 832});
return world;
}();
return maps;
}


// From the Diamond decomp's coord events (zone_event narc_0389 Twinleaf,
// 0327 Route 201, 0319 Verity Lakefront, 0396 Sandgem; Lake Verity's
// narc_0298 has none: its scene is the map's own script, run on arrival).
// Each is a rectangle in world tiles with the story variable and value it
// fires at; Platinum's readable events files name the variables and carry
// the same rectangles for Twinleaf and the Lakefront. Listed as local
// tiles of our grids. Not here, having no grid: the player's house's door
// tile (6, 10), where Mom's warning fires on the way out (narc_0392, value
// 1).
const std::vector<SceneTrigger>& scene_triggers(){
static const std::vector<SceneTrigger> triggers{
{"Barry's door", MAP_TWINLEAF_TOWN, {9, 12}, 1, 1,
"before Barry has burst out of his house (var 0x40e6 = 0)"},
{"the guitarist stops us leaving", MAP_TWINLEAF_TOWN, {12, 3}, 8, 1,
"between Barry's door and his talk upstairs (var 0x4070 = 1; 2 after it)"},
{"Barry's tall-grass warning", MAP_ROUTE_201, {14, 18}, 6, 1,
"the first time north of Twinleaf (var 0x4086 = 0)"},
{"Route 201's row 19 after the warning", MAP_ROUTE_201, {14, 19}, 6, 1,
"after the warning and before the lake (var 0x4086 = 1); its script is Diamond's binary, not read"},
{"Rowan and Dawn on the way back", MAP_ROUTE_201, {5, 14}, 1, 3,
"after the lake (var 0x4086 = 2)"},
{"Barry at the lake's entrance", MAP_VERITY_LAKEFRONT, {16, 12}, 2, 1,
"the first visit (var 0x4082 = 0): he hears Rowan and the two walk into Lake Verity; the same tiles fire again at 3, later in the story"},
{"Dawn at Sandgem's entrance", MAP_SANDGEM_TOWN, {4, 11}, 1, 5,
"the first time in from Route 201 (var 0x4071 = 0): she leads us to Rowan's lab"},
};
return triggers;
}

bool trigger_covers(const SceneTrigger& trigger, const MapTile& tile){
return tile.map == trigger.map &&
tile.pos.x >= trigger.corner.x && tile.pos.x < trigger.corner.x + trigger.width &&
tile.pos.y >= trigger.corner.y && tile.pos.y < trigger.corner.y + trigger.height;
}



// Corners are chosen on the maps' features (a row clear of the houses,
// the exit path, a map's last tile, the tile a scene fires on); where a
// straight run is longer than the planner's 12-tile open leg (the row
// through the Lakefront, the row along Route 201) it is split at the
// twelfth tile. The lower level of Route 201 (rows 13 to 16) is the way
// both to and from the lake: the upper level's ledges only drop onto it.
// Row 16 is used westward and row 14 eastward: on the way out Rowan and
// the counterpart are not yet on (8, 14..15) and Barry is gone from (16,
// 16), but 16 keeps the line one row off the Breeder's range; on the way
// back 14 reaches Rowan's column with the fewest corners.
//
// What a new-game run must confirm before the segment switches to these:
// where each scene leaves the player (Barry's warning and Rowan's scene
// are assumed to leave us on the trigger tile; the lake's scene to warp
// us back onto (17, 12), the right-hand entrance tile, facing south), and
// that the stretches through tall grass are walked with the wild-battle
// handling the replay's walk_through_grass() has, which walk_waypoints()
// does not.
namespace{
// Corners on each map, and a line from them: parentheses keep the table
// flat enough for the code-health linter's brace limit.
MapTile twinleaf(const TilePos& pos){ return {MAP_TWINLEAF_TOWN, pos}; }
MapTile route201(const TilePos& pos){ return {MAP_ROUTE_201, pos}; }
MapTile lakefront(const TilePos& pos){ return {MAP_VERITY_LAKEFRONT, pos}; }
MapTile sandgem(const TilePos& pos){ return {MAP_SANDGEM_TOWN, pos}; }
// The same, at a named point of the map.
MapTile twinleaf_point(std::string_view point){ return twinleaf(map_point("TwinleafTown", point)); }
MapTile route201_point(std::string_view point){ return route201(map_point("Route201", point)); }
MapTile lakefront_point(std::string_view point){ return lakefront(map_point("VerityLakefront", point)); }
MapTile sandgem_point(std::string_view point){ return sandgem(map_point("SandgemTown", point)); }
WalkedLine walked(
std::string checkpoint, std::string name, std::vector<MapTile> corners,
std::string ends_in, std::vector<std::string> live_triggers
){
return {std::move(checkpoint), std::move(name), std::move(corners), std::move(ends_in), std::move(live_triggers)};
}

} // namespace

const std::vector<WalkedLine>& lines(){
static const std::vector<WalkedLine> lines{
walked("00.01", "the house's doorstep to Barry's door", {
twinleaf_point("house_doorstep"), twinleaf({13, 22}), twinleaf({13, 12}), twinleaf_point("barry_doorstep"),
}, "Barry's door", {"Barry's door"}),
walked("00.01", "Barry's doorstep to Route 201", {
twinleaf_point("barry_doorstep"), twinleaf({15, 12}), twinleaf_point("twinleaf_north_exit"), route201_point("barry_warning"),
}, "Barry's tall-grass warning", {"Barry's tall-grass warning"}),
walked("00.01", "Route 201's west half to the lake's entrance", {
route201_point("barry_warning"), route201({14, 18}), route201({14, 16}), route201({0, 16}),
lakefront({20, 23}), lakefront({20, 21}), lakefront({17, 21}), lakefront_point("lake_entrance"),
}, "Barry at the lake's entrance", {"Barry at the lake's entrance", "Route 201's row 19 after the warning"}),
walked("00.03", "the lake's entrance back to Rowan", {
lakefront_point("lake_entrance"), lakefront({17, 21}), lakefront({29, 21}), route201_point("rowan_stop"),
}, "Rowan and Dawn on the way back", {"Rowan and Dawn on the way back"}),
// Row 13, a row above the Breeder, who wanders (26..28, 14..16): no
// route runs along a wander zone (plan_robust_route()).
walked("00.03", "Rowan to Dawn at Sandgem's entrance", {
route201_point("rowan_stop"), route201({17, 14}), route201({17, 13}), route201({29, 13}), route201({41, 13}),
route201({41, 7}), route201({42, 7}), route201({42, 5}), route201({52, 5}),
route201_point("route_201_east_end"), sandgem_point("dawn_stop"),
}, "Dawn at Sandgem's entrance", {"Dawn at Sandgem's entrance"}),
};
return lines;
}

} // namespace Segment00Lines
} // namespace PokemonBDSP
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* BDSP AutoStory - Segment 00's walked lines

Check warning on line 1 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<header>: header_symbols=8 (advisory above 6, limit 8)
*
* From: https://github.com/PokemonAutomation/
*
* Checkpoints 00.01 to 00.03 (the house, Twinleaf, Route 201, the Verity
* Lakefront, the lake, and back to Sandgem) replay recorded stick holds
* today. These are the same walks as lines on the maps: corner to corner,
* each stretch one straight leg, ending on the tile that starts the next
* scene. The scenes' trigger rectangles come from the Diamond decomp's
* events files, so a test can show each line steps into its scene on its
* last tile and not before. Nothing runs them on the console yet (task
* #22); the segment keeps its replays until a new-game run has checked
* the lines.
*/

#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Segment00Lines_H
#define PokemonAutomation_PokemonBDSP_AutoStory_Segment00Lines_H

#include <string>
#include <vector>
#include "Pokemon/Navigation/Pokemon_Grid.h"
#include "PokemonBDSP_AutoStory_StoryWorld.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{
namespace Segment00Lines{


// Map names in segment00_maps(); Route 201 and Sandgem Town go by
// StoryMaps' MAP_ROUTE_201 and MAP_SANDGEM_TOWN.
inline const std::string MAP_TWINLEAF_TOWN = "Twinleaf Town";
// Verity Lakefront overworld map name.
inline const std::string MAP_VERITY_LAKEFRONT = "Verity Lakefront";

// Twinleaf Town, Route 201, the Verity Lakefront and Sandgem Town joined on
// one grid at their world offsets from the decomp. Lake Verity is not in
// it: its own matrix, and the scene walks us in and the game warps us out,
// so no line is walked there.
const StoryWorld& segment00_maps();

// A rectangle of tiles that starts a scene when the player steps in while
// the story is in `when`. From the decomp's coord events, as local tiles.
struct SceneTrigger{
std::string name;
std::string map;
Pokemon::TilePos corner; // north-west tile
int width;
int height;
std::string when; // the story state it fires in
};
// Returns all scene trigger zones for Segment 00.
const std::vector<SceneTrigger>& scene_triggers();
// Returns whether given map tile falls within the scene trigger zone.
bool trigger_covers(const SceneTrigger& trigger, const MapTile& tile);

// A line walked corner to corner: every stretch between two corners is one
// straight open leg (whole tiles, as the D-pad walks them).
struct WalkedLine{
std::string checkpoint;
std::string name;
std::vector<MapTile> corners; // the first is where the line starts
std::string ends_in; // the scene the last corner steps into, "" for none
std::vector<std::string> live_triggers; // the scenes armed while this line is walked
};
// Returns all pre-defined walked route lines for Segment 00.
const std::vector<WalkedLine>& lines();

// The route records start and end on named points of the maps (Twinleaf
// Town's house_doorstep, Route 201's barry_warning, ...), all on the lines.


} // namespace Segment00Lines
} // namespace PokemonBDSP
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
Loading
Loading