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
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Fly Map
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "PokemonFRLG_FlyMap.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


const std::vector<FlyTown>& kanto_fly_towns(){
static const std::vector<FlyTown> TOWNS{
{"PalletTown", {4, 11}, {"PalletTown", {6, 8}}},
{"ViridianCity", {4, 8}, {"ViridianCity", {26, 27}}},
{"PewterCity", {4, 4}, {"PewterCity", {17, 26}}},
{"Route4", {8, 3}, {"Route4", {12, 6}}},
{"CeruleanCity", {14, 3}, {"CeruleanCity", {22, 20}}},
{"VermilionCity", {14, 9}, {"VermilionCity", {15, 7}}},
{"Route10", {18, 3}, {"Route10", {13, 21}}},
{"LavenderTown", {18, 6}, {"LavenderTown", {6, 6}}},
{"CeladonCity", {11, 6}, {"CeladonCity", {48, 12}}},
{"SaffronCity", {14, 6}, {"SaffronCity", {24, 39}}},
{"FuchsiaCity", {12, 12}, {"FuchsiaCity", {25, 32}}},
{"CinnabarIsland", {4, 14}, {"CinnabarIsland", {14, 12}}},
{"IndigoPlateau", {2, 3}, {"IndigoPlateau_Exterior", {11, 7}}},
};
return TOWNS;
}

std::optional<size_t> fly_town_index(std::string_view name){
const std::vector<FlyTown>& towns = kanto_fly_towns();
for (size_t c = 0; c < towns.size(); c++){
if (towns[c].name == name){
return c;
}
}
return std::nullopt;
}



} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* Fly Map
*
* From: https://github.com/PokemonAutomation/
*
* The towns Fly takes the player to in Kanto: each one's cell on the fly
* map and the tile the player lands on. Cells are pokefirered's
* sRegionMapSections_Kanto (src/data/region_map/region_map_layout_kanto.h,
* 22 x 15, the cursor's x and y); landing tiles its heal locations
* (src/data/heal_locations.json), which Fly warps to (SetFlyWarpDestination()
* in src/region_map.c).
*
*/

#ifndef PokemonAutomation_PokemonFRLG_FlyMap_H
#define PokemonAutomation_PokemonFRLG_FlyMap_H

#include <cstddef>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include "PokemonFRLG_OverworldRouteSteps.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


// A place on the fly map Fly can take the player to.
struct FlyTown{
// The map's name, as a step names the town ("CeladonCity", "Route4").
std::string name;
// The town's cell on the fly map: the presses right and down from its
// top-left corner, where a hold up-left leaves the cursor
// (HandleRegionMapInput() stops it at 0).
TilePos cell;
// The tile Fly lands the player on: below the Pokemon Center's door,
// or Pallet Town's player's house.
MapPosition landing;
};

// Kanto's Fly destinations, Pallet Town first.
const std::vector<FlyTown>& kanto_fly_towns();
// The index of the town named `name` in kanto_fly_towns(), if it is one.
std::optional<size_t> fly_town_index(std::string_view name);

// The fly map's width in cells (MAP_WIDTH in region_map.c).
constexpr int FLY_MAP_COLUMNS = 22;
// The fly map's height in cells (MAP_HEIGHT in region_map.c).
constexpr int FLY_MAP_ROWS = 15;



} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
m_state.black_below = map().connections.empty() && map().tiles.height <= SMALL_ROOM_ROWS
&& m_player.position.y >= map().tiles.height - BLACK_BELOW_ROWS;
m_state.dark = m_script.dark_maps.contains(map().name);
m_state.surfing = m_player.surfing;
}

void OverworldSim::schedule(Milliseconds at, SimScreen screen, bool unfreeze){
Expand Down Expand Up @@ -286,7 +287,7 @@
case Direction::EAST: point.x = 0; break;
}
const StepKind kind = classify_step_onto(map(), m_player, direction, to, point);
if (kind != StepKind::WALK){
if (kind != StepKind::WALK && kind != StepKind::STOP_SURFING){
return std::nullopt;
}
return Step{destination, after_step_onto(map(), m_player, to, point, kind), false, false, false};
Expand All @@ -313,7 +314,7 @@
return Step{m_map, PlayerState{landed, elevation_at(map(), landed), false}, false, false, true};
}
const StepKind kind = classify_step(map(), m_player, direction);
if (kind != StepKind::WALK){
if (kind != StepKind::WALK && kind != StepKind::STOP_SURFING){
return std::nullopt;
}
Step step{m_map, after_step_onto(map(), m_player, map(), ahead, kind), false, false, false};
Expand Down Expand Up @@ -355,7 +356,7 @@

// The player has taken `step`, pressed at `pressed`. Returns whether the
// game stopped them there: a warp, a trainer, a wild battle.
bool OverworldSim::after_step(const Step& step, Milliseconds pressed){

Check warning on line 359 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::OverworldSim::after_step( const Step & step , Milliseconds pressed): function_lines=35 (advisory above 25, limit 50)
const SimTiming& timing = m_script.timing;
if (step.warped && black_without_warp(pressed)){
return true;
Expand All @@ -369,10 +370,7 @@
update_view();
if (step.warped){
m_state.warps++;
for (auto& [index, tree] : m_cut_trees){
m_maps[index].objects.push_back(tree);
}
m_cut_trees.clear();
regrow_cut_trees();
if (m_state.on_bike){
// A door takes the player off (the user's; not measured).
m_state.on_bike = false;
Expand Down Expand Up @@ -841,8 +839,8 @@
sim_turn_to(m_sim, step.direction, m_rules.confirm_turn);
return std::nullopt;
}
if (step.action != RouteAction::WALK){
fail("Sim: Surf isn't modelled.");
if (step.action == RouteAction::SURF){
return surf(step);
}
if (turns_first(step, m_speed, facing)){
sim_turn_to(m_sim, step.direction, m_rules.confirm_turn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
* A step onto a connected map waits a tile first, as the console does
* while the game loads the map.
*
* Not modelled: Surf, running, HP and status. Wandering people stand on
* Not modelled: running, HP and status, and wild battles on the water.
* Surf and Fly are (SimField::SURF, SimField::FLY). Wandering people stand on
* their tile. The Bicycle is: its pace, its taps (each a tile, some
* dropped when they come too fast), SELECT and doors taking the player
* off it.
Expand Down Expand Up @@ -164,6 +165,10 @@ class OverworldSim{
bool cut_tree();
bool choose_lift_floor(size_t floor);
bool push_poster_switch();
bool start_surf();
bool fly_to_town(size_t town);
// The trees cut come back, as after a warp.
void regrow_cut_trees();
bool after_step(const Step& step, Milliseconds pressed);
bool wild_battle(Milliseconds pressed);
std::optional<SimEncounter> next_encounter();
Expand All @@ -173,8 +178,11 @@ class OverworldSim{
// Whether the Bicycle tap starting at `start` is dropped, too soon
// after the last one.
bool drops_bike_tap(Milliseconds start);
// How long a tile takes: on the Bicycle or on foot.
// How long a tile takes: on the water, on the Bicycle or on foot.
Milliseconds tile_time() const{
if (m_player.surfing){
return m_script.timing.surf_tile;
}
return m_state.on_bike ? m_script.timing.bike_tile : m_script.timing.tile;
}
bool trainer_sees(Milliseconds pressed);
Expand Down Expand Up @@ -397,6 +405,10 @@ class OverworldSimWalker{
return stop_tiles(step, timed, m_leg_dark);
}
std::optional<WalkedTiles> walk_step(const RouteStep& step, std::optional<Direction> facing);
// start_surf(): turned to the water, A, YES, and the jump onto it.
// Nothing: a Surf is never stopped part-way.
// (PokemonFRLG_OverworldSimField.cpp)
std::optional<WalkedTiles> surf(const RouteStep& step);
bool after_warp(const RouteStep& step, int warps_before, Milliseconds watched_from);
bool fade_over_since(Milliseconds from) const;
// after_warp() on a fade seen with no warp: fails, or with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
* From: https://github.com/PokemonAutomation/
*
* What A does on the sim's overworld, facing something: a tree to cut,
* the Game Corner's poster, the lift's panel (OverworldSim::use_field()).
* the Game Corner's poster, the lift's panel, the water to Surf onto; and
* Fly (OverworldSim::use_field()).
*
*/

#include <algorithm>
#include <format>
#include "PokemonFRLG_CodedRooms.h"
#include "PokemonFRLG_FlyMap.h"
#include "PokemonFRLG_OverworldSim.h"
#include "PokemonFRLG_OverworldSimField.h"
#include "PokemonFRLG_BikeSpinMechanics.h"
Expand Down Expand Up @@ -38,6 +40,10 @@
return choose_lift_floor(floor);
case SimField::BIKE_SELECT:
return press_select();
case SimField::SURF:
return start_surf();
case SimField::FLY:
return fly_to_town(floor);
}
return false;
}
Expand Down Expand Up @@ -117,6 +123,62 @@
return true;
}

bool OverworldSim::start_surf(){
const bool water = classify_step(map(), m_player, m_state.facing) == StepKind::START_SURF;
if (!water || m_state.screen != SimScreen::OVERWORLD || m_frozen){
violation("no water to Surf onto " + std::string(direction_name(m_state.facing)) + " of " + to_string(m_state.position) + ".");

Check warning on line 129 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")
return false;
}
advance_to(m_now + m_script.timing.surf_start);
m_player = PokemonFRLG::after_step(map(), m_player, m_state.facing, StepKind::START_SURF);
m_state.on_bike = false;
update_view();
note("surfed onto " + to_string(m_state.position) + ".");

Check warning on line 136 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")
return true;
}

bool OverworldSim::fly_to_town(size_t town){
const std::vector<FlyTown>& towns = kanto_fly_towns();
const MapPosition* landing = town < towns.size() ? &towns[town].landing : nullptr;
const auto to = std::find_if(m_maps.begin(), m_maps.end(), [&](const MapData& map){
return landing != nullptr && map.name == landing->map;
});
if (to == m_maps.end() || m_state.screen != SimScreen::OVERWORLD || m_frozen){
violation(std::format("no Fly to town {} from {}.", town, to_string(m_state.position)));
return false;
}
m_state.warped_from.push_back(map().name);
m_state.warps++;
regrow_cut_trees();
m_map = (int)(to - m_maps.begin());
m_player = PlayerState{landing->point, elevation_at(*to, landing->point), false};
m_state.facing = Direction::SOUTH;
m_state.on_bike = false;
update_view();
m_frozen = true;
schedule(m_now + m_script.timing.message, SimScreen::FADE, false);
schedule(m_now + m_script.timing.fly, SimScreen::OVERWORLD, true);
note("flew to " + to_string(m_state.position) + ".");

Check warning on line 161 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")
return true;
}

std::optional<WalkedTiles> OverworldSimWalker::surf(const RouteStep& step){
if (m_sim.state().facing != step.direction){
sim_turn_to(m_sim, step.direction, m_rules.confirm_turn);
}
if (!m_sim.use_field(SimField::SURF)){
fail("walk_overworld_route(): no Surf prompt facing the water.");
}
return std::nullopt;
}

void OverworldSim::regrow_cut_trees(){
for (auto& [index, tree] : m_cut_trees){
m_maps[index].objects.push_back(tree);
}
m_cut_trees.clear();
}

bool OverworldSim::push_poster_switch(){
std::vector<MapObject>& objects = m_maps[m_map].objects;
const TilePos ahead = m_player.position.next(m_state.facing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ enum class SimField{
// running is allowed, or off it, in about
// MovementMechanics::BIKE_SELECT_TIME. (PokemonFRLG_OverworldSimTaps.cpp)
BIKE_SELECT,
// Surf onto the water the player faces, from ground beside it: the
// question, "<MON> used SURF!" and the jump (SimTiming::surf_start).
// Each step on the water then takes SimTiming::surf_tile, and a step
// onto land gets the player off.
SURF,
// Not A: Fly from the party menu to the town numbered `floor` in
// kanto_fly_towns(), outdoors: the fade, then the player on its landing
// tile facing south, still for SimTiming::fly.
FLY,
};

// Register the tests of the Bicycle's taps and SELECT on a made-up map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ struct SimTiming{
Milliseconds tile = MovementMechanics::TILE_TIME;
// A tile on the Bicycle.
Milliseconds bike_tile = MovementMechanics::BIKE_TILE_TIME;
// A tile on the water.
Milliseconds surf_tile = MovementMechanics::SURF_TILE_TIME;
// From the A facing the water to the player on it, able to move
// (OverworldWalkSteps::start_surf()'s presses and wait). Not measured
// on the console.
Milliseconds surf_start{4000};
// From Fly's town picked to the player standing in it, able to move:
// the fade, the flight and the landing. Not measured on the console.
Milliseconds fly{5000};
Milliseconds flash{300};
Milliseconds battle_screen{3700};
// A wild battle's text box, before the HP boxes (battle_screen). Not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ struct SimState{
int turn_taps_dropped = 0;
// On the Bicycle (SimScript::on_bike).
bool on_bike = false;
// On the water (SimField::SURF).
bool surfing = false;
// Bicycle taps the game dropped, too soon after the last one.
int bike_taps_dropped = 0;
// Step taps the game ignored, inside the lockout after the last one
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* AutoStory Field Move Steps
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_FlyMap.h"
#include "PokemonFRLG_AutoStoryFieldMoves.h"
#include "PokemonFRLG_AutoStoryFieldMoveSteps.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


using Pokemon::Direction;
using Pokemon::StoryStep;


StoryStep fly_step(std::string name, size_t slot, std::string_view town){
StoryStep step;
step.kind = Pokemon::StoryStepKind::GAME;
step.name = std::move(name);
step.action = FLY_VARIANT;
step.args = {{"town", std::string(town)}, {"slot", (int64_t)slot}};
if (const std::optional<size_t> index = fly_town_index(town)){
const MapPosition& landing = kanto_fly_towns()[*index].landing;
step.pose_after = Pokemon::TileDeclared{landing.map, {landing.point}, Direction::SOUTH};
}
return step;
}

StoryStep surf_step(std::string name, Pokemon::GridPose water){
StoryStep step;
step.kind = Pokemon::StoryStepKind::GAME;
step.name = std::move(name);
step.action = SURF_VARIANT;
if (water.facing){
step.args = {{"direction", *water.facing}};
}
step.pose_after = Pokemon::TileDeclared{std::move(water.map), std::move(water.tiles), water.facing};
return step;
}




} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Loading
Loading