Skip to content
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Route

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=562 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -11,6 +11,7 @@
#include <string>
#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/TestRunners/UnitTest.h"
#include "Pokemon/Navigation/Pokemon_ConnectedMaps.h"
#include "Pokemon/Navigation/Pokemon_LegPlanner.h"
#include "PokemonFRLG_OverworldMaps.h"
#include "PokemonFRLG_OverworldObjects.h"
Expand Down Expand Up @@ -50,13 +51,12 @@
namespace{


using Pokemon::ConnectedMaps;
using Pokemon::MapPlace;

int find_map(const std::vector<MapData>& maps, const std::string& name){
for (size_t c = 0; c < maps.size(); c++){
if (maps[c].name == name){
return (int)c;
}
}
return -1;
const std::optional<size_t> index = ConnectedMaps(maps).find(name);
return index ? (int)*index : -1;
}

// The player on one of the loaded maps.
Expand Down Expand Up @@ -92,19 +92,16 @@

// The player taking `warp`, or nothing if it leads off the loaded maps.
std::optional<Transition> take_warp(const std::vector<MapData>& maps, const MapWarp* warp){
if (warp == nullptr || !warp->to){
if (warp == nullptr){
return std::nullopt;
}
const int destination = find_map(maps, warp->to->map);
if (destination < 0){
const std::optional<MapPlace> arrival = ConnectedMaps(maps).warp_arrival(*warp);
if (!arrival){
return std::nullopt;
}
const int destination = (int)arrival->map;
const MapData& map = maps[destination];
const auto arrival = map.points.find(warp->to->point);
if (arrival == map.points.end()){
return std::nullopt;
}
TilePos position = arrival->second;
TilePos position = arrival->tile;
Transition transition;
if (walks_out_on_arrival(map, position)){
position = position.next(Direction::SOUTH);
Expand All @@ -119,43 +116,21 @@
// Walking off the map's edge onto the map connected there, if it is loaded.
std::optional<Transition> cross_edge(const std::vector<MapData>& maps, const Located& player, Direction direction){
const MapData& map = maps[player.map];
for (const MapConnection& connection : map.connections){
if (connection.side != direction){
continue;
}
const int destination = find_map(maps, connection.to_map);
if (destination < 0){
return std::nullopt;
}
const MapData& to = maps[destination];
const TilePos here = player.state.position;
TilePos point;
switch (direction){
case Direction::NORTH:
point = {here.x - connection.offset, to.tiles.height - 1};
break;
case Direction::SOUTH:
point = {here.x - connection.offset, 0};
break;
case Direction::WEST:
point = {to.tiles.width - 1, here.y - connection.offset};
break;
case Direction::EAST:
point = {0, here.y - connection.offset};
break;
}
const StepKind kind = classify_step_onto(map, player.state, direction, to, point);
if (kind == StepKind::BLOCKED){
return std::nullopt;
}
Transition transition;
transition.next.map = destination;
transition.next.state = after_step_onto(map, player.state, to, point, kind);
transition.action = kind == StepKind::START_SURF ? RouteAction::SURF : RouteAction::WALK;
transition.dismounted = kind == StepKind::STOP_SURFING;
return transition;
const std::optional<MapPlace> across = ConnectedMaps(maps).across_edge(MapPlace{(size_t)player.map, player.state.position}, direction);
if (!across){
return std::nullopt;
}
return std::nullopt;
const MapData& to = maps[across->map];
const StepKind kind = classify_step_onto(map, player.state, direction, to, across->tile);
if (kind == StepKind::BLOCKED){
return std::nullopt;
}
Transition transition;
transition.next.map = (int)across->map;
transition.next.state = after_step_onto(map, player.state, to, across->tile, kind);
transition.action = kind == StepKind::START_SURF ? RouteAction::SURF : RouteAction::WALK;
transition.dismounted = kind == StepKind::STOP_SURFING;
return transition;
}

// Pressing `direction` once (field_control_avatar.c): an exit mat or a door
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Sim

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=998 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -9,6 +9,7 @@
#include <format>
#include "Common/Cpp/Exceptions.h"
#include "CommonFramework/Exceptions/OperationFailedException.h"
#include "Pokemon/Navigation/Pokemon_ConnectedMaps.h"
#include "Pokemon/Navigation/Pokemon_LegWalker.h"
#include "PokemonFRLG_OverworldLateBattle.h"
#include "PokemonFRLG_OverworldReanchor.h"
Expand Down Expand Up @@ -102,12 +103,8 @@
constexpr int SMALL_ROOM_ROWS = 20;

int find_map(const std::vector<MapData>& maps, const std::string& name){
for (size_t c = 0; c < maps.size(); c++){
if (maps[c].name == name){
return (int)c;
}
}
return -1;
const std::optional<size_t> index = Pokemon::ConnectedMaps(maps).find(name);
return index ? (int)*index : -1;
}

// The way a ledge on `tile` hops the player, if it is one.
Expand Down Expand Up @@ -250,19 +247,13 @@
if (m_lift_floor && m_script.lift_floors.contains(m_maps[map_index].name)){
return lift_warp(map_index);
}
if (!warp->to){
return std::nullopt;
}
const int destination = find_map(m_maps, warp->to->map);
if (destination < 0){
const std::optional<Pokemon::MapPlace> arrival = Pokemon::ConnectedMaps(m_maps).warp_arrival(*warp);
if (!arrival){
return std::nullopt;
}
const int destination = (int)arrival->map;
const MapData& to = m_maps[destination];
const auto arrival = to.points.find(warp->to->point);
if (arrival == to.points.end()){
return std::nullopt;
}
TilePos position = arrival->second;
TilePos position = arrival->tile;
const bool walked_out = walks_out_on_arrival(to, position);
if (walked_out){
position = position.next(Direction::SOUTH);
Expand All @@ -271,27 +262,16 @@
}

std::optional<OverworldSim::Step> OverworldSim::cross_edge(Direction direction) const{
for (const MapConnection& connection : map().connections){
const int destination = connection.side == direction ? find_map(m_maps, connection.to_map) : -1;
if (destination < 0){
continue;
}
const MapData& to = m_maps[destination];
const TilePos here = m_player.position;
TilePos point{here.x - connection.offset, here.y - connection.offset};
switch (direction){
case Direction::NORTH: point.y = to.tiles.height - 1; break;
case Direction::SOUTH: point.y = 0; break;
case Direction::WEST: point.x = to.tiles.width - 1; break;
case Direction::EAST: point.x = 0; break;
}
const StepKind kind = classify_step_onto(map(), m_player, direction, to, point);
if (kind != StepKind::WALK){
return std::nullopt;
}
return Step{destination, after_step_onto(map(), m_player, to, point, kind), false, false, false};
const std::optional<Pokemon::MapPlace> across = Pokemon::ConnectedMaps(m_maps).across_edge({(size_t)m_map, m_player.position}, direction);
if (!across){
return std::nullopt;
}
return std::nullopt;
const MapData& to = m_maps[across->map];
const StepKind kind = classify_step_onto(map(), m_player, direction, to, across->tile);
if (kind != StepKind::WALK){
return std::nullopt;
}
return Step{(int)across->map, after_step_onto(map(), m_player, to, across->tile, kind), false, false, false};
}

// Pressing `direction` once, as the planner's press() reads the game, and
Expand Down
Loading