From 891b8f97e2e1399011431942c18079c532a19b5d Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 09:28:24 -0800 Subject: [PATCH 01/29] FRLG AutoStory stage 1: core navigation and battles Squash of fork PRs #117, #118, #119 and #120 (frlg/autostory-mvp at b8a58dd80). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- SerialPrograms/CMakeLists.txt | 4 + .../Pokemon/Navigation/Pokemon_LegWalker.cpp | 9 +- .../Pokemon/Navigation/Pokemon_LegWalker.h | 4 +- .../Navigation/Pokemon_LegWalker_Tests.cpp | 6 +- .../Menus/PokemonFRLG_ItemListReader.cpp | 216 ++++ .../Menus/PokemonFRLG_ItemListReader.h | 72 ++ .../PokemonFRLG_NamingScreenDetector.cpp | 65 ++ .../Menus/PokemonFRLG_NamingScreenDetector.h | 57 + .../Menus/PokemonFRLG_OptionMenuReader.cpp | 205 ++++ .../Menus/PokemonFRLG_OptionMenuReader.h | 63 ++ .../Menus/PokemonFRLG_SaveCardReader.cpp | 143 +++ .../Menus/PokemonFRLG_SaveCardReader.h | 45 + .../Menus/PokemonFRLG_SummaryMovesReader.cpp | 320 ++++++ .../Menus/PokemonFRLG_SummaryMovesReader.h | 77 ++ .../PokemonFRLG_BattleFlashWatcher.cpp | 76 ++ .../PokemonFRLG_BattleFlashWatcher.h | 46 + .../PokemonFRLG_BattleHpBarReader.cpp | 87 ++ .../Inference/PokemonFRLG_BattleHpBarReader.h | 43 + .../PokemonFRLG_BattleScreenDetector.cpp | 36 + .../PokemonFRLG_BattleScreenDetector.h | 54 + .../Overworld/Maps/CeruleanCave_1F.json | 194 ++++ .../Overworld/Maps/CeruleanCave_2F.json | 180 ++++ .../Overworld/Maps/CeruleanCave_B1F.json | 159 +++ .../Overworld/Maps/CeruleanCity.json | 270 +++++ .../Maps/CeruleanCity_PokemonCenter_1F.json | 125 +++ .../Overworld/Maps/PalletTown.json | 122 +++ .../Maps/PalletTown_PlayersHouse_1F.json | 64 ++ .../Maps/PalletTown_PlayersHouse_2F.json | 46 + .../Maps/PalletTown_ProfessorOaksLab.json | 127 +++ .../Maps/PalletTown_RivalsHouse.json | 69 ++ .../Overworld/Maps/PewterCity.json | 167 +++ .../Overworld/Maps/PewterCity_Gym.json | 75 ++ .../Overworld/Maps/PewterCity_Mart.json | 78 ++ .../Overworld/Maps/PewterCity_Museum_1F.json | 108 ++ .../Maps/PewterCity_PokemonCenter_1F.json | 110 ++ .../PokemonFRLG/Overworld/Maps/Route1.json | 91 ++ .../PokemonFRLG/Overworld/Maps/Route2.json | 211 ++++ .../PokemonFRLG/Overworld/Maps/Route22.json | 90 ++ .../PokemonFRLG/Overworld/Maps/Route24.json | 154 +++ .../Route2_ViridianForest_NorthEntrance.json | 78 ++ .../Route2_ViridianForest_SouthEntrance.json | 78 ++ .../Overworld/Maps/ViridianCity.json | 216 ++++ .../Overworld/Maps/ViridianCity_Mart.json | 91 ++ .../Maps/ViridianCity_PokemonCenter_1F.json | 98 ++ .../Overworld/Maps/ViridianForest.json | 201 ++++ .../Overworld/PokemonFRLG_OverworldMap.cpp | 252 +++++ .../Overworld/PokemonFRLG_OverworldMap.h | 143 +++ .../Overworld/PokemonFRLG_OverworldMaps.cpp | 118 +++ .../Overworld/PokemonFRLG_OverworldMaps.h | 71 ++ .../PokemonFRLG_OverworldMaps_Tests.cpp | 258 +++++ .../PokemonFRLG_OverworldReanchor.cpp | 374 +++++++ .../Overworld/PokemonFRLG_OverworldReanchor.h | 115 ++ .../PokemonFRLG_OverworldReanchor_Tests.cpp | 246 +++++ .../PokemonFRLG_OverworldRecovery.cpp | 358 +++++++ .../Overworld/PokemonFRLG_OverworldRecovery.h | 134 +++ .../PokemonFRLG_OverworldRecoveryWalk.cpp | 246 +++++ .../PokemonFRLG_OverworldRecoveryWalk.h | 69 ++ .../PokemonFRLG_OverworldRecovery_Tests.cpp | 503 +++++++++ .../Overworld/PokemonFRLG_OverworldRoute.cpp | 993 ++++++++++++++++++ .../Overworld/PokemonFRLG_OverworldRoute.h | 151 +++ .../Overworld/PokemonFRLG_OverworldWalk.cpp | 445 ++++++++ .../Overworld/PokemonFRLG_OverworldWalk.h | 183 ++++ .../PokemonFRLG_OverworldWalk_Tests.cpp | 101 ++ .../PokemonFRLG_PlayerFacingReader.cpp | 263 +++++ .../PokemonFRLG_PlayerFacingReader.h | 58 + .../PokemonFRLG/PokemonFRLG_Panels.cpp | 6 +- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 31 + .../AutoStory/BattleData/map_trainers.json | 106 ++ .../Programs/AutoStory/BattleData/moves.json | 356 +++++++ .../AutoStory/BattleData/species.json | 388 +++++++ .../AutoStory/BattleData/trainers.json | 641 +++++++++++ .../AutoStory/BattleData/type_chart.json | 112 ++ .../AutoStory/PokemonFRLG_AutoStory.cpp | 233 ++++ .../AutoStory/PokemonFRLG_AutoStory.h | 56 + .../PokemonFRLG_AutoStoryActions.cpp | 846 +++++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryActions.h | 225 ++++ .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 981 +++++++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 205 ++++ .../PokemonFRLG_AutoStoryBattleData.cpp | 322 ++++++ .../PokemonFRLG_AutoStoryBattleData.h | 177 ++++ .../PokemonFRLG_AutoStoryBattleData_Tests.cpp | 204 ++++ .../PokemonFRLG_AutoStoryBattleDecisions.cpp | 390 +++++++ .../PokemonFRLG_AutoStoryBattleDecisions.h | 247 +++++ .../PokemonFRLG_AutoStoryBattleSim.cpp | 576 ++++++++++ .../PokemonFRLG_AutoStoryBattleSim.h | 199 ++++ .../PokemonFRLG_AutoStoryBattleSim_Tests.cpp | 456 ++++++++ .../AutoStory/PokemonFRLG_AutoStoryDamage.cpp | 175 +++ .../AutoStory/PokemonFRLG_AutoStoryDamage.h | 123 +++ .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 528 ++++++++++ .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 192 ++++ .../PokemonFRLG_AutoStoryFoeTracker.cpp | 77 ++ .../PokemonFRLG_AutoStoryFoeTracker.h | 72 ++ .../PokemonFRLG_AutoStoryItems_Tests.cpp | 300 ++++++ .../AutoStory/PokemonFRLG_AutoStoryParty.cpp | 445 ++++++++ .../AutoStory/PokemonFRLG_AutoStoryParty.h | 171 +++ .../PokemonFRLG_AutoStoryParty_Tests.cpp | 831 +++++++++++++++ .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 395 +++++++ .../PokemonFRLG_AutoStorySummary.cpp | 153 +++ .../AutoStory/PokemonFRLG_AutoStorySummary.h | 57 + .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 297 ++++++ .../AutoStory/PokemonFRLG_AutoStoryTable.h | 37 + .../PokemonFRLG_AutoStoryWinChance.cpp | 397 +++++++ .../PokemonFRLG_AutoStoryWinChance.h | 66 ++ .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 591 +++++++++++ SerialPrograms/cmake/SourceFiles.cmake | 68 ++ devtools/maps/frlg_battle_data.py | 278 +++++ devtools/maps/frlg_maps.py | 318 ++++++ 107 files changed, 22234 insertions(+), 5 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity_PokemonCenter_1F.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_1F.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_2F.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_ProfessorOaksLab.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_RivalsHouse.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Gym.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Mart.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Museum_1F.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_PokemonCenter_1F.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route1.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route22.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route24.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_NorthEntrance.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_SouthEntrance.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_Mart.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_PokemonCenter_1F.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianForest.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/map_trainers.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/type_chart.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp create mode 100644 devtools/maps/frlg_battle_data.py create mode 100644 devtools/maps/frlg_maps.py diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index d0966df32f..9b3302b834 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -197,6 +197,10 @@ add_library(SerialProgramsLib STATIC ${CORE_LIBRARY_SOURCES} ${LIBRARY_SOURCES}) include(cmake/EmbedTextFiles.cmake) pa_embed_text_files(SerialProgramsLib Source/Pokemon/Navigation/TestMaps Pokemon/Navigation/Pokemon_Navigation_Tests.h PokemonAutomation::Pokemon navigation_test_map_json) +pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Overworld/Maps + VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h PokemonAutomation::NintendoSwitch::PokemonFRLG overworld_map_json) +pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData + VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_battle_json) # Create binary target diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.cpp index fbb88051fb..84ed2fa37e 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.cpp @@ -63,9 +63,16 @@ LegResult walk_leg_with(const LegSpec& leg, const LegCalls& calls, size_t max_in calls.clear(outcome->interrupt); const std::string seen = std::format("{} after {}ms", calls.name(outcome->interrupt), outcome->elapsed.count()); if (stops_here(leg, result, *outcome)){ - calls.log(seen + ", stopping the leg."); result.exact = false; result.stopped = true; + if (leg.to_wall){ + calls.log(seen + ", stopping the leg."); + return result; + } + // The caller finds the player again, near where the timing says. + result.tiles = leg.tiles - remaining + + tiles_before_interrupt(leg, outcome->elapsed, calls.detection_delay(outcome->interrupt), remaining); + calls.log(std::format("{}, about {} of {} tiles walked, stopping the leg.", seen, result.tiles, leg.tiles)); return result; } if (leg.to_wall){ diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.h index ca694db900..3993176f26 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.h @@ -94,7 +94,9 @@ struct LegResult{ bool exact = true; size_t interruptions = 0; // The leg stopped at an interrupt (stop_on_interrupt, stop_if_blocked): - // the player is somewhere along it, and `tiles` is not known. + // the player is somewhere along it. For an open leg `tiles` is then how + // many the interrupt's timing says were walked (tiles_before_interrupt()), + // for the caller to look around; for a leg to a wall it is 0. bool stopped = false; }; diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp index 667fb55d64..9f9564e275 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp @@ -130,7 +130,8 @@ UnitTestResult test_open_leg_interrupted_at_end(){ return true; } -// An open leg set to stop at an interrupt doesn't walk on from a guess. +// An open leg set to stop at an interrupt doesn't walk on from a guess; it +// says how far the timing puts the player, for the caller to look around. UnitTestResult test_open_leg_stops(){ ScriptedLeg script; script.outcomes = {after_step(2)}; @@ -140,6 +141,9 @@ UnitTestResult test_open_leg_stops(){ if (script.holds.size() != 1 || !result.stopped || result.exact || script.cleared.size() != 1){ return "Expected one hold, the interrupt cleared, and the leg stopped."; } + if (result.tiles != 2){ + return std::format("Expected the timing to put the player 2 tiles in, got {}.", result.tiles); + } return true; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp new file mode 100644 index 0000000000..b37226995b --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp @@ -0,0 +1,216 @@ +/* Item List Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/Language.h" +#include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" +#include "Tests/ImageUnitTest.h" +#include "Tests/TestUtils.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Tests.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_DigitReader.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_ItemListReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// Measured on a capture of the Items pocket (console B, 2026-11-01): text +// rows from y 13 to 21, 16 apart; names from x 97, "x" at 198, the count +// to 221. +constexpr double ROW_TOP = 11; +constexpr double ROW_STEP = 16; +constexpr double ROW_HEIGHT = 12; + +class ItemNameMatcher : public OCR::SmallDictionaryMatcher{ +public: + static constexpr double MAX_LOG10P = -1.40; + static constexpr double MAX_LOG10P_SPREAD = 0.50; + + static const ItemNameMatcher& instance(){ + static const ItemNameMatcher matcher; + return matcher; + } + + std::string read(Logger& logger, Language language, const ImageViewRGB32& image) const{ + if (!languages()[language]){ + return ""; + } + const ImageRGB32 ready = preprocess_for_ocr(image); + const OCR::StringMatchResult result = match_substring_from_image_multifiltered( + &logger, language, ready, DARK_TEXT_FILTERS(), + MAX_LOG10P, MAX_LOG10P_SPREAD, 0.01, 0.50 + ); + return result.results.empty() ? "" : result.results.begin()->second.token; + } + +private: + ItemNameMatcher() + : SmallDictionaryMatcher(dictionary()) + {} + + static JsonObject dictionary(){ + JsonObject english; + for (const auto& [slug, name] : { + std::pair{"potion", "Potion"}, + {"antidote", "Antidote"}, + {"parlyz-heal", "Parlyz Heal"}, + {"poke-ball", "Poke Ball"}, + {"cancel", "Cancel"}, + }){ + JsonArray names; + names.push_back(name); + english[slug] = std::move(names); + } + JsonObject json; + json["eng"] = std::move(english); + return json; + } +}; + +ImageViewRGB32 game_box(const ImageViewRGB32& screen){ + return extract_box_reference(screen, GameSettings::instance().GAME_BOX); +} + +} + + +ImageFloatBox item_list_name_box(int row){ + return ImageFloatBox(96.0 / 240, (ROW_TOP + ROW_STEP * row) / 160, 72.0 / 240, ROW_HEIGHT / 160); +} +ImageFloatBox bag_item_count_box(int row){ + return ImageFloatBox(208.0 / 240, (ROW_TOP + ROW_STEP * row) / 160, 15.0 / 240, ROW_HEIGHT / 160); +} + +std::string read_item_list_name(Logger& logger, Language language, const ImageViewRGB32& screen, int row){ + return ItemNameMatcher::instance().read(logger, language, extract_box_reference(game_box(screen), item_list_name_box(row))); +} + +std::vector read_bag_pocket(Logger& logger, Language language, const ImageViewRGB32& screen){ + std::vector rows; + for (int row = 0; row < ITEM_LIST_ROWS; row++){ + const std::string item = read_item_list_name(logger, language, screen, row); + if (item == "cancel"){ + break; + } + const ImageViewRGB32 count = extract_box_reference(game_box(screen), bag_item_count_box(row)); + // Not Tesseract on each waterfilled digit: the font joins some strokes + // only at a corner, so the 5 and the 3 fell apart into pieces and read + // as nothing (console B, 2026-11-02). The stat boxes' templates are + // the same digits on the same cream. + rows.push_back(BagRow{item, read_digits_waterfill_template(logger, count, DigitTemplateType::StatBox)}); + } + return pocket_rows(std::move(rows)); +} + +std::vector pocket_rows(std::vector reads){ + const auto cancel = std::find_if(reads.begin(), reads.end(), [](const BagRow& row){ + return row.item == "cancel"; + }); + reads.erase(cancel, reads.end()); + while (!reads.empty() && reads.back().item.empty()){ + reads.pop_back(); + } + return reads; +} + + +namespace{ + +// The language a test image's name ends with: _. +Language language_of_test_image(const std::string& image){ + const std::vector words = parse_words(Filesystem::Path(image).stem().string()); + return words.size() < 2 ? Language::None : language_code_to_enum(words.back()); +} + +// A capture of a bag pocket, read from the top. Its golden file holds each +// row's item and count, one per line. +class Test_BagPocket : public ImageUnitTest{ +public: + Test_BagPocket(const std::string& image) + : ImageUnitTest("PokemonFRLG::ItemListReader - " + image, {image}) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const Language language = language_of_test_image(image_paths()[0]); + if (language == Language::None || language == Language::EndOfList){ + return "Error: filename must be _."; + } + std::vector labels; + std::vector values; + const std::vector rows = read_bag_pocket(logger, language, images[0]); + for (size_t c = 0; c < rows.size(); c++){ + labels.push_back(std::format("row {} item", c + 1)); + labels.push_back(std::format("row {} count", c + 1)); + values.push_back(rows[c].item.empty() ? "(unread)" : rows[c].item); + values.push_back(std::to_string(rows[c].count)); + } + return check_against_golden_file(UNIT_TEST_RESOURCE_PATH() + image_paths()[0], labels, values); + } +}; + +// A capture of a Mart's BUY list, read from the top to its CANCEL. Its +// golden file holds each row's item, one per line. +class Test_MartList : public ImageUnitTest{ +public: + Test_MartList(const std::string& image) + : ImageUnitTest("PokemonFRLG::ItemListReader - " + image, {image}) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const Language language = language_of_test_image(image_paths()[0]); + if (language == Language::None || language == Language::EndOfList){ + return "Error: filename must be _."; + } + std::vector labels; + std::vector values; + for (int row = 0; row < ITEM_LIST_ROWS; row++){ + const std::string item = read_item_list_name(logger, language, images[0], row); + labels.push_back(std::format("row {}", row + 1)); + values.push_back(item.empty() ? "(nothing)" : item); + if (item.empty() || item == "cancel"){ + break; + } + } + return check_against_golden_file(UNIT_TEST_RESOURCE_PATH() + image_paths()[0], labels, values); + } +}; + +} + +void add_tests_ItemListReader(UnitTestDatabase& database){ + // FireRed on console B, 2026-11-02, after the Viridian Mart: the 5 and + // the 3 read as nothing before the digit templates. + database.add("PokemonFRLG/ItemListReader/ItemsPocket_eng.png"); + // Console B, 2026-11-03, the save before Cerulean's rival: a MOON STONE, + // which the reader has no name for, above the PARLYZ HEAL and 15 POTIONs. + // Stopping at it read nothing, and the rival was fought with 0 Potions. + database.add("PokemonFRLG/ItemListReader/ItemsPocketMoonStone_eng.png"); + // The Viridian Mart's BUY list, the same day, the cursor on POTION. + database.add("PokemonFRLG/ItemListReader/MartBuyList_eng.png"); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h new file mode 100644 index 0000000000..cddeb636c6 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h @@ -0,0 +1,72 @@ +/* Item List Reader + * + * From: https://github.com/PokemonAutomation/ + * + * Reads the item lists of the bag's pockets and of a Mart's BUY menu, + * which the game draws alike: rows 16 pixels apart from y 13, names from + * x 97 (pokefirered: the list window at tile (11, 1), item_X 9). It knows + * the names of the items a new game meets before the Boulder Badge, in + * English only so far: in another language a name is never read. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_ItemListReader_H +#define PokemonAutomation_PokemonFRLG_ItemListReader_H + +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Rows a list shows at once. +constexpr int ITEM_LIST_ROWS = 6; + +// Where row `row` (from 0) of a list shows its item's name, and in the bag +// its count, as fractions of the game screen. +ImageFloatBox item_list_name_box(int row); +ImageFloatBox bag_item_count_box(int row); + +// The item named in row `row`: a slug such as "potion", "antidote", +// "parlyz-heal", "poke-ball", or "cancel" for the list's last row, in a +// game in `language`; empty if it can't be read, as in a language the +// reader has no names for. +std::string read_item_list_name(Logger& logger, Language language, const ImageViewRGB32& screen, int row); + +struct BagRow{ + // The item's slug, as read_item_list_name() gives it; empty if its name + // can't be read. + std::string item; + // -1 if the count couldn't be read: the row still holds at least one. + int count = 0; +}; + +// The rows of the bag's open pocket from the top, as pocket_rows() keeps +// them. The pocket must be scrolled to its top. +std::vector read_bag_pocket(Logger& logger, Language language, const ImageViewRGB32& screen); + +// The rows of a pocket from `reads`, each row as read from the top: up to +// the CANCEL (not included). A row whose name can't be read stays, with an +// empty item, so the rows below keep their places: stopping there read +// nothing below a MOON STONE, and the rival was fought with 0 of the bag's +// 15 Potions (console B, 2026-11-03). Unread rows after the last name read +// are dropped. Empty if no name is read, as in a language the reader has +// no names for. +std::vector pocket_rows(std::vector reads); + + +void add_tests_ItemListReader(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp new file mode 100644 index 0000000000..c92e0d883e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp @@ -0,0 +1,65 @@ +/* Naming Screen Detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "CommonFramework/ImageTools/FloatPixel.h" +#include "CommonTools/Images/SolidColorTest.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_NamingScreenDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// Keyboard fill colors by page (keyboard.pal 13, 14, 15) as channel ratios: +// (123, 172, 197), (213, 156, 115), (148, 189, 106). +const FloatPixel KEYBOARD_COLORS[] = { + {0.250, 0.350, 0.400}, // upper case + {0.440, 0.322, 0.238}, // lower case + {0.334, 0.427, 0.239}, // symbols +}; + +bool is_keyboard_color(const ImageViewRGB32& image, const FloatPixel& color){ + return is_solid(image, color, 0.08, 30); +} + +} + + +// Boxes are fractions of the 240x160 GBA screen inside the game box. +NamingScreenDetector::NamingScreenDetector(Color color) + : m_color(color) + , m_keyboard_left_box(25.0 / 240, 82.0 / 160, 4.0 / 240, 60.0 / 160) // x 25-29, y 82-142 + , m_keyboard_right_box(170.0 / 240, 82.0 / 160, 5.0 / 240, 60.0 / 160) // x 170-175, y 82-142 + , m_entry_box(168.0 / 240, 50.0 / 160, 6.0 / 240, 12.0 / 160) // x 168-174, y 50-62 +{} +void NamingScreenDetector::make_overlays(VideoOverlaySet& items) const{ + const BoxOption& GAME_BOX = GameSettings::instance().GAME_BOX; + items.add(m_color, GAME_BOX.inner_to_outer(m_keyboard_left_box)); + items.add(m_color, GAME_BOX.inner_to_outer(m_keyboard_right_box)); + items.add(m_color, GAME_BOX.inner_to_outer(m_entry_box)); +} +bool NamingScreenDetector::detect(const ImageViewRGB32& screen){ + ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + ImageViewRGB32 left = extract_box_reference(game_screen, m_keyboard_left_box); + ImageViewRGB32 right = extract_box_reference(game_screen, m_keyboard_right_box); + if (!is_white(extract_box_reference(game_screen, m_entry_box))){ + return false; + } + for (const FloatPixel& color : KEYBOARD_COLORS){ + if (is_keyboard_color(left, color) && is_keyboard_color(right, color)){ + return true; + } + } + return false; +} + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h new file mode 100644 index 0000000000..c486fbf9bf --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h @@ -0,0 +1,57 @@ +/* Naming Screen Detector + * + * From: https://github.com/PokemonAutomation/ + * + * Detects the in-game keyboard used to name the player, the rival, boxes and Pokemon. + * + * The boxes and colors come from pret/pokefirered src/naming_screen.c (commit + * ce6406d8c2eaf46d543c8a2606de0c3cb1951982), not from screenshots: the keyboard window + * covers tiles (3, 10)-(22, 18) and is filled with keyboard.pal color 13, 14 or 15 by page, + * and the text entry window at tiles (8, 6)-(22, 8) is white. + * Not yet checked against a capture. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_NamingScreenDetector_H +#define PokemonAutomation_PokemonFRLG_NamingScreenDetector_H + +#include +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "CommonTools/VisualDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +class NamingScreenDetector : public StaticScreenDetector{ +public: + NamingScreenDetector(Color color = COLOR_RED); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + +private: + Color m_color; + // The keyboard's margins left and right of the keys, clear of the cursor. + ImageFloatBox m_keyboard_left_box; + ImageFloatBox m_keyboard_right_box; + // The text entry window, right of the last character. + ImageFloatBox m_entry_box; +}; +class NamingScreenWatcher : public DetectorToFinder{ +public: + NamingScreenWatcher(Color color = COLOR_RED) + : DetectorToFinder("NamingScreenWatcher", std::chrono::milliseconds(250), color) + {} +}; + + +} +} +} + +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp new file mode 100644 index 0000000000..bd099bb1da --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp @@ -0,0 +1,205 @@ +/* Option Menu Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Common/Cpp/Color.h" +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" +#include "Tests/ImageUnitTest.h" +#include "Tests/TestUtils.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_OptionMenuReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// option_menu.c: the window's top-left at pixel (16, 56), values from its +// x 130 and y 2 + 13 * row, cleared 70 wide before each is drawn. +constexpr double VALUE_LEFT = 16 + 130 - 2; +constexpr double VALUE_WIDTH = 70 + 4; +constexpr double ROW_TOP = 56 + 2; +constexpr double ROW_STEP = 13; +constexpr double ROW_HEIGHT = 13; + +// Peach letters with red edges, on white or the darkened rows' light gray: +// red stays high while green and blue stay below the background's. The +// item names to the left are dark gray, out of the box. +const std::vector& VALUE_TEXT_FILTERS(){ + static const std::vector filters{ + {combine_rgb(150, 0, 0), combine_rgb(255, 200, 160)}, + {combine_rgb(150, 0, 0), combine_rgb(255, 210, 180)}, + {combine_rgb(170, 0, 0), combine_rgb(255, 190, 140)}, + }; + return filters; +} + +struct OptionValue{ + const char* slug; + const char* english; +}; + +// One matcher per item, so a value is only matched against its own row's. +class OptionValueMatcher : public OCR::SmallDictionaryMatcher{ +public: + static constexpr double MAX_LOG10P_SPREAD = 0.50; + + OptionValueMatcher(const std::vector& values, double max_log10p) + : SmallDictionaryMatcher(dictionary(values)) + , m_max_log10p(max_log10p) + {} + + std::string read(Logger& logger, Language language, const ImageViewRGB32& image) const{ + if (!languages()[language]){ + return ""; + } + const ImageRGB32 ready = preprocess_for_ocr(image); + const OCR::StringMatchResult result = match_substring_from_image_multifiltered( + &logger, language, ready, VALUE_TEXT_FILTERS(), + m_max_log10p, MAX_LOG10P_SPREAD, 0.01, 0.50 + ); + return result.results.empty() ? "" : result.results.begin()->second.token; + } + +private: + static JsonObject dictionary(const std::vector& values){ + JsonObject english; + for (const OptionValue& value : values){ + JsonArray names; + names.push_back(value.english); + english[value.slug] = std::move(names); + } + JsonObject json; + json["eng"] = std::move(english); + return json; + } + + double m_max_log10p; +}; + +std::vector slugs_of(const std::vector& values){ + std::vector ret; + for (const OptionValue& value : values){ + ret.emplace_back(value.slug); + } + return ret; +} + +// An item's name, its row (option_menu.c MENUITEM_*), its values and their +// matcher. +struct OptionItem{ + OptionItem(const char* name, size_t row, const std::vector& values, double max_log10p) + : name(name) + , row(row) + , slugs(slugs_of(values)) + , matcher(values, max_log10p) + {} + + const char* name; + size_t row; + std::vector slugs; + OptionValueMatcher matcher; +}; + +const OptionItem& option_item(OptionMenuItem item){ + static const OptionItem text_speed("TEXT SPEED", 0, {{"slow", "Slow"}, {"mid", "Mid"}, {"fast", "Fast"}}, -1.40); + // Two letters score at most log10(1/25): an exact "ON" (console B, + // 2026-11-02) is -1.398, short of the others' -1.40. + static const OptionItem battle_scene("BATTLE SCENE", 1, {{"on", "On"}, {"off", "Off"}}, -1.30); + static const OptionItem battle_style("BATTLE STYLE", 2, {{"shift", "Shift"}, {"set", "Set"}}, -1.40); + switch (item){ + case OptionMenuItem::TEXT_SPEED: + return text_speed; + case OptionMenuItem::BATTLE_SCENE: + return battle_scene; + case OptionMenuItem::BATTLE_STYLE: + return battle_style; + } + return text_speed; +} + +} + + +const char* option_menu_name(OptionMenuItem item){ + return option_item(item).name; +} + +size_t option_menu_row(OptionMenuItem item){ + return option_item(item).row; +} + +const std::vector& option_menu_values(OptionMenuItem item){ + return option_item(item).slugs; +} + +ImageFloatBox option_value_box(size_t row){ + return ImageFloatBox(VALUE_LEFT / 240, (ROW_TOP + ROW_STEP * row) / 160, VALUE_WIDTH / 240, ROW_HEIGHT / 160); +} + +std::string read_option_value(Logger& logger, Language language, const ImageViewRGB32& screen, OptionMenuItem item){ + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + const ImageViewRGB32 value = extract_box_reference(game, option_value_box(option_menu_row(item))); + return option_item(item).matcher.read(logger, language, value); +} + + +namespace{ + +// A capture of the OPTION menu, named for what it shows: +// ____, +// e.g. CursorTop_eng_fast_on_set.png. +class Test_OptionMenu : public ImageUnitTest{ +public: + Test_OptionMenu(const std::string& image) + : ImageUnitTest("PokemonFRLG::OptionMenuReader - " + image, {image}) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const std::vector words = parse_words(Filesystem::Path(image_paths()[0]).stem().string()); + if (words.size() < 5){ + return "Error: filename must be ____."; + } + const std::string& language_word = words[words.size() - 4]; + const Language language = language_code_to_enum(language_word); + if (language == Language::None || language == Language::EndOfList){ + return "Error: invalid language word in filename: " + language_word; + } + + const OptionMenuItem items[] = {OptionMenuItem::TEXT_SPEED, OptionMenuItem::BATTLE_SCENE, OptionMenuItem::BATTLE_STYLE}; + for (size_t c = 0; c < 3; c++){ + const std::string read = read_option_value(logger, language, images[0], items[c]); + TEST_RESULT_COMPONENT_EQUAL_STR(read, words[words.size() - 3 + c], option_menu_name(items[c])); + } + return true; + } +}; + +} + +void add_tests_OptionMenuReader(UnitTestDatabase& database){ + // FireRed on console B, 2026-11-02: the menu as a new game opens it, + // then with the cursor moved to BATTLE STYLE (the other rows darkened), + // before and after AutoStory set BATTLE SCENE to OFF. + database.add("PokemonFRLG/OptionMenuReader/CursorTop_eng_fast_on_set.png"); + database.add("PokemonFRLG/OptionMenuReader/CursorBattleStyle_eng_fast_on_set.png"); + database.add("PokemonFRLG/OptionMenuReader/CursorBattleStyle_eng_fast_off_set.png"); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h new file mode 100644 index 0000000000..77dd54e53e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h @@ -0,0 +1,63 @@ +/* Option Menu Reader + * + * From: https://github.com/PokemonAutomation/ + * + * Reads the values the OPTION menu shows. pokefirered option_menu.c draws + * them in the window at tile (2, 7), from x 130 of it, one row every 13 + * pixels from y 2 (FONT_NORMAL's 14-pixel letters overlap by one), in + * LIGHT_RED with a RED shadow: peach letters, red edges. The rows but the + * cursor's are darkened by 2/16. English only so far: in another language + * a value is never read. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OptionMenuReader_H +#define PokemonAutomation_PokemonFRLG_OptionMenuReader_H + +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The options AutoStory sets. +enum class OptionMenuItem{ + TEXT_SPEED, + BATTLE_SCENE, + BATTLE_STYLE, +}; + +// "TEXT SPEED", "BATTLE SCENE", "BATTLE STYLE", for logs. +const char* option_menu_name(OptionMenuItem item); + +// The item's row in the menu, from 0. The cursor opens on row 0. +size_t option_menu_row(OptionMenuItem item); + +// The item's values as slugs, in the order RIGHT steps through them: +// "slow", "mid", "fast"; "on", "off"; "shift", "set" (option_menu.c +// sTextSpeedOptions, sBattleSceneOptions, sBattleStyleOptions). +const std::vector& option_menu_values(OptionMenuItem item); + +// Where row `row` shows its value, as fractions of the game screen. +ImageFloatBox option_value_box(size_t row); + +// The value the item's row shows, one of option_menu_values(item), in a +// game in `language`; empty if it can't be read. +std::string read_option_value(Logger& logger, Language language, const ImageViewRGB32& screen, OptionMenuItem item); + + +void add_tests_OptionMenuReader(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp new file mode 100644 index 0000000000..702d314298 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp @@ -0,0 +1,143 @@ +/* Save Card Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Common/Cpp/Color.h" +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" +#include "Tests/ImageUnitTest.h" +#include "Tests/TestUtils.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_SaveCardReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// The title's blue, about (30, 80, 225) on the capture. +const std::vector& BLUE_TEXT_FILTERS(){ + static const std::vector filters{ + {combine_rgb(0, 30, 150), combine_rgb(110, 150, 255)}, + {combine_rgb(0, 0, 120), combine_rgb(140, 180, 255)}, + }; + return filters; +} + +class PlaceNameMatcher : public OCR::SmallDictionaryMatcher{ +public: + static constexpr double MAX_LOG10P = -1.40; + static constexpr double MAX_LOG10P_SPREAD = 0.50; + + static const PlaceNameMatcher& instance(){ + static const PlaceNameMatcher matcher; + return matcher; + } + + std::string read(Logger& logger, Language language, const ImageViewRGB32& image) const{ + if (!languages()[language]){ + return ""; + } + const ImageRGB32 ready = preprocess_for_ocr(image); + const OCR::StringMatchResult result = match_substring_from_image_multifiltered( + &logger, language, ready, BLUE_TEXT_FILTERS(), + MAX_LOG10P, MAX_LOG10P_SPREAD, 0.01, 0.50 + ); + return result.results.empty() ? "" : result.results.begin()->second.token; + } + +private: + PlaceNameMatcher() + : SmallDictionaryMatcher(dictionary()) + {} + + static JsonObject dictionary(){ + JsonObject english; + for (const auto& [slug, name] : { + std::pair{"pallet-town", "Pallet Town"}, + {"viridian-city", "Viridian City"}, + {"viridian-forest", "Viridian Forest"}, + {"pewter-city", "Pewter City"}, + {"route-1", "Route 1"}, + {"route-2", "Route 2"}, + }){ + JsonArray names; + names.push_back(name); + english[slug] = std::move(names); + } + JsonObject json; + json["eng"] = std::move(english); + return json; + } +}; + +} + + +ImageFloatBox save_card_title_box(){ + return ImageFloatBox(8.0 / 240, 9.0 / 160, 114.0 / 240, 13.0 / 160); +} + +std::string read_save_card_location(Logger& logger, Language language, const ImageViewRGB32& screen){ + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + return PlaceNameMatcher::instance().read(logger, language, extract_box_reference(game, save_card_title_box())); +} + + +namespace{ + +// A capture of the save card over "Would you like to save the game?", +// named __, e.g. +// Bedroom_eng_pallet-town.png. +class Test_SaveCard : public ImageUnitTest{ +public: + Test_SaveCard(const std::string& image) + : ImageUnitTest("PokemonFRLG::SaveCardReader - " + image, {image}) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const std::vector words = parse_words(Filesystem::Path(image_paths()[0]).stem().string()); + if (words.size() < 3){ + return "Error: filename must be __."; + } + const std::string& language_word = words[words.size() - 2]; + const Language language = language_code_to_enum(language_word); + if (language == Language::None || language == Language::EndOfList){ + return "Error: invalid language word in filename: " + language_word; + } + + const std::string read = read_save_card_location(logger, language, images[0]); + TEST_RESULT_COMPONENT_EQUAL_STR(read, words.back(), "place"); + return true; + } +}; + +} + +void add_tests_SaveCardReader(UnitTestDatabase& database){ + // FireRed on console B, 2026-11-02. The card covers the same corner of + // the screen everywhere; the places behind it differ. + database.add("PokemonFRLG/SaveCardReader/Bedroom_eng_pallet-town.png"); + database.add("PokemonFRLG/SaveCardReader/Outdoors_eng_pallet-town.png"); + database.add("PokemonFRLG/SaveCardReader/OaksLab_eng_pallet-town.png"); + database.add("PokemonFRLG/SaveCardReader/Forest_eng_viridian-forest.png"); + database.add("PokemonFRLG/SaveCardReader/PokemonCenter_eng_pewter-city.png"); + database.add("PokemonFRLG/SaveCardReader/OneBadge_eng_pewter-city.png"); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h new file mode 100644 index 0000000000..8a037e0242 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h @@ -0,0 +1,45 @@ +/* Save Card Reader + * + * From: https://github.com/PokemonAutomation/ + * + * Reads where the game would be saved: the place name in blue at the top + * of the card the START menu's SAVE shows ("PALLET TOWN" over PLAYER, + * BADGES and TIME). It knows the places from a new game to Pewter City, + * in English only so far: in another language nothing is read. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_SaveCardReader_H +#define PokemonAutomation_PokemonFRLG_SaveCardReader_H + +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The card's title, as a fraction of the game screen. Measured on a +// capture of the card in Pallet Town (console B, 2026-11-01): the name +// spans x 31 to 96, y 11 to 19 of the 240x160 screen, centered. +ImageFloatBox save_card_title_box(); + +// The place on the save card: "pallet-town", "viridian-city", +// "viridian-forest", "pewter-city", "route-1" or "route-2"; empty if it +// can't be read, as in a language the reader has no names for. +std::string read_save_card_location(Logger& logger, Language language, const ImageViewRGB32& screen); + + +void add_tests_SaveCardReader(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp new file mode 100644 index 0000000000..0fd8d48b8e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp @@ -0,0 +1,320 @@ +/* Summary Moves Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" +#include "Tests/ImageUnitTest.h" +#include "Tests/TestUtils.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Tests.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_DigitReader.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_StatsReader.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryDetector.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_SummaryMovesReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// Measured on captures of the page (console B, 2026-11-02): names from +// x 163, y 24 to 32 (with the shadow); the PP's digits y 34 to 43, the +// current PP's to x 216, "/" from 217 to 224, the full PP's from 224. +constexpr double ROW_STEP = 28; +constexpr double NAME_TOP = 22; +constexpr double PP_TOP = 33; +// The cursor box's left edge, x 120 to 121, from y 20 to 44 on the top +// row: (255, 72, 0). +constexpr double CURSOR_EDGE_LEFT = 120; +constexpr double CURSOR_EDGE_TOP = 24; +constexpr double CURSOR_EDGE_HEIGHT = 16; + +// The level-up moves of Squirtle's and Magikarp's lines (pret +// pokefirered src/data/pokemon/level_up_learnsets.h), then the TMs' +// and HMs' moves not among them (src/data/items.h; Hyper Beam, Protect +// and Rain Dance are above), as the game writes them. +constexpr std::pair MOVE_NAMES[] = { + {"tackle", "Tackle"}, + {"tail-whip", "Tail Whip"}, + {"bubble", "Bubble"}, + {"withdraw", "Withdraw"}, + {"water-gun", "Water Gun"}, + {"bite", "Bite"}, + {"rapid-spin", "Rapid Spin"}, + {"protect", "Protect"}, + {"rain-dance", "Rain Dance"}, + {"skull-bash", "Skull Bash"}, + {"hydro-pump", "Hydro Pump"}, + {"splash", "Splash"}, + {"flail", "Flail"}, + {"thrash", "Thrash"}, + {"dragon-rage", "Dragon Rage"}, + {"leer", "Leer"}, + {"twister", "Twister"}, + {"dragon-dance", "Dragon Dance"}, + {"hyper-beam", "Hyper Beam"}, + {"focus-punch", "Focus Punch"}, + {"dragon-claw", "Dragon Claw"}, + {"water-pulse", "Water Pulse"}, + {"calm-mind", "Calm Mind"}, + {"roar", "Roar"}, + {"toxic", "Toxic"}, + {"hail", "Hail"}, + {"bulk-up", "Bulk Up"}, + {"bullet-seed", "Bullet Seed"}, + {"hidden-power", "Hidden Power"}, + {"sunny-day", "Sunny Day"}, + {"taunt", "Taunt"}, + {"ice-beam", "Ice Beam"}, + {"blizzard", "Blizzard"}, + {"light-screen", "Light Screen"}, + {"giga-drain", "Giga Drain"}, + {"safeguard", "Safeguard"}, + {"frustration", "Frustration"}, + {"solar-beam", "SolarBeam"}, + {"iron-tail", "Iron Tail"}, + {"thunderbolt", "Thunderbolt"}, + {"thunder", "Thunder"}, + {"earthquake", "Earthquake"}, + {"return", "Return"}, + {"dig", "Dig"}, + {"psychic", "Psychic"}, + {"shadow-ball", "Shadow Ball"}, + {"brick-break", "Brick Break"}, + {"double-team", "Double Team"}, + {"reflect", "Reflect"}, + {"shock-wave", "Shock Wave"}, + {"flamethrower", "Flamethrower"}, + {"sludge-bomb", "Sludge Bomb"}, + {"sandstorm", "Sandstorm"}, + {"fire-blast", "Fire Blast"}, + {"rock-tomb", "Rock Tomb"}, + {"aerial-ace", "Aerial Ace"}, + {"torment", "Torment"}, + {"facade", "Facade"}, + {"secret-power", "Secret Power"}, + {"rest", "Rest"}, + {"attract", "Attract"}, + {"thief", "Thief"}, + {"steel-wing", "Steel Wing"}, + {"skill-swap", "Skill Swap"}, + {"snatch", "Snatch"}, + {"overheat", "Overheat"}, + {"cut", "Cut"}, + {"fly", "Fly"}, + {"surf", "Surf"}, + {"strength", "Strength"}, + {"flash", "Flash"}, + {"rock-smash", "Rock Smash"}, + {"waterfall", "Waterfall"}, +}; + +class MoveNameMatcher : public OCR::SmallDictionaryMatcher{ +public: + static constexpr double MAX_LOG10P = -1.40; + static constexpr double MAX_LOG10P_SPREAD = 0.50; + + static const MoveNameMatcher& instance(){ + static const MoveNameMatcher matcher; + return matcher; + } + + std::string read(Logger& logger, Language language, const ImageViewRGB32& image) const{ + if (!languages()[language]){ + return ""; + } + const ImageRGB32 ready = preprocess_for_ocr(image); + const OCR::StringMatchResult result = match_substring_from_image_multifiltered( + &logger, language, ready, DARK_TEXT_FILTERS(), + MAX_LOG10P, MAX_LOG10P_SPREAD, 0.01, 0.50 + ); + return result.results.empty() ? "" : result.results.begin()->second.token; + } + +private: + MoveNameMatcher() + : SmallDictionaryMatcher(dictionary()) + {} + + static JsonObject dictionary(){ + JsonObject english; + for (const auto& [slug, name] : MOVE_NAMES){ + JsonArray names; + names.push_back(name); + english[slug] = std::move(names); + } + JsonObject json; + json["eng"] = std::move(english); + return json; + } +}; + +ImageViewRGB32 game_box(const ImageViewRGB32& screen){ + return extract_box_reference(screen, GameSettings::instance().GAME_BOX); +} + +bool cursor_red(uint32_t pixel){ + const int r = (pixel >> 16) & 0xff; + const int g = (pixel >> 8) & 0xff; + const int b = pixel & 0xff; + return r > 200 && g < 140 && b < 90; +} + +int read_pp(Logger& logger, const ImageViewRGB32& screen, const ImageFloatBox& box){ + const int pp = read_digits_waterfill_template(logger, extract_box_reference(game_box(screen), box), DigitTemplateType::StatBox); + // A move has at most 64 PP (40 with three PP Ups). + return pp >= 0 && pp <= 64 ? pp : -1; +} + +} + + +ImageFloatBox summary_move_name_box(size_t row){ + return ImageFloatBox(161.0 / 240, (NAME_TOP + ROW_STEP * double(row)) / 160, 76.0 / 240, 12.0 / 160); +} +ImageFloatBox summary_move_pp_box(size_t row){ + return ImageFloatBox(204.0 / 240, (PP_TOP + ROW_STEP * double(row)) / 160, 13.0 / 240, 11.0 / 160); +} +ImageFloatBox summary_move_max_pp_box(size_t row){ + return ImageFloatBox(224.0 / 240, (PP_TOP + ROW_STEP * double(row)) / 160, 15.0 / 240, 11.0 / 160); +} + +std::string read_summary_move_name(Logger& logger, Language language, const ImageViewRGB32& screen, size_t row){ + return read_move_name(logger, language, extract_box_reference(game_box(screen), summary_move_name_box(row))); +} + +std::string read_move_name(Logger& logger, Language language, const ImageViewRGB32& name){ + return MoveNameMatcher::instance().read(logger, language, name); +} + +std::vector read_summary_moves(Logger& logger, Language language, const ImageViewRGB32& screen){ + std::vector moves; + for (size_t row = 0; row < SUMMARY_MOVE_ROWS - 1; row++){ + std::string move = read_summary_move_name(logger, language, screen, row); + if (move.empty()){ + break; + } + moves.push_back(SummaryMove{ + .move = std::move(move), + .pp = read_pp(logger, screen, summary_move_pp_box(row)), + .max_pp = read_pp(logger, screen, summary_move_max_pp_box(row)), + }); + } + return moves; +} + +std::optional read_summary_move_cursor(const ImageViewRGB32& screen){ + const ImageViewRGB32 game = game_box(screen); + std::optional cursor; + for (size_t row = 0; row < SUMMARY_MOVE_ROWS; row++){ + const ImageFloatBox box( + CURSOR_EDGE_LEFT / 240, (CURSOR_EDGE_TOP + ROW_STEP * double(row)) / 160, + 2.0 / 240, CURSOR_EDGE_HEIGHT / 160 + ); + const ImageViewRGB32 edge = extract_box_reference(game, box); + size_t red = 0; + for (size_t y = 0; y < edge.height(); y++){ + for (size_t x = 0; x < edge.width(); x++){ + red += cursor_red(edge.pixel(x, y)) ? 1 : 0; + } + } + // Most of the edge: the box is drawn there and nowhere else. + if (red * 2 > edge.width() * edge.height()){ + if (cursor){ + return std::nullopt; + } + cursor = row; + } + } + return cursor; +} + + +namespace{ + +// A capture of a summary page, named _.png. Its +// golden file holds the page shown; on the first page the species and the +// level; on KNOWN MOVES, or a move being picked, each move's name, PP and +// full PP, then the cursor's row (from 1) or "none". +class Test_SummaryScreen : public ImageUnitTest{ +public: + Test_SummaryScreen(const std::string& image) + : ImageUnitTest("PokemonFRLG::SummaryMovesReader - " + image, {image}) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const std::vector words = parse_words(Filesystem::Path(image_paths()[0]).stem().string()); + const Language language = words.size() < 2 ? Language::None : language_code_to_enum(words.back()); + if (language == Language::None || language == Language::EndOfList){ + return "Error: filename must be _."; + } + const ImageViewRGB32& screen = images[0]; + std::vector labels; + std::vector values; + const bool info = SummaryDetector(COLOR_RED).detect(screen); + const bool skills = SummaryPage2Detector(COLOR_RED).detect(screen); + const bool moves = SummaryPage3Detector(COLOR_RED).detect(screen); + // Picking a move turns the page's dot orange: no page detector sees it. + const std::optional cursor = read_summary_move_cursor(screen); + labels.push_back("page"); + values.push_back(info ? "info" : skills ? "skills" : moves ? "moves" : cursor ? "picking" : "none"); + if (info){ + PokemonFRLG_Stats stats; + StatsReader().read_page1(logger, language, screen, stats); + labels.push_back("species"); + values.push_back(stats.name.empty() ? "none" : stats.name); + labels.push_back("level"); + values.push_back(stats.level ? std::to_string(*stats.level) : "none"); + } + if (moves || cursor){ + const std::vector known = read_summary_moves(logger, language, screen); + for (size_t c = 0; c < known.size(); c++){ + labels.push_back(std::format("move {}", c + 1)); + values.push_back(known[c].move); + labels.push_back(std::format("move {} PP", c + 1)); + values.push_back(std::to_string(known[c].pp)); + labels.push_back(std::format("move {} full PP", c + 1)); + values.push_back(std::to_string(known[c].max_pp)); + } + labels.push_back("cursor"); + values.push_back(cursor ? std::to_string(*cursor + 1) : "none"); + } + return check_against_golden_file(UNIT_TEST_RESOURCE_PATH() + image_paths()[0], labels, values); + } +}; + +} + +void add_tests_SummaryMovesReader(UnitTestDatabase& database){ + // FireRed on console B, 2026-11-02: the story's Squirtle at Lv16, not + // evolved, with WATER GUN where TACKLE was: the battle had forgotten the + // top move for Water Gun instead of BUBBLE. + database.add("PokemonFRLG/SummaryMovesReader/Info_eng.png"); + database.add("PokemonFRLG/SummaryMovesReader/Skills_eng.png"); + database.add("PokemonFRLG/SummaryMovesReader/KnownMoves_eng.png"); + // A on KNOWN MOVES: the cursor box on the top move. + database.add("PokemonFRLG/SummaryMovesReader/MoveDetail_eng.png"); + // The party menu: no summary page. + database.add("PokemonFRLG/SummaryMovesReader/PartyMenu_eng.png"); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h new file mode 100644 index 0000000000..dc4202857d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h @@ -0,0 +1,77 @@ +/* Summary Moves Reader + * + * From: https://github.com/PokemonAutomation/ + * + * Reads the KNOWN MOVES page of a Pokemon's summary: each move's name and + * PP, and which row the red cursor box is on when the page picks a move + * (A on the page, or the move to forget for a new one). pokefirered's + * pokemon_summary_screen.c draws the moves in the right pane from (160, + * 19), 28 pixels apart: the name at x 3, the PP's line at y 16 with the + * current PP right-aligned in two digits at x 46, "/" at 58 and the full + * PP at 64. The fifth row is CANCEL, or the move offered. + * + * It knows the names of the moves of the lines the FRLG AutoStory party + * comes from, and of the TMs' and HMs' moves, in English only so far: in + * another language a name is never read. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_SummaryMovesReader_H +#define PokemonAutomation_PokemonFRLG_SummaryMovesReader_H + +#include +#include +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The rows of the page: four moves, then CANCEL or the move offered. +constexpr size_t SUMMARY_MOVE_ROWS = 5; + +// Where row `row` (from 0) shows its move's name, its current PP and its +// full PP, as fractions of the game screen. +ImageFloatBox summary_move_name_box(size_t row); +ImageFloatBox summary_move_pp_box(size_t row); +ImageFloatBox summary_move_max_pp_box(size_t row); + +// The move named in row `row`: a slug such as "water-gun", in a game in +// `language`; empty for an empty slot, a move the reader has no name +// for, or a language it has no names for. +std::string read_summary_move_name(Logger& logger, Language language, const ImageViewRGB32& screen, size_t row); + +// The move named in `name`, a box around one move's name in dark text on +// a light background, such as a TM CASE row's; empty as above. +std::string read_move_name(Logger& logger, Language language, const ImageViewRGB32& name); + +struct SummaryMove{ + std::string move; + // -1 if not read. The game draws a move's PP in color once it is down + // to half, which the digit templates may not read. + int pp = -1; + int max_pp = -1; +}; + +// The moves from the top, up to the first row whose name can't be read. +std::vector read_summary_moves(Logger& logger, Language language, const ImageViewRGB32& screen); + +// The row (0 to 4) the red cursor box is on, if one shows. +std::optional read_summary_move_cursor(const ImageViewRGB32& screen); + + +void add_tests_SummaryMovesReader(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.cpp new file mode 100644 index 0000000000..f7174de9b8 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.cpp @@ -0,0 +1,76 @@ +/* Battle Flash Watcher + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTools/ImageStats.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_BattleFlashWatcher.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace std::chrono_literals; + + +namespace{ + +// On the console a flash took the screen from 145 to 98 (two thirds) and +// back within 80ms, twice in about 300ms. +constexpr std::chrono::milliseconds FLASH_WINDOW = 400ms; +constexpr double FLASH_DARKER = 0.8; // the dip is below this much of the brightness before it +constexpr double FLASH_FLOOR = 0.4; // and above this much: lower is a fade to black +constexpr double FLASH_RECOVERY = 1.1; // then the screen comes back to this much of the dip + +} + + +BattleFlashWatcher::BattleFlashWatcher(Color color) + : VisualInferenceCallback("BattleFlashWatcher") + , m_color(color) +{} + +void BattleFlashWatcher::make_overlays(VideoOverlaySet& items) const{ + items.add(m_color, GameSettings::instance().GAME_BOX); +} + +bool BattleFlashWatcher::process_frame(const ImageViewRGB32& frame, WallClock timestamp){ + const ImageViewRGB32 game_screen = extract_box_reference(frame, GameSettings::instance().GAME_BOX); + const double brightness = image_stats(game_screen).average.sum(); + while (!m_history.empty() && timestamp - m_history.front().first > FLASH_WINDOW){ + m_history.pop_front(); + } + + // The brightest frame before the screen first dips, and the darkest + // frame since. + double before = 0; + double dip = -1; + for (const auto& item : m_history){ + if (dip < 0){ + if (item.second < before * FLASH_DARKER){ + dip = item.second; + }else{ + before = std::max(before, item.second); + } + }else{ + dip = std::min(dip, item.second); + } + } + m_history.emplace_back(timestamp, brightness); + + return dip >= 0 + && dip > before * FLASH_FLOOR + && brightness > dip * FLASH_RECOVERY; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h new file mode 100644 index 0000000000..a705d3473c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h @@ -0,0 +1,46 @@ +/* Battle Flash Watcher + * + * From: https://github.com/PokemonAutomation/ + * + * Every wild battle starts with the overworld flashing dark twice, within + * half a second of the step that set it off, before the battle's own wipe. + * The wipe and the battle screen differ by map and come seconds later, so + * the flash is the earliest and the same sign of a battle everywhere. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_BattleFlashWatcher_H +#define PokemonAutomation_PokemonFRLG_BattleFlashWatcher_H + +#include +#include +#include "Common/Cpp/Color.h" +#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Fires when the game screen darkens by a fifth or more and starts to come +// back within a moment. A warp's fade, or the Switch dimming its screen, +// only darkens and so doesn't count. +class BattleFlashWatcher : public VisualInferenceCallback{ +public: + BattleFlashWatcher(Color color); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool process_frame(const ImageViewRGB32& frame, WallClock timestamp) override; + +private: + Color m_color; + // Recent brightness of the game screen. + std::deque> m_history; +}; + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp new file mode 100644 index 0000000000..0d2c517a28 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp @@ -0,0 +1,87 @@ +/* Battle HP Bar Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "PokemonFRLG_BattleHpBarReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// As fractions of the 240x160 screen: the bar's fill, 48 pixels from its +// left end. The fill is 3 rows tall, a darker one over two lighter ones, +// and the box it is in bobs down by a pixel: these 5 rows hold both +// lighter rows either way (console B, 2026-11-03). The share filled is +// counted by columns, on the lighter colors: a 2-row box on the darker +// row and one lighter one, whose pixels were counted, read 17/55 HP as +// 15% of the bar, and as 2% with the box a pixel lower. +const ImageFloatBox HP_BAR_BOX(174.0 / 240, 90.0 / 160, 48.0 / 240, 5.0 / 160); + +// A column needs this many pixels of a fill color to count as filled: a +// lighter row is about 6 pixels tall at 1080p. +constexpr size_t MIN_COLUMN_PIXELS = 3; +// Filled columns for the bar to count as seen: about half a game pixel. +// At 1 HP a single pixel of red shows (console B, 2026-11-01, 1/25 HP). +constexpr size_t MIN_SEEN_COLUMNS = 3; + +// The lighter fill colors, measured on console B's captures (2026-11-01): +// green (100, 251, 171), yellow (255, 228, 23), red (255, 113, 68). +std::optional fill_color(uint32_t pixel){ + const int r = (pixel >> 16) & 0xff; + const int g = (pixel >> 8) & 0xff; + const int b = pixel & 0xff; + if (g > 200 && r < 160 && b > 120 && b < 210){ + return HpBarColor::GREEN; + } + if (r > 220 && g > 180 && b < 80){ + return HpBarColor::YELLOW; + } + if (r > 220 && g > 80 && g < 150 && b < 110){ + return HpBarColor::RED; + } + return std::nullopt; +} + +} + + +HpBarReading read_player_hp_bar(const ImageViewRGB32& game){ + const ImageViewRGB32 bar = extract_box_reference(game, HP_BAR_BOX); + size_t counts[3] = {}; + size_t filled = 0; + for (size_t x = 0; x < bar.width(); x++){ + size_t column = 0; + for (size_t y = 0; y < bar.height(); y++){ + const std::optional color = fill_color(bar.pixel(x, y)); + if (color){ + counts[(size_t)*color]++; + column++; + } + } + if (column >= MIN_COLUMN_PIXELS){ + filled++; + } + } + HpBarReading reading; + reading.seen = filled >= MIN_SEEN_COLUMNS; + reading.fill = bar.width() == 0 ? 0 : double(filled) / bar.width(); + const size_t* most = std::max_element(counts, counts + 3); + reading.color = HpBarColor(most - counts); + return reading; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h new file mode 100644 index 0000000000..0a34d8677e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h @@ -0,0 +1,43 @@ +/* Battle HP Bar Reader + * + * From: https://github.com/PokemonAutomation/ + * + * The HP bar in the player's box on a battle screen: its color and how + * much of it is filled. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_BattleHpBarReader_H +#define PokemonAutomation_PokemonFRLG_BattleHpBarReader_H + +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +enum class HpBarColor{ + GREEN, // over half + YELLOW, // over a fifth + RED, +}; + +struct HpBarReading{ + // Some of the bar is filled. + bool seen = false; + HpBarColor color = HpBarColor::GREEN; + // The filled share of the bar's width, 0 to 1: the HP to within a + // pixel of the 48-pixel bar. + double fill = 0; +}; + +// `game`: the game's screen, the Game Box of the video. +HpBarReading read_player_hp_bar(const ImageViewRGB32& game); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp new file mode 100644 index 0000000000..a3ac1c9106 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp @@ -0,0 +1,36 @@ +/* Battle Screen Detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonFRLG_BattleScreenDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +BattleScreenDetector::BattleScreenDetector(Color color) + : m_dialog(color) + , m_menu(color) + , m_opponent(color) + , m_player(color) +{} +void BattleScreenDetector::make_overlays(VideoOverlaySet& items) const{ + m_dialog.make_overlays(items); + m_opponent.make_overlays(items); + m_player.make_overlays(items); +} +bool BattleScreenDetector::detect(const ImageViewRGB32& screen){ + if (m_menu.detect(screen)){ + return true; + } + return m_dialog.detect(screen) && (m_opponent.detect(screen) || m_player.detect(screen)); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h new file mode 100644 index 0000000000..ac4257c707 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h @@ -0,0 +1,54 @@ +/* Battle Screen Detector + * + * From: https://github.com/PokemonAutomation/ + * + * A battle on screen: the battle text box, and with it the opponent's HP + * box, the player's or the battle menu. The text box alone also reads on + * the black below a small indoor map (console B, 2026-11-01: Oak's Lab's + * mat, Viridian Forest's north gate). + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_BattleScreenDetector_H +#define PokemonAutomation_PokemonFRLG_BattleScreenDetector_H + +#include +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "CommonTools/VisualDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +class BattleScreenDetector : public StaticScreenDetector{ +public: + BattleScreenDetector(Color color = COLOR_RED); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + +private: + BattleDialogDetector m_dialog; + BattleMenuDetector m_menu; + BattleOpponentDetector m_opponent; + BattlePokemonDetector m_player; +}; + +class BattleScreenWatcher : public DetectorToFinder{ +public: + BattleScreenWatcher(Color color = COLOR_RED) + : DetectorToFinder("BattleScreenWatcher", std::chrono::milliseconds(250), color) + {} +}; + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json new file mode 100644 index 0000000000..a6cb236993 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json @@ -0,0 +1,194 @@ +{ + "name": "CeruleanCave_1F", + "source": { + "decomp_file": "data/maps/CeruleanCave_1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "########################################", + "#######...##.#########wwwwwwwww#..##..##", + "#######......#########wwwwwwwww#......##", + "#######..##..#wwwwwwwwwwwwwwwww#......##", + "##.####..##..#wwwwwwwwww#...#ww##.######", + "##.#.........#wwwwwwwwww#...#wwwwwwwwww#", + "#..#....##...#www#..........#wwwwwwwwww#", + "#..#....##...#www#..........#wwwwwwwwww#", + "#..#....##...#www#.................#www#", + "####....##.###www#...######...#....#www#", + "##.#....#www##www#...##.####.......#www#", + "##......#www##www##.###...##.......#www#", + "##......#wwwwwwww#....#...##...#####www#", + "##......#wwwwwwww#..#.##.###...###.....#", + "##..##..#wwwwwwww#.........#...#.......#", + "##..#...#www#....##......###...#.....###", + "##......#...#....####...####...#...#####", + "##......#...#..................#...#####", + "#####.###...##.#...............#...#####", + "#####..........#...............#...#####", + "#####..........#...............#...#####", + "#####..........#################...#####", + "########################################" + ], + "elevation": [ + "0000000000000000000000000000000000000000", + "0000000333003000000000111111111033003300", + "0000000333333000000000111111111033333300", + "0000000330033011111111111111111033333300", + "0030000330033011111111110444011003000000", + "0030333333333011111111110444011111111110", + "0330333300333011104444444444011111111110", + "0330333300333011104444444444011111111110", + "0330333300333011104444444444444444401110", + "0000333300300011104440000004440444401110", + "0030333301110011104440030000444444401110", + "0033333301110011100000033300444444401110", + "0033333301111111103333033300444000001110", + "0033333301111111103303003000444000333330", + "0033003301111111103333333330444033333330", + "0033033301110444400333333000444033333000", + "0033333303330444400003330000444033300000", + "0033333303330444444444444444444033300000", + "0000030003330000444444444444444033300000", + "0000033333333330444444444444444033300000", + "0000033333333330444444444444444033300000", + "0000033333333330000000000000000033300000", + "0000000000000000000000000000000000000000" + ], + "points": { + "entrance": [33, 21], + "warp_0": [33, 21], + "warp_1": [34, 2], + "warp_2": [1, 7], + "warp_3": [10, 2], + "warp_4": [5, 15], + "warp_5": [30, 10], + "warp_6": [24, 11], + "warp_7": [2, 4] + }, + "warps": [ + { + "x": 33, + "y": 21, + "enter": "walk_south", + "to_map": "CeruleanCity", + "to_point": "warp_7" + }, + { + "x": 34, + "y": 2, + "enter": "step_on", + "to_map": "CeruleanCave_2F", + "to_point": "warp_0" + }, + { + "x": 1, + "y": 7, + "enter": "step_on", + "to_map": "CeruleanCave_B1F", + "to_point": "warp_0" + }, + { + "x": 10, + "y": 2, + "enter": "step_on", + "to_map": "CeruleanCave_2F", + "to_point": "warp_1" + }, + { + "x": 5, + "y": 15, + "enter": "step_on", + "to_map": "CeruleanCave_2F", + "to_point": "warp_2" + }, + { + "x": 30, + "y": 10, + "enter": "step_on", + "to_map": "CeruleanCave_2F", + "to_point": "warp_3" + }, + { + "x": 24, + "y": 11, + "enter": "step_on", + "to_map": "CeruleanCave_2F", + "to_point": "warp_4" + }, + { + "x": 2, + "y": 4, + "enter": "step_on", + "to_map": "CeruleanCave_2F", + "to_point": "warp_5" + } + ], + "objects": [ + { + "name": "item_ball", + "kind": "item", + "x": 7, + "y": 3, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_1F_NUGGET" + }, + { + "name": "item_ball", + "kind": "item", + "x": 11, + "y": 16, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_1F_FULL_RESTORE" + }, + { + "name": "item_ball", + "kind": "item", + "x": 25, + "y": 5, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_1F_MAX_ELIXIR" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 7, + "y": 21, + "hide_flag": "FLAG_TEMP_12" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 13, + "y": 21, + "hide_flag": "FLAG_TEMP_13" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 5, + "y": 20, + "hide_flag": "FLAG_TEMP_14" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 14, + "y": 20, + "hide_flag": "FLAG_TEMP_15" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 11, + "y": 21, + "hide_flag": "FLAG_TEMP_16" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 9, + "y": 18, + "hide_flag": "FLAG_TEMP_17" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json new file mode 100644 index 0000000000..185103d4c8 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json @@ -0,0 +1,180 @@ +{ + "name": "CeruleanCave_2F", + "source": { + "decomp_file": "data/maps/CeruleanCave_2F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "########################################", + "########################################", + "########################################", + "####....####..##.....#............######", + "#######.......#..###.#.#########..######", + "####..####.####.##.#.#.........#########", + "####.....#.........###########....######", + "#######.############.........####.######", + "####.#...............#######....#.######", + "####.#################..#..###.##.######", + "####.#....#.............#...#...#.######", + "####.#.##.#.#####.#######.#####.#.######", + "####.#..#.#.....#.......#.....#.#.######", + "####.#..#.#####.#######.#####.#.########", + "####.#..#.#.....#.....#.....#.#.#.######", + "####.####.#.#####.###.#.#.#.#.#.#.######", + "####.#....#.........#.#.#.#.#.#.#.######", + "####.#.####.#########.#.#.#.###.#.######", + "####.#....#.....#.....#.#.#.....#.######", + "####.############.#####.#.#######.######", + "####..............#.....#.........######", + "########################################", + "########################################" + ], + "points": { + "warp_0": [33, 4], + "warp_1": [13, 4], + "warp_2": [7, 14], + "warp_3": [26, 9], + "warp_4": [23, 10], + "warp_5": [5, 6] + }, + "warps": [ + { + "x": 33, + "y": 4, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_1" + }, + { + "x": 13, + "y": 4, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_3" + }, + { + "x": 7, + "y": 14, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_4" + }, + { + "x": 26, + "y": 9, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_5" + }, + { + "x": 23, + "y": 10, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_6" + }, + { + "x": 5, + "y": 6, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_7" + } + ], + "objects": [ + { + "name": "item_ball", + "kind": "item", + "x": 9, + "y": 18, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_2F_PP_UP" + }, + { + "name": "item_ball", + "kind": "item", + "x": 29, + "y": 16, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_2F_ULTRA_BALL" + }, + { + "name": "item_ball", + "kind": "item", + "x": 33, + "y": 12, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_2F_FULL_RESTORE" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 33, + "y": 10, + "hide_flag": "FLAG_TEMP_12" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 33, + "y": 9, + "hide_flag": "FLAG_TEMP_13" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 25, + "y": 11, + "hide_flag": "FLAG_TEMP_14" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 28, + "y": 20, + "hide_flag": "FLAG_TEMP_15" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 30, + "y": 20, + "hide_flag": "FLAG_TEMP_16" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 9, + "y": 13, + "hide_flag": "FLAG_TEMP_17" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 23, + "y": 16, + "hide_flag": "FLAG_TEMP_18" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 13, + "y": 6, + "hide_flag": "FLAG_TEMP_19" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 4, + "y": 12, + "hide_flag": "FLAG_TEMP_1A" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 10, + "y": 20, + "hide_flag": "FLAG_TEMP_1B" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json new file mode 100644 index 0000000000..683929ff37 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json @@ -0,0 +1,159 @@ +{ + "name": "CeruleanCave_B1F", + "source": { + "decomp_file": "data/maps/CeruleanCave_B1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "########################################", + "##..............##.....############....#", + "##..............#........#######.......#", + "##..............#..####.....#######....#", + "##......#####.###..####.....#######....#", + "##......#..........########.#######.#..#", + "##..##..##........#########............#", + "##..#...###......##########............#", + "##......#wwwww##................#...####", + "#########wwwww##................#...####", + "#www############................#...####", + "#www##############.########.###.#...####", + "#www#.#.#.########........#.###.#...####", + "#www#.....########........#.....#...####", + "#www#.....########........#.....#...####", + "#www###.###wwww#......#...#.###.#...####", + "#wwwwwwwwwwwwww#......#...#.###.#...####", + "#wwwwwwwwwwwwww#......#...#.....#...####", + "#wwwwwwwwwwwwww#......#...#.....#...####", + "######wwwwwwwww##.##.##...###.###...####", + "######wwwwwwwwwwww#.......###.......####", + "######wwwwwwwwwwww##.....####.......####", + "########################################" + ], + "elevation": [ + "0000000000000000000000000000000000000000", + "0033333333333333003333300000000000033330", + "0033333333333333033333333000000033333330", + "0033333333333333033000033333000000033330", + "0033333300000300033000033333000000033330", + "0033333303333333333000000003000000030330", + "0033003300333333330000000003333333333330", + "0033033300033333300000000003333333333330", + "0033333301111100444444444444444403330000", + "0000000001111100444444444444444403330000", + "0111000000000000444444444444444403330000", + "0111000000000000000000000004000403330000", + "0111030303000000003333333304000403330000", + "0111033333000000003333333304444403330000", + "0111033333000000003333333304444403330000", + "0111000300011110444444033304000403330000", + "0111111111111110444444033304000403330000", + "0111111111111110444444033304444403330000", + "0111111111111110404444033304444403330000", + "0000001111111110030000033300000003330000", + "0000001111111111110333333300033333330000", + "0000001111111111110033333000033333330000", + "0000000000000000000000000000000000000000" + ], + "points": { + "mewtwo": [7, 12], + "warp_0": [5, 7] + }, + "warps": [ + { + "x": 5, + "y": 7, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_2" + } + ], + "objects": [ + { + "name": "item_ball", + "kind": "item", + "x": 31, + "y": 9, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_B1F_ULTRA_BALL" + }, + { + "name": "item_ball", + "kind": "item", + "x": 32, + "y": 2, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_B1F_MAX_REVIVE" + }, + { + "name": "mewtwo", + "kind": "npc", + "x": 7, + "y": 12, + "hide_flag": "FLAG_HIDE_MEWTWO" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 37, + "y": 1, + "hide_flag": "FLAG_TEMP_12" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 38, + "y": 2, + "hide_flag": "FLAG_TEMP_13" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 35, + "y": 1, + "hide_flag": "FLAG_TEMP_14" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 37, + "y": 4, + "hide_flag": "FLAG_TEMP_15" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 35, + "y": 5, + "hide_flag": "FLAG_TEMP_16" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 2, + "y": 2, + "hide_flag": "FLAG_TEMP_17" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 4, + "y": 1, + "hide_flag": "FLAG_TEMP_18" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 6, + "y": 1, + "hide_flag": "FLAG_TEMP_19" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 3, + "y": 4, + "hide_flag": "FLAG_TEMP_1A" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity.json new file mode 100644 index 0000000000..0c54fa2d7d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity.json @@ -0,0 +1,270 @@ +{ + "name": "CeruleanCity", + "source": { + "decomp_file": "data/maps/CeruleanCity/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "################wwwww#...#...#wwwwwwwwwwwwwwwwww", + "################wwwww#...#vvv#wwwwwwwwwwwwwwwwww", + "####wwwwwwwwwwwwwwwww#...#...#wwwwwwwwwwwwwwwwww", + "####wwwwwwwwwwwwwwwww#...#...#wwwwwwwwwwwwwwwwww", + "####wwwwwwwwwwwwwwwww#...#...###################", + "####www###############...#...#.........#########", + "####www#.............#...#...#.........#########", + "####www#.............#...#...#.........#########", + "####www##...##########.......#...##...##########", + "####www###############......#######...##########", + "####www###############......#######...##########", + "####www###D######D####......##D####......#######", + "#.##www#..........................#......#######", + "....www#..........................#......#######", + "....www#..........................#......#######", + "....www#.....#######..............#......#######", + "wwwwwww#...vv############.........#......#......", + "wwwwwww#.....##D#########.........#......#######", + "wwwwwww#............#####vvv#######.............", + "########............SSD##...#######.............", + "............................#######vvv#..#######", + "...........................S..#D#.....#..#......", + "......................................#..#######", + "#######...............................#..#######", + "#######.....####......................#..#######", + "#######....#####....S.................#..#######", + "#######....#####.....###############..#..#######", + "#######....#####.....###############..#..#######", + "#######....S#..#.....##D###SSD######..#..#######", + "#######...............................#..#######", + "#######...............................#..#######", + "#######...............................#..#######", + "###################S######.############..#######", + "#######..................................#######", + "#######..................................#######", + "###############....#........#....###############", + "###############....#vvvvvvvv#....###############", + "###############....#........#....###############", + "###############....#........#....###############", + "###############....#........#....###############" + ], + "elevation": [ + "000000000000000011111033303330100000000000000000", + "000000000000000011111033300000100000000000000000", + "000011111111111111111033303330100000000000000000", + "000011111111111111111033303330111111111111111111", + "000011111111111111111033303330000000000000000000", + "000011100000000000000033303330333333333000000000", + "000011103333333333333033303330333333333000000000", + "000011103333333333333033303330333333333000000000", + "000011100333000000000033333330333003330000000000", + "000011100000000000000033333300000003330000000000", + "000011100000000000000033333300000003330000000000", + "000011100000000000000033333300000003333330000000", + "030011103333333333333333333333333303333330000000", + "333311103333333333333333333333333303333330000000", + "333311103333333333333333333333333303333330000000", + "333311103333300000003333333333333303333330000000", + "111111103330000000000000033333333303333330333333", + "111111103333300000000000033333333303333330000000", + "111111103333333333330000000000000003333333333333", + "000000003333333333330000033300000003333333333333", + "333333333333333333333333333300000000000330000000", + "333333333333333333333333333033000333330330333333", + "333333333333333333333333333333333333330330000000", + "000000033333333333333333333333333333330330000000", + "000000033333000033333333333333333333330330000000", + "000000033330000033330333333333333333330330000000", + "000000033330000033333000000000000000330330000000", + "000000033330000033333000000000000000330330000000", + "000000033330033033333000000000000000330330000000", + "000000033333333333333333333333333333330330000000", + "000000033333333333333333333333333333330330000000", + "000000033333333333333333333333333333330330000000", + "000000000000000000000000003000000000000330000000", + "000000033333333333333333333333333333333330000000", + "000000033333333333333333333333333333333330000000", + "000000000000000333303333333303333000000000000000", + "000000000000000333300000000003333000000000000000", + "000000000000000333303333333303333000000000000000", + "000000000000000333303333333303333000000000000000", + "000000000000000333303333333303333000000000000000" + ], + "points": { + "warp_3": [22, 19], + "warp_7": [1, 12] + }, + "warps": [ + { + "x": 10, + "y": 11, + "enter": "walk_into" + }, + { + "x": 30, + "y": 11, + "enter": "walk_into" + }, + { + "x": 15, + "y": 17, + "enter": "walk_into" + }, + { + "x": 22, + "y": 19, + "enter": "walk_into", + "to_map": "CeruleanCity_PokemonCenter_1F", + "to_point": "warp_1" + }, + { + "x": 31, + "y": 21, + "enter": "walk_into" + }, + { + "x": 13, + "y": 28, + "enter": "cave_entrance" + }, + { + "x": 29, + "y": 28, + "enter": "walk_into" + }, + { + "x": 1, + "y": 12, + "enter": "cave_entrance", + "to_map": "CeruleanCave_1F", + "to_point": "warp_0" + }, + { + "x": 10, + "y": 8, + "enter": "walk_south" + }, + { + "x": 31, + "y": 8, + "enter": "walk_south" + }, + { + "x": 31, + "y": 9, + "enter": "walk_into" + }, + { + "x": 14, + "y": 28, + "enter": "cave_entrance" + }, + { + "x": 23, + "y": 28, + "enter": "walk_into" + }, + { + "x": 17, + "y": 11, + "enter": "walk_into" + } + ], + "objects": [ + { + "name": "policeman", + "kind": "npc", + "x": 31, + "y": 12 + }, + { + "name": "rocket_m", + "kind": "npc", + "x": 33, + "y": 6, + "hide_flag": "FLAG_HIDE_CERULEAN_ROCKET" + }, + { + "name": "little_boy", + "kind": "npc", + "x": 16, + "y": 21, + "wander": { + "x0": 16, + "y0": 18, + "x1": 16, + "y1": 24 + } + }, + { + "name": "balding_man", + "kind": "npc", + "x": 9, + "y": 23, + "wander": { + "x0": 8, + "y0": 22, + "x1": 10, + "y1": 24 + } + }, + { + "name": "slowbro", + "kind": "npc", + "x": 32, + "y": 29 + }, + { + "name": "lass", + "kind": "npc", + "x": 33, + "y": 29 + }, + { + "name": "youngster", + "kind": "npc", + "x": 34, + "y": 22 + }, + { + "name": "blue", + "kind": "npc", + "x": 22, + "y": 0, + "hide_flag": "FLAG_HIDE_CERULEAN_RIVAL" + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 26, + "y": 32, + "hide_flag": "FLAG_TEMP_13" + }, + { + "name": "woman_1", + "kind": "npc", + "x": 12, + "y": 30 + }, + { + "name": "cooltrainer_m", + "kind": "npc", + "x": 1, + "y": 13, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_GUARD" + } + ], + "flag_sets": { + "after_hall_of_fame": [ + "FLAG_HIDE_CERULEAN_CAVE_GUARD", + "FLAG_HIDE_CERULEAN_RIVAL", + "FLAG_HIDE_CERULEAN_ROCKET" + ] + }, + "connections": [ + { + "side": "north", + "to_map": "Route24", + "offset": 12 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity_PokemonCenter_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity_PokemonCenter_1F.json new file mode 100644 index 0000000000..c538b6e3b1 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity_PokemonCenter_1F.json @@ -0,0 +1,125 @@ +{ + "name": "CeruleanCity_PokemonCenter_1F", + "source": { + "decomp_file": "data/maps/CeruleanCity_PokemonCenter_1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#.#############", + "###############", + "....###..##....", + "....#######....", + "...............", + "...............", + "#..........##..", + "...........##..", + "...............", + "###############" + ], + "elevation": [ + "030000000000000", + "000000000000000", + "333300033003333", + "333300000003333", + "333333333333333", + "330333333333333", + "044033333330033", + "330333333330033", + "333333333333333", + "000000000000000" + ], + "points": { + "pc": [11, 2], + "nurse_front": [7, 4], + "warp_1": [7, 8] + }, + "warps": [ + { + "x": 6, + "y": 8, + "enter": "walk_into", + "to_map": "CeruleanCity", + "to_point": "warp_3" + }, + { + "x": 7, + "y": 8, + "enter": "walk_south", + "to_map": "CeruleanCity", + "to_point": "warp_3" + }, + { + "x": 8, + "y": 8, + "enter": "walk_into", + "to_map": "CeruleanCity", + "to_point": "warp_3" + }, + { + "x": 1, + "y": 6, + "enter": "step_on" + } + ], + "objects": [ + { + "name": "nurse", + "kind": "npc", + "x": 7, + "y": 2 + }, + { + "name": "gentleman", + "kind": "npc", + "x": 12, + "y": 5 + }, + { + "name": "rocker", + "kind": "npc", + "x": 5, + "y": 4, + "wander": { + "x0": 4, + "y0": 4, + "x1": 6, + "y1": 4 + } + }, + { + "name": "youngster", + "kind": "npc", + "x": 4, + "y": 8, + "wander": { + "x0": 3, + "y0": 8, + "x1": 5, + "y1": 8 + } + }, + { + "name": "lass", + "kind": "npc", + "x": 3, + "y": 3 + }, + { + "name": "0", + "kind": "npc", + "x": 2, + "y": 1, + "hide_flag": "FLAG_HIDE_POSTGAME_GOSSIPERS" + }, + { + "name": "0", + "kind": "npc", + "x": 3, + "y": 1, + "hide_flag": "FLAG_HIDE_POSTGAME_GOSSIPERS" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown.json new file mode 100644 index 0000000000..63540ac440 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown.json @@ -0,0 +1,122 @@ +{ + "name": "PalletTown", + "source": { + "decomp_file": "data/maps/PalletTown/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "############..##########", + "############..##########", + "##....................##", + "##....................##", + "##...#####....#####...##", + "##...#####....#####...##", + "##...#####....#####...##", + "##..S#D###...S#D###...##", + "##....................##", + "##....................##", + "##...........#######..##", + "##...####S...#######..##", + "##...........#######..##", + "##...........###D###..##", + "##...S................##", + "##....................##", + "##...........###S##...##", + "##.....wwww...........##", + "##.....wwww...........##", + "##.....wwww...........##" + ], + "elevation": [ + "000000000000330000000000", + "000000000000330000000000", + "003333333333333333333300", + "003333333333333333333300", + "003330000033330000033300", + "003330000033330000033300", + "003330000033330000033300", + "003300000033300000033300", + "003333333333333333333300", + "003333333333333333333300", + "003333333333300000003300", + "003330000033300000003300", + "003333333333300000003300", + "003333333333300000003300", + "003330333333333333333300", + "003333333333333333333300", + "003333333333300000033300", + "003333311113333333333300", + "003333311113333333333300", + "003333311113333333333300" + ], + "points": { + "oaks_lab_front": [16, 14], + "warp_0": [6, 7], + "warp_1": [15, 7], + "warp_2": [16, 13] + }, + "warps": [ + { + "x": 6, + "y": 7, + "enter": "walk_into", + "to_map": "PalletTown_PlayersHouse_1F", + "to_point": "warp_1" + }, + { + "x": 15, + "y": 7, + "enter": "walk_into", + "to_map": "PalletTown_RivalsHouse", + "to_point": "warp_0" + }, + { + "x": 16, + "y": 13, + "enter": "walk_into", + "to_map": "PalletTown_ProfessorOaksLab", + "to_point": "warp_0" + } + ], + "objects": [ + { + "name": "woman_1", + "kind": "npc", + "x": 3, + "y": 10, + "wander": { + "x0": 2, + "y0": 6, + "x1": 4, + "y1": 14 + } + }, + { + "name": "fat_man", + "kind": "npc", + "x": 13, + "y": 17, + "wander": { + "x0": 7, + "y0": 15, + "x1": 19, + "y1": 19 + } + }, + { + "name": "prof_oak", + "kind": "npc", + "x": 10, + "y": 8, + "hide_flag": "FLAG_HIDE_OAK_IN_PALLET_TOWN" + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "north", + "to_map": "Route1", + "offset": 0 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_1F.json new file mode 100644 index 0000000000..ee57a2a78a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_1F.json @@ -0,0 +1,64 @@ +{ + "name": "PalletTown_PlayersHouse_1F", + "source": { + "decomp_file": "data/maps/PalletTown_PlayersHouse_1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#############", + "#############", + "#..........##", + "#............", + "#.....##.....", + "#.....##.....", + "#............", + "##..........#", + "#............", + "#############" + ], + "points": { + "warp_1": [4, 8], + "warp_2": [10, 2] + }, + "warps": [ + { + "x": 5, + "y": 8, + "enter": "walk_into", + "to_map": "PalletTown", + "to_point": "warp_0" + }, + { + "x": 4, + "y": 8, + "enter": "walk_south", + "to_map": "PalletTown", + "to_point": "warp_0" + }, + { + "x": 10, + "y": 2, + "enter": "walk_east", + "to_map": "PalletTown_PlayersHouse_2F", + "to_point": "warp_0" + }, + { + "x": 3, + "y": 9, + "enter": "walk_into", + "to_map": "PalletTown", + "to_point": "warp_0" + } + ], + "objects": [ + { + "name": "mom", + "kind": "npc", + "x": 8, + "y": 4 + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_2F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_2F.json new file mode 100644 index 0000000000..eb5cbf8d32 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_2F.json @@ -0,0 +1,46 @@ +{ + "name": "PalletTown_PlayersHouse_2F", + "source": { + "decomp_file": "data/maps/PalletTown_PlayersHouse_2F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "############", + "###########S", + "#.......##..", + "#.......##..", + "#.2...#.....", + "#.8...#.....", + "#.#.........", + "#...........", + "#..........." + ], + "elevation": [ + "000000000000", + "000000000000", + "033333330033", + "033333330033", + "033333033333", + "003033033333", + "040403333333", + "003033333333", + "033333333333" + ], + "points": { + "start": [6, 6], + "warp_0": [10, 2] + }, + "warps": [ + { + "x": 10, + "y": 2, + "enter": "walk_west", + "to_map": "PalletTown_PlayersHouse_1F", + "to_point": "warp_2" + } + ], + "objects": [], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_ProfessorOaksLab.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_ProfessorOaksLab.json new file mode 100644 index 0000000000..158ea7c73d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_ProfessorOaksLab.json @@ -0,0 +1,127 @@ +{ + "name": "PalletTown_ProfessorOaksLab", + "source": { + "decomp_file": "data/maps/PalletTown_ProfessorOaksLab/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#############", + "######SS#####", + ".............", + "#............", + "###.....###..", + ".##..........", + ".............", + ".............", + "#####...#####", + ".............", + ".............", + ".............", + "#...........#", + "#############" + ], + "points": { + "warp_0": [6, 12] + }, + "warps": [ + { + "x": 6, + "y": 12, + "enter": "walk_south", + "to_map": "PalletTown", + "to_point": "warp_2" + }, + { + "x": 7, + "y": 12, + "enter": "walk_into", + "to_map": "PalletTown", + "to_point": "warp_2" + }, + { + "x": 5, + "y": 12, + "enter": "walk_into", + "to_map": "PalletTown", + "to_point": "warp_2" + } + ], + "objects": [ + { + "name": "scientist", + "kind": "npc", + "x": 3, + "y": 11 + }, + { + "name": "worker_f", + "kind": "npc", + "x": 2, + "y": 10, + "wander": { + "x0": 2, + "y0": 6, + "x1": 2, + "y1": 13 + } + }, + { + "name": "scientist", + "kind": "npc", + "x": 11, + "y": 10 + }, + { + "name": "prof_oak", + "kind": "npc", + "x": 6, + "y": 3, + "hide_flag": "FLAG_HIDE_OAK_IN_HIS_LAB" + }, + { + "name": "item_ball", + "kind": "item", + "x": 8, + "y": 4, + "hide_flag": "FLAG_HIDE_BULBASAUR_BALL" + }, + { + "name": "item_ball", + "kind": "item", + "x": 9, + "y": 4, + "hide_flag": "FLAG_HIDE_SQUIRTLE_BALL" + }, + { + "name": "item_ball", + "kind": "item", + "x": 10, + "y": 4, + "hide_flag": "FLAG_HIDE_CHARMANDER_BALL" + }, + { + "name": "blue", + "kind": "npc", + "x": 5, + "y": 4, + "hide_flag": "FLAG_HIDE_RIVAL_IN_LAB" + }, + { + "name": "pokedex", + "kind": "npc", + "x": 4, + "y": 1, + "hide_flag": "FLAG_HIDE_POKEDEX" + }, + { + "name": "pokedex", + "kind": "npc", + "x": 5, + "y": 1, + "hide_flag": "FLAG_HIDE_POKEDEX" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_RivalsHouse.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_RivalsHouse.json new file mode 100644 index 0000000000..bfd7bdf2e0 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_RivalsHouse.json @@ -0,0 +1,69 @@ +{ + "name": "PalletTown_RivalsHouse", + "source": { + "decomp_file": "data/maps/PalletTown_RivalsHouse/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#############", + "#############", + ".............", + ".............", + "......##.....", + "......##.....", + ".............", + ".............", + "#...........#", + "#############" + ], + "points": { + "warp_0": [4, 8] + }, + "warps": [ + { + "x": 4, + "y": 8, + "enter": "walk_south", + "to_map": "PalletTown", + "to_point": "warp_1" + }, + { + "x": 5, + "y": 8, + "enter": "walk_into", + "to_map": "PalletTown", + "to_point": "warp_1" + }, + { + "x": 3, + "y": 8, + "enter": "walk_into", + "to_map": "PalletTown", + "to_point": "warp_1" + } + ], + "objects": [ + { + "name": "daisy", + "kind": "npc", + "x": 10, + "y": 6, + "wander": { + "x0": 9, + "y0": 3, + "x1": 11, + "y1": 9 + } + }, + { + "name": "town_map", + "kind": "npc", + "x": 6, + "y": 4, + "hide_flag": "FLAG_HIDE_TOWN_MAP" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity.json new file mode 100644 index 0000000000..da09eb8aa1 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity.json @@ -0,0 +1,167 @@ +{ + "name": "PewterCity", + "source": { + "decomp_file": "data/maps/PewterCity/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "################################################", + "#######################....#####################", + "####........#################.........##########", + "####........#################.........##########", + "####........#############D######......##########", + "####........###########...............##########", + "#######.....#####.#####..#######........########", + "####vvv..vvvvvvv...Svvvvvvvvvvvvvvvvv...########", + "####....................................########", + "####............................#####...########", + "######..........................#####...########", + "######..........................#D###...########", + "######..................................########", + "######...##.#######.##..................########", + "######...#############..................########", + "######...##.#######.##..................########", + "######...##S..#D#...##....####..........########", + "######...............#....######........########", + "######...............#....SSD###........########", + "######...............#.................S########", + "######################..........................", + "######..........................................", + "######.......#########..........................", + "######.......#########....##########............", + "######.......#########....##########....########", + "######.......##SSD####....#####S#####...########", + "######....................#.........#...########", + "######....................#.........#...########", + "######..#####.............#.........#...########", + "######..#####.............#.........#...########", + "######..#D###.......S.....#vvvv.vvvv#...########", + "######..................................########", + "######..................................########", + "######..................................########", + "######..................................########", + "######..................................########", + "####################....########################", + "####################....########################", + "####################....########################", + "####################....########################" + ], + "points": { + "gym_front": [15, 17], + "warp_0": [17, 6], + "warp_1": [25, 4], + "warp_2": [15, 16], + "warp_3": [28, 18], + "warp_5": [17, 25] + }, + "warps": [ + { + "x": 17, + "y": 6, + "enter": "cave_entrance", + "to_map": "PewterCity_Museum_1F", + "to_point": "warp_1" + }, + { + "x": 25, + "y": 4, + "enter": "walk_into", + "to_map": "PewterCity_Museum_1F", + "to_point": "warp_3" + }, + { + "x": 15, + "y": 16, + "enter": "walk_into", + "to_map": "PewterCity_Gym", + "to_point": "warp_1" + }, + { + "x": 28, + "y": 18, + "enter": "walk_into", + "to_map": "PewterCity_Mart", + "to_point": "warp_1" + }, + { + "x": 33, + "y": 11, + "enter": "walk_into" + }, + { + "x": 17, + "y": 25, + "enter": "walk_into", + "to_map": "PewterCity_PokemonCenter_1F", + "to_point": "warp_1" + }, + { + "x": 9, + "y": 30, + "enter": "walk_into" + } + ], + "objects": [ + { + "name": "lass", + "kind": "npc", + "x": 6, + "y": 15 + }, + { + "name": "man", + "kind": "npc", + "x": 33, + "y": 17, + "hide_flag": "FLAG_HIDE_PEWTER_MUSEUM_GUIDE" + }, + { + "name": "fat_man", + "kind": "npc", + "x": 21, + "y": 28 + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 33, + "y": 27, + "wander": { + "x0": 31, + "y0": 27, + "x1": 35, + "y1": 27 + } + }, + { + "name": "boy", + "kind": "npc", + "x": 42, + "y": 20, + "hide_flag": "FLAG_HIDE_PEWTER_CITY_GYM_GUIDE" + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 30, + "y": 5, + "hide_flag": "FLAG_TEMP_12" + }, + { + "name": "scientist", + "kind": "npc", + "x": 46, + "y": 20, + "hide_flag": "FLAG_HIDE_PEWTER_CITY_RUNNING_SHOES_GUY" + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "south", + "to_map": "Route2", + "offset": 12 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Gym.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Gym.json new file mode 100644 index 0000000000..75afb1541c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Gym.json @@ -0,0 +1,75 @@ +{ + "name": "PewterCity_Gym", + "source": { + "decomp_file": "data/maps/PewterCity_Gym/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#############", + "####.....####", + "#############", + "#....#.#....#", + "#...........#", + "#...#...#...#", + "#...........#", + "#..#.#.#.#..#", + "##.........##", + "#...#...#...#", + "##.........##", + "#...........#", + "#...S...S...#", + "#...........#", + "#...........#", + "#############" + ], + "points": { + "brock_front": [6, 6], + "warp_1": [6, 14] + }, + "warps": [ + { + "x": 5, + "y": 14, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_2" + }, + { + "x": 6, + "y": 14, + "enter": "walk_south", + "to_map": "PewterCity", + "to_point": "warp_2" + }, + { + "x": 7, + "y": 14, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_2" + } + ], + "objects": [ + { + "name": "brock", + "kind": "npc", + "x": 6, + "y": 5 + }, + { + "name": "camper", + "kind": "npc", + "x": 3, + "y": 8 + }, + { + "name": "gym_guy", + "kind": "npc", + "x": 7, + "y": 12 + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Mart.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Mart.json new file mode 100644 index 0000000000..7b4e49dea9 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Mart.json @@ -0,0 +1,78 @@ +{ + "name": "PewterCity_Mart", + "source": { + "decomp_file": "data/maps/PewterCity_Mart/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "###########", + "###########", + "##.#......#", + "...#.......", + "####...##.#", + ".......##.#", + ".##....##.#", + "...........", + "###########" + ], + "elevation": [ + "00000000000", + "00000000000", + "00303333330", + "33003333333", + "00003330030", + "33333330030", + "30033330030", + "33333333333", + "00000000000" + ], + "points": { + "warp_1": [4, 7] + }, + "warps": [ + { + "x": 3, + "y": 7, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_3" + }, + { + "x": 4, + "y": 7, + "enter": "walk_south", + "to_map": "PewterCity", + "to_point": "warp_3" + }, + { + "x": 5, + "y": 7, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_3" + } + ], + "objects": [ + { + "name": "youngster", + "kind": "npc", + "x": 8, + "y": 2 + }, + { + "name": "boy", + "kind": "npc", + "x": 6, + "y": 4 + }, + { + "name": "clerk", + "kind": "npc", + "x": 2, + "y": 3 + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Museum_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Museum_1F.json new file mode 100644 index 0000000000..1ea83f0faf --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Museum_1F.json @@ -0,0 +1,108 @@ +{ + "name": "PewterCity_Museum_1F", + "source": { + "decomp_file": "data/maps/PewterCity_Museum_1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "############################", + "############################", + "...............#............", + "...............#......#....#", + "...####........#...........#", + "...............#............", + "...........#...#...........#", + "...####..###...###.........#", + ".........###.....#..........", + "#........###....##......##..", + "############################" + ], + "points": { + "warp_1": [14, 9], + "warp_3": [21, 9] + }, + "warps": [ + { + "x": 13, + "y": 9, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_0" + }, + { + "x": 14, + "y": 9, + "enter": "walk_south", + "to_map": "PewterCity", + "to_point": "warp_0" + }, + { + "x": 15, + "y": 9, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_0" + }, + { + "x": 21, + "y": 9, + "enter": "walk_south", + "to_map": "PewterCity", + "to_point": "warp_1" + }, + { + "x": 22, + "y": 9, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_1" + }, + { + "x": 8, + "y": 8, + "enter": "walk_east" + } + ], + "objects": [ + { + "name": "worker_m", + "kind": "npc", + "x": 16, + "y": 5 + }, + { + "name": "old_man_1", + "kind": "npc", + "x": 2, + "y": 4 + }, + { + "name": "scientist", + "kind": "npc", + "x": 21, + "y": 3 + }, + { + "name": "old_amber", + "kind": "npc", + "x": 22, + "y": 3, + "hide_flag": "FLAG_HIDE_OLD_AMBER" + }, + { + "name": "scientist", + "kind": "npc", + "x": 26, + "y": 4 + }, + { + "name": "scientist", + "kind": "npc", + "x": 26, + "y": 7 + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_PokemonCenter_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_PokemonCenter_1F.json new file mode 100644 index 0000000000..90267e027f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_PokemonCenter_1F.json @@ -0,0 +1,110 @@ +{ + "name": "PewterCity_PokemonCenter_1F", + "source": { + "decomp_file": "data/maps/PewterCity_PokemonCenter_1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#.#############", + "###############", + "....###..##....", + "....#######....", + "...............", + "...............", + "#..........##..", + "...........##..", + "...............", + "###############" + ], + "elevation": [ + "030000000000000", + "000000000000000", + "333300033003333", + "333300000003333", + "333333333333333", + "330333333333333", + "044033333330033", + "330333333330033", + "333333333333333", + "000000000000000" + ], + "points": { + "nurse_front": [7, 4], + "warp_1": [7, 8] + }, + "warps": [ + { + "x": 6, + "y": 8, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_5" + }, + { + "x": 7, + "y": 8, + "enter": "walk_south", + "to_map": "PewterCity", + "to_point": "warp_5" + }, + { + "x": 8, + "y": 8, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_5" + }, + { + "x": 1, + "y": 6, + "enter": "step_on" + } + ], + "objects": [ + { + "name": "jigglypuff", + "kind": "npc", + "x": 2, + "y": 2 + }, + { + "name": "gentleman", + "kind": "npc", + "x": 4, + "y": 8 + }, + { + "name": "nurse", + "kind": "npc", + "x": 7, + "y": 2 + }, + { + "name": "youngster", + "kind": "npc", + "x": 1, + "y": 2 + }, + { + "name": "woman_1", + "kind": "npc", + "x": 13, + "y": 2 + }, + { + "name": "gba_kid", + "kind": "npc", + "x": 10, + "y": 7 + }, + { + "name": "gba_kid", + "kind": "npc", + "x": 14, + "y": 6 + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route1.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route1.json new file mode 100644 index 0000000000..c48c746b72 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route1.json @@ -0,0 +1,91 @@ +{ + "name": "Route1", + "source": { + "decomp_file": "data/maps/Route1/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "##########....##########", + "##########....##########", + "##....................##", + "##....................##", + "##......##............##", + "##vvvvvv##vvvvvv......##", + "##......##~~~~~~~~~~~~##", + "##......##~~~~~~~~~~~~##", + "##......##~~~~~~~~~~~~##", + "##......##~~~~~~~~~~~~##", + "##vvvvvv##~~~~~~~~~~~~##", + "##......##............##", + "##....................##", + "##..............~~~~~~##", + "##..............~~~~~~##", + "####vvvvvv######~~~~~~##", + "####......######~~~~~~##", + "##..............~~~~~~##", + "##....................##", + "##....................##", + "##vv.vvvv..vvvvvvvvvvv##", + "##....................##", + "##....................##", + "##....................##", + "##..........~~~~~~....##", + "############~~~~~~....##", + "############~~~~~~vvvv##", + "##..........~~~~~~....##", + "##..........~~~~~~....##", + "##....................##", + "##....................##", + "##vvvv...Svvvvvvvvvvvv##", + "##..~~~~~~~......~~~~~##", + "##..~~~~~~~......~~~~~##", + "##~~~~~~~......~~~~~..##", + "##~~~~~~~...~~.~~~~~..##", + "############~~##########", + "##.........#~~#.......##", + "############~~##########", + "############~~##########" + ], + "points": {}, + "warps": [], + "objects": [ + { + "name": "clerk", + "kind": "npc", + "x": 6, + "y": 28, + "wander": { + "x0": 6, + "y0": 27, + "x1": 6, + "y1": 29 + } + }, + { + "name": "boy", + "kind": "npc", + "x": 19, + "y": 16, + "wander": { + "x0": 18, + "y0": 16, + "x1": 20, + "y1": 16 + } + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "north", + "to_map": "ViridianCity", + "offset": -12 + }, + { + "side": "south", + "to_map": "PalletTown", + "offset": 0 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2.json new file mode 100644 index 0000000000..706949faeb --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2.json @@ -0,0 +1,211 @@ +{ + "name": "Route2", + "source": { + "decomp_file": "data/maps/Route2/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "########....############", + "########....############", + "##~~~~~~~...############", + "##~~~~~~~...#.........##", + "##~~~~~~~...#.........##", + "##~~~~~~~...#.........##", + "##~~~~~~~...#########.##", + "##~~~~~~~...#########.##", + "##~~~~~~~...#########.##", + "##..........#########.##", + "##..........#########.##", + "##..........#####.###.##", + "##..........#.S.......##", + "####....###.#.........##", + "###########...........##", + "##########............##", + "##############........##", + "##############........##", + "##############........##", + "##############........##", + "##############........##", + "###################...##", + "#################D#...##", + "##############........##", + "################......##", + "################......##", + "##################.#####", + "################......##", + "################......##", + "################......##", + "################......##", + "################......##", + "################vvv.vv##", + "################......##", + "################......##", + "################......##", + "################......##", + "################vvv.vv##", + "################......##", + "################......##", + "################......##", + "#################....###", + "########################", + "########################", + "########################", + "##........##############", + "##################..####", + "#################....###", + "################......##", + "################......##", + "###.####.#######......##", + "#####..#########vvv.vv##", + "####....########......##", + "##............##......##", + "##............##......##", + "##vvvvvvvvv...##......##", + "##....~~~~~~~.##......##", + "##....~~~~~~~.##vv.vvv##", + "##....~~~~~~~.##......##", + "##....~~~~~~~.##......##", + "##....~~~~~~~.##......##", + "##............##......##", + "##....................##", + "##....##########......##", + "##....##########......##", + "##....##########......##", + "##....##########......##", + "##............##......##", + "##............##......##", + "##....................##", + "##vvvvvvv..vvv..vv.vvv##", + "##............##......##", + "####..........##......##", + "####...S......##......##", + "####..........##......##", + "####..........##......##", + "####..........##......##", + "####..........##......##", + "#######.......##########", + "#######.....############" + ], + "points": { + "warp_0": [5, 13], + "warp_2": [5, 51] + }, + "warps": [ + { + "x": 5, + "y": 13, + "enter": "walk_south", + "to_map": "Route2_ViridianForest_NorthEntrance", + "to_point": "warp_3" + }, + { + "x": 6, + "y": 13, + "enter": "walk_south", + "to_map": "Route2_ViridianForest_NorthEntrance", + "to_point": "warp_3" + }, + { + "x": 5, + "y": 51, + "enter": "cave_entrance", + "to_map": "Route2_ViridianForest_SouthEntrance", + "to_point": "warp_1" + }, + { + "x": 17, + "y": 11, + "enter": "cave_entrance" + }, + { + "x": 17, + "y": 22, + "enter": "walk_into" + }, + { + "x": 18, + "y": 46, + "enter": "cave_entrance" + }, + { + "x": 18, + "y": 41, + "enter": "walk_south" + }, + { + "x": 19, + "y": 41, + "enter": "walk_south" + }, + { + "x": 19, + "y": 46, + "enter": "cave_entrance" + }, + { + "x": 6, + "y": 51, + "enter": "cave_entrance", + "to_map": "Route2_ViridianForest_SouthEntrance", + "to_point": "warp_1" + } + ], + "objects": [ + { + "name": "cut_tree", + "kind": "npc", + "x": 16, + "y": 62, + "hide_flag": "FLAG_TEMP_14" + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 15, + "y": 69, + "hide_flag": "FLAG_TEMP_13" + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 11, + "y": 13, + "hide_flag": "FLAG_TEMP_15" + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 18, + "y": 26, + "hide_flag": "FLAG_TEMP_16" + }, + { + "name": "item_ball", + "kind": "item", + "x": 17, + "y": 54, + "hide_flag": "FLAG_HIDE_ROUTE2_ETHER" + }, + { + "name": "item_ball", + "kind": "item", + "x": 17, + "y": 64, + "hide_flag": "FLAG_HIDE_ROUTE2_PARALYZE_HEAL" + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "north", + "to_map": "PewterCity", + "offset": -12 + }, + { + "side": "south", + "to_map": "ViridianCity", + "offset": -12 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route22.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route22.json new file mode 100644 index 0000000000..be2d5629b2 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route22.json @@ -0,0 +1,90 @@ +{ + "name": "Route22", + "source": { + "decomp_file": "data/maps/Route22/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#############################################...", + "###########################################.#...", + "##################################........#.###.", + "##################################vvvv.vvv#...##", + "######################....................#.....", + "########D######...........................######", + "#####.......###.........................##......", + "###...........#.............######......##......", + "###...........#vvvvvvvwwwwww######vv..vv##......", + "###vvvvvvv..vv#~~~~~~~wwwwww######~~~~~~##......", + "###...........#~~~~~~~wwwwww######~~~~~~##....##", + "###...........#~~~~~~~wwwwww######~~~~~~##....##", + "####...S#######~~~~~~~......######~~~~~~##....##", + "####...........~~~~~~~......######~~~~~~##....##", + "####........................######............##", + "####vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv..vvvvv##", + "####..........................................##", + "####..........................................##", + "####..........................................##", + "################################################", + "################################################", + "################################################", + "################################################", + "################################################" + ], + "elevation": [ + "000000000000000000000000000000000000000000000333", + "000000000000000000000000000000000000000000030333", + "000000000000000000000000000000000033333333030003", + "000000000000000000000000000000000000003000033300", + "000000000000000000000033333333333333333333033333", + "000000000000000333333333333333333333333333000000", + "000003333333000333333333333333333333333300333333", + "000333333333330333333333333300000033333300333333", + "000333333333330000000011111100000000330000333333", + "000000000033000333333311111100000033333300333333", + "000333333333330333333311111100000033333300333300", + "000333333333330333333311111100000033333300333300", + "000033300000000333333333333300000033333300333300", + "000033333333333333333333333300000033333300333300", + "000033333333333333333333333300000033333333333300", + "000000000000000000000000000000000000000330000000", + "000033333333333333333333333333333333333333333300", + "000033333333333333333333333333333333333333333300", + "000033333333333333333333333333333333333333333300", + "000000000000000000000000000000000000000000000000", + "000000000000000000000000000000000000000000000000", + "000000000000000000000000000000000000000000000000", + "000000000000000000000000000000000000000000000000", + "000000000000000000000000000000000000000000000000" + ], + "points": {}, + "warps": [ + { + "x": 8, + "y": 5, + "enter": "walk_into" + }, + { + "x": 9, + "y": 5, + "enter": "walk_into" + } + ], + "objects": [ + { + "name": "blue", + "kind": "npc", + "x": 25, + "y": 4, + "hide_flag": "FLAG_HIDE_ROUTE_22_RIVAL" + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "east", + "to_map": "ViridianCity", + "offset": -10 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route24.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route24.json new file mode 100644 index 0000000000..59d1789c3c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route24.json @@ -0,0 +1,154 @@ +{ + "name": "Route24", + "source": { + "decomp_file": "data/maps/Route24/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "########################", + "########################", + "########################", + "####.........>...<......", + "####.........>...<......", + "####.........>...<......", + "###vvvv..vvvv#...#vvvvvv", + "###.....................", + "###.....................", + "###.....................", + "###..........###########", + "###..........#..........", + "###..........#...#######", + "###..........#...#######", + "###..........#...#######", + "###..........#...#######", + "###...www#...#...#######", + "###...www#...#...#######", + "###...www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#wwwwww", + "###~~~www#...#...#wwwwww", + "###~~~www#...#...#wwwwww", + "###~~~www#...#...#wwwwww", + "###~~~www#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww" + ], + "elevation": [ + "000000000000000000000000", + "000000000000000000000000", + "000000000000000000000000", + "000033333333303330333333", + "000033333333303330333333", + "000033333333303330333333", + "000000033000003330000000", + "000333333333333333333333", + "000333333333333333333333", + "000333333333333333333333", + "000333333333300000000000", + "000333333333303333333333", + "000333333333303330000000", + "000333333333303330000000", + "000333333333303330000000", + "000333333333303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330111111", + "000333111033303330100000", + "000333111033303330100000", + "000333111033303330100000", + "000333111033303330100000", + "000011111033303330100000", + "000011111033303330100000", + "000011111033303330100000", + "000011111033303330100000", + "000011111033303330100000", + "000011111033303330100000", + "000011111033303330100000", + "000011111033303330100000" + ], + "points": {}, + "warps": [], + "objects": [ + { + "name": "man", + "kind": "npc", + "x": 12, + "y": 15, + "hide_flag": "FLAG_HIDE_NUGGET_BRIDGE_ROCKET" + }, + { + "name": "camper", + "kind": "npc", + "x": 12, + "y": 19 + }, + { + "name": "lass", + "kind": "npc", + "x": 10, + "y": 22 + }, + { + "name": "youngster", + "kind": "npc", + "x": 12, + "y": 25 + }, + { + "name": "lass", + "kind": "npc", + "x": 10, + "y": 28 + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 12, + "y": 31 + }, + { + "name": "camper", + "kind": "npc", + "x": 5, + "y": 21 + }, + { + "name": "item_ball", + "kind": "item", + "x": 11, + "y": 4, + "hide_flag": "FLAG_HIDE_ROUTE24_TM45" + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "south", + "to_map": "CeruleanCity", + "offset": -12 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_NorthEntrance.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_NorthEntrance.json new file mode 100644 index 0000000000..021edbb11d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_NorthEntrance.json @@ -0,0 +1,78 @@ +{ + "name": "Route2_ViridianForest_NorthEntrance", + "source": { + "decomp_file": "data/maps/Route2_ViridianForest_NorthEntrance/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "###############", + "#######.#######", + "##...#...#...##", + "#.............#", + "#..........##.#", + "###........##.#", + "#.............#", + "#..........##.#", + "###........##.#", + "#.............#", + "#.............#", + "###############" + ], + "points": { + "warp_1": [7, 10], + "warp_3": [7, 1] + }, + "warps": [ + { + "x": 6, + "y": 10, + "enter": "walk_into", + "to_map": "ViridianForest", + "to_point": "warp_2" + }, + { + "x": 7, + "y": 10, + "enter": "walk_south", + "to_map": "ViridianForest", + "to_point": "warp_2" + }, + { + "x": 8, + "y": 10, + "enter": "walk_into", + "to_map": "ViridianForest", + "to_point": "warp_2" + }, + { + "x": 7, + "y": 1, + "enter": "cave_entrance", + "to_map": "Route2", + "to_point": "warp_0" + } + ], + "objects": [ + { + "name": "youngster", + "kind": "npc", + "x": 5, + "y": 4 + }, + { + "name": "old_man_1", + "kind": "npc", + "x": 4, + "y": 7 + }, + { + "name": "cooltrainer_f", + "kind": "npc", + "x": 10, + "y": 5 + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_SouthEntrance.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_SouthEntrance.json new file mode 100644 index 0000000000..3b00abc4eb --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_SouthEntrance.json @@ -0,0 +1,78 @@ +{ + "name": "Route2_ViridianForest_SouthEntrance", + "source": { + "decomp_file": "data/maps/Route2_ViridianForest_SouthEntrance/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "###############", + "#######.#######", + "##...#...#...##", + "#.............#", + "#..........##.#", + "###........##.#", + "#.............#", + "#..........##.#", + "###........##.#", + "#.............#", + "#.............#", + "###############" + ], + "points": { + "warp_1": [7, 10], + "warp_3": [7, 1] + }, + "warps": [ + { + "x": 6, + "y": 10, + "enter": "walk_into", + "to_map": "Route2", + "to_point": "warp_2" + }, + { + "x": 7, + "y": 10, + "enter": "walk_south", + "to_map": "Route2", + "to_point": "warp_2" + }, + { + "x": 8, + "y": 10, + "enter": "walk_into", + "to_map": "Route2", + "to_point": "warp_2" + }, + { + "x": 7, + "y": 1, + "enter": "cave_entrance", + "to_map": "ViridianForest", + "to_point": "warp_0" + } + ], + "objects": [ + { + "name": "woman_2", + "kind": "npc", + "x": 10, + "y": 6 + }, + { + "name": "woman_1", + "kind": "npc", + "x": 4, + "y": 7, + "wander": { + "x0": 3, + "y0": 6, + "x1": 5, + "y1": 8 + } + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity.json new file mode 100644 index 0000000000..5bf976082a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity.json @@ -0,0 +1,216 @@ +{ + "name": "ViridianCity", + "source": { + "decomp_file": "data/maps/ViridianCity/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "###################.....########################", + "###################....S########################", + "###################.....########################", + "###################.....########################", + "###################.....####..............######", + "########..................................######", + "########.##########.......................######", + "########.###########.............######...######", + "########.##########..............######...######", + "########.###########...######....######...######", + "########.##########.....#####...S..#D#....######", + "########.###########...##D###.............######", + "########.##########........##vvvvvvvvvvvvv######", + "########.###########......................######", + "########.##########.......................######", + "######...###########.........###################", + ".........##########.S..######.............######", + "........................#####.....####....######", + ".......................##D###.....####....######", + "..................................SSD#....######", + "#######...................................######", + "#######...................................######", + "#######...................................######", + "###########.............#####.............######", + "###########.##..........#####.............######", + "#######.....##..........#####.............######", + "#######....wwwwww.......SSD##.............######", + "#######....wwwwww.........................######", + "#######....wwwwww.........................######", + "#######....wwwwww.........................######", + "#######vvvvwwwwwwvvv...vvvvvvvvvvvvvvvvvvv######", + "#######.............S.....................######", + "#######...................................######", + "#######...................................######", + "##############............................######", + "##############............................######", + "######################....######################", + "######################....######################", + "######################....######################", + "######################....######################" + ], + "elevation": [ + "000000000000000000033333000000000000000000000000", + "000000000000000000033330000000000000000000000000", + "000000000000000000033333000000000000000000000000", + "000000000000000000033333000000000000000000000000", + "000000000000000000033333000033333333333333000000", + "000000003333333333333333333333333333333333000000", + "000000003000000000033333333333333333333333000000", + "000000003000000000003333333333333000000333000000", + "000000003000000000033333333333333000000333000000", + "000000003000000000003330000003333000000333000000", + "000000003000000000033333000003330330003333000000", + "000000003000000000003330000003333333333333000000", + "000000003000000000033333333000000000000000000000", + "000000003000000000003333333333333333333333000000", + "000000003000000000033333333333333333333333000000", + "000000333000000000003333333330000000000000000000", + "333333333000000000030330000003333333333333000000", + "333333333333333333333333000003333300003333000000", + "333333333333333333333330000003333300003333000000", + "333333333333333333333333333333333300003333000000", + "000000033333333333333333333333333333333333000000", + "000000033333333333333333333333333333333333000000", + "000000033333333333333333333333333333333333000000", + "000000000003333333333333000003333333333333000000", + "000000000003003333333333000003333333333333000000", + "000000033333003333333333000003333333333333000000", + "000000033331111113333333000003333333333333000000", + "000000033331111113333333333333333333333333000000", + "000000033331111113333333333333333333333333000000", + "000000033331111113333333333333333333333333000000", + "000000000001111110003330000000000000000000000000", + "000000033333333333330333333333333333333333000000", + "000000033333333333333333333333333333333333000000", + "000000033333333333333333333333333333333333000000", + "000000000000003333333333333333333333333333000000", + "000000000000003333333333333333333333333333000000", + "000000000000000000000033330000000000000000000000", + "000000000000000000000033330000000000000000000000", + "000000000000000000000033330000000000000000000000", + "000000000000000000000033330000000000000000000000" + ], + "points": { + "warp_0": [26, 26], + "warp_4": [36, 19] + }, + "warps": [ + { + "x": 26, + "y": 26, + "enter": "walk_into", + "to_map": "ViridianCity_PokemonCenter_1F", + "to_point": "warp_1" + }, + { + "x": 25, + "y": 11, + "enter": "walk_into" + }, + { + "x": 36, + "y": 10, + "enter": "walk_into" + }, + { + "x": 25, + "y": 18, + "enter": "walk_into" + }, + { + "x": 36, + "y": 19, + "enter": "walk_into", + "to_map": "ViridianCity_Mart", + "to_point": "warp_1" + } + ], + "objects": [ + { + "name": "fat_man", + "kind": "npc", + "x": 8, + "y": 26 + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 11, + "y": 24, + "hide_flag": "FLAG_TEMP_11" + }, + { + "name": "old_man_1", + "kind": "npc", + "x": 34, + "y": 11 + }, + { + "name": "var_0", + "kind": "npc", + "x": 21, + "y": 6 + }, + { + "name": "woman_3", + "kind": "npc", + "x": 20, + "y": 12 + }, + { + "name": "youngster", + "kind": "npc", + "x": 33, + "y": 26, + "wander": { + "x0": 33, + "y0": 24, + "x1": 33, + "y1": 28 + } + }, + { + "name": "boy", + "kind": "npc", + "x": 16, + "y": 22, + "wander": { + "x0": 15, + "y0": 20, + "x1": 17, + "y1": 24 + } + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 18, + "y": 5, + "hide_flag": "FLAG_TEMP_12" + }, + { + "name": "item_ball", + "kind": "item", + "x": 17, + "y": 5, + "hide_flag": "FLAG_HIDE_VIRIDIAN_CITY_POTION" + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "north", + "to_map": "Route2", + "offset": 12 + }, + { + "side": "south", + "to_map": "Route1", + "offset": 12 + }, + { + "side": "west", + "to_map": "Route22", + "offset": 10 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_Mart.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_Mart.json new file mode 100644 index 0000000000..1078ec3405 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_Mart.json @@ -0,0 +1,91 @@ +{ + "name": "ViridianCity_Mart", + "source": { + "decomp_file": "data/maps/ViridianCity_Mart/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "###########", + "###########", + "##.#......#", + "...#.......", + "####...##.#", + ".......##.#", + ".##....##.#", + "...........", + "###########" + ], + "elevation": [ + "00000000000", + "00000000000", + "00303333330", + "33003333333", + "00003330030", + "33333330030", + "30033330030", + "33333333333", + "00000000000" + ], + "points": { + "clerk_front": [4, 3], + "warp_1": [4, 7] + }, + "warps": [ + { + "x": 3, + "y": 7, + "enter": "walk_into", + "to_map": "ViridianCity", + "to_point": "warp_4" + }, + { + "x": 4, + "y": 7, + "enter": "walk_south", + "to_map": "ViridianCity", + "to_point": "warp_4" + }, + { + "x": 5, + "y": 7, + "enter": "walk_into", + "to_map": "ViridianCity", + "to_point": "warp_4" + } + ], + "objects": [ + { + "name": "clerk", + "kind": "npc", + "x": 2, + "y": 3 + }, + { + "name": "youngster", + "kind": "npc", + "x": 6, + "y": 2, + "wander": { + "x0": 5, + "y0": 1, + "x1": 7, + "y1": 3 + } + }, + { + "name": "woman_1", + "kind": "npc", + "x": 9, + "y": 5, + "wander": { + "x0": 9, + "y0": 4, + "x1": 9, + "y1": 6 + } + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_PokemonCenter_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_PokemonCenter_1F.json new file mode 100644 index 0000000000..63a2707d8f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_PokemonCenter_1F.json @@ -0,0 +1,98 @@ +{ + "name": "ViridianCity_PokemonCenter_1F", + "source": { + "decomp_file": "data/maps/ViridianCity_PokemonCenter_1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#.#############", + "###############", + "....###..##....", + "....#######....", + "...............", + "...............", + "#..........##..", + "...........##..", + "...............", + "###############" + ], + "elevation": [ + "030000000000000", + "000000000000000", + "333300033003333", + "333300000003333", + "333333333333333", + "330333333333333", + "044033333330033", + "330333333330033", + "333333333333333", + "000000000000000" + ], + "points": { + "nurse_front": [7, 4], + "warp_1": [7, 8] + }, + "warps": [ + { + "x": 6, + "y": 8, + "enter": "walk_into", + "to_map": "ViridianCity", + "to_point": "warp_0" + }, + { + "x": 7, + "y": 8, + "enter": "walk_south", + "to_map": "ViridianCity", + "to_point": "warp_0" + }, + { + "x": 8, + "y": 8, + "enter": "walk_into", + "to_map": "ViridianCity", + "to_point": "warp_0" + }, + { + "x": 1, + "y": 6, + "enter": "step_on" + } + ], + "objects": [ + { + "name": "nurse", + "kind": "npc", + "x": 7, + "y": 2 + }, + { + "name": "gentleman", + "kind": "npc", + "x": 12, + "y": 5 + }, + { + "name": "boy", + "kind": "npc", + "x": 4, + "y": 7 + }, + { + "name": "youngster", + "kind": "npc", + "x": 2, + "y": 3, + "wander": { + "x0": 1, + "y0": 2, + "x1": 3, + "y1": 4 + } + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianForest.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianForest.json new file mode 100644 index 0000000000..93352339c5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianForest.json @@ -0,0 +1,201 @@ +{ + "name": "ViridianForest", + "source": { + "decomp_file": "data/maps/ViridianForest/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "######################################################", + "######################################################", + "######################################################", + "######################################################", + "######################################################", + "###########.............###........................###", + "###########.............###........................###", + "###########.............###........................###", + "#..#####..#.............###.....###############....###", + "####...####.............###.....###############....###", + "####...####.............###.....###############....###", + "####...####.....###.....###.....###############....###", + "####..S####~~~~~###~~~~~###~~~~~###############....###", + "###~~~~~###~~~~~###~~~~~###~~~~~###############....###", + "###~~~~~###~~~~~###~~~~~###~~~~~###############....###", + "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~~.............###", + "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~~.............###", + "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~~.............###", + "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~~.......#########", + "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~........#########", + "###~~~~~###~~~~~###~~~~~###~~~~~~######......#########", + "###~~~~~###~~~~~###~~~~~###...~~~######......#########", + "###~~~~~###~~~~~###.....###......######......#########", + "###~~~~~###~~~~~###..............######......#########", + "###~~~~~###~~~~~#####............######......#########", + "###~~~~~###~~~~~#####............######............###", + "###~~~~~###~~~~~~~#####################....S.......###", + "###~~~~~...~~~~~~~#####################............###", + "###...............#####################............###", + "###......S........#####################~~~~........###", + "###...............#####################~~~~~###....###", + "###.....................###############~~~~~###....###", + "###.....................###############~~~~~###....###", + "###.....................###############~~~~~###....###", + "##################......###############~~~~~###....###", + "##################......###############~~~~~###....###", + "#######################################~~~~~###....###", + "#######################################~~~~~###....###", + "#######################################~~~~~###....###", + "###~~~~~~~~~~~~~~~#####################~~~~~###....###", + "###~~~~~~~~~~~~~~~#####################~~~~~###....###", + "###~~~~~~~~~~~~~~~#####################~~~~~###....###", + "###~~~~~~~~~~~~~~~#####################~~~~~###....###", + "###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~######~~~~........###", + "############~~~~~~~~~~~~~~~~S..~~######~~~.........###", + "############~~~~~~~~~~~~~~~~...~~######~~~.........###", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "###~~~~~~~~~..~~~~~~~~~~~~~~###~~~~~~~~~~~...~~~~~~###", + "###~~~~~~~~~..~~~~~~~~~~~~~~###~~~~~~~~~~~...~~~~~~###", + "###~~~~~~~~~...~~~~~~~~~~~~.###.~~~~~~~~~...~~~~~~~###", + "###~~~~~~~~~....~~~~~~~~~~.......~~~~~~~....~~~~~~~###", + "###~~~~~~~~............................S....~~~~~~~###", + "###~~~~~~~~....................S...........~~~~~~~~###", + "###~~~~~~~~................................~~~~~~~~###", + "###########################......#####################", + "######################################################", + "######################################################", + "######################################################", + "######################################################", + "######################################################", + "######################################################" + ], + "points": { + "warp_0": [29, 62], + "warp_2": [5, 9] + }, + "warps": [ + { + "x": 29, + "y": 62, + "enter": "walk_south", + "to_map": "Route2_ViridianForest_SouthEntrance", + "to_point": "warp_3" + }, + { + "x": 28, + "y": 62, + "enter": "walk_south", + "to_map": "Route2_ViridianForest_SouthEntrance", + "to_point": "warp_3" + }, + { + "x": 5, + "y": 9, + "enter": "cave_entrance", + "to_map": "Route2_ViridianForest_NorthEntrance", + "to_point": "warp_1" + }, + { + "x": 6, + "y": 9, + "enter": "cave_entrance", + "to_map": "Route2_ViridianForest_NorthEntrance", + "to_point": "warp_1" + }, + { + "x": 30, + "y": 62, + "enter": "walk_south", + "to_map": "Route2_ViridianForest_SouthEntrance", + "to_point": "warp_3" + }, + { + "x": 4, + "y": 9, + "enter": "cave_entrance", + "to_map": "Route2_ViridianForest_NorthEntrance", + "to_point": "warp_1" + } + ], + "objects": [ + { + "name": "youngster", + "kind": "npc", + "x": 29, + "y": 58 + }, + { + "name": "boy", + "kind": "npc", + "x": 45, + "y": 58 + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 47, + "y": 45 + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 47, + "y": 29 + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 7, + "y": 22 + }, + { + "name": "item_ball", + "kind": "item", + "x": 5, + "y": 41, + "hide_flag": "FLAG_HIDE_VIRIDIAN_FOREST_POKE_BALL" + }, + { + "name": "item_ball", + "kind": "item", + "x": 40, + "y": 21, + "hide_flag": "FLAG_HIDE_VIRIDIAN_FOREST_ANTIDOTE" + }, + { + "name": "item_ball", + "kind": "item", + "x": 21, + "y": 34, + "hide_flag": "FLAG_HIDE_VIRIDIAN_FOREST_POTION" + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 43, + "y": 6 + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 16, + "y": 5 + }, + { + "name": "item_ball", + "kind": "item", + "x": 49, + "y": 60, + "hide_flag": "FLAG_HIDE_VIRIDIAN_FOREST_POTION_2" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp new file mode 100644 index 0000000000..e0fc1a339e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp @@ -0,0 +1,252 @@ +/* Overworld Map + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Common/Cpp/Exceptions.h" +#include "PokemonFRLG_OverworldMap.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +bool in_bounds(const MapData& map, const TilePos& point){ + return map.tiles.contains(point); +} +TileKind tile_at(const MapData& map, const TilePos& point){ + return in_bounds(map, point) ? map.tiles.at(point) : TileKind::WALL; +} +uint8_t elevation_at(const MapData& map, const TilePos& point){ + if (!in_bounds(map, point)){ + return ELEVATION_IGNORED; + } + return map.elevation ? map.elevation->at(point) : ELEVATION_GROUND; +} + +bool is_wall(const MapData& map, const TilePos& point){ + const TileKind tile = tile_at(map, point); + return tile == TileKind::WALL || tile == TileKind::DOOR || tile == TileKind::SIGN || is_ledge(map, point); +} +bool is_ledge(const MapData& map, const TilePos& point){ + switch (tile_at(map, point)){ + case TileKind::LEDGE_NORTH: + case TileKind::LEDGE_SOUTH: + case TileKind::LEDGE_WEST: + case TileKind::LEDGE_EAST: + return true; + default: + return false; + } +} +bool is_water(const MapData& map, const TilePos& point){ + return tile_at(map, point) == TileKind::WATER; +} +bool is_tall_grass(const MapData& map, const TilePos& point){ + return tile_at(map, point) == TileKind::TALL_GRASS; +} + +namespace{ + +// The tile closed on its `side` edge. +TileKind closed_side(Direction side){ + switch (side){ + case Direction::NORTH: + return TileKind::CLOSED_NORTH; + case Direction::SOUTH: + return TileKind::CLOSED_SOUTH; + case Direction::EAST: + return TileKind::CLOSED_EAST; + case Direction::WEST: + return TileKind::CLOSED_WEST; + } + return TileKind::WALL; +} +Direction opposite(Direction direction){ + switch (direction){ + case Direction::NORTH: + return Direction::SOUTH; + case Direction::SOUTH: + return Direction::NORTH; + case Direction::EAST: + return Direction::WEST; + case Direction::WEST: + return Direction::EAST; + } + return direction; +} + +// How the warp on this tile is entered, if there is one. +std::optional warp_entry(const MapData& map, const TilePos& point){ + const MapWarp* warp = warp_at(map, point); + if (warp == nullptr){ + return std::nullopt; + } + return warp->enter; +} + +} + +bool blocks_entering(const MapData& map, const TilePos& point, Direction direction){ + // Moving south enters by the north edge. + return tile_at(map, point) == closed_side(opposite(direction)); +} +bool blocks_leaving(const MapData& map, const TilePos& point, Direction direction){ + return tile_at(map, point) == closed_side(direction); +} + +bool warps_on_step(const MapData& map, const TilePos& point){ + const std::optional entry = warp_entry(map, point); + return entry == WarpEntry::STEP_ON || entry == WarpEntry::CAVE_ENTRANCE; +} +bool is_door(const MapData& map, const TilePos& point){ + return tile_at(map, point) == TileKind::DOOR; +} +std::optional exit_mat(const MapData& map, const TilePos& point){ + const std::optional entry = warp_entry(map, point); + if (!entry){ + return std::nullopt; + } + switch (*entry){ + case WarpEntry::WALK_NORTH: + return Direction::NORTH; + case WarpEntry::WALK_SOUTH: + return Direction::SOUTH; + case WarpEntry::WALK_WEST: + return Direction::WEST; + case WarpEntry::WALK_EAST: + return Direction::EAST; + default: + return std::nullopt; + } +} +bool walks_out_on_arrival(const MapData& map, const TilePos& point){ + return is_door(map, point) || warp_entry(map, point) == WarpEntry::CAVE_ENTRANCE; +} + +void hide_objects(MapData& map, const std::set& flags){ + std::vector shown; + for (const MapObject& object : map.objects){ + if (!object.hide_flag || flags.count(*object.hide_flag) == 0){ + shown.push_back(object); + } + } + map.objects = std::move(shown); +} + +namespace{ + +// The tiles `object` may stand on: its wander box, or its own tile. +Pokemon::TileBox standing_box(const MapObject& object){ + return object.wander.value_or( + Pokemon::TileBox{.x0 = object.x, .y0 = object.y, .x1 = object.x, .y1 = object.y} + ); +} + +// Whether `trainer`, standing on `from`, sees `tile` any way it looks. +bool sees_from(const MapData& map, const Pokemon::MapTrainer& trainer, const TilePos& from, const TilePos& tile){ + for (Direction look : trainer.looks){ + TilePos seen = from; + for (int c = 0; c < trainer.sight && !is_wall(map, seen.next(look)); c++){ + seen = seen.next(look); + if (seen == tile){ + return true; + } + } + } + return false; +} + +} + +const MapObject* object_at(const MapData& map, const TilePos& point){ + for (const MapObject& object : map.objects){ + const Pokemon::TileBox box = standing_box(object); + if (box.x0 <= point.x && point.x <= box.x1 && box.y0 <= point.y && point.y <= box.y1){ + return &object; + } + } + return nullptr; +} + +bool trainer_may_see(const MapData& map, const MapObject& object, const TilePos& tile){ + if (!object.trainer){ + return false; + } + const Pokemon::TileBox box = standing_box(object); + for (int y = box.y0; y <= box.y1; y++){ + for (int x = box.x0; x <= box.x1; x++){ + if (sees_from(map, *object.trainer, TilePos{x, y}, tile)){ + return true; + } + } + } + return false; +} + + + +StepKind classify_step(const MapData& map, const PlayerState& state, Direction direction){ + return classify_step_onto(map, state, direction, map, state.position.next(direction)); +} + +StepKind classify_step_onto( + const MapData& from, const PlayerState& state, Direction direction, + const MapData& to, const TilePos& destination +){ + if (is_wall(to, destination) + || blocks_leaving(from, state.position, direction) + || blocks_entering(to, destination, direction) + ){ + return StepKind::BLOCKED; + } + + const uint8_t level = elevation_at(to, destination); + const bool mismatch = state.elevation != ELEVATION_ANY + && level != ELEVATION_ANY && level != ELEVATION_IGNORED + && level != state.elevation; + if (mismatch){ + // CanStopSurfing() and IsPlayerFacingSurfableFishableWater(). + if (state.surfing && level == ELEVATION_GROUND && object_at(to, destination) == nullptr){ + return StepKind::STOP_SURFING; + } + if (!state.surfing && state.elevation == ELEVATION_GROUND && is_water(to, destination)){ + return StepKind::START_SURF; + } + return StepKind::BLOCKED; + } + + if (object_at(to, destination) != nullptr){ + return StepKind::BLOCKED; + } + return StepKind::WALK; +} + +PlayerState after_step(const MapData& map, const PlayerState& state, Direction direction, StepKind kind){ + return after_step_onto(map, state, map, state.position.next(direction), kind); +} + +PlayerState after_step_onto( + const MapData& from, const PlayerState& state, + const MapData& to, const TilePos& destination, StepKind kind +){ + PlayerState next = state; + next.position = destination; + const uint8_t level = elevation_at(to, destination); + if (level != ELEVATION_IGNORED && elevation_at(from, state.position) != ELEVATION_IGNORED){ + next.elevation = level; + } + if (kind == StepKind::START_SURF){ + next.surfing = true; + }else if (kind == StepKind::STOP_SURFING){ + next.surfing = false; + } + return next; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h new file mode 100644 index 0000000000..399d5f0537 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h @@ -0,0 +1,143 @@ +/* Overworld Map + * + * From: https://github.com/PokemonAutomation/ + * + * FRLG's walking rules on a map (a Pokemon::MapData): per tile collision, + * elevation and the behaviors that matter for walking (water, one-way + * edges), plus its warps and the objects standing on it. The map data is + * generated from the pret/pokefirered decompilation, and classify_step() + * follows the game's own collision checks (GetCollisionAtCoords() in + * src/event_object_movement.c), so a route planned on these maps is one the + * game allows. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldMap_H +#define PokemonAutomation_PokemonFRLG_OverworldMap_H + +#include +#include +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "Pokemon/Navigation/Pokemon_MapData.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +using Pokemon::Direction; +using Pokemon::TilePos; +using Pokemon::TileKind; +using Pokemon::MapData; +using Pokemon::MapWarp; +using Pokemon::MapObject; +using Pokemon::MapConnection; +using Pokemon::WarpEntry; +using Pokemon::warp_at; + + +// Elevations with a meaning of their own in the game's rules +// (IsElevationMismatchAt() and ObjectEventUpdateElevation() in +// pokefirered). +// Stairs and ladders: they join every elevation. +constexpr uint8_t ELEVATION_ANY = 0; +// Bridges and the like: they don't change the player's elevation. +constexpr uint8_t ELEVATION_IGNORED = 15; +// Ordinary ground: most walkable tiles in the decompilation's map layouts. +// Surf starts and ends here (CanStopSurfing(), and the Surf field move +// checks the player's elevation is 3). +constexpr uint8_t ELEVATION_GROUND = 3; + + +// How FRLG reads a map's tiles (Pokemon::TileKind) and warps: +// - WALL, DOOR, SIGN and the ledges are walls. A DOOR warps the player who +// walks north into it; a SIGN shows its message to the player who walks +// into it moving north or south (signposts, Center and Mart signs; +// pokefirered TrySetUpWalkIntoSignpostScript()). Ledges are hopped the +// way they face, which isn't modelled, so the planner avoids them. +// - WATER is entered only by starting to Surf. +// - CLOSED_ can't be entered or left through that side. +// - A warp entered by step_on (ladders, escalators) or cave_entrance warps +// the player who steps onto its tile; walk_ (exit mats, stairs +// at the side of a room) warps the player standing on it who walks that +// way. +// A map without an elevation grid is all ground. + +bool in_bounds(const MapData& map, const TilePos& point); +// Out-of-bounds tiles are walls. +TileKind tile_at(const MapData& map, const TilePos& point); +uint8_t elevation_at(const MapData& map, const TilePos& point); + +bool is_wall(const MapData& map, const TilePos& point); +bool is_water(const MapData& map, const TilePos& point); +bool is_tall_grass(const MapData& map, const TilePos& point); +bool is_ledge(const MapData& map, const TilePos& point); +// Whether the tile itself refuses a step in `direction`: entering it, or +// leaving it. +bool blocks_entering(const MapData& map, const TilePos& point, Direction direction); +bool blocks_leaving(const MapData& map, const TilePos& point, Direction direction); + +// Whether the game takes this tile's warp on stepping onto it (a ladder or +// cave entrance). +bool warps_on_step(const MapData& map, const TilePos& point); +// A door, entered by walking north into it. +bool is_door(const MapData& map, const TilePos& point); +// The direction that takes the exit mat on this tile, if it is one. +std::optional exit_mat(const MapData& map, const TilePos& point); +// Arriving on a door or cave entrance, the game walks the player one +// tile south, out of it. +bool walks_out_on_arrival(const MapData& map, const TilePos& point); + +// The object standing, or maybe wandering, on this tile. +const MapObject* object_at(const MapData& map, const TilePos& point); + +// Whether `object`, a trainer, may see the player on `tile`: up to its +// sight ahead, any way it looks, short of a wall, from its tile or, for +// one who wanders, from any tile it may wander to. False for an object +// that isn't a trainer. +bool trainer_may_see(const MapData& map, const MapObject& object, const TilePos& tile); + +// Removes the objects the game hides once one of `flags` is set. +void hide_objects(MapData& map, const std::set& flags); + + +// What decides where the player's next step can go. +struct PlayerState{ + TilePos position; + uint8_t elevation = ELEVATION_GROUND; + bool surfing = false; +}; + +enum class StepKind{ + BLOCKED, + WALK, // moves one tile (on land, or on water while surfing) + STOP_SURFING, // moves from water onto land and stops surfing + START_SURF, // blocked, but facing water the player can Surf onto +}; + +// What pressing `direction` once does to the player in `state`. +StepKind classify_step(const MapData& map, const PlayerState& state, Direction direction); + +// The same for a step that crosses into another map: from `state` on `from` +// onto `destination` on `to`. +StepKind classify_step_onto( + const MapData& from, const PlayerState& state, Direction direction, + const MapData& to, const TilePos& destination +); + +// The player after a step of kind WALK, STOP_SURFING or START_SURF (the +// Surf action moves the player onto the water). +PlayerState after_step(const MapData& map, const PlayerState& state, Direction direction, StepKind kind); +PlayerState after_step_onto( + const MapData& from, const PlayerState& state, + const MapData& to, const TilePos& destination, StepKind kind +); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp new file mode 100644 index 0000000000..0f7514fe28 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp @@ -0,0 +1,118 @@ +/* Overworld Maps + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonValue.h" +#include "PokemonFRLG_OverworldMaps.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +const char* const MAP_NAMES[] = { + // From a new game to Brock. + "PalletTown", + "PalletTown_PlayersHouse_1F", + "PalletTown_PlayersHouse_2F", + "PalletTown_RivalsHouse", + "PalletTown_ProfessorOaksLab", + "Route1", + "ViridianCity", + "ViridianCity_Mart", + "ViridianCity_PokemonCenter_1F", + "Route22", + "Route2", + "Route2_ViridianForest_SouthEntrance", + "ViridianForest", + "Route2_ViridianForest_NorthEntrance", + "PewterCity", + "PewterCity_PokemonCenter_1F", + "PewterCity_Mart", + "PewterCity_Museum_1F", + "PewterCity_Gym", + // Cerulean Cave, for Mewtwo. + "CeruleanCity_PokemonCenter_1F", + "CeruleanCity", + "Route24", + "CeruleanCave_1F", + "CeruleanCave_2F", + "CeruleanCave_B1F", +}; + + +const std::vector& all_maps(){ + static const std::vector MAPS = []{ + std::vector maps; + for (const char* name : MAP_NAMES){ + maps.push_back(load_map(name)); + } + return maps; + }(); + return MAPS; +} + +} + + +MapData parse_map(const std::string& json, const std::string& source){ + return Pokemon::parse_map(parse_json(json), source); +} + +MapData load_map(const std::string& name){ + const std::string source = "Maps/" + name + ".json"; + const std::vector>& files = overworld_map_json(); + const auto file = std::find_if(files.begin(), files.end(), [&](const auto& item){ return item.first == name; }); + if (file == files.end()){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, source + " is not built into the program."); + } + MapData map = parse_map(file->second, source); + if (map.name != name){ + throw ParseException(source + ": name is \"" + map.name + "\", not \"" + name + "\"."); + } + return map; +} + +std::vector overworld_maps(const std::set& set_flags){ + std::vector maps = all_maps(); + for (MapData& map : maps){ + hide_objects(map, set_flags); + } + return maps; +} + +TilePos map_point(const std::vector& maps, const std::string& map, const std::string& point){ + for (const MapData& data : maps){ + if (data.name != map){ + continue; + } + const auto iter = data.points.find(point); + if (iter != data.points.end()){ + return iter->second; + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No point \"" + point + "\" on map " + map + "."); +} + +std::set map_flag_set(const std::vector& maps, const std::string& name){ + std::set flags; + for (const MapData& map : maps){ + const auto iter = map.flag_sets.find(name); + if (iter != map.flag_sets.end()){ + flags.insert(iter->second.begin(), iter->second.end()); + } + } + return flags; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h new file mode 100644 index 0000000000..cff0668eb5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h @@ -0,0 +1,71 @@ +/* Overworld Maps + * + * From: https://github.com/PokemonAutomation/ + * + * The FRLG maps the overworld routes know about so far: every map from a + * new game in Pallet Town through Viridian City, Route 2 and Viridian + * Forest to Brock's gym in Pewter City; and Cerulean City, its Pokemon + * Center, Route 24 to its north, and the three floors of Cerulean Cave, + * where Mewtwo waits on B1F. + * + * Each map is a JSON file, Maps/.json next to this file, generated by + * devtools/maps/frlg_maps.py and built into the program by CMake + * (pa_embed_text_files() in cmake/EmbedTextFiles.cmake), so the program and + * its tests read the same copy. The schema is Pokemon::MapData's + * (Pokemon/Navigation/Pokemon_MapData.h). A warp leads to point + * "warp_" of its map, the tile of that map's warp n. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldMaps_H +#define PokemonAutomation_PokemonFRLG_OverworldMaps_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_OverworldMap.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Reads a map from its JSON text (Pokemon::parse_map()). `source` names it +// in errors. Throws ParseException, naming the map and the field, if a field +// is missing or doesn't fit the schema. +MapData parse_map(const std::string& json, const std::string& source); + +// (name, JSON text) of each file in Maps/, sorted by name. Generated at +// build time. +// TODO: move the maps to PokemonAutomation/Packages (Resources/PokemonFRLG/Maps) when ready. +const std::vector>& overworld_map_json(); + +// Reads map `name` from overworld_map_json(). Throws InternalProgramError if +// it isn't built in, and ParseException as parse_map(). +MapData load_map(const std::string& name); + +// Every map, by its decompilation name ("CeruleanCity", "CeruleanCave_B1F", ...), +// with the objects the given event flags hide removed. The maps are parsed +// once, on the first call. +std::vector overworld_maps(const std::set& set_flags = {}); + +// Point `point` of map `map` among `maps`, e.g. ("CeruleanCave_B1F", +// "mewtwo"). Throws InternalProgramError if there is none. +TilePos map_point(const std::vector& maps, const std::string& map, const std::string& point); + +// The flags in flag set `name` of every map among `maps`, e.g. +// "after_hall_of_fame": the flags the Hall of Fame sets, which clear the way +// to Cerulean Cave. +std::set map_flag_set(const std::vector& maps, const std::string& name); + + +void add_tests_OverworldMaps(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp new file mode 100644 index 0000000000..b9c82f093f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp @@ -0,0 +1,258 @@ +/* Overworld Maps Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_OverworldMaps.h" +#include "PokemonFRLG_OverworldRoute.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +class Test_OverworldMaps : public UnitTest{ +public: + Test_OverworldMaps(std::string name, std::function body) + : UnitTest("PokemonFRLG::OverworldMaps - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + + +const char* const VALID_MAP = R"({ + "name": "Test", + "source": {"decomp_file": "data/maps/Test/map.json", "revision": "test", "date": "2026-10-31"}, + "tiles": ["#.w", "~D."], + "elevation": ["031", "3f3"], + "points": {"door": [1, 1]}, + "warps": [ + {"x": 1, "y": 1, "enter": "walk_into", "to_map": "Other", "to_point": "warp_2"}, + {"x": 2, "y": 1, "enter": "walk_south"} + ], + "objects": [{"name": "nurse", "kind": "npc", "x": 0, "y": 1, "wander": {"x0": 0, "y0": 1, "x1": 1, "y1": 1}, "hide_flag": "FLAG_X"}], + "flag_sets": {"later": ["FLAG_X", "FLAG_Y"]}, + "connections": [{"side": "south", "to_map": "Other", "offset": -4}] +})"; + +// The ParseException that parsing `json` throws, or empty if it doesn't. +std::string parse_error(const std::string& json){ + try{ + parse_map(json, "Test.json"); + }catch (ParseException& e){ + return e.message(); + } + return ""; +} + +// Whether `text` contains every one of `parts`. +bool mentions(const std::string& text, std::initializer_list parts){ + for (const char* part : parts){ + if (text.find(part) == std::string::npos){ + return false; + } + } + return true; +} + +UnitTestResult test_valid_map(){ + const MapData map = parse_map(VALID_MAP, "Test.json"); + if (map.name != "Test" || map.tiles.width != 3 || map.tiles.height != 2 + || map.tiles.at({0, 1}) != TileKind::TALL_GRASS || exit_mat(map, {2, 1}) != Direction::SOUTH + ){ + return "Wrong name, size or tiles."; + } + if (elevation_at(map, {2, 0}) != 1 || elevation_at(map, {1, 1}) != 15){ + return "Wrong elevation."; + } + const MapWarp* door = warp_at(map, {1, 1}); + if (map.warps.size() != 2 || door == nullptr || !door->to || door->to->map != "Other" || door->to->point != "warp_2"){ + return "Wrong warps."; + } + const MapObject* nurse = object_at(map, {1, 1}); + if (map.objects.size() != 1 || nurse == nullptr || nurse->name != "nurse" || nurse->hide_flag != "FLAG_X"){ + return "Wrong objects."; + } + const MapConnection& connection = map.connections.at(0); + if (connection.side != Direction::SOUTH || connection.offset != -4 || connection.to_map != "Other"){ + return "Wrong connections."; + } + if (map.points.at("door") != TilePos{1, 1} || map.flag_sets.at("later") != std::set{"FLAG_X", "FLAG_Y"}){ + return "Wrong points or flag sets."; + } + return true; +} + +UnitTestResult test_missing_field(){ + std::string json = VALID_MAP; + json.replace(json.find("\"tiles\""), 7, "\"cells\""); + const std::string error = parse_error(json); + if (!mentions(error, {"Test.json", "tiles", "missing"})){ + return "Expected an error naming the missing tiles, got: \"" + error + "\""; + } + return true; +} + +UnitTestResult test_elevation_left_out(){ + std::string json = VALID_MAP; + json.erase(json.find("\"elevation\""), std::string("\"elevation\": [\"031\", \"3f3\"],").size()); + const MapData map = parse_map(json, "Test.json"); + for (int y = 0; y < 2; y++){ + for (int x = 0; x < 3; x++){ + if (elevation_at(map, {x, y}) != ELEVATION_GROUND){ + return "Expected ground everywhere without an elevation grid."; + } + } + } + return true; +} + +UnitTestResult test_bad_field_type(){ + std::string json = VALID_MAP; + json.replace(json.find("\"x\": 1"), 6, "\"x\": \"1\""); + const std::string error = parse_error(json); + if (!mentions(error, {"Test.json", "warps[0]", "x", "integer"})){ + return "Expected an error naming warps[0].x, got: \"" + error + "\""; + } + return true; +} + +UnitTestResult test_bad_row_length(){ + std::string json = VALID_MAP; + json.replace(json.find("\"~D.\""), 5, "\"~D\""); + const std::string error = parse_error(json); + if (!mentions(error, {"Test.json", "tiles[1]", "string of 3 glyphs"})){ + return "Expected an error naming the short row, got: \"" + error + "\""; + } + return true; +} + +UnitTestResult test_unknown_tile(){ + std::string json = VALID_MAP; + json.replace(json.find("\"#.w\""), 5, "\"#.?\""); + const std::string error = parse_error(json); + if (!mentions(error, {"Test.json", "tiles[0]", "unknown glyph '?'", "(2, 0)"})){ + return "Expected an error naming the unknown tile, got: \"" + error + "\""; + } + return true; +} + +// Route 3's Lass Robin, shrunk: she wanders x 2, y 2..4 looking north and +// south, sight 3, below a corridor (row 1) walled off at x 2 above it; a +// bug catcher at (5, 4) looks west, sight 2. +const char* const TRAINERS_MAP = R"({ + "name": "Trainers", + "source": {"decomp_file": "", "revision": "test", "date": "2026-11-02"}, + "tiles": ["##.####", ".......", ".......", ".......", ".......", "~~~~~~~"], + "objects": [ + {"name": "lass", "kind": "npc", "x": 2, "y": 3, "wander": {"x0": 2, "y0": 2, "x1": 2, "y1": 4}, "trainer": {"sight": 3, "looks": ["north", "south"]}}, + {"name": "bug_catcher", "kind": "npc", "x": 5, "y": 4, "facing": "west", "trainer": {"sight": 2}}, + {"name": "youngster", "kind": "npc", "x": 6, "y": 1} + ] +})"; + +// A wanderer sees from every tile she may stand on, short of a wall; a +// trainer standing still only along his facing; a non-trainer nothing. +UnitTestResult test_trainer_sight(){ + const MapData map = parse_map(TRAINERS_MAP, "Trainers.json"); + const MapObject& lass = map.objects[0]; + const MapObject& bug_catcher = map.objects[1]; + const MapObject& youngster = map.objects[2]; + struct Case{ + const MapObject* object; + TilePos tile; + bool sees; + }; + const Case cases[] = { + {&lass, {2, 1}, true}, // from (2, 2..4), north + {&lass, {2, 0}, true}, // the gap in the wall, 2 tiles up from (2, 2) + {&lass, {2, 5}, true}, // south, from (2, 4) + {&lass, {1, 1}, false}, + {&bug_catcher, {3, 4}, true}, + {&bug_catcher, {2, 4}, false}, // past his sight + {&bug_catcher, {5, 3}, false}, // not his way + {&youngster, {5, 1}, false}, + }; + for (const Case& c : cases){ + if (trainer_may_see(map, *c.object, c.tile) != c.sees){ + return c.object->name + (c.sees ? " should see " : " shouldn't see ") + Pokemon::to_string(c.tile) + "."; + } + } + return true; +} + +UnitTestResult test_not_json(){ + const std::string error = parse_error("{\"name\": "); + if (!mentions(error, {"Test.json", "not a JSON object"})){ + return "Expected an error for broken JSON, got: \"" + error + "\""; + } + return true; +} + +// A hall with an escalator at (1, 2) to a floor that isn't loaded, like +// Route 4's Pokemon Center. +const char* const ESCALATOR_HALL = R"({ + "name": "Hall", "source": {"decomp_file": "", "revision": "test", "date": "2026-11-02"}, + "tiles": ["######", "#....#", "#....#", "######"], + "warps": [{"x": 1, "y": 2, "enter": "step_on"}] +})"; + +// Holding west along the escalator's row rides it: a leg there ends by +// counting tiles, never by holding to the wall behind it (console B, +// 2026-11-02, Route 4's Pokemon Center). +UnitTestResult test_no_hold_onto_escalator(){ + const std::vector maps{parse_map(ESCALATOR_HALL, "Hall")}; + if (hold_to_wall(maps, {"Hall", {4, 2}}, false, Direction::WEST)){ + return "Expected no hold west along the escalator's row."; + } + const std::optional> route = plan_overworld_route(maps, {"Hall", {4, 2}}, {{"Hall", {2, 1}}, std::nullopt}); + if (!route || !(follow_overworld_route(maps, {"Hall", {4, 2}}, *route) == MapPosition{"Hall", {2, 1}})){ + return "Expected a route from (4, 2) to (2, 1)."; + } + for (const RouteStep& step : *route){ + if (step.to_wall && step.direction == Direction::WEST && step.end.point == TilePos{2, 2}){ + return "Expected no hold west next to the escalator: " + to_string(step); + } + } + return true; +} + +} + + +void add_tests_OverworldMaps(UnitTestDatabase& database){ + database.add("valid map", test_valid_map); + database.add("missing field", test_missing_field); + database.add("elevation left out", test_elevation_left_out); + database.add("field of the wrong type", test_bad_field_type); + database.add("row of the wrong length", test_bad_row_length); + database.add("unknown tile", test_unknown_tile); + database.add("not JSON", test_not_json); + database.add("trainer sight", test_trainer_sight); + database.add("no hold onto an escalator", test_no_hold_onto_escalator); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp new file mode 100644 index 0000000000..27b28bb54d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp @@ -0,0 +1,374 @@ +/* Overworld Re-anchor + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "PokemonFRLG_OverworldReanchor.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +constexpr size_t MAX_HOLDS = 3; + +Direction opposite(Direction direction){ + return (Direction)(((int)direction + 2) % 4); +} + +// The way from `from` to `to`, on the same row or column. +Direction towards(const TilePos& from, const TilePos& to){ + if (to.x == from.x){ + return to.y < from.y ? Direction::NORTH : Direction::SOUTH; + } + return to.x < from.x ? Direction::WEST : Direction::EAST; +} + +const MapData* map_named(const std::vector& maps, const std::string& name){ + for (const MapData& map : maps){ + if (map.name == name){ + return ↦ + } + } + return nullptr; +} + +// Whether the player could stand on `position`. +bool standable(const std::vector& maps, const MapPosition& position, bool surfing){ + const MapData* map = map_named(maps, position.map); + return map != nullptr && in_bounds(*map, position.point) + && !is_wall(*map, position.point) && object_at(*map, position.point) == nullptr + && is_water(*map, position.point) == surfing; +} + +template +void add_unique(std::vector& items, const Type& item){ + if (std::find(items.begin(), items.end(), item) == items.end()){ + items.push_back(item); + } +} + +// Where `step` started: `tiles` back from its end, on the same map. +std::optional walk_back(const std::vector& maps, const RouteStep& step){ + MapPosition position = step.end; + for (int c = 0; c < step.tiles; c++){ + position.point = position.point.next(opposite(step.direction)); + if (!standable(maps, position, step.surfing)){ + return std::nullopt; + } + } + return position; +} + +// Where trainer `object` of `map`, who may see the player on `tile`, +// stands once walked up: next to the player, on the side they came from. +// Each tile a wanderer may stand on is checked on its own, since the side +// depends on it. +void add_trainer_stops( + const MapData& map, size_t object, const MapPosition& tile, std::vector& stops +){ + const MapObject& trainer = map.objects[object]; + const Pokemon::TileBox box = trainer.wander.value_or( + Pokemon::TileBox{.x0 = trainer.x, .y0 = trainer.y, .x1 = trainer.x, .y1 = trainer.y} + ); + const int width = box.x1 - box.x0 + 1; + const int count = width * (box.y1 - box.y0 + 1); + for (int c = 0; c < count; c++){ + MapObject standing = trainer; + standing.wander.reset(); + standing.x = box.x0 + c % width; + standing.y = box.y0 + c / width; + if (trainer_may_see(map, standing, tile.point)){ + const TilePos beside = tile.point.next(towards(tile.point, TilePos{standing.x, standing.y})); + add_unique(stops, TrainerStop{.object = object, .at = MapPosition{tile.map, beside}}); + } + } +} + +// The trainers who may see the player on `tile`, and where each stands +// once walked up. +std::vector trainers_seeing(const std::vector& maps, const MapPosition& tile){ + std::vector stops; + const MapData* map = map_named(maps, tile.map); + for (size_t c = 0; map != nullptr && c < map->objects.size(); c++){ + if (trainer_may_see(*map, map->objects[c], tile.point)){ + add_trainer_stops(*map, c, tile, stops); + } + } + return stops; +} + +// `maps` with a trainer who walked up standing on each of `trainers`: they +// stay there after the battle, so the player can't walk through. +std::vector with_trainers(const std::vector& maps, const std::vector& trainers){ + std::vector ret = maps; + for (const MapPosition& at : trainers){ + for (MapData& map : ret){ + if (map.name == at.map && in_bounds(map, at.point)){ + map.tiles.cells[(size_t)at.point.y * map.tiles.width + at.point.x] = TileKind::WALL; + } + } + } + return ret; +} + +// Where the player may be, on which of the maps as they may stand (with +// or without a trainer next to them). +struct Hypothesis{ + size_t world = 0; + MapPosition at; + + bool operator==(const Hypothesis& other) const = default; +}; + +bool converged(const std::vector& positions){ + for (const Hypothesis& position : positions){ + if (!(position.at == positions[0].at)){ + return false; + } + } + return true; +} + +// Whether a person stands, or may wander, on a tile `wall` passes after +// `from`. The step rules don't have people, but one there stops the player +// short of the wall. +bool person_on_the_way( + const std::vector& world, const MapPosition& from, + bool surfing, Direction direction, const WallHold& wall +){ + RouteStep hold; + hold.direction = direction; + hold.tiles = wall.tiles; + hold.surfing = surfing; + const std::vector tiles = leg_tiles(world, from, hold); + for (size_t c = 1; c < tiles.size(); c++){ + const MapData* map = map_named(world, tiles[c].map); + if (map != nullptr && object_at(*map, tiles[c].point) != nullptr){ + return true; + } + } + return false; +} + +// Holding `direction` from each of `positions`: where they end up, as a leg +// to a wall as long as the longest of them. Nothing if any isn't stopped +// by a wall, or may be stopped short by a person. +std::optional, RouteStep>> hold_all( + const std::vector>& worlds, const std::vector& positions, + bool surfing, Direction direction +){ + std::vector ends; + RouteStep hold; + hold.direction = direction; + hold.surfing = surfing; + hold.to_wall = true; + hold.facing_after = direction; + for (const Hypothesis& position : positions){ + const std::optional wall = hold_to_wall(worlds[position.world], position.at, surfing, direction); + if (!wall || person_on_the_way(worlds[position.world], position.at, surfing, direction, *wall)){ + return std::nullopt; + } + add_unique(ends, Hypothesis{position.world, wall->end}); + hold.tiles = std::max(hold.tiles, wall->tiles); + hold.wild = hold.wild || wall->wild; + hold.end = wall->end; + } + return std::make_pair(std::move(ends), hold); +} + +int total_tiles(const std::vector& legs){ + int total = 0; + for (const RouteStep& leg : legs){ + total += leg.tiles; + } + return total; +} + +struct Found{ + std::vector holds; + MapPosition at; +}; + +// Every way of exactly `depth` holds that brings all of `positions` to one +// tile, in a fixed order. +void search( + const std::vector>& worlds, const std::vector& positions, bool surfing, + size_t depth, std::vector& holds, std::vector& found +){ + for (Direction direction : Pokemon::ALL_DIRECTIONS){ + auto next = hold_all(worlds, positions, surfing, direction); + if (!next || next->first == positions || next->second.tiles == 0){ + continue; + } + holds.push_back(next->second); + if (converged(next->first)){ + if (depth == 1){ + found.push_back(Found{holds, next->first[0].at}); + } + }else if (depth > 1){ + search(worlds, next->first, surfing, depth - 1, holds, found); + } + holds.pop_back(); + } +} + +// Whether `route`, planned from `at` on other maps, walks the same on +// `world`: each leg to a wall stops at its end, each open leg gets there. +bool walks_same(const std::vector& world, MapPosition at, const std::vector& route){ + for (const RouteStep& step : route){ + if (step.action == RouteAction::WALK && step.to_wall){ + const std::optional hold = hold_to_wall(world, at, step.surfing, step.direction); + if (!hold || !(hold->end == step.end)){ + return false; + } + }else if (step.action == RouteAction::WALK){ + const std::vector tiles = leg_tiles(world, at, step); + const size_t expected = (size_t)(step.tiles - (step.warps ? 1 : 0)) + 1; + if (tiles.size() != expected || (!step.warps && !(tiles.back() == step.end))){ + return false; + } + } + at = step.end; + } + return true; +} + +bool walks_same_everywhere( + const std::vector>& worlds, const std::vector& positions, + const MapPosition& from, const std::vector& route +){ + for (const Hypothesis& position : positions){ + if (!walks_same(worlds[position.world], from, route)){ + return false; + } + } + return true; +} + +// The ways to find the player from all of `positions`: fewest holds first, +// then fewest tiles held. None needed if they are all on one tile. +std::vector find_player( + const std::vector>& worlds, const std::vector& positions, bool surfing +){ + std::vector found; + if (converged(positions)){ + found.push_back(Found{{}, positions[0].at}); + } + for (size_t depth = 1; found.empty() && depth <= MAX_HOLDS; depth++){ + std::vector holds; + search(worlds, positions, surfing, depth, holds, found); + std::stable_sort(found.begin(), found.end(), [](const Found& a, const Found& b){ + return total_tiles(a.holds) < total_tiles(b.holds); + }); + } + return found; +} + +} + + +WalkedTiles walked_near(const RouteStep& step, int estimate, Milliseconds tile_time){ + // The estimate is rounded to the nearest tile already. + const int spread = tile_time.count() > 0 + ? (int)((STOP_TIMING_SLACK + tile_time / 2) / tile_time) + : step.tiles; + return WalkedTiles{ + .min = std::clamp(estimate - spread, 0, step.tiles), + .max = std::clamp(estimate + spread, 0, step.tiles), + }; +} + +WalkedTiles whole_leg(const RouteStep& step){ + return WalkedTiles{.min = 0, .max = step.tiles}; +} + +std::string to_string(const StopCandidate& candidate){ + std::string text = to_string(candidate.player); + if (candidate.trainer){ + text += std::format(" (stopped by a trainer, now at {})", Pokemon::to_string(candidate.trainer->at.point)); + } + return text; +} + +std::vector stop_candidates( + const std::vector& maps, + const std::optional& start, + const RouteStep& step, + WalkedTiles walked +){ + std::vector candidates; + if (step.action != RouteAction::WALK){ + return candidates; + } + const std::optional from = start ? start : walk_back(maps, step); + if (!from){ + return candidates; + } + const std::vector tiles = leg_tiles(maps, *from, step); + const int last = std::min((int)tiles.size() - 1, walked.max); + for (int c = 1; c <= last; c++){ + for (const TrainerStop& trainer : trainers_seeing(maps, tiles[c])){ + candidates.push_back(StopCandidate{.player = tiles[c], .trainer = trainer}); + } + } + if (!candidates.empty() && !step.wild){ + return candidates; + } + for (int c = std::max(0, walked.min); c <= last; c++){ + add_unique(candidates, StopCandidate{.player = tiles[c], .trainer = std::nullopt}); + } + return candidates; +} + +std::optional plan_reanchor( + const std::vector& maps, + const std::vector& candidates, + const RouteStep& step, + const RouteCosts& costs +){ + if (candidates.empty() || step.action != RouteAction::WALK){ + return std::nullopt; + } + + // The maps as they may stand: as they are, and with each trainer who + // may have walked up. + std::vector> worlds{maps}; + std::vector trainers; + std::vector positions; + for (const StopCandidate& candidate : candidates){ + size_t world = 0; + if (candidate.trainer){ + worlds.push_back(with_trainers(maps, {candidate.trainer->at})); + world = worlds.size() - 1; + add_unique(trainers, candidate.trainer->at); + } + add_unique(positions, Hypothesis{world, candidate.player}); + } + + const std::vector clear_of_trainers = with_trainers(maps, trainers); + for (const Found& at : find_player(worlds, positions, step.surfing)){ + const Direction facing = at.holds.empty() ? step.direction : at.holds.back().direction; + // The way back keeps clear of every trainer who may stand in it if + // it can, and must walk the same whether they do or not. + std::optional> back = plan_overworld_route(clear_of_trainers, at.at, RouteGoal{step.end, std::nullopt}, costs, facing); + if (!back && !trainers.empty()){ + back = plan_overworld_route(maps, at.at, RouteGoal{step.end, std::nullopt}, costs, facing); + } + if (back && (trainers.empty() || walks_same_everywhere(worlds, positions, at.at, *back))){ + return Reanchor{.holds = at.holds, .found = at.at, .back = std::move(*back)}; + } + } + return std::nullopt; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h new file mode 100644 index 0000000000..9037aa83ce --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h @@ -0,0 +1,115 @@ +/* Overworld Re-anchor + * + * From: https://github.com/PokemonAutomation/ + * + * Finding the player again after a battle or a message stopped a leg + * part-way. The timing of the stop narrows where they are to a few tiles of + * the leg (and a trainer who saw them may have stopped them earlier, on a + * tile in their sight); this looks for holds to walls, none to three, that + * end on the same tile from every one of them, and a way back to the leg's + * end that walks the same from there whichever it was. If there are none, + * the caller stops: the player is never guessed to be on one of them. + * + * The player is taken to be on the leg's line. Wider sets were tried: + * with even one tile to either side, Route 1's people and ledges cut some + * hold for some tile, and nothing on its grass legs could be found. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldReanchor_H +#define PokemonAutomation_PokemonFRLG_OverworldReanchor_H + +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_OverworldMap.h" +#include "PokemonFRLG_OverworldRoute.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// How many tiles of a stopped leg the player may have walked: from `min` +// to `max`, both included. +struct WalkedTiles{ + int min = 0; + int max = 0; +}; + +// How far off the timing of a stop may be: the interrupts' detection delays +// aren't calibrated, and video lag and the watchers' period add to them. +constexpr Milliseconds STOP_TIMING_SLACK(300); + +// Where the timing puts a stop on `step`: `estimate` tiles walked +// (Pokemon::LegResult::tiles), give or take STOP_TIMING_SLACK at +// `tile_time` a tile: a tile either side walking, two running. +WalkedTiles walked_near(const RouteStep& step, int estimate, Milliseconds tile_time); +// Anywhere on `step`, for a stop the timing doesn't place. +WalkedTiles whole_leg(const RouteStep& step); + +// A trainer who saw the player and walked up to them: which of `map`'s +// objects, and the tile next to the player they stand on afterwards. +struct TrainerStop{ + size_t object = 0; + MapPosition at; + + bool operator==(const TrainerStop& other) const = default; +}; + +// One way things may stand after a stop: the player's tile, and the +// trainer who stopped them there, if one did. +struct StopCandidate{ + MapPosition player; + std::optional trainer; + + bool operator==(const StopCandidate& other) const = default; +}; +std::string to_string(const StopCandidate& candidate); + +// Where `step`, an open WALK from `start`, may have been stopped: +// - on the tiles `walked` covers, by a wild battle or a message; +// - on any tile up to `walked.max` a trainer may see, by that trainer: +// the player stops as soon as they are seen, and the trainer speaks +// only after walking up, so later than the timing says. +// Off the grass a message is taken to be a trainer's wherever one may see +// the player, so there only the second kind are left, if there are any. +// `start` not known: worked back from the leg's end. Empty if it can't be. +std::vector stop_candidates( + const std::vector& maps, + const std::optional& start, + const RouteStep& step, + WalkedTiles walked +); + +struct Reanchor{ + // Legs to walls, in order, that bring the player to `found` from every + // candidate; none if there was only one. Each but the last ends on a + // tile that depends on the candidate; its `end` is one of them. + std::vector holds; + MapPosition found; + // From `found` back to the stopped leg's end, walking the same from + // there whichever candidate it was (a trainer who walked up stays). + std::vector back; +}; + +// After `step` stopped part-way, from `candidates`. Nothing if no holds +// bring them all to one tile, or no way back walks the same from there. +std::optional plan_reanchor( + const std::vector& maps, + const std::vector& candidates, + const RouteStep& step, + const RouteCosts& costs = default_route_costs() +); + + +void add_tests_OverworldReanchor(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp new file mode 100644 index 0000000000..bbc2cf72f5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp @@ -0,0 +1,246 @@ +/* Overworld Re-anchor Tests + * + * From: https://github.com/PokemonAutomation/ + * + * stop_candidates() and plan_reanchor(): finding the player again at a + * wall after an open leg stopped part-way. + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_OverworldMaps.h" +#include "PokemonFRLG_OverworldReanchor.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +class Test_OverworldReanchor : public UnitTest{ +public: + Test_OverworldReanchor(std::string name, std::function body) + : UnitTest("PokemonFRLG::OverworldReanchor - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + +std::string describe(const std::vector& route){ + std::string text; + for (const RouteStep& step : route){ + text += "\n " + to_string(step); + } + return text; +} + +std::string describe(const std::optional& anchor){ + if (!anchor){ + return "none"; + } + std::string text = to_string(anchor->found) + " after"; + for (const RouteStep& hold : anchor->holds){ + text += " " + to_string(hold); + } + return text + ", then" + describe(anchor->back); +} + +// How a walking leg may have stopped: anywhere (seen after the hold), and +// at each estimate the timing can give. +std::vector stops_of(const RouteStep& step){ + std::vector stops{whole_leg(step)}; + for (int estimate = 0; estimate <= step.tiles; estimate++){ + stops.push_back(walked_near(step, estimate, std::chrono::milliseconds(267))); + } + return stops; +} + +// Plans from `start` to `goal`, then checks that the player can be found +// again however an open leg through tall grass is stopped, and that the +// way back reaches that leg's end. +UnitTestResult check_reanchors(const std::vector& maps, const MapPosition& start, const RouteGoal& goal){ + const std::optional> route = plan_overworld_route(maps, start, goal); + if (!route){ + return "No route from " + to_string(start) + "."; + } + std::optional at = start; + for (const RouteStep& step : *route){ + if (step.action != RouteAction::WALK || !step.wild || step.to_wall){ + at = step.end; + continue; + } + for (const WalkedTiles& walked : stops_of(step)){ + const std::vector candidates = stop_candidates(maps, at, step, walked); + const std::optional anchor = plan_reanchor(maps, candidates, step); + if (!anchor){ + return std::format( + "Can't find the player again on {}, stopped {} to {} tiles in ({} candidates):{}", + to_string(step), walked.min, walked.max, candidates.size(), describe(*route) + ); + } + if (!(follow_overworld_route(maps, anchor->found, anchor->back) == step.end)){ + return "The way back from " + to_string(anchor->found) + " misses the end of " + to_string(step) + "."; + } + } + at = step.end; + } + return true; +} + +// Console B, 2026-11-01: battles on Route 1 left the walker a tile or a +// whole leg off its count, four times. +UnitTestResult test_viridian_mart_to_oaks_lab(){ + const std::vector maps = overworld_maps(); + return check_reanchors( + maps, {"ViridianCity_Mart", map_point(maps, "ViridianCity_Mart", "clerk_front")}, + {{"PalletTown_ProfessorOaksLab", {6, 4}}, std::nullopt} + ); +} +UnitTestResult test_pallet_to_viridian_mart(){ + const std::vector maps = overworld_maps(); + return check_reanchors( + maps, {"PalletTown", map_point(maps, "PalletTown", "oaks_lab_front")}, + {{"ViridianCity_Mart", map_point(maps, "ViridianCity_Mart", "clerk_front")}, std::nullopt} + ); +} +// All grass, walled in by trees: where the walker was lost twice (console B, +// 2026-11-01, runs 16 and 17), and where the long dungeon walks start. +UnitTestResult test_viridian_forest(){ + const std::vector maps = overworld_maps(); + return check_reanchors( + maps, {"ViridianForest", {29, 61}}, + {{"Route2_ViridianForest_NorthEntrance", {7, 8}}, std::nullopt} + ); +} + +// A field with a wall at its east end and a row of ledges to the south. +const char* const TEST_FIELD_JSON = R"({ + "name": "Field", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, + "tiles": ["########", "#......#", "#......#", "#vvvvvv#", "#......#"], + "elevation": ["33333333", "33333333", "33333333", "33333333", "33333333"] +})"; + +// Stopped part-way east, the player holds back west to the wall, the +// shorter way, and walks back. Stopped part-way south above the ledges, +// which would be hopped, they hold back north. +UnitTestResult test_rules(){ + const std::vector maps{parse_map(TEST_FIELD_JSON, "Field")}; + RouteStep east; + east.direction = Direction::EAST; + east.tiles = 3; + east.end = {"Field", {4, 1}}; + std::optional anchor = plan_reanchor(maps, stop_candidates(maps, MapPosition{"Field", {1, 1}}, east, whole_leg(east)), east); + if (!anchor || anchor->holds.size() != 1 || anchor->holds[0].direction != Direction::WEST || !(anchor->found.point == TilePos{1, 1})){ + return "Expected a hold west to (1, 1), got " + describe(anchor); + } + if (anchor->back.size() != 1 || !(anchor->back[0].end == east.end)){ + return "Expected one leg back east to (4, 1), got " + describe(anchor); + } + RouteStep south; + south.direction = Direction::SOUTH; + south.tiles = 1; + south.end = {"Field", {3, 2}}; + anchor = plan_reanchor(maps, stop_candidates(maps, std::nullopt, south, whole_leg(south)), south); + if (!anchor || anchor->holds.size() != 1 || anchor->holds[0].direction != Direction::NORTH || !(anchor->found.point == TilePos{3, 1})){ + return "Expected a hold north back to (3, 1), got " + describe(anchor); + } + return true; +} + +// The timing narrows a stop to a tile either side of its estimate walking, +// two running, within the leg. +UnitTestResult test_timing(){ + RouteStep leg; + leg.direction = Direction::EAST; + leg.tiles = 10; + struct Case{ + int estimate; + int tile_ms; + int min; + int max; + }; + const Case cases[] = { + {.estimate = 5, .tile_ms = 267, .min = 4, .max = 6}, + {.estimate = 0, .tile_ms = 267, .min = 0, .max = 1}, + {.estimate = 10, .tile_ms = 267, .min = 9, .max = 10}, + {.estimate = 5, .tile_ms = 133, .min = 3, .max = 7}, + {.estimate = 1, .tile_ms = 133, .min = 0, .max = 3}, + }; + for (const Case& c : cases){ + const WalkedTiles walked = walked_near(leg, c.estimate, std::chrono::milliseconds(c.tile_ms)); + if (walked.min != c.min || walked.max != c.max){ + return std::format( + "{} tiles in at {}ms a tile: expected {} to {}, got {} to {}.", + c.estimate, c.tile_ms, c.min, c.max, walked.min, walked.max + ); + } + } + return true; +} + +// A field with someone standing in the middle of its north row. +const char* const TEST_PERSON_JSON = R"({ + "name": "Person", "source": {"decomp_file": "", "revision": "test", "date": "2026-11-02"}, + "tiles": ["#######", "#.....#", "#.....#", "#######"], + "objects": [{"name": "youngster", "kind": "npc", "x": 3, "y": 1}] +})"; + +// Stopped going east along the south row: holding north would meet the +// person from one of the tiles, so the player holds along the row. On the +// north row, past the person, they don't hold west into them. +UnitTestResult test_person_in_the_way(){ + const std::vector maps{parse_map(TEST_PERSON_JSON, "Person")}; + RouteStep east; + east.direction = Direction::EAST; + east.tiles = 4; + east.end = {"Person", {5, 2}}; + const std::optional anchor = plan_reanchor(maps, stop_candidates(maps, MapPosition{"Person", {1, 2}}, east, whole_leg(east)), east); + if (!anchor || anchor->holds.size() != 1 || anchor->holds[0].direction == Direction::NORTH){ + return "Expected one hold along the row, clear of the person, got " + describe(anchor); + } + RouteStep north_row = east; + north_row.tiles = 1; + north_row.end = {"Person", {5, 1}}; + const std::vector beside{{.player = {"Person", {4, 1}}, .trainer = std::nullopt}, {.player = {"Person", {5, 1}}, .trainer = std::nullopt}}; + const std::optional blocked = plan_reanchor(maps, beside, north_row); + if (blocked && blocked->holds[0].direction == Direction::WEST){ + return "Expected no hold west into the person, got " + describe(blocked); + } + return true; +} + + +} + + +void add_tests_OverworldReanchor(UnitTestDatabase& database){ + database.add("rules", test_rules); + database.add("timing", test_timing); + database.add("a person in the way", test_person_in_the_way); + database.add("Viridian Mart to Oak's Lab", test_viridian_mart_to_oaks_lab); + database.add("Pallet Town to Viridian Mart", test_pallet_to_viridian_mart); + database.add("Viridian Forest", test_viridian_forest); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp new file mode 100644 index 0000000000..1a907f7a06 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp @@ -0,0 +1,358 @@ +/* Overworld Recovery + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Pokemon/Navigation/Pokemon_RouteLog.h" +#include "PokemonFRLG_OverworldReanchor.h" +#include "PokemonFRLG_OverworldRecovery.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +using Pokemon::EndBasis; +using Pokemon::ROUTE_LOG_TAG; + +std::vector route_tiles(const std::optional& position){ + if (!position){ + return {}; + } + return {{position->map, position->point}}; +} + +Pokemon::RouteLogLeg route_log_leg(const RouteStep& step){ + Pokemon::RouteLogLeg leg{.action = Pokemon::RouteLegAction::WALK, .direction = step.direction, .tiles = (size_t)step.tiles, .end = Pokemon::RouteLegEnd::OPEN}; + if (step.action == RouteAction::SURF){ + leg.action = Pokemon::RouteLegAction::SURF; + }else if (step.action == RouteAction::FACE){ + leg.action = Pokemon::RouteLegAction::FACE; + }else if (step.warps){ + leg.end = Pokemon::RouteLegEnd::WARP; + }else if (step.to_wall){ + leg.end = Pokemon::RouteLegEnd::WALL; + } + return leg; +} + +// The farthest sight of the trainers on `maps` who may see `tile`; 0 if +// none does. +int sight_onto(const std::vector& maps, const MapPosition& tile){ + int sight = 0; + for (const MapData& map : maps){ + if (map.name != tile.map){ + continue; + } + for (const MapObject& object : map.objects){ + if (trainer_may_see(map, object, tile.point)){ + sight = std::max(sight, object.trainer->sight); + } + } + } + return sight; +} + +// The route's lines in the route log the games share, as BDSP's walker +// writes them, under the caller's label. +class RouteLogLines{ +public: + RouteLogLines(const RouteCalls& calls, const RoutePlanning* planning) + : m_calls(calls) + , m_label(planning != nullptr ? planning->label : "Route") + {} + void plan(const std::optional& from, const std::vector& steps) const{ + std::vector legs; + for (const RouteStep& step : steps){ + legs.push_back({.leg = route_log_leg(step), .after = route_tiles(step.end)}); + } + m_calls.log(ROUTE_LOG_TAG + Pokemon::route_plan_line(m_label, route_tiles(from), legs)); + } + void leg(size_t index, const std::vector& steps) const{ + const RouteStep& step = steps[index]; + m_calls.log(ROUTE_LOG_TAG + Pokemon::route_leg_line(index + 1, steps.size(), {.leg = route_log_leg(step), .after = route_tiles(step.end)})); + } + void end(const RouteStep& step, const std::optional& at, EndBasis basis, const std::string& why) const{ + m_calls.log(ROUTE_LOG_TAG + Pokemon::route_leg_end_line(m_label, route_log_leg(step), route_tiles(at), basis, why)); + } + void trainer_stopped(const RouteStep& step, const MapPosition& at) const{ + m_calls.log(ROUTE_LOG_TAG + Pokemon::route_replan_line(m_label, route_log_leg(step), "stopped by a trainer who saw the player", route_tiles(at))); + } + void found(const MapPosition& at, size_t holds) const{ + m_calls.log(ROUTE_LOG_TAG + Pokemon::route_found_line(m_label, route_tiles(at), holds)); + } + // Step `number` (from 1) of a plan whose first `holds` steps are holds + // to walls, walked to its end. + void done(const RouteStep& step, size_t number, size_t holds) const{ + if (number < holds){ + // Where a hold but the last ends depends on where it started. + end(step, std::nullopt, EndBasis::UNKNOWN, "a hold from an unknown tile"); + return; + } + end(step, step.end, EndBasis::WALKED, ""); + if (number == holds){ + found(step.end, holds); + } + } + +private: + const RouteCalls& m_calls; + std::string m_label; +}; + +// Walks each step through `calls`; watches a leg that crosses a trainer's +// sight for the trainer, and logs whether a leg to a wall that ended did +// end at its wall. +class CheckedSteps{ +public: + CheckedSteps(const RouteCalls& calls, WallCheck wall_check) + : m_calls(calls) + , m_wall_check(wall_check) + {} + StepOutcome walk(const RouteStep& step, std::optional facing, const std::optional& crossing){ + const std::string leg = to_string(step); + m_reholds = m_last_late && leg == m_last ? m_reholds + 1 : 0; + StepOutcome outcome = m_calls.walk(step, facing); + if (outcome.end == StepEnd::DONE && crossing && m_calls.watch_for_trainer){ + outcome = StepOutcome{.end = m_calls.watch_for_trainer(step, crossing->approach_tiles), .walked = std::nullopt}; + } + m_last = leg; + m_last_late = outcome.end == StepEnd::LATE; + if (outcome.end == StepEnd::DONE){ + check_wall(step); + } + return outcome; + } + +private: + // TODO(forest drift, 2026-11-01): diagnostic; remove or turn into a recovery once the cause is known. + // Four runs ended the walk to Viridian Forest's north gate off its + // column, which 52 legs walked by hand didn't reproduce: one more tap + // toward a leg's wall moves nobody who stands at it. Only logged: the + // screen check can't tell a bump from a step yet, and failing on it + // stopped good runs. + void check_wall(const RouteStep& step) const{ + if (!step.to_wall || step.warps || step.action != RouteAction::WALK + || m_wall_check == WallCheck::SKIP || !m_calls.moved_past_wall + ){ + return; + } + if (!m_calls.moved_past_wall(step)){ + return; + } + m_calls.log(std::format( + "Position check (logged only): a tap after {} moved the screen as a step would; believed at {}, after {} re-hold(s) " + "for something seen late (the leg's interrupts are the \"Leg:\" lines above).", + to_string(step), to_string(step.end), m_reholds + )); + } + + const RouteCalls& m_calls; + WallCheck m_wall_check = WallCheck::TAP; + std::string m_last; + bool m_last_late = false; + size_t m_reholds = 0; +}; + +// run_route()'s walk: the plan, as rejoined or planned again after a +// stop, which step is next, where the player is and which way they face. +class RouteRun{ +public: + RouteRun(const std::vector& route, std::optional facing, const RoutePlanning* planning, const RouteCalls& calls) + : m_planning(planning) + , m_calls(calls) + , m_lines(calls, planning) + , m_steps(calls, planning != nullptr ? planning->wall_check : WallCheck::TAP) + , m_plan(route) + , m_at(planning != nullptr ? planning->start : std::nullopt) + , m_facing(facing) + {} + + void run(){ + m_lines.plan(m_at, m_plan); + while (m_next < m_plan.size()){ + const RouteStep step = m_plan[m_next]; + m_lines.leg(m_next, m_plan); + // Where a hold that finds the player starts isn't known. + const std::optional crossing = m_next >= m_holds ? crossing_here(step) : std::nullopt; + const StepOutcome outcome = m_steps.walk(step, m_facing, crossing); + if (outcome.end == StepEnd::DONE){ + m_at = step.end; + m_facing = step.facing_after; + m_lines.done(step, ++m_next, m_holds); + continue; + } + const std::optional start = m_next >= m_holds ? m_at : std::nullopt; + m_facing = std::nullopt; // not known after a stop + if (++m_stops > MAX_ROUTE_STOPS){ + m_calls.fail(std::format("walk_overworld_route(): stopped part-way {} times.", m_stops)); + return; + } + if (!after_stop(step, outcome, start, crossing)){ + return; + } + } + } + +private: + const std::vector* maps() const{ + return m_planning != nullptr ? m_planning->maps : nullptr; + } + + std::optional crossing_here(const RouteStep& step) const{ + if (!m_at || maps() == nullptr){ + return std::nullopt; + } + return trainer_crossing(*maps(), *m_at, step); + } + + // After a stop on `step`, from `start` if known. False once the route + // has failed. + bool after_stop( + const RouteStep& step, const StepOutcome& outcome, + const std::optional& start, const std::optional& crossing + ){ + if (step.to_wall){ + return after_wall_stop(step, outcome, start, crossing); + } + if (outcome.end == StepEnd::STOPPED && step.warps && !step.wild){ + m_calls.hold_to_warp(step); + m_at = step.end; + m_facing = step.facing_after; + m_next++; + m_lines.end(step, m_at, EndBasis::ASSUMED, "stopped, then held on to the warp"); + return true; + } + m_lines.end(step, std::nullopt, EndBasis::UNKNOWN, "stopped part-way"); + if (maps() == nullptr){ + m_calls.fail("walk_overworld_route(): stopped part-way on " + to_string(step) + ", with no maps to find the player again."); + return false; + } + const WalkedTiles walked = outcome.walked.value_or(whole_leg(step)); + return rejoin(step, stop_candidates(*maps(), start, step, walked), walked); + } + + // A leg to a wall seen interrupted after its hold is walked again: the + // wall stops the player at its end however far they got. Unless, off + // the grass, the maps place a trainer who saw them on one tile of it: + // they stopped there, and the route goes on from there (Camper Liam, + // console B, 2026-11-01). + bool after_wall_stop( + const RouteStep& step, const StepOutcome& outcome, + const std::optional& start, const std::optional& crossing + ){ + if (outcome.end == StepEnd::STOPPED){ + // Interrupted at once, hold after hold: by something on the + // way that speaks, a sign, which the plan didn't have there. + m_calls.fail("walk_overworld_route(): a hold toward a wall is interrupted right away, again: the player is off the route, on " + to_string(step) + "."); + return false; + } + if (crossing && !step.wild && maps() != nullptr){ + const std::vector candidates = stop_candidates(*maps(), start, step, whole_leg(step)); + if (candidates.size() == 1 && candidates[0].trainer){ + return rejoin(step, candidates, whole_leg(step)); + } + } + m_lines.end(step, std::nullopt, EndBasis::UNKNOWN, "something seen after the hold; walking it again"); + return true; + } + + // Finds the player on one of `candidates`, plans the way back to the + // end of `step` (m_plan[m_next]), and the rest of the route after it. + bool rejoin(const RouteStep& step, const std::vector& candidates, WalkedTiles walked){ + std::string where; + for (const StopCandidate& candidate : candidates){ + where += (where.empty() ? "" : "; ") + to_string(candidate); + } + m_calls.log(std::format( + "Route: {} stopped {} to {} tiles in; the player is on one of: {}.", + to_string(step), walked.min, walked.max, where.empty() ? "nothing (no start to work from)" : where + )); + const std::optional anchor = candidates.empty() + ? std::nullopt + : plan_reanchor(*maps(), candidates, step, m_planning->costs); + if (!anchor){ + m_calls.fail( + "walk_overworld_route(): stopped part-way on " + to_string(step) + + ", and no holds to walls find the player from every tile they may be on." + ); + return false; + } + std::vector plan = anchor->holds; + plan.insert(plan.end(), anchor->back.begin(), anchor->back.end()); + plan.insert(plan.end(), m_plan.begin() + m_next + 1, m_plan.end()); + m_plan = std::move(plan); + m_holds = anchor->holds.size(); + m_next = 0; + if (m_holds > 0){ + m_at = std::nullopt; + m_lines.plan(std::nullopt, m_plan); + return true; + } + // Only one tile: the player stands there, still facing the leg's + // way (also after a trainer walked up: Camper Liam, console B, + // 2026-11-01). + if (candidates[0].trainer){ + m_lines.trainer_stopped(step, anchor->found); + }else{ + m_lines.found(anchor->found, 0); + } + m_at = anchor->found; + m_facing = step.direction; + m_lines.plan(m_at, m_plan); + return true; + } + + const RoutePlanning* m_planning; + const RouteCalls& m_calls; + const RouteLogLines m_lines; + CheckedSteps m_steps; + std::vector m_plan; + std::optional m_at; + std::optional m_facing; + size_t m_next = 0; + size_t m_stops = 0; + size_t m_holds = 0; // of the plan, holds to walls that find the player +}; + +} + + +std::optional trainer_crossing( + const std::vector& maps, const MapPosition& start, const RouteStep& step +){ + if (step.action != RouteAction::WALK){ + return std::nullopt; + } + TrainerCrossing crossing; + const std::vector tiles = leg_tiles(maps, start, step); + for (size_t c = 1; c < tiles.size(); c++){ + const int sight = sight_onto(maps, tiles[c]); + if (sight > 0){ + crossing.seen.push_back(tiles[c]); + crossing.approach_tiles = std::max(crossing.approach_tiles, sight); + } + } + if (crossing.seen.empty()){ + return std::nullopt; + } + return crossing; +} + +void run_route( + const std::vector& route, std::optional facing, + const RoutePlanning* planning, const RouteCalls& calls +){ + RouteRun(route, facing, planning, calls).run(); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h new file mode 100644 index 0000000000..3e15603f4d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h @@ -0,0 +1,134 @@ +/* Overworld Recovery + * + * From: https://github.com/PokemonAutomation/ + * + * Runs a planned route step by step, and when a step ends short of where + * it was planned to, gets the player back onto it: + * + * - a leg to a wall interrupted after its hold is walked again; + * - an open leg to a warp, off the grass, stopped by a message (a + * trainer), is held on toward the warp; + * - a leg that crosses a trainer's sight (trainer_crossing()) is watched + * after for long enough that the trainer, if they saw the player, has + * walked up and spoken; + * - any other open leg stopped part-way, or a leg seen stopped by a + * trainer, has the tiles the player may be on worked out from the + * stop's timing and the trainers' sight (stop_candidates()). One tile: + * the route is planned again from it. More: holds to walls that end on + * one tile from all of them find the player (plan_reanchor()), and a + * way back to the stopped leg's end rejoins the route. The rest of the + * route is then walked as planned. + * + * Where the player is is never guessed: when no holds find them from every + * tile they may be on, the route fails, and the caller stops without + * saving. + * + * The console side is passed in, so this is tested with scripted steps. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldRecovery_H +#define PokemonAutomation_PokemonFRLG_OverworldRecovery_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_OverworldReanchor.h" +#include "PokemonFRLG_OverworldRoute.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// How one step of a route ended. +enum class StepEnd{ + DONE, + STOPPED, // stopped part-way: where the player is isn't known + LATE, // something was seen after the hold, which may have + // stopped the player before the end +}; + +// How a step ended, and for an open leg STOPPED part-way, how many of its +// tiles the timing of the stop says the player walked. Not set: anywhere +// on the leg. +struct StepOutcome{ + StepEnd end = StepEnd::DONE; + std::optional walked; +}; + +// Whether, after each leg to a wall, the walker taps once more toward the +// wall and logs whether the player moved (see RouteCalls). +enum class WallCheck{ + TAP, + SKIP, +}; + +// What the route was planned with, to plan the way back onto it: the maps +// (with the event flags the caller set) and the costs; and, for the route +// log (Pokemon_RouteLog.h), where it starts and what the caller calls it. +struct RoutePlanning{ + const std::vector* maps = nullptr; + RouteCosts costs = default_route_costs(); + std::optional start; + std::string label = "Route"; + WallCheck wall_check = WallCheck::TAP; +}; + +// The console side. `walk` walks one step from `facing` (unknown after a +// stop); `hold_to_warp` holds on along a stopped leg until its warp; +// `fail` throws. +struct RouteCalls{ + std::function facing)> walk; + std::function hold_to_warp; + std::function log; + std::function fail; + // Taps once more toward the wall a leg to a wall ended at, and says + // whether the screen moved. Only logged: a bump and a step can't be + // told apart reliably yet. Not set (or WallCheck::SKIP): not tapped. + std::function moved_past_wall; + // After a leg that ended as planned but crosses a trainer's sight: + // watches long enough for a trainer who saw the player to walk up + // `approach_tiles` tiles and speak, has what shows cleared (the + // caller's interrupts fight the trainer), and returns LATE if anything + // showed, DONE if not. Not set: not watched. + std::function watch_for_trainer; +}; + +// Where a WALK leg crosses the sight of its maps' trainers +// (trainer_may_see()): the tiles of the leg after its start that one may +// see, in order, and the farthest any of them walks up to the player +// (their sight), to watch for them that long. Trainers already beaten are +// counted too: the maps don't know them. +struct TrainerCrossing{ + std::vector seen; + int approach_tiles = 0; +}; +// Nothing if `step`, from `start`, crosses no trainer's sight. +std::optional trainer_crossing( + const std::vector& maps, const MapPosition& start, const RouteStep& step +); + +// How often a route may stop part-way before it gives up. +constexpr size_t MAX_ROUTE_STOPS = 8; + +// Walks `route` from `facing`, logging it in the shared route log lines: +// the plan, each leg as it starts and how it ended, and where the player +// was found again. Without `planning`, a stop that needs the player found +// again fails instead, and no leg is watched for trainers. +void run_route( + const std::vector& route, std::optional facing, + const RoutePlanning* planning, const RouteCalls& calls +); + + +void add_tests_OverworldRecovery(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp new file mode 100644 index 0000000000..9100f08d3f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp @@ -0,0 +1,246 @@ +/* Overworld Recovery Walk + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTools/ImageDiff.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "CommonTools/VisualDetectors/BlackScreenDetector.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_OverworldRecoveryWalk.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace OverworldWalkSteps; + + +namespace{ + +// An open leg stops at its first interruption: walking on from how far it +// got went wrong too often on the console. The timing only narrows where +// the player is, and the route finds them again at a wall. See +// walk_overworld_route_with_recovery(). +Pokemon::LegSpec leg_spec(const RouteStep& step, MoveSpeed speed){ + Pokemon::LegSpec leg; + leg.direction = step.direction; + leg.tiles = step.tiles; + leg.to_wall = step.to_wall; + leg.tile_time = tile_time(step, speed); + leg.stop_on_interrupt = !step.to_wall; + leg.stop_if_blocked = step.to_wall; + return leg; +} + +// One step of a route, for a player facing `facing`. If an open leg +// stopped part-way, returns how far the timing puts the player along it. +std::optional walk_step( + ConsoleHandle& console, ProControllerContext& context, + const RouteStep& step, std::optional facing, + const OverworldInterruptSet& interrupts, MoveSpeed speed +){ + switch (step.action){ + case RouteAction::WALK:{ + // Turning first, with a tap, makes the hold start from a standstill + // facing the right way: holding through a turn lost a tile on the + // console, while holds from a standstill were exact over 15 tiles. + if (facing != step.direction){ + pbf_press_dpad(context, dpad(step.direction), TURN_TAP, TURN_SETTLE); + } + if (const std::string note = speed_note(step, speed); !note.empty()){ + console.log(note); + } + const Pokemon::LegResult result = Pokemon::walk_leg( + console, context, leg_mover(step, speed), step.wild ? interrupts.wild : interrupts.other, + leg_spec(step, speed), MAX_INTERRUPTIONS_PER_LEG + ); + if (result.stopped){ + return walked_near(step, result.tiles, tile_time(step, speed)); + } + if (step.warps){ + wait_out_warp(console, context, step); + static_assert(AFTER_WARP_BATTLE_WATCH >= AFTER_WARP); + check_warp_was_no_battle(console, context, step); + } + break; + } + case RouteAction::SURF: + start_surf(console, context, step.direction, facing == step.direction); + break; + case RouteAction::FACE: + pbf_press_dpad(context, dpad(step.direction), FACE_HOLD, STEP_RELEASE); + break; + } + return std::nullopt; +} + +// walk_step(), then a watch for what its last step set off. Not DONE if +// the player may have stopped short of the step's end: an open leg +// stopped, or something seen after the hold, which may have stopped it +// before the end (after a warp, it was checked for already). +StepOutcome walk_and_watch( + ConsoleHandle& console, ProControllerContext& context, + const RouteStep& step, std::optional facing, + const OverworldInterruptSet& interrupts, MoveSpeed speed +){ + if (const std::optional walked = walk_step(console, context, step, facing, interrupts, speed)){ + return StepOutcome{.end = StepEnd::STOPPED, .walked = walked}; + } + if (step.action == RouteAction::FACE){ + return StepOutcome{}; + } + const Milliseconds watch = step.wild ? AFTER_WILD_LEG_WATCH : AFTER_LEG_WATCH; + const size_t late = Pokemon::clear_late_interrupts(console, context, step.wild ? interrupts.wild : interrupts.other, watch, MAX_INTERRUPTIONS_PER_LEG); + // After a warp it was checked for already. + const bool done = late == 0 || step.warps || step.action != RouteAction::WALK; + return StepOutcome{.end = done ? StepEnd::DONE : StepEnd::LATE, .walked = std::nullopt}; +} + +// Holds on along `step`, stopped part-way off the grass, until its warp's +// fade. Off the grass only a message stops a leg (a trainer who saw the +// player, a Repel wearing off), and the player then stands on the leg's +// line, so holding on reaches the warp however far they got (console B, +// 2026-11-01: Camper Liam stopped "south 9 (warp)" out of Pewter Gym). +// After a trainer the player faces them, so this turns first. +void hold_to_warp( + ConsoleHandle& console, ProControllerContext& context, + const RouteStep& step, const OverworldInterrupts& interrupts, MoveSpeed speed +){ + const Pokemon::LegMover mover = leg_mover(step, speed); + for (size_t count = 0; count <= MAX_INTERRUPTIONS_PER_LEG; count++){ + BlackScreenWatcher fade(COLOR_RED); + std::vector> watchers; + std::vector callbacks{fade}; + for (const auto& interrupt : interrupts){ + watchers.emplace_back(interrupt->make_watcher()); + callbacks.emplace_back(*watchers.back()); + } + context.wait_for_all_requests(); + const int ret = run_until( + console, context, + [&](ProControllerContext& context){ + pbf_press_dpad(context, dpad(step.direction), TURN_TAP, TURN_SETTLE); + mover(context, step.direction, tile_time(step, speed) * (step.tiles + 2)); + }, + callbacks + ); + if (ret == 0){ + wait_out_warp(console, context, step); + check_warp_was_no_battle(console, context, step); + return; + } + if (ret < 0){ + break; + } + console.log("Route: " + interrupts[ret - 1]->name() + " on the way to the warp.", COLOR_ORANGE); + interrupts[ret - 1]->clear(console, context); + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "walk_overworld_route(): no fade holding on toward the warp to " + step.end.map + ".", + console + ); +} + +// A trainer who sees the player stops them, a "!" shows over the trainer, +// the trainer walks up, then speaks. The leg's hold may run on past the +// tile the player was stopped on, so the watch counts from the hold's end, +// with room to spare: on Route 3 (console B, 2026-11-02) Lass Robin's +// message showed after the 500ms watch after the leg had ended. Not +// measured on the console yet. +constexpr Milliseconds TRAINER_NOTICE(1500); +constexpr Milliseconds TRAINER_SPEAKS(1000); + +// After `step`, which crosses a trainer's sight: watches for the trainer +// to walk up `approach_tiles` tiles and speak, and clears what shows. +StepEnd watch_for_trainer( + ConsoleHandle& console, ProControllerContext& context, + const RouteStep& step, int approach_tiles, const OverworldInterruptSet& interrupts +){ + const Milliseconds watch = TRAINER_NOTICE + TILE_TIME * approach_tiles + TRAINER_SPEAKS; + console.log(std::format("Route: {} crosses a trainer's sight; watching {} ms for them.", to_string(step), watch.count())); + const size_t seen = Pokemon::clear_late_interrupts( + console, context, step.wild ? interrupts.wild : interrupts.other, watch, MAX_INTERRUPTIONS_PER_LEG + ); + return seen == 0 ? StepEnd::DONE : StepEnd::LATE; +} + +// TODO(forest drift, 2026-11-01): diagnostic; remove or turn into a recovery once the cause is known. +// How much the game screen's top quarter, clear of the player in the +// middle, may change when a tap toward a wall only bumps the player (the +// player's own animation, an animated tile). A step scrolls the whole map +// by a tile. Not yet measured on the console: a guess on the safe side. +constexpr double WALL_TAP_MOVED_RMSD = 20.0; + +// Taps once toward the wall `step` ended at (the player faces it, so a tap +// steps if it can) and says whether the map scrolled: whether the player +// moved instead of bumping into the wall. +bool moved_past_wall(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step){ + context.wait_for_all_requests(); + VideoSnapshot before = console.video().snapshot(); + pbf_press_dpad(context, dpad(step.direction), TURN_TAP, TILE_TIME + TURN_SETTLE); + context.wait_for_all_requests(); + VideoSnapshot after = console.video().snapshot(); + if (!before || !after){ + return false; + } + const ImageFloatBox game = GameSettings::instance().GAME_BOX; + const ImageFloatBox band(game.x, game.y, game.width, game.height * 0.25); + const double change = ImageMatch::pixel_RMSD(extract_box_reference(before, band), extract_box_reference(after, band)); + console.log(std::format("Position check: a tap toward the wall of {} changed the screen by {:.1f}.", to_string(step), change)); + return change > WALL_TAP_MOVED_RMSD; +} + +} + + +void walk_overworld_route_with_recovery( + ConsoleHandle& console, ProControllerContext& context, + const std::vector& route, + const RoutePlanning& planning, + std::optional facing, + const OverworldInterruptSet& interrupts, + MoveSpeed speed +){ + if (route.empty()){ + return; + } + if (!facing){ + facing = read_facing(console, context); + } + RouteCalls calls; + calls.walk = [&](const RouteStep& step, std::optional from_facing){ + clear_open_message(console, context, step.wild ? interrupts.wild : interrupts.other, step); + check_overworld(console, context, step); + return walk_and_watch(console, context, step, from_facing, interrupts, speed); + }; + calls.hold_to_warp = [&](const RouteStep& step){ + hold_to_warp(console, context, step, interrupts.other, speed); + }; + calls.log = [&](const std::string& message){ console.log(message, COLOR_ORANGE); }; + calls.fail = [&](const std::string& message){ + OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, message, console); + }; + calls.moved_past_wall = [&](const RouteStep& step){ + return moved_past_wall(console, context, step); + }; + calls.watch_for_trainer = [&](const RouteStep& step, int approach_tiles){ + return watch_for_trainer(console, context, step, approach_tiles, interrupts); + }; + run_route(route, facing, &planning, calls); + context.wait_for_all_requests(); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h new file mode 100644 index 0000000000..aedadc9332 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h @@ -0,0 +1,69 @@ +/* Overworld Recovery Walk + * + * From: https://github.com/PokemonAutomation/ + * + * The console side of run_route() (PokemonFRLG_OverworldRecovery.h): walks + * a route with the walker's steps (PokemonFRLG_OverworldWalk.h), except + * that an open leg stops at its first interruption, and the route finds + * the player again around where the timing puts them, instead of walking + * on from a count. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldRecoveryWalk_H +#define PokemonAutomation_PokemonFRLG_OverworldRecoveryWalk_H + +#include +#include +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "PokemonFRLG_OverworldRecovery.h" +#include "PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_OverworldWalk.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Walks `route`, planned with `planning`, at `speed`, as +// walk_overworld_route() does, from the same start: standing still on the +// overworld, not on the bike, facing `facing` (read from the screen if not +// given). +// +// When a battle or a message stops an open leg part-way, where the player +// is isn't guessed: the stop's timing narrows it to a few tiles of the leg +// (walked_near()), from which run_route() finds them again with +// `planning`'s maps and costs, and walks the rest of the route as planned. +// +// After a leg that crosses a trainer's sight it watches for the trainer, +// long enough for them to walk up and speak, and hands what shows to +// `interrupts`; where the maps place the stop, the route goes on from +// there (run_route()). +// +// After each leg to a wall it taps once more toward the wall, and logs +// whether the screen moved (a diagnostic; RoutePlanning::wall_check SKIP +// turns it off, as the Fast checks level does). +// +// A message open before a step is handed to `interrupts` once +// (clear_open_message()). Throws OperationFailedException if a menu or +// message is still open before a step, a warp's fade or the Surf prompt +// doesn't show, a warp's fade turns out to be a wild battle's, a leg is +// interrupted too many times, or the player can't be found again from +// every tile they may be on. A wild battle that starts as the last leg +// ends is cleared before it returns. +void walk_overworld_route_with_recovery( + ConsoleHandle& console, ProControllerContext& context, + const std::vector& route, + const RoutePlanning& planning, + std::optional facing = std::nullopt, + const OverworldInterruptSet& interrupts = default_overworld_interrupts(), + MoveSpeed speed = MoveSpeed::WALK +); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp new file mode 100644 index 0000000000..453872473e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp @@ -0,0 +1,503 @@ +/* Overworld Recovery Tests + * + * From: https://github.com/PokemonAutomation/ + * + * run_route() with scripted steps: walk, interruption, recovery, resume. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_OverworldMaps.h" +#include "PokemonFRLG_OverworldReanchor.h" +#include "PokemonFRLG_OverworldRecovery.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +class Test_OverworldRecovery : public UnitTest{ +public: + Test_OverworldRecovery(std::string name, std::function body) + : UnitTest("PokemonFRLG::OverworldRecovery - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + +// Steps that end as scripted, by the order they are walked in; DONE if not. +struct ScriptedRoute{ + std::map ends; + std::vector walked; + std::vector held_to_warp; + std::vector logs; + std::string failure; + // Whether the tap past a leg's wall moves the player, and the taps made. + bool moves_past_wall = false; + size_t wall_taps = 0; + // The way each walked step started facing. + std::vector> facings; + // How the watches for a trainer end, in order; DONE after these. The + // approach of each watch made. + std::vector watch_ends; + std::vector watches; + + RouteCalls calls(){ + RouteCalls calls; + calls.walk = [this](const RouteStep& step, std::optional facing){ + walked.push_back(step); + facings.push_back(facing); + auto iter = ends.find(walked.size() - 1); + return iter == ends.end() ? StepOutcome{} : iter->second; + }; + calls.hold_to_warp = [this](const RouteStep& step){ held_to_warp.push_back(step); }; + calls.log = [this](const std::string& message){ logs.push_back(message); }; + calls.moved_past_wall = [this](const RouteStep&){ + wall_taps++; + return moves_past_wall; + }; + calls.fail = [this](const std::string& message){ + failure = message; + throw std::runtime_error(message); + }; + calls.watch_for_trainer = [this](const RouteStep&, int approach_tiles){ + watches.push_back(approach_tiles); + return watches.size() <= watch_ends.size() ? watch_ends[watches.size() - 1] : StepEnd::DONE; + }; + return calls; + } + // Runs, and returns whether it failed. + bool run(const std::vector& route, const RoutePlanning* planning){ + try{ + run_route(route, std::nullopt, planning, calls()); + }catch (std::runtime_error&){ + return true; + } + return false; + } +}; + +std::string describe(const std::vector& route){ + std::string text; + for (const RouteStep& step : route){ + text += "\n " + to_string(step); + } + return text; +} + +// Passes if each of `parts` is in some line of `logs`. +UnitTestResult expect_logged(const std::vector& logs, const std::vector& parts){ + for (const std::string& part : parts){ + bool found = false; + for (const std::string& line : logs){ + found = found || line.find(part) != std::string::npos; + } + if (!found){ + return "Expected a log line with \"" + part + "\"."; + } + } + return true; +} + +bool same(const RouteStep& a, const RouteStep& b){ + return to_string(a) == to_string(b); +} + +UnitTestResult expect_walked(const std::vector& expected, const std::vector& walked){ + bool match = expected.size() == walked.size(); + for (size_t c = 0; match && c < expected.size(); c++){ + match = same(expected[c], walked[c]); + } + if (!match){ + return "Walked:" + describe(walked) + "\nexpected:" + describe(expected); + } + return true; +} + +StepOutcome stop_part_way(std::optional walked = std::nullopt){ + return StepOutcome{.end = StepEnd::STOPPED, .walked = walked}; +} + +// Viridian Mart to Oak's Lab; the first open leg through grass is stopped +// by a battle halfway, by its timing. The player is found again from the +// tiles around there, walked back to that leg's end, and the rest of the +// route is walked as planned. +UnitTestResult test_stop_recover_resume(){ + const std::vector maps = overworld_maps(); + const MapPosition start{"ViridianCity_Mart", map_point(maps, "ViridianCity_Mart", "clerk_front")}; + const std::optional> route = plan_overworld_route( + maps, start, RouteGoal{{"PalletTown_ProfessorOaksLab", {6, 4}}, std::nullopt} + ); + if (!route){ + return "No route."; + } + size_t stopped = 0; + while (stopped < route->size() && !((*route)[stopped].wild && !(*route)[stopped].to_wall)){ + stopped++; + } + if (stopped == 0 || stopped == route->size()){ + return "Expected an open leg through grass:" + describe(*route); + } + const RouteStep& step = (*route)[stopped]; + const WalkedTiles walked = walked_near(step, step.tiles / 2, std::chrono::milliseconds(267)); + ScriptedRoute script; + script.ends[stopped] = StepOutcome{.end = StepEnd::STOPPED, .walked = walked}; + const RoutePlanning planning{.maps = &maps, .costs = default_route_costs(), .start = std::nullopt, .label = "Route", .wall_check = WallCheck::TAP}; + if (script.run(*route, &planning)){ + return "Failed: " + script.failure; + } + + const std::vector candidates = stop_candidates(maps, (*route)[stopped - 1].end, step, walked); + const std::optional anchor = plan_reanchor(maps, candidates, step); + if (candidates.size() != (size_t)(walked.max - walked.min + 1) || !anchor || anchor->holds.empty()){ + return std::format("Expected holds from the {} tiles around the estimate.", walked.max - walked.min + 1); + } + std::vector expected(route->begin(), route->begin() + stopped + 1); + expected.insert(expected.end(), anchor->holds.begin(), anchor->holds.end()); + expected.insert(expected.end(), anchor->back.begin(), anchor->back.end()); + expected.insert(expected.end(), route->begin() + stopped + 1, route->end()); + const UnitTestResult walked_as_expected = expect_walked(expected, script.walked); + if (walked_as_expected.result != UnitTestResult::PASSED){ + return walked_as_expected; + } + return expect_logged(script.logs, { + "): ended at an unknown tile (unknown: stopped part-way).", + std::format("{} stopped {} to {} tiles in; the player is on one of: {};", to_string(step), walked.min, walked.max, to_string(candidates[0])), + ": found again at " + anchor->found.map + " " + Pokemon::to_string(anchor->found.point), + }); +} + +// A corridor with a person at each end: nothing finds the player again. +const char* const TEST_CORRIDOR_JSON = R"({ + "name": "Corridor", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, + "tiles": ["#######", "#.....#", "#######"], + "elevation": ["3333333", "3333333", "3333333"], + "objects": [ + {"name": "youngster", "kind": "npc", "x": 1, "y": 1}, + {"name": "lass", "kind": "npc", "x": 5, "y": 1} + ] +})"; + +RouteStep walk(Direction direction, int tiles, MapPosition end){ + RouteStep step; + step.direction = direction; + step.tiles = tiles; + step.facing_after = direction; + step.end = std::move(end); + return step; +} + +// With no maps, or no walls to find the player by from every tile they may +// be on, a stop fails the route instead of guessing. +UnitTestResult test_no_recovery(){ + const std::vector maps{parse_map(TEST_CORRIDOR_JSON, "Corridor")}; + const std::vector route{walk(Direction::EAST, 2, {"Corridor", {4, 1}})}; + ScriptedRoute without_maps; + without_maps.ends[0] = stop_part_way(); + if (!without_maps.run(route, nullptr) || without_maps.failure.find("no maps") == std::string::npos){ + return "Expected a failure without maps, got: " + without_maps.failure; + } + ScriptedRoute without_walls; + without_walls.ends[0] = stop_part_way(WalkedTiles{.min = 1, .max = 2}); + const RoutePlanning planning{.maps = &maps, .costs = default_route_costs(), .start = std::nullopt, .label = "Route", .wall_check = WallCheck::TAP}; + if (!without_walls.run(route, &planning) || without_walls.failure.find("no holds to walls find the player") == std::string::npos){ + return "Expected a failure without walls, got: " + without_walls.failure; + } + return true; +} + +// A leg to a wall seen interrupted after its hold is walked again; one +// interrupted at once, again and again, fails. +UnitTestResult test_wall_legs(){ + RouteStep wall = walk(Direction::NORTH, 3, {"Corridor", {1, 1}}); + wall.to_wall = true; + ScriptedRoute late; + late.ends[0] = StepOutcome{.end = StepEnd::LATE, .walked = std::nullopt}; + if (late.run({wall}, nullptr) || late.walked.size() != 2){ + return "Expected the leg walked again."; + } + ScriptedRoute blocked; + blocked.ends[0] = stop_part_way(); + if (!blocked.run({wall}, nullptr)){ + return "Expected a blocked leg to a wall to fail."; + } + return true; +} + +// Off the grass, a leg to a warp stopped by a trainer is held on to the +// warp, and the route goes on. +UnitTestResult test_warp_leg(){ + RouteStep door = walk(Direction::SOUTH, 9, {"PewterCity", {16, 18}}); + door.warps = true; + const RouteStep after = walk(Direction::EAST, 2, {"PewterCity", {18, 18}}); + ScriptedRoute script; + script.ends[0] = stop_part_way(); + if (script.run({door, after}, nullptr) || script.held_to_warp.size() != 1 || script.walked.size() != 2){ + return "Expected a hold to the warp, then the next step."; + } + return true; +} + +// After a leg to a wall, a tap toward it that moves the screen is only +// logged (the forest drift diagnostic): a bump and a step can't be told +// apart yet. With the check off there is no tap. Open legs aren't tapped. +UnitTestResult test_wall_check(){ + RouteStep wall = walk(Direction::NORTH, 3, {"Corridor", {1, 1}}); + wall.to_wall = true; + const RouteStep open = walk(Direction::EAST, 2, {"Corridor", {3, 1}}); + struct Case{ + const char* name; + bool moves; + WallCheck check; + bool logged; + size_t taps; + }; + const Case cases[] = { + {.name = "the tap moves", .moves = true, .check = WallCheck::TAP, .logged = true, .taps = 1}, + {.name = "the tap bumps", .moves = false, .check = WallCheck::TAP, .logged = false, .taps = 1}, + {.name = "the check is off", .moves = true, .check = WallCheck::SKIP, .logged = false, .taps = 0}, + }; + for (const Case& c : cases){ + const RoutePlanning planning{.maps = nullptr, .costs = default_route_costs(), .start = std::nullopt, .label = "Route", .wall_check = c.check}; + ScriptedRoute script; + script.moves_past_wall = c.moves; + if (script.run({wall, open}, &planning) || script.walked.size() != 2 || script.wall_taps != c.taps){ + return std::format("{}: expected both legs walked after {} tap(s), got {} after {}: {}", + c.name, c.taps, script.walked.size(), script.wall_taps, script.failure); + } + const UnitTestResult logged = expect_logged(script.logs, {"Position check (logged only): a tap after " + to_string(wall)}); + if ((logged.result == UnitTestResult::PASSED) != c.logged){ + return std::string(c.name) + (c.logged ? ": expected the tap logged." : ": didn't expect the tap logged."); + } + } + return true; +} + +// The route log lines the games share (Pokemon_RouteLog.h): the plan from +// the caller's start under its label, then each leg and how it ended. +UnitTestResult test_route_logged(){ + const std::vector route{ + walk(Direction::EAST, 2, {"Corridor", {4, 1}}), + walk(Direction::WEST, 1, {"Corridor", {3, 1}}), + }; + const RoutePlanning planning{.maps = nullptr, .costs = default_route_costs(), .start = MapPosition{"Corridor", {2, 1}}, .label = "test walk", .wall_check = WallCheck::TAP}; + ScriptedRoute script; + if (script.run(route, &planning)){ + return "Failed: " + script.failure; + } + const std::vector expected{ + "[Route] test walk: plan from Corridor (2, 1):\n" + " east 2 (open) to Corridor (4, 1)\n" + " west 1 (open) to Corridor (3, 1)", + "[Route] Leg 1/2: east 2 (open) to Corridor (4, 1)", + "[Route] test walk: east 2 (open): ended at Corridor (4, 1) (walked).", + "[Route] Leg 2/2: west 1 (open) to Corridor (3, 1)", + "[Route] test walk: west 1 (open): ended at Corridor (3, 1) (walked).", + }; + for (size_t c = 0; c < expected.size(); c++){ + const std::string got = c < script.logs.size() ? "\"" + script.logs[c] + "\"" : std::string("nothing"); + if (c >= script.logs.size() || script.logs[c] != expected[c]){ + return "Log line " + std::to_string(c) + ": expected \"" + expected[c] + "\", got " + got + "."; + } + } + return true; +} + +// Route 3's Lass Robin (console B, 2026-11-02), shrunk: a corridor along +// row 1, walled at x 6, and below it Robin's column x 3, where she wanders +// y 2..4 looking north and south, sight 3. Every way east along the +// corridor crosses her sight at (3, 1), and nowhere else. +const char* const TEST_ROBIN_JSON = R"({ + "name": "Robin", "source": {"decomp_file": "", "revision": "test", "date": "2026-11-02"}, + "tiles": ["#######", "......#", "###.###", "###.###", "###.###", "#######"], + "objects": [ + {"name": "lass", "kind": "npc", "x": 3, "y": 3, "wander": {"x0": 3, "y0": 2, "x1": 3, "y1": 4}, "trainer": {"sight": 3, "looks": ["north", "south"]}} + ] +})"; + +MapPosition robin(int x, int y){ + return MapPosition{"Robin", {x, y}}; +} + +// East along the corridor crosses Robin's sight on (3, 1) only; west of +// her, or back from the wall, it doesn't. +UnitTestResult test_trainer_crossing(){ + const std::vector maps{parse_map(TEST_ROBIN_JSON, "Robin")}; + RouteStep east = walk(Direction::EAST, 5, robin(5, 1)); + east.to_wall = true; + const std::optional crossing = trainer_crossing(maps, robin(0, 1), east); + if (!crossing || crossing->seen != std::vector{robin(3, 1)} || crossing->approach_tiles != 3){ + return "Expected east along the corridor to cross her sight on (3, 1) only, with an approach of 3."; + } + if (trainer_crossing(maps, robin(0, 1), walk(Direction::EAST, 2, robin(2, 1))) + || trainer_crossing(maps, robin(5, 1), walk(Direction::WEST, 1, robin(4, 1))) + ){ + return "Expected legs off her column to cross no sight."; + } + return true; +} + +// A leg east past Robin, then a turn north: how the leg and the watch for +// her after it end, and whether she saw the player. +struct TrainerCase{ + const char* name; + RouteStep leg; + StepEnd walk_end; + std::optional walked; + StepEnd watch_end; + size_t watches; + bool seen; +}; + +// What `c`'s route should walk: the leg, then, if she saw the player, the +// way on from (3, 1) to its end, then the turn. +std::optional> expected_walk(const std::vector& maps, const TrainerCase& c, const RouteStep& face){ + std::vector expected{c.leg}; + if (c.seen){ + const std::optional> way = plan_overworld_route(maps, robin(3, 1), RouteGoal{c.leg.end, std::nullopt}, default_route_costs(), Direction::EAST); + if (!way || way->empty()){ + return std::nullopt; + } + expected.insert(expected.end(), way->begin(), way->end()); + } + expected.push_back(face); + return expected; +} + +UnitTestResult run_trainer_case(const std::vector& maps, const TrainerCase& c){ + RouteStep face = walk(Direction::NORTH, 0, c.leg.end); + face.action = RouteAction::FACE; + const RoutePlanning planning{.maps = &maps, .costs = default_route_costs(), .start = robin(0, 1), .label = "Route", .wall_check = WallCheck::SKIP}; + ScriptedRoute script; + script.ends[0] = StepOutcome{.end = c.walk_end, .walked = c.walked}; + script.watch_ends = {c.watch_end}; + if (script.run({c.leg, face}, &planning)){ + return "failed: " + script.failure; + } + const std::optional> expected = expected_walk(maps, c, face); + if (!expected){ + return "expected a way on from (3, 1)."; + } + bool match = expected->size() == script.walked.size() && script.watches.size() == c.watches; + for (size_t i = 0; match && i < expected->size(); i++){ + match = same((*expected)[i], script.walked[i]); + } + if (!match){ + return std::format("walked:{}\nexpected:{}\nafter {} watch(es)", describe(script.walked), describe(*expected), script.watches.size()); + } + if (c.watches > 0 && script.watches[0] != 3){ + return "expected a watch for an approach of 3."; + } + if (c.seen && script.facings[1] != Direction::EAST){ + return "expected the route on from (3, 1) to start facing east."; + } + const UnitTestResult logged = expect_logged(script.logs, {"stopped by a trainer who saw the player, at Robin (3, 1); planning again."}); + if ((logged.result == UnitTestResult::PASSED) != c.seen){ + return c.seen ? "expected the stop logged at (3, 1)." : "didn't expect a stop logged."; + } + return true; +} + +// She sees the player: the leg's watch for her (or the leg itself) is +// interrupted by her message, which the interrupts fight, and the route is +// planned again from (3, 1), facing east. When she doesn't, the route is +// walked as planned, after one watch. +UnitTestResult test_trainer_stops_leg(){ + const std::vector maps{parse_map(TEST_ROBIN_JSON, "Robin")}; + RouteStep wall = walk(Direction::EAST, 5, robin(5, 1)); + wall.to_wall = true; + const RouteStep open = walk(Direction::EAST, 4, robin(4, 1)); + const TrainerCase cases[] = { + {.name = "to a wall, seen", .leg = wall, .walk_end = StepEnd::DONE, .walked = std::nullopt, .watch_end = StepEnd::LATE, .watches = 1, .seen = true}, + {.name = "open, seen", .leg = open, .walk_end = StepEnd::STOPPED, .walked = std::nullopt, .watch_end = StepEnd::DONE, .watches = 0, .seen = true}, + // She stops the player on (3, 1) and speaks only after walking up, + // so the timing puts the stop past her tile: still hers. + {.name = "open, seen, timed late", .leg = open, .walk_end = StepEnd::STOPPED, .walked = WalkedTiles{.min = 3, .max = 4}, .watch_end = StepEnd::DONE, .watches = 0, .seen = true}, + {.name = "to a wall, not seen", .leg = wall, .walk_end = StepEnd::DONE, .walked = std::nullopt, .watch_end = StepEnd::DONE, .watches = 1, .seen = false}, + }; + for (const TrainerCase& c : cases){ + const UnitTestResult result = run_trainer_case(maps, c); + if (result.result != UnitTestResult::PASSED){ + return std::string(c.name) + ": " + result.message; + } + } + return true; +} + + +// On the grass a stop past Robin's column may be a wild battle's anywhere +// on the leg, or hers on (3, 1), after which she stands on (3, 2): the +// player is found again from all of them, then walks back to the leg's end. +UnitTestResult test_grass_in_sight(){ + const std::vector maps{parse_map(TEST_ROBIN_JSON, "Robin")}; + RouteStep grass = walk(Direction::EAST, 4, robin(4, 1)); + grass.wild = true; + RouteStep face = walk(Direction::NORTH, 0, grass.end); + face.action = RouteAction::FACE; + const std::vector candidates = stop_candidates(maps, robin(0, 1), grass, whole_leg(grass)); + const StopCandidate hers{.player = robin(3, 1), .trainer = TrainerStop{.object = 0, .at = robin(3, 2)}}; + if (candidates.size() != 6 || std::find(candidates.begin(), candidates.end(), hers) == candidates.end()){ + return std::format("Expected the leg's 5 tiles and hers, got {} candidates.", candidates.size()); + } + const std::optional anchor = plan_reanchor(maps, candidates, grass); + if (!anchor || anchor->holds.empty()){ + return "Expected holds that find the player."; + } + const RoutePlanning planning{.maps = &maps, .costs = default_route_costs(), .start = robin(0, 1), .label = "Route", .wall_check = WallCheck::SKIP}; + ScriptedRoute script; + script.ends[0] = stop_part_way(); + if (script.run({grass, face}, &planning)){ + return "Failed: " + script.failure; + } + std::vector expected{grass}; + expected.insert(expected.end(), anchor->holds.begin(), anchor->holds.end()); + expected.insert(expected.end(), anchor->back.begin(), anchor->back.end()); + expected.push_back(face); + const UnitTestResult walked = expect_walked(expected, script.walked); + if (walked.result != UnitTestResult::PASSED){ + return walked; + } + return expect_logged(script.logs, {"Robin (3, 1) (stopped by a trainer, now at (3, 2))"}); +} + +} + + +void add_tests_OverworldRecovery(UnitTestDatabase& database){ + database.add("stop, recover, resume", test_stop_recover_resume); + database.add("no recovery", test_no_recovery); + database.add("legs to a wall", test_wall_legs); + database.add("a leg to a warp", test_warp_leg); + database.add("the route is logged", test_route_logged); + database.add("a leg to a wall ends at it", test_wall_check); + database.add("a leg crosses a trainer's sight", test_trainer_crossing); + database.add("a trainer stops a leg", test_trainer_stops_leg); + database.add("a stop on the grass in a trainer's sight", test_grass_in_sight); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp new file mode 100644 index 0000000000..6e63bc8ed4 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp @@ -0,0 +1,993 @@ +/* Overworld Route + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/Navigation/Pokemon_LegPlanner.h" +#include "PokemonFRLG_OverworldMaps.h" +#include "PokemonFRLG_OverworldRoute.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +std::string to_string(const MapPosition& position){ + return position.map + " " + to_string(position.point); +} + +std::string to_string(const RouteStep& step){ + std::string text; + switch (step.action){ + case RouteAction::WALK: + text = std::format("walk {} {}", direction_name(step.direction), step.tiles); + if (step.warps){ + text += " (warp)"; + } + if (step.to_wall){ + text += " (to wall)"; + } + break; + case RouteAction::SURF: + text = "surf " + std::string(direction_name(step.direction)); + break; + case RouteAction::FACE: + text = "face " + std::string(direction_name(step.direction)); + break; + } + return text + " -> " + to_string(step.end); +} + + + +const RouteCosts& default_route_costs(){ + static const RouteCosts COSTS{ + {RouteCost::TILE, 1}, + {RouteCost::TURN, 2}, + {RouteCost::WARP, 30}, + {RouteCost::SURF, 40}, + {RouteCost::GRASS_TILE, 20}, + {RouteCost::OPEN_STOP, 8}, + {RouteCost::OPEN_WILD_STOP, 300}, + }; + return COSTS; +} + +int route_cost(const RouteCosts& costs, RouteCost kind){ + auto iter = costs.find(kind); + if (iter == costs.end()){ + iter = default_route_costs().find(kind); + } + return iter->second; +} + + + +namespace{ + + +int find_map(const std::vector& maps, const std::string& name){ + for (size_t c = 0; c < maps.size(); c++){ + if (maps[c].name == name){ + return (int)c; + } + } + return -1; +} + +// The player on one of the loaded maps. +struct Located{ + int map = 0; + PlayerState state; + + bool operator==(const Located& other) const{ + return map == other.map + && state.position == other.state.position + && state.elevation == other.state.elevation + && state.surfing == other.state.surfing; + } +}; +struct LocatedHash{ + size_t operator()(const Located& player) const{ + return (((std::hash()(player.state.position) * 31 + player.map) * 16 + + player.state.elevation) * 2) + (player.state.surfing ? 1 : 0); + } +}; + +// What pressing a direction once does to the player. +struct Transition{ + Located next; + RouteAction action = RouteAction::WALK; + bool warped = false; + bool walked_out = false; // the warp ended with the game walking the player out + bool dismounted = false; // stepped off the water onto land +}; + +// The player taking `warp`, or nothing if it leads off the loaded maps. +std::optional take_warp(const std::vector& maps, const MapWarp* warp){ + if (warp == nullptr || !warp->to){ + return std::nullopt; + } + const int destination = find_map(maps, warp->to->map); + if (destination < 0){ + return std::nullopt; + } + 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; + Transition transition; + if (walks_out_on_arrival(map, position)){ + position = position.next(Direction::SOUTH); + transition.walked_out = true; + } + transition.next.map = destination; + transition.next.state = PlayerState{position, elevation_at(map, position), false}; + transition.warped = true; + return transition; +} + +// Walking off the map's edge onto the map connected there, if it is loaded. +std::optional cross_edge(const std::vector& 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; + } + return std::nullopt; +} + +// Pressing `direction` once (field_control_avatar.c): an exit mat or a door +// warps without the player moving, a step onto a ladder or cave entrance +// warps after it, and anything else is a step by the collision rules. +std::optional press(const std::vector& maps, const Located& player, Direction direction){ + const MapData& map = maps[player.map]; + const TilePos here = player.state.position; + if (exit_mat(map, here) == direction){ + return take_warp(maps, warp_at(map, here)); + } + const TilePos ahead = here.next(direction); + if (direction == Direction::NORTH && is_door(map, ahead) && !player.state.surfing){ + return take_warp(maps, warp_at(map, ahead)); + } + + if (!in_bounds(map, ahead)){ + return cross_edge(maps, player, direction); + } + + const StepKind kind = classify_step(map, player.state, direction); + if (kind == StepKind::BLOCKED){ + return std::nullopt; + } + Transition transition; + transition.next = player; + transition.next.state = after_step(map, player.state, direction, kind); + transition.action = kind == StepKind::START_SURF ? RouteAction::SURF : RouteAction::WALK; + transition.dismounted = kind == StepKind::STOP_SURFING; + const TilePos landed = transition.next.state.position; + if (transition.action == RouteAction::WALK && warps_on_step(map, landed) && warp_at(map, landed) != nullptr){ + return take_warp(maps, warp_at(map, landed)); + } + return transition; +} + +// Whether pressing `direction` takes a warp to a map that isn't loaded, +// which press() refuses as if it were a wall. +bool warps_off_loaded_maps(const std::vector& maps, const Located& player, Direction direction){ + const MapData& map = maps[player.map]; + const TilePos here = player.state.position; + const TilePos ahead = here.next(direction); + const MapWarp* warp = nullptr; + if (exit_mat(map, here) == direction){ + warp = warp_at(map, here); + }else if (direction == Direction::NORTH && is_door(map, ahead) && !player.state.surfing){ + warp = warp_at(map, ahead); + }else if (in_bounds(map, ahead) && warps_on_step(map, ahead) && classify_step(map, player.state, direction) != StepKind::BLOCKED){ + warp = warp_at(map, ahead); + } + return warp != nullptr && !take_warp(maps, warp); +} + +// Whether holding `direction` stops the player where they are: a wall, or +// water they'd need to Surf onto. A leg that ends there can be +// held for longer than it takes, and walked again after an interruption. A +// person in the way doesn't count, since they may have wandered off, and +// neither does an edge to a map that isn't loaded. +bool stops_at(const std::vector& maps, const Located& player, Direction direction){ + const std::optional transition = press(maps, player, direction); + if (transition){ + return transition->action == RouteAction::SURF; + } + // Nor does a warp to a map that isn't loaded: the player takes it (console + // B, 2026-11-02, "west 5 (to wall)" rode Route 4's Pokemon Center + // escalator up to 2F). + if (warps_off_loaded_maps(maps, player, direction)){ + return false; + } + const MapData& map = maps[player.map]; + const TilePos ahead = player.state.position.next(direction); + // Held into a sign moving north or south, the game shows the sign's + // message: the player stops, but the walk is interrupted (console B, + // 2026-11-01, the poster on the bedroom's wall). + if (tile_at(map, ahead) == TileKind::SIGN && (direction == Direction::NORTH || direction == Direction::SOUTH)){ + return false; + } + // Held into a ledge the way it faces, the player hops down it (console + // B, 2026-11-01, Viridian City: "south 2 (to wall)" from the Pokemon + // Center hopped the ledge two rows down). Routes don't hop ledges, so + // none is held into. + if (is_ledge(map, ahead)){ + return false; + } + if (in_bounds(map, ahead)){ + return object_at(map, ahead) == nullptr; + } + for (const MapConnection& connection : map.connections){ + if (connection.side == direction){ + return false; + } + } + return true; +} + +// The search state: a player, the way they face (4 stands for "not known +// yet", before the first step), and whether they are in the middle of a leg +// that could go on, as opposed to just stopped by a warp or Surf. +// The game's step rules for the shared leg planner. +class StepModel{ +public: + using State = Located; + using StateHash = LocatedHash; + + StepModel(const std::vector& maps, const RouteCosts& costs) + : m_maps(maps) + , m_costs(costs) + {} + + std::optional> press(const State& state, Direction direction) const{ + const std::optional transition = PokemonFRLG::press(m_maps, state, direction); + if (!transition){ + return std::nullopt; + } + Pokemon::Step step; + step.next = transition->next; + step.action = transition->action == RouteAction::SURF ? ACTION_SURF : 0; + // Leaving the water: the player walks at half the speed from here. + step.starts_leg = transition->dismounted; + step.ends_leg = transition->warped || transition->dismounted; + step.warped = transition->warped; + step.facing = transition->walked_out ? Direction::SOUTH : direction; + if (transition->action == RouteAction::SURF){ + step.extra_cost += route_cost(m_costs, RouteCost::SURF); + } + if (transition->warped){ + step.extra_cost += route_cost(m_costs, RouteCost::WARP); + } + if (is_tall_grass(m_maps[step.next.map], step.next.state.position)){ + step.extra_cost += route_cost(m_costs, RouteCost::GRASS_TILE); + step.wild = true; + } + if (step.next.state.surfing){ + step.wild = true; + } + return step; + } + bool held_at(const State& state, Direction direction) const{ + return stops_at(m_maps, state, direction); + } + + static constexpr int ACTION_SURF = 1; + +private: + const std::vector& m_maps; + const RouteCosts& m_costs; +}; + +Pokemon::LegCosts to_leg_costs(const RouteCosts& costs){ + Pokemon::LegCosts leg_costs; + leg_costs.per_tile = route_cost(costs, RouteCost::TILE); + leg_costs.per_turn = route_cost(costs, RouteCost::TURN); + leg_costs.per_open_stop = route_cost(costs, RouteCost::OPEN_STOP); + leg_costs.per_open_wild_stop = route_cost(costs, RouteCost::OPEN_WILD_STOP); + return leg_costs; +} + +RouteStep to_route_step(const std::vector& maps, const Pokemon::Leg& leg){ + RouteStep step; + switch (leg.kind){ + case Pokemon::LegKind::WALK: + step.action = RouteAction::WALK; + break; + case Pokemon::LegKind::ACTION: + step.action = RouteAction::SURF; + break; + case Pokemon::LegKind::FACE: + step.action = RouteAction::FACE; + break; + } + step.direction = leg.direction; + step.tiles = leg.kind == Pokemon::LegKind::FACE ? 0 : leg.tiles; + step.warps = leg.warps; + step.surfing = leg.start.state.surfing; + step.to_wall = leg.to_wall; + step.facing_after = leg.facing_after; + step.end = MapPosition{maps[leg.end.map].name, leg.end.state.position}; + if (leg.kind != Pokemon::LegKind::FACE){ + // Tall grass on any map the leg crosses, or the water. Counted on the + // start map only, "north 22" from Pallet Town through Route 1's grass + // wasn't watched for battles (console B, 2026-11-01). + step.wild = leg.wild || leg.start.state.surfing || leg.kind == Pokemon::LegKind::ACTION; + } + return step; +} + +} + + + +std::optional> plan_overworld_route( + const std::vector& maps, + const MapPosition& start, + const RouteGoal& goal, + const RouteCosts& costs, + std::optional start_facing +){ + const int start_map = find_map(maps, start.map); + const int goal_map = find_map(maps, goal.position.map); + if (start_map < 0 || goal_map < 0){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Route between maps that aren't loaded."); + } + Located first; + first.map = start_map; + first.state.position = start.point; + first.state.elevation = elevation_at(maps[start_map], start.point); + first.state.surfing = is_water(maps[start_map], start.point); + + const StepModel model(maps, costs); + const auto legs = Pokemon::plan_legs( + model, first, start_facing, + std::function([&](const Located& player){ + return player.map == goal_map && player.state.position == goal.position.point; + }), + goal.facing, to_leg_costs(costs) + ); + if (!legs){ + return std::nullopt; + } + + std::vector route; + for (const Pokemon::Leg& leg : *legs){ + route.push_back(to_route_step(maps, leg)); + } + return route; +} + + +namespace{ + +// Further than any straight line on a map. +constexpr int MAX_HOLD_TILES = 128; + +std::optional locate(const std::vector& maps, const MapPosition& position, bool surfing){ + const int map = find_map(maps, position.map); + if (map < 0){ + return std::nullopt; + } + Located player; + player.map = map; + player.state = PlayerState{position.point, elevation_at(maps[map], position.point), surfing}; + return player; +} + +// A plain step: no warp, no Surf, no getting off the water. +std::optional plain_step(const std::vector& maps, const Located& player, Direction direction){ + const std::optional transition = press(maps, player, direction); + if (!transition || transition->warped || transition->dismounted || transition->action != RouteAction::WALK){ + return std::nullopt; + } + return transition->next; +} + +} + + +namespace{ + +// Holding north into a ledge stops the player: the maps don't keep which way +// a ledge faces, but FRLG's face south, east or west (pokefirered has no +// MB_JUMP_NORTH on any map these load). Only finding the player again +// relies on this; routes never hold into a ledge (stops_at()). +bool ledge_stops_north(const std::vector& maps, const Located& player, Direction direction){ + return direction == Direction::NORTH && is_ledge(maps[player.map], player.state.position.next(direction)); +} + +} + +std::optional hold_to_wall( + const std::vector& maps, + const MapPosition& from, bool surfing, Direction direction +){ + std::optional player = locate(maps, from, surfing); + WallHold hold; + for (int c = 0; player && c <= MAX_HOLD_TILES; c++){ + if (stops_at(maps, *player, direction) || ledge_stops_north(maps, *player, direction)){ + hold.end = MapPosition{maps[player->map].name, player->state.position}; + hold.tiles = c; + return hold; + } + player = plain_step(maps, *player, direction); + if (player){ + const MapData& map = maps[player->map]; + hold.wild = hold.wild || is_tall_grass(map, player->state.position) || player->state.surfing; + } + } + return std::nullopt; +} + +std::vector leg_tiles( + const std::vector& maps, + const MapPosition& start, const RouteStep& step +){ + std::vector tiles{start}; + std::optional player = locate(maps, start, step.surfing); + const int along = step.tiles - (step.warps ? 1 : 0); + for (int c = 0; player && c < along; c++){ + player = plain_step(maps, *player, step.direction); + if (player){ + tiles.push_back(MapPosition{maps[player->map].name, player->state.position}); + } + } + return tiles; +} + +MapPosition follow_overworld_route( + const std::vector& maps, + const MapPosition& start, + const std::vector& route +){ + Located player; + player.map = find_map(maps, start.map); + if (player.map < 0){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Route from a map that isn't loaded: " + start.map); + } + player.state.position = start.point; + player.state.elevation = elevation_at(maps[player.map], start.point); + player.state.surfing = is_water(maps[player.map], start.point); + + for (const RouteStep& step : route){ + if (step.action == RouteAction::FACE){ + continue; + } + for (int c = 0; c < step.tiles; c++){ + const std::optional transition = press(maps, player, step.direction); + if (!transition || transition->action != step.action){ + throw InternalProgramError( + nullptr, PA_CURRENT_FUNCTION, + "Step refused at " + to_string(MapPosition{maps[player.map].name, player.state.position}) + ": " + to_string(step) + ); + } + player = transition->next; + } + const MapPosition position{maps[player.map].name, player.state.position}; + if (!(position == step.end)){ + throw InternalProgramError( + nullptr, PA_CURRENT_FUNCTION, + "Ended at " + to_string(position) + " instead of " + to_string(step.end) + ); + } + } + return MapPosition{maps[player.map].name, player.state.position}; +} + + + +namespace{ + +class Test_OverworldRoute : public UnitTest{ +public: + Test_OverworldRoute(std::string name, std::function body) + : UnitTest("PokemonFRLG::OverworldRoute - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + +std::string describe(const std::vector& route){ + std::string text; + for (const RouteStep& step : route){ + text += "\n " + to_string(step); + } + return text; +} + +// A 5x4 map for the step rules: a pond, a raised ledge reached by a stair +// tile, and a tile that can't be entered moving south. +const MapData& small_map(){ + static const MapData MAP = parse_map(R"({ + "name": "Small", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, + "tiles": ["#####", "#.8.#", "#.w.#", "#####"], + "elevation": ["33333", "33403", "33133", "33333"] + })", "Small"); + return MAP; +} + +UnitTestResult test_step_rules(){ + const MapData& map = small_map(); + PlayerState state{{1, 1}, 3, false}; + if (classify_step(map, state, Direction::EAST) != StepKind::BLOCKED){ + return "Walked from elevation 3 onto elevation 4."; + } + if (classify_step(map, PlayerState{{2, 0}, 3, false}, Direction::SOUTH) != StepKind::BLOCKED){ + return "Entered a north-blocked tile moving south."; + } + state = PlayerState{{1, 2}, 3, false}; + if (classify_step(map, state, Direction::EAST) != StepKind::START_SURF){ + return "Can't start surfing onto the pond."; + } + state = after_step(map, state, Direction::EAST, StepKind::START_SURF); + if (!state.surfing || state.elevation != 1){ + return "Surfing didn't put the player on the water."; + } + if (classify_step(map, state, Direction::EAST) != StepKind::STOP_SURFING){ + return "Can't land from the pond."; + } + if (classify_step(map, PlayerState{{3, 2}, 3, false}, Direction::NORTH) != StepKind::WALK){ + return "Can't step from elevation 3 onto the elevation-0 stair."; + } + return true; +} + +// The maps after the Hall of Fame, which clears the way to Cerulean Cave. +std::vector post_game_maps(){ + return overworld_maps(map_flag_set(overworld_maps(), "after_hall_of_fame")); +} + +MapPosition point_on(const std::vector& maps, const std::string& map, const std::string& point){ + return MapPosition{map, map_point(maps, map, point)}; +} + +const MapData* map_named(const std::vector& maps, const std::string& name){ + const int index = find_map(maps, name); + return index < 0 ? nullptr : &maps[index]; +} + +UnitTestResult test_maps(){ + const std::vector maps = post_game_maps(); + const MapData* b1f = map_named(maps, "CeruleanCave_B1F"); + const MapData* city = map_named(maps, "CeruleanCity"); + if (b1f == nullptr || city == nullptr || map_named(maps, "CeruleanCity_PokemonCenter_1F") == nullptr){ + return "Missing a map."; + } + if (b1f->tiles.width != 40 || b1f->tiles.height != 23 || city->tiles.width != 48 || city->tiles.height != 40){ + return "Unexpected map size."; + } + const TilePos mewtwo_tile = map_point(maps, "CeruleanCave_B1F", "mewtwo"); + const MapObject* mewtwo = object_at(*b1f, mewtwo_tile); + if (mewtwo == nullptr || mewtwo->name != "mewtwo"){ + return "Mewtwo is not on B1F at " + to_string(mewtwo_tile) + "."; + } + if (object_at(*city, {1, 13}) != nullptr){ + return "The cave guard is still there after the Hall of Fame."; + } + if (object_at(*map_named(overworld_maps(), "CeruleanCity"), {1, 13}) == nullptr){ + return "The cave guard is missing before the Hall of Fame."; + } + return true; +} + +// Plans `start` to `goal`, replays it with the step rules and checks where it ends. +UnitTestResult check_route( + const std::vector& maps, + const MapPosition& start, const RouteGoal& goal, + std::vector& route +){ + const std::optional> planned = plan_overworld_route(maps, start, goal); + if (!planned){ + return "No route from " + to_string(start) + " to " + to_string(goal.position) + "."; + } + route = *planned; + const MapPosition end = follow_overworld_route(maps, start, route); + if (!(end == goal.position)){ + return "Route ends at " + to_string(end) + ":" + describe(route); + } + if (goal.facing && route.back().direction != *goal.facing){ + return "Doesn't end facing " + std::string(direction_name(*goal.facing)) + ":" + describe(route); + } + return true; +} + +// Below Mewtwo, facing it, to talk to it. +RouteGoal facing_mewtwo(const std::vector& maps){ + const TilePos mewtwo = map_point(maps, "CeruleanCave_B1F", "mewtwo"); + return RouteGoal{{"CeruleanCave_B1F", mewtwo.next(Direction::SOUTH)}, Direction::NORTH}; +} + +UnitTestResult test_entrance_to_mewtwo(){ + const std::vector maps = post_game_maps(); + std::vector route; + UnitTestResult result = check_route(maps, point_on(maps, "CeruleanCave_1F", "entrance"), facing_mewtwo(maps), route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + bool surfs = false; + bool reaches_b1f = false; + for (const RouteStep& step : route){ + surfs |= step.action == RouteAction::SURF; + reaches_b1f |= step.warps && step.end.map == "CeruleanCave_B1F"; + } + if (!surfs || !reaches_b1f){ + return "Expected to take the ladder to B1F and to surf:" + describe(route); + } + return true; +} + +UnitTestResult test_pokemon_center_to_mewtwo(){ + const std::vector maps = post_game_maps(); + std::vector route; + UnitTestResult result = check_route( + maps, point_on(maps, "CeruleanCity_PokemonCenter_1F", "pc"), facing_mewtwo(maps), route + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + // Out through the exit mat, onto the city's step below the door, and + // into the cave by its entrance. + std::vector maps_in_order; + for (const RouteStep& step : route){ + if (step.warps){ + maps_in_order.push_back(step.end.map); + } + } + if (maps_in_order.size() < 2 || maps_in_order[0] != "CeruleanCity" || maps_in_order[1] != "CeruleanCave_1F"){ + return "Expected to leave by the mat and enter the cave next:" + describe(route); + } + if (!(route[0].end.map == "CeruleanCity_PokemonCenter_1F" || route[0].warps)){ + return "Unexpected first step:" + describe(route); + } + return true; +} + +UnitTestResult test_cave_guard_blocks(){ + // Before the Hall of Fame the guard stands in the cave entrance. + const std::vector maps = overworld_maps(); + if (plan_overworld_route(maps, point_on(maps, "CeruleanCity_PokemonCenter_1F", "pc"), facing_mewtwo(maps))){ + return "Planned past the cave guard."; + } + return true; +} + +UnitTestResult test_mewtwo_tile_unreachable(){ + const std::vector maps = post_game_maps(); + const std::optional> route = plan_overworld_route( + maps, + point_on(maps, "CeruleanCave_1F", "entrance"), + {point_on(maps, "CeruleanCave_B1F", "mewtwo"), std::nullopt} + ); + if (route){ + return "Planned a route onto Mewtwo itself:" + describe(*route); + } + return true; +} + +UnitTestResult test_story_maps(){ + const std::vector maps = overworld_maps(); + for (const char* name : { + "PalletTown_PlayersHouse_2F", "PalletTown_ProfessorOaksLab", "Route1", "ViridianCity_Mart", + "Route22", "Route2", "ViridianForest", "PewterCity", "PewterCity_Museum_1F", "PewterCity_Gym", + }){ + if (map_named(maps, name) == nullptr){ + return std::string("Missing map ") + name + "."; + } + } + return true; +} + +// Which maps `route` warps into, in order. +std::vector maps_warped_into(const std::vector& route){ + std::vector maps; + for (const RouteStep& step : route){ + if (step.warps){ + maps.push_back(step.end.map); + } + } + return maps; +} + +UnitTestResult test_bedroom_to_oaks_lab(){ + const std::vector maps = overworld_maps(); + std::vector route; + UnitTestResult result = check_route( + maps, point_on(maps, "PalletTown_PlayersHouse_2F", "start"), + {point_on(maps, "PalletTown", "oaks_lab_front"), Direction::NORTH}, route + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + const std::vector warped = maps_warped_into(route); + if (warped != std::vector{"PalletTown_PlayersHouse_1F", "PalletTown"}){ + return "Expected to take the stairs and leave by the front door:" + describe(route); + } + return true; +} + +UnitTestResult test_viridian_mart_to_pewter_gym(){ + const std::vector maps = overworld_maps(); + std::vector route; + UnitTestResult result = check_route( + maps, point_on(maps, "ViridianCity_Mart", "clerk_front"), + {point_on(maps, "PewterCity", "gym_front"), Direction::NORTH}, route + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + const std::vector warped = maps_warped_into(route); + if (std::find(warped.begin(), warped.end(), "ViridianForest") == warped.end()){ + return "Expected to go through Viridian Forest:" + describe(route); + } + return true; +} + +// A room with a sign on its north wall, above the third column. +const char* const TEST_SIGN_ROOM_JSON = R"({ + "name": "SignRoom", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, + "tiles": ["##S##", "#...#", "#...#", "#...#", "#####"], + "elevation": ["33333", "33333", "33333", "33333", "33333"] +})"; + +// Walking north under a sign stops by counting tiles, never by holding into +// the sign; under the wall beside it, the wall stops the player. +UnitTestResult test_no_hold_into_sign(){ + const std::vector maps{parse_map(TEST_SIGN_ROOM_JSON, "SignRoom")}; + std::vector route; + UnitTestResult result = check_route(maps, {"SignRoom", {2, 3}}, {{"SignRoom", {2, 1}}, std::nullopt}, route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + for (const RouteStep& step : route){ + if (step.to_wall && step.end.point == TilePos{2, 1}){ + return "Expected no hold into the sign:" + describe(route); + } + } + route.clear(); + result = check_route(maps, {"SignRoom", {1, 3}}, {{"SignRoom", {1, 1}}, std::nullopt}, route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + if (route.empty() || !route.back().to_wall){ + return "Expected the wall to stop the player beside the sign:" + describe(route); + } + return true; +} + +// A yard with a row of ledges across it. +const char* const TEST_LEDGE_YARD_JSON = R"({ + "name": "LedgeYard", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, + "tiles": ["#####", "#...#", "#...#", "#vvv#", "#...#", "#####"], + "elevation": ["33333", "33333", "33333", "33333", "33333", "33333"] +})"; + +// A ledge isn't a wall to hold into: moving the way it faces the player +// would hop it, and routes don't hop ledges. Viridian City, +// from the Pokemon Center's door south to the row above the ledge. +UnitTestResult test_no_hold_into_ledge(){ + const std::vector maps{parse_map(TEST_LEDGE_YARD_JSON, "LedgeYard")}; + std::vector route; + UnitTestResult result = check_route(maps, {"LedgeYard", {2, 1}}, {{"LedgeYard", {2, 2}}, std::nullopt}, route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + for (const RouteStep& step : route){ + if (step.to_wall){ + return "Expected no hold into the ledge:" + describe(route); + } + } + route.clear(); + const std::vector world = overworld_maps(); + result = check_route(world, {"ViridianCity", {26, 27}}, {{"ViridianCity", {26, 29}}, std::nullopt}, route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + for (const RouteStep& step : route){ + if (step.to_wall && step.end.point == TilePos{26, 29}){ + return "Expected no hold into the ledge below the Pokemon Center:" + describe(route); + } + } + return true; +} + +// Two small maps that don't need the map files: a room left by the exit mat +// at its bottom, onto the door of a yard, out of which the game walks the +// player. +// No wild battle can start between the bedroom and Oak's Lab: Pallet Town's +// streets have no tall grass. Route 2 and Viridian Forest do. +UnitTestResult test_wild_steps(){ + const std::vector maps = overworld_maps(); + std::vector route; + UnitTestResult result = check_route( + maps, point_on(maps, "PalletTown_PlayersHouse_2F", "start"), + {point_on(maps, "PalletTown", "oaks_lab_front"), Direction::NORTH}, route + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + for (const RouteStep& step : route){ + if (step.wild){ + return "Expected no wild step from the bedroom to Oak's Lab, got " + to_string(step) + ":" + describe(route); + } + } + route.clear(); + result = check_route( + maps, point_on(maps, "ViridianCity_Mart", "clerk_front"), + {point_on(maps, "PewterCity", "gym_front"), Direction::NORTH}, route + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + bool forest = false; + for (const RouteStep& step : route){ + forest = forest || (step.wild && step.end.map == "ViridianForest"); + } + if (!forest){ + return "Expected a wild step in Viridian Forest:" + describe(route); + } + // The leg from Pallet Town north onto Route 1 crosses Route 1's grass + // after the map's edge. + route.clear(); + result = check_route( + maps, point_on(maps, "PalletTown", "oaks_lab_front"), + {point_on(maps, "ViridianCity_Mart", "clerk_front"), std::nullopt}, route + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + for (const RouteStep& step : route){ + if (step.end.map == "Route1" && step.direction == Direction::NORTH && step.tiles > 14 && !step.wild){ + return "Expected the leg from Pallet Town onto Route 1 to be wild, got " + to_string(step) + ":" + describe(route); + } + } + return true; +} + +const char* const TEST_ROOM_JSON = R"({ + "name": "Room", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, + "tiles": ["#####", "#...#", "#...#", "##.##"], + "elevation": ["33333", "33333", "33333", "33333"], + "points": {"warp_0": [2, 3]}, + "warps": [{"x": 2, "y": 3, "enter": "walk_south", "to_map": "Yard", "to_point": "warp_0"}] +})"; +const char* const TEST_YARD_JSON = R"({ + "name": "Yard", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, + "tiles": ["#####", "##D##", "#...#", "#####"], + "elevation": ["33333", "33333", "33333", "33333"], + "points": {"warp_0": [2, 1]}, + "warps": [{"x": 2, "y": 1, "enter": "walk_into", "to_map": "Room", "to_point": "warp_0"}] +})"; + +UnitTestResult test_route_through_warp(){ + const std::vector maps{ + parse_map(TEST_ROOM_JSON, "Room"), + parse_map(TEST_YARD_JSON, "Yard"), + }; + std::vector route; + UnitTestResult result = check_route(maps, {"Room", {2, 1}}, {{"Yard", {1, 2}}, std::nullopt}, route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + for (const RouteStep& step : route){ + if (step.warps && step.end.map == "Yard"){ + return true; + } + } + return "Expected to warp into the yard:" + describe(route); +} + +// `json` with its elevation grid replaced by `rows`, or left out if empty. +std::string with_elevation(std::string json, const std::string& rows){ + const size_t begin = json.find("\"elevation\""); + const size_t end = json.find("\n", begin); + json.erase(begin, end - begin + 1); + if (!rows.empty()){ + json.insert(begin, "\"elevation\": " + rows + ",\n"); + } + return json; +} + +// Room and yard as the decompilation writes them, their walls and the +// door at elevation 0, plan the same as with no elevation grid, which +// frlg_maps.py leaves out when every tile the player can stand on is ground. +UnitTestResult test_ground_only_elevation_left_out(){ + const std::vector written{ + parse_map(with_elevation(TEST_ROOM_JSON, R"(["00000", "03330", "03330", "00300"])"), "Room"), + parse_map(with_elevation(TEST_YARD_JSON, R"(["00000", "00000", "03330", "00000"])"), "Yard"), + }; + const std::vector left_out{ + parse_map(with_elevation(TEST_ROOM_JSON, ""), "Room"), + parse_map(with_elevation(TEST_YARD_JSON, ""), "Yard"), + }; + for (const MapPosition& start : {MapPosition{"Room", {1, 1}}, MapPosition{"Room", {3, 2}}}){ + for (const MapPosition& goal : {MapPosition{"Yard", {1, 2}}, MapPosition{"Yard", {3, 2}}, MapPosition{"Room", {2, 2}}}){ + const std::optional> a = plan_overworld_route(written, start, {goal, std::nullopt}); + const std::optional> b = plan_overworld_route(left_out, start, {goal, std::nullopt}); + if (!a || !b || describe(*a) != describe(*b)){ + return "Plans differ from " + to_string(start) + " to " + to_string(goal) + ":" + + (a ? describe(*a) : " none") + "\nwithout elevation:" + (b ? describe(*b) : " none"); + } + } + } + return true; +} + +} + +void add_tests_OverworldRoute(UnitTestDatabase& database){ + database.add("route through a warp", test_route_through_warp); + database.add("ground-only elevation left out", test_ground_only_elevation_left_out); + database.add("maps to Brock", test_story_maps); + database.add("bedroom to Oak's Lab", test_bedroom_to_oaks_lab); + database.add("Viridian Mart to Pewter Gym", test_viridian_mart_to_pewter_gym); + database.add("wild steps", test_wild_steps); + database.add("no hold into a sign", test_no_hold_into_sign); + database.add("no hold into a ledge", test_no_hold_into_ledge); + database.add("step rules", test_step_rules); + database.add("maps", test_maps); + database.add("Cerulean Cave entrance to Mewtwo", test_entrance_to_mewtwo); + database.add("Cerulean Pokemon Center to Mewtwo", test_pokemon_center_to_mewtwo); + database.add("cave guard blocks the way", test_cave_guard_blocks); + database.add("Mewtwo's tile is blocked", test_mewtwo_tile_unreachable); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h new file mode 100644 index 0000000000..ce5d6f872b --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h @@ -0,0 +1,151 @@ +/* Overworld Route + * + * From: https://github.com/PokemonAutomation/ + * + * Plans a route over one or more FRLG maps joined by warps: the D-pad legs + * to walk, where to start surfing, and which way to face at the end. FRLG + * moves exactly one tile per step, so a planned route can be walked blind. + * Legs end against walls where that costs little: such a leg can be held + * for longer than it takes, and walked again if something interrupts it. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldRoute_H +#define PokemonAutomation_PokemonFRLG_OverworldRoute_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_OverworldMap.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +struct MapPosition{ + std::string map; + TilePos point; + + bool operator==(const MapPosition& other) const = default; +}; +std::string to_string(const MapPosition& position); + + +enum class RouteAction{ + WALK, // hold `direction` for `tiles` tiles + SURF, // face `direction`, use Surf, and land on the water there + FACE, // turn to `direction` without moving +}; + +struct RouteStep{ + RouteAction action = RouteAction::WALK; + Direction direction = Direction::NORTH; + int tiles = 0; + // WALK: the last tile is a warp (ladder, stairs), so the screen fades + // and the player arrives on another map. + bool warps = false; + // WALK: on the water, where the player moves twice as fast. + bool surfing = false; + // WALK: a wall stops the player at the end, so the leg can be held for + // longer than it takes and still ends on its tile. + bool to_wall = false; + // WALK, SURF: a wild Pokemon can appear on the way: the step crosses + // tall grass or water. Elsewhere (indoors, streets) no wild battle can + // start, so the walker doesn't watch for one. + bool wild = false; + // Which way the player faces after the step. Arriving at a door or a + // cave mouth, the game walks the player a tile out, facing south. + Direction facing_after = Direction::NORTH; + // Where the player is after the step. + MapPosition end; +}; +std::string to_string(const RouteStep& step); + + +struct RouteGoal{ + MapPosition position; + // Which way to face on arrival, e.g. towards a Pokemon to talk to. + std::optional facing; +}; + +// What the planner weighs a route by. Each is a cost per occurrence. +enum class RouteCost{ + TILE, + TURN, // extra for a leg in a new direction + WARP, // the fade in and out + SURF, // the dialog and the animation + GRASS_TILE, // extra for tall grass, where wild Pokemon appear + // Extra for a leg that ends where the player could keep walking: it has + // to be timed, and if a message or a battle stops it part-way, where + // the player is can only be estimated. A leg that ends at a wall is + // walked again instead. + OPEN_STOP, + // Extra again when that leg crosses tall grass or water, where a wild + // battle is likely to stop it: the walker can't tell where it did + // (console B, 2026-11-01, Route 1, four runs). + OPEN_WILD_STOP, +}; +using RouteCosts = std::map; + +// TILE 1, TURN 2, WARP 30, SURF 40, GRASS_TILE 20, OPEN_STOP 8, +// OPEN_WILD_STOP 300. +const RouteCosts& default_route_costs(); + +// `costs`'s cost for `kind`, or the default if it has none. +int route_cost(const RouteCosts& costs, RouteCost kind); + +// The cheapest route from `start`, surfing if it is on water, to +// `goal`, or nothing if there is none. `maps` must hold every map the route +// may pass through; warps to other maps are not taken. Planned with +// Pokemon::plan_legs() on the game's step rules. +std::optional> plan_overworld_route( + const std::vector& maps, + const MapPosition& start, + const RouteGoal& goal, + const RouteCosts& costs = default_route_costs(), + std::optional start_facing = std::nullopt +); + +// Holding `direction` from `from`, on the water if `surfing`: where a wall +// stops the player, how many tiles on, and whether any tile on the way is +// tall grass or water. +struct WallHold{ + MapPosition end; + int tiles = 0; + bool wild = false; +}; +// Nothing unless every step on the way is a plain walk: a warp, Surf, a +// ledge, a person, a sign that would speak, or the edge of the loaded maps +// comes first. +std::optional hold_to_wall( + const std::vector& maps, + const MapPosition& from, bool surfing, Direction direction +); + +// The tiles a WALK `step` from `start` passes through, `start` first, short +// of a warp at its end. +std::vector leg_tiles( + const std::vector& maps, + const MapPosition& start, const RouteStep& step +); + +// Replays `route` from `start` with the game's step rules and returns where +// it ends. Throws InternalProgramError if a step can't be taken as planned. +MapPosition follow_overworld_route( + const std::vector& maps, + const MapPosition& start, + const std::vector& route +); + + +void add_tests_OverworldRoute(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp new file mode 100644 index 0000000000..348b57bcf6 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp @@ -0,0 +1,445 @@ +/* Overworld Walk + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" +#include "PokemonFRLG_PlayerFacingReader.h" +#include "PokemonFRLG_OverworldWalk.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace std::chrono_literals; +using namespace OverworldWalkSteps; + + +namespace{ + +constexpr Milliseconds FACE_SETTLE = 300ms; // the turn animation, before A reaches what is ahead +// From the end of the hold, through the fade out and in. +constexpr Milliseconds WARP_TIMEOUT = 8000ms; +constexpr Milliseconds SURF_PROMPT_TIMEOUT = 5000ms; +constexpr Milliseconds SURF_ANIMATION = 3000ms; +// After a message closes: a trainer who saw the player speaks first, then +// the battle starts, with " would like to battle!" seconds later. +constexpr Milliseconds TRAINER_BATTLE_WATCH = 6000ms; + + +// A wild battle, seen by the flashes it starts with. +class WildBattleInterrupt : public OverworldInterrupt{ +public: + virtual std::string name() const override{ + return "a wild battle"; + } + virtual std::unique_ptr make_watcher() const override{ + return std::make_unique(COLOR_RED); + } + // The first flash shows about 130ms after the step on the console, and + // the watcher needs it to start fading back. Not calibrated yet. + virtual Milliseconds detection_delay() const override{ + return 300ms; + } + virtual void clear(ConsoleHandle& console, ProControllerContext& context) const override{ + flee_battle(console, context); + } +}; + +// A wild battle whose flashes were missed, seen once "Wild +// appeared!" shows. Where an open leg stopped is then only a rough guess. +class LateWildBattleInterrupt : public WildBattleInterrupt{ +public: + virtual std::string name() const override{ + return "a wild battle (seen late)"; + } + virtual std::unique_ptr make_watcher() const override{ + return std::make_unique(COLOR_RED); + } + // The flashes, the wipe and the opening animation: 3.7s after the step's + // press, twice on Route 1 (console B, 2026-11-01). Other maps open + // battles with other wipes, so elsewhere this is a guess. + virtual Milliseconds detection_delay() const override{ + return 3700ms; + } +}; + +class MessageInterrupt : public OverworldInterrupt{ +public: + virtual std::string name() const override{ + return "a message"; + } + virtual std::unique_ptr make_watcher() const override{ + return std::make_unique(COLOR_RED); + } + // The box shows as the step ends; then video lag and the watcher's + // 250ms. Not calibrated yet. + virtual Milliseconds detection_delay() const override{ + return 400ms; + } + virtual void clear(ConsoleHandle& console, ProControllerContext& context) const override{ + WhiteDialogOverWatcher closed(COLOR_RED); + context.wait_for_all_requests(); + const int ret = run_until( + console, context, + [](ProControllerContext& context){ + for (int c = 0; c < 5; c++){ + pbf_press_button(context, BUTTON_B, 160ms, 840ms); + } + }, + {closed} + ); + if (ret < 0){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "walk_overworld_route(): a message on the overworld didn't close.", + console + ); + } + check_no_trainer_battle(console, context); + } + +private: + // A trainer's battle can't be fled, and the walker must not try (console + // B, 2026-11-01, Viridian Forest): it stops here for the caller. + static void check_no_trainer_battle(ConsoleHandle& console, ProControllerContext& context){ + BattleScreenWatcher battle(COLOR_RED); + context.wait_for_all_requests(); + if (wait_until(console, context, TRAINER_BATTLE_WATCH, {battle}) >= 0){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::NO_ERROR_REPORT, + "walk_overworld_route(): trainer battle: a battle started after a message on the overworld.", + console + ); + } + } +}; + +// A message, taken to be "REPEL's effect wore off...", after which another +// Max Repel is used from the Items pocket. +class RepelWoreOffInterrupt : public MessageInterrupt{ +public: + explicit RepelWoreOffInterrupt(int max_repel_slot) + : m_max_repel_slot(max_repel_slot) + {} + virtual std::string name() const override{ + return "a message (Repel wore off?)"; + } + virtual void clear(ConsoleHandle& console, ProControllerContext& context) const override{ + MessageInterrupt::clear(console, context); + use_max_repel_from_bag(console, context, m_max_repel_slot); + } + +private: + int m_max_repel_slot; +}; + + +Pokemon::LegSpec leg_spec(const RouteStep& step, MoveSpeed speed){ + return Pokemon::LegSpec{step.direction, step.tiles, step.to_wall, tile_time(step, speed)}; +} + +} + + +namespace OverworldWalkSteps{ + +DpadPosition dpad(Direction direction){ + switch (direction){ + case Direction::NORTH: + return DPAD_UP; + case Direction::EAST: + return DPAD_RIGHT; + case Direction::SOUTH: + return DPAD_DOWN; + case Direction::WEST: + return DPAD_LEFT; + } + return DPAD_NONE; +} + +void hold_dpad(ProControllerContext& context, Direction direction, Milliseconds duration){ + pbf_press_dpad(context, dpad(direction), duration, STEP_RELEASE); +} + +void hold_dpad_running(ProControllerContext& context, Direction direction, Milliseconds duration){ + pbf_controller_state(context, BUTTON_B, dpad(direction), {0, 0}, {0, 0}, duration); + pbf_wait(context, STEP_RELEASE); +} + +Milliseconds tile_time(const RouteStep& step, MoveSpeed speed){ + if (step.surfing){ + return SURF_TILE_TIME; + } + return speed == MoveSpeed::RUN ? RUN_TILE_TIME : TILE_TIME; +} + +Pokemon::LegMover leg_mover(const RouteStep& step, MoveSpeed speed){ + if (speed == MoveSpeed::RUN && !step.surfing){ + return hold_dpad_running; + } + return hold_dpad; +} + +Milliseconds leg_hold_time(const RouteStep& step, MoveSpeed speed){ + return Pokemon::leg_hold(leg_spec(step, speed), step.tiles); +} + +std::string speed_note(const RouteStep& step, MoveSpeed speed){ + if (step.action != RouteAction::WALK || !step.to_wall || step.surfing){ + return ""; + } + return std::format( + "[Speed] {} {}: {} tiles in {} ms, held {} ms", + move_speed_name(speed), Pokemon::direction_name(step.direction), step.tiles, + (tile_time(step, speed) * step.tiles).count(), leg_hold_time(step, speed).count() + ); +} + +// One watcher for the whole fade: a ladder's black is short enough to be +// over before a second watcher, started once the fade is seen, looks. +void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step){ + BlackScreenOverWatcher arrival(COLOR_RED); + context.wait_for_all_requests(); + if (wait_until(console, context, WARP_TIMEOUT, {arrival}) < 0){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "walk_overworld_route(): no fade in and out after walking onto the warp to " + step.end.map + ".", + console + ); + } +} + +// Fails unless the overworld is up. Under the START menu or a message the +// D-pad only moves a cursor, and legs to a wall seem to go fine: three +// "walked" that way in Viridian Forest without the player moving (console B, +// 2026-11-01). +void check_overworld(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + if (!screen){ + return; + } + const char* open = nullptr; + if (StartMenuDetector(COLOR_RED).detect(screen)){ + open = "the START menu"; + }else if (SelectionDialogDetector(COLOR_RED).detect(screen)){ + open = "a menu"; + }else if (WhiteDialogDetector(COLOR_RED).detect(screen)){ + open = "a message"; + } + if (open != nullptr){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::string("walk_overworld_route(): ") + open + " is open, before: " + to_string(step), + console + ); + } +} + +void clear_open_message( + ConsoleHandle& console, ProControllerContext& context, + const OverworldInterrupts& interrupts, const RouteStep& step +){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + if (!screen || !WhiteDialogDetector(COLOR_RED).detect(screen)){ + return; + } + console.log("Route: a message is open before " + to_string(step) + "; handing it to the leg's interrupts.", COLOR_ORANGE); + Pokemon::clear_late_interrupts(console, context, interrupts, OPEN_MESSAGE_WATCH, 1); +} + +// After a warp's fade: fails, once the battle is fled, if it was a wild +// battle's. In run 7 (console B, 2026-11-01) the player had drifted onto +// Route 1's grass, and the step meant for Oak's Lab's door set off a +// battle; its flashes and wipe passed for the warp's fade, the route went +// on as if inside, and the next screen was the battle's FIGHT menu. +void check_warp_was_no_battle(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step){ + BattleScreenWatcher battle(COLOR_RED); + context.wait_for_all_requests(); + if (wait_until(console, context, AFTER_WARP_BATTLE_WATCH, {battle}) < 0){ + return; + } + flee_battle(console, context); + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "walk_overworld_route(): a wild battle, not the warp to " + step.end.map + ": the player is off the route.", + console + ); +} + +// Each leg starts with a turn tap unless it goes the way the player faces. +// A tap while already facing that way takes a step, so a facing not given +// is read from the screen. If that fails too it taps anyway. +std::optional read_facing(ConsoleHandle& console, ProControllerContext& context){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + std::optional facing; + if (screen){ + facing = read_player_facing(screen); + } + console.log(std::string("Route: the player faces ") + (facing ? Pokemon::direction_name(*facing) : "an unknown way") + "."); + return facing; +} + +void start_surf(ConsoleHandle& console, ProControllerContext& context, Direction direction, bool facing_water){ + // "The water is a deep blue... Would you like to SURF?", with YES selected. + // An A pressed while the player is still turning is lost. + if (!facing_water){ + pbf_press_dpad(context, dpad(direction), FACE_HOLD, FACE_SETTLE); + } + pbf_press_button(context, BUTTON_A, 160ms, 0ms); + SelectionDialogWatcher prompt(COLOR_RED); + context.wait_for_all_requests(); + if (wait_until(console, context, SURF_PROMPT_TIMEOUT, {prompt}) < 0){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "walk_overworld_route(): no Surf prompt facing the water.", + console + ); + } + pbf_press_button(context, BUTTON_A, 160ms, 1000ms); + + // " used SURF!" waits for A, then the player jumps onto the water. + for (int c = 0; c < 5; c++){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + if (!screen || !WhiteDialogDetector(COLOR_RED).detect(screen)){ + break; + } + pbf_press_button(context, BUTTON_A, 160ms, 1000ms); + } + pbf_wait(context, SURF_ANIMATION); +} + +} + + + +const char* move_speed_name(MoveSpeed speed){ + switch (speed){ + case MoveSpeed::WALK: + return "walk"; + case MoveSpeed::RUN: + return "run"; + } + return "?"; +} + +OverworldInterruptSet overworld_interrupts_with_repel(int max_repel_slot){ + OverworldInterruptSet ret; + ret.wild.emplace_back(std::make_unique()); + ret.wild.emplace_back(std::make_unique()); + ret.wild.emplace_back(std::make_unique(max_repel_slot)); + ret.other.emplace_back(std::make_unique(max_repel_slot)); + return ret; +} + +void use_max_repel_from_bag(ConsoleHandle& console, ProControllerContext& context, int slot){ + console.log(std::format("Using a Max Repel (Items pocket, slot {}).", slot + 1)); + open_bag_from_overworld(console, context); + // The bag is seen while it still slides in, and ignores presses until + // it is done. + pbf_wait(context, 1000ms); + // To the Items pocket, then to the top of it. + for (int c = 0; c < 3; c++){ + pbf_press_dpad(context, DPAD_LEFT, 100ms, 600ms); + } + for (int c = 0; c < 20; c++){ + pbf_press_dpad(context, DPAD_UP, 100ms, 100ms); + } + for (int c = 0; c < slot; c++){ + pbf_press_dpad(context, DPAD_DOWN, 100ms, 300ms); + } + // USE, " used the MAX REPEL.", back to the bag, then out of the + // bag and the start menu. A third A here would open the item's menu again. + pbf_press_button(context, BUTTON_A, 160ms, 800ms); + pbf_press_button(context, BUTTON_A, 160ms, 1500ms); + pbf_press_button(context, BUTTON_A, 160ms, 1500ms); + pbf_press_button(context, BUTTON_B, 160ms, 2000ms); + pbf_press_button(context, BUTTON_B, 160ms, 1000ms); + context.wait_for_all_requests(); +} + +const OverworldInterruptSet& default_overworld_interrupts(){ + // Battles first: their screens are checked before the message box's. + static const OverworldInterruptSet interrupts = []{ + OverworldInterruptSet ret; + ret.wild.emplace_back(std::make_unique()); + ret.wild.emplace_back(std::make_unique()); + ret.wild.emplace_back(std::make_unique()); + ret.other.emplace_back(std::make_unique()); + return ret; + }(); + return interrupts; +} + + +void walk_overworld_route( + ConsoleHandle& console, ProControllerContext& context, + const std::vector& route, + std::optional facing, + const OverworldInterruptSet& interrupts, + MoveSpeed speed +){ + if (!facing){ + facing = read_facing(console, context); + } + for (const RouteStep& step : route){ + console.log("Route: " + to_string(step)); + clear_open_message(console, context, step.wild ? interrupts.wild : interrupts.other, step); + check_overworld(console, context, step); + switch (step.action){ + case RouteAction::WALK: + // Turning first, with a tap, makes the hold start from a standstill + // facing the right way: holding through a turn lost a tile on the + // console, while holds from a standstill were exact over 15 tiles. + if (facing != step.direction){ + pbf_press_dpad(context, dpad(step.direction), TURN_TAP, TURN_SETTLE); + } + if (const std::string note = speed_note(step, speed); !note.empty()){ + console.log(note); + } + Pokemon::walk_leg(console, context, leg_mover(step, speed), step.wild ? interrupts.wild : interrupts.other, leg_spec(step, speed), MAX_INTERRUPTIONS_PER_LEG); + if (step.warps){ + wait_out_warp(console, context, step); + static_assert(AFTER_WARP_BATTLE_WATCH >= AFTER_WARP); + check_warp_was_no_battle(console, context, step); + } + break; + case RouteAction::SURF: + start_surf(console, context, step.direction, facing == step.direction); + break; + case RouteAction::FACE: + pbf_press_dpad(context, dpad(step.direction), FACE_HOLD, STEP_RELEASE); + break; + } + if (step.action != RouteAction::FACE){ + Pokemon::clear_late_interrupts( + console, context, step.wild ? interrupts.wild : interrupts.other, + step.wild ? AFTER_WILD_LEG_WATCH : AFTER_LEG_WATCH, MAX_INTERRUPTIONS_PER_LEG + ); + } + facing = step.facing_after; + } + context.wait_for_all_requests(); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h new file mode 100644 index 0000000000..2c3b665033 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h @@ -0,0 +1,183 @@ +/* Overworld Walk + * + * From: https://github.com/PokemonAutomation/ + * + * Walks a planned overworld route with the D-pad. FRLG moves one tile per + * 16 frames and finishes a step once it starts, so a leg is one hold timed + * to land mid-way between the last tile and one more. Warps are waited out + * by their fade; Surf goes through its dialog. + * + * A message or a wild battle can stop the player part-way through a leg. + * Each kind is an OverworldInterrupt: the walker watches for all of them + * while it holds the D-pad, and when one shows it stops, has it cleared and + * walks the rest of the leg. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldWalk_H +#define PokemonAutomation_PokemonFRLG_OverworldWalk_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/Navigation/Pokemon_LegWalker.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "PokemonFRLG_OverworldRoute.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Something that stops the player part-way through a leg: a wild battle, a +// message. See Pokemon::LegInterrupt. +using OverworldInterrupt = Pokemon::LegInterrupt; +using OverworldInterrupts = Pokemon::LegInterrupts; + +// What to watch for on a route's steps: `wild` on steps where a wild +// Pokemon can appear (RouteStep::wild), `other` on the rest. Watching for a +// battle where none can start only risks a false one: walking to the edge +// of a small room, the screen darkens like a battle's flash (console B, +// 2026-11-01, the bedroom's east wall). +struct OverworldInterruptSet{ + OverworldInterrupts wild; + OverworldInterrupts other; +}; + +// A wild battle, run from, and a message (e.g. "REPEL's effect wore off..."), +// closed with B. See OverworldInterruptSet. +const OverworldInterruptSet& default_overworld_interrupts(); + +// The same, except that after a message another Max Repel is used, from +// slot `max_repel_slot` (from 0) of the Items pocket. Any message on the +// overworld is taken to be the one saying the last Repel wore off. +OverworldInterruptSet overworld_interrupts_with_repel(int max_repel_slot); + +// From the overworld, uses the Max Repel in `slot` (from 0) of the Items +// pocket and returns to the overworld. +void use_max_repel_from_bag(ConsoleHandle& console, ProControllerContext& context, int slot); + + +// How the player moves on foot: walking, or running with B held, which +// needs the Running Shoes (FLAG_SYS_B_DASH, from Oak's aide in Pewter City +// after Brock). On the water the player surfs at its own pace either way. +enum class MoveSpeed{ + WALK, + RUN, +}; +const char* move_speed_name(MoveSpeed speed); + + +// Walks `route` from where it was planned, at `speed`. The player must be +// standing still on the overworld and not on the bike. `facing` is the way +// the player faces at the start; if not given, it is read from the screen. +// Throws OperationFailedException if a warp's fade or the Surf prompt +// doesn't show, or a leg is interrupted too many times. +void walk_overworld_route( + ConsoleHandle& console, ProControllerContext& context, + const std::vector& route, + std::optional facing = std::nullopt, + const OverworldInterruptSet& interrupts = default_overworld_interrupts(), + MoveSpeed speed = MoveSpeed::WALK +); + + +// The pieces walk_overworld_route() is made of, for a walker that runs a +// route its own way. Each throws OperationFailedException as +// walk_overworld_route() describes. +namespace OverworldWalkSteps{ + +inline constexpr Milliseconds TILE_TIME(267); // 16 frames at 60 fps, measured exact over 15 tiles +inline constexpr Milliseconds SURF_TILE_TIME(133); // the game moves a surfing player at running speed +// 8 frames: running is 2 pixels a frame, twice walking. Not measured on the +// console yet; the walker logs each leg to a wall (speed_note()) for that. +inline constexpr Milliseconds RUN_TILE_TIME(133); +inline constexpr Milliseconds TURN_TAP(40); // turns a player facing another way, without a step +inline constexpr Milliseconds TURN_SETTLE(300); +inline constexpr Milliseconds FACE_HOLD(40); // short enough to turn without stepping +inline constexpr Milliseconds STEP_RELEASE(100); +// After a warp's fade: leaving by a door the game walks the player a tile out +// on its own, and a leg started before that ends loses tiles (on the console a +// 600ms wait cost 2 tiles). +inline constexpr Milliseconds AFTER_WARP(1500); +// After a warp's fade, which a wild battle's flashes and wipe can pass for: +// a battle's HP box shows within this long (console B, 2026-11-01). +inline constexpr Milliseconds AFTER_WARP_BATTLE_WATCH(5000); +// A message set off by a leg's last step shows after the hold ends. Caught +// here, before the next leg's turn tap, which the message would swallow. +inline constexpr Milliseconds AFTER_LEG_WATCH(500); +// The same after a leg through grass. A battle whose flashes are missed is +// seen only by its "Wild appeared!", 3.7s after its step's press +// (twice on Route 1, console B, 2026-11-01, run 7). Unless the walker waits +// that long, the next leg is walked into the battle and lost: there, "east +// 4" and "west 4". +inline constexpr Milliseconds AFTER_WILD_LEG_WATCH(3500); +// How long clear_open_message() watches for the message it saw. +inline constexpr Milliseconds OPEN_MESSAGE_WATCH(1000); +inline constexpr size_t MAX_INTERRUPTIONS_PER_LEG = 5; + +DpadPosition dpad(Direction direction); + +// The leg mover: holds the D-pad. FRLG moves exactly a tile per 16 frames. +void hold_dpad(ProControllerContext& context, Direction direction, Milliseconds duration); + +// The leg mover for running: holds the D-pad with B for the whole hold. +// Turn taps go without B: a tap only turns the player. +void hold_dpad_running(ProControllerContext& context, Direction direction, Milliseconds duration); + +// How long one tile of `step` takes at `speed`: on the water, the Surf +// pace whatever the speed. +Milliseconds tile_time(const RouteStep& step, MoveSpeed speed); + +// The mover for `step` at `speed`: hold_dpad_running() for a run on foot, +// hold_dpad() otherwise (B does nothing on the water). +Pokemon::LegMover leg_mover(const RouteStep& step, MoveSpeed speed); + +// How long the walker holds the D-pad for a WALK `step` at `speed` +// (Pokemon::leg_hold()). +Milliseconds leg_hold_time(const RouteStep& step, MoveSpeed speed); + +// For a leg to a wall on foot, the line the walker logs so a console run +// can check the pace: "[Speed] run west: 40 tiles in 5320 ms, held 5586 ms", +// the tiles at the assumed pace and the hold. Empty for other steps. +std::string speed_note(const RouteStep& step, MoveSpeed speed); + +// After a hold onto `step`'s warp: waits out its fade. +void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step); + +// Before `step`: fails unless the overworld is up. +void check_overworld(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step); + +// Before `step`: if a message is open (a trainer who saw the player on the +// last leg and spoke after its watch), hands what shows to `interrupts`, +// once, instead of failing at once. check_overworld() then fails if the +// overworld still isn't up. +void clear_open_message( + ConsoleHandle& console, ProControllerContext& context, + const OverworldInterrupts& interrupts, const RouteStep& step +); + +// After `step`'s warp: fails, once the battle is fled, if its fade was a +// wild battle's. +void check_warp_was_no_battle(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step); + +// The way the player faces, read from the screen; nothing if it can't be read. +std::optional read_facing(ConsoleHandle& console, ProControllerContext& context); + +// Facing `direction` (turning first unless `facing_water`), starts Surf. +void start_surf(ConsoleHandle& console, ProControllerContext& context, Direction direction, bool facing_water); + +} + + +void add_tests_OverworldWalk(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp new file mode 100644 index 0000000000..8265cb6bd2 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp @@ -0,0 +1,101 @@ +/* Overworld Walk Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_OverworldWalk.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace OverworldWalkSteps; + + +namespace{ + +class Test_OverworldWalk : public UnitTest{ +public: + Test_OverworldWalk(std::string name, std::function body) + : UnitTest("PokemonFRLG::OverworldWalk - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + return m_body(); + } + +private: + std::function m_body; +}; + + +struct HoldCase{ + std::string name; + MoveSpeed speed; + int tiles; + bool to_wall; + bool surfing; + // How long the D-pad is held. + Milliseconds hold; + // speed_note()'s line, or empty. + std::string note; +}; + +// An open leg lets go half a tile before its last step would end; a leg +// to a wall is held two tiles longer. Walking is 267ms a tile, running and +// surfing 133ms. +const std::vector& hold_cases(){ + static const std::vector cases{ + {.name = "walk, open", .speed = MoveSpeed::WALK, .tiles = 5, .to_wall = false, .surfing = false, + .hold = Milliseconds(4 * 267 + 133), .note = ""}, + {.name = "walk, to a wall", .speed = MoveSpeed::WALK, .tiles = 5, .to_wall = true, .surfing = false, + .hold = Milliseconds(7 * 267), .note = "[Speed] walk west: 5 tiles in 1335 ms, held 1869 ms"}, + {.name = "run, open", .speed = MoveSpeed::RUN, .tiles = 5, .to_wall = false, .surfing = false, + .hold = Milliseconds(4 * 133 + 66), .note = ""}, + {.name = "run, to a wall", .speed = MoveSpeed::RUN, .tiles = 40, .to_wall = true, .surfing = false, + .hold = Milliseconds(42 * 133), .note = "[Speed] run west: 40 tiles in 5320 ms, held 5586 ms"}, + {.name = "run, surfing to a wall", .speed = MoveSpeed::RUN, .tiles = 3, .to_wall = true, .surfing = true, + .hold = Milliseconds(5 * 133), .note = ""}, + {.name = "walk, surfing", .speed = MoveSpeed::WALK, .tiles = 3, .to_wall = false, .surfing = true, + .hold = Milliseconds(2 * 133 + 66), .note = ""}, + }; + return cases; +} + +UnitTestResult check_hold(const HoldCase& test){ + RouteStep step; + step.direction = Direction::WEST; + step.tiles = test.tiles; + step.to_wall = test.to_wall; + step.surfing = test.surfing; + const Milliseconds hold = leg_hold_time(step, test.speed); + if (hold != test.hold){ + return std::format("Expected a hold of {}ms, got {}ms.", test.hold.count(), hold.count()); + } + const std::string note = speed_note(step, test.speed); + if (note != test.note){ + return "Expected the note \"" + test.note + "\", got \"" + note + "\"."; + } + return true; +} + +} + + +void add_tests_OverworldWalk(UnitTestDatabase& database){ + for (const HoldCase& test : hold_cases()){ + database.add("hold: " + test.name, [&test]{ return check_hold(test); }); + } +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp new file mode 100644 index 0000000000..f747f401b1 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp @@ -0,0 +1,263 @@ +/* Player Facing Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Color.h" +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "Tests/TestUtils.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_PlayerFacingReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// The sprite sheet's frames are 16x32, and the standing ones are 0 (south), +// 1 (north) and 2 (west). Rows 12 to 30 are drawn; the rest is empty. +const char PLAYER_SPRITE_SHEET[] = "PokemonFRLG/PlayerSprites/red_normal.png"; +constexpr int SHEET_FRAME_WIDTH = 16; +constexpr int SHEET_FIRST_ROW = 12; + +constexpr int SPRITE_WIDTH = 16; +constexpr int SPRITE_ROWS = 19; +// Where the sprite's first drawn row sits on the GBA's 240x160 screen while +// the camera follows the player. Measured on the console. +constexpr int SPRITE_X = 112; +constexpr int SPRITE_Y = 56 + 12; +constexpr int GBA_WIDTH = 240; +constexpr int GBA_HEIGHT = 160; + +// Average difference per channel over the sprite's pixels. On the console a +// match scored about 12 and the next best sprite over 50. +constexpr double MATCH_MAX = 25; +constexpr double MATCH_MARGIN = 2.0; + + +ImageRGB32 sheet_frame(const ImageViewRGB32& sheet, int frame){ + return sheet.sub_image(frame * SHEET_FRAME_WIDTH, SHEET_FIRST_ROW, SPRITE_WIDTH, SPRITE_ROWS).copy(); +} + +// How far the screen differs from `sprite`, drawn `dy` GBA pixels lower. +double difference(const ImageViewRGB32& game, const ImageViewRGB32& sprite, bool mirror, int dy){ + const double scale_x = (double)game.width() / GBA_WIDTH; + const double scale_y = (double)game.height() / GBA_HEIGHT; + long total = 0; + int pixels = 0; + for (int row = 0; row < SPRITE_ROWS; row++){ + for (int col = 0; col < SPRITE_WIDTH; col++){ + const Color expected(sprite.pixel(mirror ? SPRITE_WIDTH - 1 - col : col, row)); + if (expected.alpha() == 0){ + continue; + } + const size_t x = (size_t)((SPRITE_X + col + 0.5) * scale_x); + const size_t y = (size_t)((SPRITE_Y + dy + row + 0.5) * scale_y); + if (x >= game.width() || y >= game.height()){ + return std::numeric_limits::max(); + } + const Color pixel(game.pixel(x, y)); + total += std::abs((int)pixel.red() - expected.red()); + total += std::abs((int)pixel.green() - expected.green()); + total += std::abs((int)pixel.blue() - expected.blue()); + pixels++; + } + } + return pixels == 0 ? std::numeric_limits::max() : (double)total / (3 * pixels); +} + +} + + +const PlayerSprites& player_sprites(){ + static const PlayerSprites SPRITES = []{ + const ImageRGB32 sheet(RESOURCE_PATH() + PLAYER_SPRITE_SHEET); + return PlayerSprites{sheet_frame(sheet, 0), sheet_frame(sheet, 1), sheet_frame(sheet, 2)}; + }(); + return SPRITES; +} + + +std::optional read_player_facing(const ImageViewRGB32& screen){ + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + return match_player_facing(game, player_sprites()); +} + +std::optional match_player_facing(const ImageViewRGB32& game, const PlayerSprites& sprites){ + struct Candidate{ + Direction direction; + const ImageViewRGB32& sprite; + bool mirror; + }; + const Candidate candidates[] = { + {Direction::SOUTH, sprites.south, false}, + {Direction::NORTH, sprites.north, false}, + {Direction::WEST, sprites.west, false}, + {Direction::EAST, sprites.west, true}, + }; + + double best = std::numeric_limits::max(); + double second = best; + Direction facing = Direction::SOUTH; + for (const Candidate& candidate : candidates){ + // A pixel either way, for a box that is slightly off. + double score = std::numeric_limits::max(); + for (int dy = -1; dy <= 1; dy++){ + score = std::min(score, difference(game, candidate.sprite, candidate.mirror, dy)); + } + if (score < best){ + second = best; + best = score; + facing = candidate.direction; + }else{ + second = std::min(second, score); + } + } + if (best > MATCH_MAX || second < best * MATCH_MARGIN){ + return std::nullopt; + } + return facing; +} + + + +namespace{ + +class Test_PlayerFacingReader : public UnitTest{ +public: + // The image's name ends with the way the player faces, or "None" where + // no standing player shows: _. + Test_PlayerFacingReader(const std::string& image) + : UnitTest("PokemonFRLG::PlayerFacingReader - " + image) + , m_image(UNIT_TEST_RESOURCE_PATH() + image) + {} + + virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{ + const std::vector words = parse_words(Filesystem::Path(m_image).stem().string()); + if (words.size() < 2){ + return "Error: filename must be _."; + } + std::string expected = words.back(); + std::transform(expected.begin(), expected.end(), expected.begin(), [](unsigned char c){ return (char)std::tolower(c); }); + + std::optional facing; + try{ + facing = read_player_facing(ImageRGB32(m_image)); + }catch (FileException& e){ + // The screenshots and the sprite sheet aren't in CI's resources yet. + return UnitTestResult(UnitTestResult::SKIPPED, "File not found: " + e.message()); + } + const std::string read = facing ? direction_name(*facing) : "none"; + if (read == expected){ + return true; + } + return "Expected " + expected + ", read " + read; + } + +private: + std::string m_image; +}; + +// Made-up sprites, so the matching is tested without the sprite sheet: +// solid red facing south, solid blue facing north, and green on the left +// half facing west. +PlayerSprites fixture_sprites(){ + PlayerSprites sprites{ + ImageRGB32(SPRITE_WIDTH, SPRITE_ROWS), + ImageRGB32(SPRITE_WIDTH, SPRITE_ROWS), + ImageRGB32(SPRITE_WIDTH, SPRITE_ROWS), + }; + sprites.south.fill(0xffff0000); + sprites.north.fill(0xff0000ff); + sprites.west.fill(0x00000000); + for (int row = 0; row < SPRITE_ROWS; row++){ + for (int col = 0; col < SPRITE_WIDTH / 2; col++){ + sprites.west.pixel(col, row) = 0xff00ff00; + } + } + return sprites; +} + +// A grey GBA screen at twice its size, with `sprite` drawn where the +// player stands. +ImageRGB32 fixture_screen(const ImageViewRGB32* sprite, bool mirror){ + ImageRGB32 game(2 * GBA_WIDTH, 2 * GBA_HEIGHT); + game.fill(0xff808080); + for (int row = 0; sprite != nullptr && row < SPRITE_ROWS; row++){ + for (int col = 0; col < SPRITE_WIDTH; col++){ + const uint32_t pixel = sprite->pixel(mirror ? SPRITE_WIDTH - 1 - col : col, row); + if (Color(pixel).alpha() == 0){ + continue; + } + for (int dy = 0; dy < 2; dy++){ + for (int dx = 0; dx < 2; dx++){ + game.pixel(2 * (SPRITE_X + col) + dx, 2 * (SPRITE_Y + row) + dy) = pixel; + } + } + } + } + return game; +} + +class Test_PlayerFacingFixture : public UnitTest{ +public: + Test_PlayerFacingFixture() + : UnitTest("PokemonFRLG::PlayerFacingReader - made-up sprites") + {} + + virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{ + const PlayerSprites sprites = fixture_sprites(); + struct Case{ + const ImageViewRGB32* sprite; + bool mirror; + std::optional expected; + }; + const Case cases[] = { + {&sprites.south, false, Direction::SOUTH}, + {&sprites.north, false, Direction::NORTH}, + {&sprites.west, false, Direction::WEST}, + {&sprites.west, true, Direction::EAST}, + {nullptr, false, std::nullopt}, + }; + for (const Case& test : cases){ + const std::optional facing = match_player_facing(fixture_screen(test.sprite, test.mirror), sprites); + if (facing != test.expected){ + return std::string("Read ") + (facing ? direction_name(*facing) : "nothing") + + " instead of " + (test.expected ? direction_name(*test.expected) : "nothing"); + } + } + return true; + } +}; + +} + +void add_tests_PlayerFacingReader(UnitTestDatabase& database){ + database.add(); + // LeafGreen on the Switch, captured with a 1080p card. + database.add("PokemonFRLG/PlayerFacingReader/Route24_South.png"); + database.add("PokemonFRLG/PlayerFacingReader/Route24_North.png"); + database.add("PokemonFRLG/PlayerFacingReader/CeruleanCave_South.png"); + database.add("PokemonFRLG/PlayerFacingReader/CeruleanCave_North.png"); + database.add("PokemonFRLG/PlayerFacingReader/Surfing_None.png"); + database.add("PokemonFRLG/PlayerFacingReader/Bag_None.png"); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h new file mode 100644 index 0000000000..fb682fde18 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h @@ -0,0 +1,58 @@ +/* Player Facing Reader + * + * From: https://github.com/PokemonAutomation/ + * + * Which way the player faces, read from the overworld. The camera keeps the + * player on the same spot of the screen, so the reader compares that spot + * with the player's standing sprites from pret/pokefirered, on the sprite's + * own pixels only, so the ground behind doesn't matter. The sprites come + * from Packages: Resources/PokemonFRLG/PlayerSprites/red_normal.png is the + * decompilation's graphics/object_events/pics/people/red_normal.png. + * + * Only the walking player is known: surfing and biking use other sprites. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_PlayerFacingReader_H +#define PokemonAutomation_PokemonFRLG_PlayerFacingReader_H + +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "PokemonFRLG_OverworldMap.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The standing player's frames, as the game draws them, with transparent +// pixels at alpha 0. Facing east is facing west mirrored. +struct PlayerSprites{ + ImageRGB32 south; + ImageRGB32 north; + ImageRGB32 west; +}; + +// Loads the frames once. Throws FileException if the file is missing. +const PlayerSprites& player_sprites(); + + +// The way the standing player faces, or nothing if no standing sprite +// matches clearly (surfing, on the bike, in a menu, mid-step). +std::optional read_player_facing(const ImageViewRGB32& screen); + +// The same on `game`, the GBA's 240x160 screen at any scale, already cut +// out of the console's. +std::optional match_player_facing(const ImageViewRGB32& game, const PlayerSprites& sprites); + + +void add_tests_PlayerFacingReader(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp index 829a795624..1fa21bd655 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp @@ -18,6 +18,8 @@ #include "Programs/Farming/PokemonFRLG_PickupFarmer.h" #include "Programs/Farming/PokemonFRLG_EvTrainer.h" +#include "Programs/AutoStory/PokemonFRLG_AutoStory.h" + #include "Programs/ShinyHunting/PokemonFRLG_GiftReset.h" #include "Programs/ShinyHunting/PokemonFRLG_LegendaryReset.h" #include "Programs/ShinyHunting/PokemonFRLG_LegendaryRunAway.h" @@ -58,7 +60,6 @@ PanelListFactory::PanelListFactory() std::vector PanelListFactory::make_panels() const{ std::vector ret; - ret.emplace_back("---- Settings ----"); ret.emplace_back(make_OptionsPanel()); @@ -70,7 +71,8 @@ std::vector PanelListFactory::make_panels() const{ ret.emplace_back(make_SingleSwitchProgram()); ret.emplace_back(make_SingleSwitchProgram()); - //ret.emplace_back("---- General ----"); + ret.emplace_back("---- General ----"); + ret.emplace_back(make_SingleSwitchProgram()); ret.emplace_back("---- Shiny Hunting ----"); ret.emplace_back(make_SingleSwitchProgram()); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index d734e275f7..1973dbe3e4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -17,9 +17,13 @@ #include "Inference/Dialogs/PokemonFRLG_PrizeSelectDetector.h" #include "Inference/Map/PokemonFRLG_PokemonLeagueDetectors.h" #include "Inference/Menus/PokemonFRLG_BagDetector.h" +#include "Inference/Menus/PokemonFRLG_ItemListReader.h" +#include "Inference/Menus/PokemonFRLG_OptionMenuReader.h" #include "Inference/Menus/PokemonFRLG_PartyEmptySlotDetector.h" #include "Inference/Menus/PokemonFRLG_PartyHeldItemDetector.h" #include "Inference/Menus/PokemonFRLG_PartyMenuDetector.h" +#include "Inference/Menus/PokemonFRLG_SaveCardReader.h" +#include "Inference/Menus/PokemonFRLG_SummaryMovesReader.h" #include "Inference/PokemonFRLG_BattleLevelUpReader.h" #include "Inference/PokemonFRLG_BattleSelectionArrowDetector.h" #include "Inference/PokemonFRLG_PartyLevelUpReader.h" @@ -27,7 +31,15 @@ #include "Inference/PokemonFRLG_StatsReader.h" #include "Inference/PokemonFRLG_TrainerIdReader.h" #include "Inference/PokemonFRLG_WildEncounterReader.h" +#include "Overworld/PokemonFRLG_OverworldMaps.h" +#include "Overworld/PokemonFRLG_OverworldReanchor.h" +#include "Overworld/PokemonFRLG_OverworldRecovery.h" +#include "Overworld/PokemonFRLG_OverworldRoute.h" +#include "Overworld/PokemonFRLG_OverworldWalk.h" +#include "Overworld/PokemonFRLG_PlayerFacingReader.h" #include "PokemonFRLG_Navigation.h" +#include "Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h" +#include "Programs/AutoStory/PokemonFRLG_AutoStoryTable.h" #include "Tests/TestUtils.h" #include "PokemonFRLG_Tests.h" @@ -263,6 +275,15 @@ void add_tests_ExitWildBattle(UnitTestDatabase& database){ } +// The menu readers AutoStory brought: the bag's and Marts' lists, the +// options, the save card and the summary's moves. +static void add_tests_AutoStoryReaders(UnitTestDatabase& database){ + add_tests_ItemListReader(database); + add_tests_OptionMenuReader(database); + add_tests_SaveCardReader(database); + add_tests_SummaryMovesReader(database); +} + void add_tests(UnitTestDatabase& database){ add_tests_AdvanceWhiteDialogDetector(database); add_tests_BoxCellOccupiedDetector(database); @@ -287,7 +308,17 @@ void add_tests(UnitTestDatabase& database){ add_tests_HallOfFameSavingDetector(database); add_tests_BattleMoveSelectionArrow(database); add_tests_BagDetector(database); + add_tests_AutoStoryReaders(database); add_tests_ExitWildBattle(database); + add_tests_OverworldMaps(database); + add_tests_OverworldRoute(database); + add_tests_OverworldWalk(database); + add_tests_OverworldReanchor(database); + add_tests_OverworldRecovery(database); + add_tests_PlayerFacingReader(database); + add_tests_AutoStory(database); + add_tests_AutoStorySimulation(database); + add_tests_AutoStoryItems(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/map_trainers.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/map_trainers.json new file mode 100644 index 0000000000..0e600db748 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/map_trainers.json @@ -0,0 +1,106 @@ +{ +"CeladonCity_GameCorner": ["TRAINER_TEAM_ROCKET_GRUNT_7"], +"CeladonCity_Gym": ["TRAINER_BEAUTY_BRIDGET", "TRAINER_BEAUTY_LORI", "TRAINER_BEAUTY_TAMIA", "TRAINER_COOLTRAINER_MARY", "TRAINER_LASS_KAY", "TRAINER_LASS_LISA", "TRAINER_LEADER_ERIKA", "TRAINER_PICNICKER_TINA"], +"CeruleanCity": ["TRAINER_RIVAL_CERULEAN_BULBASAUR", "TRAINER_RIVAL_CERULEAN_CHARMANDER", "TRAINER_RIVAL_CERULEAN_SQUIRTLE", "TRAINER_TEAM_ROCKET_GRUNT_5"], +"CeruleanCity_Gym": ["TRAINER_LEADER_MISTY", "TRAINER_PICNICKER_DIANA", "TRAINER_SWIMMER_MALE_LUIS"], +"CinnabarIsland_Gym": ["TRAINER_BURGLAR_DUSTY", "TRAINER_BURGLAR_QUINN", "TRAINER_BURGLAR_RAMON", "TRAINER_LEADER_BLAINE", "TRAINER_SUPER_NERD_AVERY", "TRAINER_SUPER_NERD_DEREK", "TRAINER_SUPER_NERD_ERIK", "TRAINER_SUPER_NERD_ZAC"], +"FiveIsland_LostCave_Room1": ["TRAINER_RUIN_MANIAC_LAWSON"], +"FiveIsland_LostCave_Room10": ["TRAINER_LADY_SELPHY"], +"FiveIsland_LostCave_Room4": ["TRAINER_PSYCHIC_LAURA"], +"FiveIsland_Meadow": ["TRAINER_TEAM_ROCKET_GRUNT_49", "TRAINER_TEAM_ROCKET_GRUNT_50", "TRAINER_TEAM_ROCKET_GRUNT_51"], +"FiveIsland_MemorialPillar": ["TRAINER_BIRD_KEEPER_CHAZ", "TRAINER_BIRD_KEEPER_HAROLD", "TRAINER_BIRD_KEEPER_MILO"], +"FiveIsland_ResortGorgeous": ["TRAINER_LADY_GILLIAN", "TRAINER_LADY_JACKI", "TRAINER_PAINTER_CELINA", "TRAINER_PAINTER_DAISY", "TRAINER_PAINTER_RAYNA", "TRAINER_SWIMMER_MALE_TOBY", "TRAINER_YOUNGSTER_DESTIN"], +"FiveIsland_RocketWarehouse": ["TRAINER_SCIENTIST_GIDEON", "TRAINER_TEAM_ROCKET_ADMIN", "TRAINER_TEAM_ROCKET_ADMIN_2", "TRAINER_TEAM_ROCKET_GRUNT_42", "TRAINER_TEAM_ROCKET_GRUNT_47", "TRAINER_TEAM_ROCKET_GRUNT_48"], +"FiveIsland_WaterLabyrinth": ["TRAINER_PKMN_BREEDER_ALIZE"], +"FourIsland_IcefallCave_Back": ["TRAINER_TEAM_ROCKET_GRUNT_45"], +"FuchsiaCity_Gym": ["TRAINER_JUGGLER_KAYDEN", "TRAINER_JUGGLER_KIRK", "TRAINER_JUGGLER_NATE", "TRAINER_JUGGLER_SHAWN", "TRAINER_LEADER_KOGA", "TRAINER_TAMER_EDGAR", "TRAINER_TAMER_PHIL"], +"MtEmber_Exterior": ["TRAINER_CRUSH_GIRL_JOCELYN", "TRAINER_PKMN_RANGER_BETH", "TRAINER_PKMN_RANGER_LOGAN", "TRAINER_TEAM_ROCKET_GRUNT_43", "TRAINER_TEAM_ROCKET_GRUNT_44"], +"MtMoon_1F": ["TRAINER_BUG_CATCHER_KENT", "TRAINER_BUG_CATCHER_ROBBY", "TRAINER_HIKER_MARCOS", "TRAINER_LASS_IRIS", "TRAINER_LASS_MIRIAM", "TRAINER_SUPER_NERD_JOVAN", "TRAINER_YOUNGSTER_JOSH"], +"MtMoon_B2F": ["TRAINER_SUPER_NERD_MIGUEL", "TRAINER_TEAM_ROCKET_GRUNT", "TRAINER_TEAM_ROCKET_GRUNT_2", "TRAINER_TEAM_ROCKET_GRUNT_3", "TRAINER_TEAM_ROCKET_GRUNT_4"], +"OneIsland_KindleRoad": ["TRAINER_BLACK_BELT_HUGH", "TRAINER_BLACK_BELT_SHEA", "TRAINER_CAMPER_BRYCE", "TRAINER_CRUSH_GIRL_SHARON", "TRAINER_CRUSH_GIRL_TANYA", "TRAINER_CRUSH_KIN_MIK_KIA", "TRAINER_FISHERMAN_TOMMY", "TRAINER_PICNICKER_CLAIRE", "TRAINER_SWIMMER_FEMALE_ABIGAIL", "TRAINER_SWIMMER_FEMALE_MARIA", "TRAINER_SWIMMER_MALE_FINN", "TRAINER_SWIMMER_MALE_GARRETT"], +"OneIsland_TreasureBeach": ["TRAINER_SWIMMER_FEMALE_AMARA"], +"PalletTown_ProfessorOaksLab": ["TRAINER_RIVAL_OAKS_LAB_BULBASAUR", "TRAINER_RIVAL_OAKS_LAB_CHARMANDER", "TRAINER_RIVAL_OAKS_LAB_SQUIRTLE"], +"PewterCity_Gym": ["TRAINER_CAMPER_LIAM", "TRAINER_LEADER_BROCK"], +"PokemonLeague_AgathasRoom": ["TRAINER_ELITE_FOUR_AGATHA", "TRAINER_ELITE_FOUR_AGATHA_2"], +"PokemonLeague_BrunosRoom": ["TRAINER_ELITE_FOUR_BRUNO", "TRAINER_ELITE_FOUR_BRUNO_2"], +"PokemonLeague_ChampionsRoom": ["TRAINER_CHAMPION_FIRST_BULBASAUR", "TRAINER_CHAMPION_FIRST_CHARMANDER", "TRAINER_CHAMPION_FIRST_SQUIRTLE", "TRAINER_CHAMPION_REMATCH_BULBASAUR", "TRAINER_CHAMPION_REMATCH_CHARMANDER", "TRAINER_CHAMPION_REMATCH_SQUIRTLE"], +"PokemonLeague_LancesRoom": ["TRAINER_ELITE_FOUR_LANCE", "TRAINER_ELITE_FOUR_LANCE_2"], +"PokemonLeague_LoreleisRoom": ["TRAINER_ELITE_FOUR_LORELEI", "TRAINER_ELITE_FOUR_LORELEI_2"], +"PokemonMansion_1F": ["TRAINER_SCIENTIST_TED", "TRAINER_YOUNGSTER_JOHNSON"], +"PokemonMansion_2F": ["TRAINER_BURGLAR_ARNIE"], +"PokemonMansion_3F": ["TRAINER_BURGLAR_SIMON", "TRAINER_SCIENTIST_BRAYDON"], +"PokemonMansion_B1F": ["TRAINER_BURGLAR_LEWIS", "TRAINER_SCIENTIST_IVAN"], +"PokemonTower_2F": ["TRAINER_RIVAL_POKEMON_TOWER_BULBASAUR", "TRAINER_RIVAL_POKEMON_TOWER_CHARMANDER", "TRAINER_RIVAL_POKEMON_TOWER_SQUIRTLE"], +"PokemonTower_3F": ["TRAINER_CHANNELER_CARLY", "TRAINER_CHANNELER_HOPE", "TRAINER_CHANNELER_PATRICIA"], +"PokemonTower_4F": ["TRAINER_CHANNELER_JODY", "TRAINER_CHANNELER_LAUREL", "TRAINER_CHANNELER_PAULA"], +"PokemonTower_5F": ["TRAINER_CHANNELER_JANAE", "TRAINER_CHANNELER_KARINA", "TRAINER_CHANNELER_RUTH", "TRAINER_CHANNELER_TAMMY"], +"PokemonTower_6F": ["TRAINER_CHANNELER_ANGELICA", "TRAINER_CHANNELER_EMILIA", "TRAINER_CHANNELER_JENNIFER"], +"PokemonTower_7F": ["TRAINER_TEAM_ROCKET_GRUNT_19", "TRAINER_TEAM_ROCKET_GRUNT_20", "TRAINER_TEAM_ROCKET_GRUNT_21"], +"RockTunnel_1F": ["TRAINER_HIKER_LENNY", "TRAINER_HIKER_LUCAS", "TRAINER_HIKER_OLIVER", "TRAINER_PICNICKER_ARIANA", "TRAINER_PICNICKER_DANA", "TRAINER_PICNICKER_LEAH", "TRAINER_POKEMANIAC_ASHTON"], +"RockTunnel_B1F": ["TRAINER_HIKER_ALLEN", "TRAINER_HIKER_DUDLEY", "TRAINER_HIKER_ERIC", "TRAINER_PICNICKER_MARTHA", "TRAINER_PICNICKER_SOFIA", "TRAINER_POKEMANIAC_COOPER", "TRAINER_POKEMANIAC_STEVE", "TRAINER_POKEMANIAC_WINSTON"], +"RocketHideout_B1F": ["TRAINER_TEAM_ROCKET_GRUNT_10", "TRAINER_TEAM_ROCKET_GRUNT_11", "TRAINER_TEAM_ROCKET_GRUNT_12", "TRAINER_TEAM_ROCKET_GRUNT_8", "TRAINER_TEAM_ROCKET_GRUNT_9"], +"RocketHideout_B2F": ["TRAINER_TEAM_ROCKET_GRUNT_13"], +"RocketHideout_B3F": ["TRAINER_TEAM_ROCKET_GRUNT_14", "TRAINER_TEAM_ROCKET_GRUNT_15"], +"RocketHideout_B4F": ["TRAINER_BOSS_GIOVANNI", "TRAINER_TEAM_ROCKET_GRUNT_16", "TRAINER_TEAM_ROCKET_GRUNT_17", "TRAINER_TEAM_ROCKET_GRUNT_18"], +"Route10": ["TRAINER_HIKER_CLARK", "TRAINER_HIKER_TRENT", "TRAINER_PICNICKER_CAROL", "TRAINER_PICNICKER_HEIDI", "TRAINER_POKEMANIAC_HERMAN", "TRAINER_POKEMANIAC_MARK"], +"Route11": ["TRAINER_ENGINEER_BERNIE", "TRAINER_ENGINEER_BRAXTON", "TRAINER_GAMER_DARIAN", "TRAINER_GAMER_DIRK", "TRAINER_GAMER_HUGO", "TRAINER_GAMER_JASPER", "TRAINER_YOUNGSTER_DAVE", "TRAINER_YOUNGSTER_DILLON", "TRAINER_YOUNGSTER_EDDIE", "TRAINER_YOUNGSTER_YASU"], +"Route12": ["TRAINER_CAMPER_JUSTIN", "TRAINER_FISHERMAN_ANDREW", "TRAINER_FISHERMAN_CHIP", "TRAINER_FISHERMAN_ELLIOT", "TRAINER_FISHERMAN_HANK", "TRAINER_FISHERMAN_NED", "TRAINER_ROCKER_LUCA", "TRAINER_YOUNG_COUPLE_GIA_JES"], +"Route13": ["TRAINER_BEAUTY_LOLA", "TRAINER_BEAUTY_SHEILA", "TRAINER_BIKER_JARED", "TRAINER_BIRD_KEEPER_PERRY", "TRAINER_BIRD_KEEPER_ROBERT", "TRAINER_BIRD_KEEPER_SEBASTIAN", "TRAINER_PICNICKER_ALMA", "TRAINER_PICNICKER_GWEN", "TRAINER_PICNICKER_SUSIE", "TRAINER_PICNICKER_VALERIE"], +"Route14": ["TRAINER_BIKER_GERALD", "TRAINER_BIKER_ISAAC", "TRAINER_BIKER_LUKAS", "TRAINER_BIKER_MALIK", "TRAINER_BIRD_KEEPER_BECK", "TRAINER_BIRD_KEEPER_BENNY", "TRAINER_BIRD_KEEPER_CARTER", "TRAINER_BIRD_KEEPER_DONALD", "TRAINER_BIRD_KEEPER_MARLON", "TRAINER_BIRD_KEEPER_MITCH", "TRAINER_TWINS_KIRI_JAN"], +"Route15": ["TRAINER_BEAUTY_GRACE", "TRAINER_BEAUTY_OLIVIA", "TRAINER_BIKER_ALEX", "TRAINER_BIKER_ERNEST", "TRAINER_BIRD_KEEPER_CHESTER", "TRAINER_BIRD_KEEPER_EDWIN", "TRAINER_CRUSH_KIN_RON_MYA", "TRAINER_PICNICKER_BECKY", "TRAINER_PICNICKER_CELIA", "TRAINER_PICNICKER_KINDRA", "TRAINER_PICNICKER_YAZMIN"], +"Route16": ["TRAINER_BIKER_HIDEO", "TRAINER_BIKER_LAO", "TRAINER_BIKER_RUBEN", "TRAINER_CUE_BALL_CAMRON", "TRAINER_CUE_BALL_KOJI", "TRAINER_CUE_BALL_LUKE", "TRAINER_YOUNG_COUPLE_LEA_JED"], +"Route17": ["TRAINER_BIKER_BILLY", "TRAINER_BIKER_JAXON", "TRAINER_BIKER_NIKOLAS", "TRAINER_BIKER_VIRGIL", "TRAINER_BIKER_WILLIAM", "TRAINER_CUE_BALL_COREY", "TRAINER_CUE_BALL_ISAIAH", "TRAINER_CUE_BALL_JAMAL", "TRAINER_CUE_BALL_RAUL", "TRAINER_CUE_BALL_ZEEK"], +"Route18": ["TRAINER_BIRD_KEEPER_JACOB", "TRAINER_BIRD_KEEPER_RAMIRO", "TRAINER_BIRD_KEEPER_WILTON"], +"Route19": ["TRAINER_SIS_AND_BRO_LIA_LUC", "TRAINER_SWIMMER_FEMALE_ALICE", "TRAINER_SWIMMER_FEMALE_ANYA", "TRAINER_SWIMMER_FEMALE_CONNIE", "TRAINER_SWIMMER_MALE_AXLE", "TRAINER_SWIMMER_MALE_DAVID", "TRAINER_SWIMMER_MALE_DOUGLAS", "TRAINER_SWIMMER_MALE_MATTHEW", "TRAINER_SWIMMER_MALE_REECE", "TRAINER_SWIMMER_MALE_RICHARD", "TRAINER_SWIMMER_MALE_TONY"], +"Route20": ["TRAINER_BIRD_KEEPER_ROGER", "TRAINER_PICNICKER_IRENE", "TRAINER_PICNICKER_MISSY", "TRAINER_SWIMMER_FEMALE_MELISSA", "TRAINER_SWIMMER_FEMALE_NORA", "TRAINER_SWIMMER_FEMALE_SHIRLEY", "TRAINER_SWIMMER_FEMALE_TIFFANY", "TRAINER_SWIMMER_MALE_BARRY", "TRAINER_SWIMMER_MALE_DARRIN", "TRAINER_SWIMMER_MALE_DEAN"], +"Route21_North": ["TRAINER_FISHERMAN_RONALD", "TRAINER_FISHERMAN_WADE", "TRAINER_SIS_AND_BRO_LIL_IAN", "TRAINER_SWIMMER_MALE_SPENCER"], +"Route21_South": ["TRAINER_FISHERMAN_CLAUDE", "TRAINER_FISHERMAN_NOLAN", "TRAINER_SWIMMER_MALE_JACK", "TRAINER_SWIMMER_MALE_JEROME", "TRAINER_SWIMMER_MALE_ROLAND"], +"Route22": ["TRAINER_RIVAL_ROUTE22_EARLY_BULBASAUR", "TRAINER_RIVAL_ROUTE22_EARLY_CHARMANDER", "TRAINER_RIVAL_ROUTE22_EARLY_SQUIRTLE", "TRAINER_RIVAL_ROUTE22_LATE_BULBASAUR", "TRAINER_RIVAL_ROUTE22_LATE_CHARMANDER", "TRAINER_RIVAL_ROUTE22_LATE_SQUIRTLE"], +"Route24": ["TRAINER_BUG_CATCHER_CALE", "TRAINER_CAMPER_ETHAN", "TRAINER_CAMPER_SHANE", "TRAINER_LASS_ALI", "TRAINER_LASS_RELI", "TRAINER_TEAM_ROCKET_GRUNT_6", "TRAINER_YOUNGSTER_TIMMY"], +"Route25": ["TRAINER_CAMPER_FLINT", "TRAINER_HIKER_FRANKLIN", "TRAINER_HIKER_NOB", "TRAINER_HIKER_WAYNE", "TRAINER_LASS_HALEY", "TRAINER_PICNICKER_KELSEY", "TRAINER_YOUNGSTER_CHAD", "TRAINER_YOUNGSTER_DAN", "TRAINER_YOUNGSTER_JOEY"], +"Route3": ["TRAINER_BUG_CATCHER_COLTON", "TRAINER_BUG_CATCHER_GREG", "TRAINER_BUG_CATCHER_JAMES", "TRAINER_LASS_JANICE", "TRAINER_LASS_ROBIN", "TRAINER_LASS_SALLY", "TRAINER_YOUNGSTER_BEN", "TRAINER_YOUNGSTER_CALVIN"], +"Route4": ["TRAINER_LASS_CRISSY"], +"Route6": ["TRAINER_BUG_CATCHER_ELIJAH", "TRAINER_BUG_CATCHER_KEIGO", "TRAINER_CAMPER_JEFF", "TRAINER_CAMPER_RICKY", "TRAINER_PICNICKER_ISABELLE", "TRAINER_PICNICKER_NANCY"], +"Route8": ["TRAINER_BIKER_JAREN", "TRAINER_BIKER_RICARDO", "TRAINER_GAMER_RICH", "TRAINER_GAMER_STAN", "TRAINER_LASS_ANDREA", "TRAINER_LASS_JULIA", "TRAINER_LASS_MEGAN", "TRAINER_LASS_PAIGE", "TRAINER_SUPER_NERD_AIDAN", "TRAINER_SUPER_NERD_GLENN", "TRAINER_SUPER_NERD_LESLIE", "TRAINER_TWINS_ELI_ANNE"], +"Route9": ["TRAINER_BUG_CATCHER_BRENT", "TRAINER_BUG_CATCHER_CONNER", "TRAINER_CAMPER_CHRIS", "TRAINER_CAMPER_DREW", "TRAINER_HIKER_ALAN", "TRAINER_HIKER_BRICE", "TRAINER_HIKER_JEREMY", "TRAINER_PICNICKER_ALICIA", "TRAINER_PICNICKER_CAITLIN"], +"SSAnne_1F_Room2": ["TRAINER_LASS_ANN", "TRAINER_YOUNGSTER_TYLER"], +"SSAnne_1F_Room5": ["TRAINER_GENTLEMAN_ARTHUR"], +"SSAnne_1F_Room7": ["TRAINER_GENTLEMAN_THOMAS"], +"SSAnne_2F_Corridor": ["TRAINER_RIVAL_SS_ANNE_BULBASAUR", "TRAINER_RIVAL_SS_ANNE_CHARMANDER", "TRAINER_RIVAL_SS_ANNE_SQUIRTLE"], +"SSAnne_2F_Room2": ["TRAINER_FISHERMAN_DALE", "TRAINER_GENTLEMAN_BROOKS"], +"SSAnne_2F_Room4": ["TRAINER_GENTLEMAN_LAMAR", "TRAINER_LASS_DAWN"], +"SSAnne_B1F_Room1": ["TRAINER_FISHERMAN_BARNY", "TRAINER_SAILOR_PHILLIP"], +"SSAnne_B1F_Room2": ["TRAINER_SAILOR_HUEY"], +"SSAnne_B1F_Room3": ["TRAINER_SAILOR_DYLAN"], +"SSAnne_B1F_Room4": ["TRAINER_SAILOR_DUNCAN", "TRAINER_SAILOR_LEONARD"], +"SSAnne_Deck": ["TRAINER_SAILOR_EDMOND", "TRAINER_SAILOR_TREVOR"], +"SaffronCity_Dojo": ["TRAINER_BLACK_BELT_AARON", "TRAINER_BLACK_BELT_HIDEKI", "TRAINER_BLACK_BELT_HITOSHI", "TRAINER_BLACK_BELT_KOICHI", "TRAINER_BLACK_BELT_MIKE"], +"SaffronCity_Gym": ["TRAINER_CHANNELER_AMANDA", "TRAINER_CHANNELER_STACY", "TRAINER_CHANNELER_TASHA", "TRAINER_LEADER_SABRINA", "TRAINER_PSYCHIC_CAMERON", "TRAINER_PSYCHIC_JOHAN", "TRAINER_PSYCHIC_PRESTON", "TRAINER_PSYCHIC_TYRON"], +"SevenIsland_SevaultCanyon": ["TRAINER_COOLTRAINER_LEROY", "TRAINER_COOLTRAINER_MICHELLE", "TRAINER_COOL_COUPLE_LEX_NYA", "TRAINER_CRUSH_GIRL_CYNDY", "TRAINER_PKMN_RANGER_JACKSON", "TRAINER_PKMN_RANGER_KATELYN", "TRAINER_TAMER_EVAN"], +"SevenIsland_SevaultCanyon_Entrance": ["TRAINER_AROMA_LADY_MIAH", "TRAINER_JUGGLER_MASON", "TRAINER_PKMN_RANGER_MADELINE", "TRAINER_PKMN_RANGER_NICOLAS", "TRAINER_YOUNG_COUPLE_EVE_JON"], +"SevenIsland_TanobyRuins": ["TRAINER_GENTLEMAN_CLIFFORD", "TRAINER_PAINTER_EDNA", "TRAINER_RUIN_MANIAC_BENJAMIN", "TRAINER_RUIN_MANIAC_BRANDON"], +"SevenIsland_TrainerTower": ["TRAINER_PSYCHIC_DARIO", "TRAINER_PSYCHIC_RODETTE"], +"SilphCo_10F": ["TRAINER_SCIENTIST_TRAVIS", "TRAINER_TEAM_ROCKET_GRUNT_39"], +"SilphCo_11F": ["TRAINER_BOSS_GIOVANNI_2", "TRAINER_TEAM_ROCKET_GRUNT_40", "TRAINER_TEAM_ROCKET_GRUNT_41"], +"SilphCo_2F": ["TRAINER_SCIENTIST_CONNOR", "TRAINER_SCIENTIST_JERRY", "TRAINER_TEAM_ROCKET_GRUNT_23", "TRAINER_TEAM_ROCKET_GRUNT_24"], +"SilphCo_3F": ["TRAINER_SCIENTIST_JOSE", "TRAINER_TEAM_ROCKET_GRUNT_25"], +"SilphCo_4F": ["TRAINER_SCIENTIST_RODNEY", "TRAINER_TEAM_ROCKET_GRUNT_26", "TRAINER_TEAM_ROCKET_GRUNT_27"], +"SilphCo_5F": ["TRAINER_JUGGLER_DALTON", "TRAINER_SCIENTIST_BEAU", "TRAINER_TEAM_ROCKET_GRUNT_28", "TRAINER_TEAM_ROCKET_GRUNT_29"], +"SilphCo_6F": ["TRAINER_SCIENTIST_TAYLOR", "TRAINER_TEAM_ROCKET_GRUNT_30", "TRAINER_TEAM_ROCKET_GRUNT_31"], +"SilphCo_7F": ["TRAINER_RIVAL_SILPH_BULBASAUR", "TRAINER_RIVAL_SILPH_CHARMANDER", "TRAINER_RIVAL_SILPH_SQUIRTLE", "TRAINER_SCIENTIST_JOSHUA", "TRAINER_TEAM_ROCKET_GRUNT_33", "TRAINER_TEAM_ROCKET_GRUNT_34", "TRAINER_TEAM_ROCKET_GRUNT_35"], +"SilphCo_8F": ["TRAINER_SCIENTIST_PARKER", "TRAINER_TEAM_ROCKET_GRUNT_32", "TRAINER_TEAM_ROCKET_GRUNT_36"], +"SilphCo_9F": ["TRAINER_SCIENTIST_ED", "TRAINER_TEAM_ROCKET_GRUNT_37", "TRAINER_TEAM_ROCKET_GRUNT_38"], +"SixIsland_GreenPath": ["TRAINER_PSYCHIC_JACLYN"], +"SixIsland_OutcastIsland": ["TRAINER_FISHERMAN_TYLOR", "TRAINER_SIS_AND_BRO_AVA_GEB", "TRAINER_SWIMMER_FEMALE_NICOLE", "TRAINER_SWIMMER_MALE_MYMO", "TRAINER_TEAM_ROCKET_GRUNT_46"], +"SixIsland_PatternBush": ["TRAINER_BUG_CATCHER_GARRET", "TRAINER_BUG_CATCHER_JONAH", "TRAINER_BUG_CATCHER_VANCE", "TRAINER_CAMPER_RILEY", "TRAINER_LASS_DALIA", "TRAINER_LASS_JOANA", "TRAINER_PICNICKER_MARCY", "TRAINER_PKMN_BREEDER_ALLISON", "TRAINER_PKMN_BREEDER_BETHANY", "TRAINER_RUIN_MANIAC_LAYTON", "TRAINER_YOUNGSTER_CORDELL", "TRAINER_YOUNGSTER_NASH"], +"SixIsland_RuinValley": ["TRAINER_HIKER_DARYL", "TRAINER_POKEMANIAC_HECTOR", "TRAINER_RUIN_MANIAC_FOSTER", "TRAINER_RUIN_MANIAC_LARRY", "TRAINER_RUIN_MANIAC_STANLY"], +"SixIsland_WaterPath": ["TRAINER_AROMA_LADY_ROSE", "TRAINER_HIKER_EARL", "TRAINER_JUGGLER_EDWARD", "TRAINER_SWIMMER_FEMALE_DENISE", "TRAINER_SWIMMER_MALE_SAMIR", "TRAINER_TWINS_MIU_MIA"], +"ThreeIsland": ["TRAINER_BIKER_GOON", "TRAINER_BIKER_GOON_2", "TRAINER_BIKER_GOON_3", "TRAINER_CUE_BALL_PAXTON"], +"ThreeIsland_BondBridge": ["TRAINER_AROMA_LADY_NIKKI", "TRAINER_AROMA_LADY_VIOLET", "TRAINER_SWIMMER_FEMALE_TISHA", "TRAINER_TUBER_ALEXIS", "TRAINER_TUBER_AMIRA", "TRAINER_TWINS_JOY_MEG"], +"VermilionCity_Gym": ["TRAINER_ENGINEER_BAILY", "TRAINER_GENTLEMAN_TUCKER", "TRAINER_LEADER_LT_SURGE", "TRAINER_SAILOR_DWAYNE"], +"VictoryRoad_1F": ["TRAINER_COOLTRAINER_NAOMI", "TRAINER_COOLTRAINER_ROLANDO"], +"VictoryRoad_2F": ["TRAINER_BLACK_BELT_DAISUKE", "TRAINER_JUGGLER_GREGORY", "TRAINER_JUGGLER_NELSON", "TRAINER_POKEMANIAC_DAWSON", "TRAINER_TAMER_VINCENT"], +"VictoryRoad_3F": ["TRAINER_COOLTRAINER_ALEXA", "TRAINER_COOLTRAINER_CAROLINE", "TRAINER_COOLTRAINER_COLBY", "TRAINER_COOLTRAINER_GEORGE", "TRAINER_COOL_COUPLE_RAY_TYRA"], +"ViridianCity_Gym": ["TRAINER_BLACK_BELT_ATSUSHI", "TRAINER_BLACK_BELT_KIYO", "TRAINER_BLACK_BELT_TAKASHI", "TRAINER_COOLTRAINER_SAMUEL", "TRAINER_COOLTRAINER_WARREN", "TRAINER_COOLTRAINER_YUJI", "TRAINER_LEADER_GIOVANNI", "TRAINER_TAMER_COLE", "TRAINER_TAMER_JASON"], +"ViridianForest": ["TRAINER_BUG_CATCHER_ANTHONY", "TRAINER_BUG_CATCHER_CHARLIE", "TRAINER_BUG_CATCHER_DOUG", "TRAINER_BUG_CATCHER_RICK", "TRAINER_BUG_CATCHER_SAMMY"] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json new file mode 100644 index 0000000000..64425be1f6 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json @@ -0,0 +1,356 @@ +{ +"pound": [40, "normal", 35, 100, 0, "hit", 0], +"karate-chop": [50, "fighting", 25, 100, 0, "high-critical", 0], +"double-slap": [15, "normal", 10, 85, 0, "multi-hit", 0], +"comet-punch": [18, "normal", 15, 85, 0, "multi-hit", 0], +"mega-punch": [80, "normal", 20, 85, 0, "hit", 0], +"pay-day": [40, "normal", 20, 100, 0, "pay-day", 100], +"fire-punch": [75, "fire", 15, 100, 0, "burn-hit", 10], +"ice-punch": [75, "ice", 15, 100, 0, "freeze-hit", 10], +"thunder-punch": [75, "electric", 15, 100, 0, "paralyze-hit", 10], +"scratch": [40, "normal", 35, 100, 0, "hit", 0], +"vise-grip": [55, "normal", 30, 100, 0, "hit", 0], +"guillotine": [1, "normal", 5, 30, 0, "ohko", 0], +"razor-wind": [80, "normal", 10, 100, 0, "razor-wind", 0], +"swords-dance": [0, "normal", 30, 0, 0, "attack-up-2", 0], +"cut": [50, "normal", 30, 95, 0, "hit", 0], +"gust": [40, "flying", 35, 100, 0, "gust", 0], +"wing-attack": [60, "flying", 35, 100, 0, "hit", 0], +"whirlwind": [0, "normal", 20, 100, -6, "roar", 0], +"fly": [70, "flying", 15, 95, 0, "semi-invulnerable", 0], +"bind": [15, "normal", 20, 75, 0, "trap", 100], +"slam": [80, "normal", 20, 75, 0, "hit", 0], +"vine-whip": [35, "grass", 10, 100, 0, "hit", 0], +"stomp": [65, "normal", 20, 100, 0, "flinch-minimize-hit", 30], +"double-kick": [30, "fighting", 30, 100, 0, "double-hit", 0], +"mega-kick": [120, "normal", 5, 75, 0, "hit", 0], +"jump-kick": [70, "fighting", 25, 95, 0, "recoil-if-miss", 0], +"rolling-kick": [60, "fighting", 15, 85, 0, "flinch-hit", 30], +"sand-attack": [0, "ground", 15, 100, 0, "accuracy-down", 0], +"headbutt": [70, "normal", 15, 100, 0, "flinch-hit", 30], +"horn-attack": [65, "normal", 25, 100, 0, "hit", 0], +"fury-attack": [15, "normal", 20, 85, 0, "multi-hit", 0], +"horn-drill": [1, "normal", 5, 30, 0, "ohko", 0], +"tackle": [35, "normal", 35, 95, 0, "hit", 0], +"body-slam": [85, "normal", 15, 100, 0, "paralyze-hit", 30], +"wrap": [15, "normal", 20, 85, 0, "trap", 100], +"take-down": [90, "normal", 20, 85, 0, "recoil", 0], +"thrash": [90, "normal", 20, 100, 0, "rampage", 100], +"double-edge": [120, "normal", 15, 100, 0, "double-edge", 0], +"tail-whip": [0, "normal", 30, 100, 0, "defense-down", 0], +"poison-sting": [15, "poison", 35, 100, 0, "poison-hit", 30], +"twineedle": [25, "bug", 20, 100, 0, "twineedle", 20], +"pin-missile": [14, "bug", 20, 85, 0, "multi-hit", 0], +"leer": [0, "normal", 30, 100, 0, "defense-down", 0], +"bite": [60, "dark", 25, 100, 0, "flinch-hit", 30], +"growl": [0, "normal", 40, 100, 0, "attack-down", 0], +"roar": [0, "normal", 20, 100, -6, "roar", 0], +"sing": [0, "normal", 15, 55, 0, "sleep", 0], +"supersonic": [0, "normal", 20, 55, 0, "confuse", 0], +"sonic-boom": [1, "normal", 20, 90, 0, "sonicboom", 0], +"disable": [0, "normal", 20, 55, 0, "disable", 0], +"acid": [40, "poison", 30, 100, 0, "defense-down-hit", 10], +"ember": [40, "fire", 25, 100, 0, "burn-hit", 10], +"flamethrower": [95, "fire", 15, 100, 0, "burn-hit", 10], +"mist": [0, "ice", 30, 0, 0, "mist", 0], +"water-gun": [40, "water", 25, 100, 0, "hit", 0], +"hydro-pump": [120, "water", 5, 80, 0, "hit", 0], +"surf": [95, "water", 15, 100, 0, "hit", 0], +"ice-beam": [95, "ice", 10, 100, 0, "freeze-hit", 10], +"blizzard": [120, "ice", 5, 70, 0, "freeze-hit", 10], +"psybeam": [65, "psychic", 20, 100, 0, "confuse-hit", 10], +"bubble-beam": [65, "water", 20, 100, 0, "speed-down-hit", 10], +"aurora-beam": [65, "ice", 20, 100, 0, "attack-down-hit", 10], +"hyper-beam": [150, "normal", 5, 90, 0, "recharge", 0], +"peck": [35, "flying", 35, 100, 0, "hit", 0], +"drill-peck": [80, "flying", 20, 100, 0, "hit", 0], +"submission": [80, "fighting", 25, 80, 0, "recoil", 0], +"low-kick": [1, "fighting", 20, 100, 0, "low-kick", 0], +"counter": [1, "fighting", 20, 100, -5, "counter", 0], +"seismic-toss": [1, "fighting", 20, 100, 0, "level-damage", 0], +"strength": [80, "normal", 15, 100, 0, "hit", 0], +"absorb": [20, "grass", 20, 100, 0, "absorb", 0], +"mega-drain": [40, "grass", 10, 100, 0, "absorb", 0], +"leech-seed": [0, "grass", 10, 90, 0, "leech-seed", 0], +"growth": [0, "normal", 40, 0, 0, "special-attack-up", 0], +"razor-leaf": [55, "grass", 25, 95, 0, "high-critical", 0], +"solar-beam": [120, "grass", 10, 100, 0, "solar-beam", 0], +"poison-powder": [0, "poison", 35, 75, 0, "poison", 0], +"stun-spore": [0, "grass", 30, 75, 0, "paralyze", 0], +"sleep-powder": [0, "grass", 15, 75, 0, "sleep", 0], +"petal-dance": [70, "grass", 20, 100, 0, "rampage", 100], +"string-shot": [0, "bug", 40, 95, 0, "speed-down", 0], +"dragon-rage": [1, "dragon", 10, 100, 0, "dragon-rage", 0], +"fire-spin": [15, "fire", 15, 70, 0, "trap", 100], +"thunder-shock": [40, "electric", 30, 100, 0, "paralyze-hit", 10], +"thunderbolt": [95, "electric", 15, 100, 0, "paralyze-hit", 10], +"thunder-wave": [0, "electric", 20, 100, 0, "paralyze", 0], +"thunder": [120, "electric", 10, 70, 0, "thunder", 30], +"rock-throw": [50, "rock", 15, 90, 0, "hit", 0], +"earthquake": [100, "ground", 10, 100, 0, "earthquake", 0], +"fissure": [1, "ground", 5, 30, 0, "ohko", 0], +"dig": [60, "ground", 10, 100, 0, "semi-invulnerable", 0], +"toxic": [0, "poison", 10, 85, 0, "toxic", 100], +"confusion": [50, "psychic", 25, 100, 0, "confuse-hit", 10], +"psychic": [90, "psychic", 10, 100, 0, "special-defense-down-hit", 10], +"hypnosis": [0, "psychic", 20, 60, 0, "sleep", 0], +"meditate": [0, "psychic", 40, 0, 0, "attack-up", 0], +"agility": [0, "psychic", 30, 0, 0, "speed-up-2", 0], +"quick-attack": [40, "normal", 30, 100, 1, "quick-attack", 0], +"rage": [20, "normal", 20, 100, 0, "rage", 0], +"teleport": [0, "psychic", 20, 0, 0, "teleport", 0], +"night-shade": [1, "ghost", 15, 100, 0, "level-damage", 0], +"mimic": [0, "normal", 10, 100, 0, "mimic", 0], +"screech": [0, "normal", 40, 85, 0, "defense-down-2", 0], +"double-team": [0, "normal", 15, 0, 0, "evasion-up", 0], +"recover": [0, "normal", 20, 0, 0, "restore-hp", 0], +"harden": [0, "normal", 30, 0, 0, "defense-up", 0], +"minimize": [0, "normal", 20, 0, 0, "minimize", 0], +"smokescreen": [0, "normal", 20, 100, 0, "accuracy-down", 0], +"confuse-ray": [0, "ghost", 10, 100, 0, "confuse", 0], +"withdraw": [0, "water", 40, 0, 0, "defense-up", 0], +"defense-curl": [0, "normal", 40, 0, 0, "defense-curl", 0], +"barrier": [0, "psychic", 30, 0, 0, "defense-up-2", 0], +"light-screen": [0, "psychic", 30, 0, 0, "light-screen", 0], +"haze": [0, "ice", 30, 0, 0, "haze", 0], +"reflect": [0, "psychic", 20, 0, 0, "reflect", 0], +"focus-energy": [0, "normal", 30, 0, 0, "focus-energy", 0], +"bide": [1, "normal", 10, 100, 0, "bide", 0], +"metronome": [0, "normal", 10, 0, 0, "metronome", 0], +"mirror-move": [0, "flying", 20, 0, 0, "mirror-move", 0], +"self-destruct": [200, "normal", 5, 100, 0, "explosion", 0], +"egg-bomb": [100, "normal", 10, 75, 0, "hit", 0], +"lick": [20, "ghost", 30, 100, 0, "paralyze-hit", 30], +"smog": [20, "poison", 20, 70, 0, "poison-hit", 40], +"sludge": [65, "poison", 20, 100, 0, "poison-hit", 30], +"bone-club": [65, "ground", 20, 85, 0, "flinch-hit", 10], +"fire-blast": [120, "fire", 5, 85, 0, "burn-hit", 10], +"waterfall": [80, "water", 15, 100, 0, "hit", 0], +"clamp": [35, "water", 10, 75, 0, "trap", 100], +"swift": [60, "normal", 20, 0, 0, "always-hit", 0], +"skull-bash": [100, "normal", 15, 100, 0, "skull-bash", 0], +"spike-cannon": [20, "normal", 15, 100, 0, "multi-hit", 0], +"constrict": [10, "normal", 35, 100, 0, "speed-down-hit", 10], +"amnesia": [0, "psychic", 20, 0, 0, "special-defense-up-2", 0], +"kinesis": [0, "psychic", 15, 80, 0, "accuracy-down", 0], +"soft-boiled": [0, "normal", 10, 100, 0, "softboiled", 0], +"high-jump-kick": [85, "fighting", 20, 90, 0, "recoil-if-miss", 0], +"glare": [0, "normal", 30, 75, 0, "paralyze", 0], +"dream-eater": [100, "psychic", 15, 100, 0, "dream-eater", 0], +"poison-gas": [0, "poison", 40, 55, 0, "poison", 0], +"barrage": [15, "normal", 20, 85, 0, "multi-hit", 0], +"leech-life": [20, "bug", 15, 100, 0, "absorb", 0], +"lovely-kiss": [0, "normal", 10, 75, 0, "sleep", 0], +"sky-attack": [140, "flying", 5, 90, 0, "sky-attack", 30], +"transform": [0, "normal", 10, 0, 0, "transform", 0], +"bubble": [20, "water", 30, 100, 0, "speed-down-hit", 10], +"dizzy-punch": [70, "normal", 10, 100, 0, "confuse-hit", 20], +"spore": [0, "grass", 15, 100, 0, "sleep", 0], +"flash": [0, "normal", 20, 70, 0, "accuracy-down", 0], +"psywave": [1, "psychic", 15, 80, 0, "psywave", 0], +"splash": [0, "normal", 40, 0, 0, "splash", 0], +"acid-armor": [0, "poison", 40, 0, 0, "defense-up-2", 0], +"crabhammer": [90, "water", 10, 85, 0, "high-critical", 0], +"explosion": [250, "normal", 5, 100, 0, "explosion", 0], +"fury-swipes": [18, "normal", 15, 80, 0, "multi-hit", 0], +"bonemerang": [50, "ground", 10, 90, 0, "double-hit", 0], +"rest": [0, "psychic", 10, 0, 0, "rest", 0], +"rock-slide": [75, "rock", 10, 90, 0, "flinch-hit", 30], +"hyper-fang": [80, "normal", 15, 90, 0, "flinch-hit", 10], +"sharpen": [0, "normal", 30, 0, 0, "attack-up", 0], +"conversion": [0, "normal", 30, 0, 0, "conversion", 0], +"tri-attack": [80, "normal", 10, 100, 0, "tri-attack", 20], +"super-fang": [1, "normal", 10, 90, 0, "super-fang", 0], +"slash": [70, "normal", 20, 100, 0, "high-critical", 0], +"substitute": [0, "normal", 10, 0, 0, "substitute", 0], +"struggle": [50, "normal", 1, 100, 0, "recoil", 0], +"sketch": [0, "normal", 1, 0, 0, "sketch", 0], +"triple-kick": [10, "fighting", 10, 90, 0, "triple-kick", 0], +"thief": [40, "dark", 10, 100, 0, "thief", 100], +"spider-web": [0, "bug", 10, 100, 0, "mean-look", 0], +"mind-reader": [0, "normal", 5, 100, 0, "lock-on", 0], +"nightmare": [0, "ghost", 15, 100, 0, "nightmare", 0], +"flame-wheel": [60, "fire", 25, 100, 0, "thaw-hit", 10], +"snore": [40, "normal", 15, 100, 0, "snore", 30], +"curse": [0, "mystery", 10, 0, 0, "curse", 0], +"flail": [1, "normal", 15, 100, 0, "flail", 0], +"conversion-2": [0, "normal", 30, 100, 0, "conversion-2", 0], +"aeroblast": [100, "flying", 5, 95, 0, "high-critical", 0], +"cotton-spore": [0, "grass", 40, 85, 0, "speed-down-2", 0], +"reversal": [1, "fighting", 15, 100, 0, "flail", 0], +"spite": [0, "ghost", 10, 100, 0, "spite", 0], +"powder-snow": [40, "ice", 25, 100, 0, "freeze-hit", 10], +"protect": [0, "normal", 10, 0, 3, "protect", 0], +"mach-punch": [40, "fighting", 30, 100, 1, "quick-attack", 0], +"scary-face": [0, "normal", 10, 90, 0, "speed-down-2", 0], +"feint-attack": [60, "dark", 20, 0, 0, "always-hit", 0], +"sweet-kiss": [0, "normal", 10, 75, 0, "confuse", 0], +"belly-drum": [0, "normal", 10, 0, 0, "belly-drum", 0], +"sludge-bomb": [90, "poison", 10, 100, 0, "poison-hit", 30], +"mud-slap": [20, "ground", 10, 100, 0, "accuracy-down-hit", 100], +"octazooka": [65, "water", 10, 85, 0, "accuracy-down-hit", 50], +"spikes": [0, "ground", 20, 0, 0, "spikes", 0], +"zap-cannon": [100, "electric", 5, 50, 0, "paralyze-hit", 100], +"foresight": [0, "normal", 40, 100, 0, "foresight", 0], +"destiny-bond": [0, "ghost", 5, 0, 0, "destiny-bond", 0], +"perish-song": [0, "normal", 5, 0, 0, "perish-song", 0], +"icy-wind": [55, "ice", 15, 95, 0, "speed-down-hit", 100], +"detect": [0, "fighting", 5, 0, 3, "protect", 0], +"bone-rush": [25, "ground", 10, 80, 0, "multi-hit", 0], +"lock-on": [0, "normal", 5, 100, 0, "lock-on", 0], +"outrage": [90, "dragon", 15, 100, 0, "rampage", 100], +"sandstorm": [0, "rock", 10, 0, 0, "sandstorm", 0], +"giga-drain": [60, "grass", 5, 100, 0, "absorb", 0], +"endure": [0, "normal", 10, 0, 3, "endure", 0], +"charm": [0, "normal", 20, 100, 0, "attack-down-2", 0], +"rollout": [30, "rock", 20, 90, 0, "rollout", 0], +"false-swipe": [40, "normal", 40, 100, 0, "false-swipe", 0], +"swagger": [0, "normal", 15, 90, 0, "swagger", 100], +"milk-drink": [0, "normal", 10, 0, 0, "softboiled", 0], +"spark": [65, "electric", 20, 100, 0, "paralyze-hit", 30], +"fury-cutter": [10, "bug", 20, 95, 0, "fury-cutter", 0], +"steel-wing": [70, "steel", 25, 90, 0, "defense-up-hit", 10], +"mean-look": [0, "normal", 5, 100, 0, "mean-look", 0], +"attract": [0, "normal", 15, 100, 0, "attract", 0], +"sleep-talk": [0, "normal", 10, 0, 0, "sleep-talk", 0], +"heal-bell": [0, "normal", 5, 0, 0, "heal-bell", 0], +"return": [1, "normal", 20, 100, 0, "return", 0], +"present": [1, "normal", 15, 90, 0, "present", 0], +"frustration": [1, "normal", 20, 100, 0, "frustration", 0], +"safeguard": [0, "normal", 25, 0, 0, "safeguard", 0], +"pain-split": [0, "normal", 20, 100, 0, "pain-split", 0], +"sacred-fire": [100, "fire", 5, 95, 0, "thaw-hit", 50], +"magnitude": [1, "ground", 30, 100, 0, "magnitude", 0], +"dynamic-punch": [100, "fighting", 5, 50, 0, "confuse-hit", 100], +"megahorn": [120, "bug", 10, 85, 0, "hit", 0], +"dragon-breath": [60, "dragon", 20, 100, 0, "paralyze-hit", 30], +"baton-pass": [0, "normal", 40, 0, 0, "baton-pass", 0], +"encore": [0, "normal", 5, 100, 0, "encore", 0], +"pursuit": [40, "dark", 20, 100, 0, "pursuit", 0], +"rapid-spin": [20, "normal", 40, 100, 0, "rapid-spin", 0], +"sweet-scent": [0, "normal", 20, 100, 0, "evasion-down", 0], +"iron-tail": [100, "steel", 15, 75, 0, "defense-down-hit", 30], +"metal-claw": [50, "steel", 35, 95, 0, "attack-up-hit", 10], +"vital-throw": [70, "fighting", 10, 100, -1, "vital-throw", 0], +"morning-sun": [0, "normal", 5, 0, 0, "morning-sun", 0], +"synthesis": [0, "grass", 5, 0, 0, "synthesis", 0], +"moonlight": [0, "normal", 5, 0, 0, "moonlight", 0], +"hidden-power": [1, "normal", 15, 100, 0, "hidden-power", 0], +"cross-chop": [100, "fighting", 5, 80, 0, "high-critical", 0], +"twister": [40, "dragon", 20, 100, 0, "twister", 20], +"rain-dance": [0, "water", 5, 0, 0, "rain-dance", 0], +"sunny-day": [0, "fire", 5, 0, 0, "sunny-day", 0], +"crunch": [80, "dark", 15, 100, 0, "special-defense-down-hit", 20], +"mirror-coat": [1, "psychic", 20, 100, -5, "mirror-coat", 0], +"psych-up": [0, "normal", 10, 0, 0, "psych-up", 0], +"extreme-speed": [80, "normal", 5, 100, 1, "quick-attack", 0], +"ancient-power": [60, "rock", 5, 100, 0, "all-stats-up-hit", 10], +"shadow-ball": [80, "ghost", 15, 100, 0, "special-defense-down-hit", 20], +"future-sight": [80, "psychic", 15, 90, 0, "future-sight", 0], +"rock-smash": [20, "fighting", 15, 100, 0, "defense-down-hit", 50], +"whirlpool": [15, "water", 15, 70, 0, "trap", 100], +"beat-up": [10, "dark", 10, 100, 0, "beat-up", 0], +"fake-out": [40, "normal", 10, 100, 1, "fake-out", 0], +"uproar": [50, "normal", 10, 100, 0, "uproar", 100], +"stockpile": [0, "normal", 10, 0, 0, "stockpile", 0], +"spit-up": [100, "normal", 10, 100, 0, "spit-up", 0], +"swallow": [0, "normal", 10, 0, 0, "swallow", 0], +"heat-wave": [100, "fire", 10, 90, 0, "burn-hit", 10], +"hail": [0, "ice", 10, 0, 0, "hail", 0], +"torment": [0, "dark", 15, 100, 0, "torment", 0], +"flatter": [0, "dark", 15, 100, 0, "flatter", 0], +"will-o-wisp": [0, "fire", 15, 75, 0, "will-o-wisp", 0], +"memento": [0, "dark", 10, 100, 0, "memento", 0], +"facade": [70, "normal", 20, 100, 0, "facade", 0], +"focus-punch": [150, "fighting", 20, 100, -3, "focus-punch", 0], +"smelling-salts": [60, "normal", 10, 100, 0, "smellingsalt", 0], +"follow-me": [0, "normal", 20, 100, 3, "follow-me", 0], +"nature-power": [0, "normal", 20, 0, 0, "nature-power", 0], +"charge": [0, "electric", 20, 100, 0, "charge", 0], +"taunt": [0, "dark", 20, 100, 0, "taunt", 0], +"helping-hand": [0, "normal", 20, 100, 5, "helping-hand", 0], +"trick": [0, "psychic", 10, 100, 0, "trick", 0], +"role-play": [0, "psychic", 10, 100, 0, "role-play", 0], +"wish": [0, "normal", 10, 100, 0, "wish", 0], +"assist": [0, "normal", 20, 100, 0, "assist", 0], +"ingrain": [0, "grass", 20, 100, 0, "ingrain", 0], +"superpower": [120, "fighting", 5, 100, 0, "superpower", 0], +"magic-coat": [0, "psychic", 15, 100, 4, "magic-coat", 0], +"recycle": [0, "normal", 10, 100, 0, "recycle", 0], +"revenge": [60, "fighting", 10, 100, -4, "revenge", 0], +"brick-break": [75, "fighting", 15, 100, 0, "brick-break", 0], +"yawn": [0, "normal", 10, 100, 0, "yawn", 0], +"knock-off": [20, "dark", 20, 100, 0, "knock-off", 100], +"endeavor": [1, "normal", 5, 100, 0, "endeavor", 0], +"eruption": [150, "fire", 5, 100, 0, "eruption", 0], +"skill-swap": [0, "psychic", 10, 100, 0, "skill-swap", 0], +"imprison": [0, "psychic", 10, 100, 0, "imprison", 0], +"refresh": [0, "normal", 20, 100, 0, "refresh", 0], +"grudge": [0, "ghost", 5, 100, 0, "grudge", 0], +"snatch": [0, "dark", 10, 100, 4, "snatch", 0], +"secret-power": [70, "normal", 20, 100, 0, "secret-power", 30], +"dive": [60, "water", 10, 100, 0, "semi-invulnerable", 0], +"arm-thrust": [15, "fighting", 20, 100, 0, "multi-hit", 0], +"camouflage": [0, "normal", 20, 100, 0, "camouflage", 0], +"tail-glow": [0, "bug", 20, 100, 0, "special-attack-up-2", 0], +"luster-purge": [70, "psychic", 5, 100, 0, "special-defense-down-hit", 50], +"mist-ball": [70, "psychic", 5, 100, 0, "special-attack-down-hit", 50], +"feather-dance": [0, "flying", 15, 100, 0, "attack-down-2", 0], +"teeter-dance": [0, "normal", 20, 100, 0, "teeter-dance", 0], +"blaze-kick": [85, "fire", 10, 90, 0, "blaze-kick", 10], +"mud-sport": [0, "ground", 15, 100, 0, "mud-sport", 0], +"ice-ball": [30, "ice", 20, 90, 0, "rollout", 0], +"needle-arm": [60, "grass", 15, 100, 0, "flinch-minimize-hit", 30], +"slack-off": [0, "normal", 10, 100, 0, "restore-hp", 0], +"hyper-voice": [90, "normal", 10, 100, 0, "hit", 0], +"poison-fang": [50, "poison", 15, 100, 0, "poison-fang", 30], +"crush-claw": [75, "normal", 10, 95, 0, "defense-down-hit", 50], +"blast-burn": [150, "fire", 5, 90, 0, "recharge", 0], +"hydro-cannon": [150, "water", 5, 90, 0, "recharge", 0], +"meteor-mash": [100, "steel", 10, 85, 0, "attack-up-hit", 20], +"astonish": [30, "ghost", 15, 100, 0, "flinch-minimize-hit", 30], +"weather-ball": [50, "normal", 10, 100, 0, "weather-ball", 0], +"aromatherapy": [0, "grass", 5, 0, 0, "heal-bell", 0], +"fake-tears": [0, "dark", 20, 100, 0, "special-defense-down-2", 0], +"air-cutter": [55, "flying", 25, 95, 0, "high-critical", 0], +"overheat": [140, "fire", 5, 90, 0, "overheat", 100], +"odor-sleuth": [0, "normal", 40, 100, 0, "foresight", 0], +"rock-tomb": [50, "rock", 10, 80, 0, "speed-down-hit", 100], +"silver-wind": [60, "bug", 5, 100, 0, "all-stats-up-hit", 10], +"metal-sound": [0, "steel", 40, 85, 0, "special-defense-down-2", 0], +"grass-whistle": [0, "grass", 15, 55, 0, "sleep", 0], +"tickle": [0, "normal", 20, 100, 0, "tickle", 0], +"cosmic-power": [0, "psychic", 20, 0, 0, "cosmic-power", 0], +"water-spout": [150, "water", 5, 100, 0, "eruption", 0], +"signal-beam": [75, "bug", 15, 100, 0, "confuse-hit", 10], +"shadow-punch": [60, "ghost", 20, 0, 0, "always-hit", 0], +"extrasensory": [80, "psychic", 30, 100, 0, "flinch-minimize-hit", 10], +"sky-uppercut": [85, "fighting", 15, 90, 0, "sky-uppercut", 0], +"sand-tomb": [15, "ground", 15, 70, 0, "trap", 100], +"sheer-cold": [1, "ice", 5, 30, 0, "ohko", 0], +"muddy-water": [95, "water", 10, 85, 0, "accuracy-down-hit", 30], +"bullet-seed": [10, "grass", 30, 100, 0, "multi-hit", 0], +"aerial-ace": [60, "flying", 20, 0, 0, "always-hit", 0], +"icicle-spear": [10, "ice", 30, 100, 0, "multi-hit", 0], +"iron-defense": [0, "steel", 15, 0, 0, "defense-up-2", 0], +"block": [0, "normal", 5, 100, 0, "mean-look", 0], +"howl": [0, "normal", 40, 0, 0, "attack-up", 0], +"dragon-claw": [80, "dragon", 15, 100, 0, "hit", 0], +"frenzy-plant": [150, "grass", 5, 90, 0, "recharge", 0], +"bulk-up": [0, "fighting", 20, 0, 0, "bulk-up", 0], +"bounce": [85, "flying", 5, 85, 0, "semi-invulnerable", 30], +"mud-shot": [55, "ground", 15, 95, 0, "speed-down-hit", 100], +"poison-tail": [50, "poison", 25, 100, 0, "poison-tail", 10], +"covet": [40, "normal", 40, 100, 0, "thief", 100], +"volt-tackle": [120, "electric", 15, 100, 0, "double-edge", 0], +"magical-leaf": [60, "grass", 20, 0, 0, "always-hit", 0], +"water-sport": [0, "water", 15, 100, 0, "water-sport", 0], +"calm-mind": [0, "psychic", 20, 0, 0, "calm-mind", 0], +"leaf-blade": [70, "grass", 15, 100, 0, "high-critical", 0], +"dragon-dance": [0, "dragon", 20, 0, 0, "dragon-dance", 0], +"rock-blast": [25, "rock", 10, 80, 0, "multi-hit", 0], +"shock-wave": [60, "electric", 20, 0, 0, "always-hit", 0], +"water-pulse": [60, "water", 20, 100, 0, "confuse-hit", 20], +"doom-desire": [120, "steel", 5, 85, 0, "future-sight", 0], +"psycho-boost": [140, "psychic", 5, 90, 0, "overheat", 100] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json new file mode 100644 index 0000000000..5393e90c95 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json @@ -0,0 +1,388 @@ +{ +"bulbasaur": ["grass", "poison", 45, 49, 49, 65, 65, 45], +"ivysaur": ["grass", "poison", 60, 62, 63, 80, 80, 60], +"venusaur": ["grass", "poison", 80, 82, 83, 100, 100, 80], +"charmander": ["fire", "fire", 39, 52, 43, 60, 50, 65], +"charmeleon": ["fire", "fire", 58, 64, 58, 80, 65, 80], +"charizard": ["fire", "flying", 78, 84, 78, 109, 85, 100], +"squirtle": ["water", "water", 44, 48, 65, 50, 64, 43], +"wartortle": ["water", "water", 59, 63, 80, 65, 80, 58], +"blastoise": ["water", "water", 79, 83, 100, 85, 105, 78], +"caterpie": ["bug", "bug", 45, 30, 35, 20, 20, 45], +"metapod": ["bug", "bug", 50, 20, 55, 25, 25, 30], +"butterfree": ["bug", "flying", 60, 45, 50, 80, 80, 70], +"weedle": ["bug", "poison", 40, 35, 30, 20, 20, 50], +"kakuna": ["bug", "poison", 45, 25, 50, 25, 25, 35], +"beedrill": ["bug", "poison", 65, 80, 40, 45, 80, 75], +"pidgey": ["normal", "flying", 40, 45, 40, 35, 35, 56], +"pidgeotto": ["normal", "flying", 63, 60, 55, 50, 50, 71], +"pidgeot": ["normal", "flying", 83, 80, 75, 70, 70, 91], +"rattata": ["normal", "normal", 30, 56, 35, 25, 35, 72], +"raticate": ["normal", "normal", 55, 81, 60, 50, 70, 97], +"spearow": ["normal", "flying", 40, 60, 30, 31, 31, 70], +"fearow": ["normal", "flying", 65, 90, 65, 61, 61, 100], +"ekans": ["poison", "poison", 35, 60, 44, 40, 54, 55], +"arbok": ["poison", "poison", 60, 85, 69, 65, 79, 80], +"pikachu": ["electric", "electric", 35, 55, 30, 50, 40, 90], +"raichu": ["electric", "electric", 60, 90, 55, 90, 80, 100], +"sandshrew": ["ground", "ground", 50, 75, 85, 20, 30, 40], +"sandslash": ["ground", "ground", 75, 100, 110, 45, 55, 65], +"nidoran-f": ["poison", "poison", 55, 47, 52, 40, 40, 41], +"nidorina": ["poison", "poison", 70, 62, 67, 55, 55, 56], +"nidoqueen": ["poison", "ground", 90, 82, 87, 75, 85, 76], +"nidoran-m": ["poison", "poison", 46, 57, 40, 40, 40, 50], +"nidorino": ["poison", "poison", 61, 72, 57, 55, 55, 65], +"nidoking": ["poison", "ground", 81, 92, 77, 85, 75, 85], +"clefairy": ["normal", "normal", 70, 45, 48, 60, 65, 35], +"clefable": ["normal", "normal", 95, 70, 73, 85, 90, 60], +"vulpix": ["fire", "fire", 38, 41, 40, 50, 65, 65], +"ninetales": ["fire", "fire", 73, 76, 75, 81, 100, 100], +"jigglypuff": ["normal", "normal", 115, 45, 20, 45, 25, 20], +"wigglytuff": ["normal", "normal", 140, 70, 45, 75, 50, 45], +"zubat": ["poison", "flying", 40, 45, 35, 30, 40, 55], +"golbat": ["poison", "flying", 75, 80, 70, 65, 75, 90], +"oddish": ["grass", "poison", 45, 50, 55, 75, 65, 30], +"gloom": ["grass", "poison", 60, 65, 70, 85, 75, 40], +"vileplume": ["grass", "poison", 75, 80, 85, 100, 90, 50], +"paras": ["bug", "grass", 35, 70, 55, 45, 55, 25], +"parasect": ["bug", "grass", 60, 95, 80, 60, 80, 30], +"venonat": ["bug", "poison", 60, 55, 50, 40, 55, 45], +"venomoth": ["bug", "poison", 70, 65, 60, 90, 75, 90], +"diglett": ["ground", "ground", 10, 55, 25, 35, 45, 95], +"dugtrio": ["ground", "ground", 35, 80, 50, 50, 70, 120], +"meowth": ["normal", "normal", 40, 45, 35, 40, 40, 90], +"persian": ["normal", "normal", 65, 70, 60, 65, 65, 115], +"psyduck": ["water", "water", 50, 52, 48, 65, 50, 55], +"golduck": ["water", "water", 80, 82, 78, 95, 80, 85], +"mankey": ["fighting", "fighting", 40, 80, 35, 35, 45, 70], +"primeape": ["fighting", "fighting", 65, 105, 60, 60, 70, 95], +"growlithe": ["fire", "fire", 55, 70, 45, 70, 50, 60], +"arcanine": ["fire", "fire", 90, 110, 80, 100, 80, 95], +"poliwag": ["water", "water", 40, 50, 40, 40, 40, 90], +"poliwhirl": ["water", "water", 65, 65, 65, 50, 50, 90], +"poliwrath": ["water", "fighting", 90, 85, 95, 70, 90, 70], +"abra": ["psychic", "psychic", 25, 20, 15, 105, 55, 90], +"kadabra": ["psychic", "psychic", 40, 35, 30, 120, 70, 105], +"alakazam": ["psychic", "psychic", 55, 50, 45, 135, 85, 120], +"machop": ["fighting", "fighting", 70, 80, 50, 35, 35, 35], +"machoke": ["fighting", "fighting", 80, 100, 70, 50, 60, 45], +"machamp": ["fighting", "fighting", 90, 130, 80, 65, 85, 55], +"bellsprout": ["grass", "poison", 50, 75, 35, 70, 30, 40], +"weepinbell": ["grass", "poison", 65, 90, 50, 85, 45, 55], +"victreebel": ["grass", "poison", 80, 105, 65, 100, 60, 70], +"tentacool": ["water", "poison", 40, 40, 35, 50, 100, 70], +"tentacruel": ["water", "poison", 80, 70, 65, 80, 120, 100], +"geodude": ["rock", "ground", 40, 80, 100, 30, 30, 20], +"graveler": ["rock", "ground", 55, 95, 115, 45, 45, 35], +"golem": ["rock", "ground", 80, 110, 130, 55, 65, 45], +"ponyta": ["fire", "fire", 50, 85, 55, 65, 65, 90], +"rapidash": ["fire", "fire", 65, 100, 70, 80, 80, 105], +"slowpoke": ["water", "psychic", 90, 65, 65, 40, 40, 15], +"slowbro": ["water", "psychic", 95, 75, 110, 100, 80, 30], +"magnemite": ["electric", "steel", 25, 35, 70, 95, 55, 45], +"magneton": ["electric", "steel", 50, 60, 95, 120, 70, 70], +"farfetch-d": ["normal", "flying", 52, 65, 55, 58, 62, 60], +"doduo": ["normal", "flying", 35, 85, 45, 35, 35, 75], +"dodrio": ["normal", "flying", 60, 110, 70, 60, 60, 100], +"seel": ["water", "water", 65, 45, 55, 45, 70, 45], +"dewgong": ["water", "ice", 90, 70, 80, 70, 95, 70], +"grimer": ["poison", "poison", 80, 80, 50, 40, 50, 25], +"muk": ["poison", "poison", 105, 105, 75, 65, 100, 50], +"shellder": ["water", "water", 30, 65, 100, 45, 25, 40], +"cloyster": ["water", "ice", 50, 95, 180, 85, 45, 70], +"gastly": ["ghost", "poison", 30, 35, 30, 100, 35, 80], +"haunter": ["ghost", "poison", 45, 50, 45, 115, 55, 95], +"gengar": ["ghost", "poison", 60, 65, 60, 130, 75, 110], +"onix": ["rock", "ground", 35, 45, 160, 30, 45, 70], +"drowzee": ["psychic", "psychic", 60, 48, 45, 43, 90, 42], +"hypno": ["psychic", "psychic", 85, 73, 70, 73, 115, 67], +"krabby": ["water", "water", 30, 105, 90, 25, 25, 50], +"kingler": ["water", "water", 55, 130, 115, 50, 50, 75], +"voltorb": ["electric", "electric", 40, 30, 50, 55, 55, 100], +"electrode": ["electric", "electric", 60, 50, 70, 80, 80, 140], +"exeggcute": ["grass", "psychic", 60, 40, 80, 60, 45, 40], +"exeggutor": ["grass", "psychic", 95, 95, 85, 125, 65, 55], +"cubone": ["ground", "ground", 50, 50, 95, 40, 50, 35], +"marowak": ["ground", "ground", 60, 80, 110, 50, 80, 45], +"hitmonlee": ["fighting", "fighting", 50, 120, 53, 35, 110, 87], +"hitmonchan": ["fighting", "fighting", 50, 105, 79, 35, 110, 76], +"lickitung": ["normal", "normal", 90, 55, 75, 60, 75, 30], +"koffing": ["poison", "poison", 40, 65, 95, 60, 45, 35], +"weezing": ["poison", "poison", 65, 90, 120, 85, 70, 60], +"rhyhorn": ["ground", "rock", 80, 85, 95, 30, 30, 25], +"rhydon": ["ground", "rock", 105, 130, 120, 45, 45, 40], +"chansey": ["normal", "normal", 250, 5, 5, 35, 105, 50], +"tangela": ["grass", "grass", 65, 55, 115, 100, 40, 60], +"kangaskhan": ["normal", "normal", 105, 95, 80, 40, 80, 90], +"horsea": ["water", "water", 30, 40, 70, 70, 25, 60], +"seadra": ["water", "water", 55, 65, 95, 95, 45, 85], +"goldeen": ["water", "water", 45, 67, 60, 35, 50, 63], +"seaking": ["water", "water", 80, 92, 65, 65, 80, 68], +"staryu": ["water", "water", 30, 45, 55, 70, 55, 85], +"starmie": ["water", "psychic", 60, 75, 85, 100, 85, 115], +"mr-mime": ["psychic", "psychic", 40, 45, 65, 100, 120, 90], +"scyther": ["bug", "flying", 70, 110, 80, 55, 80, 105], +"jynx": ["ice", "psychic", 65, 50, 35, 115, 95, 95], +"electabuzz": ["electric", "electric", 65, 83, 57, 95, 85, 105], +"magmar": ["fire", "fire", 65, 95, 57, 100, 85, 93], +"pinsir": ["bug", "bug", 65, 125, 100, 55, 70, 85], +"tauros": ["normal", "normal", 75, 100, 95, 40, 70, 110], +"magikarp": ["water", "water", 20, 10, 55, 15, 20, 80], +"gyarados": ["water", "flying", 95, 125, 79, 60, 100, 81], +"lapras": ["water", "ice", 130, 85, 80, 85, 95, 60], +"ditto": ["normal", "normal", 48, 48, 48, 48, 48, 48], +"eevee": ["normal", "normal", 55, 55, 50, 45, 65, 55], +"vaporeon": ["water", "water", 130, 65, 60, 110, 95, 65], +"jolteon": ["electric", "electric", 65, 65, 60, 110, 95, 130], +"flareon": ["fire", "fire", 65, 130, 60, 95, 110, 65], +"porygon": ["normal", "normal", 65, 60, 70, 85, 75, 40], +"omanyte": ["rock", "water", 35, 40, 100, 90, 55, 35], +"omastar": ["rock", "water", 70, 60, 125, 115, 70, 55], +"kabuto": ["rock", "water", 30, 80, 90, 55, 45, 55], +"kabutops": ["rock", "water", 60, 115, 105, 65, 70, 80], +"aerodactyl": ["rock", "flying", 80, 105, 65, 60, 75, 130], +"snorlax": ["normal", "normal", 160, 110, 65, 65, 110, 30], +"articuno": ["ice", "flying", 90, 85, 100, 95, 125, 85], +"zapdos": ["electric", "flying", 90, 90, 85, 125, 90, 100], +"moltres": ["fire", "flying", 90, 100, 90, 125, 85, 90], +"dratini": ["dragon", "dragon", 41, 64, 45, 50, 50, 50], +"dragonair": ["dragon", "dragon", 61, 84, 65, 70, 70, 70], +"dragonite": ["dragon", "flying", 91, 134, 95, 100, 100, 80], +"mewtwo": ["psychic", "psychic", 106, 110, 90, 154, 90, 130], +"mew": ["psychic", "psychic", 100, 100, 100, 100, 100, 100], +"chikorita": ["grass", "grass", 45, 49, 65, 49, 65, 45], +"bayleef": ["grass", "grass", 60, 62, 80, 63, 80, 60], +"meganium": ["grass", "grass", 80, 82, 100, 83, 100, 80], +"cyndaquil": ["fire", "fire", 39, 52, 43, 60, 50, 65], +"quilava": ["fire", "fire", 58, 64, 58, 80, 65, 80], +"typhlosion": ["fire", "fire", 78, 84, 78, 109, 85, 100], +"totodile": ["water", "water", 50, 65, 64, 44, 48, 43], +"croconaw": ["water", "water", 65, 80, 80, 59, 63, 58], +"feraligatr": ["water", "water", 85, 105, 100, 79, 83, 78], +"sentret": ["normal", "normal", 35, 46, 34, 35, 45, 20], +"furret": ["normal", "normal", 85, 76, 64, 45, 55, 90], +"hoothoot": ["normal", "flying", 60, 30, 30, 36, 56, 50], +"noctowl": ["normal", "flying", 100, 50, 50, 76, 96, 70], +"ledyba": ["bug", "flying", 40, 20, 30, 40, 80, 55], +"ledian": ["bug", "flying", 55, 35, 50, 55, 110, 85], +"spinarak": ["bug", "poison", 40, 60, 40, 40, 40, 30], +"ariados": ["bug", "poison", 70, 90, 70, 60, 60, 40], +"crobat": ["poison", "flying", 85, 90, 80, 70, 80, 130], +"chinchou": ["water", "electric", 75, 38, 38, 56, 56, 67], +"lanturn": ["water", "electric", 125, 58, 58, 76, 76, 67], +"pichu": ["electric", "electric", 20, 40, 15, 35, 35, 60], +"cleffa": ["normal", "normal", 50, 25, 28, 45, 55, 15], +"igglybuff": ["normal", "normal", 90, 30, 15, 40, 20, 15], +"togepi": ["normal", "normal", 35, 20, 65, 40, 65, 20], +"togetic": ["normal", "flying", 55, 40, 85, 80, 105, 40], +"natu": ["psychic", "flying", 40, 50, 45, 70, 45, 70], +"xatu": ["psychic", "flying", 65, 75, 70, 95, 70, 95], +"mareep": ["electric", "electric", 55, 40, 40, 65, 45, 35], +"flaaffy": ["electric", "electric", 70, 55, 55, 80, 60, 45], +"ampharos": ["electric", "electric", 90, 75, 75, 115, 90, 55], +"bellossom": ["grass", "grass", 75, 80, 85, 90, 100, 50], +"marill": ["water", "water", 70, 20, 50, 20, 50, 40], +"azumarill": ["water", "water", 100, 50, 80, 50, 80, 50], +"sudowoodo": ["rock", "rock", 70, 100, 115, 30, 65, 30], +"politoed": ["water", "water", 90, 75, 75, 90, 100, 70], +"hoppip": ["grass", "flying", 35, 35, 40, 35, 55, 50], +"skiploom": ["grass", "flying", 55, 45, 50, 45, 65, 80], +"jumpluff": ["grass", "flying", 75, 55, 70, 55, 85, 110], +"aipom": ["normal", "normal", 55, 70, 55, 40, 55, 85], +"sunkern": ["grass", "grass", 30, 30, 30, 30, 30, 30], +"sunflora": ["grass", "grass", 75, 75, 55, 105, 85, 30], +"yanma": ["bug", "flying", 65, 65, 45, 75, 45, 95], +"wooper": ["water", "ground", 55, 45, 45, 25, 25, 15], +"quagsire": ["water", "ground", 95, 85, 85, 65, 65, 35], +"espeon": ["psychic", "psychic", 65, 65, 60, 130, 95, 110], +"umbreon": ["dark", "dark", 95, 65, 110, 60, 130, 65], +"murkrow": ["dark", "flying", 60, 85, 42, 85, 42, 91], +"slowking": ["water", "psychic", 95, 75, 80, 100, 110, 30], +"misdreavus": ["ghost", "ghost", 60, 60, 60, 85, 85, 85], +"unown": ["psychic", "psychic", 48, 72, 48, 72, 48, 48], +"wobbuffet": ["psychic", "psychic", 190, 33, 58, 33, 58, 33], +"girafarig": ["normal", "psychic", 70, 80, 65, 90, 65, 85], +"pineco": ["bug", "bug", 50, 65, 90, 35, 35, 15], +"forretress": ["bug", "steel", 75, 90, 140, 60, 60, 40], +"dunsparce": ["normal", "normal", 100, 70, 70, 65, 65, 45], +"gligar": ["ground", "flying", 65, 75, 105, 35, 65, 85], +"steelix": ["steel", "ground", 75, 85, 200, 55, 65, 30], +"snubbull": ["normal", "normal", 60, 80, 50, 40, 40, 30], +"granbull": ["normal", "normal", 90, 120, 75, 60, 60, 45], +"qwilfish": ["water", "poison", 65, 95, 75, 55, 55, 85], +"scizor": ["bug", "steel", 70, 130, 100, 55, 80, 65], +"shuckle": ["bug", "rock", 20, 10, 230, 10, 230, 5], +"heracross": ["bug", "fighting", 80, 125, 75, 40, 95, 85], +"sneasel": ["dark", "ice", 55, 95, 55, 35, 75, 115], +"teddiursa": ["normal", "normal", 60, 80, 50, 50, 50, 40], +"ursaring": ["normal", "normal", 90, 130, 75, 75, 75, 55], +"slugma": ["fire", "fire", 40, 40, 40, 70, 40, 20], +"magcargo": ["fire", "rock", 50, 50, 120, 80, 80, 30], +"swinub": ["ice", "ground", 50, 50, 40, 30, 30, 50], +"piloswine": ["ice", "ground", 100, 100, 80, 60, 60, 50], +"corsola": ["water", "rock", 55, 55, 85, 65, 85, 35], +"remoraid": ["water", "water", 35, 65, 35, 65, 35, 65], +"octillery": ["water", "water", 75, 105, 75, 105, 75, 45], +"delibird": ["ice", "flying", 45, 55, 45, 65, 45, 75], +"mantine": ["water", "flying", 65, 40, 70, 80, 140, 70], +"skarmory": ["steel", "flying", 65, 80, 140, 40, 70, 70], +"houndour": ["dark", "fire", 45, 60, 30, 80, 50, 65], +"houndoom": ["dark", "fire", 75, 90, 50, 110, 80, 95], +"kingdra": ["water", "dragon", 75, 95, 95, 95, 95, 85], +"phanpy": ["ground", "ground", 90, 60, 60, 40, 40, 40], +"donphan": ["ground", "ground", 90, 120, 120, 60, 60, 50], +"porygon2": ["normal", "normal", 85, 80, 90, 105, 95, 60], +"stantler": ["normal", "normal", 73, 95, 62, 85, 65, 85], +"smeargle": ["normal", "normal", 55, 20, 35, 20, 45, 75], +"tyrogue": ["fighting", "fighting", 35, 35, 35, 35, 35, 35], +"hitmontop": ["fighting", "fighting", 50, 95, 95, 35, 110, 70], +"smoochum": ["ice", "psychic", 45, 30, 15, 85, 65, 65], +"elekid": ["electric", "electric", 45, 63, 37, 65, 55, 95], +"magby": ["fire", "fire", 45, 75, 37, 70, 55, 83], +"miltank": ["normal", "normal", 95, 80, 105, 40, 70, 100], +"blissey": ["normal", "normal", 255, 10, 10, 75, 135, 55], +"raikou": ["electric", "electric", 90, 85, 75, 115, 100, 115], +"entei": ["fire", "fire", 115, 115, 85, 90, 75, 100], +"suicune": ["water", "water", 100, 75, 115, 90, 115, 85], +"larvitar": ["rock", "ground", 50, 64, 50, 45, 50, 41], +"pupitar": ["rock", "ground", 70, 84, 70, 65, 70, 51], +"tyranitar": ["rock", "dark", 100, 134, 110, 95, 100, 61], +"lugia": ["psychic", "flying", 106, 90, 130, 90, 154, 110], +"ho-oh": ["fire", "flying", 106, 130, 90, 110, 154, 90], +"celebi": ["psychic", "grass", 100, 100, 100, 100, 100, 100], +"treecko": ["grass", "grass", 40, 45, 35, 65, 55, 70], +"grovyle": ["grass", "grass", 50, 65, 45, 85, 65, 95], +"sceptile": ["grass", "grass", 70, 85, 65, 105, 85, 120], +"torchic": ["fire", "fire", 45, 60, 40, 70, 50, 45], +"combusken": ["fire", "fighting", 60, 85, 60, 85, 60, 55], +"blaziken": ["fire", "fighting", 80, 120, 70, 110, 70, 80], +"mudkip": ["water", "water", 50, 70, 50, 50, 50, 40], +"marshtomp": ["water", "ground", 70, 85, 70, 60, 70, 50], +"swampert": ["water", "ground", 100, 110, 90, 85, 90, 60], +"poochyena": ["dark", "dark", 35, 55, 35, 30, 30, 35], +"mightyena": ["dark", "dark", 70, 90, 70, 60, 60, 70], +"zigzagoon": ["normal", "normal", 38, 30, 41, 30, 41, 60], +"linoone": ["normal", "normal", 78, 70, 61, 50, 61, 100], +"wurmple": ["bug", "bug", 45, 45, 35, 20, 30, 20], +"silcoon": ["bug", "bug", 50, 35, 55, 25, 25, 15], +"beautifly": ["bug", "flying", 60, 70, 50, 90, 50, 65], +"cascoon": ["bug", "bug", 50, 35, 55, 25, 25, 15], +"dustox": ["bug", "poison", 60, 50, 70, 50, 90, 65], +"lotad": ["water", "grass", 40, 30, 30, 40, 50, 30], +"lombre": ["water", "grass", 60, 50, 50, 60, 70, 50], +"ludicolo": ["water", "grass", 80, 70, 70, 90, 100, 70], +"seedot": ["grass", "grass", 40, 40, 50, 30, 30, 30], +"nuzleaf": ["grass", "dark", 70, 70, 40, 60, 40, 60], +"shiftry": ["grass", "dark", 90, 100, 60, 90, 60, 80], +"nincada": ["bug", "ground", 31, 45, 90, 30, 30, 40], +"ninjask": ["bug", "flying", 61, 90, 45, 50, 50, 160], +"shedinja": ["bug", "ghost", 1, 90, 45, 30, 30, 40], +"taillow": ["normal", "flying", 40, 55, 30, 30, 30, 85], +"swellow": ["normal", "flying", 60, 85, 60, 50, 50, 125], +"shroomish": ["grass", "grass", 60, 40, 60, 40, 60, 35], +"breloom": ["grass", "fighting", 60, 130, 80, 60, 60, 70], +"spinda": ["normal", "normal", 60, 60, 60, 60, 60, 60], +"wingull": ["water", "flying", 40, 30, 30, 55, 30, 85], +"pelipper": ["water", "flying", 60, 50, 100, 85, 70, 65], +"surskit": ["bug", "water", 40, 30, 32, 50, 52, 65], +"masquerain": ["bug", "flying", 70, 60, 62, 80, 82, 60], +"wailmer": ["water", "water", 130, 70, 35, 70, 35, 60], +"wailord": ["water", "water", 170, 90, 45, 90, 45, 60], +"skitty": ["normal", "normal", 50, 45, 45, 35, 35, 50], +"delcatty": ["normal", "normal", 70, 65, 65, 55, 55, 70], +"kecleon": ["normal", "normal", 60, 90, 70, 60, 120, 40], +"baltoy": ["ground", "psychic", 40, 40, 55, 40, 70, 55], +"claydol": ["ground", "psychic", 60, 70, 105, 70, 120, 75], +"nosepass": ["rock", "rock", 30, 45, 135, 45, 90, 30], +"torkoal": ["fire", "fire", 70, 85, 140, 85, 70, 20], +"sableye": ["dark", "ghost", 50, 75, 75, 65, 65, 50], +"barboach": ["water", "ground", 50, 48, 43, 46, 41, 60], +"whiscash": ["water", "ground", 110, 78, 73, 76, 71, 60], +"luvdisc": ["water", "water", 43, 30, 55, 40, 65, 97], +"corphish": ["water", "water", 43, 80, 65, 50, 35, 35], +"crawdaunt": ["water", "dark", 63, 120, 85, 90, 55, 55], +"feebas": ["water", "water", 20, 15, 20, 10, 55, 80], +"milotic": ["water", "water", 95, 60, 79, 100, 125, 81], +"carvanha": ["water", "dark", 45, 90, 20, 65, 20, 65], +"sharpedo": ["water", "dark", 70, 120, 40, 95, 40, 95], +"trapinch": ["ground", "ground", 45, 100, 45, 45, 45, 10], +"vibrava": ["ground", "dragon", 50, 70, 50, 50, 50, 70], +"flygon": ["ground", "dragon", 80, 100, 80, 80, 80, 100], +"makuhita": ["fighting", "fighting", 72, 60, 30, 20, 30, 25], +"hariyama": ["fighting", "fighting", 144, 120, 60, 40, 60, 50], +"electrike": ["electric", "electric", 40, 45, 40, 65, 40, 65], +"manectric": ["electric", "electric", 70, 75, 60, 105, 60, 105], +"numel": ["fire", "ground", 60, 60, 40, 65, 45, 35], +"camerupt": ["fire", "ground", 70, 100, 70, 105, 75, 40], +"spheal": ["ice", "water", 70, 40, 50, 55, 50, 25], +"sealeo": ["ice", "water", 90, 60, 70, 75, 70, 45], +"walrein": ["ice", "water", 110, 80, 90, 95, 90, 65], +"cacnea": ["grass", "grass", 50, 85, 40, 85, 40, 35], +"cacturne": ["grass", "dark", 70, 115, 60, 115, 60, 55], +"snorunt": ["ice", "ice", 50, 50, 50, 50, 50, 50], +"glalie": ["ice", "ice", 80, 80, 80, 80, 80, 80], +"lunatone": ["rock", "psychic", 70, 55, 65, 95, 85, 70], +"solrock": ["rock", "psychic", 70, 95, 85, 55, 65, 70], +"azurill": ["normal", "normal", 50, 20, 40, 20, 40, 20], +"spoink": ["psychic", "psychic", 60, 25, 35, 70, 80, 60], +"grumpig": ["psychic", "psychic", 80, 45, 65, 90, 110, 80], +"plusle": ["electric", "electric", 60, 50, 40, 85, 75, 95], +"minun": ["electric", "electric", 60, 40, 50, 75, 85, 95], +"mawile": ["steel", "steel", 50, 85, 85, 55, 55, 50], +"meditite": ["fighting", "psychic", 30, 40, 55, 40, 55, 60], +"medicham": ["fighting", "psychic", 60, 60, 75, 60, 75, 80], +"swablu": ["normal", "flying", 45, 40, 60, 40, 75, 50], +"altaria": ["dragon", "flying", 75, 70, 90, 70, 105, 80], +"wynaut": ["psychic", "psychic", 95, 23, 48, 23, 48, 23], +"duskull": ["ghost", "ghost", 20, 40, 90, 30, 90, 25], +"dusclops": ["ghost", "ghost", 40, 70, 130, 60, 130, 25], +"roselia": ["grass", "poison", 50, 60, 45, 100, 80, 65], +"slakoth": ["normal", "normal", 60, 60, 60, 35, 35, 30], +"vigoroth": ["normal", "normal", 80, 80, 80, 55, 55, 90], +"slaking": ["normal", "normal", 150, 160, 100, 95, 65, 100], +"gulpin": ["poison", "poison", 70, 43, 53, 43, 53, 40], +"swalot": ["poison", "poison", 100, 73, 83, 73, 83, 55], +"tropius": ["grass", "flying", 99, 68, 83, 72, 87, 51], +"whismur": ["normal", "normal", 64, 51, 23, 51, 23, 28], +"loudred": ["normal", "normal", 84, 71, 43, 71, 43, 48], +"exploud": ["normal", "normal", 104, 91, 63, 91, 63, 68], +"clamperl": ["water", "water", 35, 64, 85, 74, 55, 32], +"huntail": ["water", "water", 55, 104, 105, 94, 75, 52], +"gorebyss": ["water", "water", 55, 84, 105, 114, 75, 52], +"absol": ["dark", "dark", 65, 130, 60, 75, 60, 75], +"shuppet": ["ghost", "ghost", 44, 75, 35, 63, 33, 45], +"banette": ["ghost", "ghost", 64, 115, 65, 83, 63, 65], +"seviper": ["poison", "poison", 73, 100, 60, 100, 60, 65], +"zangoose": ["normal", "normal", 73, 115, 60, 60, 60, 90], +"relicanth": ["water", "rock", 100, 90, 130, 45, 65, 55], +"aron": ["steel", "rock", 50, 70, 100, 40, 40, 30], +"lairon": ["steel", "rock", 60, 90, 140, 50, 50, 40], +"aggron": ["steel", "rock", 70, 110, 180, 60, 60, 50], +"castform": ["normal", "normal", 70, 70, 70, 70, 70, 70], +"volbeat": ["bug", "bug", 65, 73, 55, 47, 75, 85], +"illumise": ["bug", "bug", 65, 47, 55, 73, 75, 85], +"lileep": ["rock", "grass", 66, 41, 77, 61, 87, 23], +"cradily": ["rock", "grass", 86, 81, 97, 81, 107, 43], +"anorith": ["rock", "bug", 45, 95, 50, 40, 50, 75], +"armaldo": ["rock", "bug", 75, 125, 100, 70, 80, 45], +"ralts": ["psychic", "psychic", 28, 25, 25, 45, 35, 40], +"kirlia": ["psychic", "psychic", 38, 35, 35, 65, 55, 50], +"gardevoir": ["psychic", "psychic", 68, 65, 65, 125, 115, 80], +"bagon": ["dragon", "dragon", 45, 75, 60, 40, 30, 50], +"shelgon": ["dragon", "dragon", 65, 95, 100, 60, 50, 50], +"salamence": ["dragon", "flying", 95, 135, 80, 110, 80, 100], +"beldum": ["steel", "psychic", 40, 55, 80, 35, 60, 30], +"metang": ["steel", "psychic", 60, 75, 100, 55, 80, 50], +"metagross": ["steel", "psychic", 80, 135, 130, 95, 90, 70], +"regirock": ["rock", "rock", 80, 100, 200, 50, 100, 50], +"regice": ["ice", "ice", 80, 50, 100, 100, 200, 50], +"registeel": ["steel", "steel", 80, 75, 150, 75, 150, 50], +"kyogre": ["water", "water", 100, 100, 90, 150, 140, 90], +"groudon": ["ground", "ground", 100, 150, 140, 100, 90, 90], +"rayquaza": ["dragon", "flying", 105, 150, 90, 150, 90, 95], +"latias": ["dragon", "psychic", 80, 80, 90, 110, 130, 110], +"latios": ["dragon", "psychic", 80, 90, 80, 130, 110, 110], +"jirachi": ["steel", "psychic", 100, 100, 100, 100, 100, 100], +"deoxys": ["psychic", "psychic", 50, 150, 50, 150, 50, 150], +"chimecho": ["psychic", "psychic", 65, 50, 70, 95, 80, 65] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json new file mode 100644 index 0000000000..3877817c87 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json @@ -0,0 +1,641 @@ +{ +"TRAINER_YOUNGSTER_BEN": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 11, 0, 8, ["tackle", "tail-whip", "quick-attack"]], ["ekans", 11, 0, 12, ["wrap", "leer", "poison-sting"]]]}, +"TRAINER_YOUNGSTER_CALVIN": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 14, 0, 17, ["peck", "growl", "leer", "fury-attack"]]]}, +"TRAINER_YOUNGSTER_JOSH": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 10, 0, 10, ["tackle", "tail-whip", "quick-attack"]], ["rattata", 10, 0, 9, ["tackle", "tail-whip", "quick-attack"]], ["zubat", 10, 0, 10, ["leech-life", "astonish"]]]}, +"TRAINER_YOUNGSTER_TIMMY": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 14, 0, 6, ["scratch", "defense-curl", "sand-attack"]], ["ekans", 14, 0, 21, ["wrap", "leer", "poison-sting", "bite"]]]}, +"TRAINER_YOUNGSTER_JOEY": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 15, 0, 3, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["spearow", 15, 0, 16, ["peck", "growl", "leer", "fury-attack"]]]}, +"TRAINER_YOUNGSTER_DAN": {"ai": ["check-bad-move"], "items": [], "party": [["slowpoke", 17, 0, 22, ["tackle", "growl", "water-gun", "confusion"]]]}, +"TRAINER_YOUNGSTER_CHAD": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 14, 0, 1, ["wrap", "leer", "poison-sting", "bite"]], ["sandshrew", 14, 0, 21, ["scratch", "defense-curl", "sand-attack"]]]}, +"TRAINER_YOUNGSTER_TYLER": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 21, 0, 19, ["focus-energy", "double-kick", "poison-sting", "horn-attack"]]]}, +"TRAINER_YOUNGSTER_EDDIE": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 21, 0, 8, ["leer", "poison-sting", "bite", "glare"]]]}, +"TRAINER_YOUNGSTER_DILLON": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 19, 0, 13, ["scratch", "defense-curl", "sand-attack", "poison-sting"]], ["zubat", 19, 0, 5, ["leech-life", "astonish", "supersonic", "bite"]]]}, +"TRAINER_YOUNGSTER_YASU": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 17, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["rattata", 17, 0, 2, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["raticate", 17, 0, 2, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]]]}, +"TRAINER_YOUNGSTER_DAVE": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 18, 0, 15, ["peck", "focus-energy", "double-kick", "poison-sting"]], ["nidorino", 18, 0, 12, ["peck", "focus-energy", "double-kick", "poison-sting"]]]}, +"TRAINER_YOUNGSTER_BEN_2": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 17, 20, 8, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["ekans", 17, 20, 12, ["wrap", "leer", "poison-sting", "bite"]]]}, +"TRAINER_BUG_CATCHER_RICK": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 6, 0, 16, ["poison-sting", "string-shot"]], ["caterpie", 6, 0, 16, ["tackle", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_DOUG": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 7, 0, 2, ["poison-sting", "string-shot"]], ["kakuna", 7, 0, 23, ["harden"]], ["weedle", 7, 0, 14, ["poison-sting", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_SAMMY": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 9, 0, 12, ["poison-sting", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_COLTON": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 10, 0, 21, ["tackle", "string-shot"]], ["weedle", 10, 0, 11, ["poison-sting", "string-shot"]], ["caterpie", 10, 0, 21, ["tackle", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_GREG": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 9, 0, 17, ["poison-sting", "string-shot"]], ["kakuna", 9, 0, 3, ["harden"]], ["caterpie", 9, 0, 4, ["tackle", "string-shot"]], ["metapod", 9, 0, 21, ["harden"]]]}, +"TRAINER_BUG_CATCHER_JAMES": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 11, 0, 19, ["tackle", "string-shot"]], ["metapod", 11, 0, 18, ["harden"]]]}, +"TRAINER_BUG_CATCHER_KENT": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 11, 0, 20, ["poison-sting", "string-shot"]], ["kakuna", 11, 0, 9, ["harden"]]]}, +"TRAINER_BUG_CATCHER_ROBBY": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 10, 0, 3, ["tackle", "string-shot"]], ["metapod", 10, 0, 11, ["harden"]], ["caterpie", 10, 0, 3, ["tackle", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_CALE": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 10, 0, 16, ["tackle", "string-shot"]], ["weedle", 10, 0, 1, ["poison-sting", "string-shot"]], ["metapod", 10, 0, 22, ["harden"]], ["kakuna", 10, 0, 12, ["harden"]]]}, +"TRAINER_BUG_CATCHER_KEIGO": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 16, 0, 18, ["poison-sting", "string-shot"]], ["caterpie", 16, 0, 20, ["tackle", "string-shot"]], ["weedle", 16, 0, 2, ["poison-sting", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_ELIJAH": {"ai": ["check-bad-move"], "items": [], "party": [["butterfree", 20, 0, 7, ["poison-powder", "stun-spore", "sleep-powder", "supersonic"]]]}, +"TRAINER_BUG_CATCHER_2": {"ai": ["check-bad-move"], "items": [], "party": [["metapod", 18, 0, 17, ["harden"]], ["caterpie", 18, 0, 7, ["tackle", "string-shot"]], ["venonat", 18, 0, 15, ["disable", "foresight", "supersonic", "confusion"]]]}, +"TRAINER_BUG_CATCHER_BRENT": {"ai": ["check-bad-move"], "items": [], "party": [["beedrill", 19, 0, 0, ["fury-attack", "focus-energy"]], ["beedrill", 19, 0, 14, ["fury-attack", "focus-energy"]]]}, +"TRAINER_BUG_CATCHER_CONNER": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 20, 0, 11, ["tackle", "string-shot"]], ["weedle", 20, 0, 16, ["poison-sting", "string-shot"]], ["venonat", 20, 0, 9, ["foresight", "supersonic", "confusion", "poison-powder"]]]}, +"TRAINER_LASS_JANICE": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 9, 0, 10, ["tackle", "sand-attack", "gust"]], ["pidgey", 9, 0, 0, ["tackle", "sand-attack", "gust"]]]}, +"TRAINER_LASS_SALLY": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 10, 0, 12, ["tackle", "tail-whip", "quick-attack"]], ["nidoran-f", 10, 0, 10, ["growl", "scratch", "tail-whip"]]]}, +"TRAINER_LASS_ROBIN": {"ai": ["check-bad-move"], "items": [], "party": [["jigglypuff", 14, 0, 22, ["sing", "defense-curl", "pound", "disable"]]]}, +"TRAINER_LASS_CRISSY": {"ai": ["check-bad-move"], "items": [], "party": [["paras", 31, 0, 9, ["poison-powder", "leech-life", "spore", "slash"]], ["paras", 31, 0, 23, ["poison-powder", "leech-life", "spore", "slash"]], ["parasect", 31, 0, 3, ["stun-spore", "poison-powder", "leech-life", "spore"]]]}, +"TRAINER_LASS_MIRIAM": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 11, 0, 19, ["absorb", "sweet-scent"]], ["bellsprout", 11, 0, 18, ["vine-whip", "growth", "wrap"]]]}, +"TRAINER_LASS_IRIS": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 14, 0, 16, ["growl", "encore", "sing", "double-slap"]]]}, +"TRAINER_LASS_RELI": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 16, 0, 21, ["leer", "peck", "focus-energy", "double-kick"]], ["nidoran-f", 16, 0, 3, ["growl", "scratch", "tail-whip", "double-kick"]]]}, +"TRAINER_LASS_ALI": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 12, 0, 17, ["tackle", "sand-attack", "gust"]], ["oddish", 12, 0, 22, ["absorb", "sweet-scent"]], ["bellsprout", 12, 0, 2, ["vine-whip", "growth", "wrap"]]]}, +"TRAINER_LASS_2": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 15, 0, 18, ["leer", "peck", "focus-energy", "double-kick"]], ["nidoran-f", 15, 0, 22, ["growl", "scratch", "tail-whip", "double-kick"]]]}, +"TRAINER_LASS_HALEY": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 13, 0, 6, ["absorb", "sweet-scent"]], ["pidgey", 13, 0, 9, ["tackle", "sand-attack", "gust", "quick-attack"]], ["oddish", 13, 0, 20, ["absorb", "sweet-scent"]]]}, +"TRAINER_LASS_ANN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 18, 0, 9, ["tackle", "sand-attack", "gust", "quick-attack"]], ["nidoran-f", 18, 0, 10, ["scratch", "tail-whip", "double-kick", "poison-sting"]]]}, +"TRAINER_LASS_DAWN": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 18, 0, 9, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["pikachu", 18, 0, 1, ["tail-whip", "thunder-wave", "quick-attack", "double-team"]]]}, +"TRAINER_LASS_PAIGE": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-f", 23, 0, 7, ["double-kick", "poison-sting", "bite", "helping-hand"]], ["nidorina", 23, 0, 22, ["tail-whip", "double-kick", "poison-sting", "bite"]]]}, +"TRAINER_LASS_ANDREA": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 24, 0, 24, ["scratch", "growl", "bite", "pay-day"]], ["meowth", 24, 0, 3, ["scratch", "growl", "bite", "pay-day"]], ["meowth", 24, 0, 7, ["scratch", "growl", "bite", "pay-day"]]]}, +"TRAINER_LASS_MEGAN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 19, 0, 7, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["rattata", 19, 0, 0, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["nidoran-m", 19, 0, 18, ["peck", "focus-energy", "double-kick", "poison-sting"]], ["meowth", 19, 0, 13, ["scratch", "growl", "bite", "pay-day"]], ["pikachu", 19, 0, 9, ["tail-whip", "thunder-wave", "quick-attack", "double-team"]]]}, +"TRAINER_LASS_JULIA": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 22, 0, 20, ["sing", "double-slap", "follow-me", "minimize"]], ["clefairy", 22, 0, 20, ["sing", "double-slap", "follow-me", "minimize"]]]}, +"TRAINER_LASS_KAY": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 23, 0, 15, ["sleep-powder", "poison-powder", "stun-spore", "acid"]], ["weepinbell", 23, 0, 13, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]]]}, +"TRAINER_LASS_LISA": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 23, 0, 5, ["poison-powder", "stun-spore", "sleep-powder", "acid"]], ["gloom", 23, 0, 17, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]]]}, +"TRAINER_SAILOR_EDMOND": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 18, 0, 19, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["shellder", 18, 0, 21, ["tackle", "withdraw", "icicle-spear", "supersonic"]]]}, +"TRAINER_SAILOR_TREVOR": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 17, 0, 2, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["tentacool", 17, 0, 10, ["poison-sting", "supersonic", "constrict"]]]}, +"TRAINER_SAILOR_LEONARD": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 21, 0, 13, ["tackle", "withdraw", "icicle-spear", "supersonic"]]]}, +"TRAINER_SAILOR_DUNCAN": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 17, 0, 16, ["bubble", "smokescreen", "leer"]], ["shellder", 17, 0, 5, ["tackle", "withdraw", "icicle-spear", "supersonic"]], ["tentacool", 17, 0, 17, ["poison-sting", "supersonic", "constrict"]]]}, +"TRAINER_SAILOR_HUEY": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 18, 0, 3, ["poison-sting", "supersonic", "constrict"]], ["staryu", 18, 0, 16, ["harden", "water-gun", "rapid-spin", "recover"]]]}, +"TRAINER_SAILOR_DYLAN": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 17, 0, 19, ["bubble", "smokescreen", "leer"]], ["horsea", 17, 0, 2, ["bubble", "smokescreen", "leer"]], ["horsea", 17, 0, 10, ["bubble", "smokescreen", "leer"]]]}, +"TRAINER_SAILOR_PHILLIP": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 20, 0, 22, ["leer", "focus-energy", "karate-chop", "seismic-toss"]]]}, +"TRAINER_SAILOR_DWAYNE": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 21, 0, 15, ["thunder-wave", "quick-attack", "double-team", "slam"]], ["pikachu", 21, 0, 19, ["thunder-wave", "quick-attack", "double-team", "slam"]]]}, +"TRAINER_CAMPER_LIAM": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 10, 0, 13, ["tackle", "defense-curl"]], ["sandshrew", 11, 0, 22, ["scratch", "defense-curl", "sand-attack"]]]}, +"TRAINER_CAMPER_SHANE": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 14, 0, 21, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["ekans", 14, 0, 13, ["wrap", "leer", "poison-sting", "bite"]]]}, +"TRAINER_CAMPER_ETHAN": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 18, 0, 14, ["leer", "low-kick", "karate-chop", "fury-swipes"]]]}, +"TRAINER_CAMPER_RICKY": {"ai": ["check-bad-move"], "items": [], "party": [["squirtle", 20, 0, 16, ["bubble", "withdraw", "water-gun", "bite"]]]}, +"TRAINER_CAMPER_JEFF": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 16, 0, 6, ["peck", "growl", "leer", "fury-attack"]], ["raticate", 16, 0, 22, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]]]}, +"TRAINER_CAMPER_CHRIS": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 21, 0, 4, ["roar", "ember", "leer", "odor-sleuth"]], ["charmander", 21, 0, 21, ["growl", "ember", "metal-claw", "smokescreen"]]]}, +"TRAINER_CAMPER_DREW": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 19, 0, 23, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["sandshrew", 19, 0, 22, ["scratch", "defense-curl", "sand-attack", "poison-sting"]], ["ekans", 19, 0, 16, ["wrap", "leer", "poison-sting", "bite"]], ["sandshrew", 19, 0, 15, ["scratch", "defense-curl", "sand-attack", "poison-sting"]]]}, +"TRAINER_PICNICKER_DIANA": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 19, 0, 8, ["tail-whip", "water-sport", "supersonic", "horn-attack"]]]}, +"TRAINER_PICNICKER_NANCY": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 16, 0, 15, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["pikachu", 16, 0, 13, ["tail-whip", "thunder-wave", "quick-attack", "double-team"]]]}, +"TRAINER_PICNICKER_ISABELLE": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 16, 0, 5, ["tackle", "sand-attack", "gust", "quick-attack"]], ["pidgey", 16, 0, 15, ["tackle", "sand-attack", "gust", "quick-attack"]], ["pidgey", 16, 0, 0, ["tackle", "sand-attack", "gust", "quick-attack"]]]}, +"TRAINER_PICNICKER_KELSEY": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 15, 0, 1, ["leer", "peck", "focus-energy", "double-kick"]], ["nidoran-f", 15, 0, 13, ["growl", "scratch", "tail-whip", "double-kick"]]]}, +"TRAINER_PICNICKER_ALICIA": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 18, 0, 1, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bellsprout", 18, 0, 7, ["growth", "wrap", "sleep-powder", "poison-powder"]], ["oddish", 18, 0, 13, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bellsprout", 18, 0, 19, ["growth", "wrap", "sleep-powder", "poison-powder"]]]}, +"TRAINER_PICNICKER_CAITLIN": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 23, 0, 15, ["scratch", "growl", "bite", "pay-day"]]]}, +"TRAINER_PICNICKER_HEIDI": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 20, 0, 11, ["thunder-wave", "quick-attack", "double-team", "slam"]], ["clefairy", 20, 0, 3, ["encore", "sing", "double-slap", "follow-me"]]]}, +"TRAINER_PICNICKER_CAROL": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 21, 0, 11, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["pidgeotto", 21, 0, 20, ["sand-attack", "gust", "quick-attack", "whirlwind"]]]}, +"TRAINER_PICNICKER_SOFIA": {"ai": ["check-bad-move"], "items": [], "party": [["jigglypuff", 21, 0, 24, ["defense-curl", "pound", "disable", "rollout"]], ["pidgey", 21, 0, 21, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["meowth", 21, 0, 1, ["scratch", "growl", "bite", "pay-day"]]]}, +"TRAINER_PICNICKER_MARTHA": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 22, 0, 7, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bulbasaur", 22, 0, 20, ["vine-whip", "poison-powder", "sleep-powder", "razor-leaf"]]]}, +"TRAINER_PICNICKER_TINA": {"ai": ["check-bad-move"], "items": [], "party": [["bulbasaur", 24, 0, 24, ["vine-whip", "poison-powder", "sleep-powder", "razor-leaf"]], ["ivysaur", 24, 0, 4, ["vine-whip", "poison-powder", "sleep-powder", "razor-leaf"]]]}, +"TRAINER_PICNICKER_HANNAH": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 24, 0, 9, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["meowth", 24, 0, 6, ["scratch", "growl", "bite", "pay-day"]], ["rattata", 24, 0, 1, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["pikachu", 24, 0, 24, ["thunder-wave", "quick-attack", "double-team", "slam"]], ["meowth", 24, 0, 21, ["scratch", "growl", "bite", "pay-day"]]]}, +"TRAINER_POKEMANIAC_MARK": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 29, 30, 6, ["stomp", "fury-attack", "scary-face", "rock-blast"]], ["lickitung", 29, 30, 8, ["defense-curl", "knock-off", "stomp", "wrap"]]]}, +"TRAINER_POKEMANIAC_HERMAN": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 20, 30, 17, ["tail-whip", "bone-club", "headbutt", "leer"]], ["slowpoke", 20, 30, 16, ["tackle", "growl", "water-gun", "confusion"]]]}, +"TRAINER_POKEMANIAC_COOPER": {"ai": ["check-bad-move"], "items": [], "party": [["slowpoke", 20, 30, 13, ["tackle", "growl", "water-gun", "confusion"]], ["slowpoke", 20, 30, 15, ["tackle", "growl", "water-gun", "confusion"]], ["slowpoke", 20, 30, 17, ["tackle", "growl", "water-gun", "confusion"]]]}, +"TRAINER_POKEMANIAC_STEVE": {"ai": ["check-bad-move"], "items": [], "party": [["charmander", 22, 30, 12, ["growl", "ember", "metal-claw", "smokescreen"]], ["cubone", 22, 30, 24, ["bone-club", "headbutt", "leer", "focus-energy"]]]}, +"TRAINER_POKEMANIAC_WINSTON": {"ai": ["check-bad-move"], "items": [], "party": [["slowpoke", 25, 30, 6, ["growl", "water-gun", "confusion", "disable"]]]}, +"TRAINER_POKEMANIAC_DAWSON": {"ai": ["check-bad-move"], "items": [], "party": [["charmeleon", 40, 30, 12, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]], ["lapras", 40, 30, 12, ["confuse-ray", "perish-song", "ice-beam", "rain-dance"]], ["lickitung", 40, 30, 19, ["stomp", "wrap", "disable", "slam"]]]}, +"TRAINER_POKEMANIAC_ASHTON": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 23, 30, 0, ["bone-club", "headbutt", "leer", "focus-energy"]], ["slowpoke", 23, 30, 7, ["tackle", "growl", "water-gun", "confusion"]]]}, +"TRAINER_SUPER_NERD_JOVAN": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 11, 0, 4, ["metal-sound", "tackle", "thunder-shock", "supersonic"]], ["voltorb", 11, 0, 17, ["charge", "tackle", "screech"]]]}, +"TRAINER_SUPER_NERD_MIGUEL": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 12, 0, 0, ["poison-gas", "pound", "harden", "disable"]], ["voltorb", 12, 0, 9, ["charge", "tackle", "screech"]], ["koffing", 12, 0, 2, ["poison-gas", "tackle", "smog"]]]}, +"TRAINER_SUPER_NERD_AIDAN": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 20, 0, 1, ["sonic-boom", "screech", "tackle", "charge"]], ["koffing", 20, 0, 0, ["sludge", "smog", "tackle", "poison-gas"]], ["voltorb", 20, 0, 15, ["sonic-boom", "screech", "tackle", "charge"]], ["magnemite", 20, 0, 10, ["sonic-boom", "supersonic", "thunder-shock", "tackle"]]]}, +"TRAINER_SUPER_NERD_GLENN": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 22, 0, 19, ["harden", "disable", "sludge", "minimize"]], ["muk", 22, 0, 4, ["harden", "disable", "sludge", "minimize"]], ["grimer", 22, 0, 12, ["harden", "disable", "sludge", "minimize"]]]}, +"TRAINER_SUPER_NERD_LESLIE": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 26, 0, 24, ["sludge", "smokescreen", "smog", "self-destruct"]]]}, +"TRAINER_SUPER_NERD_1": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 22, 0, 6, ["tackle", "smog", "self-destruct", "sludge"]], ["magnemite", 22, 0, 22, ["thunder-shock", "supersonic", "sonic-boom", "thunder-wave"]], ["weezing", 22, 0, 18, ["tackle", "smog", "self-destruct", "sludge"]]]}, +"TRAINER_SUPER_NERD_2": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 20, 0, 2, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["magnemite", 20, 0, 18, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["koffing", 20, 0, 13, ["poison-gas", "tackle", "smog", "self-destruct"]], ["magnemite", 20, 0, 4, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]]]}, +"TRAINER_SUPER_NERD_3": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 24, 0, 2, ["thunder-shock", "supersonic", "sonic-boom", "thunder-wave"]], ["voltorb", 24, 0, 13, ["tackle", "screech", "sonic-boom", "spark"]]]}, +"TRAINER_SUPER_NERD_ERIK": {"ai": ["check-bad-move"], "items": [], "party": [["vulpix", 36, 0, 3, ["confuse-ray", "imprison", "flamethrower", "safeguard"]], ["vulpix", 36, 0, 20, ["confuse-ray", "imprison", "flamethrower", "safeguard"]], ["ninetales", 36, 0, 5, ["ember", "quick-attack", "confuse-ray", "safeguard"]]]}, +"TRAINER_SUPER_NERD_AVERY": {"ai": ["check-bad-move"], "items": [], "party": [["ponyta", 34, 0, 9, ["ember", "stomp", "fire-spin", "take-down"]], ["charmander", 34, 0, 10, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]], ["vulpix", 34, 0, 11, ["confuse-ray", "imprison", "flamethrower", "safeguard"]], ["growlithe", 34, 0, 13, ["leer", "odor-sleuth", "take-down", "flame-wheel"]]]}, +"TRAINER_SUPER_NERD_DEREK": {"ai": ["check-bad-move"], "items": [], "party": [["rapidash", 41, 0, 8, ["fire-spin", "take-down", "agility", "fury-attack"]]]}, +"TRAINER_SUPER_NERD_ZAC": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 37, 0, 10, ["odor-sleuth", "take-down", "flame-wheel", "helping-hand"]], ["vulpix", 37, 0, 8, ["imprison", "flamethrower", "safeguard", "grudge"]]]}, +"TRAINER_HIKER_MARCOS": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 10, 0, 24, ["tackle", "defense-curl", "mud-sport"]], ["geodude", 10, 0, 12, ["tackle", "defense-curl", "mud-sport"]], ["onix", 10, 0, 8, ["tackle", "screech", "bind"]]]}, +"TRAINER_HIKER_FRANKLIN": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 15, 0, 6, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["geodude", 15, 0, 22, ["tackle", "defense-curl", "mud-sport", "rock-throw"]]]}, +"TRAINER_HIKER_NOB": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 13, 0, 23, ["tackle", "defense-curl", "mud-sport", "rock-throw"]], ["geodude", 13, 0, 10, ["tackle", "defense-curl", "mud-sport", "rock-throw"]], ["machop", 13, 0, 1, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["geodude", 13, 0, 13, ["tackle", "defense-curl", "mud-sport", "rock-throw"]]]}, +"TRAINER_HIKER_WAYNE": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 17, 0, 10, ["tackle", "screech", "bind", "rock-throw"]]]}, +"TRAINER_HIKER_ALAN": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 21, 0, 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["onix", 21, 0, 14, ["harden", "rock-throw", "bind", "screech"]]]}, +"TRAINER_HIKER_BRICE": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 20, 0, 16, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]], ["machop", 20, 0, 0, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["geodude", 20, 0, 5, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]]]}, +"TRAINER_HIKER_CLARK": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 21, 0, 14, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["onix", 21, 0, 0, ["harden", "rock-throw", "bind", "screech"]]]}, +"TRAINER_HIKER_TRENT": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 19, 0, 14, ["screech", "bind", "rock-throw", "harden"]], ["graveler", 19, 0, 12, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]]]}, +"TRAINER_HIKER_DUDLEY": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 21, 0, 11, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["geodude", 21, 0, 11, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["graveler", 21, 0, 14, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]]}, +"TRAINER_HIKER_ALLEN": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 25, 0, 8, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]]}, +"TRAINER_HIKER_ERIC": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 20, 0, 17, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["onix", 20, 0, 2, ["screech", "bind", "rock-throw", "harden"]]]}, +"TRAINER_HIKER_LENNY": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 19, 0, 14, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]], ["machop", 19, 0, 21, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["geodude", 19, 0, 24, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]], ["geodude", 19, 0, 2, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]]]}, +"TRAINER_HIKER_OLIVER": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 20, 0, 4, ["screech", "bind", "rock-throw", "harden"]], ["onix", 20, 0, 22, ["screech", "bind", "rock-throw", "harden"]], ["geodude", 20, 0, 7, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]]]}, +"TRAINER_HIKER_LUCAS": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 21, 0, 5, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["graveler", 21, 0, 2, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]]}, +"TRAINER_BIKER_JARED": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 28, 0, 14, ["smokescreen", "sludge", "smog", "poison-gas"]], ["koffing", 28, 0, 17, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, 0, 20, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_BIKER_MALIK": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 29, 0, 12, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 29, 0, 9, ["screech", "minimize", "sludge", "disable"]]]}, +"TRAINER_BIKER_ERNEST": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 25, 0, 13, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, 0, 15, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, 0, 18, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, 0, 20, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 25, 0, 18, ["minimize", "sludge", "disable", "pound"]]]}, +"TRAINER_BIKER_ALEX": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 28, 0, 22, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 28, 0, 4, ["screech", "minimize", "sludge", "disable"]], ["weezing", 28, 0, 16, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_BIKER_LAO": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 29, 0, 18, ["screech", "minimize", "sludge", "disable"]], ["koffing", 29, 0, 4, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_BIKER_HIDEO": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 33, 0, 8, ["self-destruct", "sludge", "smokescreen", "haze"]]]}, +"TRAINER_BIKER_RUBEN": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 28, 0, 22, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, 0, 7, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 28, 0, 18, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_BIKER_BILLY": {"ai": ["check-bad-move"], "items": [], "party": [["muk", 33, 0, 19, ["disable", "sludge", "minimize", "screech"]]]}, +"TRAINER_BIKER_NIKOLAS": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 29, 0, 20, ["spark", "sonic-boom", "screech", "charge"]], ["voltorb", 29, 0, 4, ["spark", "sonic-boom", "screech", "charge"]]]}, +"TRAINER_BIKER_JAXON": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 29, 0, 21, ["sludge", "smokescreen", "smog", "tackle"]], ["muk", 29, 0, 3, ["screech", "minimize", "sludge", "disable"]]]}, +"TRAINER_BIKER_WILLIAM": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 25, 0, 17, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, 0, 24, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, 0, 5, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, 0, 11, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, 0, 18, ["smokescreen", "sludge", "self-destruct", "tackle"]]]}, +"TRAINER_BIKER_LUKAS": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 26, 0, 20, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 26, 0, 4, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 26, 0, 9, ["screech", "minimize", "sludge", "disable"]], ["koffing", 26, 0, 18, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_BIKER_ISAAC": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 28, 0, 5, ["screech", "minimize", "sludge", "disable"]], ["grimer", 28, 0, 24, ["screech", "minimize", "sludge", "disable"]], ["koffing", 28, 0, 22, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_BIKER_GERALD": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 29, 0, 9, ["smokescreen", "sludge", "smog", "tackle"]], ["muk", 29, 0, 5, ["screech", "minimize", "sludge", "disable"]]]}, +"TRAINER_BURGLAR_1": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 29, 0, 7, ["ember", "leer", "odor-sleuth", "take-down"]], ["vulpix", 29, 0, 2, ["will-o-wisp", "confuse-ray", "imprison", "flamethrower"]]]}, +"TRAINER_BURGLAR_2": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 33, 0, 7, ["leer", "odor-sleuth", "take-down", "flame-wheel"]]]}, +"TRAINER_BURGLAR_3": {"ai": ["check-bad-move"], "items": [], "party": [["vulpix", 28, 0, 6, ["quick-attack", "will-o-wisp", "confuse-ray", "imprison"]], ["charmander", 28, 0, 1, ["ember", "metal-claw", "smokescreen", "scary-face"]], ["ponyta", 28, 0, 18, ["tail-whip", "ember", "stomp", "fire-spin"]]]}, +"TRAINER_BURGLAR_QUINN": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 36, 0, 12, ["leer", "odor-sleuth", "take-down", "flame-wheel"]], ["vulpix", 36, 0, 12, ["confuse-ray", "imprison", "flamethrower", "safeguard"]], ["ninetales", 36, 0, 5, ["ember", "quick-attack", "confuse-ray", "safeguard"]]]}, +"TRAINER_BURGLAR_RAMON": {"ai": ["check-bad-move"], "items": [], "party": [["ponyta", 41, 0, 24, ["stomp", "fire-spin", "take-down", "agility"]]]}, +"TRAINER_BURGLAR_DUSTY": {"ai": ["check-bad-move"], "items": [], "party": [["vulpix", 37, 0, 20, ["imprison", "flamethrower", "safeguard", "grudge"]], ["growlithe", 37, 0, 5, ["odor-sleuth", "take-down", "flame-wheel", "helping-hand"]]]}, +"TRAINER_BURGLAR_ARNIE": {"ai": ["check-bad-move"], "items": [], "party": [["charmander", 34, 0, 18, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]], ["charmeleon", 34, 0, 4, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]]]}, +"TRAINER_BURGLAR_4": {"ai": ["check-bad-move"], "items": [], "party": [["charmander", 34, 0, 6, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]], ["charmeleon", 34, 0, 5, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]]]}, +"TRAINER_BURGLAR_SIMON": {"ai": ["check-bad-move"], "items": [], "party": [["ninetales", 38, 0, 24, ["ember", "quick-attack", "confuse-ray", "safeguard"]]]}, +"TRAINER_BURGLAR_LEWIS": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 34, 0, 20, ["leer", "odor-sleuth", "take-down", "flame-wheel"]], ["ponyta", 34, 0, 0, ["ember", "stomp", "fire-spin", "take-down"]]]}, +"TRAINER_ENGINEER_BAILY": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 21, 0, 21, ["tackle", "screech", "sonic-boom", "spark"]], ["magnemite", 21, 0, 11, ["thunder-shock", "supersonic", "sonic-boom", "thunder-wave"]]]}, +"TRAINER_ENGINEER_BRAXTON": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 21, 0, 3, ["thunder-shock", "supersonic", "sonic-boom", "thunder-wave"]]]}, +"TRAINER_ENGINEER_BERNIE": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 18, 0, 16, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["magnemite", 18, 0, 21, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["magneton", 18, 0, 22, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]]]}, +"TRAINER_FISHERMAN_DALE": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 17, 0, 16, ["tail-whip", "water-sport", "supersonic", "horn-attack"]], ["tentacool", 17, 0, 11, ["poison-sting", "supersonic", "constrict"]], ["goldeen", 17, 0, 16, ["tail-whip", "water-sport", "supersonic", "horn-attack"]]]}, +"TRAINER_FISHERMAN_BARNY": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 17, 0, 0, ["poison-sting", "supersonic", "constrict"]], ["staryu", 17, 0, 10, ["harden", "water-gun", "rapid-spin", "recover"]], ["shellder", 17, 0, 1, ["tackle", "withdraw", "icicle-spear", "supersonic"]]]}, +"TRAINER_FISHERMAN_NED": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 22, 0, 6, ["tail-whip", "water-sport", "supersonic", "horn-attack"]], ["poliwag", 22, 0, 2, ["bubble", "hypnosis", "water-gun", "double-slap"]], ["goldeen", 22, 0, 22, ["tail-whip", "water-sport", "supersonic", "horn-attack"]]]}, +"TRAINER_FISHERMAN_CHIP": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 24, 0, 15, ["poison-sting", "supersonic", "constrict", "acid"]], ["goldeen", 24, 0, 4, ["water-sport", "supersonic", "horn-attack", "flail"]]]}, +"TRAINER_FISHERMAN_HANK": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 27, 0, 13, ["water-sport", "supersonic", "horn-attack", "flail"]]]}, +"TRAINER_FISHERMAN_ELLIOT": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 21, 0, 5, ["bubble", "hypnosis", "water-gun", "double-slap"]], ["shellder", 21, 0, 15, ["tackle", "withdraw", "icicle-spear", "supersonic"]], ["goldeen", 21, 0, 8, ["tail-whip", "water-sport", "supersonic", "horn-attack"]], ["horsea", 21, 0, 9, ["bubble", "smokescreen", "leer"]]]}, +"TRAINER_FISHERMAN_RONALD": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 28, 0, 24, ["water-sport", "supersonic", "horn-attack", "flail"]], ["goldeen", 28, 0, 13, ["water-sport", "supersonic", "horn-attack", "flail"]], ["seaking", 28, 0, 1, ["water-sport", "supersonic", "horn-attack", "flail"]], ["seaking", 28, 0, 14, ["water-sport", "supersonic", "horn-attack", "flail"]]]}, +"TRAINER_FISHERMAN_CLAUDE": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 31, 0, 9, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["cloyster", 31, 0, 11, ["withdraw", "supersonic", "aurora-beam", "protect"]]]}, +"TRAINER_FISHERMAN_WADE": {"ai": ["check-bad-move"], "items": [], "party": [["magikarp", 27, 0, 7, ["splash", "tackle"]], ["magikarp", 27, 0, 3, ["splash", "tackle"]], ["magikarp", 27, 0, 24, ["splash", "tackle"]], ["magikarp", 27, 0, 20, ["splash", "tackle"]], ["magikarp", 27, 0, 16, ["splash", "tackle"]], ["magikarp", 27, 0, 12, ["splash", "tackle"]]]}, +"TRAINER_FISHERMAN_NOLAN": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 33, 0, 10, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["goldeen", 33, 0, 10, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_FISHERMAN_ANDREW": {"ai": ["check-bad-move"], "items": [], "party": [["magikarp", 24, 0, 6, ["splash", "tackle"]], ["magikarp", 24, 0, 1, ["splash", "tackle"]]]}, +"TRAINER_SWIMMER_MALE_LUIS": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 16, 0, 8, ["bubble", "smokescreen", "leer"]], ["shellder", 16, 0, 14, ["tackle", "withdraw", "icicle-spear", "supersonic"]]]}, +"TRAINER_SWIMMER_MALE_RICHARD": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 30, 0, 13, ["constrict", "acid", "bubble-beam", "wrap"]], ["shellder", 30, 0, 17, ["icicle-spear", "supersonic", "aurora-beam", "protect"]]]}, +"TRAINER_SWIMMER_MALE_REECE": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 29, 0, 16, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["horsea", 29, 0, 4, ["smokescreen", "leer", "water-gun", "twister"]], ["staryu", 29, 0, 20, ["recover", "camouflage", "swift", "bubble-beam"]]]}, +"TRAINER_SWIMMER_MALE_MATTHEW": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 30, 0, 23, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["poliwhirl", 30, 0, 1, ["hypnosis", "water-gun", "double-slap", "rain-dance"]]]}, +"TRAINER_SWIMMER_MALE_DOUGLAS": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 27, 0, 14, ["bubble", "smokescreen", "leer", "water-gun"]], ["tentacool", 27, 0, 24, ["supersonic", "constrict", "acid", "bubble-beam"]], ["tentacool", 27, 0, 9, ["supersonic", "constrict", "acid", "bubble-beam"]], ["goldeen", 27, 0, 4, ["water-sport", "supersonic", "horn-attack", "flail"]]]}, +"TRAINER_SWIMMER_MALE_DAVID": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 29, 0, 15, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["shellder", 29, 0, 11, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["seaking", 29, 0, 14, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_SWIMMER_MALE_TONY": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 30, 0, 11, ["smokescreen", "leer", "water-gun", "twister"]], ["horsea", 30, 0, 11, ["smokescreen", "leer", "water-gun", "twister"]]]}, +"TRAINER_SWIMMER_MALE_AXLE": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 27, 0, 1, ["supersonic", "constrict", "acid", "bubble-beam"]], ["tentacool", 27, 0, 16, ["supersonic", "constrict", "acid", "bubble-beam"]], ["staryu", 27, 0, 2, ["rapid-spin", "recover", "camouflage", "swift"]], ["horsea", 27, 0, 10, ["bubble", "smokescreen", "leer", "water-gun"]], ["tentacruel", 27, 0, 0, ["supersonic", "constrict", "acid", "bubble-beam"]]]}, +"TRAINER_SWIMMER_MALE_BARRY": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 31, 0, 1, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["cloyster", 31, 0, 20, ["withdraw", "supersonic", "aurora-beam", "protect"]]]}, +"TRAINER_SWIMMER_MALE_DEAN": {"ai": ["check-bad-move"], "items": [], "party": [["staryu", 35, 0, 14, ["camouflage", "swift", "bubble-beam", "minimize"]]]}, +"TRAINER_SWIMMER_MALE_DARRIN": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 28, 0, 8, ["bubble", "smokescreen", "leer", "water-gun"]], ["horsea", 28, 0, 5, ["bubble", "smokescreen", "leer", "water-gun"]], ["seadra", 28, 0, 19, ["bubble", "smokescreen", "leer", "water-gun"]], ["horsea", 28, 0, 16, ["bubble", "smokescreen", "leer", "water-gun"]]]}, +"TRAINER_SWIMMER_MALE_SPENCER": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 33, 0, 12, ["smokescreen", "leer", "water-gun", "twister"]], ["tentacruel", 33, 0, 3, ["constrict", "acid", "bubble-beam", "wrap"]]]}, +"TRAINER_SWIMMER_MALE_JACK": {"ai": ["check-bad-move"], "items": [], "party": [["starmie", 37, 0, 22, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_SWIMMER_MALE_JEROME": {"ai": ["check-bad-move"], "items": [], "party": [["staryu", 33, 0, 23, ["camouflage", "swift", "bubble-beam", "minimize"]], ["wartortle", 33, 0, 1, ["water-gun", "bite", "rapid-spin", "protect"]]]}, +"TRAINER_SWIMMER_MALE_ROLAND": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 32, 0, 17, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["tentacool", 32, 0, 21, ["constrict", "acid", "bubble-beam", "wrap"]], ["seadra", 32, 0, 10, ["smokescreen", "leer", "water-gun", "twister"]]]}, +"TRAINER_CUE_BALL_KOJI": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 28, 0, 2, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["mankey", 28, 0, 21, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["machop", 28, 0, 12, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_CUE_BALL_LUKE": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 29, 0, 4, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["machop", 29, 0, 19, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_CUE_BALL_CAMRON": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 29, 0, 1, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["machop", 29, 0, 13, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_CUE_BALL_RAUL": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 29, 0, 22, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["primeape", 29, 0, 24, ["fury-swipes", "focus-energy", "seismic-toss", "rage"]]]}, +"TRAINER_CUE_BALL_ISAIAH": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 29, 0, 21, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["machamp", 29, 0, 16, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_CUE_BALL_ZEEK": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 33, 0, 5, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, +"TRAINER_CUE_BALL_JAMAL": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 26, 0, 23, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["mankey", 26, 0, 10, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["machamp", 26, 0, 4, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["machop", 26, 0, 13, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_CUE_BALL_COREY": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 29, 0, 13, ["fury-swipes", "focus-energy", "seismic-toss", "rage"]], ["machoke", 29, 0, 12, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_CUE_BALL_CHASE": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 31, 0, 6, ["constrict", "acid", "bubble-beam", "wrap"]], ["tentacool", 31, 0, 1, ["constrict", "acid", "bubble-beam", "wrap"]], ["tentacruel", 31, 0, 21, ["constrict", "acid", "bubble-beam", "wrap"]]]}, +"TRAINER_GAMER_HUGO": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 18, 0, 16, ["bubble", "hypnosis", "water-gun"]], ["horsea", 18, 0, 3, ["bubble", "smokescreen", "leer"]]]}, +"TRAINER_GAMER_JASPER": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 18, 0, 21, ["growth", "wrap", "sleep-powder", "poison-powder"]], ["oddish", 18, 0, 6, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]]]}, +"TRAINER_GAMER_DIRK": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 18, 0, 13, ["charge", "tackle", "screech", "sonic-boom"]], ["magnemite", 18, 0, 20, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]]]}, +"TRAINER_GAMER_DARIAN": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 18, 0, 10, ["bite", "roar", "ember", "leer"]], ["vulpix", 18, 0, 8, ["tail-whip", "roar", "quick-attack", "will-o-wisp"]]]}, +"TRAINER_GAMER_STAN": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 22, 0, 9, ["bubble", "hypnosis", "water-gun", "double-slap"]], ["poliwag", 22, 0, 7, ["bubble", "hypnosis", "water-gun", "double-slap"]], ["poliwhirl", 22, 0, 21, ["bubble", "hypnosis", "water-gun", "double-slap"]]]}, +"TRAINER_GAMER_RICH": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 24, 0, 24, ["roar", "ember", "leer", "odor-sleuth"]], ["vulpix", 24, 0, 11, ["roar", "quick-attack", "will-o-wisp", "confuse-ray"]]]}, +"TRAINER_BEAUTY_BRIDGET": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 21, 0, 22, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bellsprout", 21, 0, 24, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]], ["oddish", 21, 0, 1, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bellsprout", 21, 0, 3, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]]]}, +"TRAINER_BEAUTY_TAMIA": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 24, 0, 14, ["sleep-powder", "poison-powder", "stun-spore", "acid"]], ["bellsprout", 24, 0, 8, ["sleep-powder", "poison-powder", "stun-spore", "acid"]]]}, +"TRAINER_BEAUTY_LORI": {"ai": ["check-bad-move"], "items": [], "party": [["exeggcute", 24, 0, 9, ["hypnosis", "reflect", "leech-seed", "confusion"]]]}, +"TRAINER_BEAUTY_LOLA": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 27, 0, 22, ["quick-attack", "hyper-fang", "focus-energy", "pursuit"]], ["pikachu", 27, 0, 2, ["quick-attack", "double-team", "slam", "thunderbolt"]], ["rattata", 27, 0, 4, ["quick-attack", "hyper-fang", "focus-energy", "pursuit"]]]}, +"TRAINER_BEAUTY_SHEILA": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 29, 0, 17, ["follow-me", "minimize", "defense-curl", "metronome"]], ["meowth", 29, 0, 12, ["growl", "bite", "pay-day", "feint-attack"]]]}, +"TRAINER_SWIMMER_FEMALE_TIFFANY": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 35, 0, 1, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_SWIMMER_FEMALE_NORA": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 30, 0, 23, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["shellder", 30, 0, 1, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["cloyster", 30, 0, 8, ["withdraw", "supersonic", "aurora-beam", "protect"]]]}, +"TRAINER_SWIMMER_FEMALE_MELISSA": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 31, 0, 10, ["water-gun", "double-slap", "rain-dance", "body-slam"]], ["seaking", 31, 0, 23, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_BEAUTY_GRACE": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 29, 0, 14, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["wigglytuff", 29, 0, 24, ["sing", "disable", "defense-curl", "double-slap"]]]}, +"TRAINER_BEAUTY_OLIVIA": {"ai": ["check-bad-move"], "items": [], "party": [["bulbasaur", 29, 0, 0, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]], ["ivysaur", 29, 0, 6, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]]]}, +"TRAINER_BEAUTY_LAUREN": {"ai": ["check-bad-move"], "items": [], "party": [["weepinbell", 33, 0, 20, ["poison-powder", "stun-spore", "acid", "sweet-scent"]], ["bellsprout", 33, 0, 17, ["poison-powder", "stun-spore", "acid", "sweet-scent"]], ["weepinbell", 33, 0, 17, ["poison-powder", "stun-spore", "acid", "sweet-scent"]]]}, +"TRAINER_SWIMMER_FEMALE_ANYA": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 27, 0, 15, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["goldeen", 27, 0, 9, ["water-sport", "supersonic", "horn-attack", "flail"]], ["seaking", 27, 0, 2, ["water-sport", "supersonic", "horn-attack", "flail"]], ["goldeen", 27, 0, 21, ["water-sport", "supersonic", "horn-attack", "flail"]], ["poliwag", 27, 0, 16, ["hypnosis", "water-gun", "double-slap", "rain-dance"]]]}, +"TRAINER_SWIMMER_FEMALE_ALICE": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 30, 0, 14, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 30, 0, 7, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_SWIMMER_FEMALE_CONNIE": {"ai": ["check-bad-move"], "items": [], "party": [["staryu", 29, 0, 21, ["recover", "camouflage", "swift", "bubble-beam"]], ["staryu", 29, 0, 22, ["recover", "camouflage", "swift", "bubble-beam"]], ["staryu", 29, 0, 23, ["recover", "camouflage", "swift", "bubble-beam"]]]}, +"TRAINER_SWIMMER_FEMALE_SHIRLEY": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 30, 0, 17, ["smokescreen", "leer", "water-gun", "twister"]], ["horsea", 30, 0, 22, ["smokescreen", "leer", "water-gun", "twister"]], ["seadra", 30, 0, 19, ["smokescreen", "leer", "water-gun", "twister"]]]}, +"TRAINER_PSYCHIC_JOHAN": {"ai": ["check-bad-move"], "items": [], "party": [["kadabra", 31, 50, 19, ["psybeam", "reflect", "recover", "future-sight"]], ["slowpoke", 31, 50, 11, ["water-gun", "confusion", "disable", "headbutt"]], ["mr-mime", 31, 50, 14, ["reflect", "magical-leaf", "encore", "psybeam"]], ["kadabra", 31, 50, 22, ["psybeam", "reflect", "recover", "future-sight"]]]}, +"TRAINER_PSYCHIC_TYRON": {"ai": ["check-bad-move"], "items": [], "party": [["mr-mime", 34, 50, 3, ["magical-leaf", "encore", "psybeam", "recycle"]], ["kadabra", 34, 50, 0, ["reflect", "recover", "future-sight", "role-play"]]]}, +"TRAINER_PSYCHIC_CAMERON": {"ai": ["check-bad-move"], "items": [], "party": [["slowpoke", 33, 50, 11, ["water-gun", "confusion", "disable", "headbutt"]], ["slowpoke", 33, 50, 11, ["water-gun", "confusion", "disable", "headbutt"]], ["slowbro", 33, 50, 23, ["water-gun", "confusion", "disable", "headbutt"]]]}, +"TRAINER_PSYCHIC_PRESTON": {"ai": ["check-bad-move"], "items": [], "party": [["slowbro", 38, 50, 1, ["disable", "headbutt", "amnesia", "withdraw"]]]}, +"TRAINER_ROCKER_RANDALL": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 20, 0, 6, ["charge", "tackle", "screech", "sonic-boom"]], ["magnemite", 20, 0, 6, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["voltorb", 20, 0, 1, ["charge", "tackle", "screech", "sonic-boom"]]]}, +"TRAINER_ROCKER_LUCA": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 29, 0, 8, ["screech", "sonic-boom", "spark", "self-destruct"]], ["electrode", 29, 0, 10, ["screech", "sonic-boom", "spark", "self-destruct"]]]}, +"TRAINER_JUGGLER_DALTON": {"ai": ["check-bad-move"], "items": [], "party": [["kadabra", 29, 0, 18, ["disable", "psybeam", "reflect", "recover"]], ["mr-mime", 29, 0, 20, ["reflect", "magical-leaf", "encore", "psybeam"]]]}, +"TRAINER_JUGGLER_NELSON": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 41, 0, 19, ["meditate", "psychic", "psych-up", "swagger"]], ["hypno", 41, 0, 12, ["headbutt", "poison-gas", "meditate", "psychic"]], ["kadabra", 41, 0, 22, ["recover", "future-sight", "role-play", "psychic"]], ["kadabra", 41, 0, 7, ["recover", "future-sight", "role-play", "psychic"]]]}, +"TRAINER_JUGGLER_KIRK": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 31, 0, 7, ["headbutt", "poison-gas", "meditate", "psychic"]], ["drowzee", 31, 0, 3, ["headbutt", "poison-gas", "meditate", "psychic"]], ["kadabra", 31, 0, 1, ["psybeam", "reflect", "recover", "future-sight"]], ["drowzee", 31, 0, 22, ["headbutt", "poison-gas", "meditate", "psychic"]]]}, +"TRAINER_JUGGLER_SHAWN": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 34, 0, 19, ["headbutt", "poison-gas", "meditate", "psychic"]], ["hypno", 34, 0, 12, ["confusion", "headbutt", "poison-gas", "meditate"]]]}, +"TRAINER_JUGGLER_GREGORY": {"ai": ["check-bad-move"], "items": [], "party": [["mr-mime", 48, 0, 3, ["psychic", "role-play", "double-slap", "encore"]]]}, +"TRAINER_JUGGLER_EDWARD": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 46, 0, 23, ["swift", "light-screen", "spark", "sonic-boom"]], ["voltorb", 46, 0, 10, ["swift", "light-screen", "spark", "sonic-boom"]], ["electrode", 47, 0, 2, ["swift", "spark", "self-destruct", "sonic-boom"]], ["mr-mime", 48, 0, 13, ["psychic", "role-play", "reflect", "encore"]]]}, +"TRAINER_JUGGLER_KAYDEN": {"ai": ["check-bad-move"], "items": [], "party": [["hypno", 38, 0, 15, ["headbutt", "poison-gas", "meditate", "psychic"]]]}, +"TRAINER_JUGGLER_NATE": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 34, 0, 3, ["headbutt", "poison-gas", "meditate", "psychic"]], ["kadabra", 34, 0, 22, ["reflect", "recover", "future-sight", "role-play"]]]}, +"TRAINER_TAMER_PHIL": {"ai": ["check-bad-move"], "items": [], "party": [["sandslash", 34, 40, 21, ["sand-attack", "poison-sting", "slash", "swift"]], ["arbok", 34, 40, 17, ["poison-sting", "bite", "glare", "screech"]]]}, +"TRAINER_TAMER_EDGAR": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 33, 40, 13, ["poison-sting", "bite", "glare", "screech"]], ["sandslash", 33, 40, 4, ["sand-attack", "poison-sting", "slash", "swift"]], ["arbok", 33, 40, 6, ["poison-sting", "bite", "glare", "screech"]]]}, +"TRAINER_TAMER_JASON": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 43, 40, 18, ["scary-face", "rock-blast", "horn-drill", "take-down"]]]}, +"TRAINER_TAMER_COLE": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 39, 40, 22, ["bite", "glare", "screech", "acid"]], ["tauros", 39, 40, 6, ["scary-face", "pursuit", "swagger", "rest"]]]}, +"TRAINER_TAMER_VINCENT": {"ai": ["check-bad-move"], "items": [], "party": [["persian", 44, 40, 24, ["pay-day", "feint-attack", "screech", "fury-swipes"]], ["golduck", 44, 40, 8, ["confusion", "screech", "psych-up", "fury-swipes"]]]}, +"TRAINER_TAMER_JOHN": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 42, 40, 5, ["fury-attack", "scary-face", "rock-blast", "horn-drill"]], ["primeape", 42, 40, 2, ["focus-energy", "seismic-toss", "rage", "cross-chop"]], ["arbok", 42, 40, 10, ["bite", "glare", "screech", "acid"]], ["tauros", 42, 40, 16, ["scary-face", "pursuit", "swagger", "rest"]]]}, +"TRAINER_BIRD_KEEPER_SEBASTIAN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 29, 0, 12, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 29, 0, 6, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, +"TRAINER_BIRD_KEEPER_PERRY": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 25, 0, 2, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["pidgey", 25, 0, 16, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgey", 25, 0, 5, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["spearow", 25, 0, 21, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["spearow", 25, 0, 12, ["leer", "fury-attack", "pursuit", "aerial-ace"]]]}, +"TRAINER_BIRD_KEEPER_ROBERT": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 26, 0, 17, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 26, 0, 16, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["spearow", 26, 0, 24, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 26, 0, 17, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_DONALD": {"ai": ["check-bad-move"], "items": [], "party": [["farfetch-d", 33, 0, 7, ["fury-attack", "knock-off", "fury-cutter", "swords-dance"]]]}, +"TRAINER_BIRD_KEEPER_BENNY": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 29, 0, 20, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 29, 0, 14, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_EDWIN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 26, 0, 6, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["farfetch-d", 26, 0, 16, ["leer", "fury-attack", "knock-off", "fury-cutter"]], ["doduo", 26, 0, 10, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["pidgey", 26, 0, 12, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, +"TRAINER_BIRD_KEEPER_CHESTER": {"ai": ["check-bad-move"], "items": [], "party": [["dodrio", 28, 0, 2, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["doduo", 28, 0, 16, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["doduo", 28, 0, 5, ["pursuit", "fury-attack", "tri-attack", "rage"]]]}, +"TRAINER_BIRD_KEEPER_WILTON": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 29, 0, 9, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 29, 0, 17, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_RAMIRO": {"ai": ["check-bad-move"], "items": [], "party": [["dodrio", 34, 0, 12, ["pursuit", "fury-attack", "tri-attack", "rage"]]]}, +"TRAINER_BIRD_KEEPER_JACOB": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 26, 0, 21, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["spearow", 26, 0, 6, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 26, 0, 1, ["growl", "leer", "fury-attack", "pursuit"]], ["spearow", 26, 0, 11, ["leer", "fury-attack", "pursuit", "aerial-ace"]]]}, +"TRAINER_BIRD_KEEPER_ROGER": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 30, 0, 23, ["growl", "leer", "fury-attack", "pursuit"]], ["fearow", 30, 0, 10, ["growl", "leer", "fury-attack", "pursuit"]], ["pidgeotto", 30, 0, 3, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, +"TRAINER_BIRD_KEEPER_REED": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 39, 0, 2, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["pidgeotto", 39, 0, 18, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["pidgey", 39, 0, 16, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["pidgeotto", 39, 0, 7, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]]]}, +"TRAINER_BIRD_KEEPER_KEITH": {"ai": ["check-bad-move"], "items": [], "party": [["farfetch-d", 39, 0, 9, ["knock-off", "fury-cutter", "swords-dance", "agility"]], ["fearow", 39, 0, 11, ["leer", "fury-attack", "pursuit", "mirror-move"]]]}, +"TRAINER_BIRD_KEEPER_CARTER": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 28, 0, 14, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["doduo", 28, 0, 9, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["pidgeotto", 28, 0, 5, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, +"TRAINER_BIRD_KEEPER_MITCH": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 26, 0, 1, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["spearow", 26, 0, 18, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["pidgey", 26, 0, 8, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["fearow", 26, 0, 10, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_BECK": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 29, 0, 11, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["fearow", 29, 0, 5, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_MARLON": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 28, 0, 14, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["doduo", 28, 0, 7, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["fearow", 28, 0, 20, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BLACK_BELT_KOICHI": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonlee", 37, 100, 12, ["focus-energy", "high-jump-kick", "mind-reader", "foresight"]], ["hitmonchan", 37, 100, 3, ["thunder-punch", "ice-punch", "fire-punch", "sky-uppercut"]]]}, +"TRAINER_BLACK_BELT_MIKE": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 31, 100, 13, ["fury-swipes", "focus-energy", "seismic-toss", "cross-chop"]], ["mankey", 31, 100, 15, ["fury-swipes", "focus-energy", "seismic-toss", "cross-chop"]], ["primeape", 31, 100, 8, ["fury-swipes", "focus-energy", "seismic-toss", "rage"]]]}, +"TRAINER_BLACK_BELT_HIDEKI": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 32, 100, 15, ["seismic-toss", "foresight", "revenge", "vital-throw"]], ["machoke", 32, 100, 10, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_BLACK_BELT_AARON": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 36, 100, 11, ["focus-energy", "seismic-toss", "rage", "cross-chop"]]]}, +"TRAINER_BLACK_BELT_HITOSHI": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 31, 100, 8, ["seismic-toss", "foresight", "revenge", "vital-throw"]], ["mankey", 31, 100, 8, ["fury-swipes", "focus-energy", "seismic-toss", "cross-chop"]], ["primeape", 31, 100, 24, ["fury-swipes", "focus-energy", "seismic-toss", "rage"]]]}, +"TRAINER_BLACK_BELT_ATSUSHI": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 40, 100, 12, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machoke", 40, 100, 4, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, +"TRAINER_BLACK_BELT_KIYO": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 43, 100, 8, ["foresight", "revenge", "vital-throw", "submission"]]]}, +"TRAINER_BLACK_BELT_TAKASHI": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 38, 100, 10, ["seismic-toss", "foresight", "revenge", "vital-throw"]], ["machop", 38, 100, 18, ["foresight", "revenge", "vital-throw", "submission"]], ["machoke", 38, 100, 17, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, +"TRAINER_BLACK_BELT_DAISUKE": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 43, 100, 16, ["foresight", "revenge", "vital-throw", "submission"]], ["machop", 43, 100, 5, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machoke", 43, 100, 10, ["foresight", "revenge", "vital-throw", "submission"]]]}, +"TRAINER_RIVAL_OAKS_LAB_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["squirtle", 5, 0, 11, ["tackle", "tail-whip"]]]}, +"TRAINER_RIVAL_OAKS_LAB_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["bulbasaur", 5, 0, 8, ["tackle", "growl"]]]}, +"TRAINER_RIVAL_OAKS_LAB_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["charmander", 5, 0, 2, ["scratch", "growl"]]]}, +"TRAINER_RIVAL_ROUTE22_EARLY_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgey", 9, 50, 24, ["tackle", "sand-attack"]], ["squirtle", 9, 50, 24, ["tackle", "tail-whip"]]]}, +"TRAINER_RIVAL_ROUTE22_EARLY_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgey", 9, 50, 24, ["tackle", "sand-attack"]], ["bulbasaur", 9, 50, 21, ["tackle", "growl"]]]}, +"TRAINER_RIVAL_ROUTE22_EARLY_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgey", 9, 50, 24, ["tackle", "sand-attack"]], ["charmander", 9, 50, 15, ["scratch", "growl"]]]}, +"TRAINER_RIVAL_CERULEAN_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 17, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, 50, 9, ["teleport"]], ["rattata", 15, 50, 3, ["tackle", "tail-whip", "quick-attack"]], ["squirtle", 18, 100, 3, ["tackle", "tail-whip", "withdraw", "water-gun"]]]}, +"TRAINER_RIVAL_CERULEAN_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 17, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, 50, 9, ["teleport"]], ["rattata", 15, 50, 3, ["tackle", "tail-whip", "quick-attack"]], ["bulbasaur", 18, 100, 0, ["sleep-powder", "poison-powder", "vine-whip", "leech-seed"]]]}, +"TRAINER_RIVAL_CERULEAN_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 17, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, 50, 9, ["teleport"]], ["rattata", 15, 50, 3, ["tackle", "tail-whip", "quick-attack"]], ["charmander", 18, 100, 19, ["metal-claw", "ember", "growl", "scratch"]]]}, +"TRAINER_SCIENTIST_TED": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 29, 0, 24, ["screech", "sonic-boom", "spark", "self-destruct"]], ["weezing", 29, 0, 17, ["smog", "self-destruct", "sludge", "smokescreen"]]]}, +"TRAINER_SCIENTIST_CONNOR": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 26, 0, 22, ["screech", "minimize", "sludge", "disable"]], ["weezing", 26, 0, 13, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 26, 0, 3, ["smokescreen", "sludge", "smog", "self-destruct"]], ["weezing", 26, 0, 19, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_SCIENTIST_JERRY": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 28, 0, 13, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["voltorb", 28, 0, 10, ["screech", "sonic-boom", "spark", "self-destruct"]], ["magneton", 28, 0, 8, ["supersonic", "sonic-boom", "thunder-wave", "spark"]]]}, +"TRAINER_SCIENTIST_JOSE": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 29, 0, 10, ["spark", "sonic-boom", "screech", "tackle"]], ["weezing", 29, 0, 14, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_SCIENTIST_RODNEY": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 33, 0, 9, ["screech", "sonic-boom", "spark", "self-destruct"]]]}, +"TRAINER_SCIENTIST_BEAU": {"ai": ["check-bad-move"], "items": [], "party": [["magneton", 26, 0, 11, ["spark", "thunder-wave", "sonic-boom", "supersonic"]], ["koffing", 26, 0, 19, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 26, 0, 3, ["smokescreen", "sludge", "smog", "tackle"]], ["magnemite", 26, 0, 7, ["spark", "thunder-wave", "sonic-boom", "supersonic"]]]}, +"TRAINER_SCIENTIST_TAYLOR": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 25, 0, 14, ["spark", "sonic-boom", "screech", "tackle"]], ["koffing", 25, 0, 1, ["smokescreen", "sludge", "smog", "tackle"]], ["magneton", 25, 0, 5, ["thunder-wave", "sonic-boom", "supersonic", "thunder-shock"]], ["magnemite", 25, 0, 13, ["thunder-wave", "sonic-boom", "supersonic", "thunder-shock"]], ["koffing", 25, 0, 0, ["smokescreen", "sludge", "smog", "self-destruct"]]]}, +"TRAINER_SCIENTIST_JOSHUA": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 29, 0, 17, ["screech", "sonic-boom", "spark", "self-destruct"]], ["muk", 29, 0, 0, ["disable", "sludge", "minimize", "screech"]]]}, +"TRAINER_SCIENTIST_PARKER": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 29, 0, 12, ["disable", "sludge", "minimize", "screech"]], ["electrode", 29, 0, 13, ["screech", "sonic-boom", "spark", "self-destruct"]]]}, +"TRAINER_SCIENTIST_ED": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 28, 0, 8, ["spark", "sonic-boom", "screech", "tackle"]], ["koffing", 28, 0, 14, ["smokescreen", "sludge", "tackle", "smog"]], ["magneton", 28, 0, 12, ["spark", "thunder-wave", "sonic-boom", "supersonic"]]]}, +"TRAINER_SCIENTIST_TRAVIS": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 29, 0, 7, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["koffing", 29, 0, 7, ["smog", "self-destruct", "sludge", "smokescreen"]]]}, +"TRAINER_SCIENTIST_BRAYDON": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 33, 0, 13, ["sonic-boom", "thunder-wave", "spark", "lock-on"]], ["magneton", 33, 0, 11, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["voltorb", 33, 0, 8, ["sonic-boom", "spark", "self-destruct", "rollout"]]]}, +"TRAINER_SCIENTIST_IVAN": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 34, 0, 17, ["sonic-boom", "thunder-wave", "spark", "lock-on"]], ["electrode", 34, 0, 23, ["sonic-boom", "spark", "self-destruct", "rollout"]]]}, +"TRAINER_BOSS_GIOVANNI": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 25, 250, 21, ["bind", "rock-throw", "harden", "rage"]], ["rhyhorn", 24, 250, 18, ["tail-whip", "stomp", "fury-attack", "scary-face"]], ["kangaskhan", 29, 250, 24, ["bite", "tail-whip", "fake-out", "mega-punch"]]]}, +"TRAINER_BOSS_GIOVANNI_2": {"ai": ["check-bad-move"], "items": [], "party": [["nidorino", 37, 250, 1, ["poison-sting", "horn-attack", "helping-hand", "fury-attack"]], ["kangaskhan", 35, 250, 7, ["tail-whip", "fake-out", "mega-punch", "rage"]], ["rhyhorn", 37, 250, 4, ["stomp", "fury-attack", "scary-face", "rock-blast"]], ["nidoqueen", 41, 250, 21, ["tail-whip", "double-kick", "poison-sting", "body-slam"]]]}, +"TRAINER_LEADER_GIOVANNI": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "hyper-potion", "full-heal"], "party": [["rhyhorn", 45, 0, 8, ["take-down", "rock-blast", "scary-face", "earthquake"]], ["dugtrio", 42, 0, 8, ["slash", "sand-tomb", "mud-slap", "earthquake"]], ["nidoqueen", 44, 0, 0, ["body-slam", "double-kick", "poison-sting", "earthquake"]], ["nidoking", 45, 0, 0, ["thrash", "double-kick", "poison-sting", "earthquake"]], ["rhyhorn", 50, 0, 22, ["take-down", "rock-blast", "scary-face", "earthquake"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 13, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["zubat", 13, 0, 4, ["leech-life", "astonish", "supersonic"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_2": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 11, 0, 6, ["scratch", "defense-curl", "sand-attack"]], ["rattata", 11, 0, 14, ["tackle", "tail-whip", "quick-attack"]], ["zubat", 11, 0, 24, ["leech-life", "astonish", "supersonic"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_3": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 11, 0, 21, ["leech-life", "astonish", "supersonic"]], ["ekans", 11, 0, 11, ["wrap", "leer", "poison-sting"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_4": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 13, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["sandshrew", 13, 0, 14, ["scratch", "defense-curl", "sand-attack"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_5": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 17, 0, 3, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["drowzee", 17, 0, 1, ["hypnosis", "disable", "confusion", "headbutt"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_6": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 15, 0, 1, ["wrap", "leer", "poison-sting", "bite"]], ["zubat", 15, 0, 11, ["leech-life", "astonish", "supersonic"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_7": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 20, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["zubat", 20, 0, 21, ["leech-life", "astonish", "supersonic", "bite"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_8": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 21, 0, 9, ["disable", "confusion", "headbutt", "poison-gas"]], ["machop", 21, 0, 1, ["leer", "focus-energy", "karate-chop", "seismic-toss"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_9": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 21, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["raticate", 21, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_10": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 20, 0, 12, ["minimize", "sludge", "disable", "harden"]], ["koffing", 20, 0, 17, ["smog", "tackle", "poison-gas"]], ["koffing", 20, 0, 22, ["smog", "tackle", "poison-gas"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_11": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 19, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["raticate", 19, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["raticate", 19, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["rattata", 19, 0, 2, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_12": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 22, 0, 12, ["minimize", "sludge", "disable", "harden"]], ["koffing", 22, 0, 17, ["sludge", "smog", "tackle", "poison-gas"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_13": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 17, 0, 21, ["bite", "astonish", "supersonic", "leech-life"]], ["koffing", 17, 0, 1, ["smog", "tackle", "poison-gas"]], ["grimer", 17, 0, 2, ["sludge", "disable", "harden", "pound"]], ["zubat", 17, 0, 12, ["bite", "astonish", "supersonic", "leech-life"]], ["raticate", 17, 0, 12, ["hyper-fang", "quick-attack", "tail-whip", "tackle"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_14": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 20, 0, 19, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["raticate", 20, 0, 19, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["drowzee", 20, 0, 17, ["hypnosis", "disable", "confusion", "headbutt"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_15": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 21, 0, 3, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["machop", 21, 0, 20, ["leer", "focus-energy", "karate-chop", "seismic-toss"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_16": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 23, 0, 6, ["defense-curl", "sand-attack", "poison-sting", "slash"]], ["ekans", 23, 0, 21, ["leer", "poison-sting", "bite", "glare"]], ["sandslash", 23, 0, 7, ["scratch", "defense-curl", "sand-attack", "poison-sting"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_17": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 23, 0, 1, ["leer", "poison-sting", "bite", "glare"]], ["sandshrew", 23, 0, 21, ["defense-curl", "sand-attack", "poison-sting", "slash"]], ["arbok", 23, 0, 18, ["leer", "poison-sting", "bite", "glare"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_18": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 21, 0, 16, ["tackle", "smog", "self-destruct", "sludge"]], ["zubat", 21, 0, 1, ["astonish", "supersonic", "bite", "wing-attack"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_19": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 25, 0, 21, ["astonish", "supersonic", "bite", "wing-attack"]], ["zubat", 25, 0, 6, ["astonish", "supersonic", "bite", "wing-attack"]], ["golbat", 25, 0, 4, ["astonish", "supersonic", "bite", "wing-attack"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_20": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 26, 0, 16, ["smog", "self-destruct", "sludge", "smokescreen"]], ["drowzee", 26, 0, 14, ["disable", "confusion", "headbutt", "poison-gas"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_21": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 23, 0, 21, ["astonish", "supersonic", "bite", "wing-attack"]], ["rattata", 23, 0, 4, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["raticate", 23, 0, 4, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["zubat", 23, 0, 14, ["astonish", "supersonic", "bite", "wing-attack"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_22": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 26, 0, 9, ["disable", "confusion", "headbutt", "poison-gas"]], ["koffing", 26, 0, 14, ["smog", "self-destruct", "sludge", "smokescreen"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_23": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 29, 0, 2, ["leer", "focus-energy", "bonemerang", "rage"]], ["zubat", 29, 0, 12, ["supersonic", "bite", "wing-attack", "confuse-ray"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_24": {"ai": ["check-bad-move"], "items": [], "party": [["golbat", 25, 0, 9, ["astonish", "supersonic", "bite", "wing-attack"]], ["zubat", 25, 0, 19, ["astonish", "supersonic", "bite", "wing-attack"]], ["zubat", 25, 0, 4, ["astonish", "supersonic", "bite", "wing-attack"]], ["raticate", 25, 0, 4, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["zubat", 25, 0, 14, ["astonish", "supersonic", "bite", "wing-attack"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_25": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 28, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["hypno", 28, 0, 19, ["disable", "confusion", "headbutt", "poison-gas"]], ["raticate", 28, 0, 19, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_26": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 29, 0, 3, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["drowzee", 29, 0, 1, ["confusion", "headbutt", "poison-gas", "meditate"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_27": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 28, 0, 1, ["poison-sting", "bite", "glare", "screech"]], ["zubat", 28, 0, 11, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["cubone", 28, 0, 2, ["headbutt", "leer", "focus-energy", "bonemerang"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_28": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 33, 0, 8, ["poison-sting", "bite", "glare", "screech"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_29": {"ai": ["check-bad-move"], "items": [], "party": [["hypno", 33, 0, 19, ["confusion", "headbutt", "poison-gas", "meditate"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_30": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 29, 0, 3, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["machoke", 29, 0, 11, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_31": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 28, 0, 21, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["zubat", 28, 0, 6, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["golbat", 28, 0, 4, ["supersonic", "bite", "wing-attack", "confuse-ray"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_32": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 26, 0, 11, ["scary-face", "hyper-fang", "quick-attack", "tail-whip"]], ["arbok", 26, 0, 8, ["glare", "bite", "poison-sting", "leer"]], ["koffing", 26, 0, 13, ["smokescreen", "sludge", "smog", "tackle"]], ["golbat", 26, 0, 11, ["wing-attack", "bite", "astonish", "supersonic"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_33": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 29, 0, 2, ["leer", "focus-energy", "bonemerang", "rage"]], ["cubone", 29, 0, 18, ["leer", "focus-energy", "bonemerang", "rage"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_34": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 29, 0, 6, ["defense-curl", "sand-attack", "poison-sting", "slash"]], ["sandslash", 29, 0, 17, ["defense-curl", "sand-attack", "poison-sting", "slash"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_35": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 26, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["zubat", 26, 0, 21, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["golbat", 26, 0, 19, ["astonish", "supersonic", "bite", "wing-attack"]], ["rattata", 26, 0, 2, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_36": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 28, 0, 17, ["smog", "self-destruct", "sludge", "smokescreen"]], ["golbat", 28, 0, 15, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["koffing", 28, 0, 20, ["smog", "self-destruct", "sludge", "smokescreen"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_37": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 28, 0, 9, ["confusion", "headbutt", "poison-gas", "meditate"]], ["grimer", 28, 0, 10, ["disable", "sludge", "minimize", "screech"]], ["machop", 28, 0, 2, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_38": {"ai": ["check-bad-move"], "items": [], "party": [["golbat", 28, 0, 9, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["drowzee", 28, 0, 7, ["confusion", "headbutt", "poison-gas", "meditate"]], ["hypno", 28, 0, 15, ["disable", "confusion", "headbutt", "poison-gas"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_39": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 33, 0, 19, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_40": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 25, 0, 19, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["rattata", 25, 0, 2, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["zubat", 25, 0, 12, ["astonish", "supersonic", "bite", "wing-attack"]], ["rattata", 25, 0, 20, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["ekans", 25, 0, 10, ["poison-sting", "bite", "glare", "screech"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_41": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 32, 0, 2, ["leer", "focus-energy", "bonemerang", "rage"]], ["drowzee", 32, 0, 0, ["headbutt", "poison-gas", "meditate", "psychic"]], ["marowak", 32, 0, 14, ["leer", "focus-energy", "bonemerang", "rage"]]]}, +"TRAINER_COOLTRAINER_SAMUEL": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["super-potion"], "party": [["sandslash", 37, 100, 9, ["slash", "swift", "sand-attack", "poison-sting"]], ["sandslash", 37, 100, 7, ["slash", "swift", "sand-attack", "poison-sting"]], ["rhyhorn", 38, 100, 2, ["take-down", "rock-blast", "fury-attack", "scary-face"]], ["nidorino", 39, 100, 15, ["fury-attack", "horn-attack", "poison-sting", "double-kick"]], ["nidoking", 39, 100, 13, ["thrash", "double-kick", "poison-sting", "focus-energy"]]]}, +"TRAINER_COOLTRAINER_GEORGE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["exeggutor", 42, 100, 0, ["egg-bomb", "confusion", "stun-spore", "sleep-powder"]], ["sandslash", 42, 100, 14, ["fury-swipes", "swift", "poison-sting", "sand-attack"]], ["cloyster", 42, 100, 7, ["spike-cannon", "spikes", "aurora-beam", "supersonic"]], ["electrode", 42, 100, 11, ["spark", "sonic-boom", "screech", "light-screen"]], ["arcanine", 42, 100, 17, ["flame-wheel", "roar", "bite", "take-down"]]]}, +"TRAINER_COOLTRAINER_COLBY": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["kingler", 41, 100, 1, ["guillotine", "stomp", "mud-shot", "bubble"]], ["poliwhirl", 42, 100, 24, ["body-slam", "double-slap", "water-gun", "hypnosis"]], ["tentacruel", 42, 100, 20, ["barrier", "wrap", "bubble-beam", "acid"]], ["seadra", 42, 100, 1, ["water-gun", "smokescreen", "twister", "leer"]], ["blastoise", 43, 100, 4, ["water-gun", "bite", "rapid-spin", "rain-dance"]]]}, +"TRAINER_COOLTRAINER_PAUL": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["slowpoke", 42, 100, 24, ["headbutt", "confusion", "water-gun", "disable"]], ["shellder", 42, 100, 14, ["aurora-beam", "clamp", "supersonic", "leer"]], ["kingler", 42, 100, 21, ["guillotine", "stomp", "mud-shot", "bubble"]], ["starmie", 42, 100, 7, ["bubble-beam", "swift", "recover", "rapid-spin"]], ["golduck", 42, 100, 21, ["confusion", "scratch", "screech", "disable"]]]}, +"TRAINER_COOLTRAINER_ROLANDO": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["raticate", 42, 100, 12, ["super-fang", "pursuit", "scary-face", "quick-attack"]], ["ivysaur", 42, 100, 0, ["razor-leaf", "sleep-powder", "sweet-scent", "synthesis"]], ["wartortle", 42, 100, 22, ["water-gun", "bite", "rapid-spin", "tail-whip"]], ["charmeleon", 42, 100, 7, ["flamethrower", "slash", "smokescreen", "scary-face"]], ["charizard", 42, 100, 15, ["flamethrower", "wing-attack", "smokescreen", "scary-face"]]]}, +"TRAINER_COOLTRAINER_GILBERT": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["pidgeotto", 42, 100, 21, ["wing-attack", "feather-dance", "whirlwind", "quick-attack"]], ["fearow", 42, 100, 0, ["drill-peck", "mirror-move", "pursuit", "leer"]], ["persian", 42, 100, 4, ["pay-day", "feint-attack", "screech", "bite"]], ["lickitung", 42, 100, 9, ["slam", "disable", "wrap", "supersonic"]], ["tauros", 42, 100, 19, ["horn-attack", "scary-face", "swagger", "tail-whip"]]]}, +"TRAINER_COOLTRAINER_OWEN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["nidorino", 42, 100, 8, ["scratch", "poison-sting", "double-kick", "bite"]], ["nidorina", 42, 100, 21, ["horn-attack", "poison-sting", "double-kick", "leer"]], ["raticate", 42, 100, 17, ["super-fang", "pursuit", "scary-face", "quick-attack"]], ["sandslash", 42, 100, 24, ["fury-swipes", "swift", "slash", "poison-sting"]], ["rhyhorn", 42, 100, 3, ["rock-blast", "scary-face", "stomp", "tail-whip"]]]}, +"TRAINER_COOLTRAINER_BERKE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["seel", 42, 100, 22, ["take-down", "aurora-beam", "icy-wind", "growl"]], ["graveler", 42, 100, 4, ["rock-blast", "magnitude", "rock-throw", "mud-sport"]], ["kingler", 42, 100, 23, ["guillotine", "stomp", "mud-shot", "bubble"]], ["onix", 42, 100, 10, ["slam", "sandstorm", "dragon-breath", "rock-throw"]], ["cloyster", 42, 100, 16, ["spike-cannon", "aurora-beam", "supersonic", "protect"]]]}, +"TRAINER_COOLTRAINER_YUJI": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["sandslash", 38, 100, 16, ["slash", "swift", "sand-attack", "poison-sting"]], ["graveler", 38, 100, 1, ["rock-blast", "magnitude", "mud-sport", "defense-curl"]], ["onix", 38, 100, 16, ["dragon-breath", "sandstorm", "rock-throw", "bind"]], ["graveler", 38, 100, 1, ["rock-blast", "magnitude", "rollout", "defense-curl"]], ["marowak", 38, 100, 9, ["bonemerang", "headbutt", "leer", "growl"]]]}, +"TRAINER_COOLTRAINER_WARREN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["marowak", 37, 100, 10, ["bonemerang", "headbutt", "leer", "growl"]], ["marowak", 37, 100, 9, ["bonemerang", "headbutt", "leer", "growl"]], ["rhyhorn", 38, 100, 2, ["take-down", "rock-blast", "fury-attack", "scary-face"]], ["nidorina", 39, 100, 4, ["fury-swipes", "bite", "poison-sting", "double-kick"]], ["nidoqueen", 39, 100, 17, ["body-slam", "bite", "poison-sting", "double-kick"]]]}, +"TRAINER_COOLTRAINER_MARY": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["super-potion"], "party": [["bellsprout", 22, 100, 1, ["wrap", "stun-spore", "poison-powder", "growth"]], ["oddish", 22, 100, 7, ["poison-powder", "stun-spore", "absorb", "sweet-scent"]], ["weepinbell", 22, 100, 16, ["vine-whip", "stun-spore", "poison-powder", "growth"]], ["gloom", 22, 100, 24, ["absorb", "stun-spore", "poison-powder", "sweet-scent"]], ["ivysaur", 22, 100, 7, ["razor-leaf", "sleep-powder", "vine-whip", "leech-seed"]]]}, +"TRAINER_COOLTRAINER_CAROLINE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["bellsprout", 42, 100, 10, ["razor-leaf", "acid", "stun-spore", "poison-powder"]], ["weepinbell", 42, 100, 3, ["razor-leaf", "acid", "sleep-powder", "poison-powder"]], ["victreebel", 42, 100, 9, ["razor-leaf", "acid", "stun-spore", "sleep-powder"]], ["paras", 42, 100, 9, ["growth", "slash", "leech-life", "stun-spore"]], ["parasect", 42, 100, 0, ["spore", "slash", "leech-life", "poison-powder"]]]}, +"TRAINER_COOLTRAINER_ALEXA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["clefairy", 42, 100, 10, ["light-screen", "cosmic-power", "double-slap", "encore"]], ["jigglypuff", 42, 100, 22, ["sing", "body-slam", "rollout", "disable"]], ["persian", 42, 100, 14, ["pay-day", "feint-attack", "bite", "screech"]], ["dewgong", 42, 100, 14, ["sheer-cold", "take-down", "rest", "aurora-beam"]], ["chansey", 42, 100, 14, ["sing", "egg-bomb", "soft-boiled", "minimize"]]]}, +"TRAINER_COOLTRAINER_SHANNON": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["beedrill", 42, 100, 22, ["pin-missile", "twineedle", "agility", "pursuit"]], ["butterfree", 42, 100, 24, ["safeguard", "psybeam", "gust", "supersonic"]], ["parasect", 42, 100, 22, ["spore", "leech-life", "slash", "growth"]], ["venonat", 42, 100, 2, ["psybeam", "stun-spore", "leech-life", "disable"]], ["venomoth", 42, 100, 24, ["psybeam", "gust", "supersonic", "leech-life"]]]}, +"TRAINER_COOLTRAINER_NAOMI": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["persian", 42, 100, 16, ["fury-swipes", "screech", "feint-attack", "pay-day"]], ["ponyta", 42, 100, 0, ["agility", "take-down", "fire-spin", "stomp"]], ["rapidash", 42, 100, 1, ["fury-attack", "fire-spin", "stomp", "growl"]], ["vulpix", 42, 100, 13, ["flamethrower", "confuse-ray", "quick-attack", "imprison"]], ["ninetales", 42, 100, 18, ["safeguard", "will-o-wisp", "confuse-ray", "fire-spin"]]]}, +"TRAINER_COOLTRAINER_BROOKE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["tangela", 42, 100, 9, ["slam", "bind", "mega-drain", "ingrain"]], ["gloom", 42, 100, 3, ["acid", "moonlight", "sleep-powder", "stun-spore"]], ["vileplume", 42, 100, 4, ["mega-drain", "acid", "stun-spore", "aromatherapy"]], ["ivysaur", 42, 100, 23, ["razor-leaf", "sweet-scent", "growl", "leech-seed"]], ["venusaur", 42, 100, 19, ["razor-leaf", "growth", "sleep-powder", "poison-powder"]]]}, +"TRAINER_COOLTRAINER_AUSTINA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["rhyhorn", 42, 100, 15, ["horn-drill", "rock-blast", "scary-face", "stomp"]], ["nidorina", 42, 100, 19, ["double-kick", "fury-swipes", "bite", "flatter"]], ["nidoqueen", 42, 100, 9, ["body-slam", "double-kick", "bite", "growl"]], ["nidorino", 42, 100, 22, ["horn-attack", "poison-sting", "focus-energy", "leer"]], ["nidoking", 42, 100, 20, ["thrash", "double-kick", "poison-sting", "peck"]]]}, +"TRAINER_COOLTRAINER_JULIE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["persian", 42, 100, 21, ["fury-swipes", "bite", "screech", "feint-attack"]], ["ninetales", 42, 100, 6, ["flamethrower", "will-o-wisp", "confuse-ray", "grudge"]], ["rapidash", 42, 100, 12, ["fury-attack", "fire-spin", "take-down", "agility"]], ["pikachu", 42, 100, 10, ["thunderbolt", "thunder-wave", "double-team", "quick-attack"]], ["raichu", 42, 100, 13, ["thunder", "thunder-wave", "slam", "double-team"]]]}, +"TRAINER_ELITE_FOUR_LORELEI": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["dewgong", 52, 250, 0, ["ice-beam", "surf", "hail", "safeguard"]], ["cloyster", 51, 250, 23, ["spikes", "protect", "hail", "dive"]], ["slowbro", 52, 250, 2, ["ice-beam", "surf", "amnesia", "yawn"]], ["jynx", 54, 250, 22, ["ice-punch", "double-slap", "lovely-kiss", "attract"]], ["lapras", 54, 250, 13, ["confuse-ray", "ice-beam", "surf", "body-slam"]]]}, +"TRAINER_ELITE_FOUR_BRUNO": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["onix", 51, 250, 22, ["earthquake", "rock-tomb", "iron-tail", "roar"]], ["hitmonchan", 53, 250, 12, ["sky-uppercut", "mach-punch", "rock-tomb", "counter"]], ["hitmonlee", 53, 250, 12, ["mega-kick", "foresight", "brick-break", "facade"]], ["onix", 54, 250, 23, ["double-edge", "earthquake", "iron-tail", "sand-tomb"]], ["machamp", 56, 250, 15, ["cross-chop", "bulk-up", "scary-face", "rock-tomb"]]]}, +"TRAINER_ELITE_FOUR_AGATHA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["gengar", 54, 250, 2, ["shadow-punch", "confuse-ray", "toxic", "double-team"]], ["golbat", 54, 250, 14, ["confuse-ray", "poison-fang", "air-cutter", "bite"]], ["haunter", 53, 250, 22, ["hypnosis", "dream-eater", "curse", "mean-look"]], ["arbok", 56, 250, 8, ["sludge-bomb", "screech", "iron-tail", "bite"]], ["gengar", 58, 250, 15, ["shadow-ball", "sludge-bomb", "hypnosis", "nightmare"]]]}, +"TRAINER_ELITE_FOUR_LANCE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["gyarados", 56, 250, 19, ["hyper-beam", "dragon-rage", "twister", "bite"]], ["dragonair", 54, 250, 0, ["hyper-beam", "safeguard", "dragon-rage", "outrage"]], ["dragonair", 54, 250, 6, ["hyper-beam", "safeguard", "thunder-wave", "outrage"]], ["aerodactyl", 58, 250, 5, ["hyper-beam", "ancient-power", "wing-attack", "scary-face"]], ["dragonite", 60, 250, 22, ["hyper-beam", "safeguard", "outrage", "wing-attack"]]]}, +"TRAINER_LEADER_BROCK": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["geodude", 12, 0, 13, ["tackle", "defense-curl"]], ["onix", 14, 0, 23, ["tackle", "bind", "rock-tomb"]]]}, +"TRAINER_LEADER_MISTY": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["super-potion"], "party": [["staryu", 18, 0, 11, ["tackle", "harden", "recover", "water-pulse"]], ["starmie", 21, 0, 4, ["swift", "recover", "rapid-spin", "water-pulse"]]]}, +"TRAINER_LEADER_LT_SURGE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["super-potion", "full-heal"], "party": [["voltorb", 21, 0, 9, ["sonic-boom", "tackle", "screech", "shock-wave"]], ["pikachu", 18, 0, 22, ["quick-attack", "thunder-wave", "double-team", "shock-wave"]], ["raichu", 24, 0, 15, ["quick-attack", "thunder-wave", "double-team", "shock-wave"]]]}, +"TRAINER_LEADER_ERIKA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "full-heal"], "party": [["victreebel", 29, 0, 5, ["stun-spore", "acid", "poison-powder", "giga-drain"]], ["tangela", 24, 0, 21, ["poison-powder", "constrict", "ingrain", "giga-drain"]], ["vileplume", 29, 0, 24, ["sleep-powder", "acid", "stun-spore", "giga-drain"]]]}, +"TRAINER_LEADER_KOGA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "hyper-potion", "full-heal"], "party": [["koffing", 37, 0, 24, ["self-destruct", "sludge", "smokescreen", "toxic"]], ["muk", 39, 0, 10, ["minimize", "sludge", "acid-armor", "toxic"]], ["koffing", 37, 0, 23, ["self-destruct", "sludge", "smokescreen", "toxic"]], ["weezing", 43, 0, 12, ["tackle", "sludge", "smokescreen", "toxic"]]]}, +"TRAINER_LEADER_BLAINE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "hyper-potion", "full-heal"], "party": [["growlithe", 42, 0, 11, ["bite", "roar", "take-down", "fire-blast"]], ["ponyta", 40, 0, 7, ["stomp", "bounce", "fire-spin", "fire-blast"]], ["rapidash", 42, 0, 20, ["stomp", "bounce", "fire-spin", "fire-blast"]], ["arcanine", 47, 0, 17, ["bite", "roar", "take-down", "fire-blast"]]]}, +"TRAINER_LEADER_SABRINA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "hyper-potion", "full-heal"], "party": [["kadabra", 38, 0, 6, ["psybeam", "reflect", "future-sight", "calm-mind"]], ["mr-mime", 37, 0, 12, ["barrier", "psybeam", "baton-pass", "calm-mind"]], ["venomoth", 38, 0, 8, ["psybeam", "gust", "leech-life", "supersonic"]], ["alakazam", 43, 0, 3, ["psychic", "recover", "future-sight", "calm-mind"]]]}, +"TRAINER_GENTLEMAN_THOMAS": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 18, 0, 9, ["bite", "roar", "ember", "leer"]], ["growlithe", 18, 0, 7, ["bite", "roar", "ember", "leer"]]]}, +"TRAINER_GENTLEMAN_ARTHUR": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 19, 0, 21, ["peck", "focus-energy", "double-kick", "poison-sting"]], ["nidoran-f", 19, 0, 12, ["scratch", "tail-whip", "double-kick", "poison-sting"]]]}, +"TRAINER_GENTLEMAN_TUCKER": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 23, 0, 1, ["thunder-wave", "quick-attack", "double-team", "slam"]]]}, +"TRAINER_GENTLEMAN_NORTON": {"ai": ["check-bad-move"], "items": [], "party": [["persian", 48, 0, 12, ["pay-day", "feint-attack", "screech", "fury-swipes"]]]}, +"TRAINER_GENTLEMAN_WALTER": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 17, 0, 2, ["bite", "roar", "ember", "leer"]], ["ponyta", 17, 0, 14, ["quick-attack", "growl", "tail-whip", "ember"]]]}, +"TRAINER_RIVAL_SS_ANNE_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 19, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["raticate", 16, 50, 3, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["kadabra", 18, 50, 14, ["teleport", "kinesis", "confusion", "disable"]], ["wartortle", 20, 100, 21, ["bubble", "withdraw", "water-gun", "bite"]]]}, +"TRAINER_RIVAL_SS_ANNE_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 19, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["raticate", 16, 50, 3, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["kadabra", 18, 50, 14, ["teleport", "kinesis", "confusion", "disable"]], ["ivysaur", 20, 100, 12, ["leech-seed", "vine-whip", "poison-powder", "sleep-powder"]]]}, +"TRAINER_RIVAL_SS_ANNE_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 19, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["raticate", 16, 50, 3, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["kadabra", 18, 50, 14, ["teleport", "kinesis", "confusion", "disable"]], ["charmeleon", 20, 100, 9, ["growl", "ember", "metal-claw", "smokescreen"]]]}, +"TRAINER_RIVAL_POKEMON_TOWER_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 25, 100, 17, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["growlithe", 23, 100, 9, ["roar", "ember", "leer", "odor-sleuth"]], ["exeggcute", 22, 100, 6, ["hypnosis", "reflect", "leech-seed", "confusion"]], ["kadabra", 20, 100, 17, ["teleport", "kinesis", "confusion", "disable"]], ["wartortle", 25, 100, 24, ["withdraw", "water-gun", "bite", "rapid-spin"]]]}, +"TRAINER_RIVAL_POKEMON_TOWER_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 25, 100, 17, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["gyarados", 23, 100, 6, ["thrash", "bite"]], ["growlithe", 22, 100, 23, ["roar", "ember", "leer", "odor-sleuth"]], ["kadabra", 20, 100, 9, ["teleport", "kinesis", "confusion", "disable"]], ["ivysaur", 25, 100, 7, ["vine-whip", "poison-powder", "sleep-powder", "razor-leaf"]]]}, +"TRAINER_RIVAL_POKEMON_TOWER_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 25, 100, 17, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["exeggcute", 23, 100, 14, ["hypnosis", "reflect", "leech-seed", "confusion"]], ["gyarados", 22, 100, 3, ["thrash", "bite"]], ["kadabra", 20, 100, 14, ["teleport", "kinesis", "confusion", "disable"]], ["charmeleon", 25, 100, 9, ["growl", "ember", "metal-claw", "smokescreen"]]]}, +"TRAINER_RIVAL_SILPH_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 37, 100, 0, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["growlithe", 38, 100, 17, ["odor-sleuth", "take-down", "flame-wheel", "helping-hand"]], ["exeggcute", 35, 100, 14, ["leech-seed", "confusion", "stun-spore", "poison-powder"]], ["alakazam", 35, 100, 9, ["reflect", "recover", "future-sight", "calm-mind"]], ["blastoise", 40, 150, 11, ["water-gun", "bite", "rapid-spin", "protect"]]]}, +"TRAINER_RIVAL_SILPH_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 37, 100, 0, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["gyarados", 38, 100, 14, ["bite", "dragon-rage", "leer", "twister"]], ["growlithe", 35, 100, 6, ["leer", "odor-sleuth", "take-down", "flame-wheel"]], ["alakazam", 35, 100, 1, ["reflect", "recover", "future-sight", "calm-mind"]], ["venusaur", 40, 150, 1, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]]]}, +"TRAINER_RIVAL_SILPH_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 37, 100, 0, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["exeggcute", 38, 100, 22, ["confusion", "stun-spore", "poison-powder", "sleep-powder"]], ["gyarados", 35, 100, 11, ["bite", "dragon-rage", "leer", "twister"]], ["alakazam", 35, 100, 6, ["reflect", "recover", "future-sight", "calm-mind"]], ["charizard", 40, 150, 24, ["smokescreen", "scary-face", "flamethrower", "wing-attack"]]]}, +"TRAINER_RIVAL_ROUTE22_LATE_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 47, 150, 0, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, 150, 19, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["growlithe", 45, 150, 11, ["flame-wheel", "take-down", "leer", "agility"]], ["exeggcute", 45, 150, 8, ["solar-beam", "sleep-powder", "poison-powder", "stun-spore"]], ["alakazam", 47, 150, 3, ["psychic", "calm-mind", "future-sight", "disable"]], ["blastoise", 53, 250, 5, ["water-gun", "rain-dance", "bite", "rapid-spin"]]]}, +"TRAINER_RIVAL_ROUTE22_LATE_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 47, 150, 0, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, 150, 19, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["gyarados", 45, 150, 8, ["hydro-pump", "twister", "leer", "rain-dance"]], ["growlithe", 45, 150, 0, ["flame-wheel", "take-down", "leer", "agility"]], ["alakazam", 47, 150, 20, ["psychic", "calm-mind", "future-sight", "disable"]], ["venusaur", 53, 250, 20, ["razor-leaf", "sweet-scent", "growth", "synthesis"]]]}, +"TRAINER_RIVAL_ROUTE22_LATE_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 47, 150, 0, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, 150, 19, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["exeggcute", 45, 150, 16, ["solar-beam", "sleep-powder", "poison-powder", "stun-spore"]], ["gyarados", 45, 150, 5, ["hydro-pump", "twister", "leer", "rain-dance"]], ["alakazam", 47, 150, 0, ["psychic", "calm-mind", "future-sight", "disable"]], ["charizard", 53, 250, 18, ["flamethrower", "wing-attack", "slash", "scary-face"]]]}, +"TRAINER_CHAMPION_FIRST_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["pidgeot", 59, 255, 0, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, 255, 20, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, 255, 16, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["arcanine", 59, 255, 5, ["extreme-speed", "flamethrower", "roar", "bite"]], ["exeggutor", 61, 255, 2, ["giga-drain", "egg-bomb", "sleep-powder", "light-screen"]], ["blastoise", 63, 255, 4, ["hydro-pump", "rain-dance", "skull-bash", "bite"]]]}, +"TRAINER_CHAMPION_FIRST_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["pidgeot", 59, 255, 0, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, 255, 20, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, 255, 16, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["gyarados", 59, 255, 5, ["hydro-pump", "dragon-rage", "bite", "thrash"]], ["arcanine", 61, 255, 19, ["extreme-speed", "flamethrower", "roar", "bite"]], ["venusaur", 63, 255, 19, ["solar-beam", "synthesis", "sunny-day", "growth"]]]}, +"TRAINER_CHAMPION_FIRST_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["pidgeot", 59, 255, 0, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, 255, 20, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, 255, 16, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["exeggutor", 59, 255, 13, ["giga-drain", "egg-bomb", "sleep-powder", "light-screen"]], ["gyarados", 61, 255, 2, ["hydro-pump", "dragon-rage", "bite", "thrash"]], ["charizard", 63, 255, 20, ["fire-blast", "aerial-ace", "slash", "fire-spin"]]]}, +"TRAINER_CHANNELER_PATRICIA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 10, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_CARLY": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 4, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_HOPE": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 23, 0, 23, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_PAULA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 6, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_LAUREL": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 23, 0, 5, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 23, 0, 15, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_JODY": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 8, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_TAMMY": {"ai": ["check-bad-move"], "items": [], "party": [["haunter", 23, 0, 16, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_RUTH": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 11, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_KARINA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 15, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_JANAE": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 11, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_ANGELICA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 10, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 22, 0, 0, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 22, 0, 15, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_EMILIA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 10, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_JENNIFER": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 9, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_1": {"ai": ["check-bad-move"], "items": [], "party": [["haunter", 23, 0, 4, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_2": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_3": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_4": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_5": {"ai": ["check-bad-move"], "items": [], "party": [["haunter", 22, 0, 4, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_6": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 22, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 22, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_7": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_8": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_AMANDA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 34, 0, 20, ["night-shade", "confuse-ray", "dream-eater", "destiny-bond"]], ["haunter", 34, 0, 4, ["night-shade", "confuse-ray", "shadow-punch", "dream-eater"]]]}, +"TRAINER_CHANNELER_STACY": {"ai": ["check-bad-move"], "items": [], "party": [["haunter", 38, 0, 17, ["night-shade", "confuse-ray", "shadow-punch", "dream-eater"]]]}, +"TRAINER_CHANNELER_TASHA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 33, 0, 19, ["night-shade", "confuse-ray", "dream-eater", "destiny-bond"]], ["gastly", 33, 0, 18, ["night-shade", "confuse-ray", "dream-eater", "destiny-bond"]], ["haunter", 33, 0, 1, ["night-shade", "confuse-ray", "shadow-punch", "dream-eater"]]]}, +"TRAINER_HIKER_JEREMY": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 20, 0, 20, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["onix", 20, 0, 8, ["screech", "bind", "rock-throw", "harden"]]]}, +"TRAINER_PICNICKER_ALMA": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 28, 0, 5, ["water-sport", "supersonic", "horn-attack", "flail"]], ["poliwag", 28, 0, 16, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["horsea", 28, 0, 9, ["bubble", "smokescreen", "leer", "water-gun"]]]}, +"TRAINER_PICNICKER_SUSIE": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 24, 0, 5, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["meowth", 24, 0, 23, ["scratch", "growl", "bite", "pay-day"]], ["rattata", 24, 0, 14, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["pikachu", 24, 0, 8, ["thunder-wave", "quick-attack", "double-team", "slam"]], ["meowth", 24, 0, 1, ["scratch", "growl", "bite", "pay-day"]]]}, +"TRAINER_PICNICKER_VALERIE": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 30, 0, 24, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["poliwag", 30, 0, 3, ["hypnosis", "water-gun", "double-slap", "rain-dance"]]]}, +"TRAINER_PICNICKER_GWEN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 27, 0, 20, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["meowth", 27, 0, 3, ["growl", "bite", "pay-day", "feint-attack"]], ["pidgey", 27, 0, 3, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 27, 0, 21, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, +"TRAINER_BIKER_VIRGIL": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 28, 0, 15, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, 0, 18, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 28, 0, 22, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_CAMPER_FLINT": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 14, 0, 5, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["ekans", 14, 0, 6, ["wrap", "leer", "poison-sting", "bite"]]]}, +"TRAINER_PICNICKER_MISSY": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 31, 0, 19, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 31, 0, 17, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_PICNICKER_IRENE": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 30, 0, 5, ["constrict", "acid", "bubble-beam", "wrap"]], ["horsea", 30, 0, 8, ["smokescreen", "leer", "water-gun", "twister"]], ["seel", 30, 0, 4, ["growl", "icy-wind", "aurora-beam", "rest"]]]}, +"TRAINER_PICNICKER_DANA": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 20, 0, 4, ["scratch", "growl", "bite", "pay-day"]], ["oddish", 20, 0, 13, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["pidgey", 20, 0, 14, ["sand-attack", "gust", "quick-attack", "whirlwind"]]]}, +"TRAINER_PICNICKER_ARIANA": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 19, 0, 22, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["rattata", 19, 0, 5, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["rattata", 19, 0, 13, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["bellsprout", 19, 0, 23, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]]]}, +"TRAINER_PICNICKER_LEAH": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 22, 0, 15, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]], ["clefairy", 22, 0, 12, ["sing", "double-slap", "follow-me", "minimize"]]]}, +"TRAINER_CAMPER_JUSTIN": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 29, 0, 13, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]], ["nidorino", 29, 0, 8, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]]]}, +"TRAINER_PICNICKER_YAZMIN": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 29, 0, 19, ["sleep-powder", "poison-powder", "stun-spore", "acid"]], ["oddish", 29, 0, 18, ["poison-powder", "stun-spore", "sleep-powder", "acid"]], ["tangela", 29, 0, 14, ["growth", "poison-powder", "vine-whip", "bind"]]]}, +"TRAINER_PICNICKER_KINDRA": {"ai": ["check-bad-move"], "items": [], "party": [["gloom", 28, 0, 10, ["poison-powder", "stun-spore", "sleep-powder", "acid"]], ["oddish", 28, 0, 23, ["poison-powder", "stun-spore", "sleep-powder", "acid"]], ["oddish", 28, 0, 11, ["poison-powder", "stun-spore", "sleep-powder", "acid"]]]}, +"TRAINER_PICNICKER_BECKY": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 29, 0, 2, ["quick-attack", "double-team", "slam", "thunderbolt"]], ["raichu", 29, 0, 14, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, +"TRAINER_PICNICKER_CELIA": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 33, 0, 7, ["minimize", "defense-curl", "metronome", "cosmic-power"]]]}, +"TRAINER_GENTLEMAN_BROOKS": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 23, 0, 13, ["thunder-wave", "quick-attack", "double-team", "slam"]]]}, +"TRAINER_GENTLEMAN_LAMAR": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 17, 0, 7, ["bite", "roar", "ember", "leer"]], ["ponyta", 17, 0, 24, ["quick-attack", "growl", "tail-whip", "ember"]]]}, +"TRAINER_TWINS_ELI_ANNE": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 22, 0, 22, ["sing", "double-slap", "follow-me", "minimize"]], ["jigglypuff", 22, 0, 13, ["defense-curl", "pound", "disable", "rollout"]]]}, +"TRAINER_COOL_COUPLE_RAY_TYRA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["nidoqueen", 45, 100, 1, ["superpower", "body-slam", "double-kick", "poison-sting"]], ["nidoking", 45, 100, 7, ["megahorn", "thrash", "double-kick", "poison-sting"]]]}, +"TRAINER_YOUNG_COUPLE_GIA_JES": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 24, 0, 23, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]], ["nidoran-f", 24, 0, 24, ["double-kick", "poison-sting", "bite", "helping-hand"]]]}, +"TRAINER_TWINS_KIRI_JAN": {"ai": ["check-bad-move"], "items": [], "party": [["charmander", 29, 0, 12, ["ember", "metal-claw", "smokescreen", "scary-face"]], ["squirtle", 29, 0, 5, ["water-gun", "bite", "rapid-spin", "protect"]]]}, +"TRAINER_CRUSH_KIN_RON_MYA": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 29, 50, 0, ["mach-punch", "thunder-punch", "ice-punch", "fire-punch"]], ["hitmonlee", 29, 50, 7, ["jump-kick", "brick-break", "focus-energy", "high-jump-kick"]]]}, +"TRAINER_YOUNG_COUPLE_LEA_JED": {"ai": ["check-bad-move"], "items": [], "party": [["rapidash", 29, 0, 0, ["tail-whip", "ember", "stomp", "fire-spin"]], ["ninetales", 29, 0, 1, ["ember", "quick-attack", "confuse-ray", "safeguard"]]]}, +"TRAINER_SIS_AND_BRO_LIA_LUC": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 30, 0, 1, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 30, 0, 23, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_SIS_AND_BRO_LIL_IAN": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 33, 0, 20, ["smokescreen", "leer", "water-gun", "twister"]], ["starmie", 33, 0, 0, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_YOUNGSTER_BEN_3": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 28, 60, 0, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["ekans", 28, 60, 4, ["poison-sting", "bite", "glare", "screech"]]]}, +"TRAINER_YOUNGSTER_BEN_4": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 48, 120, 0, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["arbok", 48, 120, 11, ["acid", "stockpile", "swallow", "spit-up"]]]}, +"TRAINER_YOUNGSTER_CHAD_2": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 20, 20, 1, ["leer", "poison-sting", "bite", "glare"]], ["sandshrew", 20, 20, 21, ["scratch", "defense-curl", "sand-attack", "poison-sting"]]]}, +"TRAINER_LASS_RELI_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 20, 20, 15, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["nidoran-f", 20, 20, 22, ["tail-whip", "double-kick", "poison-sting", "bite"]]]}, +"TRAINER_LASS_RELI_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 28, 60, 8, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["nidorina", 28, 60, 18, ["double-kick", "poison-sting", "bite", "helping-hand"]]]}, +"TRAINER_YOUNGSTER_TIMMY_2": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 19, 20, 11, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["ekans", 19, 20, 1, ["wrap", "leer", "poison-sting", "bite"]], ["zubat", 19, 20, 11, ["leech-life", "astonish", "supersonic", "bite"]]]}, +"TRAINER_YOUNGSTER_TIMMY_3": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 27, 60, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["ekans", 27, 60, 1, ["poison-sting", "bite", "glare", "screech"]], ["golbat", 27, 60, 24, ["astonish", "supersonic", "bite", "wing-attack"]]]}, +"TRAINER_YOUNGSTER_TIMMY_4": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 52, 120, 11, ["scary-face", "pursuit", "super-fang", "endeavor"]], ["arbok", 52, 120, 8, ["acid", "stockpile", "swallow", "spit-up"]], ["golbat", 52, 120, 6, ["confuse-ray", "air-cutter", "mean-look", "poison-fang"]]]}, +"TRAINER_YOUNGSTER_CHAD_3": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 28, 60, 8, ["poison-sting", "bite", "glare", "screech"]], ["sandshrew", 28, 60, 3, ["defense-curl", "sand-attack", "poison-sting", "slash"]]]}, +"TRAINER_LASS_JANICE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 20, 20, 3, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["pidgeotto", 20, 20, 11, ["sand-attack", "gust", "quick-attack", "whirlwind"]]]}, +"TRAINER_LASS_JANICE_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 28, 60, 3, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 28, 60, 11, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, +"TRAINER_YOUNGSTER_CHAD_4": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 48, 80, 8, ["acid", "stockpile", "swallow", "spit-up"]], ["sandslash", 48, 80, 19, ["poison-sting", "slash", "swift", "fury-swipes"]]]}, +"TRAINER_HIKER_FRANKLIN_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 25, 40, 22, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["graveler", 25, 40, 16, ["mud-sport", "rock-throw", "magnitude", "self-destruct"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_42": {"ai": ["check-bad-move"], "items": [], "party": [["houndour", 49, 0, 20, ["odor-sleuth", "feint-attack", "flamethrower", "crunch"]], ["houndour", 49, 0, 4, ["odor-sleuth", "feint-attack", "flamethrower", "crunch"]]]}, +"TRAINER_PSYCHIC_JACLYN": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 48, 100, 6, ["night-shade", "confuse-ray", "future-sight", "wish"]], ["slowbro", 48, 100, 3, ["psychic", "headbutt", "amnesia", "yawn"]], ["kadabra", 49, 100, 4, ["psychic", "future-sight", "recover", "reflect"]]]}, +"TRAINER_CRUSH_GIRL_SHARON": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 37, 50, 17, ["focus-energy", "seismic-toss", "cross-chop", "swagger"]], ["primeape", 37, 50, 14, ["focus-energy", "seismic-toss", "rage", "cross-chop"]]]}, +"TRAINER_TUBER_AMIRA": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 34, 0, 3, ["water-gun", "double-slap", "rain-dance", "body-slam"]], ["poliwhirl", 35, 0, 11, ["water-gun", "double-slap", "rain-dance", "body-slam"]], ["poliwag", 34, 0, 3, ["water-gun", "double-slap", "rain-dance", "body-slam"]]]}, +"TRAINER_PKMN_BREEDER_ALIZE": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 48, 30, 10, ["slam", "thunderbolt", "agility", "thunder"]], ["clefairy", 48, 30, 10, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["marill", 48, 30, 19, ["bubble-beam", "double-edge", "rain-dance", "hydro-pump"]]]}, +"TRAINER_PKMN_RANGER_NICOLAS": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["weepinbell", 51, 100, 14, ["razor-leaf", "acid", "sweet-scent", "wrap"]], ["victreebel", 51, 100, 5, ["razor-leaf", "acid", "sleep-powder", "stun-spore"]]]}, +"TRAINER_PKMN_RANGER_MADELINE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["gloom", 51, 100, 3, ["petal-dance", "acid", "sweet-scent", "poison-powder"]], ["vileplume", 51, 100, 18, ["petal-dance", "moonlight", "acid", "stun-spore"]]]}, +"TRAINER_AROMA_LADY_NIKKI": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 37, 0, 24, ["stun-spore", "acid", "sweet-scent", "razor-leaf"]], ["weepinbell", 37, 0, 6, ["poison-powder", "stun-spore", "acid", "sweet-scent"]]]}, +"TRAINER_RUIN_MANIAC_STANLY": {"ai": ["check-bad-move"], "items": [], "party": [["graveler", 48, 0, 9, ["self-destruct", "rollout", "rock-blast", "earthquake"]], ["onix", 48, 0, 12, ["dragon-breath", "sandstorm", "slam", "iron-tail"]], ["graveler", 48, 0, 10, ["self-destruct", "rollout", "rock-blast", "earthquake"]]]}, +"TRAINER_LADY_JACKI": {"ai": ["check-bad-move"], "items": ["full-restore"], "party": [["hoppip", 48, 0, 21, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]], ["skiploom", 50, 0, 18, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]]]}, +"TRAINER_PAINTER_DAISY": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 50, 50, 22, ["dynamic-punch", "dizzy-punch", "focus-punch", "mega-punch"]]]}, +"TRAINER_BIKER_GOON": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 37, 0, 1, ["haze", "smokescreen", "sludge", "tackle"]], ["grimer", 37, 0, 12, ["acid-armor", "screech", "minimize", "sludge"]]]}, +"TRAINER_BIKER_GOON_2": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 38, 0, 1, ["haze", "smokescreen", "sludge", "tackle"]]]}, +"TRAINER_BIKER_GOON_3": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 38, 0, 22, ["sludge", "minimize", "screech", "acid-armor"]]]}, +"TRAINER_BUG_CATCHER_ANTHONY": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 7, 0, 20, ["tackle", "string-shot"]], ["caterpie", 8, 0, 4, ["tackle", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_CHARLIE": {"ai": ["check-bad-move"], "items": [], "party": [["metapod", 7, 0, 15, ["harden"]], ["caterpie", 7, 0, 3, ["tackle", "string-shot"]], ["metapod", 7, 0, 7, ["harden"]]]}, +"TRAINER_TWINS_ELI_ANNE_2": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 28, 60, 22, ["double-slap", "follow-me", "minimize", "defense-curl"]], ["jigglypuff", 28, 60, 13, ["pound", "disable", "rollout", "double-slap"]]]}, +"TRAINER_YOUNGSTER_JOHNSON": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 33, 0, 23, ["bite", "glare", "screech", "acid"]], ["ekans", 33, 0, 10, ["bite", "glare", "screech", "acid"]], ["raticate", 34, 0, 7, ["quick-attack", "hyper-fang", "scary-face", "pursuit"]]]}, +"TRAINER_BIKER_RICARDO": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 22, 0, 1, ["sludge", "smog", "tackle", "poison-gas"]], ["koffing", 22, 0, 16, ["sludge", "smog", "tackle", "poison-gas"]], ["grimer", 23, 0, 2, ["minimize", "sludge", "disable", "pound"]]]}, +"TRAINER_BIKER_JAREN": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 24, 0, 20, ["harden", "disable", "sludge", "minimize"]], ["grimer", 24, 0, 4, ["harden", "disable", "sludge", "minimize"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_43": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 37, 0, 2, ["bonemerang", "rage", "false-swipe", "thrash"]], ["marowak", 37, 0, 16, ["leer", "focus-energy", "bonemerang", "rage"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_44": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 35, 0, 19, ["hyper-fang", "focus-energy", "pursuit", "super-fang"]], ["raticate", 35, 0, 19, ["quick-attack", "hyper-fang", "scary-face", "pursuit"]], ["sandshrew", 35, 0, 14, ["sand-attack", "poison-sting", "slash", "swift"]], ["sandslash", 35, 0, 0, ["sand-attack", "poison-sting", "slash", "swift"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_45": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 38, 0, 21, ["wing-attack", "confuse-ray", "air-cutter", "mean-look"]], ["zubat", 38, 0, 6, ["wing-attack", "confuse-ray", "air-cutter", "mean-look"]], ["golbat", 38, 0, 4, ["bite", "wing-attack", "confuse-ray", "air-cutter"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_46": {"ai": ["check-bad-move"], "items": [], "party": [["muk", 48, 0, 14, ["minimize", "screech", "acid-armor", "sludge-bomb"]], ["golbat", 48, 0, 12, ["wing-attack", "confuse-ray", "air-cutter", "mean-look"]], ["raticate", 48, 0, 12, ["hyper-fang", "scary-face", "pursuit", "super-fang"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_47": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 48, 0, 3, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machop", 48, 0, 20, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machoke", 48, 0, 3, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_48": {"ai": ["check-bad-move"], "items": [], "party": [["hypno", 49, 0, 19, ["meditate", "psychic", "psych-up", "swagger"]], ["hypno", 49, 0, 2, ["meditate", "psychic", "psych-up", "swagger"]]]}, +"TRAINER_TEAM_ROCKET_ADMIN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["muk", 52, 150, 5, ["sludge-bomb", "screech", "minimize", "rock-tomb"]], ["arbok", 53, 150, 18, ["sludge-bomb", "bite", "earthquake", "iron-tail"]], ["vileplume", 54, 150, 3, ["sludge-bomb", "giga-drain", "sleep-powder", "stun-spore"]]]}, +"TRAINER_TEAM_ROCKET_ADMIN_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["golbat", 53, 200, 0, ["confuse-ray", "sludge-bomb", "air-cutter", "shadow-ball"]], ["weezing", 54, 200, 22, ["sludge-bomb", "thunderbolt", "explosion", "shadow-ball"]], ["houndoom", 55, 200, 6, ["flamethrower", "crunch", "iron-tail", "shadow-ball"]]]}, +"TRAINER_SCIENTIST_GIDEON": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 46, 0, 17, ["swift", "screech", "spark", "sonic-boom"]], ["electrode", 46, 0, 3, ["spark", "sonic-boom", "screech", "charge"]], ["magnemite", 46, 0, 14, ["screech", "swift", "spark", "thunder-wave"]], ["magneton", 46, 0, 21, ["tri-attack", "spark", "thunder-wave", "sonic-boom"]], ["porygon", 46, 0, 13, ["tri-attack", "conversion", "recover", "psybeam"]]]}, +"TRAINER_SWIMMER_FEMALE_AMARA": {"ai": ["check-bad-move"], "items": [], "party": [["seel", 36, 0, 14, ["growl", "icy-wind", "aurora-beam", "rest"]], ["seel", 36, 0, 8, ["growl", "icy-wind", "aurora-beam", "rest"]], ["dewgong", 36, 0, 4, ["icy-wind", "aurora-beam", "rest", "sheer-cold"]]]}, +"TRAINER_SWIMMER_FEMALE_MARIA": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 37, 0, 11, ["smokescreen", "leer", "water-gun", "twister"]], ["seadra", 37, 0, 2, ["smokescreen", "leer", "water-gun", "twister"]]]}, +"TRAINER_SWIMMER_FEMALE_ABIGAIL": {"ai": ["check-bad-move"], "items": [], "party": [["psyduck", 35, 0, 9, ["disable", "confusion", "screech", "psych-up"]], ["psyduck", 36, 0, 23, ["disable", "confusion", "screech", "psych-up"]], ["golduck", 37, 0, 6, ["disable", "confusion", "screech", "psych-up"]]]}, +"TRAINER_SWIMMER_MALE_FINN": {"ai": ["check-bad-move"], "items": [], "party": [["starmie", 38, 0, 5, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_SWIMMER_MALE_GARRETT": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 35, 0, 8, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["cloyster", 35, 0, 9, ["withdraw", "supersonic", "aurora-beam", "protect"]], ["wartortle", 38, 0, 16, ["bite", "rapid-spin", "protect", "rain-dance"]]]}, +"TRAINER_FISHERMAN_TOMMY": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 33, 0, 16, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["goldeen", 33, 0, 21, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 35, 0, 0, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 35, 0, 4, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 35, 0, 8, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_CRUSH_GIRL_TANYA": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonlee", 38, 50, 7, ["focus-energy", "high-jump-kick", "mind-reader", "foresight"]], ["hitmonchan", 38, 50, 18, ["ice-punch", "fire-punch", "sky-uppercut", "mega-punch"]]]}, +"TRAINER_BLACK_BELT_SHEA": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 38, 100, 5, ["foresight", "revenge", "vital-throw", "submission"]], ["machoke", 38, 100, 15, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, +"TRAINER_BLACK_BELT_HUGH": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 37, 100, 21, ["foresight", "revenge", "vital-throw", "submission"]], ["machoke", 37, 100, 22, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, +"TRAINER_CAMPER_BRYCE": {"ai": ["check-bad-move"], "items": [], "party": [["nidorino", 36, 0, 0, ["poison-sting", "horn-attack", "helping-hand", "fury-attack"]], ["raticate", 36, 0, 13, ["quick-attack", "hyper-fang", "scary-face", "pursuit"]], ["sandslash", 36, 0, 12, ["sand-attack", "poison-sting", "slash", "swift"]]]}, +"TRAINER_PICNICKER_CLAIRE": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 35, 0, 4, ["bite", "pay-day", "feint-attack", "screech"]], ["meowth", 35, 0, 13, ["bite", "pay-day", "feint-attack", "screech"]], ["pikachu", 35, 0, 23, ["double-team", "slam", "thunderbolt", "agility"]], ["clefairy", 35, 0, 9, ["minimize", "defense-curl", "metronome", "cosmic-power"]]]}, +"TRAINER_CRUSH_KIN_MIK_KIA": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 39, 50, 16, ["seismic-toss", "foresight", "revenge", "vital-throw"]], ["primeape", 39, 50, 7, ["focus-energy", "seismic-toss", "rage", "cross-chop"]]]}, +"TRAINER_AROMA_LADY_VIOLET": {"ai": ["check-bad-move"], "items": [], "party": [["bulbasaur", 36, 0, 15, ["sleep-powder", "razor-leaf", "sweet-scent", "growth"]], ["ivysaur", 36, 0, 11, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]], ["ivysaur", 36, 0, 7, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]]]}, +"TRAINER_TUBER_ALEXIS": {"ai": ["check-bad-move"], "items": [], "party": [["staryu", 34, 0, 22, ["camouflage", "swift", "bubble-beam", "minimize"]], ["staryu", 34, 0, 8, ["camouflage", "swift", "bubble-beam", "minimize"]], ["krabby", 34, 0, 24, ["harden", "mud-shot", "stomp", "guillotine"]], ["krabby", 34, 0, 15, ["harden", "mud-shot", "stomp", "guillotine"]]]}, +"TRAINER_TWINS_JOY_MEG": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 37, 0, 21, ["defense-curl", "metronome", "cosmic-power", "moonlight"]], ["clefairy", 37, 0, 14, ["defense-curl", "metronome", "cosmic-power", "moonlight"]]]}, +"TRAINER_SWIMMER_FEMALE_TISHA": {"ai": ["check-bad-move"], "items": [], "party": [["kingler", 38, 0, 10, ["harden", "mud-shot", "stomp", "guillotine"]]]}, +"TRAINER_PAINTER_CELINA": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 50, 50, 4, ["fly", "dig", "dive", "bounce"]]]}, +"TRAINER_PAINTER_RAYNA": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 50, 50, 3, ["cross-chop", "megahorn", "double-edge", "self-destruct"]]]}, +"TRAINER_LADY_GILLIAN": {"ai": ["check-bad-move"], "items": ["full-restore"], "party": [["mareep", 47, 0, 1, ["thunder-wave", "cotton-spore", "light-screen", "thunder"]], ["mareep", 48, 0, 16, ["thunder-wave", "cotton-spore", "light-screen", "thunder"]], ["flaaffy", 49, 0, 16, ["thunder-wave", "cotton-spore", "light-screen", "thunder"]]]}, +"TRAINER_YOUNGSTER_DESTIN": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 48, 0, 23, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["pidgeotto", 48, 0, 5, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, +"TRAINER_SWIMMER_MALE_TOBY": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 48, 0, 23, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["tentacool", 48, 0, 8, ["bubble-beam", "wrap", "barrier", "screech"]], ["tentacruel", 48, 0, 18, ["bubble-beam", "wrap", "barrier", "screech"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_49": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 48, 0, 19, ["focus-energy", "pursuit", "super-fang", "endeavor"]], ["grimer", 48, 0, 20, ["minimize", "screech", "acid-armor", "sludge-bomb"]], ["muk", 48, 0, 23, ["minimize", "screech", "acid-armor", "sludge-bomb"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_50": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 49, 0, 16, ["memento", "haze", "smokescreen", "sludge"]], ["weezing", 49, 0, 22, ["haze", "smokescreen", "sludge", "self-destruct"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_51": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 48, 50, 1, ["stockpile", "swallow", "spit-up", "haze"]], ["gloom", 48, 50, 13, ["sleep-powder", "acid", "moonlight", "petal-dance"]], ["gloom", 48, 50, 0, ["sleep-powder", "acid", "moonlight", "petal-dance"]]]}, +"TRAINER_BIRD_KEEPER_MILO": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 47, 0, 11, ["wing-attack", "feather-dance", "agility", "mirror-move"]], ["pidgeotto", 49, 0, 4, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, +"TRAINER_BIRD_KEEPER_CHAZ": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 47, 0, 22, ["aerial-ace", "mirror-move", "drill-peck", "agility"]], ["fearow", 49, 0, 18, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, +"TRAINER_BIRD_KEEPER_HAROLD": {"ai": ["check-bad-move"], "items": [], "party": [["hoothoot", 47, 0, 4, ["hypnosis", "reflect", "take-down", "confusion"]], ["noctowl", 49, 0, 22, ["hypnosis", "reflect", "take-down", "confusion"]]]}, +"TRAINER_FISHERMAN_TYLOR": {"ai": ["check-bad-move"], "items": [], "party": [["qwilfish", 49, 0, 2, ["revenge", "take-down", "hydro-pump", "destiny-bond"]], ["qwilfish", 49, 0, 18, ["revenge", "take-down", "hydro-pump", "destiny-bond"]]]}, +"TRAINER_SWIMMER_MALE_MYMO": {"ai": ["check-bad-move"], "items": [], "party": [["kingler", 49, 0, 14, ["mud-shot", "stomp", "guillotine", "protect"]], ["wartortle", 49, 0, 10, ["rapid-spin", "protect", "rain-dance", "skull-bash"]]]}, +"TRAINER_SWIMMER_FEMALE_NICOLE": {"ai": ["check-bad-move"], "items": [], "party": [["marill", 50, 0, 0, ["bubble-beam", "double-edge", "rain-dance", "hydro-pump"]]]}, +"TRAINER_SIS_AND_BRO_AVA_GEB": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 50, 0, 23, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["starmie", 50, 0, 14, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_AROMA_LADY_ROSE": {"ai": ["check-bad-move"], "items": [], "party": [["sunkern", 49, 0, 0, ["endeavor", "sunny-day", "synthesis", "giga-drain"]], ["sunflora", 49, 0, 20, ["bullet-seed", "sunny-day", "petal-dance", "solar-beam"]]]}, +"TRAINER_SWIMMER_MALE_SAMIR": {"ai": ["check-bad-move"], "items": [], "party": [["gyarados", 50, 0, 19, ["twister", "hydro-pump", "rain-dance", "dragon-dance"]]]}, +"TRAINER_SWIMMER_FEMALE_DENISE": {"ai": ["check-bad-move"], "items": [], "party": [["chinchou", 49, 0, 16, ["confuse-ray", "take-down", "hydro-pump", "charge"]], ["lanturn", 49, 0, 10, ["water-gun", "spark", "confuse-ray", "take-down"]]]}, +"TRAINER_TWINS_MIU_MIA": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 50, 0, 16, ["thunderbolt", "agility", "thunder", "light-screen"]], ["pikachu", 50, 0, 4, ["thunderbolt", "agility", "thunder", "light-screen"]]]}, +"TRAINER_HIKER_EARL": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 49, 0, 2, ["dragon-breath", "sandstorm", "slam", "iron-tail"]], ["machoke", 49, 0, 5, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_RUIN_MANIAC_FOSTER": {"ai": ["check-bad-move"], "items": [], "party": [["golem", 50, 0, 22, ["self-destruct", "rollout", "rock-blast", "earthquake"]]]}, +"TRAINER_RUIN_MANIAC_LARRY": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 49, 0, 8, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machoke", 49, 0, 5, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_HIKER_DARYL": {"ai": ["check-bad-move"], "items": [], "party": [["sudowoodo", 50, 0, 6, ["rock-slide", "block", "feint-attack", "slam"]]]}, +"TRAINER_POKEMANIAC_HECTOR": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 49, 30, 19, ["scary-face", "rock-blast", "horn-drill", "take-down"]], ["kangaskhan", 49, 30, 11, ["rage", "endure", "dizzy-punch", "reversal"]]]}, +"TRAINER_PSYCHIC_DARIO": {"ai": ["check-bad-move"], "items": [], "party": [["girafarig", 52, 100, 23, ["crunch", "psybeam", "odor-sleuth", "agility"]]]}, +"TRAINER_PSYCHIC_RODETTE": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 48, 100, 4, ["night-shade", "confuse-ray", "wish", "future-sight"]], ["drowzee", 48, 100, 1, ["psychic", "disable", "psych-up", "future-sight"]], ["hypno", 50, 100, 8, ["psychic", "hypnosis", "psych-up", "future-sight"]]]}, +"TRAINER_AROMA_LADY_MIAH": {"ai": ["check-bad-move"], "items": [], "party": [["bellossom", 50, 0, 11, ["sweet-scent", "stun-spore", "magical-leaf", "petal-dance"]], ["bellossom", 50, 0, 2, ["sweet-scent", "stun-spore", "magical-leaf", "petal-dance"]]]}, +"TRAINER_YOUNG_COUPLE_EVE_JON": {"ai": ["check-bad-move"], "items": [], "party": [["golduck", 50, 0, 20, ["confusion", "screech", "psych-up", "fury-swipes"]], ["psyduck", 50, 0, 18, ["screech", "psych-up", "fury-swipes", "hydro-pump"]]]}, +"TRAINER_JUGGLER_MASON": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 47, 0, 24, ["swift", "light-screen", "spark", "sonic-boom"]], ["pineco", 47, 0, 19, ["spikes", "bide", "rapid-spin", "take-down"]], ["voltorb", 47, 0, 7, ["swift", "light-screen", "spark", "sonic-boom"]], ["pineco", 47, 0, 2, ["spikes", "bide", "rapid-spin", "explosion"]]]}, +"TRAINER_CRUSH_GIRL_CYNDY": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 48, 50, 18, ["seismic-toss", "rage", "cross-chop", "swagger"]], ["hitmontop", 48, 50, 23, ["rapid-spin", "counter", "agility", "detect"]], ["machoke", 48, 50, 2, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_CRUSH_GIRL_JOCELYN": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 38, 50, 17, ["ice-punch", "fire-punch", "sky-uppercut", "mega-punch"]], ["hitmonchan", 38, 50, 23, ["ice-punch", "fire-punch", "sky-uppercut", "mega-punch"]]]}, +"TRAINER_TAMER_EVAN": {"ai": ["check-bad-move"], "items": [], "party": [["sandslash", 48, 40, 3, ["poison-sting", "slash", "swift", "fury-swipes"]], ["lickitung", 48, 40, 24, ["wrap", "disable", "slam", "screech"]], ["ursaring", 49, 40, 10, ["rest", "slash", "snore", "thrash"]]]}, +"TRAINER_POKEMANIAC_MARK_2": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 33, 90, 6, ["stomp", "fury-attack", "scary-face", "rock-blast"]], ["lickitung", 33, 90, 8, ["defense-curl", "knock-off", "stomp", "wrap"]]]}, +"TRAINER_PKMN_RANGER_LOGAN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["exeggcute", 37, 100, 11, ["sleep-powder", "poison-powder", "stun-spore", "confusion"]], ["exeggutor", 40, 100, 11, ["egg-bomb", "stomp", "confusion", "hypnosis"]]]}, +"TRAINER_PKMN_RANGER_JACKSON": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["tangela", 49, 100, 8, ["slam", "mega-drain", "bind", "ingrain"]], ["exeggcute", 49, 100, 9, ["confusion", "poison-powder", "barrage", "reflect"]], ["exeggutor", 49, 100, 10, ["confusion", "egg-bomb", "sleep-powder", "stomp"]]]}, +"TRAINER_PKMN_RANGER_BETH": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["bellsprout", 38, 100, 19, ["stun-spore", "acid", "sweet-scent", "razor-leaf"]], ["gloom", 38, 100, 20, ["stun-spore", "sleep-powder", "acid", "moonlight"]], ["gloom", 38, 100, 21, ["stun-spore", "sleep-powder", "acid", "moonlight"]]]}, +"TRAINER_PKMN_RANGER_KATELYN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["chansey", 52, 100, 22, ["egg-bomb", "defense-curl", "minimize", "soft-boiled"]]]}, +"TRAINER_COOLTRAINER_LEROY": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["rhydon", 47, 100, 16, ["take-down", "horn-drill", "rock-blast", "scary-face"]], ["slowbro", 48, 100, 7, ["psychic", "headbutt", "amnesia", "disable"]], ["kangaskhan", 47, 100, 19, ["dizzy-punch", "bite", "endure", "reversal"]], ["machoke", 48, 100, 22, ["cross-chop", "vital-throw", "revenge", "seismic-toss"]], ["ursaring", 50, 100, 22, ["slash", "feint-attack", "snore", "rest"]]]}, +"TRAINER_COOLTRAINER_MICHELLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["persian", 47, 100, 4, ["slash", "screech", "feint-attack", "bite"]], ["dewgong", 47, 100, 21, ["ice-beam", "take-down", "icy-wind", "growl"]], ["ninetales", 48, 100, 14, ["flamethrower", "confuse-ray", "will-o-wisp", "grudge"]], ["rapidash", 48, 100, 3, ["bounce", "agility", "fire-spin", "take-down"]], ["girafarig", 50, 100, 8, ["crunch", "psybeam", "stomp", "odor-sleuth"]]]}, +"TRAINER_COOL_COUPLE_LEX_NYA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["miltank", 52, 100, 22, ["body-slam", "milk-drink", "growl", "defense-curl"]], ["tauros", 52, 100, 9, ["thrash", "horn-attack", "pursuit", "swagger"]]]}, +"TRAINER_RUIN_MANIAC_BRANDON": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 50, 0, 17, ["dragon-breath", "sandstorm", "slam", "iron-tail"]]]}, +"TRAINER_RUIN_MANIAC_BENJAMIN": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 48, 0, 0, ["earthquake", "rock-blast", "rollout", "self-destruct"]], ["graveler", 48, 0, 17, ["earthquake", "rock-blast", "rock-throw", "self-destruct"]], ["graveler", 48, 0, 9, ["earthquake", "rock-blast", "rock-throw", "self-destruct"]]]}, +"TRAINER_PAINTER_EDNA": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 50, 50, 2, ["fake-out", "extreme-speed", "protect", "quick-attack"]]]}, +"TRAINER_GENTLEMAN_CLIFFORD": {"ai": ["check-bad-move"], "items": [], "party": [["marowak", 49, 0, 6, ["bonemerang", "rage", "false-swipe", "thrash"]], ["golduck", 49, 0, 22, ["confusion", "screech", "psych-up", "fury-swipes"]]]}, +"TRAINER_LADY_SELPHY": {"ai": ["check-bad-move"], "items": ["full-restore"], "party": [["persian", 49, 0, 21, ["pay-day", "bite", "taunt", "torment"]], ["persian", 49, 0, 6, ["pay-day", "scratch", "torment", "taunt"]]]}, +"TRAINER_RUIN_MANIAC_LAWSON": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 47, 0, 22, ["dragon-breath", "sandstorm", "slam", "iron-tail"]], ["graveler", 48, 0, 3, ["self-destruct", "rollout", "rock-blast", "earthquake"]], ["marowak", 49, 0, 7, ["bonemerang", "rage", "false-swipe", "thrash"]]]}, +"TRAINER_PSYCHIC_LAURA": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 48, 100, 18, ["teleport", "wish", "future-sight", "confuse-ray"]], ["natu", 48, 100, 16, ["teleport", "wish", "future-sight", "confuse-ray"]], ["xatu", 49, 100, 24, ["night-shade", "teleport", "wish", "future-sight"]]]}, +"TRAINER_PKMN_BREEDER_BETHANY": {"ai": ["check-bad-move"], "items": [], "party": [["chansey", 50, 30, 10, ["sing", "egg-bomb", "defense-curl", "light-screen"]]]}, +"TRAINER_PKMN_BREEDER_ALLISON": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 48, 30, 17, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["clefairy", 48, 30, 23, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["clefable", 48, 30, 6, ["sing", "double-slap", "minimize", "metronome"]]]}, +"TRAINER_BUG_CATCHER_GARRET": {"ai": ["check-bad-move"], "items": [], "party": [["heracross", 49, 0, 1, ["brick-break", "counter", "take-down", "reversal"]]]}, +"TRAINER_BUG_CATCHER_JONAH": {"ai": ["check-bad-move"], "items": [], "party": [["yanma", 45, 0, 8, ["detect", "uproar", "wing-attack", "supersonic"]], ["beedrill", 45, 0, 6, ["pursuit", "pin-missile", "agility", "endeavor"]], ["yanma", 46, 0, 3, ["detect", "uproar", "wing-attack", "supersonic"]], ["beedrill", 47, 0, 1, ["pursuit", "pin-missile", "agility", "endeavor"]]]}, +"TRAINER_BUG_CATCHER_VANCE": {"ai": ["check-bad-move"], "items": [], "party": [["venonat", 48, 0, 19, ["stun-spore", "psybeam", "sleep-powder", "psychic"]], ["venomoth", 48, 0, 19, ["stun-spore", "gust", "psybeam", "sleep-powder"]]]}, +"TRAINER_YOUNGSTER_NASH": {"ai": ["check-bad-move"], "items": [], "party": [["weepinbell", 47, 0, 5, ["stun-spore", "acid", "sweet-scent", "razor-leaf"]], ["weepinbell", 47, 0, 24, ["stun-spore", "acid", "sweet-scent", "razor-leaf"]], ["victreebel", 49, 0, 6, ["vine-whip", "sleep-powder", "sweet-scent", "razor-leaf"]]]}, +"TRAINER_YOUNGSTER_CORDELL": {"ai": ["check-bad-move"], "items": [], "party": [["farfetch-d", 48, 0, 12, ["swords-dance", "agility", "slash", "false-swipe"]], ["farfetch-d", 48, 0, 13, ["swords-dance", "agility", "slash", "false-swipe"]]]}, +"TRAINER_LASS_DALIA": {"ai": ["check-bad-move"], "items": [], "party": [["hoppip", 46, 0, 13, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]], ["hoppip", 47, 0, 6, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]], ["skiploom", 47, 0, 11, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]], ["skiploom", 48, 0, 16, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]]]}, +"TRAINER_LASS_JOANA": {"ai": ["check-bad-move"], "items": [], "party": [["snubbull", 49, 0, 17, ["lick", "roar", "rage", "take-down"]]]}, +"TRAINER_CAMPER_RILEY": {"ai": ["check-bad-move"], "items": [], "party": [["pinsir", 49, 0, 11, ["brick-break", "guillotine", "submission", "swords-dance"]], ["heracross", 50, 0, 10, ["brick-break", "counter", "take-down", "reversal"]]]}, +"TRAINER_PICNICKER_MARCY": {"ai": ["check-bad-move"], "items": [], "party": [["paras", 48, 0, 20, ["spore", "slash", "growth", "giga-drain"]], ["paras", 48, 0, 20, ["spore", "slash", "growth", "giga-drain"]], ["parasect", 49, 0, 11, ["leech-life", "spore", "slash", "growth"]]]}, +"TRAINER_RUIN_MANIAC_LAYTON": {"ai": ["check-bad-move"], "items": [], "party": [["sandslash", 48, 0, 5, ["poison-sting", "slash", "swift", "fury-swipes"]], ["onix", 48, 0, 9, ["dragon-breath", "sandstorm", "slam", "iron-tail"]], ["sandslash", 48, 0, 3, ["poison-sting", "slash", "swift", "fury-swipes"]]]}, +"TRAINER_PICNICKER_KELSEY_2": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 21, 20, 1, ["focus-energy", "double-kick", "poison-sting", "horn-attack"]], ["nidoran-f", 21, 20, 13, ["tail-whip", "double-kick", "poison-sting", "bite"]]]}, +"TRAINER_PICNICKER_KELSEY_3": {"ai": ["check-bad-move"], "items": [], "party": [["nidorino", 29, 60, 19, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]], ["nidorina", 29, 60, 9, ["double-kick", "poison-sting", "bite", "helping-hand"]]]}, +"TRAINER_PICNICKER_KELSEY_4": {"ai": ["check-bad-move"], "items": [], "party": [["nidorino", 49, 80, 19, ["horn-attack", "helping-hand", "fury-attack", "flatter"]], ["nidorina", 49, 80, 9, ["bite", "helping-hand", "fury-swipes", "flatter"]]]}, +"TRAINER_CAMPER_RICKY_2": {"ai": ["check-bad-move"], "items": [], "party": [["squirtle", 22, 20, 16, ["bubble", "withdraw", "water-gun", "bite"]]]}, +"TRAINER_CAMPER_RICKY_3": {"ai": ["check-bad-move"], "items": [], "party": [["wartortle", 30, 60, 23, ["withdraw", "water-gun", "bite", "rapid-spin"]]]}, +"TRAINER_CAMPER_RICKY_4": {"ai": ["check-bad-move"], "items": [], "party": [["wartortle", 55, 120, 23, ["protect", "rain-dance", "skull-bash", "hydro-pump"]]]}, +"TRAINER_CAMPER_JEFF_2": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 21, 20, 6, ["growl", "leer", "fury-attack", "pursuit"]], ["raticate", 21, 20, 22, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, +"TRAINER_CAMPER_JEFF_3": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 29, 60, 16, ["growl", "leer", "fury-attack", "pursuit"]], ["raticate", 29, 60, 7, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, +"TRAINER_CAMPER_JEFF_4": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 54, 120, 16, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["raticate", 54, 120, 7, ["scary-face", "pursuit", "super-fang", "endeavor"]]]}, +"TRAINER_PICNICKER_ISABELLE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 21, 20, 23, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["pidgeotto", 21, 20, 1, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["pidgey", 18, 20, 11, ["tackle", "sand-attack", "gust", "quick-attack"]]]}, +"TRAINER_PICNICKER_ISABELLE_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 29, 60, 23, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 29, 60, 1, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 26, 60, 4, ["sand-attack", "gust", "quick-attack", "whirlwind"]]]}, +"TRAINER_PICNICKER_ISABELLE_4": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 47, 80, 23, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["pidgeotto", 47, 80, 1, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["pidgeot", 50, 80, 12, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, +"TRAINER_YOUNGSTER_YASU_2": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 22, 40, 19, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["raticate", 22, 40, 19, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["raticate", 22, 40, 19, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, +"TRAINER_YOUNGSTER_YASU_3": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 47, 80, 11, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["raticate", 47, 80, 11, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["raticate", 47, 80, 11, ["hyper-fang", "scary-face", "pursuit", "super-fang"]]]}, +"TRAINER_ENGINEER_BERNIE_2": {"ai": ["check-bad-move"], "items": [], "party": [["magneton", 28, 60, 12, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["magneton", 28, 60, 13, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["magneton", 28, 60, 14, ["supersonic", "sonic-boom", "thunder-wave", "spark"]]]}, +"TRAINER_GAMER_DARIAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 29, 60, 10, ["ember", "leer", "odor-sleuth", "take-down"]], ["vulpix", 29, 60, 8, ["will-o-wisp", "confuse-ray", "imprison", "flamethrower"]]]}, +"TRAINER_CAMPER_CHRIS_2": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 24, 40, 4, ["roar", "ember", "leer", "odor-sleuth"]], ["charmander", 24, 40, 21, ["growl", "ember", "metal-claw", "smokescreen"]]]}, +"TRAINER_CAMPER_CHRIS_3": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 29, 60, 4, ["ember", "leer", "odor-sleuth", "take-down"]], ["charmeleon", 29, 60, 0, ["ember", "metal-claw", "smokescreen", "scary-face"]]]}, +"TRAINER_CAMPER_CHRIS_4": {"ai": ["check-bad-move"], "items": [], "party": [["arcanine", 54, 120, 1, ["roar", "ember", "odor-sleuth", "extreme-speed"]], ["charmeleon", 54, 120, 22, ["scary-face", "flamethrower", "slash", "dragon-rage"]]]}, +"TRAINER_PICNICKER_ALICIA_2": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 25, 40, 1, ["growl", "bite", "pay-day", "feint-attack"]]]}, +"TRAINER_PICNICKER_ALICIA_3": {"ai": ["check-bad-move"], "items": [], "party": [["persian", 30, 60, 5, ["growl", "bite", "pay-day", "feint-attack"]]]}, +"TRAINER_PICNICKER_ALICIA_4": {"ai": ["check-bad-move"], "items": [], "party": [["persian", 55, 120, 5, ["screech", "fury-swipes", "slash", "fake-out"]]]}, +"TRAINER_HIKER_JEREMY_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 30, 60, 11, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["onix", 28, 60, 24, ["bind", "rock-throw", "harden", "rage"]]]}, +"TRAINER_POKEMANIAC_MARK_3": {"ai": ["check-bad-move"], "items": [], "party": [["rhydon", 54, 150, 8, ["scary-face", "rock-blast", "horn-drill", "take-down"]], ["lickitung", 54, 150, 10, ["disable", "slam", "screech", "refresh"]]]}, +"TRAINER_POKEMANIAC_HERMAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["marowak", 29, 90, 15, ["headbutt", "leer", "focus-energy", "bonemerang"]], ["slowbro", 29, 90, 1, ["water-gun", "confusion", "disable", "headbutt"]]]}, +"TRAINER_POKEMANIAC_HERMAN_3": {"ai": ["check-bad-move"], "items": [], "party": [["marowak", 54, 150, 15, ["rage", "false-swipe", "thrash", "bone-rush"]], ["slowbro", 54, 150, 1, ["headbutt", "amnesia", "withdraw", "psychic"]]]}, +"TRAINER_HIKER_TRENT_2": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 31, 60, 14, ["rock-throw", "harden", "rage", "dragon-breath"]], ["graveler", 31, 60, 12, ["rock-throw", "magnitude", "self-destruct", "rollout"]]]}, +"TRAINER_LASS_MEGAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 22, 40, 0, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["raticate", 22, 40, 10, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["nidoran-m", 23, 40, 3, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]], ["meowth", 21, 40, 23, ["scratch", "growl", "bite", "pay-day"]], ["pikachu", 22, 40, 19, ["thunder-wave", "quick-attack", "double-team", "slam"]]]}, +"TRAINER_LASS_MEGAN_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeot", 46, 80, 8, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["raticate", 47, 80, 18, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["nidorino", 47, 80, 4, ["horn-attack", "helping-hand", "fury-attack", "flatter"]], ["persian", 47, 80, 3, ["pay-day", "feint-attack", "screech", "fury-swipes"]], ["raichu", 48, 80, 4, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, +"TRAINER_SUPER_NERD_GLENN_2": {"ai": ["check-bad-move"], "items": [], "party": [["muk", 28, 60, 21, ["disable", "sludge", "minimize", "screech"]], ["muk", 28, 60, 6, ["disable", "sludge", "minimize", "screech"]], ["muk", 28, 60, 16, ["disable", "sludge", "minimize", "screech"]]]}, +"TRAINER_GAMER_RICH_2": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 30, 60, 24, ["ember", "leer", "odor-sleuth", "take-down"]], ["vulpix", 30, 60, 11, ["will-o-wisp", "confuse-ray", "imprison", "flamethrower"]]]}, +"TRAINER_BIKER_JAREN_2": {"ai": ["check-bad-move"], "items": [], "party": [["muk", 28, 60, 22, ["disable", "sludge", "minimize", "screech"]], ["muk", 30, 60, 8, ["disable", "sludge", "minimize", "screech"]]]}, +"TRAINER_FISHERMAN_ELLIOT_2": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 28, 60, 21, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["cloyster", 28, 60, 10, ["withdraw", "supersonic", "aurora-beam", "protect"]], ["seaking", 28, 60, 2, ["water-sport", "supersonic", "horn-attack", "flail"]], ["seadra", 28, 60, 20, ["bubble", "smokescreen", "leer", "water-gun"]]]}, +"TRAINER_ROCKER_LUCA_2": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 33, 60, 13, ["screech", "sonic-boom", "spark", "self-destruct"]], ["electrode", 33, 60, 15, ["screech", "sonic-boom", "spark", "self-destruct"]]]}, +"TRAINER_BEAUTY_SHEILA_2": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 49, 80, 17, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["persian", 49, 80, 16, ["feint-attack", "screech", "fury-swipes", "slash"]]]}, +"TRAINER_BIRD_KEEPER_ROBERT_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 28, 60, 10, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 28, 60, 9, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["fearow", 28, 60, 2, ["growl", "leer", "fury-attack", "pursuit"]], ["fearow", 28, 60, 20, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_ROBERT_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeot", 47, 80, 18, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["pidgeot", 47, 80, 0, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["fearow", 47, 80, 18, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 47, 80, 11, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, +"TRAINER_PICNICKER_SUSIE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 27, 60, 23, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["meowth", 27, 60, 16, ["growl", "bite", "pay-day", "feint-attack"]], ["raticate", 27, 60, 24, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["pikachu", 27, 60, 18, ["quick-attack", "double-team", "slam", "thunderbolt"]], ["meowth", 27, 60, 11, ["growl", "bite", "pay-day", "feint-attack"]]]}, +"TRAINER_PICNICKER_SUSIE_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 47, 80, 23, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["persian", 47, 80, 20, ["pay-day", "feint-attack", "screech", "fury-swipes"]], ["raticate", 47, 80, 3, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["pikachu", 47, 80, 22, ["slam", "thunderbolt", "agility", "thunder"]], ["persian", 47, 80, 19, ["pay-day", "feint-attack", "screech", "fury-swipes"]]]}, +"TRAINER_PICNICKER_SUSIE_4": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeot", 52, 120, 6, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["persian", 52, 120, 3, ["feint-attack", "screech", "fury-swipes", "slash"]], ["raticate", 52, 120, 11, ["scary-face", "pursuit", "super-fang", "endeavor"]], ["raichu", 52, 120, 10, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]], ["persian", 52, 120, 7, ["feint-attack", "screech", "fury-swipes", "slash"]]]}, +"TRAINER_BIKER_LUKAS_2": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 47, 80, 20, ["smokescreen", "haze", "explosion", "destiny-bond"]], ["koffing", 47, 80, 4, ["smokescreen", "haze", "explosion", "destiny-bond"]], ["muk", 47, 80, 11, ["minimize", "screech", "acid-armor", "sludge-bomb"]], ["weezing", 47, 80, 21, ["sludge", "smokescreen", "haze", "explosion"]]]}, +"TRAINER_BIRD_KEEPER_BENNY_2": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 32, 60, 5, ["leer", "fury-attack", "pursuit", "mirror-move"]], ["fearow", 32, 60, 24, ["leer", "fury-attack", "pursuit", "mirror-move"]]]}, +"TRAINER_BIRD_KEEPER_BENNY_3": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 49, 80, 5, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 49, 80, 24, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, +"TRAINER_BIRD_KEEPER_MARLON_2": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 30, 60, 24, ["growl", "leer", "fury-attack", "pursuit"]], ["doduo", 30, 60, 17, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["fearow", 30, 60, 5, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_MARLON_3": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 48, 80, 24, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["dodrio", 48, 80, 19, ["tri-attack", "rage", "uproar", "drill-peck"]], ["fearow", 48, 80, 7, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, +"TRAINER_BEAUTY_GRACE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeot", 49, 80, 22, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["wigglytuff", 49, 80, 7, ["sing", "disable", "defense-curl", "double-slap"]]]}, +"TRAINER_BIRD_KEEPER_CHESTER_2": {"ai": ["check-bad-move"], "items": [], "party": [["dodrio", 30, 60, 2, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["dodrio", 30, 60, 18, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["doduo", 30, 60, 7, ["pursuit", "fury-attack", "tri-attack", "rage"]]]}, +"TRAINER_BIRD_KEEPER_CHESTER_3": {"ai": ["check-bad-move"], "items": [], "party": [["dodrio", 48, 80, 2, ["tri-attack", "rage", "uproar", "drill-peck"]], ["dodrio", 48, 80, 18, ["tri-attack", "rage", "uproar", "drill-peck"]], ["dodrio", 48, 80, 9, ["tri-attack", "rage", "uproar", "drill-peck"]]]}, +"TRAINER_PICNICKER_BECKY_2": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 32, 60, 2, ["quick-attack", "double-team", "slam", "thunderbolt"]], ["raichu", 32, 60, 14, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, +"TRAINER_PICNICKER_BECKY_3": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 49, 80, 2, ["slam", "thunderbolt", "agility", "thunder"]], ["raichu", 49, 80, 14, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, +"TRAINER_PICNICKER_BECKY_4": {"ai": ["check-bad-move"], "items": [], "party": [["raichu", 54, 120, 7, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]], ["raichu", 54, 120, 19, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, +"TRAINER_CRUSH_KIN_RON_MYA_2": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 33, 110, 0, ["thunder-punch", "ice-punch", "fire-punch", "sky-uppercut"]], ["hitmonlee", 33, 110, 7, ["brick-break", "focus-energy", "high-jump-kick", "mind-reader"]]]}, +"TRAINER_CRUSH_KIN_RON_MYA_3": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 51, 130, 0, ["sky-uppercut", "mega-punch", "detect", "counter"]], ["hitmonlee", 51, 130, 7, ["foresight", "endure", "mega-kick", "reversal"]]]}, +"TRAINER_CRUSH_KIN_RON_MYA_4": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 56, 170, 0, ["sky-uppercut", "mega-punch", "detect", "counter"]], ["hitmonlee", 56, 170, 7, ["foresight", "endure", "mega-kick", "reversal"]]]}, +"TRAINER_BIKER_RUBEN_2": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 48, 80, 22, ["sludge", "smokescreen", "haze", "explosion"]], ["weezing", 48, 80, 8, ["sludge", "smokescreen", "haze", "explosion"]], ["weezing", 48, 80, 19, ["sludge", "smokescreen", "haze", "explosion"]]]}, +"TRAINER_CUE_BALL_CAMRON_2": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 49, 80, 17, ["seismic-toss", "rage", "cross-chop", "swagger"]], ["machoke", 49, 80, 20, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_BIKER_JAXON_2": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 49, 80, 21, ["sludge", "smokescreen", "haze", "explosion"]], ["muk", 49, 80, 3, ["minimize", "screech", "acid-armor", "sludge-bomb"]]]}, +"TRAINER_CUE_BALL_ISAIAH_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 49, 80, 12, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machamp", 49, 80, 7, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_CUE_BALL_COREY_2": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 49, 80, 13, ["seismic-toss", "rage", "cross-chop", "swagger"]], ["machamp", 49, 80, 6, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_BIRD_KEEPER_JACOB_2": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 28, 60, 6, ["growl", "leer", "fury-attack", "pursuit"]], ["spearow", 28, 60, 16, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 28, 60, 11, ["growl", "leer", "fury-attack", "pursuit"]], ["spearow", 28, 60, 21, ["leer", "fury-attack", "pursuit", "aerial-ace"]]]}, +"TRAINER_BIRD_KEEPER_JACOB_3": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 47, 80, 6, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 47, 80, 1, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 47, 80, 21, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 47, 80, 16, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, +"TRAINER_SWIMMER_FEMALE_ALICE_2": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 49, 80, 13, ["flail", "fury-attack", "waterfall", "horn-drill"]], ["seaking", 49, 80, 6, ["flail", "fury-attack", "waterfall", "horn-drill"]]]}, +"TRAINER_SWIMMER_MALE_DARRIN_2": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 52, 120, 0, ["water-gun", "twister", "agility", "hydro-pump"]], ["seadra", 52, 120, 14, ["water-gun", "twister", "agility", "hydro-pump"]], ["seadra", 52, 120, 3, ["water-gun", "twister", "agility", "hydro-pump"]], ["seadra", 52, 120, 17, ["water-gun", "twister", "agility", "hydro-pump"]]]}, +"TRAINER_PICNICKER_MISSY_2": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 49, 80, 18, ["flail", "fury-attack", "waterfall", "horn-drill"]], ["seaking", 49, 80, 16, ["flail", "fury-attack", "waterfall", "horn-drill"]]]}, +"TRAINER_PICNICKER_MISSY_3": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 54, 120, 18, ["flail", "fury-attack", "waterfall", "horn-drill"]], ["seaking", 54, 120, 16, ["flail", "fury-attack", "waterfall", "horn-drill"]]]}, +"TRAINER_FISHERMAN_WADE_2": {"ai": ["check-bad-move"], "items": [], "party": [["magikarp", 47, 80, 7, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 3, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 24, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 20, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 16, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 12, ["splash", "tackle", "flail"]]]}, +"TRAINER_SWIMMER_MALE_JACK_2": {"ai": ["check-bad-move"], "items": [], "party": [["starmie", 50, 80, 22, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_SIS_AND_BRO_LIL_IAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 50, 80, 20, ["leer", "water-gun", "twister", "agility"]], ["starmie", 50, 80, 0, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_SIS_AND_BRO_LIL_IAN_3": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 55, 120, 20, ["water-gun", "twister", "agility", "hydro-pump"]], ["starmie", 55, 120, 0, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_SWIMMER_MALE_FINN_2": {"ai": ["check-bad-move"], "items": [], "party": [["starmie", 50, 80, 5, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_CRUSH_GIRL_SHARON_2": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 50, 130, 17, ["cross-chop", "swagger", "screech", "thrash"]], ["primeape", 50, 130, 14, ["seismic-toss", "rage", "cross-chop", "swagger"]]]}, +"TRAINER_CRUSH_GIRL_SHARON_3": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 55, 170, 8, ["rage", "cross-chop", "swagger", "screech"]], ["primeape", 55, 170, 5, ["rage", "cross-chop", "swagger", "screech"]]]}, +"TRAINER_CRUSH_GIRL_TANYA_2": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonlee", 50, 130, 7, ["mind-reader", "foresight", "endure", "mega-kick"]], ["hitmonchan", 50, 130, 18, ["sky-uppercut", "mega-punch", "detect", "counter"]]]}, +"TRAINER_CRUSH_GIRL_TANYA_3": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonlee", 55, 170, 7, ["foresight", "endure", "mega-kick", "reversal"]], ["hitmonchan", 55, 170, 18, ["sky-uppercut", "mega-punch", "detect", "counter"]]]}, +"TRAINER_BLACK_BELT_SHEA_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 50, 180, 21, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machoke", 50, 180, 6, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_BLACK_BELT_SHEA_3": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 55, 220, 21, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machamp", 55, 220, 0, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, +"TRAINER_BLACK_BELT_HUGH_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 50, 180, 12, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machoke", 50, 180, 13, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_BLACK_BELT_HUGH_3": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 55, 220, 12, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machamp", 55, 220, 7, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, +"TRAINER_CRUSH_KIN_MIK_KIA_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 51, 130, 16, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["primeape", 51, 130, 7, ["seismic-toss", "rage", "cross-chop", "swagger"]]]}, +"TRAINER_CRUSH_KIN_MIK_KIA_3": {"ai": ["check-bad-move"], "items": [], "party": [["machamp", 56, 170, 10, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["primeape", 56, 170, 1, ["rage", "cross-chop", "swagger", "screech"]]]}, +"TRAINER_TUBER_AMIRA_2": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 47, 80, 19, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["poliwhirl", 47, 80, 2, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["poliwhirl", 47, 80, 10, ["double-slap", "rain-dance", "body-slam", "belly-drum"]]]}, +"TRAINER_TWINS_JOY_MEG_2": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 49, 80, 21, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["clefairy", 49, 80, 14, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]]]}, +"TRAINER_PAINTER_RAYNA_2": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 54, 120, 3, ["cross-chop", "megahorn", "double-edge", "self-destruct"]]]}, +"TRAINER_YOUNGSTER_DESTIN_2": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 53, 120, 23, ["scary-face", "pursuit", "super-fang", "endeavor"]], ["pidgeot", 53, 120, 13, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, +"TRAINER_PKMN_BREEDER_ALIZE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 53, 150, 10, ["thunderbolt", "agility", "thunder", "light-screen"]], ["clefairy", 53, 150, 10, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["marill", 53, 150, 19, ["bubble-beam", "double-edge", "rain-dance", "hydro-pump"]]]}, +"TRAINER_YOUNG_COUPLE_GIA_JES_2": {"ai": ["check-bad-move"], "items": [], "party": [["nidorina", 30, 60, 7, ["double-kick", "poison-sting", "bite", "helping-hand"]], ["nidorino", 30, 60, 20, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]]]}, +"TRAINER_YOUNG_COUPLE_GIA_JES_3": {"ai": ["check-bad-move"], "items": [], "party": [["nidoking", 55, 120, 1, ["double-kick", "poison-sting", "thrash", "megahorn"]], ["nidoqueen", 55, 120, 16, ["double-kick", "poison-sting", "body-slam", "superpower"]]]}, +"TRAINER_BIRD_KEEPER_MILO_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 53, 120, 4, ["wing-attack", "feather-dance", "agility", "mirror-move"]], ["pidgeot", 55, 120, 5, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, +"TRAINER_BIRD_KEEPER_CHAZ_2": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 53, 120, 7, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 55, 120, 3, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, +"TRAINER_BIRD_KEEPER_HAROLD_2": {"ai": ["check-bad-move"], "items": [], "party": [["noctowl", 53, 120, 4, ["hypnosis", "reflect", "take-down", "confusion"]], ["noctowl", 55, 120, 22, ["hypnosis", "reflect", "take-down", "confusion"]]]}, +"TRAINER_SWIMMER_FEMALE_NICOLE_2": {"ai": ["check-bad-move"], "items": [], "party": [["marill", 54, 120, 0, ["bubble-beam", "double-edge", "rain-dance", "hydro-pump"]]]}, +"TRAINER_PSYCHIC_JACLYN_2": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 52, 220, 6, ["psychic", "confuse-ray", "future-sight", "wish"]], ["slowbro", 52, 220, 3, ["psychic", "headbutt", "amnesia", "yawn"]], ["kadabra", 54, 220, 4, ["psychic", "future-sight", "recover", "reflect"]]]}, +"TRAINER_SWIMMER_MALE_SAMIR_2": {"ai": ["check-bad-move"], "items": [], "party": [["gyarados", 55, 120, 19, ["hydro-pump", "rain-dance", "dragon-dance", "hyper-beam"]]]}, +"TRAINER_HIKER_EARL_2": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 54, 120, 2, ["sandstorm", "slam", "iron-tail", "sand-tomb"]], ["machamp", 54, 120, 24, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, +"TRAINER_RUIN_MANIAC_LARRY_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 54, 120, 8, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machoke", 54, 120, 5, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, +"TRAINER_POKEMANIAC_HECTOR_2": {"ai": ["check-bad-move"], "items": [], "party": [["rhydon", 55, 150, 21, ["scary-face", "rock-blast", "horn-drill", "take-down"]], ["kangaskhan", 55, 150, 13, ["rage", "endure", "dizzy-punch", "reversal"]]]}, +"TRAINER_PSYCHIC_DARIO_2": {"ai": ["check-bad-move"], "items": [], "party": [["girafarig", 56, 220, 23, ["crunch", "psybeam", "odor-sleuth", "agility"]]]}, +"TRAINER_PSYCHIC_RODETTE_2": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 53, 220, 4, ["psychic", "confuse-ray", "wish", "future-sight"]], ["hypno", 53, 220, 11, ["psychic", "disable", "psych-up", "future-sight"]], ["hypno", 53, 220, 18, ["psychic", "hypnosis", "psych-up", "future-sight"]]]}, +"TRAINER_JUGGLER_MASON_2": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 52, 120, 4, ["self-destruct", "rollout", "light-screen", "swift"]], ["pineco", 52, 120, 24, ["bide", "explosion", "spikes", "double-edge"]], ["electrode", 52, 120, 17, ["self-destruct", "rollout", "light-screen", "swift"]], ["pineco", 52, 120, 12, ["bide", "explosion", "spikes", "double-edge"]]]}, +"TRAINER_PKMN_RANGER_NICOLAS_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["victreebel", 55, 220, 2, ["razor-leaf", "acid", "stun-spore", "wrap"]], ["victreebel", 55, 220, 18, ["razor-leaf", "acid", "sleep-powder", "slam"]]]}, +"TRAINER_PKMN_RANGER_MADELINE_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["vileplume", 55, 220, 10, ["petal-dance", "moonlight", "acid", "sleep-powder"]], ["vileplume", 55, 220, 0, ["petal-dance", "moonlight", "acid", "stun-spore"]]]}, +"TRAINER_CRUSH_GIRL_CYNDY_2": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 54, 170, 18, ["rage", "cross-chop", "swagger", "screech"]], ["hitmontop", 54, 170, 23, ["counter", "agility", "detect", "endeavor"]], ["machamp", 54, 170, 21, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, +"TRAINER_TAMER_EVAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["sandslash", 52, 160, 3, ["slash", "swift", "fury-swipes", "sand-tomb"]], ["lickitung", 52, 160, 24, ["disable", "slam", "screech", "refresh"]], ["ursaring", 55, 160, 10, ["rest", "slash", "snore", "thrash"]]]}, +"TRAINER_PKMN_RANGER_JACKSON_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["tangela", 53, 220, 8, ["slam", "mega-drain", "bind", "ingrain"]], ["exeggutor", 54, 220, 9, ["confusion", "egg-bomb", "stun-spore", "reflect"]], ["exeggutor", 55, 220, 10, ["confusion", "egg-bomb", "sleep-powder", "stomp"]]]}, +"TRAINER_PKMN_RANGER_KATELYN_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["chansey", 56, 220, 22, ["egg-bomb", "defense-curl", "minimize", "soft-boiled"]]]}, +"TRAINER_COOLTRAINER_LEROY_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["rhydon", 52, 220, 16, ["earthquake", "horn-drill", "rock-blast", "scary-face"]], ["slowbro", 54, 220, 7, ["psychic", "headbutt", "amnesia", "disable"]], ["kangaskhan", 52, 220, 19, ["dizzy-punch", "bite", "endure", "reversal"]], ["machamp", 52, 220, 16, ["cross-chop", "vital-throw", "revenge", "seismic-toss"]], ["ursaring", 55, 220, 16, ["slash", "feint-attack", "snore", "rest"]]]}, +"TRAINER_COOLTRAINER_MICHELLE_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["persian", 53, 220, 4, ["slash", "screech", "feint-attack", "bite"]], ["dewgong", 53, 220, 21, ["ice-beam", "take-down", "icy-wind", "sheer-cold"]], ["ninetales", 54, 220, 14, ["flamethrower", "confuse-ray", "will-o-wisp", "grudge"]], ["rapidash", 54, 220, 3, ["bounce", "agility", "fire-spin", "take-down"]], ["girafarig", 56, 220, 8, ["crunch", "psybeam", "stomp", "odor-sleuth"]]]}, +"TRAINER_COOL_COUPLE_LEX_NYA_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["miltank", 57, 220, 22, ["body-slam", "milk-drink", "growl", "defense-curl"]], ["tauros", 57, 220, 9, ["take-down", "scary-face", "pursuit", "swagger"]]]}, +"TRAINER_BUG_CATCHER_COLTON_2": {"ai": ["check-bad-move"], "items": [], "party": [["metapod", 19, 20, 12, ["harden"]], ["weedle", 19, 20, 2, ["poison-sting", "string-shot"]], ["metapod", 19, 20, 3, ["harden"]]]}, +"TRAINER_BUG_CATCHER_COLTON_3": {"ai": ["check-bad-move"], "items": [], "party": [["butterfree", 27, 60, 11, ["stun-spore", "sleep-powder", "supersonic", "whirlwind"]], ["kakuna", 27, 60, 6, ["harden"]], ["butterfree", 27, 60, 6, ["stun-spore", "sleep-powder", "supersonic", "whirlwind"]]]}, +"TRAINER_BUG_CATCHER_COLTON_4": {"ai": ["check-bad-move"], "items": [], "party": [["butterfree", 51, 120, 11, ["gust", "psybeam", "safeguard", "silver-wind"]], ["beedrill", 54, 120, 11, ["pursuit", "pin-missile", "agility", "endeavor"]], ["butterfree", 51, 120, 11, ["gust", "psybeam", "safeguard", "silver-wind"]]]}, +"TRAINER_SWIMMER_MALE_MATTHEW_2": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 49, 80, 14, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["poliwrath", 49, 80, 17, ["water-gun", "hypnosis", "double-slap", "submission"]]]}, +"TRAINER_SWIMMER_MALE_TONY_2": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 49, 80, 3, ["leer", "water-gun", "twister", "agility"]], ["seadra", 49, 80, 20, ["leer", "water-gun", "twister", "agility"]]]}, +"TRAINER_SWIMMER_FEMALE_MELISSA_2": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 49, 80, 1, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["seaking", 49, 80, 14, ["flail", "fury-attack", "waterfall", "horn-drill"]]]}, +"TRAINER_ELITE_FOUR_LORELEI_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["dewgong", 64, 255, 16, ["ice-beam", "surf", "signal-beam", "double-team"]], ["cloyster", 63, 255, 14, ["ice-beam", "surf", "supersonic", "rain-dance"]], ["piloswine", 63, 255, 8, ["blizzard", "earthquake", "double-edge", "rock-slide"]], ["jynx", 66, 255, 3, ["ice-beam", "psychic", "lovely-kiss", "attract"]], ["lapras", 66, 255, 19, ["ice-beam", "surf", "psychic", "thunder"]]]}, +"TRAINER_ELITE_FOUR_BRUNO_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["steelix", 65, 255, 12, ["earthquake", "iron-tail", "crunch", "rock-tomb"]], ["hitmonchan", 65, 255, 2, ["sky-uppercut", "mach-punch", "rock-slide", "counter"]], ["hitmonlee", 65, 255, 2, ["mega-kick", "foresight", "earthquake", "rock-slide"]], ["steelix", 66, 255, 3, ["earthquake", "iron-tail", "crunch", "dragon-breath"]], ["machamp", 68, 255, 20, ["cross-chop", "earthquake", "brick-break", "rock-slide"]]]}, +"TRAINER_ELITE_FOUR_AGATHA_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["gengar", 66, 255, 18, ["shadow-ball", "psychic", "confuse-ray", "hypnosis"]], ["crobat", 66, 255, 17, ["sludge-bomb", "air-cutter", "shadow-ball", "confuse-ray"]], ["misdreavus", 65, 255, 12, ["shadow-ball", "psychic", "thunderbolt", "attract"]], ["arbok", 68, 255, 23, ["sludge-bomb", "earthquake", "giga-drain", "double-team"]], ["gengar", 70, 255, 5, ["shadow-ball", "psychic", "thunderbolt", "sludge-bomb"]]]}, +"TRAINER_ELITE_FOUR_LANCE_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["gyarados", 68, 255, 19, ["hyper-beam", "dragon-dance", "earthquake", "thunder-wave"]], ["dragonite", 66, 255, 11, ["hyper-beam", "earthquake", "dragon-claw", "flamethrower"]], ["kingdra", 66, 255, 22, ["hyper-beam", "dragon-dance", "surf", "ice-beam"]], ["aerodactyl", 70, 255, 21, ["hyper-beam", "ancient-power", "aerial-ace", "earthquake"]], ["dragonite", 72, 255, 13, ["hyper-beam", "outrage", "thunderbolt", "ice-beam"]]]}, +"TRAINER_CHAMPION_REMATCH_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["heracross", 72, 255, 12, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, 255, 7, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, 255, 3, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["arcanine", 73, 255, 17, ["extreme-speed", "overheat", "aerial-ace", "iron-tail"]], ["exeggutor", 73, 255, 14, ["giga-drain", "psychic", "sleep-powder", "light-screen"]], ["blastoise", 75, 255, 16, ["hydro-pump", "ice-beam", "earthquake", "rain-dance"]]]}, +"TRAINER_CHAMPION_REMATCH_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["heracross", 72, 255, 12, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, 255, 7, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, 255, 3, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["gyarados", 73, 255, 17, ["hydro-pump", "dragon-dance", "earthquake", "hyper-beam"]], ["arcanine", 73, 255, 6, ["extreme-speed", "overheat", "aerial-ace", "iron-tail"]], ["venusaur", 75, 255, 6, ["solar-beam", "sludge-bomb", "earthquake", "sunny-day"]]]}, +"TRAINER_CHAMPION_REMATCH_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["heracross", 72, 255, 12, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, 255, 7, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, 255, 3, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["exeggutor", 73, 255, 0, ["giga-drain", "psychic", "sleep-powder", "light-screen"]], ["gyarados", 73, 255, 14, ["hydro-pump", "dragon-dance", "earthquake", "hyper-beam"]], ["charizard", 75, 255, 7, ["fire-blast", "dragon-claw", "aerial-ace", "earthquake"]]]}, +"TRAINER_CUE_BALL_PAXTON": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 39, 50, 18, ["self-destruct", "sludge", "smokescreen", "haze"]], ["muk", 39, 50, 22, ["sludge", "minimize", "screech", "acid-armor"]]]} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/type_chart.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/type_chart.json new file mode 100644 index 0000000000..555a4f323d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/type_chart.json @@ -0,0 +1,112 @@ +[ +["normal", "rock", 5], +["normal", "steel", 5], +["fire", "fire", 5], +["fire", "water", 5], +["fire", "grass", 20], +["fire", "ice", 20], +["fire", "bug", 20], +["fire", "rock", 5], +["fire", "dragon", 5], +["fire", "steel", 20], +["water", "fire", 20], +["water", "water", 5], +["water", "grass", 5], +["water", "ground", 20], +["water", "rock", 20], +["water", "dragon", 5], +["electric", "water", 20], +["electric", "electric", 5], +["electric", "grass", 5], +["electric", "ground", 0], +["electric", "flying", 20], +["electric", "dragon", 5], +["grass", "fire", 5], +["grass", "water", 20], +["grass", "grass", 5], +["grass", "poison", 5], +["grass", "ground", 20], +["grass", "flying", 5], +["grass", "bug", 5], +["grass", "rock", 20], +["grass", "dragon", 5], +["grass", "steel", 5], +["ice", "water", 5], +["ice", "grass", 20], +["ice", "ice", 5], +["ice", "ground", 20], +["ice", "flying", 20], +["ice", "dragon", 20], +["ice", "steel", 5], +["ice", "fire", 5], +["fighting", "normal", 20], +["fighting", "ice", 20], +["fighting", "poison", 5], +["fighting", "flying", 5], +["fighting", "psychic", 5], +["fighting", "bug", 5], +["fighting", "rock", 20], +["fighting", "dark", 20], +["fighting", "steel", 20], +["poison", "grass", 20], +["poison", "poison", 5], +["poison", "ground", 5], +["poison", "rock", 5], +["poison", "ghost", 5], +["poison", "steel", 0], +["ground", "fire", 20], +["ground", "electric", 20], +["ground", "grass", 5], +["ground", "poison", 20], +["ground", "flying", 0], +["ground", "bug", 5], +["ground", "rock", 20], +["ground", "steel", 20], +["flying", "electric", 5], +["flying", "grass", 20], +["flying", "fighting", 20], +["flying", "bug", 20], +["flying", "rock", 5], +["flying", "steel", 5], +["psychic", "fighting", 20], +["psychic", "poison", 20], +["psychic", "psychic", 5], +["psychic", "dark", 0], +["psychic", "steel", 5], +["bug", "fire", 5], +["bug", "grass", 20], +["bug", "fighting", 5], +["bug", "poison", 5], +["bug", "flying", 5], +["bug", "psychic", 20], +["bug", "ghost", 5], +["bug", "dark", 20], +["bug", "steel", 5], +["rock", "fire", 20], +["rock", "ice", 20], +["rock", "fighting", 5], +["rock", "ground", 5], +["rock", "flying", 20], +["rock", "bug", 20], +["rock", "steel", 5], +["ghost", "normal", 0], +["ghost", "psychic", 20], +["ghost", "dark", 5], +["ghost", "steel", 5], +["ghost", "ghost", 20], +["dragon", "dragon", 20], +["dragon", "steel", 5], +["dark", "fighting", 5], +["dark", "psychic", 20], +["dark", "ghost", 20], +["dark", "dark", 5], +["dark", "steel", 5], +["steel", "fire", 5], +["steel", "water", 5], +["steel", "electric", 5], +["steel", "ice", 20], +["steel", "rock", 20], +["steel", "steel", 5], +["normal", "ghost", 0], +["fighting", "ghost", 0] +] diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp new file mode 100644 index 0000000000..fb400f1e09 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -0,0 +1,233 @@ +/* AutoStory + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/Notifications/ProgramNotifications.h" +#include "CommonFramework/VideoPipeline/VideoOverlay.h" +#include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" +#include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/Pokemon_Strings.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" +#include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStoryTable.h" +#include "PokemonFRLG_AutoStory.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +AutoStory_Descriptor::AutoStory_Descriptor() + : SingleSwitchProgramDescriptor( + "PokemonFRLG:AutoStory", + Pokemon::STRING_POKEMON + " FRLG", "AutoStory", + "", + "Play FireRed (English) from a new game to the Boulder Badge.", + PanelQualityStanding::OFFICIAL_BETA, + ProgramControllerClass::StandardController_NoRestrictions, + FeedbackType::REQUIRED, + AllowCommandsWhenRunning::DISABLE_COMMANDS + ) +{} + +std::unique_ptr AutoStory_Descriptor::make_stats() const{ + return std::make_unique(); +} + + +namespace{ + +// The start and end dropdowns' entries: the table's checkpoints, 00.01 to +// 00.10. The options hold a reference to it. +const StringSelectDatabase& checkpoint_database(){ + static const StringSelectDatabase database = Pokemon::story_checkpoint_database(story_checkpoints()); + return database; +} + +} + +AutoStory::AutoStory() + : RUN(checkpoint_database()) + , NEW_GAME_FROM_TITLE( + "New game from the title screen:
The game is on its title screen with no save data. " + "Needed to start at 00.01. Otherwise the program loads the save, which must be the one the start checkpoint begins from.", + LockMode::LOCK_WHILE_RUNNING, + true + ) + , NOTIFICATIONS({ + &NOTIFICATION_PROGRAM_FINISH, + &NOTIFICATION_ERROR_FATAL, + }) +{ + PA_ADD_OPTION(RUN); + PA_ADD_OPTION(NEW_GAME_FROM_TITLE); + PA_ADD_OPTION(NOTIFICATIONS); +} + + +// The save loaded must be the one checkpoint `first` starts from: one left +// by an earlier checkpoint (a run that failed before saving) would start +// it in the wrong place (console B, 2026-11-01: 00.09 on the forest's +// save). Checked on the SAVE card; a card that can't be read is let pass. +static void check_start_save( + SingleSwitchProgramEnvironment& env, StoryEnv& story, const StoryCheckpoint& checkpoint +){ + if (!checkpoint.start){ + return; + } + const std::string error = check_save_place(story, checkpoint.start->map); + if (!error.empty()){ + throw UserSetupError(env.console, error + " Start at the checkpoint " + checkpoint.id + " the save is for."); + } +} + +namespace{ + +// A failed attempt reloads the last save, with the supplies it had, read +// from its bag again; the engine's lines go to the console's log. +Pokemon::SegmentHooks story_hooks(SingleSwitchProgramEnvironment& env, StoryEnv& story){ + Pokemon::SegmentHooks hooks; + hooks.reload = [&story](Pokemon::RunState&){ + if (!story.has_save){ + return Pokemon::outcome_failed("no_save", "nothing saved yet"); + } + // The save reloaded must be where the checkpoint starts: a save + // that didn't happen leaves an older one (console B, 2026-11-02: + // 00.02 walked the bedroom's route in Pewter City). + try{ + soft_reset(story.console, story.context); + const std::string error = check_save_place(story, story.start_map); + if (!error.empty()){ + return Pokemon::outcome_failed("wrong_save", error); + } + story.supplies = story.saved_supplies; + // Every reload, so each verify run starts from the bag as the + // save holds it, not from a count once read wrong or not at + // all (console B, 2026-11-03: 0 Potions in all 3 runs). + read_bag_supplies(story, story.start_menu); + }catch (OperationFailedException& e){ + return Pokemon::outcome_failed("reload_failed", e.message()); + } + return Pokemon::outcome_ok(); + }; + hooks.log = [&env](const std::string& line){ + env.console.log(line); + }; + // The checkpoint and the step under way, for whoever watches the stream. + hooks.status = [&env](const std::string& line){ + env.console.overlay().add_log(line); + }; + return hooks; +} + +// The game on the save checkpoint `checkpoint` starts from, with the +// supplies and moves read from it. +void load_verify_save( + SingleSwitchProgramEnvironment& env, ProControllerContext& context, StoryEnv& story, const StoryCheckpoint& checkpoint +){ + if (!checkpoint.start){ + throw UserSetupError(env.console, + "Verify mode reloads the checkpoint's save between runs: " + checkpoint.id + " starts a new game and has none." + ); + } + env.console.log("Verify mode: loading the save for " + checkpoint.id + "."); + soft_reset(env.console, context); + story.has_save = true; + check_start_save(env, story, checkpoint); + read_lead_moves(story, checkpoint.menu); + read_bag_supplies(story, checkpoint.menu); +} + +// Verify mode: the start checkpoint run from its save as `policy` says, +// never saving at its end, so every run starts from the same save. +// Throws unless enough runs pass. +void verify_story_checkpoint( + SingleSwitchProgramEnvironment& env, ProControllerContext& context, + const Pokemon::StoryRunOptions& run, const Pokemon::VerifyPolicy& policy, EventNotificationOption& finished +){ + const std::vector& checkpoints = story_checkpoints(); + const StoryCheckpoint& checkpoint = checkpoints[run.start_index()]; + StoryEnv story{env.console, context, checkpoint.supplies, checkpoint.supplies, false, run.checks()}; + load_verify_save(env, context, story, checkpoint); + StoryExecutor executor(story); + executor.set_checks(run.checks()); + executor.set_language(run.language()); + Pokemon::Segment segment = make_story_segment(checkpoints, executor); + Pokemon::SegmentHooks hooks = story_hooks(env, story); + + Pokemon::RunState state; + const Pokemon::VerifyReport report = Pokemon::verify_checkpoint(state, segment, checkpoint.id, policy, hooks); + const std::string summary = std::format( + "AutoStory verify: {} {}/{} passed, {} needed.", checkpoint.id, report.passes, policy.runs, policy.passes_needed + ); + if (!report.verified){ + throw OperationFailedException(ErrorReportMode::NO_ERROR_REPORT, summary); + } + env.console.log(summary); + send_program_finished_notification(env, finished, summary); +} + + +} + +void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ + if (const std::optional verify = RUN.VERIFY.policy()){ + verify_story_checkpoint(env, context, RUN, *verify, NOTIFICATION_PROGRAM_FINISH); + return; + } + const std::vector& checkpoints = story_checkpoints(); + const size_t first = RUN.start_index(); + const size_t last = RUN.end_index(); + if (first > last || last >= checkpoints.size()){ + throw UserSetupError(env.console, "The start checkpoint must not come after the end checkpoint."); + } + if (first == 0 && !NEW_GAME_FROM_TITLE){ + throw UserSetupError(env.console, "Checkpoint 00.01 starts a new game: start on the title screen with no save."); + } + + StoryEnv story{env.console, context, checkpoints[first].supplies, checkpoints[first].supplies, false, RUN.checks()}; + if (!(first == 0 && NEW_GAME_FROM_TITLE)){ + env.console.log("Loading the save for " + checkpoints[first].id + "."); + soft_reset(env.console, context); + story.has_save = true; + check_start_save(env, story, checkpoints[first]); + read_lead_moves(story, checkpoints[first].menu); + read_bag_supplies(story, checkpoints[first].menu); + } + + StoryExecutor executor(story); + executor.set_checks(RUN.checks()); + executor.set_language(RUN.language()); + Pokemon::Segment segment = make_story_segment(checkpoints, executor); + Pokemon::SegmentHooks hooks = story_hooks(env, story); + + Pokemon::RunState state; + const Pokemon::SegmentReport report = run_segment( + state, segment, Pokemon::SegmentRange{checkpoints[first].id, checkpoints[last].id}, RUN.policy(), hooks + ); + Pokemon::record_story_stats(env.current_stats(), report); + env.update_stats(); + if (!report.completed){ + throw OperationFailedException( + ErrorReportMode::NO_ERROR_REPORT, + std::format( + "AutoStory stopped at {} {}: {}", + report.failed_checkpoint, report.failed_event, Pokemon::to_string(report.failure) + ) + ); + } + env.console.log("AutoStory: done through " + checkpoints[last].id + "."); + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h new file mode 100644 index 0000000000..e92eb74549 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h @@ -0,0 +1,56 @@ +/* AutoStory + * + * From: https://github.com/PokemonAutomation/ + * + * Plays FireRed from a new game to the Boulder Badge, as the story + * checkpoints of PokemonFRLG_AutoStoryTable.h run by the shared story + * engine. Each checkpoint saves at its end; one that fails is retried from + * that save, as the shared retry options say. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStory_H +#define PokemonAutomation_PokemonFRLG_AutoStory_H + +#include "Common/Cpp/Options/BooleanCheckBoxOption.h" +#include "Common/Cpp/Options/EnumDropdownOption.h" +#include "CommonFramework/Notifications/EventNotificationsTable.h" +#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "Pokemon/Options/Pokemon_StoryRunOptions.h" +#include "PokemonFRLG_AutoStoryActions.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +class AutoStory_Descriptor : public SingleSwitchProgramDescriptor{ +public: + AutoStory_Descriptor(); + virtual std::unique_ptr make_stats() const override; +}; + +class AutoStory : public SingleSwitchProgramInstance{ +public: + using Descriptor = AutoStory_Descriptor; + AutoStory(); + virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override; + virtual void start_program_border_check( + VideoStream& stream, + FeedbackType feedback_type + ) override{} + +private: + // The start and end checkpoints, attempts, checks and language, as in + // every game's AutoStory. + Pokemon::StoryRunOptions RUN; + BooleanCheckBoxOption NEW_GAME_FROM_TITLE; + EventNotificationsOption NOTIFICATIONS; +}; + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp new file mode 100644 index 0000000000..a67e107e31 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -0,0 +1,846 @@ +/* AutoStory Actions + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/Tools/DebugDumper.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "CommonTools/Images/SolidColorTest.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_SelectionArrowDetector.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "VideoGames/PokemonFRLG/Programs/PokemonFRLG_StartMenuNavigation.h" +#include "PokemonFRLG_AutoStoryActions.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace std::chrono_literals; +using Pokemon::Direction; + + +namespace{ + +constexpr Milliseconds POLL = 300ms; +// Text without an arrow or a prompt this long: press anyway, for a last +// line that waits without an arrow (Oak's "Here, come with me!"). +constexpr Milliseconds TEXT_STILL = 4000ms; +// In the intro: A this often on a message box; how long with no box +// before checking for the bedroom; and before pressing A on a screen +// nothing reads. +constexpr Milliseconds INTRO_A_EVERY = 1500ms; +constexpr Milliseconds INTRO_QUIET = 3000ms; +constexpr Milliseconds INTRO_STUCK = 15000ms; +constexpr Milliseconds INTRO_TIMEOUT = 600000ms; +// "Wait about 8 s" after YES at the nurse (console B, 2026-11-01): 1.5 s +// between presses did not heal. +constexpr Milliseconds HEAL_TIME = 8000ms; +// FRLG takes a tap this short as a turn, without a step. +constexpr Milliseconds TURN_TAP = 40ms; +constexpr Milliseconds TURN_SETTLE = 300ms; + +DpadPosition dpad(Direction direction){ + switch (direction){ + case Direction::NORTH: + return DPAD_UP; + case Direction::EAST: + return DPAD_RIGHT; + case Direction::SOUTH: + return DPAD_DOWN; + case Direction::WEST: + return DPAD_LEFT; + } + return DPAD_NONE; +} + +void press(ProControllerContext& context, Button button, Milliseconds after = 340ms){ + pbf_press_button(context, button, 160ms, after); +} + +void tap(ProControllerContext& context, DpadPosition position, Milliseconds after = 400ms){ + pbf_press_dpad(context, position, 160ms, after); +} + + + +bool wait_for_yes_no(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout){ + SelectionArrowWatcher yes(COLOR_RED, &console.overlay(), SelectionArrowPositionConfirmationMenu::YES); + context.wait_for_all_requests(); + return wait_until(console, context, timeout, {yes}) >= 0; +} + +// The START menu row the arrow is on, from the top, as the closest of the +// first `rows` rows. Nothing if no arrow shows. +std::optional start_cursor_row(ConsoleHandle& console, ProControllerContext& context, int rows){ + SelectionArrowWatcher arrow(COLOR_RED, &console.overlay(), MENU_ARROW_BOX); + context.wait_for_all_requests(); + if (wait_until(console, context, 2000ms, {arrow}) < 0){ + return std::nullopt; + } + const double arrow_y = arrow.last_detected().y + arrow.last_detected().height / 2; + int current = 0; + double closest = std::numeric_limits::max(); + for (int c = 0; c < rows; c++){ + const ImageFloatBox box = SelectionArrowDetector::arrow_box_for_position(static_cast(c)); + const double distance = std::abs(arrow_y - (box.y + box.height / 2)); + if (distance < closest){ + closest = distance; + current = c; + } + } + return current; +} + +// The START menu's cursor onto `row`, read from the arrow. As +// move_cursor_to_position(), for a menu of any length. +bool move_start_cursor(ConsoleHandle& console, ProControllerContext& context, int rows, int row){ + const std::optional current = start_cursor_row(console, context, rows); + if (!current){ + return false; + } + console.log(std::format("START menu: cursor on row {}, moving to row {}.", *current + 1, row + 1)); + const int down = (row - *current + rows) % rows; + const int up = (*current - row + rows) % rows; + for (int c = 0; c < std::min(down, up); c++){ + tap(context, down <= up ? DPAD_DOWN : DPAD_UP); + } + context.wait_for_all_requests(); + return true; +} + +// The START menu's cursor onto SAVE, in a menu of any length: up past the +// top wraps to EXIT, the last row, whose place gives the length; SAVE is +// two above it. +bool move_start_cursor_to_save(ConsoleHandle& console, ProControllerContext& context){ + const int most = start_menu_rows(StartMenu::FULL); + const std::optional current = start_cursor_row(console, context, most); + if (!current){ + return false; + } + for (int c = 0; c <= *current; c++){ + tap(context, DPAD_UP); + } + const std::optional last = start_cursor_row(console, context, most); + if (!last){ + return false; + } + console.log(std::format("START menu: {} rows, moving to SAVE.", *last + 1)); + tap(context, DPAD_UP); + tap(context, DPAD_UP); + context.wait_for_all_requests(); + return true; +} + +void open_start_menu_row(ConsoleHandle& console, ProControllerContext& context, StartMenu menu, int row){ + open_start_menu(console, context); + if (!move_start_cursor(console, context, start_menu_rows(menu), row)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "START menu: no cursor.", console + ); + } + press(context, BUTTON_A, 1500ms); +} + + +// The new game's intro, from the title screen. Everything but the names +// is advanced with A, which never hurts there (BOY is the default, YES to +// "So your name is ...?" and "Er, was it GREEN?"); B is never pressed +// outside the keyboard, since in the intro it goes back to the controls +// pages (console B, 2026-11-01). The controls pages read as a message box +// without an arrow, and the arrow at the end of Oak's lines may be missed, +// so a message box gets A every 1.5 s whatever it shows. The player's name +// is asked on the keyboard straight away: B deletes whatever a stray A +// typed and START jumps to OK, which confirms the empty name as the +// default. The rival's is asked on a list with NEW NAME first, where A +// would open the keyboard: the cursor goes to the first preset name (the +// game's default rival, GREEN in FireRed, RED in LeafGreen) and A picks +// it, then YES confirms it (pokefirered oak_speech.c). If the keyboard +// opens anyway, the list was missed, and the empty name is confirmed +// there instead, which also names the rival GREEN. +class NewGameIntro{ +public: + NewGameIntro(ConsoleHandle& console, ProControllerContext& context) + : m_console(console) + , m_context(context) + {} + + void run(){ + press_a_until_dialog(); + const WallClock deadline = current_time() + INTRO_TIMEOUT; + m_last_dialog = current_time(); + m_last_press = m_last_dialog; + while (current_time() < deadline){ + if (step()){ + m_console.log("New game: the bedroom."); + return; + } + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "play_new_game_intro(): still in the intro after 10 minutes.", m_console + ); + } + +private: + // The title, then the controls pages, which A turns, up to a message box. + void press_a_until_dialog(){ + WhiteDialogWatcher dialog(COLOR_RED); + m_context.wait_for_all_requests(); + const int ret = run_until( + m_console, m_context, + [](ProControllerContext& context){ + for (int c = 0; c < 80; c++){ + pbf_press_button(context, BUTTON_A, 160ms, 1340ms); + } + }, + {dialog} + ); + if (ret < 0){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "play_new_game_intro(): no message after the title screen.", m_console + ); + } + } + + // True once the bedroom shows. + bool step(){ + m_context.wait_for_all_requests(); + const WallClock now = current_time(); + VideoSnapshot screen = m_console.video().snapshot(); + if (!screen){ + pbf_wait(m_context, POLL); + return false; + } + if (names(screen)){ + m_last_dialog = current_time(); + m_last_press = m_last_dialog; + return false; + } + if (yes_no_cursor(screen) || WhiteDialogDetector(COLOR_RED).detect(screen)){ + m_dialog_seen = true; + m_last_dialog = now; + if (now - m_last_press >= INTRO_A_EVERY){ + press(m_context, BUTTON_A, 200ms); + m_last_press = now; + }else{ + pbf_wait(m_context, POLL); + } + return false; + } + return quiet(screen, now); + } + + // True if a keyboard or the rival's name list showed and was handled. + bool names(const ImageViewRGB32& screen){ + IntroNameScreen shown = IntroNameScreen::OTHER; + std::optional list_row; + if (NamingScreenDetector(COLOR_RED).detect(screen)){ + shown = IntroNameScreen::KEYBOARD; + }else if (m_keyboards_seen > 0){ + // The list shows over a message box: look for it before the A + // every 1.5 s, which would open the keyboard. + list_row = rival_name_list_cursor(screen); + shown = list_row ? IntroNameScreen::RIVAL_LIST : IntroNameScreen::OTHER; + } + switch (intro_name_step(shown, m_keyboards_seen, m_presets_picked)){ + case IntroNameStep::PLAYER_KEYBOARD: + m_keyboards_seen++; + enter_empty_name(); + return true; + case IntroNameStep::RIVAL_KEYBOARD: + m_keyboards_seen++; + m_console.log("New game: the rival's keyboard opened, so the name list was missed.", COLOR_ORANGE); + enter_empty_name(); + return true; + case IntroNameStep::RIVAL_PRESET: + pick_rival_preset(*list_row); + return true; + case IntroNameStep::NONE: + return false; + } + return false; + } + + // Row 1 is the first preset name. The cursor is read again before A, so + // a dropped press is made up on the next look. + void pick_rival_preset(int row){ + if (row != 1){ + m_console.log(std::format("New game: the rival's name list, cursor on row {}, moving to the first preset name.", row)); + const DpadPosition direction = row < 1 ? DPAD_DOWN : DPAD_UP; + for (int c = 0; c < std::abs(row - 1); c++){ + tap(m_context, direction, 300ms); + } + m_context.wait_for_all_requests(); + return; + } + m_console.log("New game: the rival's name list, picking the first preset name."); + press(m_context, BUTTON_A, 2000ms); + m_context.wait_for_all_requests(); + m_presets_picked++; + } + + // No message box and no keyboard: a fade, a pause in the speech, or + // the bedroom. + bool quiet(const ImageViewRGB32& screen, WallClock now){ + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + if (is_black(game) || !m_dialog_seen || now - m_last_dialog < INTRO_QUIET){ + pbf_wait(m_context, POLL); + return false; + } + // START does nothing in the intro. + if (overworld_shows(m_console, m_context)){ + return true; + } + // A screen still waiting for A that none of the detectors knows. + if (now - m_last_press > INTRO_STUCK){ + m_console.log("New game: nothing known on screen, pressing A."); + press(m_context, BUTTON_A, 200ms); + m_last_press = current_time(); + } + return false; + } + + void enter_empty_name(){ + m_console.log("New game: the keyboard, confirming an empty name."); + for (int c = 0; c < 8; c++){ + press(m_context, BUTTON_B, 340ms); + } + press(m_context, BUTTON_PLUS, 500ms); + press(m_context, BUTTON_A, 2000ms); + m_context.wait_for_all_requests(); + } + + ConsoleHandle& m_console; + ProControllerContext& m_context; + WallClock m_last_dialog; + WallClock m_last_press; + bool m_dialog_seen = false; + size_t m_keyboards_seen = 0; + size_t m_presets_picked = 0; +}; + +} + + +IntroNameStep intro_name_step(IntroNameScreen screen, size_t keyboards_seen, size_t presets_picked){ + switch (screen){ + case IntroNameScreen::KEYBOARD: + return keyboards_seen == 0 ? IntroNameStep::PLAYER_KEYBOARD : IntroNameStep::RIVAL_KEYBOARD; + case IntroNameScreen::RIVAL_LIST: + // The list only comes after the player's keyboard. + return keyboards_seen > 0 && presets_picked < RIVAL_PRESET_TRIES ? IntroNameStep::RIVAL_PRESET : IntroNameStep::NONE; + case IntroNameScreen::OTHER: + return IntroNameStep::NONE; + } + return IntroNameStep::NONE; +} + + +int start_menu_rows(StartMenu menu){ + switch (menu){ + case StartMenu::BEFORE_POKEMON: + return 5; + case StartMenu::BEFORE_POKEDEX: + return 6; + case StartMenu::FULL: + return 7; + } + return 7; +} +int start_menu_save_row(StartMenu menu){ + return start_menu_rows(menu) - 3; +} +int start_menu_option_row(StartMenu menu){ + return start_menu_rows(menu) - 2; +} + + +std::optional yes_no_cursor(const ImageViewRGB32& screen){ + // The box's white right of NO (x 196-212, y 92-102 on the 240x160 + // screen). Without it the arrow alone matches the dark edge of a rock + // on Route 3 at (36, 8), right where YES's arrow shows. + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + if (!is_white(extract_box_reference(game, ImageFloatBox(196.0 / 240, 92.0 / 160, 16.0 / 240, 10.0 / 160)))){ + return std::nullopt; + } + if (SelectionArrowDetector(COLOR_RED, nullptr, SelectionArrowPositionConfirmationMenu::YES).detect(screen)){ + return true; + } + if (SelectionArrowDetector(COLOR_RED, nullptr, SelectionArrowPositionConfirmationMenu::NO).detect(screen)){ + return false; + } + return std::nullopt; +} + +std::optional rival_name_list_cursor(const ImageViewRGB32& screen){ + // On the 240x160 screen: the list's window spans x 16-112, y 16-96, and + // this box (x 64-100, y 36-46) is white there, right of the names and + // below NEW NAME. A YES/NO box's right frame runs through it. + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + if (!is_white(extract_box_reference(game, ImageFloatBox(0.267, 0.225, 0.15, 0.0625)))){ + return std::nullopt; + } + for (int row = 0; row < 5; row++){ + // The START menu's arrow box (window at x 176, y 8; the box starts + // 1.4 px left and 0.4 px below), moved to the list's cursor at + // x 16, y 17 + 16 * row. + const ImageFloatBox box(14.6 / 240, (17.4 + 16 * row) / 160, 0.0369231, 0.0778846); + if (SelectionArrowDetector(COLOR_RED, nullptr, box).detect(screen)){ + return row; + } + } + return std::nullopt; +} + +bool overworld_shows(ConsoleHandle& console, ProControllerContext& context){ + press(context, BUTTON_PLUS, 1200ms); + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + if (!screen || !StartMenuDetector(COLOR_RED).detect(screen)){ + return false; + } + press(context, BUTTON_B, 600ms); + context.wait_for_all_requests(); + return true; +} + +namespace{ +bool yes_no_shows(ConsoleHandle& console){ + VideoSnapshot screen = console.video().snapshot(); + return screen && yes_no_cursor(screen).has_value(); +} +} + +TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout, bool stop_at_battle){ + const WallClock deadline = current_time() + timeout; + // A YES/NO here is a move to learn: "Delete a move to make room?" NO, + // then, right after, "Stop learning?" YES. B to "Stop learning?" goes + // back to the first, for good (console B, 2026-11-01). + std::optional last_no; + while (current_time() < deadline){ + BattleScreenWatcher battle(COLOR_RED); + BattleMenuWatcher battle_menu(COLOR_RED); + SelectionArrowWatcher yes(COLOR_RED, &console.overlay(), SelectionArrowPositionConfirmationMenu::YES); + SelectionArrowWatcher no(COLOR_RED, &console.overlay(), SelectionArrowPositionConfirmationMenu::NO); + BattleLearnDialogWatcher learn(COLOR_RED); + context.wait_for_all_requests(); + int ret = run_until( + console, context, + [](ProControllerContext& context){ + for (int c = 0; c < 5; c++){ + pbf_press_button(context, BUTTON_B, 160ms, 340ms); + } + }, + {battle, battle_menu, yes, no, learn} + ); + // The arrow watchers alone match scenery (a rock's edge on Route 3), + // so a YES/NO also needs its box. + if ((ret == 2 || ret == 3) && !yes_no_shows(console)){ + ret = -1; + } + if (ret >= 2){ + const bool stop_learning = last_no && current_time() - *last_no < 10000ms; + console.log(stop_learning ? "Text: YES/NO, YES (stop learning)." : "Text: YES/NO, NO."); + press(context, stop_learning ? BUTTON_A : BUTTON_B, 1500ms); + last_no = stop_learning ? std::nullopt : std::optional(current_time()); + continue; + } + if (ret >= 0 && stop_at_battle){ + return TextEnd::BATTLE; + } + if (ret < 0 && overworld_shows(console, context)){ + return TextEnd::OVERWORLD; + } + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("advance_text(): the overworld didn't come back within {} s.", timeout.count() / 1000), + console + ); +} + +void mash_until_overworld(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout){ + advance_text(console, context, timeout, false); +} + +void answer_yes_no(ConsoleHandle& console, ProControllerContext& context, bool yes, Button advance, Milliseconds timeout){ + const WallClock deadline = current_time() + timeout; + WallClock last_press = current_time(); + while (current_time() < deadline){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + const std::optional on_yes = screen ? yes_no_cursor(screen) : std::nullopt; + if (on_yes){ + console.log(yes ? "Answering YES." : "Answering NO."); + if (yes && !*on_yes){ + tap(context, DPAD_UP); + } + press(context, yes ? BUTTON_A : BUTTON_B, 800ms); + context.wait_for_all_requests(); + return; + } + const WallClock now = current_time(); + if ((screen && AdvanceWhiteDialogDetector(COLOR_RED).detect(screen)) || now - last_press > TEXT_STILL){ + press(context, advance, 300ms); + last_press = now; + } + pbf_wait(context, POLL); + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "answer_yes_no(): no YES/NO.", console + ); +} + +void step_once(ProControllerContext& context, Direction direction, std::optional facing){ + if (facing != direction){ + pbf_press_dpad(context, dpad(direction), TURN_TAP, TURN_SETTLE); + } + // A step, once started, finishes on its own. + pbf_press_dpad(context, dpad(direction), 120ms, 500ms); + context.wait_for_all_requests(); +} + +void face_wall(ProControllerContext& context, Direction direction){ + pbf_press_dpad(context, dpad(direction), TURN_TAP, TURN_SETTLE); + context.wait_for_all_requests(); +} + +SaveAction SaveDialog::next(SaveScreen screen){ + if (screen != SaveScreen::NOTHING){ + m_nothing_seen = 0; + } + switch (screen){ + case SaveScreen::YES_NO: + m_paged_since_yes = false; + return SaveAction::ANSWER_YES; + case SaveScreen::PAGED_TEXT: + m_paged_since_yes = true; + return SaveAction::NEXT_PAGE; + case SaveScreen::TEXT: + return SaveAction::WAIT; + case SaveScreen::START_MENU: + return SaveAction::FAIL_CANCELLED; + case SaveScreen::NOTHING: + // Twice in a row: not the frame between two boxes. + if (++m_nothing_seen < 2){ + return SaveAction::WAIT; + } + return m_paged_since_yes ? SaveAction::FAIL_ERROR : SaveAction::CHECK_OVERWORLD; + } + return SaveAction::WAIT; +} + +namespace{ + +// The four WARNING pages over another game's save, at the new game's text +// speed, the save itself and its 60-frame pause, with room to spare. +constexpr Milliseconds SAVE_TIMEOUT = 30000ms; + +SaveScreen read_save_screen(const ImageViewRGB32& screen){ + if (yes_no_cursor(screen)){ + return SaveScreen::YES_NO; + } + // Before the message boxes: the menu can show a help box under it. + if (StartMenuDetector(COLOR_RED).detect(screen)){ + return SaveScreen::START_MENU; + } + if (AdvanceWhiteDialogDetector(COLOR_RED).detect(screen)){ + return SaveScreen::PAGED_TEXT; + } + if (WhiteDialogDetector(COLOR_RED).detect(screen)){ + return SaveScreen::TEXT; + } + return SaveScreen::NOTHING; +} + +// From the save card's first YES/NO to the overworld, as SaveDialog says. +void run_save_dialog(ConsoleHandle& console, ProControllerContext& context){ + SaveDialog dialog; + const WallClock deadline = current_time() + SAVE_TIMEOUT; + while (current_time() < deadline){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + if (!screen){ + pbf_wait(context, POLL); + continue; + } + switch (dialog.next(read_save_screen(screen))){ + case SaveAction::WAIT: + pbf_wait(context, POLL); + break; + case SaveAction::ANSWER_YES: + // The overwrite over another game's save starts on NO. + if (yes_no_cursor(screen) == false){ + tap(context, DPAD_UP); + } + console.log("Save: YES."); + press(context, BUTTON_A, 1000ms); + break; + case SaveAction::NEXT_PAGE: + press(context, BUTTON_A, 500ms); + break; + case SaveAction::CHECK_OVERWORLD: + if (overworld_shows(console, context)){ + console.log("Saved."); + return; + } + break; + case SaveAction::FAIL_CANCELLED: + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "save_game(): the START menu came back: the save was cancelled.", console + ); + case SaveAction::FAIL_ERROR: + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "save_game(): a message after the last YES: the save failed.", console + ); + } + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("save_game(): not back on the overworld {} s after saving.", SAVE_TIMEOUT.count() / 1000), + console + ); +} + +} + +void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu menu){ + console.log("Saving the game."); + open_start_menu_row(console, context, menu, start_menu_save_row(menu)); + // The save card and "Would you like to save the game?" + if (!wait_for_yes_no(console, context, 5000ms)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "save_game(): no YES/NO to save.", console + ); + } + context.wait_for_all_requests(); + dump_debug_image(console, "AutoStory/save", "save-card", console.video().snapshot()); + run_save_dialog(console, context); +} + +std::string read_save_place(ConsoleHandle& console, ProControllerContext& context, Language language){ + open_start_menu(console, context); + if (!move_start_cursor_to_save(console, context)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "START menu: no cursor.", console + ); + } + press(context, BUTTON_A, 1500ms); + std::string place; + if (wait_for_yes_no(console, context, 5000ms)){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + place = screen ? read_save_card_location(console, language, screen) : ""; + dump_debug_image(console, "AutoStory/save", "card-" + (place.empty() ? std::string("unread") : place), screen); + } + // NO, then out of the menu. + press(context, BUTTON_B, 1000ms); + mash_until_overworld(console, context, 20000ms); + return place; +} + +std::optional option_right_presses( + const std::vector& values, const std::string& current, const std::string& target +){ + const auto from = std::find(values.begin(), values.end(), current); + const auto to = std::find(values.begin(), values.end(), target); + if (from == values.end() || to == values.end()){ + return std::nullopt; + } + const size_t count = values.size(); + return (static_cast(to - values.begin()) + count - static_cast(from - values.begin())) % count; +} + +static void options_shot(ConsoleHandle& console, ProControllerContext& context, const std::string& label){ + context.wait_for_all_requests(); + dump_debug_image(console, "AutoStory/options", label, console.video().snapshot()); +} + +// The item's value, read up to 3 times while the menu may still be fading +// in or redrawing; empty if never read. +static std::string read_option( + ConsoleHandle& console, ProControllerContext& context, OptionMenuItem item, Language language +){ + for (size_t attempt = 0; attempt < 3; attempt++){ + if (attempt > 0){ + pbf_wait(context, 500ms); + } + context.wait_for_all_requests(); + const VideoSnapshot screen = console.video().snapshot(); + const std::string value = screen ? read_option_value(console, language, screen, item) : ""; + if (!value.empty()){ + return value; + } + } + return ""; +} + +// With the cursor on the item's row: RIGHT until it shows `target`. +static void set_option( + ConsoleHandle& console, ProControllerContext& context, + OptionMenuItem item, const std::string& target, Language language +){ + const char* name = option_menu_name(item); + const std::string current = read_option(console, context, item, language); + const std::optional presses = option_right_presses(option_menu_values(item), current, target); + if (!presses){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("set_options(): can't read {} (read \"{}\", language {}).", name, current, language_data(language).name), + console + ); + } + console.log(std::format("Options: {} is {}, {} RIGHT to {}.", name, current, *presses, target)); + for (size_t i = 0; i < *presses; i++){ + tap(context, DPAD_RIGHT); + } + const std::string now = read_option(console, context, item, language); + if (now != target){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("set_options(): {} reads \"{}\" after {} RIGHT from {}, not {}.", name, now, *presses, current, target), + console + ); + } +} + +void set_options(ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language){ + console.log("Options: text speed FAST, battle scene OFF, battle style SET."); + open_start_menu_row(console, context, menu, start_menu_option_row(menu)); + options_shot(console, context, "before"); + struct Target{ + OptionMenuItem item; + const char* value; + }; + // In row order. The cursor opens on TEXT SPEED (option_menu.c: + // cursorPos = 0) and DOWN moves it a row. Were it on another row, the + // presses would change that row instead, and the read after them fails. + const Target targets[] = { + {.item = OptionMenuItem::TEXT_SPEED, .value = "fast"}, + {.item = OptionMenuItem::BATTLE_SCENE, .value = "off"}, + {.item = OptionMenuItem::BATTLE_STYLE, .value = "set"}, + }; + size_t cursor = 0; + for (const Target& target : targets){ + for (; cursor < option_menu_row(target.item); cursor++){ + tap(context, DPAD_DOWN); + } + set_option(console, context, target.item, target.value, language); + } + options_shot(console, context, "after"); + press(context, BUTTON_B, 1500ms); + mash_until_overworld(console, context, 20000ms); +} + +void heal_at_center(ConsoleHandle& console, ProControllerContext& context){ + console.log("Healing at the Pokemon Center."); + // The nurse's YES/NO isn't seen by the selection detector (console B, + // 2026-11-01); YES is the default, so A after her lines is YES. + // "Welcome ... We heal your POKEMON ... Shall we heal?" is 3 lines. + press(context, BUTTON_A, 1500ms); + press(context, BUTTON_A, 1500ms); + press(context, BUTTON_A, 2500ms); + press(context, BUTTON_A, 1000ms); + pbf_wait(context, HEAL_TIME); + mash_until_overworld(console, context, 30000ms); +} + +// A picture of the Mart screen for the run's record: the list with the +// cursor, the quantity, the bag after. +static void mart_shot(ConsoleHandle& console, ProControllerContext& context, const std::string& label){ + context.wait_for_all_requests(); + dump_debug_image(console, "AutoStory/mart", label, console.video().snapshot()); +} + +int mart_cursor_moves(int cursor, int row){ + return row - cursor; +} + +// THOROUGH: the item on the cursor's row is `order.item`. +static void check_mart_row(ConsoleHandle& console, ProControllerContext& context, const MartOrder& order, Language language){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + const std::string item = screen ? read_item_list_name(console, language, screen, order.row) : ""; + if (item == order.item){ + console.log(std::format("Mart: row {} is {}.", order.row + 1, item)); + return; + } + if (item.empty()){ + console.log(std::format("Mart: couldn't read row {}, expected {}; buying anyway.", order.row + 1, order.item), COLOR_ORANGE); + dump_debug_image(console, "AutoStory/mart", std::format("row{}-unread", order.row + 1), screen); + return; + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("buy_items(): row {} is {}, not {}.", order.row + 1, item, order.item), + console + ); +} + +void buy_items( + ConsoleHandle& console, ProControllerContext& context, + const std::vector& orders, StoryChecks checks, Language language +){ + // "May I help you?" with BUY on top, then the list, cursor on its top. + press(context, BUTTON_A, 2000ms); + press(context, BUTTON_A, 2000ms); + // After a purchase the cursor stays on the item bought (run on console B, + // 2026-11-01: rows {1, 2, 3} counted from the top each time bought + // Parlyz Heals instead of Antidotes, and the third order hit CANCEL). + int cursor = 0; + for (const MartOrder& order : orders){ + console.log(std::format("Mart: buying {} of row {} (cursor on row {}).", order.quantity, order.row + 1, cursor + 1)); + const int moves = mart_cursor_moves(cursor, order.row); + for (int c = 0; c < std::abs(moves); c++){ + tap(context, moves > 0 ? DPAD_DOWN : DPAD_UP, 300ms); + } + cursor = order.row; + mart_shot(console, context, std::format("row{}-list", order.row + 1)); + if (checks == StoryChecks::THOROUGH){ + check_mart_row(console, context, order, language); + } + // "How many?" drops presses while its text prints. + press(context, BUTTON_A, 2500ms); + for (int c = 1; c < order.quantity; c++){ + tap(context, DPAD_UP, 340ms); + } + mart_shot(console, context, std::format("row{}-quantity", order.row + 1)); + // "That will be..." YES/NO, YES, "Here you are!"; the cursor stays + // on the row. + press(context, BUTTON_A, 3500ms); + press(context, BUTTON_A, 2000ms); + press(context, BUTTON_A, 1500ms); + mart_shot(console, context, std::format("row{}-bought", order.row + 1)); + } + press(context, BUTTON_B, 1500ms); + press(context, BUTTON_B, 1500ms); + mash_until_overworld(console, context, 20000ms); +} + +void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context){ + console.log("New game: from the title screen."); + NewGameIntro(console, context).run(); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h new file mode 100644 index 0000000000..78d88a0d14 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -0,0 +1,225 @@ +/* AutoStory Actions + * + * From: https://github.com/PokemonAutomation/ + * + * The console steps the FRLG story is made of, as a by-hand run from a new + * game to Brock found them (console B, 2026-11-01): reading text to its end, + * YES/NO prompts, saving from the START menu, the nurse, the Viridian Mart, + * and the new game's intro. Story text is advanced with B, which never + * starts a talk; the overworld is back once START opens the menu, which it + * doesn't while a scene runs. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryActions_H +#define PokemonAutomation_PokemonFRLG_AutoStoryActions_H + +#include +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "CommonFramework/Language.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/Navigation/Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// How much the story checks the screen before and after it acts: the +// shared level (Pokemon_StorySteps.h, set by StoryRunOptions). For FRLG, +// THOROUGH reads a Mart row's item before buying it, the bag's Items +// pocket after shopping (the counts the story then keeps), and an item's +// name in the bag before using it. FAST trusts the counts it keeps and the +// timings. +using StoryChecks = Pokemon::StoryChecks; + +// The START menu as the story grows it. Before the starter: BAG, the +// player, SAVE, OPTION, EXIT; the starter adds POKEMON on top, the Pokedex +// POKEDEX above that. +enum class StartMenu{ + BEFORE_POKEMON, + BEFORE_POKEDEX, + FULL, +}; +int start_menu_rows(StartMenu menu); +int start_menu_save_row(StartMenu menu); +int start_menu_option_row(StartMenu menu); + + +// Whether the overworld is up: START opens the menu only there, with no +// scene running. If it opened, it is closed again. +bool overworld_shows(ConsoleHandle& console, ProControllerContext& context); + + +// Which row of the standard YES/NO box the arrow is on (true: YES), if +// one shows. +std::optional yes_no_cursor(const ImageViewRGB32& screen); + +// The arrow's row on Oak's list of rival names (NEW NAME, then four preset +// names), if the list shows. In pokefirered's oak_speech.c the list is a +// 12x10-tile window at tile (2, 2), rows 16 px apart, the cursor starting +// on NEW NAME. The intro's YES/NO boxes open in the same corner but are +// 6x4 tiles: the list is told from them by its white past their frame. +std::optional rival_name_list_cursor(const ImageViewRGB32& screen); + +// What shows in the new game's intro, as far as the names go. +enum class IntroNameScreen{ + OTHER, + KEYBOARD, + RIVAL_LIST, +}; +// What the new game's intro does about the names. The player's name is +// asked on a keyboard, always first; the rival's on the name list, where +// the first preset name is picked, as SID Helper does. A keyboard after +// the player's is the rival's, opened because the list was missed. +enum class IntroNameStep{ + NONE, + PLAYER_KEYBOARD, + RIVAL_PRESET, + RIVAL_KEYBOARD, +}; +// A preset picked returns to the list only after NO on "Er, was it ...?", +// so after this many picks A opens the keyboard instead. +constexpr size_t RIVAL_PRESET_TRIES = 3; +IntroNameStep intro_name_step(IntroNameScreen screen, size_t keyboards_seen, size_t presets_picked); + + +enum class TextEnd{ + OVERWORLD, + BATTLE, +}; + +// Presses B until the overworld is back or, if `stop_at_battle`, a battle +// shows. Throws OperationFailedException after `timeout`. +TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout, bool stop_at_battle); + +// advance_text() to the overworld. +void mash_until_overworld(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout); + +// Advances text with `advance` until a YES/NO shows, then answers it. B +// answers NO. Throws OperationFailedException after `timeout`. +void answer_yes_no(ConsoleHandle& console, ProControllerContext& context, bool yes, Button advance, Milliseconds timeout); + +// From the overworld: one step `direction`, onto a trigger or into a door. +// `facing` is the way the player faces, if known; a player facing another +// way is turned first. +void step_once(ProControllerContext& context, Pokemon::Direction direction, std::optional facing); + +// From the overworld, turns to face `direction` without stepping: the +// player must have a wall that way. +void face_wall(ProControllerContext& context, Pokemon::Direction direction); + +// The save dialog after SAVE, as pokefirered's start_menu.c runs it: +// "Would you like to save the game?" YES/NO (YES first). Then, over a save +// of this game, "There is already a saved file. Is it okay to overwrite +// it?" YES/NO (YES first); over another game's save (a new game), "WARNING! +// There is a different game file that is already saved." on four pages, +// ending "...overwrite the other save file?" YES/NO with NO first. Then +// "SAVING... DON'T TURN OFF THE POWER.", "PLAYER saved the game." and, +// without a press, the overworld. NO at any YES/NO brings the START menu +// back; a failed save shows "Save error." and waits for A held. +enum class SaveScreen{ + YES_NO, + // A message with the arrow for the next page. + PAGED_TEXT, + // A message without an arrow: SAVING, or saved. + TEXT, + START_MENU, + // No message and no menu: the overworld, or a frame between two boxes. + NOTHING, +}; +enum class SaveAction{ + WAIT, + ANSWER_YES, + NEXT_PAGE, + // Confirm the overworld (START opens the menu): the game is saved. + CHECK_OVERWORLD, + // The START menu is back: a YES/NO was answered NO. + FAIL_CANCELLED, + // A paged message after the last YES: "Save error." + FAIL_ERROR, +}; +// What save_game() does on each screen it reads after the save card's +// first YES/NO shows. Every YES/NO gets YES; B is never pressed. +class SaveDialog{ +public: + SaveAction next(SaveScreen screen); + +private: + bool m_paged_since_yes = false; + size_t m_nothing_seen = 0; +}; + +// From the overworld: SAVE, YES, and YES again to overwrite an older save +// (see SaveDialog). The menu's cursor is read, since the game remembers it +// and the menu grows. Returns to the overworld; throws +// OperationFailedException if the save wasn't made. +void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu menu); + +// From the overworld: the place the START menu's SAVE card names (see +// read_save_card_location()), then NO, back to the overworld. Empty if it +// can't be read. The menu's length is read, not assumed, so a save made +// with another START menu (another checkpoint's) is read too. +std::string read_save_place(ConsoleHandle& console, ProControllerContext& context, Language language); + +// RIGHT presses that turn an option showing `current` into `target`. +// RIGHT steps through `values` and wraps from the last to the first +// (pokefirered option_menu.c OptionMenu_ProcessInput). Nothing if either +// isn't one of `values`. +std::optional option_right_presses( + const std::vector& values, const std::string& current, const std::string& target +); + +// From the overworld: OPTION, text speed FAST, battle scene OFF (no move +// animations), battle style SET (no "Will you switch?" between a +// trainer's Pokemon). Returns to the overworld. A new game keeps the +// options of the save it replaces, so each value is read and stepped to +// its target, then read again; one that can't be read, as in a language +// the reader has no names for, or that isn't the target after the +// presses, fails with a screenshot and leaves the menu open. +void set_options(ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language); + +// Facing the nurse: A, YES, the heal, and the text to its end. +void heal_at_center(ConsoleHandle& console, ProControllerContext& context); + +// One line of a Mart's BUY list: the row (from 0) and how many. +struct MartOrder{ + int row = 0; + int quantity = 1; + // The item's slug for the check (see read_item_list_name()). + const char* item = ""; +}; + +// Down (positive) or up (negative) presses to move a Mart list's cursor +// from `cursor` to `row`. After a purchase the cursor stays on its row. +int mart_cursor_moves(int cursor, int row); + +// Facing a Mart clerk: BUY each order, then out to the overworld. +// THOROUGH: each row's item is read before buying; one that reads as +// another item fails with a screenshot, one that can't be read is only +// logged. +// `language` is the game's: in one the reader has no names for, rows are +// bought by position only. +void buy_items( + ConsoleHandle& console, ProControllerContext& context, + const std::vector& orders, StoryChecks checks, Language language +); + +// From the title screen of a game with no save, to the bedroom: the +// controls pages, Oak's speech, BOY, the default name for the player (an +// empty name confirmed) and the rival's first preset name. Returns on the +// overworld. +void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp new file mode 100644 index 0000000000..8428706822 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -0,0 +1,981 @@ +/* AutoStory Battle + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTools/ImageStats.h" +#include "CommonFramework/Tools/DebugDumper.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyMenuDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattleData.h" +#include "PokemonFRLG_AutoStoryBattleDecisions.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryFoeTracker.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace std::chrono_literals; + + +namespace{ + +constexpr Milliseconds POLL = 300ms; +constexpr Milliseconds BATTLE_TIMEOUT = 600000ms; +// To see the battle at all, from its first flash. +constexpr Milliseconds BATTLE_START_TIMEOUT = 20000ms; +// No battle screen for this long: check for the overworld with START. +constexpr Milliseconds BATTLE_GONE = 2000ms; +// A battle screen with neither an arrow nor a menu for this long: B, for +// a prompt the detectors miss. +constexpr Milliseconds STUCK = 8000ms; +// Seen this many polls in a row: the starter fainted. +constexpr int FAINT_POLLS = 3; +// No battle menu for this long: A and B in turn, for a prompt nothing reads. +// Only near battle screens: A on the overworld after a gym leader's speech +// would talk to them again. +constexpr Milliseconds NO_MENU = 60000ms; +constexpr Milliseconds NO_MENU_NEAR = 10000ms; +// No battle screen yet and no turn taken: whether the overworld is back +// is checked by START this often (a trainer's battle that never started, +// console B, 2026-11-01: 10 minutes of B on the overworld). +constexpr Milliseconds OVERWORLD_CHECK = 3000ms; +// No battle menu or HP box this long after a battle was seen: there was +// none (console B, 2026-11-01, Viridian Forest's north gate mat). +constexpr Milliseconds NOT_A_BATTLE = 15000ms; +// An evolution's animation, with no presses: as long as exit_wild_battle() +// (PokemonFRLG_Navigation.cpp) waits for one. +constexpr Milliseconds EVOLUTION = 20000ms; +// Text and the move learn prompts after a battle, on the overworld. +constexpr Milliseconds AFTER_BATTLE_TEXT = 60000ms; +// The move list to fade in after "Delete a move?", and its cursor to move. +constexpr Milliseconds MOVE_LIST_TIMEOUT = 5000ms; + +// In the player's box, as a fraction of the 240x160 screen: the status +// badge left of the HP numbers. The box bobs by a pixel; this keeps a +// pixel inside. +const ImageFloatBox STATUS_BADGE_BOX(146.0 / 240, 99.0 / 160, 12.0 / 240, 4.0 / 160); + +StatusCondition read_status_badge(const ImageViewRGB32& badge){ + const ImageStats stats = image_stats(badge); + const double r = stats.average.r; + const double g = stats.average.g; + const double b = stats.average.b; + const double off_white = std::abs(r - 255) + std::abs(g - 255) + std::abs(b - 217); + if (off_white < 60){ + return StatusCondition::NONE; + } + if (r > 200 && g < 200 && b > 180){ + return StatusCondition::POISON; + } + // Not measured yet: PAR's badge is taken to be the yellow one. + if (r > 180 && g > 150 && b < 140){ + return StatusCondition::PARALYSIS; + } + return StatusCondition::OTHER; +} + + +enum class BattleScreen{ + // Keep in step with screen_name(). + MENU, // "What will do?" with FIGHT/BAG/POKEMON/RUN + LEARN, // a YES/NO about a move to learn + ADVANCE, // battle text waiting for a button + OTHER, // the battle, busy + NONE, // no battle on screen +}; + +const char* screen_name(BattleScreen screen){ + switch (screen){ + case BattleScreen::MENU: + return "battle menu"; + case BattleScreen::LEARN: + return "move prompt"; + case BattleScreen::ADVANCE: + return "battle text with arrow"; + case BattleScreen::OTHER: + return "battle text box"; + case BattleScreen::NONE: + return "no battle screen"; + } + return "?"; +} + +// Until `confirmed`, the battle text box alone counts for nothing: it also +// reads on the black below a small indoor map. +BattleScreen read_battle_screen(const ImageViewRGB32& screen, bool confirmed){ + if (BattleMenuDetector(COLOR_RED).detect(screen)){ + return BattleScreen::MENU; + } + if (BattleLearnDialogDetector(COLOR_RED).detect(screen)){ + return BattleScreen::LEARN; + } + if (!confirmed && !BattleScreenDetector(COLOR_RED).detect(screen)){ + return BattleScreen::NONE; + } + if (AdvanceBattleDialogDetector(COLOR_RED).detect(screen)){ + return BattleScreen::ADVANCE; + } + if (BattleDialogDetector(COLOR_RED).detect(screen)){ + return BattleScreen::OTHER; + } + return BattleScreen::NONE; +} + +BattleTextScreen read_text_screen(const ImageViewRGB32& screen){ + return BattleTextScreen{ + .text_box = BattleDialogDetector(COLOR_RED).detect(screen), + .hp_box = BattleScreenDetector(COLOR_RED).detect(screen), + .arrow = AdvanceBattleDialogDetector(COLOR_RED).detect(screen), + .yes_no = BattleLearnDialogDetector(COLOR_RED).detect(screen) || yes_no_cursor(screen).has_value(), + }; +} + +// The player's Pokemon gone while the opponent's is still there. +bool starter_fainted(const ImageViewRGB32& screen){ + return !BattlePokemonDetector(COLOR_RED).detect(screen) && BattleOpponentDetector(COLOR_RED).detect(screen); +} + +void tap(ProControllerContext& context, DpadPosition position){ + pbf_press_dpad(context, position, 160ms, 240ms); +} + +// In the bag, with the cursor on `row`: whether that row is `item`. FAST +// doesn't look. A row that can't be read (as in a language the reader has +// no names for) is taken by its position; only another item's name stops it. +bool bag_row_is( + ConsoleHandle& console, ProControllerContext& context, + int row, const std::string& item, StoryChecks checks, Language language +){ + if (checks == StoryChecks::FAST){ + return true; + } + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + const std::string read = screen ? read_item_list_name(console, language, screen, row) : ""; + if (read == item){ + return true; + } + if (read.empty()){ + console.log(std::format("Bag: row {} unread, taking it as the {} by its position.", row + 1, item), COLOR_ORANGE); + return true; + } + console.log(std::format("Bag: row {} reads \"{}\", not {}: not using it.", row + 1, read, item), COLOR_RED); + dump_debug_image(console, "AutoStory/bag", std::format("row{}-not-{}", row + 1, item), screen); + return false; +} + +// From the battle menu: `item`, in `row` (from 0) of the Items pocket, on +// the starter. The bag opens on the pocket used last; Items is the first. +// Returns whether it was used; if the row holds something else (THOROUGH), +// backs out to the battle menu. Not run on the console yet. +bool use_item( + ConsoleHandle& console, ProControllerContext& context, + int row, const std::string& item, StoryChecks checks, Language language +){ + console.log(std::format("Battle: using the {} in row {} of the Items pocket.", item, row + 1)); + tap(context, DPAD_LEFT); + tap(context, DPAD_UP); + tap(context, DPAD_RIGHT); + pbf_press_button(context, BUTTON_A, 160ms, 1500ms); + for (int c = 0; c < 2; c++){ + pbf_press_dpad(context, DPAD_LEFT, 160ms, 500ms); + } + for (int c = 0; c < 12; c++){ + pbf_press_dpad(context, DPAD_UP, 100ms, 150ms); + } + for (int c = 0; c < row; c++){ + tap(context, DPAD_DOWN); + } + if (!bag_row_is(console, context, row, item, checks, language)){ + pbf_press_button(context, BUTTON_B, 160ms, 1500ms); + return false; + } + // The item, USE, then the starter in the party list. + pbf_press_button(context, BUTTON_A, 160ms, 800ms); + pbf_press_button(context, BUTTON_A, 160ms, 1500ms); + pbf_press_button(context, BUTTON_A, 160ms, 1000ms); + return true; +} + +// RUN, bottom right of the battle menu. +void run_away(ProControllerContext& context){ + tap(context, DPAD_LEFT); + tap(context, DPAD_UP); + tap(context, DPAD_RIGHT); + tap(context, DPAD_DOWN); + pbf_press_button(context, BUTTON_A, 160ms, 500ms); +} + +// FIGHT, then the move in `slot` from the top left. The cursor doesn't +// move onto an empty slot. +void use_move(ProControllerContext& context, size_t slot){ + tap(context, DPAD_LEFT); + tap(context, DPAD_UP); + pbf_press_button(context, BUTTON_A, 160ms, 1000ms); + tap(context, DPAD_LEFT); + tap(context, DPAD_UP); + if (slot % 2 == 1){ + tap(context, DPAD_RIGHT); + } + if (slot >= 2){ + tap(context, DPAD_DOWN); + } + pbf_press_button(context, BUTTON_A, 160ms, 500ms); +} + +// The move list's cursor row once it shows, and, if `before` is given, once +// it has left that row: up to `timeout`. +std::optional read_move_list_cursor( + ConsoleHandle& console, ProControllerContext& context, + std::optional before, Milliseconds timeout +){ + const WallClock deadline = current_time() + timeout; + while (true){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + const std::optional cursor = screen ? read_summary_move_cursor(screen) : std::nullopt; + if (cursor && cursor != before){ + return cursor; + } + if (current_time() >= deadline){ + return std::nullopt; + } + pbf_wait(context, POLL); + } +} + +// After YES to "Delete a move?": the move list fades in with its cursor on +// the top move (pret pokemon_summary_screen.c); A on a move forgets it, +// B would go back to "Stop learning?". The cursor is read before A and +// after each press: DOWNs sent while the list faded in were lost, and A +// forgot the top move, Tackle, for Water Gun instead of Bubble (console B, +// 2026-11-02). Done in one go, so the loop's B presses can't land on the +// list. A list whose cursor never shows gets the presses by time, as +// before; a cursor that can't be brought to `slot` fails the battle. +// YES, then `slot` on the move list. False, with nothing more pressed, if no move list showed. +bool forget_move(ConsoleHandle& console, ProControllerContext& context, size_t slot){ + pbf_press_button(context, BUTTON_A, 160ms, 0ms); + std::optional cursor = read_move_list_cursor(console, context, std::nullopt, MOVE_LIST_TIMEOUT); + if (!cursor){ + console.log("Battle: no move list after YES; the moves stay as they were.", COLOR_ORANGE); + return false; + } + for (size_t presses = 0; *cursor != slot; presses++){ + if (presses >= 2 * SUMMARY_MOVE_ROWS){ + break; + } + const size_t from = *cursor; + pbf_press_dpad(context, from < slot ? DPAD_DOWN : DPAD_UP, 160ms, 0ms); + cursor = read_move_list_cursor(console, context, from, MOVE_LIST_TIMEOUT); + if (!cursor){ + break; + } + } + if (cursor != slot){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("forget_move(): the cursor didn't reach move {} on the move list.", slot + 1), + console + ); + } + pbf_press_button(context, BUTTON_A, 160ms, 2000ms); + return true; +} + +// The party list in battle opens on the lead: down to `slot`, then A, and +// SHIFT, the top of its menu. +TurnResult item_result(bool used){ + return used ? TurnResult::DONE : TurnResult::NOT_DONE; +} + +void send_member(ProControllerContext& context, size_t slot){ + for (size_t c = 0; c < slot; c++){ + pbf_press_dpad(context, DPAD_DOWN, 160ms, 400ms); + } + pbf_press_button(context, BUTTON_A, 160ms, 800ms); + pbf_press_button(context, BUTTON_A, 160ms, 1500ms); +} + + +class BattleLoop{ +public: + BattleLoop( + ConsoleHandle& console, ProControllerContext& context, + Supplies& supplies, BattleKind kind, StoryChecks checks, Language language + ) + : m_console(console) + , m_context(context) + , m_supplies(supplies) + , m_decisions(supplies, kind) + , m_evolution(supplies.lead) + , m_foes(kind == BattleKind::TRAINER ? supplies.trainer : "", supplies.lead) + , m_kind(kind) + , m_checks(checks) + , m_language(language) + , m_start(current_time()) + , m_last_battle(m_start) + , m_last_press(m_start) + , m_last_menu(m_start) + , m_last_overworld_check(m_start) + {} + + BattleEnd run(){ + m_console.log( + m_kind == BattleKind::TRAINER ? "Battle: fighting a trainer." : + m_kind == BattleKind::WILD_FIGHT ? "Battle: fighting a wild Pokemon." : "Battle: running from a wild Pokemon." + ); + bool over = false; + while (!over){ + over = step(); + } + m_console.log(std::format( + "Battle: over after {} turns{}.", m_decisions.turns(), m_decisions.lost() ? ", the starter fainted" : "" + )); + return m_decisions.lost() ? BattleEnd::LOST : BattleEnd::WON; + } + +private: + // One look at the screen and what it asks for. True once the battle is over. + bool step(){ + m_context.wait_for_all_requests(); + const WallClock now = current_time(); + check_time(now); + VideoSnapshot screen = m_console.video().snapshot(); + if (!screen){ + pbf_wait(m_context, POLL); + return false; + } + if (!m_confirmed && BattleScreenDetector(COLOR_RED).detect(screen)){ + m_console.log("Battle: the battle menu or an HP box shows."); + m_confirmed = true; + } + if (!m_confirmed && now - m_start > NOT_A_BATTLE){ + m_console.log("Battle: no battle menu or HP box in 15 s: not a battle.", COLOR_ORANGE); + return true; + } + if (between_turns(screen, now)){ + return false; + } + if (battle_gone(screen, now)){ + return true; + } + const BattleScreen seen = read_battle_screen(screen, m_confirmed); + if (seen != m_last_seen){ + m_console.log(std::format("Battle: {} (turn {}).", screen_name(seen), m_decisions.turns())); + m_last_seen = seen; + } + if (seen == BattleScreen::MENU){ + m_last_menu = now; + m_move_chosen = false; + }else if (now - m_last_menu > NO_MENU && now - m_last_battle < NO_MENU_NEAR && now - m_last_press > 1500ms){ + // Something waits that none of the battle screens knows. + return press_blind(now); + } + if (seen == BattleScreen::NONE){ + m_refusal.no_battle_screen(); + return no_battle_screen(screen, now); + } + m_seen_battle = true; + m_last_battle = now; + read_hp(screen); + watch_for_faint(screen); + m_foes.boxes_seen(BattleBoxes{.lead = BattlePokemonDetector(COLOR_RED).detect(screen), .foe = BattleOpponentDetector(COLOR_RED).detect(screen)}); + act(seen, screen, now); + return false; + } + + // The screens between the turns that need more than B: "no PP left", + // the party list once the lead fainted, and an evolution after the + // battle. True if one was handled. + bool between_turns(const ImageViewRGB32& screen, WallClock now){ + if (!m_confirmed){ + return false; + } + if (m_move_chosen && BattleOutOfPpDetector(COLOR_RED).detect(screen)){ + m_console.log("Battle: no PP left for that move; choosing again.", COLOR_ORANGE); + m_decisions.turn_done(TurnChoice::MOVE, TurnResult::NOT_DONE); + m_move_chosen = false; + m_refusal = MoveRefusalWatch(); + pbf_press_button(m_context, BUTTON_B, 160ms, 800ms); + pbf_press_button(m_context, BUTTON_B, 160ms, 800ms); + m_last_press = now; + return true; + } + if (m_decisions.lost() && PartyMenuDetector(COLOR_RED).detect(screen)){ + send_next_member(now); + return true; + } + if (m_evolution.holds(read_text_screen(screen))){ + wait_out_evolution(); + return true; + } + return false; + } + + // The party list after the lead fainted: the next member allowed in, or + // a stop with only protected members left. + void send_next_member(WallClock now){ + const std::optional slot = m_decisions.next_member_slot(); + if (!slot){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::NO_ERROR_REPORT, + "fight_battle(): the starter fainted and only protected members are left; not sending one.", + m_console + ); + } + m_console.log(std::format("Battle: the lead fainted; sending party slot {}.", *slot + 1), COLOR_ORANGE); + send_member(m_context, *slot); + m_last_press = now; + } + + // Nothing pressed while the screen may be an evolution, up to EVOLUTION. + void wait_out_evolution(){ + const WallClock start = current_time(); + bool holds = true; + while (holds && current_time() - start < EVOLUTION){ + pbf_wait(m_context, POLL); + m_context.wait_for_all_requests(); + VideoSnapshot screen = m_console.video().snapshot(); + holds = !screen || m_evolution.holds(read_text_screen(screen)); + } + const WallClock end = current_time(); + const Milliseconds held = std::chrono::duration_cast(end - start); + if (held >= 2000ms){ + m_console.log(std::format("Battle: no B for {} s, for an evolution.", held.count() / 1000)); + } + m_evolution.held(held, m_decisions.lost()); + m_last_press = end; + m_last_battle = end; + } + + // True once START opens the menu, after no battle menu, HP box or + // YES/NO for a while: whatever the text box reads, the battle is over. + bool battle_gone(const ImageViewRGB32& screen, WallClock now){ + const BattleSeen seen = BattleMenuDetector(COLOR_RED).detect(screen) ? BattleSeen::MENU + : battle_shows(screen) ? BattleSeen::BATTLE : BattleSeen::NONE; + m_end.seen(seen, now); + if (!m_end.check_overworld(now)){ + return false; + } + m_last_overworld_check = now; + return overworld_shows(m_console, m_context); + } + + // A or B, in turn. True once they have gone on too long: the walk, + // which finds the player again, takes over. + bool press_blind(WallClock now){ + if (m_end.pressed_blind(now)){ + m_console.log("Battle: no battle menu after pressing A and B; leaving the rest to the walk.", COLOR_RED); + return true; + } + m_console.log(std::format("Battle: no battle menu for {} s, pressing {}.", + std::chrono::duration_cast(now - m_last_menu).count(), m_press_a ? "A" : "B")); + pbf_press_button(m_context, m_press_a ? BUTTON_A : BUTTON_B, 160ms, 200ms); + m_press_a = !m_press_a; + m_last_press = now; + return false; + } + + // True once the battle is over: only when START opens the menu. The + // battle screens are gone during the opening slide-in (console B: "over + // after 0 turns" at the rival) and under a move prompt's YES/NO (console + // B, 2026-11-01, Viridian Forest: called over, then stuck at "Stop + // learning?"). + bool no_battle_screen(const ImageViewRGB32& screen, WallClock now){ + if (!m_seen_battle){ + pbf_wait(m_context, POLL); + return false; + } + if (m_decisions.turns() > 0 && yes_no_cursor(screen)){ + answer_prompt(screen, now); + return false; + } + if (now - m_last_battle > BATTLE_GONE && now - m_last_overworld_check > OVERWORLD_CHECK){ + m_last_overworld_check = now; + if (overworld_shows(m_console, m_context)){ + return true; + } + } + // Oak's white text box in the rival's battle reads as no battle screen: + // B moves it on, and B does nothing on the overworld once the battle is over. + if (now - m_last_press > 1500ms){ + pbf_press_button(m_context, BUTTON_B, 160ms, 200ms); + m_last_press = now; + return false; + } + pbf_wait(m_context, POLL); + return false; + } + + void check_time(WallClock now){ + if (!m_seen_battle && now - m_start > BATTLE_START_TIMEOUT){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "fight_battle(): no battle on screen.", m_console + ); + } + if (now - m_start > BATTLE_TIMEOUT){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "fight_battle(): the battle took over 10 minutes.", m_console + ); + } + } + + void act(BattleScreen seen, const ImageViewRGB32& screen, WallClock now){ + switch (seen){ + case BattleScreen::MENU: + take_turn(screen); + m_last_press = now; + return; + case BattleScreen::LEARN: + if (m_decisions.turns() == 0){ + // The prompts come after a turn; before one it is a misread. + break; + } + answer_prompt(screen, now); + return; + case BattleScreen::ADVANCE: + pbf_press_button(m_context, BUTTON_B, 160ms, 200ms); + m_last_press = now; + return; + default: + break; + } + if (now - m_last_press > STUCK){ + pbf_press_button(m_context, BUTTON_B, 160ms, 200ms); + m_last_press = now; + } + pbf_wait(m_context, POLL); + } + + // The HP bar whenever the starter's box shows, so the last reading + // includes the battle's last hit. Not once another member is out. + void read_hp(const ImageViewRGB32& screen){ + if (m_decisions.lost() || !BattlePokemonDetector(COLOR_RED).detect(screen)){ + return; + } + const PartyStatus status = read_party_status(screen); + if (status.hp_seen){ + m_supplies.hurt = status.hp_red || status.hp_yellow; + m_supplies.hp_red = status.hp_red; + m_supplies.hp_fill = status.hp_fill; + } + m_supplies.status = status.status; + } + + void answer_prompt(const ImageViewRGB32& screen, WallClock now){ + dump_debug_image(m_console, "AutoStory/battle", std::format("turn{}-yes-no", m_decisions.turns()), screen); + const PromptAnswer answer = m_decisions.prompt(starter_fainted(screen)); + if (answer.forget_slot){ + m_console.log(std::format("Battle: learning the new move over move {}.", *answer.forget_slot + 1)); + if (forget_move(m_console, m_context, *answer.forget_slot) && answer.learned){ + m_supplies.lead = *answer.learned; + } + }else{ + m_console.log(std::format("Battle: answering {} to a YES/NO.", answer.answer == YesNo::YES ? "YES" : "NO")); + pbf_press_button(m_context, answer.answer == YesNo::YES ? BUTTON_A : BUTTON_B, 160ms, 1500ms); + } + m_last_press = now; + } + + void take_turn(const ImageViewRGB32& screen){ + m_faint_polls = 0; + if (m_kind != BattleKind::TRAINER && m_decisions.turns() == 0){ + m_supplies.wild_foes = read_wild_foes(m_console.logger(), m_language, screen); + } + if (!m_foes.species().empty()){ + m_foes.at_menu(read_trainer_foe(m_console.logger(), m_language, screen, m_foes.species())); + m_supplies.foe_out = m_foes.out(); + } + if (m_refusal.refused(current_time())){ + m_console.log("Battle: the move list came back without a turn (Disable?); choosing another move.", COLOR_ORANGE); + m_decisions.turn_done(TurnChoice::MOVE, TurnResult::REFUSED); + } + const PartyStatus status = read_party_status(screen); + const TurnAction action = m_decisions.turn(status); + m_evolution.turn_taken(action.choice); + m_console.log(std::format( + "Battle: turn {}, HP {} ({:.0f}% of the bar), {}, {} Potions, {} Antidotes, {} Parlyz Heals.", + m_decisions.turns(), status.hp_red ? "red" : status.hp_yellow ? "yellow" : "green", 100 * status.hp_fill, + status_name(status.status), m_supplies.potions, m_supplies.antidotes, m_supplies.parlyz_heals + )); + dump_debug_image(m_console, "AutoStory/battle", std::format("turn{}-menu", m_decisions.turns()), screen); + switch (action.choice){ + case TurnChoice::RUN: + m_console.log("Battle: RUN."); + run_away(m_context); + return; + case TurnChoice::POTION: + m_decisions.turn_done(action.choice, item_result(use_item(m_console, m_context, item_row(m_supplies, "potion"), "potion", m_checks, m_language))); + return; + case TurnChoice::ANTIDOTE: + m_decisions.turn_done(action.choice, item_result(use_item(m_console, m_context, item_row(m_supplies, "antidote"), "antidote", m_checks, m_language))); + return; + case TurnChoice::MOVE: + m_console.log(std::format("Battle: move {}.", action.slot + 1)); + m_refusal.move_chosen(current_time()); + use_move(m_context, action.slot); + m_move_chosen = true; + return; + } + } + + void watch_for_faint(const ImageViewRGB32& screen){ + if (m_decisions.turns() == 0 || m_decisions.lost()){ + return; + } + m_faint_polls = starter_fainted(screen) ? m_faint_polls + 1 : 0; + if (m_faint_polls >= FAINT_POLLS){ + m_console.log("Battle: the starter fainted.", COLOR_RED); + m_decisions.lead_fainted(); + } + } + + ConsoleHandle& m_console; + ProControllerContext& m_context; + Supplies& m_supplies; + BattleDecisions m_decisions; + EvolutionHold m_evolution; + TrainerFoeTracker m_foes; + BattleEndWatch m_end; + MoveRefusalWatch m_refusal; + const BattleKind m_kind; + const StoryChecks m_checks; + const Language m_language; + const WallClock m_start; + WallClock m_last_battle; + WallClock m_last_press; + WallClock m_last_menu; + WallClock m_last_overworld_check; + BattleScreen m_last_seen = BattleScreen::NONE; + bool m_seen_battle = false; + bool m_confirmed = false; + bool m_press_a = true; + // A move was chosen and no battle menu has shown since. + bool m_move_chosen = false; + int m_faint_polls = 0; +}; + + +// From the overworld: the bag open on the Items pocket, cursor on its top. +void open_items_pocket(ConsoleHandle& console, ProControllerContext& context){ + open_bag_from_overworld(console, context); + // The bag ignores presses while it slides in. + pbf_wait(context, 1000ms); + for (int c = 0; c < 3; c++){ + pbf_press_dpad(context, DPAD_LEFT, 100ms, 500ms); + } + for (int c = 0; c < 20; c++){ + pbf_press_dpad(context, DPAD_UP, 100ms, 100ms); + } +} + +// From the overworld: `item`, in `row` (from 0) of the Items pocket, on +// the starter. Returns whether it was used (THOROUGH reads the row first). +// Not run on the console yet. +bool use_item_on_overworld( + ConsoleHandle& console, ProControllerContext& context, + int row, const std::string& item, StoryChecks checks, Language language +){ + console.log(std::format("Story: using a {} from the bag (Items pocket, row {}).", item, row + 1)); + open_items_pocket(console, context); + for (int c = 0; c < row; c++){ + pbf_press_dpad(context, DPAD_DOWN, 100ms, 300ms); + } + if (!bag_row_is(console, context, row, item, checks, language)){ + mash_until_overworld(console, context, AFTER_BATTLE_TEXT); + return false; + } + // The item, USE, the starter, then its message. + pbf_press_button(context, BUTTON_A, 160ms, 800ms); + pbf_press_button(context, BUTTON_A, 160ms, 1500ms); + pbf_press_button(context, BUTTON_A, 160ms, 2500ms); + pbf_press_button(context, BUTTON_B, 160ms, 1500ms); + mash_until_overworld(console, context, AFTER_BATTLE_TEXT); + return true; +} + +void fail_on_blackout(ConsoleHandle& console, BattleEnd end){ + if (end == BattleEnd::LOST){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::NO_ERROR_REPORT, "Story: blackout: the starter fainted in a battle on the way.", console + ); + } +} + + +// A wild battle, seen by its flashes or, when they were missed, by "Wild +// appeared!". +class StoryWildBattle : public OverworldInterrupt{ +public: + StoryWildBattle(Supplies& supplies, bool fight, bool late, StoryChecks checks, Language language) + : m_supplies(supplies) + , m_checks(checks) + , m_language(language) + , m_fight(fight) + , m_late(late) + {} + virtual std::string name() const override{ + return m_late ? "a wild battle (seen late)" : "a wild battle"; + } + virtual std::unique_ptr make_watcher() const override{ + if (m_late){ + return std::make_unique(COLOR_RED); + } + return std::make_unique(COLOR_RED); + } + // As the walker's own wild battle interrupts. + virtual Milliseconds detection_delay() const override{ + return m_late ? 2000ms : 300ms; + } + // Run from or fought by the battle loop, which returns only once START + // opens on the overworld, so nothing of the battle is left before the + // next leg. + virtual void clear(ConsoleHandle& console, ProControllerContext& context) const override{ + const BattleKind kind = m_fight ? BattleKind::WILD_FIGHT : BattleKind::WILD_RUN; + fail_on_blackout(console, fight_battle(console, context, m_supplies, kind, m_checks, m_language)); + recover_after_battle(console, context, m_supplies, m_checks, m_language); + } + +private: + Supplies& m_supplies; + const StoryChecks m_checks; + const Language m_language; + const bool m_fight; + const bool m_late; +}; + +// A message: read to its end, then a trainer's battle if one starts. +class StoryMessage : public OverworldInterrupt{ +public: + StoryMessage(Supplies& supplies, StoryChecks checks, Language language) + : m_supplies(supplies) + , m_checks(checks) + , m_language(language) + {} + virtual std::string name() const override{ + return "a message"; + } + virtual std::unique_ptr make_watcher() const override{ + return std::make_unique(COLOR_RED); + } + virtual Milliseconds detection_delay() const override{ + return 400ms; + } + virtual void clear(ConsoleHandle& console, ProControllerContext& context) const override{ + if (advance_text(console, context, AFTER_BATTLE_TEXT, true) == TextEnd::OVERWORLD){ + return; + } + console.log("Story: a trainer's battle after a message on the overworld."); + fail_on_blackout(console, fight_battle(console, context, m_supplies, BattleKind::TRAINER, m_checks, m_language)); + mash_until_overworld(console, context, AFTER_BATTLE_TEXT); + recover_after_battle(console, context, m_supplies, m_checks, m_language); + } + +private: + Supplies& m_supplies; + const StoryChecks m_checks; + const Language m_language; +}; + +} + + +const char* status_name(StatusCondition status){ + switch (status){ + case StatusCondition::NONE: + return "no status"; + case StatusCondition::POISON: + return "PSN"; + case StatusCondition::PARALYSIS: + return "PAR"; + case StatusCondition::OTHER: + return "a status"; + } + return "?"; +} + +PartyStatus read_party_status(const ImageViewRGB32& screen){ + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + const HpBarReading bar = read_player_hp_bar(game); + PartyStatus status; + status.hp_seen = bar.seen; + status.hp_yellow = bar.seen && bar.color == HpBarColor::YELLOW; + status.hp_red = bar.seen && bar.color == HpBarColor::RED; + status.hp_fill = bar.fill; + status.status = read_status_badge(extract_box_reference(game, STATUS_BADGE_BOX)); + return status; +} + +bool battle_shows(const ImageViewRGB32& screen){ + const BattleTextScreen text = read_text_screen(screen); + return text.hp_box || text.yes_no; +} + +// The count the story keeps for `item`, or null for an item it doesn't count. +static int* count_slot(Supplies& supplies, const std::string& item){ + if (item == "potion"){ + return &supplies.potions; + } + if (item == "antidote"){ + return &supplies.antidotes; + } + if (item == "parlyz-heal"){ + return &supplies.parlyz_heals; + } + return nullptr; +} + +int item_count(const Supplies& supplies, const std::string& item){ + if (item == "potion"){ + return supplies.potions; + } + if (item == "antidote"){ + return supplies.antidotes; + } + if (item == "parlyz-heal"){ + return supplies.parlyz_heals; + } + return 0; +} + +// Whether the story keeps a count for `item`. +static bool counted(const std::string& item){ + Supplies probe; + return count_slot(probe, item) != nullptr; +} + +int item_row(const Supplies& supplies, const std::string& item){ + int row = 0; + for (const std::string& slot : supplies.pocket){ + if (counted(slot) && item_count(supplies, slot) <= 0){ + continue; + } + if (slot == item){ + return row; + } + row++; + } + return -1; +} + +std::vector set_from_bag(Supplies& supplies, const std::vector& rows){ + const Supplies before = supplies; + supplies.potions = 0; + supplies.antidotes = 0; + supplies.parlyz_heals = 0; + supplies.pocket.clear(); + std::vector unread; + for (const BagRow& row : rows){ + supplies.pocket.push_back(row.item); + int* slot = count_slot(supplies, row.item); + if (slot == nullptr){ + continue; + } + if (row.count > 0){ + *slot = row.count; + continue; + } + // Taking an unread count for none left the starter unhealed at + // 9 HP until it fainted (console B, 2026-11-02). + *slot = std::max(item_count(before, row.item), 1); + unread.push_back(row.item); + } + return unread; +} + +std::vector set_from_loaded_bag(Supplies& supplies, Supplies& saved, const std::vector& rows){ + if (rows.empty()){ + return {}; + } + std::vector unread = set_from_bag(supplies, rows); + saved.potions = supplies.potions; + saved.antidotes = supplies.antidotes; + saved.parlyz_heals = supplies.parlyz_heals; + saved.pocket = supplies.pocket; + return unread; +} + +std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context, Language language){ + open_items_pocket(console, context); + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + dump_debug_image(console, "AutoStory/bag", "items-pocket", screen); + std::vector rows = screen ? read_bag_pocket(console, language, screen) : std::vector{}; + std::string text; + for (const BagRow& row : rows){ + text += std::format(" {} x{};", row.item, row.count); + } + console.log("Bag: Items pocket:" + (text.empty() ? std::string(" nothing read.") : text)); + mash_until_overworld(console, context, AFTER_BATTLE_TEXT); + return rows; +} + +void recover_after_battle( + ConsoleHandle& console, ProControllerContext& context, + Supplies& supplies, StoryChecks checks, Language language +){ + if (supplies.status == StatusCondition::POISON && supplies.antidotes > 0){ + if (use_item_on_overworld(console, context, item_row(supplies, "antidote"), "antidote", checks, language)){ + supplies.antidotes--; + supplies.status = StatusCondition::NONE; + } + }else if (supplies.status == StatusCondition::PARALYSIS && supplies.parlyz_heals > 0){ + if (use_item_on_overworld(console, context, item_row(supplies, "parlyz-heal"), "parlyz-heal", checks, language)){ + supplies.parlyz_heals--; + supplies.status = StatusCondition::NONE; + } + } + // One Potion (20 HP) takes a starter of these levels (about 30 HP) + // from red to green; the bar can't be read again on the overworld. + if (supplies.hurt && supplies.potions > 0){ + if (use_item_on_overworld(console, context, item_row(supplies, "potion"), "potion", checks, language)){ + supplies.potions--; + supplies.hurt = false; + supplies.hp_red = false; + supplies.hp_fill = 1.0; + } + } +} + +BattleEnd fight_battle( + ConsoleHandle& console, ProControllerContext& context, + Supplies& supplies, BattleKind kind, StoryChecks checks, Language language +){ + return BattleLoop(console, context, supplies, kind, checks, language).run(); +} + +OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks, Language language){ + // Battles first: their screens are checked before the message box's. + OverworldInterruptSet ret; + ret.wild.emplace_back(std::make_unique(supplies, fight_wild, false, checks, language)); + ret.wild.emplace_back(std::make_unique(supplies, fight_wild, true, checks, language)); + ret.wild.emplace_back(std::make_unique(supplies, checks, language)); + ret.other.emplace_back(std::make_unique(supplies, checks, language)); + return ret; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h new file mode 100644 index 0000000000..7b16b43608 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -0,0 +1,205 @@ +/* AutoStory Battle + * + * From: https://github.com/PokemonAutomation/ + * + * The battle loop of the FRLG story, the starter leading, as the by-hand + * run to Brock played it (console B, 2026-11-01): at each turn the cursor + * is put back on FIGHT and the move list's top left, since the game + * remembers both, then onto the move BattleDecisions picks. A Potion is + * used when the HP bar turns yellow or red, an Antidote (once a battle) + * when the status reads PSN at two turns in a row; after the battle, PSN + * and PAR are cured from the bag. Move prompts, an evolution after the + * battle and a fainted lead are as PokemonFRLG_AutoStoryBattleDecisions.h + * says. + * + * Also the overworld interrupts the story walks routes with: wild battles + * run from (or fought, for EXP), and messages, after which a trainer's + * battle is fought instead of stopping the route. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattle_H +#define PokemonAutomation_PokemonFRLG_AutoStoryBattle_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattleData.h" +#include "PokemonFRLG_AutoStoryParty.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// A status condition, as far as the story treats them: the two it carries +// items for, and the rest, which only a nurse cures. +enum class StatusCondition{ + NONE, + POISON, + PARALYSIS, + OTHER, // SLP, BRN, FRZ +}; +const char* status_name(StatusCondition status); + +// The healing items in the Items pocket, in the order they were bought: +// Potions, Antidotes, then Parlyz Heals. +struct Supplies{ + int potions = 0; + int antidotes = 0; + int parlyz_heals = 0; + // The Items pocket's order, by slug (see read_item_list_name()): the + // order bought, or as read from the bag, with "" for a row whose name + // couldn't be read. A counted item with none left takes no row; the + // others always take theirs. + std::vector pocket = {"potion", "antidote", "parlyz-heal"}; + // The starter's status at the last battle screen that showed it, and + // not cured since. + StatusCondition status = StatusCondition::NONE; + // The starter's HP bar wasn't green (or was red) at the last battle + // screen that showed it, and no Potion or nurse healed it since. + bool hurt = false; + bool hp_red = false; + // The starter's HP bar's filled share at the last battle screen that + // showed it, 1 after the nurse or a Potion on the overworld. + double hp_fill = 1.0; + // The starter's moves and their PP, as far as the story knows them: + // a new game's Squirtle unless a checkpoint's row says otherwise. + PartyMember lead = new_member("squirtle", 5); + // Party slots (from 0, the lead) that are never sent in when the lead + // faints, so they gain no EXP and learn or evolve nothing: a member + // kept for later, or one the user keeps for a trade. + std::vector protected_slots = {}; + // The party of the trainer the table's battle step fights, when the + // story knows it (trainer_party()): the lead's attacks are chosen + // against it while the one out isn't known. Empty otherwise; wild + // battles never use it. + std::vector foes = {}; + // That trainer (story_trainer()), "" otherwise. + std::string trainer = {}; + // How carefully that battle is fought (story_battle_risk()). + BattleRisk risk = BattleRisk::LOW; + // The slot of the trainer's party out, as the battle loop tracks it + // (TrainerFoeTracker): the lead's attacks are chosen against it. + std::optional foe_out = {}; + // The wild Pokemon of the battle going on, as read at its first battle + // menu (read_wild_foes()): the lead's attacks are chosen against it. + // Empty when it wasn't read; trainer battles never use it. + std::vector wild_foes = {}; +}; + +// The nurse healed the party: HP, status and PP. +void healed_by_nurse(Supplies& supplies); + +// The lead's attacks are low on PP: the nurse before a fight that needs them. +bool attacks_low_on_pp(const Supplies& supplies); + +// Before a trainer's battle, once the items are used: the nurse for HP +// not green (no Potion left to heal it), a status no item cured, or +// attacks low on PP. Yellow HP counts (console B, 2026-11-03: 17/55 HP +// and no Potion into Miguel's battle, which only red would have stopped). +bool nurse_before_battle(const Supplies& supplies); + +enum class BattleKind{ + WILD_RUN, // RUN, or fight after a few "Can't escape!" + WILD_FIGHT, // fight for EXP with green HP, no status and 2 Potions, else RUN + TRAINER, +}; + +enum class BattleEnd{ + WON, + // The starter fainted: a blackout, or a wild battle run from (or won) + // by the next member, except in the lab's rival battle, which the + // story goes on from. + LOST, +}; + +// How many of `item` (a slug) the bag holds, as far as known. +int item_count(const Supplies& supplies, const std::string& item); + +// The row (from 0) of `item` in the Items pocket, or -1 if none is left. +// Items the story doesn't count, such as a MOON STONE, take rows too. +int item_row(const Supplies& supplies, const std::string& item); + +// Sets the counts and the pocket's order from the Items pocket as read. +// A row whose count couldn't be read still holds at least one: it keeps +// the count known before (the order bought), or 1. Returns those rows' +// items, for the log. +std::vector set_from_bag(Supplies& supplies, const std::vector& rows); + +// After a save is loaded: the Items pocket as read, taken into `supplies` +// and `saved` (what a reload restores) in place of the row's counts, as +// set_from_bag() does. With nothing read both keep the row's. Returns the +// items whose count couldn't be read. +std::vector set_from_loaded_bag(Supplies& supplies, Supplies& saved, const std::vector& rows); + +// From the overworld: opens the Items pocket, reads it, and closes the +// bag again. Empty if nothing could be read. +std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context, Language language); + + +// What the HP bar (read_player_hp_bar()) and the status badge of the +// player's Pokemon show, on a battle screen with its box. The badge's +// place measured on console B's captures (2026-11-01): off-white +// (255, 255, 217) with no status, (228, 168, 212) for PSN. +struct PartyStatus{ + bool hp_seen = false; + bool hp_yellow = false; + bool hp_red = false; + // The HP bar's filled share of its width, 0 to 1, for the log. + double hp_fill = 0; + StatusCondition status = StatusCondition::NONE; +}; +PartyStatus read_party_status(const ImageViewRGB32& screen); + +// Whether `screen` shows a battle, for the battle loop's end: the battle +// menu, an HP box or a YES/NO. Not the text box alone, which also reads on +// the black below a small room or a dark cave's corridor. +bool battle_shows(const ImageViewRGB32& screen); + +// From anywhere in a battle (or its opening), plays it to the end as +// `kind` says, using `supplies` as needed. Returns once START opens the +// menu on the overworld: text after the battle (a gym leader's speech) is +// read with B on the way. After 30 s of A and B for a screen nothing reads, +// returns anyway, for the walk to find the player. Throws +// OperationFailedException if it runs over 10 minutes. +// THOROUGH: an item's name is read in the bag before it is used, and a +// different one isn't used. +BattleEnd fight_battle( + ConsoleHandle& console, ProControllerContext& context, + Supplies& supplies, BattleKind kind, StoryChecks checks, Language language +); + + +// From the overworld, after a battle: an Antidote for PSN, a Parlyz Heal +// for PAR, then a Potion if the HP bar wasn't green, each if one is left. +// The bag's inputs are not checked on the console yet. +void recover_after_battle( + ConsoleHandle& console, ProControllerContext& context, + Supplies& supplies, StoryChecks checks, Language language +); + + +// The interrupts for walking story routes. Wild battles are run from, or +// fought if `fight_wild`. A message is advanced until the overworld is +// back; a battle that starts after it (a trainer who saw the player) is +// fought. A battle lost (a blackout) throws OperationFailedException. +OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks, Language language); + + +void add_tests_AutoStoryItems(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp new file mode 100644 index 0000000000..4b7e4f2e3c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp @@ -0,0 +1,322 @@ +/* AutoStory Battle Data + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "Common/Cpp/Json/JsonValue.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_WildEncounterReader.h" +#include "PokemonFRLG_AutoStoryBattleData.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// The trainer each of the story's battle steps fights, by the map the +// step leaves the player on and the step's name. The rival's teams are +// those against a player who took Squirtle. On a map with more than one +// trainer of a kind, the object's tile and script (pret +// data/maps//map.json, scripts.inc) say which. A row's `risk`, when +// set, overrides its trainer's default_battle_risk(): tune it here. +struct StoryTrainer{ + std::string_view map; + std::string_view battle; + std::string_view trainer; + std::optional risk = std::nullopt; +}; +constexpr StoryTrainer STORY_TRAINERS[] = { + {.map = "PalletTown_ProfessorOaksLab", .battle = "rival_battle", .trainer = "TRAINER_RIVAL_OAKS_LAB_BULBASAUR"}, + {.map = "PewterCity_Gym", .battle = "camper_liam", .trainer = "TRAINER_CAMPER_LIAM"}, + {.map = "PewterCity_Gym", .battle = "brock", .trainer = "TRAINER_LEADER_BROCK"}, + {.map = "Route3", .battle = "bug_catcher_colton", .trainer = "TRAINER_BUG_CATCHER_COLTON"}, + {.map = "Route3", .battle = "bug_catcher_greg", .trainer = "TRAINER_BUG_CATCHER_GREG"}, + {.map = "Route3", .battle = "bug_catcher_james", .trainer = "TRAINER_BUG_CATCHER_JAMES"}, + // Grunt1 at (12, 20), MtMoon_B2F_EventScript_Grunt1. + {.map = "MtMoon_B2F", .battle = "rocket_grunt", .trainer = "TRAINER_TEAM_ROCKET_GRUNT"}, + {.map = "MtMoon_B2F", .battle = "super_nerd_miguel", .trainer = "TRAINER_SUPER_NERD_MIGUEL"}, + {.map = "CeruleanCity", .battle = "rival_cerulean", .trainer = "TRAINER_RIVAL_CERULEAN_BULBASAUR"}, + {.map = "Route24", .battle = "bug_catcher_cale", .trainer = "TRAINER_BUG_CATCHER_CALE"}, + {.map = "Route24", .battle = "lass_ali", .trainer = "TRAINER_LASS_ALI"}, + {.map = "Route24", .battle = "youngster_timmy", .trainer = "TRAINER_YOUNGSTER_TIMMY"}, + {.map = "Route24", .battle = "lass_reli", .trainer = "TRAINER_LASS_RELI"}, + {.map = "Route24", .battle = "camper_ethan", .trainer = "TRAINER_CAMPER_ETHAN"}, + // The Nugget Bridge Rocket, Route24_EventScript_Rocket. + {.map = "Route24", .battle = "rocket_grunt", .trainer = "TRAINER_TEAM_ROCKET_GRUNT_6"}, + {.map = "CeruleanCity_Gym", .battle = "misty", .trainer = "TRAINER_LEADER_MISTY"}, +}; + +using JsonTable = std::map>; + +const JsonValue& file_json(const std::string& name){ + static const JsonTable FILES = []{ + JsonTable files; + for (const auto& [file, text] : autostory_battle_json()){ + files.emplace(file, parse_json(text)); + } + return files; + }(); + const auto it = FILES.find(name); + if (it == FILES.end()){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "BattleData/" + name + ".json is not built into the program."); + } + return it->second; +} + +PokemonType type_of(const JsonValue& value){ + return Pokemon::POKEMON_TYPE_SLUGS().get_enum(value.to_string_throw(), PokemonType::NONE); +} + +uint8_t byte_of(const JsonValue& value){ + return static_cast(std::clamp(value.to_integer_throw(), 0, 255)); +} + +template +using Table = std::map>; + +// [power, type, pp, accuracy, priority, effect, chance] +const Table& moves(){ + static const Table MOVES = []{ + Table moves; + for (const auto& [name, value] : file_json("moves").to_object_throw()){ + const JsonArray& entry = value.to_array_throw(); + moves.emplace(name, MoveData{ + .power = byte_of(entry[0]), .type = type_of(entry[1]), .pp = byte_of(entry[2]), + .accuracy = byte_of(entry[3]), .priority = static_cast(entry[4].to_integer_throw()), + .effect = entry[5].to_string_throw(), .effect_chance = byte_of(entry[6]), + }); + } + return moves; + }(); + return MOVES; +} + +// [type, type, HP, Attack, Defense, Sp. Atk, Sp. Def, Speed] +const Table& species(){ + static const Table SPECIES = []{ + Table species; + for (const auto& [name, value] : file_json("species").to_object_throw()){ + const JsonArray& entry = value.to_array_throw(); + species.emplace(name, SpeciesData{ + .first = type_of(entry[0]), .second = type_of(entry[1]), + .base = BaseStats{ + .hp = byte_of(entry[2]), .attack = byte_of(entry[3]), .defense = byte_of(entry[4]), + .sp_attack = byte_of(entry[5]), .sp_defense = byte_of(entry[6]), .speed = byte_of(entry[7]), + }, + }); + } + return species; + }(); + return SPECIES; +} + +// The type chart's rows in its order: (attack, defend, tenths). +const std::vector>& chart_rows(){ + static const std::vector> ROWS = []{ + std::vector> rows; + for (const JsonValue& value : file_json("type_chart").to_array_throw()){ + const JsonArray& entry = value.to_array_throw(); + rows.emplace_back(type_of(entry[0]), type_of(entry[1]), static_cast(entry[2].to_integer_throw())); + } + return rows; + }(); + return ROWS; +} + +std::vector strings_of(const JsonValue& value){ + std::vector strings; + for (const JsonValue& item : value.to_array_throw()){ + strings.push_back(item.to_string_throw()); + } + return strings; +} + +// [species, level, iv, nature, [moves]] +TrainerMon trainer_mon(const JsonArray& entry){ + return TrainerMon{ + .species = entry[0].to_string_throw(), .level = byte_of(entry[1]), + .iv = byte_of(entry[2]), .nature = byte_of(entry[3]), .moves = strings_of(entry[4]), + }; +} + +// {"ai": [...], "items": [...], "party": [...]} +TrainerData trainer_entry(const JsonObject& entry){ + TrainerData data{.ai = strings_of(entry.get_value_throw("ai")), .items = strings_of(entry.get_value_throw("items")), .party = {}}; + for (const JsonValue& value : entry.get_value_throw("party").to_array_throw()){ + data.party.push_back(trainer_mon(value.to_array_throw())); + } + return data; +} + +bool starts_with_any(std::string_view text, std::initializer_list prefixes){ + return std::ranges::any_of(prefixes, [text](std::string_view prefix){ + return text.starts_with(prefix); + }); +} + +} + + +const MoveData* move_data(std::string_view move){ + const auto it = moves().find(move); + return it == moves().end() ? nullptr : &it->second; +} + +const SpeciesData* species_data(std::string_view name){ + const auto it = species().find(name); + return it == species().end() ? nullptr : &it->second; +} + +const std::set& battle_species(){ + static const std::set NAMES = []{ + std::set names; + for (const auto& item : species()){ + names.insert(item.first); + } + return names; + }(); + return NAMES; +} + +std::vector wild_foes(std::string_view species){ + if (species_data(species) == nullptr){ + return {}; + } + return {std::string(species)}; +} + +std::vector read_wild_foes(Logger& logger, Language language, const ImageViewRGB32& screen){ + if (language == Language::None){ + return {}; + } + const std::string species = WildEncounterReader().read_encounter(logger, language, screen, battle_species()).name; + std::vector foes = wild_foes(species); + logger.log(foes.empty() + ? "Battle: the wild Pokemon wasn't read; attacks in the plan's order." + : "Battle: a wild " + species + "; attacks are chosen against it." + ); + return foes; +} + +size_t type_effectiveness(PokemonType attack, PokemonType defend){ + static const std::map, size_t> CHART = []{ + std::map, size_t> chart; + for (const JsonValue& value : file_json("type_chart").to_array_throw()){ + const JsonArray& entry = value.to_array_throw(); + chart[{type_of(entry[0]), type_of(entry[1])}] = static_cast(entry[2].to_integer_throw()); + } + return chart; + }(); + const auto it = CHART.find({attack, defend}); + return it == CHART.end() ? 10 : it->second; +} + +std::vector type_multipliers(PokemonType attack, PokemonType first, PokemonType second){ + std::vector multipliers; + for (const auto& [row_attack, defend, tenths] : chart_rows()){ + if (row_attack != attack){ + continue; + } + if (defend == first){ + multipliers.push_back(tenths); + } + if (defend == second && first != second){ + multipliers.push_back(tenths); + } + } + return multipliers; +} + +bool special_type(PokemonType type){ + switch (type){ + case PokemonType::FIRE: + case PokemonType::WATER: + case PokemonType::GRASS: + case PokemonType::ELECTRIC: + case PokemonType::PSYCHIC: + case PokemonType::ICE: + case PokemonType::DRAGON: + case PokemonType::DARK: + return true; + default: + return false; + } +} + +std::vector trainer_mons(std::string_view trainer){ + std::optional data = trainer_data(trainer); + return data ? std::move(data->party) : std::vector{}; +} + +std::optional trainer_data(std::string_view trainer){ + const JsonObject& trainers = file_json("trainers").to_object_throw(); + const auto it = trainers.find(std::string(trainer)); + if (it == trainers.end()){ + return std::nullopt; + } + return trainer_entry(it->second.to_object_throw()); +} + +std::string read_trainer_foe(Logger& logger, Language language, const ImageViewRGB32& screen, const std::vector& party){ + if (language == Language::None || party.empty()){ + return ""; + } + const std::set species(party.begin(), party.end()); + std::string read = WildEncounterReader().read_encounter(logger, language, screen, species).name; + if (!species.contains(read)){ + read.clear(); + } + logger.log(read.empty() ? "Battle: the trainer's Pokemon wasn't read." : "Battle: the trainer's " + read + " is out."); + return read; +} + +std::vector map_trainers(std::string_view map){ + const JsonObject& maps = file_json("map_trainers").to_object_throw(); + const auto it = maps.find(std::string(map)); + return it == maps.end() ? std::vector{} : strings_of(it->second); +} + +std::optional story_trainer(std::string_view map, std::string_view battle){ + for (const StoryTrainer& entry : STORY_TRAINERS){ + if (entry.map == map && entry.battle == battle){ + return entry.trainer; + } + } + return std::nullopt; +} + +const char* battle_risk_name(BattleRisk risk){ + return risk == BattleRisk::HIGH ? "high" : "low"; +} + +BattleRisk default_battle_risk(std::string_view trainer){ + const bool big = starts_with_any(trainer, { + "TRAINER_RIVAL_", "TRAINER_CHAMPION_", "TRAINER_LEADER_", "TRAINER_ELITE_FOUR_", "TRAINER_BOSS_", "TRAINER_TEAM_ROCKET_ADMIN", + }); + return big ? BattleRisk::HIGH : BattleRisk::LOW; +} + +BattleRisk story_battle_risk(std::string_view map, std::string_view battle){ + for (const StoryTrainer& entry : STORY_TRAINERS){ + if (entry.map == map && entry.battle == battle){ + return entry.risk ? *entry.risk : default_battle_risk(entry.trainer); + } + } + return BattleRisk::LOW; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h new file mode 100644 index 0000000000..cc15a6b446 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h @@ -0,0 +1,177 @@ +/* AutoStory Battle Data + * + * From: https://github.com/PokemonAutomation/ + * + * The game's data the story's attacks are chosen from, generated from + * pret/pokefirered by devtools/maps/frlg_battle_data.py into BattleData/ + * and built into the program: the type chart, every species' types and + * base stats, every move's power, type, PP, accuracy, priority and + * effect, every trainer's AI flags, items and party, and the trainers + * each map battles. Also which trainer each of the story's battle steps + * fights, and how carefully (BattleRisk). + * + * Names are the program's slugs ("water-gun", "mr-mime"); trainers are + * pret's constants ("TRAINER_SUPER_NERD_MIGUEL"). + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattleData_H +#define PokemonAutomation_PokemonFRLG_AutoStoryBattleData_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" +#include "Pokemon/Pokemon_Types.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +using Pokemon::PokemonType; + +struct MoveData{ + // Moves whose damage doesn't come from their power (Flail, Dragon + // Rage) have 1; moves that do no damage 0. + uint8_t power = 0; + // NONE for Curse's "???". + PokemonType type = PokemonType::NONE; + uint8_t pp = 0; + // In percent; 0 never misses. + uint8_t accuracy = 0; + int8_t priority = 0; + // pret's EFFECT_X as a slug: "hit", "flinch-hit", "sleep", + // "attack-down", "dragon-rage". + std::string effect = {}; + // The secondary effect's chance in percent (Bite's flinch: 30). + uint8_t effect_chance = 0; +}; + +// The base stats, in the game's order. +struct BaseStats{ + uint8_t hp = 0; + uint8_t attack = 0; + uint8_t defense = 0; + uint8_t sp_attack = 0; + uint8_t sp_defense = 0; + uint8_t speed = 0; +}; + +struct SpeciesData{ + // The same type twice for a species with one. + PokemonType first = PokemonType::NONE; + PokemonType second = PokemonType::NONE; + BaseStats base = {}; +}; + +struct TrainerMon{ + std::string species; + uint8_t level = 0; + // pret's iv, 0 to 255: every IV is iv * 31 / 255 (CreateNPCTrainerParty). + uint8_t iv = 0; + // The nature's index (0 Hardy, 1 Lonely, ... 24 Quirky): the one the + // game's personality gives it (see frlg_battle_data.py). + uint8_t nature = 0; + // The moves the party gives it, else the level-up moves the game gives. + std::vector moves; +}; + +struct TrainerData{ + // pret's AI flags as slugs: "check-bad-move", "try-to-faint", ... + std::vector ai = {}; + // The items the trainer can use, in order, each once ("super-potion"). + std::vector items = {}; + std::vector party = {}; +}; + +// None for a move or species the data doesn't have. +const MoveData* move_data(std::string_view move); +const SpeciesData* species_data(std::string_view species); + +// Every species, for reading a wild Pokemon's name. +const std::set& battle_species(); + +// The foes of a wild battle whose Pokemon was read as `species`: it, or +// none when it wasn't read ("") or the data doesn't have it. +std::vector wild_foes(std::string_view species); + +// The foes of the wild battle on `screen`, a battle menu: the Pokemon its +// HP box names (WildEncounterReader, among battle_species()), as +// wild_foes() takes it. Logs what it read. +std::vector read_wild_foes(Logger& logger, Language language, const ImageViewRGB32& screen); + +// How well `attack` hits `defend`, in tenths: 20 is 2x, 5 is 0.5x. +size_t type_effectiveness(PokemonType attack, PokemonType defend); + +// The multipliers (in tenths) a move of type `attack` meets on a Pokemon +// of types `first` and `second`, in the type chart's order, as the game +// applies them one after another (pret Cmd_typecalc); none for 1x. +std::vector type_multipliers(PokemonType attack, PokemonType first, PokemonType second); + +// Gen 3 splits physical and special by type: Fire, Water, Grass, +// Electric, Psychic, Ice, Dragon and Dark are special. +bool special_type(PokemonType type); + +// A trainer's party in order; empty for a trainer the data doesn't have. +std::vector trainer_mons(std::string_view trainer); + +// A trainer's AI flags, items and party; none for one the data doesn't have. +std::optional trainer_data(std::string_view trainer); + +// The Pokemon a trainer's battle shows on `screen`, a battle menu: the +// name its HP box shows (WildEncounterReader), among `party`'s species. +// Empty if not read. Logs what it read. +std::string read_trainer_foe(Logger& logger, Language language, const ImageViewRGB32& screen, const std::vector& party); + +// The trainers `map`'s scripts and objects battle. +std::vector map_trainers(std::string_view map); + +// The trainer the story's battle step `battle` fights on `map` (the map +// it leaves the player on). None for a battle the table doesn't name. +std::optional story_trainer(std::string_view map, std::string_view battle); + +// How carefully a battle step is fought. +enum class BattleRisk{ + // The move with the best expected damage against the foe out. + LOW, + // A battle sim (PokemonFRLG_AutoStoryBattleSim.h) picks the moves and + // Potions, and the step fails before the fight when it wins too rarely. + HIGH, +}; +const char* battle_risk_name(BattleRisk risk); + +// A trainer's risk by its kind: HIGH for the rival, gym leaders, bosses +// (Giovanni, the Rocket admins), the Elite Four and the Champion; LOW +// for the rest. +BattleRisk default_battle_risk(std::string_view trainer); + +// The risk of the story's battle step `battle` on `map`: its table row's, +// else its trainer's default. LOW for a battle the table doesn't name. +BattleRisk story_battle_risk(std::string_view map, std::string_view battle); + +// A HIGH battle is fought only if the sim wins at least this often. +inline constexpr double MIN_WIN_CHANCE = 0.70; + + +// (name, JSON text) of each file in BattleData/, sorted by name. +// Generated at build time (SerialPrograms/cmake/EmbedTextFiles.cmake). +const std::vector>& autostory_battle_json(); + + +void add_tests_AutoStoryBattleData(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp new file mode 100644 index 0000000000..42ff159fbf --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp @@ -0,0 +1,204 @@ +/* AutoStory Battle Data Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The generated battle data, the trainer each story battle fights, and the + * attacks chosen against trainers' parties and wild Pokemon from it. + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryBattleData.h" +#include "PokemonFRLG_AutoStoryBattleDecisions.h" +#include "PokemonFRLG_AutoStoryBattleSim.h" +#include "PokemonFRLG_AutoStoryParty.h" +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +class Test_AutoStoryBattleData : public UnitTest{ +public: + Test_AutoStoryBattleData(std::string name, std::function body) + : UnitTest("PokemonFRLG::AutoStoryBattleData - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + +const PartyStatus GREEN{.hp_seen = true, .hp_yellow = false, .hp_red = false, .status = StatusCondition::NONE}; + +// The story's Wartortle once Bite is in: Tackle, Bite, Water Gun, Withdraw. +constexpr size_t BITE = 1; +constexpr size_t WATER_GUN = BOTTOM_LEFT_MOVE; + +std::string slot_name(std::optional slot){ + return slot ? std::to_string(*slot) : "none"; +} + +// The slot a wild battle's first turn attacks with, against `species` as +// read off the screen. +size_t wild_turn(const PartyMember& lead, std::string_view species){ + Supplies supplies; + supplies.lead = lead; + supplies.potions = 5; + supplies.wild_foes = wild_foes(species); + BattleDecisions wild(supplies, BattleKind::WILD_FIGHT); + return wild.turn(GREEN).slot; +} + + +// Spot checks against pret: the type chart, Bite, and species' types and +// stats. +UnitTestResult test_data(){ + if (type_effectiveness(PokemonType::WATER, PokemonType::FIRE) != 20 + || type_effectiveness(PokemonType::DARK, PokemonType::PSYCHIC) != 20 + || type_effectiveness(PokemonType::NORMAL, PokemonType::GHOST) != 0 + || type_effectiveness(PokemonType::WATER, PokemonType::NORMAL) != 10 + ){ + return "Expected Water 2x on Fire, Dark 2x on Psychic, Normal 0x on Ghost, Water 1x on Normal."; + } + const MoveData* bite = move_data("bite"); + if (bite == nullptr || bite->power != 60 || bite->type != PokemonType::DARK || bite->pp != 25 || !special_type(bite->type)){ + return "Expected Bite: 60 power, Dark (special in Gen 3), 25 PP."; + } + const SpeciesData* starmie = species_data("starmie"); + if (starmie == nullptr || starmie->first != PokemonType::WATER || starmie->second != PokemonType::PSYCHIC || starmie->base.sp_attack != 100){ + return "Expected Starmie: Water, Psychic, base Sp. Atk 100."; + } + if (battle_species().size() != 386 || species_data("farfetch-d") == nullptr || species_data("missingno") != nullptr){ + return std::format("Expected the 386 species by the program's slugs, got {}.", battle_species().size()); + } + return true; +} + +// Every battle step in the table fights a trainer its map battles in +// pret's scripts, with a party. +UnitTestResult test_story_trainers(){ + size_t battles = 0; + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + for (const StoryStep& step : checkpoint.steps){ + if (step.kind != StoryStepKind::BATTLE){ + continue; + } + battles++; + const std::string map = step.pose_after ? step.pose_after->map : ""; + const std::optional trainer = story_trainer(map, step.name); + if (!trainer){ + return std::format("{}, {} on {}: no trainer.", checkpoint.id, step.name, map); + } + const std::vector on_map = map_trainers(map); + if (std::find(on_map.begin(), on_map.end(), *trainer) == on_map.end()){ + return std::format("{} on {}: {} isn't one of the map's trainers.", step.name, map, *trainer); + } + if (trainer_party(*trainer).empty()){ + return std::format("{} on {}: {} has no party.", step.name, map, *trainer); + } + } + } + if (battles == 0){ + return "Expected battle steps in the table."; + } + if (trainer_party(*story_trainer("CeruleanCity_Gym", "misty")) != std::vector{"staryu", "starmie"}){ + return "Expected Misty's Staryu and Starmie."; + } + return true; +} + +// Mt. Moon: Super Nerd Miguel's Grimer (Poison) takes Water Gun, with or +// without Bite known: Bite (60, Dark) ties Water Gun (40 x 1.5 STAB), both +// special, and the tie goes to the plan's Water Gun. +UnitTestResult test_miguel_grimer(){ + const std::optional miguel = story_trainer("MtMoon_B2F", "super_nerd_miguel"); + if (!miguel || trainer_party(*miguel) != std::vector{"grimer", "voltorb", "koffing"}){ + return "Expected Miguel's Grimer, Voltorb and Koffing (pret's sParty_SuperNerdMiguel)."; + } + const std::vector leads{grown_to(new_member("squirtle", 5), 17), grown_to(new_member("squirtle", 5), 20)}; + for (const PartyMember& lead : leads){ + for (const std::vector& foes : {std::vector{"grimer"}, trainer_party(*miguel)}){ + const std::optional slot = attack_slot_against(lead, foes); + if (slot != WATER_GUN){ + return std::format("{} against {} foes: expected Water Gun, got slot {}.", lead.species, foes.size(), slot_name(slot)); + } + } + } + return true; +} + +// Bite where it does more than Water Gun: on a Psychic or Ghost foe (2x), +// and on one that resists Water, where Bite's 1x beats Water Gun's +// 0.5 x 1.5 STAB. Against a wild Pokemon as read, and a trainer's party. +UnitTestResult test_bite_wins(){ + const PartyMember wartortle = grown_to(new_member("squirtle", 5), 20); + for (std::string_view foe : {"abra", "starmie", "gastly", "staryu", "oddish", "dratini"}){ + const size_t slot = wild_turn(wartortle, foe); + if (slot != BITE){ + return std::format("A wild {}: expected Bite, got slot {}.", foe, slot); + } + } + for (std::string_view foe : {"geodude", "pidgey", "rattata"}){ + const size_t slot = wild_turn(wartortle, foe); + if (slot != WATER_GUN){ + return std::format("A wild {}: expected Water Gun, got slot {}.", foe, slot); + } + } + if (attack_slot_against(wartortle, trainer_party(*story_trainer("CeruleanCity_Gym", "misty"))) != BITE){ + return "Expected Bite against Misty's party."; + } + return true; +} + +// A wild Pokemon that wasn't read, or a name the data doesn't have, gets +// the plan's order: Water Gun first. +UnitTestResult test_wild_fallback(){ + const PartyMember wartortle = grown_to(new_member("squirtle", 5), 20); + for (std::string_view read : {"", "missingno"}){ + if (!wild_foes(read).empty()){ + return std::format("Expected no foes for \"{}\".", read); + } + const size_t slot = wild_turn(wartortle, read); + if (slot != WATER_GUN || attack_slot(wartortle) != WATER_GUN){ + return std::format("A wild \"{}\": expected the plan's Water Gun, got slot {}.", read, slot); + } + } + return true; +} + +} + + +void add_tests_AutoStoryBattleData(UnitTestDatabase& database){ + database.add("type chart, moves and species from pret", test_data); + database.add("every story battle fights a trainer with a party", test_story_trainers); + database.add("Miguel's Grimer: Water Gun", test_miguel_grimer); + database.add("Bite on Psychic, Ghost and Water-resistant foes", test_bite_wins); + database.add("a wild Pokemon not read: the plan's order", test_wild_fallback); + add_tests_AutoStoryBattleSim(database); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp new file mode 100644 index 0000000000..145b9e8c5f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -0,0 +1,390 @@ +/* AutoStory Battle Decisions + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "PokemonFRLG_AutoStoryBattleDecisions.h" +#include "PokemonFRLG_AutoStoryBattleSim.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +constexpr size_t PARTY_SLOTS = 6; +// A wild Pokemon is fought (WILD_FIGHT) only with green HP and this many +// Potions left; otherwise it is run from. +constexpr int MIN_POTIONS_TO_FIGHT = 2; +// RUN this many times ("Can't escape!") before fighting instead. +constexpr int RUN_TRIES = 4; +// PSN read at this many turns in a row before an Antidote. +constexpr int PSN_READS = 2; +// An evolution screen held this long was an evolution, not a text box +// between two others. +constexpr Milliseconds EVOLUTION_SEEN = std::chrono::milliseconds(5000); +// Nothing pressed for at most this long in all in a battle: an evolution +// and the next member's, with room to spare. +constexpr Milliseconds EVOLUTION_HOLDS = std::chrono::milliseconds(45000); +// No battle menu, HP box or YES/NO for this long: START, to see whether +// the overworld is back. Longer than a turn's text between two HP boxes. +constexpr Milliseconds BATTLE_GONE = std::chrono::milliseconds(3000); +// START at most this often: each look takes over a second. +constexpr Milliseconds OVERWORLD_CHECK = std::chrono::milliseconds(3000); +// A and B pressed blind for this long with no battle menu: give up. +constexpr Milliseconds BLIND_PRESSES = std::chrono::milliseconds(30000); +// Turns a move turned down is left alone: the longest Disable (pret +// battle_script_commands.c Cmd_disablelastusedattack, 2 to 5 turns). +constexpr int DISABLE_TURNS = 5; +// The battle menu back this soon after a move was chosen, with the move +// list between: the move wasn't used. +constexpr Milliseconds REFUSED_WITHIN = std::chrono::milliseconds(7000); +// Below this much PP left in the lead's attacks, the nurse before a fight +// that needs them: about a trainer's worth of turns. +constexpr size_t LOW_ATTACK_PP = 10; +// The move prompts a turn can bring: two moves offered, NO then YES each. +constexpr int MOVE_PROMPTS = 4; + +// The trainer's Pokemon out, at full HP (its damage taken isn't read), +// when the battle loop knows which. +std::optional foe_out(const Supplies& supplies){ + if (supplies.trainer.empty() || !supplies.foe_out){ + return std::nullopt; + } + const std::vector party = trainer_mons(supplies.trainer); + return *supplies.foe_out < party.size() ? trainer_battler(party[*supplies.foe_out]) : std::nullopt; +} + +// A trainer's battle: against the foe out, the best expected damage at +// BattleRisk::LOW, the sim's planned move at HIGH (its items taken as not +// used yet); else, or while the story doesn't know all the lead's +// moves, attack_slot_against() the whole party. +std::optional trainer_attack_slot(const PartyMember& usable, const Supplies& supplies){ + const std::optional foe = foe_out(supplies); + const std::optional own = own_battler(usable); + std::optional slot; + if (foe && own && attack_slot(usable)){ + const std::optional trainer = trainer_data(supplies.trainer); + slot = supplies.risk == BattleRisk::HIGH && trainer + ? planned_attack_slot(*own, *foe, trainer->items, trainer->party.size()) + : best_damage_slot(*own, *foe); + } + return slot ? slot : attack_slot_against(usable, supplies.foes); +} + +// A Potion this turn, against a known foe (`seen_hit` the HP its last hit +// took, 0 if not seen): at BattleRisk::HIGH when its next hit could faint +// the lead (potion_now(), the HP from the bar's share) or the bar is red, +// at LOW whenever the bar isn't green; either only if potion_pays(). +// Against a foe not known, whenever the bar isn't green, unless the last +// hit took a Potion's worth or more. +bool wants_potion(const Supplies& supplies, const PartyStatus& status, double seen_hit){ + const bool hurt = status.hp_red || status.hp_yellow; + const std::optional foe = foe_out(supplies); + const std::optional own = own_battler(supplies.lead, status.hp_seen ? status.hp_fill : 1.0); + if (!foe || !own){ + return hurt && seen_hit < POTION_HP; + } + if (supplies.risk == BattleRisk::HIGH && potion_now(*own, *foe, supplies.potions, seen_hit)){ + return true; + } + const bool asked = supplies.risk == BattleRisk::HIGH ? status.hp_red : hurt; + return asked && potion_pays(potion_case(*own, *foe, seen_hit)); +} + +// The lead's HP from the bar's share, if it showed. +std::optional lead_hp(const Supplies& supplies, const PartyStatus& status){ + const std::optional own = own_battler(supplies.lead); + if (!status.hp_seen || !own){ + return std::nullopt; + } + return status.hp_fill * own->body.stats.hp; +} + +} + + +void healed_by_nurse(Supplies& supplies){ + supplies.hurt = false; + supplies.hp_red = false; + supplies.hp_fill = 1.0; + supplies.status = StatusCondition::NONE; + restore_pp(supplies.lead); +} + +bool attacks_low_on_pp(const Supplies& supplies){ + return attack_slot(supplies.lead).has_value() && attack_pp(supplies.lead) < LOW_ATTACK_PP; +} + +bool nurse_before_battle(const Supplies& supplies){ + return supplies.hurt || supplies.status != StatusCondition::NONE || attacks_low_on_pp(supplies); +} + + +BattleDecisions::BattleDecisions(Supplies& supplies, BattleKind kind) + : m_supplies(supplies) + , m_kind(kind) +{} + +TurnAction BattleDecisions::turn(const PartyStatus& status){ + m_turns++; + m_move_prompts = 0; + m_before_forget.reset(); + count_down_refused(); + m_last_move_slot.reset(); + if (!m_lost){ + return lead_turn(status); + } + // The next member is out: it runs from a wild Pokemon for as long as + // it takes, and against a trainer uses its first move. + if (m_kind != BattleKind::TRAINER){ + return TurnAction{.choice = TurnChoice::RUN}; + } + return TurnAction{.choice = TurnChoice::MOVE, .slot = TOP_LEFT_MOVE}; +} + +TurnAction BattleDecisions::lead_turn(const PartyStatus& status){ + const bool hurt = status.hp_red || status.hp_yellow; + m_supplies.hurt = hurt; + if (status.hp_seen){ + m_supplies.hp_fill = status.hp_fill; + } + m_supplies.status = status.status; + m_psn_reads = status.status == StatusCondition::POISON ? m_psn_reads + 1 : 0; + // A wild Pokemon is fought for EXP only at full strength: fighting + // every one in Viridian Forest used up all 4 Potions and then the + // starter (console B, 2026-11-01). With a status, it is run from too. + const bool weak = hurt || status.status != StatusCondition::NONE || m_supplies.potions < MIN_POTIONS_TO_FIGHT; + const bool run = m_kind == BattleKind::WILD_RUN || (m_kind == BattleKind::WILD_FIGHT && weak); + if (run && m_run_tries < RUN_TRIES){ + m_run_tries++; + return TurnAction{.choice = TurnChoice::RUN}; + } + see_hit(status); + if (!m_items_off && m_supplies.potions > 0 && wants_potion(m_supplies, status, m_seen_hit)){ + return TurnAction{.choice = TurnChoice::POTION}; + } + if (!m_items_off && m_psn_reads >= PSN_READS && !m_antidote_used && m_supplies.antidotes > 0){ + m_antidote_used = true; + return TurnAction{.choice = TurnChoice::ANTIDOTE}; + } + return move_turn(); +} + +void BattleDecisions::see_hit(const PartyStatus& status){ + if (m_supplies.foe_out != m_hit_by){ + m_seen_hit = 0; + m_hit_by = m_supplies.foe_out; + } + const std::optional hp = lead_hp(m_supplies, status); + if (hp && m_last_hp){ + const double taken = *m_last_hp + (m_healed ? POTION_HP : 0) - *hp; + if (taken > 0){ + m_seen_hit = taken; + } + } + m_last_hp = hp; + m_healed = false; +} + +// The plan's attack with PP left, or against known foes (a trainer's +// party, the wild Pokemon read), the one that does them most damage. While the story doesn't know +// all four moves, the bottom left one (Bubble from Lv7), which the cursor +// can't reach while that slot is empty, so before Bubble it stays on +// Tackle. +TurnAction BattleDecisions::move_turn(){ + PartyMember usable = m_supplies.lead; + for (const auto& refused : m_refused){ + if (refused.first < usable.moves.size()){ + usable.moves[refused.first].pp = 0; + } + } + const std::optional slot = m_kind == BattleKind::TRAINER + ? trainer_attack_slot(usable, m_supplies) + : attack_slot_against(usable, m_supplies.wild_foes); + if (!slot){ + return TurnAction{.choice = TurnChoice::MOVE, .slot = BOTTOM_LEFT_MOVE}; + } + spend_pp(m_supplies.lead, *slot); + m_last_move_slot = slot; + return TurnAction{.choice = TurnChoice::MOVE, .slot = *slot}; +} + +void BattleDecisions::count_down_refused(){ + for (auto it = m_refused.begin(); it != m_refused.end();){ + it = --it->second <= 0 ? m_refused.erase(it) : std::next(it); + } +} + +void BattleDecisions::move_refused(){ + if (!m_last_move_slot){ + return; + } + const size_t slot = *m_last_move_slot; + if (slot < m_supplies.lead.moves.size()){ + m_supplies.lead.moves[slot].pp++; + } + // One more: the next turn() counts down the one that didn't happen. + m_refused[slot] = DISABLE_TURNS + 1; + m_last_move_slot.reset(); +} + +void BattleDecisions::turn_done(TurnChoice choice, TurnResult result){ + if (result == TurnResult::REFUSED){ + move_refused(); + return; + } + const bool done = result == TurnResult::DONE; + if (!done && choice == TurnChoice::MOVE){ + if (m_last_move_slot){ + no_pp_left(m_supplies.lead, *m_last_move_slot); + } + return; + } + if (!done){ + m_items_off = true; + return; + } + switch (choice){ + case TurnChoice::POTION: + m_healed = true; + m_supplies.potions--; + m_supplies.hurt = false; + m_supplies.hp_red = false; + return; + case TurnChoice::ANTIDOTE: + m_supplies.antidotes--; + return; + case TurnChoice::RUN: + case TurnChoice::MOVE: + return; + } +} + +PromptAnswer BattleDecisions::prompt(bool lead_box_gone){ + if (lead_box_gone){ + lead_fainted(); + // NO tries to run; if that fails, the party list opens. + return PromptAnswer{.answer = m_kind == BattleKind::TRAINER ? YesNo::YES : YesNo::NO}; + } + m_move_prompts++; + if (m_before_forget){ + // A YES/NO right after the move list: it closed with no move + // forgotten, and this is "Stop learning ?" (console B, + // 2026-11-03, Miguel's battle). The lead keeps its moves. + m_supplies.lead = std::move(*m_before_forget); + m_before_forget.reset(); + return PromptAnswer{.answer = YesNo::YES}; + } + if (m_move_prompts > MOVE_PROMPTS){ + // More than the move prompts can be: YES ends either one, as + // "Delete a move?" opens the move list, which the loop's B closes. + return PromptAnswer{.answer = YesNo::YES}; + } + if (m_declined_delete){ + // "Stop learning ?" YES; NO would ask "Delete a move?" again. + m_declined_delete = false; + return PromptAnswer{.answer = YesNo::YES}; + } + PartyMember learning = m_supplies.lead; + const LearnDecision decision = learn_move(learning); + if (decision.forget_slot){ + m_before_forget = m_supplies.lead; + return PromptAnswer{.answer = YesNo::YES, .forget_slot = decision.forget_slot, .learned = std::move(learning)}; + } + m_supplies.lead = std::move(learning); + m_declined_delete = true; + return PromptAnswer{.answer = YesNo::NO}; +} + +std::optional BattleDecisions::next_member_slot(){ + lead_fainted(); + // A slot sent before and still offered was empty or fainted: the next. + for (size_t slot = 1; slot < PARTY_SLOTS; slot++){ + const bool kept = std::ranges::find(m_supplies.protected_slots, slot) != m_supplies.protected_slots.end(); + if (!kept && !m_sent.contains(slot)){ + m_sent.insert(slot); + return slot; + } + } + return std::nullopt; +} + +void BattleDecisions::lead_fainted(){ + m_lost = true; +} + +EvolutionHold::EvolutionHold(PartyMember& lead) + : m_lead(lead) +{} + +void EvolutionHold::turn_taken(TurnChoice choice){ + m_attacked = choice == TurnChoice::MOVE; +} + +bool EvolutionHold::holds(const BattleTextScreen& screen) const{ + return m_attacked && m_held < EVOLUTION_HOLDS && screen.text_box && !screen.hp_box && !screen.arrow && !screen.yes_no; +} + +void EvolutionHold::held(Milliseconds held, bool lead_fainted){ + m_held += held; + // Only the lead fights, so only it evolves; once a battle. + if (held < EVOLUTION_SEEN || m_evolved || lead_fainted){ + return; + } + m_evolved = true; + evolve(m_lead); +} + +void BattleEndWatch::seen(BattleSeen what, WallClock now){ + if (what != BattleSeen::NONE){ + m_last_battle = now; + } + if (what == BattleSeen::MENU){ + m_blind_since.reset(); + } +} + +bool BattleEndWatch::check_overworld(WallClock now){ + if (!m_last_battle || now - *m_last_battle < BATTLE_GONE){ + return false; + } + if (m_last_check && now - *m_last_check < OVERWORLD_CHECK){ + return false; + } + m_last_check = now; + return true; +} + +void MoveRefusalWatch::move_chosen(WallClock now){ + m_chosen = now; + m_list_back = false; +} + +void MoveRefusalWatch::no_battle_screen(){ + m_list_back = m_chosen.has_value(); +} + +bool MoveRefusalWatch::refused(WallClock now){ + const bool refused = m_chosen && m_list_back && now - *m_chosen < REFUSED_WITHIN; + m_chosen.reset(); + m_list_back = false; + return refused; +} + +bool BattleEndWatch::pressed_blind(WallClock now){ + if (!m_blind_since){ + m_blind_since = now; + } + return now - *m_blind_since >= BLIND_PRESSES; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h new file mode 100644 index 0000000000..7d5e8e1736 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h @@ -0,0 +1,247 @@ +/* AutoStory Battle Decisions + * + * From: https://github.com/PokemonAutomation/ + * + * What the story's battle loop chooses at each screen, apart from reading + * the screens and pressing the buttons, so the choices run in tests: + * each turn's action, the YES/NO prompts (a move to learn, "Use next + * POKEMON?"), when not to press B for an evolution, and the lead's PP. + * + * The party is the lead (the starter) and members that don't fight: the + * lead is never switched out. If it faints, a wild battle is run from + * ("Use next POKEMON?" NO); a trainer's, or a failed run, sends the next + * member not in Supplies::protected_slots, which only runs or uses its + * first move; with only protected ones left, the program stops instead. + * The battle counts as lost either way. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattleDecisions_H +#define PokemonAutomation_PokemonFRLG_AutoStoryBattleDecisions_H + +#include +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryParty.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +enum class TurnChoice{ + RUN, + POTION, + ANTIDOTE, + MOVE, +}; + +struct TurnAction{ + TurnChoice choice = TurnChoice::MOVE; + // For MOVE, the move list's slot. + size_t slot = BOTTOM_LEFT_MOVE; +}; + +// What came of a TurnAction. +enum class TurnResult{ + DONE, + // An item not used (another item in its row), or a move the game said + // has no PP left. + NOT_DONE, + // The game turned the move down although it has PP left: a foe's + // Disable (console B, 2026-11-03, Mt. Moon: Miguel's Grimer disabled + // Water Gun, and the loop chose it 17 more times while no turn passed). + // Its PP comes back, and it isn't chosen for as long as Disable can + // last (pret: 2 to 5 turns). + REFUSED, +}; + +enum class YesNo{ + YES, + NO, +}; + +// A battle screen as the loop reads it, for the evolution check. +struct BattleTextScreen{ + // The battle's text box. + bool text_box = false; + // The battle menu or an HP box. + bool hp_box = false; + // The text waits for a button. + bool arrow = false; + // A YES/NO box. + bool yes_no = false; +}; + +struct PromptAnswer{ + YesNo answer = YesNo::NO; + // After YES to "Delete a move?": the slot to forget on the move list + // that opens, its cursor on the top move. + std::optional forget_slot = {}; + // With forget_slot: the lead once the move is learned, to keep only if + // the move list opened (console B, 2026-11-03: a YES/NO read where no + // move list followed was taken as Bite over Tail Whip, and the loop + // later chose Tail Whip for Bite). + std::optional learned = {}; +}; + + +class BattleDecisions{ +public: + BattleDecisions(Supplies& supplies, BattleKind kind); + + // At the battle menu, with the player's box as read. + TurnAction turn(const PartyStatus& status); + // What came of what turn() chose. + void turn_done(TurnChoice choice, TurnResult result); + + // A YES/NO in or after the battle. With the lead's box gone and the + // opponent's there, it is "Use next POKEMON?"; else the move prompts: + // "Delete a move to make room?", then "Stop learning?" after a NO, or + // after YES and a move list closed with nothing forgotten. Past + // MOVE_PROMPTS since the last turn, a plain YES, which ends them + // either way (console B, 2026-11-03: NO and YES out of step with the + // game went round for 75 s). + PromptAnswer prompt(bool lead_box_gone); + + // The party list opened with the lead fainted: the slot to send in, + // or none if every member left is protected. + std::optional next_member_slot(); + + // The lead's box gone for good: it fainted. + void lead_fainted(); + bool lost() const{ return m_lost; } + + size_t turns() const{ return m_turns; } + +private: + TurnAction lead_turn(const PartyStatus& status); + TurnAction move_turn(); + // The HP the lead lost since the last turn, from the bar. + void see_hit(const PartyStatus& status); + void count_down_refused(); + void move_refused(); + + Supplies& m_supplies; + const BattleKind m_kind; + size_t m_turns = 0; + int m_run_tries = 0; + int m_psn_reads = 0; + bool m_antidote_used = false; + // An item read as another in the bag: none is used again this battle. + bool m_items_off = false; + bool m_lost = false; + // NO was answered to "Delete a move?": "Stop learning?" comes next. + bool m_declined_delete = false; + // The move prompts since the last turn. + int m_move_prompts = 0; + // YES was answered to "Delete a move?": the lead as it was before. + // A YES/NO before the next turn means nothing was forgotten. + std::optional m_before_forget; + std::optional m_last_move_slot; + // The lead's HP at the last turn, from the bar, and whether a Potion + // was used on it since. + std::optional m_last_hp; + bool m_healed = false; + // The HP the last hit seen took, from the foe out `m_hit_by`; 0 if none + // was seen. + double m_seen_hit = 0; + std::optional m_hit_by; + // The slots the game turned down, and the turns until they are tried again. + std::map m_refused; + // The members sent in after the lead fainted. + std::set m_sent; +}; + + +// No B while an evolution may be on screen: any B cancels it (pret +// evolution_scene.c; console B, 2026-11-02: Squirtle stayed Lv16 after the +// battle loop's B presses). +class EvolutionHold{ +public: + explicit EvolutionHold(PartyMember& lead); + + // The loop took a turn: only one that attacked can end the battle in a + // win, and so in an evolution. + void turn_taken(TurnChoice choice); + // Whether `screen` may be an evolution: after a turn that attacked (not + // after RUN: console B, 2026-11-03, a minute without B after "Got away + // safely!"), the text box with no HP box and no arrow or YES/NO, as + // "What? is evolving!" shows through the animation. Nothing + // is pressed while it shows, for at most EVOLUTION_HOLDS in all in a + // battle, in case it is something else. + bool holds(const BattleTextScreen& screen) const; + // Such a screen showed for `held` with nothing pressed: long enough, + // and the lead evolved (unless it had fainted). + void held(Milliseconds held, bool lead_fainted); + +private: + PartyMember& m_lead; + bool m_attacked = false; + bool m_evolved = false; + Milliseconds m_held = Milliseconds::zero(); +}; + + +// What the battle loop saw of the battle at a poll. +enum class BattleSeen{ + NONE, + BATTLE, // as battle_shows() reads it + MENU, // the battle menu +}; + +// When the battle loop presses START to see whether the overworld is +// back, and when it gives up pressing A and B for a screen nothing reads. +// The battle counts as on screen by its menu, an HP box or a YES/NO only: +// its text box alone also reads on the black below a dark cave's corridor +// (console B, 2026-11-03, Mt. Moon B2F: after "Got away safely!" the loop +// took the cave for the battle and pressed A and B for 9 minutes). +class BattleEndWatch{ +public: + // What the loop read at `now`. + void seen(BattleSeen what, WallClock now); + // Whether to press START at `now`: a battle was seen, and none since + // for BATTLE_GONE. At most every OVERWORLD_CHECK. + bool check_overworld(WallClock now); + // A or B was pressed blind at `now`. True once that has gone on for + // BLIND_PRESSES with no battle menu: the loop stops, and the walker, + // which finds the player again, goes on. + bool pressed_blind(WallClock now); + +private: + std::optional m_last_battle; + std::optional m_last_check; + std::optional m_blind_since; +}; + + +// Whether the game turned down the move chosen, at the battle menu after +// it: the move list came back (no battle screen reads on it) and the menu +// followed sooner than any turn (console B, 2026-11-03: 5.7 s from the +// choice for a disabled move, 8.3 s and up for a turn). +class MoveRefusalWatch{ +public: + void move_chosen(WallClock now); + // No battle screen read while the battle goes on. + void no_battle_screen(); + // At the battle menu: true if the move chosen before it was turned down. + bool refused(WallClock now); + +private: + std::optional m_chosen; + bool m_list_back = false; +}; + + +void add_tests_AutoStoryParty(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp new file mode 100644 index 0000000000..23e7f10f78 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp @@ -0,0 +1,576 @@ +/* AutoStory Battle Sim + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "PokemonFRLG_AutoStoryBattleSim.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +constexpr int START_SCORE = 100; +constexpr int BAD_MOVE = 10; +constexpr int CAN_FAINT = 4; +constexpr int QUICK_FAINT = 2; +constexpr int NOT_STRONGEST = 1; +constexpr int MAX_STAGE = 6; +// More turns than this to faint a foe counts as never. +constexpr size_t TURNS_CAP = 30; +// The hits a multi-hit move is taken to land when sizing a foe's hit. +constexpr uint32_t MULTI_HITS = 3; + +const MoveData& data_of(std::string_view move){ + static const MoveData NONE; + const MoveData* data = move_data(move); + return data == nullptr ? NONE : *data; +} + +size_t effectiveness(PokemonType type, const Combatant& target){ + size_t tenths = 10; + for (size_t multiplier : type_multipliers(type, target.first, target.second)){ + tenths = tenths * multiplier / 10; + } + return tenths; +} + +bool has_type(const Combatant& combatant, PokemonType type){ + return combatant.first == type || combatant.second == type; +} + +uint32_t hits_of(const MoveData& move){ + if (move.effect == "multi-hit"){ + return MULTI_HITS; + } + return move.effect == "double-hit" || move.effect == "twineedle" ? 2 : 1; +} + +uint32_t speed_of(const SimBattler& battler){ + const uint32_t speed = staged_stat(battler.body.stats.speed, battler.body.stages[static_cast(Stage::SPEED)]); + return battler.status == SimStatus::PARALYSIS ? speed / 4 : speed; +} + +bool status_effect(std::string_view effect){ + return effect == "sleep" || effect == "poison" || effect == "toxic" || effect == "paralyze"; +} + +// A stat-stage effect ("attack-down", "defense-up-2") at its limit. +bool stage_at_limit(std::string_view effect, const SimBattler& user, const SimBattler& target){ + static const std::pair STATS[] = { + {"attack-", Stage::ATTACK}, {"defense-", Stage::DEFENSE}, {"speed-", Stage::SPEED}, + {"special-attack-", Stage::SP_ATTACK}, {"special-defense-", Stage::SP_DEFENSE}, + {"accuracy-", Stage::ACCURACY}, {"evasion-", Stage::EVASION}, + }; + for (const auto& [prefix, stage] : STATS){ + if (!effect.starts_with(prefix) || effect.ends_with("-hit")){ + continue; + } + const bool up = effect.substr(prefix.size()).starts_with("up"); + const int now = (up ? user : target).body.stages[static_cast(stage)]; + return up ? now >= MAX_STAGE : now <= -MAX_STAGE; + } + return false; +} + +// AI_CheckBadMove, as the top of the header says. +bool bad_move(const MoveData& move, const SimBattler& user, const SimBattler& target){ + if (move.power > 0 && effectiveness(move.type, target.body) == 0){ + return true; + } + if (status_effect(move.effect) && target.status != SimStatus::NONE){ + return true; + } + if ((move.effect == "poison" || move.effect == "toxic") + && (has_type(target.body, PokemonType::POISON) || has_type(target.body, PokemonType::STEEL)) + ){ + return true; + } + if (move.effect == "leech-seed" && (target.seeded || has_type(target.body, PokemonType::GRASS))){ + return true; + } + if ((move.effect == "restore-hp" || move.effect == "softboiled") && user.hp >= user.body.stats.hp){ + return true; + } + return stage_at_limit(move.effect, user, target); +} + +void add_try_to_faint(std::vector& scores, const SimBattler& foe, const SimBattler& target){ + std::vector damage(foe.moves.size(), 0); + double strongest = 0; + for (size_t slot = 0; slot < foe.moves.size(); slot++){ + const MoveData& move = data_of(foe.moves[slot].move); + if (move.power > 0 && foe.moves[slot].pp > 0){ + damage[slot] = average_damage(foe.body, target.body, move) * hits_of(move); + strongest = move.power > 1 ? std::max(strongest, damage[slot]) : strongest; + } + } + for (size_t slot = 0; slot < foe.moves.size(); slot++){ + const MoveData& move = data_of(foe.moves[slot].move); + if (scores[slot] <= 0 || move.power == 0){ + continue; + } + if (damage[slot] >= target.hp){ + scores[slot] += CAN_FAINT + (move.effect == "quick-attack" ? QUICK_FAINT : 0); + }else if (move.power > 1 && damage[slot] < strongest){ + scores[slot] -= NOT_STRONGEST; + } + } +} + +// CHECK_VIABILITY's terms: HP in percent, a stage as the game's level (6 +// for none), the speed comparison, and if_random_less_than (n / 256). +int hp_percent(const SimBattler& battler){ + return battler.hp * 100 / std::max(battler.body.stats.hp, 1); +} +int level(const SimBattler& battler, Stage stage){ + return battler.body.stages[static_cast(stage)] + MAX_STAGE; +} +bool faster(const SimBattler& a, const SimBattler& b){ + return speed_of(a) > speed_of(b); +} +bool random_below(std::mt19937& rng, uint32_t n){ + return rng() % 256 < n; +} + +bool physical_type(PokemonType type){ + switch (type){ + case PokemonType::NORMAL: + case PokemonType::FIGHTING: + case PokemonType::GROUND: + case PokemonType::ROCK: + case PokemonType::BUG: + case PokemonType::STEEL: + return true; + default: + return false; + } +} + +int cv_attack_down(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ + int score = 0; + if (level(target, Stage::ATTACK) != MAX_STAGE){ + score -= user.hp * 100 > 90 * user.body.stats.hp ? 1 : 2; + score -= level(target, Stage::ATTACK) > 3 || random_below(rng, 50) ? 0 : 2; + } + score -= hp_percent(target) > 70 ? 0 : 2; + const bool physical = physical_type(target.body.first) || physical_type(target.body.second); + return score - (physical || random_below(rng, 50) ? 0 : 2); +} + +int cv_defense_down(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ + int score = 0; + if (hp_percent(user) < 70 || level(target, Stage::DEFENSE) <= 3){ + score -= random_below(rng, 50) ? 0 : 2; + } + return score - (hp_percent(target) > 70 ? 0 : 2); +} + +int cv_accuracy_down(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ + int score = 0; + if (hp_percent(user) < 70 || hp_percent(target) <= 70){ + score -= random_below(rng, 100) ? 0 : 1; + } + score -= level(user, Stage::ACCURACY) > 4 || random_below(rng, 80) ? 0 : 2; + score += target.seeded && !random_below(rng, 70) ? 2 : 0; + if (hp_percent(user) > 70 || level(target, Stage::ACCURACY) == MAX_STAGE){ + return score; + } + const bool low = hp_percent(user) < 40 || hp_percent(target) < 40; + return score - (low || !random_below(rng, 70) ? 2 : 0); +} + +int cv_toxic(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ + int score = 0; + score -= hp_percent(user) > 50 || random_below(rng, 50) ? 0 : 3; + return score - (hp_percent(target) > 50 || random_below(rng, 50) ? 0 : 3); +} + +int cv_heal(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ + if (hp_percent(user) == 100){ + return -3; + } + if (!faster(target, user)){ + return -8; + } + if (hp_percent(user) >= 70 && !random_below(rng, 30)){ + return -3; + } + return random_below(rng, 20) ? 0 : 2; +} + +// CHECK_VIABILITY for the status moves (see the header). +int viability(const MoveData& move, const SimBattler& user, const SimBattler& target, std::mt19937& rng){ + const std::string_view effect = move.effect; + if (effect == "attack-down"){ + return cv_attack_down(user, target, rng); + } + if (effect == "defense-down"){ + return cv_defense_down(user, target, rng); + } + if (effect == "accuracy-down"){ + return cv_accuracy_down(user, target, rng); + } + if (effect == "speed-down"){ + return faster(target, user) ? (random_below(rng, 70) ? 0 : 2) : -3; + } + if (effect == "poison"){ + return hp_percent(user) < 50 || hp_percent(target) <= 50 ? -1 : 0; + } + if (effect == "toxic" || effect == "leech-seed"){ + return cv_toxic(user, target, rng); + } + if (effect == "paralyze"){ + return faster(target, user) ? (random_below(rng, 20) ? 0 : 3) : (hp_percent(user) > 70 ? 0 : -1); + } + if (effect == "restore-hp" || effect == "softboiled"){ + return cv_heal(user, target, rng); + } + return 0; +} + +bool has_super_effective(const SimBattler& foe, const SimBattler& lead){ + return std::ranges::any_of(foe.moves, [&lead](const SimMove& known){ + const MoveData& move = data_of(known.move); + return move.power > 0 && effectiveness(move.type, lead.body) > 10; + }); +} + +// GetMostSuitableMonToSwitchInto's first pass: the lead's two types +// (the same one twice for a single type) against each, the best +// that has a super effective move. +std::optional suitable_by_type(const std::vector& left, const std::vector& party, const SimBattler& lead){ + std::set invalid; + while (invalid.size() < left.size()){ + std::optional best; + size_t best_tenths = 0; + for (size_t slot : left){ + const size_t tenths = invalid.contains(slot) ? 0 + : effectiveness(lead.body.first, party[slot].body) * effectiveness(lead.body.second, party[slot].body) / 10; + if (!invalid.contains(slot) && tenths > best_tenths){ + best = slot; + best_tenths = tenths; + } + } + if (!best){ + return std::nullopt; + } + if (has_super_effective(party[*best], lead)){ + return best; + } + invalid.insert(*best); + } + return std::nullopt; +} + +// Its second pass: the strongest move, compared as the game's u8 does. +std::optional suitable_by_damage(const std::vector& left, const std::vector& party, const SimBattler& fainted, const SimBattler& lead){ + std::optional best; + uint8_t best_damage = 0; + for (size_t slot : left){ + for (const SimMove& known : party[slot].moves){ + const MoveData& move = data_of(known.move); + const uint32_t damage = move.power > 1 ? damage_before_roll(fainted.body, lead.body, move, false) : 0; + if (best_damage < damage){ + best_damage = static_cast(damage); + best = slot; + } + } + } + return best; +} + +uint32_t lowest_roll(const SimBattler& own, const SimBattler& foe, const MoveData& move){ + return damage_range(own.body, foe.body, move, false).min * hits_of(move); +} + +double mean_per_turn(const SimBattler& own, const SimBattler& foe, const MoveData& move){ + const double accuracy = move.accuracy == 0 ? 1.0 : move.accuracy / 100.0; + return average_damage(own.body, foe.body, move) * hits_of(move) * accuracy; +} + +// Turns to faint `foe` with `per_turn` a turn, the AI healing it as +// ai_item_choice() says. +size_t turns_to_faint(SimBattler foe, std::vector items, size_t foes_left, double per_turn){ + double hp = foe.hp; + for (size_t turn = 1; turn <= TURNS_CAP; turn++){ + foe.hp = static_cast(std::max(0.0, std::ceil(hp))); + if (const std::optional item = ai_item_choice(foe, items, foes_left)){ + hp = std::min(foe.body.stats.hp, hp + ai_item_hp(items[*item])); + items[*item].clear(); + } + hp -= per_turn; + if (hp <= 0){ + return turn; + } + } + return TURNS_CAP + 1; +} + +// The slots with PP left that do damage to `foe`. +std::vector damaging_slots(const SimBattler& own, const SimBattler& foe){ + std::vector slots; + for (size_t slot = 0; slot < own.moves.size(); slot++){ + const MoveData& move = data_of(own.moves[slot].move); + if (own.moves[slot].pp > 0 && damage_before_roll(own.body, foe.body, move, false) > 0){ + slots.push_back(slot); + } + } + return slots; +} + +} + + +std::optional own_battler(const PartyMember& lead, double hp_share, const Genes& genes){ + std::optional body = combatant(lead.species, battle_level(lead), genes); + if (!body){ + return std::nullopt; + } + if (lead.stats && lead.level > 0){ + // The stats read, and what the levels since add with `genes`. + const Stats then = combatant(lead.species, lead.level, genes)->stats; + const Stats now = body->stats; + const auto grown = [](uint16_t read, uint16_t before, uint16_t after){ + return static_cast(read + after - before); + }; + body->stats = Stats{ + .hp = grown(lead.stats->hp, then.hp, now.hp), + .attack = grown(lead.stats->attack, then.attack, now.attack), + .defense = grown(lead.stats->defense, then.defense, now.defense), + .sp_attack = grown(lead.stats->sp_attack, then.sp_attack, now.sp_attack), + .sp_defense = grown(lead.stats->sp_defense, then.sp_defense, now.sp_defense), + .speed = grown(lead.stats->speed, then.speed, now.speed), + }; + } + SimBattler battler{.species = lead.species, .body = *body, .hp = 0, .moves = {}}; + battler.hp = static_cast(std::clamp(std::round(body->stats.hp * hp_share), 1, body->stats.hp)); + for (const KnownMove& known : lead.moves){ + battler.moves.push_back(SimMove{.move = known.move, .pp = known.pp}); + } + return battler; +} + +std::optional trainer_battler(const TrainerMon& mon){ + std::optional body = combatant(mon.species, mon.level, Genes{.iv = trainer_iv(mon.iv), .ev = 0, .nature = mon.nature}); + if (!body){ + return std::nullopt; + } + SimBattler battler{.species = mon.species, .body = *body, .hp = body->stats.hp, .moves = {}}; + for (const std::string& move : mon.moves){ + battler.moves.push_back(SimMove{.move = move, .pp = data_of(move).pp}); + } + return battler; +} + +std::optional sim_trainer(std::string_view trainer){ + const std::optional data = trainer_data(trainer); + if (!data || data->party.empty()){ + return std::nullopt; + } + SimTrainer sim{ + .party = {}, .items = data->items, + .check_bad_move = std::ranges::find(data->ai, "check-bad-move") != data->ai.end(), + .try_to_faint = std::ranges::find(data->ai, "try-to-faint") != data->ai.end(), + .check_viability = std::ranges::find(data->ai, "check-viability") != data->ai.end(), + }; + for (const TrainerMon& mon : data->party){ + std::optional battler = trainer_battler(mon); + if (!battler){ + return std::nullopt; + } + sim.party.push_back(std::move(*battler)); + } + return sim; +} + +uint16_t ai_item_hp(std::string_view item){ + static const std::pair HEALS[] = { + {"potion", 20}, {"super-potion", 50}, {"hyper-potion", 200}, {"max-potion", 255}, {"full-restore", 255}, + }; + for (const auto& [name, hp] : HEALS){ + if (name == item){ + return hp; + } + } + return 0; +} + +std::optional ai_item_choice(const SimBattler& foe, const std::vector& items, size_t foes_left){ + const uint16_t max_hp = foe.body.stats.hp; + for (size_t i = 0; i < items.size(); i++){ + if (i > 0 && foes_left > items.size() - i + 1){ + continue; + } + const uint16_t heal = ai_item_hp(items[i]); + if (heal == 0 || foe.hp == 0){ + continue; + } + const bool low = foe.hp < max_hp / 4; + if (low || (items[i] != "full-restore" && max_hp - foe.hp > heal)){ + return i; + } + } + return std::nullopt; +} + +std::vector ai_move_scores(const SimTrainer& trainer, const SimBattler& foe, const SimBattler& target, std::mt19937& rng){ + std::vector scores; + for (const SimMove& known : foe.moves){ + const MoveData& move = data_of(known.move); + const bool bad = trainer.check_bad_move && bad_move(move, foe, target); + const int viable = trainer.check_viability ? viability(move, foe, target, rng) : 0; + scores.push_back(known.pp == 0 ? 0 : START_SCORE - (bad ? BAD_MOVE : 0) + viable); + } + if (trainer.try_to_faint){ + add_try_to_faint(scores, foe, target); + } + return scores; +} + +size_t ai_next_foe(const std::vector& party, size_t fainted, const SimBattler& lead){ + std::vector left; + for (size_t slot = 0; slot < party.size(); slot++){ + if (slot != fainted && party[slot].hp > 0){ + left.push_back(slot); + } + } + if (left.empty()){ + return fainted; + } + if (const std::optional slot = suitable_by_type(left, party, lead)){ + return *slot; + } + if (const std::optional slot = suitable_by_damage(left, party, party[fainted], lead)){ + return *slot; + } + return left.front(); +} + +std::optional best_damage_slot(const SimBattler& own, const SimBattler& foe){ + std::optional best; + double best_damage = 0; + for (size_t slot : damaging_slots(own, foe)){ + const double damage = mean_per_turn(own, foe, data_of(own.moves[slot].move)); + if (damage > best_damage){ + best = slot; + best_damage = damage; + } + } + return best; +} + +std::optional planned_attack_slot( + const SimBattler& own, const SimBattler& foe, + const std::vector& items, size_t foes_left +){ + using Rank = std::tuple; + std::optional best; + Rank best_rank{}; + for (size_t slot : damaging_slots(own, foe)){ + const MoveData& move = data_of(own.moves[slot].move); + const bool faints = lowest_roll(own, foe, move) >= foe.hp; + const int sure = move.accuracy == 0 ? 100 : move.accuracy; + // Fewest turns, then surest, then weakest, then most PP left. + const size_t turns = faints ? 1 : turns_to_faint(foe, items, foes_left, mean_per_turn(own, foe, move)); + const Rank rank{turns, -(faints ? sure : 0), move.power, -own.moves[slot].pp}; + if (!best || rank < best_rank){ + best = slot; + best_rank = rank; + } + } + return best; +} + +uint32_t foe_max_hit(const SimBattler& foe, const SimBattler& own){ + uint32_t most = 0; + for (const SimMove& known : foe.moves){ + const MoveData& move = data_of(known.move); + if (known.pp > 0){ + most = std::max(most, damage_range(foe.body, own.body, move, false).max * hits_of(move)); + } + } + return most; +} + +PotionCase potion_case(const SimBattler& own, const SimBattler& foe, double seen_hit){ + double expected = 0; + for (const SimMove& known : foe.moves){ + if (known.pp > 0){ + expected = std::max(expected, mean_per_turn(foe, own, data_of(known.move))); + } + } + const std::optional slot = planned_attack_slot(own, foe, {}, 1); + const size_t turns = slot + ? turns_to_faint(foe, {}, 1, mean_per_turn(own, foe, data_of(own.moves[*slot].move))) + : TURNS_CAP + 1; + // A faster foe hits before each of the lead's attacks, a slower one + // only between them. + const size_t hits = speed_of(foe) >= speed_of(own) ? turns : turns - 1; + return PotionCase{ + .hp = own.hp, + .max_hp = own.body.stats.hp, + .expected_hit = std::max(expected, seen_hit), + .max_hit = std::max(foe_max_hit(foe, own), static_cast(std::ceil(seen_hit))), + .hits_to_ko = hits, + }; +} + +bool potion_pays(const PotionCase& c){ + const uint16_t heal = static_cast(std::min(POTION_HP, c.max_hp - c.hp)); + if (heal == 0){ + return false; + } + const double healed = c.hp + heal; + if (heal > c.expected_hit && healed > c.expected_hit){ + return true; + } + const bool lasts_if_healed = healed > c.expected_hit * static_cast(c.hits_to_ko + 1); + const bool lasts_now = c.hp > c.expected_hit * static_cast(c.hits_to_ko); + return lasts_if_healed && !lasts_now; +} + +bool potion_now(const SimBattler& own, const SimBattler& foe, int potions, double seen_hit){ + const uint16_t max_hp = own.body.stats.hp; + if (potions <= 0 || own.hp >= max_hp){ + return false; + } + const PotionCase c = potion_case(own, foe, seen_hit); + const uint32_t healed = std::min(max_hp, own.hp + POTION_HP); + return c.max_hit >= own.hp && healed > c.max_hit && potion_pays(c); +} + +OwnTurn own_turn( + const SimBattler& own, int potions, const SimBattler& foe, + const std::vector& items, size_t foes_left +){ + const std::optional slot = planned_attack_slot(own, foe, items, foes_left); + if (slot){ + const MoveData& move = data_of(own.moves[*slot].move); + const bool foe_priority = std::ranges::any_of(foe.moves, [](const SimMove& known){ + return known.pp > 0 && data_of(known.move).priority > 0; + }); + const bool first = speed_of(own) > speed_of(foe) && !foe_priority && move.priority >= 0; + const bool sure = move.accuracy == 0 || move.accuracy >= 100; + if (first && sure && lowest_roll(own, foe, move) >= foe.hp && !ai_item_choice(foe, items, foes_left)){ + return OwnTurn{.potion = false, .slot = slot}; + } + } + if (potion_now(own, foe, potions)){ + return OwnTurn{.potion = true, .slot = std::nullopt}; + } + return OwnTurn{.potion = false, .slot = slot}; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h new file mode 100644 index 0000000000..d5e142d2b7 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h @@ -0,0 +1,199 @@ +/* AutoStory Battle Sim + * + * From: https://github.com/PokemonAutomation/ + * + * The story's lead against a trainer's party as Gen 3 FireRed plays it, + * for the battles fought at BattleRisk::HIGH: the Pokemon on each side, + * the trainer AI's choices (its items, its moves, its next Pokemon) and + * the lead's (its move, a Potion). PokemonFRLG_AutoStoryWinChance.h plays + * whole battles from these. + * + * The trainer's side is pret's: party, levels, IVs, natures, moves, items + * and AI flags (trainers.json). The lead is what its summary showed + * when the run started (species, level, moves and PP, stats from POKEMON + * SKILLS), with the levels since (battle_level()) added at OWN_GENES; + * without a summary, its species and battle_level() at OWN_GENES. + * + * Approximations, from pret/pokefirered: + * - The AI's move (battle_ai_script_commands.c, data/battle_ai_scripts.s): + * every move starts at 100; CHECK_BAD_MOVE takes 10 off a move the + * target is immune to, a status the target already has, Leech Seed on + * a seeded or Grass target, and a stat change past +-6; TRY_TO_FAINT + * adds 4 to a move that faints the target at the mean roll (6 for Quick + * Attack) and takes 1 off the damaging moves that aren't its strongest; + * CHECK_VIABILITY scores the status moves the early trainers carry + * (AI_CV_AttackDown, DefenseDown, AccuracyDown, SpeedDown, Poison, + * Toxic for Leech Seed too, Paralyze, Heal) by HP, speed and stages, + * with their random parts. The best score wins, ties at random. The + * other scripts, and CHECK_VIABILITY on damaging moves, are left out. + * - The AI's items (battle_ai_switch_items.c ShouldUseItem) as the game + * has them for the HP items: Full Restore below 1/4 HP, the others + * below 1/4 or when more HP is missing than the item heals; each item + * once, and item i > 0 only once at most itemsNo - i + 1 Pokemon are + * left. Other items are not used. + * - The AI's next Pokemon (GetMostSuitableMonToSwitchInto): the one the + * lead's types hit hardest that has a super effective move against the + * lead, else the one whose strongest move does the lead most damage, + * else the first left. + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattleSim_H +#define PokemonAutomation_PokemonFRLG_AutoStoryBattleSim_H + +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_AutoStoryBattleData.h" +#include "PokemonFRLG_AutoStoryDamage.h" +#include "PokemonFRLG_AutoStoryParty.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The lead's IVs and EVs, which the story doesn't read: middling IVs, no +// EVs, a neutral nature (Hardy). +inline constexpr Genes OWN_GENES{.iv = 15, .ev = 0, .nature = 0}; + +// HP a Potion heals. +inline constexpr uint16_t POTION_HP = 20; + +enum class SimStatus{ + NONE, + SLEEP, + POISON, // and Toxic, as plain poison + PARALYSIS, +}; + +struct SimMove{ + std::string move = {}; + uint8_t pp = 0; +}; + +// A Pokemon in the sim. +struct SimBattler{ + std::string species = {}; + Combatant body = {}; + uint16_t hp = 0; + // In the move list's slot order. + std::vector moves = {}; + SimStatus status = SimStatus::NONE; + // SLEEP: the game's counter (2 to 5): each turn takes one off, and it + // moves on the turn it reaches 0. + uint8_t sleep = 0; + bool seeded = false; +}; + +// The lead with `hp_share` of its HP (1 for full), its moves and PP as +// the story counts them, at battle_level(): its stats as read +// (PartyMember::stats) plus what the levels since add with `genes`, else +// from `genes`. None for a species the data doesn't have. +std::optional own_battler(const PartyMember& lead, double hp_share = 1.0, const Genes& genes = OWN_GENES); + +// A trainer's Pokemon at full HP and PP. +std::optional trainer_battler(const TrainerMon& mon); + +struct SimTrainer{ + std::vector party = {}; + // Each used once; a used one becomes "". + std::vector items = {}; + bool check_bad_move = false; + bool try_to_faint = false; + bool check_viability = false; +}; +// None for a trainer the data doesn't have (or a species in its party). +std::optional sim_trainer(std::string_view trainer); + + +// The HP the AI's `item` heals (255 for all of it), 0 for one that +// doesn't heal. +uint16_t ai_item_hp(std::string_view item); + +// The item the AI uses on `foe` this turn (its index in `items`), with +// `foes_left` Pokemon on its side not fainted, none for its move. +std::optional ai_item_choice(const SimBattler& foe, const std::vector& items, size_t foes_left); + +// The scores the AI gives `foe`'s moves against `target` (see the top); +// 0 for a move with no PP. In slot order. `rng` for CHECK_VIABILITY's +// random parts. +std::vector ai_move_scores(const SimTrainer& trainer, const SimBattler& foe, const SimBattler& target, std::mt19937& rng); + +// The party slot the AI sends out after `fainted`, of the ones still up. +size_t ai_next_foe(const std::vector& party, size_t fainted, const SimBattler& lead); + + +// BattleRisk::LOW: the slot with PP left whose mean damage against `foe` +// is highest. None if no move does damage. +std::optional best_damage_slot(const SimBattler& own, const SimBattler& foe); + +// BattleRisk::HIGH: a move that faints `foe` at the lowest roll, the +// weakest of them to keep the strong moves' PP; else the one that faints +// it in the fewest turns at the mean roll and accuracy, counting the +// heals the AI would use on it from `items` (ai_item_choice()), ties to +// the weaker move. None if no move does damage. +std::optional planned_attack_slot( + const SimBattler& own, const SimBattler& foe, + const std::vector& items, size_t foes_left +); + +// The most `foe` can do to `own` with one move, no crit, highest roll. +uint32_t foe_max_hit(const SimBattler& foe, const SimBattler& own); + +// What a Potion now is weighed on. +struct PotionCase{ + uint16_t hp = 0; + uint16_t max_hp = 0; + // The foe's next hit, on average and at most. + double expected_hit = 0; + uint32_t max_hit = 0; + // The foe's hits the lead takes before its attacks faint the foe, if + // it attacks from now on. + size_t hits_to_ko = 0; +}; +// `own` against `foe`: the foe's strongest move at the mean roll and +// accuracy, or `seen_hit` (HP the last hit took, as the battle loop read +// it) if more; the lead's planned move against the foe at its HP now. +PotionCase potion_case(const SimBattler& own, const SimBattler& foe, double seen_hit = 0); + +// At either BattleRisk: a Potion is worth the turn only if, after it and +// the foe's expected hit, the lead has gained HP, or if it lets the lead +// last until its attacks faint the foe when attacking now wouldn't. +// Otherwise it attacks: a Potion the next hit undoes only gives the foe +// another turn (console B, 2026-11-03, m51: five Potions at 8/60 HP each +// undone by Misty's Starmie, then no Potions and a faint). +bool potion_pays(const PotionCase& c); + +// BattleRisk::HIGH: a Potion now: `foe`'s next hit could faint `own`, +// after the Potion it couldn't, and potion_pays(). +bool potion_now(const SimBattler& own, const SimBattler& foe, int potions, double seen_hit = 0); + +// The lead's turn at BattleRisk::HIGH. +struct OwnTurn{ + bool potion = false; + // Not a Potion: the move's slot, none if no move does damage. + std::optional slot = std::nullopt; +}; +// planned_attack_slot()'s move when it surely faints `foe` first (the +// lead is faster, the lowest roll faints it, it never misses and the AI +// won't heal first), else a Potion if potion_now(), else that move. +OwnTurn own_turn( + const SimBattler& own, int potions, const SimBattler& foe, + const std::vector& items, size_t foes_left +); + + +// The damage calculator, the sim's choices and its win chance. +void add_tests_AutoStoryBattleSim(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp new file mode 100644 index 0000000000..375d088738 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp @@ -0,0 +1,456 @@ +/* AutoStory Battle Sim Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The Gen 3 damage calculator against numbers worked by hand and the + * Elite Four Farmer's Starmie table, the move chosen against the foe out, + * the trainer AI's items and next Pokemon, and the win chance before the + * Cerulean rival. + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryBattleDecisions.h" +#include "PokemonFRLG_AutoStoryBattleSim.h" +#include "PokemonFRLG_AutoStoryFoeTracker.h" +#include "PokemonFRLG_AutoStoryWinChance.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +class Test_AutoStoryBattleSim : public UnitTest{ +public: + Test_AutoStoryBattleSim(std::string name, std::function body) + : UnitTest("PokemonFRLG::AutoStoryBattleSim - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + +constexpr std::string_view RIVAL = "TRAINER_RIVAL_CERULEAN_BULBASAUR"; +constexpr std::string_view MISTY = "TRAINER_LEADER_MISTY"; + +std::string stats_text(const Stats& s){ + return std::format("{}/{}/{}/{}/{}/{}", s.hp, s.attack, s.defense, s.sp_attack, s.sp_defense, s.speed); +} + +std::string range_text(const DamageRange& r){ + return std::format("{}-{}", r.min, r.max); +} + +// The story's Wartortle at Lv22, OWN_GENES. +Combatant wartortle22(){ + return *combatant("wartortle", 22, OWN_GENES); +} + +// The rival's Bulbasaur: Lv18, pret iv 100 (IVs 12), Hardy. +Combatant rival_bulbasaur(){ + return *combatant("bulbasaur", 18, Genes{.iv = trainer_iv(100), .ev = 0, .nature = 0}); +} + + +// Worked by hand from CalculateMonStats and CalculateBaseDamage: +// Wartortle Lv22 IV15: HP (2*59+15)*22/100+32 = 61, Attack 141*22/100+5 = 36, +// ... Bite on the Bulbasaur (Sp. Def 142*18/100+5 = 30): 36*60*10/30/50+2 +// = 16, no STAB, neutral: 13 to 16; a crit doubles the 16 before the +// roll: 27 to 32. Water Gun: 36*40*10/30/50+2 = 11, STAB 16, Grass 0.5x +// 8: 6 to 8. Its Vine Whip back: 30*35*9/43/50+2 = 6, STAB 9, Water 2x +// 18: 15 to 18. +UnitTestResult test_hand_numbers(){ + const Combatant own = wartortle22(); + const Combatant foe = rival_bulbasaur(); + if (stats_text(own.stats) != "61/36/43/36/43/33" || stats_text(foe.stats) != "46/24/24/30/30/23"){ + return "Stats: expected 61/36/43/36/43/33 and 46/24/24/30/30/23, got " + stats_text(own.stats) + " and " + stats_text(foe.stats) + "."; + } + const std::vector> cases = { + {"Bite", damage_range(own, foe, *move_data("bite"), false), "13-16"}, + {"Bite, crit", damage_range(own, foe, *move_data("bite"), true), "27-32"}, + {"Water Gun", damage_range(own, foe, *move_data("water-gun"), false), "6-8"}, + {"Vine Whip", damage_range(foe, own, *move_data("vine-whip"), false), "15-18"}, + {"Dragon Rage", damage_range(own, foe, *move_data("dragon-rage"), false), "40-40"}, + }; + for (const auto& [name, range, expected] : cases){ + if (range_text(range) != expected){ + return std::format("{}: expected {}, got {}.", name, expected, range_text(range)); + } + } + // Tail Whip's -1: Defense 24 * 10 / 15 = 16; Tackle 36*35*10/16/50+2 = 17. + Combatant whipped = foe; + whipped.stages[static_cast(Stage::DEFENSE)] = -1; + const DamageRange tackle = damage_range(own, whipped, *move_data("tackle"), false); + if (range_text(tackle) != "14-17"){ + return "Tackle after Tail Whip: expected 14-17, got " + range_text(tackle) + "."; + } + return true; +} + + +// The Elite Four Farmer's STARMIE_PLAN (PokemonFRLG_EliteFourFarmer.cpp): +// each pick "one-hit KOs each rematch opponent (min damage roll, no crit)" +// at Sp. Atk 302, Lv100. Every rematch party's Pokemon of that species. +const std::map& starmie_plan(){ + static const std::map PLAN = { + {"dewgong", "thunderbolt"}, {"cloyster", "thunderbolt"}, {"piloswine", "surf"}, + {"jynx", "surf"}, {"lapras", "thunderbolt"}, {"steelix", "surf"}, + {"hitmonchan", "psychic"}, {"hitmonlee", "psychic"}, {"machamp", "psychic"}, + {"gengar", "psychic"}, {"crobat", "thunderbolt"}, {"misdreavus", "surf"}, + {"arbok", "psychic"}, {"gyarados", "thunderbolt"}, {"dragonite", "ice-beam"}, + {"kingdra", "psychic"}, {"aerodactyl", "surf"}, {"heracross", "psychic"}, + {"alakazam", "surf"}, {"tyranitar", "surf"}, {"arcanine", "surf"}, + {"exeggutor", "ice-beam"}, {"blastoise", "thunderbolt"}, {"venusaur", "psychic"}, + {"charizard", "thunderbolt"}, + }; + return PLAN; +} + +Combatant starmie(uint16_t sp_attack){ + Combatant body = *combatant("starmie", 100, OWN_GENES); + body.stats.sp_attack = sp_attack; + body.volcano_badge = true; + return body; +} + +// The species whose pick misses the OHKO at `sp_attack`; "" for none. +std::string first_miss(uint16_t sp_attack, std::string_view only = ""){ + for (std::string_view trainer : { + "TRAINER_ELITE_FOUR_LORELEI_2", "TRAINER_ELITE_FOUR_BRUNO_2", "TRAINER_ELITE_FOUR_AGATHA_2", "TRAINER_ELITE_FOUR_LANCE_2", + "TRAINER_CHAMPION_REMATCH_SQUIRTLE", "TRAINER_CHAMPION_REMATCH_BULBASAUR", "TRAINER_CHAMPION_REMATCH_CHARMANDER", + }){ + for (const TrainerMon& mon : trainer_mons(trainer)){ + const auto pick = starmie_plan().find(mon.species); + if (pick == starmie_plan().end() || (!only.empty() && mon.species != only)){ + continue; + } + const Combatant foe = *combatant(mon.species, mon.level, Genes{.iv = trainer_iv(mon.iv), .ev = 0, .nature = mon.nature}); + const DamageRange range = damage_range(starmie(sp_attack), foe, *move_data(pick->second), false); + if (range.min < foe.stats.hp){ + return std::format("{} {} Lv{} ({} HP, {} {})", trainer, mon.species, mon.level, foe.stats.hp, pick->second, range_text(range)); + } + } + } + return ""; +} + +UnitTestResult test_elite_four_table(){ + const std::string miss = first_miss(302); + if (!miss.empty()){ + return "At Sp. Atk 302, no OHKO at the lowest roll: " + miss + "."; + } + if (first_miss(301, "kingdra").empty()){ + return "Expected Kingdra to set the 302 Sp. Atk requirement: Psychic OHKOs it at 301 too."; + } + return true; +} + + +// Misty's Staryu (Water) and Starmie (Water/Psychic): a lead with +// Thundershock and Bite thunders the Staryu (2x against 1x) and bites the +// Starmie (both 2x, Bite stronger). As the battle loop asks, with the +// foe out known; summing over the party picked one move for both. +UnitTestResult test_misty_per_foe(){ + const PartyMember lead = member_from_summary("wartortle", 22, { + {.move = "tackle", .pp = 35, .max_pp = 35}, {.move = "bite", .pp = 25, .max_pp = 25}, + {.move = "thunder-shock", .pp = 30, .max_pp = 30}, {.move = "withdraw", .pp = 40, .max_pp = 40}, + }); + for (const BattleRisk risk : {BattleRisk::LOW, BattleRisk::HIGH}){ + for (const auto& [out, expected] : {std::pair{0, 2}, {1, 1}}){ + Supplies supplies; + supplies.lead = lead; + supplies.potions = 0; + supplies.trainer = std::string(MISTY); + supplies.foes = trainer_party(MISTY); + supplies.risk = risk; + supplies.foe_out = out; + BattleDecisions decisions(supplies, BattleKind::TRAINER); + const PartyStatus green{.hp_seen = true, .hp_yellow = false, .hp_red = false, .hp_fill = 1, .status = StatusCondition::NONE}; + const size_t slot = decisions.turn(green).slot; + if (slot != expected){ + return std::format("Risk {}, foe {}: expected slot {}, got {}.", battle_risk_name(risk), out, expected, slot); + } + } + } + return true; +} + + +// ShouldUseItem for Misty's Super Potion on her Starmie (56 HP): below +// 1/4 (14) or more than 50 missing; a Full Restore only below 1/4. A +// second item waits until at most itemsNo - 1 + 1 Pokemon are left. +UnitTestResult test_ai_heal_rule(){ + SimBattler starmie = *trainer_battler(trainer_mons(MISTY)[1]); + if (starmie.body.stats.hp != 56){ + return std::format("Expected Misty's Starmie at 56 HP, got {}.", starmie.body.stats.hp); + } + const std::vector super = {"super-potion"}; + const std::vector, size_t, bool>> cases = { + {56, super, 1, false}, {20, super, 1, false}, {13, super, 1, true}, {5, super, 1, true}, + {20, {"full-restore"}, 1, false}, {13, {"full-restore"}, 1, true}, + {13, {"", "hyper-potion"}, 3, false}, {13, {"", "hyper-potion"}, 2, true}, + }; + for (const auto& [hp, items, left, uses] : cases){ + starmie.hp = hp; + if (ai_item_choice(starmie, items, left).has_value() != uses){ + return std::format("At {} HP with {} items, {} left: expected {}.", hp, items.size(), left, uses ? "an item" : "none"); + } + } + // Each item once: the heal it would use is gone after. + starmie.hp = 6; + std::vector once = super; + once[*ai_item_choice(starmie, once, 1)].clear(); + if (ai_item_choice(starmie, once, 1)){ + return "Expected the Super Potion used only once."; + } + return true; +} + + +// GetMostSuitableMonToSwitchInto against a Wartortle after the rival's +// Pidgeotto: Water hits Abra and Rattata 1x and Bulbasaur 0.25x, but +// only Bulbasaur has a move super effective on Water (Vine Whip): it +// comes next, not Abra. The tracker, with no name read, follows that. +UnitTestResult test_next_foe(){ + const PartyMember lead = grown_to(new_member("squirtle", 5), 22); + TrainerFoeTracker tracker(RIVAL, lead); + if (tracker.out() != 0){ + return "Expected the rival's Pidgeotto out first."; + } + for (int i = 0; i < 3; i++){ + tracker.boxes_seen(BattleBoxes{.lead = true, .foe = false}); + } + tracker.at_menu(""); + if (tracker.out() != 3){ + return std::format("Expected Bulbasaur (slot 3) after Pidgeotto, got {}.", tracker.out() ? std::to_string(*tracker.out()) : "none"); + } + tracker.at_menu("abra"); + if (tracker.out() != 1){ + return "Expected the name read (Abra) over the AI's choice."; + } + return true; +} + + +// The default risks: the rival and gym leaders HIGH, route trainers and +// grunts LOW. +UnitTestResult test_risks(){ + const std::vector> cases = { + {"CeruleanCity", "rival_cerulean", BattleRisk::HIGH}, + {"CeruleanCity_Gym", "misty", BattleRisk::HIGH}, + {"PewterCity_Gym", "brock", BattleRisk::HIGH}, + {"Route24", "lass_ali", BattleRisk::LOW}, + {"MtMoon_B2F", "rocket_grunt", BattleRisk::LOW}, + {"Route1", "nobody", BattleRisk::LOW}, + }; + for (const auto& [map, battle, risk] : cases){ + if (story_battle_risk(map, battle) != risk){ + return std::format("{} on {}: expected {}.", battle, map, battle_risk_name(risk)); + } + } + return true; +} + + +// The Cerulean rival (Pidgeotto, Abra, Rattata, then a Bulbasaur with +// Sleep Powder, Poison Powder and Leech Seed): the Lv22 Wartortle with 5 +// Potions that 00.15's GRIND plans for wins about a quarter of the sim's +// battles, and is refused with the reason; at Lv30 it wins over 90%. +UnitTestResult test_rival_win_chance(){ + const std::optional planned = story_win_chance(grown_to(new_member("squirtle", 5), 22), 5, 1.0, RIVAL); + const std::optional refusal = planned ? win_chance_refusal(*planned) : std::nullopt; + if (!planned || planned->chance < 0.15 || planned->chance > 0.40){ + return std::format("Lv22, 5 Potions: expected 15% to 40%, got {:.1f}%.", planned ? 100 * planned->chance : 0.0); + } + if (refusal != std::format("win chance {:.0f}% < 70% with {}: grind first", std::floor(100 * planned->chance), planned->inputs)){ + return "Lv22, 5 Potions: expected a refusal with the chance, got \"" + refusal.value_or("") + "\"."; + } + const std::optional ground = story_win_chance(grown_to(new_member("squirtle", 5), 30), 5, 1.0, RIVAL); + if (!ground || ground->chance < 0.90 || win_chance_refusal(*ground)){ + return std::format("Lv30, 5 Potions: expected over 90% and no refusal, got {:.1f}%.", ground ? 100 * ground->chance : 0.0); + } + return true; +} + + +// Console B, 2026-11-03 (run m51), Misty: the Wartortle's moves, Bite, +// Tail Whip, Bubble, Withdraw (Water Gun was lost earlier). +std::vector m51_moves(){ + return { + {.move = "bite", .pp = 25, .max_pp = 25}, {.move = "tail-whip", .pp = 30, .max_pp = 30}, + {.move = "bubble", .pp = 30, .max_pp = 30}, {.move = "withdraw", .pp = 40, .max_pp = 40}, + }; +} + +// m51's Wartortle as its summary would read: `level`, 60 HP at Lv20, +// the other stats at OWN_GENES. +PartyMember m51_lead(uint8_t level){ + Stats stats = combatant("wartortle", 20, OWN_GENES)->stats; + stats.hp = 60; + PartyMember lead = member_from_summary("wartortle", 20, m51_moves(), stats); + lead.moves_through_level = level; + return lead; +} + +// m51's Wartortle Lv20 at `hp` of 60. +SimBattler m51_wartortle(uint16_t hp){ + SimBattler own = *own_battler(m51_lead(20)); + own.hp = hp; + return own; +} + +// m51, turns 8 to 13: at 8/60 HP against Misty's Starmie, which hit +// about 20 a turn, the HIGH tier's Potion (+20) was undone by each hit, +// five times over; then Bite once with no Potions left, and it fainted. +// The loop replayed at either tier: once a Potion is seen undone by the +// next hit, no more, but Bite, which also flinches. +UnitTestResult test_m51_potion_loop(){ + for (const BattleRisk risk : {BattleRisk::LOW, BattleRisk::HIGH}){ + Supplies supplies; + supplies.lead = m51_lead(20); + supplies.potions = 5; + supplies.trainer = std::string(MISTY); + supplies.foes = trainer_party(MISTY); + supplies.risk = risk; + supplies.foe_out = 1; + BattleDecisions decisions(supplies, BattleKind::TRAINER); + const PartyStatus red{.hp_seen = true, .hp_yellow = false, .hp_red = true, .hp_fill = 8.0 / 60, .status = StatusCondition::NONE}; + int potions = 0; + for (int turn = 8; turn <= 13; turn++){ + const TurnAction action = decisions.turn(red); + if (action.choice == TurnChoice::POTION){ + potions++; + }else if (action.choice != TurnChoice::MOVE || action.slot != 0){ + return std::format("Risk {}, turn {}: expected a Potion or Bite (slot 0), got slot {}.", battle_risk_name(risk), turn, action.slot); + } + decisions.turn_done(action.choice, TurnResult::DONE); + } + if (potions > 1){ + return std::format("Risk {}: {} Potions at 8/60 HP over turns 8 to 13, each undone by the next hit; expected at most 1.", battle_risk_name(risk), potions); + } + } + return true; +} + +// The sim's own choice by the same rule: at 8/60 a Potion against a foe +// whose hit undoes it, no Potion; against one whose hit could faint the +// lead but heals less than 20, a Potion. +UnitTestResult test_sim_potion_rule(){ + const SimTrainer misty = *sim_trainer(MISTY); + SimBattler starmie = misty.party[1]; + const SimBattler own = m51_wartortle(8); + // Starmie as m51 saw it: at least the Potion's 20 a hit. + starmie.body.stats.attack = static_cast(starmie.body.stats.attack * 2); + starmie.body.stats.sp_attack = static_cast(starmie.body.stats.sp_attack * 2); + if (potion_case(own, starmie).expected_hit < POTION_HP){ + return std::format("Expected Starmie's mean hit at 20 or more, got {:.1f}.", potion_case(own, starmie).expected_hit); + } + const OwnTurn sim = own_turn(own, 5, starmie, misty.items, 1); + if (sim.potion || sim.slot != size_t(0)){ + return std::format( + "Sim at 8/60 against Starmie (max hit {}): expected Bite (slot 0), got {}.", + foe_max_hit(starmie, own), sim.potion ? "a Potion" : "slot " + std::to_string(sim.slot.value_or(9)) + ); + } + const SimBattler& staryu = misty.party[0]; + const SimBattler low = m51_wartortle(6); + const uint32_t hit = foe_max_hit(staryu, low); + if (hit < 6 || hit >= POTION_HP){ + return std::format("Expected Staryu's best hit on the Wartortle from 6 to 19, got {}.", hit); + } + if (!own_turn(low, 5, staryu, misty.items, 2).potion){ + return std::format("At 6/60 against Staryu (max hit {}): expected a Potion.", hit); + } + return true; +} + +// The sim plays the lead the summary showed, not the one the story +// counts: m51's Wartortle (Lv20, 60 HP, Bite, Tail Whip, Bubble, +// Withdraw) with 5 Potions wins about 96% against Misty; the story's own +// Wartortle Lv20 (Tackle, Bite, Water Gun, Withdraw; 56 HP at OWN_GENES) +// about 94%, from other inputs. m51 lost: the sim leaves out Water +// Pulse's confusion, among others (PokemonFRLG_AutoStoryWinChance.h). +UnitTestResult test_misty_real_lead(){ + const std::optional real = story_win_chance(m51_lead(20), 5, 1.0, MISTY); + const std::optional story = story_win_chance(grown_to(new_member("squirtle", 5), 20), 5, 1.0, MISTY); + if (!real || !story){ + return "Expected win chances for both leads."; + } + const std::string expected = "wartortle Lv20 60/60 HP: bite 25/25, tail-whip 30/30, bubble 30/30, withdraw 40/40; 5 Potions"; + if (real->inputs != expected){ + return "m51's lead: expected the inputs \"" + expected + "\", got \"" + real->inputs + "\"."; + } + if (real->chance < 0.90 || story->chance < 0.85 || real->chance == story->chance || story->inputs == real->inputs){ + return std::format( + "Expected m51's lead ({:.1f}%) and the story's ({:.1f}%, {}) to differ, both over 85%.", + 100 * real->chance, 100 * story->chance, story->inputs + ); + } + return true; +} + +// The Cerulean rival against m51's moves (no Water Gun), the levels +// since the summary added to its stats: refused at Lv20, 22 and 25 (about +// 32%, 37%, 66%), fought at Lv30 (about 95%). The refusal names the +// chance and the lead it was played with. +UnitTestResult test_rival_real_moves(){ + const std::vector> cases = { + {20, 0.20, 0.45}, {22, 0.25, 0.50}, {25, 0.50, 0.70}, {30, 0.90, 1.00}, + }; + for (const auto& [level, low, high] : cases){ + const std::optional estimate = story_win_chance(m51_lead(level), 5, 1.0, RIVAL); + if (!estimate || estimate->chance < low || estimate->chance >= high){ + return std::format("Lv{}: expected {:.0f}% to {:.0f}%, got {:.1f}%.", level, 100 * low, 100 * high, estimate ? 100 * estimate->chance : 0.0); + } + const bool refused = win_chance_refusal(*estimate).has_value(); + if (refused != (level < 30)){ + return std::format("Lv{} at {:.1f}%: expected {}.", level, 100 * estimate->chance, level < 30 ? "a refusal" : "no refusal"); + } + } + const std::optional lv22 = story_win_chance(m51_lead(22), 5, 1.0, RIVAL); + const std::string refusal = win_chance_refusal(*lv22).value_or(""); + if (refusal.find("wartortle Lv22 65/65 HP: bite") == std::string::npos || refusal.find("; 5 Potions") == std::string::npos){ + return "Lv22: expected the refusal to name the lead's level, HP, moves and Potions, got \"" + refusal + "\"."; + } + return true; +} +} + + +void add_tests_AutoStoryBattleSim(UnitTestDatabase& database){ + database.add("Gen 3 stats and damage worked by hand", test_hand_numbers); + database.add("the Elite Four Farmer's Starmie picks OHKO at Sp. Atk 302", test_elite_four_table); + database.add("Misty: Thundershock on Staryu, Bite on Starmie", test_misty_per_foe); + database.add("the trainer AI's healing items", test_ai_heal_rule); + database.add("the rival's next Pokemon when no name is read", test_next_foe); + database.add("battle risks by trainer", test_risks); + database.add("Cerulean rival: refused at Lv22, fought at Lv30", test_rival_win_chance); + database.add("m51: no Potion the foe's hit undoes", test_m51_potion_loop); + database.add("the sim's Potion: only when it outheals the hit", test_sim_potion_rule); + database.add("Misty: m51's lead as the summary showed it", test_misty_real_lead); + database.add("Cerulean rival with m51's moves at Lv20 to 30", test_rival_real_moves); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp new file mode 100644 index 0000000000..a2eb5b8bf4 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp @@ -0,0 +1,175 @@ +/* AutoStory Damage + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "PokemonFRLG_AutoStoryDamage.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +constexpr uint32_t MAX_IV = 31; +constexpr uint32_t MIN_ROLL = 85; +constexpr uint32_t MAX_ROLL = 100; +constexpr uint32_t ROLLS = MAX_ROLL - MIN_ROLL + 1; +constexpr int MAX_STAGE = 6; + +// CALC_STAT with ModifyStatByNature. `index` is the nature table's: +// Attack 0, Defense 1, Speed 2, Sp. Atk 3, Sp. Def 4. +uint16_t other_stat(uint8_t base, const Genes& genes, uint8_t level, size_t index){ + uint32_t stat = (2 * base + genes.iv + genes.ev / 4) * level / 100 + 5; + const size_t raised = genes.nature / 5; + const size_t lowered = genes.nature % 5; + if (raised != lowered && index == raised){ + stat = stat * 110 / 100; + }else if (raised != lowered && index == lowered){ + stat = stat * 90 / 100; + } + return static_cast(stat); +} + +uint32_t boosted(uint32_t stat, bool badge){ + return badge ? 110 * stat / 100 : stat; +} + +// APPLY_STAT_MOD, and a crit's: the attacker's drops and the defender's +// rises are left out. +uint32_t attack_side(uint32_t stat, int stage, bool crit){ + return crit && stage <= 0 ? stat : staged_stat(stat, stage); +} +uint32_t defense_side(uint32_t stat, int stage, bool crit){ + return crit && stage >= 0 ? stat : staged_stat(stat, stage); +} + +int stage_of(const Combatant& combatant, Stage stage){ + return combatant.stages[static_cast(stage)]; +} + +// CalculateBaseDamage, for a physical or special move. +uint32_t base_damage(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit){ + const bool special = special_type(move.type); + const uint32_t attack = special + ? attack_side(boosted(attacker.stats.sp_attack, attacker.volcano_badge), stage_of(attacker, Stage::SP_ATTACK), crit) + : attack_side(boosted(attacker.stats.attack, attacker.boulder_badge), stage_of(attacker, Stage::ATTACK), crit); + const uint32_t defense = special + ? defense_side(boosted(defender.stats.sp_defense, defender.volcano_badge), stage_of(defender, Stage::SP_DEFENSE), crit) + : defense_side(boosted(defender.stats.defense, defender.soul_badge), stage_of(defender, Stage::DEFENSE), crit); + uint32_t damage = attack * move.power; + damage *= 2 * attacker.level / 5 + 2; + damage /= std::max(defense, 1); + damage /= 50; + // Only the physical branch has this. + if (!special && damage == 0){ + damage = 1; + } + return damage + 2; +} + +} + + +uint8_t trainer_iv(uint8_t pret_iv){ + return static_cast(pret_iv * MAX_IV / 255); +} + +Stats gen3_stats(const BaseStats& base, uint8_t level, const Genes& genes){ + return Stats{ + .hp = static_cast((2 * base.hp + genes.iv + genes.ev / 4) * level / 100 + level + 10), + .attack = other_stat(base.attack, genes, level, 0), + .defense = other_stat(base.defense, genes, level, 1), + .sp_attack = other_stat(base.sp_attack, genes, level, 3), + .sp_defense = other_stat(base.sp_defense, genes, level, 4), + .speed = other_stat(base.speed, genes, level, 2), + }; +} + +uint32_t staged_stat(uint32_t stat, int stage){ + stage = std::clamp(stage, -MAX_STAGE, MAX_STAGE); + // gStatStageRatios: (10 + 5n) / 10 up, 10 / (10 + 5n) down. + return stage >= 0 ? stat * (10 + 5 * stage) / 10 : stat * 10 / (10 - 5 * stage); +} + +std::optional combatant(std::string_view species, uint8_t level, const Genes& genes){ + const SpeciesData* data = species_data(species); + if (data == nullptr){ + return std::nullopt; + } + return Combatant{.first = data->first, .second = data->second, .level = level, .stats = gen3_stats(data->base, level, genes)}; +} + +std::optional fixed_damage(const MoveData& move, const Combatant& attacker){ + if (move.effect == "dragon-rage"){ + return 40; + } + if (move.effect == "sonicboom"){ + return 20; + } + if (move.effect == "level-damage"){ + return attacker.level; + } + return std::nullopt; +} + +uint32_t damage_before_roll(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit){ + if (move.power == 0 || move.type == PokemonType::NONE){ + return 0; + } + const std::vector multipliers = type_multipliers(move.type, defender.first, defender.second); + const bool immune = std::ranges::find(multipliers, 0) != multipliers.end(); + if (const std::optional fixed = fixed_damage(move, attacker)){ + return immune ? 0 : *fixed; + } + uint32_t damage = base_damage(attacker, defender, move, crit); + if (crit){ + damage *= 2; + } + if (attacker.first == move.type || attacker.second == move.type){ + damage = damage * 15 / 10; + } + for (size_t tenths : multipliers){ + damage = static_cast(damage * tenths / 10); + if (damage == 0 && tenths != 0){ + damage = 1; + } + } + return damage; +} + +uint32_t rolled_damage(uint32_t before, uint32_t percent){ + if (before == 0){ + return 0; + } + return std::max(before * percent / 100, 1); +} + +DamageRange damage_range(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit){ + const uint32_t before = damage_before_roll(attacker, defender, move, crit); + if (fixed_damage(move, attacker)){ + return DamageRange{.min = before, .max = before}; + } + return DamageRange{.min = rolled_damage(before, MIN_ROLL), .max = rolled_damage(before, MAX_ROLL)}; +} + +double average_damage(const Combatant& attacker, const Combatant& defender, const MoveData& move){ + const uint32_t before = damage_before_roll(attacker, defender, move, false); + if (fixed_damage(move, attacker)){ + return before; + } + uint32_t total = 0; + for (uint32_t percent = MIN_ROLL; percent <= MAX_ROLL; percent++){ + total += rolled_damage(before, percent); + } + return static_cast(total) / ROLLS; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h new file mode 100644 index 0000000000..745d40ebe5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h @@ -0,0 +1,123 @@ +/* AutoStory Damage + * + * From: https://github.com/PokemonAutomation/ + * + * Gen 3 stats and damage as FireRed computes them, for the story's move + * choices and battle sim (PokemonFRLG_AutoStoryBattleSim.h). From + * pret/pokefirered: + * - stats: CalculateMonStats (src/pokemon.c), the nature's 10% as + * ModifyStatByNature; + * - damage: CalculateBaseDamage (src/pokemon.c), whose result already + * holds the +2, then in battle_script_commands.c Cmd_damagecalc's crit + * x2, Cmd_typecalc's STAB x1.5 and type multipliers one by one in the + * type chart's order (ModulateDmgByType: at least 1 unless 0x), then + * ApplyRandomDmgMultiplier's roll of 85 to 100 percent (at least 1). + * Physical or special goes by the move's type. Stat stages (and a + * crit's ignoring of the unhelpful ones) and the player's badge boosts + * are in; burn, Reflect, Light Screen, weather, abilities and held items + * are not. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryDamage_H +#define PokemonAutomation_PokemonFRLG_AutoStoryDamage_H + +#include +#include +#include +#include +#include "PokemonFRLG_AutoStoryBattleData.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// A Pokemon's stats, in the game's order. +struct Stats{ + uint16_t hp = 0; + uint16_t attack = 0; + uint16_t defense = 0; + uint16_t sp_attack = 0; + uint16_t sp_defense = 0; + uint16_t speed = 0; +}; + +// The same IV and EV in every stat, and the nature's index (0 Hardy to +// 24 Quirky; a nature raises stat n / 5 and lowers n % 5, of Attack, +// Defense, Speed, Sp. Atk, Sp. Def). +struct Genes{ + uint8_t iv = 0; + uint8_t ev = 0; + uint8_t nature = 0; +}; + +// A trainer's Pokemon's IVs from pret's iv (0 to 255). +uint8_t trainer_iv(uint8_t pret_iv); + +Stats gen3_stats(const BaseStats& base, uint8_t level, const Genes& genes); + +// The stat stages the damage formula and the sim use, from -6 to +6. +enum class Stage : size_t{ + ATTACK, + DEFENSE, + SPEED, + SP_ATTACK, + SP_DEFENSE, + ACCURACY, + EVASION, +}; +inline constexpr size_t STAGES = 7; +using StatStages = std::array; + +// `stat` at `stage` (gStatStageRatios). +uint32_t staged_stat(uint32_t stat, int stage); + +// A Pokemon in battle as the damage formula sees it. +struct Combatant{ + PokemonType first = PokemonType::NONE; + PokemonType second = PokemonType::NONE; + uint8_t level = 0; + Stats stats = {}; + StatStages stages = {}; + // The player's badges that boost this Pokemon's stats by 10% + // (ShouldGetStatBadgeBoost): the Boulder Badge its Attack, the Soul + // Badge its Defense, the Volcano Badge its Sp. Atk and Sp. Def. Only + // for the player's Pokemon. + bool boulder_badge = false; + bool soul_badge = false; + bool volcano_badge = false; +}; + +// `species` at `level` with `genes`: its types and stats. +std::optional combatant(std::string_view species, uint8_t level, const Genes& genes); + +// The damage of a move whose damage doesn't come from the formula: +// Dragon Rage 40, Sonic Boom 20, Seismic Toss and Night Shade the +// attacker's level. None for the rest. +std::optional fixed_damage(const MoveData& move, const Combatant& attacker); + +// The damage before the random roll: CalculateBaseDamage (with its +2), +// the crit, STAB and the type chart. 0 for a move with no power, or one +// the defender is immune to. Fixed damage as fixed_damage() says. +uint32_t damage_before_roll(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit); + +// `before` at the random roll `percent` (85 to 100). +uint32_t rolled_damage(uint32_t before, uint32_t percent); + +struct DamageRange{ + uint32_t min = 0; + uint32_t max = 0; +}; +// The damage at the lowest roll (85) and the highest (100). +DamageRange damage_range(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit); + +// The mean over the 16 rolls, without crits. +double average_damage(const Combatant& attacker, const Combatant& defender, const MoveData& move); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp new file mode 100644 index 0000000000..4c205cbb49 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -0,0 +1,528 @@ +/* AutoStory Events + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "Pokemon/AutoStory/Pokemon_TilePose.h" +#include "Pokemon/Navigation/Pokemon_RouteLog.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryBattleData.h" +#include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStorySummary.h" +#include "PokemonFRLG_AutoStoryWinChance.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace std::chrono_literals; +using Pokemon::facing_of; +using Pokemon::Outcome; +using Pokemon::RunState; + + +namespace{ + +// The longest scenes: the old man's tutorial (about 60 lines and his +// catching demo), the lab's Pokedex scene (about 75 lines). +constexpr Milliseconds SCENE_TIMEOUT = 300000ms; +constexpr Milliseconds YES_NO_TIMEOUT = 60000ms; +constexpr Milliseconds BATTLE_TEXT_TIMEOUT = 90000ms; + +// The engine knows nothing of consoles: a failed console step is a failed +// Outcome, which the segment answers by reloading the save. +template +Outcome guarded(Body&& body){ + try{ + return body(); + }catch (OperationFailedException& e){ + return Pokemon::outcome_failed("operation_failed", e.message()); + } +} + +const MapData* find_story_map(const std::string& name){ + for (const MapData& map : story_maps()){ + if (map.name == name){ + return ↦ + } + } + return nullptr; +} + +// Turns the player to a wall next to `position`, which turns without a +// step whichever way the player faced. Nothing if no wall is next to it. +std::optional face_a_wall(StoryEnv& env, const MapPosition& position){ + const MapData* map = find_story_map(position.map); + if (map == nullptr){ + return std::nullopt; + } + const std::optional wall = wall_beside(*map, position.point); + if (wall){ + env.console.log(std::string("Story: facing unknown, turning to the wall ") + direction_name(*wall) + "."); + face_wall(env.context, *wall); + } + return wall; +} + +// The shared route log's arrival line (Pokemon_RouteLog.h), as BDSP's walker +// writes it: where the route was walked to. +void log_arrival(StoryEnv& env, const std::string& label, const std::string& map, const TilePos& tile){ + env.console.log(Pokemon::ROUTE_LOG_TAG + Pokemon::route_arrived_line(label, {{map, tile}})); +} + +// The walker's check that each leg to a wall ended at it (a diagnostic): +// with Thorough checks only, as Fast trusts the walk. +WallCheck wall_check(const StoryEnv& env){ + return env.checks == StoryChecks::THOROUGH ? WallCheck::TAP : WallCheck::SKIP; +} + +Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ + const std::vector tiles = Pokemon::tiles_of(state.pose); + if (tiles.size() != 1 || state.pose.certainty != Pokemon::PoseCertainty::TILE){ + return Pokemon::outcome_failed("no_pose", Pokemon::to_string(state.pose)); + } + const MapPosition start{state.pose.map, tiles[0]}; + std::optional facing = facing_of(state.pose); + if (!facing){ + facing = face_a_wall(env, start); + } + if (!facing){ + return Pokemon::outcome_failed("unknown_facing", to_string(start)); + } + const std::optional target = step.target ? story_pose(*step.target) : std::nullopt; + if (!target){ + return Pokemon::outcome_failed("bad_target", step.target ? Pokemon::to_string(*step.target) : "none"); + } + const RouteGoal goal{{target->map, target->tile}, target->facing}; + const std::optional> route = plan_overworld_route( + story_maps(), start, goal, default_route_costs(), facing + ); + if (!route){ + return Pokemon::outcome_failed("no_route", to_string(start) + " to " + to_string(goal.position)); + } + const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks, env.language); + // Planning lets the walker recover a stopped open leg: it plans back to + // the leg's end, then walks the rest as given. + const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name, .wall_check = wall_check(env)}; + walk_overworld_route_with_recovery(env.console, env.context, *route, planning, facing, interrupts, move_speed(step)); + log_arrival(env, step.name, target->map, target->tile); + const std::optional end_facing = route->empty() ? facing : std::optional(route->back().facing_after); + return Pokemon::outcome_ok(to_pose(StoryPose{target->map, target->tile, end_facing})); +} + +Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ + const std::vector tiles = Pokemon::tiles_of(state.pose); + if (tiles.size() != 1 || state.pose.certainty != Pokemon::PoseCertainty::TILE){ + return Pokemon::outcome_failed("no_pose", Pokemon::to_string(state.pose)); + } + const MapPosition start{state.pose.map, tiles[0]}; + std::optional facing = facing_of(state.pose); + if (!facing){ + facing = face_a_wall(env, start); + } + const std::optional> route = fixed_route(story_maps(), start, step.legs); + if (!facing || !route || route->empty()){ + return Pokemon::outcome_failed("bad_legs", to_string(start)); + } + const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks, env.language); + // Planning lets the walker recover a stopped open leg: it plans back to + // the leg's end, then walks the rest as given. + const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name, .wall_check = wall_check(env)}; + walk_overworld_route_with_recovery(env.console, env.context, *route, planning, facing, interrupts, move_speed(step)); + log_arrival(env, step.name, route->back().end.map, route->back().end.point); + return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after})); +} + +Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ + step_once(env.context, step.direction, facing_of(state.pose)); + const std::vector tiles = Pokemon::tiles_of(state.pose); + if (tiles.size() != 1){ + return Pokemon::outcome_ok(); + } + return Pokemon::outcome_ok(to_pose(StoryPose{state.pose.map, tiles[0].next(step.direction), step.direction})); +} + +// Before a BattleRisk::HIGH battle the story may lose: the sim's win +// chance, the HP as the last bar read left it. Why not to fight, if so. +std::optional refuse_battle(StoryEnv& env, const StoryStep& step, std::string_view trainer){ + const Supplies& supplies = env.supplies; + if (step.may_lose || supplies.risk != BattleRisk::HIGH){ + return std::nullopt; + } + const std::optional estimate = story_win_chance(supplies.lead, supplies.potions, supplies.hp_fill, trainer); + if (!estimate){ + return std::nullopt; + } + env.console.log(std::format( + "Story: {} against {}: the sim wins {} of {} ({:.0f}%) with {}.", + step.name, trainer, estimate->wins, estimate->battles, 100 * estimate->chance, estimate->inputs + )); + return win_chance_refusal(*estimate); +} + +Outcome battle(StoryEnv& env, const StoryStep& step){ + const std::optional trainer = step.pose_after ? story_trainer(step.pose_after->map, step.name) : std::nullopt; + env.supplies.trainer = trainer ? std::string(*trainer) : ""; + env.supplies.risk = trainer ? story_battle_risk(step.pose_after->map, step.name) : BattleRisk::LOW; + env.supplies.foe_out.reset(); + if (const std::optional refusal = trainer ? refuse_battle(env, step, *trainer) : std::nullopt){ + env.console.log("Story: " + step.name + ": " + *refusal + ".", COLOR_RED); + return Pokemon::outcome_failed("win_chance", *refusal); + } + if (advance_text(env.console, env.context, BATTLE_TEXT_TIMEOUT, true) != TextEnd::BATTLE){ + return Pokemon::outcome_failed("no_battle"); + } + env.supplies.foes = trainer ? trainer_party(*trainer) : std::vector{}; + if (!env.supplies.foes.empty()){ + env.console.log(std::format( + "Story: {} is {}, risk {}; attacks are chosen against the foe out.", + step.name, *trainer, battle_risk_name(env.supplies.risk) + )); + } + const BattleEnd end = fight_battle(env.console, env.context, env.supplies, BattleKind::TRAINER, env.checks, env.language); + env.supplies.foes.clear(); + env.supplies.trainer.clear(); + env.supplies.foe_out.reset(); + if (end == BattleEnd::LOST && !step.may_lose){ + return Pokemon::outcome_failed("blackout"); + } + mash_until_overworld(env.console, env.context, SCENE_TIMEOUT); + return Pokemon::outcome_ok(); +} + +// HP and status are the battle loop's last reading. Items first (an +// Antidote, a Parlyz Heal, a Potion); then the nurse as +// nurse_before_battle() says. +Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ + Supplies& supplies = env.supplies; + env.console.log(std::format( + "Story: before the battle, HP {}, {}, {} Potions.", + supplies.hp_red ? "red" : supplies.hurt ? "yellow" : "green", status_name(supplies.status), supplies.potions + )); + recover_after_battle(env.console, env.context, supplies, env.checks, env.language); + if (!nurse_before_battle(supplies)){ + return Pokemon::outcome_ok(); + } + Outcome walked = walk_route(env, state, step); + if (!walked.succeeded()){ + return walked; + } + heal_at_center(env.console, env.context); + healed_by_nurse(supplies); + return walked; +} + +// Viridian Mart before the Boulder Badge (pokefirered ViridianCity_Mart_Items): +// POKE BALL, POTION (300), ANTIDOTE (100), PARLYZ HEAL (200). Each item +// the story buys: its row, and where the bag's count is kept. +struct MartItem{ + const char* item; + int row; + int Supplies::* count; + // The name the item list reader reads (read_item_list_name()). + const char* slug; +}; +constexpr MartItem VIRIDIAN_MART_ITEMS[] = { + {.item = "potion", .row = 1, .count = &Supplies::potions, .slug = "potion"}, + {.item = "antidote", .row = 2, .count = &Supplies::antidotes, .slug = "antidote"}, + {.item = "parlyz_heal", .row = 3, .count = &Supplies::parlyz_heals, .slug = "parlyz-heal"}, +}; + +const MartItem* viridian_mart_item(const std::string& name){ + for (const MartItem& item : VIRIDIAN_MART_ITEMS){ + if (name == item.item){ + return &item; + } + } + return nullptr; +} + +Outcome shop(StoryEnv& env, const StoryStep& step){ + const std::optional> orders = viridian_mart_orders(step.items); + if (!orders){ + return Pokemon::outcome_failed("unknown_item", step.name); + } + // 2000 of the 3000 a new game starts with, plus the rival's prize. + buy_items(env.console, env.context, *orders, env.checks, env.language); + for (const Pokemon::StoryItem& item : step.items){ + env.supplies.*viridian_mart_item(item.item)->count += (int)item.quantity; + } + if (env.checks == StoryChecks::FAST){ + return Pokemon::outcome_ok(); + } + // The counts from the bag, not from the orders: a wrong row once bought + // Parlyz Heals for Antidotes unnoticed (console B, 2026-11-01). + const std::vector rows = read_items_pocket(env.console, env.context, env.language); + if (rows.empty()){ + env.console.log("Story: couldn't read the Items pocket; keeping the counts ordered.", COLOR_ORANGE); + return Pokemon::outcome_ok(); + } + for (const std::string& item : set_from_bag(env.supplies, rows)){ + env.console.log(std::format( + "Story: couldn't read how many {} the bag holds; counting {}.", + item, item_count(env.supplies, item) + ), COLOR_ORANGE); + } + return Pokemon::outcome_ok(); +} + +} + + +std::optional> viridian_mart_orders(const std::vector& items){ + std::vector orders; + for (const Pokemon::StoryItem& wanted : items){ + const MartItem* found = viridian_mart_item(wanted.item); + if (found == nullptr){ + return std::nullopt; + } + orders.push_back(MartOrder{found->row, (int)wanted.quantity, found->slug}); + } + return orders; +} + +const std::vector& story_maps(){ + static const std::vector maps = overworld_maps(map_flag_set(overworld_maps(), "after_hall_of_fame")); + return maps; +} + +MoveSpeed move_speed(const StoryStep& step){ + return step.variant == RUN_VARIANT ? MoveSpeed::RUN : MoveSpeed::WALK; +} + +Pokemon::Pose to_pose(const StoryPose& pose){ + return Pokemon::tile_pose(pose.map, {pose.tile}, pose.facing); +} + +std::optional story_pose(const Pokemon::Pose& pose){ + const std::vector tiles = Pokemon::tiles_of(pose); + if (tiles.size() != 1){ + return std::nullopt; + } + return StoryPose{pose.map, tiles[0], facing_of(pose)}; +} + +std::string save_card_place(const std::string& map){ + // The longer names first: "ViridianForest" before "ViridianCity". + static const std::pair PLACES[] = { + {"PalletTown", "pallet-town"}, + {"ViridianForest", "viridian-forest"}, + {"ViridianCity", "viridian-city"}, + {"PewterCity", "pewter-city"}, + }; + for (const auto& [prefix, place] : PLACES){ + if (map.rfind(prefix, 0) == 0){ + return place; + } + } + return ""; +} + +std::string save_place_error(const std::string& start_map, const std::string& place){ + const std::string expected = save_card_place(start_map); + if (expected.empty() || place.empty() || place == expected){ + return ""; + } + return "The save is in " + place + ", but the checkpoint starts in " + expected + " (" + start_map + ")."; +} + +std::optional> fixed_route( + const std::vector& maps, const MapPosition& start, const std::vector& legs +){ + const MapData* map = nullptr; + for (const MapData& candidate : maps){ + if (candidate.name == start.map){ + map = &candidate; + } + } + if (map == nullptr || !in_bounds(*map, start.point)){ + return std::nullopt; + } + std::vector route; + PlayerState player{start.point, elevation_at(*map, start.point), false}; + for (const StoryLeg& leg : legs){ + RouteStep step; + step.direction = leg.direction; + step.tiles = leg.tiles; + step.facing_after = leg.direction; + for (int c = 0; c < leg.tiles; c++){ + const StepKind kind = classify_step(*map, player, leg.direction); + const TilePos next = player.position.next(leg.direction); + if (kind != StepKind::WALK || !in_bounds(*map, next) || warps_on_step(*map, next)){ + return std::nullopt; + } + step.wild |= is_tall_grass(*map, next); + player = after_step(*map, player, leg.direction, kind); + } + step.to_wall = classify_step(*map, player, leg.direction) == StepKind::BLOCKED; + step.end = MapPosition{map->name, player.position}; + route.push_back(step); + } + return route; +} + +std::optional wall_beside(const MapData& map, const TilePos& tile){ + for (Direction direction : {Direction::WEST, Direction::EAST, Direction::NORTH, Direction::SOUTH}){ + const TilePos next = tile.next(direction); + if (in_bounds(map, next) && tile_at(map, next) == TileKind::WALL && object_at(map, next) == nullptr){ + return direction; + } + } + return std::nullopt; +} + +StoryExecutor::StoryExecutor(StoryEnv& env) + : m_env(env) +{} + +Outcome StoryExecutor::run(RunState& state, const StoryStep& step){ + return guarded([&]{ return Pokemon::StoryStepExecutor::run(state, step); }); +} + +Outcome StoryExecutor::new_game(RunState&, const StoryStep&){ + play_new_game_intro(m_env.console, m_env.context); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::options(RunState&, const StoryStep&){ + set_options(m_env.console, m_env.context, m_menu, m_env.language); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::route(RunState& state, const StoryStep& step){ + return walk_route(m_env, state, step); +} + +Outcome StoryExecutor::legs(RunState& state, const StoryStep& step){ + return walk_legs(m_env, state, step); +} + +Outcome StoryExecutor::step(RunState& state, const StoryStep& step){ + return take_step(m_env, state, step); +} + +Outcome StoryExecutor::talk(RunState&, const StoryStep&){ + pbf_press_button(m_env.context, BUTTON_A, 160ms, 800ms); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::answer(RunState&, const StoryStep& step){ + answer_yes_no(m_env.console, m_env.context, step.yes, BUTTON_B, YES_NO_TIMEOUT); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::mash(RunState&, const StoryStep&){ + mash_until_overworld(m_env.console, m_env.context, SCENE_TIMEOUT); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::battle(RunState&, const StoryStep& step){ + return PokemonFRLG::battle(m_env, step); +} + +Outcome StoryExecutor::heal(RunState&, const StoryStep&){ + heal_at_center(m_env.console, m_env.context); + healed_by_nurse(m_env.supplies); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::shop(RunState&, const StoryStep& step){ + return PokemonFRLG::shop(m_env, step); +} + +Outcome StoryExecutor::ready(RunState& state, const StoryStep& step){ + return get_ready(m_env, state, step); +} + + +std::string check_save_place(StoryEnv& env, const std::string& start_map){ + if (save_card_place(start_map).empty()){ + return ""; + } + const std::string place = read_save_place(env.console, env.context, env.language); + if (place.empty()){ + env.console.log("Couldn't read the save card's place; going on.", COLOR_ORANGE); + return ""; + } + const std::string error = save_place_error(start_map, place); + if (error.empty()){ + env.console.log("The save is in " + place + ", where the checkpoint starts."); + } + return error; +} + +void read_lead_moves(StoryEnv& env, StartMenu menu){ + const std::optional read = read_party_summary(env.console, env.context, menu, env.language, 0); + if (!read || read->moves.empty()){ + env.console.log("Couldn't read the lead's moves; going on with the checkpoint's.", COLOR_ORANGE); + return; + } + const PartyMember& before = env.supplies.lead; + const std::string species = read->species.empty() ? before.species : read->species; + const uint8_t level = read->level && *read->level <= 100 ? static_cast(*read->level) : before.moves_through_level; + // The stats belong to the species and level read. + const bool stats_fit = species == read->species && read->level.has_value(); + env.supplies.lead = member_from_summary(species, level, read->moves, stats_fit ? read->stats : std::nullopt); + env.saved_supplies.lead = env.supplies.lead; +} + +void read_bag_supplies(StoryEnv& env, StartMenu menu){ + if (menu != StartMenu::FULL){ + return; + } + const std::vector rows = read_items_pocket(env.console, env.context, env.language); + if (rows.empty()){ + env.console.log("Couldn't read the Items pocket; going on with the checkpoint's items.", COLOR_ORANGE); + return; + } + for (const std::string& item : set_from_loaded_bag(env.supplies, env.saved_supplies, rows)){ + env.console.log(std::format( + "Story: couldn't read how many {} the bag holds; counting {}.", item, item_count(env.supplies, item) + ), COLOR_ORANGE); + } +} + +Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& executor){ + executor.set_menu(data.menu); + Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); + StoryEnv& env = executor.env(); + env.start_map = data.start ? data.start->map : ""; + env.start_menu = data.menu; + const StartMenu menu = data.menu; + checkpoint.save = [&env, menu](RunState&){ + return guarded([&]{ + save_game(env.console, env.context, menu); + env.has_save = true; + env.saved_supplies = env.supplies; + return Pokemon::outcome_ok(); + }); + }; + return checkpoint; +} + +Pokemon::Segment make_story_segment(const std::vector& checkpoints, StoryExecutor& executor){ + Pokemon::Segment segment; + segment.id = "00"; + for (const StoryCheckpoint& data : checkpoints){ + segment.checkpoints.push_back(Pokemon::CheckpointSpec{ + data.id, data.title, false, + [&data, &executor]{ return build_checkpoint(data, executor); } + }); + } + return segment; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h new file mode 100644 index 0000000000..887ca363b6 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -0,0 +1,192 @@ +/* AutoStory Events + * + * From: https://github.com/PokemonAutomation/ + * + * The FRLG story as data for the shared story engine + * (Pokemon/AutoStory/Pokemon_StoryEvents.h, Pokemon_StorySegments.h). + * A checkpoint is a list of the shared StorySteps + * (Pokemon/AutoStory/Pokemon_StorySteps.h), each one kind of event (a + * route, a talk, text read to its end, a YES/NO, a battle, the nurse, the + * Mart); StoryExecutor does each kind on the console, and + * make_story_segment() turns the table into engine checkpoints. Routes + * plan from the pose the run carries and return where they leave the + * player; scenes that move the player say where in the table. + * + * The table itself is in PokemonFRLG_AutoStoryTable.h; it is plain data, + * so its routes are planned in unit tests without a console. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryEvents_H +#define PokemonAutomation_PokemonFRLG_AutoStoryEvents_H + +#include +#include +#include +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryEvents.h" +#include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +using Pokemon::StoryLeg; +using Pokemon::StoryStep; +using Pokemon::StoryStepKind; + +// Where the player stands and faces: the one-tile poses of FRLG's table +// and routes. An unknown facing (after a scene that turns the player) is +// set before the next route by turning to a wall. +struct StoryPose{ + std::string map; + TilePos tile; + std::optional facing; +}; + +// The variant of a ROUTE or LEGS step that runs, with B held: the player +// has the Running Shoes (00.10 on). +inline const std::string RUN_VARIANT = "run"; + +// How `step`, a ROUTE or LEGS, moves the player: RUN_VARIANT runs. +MoveSpeed move_speed(const StoryStep& step); + + +// A shared checkpoint with what FRLG adds to it. +struct StoryCheckpoint : public Pokemon::StoryCheckpoint{ + // The healing items at its start, for a run that loads its save. + Supplies supplies; + // The START menu at its end, when it saves. + StartMenu menu = StartMenu::FULL; +}; + + +// The maps the story plans on: every map to Brock, with the objects the +// game hides after the Hall of Fame removed, as the lab's frlg_route does. +const std::vector& story_maps(); + +Pokemon::Pose to_pose(const StoryPose& pose); +// `pose` as a StoryPose: nothing unless it is on one tile. +std::optional story_pose(const Pokemon::Pose& pose); + +// The place the save card names for a save on `map` (see +// read_save_card_location()), or empty for a map whose place isn't known. +std::string save_card_place(const std::string& map); + +// Why a save whose card names `place` can't start a checkpoint that starts +// on `start_map`, or empty if it can: the places match, the card couldn't +// be read (empty `place`), or the map has no known place. +std::string save_place_error(const std::string& start_map, const std::string& place); + +// `legs` from `start` as route steps for the walker, each checked against +// the map: nothing if a step is blocked or leaves the map. A leg ends "to +// wall" if the next step its way is blocked. +std::optional> fixed_route( + const std::vector& maps, const MapPosition& start, const std::vector& legs +); + +// A way the player at `tile` can turn to without stepping: a wall there, +// with no one standing in it. West and east first: walking north or south +// into a sign would read it. +std::optional wall_beside(const MapData& map, const TilePos& tile); + +// `items` as orders at the Viridian Mart before the Boulder Badge: the +// rows of POKE BALL, POTION, ANTIDOTE, PARLYZ HEAL. Nothing if it does +// not sell one of them. +std::optional> viridian_mart_orders(const std::vector& items); + + +// What the story's events act on. `supplies` are what the bag holds now, +// `saved_supplies` what the last save holds. +struct StoryEnv{ + ConsoleHandle& console; + ProControllerContext& context; + Supplies supplies; + Supplies saved_supplies; + // Whether the game has a save to reload. + bool has_save = false; + StoryChecks checks = StoryChecks::THOROUGH; + // The game's language, for reading item names. In one the readers have + // no names for, the checks fall back to positions and counts. + Language language = Language::English; + // The map the checkpoint under way starts on, where its save is: a + // reload checks the save card against it. + std::string start_map = {}; + // That checkpoint's START menu: a reload reads the bag again with it. + StartMenu start_menu = StartMenu::BEFORE_POKEMON; +}; + +// After a save is loaded for a checkpoint that starts on `start_map`: the +// save card's place, read from the START menu, against it, at every checks +// level. Empty if the save is there (or the card can't be read), else why +// not. +std::string check_save_place(StoryEnv& env, const std::string& start_map); + +// After a save is loaded, with START's menu `menu`: the lead's moves as its +// summary shows them, which the battles then start from in place of the +// row's (in env's supplies and the ones a reload restores). The row's are +// kept if no move can be read. +void read_lead_moves(StoryEnv& env, StartMenu menu); + +// After a save is loaded, with START's menu `menu`: the Items pocket's +// counts as read (set_from_loaded_bag()), in place of the row's, which +// are kept if nothing can be read. Only with the full menu: the rows +// before it carry the items they have. +void read_bag_supplies(StoryEnv& env, StartMenu menu); + +// Does FRLG's kinds of story step on the console. A console step that +// fails is a failed Outcome, which the segment answers by reloading. +class StoryExecutor : public Pokemon::StoryStepExecutor{ +public: + explicit StoryExecutor(StoryEnv& env); + + StoryEnv& env(){ + return m_env; + } + // The START menu SET_OPTIONS leaves: the checkpoint's being built. + void set_menu(StartMenu menu){ + m_menu = menu; + } + + virtual Pokemon::Outcome run(Pokemon::RunState& state, const StoryStep& step) override; + +protected: + virtual Pokemon::Outcome new_game(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome options(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome route(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome legs(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome step(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome talk(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome answer(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome mash(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome battle(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome heal(Pokemon::RunState& state, const StoryStep& step) override; + // The Viridian Mart, before the Boulder Badge: Potions, Antidotes and Parlyz Heals. + virtual Pokemon::Outcome shop(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome ready(Pokemon::RunState& state, const StoryStep& step) override; + +private: + StoryEnv& m_env; + StartMenu m_menu = StartMenu::FULL; +}; + +// The checkpoint `data` as events, saving at its end. +Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& executor); + +// `checkpoints` (kept alive by the caller) as a segment for run_segment(). +Pokemon::Segment make_story_segment(const std::vector& checkpoints, StoryExecutor& executor); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp new file mode 100644 index 0000000000..ce5fb1c586 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp @@ -0,0 +1,77 @@ +/* AutoStory Foe Tracker + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonFRLG_AutoStoryFoeTracker.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// Looks in a row with the foe's box gone and the lead's there: a faint, +// not a frame between two animations (as for the lead's, FAINT_POLLS in +// PokemonFRLG_AutoStoryBattle.cpp). +constexpr int FOE_GONE_POLLS = 3; + +} + + +TrainerFoeTracker::TrainerFoeTracker(std::string_view trainer, const PartyMember& lead) + : m_lead(own_battler(lead)) +{ + const std::optional sim = trainer.empty() ? std::nullopt : sim_trainer(trainer); + if (!sim){ + return; + } + m_party = sim->party; + for (const SimBattler& battler : m_party){ + m_species.push_back(battler.species); + } +} + +void TrainerFoeTracker::boxes_seen(BattleBoxes boxes){ + if (m_party.empty() || boxes.foe || !boxes.lead){ + m_gone_polls = boxes.foe ? 0 : m_gone_polls; + return; + } + if (++m_gone_polls == FOE_GONE_POLLS && !m_next_due){ + m_fainted.insert(m_out); + m_party[m_out].hp = 0; + m_next_due = true; + } +} + +void TrainerFoeTracker::at_menu(std::string_view read){ + if (m_party.empty()){ + return; + } + if (m_next_due && m_lead){ + m_out = ai_next_foe(m_party, m_out, *m_lead); + } + m_next_due = false; + if (read.empty() || m_species[m_out] == read){ + return; + } + // The name says otherwise: the first of that species not fainted. + for (size_t slot = 0; slot < m_party.size(); slot++){ + if (m_species[slot] == read && !m_fainted.contains(slot)){ + m_out = slot; + return; + } + } +} + +std::optional TrainerFoeTracker::out() const{ + return m_party.empty() ? std::nullopt : std::optional(m_out); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h new file mode 100644 index 0000000000..2dc37a8b90 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h @@ -0,0 +1,72 @@ +/* AutoStory Foe Tracker + * + * From: https://github.com/PokemonAutomation/ + * + * Which of a trainer's Pokemon is out, in a story battle whose trainer + * the story knows, so the lead's move is chosen against that one. The + * name in the foe's HP box is read at each battle menu + * (read_trainer_foe()). When it isn't read, the tracker goes by the game: + * the party's first Pokemon opens, a foe faints when its box is gone + * while the lead's stays, and the next one is the AI's choice + * (ai_next_foe()) against the lead. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryFoeTracker_H +#define PokemonAutomation_PokemonFRLG_AutoStoryFoeTracker_H + +#include +#include +#include +#include +#include +#include +#include "PokemonFRLG_AutoStoryBattleSim.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Which HP boxes a battle screen shows. +struct BattleBoxes{ + bool lead = false; + bool foe = false; +}; + +class TrainerFoeTracker{ +public: + // `trainer`: pret's constant, or "" when the battle's trainer isn't + // known (then nothing is tracked). `lead`: the story's lead, for the + // AI's next Pokemon. + TrainerFoeTracker(std::string_view trainer, const PartyMember& lead); + + // The species in the party, for reading the name. + const std::vector& species() const{ return m_species; } + + // At each look at a battle screen. + void boxes_seen(BattleBoxes boxes); + + // At a battle menu, with the foe's species as read ("" if not read). + void at_menu(std::string_view read); + + // The party slot out; none when the trainer isn't known. + std::optional out() const; + +private: + std::vector m_party; + std::vector m_species; + std::optional m_lead; + std::set m_fainted; + size_t m_out = 0; + int m_gone_polls = 0; + // A foe fainted, and no menu since: the next one isn't known yet. + bool m_next_due = false; +}; + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp new file mode 100644 index 0000000000..107e9fc670 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -0,0 +1,300 @@ +/* AutoStory Items Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The Mart cursor's moves, and the bag's rows as the story counts them. + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/Language.h" +#include "Tests/ImageUnitTest.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryBattleDecisions.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +class Test_AutoStoryItems : public UnitTest{ +public: + Test_AutoStoryItems(std::string name, std::function body) + : UnitTest("PokemonFRLG::AutoStoryItems - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_body(logger); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + + +// The orders the story gives the Viridian Mart: rows 1, 2, 3 in turn. The +// cursor stays on the row bought, so each is one row down from the last. +UnitTestResult test_mart_cursor(Logger&){ + if (mart_cursor_moves(0, 1) != 1 || mart_cursor_moves(1, 2) != 1 || mart_cursor_moves(2, 3) != 1){ + return "Expected one press down between the story's orders."; + } + if (mart_cursor_moves(3, 1) != -2 || mart_cursor_moves(2, 2) != 0){ + return "Expected presses up to a row above, none to the same row."; + } + int cursor = 0; + std::vector bought; + for (int row : {1, 2, 3}){ + cursor += mart_cursor_moves(cursor, row); + bought.push_back(cursor); + } + if (bought != std::vector{1, 2, 3}){ + return "The cursor didn't land on rows 1, 2, 3."; + } + return true; +} + +// Rows skip items with none left; the order read from the bag replaces +// the order bought. +UnitTestResult test_pocket_rows(Logger&){ + Supplies supplies; + supplies.potions = 5; + supplies.antidotes = 3; + supplies.parlyz_heals = 1; + if (item_row(supplies, "potion") != 0 || item_row(supplies, "antidote") != 1 || item_row(supplies, "parlyz-heal") != 2){ + return "Wrong rows for the order bought."; + } + supplies.potions = 0; + if (item_row(supplies, "potion") != -1 || item_row(supplies, "antidote") != 0){ + return "An item with none left still takes a row."; + } + set_from_bag(supplies, {{"potion", 4}, {"parlyz-heal", 3}}); + if (supplies.potions != 4 || supplies.antidotes != 0 || supplies.parlyz_heals != 3){ + return "Counts not taken from the bag."; + } + if (item_row(supplies, "parlyz-heal") != 1 || item_row(supplies, "antidote") != -1){ + return "Rows not taken from the bag."; + } + return true; +} + +// #211: a row loaded from a save counted no Potions, so its wild battles +// were all run from. The counts come from the bag as read, both for the +// run and for a reload; with nothing read, the row's are kept. +UnitTestResult test_loaded_bag(Logger&){ + Supplies row; + Supplies saved = row; + const std::vector unread = set_from_loaded_bag(row, saved, {{"potion", 4}, {"antidote", 2}}); + if (row.potions != 4 || saved.potions != 4 || row.antidotes != 2 || saved.antidotes != 2 || !unread.empty()){ + return std::format( + "Expected 4 Potions and 2 Antidotes from the bag, now and for a reload; got {} and {}, {} and {}.", + row.potions, saved.potions, row.antidotes, saved.antidotes + ); + } + if (item_row(saved, "antidote") != 1){ + return "Expected the reload's pocket order from the bag."; + } + + Supplies known; + known.potions = 2; + Supplies known_saved = known; + set_from_loaded_bag(known, known_saved, {}); + if (known.potions != 2 || known_saved.potions != 2){ + return "Expected the row's 2 Potions kept with nothing read."; + } + return true; +} + +// A count the bag reader couldn't read (-1) is never taken for none: the +// row still holds some, so it keeps the count bought, or 1 with none +// known, and the battle's checks (a count above 0, a row) still use it. +UnitTestResult test_unread_counts(Logger&){ + Supplies bought; + bought.potions = 5; + bought.antidotes = 3; + bought.parlyz_heals = 1; + const std::vector rows{{"potion", -1}, {"antidote", -1}, {"parlyz-heal", 1}}; + const std::vector unread = set_from_bag(bought, rows); + if (unread != std::vector{"potion", "antidote"}){ + return "Expected the Potion and Antidote counts reported unread."; + } + if (bought.potions != 5 || bought.antidotes != 3 || bought.parlyz_heals != 1){ + return std::format( + "Expected 5 Potions, 3 Antidotes, 1 Parlyz Heal kept from the order, got {}, {}, {}.", + bought.potions, bought.antidotes, bought.parlyz_heals + ); + } + + Supplies unknown; + unknown.potions = 0; + unknown.antidotes = 0; + unknown.parlyz_heals = 0; + set_from_bag(unknown, rows); + if (item_count(unknown, "potion") <= 0 || item_count(unknown, "antidote") <= 0){ + return std::format( + "Expected unread counts with none known to count as some, got {} Potions, {} Antidotes.", + unknown.potions, unknown.antidotes + ); + } + if (item_row(unknown, "potion") != 0 || item_row(unknown, "antidote") != 1 || item_row(unknown, "parlyz-heal") != 2){ + return std::format( + "Expected rows 0, 1, 2 with unread counts, got {}, {}, {}.", + item_row(unknown, "potion"), item_row(unknown, "antidote"), item_row(unknown, "parlyz-heal") + ); + } + return true; +} + +// Console B, 2026-11-03: a save from Mt. Moon has a MOON STONE above the +// PARLYZ HEAL and 15 POTIONs. An item the story doesn't count still takes +// its row, so the battle knows all 15 Potions and finds them in row 2. +UnitTestResult test_loaded_bag_other_items(Logger&){ + Supplies row; + row.potions = 0; + row.parlyz_heals = 0; + Supplies saved = row; + set_from_loaded_bag(row, saved, {{"", 1}, {"parlyz-heal", 1}, {"potion", 15}}); + if (row.potions != 15 || saved.potions != 15 || row.parlyz_heals != 1){ + return std::format( + "Expected 15 Potions and 1 Parlyz Heal from the bag, now and for a reload; got {}, {} and {}.", + row.potions, saved.potions, row.parlyz_heals + ); + } + if (item_row(row, "parlyz-heal") != 1 || item_row(row, "potion") != 2 || item_row(saved, "potion") != 2){ + return std::format( + "Expected the Parlyz Heal in row 1 and the Potions in row 2 below the Moon Stone, got {} and {}.", + item_row(row, "parlyz-heal"), item_row(row, "potion") + ); + } + return true; +} + +// The pocket's rows as read: an unread name keeps its row, so the rows +// below it are still read; the rows end at CANCEL, or at the last name read. +UnitTestResult test_pocket_rows_unread(Logger&){ + const std::vector rows = pocket_rows({{"", 1}, {"parlyz-heal", 1}, {"potion", 15}, {"cancel", -1}, {"", -1}}); + if (rows.size() != 3 || !rows[0].item.empty() || rows[2].item != "potion" || rows[2].count != 15){ + return std::format("Expected 3 rows, the Potions' last with 15, got {}.", rows.size()); + } + if (pocket_rows({{"potion", 3}, {"", -1}, {"", -1}}).size() != 1){ + return "Expected the unread rows after the last name dropped."; + } + if (!pocket_rows({{"", 1}, {"", 2}}).empty()){ + return "Expected nothing with no name read."; + } + return true; +} + +// In a language the reader has no names for, nothing is read, so the +// checks fall back to positions instead of failing. +UnitTestResult test_unread_language(Logger& logger){ + const ImageRGB32 screen(1920, 1080); + if (!read_item_list_name(logger, Language::Japanese, screen, 0).empty()){ + return "Read an item name in Japanese."; + } + if (!read_bag_pocket(logger, Language::Japanese, screen).empty()){ + return "Read bag rows in Japanese."; + } + if (!read_save_card_location(logger, Language::Japanese, screen).empty()){ + return "Read a save card's place in Japanese."; + } + return true; +} + + +// battle_shows(), the battle loop's look at whether the battle is still on +// screen, on console B's captures. +class Test_BattleShows : public ImageUnitTest{ +public: + Test_BattleShows(const std::string& image, bool expected) + : ImageUnitTest("PokemonFRLG::AutoStoryBattle - " + image, {image}) + , m_expected(expected) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + return battle_shows(images[0]) == m_expected; + } + +private: + bool m_expected; +}; + +// read_party_status() on console B's captures: the bar's color, and its +// colored share within a pixel of the 48-pixel bar of `hp` / `max_hp`. +// Console B, 2026-11-03, before Miguel: 17/55 HP read as 15% of the bar, +// then 2% with the box a pixel lower. +class Test_PartyHp : public ImageUnitTest{ +public: + Test_PartyHp(const std::string& image, std::string_view color, int hp, int max_hp) + : ImageUnitTest("PokemonFRLG::AutoStoryBattle - " + image, {image}) + , m_color(color) + , m_share(double(hp) / max_hp) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const PartyStatus status = read_party_status(images[0]); + const std::string_view color = !status.hp_seen ? "none" : status.hp_red ? "red" : status.hp_yellow ? "yellow" : "green"; + if (color != m_color){ + return std::format("Expected an HP bar read as {}, got {}.", m_color, color); + } + if (std::abs(status.hp_fill - m_share) > 1.0 / 48){ + return std::format("Expected {:.0f}% of the bar, got {:.0f}%.", 100 * m_share, 100 * status.hp_fill); + } + return true; + } + +private: + std::string_view m_color; + double m_share; +}; + + +} + + +void add_tests_AutoStoryItems(UnitTestDatabase& database){ + database.add("Mart cursor stays on the row bought", test_mart_cursor); + database.add("Items pocket rows", test_pocket_rows); + database.add("a loaded save's counts come from the bag", test_loaded_bag); + database.add("an item the story doesn't count keeps its row", test_loaded_bag_other_items); + database.add("an unread item name keeps its row", test_pocket_rows_unread); + database.add("unread bag counts count as some", test_unread_counts); + database.add("no item names read in a language without them", test_unread_language); + // "Wild CHANSEY appeared!" with its HP box, and Mt. Moon B2F's corridor + // after "Got away safely!", whose black lower half reads as the battle's + // text box (console B, 2026-11-03: 9 minutes of A and B there). + database.add("PokemonFRLG/WildEncounterReader/eng_chansey.jpg", true); + database.add("PokemonFRLG/AutoStoryBattle/MtMoonB2F_AfterRun_False.png", false); + database.add("PokemonFRLG/AutoStoryBattle/MtMoon1F_HpGreen_Full.png", "green", 45, 45); + database.add("PokemonFRLG/AutoStoryBattle/MtMoon1F_HpGreen_27of45.png", "green", 27, 45); + database.add("PokemonFRLG/AutoStoryBattle/MtMoonB2F_HpYellow_17of55.png", "yellow", 17, 55); + database.add("PokemonFRLG/AutoStoryBattle/MtMoonB2F_HpYellow_17of55_BarLow.png", "yellow", 17, 55); + // The battle's choices, registered here to keep add_tests() within its size. + add_tests_AutoStoryParty(database); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp new file mode 100644 index 0000000000..117355debf --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp @@ -0,0 +1,445 @@ +/* AutoStory Party + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "PokemonFRLG_AutoStoryBattleData.h" +#include "PokemonFRLG_AutoStoryParty.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +struct LevelUpMove{ + std::string_view species; + uint8_t level = 0; + std::string_view move; +}; + +// pret/pokefirered src/data/pokemon/level_up_learnsets.h, the lines the +// story's party comes from. +constexpr LevelUpMove LEVEL_UP_MOVES[] = { + {.species = "squirtle", .level = 1, .move = "tackle"}, + {.species = "squirtle", .level = 4, .move = "tail-whip"}, + {.species = "squirtle", .level = 7, .move = "bubble"}, + {.species = "squirtle", .level = 10, .move = "withdraw"}, + {.species = "squirtle", .level = 13, .move = "water-gun"}, + {.species = "squirtle", .level = 18, .move = "bite"}, + {.species = "squirtle", .level = 23, .move = "rapid-spin"}, + {.species = "squirtle", .level = 28, .move = "protect"}, + {.species = "squirtle", .level = 33, .move = "rain-dance"}, + {.species = "squirtle", .level = 40, .move = "skull-bash"}, + {.species = "squirtle", .level = 47, .move = "hydro-pump"}, + {.species = "wartortle", .level = 1, .move = "tackle"}, + {.species = "wartortle", .level = 1, .move = "tail-whip"}, + {.species = "wartortle", .level = 1, .move = "bubble"}, + {.species = "wartortle", .level = 4, .move = "tail-whip"}, + {.species = "wartortle", .level = 7, .move = "bubble"}, + {.species = "wartortle", .level = 10, .move = "withdraw"}, + {.species = "wartortle", .level = 13, .move = "water-gun"}, + {.species = "wartortle", .level = 19, .move = "bite"}, + {.species = "wartortle", .level = 25, .move = "rapid-spin"}, + {.species = "wartortle", .level = 31, .move = "protect"}, + {.species = "wartortle", .level = 37, .move = "rain-dance"}, + {.species = "wartortle", .level = 45, .move = "skull-bash"}, + {.species = "wartortle", .level = 53, .move = "hydro-pump"}, + {.species = "blastoise", .level = 1, .move = "tackle"}, + {.species = "blastoise", .level = 1, .move = "tail-whip"}, + {.species = "blastoise", .level = 1, .move = "bubble"}, + {.species = "blastoise", .level = 1, .move = "withdraw"}, + {.species = "blastoise", .level = 4, .move = "tail-whip"}, + {.species = "blastoise", .level = 7, .move = "bubble"}, + {.species = "blastoise", .level = 10, .move = "withdraw"}, + {.species = "blastoise", .level = 13, .move = "water-gun"}, + {.species = "blastoise", .level = 19, .move = "bite"}, + {.species = "blastoise", .level = 25, .move = "rapid-spin"}, + {.species = "blastoise", .level = 31, .move = "protect"}, + {.species = "blastoise", .level = 42, .move = "rain-dance"}, + {.species = "blastoise", .level = 55, .move = "skull-bash"}, + {.species = "blastoise", .level = 68, .move = "hydro-pump"}, + {.species = "magikarp", .level = 1, .move = "splash"}, + {.species = "magikarp", .level = 15, .move = "tackle"}, + {.species = "magikarp", .level = 30, .move = "flail"}, + {.species = "gyarados", .level = 1, .move = "thrash"}, + {.species = "gyarados", .level = 20, .move = "bite"}, + {.species = "gyarados", .level = 25, .move = "dragon-rage"}, + {.species = "gyarados", .level = 30, .move = "leer"}, + {.species = "gyarados", .level = 35, .move = "twister"}, + {.species = "gyarados", .level = 40, .move = "hydro-pump"}, + {.species = "gyarados", .level = 45, .move = "rain-dance"}, + {.species = "gyarados", .level = 50, .move = "dragon-dance"}, + {.species = "gyarados", .level = 55, .move = "hyper-beam"}, +}; + +struct Evolution{ + std::string_view species; + LevelEvolution evolution; +}; + +// pret/pokefirered src/data/pokemon/evolution.h. +constexpr Evolution EVOLUTIONS[] = { + {.species = "squirtle", .evolution = {.into = "wartortle", .level = 16}}, + {.species = "wartortle", .evolution = {.into = "blastoise", .level = 36}}, + {.species = "magikarp", .evolution = {.into = "gyarados", .level = 20}}, +}; + +// The story's plan per line (named by its first species): a level-up move +// it learns over a full move list, and the move whose slot it takes. Any +// other move offered over four is declined. Squirtle's is the speedrun's: +// Water Gun where Bubble was (so the attack stays bottom left), Bite over +// Tail Whip. TM moves are not level-up prompts and are not here. +struct LearnRule{ + std::string_view line; + std::string_view move; + std::string_view replaces; +}; +constexpr LearnRule LEARN_RULES[] = { + {.line = "squirtle", .move = "water-gun", .replaces = "bubble"}, + {.line = "squirtle", .move = "bite", .replaces = "tail-whip"}, + // A save whose Water Gun took another slot may have no Tail Whip. + {.line = "squirtle", .move = "bite", .replaces = "withdraw"}, + {.line = "magikarp", .move = "twister", .replaces = "splash"}, +}; + +// The attacks per line, the one used first at the top. Past these, the +// strongest damaging move with PP left. +struct Attack{ + std::string_view line; + std::string_view move; +}; +constexpr Attack ATTACKS[] = { + {.line = "squirtle", .move = "water-gun"}, + {.line = "squirtle", .move = "bite"}, + {.line = "squirtle", .move = "bubble"}, + {.line = "squirtle", .move = "tackle"}, + {.line = "magikarp", .move = "bite"}, + {.line = "magikarp", .move = "twister"}, + {.line = "magikarp", .move = "tackle"}, +}; + + +// The first species of `species`'s line. +std::string_view line_of(std::string_view species){ + for (const Evolution& evolution : EVOLUTIONS){ + if (evolution.evolution.into == species){ + return line_of(evolution.species); + } + } + return species; +} + +bool knows(const PartyMember& member, std::string_view move){ + return std::ranges::any_of(member.moves, [move](const KnownMove& known){ + return known.move == move; + }); +} + +std::optional slot_of(const PartyMember& member, std::string_view move){ + for (size_t slot = 0; slot < member.moves.size(); slot++){ + if (member.moves[slot].move == move){ + return slot; + } + } + return std::nullopt; +} + +// The next level-up move past `moves_through_level` that it doesn't know. +const LevelUpMove* next_move(const PartyMember& member){ + for (const LevelUpMove& entry : LEVEL_UP_MOVES){ + if (entry.species == member.species && entry.level > member.moves_through_level && !knows(member, entry.move)){ + return &entry; + } + } + return nullptr; +} + +KnownMove at_full_pp(std::string_view move){ + return KnownMove{.move = std::string(move), .pp = max_pp(move)}; +} + +// The slot the plan gives `move`, over a full move list: the first of +// its rules' moves the member knows. +std::optional forget_slot_for(const PartyMember& member, std::string_view move){ + const std::string_view line = line_of(member.species); + for (const LearnRule& rule : LEARN_RULES){ + if (rule.line != line || rule.move != move){ + continue; + } + if (const std::optional slot = slot_of(member, rule.replaces)){ + return slot; + } + } + return std::nullopt; +} + +// Learns, or answers the prompt for, each of its moves at exactly `level`. +void take_level(PartyMember& member, uint8_t level){ + for (const LevelUpMove& entry : LEVEL_UP_MOVES){ + if (entry.species != member.species || entry.level != level || knows(member, entry.move)){ + continue; + } + if (member.moves.size() < MAX_MOVES){ + member.moves.emplace_back(at_full_pp(entry.move)); + }else if (std::optional slot = forget_slot_for(member, entry.move)){ + member.moves[*slot] = at_full_pp(entry.move); + } + } + member.moves_through_level = level; +} + +// The base stat `attacker` uses `move` with: Attack or Sp. Atk, by the +// move's type. +uint8_t attacking_stat(const SpeciesData& attacker, const MoveData& move){ + return special_type(move.type) ? attacker.base.sp_attack : attacker.base.attack; +} + +// In tenths. +size_t effectiveness(const MoveData& move, const SpeciesData& defender){ + size_t tenths = type_effectiveness(move.type, defender.first); + if (defender.second != defender.first){ + tenths = tenths * type_effectiveness(move.type, defender.second) / 10; + } + return tenths; +} + +// `move`'s expected damage, summed over `foes`: its power times STAB +// times its effectiveness times the lead's base attacking stat for it. +// The foe's Defense and Sp. Def, levels, IVs, EVs, natures and accuracy +// are left out. Each foe must be in species_data(). +size_t expected_damage(const PartyMember& member, std::string_view move, const std::vector& foes){ + const MoveData* data = move_data(move); + const SpeciesData* own = species_data(member.species); + if (data == nullptr || own == nullptr){ + return 0; + } + const bool stab = own->first == data->type || own->second == data->type; + size_t damage = 0; + for (const std::string& foe : foes){ + damage += (size_t)data->power * (stab ? 15 : 10) * effectiveness(*data, *species_data(foe)) * attacking_stat(*own, *data); + } + return damage; +} + +// The member's slots in the plan's order: its line's attacks first, as +// ATTACKS lists them, then the rest in slot order. +std::vector attack_order(const PartyMember& member){ + std::vector order; + const std::string_view line = line_of(member.species); + for (const Attack& attack : ATTACKS){ + const std::optional slot = attack.line == line ? slot_of(member, attack.move) : std::nullopt; + if (slot && std::ranges::find(order, *slot) == order.end()){ + order.push_back(*slot); + } + } + for (size_t slot = 0; slot < member.moves.size(); slot++){ + if (std::ranges::find(order, slot) == order.end()){ + order.push_back(slot); + } + } + return order; +} + +} + + +std::optional level_evolution(std::string_view species){ + for (const Evolution& evolution : EVOLUTIONS){ + if (evolution.species == species){ + return evolution.evolution; + } + } + return std::nullopt; +} + +uint8_t max_pp(std::string_view move){ + const MoveData* data = move_data(move); + return data == nullptr ? 0 : data->pp; +} + +uint8_t move_power(std::string_view move){ + const MoveData* data = move_data(move); + return data == nullptr ? 0 : data->power; +} + +PartyMember new_member(std::string_view species, uint8_t level){ + PartyMember member{ + .species = std::string(species), .moves = {}, .moves_through_level = level, .moves_read = false, + .level = 0, .stats = std::nullopt, + }; + for (const LevelUpMove& entry : LEVEL_UP_MOVES){ + if (entry.species != species || entry.level > level || knows(member, entry.move)){ + continue; + } + if (member.moves.size() == MAX_MOVES){ + member.moves.erase(member.moves.begin()); + } + member.moves.emplace_back(at_full_pp(entry.move)); + } + return member; +} + +PartyMember grown_to(PartyMember member, uint8_t level){ + for (uint8_t at = static_cast(member.moves_through_level + 1); at <= level; at++){ + take_level(member, at); + const std::optional evolution = level_evolution(member.species); + if (evolution && evolution->level <= at){ + evolve(member); + // The new species learns its moves of the level it evolved at. + take_level(member, at); + } + } + return member; +} + +PartyMember story_lead_after_brock(){ + return grown_to(new_member("squirtle", 5), 13); +} + +uint8_t battle_level(const PartyMember& member){ + return std::max(member.level, member.moves_through_level); +} + +PartyMember member_from_summary( + std::string_view species, uint8_t level, const std::vector& moves, + const std::optional& stats +){ + PartyMember member{ + .species = std::string(species), .moves = {}, .moves_through_level = level, .moves_read = true, + .level = level, .stats = stats, + }; + for (const SummaryMove& read : moves){ + const uint8_t full = max_pp(read.move); + const uint8_t pp = read.pp >= 0 ? static_cast(std::min(read.pp, 255)) : static_cast(full / 2); + member.moves.emplace_back(KnownMove{.move = read.move, .pp = pp}); + } + return member; +} + +LearnDecision learn_move(PartyMember& member){ + while (member.moves.size() < MAX_MOVES){ + const LevelUpMove* learned = next_move(member); + if (learned == nullptr){ + break; + } + member.moves.emplace_back(at_full_pp(learned->move)); + member.moves_through_level = learned->level; + } + const LevelUpMove* offered = next_move(member); + if (offered == nullptr){ + return LearnDecision{}; + } + member.moves_through_level = offered->level; + LearnDecision decision{.move = std::string(offered->move), .forget_slot = forget_slot_for(member, offered->move)}; + if (decision.forget_slot){ + member.moves[*decision.forget_slot] = at_full_pp(offered->move); + } + return decision; +} + +void evolve(PartyMember& member){ + if (const std::optional evolution = level_evolution(member.species)){ + member.species = std::string(evolution->into); + member.stats.reset(); + } +} + +std::optional attack_slot(const PartyMember& member){ + if (member.moves.size() < MAX_MOVES && !member.moves_read){ + return std::nullopt; + } + const std::string_view line = line_of(member.species); + for (const Attack& attack : ATTACKS){ + if (attack.line != line){ + continue; + } + const std::optional slot = slot_of(member, attack.move); + if (slot && member.moves[*slot].pp > 0){ + return slot; + } + } + std::optional strongest; + for (size_t slot = 0; slot < member.moves.size(); slot++){ + const uint8_t power = move_power(member.moves[slot].move); + if (power > 0 && member.moves[slot].pp > 0 && (!strongest || power > move_power(member.moves[*strongest].move))){ + strongest = slot; + } + } + if (strongest){ + return strongest; + } + for (size_t slot = 0; slot < member.moves.size(); slot++){ + if (member.moves[slot].pp > 0){ + return slot; + } + } + return TOP_LEFT_MOVE; +} + +std::vector trainer_party(std::string_view trainer){ + std::vector party; + for (const TrainerMon& mon : trainer_mons(trainer)){ + party.push_back(mon.species); + } + return party; +} + +std::optional attack_slot_against(const PartyMember& member, const std::vector& foes){ + const std::optional plan = attack_slot(member); + std::vector known; + std::ranges::copy_if(foes, std::back_inserter(known), [](const std::string& foe){ + return species_data(foe) != nullptr; + }); + if (known.empty() || !plan){ + return plan; + } + std::optional best; + size_t best_damage = 0; + for (size_t slot : attack_order(member)){ + const size_t damage = expected_damage(member, member.moves[slot].move, known); + if (member.moves[slot].pp > 0 && damage > best_damage){ + best = slot; + best_damage = damage; + } + } + return best ? best : plan; +} + +size_t attack_pp(const PartyMember& member){ + size_t pp = 0; + for (const KnownMove& known : member.moves){ + if (move_power(known.move) > 0){ + pp += known.pp; + } + } + return pp; +} + +void spend_pp(PartyMember& member, size_t slot){ + if (slot < member.moves.size() && member.moves[slot].pp > 0){ + member.moves[slot].pp--; + } +} + +void no_pp_left(PartyMember& member, size_t slot){ + if (slot < member.moves.size()){ + member.moves[slot].pp = 0; + } +} + +void restore_pp(PartyMember& member){ + for (KnownMove& known : member.moves){ + known.pp = max_pp(known.move); + } +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h new file mode 100644 index 0000000000..ad6f636b3d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h @@ -0,0 +1,171 @@ +/* AutoStory Party + * + * From: https://github.com/PokemonAutomation/ + * + * The lead's moves as the story knows them, and the data its choices come + * from: level-up moves and evolutions (pret/pokefirered + * src/data/pokemon/level_up_learnsets.h, evolution.h), which new move + * takes which old one's slot, and which moves the lead attacks with + * first. Moves' PP, power and type, species' types and trainers' parties + * are the generated battle data (PokemonFRLG_AutoStoryBattleData.h). + * + * The story starts from the moves read off the lead's summary when a run + * loads a save (member_from_summary()), else from the moves a checkpoint's + * row says the lead has, and follows the game: a move learned into a free + * slot shows no prompt, so at the next "Delete a move?" the moves due + * before it are taken as learned. Which move is offered is the next + * level-up move after the last one, so the level isn't needed. + * + * Attacks are picked by name and PP, never by slot: a save's moves can sit + * in other slots than the plan's (console B, 2026-11-02: Water Gun took + * Tackle's slot, not Bubble's). + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryParty_H +#define PokemonAutomation_PokemonFRLG_AutoStoryParty_H + +#include +#include +#include +#include +#include +#include +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" +#include "PokemonFRLG_AutoStoryDamage.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The move slots, in the order of the battle's move list and the summary. +inline constexpr size_t TOP_LEFT_MOVE = 0; +inline constexpr size_t BOTTOM_LEFT_MOVE = 2; +inline constexpr size_t MAX_MOVES = 4; + +// A move the lead knows, by slug ("water-gun"), and the PP the story +// counts left. +struct KnownMove{ + std::string move; + uint8_t pp = 0; +}; + +struct PartyMember{ + std::string species; + // In slot order. Fewer than four while moves learned into free slots + // haven't been taken in yet (see the top of this file). + std::vector moves; + // The level of the last level-up move offered to it, learned or not. + uint8_t moves_through_level = 0; + // The moves were read off its summary: they are all it knows, even + // fewer than four. + bool moves_read = false; + // Its level as its summary showed it, 0 if not read. Level-ups since + // aren't seen: battle_level() takes the higher of this and + // moves_through_level. + uint8_t level = {}; + // Its stats as POKEMON SKILLS showed them at `level`, as this + // species; none if not read, or once it evolves. + std::optional stats = {}; +}; + +// The level the battle sim takes for `member`. +uint8_t battle_level(const PartyMember& member); + +// The species `species` evolves into by level, and at which level. +struct LevelEvolution{ + std::string_view into; + uint8_t level = 0; +}; +std::optional level_evolution(std::string_view species); + +// A move's full PP; 0 for a move the table doesn't have. +uint8_t max_pp(std::string_view move); + +// A move's power; 0 for one that does no damage, or that the table +// doesn't have. +uint8_t move_power(std::string_view move); + +// As the game gives `species` at `level` (a starter, a gift): its last four +// level-up moves up to `level`, at full PP. +PartyMember new_member(std::string_view species, uint8_t level); + +// The member as the story plays it up to `level`: each level-up move is +// learned into a free slot or answered as learn_move() says, and it +// evolves at its level. For the rows that start after a part of the story. +PartyMember grown_to(PartyMember member, uint8_t level); + +// Squirtle as the story leaves it after Brock (Lv13, Water Gun offered). +PartyMember story_lead_after_brock(); + +// `species` at `level` with `moves` as its summary shows them, in slot +// order, and its `stats` if POKEMON SKILLS was read. A PP that wasn't +// read is taken as half the move's full PP: the game draws the PP in +// color from half down (pokefirered pokemon_summary_screen.c), which the +// reader may not read. +PartyMember member_from_summary( + std::string_view species, uint8_t level, const std::vector& moves, + const std::optional& stats = std::nullopt +); + + +// The answer to "Delete a move to make room for ?". +struct LearnDecision{ + // The move offered, if the table knows which one it is. + std::optional move = {}; + // The slot to forget for it, or none to keep the moves as they are. + std::optional forget_slot = {}; +}; + +// At "Delete a move to make room for ...?": takes in the moves learned +// into free slots since the last prompt, decides on the move offered, and +// leaves `member` as that answer will. +LearnDecision learn_move(PartyMember& member); + +// The lead evolved: its species becomes what it evolves into. +void evolve(PartyMember& member); + + +// The slot to attack with: the first of the plan's attacks for its line +// that it knows with PP left, else its strongest damaging move with PP +// left, else any move with PP left, else the top left (Struggle). None +// while the story doesn't know all its moves (fewer than four, not read). +std::optional attack_slot(const PartyMember& member); + +// The species of `trainer`'s party, in order: pret's constant +// ("TRAINER_LEADER_MISTY", see story_trainer()), from pret/pokefirered +// src/data/trainer_parties.h. Empty for a trainer the data doesn't have. +std::vector trainer_party(std::string_view trainer); + +// The slot to attack `foes` with, any of them as likely to be out: the +// move with PP left that does the most expected damage, ties going to +// attack_slot()'s order. Expected damage, summed over the foes, is power +// times STAB times the type chart, times the lead's base Attack or Sp. +// Atk, whichever the move's type uses (Gen 3: Fire, Water, Grass, +// Electric, Psychic, Ice, Dragon and Dark are special): Water Gun and Bite +// compare on Sp. Atk, Tackle on Attack. The foe's defenses are left out, +// so a frail foe's low Defense doesn't pull Tackle ahead of a type +// advantage. A foe the data doesn't +// have is left out; with none left, or while the story doesn't know all +// the lead's moves, attack_slot() itself (the plan's order). +std::optional attack_slot_against(const PartyMember& member, const std::vector& foes); + +// The PP left in the damaging moves it knows. +size_t attack_pp(const PartyMember& member); + +// One use of the move in `slot`. +void spend_pp(PartyMember& member, size_t slot); + +// The game said the move in `slot` has no PP left. +void no_pp_left(PartyMember& member, size_t slot); + +// The nurse heals: every move back to full PP. +void restore_pp(PartyMember& member); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp new file mode 100644 index 0000000000..1b5388de98 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp @@ -0,0 +1,831 @@ +/* AutoStory Party Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The lead's moves as the story tracks them, and the battle loop's choices + * (BattleDecisions) against scripted screens: move prompts, a fainted lead, + * PP, and no B while an evolution may be on screen. + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryBattleData.h" +#include "PokemonFRLG_AutoStoryBattleDecisions.h" +#include "PokemonFRLG_AutoStoryParty.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace std::chrono_literals; + + +namespace{ + +class Test_AutoStoryParty : public UnitTest{ +public: + Test_AutoStoryParty(std::string name, std::function body) + : UnitTest("PokemonFRLG::AutoStoryParty - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_body(logger); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + + +std::vector move_names(const PartyMember& member){ + std::vector names; + for (const KnownMove& known : member.moves){ + names.push_back(known.move); + } + return names; +} + +std::string joined(const std::vector& names){ + std::string text; + for (const std::string& name : names){ + text += (text.empty() ? "" : ", ") + name; + } + return "[" + text + "]"; +} + +PartyMember with_moves(std::string species, std::vector moves, uint8_t through){ + PartyMember member{.species = std::move(species), .moves = {}, .moves_through_level = through, .moves_read = false}; + for (std::string& move : moves){ + const uint8_t pp = max_pp(move); + member.moves.emplace_back(KnownMove{.move = std::move(move), .pp = pp}); + } + return member; +} + +const PartyStatus GREEN{.hp_seen = true, .hp_yellow = false, .hp_red = false, .status = StatusCondition::NONE}; + + +// The moves the game gives, and the story's plan played to a level. +UnitTestResult test_movesets(Logger&){ + struct Case{ + std::string name; + PartyMember member; + std::string species; + std::vector moves; + }; + const std::vector cases{ + {.name = "new game Squirtle", .member = new_member("squirtle", 5), .species = "squirtle", .moves = {"tackle", "tail-whip"}}, + {.name = "Squirtle after Brock", .member = story_lead_after_brock(), .species = "squirtle", .moves = {"tackle", "tail-whip", "water-gun", "withdraw"}}, + {.name = "Squirtle to Lv20", .member = grown_to(new_member("squirtle", 5), 20), .species = "wartortle", .moves = {"tackle", "bite", "water-gun", "withdraw"}}, + {.name = "Magikarp to Lv25", .member = grown_to(new_member("magikarp", 5), 25), .species = "gyarados", .moves = {"splash", "tackle", "bite", "dragon-rage"}}, + }; + for (const Case& c : cases){ + if (c.member.species != c.species || move_names(c.member) != c.moves){ + return std::format( + "{}: expected {} {}, got {} {}.", + c.name, c.species, joined(c.moves), c.member.species, joined(move_names(c.member)) + ); + } + } + return true; +} + +// "Delete a move?": the move offered is the next level-up move, after the +// moves learned into free slots, and the plan says which slot it takes. +UnitTestResult test_learn_prompts(Logger&){ + struct Case{ + std::string name; + PartyMember member; + std::string offered; + std::optional forget_slot; + std::vector after; + }; + const std::vector cases{ + { + .name = "first prompt of a new game", + .member = new_member("squirtle", 5), + .offered = "water-gun", .forget_slot = BOTTOM_LEFT_MOVE, + .after = {"tackle", "tail-whip", "water-gun", "withdraw"}, + }, + { + .name = "Bite after Brock", + .member = story_lead_after_brock(), + .offered = "bite", .forget_slot = 1, + .after = {"tackle", "bite", "water-gun", "withdraw"}, + }, + { + // The lab's save from before the story learned moves. + .name = "Bite with Bubble kept", + .member = with_moves("squirtle", {"tackle", "tail-whip", "bubble", "withdraw"}, 13), + .offered = "bite", .forget_slot = 1, + .after = {"tackle", "bite", "bubble", "withdraw"}, + }, + { + .name = "Wartortle declines Rapid Spin", + .member = with_moves("wartortle", {"tackle", "bite", "water-gun", "withdraw"}, 19), + .offered = "rapid-spin", .forget_slot = std::nullopt, + .after = {"tackle", "bite", "water-gun", "withdraw"}, + }, + }; + for (Case c : cases){ + const LearnDecision decision = learn_move(c.member); + if (decision.move != c.offered || decision.forget_slot != c.forget_slot || move_names(c.member) != c.after){ + return std::format( + "{}: expected {} over slot {}, leaving {}; got {} over slot {}, leaving {}.", + c.name, c.offered, c.forget_slot ? std::to_string(*c.forget_slot) : "none", joined(c.after), + decision.move.value_or("nothing"), decision.forget_slot ? std::to_string(*decision.forget_slot) : "none", + joined(move_names(c.member)) + ); + } + } + return true; +} + +// NO to "Delete a move?" is followed by YES to "Stop learning?" (B there +// asks "Delete a move?" again, console B 2026-11-01); a move the plan +// wants is YES with the slot to forget. +UnitTestResult test_prompt_answers(Logger&){ + Supplies supplies; + supplies.lead = with_moves("wartortle", {"tackle", "bite", "water-gun", "withdraw"}, 19); + BattleDecisions decline(supplies, BattleKind::TRAINER); + decline.turn(GREEN); + const PromptAnswer first = decline.prompt(false); + const PromptAnswer second = decline.prompt(false); + if (first.answer != YesNo::NO || first.forget_slot || second.answer != YesNo::YES || second.forget_slot){ + return "Expected NO to \"Delete a move?\", then YES to \"Stop learning?\"."; + } + + Supplies learning; + learning.lead = story_lead_after_brock(); + BattleDecisions learn(learning, BattleKind::WILD_FIGHT); + learn.turn(GREEN); + const PromptAnswer answer = learn.prompt(false); + if (answer.answer != YesNo::YES || answer.forget_slot != std::optional(1)){ + return "Expected YES and Tail Whip's slot (1) for Bite."; + } + return true; +} + +// The lead fainted: a wild battle is run from, and a member sent only +// runs; in a trainer's, the next member is sent and uses its first move. +// Protected members are never sent: with only those left there is no +// slot, and the loop stops. Either way the +// battle is lost, and no item goes to the fainted lead. +UnitTestResult test_fainted_lead(Logger&){ + Supplies protected_party; + protected_party.protected_slots = {1, 2, 3, 4, 5}; + BattleDecisions only_protected(protected_party, BattleKind::WILD_FIGHT); + only_protected.turn(GREEN); + if (only_protected.prompt(true).answer != YesNo::NO || !only_protected.lost()){ + return "Expected NO to \"Use next POKEMON?\" in a wild battle, and the battle lost."; + } + if (only_protected.next_member_slot()){ + return "Expected no member sent with every member after the lead protected."; + } + + // Slot 1 protected, the rest not. + Supplies wild_supplies; + wild_supplies.potions = 3; + wild_supplies.protected_slots = {1}; + BattleDecisions wild(wild_supplies, BattleKind::WILD_FIGHT); + wild.turn(GREEN); + wild.prompt(true); + if (wild.next_member_slot() != std::optional(2) || wild.next_member_slot() != std::optional(3)){ + return "Expected slot 2 past the protected slot 1, then slot 3 if 2 couldn't go."; + } + const PartyStatus red{.hp_seen = true, .hp_yellow = false, .hp_red = true, .status = StatusCondition::NONE}; + for (int c = 0; c < 10; c++){ + if (wild.turn(red).choice != TurnChoice::RUN){ + return std::format("Expected the next member to run at turn {}, not fight or use an item.", c + 1); + } + } + + Supplies trainer_supplies; + BattleDecisions trainer(trainer_supplies, BattleKind::TRAINER); + trainer.turn(GREEN); + if (trainer.next_member_slot() != std::optional(1) || !trainer.lost()){ + return "Expected the member after the lead sent in a trainer's battle, and the battle lost."; + } + const TurnAction action = trainer.turn(GREEN); + if (action.choice != TurnChoice::MOVE || action.slot != TOP_LEFT_MOVE){ + return "Expected the next member to use its first move against a trainer."; + } + return true; +} + +// Water Gun until its 25 PP are gone, then Tackle; a "no PP left" moves +// on at once; the nurse restores all. Before the story knows four moves, +// the bottom left slot, as before. +UnitTestResult test_pp(Logger&){ + Supplies supplies; + supplies.lead = story_lead_after_brock(); + BattleDecisions decisions(supplies, BattleKind::TRAINER); + for (int c = 0; c < 25; c++){ + const TurnAction action = decisions.turn(GREEN); + if (action.choice != TurnChoice::MOVE || action.slot != BOTTOM_LEFT_MOVE){ + return std::format("Expected Water Gun (slot 2) at turn {}.", c + 1); + } + } + if (decisions.turn(GREEN).slot != TOP_LEFT_MOVE || attacks_low_on_pp(supplies)){ + return "Expected Tackle once Water Gun is out of PP, with its 34 PP not low."; + } + for (int c = 0; c < 30; c++){ + decisions.turn(GREEN); + } + if (!attacks_low_on_pp(supplies)){ + return "Expected the attacks low on PP with 4 Tackles left."; + } + healed_by_nurse(supplies); + if (supplies.lead.moves[BOTTOM_LEFT_MOVE].pp != 25 || attacks_low_on_pp(supplies)){ + return "Expected the nurse to restore Water Gun's 25 PP."; + } + + BattleDecisions out(supplies, BattleKind::TRAINER); + out.turn(GREEN); + out.turn_done(TurnChoice::MOVE, TurnResult::NOT_DONE); + if (out.turn(GREEN).slot != TOP_LEFT_MOVE){ + return "Expected Tackle after the game said Water Gun has no PP left."; + } + + Supplies new_game; + BattleDecisions unknown(new_game, BattleKind::TRAINER); + if (unknown.turn(GREEN).slot != BOTTOM_LEFT_MOVE){ + return "Expected the bottom left slot while the moves aren't all known."; + } + return true; +} + +// Regression: the save console B left after Route 3 (2026-11-02) has +// Squirtle Lv16 with WATER GUN where TACKLE was and BUBBLE kept, as its +// summary shows. From the moves read, the battle uses Water Gun from the +// top left, then Bubble; never a Tackle it doesn't know, nor Bubble's slot +// for Water Gun. +UnitTestResult test_moves_from_summary(Logger&){ + const std::vector read{ + {.move = "water-gun", .pp = 25, .max_pp = 25}, + {.move = "tail-whip", .pp = 30, .max_pp = 30}, + {.move = "bubble", .pp = 30, .max_pp = 30}, + {.move = "withdraw", .pp = 40, .max_pp = 40}, + }; + Supplies supplies; + supplies.lead = member_from_summary("squirtle", 16, read); + if (attack_pp(supplies.lead) != 55){ + return std::format("Expected 55 PP in Water Gun and Bubble, got {}.", attack_pp(supplies.lead)); + } + BattleDecisions decisions(supplies, BattleKind::TRAINER); + struct Turns{ + size_t count; + size_t slot; + std::string move; + }; + const std::vector plan{ + {.count = 25, .slot = TOP_LEFT_MOVE, .move = "Water Gun"}, + {.count = 30, .slot = BOTTOM_LEFT_MOVE, .move = "Bubble"}, + // No damaging move left: a move with PP, so the turn isn't lost to "no PP left". + {.count = 1, .slot = 1, .move = "Tail Whip"}, + }; + size_t turn = 0; + for (const Turns& turns : plan){ + for (size_t c = 0; c < turns.count; c++){ + turn++; + const TurnAction action = decisions.turn(GREEN); + if (action.choice != TurnChoice::MOVE || action.slot != turns.slot){ + return std::format("Expected {} (slot {}) at turn {}, got slot {}.", turns.move, turns.slot, turn, action.slot); + } + } + } + + // Bite at Lv18 takes Tail Whip's slot, as the plan says. + PartyMember lead = member_from_summary("squirtle", 16, read); + const LearnDecision bite = learn_move(lead); + if (bite.move != std::optional("bite") || bite.forget_slot != std::optional(1)){ + return "Expected Bite offered over Tail Whip (slot 1) after the moves read."; + } + return true; +} + +// Moves read off a summary: all it knows even when fewer than four, a PP +// not read taken as half the full PP (the game colors it from half down), +// and the strongest damaging move once the plan's attacks are gone. +UnitTestResult test_summary_members(Logger&){ + struct Case{ + std::string name; + PartyMember member; + std::optional slot; + size_t pp; + }; + const std::vector cases{ + { + .name = "three moves read", + .member = member_from_summary("squirtle", 9, { + {.move = "tackle", .pp = 35, .max_pp = 35}, {.move = "tail-whip", .pp = 30, .max_pp = 30}, + {.move = "bubble", .pp = 30, .max_pp = 30}, + }), + .slot = 2, .pp = 65, + }, + { + .name = "Water Gun's PP not read", + .member = member_from_summary("squirtle", 16, { + {.move = "water-gun", .pp = -1, .max_pp = -1}, {.move = "tail-whip", .pp = 30, .max_pp = 30}, + {.move = "bubble", .pp = 30, .max_pp = 30}, {.move = "withdraw", .pp = 40, .max_pp = 40}, + }), + .slot = 0, .pp = 42, + }, + { + .name = "none of the plan's attacks", + .member = member_from_summary("wartortle", 40, { + {.move = "tail-whip", .pp = 30, .max_pp = 30}, {.move = "rapid-spin", .pp = 40, .max_pp = 40}, + {.move = "skull-bash", .pp = 15, .max_pp = 15}, {.move = "withdraw", .pp = 40, .max_pp = 40}, + }), + .slot = 2, .pp = 55, + }, + { + .name = "four moves not read, fewer known", + .member = with_moves("squirtle", {"tackle", "tail-whip", "bubble"}, 7), + .slot = std::nullopt, .pp = 65, + }, + }; + for (const Case& c : cases){ + const std::optional slot = attack_slot(c.member); + if (slot != c.slot || attack_pp(c.member) != c.pp){ + return std::format( + "{}: expected slot {} and {} PP in attacks, got slot {} and {}.", + c.name, c.slot ? std::to_string(*c.slot) : "none", c.pp, + slot ? std::to_string(*slot) : "none", attack_pp(c.member) + ); + } + } + return true; +} + + +// #211: Bite, not Water Gun, against the trainers whose parties resist +// Water Gun: the Cerulean rival's Bulbasaur, and Misty's Staryu and +// Starmie (Water, Psychic: Bite does twice). Once Bite is out of PP, +// Tackle (35, on Bulbasaur's lower Defense) over the resisted Water Gun +// (40 x 1.5 x 0.5); and the battle loop picks Bite against a known party, +// but not in a wild battle, which has its own foes (BattleData tests). +UnitTestResult test_attack_by_matchup(Logger&){ + PartyMember wartortle = grown_to(new_member("squirtle", 5), 20); + const std::vector bulbasaur{"bulbasaur"}; + const std::optional bite = 1; + const std::optional water_gun = BOTTOM_LEFT_MOVE; + if (move_names(wartortle) != std::vector{"tackle", "bite", "water-gun", "withdraw"}){ + return "Expected Wartortle Lv20 with Tackle, Bite, Water Gun, Withdraw, got " + joined(move_names(wartortle)) + "."; + } + struct Case{ + std::string name; + std::vector foes; + }; + const std::vector cases{ + {.name = "the rival's Bulbasaur", .foes = bulbasaur}, + {.name = "the Cerulean rival's party", .foes = trainer_party("TRAINER_RIVAL_CERULEAN_BULBASAUR")}, + {.name = "Misty's party", .foes = trainer_party("TRAINER_LEADER_MISTY")}, + }; + for (const Case& c : cases){ + const std::optional slot = attack_slot_against(wartortle, c.foes); + if (slot != bite){ + return std::format("{} ({}): expected Bite (slot 1), got slot {}.", c.name, joined(c.foes), slot ? std::to_string(*slot) : "none"); + } + } + const std::vector rival = trainer_party(story_trainer("CeruleanCity", "rival_cerulean").value_or("")); + if (rival != std::vector{"pidgeotto", "abra", "rattata", "bulbasaur"}){ + return "Expected the Cerulean rival's party from pret's sParty_RivalCeruleanBulbasaur, got " + joined(rival) + "."; + } + + PartyMember no_bite = wartortle; + no_bite.moves[1].pp = 0; + if (attack_slot_against(no_bite, bulbasaur) != TOP_LEFT_MOVE || attack_slot_against(no_bite, {"pidgeotto"}) != water_gun){ + return "Expected Tackle against Bulbasaur once Bite is out of PP, and Water Gun against Pidgeotto."; + } + + Supplies supplies; + supplies.lead = wartortle; + supplies.foes = bulbasaur; + BattleDecisions trainer(supplies, BattleKind::TRAINER); + if (trainer.turn(GREEN).slot != *bite || supplies.lead.moves[1].pp != 24){ + return "Expected the trainer battle's turn to use Bite against Bulbasaur, spending its PP."; + } + BattleDecisions wild(supplies, BattleKind::WILD_FIGHT); + supplies.potions = 5; + if (wild.turn(GREEN).slot != *water_gun){ + return "Expected a wild battle with nothing read to keep the plan's order (Water Gun), whatever foes are set."; + } + return true; +} + +// A trainer the data doesn't have, a species it doesn't have, and no foes +// at all get the plan's order: Water Gun first. +UnitTestResult test_attack_unknown_foe(Logger&){ + const PartyMember wartortle = grown_to(new_member("squirtle", 5), 20); + if (!trainer_party("TRAINER_NOBODY").empty() || story_trainer("Route24", "nobody")){ + return "Expected no party for a trainer the data doesn't have."; + } + const std::vector> unknown{{}, {"missingno"}, trainer_party("TRAINER_NOBODY")}; + for (const std::vector& foes : unknown){ + if (attack_slot_against(wartortle, foes) != attack_slot(wartortle) || attack_slot(wartortle) != BOTTOM_LEFT_MOVE){ + return "Expected the plan's order (Water Gun) against " + joined(foes) + "."; + } + } + return true; +} + +// Bite is learned when offered (Wartortle Lv19, pret's +// sWartortleLevelUpLearnset) over Tail Whip, else over Withdraw; never +// over Water Gun. +UnitTestResult test_bite_learned(Logger&){ + struct Case{ + std::string name; + std::vector moves; + size_t forget; + }; + const std::vector cases{ + {.name = "with Tail Whip", .moves = {"tackle", "tail-whip", "water-gun", "withdraw"}, .forget = 1}, + {.name = "Water Gun over Tackle, no Tail Whip", .moves = {"water-gun", "bubble", "tackle", "withdraw"}, .forget = 3}, + }; + for (const Case& c : cases){ + PartyMember member = with_moves("wartortle", c.moves, 18); + const LearnDecision decision = learn_move(member); + if (decision.move != "bite" || decision.forget_slot != c.forget){ + return std::format( + "{}: expected Bite over slot {}, got {} over slot {}.", c.name, c.forget, + decision.move.value_or("nothing"), decision.forget_slot ? std::to_string(*decision.forget_slot) : "none" + ); + } + } + return true; +} + + +// A fake evolution scene: B pressed while it shows "is evolving!" cancels +// the evolution, as in the game. +struct FakeEvolution{ + std::vector frames; + size_t evolving_from = 0; + size_t evolving_to = 0; +}; + +// Plays `scene` against the loop's rule (B at any screen it doesn't hold +// for): whether the evolution went through. +bool evolves_against_loop(const FakeEvolution& scene, const EvolutionHold& hold){ + bool cancelled = false; + for (size_t frame = 0; frame < scene.frames.size(); frame++){ + const bool pressed_b = !hold.holds(scene.frames[frame]); + if (pressed_b && frame >= scene.evolving_from && frame < scene.evolving_to){ + cancelled = true; + } + } + return !cancelled; +} + +// Regression: Squirtle stayed Lv16 on console B (2026-11-02), the B +// presses after the battle cancelling its evolution. No B while "What? +// SQUIRTLE is evolving!" shows; B again for the arrow after it. +UnitTestResult test_no_b_during_evolution(Logger&){ + const BattleTextScreen in_battle{.text_box = true, .hp_box = true, .arrow = false, .yes_no = false}; + const BattleTextScreen evolving{.text_box = true, .hp_box = false, .arrow = false, .yes_no = false}; + const BattleTextScreen congratulations{.text_box = true, .hp_box = false, .arrow = true, .yes_no = false}; + const BattleTextScreen learn_prompt{.text_box = true, .hp_box = false, .arrow = false, .yes_no = true}; + FakeEvolution scene; + scene.frames = {in_battle, in_battle, congratulations}; + scene.frames.insert(scene.frames.begin() + 2, 40, evolving); + scene.evolving_from = 2; + scene.evolving_to = 42; + + PartyMember lead = with_moves("squirtle", {"tackle", "tail-whip", "bubble", "withdraw"}, 13); + EvolutionHold hold(lead); + hold.turn_taken(TurnChoice::MOVE); + if (!evolves_against_loop(scene, hold)){ + return "B was pressed during \"is evolving!\": the evolution would be cancelled."; + } + if (hold.holds(congratulations) || hold.holds(learn_prompt)){ + return "Expected B (or the prompt's answer) for the text with an arrow and the YES/NO after the evolution."; + } + + hold.held(1s, false); + if (lead.species != "squirtle"){ + return "A text box held for 1 s was taken for an evolution."; + } + hold.held(15s, false); + if (lead.species != "wartortle"){ + return "Expected Squirtle to be Wartortle after 15 s of its evolution screen, got " + lead.species + "."; + } + hold.held(40s, false); + if (hold.holds(evolving)){ + return "Expected no more holding once a battle's holds reach their cap."; + } + + PartyMember other = new_member("squirtle", 5); + EvolutionHold before_turn(other); + if (before_turn.holds(evolving)){ + return "Held before the first turn, where Oak's text box needs B."; + } + return true; +} + +// A poll of the battle loop: what it read, at `ms` from the start. +struct LoopPoll{ + int ms; + BattleTextScreen screen; + bool menu = false; +}; + +// Regression: console B, 2026-11-03, Mt. Moon B2F: RUN, "Got away +// safely!", then the cave corridor, whose black lower half reads as the +// battle's text box with no HP box. The loop held B for an evolution for +// a minute, then pressed A and B for 9 minutes. After RUN nothing is held, +// and START looks for the overworld within seconds of the last HP box. +UnitTestResult test_run_then_overworld(Logger&){ + const BattleTextScreen menu_screen{.text_box = true, .hp_box = true, .arrow = false, .yes_no = false}; + const BattleTextScreen got_away{.text_box = true, .hp_box = true, .arrow = true, .yes_no = false}; + const BattleTextScreen dark_cave{.text_box = true, .hp_box = false, .arrow = false, .yes_no = false}; + std::vector polls{{.ms = 0, .screen = menu_screen, .menu = true}}; + for (int ms = 300; ms <= 1500; ms += 300){ + polls.push_back({.ms = ms, .screen = got_away}); + } + for (int ms = 1800; ms <= 60000; ms += 300){ + polls.push_back({.ms = ms, .screen = dark_cave}); + } + + Supplies supplies; + BattleDecisions decisions(supplies, BattleKind::WILD_RUN); + EvolutionHold hold(supplies.lead); + BattleEndWatch watch; + const WallClock start = current_time(); + const TurnChoice choice = decisions.turn(PartyStatus{.hp_seen = true}).choice; + if (choice != TurnChoice::RUN){ + return "Expected RUN from a wild Pokemon."; + } + hold.turn_taken(choice); + for (const LoopPoll& poll : polls){ + const WallClock now = start + std::chrono::milliseconds(poll.ms); + if (hold.holds(poll.screen)){ + return std::format("Held B for an evolution at {} ms, after RUN.", poll.ms); + } + const bool battle = poll.screen.hp_box || poll.screen.yes_no; + watch.seen(poll.menu ? BattleSeen::MENU : battle ? BattleSeen::BATTLE : BattleSeen::NONE, now); + if (watch.check_overworld(now)){ + // The last HP box at 1.5 s; START within the next 3.5 s. + if (poll.ms > 5000){ + return std::format("START first looked for the overworld at {} ms.", poll.ms); + } + return true; + } + } + return "START never looked for the overworld in the dark cave."; +} + +// START only once the battle is gone for a while, and then not at every +// poll; A and B blind for at most 30 s since the last battle menu. +UnitTestResult test_end_watch_timing(Logger&){ + const WallClock start = current_time(); + const auto at = [&](int ms){ return start + std::chrono::milliseconds(ms); }; + BattleEndWatch watch; + if (watch.check_overworld(at(10000))){ + return "Looked for the overworld before any battle screen showed."; + } + for (int ms = 0; ms <= 20000; ms += 300){ + watch.seen(BattleSeen::BATTLE, at(ms)); + if (watch.check_overworld(at(ms))){ + return std::format("Looked for the overworld at {} ms with an HP box on screen.", ms); + } + } + int checks = 0; + for (int ms = 20100; ms <= 32000; ms += 300){ + watch.seen(BattleSeen::NONE, at(ms)); + checks += watch.check_overworld(at(ms)) ? 1 : 0; + } + if (checks < 2 || checks > 4){ + return std::format("Expected START every 3 s for 12 s without the battle, got {} looks.", checks); + } + for (int ms = 0; ms < 30000; ms += 1500){ + if (watch.pressed_blind(at(40000 + ms))){ + return std::format("Gave up pressing blind after {} ms.", ms); + } + } + if (!watch.pressed_blind(at(70000))){ + return "Expected to give up after 30 s of blind presses."; + } + watch.seen(BattleSeen::MENU, at(71000)); + if (watch.pressed_blind(at(72000))){ + return "Expected the battle menu to start the blind presses' time over."; + } + return true; +} + + +} + + +// The lead console B took into Super Nerd Miguel's battle (2026-11-03, +// Mt. Moon B2F), as its summary read before the run. +PartyMember squirtle_before_miguel(){ + return member_from_summary("squirtle", 16, { + {.move = "water-gun", .pp = 25, .max_pp = 25}, + {.move = "tail-whip", .pp = 30, .max_pp = 30}, + {.move = "bubble", .pp = 30, .max_pp = 30}, + {.move = "withdraw", .pp = 40, .max_pp = 40}, + }); +} + +// Regression, console B 2026-11-03: in the trainer's battle before the +// Rocket Grunt, a YES/NO read at a level-up (Lv17: no move to learn) got +// the plan's YES for Bite over Tail Whip, and no move list followed. The +// story still took Tail Whip as Bite, and in Miguel's battle chose it as +// its attack for 7 turns, until the starter fainted. The moves change only +// once the move list was seen. +UnitTestResult test_yes_no_without_move_list(Logger&){ + Supplies supplies; + supplies.lead = squirtle_before_miguel(); + BattleDecisions decisions(supplies, BattleKind::TRAINER); + decisions.turn(GREEN); + const PromptAnswer answer = decisions.prompt(false); + if (answer.answer != YesNo::YES || answer.forget_slot != std::optional(1)){ + return "Expected the plan's YES, Bite over Tail Whip (slot 1)."; + } + const std::vector before{"water-gun", "tail-whip", "bubble", "withdraw"}; + if (move_names(supplies.lead) != before){ + return "Expected the moves unchanged with no move list seen, got " + joined(move_names(supplies.lead)) + "."; + } + const std::vector after{"water-gun", "bite", "bubble", "withdraw"}; + if (!answer.learned || move_names(*answer.learned) != after){ + return "Expected the lead to keep once the move list shows to have Bite over Tail Whip."; + } + return true; +} + +// Regression, console B 2026-11-03, Super Nerd Miguel (pret +// sParty_SuperNerdMiguel: Grimer Lv12, whose moves include Disable): after +// turn 1, Water Gun was turned down 17 times with no turn passing, and +// each try spent a PP of the story's count. Turned down once, it is left +// alone for as long as Disable lasts, its PP given back, and Bubble (not +// Tail Whip) attacks meanwhile. +UnitTestResult test_disabled_move(Logger&){ + Supplies supplies; + supplies.lead = squirtle_before_miguel(); + supplies.foes = {"grimer", "voltorb", "koffing"}; + BattleDecisions decisions(supplies, BattleKind::TRAINER); + if (decisions.turn(GREEN).slot != TOP_LEFT_MOVE || decisions.turn(GREEN).slot != TOP_LEFT_MOVE){ + return "Expected Water Gun (slot 0) at turns 1 and 2."; + } + decisions.turn_done(TurnChoice::MOVE, TurnResult::REFUSED); + if (supplies.lead.moves[TOP_LEFT_MOVE].pp != 24){ + return std::format("Expected Water Gun at 24 PP after one turn and one refused, got {}.", supplies.lead.moves[TOP_LEFT_MOVE].pp); + } + for (int c = 0; c < 5; c++){ + const TurnAction action = decisions.turn(GREEN); + if (action.choice != TurnChoice::MOVE || action.slot != BOTTOM_LEFT_MOVE){ + return std::format("Expected Bubble (slot 2) at turn {} after Water Gun was turned down, got slot {}.", c + 1, action.slot); + } + } + if (decisions.turn(GREEN).slot != TOP_LEFT_MOVE){ + return "Expected Water Gun again once Disable is over."; + } + return true; +} + +// The loop's view of a move turned down (console B, 2026-11-03): the move +// list back (no battle screen) and the battle menu 5.7 s after the choice. +// Not a turn (8.3 s and up, with no move list), nor a menu long after one +// (a YES/NO's presses, 25 s). +UnitTestResult test_move_refusal_watch(Logger&){ + const WallClock start = current_time(); + MoveRefusalWatch watch; + watch.move_chosen(start); + watch.no_battle_screen(); + if (!watch.refused(start + 5700ms)){ + return "Expected the move list then the menu at 5.7 s read as the move turned down."; + } + watch.move_chosen(start); + if (watch.refused(start + 5000ms)){ + return "Expected no refusal without the move list between."; + } + watch.move_chosen(start); + watch.no_battle_screen(); + if (watch.refused(start + 25000ms)){ + return "Expected no refusal for a menu 25 s after the choice."; + } + watch.no_battle_screen(); + if (watch.refused(start + 26000ms)){ + return "Expected no refusal with no move chosen."; + } + return true; +} + +// Regression, console B 2026-11-03, Miguel's battle (m48): the move list +// opened after YES to "Delete a move to make room for BITE?", and closed +// with no move forgotten, so the game asked "Stop learning BITE?" where +// the story expected the next move's "Delete a move?". NO there and YES +// at "Delete a move?" went round 13 times (75 s), until presses by time +// ended it. A YES/NO right after the move list is "Stop learning?": YES, +// and the lead keeps its moves. +UnitTestResult test_move_list_closed(Logger&){ + enum class Prompt{DELETE, STOP}; + Supplies supplies; + supplies.lead = squirtle_before_miguel(); + BattleDecisions decisions(supplies, BattleKind::TRAINER); + decisions.turn(GREEN); + Prompt prompt = Prompt::DELETE; + for (int answers = 1; answers <= 8; answers++){ + const PromptAnswer answer = decisions.prompt(false); + if (answer.learned){ + // The move list showed, as the loop saw it. + supplies.lead = *answer.learned; + } + if (prompt == Prompt::STOP && answer.answer == YesNo::YES){ + const std::vector before{"water-gun", "tail-whip", "bubble", "withdraw"}; + if (move_names(supplies.lead) != before){ + return "Expected the moves as before Bite was offered, got " + joined(move_names(supplies.lead)) + "."; + } + return true; + } + // The move list closes with nothing forgotten: "Stop learning?", + // as after NO; NO there asks "Delete a move?" again. + prompt = prompt == Prompt::DELETE ? Prompt::STOP : Prompt::DELETE; + } + return "Expected the move prompts to end within 8 answers."; +} + +// However the YES/NOs come, a few after a turn are all the move prompts +// can be (two moves offered, NO then YES each); after those, YES only, +// which ends either prompt ("Delete a move?": the move list, which the +// loop's B closes; "Stop learning?": done), and the moves stay as they are. +UnitTestResult test_move_prompts_bounded(Logger&){ + Supplies supplies; + supplies.lead = with_moves("wartortle", {"tackle", "bite", "water-gun", "withdraw"}, 19); + BattleDecisions decisions(supplies, BattleKind::TRAINER); + decisions.turn(GREEN); + for (int answers = 1; answers <= 12; answers++){ + const PromptAnswer answer = decisions.prompt(false); + if (answers > 4 && (answer.answer != YesNo::YES || answer.forget_slot)){ + return std::format("Expected a plain YES at the move prompt {} after a turn.", answers); + } + } + const std::vector moves{"tackle", "bite", "water-gun", "withdraw"}; + if (move_names(supplies.lead) != moves){ + return "Expected the moves unchanged, got " + joined(move_names(supplies.lead)) + "."; + } + return true; +} + +// Regression, console B 2026-11-03, before Miguel (m48): yellow HP +// (17/55) and no Potion left, and the story went into the battle, as the +// nurse was only for red HP. After the items, the nurse for any HP not +// green, a status, or attacks low on PP. +UnitTestResult test_nurse_before_battle(Logger&){ + Supplies supplies; + supplies.lead = squirtle_before_miguel(); + if (nurse_before_battle(supplies)){ + return "Expected no nurse with green HP, no status and full PP."; + } + supplies.hurt = true; + if (!nurse_before_battle(supplies)){ + return "Expected the nurse for yellow HP that no Potion healed."; + } + supplies.hurt = false; + supplies.status = StatusCondition::OTHER; + if (!nurse_before_battle(supplies)){ + return "Expected the nurse for a status no item cured."; + } + return true; +} + +void add_tests_AutoStoryParty(UnitTestDatabase& database){ + database.add("movesets the game gives and the story plays", test_movesets); + database.add("move offered and slot forgotten", test_learn_prompts); + database.add("YES/NO answers to move prompts", test_prompt_answers); + database.add("fainted lead runs or sends the next member", test_fainted_lead); + database.add("PP: preferred attack, then Tackle; nurse restores", test_pp); + database.add("moves read off the summary, Water Gun over Tackle", test_moves_from_summary); + database.add("summary members: fewer moves, unread PP, strongest attack", test_summary_members); + database.add("no B during an evolution", test_no_b_during_evolution); + database.add("RUN, then a dark cave: no evolution wait, START soon", test_run_then_overworld); + database.add("battle end: START after the battle is gone, A and B for 30 s at most", test_end_watch_timing); + database.add("attacks by matchup: Bite on the rival's Bulbasaur and Misty", test_attack_by_matchup); + database.add("attacks against an unknown foe: the plan's order", test_attack_unknown_foe); + database.add("Bite learned over Tail Whip or Withdraw", test_bite_learned); + database.add("a YES/NO with no move list after it changes no move", test_yes_no_without_move_list); + database.add("a disabled move: left alone while Disable lasts, PP back", test_disabled_move); + database.add("a move turned down: the move list, then the menu sooner than a turn", test_move_refusal_watch); + database.add("the move list closed with nothing forgotten: YES to \"Stop learning?\"", test_move_list_closed); + database.add("move prompts after a turn: a plain YES after the first few", test_move_prompts_bounded); + database.add("the nurse before a battle for HP not green with no Potion", test_nurse_before_battle); + add_tests_AutoStoryBattleData(database); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp new file mode 100644 index 0000000000..6410a0710c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -0,0 +1,395 @@ +/* AutoStory Simulation Tests + * + * From: https://github.com/PokemonAutomation/ + * + * A run of the whole story table, new game to the Boulder Badge, without + * the console: story_checkpoints() built into engine checkpoints by the + * shared builder, saving at each end as the program does, run by the + * shared runner with the program's retry policy, against a fake game. + * The fake plans each ROUTE on the story maps from where the run's pose + * says we stand (turning to a wall when the facing is unknown, as the + * program does), walks each LEGS on them, steps onto triggers, and passes + * every other step unless told to fail it. + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +using Pokemon::Outcome; +using Pokemon::RunState; + +std::string joined(const std::vector& lines){ + std::string text; + for (const std::string& line : lines){ + text += "\n " + line; + } + return text; +} + +const MapData* map_named(const std::string& name){ + for (const MapData& map : story_maps()){ + if (map.name == name){ + return ↦ + } + } + return nullptr; +} + +// Whether the player, at the end of a WALK `step`, stops there holding on: +// the map's edge, a wall, or water to Surf onto, but no warp of any kind, +// even one to a map that isn't loaded. +bool stops_past_end(const RouteStep& step){ + const MapData& map = *map_named(step.end.map); + const TilePos here = step.end.point; + const TilePos ahead = here.next(step.direction); + if (!in_bounds(map, ahead)){ + return true; + } + if (warps_on_step(map, ahead) || exit_mat(map, here) == step.direction + || (step.direction == Direction::NORTH && is_door(map, ahead)) + ){ + return false; + } + const StepKind kind = classify_step(map, PlayerState{here, elevation_at(map, here), step.surfing}, step.direction); + return kind == StepKind::BLOCKED || kind == StepKind::START_SURF; +} + +// The first leg of `route` to a wall that holding on would carry past its +// end, or nothing (console B, 2026-11-02: one rode Route 4's Pokemon +// Center escalator). +std::optional overrun_wall_leg(const std::vector& route){ + for (const RouteStep& step : route){ + if (step.to_wall && !stops_past_end(step)){ + return to_string(step); + } + } + return std::nullopt; +} + +// Where the run stands, with a facing: a wall beside it when unknown. +struct Standing{ + MapPosition position; + Direction facing = Direction::NORTH; + std::string error; +}; +Standing standing(const Pokemon::Pose& pose){ + const std::optional at = story_pose(pose); + if (!at){ + return {{}, Direction::NORTH, "no one-tile pose: " + Pokemon::to_string(pose)}; + } + std::optional facing = at->facing; + if (!facing){ + const MapData* map = map_named(at->map); + facing = map ? wall_beside(*map, at->tile) : std::nullopt; + } + if (!facing){ + return {{}, Direction::NORTH, "facing unknown and no wall beside " + to_string(MapPosition{at->map, at->tile})}; + } + return {{at->map, at->tile}, *facing, ""}; +} + +class FakeGame : public Pokemon::StoryStepExecutor{ +public: + struct Failure{ + std::string failure; + size_t times = 0; + }; + + std::vector trace; + std::map failures; + // What the Mart sold, by its list's names. + std::map bag; + + virtual void begin_attempt(const Pokemon::StoryCheckpoint& data) override{ + m_row = data.id; + trace.push_back("begin " + data.id); + } + virtual Outcome run(RunState& state, const StoryStep& step) override{ + const std::string key = m_row + "/" + step.name; + trace.push_back(key); + auto failure = failures.find(key); + if (failure != failures.end() && failure->second.times > 0){ + failure->second.times--; + return Pokemon::outcome_failed(failure->second.failure, key); + } + return Pokemon::StoryStepExecutor::run(state, step); + } +protected: + virtual Outcome route(RunState& state, const StoryStep& step) override{ + return walk_to(state.pose, step); + } + virtual Outcome legs(RunState& state, const StoryStep& step) override{ + const Standing at = standing(state.pose); + if (!at.error.empty()){ + return Pokemon::outcome_failed("no_pose", at.error); + } + const std::optional> route = fixed_route(story_maps(), at.position, step.legs); + if (!route || route->empty()){ + return Pokemon::outcome_failed("bad_legs", to_string(at.position)); + } + return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after})); + } + virtual Outcome step(RunState& state, const StoryStep& step) override{ + const std::optional at = story_pose(state.pose); + if (!at){ + return Pokemon::outcome_failed("no_pose", Pokemon::to_string(state.pose)); + } + return Pokemon::outcome_ok(to_pose(StoryPose{at->map, at->tile.next(step.direction), step.direction})); + } + // The nurse's way must plan too, but the run goes on from where it stands. + virtual Outcome ready(RunState& state, const StoryStep& step) override{ + const Outcome to_nurse = walk_to(state.pose, step); + return to_nurse.succeeded() ? Pokemon::outcome_ok() : to_nurse; + } + virtual Outcome new_game(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + virtual Outcome options(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + virtual Outcome talk(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + virtual Outcome answer(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + virtual Outcome mash(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + virtual Outcome battle(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + virtual Outcome heal(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + // The Viridian Mart's list as the game shows it. After a purchase the + // cursor stays on the row bought (console B, 2026-11-01), so each + // order moves it from there, as buy_items() does since ad5d40885. + virtual Outcome shop(RunState&, const StoryStep& step) override{ + static const std::vector LIST{"poke_ball", "potion", "antidote", "parlyz_heal", "cancel"}; + const std::optional> orders = viridian_mart_orders(step.items); + if (!orders){ + return Pokemon::outcome_failed("unknown_item", step.name); + } + int cursor = 0; + for (size_t c = 0; c < orders->size(); c++){ + const MartOrder& order = (*orders)[c]; + // The presses: down or up from where the cursor is. + cursor += order.row - cursor; + if (cursor < 0 || cursor >= (int)LIST.size() || LIST[cursor] == "cancel"){ + return Pokemon::outcome_failed("mart_cancel", std::format("order {} ends on row {}", c + 1, cursor + 1)); + } + if (LIST[cursor] != step.items[c].item){ + return Pokemon::outcome_failed("wrong_item", std::format("{} instead of {}", LIST[cursor], step.items[c].item)); + } + bag[LIST[cursor]] += order.quantity; + } + return Pokemon::outcome_ok(); + } + +private: + Outcome walk_to(const Pokemon::Pose& pose, const StoryStep& step){ + const Standing at = standing(pose); + if (!at.error.empty()){ + return Pokemon::outcome_failed("no_pose", at.error); + } + const std::optional target = story_pose(*step.target); + const RouteGoal goal{{target->map, target->tile}, target->facing}; + const std::optional> route = plan_overworld_route( + story_maps(), at.position, goal, default_route_costs(), at.facing + ); + if (!route){ + return Pokemon::outcome_failed("no_route", to_string(at.position) + " to " + to_string(goal.position)); + } + const MapPosition end = follow_overworld_route(story_maps(), at.position, *route); + if (!(end == goal.position)){ + return Pokemon::outcome_failed("wrong_end", to_string(end)); + } + if (const std::optional leg = overrun_wall_leg(*route)){ + return Pokemon::outcome_failed("wall_overrun", *leg); + } + const Direction facing = route->empty() ? at.facing : route->back().facing_after; + return Pokemon::outcome_ok(to_pose(StoryPose{target->map, target->tile, facing})); + } + + std::string m_row; +}; + + +// One simulated run, segment built as the program builds it: each +// checkpoint saves at its end (hooks.save stands for save_game()). +struct Simulation{ + FakeGame game; + std::vector lines; + // Where each save stood: the end of its checkpoint. + std::vector> saves; + Pokemon::SegmentPolicy policy; + + // A language no reader supports, so a step that needed text would show. + Pokemon::SegmentReport run(const Pokemon::SegmentRange& range){ + game.set_language(Language::Japanese); + Pokemon::Segment segment; + segment.id = "00"; + for (const StoryCheckpoint& data : story_checkpoints()){ + segment.checkpoints.push_back(Pokemon::CheckpointSpec{ + .id = data.id, .title = data.title, .saves = true, + .build = [this, &data]{ return Pokemon::build_story_checkpoint(data, game); }, + }); + } + Pokemon::SegmentHooks hooks; + hooks.save = [this](RunState& state){ + game.trace.push_back("save"); + saves.emplace_back(last_begun(), state.pose); + return Pokemon::outcome_ok(); + }; + hooks.reload = [this](RunState&){ + game.trace.push_back("reload"); + return Pokemon::outcome_ok(); + }; + hooks.log = [this](const std::string& line){ lines.push_back(line); }; + RunState state; + return Pokemon::run_segment(state, segment, range, policy, hooks); + } + std::string last_begun() const{ + for (auto it = game.trace.rbegin(); it != game.trace.rend(); ++it){ + if (it->starts_with("begin ")){ + return it->substr(6); + } + } + return ""; + } + std::vector begun() const{ + std::vector ids; + for (const std::string& item : game.trace){ + if (item.starts_with("begin ")){ + ids.push_back(item.substr(6)); + } + } + return ids; + } + size_t count(const std::string& item) const{ + return (size_t)std::count(game.trace.begin(), game.trace.end(), item); + } +}; + + +class Test_AutoStorySimulation : public UnitTest{ +public: + Test_AutoStorySimulation(std::string name, std::function body) + : UnitTest("PokemonFRLG::AutoStory - Simulation: " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + + +UnitTestResult test_whole_story(){ + Simulation sim; + const Pokemon::SegmentReport report = sim.run({}); + if (!report.completed){ + return "Expected the whole story through:" + joined(sim.lines); + } + std::vector ids; + for (const StoryCheckpoint& data : story_checkpoints()){ + ids.push_back(data.id); + } + if (sim.begun() != ids || sim.saves.size() != ids.size()){ + return "Expected each checkpoint once, in order, each saving at its end:" + joined(sim.game.trace); + } + // Each checkpoint starts where the save before it stands. + for (size_t c = 1; c < story_checkpoints().size(); c++){ + const StoryCheckpoint& data = story_checkpoints()[c]; + const std::optional start = story_pose(*data.start); + const std::optional saved = story_pose(sim.saves[c - 1].second); + const bool same = start && saved && start->map == saved->map && start->tile == saved->tile + && (!start->facing || start->facing == saved->facing); + if (!same){ + return std::format("{} starts at {}, but {} saved at {}.", data.id, + Pokemon::to_string(*data.start), sim.saves[c - 1].first, Pokemon::to_string(sim.saves[c - 1].second)); + } + } + if (report.one_shot_passes() != report.checkpoints_run){ + return "Expected every checkpoint one-shot:" + joined(sim.lines); + } + // 00.07's shopping, with the cursor staying on each row bought. + const std::map bought{{"potion", 5}, {"antidote", 3}, {"parlyz_heal", 1}}; + if (sim.game.bag != bought){ + std::string text; + for (const auto& item : sim.game.bag){ + text += std::format(" {} {}", item.second, item.first); + } + return "Expected 5 Potions, 3 Antidotes and 1 Parlyz Heal; bought" + text + "."; + } + return true; +} + +UnitTestResult test_start_and_end(){ + Simulation sim; + const Pokemon::SegmentReport report = sim.run({.from = "00.05", .to = "00.07"}); + if (!report.completed || sim.begun() != std::vector{"00.05", "00.06", "00.07"}){ + return "Expected 00.05 to 00.07 only:" + joined(sim.begun()); + } + return true; +} + +// A walk that fails once (a trainer the walker could not recover from): +// the checkpoint reloads its last save and runs again from its start. +UnitTestResult test_retry_from_save(){ + Simulation sim; + sim.game.failures["00.08/forest_north"] = {.failure = "operation_failed", .times = 1}; + const Pokemon::SegmentReport report = sim.run({.from = "00.08", .to = "00.09"}); + if (!report.completed || report.reloads != 1 || sim.begun() != std::vector{"00.08", "00.08", "00.09"} + || sim.count("00.08/forest_east") != 2 + ){ + return "Expected 00.08 reloaded once and run again from its start:" + joined(sim.game.trace); + } + if (std::find(sim.lines.begin(), sim.lines.end(), "[Checkpoint] 00.08: passed on attempt 2 (1 reset)") == sim.lines.end()){ + return "Expected the retried pass logged:" + joined(sim.lines); + } + return true; +} + +// Brock's battle lost every time: three attempts, then the stop. +UnitTestResult test_gives_up_after_attempts(){ + Simulation sim; + sim.game.failures["00.09/brock"] = {.failure = "blackout", .times = 10}; + const Pokemon::SegmentReport report = sim.run({.from = "00.09", .to = std::nullopt}); + if (report.completed || report.reloads != 2 || report.failed_checkpoint != "00.09" || report.failed_event != "brock" + || report.failure.failure != "blackout" || sim.count("00.09/brock") != 3 || !sim.saves.empty() + ){ + return "Expected 00.09 tried 3 times, then a stop on Brock:" + joined(sim.game.trace) + joined(sim.lines); + } + return true; +} + +} + + +void add_tests_AutoStorySimulation(UnitTestDatabase& database){ + const auto add = [&](std::string name, UnitTestResult (*body)()){ + database.add(std::move(name), body); + }; + add("new game to Brock, in order, each start where the last save stood", test_whole_story); + add("start and end checkpoints", test_start_and_end); + add("a failed walk reloads its checkpoint's save", test_retry_from_save); + add("a battle lost every time stops after 3 attempts", test_gives_up_after_attempts); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp new file mode 100644 index 0000000000..bfc466a410 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp @@ -0,0 +1,153 @@ +/* AutoStory Summary + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "CommonFramework/Tools/DebugDumper.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_PartyDialogs.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_StatsReader.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" +#include "PokemonFRLG_AutoStorySummary.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace std::chrono_literals; + + +namespace{ + +void press(ProControllerContext& context, Button button){ + pbf_press_button(context, button, 160ms, 0ms); +} + +void tap(ProControllerContext& context, DpadPosition position, Milliseconds after = 400ms){ + pbf_press_dpad(context, position, 160ms, after); +} + +// Up to `timeout` for `watcher`'s screen, after a press. A screen that +// shows is given a moment to finish drawing before it is read. +bool wait_drawn(ConsoleHandle& console, ProControllerContext& context, VisualInferenceCallback& watcher, Milliseconds timeout){ + context.wait_for_all_requests(); + if (wait_until(console, context, timeout, {watcher}) < 0){ + return false; + } + pbf_wait(context, 500ms); + context.wait_for_all_requests(); + return true; +} + +// POKEMON SKILLS' stats, none unless all six read. +std::optional skills_stats(ConsoleHandle& console, Language language, const ImageViewRGB32& screen){ + PokemonFRLG_Stats read; + StatsReader().read_page2(console, language, screen, read); + if (!read.hp || !read.attack || !read.defense || !read.sp_attack || !read.sp_defense || !read.speed){ + return std::nullopt; + } + return Stats{ + .hp = static_cast(*read.hp), .attack = static_cast(*read.attack), + .defense = static_cast(*read.defense), .sp_attack = static_cast(*read.sp_attack), + .sp_defense = static_cast(*read.sp_defense), .speed = static_cast(*read.speed), + }; +} + +// From the party menu with the cursor on the member: its summary, read. +std::optional read_open_summary(ConsoleHandle& console, ProControllerContext& context, Language language){ + PartySelectionWatcher submenu(COLOR_RED); + press(context, BUTTON_A); + if (!wait_drawn(console, context, submenu, 5000ms)){ + console.log("Summary: the party member's menu didn't show.", COLOR_ORANGE); + return std::nullopt; + } + // SUMMARY, the menu's top row. + SummaryWatcher info(COLOR_RED); + press(context, BUTTON_A); + if (!wait_drawn(console, context, info, 5000ms)){ + console.log("Summary: the summary's first page didn't show.", COLOR_ORANGE); + return std::nullopt; + } + SummaryRead read; + { + VideoSnapshot screen = console.video().snapshot(); + if (!screen){ + return std::nullopt; + } + PokemonFRLG_Stats stats; + StatsReader().read_page1(console, language, screen, stats); + read.species = stats.name; + read.level = stats.level; + } + SummaryPage2Watcher skills(COLOR_RED); + tap(context, DPAD_RIGHT, 0ms); + if (!wait_drawn(console, context, skills, 3000ms)){ + console.log("Summary: POKEMON SKILLS didn't show.", COLOR_ORANGE); + return std::nullopt; + } + if (VideoSnapshot page = console.video().snapshot()){ + read.stats = skills_stats(console, language, page); + } + SummaryPage3Watcher moves(COLOR_RED); + tap(context, DPAD_RIGHT, 0ms); + if (!wait_drawn(console, context, moves, 3000ms)){ + console.log("Summary: KNOWN MOVES didn't show.", COLOR_ORANGE); + return std::nullopt; + } + VideoSnapshot screen = console.video().snapshot(); + if (!screen){ + return std::nullopt; + } + read.moves = read_summary_moves(console, language, screen); + dump_debug_image(console, "AutoStory/summary", "moves", screen); + return read; +} + +} + +std::optional read_party_summary( + ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language, size_t slot +){ + if (menu == StartMenu::BEFORE_POKEMON){ + return std::nullopt; + } + open_party_menu_from_overworld( + console, context, menu == StartMenu::BEFORE_POKEDEX ? StartMenuContext::NO_DEX : StartMenuContext::STANDARD + ); + context.wait_for_all_requests(); + // The party menu opens on the lead; DOWN steps through the slots. + for (size_t c = 0; c < slot; c++){ + tap(context, DPAD_DOWN); + } + const std::optional read = read_open_summary(console, context, language); + mash_until_overworld(console, context, 20000ms); + if (read){ + std::string moves; + for (const SummaryMove& move : read->moves){ + moves += std::format("{}{} {}/{}", moves.empty() ? "" : ", ", move.move, move.pp, move.max_pp); + } + const std::string stats = read->stats + ? std::format( + "{} HP, {}/{}/{}/{}/{}", read->stats->hp, read->stats->attack, read->stats->defense, + read->stats->sp_attack, read->stats->sp_defense, read->stats->speed + ) + : "stats not read"; + console.log(std::format( + "Summary of party slot {}: {} Lv{}, {}, {}.", + slot + 1, read->species.empty() ? "?" : read->species, + read->level ? std::to_string(*read->level) : "?", stats, moves.empty() ? "no moves read" : moves + )); + } + return read; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h new file mode 100644 index 0000000000..9839147e90 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h @@ -0,0 +1,57 @@ +/* AutoStory Summary + * + * From: https://github.com/PokemonAutomation/ + * + * Reading a party member's summary from the overworld: its species, + * level and moves, for the battles' move plan and the steps that check a + * level. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStorySummary_H +#define PokemonAutomation_PokemonFRLG_AutoStorySummary_H + +#include +#include +#include +#include +#include "CommonFramework/Language.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryDamage.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// A party member as its summary shows it. +struct SummaryRead{ + // The species' slug, empty if not read. + std::string species = {}; + std::optional level = std::nullopt; + // KNOWN MOVES, from the top, up to the first name not read. + std::vector moves = {}; + // POKEMON SKILLS (HP as its maximum), none unless all six were read. + std::optional stats = std::nullopt; +}; + +// From the overworld: the party menu, party slot `slot`'s SUMMARY, its +// first page (species, level), POKEMON SKILLS (stats) and KNOWN MOVES, +// then back to the overworld. +// Each screen is waited for before the next press: a press sent before a +// menu is drawn goes to what was there before (console B, 2026-11-02, the +// PC's menus). Nothing if a screen didn't show, or before the starter +// (`menu` has no POKEMON). +std::optional read_party_summary( + ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language, size_t slot +); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp new file mode 100644 index 0000000000..7db4cec429 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -0,0 +1,297 @@ +/* AutoStory Table + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +constexpr Direction NORTH = Direction::NORTH; +constexpr Direction SOUTH = Direction::SOUTH; +constexpr Direction EAST = Direction::EAST; +constexpr Direction WEST = Direction::WEST; + +const char* const BEDROOM = "PalletTown_PlayersHouse_2F"; +const char* const PALLET = "PalletTown"; +const char* const LAB = "PalletTown_ProfessorOaksLab"; +const char* const VIRIDIAN = "ViridianCity"; +const char* const VIRIDIAN_MART = "ViridianCity_Mart"; +const char* const VIRIDIAN_CENTER = "ViridianCity_PokemonCenter_1F"; +const char* const FOREST = "ViridianForest"; +const char* const FOREST_GATE = "Route2_ViridianForest_NorthEntrance"; +const char* const PEWTER = "PewterCity"; +const char* const PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; +const char* const GYM = "PewterCity_Gym"; + +Pokemon::Pose at(const char* map, int x, int y, std::optional facing = std::nullopt){ + return to_pose(StoryPose{map, {x, y}, facing}); +} + +StoryCheckpoint row( + std::string id, std::string title, std::optional start, + Supplies supplies, StartMenu menu, std::vector steps +){ + StoryCheckpoint checkpoint; + checkpoint.id = std::move(id); + checkpoint.title = std::move(title); + checkpoint.start = std::move(start); + checkpoint.steps = std::move(steps); + checkpoint.supplies = supplies; + checkpoint.menu = menu; + return checkpoint; +} + +// At the rows after Brock: no items counted, the starter with the moves +// the story gave it by Lv13. A run that loads a save reads the moves off +// the lead's summary instead (read_lead_moves()), so a save whose moves +// differ from these (console B, 2026-11-02: Water Gun where Tackle was) +// is fought with the moves it has. +Supplies after_brock(){ + Supplies supplies; + supplies.lead = story_lead_after_brock(); + return supplies; +} + +// What a walk does about wild Pokemon: runs, or fights them for EXP. +enum class WildBattles{ + RUN, + FIGHT, +}; + +StoryStep make(StoryStepKind kind, std::string name, std::string why){ + StoryStep step; + step.kind = kind; + step.name = std::move(name); + step.why = std::move(why); + return step; +} + +StoryStep route(std::string name, Pokemon::Pose target, std::string why, WildBattles wild = WildBattles::RUN){ + StoryStep step = make(StoryStepKind::ROUTE, std::move(name), std::move(why)); + step.target = std::move(target); + step.fight_wild = wild == WildBattles::FIGHT; + return step; +} + +StoryStep step_into(std::string name, Direction direction, std::string why){ + StoryStep step = make(StoryStepKind::STEP, std::move(name), std::move(why)); + step.direction = direction; + return step; +} + +StoryStep answer(std::string name, bool yes, std::string why){ + StoryStep step = make(StoryStepKind::ANSWER, std::move(name), std::move(why)); + step.yes = yes; + return step; +} + +StoryStep scene(std::string name, std::optional pose_after, std::string why){ + StoryStep step = make(StoryStepKind::MASH, std::move(name), std::move(why)); + step.pose_after = std::move(pose_after); + return step; +} + +StoryStep battle(std::string name, Pokemon::Pose pose_after, bool may_lose, std::string why){ + StoryStep step = make(StoryStepKind::BATTLE, std::move(name), std::move(why)); + step.pose_after = std::move(pose_after); + step.may_lose = may_lose; + return step; +} + +StoryStep legs(std::string name, std::vector legs, std::string why, WildBattles wild = WildBattles::RUN){ + StoryStep step = make(StoryStepKind::LEGS, std::move(name), std::move(why)); + step.legs = std::move(legs); + step.fight_wild = wild == WildBattles::FIGHT; + return step; +} + +// `step`, a ROUTE or LEGS, run with B held: from the Running Shoes on. No +// checkpoint after 00.10 is in the table yet. +[[maybe_unused]] StoryStep running(StoryStep step){ + step.variant = RUN_VARIANT; + return step; +} + +StoryStep new_game_intro(Pokemon::Pose pose_after, std::string why){ + StoryStep step = make(StoryStepKind::NEW_GAME, "intro", std::move(why)); + step.pose_after = std::move(pose_after); + return step; +} + +StoryStep talk(std::string name, std::string why){ + return make(StoryStepKind::TALK, std::move(name), std::move(why)); +} + +StoryStep ready(std::string name, Pokemon::Pose nurse, std::string why){ + StoryStep step = make(StoryStepKind::READY, std::move(name), std::move(why)); + step.target = std::move(nurse); + return step; +} + +StoryStep heal(std::string name){ + return make(StoryStepKind::HEAL, std::move(name), "full HP"); +} + +StoryStep shop(std::string name, std::vector items, std::string why){ + StoryStep step = make(StoryStepKind::SHOP, std::move(name), std::move(why)); + step.items = std::move(items); + return step; +} + + +StoryCheckpoint new_game(){ + return row("00.01", "new game to the bedroom", std::nullopt, {}, StartMenu::BEFORE_POKEMON, { + // new_game.c: the bedroom at (6, 6), facing the TV. + new_game_intro(at(BEDROOM, 6, 6, NORTH), "Oak's speech, BOY, default names, rival GREEN"), + make(StoryStepKind::OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon"), + }); +} + +StoryCheckpoint leave_house(){ + return row("00.02", "bedroom to Pallet Town", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, { + route("front_door", at(PALLET, 6, 8), "down the stairs and out of the house"), + }); +} + +StoryCheckpoint oaks_trigger(){ + return row("00.03", "Oak stops the player and walks them to the lab", at(PALLET, 6, 8, SOUTH), {}, StartMenu::BEFORE_POKEMON, { + route("below_oaks_trigger", at(PALLET, 12, 2, NORTH), "below the north exit, short of Oak's trigger at (12, 1)"), + step_into("oaks_trigger", NORTH, "the trigger: \"Don't go out!\""), + // PlayerEnter walks the player up 8 tiles from the lab's door. + scene("to_the_lab", at(LAB, 6, 4, NORTH), "Oak walks the player into the lab; the scene ends at the table"), + }); +} + +StoryCheckpoint starter(){ + return row("00.04", "Squirtle, then the rival's battle", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEDEX, { + route("below_squirtle", at(LAB, 9, 5, NORTH), "under Squirtle's ball (9, 4)"), + talk("squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\""), + answer("choose_squirtle", true, "take Squirtle"), + answer("no_nickname", false, "\"give a nickname?\" NO"), + scene("rival_takes_bulbasaur", at(LAB, 9, 5, NORTH), "the rival picks his ball; the player still faces the table (console B, 2026-11-01)"), + route("above_rival_trigger", at(LAB, 7, 7, SOUTH), "short of the rival's trigger row 8"), + step_into("rival_trigger", SOUTH, "\"Wait, let's check out our POKEMON!\""), + // The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down. + battle("rival_battle", at(LAB, 7, 8, SOUTH), true, "the tutorial battle; losing goes on too"), + }); +} + +StoryCheckpoint parcel(){ + return row("00.05", "Route 1 to Viridian Mart: Oak's Parcel", at(LAB, 7, 8, SOUTH), {}, StartMenu::BEFORE_POKEDEX, { + route("below_mart_door", at(VIRIDIAN, 36, 20, NORTH), "Route 1, running from wild battles"), + step_into("mart_door", NORTH, "the clerk's scene starts on entering"), + // ApproachCounter: up 4 from the mat, then faces the clerk. + scene("parcel_from_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "the clerk gives OAK'S PARCEL"), + }); +} + +StoryCheckpoint pokedex(){ + return row("00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, { + route("below_oak", at(LAB, 6, 4, NORTH), "back down Route 1 to Oak"), + talk("give_parcel", "Oak takes the parcel"), + scene("pokedex_scene", at(LAB, 6, 4, SOUTH), "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)"), + }); +} + +StoryCheckpoint shopping(){ + return row("00.07", "Viridian shopping, then into Viridian Forest", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { + route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again"), + // 2000 of the 3000 a new game starts with, plus the rival's prize. + shop("potions_and_antidotes", {{"potion", 5}, {"antidote", 3}, {"parlyz_heal", 1}}, "5 Potions, 3 Antidotes, 1 Parlyz Heal"), + route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest"), + heal("heal_viridian"), + route("below_old_man_trigger", at(VIRIDIAN, 20, 9, NORTH), "short of the tutorial trigger (20, 8)"), + step_into("old_man_trigger", NORTH, "the old man's catching tutorial can't be walked around"), + // TutorialTriggerLeft turns the player right, to the old man. + scene("old_man_tutorial", at(VIRIDIAN, 20, 8, EAST), "about 60 lines and his demo battle; TEACHY TV"), + // After his demo the old man stands east of the player, beside (20, 8), where + // the map doesn't have him: "east 2" from there didn't move, and the walk north + // ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first. + route("past_old_man", at(VIRIDIAN, 20, 5, NORTH), "north along column 20, clear of the old man"), + // The gate's north warp lands on the forest's exit mat (29, 62), facing + // north. The save there keeps a forest failure from going back to Pallet. + route("forest_entrance", at(FOREST, 29, 62, NORTH), "Route 2 and the south gate, running from wild battles"), + }); +} + +StoryCheckpoint forest(){ + // The supplies bought in 00.07. + return row("00.08", "Viridian Forest to Pewter Center", at(FOREST, 29, 62, NORTH), {5, 3, 1}, StartMenu::FULL, { + // Wild battles are fought for EXP. Straight up the east side from the + // entrance, each leg ending on a wall (the Boy at (45, 58) stops the + // east one). Rick (47, 45) sees (42..46, 45), so the last leg meets + // his battle and is held on to its wall after it. The by-hand run's + // detour west to (13, 46) and back is dropped. + legs("forest_east", {{EAST, 1}, {NORTH, 4}, {EAST, 14}, {NORTH, 15}}, "up the east side to (44, 43)", WildBattles::FIGHT), + route("forest_north", at(FOREST, 39, 25), "north part", WildBattles::FIGHT), + // To the gate by legs that end on walls, which the walker holds again + // after a battle instead of estimating where it stopped: planned + // routes with open legs lost the player in the north of the forest + // (console B, 2026-11-01). The two 1-tile legs are single steps. + legs("forest_exit", { + {NORTH, 10}, {WEST, 12}, {SOUTH, 10}, {WEST, 6}, {NORTH, 20}, + {SOUTH, 1}, {WEST, 10}, {SOUTH, 27}, {WEST, 8}, {NORTH, 20}, {EAST, 1}, + }, "walls all the way to the gate's column", WildBattles::FIGHT), + route("forest_gate", at(FOREST_GATE, 7, 10, NORTH), "north onto the exit, arriving on the gate's mat", WildBattles::FIGHT), + // Out of the forest, wild battles are run from; trainers are still fought. + route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center"), + heal("heal_pewter"), + }); +} + +StoryCheckpoint brock(){ + // The by-hand save: 2 Potions and 1 Antidote left after the forest. + return row("00.09", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { + // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight + // 4) and sees (4..7, 8): walking north up column 6 from the door, + // the step onto (6, 8) starts his battle. He walks up to the player, + // who stays put and keeps facing north (FRLG doesn't turn the player + // to a trainer). That step is taken on its own, so no leg is cut. + route("below_liam_line", at(GYM, 6, 9, NORTH), "in by the door, up column 6 to below Liam's row"), + step_into("liam_line", NORTH, "onto (6, 8), in Liam's line"), + battle("camper_liam", at(GYM, 6, 8, NORTH), false, "Geodude and Sandshrew; EXP before Brock"), + // On to Brock unless red HP or a status is left that no item cures. + ready("ready_for_brock", at(PEWTER_CENTER, 7, 4, NORTH), "items for a status or low HP; the nurse only if they can't"), + route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5); Liam, beaten, stands at (5, 8)"), + talk("challenge_brock", "Brock's speech"), + battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39"), + }); +} + +StoryCheckpoint running_shoes(){ + return row("00.10", "Pewter: the Running Shoes from Oak's aide", at(GYM, 6, 6, NORTH), after_brock(), StartMenu::FULL, { + // Brock's win sets VAR_MAP_SCENE_PEWTER_CITY to 1 and shows the aide at + // (46, 20); his triggers are (46, 21..23) (PewterCity map.json). The + // Gym guide's triggers at (42..43, 21..23) need the scene at 0. + route("before_aide_trigger", at(PEWTER, 45, 21, EAST), "out of the Gym, east along row 21, short of the top trigger"), + step_into("aide_trigger", EAST, "onto (46, 21), below the aide"), + // RunningShoesAideTriggerTop: the aide talks from (46, 20), no YES/NO; + // the player only turns up. He walks off and is removed; FLAG_SYS_B_DASH + // is set (console B, 2026-11-02: about 20 B presses to the overworld). + scene("shoes_from_aide", at(PEWTER, 46, 21, NORTH), "\"Oh, PLAYER!\" ... the Running Shoes; ends facing north"), + }); +} + +} + + +const std::vector& story_checkpoints(){ + static const std::vector checkpoints{ + new_game(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), + running_shoes(), + }; + return checkpoints; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h new file mode 100644 index 0000000000..d8a3f8b15d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -0,0 +1,37 @@ +/* AutoStory Table + * + * From: https://github.com/PokemonAutomation/ + * + * FireRed from a new game to the Boulder Badge and the Running Shoes, as + * story checkpoints 00.01 to 00.10, each saved at its end. After 00.10 + * every route and leg runs. Taken from a by-hand run on + * console B (2026-11-01) and the pokefirered map scripts. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryTable_H +#define PokemonAutomation_PokemonFRLG_AutoStoryTable_H + +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_AutoStoryEvents.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Checkpoints 00.01 to 00.10, in order. +const std::vector& story_checkpoints(); + + +void add_tests_AutoStory(UnitTestDatabase& database); +// The table run end to end against a fake game (PokemonFRLG_AutoStorySimulation_Tests.cpp). +void add_tests_AutoStorySimulation(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp new file mode 100644 index 0000000000..5a636778dd --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp @@ -0,0 +1,397 @@ +/* AutoStory Win Chance + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "PokemonFRLG_AutoStoryWinChance.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// A battle still going after this many turns counts as lost. +constexpr size_t MAX_TURNS = 100; +constexpr uint32_t CRIT_CHANCE = 16; +constexpr uint32_t HIGH_CRIT_CHANCE = 8; +constexpr int MAX_STAGE = 6; + +// sAccuracyStageRatios, -6 to +6, in hundredths. +constexpr uint32_t ACCURACY_RATIOS[] = {33, 36, 43, 50, 60, 75, 100, 133, 166, 200, 233, 266, 300}; + +const MoveData& data_of(std::string_view move){ + static const MoveData NONE; + const MoveData* data = move_data(move); + return data == nullptr ? NONE : *data; +} + +int8_t& stage(SimBattler& battler, Stage which){ + return battler.body.stages[static_cast(which)]; +} + +uint16_t eighth(const SimBattler& battler){ + return std::max(battler.body.stats.hp / 8, 1); +} + +void lose_hp(SimBattler& battler, uint32_t damage){ + battler.hp = static_cast(battler.hp > damage ? battler.hp - damage : 0); +} + +void gain_hp(SimBattler& battler, uint32_t heal){ + battler.hp = static_cast(std::min(battler.body.stats.hp, battler.hp + heal)); +} + +// "attack-down", "speed-up-2", "defense-down-hit": the stage, by how much +// and on whom. None for another effect. +struct StageChange{ + Stage stat = Stage::ATTACK; + int amount = 0; + bool on_user = false; +}; +std::optional stage_change(std::string_view effect){ + static const std::pair STATS[] = { + {"attack-", Stage::ATTACK}, {"defense-", Stage::DEFENSE}, {"speed-", Stage::SPEED}, + {"special-attack-", Stage::SP_ATTACK}, {"special-defense-", Stage::SP_DEFENSE}, + {"accuracy-", Stage::ACCURACY}, {"evasion-", Stage::EVASION}, + }; + for (const auto& [prefix, stat] : STATS){ + if (!effect.starts_with(prefix)){ + continue; + } + std::string_view rest = effect.substr(prefix.size()); + if (rest.ends_with("-hit")){ + rest.remove_suffix(4); + } + const bool up = rest.starts_with("up"); + if (!up && !rest.starts_with("down")){ + return std::nullopt; + } + const int amount = rest.ends_with("-2") ? 2 : 1; + return StageChange{.stat = stat, .amount = up ? amount : -amount, .on_user = up}; + } + return std::nullopt; +} + +void change_stage(SimBattler& user, SimBattler& target, std::string_view effect){ + if (const std::optional change = stage_change(effect)){ + int8_t& now = stage(change->on_user ? user : target, change->stat); + now = static_cast(std::clamp(now + change->amount, -MAX_STAGE, MAX_STAGE)); + } +} + + +// One battle, played once. +class SimBattle{ +public: + SimBattle(const SimBattler& own, int potions, const SimTrainer& trainer, std::mt19937& rng) + : m_own(own) + , m_potions(potions) + , m_trainer(trainer) + , m_rng(rng) + {} + + bool won(){ + for (size_t turn = 0; turn < MAX_TURNS; turn++){ + play_turn(); + if (m_own.hp == 0){ + return false; + } + if (foe().hp == 0 && !send_next()){ + return true; + } + } + return false; + } + +private: + SimBattler& foe(){ + return m_trainer.party[m_out]; + } + + size_t foes_left() const{ + return static_cast(std::ranges::count_if(m_trainer.party, [](const SimBattler& battler){ + return battler.hp > 0; + })); + } + + bool send_next(){ + if (foes_left() == 0){ + return false; + } + m_out = ai_next_foe(m_trainer.party, m_out, m_own); + return true; + } + + uint32_t random(uint32_t n){ + return static_cast(m_rng() % n); + } + + // The AI's move: the best score, ties at random. None with no PP left. + std::optional foe_move(){ + const std::vector scores = ai_move_scores(m_trainer, foe(), m_own, m_rng); + const int best = scores.empty() ? 0 : *std::ranges::max_element(scores); + std::vector ties; + for (size_t slot = 0; slot < scores.size(); slot++){ + if (best > 0 && scores[slot] == best){ + ties.push_back(slot); + } + } + if (ties.empty()){ + return std::nullopt; + } + return ties[random(static_cast(ties.size()))]; + } + + void play_turn(){ + const size_t left = foes_left(); + const OwnTurn own = own_turn(m_own, m_potions, foe(), m_trainer.items, left); + const std::optional item = ai_item_choice(foe(), m_trainer.items, left); + const std::optional foe_slot = item ? std::nullopt : foe_move(); + if (own.potion){ + gain_hp(m_own, POTION_HP); + m_potions--; + } + if (item){ + gain_hp(foe(), ai_item_hp(m_trainer.items[*item])); + m_trainer.items[*item].clear(); + } + const std::string own_move = own.potion ? "" : own.slot ? m_own.moves[*own.slot].move : "struggle"; + const std::string foe_used = item ? "" : foe_slot ? foe().moves[*foe_slot].move : "struggle"; + play_moves(own_move, own.slot, foe_used, foe_slot); + end_of_turn(); + } + + bool own_first(const std::string& own_move, const std::string& foe_used){ + const int own_priority = data_of(own_move).priority; + const int foe_priority = data_of(foe_used).priority; + if (own_priority != foe_priority){ + return own_priority > foe_priority; + } + const uint32_t own_speed = speed(m_own); + const uint32_t foe_speed = speed(foe()); + return own_speed != foe_speed ? own_speed > foe_speed : random(2) == 0; + } + + void play_moves(const std::string& own_move, std::optional own_slot, const std::string& foe_used, std::optional foe_slot){ + m_flinched = false; + const bool first = own_move.empty() || foe_used.empty() || own_first(own_move, foe_used); + if (first){ + use(m_own, foe(), own_move, own_slot, true); + use(foe(), m_own, foe_used, foe_slot, false); + }else{ + use(foe(), m_own, foe_used, foe_slot, true); + use(m_own, foe(), own_move, own_slot, false); + } + } + + static uint32_t speed(const SimBattler& battler){ + const uint32_t speed = staged_stat(battler.body.stats.speed, battler.body.stages[static_cast(Stage::SPEED)]); + return battler.status == SimStatus::PARALYSIS ? speed / 4 : speed; + } + + // Whether `user` gets to move: sleep, flinch, paralysis. + bool can_move(SimBattler& user, bool moves_first){ + if (user.status == SimStatus::SLEEP){ + if (--user.sleep > 0){ + return false; + } + user.status = SimStatus::NONE; + } + if (!moves_first && m_flinched){ + return false; + } + return user.status != SimStatus::PARALYSIS || random(4) != 0; + } + + bool hits(const SimBattler& user, const SimBattler& target, const MoveData& move){ + if (move.accuracy == 0){ + return true; + } + const int buff = std::clamp( + user.body.stages[static_cast(Stage::ACCURACY)] - target.body.stages[static_cast(Stage::EVASION)], + -MAX_STAGE, MAX_STAGE + ); + const uint32_t chance = move.accuracy * ACCURACY_RATIOS[buff + MAX_STAGE] / 100; + return random(100) + 1 <= chance; + } + + void use(SimBattler& user, SimBattler& target, const std::string& move_name, std::optional slot, bool moves_first){ + if (move_name.empty() || user.hp == 0 || target.hp == 0 || !can_move(user, moves_first)){ + return; + } + if (slot && user.moves[*slot].pp > 0){ + user.moves[*slot].pp--; + } + const MoveData& move = data_of(move_name); + if (!hits(user, target, move)){ + return; + } + if (move.power > 0){ + strike(user, target, move, moves_first); + }else{ + apply_status_move(user, target, move); + } + } + + uint32_t hit_count(const MoveData& move){ + if (move.effect == "double-hit" || move.effect == "twineedle"){ + return 2; + } + if (move.effect != "multi-hit"){ + return 1; + } + // Cmd_setmultihitcounter: 2 or 3 at 3/8 each, 4 or 5 at 1/8 each. + const uint32_t first = random(4); + return first > 1 ? random(4) + 2 : first + 2; + } + + uint32_t one_hit(const SimBattler& user, const SimBattler& target, const MoveData& move){ + if (move.effect == "super-fang"){ + return std::max(target.hp / 2, 1); + } + const bool crit = random(move.effect == "high-critical" ? HIGH_CRIT_CHANCE : CRIT_CHANCE) == 0; + const uint32_t before = damage_before_roll(user.body, target.body, move, crit); + return fixed_damage(move, user.body) ? before : rolled_damage(before, 100 - random(16)); + } + + void strike(SimBattler& user, SimBattler& target, const MoveData& move, bool moves_first){ + const uint32_t count = hit_count(move); + uint32_t dealt = 0; + for (uint32_t i = 0; i < count && target.hp > 0; i++){ + const uint32_t damage = std::min(one_hit(user, target, move), target.hp); + lose_hp(target, damage); + dealt += damage; + } + if (move.effect == "absorb"){ + gain_hp(user, std::max(dealt / 2, 1)); + } + if (dealt > 0 && target.hp > 0 && random(100) < move.effect_chance){ + secondary(user, target, move, moves_first); + } + } + + void secondary(SimBattler& user, SimBattler& target, const MoveData& move, bool moves_first){ + if (move.effect == "flinch-hit" || move.effect == "flinch-minimize-hit"){ + m_flinched = moves_first; + }else if (move.effect == "poison-hit"){ + set_status(target, SimStatus::POISON); + }else if (move.effect == "paralyze-hit"){ + set_status(target, SimStatus::PARALYSIS); + }else{ + change_stage(user, target, move.effect); + } + } + + void set_status(SimBattler& target, SimStatus status){ + if (target.status != SimStatus::NONE){ + return; + } + const bool poison_proof = target.body.first == PokemonType::POISON || target.body.second == PokemonType::POISON + || target.body.first == PokemonType::STEEL || target.body.second == PokemonType::STEEL; + if (status == SimStatus::POISON && poison_proof){ + return; + } + target.status = status; + if (status == SimStatus::SLEEP){ + target.sleep = static_cast(2 + random(4)); + } + } + + void apply_status_move(SimBattler& user, SimBattler& target, const MoveData& move){ + if (move.effect == "sleep"){ + set_status(target, SimStatus::SLEEP); + }else if (move.effect == "poison" || move.effect == "toxic"){ + set_status(target, SimStatus::POISON); + }else if (move.effect == "paralyze"){ + set_status(target, SimStatus::PARALYSIS); + }else if (move.effect == "leech-seed"){ + const bool grass = target.body.first == PokemonType::GRASS || target.body.second == PokemonType::GRASS; + target.seeded = target.seeded || !grass; + }else if (move.effect == "restore-hp" || move.effect == "softboiled"){ + gain_hp(user, user.body.stats.hp / 2); + }else{ + change_stage(user, target, move.effect); + } + } + + void end_of_turn(){ + for (SimBattler* battler : {&m_own, &foe()}){ + if (battler->hp > 0 && battler->status == SimStatus::POISON){ + lose_hp(*battler, eighth(*battler)); + } + } + seed(m_own, foe()); + seed(foe(), m_own); + } + + static void seed(SimBattler& seeded, SimBattler& other){ + if (!seeded.seeded || seeded.hp == 0 || other.hp == 0){ + return; + } + const uint16_t drained = std::min(eighth(seeded), seeded.hp); + lose_hp(seeded, drained); + gain_hp(other, drained); + } + + SimBattler m_own; + int m_potions; + SimTrainer m_trainer; + std::mt19937& m_rng; + size_t m_out = 0; + bool m_flinched = false; +}; + +} + + +WinEstimate estimate_win_chance(const SimBattler& own, int potions, const SimTrainer& trainer, size_t battles, uint32_t seed){ + std::mt19937 rng(seed); + WinEstimate estimate{.battles = battles, .wins = 0, .chance = 0}; + for (size_t i = 0; i < battles; i++){ + SimBattle battle(own, potions, trainer, rng); + estimate.wins += battle.won() ? 1 : 0; + } + estimate.chance = battles == 0 ? 0 : static_cast(estimate.wins) / battles; + return estimate; +} + +std::optional story_win_chance(const PartyMember& lead, int potions, double hp_share, std::string_view trainer){ + const std::optional own = own_battler(lead, hp_share); + const std::optional sim = sim_trainer(trainer); + if (!own || !sim){ + return std::nullopt; + } + WinEstimate estimate = estimate_win_chance(*own, potions, *sim); + estimate.inputs = std::format("{} Lv{} {}/{} HP:", own->species, own->body.level, own->hp, own->body.stats.hp); + for (size_t slot = 0; slot < own->moves.size(); slot++){ + estimate.inputs += std::format( + "{} {} {}/{}", slot == 0 ? "" : ",", own->moves[slot].move, own->moves[slot].pp, max_pp(own->moves[slot].move) + ); + } + estimate.inputs += std::format("; {} Potions", potions); + return estimate; +} + +std::optional win_chance_refusal(const WinEstimate& estimate, double minimum){ + if (estimate.chance >= minimum){ + return std::nullopt; + } + return std::format( + "win chance {:.0f}% < {:.0f}%{}: grind first", + std::floor(100 * estimate.chance), std::round(100 * minimum), + estimate.inputs.empty() ? "" : " with " + estimate.inputs + ); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h new file mode 100644 index 0000000000..9056a41f83 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h @@ -0,0 +1,66 @@ +/* AutoStory Win Chance + * + * From: https://github.com/PokemonAutomation/ + * + * Before a BattleRisk::HIGH battle: how often the lead beats the trainer, + * by playing the battle many times over (Monte Carlo) with the choices + * of PokemonFRLG_AutoStoryBattleSim.h and the game's random parts: the + * damage roll, crits (1/16, 1/8 for a high-crit move), accuracy with + * accuracy and evasion stages, speed ties, secondary effects, and the + * AI's ties. Too low a chance stops the story before the fight, for a + * GRIND or the nurse first. + * + * Each turn: the Potion and the AI's item first, then the moves by + * priority and speed (a quarter with PARALYSIS). Sleep (2 to 5 on the + * game's counter), poison (1/8 HP a turn), paralysis (1/4 no move), Leech + * Seed (1/8 a turn to the other side), flinch, one- and two-stage stat + * changes, multi-hit moves (2 to 5 as the game draws them), drain (half) + * and Recover (half) are played; burn, freeze, confusion, recoil, + * recharge, two-turn moves, trapping, abilities and held items are not. + * The lead is never switched out: a fainted lead is a lost battle. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryWinChance_H +#define PokemonAutomation_PokemonFRLG_AutoStoryWinChance_H + +#include +#include +#include +#include +#include +#include "PokemonFRLG_AutoStoryBattleSim.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +struct WinEstimate{ + size_t battles = 0; + size_t wins = 0; + // wins / battles + double chance = 0; + // The lead and Potions the battles were played with, for the log: + // "wartortle Lv20 60/60 HP: bite 25/25, ...; 5 Potions". + std::string inputs = {}; +}; + +// `own` with `potions` Potions against `trainer`, `battles` times, from a +// fixed `seed` so the same inputs give the same estimate. +WinEstimate estimate_win_chance(const SimBattler& own, int potions, const SimTrainer& trainer, size_t battles = 1000, uint32_t seed = 1); + +// The story's lead (`hp_share` of its HP) with `potions` against +// `trainer`. None if the data lacks the lead's species or the trainer. +std::optional story_win_chance(const PartyMember& lead, int potions, double hp_share, std::string_view trainer); + +// Why not to fight: "win chance 41% < 70% with : grind first", or +// none at `minimum` or above. +std::optional win_chance_refusal(const WinEstimate& estimate, double minimum = MIN_WIN_CHANCE); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp new file mode 100644 index 0000000000..fa4b926b71 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -0,0 +1,591 @@ +/* AutoStory Tests + * + * From: https://github.com/PokemonAutomation/ + * + * Plans every route of the story table on the map files, from where the + * table says the player stands, and checks that each checkpoint starts + * where the one before it ends. + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +class Test_AutoStory : public UnitTest{ +public: + Test_AutoStory(std::string name, std::function body) + : UnitTest("PokemonFRLG::AutoStory - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + +const MapData* find_map_named(const std::string& name){ + for (const MapData& map : story_maps()){ + if (map.name == name){ + return ↦ + } + } + return nullptr; +} + +std::string describe(const std::vector& route){ + std::string text; + for (const RouteStep& step : route){ + text += "\n " + to_string(step); + } + return text; +} + +std::string describe(const StoryPose& pose){ + return to_string(MapPosition{pose.map, pose.tile}) + + (pose.facing ? std::string(" facing ") + direction_name(*pose.facing) : ""); +} + +// A table pose as a StoryPose; FRLG's table has one-tile poses only. +StoryPose one_tile(const Pokemon::Pose& pose){ + const std::optional ret = story_pose(pose); + if (!ret){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Not a one-tile pose: " + Pokemon::to_string(pose)); + } + return *ret; +} + +Direction reverse(Direction direction){ + switch (direction){ + case Direction::NORTH: + return Direction::SOUTH; + case Direction::EAST: + return Direction::WEST; + case Direction::SOUTH: + return Direction::NORTH; + case Direction::WEST: + return Direction::EAST; + } + return direction; +} + +// The tiles a route's walking legs pass over on `map`. +std::vector tiles_walked_on(const std::vector& route, const std::string& map){ + std::vector tiles; + for (const RouteStep& step : route){ + if (step.action != RouteAction::WALK || step.end.map != map){ + continue; + } + TilePos tile = step.end.point; + for (int c = 0; c < step.tiles; c++){ + tiles.push_back(tile); + tile = tile.next(reverse(step.direction)); + } + } + return tiles; +} + +// Steps that must reach Viridian Forest's gate by legs the walker can hold +// again after a battle: each ends on a wall or a warp, or is one step. +bool held_legs_only(const std::string& name){ + return name == "forest_east" || name == "forest_exit" || name == "forest_gate"; +} +UnitTestResult check_held_legs(const std::string& name, const std::vector& route){ + for (const RouteStep& step : route){ + if (step.action == RouteAction::WALK && !step.to_wall && !step.warps && step.tiles != 1){ + return name + ": an open leg, " + to_string(step) + ":" + describe(route); + } + } + return true; +} + +// Walks `step`'s fixed legs from `pose` and moves `pose` to their end. +UnitTestResult check_legs(StoryPose& pose, const StoryStep& step){ + const std::optional> route = fixed_route(story_maps(), MapPosition{pose.map, pose.tile}, step.legs); + if (!route || route->empty()){ + return step.name + ": the legs can't be walked from " + describe(pose) + "."; + } + if (held_legs_only(step.name)){ + UnitTestResult result = check_held_legs(step.name, *route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + } + pose = StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after}; + return true; +} + +// Plans `step` from `pose` and moves `pose` to its end. +UnitTestResult check_route(StoryPose& pose, const StoryStep& step){ + const MapPosition start{pose.map, pose.tile}; + std::optional facing = pose.facing; + if (!facing){ + const MapData* map = find_map_named(pose.map); + facing = map ? wall_beside(*map, pose.tile) : std::nullopt; + if (!facing){ + return step.name + ": the facing is unknown at " + describe(pose) + " and no wall is beside it."; + } + } + if (!step.target){ + return step.name + ": no target."; + } + const StoryPose target = one_tile(*step.target); + const RouteGoal goal{{target.map, target.tile}, target.facing}; + const std::optional> route = plan_overworld_route(story_maps(), start, goal, default_route_costs(), facing); + if (!route){ + return step.name + ": no route from " + to_string(start) + " to " + to_string(goal.position) + "."; + } + const MapPosition end = follow_overworld_route(story_maps(), start, *route); + if (!(end == goal.position)){ + return step.name + ": the route ends at " + to_string(end) + ":" + describe(*route); + } + if (goal.facing && !route->empty() && route->back().facing_after != *goal.facing){ + return step.name + ": the route doesn't end facing " + direction_name(*goal.facing) + ":" + describe(*route); + } + if (held_legs_only(step.name)){ + UnitTestResult result = check_held_legs(step.name, *route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + } + if (step.name == "below_old_man_trigger"){ + for (const TilePos& tile : tiles_walked_on(*route, "ViridianCity")){ + if (tile == TilePos{20, 8} || tile == TilePos{22, 8}){ + return step.name + ": walks over the old man's trigger " + to_string(tile) + ":" + describe(*route); + } + } + } + pose = StoryPose{target.map, target.tile, route->empty() ? facing : route->back().facing_after}; + return true; +} + +// Follows `checkpoint` from its start; `pose` ends where it leaves the player. +UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& pose){ + for (const StoryStep& step : checkpoint.steps){ + if (step.kind == StoryStepKind::ROUTE || step.kind == StoryStepKind::LEGS){ + UnitTestResult result = step.kind == StoryStepKind::ROUTE ? check_route(pose, step) : check_legs(pose, step); + if (result.result != UnitTestResult::PASSED){ + return checkpoint.id + " " + result.message; + } + }else if (step.kind == StoryStepKind::READY){ + // The nurse may be needed: that way must plan too, but the pose + // goes on from where the player stands. + StoryPose nurse_pose = pose; + StoryStep to_nurse = step; + UnitTestResult result = check_route(nurse_pose, to_nurse); + if (result.result != UnitTestResult::PASSED){ + return checkpoint.id + " " + result.message; + } + }else if (step.kind == StoryStepKind::STEP){ + pose = StoryPose{pose.map, pose.tile.next(step.direction), step.direction}; + } + if (step.pose_after){ + pose = one_tile(*step.pose_after); + } + } + return true; +} + +UnitTestResult test_routes_and_chain(){ + const std::vector& checkpoints = story_checkpoints(); + if (checkpoints.size() != 10 || checkpoints[0].start){ + return "Expected 10 checkpoints, the first from a new game."; + } + StoryPose pose; + for (size_t c = 0; c < checkpoints.size(); c++){ + const StoryCheckpoint& checkpoint = checkpoints[c]; + if (c > 0){ + const StoryPose start = one_tile(*checkpoint.start); + const bool same_facing = !start.facing || start.facing == pose.facing; + if (start.map != pose.map || !(start.tile == pose.tile) || !same_facing){ + return checkpoint.id + " starts at " + describe(start) + ", but " + checkpoints[c - 1].id + " ends at " + describe(pose) + "."; + } + pose = start; + } + UnitTestResult result = check_checkpoint(checkpoint, pose); + if (result.result != UnitTestResult::PASSED){ + return result; + } + } + return true; +} + +struct ExpectedLeg{ + Direction direction; + int tiles; + TilePos end; +}; + +// Plans `start` to `goal` on the story maps and checks the walking legs +// on `map`, except the step that warps onto it, against `expected`. +UnitTestResult check_legs_on( + const MapPosition& start, Direction start_facing, const RouteGoal& goal, + const std::string& map, const std::vector& expected +){ + const std::optional> route = plan_overworld_route( + story_maps(), start, goal, default_route_costs(), start_facing + ); + if (!route){ + return "No route from " + to_string(start) + " to " + to_string(goal.position) + "."; + } + std::vector legs; + for (const RouteStep& step : *route){ + if (step.action == RouteAction::WALK && !step.warps && step.end.map == map){ + legs.push_back(step); + } + } + bool same = legs.size() == expected.size(); + for (size_t c = 0; same && c < legs.size(); c++){ + same = legs[c].direction == expected[c].direction && legs[c].tiles == expected[c].tiles && legs[c].end.point == expected[c].end; + } + if (!same){ + return "Unexpected legs on " + map + " from " + to_string(start) + " to " + to_string(goal.position) + ":" + describe(*route); + } + return true; +} + +// 00.09, each walk from where the one before leaves the player. +UnitTestResult test_pewter_gym_walks(){ + const MapPosition nurse{"PewterCity_PokemonCenter_1F", {7, 4}}; + // In by the door's mat (6, 14), straight up column 6 to below Liam's row. + UnitTestResult result = check_legs_on( + nurse, Direction::NORTH, RouteGoal{{"PewterCity_Gym", {6, 9}}, Direction::NORTH}, + "PewterCity_Gym", {{Direction::NORTH, 5, {6, 9}}} + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + // The step onto (6, 8), into Liam's line. + const MapData& gym = *find_map_named("PewterCity_Gym"); + if (classify_step(gym, PlayerState{{6, 9}, elevation_at(gym, {6, 9}), false}, Direction::NORTH) != StepKind::WALK){ + return "Can't step north from (6, 9) onto (6, 8)."; + } + // After Liam, on to Brock: two tiles north. + result = check_legs_on( + MapPosition{"PewterCity_Gym", {6, 8}}, Direction::NORTH, RouteGoal{{"PewterCity_Gym", {6, 6}}, Direction::NORTH}, + "PewterCity_Gym", {{Direction::NORTH, 2, {6, 6}}} + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + // The nurse's way: from her counter back in and up column 6 to Brock. + return check_legs_on( + nurse, Direction::NORTH, RouteGoal{{"PewterCity_Gym", {6, 6}}, Direction::NORTH}, + "PewterCity_Gym", {{Direction::NORTH, 8, {6, 6}}} + ); +} + +// 00.10: out of the Gym to the aide's top trigger. The route keeps off his +// three trigger tiles (46, 21..23), which would start the scene a step +// early, and the step east from its end lands on (46, 21). +UnitTestResult test_pewter_aide_walk(){ + const MapPosition gym{"PewterCity_Gym", {6, 6}}; + const MapPosition goal{"PewterCity", {45, 21}}; + const std::optional> route = plan_overworld_route( + story_maps(), gym, RouteGoal{goal, Direction::EAST}, default_route_costs(), Direction::NORTH + ); + if (!route || route->empty()){ + return "No route from " + to_string(gym) + " to " + to_string(goal) + "."; + } + MapPosition from = gym; + for (const RouteStep& step : *route){ + if (step.action != RouteAction::WALK){ + continue; + } + for (const MapPosition& tile : leg_tiles(story_maps(), from, step)){ + if (tile.map == "PewterCity" && tile.point.x == 46 && tile.point.y >= 21 && tile.point.y <= 23){ + return "The route crosses the aide's trigger " + to_string(tile) + ":" + describe(*route); + } + } + from = step.end; + } + if (route->back().end != goal){ + return "Expected the route to end at " + to_string(goal) + ", got " + to_string(route->back().end) + "."; + } + const MapData& pewter = *find_map_named("PewterCity"); + if (classify_step(pewter, PlayerState{{45, 21}, elevation_at(pewter, {45, 21}), false}, Direction::EAST) != StepKind::WALK){ + return "Can't step east from (45, 21) onto the trigger (46, 21)."; + } + return true; +} + +// Every ROUTE and LEGS after the Running Shoes (00.10) runs; none before. +UnitTestResult test_runs_after_shoes(){ + bool has_shoes = false; + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + for (const StoryStep& step : checkpoint.steps){ + if (step.kind != StoryStepKind::ROUTE && step.kind != StoryStepKind::LEGS){ + continue; + } + const MoveSpeed expected = has_shoes ? MoveSpeed::RUN : MoveSpeed::WALK; + if (move_speed(step) != expected){ + return checkpoint.id + "/" + step.name + ": expected to " + move_speed_name(expected) + ", it would " + move_speed_name(move_speed(step)) + "."; + } + } + has_shoes = has_shoes || checkpoint.id == "00.10"; + } + if (!has_shoes){ + return "No checkpoint 00.10, where the player gets the Running Shoes."; + } + return true; +} + +// Every checkpoint that starts from a save has a place the save card +// names, so a save left elsewhere is caught before it runs; and the +// places of the starts that matter differ. +UnitTestResult test_save_places(){ + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + if (checkpoint.start && save_card_place(checkpoint.start->map).empty()){ + return checkpoint.id + " starts on " + checkpoint.start->map + ", which has no save card place."; + } + } + if (save_card_place("ViridianForest") != "viridian-forest" || save_card_place("ViridianCity_Mart") != "viridian-city" + || save_card_place("PewterCity_PokemonCenter_1F") != "pewter-city" || save_card_place("PalletTown_ProfessorOaksLab") != "pallet-town" + ){ + return "Wrong save card places."; + } + if (!save_card_place("Route22").empty()){ + return "A place for a map the table doesn't use."; + } + return true; +} + +// A reload's save checked against the checkpoint's start: a save left in +// Pewter City (a new game whose save didn't happen) can't start 00.02 in +// the bedroom. The check takes no checks level: Fast runs it too. +UnitTestResult test_save_place_error(){ + struct Case{ + std::string start_map; + std::string place; + bool error; + }; + const Case CASES[] = { + {.start_map = "PalletTown_PlayersHouse_2F", .place = "pewter-city", .error = true}, + {.start_map = "PalletTown_PlayersHouse_2F", .place = "pallet-town", .error = false}, + // A card that can't be read is let pass. + {.start_map = "PalletTown_PlayersHouse_2F", .place = "", .error = false}, + {.start_map = "ViridianForest", .place = "viridian-city", .error = true}, + // A map with no known place isn't checked. + {.start_map = "Route22", .place = "pewter-city", .error = false}, + }; + for (const Case& c : CASES){ + const std::string error = save_place_error(c.start_map, c.place); + if (error.empty() == c.error){ + return "A save in \"" + c.place + "\" for a start on " + c.start_map + ": expected " + + (c.error ? "an error" : "no error") + ", got \"" + error + "\"."; + } + } + return true; +} + +const char* save_action_name(SaveAction action){ + switch (action){ + case SaveAction::WAIT: + return "WAIT"; + case SaveAction::ANSWER_YES: + return "ANSWER_YES"; + case SaveAction::NEXT_PAGE: + return "NEXT_PAGE"; + case SaveAction::CHECK_OVERWORLD: + return "CHECK_OVERWORLD"; + case SaveAction::FAIL_CANCELLED: + return "FAIL_CANCELLED"; + case SaveAction::FAIL_ERROR: + return "FAIL_ERROR"; + } + return "?"; +} + +// save_game()'s answers to the save dialogs of pokefirered's start_menu.c, +// screen by screen from the first YES/NO. +UnitTestResult test_save_dialog(){ + using S = SaveScreen; + using A = SaveAction; + struct Case{ + std::string name; + std::vector> screens; + }; + const std::vector CASES = { + { + .name = "first save", + .screens = {{S::YES_NO, A::ANSWER_YES}, {S::TEXT, A::WAIT}, {S::TEXT, A::WAIT}, {S::NOTHING, A::WAIT}, {S::NOTHING, A::CHECK_OVERWORLD}}, + }, + { + .name = "over this game's save", + .screens = {{S::YES_NO, A::ANSWER_YES}, {S::TEXT, A::WAIT}, {S::YES_NO, A::ANSWER_YES}, {S::TEXT, A::WAIT}, {S::NOTHING, A::WAIT}, {S::NOTHING, A::CHECK_OVERWORLD}}, + }, + { + // WARNING!, four pages, then the YES/NO that starts on NO. + .name = "a new game over another game's save", + .screens = { + {S::YES_NO, A::ANSWER_YES}, + {S::PAGED_TEXT, A::NEXT_PAGE}, {S::NOTHING, A::WAIT}, {S::PAGED_TEXT, A::NEXT_PAGE}, {S::PAGED_TEXT, A::NEXT_PAGE}, + {S::TEXT, A::WAIT}, {S::YES_NO, A::ANSWER_YES}, {S::TEXT, A::WAIT}, {S::NOTHING, A::WAIT}, {S::NOTHING, A::CHECK_OVERWORLD}, + }, + }, + { + .name = "cancelled: the START menu is back", + .screens = {{S::YES_NO, A::ANSWER_YES}, {S::TEXT, A::WAIT}, {S::START_MENU, A::FAIL_CANCELLED}}, + }, + { + .name = "Save error.", + .screens = {{S::YES_NO, A::ANSWER_YES}, {S::TEXT, A::WAIT}, {S::PAGED_TEXT, A::NEXT_PAGE}, {S::NOTHING, A::WAIT}, {S::NOTHING, A::FAIL_ERROR}}, + }, + }; + for (const Case& c : CASES){ + SaveDialog dialog; + for (size_t i = 0; i < c.screens.size(); i++){ + const SaveAction action = dialog.next(c.screens[i].first); + if (action != c.screens[i].second){ + return c.name + ", screen " + std::to_string(i + 1) + ": expected " + save_action_name(c.screens[i].second) + + ", got " + save_action_name(action) + "."; + } + } + } + return true; +} + +UnitTestResult test_lint(){ + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + const std::vector problems = Pokemon::lint_story_checkpoint(checkpoint); + if (!problems.empty()){ + return problems[0]; + } + } + return true; +} + +UnitTestResult test_unique_names(){ + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + for (size_t i = 0; i < checkpoint.steps.size(); i++){ + for (size_t j = i + 1; j < checkpoint.steps.size(); j++){ + if (checkpoint.steps[i].name == checkpoint.steps[j].name){ + return checkpoint.id + " has two steps named " + checkpoint.steps[i].name + "."; + } + } + } + } + return true; +} +// The intro's names: the player's keyboard first, then the rival's list, +// where a preset is picked; a keyboard after the player's means the list +// was missed. +UnitTestResult test_intro_names(){ + struct Case{ + const char* what; + IntroNameScreen screen; + size_t keyboards_seen; + size_t presets_picked; + IntroNameStep expected; + }; + const std::vector cases{ + {.what = "the first keyboard", .screen = IntroNameScreen::KEYBOARD, .keyboards_seen = 0, .presets_picked = 0, .expected = IntroNameStep::PLAYER_KEYBOARD}, + {.what = "the list after the player's keyboard", .screen = IntroNameScreen::RIVAL_LIST, .keyboards_seen = 1, .presets_picked = 0, .expected = IntroNameStep::RIVAL_PRESET}, + {.what = "a list read before the player's keyboard", .screen = IntroNameScreen::RIVAL_LIST, .keyboards_seen = 0, .presets_picked = 0, .expected = IntroNameStep::NONE}, + {.what = "the second keyboard", .screen = IntroNameScreen::KEYBOARD, .keyboards_seen = 1, .presets_picked = 0, .expected = IntroNameStep::RIVAL_KEYBOARD}, + {.what = "a keyboard after a preset was picked", .screen = IntroNameScreen::KEYBOARD, .keyboards_seen = 1, .presets_picked = 1, .expected = IntroNameStep::RIVAL_KEYBOARD}, + {.what = "the list again after a NO", .screen = IntroNameScreen::RIVAL_LIST, .keyboards_seen = 1, .presets_picked = 1, .expected = IntroNameStep::RIVAL_PRESET}, + {.what = "the list after every try", .screen = IntroNameScreen::RIVAL_LIST, .keyboards_seen = 1, .presets_picked = RIVAL_PRESET_TRIES, .expected = IntroNameStep::NONE}, + {.what = "a message box", .screen = IntroNameScreen::OTHER, .keyboards_seen = 1, .presets_picked = 0, .expected = IntroNameStep::NONE}, + }; + for (const Case& c : cases){ + const IntroNameStep step = intro_name_step(c.screen, c.keyboards_seen, c.presets_picked); + if (step != c.expected){ + return std::string(c.what) + ": expected step " + std::to_string(static_cast(c.expected)) + + ", got " + std::to_string(static_cast(step)) + "."; + } + } + // A black screen is no list. + ImageRGB32 black(1920, 1080); + black.fill(0xff000000); + if (rival_name_list_cursor(black).has_value()){ + return "Read the rival's name list on a black screen."; + } + return true; +} + +// set_options()'s RIGHT presses from each value an old save can leave: +// on console B a save with FAST and SET became SLOW and SHIFT when the +// presses assumed MID and SHIFT. +UnitTestResult test_option_presses(){ + const std::vector& speed = option_menu_values(OptionMenuItem::TEXT_SPEED); + const std::vector& scene = option_menu_values(OptionMenuItem::BATTLE_SCENE); + const std::vector& style = option_menu_values(OptionMenuItem::BATTLE_STYLE); + struct Case{ + const std::vector& values; + std::string current; + std::string target; + std::optional expected; + }; + const std::vector cases{ + {.values = speed, .current = "slow", .target = "fast", .expected = 2}, + {.values = speed, .current = "mid", .target = "fast", .expected = 1}, + {.values = speed, .current = "fast", .target = "fast", .expected = 0}, + {.values = scene, .current = "on", .target = "off", .expected = 1}, + {.values = scene, .current = "off", .target = "off", .expected = 0}, + {.values = style, .current = "shift", .target = "set", .expected = 1}, + {.values = style, .current = "set", .target = "set", .expected = 0}, + // RIGHT wraps from the last value to the first. + {.values = speed, .current = "fast", .target = "slow", .expected = 1}, + // Unread, or another row's value: no guess. + {.values = speed, .current = "", .target = "fast", .expected = std::nullopt}, + {.values = style, .current = "fast", .target = "set", .expected = std::nullopt}, + {.values = scene, .current = "set", .target = "off", .expected = std::nullopt}, + }; + for (const Case& c : cases){ + const std::optional presses = option_right_presses(c.values, c.current, c.target); + if (presses != c.expected){ + auto text = [](const std::optional& n){ + return n ? std::to_string(*n) + " RIGHT" : std::string("no presses"); + }; + return "\"" + c.current + "\" to " + c.target + ": expected " + text(c.expected) + ", got " + text(presses) + "."; + } + } + return true; +} + +} + + +void add_tests_AutoStory(UnitTestDatabase& database){ + database.add("every route plans, and checkpoints chain", test_routes_and_chain); + database.add("step names are unique per checkpoint", test_unique_names); + database.add("every save has a place on the save card", test_save_places); + database.add("a reload's save is checked against the start", test_save_place_error); + database.add("save dialogs: every YES/NO is YES, a cancel fails", test_save_dialog); + database.add("every checkpoint lints clean", test_lint); + database.add("Pewter Gym walks", test_pewter_gym_walks); + database.add("Pewter: to the aide's trigger", test_pewter_aide_walk); + database.add("routes run after the Running Shoes", test_runs_after_shoes); + database.add("intro: names, the rival's from the list", test_intro_names); + database.add("options: RIGHT presses from the shown value", test_option_presses); +} + + + +} +} +} diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 46553724c9..c99a56150f 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1744,8 +1744,14 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Inference/Map/PokemonFRLG_PokemonLeagueDetectors.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_BagDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_BagDetector.h + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_LoadMenuDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_LoadMenuDetector.h + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyEmptySlotDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyEmptySlotDetector.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyHeldItemDetector.cpp @@ -1753,16 +1759,26 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyMenuDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyMenuDetector.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryDetector.h + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_TrainerCardDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_TrainerCardDetector.h Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleLevelUpReader.cpp Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleLevelUpReader.h + Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.cpp + Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h + Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp + Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.cpp Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.h + Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp + Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleSelectionArrowDetector.cpp Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleSelectionArrowDetector.h Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_DaycareManDetector.cpp @@ -1791,6 +1807,26 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Inference/Sounds/PokemonFRLG_CatchFanfareDetector.h Source/VideoGames/PokemonFRLG/Inference/Sounds/PokemonFRLG_ShinySoundDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Sounds/PokemonFRLG_ShinySoundDetector.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp @@ -1799,6 +1835,38 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EliteFourFarmer.cpp Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EliteFourFarmer.h Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EvTrainer.cpp diff --git a/devtools/maps/frlg_battle_data.py b/devtools/maps/frlg_battle_data.py new file mode 100644 index 0000000000..d89c74e5ec --- /dev/null +++ b/devtools/maps/frlg_battle_data.py @@ -0,0 +1,278 @@ +"""Writes the FRLG battle data AutoStory chooses its attacks from, as JSON, from the pret/pokefirered decompilation. + +Usage: + python3 devtools/maps/frlg_battle_data.py --out SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData + python3 devtools/maps/frlg_battle_data.py --out --check + +Reads, at frlg_maps.COMMIT (cached in --cache like frlg_maps.py): +- src/battle_main.c gTypeEffectiveness: type_chart.json, each pairing that + isn't 1x, in tenths; +- src/data/pokemon/species_info.h: species.json, every species' two types + and base stats: HP, Attack, Defense, Sp. Atk, Sp. Def, Speed; +- src/data/battle_moves.h: moves.json, every move's power, type, PP, + accuracy, priority, effect (EFFECT_FLINCH_HIT is "flinch-hit") and its + secondary effect's chance; +- src/data/trainers.h and src/data/trainer_parties.h: trainers.json, every + trainer's AI flags (AI_SCRIPT_TRY_TO_FAINT is "try-to-faint"), items and + party (not the Ruby/Sapphire placeholders, DUMMY_TRAINER_MON): each + member's species, level, iv (0 to 255, as pret has it), nature and moves. + A party that gives no moves gets the game's (GiveBoxMonInitialMoveset: + the last four of its level-up moves up to its level, from + src/data/pokemon/level_up_learnsets.h). The nature is the one + CreateNPCTrainerParty's personality gives: a hash of the trainer's and + the species' names (charmap.txt) on top of 0x78 for a female trainer, + 0x80 for a double battle, else 0x88, mod 25; +- data/maps/*/scripts.inc, map.json and data/scripts/trainers.inc: + map_trainers.json, the trainers each map battles (trainerbattle_* + TRAINER_X in its scripts or its objects'). +Names are the program's slugs: SPECIES_MR_MIME is "mr-mime", MOVE_WATER_GUN +"water-gun", TYPE_WATER "water". One entry per line, so a change in pret +shows as a line in the diff. --check writes nothing: it regenerates the files +and fails if any differs. +""" +import argparse +import json +import os +import re +import sys +from concurrent.futures import ThreadPoolExecutor + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +import frlg_maps # noqa: E402 + +# Slugs the plain rule (lower case, '_' to '-') gets wrong: the program's +# names, from Resources/Pokemon/Pokedex/Pokedex-National.json and PokeAPI. +SPECIES_SLUGS = {'FARFETCHD': 'farfetch-d'} +MOVE_SLUGS = { + 'FAINT_ATTACK': 'feint-attack', + 'HI_JUMP_KICK': 'high-jump-kick', + 'SMELLING_SALT': 'smelling-salts', + 'VICE_GRIP': 'vise-grip', +} +# Not species a battle can show. +SKIPPED_SPECIES = re.compile(r'NONE$|EGG$|OLD_UNOWN_') +# The AI flags, as include/constants/battle_ai.h names them. +AI_FLAG = re.compile(r'AI_SCRIPT_(\w+)') +# gTypeEffectiveness's multipliers, in tenths. +MULTIPLIERS = {'TYPE_MUL_NO_EFFECT': 0, 'TYPE_MUL_NOT_EFFECTIVE': 5, 'TYPE_MUL_SUPER_EFFECTIVE': 20} + + +def slug(name, fixes=None): + return (fixes or {}).get(name) or name.lower().replace('_', '-') + + +def type_slug(name): + return name[len('TYPE_'):].lower() + + +def entries(text, prefix): + """(NAME, body) for each designated initializer `[PREFIX_NAME] = { body }`.""" + pattern = re.compile(r'\[' + prefix + r'_(\w+)\]\s*=\s*\{((?:(?!\n \[).)*?)\n \},', re.S) + return pattern.findall(text) + + +def field(body, name): + match = re.search(r'\.' + name + r'\s*=\s*([^,\n]+(?:\{[^}]*\})?)', body) + return match.group(1).strip() if match else None + + +def type_chart(text): + table = re.search(r'gTypeEffectiveness\[\d+\]\s*=\s*\{(.*?)\};', text, re.S).group(1) + chart = [] + for attack, defend, mul in re.findall(r'(TYPE_\w+),\s*(TYPE_\w+),\s*(TYPE_MUL_\w+)', table): + if attack in ('TYPE_FORESIGHT', 'TYPE_ENDTABLE'): + continue + chart.append([type_slug(attack), type_slug(defend), MULTIPLIERS[mul]]) + return chart + + +def species(text): + data = {} + for name, body in entries(text, 'SPECIES'): + if SKIPPED_SPECIES.search(name): + continue + types = re.search(r'\.types\s*=\s*\{(TYPE_\w+),\s*(TYPE_\w+)\}', body) + stats = [int(field(body, f)) for f in ('baseHP', 'baseAttack', 'baseDefense', 'baseSpAttack', 'baseSpDefense', 'baseSpeed')] + data[slug(name, SPECIES_SLUGS)] = [type_slug(types.group(1)), type_slug(types.group(2))] + stats + return data + + +def moves(text): + data = {} + for name, body in entries(text, 'MOVE'): + if name == 'NONE': + continue + data[slug(name, MOVE_SLUGS)] = [ + int(field(body, 'power')), type_slug(field(body, 'type')), int(field(body, 'pp')), + int(field(body, 'accuracy')), int(field(body, 'priority')), + slug(field(body, 'effect')[len('EFFECT_'):]), int(field(body, 'secondaryEffectChance')), + ] + return data + + +def learnsets(text, pointers): + """{species slug: [(level, move slug), ...]} from level_up_learnsets.h.""" + by_name = {} + for name, body in re.findall(r'static const u16 (s\w+LevelUpLearnset)\[\]\s*=\s*\{(.*?)\};', text, re.S): + by_name[name] = [(int(lvl), slug(move, MOVE_SLUGS)) for lvl, move in re.findall(r'LEVEL_UP_MOVE\(\s*(\d+),\s*MOVE_(\w+)\)', body)] + return {slug(s, SPECIES_SLUGS): by_name[n] for s, n in re.findall(r'\[SPECIES_(\w+)\]\s*=\s*(s\w+LevelUpLearnset)', pointers)} + + +def initial_moves(learnset, level): + """GiveBoxMonInitialMoveset: each level-up move up to `level` in turn; + one already known is skipped, a fifth pushes out the first.""" + known = [] + for move_level, move in learnset: + if move_level > level: + break + if move in known: + continue + if len(known) == 4: + known.pop(0) + known.append(move) + return known + + +def charmap(text): + """{character: byte} for the single characters charmap.txt maps.""" + chars = {} + for char, code in re.findall(r"^'(\\?.)'\s*=\s*([0-9A-F]{2})\s*$", text, re.M): + chars[char[-1]] = int(code, 16) + return chars + + +def name_sum(name, chars): + return sum(chars[c] for c in name) + + +def species_names(text): + return {slug(name, SPECIES_SLUGS): value for name, value in re.findall(r'\[SPECIES_(\w+)\]\s*=\s*_\("(.*?)"\)', text)} + + +def parties(text, moves_at): + """sParty_X: [(species, level, iv, [moves]), ...]; `moves_at(species, + level)` gives a member's moves where the party doesn't.""" + data = {} + # A placeholder's {DUMMY_TRAINER_MON} on one line doesn't match. + for name, body in re.findall(r'struct TrainerMon\w+ (sParty_\w+)\[\]\s*=\s*\{\n((?:(?!\nstatic ).)*?)\n\};', text, re.S): + party = [] + for mon in re.findall(r'\{(.*?)\n \}', body, re.S): + species, level = slug(field(mon, 'species')[len('SPECIES_'):], SPECIES_SLUGS), int(field(mon, 'lvl')) + given = re.search(r'\.moves\s*=\s*\{(.*?)\}', mon) + if given: + moves = [slug(m.strip()[len('MOVE_'):], MOVE_SLUGS) for m in given.group(1).split(',') if m.strip() != 'MOVE_NONE'] + else: + moves = moves_at(species, level) + party.append((species, level, int(field(mon, 'iv')), moves)) + data[name] = party + return data + + +def personality_base(body): + """CreateNPCTrainerParty's personality before the name hash.""" + if field(body, 'doubleBattle') == 'TRUE': + return 0x80 + if 'F_TRAINER_FEMALE' in field(body, 'encounterMusic_gender'): + return 0x78 + return 0x88 + + +def trainers(text, party_text, learned, names, chars): + by_party = parties(party_text, lambda species, level: initial_moves(learned.get(species, []), level)) + data = {} + for name, body in entries(text, 'TRAINER'): + if name == 'NONE': + continue + party = re.search(r'\.party\s*=\s*\w+\((sParty_\w+)\)', body) + # Left out: the Ruby/Sapphire placeholders (DUMMY_TRAINER_MON). + if not party or party.group(1) not in by_party: + continue + trainer_sum = name_sum(re.search(r'\.trainerName\s*=\s*_\("(.*?)"\)', body).group(1), chars) + name_hash = 0 + members = [] + for species, level, iv, moves in by_party[party.group(1)]: + name_hash += trainer_sum + name_sum(names[species], chars) + nature = ((personality_base(body) + (name_hash << 8)) & 0xFFFFFFFF) % 25 + members.append([species, level, iv, nature, moves]) + items = re.search(r'\.items\s*=\s*\{(.*?)\}', body).group(1) + data['TRAINER_' + name] = { + 'ai': [slug(flag) for flag in AI_FLAG.findall(field(body, 'aiFlags') or '')], + 'items': [slug(item.strip()[len('ITEM_'):]) for item in items.split(',') if item.strip() not in ('', 'ITEM_NONE')], + 'party': members, + } + return data + + +def script_trainers(text): + """{label: TRAINER_X} for each script whose first line battles a trainer.""" + return dict(re.findall(r'^(\w+)::\n\s*trainerbattle\w* (TRAINER_\w+)', text, re.M)) + + +def map_trainers(decomp): + """The trainers each map battles: in its own scripts, and its objects' + scripts in data/scripts/trainers.inc (most trainers on routes).""" + groups = json.loads(decomp.read('data/maps/map_groups.json')) + names = sorted(m for group in groups['group_order'] for m in groups[group]) + shared = script_trainers(decomp.read('data/scripts/trainers.inc').decode()) + read = lambda m: (decomp.read(f'data/maps/{m}/scripts.inc').decode(), json.loads(decomp.read(f'data/maps/{m}/map.json'))) + with ThreadPoolExecutor(16) as pool: + sources = list(pool.map(read, names)) + data = {} + for name, (scripts, source) in zip(names, sources): + battled = set(re.findall(r'trainerbattle\w* (TRAINER_\w+)', scripts)) + battled |= {shared[o['script']] for o in source.get('object_events', []) if o.get('script') in shared} + if battled: + data[name] = sorted(battled) + return data + + +def json_lines(data): + """A JSON object (or a list), one entry per line.""" + if isinstance(data, list): + lines = [json.dumps(item) for item in data] + return '[\n' + ',\n'.join(lines) + '\n]\n' + lines = [f'{json.dumps(key)}: {json.dumps(value)}' for key, value in data.items()] + return '{\n' + ',\n'.join(lines) + '\n}\n' + + +def files(decomp): + read = lambda rel: decomp.read(rel).decode() + return { + 'type_chart': json_lines(type_chart(read('src/battle_main.c'))), + 'species': json_lines(species(read('src/data/pokemon/species_info.h'))), + 'moves': json_lines(moves(read('src/data/battle_moves.h'))), + 'trainers': json_lines(trainers( + read('src/data/trainers.h'), read('src/data/trainer_parties.h'), + learnsets(read('src/data/pokemon/level_up_learnsets.h'), read('src/data/pokemon/level_up_learnset_pointers.h')), + species_names(read('src/data/text/species_names.h')), charmap(read('charmap.txt')), + )), + 'map_trainers': json_lines(map_trainers(decomp)), + } + + +def main(): + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('--commit', default=frlg_maps.COMMIT) + parser.add_argument('--cache', default=os.path.expanduser('~/.cache/pokefirered')) + parser.add_argument('--out', required=True, help='folder of the .json files') + parser.add_argument('--check', action='store_true', help='check the files in --out instead of writing them') + args = parser.parse_args() + generated = files(frlg_maps.Decomp(args.commit, args.cache)) + if args.check: + differ = [] + for name, text in generated.items(): + path = os.path.join(args.out, name + '.json') + if not os.path.exists(path) or open(path, newline='').read() != text: + differ.append(name) + if differ: + sys.exit(f'Differ from the generator: {" ".join(differ)}. Regenerate them without --check.') + print(f'{len(generated)} files in {args.out} match the generator.') + return + os.makedirs(args.out, exist_ok=True) + for name, text in generated.items(): + with open(os.path.join(args.out, name + '.json'), 'w', newline='') as out: + out.write(text) + + +if __name__ == '__main__': + main() diff --git a/devtools/maps/frlg_maps.py b/devtools/maps/frlg_maps.py new file mode 100644 index 0000000000..3a4ef4a25a --- /dev/null +++ b/devtools/maps/frlg_maps.py @@ -0,0 +1,318 @@ +"""Writes FRLG overworld maps as JSON, from the pret/pokefirered decompilation. + +TODO: move the maps to PokemonAutomation/Packages (Resources/PokemonFRLG/Maps) when ready. + +Usage: + python3 devtools/maps/frlg_maps.py --out SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps \ + CeruleanCity_PokemonCenter_1F CeruleanCity Route24 \ + CeruleanCave_1F CeruleanCave_2F CeruleanCave_B1F + python3 devtools/maps/frlg_maps.py --out + python3 devtools/maps/frlg_maps.py --out --check + +Downloads each map's data/maps//map.json, its layout's map.bin and its +tilesets' metatile_attributes.bin at --commit into --cache, then writes +/.json in the schema of Pokemon::MapData (Pokemon_MapData.h). +Warps and connections lead only to maps in the same run: a warp to another map +has no destination, and a connection to one is left out. A warp arrives at +point "warp_" of its map, the tile of that map's warp n. Other named points +and flag sets come from POINTS and FLAG_SETS below. + +Without map names, the maps are the ones already in --out. --check writes +nothing: it regenerates them and fails if any file differs. The program +builds in the files of SerialPrograms/Source/VideoGames/PokemonFRLG/ +Overworld/Maps, the folder to write and check. +""" +import argparse +import json +import os +import re +import struct +import subprocess +import sys + +COMMIT = 'ce6406d8c2eaf46d543c8a2606de0c3cb1951982' +# When COMMIT was pinned, for each map's "source". +COMMIT_DATE = '2026-10-31' + +# Behaviors with a glyph of their own (Pokemon_MapData.h has the legend). +TERRAIN = { + 'MB_TALL_GRASS': '~', 'MB_WARP_DOOR': 'D', + 'MB_IMPASSABLE_NORTH': '8', 'MB_IMPASSABLE_SOUTH': '2', + 'MB_IMPASSABLE_EAST': '6', 'MB_IMPASSABLE_WEST': '4', +} +# Open tiles whose warp is taken other than by walking into it: how. +WARP_ENTRIES = { + 'MB_CAVE_DOOR': 'cave_entrance', + 'MB_LADDER': 'step_on', 'MB_UP_ESCALATOR': 'step_on', 'MB_DOWN_ESCALATOR': 'step_on', + 'MB_SOUTH_ARROW_WARP': 'walk_south', 'MB_NORTH_ARROW_WARP': 'walk_north', + 'MB_EAST_ARROW_WARP': 'walk_east', 'MB_WEST_ARROW_WARP': 'walk_west', + # Stairs at the side of a room warp like an exit mat, the way the stairs + # go up or down (IsDirectionalStairWarpMetatileBehavior()). + 'MB_UP_RIGHT_STAIR_WARP': 'walk_east', 'MB_DOWN_RIGHT_STAIR_WARP': 'walk_east', + 'MB_UP_LEFT_STAIR_WARP': 'walk_west', 'MB_DOWN_LEFT_STAIR_WARP': 'walk_west', +} +# Ledges, by the way the player hops over them. +LEDGES = {'MB_JUMP_NORTH': '^', 'MB_JUMP_SOUTH': 'v', 'MB_JUMP_WEST': '<', 'MB_JUMP_EAST': '>'} +FLOOR = ('MB_NORMAL', 'MB_CAVE', 'MB_ROCK_STAIRS', 'MB_TALL_GRASS') +DIRECTIONS = {'up': 'north', 'down': 'south', 'left': 'west', 'right': 'east'} + +# Places and flag sets the decompilation doesn't name, written into the map +# they belong to. +# A `*_front` point is where the player stands to talk to someone across a +# counter, or to walk north through a door. +POINTS = { + # Where a new game starts (WarpToPlayersRoom() in src/new_game.c). + 'PalletTown_PlayersHouse_2F': {'start': (6, 6)}, + 'PalletTown': {'oaks_lab_front': (16, 14)}, + # The clerk is across the counter to the west. + 'ViridianCity_Mart': {'clerk_front': (4, 3)}, + 'ViridianCity_PokemonCenter_1F': {'nurse_front': (7, 4)}, + 'PewterCity': {'gym_front': (15, 17)}, + 'PewterCity_PokemonCenter_1F': {'nurse_front': (7, 4)}, + 'PewterCity_Gym': {'brock_front': (6, 6)}, + # The tile in front of the PC. + 'CeruleanCity_PokemonCenter_1F': {'pc': (11, 2), 'nurse_front': (7, 4)}, + # Where the player stands after entering from Cerulean City. + 'CeruleanCave_1F': {'entrance': (33, 21)}, + # Mewtwo's tile. Its battle starts by talking to it from the south. + 'CeruleanCave_B1F': {'mewtwo': (7, 12)}, +} +FLAG_SETS = { + # Set once the player has entered the Hall of Fame. They clear the way + # to Cerulean Cave: its guard, the rival and the Rocket. + 'CeruleanCity': {'after_hall_of_fame': [ + 'FLAG_HIDE_CERULEAN_CAVE_GUARD', + 'FLAG_HIDE_CERULEAN_RIVAL', + 'FLAG_HIDE_CERULEAN_ROCKET', + ]}, +} + + +class Decomp: + def __init__(self, commit, cache): + self.raw = 'https://raw.githubusercontent.com/pret/pokefirered/' + commit + self.cache = os.path.join(cache, commit) + + def path(self, rel): + local = os.path.join(self.cache, rel) + if not os.path.exists(local): + os.makedirs(os.path.dirname(local), exist_ok=True) + subprocess.run(['curl', '-sfL', f'{self.raw}/{rel}', '-o', local], check=True) + return local + + def read(self, rel): + with open(self.path(rel), 'rb') as file: + return file.read() + + +def behaviors(decomp): + names = {} + for line in decomp.read('include/constants/metatile_behaviors.h').decode().splitlines(): + match = re.match(r'#define (MB_\w+)\s+(0x[0-9A-Fa-f]+|\d+)', line) + if match: + names[int(match.group(2), 0)] = match.group(1) + return names + + +def tileset_attributes(decomp, symbol, kind): + name = re.sub(r'([a-z])([A-Z0-9])', r'\1_\2', symbol.replace('gTileset_', '')).lower() + data = decomp.read(f'data/tilesets/{kind}/{name}/metatile_attributes.bin') + return [struct.unpack_from('> 10) & 3, value >> 12 + attributes = primary[metatile] if metatile < 640 else secondary[metatile - 640] + behavior = names.get(attributes & 0x1ff, hex(attributes & 0x1ff)) + glyph, entry = tile_glyph(behavior, collision, unhandled, (x, y) in signs) + row += glyph + if entry: + entries[(x, y)] = entry + levels += '%x' % level + tiles.append(row) + elevation.append(levels) + return tiles, elevation, entries + + +def wander_box(obj, tiles): + """The tiles a wandering person may stand on, kept inside the map, or None + if they stand still.""" + movement = obj.get('movement_type', '') + if 'WANDER' not in movement: + return None + x = 0 if 'UP_AND_DOWN' in movement else int(obj.get('movement_range_x') or 0) + y = 0 if 'LEFT_AND_RIGHT' in movement else int(obj.get('movement_range_y') or 0) + if x == 0 and y == 0: + return None + return { + 'x0': max(obj['x'] - x, 0), 'y0': max(obj['y'] - y, 0), + 'x1': min(obj['x'] + x, len(tiles[0]) - 1), 'y1': min(obj['y'] + y, len(tiles) - 1), + } + + +def map_object(obj, tiles): + kind = obj['graphics_id'].replace('OBJ_EVENT_GFX_', '').lower() + data = {'name': kind, 'kind': 'item' if kind == 'item_ball' else 'npc', 'x': obj['x'], 'y': obj['y']} + box = wander_box(obj, tiles) + if box: + data['wander'] = box + flag = obj.get('flag') or '0' + if flag != '0': + data['hide_flag'] = flag + return data + + +# Tiles the player never walks onto: their elevation only matters for doors, +# which the player is put on by a warp and leaves at once. +UNWALKABLE = '#^v<>DS' +GROUND = '3' + + +def ground_only(tiles, elevation): + """Whether every walkable tile is at ground level, so that the map can + leave out its elevation grid (the loader reads ground everywhere).""" + return all(level == GROUND for row, levels in zip(tiles, elevation) + for tile, level in zip(row, levels) if tile not in UNWALKABLE) + + +def warp_point(index): + return f'warp_{index}' + + +def warp(event, entries, loaded, sources): + """A warp event as MapData's warp: how it is entered, and the point it + leads to, if its map is loaded and has that warp.""" + data = {'x': event['x'], 'y': event['y'], 'enter': entries.get((event['x'], event['y']), 'walk_into')} + to_map, index = loaded.get(event['dest_map']), int(event['dest_warp_id']) + if to_map is not None and index < len(sources[to_map].get('warp_events', [])): + data['to_map'] = to_map + data['to_point'] = warp_point(index) + return data + + +def arrivals(sources, loaded): + """For each map, the indices of its warps that a warp leads to.""" + arriving = {name: set() for name in sources} + for source in sources.values(): + for event in source.get('warp_events', []): + to_map = loaded.get(event['dest_map']) + if to_map is not None and int(event['dest_warp_id']) < len(sources[to_map].get('warp_events', [])): + arriving[to_map].add(int(event['dest_warp_id'])) + return arriving + + +def map_json(decomp, name, sources, layouts, names, loaded, unhandled): + source = sources[name] + signs = frozenset((e['x'], e['y']) for e in source.get('bg_events', []) if e.get('type') == 'sign') + tiles, elevation, entries = grid(decomp, layouts[source['layout']], names, unhandled, signs) + warp_events = source.get('warp_events', []) + points = {n: [x, y] for n, (x, y) in POINTS.get(name, {}).items()} + for index in sorted(arrivals(sources, loaded)[name]): + points[warp_point(index)] = [warp_events[index]['x'], warp_events[index]['y']] + data = { + 'name': name, + 'source': {'decomp_file': f'data/maps/{name}/map.json', 'revision': COMMIT, 'date': COMMIT_DATE}, + 'tiles': tiles, 'elevation': elevation, + 'points': points, + 'warps': [warp(event, entries, loaded, sources) for event in warp_events], + # A few objects stand off the map, where no route meets them. + 'objects': [ + map_object(obj, tiles) for obj in source.get('object_events', []) + if 0 <= obj['x'] < len(tiles[0]) and 0 <= obj['y'] < len(tiles) + ], + 'flag_sets': FLAG_SETS.get(name, {}), + 'connections': [ + {'side': DIRECTIONS[c['direction']], 'to_map': loaded[c['map']], 'offset': c['offset']} + for c in (source.get('connections') or []) if c['map'] in loaded + ], + } + if ground_only(tiles, elevation): + del data['elevation'] + return data + + +def json_text(data): + text = json.dumps(data, indent=4) + # A point's [x, y] on one line. + return re.sub(r'\[\s*(-?\d+),\s*(-?\d+)\s*\]', r'[\1, \2]', text) + '\n' + + +def main(): + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('--commit', default=COMMIT) + parser.add_argument('--cache', default=os.path.expanduser('~/.cache/pokefirered')) + parser.add_argument('--out', required=True, help='folder of the .json files') + parser.add_argument('--check', action='store_true', help='check the files in --out instead of writing them') + parser.add_argument('maps', nargs='*', help='default: the maps already in --out') + args = parser.parse_args() + if not args.maps and os.path.isdir(args.out): + args.maps = sorted(f[:-5] for f in os.listdir(args.out) if f.endswith('.json')) + if not args.maps: + parser.error('no maps given, and none in --out') + + decomp = Decomp(args.commit, args.cache) + names = behaviors(decomp) + layouts = {l['id']: l for l in json.loads(decomp.read('data/layouts/layouts.json'))['layouts'] if 'id' in l} + sources = {m: json.loads(decomp.read(f'data/maps/{m}/map.json')) for m in args.maps} + loaded = {source['id']: m for m, source in sources.items()} + unhandled = {} + maps = [(name, json_text(map_json(decomp, name, sources, layouts, names, loaded, unhandled))) for name in args.maps] + if unhandled: + print(f'Non-collision behaviors written as floor: {unhandled}') + if args.check: + differ = [] + for name, text in maps: + path = os.path.join(args.out, name + '.json') + if not os.path.exists(path) or open(path, newline='').read() != text: + differ.append(name) + if differ: + sys.exit(f'Differ from the generator: {" ".join(differ)}. Regenerate them without --check.') + print(f'{len(maps)} maps in {args.out} match the generator.') + return + os.makedirs(args.out, exist_ok=True) + for name, text in maps: + with open(os.path.join(args.out, name + '.json'), 'w', newline='') as out: + out.write(text) + + +if __name__ == '__main__': + main() From 6cd80bc435b942ea5ebfeee5cab5d4adb45ef17b Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 5 Nov 2026 13:10:55 -0800 Subject: [PATCH 02/29] FRLG AutoStory stage 1: align with PR #231 lint conventions Clean up namespace closing comments, namespace-scope symbol documentation, and refactor unit tests to table-driven TestCase scenarios. --- .../Menus/PokemonFRLG_ItemListReader.cpp | 10 +- .../Menus/PokemonFRLG_ItemListReader.h | 9 +- .../PokemonFRLG_NamingScreenDetector.cpp | 8 +- .../Menus/PokemonFRLG_NamingScreenDetector.h | 8 +- .../Menus/PokemonFRLG_OptionMenuReader.cpp | 10 +- .../Menus/PokemonFRLG_OptionMenuReader.h | 7 +- .../Menus/PokemonFRLG_SaveCardReader.cpp | 10 +- .../Menus/PokemonFRLG_SaveCardReader.h | 7 +- .../Menus/PokemonFRLG_SummaryMovesReader.cpp | 10 +- .../Menus/PokemonFRLG_SummaryMovesReader.h | 10 +- .../PokemonFRLG_BattleFlashWatcher.cpp | 8 +- .../PokemonFRLG_BattleFlashWatcher.h | 6 +- .../PokemonFRLG_BattleHpBarReader.cpp | 8 +- .../Inference/PokemonFRLG_BattleHpBarReader.h | 8 +- .../PokemonFRLG_BattleScreenDetector.cpp | 6 +- .../PokemonFRLG_BattleScreenDetector.h | 8 +- .../Overworld/PokemonFRLG_OverworldMap.cpp | 10 +- .../Overworld/PokemonFRLG_OverworldMap.h | 24 +++- .../Overworld/PokemonFRLG_OverworldMaps.cpp | 8 +- .../Overworld/PokemonFRLG_OverworldMaps.h | 7 +- .../PokemonFRLG_OverworldMaps_Tests.cpp | 84 ++++++++--- .../PokemonFRLG_OverworldReanchor.cpp | 8 +- .../Overworld/PokemonFRLG_OverworldReanchor.h | 9 +- .../PokemonFRLG_OverworldReanchor_Tests.cpp | 68 +++++++-- .../PokemonFRLG_OverworldRecovery.cpp | 8 +- .../Overworld/PokemonFRLG_OverworldRecovery.h | 7 +- .../PokemonFRLG_OverworldRecoveryWalk.cpp | 8 +- .../PokemonFRLG_OverworldRecoveryWalk.h | 6 +- .../PokemonFRLG_OverworldRecovery_Tests.cpp | 83 ++++++++--- .../Overworld/PokemonFRLG_OverworldRoute.cpp | 14 +- .../Overworld/PokemonFRLG_OverworldRoute.h | 14 +- .../Overworld/PokemonFRLG_OverworldWalk.cpp | 10 +- .../Overworld/PokemonFRLG_OverworldWalk.h | 27 ++-- .../PokemonFRLG_OverworldWalk_Tests.cpp | 126 ++++++++-------- .../PokemonFRLG_PlayerFacingReader.cpp | 10 +- .../PokemonFRLG_PlayerFacingReader.h | 7 +- .../AutoStory/PokemonFRLG_AutoStory.cpp | 10 +- .../AutoStory/PokemonFRLG_AutoStory.h | 8 +- .../PokemonFRLG_AutoStoryActions.cpp | 12 +- .../AutoStory/PokemonFRLG_AutoStoryActions.h | 12 +- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 8 +- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 11 +- .../PokemonFRLG_AutoStoryBattleData.cpp | 8 +- .../PokemonFRLG_AutoStoryBattleData.h | 14 +- .../PokemonFRLG_AutoStoryBattleData_Tests.cpp | 63 ++++++-- .../PokemonFRLG_AutoStoryBattleDecisions.cpp | 8 +- .../PokemonFRLG_AutoStoryBattleDecisions.h | 12 +- .../PokemonFRLG_AutoStoryBattleSim.cpp | 8 +- .../PokemonFRLG_AutoStoryBattleSim.h | 9 +- .../PokemonFRLG_AutoStoryBattleSim_Tests.cpp | 93 +++++++++--- .../AutoStory/PokemonFRLG_AutoStoryDamage.cpp | 8 +- .../AutoStory/PokemonFRLG_AutoStoryDamage.h | 10 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 8 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 10 +- .../PokemonFRLG_AutoStoryFoeTracker.cpp | 8 +- .../PokemonFRLG_AutoStoryFoeTracker.h | 7 +- .../PokemonFRLG_AutoStoryItems_Tests.cpp | 73 +++++++--- .../AutoStory/PokemonFRLG_AutoStoryParty.cpp | 8 +- .../AutoStory/PokemonFRLG_AutoStoryParty.h | 10 +- .../PokemonFRLG_AutoStoryParty_Tests.cpp | 134 ++++++++++++++---- .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 61 +++++--- .../PokemonFRLG_AutoStorySummary.cpp | 8 +- .../AutoStory/PokemonFRLG_AutoStorySummary.h | 6 +- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 8 +- .../AutoStory/PokemonFRLG_AutoStoryTable.h | 7 +- .../PokemonFRLG_AutoStoryWinChance.cpp | 8 +- .../PokemonFRLG_AutoStoryWinChance.h | 7 +- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 93 +++++++++--- 68 files changed, 978 insertions(+), 443 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp index b37226995b..814ece7a7f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp @@ -85,7 +85,7 @@ ImageViewRGB32 game_box(const ImageViewRGB32& screen){ return extract_box_reference(screen, GameSettings::instance().GAME_BOX); } -} +} // namespace ImageFloatBox item_list_name_box(int row){ @@ -195,7 +195,7 @@ class Test_MartList : public ImageUnitTest{ } }; -} +} // namespace void add_tests_ItemListReader(UnitTestDatabase& database){ // FireRed on console B, 2026-11-02, after the Viridian Mart: the 5 and @@ -211,6 +211,6 @@ void add_tests_ItemListReader(UnitTestDatabase& database){ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h index cddeb636c6..3b8216ba95 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h @@ -32,6 +32,7 @@ constexpr int ITEM_LIST_ROWS = 6; // Where row `row` (from 0) of a list shows its item's name, and in the bag // its count, as fractions of the game screen. ImageFloatBox item_list_name_box(int row); +// Where row `row` of the bag shows its item count. ImageFloatBox bag_item_count_box(int row); // The item named in row `row`: a slug such as "potion", "antidote", @@ -40,6 +41,7 @@ ImageFloatBox bag_item_count_box(int row); // reader has no names for. std::string read_item_list_name(Logger& logger, Language language, const ImageViewRGB32& screen, int row); +// A single item entry in the bag pocket. struct BagRow{ // The item's slug, as read_item_list_name() gives it; empty if its name // can't be read. @@ -62,11 +64,12 @@ std::vector read_bag_pocket(Logger& logger, Language language, const Ima std::vector pocket_rows(std::vector reads); +// Registers item list reader unit tests. void add_tests_ItemListReader(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp index c92e0d883e..319344ca59 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp @@ -28,7 +28,7 @@ bool is_keyboard_color(const ImageViewRGB32& image, const FloatPixel& color){ return is_solid(image, color, 0.08, 30); } -} +} // namespace // Boxes are fractions of the 240x160 GBA screen inside the game box. @@ -60,6 +60,6 @@ bool NamingScreenDetector::detect(const ImageViewRGB32& screen){ } -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h index c486fbf9bf..96d9c9499f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h @@ -27,6 +27,7 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ +// Detects the character/pokemon naming screen keyboard. class NamingScreenDetector : public StaticScreenDetector{ public: NamingScreenDetector(Color color = COLOR_RED); @@ -42,6 +43,7 @@ class NamingScreenDetector : public StaticScreenDetector{ // The text entry window, right of the last character. ImageFloatBox m_entry_box; }; +// Visual watcher for the naming screen keyboard. class NamingScreenWatcher : public DetectorToFinder{ public: NamingScreenWatcher(Color color = COLOR_RED) @@ -50,8 +52,8 @@ class NamingScreenWatcher : public DetectorToFinder{ }; -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp index bd099bb1da..3894ccace8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp @@ -127,7 +127,7 @@ const OptionItem& option_item(OptionMenuItem item){ return text_speed; } -} +} // namespace const char* option_menu_name(OptionMenuItem item){ @@ -187,7 +187,7 @@ class Test_OptionMenu : public ImageUnitTest{ } }; -} +} // namespace void add_tests_OptionMenuReader(UnitTestDatabase& database){ // FireRed on console B, 2026-11-02: the menu as a new game opens it, @@ -200,6 +200,6 @@ void add_tests_OptionMenuReader(UnitTestDatabase& database){ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h index 77dd54e53e..0d6223eb54 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h @@ -53,11 +53,12 @@ ImageFloatBox option_value_box(size_t row); std::string read_option_value(Logger& logger, Language language, const ImageViewRGB32& screen, OptionMenuItem item); +// Registers option menu reader unit tests. void add_tests_OptionMenuReader(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp index 702d314298..b132983210 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp @@ -79,7 +79,7 @@ class PlaceNameMatcher : public OCR::SmallDictionaryMatcher{ } }; -} +} // namespace ImageFloatBox save_card_title_box(){ @@ -123,7 +123,7 @@ class Test_SaveCard : public ImageUnitTest{ } }; -} +} // namespace void add_tests_SaveCardReader(UnitTestDatabase& database){ // FireRed on console B, 2026-11-02. The card covers the same corner of @@ -138,6 +138,6 @@ void add_tests_SaveCardReader(UnitTestDatabase& database){ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h index 8a037e0242..e8cc916122 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h @@ -35,11 +35,12 @@ ImageFloatBox save_card_title_box(); std::string read_save_card_location(Logger& logger, Language language, const ImageViewRGB32& screen); +// Registers save card reader unit tests. void add_tests_SaveCardReader(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp index 0fd8d48b8e..66c68224cf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp @@ -178,7 +178,7 @@ int read_pp(Logger& logger, const ImageViewRGB32& screen, const ImageFloatBox& b return pp >= 0 && pp <= 64 ? pp : -1; } -} +} // namespace ImageFloatBox summary_move_name_box(size_t row){ @@ -298,7 +298,7 @@ class Test_SummaryScreen : public ImageUnitTest{ } }; -} +} // namespace void add_tests_SummaryMovesReader(UnitTestDatabase& database){ // FireRed on console B, 2026-11-02: the story's Squirtle at Lv16, not @@ -315,6 +315,6 @@ void add_tests_SummaryMovesReader(UnitTestDatabase& database){ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h index dc4202857d..f5bd20bf27 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h @@ -40,7 +40,9 @@ constexpr size_t SUMMARY_MOVE_ROWS = 5; // Where row `row` (from 0) shows its move's name, its current PP and its // full PP, as fractions of the game screen. ImageFloatBox summary_move_name_box(size_t row); +// Where row `row` of summary moves shows its current PP. ImageFloatBox summary_move_pp_box(size_t row); +// Where row `row` of summary moves shows its max PP. ImageFloatBox summary_move_max_pp_box(size_t row); // The move named in row `row`: a slug such as "water-gun", in a game in @@ -52,6 +54,7 @@ std::string read_summary_move_name(Logger& logger, Language language, const Imag // a light background, such as a TM CASE row's; empty as above. std::string read_move_name(Logger& logger, Language language, const ImageViewRGB32& name); +// A single move entry read from the summary moves screen. struct SummaryMove{ std::string move; // -1 if not read. The game draws a move's PP in color once it is down @@ -67,11 +70,12 @@ std::vector read_summary_moves(Logger& logger, Language language, c std::optional read_summary_move_cursor(const ImageViewRGB32& screen); +// Registers summary moves reader unit tests. void add_tests_SummaryMovesReader(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.cpp index f7174de9b8..5540cc153b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.cpp @@ -28,7 +28,7 @@ constexpr double FLASH_DARKER = 0.8; // the dip is below this much of the br constexpr double FLASH_FLOOR = 0.4; // and above this much: lower is a fade to black constexpr double FLASH_RECOVERY = 1.1; // then the screen comes back to this much of the dip -} +} // namespace BattleFlashWatcher::BattleFlashWatcher(Color color) @@ -71,6 +71,6 @@ bool BattleFlashWatcher::process_frame(const ImageViewRGB32& frame, WallClock ti -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h index a705d3473c..f73884f5fc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h @@ -40,7 +40,7 @@ class BattleFlashWatcher : public VisualInferenceCallback{ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp index 0d2c517a28..4b8905da59 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp @@ -52,7 +52,7 @@ std::optional fill_color(uint32_t pixel){ return std::nullopt; } -} +} // namespace HpBarReading read_player_hp_bar(const ImageViewRGB32& game){ @@ -82,6 +82,6 @@ HpBarReading read_player_hp_bar(const ImageViewRGB32& game){ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h index 0a34d8677e..163a7be512 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h @@ -17,12 +17,14 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ +// Color classification of an HP bar. enum class HpBarColor{ GREEN, // over half YELLOW, // over a fifth RED, }; +// Parsed health bar reading indicating fraction and health state color. struct HpBarReading{ // Some of the bar is filled. bool seen = false; @@ -37,7 +39,7 @@ HpBarReading read_player_hp_bar(const ImageViewRGB32& game); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp index a3ac1c9106..78da90a3c2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp @@ -31,6 +31,6 @@ bool BattleScreenDetector::detect(const ImageViewRGB32& screen){ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h index ac4257c707..88516f4313 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h @@ -25,6 +25,7 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ +// Detects active overworld battle screen interface. class BattleScreenDetector : public StaticScreenDetector{ public: BattleScreenDetector(Color color = COLOR_RED); @@ -39,6 +40,7 @@ class BattleScreenDetector : public StaticScreenDetector{ BattlePokemonDetector m_player; }; +// Visual watcher for battle screen transition. class BattleScreenWatcher : public DetectorToFinder{ public: BattleScreenWatcher(Color color = COLOR_RED) @@ -48,7 +50,7 @@ class BattleScreenWatcher : public DetectorToFinder{ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp index e0fc1a339e..5171db55b0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp @@ -86,7 +86,7 @@ std::optional warp_entry(const MapData& map, const TilePos& point){ return warp->enter; } -} +} // namespace bool blocks_entering(const MapData& map, const TilePos& point, Direction direction){ // Moving south enters by the north edge. @@ -158,7 +158,7 @@ bool sees_from(const MapData& map, const Pokemon::MapTrainer& trainer, const Til return false; } -} +} // namespace const MapObject* object_at(const MapData& map, const TilePos& point){ for (const MapObject& object : map.objects){ @@ -247,6 +247,6 @@ PlayerState after_step_onto( -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h index 399d5f0537..e4dc68dc2f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h @@ -27,14 +27,23 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ +// Direction enum from Pokemon navigation. using Pokemon::Direction; +// Grid tile coordinates. using Pokemon::TilePos; +// Classification of tile terrain. using Pokemon::TileKind; +// Parsed map representation. using Pokemon::MapData; +// Warp point connection. using Pokemon::MapWarp; +// Entity object on a map. using Pokemon::MapObject; +// Inter-map border connection. using Pokemon::MapConnection; +// Warp entry trigger definition. using Pokemon::WarpEntry; +// Finds warp located at specific tile coordinates. using Pokemon::warp_at; @@ -65,18 +74,25 @@ constexpr uint8_t ELEVATION_GROUND = 3; // way. // A map without an elevation grid is all ground. +// Whether the given point falls within the map bounds. bool in_bounds(const MapData& map, const TilePos& point); // Out-of-bounds tiles are walls. TileKind tile_at(const MapData& map, const TilePos& point); +// Returns the elevation index at the given coordinate. uint8_t elevation_at(const MapData& map, const TilePos& point); +// Whether the tile at point is unwalkable wall terrain. bool is_wall(const MapData& map, const TilePos& point); +// Whether the tile at point is water terrain. bool is_water(const MapData& map, const TilePos& point); +// Whether the tile at point is tall grass terrain. bool is_tall_grass(const MapData& map, const TilePos& point); +// Whether the tile at point is a one-way ledge. bool is_ledge(const MapData& map, const TilePos& point); // Whether the tile itself refuses a step in `direction`: entering it, or // leaving it. bool blocks_entering(const MapData& map, const TilePos& point, Direction direction); +// Whether leaving the tile in the given direction is blocked. bool blocks_leaving(const MapData& map, const TilePos& point, Direction direction); // Whether the game takes this tile's warp on stepping onto it (a ladder or @@ -110,6 +126,7 @@ struct PlayerState{ bool surfing = false; }; +// Classification of movement result when taking a step. enum class StepKind{ BLOCKED, WALK, // moves one tile (on land, or on water while surfing) @@ -130,6 +147,7 @@ StepKind classify_step_onto( // The player after a step of kind WALK, STOP_SURFING or START_SURF (the // Surf action moves the player onto the water). PlayerState after_step(const MapData& map, const PlayerState& state, Direction direction, StepKind kind); +// The player state resulting from stepping across map boundaries. PlayerState after_step_onto( const MapData& from, const PlayerState& state, const MapData& to, const TilePos& destination, StepKind kind @@ -137,7 +155,7 @@ PlayerState after_step_onto( -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp index 0f7514fe28..2223f68f10 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp @@ -58,7 +58,7 @@ const std::vector& all_maps(){ return MAPS; } -} +} // namespace MapData parse_map(const std::string& json, const std::string& source){ @@ -113,6 +113,6 @@ std::set map_flag_set(const std::vector& maps, const std:: -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h index cff0668eb5..84a6745fd8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h @@ -61,11 +61,12 @@ TilePos map_point(const std::vector& maps, const std::string& map, cons std::set map_flag_set(const std::vector& maps, const std::string& name); +// Registers overworld map unit tests. void add_tests_OverworldMaps(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp index b9c82f093f..4bed71ad17 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp @@ -20,22 +20,36 @@ namespace PokemonFRLG{ namespace{ +struct OverworldMapsInput{ + std::string name; + UnitTestResult (*body)(); +}; + +struct OverworldMapsExpectation{ + const char* description; +}; + +struct OverworldMapsTestCase{ + OverworldMapsInput input; + OverworldMapsExpectation expectation; +}; + class Test_OverworldMaps : public UnitTest{ public: - Test_OverworldMaps(std::string name, std::function body) - : UnitTest("PokemonFRLG::OverworldMaps - " + std::move(name)) - , m_body(std::move(body)) + explicit Test_OverworldMaps(OverworldMapsTestCase scenario) + : UnitTest("PokemonFRLG::OverworldMaps - " + scenario.input.name) + , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ try{ - return m_body(); + return m_scenario.input.body(); }catch (Exception& e){ return std::string(e.name()) + ": " + e.message(); } } private: - std::function m_body; + OverworldMapsTestCase m_scenario; }; @@ -236,23 +250,57 @@ UnitTestResult test_no_hold_onto_escalator(){ return true; } -} + +const OverworldMapsTestCase OVERWORLD_MAPS_CASES[] = { + { + .input = {.name = "valid map", .body = test_valid_map}, + .expectation = {.description = "parses valid map json and properties"}, + }, + { + .input = {.name = "missing field", .body = test_missing_field}, + .expectation = {.description = "detects missing required fields in map json"}, + }, + { + .input = {.name = "elevation left out", .body = test_elevation_left_out}, + .expectation = {.description = "handles omitted elevation data cleanly"}, + }, + { + .input = {.name = "field of the wrong type", .body = test_bad_field_type}, + .expectation = {.description = "rejects invalid field types in map json"}, + }, + { + .input = {.name = "row of the wrong length", .body = test_bad_row_length}, + .expectation = {.description = "rejects rows not matching declared width"}, + }, + { + .input = {.name = "unknown tile", .body = test_unknown_tile}, + .expectation = {.description = "rejects unmapped character codes in tile map"}, + }, + { + .input = {.name = "not JSON", .body = test_not_json}, + .expectation = {.description = "rejects malformed json input string"}, + }, + { + .input = {.name = "trainer sight", .body = test_trainer_sight}, + .expectation = {.description = "evaluates line of sight for trainer objects"}, + }, + { + .input = {.name = "no hold onto an escalator", .body = test_no_hold_onto_escalator}, + .expectation = {.description = "prevents holding into an escalator"}, + }, +}; + +} // namespace void add_tests_OverworldMaps(UnitTestDatabase& database){ - database.add("valid map", test_valid_map); - database.add("missing field", test_missing_field); - database.add("elevation left out", test_elevation_left_out); - database.add("field of the wrong type", test_bad_field_type); - database.add("row of the wrong length", test_bad_row_length); - database.add("unknown tile", test_unknown_tile); - database.add("not JSON", test_not_json); - database.add("trainer sight", test_trainer_sight); - database.add("no hold onto an escalator", test_no_hold_onto_escalator); + for (const auto& scenario : OVERWORLD_MAPS_CASES){ + database.add(scenario); + } } -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp index 27b28bb54d..b8fdbf7c43 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp @@ -270,7 +270,7 @@ std::vector find_player( return found; } -} +} // namespace WalkedTiles walked_near(const RouteStep& step, int estimate, Milliseconds tile_time){ @@ -369,6 +369,6 @@ std::optional plan_reanchor( -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h index 9037aa83ce..c4aaa0ba4f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h @@ -67,6 +67,7 @@ struct StopCandidate{ bool operator==(const StopCandidate& other) const = default; }; +// Formats a StopCandidate as a string. std::string to_string(const StopCandidate& candidate); // Where `step`, an open WALK from `start`, may have been stopped: @@ -84,6 +85,7 @@ std::vector stop_candidates( WalkedTiles walked ); +// A candidate reanchor route step with its cost estimate. struct Reanchor{ // Legs to walls, in order, that bring the player to `found` from every // candidate; none if there was only one. Each but the last ends on a @@ -105,11 +107,12 @@ std::optional plan_reanchor( ); +// Registers overworld reanchor unit tests. void add_tests_OverworldReanchor(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp index bbc2cf72f5..8e91a54445 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp @@ -25,22 +25,36 @@ namespace PokemonFRLG{ namespace{ +struct OverworldReanchorInput{ + std::string name; + UnitTestResult (*body)(); +}; + +struct OverworldReanchorExpectation{ + const char* description; +}; + +struct OverworldReanchorTestCase{ + OverworldReanchorInput input; + OverworldReanchorExpectation expectation; +}; + class Test_OverworldReanchor : public UnitTest{ public: - Test_OverworldReanchor(std::string name, std::function body) - : UnitTest("PokemonFRLG::OverworldReanchor - " + std::move(name)) - , m_body(std::move(body)) + explicit Test_OverworldReanchor(OverworldReanchorTestCase scenario) + : UnitTest("PokemonFRLG::OverworldReanchor - " + scenario.input.name) + , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ try{ - return m_body(); + return m_scenario.input.body(); }catch (Exception& e){ return std::string(e.name()) + ": " + e.message(); } } private: - std::function m_body; + OverworldReanchorTestCase m_scenario; }; std::string describe(const std::vector& route){ @@ -227,20 +241,44 @@ UnitTestResult test_person_in_the_way(){ } -} +const OverworldReanchorTestCase OVERWORLD_REANCHOR_CASES[] = { + { + .input = {.name = "rules", .body = test_rules}, + .expectation = {.description = "tests reanchor candidate generation and rules"}, + }, + { + .input = {.name = "timing", .body = test_timing}, + .expectation = {.description = "verifies reanchor hold durations and timing"}, + }, + { + .input = {.name = "a person in the way", .body = test_person_in_the_way}, + .expectation = {.description = "avoids planning reanchor into dynamic map obstacle"}, + }, + { + .input = {.name = "Viridian Mart to Oak's Lab", .body = test_viridian_mart_to_oaks_lab}, + .expectation = {.description = "reanchors along route from Viridian Mart to Oak's Lab"}, + }, + { + .input = {.name = "Pallet Town to Viridian Mart", .body = test_pallet_to_viridian_mart}, + .expectation = {.description = "reanchors along route from Pallet Town to Viridian Mart"}, + }, + { + .input = {.name = "Viridian Forest", .body = test_viridian_forest}, + .expectation = {.description = "reanchors along route through Viridian Forest"}, + }, +}; + +} // namespace void add_tests_OverworldReanchor(UnitTestDatabase& database){ - database.add("rules", test_rules); - database.add("timing", test_timing); - database.add("a person in the way", test_person_in_the_way); - database.add("Viridian Mart to Oak's Lab", test_viridian_mart_to_oaks_lab); - database.add("Pallet Town to Viridian Mart", test_pallet_to_viridian_mart); - database.add("Viridian Forest", test_viridian_forest); + for (const auto& scenario : OVERWORLD_REANCHOR_CASES){ + database.add(scenario); + } } -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp index 1a907f7a06..7e37bafded 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp @@ -320,7 +320,7 @@ class RouteRun{ size_t m_holds = 0; // of the plan, holds to walls that find the player }; -} +} // namespace std::optional trainer_crossing( @@ -353,6 +353,6 @@ void run_route( -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h index 3e15603f4d..e5ac8ab70b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h @@ -124,11 +124,12 @@ void run_route( ); +// Registers overworld recovery unit tests. void add_tests_OverworldRecovery(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp index 9100f08d3f..c57672d043 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp @@ -199,7 +199,7 @@ bool moved_past_wall(ConsoleHandle& console, ProControllerContext& context, cons return change > WALL_TAP_MOVED_RMSD; } -} +} // namespace void walk_overworld_route_with_recovery( @@ -241,6 +241,6 @@ void walk_overworld_route_with_recovery( -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h index aedadc9332..5f24a07949 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h @@ -63,7 +63,7 @@ void walk_overworld_route_with_recovery( -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp index 453872473e..7f404a1ec0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp @@ -28,22 +28,36 @@ namespace PokemonFRLG{ namespace{ +struct OverworldRecoveryInput{ + std::string name; + UnitTestResult (*body)(); +}; + +struct OverworldRecoveryExpectation{ + const char* description; +}; + +struct OverworldRecoveryTestCase{ + OverworldRecoveryInput input; + OverworldRecoveryExpectation expectation; +}; + class Test_OverworldRecovery : public UnitTest{ public: - Test_OverworldRecovery(std::string name, std::function body) - : UnitTest("PokemonFRLG::OverworldRecovery - " + std::move(name)) - , m_body(std::move(body)) + explicit Test_OverworldRecovery(OverworldRecoveryTestCase scenario) + : UnitTest("PokemonFRLG::OverworldRecovery - " + scenario.input.name) + , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ try{ - return m_body(); + return m_scenario.input.body(); }catch (Exception& e){ return std::string(e.name()) + ": " + e.message(); } } private: - std::function m_body; + OverworldRecoveryTestCase m_scenario; }; // Steps that end as scripted, by the order they are walked in; DONE if not. @@ -481,23 +495,56 @@ UnitTestResult test_grass_in_sight(){ return expect_logged(script.logs, {"Robin (3, 1) (stopped by a trainer, now at (3, 2))"}); } -} +const OverworldRecoveryTestCase OVERWORLD_RECOVERY_CASES[] = { + { + .input = {.name = "stop, recover, resume", .body = test_stop_recover_resume}, + .expectation = {.description = "verifies full stop, recovery reanchor, and resume sequence"}, + }, + { + .input = {.name = "no recovery", .body = test_no_recovery}, + .expectation = {.description = "handles clean runs where no recovery interruption occurs"}, + }, + { + .input = {.name = "legs to a wall", .body = test_wall_legs}, + .expectation = {.description = "tests wall-stopping leg recovery"}, + }, + { + .input = {.name = "a leg to a warp", .body = test_warp_leg}, + .expectation = {.description = "tests warp arrival leg recovery"}, + }, + { + .input = {.name = "the route is logged", .body = test_route_logged}, + .expectation = {.description = "verifies route execution logging and breadcrumbs"}, + }, + { + .input = {.name = "a leg to a wall ends at it", .body = test_wall_check}, + .expectation = {.description = "validates arrival position at wall terminator"}, + }, + { + .input = {.name = "a leg crosses a trainer's sight", .body = test_trainer_crossing}, + .expectation = {.description = "recovers when traversing through trainer vision cones"}, + }, + { + .input = {.name = "a trainer stops a leg", .body = test_trainer_stops_leg}, + .expectation = {.description = "handles forced stop and battle start from trainer challenge"}, + }, + { + .input = {.name = "a stop on the grass in a trainer's sight", .body = test_grass_in_sight}, + .expectation = {.description = "handles wild encounter in trainer sight line"}, + }, +}; + +} // namespace void add_tests_OverworldRecovery(UnitTestDatabase& database){ - database.add("stop, recover, resume", test_stop_recover_resume); - database.add("no recovery", test_no_recovery); - database.add("legs to a wall", test_wall_legs); - database.add("a leg to a warp", test_warp_leg); - database.add("the route is logged", test_route_logged); - database.add("a leg to a wall ends at it", test_wall_check); - database.add("a leg crosses a trainer's sight", test_trainer_crossing); - database.add("a trainer stops a leg", test_trainer_stops_leg); - database.add("a stop on the grass in a trainer's sight", test_grass_in_sight); + for (const auto& scenario : OVERWORLD_RECOVERY_CASES){ + database.add(scenario); + } } -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp index 6e63bc8ed4..9bafa42c91 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp @@ -362,7 +362,7 @@ RouteStep to_route_step(const std::vector& maps, const Pokemon::Leg plain_step(const std::vector& maps, const Locate return transition->next; } -} +} // namespace namespace{ @@ -442,7 +442,7 @@ bool ledge_stops_north(const std::vector& maps, const Located& player, return direction == Direction::NORTH && is_ledge(maps[player.map], player.state.position.next(direction)); } -} +} // namespace std::optional hold_to_wall( const std::vector& maps, @@ -967,7 +967,7 @@ UnitTestResult test_ground_only_elevation_left_out(){ return true; } -} +} // namespace void add_tests_OverworldRoute(UnitTestDatabase& database){ database.add("route through a warp", test_route_through_warp); @@ -988,6 +988,6 @@ void add_tests_OverworldRoute(UnitTestDatabase& database){ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h index ce5d6f872b..a3c659ba8c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h @@ -25,21 +25,25 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ +// Position on a specific map. struct MapPosition{ std::string map; TilePos point; bool operator==(const MapPosition& other) const = default; }; +// Formats a MapPosition as a string. std::string to_string(const MapPosition& position); +// Action associated with reaching a route waypoint. enum class RouteAction{ WALK, // hold `direction` for `tiles` tiles SURF, // face `direction`, use Surf, and land on the water there FACE, // turn to `direction` without moving }; +// A single step along an overworld path. struct RouteStep{ RouteAction action = RouteAction::WALK; Direction direction = Direction::NORTH; @@ -62,9 +66,11 @@ struct RouteStep{ // Where the player is after the step. MapPosition end; }; +// Formats a RouteStep as a string. std::string to_string(const RouteStep& step); +// Navigation goal specification. struct RouteGoal{ MapPosition position; // Which way to face on arrival, e.g. towards a Pokemon to talk to. @@ -88,6 +94,7 @@ enum class RouteCost{ // (console B, 2026-11-01, Route 1, four runs). OPEN_WILD_STOP, }; +// Cost mapping table for path planning. using RouteCosts = std::map; // TILE 1, TURN 2, WARP 30, SURF 40, GRASS_TILE 20, OPEN_STOP 8, @@ -141,11 +148,12 @@ MapPosition follow_overworld_route( ); +// Registers overworld route unit tests. void add_tests_OverworldRoute(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp index 348b57bcf6..b60f08dbcc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp @@ -151,7 +151,7 @@ Pokemon::LegSpec leg_spec(const RouteStep& step, MoveSpeed speed){ return Pokemon::LegSpec{step.direction, step.tiles, step.to_wall, tile_time(step, speed)}; } -} +} // namespace namespace OverworldWalkSteps{ @@ -325,7 +325,7 @@ void start_surf(ConsoleHandle& console, ProControllerContext& context, Direction pbf_wait(context, SURF_ANIMATION); } -} +} // namespace OverworldWalkSteps @@ -440,6 +440,6 @@ void walk_overworld_route( -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h index 2c3b665033..e98eb4e20b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h @@ -35,6 +35,7 @@ namespace PokemonFRLG{ // Something that stops the player part-way through a leg: a wild battle, a // message. See Pokemon::LegInterrupt. using OverworldInterrupt = Pokemon::LegInterrupt; +// Overworld movement interruption triggers. using OverworldInterrupts = Pokemon::LegInterrupts; // What to watch for on a route's steps: `wild` on steps where a wild @@ -68,6 +69,7 @@ enum class MoveSpeed{ WALK, RUN, }; +// Name of a movement speed. const char* move_speed_name(MoveSpeed speed); @@ -90,14 +92,20 @@ void walk_overworld_route( // walk_overworld_route() describes. namespace OverworldWalkSteps{ -inline constexpr Milliseconds TILE_TIME(267); // 16 frames at 60 fps, measured exact over 15 tiles -inline constexpr Milliseconds SURF_TILE_TIME(133); // the game moves a surfing player at running speed +// Walking duration for a single tile (16 frames at 60 fps). +inline constexpr Milliseconds TILE_TIME(267); +// Surfing duration for a single tile. +inline constexpr Milliseconds SURF_TILE_TIME(133); // 8 frames: running is 2 pixels a frame, twice walking. Not measured on the // console yet; the walker logs each leg to a wall (speed_note()) for that. inline constexpr Milliseconds RUN_TILE_TIME(133); -inline constexpr Milliseconds TURN_TAP(40); // turns a player facing another way, without a step +// turns a player facing another way, without a step. +inline constexpr Milliseconds TURN_TAP(40); +// duration to wait after turning to allow state to settle. inline constexpr Milliseconds TURN_SETTLE(300); -inline constexpr Milliseconds FACE_HOLD(40); // short enough to turn without stepping +// short enough to turn without stepping. +inline constexpr Milliseconds FACE_HOLD(40); +// duration of button release between movement steps. inline constexpr Milliseconds STEP_RELEASE(100); // After a warp's fade: leaving by a door the game walks the player a tile out // on its own, and a leg started before that ends loses tiles (on the console a @@ -117,8 +125,10 @@ inline constexpr Milliseconds AFTER_LEG_WATCH(500); inline constexpr Milliseconds AFTER_WILD_LEG_WATCH(3500); // How long clear_open_message() watches for the message it saw. inline constexpr Milliseconds OPEN_MESSAGE_WATCH(1000); +// Maximum interruptions before a leg is abandoned. inline constexpr size_t MAX_INTERRUPTIONS_PER_LEG = 5; +// Maps Direction to corresponding DpadPosition. DpadPosition dpad(Direction direction); // The leg mover: holds the D-pad. FRLG moves exactly a tile per 16 frames. @@ -170,14 +180,15 @@ std::optional read_facing(ConsoleHandle& console, ProControllerContex // Facing `direction` (turning first unless `facing_water`), starts Surf. void start_surf(ConsoleHandle& console, ProControllerContext& context, Direction direction, bool facing_water); -} +} // namespace OverworldWalkSteps +// Registers overworld walk unit tests. void add_tests_OverworldWalk(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp index 8265cb6bd2..ce03db9c52 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp @@ -20,82 +20,92 @@ using namespace OverworldWalkSteps; namespace{ +struct OverworldWalkInput{ + const char* name; + MoveSpeed speed; + int tiles; + bool to_wall; + bool surfing; +}; + +struct OverworldWalkExpectation{ + Milliseconds hold; + const char* note; +}; + +struct OverworldWalkTestCase{ + OverworldWalkInput input; + OverworldWalkExpectation expectation; +}; + class Test_OverworldWalk : public UnitTest{ public: - Test_OverworldWalk(std::string name, std::function body) - : UnitTest("PokemonFRLG::OverworldWalk - " + std::move(name)) - , m_body(std::move(body)) + explicit Test_OverworldWalk(OverworldWalkTestCase scenario) + : UnitTest("PokemonFRLG::OverworldWalk - hold: " + std::string(scenario.input.name)) + , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - return m_body(); + RouteStep step; + step.direction = Direction::WEST; + step.tiles = m_scenario.input.tiles; + step.to_wall = m_scenario.input.to_wall; + step.surfing = m_scenario.input.surfing; + const Milliseconds hold = leg_hold_time(step, m_scenario.input.speed); + if (hold != m_scenario.expectation.hold){ + return std::format("Expected a hold of {}ms, got {}ms.", m_scenario.expectation.hold.count(), hold.count()); + } + const std::string note = speed_note(step, m_scenario.input.speed); + if (note != m_scenario.expectation.note){ + return "Expected the note \"" + std::string(m_scenario.expectation.note) + "\", got \"" + note + "\"."; + } + return true; } private: - std::function m_body; -}; - - -struct HoldCase{ - std::string name; - MoveSpeed speed; - int tiles; - bool to_wall; - bool surfing; - // How long the D-pad is held. - Milliseconds hold; - // speed_note()'s line, or empty. - std::string note; + OverworldWalkTestCase m_scenario; }; // An open leg lets go half a tile before its last step would end; a leg // to a wall is held two tiles longer. Walking is 267ms a tile, running and // surfing 133ms. -const std::vector& hold_cases(){ - static const std::vector cases{ - {.name = "walk, open", .speed = MoveSpeed::WALK, .tiles = 5, .to_wall = false, .surfing = false, - .hold = Milliseconds(4 * 267 + 133), .note = ""}, - {.name = "walk, to a wall", .speed = MoveSpeed::WALK, .tiles = 5, .to_wall = true, .surfing = false, - .hold = Milliseconds(7 * 267), .note = "[Speed] walk west: 5 tiles in 1335 ms, held 1869 ms"}, - {.name = "run, open", .speed = MoveSpeed::RUN, .tiles = 5, .to_wall = false, .surfing = false, - .hold = Milliseconds(4 * 133 + 66), .note = ""}, - {.name = "run, to a wall", .speed = MoveSpeed::RUN, .tiles = 40, .to_wall = true, .surfing = false, - .hold = Milliseconds(42 * 133), .note = "[Speed] run west: 40 tiles in 5320 ms, held 5586 ms"}, - {.name = "run, surfing to a wall", .speed = MoveSpeed::RUN, .tiles = 3, .to_wall = true, .surfing = true, - .hold = Milliseconds(5 * 133), .note = ""}, - {.name = "walk, surfing", .speed = MoveSpeed::WALK, .tiles = 3, .to_wall = false, .surfing = true, - .hold = Milliseconds(2 * 133 + 66), .note = ""}, - }; - return cases; -} - -UnitTestResult check_hold(const HoldCase& test){ - RouteStep step; - step.direction = Direction::WEST; - step.tiles = test.tiles; - step.to_wall = test.to_wall; - step.surfing = test.surfing; - const Milliseconds hold = leg_hold_time(step, test.speed); - if (hold != test.hold){ - return std::format("Expected a hold of {}ms, got {}ms.", test.hold.count(), hold.count()); - } - const std::string note = speed_note(step, test.speed); - if (note != test.note){ - return "Expected the note \"" + test.note + "\", got \"" + note + "\"."; - } - return true; -} +const OverworldWalkTestCase OVERWORLD_WALK_CASES[] = { + { + .input = {.name = "walk, open", .speed = MoveSpeed::WALK, .tiles = 5, .to_wall = false, .surfing = false}, + .expectation = {.hold = Milliseconds(4 * 267 + 133), .note = ""}, + }, + { + .input = {.name = "walk, to a wall", .speed = MoveSpeed::WALK, .tiles = 5, .to_wall = true, .surfing = false}, + .expectation = {.hold = Milliseconds(7 * 267), .note = "[Speed] walk west: 5 tiles in 1335 ms, held 1869 ms"}, + }, + { + .input = {.name = "run, open", .speed = MoveSpeed::RUN, .tiles = 5, .to_wall = false, .surfing = false}, + .expectation = {.hold = Milliseconds(4 * 133 + 66), .note = ""}, + }, + { + .input = {.name = "run, to a wall", .speed = MoveSpeed::RUN, .tiles = 40, .to_wall = true, .surfing = false}, + .expectation = {.hold = Milliseconds(42 * 133), .note = "[Speed] run west: 40 tiles in 5320 ms, held 5586 ms"}, + }, + { + .input = {.name = "run, surfing to a wall", .speed = MoveSpeed::RUN, .tiles = 3, .to_wall = true, .surfing = true}, + .expectation = {.hold = Milliseconds(5 * 133), .note = ""}, + }, + { + .input = {.name = "walk, surfing", .speed = MoveSpeed::WALK, .tiles = 3, .to_wall = false, .surfing = true}, + .expectation = {.hold = Milliseconds(2 * 133 + 66), .note = ""}, + }, +}; -} +} // namespace void add_tests_OverworldWalk(UnitTestDatabase& database){ - for (const HoldCase& test : hold_cases()){ - database.add("hold: " + test.name, [&test]{ return check_hold(test); }); + for (const auto& scenario : OVERWORLD_WALK_CASES){ + database.add(scenario); } } -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp index f747f401b1..b779c293bf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp @@ -79,7 +79,7 @@ double difference(const ImageViewRGB32& game, const ImageViewRGB32& sprite, bool return pixels == 0 ? std::numeric_limits::max() : (double)total / (3 * pixels); } -} +} // namespace const PlayerSprites& player_sprites(){ @@ -243,7 +243,7 @@ class Test_PlayerFacingFixture : public UnitTest{ } }; -} +} // namespace void add_tests_PlayerFacingReader(UnitTestDatabase& database){ database.add(); @@ -258,6 +258,6 @@ void add_tests_PlayerFacingReader(UnitTestDatabase& database){ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h index fb682fde18..bbb12c7d11 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h @@ -48,11 +48,12 @@ std::optional read_player_facing(const ImageViewRGB32& screen); std::optional match_player_facing(const ImageViewRGB32& game, const PlayerSprites& sprites); +// Registers player facing reader unit tests. void add_tests_PlayerFacingReader(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index fb400f1e09..bc6683fb45 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -50,7 +50,7 @@ const StringSelectDatabase& checkpoint_database(){ return database; } -} +} // namespace AutoStory::AutoStory() : RUN(checkpoint_database()) @@ -174,7 +174,7 @@ void verify_story_checkpoint( } -} +} // namespace void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ if (const std::optional verify = RUN.VERIFY.policy()){ @@ -228,6 +228,6 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h index e92eb74549..7ca3556eb0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h @@ -24,12 +24,14 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ +// Program descriptor for FRLG AutoStory. class AutoStory_Descriptor : public SingleSwitchProgramDescriptor{ public: AutoStory_Descriptor(); virtual std::unique_ptr make_stats() const override; }; +// Program instance executing FRLG AutoStory. class AutoStory : public SingleSwitchProgramInstance{ public: using Descriptor = AutoStory_Descriptor; @@ -50,7 +52,7 @@ class AutoStory : public SingleSwitchProgramInstance{ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index a67e107e31..e484701c7d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -336,7 +336,7 @@ class NewGameIntro{ size_t m_presets_picked = 0; }; -} +} // namespace IntroNameStep intro_name_step(IntroNameScreen screen, size_t keyboards_seen, size_t presets_picked){ @@ -426,7 +426,7 @@ bool yes_no_shows(ConsoleHandle& console){ VideoSnapshot screen = console.video().snapshot(); return screen && yes_no_cursor(screen).has_value(); } -} +} // namespace TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout, bool stop_at_battle){ const WallClock deadline = current_time() + timeout; @@ -619,7 +619,7 @@ void run_save_dialog(ConsoleHandle& console, ProControllerContext& context){ ); } -} +} // namespace void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu menu){ console.log("Saving the game."); @@ -841,6 +841,6 @@ void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context){ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index 78d88a0d14..27eeb690b3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -47,8 +47,11 @@ enum class StartMenu{ BEFORE_POKEDEX, FULL, }; +// Total rows in the start menu. int start_menu_rows(StartMenu menu); +// Row index of the SAVE option in the start menu. int start_menu_save_row(StartMenu menu); +// Row index of the OPTION item in the start menu. int start_menu_option_row(StartMenu menu); @@ -87,9 +90,11 @@ enum class IntroNameStep{ // A preset picked returns to the list only after NO on "Er, was it ...?", // so after this many picks A opens the keyboard instead. constexpr size_t RIVAL_PRESET_TRIES = 3; +// Determines the next input step in character/rival naming sequence. IntroNameStep intro_name_step(IntroNameScreen screen, size_t keyboards_seen, size_t presets_picked); +// Expected screen state when dialogue text finishes. enum class TextEnd{ OVERWORLD, BATTLE, @@ -134,6 +139,7 @@ enum class SaveScreen{ // No message and no menu: the overworld, or a frame between two boxes. NOTHING, }; +// Action to perform in the save menu loop. enum class SaveAction{ WAIT, ANSWER_YES, @@ -219,7 +225,7 @@ void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 8428706822..555ecccfbe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -797,7 +797,7 @@ class StoryMessage : public OverworldInterrupt{ const Language m_language; }; -} +} // namespace const char* status_name(StatusCondition status){ @@ -976,6 +976,6 @@ OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, Stor -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index 7b16b43608..b0cca42e3c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -48,6 +48,7 @@ enum class StatusCondition{ PARALYSIS, OTHER, // SLP, BRN, FRZ }; +// String representation of a status condition. const char* status_name(StatusCondition status); // The healing items in the Items pocket, in the order they were bought: @@ -108,12 +109,14 @@ bool attacks_low_on_pp(const Supplies& supplies); // and no Potion into Miguel's battle, which only red would have stopped). bool nurse_before_battle(const Supplies& supplies); +// Type of battle engagement strategy. enum class BattleKind{ WILD_RUN, // RUN, or fight after a few "Can't escape!" WILD_FIGHT, // fight for EXP with green HP, no status and 2 Potions, else RUN TRAINER, }; +// Terminal state of a battle encounter. enum class BattleEnd{ WON, // The starter fainted: a blackout, or a wild battle run from (or won) @@ -158,6 +161,7 @@ struct PartyStatus{ double hp_fill = 0; StatusCondition status = StatusCondition::NONE; }; +// Reads current party health and status from battle screen. PartyStatus read_party_status(const ImageViewRGB32& screen); // Whether `screen` shows a battle, for the battle loop's end: the battle @@ -195,11 +199,12 @@ void recover_after_battle( OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks, Language language); +// Registers AutoStory item usage unit tests. void add_tests_AutoStoryItems(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp index 4b7e4f2e3c..d81e715c71 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp @@ -164,7 +164,7 @@ bool starts_with_any(std::string_view text, std::initializer_list moves; }; +// Trainer AI flags and team definition. struct TrainerData{ // pret's AI flags as slugs: "check-bad-move", "try-to-faint", ... std::vector ai = {}; @@ -95,6 +100,7 @@ struct TrainerData{ // None for a move or species the data doesn't have. const MoveData* move_data(std::string_view move); +// Base stats and typing for species; nullptr if unknown. const SpeciesData* species_data(std::string_view species); // Every species, for reading a wild Pokemon's name. @@ -147,6 +153,7 @@ enum class BattleRisk{ // Potions, and the step fails before the fight when it wins too rarely. HIGH, }; +// String representation of battle risk level. const char* battle_risk_name(BattleRisk risk); // A trainer's risk by its kind: HIGH for the rival, gym leaders, bosses @@ -167,11 +174,12 @@ inline constexpr double MIN_WIN_CHANCE = 0.70; const std::vector>& autostory_battle_json(); +// Registers AutoStory battle data unit tests. void add_tests_AutoStoryBattleData(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp index 42ff159fbf..d2e1cda312 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp @@ -29,22 +29,36 @@ namespace PokemonFRLG{ namespace{ +struct AutoStoryBattleDataInput{ + std::string name; + UnitTestResult (*body)(); +}; + +struct AutoStoryBattleDataExpectation{ + const char* description; +}; + +struct AutoStoryBattleDataTestCase{ + AutoStoryBattleDataInput input; + AutoStoryBattleDataExpectation expectation; +}; + class Test_AutoStoryBattleData : public UnitTest{ public: - Test_AutoStoryBattleData(std::string name, std::function body) - : UnitTest("PokemonFRLG::AutoStoryBattleData - " + std::move(name)) - , m_body(std::move(body)) + explicit Test_AutoStoryBattleData(AutoStoryBattleDataTestCase scenario) + : UnitTest("PokemonFRLG::AutoStoryBattleData - " + scenario.input.name) + , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ try{ - return m_body(); + return m_scenario.input.body(); }catch (Exception& e){ return std::string(e.name()) + ": " + e.message(); } } private: - std::function m_body; + AutoStoryBattleDataTestCase m_scenario; }; const PartyStatus GREEN{.hp_seen = true, .hp_yellow = false, .hp_red = false, .status = StatusCondition::NONE}; @@ -185,20 +199,41 @@ UnitTestResult test_wild_fallback(){ return true; } -} +const AutoStoryBattleDataTestCase AUTO_STORY_BATTLE_DATA_CASES[] = { + { + .input = {.name = "type chart, moves and species from pret", .body = test_data}, + .expectation = {.description = "validates decompiled type charts, moves, and species"}, + }, + { + .input = {.name = "every story battle fights a trainer with a party", .body = test_story_trainers}, + .expectation = {.description = "ensures all scripted story battles encounter valid teams"}, + }, + { + .input = {.name = "Miguel's Grimer: Water Gun", .body = test_miguel_grimer}, + .expectation = {.description = "verifies move matchup choice against Miguel Grimer"}, + }, + { + .input = {.name = "Bite on Psychic, Ghost and Water-resistant foes", .body = test_bite_wins}, + .expectation = {.description = "verifies move matchup prioritization for Bite"}, + }, + { + .input = {.name = "a wild Pokemon not read: the plan's order", .body = test_wild_fallback}, + .expectation = {.description = "falls back to default move preference when unread"}, + }, +}; + +} // namespace void add_tests_AutoStoryBattleData(UnitTestDatabase& database){ - database.add("type chart, moves and species from pret", test_data); - database.add("every story battle fights a trainer with a party", test_story_trainers); - database.add("Miguel's Grimer: Water Gun", test_miguel_grimer); - database.add("Bite on Psychic, Ghost and Water-resistant foes", test_bite_wins); - database.add("a wild Pokemon not read: the plan's order", test_wild_fallback); + for (const auto& scenario : AUTO_STORY_BATTLE_DATA_CASES){ + database.add(scenario); + } add_tests_AutoStoryBattleSim(database); } -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp index 145b9e8c5f..21a587697d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -105,7 +105,7 @@ std::optional lead_hp(const Supplies& supplies, const PartyStatus& statu return status.hp_fill * own->body.stats.hp; } -} +} // namespace void healed_by_nurse(Supplies& supplies){ @@ -385,6 +385,6 @@ bool BattleEndWatch::pressed_blind(WallClock now){ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h index 7d5e8e1736..5c115b1235 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h @@ -33,6 +33,7 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ +// High-level action chosen for a battle turn. enum class TurnChoice{ RUN, POTION, @@ -40,6 +41,7 @@ enum class TurnChoice{ MOVE, }; +// Decided battle action including slot or item index. struct TurnAction{ TurnChoice choice = TurnChoice::MOVE; // For MOVE, the move list's slot. @@ -60,6 +62,7 @@ enum class TurnResult{ REFUSED, }; +// Binary prompt decision. enum class YesNo{ YES, NO, @@ -77,6 +80,7 @@ struct BattleTextScreen{ bool yes_no = false; }; +// Answer to an in-battle prompt dialogue. struct PromptAnswer{ YesNo answer = YesNo::NO; // After YES to "Delete a move?": the slot to forget on the move list @@ -90,6 +94,7 @@ struct PromptAnswer{ }; +// State machine deciding turn choices and prompt answers in battles. class BattleDecisions{ public: BattleDecisions(Supplies& supplies, BattleKind kind); @@ -237,11 +242,12 @@ class MoveRefusalWatch{ }; +// Registers AutoStory party management unit tests. void add_tests_AutoStoryParty(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp index 23e7f10f78..527fdfc447 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp @@ -326,7 +326,7 @@ std::vector damaging_slots(const SimBattler& own, const SimBattler& foe) return slots; } -} +} // namespace std::optional own_battler(const PartyMember& lead, double hp_share, const Genes& genes){ @@ -571,6 +571,6 @@ OwnTurn own_turn( -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h index d5e142d2b7..1acd32e2a5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h @@ -64,6 +64,7 @@ inline constexpr Genes OWN_GENES{.iv = 15, .ev = 0, .nature = 0}; // HP a Potion heals. inline constexpr uint16_t POTION_HP = 20; +// Simulated battler status condition. enum class SimStatus{ NONE, SLEEP, @@ -71,6 +72,7 @@ enum class SimStatus{ PARALYSIS, }; +// A move in simulated combat. struct SimMove{ std::string move = {}; uint8_t pp = 0; @@ -99,6 +101,7 @@ std::optional own_battler(const PartyMember& lead, double hp_share = // A trainer's Pokemon at full HP and PP. std::optional trainer_battler(const TrainerMon& mon); +// Simulated opposing trainer state. struct SimTrainer{ std::vector party = {}; // Each used once; a used one becomes "". @@ -193,7 +196,7 @@ void add_tests_AutoStoryBattleSim(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp index 375d088738..d617a8b611 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp @@ -30,22 +30,36 @@ namespace PokemonFRLG{ namespace{ +struct AutoStoryBattleSimInput{ + std::string name; + UnitTestResult (*body)(); +}; + +struct AutoStoryBattleSimExpectation{ + const char* description; +}; + +struct AutoStoryBattleSimTestCase{ + AutoStoryBattleSimInput input; + AutoStoryBattleSimExpectation expectation; +}; + class Test_AutoStoryBattleSim : public UnitTest{ public: - Test_AutoStoryBattleSim(std::string name, std::function body) - : UnitTest("PokemonFRLG::AutoStoryBattleSim - " + std::move(name)) - , m_body(std::move(body)) + explicit Test_AutoStoryBattleSim(AutoStoryBattleSimTestCase scenario) + : UnitTest("PokemonFRLG::AutoStoryBattleSim - " + scenario.input.name) + , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ try{ - return m_body(); + return m_scenario.input.body(); }catch (Exception& e){ return std::string(e.name()) + ": " + e.message(); } } private: - std::function m_body; + AutoStoryBattleSimTestCase m_scenario; }; constexpr std::string_view RIVAL = "TRAINER_RIVAL_CERULEAN_BULBASAUR"; @@ -432,25 +446,64 @@ UnitTestResult test_rival_real_moves(){ } return true; } -} +const AutoStoryBattleSimTestCase AUTO_STORY_BATTLE_SIM_CASES[] = { + { + .input = {.name = "Gen 3 stats and damage worked by hand", .body = test_hand_numbers}, + .expectation = {.description = "verifies Gen 3 stat calculation and damage formula numbers"}, + }, + { + .input = {.name = "the Elite Four Farmer's Starmie picks OHKO at Sp. Atk 302", .body = test_elite_four_table}, + .expectation = {.description = "verifies OHKO move selection against Elite Four Starmie"}, + }, + { + .input = {.name = "Misty: Thundershock on Staryu, Bite on Starmie", .body = test_misty_per_foe}, + .expectation = {.description = "validates targeted attack decisions in Misty gym battle"}, + }, + { + .input = {.name = "the trainer AI's healing items", .body = test_ai_heal_rule}, + .expectation = {.description = "simulates opponent trainer AI heal threshold logic"}, + }, + { + .input = {.name = "the rival's next Pokemon when no name is read", .body = test_next_foe}, + .expectation = {.description = "predicts next pokemon in rival roster when unread"}, + }, + { + .input = {.name = "battle risks by trainer", .body = test_risks}, + .expectation = {.description = "evaluates risk classification across various trainers"}, + }, + { + .input = {.name = "Cerulean rival: refused at Lv22, fought at Lv30", .body = test_rival_win_chance}, + .expectation = {.description = "simulates battle level threshold for Cerulean rival"}, + }, + { + .input = {.name = "m51: no Potion the foe's hit undoes", .body = test_m51_potion_loop}, + .expectation = {.description = "avoids endless potion loop when damage outpaces heal"}, + }, + { + .input = {.name = "the sim's Potion: only when it outheals the hit", .body = test_sim_potion_rule}, + .expectation = {.description = "verifies potion usage condition based on damage expectations"}, + }, + { + .input = {.name = "Misty: m51's lead as the summary showed it", .body = test_misty_real_lead}, + .expectation = {.description = "simulates Misty battle using lead Pokemon status"}, + }, + { + .input = {.name = "Cerulean rival with m51's moves at Lv20 to 30", .body = test_rival_real_moves}, + .expectation = {.description = "simulates Cerulean rival across level ranges"}, + }, +}; + +} // namespace void add_tests_AutoStoryBattleSim(UnitTestDatabase& database){ - database.add("Gen 3 stats and damage worked by hand", test_hand_numbers); - database.add("the Elite Four Farmer's Starmie picks OHKO at Sp. Atk 302", test_elite_four_table); - database.add("Misty: Thundershock on Staryu, Bite on Starmie", test_misty_per_foe); - database.add("the trainer AI's healing items", test_ai_heal_rule); - database.add("the rival's next Pokemon when no name is read", test_next_foe); - database.add("battle risks by trainer", test_risks); - database.add("Cerulean rival: refused at Lv22, fought at Lv30", test_rival_win_chance); - database.add("m51: no Potion the foe's hit undoes", test_m51_potion_loop); - database.add("the sim's Potion: only when it outheals the hit", test_sim_potion_rule); - database.add("Misty: m51's lead as the summary showed it", test_misty_real_lead); - database.add("Cerulean rival with m51's moves at Lv20 to 30", test_rival_real_moves); + for (const auto& scenario : AUTO_STORY_BATTLE_SIM_CASES){ + database.add(scenario); + } } -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp index a2eb5b8bf4..f4a4151d4e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp @@ -71,7 +71,7 @@ uint32_t base_damage(const Combatant& attacker, const Combatant& defender, const return damage + 2; } -} +} // namespace uint8_t trainer_iv(uint8_t pret_iv){ @@ -170,6 +170,6 @@ double average_damage(const Combatant& attacker, const Combatant& defender, cons -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h index 745d40ebe5..31fb7c7499 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h @@ -55,6 +55,7 @@ struct Genes{ // A trainer's Pokemon's IVs from pret's iv (0 to 255). uint8_t trainer_iv(uint8_t pret_iv); +// Calculates Gen 3 stats from base stats, level, and genes. Stats gen3_stats(const BaseStats& base, uint8_t level, const Genes& genes); // The stat stages the damage formula and the sim use, from -6 to +6. @@ -67,7 +68,9 @@ enum class Stage : size_t{ ACCURACY, EVASION, }; +// Number of modifier stat stages. inline constexpr size_t STAGES = 7; +// Array of stat stage modifiers. using StatStages = std::array; // `stat` at `stage` (gStatStageRatios). @@ -105,6 +108,7 @@ uint32_t damage_before_roll(const Combatant& attacker, const Combatant& defender // `before` at the random roll `percent` (85 to 100). uint32_t rolled_damage(uint32_t before, uint32_t percent); +// Minimum and maximum simulated damage roll. struct DamageRange{ uint32_t min = 0; uint32_t max = 0; @@ -117,7 +121,7 @@ double average_damage(const Combatant& attacker, const Combatant& defender, cons -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 4c205cbb49..5e5ed4708c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -275,7 +275,7 @@ Outcome shop(StoryEnv& env, const StoryStep& step){ return Pokemon::outcome_ok(); } -} +} // namespace std::optional> viridian_mart_orders(const std::vector& items){ @@ -523,6 +523,6 @@ Pokemon::Segment make_story_segment(const std::vector& checkpoi -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 887ca363b6..a9be27da6b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -39,8 +39,11 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ +// Story leg definition imported from Pokemon AutoStory. using Pokemon::StoryLeg; +// Story step definition imported from Pokemon AutoStory. using Pokemon::StoryStep; +// Story step kind classification imported from Pokemon AutoStory. using Pokemon::StoryStepKind; // Where the player stands and faces: the one-tile poses of FRLG's table @@ -73,6 +76,7 @@ struct StoryCheckpoint : public Pokemon::StoryCheckpoint{ // game hides after the Hall of Fame removed, as the lab's frlg_route does. const std::vector& story_maps(); +// Converts a StoryPose to a general navigation Pose. Pokemon::Pose to_pose(const StoryPose& pose); // `pose` as a StoryPose: nothing unless it is on one tile. std::optional story_pose(const Pokemon::Pose& pose); @@ -186,7 +190,7 @@ Pokemon::Segment make_story_segment(const std::vector& checkpoi -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp index ce5fb1c586..97117c6339 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp @@ -18,7 +18,7 @@ namespace{ // PokemonFRLG_AutoStoryBattle.cpp). constexpr int FOE_GONE_POLLS = 3; -} +} // namespace TrainerFoeTracker::TrainerFoeTracker(std::string_view trainer, const PartyMember& lead) @@ -72,6 +72,6 @@ std::optional TrainerFoeTracker::out() const{ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h index 2dc37a8b90..54d1f5a449 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h @@ -34,6 +34,7 @@ struct BattleBoxes{ bool foe = false; }; +// Tracks opposing trainer identity and species roster during battle. class TrainerFoeTracker{ public: // `trainer`: pret's constant, or "" when the battle's trainer isn't @@ -66,7 +67,7 @@ class TrainerFoeTracker{ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index 107e9fc670..21dd37d538 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -28,22 +28,36 @@ namespace PokemonFRLG{ namespace{ +struct AutoStoryItemsInput{ + std::string name; + UnitTestResult (*body)(Logger&); +}; + +struct AutoStoryItemsExpectation{ + const char* description; +}; + +struct AutoStoryItemsTestCase{ + AutoStoryItemsInput input; + AutoStoryItemsExpectation expectation; +}; + class Test_AutoStoryItems : public UnitTest{ public: - Test_AutoStoryItems(std::string name, std::function body) - : UnitTest("PokemonFRLG::AutoStoryItems - " + std::move(name)) - , m_body(std::move(body)) + explicit Test_AutoStoryItems(AutoStoryItemsTestCase scenario) + : UnitTest("PokemonFRLG::AutoStoryItems - " + scenario.input.name) + , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ try{ - return m_body(logger); + return m_scenario.input.body(logger); }catch (Exception& e){ return std::string(e.name()) + ": " + e.message(); } } private: - std::function m_body; + AutoStoryItemsTestCase m_scenario; }; @@ -269,17 +283,44 @@ class Test_PartyHp : public ImageUnitTest{ }; -} +const AutoStoryItemsTestCase AUTO_STORY_ITEMS_CASES[] = { + { + .input = {.name = "Mart cursor stays on the row bought", .body = test_mart_cursor}, + .expectation = {.description = "verifies mart cursor remains on purchased item index"}, + }, + { + .input = {.name = "Items pocket rows", .body = test_pocket_rows}, + .expectation = {.description = "parses item pocket rows from visual representation"}, + }, + { + .input = {.name = "a loaded save's counts come from the bag", .body = test_loaded_bag}, + .expectation = {.description = "initializes bag counts when loading saved state"}, + }, + { + .input = {.name = "an item the story doesn't count keeps its row", .body = test_loaded_bag_other_items}, + .expectation = {.description = "preserves row indexing for uncounted items"}, + }, + { + .input = {.name = "an unread item name keeps its row", .body = test_pocket_rows_unread}, + .expectation = {.description = "preserves placeholder row when item name is unread"}, + }, + { + .input = {.name = "unread bag counts count as some", .body = test_unread_counts}, + .expectation = {.description = "treats unread quantities as holding at least one"}, + }, + { + .input = {.name = "no item names read in a language without them", .body = test_unread_language}, + .expectation = {.description = "handles unsupported languages gracefully"}, + }, +}; + +} // namespace void add_tests_AutoStoryItems(UnitTestDatabase& database){ - database.add("Mart cursor stays on the row bought", test_mart_cursor); - database.add("Items pocket rows", test_pocket_rows); - database.add("a loaded save's counts come from the bag", test_loaded_bag); - database.add("an item the story doesn't count keeps its row", test_loaded_bag_other_items); - database.add("an unread item name keeps its row", test_pocket_rows_unread); - database.add("unread bag counts count as some", test_unread_counts); - database.add("no item names read in a language without them", test_unread_language); + for (const auto& scenario : AUTO_STORY_ITEMS_CASES){ + database.add(scenario); + } // "Wild CHANSEY appeared!" with its HP box, and Mt. Moon B2F's corridor // after "Got away safely!", whose black lower half reads as the battle's // text box (console B, 2026-11-03: 9 minutes of A and B there). @@ -295,6 +336,6 @@ void add_tests_AutoStoryItems(UnitTestDatabase& database){ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp index 117355debf..c167b7678d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp @@ -245,7 +245,7 @@ std::vector attack_order(const PartyMember& member){ return order; } -} +} // namespace std::optional level_evolution(std::string_view species){ @@ -440,6 +440,6 @@ void restore_pp(PartyMember& member){ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h index ad6f636b3d..43fca42a90 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h @@ -41,7 +41,9 @@ namespace PokemonFRLG{ // The move slots, in the order of the battle's move list and the summary. inline constexpr size_t TOP_LEFT_MOVE = 0; +// Move slot index for bottom-left move. inline constexpr size_t BOTTOM_LEFT_MOVE = 2; +// Maximum number of moves a Pokemon can know. inline constexpr size_t MAX_MOVES = 4; // A move the lead knows, by slug ("water-gun"), and the PP the story @@ -51,6 +53,7 @@ struct KnownMove{ uint8_t pp = 0; }; +// Party member Pokemon status and learned moves. struct PartyMember{ std::string species; // In slot order. Fewer than four while moves learned into free slots @@ -78,6 +81,7 @@ struct LevelEvolution{ std::string_view into; uint8_t level = 0; }; +// Level-up evolution target if species evolves by level. std::optional level_evolution(std::string_view species); // A move's full PP; 0 for a move the table doesn't have. @@ -165,7 +169,7 @@ void restore_pp(PartyMember& member); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp index 1b5388de98..21a2e829cf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp @@ -29,22 +29,36 @@ using namespace std::chrono_literals; namespace{ +struct AutoStoryPartyInput{ + std::string name; + UnitTestResult (*body)(Logger&); +}; + +struct AutoStoryPartyExpectation{ + const char* description; +}; + +struct AutoStoryPartyTestCase{ + AutoStoryPartyInput input; + AutoStoryPartyExpectation expectation; +}; + class Test_AutoStoryParty : public UnitTest{ public: - Test_AutoStoryParty(std::string name, std::function body) - : UnitTest("PokemonFRLG::AutoStoryParty - " + std::move(name)) - , m_body(std::move(body)) + explicit Test_AutoStoryParty(AutoStoryPartyTestCase scenario) + : UnitTest("PokemonFRLG::AutoStoryParty - " + scenario.input.name) + , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ try{ - return m_body(logger); + return m_scenario.input.body(logger); }catch (Exception& e){ return std::string(e.name()) + ": " + e.message(); } } private: - std::function m_body; + AutoStoryPartyTestCase m_scenario; }; @@ -625,7 +639,7 @@ UnitTestResult test_end_watch_timing(Logger&){ } -} +} // namespace // The lead console B took into Super Nerd Miguel's battle (2026-11-03, @@ -801,31 +815,95 @@ UnitTestResult test_nurse_before_battle(Logger&){ return true; } +const AutoStoryPartyTestCase AUTO_STORY_PARTY_CASES[] = { + { + .input = {.name = "movesets the game gives and the story plays", .body = test_movesets}, + .expectation = {.description = "verifies movesets progression through early game"}, + }, + { + .input = {.name = "move offered and slot forgotten", .body = test_learn_prompts}, + .expectation = {.description = "determines move learning replacements and prompts"}, + }, + { + .input = {.name = "YES/NO answers to move prompts", .body = test_prompt_answers}, + .expectation = {.description = "answers prompts when deciding to learn new moves"}, + }, + { + .input = {.name = "fainted lead runs or sends the next member", .body = test_fainted_lead}, + .expectation = {.description = "switches to next alive member when lead faints"}, + }, + { + .input = {.name = "PP: preferred attack, then Tackle; nurse restores", .body = test_pp}, + .expectation = {.description = "tracks PP depletion and replenishment"}, + }, + { + .input = {.name = "moves read off the summary, Water Gun over Tackle", .body = test_moves_from_summary}, + .expectation = {.description = "reads move list from summary screen"}, + }, + { + .input = {.name = "summary members: fewer moves, unread PP, strongest attack", .body = test_summary_members}, + .expectation = {.description = "handles party members with partial move data"}, + }, + { + .input = {.name = "no B during an evolution", .body = test_no_b_during_evolution}, + .expectation = {.description = "prevents cancelling evolution sequence"}, + }, + { + .input = {.name = "RUN, then a dark cave: no evolution wait, START soon", .body = test_run_then_overworld}, + .expectation = {.description = "handles post-battle overworld transition in dark cave"}, + }, + { + .input = {.name = "battle end: START after the battle is gone, A and B for 30 s at most", .body = test_end_watch_timing}, + .expectation = {.description = "verifies timing constraints on battle end loop"}, + }, + { + .input = {.name = "attacks by matchup: Bite on the rival's Bulbasaur and Misty", .body = test_attack_by_matchup}, + .expectation = {.description = "selects optimal attack move based on type matchup"}, + }, + { + .input = {.name = "attacks against an unknown foe: the plan's order", .body = test_attack_unknown_foe}, + .expectation = {.description = "falls back to default move preference order against unknown foe"}, + }, + { + .input = {.name = "Bite learned over Tail Whip or Withdraw", .body = test_bite_learned}, + .expectation = {.description = "prioritizes learning offensive moves over status moves"}, + }, + { + .input = {.name = "a YES/NO with no move list after it changes no move", .body = test_yes_no_without_move_list}, + .expectation = {.description = "maintains moveset when prompt completes without move selection"}, + }, + { + .input = {.name = "a disabled move: left alone while Disable lasts, PP back", .body = test_disabled_move}, + .expectation = {.description = "avoids selecting disabled moves"}, + }, + { + .input = {.name = "a move turned down: the move list, then the menu sooner than a turn", .body = test_move_refusal_watch}, + .expectation = {.description = "handles refusing a new move cleanly"}, + }, + { + .input = {.name = "the move list closed with nothing forgotten: YES to \"Stop learning?\"", .body = test_move_list_closed}, + .expectation = {.description = "confirms stopping learning when cancelling move list"}, + }, + { + .input = {.name = "move prompts after a turn: a plain YES after the first few", .body = test_move_prompts_bounded}, + .expectation = {.description = "bounds prompt handling attempts after turns"}, + }, + { + .input = {.name = "the nurse before a battle for HP not green with no Potion", .body = test_nurse_before_battle}, + .expectation = {.description = "triggers pokemon center visit when health is low and without potions"}, + }, +}; + + void add_tests_AutoStoryParty(UnitTestDatabase& database){ - database.add("movesets the game gives and the story plays", test_movesets); - database.add("move offered and slot forgotten", test_learn_prompts); - database.add("YES/NO answers to move prompts", test_prompt_answers); - database.add("fainted lead runs or sends the next member", test_fainted_lead); - database.add("PP: preferred attack, then Tackle; nurse restores", test_pp); - database.add("moves read off the summary, Water Gun over Tackle", test_moves_from_summary); - database.add("summary members: fewer moves, unread PP, strongest attack", test_summary_members); - database.add("no B during an evolution", test_no_b_during_evolution); - database.add("RUN, then a dark cave: no evolution wait, START soon", test_run_then_overworld); - database.add("battle end: START after the battle is gone, A and B for 30 s at most", test_end_watch_timing); - database.add("attacks by matchup: Bite on the rival's Bulbasaur and Misty", test_attack_by_matchup); - database.add("attacks against an unknown foe: the plan's order", test_attack_unknown_foe); - database.add("Bite learned over Tail Whip or Withdraw", test_bite_learned); - database.add("a YES/NO with no move list after it changes no move", test_yes_no_without_move_list); - database.add("a disabled move: left alone while Disable lasts, PP back", test_disabled_move); - database.add("a move turned down: the move list, then the menu sooner than a turn", test_move_refusal_watch); - database.add("the move list closed with nothing forgotten: YES to \"Stop learning?\"", test_move_list_closed); - database.add("move prompts after a turn: a plain YES after the first few", test_move_prompts_bounded); - database.add("the nurse before a battle for HP not green with no Potion", test_nurse_before_battle); + for (const auto& scenario : AUTO_STORY_PARTY_CASES){ + database.add(scenario); + } add_tests_AutoStoryBattleData(database); } -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index 6410a0710c..bf6ac032a3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -277,22 +277,36 @@ struct Simulation{ }; +struct AutoStorySimulationInput{ + std::string name; + UnitTestResult (*body)(); +}; + +struct AutoStorySimulationExpectation{ + const char* description; +}; + +struct AutoStorySimulationTestCase{ + AutoStorySimulationInput input; + AutoStorySimulationExpectation expectation; +}; + class Test_AutoStorySimulation : public UnitTest{ public: - Test_AutoStorySimulation(std::string name, std::function body) - : UnitTest("PokemonFRLG::AutoStory - Simulation: " + std::move(name)) - , m_body(std::move(body)) + explicit Test_AutoStorySimulation(AutoStorySimulationTestCase scenario) + : UnitTest("PokemonFRLG::AutoStory - Simulation: " + scenario.input.name) + , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ try{ - return m_body(); + return m_scenario.input.body(); }catch (Exception& e){ return std::string(e.name()) + ": " + e.message(); } } private: - std::function m_body; + AutoStorySimulationTestCase m_scenario; }; @@ -375,21 +389,36 @@ UnitTestResult test_gives_up_after_attempts(){ return true; } -} +const AutoStorySimulationTestCase AUTO_STORY_SIMULATION_CASES[] = { + { + .input = {.name = "new game to Brock, in order, each start where the last save stood", .body = test_whole_story}, + .expectation = {.description = "runs full story progression from new game through Brock gym"}, + }, + { + .input = {.name = "start and end checkpoints", .body = test_start_and_end}, + .expectation = {.description = "executes segment bounded by start and end checkpoints"}, + }, + { + .input = {.name = "a failed walk reloads its checkpoint's save", .body = test_retry_from_save}, + .expectation = {.description = "reloads checkpoint save state on simulated movement failure"}, + }, + { + .input = {.name = "a battle lost every time stops after 3 attempts", .body = test_gives_up_after_attempts}, + .expectation = {.description = "aborts after three consecutive battle blackouts"}, + }, +}; + +} // namespace void add_tests_AutoStorySimulation(UnitTestDatabase& database){ - const auto add = [&](std::string name, UnitTestResult (*body)()){ - database.add(std::move(name), body); - }; - add("new game to Brock, in order, each start where the last save stood", test_whole_story); - add("start and end checkpoints", test_start_and_end); - add("a failed walk reloads its checkpoint's save", test_retry_from_save); - add("a battle lost every time stops after 3 attempts", test_gives_up_after_attempts); + for (const auto& scenario : AUTO_STORY_SIMULATION_CASES){ + database.add(scenario); + } } -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp index bfc466a410..f6fe9b27cf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp @@ -108,7 +108,7 @@ std::optional read_open_summary(ConsoleHandle& console, ProControll return read; } -} +} // namespace std::optional read_party_summary( ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language, size_t slot @@ -148,6 +148,6 @@ std::optional read_party_summary( -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h index 9839147e90..16f332577d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h @@ -51,7 +51,7 @@ std::optional read_party_summary( -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 7db4cec429..5a88824d81 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -279,7 +279,7 @@ StoryCheckpoint running_shoes(){ }); } -} +} // namespace const std::vector& story_checkpoints(){ @@ -292,6 +292,6 @@ const std::vector& story_checkpoints(){ -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index d8a3f8b15d..ab7731466e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -25,13 +25,14 @@ namespace PokemonFRLG{ const std::vector& story_checkpoints(); +// Registers AutoStory table validation unit tests. void add_tests_AutoStory(UnitTestDatabase& database); // The table run end to end against a fake game (PokemonFRLG_AutoStorySimulation_Tests.cpp). void add_tests_AutoStorySimulation(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp index 5a636778dd..4a696f339b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp @@ -348,7 +348,7 @@ class SimBattle{ bool m_flinched = false; }; -} +} // namespace WinEstimate estimate_win_chance(const SimBattler& own, int potions, const SimTrainer& trainer, size_t battles, uint32_t seed){ @@ -392,6 +392,6 @@ std::optional win_chance_refusal(const WinEstimate& estimate, doubl -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h index 9056a41f83..bc88daa6d5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h @@ -36,6 +36,7 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ +// Outcome count and win probability estimate from Monte Carlo simulations. struct WinEstimate{ size_t battles = 0; size_t wins = 0; @@ -60,7 +61,7 @@ std::optional win_chance_refusal(const WinEstimate& estimate, doubl -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index fa4b926b71..ee7c0f43c7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -29,22 +29,36 @@ namespace PokemonFRLG{ namespace{ +struct AutoStoryInput{ + std::string name; + UnitTestResult (*body)(); +}; + +struct AutoStoryExpectation{ + const char* description; +}; + +struct AutoStoryTestCase{ + AutoStoryInput input; + AutoStoryExpectation expectation; +}; + class Test_AutoStory : public UnitTest{ public: - Test_AutoStory(std::string name, std::function body) - : UnitTest("PokemonFRLG::AutoStory - " + std::move(name)) - , m_body(std::move(body)) + explicit Test_AutoStory(AutoStoryTestCase scenario) + : UnitTest("PokemonFRLG::AutoStory - " + scenario.input.name) + , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ try{ - return m_body(); + return m_scenario.input.body(); }catch (Exception& e){ return std::string(e.name()) + ": " + e.message(); } } private: - std::function m_body; + AutoStoryTestCase m_scenario; }; const MapData* find_map_named(const std::string& name){ @@ -567,25 +581,64 @@ UnitTestResult test_option_presses(){ return true; } -} +const AutoStoryTestCase AUTO_STORY_CASES[] = { + { + .input = {.name = "every route plans, and checkpoints chain", .body = test_routes_and_chain}, + .expectation = {.description = "verifies route planning validity across all chained checkpoints"}, + }, + { + .input = {.name = "step names are unique per checkpoint", .body = test_unique_names}, + .expectation = {.description = "ensures step identifier uniqueness within checkpoints"}, + }, + { + .input = {.name = "every save has a place on the save card", .body = test_save_places}, + .expectation = {.description = "validates save location identifiers on save card"}, + }, + { + .input = {.name = "a reload's save is checked against the start", .body = test_save_place_error}, + .expectation = {.description = "detects mismatch between checkpoint initial state and save point"}, + }, + { + .input = {.name = "save dialogs: every YES/NO is YES, a cancel fails", .body = test_save_dialog}, + .expectation = {.description = "verifies save confirmation prompt interactions"}, + }, + { + .input = {.name = "every checkpoint lints clean", .body = test_lint}, + .expectation = {.description = "validates semantic lint rules across story step sequence"}, + }, + { + .input = {.name = "Pewter Gym walks", .body = test_pewter_gym_walks}, + .expectation = {.description = "verifies Pewter Gym route planning and obstacle avoidance"}, + }, + { + .input = {.name = "Pewter: to the aide's trigger", .body = test_pewter_aide_walk}, + .expectation = {.description = "plans path to Running Shoes aide trigger tile"}, + }, + { + .input = {.name = "routes run after the Running Shoes", .body = test_runs_after_shoes}, + .expectation = {.description = "switches movement speed to running once shoes acquired"}, + }, + { + .input = {.name = "intro: names, the rival's from the list", .body = test_intro_names}, + .expectation = {.description = "verifies character and rival naming inputs"}, + }, + { + .input = {.name = "options: RIGHT presses from the shown value", .body = test_option_presses}, + .expectation = {.description = "calculates Dpad RIGHT inputs for setting game options"}, + }, +}; + +} // namespace void add_tests_AutoStory(UnitTestDatabase& database){ - database.add("every route plans, and checkpoints chain", test_routes_and_chain); - database.add("step names are unique per checkpoint", test_unique_names); - database.add("every save has a place on the save card", test_save_places); - database.add("a reload's save is checked against the start", test_save_place_error); - database.add("save dialogs: every YES/NO is YES, a cancel fails", test_save_dialog); - database.add("every checkpoint lints clean", test_lint); - database.add("Pewter Gym walks", test_pewter_gym_walks); - database.add("Pewter: to the aide's trigger", test_pewter_aide_walk); - database.add("routes run after the Running Shoes", test_runs_after_shoes); - database.add("intro: names, the rival's from the list", test_intro_names); - database.add("options: RIGHT presses from the shown value", test_option_presses); + for (const auto& scenario : AUTO_STORY_CASES){ + database.add(scenario); + } } -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation From 0e4162eb79c91d6c360163a91ae2bb287df75d6c Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 5 Nov 2026 18:35:11 -0800 Subject: [PATCH 03/29] PokemonFRLG: use string_view for file_json to avoid dangling reference in GCC --- .../Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp index d81e715c71..186f737d0f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp @@ -58,7 +58,7 @@ constexpr StoryTrainer STORY_TRAINERS[] = { using JsonTable = std::map>; -const JsonValue& file_json(const std::string& name){ +const JsonValue& file_json(std::string_view name){ static const JsonTable FILES = []{ JsonTable files; for (const auto& [file, text] : autostory_battle_json()){ @@ -68,7 +68,7 @@ const JsonValue& file_json(const std::string& name){ }(); const auto it = FILES.find(name); if (it == FILES.end()){ - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "BattleData/" + name + ".json is not built into the program."); + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "BattleData/" + std::string(name) + ".json is not built into the program."); } return it->second; } From b5c41d3c4d32b65d20792ce859c11963de1dc41b Mon Sep 17 00:00:00 2001 From: Di Fan <26423504+dayfine@users.noreply.github.com> Date: Sat, 7 Nov 2026 22:20:59 -0800 Subject: [PATCH 04/29] Export evaluated FRLG story checkpoints for offline validation (#251) * Export evaluated FRLG checkpoints without console execution * Provide offline UI flag and capture before unrelated tests --- .../workflows/cpp-ci-serial-programs-base.yml | 22 +++- SerialPrograms/CMakeLists.txt | 1 + .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 + .../AutoStory/PokemonFRLG_AutoStoryExport.cpp | 103 ++++++++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryExport.h | 18 +++ .../PokemonFRLG_AutoStoryExport_Tests.cpp | 102 +++++++++++++++++ .../PokemonFRLG_AutoStoryExport_Tests.h | 15 +++ SerialPrograms/cmake/SourceFiles.cmake | 4 + devtools/story-export/FRLG.cmake | 17 +++ devtools/story-export/README.md | 38 +++++++ devtools/story-export/frlg_main.cpp | 34 ++++++ 11 files changed, 355 insertions(+), 1 deletion(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h create mode 100644 devtools/story-export/FRLG.cmake create mode 100644 devtools/story-export/README.md create mode 100644 devtools/story-export/frlg_main.cpp diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml index 58f1a9d890..9595aa79f0 100644 --- a/.github/workflows/cpp-ci-serial-programs-base.yml +++ b/.github/workflows/cpp-ci-serial-programs-base.yml @@ -208,12 +208,32 @@ jobs: cd Arduino-Source/SerialPrograms mkdir bin cd bin - cmake .. -DQT_MAJOR:STRING=6 ${{env.CMAKE_ADDITIONAL_FLAGS}} + cmake .. -DQT_MAJOR:STRING=6 -DPA_FRLG_STORY_EXPORT=ON ${{env.CMAKE_ADDITIONAL_FLAGS}} # By default Ninja reads each compile's .d dependency file into its own database, then deletes it. # To keep them for the downstream clang-query cache (see .github/scripts/clang-query-cached.py), add # -d keepdepfile cmake --build . --config RelWithDebInfo --parallel ${{env.BUILD_PARALLEL}} -- -d keepdepfile + - name: Export evaluated FRLG Parcel checkpoint (Ubuntu) + if: startsWith(inputs.os, 'ubuntu') && inputs.run-tests + run: | + cd Arduino-Source/SerialPrograms/bin + ./StoryCheckpointExport 00.05 > frlg-parcel.native.json + python3 - <<'PYTHON' + import json + from pathlib import Path + data = json.loads(Path('frlg-parcel.native.json').read_text()) + assert data['game'] == 'frlg' and data['checkpoint']['id'] == '00.05' + assert len(data['checkpoint']['events']) == 3 + PYTHON + + - name: Upload evaluated FRLG checkpoint + if: startsWith(inputs.os, 'ubuntu') && inputs.run-tests + uses: actions/upload-artifact@v7 + with: + name: frlg-checkpoint-${{inputs.os}}-${{inputs.compiler}} + path: Arduino-Source/SerialPrograms/bin/frlg-parcel.native.json + - name: Prepare upload build if: inputs.upload-build shell: bash diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index d43d52d625..73729ebde9 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -921,6 +921,7 @@ if(COMMAND_LINE_EXE) include(Source/CommandLine/CommandLineExecutable.cmake) endif() +include(../devtools/story-export/FRLG.cmake) if(PA_PYTHON_BINDINGS) # Python bindings (GUI-free) from subdirectory include(Source/PythonBindings/PythonBindings.cmake) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 1973dbe3e4..d8cd48d681 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -40,6 +40,7 @@ #include "PokemonFRLG_Navigation.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryTable.h" +#include "Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h" #include "Tests/TestUtils.h" #include "PokemonFRLG_Tests.h" @@ -317,6 +318,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_OverworldRecovery(database); add_tests_PlayerFacingReader(database); add_tests_AutoStory(database); + add_tests_AutoStoryExport(database); add_tests_AutoStorySimulation(database); add_tests_AutoStoryItems(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp new file mode 100644 index 0000000000..a0b85c21ea --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp @@ -0,0 +1,103 @@ +/* FRLG Authored Checkpoint Export + * From: https://github.com/PokemonAutomation/ + */ +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepJson.h" +#include "PokemonFRLG_AutoStoryExport.h" +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ +namespace{ +const char* menu_name(StartMenu menu){ + switch (menu){ + case StartMenu::BEFORE_POKEMON: return "before_pokemon"; + case StartMenu::BEFORE_POKEDEX: return "before_pokedex"; + case StartMenu::FULL: return "full"; + } + throw ParseException("Unsupported FRLG START menu."); +} +JsonArray strings(const std::vector& values){ + JsonArray result; + for (const std::string& value : values){ + result.push_back(value); + } + return result; +} +int64_t count(size_t value){ + if (value > (size_t)std::numeric_limits::max()){ + throw ParseException("FRLG checkpoint count exceeds JSON integer range."); + } + return (int64_t)value; +} +JsonObject stats_json(const Stats& stats){ + JsonObject result; + result["hp"] = stats.hp; + result["attack"] = stats.attack; + result["defense"] = stats.defense; + result["sp_attack"] = stats.sp_attack; + result["sp_defense"] = stats.sp_defense; + result["speed"] = stats.speed; + return result; +} +JsonObject member_json(const PartyMember& member){ + JsonObject result; + result["species"] = member.species; + JsonArray moves; + for (const KnownMove& move : member.moves){ + JsonObject entry; + entry["move"] = move.move; + entry["pp"] = move.pp; + moves.push_back(std::move(entry)); + } + result["moves"] = std::move(moves); + result["moves_through_level"] = member.moves_through_level; + result["moves_read"] = member.moves_read; + result["level"] = member.level; + result["stats"] = member.stats ? JsonValue(stats_json(*member.stats)) : JsonValue(); + return result; +} +JsonObject supplies_json(const Supplies& supplies){ + JsonObject result; + result["potions"] = supplies.potions; + result["antidotes"] = supplies.antidotes; + result["parlyz_heals"] = supplies.parlyz_heals; + result["pocket"] = strings(supplies.pocket); + result["status"] = status_name(supplies.status); + result["hurt"] = supplies.hurt; + result["hp_red"] = supplies.hp_red; + result["hp_fill"] = supplies.hp_fill; + result["lead"] = member_json(supplies.lead); + JsonArray protected_slots; + for (size_t slot : supplies.protected_slots){ + protected_slots.push_back(count(slot)); + } + result["protected_slots"] = std::move(protected_slots); + result["foes"] = strings(supplies.foes); + result["trainer"] = supplies.trainer; + result["risk"] = battle_risk_name(supplies.risk); + result["foe_out"] = supplies.foe_out ? JsonValue(count(*supplies.foe_out)) : JsonValue(); + result["wild_foes"] = strings(supplies.wild_foes); + return result; +} +} // namespace +JsonValue story_checkpoint_export(const StoryCheckpoint& checkpoint){ + JsonObject result; + result["format"] = "pokesim-native-checkpoint-export/1"; + result["game"] = "frlg"; + result["status"] = "native-table-export"; + result["checkpoint"] = Pokemon::story_checkpoint_json(checkpoint); + JsonObject native; + native["menu"] = menu_name(checkpoint.menu); + native["supplies"] = supplies_json(checkpoint.supplies); + result["native_fields"] = std::move(native); + result["state_basis"] = "native-table-bookkeeping"; + result["unbound"] = strings({"runtime_configuration", "map_pins", "executor_bindings", "entry_evidence", "effective_save_retry_policy"}); + return result; +} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.h new file mode 100644 index 0000000000..f2cc73c6b2 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.h @@ -0,0 +1,18 @@ +/* FRLG Authored Checkpoint Export + * From: https://github.com/PokemonAutomation/ + */ +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryExport_H +#define PokemonAutomation_PokemonFRLG_AutoStoryExport_H +#include "Common/Cpp/Json/JsonValue.h" +#include "PokemonFRLG_AutoStoryEvents.h" +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ +// Capture evaluated shared fields and every FRLG checkpoint extension. +// Native supplies are bookkeeping, not observed state or entry requirements. +// Runtime options, map pins, effective policies and execution remain unbound. +JsonValue story_checkpoint_export(const StoryCheckpoint& checkpoint); +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp new file mode 100644 index 0000000000..bc4e0f3f12 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp @@ -0,0 +1,102 @@ +/* FRLG Checkpoint Export Tests + * From: https://github.com/PokemonAutomation/ + */ +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepJson.h" +#include "PokemonFRLG_AutoStoryExport.h" +#include "PokemonFRLG_AutoStoryTable.h" +#include "PokemonFRLG_AutoStoryExport_Tests.h" +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ +namespace{ +struct ExportInput{ + std::string_view id; + bool custom = false; +}; +struct ExportExpectation{ + std::vector events; + std::string_view menu; + std::string_view native_json = {}; +}; +struct ExportCase{ + ExportInput input; + ExportExpectation expectation; +}; +const ExportCase CASES[] = { + {.input = {.id = "00.05"}, .expectation = {.events = {"below_mart_door", "mart_door", "parcel_from_clerk"}, .menu = "before_pokedex"}}, + {.input = {.id = "00.05", .custom = true}, .expectation = { + .events = {"below_mart_door", "mart_door", "parcel_from_clerk"}, .menu = "full", + .native_json = R"({"menu":"full","supplies":{"potions":2,"antidotes":3,"parlyz_heals":4,"pocket":["antidote",""],"status":"PSN","hurt":true,"hp_red":true,"hp_fill":0.25,"lead":{"species":"wartortle","moves":[{"move":"bite","pp":0}],"moves_through_level":18,"moves_read":true,"level":19,"stats":{"hp":50,"attack":20,"defense":30,"sp_attack":40,"sp_defense":35,"speed":25}},"protected_slots":[0,2],"foes":["staryu"],"trainer":"misty","risk":"high","foe_out":0,"wild_foes":["pidgey"]}})" + }}, +}; +void customize(StoryCheckpoint& row){ + row.menu = StartMenu::FULL; + Supplies& state = row.supplies; + state.potions = 2; + state.antidotes = 3; + state.parlyz_heals = 4; + state.pocket = {"antidote", ""}; + state.status = StatusCondition::POISON; + state.hurt = true; + state.hp_red = true; + state.hp_fill = 0.25; + state.lead = PartyMember{.species = "wartortle", .moves = {{"bite", 0}}, + .moves_through_level = 18, .moves_read = true, .level = 19, + .stats = Stats{.hp = 50, .attack = 20, .defense = 30, .sp_attack = 40, .sp_defense = 35, .speed = 25}}; + state.protected_slots = {0, 2}; + state.foes = {"staryu"}; + state.trainer = "misty"; + state.risk = BattleRisk::HIGH; + state.foe_out = 0; + state.wild_foes = {"pidgey"}; +} +std::string check_export(StoryCheckpoint row, const ExportCase& test){ + if (test.input.custom){ + customize(row); + } + const JsonValue encoded = story_checkpoint_export(row); + const JsonObject& root = encoded.to_object_throw(); + const JsonObject& native = root.get_object_throw("native_fields"); + if (native.get_string_throw("menu") != test.expectation.menu){ + return "Expected menu " + std::string(test.expectation.menu) + ", read " + native.get_string_throw("menu"); + } + if (!test.expectation.native_json.empty() && !(JsonValue(native.clone()) == parse_json(std::string(test.expectation.native_json)))){ + return "Expected native fields " + std::string(test.expectation.native_json) + ", read " + native.dump(); + } + const auto decoded = Pokemon::read_story_checkpoint(root.get_value_throw("checkpoint"), "export test"); + if (!(Pokemon::story_checkpoint_json(decoded) == Pokemon::story_checkpoint_json(row))){ + return "Expected every authored common field to survive export/import."; + } + std::vector names; + for (const auto& step : decoded.steps){ + names.push_back(step.name); + } + return names == test.expectation.events ? "" : "Expected Parcel's three authored events in order."; +} +class ExportTest : public UnitTest{ +public: + explicit ExportTest(ExportCase test) + : UnitTest("PokemonFRLG::CheckpointExport - " + std::string(test.input.id) + (test.input.custom ? " custom" : " authored")), m_test(test){} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + for (const auto& row : story_checkpoints()){ + if (row.id == m_test.input.id){ + const std::string error = check_export(row, m_test); + return error.empty() ? UnitTestResult(true) : UnitTestResult(error); + } + } + return UnitTestResult("Expected checkpoint " + std::string(m_test.input.id) + ", read no matching row."); + } +private: + ExportCase m_test; +}; +} // namespace +void add_tests_AutoStoryExport(UnitTestDatabase& database){ + for (const ExportCase& test : CASES){ + database.add(test); + } +} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h new file mode 100644 index 0000000000..90eabc74a9 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h @@ -0,0 +1,15 @@ +/* FRLG Checkpoint Export Tests + * From: https://github.com/PokemonAutomation/ + */ +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryExport_Tests_H +#define PokemonAutomation_PokemonFRLG_AutoStoryExport_Tests_H +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ +// Register evaluated-table and non-default native-extension preservation tests. +void add_tests_AutoStoryExport(UnitTestDatabase& database); +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index a9052417a4..9f742cd8d4 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1870,6 +1870,10 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp diff --git a/devtools/story-export/FRLG.cmake b/devtools/story-export/FRLG.cmake new file mode 100644 index 0000000000..2c217b0480 --- /dev/null +++ b/devtools/story-export/FRLG.cmake @@ -0,0 +1,17 @@ +# Evaluates the real game table without constructing a console executor. +# Full application libraries are build dependencies; this is not PA_CORE_ONLY. +option(PA_FRLG_STORY_EXPORT "Build the offline evaluated FRLG checkpoint exporter" OFF) +if(PA_FRLG_STORY_EXPORT) + execute_process(COMMAND git rev-parse HEAD WORKING_DIRECTORY "${REPO_ROOT_DIR}" + OUTPUT_VARIABLE STORY_EXPORT_REVISION OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY) + execute_process(COMMAND git diff --quiet HEAD WORKING_DIRECTORY "${REPO_ROOT_DIR}" + RESULT_VARIABLE STORY_EXPORT_DIRTY) + if(NOT STORY_EXPORT_DIRTY EQUAL 0) + message(FATAL_ERROR "Commit tracked changes before configuring a provenance-bearing story export.") + endif() + add_executable(StoryCheckpointExport + ../devtools/story-export/frlg_main.cpp) + target_link_libraries(StoryCheckpointExport PRIVATE SerialProgramsLib) + apply_common_target_properties(StoryCheckpointExport) + target_compile_definitions(StoryCheckpointExport PRIVATE PA_STORY_EXPORT_REVISION="${STORY_EXPORT_REVISION}") +endif() diff --git a/devtools/story-export/README.md b/devtools/story-export/README.md new file mode 100644 index 0000000000..8195c7b3fe --- /dev/null +++ b/devtools/story-export/README.md @@ -0,0 +1,38 @@ +# Evaluated native story checkpoint capture + +This first adapter exports FRLG stage 1's actual `story_checkpoints()` rows. +It does not parse C++ text, construct a story executor, load a save, open a +profile or send controller inputs. It is a full-library build target, not the +Qt-free core target; linking Qt libraries does not create an application/window. + +From a clean committed checkout with the usual native build dependencies: + +```sh +cmake -S SerialPrograms -B build -DPA_FRLG_STORY_EXPORT=ON +cmake --build build --target StoryCheckpointExport -j4 +build/StoryCheckpointExport 00.05 > frlg-parcel.native.json +``` + +On multi-configuration generators add `--config RelWithDebInfo`, then run +`build/RelWithDebInfo/StoryCheckpointExport.exe`. The current full-library CI +builds the target on every platform and captures Parcel as a Linux artifact. +Reconfigure after switching source revisions: `source_revision` names the clean +revision used at configure time. Canonical captures should come from clean CI. + +The `pokesim-native-checkpoint-export/1` capture contains the shared checkpoint +codec plus all fields of this source revision's FRLG checkpoint extension: +menu and supplies (including party moves/PP, optional stats, slot zero, and +foe bookkeeping). Defaults remain native bookkeeping, not measured state or +requirements. No inference of full HP, actual inventory or battle probability +is permitted from this capture alone. + +Runtime configuration, map pins, executor bindings, entry evidence and effective +save/retry policy are explicitly unbound. This is not the proposed executable +story-plan envelope, and must not be passed directly to a console executor. +Other native revisions with more checkpoint fields need an updated adapter. +BDSP `01.03`, policy binding and native/Python execution parity remain next. + +Stdout is machine JSON; import/format it through PokemonSimulation's native +export CLI and compact contract formatter before checking in review data. +Tests next to the adapter check the real Parcel row and every native extension +field using synthetic non-default state. They do not validate console timings. diff --git a/devtools/story-export/frlg_main.cpp b/devtools/story-export/frlg_main.cpp new file mode 100644 index 0000000000..72d3a0bbcf --- /dev/null +++ b/devtools/story-export/frlg_main.cpp @@ -0,0 +1,34 @@ +/* Offline evaluated FRLG table export. No console or profile initialization. + * cmake -S SerialPrograms -B build -DPA_FRLG_STORY_EXPORT=ON + * cmake --build build --target StoryCheckpointExport -j4 + * build/StoryCheckpointExport 00.05 > frlg-parcel.native.json + * Format the captured JSON with PokemonSimulation's contract formatter. + */ +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.h" +#include "VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h" + +int main(int argc, char** argv){ + if (argc != 2){ + std::cerr << "Usage: StoryCheckpointExport CHECKPOINT_ID\n"; + return 2; + } + try{ + for (const auto& row : PokemonAutomation::NintendoSwitch::PokemonFRLG::story_checkpoints()){ + if (row.id != std::string_view(argv[1])){ + continue; + } + auto result = PokemonAutomation::NintendoSwitch::PokemonFRLG::story_checkpoint_export(row); + result.to_object_throw()["source_revision"] = PA_STORY_EXPORT_REVISION; + std::cout << result.dump(-1) << '\n'; + return 0; + } + std::cerr << "Unknown checkpoint: " << argv[1] << '\n'; + }catch (const PokemonAutomation::Exception& error){ + std::cerr << error.to_str() << '\n'; + } + return 1; +} From 0f79fd274655311e332df77e04b09f603983da5c Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 01:30:58 -0800 Subject: [PATCH 05/29] FRLG AutoStory: run the console executor through the story action table StoryExecutor now runs each step through a shared TableExecutor on FRLG's rows (PokemonFRLG_AutoStoryStepTable.h) instead of one virtual per kind. The rows bind to the same console actions as before; a failed console step is still the failed Outcome "operation_failed" (the default StepGuard). Tests run the rows with a recorder against the per-kind dispatch they replace, and lint every checkpoint against them. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 + .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 121 +++++---- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 30 +-- .../PokemonFRLG_AutoStoryStepTable.cpp | 67 +++++ .../PokemonFRLG_AutoStoryStepTable.h | 73 ++++++ .../PokemonFRLG_AutoStoryStepTable_Tests.cpp | 234 ++++++++++++++++++ SerialPrograms/cmake/SourceFiles.cmake | 3 + 7 files changed, 461 insertions(+), 69 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index cea4ff7bc9..1ec1732b99 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -40,6 +40,7 @@ #include "Overworld/PokemonFRLG_PlayerFacingReader.h" #include "PokemonFRLG_Navigation.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h" +#include "Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryTable.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h" #include "Tests/TestUtils.h" @@ -319,6 +320,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_OverworldRecovery(database); add_tests_PlayerFacingReader(database); add_tests_AutoStory(database); + add_tests_AutoStoryStepTable(database); add_tests_AutoStoryExport(database); add_tests_AutoStorySimulation(database); add_tests_AutoStoryItems(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 5e5ed4708c..26f334f1ea 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -7,6 +7,7 @@ #include #include #include +#include "Common/Cpp/Exceptions.h" #include "CommonFramework/Exceptions/OperationFailedException.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "Pokemon/AutoStory/Pokemon_TilePose.h" @@ -380,67 +381,83 @@ std::optional wall_beside(const MapData& map, const TilePos& tile){ return std::nullopt; } -StoryExecutor::StoryExecutor(StoryEnv& env) - : m_env(env) -{} - -Outcome StoryExecutor::run(RunState& state, const StoryStep& step){ - return guarded([&]{ return Pokemon::StoryStepExecutor::run(state, step); }); -} - -Outcome StoryExecutor::new_game(RunState&, const StoryStep&){ - play_new_game_intro(m_env.console, m_env.context); - return Pokemon::outcome_ok(); -} - -Outcome StoryExecutor::options(RunState&, const StoryStep&){ - set_options(m_env.console, m_env.context, m_menu, m_env.language); - return Pokemon::outcome_ok(); -} - -Outcome StoryExecutor::route(RunState& state, const StoryStep& step){ - return walk_route(m_env, state, step); -} - -Outcome StoryExecutor::legs(RunState& state, const StoryStep& step){ - return walk_legs(m_env, state, step); -} - -Outcome StoryExecutor::step(RunState& state, const StoryStep& step){ - return take_step(m_env, state, step); -} +namespace{ -Outcome StoryExecutor::talk(RunState&, const StoryStep&){ - pbf_press_button(m_env.context, BUTTON_A, 160ms, 800ms); - return Pokemon::outcome_ok(); -} +// How the console does an action that needs only the env. +using ConsoleAction = Outcome (*)(StoryEnv& env, RunState& state, const StoryStep& step); -Outcome StoryExecutor::answer(RunState&, const StoryStep& step){ - answer_yes_no(m_env.console, m_env.context, step.yes, BUTTON_B, YES_NO_TIMEOUT); - return Pokemon::outcome_ok(); +ConsoleAction console_action_of(StoryActionId id){ + switch (id){ + case StoryActionId::NEW_GAME: + return [](StoryEnv& env, RunState&, const StoryStep&){ + play_new_game_intro(env.console, env.context); + return Pokemon::outcome_ok(); + }; + case StoryActionId::ROUTE: + return [](StoryEnv& env, RunState& state, const StoryStep& step){ return walk_route(env, state, step); }; + case StoryActionId::LEGS: + return walk_legs; + case StoryActionId::STEP: + return take_step; + case StoryActionId::TALK: + return [](StoryEnv& env, RunState&, const StoryStep&){ + pbf_press_button(env.context, BUTTON_A, 160ms, 800ms); + return Pokemon::outcome_ok(); + }; + case StoryActionId::ANSWER: + return [](StoryEnv& env, RunState&, const StoryStep& step){ + answer_yes_no(env.console, env.context, step.yes, BUTTON_B, YES_NO_TIMEOUT); + return Pokemon::outcome_ok(); + }; + case StoryActionId::MASH: + return [](StoryEnv& env, RunState&, const StoryStep&){ + mash_until_overworld(env.console, env.context, SCENE_TIMEOUT); + return Pokemon::outcome_ok(); + }; + case StoryActionId::BATTLE: + return [](StoryEnv& env, RunState&, const StoryStep& step){ return battle(env, step); }; + case StoryActionId::HEAL: + return [](StoryEnv& env, RunState&, const StoryStep&){ + heal_at_center(env.console, env.context); + healed_by_nurse(env.supplies); + return Pokemon::outcome_ok(); + }; + case StoryActionId::SHOP: + return [](StoryEnv& env, RunState&, const StoryStep& step){ return shop(env, step); }; + case StoryActionId::READY: + return get_ready; + case StoryActionId::OPTIONS: + case StoryActionId::GAME: + break; + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::string("No console action for ") + story_action_name(id)); } -Outcome StoryExecutor::mash(RunState&, const StoryStep&){ - mash_until_overworld(m_env.console, m_env.context, SCENE_TIMEOUT); - return Pokemon::outcome_ok(); -} +} // namespace -Outcome StoryExecutor::battle(RunState&, const StoryStep& step){ - return PokemonFRLG::battle(m_env, step); -} -Outcome StoryExecutor::heal(RunState&, const StoryStep&){ - heal_at_center(m_env.console, m_env.context); - healed_by_nurse(m_env.supplies); - return Pokemon::outcome_ok(); -} +StoryExecutor::StoryExecutor(StoryEnv& env) + : m_env(env) + , m_table(make_story_action_table([this](StoryActionId id){ return console_action(id); })) + , m_executor(m_table, m_guard) +{} -Outcome StoryExecutor::shop(RunState&, const StoryStep& step){ - return PokemonFRLG::shop(m_env, step); +Outcome StoryExecutor::run(RunState& state, const StoryStep& step){ + return m_executor.run(state, step); } -Outcome StoryExecutor::ready(RunState& state, const StoryStep& step){ - return get_ready(m_env, state, step); +Pokemon::StoryAction StoryExecutor::console_action(StoryActionId id){ + if (id == StoryActionId::OPTIONS){ + return {.act = [this](RunState&, const StoryStep&){ + set_options(m_env.console, m_env.context, m_menu, m_env.language); + return Pokemon::outcome_ok(); + }, .needs_console = true}; + } + if (id == StoryActionId::GAME){ + return {.act = [this](RunState& state, const StoryStep& step){ return game(state, step); }, .needs_console = true}; + } + const ConsoleAction action = console_action_of(id); + return {.act = [this, action](RunState& state, const StoryStep& step){ return action(m_env, state, step); }, .needs_console = true}; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index a9be27da6b..c58aa9ecf0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -25,6 +25,7 @@ #include #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryActions.h" #include "Pokemon/AutoStory/Pokemon_StoryEvents.h" #include "Pokemon/AutoStory/Pokemon_StorySegments.h" #include "Pokemon/AutoStory/Pokemon_StorySteps.h" @@ -33,6 +34,7 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryStepTable.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -146,8 +148,9 @@ void read_lead_moves(StoryEnv& env, StartMenu menu); // before it carry the items they have. void read_bag_supplies(StoryEnv& env, StartMenu menu); -// Does FRLG's kinds of story step on the console. A console step that -// fails is a failed Outcome, which the segment answers by reloading. +// Does FRLG's kinds of story step on the console, each with its row of +// story_action_rows() (PokemonFRLG_AutoStoryStepTable.h). A console step +// that fails is a failed Outcome, which the segment answers by reloading. class StoryExecutor : public Pokemon::StoryStepExecutor{ public: explicit StoryExecutor(StoryEnv& env); @@ -160,26 +163,19 @@ class StoryExecutor : public Pokemon::StoryStepExecutor{ m_menu = menu; } + // The step's action from the table. virtual Pokemon::Outcome run(Pokemon::RunState& state, const StoryStep& step) override; -protected: - virtual Pokemon::Outcome new_game(Pokemon::RunState& state, const StoryStep& step) override; - virtual Pokemon::Outcome options(Pokemon::RunState& state, const StoryStep& step) override; - virtual Pokemon::Outcome route(Pokemon::RunState& state, const StoryStep& step) override; - virtual Pokemon::Outcome legs(Pokemon::RunState& state, const StoryStep& step) override; - virtual Pokemon::Outcome step(Pokemon::RunState& state, const StoryStep& step) override; - virtual Pokemon::Outcome talk(Pokemon::RunState& state, const StoryStep& step) override; - virtual Pokemon::Outcome answer(Pokemon::RunState& state, const StoryStep& step) override; - virtual Pokemon::Outcome mash(Pokemon::RunState& state, const StoryStep& step) override; - virtual Pokemon::Outcome battle(Pokemon::RunState& state, const StoryStep& step) override; - virtual Pokemon::Outcome heal(Pokemon::RunState& state, const StoryStep& step) override; - // The Viridian Mart, before the Boulder Badge: Potions, Antidotes and Parlyz Heals. - virtual Pokemon::Outcome shop(Pokemon::RunState& state, const StoryStep& step) override; - virtual Pokemon::Outcome ready(Pokemon::RunState& state, const StoryStep& step) override; - private: + // How the console does `id`. + Pokemon::StoryAction console_action(StoryActionId id); + StoryEnv& m_env; StartMenu m_menu = StartMenu::FULL; + // FRLG does nothing around a step: a failed one fails the step. + Pokemon::StepGuard m_guard; + Pokemon::StoryActionTable m_table; + Pokemon::TableExecutor m_executor; }; // The checkpoint `data` as events, saving at its end. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp new file mode 100644 index 0000000000..2869e1c299 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp @@ -0,0 +1,67 @@ +/* AutoStory Step Table + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Common/Cpp/Exceptions.h" +#include "PokemonFRLG_AutoStoryStepTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using Pokemon::StoryStepKind; + + +const char* story_action_name(StoryActionId id){ + switch (id){ + case StoryActionId::NEW_GAME: return "new_game"; + case StoryActionId::OPTIONS: return "options"; + case StoryActionId::ROUTE: return "route"; + case StoryActionId::LEGS: return "legs"; + case StoryActionId::STEP: return "step"; + case StoryActionId::TALK: return "talk"; + case StoryActionId::ANSWER: return "answer"; + case StoryActionId::MASH: return "mash"; + case StoryActionId::BATTLE: return "battle"; + case StoryActionId::HEAL: return "heal"; + case StoryActionId::SHOP: return "shop"; + case StoryActionId::READY: return "ready"; + case StoryActionId::GAME: return "game"; + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown story action."); +} + +const std::vector& story_action_rows(){ + static const std::vector ROWS{ + {StoryStepKind::NEW_GAME, "", StoryActionId::NEW_GAME}, + {StoryStepKind::OPTIONS, "", StoryActionId::OPTIONS}, + {StoryStepKind::ROUTE, "", StoryActionId::ROUTE}, + {StoryStepKind::LEGS, "", StoryActionId::LEGS}, + {StoryStepKind::STEP, "", StoryActionId::STEP}, + {StoryStepKind::TALK, "", StoryActionId::TALK}, + {StoryStepKind::ANSWER, "", StoryActionId::ANSWER}, + {StoryStepKind::MASH, "", StoryActionId::MASH}, + {StoryStepKind::BATTLE, "", StoryActionId::BATTLE}, + {StoryStepKind::HEAL, "", StoryActionId::HEAL}, + {StoryStepKind::SHOP, "", StoryActionId::SHOP}, + {StoryStepKind::READY, "", StoryActionId::READY}, + {StoryStepKind::GAME, "", StoryActionId::GAME}, + }; + return ROWS; +} + +Pokemon::StoryActionTable make_story_action_table(const StoryActionBinding& bind){ + Pokemon::StoryActionTable table; + for (const StoryActionRow& row : story_action_rows()){ + table.add(row.kind, row.variant, bind(row.id)); + } + return table; +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h new file mode 100644 index 0000000000..002e749cb3 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h @@ -0,0 +1,73 @@ +/* AutoStory Step Table + * + * From: https://github.com/PokemonAutomation/ + * + * FRLG's story steps as rows of the shared action table + * (Pokemon/AutoStory/Pokemon_StoryActions.h): each row names what does + * a kind of step, or one variant of it. The console (StoryExecutor) binds + * each name to its console action; the tests bind them to a recorder, so + * the rows are checked without a console. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryStepTable_H +#define PokemonAutomation_PokemonFRLG_AutoStoryStepTable_H + +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/AutoStory/Pokemon_StoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StorySteps.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// What does a step: one of FRLG's story actions. +enum class StoryActionId{ + NEW_GAME, + OPTIONS, + ROUTE, + LEGS, + STEP, + TALK, + ANSWER, + MASH, + BATTLE, + HEAL, + SHOP, + READY, + // A GAME step: one only FRLG has. + GAME, +}; +// "route", "game": the action's name in logs and test traces. +const char* story_action_name(StoryActionId id); + +// A row of FRLG's table: the action for steps of `kind` whose variant is +// named `variant`, or for every other step of `kind` if it is empty. +struct StoryActionRow{ + Pokemon::StoryStepKind kind; + std::string variant; + StoryActionId id; +}; +// Every row. TRAIN and SAVE have none: FRLG's story doesn't use them. +const std::vector& story_action_rows(); + +// How one binding (the console, a test) does each action. +using StoryActionBinding = std::function; +// The rows as a table, each with `bind`'s action for its id. +Pokemon::StoryActionTable make_story_action_table(const StoryActionBinding& bind); + + +// The rows against the dispatch they replaced, and every checkpoint linted +// against them. +void add_tests_AutoStoryStepTable(UnitTestDatabase& database); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp new file mode 100644 index 0000000000..1934284d6a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp @@ -0,0 +1,234 @@ +/* AutoStory Step Table Tests + * + * From: https://github.com/PokemonAutomation/ + * + * FRLG's rows run with a recorder for each action: every step of the + * story, and every kind with each variant the rows name, must reach the + * action the per-kind dispatch they replaced reached. + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_StoryActions.h" +#include "PokemonFRLG_AutoStoryStepTable.h" +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +using Pokemon::StoryStepKind; + +const StoryStepKind ALL_KINDS[] = { + StoryStepKind::NEW_GAME, StoryStepKind::OPTIONS, StoryStepKind::ROUTE, StoryStepKind::LEGS, + StoryStepKind::STEP, StoryStepKind::TALK, StoryStepKind::ANSWER, StoryStepKind::MASH, + StoryStepKind::BATTLE, StoryStepKind::TRAIN, StoryStepKind::HEAL, StoryStepKind::SHOP, + StoryStepKind::SAVE, StoryStepKind::READY, StoryStepKind::GAME, +}; + +// The action StoryExecutor ran for `step` before the table: the shared +// per-kind dispatch (StoryStepExecutor::run()) into the kinds it +// overrode. Nothing for the kinds it left to the shared executor. +std::optional old_dispatch(const StoryStep& step){ + switch (step.kind){ + case StoryStepKind::NEW_GAME: return StoryActionId::NEW_GAME; + case StoryStepKind::OPTIONS: return StoryActionId::OPTIONS; + case StoryStepKind::ROUTE: return StoryActionId::ROUTE; + case StoryStepKind::LEGS: return StoryActionId::LEGS; + case StoryStepKind::STEP: return StoryActionId::STEP; + case StoryStepKind::TALK: return StoryActionId::TALK; + case StoryStepKind::ANSWER: return StoryActionId::ANSWER; + case StoryStepKind::MASH: return StoryActionId::MASH; + case StoryStepKind::BATTLE: return StoryActionId::BATTLE; + case StoryStepKind::HEAL: return StoryActionId::HEAL; + case StoryStepKind::SHOP: return StoryActionId::SHOP; + case StoryStepKind::READY: return StoryActionId::READY; + case StoryStepKind::GAME: return StoryActionId::GAME; + case StoryStepKind::TRAIN: + case StoryStepKind::SAVE: + return std::nullopt; + } + return std::nullopt; +} + +// FRLG's rows bound to a recorder: each action adds its name to `trace`. +class FakeGame{ +public: + FakeGame() + : m_table(make_story_action_table([this](StoryActionId id){ return recorder(id); })) + , m_executor(m_table, m_guard) + {} + + const Pokemon::StoryActionTable& table() const{ + return m_table; + } + // `step` through the table: the outcome, and the actions it ran. + Pokemon::Outcome run(const StoryStep& step, std::vector& trace){ + m_trace = &trace; + Pokemon::RunState state; + return m_executor.run(state, step); + } + +private: + Pokemon::StoryAction recorder(StoryActionId id){ + return {.act = [this, id](Pokemon::RunState&, const StoryStep&){ + m_trace->emplace_back(story_action_name(id)); + return Pokemon::outcome_ok(); + }}; + } + + std::vector* m_trace = nullptr; + Pokemon::StepGuard m_guard; + Pokemon::StoryActionTable m_table; + Pokemon::TableExecutor m_executor; +}; + +// Why `step` didn't run what old_dispatch() did, or empty. +std::string parity_error(FakeGame& game, const StoryStep& step){ + std::vector trace; + const Pokemon::Outcome outcome = game.run(step, trace); + const std::optional expected = old_dispatch(step); + const std::string label = std::format("{} '{}' ({})", Pokemon::story_step_kind_name(step.kind), step.variant, step.name); + if (!expected){ + if (!trace.empty() || outcome.failure != "unsupported_step"){ + return label + ": expected unsupported, ran " + (trace.empty() ? outcome.failure : trace[0]); + } + return ""; + } + if (trace != std::vector{story_action_name(*expected)} || !outcome.succeeded()){ + return std::format("{}: expected {}, ran {} action(s){}", label, story_action_name(*expected), + trace.size(), trace.empty() ? "" : ", first " + trace[0]); + } + return ""; +} + +// Every kind, with no variant, an unknown one, and each one a row names. +std::vector every_kind_and_variant(){ + std::vector variants{"", "no_such_variant", "no_such_variant key=1"}; + for (const StoryActionRow& row : story_action_rows()){ + if (!row.variant.empty()){ + variants.push_back(row.variant); + } + } + std::vector steps; + for (StoryStepKind kind : ALL_KINDS){ + for (const std::string& variant : variants){ + StoryStep step; + step.kind = kind; + step.name = "synthetic"; + step.variant = variant; + steps.push_back(std::move(step)); + } + } + return steps; +} + +UnitTestResult test_parity_every_kind(){ + FakeGame game; + for (const StoryStep& step : every_kind_and_variant()){ + const std::string error = parity_error(game, step); + if (!error.empty()){ + return error; + } + } + return true; +} + +UnitTestResult test_parity_story_steps(){ + FakeGame game; + for (const StoryCheckpoint& data : story_checkpoints()){ + for (const StoryStep& step : data.steps){ + const std::string error = parity_error(game, step); + if (!error.empty()){ + return data.id + " " + error; + } + } + } + return true; +} + +UnitTestResult test_every_step_bound(){ + FakeGame game; + std::string problems; + for (const StoryCheckpoint& data : story_checkpoints()){ + for (const std::string& problem : Pokemon::lint_story_checkpoint(data, game.table())){ + problems += "\n" + problem; + } + } + if (!problems.empty()){ + return "Expected every step to have an action:" + problems; + } + return true; +} + + +struct StepTableInput{ + std::string name; + UnitTestResult (*body)(); +}; + +struct StepTableExpectation{ + const char* description; +}; + +struct StepTableTestCase{ + StepTableInput input; + StepTableExpectation expectation; +}; + +class Test_StepTable : public UnitTest{ +public: + explicit Test_StepTable(StepTableTestCase scenario) + : UnitTest("PokemonFRLG::AutoStoryStepTable - " + scenario.input.name) + , m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_scenario.input.body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + StepTableTestCase m_scenario; +}; + +const StepTableTestCase STEP_TABLE_CASES[] = { + { + .input = {.name = "every kind and variant runs what the per-kind dispatch ran", .body = test_parity_every_kind}, + .expectation = {.description = "table rows match the replaced dispatch for each kind and variant"}, + }, + { + .input = {.name = "every story step runs what the per-kind dispatch ran", .body = test_parity_story_steps}, + .expectation = {.description = "table rows match the replaced dispatch for each authored step"}, + }, + { + .input = {.name = "every checkpoint's steps have an action", .body = test_every_step_bound}, + .expectation = {.description = "lint_story_checkpoint finds no unbound step"}, + }, +}; + +} // namespace + + +void add_tests_AutoStoryStepTable(UnitTestDatabase& database){ + for (const auto& scenario : STEP_TABLE_CASES){ + database.add(scenario); + } +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 92bdc731b1..0fcb182872 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1883,6 +1883,9 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp From adba2e842f68e94b1b52e3502254c46388f7171d Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 01:41:42 -0800 Subject: [PATCH 06/29] FRLG AutoStory: register the step table tests with the simulation tests PokemonFRLG_Tests.cpp and PokemonFRLG_AutoStory_Tests.cpp reach their length limits further down the stack, so add_tests_AutoStorySimulation() registers them. A StoryExecutor can't be copied: its table's actions point at it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp | 2 -- .../Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h | 3 +++ .../AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 1ec1732b99..cea4ff7bc9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -40,7 +40,6 @@ #include "Overworld/PokemonFRLG_PlayerFacingReader.h" #include "PokemonFRLG_Navigation.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h" -#include "Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryTable.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h" #include "Tests/TestUtils.h" @@ -320,7 +319,6 @@ void add_tests(UnitTestDatabase& database){ add_tests_OverworldRecovery(database); add_tests_PlayerFacingReader(database); add_tests_AutoStory(database); - add_tests_AutoStoryStepTable(database); add_tests_AutoStoryExport(database); add_tests_AutoStorySimulation(database); add_tests_AutoStoryItems(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index c58aa9ecf0..022bb06be1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -154,6 +154,9 @@ void read_bag_supplies(StoryEnv& env, StartMenu menu); class StoryExecutor : public Pokemon::StoryStepExecutor{ public: explicit StoryExecutor(StoryEnv& env); + // Its table's actions point at it. + StoryExecutor(const StoryExecutor&) = delete; + StoryExecutor& operator=(const StoryExecutor&) = delete; StoryEnv& env(){ return m_env; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index bf6ac032a3..a029c9c09a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -24,6 +24,7 @@ #include "Pokemon/AutoStory/Pokemon_StorySegments.h" #include "Pokemon/AutoStory/Pokemon_StorySteps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" namespace PokemonAutomation{ @@ -412,6 +413,7 @@ const AutoStorySimulationTestCase AUTO_STORY_SIMULATION_CASES[] = { void add_tests_AutoStorySimulation(UnitTestDatabase& database){ + add_tests_AutoStoryStepTable(database); for (const auto& scenario : AUTO_STORY_SIMULATION_CASES){ database.add(scenario); } From ef16b37bf4aee970cc3e2aef8ad55ed39d09c745 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 01:58:34 -0800 Subject: [PATCH 07/29] FRLG AutoStory: a sim test for a save off the checkpoint's start pose console B, 00.27, 2026-11-09: the save stood in Cerulean City below the Center's door; nothing checked it against the row's start, and the run walked as if from the counter. Red: 00.09 from a save below Pewter Center's door runs its steps. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index a029c9c09a..aacaea1f55 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -116,6 +116,9 @@ class FakeGame : public Pokemon::StoryStepExecutor{ std::vector trace; std::map failures; + // Where the save loaded stands, when it isn't where its checkpoint + // starts: the start check reads it. + std::optional save_stands; // What the Mart sold, by its list's names. std::map bag; @@ -377,6 +380,45 @@ UnitTestResult test_retry_from_save(){ return true; } +// Outside `building`'s door on `map`, facing away from it. +StoryPose below_door(const std::string& map, const std::string& building){ + const MapData* data = map_named(map); + if (data != nullptr){ + for (const MapWarp& warp : data->warps){ + if (warp.to && warp.to->map == building){ + return StoryPose{map, TilePos{warp.x, warp.y}.next(Direction::SOUTH), Direction::SOUTH}; + } + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No door to " + building + " on " + map); +} + +// console B, FRLG 00.27, 2026-11-09: the save stood in Cerulean City below +// the Center's door, not at the counter where the checkpoint starts; the +// run walked south as if from the counter and failed at a warp. 00.09 +// starts at Pewter's counter: from a save below that Center's door, the +// start check stops it before any step and without saving. +UnitTestResult test_save_off_start_pose(){ + Simulation sim; + sim.game.save_stands = below_door("PewterCity", "PewterCity_PokemonCenter_1F"); + const Pokemon::SegmentReport report = sim.run({.from = "00.09", .to = "00.09"}); + const bool stepped = std::any_of(sim.game.trace.begin(), sim.game.trace.end(), [](const std::string& item){ + return item.starts_with("00.09/"); + }); + if (report.completed || report.failed_checkpoint != "00.09" || report.failure.failure != "start_failed" + || stepped || !sim.saves.empty() + ){ + return "Expected 00.09 stopped at its start check, before any step:" + joined(sim.game.trace) + joined(sim.lines); + } + const bool told = std::any_of(sim.lines.begin(), sim.lines.end(), [](const std::string& line){ + return line.starts_with("start pose mismatch: "); + }); + if (!told){ + return "Expected the mismatch logged:" + joined(sim.lines); + } + return true; +} + // Brock's battle lost every time: three attempts, then the stop. UnitTestResult test_gives_up_after_attempts(){ Simulation sim; @@ -407,6 +449,10 @@ const AutoStorySimulationTestCase AUTO_STORY_SIMULATION_CASES[] = { .input = {.name = "a battle lost every time stops after 3 attempts", .body = test_gives_up_after_attempts}, .expectation = {.description = "aborts after three consecutive battle blackouts"}, }, + { + .input = {.name = "a save off the start pose stops before any step", .body = test_save_off_start_pose}, + .expectation = {.description = "fails the start check without walking or saving"}, + }, }; } // namespace From 7d5be2ccd64ecf0ce2824c00ea30a497fa26cac4 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 02:00:45 -0800 Subject: [PATCH 08/29] FRLG AutoStory: check the save stands at the checkpoint's start pose Every row with a start pose gets the engine's start check (Checkpoint::start): the save it starts from, as the game reads it, must stand on the start's map and tile, and face its way when both facings are known, or the checkpoint stops with start_failed before its first step and without saving. The sim reads the fake game's save; the console has no tile reader yet, so there the check logs that nothing was read and passes, behind the save card's place check at load. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 44 ++++++++++++++++++- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 21 +++++++++ .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 17 ++++--- 3 files changed, 75 insertions(+), 7 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 26f334f1ea..5bd4658628 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -336,6 +336,41 @@ std::string save_place_error(const std::string& start_map, const std::string& pl return "The save is in " + place + ", but the checkpoint starts in " + expected + " (" + start_map + ")."; } +std::string start_pose_mismatch(const Pokemon::Pose& start, const StoryPose& stands){ + const std::optional at = story_pose(start); + if (at && at->map == stands.map && at->tile == stands.tile + && (!at->facing || !stands.facing || at->facing == stands.facing) + ){ + return ""; + } + return "The save stands at " + Pokemon::to_string(to_pose(stands)) + + ", but the checkpoint starts at " + Pokemon::to_string(start) + "."; +} + +Pokemon::Checkpoint build_checked_checkpoint( + const StoryCheckpoint& data, Pokemon::StoryStepExecutor& executor, SavePoseReader read, StoryLog log +){ + Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); + if (!data.start){ + return checkpoint; + } + checkpoint.start.push_back(Pokemon::condition("save_at_start_pose", + [start = *data.start, read = std::move(read), log = std::move(log)](RunState&){ + const std::optional stands = read(); + if (!stands){ + log("start pose not read: going on from the save as the checkpoint's start."); + return true; + } + const std::string mismatch = start_pose_mismatch(start, *stands); + if (!mismatch.empty()){ + log("start pose mismatch: " + mismatch); + } + return mismatch.empty(); + } + )); + return checkpoint; +} + std::optional> fixed_route( const std::vector& maps, const MapPosition& start, const std::vector& legs ){ @@ -510,8 +545,15 @@ void read_bag_supplies(StoryEnv& env, StartMenu menu){ Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& executor){ executor.set_menu(data.menu); - Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); StoryEnv& env = executor.env(); + // The console has no reader for the tile the save stands on yet: the + // save card's place is checked when the save is loaded + // (check_save_place()), and the start check passes. + Pokemon::Checkpoint checkpoint = build_checked_checkpoint( + data, executor, + []{ return std::optional(); }, + [&env](const std::string& line){ env.console.log(line, COLOR_ORANGE); } + ); env.start_map = data.start ? data.start->map : ""; env.start_menu = data.menu; const StartMenu menu = data.menu; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 022bb06be1..3867e5aa1f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -20,6 +20,7 @@ #ifndef PokemonAutomation_PokemonFRLG_AutoStoryEvents_H #define PokemonAutomation_PokemonFRLG_AutoStoryEvents_H +#include #include #include #include @@ -92,6 +93,26 @@ std::string save_card_place(const std::string& map); // be read (empty `place`), or the map has no known place. std::string save_place_error(const std::string& start_map, const std::string& place); +// Why a save standing at `stands` can't start a checkpoint that starts at +// `start`, or empty if it can: the same map and tile, and the same facing +// when both are known. +std::string start_pose_mismatch(const Pokemon::Pose& start, const StoryPose& stands); + +// Where the save just loaded stands, as the game reads it: nothing when it +// can't be read. +using SavePoseReader = std::function()>; +// Where the start check says what it found. +using StoryLog = std::function; + +// The checkpoint `data` as events (Pokemon::build_story_checkpoint()), and +// for a row with a start pose, the start check: the save it starts from, +// as `read` reads it, must stand there (start_pose_mismatch()), or the +// checkpoint stops before its first event, "start_failed". A save that +// can't be read passes. `log` gets a mismatch, or that nothing was read. +Pokemon::Checkpoint build_checked_checkpoint( + const StoryCheckpoint& data, Pokemon::StoryStepExecutor& executor, SavePoseReader read, StoryLog log +); + // `legs` from `start` as route steps for the walker, each checked against // the map: nothing if a step is blocked or leaves the map. A leg ends "to // wall" if the next step its way is blocked. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index aacaea1f55..9d5ab91021 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -241,7 +241,13 @@ struct Simulation{ for (const StoryCheckpoint& data : story_checkpoints()){ segment.checkpoints.push_back(Pokemon::CheckpointSpec{ .id = data.id, .title = data.title, .saves = true, - .build = [this, &data]{ return Pokemon::build_story_checkpoint(data, game); }, + .build = [this, &data]{ + return build_checked_checkpoint( + data, game, + [this]{ return game.save_stands; }, + [this](const std::string& line){ lines.push_back(line); } + ); + }, }); } Pokemon::SegmentHooks hooks; @@ -383,11 +389,10 @@ UnitTestResult test_retry_from_save(){ // Outside `building`'s door on `map`, facing away from it. StoryPose below_door(const std::string& map, const std::string& building){ const MapData* data = map_named(map); - if (data != nullptr){ - for (const MapWarp& warp : data->warps){ - if (warp.to && warp.to->map == building){ - return StoryPose{map, TilePos{warp.x, warp.y}.next(Direction::SOUTH), Direction::SOUTH}; - } + const std::vector none; + for (const MapWarp& warp : data ? data->warps : none){ + if (warp.to && warp.to->map == building){ + return StoryPose{map, TilePos{warp.x, warp.y}.next(Direction::SOUTH), Direction::SOUTH}; } } throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No door to " + building + " on " + map); From 6f235d3e44346d34ec7f01969b8adbef850d628c Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 02:04:03 -0800 Subject: [PATCH 09/29] FRLG AutoStory: add the start pose check to a checkpoint already built The later stages build rows with build_story_checkpoint()'s PreparedSteps overload; add_start_pose_check() takes the built checkpoint, so each builder keeps its own call. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 17 ++++++++--------- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 15 ++++++++------- .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 19 ++++++++++++------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 5bd4658628..134a83256f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -347,15 +347,14 @@ std::string start_pose_mismatch(const Pokemon::Pose& start, const StoryPose& sta + ", but the checkpoint starts at " + Pokemon::to_string(start) + "."; } -Pokemon::Checkpoint build_checked_checkpoint( - const StoryCheckpoint& data, Pokemon::StoryStepExecutor& executor, SavePoseReader read, StoryLog log +void add_start_pose_check( + Pokemon::Checkpoint& checkpoint, const std::optional& start, SavePoseReader read, StoryLog log ){ - Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); - if (!data.start){ - return checkpoint; + if (!start){ + return; } checkpoint.start.push_back(Pokemon::condition("save_at_start_pose", - [start = *data.start, read = std::move(read), log = std::move(log)](RunState&){ + [start = *start, read = std::move(read), log = std::move(log)](RunState&){ const std::optional stands = read(); if (!stands){ log("start pose not read: going on from the save as the checkpoint's start."); @@ -368,7 +367,6 @@ Pokemon::Checkpoint build_checked_checkpoint( return mismatch.empty(); } )); - return checkpoint; } std::optional> fixed_route( @@ -549,8 +547,9 @@ Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& // The console has no reader for the tile the save stands on yet: the // save card's place is checked when the save is loaded // (check_save_place()), and the start check passes. - Pokemon::Checkpoint checkpoint = build_checked_checkpoint( - data, executor, + Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); + add_start_pose_check( + checkpoint, data.start, []{ return std::optional(); }, [&env](const std::string& line){ env.console.log(line, COLOR_ORANGE); } ); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 3867e5aa1f..701d5f335c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -104,13 +104,14 @@ using SavePoseReader = std::function()>; // Where the start check says what it found. using StoryLog = std::function; -// The checkpoint `data` as events (Pokemon::build_story_checkpoint()), and -// for a row with a start pose, the start check: the save it starts from, -// as `read` reads it, must stand there (start_pose_mismatch()), or the -// checkpoint stops before its first event, "start_failed". A save that -// can't be read passes. `log` gets a mismatch, or that nothing was read. -Pokemon::Checkpoint build_checked_checkpoint( - const StoryCheckpoint& data, Pokemon::StoryStepExecutor& executor, SavePoseReader read, StoryLog log +// Adds to `checkpoint`, built from a row that starts at `start`, the start +// check: the save it starts from, as `read` reads it, must stand there +// (start_pose_mismatch()), or the checkpoint stops before its first event, +// "start_failed". A save that can't be read passes. `log` gets a +// mismatch, or that nothing was read. A row with no start (a new game) +// gets none. +void add_start_pose_check( + Pokemon::Checkpoint& checkpoint, const std::optional& start, SavePoseReader read, StoryLog log ); // `legs` from `start` as route steps for the walker, each checked against diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index 9d5ab91021..e057d26a42 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -241,13 +241,7 @@ struct Simulation{ for (const StoryCheckpoint& data : story_checkpoints()){ segment.checkpoints.push_back(Pokemon::CheckpointSpec{ .id = data.id, .title = data.title, .saves = true, - .build = [this, &data]{ - return build_checked_checkpoint( - data, game, - [this]{ return game.save_stands; }, - [this](const std::string& line){ lines.push_back(line); } - ); - }, + .build = [this, &data]{ return build_row(data); }, }); } Pokemon::SegmentHooks hooks; @@ -264,6 +258,17 @@ struct Simulation{ RunState state; return Pokemon::run_segment(state, segment, range, policy, hooks); } + // As the program builds it, with the start check reading the fake + // game's save. + Pokemon::Checkpoint build_row(const StoryCheckpoint& data){ + Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, game); + add_start_pose_check( + checkpoint, data.start, + [this]{ return game.save_stands; }, + [this](const std::string& line){ lines.push_back(line); } + ); + return checkpoint; + } std::string last_begun() const{ for (auto it = game.trace.rbegin(); it != game.trace.rend(); ++it){ if (it->starts_with("begin ")){ From 77c0d8dd4da57d425af5e173c568f1d27181c806 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 02:07:57 -0800 Subject: [PATCH 10/29] FRLG AutoStory: shorten the start pose sim test The stage 5 simulation tests would pass the file length limit with it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 59 +++++-------------- 1 file changed, 15 insertions(+), 44 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index e057d26a42..56328674f7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -116,8 +116,7 @@ class FakeGame : public Pokemon::StoryStepExecutor{ std::vector trace; std::map failures; - // Where the save loaded stands, when it isn't where its checkpoint - // starts: the start check reads it. + // Where the save loaded stands, when not at its checkpoint's start. std::optional save_stands; // What the Mart sold, by its list's names. std::map bag; @@ -241,7 +240,11 @@ struct Simulation{ for (const StoryCheckpoint& data : story_checkpoints()){ segment.checkpoints.push_back(Pokemon::CheckpointSpec{ .id = data.id, .title = data.title, .saves = true, - .build = [this, &data]{ return build_row(data); }, + .build = [this, &data]{ + Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, game); + add_start_pose_check(checkpoint, data.start, [this]{ return game.save_stands; }, [this](const std::string& line){ lines.push_back(line); }); + return checkpoint; + }, }); } Pokemon::SegmentHooks hooks; @@ -258,17 +261,6 @@ struct Simulation{ RunState state; return Pokemon::run_segment(state, segment, range, policy, hooks); } - // As the program builds it, with the start check reading the fake - // game's save. - Pokemon::Checkpoint build_row(const StoryCheckpoint& data){ - Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, game); - add_start_pose_check( - checkpoint, data.start, - [this]{ return game.save_stands; }, - [this](const std::string& line){ lines.push_back(line); } - ); - return checkpoint; - } std::string last_begun() const{ for (auto it = game.trace.rbegin(); it != game.trace.rend(); ++it){ if (it->starts_with("begin ")){ @@ -391,40 +383,19 @@ UnitTestResult test_retry_from_save(){ return true; } -// Outside `building`'s door on `map`, facing away from it. -StoryPose below_door(const std::string& map, const std::string& building){ - const MapData* data = map_named(map); - const std::vector none; - for (const MapWarp& warp : data ? data->warps : none){ - if (warp.to && warp.to->map == building){ - return StoryPose{map, TilePos{warp.x, warp.y}.next(Direction::SOUTH), Direction::SOUTH}; - } - } - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No door to " + building + " on " + map); -} - -// console B, FRLG 00.27, 2026-11-09: the save stood in Cerulean City below -// the Center's door, not at the counter where the checkpoint starts; the -// run walked south as if from the counter and failed at a warp. 00.09 -// starts at Pewter's counter: from a save below that Center's door, the -// start check stops it before any step and without saving. +// console B, FRLG 00.27, 2026-11-09: the save stood below Cerulean Center's +// door, and the run walked as if from the counter where 00.27 starts. 00.09 +// from below Pewter Center's door (17, 25) stops before any step or save. UnitTestResult test_save_off_start_pose(){ Simulation sim; - sim.game.save_stands = below_door("PewterCity", "PewterCity_PokemonCenter_1F"); + sim.game.save_stands = StoryPose{"PewterCity", TilePos{17, 26}, Direction::SOUTH}; const Pokemon::SegmentReport report = sim.run({.from = "00.09", .to = "00.09"}); - const bool stepped = std::any_of(sim.game.trace.begin(), sim.game.trace.end(), [](const std::string& item){ - return item.starts_with("00.09/"); - }); - if (report.completed || report.failed_checkpoint != "00.09" || report.failure.failure != "start_failed" - || stepped || !sim.saves.empty() + const auto stepped = [](const std::string& item){ return item.starts_with("00.09/"); }; + const auto told = [](const std::string& line){ return line.starts_with("start pose mismatch: "); }; + if (report.completed || report.failure.failure != "start_failed" || !sim.saves.empty() + || std::ranges::any_of(sim.game.trace, stepped) || std::ranges::none_of(sim.lines, told) ){ - return "Expected 00.09 stopped at its start check, before any step:" + joined(sim.game.trace) + joined(sim.lines); - } - const bool told = std::any_of(sim.lines.begin(), sim.lines.end(), [](const std::string& line){ - return line.starts_with("start pose mismatch: "); - }); - if (!told){ - return "Expected the mismatch logged:" + joined(sim.lines); + return "Expected 00.09 stopped at its start check, the mismatch logged:" + joined(sim.game.trace) + joined(sim.lines); } return true; } From 7f0dd9bc7a52dc73841be56dd61b99bb6de8a863 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 03:21:17 -0800 Subject: [PATCH 11/29] FRLG AutoStory: check a loaded save's start against a kept frame The console had no reader for the map and tile a save stands on, so the start check always passed. Each save at a checkpoint's end now keeps a frame of the game screen as the next checkpoint's start frame (PNG and JSON under USER_FILE_PATH()/PokemonFRLG/AutoStoryStartFrames/), and the start check compares the screen after a save loads with it, tile by tile, ignoring people who moved. A clear mismatch stops the checkpoint before any step or save; no frame kept passes as before. The option "Keep the start frame" keeps one from a save made by hand. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 + .../AutoStory/PokemonFRLG_AutoStory.cpp | 10 + .../AutoStory/PokemonFRLG_AutoStory.h | 1 + .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 123 +++++- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 33 +- .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 84 +++- .../PokemonFRLG_AutoStoryStartFrames.cpp | 170 ++++++++ .../PokemonFRLG_AutoStoryStartFrames.h | 110 +++++ ...PokemonFRLG_AutoStoryStartFrames_Tests.cpp | 384 ++++++++++++++++++ SerialPrograms/cmake/SourceFiles.cmake | 3 + 10 files changed, 897 insertions(+), 23 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index cea4ff7bc9..ac4f4e3003 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -9,6 +9,7 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/StaticGlobals.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.h" +#include "Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h" #include "Inference/Box/PokemonFRLG_BoxCellOccupiedDetector.h" #include "Inference/Box/PokemonFRLG_BoxCellReader.h" #include "Inference/Box/PokemonFRLG_BoxGenderReader.h" @@ -323,6 +324,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStorySimulation(database); add_tests_AutoStoryItems(database); add_tests_AutoStoryScreenEvents(database); + add_tests_AutoStoryStartFrames(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index bc6683fb45..2ef8568881 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -60,6 +60,13 @@ AutoStory::AutoStory() LockMode::LOCK_WHILE_RUNNING, true ) + , KEEP_START_FRAME( + "Keep the start frame:
Off by default. The save loaded was made by hand where the start checkpoint " + "begins: keep the screen after loading it as that checkpoint's start frame, which later runs compare their " + "save with. The program keeps one by itself at each save it makes.", + LockMode::LOCK_WHILE_RUNNING, + false + ) , NOTIFICATIONS({ &NOTIFICATION_PROGRAM_FINISH, &NOTIFICATION_ERROR_FATAL, @@ -67,6 +74,7 @@ AutoStory::AutoStory() { PA_ADD_OPTION(RUN); PA_ADD_OPTION(NEW_GAME_FROM_TITLE); + PA_ADD_OPTION(KEEP_START_FRAME); PA_ADD_OPTION(NOTIFICATIONS); } @@ -154,6 +162,7 @@ void verify_story_checkpoint( const std::vector& checkpoints = story_checkpoints(); const StoryCheckpoint& checkpoint = checkpoints[run.start_index()]; StoryEnv story{env.console, context, checkpoint.supplies, checkpoint.supplies, false, run.checks()}; + use_start_frames(story, false); load_verify_save(env, context, story, checkpoint); StoryExecutor executor(story); executor.set_checks(run.checks()); @@ -192,6 +201,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex } StoryEnv story{env.console, context, checkpoints[first].supplies, checkpoints[first].supplies, false, RUN.checks()}; + use_start_frames(story, KEEP_START_FRAME); if (!(first == 0 && NEW_GAME_FROM_TITLE)){ env.console.log("Loading the save for " + checkpoints[first].id + "."); soft_reset(env.console, context); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h index 7ca3556eb0..2ded1ec039 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h @@ -47,6 +47,7 @@ class AutoStory : public SingleSwitchProgramInstance{ // every game's AutoStory. Pokemon::StoryRunOptions RUN; BooleanCheckBoxOption NEW_GAME_FROM_TITLE; + BooleanCheckBoxOption KEEP_START_FRAME; EventNotificationsOption NOTIFICATIONS; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 134a83256f..5aaca54cda 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -9,6 +9,8 @@ #include #include "Common/Cpp/Exceptions.h" #include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "Pokemon/Navigation/Pokemon_RouteLog.h" @@ -16,9 +18,11 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStorySummary.h" +#include "PokemonFRLG_AutoStoryTable.h" #include "PokemonFRLG_AutoStoryWinChance.h" namespace PokemonAutomation{ @@ -347,28 +351,51 @@ std::string start_pose_mismatch(const Pokemon::Pose& start, const StoryPose& sta + ", but the checkpoint starts at " + Pokemon::to_string(start) + "."; } -void add_start_pose_check( - Pokemon::Checkpoint& checkpoint, const std::optional& start, SavePoseReader read, StoryLog log +void add_start_check( + Pokemon::Checkpoint& checkpoint, const std::optional& start, StartReader read, StoryLog log ){ if (!start){ return; } checkpoint.start.push_back(Pokemon::condition("save_at_start_pose", - [start = *start, read = std::move(read), log = std::move(log)](RunState&){ - const std::optional stands = read(); - if (!stands){ - log("start pose not read: going on from the save as the checkpoint's start."); + [read = std::move(read), log = std::move(log)](RunState&){ + const StartRead found = read(); + switch (found.found){ + case StartFound::NOT_READ: + log("start pose not read: " + (found.detail.empty() ? "" : found.detail + "; ") + + "going on from the save as the checkpoint's start."); return true; + case StartFound::AT_START: + if (!found.detail.empty()){ + log("start pose matches: " + found.detail); + } + return true; + case StartFound::ELSEWHERE: + log("start pose mismatch: " + found.detail); + return false; } - const std::string mismatch = start_pose_mismatch(start, *stands); - if (!mismatch.empty()){ - log("start pose mismatch: " + mismatch); - } - return mismatch.empty(); + return false; } )); } +void add_start_pose_check( + Pokemon::Checkpoint& checkpoint, const std::optional& start, SavePoseReader read, StoryLog log +){ + if (!start){ + return; + } + StartReader reader = [start = *start, read = std::move(read)]() -> StartRead{ + const std::optional stands = read(); + if (!stands){ + return {}; + } + const std::string mismatch = start_pose_mismatch(start, *stands); + return mismatch.empty() ? StartRead{StartFound::AT_START} : StartRead{StartFound::ELSEWHERE, mismatch}; + }; + add_start_check(checkpoint, start, std::move(reader), std::move(log)); +} + std::optional> fixed_route( const std::vector& maps, const MapPosition& start, const std::vector& legs ){ @@ -541,24 +568,86 @@ void read_bag_supplies(StoryEnv& env, StartMenu menu){ } } +namespace{ + +// Frames the start check tries (read_start_frames()), a second apart. +constexpr size_t START_FRAME_TRIES = 3; +constexpr Milliseconds START_FRAME_WAIT = 1000ms; + +// The game screen now, as the start frames keep it; empty with no video. +ImageRGB32 console_start_frame(StoryEnv& env){ + env.context.wait_for_all_requests(); + const VideoSnapshot snapshot = env.console.video().snapshot(); + if (!snapshot){ + return ImageRGB32(); + } + return start_frame(extract_box_reference(snapshot, GameSettings::instance().GAME_BOX)); +} + +// The console's start check for `checkpoint`: the screen against the +// start frame kept for it. With keep_start_frame (a save made by hand), +// the screen is kept as that frame instead, and passes. +StartRead read_console_start(StoryEnv& env, const std::string& checkpoint){ + if (env.keep_start_frame){ + env.keep_start_frame = false; + const ImageRGB32 frame = console_start_frame(env); + if (!frame || !env.start_frames.save(checkpoint, frame, "kept by the program's option from the save loaded")){ + return {StartFound::NOT_READ, "couldn't keep the screen as " + checkpoint + "'s start frame"}; + } + return {StartFound::AT_START, "kept the screen as " + checkpoint + "'s start frame"}; + } + size_t frames = 0; + return read_start_frames(env.start_frames.load(checkpoint), [&env, &frames]{ + if (frames++ > 0){ + env.context.wait_for(START_FRAME_WAIT); + } + return console_start_frame(env); + }, START_FRAME_TRIES); +} + +// After the save at the end of `ended`: the screen, kept as the start +// frame of the table's next checkpoint, which starts there. +void keep_next_start_frame(StoryEnv& env, const std::string& ended){ + const std::vector& table = story_checkpoints(); + for (size_t c = 0; c + 1 < table.size(); c++){ + if (table[c].id != ended || !table[c + 1].start){ + continue; + } + const ImageRGB32 frame = console_start_frame(env); + if (frame){ + env.start_frames.save(table[c + 1].id, frame, "saved at the end of " + ended); + } + return; + } +} + +} // namespace + +void use_start_frames(StoryEnv& env, bool keep_first){ + env.start_frames = program_start_frames(); + env.keep_start_frame = keep_first; +} + Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& executor){ executor.set_menu(data.menu); StoryEnv& env = executor.env(); - // The console has no reader for the tile the save stands on yet: the - // save card's place is checked when the save is loaded - // (check_save_place()), and the start check passes. + // The console has no reader for the tile the save stands on: the save + // card's place is checked when the save is loaded (check_save_place()), + // and the start check compares the screen with the frame kept when the + // program last saved there. With none kept, it passes. Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); - add_start_pose_check( + add_start_check( checkpoint, data.start, - []{ return std::optional(); }, + [&env, id = data.id]{ return read_console_start(env, id); }, [&env](const std::string& line){ env.console.log(line, COLOR_ORANGE); } ); env.start_map = data.start ? data.start->map : ""; env.start_menu = data.menu; const StartMenu menu = data.menu; - checkpoint.save = [&env, menu](RunState&){ + checkpoint.save = [&env, menu, id = data.id](RunState&){ return guarded([&]{ save_game(env.console, env.context, menu); + keep_next_start_frame(env, id); env.has_save = true; env.saved_supplies = env.supplies; return Pokemon::outcome_ok(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 701d5f335c..d7a4d0905b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -35,6 +35,7 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryStartFrames.h" #include "PokemonFRLG_AutoStoryStepTable.h" namespace PokemonAutomation{ @@ -104,12 +105,22 @@ using SavePoseReader = std::function()>; // Where the start check says what it found. using StoryLog = std::function; +// Where the save just loaded is, against the start of the checkpoint it +// starts: the console's reads it from frames (PokemonFRLG_AutoStoryStartFrames.h). +using StartReader = std::function; + // Adds to `checkpoint`, built from a row that starts at `start`, the start -// check: the save it starts from, as `read` reads it, must stand there -// (start_pose_mismatch()), or the checkpoint stops before its first event, -// "start_failed". A save that can't be read passes. `log` gets a -// mismatch, or that nothing was read. A row with no start (a new game) -// gets none. +// check: the save it starts from, as `read` finds it, must be there, or +// the checkpoint stops before its first event, "start_failed". A save +// `read` can't tell about passes. `log` gets a mismatch ("start pose +// mismatch: "), that nothing was read ("start pose not read: "), or what +// a match saw. A row with no start (a new game) gets none. +void add_start_check( + Pokemon::Checkpoint& checkpoint, const std::optional& start, StartReader read, StoryLog log +); + +// add_start_check() with a reader of the tile the save stands on, which +// must be the start's (start_pose_mismatch()). void add_start_pose_check( Pokemon::Checkpoint& checkpoint, const std::optional& start, SavePoseReader read, StoryLog log ); @@ -150,8 +161,20 @@ struct StoryEnv{ std::string start_map = {}; // That checkpoint's START menu: a reload reads the bag again with it. StartMenu start_menu = StartMenu::BEFORE_POKEMON; + // The frames of where each checkpoint starts, for the start check: a + // save at a checkpoint's end keeps one for the next checkpoint. + StartFrameStore start_frames = {}; + // The next start check keeps the screen as its checkpoint's start + // frame and passes: the user saved there by hand. + bool keep_start_frame = false; }; +// The console's start check compares with the program's start frames +// (program_start_frames()); `keep_first`: the first start check keeps the +// screen as its checkpoint's frame instead (the option for a save made by +// hand). +void use_start_frames(StoryEnv& env, bool keep_first); + // After a save is loaded for a checkpoint that starts on `start_map`: the // save card's place, read from the START menu, against it, at every checks // level. Empty if the save is there (or the card can't be read), else why diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index 56328674f7..2c3a036cb9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -21,6 +21,7 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" #include "Pokemon/AutoStory/Pokemon_StorySegments.h" #include "Pokemon/AutoStory/Pokemon_StorySteps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" @@ -231,6 +232,9 @@ struct Simulation{ // Where each save stood: the end of its checkpoint. std::vector> saves; Pokemon::SegmentPolicy policy; + // The start check's reader, as the console's: unset, the fake game's + // save pose is read. + StartReader start_reader; // A language no reader supports, so a step that needed text would show. Pokemon::SegmentReport run(const Pokemon::SegmentRange& range){ @@ -242,7 +246,7 @@ struct Simulation{ .id = data.id, .title = data.title, .saves = true, .build = [this, &data]{ Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, game); - add_start_pose_check(checkpoint, data.start, [this]{ return game.save_stands; }, [this](const std::string& line){ lines.push_back(line); }); + add_start(checkpoint, data); return checkpoint; }, }); @@ -261,6 +265,14 @@ struct Simulation{ RunState state; return Pokemon::run_segment(state, segment, range, policy, hooks); } + void add_start(Pokemon::Checkpoint& checkpoint, const StoryCheckpoint& data){ + StoryLog log = [this](const std::string& line){ lines.push_back(line); }; + if (start_reader){ + add_start_check(checkpoint, data.start, start_reader, std::move(log)); + }else{ + add_start_pose_check(checkpoint, data.start, [this]{ return game.save_stands; }, std::move(log)); + } + } std::string last_begun() const{ for (auto it = game.trace.rbegin(); it != game.trace.rend(); ++it){ if (it->starts_with("begin ")){ @@ -400,6 +412,68 @@ UnitTestResult test_save_off_start_pose(){ return true; } +// A screen of 15x10 flat tiles coloured from `seed`, as start_frame() +// keeps it; `visitor` stands a person on tile (3, 3). +ImageRGB32 tiled_screen(uint32_t seed, bool visitor){ + ImageRGB32 screen(240, 160); + for (size_t ty = 0; ty < 10; ty++){ + for (size_t tx = 0; tx < 15; tx++){ + seed = seed * 1664525u + 1013904223u; + const bool person = visitor && tx == 3 && (ty == 2 || ty == 3); + const uint32_t color = person ? 0xffe84030 : (0xff000000 | (seed >> 8)); + for (size_t y = ty * 16; y < ty * 16 + 16; y++){ + for (size_t x = tx * 16; x < tx * 16 + 16; x++){ + screen.pixel(x, y) = color; + } + } + } + } + return screen; +} + +// 00.09 with the console's start check on frames: the frame kept for its +// start (tiled_screen(1), if `kept`) against `screen` after the save loads. +Pokemon::SegmentReport run_with_start_frame(Simulation& sim, bool kept, StartFrameSource screen){ + sim.start_reader = [kept, screen = std::move(screen)]{ + std::optional reference; + if (kept){ + reference = tiled_screen(1, false); + } + return read_start_frames(reference, screen, 3); + }; + return sim.run({.from = "00.09", .to = "00.09"}); +} + +// console B, FRLG 00.27, 2026-11-09, with no tile reader: the screen +// after the save loads isn't the frame kept where 00.09 starts, so it +// stops before any step or save. +UnitTestResult test_start_frame_elsewhere(){ + Simulation sim; + const Pokemon::SegmentReport report = run_with_start_frame(sim, true, []{ return tiled_screen(2, false); }); + const auto stepped = [](const std::string& item){ return item.starts_with("00.09/"); }; + const auto told = [](const std::string& line){ return line.starts_with("start pose mismatch: "); }; + if (report.completed || report.failure.failure != "start_failed" || !sim.saves.empty() + || std::ranges::any_of(sim.game.trace, stepped) || std::ranges::none_of(sim.lines, told) + ){ + return "Expected 00.09 stopped at its start check, the mismatch logged:" + joined(sim.game.trace) + joined(sim.lines); + } + return true; +} + +// The kept frame with a visitor in it, and none kept: both go on. +UnitTestResult test_start_frame_passes(){ + for (const bool kept : {true, false}){ + Simulation sim; + const Pokemon::SegmentReport report = run_with_start_frame(sim, kept, []{ return tiled_screen(1, true); }); + const std::string expected = kept ? "start pose matches: " : "start pose not read: no start frame kept"; + const auto told = [&](const std::string& line){ return line.starts_with(expected); }; + if (!report.completed || std::ranges::none_of(sim.lines, told)){ + return "Expected 00.09 run, \"" + expected + "\" logged:" + joined(sim.lines); + } + } + return true; +} + // Brock's battle lost every time: three attempts, then the stop. UnitTestResult test_gives_up_after_attempts(){ Simulation sim; @@ -434,6 +508,14 @@ const AutoStorySimulationTestCase AUTO_STORY_SIMULATION_CASES[] = { .input = {.name = "a save off the start pose stops before any step", .body = test_save_off_start_pose}, .expectation = {.description = "fails the start check without walking or saving"}, }, + { + .input = {.name = "a screen off the start frame stops before any step", .body = test_start_frame_elsewhere}, + .expectation = {.description = "fails the start check on frames without walking or saving"}, + }, + { + .input = {.name = "the start frame with a visitor, or none kept, goes on", .body = test_start_frame_passes}, + .expectation = {.description = "passes the start check on frames when the place matches or nothing is kept"}, + }, }; } // namespace diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp new file mode 100644 index 0000000000..62c1daeb40 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp @@ -0,0 +1,170 @@ +/* AutoStory Start Frames + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/PrettyPrint.h" +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "Common/Cpp/Json/JsonValue.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "PokemonFRLG_AutoStoryStartFrames.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +constexpr size_t FRAME_WIDTH = 240; +constexpr size_t FRAME_HEIGHT = 160; +constexpr size_t TILE = 16; +// A tile is compared as its four 8x8 quarters' average colours, so an +// animated tile, whose pattern shifts a few pixels, keeps its averages. +constexpr size_t BLOCK = 8; + +// The thresholds, from console B's captures (Route 10 outside the +// Center and on its grass, S.S. Anne's 1F corridor) and edits of them, +// with 8x8 quarters and 24 below: +// - the same frame with the player's 16x32 sprite copied onto one or two +// other tiles, as a person who walked there: 1 to 4 tiles changed of +// 150; the river's pattern shifted 2 or 4 pixels, as its animation +// does: 0 to 10; +// - another place on the same route, or Route 10 against the S.S. Anne: +// 131 and 148; +// - the view one step off: 20 to 78, depending on how plain the floor is; +// six steps along the S.S. Anne's plain corridor: 36. +// A quarter of the tiles (37) leaves room for a river and 6 people who +// moved (at most 4 tiles each: where they stood and stand), and catches +// another place and 5 of the 6 single steps off; a step along a plain +// corridor can pass. + +// A tile has changed when its quarters differ by more than this, on +// average per colour channel (0 to 255). +constexpr unsigned TILE_CHANGE = 24; +// The same place when at most a quarter of the tiles changed. +constexpr size_t MOST_CHANGED_PERCENT = 25; + +// The block at (`bx`, `by`): its channels' totals in `a` less those in +// `b`, summed as absolute values. +uint64_t block_difference(const ImageViewRGB32& a, const ImageViewRGB32& b, size_t bx, size_t by){ + int64_t sums[3] = {0, 0, 0}; + for (size_t y = by; y < by + BLOCK; y++){ + for (size_t x = bx; x < bx + BLOCK; x++){ + const uint32_t p = a.pixel(x, y); + const uint32_t q = b.pixel(x, y); + for (int c = 0; c < 3; c++){ + sums[c] += (int64_t)((p >> (8 * c)) & 0xff) - (int64_t)((q >> (8 * c)) & 0xff); + } + } + } + return (uint64_t)(std::llabs(sums[0]) + std::llabs(sums[1]) + std::llabs(sums[2])); +} + +// The tile at (`tx`, `ty`)'s quarters' average difference per channel. +unsigned tile_difference(const ImageViewRGB32& a, const ImageViewRGB32& b, size_t tx, size_t ty){ + uint64_t total = 0; + for (size_t by = ty * TILE; by < (ty + 1) * TILE; by += BLOCK){ + for (size_t bx = tx * TILE; bx < (tx + 1) * TILE; bx += BLOCK){ + total += block_difference(a, b, bx, by); + } + } + return (unsigned)(total / (TILE * TILE * 3)); +} + +} // namespace + + +ImageRGB32 start_frame(const ImageViewRGB32& game_screen){ + return game_screen.scale_to(FRAME_WIDTH, FRAME_HEIGHT); +} + +StartFrameDifference compare_start_frames(const ImageViewRGB32& reference, const ImageViewRGB32& frame){ + const ImageRGB32 a = start_frame(reference); + const ImageRGB32 b = start_frame(frame); + StartFrameDifference difference; + for (size_t ty = 0; ty < FRAME_HEIGHT / TILE; ty++){ + for (size_t tx = 0; tx < FRAME_WIDTH / TILE; tx++){ + difference.tiles++; + if (tile_difference(a, b, tx, ty) > TILE_CHANGE){ + difference.changed++; + } + } + } + return difference; +} + +bool same_start_place(const StartFrameDifference& difference){ + return difference.tiles > 0 && difference.changed * 100 <= difference.tiles * MOST_CHANGED_PERCENT; +} + +std::string to_string(const StartFrameDifference& difference){ + return std::format("{} of {} tiles changed", difference.changed, difference.tiles); +} + + +StartRead read_start_frames(const std::optional& reference, const StartFrameSource& next_frame, size_t tries){ + if (!reference){ + return {StartFound::NOT_READ, "no start frame kept for this checkpoint"}; + } + std::string seen; + for (size_t attempt = 0; attempt < tries; attempt++){ + const ImageRGB32 frame = next_frame(); + if (!frame){ + return {StartFound::NOT_READ, "no video"}; + } + const StartFrameDifference difference = compare_start_frames(*reference, frame); + if (same_start_place(difference)){ + return {StartFound::AT_START, "the start frame matches: " + to_string(difference)}; + } + seen += (seen.empty() ? "" : ", ") + to_string(difference); + } + return {StartFound::ELSEWHERE, "the screen isn't the checkpoint's start frame: " + seen}; +} + + +StartFrameStore::StartFrameStore(std::string folder) + : m_folder(std::move(folder)) +{} + +bool StartFrameStore::save(const std::string& checkpoint, const ImageViewRGB32& frame, const std::string& source) const{ + if (m_folder.empty()){ + return false; + } + Filesystem::create_directories(m_folder); + if (!frame.save(m_folder + checkpoint + ".png")){ + return false; + } + JsonObject json; + json["checkpoint"] = checkpoint; + json["kept"] = now_to_filestring(); + json["source"] = source; + JsonValue(std::move(json)).dump(m_folder + checkpoint + ".json"); + return true; +} + +std::optional StartFrameStore::load(const std::string& checkpoint) const{ + const std::string path = m_folder + checkpoint + ".png"; + if (m_folder.empty() || !Filesystem::exists(path)){ + return std::nullopt; + } + ImageRGB32 frame(path); + if (!frame){ + return std::nullopt; + } + return frame; +} + +StartFrameStore program_start_frames(){ + return StartFrameStore(USER_FILE_PATH() + "PokemonFRLG/AutoStoryStartFrames/"); +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h new file mode 100644 index 0000000000..9712a1bce0 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h @@ -0,0 +1,110 @@ +/* AutoStory Start Frames + * + * From: https://github.com/PokemonAutomation/ + * + * The console's start check, with no reader for the map or the tile: a + * frame of the game where each checkpoint starts, kept when the program + * saves there, and the frame after that save is loaded compared with it. + * FRLG's camera follows the player on whole tiles, so the same pose shows + * the same tiles, up to people walking about and animated tiles (water, + * flowers); another place, even a step away, shows other tiles. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryStartFrames_H +#define PokemonAutomation_PokemonFRLG_AutoStoryStartFrames_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The game screen as the start check keeps and compares it: the GBA's own +// 240x160 pixels, 15x10 tiles of 16. `game_screen` is the game's part of +// the frame (GameSettings' GAME_BOX). +ImageRGB32 start_frame(const ImageViewRGB32& game_screen); + +// How a frame differs from a checkpoint start's frame, tile by tile. +struct StartFrameDifference{ + size_t tiles = 0; + // The tiles whose pixels differ by more than an animated tile's do. + size_t changed = 0; +}; + +// The two frames, each scaled as start_frame() does, tile by tile. +StartFrameDifference compare_start_frames(const ImageViewRGB32& reference, const ImageViewRGB32& frame); + +// Whether the difference leaves the same place: few enough tiles changed +// for people who moved, too many for another place (see the .cpp). +bool same_start_place(const StartFrameDifference& difference); + +// "12 of 150 tiles changed". +std::string to_string(const StartFrameDifference& difference); + + +// What a start reader found about the save just loaded. +enum class StartFound{ + // It can't tell: the check passes. + NOT_READ, + AT_START, + ELSEWHERE, +}; +// A start reader's answer, with the line the start check logs for it. +struct StartRead{ + StartFound found = StartFound::NOT_READ; + // For the log: why nothing was read, or what was seen. + std::string detail = {}; +}; + +// The game screen now, as start_frame() makes it; an empty image when +// there is no video. Called again for each frame tried. +using StartFrameSource = std::function; + +// The start check on frames: up to `tries` frames from `next_frame` +// against `reference`, the first one that shows the same place +// (same_start_place()) passing, so a fade or a passer-by in front of the +// camera on one frame doesn't fail the check. No reference, or no video, +// is NOT_READ. +StartRead read_start_frames(const std::optional& reference, const StartFrameSource& next_frame, size_t tries); + + +// Where the start frames are kept: for each checkpoint, .png, the +// frame, and .json, the checkpoint, when it was kept and why. +class StartFrameStore{ +public: + // Keeps nothing and finds nothing (the simulation). + StartFrameStore() = default; + // `folder` ends with "/". + explicit StartFrameStore(std::string folder); + + // Replaces the frame kept for `checkpoint`; `source` says why it is kept. + // Returns false if it couldn't be written. + bool save(const std::string& checkpoint, const ImageViewRGB32& frame, const std::string& source) const; + // The frame kept for `checkpoint`, if any. + std::optional load(const std::string& checkpoint) const; + +private: + std::string m_folder; +}; + +// The program's store: USER_FILE_PATH()/PokemonFRLG/AutoStoryStartFrames/. +StartFrameStore program_start_frames(); + + +// Registers the comparison's and the store's unit tests (synthetic frames). +void add_tests_AutoStoryStartFrames(UnitTestDatabase& database); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp new file mode 100644 index 0000000000..9e733adf26 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp @@ -0,0 +1,384 @@ +/* AutoStory Start Frames Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The start frame comparison on synthetic screens: a map of textured + * 16x16 tiles seen through the GBA's 15x10-tile camera, with people drawn + * on it, scaled up to the size the game takes in a 1080p capture and + * given a capture's noise. The thresholds were chosen on console B's + * captures (see PokemonFRLG_AutoStoryStartFrames.cpp); game captures + * aren't kept in the repo. + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "PokemonFRLG_AutoStoryStartFrames.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +constexpr size_t TILE = 16; +constexpr size_t VIEW_TILES_X = 15; +constexpr size_t VIEW_TILES_Y = 10; +// GAME_BOX in a 1920x1080 capture. +constexpr size_t CAPTURE_WIDTH = 1560; +constexpr size_t CAPTURE_HEIGHT = 1040; + +uint32_t next_random(uint32_t& state){ + state = state * 1664525u + 1013904223u; + return state >> 8; +} + +uint32_t rgb(uint32_t r, uint32_t g, uint32_t b){ + return 0xff000000 | (std::min(r, 255) << 16) | (std::min(g, 255) << 8) | std::min(b, 255); +} + +// A map's tiles: indoor floors and walls, or grass, paths and trees. +struct Tileset{ + std::vector colors; +}; +const Tileset INDOOR{{rgb(200, 184, 152), rgb(176, 160, 128), rgb(232, 224, 208), rgb(120, 112, 104), rgb(208, 96, 72), rgb(88, 136, 200)}}; +const Tileset OUTDOOR{{rgb(96, 192, 120), rgb(72, 160, 96), rgb(216, 200, 144), rgb(48, 112, 64), rgb(120, 168, 232), rgb(152, 136, 120)}}; + +// The tile `kind` of `tileset`: its colour, shaded in a pattern of its own. +uint32_t tile_pixel(const Tileset& tileset, size_t kind, size_t x, size_t y){ + const uint32_t base = tileset.colors[kind % tileset.colors.size()]; + const int shade = (int)((x * (3 + kind) + y * (5 + 2 * kind)) % 7) * 10 - 30; + const auto channel = [&](int shift){ + return (uint32_t)std::clamp((int)((base >> shift) & 0xff) + shade, 0, 255); + }; + return rgb(channel(16), channel(8), channel(0)); +} + +// A map of 40x30 tiles, the same for the same seed. +struct Map{ + const Tileset* tileset; + std::vector tiles; +}; +constexpr size_t MAP_WIDTH = 40; +constexpr size_t MAP_HEIGHT = 30; +Map make_map(const Tileset& tileset, uint32_t seed){ + Map map{&tileset, {}}; + for (size_t c = 0; c < MAP_WIDTH * MAP_HEIGHT; c++){ + map.tiles.push_back(next_random(seed) % tileset.colors.size()); + } + return map; +} + +// A person standing on view tile (`tx`, `ty`): 16x32, their head on the +// tile above. +struct Person{ + size_t tx; + size_t ty; +}; + +// What the camera at map tile (`cx`, `cy`) shows, with `people` on it, as +// the capture shows the game: scaled up, with noise. +ImageRGB32 screen(const Map& map, size_t cx, size_t cy, const std::vector& people, uint32_t noise_seed){ + ImageRGB32 view(VIEW_TILES_X * TILE, VIEW_TILES_Y * TILE); + for (size_t y = 0; y < view.height(); y++){ + for (size_t x = 0; x < view.width(); x++){ + const size_t kind = map.tiles[(cy + y / TILE) * MAP_WIDTH + cx + x / TILE]; + view.pixel(x, y) = tile_pixel(*map.tileset, kind, x % TILE, y % TILE); + } + } + for (const Person& person : people){ + for (size_t y = person.ty * TILE - TILE; y < person.ty * TILE + TILE; y++){ + for (size_t x = person.tx * TILE; x < person.tx * TILE + TILE; x++){ + const size_t row = y - (person.ty * TILE - TILE); + view.pixel(x, y) = row < 10 ? rgb(232, 64, 48) : row < 20 ? rgb(248, 208, 168) : rgb(48, 80, 176); + } + } + } + ImageRGB32 capture = view.scale_to(CAPTURE_WIDTH, CAPTURE_HEIGHT); + for (size_t y = 0; y < capture.height(); y++){ + for (size_t x = 0; x < capture.width(); x++){ + const uint32_t pixel = capture.pixel(x, y); + const int jitter = (int)(next_random(noise_seed) % 9) - 4; + const auto channel = [&](int shift){ + return (uint32_t)std::clamp((int)((pixel >> shift) & 0xff) + jitter, 0, 255); + }; + capture.pixel(x, y) = rgb(channel(16), channel(8), channel(0)); + } + } + return capture; +} + +const Map CENTER = make_map(INDOOR, 27); +const Map CITY = make_map(OUTDOOR, 10); +const Map ROUTE = make_map(OUTDOOR, 4); +// The player, in the middle of the view. +const Person PLAYER{7, 5}; + + +struct CompareInput{ + std::string name; + ImageRGB32 (*frame)(); +}; +struct CompareExpectation{ + bool same_place; +}; +struct CompareCase{ + CompareInput input; + CompareExpectation expectation; +}; + +// The reference: Cerulean Center's counter, the nurse behind it, a +// visitor by the door. +ImageRGB32 counter_reference(){ + return screen(CENTER, 10, 8, {PLAYER, {7, 3}, {11, 8}}, 1); +} + +class Test_StartFrameCompare : public UnitTest{ +public: + explicit Test_StartFrameCompare(CompareCase test_case) + : UnitTest("PokemonFRLG::AutoStoryStartFrames - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const StartFrameDifference difference = compare_start_frames(counter_reference(), m_case.input.frame()); + if (same_start_place(difference) != m_case.expectation.same_place){ + return std::format( + "expected {}, got {}", + m_case.expectation.same_place ? "the same place" : "another place", to_string(difference) + ); + } + return true; + } + +private: + CompareCase m_case; +}; + +const CompareCase COMPARE_CASES[] = { + { + .input = {"the same screen, another capture", []{ return screen(CENTER, 10, 8, {PLAYER, {7, 3}, {11, 8}}, 2); }}, + .expectation = {true}, + }, + { + .input = {"the visitor walked off", []{ return screen(CENTER, 10, 8, {PLAYER, {7, 3}}, 3); }}, + .expectation = {true}, + }, + { + .input = {"three people moved", []{ return screen(CENTER, 10, 8, {PLAYER, {8, 3}, {2, 7}, {12, 2}, {4, 8}}, 4); }}, + .expectation = {true}, + }, + { + .input = {"one step off the counter", []{ return screen(CENTER, 10, 9, {PLAYER, {7, 2}, {11, 7}}, 5); }}, + .expectation = {false}, + }, + { + .input = {"outside the Center's door", []{ return screen(CITY, 12, 6, {PLAYER}, 6); }}, + .expectation = {false}, + }, + { + .input = {"another map", []{ return screen(ROUTE, 3, 14, {PLAYER, {3, 6}}, 7); }}, + .expectation = {false}, + }, + { + .input = {"a black fade", []{ + ImageRGB32 black(CAPTURE_WIDTH, CAPTURE_HEIGHT); + black.fill(0xff000000); + return black; + }}, + .expectation = {false}, + }, +}; + + +// read_start_frames() on a run of frames. +struct ReadInput{ + std::string name; + bool has_reference; + // The screens, one per frame read; an empty one is no video. + std::vector frames; +}; +struct ReadExpectation{ + StartFound found; + size_t frames_read; +}; +struct ReadCase{ + ReadInput input; + ReadExpectation expectation; +}; + +ImageRGB32 no_video(){ + return ImageRGB32(); +} +ImageRGB32 black_fade(){ + ImageRGB32 black(CAPTURE_WIDTH, CAPTURE_HEIGHT); + black.fill(0xff000000); + return black; +} +ImageRGB32 at_counter(){ + return screen(CENTER, 10, 8, {PLAYER, {7, 3}}, 8); +} +ImageRGB32 outside_door(){ + return screen(CITY, 12, 6, {PLAYER}, 9); +} + +std::string to_string(StartFound found){ + switch (found){ + case StartFound::NOT_READ: + return "NOT_READ"; + case StartFound::AT_START: + return "AT_START"; + case StartFound::ELSEWHERE: + return "ELSEWHERE"; + } + return "?"; +} + +class Test_StartFrameRead : public UnitTest{ +public: + explicit Test_StartFrameRead(ReadCase test_case) + : UnitTest("PokemonFRLG::AutoStoryStartFrames - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + std::optional reference; + if (m_case.input.has_reference){ + reference = start_frame(counter_reference()); + } + size_t read = 0; + const StartRead got = read_start_frames(reference, [&]{ + return m_case.input.frames[std::min(read++, m_case.input.frames.size() - 1)](); + }, 3); + if (got.found != m_case.expectation.found || read != m_case.expectation.frames_read){ + return std::format( + "expected {} after {} frames, got {} after {}: {}", + to_string(m_case.expectation.found), m_case.expectation.frames_read, to_string(got.found), read, got.detail + ); + } + return true; + } + +private: + ReadCase m_case; +}; + +const ReadCase READ_CASES[] = { + { + .input = {"no frame kept: not read", false, {at_counter}}, + .expectation = {StartFound::NOT_READ, 0}, + }, + { + .input = {"no video: not read", true, {no_video}}, + .expectation = {StartFound::NOT_READ, 1}, + }, + { + .input = {"the counter: at the start", true, {at_counter}}, + .expectation = {StartFound::AT_START, 1}, + }, + { + .input = {"a fade, then the counter: at the start", true, {black_fade, at_counter}}, + .expectation = {StartFound::AT_START, 2}, + }, + { + .input = {"outside the door three times: elsewhere", true, {outside_door}}, + .expectation = {StartFound::ELSEWHERE, 3}, + }, +}; + + +// The store, given two frames for 00.28 (outside the door, then the +// counter): what it finds for 00.28 and 00.27. +struct StoreInput{ + std::string name; + // A folder to keep them in; none for the simulation's store. + bool has_folder; +}; +struct StoreExpectation{ + // 00.28's frame is found, and is the last one kept (the counter). + bool finds_last; +}; +struct StoreCase{ + StoreInput input; + StoreExpectation expectation; +}; + +class Test_StartFrameStore : public UnitTest{ +public: + explicit Test_StartFrameStore(StoreCase test_case) + : UnitTest("PokemonFRLG::AutoStoryStartFrames - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + if (!m_case.input.has_folder){ + return check(StartFrameStore()); + } + const std::string folder = Filesystem::unique_temp_path(USER_FILE_PATH() + "AutoStoryStartFrames").string() + "/"; + const UnitTestResult result = check(StartFrameStore(folder)); + Filesystem::remove_all(folder); + return result; + } + +private: + UnitTestResult check(const StartFrameStore& store) const{ + if (store.load("00.28")){ + return "expected no frame before one is kept"; + } + const bool kept = store.save("00.28", start_frame(outside_door()), "test") + && store.save("00.28", start_frame(at_counter()), "test"); + const std::optional found = store.load("00.28"); + const bool finds_last = kept && found && found->width() == 240 && found->height() == 160 + && same_start_place(compare_start_frames(*found, at_counter())); + if (finds_last != m_case.expectation.finds_last || store.load("00.27")){ + return std::format( + "expected 00.28's last frame {}found and none for 00.27; kept: {}, found: {}", + m_case.expectation.finds_last ? "" : "not ", kept, found.has_value() + ); + } + return true; + } + + StoreCase m_case; +}; + +const StoreCase STORE_CASES[] = { + { + .input = {"the store keeps the last frame per checkpoint", true}, + .expectation = {true}, + }, + { + .input = {"a store with no folder keeps nothing", false}, + .expectation = {false}, + }, +}; + +} // namespace + + +void add_tests_AutoStoryStartFrames(UnitTestDatabase& database){ + for (const auto& item : COMPARE_CASES){ + database.add(item); + } + for (const auto& item : READ_CASES){ + database.add(item); + } + for (const auto& item : STORE_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 6efab6c8fe..bd7c263543 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1889,6 +1889,9 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp From b085825a0822f4c24d525e140943a266f64da4a8 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 03:29:46 -0800 Subject: [PATCH 12/29] FRLG AutoStory: set up the start frames with the story's state Keeps AutoStory's constructor and program() inside the function length limit on the stages above: the option's text is a constant, the story's state is made by story_env(), and the start frame tests register with the simulation's. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 -- .../AutoStory/PokemonFRLG_AutoStory.cpp | 32 ++++++++++++------- .../AutoStory/PokemonFRLG_AutoStory.h | 1 + .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 5 --- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 6 ---- .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 1 + 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index ac4f4e3003..cea4ff7bc9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -9,7 +9,6 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/StaticGlobals.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.h" -#include "Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h" #include "Inference/Box/PokemonFRLG_BoxCellOccupiedDetector.h" #include "Inference/Box/PokemonFRLG_BoxCellReader.h" #include "Inference/Box/PokemonFRLG_BoxGenderReader.h" @@ -324,7 +323,6 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStorySimulation(database); add_tests_AutoStoryItems(database); add_tests_AutoStoryScreenEvents(database); - add_tests_AutoStoryStartFrames(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 2ef8568881..6dab6ec05e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -50,6 +50,11 @@ const StringSelectDatabase& checkpoint_database(){ return database; } +const char* const KEEP_START_FRAME_TEXT = + "Keep the start frame:
Off by default. The save loaded was made by hand where the start checkpoint " + "begins: keep the screen after loading it as that checkpoint's start frame, which later runs compare their " + "save with. The program keeps one by itself at each save it makes."; + } // namespace AutoStory::AutoStory() @@ -60,13 +65,7 @@ AutoStory::AutoStory() LockMode::LOCK_WHILE_RUNNING, true ) - , KEEP_START_FRAME( - "Keep the start frame:
Off by default. The save loaded was made by hand where the start checkpoint " - "begins: keep the screen after loading it as that checkpoint's start frame, which later runs compare their " - "save with. The program keeps one by itself at each save it makes.", - LockMode::LOCK_WHILE_RUNNING, - false - ) + , KEEP_START_FRAME(KEEP_START_FRAME_TEXT, LockMode::LOCK_WHILE_RUNNING, false) , NOTIFICATIONS({ &NOTIFICATION_PROGRAM_FINISH, &NOTIFICATION_ERROR_FATAL, @@ -97,6 +96,19 @@ static void check_start_save( namespace{ +// The story's state for a run from `checkpoint`: its supplies, the checks +// level, and the program's start frames, the first start check keeping +// the screen as its frame if `keep_start_frame` (a save made by hand). +StoryEnv story_env( + SingleSwitchProgramEnvironment& env, ProControllerContext& context, + const StoryCheckpoint& checkpoint, StoryChecks checks, bool keep_start_frame +){ + StoryEnv story{env.console, context, checkpoint.supplies, checkpoint.supplies, false, checks}; + story.start_frames = program_start_frames(); + story.keep_start_frame = keep_start_frame; + return story; +} + // A failed attempt reloads the last save, with the supplies it had, read // from its bag again; the engine's lines go to the console's log. Pokemon::SegmentHooks story_hooks(SingleSwitchProgramEnvironment& env, StoryEnv& story){ @@ -161,8 +173,7 @@ void verify_story_checkpoint( ){ const std::vector& checkpoints = story_checkpoints(); const StoryCheckpoint& checkpoint = checkpoints[run.start_index()]; - StoryEnv story{env.console, context, checkpoint.supplies, checkpoint.supplies, false, run.checks()}; - use_start_frames(story, false); + StoryEnv story = story_env(env, context, checkpoint, run.checks(), false); load_verify_save(env, context, story, checkpoint); StoryExecutor executor(story); executor.set_checks(run.checks()); @@ -200,8 +211,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex throw UserSetupError(env.console, "Checkpoint 00.01 starts a new game: start on the title screen with no save."); } - StoryEnv story{env.console, context, checkpoints[first].supplies, checkpoints[first].supplies, false, RUN.checks()}; - use_start_frames(story, KEEP_START_FRAME); + StoryEnv story = story_env(env, context, checkpoints[first], RUN.checks(), KEEP_START_FRAME); if (!(first == 0 && NEW_GAME_FROM_TITLE)){ env.console.log("Loading the save for " + checkpoints[first].id + "."); soft_reset(env.console, context); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h index 2ded1ec039..285a2c16b8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h @@ -47,6 +47,7 @@ class AutoStory : public SingleSwitchProgramInstance{ // every game's AutoStory. Pokemon::StoryRunOptions RUN; BooleanCheckBoxOption NEW_GAME_FROM_TITLE; + // The save loaded was made by hand: keep the screen as its start frame. BooleanCheckBoxOption KEEP_START_FRAME; EventNotificationsOption NOTIFICATIONS; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 5aaca54cda..c1828b83d8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -623,11 +623,6 @@ void keep_next_start_frame(StoryEnv& env, const std::string& ended){ } // namespace -void use_start_frames(StoryEnv& env, bool keep_first){ - env.start_frames = program_start_frames(); - env.keep_start_frame = keep_first; -} - Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& executor){ executor.set_menu(data.menu); StoryEnv& env = executor.env(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index d7a4d0905b..5000e40322 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -169,12 +169,6 @@ struct StoryEnv{ bool keep_start_frame = false; }; -// The console's start check compares with the program's start frames -// (program_start_frames()); `keep_first`: the first start check keeps the -// screen as its checkpoint's frame instead (the option for a save made by -// hand). -void use_start_frames(StoryEnv& env, bool keep_first); - // After a save is loaded for a checkpoint that starts on `start_map`: the // save card's place, read from the START menu, against it, at every checks // level. Empty if the save is there (or the card can't be read), else why diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index 2c3a036cb9..fa45083f3f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -523,6 +523,7 @@ const AutoStorySimulationTestCase AUTO_STORY_SIMULATION_CASES[] = { void add_tests_AutoStorySimulation(UnitTestDatabase& database){ add_tests_AutoStoryStepTable(database); + add_tests_AutoStoryStartFrames(database); for (const auto& scenario : AUTO_STORY_SIMULATION_CASES){ database.add(scenario); } From a9dfe154fb8caa9bf95a31d023e256f0a596d833 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 03:33:42 -0800 Subject: [PATCH 13/29] FRLG AutoStory: test the start check on frames on its own checkpoint The frame start check's run tests move from the story simulation to the start frames' tests, as a checkpoint of one walk with the check build_checkpoint() adds: a save outside the door stops before the walk, one at the counter or with no frame kept walks. The simulation's file stays under its length limit on the stages above. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 84 +--------------- ...PokemonFRLG_AutoStoryStartFrames_Tests.cpp | 96 +++++++++++++++++++ 2 files changed, 97 insertions(+), 83 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index fa45083f3f..6148a1211b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -21,7 +21,6 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" -#include "CommonFramework/ImageTypes/ImageRGB32.h" #include "Pokemon/AutoStory/Pokemon_StorySegments.h" #include "Pokemon/AutoStory/Pokemon_StorySteps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" @@ -232,9 +231,6 @@ struct Simulation{ // Where each save stood: the end of its checkpoint. std::vector> saves; Pokemon::SegmentPolicy policy; - // The start check's reader, as the console's: unset, the fake game's - // save pose is read. - StartReader start_reader; // A language no reader supports, so a step that needed text would show. Pokemon::SegmentReport run(const Pokemon::SegmentRange& range){ @@ -246,7 +242,7 @@ struct Simulation{ .id = data.id, .title = data.title, .saves = true, .build = [this, &data]{ Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, game); - add_start(checkpoint, data); + add_start_pose_check(checkpoint, data.start, [this]{ return game.save_stands; }, [this](const std::string& line){ lines.push_back(line); }); return checkpoint; }, }); @@ -265,14 +261,6 @@ struct Simulation{ RunState state; return Pokemon::run_segment(state, segment, range, policy, hooks); } - void add_start(Pokemon::Checkpoint& checkpoint, const StoryCheckpoint& data){ - StoryLog log = [this](const std::string& line){ lines.push_back(line); }; - if (start_reader){ - add_start_check(checkpoint, data.start, start_reader, std::move(log)); - }else{ - add_start_pose_check(checkpoint, data.start, [this]{ return game.save_stands; }, std::move(log)); - } - } std::string last_begun() const{ for (auto it = game.trace.rbegin(); it != game.trace.rend(); ++it){ if (it->starts_with("begin ")){ @@ -412,68 +400,6 @@ UnitTestResult test_save_off_start_pose(){ return true; } -// A screen of 15x10 flat tiles coloured from `seed`, as start_frame() -// keeps it; `visitor` stands a person on tile (3, 3). -ImageRGB32 tiled_screen(uint32_t seed, bool visitor){ - ImageRGB32 screen(240, 160); - for (size_t ty = 0; ty < 10; ty++){ - for (size_t tx = 0; tx < 15; tx++){ - seed = seed * 1664525u + 1013904223u; - const bool person = visitor && tx == 3 && (ty == 2 || ty == 3); - const uint32_t color = person ? 0xffe84030 : (0xff000000 | (seed >> 8)); - for (size_t y = ty * 16; y < ty * 16 + 16; y++){ - for (size_t x = tx * 16; x < tx * 16 + 16; x++){ - screen.pixel(x, y) = color; - } - } - } - } - return screen; -} - -// 00.09 with the console's start check on frames: the frame kept for its -// start (tiled_screen(1), if `kept`) against `screen` after the save loads. -Pokemon::SegmentReport run_with_start_frame(Simulation& sim, bool kept, StartFrameSource screen){ - sim.start_reader = [kept, screen = std::move(screen)]{ - std::optional reference; - if (kept){ - reference = tiled_screen(1, false); - } - return read_start_frames(reference, screen, 3); - }; - return sim.run({.from = "00.09", .to = "00.09"}); -} - -// console B, FRLG 00.27, 2026-11-09, with no tile reader: the screen -// after the save loads isn't the frame kept where 00.09 starts, so it -// stops before any step or save. -UnitTestResult test_start_frame_elsewhere(){ - Simulation sim; - const Pokemon::SegmentReport report = run_with_start_frame(sim, true, []{ return tiled_screen(2, false); }); - const auto stepped = [](const std::string& item){ return item.starts_with("00.09/"); }; - const auto told = [](const std::string& line){ return line.starts_with("start pose mismatch: "); }; - if (report.completed || report.failure.failure != "start_failed" || !sim.saves.empty() - || std::ranges::any_of(sim.game.trace, stepped) || std::ranges::none_of(sim.lines, told) - ){ - return "Expected 00.09 stopped at its start check, the mismatch logged:" + joined(sim.game.trace) + joined(sim.lines); - } - return true; -} - -// The kept frame with a visitor in it, and none kept: both go on. -UnitTestResult test_start_frame_passes(){ - for (const bool kept : {true, false}){ - Simulation sim; - const Pokemon::SegmentReport report = run_with_start_frame(sim, kept, []{ return tiled_screen(1, true); }); - const std::string expected = kept ? "start pose matches: " : "start pose not read: no start frame kept"; - const auto told = [&](const std::string& line){ return line.starts_with(expected); }; - if (!report.completed || std::ranges::none_of(sim.lines, told)){ - return "Expected 00.09 run, \"" + expected + "\" logged:" + joined(sim.lines); - } - } - return true; -} - // Brock's battle lost every time: three attempts, then the stop. UnitTestResult test_gives_up_after_attempts(){ Simulation sim; @@ -508,14 +434,6 @@ const AutoStorySimulationTestCase AUTO_STORY_SIMULATION_CASES[] = { .input = {.name = "a save off the start pose stops before any step", .body = test_save_off_start_pose}, .expectation = {.description = "fails the start check without walking or saving"}, }, - { - .input = {.name = "a screen off the start frame stops before any step", .body = test_start_frame_elsewhere}, - .expectation = {.description = "fails the start check on frames without walking or saving"}, - }, - { - .input = {.name = "the start frame with a visitor, or none kept, goes on", .body = test_start_frame_passes}, - .expectation = {.description = "passes the start check on frames when the place matches or nothing is kept"}, - }, }; } // namespace diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp index 9e733adf26..f6a9cfb692 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp @@ -21,6 +21,8 @@ #include "Common/Cpp/TestRunners/UnitTest.h" #include "CommonFramework/GlobalAutoPaths.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "Pokemon/AutoStory/Pokemon_StoryEvents.h" +#include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStoryStartFrames.h" namespace PokemonAutomation{ @@ -296,6 +298,97 @@ const ReadCase READ_CASES[] = { }; +// console B, FRLG 00.27, 2026-11-09: the save stood outside Cerulean +// Center's door, not at the counter where 00.27 starts, and the run walked +// off. A checkpoint of one walk with the console's start check on frames +// (add_start_check(), as build_checkpoint() adds it): the walk runs only +// when the screen after the save loads shows the kept frame's place, or +// when no frame is kept. +struct StartCheckInput{ + std::string name; + bool has_reference; + ImageRGB32 (*screen)(); +}; +struct StartCheckExpectation{ + bool walked; + // The start check's log line starts with this. + std::string logged; +}; +struct StartCheckCase{ + StartCheckInput input; + StartCheckExpectation expectation; +}; + +class Test_StartFrameCheck : public UnitTest{ +public: + explicit Test_StartFrameCheck(StartCheckCase test_case) + : UnitTest("PokemonFRLG::AutoStoryStartFrames - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + size_t walks = 0; + std::vector lines; + Pokemon::Checkpoint checkpoint = one_walk(walks); + add_start_check( + checkpoint, to_pose(StoryPose{"CeruleanCity_PokemonCenter_1F", TilePos{7, 4}, Direction::NORTH}), + [this]{ return read_start_frames(reference(), m_case.input.screen, 3); }, + [&lines](const std::string& line){ lines.push_back(line); } + ); + Pokemon::RunState state; + Pokemon::EventLogger log = [](const std::string&){}; + const Pokemon::CheckpointReport report = Pokemon::run_checkpoint(state, checkpoint, log); + const bool stopped = !report.completed && report.failure.failure == "start_failed"; + const bool logged = lines.size() == 1 && lines[0].starts_with(m_case.expectation.logged); + if ((m_case.expectation.walked ? !report.completed || walks != 1 : !stopped || walks != 0) || !logged){ + return std::format( + "expected {}, \"{}\" logged; got {} walk(s), {}: {}", + m_case.expectation.walked ? "the walk" : "a stop before it", m_case.expectation.logged, + walks, Pokemon::to_string(report.failure), lines.empty() ? "nothing logged" : lines[0] + ); + } + return true; + } + +private: + static Pokemon::Checkpoint one_walk(size_t& walks){ + Pokemon::Checkpoint checkpoint; + checkpoint.id = "00.27"; + Pokemon::Event walk; + walk.name = "to_the_door"; + walk.act = [&walks](Pokemon::RunState&){ + walks++; + return Pokemon::outcome_ok(); + }; + checkpoint.events.push_back(std::move(walk)); + return checkpoint; + } + std::optional reference() const{ + if (!m_case.input.has_reference){ + return std::nullopt; + } + return start_frame(counter_reference()); + } + + StartCheckCase m_case; +}; + +const StartCheckCase START_CHECK_CASES[] = { + { + .input = {"a save outside the door stops before any step", true, outside_door}, + .expectation = {false, "start pose mismatch: "}, + }, + { + .input = {"a save at the counter walks", true, at_counter}, + .expectation = {true, "start pose matches: "}, + }, + { + .input = {"no frame kept walks, as before", false, outside_door}, + .expectation = {true, "start pose not read: no start frame kept"}, + }, +}; + + // The store, given two frames for 00.28 (outside the door, then the // counter): what it finds for 00.28 and 00.27. struct StoreInput{ @@ -372,6 +465,9 @@ void add_tests_AutoStoryStartFrames(UnitTestDatabase& database){ for (const auto& item : READ_CASES){ database.add(item); } + for (const auto& item : START_CHECK_CASES){ + database.add(item); + } for (const auto& item : STORE_CASES){ database.add(item); } From a8cc3e71001353d30269668e57a387467db0a35e Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 03:36:48 -0800 Subject: [PATCH 14/29] FRLG AutoStory: keep the start check with the start frames The start check (add_start_check()) and the console's frame reads move from AutoStoryEvents.cpp to AutoStoryStartFrames.cpp, which keeps the events file inside its length limit on the stages above. Nothing else changes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 74 ++---------------- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 20 ++--- .../PokemonFRLG_AutoStoryStartFrames.cpp | 77 +++++++++++++++++++ .../PokemonFRLG_AutoStoryStartFrames.h | 47 +++++++++++ 4 files changed, 136 insertions(+), 82 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index c1828b83d8..5a2eef7558 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -9,8 +9,6 @@ #include #include "Common/Cpp/Exceptions.h" #include "CommonFramework/Exceptions/OperationFailedException.h" -#include "CommonFramework/ImageTools/ImageBoxes.h" -#include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "Pokemon/Navigation/Pokemon_RouteLog.h" @@ -18,7 +16,6 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" -#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStorySummary.h" @@ -351,34 +348,6 @@ std::string start_pose_mismatch(const Pokemon::Pose& start, const StoryPose& sta + ", but the checkpoint starts at " + Pokemon::to_string(start) + "."; } -void add_start_check( - Pokemon::Checkpoint& checkpoint, const std::optional& start, StartReader read, StoryLog log -){ - if (!start){ - return; - } - checkpoint.start.push_back(Pokemon::condition("save_at_start_pose", - [read = std::move(read), log = std::move(log)](RunState&){ - const StartRead found = read(); - switch (found.found){ - case StartFound::NOT_READ: - log("start pose not read: " + (found.detail.empty() ? "" : found.detail + "; ") - + "going on from the save as the checkpoint's start."); - return true; - case StartFound::AT_START: - if (!found.detail.empty()){ - log("start pose matches: " + found.detail); - } - return true; - case StartFound::ELSEWHERE: - log("start pose mismatch: " + found.detail); - return false; - } - return false; - } - )); -} - void add_start_pose_check( Pokemon::Checkpoint& checkpoint, const std::optional& start, SavePoseReader read, StoryLog log ){ @@ -570,39 +539,14 @@ void read_bag_supplies(StoryEnv& env, StartMenu menu){ namespace{ -// Frames the start check tries (read_start_frames()), a second apart. -constexpr size_t START_FRAME_TRIES = 3; -constexpr Milliseconds START_FRAME_WAIT = 1000ms; - -// The game screen now, as the start frames keep it; empty with no video. -ImageRGB32 console_start_frame(StoryEnv& env){ - env.context.wait_for_all_requests(); - const VideoSnapshot snapshot = env.console.video().snapshot(); - if (!snapshot){ - return ImageRGB32(); - } - return start_frame(extract_box_reference(snapshot, GameSettings::instance().GAME_BOX)); -} - -// The console's start check for `checkpoint`: the screen against the -// start frame kept for it. With keep_start_frame (a save made by hand), -// the screen is kept as that frame instead, and passes. +// The console's start check for `checkpoint`; with keep_start_frame (a +// save made by hand), the screen is kept as its frame instead. StartRead read_console_start(StoryEnv& env, const std::string& checkpoint){ if (env.keep_start_frame){ env.keep_start_frame = false; - const ImageRGB32 frame = console_start_frame(env); - if (!frame || !env.start_frames.save(checkpoint, frame, "kept by the program's option from the save loaded")){ - return {StartFound::NOT_READ, "couldn't keep the screen as " + checkpoint + "'s start frame"}; - } - return {StartFound::AT_START, "kept the screen as " + checkpoint + "'s start frame"}; + return keep_console_start(env.console, env.context, env.start_frames, checkpoint); } - size_t frames = 0; - return read_start_frames(env.start_frames.load(checkpoint), [&env, &frames]{ - if (frames++ > 0){ - env.context.wait_for(START_FRAME_WAIT); - } - return console_start_frame(env); - }, START_FRAME_TRIES); + return check_console_start(env.console, env.context, env.start_frames, checkpoint); } // After the save at the end of `ended`: the screen, kept as the start @@ -610,14 +554,10 @@ StartRead read_console_start(StoryEnv& env, const std::string& checkpoint){ void keep_next_start_frame(StoryEnv& env, const std::string& ended){ const std::vector& table = story_checkpoints(); for (size_t c = 0; c + 1 < table.size(); c++){ - if (table[c].id != ended || !table[c + 1].start){ - continue; + if (table[c].id == ended && table[c + 1].start){ + keep_console_frame(env.console, env.context, env.start_frames, table[c + 1].id, "saved at the end of " + ended); + return; } - const ImageRGB32 frame = console_start_frame(env); - if (frame){ - env.start_frames.save(table[c + 1].id, frame, "saved at the end of " + ended); - } - return; } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 5000e40322..53825f5098 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -105,22 +105,12 @@ using SavePoseReader = std::function()>; // Where the start check says what it found. using StoryLog = std::function; -// Where the save just loaded is, against the start of the checkpoint it -// starts: the console's reads it from frames (PokemonFRLG_AutoStoryStartFrames.h). -using StartReader = std::function; - // Adds to `checkpoint`, built from a row that starts at `start`, the start -// check: the save it starts from, as `read` finds it, must be there, or -// the checkpoint stops before its first event, "start_failed". A save -// `read` can't tell about passes. `log` gets a mismatch ("start pose -// mismatch: "), that nothing was read ("start pose not read: "), or what -// a match saw. A row with no start (a new game) gets none. -void add_start_check( - Pokemon::Checkpoint& checkpoint, const std::optional& start, StartReader read, StoryLog log -); - -// add_start_check() with a reader of the tile the save stands on, which -// must be the start's (start_pose_mismatch()). +// check: the save it starts from, as `read` reads it, must stand there +// (start_pose_mismatch()), or the checkpoint stops before its first event, +// "start_failed". A save that can't be read passes. `log` gets a +// mismatch, or that nothing was read. A row with no start (a new game) +// gets none. (add_start_check() with a reader of the tile.) void add_start_pose_check( Pokemon::Checkpoint& checkpoint, const std::optional& start, SavePoseReader read, StoryLog log ); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp index 62c1daeb40..22658b98fb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp @@ -11,6 +11,9 @@ #include "Common/Cpp/Json/JsonObject.h" #include "Common/Cpp/Json/JsonValue.h" #include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_AutoStoryStartFrames.h" namespace PokemonAutomation{ @@ -49,6 +52,11 @@ constexpr unsigned TILE_CHANGE = 24; // The same place when at most a quarter of the tiles changed. constexpr size_t MOST_CHANGED_PERCENT = 25; +// Frames the console's start check tries, a second apart: a fade or a +// passer-by in front of the camera on one frame doesn't fail it. +constexpr size_t START_FRAME_TRIES = 3; +constexpr Milliseconds START_FRAME_WAIT = std::chrono::milliseconds(1000); + // The block at (`bx`, `by`): its channels' totals in `a` less those in // `b`, summed as absolute values. uint64_t block_difference(const ImageViewRGB32& a, const ImageViewRGB32& b, size_t bx, size_t by){ @@ -164,6 +172,75 @@ StartFrameStore program_start_frames(){ } +ImageRGB32 console_start_frame(ConsoleHandle& console, ProControllerContext& context){ + context.wait_for_all_requests(); + const VideoSnapshot snapshot = console.video().snapshot(); + if (!snapshot){ + return ImageRGB32(); + } + return start_frame(extract_box_reference(snapshot, GameSettings::instance().GAME_BOX)); +} + +StartRead check_console_start( + ConsoleHandle& console, ProControllerContext& context, const StartFrameStore& store, const std::string& checkpoint +){ + size_t frames = 0; + return read_start_frames(store.load(checkpoint), [&]{ + if (frames++ > 0){ + context.wait_for(START_FRAME_WAIT); + } + return console_start_frame(console, context); + }, START_FRAME_TRIES); +} + +bool keep_console_frame( + ConsoleHandle& console, ProControllerContext& context, const StartFrameStore& store, + const std::string& checkpoint, const std::string& source +){ + const ImageRGB32 frame = console_start_frame(console, context); + return frame && store.save(checkpoint, frame, source); +} + +StartRead keep_console_start( + ConsoleHandle& console, ProControllerContext& context, const StartFrameStore& store, const std::string& checkpoint +){ + if (!keep_console_frame(console, context, store, checkpoint, "kept by the program's option from the save loaded")){ + return {StartFound::NOT_READ, "couldn't keep the screen as " + checkpoint + "'s start frame"}; + } + return {StartFound::AT_START, "kept the screen as " + checkpoint + "'s start frame"}; +} + + +void add_start_check( + Pokemon::Checkpoint& checkpoint, const std::optional& start, StartReader read, + std::function log +){ + if (!start){ + return; + } + checkpoint.start.push_back(Pokemon::condition("save_at_start_pose", + [read = std::move(read), log = std::move(log)](Pokemon::RunState&){ + const StartRead found = read(); + switch (found.found){ + case StartFound::NOT_READ: + log("start pose not read: " + (found.detail.empty() ? "" : found.detail + "; ") + + "going on from the save as the checkpoint's start."); + return true; + case StartFound::AT_START: + if (!found.detail.empty()){ + log("start pose matches: " + found.detail); + } + return true; + case StartFound::ELSEWHERE: + log("start pose mismatch: " + found.detail); + return false; + } + return false; + } + )); +} + + } // namespace PokemonFRLG } // namespace NintendoSwitch diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h index 9712a1bce0..9c2d4e25d2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h @@ -9,6 +9,9 @@ * the same tiles, up to people walking about and animated tiles (water, * flowers); another place, even a step away, shows other tiles. * + * Also the start check itself (add_start_check()), which takes its + * reader: frames on the console, the save's pose in the simulation. + * */ #ifndef PokemonAutomation_PokemonFRLG_AutoStoryStartFrames_H @@ -21,6 +24,9 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryEvents.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -99,6 +105,47 @@ class StartFrameStore{ StartFrameStore program_start_frames(); +// The game screen on the console now, as start_frame() makes it; empty +// with no video. +ImageRGB32 console_start_frame(ConsoleHandle& console, ProControllerContext& context); + +// The console's start check for `checkpoint`: the screen against the +// frame `store` keeps for it, up to 3 frames a second apart +// (read_start_frames()). +StartRead check_console_start( + ConsoleHandle& console, ProControllerContext& context, const StartFrameStore& store, const std::string& checkpoint +); + +// The screen kept as `checkpoint`'s start frame, `source` saying why. +// Returns false if there was no video or it couldn't be written. +bool keep_console_frame( + ConsoleHandle& console, ProControllerContext& context, const StartFrameStore& store, + const std::string& checkpoint, const std::string& source +); + +// The start check for a save made by hand: the screen is kept as +// `checkpoint`'s start frame, and the save is taken to be there. +StartRead keep_console_start( + ConsoleHandle& console, ProControllerContext& context, const StartFrameStore& store, const std::string& checkpoint +); + + +// Where the save just loaded is, against the start of the checkpoint it +// starts. +using StartReader = std::function; + +// Adds to `checkpoint`, built from a row that starts at `start`, the start +// check: the save it starts from, as `read` finds it, must be there, or +// the checkpoint stops before its first event, "start_failed". A save +// `read` can't tell about passes. `log` gets a mismatch ("start pose +// mismatch: "), that nothing was read ("start pose not read: "), or what +// a match saw. A row with no start (a new game) gets none. +void add_start_check( + Pokemon::Checkpoint& checkpoint, const std::optional& start, StartReader read, + std::function log +); + + // Registers the comparison's and the store's unit tests (synthetic frames). void add_tests_AutoStoryStartFrames(UnitTestDatabase& database); From bde6bacbc9254fd0c47f4018b900b796e8a7064f Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 04:36:14 -0800 Subject: [PATCH 15/29] FRLG AutoStory: clear interrupts between story steps on the console Binds the shared between-step interrupts (Pokemon_StoryInterrupts.h) for FRLG's console executor: it looks at the screen for 400 ms before each step and clears what it finds as the walker does part-way through a leg (a wild battle run from, a message read and a trainer's battle after it fought), or presses through a warp's scene and loses the pose. The steps that press through text start on a message; a BATTLE also on its battle already showing, GAME and NEW_GAME on anything. The look and the knobs are not measured on FRLG yet. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 29 ++- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 12 +- .../PokemonFRLG_AutoStoryStepInterrupts.cpp | 85 +++++++ .../PokemonFRLG_AutoStoryStepInterrupts.h | 104 ++++++++ ...emonFRLG_AutoStoryStepInterrupts_Tests.cpp | 229 ++++++++++++++++++ .../PokemonFRLG_AutoStoryStepTable_Tests.cpp | 2 + SerialPrograms/cmake/SourceFiles.cmake | 3 + 7 files changed, 461 insertions(+), 3 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 5a2eef7558..fa6a02aee9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -467,9 +467,14 @@ ConsoleAction console_action_of(StoryActionId id){ StoryExecutor::StoryExecutor(StoryEnv& env) : m_env(env) + , m_guard(env.console.logger()) , m_table(make_story_action_table([this](StoryActionId id){ return console_action(id); })) , m_executor(m_table, m_guard) -{} + , m_look(env.console, env.context) + , m_interrupts(step_interrupts([this](bool fresh){ return m_look.look(fresh); }, console_interrupt_actions())) +{ + m_executor.set_interrupts(&m_interrupts); +} Outcome StoryExecutor::run(RunState& state, const StoryStep& step){ return m_executor.run(state, step); @@ -489,6 +494,28 @@ Pokemon::StoryAction StoryExecutor::console_action(StoryActionId id){ return {.act = [this, action](RunState& state, const StoryStep& step){ return action(m_env, state, step); }, .needs_console = true}; } +// As the walker clears them part-way through a leg (story_interrupts()): +// a wild battle is run from; a message is read to its end, and a +// trainer's battle after it fought. A warp's scene is pressed through. +StepInterruptActions StoryExecutor::console_interrupt_actions(){ + const auto walker_clears = [this](bool wild){ + return [this, wild](RunState&, const Pokemon::InterruptVerdict&){ + const OverworldInterruptSet set = story_interrupts(m_env.supplies, false, m_env.checks, m_env.language); + (wild ? set.wild : set.other).front()->clear(m_env.console, m_env.context); + return Pokemon::outcome_ok(); + }; + }; + return StepInterruptActions{ + .wild = walker_clears(true), + .trainer = walker_clears(false), + .dialog = walker_clears(false), + .warp = [this](RunState&, const Pokemon::InterruptVerdict&){ + mash_until_overworld(m_env.console, m_env.context, SCENE_TIMEOUT); + return Pokemon::outcome_ok(); + }, + }; +} + std::string check_save_place(StoryEnv& env, const std::string& start_map){ if (save_card_place(start_map).empty()){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 53825f5098..433bfc2c4d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -36,6 +36,7 @@ #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattle.h" #include "PokemonFRLG_AutoStoryStartFrames.h" +#include "PokemonFRLG_AutoStoryStepInterrupts.h" #include "PokemonFRLG_AutoStoryStepTable.h" namespace PokemonAutomation{ @@ -180,6 +181,8 @@ void read_bag_supplies(StoryEnv& env, StartMenu menu); // Does FRLG's kinds of story step on the console, each with its row of // story_action_rows() (PokemonFRLG_AutoStoryStepTable.h). A console step // that fails is a failed Outcome, which the segment answers by reloading. +// Before each step it clears what came up since the step before +// (step_interrupts(), PokemonFRLG_AutoStoryStepInterrupts.h). class StoryExecutor : public Pokemon::StoryStepExecutor{ public: explicit StoryExecutor(StoryEnv& env); @@ -201,13 +204,18 @@ class StoryExecutor : public Pokemon::StoryStepExecutor{ private: // How the console does `id`. Pokemon::StoryAction console_action(StoryActionId id); + // How the console clears each kind of interrupt between steps. + StepInterruptActions console_interrupt_actions(); StoryEnv& m_env; StartMenu m_menu = StartMenu::FULL; - // FRLG does nothing around a step: a failed one fails the step. - Pokemon::StepGuard m_guard; + // A failed step fails the step; an interrupt between steps is logged. + InterruptLogGuard m_guard; Pokemon::StoryActionTable m_table; Pokemon::TableExecutor m_executor; + // What is cleared between steps, looked for on the screen. + ConsoleScreenLook m_look; + Pokemon::StoryInterrupts m_interrupts; }; // The checkpoint `data` as events, saving at its end. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp new file mode 100644 index 0000000000..d1019d2918 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp @@ -0,0 +1,85 @@ +/* AutoStory Step Interrupts + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Color.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "PokemonFRLG_AutoStoryStepInterrupts.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using Pokemon::InterruptKind; +using Pokemon::InterruptPose; +using Pokemon::StoryStepKind; + + +bool presses_through_text(StoryStepKind kind){ + switch (kind){ + case StoryStepKind::MASH: + case StoryStepKind::ANSWER: + case StoryStepKind::BATTLE: + case StoryStepKind::GAME: + case StoryStepKind::NEW_GAME: + return true; + default: + return false; + } +} + +Pokemon::StoryInterrupts step_interrupts(Pokemon::ScreenLookFunction look, const StepInterruptActions& actions){ + Pokemon::StoryInterrupts out; + out.look = std::move(look); + out.handlers.add(InterruptKind::WILD_ENCOUNTER, {.handle = actions.wild, .pose = InterruptPose::UNCHANGED}); + out.handlers.add(InterruptKind::TRAINER_SIGHT, {.handle = actions.trainer, .pose = InterruptPose::UNCHANGED}); + out.handlers.add(InterruptKind::DIALOG, {.handle = actions.dialog, .pose = InterruptPose::UNCHANGED}); + out.handlers.add(InterruptKind::WARP, {.handle = actions.warp, .pose = InterruptPose::LOST}); + for (StoryStepKind step : {StoryStepKind::MASH, StoryStepKind::ANSWER, StoryStepKind::BATTLE, StoryStepKind::GAME, StoryStepKind::NEW_GAME}){ + out.handlers.starts_on(step, InterruptKind::DIALOG); + } + out.handlers.starts_on(StoryStepKind::BATTLE, InterruptKind::TRAINER_SIGHT); + out.handlers.starts_on(StoryStepKind::BATTLE, InterruptKind::WILD_ENCOUNTER); + for (StoryStepKind step : {StoryStepKind::GAME, StoryStepKind::NEW_GAME}){ + for (InterruptKind kind : {InterruptKind::WILD_ENCOUNTER, InterruptKind::TRAINER_SIGHT, InterruptKind::WARP}){ + out.handlers.starts_on(step, kind); + } + } + return out; +} + + +ConsoleScreenLook::ConsoleScreenLook(VideoStream& stream, ProControllerContext& context) + : m_stream(stream) + , m_context(context) + , m_watcher(m_observer) + , m_start(current_time()) +{} + +Pokemon::ScreenLook ConsoleScreenLook::look(bool fresh){ + if (fresh){ + m_watcher.reset(); + m_start = current_time(); + } + wait_until(m_stream, m_context, BETWEEN_STEPS_LOOK, {m_watcher}); + return {.log = m_watcher.log(), .window = {.start = m_start, .end = current_time()}}; +} + + +void InterruptLogGuard::on_interrupt(const Pokemon::StoryStep& step, const Pokemon::InterruptCheck& check){ + const bool cleared = check.outcome.succeeded(); + m_logger.log(std::format( + "Story: {}: before it, {}: {}", step.name, + Pokemon::interrupt_kind_name(check.verdict.kind), cleared ? "cleared" : Pokemon::to_string(check.outcome) + ), cleared ? COLOR_ORANGE : COLOR_RED); +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h new file mode 100644 index 0000000000..547414413d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h @@ -0,0 +1,104 @@ +/* AutoStory Step Interrupts + * + * From: https://github.com/PokemonAutomation/ + * + * FRLG's interrupts between story steps (Pokemon_StoryInterrupts.h): a + * wild battle is run from, a trainer who saw the player is fought, a + * message is read to its end (and a trainer's battle after it fought), + * and a warp's fade is pressed through, the pose then lost. The console + * (ConsoleScreenLook and StoryExecutor's console actions) and the + * simulations bind the same table. + * + * The steps that press through text (MASH, ANSWER, BATTLE, GAME, + * NEW_GAME) start on a message: one showing before them is theirs. A + * BATTLE starts on its trainer's lines, and on its battle already + * showing, which reads as a wild one when the lines were missed. A GAME + * step (a measured script: a capture, the PC, a gift's summary) and + * NEW_GAME (the title screen) start on anything. FRLG's story has no + * TRAIN steps. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryStepInterrupts_H +#define PokemonAutomation_PokemonFRLG_AutoStoryStepInterrupts_H + +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/Time.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/Tools/VideoStream.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "Pokemon/AutoStory/Pokemon_ScreenEvents.h" +#include "Pokemon/AutoStory/Pokemon_StoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryInterrupts.h" +#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "PokemonFRLG_AutoStoryScreenEvents.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// What clears each kind of interrupt, as a binding does it. +struct StepInterruptActions{ + Pokemon::InterruptAction wild = {}; + Pokemon::InterruptAction trainer = {}; + Pokemon::InterruptAction dialog = {}; + Pokemon::InterruptAction warp = {}; +}; + +// FRLG's interrupts between steps: `look` judged with the shared knobs, +// `actions` for each kind, and the steps that start on one. The knobs +// are the shared defaults, BDSP's timings: FRLG's flash-to-battle and +// lines-to-battle times are not measured on the console yet. +Pokemon::StoryInterrupts step_interrupts(Pokemon::ScreenLookFunction look, const StepInterruptActions& actions); + +// Whether a step of `kind` presses through any text showing when it +// starts; a step of another kind is stopped by it (a walk, a talk). +bool presses_through_text(Pokemon::StoryStepKind kind); + + +// How long the console looks at the screen before a step: the walker's +// wait for a message box (its StoryMessage interrupt's detection delay). +// Not measured as a look between steps yet. +constexpr Milliseconds BETWEEN_STEPS_LOOK = Milliseconds(400); + +// The console's look between steps: FrlgScreenObserver's events for +// BETWEEN_STEPS_LOOK, everything showing in it judged. +class ConsoleScreenLook{ +public: + ConsoleScreenLook(VideoStream& stream, ProControllerContext& context); + + Pokemon::ScreenLook look(bool fresh); + +private: + VideoStream& m_stream; + ProControllerContext& m_context; + FrlgScreenObserver m_observer; + Pokemon::ScreenEventWatcher m_watcher; + WallClock m_start; +}; + +// The console's guard: a failed step fails it, as before; each interrupt +// found between steps is logged, cleared or not. +class InterruptLogGuard : public Pokemon::StepGuard{ +public: + explicit InterruptLogGuard(Logger& logger) + : m_logger(logger) + {} + + virtual void on_interrupt(const Pokemon::StoryStep& step, const Pokemon::InterruptCheck& check) override; + +private: + Logger& m_logger; +}; + + +// The binding's table against a scripted screen. +void add_tests_AutoStoryStepInterrupts(UnitTestDatabase& database); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp new file mode 100644 index 0000000000..29b8b0693f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp @@ -0,0 +1,229 @@ +/* AutoStory Step Interrupts Tests + * + * From: https://github.com/PokemonAutomation/ + * + * FRLG's table of interrupts between steps (step_interrupts()) on the + * shared executor, against a scripted screen: what each kind of step is + * stopped by and what it starts on. + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_ScreenEvents.h" +#include "Pokemon/AutoStory/Pokemon_StoryActions.h" +#include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStoryStepTable.h" +#include "PokemonFRLG_AutoStoryStepInterrupts.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +using Pokemon::ScreenEvent; +using Pokemon::ScreenEvents; +using Pokemon::StoryStepKind; + +const WallClock T0 = WallClock() + std::chrono::hours(1); + +// What FrlgScreenObserver reports of each screen (no PLAYER_CAN_MOVE). +const ScreenEvents OVERWORLD{}; +const ScreenEvents BOX{ScreenEvent::DIALOG_BOX}; +const ScreenEvents WHITE{ScreenEvent::FADE_WHITE}; +const ScreenEvents BLACK{ScreenEvent::FADE_BLACK}; +const ScreenEvents BATTLE{ScreenEvent::BATTLE_STARTED}; + +// One frame of the scripted screen: its events, `ms` after T0. +struct Frame{ + int ms; + ScreenEvents events; +}; + +// FRLG's rows bound to a recorder, and its interrupts to a scripted look +// and handlers that note what they cleared, all in `trace`. +class FakeGame{ +public: + explicit FakeGame(std::vector screen) + : m_screen(std::move(screen)) + , m_table(make_story_action_table([this](StoryActionId id){ return recorder(id); })) + , m_executor(m_table, m_guard) + , m_interrupts(step_interrupts([this](bool){ return look(); }, noting())) + { + m_executor.set_interrupts(&m_interrupts); + } + + // `kind`'s step through the table, from a known pose: its outcome. + Pokemon::Outcome run(StoryStepKind kind){ + Pokemon::StoryStep step; + step.kind = kind; + step.name = "synthetic"; + return m_executor.run(state, step); + } + + Pokemon::RunState state{.pose = to_pose(StoryPose{"Route1", TilePos{1, 2}, std::nullopt})}; + std::vector trace; + +private: + // The screen until its last frame, then quiet: a cleared interrupt is + // gone at the next look. + Pokemon::ScreenLook look(){ + Pokemon::ScreenLook out; + int until = 300; + for (const Frame& frame : std::exchange(m_screen, {})){ + out.log.record(frame.events, T0 + Milliseconds(frame.ms)); + until = std::max(until, frame.ms + 300); + } + out.window = {T0, T0 + Milliseconds(until)}; + return out; + } + StepInterruptActions noting(){ + const auto note = [this](const char* kind){ + return [this, kind](Pokemon::RunState&, const Pokemon::InterruptVerdict&){ + trace.push_back(std::string("clear ") + kind); + return Pokemon::outcome_ok(); + }; + }; + return {.wild = note("wild"), .trainer = note("trainer"), .dialog = note("dialog"), .warp = note("warp")}; + } + Pokemon::StoryAction recorder(StoryActionId id){ + return {.act = [this, id](Pokemon::RunState&, const Pokemon::StoryStep&){ + trace.emplace_back(story_action_name(id)); + return Pokemon::outcome_ok(); + }}; + } + + std::vector m_screen; + Pokemon::StepGuard m_guard; + Pokemon::StoryActionTable m_table; + Pokemon::TableExecutor m_executor; + Pokemon::StoryInterrupts m_interrupts; +}; + +// Runs a `kind` step after `screen`; empty if what ran was `expected`. +std::string ran(std::vector screen, StoryStepKind kind, const std::vector& expected){ + FakeGame game(std::move(screen)); + const Pokemon::Outcome outcome = game.run(kind); + if (outcome.succeeded() && game.trace == expected){ + return ""; + } + std::string got = Pokemon::to_string(outcome) + ":"; + for (const std::string& item : game.trace){ + got += " " + item; + } + return std::string(Pokemon::story_step_kind_name(kind)) + ": got " + got; +} + +UnitTestResult test_message(){ + const std::vector message{{0, OVERWORLD}, {100, BOX}}; + for (const std::string& error : { + ran(message, StoryStepKind::ROUTE, {"clear dialog", "route"}), + ran(message, StoryStepKind::TALK, {"clear dialog", "talk"}), + ran(message, StoryStepKind::MASH, {"mash"}), + ran(message, StoryStepKind::ANSWER, {"answer"}), + ran(message, StoryStepKind::BATTLE, {"battle"}), + }){ + if (!error.empty()){ + return error; + } + } + return true; +} + +UnitTestResult test_battle(){ + const std::vector wild{{0, OVERWORLD}, {100, WHITE}, {400, OVERWORLD}, {1500, BATTLE}}; + const std::vector trainer{{0, OVERWORLD}, {100, BOX}, {2000, BLACK}, {2500, BATTLE}}; + for (const std::string& error : { + ran(wild, StoryStepKind::ROUTE, {"clear wild", "route"}), + ran(wild, StoryStepKind::BATTLE, {"battle"}), + ran(trainer, StoryStepKind::LEGS, {"clear trainer", "legs"}), + ran(trainer, StoryStepKind::BATTLE, {"battle"}), + ran(trainer, StoryStepKind::GAME, {"game"}), + }){ + if (!error.empty()){ + return error; + } + } + return true; +} + +UnitTestResult test_warp(){ + const std::vector warp{{0, OVERWORLD}, {100, BLACK}, {600, OVERWORLD}, {9000, OVERWORLD}}; + FakeGame game(warp); + const Pokemon::Outcome outcome = game.run(StoryStepKind::STEP); + if (!outcome.succeeded() || game.trace != std::vector{"clear warp", "step"}){ + return "Expected the warp cleared before the step, got " + Pokemon::to_string(outcome); + } + if (game.state.pose.where != nullptr){ + return "Expected the pose lost after a warp, got " + Pokemon::to_string(game.state.pose); + } + return ran(warp, StoryStepKind::GAME, {"game"}); +} + + +struct StepInterruptsInput{ + std::string name; + UnitTestResult (*body)(); +}; +struct StepInterruptsExpectation{ + const char* description; +}; +struct StepInterruptsTestCase{ + StepInterruptsInput input; + StepInterruptsExpectation expectation; +}; + +class Test_StepInterrupts : public UnitTest{ +public: + explicit Test_StepInterrupts(StepInterruptsTestCase scenario) + : UnitTest("PokemonFRLG::AutoStoryStepInterrupts - " + scenario.input.name) + , m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_scenario.input.body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + StepInterruptsTestCase m_scenario; +}; + +const StepInterruptsTestCase STEP_INTERRUPTS_CASES[] = { + { + .input = {.name = "a message before a step", .body = test_message}, + .expectation = {.description = "read before a walk or a talk; the step's own before one that presses through text"}, + }, + { + .input = {.name = "a battle before a step", .body = test_battle}, + .expectation = {.description = "run from or fought before a walk; a BATTLE's own, its lines missed or not"}, + }, + { + .input = {.name = "a warp before a step", .body = test_warp}, + .expectation = {.description = "pressed through and the pose lost; a GAME's own"}, + }, +}; + +} // namespace + + +void add_tests_AutoStoryStepInterrupts(UnitTestDatabase& database){ + for (const auto& scenario : STEP_INTERRUPTS_CASES){ + database.add(scenario); + } +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp index 1934284d6a..ef2de6078e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp @@ -16,6 +16,7 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "Pokemon/AutoStory/Pokemon_StoryActions.h" +#include "PokemonFRLG_AutoStoryStepInterrupts.h" #include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" @@ -225,6 +226,7 @@ void add_tests_AutoStoryStepTable(UnitTestDatabase& database){ for (const auto& scenario : STEP_TABLE_CASES){ database.add(scenario); } + add_tests_AutoStoryStepInterrupts(database); } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 2cd33c9dfb..67257eb41f 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1895,6 +1895,9 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp From 3876fbd4ecc54119c502618f3c7140043138b8ae Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 04:39:13 -0800 Subject: [PATCH 16/29] FRLG AutoStory: step interrupts test returns its pass Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp index 29b8b0693f..1a298098d9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp @@ -164,7 +164,11 @@ UnitTestResult test_warp(){ if (game.state.pose.where != nullptr){ return "Expected the pose lost after a warp, got " + Pokemon::to_string(game.state.pose); } - return ran(warp, StoryStepKind::GAME, {"game"}); + const std::string error = ran(warp, StoryStepKind::GAME, {"game"}); + if (!error.empty()){ + return error; + } + return true; } From 40ee31f86a127a4edf783318cd7e7c6d1d4317a2 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 04:47:25 -0800 Subject: [PATCH 17/29] FRLG AutoStory: the console's interrupt actions beside the table Moves them out of StoryExecutor into console_interrupt_actions(), next to step_interrupts(), keeping the executor's file small. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 29 ++++--------------- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 2 -- .../PokemonFRLG_AutoStoryStepInterrupts.cpp | 27 +++++++++++++++++ .../PokemonFRLG_AutoStoryStepInterrupts.h | 17 +++++++++-- 4 files changed, 48 insertions(+), 27 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index fa6a02aee9..5a2baefcf1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -471,7 +471,12 @@ StoryExecutor::StoryExecutor(StoryEnv& env) , m_table(make_story_action_table([this](StoryActionId id){ return console_action(id); })) , m_executor(m_table, m_guard) , m_look(env.console, env.context) - , m_interrupts(step_interrupts([this](bool fresh){ return m_look.look(fresh); }, console_interrupt_actions())) + , m_interrupts(step_interrupts( + [this](bool fresh){ return m_look.look(fresh); }, + console_interrupt_actions(env.console, env.context, [&env]{ + return story_interrupts(env.supplies, false, env.checks, env.language); + }) + )) { m_executor.set_interrupts(&m_interrupts); } @@ -494,28 +499,6 @@ Pokemon::StoryAction StoryExecutor::console_action(StoryActionId id){ return {.act = [this, action](RunState& state, const StoryStep& step){ return action(m_env, state, step); }, .needs_console = true}; } -// As the walker clears them part-way through a leg (story_interrupts()): -// a wild battle is run from; a message is read to its end, and a -// trainer's battle after it fought. A warp's scene is pressed through. -StepInterruptActions StoryExecutor::console_interrupt_actions(){ - const auto walker_clears = [this](bool wild){ - return [this, wild](RunState&, const Pokemon::InterruptVerdict&){ - const OverworldInterruptSet set = story_interrupts(m_env.supplies, false, m_env.checks, m_env.language); - (wild ? set.wild : set.other).front()->clear(m_env.console, m_env.context); - return Pokemon::outcome_ok(); - }; - }; - return StepInterruptActions{ - .wild = walker_clears(true), - .trainer = walker_clears(false), - .dialog = walker_clears(false), - .warp = [this](RunState&, const Pokemon::InterruptVerdict&){ - mash_until_overworld(m_env.console, m_env.context, SCENE_TIMEOUT); - return Pokemon::outcome_ok(); - }, - }; -} - std::string check_save_place(StoryEnv& env, const std::string& start_map){ if (save_card_place(start_map).empty()){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 433bfc2c4d..f8f006c849 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -204,8 +204,6 @@ class StoryExecutor : public Pokemon::StoryStepExecutor{ private: // How the console does `id`. Pokemon::StoryAction console_action(StoryActionId id); - // How the console clears each kind of interrupt between steps. - StepInterruptActions console_interrupt_actions(); StoryEnv& m_env; StartMenu m_menu = StartMenu::FULL; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp index d1019d2918..83409af59a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp @@ -8,6 +8,7 @@ #include #include "Common/Cpp/Color.h" #include "CommonTools/Async/InferenceRoutines.h" +#include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryStepInterrupts.h" namespace PokemonAutomation{ @@ -17,6 +18,10 @@ namespace PokemonFRLG{ using Pokemon::InterruptKind; using Pokemon::InterruptPose; using Pokemon::StoryStepKind; +using namespace std::chrono_literals; + +// A warp's scene is a fade and the map's name: well within this. +constexpr Milliseconds WARP_SCENE_TIMEOUT = 60000ms; bool presses_through_text(StoryStepKind kind){ @@ -32,6 +37,28 @@ bool presses_through_text(StoryStepKind kind){ } } +StepInterruptActions console_interrupt_actions( + ConsoleHandle& console, ProControllerContext& context, + std::function walker +){ + const auto walker_clears = [&console, &context, walker](bool wild){ + return [&console, &context, walker, wild](Pokemon::RunState&, const Pokemon::InterruptVerdict&){ + const OverworldInterruptSet set = walker(); + (wild ? set.wild : set.other).front()->clear(console, context); + return Pokemon::outcome_ok(); + }; + }; + return StepInterruptActions{ + .wild = walker_clears(true), + .trainer = walker_clears(false), + .dialog = walker_clears(false), + .warp = [&console, &context](Pokemon::RunState&, const Pokemon::InterruptVerdict&){ + mash_until_overworld(console, context, WARP_SCENE_TIMEOUT); + return Pokemon::outcome_ok(); + }, + }; +} + Pokemon::StoryInterrupts step_interrupts(Pokemon::ScreenLookFunction look, const StepInterruptActions& actions){ Pokemon::StoryInterrupts out; out.look = std::move(look); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h index 547414413d..e9b91d2686 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h @@ -6,8 +6,8 @@ * wild battle is run from, a trainer who saw the player is fought, a * message is read to its end (and a trainer's battle after it fought), * and a warp's fade is pressed through, the pose then lost. The console - * (ConsoleScreenLook and StoryExecutor's console actions) and the - * simulations bind the same table. + * (ConsoleScreenLook and console_interrupt_actions()), the simulation + * and the replay bind the same table. * * The steps that press through text (MASH, ANSWER, BATTLE, GAME, * NEW_GAME) start on a message: one showing before them is theirs. A @@ -22,15 +22,18 @@ #ifndef PokemonAutomation_PokemonFRLG_AutoStoryStepInterrupts_H #define PokemonAutomation_PokemonFRLG_AutoStoryStepInterrupts_H +#include #include "Common/Cpp/Logging/AbstractLogger.h" #include "Common/Cpp/Time.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/Tools/VideoStream.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "Pokemon/AutoStory/Pokemon_ScreenEvents.h" #include "Pokemon/AutoStory/Pokemon_StoryActions.h" #include "Pokemon/AutoStory/Pokemon_StoryInterrupts.h" #include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_AutoStoryScreenEvents.h" namespace PokemonAutomation{ @@ -52,6 +55,16 @@ struct StepInterruptActions{ // lines-to-battle times are not measured on the console yet. Pokemon::StoryInterrupts step_interrupts(Pokemon::ScreenLookFunction look, const StepInterruptActions& actions); +// The console's actions, as the walker clears what stops a leg +// part-way (`walker()`'s interrupts, story_interrupts() in +// PokemonFRLG_AutoStoryBattle.h, built when one is cleared): a wild +// battle is run from, a message read to its end and a trainer's battle +// after it fought. A warp's scene is pressed through. +StepInterruptActions console_interrupt_actions( + ConsoleHandle& console, ProControllerContext& context, + std::function walker +); + // Whether a step of `kind` presses through any text showing when it // starts; a step of another kind is stopped by it (a walk, a talk). bool presses_through_text(Pokemon::StoryStepKind kind); From 8c007f53306bff4ba4a22527c14d44226622bf6a Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 14:51:12 -0800 Subject: [PATCH 18/29] FRLG AutoStory: log the screen before every step Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp | 4 ++++ .../Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp index 83409af59a..5930c46d2e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp @@ -105,6 +105,10 @@ void InterruptLogGuard::on_interrupt(const Pokemon::StoryStep& step, const Pokem ), cleared ? COLOR_ORANGE : COLOR_RED); } +void InterruptLogGuard::on_screen(const Pokemon::StoryStep& step, const Pokemon::ScreenSettle& screen){ + m_logger.log(std::format("[Screen] before {}: {}", step.name, Pokemon::describe(screen))); +} + } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h index e9b91d2686..63336a8b2c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h @@ -92,7 +92,8 @@ class ConsoleScreenLook{ }; // The console's guard: a failed step fails it, as before; each interrupt -// found between steps is logged, cleared or not. +// found between steps is logged, cleared or not, and how the screen looked +// before every step. class InterruptLogGuard : public Pokemon::StepGuard{ public: explicit InterruptLogGuard(Logger& logger) @@ -100,6 +101,7 @@ class InterruptLogGuard : public Pokemon::StepGuard{ {} virtual void on_interrupt(const Pokemon::StoryStep& step, const Pokemon::InterruptCheck& check) override; + virtual void on_screen(const Pokemon::StoryStep& step, const Pokemon::ScreenSettle& screen) override; private: Logger& m_logger; From 5e00efab13c28035efa1f2509b29b692a8aaec78 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 15:50:11 -0800 Subject: [PATCH 19/29] FRLG AutoStory: look for the Switch HOME menu before each step ConsoleScreenLook puts Pokemon::SwitchHomeObserver in front of FRLG's observer, so a step that starts on HOME fails as game_not_running before any input, as BDSP's (lab-B 2026-11-09 15:31). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp | 7 ++++--- .../AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp index 5930c46d2e..e8774ec4af 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp @@ -80,10 +80,11 @@ Pokemon::StoryInterrupts step_interrupts(Pokemon::ScreenLookFunction look, const } -ConsoleScreenLook::ConsoleScreenLook(VideoStream& stream, ProControllerContext& context) - : m_stream(stream) +ConsoleScreenLook::ConsoleScreenLook(ConsoleHandle& console, ProControllerContext& context) + : m_stream(console) , m_context(context) - , m_watcher(m_observer) + , m_eyes(console, m_observer) + , m_watcher(m_eyes) , m_start(current_time()) {} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h index 63336a8b2c..d1d3e5d32a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h @@ -77,9 +77,11 @@ constexpr Milliseconds BETWEEN_STEPS_LOOK = Milliseconds(400); // The console's look between steps: FrlgScreenObserver's events for // BETWEEN_STEPS_LOOK, everything showing in it judged. +// The Switch's HOME menu comes first (Pokemon::SwitchHomeObserver), so a +// step that starts on it fails instead of pressing buttons on HOME. class ConsoleScreenLook{ public: - ConsoleScreenLook(VideoStream& stream, ProControllerContext& context); + ConsoleScreenLook(ConsoleHandle& console, ProControllerContext& context); Pokemon::ScreenLook look(bool fresh); @@ -87,6 +89,7 @@ class ConsoleScreenLook{ VideoStream& m_stream; ProControllerContext& m_context; FrlgScreenObserver m_observer; + Pokemon::SwitchHomeObserver m_eyes; Pokemon::ScreenEventWatcher m_watcher; WallClock m_start; }; From 495c1708e923ede269c44ba95b93a7a32c2d15fb Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 21:38:32 -0800 Subject: [PATCH 20/29] FRLG AutoStory: expect the route plan on one log line Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp index 7f404a1ec0..445525c7f7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp @@ -321,9 +321,7 @@ UnitTestResult test_route_logged(){ return "Failed: " + script.failure; } const std::vector expected{ - "[Route] test walk: plan from Corridor (2, 1):\n" - " east 2 (open) to Corridor (4, 1)\n" - " west 1 (open) to Corridor (3, 1)", + "[Route] test walk: plan from Corridor (2, 1): east 2 (open) to Corridor (4, 1); west 1 (open) to Corridor (3, 1)", "[Route] Leg 1/2: east 2 (open) to Corridor (4, 1)", "[Route] test walk: east 2 (open): ended at Corridor (4, 1) (walked).", "[Route] Leg 2/2: west 1 (open) to Corridor (3, 1)", From 51cb26677a5a5b1ae58362329cb42e31045fffcb Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 09:58:23 -0800 Subject: [PATCH 21/29] FRLG AutoStory: checkpoints 00.01-00.10 as authored JSON, on #312's action/args steps The FRLG stack stopped building after #312: the C++ rows set step.target, legs, direction, fight_wild and may_lose directly, StoryChecks became StoryCheckLevel, Pokemon_StorySteps.h moved to Pokemon_StoryStepExecutor.h and the JSON codecs to Data/. - Each checkpoint is StoryData/frlg-.plan.json (pokesim-authored- checkpoint/1), read with read_authored_checkpoint() against FRLG's actions: the built-in ones plus ROUTE/LEGS "run". The parser fills in the fallbacks (fight_wild, may_lose, yes), so the files give only what differs. FRLG's execution object carries the START menu, the supplies, the lead after Brock and the notes that were C++ comments. - The executor, the step-table, sim and route tests read typed args (story_arg()); the sim's fake game dispatches by kind in run(). - Check levels: DEFAULT and above check the screen as THOROUGH did; FAST and SPEEDRUN trust counts as FAST did. - AutoStory: StoryRunOptions with the FRLG languages, the check level and language into StoryEnv, record_story_counts(). The old C++ rows stay in PokemonFRLG_AutoStoryTableParity_Tests.cpp for this commit only: each file loads to the same steps, args, poses, supplies and START menu. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- SerialPrograms/CMakeLists.txt | 2 + .../PokemonFRLG_OverworldRecovery.cpp | 10 +- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 1 + .../AutoStory/PokemonFRLG_AutoStory.cpp | 27 +- .../PokemonFRLG_AutoStoryActions.cpp | 4 +- .../AutoStory/PokemonFRLG_AutoStoryActions.h | 21 +- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 26 +- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 6 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 52 ++- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 6 +- .../AutoStory/PokemonFRLG_AutoStoryExport.cpp | 2 +- .../PokemonFRLG_AutoStoryExport_Tests.cpp | 2 +- .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 79 ++-- .../PokemonFRLG_AutoStoryStepInterrupts.h | 2 +- .../PokemonFRLG_AutoStoryStepTable.cpp | 20 +- .../PokemonFRLG_AutoStoryStepTable.h | 13 +- .../PokemonFRLG_AutoStoryStepTable_Tests.cpp | 4 +- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 369 +++++------------- .../AutoStory/PokemonFRLG_AutoStoryTable.h | 32 +- ...PokemonFRLG_AutoStoryTableParity_Tests.cpp | 344 ++++++++++++++++ .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 13 +- .../AutoStory/StoryData/frlg-00.01.plan.json | 29 ++ .../AutoStory/StoryData/frlg-00.02.plan.json | 22 ++ .../AutoStory/StoryData/frlg-00.03.plan.json | 41 ++ .../AutoStory/StoryData/frlg-00.04.plan.json | 76 ++++ .../AutoStory/StoryData/frlg-00.05.plan.json | 41 ++ .../AutoStory/StoryData/frlg-00.06.plan.json | 33 ++ .../AutoStory/StoryData/frlg-00.07.plan.json | 95 +++++ .../AutoStory/StoryData/frlg-00.08.plan.json | 82 ++++ .../AutoStory/StoryData/frlg-00.09.plan.json | 79 ++++ .../AutoStory/StoryData/frlg-00.10.plan.json | 48 +++ SerialPrograms/cmake/SourceFiles.cmake | 1 + 32 files changed, 1212 insertions(+), 370 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.02.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.03.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.05.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.06.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.07.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.08.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.10.plan.json diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 73729ebde9..5a90664df8 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -231,6 +231,8 @@ pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Overworld/Ma VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h PokemonAutomation::NintendoSwitch::PokemonFRLG overworld_map_json) pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_battle_json) +pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData + VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_checkpoint_json) # Create binary target diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp index 7e37bafded..ce552195c7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp @@ -71,20 +71,20 @@ class RouteLogLines{ for (const RouteStep& step : steps){ legs.push_back({.leg = route_log_leg(step), .after = route_tiles(step.end)}); } - m_calls.log(ROUTE_LOG_TAG + Pokemon::route_plan_line(m_label, route_tiles(from), legs)); + m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_plan_line(m_label, route_tiles(from), legs)); } void leg(size_t index, const std::vector& steps) const{ const RouteStep& step = steps[index]; - m_calls.log(ROUTE_LOG_TAG + Pokemon::route_leg_line(index + 1, steps.size(), {.leg = route_log_leg(step), .after = route_tiles(step.end)})); + m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_leg_line(index + 1, steps.size(), {.leg = route_log_leg(step), .after = route_tiles(step.end)})); } void end(const RouteStep& step, const std::optional& at, EndBasis basis, const std::string& why) const{ - m_calls.log(ROUTE_LOG_TAG + Pokemon::route_leg_end_line(m_label, route_log_leg(step), route_tiles(at), basis, why)); + m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_leg_end_line(m_label, route_log_leg(step), route_tiles(at), basis, why)); } void trainer_stopped(const RouteStep& step, const MapPosition& at) const{ - m_calls.log(ROUTE_LOG_TAG + Pokemon::route_replan_line(m_label, route_log_leg(step), "stopped by a trainer who saw the player", route_tiles(at))); + m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_replan_line(m_label, route_log_leg(step), "stopped by a trainer who saw the player", route_tiles(at))); } void found(const MapPosition& at, size_t holds) const{ - m_calls.log(ROUTE_LOG_TAG + Pokemon::route_found_line(m_label, route_tiles(at), holds)); + m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_found_line(m_label, route_tiles(at), holds)); } // Step `number` (from 1) of a plan whose first `holds` steps are holds // to walls, walked to its end. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index cea4ff7bc9..4a5a0b5310 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -319,6 +319,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_OverworldRecovery(database); add_tests_PlayerFacingReader(database); add_tests_AutoStory(database); + add_tests_AutoStoryTableParity(database); add_tests_AutoStoryExport(database); add_tests_AutoStorySimulation(database); add_tests_AutoStoryItems(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 6dab6ec05e..431de98ad7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -11,7 +11,9 @@ #include "CommonFramework/Notifications/ProgramNotifications.h" #include "CommonFramework/VideoPipeline/VideoOverlay.h" #include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" +#include "Pokemon/AutoStory/Pokemon_StoryLog.h" #include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/Options/Pokemon_GameLanguages.h" #include "Pokemon/Pokemon_Strings.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "PokemonFRLG_AutoStoryEvents.h" @@ -46,7 +48,14 @@ namespace{ // The start and end dropdowns' entries: the table's checkpoints, 00.01 to // 00.10. The options hold a reference to it. const StringSelectDatabase& checkpoint_database(){ - static const StringSelectDatabase database = Pokemon::story_checkpoint_database(story_checkpoints()); + static const std::vector labels = []{ + std::vector result; + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + result.push_back(Pokemon::story_checkpoint_label(checkpoint)); + } + return result; + }(); + static const StringSelectDatabase database = Pokemon::story_checkpoint_database(labels); return database; } @@ -58,7 +67,7 @@ const char* const KEEP_START_FRAME_TEXT = } // namespace AutoStory::AutoStory() - : RUN(checkpoint_database()) + : RUN(checkpoint_database(), Pokemon::FireRedLeafGreenLanguages_Database()) , NEW_GAME_FROM_TITLE( "New game from the title screen:
The game is on its title screen with no save data. " "Needed to start at 00.01. Otherwise the program loads the save, which must be the one the start checkpoint begins from.", @@ -101,7 +110,7 @@ namespace{ // the screen as its frame if `keep_start_frame` (a save made by hand). StoryEnv story_env( SingleSwitchProgramEnvironment& env, ProControllerContext& context, - const StoryCheckpoint& checkpoint, StoryChecks checks, bool keep_start_frame + const StoryCheckpoint& checkpoint, Pokemon::StoryCheckLevel checks, bool keep_start_frame ){ StoryEnv story{env.console, context, checkpoint.supplies, checkpoint.supplies, false, checks}; story.start_frames = program_start_frames(); @@ -173,11 +182,10 @@ void verify_story_checkpoint( ){ const std::vector& checkpoints = story_checkpoints(); const StoryCheckpoint& checkpoint = checkpoints[run.start_index()]; - StoryEnv story = story_env(env, context, checkpoint, run.checks(), false); + StoryEnv story = story_env(env, context, checkpoint, run.check_level(), false); load_verify_save(env, context, story, checkpoint); + story.language = run.language(); StoryExecutor executor(story); - executor.set_checks(run.checks()); - executor.set_language(run.language()); Pokemon::Segment segment = make_story_segment(checkpoints, executor); Pokemon::SegmentHooks hooks = story_hooks(env, story); @@ -211,7 +219,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex throw UserSetupError(env.console, "Checkpoint 00.01 starts a new game: start on the title screen with no save."); } - StoryEnv story = story_env(env, context, checkpoints[first], RUN.checks(), KEEP_START_FRAME); + StoryEnv story = story_env(env, context, checkpoints[first], RUN.check_level(), KEEP_START_FRAME); if (!(first == 0 && NEW_GAME_FROM_TITLE)){ env.console.log("Loading the save for " + checkpoints[first].id + "."); soft_reset(env.console, context); @@ -221,9 +229,8 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex read_bag_supplies(story, checkpoints[first].menu); } + story.language = RUN.language(); StoryExecutor executor(story); - executor.set_checks(RUN.checks()); - executor.set_language(RUN.language()); Pokemon::Segment segment = make_story_segment(checkpoints, executor); Pokemon::SegmentHooks hooks = story_hooks(env, story); @@ -231,7 +238,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex const Pokemon::SegmentReport report = run_segment( state, segment, Pokemon::SegmentRange{checkpoints[first].id, checkpoints[last].id}, RUN.policy(), hooks ); - Pokemon::record_story_stats(env.current_stats(), report); + Pokemon::record_story_counts(env.current_stats(), report.story_counts()); env.update_stats(); if (!report.completed){ throw OperationFailedException( diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index e484701c7d..d38e145428 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -796,7 +796,7 @@ static void check_mart_row(ConsoleHandle& console, ProControllerContext& context void buy_items( ConsoleHandle& console, ProControllerContext& context, - const std::vector& orders, StoryChecks checks, Language language + const std::vector& orders, Pokemon::StoryCheckLevel checks, Language language ){ // "May I help you?" with BUY on top, then the list, cursor on its top. press(context, BUTTON_A, 2000ms); @@ -813,7 +813,7 @@ void buy_items( } cursor = order.row; mart_shot(console, context, std::format("row{}-list", order.row + 1)); - if (checks == StoryChecks::THOROUGH){ + if (checks_screen(checks)){ check_mart_row(console, context, order, language); } // "How many?" drops presses while its text prints. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index 27eeb690b3..31d2a99fbf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -23,7 +23,8 @@ #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" #include "Pokemon/Navigation/Pokemon_Grid.h" namespace PokemonAutomation{ @@ -31,13 +32,15 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// How much the story checks the screen before and after it acts: the -// shared level (Pokemon_StorySteps.h, set by StoryRunOptions). For FRLG, -// THOROUGH reads a Mart row's item before buying it, the bag's Items -// pocket after shopping (the counts the story then keeps), and an item's -// name in the bag before using it. FAST trusts the counts it keeps and the -// timings. -using StoryChecks = Pokemon::StoryChecks; +// Whether the shared check level (Types/Pokemon_StoryCheckLevel.h, set by +// StoryRunOptions) has the story check the screen before and after it +// acts: DEFAULT and above (TESTING, THOROUGH). Then FRLG reads a Mart +// row's item before buying it, the bag's Items pocket after shopping (the +// counts the story then keeps), and an item's name in the bag before +// using it. FAST and SPEEDRUN trust the counts it keeps and the timings. +inline bool checks_screen(Pokemon::StoryCheckLevel level){ + return level <= Pokemon::StoryCheckLevel::DEFAULT; +} // The START menu as the story grows it. Before the starter: BAG, the // player, SAVE, OPTION, EXIT; the starter adds POKEMON on top, the Pokedex @@ -214,7 +217,7 @@ int mart_cursor_moves(int cursor, int row); // bought by position only. void buy_items( ConsoleHandle& console, ProControllerContext& context, - const std::vector& orders, StoryChecks checks, Language language + const std::vector& orders, Pokemon::StoryCheckLevel checks, Language language ); // From the title screen of a game with no save, to the bedroom: the diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 555ecccfbe..8e02ced513 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -164,9 +164,9 @@ void tap(ProControllerContext& context, DpadPosition position){ // no names for) is taken by its position; only another item's name stops it. bool bag_row_is( ConsoleHandle& console, ProControllerContext& context, - int row, const std::string& item, StoryChecks checks, Language language + int row, const std::string& item, Pokemon::StoryCheckLevel checks, Language language ){ - if (checks == StoryChecks::FAST){ + if (!checks_screen(checks)){ return true; } context.wait_for_all_requests(); @@ -190,7 +190,7 @@ bool bag_row_is( // backs out to the battle menu. Not run on the console yet. bool use_item( ConsoleHandle& console, ProControllerContext& context, - int row, const std::string& item, StoryChecks checks, Language language + int row, const std::string& item, Pokemon::StoryCheckLevel checks, Language language ){ console.log(std::format("Battle: using the {} in row {} of the Items pocket.", item, row + 1)); tap(context, DPAD_LEFT); @@ -321,7 +321,7 @@ class BattleLoop{ public: BattleLoop( ConsoleHandle& console, ProControllerContext& context, - Supplies& supplies, BattleKind kind, StoryChecks checks, Language language + Supplies& supplies, BattleKind kind, Pokemon::StoryCheckLevel checks, Language language ) : m_console(console) , m_context(context) @@ -659,7 +659,7 @@ class BattleLoop{ BattleEndWatch m_end; MoveRefusalWatch m_refusal; const BattleKind m_kind; - const StoryChecks m_checks; + const Pokemon::StoryCheckLevel m_checks; const Language m_language; const WallClock m_start; WallClock m_last_battle; @@ -694,7 +694,7 @@ void open_items_pocket(ConsoleHandle& console, ProControllerContext& context){ // Not run on the console yet. bool use_item_on_overworld( ConsoleHandle& console, ProControllerContext& context, - int row, const std::string& item, StoryChecks checks, Language language + int row, const std::string& item, Pokemon::StoryCheckLevel checks, Language language ){ console.log(std::format("Story: using a {} from the bag (Items pocket, row {}).", item, row + 1)); open_items_pocket(console, context); @@ -727,7 +727,7 @@ void fail_on_blackout(ConsoleHandle& console, BattleEnd end){ // appeared!". class StoryWildBattle : public OverworldInterrupt{ public: - StoryWildBattle(Supplies& supplies, bool fight, bool late, StoryChecks checks, Language language) + StoryWildBattle(Supplies& supplies, bool fight, bool late, Pokemon::StoryCheckLevel checks, Language language) : m_supplies(supplies) , m_checks(checks) , m_language(language) @@ -758,7 +758,7 @@ class StoryWildBattle : public OverworldInterrupt{ private: Supplies& m_supplies; - const StoryChecks m_checks; + const Pokemon::StoryCheckLevel m_checks; const Language m_language; const bool m_fight; const bool m_late; @@ -767,7 +767,7 @@ class StoryWildBattle : public OverworldInterrupt{ // A message: read to its end, then a trainer's battle if one starts. class StoryMessage : public OverworldInterrupt{ public: - StoryMessage(Supplies& supplies, StoryChecks checks, Language language) + StoryMessage(Supplies& supplies, Pokemon::StoryCheckLevel checks, Language language) : m_supplies(supplies) , m_checks(checks) , m_language(language) @@ -793,7 +793,7 @@ class StoryMessage : public OverworldInterrupt{ private: Supplies& m_supplies; - const StoryChecks m_checks; + const Pokemon::StoryCheckLevel m_checks; const Language m_language; }; @@ -932,7 +932,7 @@ std::vector read_items_pocket(ConsoleHandle& console, ProControllerConte void recover_after_battle( ConsoleHandle& console, ProControllerContext& context, - Supplies& supplies, StoryChecks checks, Language language + Supplies& supplies, Pokemon::StoryCheckLevel checks, Language language ){ if (supplies.status == StatusCondition::POISON && supplies.antidotes > 0){ if (use_item_on_overworld(console, context, item_row(supplies, "antidote"), "antidote", checks, language)){ @@ -959,12 +959,12 @@ void recover_after_battle( BattleEnd fight_battle( ConsoleHandle& console, ProControllerContext& context, - Supplies& supplies, BattleKind kind, StoryChecks checks, Language language + Supplies& supplies, BattleKind kind, Pokemon::StoryCheckLevel checks, Language language ){ return BattleLoop(console, context, supplies, kind, checks, language).run(); } -OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks, Language language){ +OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, Pokemon::StoryCheckLevel checks, Language language){ // Battles first: their screens are checked before the message box's. OverworldInterruptSet ret; ret.wild.emplace_back(std::make_unique(supplies, fight_wild, false, checks, language)); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index b0cca42e3c..7f65bf3d0b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -179,7 +179,7 @@ bool battle_shows(const ImageViewRGB32& screen); // different one isn't used. BattleEnd fight_battle( ConsoleHandle& console, ProControllerContext& context, - Supplies& supplies, BattleKind kind, StoryChecks checks, Language language + Supplies& supplies, BattleKind kind, Pokemon::StoryCheckLevel checks, Language language ); @@ -188,7 +188,7 @@ BattleEnd fight_battle( // The bag's inputs are not checked on the console yet. void recover_after_battle( ConsoleHandle& console, ProControllerContext& context, - Supplies& supplies, StoryChecks checks, Language language + Supplies& supplies, Pokemon::StoryCheckLevel checks, Language language ); @@ -196,7 +196,7 @@ void recover_after_battle( // fought if `fight_wild`. A message is advanced until the overworld is // back; a battle that starts after it (a trainer who saw the player) is // fought. A battle lost (a blackout) throws OperationFailedException. -OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks, Language language); +OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, Pokemon::StoryCheckLevel checks, Language language); // Registers AutoStory item usage unit tests. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 5a2baefcf1..7756577c90 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -51,6 +51,20 @@ Outcome guarded(Body&& body){ } } +// The step's arg `key`, which its action declares. +template +const Type& arg(const StoryStep& step, std::string_view key){ + return Pokemon::story_arg(step.args, key); +} + +// A checkpoint's start as the engine's Pose: nothing for a new game. +std::optional start_pose(const StoryCheckpoint& checkpoint){ + if (!checkpoint.start){ + return std::nullopt; + } + return Pokemon::pose_of(*checkpoint.start); +} + const MapData* find_story_map(const std::string& name){ for (const MapData& map : story_maps()){ if (map.name == name){ @@ -78,13 +92,13 @@ std::optional face_a_wall(StoryEnv& env, const MapPosition& position) // The shared route log's arrival line (Pokemon_RouteLog.h), as BDSP's walker // writes it: where the route was walked to. void log_arrival(StoryEnv& env, const std::string& label, const std::string& map, const TilePos& tile){ - env.console.log(Pokemon::ROUTE_LOG_TAG + Pokemon::route_arrived_line(label, {{map, tile}})); + env.console.log(std::string(Pokemon::ROUTE_LOG_TAG) + Pokemon::route_arrived_line(label, {{map, tile}})); } // The walker's check that each leg to a wall ended at it (a diagnostic): // with Thorough checks only, as Fast trusts the walk. WallCheck wall_check(const StoryEnv& env){ - return env.checks == StoryChecks::THOROUGH ? WallCheck::TAP : WallCheck::SKIP; + return checks_screen(env.checks) ? WallCheck::TAP : WallCheck::SKIP; } Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ @@ -100,9 +114,10 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ if (!facing){ return Pokemon::outcome_failed("unknown_facing", to_string(start)); } - const std::optional target = step.target ? story_pose(*step.target) : std::nullopt; + const Pokemon::Pose target_pose = Pokemon::pose_of(arg(step, "target")); + const std::optional target = story_pose(target_pose); if (!target){ - return Pokemon::outcome_failed("bad_target", step.target ? Pokemon::to_string(*step.target) : "none"); + return Pokemon::outcome_failed("bad_target", Pokemon::to_string(target_pose)); } const RouteGoal goal{{target->map, target->tile}, target->facing}; const std::optional> route = plan_overworld_route( @@ -111,7 +126,7 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ if (!route){ return Pokemon::outcome_failed("no_route", to_string(start) + " to " + to_string(goal.position)); } - const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks, env.language); + const OverworldInterruptSet interrupts = story_interrupts(env.supplies, arg(step, "fight_wild"), env.checks, env.language); // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name, .wall_check = wall_check(env)}; @@ -131,11 +146,11 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ if (!facing){ facing = face_a_wall(env, start); } - const std::optional> route = fixed_route(story_maps(), start, step.legs); + const std::optional> route = fixed_route(story_maps(), start, arg>(step, "legs")); if (!facing || !route || route->empty()){ return Pokemon::outcome_failed("bad_legs", to_string(start)); } - const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks, env.language); + const OverworldInterruptSet interrupts = story_interrupts(env.supplies, arg(step, "fight_wild"), env.checks, env.language); // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name, .wall_check = wall_check(env)}; @@ -145,19 +160,20 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ } Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ - step_once(env.context, step.direction, facing_of(state.pose)); + const Direction direction = arg(step, "direction"); + step_once(env.context, direction, facing_of(state.pose)); const std::vector tiles = Pokemon::tiles_of(state.pose); if (tiles.size() != 1){ return Pokemon::outcome_ok(); } - return Pokemon::outcome_ok(to_pose(StoryPose{state.pose.map, tiles[0].next(step.direction), step.direction})); + return Pokemon::outcome_ok(to_pose(StoryPose{state.pose.map, tiles[0].next(direction), direction})); } // Before a BattleRisk::HIGH battle the story may lose: the sim's win // chance, the HP as the last bar read left it. Why not to fight, if so. std::optional refuse_battle(StoryEnv& env, const StoryStep& step, std::string_view trainer){ const Supplies& supplies = env.supplies; - if (step.may_lose || supplies.risk != BattleRisk::HIGH){ + if (arg(step, "may_lose") || supplies.risk != BattleRisk::HIGH){ return std::nullopt; } const std::optional estimate = story_win_chance(supplies.lead, supplies.potions, supplies.hp_fill, trainer); @@ -194,7 +210,7 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ env.supplies.foes.clear(); env.supplies.trainer.clear(); env.supplies.foe_out.reset(); - if (end == BattleEnd::LOST && !step.may_lose){ + if (end == BattleEnd::LOST && !arg(step, "may_lose")){ return Pokemon::outcome_failed("blackout"); } mash_until_overworld(env.console, env.context, SCENE_TIMEOUT); @@ -249,16 +265,16 @@ const MartItem* viridian_mart_item(const std::string& name){ } Outcome shop(StoryEnv& env, const StoryStep& step){ - const std::optional> orders = viridian_mart_orders(step.items); + const std::optional> orders = viridian_mart_orders(arg>(step, "items")); if (!orders){ return Pokemon::outcome_failed("unknown_item", step.name); } // 2000 of the 3000 a new game starts with, plus the rival's prize. buy_items(env.console, env.context, *orders, env.checks, env.language); - for (const Pokemon::StoryItem& item : step.items){ + for (const Pokemon::StoryItem& item : arg>(step, "items")){ env.supplies.*viridian_mart_item(item.item)->count += (int)item.quantity; } - if (env.checks == StoryChecks::FAST){ + if (!checks_screen(env.checks)){ return Pokemon::outcome_ok(); } // The counts from the bag, not from the orders: a wrong row once bought @@ -298,7 +314,7 @@ const std::vector& story_maps(){ } MoveSpeed move_speed(const StoryStep& step){ - return step.variant == RUN_VARIANT ? MoveSpeed::RUN : MoveSpeed::WALK; + return step.action == RUN_VARIANT ? MoveSpeed::RUN : MoveSpeed::WALK; } Pokemon::Pose to_pose(const StoryPose& pose){ @@ -435,7 +451,7 @@ ConsoleAction console_action_of(StoryActionId id){ }; case StoryActionId::ANSWER: return [](StoryEnv& env, RunState&, const StoryStep& step){ - answer_yes_no(env.console, env.context, step.yes, BUTTON_B, YES_NO_TIMEOUT); + answer_yes_no(env.console, env.context, arg(step, "yes"), BUTTON_B, YES_NO_TIMEOUT); return Pokemon::outcome_ok(); }; case StoryActionId::MASH: @@ -493,7 +509,7 @@ Pokemon::StoryAction StoryExecutor::console_action(StoryActionId id){ }, .needs_console = true}; } if (id == StoryActionId::GAME){ - return {.act = [this](RunState& state, const StoryStep& step){ return game(state, step); }, .needs_console = true}; + return {.act = [](RunState&, const StoryStep& step){ return Pokemon::unsupported_step(step); }, .needs_console = true}; } const ConsoleAction action = console_action_of(id); return {.act = [this, action](RunState& state, const StoryStep& step){ return action(m_env, state, step); }, .needs_console = true}; @@ -582,7 +598,7 @@ Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& // program last saved there. With none kept, it passes. Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); add_start_check( - checkpoint, data.start, + checkpoint, start_pose(data), [&env, id = data.id]{ return read_console_start(env, id); }, [&env](const std::string& line){ env.console.log(line, COLOR_ORANGE); } ); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index f8f006c849..d9f357e718 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -5,7 +5,7 @@ * The FRLG story as data for the shared story engine * (Pokemon/AutoStory/Pokemon_StoryEvents.h, Pokemon_StorySegments.h). * A checkpoint is a list of the shared StorySteps - * (Pokemon/AutoStory/Pokemon_StorySteps.h), each one kind of event (a + * (Pokemon/AutoStory/Pokemon_StoryStepExecutor.h), each one kind of event (a * route, a talk, text read to its end, a YES/NO, a battle, the nurse, the * Mart); StoryExecutor does each kind on the console, and * make_story_segment() turns the table into engine checkpoints. Routes @@ -29,7 +29,7 @@ #include "Pokemon/AutoStory/Pokemon_StoryActions.h" #include "Pokemon/AutoStory/Pokemon_StoryEvents.h" #include "Pokemon/AutoStory/Pokemon_StorySegments.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" @@ -143,7 +143,7 @@ struct StoryEnv{ Supplies saved_supplies; // Whether the game has a save to reload. bool has_save = false; - StoryChecks checks = StoryChecks::THOROUGH; + Pokemon::StoryCheckLevel checks = Pokemon::StoryCheckLevel::DEFAULT; // The game's language, for reading item names. In one the readers have // no names for, the checks fall back to positions and counts. Language language = Language::English; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp index a0b85c21ea..3d7dd7f18a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp @@ -6,7 +6,7 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" -#include "Pokemon/AutoStory/Pokemon_StoryStepJson.h" +#include "Pokemon/AutoStory/Data/Pokemon_StoryStepJson.h" #include "PokemonFRLG_AutoStoryExport.h" namespace PokemonAutomation{ namespace NintendoSwitch{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp index bc4e0f3f12..7f3757d020 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp @@ -3,7 +3,7 @@ */ #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" -#include "Pokemon/AutoStory/Pokemon_StoryStepJson.h" +#include "Pokemon/AutoStory/Data/Pokemon_StoryStepJson.h" #include "PokemonFRLG_AutoStoryExport.h" #include "PokemonFRLG_AutoStoryTable.h" #include "PokemonFRLG_AutoStoryExport_Tests.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index 6148a1211b..9199c2478e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -22,7 +22,7 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "Pokemon/AutoStory/Pokemon_StorySegments.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" @@ -45,6 +45,14 @@ std::string joined(const std::vector& lines){ return text; } +// A checkpoint's start as the engine's Pose: nothing for a new game. +std::optional start_pose(const StoryCheckpoint& checkpoint){ + if (!checkpoint.start){ + return std::nullopt; + } + return Pokemon::pose_of(*checkpoint.start); +} + const MapData* map_named(const std::string& name){ for (const MapData& map : story_maps()){ if (map.name == name){ @@ -133,48 +141,66 @@ class FakeGame : public Pokemon::StoryStepExecutor{ failure->second.times--; return Pokemon::outcome_failed(failure->second.failure, key); } - return Pokemon::StoryStepExecutor::run(state, step); + return act(state, step); } -protected: - virtual Outcome route(RunState& state, const StoryStep& step) override{ - return walk_to(state.pose, step); +private: + // The step by its kind, as the console does it (StoryExecutor), with + // nothing done on a screen. + Outcome act(RunState& state, const StoryStep& step){ + switch (step.kind){ + case StoryStepKind::ROUTE: + return walk_to(state.pose, step); + case StoryStepKind::LEGS: + return legs(state, step); + case StoryStepKind::STEP: + return take_step(state, step); + case StoryStepKind::READY: + return ready(state, step); + case StoryStepKind::SHOP: + return shop(step); + case StoryStepKind::NEW_GAME: + case StoryStepKind::OPTIONS: + case StoryStepKind::TALK: + case StoryStepKind::ANSWER: + case StoryStepKind::MASH: + case StoryStepKind::BATTLE: + case StoryStepKind::HEAL: + return Pokemon::outcome_ok(); + default: + return Pokemon::unsupported_step(step); + } } - virtual Outcome legs(RunState& state, const StoryStep& step) override{ + Outcome legs(RunState& state, const StoryStep& step){ const Standing at = standing(state.pose); if (!at.error.empty()){ return Pokemon::outcome_failed("no_pose", at.error); } - const std::optional> route = fixed_route(story_maps(), at.position, step.legs); + const std::optional> route = fixed_route(story_maps(), at.position, Pokemon::story_arg>(step.args, "legs")); if (!route || route->empty()){ return Pokemon::outcome_failed("bad_legs", to_string(at.position)); } return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after})); } - virtual Outcome step(RunState& state, const StoryStep& step) override{ + Outcome take_step(RunState& state, const StoryStep& step){ const std::optional at = story_pose(state.pose); if (!at){ return Pokemon::outcome_failed("no_pose", Pokemon::to_string(state.pose)); } - return Pokemon::outcome_ok(to_pose(StoryPose{at->map, at->tile.next(step.direction), step.direction})); + const Direction direction = Pokemon::story_arg(step.args, "direction"); + return Pokemon::outcome_ok(to_pose(StoryPose{at->map, at->tile.next(direction), direction})); } // The nurse's way must plan too, but the run goes on from where it stands. - virtual Outcome ready(RunState& state, const StoryStep& step) override{ + Outcome ready(RunState& state, const StoryStep& step){ const Outcome to_nurse = walk_to(state.pose, step); return to_nurse.succeeded() ? Pokemon::outcome_ok() : to_nurse; } - virtual Outcome new_game(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } - virtual Outcome options(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } - virtual Outcome talk(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } - virtual Outcome answer(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } - virtual Outcome mash(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } - virtual Outcome battle(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } - virtual Outcome heal(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } // The Viridian Mart's list as the game shows it. After a purchase the // cursor stays on the row bought (console B, 2026-11-01), so each // order moves it from there, as buy_items() does since ad5d40885. - virtual Outcome shop(RunState&, const StoryStep& step) override{ + Outcome shop(const StoryStep& step){ + const std::vector& items = Pokemon::story_arg>(step.args, "items"); static const std::vector LIST{"poke_ball", "potion", "antidote", "parlyz_heal", "cancel"}; - const std::optional> orders = viridian_mart_orders(step.items); + const std::optional> orders = viridian_mart_orders(items); if (!orders){ return Pokemon::outcome_failed("unknown_item", step.name); } @@ -186,21 +212,20 @@ class FakeGame : public Pokemon::StoryStepExecutor{ if (cursor < 0 || cursor >= (int)LIST.size() || LIST[cursor] == "cancel"){ return Pokemon::outcome_failed("mart_cancel", std::format("order {} ends on row {}", c + 1, cursor + 1)); } - if (LIST[cursor] != step.items[c].item){ - return Pokemon::outcome_failed("wrong_item", std::format("{} instead of {}", LIST[cursor], step.items[c].item)); + if (LIST[cursor] != items[c].item){ + return Pokemon::outcome_failed("wrong_item", std::format("{} instead of {}", LIST[cursor], items[c].item)); } bag[LIST[cursor]] += order.quantity; } return Pokemon::outcome_ok(); } -private: Outcome walk_to(const Pokemon::Pose& pose, const StoryStep& step){ const Standing at = standing(pose); if (!at.error.empty()){ return Pokemon::outcome_failed("no_pose", at.error); } - const std::optional target = story_pose(*step.target); + const std::optional target = story_pose(Pokemon::pose_of(Pokemon::story_arg(step.args, "target"))); const RouteGoal goal{{target->map, target->tile}, target->facing}; const std::optional> route = plan_overworld_route( story_maps(), at.position, goal, default_route_costs(), at.facing @@ -232,9 +257,7 @@ struct Simulation{ std::vector> saves; Pokemon::SegmentPolicy policy; - // A language no reader supports, so a step that needed text would show. Pokemon::SegmentReport run(const Pokemon::SegmentRange& range){ - game.set_language(Language::Japanese); Pokemon::Segment segment; segment.id = "00"; for (const StoryCheckpoint& data : story_checkpoints()){ @@ -242,7 +265,7 @@ struct Simulation{ .id = data.id, .title = data.title, .saves = true, .build = [this, &data]{ Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, game); - add_start_pose_check(checkpoint, data.start, [this]{ return game.save_stands; }, [this](const std::string& line){ lines.push_back(line); }); + add_start_pose_check(checkpoint, start_pose(data), [this]{ return game.save_stands; }, [this](const std::string& line){ lines.push_back(line); }); return checkpoint; }, }); @@ -333,13 +356,13 @@ UnitTestResult test_whole_story(){ // Each checkpoint starts where the save before it stands. for (size_t c = 1; c < story_checkpoints().size(); c++){ const StoryCheckpoint& data = story_checkpoints()[c]; - const std::optional start = story_pose(*data.start); + const std::optional start = story_pose(*start_pose(data)); const std::optional saved = story_pose(sim.saves[c - 1].second); const bool same = start && saved && start->map == saved->map && start->tile == saved->tile && (!start->facing || start->facing == saved->facing); if (!same){ return std::format("{} starts at {}, but {} saved at {}.", data.id, - Pokemon::to_string(*data.start), sim.saves[c - 1].first, Pokemon::to_string(sim.saves[c - 1].second)); + Pokemon::to_string(*start_pose(data)), sim.saves[c - 1].first, Pokemon::to_string(sim.saves[c - 1].second)); } } if (report.one_shot_passes() != report.checkpoints_run){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h index d1d3e5d32a..a396b790c7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h @@ -32,7 +32,7 @@ #include "Pokemon/AutoStory/Pokemon_ScreenEvents.h" #include "Pokemon/AutoStory/Pokemon_StoryActions.h" #include "Pokemon/AutoStory/Pokemon_StoryInterrupts.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_AutoStoryScreenEvents.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp index 2869e1c299..7d9da2e079 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp @@ -52,10 +52,28 @@ const std::vector& story_action_rows(){ return ROWS; } +std::span story_action_specs(){ + static const std::vector SPECS = []{ + const std::span builtin = Pokemon::builtin_story_actions(); + std::vector specs(builtin.begin(), builtin.end()); + for (StoryStepKind kind : {StoryStepKind::ROUTE, StoryStepKind::LEGS}){ + Pokemon::StoryActionSpec run = *Pokemon::find_story_action(builtin, kind, ""); + run.name = "run"; + specs.push_back(std::move(run)); + } + return specs; + }(); + return SPECS; +} + Pokemon::StoryActionTable make_story_action_table(const StoryActionBinding& bind){ Pokemon::StoryActionTable table; for (const StoryActionRow& row : story_action_rows()){ - table.add(row.kind, row.variant, bind(row.id)); + Pokemon::StoryAction action = bind(row.id); + if (const Pokemon::StoryActionSpec* spec = Pokemon::find_story_action(story_action_specs(), row.kind, row.variant)){ + action.args = spec->args; + } + table.add(row.kind, row.variant, std::move(action)); } return table; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h index 002e749cb3..3743d498a2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h @@ -14,11 +14,13 @@ #define PokemonAutomation_PokemonFRLG_AutoStoryStepTable_H #include +#include #include #include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" #include "Pokemon/AutoStory/Pokemon_StoryActions.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -55,9 +57,16 @@ struct StoryActionRow{ // Every row. TRAIN and SAVE have none: FRLG's story doesn't use them. const std::vector& story_action_rows(); +// The actions FRLG's steps name, with the args each takes: the built-in +// ones (Pokemon_BuiltinStoryActions.h), then a ROUTE and a LEGS named +// "run" (RUN_VARIANT), which take the same args and run with B held. +// A story file is read against these. +std::span story_action_specs(); + // How one binding (the console, a test) does each action. using StoryActionBinding = std::function; -// The rows as a table, each with `bind`'s action for its id. +// The rows as a table, each with `bind`'s action for its id and its +// spec's args. Pokemon::StoryActionTable make_story_action_table(const StoryActionBinding& bind); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp index ef2de6078e..e1903cfcf4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp @@ -98,7 +98,7 @@ std::string parity_error(FakeGame& game, const StoryStep& step){ std::vector trace; const Pokemon::Outcome outcome = game.run(step, trace); const std::optional expected = old_dispatch(step); - const std::string label = std::format("{} '{}' ({})", Pokemon::story_step_kind_name(step.kind), step.variant, step.name); + const std::string label = std::format("{} '{}' ({})", Pokemon::story_step_kind_name(step.kind), step.action, step.name); if (!expected){ if (!trace.empty() || outcome.failure != "unsupported_step"){ return label + ": expected unsupported, ran " + (trace.empty() ? outcome.failure : trace[0]); @@ -126,7 +126,7 @@ std::vector every_kind_and_variant(){ StoryStep step; step.kind = kind; step.name = "synthetic"; - step.variant = variant; + step.action = variant; steps.push_back(std::move(step)); } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 5a88824d81..88573b08af 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -4,6 +4,14 @@ * */ +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "Pokemon/AutoStory/Data/Pokemon_AuthoredCheckpointJson.h" +#include "PokemonFRLG_AutoStoryParty.h" +#include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" namespace PokemonAutomation{ @@ -13,280 +21,115 @@ namespace PokemonFRLG{ namespace{ -constexpr Direction NORTH = Direction::NORTH; -constexpr Direction SOUTH = Direction::SOUTH; -constexpr Direction EAST = Direction::EAST; -constexpr Direction WEST = Direction::WEST; - -const char* const BEDROOM = "PalletTown_PlayersHouse_2F"; -const char* const PALLET = "PalletTown"; -const char* const LAB = "PalletTown_ProfessorOaksLab"; -const char* const VIRIDIAN = "ViridianCity"; -const char* const VIRIDIAN_MART = "ViridianCity_Mart"; -const char* const VIRIDIAN_CENTER = "ViridianCity_PokemonCenter_1F"; -const char* const FOREST = "ViridianForest"; -const char* const FOREST_GATE = "Route2_ViridianForest_NorthEntrance"; -const char* const PEWTER = "PewterCity"; -const char* const PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; -const char* const GYM = "PewterCity_Gym"; - -Pokemon::Pose at(const char* map, int x, int y, std::optional facing = std::nullopt){ - return to_pose(StoryPose{map, {x, y}, facing}); -} - -StoryCheckpoint row( - std::string id, std::string title, std::optional start, - Supplies supplies, StartMenu menu, std::vector steps -){ - StoryCheckpoint checkpoint; - checkpoint.id = std::move(id); - checkpoint.title = std::move(title); - checkpoint.start = std::move(start); - checkpoint.steps = std::move(steps); - checkpoint.supplies = supplies; - checkpoint.menu = menu; - return checkpoint; -} - -// At the rows after Brock: no items counted, the starter with the moves -// the story gave it by Lv13. A run that loads a save reads the moves off -// the lead's summary instead (read_lead_moves()), so a save whose moves -// differ from these (console B, 2026-11-02: Water Gun where Tackle was) -// is fought with the moves it has. -Supplies after_brock(){ +// The wire names of the START menus. +StartMenu read_start_menu(std::string_view name, std::string_view source){ + if (name == "before_pokemon"){ + return StartMenu::BEFORE_POKEMON; + } + if (name == "before_pokedex"){ + return StartMenu::BEFORE_POKEDEX; + } + if (name == "full"){ + return StartMenu::FULL; + } + throw ParseException(std::format("{}: unknown START menu {}", source, name)); +} + +// `object`'s fields, each of which must be one of `keys`. +void only_fields(const JsonObject& object, std::initializer_list keys, std::string_view source){ + for (const auto& [key, unused] : object){ + bool known = false; + for (std::string_view allowed : keys){ + known |= key == allowed; + } + if (!known){ + throw ParseException(std::format("{}: unsupported execution field {}", source, key)); + } + } +} + +int read_count(const JsonObject& object, const std::string& key, std::string_view source){ + const JsonValue* value = object.get_value(key); + if (value == nullptr){ + return 0; + } + const int64_t count = value->to_integer_throw(std::string(source)); + if (count < 0 || count > 999){ + throw ParseException(std::format("{}: {} out of range", source, key)); + } + return (int)count; +} + +Supplies read_supplies(const JsonObject& execution, std::string_view source){ Supplies supplies; - supplies.lead = story_lead_after_brock(); + if (const JsonObject* items = execution.get_object("supplies")){ + only_fields(*items, {"potions", "antidotes", "parlyz_heals"}, source); + supplies.potions = read_count(*items, "potions", source); + supplies.antidotes = read_count(*items, "antidotes", source); + supplies.parlyz_heals = read_count(*items, "parlyz_heals", source); + } + if (const std::string* lead = execution.get_string("lead")){ + if (*lead != "after_brock"){ + throw ParseException(std::format("{}: unknown lead {}", source, *lead)); + } + supplies.lead = story_lead_after_brock(); + }else if (execution.get_value("lead") != nullptr){ + throw ParseException(std::format("{}: lead must be a string", source)); + } return supplies; } -// What a walk does about wild Pokemon: runs, or fights them for EXP. -enum class WildBattles{ - RUN, - FIGHT, -}; - -StoryStep make(StoryStepKind kind, std::string name, std::string why){ - StoryStep step; - step.kind = kind; - step.name = std::move(name); - step.why = std::move(why); - return step; -} - -StoryStep route(std::string name, Pokemon::Pose target, std::string why, WildBattles wild = WildBattles::RUN){ - StoryStep step = make(StoryStepKind::ROUTE, std::move(name), std::move(why)); - step.target = std::move(target); - step.fight_wild = wild == WildBattles::FIGHT; - return step; -} - -StoryStep step_into(std::string name, Direction direction, std::string why){ - StoryStep step = make(StoryStepKind::STEP, std::move(name), std::move(why)); - step.direction = direction; - return step; -} - -StoryStep answer(std::string name, bool yes, std::string why){ - StoryStep step = make(StoryStepKind::ANSWER, std::move(name), std::move(why)); - step.yes = yes; - return step; -} - -StoryStep scene(std::string name, std::optional pose_after, std::string why){ - StoryStep step = make(StoryStepKind::MASH, std::move(name), std::move(why)); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep battle(std::string name, Pokemon::Pose pose_after, bool may_lose, std::string why){ - StoryStep step = make(StoryStepKind::BATTLE, std::move(name), std::move(why)); - step.pose_after = std::move(pose_after); - step.may_lose = may_lose; - return step; -} - -StoryStep legs(std::string name, std::vector legs, std::string why, WildBattles wild = WildBattles::RUN){ - StoryStep step = make(StoryStepKind::LEGS, std::move(name), std::move(why)); - step.legs = std::move(legs); - step.fight_wild = wild == WildBattles::FIGHT; - return step; -} - -// `step`, a ROUTE or LEGS, run with B held: from the Running Shoes on. No -// checkpoint after 00.10 is in the table yet. -[[maybe_unused]] StoryStep running(StoryStep step){ - step.variant = RUN_VARIANT; - return step; -} - -StoryStep new_game_intro(Pokemon::Pose pose_after, std::string why){ - StoryStep step = make(StoryStepKind::NEW_GAME, "intro", std::move(why)); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep talk(std::string name, std::string why){ - return make(StoryStepKind::TALK, std::move(name), std::move(why)); -} - -StoryStep ready(std::string name, Pokemon::Pose nurse, std::string why){ - StoryStep step = make(StoryStepKind::READY, std::move(name), std::move(why)); - step.target = std::move(nurse); - return step; +// The keys of the notes: "checkpoint" or a step's id, each a list of lines. +std::set read_note_keys(const JsonObject& execution, std::string_view source){ + std::set keys; + const JsonValue* notes = execution.get_value("notes"); + if (notes == nullptr){ + return keys; + } + for (const auto& [key, lines] : notes->to_object_throw(std::string(source))){ + for (const JsonValue& line : lines.to_array_throw(std::string(source))){ + line.to_string_throw(std::string(source)); + } + keys.insert(key); + } + return keys; } -StoryStep heal(std::string name){ - return make(StoryStepKind::HEAL, std::move(name), "full HP"); -} - -StoryStep shop(std::string name, std::vector items, std::string why){ - StoryStep step = make(StoryStepKind::SHOP, std::move(name), std::move(why)); - step.items = std::move(items); - return step; -} - - -StoryCheckpoint new_game(){ - return row("00.01", "new game to the bedroom", std::nullopt, {}, StartMenu::BEFORE_POKEMON, { - // new_game.c: the bedroom at (6, 6), facing the TV. - new_game_intro(at(BEDROOM, 6, 6, NORTH), "Oak's speech, BOY, default names, rival GREEN"), - make(StoryStepKind::OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon"), - }); -} - -StoryCheckpoint leave_house(){ - return row("00.02", "bedroom to Pallet Town", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, { - route("front_door", at(PALLET, 6, 8), "down the stairs and out of the house"), - }); -} - -StoryCheckpoint oaks_trigger(){ - return row("00.03", "Oak stops the player and walks them to the lab", at(PALLET, 6, 8, SOUTH), {}, StartMenu::BEFORE_POKEMON, { - route("below_oaks_trigger", at(PALLET, 12, 2, NORTH), "below the north exit, short of Oak's trigger at (12, 1)"), - step_into("oaks_trigger", NORTH, "the trigger: \"Don't go out!\""), - // PlayerEnter walks the player up 8 tiles from the lab's door. - scene("to_the_lab", at(LAB, 6, 4, NORTH), "Oak walks the player into the lab; the scene ends at the table"), - }); -} - -StoryCheckpoint starter(){ - return row("00.04", "Squirtle, then the rival's battle", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEDEX, { - route("below_squirtle", at(LAB, 9, 5, NORTH), "under Squirtle's ball (9, 4)"), - talk("squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\""), - answer("choose_squirtle", true, "take Squirtle"), - answer("no_nickname", false, "\"give a nickname?\" NO"), - scene("rival_takes_bulbasaur", at(LAB, 9, 5, NORTH), "the rival picks his ball; the player still faces the table (console B, 2026-11-01)"), - route("above_rival_trigger", at(LAB, 7, 7, SOUTH), "short of the rival's trigger row 8"), - step_into("rival_trigger", SOUTH, "\"Wait, let's check out our POKEMON!\""), - // The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down. - battle("rival_battle", at(LAB, 7, 8, SOUTH), true, "the tutorial battle; losing goes on too"), - }); -} - -StoryCheckpoint parcel(){ - return row("00.05", "Route 1 to Viridian Mart: Oak's Parcel", at(LAB, 7, 8, SOUTH), {}, StartMenu::BEFORE_POKEDEX, { - route("below_mart_door", at(VIRIDIAN, 36, 20, NORTH), "Route 1, running from wild battles"), - step_into("mart_door", NORTH, "the clerk's scene starts on entering"), - // ApproachCounter: up 4 from the mat, then faces the clerk. - scene("parcel_from_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "the clerk gives OAK'S PARCEL"), - }); -} - -StoryCheckpoint pokedex(){ - return row("00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, { - route("below_oak", at(LAB, 6, 4, NORTH), "back down Route 1 to Oak"), - talk("give_parcel", "Oak takes the parcel"), - scene("pokedex_scene", at(LAB, 6, 4, SOUTH), "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)"), - }); -} - -StoryCheckpoint shopping(){ - return row("00.07", "Viridian shopping, then into Viridian Forest", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { - route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again"), - // 2000 of the 3000 a new game starts with, plus the rival's prize. - shop("potions_and_antidotes", {{"potion", 5}, {"antidote", 3}, {"parlyz_heal", 1}}, "5 Potions, 3 Antidotes, 1 Parlyz Heal"), - route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest"), - heal("heal_viridian"), - route("below_old_man_trigger", at(VIRIDIAN, 20, 9, NORTH), "short of the tutorial trigger (20, 8)"), - step_into("old_man_trigger", NORTH, "the old man's catching tutorial can't be walked around"), - // TutorialTriggerLeft turns the player right, to the old man. - scene("old_man_tutorial", at(VIRIDIAN, 20, 8, EAST), "about 60 lines and his demo battle; TEACHY TV"), - // After his demo the old man stands east of the player, beside (20, 8), where - // the map doesn't have him: "east 2" from there didn't move, and the walk north - // ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first. - route("past_old_man", at(VIRIDIAN, 20, 5, NORTH), "north along column 20, clear of the old man"), - // The gate's north warp lands on the forest's exit mat (29, 62), facing - // north. The save there keeps a forest failure from going back to Pallet. - route("forest_entrance", at(FOREST, 29, 62, NORTH), "Route 2 and the south gate, running from wild battles"), - }); -} - -StoryCheckpoint forest(){ - // The supplies bought in 00.07. - return row("00.08", "Viridian Forest to Pewter Center", at(FOREST, 29, 62, NORTH), {5, 3, 1}, StartMenu::FULL, { - // Wild battles are fought for EXP. Straight up the east side from the - // entrance, each leg ending on a wall (the Boy at (45, 58) stops the - // east one). Rick (47, 45) sees (42..46, 45), so the last leg meets - // his battle and is held on to its wall after it. The by-hand run's - // detour west to (13, 46) and back is dropped. - legs("forest_east", {{EAST, 1}, {NORTH, 4}, {EAST, 14}, {NORTH, 15}}, "up the east side to (44, 43)", WildBattles::FIGHT), - route("forest_north", at(FOREST, 39, 25), "north part", WildBattles::FIGHT), - // To the gate by legs that end on walls, which the walker holds again - // after a battle instead of estimating where it stopped: planned - // routes with open legs lost the player in the north of the forest - // (console B, 2026-11-01). The two 1-tile legs are single steps. - legs("forest_exit", { - {NORTH, 10}, {WEST, 12}, {SOUTH, 10}, {WEST, 6}, {NORTH, 20}, - {SOUTH, 1}, {WEST, 10}, {SOUTH, 27}, {WEST, 8}, {NORTH, 20}, {EAST, 1}, - }, "walls all the way to the gate's column", WildBattles::FIGHT), - route("forest_gate", at(FOREST_GATE, 7, 10, NORTH), "north onto the exit, arriving on the gate's mat", WildBattles::FIGHT), - // Out of the forest, wild battles are run from; trainers are still fought. - route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center"), - heal("heal_pewter"), - }); -} +} // namespace -StoryCheckpoint brock(){ - // The by-hand save: 2 Potions and 1 Antidote left after the forest. - return row("00.09", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { - // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight - // 4) and sees (4..7, 8): walking north up column 6 from the door, - // the step onto (6, 8) starts his battle. He walks up to the player, - // who stays put and keeps facing north (FRLG doesn't turn the player - // to a trainer). That step is taken on its own, so no leg is cut. - route("below_liam_line", at(GYM, 6, 9, NORTH), "in by the door, up column 6 to below Liam's row"), - step_into("liam_line", NORTH, "onto (6, 8), in Liam's line"), - battle("camper_liam", at(GYM, 6, 8, NORTH), false, "Geodude and Sandshrew; EXP before Brock"), - // On to Brock unless red HP or a status is left that no item cures. - ready("ready_for_brock", at(PEWTER_CENTER, 7, 4, NORTH), "items for a status or low HP; the nurse only if they can't"), - route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5); Liam, beaten, stands at (5, 8)"), - talk("challenge_brock", "Brock's speech"), - battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39"), - }); -} -StoryCheckpoint running_shoes(){ - return row("00.10", "Pewter: the Running Shoes from Oak's aide", at(GYM, 6, 6, NORTH), after_brock(), StartMenu::FULL, { - // Brock's win sets VAR_MAP_SCENE_PEWTER_CITY to 1 and shows the aide at - // (46, 20); his triggers are (46, 21..23) (PewterCity map.json). The - // Gym guide's triggers at (42..43, 21..23) need the scene at 0. - route("before_aide_trigger", at(PEWTER, 45, 21, EAST), "out of the Gym, east along row 21, short of the top trigger"), - step_into("aide_trigger", EAST, "onto (46, 21), below the aide"), - // RunningShoesAideTriggerTop: the aide talks from (46, 20), no YES/NO; - // the player only turns up. He walks off and is removed; FLAG_SYS_B_DASH - // is set (console B, 2026-11-02: about 20 B presses to the overworld). - scene("shoes_from_aide", at(PEWTER, 46, 21, NORTH), "\"Oh, PLAYER!\" ... the Running Shoes; ends facing north"), - }); +StoryCheckpoint read_story_checkpoint_file(const JsonValue& value, std::string_view source){ + StoryCheckpoint checkpoint; + std::set note_keys; + const Pokemon::ExecutionReader read_execution = [&](const JsonObject& execution, std::string_view where){ + only_fields(execution, {"menu", "supplies", "lead", "notes"}, where); + checkpoint.menu = read_start_menu(execution.get_string_throw("menu", std::string(where)), where); + checkpoint.supplies = read_supplies(execution, where); + note_keys = read_note_keys(execution, where); + }; + static_cast(checkpoint) = Pokemon::read_authored_checkpoint( + value, "frlg", source, read_execution, story_action_specs() + ); + for (const std::string& key : note_keys){ + bool found = key == "checkpoint"; + for (const StoryStep& step : checkpoint.steps){ + found |= step.name == key; + } + if (!found){ + throw ParseException(std::format("{}: notes for unknown step {}", source, key)); + } + } + return checkpoint; } -} // namespace - - const std::vector& story_checkpoints(){ - static const std::vector checkpoints{ - new_game(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), - running_shoes(), - }; + static const std::vector checkpoints = []{ + std::vector result; + for (const auto& [name, text] : autostory_checkpoint_json()){ + result.push_back(read_story_checkpoint_file(parse_json(text), name)); + } + return result; + }(); return checkpoints; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index ab7731466e..d89e1dcf30 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -7,12 +7,31 @@ * every route and leg runs. Taken from a by-hand run on * console B (2026-11-01) and the pokefirered map scripts. * + * Each checkpoint is an authored JSON file in StoryData/ + * (frlg-.plan.json, format pokesim-authored-checkpoint/1): the shared + * checkpoint, its steps each an action with args, read against FRLG's + * actions (story_action_specs()), and FRLG's execution object: + * + * "menu" before_pokemon, before_pokedex or full: the START menu + * at its end (StoryCheckpoint::menu); + * "supplies" optional: {"potions", "antidotes", "parlyz_heals"} at + * its start, for a run that loads its save; + * "lead" optional: "after_brock", the starter as the story left + * it by Brock (story_lead_after_brock()); + * "notes" optional: {"checkpoint" or a step's id: [lines]}, the + * reasons behind a step that a reader of the file needs. + * The program doesn't read them. + * */ #ifndef PokemonAutomation_PokemonFRLG_AutoStoryTable_H #define PokemonAutomation_PokemonFRLG_AutoStoryTable_H +#include +#include +#include #include +#include "Common/Cpp/Json/JsonValue.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "PokemonFRLG_AutoStoryEvents.h" @@ -21,12 +40,23 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Checkpoints 00.01 to 00.10, in order. +// (name, JSON text) of each file in StoryData/, sorted by name. +// Generated at build time (SerialPrograms/cmake/EmbedTextFiles.cmake). +const std::vector>& autostory_checkpoint_json(); + +// The checkpoint of an authored FRLG file. Throws ParseException when +// the file is malformed, names an action FRLG doesn't have, gives an +// action args it doesn't take, or has notes for a step it doesn't have. +StoryCheckpoint read_story_checkpoint_file(const JsonValue& value, std::string_view source); + +// Checkpoints 00.01 to 00.10, in order: every file in StoryData/. const std::vector& story_checkpoints(); // Registers AutoStory table validation unit tests. void add_tests_AutoStory(UnitTestDatabase& database); +// The story files against the C++ rows they replace. +void add_tests_AutoStoryTableParity(UnitTestDatabase& database); // The table run end to end against a fake game (PokemonFRLG_AutoStorySimulation_Tests.cpp). void add_tests_AutoStorySimulation(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp new file mode 100644 index 0000000000..9b592aeed1 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp @@ -0,0 +1,344 @@ +/* AutoStory Table Parity Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The C++ rows the story table had before StoryData/, built with the + * shared step API, against the checkpoints read from the files: each + * loads to the same steps, args (with the fallbacks the reader fills in), + * poses, supplies and START menu. Removed with the C++ rows. + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Data/Pokemon_StoryStepJson.h" +#include "PokemonFRLG_AutoStoryParty.h" +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +constexpr Direction NORTH = Direction::NORTH; +constexpr Direction SOUTH = Direction::SOUTH; +constexpr Direction EAST = Direction::EAST; +constexpr Direction WEST = Direction::WEST; + +constexpr std::string_view BEDROOM = "PalletTown_PlayersHouse_2F"; +constexpr std::string_view PALLET = "PalletTown"; +constexpr std::string_view LAB = "PalletTown_ProfessorOaksLab"; +constexpr std::string_view VIRIDIAN = "ViridianCity"; +constexpr std::string_view VIRIDIAN_MART = "ViridianCity_Mart"; +constexpr std::string_view VIRIDIAN_CENTER = "ViridianCity_PokemonCenter_1F"; +constexpr std::string_view FOREST = "ViridianForest"; +constexpr std::string_view FOREST_GATE = "Route2_ViridianForest_NorthEntrance"; +constexpr std::string_view PEWTER = "PewterCity"; +constexpr std::string_view PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; +constexpr std::string_view GYM = "PewterCity_Gym"; + +Pokemon::GridPose at(std::string_view map, int x, int y, std::optional facing = std::nullopt){ + return Pokemon::GridPose{std::string(map), {{x, y}}, facing}; +} + +StoryCheckpoint row( + std::string id, std::string title, std::optional start, + Supplies supplies, StartMenu menu, std::vector steps +){ + StoryCheckpoint checkpoint; + checkpoint.id = std::move(id); + checkpoint.title = std::move(title); + checkpoint.start = std::move(start); + checkpoint.steps = std::move(steps); + checkpoint.supplies = supplies; + checkpoint.menu = menu; + return checkpoint; +} + +Supplies after_brock(){ + Supplies supplies; + supplies.lead = story_lead_after_brock(); + return supplies; +} + +// What a walk does about wild Pokemon: runs, or fights them for EXP. +enum class WildBattles{ + RUN, + FIGHT, +}; + +StoryStep make(StoryStepKind kind, std::string name, std::string why, Pokemon::StoryActionArgs args = {}){ + StoryStep step; + step.kind = kind; + step.name = std::move(name); + step.why = std::move(why); + step.args = std::move(args); + return step; +} + +StoryStep route(std::string name, Pokemon::GridPose target, std::string why, WildBattles wild = WildBattles::RUN){ + return make(StoryStepKind::ROUTE, std::move(name), std::move(why), { + {"target", std::move(target)}, {"fight_wild", wild == WildBattles::FIGHT}, + }); +} + +StoryStep step_into(std::string name, Direction direction, std::string why){ + return make(StoryStepKind::STEP, std::move(name), std::move(why), {{"direction", direction}}); +} + +StoryStep answer(std::string name, bool yes, std::string why){ + return make(StoryStepKind::ANSWER, std::move(name), std::move(why), {{"yes", yes}}); +} + +StoryStep scene(std::string name, std::optional pose_after, std::string why){ + StoryStep step = make(StoryStepKind::MASH, std::move(name), std::move(why)); + step.pose_after = std::move(pose_after); + return step; +} + +StoryStep battle(std::string name, Pokemon::GridPose pose_after, bool may_lose, std::string why){ + StoryStep step = make(StoryStepKind::BATTLE, std::move(name), std::move(why), {{"may_lose", may_lose}}); + step.pose_after = std::move(pose_after); + return step; +} + +StoryStep legs(std::string name, std::vector legs, std::string why, WildBattles wild = WildBattles::RUN){ + return make(StoryStepKind::LEGS, std::move(name), std::move(why), { + {"legs", std::move(legs)}, {"fight_wild", wild == WildBattles::FIGHT}, + }); +} + +StoryStep new_game_intro(Pokemon::GridPose pose_after, std::string why){ + StoryStep step = make(StoryStepKind::NEW_GAME, "intro", std::move(why)); + step.pose_after = std::move(pose_after); + return step; +} + +StoryStep talk(std::string name, std::string why){ + return make(StoryStepKind::TALK, std::move(name), std::move(why)); +} + +StoryStep ready(std::string name, Pokemon::GridPose nurse, std::string why){ + return make(StoryStepKind::READY, std::move(name), std::move(why), {{"target", std::move(nurse)}}); +} + +StoryStep heal(std::string name){ + return make(StoryStepKind::HEAL, std::move(name), "full HP"); +} + +StoryStep shop(std::string name, std::vector items, std::string why){ + return make(StoryStepKind::SHOP, std::move(name), std::move(why), {{"items", std::move(items)}}); +} + + +StoryCheckpoint new_game(){ + return row("00.01", "new game to the bedroom", std::nullopt, {}, StartMenu::BEFORE_POKEMON, { + // new_game.c: the bedroom at (6, 6), facing the TV. + new_game_intro(at(BEDROOM, 6, 6, NORTH), "Oak's speech, BOY, default names, rival GREEN"), + make(StoryStepKind::OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon"), + }); +} + +StoryCheckpoint leave_house(){ + return row("00.02", "bedroom to Pallet Town", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, { + route("front_door", at(PALLET, 6, 8), "down the stairs and out of the house"), + }); +} + +StoryCheckpoint oaks_trigger(){ + return row("00.03", "Oak stops the player and walks them to the lab", at(PALLET, 6, 8, SOUTH), {}, StartMenu::BEFORE_POKEMON, { + route("below_oaks_trigger", at(PALLET, 12, 2, NORTH), "below the north exit, short of Oak's trigger at (12, 1)"), + step_into("oaks_trigger", NORTH, "the trigger: \"Don't go out!\""), + // PlayerEnter walks the player up 8 tiles from the lab's door. + scene("to_the_lab", at(LAB, 6, 4, NORTH), "Oak walks the player into the lab; the scene ends at the table"), + }); +} + +StoryCheckpoint starter(){ + return row("00.04", "Squirtle, then the rival's battle", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEDEX, { + route("below_squirtle", at(LAB, 9, 5, NORTH), "under Squirtle's ball (9, 4)"), + talk("squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\""), + answer("choose_squirtle", true, "take Squirtle"), + answer("no_nickname", false, "\"give a nickname?\" NO"), + scene("rival_takes_bulbasaur", at(LAB, 9, 5, NORTH), "the rival picks his ball; the player still faces the table (console B, 2026-11-01)"), + route("above_rival_trigger", at(LAB, 7, 7, SOUTH), "short of the rival's trigger row 8"), + step_into("rival_trigger", SOUTH, "\"Wait, let's check out our POKEMON!\""), + // The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down. + battle("rival_battle", at(LAB, 7, 8, SOUTH), true, "the tutorial battle; losing goes on too"), + }); +} + +StoryCheckpoint parcel(){ + return row("00.05", "Route 1 to Viridian Mart: Oak's Parcel", at(LAB, 7, 8, SOUTH), {}, StartMenu::BEFORE_POKEDEX, { + route("below_mart_door", at(VIRIDIAN, 36, 20, NORTH), "Route 1, running from wild battles"), + step_into("mart_door", NORTH, "the clerk's scene starts on entering"), + // ApproachCounter: up 4 from the mat, then faces the clerk. + scene("parcel_from_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "the clerk gives OAK'S PARCEL"), + }); +} + +StoryCheckpoint pokedex(){ + return row("00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, { + route("below_oak", at(LAB, 6, 4, NORTH), "back down Route 1 to Oak"), + talk("give_parcel", "Oak takes the parcel"), + scene("pokedex_scene", at(LAB, 6, 4, SOUTH), "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)"), + }); +} + +StoryCheckpoint shopping(){ + return row("00.07", "Viridian shopping, then into Viridian Forest", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { + route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again"), + // 2000 of the 3000 a new game starts with, plus the rival's prize. + shop("potions_and_antidotes", {{"potion", 5}, {"antidote", 3}, {"parlyz_heal", 1}}, "5 Potions, 3 Antidotes, 1 Parlyz Heal"), + route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest"), + heal("heal_viridian"), + route("below_old_man_trigger", at(VIRIDIAN, 20, 9, NORTH), "short of the tutorial trigger (20, 8)"), + step_into("old_man_trigger", NORTH, "the old man's catching tutorial can't be walked around"), + // TutorialTriggerLeft turns the player right, to the old man. + scene("old_man_tutorial", at(VIRIDIAN, 20, 8, EAST), "about 60 lines and his demo battle; TEACHY TV"), + // After his demo the old man stands east of the player, beside (20, 8), where + // the map doesn't have him: "east 2" from there didn't move, and the walk north + // ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first. + route("past_old_man", at(VIRIDIAN, 20, 5, NORTH), "north along column 20, clear of the old man"), + // The gate's north warp lands on the forest's exit mat (29, 62), facing + // north. The save there keeps a forest failure from going back to Pallet. + route("forest_entrance", at(FOREST, 29, 62, NORTH), "Route 2 and the south gate, running from wild battles"), + }); +} + +StoryCheckpoint forest(){ + // The supplies bought in 00.07. + return row("00.08", "Viridian Forest to Pewter Center", at(FOREST, 29, 62, NORTH), {5, 3, 1}, StartMenu::FULL, { + // Wild battles are fought for EXP. Straight up the east side from the + // entrance, each leg ending on a wall (the Boy at (45, 58) stops the + // east one). Rick (47, 45) sees (42..46, 45), so the last leg meets + // his battle and is held on to its wall after it. The by-hand run's + // detour west to (13, 46) and back is dropped. + legs("forest_east", {{EAST, 1}, {NORTH, 4}, {EAST, 14}, {NORTH, 15}}, "up the east side to (44, 43)", WildBattles::FIGHT), + route("forest_north", at(FOREST, 39, 25), "north part", WildBattles::FIGHT), + // To the gate by legs that end on walls, which the walker holds again + // after a battle instead of estimating where it stopped: planned + // routes with open legs lost the player in the north of the forest + // (console B, 2026-11-01). The two 1-tile legs are single steps. + legs("forest_exit", { + {NORTH, 10}, {WEST, 12}, {SOUTH, 10}, {WEST, 6}, {NORTH, 20}, + {SOUTH, 1}, {WEST, 10}, {SOUTH, 27}, {WEST, 8}, {NORTH, 20}, {EAST, 1}, + }, "walls all the way to the gate's column", WildBattles::FIGHT), + route("forest_gate", at(FOREST_GATE, 7, 10, NORTH), "north onto the exit, arriving on the gate's mat", WildBattles::FIGHT), + // Out of the forest, wild battles are run from; trainers are still fought. + route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center"), + heal("heal_pewter"), + }); +} + +StoryCheckpoint brock(){ + // The by-hand save: 2 Potions and 1 Antidote left after the forest. + return row("00.09", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { + // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight + // 4) and sees (4..7, 8): walking north up column 6 from the door, + // the step onto (6, 8) starts his battle. He walks up to the player, + // who stays put and keeps facing north (FRLG doesn't turn the player + // to a trainer). That step is taken on its own, so no leg is cut. + route("below_liam_line", at(GYM, 6, 9, NORTH), "in by the door, up column 6 to below Liam's row"), + step_into("liam_line", NORTH, "onto (6, 8), in Liam's line"), + battle("camper_liam", at(GYM, 6, 8, NORTH), false, "Geodude and Sandshrew; EXP before Brock"), + // On to Brock unless red HP or a status is left that no item cures. + ready("ready_for_brock", at(PEWTER_CENTER, 7, 4, NORTH), "items for a status or low HP; the nurse only if they can't"), + route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5); Liam, beaten, stands at (5, 8)"), + talk("challenge_brock", "Brock's speech"), + battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39"), + }); +} + +StoryCheckpoint running_shoes(){ + return row("00.10", "Pewter: the Running Shoes from Oak's aide", at(GYM, 6, 6, NORTH), after_brock(), StartMenu::FULL, { + // Brock's win sets VAR_MAP_SCENE_PEWTER_CITY to 1 and shows the aide at + // (46, 20); his triggers are (46, 21..23) (PewterCity map.json). The + // Gym guide's triggers at (42..43, 21..23) need the scene at 0. + route("before_aide_trigger", at(PEWTER, 45, 21, EAST), "out of the Gym, east along row 21, short of the top trigger"), + step_into("aide_trigger", EAST, "onto (46, 21), below the aide"), + // RunningShoesAideTriggerTop: the aide talks from (46, 20), no YES/NO; + // the player only turns up. He walks off and is removed; FLAG_SYS_B_DASH + // is set (console B, 2026-11-02: about 20 B presses to the overworld). + scene("shoes_from_aide", at(PEWTER, 46, 21, NORTH), "\"Oh, PLAYER!\" ... the Running Shoes; ends facing north"), + }); +} + + +std::vector cpp_rows(){ + return { + new_game(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), + running_shoes(), + }; +} + +// Why `loaded` differs from `row`, or empty. Steps compare as their +// shared JSON, which writes every field. +std::string checkpoint_difference(const StoryCheckpoint& row, const StoryCheckpoint& loaded){ + const std::string row_json = Pokemon::story_checkpoint_json(row).dump(); + const std::string loaded_json = Pokemon::story_checkpoint_json(loaded).dump(); + if (row_json != loaded_json){ + return std::format("{}: the file loads to\n{}\nbut the C++ row is\n{}", row.id, loaded_json, row_json); + } + if (row.menu != loaded.menu){ + return row.id + ": a different START menu."; + } + const Supplies& a = row.supplies; + const Supplies& b = loaded.supplies; + if (a.potions != b.potions || a.antidotes != b.antidotes || a.parlyz_heals != b.parlyz_heals){ + return row.id + ": different supplies."; + } + if (a.lead.species != b.lead.species || a.lead.level != b.lead.level || a.lead.moves.size() != b.lead.moves.size()){ + return row.id + ": a different lead."; + } + for (size_t c = 0; c < a.lead.moves.size(); c++){ + if (a.lead.moves[c].move != b.lead.moves[c].move || a.lead.moves[c].pp != b.lead.moves[c].pp){ + return row.id + ": a different lead move " + std::to_string(c + 1) + "."; + } + } + return ""; +} + +class Test_AutoStoryTableParity : public UnitTest{ +public: + Test_AutoStoryTableParity() + : UnitTest("PokemonFRLG::AutoStory - the story files load to the C++ rows") + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + const std::vector rows = cpp_rows(); + const std::vector& loaded = story_checkpoints(); + if (rows.size() != loaded.size()){ + return std::format("{} C++ rows, {} files.", rows.size(), loaded.size()); + } + for (size_t c = 0; c < rows.size(); c++){ + const std::string difference = checkpoint_difference(rows[c], loaded[c]); + if (!difference.empty()){ + return difference; + } + } + return true; + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } +}; + +} // namespace + + +void add_tests_AutoStoryTableParity(UnitTestDatabase& database){ + database.add(); +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index ee7c0f43c7..9aa3be8596 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -84,7 +84,8 @@ std::string describe(const StoryPose& pose){ } // A table pose as a StoryPose; FRLG's table has one-tile poses only. -StoryPose one_tile(const Pokemon::Pose& pose){ +StoryPose one_tile(const Pokemon::GridPose& grid_pose){ + const Pokemon::Pose pose = Pokemon::pose_of(grid_pose); const std::optional ret = story_pose(pose); if (!ret){ throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Not a one-tile pose: " + Pokemon::to_string(pose)); @@ -138,7 +139,7 @@ UnitTestResult check_held_legs(const std::string& name, const std::vector> route = fixed_route(story_maps(), MapPosition{pose.map, pose.tile}, step.legs); + const std::optional> route = fixed_route(story_maps(), MapPosition{pose.map, pose.tile}, Pokemon::story_arg>(step.args, "legs")); if (!route || route->empty()){ return step.name + ": the legs can't be walked from " + describe(pose) + "."; } @@ -163,10 +164,7 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step){ return step.name + ": the facing is unknown at " + describe(pose) + " and no wall is beside it."; } } - if (!step.target){ - return step.name + ": no target."; - } - const StoryPose target = one_tile(*step.target); + const StoryPose target = one_tile(Pokemon::story_arg(step.args, "target")); const RouteGoal goal{{target.map, target.tile}, target.facing}; const std::optional> route = plan_overworld_route(story_maps(), start, goal, default_route_costs(), facing); if (!route){ @@ -214,7 +212,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po return checkpoint.id + " " + result.message; } }else if (step.kind == StoryStepKind::STEP){ - pose = StoryPose{pose.map, pose.tile.next(step.direction), step.direction}; + const Direction direction = Pokemon::story_arg(step.args, "direction"); + pose = StoryPose{pose.map, pose.tile.next(direction), direction}; } if (step.pose_after){ pose = one_tile(*step.pose_after); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01.plan.json new file mode 100644 index 0000000000..31eea5b1d0 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01.plan.json @@ -0,0 +1,29 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.01", + "title": "new game to the bedroom", + "events": [ + { + "id": "intro", + "kind": "new_game", + "declared_after": {"map": "PalletTown_PlayersHouse_2F", "tiles": [[6, 6]], "facing": "north"}, + "why": "Oak's speech, BOY, default names, rival GREEN" + }, + { + "id": "options", + "kind": "options", + "why": "fast text; no switch prompt between a trainer's Pokemon" + } + ] + }, + "execution": { + "menu": "before_pokemon", + "notes": { + "intro": [ + "new_game.c: the bedroom at (6, 6), facing the TV." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.02.plan.json new file mode 100644 index 0000000000..2f09e7db16 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.02.plan.json @@ -0,0 +1,22 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.02", + "title": "bedroom to Pallet Town", + "start": {"map": "PalletTown_PlayersHouse_2F", "tiles": [[6, 6]], "facing": "north"}, + "events": [ + { + "id": "front_door", + "kind": "route", + "args": { + "target": {"map": "PalletTown", "tiles": [[6, 8]]} + }, + "why": "down the stairs and out of the house" + } + ] + }, + "execution": { + "menu": "before_pokemon" + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.03.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.03.plan.json new file mode 100644 index 0000000000..b44478b878 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.03.plan.json @@ -0,0 +1,41 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.03", + "title": "Oak stops the player and walks them to the lab", + "start": {"map": "PalletTown", "tiles": [[6, 8]], "facing": "south"}, + "events": [ + { + "id": "below_oaks_trigger", + "kind": "route", + "args": { + "target": {"map": "PalletTown", "tiles": [[12, 2]], "facing": "north"} + }, + "why": "below the north exit, short of Oak's trigger at (12, 1)" + }, + { + "id": "oaks_trigger", + "kind": "step", + "args": { + "direction": "north" + }, + "why": "the trigger: \"Don't go out!\"" + }, + { + "id": "to_the_lab", + "kind": "scene", + "declared_after": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[6, 4]], "facing": "north"}, + "why": "Oak walks the player into the lab; the scene ends at the table" + } + ] + }, + "execution": { + "menu": "before_pokemon", + "notes": { + "to_the_lab": [ + "PlayerEnter walks the player up 8 tiles from the lab's door." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json new file mode 100644 index 0000000000..af5c28173a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json @@ -0,0 +1,76 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.04", + "title": "Squirtle, then the rival's battle", + "start": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[6, 4]], "facing": "north"}, + "events": [ + { + "id": "below_squirtle", + "kind": "route", + "args": { + "target": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[9, 5]], "facing": "north"} + }, + "why": "under Squirtle's ball (9, 4)" + }, + { + "id": "squirtle_ball", + "kind": "talk", + "why": "\"So, you want the WATER POKEMON SQUIRTLE?\"" + }, + { + "id": "choose_squirtle", + "kind": "answer", + "why": "take Squirtle" + }, + { + "id": "no_nickname", + "kind": "answer", + "args": { + "yes": false + }, + "why": "\"give a nickname?\" NO" + }, + { + "id": "rival_takes_bulbasaur", + "kind": "scene", + "declared_after": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[9, 5]], "facing": "north"}, + "why": "the rival picks his ball; the player still faces the table (console B, 2026-11-01)" + }, + { + "id": "above_rival_trigger", + "kind": "route", + "args": { + "target": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[7, 7]], "facing": "south"} + }, + "why": "short of the rival's trigger row 8" + }, + { + "id": "rival_trigger", + "kind": "step", + "args": { + "direction": "south" + }, + "why": "\"Wait, let's check out our POKEMON!\"" + }, + { + "id": "rival_battle", + "kind": "battle", + "args": { + "may_lose": true + }, + "declared_after": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[7, 8]], "facing": "south"}, + "why": "the tutorial battle; losing goes on too" + } + ] + }, + "execution": { + "menu": "before_pokedex", + "notes": { + "rival_battle": [ + "The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.05.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.05.plan.json new file mode 100644 index 0000000000..d3923d0565 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.05.plan.json @@ -0,0 +1,41 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.05", + "title": "Route 1 to Viridian Mart: Oak's Parcel", + "start": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[7, 8]], "facing": "south"}, + "events": [ + { + "id": "below_mart_door", + "kind": "route", + "args": { + "target": {"map": "ViridianCity", "tiles": [[36, 20]], "facing": "north"} + }, + "why": "Route 1, running from wild battles" + }, + { + "id": "mart_door", + "kind": "step", + "args": { + "direction": "north" + }, + "why": "the clerk's scene starts on entering" + }, + { + "id": "parcel_from_clerk", + "kind": "scene", + "declared_after": {"map": "ViridianCity_Mart", "tiles": [[4, 3]], "facing": "west"}, + "why": "the clerk gives OAK'S PARCEL" + } + ] + }, + "execution": { + "menu": "before_pokedex", + "notes": { + "parcel_from_clerk": [ + "ApproachCounter: up 4 from the mat, then faces the clerk." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.06.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.06.plan.json new file mode 100644 index 0000000000..431917879d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.06.plan.json @@ -0,0 +1,33 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.06", + "title": "Oak's Parcel to the Pokedex", + "start": {"map": "ViridianCity_Mart", "tiles": [[4, 3]], "facing": "west"}, + "events": [ + { + "id": "below_oak", + "kind": "route", + "args": { + "target": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[6, 4]], "facing": "north"} + }, + "why": "back down Route 1 to Oak" + }, + { + "id": "give_parcel", + "kind": "talk", + "why": "Oak takes the parcel" + }, + { + "id": "pokedex_scene", + "kind": "scene", + "declared_after": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[6, 4]], "facing": "south"}, + "why": "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)" + } + ] + }, + "execution": { + "menu": "full" + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.07.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.07.plan.json new file mode 100644 index 0000000000..4abe1885aa --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.07.plan.json @@ -0,0 +1,95 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.07", + "title": "Viridian shopping, then into Viridian Forest", + "start": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[6, 4]], "facing": "south"}, + "events": [ + { + "id": "mart_clerk", + "kind": "route", + "args": { + "target": {"map": "ViridianCity_Mart", "tiles": [[4, 3]], "facing": "west"} + }, + "why": "Route 1 again" + }, + { + "id": "potions_and_antidotes", + "kind": "shop", + "args": { + "items": [{"item": "potion", "quantity": 5}, {"item": "antidote", "quantity": 3}, {"item": "parlyz_heal", "quantity": 1}] + }, + "why": "5 Potions, 3 Antidotes, 1 Parlyz Heal" + }, + { + "id": "viridian_nurse", + "kind": "route", + "args": { + "target": {"map": "ViridianCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "heal before the forest" + }, + { + "id": "heal_viridian", + "kind": "heal", + "why": "full HP" + }, + { + "id": "below_old_man_trigger", + "kind": "route", + "args": { + "target": {"map": "ViridianCity", "tiles": [[20, 9]], "facing": "north"} + }, + "why": "short of the tutorial trigger (20, 8)" + }, + { + "id": "old_man_trigger", + "kind": "step", + "args": { + "direction": "north" + }, + "why": "the old man's catching tutorial can't be walked around" + }, + { + "id": "old_man_tutorial", + "kind": "scene", + "declared_after": {"map": "ViridianCity", "tiles": [[20, 8]], "facing": "east"}, + "why": "about 60 lines and his demo battle; TEACHY TV" + }, + { + "id": "past_old_man", + "kind": "route", + "args": { + "target": {"map": "ViridianCity", "tiles": [[20, 5]], "facing": "north"} + }, + "why": "north along column 20, clear of the old man" + }, + { + "id": "forest_entrance", + "kind": "route", + "args": { + "target": {"map": "ViridianForest", "tiles": [[29, 62]], "facing": "north"} + }, + "why": "Route 2 and the south gate, running from wild battles" + } + ] + }, + "execution": { + "menu": "full", + "notes": { + "potions_and_antidotes": [ + "2000 of the 3000 a new game starts with, plus the rival's prize." + ], + "old_man_tutorial": [ + "TutorialTriggerLeft turns the player right, to the old man." + ], + "past_old_man": [ + "After his demo the old man stands east of the player, beside (20, 8), where the map doesn't have him: \"east 2\" from there didn't move, and the walk north ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first." + ], + "forest_entrance": [ + "The gate's north warp lands on the forest's exit mat (29, 62), facing north. The save there keeps a forest failure from going back to Pallet." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.08.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.08.plan.json new file mode 100644 index 0000000000..c02e6e877f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.08.plan.json @@ -0,0 +1,82 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.08", + "title": "Viridian Forest to Pewter Center", + "start": {"map": "ViridianForest", "tiles": [[29, 62]], "facing": "north"}, + "events": [ + { + "id": "forest_east", + "kind": "legs", + "args": { + "legs": [{"direction": "east", "tiles": 1}, {"direction": "north", "tiles": 4}, {"direction": "east", "tiles": 14}, {"direction": "north", "tiles": 15}], + "fight_wild": true + }, + "why": "up the east side to (44, 43)" + }, + { + "id": "forest_north", + "kind": "route", + "args": { + "target": {"map": "ViridianForest", "tiles": [[39, 25]]}, + "fight_wild": true + }, + "why": "north part" + }, + { + "id": "forest_exit", + "kind": "legs", + "args": { + "legs": [{"direction": "north", "tiles": 10}, {"direction": "west", "tiles": 12}, {"direction": "south", "tiles": 10}, {"direction": "west", "tiles": 6}, {"direction": "north", "tiles": 20}, {"direction": "south", "tiles": 1}, {"direction": "west", "tiles": 10}, {"direction": "south", "tiles": 27}, {"direction": "west", "tiles": 8}, {"direction": "north", "tiles": 20}, {"direction": "east", "tiles": 1}], + "fight_wild": true + }, + "why": "walls all the way to the gate's column" + }, + { + "id": "forest_gate", + "kind": "route", + "args": { + "target": {"map": "Route2_ViridianForest_NorthEntrance", "tiles": [[7, 10]], "facing": "north"}, + "fight_wild": true + }, + "why": "north onto the exit, arriving on the gate's mat" + }, + { + "id": "pewter_nurse", + "kind": "route", + "args": { + "target": {"map": "PewterCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "Route 2 north to Pewter's Center" + }, + { + "id": "heal_pewter", + "kind": "heal", + "why": "full HP" + } + ] + }, + "execution": { + "menu": "full", + "supplies": { + "potions": 5, + "antidotes": 3, + "parlyz_heals": 1 + }, + "notes": { + "checkpoint": [ + "The supplies bought in 00.07." + ], + "forest_east": [ + "Wild battles are fought for EXP. Straight up the east side from the entrance, each leg ending on a wall (the Boy at (45, 58) stops the east one). Rick (47, 45) sees (42..46, 45), so the last leg meets his battle and is held on to its wall after it. The by-hand run's detour west to (13, 46) and back is dropped." + ], + "forest_exit": [ + "To the gate by legs that end on walls, which the walker holds again after a battle instead of estimating where it stopped: planned routes with open legs lost the player in the north of the forest (console B, 2026-11-01). The two 1-tile legs are single steps." + ], + "pewter_nurse": [ + "Out of the forest, wild battles are run from; trainers are still fought." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json new file mode 100644 index 0000000000..28b36cc3e4 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json @@ -0,0 +1,79 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.09", + "title": "Pewter Gym: Camper Liam, then Brock", + "start": {"map": "PewterCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"}, + "events": [ + { + "id": "below_liam_line", + "kind": "route", + "args": { + "target": {"map": "PewterCity_Gym", "tiles": [[6, 9]], "facing": "north"} + }, + "why": "in by the door, up column 6 to below Liam's row" + }, + { + "id": "liam_line", + "kind": "step", + "args": { + "direction": "north" + }, + "why": "onto (6, 8), in Liam's line" + }, + { + "id": "camper_liam", + "kind": "battle", + "declared_after": {"map": "PewterCity_Gym", "tiles": [[6, 8]], "facing": "north"}, + "why": "Geodude and Sandshrew; EXP before Brock" + }, + { + "id": "ready_for_brock", + "kind": "ready", + "args": { + "target": {"map": "PewterCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "items for a status or low HP; the nurse only if they can't" + }, + { + "id": "before_brock", + "kind": "route", + "args": { + "target": {"map": "PewterCity_Gym", "tiles": [[6, 6]], "facing": "north"} + }, + "why": "below Brock (6, 5); Liam, beaten, stands at (5, 8)" + }, + { + "id": "challenge_brock", + "kind": "talk", + "why": "Brock's speech" + }, + { + "id": "brock", + "kind": "battle", + "declared_after": {"map": "PewterCity_Gym", "tiles": [[6, 6]], "facing": "north"}, + "why": "Geodude and Onix, with Bubble; Boulder Badge and TM39" + } + ] + }, + "execution": { + "menu": "full", + "supplies": { + "potions": 2, + "antidotes": 1, + "parlyz_heals": 0 + }, + "notes": { + "checkpoint": [ + "The by-hand save: 2 Potions and 1 Antidote left after the forest." + ], + "below_liam_line": [ + "Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight 4) and sees (4..7, 8): walking north up column 6 from the door, the step onto (6, 8) starts his battle. He walks up to the player, who stays put and keeps facing north (FRLG doesn't turn the player to a trainer). That step is taken on its own, so no leg is cut." + ], + "ready_for_brock": [ + "On to Brock unless red HP or a status is left that no item cures." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.10.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.10.plan.json new file mode 100644 index 0000000000..b8cf6a8ccd --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.10.plan.json @@ -0,0 +1,48 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.10", + "title": "Pewter: the Running Shoes from Oak's aide", + "start": {"map": "PewterCity_Gym", "tiles": [[6, 6]], "facing": "north"}, + "events": [ + { + "id": "before_aide_trigger", + "kind": "route", + "args": { + "target": {"map": "PewterCity", "tiles": [[45, 21]], "facing": "east"} + }, + "why": "out of the Gym, east along row 21, short of the top trigger" + }, + { + "id": "aide_trigger", + "kind": "step", + "args": { + "direction": "east" + }, + "why": "onto (46, 21), below the aide" + }, + { + "id": "shoes_from_aide", + "kind": "scene", + "declared_after": {"map": "PewterCity", "tiles": [[46, 21]], "facing": "north"}, + "why": "\"Oh, PLAYER!\" ... the Running Shoes; ends facing north" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "At the rows after Brock: no items counted, the starter with the moves the story gave it by Lv13. A run that loads a save reads the moves off the lead's summary instead (read_lead_moves()), so a save whose moves differ from these (console B, 2026-11-02: Water Gun where Tackle was) is fought with the moves it has." + ], + "before_aide_trigger": [ + "Brock's win sets VAR_MAP_SCENE_PEWTER_CITY to 1 and shows the aide at (46, 20); his triggers are (46, 21..23) (PewterCity map.json). The Gym guide's triggers at (42..43, 21..23) need the scene at 0." + ], + "shoes_from_aide": [ + "RunningShoesAideTriggerTop: the aide talks from (46, 20), no YES/NO; the player only turns up. He walks off and is removed; FLAG_SYS_B_DASH is set (console B, 2026-11-02: about 20 B presses to the overworld)." + ] + } + } +} diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 9de1bf1a1f..cb22d12626 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1947,6 +1947,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp From 3f0b338f11daad2b62feae9ecccc12791313815a Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 09:59:00 -0800 Subject: [PATCH 22/29] FRLG AutoStory: delete the C++ story rows, parity proven The previous commit's parity test passed: every StoryData file loads to its old C++ row. The rows and the test go; StoryData/ is the table. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 1 - .../AutoStory/PokemonFRLG_AutoStoryTable.h | 2 - ...PokemonFRLG_AutoStoryTableParity_Tests.cpp | 344 ------------------ SerialPrograms/cmake/SourceFiles.cmake | 1 - 4 files changed, 348 deletions(-) delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 4a5a0b5310..cea4ff7bc9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -319,7 +319,6 @@ void add_tests(UnitTestDatabase& database){ add_tests_OverworldRecovery(database); add_tests_PlayerFacingReader(database); add_tests_AutoStory(database); - add_tests_AutoStoryTableParity(database); add_tests_AutoStoryExport(database); add_tests_AutoStorySimulation(database); add_tests_AutoStoryItems(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index d89e1dcf30..99d5ed45d4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -55,8 +55,6 @@ const std::vector& story_checkpoints(); // Registers AutoStory table validation unit tests. void add_tests_AutoStory(UnitTestDatabase& database); -// The story files against the C++ rows they replace. -void add_tests_AutoStoryTableParity(UnitTestDatabase& database); // The table run end to end against a fake game (PokemonFRLG_AutoStorySimulation_Tests.cpp). void add_tests_AutoStorySimulation(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp deleted file mode 100644 index 9b592aeed1..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp +++ /dev/null @@ -1,344 +0,0 @@ -/* AutoStory Table Parity Tests - * - * From: https://github.com/PokemonAutomation/ - * - * The C++ rows the story table had before StoryData/, built with the - * shared step API, against the checkpoints read from the files: each - * loads to the same steps, args (with the fallbacks the reader fills in), - * poses, supplies and START menu. Removed with the C++ rows. - * - */ - -#include -#include -#include -#include -#include "Common/Cpp/Exceptions.h" -#include "Common/Cpp/TestRunners/UnitTest.h" -#include "Pokemon/AutoStory/Data/Pokemon_StoryStepJson.h" -#include "PokemonFRLG_AutoStoryParty.h" -#include "PokemonFRLG_AutoStoryTable.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -namespace{ - -constexpr Direction NORTH = Direction::NORTH; -constexpr Direction SOUTH = Direction::SOUTH; -constexpr Direction EAST = Direction::EAST; -constexpr Direction WEST = Direction::WEST; - -constexpr std::string_view BEDROOM = "PalletTown_PlayersHouse_2F"; -constexpr std::string_view PALLET = "PalletTown"; -constexpr std::string_view LAB = "PalletTown_ProfessorOaksLab"; -constexpr std::string_view VIRIDIAN = "ViridianCity"; -constexpr std::string_view VIRIDIAN_MART = "ViridianCity_Mart"; -constexpr std::string_view VIRIDIAN_CENTER = "ViridianCity_PokemonCenter_1F"; -constexpr std::string_view FOREST = "ViridianForest"; -constexpr std::string_view FOREST_GATE = "Route2_ViridianForest_NorthEntrance"; -constexpr std::string_view PEWTER = "PewterCity"; -constexpr std::string_view PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; -constexpr std::string_view GYM = "PewterCity_Gym"; - -Pokemon::GridPose at(std::string_view map, int x, int y, std::optional facing = std::nullopt){ - return Pokemon::GridPose{std::string(map), {{x, y}}, facing}; -} - -StoryCheckpoint row( - std::string id, std::string title, std::optional start, - Supplies supplies, StartMenu menu, std::vector steps -){ - StoryCheckpoint checkpoint; - checkpoint.id = std::move(id); - checkpoint.title = std::move(title); - checkpoint.start = std::move(start); - checkpoint.steps = std::move(steps); - checkpoint.supplies = supplies; - checkpoint.menu = menu; - return checkpoint; -} - -Supplies after_brock(){ - Supplies supplies; - supplies.lead = story_lead_after_brock(); - return supplies; -} - -// What a walk does about wild Pokemon: runs, or fights them for EXP. -enum class WildBattles{ - RUN, - FIGHT, -}; - -StoryStep make(StoryStepKind kind, std::string name, std::string why, Pokemon::StoryActionArgs args = {}){ - StoryStep step; - step.kind = kind; - step.name = std::move(name); - step.why = std::move(why); - step.args = std::move(args); - return step; -} - -StoryStep route(std::string name, Pokemon::GridPose target, std::string why, WildBattles wild = WildBattles::RUN){ - return make(StoryStepKind::ROUTE, std::move(name), std::move(why), { - {"target", std::move(target)}, {"fight_wild", wild == WildBattles::FIGHT}, - }); -} - -StoryStep step_into(std::string name, Direction direction, std::string why){ - return make(StoryStepKind::STEP, std::move(name), std::move(why), {{"direction", direction}}); -} - -StoryStep answer(std::string name, bool yes, std::string why){ - return make(StoryStepKind::ANSWER, std::move(name), std::move(why), {{"yes", yes}}); -} - -StoryStep scene(std::string name, std::optional pose_after, std::string why){ - StoryStep step = make(StoryStepKind::MASH, std::move(name), std::move(why)); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep battle(std::string name, Pokemon::GridPose pose_after, bool may_lose, std::string why){ - StoryStep step = make(StoryStepKind::BATTLE, std::move(name), std::move(why), {{"may_lose", may_lose}}); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep legs(std::string name, std::vector legs, std::string why, WildBattles wild = WildBattles::RUN){ - return make(StoryStepKind::LEGS, std::move(name), std::move(why), { - {"legs", std::move(legs)}, {"fight_wild", wild == WildBattles::FIGHT}, - }); -} - -StoryStep new_game_intro(Pokemon::GridPose pose_after, std::string why){ - StoryStep step = make(StoryStepKind::NEW_GAME, "intro", std::move(why)); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep talk(std::string name, std::string why){ - return make(StoryStepKind::TALK, std::move(name), std::move(why)); -} - -StoryStep ready(std::string name, Pokemon::GridPose nurse, std::string why){ - return make(StoryStepKind::READY, std::move(name), std::move(why), {{"target", std::move(nurse)}}); -} - -StoryStep heal(std::string name){ - return make(StoryStepKind::HEAL, std::move(name), "full HP"); -} - -StoryStep shop(std::string name, std::vector items, std::string why){ - return make(StoryStepKind::SHOP, std::move(name), std::move(why), {{"items", std::move(items)}}); -} - - -StoryCheckpoint new_game(){ - return row("00.01", "new game to the bedroom", std::nullopt, {}, StartMenu::BEFORE_POKEMON, { - // new_game.c: the bedroom at (6, 6), facing the TV. - new_game_intro(at(BEDROOM, 6, 6, NORTH), "Oak's speech, BOY, default names, rival GREEN"), - make(StoryStepKind::OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon"), - }); -} - -StoryCheckpoint leave_house(){ - return row("00.02", "bedroom to Pallet Town", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, { - route("front_door", at(PALLET, 6, 8), "down the stairs and out of the house"), - }); -} - -StoryCheckpoint oaks_trigger(){ - return row("00.03", "Oak stops the player and walks them to the lab", at(PALLET, 6, 8, SOUTH), {}, StartMenu::BEFORE_POKEMON, { - route("below_oaks_trigger", at(PALLET, 12, 2, NORTH), "below the north exit, short of Oak's trigger at (12, 1)"), - step_into("oaks_trigger", NORTH, "the trigger: \"Don't go out!\""), - // PlayerEnter walks the player up 8 tiles from the lab's door. - scene("to_the_lab", at(LAB, 6, 4, NORTH), "Oak walks the player into the lab; the scene ends at the table"), - }); -} - -StoryCheckpoint starter(){ - return row("00.04", "Squirtle, then the rival's battle", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEDEX, { - route("below_squirtle", at(LAB, 9, 5, NORTH), "under Squirtle's ball (9, 4)"), - talk("squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\""), - answer("choose_squirtle", true, "take Squirtle"), - answer("no_nickname", false, "\"give a nickname?\" NO"), - scene("rival_takes_bulbasaur", at(LAB, 9, 5, NORTH), "the rival picks his ball; the player still faces the table (console B, 2026-11-01)"), - route("above_rival_trigger", at(LAB, 7, 7, SOUTH), "short of the rival's trigger row 8"), - step_into("rival_trigger", SOUTH, "\"Wait, let's check out our POKEMON!\""), - // The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down. - battle("rival_battle", at(LAB, 7, 8, SOUTH), true, "the tutorial battle; losing goes on too"), - }); -} - -StoryCheckpoint parcel(){ - return row("00.05", "Route 1 to Viridian Mart: Oak's Parcel", at(LAB, 7, 8, SOUTH), {}, StartMenu::BEFORE_POKEDEX, { - route("below_mart_door", at(VIRIDIAN, 36, 20, NORTH), "Route 1, running from wild battles"), - step_into("mart_door", NORTH, "the clerk's scene starts on entering"), - // ApproachCounter: up 4 from the mat, then faces the clerk. - scene("parcel_from_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "the clerk gives OAK'S PARCEL"), - }); -} - -StoryCheckpoint pokedex(){ - return row("00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, { - route("below_oak", at(LAB, 6, 4, NORTH), "back down Route 1 to Oak"), - talk("give_parcel", "Oak takes the parcel"), - scene("pokedex_scene", at(LAB, 6, 4, SOUTH), "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)"), - }); -} - -StoryCheckpoint shopping(){ - return row("00.07", "Viridian shopping, then into Viridian Forest", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { - route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again"), - // 2000 of the 3000 a new game starts with, plus the rival's prize. - shop("potions_and_antidotes", {{"potion", 5}, {"antidote", 3}, {"parlyz_heal", 1}}, "5 Potions, 3 Antidotes, 1 Parlyz Heal"), - route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest"), - heal("heal_viridian"), - route("below_old_man_trigger", at(VIRIDIAN, 20, 9, NORTH), "short of the tutorial trigger (20, 8)"), - step_into("old_man_trigger", NORTH, "the old man's catching tutorial can't be walked around"), - // TutorialTriggerLeft turns the player right, to the old man. - scene("old_man_tutorial", at(VIRIDIAN, 20, 8, EAST), "about 60 lines and his demo battle; TEACHY TV"), - // After his demo the old man stands east of the player, beside (20, 8), where - // the map doesn't have him: "east 2" from there didn't move, and the walk north - // ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first. - route("past_old_man", at(VIRIDIAN, 20, 5, NORTH), "north along column 20, clear of the old man"), - // The gate's north warp lands on the forest's exit mat (29, 62), facing - // north. The save there keeps a forest failure from going back to Pallet. - route("forest_entrance", at(FOREST, 29, 62, NORTH), "Route 2 and the south gate, running from wild battles"), - }); -} - -StoryCheckpoint forest(){ - // The supplies bought in 00.07. - return row("00.08", "Viridian Forest to Pewter Center", at(FOREST, 29, 62, NORTH), {5, 3, 1}, StartMenu::FULL, { - // Wild battles are fought for EXP. Straight up the east side from the - // entrance, each leg ending on a wall (the Boy at (45, 58) stops the - // east one). Rick (47, 45) sees (42..46, 45), so the last leg meets - // his battle and is held on to its wall after it. The by-hand run's - // detour west to (13, 46) and back is dropped. - legs("forest_east", {{EAST, 1}, {NORTH, 4}, {EAST, 14}, {NORTH, 15}}, "up the east side to (44, 43)", WildBattles::FIGHT), - route("forest_north", at(FOREST, 39, 25), "north part", WildBattles::FIGHT), - // To the gate by legs that end on walls, which the walker holds again - // after a battle instead of estimating where it stopped: planned - // routes with open legs lost the player in the north of the forest - // (console B, 2026-11-01). The two 1-tile legs are single steps. - legs("forest_exit", { - {NORTH, 10}, {WEST, 12}, {SOUTH, 10}, {WEST, 6}, {NORTH, 20}, - {SOUTH, 1}, {WEST, 10}, {SOUTH, 27}, {WEST, 8}, {NORTH, 20}, {EAST, 1}, - }, "walls all the way to the gate's column", WildBattles::FIGHT), - route("forest_gate", at(FOREST_GATE, 7, 10, NORTH), "north onto the exit, arriving on the gate's mat", WildBattles::FIGHT), - // Out of the forest, wild battles are run from; trainers are still fought. - route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center"), - heal("heal_pewter"), - }); -} - -StoryCheckpoint brock(){ - // The by-hand save: 2 Potions and 1 Antidote left after the forest. - return row("00.09", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { - // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight - // 4) and sees (4..7, 8): walking north up column 6 from the door, - // the step onto (6, 8) starts his battle. He walks up to the player, - // who stays put and keeps facing north (FRLG doesn't turn the player - // to a trainer). That step is taken on its own, so no leg is cut. - route("below_liam_line", at(GYM, 6, 9, NORTH), "in by the door, up column 6 to below Liam's row"), - step_into("liam_line", NORTH, "onto (6, 8), in Liam's line"), - battle("camper_liam", at(GYM, 6, 8, NORTH), false, "Geodude and Sandshrew; EXP before Brock"), - // On to Brock unless red HP or a status is left that no item cures. - ready("ready_for_brock", at(PEWTER_CENTER, 7, 4, NORTH), "items for a status or low HP; the nurse only if they can't"), - route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5); Liam, beaten, stands at (5, 8)"), - talk("challenge_brock", "Brock's speech"), - battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39"), - }); -} - -StoryCheckpoint running_shoes(){ - return row("00.10", "Pewter: the Running Shoes from Oak's aide", at(GYM, 6, 6, NORTH), after_brock(), StartMenu::FULL, { - // Brock's win sets VAR_MAP_SCENE_PEWTER_CITY to 1 and shows the aide at - // (46, 20); his triggers are (46, 21..23) (PewterCity map.json). The - // Gym guide's triggers at (42..43, 21..23) need the scene at 0. - route("before_aide_trigger", at(PEWTER, 45, 21, EAST), "out of the Gym, east along row 21, short of the top trigger"), - step_into("aide_trigger", EAST, "onto (46, 21), below the aide"), - // RunningShoesAideTriggerTop: the aide talks from (46, 20), no YES/NO; - // the player only turns up. He walks off and is removed; FLAG_SYS_B_DASH - // is set (console B, 2026-11-02: about 20 B presses to the overworld). - scene("shoes_from_aide", at(PEWTER, 46, 21, NORTH), "\"Oh, PLAYER!\" ... the Running Shoes; ends facing north"), - }); -} - - -std::vector cpp_rows(){ - return { - new_game(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), - running_shoes(), - }; -} - -// Why `loaded` differs from `row`, or empty. Steps compare as their -// shared JSON, which writes every field. -std::string checkpoint_difference(const StoryCheckpoint& row, const StoryCheckpoint& loaded){ - const std::string row_json = Pokemon::story_checkpoint_json(row).dump(); - const std::string loaded_json = Pokemon::story_checkpoint_json(loaded).dump(); - if (row_json != loaded_json){ - return std::format("{}: the file loads to\n{}\nbut the C++ row is\n{}", row.id, loaded_json, row_json); - } - if (row.menu != loaded.menu){ - return row.id + ": a different START menu."; - } - const Supplies& a = row.supplies; - const Supplies& b = loaded.supplies; - if (a.potions != b.potions || a.antidotes != b.antidotes || a.parlyz_heals != b.parlyz_heals){ - return row.id + ": different supplies."; - } - if (a.lead.species != b.lead.species || a.lead.level != b.lead.level || a.lead.moves.size() != b.lead.moves.size()){ - return row.id + ": a different lead."; - } - for (size_t c = 0; c < a.lead.moves.size(); c++){ - if (a.lead.moves[c].move != b.lead.moves[c].move || a.lead.moves[c].pp != b.lead.moves[c].pp){ - return row.id + ": a different lead move " + std::to_string(c + 1) + "."; - } - } - return ""; -} - -class Test_AutoStoryTableParity : public UnitTest{ -public: - Test_AutoStoryTableParity() - : UnitTest("PokemonFRLG::AutoStory - the story files load to the C++ rows") - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - try{ - const std::vector rows = cpp_rows(); - const std::vector& loaded = story_checkpoints(); - if (rows.size() != loaded.size()){ - return std::format("{} C++ rows, {} files.", rows.size(), loaded.size()); - } - for (size_t c = 0; c < rows.size(); c++){ - const std::string difference = checkpoint_difference(rows[c], loaded[c]); - if (!difference.empty()){ - return difference; - } - } - return true; - }catch (Exception& e){ - return std::string(e.name()) + ": " + e.message(); - } - } -}; - -} // namespace - - -void add_tests_AutoStoryTableParity(UnitTestDatabase& database){ - database.add(); -} - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index cb22d12626..9de1bf1a1f 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1947,7 +1947,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp From d0b6ad0bcc2283c7f0673cf79f5d0313c71b31f2 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 11:38:18 -0800 Subject: [PATCH 23/29] FRLG AutoStory: mark stage 1's checkpoints "phase": "testing" Each StoryData file of 00.01 to 00.10 gets "metadata": {"phase": "testing"}, as the later stages' files have. The table reader takes the metadata off before the shared reader (which doesn't take it yet), checking it holds only a known phase, as stage 3's reader does. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 26 ++++++++++++++++++- .../AutoStory/PokemonFRLG_AutoStoryTable.h | 3 +++ .../AutoStory/StoryData/frlg-00.01.plan.json | 3 ++- .../AutoStory/StoryData/frlg-00.02.plan.json | 3 ++- .../AutoStory/StoryData/frlg-00.03.plan.json | 3 ++- .../AutoStory/StoryData/frlg-00.04.plan.json | 3 ++- .../AutoStory/StoryData/frlg-00.05.plan.json | 3 ++- .../AutoStory/StoryData/frlg-00.06.plan.json | 3 ++- .../AutoStory/StoryData/frlg-00.07.plan.json | 3 ++- .../AutoStory/StoryData/frlg-00.08.plan.json | 3 ++- .../AutoStory/StoryData/frlg-00.09.plan.json | 3 ++- .../AutoStory/StoryData/frlg-00.10.plan.json | 3 ++- 12 files changed, 48 insertions(+), 11 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 88573b08af..8c9b714717 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -95,6 +95,30 @@ std::set read_note_keys(const JsonObject& execution, std::string_vi return keys; } +// The file without its "metadata", which the shared reader doesn't take +// (yet): {"phase": testing, verification or reproduction}, how far the +// checkpoint is trusted to save (the engine's save policy reads it). +JsonValue without_metadata(const JsonValue& value, std::string_view source){ + JsonObject stripped; + for (const auto& [key, field] : value.to_object_throw(std::string(source))){ + if (key != "metadata"){ + stripped[key] = field.clone(); + continue; + } + const JsonObject& metadata = field.to_object_throw(std::string(source)); + for (const auto& [metadata_key, unused] : metadata){ + if (metadata_key != "phase"){ + throw ParseException(std::format("{}: unsupported metadata field {}", source, metadata_key)); + } + } + const std::string& phase = metadata.get_string_throw("phase", std::string(source)); + if (phase != "testing" && phase != "verification" && phase != "reproduction"){ + throw ParseException(std::format("{}: unknown phase {}", source, phase)); + } + } + return JsonValue(std::move(stripped)); +} + } // namespace @@ -108,7 +132,7 @@ StoryCheckpoint read_story_checkpoint_file(const JsonValue& value, std::string_v note_keys = read_note_keys(execution, where); }; static_cast(checkpoint) = Pokemon::read_authored_checkpoint( - value, "frlg", source, read_execution, story_action_specs() + without_metadata(value, source), "frlg", source, read_execution, story_action_specs() ); for (const std::string& key : note_keys){ bool found = key == "checkpoint"; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index 99d5ed45d4..62cbb37513 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -22,6 +22,9 @@ * reasons behind a step that a reader of the file needs. * The program doesn't read them. * + * Beside "execution", "metadata": {"phase": testing, verification or + * reproduction}: how far the checkpoint is trusted. + * */ #ifndef PokemonAutomation_PokemonFRLG_AutoStoryTable_H diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01.plan.json index 31eea5b1d0..3e47c1be6b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01.plan.json @@ -25,5 +25,6 @@ "new_game.c: the bedroom at (6, 6), facing the TV." ] } - } + }, + "metadata": {"phase": "testing"} } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.02.plan.json index 2f09e7db16..06d522c23d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.02.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.02.plan.json @@ -18,5 +18,6 @@ }, "execution": { "menu": "before_pokemon" - } + }, + "metadata": {"phase": "testing"} } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.03.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.03.plan.json index b44478b878..0a86b054dc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.03.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.03.plan.json @@ -37,5 +37,6 @@ "PlayerEnter walks the player up 8 tiles from the lab's door." ] } - } + }, + "metadata": {"phase": "testing"} } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json index af5c28173a..54ca333a84 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json @@ -72,5 +72,6 @@ "The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down." ] } - } + }, + "metadata": {"phase": "testing"} } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.05.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.05.plan.json index d3923d0565..19e8a2e15e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.05.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.05.plan.json @@ -37,5 +37,6 @@ "ApproachCounter: up 4 from the mat, then faces the clerk." ] } - } + }, + "metadata": {"phase": "testing"} } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.06.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.06.plan.json index 431917879d..f58aba06bb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.06.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.06.plan.json @@ -29,5 +29,6 @@ }, "execution": { "menu": "full" - } + }, + "metadata": {"phase": "testing"} } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.07.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.07.plan.json index 4abe1885aa..75e4db6a09 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.07.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.07.plan.json @@ -91,5 +91,6 @@ "The gate's north warp lands on the forest's exit mat (29, 62), facing north. The save there keeps a forest failure from going back to Pallet." ] } - } + }, + "metadata": {"phase": "testing"} } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.08.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.08.plan.json index c02e6e877f..ddb92f9f99 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.08.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.08.plan.json @@ -78,5 +78,6 @@ "Out of the forest, wild battles are run from; trainers are still fought." ] } - } + }, + "metadata": {"phase": "testing"} } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json index 28b36cc3e4..c756fe3bec 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json @@ -75,5 +75,6 @@ "On to Brock unless red HP or a status is left that no item cures." ] } - } + }, + "metadata": {"phase": "testing"} } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.10.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.10.plan.json index b8cf6a8ccd..6c4b5e9883 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.10.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.10.plan.json @@ -44,5 +44,6 @@ "RunningShoesAideTriggerTop: the aide talks from (46, 20), no YES/NO; the player only turns up. He walks off and is removed; FLAG_SYS_B_DASH is set (console B, 2026-11-02: about 20 B presses to the overworld)." ] } - } + }, + "metadata": {"phase": "testing"} } From 4984b176b0ee52aa71763d7d1388003c82195f04 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 13:50:00 -0800 Subject: [PATCH 24/29] FRLG: build maps from pinned Packages resources from stage 1 on Apply #238's switch where the maps are first added: overworld_map_json() embeds the pinned PokemonSimulation pack prepared under Packages/Resources/Pokemon/Maps/frlg (devtools/maps/map-resources.lock.json), so the 25 authored map JSONs and their generator, devtools/maps/frlg_maps.py, are gone. frlg_battle_data.py forwards to the pinned Simulation exporter. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../workflows/cpp-ci-serial-programs-base.yml | 15 + .gitignore | 3 + SerialPrograms/CMakeLists.txt | 4 +- .../Overworld/Maps/CeruleanCave_1F.json | 194 ----------- .../Overworld/Maps/CeruleanCave_2F.json | 180 ---------- .../Overworld/Maps/CeruleanCave_B1F.json | 159 --------- .../Overworld/Maps/CeruleanCity.json | 270 --------------- .../Maps/CeruleanCity_PokemonCenter_1F.json | 125 ------- .../Overworld/Maps/PalletTown.json | 122 ------- .../Maps/PalletTown_PlayersHouse_1F.json | 64 ---- .../Maps/PalletTown_PlayersHouse_2F.json | 46 --- .../Maps/PalletTown_ProfessorOaksLab.json | 127 ------- .../Maps/PalletTown_RivalsHouse.json | 69 ---- .../Overworld/Maps/PewterCity.json | 167 --------- .../Overworld/Maps/PewterCity_Gym.json | 75 ----- .../Overworld/Maps/PewterCity_Mart.json | 78 ----- .../Overworld/Maps/PewterCity_Museum_1F.json | 108 ------ .../Maps/PewterCity_PokemonCenter_1F.json | 110 ------ .../PokemonFRLG/Overworld/Maps/Route1.json | 91 ----- .../PokemonFRLG/Overworld/Maps/Route2.json | 211 ------------ .../PokemonFRLG/Overworld/Maps/Route22.json | 90 ----- .../PokemonFRLG/Overworld/Maps/Route24.json | 154 --------- .../Route2_ViridianForest_NorthEntrance.json | 78 ----- .../Route2_ViridianForest_SouthEntrance.json | 78 ----- .../Overworld/Maps/ViridianCity.json | 216 ------------ .../Overworld/Maps/ViridianCity_Mart.json | 91 ----- .../Maps/ViridianCity_PokemonCenter_1F.json | 98 ------ .../Overworld/Maps/ViridianForest.json | 201 ----------- .../Overworld/PokemonFRLG_OverworldMaps.h | 4 +- .../cmake/PokesimMapResources.cmake | 15 + devtools/maps/RESOURCE_MAPS.md | 46 +++ devtools/maps/frlg_battle_data.py | 277 +-------------- devtools/maps/frlg_maps.py | 318 ------------------ devtools/maps/map-resources.lock.json | 11 + 34 files changed, 102 insertions(+), 3793 deletions(-) delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity_PokemonCenter_1F.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_1F.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_2F.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_ProfessorOaksLab.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_RivalsHouse.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Gym.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Mart.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Museum_1F.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_PokemonCenter_1F.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route1.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route22.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route24.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_NorthEntrance.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_SouthEntrance.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_Mart.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_PokemonCenter_1F.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianForest.json create mode 100644 SerialPrograms/cmake/PokesimMapResources.cmake create mode 100644 devtools/maps/RESOURCE_MAPS.md delete mode 100644 devtools/maps/frlg_maps.py create mode 100644 devtools/maps/map-resources.lock.json diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml index 9595aa79f0..ff4bc1ee28 100644 --- a/.github/workflows/cpp-ci-serial-programs-base.yml +++ b/.github/workflows/cpp-ci-serial-programs-base.yml @@ -88,6 +88,19 @@ jobs: ref: 'master' path: 'Arduino-Source/Packages' + - name: Install Python for pinned map preparation + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Prepare approved FRLG map resources + id: map-resources + uses: dayfine/PokemonSimulation/integrations/arduino-source/verify-map-packs@906956e94fc912ae9adb0e44845da780f3bc7e4c + with: + layout: resources + operation: prepare + consumer-directory: Arduino-Source + - name: Install Qt uses: jurplel/install-qt-action@v4 with: @@ -204,6 +217,8 @@ jobs: # every file missed, compiling took 10-40% longer than before on Linux and macOS, and # about twice as long on Windows. CCACHE_DEPEND: 1 + POKESIM_TOOLS_SOURCE: ${{ steps.map-resources.outputs.tools-source }} + POKESIM_SOURCE_CACHE: ${{ steps.map-resources.outputs.source-cache }} run: | cd Arduino-Source/SerialPrograms mkdir bin diff --git a/.gitignore b/.gitignore index ef6f409ae9..a6b04ddffd 100644 --- a/.gitignore +++ b/.gitignore @@ -81,3 +81,6 @@ Packages/* # Local agent/linter environments. .venv-code-health/ __pycache__/ + +# External PokemonSimulation tools/data cache; prepared maps live in ignored Packages. +.pokesim-map-source/ diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 5a90664df8..4822575e56 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -227,7 +227,9 @@ add_library(SerialProgramsLib STATIC ${CORE_LIBRARY_SOURCES} ${LIBRARY_SOURCES}) include(cmake/EmbedTextFiles.cmake) pa_embed_text_files(SerialProgramsLib Source/Pokemon/Navigation/TestMaps Pokemon/Navigation/Pokemon_Navigation_Tests.h PokemonAutomation::Pokemon navigation_test_map_json) -pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Overworld/Maps +include(cmake/PokesimMapResources.cmake) +pa_frlg_map_resources(FRLG_MAP_RESOURCES) +pa_embed_text_files(SerialProgramsLib "${FRLG_MAP_RESOURCES}" VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h PokemonAutomation::NintendoSwitch::PokemonFRLG overworld_map_json) pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_battle_json) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json deleted file mode 100644 index a6cb236993..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json +++ /dev/null @@ -1,194 +0,0 @@ -{ - "name": "CeruleanCave_1F", - "source": { - "decomp_file": "data/maps/CeruleanCave_1F/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "########################################", - "#######...##.#########wwwwwwwww#..##..##", - "#######......#########wwwwwwwww#......##", - "#######..##..#wwwwwwwwwwwwwwwww#......##", - "##.####..##..#wwwwwwwwww#...#ww##.######", - "##.#.........#wwwwwwwwww#...#wwwwwwwwww#", - "#..#....##...#www#..........#wwwwwwwwww#", - "#..#....##...#www#..........#wwwwwwwwww#", - "#..#....##...#www#.................#www#", - "####....##.###www#...######...#....#www#", - "##.#....#www##www#...##.####.......#www#", - "##......#www##www##.###...##.......#www#", - "##......#wwwwwwww#....#...##...#####www#", - "##......#wwwwwwww#..#.##.###...###.....#", - "##..##..#wwwwwwww#.........#...#.......#", - "##..#...#www#....##......###...#.....###", - "##......#...#....####...####...#...#####", - "##......#...#..................#...#####", - "#####.###...##.#...............#...#####", - "#####..........#...............#...#####", - "#####..........#...............#...#####", - "#####..........#################...#####", - "########################################" - ], - "elevation": [ - "0000000000000000000000000000000000000000", - "0000000333003000000000111111111033003300", - "0000000333333000000000111111111033333300", - "0000000330033011111111111111111033333300", - "0030000330033011111111110444011003000000", - "0030333333333011111111110444011111111110", - "0330333300333011104444444444011111111110", - "0330333300333011104444444444011111111110", - "0330333300333011104444444444444444401110", - "0000333300300011104440000004440444401110", - "0030333301110011104440030000444444401110", - "0033333301110011100000033300444444401110", - "0033333301111111103333033300444000001110", - "0033333301111111103303003000444000333330", - "0033003301111111103333333330444033333330", - "0033033301110444400333333000444033333000", - "0033333303330444400003330000444033300000", - "0033333303330444444444444444444033300000", - "0000030003330000444444444444444033300000", - "0000033333333330444444444444444033300000", - "0000033333333330444444444444444033300000", - "0000033333333330000000000000000033300000", - "0000000000000000000000000000000000000000" - ], - "points": { - "entrance": [33, 21], - "warp_0": [33, 21], - "warp_1": [34, 2], - "warp_2": [1, 7], - "warp_3": [10, 2], - "warp_4": [5, 15], - "warp_5": [30, 10], - "warp_6": [24, 11], - "warp_7": [2, 4] - }, - "warps": [ - { - "x": 33, - "y": 21, - "enter": "walk_south", - "to_map": "CeruleanCity", - "to_point": "warp_7" - }, - { - "x": 34, - "y": 2, - "enter": "step_on", - "to_map": "CeruleanCave_2F", - "to_point": "warp_0" - }, - { - "x": 1, - "y": 7, - "enter": "step_on", - "to_map": "CeruleanCave_B1F", - "to_point": "warp_0" - }, - { - "x": 10, - "y": 2, - "enter": "step_on", - "to_map": "CeruleanCave_2F", - "to_point": "warp_1" - }, - { - "x": 5, - "y": 15, - "enter": "step_on", - "to_map": "CeruleanCave_2F", - "to_point": "warp_2" - }, - { - "x": 30, - "y": 10, - "enter": "step_on", - "to_map": "CeruleanCave_2F", - "to_point": "warp_3" - }, - { - "x": 24, - "y": 11, - "enter": "step_on", - "to_map": "CeruleanCave_2F", - "to_point": "warp_4" - }, - { - "x": 2, - "y": 4, - "enter": "step_on", - "to_map": "CeruleanCave_2F", - "to_point": "warp_5" - } - ], - "objects": [ - { - "name": "item_ball", - "kind": "item", - "x": 7, - "y": 3, - "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_1F_NUGGET" - }, - { - "name": "item_ball", - "kind": "item", - "x": 11, - "y": 16, - "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_1F_FULL_RESTORE" - }, - { - "name": "item_ball", - "kind": "item", - "x": 25, - "y": 5, - "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_1F_MAX_ELIXIR" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 7, - "y": 21, - "hide_flag": "FLAG_TEMP_12" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 13, - "y": 21, - "hide_flag": "FLAG_TEMP_13" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 5, - "y": 20, - "hide_flag": "FLAG_TEMP_14" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 14, - "y": 20, - "hide_flag": "FLAG_TEMP_15" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 11, - "y": 21, - "hide_flag": "FLAG_TEMP_16" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 9, - "y": 18, - "hide_flag": "FLAG_TEMP_17" - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json deleted file mode 100644 index 185103d4c8..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json +++ /dev/null @@ -1,180 +0,0 @@ -{ - "name": "CeruleanCave_2F", - "source": { - "decomp_file": "data/maps/CeruleanCave_2F/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "########################################", - "########################################", - "########################################", - "####....####..##.....#............######", - "#######.......#..###.#.#########..######", - "####..####.####.##.#.#.........#########", - "####.....#.........###########....######", - "#######.############.........####.######", - "####.#...............#######....#.######", - "####.#################..#..###.##.######", - "####.#....#.............#...#...#.######", - "####.#.##.#.#####.#######.#####.#.######", - "####.#..#.#.....#.......#.....#.#.######", - "####.#..#.#####.#######.#####.#.########", - "####.#..#.#.....#.....#.....#.#.#.######", - "####.####.#.#####.###.#.#.#.#.#.#.######", - "####.#....#.........#.#.#.#.#.#.#.######", - "####.#.####.#########.#.#.#.###.#.######", - "####.#....#.....#.....#.#.#.....#.######", - "####.############.#####.#.#######.######", - "####..............#.....#.........######", - "########################################", - "########################################" - ], - "points": { - "warp_0": [33, 4], - "warp_1": [13, 4], - "warp_2": [7, 14], - "warp_3": [26, 9], - "warp_4": [23, 10], - "warp_5": [5, 6] - }, - "warps": [ - { - "x": 33, - "y": 4, - "enter": "step_on", - "to_map": "CeruleanCave_1F", - "to_point": "warp_1" - }, - { - "x": 13, - "y": 4, - "enter": "step_on", - "to_map": "CeruleanCave_1F", - "to_point": "warp_3" - }, - { - "x": 7, - "y": 14, - "enter": "step_on", - "to_map": "CeruleanCave_1F", - "to_point": "warp_4" - }, - { - "x": 26, - "y": 9, - "enter": "step_on", - "to_map": "CeruleanCave_1F", - "to_point": "warp_5" - }, - { - "x": 23, - "y": 10, - "enter": "step_on", - "to_map": "CeruleanCave_1F", - "to_point": "warp_6" - }, - { - "x": 5, - "y": 6, - "enter": "step_on", - "to_map": "CeruleanCave_1F", - "to_point": "warp_7" - } - ], - "objects": [ - { - "name": "item_ball", - "kind": "item", - "x": 9, - "y": 18, - "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_2F_PP_UP" - }, - { - "name": "item_ball", - "kind": "item", - "x": 29, - "y": 16, - "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_2F_ULTRA_BALL" - }, - { - "name": "item_ball", - "kind": "item", - "x": 33, - "y": 12, - "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_2F_FULL_RESTORE" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 33, - "y": 10, - "hide_flag": "FLAG_TEMP_12" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 33, - "y": 9, - "hide_flag": "FLAG_TEMP_13" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 25, - "y": 11, - "hide_flag": "FLAG_TEMP_14" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 28, - "y": 20, - "hide_flag": "FLAG_TEMP_15" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 30, - "y": 20, - "hide_flag": "FLAG_TEMP_16" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 9, - "y": 13, - "hide_flag": "FLAG_TEMP_17" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 23, - "y": 16, - "hide_flag": "FLAG_TEMP_18" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 13, - "y": 6, - "hide_flag": "FLAG_TEMP_19" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 4, - "y": 12, - "hide_flag": "FLAG_TEMP_1A" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 10, - "y": 20, - "hide_flag": "FLAG_TEMP_1B" - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json deleted file mode 100644 index 683929ff37..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json +++ /dev/null @@ -1,159 +0,0 @@ -{ - "name": "CeruleanCave_B1F", - "source": { - "decomp_file": "data/maps/CeruleanCave_B1F/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "########################################", - "##..............##.....############....#", - "##..............#........#######.......#", - "##..............#..####.....#######....#", - "##......#####.###..####.....#######....#", - "##......#..........########.#######.#..#", - "##..##..##........#########............#", - "##..#...###......##########............#", - "##......#wwwww##................#...####", - "#########wwwww##................#...####", - "#www############................#...####", - "#www##############.########.###.#...####", - "#www#.#.#.########........#.###.#...####", - "#www#.....########........#.....#...####", - "#www#.....########........#.....#...####", - "#www###.###wwww#......#...#.###.#...####", - "#wwwwwwwwwwwwww#......#...#.###.#...####", - "#wwwwwwwwwwwwww#......#...#.....#...####", - "#wwwwwwwwwwwwww#......#...#.....#...####", - "######wwwwwwwww##.##.##...###.###...####", - "######wwwwwwwwwwww#.......###.......####", - "######wwwwwwwwwwww##.....####.......####", - "########################################" - ], - "elevation": [ - "0000000000000000000000000000000000000000", - "0033333333333333003333300000000000033330", - "0033333333333333033333333000000033333330", - "0033333333333333033000033333000000033330", - "0033333300000300033000033333000000033330", - "0033333303333333333000000003000000030330", - "0033003300333333330000000003333333333330", - "0033033300033333300000000003333333333330", - "0033333301111100444444444444444403330000", - "0000000001111100444444444444444403330000", - "0111000000000000444444444444444403330000", - "0111000000000000000000000004000403330000", - "0111030303000000003333333304000403330000", - "0111033333000000003333333304444403330000", - "0111033333000000003333333304444403330000", - "0111000300011110444444033304000403330000", - "0111111111111110444444033304000403330000", - "0111111111111110444444033304444403330000", - "0111111111111110404444033304444403330000", - "0000001111111110030000033300000003330000", - "0000001111111111110333333300033333330000", - "0000001111111111110033333000033333330000", - "0000000000000000000000000000000000000000" - ], - "points": { - "mewtwo": [7, 12], - "warp_0": [5, 7] - }, - "warps": [ - { - "x": 5, - "y": 7, - "enter": "step_on", - "to_map": "CeruleanCave_1F", - "to_point": "warp_2" - } - ], - "objects": [ - { - "name": "item_ball", - "kind": "item", - "x": 31, - "y": 9, - "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_B1F_ULTRA_BALL" - }, - { - "name": "item_ball", - "kind": "item", - "x": 32, - "y": 2, - "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_B1F_MAX_REVIVE" - }, - { - "name": "mewtwo", - "kind": "npc", - "x": 7, - "y": 12, - "hide_flag": "FLAG_HIDE_MEWTWO" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 37, - "y": 1, - "hide_flag": "FLAG_TEMP_12" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 38, - "y": 2, - "hide_flag": "FLAG_TEMP_13" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 35, - "y": 1, - "hide_flag": "FLAG_TEMP_14" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 37, - "y": 4, - "hide_flag": "FLAG_TEMP_15" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 35, - "y": 5, - "hide_flag": "FLAG_TEMP_16" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 2, - "y": 2, - "hide_flag": "FLAG_TEMP_17" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 4, - "y": 1, - "hide_flag": "FLAG_TEMP_18" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 6, - "y": 1, - "hide_flag": "FLAG_TEMP_19" - }, - { - "name": "rock_smash_rock", - "kind": "npc", - "x": 3, - "y": 4, - "hide_flag": "FLAG_TEMP_1A" - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity.json deleted file mode 100644 index 0c54fa2d7d..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity.json +++ /dev/null @@ -1,270 +0,0 @@ -{ - "name": "CeruleanCity", - "source": { - "decomp_file": "data/maps/CeruleanCity/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "################wwwww#...#...#wwwwwwwwwwwwwwwwww", - "################wwwww#...#vvv#wwwwwwwwwwwwwwwwww", - "####wwwwwwwwwwwwwwwww#...#...#wwwwwwwwwwwwwwwwww", - "####wwwwwwwwwwwwwwwww#...#...#wwwwwwwwwwwwwwwwww", - "####wwwwwwwwwwwwwwwww#...#...###################", - "####www###############...#...#.........#########", - "####www#.............#...#...#.........#########", - "####www#.............#...#...#.........#########", - "####www##...##########.......#...##...##########", - "####www###############......#######...##########", - "####www###############......#######...##########", - "####www###D######D####......##D####......#######", - "#.##www#..........................#......#######", - "....www#..........................#......#######", - "....www#..........................#......#######", - "....www#.....#######..............#......#######", - "wwwwwww#...vv############.........#......#......", - "wwwwwww#.....##D#########.........#......#######", - "wwwwwww#............#####vvv#######.............", - "########............SSD##...#######.............", - "............................#######vvv#..#######", - "...........................S..#D#.....#..#......", - "......................................#..#######", - "#######...............................#..#######", - "#######.....####......................#..#######", - "#######....#####....S.................#..#######", - "#######....#####.....###############..#..#######", - "#######....#####.....###############..#..#######", - "#######....S#..#.....##D###SSD######..#..#######", - "#######...............................#..#######", - "#######...............................#..#######", - "#######...............................#..#######", - "###################S######.############..#######", - "#######..................................#######", - "#######..................................#######", - "###############....#........#....###############", - "###############....#vvvvvvvv#....###############", - "###############....#........#....###############", - "###############....#........#....###############", - "###############....#........#....###############" - ], - "elevation": [ - "000000000000000011111033303330100000000000000000", - "000000000000000011111033300000100000000000000000", - "000011111111111111111033303330100000000000000000", - "000011111111111111111033303330111111111111111111", - "000011111111111111111033303330000000000000000000", - "000011100000000000000033303330333333333000000000", - "000011103333333333333033303330333333333000000000", - "000011103333333333333033303330333333333000000000", - "000011100333000000000033333330333003330000000000", - "000011100000000000000033333300000003330000000000", - "000011100000000000000033333300000003330000000000", - "000011100000000000000033333300000003333330000000", - "030011103333333333333333333333333303333330000000", - "333311103333333333333333333333333303333330000000", - "333311103333333333333333333333333303333330000000", - "333311103333300000003333333333333303333330000000", - "111111103330000000000000033333333303333330333333", - "111111103333300000000000033333333303333330000000", - "111111103333333333330000000000000003333333333333", - "000000003333333333330000033300000003333333333333", - "333333333333333333333333333300000000000330000000", - "333333333333333333333333333033000333330330333333", - "333333333333333333333333333333333333330330000000", - "000000033333333333333333333333333333330330000000", - "000000033333000033333333333333333333330330000000", - "000000033330000033330333333333333333330330000000", - "000000033330000033333000000000000000330330000000", - "000000033330000033333000000000000000330330000000", - "000000033330033033333000000000000000330330000000", - "000000033333333333333333333333333333330330000000", - "000000033333333333333333333333333333330330000000", - "000000033333333333333333333333333333330330000000", - "000000000000000000000000003000000000000330000000", - "000000033333333333333333333333333333333330000000", - "000000033333333333333333333333333333333330000000", - "000000000000000333303333333303333000000000000000", - "000000000000000333300000000003333000000000000000", - "000000000000000333303333333303333000000000000000", - "000000000000000333303333333303333000000000000000", - "000000000000000333303333333303333000000000000000" - ], - "points": { - "warp_3": [22, 19], - "warp_7": [1, 12] - }, - "warps": [ - { - "x": 10, - "y": 11, - "enter": "walk_into" - }, - { - "x": 30, - "y": 11, - "enter": "walk_into" - }, - { - "x": 15, - "y": 17, - "enter": "walk_into" - }, - { - "x": 22, - "y": 19, - "enter": "walk_into", - "to_map": "CeruleanCity_PokemonCenter_1F", - "to_point": "warp_1" - }, - { - "x": 31, - "y": 21, - "enter": "walk_into" - }, - { - "x": 13, - "y": 28, - "enter": "cave_entrance" - }, - { - "x": 29, - "y": 28, - "enter": "walk_into" - }, - { - "x": 1, - "y": 12, - "enter": "cave_entrance", - "to_map": "CeruleanCave_1F", - "to_point": "warp_0" - }, - { - "x": 10, - "y": 8, - "enter": "walk_south" - }, - { - "x": 31, - "y": 8, - "enter": "walk_south" - }, - { - "x": 31, - "y": 9, - "enter": "walk_into" - }, - { - "x": 14, - "y": 28, - "enter": "cave_entrance" - }, - { - "x": 23, - "y": 28, - "enter": "walk_into" - }, - { - "x": 17, - "y": 11, - "enter": "walk_into" - } - ], - "objects": [ - { - "name": "policeman", - "kind": "npc", - "x": 31, - "y": 12 - }, - { - "name": "rocket_m", - "kind": "npc", - "x": 33, - "y": 6, - "hide_flag": "FLAG_HIDE_CERULEAN_ROCKET" - }, - { - "name": "little_boy", - "kind": "npc", - "x": 16, - "y": 21, - "wander": { - "x0": 16, - "y0": 18, - "x1": 16, - "y1": 24 - } - }, - { - "name": "balding_man", - "kind": "npc", - "x": 9, - "y": 23, - "wander": { - "x0": 8, - "y0": 22, - "x1": 10, - "y1": 24 - } - }, - { - "name": "slowbro", - "kind": "npc", - "x": 32, - "y": 29 - }, - { - "name": "lass", - "kind": "npc", - "x": 33, - "y": 29 - }, - { - "name": "youngster", - "kind": "npc", - "x": 34, - "y": 22 - }, - { - "name": "blue", - "kind": "npc", - "x": 22, - "y": 0, - "hide_flag": "FLAG_HIDE_CERULEAN_RIVAL" - }, - { - "name": "cut_tree", - "kind": "npc", - "x": 26, - "y": 32, - "hide_flag": "FLAG_TEMP_13" - }, - { - "name": "woman_1", - "kind": "npc", - "x": 12, - "y": 30 - }, - { - "name": "cooltrainer_m", - "kind": "npc", - "x": 1, - "y": 13, - "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_GUARD" - } - ], - "flag_sets": { - "after_hall_of_fame": [ - "FLAG_HIDE_CERULEAN_CAVE_GUARD", - "FLAG_HIDE_CERULEAN_RIVAL", - "FLAG_HIDE_CERULEAN_ROCKET" - ] - }, - "connections": [ - { - "side": "north", - "to_map": "Route24", - "offset": 12 - } - ] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity_PokemonCenter_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity_PokemonCenter_1F.json deleted file mode 100644 index c538b6e3b1..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity_PokemonCenter_1F.json +++ /dev/null @@ -1,125 +0,0 @@ -{ - "name": "CeruleanCity_PokemonCenter_1F", - "source": { - "decomp_file": "data/maps/CeruleanCity_PokemonCenter_1F/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "#.#############", - "###############", - "....###..##....", - "....#######....", - "...............", - "...............", - "#..........##..", - "...........##..", - "...............", - "###############" - ], - "elevation": [ - "030000000000000", - "000000000000000", - "333300033003333", - "333300000003333", - "333333333333333", - "330333333333333", - "044033333330033", - "330333333330033", - "333333333333333", - "000000000000000" - ], - "points": { - "pc": [11, 2], - "nurse_front": [7, 4], - "warp_1": [7, 8] - }, - "warps": [ - { - "x": 6, - "y": 8, - "enter": "walk_into", - "to_map": "CeruleanCity", - "to_point": "warp_3" - }, - { - "x": 7, - "y": 8, - "enter": "walk_south", - "to_map": "CeruleanCity", - "to_point": "warp_3" - }, - { - "x": 8, - "y": 8, - "enter": "walk_into", - "to_map": "CeruleanCity", - "to_point": "warp_3" - }, - { - "x": 1, - "y": 6, - "enter": "step_on" - } - ], - "objects": [ - { - "name": "nurse", - "kind": "npc", - "x": 7, - "y": 2 - }, - { - "name": "gentleman", - "kind": "npc", - "x": 12, - "y": 5 - }, - { - "name": "rocker", - "kind": "npc", - "x": 5, - "y": 4, - "wander": { - "x0": 4, - "y0": 4, - "x1": 6, - "y1": 4 - } - }, - { - "name": "youngster", - "kind": "npc", - "x": 4, - "y": 8, - "wander": { - "x0": 3, - "y0": 8, - "x1": 5, - "y1": 8 - } - }, - { - "name": "lass", - "kind": "npc", - "x": 3, - "y": 3 - }, - { - "name": "0", - "kind": "npc", - "x": 2, - "y": 1, - "hide_flag": "FLAG_HIDE_POSTGAME_GOSSIPERS" - }, - { - "name": "0", - "kind": "npc", - "x": 3, - "y": 1, - "hide_flag": "FLAG_HIDE_POSTGAME_GOSSIPERS" - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown.json deleted file mode 100644 index 63540ac440..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown.json +++ /dev/null @@ -1,122 +0,0 @@ -{ - "name": "PalletTown", - "source": { - "decomp_file": "data/maps/PalletTown/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "############..##########", - "############..##########", - "##....................##", - "##....................##", - "##...#####....#####...##", - "##...#####....#####...##", - "##...#####....#####...##", - "##..S#D###...S#D###...##", - "##....................##", - "##....................##", - "##...........#######..##", - "##...####S...#######..##", - "##...........#######..##", - "##...........###D###..##", - "##...S................##", - "##....................##", - "##...........###S##...##", - "##.....wwww...........##", - "##.....wwww...........##", - "##.....wwww...........##" - ], - "elevation": [ - "000000000000330000000000", - "000000000000330000000000", - "003333333333333333333300", - "003333333333333333333300", - "003330000033330000033300", - "003330000033330000033300", - "003330000033330000033300", - "003300000033300000033300", - "003333333333333333333300", - "003333333333333333333300", - "003333333333300000003300", - "003330000033300000003300", - "003333333333300000003300", - "003333333333300000003300", - "003330333333333333333300", - "003333333333333333333300", - "003333333333300000033300", - "003333311113333333333300", - "003333311113333333333300", - "003333311113333333333300" - ], - "points": { - "oaks_lab_front": [16, 14], - "warp_0": [6, 7], - "warp_1": [15, 7], - "warp_2": [16, 13] - }, - "warps": [ - { - "x": 6, - "y": 7, - "enter": "walk_into", - "to_map": "PalletTown_PlayersHouse_1F", - "to_point": "warp_1" - }, - { - "x": 15, - "y": 7, - "enter": "walk_into", - "to_map": "PalletTown_RivalsHouse", - "to_point": "warp_0" - }, - { - "x": 16, - "y": 13, - "enter": "walk_into", - "to_map": "PalletTown_ProfessorOaksLab", - "to_point": "warp_0" - } - ], - "objects": [ - { - "name": "woman_1", - "kind": "npc", - "x": 3, - "y": 10, - "wander": { - "x0": 2, - "y0": 6, - "x1": 4, - "y1": 14 - } - }, - { - "name": "fat_man", - "kind": "npc", - "x": 13, - "y": 17, - "wander": { - "x0": 7, - "y0": 15, - "x1": 19, - "y1": 19 - } - }, - { - "name": "prof_oak", - "kind": "npc", - "x": 10, - "y": 8, - "hide_flag": "FLAG_HIDE_OAK_IN_PALLET_TOWN" - } - ], - "flag_sets": {}, - "connections": [ - { - "side": "north", - "to_map": "Route1", - "offset": 0 - } - ] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_1F.json deleted file mode 100644 index ee57a2a78a..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_1F.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "name": "PalletTown_PlayersHouse_1F", - "source": { - "decomp_file": "data/maps/PalletTown_PlayersHouse_1F/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "#############", - "#############", - "#..........##", - "#............", - "#.....##.....", - "#.....##.....", - "#............", - "##..........#", - "#............", - "#############" - ], - "points": { - "warp_1": [4, 8], - "warp_2": [10, 2] - }, - "warps": [ - { - "x": 5, - "y": 8, - "enter": "walk_into", - "to_map": "PalletTown", - "to_point": "warp_0" - }, - { - "x": 4, - "y": 8, - "enter": "walk_south", - "to_map": "PalletTown", - "to_point": "warp_0" - }, - { - "x": 10, - "y": 2, - "enter": "walk_east", - "to_map": "PalletTown_PlayersHouse_2F", - "to_point": "warp_0" - }, - { - "x": 3, - "y": 9, - "enter": "walk_into", - "to_map": "PalletTown", - "to_point": "warp_0" - } - ], - "objects": [ - { - "name": "mom", - "kind": "npc", - "x": 8, - "y": 4 - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_2F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_2F.json deleted file mode 100644 index eb5cbf8d32..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_2F.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "PalletTown_PlayersHouse_2F", - "source": { - "decomp_file": "data/maps/PalletTown_PlayersHouse_2F/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "############", - "###########S", - "#.......##..", - "#.......##..", - "#.2...#.....", - "#.8...#.....", - "#.#.........", - "#...........", - "#..........." - ], - "elevation": [ - "000000000000", - "000000000000", - "033333330033", - "033333330033", - "033333033333", - "003033033333", - "040403333333", - "003033333333", - "033333333333" - ], - "points": { - "start": [6, 6], - "warp_0": [10, 2] - }, - "warps": [ - { - "x": 10, - "y": 2, - "enter": "walk_west", - "to_map": "PalletTown_PlayersHouse_1F", - "to_point": "warp_2" - } - ], - "objects": [], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_ProfessorOaksLab.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_ProfessorOaksLab.json deleted file mode 100644 index 158ea7c73d..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_ProfessorOaksLab.json +++ /dev/null @@ -1,127 +0,0 @@ -{ - "name": "PalletTown_ProfessorOaksLab", - "source": { - "decomp_file": "data/maps/PalletTown_ProfessorOaksLab/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "#############", - "######SS#####", - ".............", - "#............", - "###.....###..", - ".##..........", - ".............", - ".............", - "#####...#####", - ".............", - ".............", - ".............", - "#...........#", - "#############" - ], - "points": { - "warp_0": [6, 12] - }, - "warps": [ - { - "x": 6, - "y": 12, - "enter": "walk_south", - "to_map": "PalletTown", - "to_point": "warp_2" - }, - { - "x": 7, - "y": 12, - "enter": "walk_into", - "to_map": "PalletTown", - "to_point": "warp_2" - }, - { - "x": 5, - "y": 12, - "enter": "walk_into", - "to_map": "PalletTown", - "to_point": "warp_2" - } - ], - "objects": [ - { - "name": "scientist", - "kind": "npc", - "x": 3, - "y": 11 - }, - { - "name": "worker_f", - "kind": "npc", - "x": 2, - "y": 10, - "wander": { - "x0": 2, - "y0": 6, - "x1": 2, - "y1": 13 - } - }, - { - "name": "scientist", - "kind": "npc", - "x": 11, - "y": 10 - }, - { - "name": "prof_oak", - "kind": "npc", - "x": 6, - "y": 3, - "hide_flag": "FLAG_HIDE_OAK_IN_HIS_LAB" - }, - { - "name": "item_ball", - "kind": "item", - "x": 8, - "y": 4, - "hide_flag": "FLAG_HIDE_BULBASAUR_BALL" - }, - { - "name": "item_ball", - "kind": "item", - "x": 9, - "y": 4, - "hide_flag": "FLAG_HIDE_SQUIRTLE_BALL" - }, - { - "name": "item_ball", - "kind": "item", - "x": 10, - "y": 4, - "hide_flag": "FLAG_HIDE_CHARMANDER_BALL" - }, - { - "name": "blue", - "kind": "npc", - "x": 5, - "y": 4, - "hide_flag": "FLAG_HIDE_RIVAL_IN_LAB" - }, - { - "name": "pokedex", - "kind": "npc", - "x": 4, - "y": 1, - "hide_flag": "FLAG_HIDE_POKEDEX" - }, - { - "name": "pokedex", - "kind": "npc", - "x": 5, - "y": 1, - "hide_flag": "FLAG_HIDE_POKEDEX" - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_RivalsHouse.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_RivalsHouse.json deleted file mode 100644 index bfd7bdf2e0..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_RivalsHouse.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "PalletTown_RivalsHouse", - "source": { - "decomp_file": "data/maps/PalletTown_RivalsHouse/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "#############", - "#############", - ".............", - ".............", - "......##.....", - "......##.....", - ".............", - ".............", - "#...........#", - "#############" - ], - "points": { - "warp_0": [4, 8] - }, - "warps": [ - { - "x": 4, - "y": 8, - "enter": "walk_south", - "to_map": "PalletTown", - "to_point": "warp_1" - }, - { - "x": 5, - "y": 8, - "enter": "walk_into", - "to_map": "PalletTown", - "to_point": "warp_1" - }, - { - "x": 3, - "y": 8, - "enter": "walk_into", - "to_map": "PalletTown", - "to_point": "warp_1" - } - ], - "objects": [ - { - "name": "daisy", - "kind": "npc", - "x": 10, - "y": 6, - "wander": { - "x0": 9, - "y0": 3, - "x1": 11, - "y1": 9 - } - }, - { - "name": "town_map", - "kind": "npc", - "x": 6, - "y": 4, - "hide_flag": "FLAG_HIDE_TOWN_MAP" - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity.json deleted file mode 100644 index da09eb8aa1..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity.json +++ /dev/null @@ -1,167 +0,0 @@ -{ - "name": "PewterCity", - "source": { - "decomp_file": "data/maps/PewterCity/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "################################################", - "#######################....#####################", - "####........#################.........##########", - "####........#################.........##########", - "####........#############D######......##########", - "####........###########...............##########", - "#######.....#####.#####..#######........########", - "####vvv..vvvvvvv...Svvvvvvvvvvvvvvvvv...########", - "####....................................########", - "####............................#####...########", - "######..........................#####...########", - "######..........................#D###...########", - "######..................................########", - "######...##.#######.##..................########", - "######...#############..................########", - "######...##.#######.##..................########", - "######...##S..#D#...##....####..........########", - "######...............#....######........########", - "######...............#....SSD###........########", - "######...............#.................S########", - "######################..........................", - "######..........................................", - "######.......#########..........................", - "######.......#########....##########............", - "######.......#########....##########....########", - "######.......##SSD####....#####S#####...########", - "######....................#.........#...########", - "######....................#.........#...########", - "######..#####.............#.........#...########", - "######..#####.............#.........#...########", - "######..#D###.......S.....#vvvv.vvvv#...########", - "######..................................########", - "######..................................########", - "######..................................########", - "######..................................########", - "######..................................########", - "####################....########################", - "####################....########################", - "####################....########################", - "####################....########################" - ], - "points": { - "gym_front": [15, 17], - "warp_0": [17, 6], - "warp_1": [25, 4], - "warp_2": [15, 16], - "warp_3": [28, 18], - "warp_5": [17, 25] - }, - "warps": [ - { - "x": 17, - "y": 6, - "enter": "cave_entrance", - "to_map": "PewterCity_Museum_1F", - "to_point": "warp_1" - }, - { - "x": 25, - "y": 4, - "enter": "walk_into", - "to_map": "PewterCity_Museum_1F", - "to_point": "warp_3" - }, - { - "x": 15, - "y": 16, - "enter": "walk_into", - "to_map": "PewterCity_Gym", - "to_point": "warp_1" - }, - { - "x": 28, - "y": 18, - "enter": "walk_into", - "to_map": "PewterCity_Mart", - "to_point": "warp_1" - }, - { - "x": 33, - "y": 11, - "enter": "walk_into" - }, - { - "x": 17, - "y": 25, - "enter": "walk_into", - "to_map": "PewterCity_PokemonCenter_1F", - "to_point": "warp_1" - }, - { - "x": 9, - "y": 30, - "enter": "walk_into" - } - ], - "objects": [ - { - "name": "lass", - "kind": "npc", - "x": 6, - "y": 15 - }, - { - "name": "man", - "kind": "npc", - "x": 33, - "y": 17, - "hide_flag": "FLAG_HIDE_PEWTER_MUSEUM_GUIDE" - }, - { - "name": "fat_man", - "kind": "npc", - "x": 21, - "y": 28 - }, - { - "name": "bug_catcher", - "kind": "npc", - "x": 33, - "y": 27, - "wander": { - "x0": 31, - "y0": 27, - "x1": 35, - "y1": 27 - } - }, - { - "name": "boy", - "kind": "npc", - "x": 42, - "y": 20, - "hide_flag": "FLAG_HIDE_PEWTER_CITY_GYM_GUIDE" - }, - { - "name": "cut_tree", - "kind": "npc", - "x": 30, - "y": 5, - "hide_flag": "FLAG_TEMP_12" - }, - { - "name": "scientist", - "kind": "npc", - "x": 46, - "y": 20, - "hide_flag": "FLAG_HIDE_PEWTER_CITY_RUNNING_SHOES_GUY" - } - ], - "flag_sets": {}, - "connections": [ - { - "side": "south", - "to_map": "Route2", - "offset": 12 - } - ] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Gym.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Gym.json deleted file mode 100644 index 75afb1541c..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Gym.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "name": "PewterCity_Gym", - "source": { - "decomp_file": "data/maps/PewterCity_Gym/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "#############", - "####.....####", - "#############", - "#....#.#....#", - "#...........#", - "#...#...#...#", - "#...........#", - "#..#.#.#.#..#", - "##.........##", - "#...#...#...#", - "##.........##", - "#...........#", - "#...S...S...#", - "#...........#", - "#...........#", - "#############" - ], - "points": { - "brock_front": [6, 6], - "warp_1": [6, 14] - }, - "warps": [ - { - "x": 5, - "y": 14, - "enter": "walk_into", - "to_map": "PewterCity", - "to_point": "warp_2" - }, - { - "x": 6, - "y": 14, - "enter": "walk_south", - "to_map": "PewterCity", - "to_point": "warp_2" - }, - { - "x": 7, - "y": 14, - "enter": "walk_into", - "to_map": "PewterCity", - "to_point": "warp_2" - } - ], - "objects": [ - { - "name": "brock", - "kind": "npc", - "x": 6, - "y": 5 - }, - { - "name": "camper", - "kind": "npc", - "x": 3, - "y": 8 - }, - { - "name": "gym_guy", - "kind": "npc", - "x": 7, - "y": 12 - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Mart.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Mart.json deleted file mode 100644 index 7b4e49dea9..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Mart.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "name": "PewterCity_Mart", - "source": { - "decomp_file": "data/maps/PewterCity_Mart/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "###########", - "###########", - "##.#......#", - "...#.......", - "####...##.#", - ".......##.#", - ".##....##.#", - "...........", - "###########" - ], - "elevation": [ - "00000000000", - "00000000000", - "00303333330", - "33003333333", - "00003330030", - "33333330030", - "30033330030", - "33333333333", - "00000000000" - ], - "points": { - "warp_1": [4, 7] - }, - "warps": [ - { - "x": 3, - "y": 7, - "enter": "walk_into", - "to_map": "PewterCity", - "to_point": "warp_3" - }, - { - "x": 4, - "y": 7, - "enter": "walk_south", - "to_map": "PewterCity", - "to_point": "warp_3" - }, - { - "x": 5, - "y": 7, - "enter": "walk_into", - "to_map": "PewterCity", - "to_point": "warp_3" - } - ], - "objects": [ - { - "name": "youngster", - "kind": "npc", - "x": 8, - "y": 2 - }, - { - "name": "boy", - "kind": "npc", - "x": 6, - "y": 4 - }, - { - "name": "clerk", - "kind": "npc", - "x": 2, - "y": 3 - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Museum_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Museum_1F.json deleted file mode 100644 index 1ea83f0faf..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Museum_1F.json +++ /dev/null @@ -1,108 +0,0 @@ -{ - "name": "PewterCity_Museum_1F", - "source": { - "decomp_file": "data/maps/PewterCity_Museum_1F/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "############################", - "############################", - "...............#............", - "...............#......#....#", - "...####........#...........#", - "...............#............", - "...........#...#...........#", - "...####..###...###.........#", - ".........###.....#..........", - "#........###....##......##..", - "############################" - ], - "points": { - "warp_1": [14, 9], - "warp_3": [21, 9] - }, - "warps": [ - { - "x": 13, - "y": 9, - "enter": "walk_into", - "to_map": "PewterCity", - "to_point": "warp_0" - }, - { - "x": 14, - "y": 9, - "enter": "walk_south", - "to_map": "PewterCity", - "to_point": "warp_0" - }, - { - "x": 15, - "y": 9, - "enter": "walk_into", - "to_map": "PewterCity", - "to_point": "warp_0" - }, - { - "x": 21, - "y": 9, - "enter": "walk_south", - "to_map": "PewterCity", - "to_point": "warp_1" - }, - { - "x": 22, - "y": 9, - "enter": "walk_into", - "to_map": "PewterCity", - "to_point": "warp_1" - }, - { - "x": 8, - "y": 8, - "enter": "walk_east" - } - ], - "objects": [ - { - "name": "worker_m", - "kind": "npc", - "x": 16, - "y": 5 - }, - { - "name": "old_man_1", - "kind": "npc", - "x": 2, - "y": 4 - }, - { - "name": "scientist", - "kind": "npc", - "x": 21, - "y": 3 - }, - { - "name": "old_amber", - "kind": "npc", - "x": 22, - "y": 3, - "hide_flag": "FLAG_HIDE_OLD_AMBER" - }, - { - "name": "scientist", - "kind": "npc", - "x": 26, - "y": 4 - }, - { - "name": "scientist", - "kind": "npc", - "x": 26, - "y": 7 - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_PokemonCenter_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_PokemonCenter_1F.json deleted file mode 100644 index 90267e027f..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_PokemonCenter_1F.json +++ /dev/null @@ -1,110 +0,0 @@ -{ - "name": "PewterCity_PokemonCenter_1F", - "source": { - "decomp_file": "data/maps/PewterCity_PokemonCenter_1F/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "#.#############", - "###############", - "....###..##....", - "....#######....", - "...............", - "...............", - "#..........##..", - "...........##..", - "...............", - "###############" - ], - "elevation": [ - "030000000000000", - "000000000000000", - "333300033003333", - "333300000003333", - "333333333333333", - "330333333333333", - "044033333330033", - "330333333330033", - "333333333333333", - "000000000000000" - ], - "points": { - "nurse_front": [7, 4], - "warp_1": [7, 8] - }, - "warps": [ - { - "x": 6, - "y": 8, - "enter": "walk_into", - "to_map": "PewterCity", - "to_point": "warp_5" - }, - { - "x": 7, - "y": 8, - "enter": "walk_south", - "to_map": "PewterCity", - "to_point": "warp_5" - }, - { - "x": 8, - "y": 8, - "enter": "walk_into", - "to_map": "PewterCity", - "to_point": "warp_5" - }, - { - "x": 1, - "y": 6, - "enter": "step_on" - } - ], - "objects": [ - { - "name": "jigglypuff", - "kind": "npc", - "x": 2, - "y": 2 - }, - { - "name": "gentleman", - "kind": "npc", - "x": 4, - "y": 8 - }, - { - "name": "nurse", - "kind": "npc", - "x": 7, - "y": 2 - }, - { - "name": "youngster", - "kind": "npc", - "x": 1, - "y": 2 - }, - { - "name": "woman_1", - "kind": "npc", - "x": 13, - "y": 2 - }, - { - "name": "gba_kid", - "kind": "npc", - "x": 10, - "y": 7 - }, - { - "name": "gba_kid", - "kind": "npc", - "x": 14, - "y": 6 - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route1.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route1.json deleted file mode 100644 index c48c746b72..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route1.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "name": "Route1", - "source": { - "decomp_file": "data/maps/Route1/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "##########....##########", - "##########....##########", - "##....................##", - "##....................##", - "##......##............##", - "##vvvvvv##vvvvvv......##", - "##......##~~~~~~~~~~~~##", - "##......##~~~~~~~~~~~~##", - "##......##~~~~~~~~~~~~##", - "##......##~~~~~~~~~~~~##", - "##vvvvvv##~~~~~~~~~~~~##", - "##......##............##", - "##....................##", - "##..............~~~~~~##", - "##..............~~~~~~##", - "####vvvvvv######~~~~~~##", - "####......######~~~~~~##", - "##..............~~~~~~##", - "##....................##", - "##....................##", - "##vv.vvvv..vvvvvvvvvvv##", - "##....................##", - "##....................##", - "##....................##", - "##..........~~~~~~....##", - "############~~~~~~....##", - "############~~~~~~vvvv##", - "##..........~~~~~~....##", - "##..........~~~~~~....##", - "##....................##", - "##....................##", - "##vvvv...Svvvvvvvvvvvv##", - "##..~~~~~~~......~~~~~##", - "##..~~~~~~~......~~~~~##", - "##~~~~~~~......~~~~~..##", - "##~~~~~~~...~~.~~~~~..##", - "############~~##########", - "##.........#~~#.......##", - "############~~##########", - "############~~##########" - ], - "points": {}, - "warps": [], - "objects": [ - { - "name": "clerk", - "kind": "npc", - "x": 6, - "y": 28, - "wander": { - "x0": 6, - "y0": 27, - "x1": 6, - "y1": 29 - } - }, - { - "name": "boy", - "kind": "npc", - "x": 19, - "y": 16, - "wander": { - "x0": 18, - "y0": 16, - "x1": 20, - "y1": 16 - } - } - ], - "flag_sets": {}, - "connections": [ - { - "side": "north", - "to_map": "ViridianCity", - "offset": -12 - }, - { - "side": "south", - "to_map": "PalletTown", - "offset": 0 - } - ] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2.json deleted file mode 100644 index 706949faeb..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2.json +++ /dev/null @@ -1,211 +0,0 @@ -{ - "name": "Route2", - "source": { - "decomp_file": "data/maps/Route2/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "########....############", - "########....############", - "##~~~~~~~...############", - "##~~~~~~~...#.........##", - "##~~~~~~~...#.........##", - "##~~~~~~~...#.........##", - "##~~~~~~~...#########.##", - "##~~~~~~~...#########.##", - "##~~~~~~~...#########.##", - "##..........#########.##", - "##..........#########.##", - "##..........#####.###.##", - "##..........#.S.......##", - "####....###.#.........##", - "###########...........##", - "##########............##", - "##############........##", - "##############........##", - "##############........##", - "##############........##", - "##############........##", - "###################...##", - "#################D#...##", - "##############........##", - "################......##", - "################......##", - "##################.#####", - "################......##", - "################......##", - "################......##", - "################......##", - "################......##", - "################vvv.vv##", - "################......##", - "################......##", - "################......##", - "################......##", - "################vvv.vv##", - "################......##", - "################......##", - "################......##", - "#################....###", - "########################", - "########################", - "########################", - "##........##############", - "##################..####", - "#################....###", - "################......##", - "################......##", - "###.####.#######......##", - "#####..#########vvv.vv##", - "####....########......##", - "##............##......##", - "##............##......##", - "##vvvvvvvvv...##......##", - "##....~~~~~~~.##......##", - "##....~~~~~~~.##vv.vvv##", - "##....~~~~~~~.##......##", - "##....~~~~~~~.##......##", - "##....~~~~~~~.##......##", - "##............##......##", - "##....................##", - "##....##########......##", - "##....##########......##", - "##....##########......##", - "##....##########......##", - "##............##......##", - "##............##......##", - "##....................##", - "##vvvvvvv..vvv..vv.vvv##", - "##............##......##", - "####..........##......##", - "####...S......##......##", - "####..........##......##", - "####..........##......##", - "####..........##......##", - "####..........##......##", - "#######.......##########", - "#######.....############" - ], - "points": { - "warp_0": [5, 13], - "warp_2": [5, 51] - }, - "warps": [ - { - "x": 5, - "y": 13, - "enter": "walk_south", - "to_map": "Route2_ViridianForest_NorthEntrance", - "to_point": "warp_3" - }, - { - "x": 6, - "y": 13, - "enter": "walk_south", - "to_map": "Route2_ViridianForest_NorthEntrance", - "to_point": "warp_3" - }, - { - "x": 5, - "y": 51, - "enter": "cave_entrance", - "to_map": "Route2_ViridianForest_SouthEntrance", - "to_point": "warp_1" - }, - { - "x": 17, - "y": 11, - "enter": "cave_entrance" - }, - { - "x": 17, - "y": 22, - "enter": "walk_into" - }, - { - "x": 18, - "y": 46, - "enter": "cave_entrance" - }, - { - "x": 18, - "y": 41, - "enter": "walk_south" - }, - { - "x": 19, - "y": 41, - "enter": "walk_south" - }, - { - "x": 19, - "y": 46, - "enter": "cave_entrance" - }, - { - "x": 6, - "y": 51, - "enter": "cave_entrance", - "to_map": "Route2_ViridianForest_SouthEntrance", - "to_point": "warp_1" - } - ], - "objects": [ - { - "name": "cut_tree", - "kind": "npc", - "x": 16, - "y": 62, - "hide_flag": "FLAG_TEMP_14" - }, - { - "name": "cut_tree", - "kind": "npc", - "x": 15, - "y": 69, - "hide_flag": "FLAG_TEMP_13" - }, - { - "name": "cut_tree", - "kind": "npc", - "x": 11, - "y": 13, - "hide_flag": "FLAG_TEMP_15" - }, - { - "name": "cut_tree", - "kind": "npc", - "x": 18, - "y": 26, - "hide_flag": "FLAG_TEMP_16" - }, - { - "name": "item_ball", - "kind": "item", - "x": 17, - "y": 54, - "hide_flag": "FLAG_HIDE_ROUTE2_ETHER" - }, - { - "name": "item_ball", - "kind": "item", - "x": 17, - "y": 64, - "hide_flag": "FLAG_HIDE_ROUTE2_PARALYZE_HEAL" - } - ], - "flag_sets": {}, - "connections": [ - { - "side": "north", - "to_map": "PewterCity", - "offset": -12 - }, - { - "side": "south", - "to_map": "ViridianCity", - "offset": -12 - } - ] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route22.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route22.json deleted file mode 100644 index be2d5629b2..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route22.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "name": "Route22", - "source": { - "decomp_file": "data/maps/Route22/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "#############################################...", - "###########################################.#...", - "##################################........#.###.", - "##################################vvvv.vvv#...##", - "######################....................#.....", - "########D######...........................######", - "#####.......###.........................##......", - "###...........#.............######......##......", - "###...........#vvvvvvvwwwwww######vv..vv##......", - "###vvvvvvv..vv#~~~~~~~wwwwww######~~~~~~##......", - "###...........#~~~~~~~wwwwww######~~~~~~##....##", - "###...........#~~~~~~~wwwwww######~~~~~~##....##", - "####...S#######~~~~~~~......######~~~~~~##....##", - "####...........~~~~~~~......######~~~~~~##....##", - "####........................######............##", - "####vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv..vvvvv##", - "####..........................................##", - "####..........................................##", - "####..........................................##", - "################################################", - "################################################", - "################################################", - "################################################", - "################################################" - ], - "elevation": [ - "000000000000000000000000000000000000000000000333", - "000000000000000000000000000000000000000000030333", - "000000000000000000000000000000000033333333030003", - "000000000000000000000000000000000000003000033300", - "000000000000000000000033333333333333333333033333", - "000000000000000333333333333333333333333333000000", - "000003333333000333333333333333333333333300333333", - "000333333333330333333333333300000033333300333333", - "000333333333330000000011111100000000330000333333", - "000000000033000333333311111100000033333300333333", - "000333333333330333333311111100000033333300333300", - "000333333333330333333311111100000033333300333300", - "000033300000000333333333333300000033333300333300", - "000033333333333333333333333300000033333300333300", - "000033333333333333333333333300000033333333333300", - "000000000000000000000000000000000000000330000000", - "000033333333333333333333333333333333333333333300", - "000033333333333333333333333333333333333333333300", - "000033333333333333333333333333333333333333333300", - "000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000000" - ], - "points": {}, - "warps": [ - { - "x": 8, - "y": 5, - "enter": "walk_into" - }, - { - "x": 9, - "y": 5, - "enter": "walk_into" - } - ], - "objects": [ - { - "name": "blue", - "kind": "npc", - "x": 25, - "y": 4, - "hide_flag": "FLAG_HIDE_ROUTE_22_RIVAL" - } - ], - "flag_sets": {}, - "connections": [ - { - "side": "east", - "to_map": "ViridianCity", - "offset": -10 - } - ] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route24.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route24.json deleted file mode 100644 index 59d1789c3c..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route24.json +++ /dev/null @@ -1,154 +0,0 @@ -{ - "name": "Route24", - "source": { - "decomp_file": "data/maps/Route24/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "########################", - "########################", - "########################", - "####.........>...<......", - "####.........>...<......", - "####.........>...<......", - "###vvvv..vvvv#...#vvvvvv", - "###.....................", - "###.....................", - "###.....................", - "###..........###########", - "###..........#..........", - "###..........#...#######", - "###..........#...#######", - "###..........#...#######", - "###..........#...#######", - "###...www#...#...#######", - "###...www#...#...#######", - "###...www#...#...#######", - "###~~~www#...#...#######", - "###~~~www#...#...#######", - "###~~~www#...#...#######", - "###~~~www#...#...#######", - "###~~~www#...#...#######", - "###~~~www#...#...#######", - "###~~~www#...#...#######", - "###~~~www#...#...#######", - "###~~~www#...#...#wwwwww", - "###~~~www#...#...#wwwwww", - "###~~~www#...#...#wwwwww", - "###~~~www#...#...#wwwwww", - "###~~~www#...#...#wwwwww", - "####wwwww#...#...#wwwwww", - "####wwwww#...#...#wwwwww", - "####wwwww#...#...#wwwwww", - "####wwwww#...#...#wwwwww", - "####wwwww#...#...#wwwwww", - "####wwwww#...#...#wwwwww", - "####wwwww#...#...#wwwwww", - "####wwwww#...#...#wwwwww" - ], - "elevation": [ - "000000000000000000000000", - "000000000000000000000000", - "000000000000000000000000", - "000033333333303330333333", - "000033333333303330333333", - "000033333333303330333333", - "000000033000003330000000", - "000333333333333333333333", - "000333333333333333333333", - "000333333333333333333333", - "000333333333300000000000", - "000333333333303333333333", - "000333333333303330000000", - "000333333333303330000000", - "000333333333303330000000", - "000333333333303330000000", - "000333111033303330000000", - "000333111033303330000000", - "000333111033303330000000", - "000333111033303330000000", - "000333111033303330000000", - "000333111033303330000000", - "000333111033303330000000", - "000333111033303330000000", - "000333111033303330000000", - "000333111033303330000000", - "000333111033303330000000", - "000333111033303330111111", - "000333111033303330100000", - "000333111033303330100000", - "000333111033303330100000", - "000333111033303330100000", - "000011111033303330100000", - "000011111033303330100000", - "000011111033303330100000", - "000011111033303330100000", - "000011111033303330100000", - "000011111033303330100000", - "000011111033303330100000", - "000011111033303330100000" - ], - "points": {}, - "warps": [], - "objects": [ - { - "name": "man", - "kind": "npc", - "x": 12, - "y": 15, - "hide_flag": "FLAG_HIDE_NUGGET_BRIDGE_ROCKET" - }, - { - "name": "camper", - "kind": "npc", - "x": 12, - "y": 19 - }, - { - "name": "lass", - "kind": "npc", - "x": 10, - "y": 22 - }, - { - "name": "youngster", - "kind": "npc", - "x": 12, - "y": 25 - }, - { - "name": "lass", - "kind": "npc", - "x": 10, - "y": 28 - }, - { - "name": "bug_catcher", - "kind": "npc", - "x": 12, - "y": 31 - }, - { - "name": "camper", - "kind": "npc", - "x": 5, - "y": 21 - }, - { - "name": "item_ball", - "kind": "item", - "x": 11, - "y": 4, - "hide_flag": "FLAG_HIDE_ROUTE24_TM45" - } - ], - "flag_sets": {}, - "connections": [ - { - "side": "south", - "to_map": "CeruleanCity", - "offset": -12 - } - ] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_NorthEntrance.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_NorthEntrance.json deleted file mode 100644 index 021edbb11d..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_NorthEntrance.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "name": "Route2_ViridianForest_NorthEntrance", - "source": { - "decomp_file": "data/maps/Route2_ViridianForest_NorthEntrance/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "###############", - "#######.#######", - "##...#...#...##", - "#.............#", - "#..........##.#", - "###........##.#", - "#.............#", - "#..........##.#", - "###........##.#", - "#.............#", - "#.............#", - "###############" - ], - "points": { - "warp_1": [7, 10], - "warp_3": [7, 1] - }, - "warps": [ - { - "x": 6, - "y": 10, - "enter": "walk_into", - "to_map": "ViridianForest", - "to_point": "warp_2" - }, - { - "x": 7, - "y": 10, - "enter": "walk_south", - "to_map": "ViridianForest", - "to_point": "warp_2" - }, - { - "x": 8, - "y": 10, - "enter": "walk_into", - "to_map": "ViridianForest", - "to_point": "warp_2" - }, - { - "x": 7, - "y": 1, - "enter": "cave_entrance", - "to_map": "Route2", - "to_point": "warp_0" - } - ], - "objects": [ - { - "name": "youngster", - "kind": "npc", - "x": 5, - "y": 4 - }, - { - "name": "old_man_1", - "kind": "npc", - "x": 4, - "y": 7 - }, - { - "name": "cooltrainer_f", - "kind": "npc", - "x": 10, - "y": 5 - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_SouthEntrance.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_SouthEntrance.json deleted file mode 100644 index 3b00abc4eb..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_SouthEntrance.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "name": "Route2_ViridianForest_SouthEntrance", - "source": { - "decomp_file": "data/maps/Route2_ViridianForest_SouthEntrance/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "###############", - "#######.#######", - "##...#...#...##", - "#.............#", - "#..........##.#", - "###........##.#", - "#.............#", - "#..........##.#", - "###........##.#", - "#.............#", - "#.............#", - "###############" - ], - "points": { - "warp_1": [7, 10], - "warp_3": [7, 1] - }, - "warps": [ - { - "x": 6, - "y": 10, - "enter": "walk_into", - "to_map": "Route2", - "to_point": "warp_2" - }, - { - "x": 7, - "y": 10, - "enter": "walk_south", - "to_map": "Route2", - "to_point": "warp_2" - }, - { - "x": 8, - "y": 10, - "enter": "walk_into", - "to_map": "Route2", - "to_point": "warp_2" - }, - { - "x": 7, - "y": 1, - "enter": "cave_entrance", - "to_map": "ViridianForest", - "to_point": "warp_0" - } - ], - "objects": [ - { - "name": "woman_2", - "kind": "npc", - "x": 10, - "y": 6 - }, - { - "name": "woman_1", - "kind": "npc", - "x": 4, - "y": 7, - "wander": { - "x0": 3, - "y0": 6, - "x1": 5, - "y1": 8 - } - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity.json deleted file mode 100644 index 5bf976082a..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity.json +++ /dev/null @@ -1,216 +0,0 @@ -{ - "name": "ViridianCity", - "source": { - "decomp_file": "data/maps/ViridianCity/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "###################.....########################", - "###################....S########################", - "###################.....########################", - "###################.....########################", - "###################.....####..............######", - "########..................................######", - "########.##########.......................######", - "########.###########.............######...######", - "########.##########..............######...######", - "########.###########...######....######...######", - "########.##########.....#####...S..#D#....######", - "########.###########...##D###.............######", - "########.##########........##vvvvvvvvvvvvv######", - "########.###########......................######", - "########.##########.......................######", - "######...###########.........###################", - ".........##########.S..######.............######", - "........................#####.....####....######", - ".......................##D###.....####....######", - "..................................SSD#....######", - "#######...................................######", - "#######...................................######", - "#######...................................######", - "###########.............#####.............######", - "###########.##..........#####.............######", - "#######.....##..........#####.............######", - "#######....wwwwww.......SSD##.............######", - "#######....wwwwww.........................######", - "#######....wwwwww.........................######", - "#######....wwwwww.........................######", - "#######vvvvwwwwwwvvv...vvvvvvvvvvvvvvvvvvv######", - "#######.............S.....................######", - "#######...................................######", - "#######...................................######", - "##############............................######", - "##############............................######", - "######################....######################", - "######################....######################", - "######################....######################", - "######################....######################" - ], - "elevation": [ - "000000000000000000033333000000000000000000000000", - "000000000000000000033330000000000000000000000000", - "000000000000000000033333000000000000000000000000", - "000000000000000000033333000000000000000000000000", - "000000000000000000033333000033333333333333000000", - "000000003333333333333333333333333333333333000000", - "000000003000000000033333333333333333333333000000", - "000000003000000000003333333333333000000333000000", - "000000003000000000033333333333333000000333000000", - "000000003000000000003330000003333000000333000000", - "000000003000000000033333000003330330003333000000", - "000000003000000000003330000003333333333333000000", - "000000003000000000033333333000000000000000000000", - "000000003000000000003333333333333333333333000000", - "000000003000000000033333333333333333333333000000", - "000000333000000000003333333330000000000000000000", - "333333333000000000030330000003333333333333000000", - "333333333333333333333333000003333300003333000000", - "333333333333333333333330000003333300003333000000", - "333333333333333333333333333333333300003333000000", - "000000033333333333333333333333333333333333000000", - "000000033333333333333333333333333333333333000000", - "000000033333333333333333333333333333333333000000", - "000000000003333333333333000003333333333333000000", - "000000000003003333333333000003333333333333000000", - "000000033333003333333333000003333333333333000000", - "000000033331111113333333000003333333333333000000", - "000000033331111113333333333333333333333333000000", - "000000033331111113333333333333333333333333000000", - "000000033331111113333333333333333333333333000000", - "000000000001111110003330000000000000000000000000", - "000000033333333333330333333333333333333333000000", - "000000033333333333333333333333333333333333000000", - "000000033333333333333333333333333333333333000000", - "000000000000003333333333333333333333333333000000", - "000000000000003333333333333333333333333333000000", - "000000000000000000000033330000000000000000000000", - "000000000000000000000033330000000000000000000000", - "000000000000000000000033330000000000000000000000", - "000000000000000000000033330000000000000000000000" - ], - "points": { - "warp_0": [26, 26], - "warp_4": [36, 19] - }, - "warps": [ - { - "x": 26, - "y": 26, - "enter": "walk_into", - "to_map": "ViridianCity_PokemonCenter_1F", - "to_point": "warp_1" - }, - { - "x": 25, - "y": 11, - "enter": "walk_into" - }, - { - "x": 36, - "y": 10, - "enter": "walk_into" - }, - { - "x": 25, - "y": 18, - "enter": "walk_into" - }, - { - "x": 36, - "y": 19, - "enter": "walk_into", - "to_map": "ViridianCity_Mart", - "to_point": "warp_1" - } - ], - "objects": [ - { - "name": "fat_man", - "kind": "npc", - "x": 8, - "y": 26 - }, - { - "name": "cut_tree", - "kind": "npc", - "x": 11, - "y": 24, - "hide_flag": "FLAG_TEMP_11" - }, - { - "name": "old_man_1", - "kind": "npc", - "x": 34, - "y": 11 - }, - { - "name": "var_0", - "kind": "npc", - "x": 21, - "y": 6 - }, - { - "name": "woman_3", - "kind": "npc", - "x": 20, - "y": 12 - }, - { - "name": "youngster", - "kind": "npc", - "x": 33, - "y": 26, - "wander": { - "x0": 33, - "y0": 24, - "x1": 33, - "y1": 28 - } - }, - { - "name": "boy", - "kind": "npc", - "x": 16, - "y": 22, - "wander": { - "x0": 15, - "y0": 20, - "x1": 17, - "y1": 24 - } - }, - { - "name": "cut_tree", - "kind": "npc", - "x": 18, - "y": 5, - "hide_flag": "FLAG_TEMP_12" - }, - { - "name": "item_ball", - "kind": "item", - "x": 17, - "y": 5, - "hide_flag": "FLAG_HIDE_VIRIDIAN_CITY_POTION" - } - ], - "flag_sets": {}, - "connections": [ - { - "side": "north", - "to_map": "Route2", - "offset": 12 - }, - { - "side": "south", - "to_map": "Route1", - "offset": 12 - }, - { - "side": "west", - "to_map": "Route22", - "offset": 10 - } - ] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_Mart.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_Mart.json deleted file mode 100644 index 1078ec3405..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_Mart.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "name": "ViridianCity_Mart", - "source": { - "decomp_file": "data/maps/ViridianCity_Mart/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "###########", - "###########", - "##.#......#", - "...#.......", - "####...##.#", - ".......##.#", - ".##....##.#", - "...........", - "###########" - ], - "elevation": [ - "00000000000", - "00000000000", - "00303333330", - "33003333333", - "00003330030", - "33333330030", - "30033330030", - "33333333333", - "00000000000" - ], - "points": { - "clerk_front": [4, 3], - "warp_1": [4, 7] - }, - "warps": [ - { - "x": 3, - "y": 7, - "enter": "walk_into", - "to_map": "ViridianCity", - "to_point": "warp_4" - }, - { - "x": 4, - "y": 7, - "enter": "walk_south", - "to_map": "ViridianCity", - "to_point": "warp_4" - }, - { - "x": 5, - "y": 7, - "enter": "walk_into", - "to_map": "ViridianCity", - "to_point": "warp_4" - } - ], - "objects": [ - { - "name": "clerk", - "kind": "npc", - "x": 2, - "y": 3 - }, - { - "name": "youngster", - "kind": "npc", - "x": 6, - "y": 2, - "wander": { - "x0": 5, - "y0": 1, - "x1": 7, - "y1": 3 - } - }, - { - "name": "woman_1", - "kind": "npc", - "x": 9, - "y": 5, - "wander": { - "x0": 9, - "y0": 4, - "x1": 9, - "y1": 6 - } - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_PokemonCenter_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_PokemonCenter_1F.json deleted file mode 100644 index 63a2707d8f..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_PokemonCenter_1F.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "name": "ViridianCity_PokemonCenter_1F", - "source": { - "decomp_file": "data/maps/ViridianCity_PokemonCenter_1F/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "#.#############", - "###############", - "....###..##....", - "....#######....", - "...............", - "...............", - "#..........##..", - "...........##..", - "...............", - "###############" - ], - "elevation": [ - "030000000000000", - "000000000000000", - "333300033003333", - "333300000003333", - "333333333333333", - "330333333333333", - "044033333330033", - "330333333330033", - "333333333333333", - "000000000000000" - ], - "points": { - "nurse_front": [7, 4], - "warp_1": [7, 8] - }, - "warps": [ - { - "x": 6, - "y": 8, - "enter": "walk_into", - "to_map": "ViridianCity", - "to_point": "warp_0" - }, - { - "x": 7, - "y": 8, - "enter": "walk_south", - "to_map": "ViridianCity", - "to_point": "warp_0" - }, - { - "x": 8, - "y": 8, - "enter": "walk_into", - "to_map": "ViridianCity", - "to_point": "warp_0" - }, - { - "x": 1, - "y": 6, - "enter": "step_on" - } - ], - "objects": [ - { - "name": "nurse", - "kind": "npc", - "x": 7, - "y": 2 - }, - { - "name": "gentleman", - "kind": "npc", - "x": 12, - "y": 5 - }, - { - "name": "boy", - "kind": "npc", - "x": 4, - "y": 7 - }, - { - "name": "youngster", - "kind": "npc", - "x": 2, - "y": 3, - "wander": { - "x0": 1, - "y0": 2, - "x1": 3, - "y1": 4 - } - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianForest.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianForest.json deleted file mode 100644 index 93352339c5..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianForest.json +++ /dev/null @@ -1,201 +0,0 @@ -{ - "name": "ViridianForest", - "source": { - "decomp_file": "data/maps/ViridianForest/map.json", - "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", - "date": "2026-10-31" - }, - "tiles": [ - "######################################################", - "######################################################", - "######################################################", - "######################################################", - "######################################################", - "###########.............###........................###", - "###########.............###........................###", - "###########.............###........................###", - "#..#####..#.............###.....###############....###", - "####...####.............###.....###############....###", - "####...####.............###.....###############....###", - "####...####.....###.....###.....###############....###", - "####..S####~~~~~###~~~~~###~~~~~###############....###", - "###~~~~~###~~~~~###~~~~~###~~~~~###############....###", - "###~~~~~###~~~~~###~~~~~###~~~~~###############....###", - "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~~.............###", - "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~~.............###", - "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~~.............###", - "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~~.......#########", - "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~........#########", - "###~~~~~###~~~~~###~~~~~###~~~~~~######......#########", - "###~~~~~###~~~~~###~~~~~###...~~~######......#########", - "###~~~~~###~~~~~###.....###......######......#########", - "###~~~~~###~~~~~###..............######......#########", - "###~~~~~###~~~~~#####............######......#########", - "###~~~~~###~~~~~#####............######............###", - "###~~~~~###~~~~~~~#####################....S.......###", - "###~~~~~...~~~~~~~#####################............###", - "###...............#####################............###", - "###......S........#####################~~~~........###", - "###...............#####################~~~~~###....###", - "###.....................###############~~~~~###....###", - "###.....................###############~~~~~###....###", - "###.....................###############~~~~~###....###", - "##################......###############~~~~~###....###", - "##################......###############~~~~~###....###", - "#######################################~~~~~###....###", - "#######################################~~~~~###....###", - "#######################################~~~~~###....###", - "###~~~~~~~~~~~~~~~#####################~~~~~###....###", - "###~~~~~~~~~~~~~~~#####################~~~~~###....###", - "###~~~~~~~~~~~~~~~#####################~~~~~###....###", - "###~~~~~~~~~~~~~~~#####################~~~~~###....###", - "###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~######~~~~........###", - "############~~~~~~~~~~~~~~~~S..~~######~~~.........###", - "############~~~~~~~~~~~~~~~~...~~######~~~.........###", - "############..~~~#########~~...~~######~~~...#########", - "############..~~~#########~~...~~######~~~...#########", - "############..~~~#########~~...~~######~~~...#########", - "############..~~~#########~~...~~######~~~...#########", - "############..~~~#########~~...~~######~~~...#########", - "############..~~~#########~~...~~######~~~...#########", - "############..~~~#########~~...~~######~~~...#########", - "############..~~~#########~~...~~######~~~...#########", - "############..~~~#########~~...~~######~~~...#########", - "###~~~~~~~~~..~~~~~~~~~~~~~~###~~~~~~~~~~~...~~~~~~###", - "###~~~~~~~~~..~~~~~~~~~~~~~~###~~~~~~~~~~~...~~~~~~###", - "###~~~~~~~~~...~~~~~~~~~~~~.###.~~~~~~~~~...~~~~~~~###", - "###~~~~~~~~~....~~~~~~~~~~.......~~~~~~~....~~~~~~~###", - "###~~~~~~~~............................S....~~~~~~~###", - "###~~~~~~~~....................S...........~~~~~~~~###", - "###~~~~~~~~................................~~~~~~~~###", - "###########################......#####################", - "######################################################", - "######################################################", - "######################################################", - "######################################################", - "######################################################", - "######################################################" - ], - "points": { - "warp_0": [29, 62], - "warp_2": [5, 9] - }, - "warps": [ - { - "x": 29, - "y": 62, - "enter": "walk_south", - "to_map": "Route2_ViridianForest_SouthEntrance", - "to_point": "warp_3" - }, - { - "x": 28, - "y": 62, - "enter": "walk_south", - "to_map": "Route2_ViridianForest_SouthEntrance", - "to_point": "warp_3" - }, - { - "x": 5, - "y": 9, - "enter": "cave_entrance", - "to_map": "Route2_ViridianForest_NorthEntrance", - "to_point": "warp_1" - }, - { - "x": 6, - "y": 9, - "enter": "cave_entrance", - "to_map": "Route2_ViridianForest_NorthEntrance", - "to_point": "warp_1" - }, - { - "x": 30, - "y": 62, - "enter": "walk_south", - "to_map": "Route2_ViridianForest_SouthEntrance", - "to_point": "warp_3" - }, - { - "x": 4, - "y": 9, - "enter": "cave_entrance", - "to_map": "Route2_ViridianForest_NorthEntrance", - "to_point": "warp_1" - } - ], - "objects": [ - { - "name": "youngster", - "kind": "npc", - "x": 29, - "y": 58 - }, - { - "name": "boy", - "kind": "npc", - "x": 45, - "y": 58 - }, - { - "name": "bug_catcher", - "kind": "npc", - "x": 47, - "y": 45 - }, - { - "name": "bug_catcher", - "kind": "npc", - "x": 47, - "y": 29 - }, - { - "name": "bug_catcher", - "kind": "npc", - "x": 7, - "y": 22 - }, - { - "name": "item_ball", - "kind": "item", - "x": 5, - "y": 41, - "hide_flag": "FLAG_HIDE_VIRIDIAN_FOREST_POKE_BALL" - }, - { - "name": "item_ball", - "kind": "item", - "x": 40, - "y": 21, - "hide_flag": "FLAG_HIDE_VIRIDIAN_FOREST_ANTIDOTE" - }, - { - "name": "item_ball", - "kind": "item", - "x": 21, - "y": 34, - "hide_flag": "FLAG_HIDE_VIRIDIAN_FOREST_POTION" - }, - { - "name": "bug_catcher", - "kind": "npc", - "x": 43, - "y": 6 - }, - { - "name": "bug_catcher", - "kind": "npc", - "x": 16, - "y": 5 - }, - { - "name": "item_ball", - "kind": "item", - "x": 49, - "y": 60, - "hide_flag": "FLAG_HIDE_VIRIDIAN_FOREST_POTION_2" - } - ], - "flag_sets": {}, - "connections": [] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h index 84a6745fd8..f561970d25 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h @@ -8,8 +8,8 @@ * Center, Route 24 to its north, and the three floors of Cerulean Cave, * where Mewtwo waits on B1F. * - * Each map is a JSON file, Maps/.json next to this file, generated by - * devtools/maps/frlg_maps.py and built into the program by CMake + * Each map is a pinned PokemonSimulation JSON resource, prepared under + * Packages/Resources/Pokemon/Maps/frlg and built into the program by CMake * (pa_embed_text_files() in cmake/EmbedTextFiles.cmake), so the program and * its tests read the same copy. The schema is Pokemon::MapData's * (Pokemon/Navigation/Pokemon_MapData.h). A warp leads to point diff --git a/SerialPrograms/cmake/PokesimMapResources.cmake b/SerialPrograms/cmake/PokesimMapResources.cmake new file mode 100644 index 0000000000..67d0124ce1 --- /dev/null +++ b/SerialPrograms/cmake/PokesimMapResources.cmake @@ -0,0 +1,15 @@ +# Resolve FRLG's prepared map input. Configuration never prepares or downloads maps. +# Supply -DPOKESIM_TOOLS_SOURCE=/path/to/tools -DPOKESIM_SOURCE_CACHE=/path/to/cache. +# See devtools/maps/RESOURCE_MAPS.md for the explicit prepare step and pinned CI. +function(pa_frlg_map_resources OUT) + get_filename_component(CONSUMER "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../.." ABSOLUTE) + set(POKESIM_TOOLS_SOURCE "$ENV{POKESIM_TOOLS_SOURCE}" CACHE PATH "Pinned PokemonSimulation tools checkout") + set(POKESIM_SOURCE_CACHE "$ENV{POKESIM_SOURCE_CACHE}" CACHE PATH "Approved publishing Git cache") + if(NOT POKESIM_TOOLS_SOURCE OR NOT POKESIM_SOURCE_CACHE) + message(FATAL_ERROR "Set POKESIM_TOOLS_SOURCE and POKESIM_SOURCE_CACHE after preparing devtools/maps/map-resources.lock.json; see devtools/maps/RESOURCE_MAPS.md.") + endif() + include("${POKESIM_TOOLS_SOURCE}/integrations/arduino-source/resource-maps.cmake") + pa_pokesim_map_directory(MAPS frlg "${CONSUMER}" "${POKESIM_SOURCE_CACHE}") + file(RELATIVE_PATH RELATIVE_MAPS "${CMAKE_CURRENT_SOURCE_DIR}" "${MAPS}") + set(${OUT} "${RELATIVE_MAPS}" PARENT_SCOPE) +endfunction() diff --git a/devtools/maps/RESOURCE_MAPS.md b/devtools/maps/RESOURCE_MAPS.md new file mode 100644 index 0000000000..7d314b00e4 --- /dev/null +++ b/devtools/maps/RESOURCE_MAPS.md @@ -0,0 +1,46 @@ +# FRLG map resources + +FRLG's existing `overworld_map_json()` API now embeds JSON from prepared +`Packages/Resources/Pokemon/Maps/frlg`, rather than an authored source-map copy. +Its native map decoder, route/story/recovery code and controller behavior are +unchanged. Resource preparation happens before configuring, with no implicit +fallback to the deleted source directory and no map download during configure. +This is a change of build input, not runtime filesystem loading. + +The resource lock and CI tools pin published PokemonSimulation main +`906956e94fc912ae9adb0e44845da780f3bc7e4c`. The 53-map resource pack now uses the +compact v2 wire format, read by #114's shared decoder. V2 groups records by kind +and omits empty sections; map geometry, triggers and per-kind record order must +match the previous v1 pack. Native schema, map, route/story and recovery tests +verify this adoption; their current results are recorded in the fork PR. +BDSP's held map differences are not imported or overwritten. + +Clone a full tools/data checkout outside deployed Resources, then explicitly +select the published tool version used by CI: + +```sh +git clone https://github.com/dayfine/PokemonSimulation.git /path/to/pokesim +git -C /path/to/pokesim checkout 906956e94fc912ae9adb0e44845da780f3bc7e4c +PYTHONPATH=/path/to/pokesim/src python3 -m pokesim.maps.consumer_sync prepare \ + --layout resources --source /path/to/pokesim --consumer /path/to/Arduino-Source +cmake -S SerialPrograms -B /path/to/build \ + -DPOKESIM_TOOLS_SOURCE=/path/to/pokesim -DPOKESIM_SOURCE_CACHE=/path/to/pokesim +``` + +CI checks out Packages, prepares this same resource lock through the pinned +integration action, and passes its tools/cache paths to CMake. Missing, partial, +modified, extra or unapproved resource data fails before compilation. The pack +includes pinned license/provenance. Generated resources and external caches are +ignored; the resource lock is checked in. + +The duplicate FRLG builder and Python tests are removed. `frlg_battle_data.py` +is a thin CLI forwarder to `pokesim.games.frlg.battle_data_export`; set +`PYTHONPATH=/src` when running it. All five existing battle-data +outputs reproduced byte-for-byte after the move. Map-builder tests already live +beside their source in PokemonSimulation. Native game tests remain here. +The shared Sinnoh decomp CLI remains a separate consumer migration. + +Native map, story, transition and recovery tests must run from this tree without +the old map directory before adopting this handoff in the owning chain. This +fork setup is not yet an upstream resource submission: handoff must make the +required data available through the agreed Packages repository/process. diff --git a/devtools/maps/frlg_battle_data.py b/devtools/maps/frlg_battle_data.py index d89c74e5ec..b46a637431 100644 --- a/devtools/maps/frlg_battle_data.py +++ b/devtools/maps/frlg_battle_data.py @@ -1,277 +1,14 @@ -"""Writes the FRLG battle data AutoStory chooses its attacks from, as JSON, from the pret/pokefirered decompilation. +"""Forward native battle-data generation to the pinned PokemonSimulation tools. -Usage: - python3 devtools/maps/frlg_battle_data.py --out SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData - python3 devtools/maps/frlg_battle_data.py --out --check +Example: + PYTHONPATH=/path/to/pokesim/src python3 devtools/maps/frlg_battle_data.py \ + --out SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData --check -Reads, at frlg_maps.COMMIT (cached in --cache like frlg_maps.py): -- src/battle_main.c gTypeEffectiveness: type_chart.json, each pairing that - isn't 1x, in tenths; -- src/data/pokemon/species_info.h: species.json, every species' two types - and base stats: HP, Attack, Defense, Sp. Atk, Sp. Def, Speed; -- src/data/battle_moves.h: moves.json, every move's power, type, PP, - accuracy, priority, effect (EFFECT_FLINCH_HIT is "flinch-hit") and its - secondary effect's chance; -- src/data/trainers.h and src/data/trainer_parties.h: trainers.json, every - trainer's AI flags (AI_SCRIPT_TRY_TO_FAINT is "try-to-faint"), items and - party (not the Ruby/Sapphire placeholders, DUMMY_TRAINER_MON): each - member's species, level, iv (0 to 255, as pret has it), nature and moves. - A party that gives no moves gets the game's (GiveBoxMonInitialMoveset: - the last four of its level-up moves up to its level, from - src/data/pokemon/level_up_learnsets.h). The nature is the one - CreateNPCTrainerParty's personality gives: a hash of the trainer's and - the species' names (charmap.txt) on top of 0x78 for a female trainer, - 0x80 for a double battle, else 0x88, mod 25; -- data/maps/*/scripts.inc, map.json and data/scripts/trainers.inc: - map_trainers.json, the trainers each map battles (trainerbattle_* - TRAINER_X in its scripts or its objects'). -Names are the program's slugs: SPECIES_MR_MIME is "mr-mime", MOVE_WATER_GUN -"water-gun", TYPE_WATER "water". One entry per line, so a change in pret -shows as a line in the diff. --check writes nothing: it regenerates the files -and fails if any differs. +The implementation and FireRed source pin belong to PokemonSimulation. Use the +same tools checkout documented in RESOURCE_MAPS.md; no map-builder copy is needed. """ -import argparse -import json -import os -import re -import sys -from concurrent.futures import ThreadPoolExecutor -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) -import frlg_maps # noqa: E402 - -# Slugs the plain rule (lower case, '_' to '-') gets wrong: the program's -# names, from Resources/Pokemon/Pokedex/Pokedex-National.json and PokeAPI. -SPECIES_SLUGS = {'FARFETCHD': 'farfetch-d'} -MOVE_SLUGS = { - 'FAINT_ATTACK': 'feint-attack', - 'HI_JUMP_KICK': 'high-jump-kick', - 'SMELLING_SALT': 'smelling-salts', - 'VICE_GRIP': 'vise-grip', -} -# Not species a battle can show. -SKIPPED_SPECIES = re.compile(r'NONE$|EGG$|OLD_UNOWN_') -# The AI flags, as include/constants/battle_ai.h names them. -AI_FLAG = re.compile(r'AI_SCRIPT_(\w+)') -# gTypeEffectiveness's multipliers, in tenths. -MULTIPLIERS = {'TYPE_MUL_NO_EFFECT': 0, 'TYPE_MUL_NOT_EFFECTIVE': 5, 'TYPE_MUL_SUPER_EFFECTIVE': 20} - - -def slug(name, fixes=None): - return (fixes or {}).get(name) or name.lower().replace('_', '-') - - -def type_slug(name): - return name[len('TYPE_'):].lower() - - -def entries(text, prefix): - """(NAME, body) for each designated initializer `[PREFIX_NAME] = { body }`.""" - pattern = re.compile(r'\[' + prefix + r'_(\w+)\]\s*=\s*\{((?:(?!\n \[).)*?)\n \},', re.S) - return pattern.findall(text) - - -def field(body, name): - match = re.search(r'\.' + name + r'\s*=\s*([^,\n]+(?:\{[^}]*\})?)', body) - return match.group(1).strip() if match else None - - -def type_chart(text): - table = re.search(r'gTypeEffectiveness\[\d+\]\s*=\s*\{(.*?)\};', text, re.S).group(1) - chart = [] - for attack, defend, mul in re.findall(r'(TYPE_\w+),\s*(TYPE_\w+),\s*(TYPE_MUL_\w+)', table): - if attack in ('TYPE_FORESIGHT', 'TYPE_ENDTABLE'): - continue - chart.append([type_slug(attack), type_slug(defend), MULTIPLIERS[mul]]) - return chart - - -def species(text): - data = {} - for name, body in entries(text, 'SPECIES'): - if SKIPPED_SPECIES.search(name): - continue - types = re.search(r'\.types\s*=\s*\{(TYPE_\w+),\s*(TYPE_\w+)\}', body) - stats = [int(field(body, f)) for f in ('baseHP', 'baseAttack', 'baseDefense', 'baseSpAttack', 'baseSpDefense', 'baseSpeed')] - data[slug(name, SPECIES_SLUGS)] = [type_slug(types.group(1)), type_slug(types.group(2))] + stats - return data - - -def moves(text): - data = {} - for name, body in entries(text, 'MOVE'): - if name == 'NONE': - continue - data[slug(name, MOVE_SLUGS)] = [ - int(field(body, 'power')), type_slug(field(body, 'type')), int(field(body, 'pp')), - int(field(body, 'accuracy')), int(field(body, 'priority')), - slug(field(body, 'effect')[len('EFFECT_'):]), int(field(body, 'secondaryEffectChance')), - ] - return data - - -def learnsets(text, pointers): - """{species slug: [(level, move slug), ...]} from level_up_learnsets.h.""" - by_name = {} - for name, body in re.findall(r'static const u16 (s\w+LevelUpLearnset)\[\]\s*=\s*\{(.*?)\};', text, re.S): - by_name[name] = [(int(lvl), slug(move, MOVE_SLUGS)) for lvl, move in re.findall(r'LEVEL_UP_MOVE\(\s*(\d+),\s*MOVE_(\w+)\)', body)] - return {slug(s, SPECIES_SLUGS): by_name[n] for s, n in re.findall(r'\[SPECIES_(\w+)\]\s*=\s*(s\w+LevelUpLearnset)', pointers)} - - -def initial_moves(learnset, level): - """GiveBoxMonInitialMoveset: each level-up move up to `level` in turn; - one already known is skipped, a fifth pushes out the first.""" - known = [] - for move_level, move in learnset: - if move_level > level: - break - if move in known: - continue - if len(known) == 4: - known.pop(0) - known.append(move) - return known - - -def charmap(text): - """{character: byte} for the single characters charmap.txt maps.""" - chars = {} - for char, code in re.findall(r"^'(\\?.)'\s*=\s*([0-9A-F]{2})\s*$", text, re.M): - chars[char[-1]] = int(code, 16) - return chars - - -def name_sum(name, chars): - return sum(chars[c] for c in name) - - -def species_names(text): - return {slug(name, SPECIES_SLUGS): value for name, value in re.findall(r'\[SPECIES_(\w+)\]\s*=\s*_\("(.*?)"\)', text)} - - -def parties(text, moves_at): - """sParty_X: [(species, level, iv, [moves]), ...]; `moves_at(species, - level)` gives a member's moves where the party doesn't.""" - data = {} - # A placeholder's {DUMMY_TRAINER_MON} on one line doesn't match. - for name, body in re.findall(r'struct TrainerMon\w+ (sParty_\w+)\[\]\s*=\s*\{\n((?:(?!\nstatic ).)*?)\n\};', text, re.S): - party = [] - for mon in re.findall(r'\{(.*?)\n \}', body, re.S): - species, level = slug(field(mon, 'species')[len('SPECIES_'):], SPECIES_SLUGS), int(field(mon, 'lvl')) - given = re.search(r'\.moves\s*=\s*\{(.*?)\}', mon) - if given: - moves = [slug(m.strip()[len('MOVE_'):], MOVE_SLUGS) for m in given.group(1).split(',') if m.strip() != 'MOVE_NONE'] - else: - moves = moves_at(species, level) - party.append((species, level, int(field(mon, 'iv')), moves)) - data[name] = party - return data - - -def personality_base(body): - """CreateNPCTrainerParty's personality before the name hash.""" - if field(body, 'doubleBattle') == 'TRUE': - return 0x80 - if 'F_TRAINER_FEMALE' in field(body, 'encounterMusic_gender'): - return 0x78 - return 0x88 - - -def trainers(text, party_text, learned, names, chars): - by_party = parties(party_text, lambda species, level: initial_moves(learned.get(species, []), level)) - data = {} - for name, body in entries(text, 'TRAINER'): - if name == 'NONE': - continue - party = re.search(r'\.party\s*=\s*\w+\((sParty_\w+)\)', body) - # Left out: the Ruby/Sapphire placeholders (DUMMY_TRAINER_MON). - if not party or party.group(1) not in by_party: - continue - trainer_sum = name_sum(re.search(r'\.trainerName\s*=\s*_\("(.*?)"\)', body).group(1), chars) - name_hash = 0 - members = [] - for species, level, iv, moves in by_party[party.group(1)]: - name_hash += trainer_sum + name_sum(names[species], chars) - nature = ((personality_base(body) + (name_hash << 8)) & 0xFFFFFFFF) % 25 - members.append([species, level, iv, nature, moves]) - items = re.search(r'\.items\s*=\s*\{(.*?)\}', body).group(1) - data['TRAINER_' + name] = { - 'ai': [slug(flag) for flag in AI_FLAG.findall(field(body, 'aiFlags') or '')], - 'items': [slug(item.strip()[len('ITEM_'):]) for item in items.split(',') if item.strip() not in ('', 'ITEM_NONE')], - 'party': members, - } - return data - - -def script_trainers(text): - """{label: TRAINER_X} for each script whose first line battles a trainer.""" - return dict(re.findall(r'^(\w+)::\n\s*trainerbattle\w* (TRAINER_\w+)', text, re.M)) - - -def map_trainers(decomp): - """The trainers each map battles: in its own scripts, and its objects' - scripts in data/scripts/trainers.inc (most trainers on routes).""" - groups = json.loads(decomp.read('data/maps/map_groups.json')) - names = sorted(m for group in groups['group_order'] for m in groups[group]) - shared = script_trainers(decomp.read('data/scripts/trainers.inc').decode()) - read = lambda m: (decomp.read(f'data/maps/{m}/scripts.inc').decode(), json.loads(decomp.read(f'data/maps/{m}/map.json'))) - with ThreadPoolExecutor(16) as pool: - sources = list(pool.map(read, names)) - data = {} - for name, (scripts, source) in zip(names, sources): - battled = set(re.findall(r'trainerbattle\w* (TRAINER_\w+)', scripts)) - battled |= {shared[o['script']] for o in source.get('object_events', []) if o.get('script') in shared} - if battled: - data[name] = sorted(battled) - return data - - -def json_lines(data): - """A JSON object (or a list), one entry per line.""" - if isinstance(data, list): - lines = [json.dumps(item) for item in data] - return '[\n' + ',\n'.join(lines) + '\n]\n' - lines = [f'{json.dumps(key)}: {json.dumps(value)}' for key, value in data.items()] - return '{\n' + ',\n'.join(lines) + '\n}\n' - - -def files(decomp): - read = lambda rel: decomp.read(rel).decode() - return { - 'type_chart': json_lines(type_chart(read('src/battle_main.c'))), - 'species': json_lines(species(read('src/data/pokemon/species_info.h'))), - 'moves': json_lines(moves(read('src/data/battle_moves.h'))), - 'trainers': json_lines(trainers( - read('src/data/trainers.h'), read('src/data/trainer_parties.h'), - learnsets(read('src/data/pokemon/level_up_learnsets.h'), read('src/data/pokemon/level_up_learnset_pointers.h')), - species_names(read('src/data/text/species_names.h')), charmap(read('charmap.txt')), - )), - 'map_trainers': json_lines(map_trainers(decomp)), - } - - -def main(): - parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument('--commit', default=frlg_maps.COMMIT) - parser.add_argument('--cache', default=os.path.expanduser('~/.cache/pokefirered')) - parser.add_argument('--out', required=True, help='folder of the .json files') - parser.add_argument('--check', action='store_true', help='check the files in --out instead of writing them') - args = parser.parse_args() - generated = files(frlg_maps.Decomp(args.commit, args.cache)) - if args.check: - differ = [] - for name, text in generated.items(): - path = os.path.join(args.out, name + '.json') - if not os.path.exists(path) or open(path, newline='').read() != text: - differ.append(name) - if differ: - sys.exit(f'Differ from the generator: {" ".join(differ)}. Regenerate them without --check.') - print(f'{len(generated)} files in {args.out} match the generator.') - return - os.makedirs(args.out, exist_ok=True) - for name, text in generated.items(): - with open(os.path.join(args.out, name + '.json'), 'w', newline='') as out: - out.write(text) +from pokesim.games.frlg.battle_data_export import main if __name__ == '__main__': diff --git a/devtools/maps/frlg_maps.py b/devtools/maps/frlg_maps.py deleted file mode 100644 index 3a4ef4a25a..0000000000 --- a/devtools/maps/frlg_maps.py +++ /dev/null @@ -1,318 +0,0 @@ -"""Writes FRLG overworld maps as JSON, from the pret/pokefirered decompilation. - -TODO: move the maps to PokemonAutomation/Packages (Resources/PokemonFRLG/Maps) when ready. - -Usage: - python3 devtools/maps/frlg_maps.py --out SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps \ - CeruleanCity_PokemonCenter_1F CeruleanCity Route24 \ - CeruleanCave_1F CeruleanCave_2F CeruleanCave_B1F - python3 devtools/maps/frlg_maps.py --out - python3 devtools/maps/frlg_maps.py --out --check - -Downloads each map's data/maps//map.json, its layout's map.bin and its -tilesets' metatile_attributes.bin at --commit into --cache, then writes -/.json in the schema of Pokemon::MapData (Pokemon_MapData.h). -Warps and connections lead only to maps in the same run: a warp to another map -has no destination, and a connection to one is left out. A warp arrives at -point "warp_" of its map, the tile of that map's warp n. Other named points -and flag sets come from POINTS and FLAG_SETS below. - -Without map names, the maps are the ones already in --out. --check writes -nothing: it regenerates them and fails if any file differs. The program -builds in the files of SerialPrograms/Source/VideoGames/PokemonFRLG/ -Overworld/Maps, the folder to write and check. -""" -import argparse -import json -import os -import re -import struct -import subprocess -import sys - -COMMIT = 'ce6406d8c2eaf46d543c8a2606de0c3cb1951982' -# When COMMIT was pinned, for each map's "source". -COMMIT_DATE = '2026-10-31' - -# Behaviors with a glyph of their own (Pokemon_MapData.h has the legend). -TERRAIN = { - 'MB_TALL_GRASS': '~', 'MB_WARP_DOOR': 'D', - 'MB_IMPASSABLE_NORTH': '8', 'MB_IMPASSABLE_SOUTH': '2', - 'MB_IMPASSABLE_EAST': '6', 'MB_IMPASSABLE_WEST': '4', -} -# Open tiles whose warp is taken other than by walking into it: how. -WARP_ENTRIES = { - 'MB_CAVE_DOOR': 'cave_entrance', - 'MB_LADDER': 'step_on', 'MB_UP_ESCALATOR': 'step_on', 'MB_DOWN_ESCALATOR': 'step_on', - 'MB_SOUTH_ARROW_WARP': 'walk_south', 'MB_NORTH_ARROW_WARP': 'walk_north', - 'MB_EAST_ARROW_WARP': 'walk_east', 'MB_WEST_ARROW_WARP': 'walk_west', - # Stairs at the side of a room warp like an exit mat, the way the stairs - # go up or down (IsDirectionalStairWarpMetatileBehavior()). - 'MB_UP_RIGHT_STAIR_WARP': 'walk_east', 'MB_DOWN_RIGHT_STAIR_WARP': 'walk_east', - 'MB_UP_LEFT_STAIR_WARP': 'walk_west', 'MB_DOWN_LEFT_STAIR_WARP': 'walk_west', -} -# Ledges, by the way the player hops over them. -LEDGES = {'MB_JUMP_NORTH': '^', 'MB_JUMP_SOUTH': 'v', 'MB_JUMP_WEST': '<', 'MB_JUMP_EAST': '>'} -FLOOR = ('MB_NORMAL', 'MB_CAVE', 'MB_ROCK_STAIRS', 'MB_TALL_GRASS') -DIRECTIONS = {'up': 'north', 'down': 'south', 'left': 'west', 'right': 'east'} - -# Places and flag sets the decompilation doesn't name, written into the map -# they belong to. -# A `*_front` point is where the player stands to talk to someone across a -# counter, or to walk north through a door. -POINTS = { - # Where a new game starts (WarpToPlayersRoom() in src/new_game.c). - 'PalletTown_PlayersHouse_2F': {'start': (6, 6)}, - 'PalletTown': {'oaks_lab_front': (16, 14)}, - # The clerk is across the counter to the west. - 'ViridianCity_Mart': {'clerk_front': (4, 3)}, - 'ViridianCity_PokemonCenter_1F': {'nurse_front': (7, 4)}, - 'PewterCity': {'gym_front': (15, 17)}, - 'PewterCity_PokemonCenter_1F': {'nurse_front': (7, 4)}, - 'PewterCity_Gym': {'brock_front': (6, 6)}, - # The tile in front of the PC. - 'CeruleanCity_PokemonCenter_1F': {'pc': (11, 2), 'nurse_front': (7, 4)}, - # Where the player stands after entering from Cerulean City. - 'CeruleanCave_1F': {'entrance': (33, 21)}, - # Mewtwo's tile. Its battle starts by talking to it from the south. - 'CeruleanCave_B1F': {'mewtwo': (7, 12)}, -} -FLAG_SETS = { - # Set once the player has entered the Hall of Fame. They clear the way - # to Cerulean Cave: its guard, the rival and the Rocket. - 'CeruleanCity': {'after_hall_of_fame': [ - 'FLAG_HIDE_CERULEAN_CAVE_GUARD', - 'FLAG_HIDE_CERULEAN_RIVAL', - 'FLAG_HIDE_CERULEAN_ROCKET', - ]}, -} - - -class Decomp: - def __init__(self, commit, cache): - self.raw = 'https://raw.githubusercontent.com/pret/pokefirered/' + commit - self.cache = os.path.join(cache, commit) - - def path(self, rel): - local = os.path.join(self.cache, rel) - if not os.path.exists(local): - os.makedirs(os.path.dirname(local), exist_ok=True) - subprocess.run(['curl', '-sfL', f'{self.raw}/{rel}', '-o', local], check=True) - return local - - def read(self, rel): - with open(self.path(rel), 'rb') as file: - return file.read() - - -def behaviors(decomp): - names = {} - for line in decomp.read('include/constants/metatile_behaviors.h').decode().splitlines(): - match = re.match(r'#define (MB_\w+)\s+(0x[0-9A-Fa-f]+|\d+)', line) - if match: - names[int(match.group(2), 0)] = match.group(1) - return names - - -def tileset_attributes(decomp, symbol, kind): - name = re.sub(r'([a-z])([A-Z0-9])', r'\1_\2', symbol.replace('gTileset_', '')).lower() - data = decomp.read(f'data/tilesets/{kind}/{name}/metatile_attributes.bin') - return [struct.unpack_from('> 10) & 3, value >> 12 - attributes = primary[metatile] if metatile < 640 else secondary[metatile - 640] - behavior = names.get(attributes & 0x1ff, hex(attributes & 0x1ff)) - glyph, entry = tile_glyph(behavior, collision, unhandled, (x, y) in signs) - row += glyph - if entry: - entries[(x, y)] = entry - levels += '%x' % level - tiles.append(row) - elevation.append(levels) - return tiles, elevation, entries - - -def wander_box(obj, tiles): - """The tiles a wandering person may stand on, kept inside the map, or None - if they stand still.""" - movement = obj.get('movement_type', '') - if 'WANDER' not in movement: - return None - x = 0 if 'UP_AND_DOWN' in movement else int(obj.get('movement_range_x') or 0) - y = 0 if 'LEFT_AND_RIGHT' in movement else int(obj.get('movement_range_y') or 0) - if x == 0 and y == 0: - return None - return { - 'x0': max(obj['x'] - x, 0), 'y0': max(obj['y'] - y, 0), - 'x1': min(obj['x'] + x, len(tiles[0]) - 1), 'y1': min(obj['y'] + y, len(tiles) - 1), - } - - -def map_object(obj, tiles): - kind = obj['graphics_id'].replace('OBJ_EVENT_GFX_', '').lower() - data = {'name': kind, 'kind': 'item' if kind == 'item_ball' else 'npc', 'x': obj['x'], 'y': obj['y']} - box = wander_box(obj, tiles) - if box: - data['wander'] = box - flag = obj.get('flag') or '0' - if flag != '0': - data['hide_flag'] = flag - return data - - -# Tiles the player never walks onto: their elevation only matters for doors, -# which the player is put on by a warp and leaves at once. -UNWALKABLE = '#^v<>DS' -GROUND = '3' - - -def ground_only(tiles, elevation): - """Whether every walkable tile is at ground level, so that the map can - leave out its elevation grid (the loader reads ground everywhere).""" - return all(level == GROUND for row, levels in zip(tiles, elevation) - for tile, level in zip(row, levels) if tile not in UNWALKABLE) - - -def warp_point(index): - return f'warp_{index}' - - -def warp(event, entries, loaded, sources): - """A warp event as MapData's warp: how it is entered, and the point it - leads to, if its map is loaded and has that warp.""" - data = {'x': event['x'], 'y': event['y'], 'enter': entries.get((event['x'], event['y']), 'walk_into')} - to_map, index = loaded.get(event['dest_map']), int(event['dest_warp_id']) - if to_map is not None and index < len(sources[to_map].get('warp_events', [])): - data['to_map'] = to_map - data['to_point'] = warp_point(index) - return data - - -def arrivals(sources, loaded): - """For each map, the indices of its warps that a warp leads to.""" - arriving = {name: set() for name in sources} - for source in sources.values(): - for event in source.get('warp_events', []): - to_map = loaded.get(event['dest_map']) - if to_map is not None and int(event['dest_warp_id']) < len(sources[to_map].get('warp_events', [])): - arriving[to_map].add(int(event['dest_warp_id'])) - return arriving - - -def map_json(decomp, name, sources, layouts, names, loaded, unhandled): - source = sources[name] - signs = frozenset((e['x'], e['y']) for e in source.get('bg_events', []) if e.get('type') == 'sign') - tiles, elevation, entries = grid(decomp, layouts[source['layout']], names, unhandled, signs) - warp_events = source.get('warp_events', []) - points = {n: [x, y] for n, (x, y) in POINTS.get(name, {}).items()} - for index in sorted(arrivals(sources, loaded)[name]): - points[warp_point(index)] = [warp_events[index]['x'], warp_events[index]['y']] - data = { - 'name': name, - 'source': {'decomp_file': f'data/maps/{name}/map.json', 'revision': COMMIT, 'date': COMMIT_DATE}, - 'tiles': tiles, 'elevation': elevation, - 'points': points, - 'warps': [warp(event, entries, loaded, sources) for event in warp_events], - # A few objects stand off the map, where no route meets them. - 'objects': [ - map_object(obj, tiles) for obj in source.get('object_events', []) - if 0 <= obj['x'] < len(tiles[0]) and 0 <= obj['y'] < len(tiles) - ], - 'flag_sets': FLAG_SETS.get(name, {}), - 'connections': [ - {'side': DIRECTIONS[c['direction']], 'to_map': loaded[c['map']], 'offset': c['offset']} - for c in (source.get('connections') or []) if c['map'] in loaded - ], - } - if ground_only(tiles, elevation): - del data['elevation'] - return data - - -def json_text(data): - text = json.dumps(data, indent=4) - # A point's [x, y] on one line. - return re.sub(r'\[\s*(-?\d+),\s*(-?\d+)\s*\]', r'[\1, \2]', text) + '\n' - - -def main(): - parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument('--commit', default=COMMIT) - parser.add_argument('--cache', default=os.path.expanduser('~/.cache/pokefirered')) - parser.add_argument('--out', required=True, help='folder of the .json files') - parser.add_argument('--check', action='store_true', help='check the files in --out instead of writing them') - parser.add_argument('maps', nargs='*', help='default: the maps already in --out') - args = parser.parse_args() - if not args.maps and os.path.isdir(args.out): - args.maps = sorted(f[:-5] for f in os.listdir(args.out) if f.endswith('.json')) - if not args.maps: - parser.error('no maps given, and none in --out') - - decomp = Decomp(args.commit, args.cache) - names = behaviors(decomp) - layouts = {l['id']: l for l in json.loads(decomp.read('data/layouts/layouts.json'))['layouts'] if 'id' in l} - sources = {m: json.loads(decomp.read(f'data/maps/{m}/map.json')) for m in args.maps} - loaded = {source['id']: m for m, source in sources.items()} - unhandled = {} - maps = [(name, json_text(map_json(decomp, name, sources, layouts, names, loaded, unhandled))) for name in args.maps] - if unhandled: - print(f'Non-collision behaviors written as floor: {unhandled}') - if args.check: - differ = [] - for name, text in maps: - path = os.path.join(args.out, name + '.json') - if not os.path.exists(path) or open(path, newline='').read() != text: - differ.append(name) - if differ: - sys.exit(f'Differ from the generator: {" ".join(differ)}. Regenerate them without --check.') - print(f'{len(maps)} maps in {args.out} match the generator.') - return - os.makedirs(args.out, exist_ok=True) - for name, text in maps: - with open(os.path.join(args.out, name + '.json'), 'w', newline='') as out: - out.write(text) - - -if __name__ == '__main__': - main() diff --git a/devtools/maps/map-resources.lock.json b/devtools/maps/map-resources.lock.json new file mode 100644 index 0000000000..3bded16bc7 --- /dev/null +++ b/devtools/maps/map-resources.lock.json @@ -0,0 +1,11 @@ +{ + "format": "pokesim-map-resource-lock/1", + "repository": "dayfine/PokemonSimulation", + "games": { + "frlg": { + "revision": "906956e94fc912ae9adb0e44845da780f3bc7e4c", + "manifest_path": "data/maps/runtime-manifest.json", + "manifest_sha256": "856e07a265da0b273172a7aa97a2aa335c90ea0a39162d50912b55fb60a86bc7" + } + } +} From d136b1ad190488b66404ff6f444cd6871313cf7b Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 14:13:09 -0800 Subject: [PATCH 25/29] FRLG AutoStory: drop the battle sim, strongest move as the fallback Battle simulation moves to PokemonSimulation, whose plan for a trainer battle will come in the checkpoint JSON. Until then a battle's move is the fallback: the strongest by power x STAB x type effectiveness x accuracy (attack_slot_against(), now with accuracy), against the trainer's Pokemon out as read at the battle menu, else against its whole party. A Potion is used whenever the bar isn't green, unless the last hit took a Potion's worth. HIGH-risk battles are no longer refused before the fight. Deleted: AutoStoryBattleSim, AutoStoryWinChance, AutoStoryFoeTracker and AutoStoryDamage (Gen 3 damage, used only by them; Stats moves to PokemonFRLG_AutoStoryStats.h), BattleSim_Tests, map_trainers.json with map_trainers() and MIN_WIN_CHANCE. Supplies::foe_out is the species read. The battle-risk test moves to the BattleData tests. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/BattleData/map_trainers.json | 106 ---- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 9 +- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 7 +- .../PokemonFRLG_AutoStoryBattleData.cpp | 8 +- .../PokemonFRLG_AutoStoryBattleData.h | 18 +- .../PokemonFRLG_AutoStoryBattleData_Tests.cpp | 36 +- .../PokemonFRLG_AutoStoryBattleDecisions.cpp | 64 +- .../PokemonFRLG_AutoStoryBattleDecisions.h | 2 +- .../PokemonFRLG_AutoStoryBattleSim.cpp | 576 ------------------ .../PokemonFRLG_AutoStoryBattleSim.h | 202 ------ .../PokemonFRLG_AutoStoryBattleSim_Tests.cpp | 509 ---------------- .../AutoStory/PokemonFRLG_AutoStoryDamage.cpp | 175 ------ .../AutoStory/PokemonFRLG_AutoStoryDamage.h | 127 ---- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 27 +- .../AutoStory/PokemonFRLG_AutoStoryExport.cpp | 4 +- .../PokemonFRLG_AutoStoryExport_Tests.cpp | 4 +- .../PokemonFRLG_AutoStoryFoeTracker.cpp | 77 --- .../PokemonFRLG_AutoStoryFoeTracker.h | 73 --- .../AutoStory/PokemonFRLG_AutoStoryParty.cpp | 10 +- .../AutoStory/PokemonFRLG_AutoStoryParty.h | 9 +- .../AutoStory/PokemonFRLG_AutoStoryStats.h | 34 ++ .../AutoStory/PokemonFRLG_AutoStorySummary.h | 2 +- .../PokemonFRLG_AutoStoryWinChance.cpp | 397 ------------ .../PokemonFRLG_AutoStoryWinChance.h | 67 -- SerialPrograms/cmake/SourceFiles.cmake | 10 +- 25 files changed, 111 insertions(+), 2442 deletions(-) delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/map_trainers.json delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStats.h delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/map_trainers.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/map_trainers.json deleted file mode 100644 index 0e600db748..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/map_trainers.json +++ /dev/null @@ -1,106 +0,0 @@ -{ -"CeladonCity_GameCorner": ["TRAINER_TEAM_ROCKET_GRUNT_7"], -"CeladonCity_Gym": ["TRAINER_BEAUTY_BRIDGET", "TRAINER_BEAUTY_LORI", "TRAINER_BEAUTY_TAMIA", "TRAINER_COOLTRAINER_MARY", "TRAINER_LASS_KAY", "TRAINER_LASS_LISA", "TRAINER_LEADER_ERIKA", "TRAINER_PICNICKER_TINA"], -"CeruleanCity": ["TRAINER_RIVAL_CERULEAN_BULBASAUR", "TRAINER_RIVAL_CERULEAN_CHARMANDER", "TRAINER_RIVAL_CERULEAN_SQUIRTLE", "TRAINER_TEAM_ROCKET_GRUNT_5"], -"CeruleanCity_Gym": ["TRAINER_LEADER_MISTY", "TRAINER_PICNICKER_DIANA", "TRAINER_SWIMMER_MALE_LUIS"], -"CinnabarIsland_Gym": ["TRAINER_BURGLAR_DUSTY", "TRAINER_BURGLAR_QUINN", "TRAINER_BURGLAR_RAMON", "TRAINER_LEADER_BLAINE", "TRAINER_SUPER_NERD_AVERY", "TRAINER_SUPER_NERD_DEREK", "TRAINER_SUPER_NERD_ERIK", "TRAINER_SUPER_NERD_ZAC"], -"FiveIsland_LostCave_Room1": ["TRAINER_RUIN_MANIAC_LAWSON"], -"FiveIsland_LostCave_Room10": ["TRAINER_LADY_SELPHY"], -"FiveIsland_LostCave_Room4": ["TRAINER_PSYCHIC_LAURA"], -"FiveIsland_Meadow": ["TRAINER_TEAM_ROCKET_GRUNT_49", "TRAINER_TEAM_ROCKET_GRUNT_50", "TRAINER_TEAM_ROCKET_GRUNT_51"], -"FiveIsland_MemorialPillar": ["TRAINER_BIRD_KEEPER_CHAZ", "TRAINER_BIRD_KEEPER_HAROLD", "TRAINER_BIRD_KEEPER_MILO"], -"FiveIsland_ResortGorgeous": ["TRAINER_LADY_GILLIAN", "TRAINER_LADY_JACKI", "TRAINER_PAINTER_CELINA", "TRAINER_PAINTER_DAISY", "TRAINER_PAINTER_RAYNA", "TRAINER_SWIMMER_MALE_TOBY", "TRAINER_YOUNGSTER_DESTIN"], -"FiveIsland_RocketWarehouse": ["TRAINER_SCIENTIST_GIDEON", "TRAINER_TEAM_ROCKET_ADMIN", "TRAINER_TEAM_ROCKET_ADMIN_2", "TRAINER_TEAM_ROCKET_GRUNT_42", "TRAINER_TEAM_ROCKET_GRUNT_47", "TRAINER_TEAM_ROCKET_GRUNT_48"], -"FiveIsland_WaterLabyrinth": ["TRAINER_PKMN_BREEDER_ALIZE"], -"FourIsland_IcefallCave_Back": ["TRAINER_TEAM_ROCKET_GRUNT_45"], -"FuchsiaCity_Gym": ["TRAINER_JUGGLER_KAYDEN", "TRAINER_JUGGLER_KIRK", "TRAINER_JUGGLER_NATE", "TRAINER_JUGGLER_SHAWN", "TRAINER_LEADER_KOGA", "TRAINER_TAMER_EDGAR", "TRAINER_TAMER_PHIL"], -"MtEmber_Exterior": ["TRAINER_CRUSH_GIRL_JOCELYN", "TRAINER_PKMN_RANGER_BETH", "TRAINER_PKMN_RANGER_LOGAN", "TRAINER_TEAM_ROCKET_GRUNT_43", "TRAINER_TEAM_ROCKET_GRUNT_44"], -"MtMoon_1F": ["TRAINER_BUG_CATCHER_KENT", "TRAINER_BUG_CATCHER_ROBBY", "TRAINER_HIKER_MARCOS", "TRAINER_LASS_IRIS", "TRAINER_LASS_MIRIAM", "TRAINER_SUPER_NERD_JOVAN", "TRAINER_YOUNGSTER_JOSH"], -"MtMoon_B2F": ["TRAINER_SUPER_NERD_MIGUEL", "TRAINER_TEAM_ROCKET_GRUNT", "TRAINER_TEAM_ROCKET_GRUNT_2", "TRAINER_TEAM_ROCKET_GRUNT_3", "TRAINER_TEAM_ROCKET_GRUNT_4"], -"OneIsland_KindleRoad": ["TRAINER_BLACK_BELT_HUGH", "TRAINER_BLACK_BELT_SHEA", "TRAINER_CAMPER_BRYCE", "TRAINER_CRUSH_GIRL_SHARON", "TRAINER_CRUSH_GIRL_TANYA", "TRAINER_CRUSH_KIN_MIK_KIA", "TRAINER_FISHERMAN_TOMMY", "TRAINER_PICNICKER_CLAIRE", "TRAINER_SWIMMER_FEMALE_ABIGAIL", "TRAINER_SWIMMER_FEMALE_MARIA", "TRAINER_SWIMMER_MALE_FINN", "TRAINER_SWIMMER_MALE_GARRETT"], -"OneIsland_TreasureBeach": ["TRAINER_SWIMMER_FEMALE_AMARA"], -"PalletTown_ProfessorOaksLab": ["TRAINER_RIVAL_OAKS_LAB_BULBASAUR", "TRAINER_RIVAL_OAKS_LAB_CHARMANDER", "TRAINER_RIVAL_OAKS_LAB_SQUIRTLE"], -"PewterCity_Gym": ["TRAINER_CAMPER_LIAM", "TRAINER_LEADER_BROCK"], -"PokemonLeague_AgathasRoom": ["TRAINER_ELITE_FOUR_AGATHA", "TRAINER_ELITE_FOUR_AGATHA_2"], -"PokemonLeague_BrunosRoom": ["TRAINER_ELITE_FOUR_BRUNO", "TRAINER_ELITE_FOUR_BRUNO_2"], -"PokemonLeague_ChampionsRoom": ["TRAINER_CHAMPION_FIRST_BULBASAUR", "TRAINER_CHAMPION_FIRST_CHARMANDER", "TRAINER_CHAMPION_FIRST_SQUIRTLE", "TRAINER_CHAMPION_REMATCH_BULBASAUR", "TRAINER_CHAMPION_REMATCH_CHARMANDER", "TRAINER_CHAMPION_REMATCH_SQUIRTLE"], -"PokemonLeague_LancesRoom": ["TRAINER_ELITE_FOUR_LANCE", "TRAINER_ELITE_FOUR_LANCE_2"], -"PokemonLeague_LoreleisRoom": ["TRAINER_ELITE_FOUR_LORELEI", "TRAINER_ELITE_FOUR_LORELEI_2"], -"PokemonMansion_1F": ["TRAINER_SCIENTIST_TED", "TRAINER_YOUNGSTER_JOHNSON"], -"PokemonMansion_2F": ["TRAINER_BURGLAR_ARNIE"], -"PokemonMansion_3F": ["TRAINER_BURGLAR_SIMON", "TRAINER_SCIENTIST_BRAYDON"], -"PokemonMansion_B1F": ["TRAINER_BURGLAR_LEWIS", "TRAINER_SCIENTIST_IVAN"], -"PokemonTower_2F": ["TRAINER_RIVAL_POKEMON_TOWER_BULBASAUR", "TRAINER_RIVAL_POKEMON_TOWER_CHARMANDER", "TRAINER_RIVAL_POKEMON_TOWER_SQUIRTLE"], -"PokemonTower_3F": ["TRAINER_CHANNELER_CARLY", "TRAINER_CHANNELER_HOPE", "TRAINER_CHANNELER_PATRICIA"], -"PokemonTower_4F": ["TRAINER_CHANNELER_JODY", "TRAINER_CHANNELER_LAUREL", "TRAINER_CHANNELER_PAULA"], -"PokemonTower_5F": ["TRAINER_CHANNELER_JANAE", "TRAINER_CHANNELER_KARINA", "TRAINER_CHANNELER_RUTH", "TRAINER_CHANNELER_TAMMY"], -"PokemonTower_6F": ["TRAINER_CHANNELER_ANGELICA", "TRAINER_CHANNELER_EMILIA", "TRAINER_CHANNELER_JENNIFER"], -"PokemonTower_7F": ["TRAINER_TEAM_ROCKET_GRUNT_19", "TRAINER_TEAM_ROCKET_GRUNT_20", "TRAINER_TEAM_ROCKET_GRUNT_21"], -"RockTunnel_1F": ["TRAINER_HIKER_LENNY", "TRAINER_HIKER_LUCAS", "TRAINER_HIKER_OLIVER", "TRAINER_PICNICKER_ARIANA", "TRAINER_PICNICKER_DANA", "TRAINER_PICNICKER_LEAH", "TRAINER_POKEMANIAC_ASHTON"], -"RockTunnel_B1F": ["TRAINER_HIKER_ALLEN", "TRAINER_HIKER_DUDLEY", "TRAINER_HIKER_ERIC", "TRAINER_PICNICKER_MARTHA", "TRAINER_PICNICKER_SOFIA", "TRAINER_POKEMANIAC_COOPER", "TRAINER_POKEMANIAC_STEVE", "TRAINER_POKEMANIAC_WINSTON"], -"RocketHideout_B1F": ["TRAINER_TEAM_ROCKET_GRUNT_10", "TRAINER_TEAM_ROCKET_GRUNT_11", "TRAINER_TEAM_ROCKET_GRUNT_12", "TRAINER_TEAM_ROCKET_GRUNT_8", "TRAINER_TEAM_ROCKET_GRUNT_9"], -"RocketHideout_B2F": ["TRAINER_TEAM_ROCKET_GRUNT_13"], -"RocketHideout_B3F": ["TRAINER_TEAM_ROCKET_GRUNT_14", "TRAINER_TEAM_ROCKET_GRUNT_15"], -"RocketHideout_B4F": ["TRAINER_BOSS_GIOVANNI", "TRAINER_TEAM_ROCKET_GRUNT_16", "TRAINER_TEAM_ROCKET_GRUNT_17", "TRAINER_TEAM_ROCKET_GRUNT_18"], -"Route10": ["TRAINER_HIKER_CLARK", "TRAINER_HIKER_TRENT", "TRAINER_PICNICKER_CAROL", "TRAINER_PICNICKER_HEIDI", "TRAINER_POKEMANIAC_HERMAN", "TRAINER_POKEMANIAC_MARK"], -"Route11": ["TRAINER_ENGINEER_BERNIE", "TRAINER_ENGINEER_BRAXTON", "TRAINER_GAMER_DARIAN", "TRAINER_GAMER_DIRK", "TRAINER_GAMER_HUGO", "TRAINER_GAMER_JASPER", "TRAINER_YOUNGSTER_DAVE", "TRAINER_YOUNGSTER_DILLON", "TRAINER_YOUNGSTER_EDDIE", "TRAINER_YOUNGSTER_YASU"], -"Route12": ["TRAINER_CAMPER_JUSTIN", "TRAINER_FISHERMAN_ANDREW", "TRAINER_FISHERMAN_CHIP", "TRAINER_FISHERMAN_ELLIOT", "TRAINER_FISHERMAN_HANK", "TRAINER_FISHERMAN_NED", "TRAINER_ROCKER_LUCA", "TRAINER_YOUNG_COUPLE_GIA_JES"], -"Route13": ["TRAINER_BEAUTY_LOLA", "TRAINER_BEAUTY_SHEILA", "TRAINER_BIKER_JARED", "TRAINER_BIRD_KEEPER_PERRY", "TRAINER_BIRD_KEEPER_ROBERT", "TRAINER_BIRD_KEEPER_SEBASTIAN", "TRAINER_PICNICKER_ALMA", "TRAINER_PICNICKER_GWEN", "TRAINER_PICNICKER_SUSIE", "TRAINER_PICNICKER_VALERIE"], -"Route14": ["TRAINER_BIKER_GERALD", "TRAINER_BIKER_ISAAC", "TRAINER_BIKER_LUKAS", "TRAINER_BIKER_MALIK", "TRAINER_BIRD_KEEPER_BECK", "TRAINER_BIRD_KEEPER_BENNY", "TRAINER_BIRD_KEEPER_CARTER", "TRAINER_BIRD_KEEPER_DONALD", "TRAINER_BIRD_KEEPER_MARLON", "TRAINER_BIRD_KEEPER_MITCH", "TRAINER_TWINS_KIRI_JAN"], -"Route15": ["TRAINER_BEAUTY_GRACE", "TRAINER_BEAUTY_OLIVIA", "TRAINER_BIKER_ALEX", "TRAINER_BIKER_ERNEST", "TRAINER_BIRD_KEEPER_CHESTER", "TRAINER_BIRD_KEEPER_EDWIN", "TRAINER_CRUSH_KIN_RON_MYA", "TRAINER_PICNICKER_BECKY", "TRAINER_PICNICKER_CELIA", "TRAINER_PICNICKER_KINDRA", "TRAINER_PICNICKER_YAZMIN"], -"Route16": ["TRAINER_BIKER_HIDEO", "TRAINER_BIKER_LAO", "TRAINER_BIKER_RUBEN", "TRAINER_CUE_BALL_CAMRON", "TRAINER_CUE_BALL_KOJI", "TRAINER_CUE_BALL_LUKE", "TRAINER_YOUNG_COUPLE_LEA_JED"], -"Route17": ["TRAINER_BIKER_BILLY", "TRAINER_BIKER_JAXON", "TRAINER_BIKER_NIKOLAS", "TRAINER_BIKER_VIRGIL", "TRAINER_BIKER_WILLIAM", "TRAINER_CUE_BALL_COREY", "TRAINER_CUE_BALL_ISAIAH", "TRAINER_CUE_BALL_JAMAL", "TRAINER_CUE_BALL_RAUL", "TRAINER_CUE_BALL_ZEEK"], -"Route18": ["TRAINER_BIRD_KEEPER_JACOB", "TRAINER_BIRD_KEEPER_RAMIRO", "TRAINER_BIRD_KEEPER_WILTON"], -"Route19": ["TRAINER_SIS_AND_BRO_LIA_LUC", "TRAINER_SWIMMER_FEMALE_ALICE", "TRAINER_SWIMMER_FEMALE_ANYA", "TRAINER_SWIMMER_FEMALE_CONNIE", "TRAINER_SWIMMER_MALE_AXLE", "TRAINER_SWIMMER_MALE_DAVID", "TRAINER_SWIMMER_MALE_DOUGLAS", "TRAINER_SWIMMER_MALE_MATTHEW", "TRAINER_SWIMMER_MALE_REECE", "TRAINER_SWIMMER_MALE_RICHARD", "TRAINER_SWIMMER_MALE_TONY"], -"Route20": ["TRAINER_BIRD_KEEPER_ROGER", "TRAINER_PICNICKER_IRENE", "TRAINER_PICNICKER_MISSY", "TRAINER_SWIMMER_FEMALE_MELISSA", "TRAINER_SWIMMER_FEMALE_NORA", "TRAINER_SWIMMER_FEMALE_SHIRLEY", "TRAINER_SWIMMER_FEMALE_TIFFANY", "TRAINER_SWIMMER_MALE_BARRY", "TRAINER_SWIMMER_MALE_DARRIN", "TRAINER_SWIMMER_MALE_DEAN"], -"Route21_North": ["TRAINER_FISHERMAN_RONALD", "TRAINER_FISHERMAN_WADE", "TRAINER_SIS_AND_BRO_LIL_IAN", "TRAINER_SWIMMER_MALE_SPENCER"], -"Route21_South": ["TRAINER_FISHERMAN_CLAUDE", "TRAINER_FISHERMAN_NOLAN", "TRAINER_SWIMMER_MALE_JACK", "TRAINER_SWIMMER_MALE_JEROME", "TRAINER_SWIMMER_MALE_ROLAND"], -"Route22": ["TRAINER_RIVAL_ROUTE22_EARLY_BULBASAUR", "TRAINER_RIVAL_ROUTE22_EARLY_CHARMANDER", "TRAINER_RIVAL_ROUTE22_EARLY_SQUIRTLE", "TRAINER_RIVAL_ROUTE22_LATE_BULBASAUR", "TRAINER_RIVAL_ROUTE22_LATE_CHARMANDER", "TRAINER_RIVAL_ROUTE22_LATE_SQUIRTLE"], -"Route24": ["TRAINER_BUG_CATCHER_CALE", "TRAINER_CAMPER_ETHAN", "TRAINER_CAMPER_SHANE", "TRAINER_LASS_ALI", "TRAINER_LASS_RELI", "TRAINER_TEAM_ROCKET_GRUNT_6", "TRAINER_YOUNGSTER_TIMMY"], -"Route25": ["TRAINER_CAMPER_FLINT", "TRAINER_HIKER_FRANKLIN", "TRAINER_HIKER_NOB", "TRAINER_HIKER_WAYNE", "TRAINER_LASS_HALEY", "TRAINER_PICNICKER_KELSEY", "TRAINER_YOUNGSTER_CHAD", "TRAINER_YOUNGSTER_DAN", "TRAINER_YOUNGSTER_JOEY"], -"Route3": ["TRAINER_BUG_CATCHER_COLTON", "TRAINER_BUG_CATCHER_GREG", "TRAINER_BUG_CATCHER_JAMES", "TRAINER_LASS_JANICE", "TRAINER_LASS_ROBIN", "TRAINER_LASS_SALLY", "TRAINER_YOUNGSTER_BEN", "TRAINER_YOUNGSTER_CALVIN"], -"Route4": ["TRAINER_LASS_CRISSY"], -"Route6": ["TRAINER_BUG_CATCHER_ELIJAH", "TRAINER_BUG_CATCHER_KEIGO", "TRAINER_CAMPER_JEFF", "TRAINER_CAMPER_RICKY", "TRAINER_PICNICKER_ISABELLE", "TRAINER_PICNICKER_NANCY"], -"Route8": ["TRAINER_BIKER_JAREN", "TRAINER_BIKER_RICARDO", "TRAINER_GAMER_RICH", "TRAINER_GAMER_STAN", "TRAINER_LASS_ANDREA", "TRAINER_LASS_JULIA", "TRAINER_LASS_MEGAN", "TRAINER_LASS_PAIGE", "TRAINER_SUPER_NERD_AIDAN", "TRAINER_SUPER_NERD_GLENN", "TRAINER_SUPER_NERD_LESLIE", "TRAINER_TWINS_ELI_ANNE"], -"Route9": ["TRAINER_BUG_CATCHER_BRENT", "TRAINER_BUG_CATCHER_CONNER", "TRAINER_CAMPER_CHRIS", "TRAINER_CAMPER_DREW", "TRAINER_HIKER_ALAN", "TRAINER_HIKER_BRICE", "TRAINER_HIKER_JEREMY", "TRAINER_PICNICKER_ALICIA", "TRAINER_PICNICKER_CAITLIN"], -"SSAnne_1F_Room2": ["TRAINER_LASS_ANN", "TRAINER_YOUNGSTER_TYLER"], -"SSAnne_1F_Room5": ["TRAINER_GENTLEMAN_ARTHUR"], -"SSAnne_1F_Room7": ["TRAINER_GENTLEMAN_THOMAS"], -"SSAnne_2F_Corridor": ["TRAINER_RIVAL_SS_ANNE_BULBASAUR", "TRAINER_RIVAL_SS_ANNE_CHARMANDER", "TRAINER_RIVAL_SS_ANNE_SQUIRTLE"], -"SSAnne_2F_Room2": ["TRAINER_FISHERMAN_DALE", "TRAINER_GENTLEMAN_BROOKS"], -"SSAnne_2F_Room4": ["TRAINER_GENTLEMAN_LAMAR", "TRAINER_LASS_DAWN"], -"SSAnne_B1F_Room1": ["TRAINER_FISHERMAN_BARNY", "TRAINER_SAILOR_PHILLIP"], -"SSAnne_B1F_Room2": ["TRAINER_SAILOR_HUEY"], -"SSAnne_B1F_Room3": ["TRAINER_SAILOR_DYLAN"], -"SSAnne_B1F_Room4": ["TRAINER_SAILOR_DUNCAN", "TRAINER_SAILOR_LEONARD"], -"SSAnne_Deck": ["TRAINER_SAILOR_EDMOND", "TRAINER_SAILOR_TREVOR"], -"SaffronCity_Dojo": ["TRAINER_BLACK_BELT_AARON", "TRAINER_BLACK_BELT_HIDEKI", "TRAINER_BLACK_BELT_HITOSHI", "TRAINER_BLACK_BELT_KOICHI", "TRAINER_BLACK_BELT_MIKE"], -"SaffronCity_Gym": ["TRAINER_CHANNELER_AMANDA", "TRAINER_CHANNELER_STACY", "TRAINER_CHANNELER_TASHA", "TRAINER_LEADER_SABRINA", "TRAINER_PSYCHIC_CAMERON", "TRAINER_PSYCHIC_JOHAN", "TRAINER_PSYCHIC_PRESTON", "TRAINER_PSYCHIC_TYRON"], -"SevenIsland_SevaultCanyon": ["TRAINER_COOLTRAINER_LEROY", "TRAINER_COOLTRAINER_MICHELLE", "TRAINER_COOL_COUPLE_LEX_NYA", "TRAINER_CRUSH_GIRL_CYNDY", "TRAINER_PKMN_RANGER_JACKSON", "TRAINER_PKMN_RANGER_KATELYN", "TRAINER_TAMER_EVAN"], -"SevenIsland_SevaultCanyon_Entrance": ["TRAINER_AROMA_LADY_MIAH", "TRAINER_JUGGLER_MASON", "TRAINER_PKMN_RANGER_MADELINE", "TRAINER_PKMN_RANGER_NICOLAS", "TRAINER_YOUNG_COUPLE_EVE_JON"], -"SevenIsland_TanobyRuins": ["TRAINER_GENTLEMAN_CLIFFORD", "TRAINER_PAINTER_EDNA", "TRAINER_RUIN_MANIAC_BENJAMIN", "TRAINER_RUIN_MANIAC_BRANDON"], -"SevenIsland_TrainerTower": ["TRAINER_PSYCHIC_DARIO", "TRAINER_PSYCHIC_RODETTE"], -"SilphCo_10F": ["TRAINER_SCIENTIST_TRAVIS", "TRAINER_TEAM_ROCKET_GRUNT_39"], -"SilphCo_11F": ["TRAINER_BOSS_GIOVANNI_2", "TRAINER_TEAM_ROCKET_GRUNT_40", "TRAINER_TEAM_ROCKET_GRUNT_41"], -"SilphCo_2F": ["TRAINER_SCIENTIST_CONNOR", "TRAINER_SCIENTIST_JERRY", "TRAINER_TEAM_ROCKET_GRUNT_23", "TRAINER_TEAM_ROCKET_GRUNT_24"], -"SilphCo_3F": ["TRAINER_SCIENTIST_JOSE", "TRAINER_TEAM_ROCKET_GRUNT_25"], -"SilphCo_4F": ["TRAINER_SCIENTIST_RODNEY", "TRAINER_TEAM_ROCKET_GRUNT_26", "TRAINER_TEAM_ROCKET_GRUNT_27"], -"SilphCo_5F": ["TRAINER_JUGGLER_DALTON", "TRAINER_SCIENTIST_BEAU", "TRAINER_TEAM_ROCKET_GRUNT_28", "TRAINER_TEAM_ROCKET_GRUNT_29"], -"SilphCo_6F": ["TRAINER_SCIENTIST_TAYLOR", "TRAINER_TEAM_ROCKET_GRUNT_30", "TRAINER_TEAM_ROCKET_GRUNT_31"], -"SilphCo_7F": ["TRAINER_RIVAL_SILPH_BULBASAUR", "TRAINER_RIVAL_SILPH_CHARMANDER", "TRAINER_RIVAL_SILPH_SQUIRTLE", "TRAINER_SCIENTIST_JOSHUA", "TRAINER_TEAM_ROCKET_GRUNT_33", "TRAINER_TEAM_ROCKET_GRUNT_34", "TRAINER_TEAM_ROCKET_GRUNT_35"], -"SilphCo_8F": ["TRAINER_SCIENTIST_PARKER", "TRAINER_TEAM_ROCKET_GRUNT_32", "TRAINER_TEAM_ROCKET_GRUNT_36"], -"SilphCo_9F": ["TRAINER_SCIENTIST_ED", "TRAINER_TEAM_ROCKET_GRUNT_37", "TRAINER_TEAM_ROCKET_GRUNT_38"], -"SixIsland_GreenPath": ["TRAINER_PSYCHIC_JACLYN"], -"SixIsland_OutcastIsland": ["TRAINER_FISHERMAN_TYLOR", "TRAINER_SIS_AND_BRO_AVA_GEB", "TRAINER_SWIMMER_FEMALE_NICOLE", "TRAINER_SWIMMER_MALE_MYMO", "TRAINER_TEAM_ROCKET_GRUNT_46"], -"SixIsland_PatternBush": ["TRAINER_BUG_CATCHER_GARRET", "TRAINER_BUG_CATCHER_JONAH", "TRAINER_BUG_CATCHER_VANCE", "TRAINER_CAMPER_RILEY", "TRAINER_LASS_DALIA", "TRAINER_LASS_JOANA", "TRAINER_PICNICKER_MARCY", "TRAINER_PKMN_BREEDER_ALLISON", "TRAINER_PKMN_BREEDER_BETHANY", "TRAINER_RUIN_MANIAC_LAYTON", "TRAINER_YOUNGSTER_CORDELL", "TRAINER_YOUNGSTER_NASH"], -"SixIsland_RuinValley": ["TRAINER_HIKER_DARYL", "TRAINER_POKEMANIAC_HECTOR", "TRAINER_RUIN_MANIAC_FOSTER", "TRAINER_RUIN_MANIAC_LARRY", "TRAINER_RUIN_MANIAC_STANLY"], -"SixIsland_WaterPath": ["TRAINER_AROMA_LADY_ROSE", "TRAINER_HIKER_EARL", "TRAINER_JUGGLER_EDWARD", "TRAINER_SWIMMER_FEMALE_DENISE", "TRAINER_SWIMMER_MALE_SAMIR", "TRAINER_TWINS_MIU_MIA"], -"ThreeIsland": ["TRAINER_BIKER_GOON", "TRAINER_BIKER_GOON_2", "TRAINER_BIKER_GOON_3", "TRAINER_CUE_BALL_PAXTON"], -"ThreeIsland_BondBridge": ["TRAINER_AROMA_LADY_NIKKI", "TRAINER_AROMA_LADY_VIOLET", "TRAINER_SWIMMER_FEMALE_TISHA", "TRAINER_TUBER_ALEXIS", "TRAINER_TUBER_AMIRA", "TRAINER_TWINS_JOY_MEG"], -"VermilionCity_Gym": ["TRAINER_ENGINEER_BAILY", "TRAINER_GENTLEMAN_TUCKER", "TRAINER_LEADER_LT_SURGE", "TRAINER_SAILOR_DWAYNE"], -"VictoryRoad_1F": ["TRAINER_COOLTRAINER_NAOMI", "TRAINER_COOLTRAINER_ROLANDO"], -"VictoryRoad_2F": ["TRAINER_BLACK_BELT_DAISUKE", "TRAINER_JUGGLER_GREGORY", "TRAINER_JUGGLER_NELSON", "TRAINER_POKEMANIAC_DAWSON", "TRAINER_TAMER_VINCENT"], -"VictoryRoad_3F": ["TRAINER_COOLTRAINER_ALEXA", "TRAINER_COOLTRAINER_CAROLINE", "TRAINER_COOLTRAINER_COLBY", "TRAINER_COOLTRAINER_GEORGE", "TRAINER_COOL_COUPLE_RAY_TYRA"], -"ViridianCity_Gym": ["TRAINER_BLACK_BELT_ATSUSHI", "TRAINER_BLACK_BELT_KIYO", "TRAINER_BLACK_BELT_TAKASHI", "TRAINER_COOLTRAINER_SAMUEL", "TRAINER_COOLTRAINER_WARREN", "TRAINER_COOLTRAINER_YUJI", "TRAINER_LEADER_GIOVANNI", "TRAINER_TAMER_COLE", "TRAINER_TAMER_JASON"], -"ViridianForest": ["TRAINER_BUG_CATCHER_ANTHONY", "TRAINER_BUG_CATCHER_CHARLIE", "TRAINER_BUG_CATCHER_DOUG", "TRAINER_BUG_CATCHER_RICK", "TRAINER_BUG_CATCHER_SAMMY"] -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 8e02ced513..5e48eeaf18 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -28,7 +28,6 @@ #include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryBattleDecisions.h" #include "PokemonFRLG_AutoStoryBattle.h" -#include "PokemonFRLG_AutoStoryFoeTracker.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -328,7 +327,6 @@ class BattleLoop{ , m_supplies(supplies) , m_decisions(supplies, kind) , m_evolution(supplies.lead) - , m_foes(kind == BattleKind::TRAINER ? supplies.trainer : "", supplies.lead) , m_kind(kind) , m_checks(checks) , m_language(language) @@ -399,7 +397,6 @@ class BattleLoop{ m_last_battle = now; read_hp(screen); watch_for_faint(screen); - m_foes.boxes_seen(BattleBoxes{.lead = BattlePokemonDetector(COLOR_RED).detect(screen), .foe = BattleOpponentDetector(COLOR_RED).detect(screen)}); act(seen, screen, now); return false; } @@ -602,9 +599,8 @@ class BattleLoop{ if (m_kind != BattleKind::TRAINER && m_decisions.turns() == 0){ m_supplies.wild_foes = read_wild_foes(m_console.logger(), m_language, screen); } - if (!m_foes.species().empty()){ - m_foes.at_menu(read_trainer_foe(m_console.logger(), m_language, screen, m_foes.species())); - m_supplies.foe_out = m_foes.out(); + if (m_kind == BattleKind::TRAINER && !m_supplies.foes.empty()){ + m_supplies.foe_out = read_trainer_foe(m_console.logger(), m_language, screen, m_supplies.foes); } if (m_refusal.refused(current_time())){ m_console.log("Battle: the move list came back without a turn (Disable?); choosing another move.", COLOR_ORANGE); @@ -655,7 +651,6 @@ class BattleLoop{ Supplies& m_supplies; BattleDecisions m_decisions; EvolutionHold m_evolution; - TrainerFoeTracker m_foes; BattleEndWatch m_end; MoveRefusalWatch m_refusal; const BattleKind m_kind; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index 7f65bf3d0b..83cd611d35 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -88,9 +88,10 @@ struct Supplies{ std::string trainer = {}; // How carefully that battle is fought (story_battle_risk()). BattleRisk risk = BattleRisk::LOW; - // The slot of the trainer's party out, as the battle loop tracks it - // (TrainerFoeTracker): the lead's attacks are chosen against it. - std::optional foe_out = {}; + // The species of the trainer's Pokemon out, as read at the last battle + // menu (read_trainer_foe()), "" if not read: the lead's attacks are + // chosen against it. + std::string foe_out = {}; // The wild Pokemon of the battle going on, as read at its first battle // menu (read_wild_foes()): the lead's attacks are chosen against it. // Empty when it wasn't read; trainer battles never use it. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp index 186f737d0f..34a2a1e90e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp @@ -280,12 +280,6 @@ std::string read_trainer_foe(Logger& logger, Language language, const ImageViewR return read; } -std::vector map_trainers(std::string_view map){ - const JsonObject& maps = file_json("map_trainers").to_object_throw(); - const auto it = maps.find(std::string(map)); - return it == maps.end() ? std::vector{} : strings_of(it->second); -} - std::optional story_trainer(std::string_view map, std::string_view battle){ for (const StoryTrainer& entry : STORY_TRAINERS){ if (entry.map == map && entry.battle == battle){ @@ -295,7 +289,7 @@ std::optional story_trainer(std::string_view map, std::string_ return std::nullopt; } -const char* battle_risk_name(BattleRisk risk){ +std::string_view battle_risk_name(BattleRisk risk){ return risk == BattleRisk::HIGH ? "high" : "low"; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h index bb9dc65af4..379a9f3e25 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h @@ -6,9 +6,9 @@ * pret/pokefirered by devtools/maps/frlg_battle_data.py into BattleData/ * and built into the program: the type chart, every species' types and * base stats, every move's power, type, PP, accuracy, priority and - * effect, every trainer's AI flags, items and party, and the trainers - * each map battles. Also which trainer each of the story's battle steps - * fights, and how carefully (BattleRisk). + * effect, and every trainer's AI flags, items and party. Also which + * trainer each of the story's battle steps fights, and how carefully + * (BattleRisk). * * Names are the program's slugs ("water-gun", "mr-mime"); trainers are * pret's constants ("TRAINER_SUPER_NERD_MIGUEL"). @@ -138,9 +138,6 @@ std::optional trainer_data(std::string_view trainer); // Empty if not read. Logs what it read. std::string read_trainer_foe(Logger& logger, Language language, const ImageViewRGB32& screen, const std::vector& party); -// The trainers `map`'s scripts and objects battle. -std::vector map_trainers(std::string_view map); - // The trainer the story's battle step `battle` fights on `map` (the map // it leaves the player on). None for a battle the table doesn't name. std::optional story_trainer(std::string_view map, std::string_view battle); @@ -149,12 +146,12 @@ std::optional story_trainer(std::string_view map, std::string_ enum class BattleRisk{ // The move with the best expected damage against the foe out. LOW, - // A battle sim (PokemonFRLG_AutoStoryBattleSim.h) picks the moves and - // Potions, and the step fails before the fight when it wins too rarely. + // The battles the simulation's plan is for (the rival, gym leaders, + // bosses); fought as LOW until the checkpoint carries a plan. HIGH, }; // String representation of battle risk level. -const char* battle_risk_name(BattleRisk risk); +std::string_view battle_risk_name(BattleRisk risk); // A trainer's risk by its kind: HIGH for the rival, gym leaders, bosses // (Giovanni, the Rocket admins), the Elite Four and the Champion; LOW @@ -165,9 +162,6 @@ BattleRisk default_battle_risk(std::string_view trainer); // else its trainer's default. LOW for a battle the table doesn't name. BattleRisk story_battle_risk(std::string_view map, std::string_view battle); -// A HIGH battle is fought only if the sim wins at least this often. -inline constexpr double MIN_WIN_CHANCE = 0.70; - // (name, JSON text) of each file in BattleData/, sorted by name. // Generated at build time (SerialPrograms/cmake/EmbedTextFiles.cmake). diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp index d2e1cda312..77bbf0a6ca 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp @@ -12,13 +12,14 @@ #include #include #include +#include +#include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "PokemonFRLG_AutoStoryBattle.h" #include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryBattleDecisions.h" -#include "PokemonFRLG_AutoStoryBattleSim.h" #include "PokemonFRLG_AutoStoryParty.h" #include "PokemonFRLG_AutoStoryTable.h" @@ -35,7 +36,7 @@ struct AutoStoryBattleDataInput{ }; struct AutoStoryBattleDataExpectation{ - const char* description; + std::string_view description; }; struct AutoStoryBattleDataTestCase{ @@ -107,8 +108,7 @@ UnitTestResult test_data(){ return true; } -// Every battle step in the table fights a trainer its map battles in -// pret's scripts, with a party. +// Every battle step in the table fights a trainer with a party. UnitTestResult test_story_trainers(){ size_t battles = 0; for (const StoryCheckpoint& checkpoint : story_checkpoints()){ @@ -122,10 +122,6 @@ UnitTestResult test_story_trainers(){ if (!trainer){ return std::format("{}, {} on {}: no trainer.", checkpoint.id, step.name, map); } - const std::vector on_map = map_trainers(map); - if (std::find(on_map.begin(), on_map.end(), *trainer) == on_map.end()){ - return std::format("{} on {}: {} isn't one of the map's trainers.", step.name, map, *trainer); - } if (trainer_party(*trainer).empty()){ return std::format("{} on {}: {} has no party.", step.name, map, *trainer); } @@ -183,6 +179,25 @@ UnitTestResult test_bite_wins(){ return true; } +// The default risks: the rival and gym leaders HIGH, route trainers and +// grunts LOW. +UnitTestResult test_risks(){ + const std::vector> cases = { + {"CeruleanCity", "rival_cerulean", BattleRisk::HIGH}, + {"CeruleanCity_Gym", "misty", BattleRisk::HIGH}, + {"PewterCity_Gym", "brock", BattleRisk::HIGH}, + {"Route24", "lass_ali", BattleRisk::LOW}, + {"MtMoon_B2F", "rocket_grunt", BattleRisk::LOW}, + {"Route1", "nobody", BattleRisk::LOW}, + }; + for (const auto& [map, battle, risk] : cases){ + if (story_battle_risk(map, battle) != risk){ + return std::format("{} on {}: expected {}.", battle, map, battle_risk_name(risk)); + } + } + return true; +} + // A wild Pokemon that wasn't read, or a name the data doesn't have, gets // the plan's order: Water Gun first. UnitTestResult test_wild_fallback(){ @@ -220,6 +235,10 @@ const AutoStoryBattleDataTestCase AUTO_STORY_BATTLE_DATA_CASES[] = { .input = {.name = "a wild Pokemon not read: the plan's order", .body = test_wild_fallback}, .expectation = {.description = "falls back to default move preference when unread"}, }, + { + .input = {.name = "battle risks by trainer", .body = test_risks}, + .expectation = {.description = "rival and gym leaders HIGH, route trainers and grunts LOW"}, + }, }; } // namespace @@ -229,7 +248,6 @@ void add_tests_AutoStoryBattleData(UnitTestDatabase& database){ for (const auto& scenario : AUTO_STORY_BATTLE_DATA_CASES){ database.add(scenario); } - add_tests_AutoStoryBattleSim(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp index 21a587697d..4cff39ebe1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -7,7 +7,6 @@ #include #include #include "PokemonFRLG_AutoStoryBattleDecisions.h" -#include "PokemonFRLG_AutoStoryBattleSim.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -48,61 +47,32 @@ constexpr Milliseconds REFUSED_WITHIN = std::chrono::milliseconds(7000); constexpr size_t LOW_ATTACK_PP = 10; // The move prompts a turn can bring: two moves offered, NO then YES each. constexpr int MOVE_PROMPTS = 4; +// The HP a Potion heals (pret src/data/items.h). +constexpr double POTION_HP = 20; -// The trainer's Pokemon out, at full HP (its damage taken isn't read), -// when the battle loop knows which. -std::optional foe_out(const Supplies& supplies){ - if (supplies.trainer.empty() || !supplies.foe_out){ - return std::nullopt; - } - const std::vector party = trainer_mons(supplies.trainer); - return *supplies.foe_out < party.size() ? trainer_battler(party[*supplies.foe_out]) : std::nullopt; -} - -// A trainer's battle: against the foe out, the best expected damage at -// BattleRisk::LOW, the sim's planned move at HIGH (its items taken as not -// used yet); else, or while the story doesn't know all the lead's -// moves, attack_slot_against() the whole party. +// A trainer's battle, until the checkpoint carries the simulation's plan: +// the strongest move (attack_slot_against()) against the foe out as read +// at the battle menu, else against the whole party. std::optional trainer_attack_slot(const PartyMember& usable, const Supplies& supplies){ - const std::optional foe = foe_out(supplies); - const std::optional own = own_battler(usable); - std::optional slot; - if (foe && own && attack_slot(usable)){ - const std::optional trainer = trainer_data(supplies.trainer); - slot = supplies.risk == BattleRisk::HIGH && trainer - ? planned_attack_slot(*own, *foe, trainer->items, trainer->party.size()) - : best_damage_slot(*own, *foe); + if (!supplies.foe_out.empty()){ + return attack_slot_against(usable, std::vector{supplies.foe_out}); } - return slot ? slot : attack_slot_against(usable, supplies.foes); + return attack_slot_against(usable, supplies.foes); } -// A Potion this turn, against a known foe (`seen_hit` the HP its last hit -// took, 0 if not seen): at BattleRisk::HIGH when its next hit could faint -// the lead (potion_now(), the HP from the bar's share) or the bar is red, -// at LOW whenever the bar isn't green; either only if potion_pays(). -// Against a foe not known, whenever the bar isn't green, unless the last -// hit took a Potion's worth or more. -bool wants_potion(const Supplies& supplies, const PartyStatus& status, double seen_hit){ - const bool hurt = status.hp_red || status.hp_yellow; - const std::optional foe = foe_out(supplies); - const std::optional own = own_battler(supplies.lead, status.hp_seen ? status.hp_fill : 1.0); - if (!foe || !own){ - return hurt && seen_hit < POTION_HP; - } - if (supplies.risk == BattleRisk::HIGH && potion_now(*own, *foe, supplies.potions, seen_hit)){ - return true; - } - const bool asked = supplies.risk == BattleRisk::HIGH ? status.hp_red : hurt; - return asked && potion_pays(potion_case(*own, *foe, seen_hit)); +// A Potion this turn: whenever the bar isn't green, unless the last hit +// took a Potion's worth or more (`seen_hit`, 0 if not seen). +bool wants_potion(const PartyStatus& status, double seen_hit){ + return (status.hp_red || status.hp_yellow) && seen_hit < POTION_HP; } -// The lead's HP from the bar's share, if it showed. +// The lead's HP from the bar's share, if it showed and POKEMON SKILLS was +// read for its species. std::optional lead_hp(const Supplies& supplies, const PartyStatus& status){ - const std::optional own = own_battler(supplies.lead); - if (!status.hp_seen || !own){ + if (!status.hp_seen || !supplies.lead.stats){ return std::nullopt; } - return status.hp_fill * own->body.stats.hp; + return status.hp_fill * supplies.lead.stats->hp; } } // namespace @@ -165,7 +135,7 @@ TurnAction BattleDecisions::lead_turn(const PartyStatus& status){ return TurnAction{.choice = TurnChoice::RUN}; } see_hit(status); - if (!m_items_off && m_supplies.potions > 0 && wants_potion(m_supplies, status, m_seen_hit)){ + if (!m_items_off && m_supplies.potions > 0 && wants_potion(status, m_seen_hit)){ return TurnAction{.choice = TurnChoice::POTION}; } if (!m_items_off && m_psn_reads >= PSN_READS && !m_antidote_used && m_supplies.antidotes > 0){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h index 5c115b1235..e8de3d3882 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h @@ -155,7 +155,7 @@ class BattleDecisions{ // The HP the last hit seen took, from the foe out `m_hit_by`; 0 if none // was seen. double m_seen_hit = 0; - std::optional m_hit_by; + std::string m_hit_by; // The slots the game turned down, and the turns until they are tried again. std::map m_refused; // The members sent in after the lead fainted. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp deleted file mode 100644 index 527fdfc447..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp +++ /dev/null @@ -1,576 +0,0 @@ -/* AutoStory Battle Sim - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include -#include -#include "PokemonFRLG_AutoStoryBattleSim.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -namespace{ - -constexpr int START_SCORE = 100; -constexpr int BAD_MOVE = 10; -constexpr int CAN_FAINT = 4; -constexpr int QUICK_FAINT = 2; -constexpr int NOT_STRONGEST = 1; -constexpr int MAX_STAGE = 6; -// More turns than this to faint a foe counts as never. -constexpr size_t TURNS_CAP = 30; -// The hits a multi-hit move is taken to land when sizing a foe's hit. -constexpr uint32_t MULTI_HITS = 3; - -const MoveData& data_of(std::string_view move){ - static const MoveData NONE; - const MoveData* data = move_data(move); - return data == nullptr ? NONE : *data; -} - -size_t effectiveness(PokemonType type, const Combatant& target){ - size_t tenths = 10; - for (size_t multiplier : type_multipliers(type, target.first, target.second)){ - tenths = tenths * multiplier / 10; - } - return tenths; -} - -bool has_type(const Combatant& combatant, PokemonType type){ - return combatant.first == type || combatant.second == type; -} - -uint32_t hits_of(const MoveData& move){ - if (move.effect == "multi-hit"){ - return MULTI_HITS; - } - return move.effect == "double-hit" || move.effect == "twineedle" ? 2 : 1; -} - -uint32_t speed_of(const SimBattler& battler){ - const uint32_t speed = staged_stat(battler.body.stats.speed, battler.body.stages[static_cast(Stage::SPEED)]); - return battler.status == SimStatus::PARALYSIS ? speed / 4 : speed; -} - -bool status_effect(std::string_view effect){ - return effect == "sleep" || effect == "poison" || effect == "toxic" || effect == "paralyze"; -} - -// A stat-stage effect ("attack-down", "defense-up-2") at its limit. -bool stage_at_limit(std::string_view effect, const SimBattler& user, const SimBattler& target){ - static const std::pair STATS[] = { - {"attack-", Stage::ATTACK}, {"defense-", Stage::DEFENSE}, {"speed-", Stage::SPEED}, - {"special-attack-", Stage::SP_ATTACK}, {"special-defense-", Stage::SP_DEFENSE}, - {"accuracy-", Stage::ACCURACY}, {"evasion-", Stage::EVASION}, - }; - for (const auto& [prefix, stage] : STATS){ - if (!effect.starts_with(prefix) || effect.ends_with("-hit")){ - continue; - } - const bool up = effect.substr(prefix.size()).starts_with("up"); - const int now = (up ? user : target).body.stages[static_cast(stage)]; - return up ? now >= MAX_STAGE : now <= -MAX_STAGE; - } - return false; -} - -// AI_CheckBadMove, as the top of the header says. -bool bad_move(const MoveData& move, const SimBattler& user, const SimBattler& target){ - if (move.power > 0 && effectiveness(move.type, target.body) == 0){ - return true; - } - if (status_effect(move.effect) && target.status != SimStatus::NONE){ - return true; - } - if ((move.effect == "poison" || move.effect == "toxic") - && (has_type(target.body, PokemonType::POISON) || has_type(target.body, PokemonType::STEEL)) - ){ - return true; - } - if (move.effect == "leech-seed" && (target.seeded || has_type(target.body, PokemonType::GRASS))){ - return true; - } - if ((move.effect == "restore-hp" || move.effect == "softboiled") && user.hp >= user.body.stats.hp){ - return true; - } - return stage_at_limit(move.effect, user, target); -} - -void add_try_to_faint(std::vector& scores, const SimBattler& foe, const SimBattler& target){ - std::vector damage(foe.moves.size(), 0); - double strongest = 0; - for (size_t slot = 0; slot < foe.moves.size(); slot++){ - const MoveData& move = data_of(foe.moves[slot].move); - if (move.power > 0 && foe.moves[slot].pp > 0){ - damage[slot] = average_damage(foe.body, target.body, move) * hits_of(move); - strongest = move.power > 1 ? std::max(strongest, damage[slot]) : strongest; - } - } - for (size_t slot = 0; slot < foe.moves.size(); slot++){ - const MoveData& move = data_of(foe.moves[slot].move); - if (scores[slot] <= 0 || move.power == 0){ - continue; - } - if (damage[slot] >= target.hp){ - scores[slot] += CAN_FAINT + (move.effect == "quick-attack" ? QUICK_FAINT : 0); - }else if (move.power > 1 && damage[slot] < strongest){ - scores[slot] -= NOT_STRONGEST; - } - } -} - -// CHECK_VIABILITY's terms: HP in percent, a stage as the game's level (6 -// for none), the speed comparison, and if_random_less_than (n / 256). -int hp_percent(const SimBattler& battler){ - return battler.hp * 100 / std::max(battler.body.stats.hp, 1); -} -int level(const SimBattler& battler, Stage stage){ - return battler.body.stages[static_cast(stage)] + MAX_STAGE; -} -bool faster(const SimBattler& a, const SimBattler& b){ - return speed_of(a) > speed_of(b); -} -bool random_below(std::mt19937& rng, uint32_t n){ - return rng() % 256 < n; -} - -bool physical_type(PokemonType type){ - switch (type){ - case PokemonType::NORMAL: - case PokemonType::FIGHTING: - case PokemonType::GROUND: - case PokemonType::ROCK: - case PokemonType::BUG: - case PokemonType::STEEL: - return true; - default: - return false; - } -} - -int cv_attack_down(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ - int score = 0; - if (level(target, Stage::ATTACK) != MAX_STAGE){ - score -= user.hp * 100 > 90 * user.body.stats.hp ? 1 : 2; - score -= level(target, Stage::ATTACK) > 3 || random_below(rng, 50) ? 0 : 2; - } - score -= hp_percent(target) > 70 ? 0 : 2; - const bool physical = physical_type(target.body.first) || physical_type(target.body.second); - return score - (physical || random_below(rng, 50) ? 0 : 2); -} - -int cv_defense_down(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ - int score = 0; - if (hp_percent(user) < 70 || level(target, Stage::DEFENSE) <= 3){ - score -= random_below(rng, 50) ? 0 : 2; - } - return score - (hp_percent(target) > 70 ? 0 : 2); -} - -int cv_accuracy_down(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ - int score = 0; - if (hp_percent(user) < 70 || hp_percent(target) <= 70){ - score -= random_below(rng, 100) ? 0 : 1; - } - score -= level(user, Stage::ACCURACY) > 4 || random_below(rng, 80) ? 0 : 2; - score += target.seeded && !random_below(rng, 70) ? 2 : 0; - if (hp_percent(user) > 70 || level(target, Stage::ACCURACY) == MAX_STAGE){ - return score; - } - const bool low = hp_percent(user) < 40 || hp_percent(target) < 40; - return score - (low || !random_below(rng, 70) ? 2 : 0); -} - -int cv_toxic(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ - int score = 0; - score -= hp_percent(user) > 50 || random_below(rng, 50) ? 0 : 3; - return score - (hp_percent(target) > 50 || random_below(rng, 50) ? 0 : 3); -} - -int cv_heal(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ - if (hp_percent(user) == 100){ - return -3; - } - if (!faster(target, user)){ - return -8; - } - if (hp_percent(user) >= 70 && !random_below(rng, 30)){ - return -3; - } - return random_below(rng, 20) ? 0 : 2; -} - -// CHECK_VIABILITY for the status moves (see the header). -int viability(const MoveData& move, const SimBattler& user, const SimBattler& target, std::mt19937& rng){ - const std::string_view effect = move.effect; - if (effect == "attack-down"){ - return cv_attack_down(user, target, rng); - } - if (effect == "defense-down"){ - return cv_defense_down(user, target, rng); - } - if (effect == "accuracy-down"){ - return cv_accuracy_down(user, target, rng); - } - if (effect == "speed-down"){ - return faster(target, user) ? (random_below(rng, 70) ? 0 : 2) : -3; - } - if (effect == "poison"){ - return hp_percent(user) < 50 || hp_percent(target) <= 50 ? -1 : 0; - } - if (effect == "toxic" || effect == "leech-seed"){ - return cv_toxic(user, target, rng); - } - if (effect == "paralyze"){ - return faster(target, user) ? (random_below(rng, 20) ? 0 : 3) : (hp_percent(user) > 70 ? 0 : -1); - } - if (effect == "restore-hp" || effect == "softboiled"){ - return cv_heal(user, target, rng); - } - return 0; -} - -bool has_super_effective(const SimBattler& foe, const SimBattler& lead){ - return std::ranges::any_of(foe.moves, [&lead](const SimMove& known){ - const MoveData& move = data_of(known.move); - return move.power > 0 && effectiveness(move.type, lead.body) > 10; - }); -} - -// GetMostSuitableMonToSwitchInto's first pass: the lead's two types -// (the same one twice for a single type) against each, the best -// that has a super effective move. -std::optional suitable_by_type(const std::vector& left, const std::vector& party, const SimBattler& lead){ - std::set invalid; - while (invalid.size() < left.size()){ - std::optional best; - size_t best_tenths = 0; - for (size_t slot : left){ - const size_t tenths = invalid.contains(slot) ? 0 - : effectiveness(lead.body.first, party[slot].body) * effectiveness(lead.body.second, party[slot].body) / 10; - if (!invalid.contains(slot) && tenths > best_tenths){ - best = slot; - best_tenths = tenths; - } - } - if (!best){ - return std::nullopt; - } - if (has_super_effective(party[*best], lead)){ - return best; - } - invalid.insert(*best); - } - return std::nullopt; -} - -// Its second pass: the strongest move, compared as the game's u8 does. -std::optional suitable_by_damage(const std::vector& left, const std::vector& party, const SimBattler& fainted, const SimBattler& lead){ - std::optional best; - uint8_t best_damage = 0; - for (size_t slot : left){ - for (const SimMove& known : party[slot].moves){ - const MoveData& move = data_of(known.move); - const uint32_t damage = move.power > 1 ? damage_before_roll(fainted.body, lead.body, move, false) : 0; - if (best_damage < damage){ - best_damage = static_cast(damage); - best = slot; - } - } - } - return best; -} - -uint32_t lowest_roll(const SimBattler& own, const SimBattler& foe, const MoveData& move){ - return damage_range(own.body, foe.body, move, false).min * hits_of(move); -} - -double mean_per_turn(const SimBattler& own, const SimBattler& foe, const MoveData& move){ - const double accuracy = move.accuracy == 0 ? 1.0 : move.accuracy / 100.0; - return average_damage(own.body, foe.body, move) * hits_of(move) * accuracy; -} - -// Turns to faint `foe` with `per_turn` a turn, the AI healing it as -// ai_item_choice() says. -size_t turns_to_faint(SimBattler foe, std::vector items, size_t foes_left, double per_turn){ - double hp = foe.hp; - for (size_t turn = 1; turn <= TURNS_CAP; turn++){ - foe.hp = static_cast(std::max(0.0, std::ceil(hp))); - if (const std::optional item = ai_item_choice(foe, items, foes_left)){ - hp = std::min(foe.body.stats.hp, hp + ai_item_hp(items[*item])); - items[*item].clear(); - } - hp -= per_turn; - if (hp <= 0){ - return turn; - } - } - return TURNS_CAP + 1; -} - -// The slots with PP left that do damage to `foe`. -std::vector damaging_slots(const SimBattler& own, const SimBattler& foe){ - std::vector slots; - for (size_t slot = 0; slot < own.moves.size(); slot++){ - const MoveData& move = data_of(own.moves[slot].move); - if (own.moves[slot].pp > 0 && damage_before_roll(own.body, foe.body, move, false) > 0){ - slots.push_back(slot); - } - } - return slots; -} - -} // namespace - - -std::optional own_battler(const PartyMember& lead, double hp_share, const Genes& genes){ - std::optional body = combatant(lead.species, battle_level(lead), genes); - if (!body){ - return std::nullopt; - } - if (lead.stats && lead.level > 0){ - // The stats read, and what the levels since add with `genes`. - const Stats then = combatant(lead.species, lead.level, genes)->stats; - const Stats now = body->stats; - const auto grown = [](uint16_t read, uint16_t before, uint16_t after){ - return static_cast(read + after - before); - }; - body->stats = Stats{ - .hp = grown(lead.stats->hp, then.hp, now.hp), - .attack = grown(lead.stats->attack, then.attack, now.attack), - .defense = grown(lead.stats->defense, then.defense, now.defense), - .sp_attack = grown(lead.stats->sp_attack, then.sp_attack, now.sp_attack), - .sp_defense = grown(lead.stats->sp_defense, then.sp_defense, now.sp_defense), - .speed = grown(lead.stats->speed, then.speed, now.speed), - }; - } - SimBattler battler{.species = lead.species, .body = *body, .hp = 0, .moves = {}}; - battler.hp = static_cast(std::clamp(std::round(body->stats.hp * hp_share), 1, body->stats.hp)); - for (const KnownMove& known : lead.moves){ - battler.moves.push_back(SimMove{.move = known.move, .pp = known.pp}); - } - return battler; -} - -std::optional trainer_battler(const TrainerMon& mon){ - std::optional body = combatant(mon.species, mon.level, Genes{.iv = trainer_iv(mon.iv), .ev = 0, .nature = mon.nature}); - if (!body){ - return std::nullopt; - } - SimBattler battler{.species = mon.species, .body = *body, .hp = body->stats.hp, .moves = {}}; - for (const std::string& move : mon.moves){ - battler.moves.push_back(SimMove{.move = move, .pp = data_of(move).pp}); - } - return battler; -} - -std::optional sim_trainer(std::string_view trainer){ - const std::optional data = trainer_data(trainer); - if (!data || data->party.empty()){ - return std::nullopt; - } - SimTrainer sim{ - .party = {}, .items = data->items, - .check_bad_move = std::ranges::find(data->ai, "check-bad-move") != data->ai.end(), - .try_to_faint = std::ranges::find(data->ai, "try-to-faint") != data->ai.end(), - .check_viability = std::ranges::find(data->ai, "check-viability") != data->ai.end(), - }; - for (const TrainerMon& mon : data->party){ - std::optional battler = trainer_battler(mon); - if (!battler){ - return std::nullopt; - } - sim.party.push_back(std::move(*battler)); - } - return sim; -} - -uint16_t ai_item_hp(std::string_view item){ - static const std::pair HEALS[] = { - {"potion", 20}, {"super-potion", 50}, {"hyper-potion", 200}, {"max-potion", 255}, {"full-restore", 255}, - }; - for (const auto& [name, hp] : HEALS){ - if (name == item){ - return hp; - } - } - return 0; -} - -std::optional ai_item_choice(const SimBattler& foe, const std::vector& items, size_t foes_left){ - const uint16_t max_hp = foe.body.stats.hp; - for (size_t i = 0; i < items.size(); i++){ - if (i > 0 && foes_left > items.size() - i + 1){ - continue; - } - const uint16_t heal = ai_item_hp(items[i]); - if (heal == 0 || foe.hp == 0){ - continue; - } - const bool low = foe.hp < max_hp / 4; - if (low || (items[i] != "full-restore" && max_hp - foe.hp > heal)){ - return i; - } - } - return std::nullopt; -} - -std::vector ai_move_scores(const SimTrainer& trainer, const SimBattler& foe, const SimBattler& target, std::mt19937& rng){ - std::vector scores; - for (const SimMove& known : foe.moves){ - const MoveData& move = data_of(known.move); - const bool bad = trainer.check_bad_move && bad_move(move, foe, target); - const int viable = trainer.check_viability ? viability(move, foe, target, rng) : 0; - scores.push_back(known.pp == 0 ? 0 : START_SCORE - (bad ? BAD_MOVE : 0) + viable); - } - if (trainer.try_to_faint){ - add_try_to_faint(scores, foe, target); - } - return scores; -} - -size_t ai_next_foe(const std::vector& party, size_t fainted, const SimBattler& lead){ - std::vector left; - for (size_t slot = 0; slot < party.size(); slot++){ - if (slot != fainted && party[slot].hp > 0){ - left.push_back(slot); - } - } - if (left.empty()){ - return fainted; - } - if (const std::optional slot = suitable_by_type(left, party, lead)){ - return *slot; - } - if (const std::optional slot = suitable_by_damage(left, party, party[fainted], lead)){ - return *slot; - } - return left.front(); -} - -std::optional best_damage_slot(const SimBattler& own, const SimBattler& foe){ - std::optional best; - double best_damage = 0; - for (size_t slot : damaging_slots(own, foe)){ - const double damage = mean_per_turn(own, foe, data_of(own.moves[slot].move)); - if (damage > best_damage){ - best = slot; - best_damage = damage; - } - } - return best; -} - -std::optional planned_attack_slot( - const SimBattler& own, const SimBattler& foe, - const std::vector& items, size_t foes_left -){ - using Rank = std::tuple; - std::optional best; - Rank best_rank{}; - for (size_t slot : damaging_slots(own, foe)){ - const MoveData& move = data_of(own.moves[slot].move); - const bool faints = lowest_roll(own, foe, move) >= foe.hp; - const int sure = move.accuracy == 0 ? 100 : move.accuracy; - // Fewest turns, then surest, then weakest, then most PP left. - const size_t turns = faints ? 1 : turns_to_faint(foe, items, foes_left, mean_per_turn(own, foe, move)); - const Rank rank{turns, -(faints ? sure : 0), move.power, -own.moves[slot].pp}; - if (!best || rank < best_rank){ - best = slot; - best_rank = rank; - } - } - return best; -} - -uint32_t foe_max_hit(const SimBattler& foe, const SimBattler& own){ - uint32_t most = 0; - for (const SimMove& known : foe.moves){ - const MoveData& move = data_of(known.move); - if (known.pp > 0){ - most = std::max(most, damage_range(foe.body, own.body, move, false).max * hits_of(move)); - } - } - return most; -} - -PotionCase potion_case(const SimBattler& own, const SimBattler& foe, double seen_hit){ - double expected = 0; - for (const SimMove& known : foe.moves){ - if (known.pp > 0){ - expected = std::max(expected, mean_per_turn(foe, own, data_of(known.move))); - } - } - const std::optional slot = planned_attack_slot(own, foe, {}, 1); - const size_t turns = slot - ? turns_to_faint(foe, {}, 1, mean_per_turn(own, foe, data_of(own.moves[*slot].move))) - : TURNS_CAP + 1; - // A faster foe hits before each of the lead's attacks, a slower one - // only between them. - const size_t hits = speed_of(foe) >= speed_of(own) ? turns : turns - 1; - return PotionCase{ - .hp = own.hp, - .max_hp = own.body.stats.hp, - .expected_hit = std::max(expected, seen_hit), - .max_hit = std::max(foe_max_hit(foe, own), static_cast(std::ceil(seen_hit))), - .hits_to_ko = hits, - }; -} - -bool potion_pays(const PotionCase& c){ - const uint16_t heal = static_cast(std::min(POTION_HP, c.max_hp - c.hp)); - if (heal == 0){ - return false; - } - const double healed = c.hp + heal; - if (heal > c.expected_hit && healed > c.expected_hit){ - return true; - } - const bool lasts_if_healed = healed > c.expected_hit * static_cast(c.hits_to_ko + 1); - const bool lasts_now = c.hp > c.expected_hit * static_cast(c.hits_to_ko); - return lasts_if_healed && !lasts_now; -} - -bool potion_now(const SimBattler& own, const SimBattler& foe, int potions, double seen_hit){ - const uint16_t max_hp = own.body.stats.hp; - if (potions <= 0 || own.hp >= max_hp){ - return false; - } - const PotionCase c = potion_case(own, foe, seen_hit); - const uint32_t healed = std::min(max_hp, own.hp + POTION_HP); - return c.max_hit >= own.hp && healed > c.max_hit && potion_pays(c); -} - -OwnTurn own_turn( - const SimBattler& own, int potions, const SimBattler& foe, - const std::vector& items, size_t foes_left -){ - const std::optional slot = planned_attack_slot(own, foe, items, foes_left); - if (slot){ - const MoveData& move = data_of(own.moves[*slot].move); - const bool foe_priority = std::ranges::any_of(foe.moves, [](const SimMove& known){ - return known.pp > 0 && data_of(known.move).priority > 0; - }); - const bool first = speed_of(own) > speed_of(foe) && !foe_priority && move.priority >= 0; - const bool sure = move.accuracy == 0 || move.accuracy >= 100; - if (first && sure && lowest_roll(own, foe, move) >= foe.hp && !ai_item_choice(foe, items, foes_left)){ - return OwnTurn{.potion = false, .slot = slot}; - } - } - if (potion_now(own, foe, potions)){ - return OwnTurn{.potion = true, .slot = std::nullopt}; - } - return OwnTurn{.potion = false, .slot = slot}; -} - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h deleted file mode 100644 index 1acd32e2a5..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h +++ /dev/null @@ -1,202 +0,0 @@ -/* AutoStory Battle Sim - * - * From: https://github.com/PokemonAutomation/ - * - * The story's lead against a trainer's party as Gen 3 FireRed plays it, - * for the battles fought at BattleRisk::HIGH: the Pokemon on each side, - * the trainer AI's choices (its items, its moves, its next Pokemon) and - * the lead's (its move, a Potion). PokemonFRLG_AutoStoryWinChance.h plays - * whole battles from these. - * - * The trainer's side is pret's: party, levels, IVs, natures, moves, items - * and AI flags (trainers.json). The lead is what its summary showed - * when the run started (species, level, moves and PP, stats from POKEMON - * SKILLS), with the levels since (battle_level()) added at OWN_GENES; - * without a summary, its species and battle_level() at OWN_GENES. - * - * Approximations, from pret/pokefirered: - * - The AI's move (battle_ai_script_commands.c, data/battle_ai_scripts.s): - * every move starts at 100; CHECK_BAD_MOVE takes 10 off a move the - * target is immune to, a status the target already has, Leech Seed on - * a seeded or Grass target, and a stat change past +-6; TRY_TO_FAINT - * adds 4 to a move that faints the target at the mean roll (6 for Quick - * Attack) and takes 1 off the damaging moves that aren't its strongest; - * CHECK_VIABILITY scores the status moves the early trainers carry - * (AI_CV_AttackDown, DefenseDown, AccuracyDown, SpeedDown, Poison, - * Toxic for Leech Seed too, Paralyze, Heal) by HP, speed and stages, - * with their random parts. The best score wins, ties at random. The - * other scripts, and CHECK_VIABILITY on damaging moves, are left out. - * - The AI's items (battle_ai_switch_items.c ShouldUseItem) as the game - * has them for the HP items: Full Restore below 1/4 HP, the others - * below 1/4 or when more HP is missing than the item heals; each item - * once, and item i > 0 only once at most itemsNo - i + 1 Pokemon are - * left. Other items are not used. - * - The AI's next Pokemon (GetMostSuitableMonToSwitchInto): the one the - * lead's types hit hardest that has a super effective move against the - * lead, else the one whose strongest move does the lead most damage, - * else the first left. - */ - -#ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattleSim_H -#define PokemonAutomation_PokemonFRLG_AutoStoryBattleSim_H - -#include -#include -#include -#include -#include -#include -#include -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" -#include "PokemonFRLG_AutoStoryBattleData.h" -#include "PokemonFRLG_AutoStoryDamage.h" -#include "PokemonFRLG_AutoStoryParty.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -// The lead's IVs and EVs, which the story doesn't read: middling IVs, no -// EVs, a neutral nature (Hardy). -inline constexpr Genes OWN_GENES{.iv = 15, .ev = 0, .nature = 0}; - -// HP a Potion heals. -inline constexpr uint16_t POTION_HP = 20; - -// Simulated battler status condition. -enum class SimStatus{ - NONE, - SLEEP, - POISON, // and Toxic, as plain poison - PARALYSIS, -}; - -// A move in simulated combat. -struct SimMove{ - std::string move = {}; - uint8_t pp = 0; -}; - -// A Pokemon in the sim. -struct SimBattler{ - std::string species = {}; - Combatant body = {}; - uint16_t hp = 0; - // In the move list's slot order. - std::vector moves = {}; - SimStatus status = SimStatus::NONE; - // SLEEP: the game's counter (2 to 5): each turn takes one off, and it - // moves on the turn it reaches 0. - uint8_t sleep = 0; - bool seeded = false; -}; - -// The lead with `hp_share` of its HP (1 for full), its moves and PP as -// the story counts them, at battle_level(): its stats as read -// (PartyMember::stats) plus what the levels since add with `genes`, else -// from `genes`. None for a species the data doesn't have. -std::optional own_battler(const PartyMember& lead, double hp_share = 1.0, const Genes& genes = OWN_GENES); - -// A trainer's Pokemon at full HP and PP. -std::optional trainer_battler(const TrainerMon& mon); - -// Simulated opposing trainer state. -struct SimTrainer{ - std::vector party = {}; - // Each used once; a used one becomes "". - std::vector items = {}; - bool check_bad_move = false; - bool try_to_faint = false; - bool check_viability = false; -}; -// None for a trainer the data doesn't have (or a species in its party). -std::optional sim_trainer(std::string_view trainer); - - -// The HP the AI's `item` heals (255 for all of it), 0 for one that -// doesn't heal. -uint16_t ai_item_hp(std::string_view item); - -// The item the AI uses on `foe` this turn (its index in `items`), with -// `foes_left` Pokemon on its side not fainted, none for its move. -std::optional ai_item_choice(const SimBattler& foe, const std::vector& items, size_t foes_left); - -// The scores the AI gives `foe`'s moves against `target` (see the top); -// 0 for a move with no PP. In slot order. `rng` for CHECK_VIABILITY's -// random parts. -std::vector ai_move_scores(const SimTrainer& trainer, const SimBattler& foe, const SimBattler& target, std::mt19937& rng); - -// The party slot the AI sends out after `fainted`, of the ones still up. -size_t ai_next_foe(const std::vector& party, size_t fainted, const SimBattler& lead); - - -// BattleRisk::LOW: the slot with PP left whose mean damage against `foe` -// is highest. None if no move does damage. -std::optional best_damage_slot(const SimBattler& own, const SimBattler& foe); - -// BattleRisk::HIGH: a move that faints `foe` at the lowest roll, the -// weakest of them to keep the strong moves' PP; else the one that faints -// it in the fewest turns at the mean roll and accuracy, counting the -// heals the AI would use on it from `items` (ai_item_choice()), ties to -// the weaker move. None if no move does damage. -std::optional planned_attack_slot( - const SimBattler& own, const SimBattler& foe, - const std::vector& items, size_t foes_left -); - -// The most `foe` can do to `own` with one move, no crit, highest roll. -uint32_t foe_max_hit(const SimBattler& foe, const SimBattler& own); - -// What a Potion now is weighed on. -struct PotionCase{ - uint16_t hp = 0; - uint16_t max_hp = 0; - // The foe's next hit, on average and at most. - double expected_hit = 0; - uint32_t max_hit = 0; - // The foe's hits the lead takes before its attacks faint the foe, if - // it attacks from now on. - size_t hits_to_ko = 0; -}; -// `own` against `foe`: the foe's strongest move at the mean roll and -// accuracy, or `seen_hit` (HP the last hit took, as the battle loop read -// it) if more; the lead's planned move against the foe at its HP now. -PotionCase potion_case(const SimBattler& own, const SimBattler& foe, double seen_hit = 0); - -// At either BattleRisk: a Potion is worth the turn only if, after it and -// the foe's expected hit, the lead has gained HP, or if it lets the lead -// last until its attacks faint the foe when attacking now wouldn't. -// Otherwise it attacks: a Potion the next hit undoes only gives the foe -// another turn (console B, 2026-11-03, m51: five Potions at 8/60 HP each -// undone by Misty's Starmie, then no Potions and a faint). -bool potion_pays(const PotionCase& c); - -// BattleRisk::HIGH: a Potion now: `foe`'s next hit could faint `own`, -// after the Potion it couldn't, and potion_pays(). -bool potion_now(const SimBattler& own, const SimBattler& foe, int potions, double seen_hit = 0); - -// The lead's turn at BattleRisk::HIGH. -struct OwnTurn{ - bool potion = false; - // Not a Potion: the move's slot, none if no move does damage. - std::optional slot = std::nullopt; -}; -// planned_attack_slot()'s move when it surely faints `foe` first (the -// lead is faster, the lowest roll faints it, it never misses and the AI -// won't heal first), else a Potion if potion_now(), else that move. -OwnTurn own_turn( - const SimBattler& own, int potions, const SimBattler& foe, - const std::vector& items, size_t foes_left -); - - -// The damage calculator, the sim's choices and its win chance. -void add_tests_AutoStoryBattleSim(UnitTestDatabase& database); - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp deleted file mode 100644 index d617a8b611..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp +++ /dev/null @@ -1,509 +0,0 @@ -/* AutoStory Battle Sim Tests - * - * From: https://github.com/PokemonAutomation/ - * - * The Gen 3 damage calculator against numbers worked by hand and the - * Elite Four Farmer's Starmie table, the move chosen against the foe out, - * the trainer AI's items and next Pokemon, and the win chance before the - * Cerulean rival. - * - */ - -#include -#include -#include -#include -#include -#include -#include "Common/Cpp/Exceptions.h" -#include "Common/Cpp/TestRunners/UnitTest.h" -#include "PokemonFRLG_AutoStoryBattle.h" -#include "PokemonFRLG_AutoStoryBattleDecisions.h" -#include "PokemonFRLG_AutoStoryBattleSim.h" -#include "PokemonFRLG_AutoStoryFoeTracker.h" -#include "PokemonFRLG_AutoStoryWinChance.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -namespace{ - -struct AutoStoryBattleSimInput{ - std::string name; - UnitTestResult (*body)(); -}; - -struct AutoStoryBattleSimExpectation{ - const char* description; -}; - -struct AutoStoryBattleSimTestCase{ - AutoStoryBattleSimInput input; - AutoStoryBattleSimExpectation expectation; -}; - -class Test_AutoStoryBattleSim : public UnitTest{ -public: - explicit Test_AutoStoryBattleSim(AutoStoryBattleSimTestCase scenario) - : UnitTest("PokemonFRLG::AutoStoryBattleSim - " + scenario.input.name) - , m_scenario(std::move(scenario)) - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - try{ - return m_scenario.input.body(); - }catch (Exception& e){ - return std::string(e.name()) + ": " + e.message(); - } - } - -private: - AutoStoryBattleSimTestCase m_scenario; -}; - -constexpr std::string_view RIVAL = "TRAINER_RIVAL_CERULEAN_BULBASAUR"; -constexpr std::string_view MISTY = "TRAINER_LEADER_MISTY"; - -std::string stats_text(const Stats& s){ - return std::format("{}/{}/{}/{}/{}/{}", s.hp, s.attack, s.defense, s.sp_attack, s.sp_defense, s.speed); -} - -std::string range_text(const DamageRange& r){ - return std::format("{}-{}", r.min, r.max); -} - -// The story's Wartortle at Lv22, OWN_GENES. -Combatant wartortle22(){ - return *combatant("wartortle", 22, OWN_GENES); -} - -// The rival's Bulbasaur: Lv18, pret iv 100 (IVs 12), Hardy. -Combatant rival_bulbasaur(){ - return *combatant("bulbasaur", 18, Genes{.iv = trainer_iv(100), .ev = 0, .nature = 0}); -} - - -// Worked by hand from CalculateMonStats and CalculateBaseDamage: -// Wartortle Lv22 IV15: HP (2*59+15)*22/100+32 = 61, Attack 141*22/100+5 = 36, -// ... Bite on the Bulbasaur (Sp. Def 142*18/100+5 = 30): 36*60*10/30/50+2 -// = 16, no STAB, neutral: 13 to 16; a crit doubles the 16 before the -// roll: 27 to 32. Water Gun: 36*40*10/30/50+2 = 11, STAB 16, Grass 0.5x -// 8: 6 to 8. Its Vine Whip back: 30*35*9/43/50+2 = 6, STAB 9, Water 2x -// 18: 15 to 18. -UnitTestResult test_hand_numbers(){ - const Combatant own = wartortle22(); - const Combatant foe = rival_bulbasaur(); - if (stats_text(own.stats) != "61/36/43/36/43/33" || stats_text(foe.stats) != "46/24/24/30/30/23"){ - return "Stats: expected 61/36/43/36/43/33 and 46/24/24/30/30/23, got " + stats_text(own.stats) + " and " + stats_text(foe.stats) + "."; - } - const std::vector> cases = { - {"Bite", damage_range(own, foe, *move_data("bite"), false), "13-16"}, - {"Bite, crit", damage_range(own, foe, *move_data("bite"), true), "27-32"}, - {"Water Gun", damage_range(own, foe, *move_data("water-gun"), false), "6-8"}, - {"Vine Whip", damage_range(foe, own, *move_data("vine-whip"), false), "15-18"}, - {"Dragon Rage", damage_range(own, foe, *move_data("dragon-rage"), false), "40-40"}, - }; - for (const auto& [name, range, expected] : cases){ - if (range_text(range) != expected){ - return std::format("{}: expected {}, got {}.", name, expected, range_text(range)); - } - } - // Tail Whip's -1: Defense 24 * 10 / 15 = 16; Tackle 36*35*10/16/50+2 = 17. - Combatant whipped = foe; - whipped.stages[static_cast(Stage::DEFENSE)] = -1; - const DamageRange tackle = damage_range(own, whipped, *move_data("tackle"), false); - if (range_text(tackle) != "14-17"){ - return "Tackle after Tail Whip: expected 14-17, got " + range_text(tackle) + "."; - } - return true; -} - - -// The Elite Four Farmer's STARMIE_PLAN (PokemonFRLG_EliteFourFarmer.cpp): -// each pick "one-hit KOs each rematch opponent (min damage roll, no crit)" -// at Sp. Atk 302, Lv100. Every rematch party's Pokemon of that species. -const std::map& starmie_plan(){ - static const std::map PLAN = { - {"dewgong", "thunderbolt"}, {"cloyster", "thunderbolt"}, {"piloswine", "surf"}, - {"jynx", "surf"}, {"lapras", "thunderbolt"}, {"steelix", "surf"}, - {"hitmonchan", "psychic"}, {"hitmonlee", "psychic"}, {"machamp", "psychic"}, - {"gengar", "psychic"}, {"crobat", "thunderbolt"}, {"misdreavus", "surf"}, - {"arbok", "psychic"}, {"gyarados", "thunderbolt"}, {"dragonite", "ice-beam"}, - {"kingdra", "psychic"}, {"aerodactyl", "surf"}, {"heracross", "psychic"}, - {"alakazam", "surf"}, {"tyranitar", "surf"}, {"arcanine", "surf"}, - {"exeggutor", "ice-beam"}, {"blastoise", "thunderbolt"}, {"venusaur", "psychic"}, - {"charizard", "thunderbolt"}, - }; - return PLAN; -} - -Combatant starmie(uint16_t sp_attack){ - Combatant body = *combatant("starmie", 100, OWN_GENES); - body.stats.sp_attack = sp_attack; - body.volcano_badge = true; - return body; -} - -// The species whose pick misses the OHKO at `sp_attack`; "" for none. -std::string first_miss(uint16_t sp_attack, std::string_view only = ""){ - for (std::string_view trainer : { - "TRAINER_ELITE_FOUR_LORELEI_2", "TRAINER_ELITE_FOUR_BRUNO_2", "TRAINER_ELITE_FOUR_AGATHA_2", "TRAINER_ELITE_FOUR_LANCE_2", - "TRAINER_CHAMPION_REMATCH_SQUIRTLE", "TRAINER_CHAMPION_REMATCH_BULBASAUR", "TRAINER_CHAMPION_REMATCH_CHARMANDER", - }){ - for (const TrainerMon& mon : trainer_mons(trainer)){ - const auto pick = starmie_plan().find(mon.species); - if (pick == starmie_plan().end() || (!only.empty() && mon.species != only)){ - continue; - } - const Combatant foe = *combatant(mon.species, mon.level, Genes{.iv = trainer_iv(mon.iv), .ev = 0, .nature = mon.nature}); - const DamageRange range = damage_range(starmie(sp_attack), foe, *move_data(pick->second), false); - if (range.min < foe.stats.hp){ - return std::format("{} {} Lv{} ({} HP, {} {})", trainer, mon.species, mon.level, foe.stats.hp, pick->second, range_text(range)); - } - } - } - return ""; -} - -UnitTestResult test_elite_four_table(){ - const std::string miss = first_miss(302); - if (!miss.empty()){ - return "At Sp. Atk 302, no OHKO at the lowest roll: " + miss + "."; - } - if (first_miss(301, "kingdra").empty()){ - return "Expected Kingdra to set the 302 Sp. Atk requirement: Psychic OHKOs it at 301 too."; - } - return true; -} - - -// Misty's Staryu (Water) and Starmie (Water/Psychic): a lead with -// Thundershock and Bite thunders the Staryu (2x against 1x) and bites the -// Starmie (both 2x, Bite stronger). As the battle loop asks, with the -// foe out known; summing over the party picked one move for both. -UnitTestResult test_misty_per_foe(){ - const PartyMember lead = member_from_summary("wartortle", 22, { - {.move = "tackle", .pp = 35, .max_pp = 35}, {.move = "bite", .pp = 25, .max_pp = 25}, - {.move = "thunder-shock", .pp = 30, .max_pp = 30}, {.move = "withdraw", .pp = 40, .max_pp = 40}, - }); - for (const BattleRisk risk : {BattleRisk::LOW, BattleRisk::HIGH}){ - for (const auto& [out, expected] : {std::pair{0, 2}, {1, 1}}){ - Supplies supplies; - supplies.lead = lead; - supplies.potions = 0; - supplies.trainer = std::string(MISTY); - supplies.foes = trainer_party(MISTY); - supplies.risk = risk; - supplies.foe_out = out; - BattleDecisions decisions(supplies, BattleKind::TRAINER); - const PartyStatus green{.hp_seen = true, .hp_yellow = false, .hp_red = false, .hp_fill = 1, .status = StatusCondition::NONE}; - const size_t slot = decisions.turn(green).slot; - if (slot != expected){ - return std::format("Risk {}, foe {}: expected slot {}, got {}.", battle_risk_name(risk), out, expected, slot); - } - } - } - return true; -} - - -// ShouldUseItem for Misty's Super Potion on her Starmie (56 HP): below -// 1/4 (14) or more than 50 missing; a Full Restore only below 1/4. A -// second item waits until at most itemsNo - 1 + 1 Pokemon are left. -UnitTestResult test_ai_heal_rule(){ - SimBattler starmie = *trainer_battler(trainer_mons(MISTY)[1]); - if (starmie.body.stats.hp != 56){ - return std::format("Expected Misty's Starmie at 56 HP, got {}.", starmie.body.stats.hp); - } - const std::vector super = {"super-potion"}; - const std::vector, size_t, bool>> cases = { - {56, super, 1, false}, {20, super, 1, false}, {13, super, 1, true}, {5, super, 1, true}, - {20, {"full-restore"}, 1, false}, {13, {"full-restore"}, 1, true}, - {13, {"", "hyper-potion"}, 3, false}, {13, {"", "hyper-potion"}, 2, true}, - }; - for (const auto& [hp, items, left, uses] : cases){ - starmie.hp = hp; - if (ai_item_choice(starmie, items, left).has_value() != uses){ - return std::format("At {} HP with {} items, {} left: expected {}.", hp, items.size(), left, uses ? "an item" : "none"); - } - } - // Each item once: the heal it would use is gone after. - starmie.hp = 6; - std::vector once = super; - once[*ai_item_choice(starmie, once, 1)].clear(); - if (ai_item_choice(starmie, once, 1)){ - return "Expected the Super Potion used only once."; - } - return true; -} - - -// GetMostSuitableMonToSwitchInto against a Wartortle after the rival's -// Pidgeotto: Water hits Abra and Rattata 1x and Bulbasaur 0.25x, but -// only Bulbasaur has a move super effective on Water (Vine Whip): it -// comes next, not Abra. The tracker, with no name read, follows that. -UnitTestResult test_next_foe(){ - const PartyMember lead = grown_to(new_member("squirtle", 5), 22); - TrainerFoeTracker tracker(RIVAL, lead); - if (tracker.out() != 0){ - return "Expected the rival's Pidgeotto out first."; - } - for (int i = 0; i < 3; i++){ - tracker.boxes_seen(BattleBoxes{.lead = true, .foe = false}); - } - tracker.at_menu(""); - if (tracker.out() != 3){ - return std::format("Expected Bulbasaur (slot 3) after Pidgeotto, got {}.", tracker.out() ? std::to_string(*tracker.out()) : "none"); - } - tracker.at_menu("abra"); - if (tracker.out() != 1){ - return "Expected the name read (Abra) over the AI's choice."; - } - return true; -} - - -// The default risks: the rival and gym leaders HIGH, route trainers and -// grunts LOW. -UnitTestResult test_risks(){ - const std::vector> cases = { - {"CeruleanCity", "rival_cerulean", BattleRisk::HIGH}, - {"CeruleanCity_Gym", "misty", BattleRisk::HIGH}, - {"PewterCity_Gym", "brock", BattleRisk::HIGH}, - {"Route24", "lass_ali", BattleRisk::LOW}, - {"MtMoon_B2F", "rocket_grunt", BattleRisk::LOW}, - {"Route1", "nobody", BattleRisk::LOW}, - }; - for (const auto& [map, battle, risk] : cases){ - if (story_battle_risk(map, battle) != risk){ - return std::format("{} on {}: expected {}.", battle, map, battle_risk_name(risk)); - } - } - return true; -} - - -// The Cerulean rival (Pidgeotto, Abra, Rattata, then a Bulbasaur with -// Sleep Powder, Poison Powder and Leech Seed): the Lv22 Wartortle with 5 -// Potions that 00.15's GRIND plans for wins about a quarter of the sim's -// battles, and is refused with the reason; at Lv30 it wins over 90%. -UnitTestResult test_rival_win_chance(){ - const std::optional planned = story_win_chance(grown_to(new_member("squirtle", 5), 22), 5, 1.0, RIVAL); - const std::optional refusal = planned ? win_chance_refusal(*planned) : std::nullopt; - if (!planned || planned->chance < 0.15 || planned->chance > 0.40){ - return std::format("Lv22, 5 Potions: expected 15% to 40%, got {:.1f}%.", planned ? 100 * planned->chance : 0.0); - } - if (refusal != std::format("win chance {:.0f}% < 70% with {}: grind first", std::floor(100 * planned->chance), planned->inputs)){ - return "Lv22, 5 Potions: expected a refusal with the chance, got \"" + refusal.value_or("") + "\"."; - } - const std::optional ground = story_win_chance(grown_to(new_member("squirtle", 5), 30), 5, 1.0, RIVAL); - if (!ground || ground->chance < 0.90 || win_chance_refusal(*ground)){ - return std::format("Lv30, 5 Potions: expected over 90% and no refusal, got {:.1f}%.", ground ? 100 * ground->chance : 0.0); - } - return true; -} - - -// Console B, 2026-11-03 (run m51), Misty: the Wartortle's moves, Bite, -// Tail Whip, Bubble, Withdraw (Water Gun was lost earlier). -std::vector m51_moves(){ - return { - {.move = "bite", .pp = 25, .max_pp = 25}, {.move = "tail-whip", .pp = 30, .max_pp = 30}, - {.move = "bubble", .pp = 30, .max_pp = 30}, {.move = "withdraw", .pp = 40, .max_pp = 40}, - }; -} - -// m51's Wartortle as its summary would read: `level`, 60 HP at Lv20, -// the other stats at OWN_GENES. -PartyMember m51_lead(uint8_t level){ - Stats stats = combatant("wartortle", 20, OWN_GENES)->stats; - stats.hp = 60; - PartyMember lead = member_from_summary("wartortle", 20, m51_moves(), stats); - lead.moves_through_level = level; - return lead; -} - -// m51's Wartortle Lv20 at `hp` of 60. -SimBattler m51_wartortle(uint16_t hp){ - SimBattler own = *own_battler(m51_lead(20)); - own.hp = hp; - return own; -} - -// m51, turns 8 to 13: at 8/60 HP against Misty's Starmie, which hit -// about 20 a turn, the HIGH tier's Potion (+20) was undone by each hit, -// five times over; then Bite once with no Potions left, and it fainted. -// The loop replayed at either tier: once a Potion is seen undone by the -// next hit, no more, but Bite, which also flinches. -UnitTestResult test_m51_potion_loop(){ - for (const BattleRisk risk : {BattleRisk::LOW, BattleRisk::HIGH}){ - Supplies supplies; - supplies.lead = m51_lead(20); - supplies.potions = 5; - supplies.trainer = std::string(MISTY); - supplies.foes = trainer_party(MISTY); - supplies.risk = risk; - supplies.foe_out = 1; - BattleDecisions decisions(supplies, BattleKind::TRAINER); - const PartyStatus red{.hp_seen = true, .hp_yellow = false, .hp_red = true, .hp_fill = 8.0 / 60, .status = StatusCondition::NONE}; - int potions = 0; - for (int turn = 8; turn <= 13; turn++){ - const TurnAction action = decisions.turn(red); - if (action.choice == TurnChoice::POTION){ - potions++; - }else if (action.choice != TurnChoice::MOVE || action.slot != 0){ - return std::format("Risk {}, turn {}: expected a Potion or Bite (slot 0), got slot {}.", battle_risk_name(risk), turn, action.slot); - } - decisions.turn_done(action.choice, TurnResult::DONE); - } - if (potions > 1){ - return std::format("Risk {}: {} Potions at 8/60 HP over turns 8 to 13, each undone by the next hit; expected at most 1.", battle_risk_name(risk), potions); - } - } - return true; -} - -// The sim's own choice by the same rule: at 8/60 a Potion against a foe -// whose hit undoes it, no Potion; against one whose hit could faint the -// lead but heals less than 20, a Potion. -UnitTestResult test_sim_potion_rule(){ - const SimTrainer misty = *sim_trainer(MISTY); - SimBattler starmie = misty.party[1]; - const SimBattler own = m51_wartortle(8); - // Starmie as m51 saw it: at least the Potion's 20 a hit. - starmie.body.stats.attack = static_cast(starmie.body.stats.attack * 2); - starmie.body.stats.sp_attack = static_cast(starmie.body.stats.sp_attack * 2); - if (potion_case(own, starmie).expected_hit < POTION_HP){ - return std::format("Expected Starmie's mean hit at 20 or more, got {:.1f}.", potion_case(own, starmie).expected_hit); - } - const OwnTurn sim = own_turn(own, 5, starmie, misty.items, 1); - if (sim.potion || sim.slot != size_t(0)){ - return std::format( - "Sim at 8/60 against Starmie (max hit {}): expected Bite (slot 0), got {}.", - foe_max_hit(starmie, own), sim.potion ? "a Potion" : "slot " + std::to_string(sim.slot.value_or(9)) - ); - } - const SimBattler& staryu = misty.party[0]; - const SimBattler low = m51_wartortle(6); - const uint32_t hit = foe_max_hit(staryu, low); - if (hit < 6 || hit >= POTION_HP){ - return std::format("Expected Staryu's best hit on the Wartortle from 6 to 19, got {}.", hit); - } - if (!own_turn(low, 5, staryu, misty.items, 2).potion){ - return std::format("At 6/60 against Staryu (max hit {}): expected a Potion.", hit); - } - return true; -} - -// The sim plays the lead the summary showed, not the one the story -// counts: m51's Wartortle (Lv20, 60 HP, Bite, Tail Whip, Bubble, -// Withdraw) with 5 Potions wins about 96% against Misty; the story's own -// Wartortle Lv20 (Tackle, Bite, Water Gun, Withdraw; 56 HP at OWN_GENES) -// about 94%, from other inputs. m51 lost: the sim leaves out Water -// Pulse's confusion, among others (PokemonFRLG_AutoStoryWinChance.h). -UnitTestResult test_misty_real_lead(){ - const std::optional real = story_win_chance(m51_lead(20), 5, 1.0, MISTY); - const std::optional story = story_win_chance(grown_to(new_member("squirtle", 5), 20), 5, 1.0, MISTY); - if (!real || !story){ - return "Expected win chances for both leads."; - } - const std::string expected = "wartortle Lv20 60/60 HP: bite 25/25, tail-whip 30/30, bubble 30/30, withdraw 40/40; 5 Potions"; - if (real->inputs != expected){ - return "m51's lead: expected the inputs \"" + expected + "\", got \"" + real->inputs + "\"."; - } - if (real->chance < 0.90 || story->chance < 0.85 || real->chance == story->chance || story->inputs == real->inputs){ - return std::format( - "Expected m51's lead ({:.1f}%) and the story's ({:.1f}%, {}) to differ, both over 85%.", - 100 * real->chance, 100 * story->chance, story->inputs - ); - } - return true; -} - -// The Cerulean rival against m51's moves (no Water Gun), the levels -// since the summary added to its stats: refused at Lv20, 22 and 25 (about -// 32%, 37%, 66%), fought at Lv30 (about 95%). The refusal names the -// chance and the lead it was played with. -UnitTestResult test_rival_real_moves(){ - const std::vector> cases = { - {20, 0.20, 0.45}, {22, 0.25, 0.50}, {25, 0.50, 0.70}, {30, 0.90, 1.00}, - }; - for (const auto& [level, low, high] : cases){ - const std::optional estimate = story_win_chance(m51_lead(level), 5, 1.0, RIVAL); - if (!estimate || estimate->chance < low || estimate->chance >= high){ - return std::format("Lv{}: expected {:.0f}% to {:.0f}%, got {:.1f}%.", level, 100 * low, 100 * high, estimate ? 100 * estimate->chance : 0.0); - } - const bool refused = win_chance_refusal(*estimate).has_value(); - if (refused != (level < 30)){ - return std::format("Lv{} at {:.1f}%: expected {}.", level, 100 * estimate->chance, level < 30 ? "a refusal" : "no refusal"); - } - } - const std::optional lv22 = story_win_chance(m51_lead(22), 5, 1.0, RIVAL); - const std::string refusal = win_chance_refusal(*lv22).value_or(""); - if (refusal.find("wartortle Lv22 65/65 HP: bite") == std::string::npos || refusal.find("; 5 Potions") == std::string::npos){ - return "Lv22: expected the refusal to name the lead's level, HP, moves and Potions, got \"" + refusal + "\"."; - } - return true; -} -const AutoStoryBattleSimTestCase AUTO_STORY_BATTLE_SIM_CASES[] = { - { - .input = {.name = "Gen 3 stats and damage worked by hand", .body = test_hand_numbers}, - .expectation = {.description = "verifies Gen 3 stat calculation and damage formula numbers"}, - }, - { - .input = {.name = "the Elite Four Farmer's Starmie picks OHKO at Sp. Atk 302", .body = test_elite_four_table}, - .expectation = {.description = "verifies OHKO move selection against Elite Four Starmie"}, - }, - { - .input = {.name = "Misty: Thundershock on Staryu, Bite on Starmie", .body = test_misty_per_foe}, - .expectation = {.description = "validates targeted attack decisions in Misty gym battle"}, - }, - { - .input = {.name = "the trainer AI's healing items", .body = test_ai_heal_rule}, - .expectation = {.description = "simulates opponent trainer AI heal threshold logic"}, - }, - { - .input = {.name = "the rival's next Pokemon when no name is read", .body = test_next_foe}, - .expectation = {.description = "predicts next pokemon in rival roster when unread"}, - }, - { - .input = {.name = "battle risks by trainer", .body = test_risks}, - .expectation = {.description = "evaluates risk classification across various trainers"}, - }, - { - .input = {.name = "Cerulean rival: refused at Lv22, fought at Lv30", .body = test_rival_win_chance}, - .expectation = {.description = "simulates battle level threshold for Cerulean rival"}, - }, - { - .input = {.name = "m51: no Potion the foe's hit undoes", .body = test_m51_potion_loop}, - .expectation = {.description = "avoids endless potion loop when damage outpaces heal"}, - }, - { - .input = {.name = "the sim's Potion: only when it outheals the hit", .body = test_sim_potion_rule}, - .expectation = {.description = "verifies potion usage condition based on damage expectations"}, - }, - { - .input = {.name = "Misty: m51's lead as the summary showed it", .body = test_misty_real_lead}, - .expectation = {.description = "simulates Misty battle using lead Pokemon status"}, - }, - { - .input = {.name = "Cerulean rival with m51's moves at Lv20 to 30", .body = test_rival_real_moves}, - .expectation = {.description = "simulates Cerulean rival across level ranges"}, - }, -}; - -} // namespace - - -void add_tests_AutoStoryBattleSim(UnitTestDatabase& database){ - for (const auto& scenario : AUTO_STORY_BATTLE_SIM_CASES){ - database.add(scenario); - } -} - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp deleted file mode 100644 index f4a4151d4e..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* AutoStory Damage - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include "PokemonFRLG_AutoStoryDamage.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -namespace{ - -constexpr uint32_t MAX_IV = 31; -constexpr uint32_t MIN_ROLL = 85; -constexpr uint32_t MAX_ROLL = 100; -constexpr uint32_t ROLLS = MAX_ROLL - MIN_ROLL + 1; -constexpr int MAX_STAGE = 6; - -// CALC_STAT with ModifyStatByNature. `index` is the nature table's: -// Attack 0, Defense 1, Speed 2, Sp. Atk 3, Sp. Def 4. -uint16_t other_stat(uint8_t base, const Genes& genes, uint8_t level, size_t index){ - uint32_t stat = (2 * base + genes.iv + genes.ev / 4) * level / 100 + 5; - const size_t raised = genes.nature / 5; - const size_t lowered = genes.nature % 5; - if (raised != lowered && index == raised){ - stat = stat * 110 / 100; - }else if (raised != lowered && index == lowered){ - stat = stat * 90 / 100; - } - return static_cast(stat); -} - -uint32_t boosted(uint32_t stat, bool badge){ - return badge ? 110 * stat / 100 : stat; -} - -// APPLY_STAT_MOD, and a crit's: the attacker's drops and the defender's -// rises are left out. -uint32_t attack_side(uint32_t stat, int stage, bool crit){ - return crit && stage <= 0 ? stat : staged_stat(stat, stage); -} -uint32_t defense_side(uint32_t stat, int stage, bool crit){ - return crit && stage >= 0 ? stat : staged_stat(stat, stage); -} - -int stage_of(const Combatant& combatant, Stage stage){ - return combatant.stages[static_cast(stage)]; -} - -// CalculateBaseDamage, for a physical or special move. -uint32_t base_damage(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit){ - const bool special = special_type(move.type); - const uint32_t attack = special - ? attack_side(boosted(attacker.stats.sp_attack, attacker.volcano_badge), stage_of(attacker, Stage::SP_ATTACK), crit) - : attack_side(boosted(attacker.stats.attack, attacker.boulder_badge), stage_of(attacker, Stage::ATTACK), crit); - const uint32_t defense = special - ? defense_side(boosted(defender.stats.sp_defense, defender.volcano_badge), stage_of(defender, Stage::SP_DEFENSE), crit) - : defense_side(boosted(defender.stats.defense, defender.soul_badge), stage_of(defender, Stage::DEFENSE), crit); - uint32_t damage = attack * move.power; - damage *= 2 * attacker.level / 5 + 2; - damage /= std::max(defense, 1); - damage /= 50; - // Only the physical branch has this. - if (!special && damage == 0){ - damage = 1; - } - return damage + 2; -} - -} // namespace - - -uint8_t trainer_iv(uint8_t pret_iv){ - return static_cast(pret_iv * MAX_IV / 255); -} - -Stats gen3_stats(const BaseStats& base, uint8_t level, const Genes& genes){ - return Stats{ - .hp = static_cast((2 * base.hp + genes.iv + genes.ev / 4) * level / 100 + level + 10), - .attack = other_stat(base.attack, genes, level, 0), - .defense = other_stat(base.defense, genes, level, 1), - .sp_attack = other_stat(base.sp_attack, genes, level, 3), - .sp_defense = other_stat(base.sp_defense, genes, level, 4), - .speed = other_stat(base.speed, genes, level, 2), - }; -} - -uint32_t staged_stat(uint32_t stat, int stage){ - stage = std::clamp(stage, -MAX_STAGE, MAX_STAGE); - // gStatStageRatios: (10 + 5n) / 10 up, 10 / (10 + 5n) down. - return stage >= 0 ? stat * (10 + 5 * stage) / 10 : stat * 10 / (10 - 5 * stage); -} - -std::optional combatant(std::string_view species, uint8_t level, const Genes& genes){ - const SpeciesData* data = species_data(species); - if (data == nullptr){ - return std::nullopt; - } - return Combatant{.first = data->first, .second = data->second, .level = level, .stats = gen3_stats(data->base, level, genes)}; -} - -std::optional fixed_damage(const MoveData& move, const Combatant& attacker){ - if (move.effect == "dragon-rage"){ - return 40; - } - if (move.effect == "sonicboom"){ - return 20; - } - if (move.effect == "level-damage"){ - return attacker.level; - } - return std::nullopt; -} - -uint32_t damage_before_roll(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit){ - if (move.power == 0 || move.type == PokemonType::NONE){ - return 0; - } - const std::vector multipliers = type_multipliers(move.type, defender.first, defender.second); - const bool immune = std::ranges::find(multipliers, 0) != multipliers.end(); - if (const std::optional fixed = fixed_damage(move, attacker)){ - return immune ? 0 : *fixed; - } - uint32_t damage = base_damage(attacker, defender, move, crit); - if (crit){ - damage *= 2; - } - if (attacker.first == move.type || attacker.second == move.type){ - damage = damage * 15 / 10; - } - for (size_t tenths : multipliers){ - damage = static_cast(damage * tenths / 10); - if (damage == 0 && tenths != 0){ - damage = 1; - } - } - return damage; -} - -uint32_t rolled_damage(uint32_t before, uint32_t percent){ - if (before == 0){ - return 0; - } - return std::max(before * percent / 100, 1); -} - -DamageRange damage_range(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit){ - const uint32_t before = damage_before_roll(attacker, defender, move, crit); - if (fixed_damage(move, attacker)){ - return DamageRange{.min = before, .max = before}; - } - return DamageRange{.min = rolled_damage(before, MIN_ROLL), .max = rolled_damage(before, MAX_ROLL)}; -} - -double average_damage(const Combatant& attacker, const Combatant& defender, const MoveData& move){ - const uint32_t before = damage_before_roll(attacker, defender, move, false); - if (fixed_damage(move, attacker)){ - return before; - } - uint32_t total = 0; - for (uint32_t percent = MIN_ROLL; percent <= MAX_ROLL; percent++){ - total += rolled_damage(before, percent); - } - return static_cast(total) / ROLLS; -} - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h deleted file mode 100644 index 31fb7c7499..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h +++ /dev/null @@ -1,127 +0,0 @@ -/* AutoStory Damage - * - * From: https://github.com/PokemonAutomation/ - * - * Gen 3 stats and damage as FireRed computes them, for the story's move - * choices and battle sim (PokemonFRLG_AutoStoryBattleSim.h). From - * pret/pokefirered: - * - stats: CalculateMonStats (src/pokemon.c), the nature's 10% as - * ModifyStatByNature; - * - damage: CalculateBaseDamage (src/pokemon.c), whose result already - * holds the +2, then in battle_script_commands.c Cmd_damagecalc's crit - * x2, Cmd_typecalc's STAB x1.5 and type multipliers one by one in the - * type chart's order (ModulateDmgByType: at least 1 unless 0x), then - * ApplyRandomDmgMultiplier's roll of 85 to 100 percent (at least 1). - * Physical or special goes by the move's type. Stat stages (and a - * crit's ignoring of the unhelpful ones) and the player's badge boosts - * are in; burn, Reflect, Light Screen, weather, abilities and held items - * are not. - * - */ - -#ifndef PokemonAutomation_PokemonFRLG_AutoStoryDamage_H -#define PokemonAutomation_PokemonFRLG_AutoStoryDamage_H - -#include -#include -#include -#include -#include "PokemonFRLG_AutoStoryBattleData.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -// A Pokemon's stats, in the game's order. -struct Stats{ - uint16_t hp = 0; - uint16_t attack = 0; - uint16_t defense = 0; - uint16_t sp_attack = 0; - uint16_t sp_defense = 0; - uint16_t speed = 0; -}; - -// The same IV and EV in every stat, and the nature's index (0 Hardy to -// 24 Quirky; a nature raises stat n / 5 and lowers n % 5, of Attack, -// Defense, Speed, Sp. Atk, Sp. Def). -struct Genes{ - uint8_t iv = 0; - uint8_t ev = 0; - uint8_t nature = 0; -}; - -// A trainer's Pokemon's IVs from pret's iv (0 to 255). -uint8_t trainer_iv(uint8_t pret_iv); - -// Calculates Gen 3 stats from base stats, level, and genes. -Stats gen3_stats(const BaseStats& base, uint8_t level, const Genes& genes); - -// The stat stages the damage formula and the sim use, from -6 to +6. -enum class Stage : size_t{ - ATTACK, - DEFENSE, - SPEED, - SP_ATTACK, - SP_DEFENSE, - ACCURACY, - EVASION, -}; -// Number of modifier stat stages. -inline constexpr size_t STAGES = 7; -// Array of stat stage modifiers. -using StatStages = std::array; - -// `stat` at `stage` (gStatStageRatios). -uint32_t staged_stat(uint32_t stat, int stage); - -// A Pokemon in battle as the damage formula sees it. -struct Combatant{ - PokemonType first = PokemonType::NONE; - PokemonType second = PokemonType::NONE; - uint8_t level = 0; - Stats stats = {}; - StatStages stages = {}; - // The player's badges that boost this Pokemon's stats by 10% - // (ShouldGetStatBadgeBoost): the Boulder Badge its Attack, the Soul - // Badge its Defense, the Volcano Badge its Sp. Atk and Sp. Def. Only - // for the player's Pokemon. - bool boulder_badge = false; - bool soul_badge = false; - bool volcano_badge = false; -}; - -// `species` at `level` with `genes`: its types and stats. -std::optional combatant(std::string_view species, uint8_t level, const Genes& genes); - -// The damage of a move whose damage doesn't come from the formula: -// Dragon Rage 40, Sonic Boom 20, Seismic Toss and Night Shade the -// attacker's level. None for the rest. -std::optional fixed_damage(const MoveData& move, const Combatant& attacker); - -// The damage before the random roll: CalculateBaseDamage (with its +2), -// the crit, STAB and the type chart. 0 for a move with no power, or one -// the defender is immune to. Fixed damage as fixed_damage() says. -uint32_t damage_before_roll(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit); - -// `before` at the random roll `percent` (85 to 100). -uint32_t rolled_damage(uint32_t before, uint32_t percent); - -// Minimum and maximum simulated damage roll. -struct DamageRange{ - uint32_t min = 0; - uint32_t max = 0; -}; -// The damage at the lowest roll (85) and the highest (100). -DamageRange damage_range(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit); - -// The mean over the 16 rolls, without crits. -double average_damage(const Combatant& attacker, const Combatant& defender, const MoveData& move); - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 7756577c90..5b52f0f952 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -20,7 +20,6 @@ #include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStorySummary.h" #include "PokemonFRLG_AutoStoryTable.h" -#include "PokemonFRLG_AutoStoryWinChance.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -169,33 +168,11 @@ Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ return Pokemon::outcome_ok(to_pose(StoryPose{state.pose.map, tiles[0].next(direction), direction})); } -// Before a BattleRisk::HIGH battle the story may lose: the sim's win -// chance, the HP as the last bar read left it. Why not to fight, if so. -std::optional refuse_battle(StoryEnv& env, const StoryStep& step, std::string_view trainer){ - const Supplies& supplies = env.supplies; - if (arg(step, "may_lose") || supplies.risk != BattleRisk::HIGH){ - return std::nullopt; - } - const std::optional estimate = story_win_chance(supplies.lead, supplies.potions, supplies.hp_fill, trainer); - if (!estimate){ - return std::nullopt; - } - env.console.log(std::format( - "Story: {} against {}: the sim wins {} of {} ({:.0f}%) with {}.", - step.name, trainer, estimate->wins, estimate->battles, 100 * estimate->chance, estimate->inputs - )); - return win_chance_refusal(*estimate); -} - Outcome battle(StoryEnv& env, const StoryStep& step){ const std::optional trainer = step.pose_after ? story_trainer(step.pose_after->map, step.name) : std::nullopt; env.supplies.trainer = trainer ? std::string(*trainer) : ""; env.supplies.risk = trainer ? story_battle_risk(step.pose_after->map, step.name) : BattleRisk::LOW; - env.supplies.foe_out.reset(); - if (const std::optional refusal = trainer ? refuse_battle(env, step, *trainer) : std::nullopt){ - env.console.log("Story: " + step.name + ": " + *refusal + ".", COLOR_RED); - return Pokemon::outcome_failed("win_chance", *refusal); - } + env.supplies.foe_out.clear(); if (advance_text(env.console, env.context, BATTLE_TEXT_TIMEOUT, true) != TextEnd::BATTLE){ return Pokemon::outcome_failed("no_battle"); } @@ -209,7 +186,7 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ const BattleEnd end = fight_battle(env.console, env.context, env.supplies, BattleKind::TRAINER, env.checks, env.language); env.supplies.foes.clear(); env.supplies.trainer.clear(); - env.supplies.foe_out.reset(); + env.supplies.foe_out.clear(); if (end == BattleEnd::LOST && !arg(step, "may_lose")){ return Pokemon::outcome_failed("blackout"); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp index 3d7dd7f18a..42665efa45 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp @@ -78,8 +78,8 @@ JsonObject supplies_json(const Supplies& supplies){ result["protected_slots"] = std::move(protected_slots); result["foes"] = strings(supplies.foes); result["trainer"] = supplies.trainer; - result["risk"] = battle_risk_name(supplies.risk); - result["foe_out"] = supplies.foe_out ? JsonValue(count(*supplies.foe_out)) : JsonValue(); + result["risk"] = std::string(battle_risk_name(supplies.risk)); + result["foe_out"] = supplies.foe_out.empty() ? JsonValue() : JsonValue(supplies.foe_out); result["wild_foes"] = strings(supplies.wild_foes); return result; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp index 7f3757d020..707adc0596 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp @@ -28,7 +28,7 @@ const ExportCase CASES[] = { {.input = {.id = "00.05"}, .expectation = {.events = {"below_mart_door", "mart_door", "parcel_from_clerk"}, .menu = "before_pokedex"}}, {.input = {.id = "00.05", .custom = true}, .expectation = { .events = {"below_mart_door", "mart_door", "parcel_from_clerk"}, .menu = "full", - .native_json = R"({"menu":"full","supplies":{"potions":2,"antidotes":3,"parlyz_heals":4,"pocket":["antidote",""],"status":"PSN","hurt":true,"hp_red":true,"hp_fill":0.25,"lead":{"species":"wartortle","moves":[{"move":"bite","pp":0}],"moves_through_level":18,"moves_read":true,"level":19,"stats":{"hp":50,"attack":20,"defense":30,"sp_attack":40,"sp_defense":35,"speed":25}},"protected_slots":[0,2],"foes":["staryu"],"trainer":"misty","risk":"high","foe_out":0,"wild_foes":["pidgey"]}})" + .native_json = R"({"menu":"full","supplies":{"potions":2,"antidotes":3,"parlyz_heals":4,"pocket":["antidote",""],"status":"PSN","hurt":true,"hp_red":true,"hp_fill":0.25,"lead":{"species":"wartortle","moves":[{"move":"bite","pp":0}],"moves_through_level":18,"moves_read":true,"level":19,"stats":{"hp":50,"attack":20,"defense":30,"sp_attack":40,"sp_defense":35,"speed":25}},"protected_slots":[0,2],"foes":["staryu"],"trainer":"misty","risk":"high","foe_out":"staryu","wild_foes":["pidgey"]}})" }}, }; void customize(StoryCheckpoint& row){ @@ -49,7 +49,7 @@ void customize(StoryCheckpoint& row){ state.foes = {"staryu"}; state.trainer = "misty"; state.risk = BattleRisk::HIGH; - state.foe_out = 0; + state.foe_out = "staryu"; state.wild_foes = {"pidgey"}; } std::string check_export(StoryCheckpoint row, const ExportCase& test){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp deleted file mode 100644 index 97117c6339..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* AutoStory Foe Tracker - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonFRLG_AutoStoryFoeTracker.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -namespace{ - -// Looks in a row with the foe's box gone and the lead's there: a faint, -// not a frame between two animations (as for the lead's, FAINT_POLLS in -// PokemonFRLG_AutoStoryBattle.cpp). -constexpr int FOE_GONE_POLLS = 3; - -} // namespace - - -TrainerFoeTracker::TrainerFoeTracker(std::string_view trainer, const PartyMember& lead) - : m_lead(own_battler(lead)) -{ - const std::optional sim = trainer.empty() ? std::nullopt : sim_trainer(trainer); - if (!sim){ - return; - } - m_party = sim->party; - for (const SimBattler& battler : m_party){ - m_species.push_back(battler.species); - } -} - -void TrainerFoeTracker::boxes_seen(BattleBoxes boxes){ - if (m_party.empty() || boxes.foe || !boxes.lead){ - m_gone_polls = boxes.foe ? 0 : m_gone_polls; - return; - } - if (++m_gone_polls == FOE_GONE_POLLS && !m_next_due){ - m_fainted.insert(m_out); - m_party[m_out].hp = 0; - m_next_due = true; - } -} - -void TrainerFoeTracker::at_menu(std::string_view read){ - if (m_party.empty()){ - return; - } - if (m_next_due && m_lead){ - m_out = ai_next_foe(m_party, m_out, *m_lead); - } - m_next_due = false; - if (read.empty() || m_species[m_out] == read){ - return; - } - // The name says otherwise: the first of that species not fainted. - for (size_t slot = 0; slot < m_party.size(); slot++){ - if (m_species[slot] == read && !m_fainted.contains(slot)){ - m_out = slot; - return; - } - } -} - -std::optional TrainerFoeTracker::out() const{ - return m_party.empty() ? std::nullopt : std::optional(m_out); -} - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h deleted file mode 100644 index 54d1f5a449..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h +++ /dev/null @@ -1,73 +0,0 @@ -/* AutoStory Foe Tracker - * - * From: https://github.com/PokemonAutomation/ - * - * Which of a trainer's Pokemon is out, in a story battle whose trainer - * the story knows, so the lead's move is chosen against that one. The - * name in the foe's HP box is read at each battle menu - * (read_trainer_foe()). When it isn't read, the tracker goes by the game: - * the party's first Pokemon opens, a foe faints when its box is gone - * while the lead's stays, and the next one is the AI's choice - * (ai_next_foe()) against the lead. - * - */ - -#ifndef PokemonAutomation_PokemonFRLG_AutoStoryFoeTracker_H -#define PokemonAutomation_PokemonFRLG_AutoStoryFoeTracker_H - -#include -#include -#include -#include -#include -#include -#include "PokemonFRLG_AutoStoryBattleSim.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -// Which HP boxes a battle screen shows. -struct BattleBoxes{ - bool lead = false; - bool foe = false; -}; - -// Tracks opposing trainer identity and species roster during battle. -class TrainerFoeTracker{ -public: - // `trainer`: pret's constant, or "" when the battle's trainer isn't - // known (then nothing is tracked). `lead`: the story's lead, for the - // AI's next Pokemon. - TrainerFoeTracker(std::string_view trainer, const PartyMember& lead); - - // The species in the party, for reading the name. - const std::vector& species() const{ return m_species; } - - // At each look at a battle screen. - void boxes_seen(BattleBoxes boxes); - - // At a battle menu, with the foe's species as read ("" if not read). - void at_menu(std::string_view read); - - // The party slot out; none when the trainer isn't known. - std::optional out() const; - -private: - std::vector m_party; - std::vector m_species; - std::optional m_lead; - std::set m_fainted; - size_t m_out = 0; - int m_gone_polls = 0; - // A foe fainted, and no menu since: the next one isn't known yet. - bool m_next_due = false; -}; - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp index c167b7678d..76c639f2a7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp @@ -209,9 +209,10 @@ size_t effectiveness(const MoveData& move, const SpeciesData& defender){ } // `move`'s expected damage, summed over `foes`: its power times STAB -// times its effectiveness times the lead's base attacking stat for it. -// The foe's Defense and Sp. Def, levels, IVs, EVs, natures and accuracy -// are left out. Each foe must be in species_data(). +// times its effectiveness times the lead's base attacking stat for it, +// times its accuracy (a move that never misses as 100%). The foe's +// Defense and Sp. Def, levels, IVs, EVs and natures are left out. Each +// foe must be in species_data(). size_t expected_damage(const PartyMember& member, std::string_view move, const std::vector& foes){ const MoveData* data = move_data(move); const SpeciesData* own = species_data(member.species); @@ -219,9 +220,10 @@ size_t expected_damage(const PartyMember& member, std::string_view move, const s return 0; } const bool stab = own->first == data->type || own->second == data->type; + const size_t accuracy = data->accuracy == 0 ? 100 : data->accuracy; size_t damage = 0; for (const std::string& foe : foes){ - damage += (size_t)data->power * (stab ? 15 : 10) * effectiveness(*data, *species_data(foe)) * attacking_stat(*own, *data); + damage += (size_t)data->power * (stab ? 15 : 10) * effectiveness(*data, *species_data(foe)) * attacking_stat(*own, *data) * accuracy; } return damage; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h index 43fca42a90..9111f48d52 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h @@ -32,7 +32,7 @@ #include #include #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" -#include "PokemonFRLG_AutoStoryDamage.h" +#include "PokemonFRLG_AutoStoryStats.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -73,7 +73,8 @@ struct PartyMember{ std::optional stats = {}; }; -// The level the battle sim takes for `member`. +// The level the story takes for `member`: its level, or the level its +// moves were grown through if that is higher. uint8_t battle_level(const PartyMember& member); // The species `species` evolves into by level, and at which level. @@ -145,8 +146,8 @@ std::vector trainer_party(std::string_view trainer); // The slot to attack `foes` with, any of them as likely to be out: the // move with PP left that does the most expected damage, ties going to // attack_slot()'s order. Expected damage, summed over the foes, is power -// times STAB times the type chart, times the lead's base Attack or Sp. -// Atk, whichever the move's type uses (Gen 3: Fire, Water, Grass, +// times STAB times the type chart times accuracy, times the lead's base +// Attack or Sp. Atk, whichever the move's type uses (Gen 3: Fire, Water, Grass, // Electric, Psychic, Ice, Dragon and Dark are special): Water Gun and Bite // compare on Sp. Atk, Tackle on Attack. The foe's defenses are left out, // so a frail foe's low Defense doesn't pull Tackle ahead of a type diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStats.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStats.h new file mode 100644 index 0000000000..e279c0b474 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStats.h @@ -0,0 +1,34 @@ +/* AutoStory Stats + * + * From: https://github.com/PokemonAutomation/ + * + * A Pokemon's stats as POKEMON SKILLS shows them. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryStats_H +#define PokemonAutomation_PokemonFRLG_AutoStoryStats_H + +#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// A Pokemon's stats, in the game's order. +struct Stats{ + uint16_t hp = 0; + uint16_t attack = 0; + uint16_t defense = 0; + uint16_t sp_attack = 0; + uint16_t sp_defense = 0; + uint16_t speed = 0; +}; + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h index 16f332577d..0fd32999f7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h @@ -20,7 +20,7 @@ #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" #include "PokemonFRLG_AutoStoryActions.h" -#include "PokemonFRLG_AutoStoryDamage.h" +#include "PokemonFRLG_AutoStoryStats.h" namespace PokemonAutomation{ namespace NintendoSwitch{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp deleted file mode 100644 index 4a696f339b..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp +++ /dev/null @@ -1,397 +0,0 @@ -/* AutoStory Win Chance - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include -#include -#include "PokemonFRLG_AutoStoryWinChance.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -namespace{ - -// A battle still going after this many turns counts as lost. -constexpr size_t MAX_TURNS = 100; -constexpr uint32_t CRIT_CHANCE = 16; -constexpr uint32_t HIGH_CRIT_CHANCE = 8; -constexpr int MAX_STAGE = 6; - -// sAccuracyStageRatios, -6 to +6, in hundredths. -constexpr uint32_t ACCURACY_RATIOS[] = {33, 36, 43, 50, 60, 75, 100, 133, 166, 200, 233, 266, 300}; - -const MoveData& data_of(std::string_view move){ - static const MoveData NONE; - const MoveData* data = move_data(move); - return data == nullptr ? NONE : *data; -} - -int8_t& stage(SimBattler& battler, Stage which){ - return battler.body.stages[static_cast(which)]; -} - -uint16_t eighth(const SimBattler& battler){ - return std::max(battler.body.stats.hp / 8, 1); -} - -void lose_hp(SimBattler& battler, uint32_t damage){ - battler.hp = static_cast(battler.hp > damage ? battler.hp - damage : 0); -} - -void gain_hp(SimBattler& battler, uint32_t heal){ - battler.hp = static_cast(std::min(battler.body.stats.hp, battler.hp + heal)); -} - -// "attack-down", "speed-up-2", "defense-down-hit": the stage, by how much -// and on whom. None for another effect. -struct StageChange{ - Stage stat = Stage::ATTACK; - int amount = 0; - bool on_user = false; -}; -std::optional stage_change(std::string_view effect){ - static const std::pair STATS[] = { - {"attack-", Stage::ATTACK}, {"defense-", Stage::DEFENSE}, {"speed-", Stage::SPEED}, - {"special-attack-", Stage::SP_ATTACK}, {"special-defense-", Stage::SP_DEFENSE}, - {"accuracy-", Stage::ACCURACY}, {"evasion-", Stage::EVASION}, - }; - for (const auto& [prefix, stat] : STATS){ - if (!effect.starts_with(prefix)){ - continue; - } - std::string_view rest = effect.substr(prefix.size()); - if (rest.ends_with("-hit")){ - rest.remove_suffix(4); - } - const bool up = rest.starts_with("up"); - if (!up && !rest.starts_with("down")){ - return std::nullopt; - } - const int amount = rest.ends_with("-2") ? 2 : 1; - return StageChange{.stat = stat, .amount = up ? amount : -amount, .on_user = up}; - } - return std::nullopt; -} - -void change_stage(SimBattler& user, SimBattler& target, std::string_view effect){ - if (const std::optional change = stage_change(effect)){ - int8_t& now = stage(change->on_user ? user : target, change->stat); - now = static_cast(std::clamp(now + change->amount, -MAX_STAGE, MAX_STAGE)); - } -} - - -// One battle, played once. -class SimBattle{ -public: - SimBattle(const SimBattler& own, int potions, const SimTrainer& trainer, std::mt19937& rng) - : m_own(own) - , m_potions(potions) - , m_trainer(trainer) - , m_rng(rng) - {} - - bool won(){ - for (size_t turn = 0; turn < MAX_TURNS; turn++){ - play_turn(); - if (m_own.hp == 0){ - return false; - } - if (foe().hp == 0 && !send_next()){ - return true; - } - } - return false; - } - -private: - SimBattler& foe(){ - return m_trainer.party[m_out]; - } - - size_t foes_left() const{ - return static_cast(std::ranges::count_if(m_trainer.party, [](const SimBattler& battler){ - return battler.hp > 0; - })); - } - - bool send_next(){ - if (foes_left() == 0){ - return false; - } - m_out = ai_next_foe(m_trainer.party, m_out, m_own); - return true; - } - - uint32_t random(uint32_t n){ - return static_cast(m_rng() % n); - } - - // The AI's move: the best score, ties at random. None with no PP left. - std::optional foe_move(){ - const std::vector scores = ai_move_scores(m_trainer, foe(), m_own, m_rng); - const int best = scores.empty() ? 0 : *std::ranges::max_element(scores); - std::vector ties; - for (size_t slot = 0; slot < scores.size(); slot++){ - if (best > 0 && scores[slot] == best){ - ties.push_back(slot); - } - } - if (ties.empty()){ - return std::nullopt; - } - return ties[random(static_cast(ties.size()))]; - } - - void play_turn(){ - const size_t left = foes_left(); - const OwnTurn own = own_turn(m_own, m_potions, foe(), m_trainer.items, left); - const std::optional item = ai_item_choice(foe(), m_trainer.items, left); - const std::optional foe_slot = item ? std::nullopt : foe_move(); - if (own.potion){ - gain_hp(m_own, POTION_HP); - m_potions--; - } - if (item){ - gain_hp(foe(), ai_item_hp(m_trainer.items[*item])); - m_trainer.items[*item].clear(); - } - const std::string own_move = own.potion ? "" : own.slot ? m_own.moves[*own.slot].move : "struggle"; - const std::string foe_used = item ? "" : foe_slot ? foe().moves[*foe_slot].move : "struggle"; - play_moves(own_move, own.slot, foe_used, foe_slot); - end_of_turn(); - } - - bool own_first(const std::string& own_move, const std::string& foe_used){ - const int own_priority = data_of(own_move).priority; - const int foe_priority = data_of(foe_used).priority; - if (own_priority != foe_priority){ - return own_priority > foe_priority; - } - const uint32_t own_speed = speed(m_own); - const uint32_t foe_speed = speed(foe()); - return own_speed != foe_speed ? own_speed > foe_speed : random(2) == 0; - } - - void play_moves(const std::string& own_move, std::optional own_slot, const std::string& foe_used, std::optional foe_slot){ - m_flinched = false; - const bool first = own_move.empty() || foe_used.empty() || own_first(own_move, foe_used); - if (first){ - use(m_own, foe(), own_move, own_slot, true); - use(foe(), m_own, foe_used, foe_slot, false); - }else{ - use(foe(), m_own, foe_used, foe_slot, true); - use(m_own, foe(), own_move, own_slot, false); - } - } - - static uint32_t speed(const SimBattler& battler){ - const uint32_t speed = staged_stat(battler.body.stats.speed, battler.body.stages[static_cast(Stage::SPEED)]); - return battler.status == SimStatus::PARALYSIS ? speed / 4 : speed; - } - - // Whether `user` gets to move: sleep, flinch, paralysis. - bool can_move(SimBattler& user, bool moves_first){ - if (user.status == SimStatus::SLEEP){ - if (--user.sleep > 0){ - return false; - } - user.status = SimStatus::NONE; - } - if (!moves_first && m_flinched){ - return false; - } - return user.status != SimStatus::PARALYSIS || random(4) != 0; - } - - bool hits(const SimBattler& user, const SimBattler& target, const MoveData& move){ - if (move.accuracy == 0){ - return true; - } - const int buff = std::clamp( - user.body.stages[static_cast(Stage::ACCURACY)] - target.body.stages[static_cast(Stage::EVASION)], - -MAX_STAGE, MAX_STAGE - ); - const uint32_t chance = move.accuracy * ACCURACY_RATIOS[buff + MAX_STAGE] / 100; - return random(100) + 1 <= chance; - } - - void use(SimBattler& user, SimBattler& target, const std::string& move_name, std::optional slot, bool moves_first){ - if (move_name.empty() || user.hp == 0 || target.hp == 0 || !can_move(user, moves_first)){ - return; - } - if (slot && user.moves[*slot].pp > 0){ - user.moves[*slot].pp--; - } - const MoveData& move = data_of(move_name); - if (!hits(user, target, move)){ - return; - } - if (move.power > 0){ - strike(user, target, move, moves_first); - }else{ - apply_status_move(user, target, move); - } - } - - uint32_t hit_count(const MoveData& move){ - if (move.effect == "double-hit" || move.effect == "twineedle"){ - return 2; - } - if (move.effect != "multi-hit"){ - return 1; - } - // Cmd_setmultihitcounter: 2 or 3 at 3/8 each, 4 or 5 at 1/8 each. - const uint32_t first = random(4); - return first > 1 ? random(4) + 2 : first + 2; - } - - uint32_t one_hit(const SimBattler& user, const SimBattler& target, const MoveData& move){ - if (move.effect == "super-fang"){ - return std::max(target.hp / 2, 1); - } - const bool crit = random(move.effect == "high-critical" ? HIGH_CRIT_CHANCE : CRIT_CHANCE) == 0; - const uint32_t before = damage_before_roll(user.body, target.body, move, crit); - return fixed_damage(move, user.body) ? before : rolled_damage(before, 100 - random(16)); - } - - void strike(SimBattler& user, SimBattler& target, const MoveData& move, bool moves_first){ - const uint32_t count = hit_count(move); - uint32_t dealt = 0; - for (uint32_t i = 0; i < count && target.hp > 0; i++){ - const uint32_t damage = std::min(one_hit(user, target, move), target.hp); - lose_hp(target, damage); - dealt += damage; - } - if (move.effect == "absorb"){ - gain_hp(user, std::max(dealt / 2, 1)); - } - if (dealt > 0 && target.hp > 0 && random(100) < move.effect_chance){ - secondary(user, target, move, moves_first); - } - } - - void secondary(SimBattler& user, SimBattler& target, const MoveData& move, bool moves_first){ - if (move.effect == "flinch-hit" || move.effect == "flinch-minimize-hit"){ - m_flinched = moves_first; - }else if (move.effect == "poison-hit"){ - set_status(target, SimStatus::POISON); - }else if (move.effect == "paralyze-hit"){ - set_status(target, SimStatus::PARALYSIS); - }else{ - change_stage(user, target, move.effect); - } - } - - void set_status(SimBattler& target, SimStatus status){ - if (target.status != SimStatus::NONE){ - return; - } - const bool poison_proof = target.body.first == PokemonType::POISON || target.body.second == PokemonType::POISON - || target.body.first == PokemonType::STEEL || target.body.second == PokemonType::STEEL; - if (status == SimStatus::POISON && poison_proof){ - return; - } - target.status = status; - if (status == SimStatus::SLEEP){ - target.sleep = static_cast(2 + random(4)); - } - } - - void apply_status_move(SimBattler& user, SimBattler& target, const MoveData& move){ - if (move.effect == "sleep"){ - set_status(target, SimStatus::SLEEP); - }else if (move.effect == "poison" || move.effect == "toxic"){ - set_status(target, SimStatus::POISON); - }else if (move.effect == "paralyze"){ - set_status(target, SimStatus::PARALYSIS); - }else if (move.effect == "leech-seed"){ - const bool grass = target.body.first == PokemonType::GRASS || target.body.second == PokemonType::GRASS; - target.seeded = target.seeded || !grass; - }else if (move.effect == "restore-hp" || move.effect == "softboiled"){ - gain_hp(user, user.body.stats.hp / 2); - }else{ - change_stage(user, target, move.effect); - } - } - - void end_of_turn(){ - for (SimBattler* battler : {&m_own, &foe()}){ - if (battler->hp > 0 && battler->status == SimStatus::POISON){ - lose_hp(*battler, eighth(*battler)); - } - } - seed(m_own, foe()); - seed(foe(), m_own); - } - - static void seed(SimBattler& seeded, SimBattler& other){ - if (!seeded.seeded || seeded.hp == 0 || other.hp == 0){ - return; - } - const uint16_t drained = std::min(eighth(seeded), seeded.hp); - lose_hp(seeded, drained); - gain_hp(other, drained); - } - - SimBattler m_own; - int m_potions; - SimTrainer m_trainer; - std::mt19937& m_rng; - size_t m_out = 0; - bool m_flinched = false; -}; - -} // namespace - - -WinEstimate estimate_win_chance(const SimBattler& own, int potions, const SimTrainer& trainer, size_t battles, uint32_t seed){ - std::mt19937 rng(seed); - WinEstimate estimate{.battles = battles, .wins = 0, .chance = 0}; - for (size_t i = 0; i < battles; i++){ - SimBattle battle(own, potions, trainer, rng); - estimate.wins += battle.won() ? 1 : 0; - } - estimate.chance = battles == 0 ? 0 : static_cast(estimate.wins) / battles; - return estimate; -} - -std::optional story_win_chance(const PartyMember& lead, int potions, double hp_share, std::string_view trainer){ - const std::optional own = own_battler(lead, hp_share); - const std::optional sim = sim_trainer(trainer); - if (!own || !sim){ - return std::nullopt; - } - WinEstimate estimate = estimate_win_chance(*own, potions, *sim); - estimate.inputs = std::format("{} Lv{} {}/{} HP:", own->species, own->body.level, own->hp, own->body.stats.hp); - for (size_t slot = 0; slot < own->moves.size(); slot++){ - estimate.inputs += std::format( - "{} {} {}/{}", slot == 0 ? "" : ",", own->moves[slot].move, own->moves[slot].pp, max_pp(own->moves[slot].move) - ); - } - estimate.inputs += std::format("; {} Potions", potions); - return estimate; -} - -std::optional win_chance_refusal(const WinEstimate& estimate, double minimum){ - if (estimate.chance >= minimum){ - return std::nullopt; - } - return std::format( - "win chance {:.0f}% < {:.0f}%{}: grind first", - std::floor(100 * estimate.chance), std::round(100 * minimum), - estimate.inputs.empty() ? "" : " with " + estimate.inputs - ); -} - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h deleted file mode 100644 index bc88daa6d5..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h +++ /dev/null @@ -1,67 +0,0 @@ -/* AutoStory Win Chance - * - * From: https://github.com/PokemonAutomation/ - * - * Before a BattleRisk::HIGH battle: how often the lead beats the trainer, - * by playing the battle many times over (Monte Carlo) with the choices - * of PokemonFRLG_AutoStoryBattleSim.h and the game's random parts: the - * damage roll, crits (1/16, 1/8 for a high-crit move), accuracy with - * accuracy and evasion stages, speed ties, secondary effects, and the - * AI's ties. Too low a chance stops the story before the fight, for a - * GRIND or the nurse first. - * - * Each turn: the Potion and the AI's item first, then the moves by - * priority and speed (a quarter with PARALYSIS). Sleep (2 to 5 on the - * game's counter), poison (1/8 HP a turn), paralysis (1/4 no move), Leech - * Seed (1/8 a turn to the other side), flinch, one- and two-stage stat - * changes, multi-hit moves (2 to 5 as the game draws them), drain (half) - * and Recover (half) are played; burn, freeze, confusion, recoil, - * recharge, two-turn moves, trapping, abilities and held items are not. - * The lead is never switched out: a fainted lead is a lost battle. - * - */ - -#ifndef PokemonAutomation_PokemonFRLG_AutoStoryWinChance_H -#define PokemonAutomation_PokemonFRLG_AutoStoryWinChance_H - -#include -#include -#include -#include -#include -#include "PokemonFRLG_AutoStoryBattleSim.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -// Outcome count and win probability estimate from Monte Carlo simulations. -struct WinEstimate{ - size_t battles = 0; - size_t wins = 0; - // wins / battles - double chance = 0; - // The lead and Potions the battles were played with, for the log: - // "wartortle Lv20 60/60 HP: bite 25/25, ...; 5 Potions". - std::string inputs = {}; -}; - -// `own` with `potions` Potions against `trainer`, `battles` times, from a -// fixed `seed` so the same inputs give the same estimate. -WinEstimate estimate_win_chance(const SimBattler& own, int potions, const SimTrainer& trainer, size_t battles = 1000, uint32_t seed = 1); - -// The story's lead (`hp_share` of its HP) with `potions` against -// `trainer`. None if the data lacks the lead's species or the trainer. -std::optional story_win_chance(const PartyMember& lead, int potions, double hp_share, std::string_view trainer); - -// Why not to fight: "win chance 41% < 70% with : grind first", or -// none at `minimum` or above. -std::optional win_chance_refusal(const WinEstimate& estimate, double minimum = MIN_WIN_CHANCE); - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 8e6aee8227..b26de8dfe1 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1927,15 +1927,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h @@ -1945,6 +1938,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStats.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp @@ -1957,8 +1951,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/BoxOrganization/PokemonFRLG_BoxOrganization.cpp From 269b567cc3d931171e5a07c3d11e85ae2e008c6f Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 14:14:52 -0800 Subject: [PATCH 26/29] FRLG AutoStory: record_story_counts() takes its output last nav/story-steps moved AutoStoryStats& after the counts. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index d788c98f9d..aac1a86c4f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -239,7 +239,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex const Pokemon::SegmentReport report = run_segment( state, segment, Pokemon::SegmentRange{checkpoints[first].id, checkpoints[last].id}, RUN.policy(), hooks ); - Pokemon::record_story_counts(env.current_stats(), report.story_counts()); + Pokemon::record_story_counts(report.story_counts(), env.current_stats()); env.update_stats(); if (!report.completed){ throw OperationFailedException( From c1a38618c969e7ef3fee46c1bc241219f34aac0b Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 14:16:53 -0800 Subject: [PATCH 27/29] FRLG AutoStory stage 1: std::string_view for char* (code health) Names, test descriptions and table strings use std::string_view; the authored JSON test fixtures and the option's help text are std::string. Lines this touches build their strings with std::format. No behaviour change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Overworld/PokemonFRLG_OverworldMaps.cpp | 6 +++--- .../Overworld/PokemonFRLG_OverworldMaps_Tests.cpp | 12 ++++++------ .../PokemonFRLG_OverworldReanchor_Tests.cpp | 6 +++--- .../PokemonFRLG_OverworldRecovery_Tests.cpp | 10 +++++----- .../Overworld/PokemonFRLG_OverworldRoute.cpp | 14 +++++++------- .../Overworld/PokemonFRLG_OverworldWalk.cpp | 8 ++++---- .../Overworld/PokemonFRLG_OverworldWalk.h | 2 +- .../Overworld/PokemonFRLG_OverworldWalk_Tests.cpp | 4 ++-- .../Overworld/PokemonFRLG_PlayerFacingReader.cpp | 5 +++-- .../Programs/AutoStory/PokemonFRLG_AutoStory.cpp | 2 +- .../AutoStory/PokemonFRLG_AutoStoryActions.cpp | 4 ++-- .../AutoStory/PokemonFRLG_AutoStoryActions.h | 2 +- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 4 ++-- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 2 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 10 +++++----- .../AutoStory/PokemonFRLG_AutoStoryExport.cpp | 6 +++--- .../AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp | 2 +- .../AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp | 2 +- .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 2 +- .../PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp | 7 ++++--- .../AutoStory/PokemonFRLG_AutoStoryStepTable.cpp | 2 +- .../AutoStory/PokemonFRLG_AutoStoryStepTable.h | 2 +- .../PokemonFRLG_AutoStoryStepTable_Tests.cpp | 4 ++-- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 12 ++++++------ 24 files changed, 66 insertions(+), 64 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp index 2223f68f10..a1a91e3b2d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp @@ -16,7 +16,7 @@ namespace PokemonFRLG{ namespace{ -const char* const MAP_NAMES[] = { +constexpr std::string_view MAP_NAMES[] = { // From a new game to Brock. "PalletTown", "PalletTown_PlayersHouse_1F", @@ -50,8 +50,8 @@ const char* const MAP_NAMES[] = { const std::vector& all_maps(){ static const std::vector MAPS = []{ std::vector maps; - for (const char* name : MAP_NAMES){ - maps.push_back(load_map(name)); + for (std::string_view name : MAP_NAMES){ + maps.push_back(load_map(std::string(name))); } return maps; }(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp index 4bed71ad17..fca2836022 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp @@ -26,7 +26,7 @@ struct OverworldMapsInput{ }; struct OverworldMapsExpectation{ - const char* description; + std::string_view description; }; struct OverworldMapsTestCase{ @@ -53,7 +53,7 @@ class Test_OverworldMaps : public UnitTest{ }; -const char* const VALID_MAP = R"({ +const std::string VALID_MAP = R"({ "name": "Test", "source": {"decomp_file": "data/maps/Test/map.json", "revision": "test", "date": "2026-10-31"}, "tiles": ["#.w", "~D."], @@ -79,8 +79,8 @@ std::string parse_error(const std::string& json){ } // Whether `text` contains every one of `parts`. -bool mentions(const std::string& text, std::initializer_list parts){ - for (const char* part : parts){ +bool mentions(const std::string& text, std::initializer_list parts){ + for (std::string_view part : parts){ if (text.find(part) == std::string::npos){ return false; } @@ -173,7 +173,7 @@ UnitTestResult test_unknown_tile(){ // Route 3's Lass Robin, shrunk: she wanders x 2, y 2..4 looking north and // south, sight 3, below a corridor (row 1) walled off at x 2 above it; a // bug catcher at (5, 4) looks west, sight 2. -const char* const TRAINERS_MAP = R"({ +const std::string TRAINERS_MAP = R"({ "name": "Trainers", "source": {"decomp_file": "", "revision": "test", "date": "2026-11-02"}, "tiles": ["##.####", ".......", ".......", ".......", ".......", "~~~~~~~"], @@ -224,7 +224,7 @@ UnitTestResult test_not_json(){ // A hall with an escalator at (1, 2) to a floor that isn't loaded, like // Route 4's Pokemon Center. -const char* const ESCALATOR_HALL = R"({ +const std::string ESCALATOR_HALL = R"({ "name": "Hall", "source": {"decomp_file": "", "revision": "test", "date": "2026-11-02"}, "tiles": ["######", "#....#", "#....#", "######"], "warps": [{"x": 1, "y": 2, "enter": "step_on"}] diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp index 8e91a54445..9eeaf20652 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp @@ -31,7 +31,7 @@ struct OverworldReanchorInput{ }; struct OverworldReanchorExpectation{ - const char* description; + std::string_view description; }; struct OverworldReanchorTestCase{ @@ -145,7 +145,7 @@ UnitTestResult test_viridian_forest(){ } // A field with a wall at its east end and a row of ledges to the south. -const char* const TEST_FIELD_JSON = R"({ +const std::string TEST_FIELD_JSON = R"({ "name": "Field", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, "tiles": ["########", "#......#", "#......#", "#vvvvvv#", "#......#"], "elevation": ["33333333", "33333333", "33333333", "33333333", "33333333"] @@ -210,7 +210,7 @@ UnitTestResult test_timing(){ } // A field with someone standing in the middle of its north row. -const char* const TEST_PERSON_JSON = R"({ +const std::string TEST_PERSON_JSON = R"({ "name": "Person", "source": {"decomp_file": "", "revision": "test", "date": "2026-11-02"}, "tiles": ["#######", "#.....#", "#.....#", "#######"], "objects": [{"name": "youngster", "kind": "npc", "x": 3, "y": 1}] diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp index 445525c7f7..3b9ba87f71 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp @@ -34,7 +34,7 @@ struct OverworldRecoveryInput{ }; struct OverworldRecoveryExpectation{ - const char* description; + std::string_view description; }; struct OverworldRecoveryTestCase{ @@ -203,7 +203,7 @@ UnitTestResult test_stop_recover_resume(){ } // A corridor with a person at each end: nothing finds the player again. -const char* const TEST_CORRIDOR_JSON = R"({ +const std::string TEST_CORRIDOR_JSON = R"({ "name": "Corridor", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, "tiles": ["#######", "#.....#", "#######"], "elevation": ["3333333", "3333333", "3333333"], @@ -281,7 +281,7 @@ UnitTestResult test_wall_check(){ wall.to_wall = true; const RouteStep open = walk(Direction::EAST, 2, {"Corridor", {3, 1}}); struct Case{ - const char* name; + std::string_view name; bool moves; WallCheck check; bool logged; @@ -340,7 +340,7 @@ UnitTestResult test_route_logged(){ // row 1, walled at x 6, and below it Robin's column x 3, where she wanders // y 2..4 looking north and south, sight 3. Every way east along the // corridor crosses her sight at (3, 1), and nowhere else. -const char* const TEST_ROBIN_JSON = R"({ +const std::string TEST_ROBIN_JSON = R"({ "name": "Robin", "source": {"decomp_file": "", "revision": "test", "date": "2026-11-02"}, "tiles": ["#######", "......#", "###.###", "###.###", "###.###", "#######"], "objects": [ @@ -373,7 +373,7 @@ UnitTestResult test_trainer_crossing(){ // A leg east past Robin, then a turn north: how the leg and the watch for // her after it end, and whether she saw the player. struct TrainerCase{ - const char* name; + std::string_view name; RouteStep leg; StepEnd walk_end; std::optional walked; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp index 9bafa42c91..eb158bbe8f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp @@ -721,12 +721,12 @@ UnitTestResult test_mewtwo_tile_unreachable(){ UnitTestResult test_story_maps(){ const std::vector maps = overworld_maps(); - for (const char* name : { + for (std::string_view name : { "PalletTown_PlayersHouse_2F", "PalletTown_ProfessorOaksLab", "Route1", "ViridianCity_Mart", "Route22", "Route2", "ViridianForest", "PewterCity", "PewterCity_Museum_1F", "PewterCity_Gym", }){ - if (map_named(maps, name) == nullptr){ - return std::string("Missing map ") + name + "."; + if (map_named(maps, std::string(name)) == nullptr){ + return std::format("Missing map {}.", name); } } return true; @@ -778,7 +778,7 @@ UnitTestResult test_viridian_mart_to_pewter_gym(){ } // A room with a sign on its north wall, above the third column. -const char* const TEST_SIGN_ROOM_JSON = R"({ +const std::string TEST_SIGN_ROOM_JSON = R"({ "name": "SignRoom", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, "tiles": ["##S##", "#...#", "#...#", "#...#", "#####"], "elevation": ["33333", "33333", "33333", "33333", "33333"] @@ -810,7 +810,7 @@ UnitTestResult test_no_hold_into_sign(){ } // A yard with a row of ledges across it. -const char* const TEST_LEDGE_YARD_JSON = R"({ +const std::string TEST_LEDGE_YARD_JSON = R"({ "name": "LedgeYard", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, "tiles": ["#####", "#...#", "#...#", "#vvv#", "#...#", "#####"], "elevation": ["33333", "33333", "33333", "33333", "33333", "33333"] @@ -898,14 +898,14 @@ UnitTestResult test_wild_steps(){ return true; } -const char* const TEST_ROOM_JSON = R"({ +const std::string TEST_ROOM_JSON = R"({ "name": "Room", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, "tiles": ["#####", "#...#", "#...#", "##.##"], "elevation": ["33333", "33333", "33333", "33333"], "points": {"warp_0": [2, 3]}, "warps": [{"x": 2, "y": 3, "enter": "walk_south", "to_map": "Yard", "to_point": "warp_0"}] })"; -const char* const TEST_YARD_JSON = R"({ +const std::string TEST_YARD_JSON = R"({ "name": "Yard", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, "tiles": ["#####", "##D##", "#...#", "#####"], "elevation": ["33333", "33333", "33333", "33333"], diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp index b60f08dbcc..003ed1fb8d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp @@ -232,7 +232,7 @@ void check_overworld(ConsoleHandle& console, ProControllerContext& context, cons if (!screen){ return; } - const char* open = nullptr; + std::string_view open; if (StartMenuDetector(COLOR_RED).detect(screen)){ open = "the START menu"; }else if (SelectionDialogDetector(COLOR_RED).detect(screen)){ @@ -240,10 +240,10 @@ void check_overworld(ConsoleHandle& console, ProControllerContext& context, cons }else if (WhiteDialogDetector(COLOR_RED).detect(screen)){ open = "a message"; } - if (open != nullptr){ + if (!open.empty()){ OperationFailedExceptionWithScreenshot::fire( ErrorReportMode::SEND_ERROR_REPORT, - std::string("walk_overworld_route(): ") + open + " is open, before: " + to_string(step), + std::format("walk_overworld_route(): {} is open, before: {}", open, to_string(step)), console ); } @@ -329,7 +329,7 @@ void start_surf(ConsoleHandle& console, ProControllerContext& context, Direction -const char* move_speed_name(MoveSpeed speed){ +std::string_view move_speed_name(MoveSpeed speed){ switch (speed){ case MoveSpeed::WALK: return "walk"; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h index e98eb4e20b..50ba22786d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h @@ -70,7 +70,7 @@ enum class MoveSpeed{ RUN, }; // Name of a movement speed. -const char* move_speed_name(MoveSpeed speed); +std::string_view move_speed_name(MoveSpeed speed); // Walks `route` from where it was planned, at `speed`. The player must be diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp index ce03db9c52..54e41463ed 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp @@ -21,7 +21,7 @@ using namespace OverworldWalkSteps; namespace{ struct OverworldWalkInput{ - const char* name; + std::string_view name; MoveSpeed speed; int tiles; bool to_wall; @@ -30,7 +30,7 @@ struct OverworldWalkInput{ struct OverworldWalkExpectation{ Milliseconds hold; - const char* note; + std::string_view note; }; struct OverworldWalkTestCase{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp index b779c293bf..c93346f9e8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include #include @@ -29,7 +30,7 @@ namespace{ // The sprite sheet's frames are 16x32, and the standing ones are 0 (south), // 1 (north) and 2 (west). Rows 12 to 30 are drawn; the rest is empty. -const char PLAYER_SPRITE_SHEET[] = "PokemonFRLG/PlayerSprites/red_normal.png"; +constexpr std::string_view PLAYER_SPRITE_SHEET = "PokemonFRLG/PlayerSprites/red_normal.png"; constexpr int SHEET_FRAME_WIDTH = 16; constexpr int SHEET_FIRST_ROW = 12; @@ -84,7 +85,7 @@ double difference(const ImageViewRGB32& game, const ImageViewRGB32& sprite, bool const PlayerSprites& player_sprites(){ static const PlayerSprites SPRITES = []{ - const ImageRGB32 sheet(RESOURCE_PATH() + PLAYER_SPRITE_SHEET); + const ImageRGB32 sheet(std::format("{}{}", RESOURCE_PATH(), PLAYER_SPRITE_SHEET)); return PlayerSprites{sheet_frame(sheet, 0), sheet_frame(sheet, 1), sheet_frame(sheet, 2)}; }(); return SPRITES; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index aac1a86c4f..0bd653ac90 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -60,7 +60,7 @@ const StringSelectDatabase& checkpoint_database(){ return database; } -const char* const KEEP_START_FRAME_TEXT = +const std::string KEEP_START_FRAME_TEXT = "Keep the start frame:
Off by default. The save loaded was made by hand where the start checkpoint " "begins: keep the screen after loading it as that checkpoint's start frame, which later runs compare their " "save with. The program keeps one by itself at each save it makes."; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index 9b30f07f22..74d8f117b1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -727,7 +727,7 @@ void set_options(ConsoleHandle& console, ProControllerContext& context, StartMen options_shot(console, context, "before"); struct Target{ OptionMenuItem item; - const char* value; + std::string_view value; }; // In row order. The cursor opens on TEXT SPEED (option_menu.c: // cursorPos = 0) and DOWN moves it a row. Were it on another row, the @@ -742,7 +742,7 @@ void set_options(ConsoleHandle& console, ProControllerContext& context, StartMen for (; cursor < option_menu_row(target.item); cursor++){ tap(context, DPAD_DOWN); } - set_option(console, context, target.item, target.value, language); + set_option(console, context, target.item, std::string(target.value), language); } options_shot(console, context, "after"); press(context, BUTTON_B, 1500ms); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index 31d2a99fbf..c0044cd7d7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -202,7 +202,7 @@ struct MartOrder{ int row = 0; int quantity = 1; // The item's slug for the check (see read_item_list_name()). - const char* item = ""; + std::string_view item = ""; }; // Down (positive) or up (negative) presses to move a Mart list's cursor diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 5e48eeaf18..f119e6c6a6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -103,7 +103,7 @@ enum class BattleScreen{ NONE, // no battle on screen }; -const char* screen_name(BattleScreen screen){ +std::string_view screen_name(BattleScreen screen){ switch (screen){ case BattleScreen::MENU: return "battle menu"; @@ -795,7 +795,7 @@ class StoryMessage : public OverworldInterrupt{ } // namespace -const char* status_name(StatusCondition status){ +std::string_view status_name(StatusCondition status){ switch (status){ case StatusCondition::NONE: return "no status"; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index 83cd611d35..a03b6c3f0e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -49,7 +49,7 @@ enum class StatusCondition{ OTHER, // SLP, BRN, FRZ }; // String representation of a status condition. -const char* status_name(StatusCondition status); +std::string_view status_name(StatusCondition status); // The healing items in the Items pocket, in the order they were bought: // Potions, Antidotes, then Parlyz Heals. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 5b52f0f952..92f07baf91 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -220,11 +220,11 @@ Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ // POKE BALL, POTION (300), ANTIDOTE (100), PARLYZ HEAL (200). Each item // the story buys: its row, and where the bag's count is kept. struct MartItem{ - const char* item; + std::string_view item; int row; int Supplies::* count; // The name the item list reader reads (read_item_list_name()). - const char* slug; + std::string_view slug; }; constexpr MartItem VIRIDIAN_MART_ITEMS[] = { {.item = "potion", .row = 1, .count = &Supplies::potions, .slug = "potion"}, @@ -308,7 +308,7 @@ std::optional story_pose(const Pokemon::Pose& pose){ std::string save_card_place(const std::string& map){ // The longer names first: "ViridianForest" before "ViridianCity". - static const std::pair PLACES[] = { + static const std::pair PLACES[] = { {"PalletTown", "pallet-town"}, {"ViridianForest", "viridian-forest"}, {"ViridianCity", "viridian-city"}, @@ -316,7 +316,7 @@ std::string save_card_place(const std::string& map){ }; for (const auto& [prefix, place] : PLACES){ if (map.rfind(prefix, 0) == 0){ - return place; + return std::string(place); } } return ""; @@ -452,7 +452,7 @@ ConsoleAction console_action_of(StoryActionId id){ case StoryActionId::GAME: break; } - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::string("No console action for ") + story_action_name(id)); + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("No console action for {}", story_action_name(id))); } } // namespace diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp index 42665efa45..a991797420 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp @@ -12,7 +12,7 @@ namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ namespace{ -const char* menu_name(StartMenu menu){ +std::string_view menu_name(StartMenu menu){ switch (menu){ case StartMenu::BEFORE_POKEMON: return "before_pokemon"; case StartMenu::BEFORE_POKEDEX: return "before_pokedex"; @@ -66,7 +66,7 @@ JsonObject supplies_json(const Supplies& supplies){ result["antidotes"] = supplies.antidotes; result["parlyz_heals"] = supplies.parlyz_heals; result["pocket"] = strings(supplies.pocket); - result["status"] = status_name(supplies.status); + result["status"] = std::string(status_name(supplies.status)); result["hurt"] = supplies.hurt; result["hp_red"] = supplies.hp_red; result["hp_fill"] = supplies.hp_fill; @@ -91,7 +91,7 @@ JsonValue story_checkpoint_export(const StoryCheckpoint& checkpoint){ result["status"] = "native-table-export"; result["checkpoint"] = Pokemon::story_checkpoint_json(checkpoint); JsonObject native; - native["menu"] = menu_name(checkpoint.menu); + native["menu"] = std::string(menu_name(checkpoint.menu)); native["supplies"] = supplies_json(checkpoint.supplies); result["native_fields"] = std::move(native); result["state_basis"] = "native-table-bookkeeping"; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index 21dd37d538..36c50ea066 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -34,7 +34,7 @@ struct AutoStoryItemsInput{ }; struct AutoStoryItemsExpectation{ - const char* description; + std::string_view description; }; struct AutoStoryItemsTestCase{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp index 21a2e829cf..72163a9cfc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp @@ -35,7 +35,7 @@ struct AutoStoryPartyInput{ }; struct AutoStoryPartyExpectation{ - const char* description; + std::string_view description; }; struct AutoStoryPartyTestCase{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index 9199c2478e..8e406b7c15 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -313,7 +313,7 @@ struct AutoStorySimulationInput{ }; struct AutoStorySimulationExpectation{ - const char* description; + std::string_view description; }; struct AutoStorySimulationTestCase{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp index 1a298098d9..44b2cc21ef 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts_Tests.cpp @@ -8,6 +8,7 @@ * */ +#include #include #include #include @@ -85,9 +86,9 @@ class FakeGame{ return out; } StepInterruptActions noting(){ - const auto note = [this](const char* kind){ + const auto note = [this](std::string_view kind){ return [this, kind](Pokemon::RunState&, const Pokemon::InterruptVerdict&){ - trace.push_back(std::string("clear ") + kind); + trace.push_back(std::format("clear {}", kind)); return Pokemon::outcome_ok(); }; }; @@ -177,7 +178,7 @@ struct StepInterruptsInput{ UnitTestResult (*body)(); }; struct StepInterruptsExpectation{ - const char* description; + std::string_view description; }; struct StepInterruptsTestCase{ StepInterruptsInput input; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp index 7d9da2e079..cfc635dc87 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp @@ -14,7 +14,7 @@ namespace PokemonFRLG{ using Pokemon::StoryStepKind; -const char* story_action_name(StoryActionId id){ +std::string_view story_action_name(StoryActionId id){ switch (id){ case StoryActionId::NEW_GAME: return "new_game"; case StoryActionId::OPTIONS: return "options"; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h index 3743d498a2..2a7918060f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h @@ -45,7 +45,7 @@ enum class StoryActionId{ GAME, }; // "route", "game": the action's name in logs and test traces. -const char* story_action_name(StoryActionId id); +std::string_view story_action_name(StoryActionId id); // A row of FRLG's table: the action for steps of `kind` whose variant is // named `variant`, or for every other step of `kind` if it is empty. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp index e1903cfcf4..39898070ed 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp @@ -105,7 +105,7 @@ std::string parity_error(FakeGame& game, const StoryStep& step){ } return ""; } - if (trace != std::vector{story_action_name(*expected)} || !outcome.succeeded()){ + if (trace != std::vector{std::string(story_action_name(*expected))} || !outcome.succeeded()){ return std::format("{}: expected {}, ran {} action(s){}", label, story_action_name(*expected), trace.size(), trace.empty() ? "" : ", first " + trace[0]); } @@ -178,7 +178,7 @@ struct StepTableInput{ }; struct StepTableExpectation{ - const char* description; + std::string_view description; }; struct StepTableTestCase{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 9aa3be8596..60d71e3ac5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -8,6 +8,7 @@ * */ +#include #include #include #include @@ -35,7 +36,7 @@ struct AutoStoryInput{ }; struct AutoStoryExpectation{ - const char* description; + std::string_view description; }; struct AutoStoryTestCase{ @@ -355,7 +356,7 @@ UnitTestResult test_runs_after_shoes(){ } const MoveSpeed expected = has_shoes ? MoveSpeed::RUN : MoveSpeed::WALK; if (move_speed(step) != expected){ - return checkpoint.id + "/" + step.name + ": expected to " + move_speed_name(expected) + ", it would " + move_speed_name(move_speed(step)) + "."; + return std::format("{}/{}: expected to {}, it would {}.", checkpoint.id, step.name, move_speed_name(expected), move_speed_name(move_speed(step))); } } has_shoes = has_shoes || checkpoint.id == "00.10"; @@ -414,7 +415,7 @@ UnitTestResult test_save_place_error(){ return true; } -const char* save_action_name(SaveAction action){ +std::string_view save_action_name(SaveAction action){ switch (action){ case SaveAction::WAIT: return "WAIT"; @@ -473,8 +474,7 @@ UnitTestResult test_save_dialog(){ for (size_t i = 0; i < c.screens.size(); i++){ const SaveAction action = dialog.next(c.screens[i].first); if (action != c.screens[i].second){ - return c.name + ", screen " + std::to_string(i + 1) + ": expected " + save_action_name(c.screens[i].second) + - ", got " + save_action_name(action) + "."; + return std::format("{}, screen {}: expected {}, got {}.", c.name, i + 1, save_action_name(c.screens[i].second), save_action_name(action)); } } } @@ -508,7 +508,7 @@ UnitTestResult test_unique_names(){ // was missed. UnitTestResult test_intro_names(){ struct Case{ - const char* what; + std::string_view what; IntroNameScreen screen; size_t keyboards_seen; size_t presets_picked; From 61ebf799de5cbb67b15aff6172f64496a1d47619 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 14:24:01 -0800 Subject: [PATCH 28/29] FRLG AutoStory: split the large Overworld and AutoStory headers Moves groups of declarations unchanged into chained sub-headers so each header exports at most eight names (code health's header_symbols). Each main header includes its last sub-header, so callers are unchanged. Also drops the sim-only type_multipliers() and chart_rows(). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Overworld/PokemonFRLG_OverworldMap.h | 92 +---------- .../Overworld/PokemonFRLG_OverworldObjects.h | 43 +++++ .../Overworld/PokemonFRLG_OverworldReanchor.h | 18 +-- .../Overworld/PokemonFRLG_OverworldRecovery.h | 14 +- .../Overworld/PokemonFRLG_OverworldRoute.h | 79 +-------- .../PokemonFRLG_OverworldRouteCosts.h | 57 +++++++ .../PokemonFRLG_OverworldRouteSteps.h | 82 ++++++++++ .../PokemonFRLG_OverworldTileRules.h | 52 ++++++ .../Overworld/PokemonFRLG_OverworldTiles.h | 89 +++++++++++ .../PokemonFRLG_OverworldTrainerCrossing.h | 45 ++++++ .../Overworld/PokemonFRLG_OverworldWalk.h | 104 +----------- .../PokemonFRLG_OverworldWalkMoves.h | 65 ++++++++ .../PokemonFRLG_OverworldWalkOptions.h | 73 +++++++++ .../PokemonFRLG_OverworldWalkTimes.h | 57 +++++++ .../PokemonFRLG_OverworldWalkWatches.h | 55 +++++++ .../PokemonFRLG_OverworldWalkedTiles.h | 49 ++++++ .../AutoStory/PokemonFRLG_AutoStoryActions.h | 151 +----------------- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 100 +----------- .../PokemonFRLG_AutoStoryBattleData.cpp | 29 ---- .../PokemonFRLG_AutoStoryBattleData.h | 112 +------------ .../PokemonFRLG_AutoStoryBattleDecisions.h | 61 +------ .../PokemonFRLG_AutoStoryBattleTurns.h | 92 +++++++++++ .../PokemonFRLG_AutoStoryCheckpoints.h | 67 ++++++++ .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 90 +---------- .../AutoStory/PokemonFRLG_AutoStoryIntro.h | 71 ++++++++ .../PokemonFRLG_AutoStoryItemsPocket.h | 68 ++++++++ .../AutoStory/PokemonFRLG_AutoStoryLevelUps.h | 56 +++++++ .../AutoStory/PokemonFRLG_AutoStoryMoveData.h | 86 ++++++++++ .../PokemonFRLG_AutoStoryNewMembers.h | 55 +++++++ .../AutoStory/PokemonFRLG_AutoStoryParty.h | 93 +---------- .../PokemonFRLG_AutoStoryPartyMember.h | 76 +++++++++ .../AutoStory/PokemonFRLG_AutoStoryPoses.h | 73 +++++++++ .../AutoStory/PokemonFRLG_AutoStoryPresses.h | 66 ++++++++ .../AutoStory/PokemonFRLG_AutoStorySave.h | 91 +++++++++++ .../PokemonFRLG_AutoStorySaveChecks.h | 73 +++++++++ .../PokemonFRLG_AutoStoryStartFrameCompare.h | 56 +++++++ .../PokemonFRLG_AutoStoryStartFrameStore.h | 82 ++++++++++ .../PokemonFRLG_AutoStoryStartFrames.h | 72 +-------- .../PokemonFRLG_AutoStoryStartMenu.h | 66 ++++++++ .../PokemonFRLG_AutoStoryStoryTrainers.h | 62 +++++++ .../AutoStory/PokemonFRLG_AutoStorySupplies.h | 107 +++++++++++++ .../PokemonFRLG_AutoStoryTrainerData.h | 70 ++++++++ SerialPrograms/cmake/SourceFiles.cmake | 29 ++++ 43 files changed, 2025 insertions(+), 1003 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldObjects.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteCosts.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteSteps.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTileRules.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTiles.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTrainerCrossing.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkMoves.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkOptions.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkTimes.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkWatches.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkedTiles.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCheckpoints.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryIntro.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLevelUps.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMoveData.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryNewMembers.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPartyMember.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPoses.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPresses.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySave.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySaveChecks.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameCompare.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameStore.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartMenu.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStoryTrainers.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerData.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h index e4dc68dc2f..bcbcc8ed79 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h @@ -21,103 +21,13 @@ #include #include "Pokemon/Navigation/Pokemon_Grid.h" #include "Pokemon/Navigation/Pokemon_MapData.h" +#include "PokemonFRLG_OverworldObjects.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Direction enum from Pokemon navigation. -using Pokemon::Direction; -// Grid tile coordinates. -using Pokemon::TilePos; -// Classification of tile terrain. -using Pokemon::TileKind; -// Parsed map representation. -using Pokemon::MapData; -// Warp point connection. -using Pokemon::MapWarp; -// Entity object on a map. -using Pokemon::MapObject; -// Inter-map border connection. -using Pokemon::MapConnection; -// Warp entry trigger definition. -using Pokemon::WarpEntry; -// Finds warp located at specific tile coordinates. -using Pokemon::warp_at; - - -// Elevations with a meaning of their own in the game's rules -// (IsElevationMismatchAt() and ObjectEventUpdateElevation() in -// pokefirered). -// Stairs and ladders: they join every elevation. -constexpr uint8_t ELEVATION_ANY = 0; -// Bridges and the like: they don't change the player's elevation. -constexpr uint8_t ELEVATION_IGNORED = 15; -// Ordinary ground: most walkable tiles in the decompilation's map layouts. -// Surf starts and ends here (CanStopSurfing(), and the Surf field move -// checks the player's elevation is 3). -constexpr uint8_t ELEVATION_GROUND = 3; - - -// How FRLG reads a map's tiles (Pokemon::TileKind) and warps: -// - WALL, DOOR, SIGN and the ledges are walls. A DOOR warps the player who -// walks north into it; a SIGN shows its message to the player who walks -// into it moving north or south (signposts, Center and Mart signs; -// pokefirered TrySetUpWalkIntoSignpostScript()). Ledges are hopped the -// way they face, which isn't modelled, so the planner avoids them. -// - WATER is entered only by starting to Surf. -// - CLOSED_ can't be entered or left through that side. -// - A warp entered by step_on (ladders, escalators) or cave_entrance warps -// the player who steps onto its tile; walk_ (exit mats, stairs -// at the side of a room) warps the player standing on it who walks that -// way. -// A map without an elevation grid is all ground. - -// Whether the given point falls within the map bounds. -bool in_bounds(const MapData& map, const TilePos& point); -// Out-of-bounds tiles are walls. -TileKind tile_at(const MapData& map, const TilePos& point); -// Returns the elevation index at the given coordinate. -uint8_t elevation_at(const MapData& map, const TilePos& point); - -// Whether the tile at point is unwalkable wall terrain. -bool is_wall(const MapData& map, const TilePos& point); -// Whether the tile at point is water terrain. -bool is_water(const MapData& map, const TilePos& point); -// Whether the tile at point is tall grass terrain. -bool is_tall_grass(const MapData& map, const TilePos& point); -// Whether the tile at point is a one-way ledge. -bool is_ledge(const MapData& map, const TilePos& point); -// Whether the tile itself refuses a step in `direction`: entering it, or -// leaving it. -bool blocks_entering(const MapData& map, const TilePos& point, Direction direction); -// Whether leaving the tile in the given direction is blocked. -bool blocks_leaving(const MapData& map, const TilePos& point, Direction direction); - -// Whether the game takes this tile's warp on stepping onto it (a ladder or -// cave entrance). -bool warps_on_step(const MapData& map, const TilePos& point); -// A door, entered by walking north into it. -bool is_door(const MapData& map, const TilePos& point); -// The direction that takes the exit mat on this tile, if it is one. -std::optional exit_mat(const MapData& map, const TilePos& point); -// Arriving on a door or cave entrance, the game walks the player one -// tile south, out of it. -bool walks_out_on_arrival(const MapData& map, const TilePos& point); - -// The object standing, or maybe wandering, on this tile. -const MapObject* object_at(const MapData& map, const TilePos& point); - -// Whether `object`, a trainer, may see the player on `tile`: up to its -// sight ahead, any way it looks, short of a wall, from its tile or, for -// one who wanders, from any tile it may wander to. False for an object -// that isn't a trainer. -bool trainer_may_see(const MapData& map, const MapObject& object, const TilePos& tile); - -// Removes the objects the game hides once one of `flags` is set. -void hide_objects(MapData& map, const std::set& flags); - // What decides where the player's next step can go. struct PlayerState{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldObjects.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldObjects.h new file mode 100644 index 0000000000..70baec8852 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldObjects.h @@ -0,0 +1,43 @@ +/* Overworld Objects + * + * From: https://github.com/PokemonAutomation/ + * + * The objects standing on a map: which one is on a tile, what a + * trainer may see, and the ones the game hides by flag. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldObjects_H +#define PokemonAutomation_PokemonFRLG_OverworldObjects_H + +#include +#include +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "Pokemon/Navigation/Pokemon_MapData.h" +#include "PokemonFRLG_OverworldTileRules.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The object standing, or maybe wandering, on this tile. +const MapObject* object_at(const MapData& map, const TilePos& point); + +// Whether `object`, a trainer, may see the player on `tile`: up to its +// sight ahead, any way it looks, short of a wall, from its tile or, for +// one who wanders, from any tile it may wander to. False for an object +// that isn't a trainer. +bool trainer_may_see(const MapData& map, const MapObject& object, const TilePos& tile); + +// Removes the objects the game hides once one of `flags` is set. +void hide_objects(MapData& map, const std::set& flags); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h index c4aaa0ba4f..709712e783 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h @@ -26,29 +26,13 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "PokemonFRLG_OverworldMap.h" #include "PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_OverworldWalkedTiles.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ -// How many tiles of a stopped leg the player may have walked: from `min` -// to `max`, both included. -struct WalkedTiles{ - int min = 0; - int max = 0; -}; - -// How far off the timing of a stop may be: the interrupts' detection delays -// aren't calibrated, and video lag and the watchers' period add to them. -constexpr Milliseconds STOP_TIMING_SLACK(300); - -// Where the timing puts a stop on `step`: `estimate` tiles walked -// (Pokemon::LegResult::tiles), give or take STOP_TIMING_SLACK at -// `tile_time` a tile: a tile either side walking, two running. -WalkedTiles walked_near(const RouteStep& step, int estimate, Milliseconds tile_time); -// Anywhere on `step`, for a stop the timing doesn't place. -WalkedTiles whole_leg(const RouteStep& step); // A trainer who saw the player and walked up to them: which of `map`'s // objects, and the tile next to the player they stand on afterwards. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h index e5ac8ab70b..cef84ccb7d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h @@ -37,6 +37,7 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "PokemonFRLG_OverworldReanchor.h" #include "PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_OverworldTrainerCrossing.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -97,19 +98,6 @@ struct RouteCalls{ std::function watch_for_trainer; }; -// Where a WALK leg crosses the sight of its maps' trainers -// (trainer_may_see()): the tiles of the leg after its start that one may -// see, in order, and the farthest any of them walks up to the player -// (their sight), to watch for them that long. Trainers already beaten are -// counted too: the maps don't know them. -struct TrainerCrossing{ - std::vector seen; - int approach_tiles = 0; -}; -// Nothing if `step`, from `start`, crosses no trainer's sight. -std::optional trainer_crossing( - const std::vector& maps, const MapPosition& start, const RouteStep& step -); // How often a route may stop part-way before it gives up. constexpr size_t MAX_ROUTE_STOPS = 8; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h index a3c659ba8c..6b10505a73 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h @@ -19,90 +19,13 @@ #include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "PokemonFRLG_OverworldMap.h" +#include "PokemonFRLG_OverworldRouteCosts.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Position on a specific map. -struct MapPosition{ - std::string map; - TilePos point; - - bool operator==(const MapPosition& other) const = default; -}; -// Formats a MapPosition as a string. -std::string to_string(const MapPosition& position); - - -// Action associated with reaching a route waypoint. -enum class RouteAction{ - WALK, // hold `direction` for `tiles` tiles - SURF, // face `direction`, use Surf, and land on the water there - FACE, // turn to `direction` without moving -}; - -// A single step along an overworld path. -struct RouteStep{ - RouteAction action = RouteAction::WALK; - Direction direction = Direction::NORTH; - int tiles = 0; - // WALK: the last tile is a warp (ladder, stairs), so the screen fades - // and the player arrives on another map. - bool warps = false; - // WALK: on the water, where the player moves twice as fast. - bool surfing = false; - // WALK: a wall stops the player at the end, so the leg can be held for - // longer than it takes and still ends on its tile. - bool to_wall = false; - // WALK, SURF: a wild Pokemon can appear on the way: the step crosses - // tall grass or water. Elsewhere (indoors, streets) no wild battle can - // start, so the walker doesn't watch for one. - bool wild = false; - // Which way the player faces after the step. Arriving at a door or a - // cave mouth, the game walks the player a tile out, facing south. - Direction facing_after = Direction::NORTH; - // Where the player is after the step. - MapPosition end; -}; -// Formats a RouteStep as a string. -std::string to_string(const RouteStep& step); - - -// Navigation goal specification. -struct RouteGoal{ - MapPosition position; - // Which way to face on arrival, e.g. towards a Pokemon to talk to. - std::optional facing; -}; - -// What the planner weighs a route by. Each is a cost per occurrence. -enum class RouteCost{ - TILE, - TURN, // extra for a leg in a new direction - WARP, // the fade in and out - SURF, // the dialog and the animation - GRASS_TILE, // extra for tall grass, where wild Pokemon appear - // Extra for a leg that ends where the player could keep walking: it has - // to be timed, and if a message or a battle stops it part-way, where - // the player is can only be estimated. A leg that ends at a wall is - // walked again instead. - OPEN_STOP, - // Extra again when that leg crosses tall grass or water, where a wild - // battle is likely to stop it: the walker can't tell where it did - // (console B, 2026-11-01, Route 1, four runs). - OPEN_WILD_STOP, -}; -// Cost mapping table for path planning. -using RouteCosts = std::map; - -// TILE 1, TURN 2, WARP 30, SURF 40, GRASS_TILE 20, OPEN_STOP 8, -// OPEN_WILD_STOP 300. -const RouteCosts& default_route_costs(); - -// `costs`'s cost for `kind`, or the default if it has none. -int route_cost(const RouteCosts& costs, RouteCost kind); // The cheapest route from `start`, surfing if it is on water, to // `goal`, or nothing if there is none. `maps` must hold every map the route diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteCosts.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteCosts.h new file mode 100644 index 0000000000..8d4c82b1fc --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteCosts.h @@ -0,0 +1,57 @@ +/* Overworld Route Costs + * + * From: https://github.com/PokemonAutomation/ + * + * What the route planner weighs a route by, and the default costs. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldRouteCosts_H +#define PokemonAutomation_PokemonFRLG_OverworldRouteCosts_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_OverworldMap.h" +#include "PokemonFRLG_OverworldRouteSteps.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// What the planner weighs a route by. Each is a cost per occurrence. +enum class RouteCost{ + TILE, + TURN, // extra for a leg in a new direction + WARP, // the fade in and out + SURF, // the dialog and the animation + GRASS_TILE, // extra for tall grass, where wild Pokemon appear + // Extra for a leg that ends where the player could keep walking: it has + // to be timed, and if a message or a battle stops it part-way, where + // the player is can only be estimated. A leg that ends at a wall is + // walked again instead. + OPEN_STOP, + // Extra again when that leg crosses tall grass or water, where a wild + // battle is likely to stop it: the walker can't tell where it did + // (console B, 2026-11-01, Route 1, four runs). + OPEN_WILD_STOP, +}; +// Cost mapping table for path planning. +using RouteCosts = std::map; + +// TILE 1, TURN 2, WARP 30, SURF 40, GRASS_TILE 20, OPEN_STOP 8, +// OPEN_WILD_STOP 300. +const RouteCosts& default_route_costs(); + +// `costs`'s cost for `kind`, or the default if it has none. +int route_cost(const RouteCosts& costs, RouteCost kind); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteSteps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteSteps.h new file mode 100644 index 0000000000..c28ddc5fbc --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteSteps.h @@ -0,0 +1,82 @@ +/* Overworld Route Steps + * + * From: https://github.com/PokemonAutomation/ + * + * A planned overworld route's parts: positions on a map, the steps a + * route is walked in, and the goal it is planned to. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldRouteSteps_H +#define PokemonAutomation_PokemonFRLG_OverworldRouteSteps_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_OverworldMap.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Position on a specific map. +struct MapPosition{ + std::string map; + TilePos point; + + bool operator==(const MapPosition& other) const = default; +}; +// Formats a MapPosition as a string. +std::string to_string(const MapPosition& position); + + +// Action associated with reaching a route waypoint. +enum class RouteAction{ + WALK, // hold `direction` for `tiles` tiles + SURF, // face `direction`, use Surf, and land on the water there + FACE, // turn to `direction` without moving +}; + +// A single step along an overworld path. +struct RouteStep{ + RouteAction action = RouteAction::WALK; + Direction direction = Direction::NORTH; + int tiles = 0; + // WALK: the last tile is a warp (ladder, stairs), so the screen fades + // and the player arrives on another map. + bool warps = false; + // WALK: on the water, where the player moves twice as fast. + bool surfing = false; + // WALK: a wall stops the player at the end, so the leg can be held for + // longer than it takes and still ends on its tile. + bool to_wall = false; + // WALK, SURF: a wild Pokemon can appear on the way: the step crosses + // tall grass or water. Elsewhere (indoors, streets) no wild battle can + // start, so the walker doesn't watch for one. + bool wild = false; + // Which way the player faces after the step. Arriving at a door or a + // cave mouth, the game walks the player a tile out, facing south. + Direction facing_after = Direction::NORTH; + // Where the player is after the step. + MapPosition end; +}; +// Formats a RouteStep as a string. +std::string to_string(const RouteStep& step); + + +// Navigation goal specification. +struct RouteGoal{ + MapPosition position; + // Which way to face on arrival, e.g. towards a Pokemon to talk to. + std::optional facing; +}; + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTileRules.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTileRules.h new file mode 100644 index 0000000000..79cb3944c6 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTileRules.h @@ -0,0 +1,52 @@ +/* Overworld Tile Rules + * + * From: https://github.com/PokemonAutomation/ + * + * The walking rules of FRLG's special tiles: grass, ledges, one-way + * edges, warps, doors and exit mats. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldTileRules_H +#define PokemonAutomation_PokemonFRLG_OverworldTileRules_H + +#include +#include +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "Pokemon/Navigation/Pokemon_MapData.h" +#include "PokemonFRLG_OverworldTiles.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Whether the tile at point is tall grass terrain. +bool is_tall_grass(const MapData& map, const TilePos& point); +// Whether the tile at point is a one-way ledge. +bool is_ledge(const MapData& map, const TilePos& point); +// Whether the tile itself refuses a step in `direction`: entering it, or +// leaving it. +bool blocks_entering(const MapData& map, const TilePos& point, Direction direction); +// Whether leaving the tile in the given direction is blocked. +bool blocks_leaving(const MapData& map, const TilePos& point, Direction direction); + +// Whether the game takes this tile's warp on stepping onto it (a ladder or +// cave entrance). +bool warps_on_step(const MapData& map, const TilePos& point); +// A door, entered by walking north into it. +bool is_door(const MapData& map, const TilePos& point); +// The direction that takes the exit mat on this tile, if it is one. +std::optional exit_mat(const MapData& map, const TilePos& point); +// Arriving on a door or cave entrance, the game walks the player one +// tile south, out of it. +bool walks_out_on_arrival(const MapData& map, const TilePos& point); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTiles.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTiles.h new file mode 100644 index 0000000000..b25b5715c3 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTiles.h @@ -0,0 +1,89 @@ +/* Overworld Tiles + * + * From: https://github.com/PokemonAutomation/ + * + * A map's tiles as FRLG reads them: bounds, tile kinds, elevations, + * walls and water. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldTiles_H +#define PokemonAutomation_PokemonFRLG_OverworldTiles_H + +#include +#include +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "Pokemon/Navigation/Pokemon_MapData.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Direction enum from Pokemon navigation. +using Pokemon::Direction; +// Grid tile coordinates. +using Pokemon::TilePos; +// Classification of tile terrain. +using Pokemon::TileKind; +// Parsed map representation. +using Pokemon::MapData; +// Warp point connection. +using Pokemon::MapWarp; +// Entity object on a map. +using Pokemon::MapObject; +// Inter-map border connection. +using Pokemon::MapConnection; +// Warp entry trigger definition. +using Pokemon::WarpEntry; +// Finds warp located at specific tile coordinates. +using Pokemon::warp_at; + + +// Elevations with a meaning of their own in the game's rules +// (IsElevationMismatchAt() and ObjectEventUpdateElevation() in +// pokefirered). +// Stairs and ladders: they join every elevation. +constexpr uint8_t ELEVATION_ANY = 0; +// Bridges and the like: they don't change the player's elevation. +constexpr uint8_t ELEVATION_IGNORED = 15; +// Ordinary ground: most walkable tiles in the decompilation's map layouts. +// Surf starts and ends here (CanStopSurfing(), and the Surf field move +// checks the player's elevation is 3). +constexpr uint8_t ELEVATION_GROUND = 3; + + +// How FRLG reads a map's tiles (Pokemon::TileKind) and warps: +// - WALL, DOOR, SIGN and the ledges are walls. A DOOR warps the player who +// walks north into it; a SIGN shows its message to the player who walks +// into it moving north or south (signposts, Center and Mart signs; +// pokefirered TrySetUpWalkIntoSignpostScript()). Ledges are hopped the +// way they face, which isn't modelled, so the planner avoids them. +// - WATER is entered only by starting to Surf. +// - CLOSED_ can't be entered or left through that side. +// - A warp entered by step_on (ladders, escalators) or cave_entrance warps +// the player who steps onto its tile; walk_ (exit mats, stairs +// at the side of a room) warps the player standing on it who walks that +// way. +// A map without an elevation grid is all ground. + +// Whether the given point falls within the map bounds. +bool in_bounds(const MapData& map, const TilePos& point); +// Out-of-bounds tiles are walls. +TileKind tile_at(const MapData& map, const TilePos& point); +// Returns the elevation index at the given coordinate. +uint8_t elevation_at(const MapData& map, const TilePos& point); + +// Whether the tile at point is unwalkable wall terrain. +bool is_wall(const MapData& map, const TilePos& point); +// Whether the tile at point is water terrain. +bool is_water(const MapData& map, const TilePos& point); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTrainerCrossing.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTrainerCrossing.h new file mode 100644 index 0000000000..e00ec3bce5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTrainerCrossing.h @@ -0,0 +1,45 @@ +/* Overworld Trainer Crossing + * + * From: https://github.com/PokemonAutomation/ + * + * Where a leg crosses the sight of its maps' trainers, and how far one + * may walk up to the player. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldTrainerCrossing_H +#define PokemonAutomation_PokemonFRLG_OverworldTrainerCrossing_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_OverworldReanchor.h" +#include "PokemonFRLG_OverworldRoute.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Where a WALK leg crosses the sight of its maps' trainers +// (trainer_may_see()): the tiles of the leg after its start that one may +// see, in order, and the farthest any of them walks up to the player +// (their sight), to watch for them that long. Trainers already beaten are +// counted too: the maps don't know them. +struct TrainerCrossing{ + std::vector seen; + int approach_tiles = 0; +}; +// Nothing if `step`, from `start`, crosses no trainer's sight. +std::optional trainer_crossing( + const std::vector& maps, const MapPosition& start, const RouteStep& step +); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h index 50ba22786d..f8a7b0d71f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h @@ -26,52 +26,13 @@ #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_OverworldWalkMoves.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Something that stops the player part-way through a leg: a wild battle, a -// message. See Pokemon::LegInterrupt. -using OverworldInterrupt = Pokemon::LegInterrupt; -// Overworld movement interruption triggers. -using OverworldInterrupts = Pokemon::LegInterrupts; - -// What to watch for on a route's steps: `wild` on steps where a wild -// Pokemon can appear (RouteStep::wild), `other` on the rest. Watching for a -// battle where none can start only risks a false one: walking to the edge -// of a small room, the screen darkens like a battle's flash (console B, -// 2026-11-01, the bedroom's east wall). -struct OverworldInterruptSet{ - OverworldInterrupts wild; - OverworldInterrupts other; -}; - -// A wild battle, run from, and a message (e.g. "REPEL's effect wore off..."), -// closed with B. See OverworldInterruptSet. -const OverworldInterruptSet& default_overworld_interrupts(); - -// The same, except that after a message another Max Repel is used, from -// slot `max_repel_slot` (from 0) of the Items pocket. Any message on the -// overworld is taken to be the one saying the last Repel wore off. -OverworldInterruptSet overworld_interrupts_with_repel(int max_repel_slot); - -// From the overworld, uses the Max Repel in `slot` (from 0) of the Items -// pocket and returns to the overworld. -void use_max_repel_from_bag(ConsoleHandle& console, ProControllerContext& context, int slot); - - -// How the player moves on foot: walking, or running with B held, which -// needs the Running Shoes (FLAG_SYS_B_DASH, from Oak's aide in Pewter City -// after Brock). On the water the player surfs at its own pace either way. -enum class MoveSpeed{ - WALK, - RUN, -}; -// Name of a movement speed. -std::string_view move_speed_name(MoveSpeed speed); - // Walks `route` from where it was planned, at `speed`. The player must be // standing still on the overworld and not on the bike. `facing` is the way @@ -92,69 +53,6 @@ void walk_overworld_route( // walk_overworld_route() describes. namespace OverworldWalkSteps{ -// Walking duration for a single tile (16 frames at 60 fps). -inline constexpr Milliseconds TILE_TIME(267); -// Surfing duration for a single tile. -inline constexpr Milliseconds SURF_TILE_TIME(133); -// 8 frames: running is 2 pixels a frame, twice walking. Not measured on the -// console yet; the walker logs each leg to a wall (speed_note()) for that. -inline constexpr Milliseconds RUN_TILE_TIME(133); -// turns a player facing another way, without a step. -inline constexpr Milliseconds TURN_TAP(40); -// duration to wait after turning to allow state to settle. -inline constexpr Milliseconds TURN_SETTLE(300); -// short enough to turn without stepping. -inline constexpr Milliseconds FACE_HOLD(40); -// duration of button release between movement steps. -inline constexpr Milliseconds STEP_RELEASE(100); -// After a warp's fade: leaving by a door the game walks the player a tile out -// on its own, and a leg started before that ends loses tiles (on the console a -// 600ms wait cost 2 tiles). -inline constexpr Milliseconds AFTER_WARP(1500); -// After a warp's fade, which a wild battle's flashes and wipe can pass for: -// a battle's HP box shows within this long (console B, 2026-11-01). -inline constexpr Milliseconds AFTER_WARP_BATTLE_WATCH(5000); -// A message set off by a leg's last step shows after the hold ends. Caught -// here, before the next leg's turn tap, which the message would swallow. -inline constexpr Milliseconds AFTER_LEG_WATCH(500); -// The same after a leg through grass. A battle whose flashes are missed is -// seen only by its "Wild appeared!", 3.7s after its step's press -// (twice on Route 1, console B, 2026-11-01, run 7). Unless the walker waits -// that long, the next leg is walked into the battle and lost: there, "east -// 4" and "west 4". -inline constexpr Milliseconds AFTER_WILD_LEG_WATCH(3500); -// How long clear_open_message() watches for the message it saw. -inline constexpr Milliseconds OPEN_MESSAGE_WATCH(1000); -// Maximum interruptions before a leg is abandoned. -inline constexpr size_t MAX_INTERRUPTIONS_PER_LEG = 5; - -// Maps Direction to corresponding DpadPosition. -DpadPosition dpad(Direction direction); - -// The leg mover: holds the D-pad. FRLG moves exactly a tile per 16 frames. -void hold_dpad(ProControllerContext& context, Direction direction, Milliseconds duration); - -// The leg mover for running: holds the D-pad with B for the whole hold. -// Turn taps go without B: a tap only turns the player. -void hold_dpad_running(ProControllerContext& context, Direction direction, Milliseconds duration); - -// How long one tile of `step` takes at `speed`: on the water, the Surf -// pace whatever the speed. -Milliseconds tile_time(const RouteStep& step, MoveSpeed speed); - -// The mover for `step` at `speed`: hold_dpad_running() for a run on foot, -// hold_dpad() otherwise (B does nothing on the water). -Pokemon::LegMover leg_mover(const RouteStep& step, MoveSpeed speed); - -// How long the walker holds the D-pad for a WALK `step` at `speed` -// (Pokemon::leg_hold()). -Milliseconds leg_hold_time(const RouteStep& step, MoveSpeed speed); - -// For a leg to a wall on foot, the line the walker logs so a console run -// can check the pace: "[Speed] run west: 40 tiles in 5320 ms, held 5586 ms", -// the tiles at the assumed pace and the hold. Empty for other steps. -std::string speed_note(const RouteStep& step, MoveSpeed speed); - // After a hold onto `step`'s warp: waits out its fade. void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkMoves.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkMoves.h new file mode 100644 index 0000000000..34fe97123a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkMoves.h @@ -0,0 +1,65 @@ +/* Overworld Walk Moves + * + * From: https://github.com/PokemonAutomation/ + * + * The presses a leg is walked with: the D-pad held walking or running, + * for how long, and the pace line the walker logs. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldWalkMoves_H +#define PokemonAutomation_PokemonFRLG_OverworldWalkMoves_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/Navigation/Pokemon_LegWalker.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_OverworldWalkWatches.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace OverworldWalkSteps{ + +// Maps Direction to corresponding DpadPosition. +DpadPosition dpad(Direction direction); + +// The leg mover: holds the D-pad. FRLG moves exactly a tile per 16 frames. +void hold_dpad(ProControllerContext& context, Direction direction, Milliseconds duration); + +// The leg mover for running: holds the D-pad with B for the whole hold. +// Turn taps go without B: a tap only turns the player. +void hold_dpad_running(ProControllerContext& context, Direction direction, Milliseconds duration); + +// How long one tile of `step` takes at `speed`: on the water, the Surf +// pace whatever the speed. +Milliseconds tile_time(const RouteStep& step, MoveSpeed speed); + +// The mover for `step` at `speed`: hold_dpad_running() for a run on foot, +// hold_dpad() otherwise (B does nothing on the water). +Pokemon::LegMover leg_mover(const RouteStep& step, MoveSpeed speed); + +// How long the walker holds the D-pad for a WALK `step` at `speed` +// (Pokemon::leg_hold()). +Milliseconds leg_hold_time(const RouteStep& step, MoveSpeed speed); + +// For a leg to a wall on foot, the line the walker logs so a console run +// can check the pace: "[Speed] run west: 40 tiles in 5320 ms, held 5586 ms", +// the tiles at the assumed pace and the hold. Empty for other steps. +std::string speed_note(const RouteStep& step, MoveSpeed speed); + +} // namespace OverworldWalkSteps + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkOptions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkOptions.h new file mode 100644 index 0000000000..8473f74c0e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkOptions.h @@ -0,0 +1,73 @@ +/* Overworld Walk Options + * + * From: https://github.com/PokemonAutomation/ + * + * What a walk of an overworld route is told: what can stop the player + * part-way through a leg (OverworldInterrupt), and how fast to move. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldWalkOptions_H +#define PokemonAutomation_PokemonFRLG_OverworldWalkOptions_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/Navigation/Pokemon_LegWalker.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "PokemonFRLG_OverworldRoute.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Something that stops the player part-way through a leg: a wild battle, a +// message. See Pokemon::LegInterrupt. +using OverworldInterrupt = Pokemon::LegInterrupt; +// Overworld movement interruption triggers. +using OverworldInterrupts = Pokemon::LegInterrupts; + +// What to watch for on a route's steps: `wild` on steps where a wild +// Pokemon can appear (RouteStep::wild), `other` on the rest. Watching for a +// battle where none can start only risks a false one: walking to the edge +// of a small room, the screen darkens like a battle's flash (console B, +// 2026-11-01, the bedroom's east wall). +struct OverworldInterruptSet{ + OverworldInterrupts wild; + OverworldInterrupts other; +}; + +// A wild battle, run from, and a message (e.g. "REPEL's effect wore off..."), +// closed with B. See OverworldInterruptSet. +const OverworldInterruptSet& default_overworld_interrupts(); + +// The same, except that after a message another Max Repel is used, from +// slot `max_repel_slot` (from 0) of the Items pocket. Any message on the +// overworld is taken to be the one saying the last Repel wore off. +OverworldInterruptSet overworld_interrupts_with_repel(int max_repel_slot); + +// From the overworld, uses the Max Repel in `slot` (from 0) of the Items +// pocket and returns to the overworld. +void use_max_repel_from_bag(ConsoleHandle& console, ProControllerContext& context, int slot); + + +// How the player moves on foot: walking, or running with B held, which +// needs the Running Shoes (FLAG_SYS_B_DASH, from Oak's aide in Pewter City +// after Brock). On the water the player surfs at its own pace either way. +enum class MoveSpeed{ + WALK, + RUN, +}; +// Name of a movement speed. +std::string_view move_speed_name(MoveSpeed speed); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkTimes.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkTimes.h new file mode 100644 index 0000000000..c2a7fa95a5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkTimes.h @@ -0,0 +1,57 @@ +/* Overworld Walk Times + * + * From: https://github.com/PokemonAutomation/ + * + * How long a tile, a turn and a press take on the overworld. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldWalkTimes_H +#define PokemonAutomation_PokemonFRLG_OverworldWalkTimes_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/Navigation/Pokemon_LegWalker.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_OverworldWalkOptions.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace OverworldWalkSteps{ + +// Walking duration for a single tile (16 frames at 60 fps). +inline constexpr Milliseconds TILE_TIME(267); +// Surfing duration for a single tile. +inline constexpr Milliseconds SURF_TILE_TIME(133); +// 8 frames: running is 2 pixels a frame, twice walking. Not measured on the +// console yet; the walker logs each leg to a wall (speed_note()) for that. +inline constexpr Milliseconds RUN_TILE_TIME(133); +// turns a player facing another way, without a step. +inline constexpr Milliseconds TURN_TAP(40); +// duration to wait after turning to allow state to settle. +inline constexpr Milliseconds TURN_SETTLE(300); +// short enough to turn without stepping. +inline constexpr Milliseconds FACE_HOLD(40); +// duration of button release between movement steps. +inline constexpr Milliseconds STEP_RELEASE(100); +// After a warp's fade: leaving by a door the game walks the player a tile out +// on its own, and a leg started before that ends loses tiles (on the console a +// 600ms wait cost 2 tiles). +inline constexpr Milliseconds AFTER_WARP(1500); + +} // namespace OverworldWalkSteps + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkWatches.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkWatches.h new file mode 100644 index 0000000000..af5ced129a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkWatches.h @@ -0,0 +1,55 @@ +/* Overworld Walk Watches + * + * From: https://github.com/PokemonAutomation/ + * + * How long the walker watches for a battle or a message after a warp + * or a leg, and how often a leg may be interrupted. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldWalkWatches_H +#define PokemonAutomation_PokemonFRLG_OverworldWalkWatches_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/Navigation/Pokemon_LegWalker.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_OverworldWalkTimes.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace OverworldWalkSteps{ + +// After a warp's fade, which a wild battle's flashes and wipe can pass for: +// a battle's HP box shows within this long (console B, 2026-11-01). +inline constexpr Milliseconds AFTER_WARP_BATTLE_WATCH(5000); +// A message set off by a leg's last step shows after the hold ends. Caught +// here, before the next leg's turn tap, which the message would swallow. +inline constexpr Milliseconds AFTER_LEG_WATCH(500); +// The same after a leg through grass. A battle whose flashes are missed is +// seen only by its "Wild appeared!", 3.7s after its step's press +// (twice on Route 1, console B, 2026-11-01, run 7). Unless the walker waits +// that long, the next leg is walked into the battle and lost: there, "east +// 4" and "west 4". +inline constexpr Milliseconds AFTER_WILD_LEG_WATCH(3500); +// How long clear_open_message() watches for the message it saw. +inline constexpr Milliseconds OPEN_MESSAGE_WATCH(1000); +// Maximum interruptions before a leg is abandoned. +inline constexpr size_t MAX_INTERRUPTIONS_PER_LEG = 5; + +} // namespace OverworldWalkSteps + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkedTiles.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkedTiles.h new file mode 100644 index 0000000000..55c0f31082 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkedTiles.h @@ -0,0 +1,49 @@ +/* Overworld Walked Tiles + * + * From: https://github.com/PokemonAutomation/ + * + * How many tiles of a stopped leg the player may have walked, from the + * stop's timing or, when it doesn't place the stop, the whole leg. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldWalkedTiles_H +#define PokemonAutomation_PokemonFRLG_OverworldWalkedTiles_H + +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_OverworldMap.h" +#include "PokemonFRLG_OverworldRoute.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// How many tiles of a stopped leg the player may have walked: from `min` +// to `max`, both included. +struct WalkedTiles{ + int min = 0; + int max = 0; +}; + +// How far off the timing of a stop may be: the interrupts' detection delays +// aren't calibrated, and video lag and the watchers' period add to them. +constexpr Milliseconds STOP_TIMING_SLACK(300); + +// Where the timing puts a stop on `step`: `estimate` tiles walked +// (Pokemon::LegResult::tiles), give or take STOP_TIMING_SLACK at +// `tile_time` a tile: a tile either side walking, two running. +WalkedTiles walked_near(const RouteStep& step, int estimate, Milliseconds tile_time); +// Anywhere on `step`, for a stop the timing doesn't place. +WalkedTiles whole_leg(const RouteStep& step); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index c0044cd7d7..17f73ead43 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -26,156 +26,13 @@ #include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" #include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonFRLG_AutoStorySave.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Whether the shared check level (Types/Pokemon_StoryCheckLevel.h, set by -// StoryRunOptions) has the story check the screen before and after it -// acts: DEFAULT and above (TESTING, THOROUGH). Then FRLG reads a Mart -// row's item before buying it, the bag's Items pocket after shopping (the -// counts the story then keeps), and an item's name in the bag before -// using it. FAST and SPEEDRUN trust the counts it keeps and the timings. -inline bool checks_screen(Pokemon::StoryCheckLevel level){ - return level <= Pokemon::StoryCheckLevel::DEFAULT; -} - -// The START menu as the story grows it. Before the starter: BAG, the -// player, SAVE, OPTION, EXIT; the starter adds POKEMON on top, the Pokedex -// POKEDEX above that. -enum class StartMenu{ - BEFORE_POKEMON, - BEFORE_POKEDEX, - FULL, -}; -// Total rows in the start menu. -int start_menu_rows(StartMenu menu); -// Row index of the SAVE option in the start menu. -int start_menu_save_row(StartMenu menu); -// Row index of the OPTION item in the start menu. -int start_menu_option_row(StartMenu menu); - - -// Whether the overworld is up: START opens the menu only there, with no -// scene running. If it opened, it is closed again. -bool overworld_shows(ConsoleHandle& console, ProControllerContext& context); - - -// Which row of the standard YES/NO box the arrow is on (true: YES), if -// one shows. -std::optional yes_no_cursor(const ImageViewRGB32& screen); - -// The arrow's row on Oak's list of rival names (NEW NAME, then four preset -// names), if the list shows. In pokefirered's oak_speech.c the list is a -// 12x10-tile window at tile (2, 2), rows 16 px apart, the cursor starting -// on NEW NAME. The intro's YES/NO boxes open in the same corner but are -// 6x4 tiles: the list is told from them by its white past their frame. -std::optional rival_name_list_cursor(const ImageViewRGB32& screen); - -// What shows in the new game's intro, as far as the names go. -enum class IntroNameScreen{ - OTHER, - KEYBOARD, - RIVAL_LIST, -}; -// What the new game's intro does about the names. The player's name is -// asked on a keyboard, always first; the rival's on the name list, where -// the first preset name is picked, as SID Helper does. A keyboard after -// the player's is the rival's, opened because the list was missed. -enum class IntroNameStep{ - NONE, - PLAYER_KEYBOARD, - RIVAL_PRESET, - RIVAL_KEYBOARD, -}; -// A preset picked returns to the list only after NO on "Er, was it ...?", -// so after this many picks A opens the keyboard instead. -constexpr size_t RIVAL_PRESET_TRIES = 3; -// Determines the next input step in character/rival naming sequence. -IntroNameStep intro_name_step(IntroNameScreen screen, size_t keyboards_seen, size_t presets_picked); - - -// Expected screen state when dialogue text finishes. -enum class TextEnd{ - OVERWORLD, - BATTLE, -}; - -// Presses B until the overworld is back or, if `stop_at_battle`, a battle -// shows. Throws OperationFailedException after `timeout`. -TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout, bool stop_at_battle); - -// advance_text() to the overworld. -void mash_until_overworld(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout); - -// Advances text with `advance` until a YES/NO shows, then answers it. B -// answers NO. Throws OperationFailedException after `timeout`. -void answer_yes_no(ConsoleHandle& console, ProControllerContext& context, bool yes, Button advance, Milliseconds timeout); - -// From the overworld: one step `direction`, onto a trigger or into a door. -// `facing` is the way the player faces, if known; a player facing another -// way is turned first. -void step_once(ProControllerContext& context, Pokemon::Direction direction, std::optional facing); - -// From the overworld, turns to face `direction` without stepping: the -// player must have a wall that way. -void face_wall(ProControllerContext& context, Pokemon::Direction direction); - -// The save dialog after SAVE, as pokefirered's start_menu.c runs it: -// "Would you like to save the game?" YES/NO (YES first). Then, over a save -// of this game, "There is already a saved file. Is it okay to overwrite -// it?" YES/NO (YES first); over another game's save (a new game), "WARNING! -// There is a different game file that is already saved." on four pages, -// ending "...overwrite the other save file?" YES/NO with NO first. Then -// "SAVING... DON'T TURN OFF THE POWER.", "PLAYER saved the game." and, -// without a press, the overworld. NO at any YES/NO brings the START menu -// back; a failed save shows "Save error." and waits for A held. -enum class SaveScreen{ - YES_NO, - // A message with the arrow for the next page. - PAGED_TEXT, - // A message without an arrow: SAVING, or saved. - TEXT, - START_MENU, - // No message and no menu: the overworld, or a frame between two boxes. - NOTHING, -}; -// Action to perform in the save menu loop. -enum class SaveAction{ - WAIT, - ANSWER_YES, - NEXT_PAGE, - // Confirm the overworld (START opens the menu): the game is saved. - CHECK_OVERWORLD, - // The START menu is back: a YES/NO was answered NO. - FAIL_CANCELLED, - // A paged message after the last YES: "Save error." - FAIL_ERROR, -}; -// What save_game() does on each screen it reads after the save card's -// first YES/NO shows. Every YES/NO gets YES; B is never pressed. -class SaveDialog{ -public: - SaveAction next(SaveScreen screen); - -private: - bool m_paged_since_yes = false; - size_t m_nothing_seen = 0; -}; - -// From the overworld: SAVE, YES, and YES again to overwrite an older save -// (see SaveDialog). The menu's cursor is read, since the game remembers it -// and the menu grows. Returns to the overworld; throws -// OperationFailedException if the save wasn't made. -void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu menu); - -// From the overworld: the place the START menu's SAVE card names (see -// read_save_card_location()), then NO, back to the overworld. Empty if it -// can't be read. The menu's length is read, not assumed, so a save made -// with another START menu (another checkpoint's) is read too. -std::string read_save_place(ConsoleHandle& console, ProControllerContext& context, Language language); // RIGHT presses that turn an option showing `current` into `target`. // RIGHT steps through `values` and wraps from the last to the first @@ -220,12 +77,6 @@ void buy_items( const std::vector& orders, Pokemon::StoryCheckLevel checks, Language language ); -// From the title screen of a game with no save, to the bedroom: the -// controls pages, Oak's speech, BOY, the default name for the player (an -// empty name confirmed) and the rival's first preset name. Returns on the -// overworld. -void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context); - } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index a03b6c3f0e..cd651c25f5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -34,81 +34,13 @@ #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryParty.h" +#include "PokemonFRLG_AutoStoryItemsPocket.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ -// A status condition, as far as the story treats them: the two it carries -// items for, and the rest, which only a nurse cures. -enum class StatusCondition{ - NONE, - POISON, - PARALYSIS, - OTHER, // SLP, BRN, FRZ -}; -// String representation of a status condition. -std::string_view status_name(StatusCondition status); - -// The healing items in the Items pocket, in the order they were bought: -// Potions, Antidotes, then Parlyz Heals. -struct Supplies{ - int potions = 0; - int antidotes = 0; - int parlyz_heals = 0; - // The Items pocket's order, by slug (see read_item_list_name()): the - // order bought, or as read from the bag, with "" for a row whose name - // couldn't be read. A counted item with none left takes no row; the - // others always take theirs. - std::vector pocket = {"potion", "antidote", "parlyz-heal"}; - // The starter's status at the last battle screen that showed it, and - // not cured since. - StatusCondition status = StatusCondition::NONE; - // The starter's HP bar wasn't green (or was red) at the last battle - // screen that showed it, and no Potion or nurse healed it since. - bool hurt = false; - bool hp_red = false; - // The starter's HP bar's filled share at the last battle screen that - // showed it, 1 after the nurse or a Potion on the overworld. - double hp_fill = 1.0; - // The starter's moves and their PP, as far as the story knows them: - // a new game's Squirtle unless a checkpoint's row says otherwise. - PartyMember lead = new_member("squirtle", 5); - // Party slots (from 0, the lead) that are never sent in when the lead - // faints, so they gain no EXP and learn or evolve nothing: a member - // kept for later, or one the user keeps for a trade. - std::vector protected_slots = {}; - // The party of the trainer the table's battle step fights, when the - // story knows it (trainer_party()): the lead's attacks are chosen - // against it while the one out isn't known. Empty otherwise; wild - // battles never use it. - std::vector foes = {}; - // That trainer (story_trainer()), "" otherwise. - std::string trainer = {}; - // How carefully that battle is fought (story_battle_risk()). - BattleRisk risk = BattleRisk::LOW; - // The species of the trainer's Pokemon out, as read at the last battle - // menu (read_trainer_foe()), "" if not read: the lead's attacks are - // chosen against it. - std::string foe_out = {}; - // The wild Pokemon of the battle going on, as read at its first battle - // menu (read_wild_foes()): the lead's attacks are chosen against it. - // Empty when it wasn't read; trainer battles never use it. - std::vector wild_foes = {}; -}; - -// The nurse healed the party: HP, status and PP. -void healed_by_nurse(Supplies& supplies); - -// The lead's attacks are low on PP: the nurse before a fight that needs them. -bool attacks_low_on_pp(const Supplies& supplies); - -// Before a trainer's battle, once the items are used: the nurse for HP -// not green (no Potion left to heal it), a status no item cured, or -// attacks low on PP. Yellow HP counts (console B, 2026-11-03: 17/55 HP -// and no Potion into Miguel's battle, which only red would have stopped). -bool nurse_before_battle(const Supplies& supplies); // Type of battle engagement strategy. enum class BattleKind{ @@ -126,28 +58,6 @@ enum class BattleEnd{ LOST, }; -// How many of `item` (a slug) the bag holds, as far as known. -int item_count(const Supplies& supplies, const std::string& item); - -// The row (from 0) of `item` in the Items pocket, or -1 if none is left. -// Items the story doesn't count, such as a MOON STONE, take rows too. -int item_row(const Supplies& supplies, const std::string& item); - -// Sets the counts and the pocket's order from the Items pocket as read. -// A row whose count couldn't be read still holds at least one: it keeps -// the count known before (the order bought), or 1. Returns those rows' -// items, for the log. -std::vector set_from_bag(Supplies& supplies, const std::vector& rows); - -// After a save is loaded: the Items pocket as read, taken into `supplies` -// and `saved` (what a reload restores) in place of the row's counts, as -// set_from_bag() does. With nothing read both keep the row's. Returns the -// items whose count couldn't be read. -std::vector set_from_loaded_bag(Supplies& supplies, Supplies& saved, const std::vector& rows); - -// From the overworld: opens the Items pocket, reads it, and closes the -// bag again. Empty if nothing could be read. -std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context, Language language); // What the HP bar (read_player_hp_bar()) and the status badge of the @@ -184,14 +94,6 @@ BattleEnd fight_battle( ); -// From the overworld, after a battle: an Antidote for PSN, a Parlyz Heal -// for PAR, then a Potion if the HP bar wasn't green, each if one is left. -// The bag's inputs are not checked on the console yet. -void recover_after_battle( - ConsoleHandle& console, ProControllerContext& context, - Supplies& supplies, Pokemon::StoryCheckLevel checks, Language language -); - // The interrupts for walking story routes. Wild battles are run from, or // fought if `fight_wild`. A message is advanced until the overworld is diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp index 34a2a1e90e..1f9db71d35 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp @@ -120,19 +120,6 @@ const Table& species(){ return SPECIES; } -// The type chart's rows in its order: (attack, defend, tenths). -const std::vector>& chart_rows(){ - static const std::vector> ROWS = []{ - std::vector> rows; - for (const JsonValue& value : file_json("type_chart").to_array_throw()){ - const JsonArray& entry = value.to_array_throw(); - rows.emplace_back(type_of(entry[0]), type_of(entry[1]), static_cast(entry[2].to_integer_throw())); - } - return rows; - }(); - return ROWS; -} - std::vector strings_of(const JsonValue& value){ std::vector strings; for (const JsonValue& item : value.to_array_throw()){ @@ -221,22 +208,6 @@ size_t type_effectiveness(PokemonType attack, PokemonType defend){ return it == CHART.end() ? 10 : it->second; } -std::vector type_multipliers(PokemonType attack, PokemonType first, PokemonType second){ - std::vector multipliers; - for (const auto& [row_attack, defend, tenths] : chart_rows()){ - if (row_attack != attack){ - continue; - } - if (defend == first){ - multipliers.push_back(tenths); - } - if (defend == second && first != second){ - multipliers.push_back(tenths); - } - } - return multipliers; -} - bool special_type(PokemonType type){ switch (type){ case PokemonType::FIRE: diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h index 379a9f3e25..39822363d2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h @@ -31,77 +31,13 @@ #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "CommonFramework/Language.h" #include "Pokemon/Pokemon_Types.h" +#include "PokemonFRLG_AutoStoryStoryTrainers.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Type enum imported from Pokemon navigation. -using Pokemon::PokemonType; - -// Data attributes of a battle move. -struct MoveData{ - // Moves whose damage doesn't come from their power (Flail, Dragon - // Rage) have 1; moves that do no damage 0. - uint8_t power = 0; - // NONE for Curse's "???". - PokemonType type = PokemonType::NONE; - uint8_t pp = 0; - // In percent; 0 never misses. - uint8_t accuracy = 0; - int8_t priority = 0; - // pret's EFFECT_X as a slug: "hit", "flinch-hit", "sleep", - // "attack-down", "dragon-rage". - std::string effect = {}; - // The secondary effect's chance in percent (Bite's flinch: 30). - uint8_t effect_chance = 0; -}; - -// The base stats, in the game's order. -struct BaseStats{ - uint8_t hp = 0; - uint8_t attack = 0; - uint8_t defense = 0; - uint8_t sp_attack = 0; - uint8_t sp_defense = 0; - uint8_t speed = 0; -}; - -// Species battle base attributes and typing. -struct SpeciesData{ - // The same type twice for a species with one. - PokemonType first = PokemonType::NONE; - PokemonType second = PokemonType::NONE; - BaseStats base = {}; -}; - -// A trainer party Pokemon entry. -struct TrainerMon{ - std::string species; - uint8_t level = 0; - // pret's iv, 0 to 255: every IV is iv * 31 / 255 (CreateNPCTrainerParty). - uint8_t iv = 0; - // The nature's index (0 Hardy, 1 Lonely, ... 24 Quirky): the one the - // game's personality gives it (see frlg_battle_data.py). - uint8_t nature = 0; - // The moves the party gives it, else the level-up moves the game gives. - std::vector moves; -}; - -// Trainer AI flags and team definition. -struct TrainerData{ - // pret's AI flags as slugs: "check-bad-move", "try-to-faint", ... - std::vector ai = {}; - // The items the trainer can use, in order, each once ("super-potion"). - std::vector items = {}; - std::vector party = {}; -}; - -// None for a move or species the data doesn't have. -const MoveData* move_data(std::string_view move); -// Base stats and typing for species; nullptr if unknown. -const SpeciesData* species_data(std::string_view species); // Every species, for reading a wild Pokemon's name. const std::set& battle_species(); @@ -115,52 +51,6 @@ std::vector wild_foes(std::string_view species); // wild_foes() takes it. Logs what it read. std::vector read_wild_foes(Logger& logger, Language language, const ImageViewRGB32& screen); -// How well `attack` hits `defend`, in tenths: 20 is 2x, 5 is 0.5x. -size_t type_effectiveness(PokemonType attack, PokemonType defend); - -// The multipliers (in tenths) a move of type `attack` meets on a Pokemon -// of types `first` and `second`, in the type chart's order, as the game -// applies them one after another (pret Cmd_typecalc); none for 1x. -std::vector type_multipliers(PokemonType attack, PokemonType first, PokemonType second); - -// Gen 3 splits physical and special by type: Fire, Water, Grass, -// Electric, Psychic, Ice, Dragon and Dark are special. -bool special_type(PokemonType type); - -// A trainer's party in order; empty for a trainer the data doesn't have. -std::vector trainer_mons(std::string_view trainer); - -// A trainer's AI flags, items and party; none for one the data doesn't have. -std::optional trainer_data(std::string_view trainer); - -// The Pokemon a trainer's battle shows on `screen`, a battle menu: the -// name its HP box shows (WildEncounterReader), among `party`'s species. -// Empty if not read. Logs what it read. -std::string read_trainer_foe(Logger& logger, Language language, const ImageViewRGB32& screen, const std::vector& party); - -// The trainer the story's battle step `battle` fights on `map` (the map -// it leaves the player on). None for a battle the table doesn't name. -std::optional story_trainer(std::string_view map, std::string_view battle); - -// How carefully a battle step is fought. -enum class BattleRisk{ - // The move with the best expected damage against the foe out. - LOW, - // The battles the simulation's plan is for (the rival, gym leaders, - // bosses); fought as LOW until the checkpoint carries a plan. - HIGH, -}; -// String representation of battle risk level. -std::string_view battle_risk_name(BattleRisk risk); - -// A trainer's risk by its kind: HIGH for the rival, gym leaders, bosses -// (Giovanni, the Rocket admins), the Elite Four and the Champion; LOW -// for the rest. -BattleRisk default_battle_risk(std::string_view trainer); - -// The risk of the story's battle step `battle` on `map`: its table row's, -// else its trainer's default. LOW for a battle the table doesn't name. -BattleRisk story_battle_risk(std::string_view map, std::string_view battle); // (name, JSON text) of each file in BattleData/, sorted by name. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h index e8de3d3882..2d4c0730ff 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h @@ -27,72 +27,13 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "PokemonFRLG_AutoStoryBattle.h" #include "PokemonFRLG_AutoStoryParty.h" +#include "PokemonFRLG_AutoStoryBattleTurns.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ -// High-level action chosen for a battle turn. -enum class TurnChoice{ - RUN, - POTION, - ANTIDOTE, - MOVE, -}; - -// Decided battle action including slot or item index. -struct TurnAction{ - TurnChoice choice = TurnChoice::MOVE; - // For MOVE, the move list's slot. - size_t slot = BOTTOM_LEFT_MOVE; -}; - -// What came of a TurnAction. -enum class TurnResult{ - DONE, - // An item not used (another item in its row), or a move the game said - // has no PP left. - NOT_DONE, - // The game turned the move down although it has PP left: a foe's - // Disable (console B, 2026-11-03, Mt. Moon: Miguel's Grimer disabled - // Water Gun, and the loop chose it 17 more times while no turn passed). - // Its PP comes back, and it isn't chosen for as long as Disable can - // last (pret: 2 to 5 turns). - REFUSED, -}; - -// Binary prompt decision. -enum class YesNo{ - YES, - NO, -}; - -// A battle screen as the loop reads it, for the evolution check. -struct BattleTextScreen{ - // The battle's text box. - bool text_box = false; - // The battle menu or an HP box. - bool hp_box = false; - // The text waits for a button. - bool arrow = false; - // A YES/NO box. - bool yes_no = false; -}; - -// Answer to an in-battle prompt dialogue. -struct PromptAnswer{ - YesNo answer = YesNo::NO; - // After YES to "Delete a move?": the slot to forget on the move list - // that opens, its cursor on the top move. - std::optional forget_slot = {}; - // With forget_slot: the lead once the move is learned, to keep only if - // the move list opened (console B, 2026-11-03: a YES/NO read where no - // move list followed was taken as Bite over Tail Whip, and the loop - // later chose Tail Whip for Bite). - std::optional learned = {}; -}; - // State machine deciding turn choices and prompt answers in battles. class BattleDecisions{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h new file mode 100644 index 0000000000..4de3040e02 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h @@ -0,0 +1,92 @@ +/* AutoStory Battle Turns + * + * From: https://github.com/PokemonAutomation/ + * + * What the battle loop decides each turn and at each prompt: the turn's + * choice and what came of it, and the answer to a YES/NO. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattleTurns_H +#define PokemonAutomation_PokemonFRLG_AutoStoryBattleTurns_H + +#include +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryParty.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// High-level action chosen for a battle turn. +enum class TurnChoice{ + RUN, + POTION, + ANTIDOTE, + MOVE, +}; + +// Decided battle action including slot or item index. +struct TurnAction{ + TurnChoice choice = TurnChoice::MOVE; + // For MOVE, the move list's slot. + size_t slot = BOTTOM_LEFT_MOVE; +}; + +// What came of a TurnAction. +enum class TurnResult{ + DONE, + // An item not used (another item in its row), or a move the game said + // has no PP left. + NOT_DONE, + // The game turned the move down although it has PP left: a foe's + // Disable (console B, 2026-11-03, Mt. Moon: Miguel's Grimer disabled + // Water Gun, and the loop chose it 17 more times while no turn passed). + // Its PP comes back, and it isn't chosen for as long as Disable can + // last (pret: 2 to 5 turns). + REFUSED, +}; + +// Binary prompt decision. +enum class YesNo{ + YES, + NO, +}; + +// A battle screen as the loop reads it, for the evolution check. +struct BattleTextScreen{ + // The battle's text box. + bool text_box = false; + // The battle menu or an HP box. + bool hp_box = false; + // The text waits for a button. + bool arrow = false; + // A YES/NO box. + bool yes_no = false; +}; + +// Answer to an in-battle prompt dialogue. +struct PromptAnswer{ + YesNo answer = YesNo::NO; + // After YES to "Delete a move?": the slot to forget on the move list + // that opens, its cursor on the top move. + std::optional forget_slot = {}; + // With forget_slot: the lead once the move is learned, to keep only if + // the move list opened (console B, 2026-11-03: a YES/NO read where no + // move list followed was taken as Bite over Tail Whip, and the loop + // later chose Tail Whip for Bite). + std::optional learned = {}; +}; + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCheckpoints.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCheckpoints.h new file mode 100644 index 0000000000..f7e1c14774 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCheckpoints.h @@ -0,0 +1,67 @@ +/* AutoStory Checkpoints + * + * From: https://github.com/PokemonAutomation/ + * + * FRLG's story checkpoint, and the fixed routes, wall turns and mart + * orders its rows are built from. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryCheckpoints_H +#define PokemonAutomation_PokemonFRLG_AutoStoryCheckpoints_H + +#include +#include +#include +#include +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryEvents.h" +#include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryStartFrames.h" +#include "PokemonFRLG_AutoStoryStepInterrupts.h" +#include "PokemonFRLG_AutoStoryStepTable.h" +#include "PokemonFRLG_AutoStorySaveChecks.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// A shared checkpoint with what FRLG adds to it. +struct StoryCheckpoint : public Pokemon::StoryCheckpoint{ + // The healing items at its start, for a run that loads its save. + Supplies supplies; + // The START menu at its end, when it saves. + StartMenu menu = StartMenu::FULL; +}; +// `legs` from `start` as route steps for the walker, each checked against +// the map: nothing if a step is blocked or leaves the map. A leg ends "to +// wall" if the next step its way is blocked. +std::optional> fixed_route( + const std::vector& maps, const MapPosition& start, const std::vector& legs +); + +// A way the player at `tile` can turn to without stepping: a wall there, +// with no one standing in it. West and east first: walking north or south +// into a sign would read it. +std::optional wall_beside(const MapData& map, const TilePos& tile); + +// `items` as orders at the Viridian Mart before the Boulder Badge: the +// rows of POKE BALL, POTION, ANTIDOTE, PARLYZ HEAL. Nothing if it does +// not sell one of them. +std::optional> viridian_mart_orders(const std::vector& items); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index d9f357e718..d05392c2ea 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -38,101 +38,13 @@ #include "PokemonFRLG_AutoStoryStartFrames.h" #include "PokemonFRLG_AutoStoryStepInterrupts.h" #include "PokemonFRLG_AutoStoryStepTable.h" +#include "PokemonFRLG_AutoStoryCheckpoints.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Story leg definition imported from Pokemon AutoStory. -using Pokemon::StoryLeg; -// Story step definition imported from Pokemon AutoStory. -using Pokemon::StoryStep; -// Story step kind classification imported from Pokemon AutoStory. -using Pokemon::StoryStepKind; - -// Where the player stands and faces: the one-tile poses of FRLG's table -// and routes. An unknown facing (after a scene that turns the player) is -// set before the next route by turning to a wall. -struct StoryPose{ - std::string map; - TilePos tile; - std::optional facing; -}; - -// The variant of a ROUTE or LEGS step that runs, with B held: the player -// has the Running Shoes (00.10 on). -inline const std::string RUN_VARIANT = "run"; - -// How `step`, a ROUTE or LEGS, moves the player: RUN_VARIANT runs. -MoveSpeed move_speed(const StoryStep& step); - - -// A shared checkpoint with what FRLG adds to it. -struct StoryCheckpoint : public Pokemon::StoryCheckpoint{ - // The healing items at its start, for a run that loads its save. - Supplies supplies; - // The START menu at its end, when it saves. - StartMenu menu = StartMenu::FULL; -}; - - -// The maps the story plans on: every map to Brock, with the objects the -// game hides after the Hall of Fame removed, as the lab's frlg_route does. -const std::vector& story_maps(); - -// Converts a StoryPose to a general navigation Pose. -Pokemon::Pose to_pose(const StoryPose& pose); -// `pose` as a StoryPose: nothing unless it is on one tile. -std::optional story_pose(const Pokemon::Pose& pose); - -// The place the save card names for a save on `map` (see -// read_save_card_location()), or empty for a map whose place isn't known. -std::string save_card_place(const std::string& map); - -// Why a save whose card names `place` can't start a checkpoint that starts -// on `start_map`, or empty if it can: the places match, the card couldn't -// be read (empty `place`), or the map has no known place. -std::string save_place_error(const std::string& start_map, const std::string& place); - -// Why a save standing at `stands` can't start a checkpoint that starts at -// `start`, or empty if it can: the same map and tile, and the same facing -// when both are known. -std::string start_pose_mismatch(const Pokemon::Pose& start, const StoryPose& stands); - -// Where the save just loaded stands, as the game reads it: nothing when it -// can't be read. -using SavePoseReader = std::function()>; -// Where the start check says what it found. -using StoryLog = std::function; - -// Adds to `checkpoint`, built from a row that starts at `start`, the start -// check: the save it starts from, as `read` reads it, must stand there -// (start_pose_mismatch()), or the checkpoint stops before its first event, -// "start_failed". A save that can't be read passes. `log` gets a -// mismatch, or that nothing was read. A row with no start (a new game) -// gets none. (add_start_check() with a reader of the tile.) -void add_start_pose_check( - Pokemon::Checkpoint& checkpoint, const std::optional& start, SavePoseReader read, StoryLog log -); - -// `legs` from `start` as route steps for the walker, each checked against -// the map: nothing if a step is blocked or leaves the map. A leg ends "to -// wall" if the next step its way is blocked. -std::optional> fixed_route( - const std::vector& maps, const MapPosition& start, const std::vector& legs -); - -// A way the player at `tile` can turn to without stepping: a wall there, -// with no one standing in it. West and east first: walking north or south -// into a sign would read it. -std::optional wall_beside(const MapData& map, const TilePos& tile); - -// `items` as orders at the Viridian Mart before the Boulder Badge: the -// rows of POKE BALL, POTION, ANTIDOTE, PARLYZ HEAL. Nothing if it does -// not sell one of them. -std::optional> viridian_mart_orders(const std::vector& items); - // What the story's events act on. `supplies` are what the bag holds now, // `saved_supplies` what the last save holds. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryIntro.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryIntro.h new file mode 100644 index 0000000000..735cc17aa6 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryIntro.h @@ -0,0 +1,71 @@ +/* AutoStory Intro + * + * From: https://github.com/PokemonAutomation/ + * + * The new game's intro: what it asks about the names, and the intro + * played from the title screen to the bedroom. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryIntro_H +#define PokemonAutomation_PokemonFRLG_AutoStoryIntro_H + +#include +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "CommonFramework/Language.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonFRLG_AutoStoryPresses.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The arrow's row on Oak's list of rival names (NEW NAME, then four preset +// names), if the list shows. In pokefirered's oak_speech.c the list is a +// 12x10-tile window at tile (2, 2), rows 16 px apart, the cursor starting +// on NEW NAME. The intro's YES/NO boxes open in the same corner but are +// 6x4 tiles: the list is told from them by its white past their frame. +std::optional rival_name_list_cursor(const ImageViewRGB32& screen); + +// What shows in the new game's intro, as far as the names go. +enum class IntroNameScreen{ + OTHER, + KEYBOARD, + RIVAL_LIST, +}; +// What the new game's intro does about the names. The player's name is +// asked on a keyboard, always first; the rival's on the name list, where +// the first preset name is picked, as SID Helper does. A keyboard after +// the player's is the rival's, opened because the list was missed. +enum class IntroNameStep{ + NONE, + PLAYER_KEYBOARD, + RIVAL_PRESET, + RIVAL_KEYBOARD, +}; +// A preset picked returns to the list only after NO on "Er, was it ...?", +// so after this many picks A opens the keyboard instead. +constexpr size_t RIVAL_PRESET_TRIES = 3; +// Determines the next input step in character/rival naming sequence. +IntroNameStep intro_name_step(IntroNameScreen screen, size_t keyboards_seen, size_t presets_picked); +// From the title screen of a game with no save, to the bedroom: the +// controls pages, Oak's speech, BOY, the default name for the player (an +// empty name confirmed) and the rival's first preset name. Returns on the +// overworld. +void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.h new file mode 100644 index 0000000000..d61e0daf35 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.h @@ -0,0 +1,68 @@ +/* AutoStory Items Pocket + * + * From: https://github.com/PokemonAutomation/ + * + * The Items pocket as the story counts it: rows and counts, read from + * the bag, and the items used after a battle. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryItemsPocket_H +#define PokemonAutomation_PokemonFRLG_AutoStoryItemsPocket_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattleData.h" +#include "PokemonFRLG_AutoStoryParty.h" +#include "PokemonFRLG_AutoStorySupplies.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// How many of `item` (a slug) the bag holds, as far as known. +int item_count(const Supplies& supplies, const std::string& item); + +// The row (from 0) of `item` in the Items pocket, or -1 if none is left. +// Items the story doesn't count, such as a MOON STONE, take rows too. +int item_row(const Supplies& supplies, const std::string& item); + +// Sets the counts and the pocket's order from the Items pocket as read. +// A row whose count couldn't be read still holds at least one: it keeps +// the count known before (the order bought), or 1. Returns those rows' +// items, for the log. +std::vector set_from_bag(Supplies& supplies, const std::vector& rows); + +// After a save is loaded: the Items pocket as read, taken into `supplies` +// and `saved` (what a reload restores) in place of the row's counts, as +// set_from_bag() does. With nothing read both keep the row's. Returns the +// items whose count couldn't be read. +std::vector set_from_loaded_bag(Supplies& supplies, Supplies& saved, const std::vector& rows); + +// From the overworld: opens the Items pocket, reads it, and closes the +// bag again. Empty if nothing could be read. +std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context, Language language); +// From the overworld, after a battle: an Antidote for PSN, a Parlyz Heal +// for PAR, then a Potion if the HP bar wasn't green, each if one is left. +// The bag's inputs are not checked on the console yet. +void recover_after_battle( + ConsoleHandle& console, ProControllerContext& context, + Supplies& supplies, Pokemon::StoryCheckLevel checks, Language language +); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLevelUps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLevelUps.h new file mode 100644 index 0000000000..e157d1f414 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLevelUps.h @@ -0,0 +1,56 @@ +/* AutoStory Level Ups + * + * From: https://github.com/PokemonAutomation/ + * + * What a level up brings: an evolution by level, and the answer to + * "Delete a move to make room for ...?". + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryLevelUps_H +#define PokemonAutomation_PokemonFRLG_AutoStoryLevelUps_H + +#include +#include +#include +#include +#include +#include +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" +#include "PokemonFRLG_AutoStoryStats.h" +#include "PokemonFRLG_AutoStoryPartyMember.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The species `species` evolves into by level, and at which level. +struct LevelEvolution{ + std::string_view into; + uint8_t level = 0; +}; +// Level-up evolution target if species evolves by level. +std::optional level_evolution(std::string_view species); +// The answer to "Delete a move to make room for ?". +struct LearnDecision{ + // The move offered, if the table knows which one it is. + std::optional move = {}; + // The slot to forget for it, or none to keep the moves as they are. + std::optional forget_slot = {}; +}; + +// At "Delete a move to make room for ...?": takes in the moves learned +// into free slots since the last prompt, decides on the move offered, and +// leaves `member` as that answer will. +LearnDecision learn_move(PartyMember& member); + +// The lead evolved: its species becomes what it evolves into. +void evolve(PartyMember& member); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMoveData.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMoveData.h new file mode 100644 index 0000000000..a96840949f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMoveData.h @@ -0,0 +1,86 @@ +/* AutoStory Move Data + * + * From: https://github.com/PokemonAutomation/ + * + * Moves, species and the type chart, as pret/pokefirered has them + * (BattleData/moves.json, species.json, type_chart.json). + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryMoveData_H +#define PokemonAutomation_PokemonFRLG_AutoStoryMoveData_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" +#include "Pokemon/Pokemon_Types.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Type enum imported from Pokemon navigation. +using Pokemon::PokemonType; + +// Data attributes of a battle move. +struct MoveData{ + // Moves whose damage doesn't come from their power (Flail, Dragon + // Rage) have 1; moves that do no damage 0. + uint8_t power = 0; + // NONE for Curse's "???". + PokemonType type = PokemonType::NONE; + uint8_t pp = 0; + // In percent; 0 never misses. + uint8_t accuracy = 0; + int8_t priority = 0; + // pret's EFFECT_X as a slug: "hit", "flinch-hit", "sleep", + // "attack-down", "dragon-rage". + std::string effect = {}; + // The secondary effect's chance in percent (Bite's flinch: 30). + uint8_t effect_chance = 0; +}; + +// The base stats, in the game's order. +struct BaseStats{ + uint8_t hp = 0; + uint8_t attack = 0; + uint8_t defense = 0; + uint8_t sp_attack = 0; + uint8_t sp_defense = 0; + uint8_t speed = 0; +}; + +// Species battle base attributes and typing. +struct SpeciesData{ + // The same type twice for a species with one. + PokemonType first = PokemonType::NONE; + PokemonType second = PokemonType::NONE; + BaseStats base = {}; +}; +// None for a move or species the data doesn't have. +const MoveData* move_data(std::string_view move); +// Base stats and typing for species; nullptr if unknown. +const SpeciesData* species_data(std::string_view species); +// How well `attack` hits `defend`, in tenths: 20 is 2x, 5 is 0.5x. +size_t type_effectiveness(PokemonType attack, PokemonType defend); + +// Gen 3 splits physical and special by type: Fire, Water, Grass, +// Electric, Psychic, Ice, Dragon and Dark are special. +bool special_type(PokemonType type); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryNewMembers.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryNewMembers.h new file mode 100644 index 0000000000..0afbbafe9a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryNewMembers.h @@ -0,0 +1,55 @@ +/* AutoStory New Members + * + * From: https://github.com/PokemonAutomation/ + * + * A party member as the game gives it, as the story grows it, or as its + * summary shows it. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryNewMembers_H +#define PokemonAutomation_PokemonFRLG_AutoStoryNewMembers_H + +#include +#include +#include +#include +#include +#include +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" +#include "PokemonFRLG_AutoStoryStats.h" +#include "PokemonFRLG_AutoStoryLevelUps.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// As the game gives `species` at `level` (a starter, a gift): its last four +// level-up moves up to `level`, at full PP. +PartyMember new_member(std::string_view species, uint8_t level); + +// The member as the story plays it up to `level`: each level-up move is +// learned into a free slot or answered as learn_move() says, and it +// evolves at its level. For the rows that start after a part of the story. +PartyMember grown_to(PartyMember member, uint8_t level); + +// Squirtle as the story leaves it after Brock (Lv13, Water Gun offered). +PartyMember story_lead_after_brock(); + +// `species` at `level` with `moves` as its summary shows them, in slot +// order, and its `stats` if POKEMON SKILLS was read. A PP that wasn't +// read is taken as half the move's full PP: the game draws the PP in +// color from half down (pokefirered pokemon_summary_screen.c), which the +// reader may not read. +PartyMember member_from_summary( + std::string_view species, uint8_t level, const std::vector& moves, + const std::optional& stats = std::nullopt +); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h index 9111f48d52..95ea011756 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h @@ -33,104 +33,13 @@ #include #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" #include "PokemonFRLG_AutoStoryStats.h" +#include "PokemonFRLG_AutoStoryNewMembers.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ -// The move slots, in the order of the battle's move list and the summary. -inline constexpr size_t TOP_LEFT_MOVE = 0; -// Move slot index for bottom-left move. -inline constexpr size_t BOTTOM_LEFT_MOVE = 2; -// Maximum number of moves a Pokemon can know. -inline constexpr size_t MAX_MOVES = 4; - -// A move the lead knows, by slug ("water-gun"), and the PP the story -// counts left. -struct KnownMove{ - std::string move; - uint8_t pp = 0; -}; - -// Party member Pokemon status and learned moves. -struct PartyMember{ - std::string species; - // In slot order. Fewer than four while moves learned into free slots - // haven't been taken in yet (see the top of this file). - std::vector moves; - // The level of the last level-up move offered to it, learned or not. - uint8_t moves_through_level = 0; - // The moves were read off its summary: they are all it knows, even - // fewer than four. - bool moves_read = false; - // Its level as its summary showed it, 0 if not read. Level-ups since - // aren't seen: battle_level() takes the higher of this and - // moves_through_level. - uint8_t level = {}; - // Its stats as POKEMON SKILLS showed them at `level`, as this - // species; none if not read, or once it evolves. - std::optional stats = {}; -}; - -// The level the story takes for `member`: its level, or the level its -// moves were grown through if that is higher. -uint8_t battle_level(const PartyMember& member); - -// The species `species` evolves into by level, and at which level. -struct LevelEvolution{ - std::string_view into; - uint8_t level = 0; -}; -// Level-up evolution target if species evolves by level. -std::optional level_evolution(std::string_view species); - -// A move's full PP; 0 for a move the table doesn't have. -uint8_t max_pp(std::string_view move); - -// A move's power; 0 for one that does no damage, or that the table -// doesn't have. -uint8_t move_power(std::string_view move); - -// As the game gives `species` at `level` (a starter, a gift): its last four -// level-up moves up to `level`, at full PP. -PartyMember new_member(std::string_view species, uint8_t level); - -// The member as the story plays it up to `level`: each level-up move is -// learned into a free slot or answered as learn_move() says, and it -// evolves at its level. For the rows that start after a part of the story. -PartyMember grown_to(PartyMember member, uint8_t level); - -// Squirtle as the story leaves it after Brock (Lv13, Water Gun offered). -PartyMember story_lead_after_brock(); - -// `species` at `level` with `moves` as its summary shows them, in slot -// order, and its `stats` if POKEMON SKILLS was read. A PP that wasn't -// read is taken as half the move's full PP: the game draws the PP in -// color from half down (pokefirered pokemon_summary_screen.c), which the -// reader may not read. -PartyMember member_from_summary( - std::string_view species, uint8_t level, const std::vector& moves, - const std::optional& stats = std::nullopt -); - - -// The answer to "Delete a move to make room for ?". -struct LearnDecision{ - // The move offered, if the table knows which one it is. - std::optional move = {}; - // The slot to forget for it, or none to keep the moves as they are. - std::optional forget_slot = {}; -}; - -// At "Delete a move to make room for ...?": takes in the moves learned -// into free slots since the last prompt, decides on the move offered, and -// leaves `member` as that answer will. -LearnDecision learn_move(PartyMember& member); - -// The lead evolved: its species becomes what it evolves into. -void evolve(PartyMember& member); - // The slot to attack with: the first of the plan's attacks for its line // that it knows with PP left, else its strongest damaging move with PP diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPartyMember.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPartyMember.h new file mode 100644 index 0000000000..0751cfcf68 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPartyMember.h @@ -0,0 +1,76 @@ +/* AutoStory Party Member + * + * From: https://github.com/PokemonAutomation/ + * + * A party member as the story knows it: species, level, moves and their + * PP, and the moves' full PP and power. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryPartyMember_H +#define PokemonAutomation_PokemonFRLG_AutoStoryPartyMember_H + +#include +#include +#include +#include +#include +#include +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" +#include "PokemonFRLG_AutoStoryStats.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The move slots, in the order of the battle's move list and the summary. +inline constexpr size_t TOP_LEFT_MOVE = 0; +// Move slot index for bottom-left move. +inline constexpr size_t BOTTOM_LEFT_MOVE = 2; +// Maximum number of moves a Pokemon can know. +inline constexpr size_t MAX_MOVES = 4; + +// A move the lead knows, by slug ("water-gun"), and the PP the story +// counts left. +struct KnownMove{ + std::string move; + uint8_t pp = 0; +}; + +// Party member Pokemon status and learned moves. +struct PartyMember{ + std::string species; + // In slot order. Fewer than four while moves learned into free slots + // haven't been taken in yet (see the top of this file). + std::vector moves; + // The level of the last level-up move offered to it, learned or not. + uint8_t moves_through_level = 0; + // The moves were read off its summary: they are all it knows, even + // fewer than four. + bool moves_read = false; + // Its level as its summary showed it, 0 if not read. Level-ups since + // aren't seen: battle_level() takes the higher of this and + // moves_through_level. + uint8_t level = {}; + // Its stats as POKEMON SKILLS showed them at `level`, as this + // species; none if not read, or once it evolves. + std::optional stats = {}; +}; + +// The level the story takes for `member`: its level, or the level its +// moves were grown through if that is higher. +uint8_t battle_level(const PartyMember& member); +// A move's full PP; 0 for a move the table doesn't have. +uint8_t max_pp(std::string_view move); + +// A move's power; 0 for one that does no damage, or that the table +// doesn't have. +uint8_t move_power(std::string_view move); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPoses.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPoses.h new file mode 100644 index 0000000000..553ac917bc --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPoses.h @@ -0,0 +1,73 @@ +/* AutoStory Poses + * + * From: https://github.com/PokemonAutomation/ + * + * Where the story stands and how fast it moves: its poses, the maps it + * plans on, and the run variant. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryPoses_H +#define PokemonAutomation_PokemonFRLG_AutoStoryPoses_H + +#include +#include +#include +#include +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryEvents.h" +#include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryStartFrames.h" +#include "PokemonFRLG_AutoStoryStepInterrupts.h" +#include "PokemonFRLG_AutoStoryStepTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Story leg definition imported from Pokemon AutoStory. +using Pokemon::StoryLeg; +// Story step definition imported from Pokemon AutoStory. +using Pokemon::StoryStep; +// Story step kind classification imported from Pokemon AutoStory. +using Pokemon::StoryStepKind; + +// Where the player stands and faces: the one-tile poses of FRLG's table +// and routes. An unknown facing (after a scene that turns the player) is +// set before the next route by turning to a wall. +struct StoryPose{ + std::string map; + TilePos tile; + std::optional facing; +}; + +// The variant of a ROUTE or LEGS step that runs, with B held: the player +// has the Running Shoes (00.10 on). +inline const std::string RUN_VARIANT = "run"; + +// How `step`, a ROUTE or LEGS, moves the player: RUN_VARIANT runs. +MoveSpeed move_speed(const StoryStep& step); +// The maps the story plans on: every map to Brock, with the objects the +// game hides after the Hall of Fame removed, as the lab's frlg_route does. +const std::vector& story_maps(); + +// Converts a StoryPose to a general navigation Pose. +Pokemon::Pose to_pose(const StoryPose& pose); +// `pose` as a StoryPose: nothing unless it is on one tile. +std::optional story_pose(const Pokemon::Pose& pose); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPresses.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPresses.h new file mode 100644 index 0000000000..3d3a79aa7f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPresses.h @@ -0,0 +1,66 @@ +/* AutoStory Presses + * + * From: https://github.com/PokemonAutomation/ + * + * The story's basic presses: text advanced to its end, a YES/NO read + * and answered, a step onto a trigger and a turn to a wall. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryPresses_H +#define PokemonAutomation_PokemonFRLG_AutoStoryPresses_H + +#include +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "CommonFramework/Language.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonFRLG_AutoStoryStartMenu.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Which row of the standard YES/NO box the arrow is on (true: YES), if +// one shows. +std::optional yes_no_cursor(const ImageViewRGB32& screen); +// Expected screen state when dialogue text finishes. +enum class TextEnd{ + OVERWORLD, + BATTLE, +}; + +// Presses B until the overworld is back or, if `stop_at_battle`, a battle +// shows. Throws OperationFailedException after `timeout`. +TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout, bool stop_at_battle); + +// advance_text() to the overworld. +void mash_until_overworld(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout); + +// Advances text with `advance` until a YES/NO shows, then answers it. B +// answers NO. Throws OperationFailedException after `timeout`. +void answer_yes_no(ConsoleHandle& console, ProControllerContext& context, bool yes, Button advance, Milliseconds timeout); + +// From the overworld: one step `direction`, onto a trigger or into a door. +// `facing` is the way the player faces, if known; a player facing another +// way is turned first. +void step_once(ProControllerContext& context, Pokemon::Direction direction, std::optional facing); + +// From the overworld, turns to face `direction` without stepping: the +// player must have a wall that way. +void face_wall(ProControllerContext& context, Pokemon::Direction direction); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySave.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySave.h new file mode 100644 index 0000000000..784ad4579d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySave.h @@ -0,0 +1,91 @@ +/* AutoStory Save + * + * From: https://github.com/PokemonAutomation/ + * + * The save dialog as the story runs it, and the place the save card + * names. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStorySave_H +#define PokemonAutomation_PokemonFRLG_AutoStorySave_H + +#include +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "CommonFramework/Language.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonFRLG_AutoStoryIntro.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The save dialog after SAVE, as pokefirered's start_menu.c runs it: +// "Would you like to save the game?" YES/NO (YES first). Then, over a save +// of this game, "There is already a saved file. Is it okay to overwrite +// it?" YES/NO (YES first); over another game's save (a new game), "WARNING! +// There is a different game file that is already saved." on four pages, +// ending "...overwrite the other save file?" YES/NO with NO first. Then +// "SAVING... DON'T TURN OFF THE POWER.", "PLAYER saved the game." and, +// without a press, the overworld. NO at any YES/NO brings the START menu +// back; a failed save shows "Save error." and waits for A held. +enum class SaveScreen{ + YES_NO, + // A message with the arrow for the next page. + PAGED_TEXT, + // A message without an arrow: SAVING, or saved. + TEXT, + START_MENU, + // No message and no menu: the overworld, or a frame between two boxes. + NOTHING, +}; +// Action to perform in the save menu loop. +enum class SaveAction{ + WAIT, + ANSWER_YES, + NEXT_PAGE, + // Confirm the overworld (START opens the menu): the game is saved. + CHECK_OVERWORLD, + // The START menu is back: a YES/NO was answered NO. + FAIL_CANCELLED, + // A paged message after the last YES: "Save error." + FAIL_ERROR, +}; +// What save_game() does on each screen it reads after the save card's +// first YES/NO shows. Every YES/NO gets YES; B is never pressed. +class SaveDialog{ +public: + SaveAction next(SaveScreen screen); + +private: + bool m_paged_since_yes = false; + size_t m_nothing_seen = 0; +}; + +// From the overworld: SAVE, YES, and YES again to overwrite an older save +// (see SaveDialog). The menu's cursor is read, since the game remembers it +// and the menu grows. Returns to the overworld; throws +// OperationFailedException if the save wasn't made. +void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu menu); + +// From the overworld: the place the START menu's SAVE card names (see +// read_save_card_location()), then NO, back to the overworld. Empty if it +// can't be read. The menu's length is read, not assumed, so a save made +// with another START menu (another checkpoint's) is read too. +std::string read_save_place(ConsoleHandle& console, ProControllerContext& context, Language language); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySaveChecks.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySaveChecks.h new file mode 100644 index 0000000000..218cebb6c5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySaveChecks.h @@ -0,0 +1,73 @@ +/* AutoStory Save Checks + * + * From: https://github.com/PokemonAutomation/ + * + * Whether a loaded save starts a checkpoint: the save card's place and the + * pose the save stands at. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStorySaveChecks_H +#define PokemonAutomation_PokemonFRLG_AutoStorySaveChecks_H + +#include +#include +#include +#include +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryEvents.h" +#include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryStartFrames.h" +#include "PokemonFRLG_AutoStoryStepInterrupts.h" +#include "PokemonFRLG_AutoStoryStepTable.h" +#include "PokemonFRLG_AutoStoryPoses.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The place the save card names for a save on `map` (see +// read_save_card_location()), or empty for a map whose place isn't known. +std::string save_card_place(const std::string& map); + +// Why a save whose card names `place` can't start a checkpoint that starts +// on `start_map`, or empty if it can: the places match, the card couldn't +// be read (empty `place`), or the map has no known place. +std::string save_place_error(const std::string& start_map, const std::string& place); + +// Why a save standing at `stands` can't start a checkpoint that starts at +// `start`, or empty if it can: the same map and tile, and the same facing +// when both are known. +std::string start_pose_mismatch(const Pokemon::Pose& start, const StoryPose& stands); + +// Where the save just loaded stands, as the game reads it: nothing when it +// can't be read. +using SavePoseReader = std::function()>; +// Where the start check says what it found. +using StoryLog = std::function; + +// Adds to `checkpoint`, built from a row that starts at `start`, the start +// check: the save it starts from, as `read` reads it, must stand there +// (start_pose_mismatch()), or the checkpoint stops before its first event, +// "start_failed". A save that can't be read passes. `log` gets a +// mismatch, or that nothing was read. A row with no start (a new game) +// gets none. (add_start_check() with a reader of the tile.) +void add_start_pose_check( + Pokemon::Checkpoint& checkpoint, const std::optional& start, SavePoseReader read, StoryLog log +); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameCompare.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameCompare.h new file mode 100644 index 0000000000..0755595658 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameCompare.h @@ -0,0 +1,56 @@ +/* AutoStory Start Frame Compare + * + * From: https://github.com/PokemonAutomation/ + * + * A checkpoint start's frame as the start check keeps it, and how another + * frame differs from it. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryStartFrameCompare_H +#define PokemonAutomation_PokemonFRLG_AutoStoryStartFrameCompare_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryEvents.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The game screen as the start check keeps and compares it: the GBA's own +// 240x160 pixels, 15x10 tiles of 16. `game_screen` is the game's part of +// the frame (GameSettings' GAME_BOX). +ImageRGB32 start_frame(const ImageViewRGB32& game_screen); + +// How a frame differs from a checkpoint start's frame, tile by tile. +struct StartFrameDifference{ + size_t tiles = 0; + // The tiles whose pixels differ by more than an animated tile's do. + size_t changed = 0; +}; + +// The two frames, each scaled as start_frame() does, tile by tile. +StartFrameDifference compare_start_frames(const ImageViewRGB32& reference, const ImageViewRGB32& frame); + +// Whether the difference leaves the same place: few enough tiles changed +// for people who moved, too many for another place (see the .cpp). +bool same_start_place(const StartFrameDifference& difference); + +// "12 of 150 tiles changed". +std::string to_string(const StartFrameDifference& difference); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameStore.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameStore.h new file mode 100644 index 0000000000..c20800708b --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameStore.h @@ -0,0 +1,82 @@ +/* AutoStory Start Frame Store + * + * From: https://github.com/PokemonAutomation/ + * + * The start check on frames, and where the start frames are kept. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryStartFrameStore_H +#define PokemonAutomation_PokemonFRLG_AutoStoryStartFrameStore_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryEvents.h" +#include "PokemonFRLG_AutoStoryStartFrameCompare.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// What a start reader found about the save just loaded. +enum class StartFound{ + // It can't tell: the check passes. + NOT_READ, + AT_START, + ELSEWHERE, +}; +// A start reader's answer, with the line the start check logs for it. +struct StartRead{ + StartFound found = StartFound::NOT_READ; + // For the log: why nothing was read, or what was seen. + std::string detail = {}; +}; + +// The game screen now, as start_frame() makes it; an empty image when +// there is no video. Called again for each frame tried. +using StartFrameSource = std::function; + +// The start check on frames: up to `tries` frames from `next_frame` +// against `reference`, the first one that shows the same place +// (same_start_place()) passing, so a fade or a passer-by in front of the +// camera on one frame doesn't fail the check. No reference, or no video, +// is NOT_READ. +StartRead read_start_frames(const std::optional& reference, const StartFrameSource& next_frame, size_t tries); + + +// Where the start frames are kept: for each checkpoint, .png, the +// frame, and .json, the checkpoint, when it was kept and why. +class StartFrameStore{ +public: + // Keeps nothing and finds nothing (the simulation). + StartFrameStore() = default; + // `folder` ends with "/". + explicit StartFrameStore(std::string folder); + + // Replaces the frame kept for `checkpoint`; `source` says why it is kept. + // Returns false if it couldn't be written. + bool save(const std::string& checkpoint, const ImageViewRGB32& frame, const std::string& source) const; + // The frame kept for `checkpoint`, if any. + std::optional load(const std::string& checkpoint) const; + +private: + std::string m_folder; +}; + +// The program's store: USER_FILE_PATH()/PokemonFRLG/AutoStoryStartFrames/. +StartFrameStore program_start_frames(); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h index 9c2d4e25d2..479a2beee6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h @@ -27,83 +27,13 @@ #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "Pokemon/AutoStory/Pokemon_StoryEvents.h" +#include "PokemonFRLG_AutoStoryStartFrameStore.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ -// The game screen as the start check keeps and compares it: the GBA's own -// 240x160 pixels, 15x10 tiles of 16. `game_screen` is the game's part of -// the frame (GameSettings' GAME_BOX). -ImageRGB32 start_frame(const ImageViewRGB32& game_screen); - -// How a frame differs from a checkpoint start's frame, tile by tile. -struct StartFrameDifference{ - size_t tiles = 0; - // The tiles whose pixels differ by more than an animated tile's do. - size_t changed = 0; -}; - -// The two frames, each scaled as start_frame() does, tile by tile. -StartFrameDifference compare_start_frames(const ImageViewRGB32& reference, const ImageViewRGB32& frame); - -// Whether the difference leaves the same place: few enough tiles changed -// for people who moved, too many for another place (see the .cpp). -bool same_start_place(const StartFrameDifference& difference); - -// "12 of 150 tiles changed". -std::string to_string(const StartFrameDifference& difference); - - -// What a start reader found about the save just loaded. -enum class StartFound{ - // It can't tell: the check passes. - NOT_READ, - AT_START, - ELSEWHERE, -}; -// A start reader's answer, with the line the start check logs for it. -struct StartRead{ - StartFound found = StartFound::NOT_READ; - // For the log: why nothing was read, or what was seen. - std::string detail = {}; -}; - -// The game screen now, as start_frame() makes it; an empty image when -// there is no video. Called again for each frame tried. -using StartFrameSource = std::function; - -// The start check on frames: up to `tries` frames from `next_frame` -// against `reference`, the first one that shows the same place -// (same_start_place()) passing, so a fade or a passer-by in front of the -// camera on one frame doesn't fail the check. No reference, or no video, -// is NOT_READ. -StartRead read_start_frames(const std::optional& reference, const StartFrameSource& next_frame, size_t tries); - - -// Where the start frames are kept: for each checkpoint, .png, the -// frame, and .json, the checkpoint, when it was kept and why. -class StartFrameStore{ -public: - // Keeps nothing and finds nothing (the simulation). - StartFrameStore() = default; - // `folder` ends with "/". - explicit StartFrameStore(std::string folder); - - // Replaces the frame kept for `checkpoint`; `source` says why it is kept. - // Returns false if it couldn't be written. - bool save(const std::string& checkpoint, const ImageViewRGB32& frame, const std::string& source) const; - // The frame kept for `checkpoint`, if any. - std::optional load(const std::string& checkpoint) const; - -private: - std::string m_folder; -}; - -// The program's store: USER_FILE_PATH()/PokemonFRLG/AutoStoryStartFrames/. -StartFrameStore program_start_frames(); - // The game screen on the console now, as start_frame() makes it; empty // with no video. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartMenu.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartMenu.h new file mode 100644 index 0000000000..22d1ad5c1b --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartMenu.h @@ -0,0 +1,66 @@ +/* AutoStory Start Menu + * + * From: https://github.com/PokemonAutomation/ + * + * The START menu as the story grows it, whether the story checks the + * screen, and whether the overworld is up. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryStartMenu_H +#define PokemonAutomation_PokemonFRLG_AutoStoryStartMenu_H + +#include +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "CommonFramework/Language.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" +#include "Pokemon/Navigation/Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Whether the shared check level (Types/Pokemon_StoryCheckLevel.h, set by +// StoryRunOptions) has the story check the screen before and after it +// acts: DEFAULT and above (TESTING, THOROUGH). Then FRLG reads a Mart +// row's item before buying it, the bag's Items pocket after shopping (the +// counts the story then keeps), and an item's name in the bag before +// using it. FAST and SPEEDRUN trust the counts it keeps and the timings. +inline bool checks_screen(Pokemon::StoryCheckLevel level){ + return level <= Pokemon::StoryCheckLevel::DEFAULT; +} + +// The START menu as the story grows it. Before the starter: BAG, the +// player, SAVE, OPTION, EXIT; the starter adds POKEMON on top, the Pokedex +// POKEDEX above that. +enum class StartMenu{ + BEFORE_POKEMON, + BEFORE_POKEDEX, + FULL, +}; +// Total rows in the start menu. +int start_menu_rows(StartMenu menu); +// Row index of the SAVE option in the start menu. +int start_menu_save_row(StartMenu menu); +// Row index of the OPTION item in the start menu. +int start_menu_option_row(StartMenu menu); + + +// Whether the overworld is up: START opens the menu only there, with no +// scene running. If it opened, it is closed again. +bool overworld_shows(ConsoleHandle& console, ProControllerContext& context); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStoryTrainers.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStoryTrainers.h new file mode 100644 index 0000000000..ec7f9be1cb --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStoryTrainers.h @@ -0,0 +1,62 @@ +/* AutoStory Story Trainers + * + * From: https://github.com/PokemonAutomation/ + * + * Which trainer each of the story's battle steps fights, and how + * carefully (BattleRisk). + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryStoryTrainers_H +#define PokemonAutomation_PokemonFRLG_AutoStoryStoryTrainers_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" +#include "Pokemon/Pokemon_Types.h" +#include "PokemonFRLG_AutoStoryTrainerData.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The trainer the story's battle step `battle` fights on `map` (the map +// it leaves the player on). None for a battle the table doesn't name. +std::optional story_trainer(std::string_view map, std::string_view battle); + +// How carefully a battle step is fought. +enum class BattleRisk{ + // The move with the best expected damage against the foe out. + LOW, + // The battles the simulation's plan is for (the rival, gym leaders, + // bosses); fought as LOW until the checkpoint carries a plan. + HIGH, +}; +// String representation of battle risk level. +std::string_view battle_risk_name(BattleRisk risk); + +// A trainer's risk by its kind: HIGH for the rival, gym leaders, bosses +// (Giovanni, the Rocket admins), the Elite Four and the Champion; LOW +// for the rest. +BattleRisk default_battle_risk(std::string_view trainer); + +// The risk of the story's battle step `battle` on `map`: its table row's, +// else its trainer's default. LOW for a battle the table doesn't name. +BattleRisk story_battle_risk(std::string_view map, std::string_view battle); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h new file mode 100644 index 0000000000..47b38ae261 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h @@ -0,0 +1,107 @@ +/* AutoStory Supplies + * + * From: https://github.com/PokemonAutomation/ + * + * What the story carries into a battle: the healing items, the lead's + * status, HP and moves, and the foes it knows; and when to see the nurse. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStorySupplies_H +#define PokemonAutomation_PokemonFRLG_AutoStorySupplies_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattleData.h" +#include "PokemonFRLG_AutoStoryParty.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// A status condition, as far as the story treats them: the two it carries +// items for, and the rest, which only a nurse cures. +enum class StatusCondition{ + NONE, + POISON, + PARALYSIS, + OTHER, // SLP, BRN, FRZ +}; +// String representation of a status condition. +std::string_view status_name(StatusCondition status); + +// The healing items in the Items pocket, in the order they were bought: +// Potions, Antidotes, then Parlyz Heals. +struct Supplies{ + int potions = 0; + int antidotes = 0; + int parlyz_heals = 0; + // The Items pocket's order, by slug (see read_item_list_name()): the + // order bought, or as read from the bag, with "" for a row whose name + // couldn't be read. A counted item with none left takes no row; the + // others always take theirs. + std::vector pocket = {"potion", "antidote", "parlyz-heal"}; + // The starter's status at the last battle screen that showed it, and + // not cured since. + StatusCondition status = StatusCondition::NONE; + // The starter's HP bar wasn't green (or was red) at the last battle + // screen that showed it, and no Potion or nurse healed it since. + bool hurt = false; + bool hp_red = false; + // The starter's HP bar's filled share at the last battle screen that + // showed it, 1 after the nurse or a Potion on the overworld. + double hp_fill = 1.0; + // The starter's moves and their PP, as far as the story knows them: + // a new game's Squirtle unless a checkpoint's row says otherwise. + PartyMember lead = new_member("squirtle", 5); + // Party slots (from 0, the lead) that are never sent in when the lead + // faints, so they gain no EXP and learn or evolve nothing: a member + // kept for later, or one the user keeps for a trade. + std::vector protected_slots = {}; + // The party of the trainer the table's battle step fights, when the + // story knows it (trainer_party()): the lead's attacks are chosen + // against it while the one out isn't known. Empty otherwise; wild + // battles never use it. + std::vector foes = {}; + // That trainer (story_trainer()), "" otherwise. + std::string trainer = {}; + // How carefully that battle is fought (story_battle_risk()). + BattleRisk risk = BattleRisk::LOW; + // The species of the trainer's Pokemon out, as read at the last battle + // menu (read_trainer_foe()), "" if not read: the lead's attacks are + // chosen against it. + std::string foe_out = {}; + // The wild Pokemon of the battle going on, as read at its first battle + // menu (read_wild_foes()): the lead's attacks are chosen against it. + // Empty when it wasn't read; trainer battles never use it. + std::vector wild_foes = {}; +}; + +// The nurse healed the party: HP, status and PP. +void healed_by_nurse(Supplies& supplies); + +// The lead's attacks are low on PP: the nurse before a fight that needs them. +bool attacks_low_on_pp(const Supplies& supplies); + +// Before a trainer's battle, once the items are used: the nurse for HP +// not green (no Potion left to heal it), a status no item cured, or +// attacks low on PP. Yellow HP counts (console B, 2026-11-03: 17/55 HP +// and no Potion into Miguel's battle, which only red would have stopped). +bool nurse_before_battle(const Supplies& supplies); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerData.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerData.h new file mode 100644 index 0000000000..4e3d57bffa --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerData.h @@ -0,0 +1,70 @@ +/* AutoStory Trainer Data + * + * From: https://github.com/PokemonAutomation/ + * + * Trainers' parties, items and AI flags as pret/pokefirered has them + * (BattleData/trainers.json), and the trainer's Pokemon out as read. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryTrainerData_H +#define PokemonAutomation_PokemonFRLG_AutoStoryTrainerData_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" +#include "Pokemon/Pokemon_Types.h" +#include "PokemonFRLG_AutoStoryMoveData.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// A trainer party Pokemon entry. +struct TrainerMon{ + std::string species; + uint8_t level = 0; + // pret's iv, 0 to 255: every IV is iv * 31 / 255 (CreateNPCTrainerParty). + uint8_t iv = 0; + // The nature's index (0 Hardy, 1 Lonely, ... 24 Quirky): the one the + // game's personality gives it (see frlg_battle_data.py). + uint8_t nature = 0; + // The moves the party gives it, else the level-up moves the game gives. + std::vector moves; +}; + +// Trainer AI flags and team definition. +struct TrainerData{ + // pret's AI flags as slugs: "check-bad-move", "try-to-faint", ... + std::vector ai = {}; + // The items the trainer can use, in order, each once ("super-potion"). + std::vector items = {}; + std::vector party = {}; +}; +// A trainer's party in order; empty for a trainer the data doesn't have. +std::vector trainer_mons(std::string_view trainer); + +// A trainer's AI flags, items and party; none for one the data doesn't have. +std::optional trainer_data(std::string_view trainer); + +// The Pokemon a trainer's battle shows on `screen`, a battle menu: the +// name its HP box shows (WildEncounterReader), among `party`'s species. +// Empty if not read. Logs what it read. +std::string read_trainer_foe(Logger& logger, Language language, const ImageViewRGB32& screen, const std::vector& party); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 48263027df..d9f72f295d 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1893,6 +1893,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldObjects.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor_Tests.cpp @@ -1903,9 +1904,19 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteCosts.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteSteps.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTileRules.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTiles.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTrainerCrossing.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkedTiles.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkMoves.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkOptions.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkTimes.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkWatches.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp @@ -1927,12 +1938,28 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCheckpoints.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryIntro.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLevelUps.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMoveData.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryNewMembers.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPartyMember.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPoses.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPresses.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySave.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySaveChecks.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameCompare.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameStore.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartMenu.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStoryTrainers.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp @@ -1949,6 +1976,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -1974,6 +2002,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerData.h Source/VideoGames/PokemonFRLG/Programs/PokemonFRLG_BattleMenuNavigation.cpp Source/VideoGames/PokemonFRLG/Programs/PokemonFRLG_BattleMenuNavigation.h Source/VideoGames/PokemonFRLG/Programs/PokemonFRLG_SafariOptimalAction.cpp From 46bfa14d6295809b9d3a6c8dbc1b2835c0bc3ef1 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 15:00:28 -0800 Subject: [PATCH 29/29] FRLG AutoStory: cut the battle data to what the program reads species.json keeps each species' types; moves.json keeps each move's type, whether it does damage and its PP (PP tracking needs it). trainers.json and the story-trainer table are gone: a battle step's plan names its trainer and foes ("trainer", "foes" args on FRLG's battle action). The fallback attack is the damaging move with the best type multiplier against the foes, ties in plan then slot order; with no foe known, the first damaging move. The generator forwarder is removed, as nothing here regenerates these files. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Programs/AutoStory/BattleData/moves.json | 708 ++++++++-------- .../AutoStory/BattleData/species.json | 772 +++++++++--------- .../AutoStory/BattleData/trainers.json | 641 --------------- .../PokemonFRLG_AutoStoryBattleData.cpp | 130 +-- .../PokemonFRLG_AutoStoryBattleData.h | 25 +- .../PokemonFRLG_AutoStoryBattleData_Tests.cpp | 91 ++- .../PokemonFRLG_AutoStoryBattleDecisions.cpp | 8 +- .../PokemonFRLG_AutoStoryBattleRisk.h | 43 + .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 9 +- .../AutoStory/PokemonFRLG_AutoStoryMoveData.h | 60 +- .../AutoStory/PokemonFRLG_AutoStoryParty.cpp | 61 +- .../AutoStory/PokemonFRLG_AutoStoryParty.h | 25 +- .../PokemonFRLG_AutoStoryPartyMember.h | 5 +- .../PokemonFRLG_AutoStoryParty_Tests.cpp | 30 +- .../PokemonFRLG_AutoStoryStepTable.cpp | 14 + .../PokemonFRLG_AutoStoryStoryTrainers.h | 62 -- .../AutoStory/PokemonFRLG_AutoStorySupplies.h | 12 +- .../PokemonFRLG_AutoStoryTrainerData.h | 70 -- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 7 +- .../AutoStory/StoryData/frlg-00.04.plan.json | 4 +- .../AutoStory/StoryData/frlg-00.09.plan.json | 8 + SerialPrograms/cmake/SourceFiles.cmake | 3 +- devtools/maps/RESOURCE_MAPS.md | 9 +- devtools/maps/frlg_battle_data.py | 15 - 24 files changed, 955 insertions(+), 1857 deletions(-) delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleRisk.h delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStoryTrainers.h delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerData.h delete mode 100644 devtools/maps/frlg_battle_data.py diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json index 64425be1f6..6927368ca1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json @@ -1,356 +1,356 @@ { -"pound": [40, "normal", 35, 100, 0, "hit", 0], -"karate-chop": [50, "fighting", 25, 100, 0, "high-critical", 0], -"double-slap": [15, "normal", 10, 85, 0, "multi-hit", 0], -"comet-punch": [18, "normal", 15, 85, 0, "multi-hit", 0], -"mega-punch": [80, "normal", 20, 85, 0, "hit", 0], -"pay-day": [40, "normal", 20, 100, 0, "pay-day", 100], -"fire-punch": [75, "fire", 15, 100, 0, "burn-hit", 10], -"ice-punch": [75, "ice", 15, 100, 0, "freeze-hit", 10], -"thunder-punch": [75, "electric", 15, 100, 0, "paralyze-hit", 10], -"scratch": [40, "normal", 35, 100, 0, "hit", 0], -"vise-grip": [55, "normal", 30, 100, 0, "hit", 0], -"guillotine": [1, "normal", 5, 30, 0, "ohko", 0], -"razor-wind": [80, "normal", 10, 100, 0, "razor-wind", 0], -"swords-dance": [0, "normal", 30, 0, 0, "attack-up-2", 0], -"cut": [50, "normal", 30, 95, 0, "hit", 0], -"gust": [40, "flying", 35, 100, 0, "gust", 0], -"wing-attack": [60, "flying", 35, 100, 0, "hit", 0], -"whirlwind": [0, "normal", 20, 100, -6, "roar", 0], -"fly": [70, "flying", 15, 95, 0, "semi-invulnerable", 0], -"bind": [15, "normal", 20, 75, 0, "trap", 100], -"slam": [80, "normal", 20, 75, 0, "hit", 0], -"vine-whip": [35, "grass", 10, 100, 0, "hit", 0], -"stomp": [65, "normal", 20, 100, 0, "flinch-minimize-hit", 30], -"double-kick": [30, "fighting", 30, 100, 0, "double-hit", 0], -"mega-kick": [120, "normal", 5, 75, 0, "hit", 0], -"jump-kick": [70, "fighting", 25, 95, 0, "recoil-if-miss", 0], -"rolling-kick": [60, "fighting", 15, 85, 0, "flinch-hit", 30], -"sand-attack": [0, "ground", 15, 100, 0, "accuracy-down", 0], -"headbutt": [70, "normal", 15, 100, 0, "flinch-hit", 30], -"horn-attack": [65, "normal", 25, 100, 0, "hit", 0], -"fury-attack": [15, "normal", 20, 85, 0, "multi-hit", 0], -"horn-drill": [1, "normal", 5, 30, 0, "ohko", 0], -"tackle": [35, "normal", 35, 95, 0, "hit", 0], -"body-slam": [85, "normal", 15, 100, 0, "paralyze-hit", 30], -"wrap": [15, "normal", 20, 85, 0, "trap", 100], -"take-down": [90, "normal", 20, 85, 0, "recoil", 0], -"thrash": [90, "normal", 20, 100, 0, "rampage", 100], -"double-edge": [120, "normal", 15, 100, 0, "double-edge", 0], -"tail-whip": [0, "normal", 30, 100, 0, "defense-down", 0], -"poison-sting": [15, "poison", 35, 100, 0, "poison-hit", 30], -"twineedle": [25, "bug", 20, 100, 0, "twineedle", 20], -"pin-missile": [14, "bug", 20, 85, 0, "multi-hit", 0], -"leer": [0, "normal", 30, 100, 0, "defense-down", 0], -"bite": [60, "dark", 25, 100, 0, "flinch-hit", 30], -"growl": [0, "normal", 40, 100, 0, "attack-down", 0], -"roar": [0, "normal", 20, 100, -6, "roar", 0], -"sing": [0, "normal", 15, 55, 0, "sleep", 0], -"supersonic": [0, "normal", 20, 55, 0, "confuse", 0], -"sonic-boom": [1, "normal", 20, 90, 0, "sonicboom", 0], -"disable": [0, "normal", 20, 55, 0, "disable", 0], -"acid": [40, "poison", 30, 100, 0, "defense-down-hit", 10], -"ember": [40, "fire", 25, 100, 0, "burn-hit", 10], -"flamethrower": [95, "fire", 15, 100, 0, "burn-hit", 10], -"mist": [0, "ice", 30, 0, 0, "mist", 0], -"water-gun": [40, "water", 25, 100, 0, "hit", 0], -"hydro-pump": [120, "water", 5, 80, 0, "hit", 0], -"surf": [95, "water", 15, 100, 0, "hit", 0], -"ice-beam": [95, "ice", 10, 100, 0, "freeze-hit", 10], -"blizzard": [120, "ice", 5, 70, 0, "freeze-hit", 10], -"psybeam": [65, "psychic", 20, 100, 0, "confuse-hit", 10], -"bubble-beam": [65, "water", 20, 100, 0, "speed-down-hit", 10], -"aurora-beam": [65, "ice", 20, 100, 0, "attack-down-hit", 10], -"hyper-beam": [150, "normal", 5, 90, 0, "recharge", 0], -"peck": [35, "flying", 35, 100, 0, "hit", 0], -"drill-peck": [80, "flying", 20, 100, 0, "hit", 0], -"submission": [80, "fighting", 25, 80, 0, "recoil", 0], -"low-kick": [1, "fighting", 20, 100, 0, "low-kick", 0], -"counter": [1, "fighting", 20, 100, -5, "counter", 0], -"seismic-toss": [1, "fighting", 20, 100, 0, "level-damage", 0], -"strength": [80, "normal", 15, 100, 0, "hit", 0], -"absorb": [20, "grass", 20, 100, 0, "absorb", 0], -"mega-drain": [40, "grass", 10, 100, 0, "absorb", 0], -"leech-seed": [0, "grass", 10, 90, 0, "leech-seed", 0], -"growth": [0, "normal", 40, 0, 0, "special-attack-up", 0], -"razor-leaf": [55, "grass", 25, 95, 0, "high-critical", 0], -"solar-beam": [120, "grass", 10, 100, 0, "solar-beam", 0], -"poison-powder": [0, "poison", 35, 75, 0, "poison", 0], -"stun-spore": [0, "grass", 30, 75, 0, "paralyze", 0], -"sleep-powder": [0, "grass", 15, 75, 0, "sleep", 0], -"petal-dance": [70, "grass", 20, 100, 0, "rampage", 100], -"string-shot": [0, "bug", 40, 95, 0, "speed-down", 0], -"dragon-rage": [1, "dragon", 10, 100, 0, "dragon-rage", 0], -"fire-spin": [15, "fire", 15, 70, 0, "trap", 100], -"thunder-shock": [40, "electric", 30, 100, 0, "paralyze-hit", 10], -"thunderbolt": [95, "electric", 15, 100, 0, "paralyze-hit", 10], -"thunder-wave": [0, "electric", 20, 100, 0, "paralyze", 0], -"thunder": [120, "electric", 10, 70, 0, "thunder", 30], -"rock-throw": [50, "rock", 15, 90, 0, "hit", 0], -"earthquake": [100, "ground", 10, 100, 0, "earthquake", 0], -"fissure": [1, "ground", 5, 30, 0, "ohko", 0], -"dig": [60, "ground", 10, 100, 0, "semi-invulnerable", 0], -"toxic": [0, "poison", 10, 85, 0, "toxic", 100], -"confusion": [50, "psychic", 25, 100, 0, "confuse-hit", 10], -"psychic": [90, "psychic", 10, 100, 0, "special-defense-down-hit", 10], -"hypnosis": [0, "psychic", 20, 60, 0, "sleep", 0], -"meditate": [0, "psychic", 40, 0, 0, "attack-up", 0], -"agility": [0, "psychic", 30, 0, 0, "speed-up-2", 0], -"quick-attack": [40, "normal", 30, 100, 1, "quick-attack", 0], -"rage": [20, "normal", 20, 100, 0, "rage", 0], -"teleport": [0, "psychic", 20, 0, 0, "teleport", 0], -"night-shade": [1, "ghost", 15, 100, 0, "level-damage", 0], -"mimic": [0, "normal", 10, 100, 0, "mimic", 0], -"screech": [0, "normal", 40, 85, 0, "defense-down-2", 0], -"double-team": [0, "normal", 15, 0, 0, "evasion-up", 0], -"recover": [0, "normal", 20, 0, 0, "restore-hp", 0], -"harden": [0, "normal", 30, 0, 0, "defense-up", 0], -"minimize": [0, "normal", 20, 0, 0, "minimize", 0], -"smokescreen": [0, "normal", 20, 100, 0, "accuracy-down", 0], -"confuse-ray": [0, "ghost", 10, 100, 0, "confuse", 0], -"withdraw": [0, "water", 40, 0, 0, "defense-up", 0], -"defense-curl": [0, "normal", 40, 0, 0, "defense-curl", 0], -"barrier": [0, "psychic", 30, 0, 0, "defense-up-2", 0], -"light-screen": [0, "psychic", 30, 0, 0, "light-screen", 0], -"haze": [0, "ice", 30, 0, 0, "haze", 0], -"reflect": [0, "psychic", 20, 0, 0, "reflect", 0], -"focus-energy": [0, "normal", 30, 0, 0, "focus-energy", 0], -"bide": [1, "normal", 10, 100, 0, "bide", 0], -"metronome": [0, "normal", 10, 0, 0, "metronome", 0], -"mirror-move": [0, "flying", 20, 0, 0, "mirror-move", 0], -"self-destruct": [200, "normal", 5, 100, 0, "explosion", 0], -"egg-bomb": [100, "normal", 10, 75, 0, "hit", 0], -"lick": [20, "ghost", 30, 100, 0, "paralyze-hit", 30], -"smog": [20, "poison", 20, 70, 0, "poison-hit", 40], -"sludge": [65, "poison", 20, 100, 0, "poison-hit", 30], -"bone-club": [65, "ground", 20, 85, 0, "flinch-hit", 10], -"fire-blast": [120, "fire", 5, 85, 0, "burn-hit", 10], -"waterfall": [80, "water", 15, 100, 0, "hit", 0], -"clamp": [35, "water", 10, 75, 0, "trap", 100], -"swift": [60, "normal", 20, 0, 0, "always-hit", 0], -"skull-bash": [100, "normal", 15, 100, 0, "skull-bash", 0], -"spike-cannon": [20, "normal", 15, 100, 0, "multi-hit", 0], -"constrict": [10, "normal", 35, 100, 0, "speed-down-hit", 10], -"amnesia": [0, "psychic", 20, 0, 0, "special-defense-up-2", 0], -"kinesis": [0, "psychic", 15, 80, 0, "accuracy-down", 0], -"soft-boiled": [0, "normal", 10, 100, 0, "softboiled", 0], -"high-jump-kick": [85, "fighting", 20, 90, 0, "recoil-if-miss", 0], -"glare": [0, "normal", 30, 75, 0, "paralyze", 0], -"dream-eater": [100, "psychic", 15, 100, 0, "dream-eater", 0], -"poison-gas": [0, "poison", 40, 55, 0, "poison", 0], -"barrage": [15, "normal", 20, 85, 0, "multi-hit", 0], -"leech-life": [20, "bug", 15, 100, 0, "absorb", 0], -"lovely-kiss": [0, "normal", 10, 75, 0, "sleep", 0], -"sky-attack": [140, "flying", 5, 90, 0, "sky-attack", 30], -"transform": [0, "normal", 10, 0, 0, "transform", 0], -"bubble": [20, "water", 30, 100, 0, "speed-down-hit", 10], -"dizzy-punch": [70, "normal", 10, 100, 0, "confuse-hit", 20], -"spore": [0, "grass", 15, 100, 0, "sleep", 0], -"flash": [0, "normal", 20, 70, 0, "accuracy-down", 0], -"psywave": [1, "psychic", 15, 80, 0, "psywave", 0], -"splash": [0, "normal", 40, 0, 0, "splash", 0], -"acid-armor": [0, "poison", 40, 0, 0, "defense-up-2", 0], -"crabhammer": [90, "water", 10, 85, 0, "high-critical", 0], -"explosion": [250, "normal", 5, 100, 0, "explosion", 0], -"fury-swipes": [18, "normal", 15, 80, 0, "multi-hit", 0], -"bonemerang": [50, "ground", 10, 90, 0, "double-hit", 0], -"rest": [0, "psychic", 10, 0, 0, "rest", 0], -"rock-slide": [75, "rock", 10, 90, 0, "flinch-hit", 30], -"hyper-fang": [80, "normal", 15, 90, 0, "flinch-hit", 10], -"sharpen": [0, "normal", 30, 0, 0, "attack-up", 0], -"conversion": [0, "normal", 30, 0, 0, "conversion", 0], -"tri-attack": [80, "normal", 10, 100, 0, "tri-attack", 20], -"super-fang": [1, "normal", 10, 90, 0, "super-fang", 0], -"slash": [70, "normal", 20, 100, 0, "high-critical", 0], -"substitute": [0, "normal", 10, 0, 0, "substitute", 0], -"struggle": [50, "normal", 1, 100, 0, "recoil", 0], -"sketch": [0, "normal", 1, 0, 0, "sketch", 0], -"triple-kick": [10, "fighting", 10, 90, 0, "triple-kick", 0], -"thief": [40, "dark", 10, 100, 0, "thief", 100], -"spider-web": [0, "bug", 10, 100, 0, "mean-look", 0], -"mind-reader": [0, "normal", 5, 100, 0, "lock-on", 0], -"nightmare": [0, "ghost", 15, 100, 0, "nightmare", 0], -"flame-wheel": [60, "fire", 25, 100, 0, "thaw-hit", 10], -"snore": [40, "normal", 15, 100, 0, "snore", 30], -"curse": [0, "mystery", 10, 0, 0, "curse", 0], -"flail": [1, "normal", 15, 100, 0, "flail", 0], -"conversion-2": [0, "normal", 30, 100, 0, "conversion-2", 0], -"aeroblast": [100, "flying", 5, 95, 0, "high-critical", 0], -"cotton-spore": [0, "grass", 40, 85, 0, "speed-down-2", 0], -"reversal": [1, "fighting", 15, 100, 0, "flail", 0], -"spite": [0, "ghost", 10, 100, 0, "spite", 0], -"powder-snow": [40, "ice", 25, 100, 0, "freeze-hit", 10], -"protect": [0, "normal", 10, 0, 3, "protect", 0], -"mach-punch": [40, "fighting", 30, 100, 1, "quick-attack", 0], -"scary-face": [0, "normal", 10, 90, 0, "speed-down-2", 0], -"feint-attack": [60, "dark", 20, 0, 0, "always-hit", 0], -"sweet-kiss": [0, "normal", 10, 75, 0, "confuse", 0], -"belly-drum": [0, "normal", 10, 0, 0, "belly-drum", 0], -"sludge-bomb": [90, "poison", 10, 100, 0, "poison-hit", 30], -"mud-slap": [20, "ground", 10, 100, 0, "accuracy-down-hit", 100], -"octazooka": [65, "water", 10, 85, 0, "accuracy-down-hit", 50], -"spikes": [0, "ground", 20, 0, 0, "spikes", 0], -"zap-cannon": [100, "electric", 5, 50, 0, "paralyze-hit", 100], -"foresight": [0, "normal", 40, 100, 0, "foresight", 0], -"destiny-bond": [0, "ghost", 5, 0, 0, "destiny-bond", 0], -"perish-song": [0, "normal", 5, 0, 0, "perish-song", 0], -"icy-wind": [55, "ice", 15, 95, 0, "speed-down-hit", 100], -"detect": [0, "fighting", 5, 0, 3, "protect", 0], -"bone-rush": [25, "ground", 10, 80, 0, "multi-hit", 0], -"lock-on": [0, "normal", 5, 100, 0, "lock-on", 0], -"outrage": [90, "dragon", 15, 100, 0, "rampage", 100], -"sandstorm": [0, "rock", 10, 0, 0, "sandstorm", 0], -"giga-drain": [60, "grass", 5, 100, 0, "absorb", 0], -"endure": [0, "normal", 10, 0, 3, "endure", 0], -"charm": [0, "normal", 20, 100, 0, "attack-down-2", 0], -"rollout": [30, "rock", 20, 90, 0, "rollout", 0], -"false-swipe": [40, "normal", 40, 100, 0, "false-swipe", 0], -"swagger": [0, "normal", 15, 90, 0, "swagger", 100], -"milk-drink": [0, "normal", 10, 0, 0, "softboiled", 0], -"spark": [65, "electric", 20, 100, 0, "paralyze-hit", 30], -"fury-cutter": [10, "bug", 20, 95, 0, "fury-cutter", 0], -"steel-wing": [70, "steel", 25, 90, 0, "defense-up-hit", 10], -"mean-look": [0, "normal", 5, 100, 0, "mean-look", 0], -"attract": [0, "normal", 15, 100, 0, "attract", 0], -"sleep-talk": [0, "normal", 10, 0, 0, "sleep-talk", 0], -"heal-bell": [0, "normal", 5, 0, 0, "heal-bell", 0], -"return": [1, "normal", 20, 100, 0, "return", 0], -"present": [1, "normal", 15, 90, 0, "present", 0], -"frustration": [1, "normal", 20, 100, 0, "frustration", 0], -"safeguard": [0, "normal", 25, 0, 0, "safeguard", 0], -"pain-split": [0, "normal", 20, 100, 0, "pain-split", 0], -"sacred-fire": [100, "fire", 5, 95, 0, "thaw-hit", 50], -"magnitude": [1, "ground", 30, 100, 0, "magnitude", 0], -"dynamic-punch": [100, "fighting", 5, 50, 0, "confuse-hit", 100], -"megahorn": [120, "bug", 10, 85, 0, "hit", 0], -"dragon-breath": [60, "dragon", 20, 100, 0, "paralyze-hit", 30], -"baton-pass": [0, "normal", 40, 0, 0, "baton-pass", 0], -"encore": [0, "normal", 5, 100, 0, "encore", 0], -"pursuit": [40, "dark", 20, 100, 0, "pursuit", 0], -"rapid-spin": [20, "normal", 40, 100, 0, "rapid-spin", 0], -"sweet-scent": [0, "normal", 20, 100, 0, "evasion-down", 0], -"iron-tail": [100, "steel", 15, 75, 0, "defense-down-hit", 30], -"metal-claw": [50, "steel", 35, 95, 0, "attack-up-hit", 10], -"vital-throw": [70, "fighting", 10, 100, -1, "vital-throw", 0], -"morning-sun": [0, "normal", 5, 0, 0, "morning-sun", 0], -"synthesis": [0, "grass", 5, 0, 0, "synthesis", 0], -"moonlight": [0, "normal", 5, 0, 0, "moonlight", 0], -"hidden-power": [1, "normal", 15, 100, 0, "hidden-power", 0], -"cross-chop": [100, "fighting", 5, 80, 0, "high-critical", 0], -"twister": [40, "dragon", 20, 100, 0, "twister", 20], -"rain-dance": [0, "water", 5, 0, 0, "rain-dance", 0], -"sunny-day": [0, "fire", 5, 0, 0, "sunny-day", 0], -"crunch": [80, "dark", 15, 100, 0, "special-defense-down-hit", 20], -"mirror-coat": [1, "psychic", 20, 100, -5, "mirror-coat", 0], -"psych-up": [0, "normal", 10, 0, 0, "psych-up", 0], -"extreme-speed": [80, "normal", 5, 100, 1, "quick-attack", 0], -"ancient-power": [60, "rock", 5, 100, 0, "all-stats-up-hit", 10], -"shadow-ball": [80, "ghost", 15, 100, 0, "special-defense-down-hit", 20], -"future-sight": [80, "psychic", 15, 90, 0, "future-sight", 0], -"rock-smash": [20, "fighting", 15, 100, 0, "defense-down-hit", 50], -"whirlpool": [15, "water", 15, 70, 0, "trap", 100], -"beat-up": [10, "dark", 10, 100, 0, "beat-up", 0], -"fake-out": [40, "normal", 10, 100, 1, "fake-out", 0], -"uproar": [50, "normal", 10, 100, 0, "uproar", 100], -"stockpile": [0, "normal", 10, 0, 0, "stockpile", 0], -"spit-up": [100, "normal", 10, 100, 0, "spit-up", 0], -"swallow": [0, "normal", 10, 0, 0, "swallow", 0], -"heat-wave": [100, "fire", 10, 90, 0, "burn-hit", 10], -"hail": [0, "ice", 10, 0, 0, "hail", 0], -"torment": [0, "dark", 15, 100, 0, "torment", 0], -"flatter": [0, "dark", 15, 100, 0, "flatter", 0], -"will-o-wisp": [0, "fire", 15, 75, 0, "will-o-wisp", 0], -"memento": [0, "dark", 10, 100, 0, "memento", 0], -"facade": [70, "normal", 20, 100, 0, "facade", 0], -"focus-punch": [150, "fighting", 20, 100, -3, "focus-punch", 0], -"smelling-salts": [60, "normal", 10, 100, 0, "smellingsalt", 0], -"follow-me": [0, "normal", 20, 100, 3, "follow-me", 0], -"nature-power": [0, "normal", 20, 0, 0, "nature-power", 0], -"charge": [0, "electric", 20, 100, 0, "charge", 0], -"taunt": [0, "dark", 20, 100, 0, "taunt", 0], -"helping-hand": [0, "normal", 20, 100, 5, "helping-hand", 0], -"trick": [0, "psychic", 10, 100, 0, "trick", 0], -"role-play": [0, "psychic", 10, 100, 0, "role-play", 0], -"wish": [0, "normal", 10, 100, 0, "wish", 0], -"assist": [0, "normal", 20, 100, 0, "assist", 0], -"ingrain": [0, "grass", 20, 100, 0, "ingrain", 0], -"superpower": [120, "fighting", 5, 100, 0, "superpower", 0], -"magic-coat": [0, "psychic", 15, 100, 4, "magic-coat", 0], -"recycle": [0, "normal", 10, 100, 0, "recycle", 0], -"revenge": [60, "fighting", 10, 100, -4, "revenge", 0], -"brick-break": [75, "fighting", 15, 100, 0, "brick-break", 0], -"yawn": [0, "normal", 10, 100, 0, "yawn", 0], -"knock-off": [20, "dark", 20, 100, 0, "knock-off", 100], -"endeavor": [1, "normal", 5, 100, 0, "endeavor", 0], -"eruption": [150, "fire", 5, 100, 0, "eruption", 0], -"skill-swap": [0, "psychic", 10, 100, 0, "skill-swap", 0], -"imprison": [0, "psychic", 10, 100, 0, "imprison", 0], -"refresh": [0, "normal", 20, 100, 0, "refresh", 0], -"grudge": [0, "ghost", 5, 100, 0, "grudge", 0], -"snatch": [0, "dark", 10, 100, 4, "snatch", 0], -"secret-power": [70, "normal", 20, 100, 0, "secret-power", 30], -"dive": [60, "water", 10, 100, 0, "semi-invulnerable", 0], -"arm-thrust": [15, "fighting", 20, 100, 0, "multi-hit", 0], -"camouflage": [0, "normal", 20, 100, 0, "camouflage", 0], -"tail-glow": [0, "bug", 20, 100, 0, "special-attack-up-2", 0], -"luster-purge": [70, "psychic", 5, 100, 0, "special-defense-down-hit", 50], -"mist-ball": [70, "psychic", 5, 100, 0, "special-attack-down-hit", 50], -"feather-dance": [0, "flying", 15, 100, 0, "attack-down-2", 0], -"teeter-dance": [0, "normal", 20, 100, 0, "teeter-dance", 0], -"blaze-kick": [85, "fire", 10, 90, 0, "blaze-kick", 10], -"mud-sport": [0, "ground", 15, 100, 0, "mud-sport", 0], -"ice-ball": [30, "ice", 20, 90, 0, "rollout", 0], -"needle-arm": [60, "grass", 15, 100, 0, "flinch-minimize-hit", 30], -"slack-off": [0, "normal", 10, 100, 0, "restore-hp", 0], -"hyper-voice": [90, "normal", 10, 100, 0, "hit", 0], -"poison-fang": [50, "poison", 15, 100, 0, "poison-fang", 30], -"crush-claw": [75, "normal", 10, 95, 0, "defense-down-hit", 50], -"blast-burn": [150, "fire", 5, 90, 0, "recharge", 0], -"hydro-cannon": [150, "water", 5, 90, 0, "recharge", 0], -"meteor-mash": [100, "steel", 10, 85, 0, "attack-up-hit", 20], -"astonish": [30, "ghost", 15, 100, 0, "flinch-minimize-hit", 30], -"weather-ball": [50, "normal", 10, 100, 0, "weather-ball", 0], -"aromatherapy": [0, "grass", 5, 0, 0, "heal-bell", 0], -"fake-tears": [0, "dark", 20, 100, 0, "special-defense-down-2", 0], -"air-cutter": [55, "flying", 25, 95, 0, "high-critical", 0], -"overheat": [140, "fire", 5, 90, 0, "overheat", 100], -"odor-sleuth": [0, "normal", 40, 100, 0, "foresight", 0], -"rock-tomb": [50, "rock", 10, 80, 0, "speed-down-hit", 100], -"silver-wind": [60, "bug", 5, 100, 0, "all-stats-up-hit", 10], -"metal-sound": [0, "steel", 40, 85, 0, "special-defense-down-2", 0], -"grass-whistle": [0, "grass", 15, 55, 0, "sleep", 0], -"tickle": [0, "normal", 20, 100, 0, "tickle", 0], -"cosmic-power": [0, "psychic", 20, 0, 0, "cosmic-power", 0], -"water-spout": [150, "water", 5, 100, 0, "eruption", 0], -"signal-beam": [75, "bug", 15, 100, 0, "confuse-hit", 10], -"shadow-punch": [60, "ghost", 20, 0, 0, "always-hit", 0], -"extrasensory": [80, "psychic", 30, 100, 0, "flinch-minimize-hit", 10], -"sky-uppercut": [85, "fighting", 15, 90, 0, "sky-uppercut", 0], -"sand-tomb": [15, "ground", 15, 70, 0, "trap", 100], -"sheer-cold": [1, "ice", 5, 30, 0, "ohko", 0], -"muddy-water": [95, "water", 10, 85, 0, "accuracy-down-hit", 30], -"bullet-seed": [10, "grass", 30, 100, 0, "multi-hit", 0], -"aerial-ace": [60, "flying", 20, 0, 0, "always-hit", 0], -"icicle-spear": [10, "ice", 30, 100, 0, "multi-hit", 0], -"iron-defense": [0, "steel", 15, 0, 0, "defense-up-2", 0], -"block": [0, "normal", 5, 100, 0, "mean-look", 0], -"howl": [0, "normal", 40, 0, 0, "attack-up", 0], -"dragon-claw": [80, "dragon", 15, 100, 0, "hit", 0], -"frenzy-plant": [150, "grass", 5, 90, 0, "recharge", 0], -"bulk-up": [0, "fighting", 20, 0, 0, "bulk-up", 0], -"bounce": [85, "flying", 5, 85, 0, "semi-invulnerable", 30], -"mud-shot": [55, "ground", 15, 95, 0, "speed-down-hit", 100], -"poison-tail": [50, "poison", 25, 100, 0, "poison-tail", 10], -"covet": [40, "normal", 40, 100, 0, "thief", 100], -"volt-tackle": [120, "electric", 15, 100, 0, "double-edge", 0], -"magical-leaf": [60, "grass", 20, 0, 0, "always-hit", 0], -"water-sport": [0, "water", 15, 100, 0, "water-sport", 0], -"calm-mind": [0, "psychic", 20, 0, 0, "calm-mind", 0], -"leaf-blade": [70, "grass", 15, 100, 0, "high-critical", 0], -"dragon-dance": [0, "dragon", 20, 0, 0, "dragon-dance", 0], -"rock-blast": [25, "rock", 10, 80, 0, "multi-hit", 0], -"shock-wave": [60, "electric", 20, 0, 0, "always-hit", 0], -"water-pulse": [60, "water", 20, 100, 0, "confuse-hit", 20], -"doom-desire": [120, "steel", 5, 85, 0, "future-sight", 0], -"psycho-boost": [140, "psychic", 5, 90, 0, "overheat", 100] +"pound": ["normal", 1, 35], +"karate-chop": ["fighting", 1, 25], +"double-slap": ["normal", 1, 10], +"comet-punch": ["normal", 1, 15], +"mega-punch": ["normal", 1, 20], +"pay-day": ["normal", 1, 20], +"fire-punch": ["fire", 1, 15], +"ice-punch": ["ice", 1, 15], +"thunder-punch": ["electric", 1, 15], +"scratch": ["normal", 1, 35], +"vise-grip": ["normal", 1, 30], +"guillotine": ["normal", 1, 5], +"razor-wind": ["normal", 1, 10], +"swords-dance": ["normal", 0, 30], +"cut": ["normal", 1, 30], +"gust": ["flying", 1, 35], +"wing-attack": ["flying", 1, 35], +"whirlwind": ["normal", 0, 20], +"fly": ["flying", 1, 15], +"bind": ["normal", 1, 20], +"slam": ["normal", 1, 20], +"vine-whip": ["grass", 1, 10], +"stomp": ["normal", 1, 20], +"double-kick": ["fighting", 1, 30], +"mega-kick": ["normal", 1, 5], +"jump-kick": ["fighting", 1, 25], +"rolling-kick": ["fighting", 1, 15], +"sand-attack": ["ground", 0, 15], +"headbutt": ["normal", 1, 15], +"horn-attack": ["normal", 1, 25], +"fury-attack": ["normal", 1, 20], +"horn-drill": ["normal", 1, 5], +"tackle": ["normal", 1, 35], +"body-slam": ["normal", 1, 15], +"wrap": ["normal", 1, 20], +"take-down": ["normal", 1, 20], +"thrash": ["normal", 1, 20], +"double-edge": ["normal", 1, 15], +"tail-whip": ["normal", 0, 30], +"poison-sting": ["poison", 1, 35], +"twineedle": ["bug", 1, 20], +"pin-missile": ["bug", 1, 20], +"leer": ["normal", 0, 30], +"bite": ["dark", 1, 25], +"growl": ["normal", 0, 40], +"roar": ["normal", 0, 20], +"sing": ["normal", 0, 15], +"supersonic": ["normal", 0, 20], +"sonic-boom": ["normal", 1, 20], +"disable": ["normal", 0, 20], +"acid": ["poison", 1, 30], +"ember": ["fire", 1, 25], +"flamethrower": ["fire", 1, 15], +"mist": ["ice", 0, 30], +"water-gun": ["water", 1, 25], +"hydro-pump": ["water", 1, 5], +"surf": ["water", 1, 15], +"ice-beam": ["ice", 1, 10], +"blizzard": ["ice", 1, 5], +"psybeam": ["psychic", 1, 20], +"bubble-beam": ["water", 1, 20], +"aurora-beam": ["ice", 1, 20], +"hyper-beam": ["normal", 1, 5], +"peck": ["flying", 1, 35], +"drill-peck": ["flying", 1, 20], +"submission": ["fighting", 1, 25], +"low-kick": ["fighting", 1, 20], +"counter": ["fighting", 1, 20], +"seismic-toss": ["fighting", 1, 20], +"strength": ["normal", 1, 15], +"absorb": ["grass", 1, 20], +"mega-drain": ["grass", 1, 10], +"leech-seed": ["grass", 0, 10], +"growth": ["normal", 0, 40], +"razor-leaf": ["grass", 1, 25], +"solar-beam": ["grass", 1, 10], +"poison-powder": ["poison", 0, 35], +"stun-spore": ["grass", 0, 30], +"sleep-powder": ["grass", 0, 15], +"petal-dance": ["grass", 1, 20], +"string-shot": ["bug", 0, 40], +"dragon-rage": ["dragon", 1, 10], +"fire-spin": ["fire", 1, 15], +"thunder-shock": ["electric", 1, 30], +"thunderbolt": ["electric", 1, 15], +"thunder-wave": ["electric", 0, 20], +"thunder": ["electric", 1, 10], +"rock-throw": ["rock", 1, 15], +"earthquake": ["ground", 1, 10], +"fissure": ["ground", 1, 5], +"dig": ["ground", 1, 10], +"toxic": ["poison", 0, 10], +"confusion": ["psychic", 1, 25], +"psychic": ["psychic", 1, 10], +"hypnosis": ["psychic", 0, 20], +"meditate": ["psychic", 0, 40], +"agility": ["psychic", 0, 30], +"quick-attack": ["normal", 1, 30], +"rage": ["normal", 1, 20], +"teleport": ["psychic", 0, 20], +"night-shade": ["ghost", 1, 15], +"mimic": ["normal", 0, 10], +"screech": ["normal", 0, 40], +"double-team": ["normal", 0, 15], +"recover": ["normal", 0, 20], +"harden": ["normal", 0, 30], +"minimize": ["normal", 0, 20], +"smokescreen": ["normal", 0, 20], +"confuse-ray": ["ghost", 0, 10], +"withdraw": ["water", 0, 40], +"defense-curl": ["normal", 0, 40], +"barrier": ["psychic", 0, 30], +"light-screen": ["psychic", 0, 30], +"haze": ["ice", 0, 30], +"reflect": ["psychic", 0, 20], +"focus-energy": ["normal", 0, 30], +"bide": ["normal", 1, 10], +"metronome": ["normal", 0, 10], +"mirror-move": ["flying", 0, 20], +"self-destruct": ["normal", 1, 5], +"egg-bomb": ["normal", 1, 10], +"lick": ["ghost", 1, 30], +"smog": ["poison", 1, 20], +"sludge": ["poison", 1, 20], +"bone-club": ["ground", 1, 20], +"fire-blast": ["fire", 1, 5], +"waterfall": ["water", 1, 15], +"clamp": ["water", 1, 10], +"swift": ["normal", 1, 20], +"skull-bash": ["normal", 1, 15], +"spike-cannon": ["normal", 1, 15], +"constrict": ["normal", 1, 35], +"amnesia": ["psychic", 0, 20], +"kinesis": ["psychic", 0, 15], +"soft-boiled": ["normal", 0, 10], +"high-jump-kick": ["fighting", 1, 20], +"glare": ["normal", 0, 30], +"dream-eater": ["psychic", 1, 15], +"poison-gas": ["poison", 0, 40], +"barrage": ["normal", 1, 20], +"leech-life": ["bug", 1, 15], +"lovely-kiss": ["normal", 0, 10], +"sky-attack": ["flying", 1, 5], +"transform": ["normal", 0, 10], +"bubble": ["water", 1, 30], +"dizzy-punch": ["normal", 1, 10], +"spore": ["grass", 0, 15], +"flash": ["normal", 0, 20], +"psywave": ["psychic", 1, 15], +"splash": ["normal", 0, 40], +"acid-armor": ["poison", 0, 40], +"crabhammer": ["water", 1, 10], +"explosion": ["normal", 1, 5], +"fury-swipes": ["normal", 1, 15], +"bonemerang": ["ground", 1, 10], +"rest": ["psychic", 0, 10], +"rock-slide": ["rock", 1, 10], +"hyper-fang": ["normal", 1, 15], +"sharpen": ["normal", 0, 30], +"conversion": ["normal", 0, 30], +"tri-attack": ["normal", 1, 10], +"super-fang": ["normal", 1, 10], +"slash": ["normal", 1, 20], +"substitute": ["normal", 0, 10], +"struggle": ["normal", 1, 1], +"sketch": ["normal", 0, 1], +"triple-kick": ["fighting", 1, 10], +"thief": ["dark", 1, 10], +"spider-web": ["bug", 0, 10], +"mind-reader": ["normal", 0, 5], +"nightmare": ["ghost", 0, 15], +"flame-wheel": ["fire", 1, 25], +"snore": ["normal", 1, 15], +"curse": ["mystery", 0, 10], +"flail": ["normal", 1, 15], +"conversion-2": ["normal", 0, 30], +"aeroblast": ["flying", 1, 5], +"cotton-spore": ["grass", 0, 40], +"reversal": ["fighting", 1, 15], +"spite": ["ghost", 0, 10], +"powder-snow": ["ice", 1, 25], +"protect": ["normal", 0, 10], +"mach-punch": ["fighting", 1, 30], +"scary-face": ["normal", 0, 10], +"feint-attack": ["dark", 1, 20], +"sweet-kiss": ["normal", 0, 10], +"belly-drum": ["normal", 0, 10], +"sludge-bomb": ["poison", 1, 10], +"mud-slap": ["ground", 1, 10], +"octazooka": ["water", 1, 10], +"spikes": ["ground", 0, 20], +"zap-cannon": ["electric", 1, 5], +"foresight": ["normal", 0, 40], +"destiny-bond": ["ghost", 0, 5], +"perish-song": ["normal", 0, 5], +"icy-wind": ["ice", 1, 15], +"detect": ["fighting", 0, 5], +"bone-rush": ["ground", 1, 10], +"lock-on": ["normal", 0, 5], +"outrage": ["dragon", 1, 15], +"sandstorm": ["rock", 0, 10], +"giga-drain": ["grass", 1, 5], +"endure": ["normal", 0, 10], +"charm": ["normal", 0, 20], +"rollout": ["rock", 1, 20], +"false-swipe": ["normal", 1, 40], +"swagger": ["normal", 0, 15], +"milk-drink": ["normal", 0, 10], +"spark": ["electric", 1, 20], +"fury-cutter": ["bug", 1, 20], +"steel-wing": ["steel", 1, 25], +"mean-look": ["normal", 0, 5], +"attract": ["normal", 0, 15], +"sleep-talk": ["normal", 0, 10], +"heal-bell": ["normal", 0, 5], +"return": ["normal", 1, 20], +"present": ["normal", 1, 15], +"frustration": ["normal", 1, 20], +"safeguard": ["normal", 0, 25], +"pain-split": ["normal", 0, 20], +"sacred-fire": ["fire", 1, 5], +"magnitude": ["ground", 1, 30], +"dynamic-punch": ["fighting", 1, 5], +"megahorn": ["bug", 1, 10], +"dragon-breath": ["dragon", 1, 20], +"baton-pass": ["normal", 0, 40], +"encore": ["normal", 0, 5], +"pursuit": ["dark", 1, 20], +"rapid-spin": ["normal", 1, 40], +"sweet-scent": ["normal", 0, 20], +"iron-tail": ["steel", 1, 15], +"metal-claw": ["steel", 1, 35], +"vital-throw": ["fighting", 1, 10], +"morning-sun": ["normal", 0, 5], +"synthesis": ["grass", 0, 5], +"moonlight": ["normal", 0, 5], +"hidden-power": ["normal", 1, 15], +"cross-chop": ["fighting", 1, 5], +"twister": ["dragon", 1, 20], +"rain-dance": ["water", 0, 5], +"sunny-day": ["fire", 0, 5], +"crunch": ["dark", 1, 15], +"mirror-coat": ["psychic", 1, 20], +"psych-up": ["normal", 0, 10], +"extreme-speed": ["normal", 1, 5], +"ancient-power": ["rock", 1, 5], +"shadow-ball": ["ghost", 1, 15], +"future-sight": ["psychic", 1, 15], +"rock-smash": ["fighting", 1, 15], +"whirlpool": ["water", 1, 15], +"beat-up": ["dark", 1, 10], +"fake-out": ["normal", 1, 10], +"uproar": ["normal", 1, 10], +"stockpile": ["normal", 0, 10], +"spit-up": ["normal", 1, 10], +"swallow": ["normal", 0, 10], +"heat-wave": ["fire", 1, 10], +"hail": ["ice", 0, 10], +"torment": ["dark", 0, 15], +"flatter": ["dark", 0, 15], +"will-o-wisp": ["fire", 0, 15], +"memento": ["dark", 0, 10], +"facade": ["normal", 1, 20], +"focus-punch": ["fighting", 1, 20], +"smelling-salts": ["normal", 1, 10], +"follow-me": ["normal", 0, 20], +"nature-power": ["normal", 0, 20], +"charge": ["electric", 0, 20], +"taunt": ["dark", 0, 20], +"helping-hand": ["normal", 0, 20], +"trick": ["psychic", 0, 10], +"role-play": ["psychic", 0, 10], +"wish": ["normal", 0, 10], +"assist": ["normal", 0, 20], +"ingrain": ["grass", 0, 20], +"superpower": ["fighting", 1, 5], +"magic-coat": ["psychic", 0, 15], +"recycle": ["normal", 0, 10], +"revenge": ["fighting", 1, 10], +"brick-break": ["fighting", 1, 15], +"yawn": ["normal", 0, 10], +"knock-off": ["dark", 1, 20], +"endeavor": ["normal", 1, 5], +"eruption": ["fire", 1, 5], +"skill-swap": ["psychic", 0, 10], +"imprison": ["psychic", 0, 10], +"refresh": ["normal", 0, 20], +"grudge": ["ghost", 0, 5], +"snatch": ["dark", 0, 10], +"secret-power": ["normal", 1, 20], +"dive": ["water", 1, 10], +"arm-thrust": ["fighting", 1, 20], +"camouflage": ["normal", 0, 20], +"tail-glow": ["bug", 0, 20], +"luster-purge": ["psychic", 1, 5], +"mist-ball": ["psychic", 1, 5], +"feather-dance": ["flying", 0, 15], +"teeter-dance": ["normal", 0, 20], +"blaze-kick": ["fire", 1, 10], +"mud-sport": ["ground", 0, 15], +"ice-ball": ["ice", 1, 20], +"needle-arm": ["grass", 1, 15], +"slack-off": ["normal", 0, 10], +"hyper-voice": ["normal", 1, 10], +"poison-fang": ["poison", 1, 15], +"crush-claw": ["normal", 1, 10], +"blast-burn": ["fire", 1, 5], +"hydro-cannon": ["water", 1, 5], +"meteor-mash": ["steel", 1, 10], +"astonish": ["ghost", 1, 15], +"weather-ball": ["normal", 1, 10], +"aromatherapy": ["grass", 0, 5], +"fake-tears": ["dark", 0, 20], +"air-cutter": ["flying", 1, 25], +"overheat": ["fire", 1, 5], +"odor-sleuth": ["normal", 0, 40], +"rock-tomb": ["rock", 1, 10], +"silver-wind": ["bug", 1, 5], +"metal-sound": ["steel", 0, 40], +"grass-whistle": ["grass", 0, 15], +"tickle": ["normal", 0, 20], +"cosmic-power": ["psychic", 0, 20], +"water-spout": ["water", 1, 5], +"signal-beam": ["bug", 1, 15], +"shadow-punch": ["ghost", 1, 20], +"extrasensory": ["psychic", 1, 30], +"sky-uppercut": ["fighting", 1, 15], +"sand-tomb": ["ground", 1, 15], +"sheer-cold": ["ice", 1, 5], +"muddy-water": ["water", 1, 10], +"bullet-seed": ["grass", 1, 30], +"aerial-ace": ["flying", 1, 20], +"icicle-spear": ["ice", 1, 30], +"iron-defense": ["steel", 0, 15], +"block": ["normal", 0, 5], +"howl": ["normal", 0, 40], +"dragon-claw": ["dragon", 1, 15], +"frenzy-plant": ["grass", 1, 5], +"bulk-up": ["fighting", 0, 20], +"bounce": ["flying", 1, 5], +"mud-shot": ["ground", 1, 15], +"poison-tail": ["poison", 1, 25], +"covet": ["normal", 1, 40], +"volt-tackle": ["electric", 1, 15], +"magical-leaf": ["grass", 1, 20], +"water-sport": ["water", 0, 15], +"calm-mind": ["psychic", 0, 20], +"leaf-blade": ["grass", 1, 15], +"dragon-dance": ["dragon", 0, 20], +"rock-blast": ["rock", 1, 10], +"shock-wave": ["electric", 1, 20], +"water-pulse": ["water", 1, 20], +"doom-desire": ["steel", 1, 5], +"psycho-boost": ["psychic", 1, 5] } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json index 5393e90c95..1c1b8866aa 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json @@ -1,388 +1,388 @@ { -"bulbasaur": ["grass", "poison", 45, 49, 49, 65, 65, 45], -"ivysaur": ["grass", "poison", 60, 62, 63, 80, 80, 60], -"venusaur": ["grass", "poison", 80, 82, 83, 100, 100, 80], -"charmander": ["fire", "fire", 39, 52, 43, 60, 50, 65], -"charmeleon": ["fire", "fire", 58, 64, 58, 80, 65, 80], -"charizard": ["fire", "flying", 78, 84, 78, 109, 85, 100], -"squirtle": ["water", "water", 44, 48, 65, 50, 64, 43], -"wartortle": ["water", "water", 59, 63, 80, 65, 80, 58], -"blastoise": ["water", "water", 79, 83, 100, 85, 105, 78], -"caterpie": ["bug", "bug", 45, 30, 35, 20, 20, 45], -"metapod": ["bug", "bug", 50, 20, 55, 25, 25, 30], -"butterfree": ["bug", "flying", 60, 45, 50, 80, 80, 70], -"weedle": ["bug", "poison", 40, 35, 30, 20, 20, 50], -"kakuna": ["bug", "poison", 45, 25, 50, 25, 25, 35], -"beedrill": ["bug", "poison", 65, 80, 40, 45, 80, 75], -"pidgey": ["normal", "flying", 40, 45, 40, 35, 35, 56], -"pidgeotto": ["normal", "flying", 63, 60, 55, 50, 50, 71], -"pidgeot": ["normal", "flying", 83, 80, 75, 70, 70, 91], -"rattata": ["normal", "normal", 30, 56, 35, 25, 35, 72], -"raticate": ["normal", "normal", 55, 81, 60, 50, 70, 97], -"spearow": ["normal", "flying", 40, 60, 30, 31, 31, 70], -"fearow": ["normal", "flying", 65, 90, 65, 61, 61, 100], -"ekans": ["poison", "poison", 35, 60, 44, 40, 54, 55], -"arbok": ["poison", "poison", 60, 85, 69, 65, 79, 80], -"pikachu": ["electric", "electric", 35, 55, 30, 50, 40, 90], -"raichu": ["electric", "electric", 60, 90, 55, 90, 80, 100], -"sandshrew": ["ground", "ground", 50, 75, 85, 20, 30, 40], -"sandslash": ["ground", "ground", 75, 100, 110, 45, 55, 65], -"nidoran-f": ["poison", "poison", 55, 47, 52, 40, 40, 41], -"nidorina": ["poison", "poison", 70, 62, 67, 55, 55, 56], -"nidoqueen": ["poison", "ground", 90, 82, 87, 75, 85, 76], -"nidoran-m": ["poison", "poison", 46, 57, 40, 40, 40, 50], -"nidorino": ["poison", "poison", 61, 72, 57, 55, 55, 65], -"nidoking": ["poison", "ground", 81, 92, 77, 85, 75, 85], -"clefairy": ["normal", "normal", 70, 45, 48, 60, 65, 35], -"clefable": ["normal", "normal", 95, 70, 73, 85, 90, 60], -"vulpix": ["fire", "fire", 38, 41, 40, 50, 65, 65], -"ninetales": ["fire", "fire", 73, 76, 75, 81, 100, 100], -"jigglypuff": ["normal", "normal", 115, 45, 20, 45, 25, 20], -"wigglytuff": ["normal", "normal", 140, 70, 45, 75, 50, 45], -"zubat": ["poison", "flying", 40, 45, 35, 30, 40, 55], -"golbat": ["poison", "flying", 75, 80, 70, 65, 75, 90], -"oddish": ["grass", "poison", 45, 50, 55, 75, 65, 30], -"gloom": ["grass", "poison", 60, 65, 70, 85, 75, 40], -"vileplume": ["grass", "poison", 75, 80, 85, 100, 90, 50], -"paras": ["bug", "grass", 35, 70, 55, 45, 55, 25], -"parasect": ["bug", "grass", 60, 95, 80, 60, 80, 30], -"venonat": ["bug", "poison", 60, 55, 50, 40, 55, 45], -"venomoth": ["bug", "poison", 70, 65, 60, 90, 75, 90], -"diglett": ["ground", "ground", 10, 55, 25, 35, 45, 95], -"dugtrio": ["ground", "ground", 35, 80, 50, 50, 70, 120], -"meowth": ["normal", "normal", 40, 45, 35, 40, 40, 90], -"persian": ["normal", "normal", 65, 70, 60, 65, 65, 115], -"psyduck": ["water", "water", 50, 52, 48, 65, 50, 55], -"golduck": ["water", "water", 80, 82, 78, 95, 80, 85], -"mankey": ["fighting", "fighting", 40, 80, 35, 35, 45, 70], -"primeape": ["fighting", "fighting", 65, 105, 60, 60, 70, 95], -"growlithe": ["fire", "fire", 55, 70, 45, 70, 50, 60], -"arcanine": ["fire", "fire", 90, 110, 80, 100, 80, 95], -"poliwag": ["water", "water", 40, 50, 40, 40, 40, 90], -"poliwhirl": ["water", "water", 65, 65, 65, 50, 50, 90], -"poliwrath": ["water", "fighting", 90, 85, 95, 70, 90, 70], -"abra": ["psychic", "psychic", 25, 20, 15, 105, 55, 90], -"kadabra": ["psychic", "psychic", 40, 35, 30, 120, 70, 105], -"alakazam": ["psychic", "psychic", 55, 50, 45, 135, 85, 120], -"machop": ["fighting", "fighting", 70, 80, 50, 35, 35, 35], -"machoke": ["fighting", "fighting", 80, 100, 70, 50, 60, 45], -"machamp": ["fighting", "fighting", 90, 130, 80, 65, 85, 55], -"bellsprout": ["grass", "poison", 50, 75, 35, 70, 30, 40], -"weepinbell": ["grass", "poison", 65, 90, 50, 85, 45, 55], -"victreebel": ["grass", "poison", 80, 105, 65, 100, 60, 70], -"tentacool": ["water", "poison", 40, 40, 35, 50, 100, 70], -"tentacruel": ["water", "poison", 80, 70, 65, 80, 120, 100], -"geodude": ["rock", "ground", 40, 80, 100, 30, 30, 20], -"graveler": ["rock", "ground", 55, 95, 115, 45, 45, 35], -"golem": ["rock", "ground", 80, 110, 130, 55, 65, 45], -"ponyta": ["fire", "fire", 50, 85, 55, 65, 65, 90], -"rapidash": ["fire", "fire", 65, 100, 70, 80, 80, 105], -"slowpoke": ["water", "psychic", 90, 65, 65, 40, 40, 15], -"slowbro": ["water", "psychic", 95, 75, 110, 100, 80, 30], -"magnemite": ["electric", "steel", 25, 35, 70, 95, 55, 45], -"magneton": ["electric", "steel", 50, 60, 95, 120, 70, 70], -"farfetch-d": ["normal", "flying", 52, 65, 55, 58, 62, 60], -"doduo": ["normal", "flying", 35, 85, 45, 35, 35, 75], -"dodrio": ["normal", "flying", 60, 110, 70, 60, 60, 100], -"seel": ["water", "water", 65, 45, 55, 45, 70, 45], -"dewgong": ["water", "ice", 90, 70, 80, 70, 95, 70], -"grimer": ["poison", "poison", 80, 80, 50, 40, 50, 25], -"muk": ["poison", "poison", 105, 105, 75, 65, 100, 50], -"shellder": ["water", "water", 30, 65, 100, 45, 25, 40], -"cloyster": ["water", "ice", 50, 95, 180, 85, 45, 70], -"gastly": ["ghost", "poison", 30, 35, 30, 100, 35, 80], -"haunter": ["ghost", "poison", 45, 50, 45, 115, 55, 95], -"gengar": ["ghost", "poison", 60, 65, 60, 130, 75, 110], -"onix": ["rock", "ground", 35, 45, 160, 30, 45, 70], -"drowzee": ["psychic", "psychic", 60, 48, 45, 43, 90, 42], -"hypno": ["psychic", "psychic", 85, 73, 70, 73, 115, 67], -"krabby": ["water", "water", 30, 105, 90, 25, 25, 50], -"kingler": ["water", "water", 55, 130, 115, 50, 50, 75], -"voltorb": ["electric", "electric", 40, 30, 50, 55, 55, 100], -"electrode": ["electric", "electric", 60, 50, 70, 80, 80, 140], -"exeggcute": ["grass", "psychic", 60, 40, 80, 60, 45, 40], -"exeggutor": ["grass", "psychic", 95, 95, 85, 125, 65, 55], -"cubone": ["ground", "ground", 50, 50, 95, 40, 50, 35], -"marowak": ["ground", "ground", 60, 80, 110, 50, 80, 45], -"hitmonlee": ["fighting", "fighting", 50, 120, 53, 35, 110, 87], -"hitmonchan": ["fighting", "fighting", 50, 105, 79, 35, 110, 76], -"lickitung": ["normal", "normal", 90, 55, 75, 60, 75, 30], -"koffing": ["poison", "poison", 40, 65, 95, 60, 45, 35], -"weezing": ["poison", "poison", 65, 90, 120, 85, 70, 60], -"rhyhorn": ["ground", "rock", 80, 85, 95, 30, 30, 25], -"rhydon": ["ground", "rock", 105, 130, 120, 45, 45, 40], -"chansey": ["normal", "normal", 250, 5, 5, 35, 105, 50], -"tangela": ["grass", "grass", 65, 55, 115, 100, 40, 60], -"kangaskhan": ["normal", "normal", 105, 95, 80, 40, 80, 90], -"horsea": ["water", "water", 30, 40, 70, 70, 25, 60], -"seadra": ["water", "water", 55, 65, 95, 95, 45, 85], -"goldeen": ["water", "water", 45, 67, 60, 35, 50, 63], -"seaking": ["water", "water", 80, 92, 65, 65, 80, 68], -"staryu": ["water", "water", 30, 45, 55, 70, 55, 85], -"starmie": ["water", "psychic", 60, 75, 85, 100, 85, 115], -"mr-mime": ["psychic", "psychic", 40, 45, 65, 100, 120, 90], -"scyther": ["bug", "flying", 70, 110, 80, 55, 80, 105], -"jynx": ["ice", "psychic", 65, 50, 35, 115, 95, 95], -"electabuzz": ["electric", "electric", 65, 83, 57, 95, 85, 105], -"magmar": ["fire", "fire", 65, 95, 57, 100, 85, 93], -"pinsir": ["bug", "bug", 65, 125, 100, 55, 70, 85], -"tauros": ["normal", "normal", 75, 100, 95, 40, 70, 110], -"magikarp": ["water", "water", 20, 10, 55, 15, 20, 80], -"gyarados": ["water", "flying", 95, 125, 79, 60, 100, 81], -"lapras": ["water", "ice", 130, 85, 80, 85, 95, 60], -"ditto": ["normal", "normal", 48, 48, 48, 48, 48, 48], -"eevee": ["normal", "normal", 55, 55, 50, 45, 65, 55], -"vaporeon": ["water", "water", 130, 65, 60, 110, 95, 65], -"jolteon": ["electric", "electric", 65, 65, 60, 110, 95, 130], -"flareon": ["fire", "fire", 65, 130, 60, 95, 110, 65], -"porygon": ["normal", "normal", 65, 60, 70, 85, 75, 40], -"omanyte": ["rock", "water", 35, 40, 100, 90, 55, 35], -"omastar": ["rock", "water", 70, 60, 125, 115, 70, 55], -"kabuto": ["rock", "water", 30, 80, 90, 55, 45, 55], -"kabutops": ["rock", "water", 60, 115, 105, 65, 70, 80], -"aerodactyl": ["rock", "flying", 80, 105, 65, 60, 75, 130], -"snorlax": ["normal", "normal", 160, 110, 65, 65, 110, 30], -"articuno": ["ice", "flying", 90, 85, 100, 95, 125, 85], -"zapdos": ["electric", "flying", 90, 90, 85, 125, 90, 100], -"moltres": ["fire", "flying", 90, 100, 90, 125, 85, 90], -"dratini": ["dragon", "dragon", 41, 64, 45, 50, 50, 50], -"dragonair": ["dragon", "dragon", 61, 84, 65, 70, 70, 70], -"dragonite": ["dragon", "flying", 91, 134, 95, 100, 100, 80], -"mewtwo": ["psychic", "psychic", 106, 110, 90, 154, 90, 130], -"mew": ["psychic", "psychic", 100, 100, 100, 100, 100, 100], -"chikorita": ["grass", "grass", 45, 49, 65, 49, 65, 45], -"bayleef": ["grass", "grass", 60, 62, 80, 63, 80, 60], -"meganium": ["grass", "grass", 80, 82, 100, 83, 100, 80], -"cyndaquil": ["fire", "fire", 39, 52, 43, 60, 50, 65], -"quilava": ["fire", "fire", 58, 64, 58, 80, 65, 80], -"typhlosion": ["fire", "fire", 78, 84, 78, 109, 85, 100], -"totodile": ["water", "water", 50, 65, 64, 44, 48, 43], -"croconaw": ["water", "water", 65, 80, 80, 59, 63, 58], -"feraligatr": ["water", "water", 85, 105, 100, 79, 83, 78], -"sentret": ["normal", "normal", 35, 46, 34, 35, 45, 20], -"furret": ["normal", "normal", 85, 76, 64, 45, 55, 90], -"hoothoot": ["normal", "flying", 60, 30, 30, 36, 56, 50], -"noctowl": ["normal", "flying", 100, 50, 50, 76, 96, 70], -"ledyba": ["bug", "flying", 40, 20, 30, 40, 80, 55], -"ledian": ["bug", "flying", 55, 35, 50, 55, 110, 85], -"spinarak": ["bug", "poison", 40, 60, 40, 40, 40, 30], -"ariados": ["bug", "poison", 70, 90, 70, 60, 60, 40], -"crobat": ["poison", "flying", 85, 90, 80, 70, 80, 130], -"chinchou": ["water", "electric", 75, 38, 38, 56, 56, 67], -"lanturn": ["water", "electric", 125, 58, 58, 76, 76, 67], -"pichu": ["electric", "electric", 20, 40, 15, 35, 35, 60], -"cleffa": ["normal", "normal", 50, 25, 28, 45, 55, 15], -"igglybuff": ["normal", "normal", 90, 30, 15, 40, 20, 15], -"togepi": ["normal", "normal", 35, 20, 65, 40, 65, 20], -"togetic": ["normal", "flying", 55, 40, 85, 80, 105, 40], -"natu": ["psychic", "flying", 40, 50, 45, 70, 45, 70], -"xatu": ["psychic", "flying", 65, 75, 70, 95, 70, 95], -"mareep": ["electric", "electric", 55, 40, 40, 65, 45, 35], -"flaaffy": ["electric", "electric", 70, 55, 55, 80, 60, 45], -"ampharos": ["electric", "electric", 90, 75, 75, 115, 90, 55], -"bellossom": ["grass", "grass", 75, 80, 85, 90, 100, 50], -"marill": ["water", "water", 70, 20, 50, 20, 50, 40], -"azumarill": ["water", "water", 100, 50, 80, 50, 80, 50], -"sudowoodo": ["rock", "rock", 70, 100, 115, 30, 65, 30], -"politoed": ["water", "water", 90, 75, 75, 90, 100, 70], -"hoppip": ["grass", "flying", 35, 35, 40, 35, 55, 50], -"skiploom": ["grass", "flying", 55, 45, 50, 45, 65, 80], -"jumpluff": ["grass", "flying", 75, 55, 70, 55, 85, 110], -"aipom": ["normal", "normal", 55, 70, 55, 40, 55, 85], -"sunkern": ["grass", "grass", 30, 30, 30, 30, 30, 30], -"sunflora": ["grass", "grass", 75, 75, 55, 105, 85, 30], -"yanma": ["bug", "flying", 65, 65, 45, 75, 45, 95], -"wooper": ["water", "ground", 55, 45, 45, 25, 25, 15], -"quagsire": ["water", "ground", 95, 85, 85, 65, 65, 35], -"espeon": ["psychic", "psychic", 65, 65, 60, 130, 95, 110], -"umbreon": ["dark", "dark", 95, 65, 110, 60, 130, 65], -"murkrow": ["dark", "flying", 60, 85, 42, 85, 42, 91], -"slowking": ["water", "psychic", 95, 75, 80, 100, 110, 30], -"misdreavus": ["ghost", "ghost", 60, 60, 60, 85, 85, 85], -"unown": ["psychic", "psychic", 48, 72, 48, 72, 48, 48], -"wobbuffet": ["psychic", "psychic", 190, 33, 58, 33, 58, 33], -"girafarig": ["normal", "psychic", 70, 80, 65, 90, 65, 85], -"pineco": ["bug", "bug", 50, 65, 90, 35, 35, 15], -"forretress": ["bug", "steel", 75, 90, 140, 60, 60, 40], -"dunsparce": ["normal", "normal", 100, 70, 70, 65, 65, 45], -"gligar": ["ground", "flying", 65, 75, 105, 35, 65, 85], -"steelix": ["steel", "ground", 75, 85, 200, 55, 65, 30], -"snubbull": ["normal", "normal", 60, 80, 50, 40, 40, 30], -"granbull": ["normal", "normal", 90, 120, 75, 60, 60, 45], -"qwilfish": ["water", "poison", 65, 95, 75, 55, 55, 85], -"scizor": ["bug", "steel", 70, 130, 100, 55, 80, 65], -"shuckle": ["bug", "rock", 20, 10, 230, 10, 230, 5], -"heracross": ["bug", "fighting", 80, 125, 75, 40, 95, 85], -"sneasel": ["dark", "ice", 55, 95, 55, 35, 75, 115], -"teddiursa": ["normal", "normal", 60, 80, 50, 50, 50, 40], -"ursaring": ["normal", "normal", 90, 130, 75, 75, 75, 55], -"slugma": ["fire", "fire", 40, 40, 40, 70, 40, 20], -"magcargo": ["fire", "rock", 50, 50, 120, 80, 80, 30], -"swinub": ["ice", "ground", 50, 50, 40, 30, 30, 50], -"piloswine": ["ice", "ground", 100, 100, 80, 60, 60, 50], -"corsola": ["water", "rock", 55, 55, 85, 65, 85, 35], -"remoraid": ["water", "water", 35, 65, 35, 65, 35, 65], -"octillery": ["water", "water", 75, 105, 75, 105, 75, 45], -"delibird": ["ice", "flying", 45, 55, 45, 65, 45, 75], -"mantine": ["water", "flying", 65, 40, 70, 80, 140, 70], -"skarmory": ["steel", "flying", 65, 80, 140, 40, 70, 70], -"houndour": ["dark", "fire", 45, 60, 30, 80, 50, 65], -"houndoom": ["dark", "fire", 75, 90, 50, 110, 80, 95], -"kingdra": ["water", "dragon", 75, 95, 95, 95, 95, 85], -"phanpy": ["ground", "ground", 90, 60, 60, 40, 40, 40], -"donphan": ["ground", "ground", 90, 120, 120, 60, 60, 50], -"porygon2": ["normal", "normal", 85, 80, 90, 105, 95, 60], -"stantler": ["normal", "normal", 73, 95, 62, 85, 65, 85], -"smeargle": ["normal", "normal", 55, 20, 35, 20, 45, 75], -"tyrogue": ["fighting", "fighting", 35, 35, 35, 35, 35, 35], -"hitmontop": ["fighting", "fighting", 50, 95, 95, 35, 110, 70], -"smoochum": ["ice", "psychic", 45, 30, 15, 85, 65, 65], -"elekid": ["electric", "electric", 45, 63, 37, 65, 55, 95], -"magby": ["fire", "fire", 45, 75, 37, 70, 55, 83], -"miltank": ["normal", "normal", 95, 80, 105, 40, 70, 100], -"blissey": ["normal", "normal", 255, 10, 10, 75, 135, 55], -"raikou": ["electric", "electric", 90, 85, 75, 115, 100, 115], -"entei": ["fire", "fire", 115, 115, 85, 90, 75, 100], -"suicune": ["water", "water", 100, 75, 115, 90, 115, 85], -"larvitar": ["rock", "ground", 50, 64, 50, 45, 50, 41], -"pupitar": ["rock", "ground", 70, 84, 70, 65, 70, 51], -"tyranitar": ["rock", "dark", 100, 134, 110, 95, 100, 61], -"lugia": ["psychic", "flying", 106, 90, 130, 90, 154, 110], -"ho-oh": ["fire", "flying", 106, 130, 90, 110, 154, 90], -"celebi": ["psychic", "grass", 100, 100, 100, 100, 100, 100], -"treecko": ["grass", "grass", 40, 45, 35, 65, 55, 70], -"grovyle": ["grass", "grass", 50, 65, 45, 85, 65, 95], -"sceptile": ["grass", "grass", 70, 85, 65, 105, 85, 120], -"torchic": ["fire", "fire", 45, 60, 40, 70, 50, 45], -"combusken": ["fire", "fighting", 60, 85, 60, 85, 60, 55], -"blaziken": ["fire", "fighting", 80, 120, 70, 110, 70, 80], -"mudkip": ["water", "water", 50, 70, 50, 50, 50, 40], -"marshtomp": ["water", "ground", 70, 85, 70, 60, 70, 50], -"swampert": ["water", "ground", 100, 110, 90, 85, 90, 60], -"poochyena": ["dark", "dark", 35, 55, 35, 30, 30, 35], -"mightyena": ["dark", "dark", 70, 90, 70, 60, 60, 70], -"zigzagoon": ["normal", "normal", 38, 30, 41, 30, 41, 60], -"linoone": ["normal", "normal", 78, 70, 61, 50, 61, 100], -"wurmple": ["bug", "bug", 45, 45, 35, 20, 30, 20], -"silcoon": ["bug", "bug", 50, 35, 55, 25, 25, 15], -"beautifly": ["bug", "flying", 60, 70, 50, 90, 50, 65], -"cascoon": ["bug", "bug", 50, 35, 55, 25, 25, 15], -"dustox": ["bug", "poison", 60, 50, 70, 50, 90, 65], -"lotad": ["water", "grass", 40, 30, 30, 40, 50, 30], -"lombre": ["water", "grass", 60, 50, 50, 60, 70, 50], -"ludicolo": ["water", "grass", 80, 70, 70, 90, 100, 70], -"seedot": ["grass", "grass", 40, 40, 50, 30, 30, 30], -"nuzleaf": ["grass", "dark", 70, 70, 40, 60, 40, 60], -"shiftry": ["grass", "dark", 90, 100, 60, 90, 60, 80], -"nincada": ["bug", "ground", 31, 45, 90, 30, 30, 40], -"ninjask": ["bug", "flying", 61, 90, 45, 50, 50, 160], -"shedinja": ["bug", "ghost", 1, 90, 45, 30, 30, 40], -"taillow": ["normal", "flying", 40, 55, 30, 30, 30, 85], -"swellow": ["normal", "flying", 60, 85, 60, 50, 50, 125], -"shroomish": ["grass", "grass", 60, 40, 60, 40, 60, 35], -"breloom": ["grass", "fighting", 60, 130, 80, 60, 60, 70], -"spinda": ["normal", "normal", 60, 60, 60, 60, 60, 60], -"wingull": ["water", "flying", 40, 30, 30, 55, 30, 85], -"pelipper": ["water", "flying", 60, 50, 100, 85, 70, 65], -"surskit": ["bug", "water", 40, 30, 32, 50, 52, 65], -"masquerain": ["bug", "flying", 70, 60, 62, 80, 82, 60], -"wailmer": ["water", "water", 130, 70, 35, 70, 35, 60], -"wailord": ["water", "water", 170, 90, 45, 90, 45, 60], -"skitty": ["normal", "normal", 50, 45, 45, 35, 35, 50], -"delcatty": ["normal", "normal", 70, 65, 65, 55, 55, 70], -"kecleon": ["normal", "normal", 60, 90, 70, 60, 120, 40], -"baltoy": ["ground", "psychic", 40, 40, 55, 40, 70, 55], -"claydol": ["ground", "psychic", 60, 70, 105, 70, 120, 75], -"nosepass": ["rock", "rock", 30, 45, 135, 45, 90, 30], -"torkoal": ["fire", "fire", 70, 85, 140, 85, 70, 20], -"sableye": ["dark", "ghost", 50, 75, 75, 65, 65, 50], -"barboach": ["water", "ground", 50, 48, 43, 46, 41, 60], -"whiscash": ["water", "ground", 110, 78, 73, 76, 71, 60], -"luvdisc": ["water", "water", 43, 30, 55, 40, 65, 97], -"corphish": ["water", "water", 43, 80, 65, 50, 35, 35], -"crawdaunt": ["water", "dark", 63, 120, 85, 90, 55, 55], -"feebas": ["water", "water", 20, 15, 20, 10, 55, 80], -"milotic": ["water", "water", 95, 60, 79, 100, 125, 81], -"carvanha": ["water", "dark", 45, 90, 20, 65, 20, 65], -"sharpedo": ["water", "dark", 70, 120, 40, 95, 40, 95], -"trapinch": ["ground", "ground", 45, 100, 45, 45, 45, 10], -"vibrava": ["ground", "dragon", 50, 70, 50, 50, 50, 70], -"flygon": ["ground", "dragon", 80, 100, 80, 80, 80, 100], -"makuhita": ["fighting", "fighting", 72, 60, 30, 20, 30, 25], -"hariyama": ["fighting", "fighting", 144, 120, 60, 40, 60, 50], -"electrike": ["electric", "electric", 40, 45, 40, 65, 40, 65], -"manectric": ["electric", "electric", 70, 75, 60, 105, 60, 105], -"numel": ["fire", "ground", 60, 60, 40, 65, 45, 35], -"camerupt": ["fire", "ground", 70, 100, 70, 105, 75, 40], -"spheal": ["ice", "water", 70, 40, 50, 55, 50, 25], -"sealeo": ["ice", "water", 90, 60, 70, 75, 70, 45], -"walrein": ["ice", "water", 110, 80, 90, 95, 90, 65], -"cacnea": ["grass", "grass", 50, 85, 40, 85, 40, 35], -"cacturne": ["grass", "dark", 70, 115, 60, 115, 60, 55], -"snorunt": ["ice", "ice", 50, 50, 50, 50, 50, 50], -"glalie": ["ice", "ice", 80, 80, 80, 80, 80, 80], -"lunatone": ["rock", "psychic", 70, 55, 65, 95, 85, 70], -"solrock": ["rock", "psychic", 70, 95, 85, 55, 65, 70], -"azurill": ["normal", "normal", 50, 20, 40, 20, 40, 20], -"spoink": ["psychic", "psychic", 60, 25, 35, 70, 80, 60], -"grumpig": ["psychic", "psychic", 80, 45, 65, 90, 110, 80], -"plusle": ["electric", "electric", 60, 50, 40, 85, 75, 95], -"minun": ["electric", "electric", 60, 40, 50, 75, 85, 95], -"mawile": ["steel", "steel", 50, 85, 85, 55, 55, 50], -"meditite": ["fighting", "psychic", 30, 40, 55, 40, 55, 60], -"medicham": ["fighting", "psychic", 60, 60, 75, 60, 75, 80], -"swablu": ["normal", "flying", 45, 40, 60, 40, 75, 50], -"altaria": ["dragon", "flying", 75, 70, 90, 70, 105, 80], -"wynaut": ["psychic", "psychic", 95, 23, 48, 23, 48, 23], -"duskull": ["ghost", "ghost", 20, 40, 90, 30, 90, 25], -"dusclops": ["ghost", "ghost", 40, 70, 130, 60, 130, 25], -"roselia": ["grass", "poison", 50, 60, 45, 100, 80, 65], -"slakoth": ["normal", "normal", 60, 60, 60, 35, 35, 30], -"vigoroth": ["normal", "normal", 80, 80, 80, 55, 55, 90], -"slaking": ["normal", "normal", 150, 160, 100, 95, 65, 100], -"gulpin": ["poison", "poison", 70, 43, 53, 43, 53, 40], -"swalot": ["poison", "poison", 100, 73, 83, 73, 83, 55], -"tropius": ["grass", "flying", 99, 68, 83, 72, 87, 51], -"whismur": ["normal", "normal", 64, 51, 23, 51, 23, 28], -"loudred": ["normal", "normal", 84, 71, 43, 71, 43, 48], -"exploud": ["normal", "normal", 104, 91, 63, 91, 63, 68], -"clamperl": ["water", "water", 35, 64, 85, 74, 55, 32], -"huntail": ["water", "water", 55, 104, 105, 94, 75, 52], -"gorebyss": ["water", "water", 55, 84, 105, 114, 75, 52], -"absol": ["dark", "dark", 65, 130, 60, 75, 60, 75], -"shuppet": ["ghost", "ghost", 44, 75, 35, 63, 33, 45], -"banette": ["ghost", "ghost", 64, 115, 65, 83, 63, 65], -"seviper": ["poison", "poison", 73, 100, 60, 100, 60, 65], -"zangoose": ["normal", "normal", 73, 115, 60, 60, 60, 90], -"relicanth": ["water", "rock", 100, 90, 130, 45, 65, 55], -"aron": ["steel", "rock", 50, 70, 100, 40, 40, 30], -"lairon": ["steel", "rock", 60, 90, 140, 50, 50, 40], -"aggron": ["steel", "rock", 70, 110, 180, 60, 60, 50], -"castform": ["normal", "normal", 70, 70, 70, 70, 70, 70], -"volbeat": ["bug", "bug", 65, 73, 55, 47, 75, 85], -"illumise": ["bug", "bug", 65, 47, 55, 73, 75, 85], -"lileep": ["rock", "grass", 66, 41, 77, 61, 87, 23], -"cradily": ["rock", "grass", 86, 81, 97, 81, 107, 43], -"anorith": ["rock", "bug", 45, 95, 50, 40, 50, 75], -"armaldo": ["rock", "bug", 75, 125, 100, 70, 80, 45], -"ralts": ["psychic", "psychic", 28, 25, 25, 45, 35, 40], -"kirlia": ["psychic", "psychic", 38, 35, 35, 65, 55, 50], -"gardevoir": ["psychic", "psychic", 68, 65, 65, 125, 115, 80], -"bagon": ["dragon", "dragon", 45, 75, 60, 40, 30, 50], -"shelgon": ["dragon", "dragon", 65, 95, 100, 60, 50, 50], -"salamence": ["dragon", "flying", 95, 135, 80, 110, 80, 100], -"beldum": ["steel", "psychic", 40, 55, 80, 35, 60, 30], -"metang": ["steel", "psychic", 60, 75, 100, 55, 80, 50], -"metagross": ["steel", "psychic", 80, 135, 130, 95, 90, 70], -"regirock": ["rock", "rock", 80, 100, 200, 50, 100, 50], -"regice": ["ice", "ice", 80, 50, 100, 100, 200, 50], -"registeel": ["steel", "steel", 80, 75, 150, 75, 150, 50], -"kyogre": ["water", "water", 100, 100, 90, 150, 140, 90], -"groudon": ["ground", "ground", 100, 150, 140, 100, 90, 90], -"rayquaza": ["dragon", "flying", 105, 150, 90, 150, 90, 95], -"latias": ["dragon", "psychic", 80, 80, 90, 110, 130, 110], -"latios": ["dragon", "psychic", 80, 90, 80, 130, 110, 110], -"jirachi": ["steel", "psychic", 100, 100, 100, 100, 100, 100], -"deoxys": ["psychic", "psychic", 50, 150, 50, 150, 50, 150], -"chimecho": ["psychic", "psychic", 65, 50, 70, 95, 80, 65] +"bulbasaur": ["grass", "poison"], +"ivysaur": ["grass", "poison"], +"venusaur": ["grass", "poison"], +"charmander": ["fire", "fire"], +"charmeleon": ["fire", "fire"], +"charizard": ["fire", "flying"], +"squirtle": ["water", "water"], +"wartortle": ["water", "water"], +"blastoise": ["water", "water"], +"caterpie": ["bug", "bug"], +"metapod": ["bug", "bug"], +"butterfree": ["bug", "flying"], +"weedle": ["bug", "poison"], +"kakuna": ["bug", "poison"], +"beedrill": ["bug", "poison"], +"pidgey": ["normal", "flying"], +"pidgeotto": ["normal", "flying"], +"pidgeot": ["normal", "flying"], +"rattata": ["normal", "normal"], +"raticate": ["normal", "normal"], +"spearow": ["normal", "flying"], +"fearow": ["normal", "flying"], +"ekans": ["poison", "poison"], +"arbok": ["poison", "poison"], +"pikachu": ["electric", "electric"], +"raichu": ["electric", "electric"], +"sandshrew": ["ground", "ground"], +"sandslash": ["ground", "ground"], +"nidoran-f": ["poison", "poison"], +"nidorina": ["poison", "poison"], +"nidoqueen": ["poison", "ground"], +"nidoran-m": ["poison", "poison"], +"nidorino": ["poison", "poison"], +"nidoking": ["poison", "ground"], +"clefairy": ["normal", "normal"], +"clefable": ["normal", "normal"], +"vulpix": ["fire", "fire"], +"ninetales": ["fire", "fire"], +"jigglypuff": ["normal", "normal"], +"wigglytuff": ["normal", "normal"], +"zubat": ["poison", "flying"], +"golbat": ["poison", "flying"], +"oddish": ["grass", "poison"], +"gloom": ["grass", "poison"], +"vileplume": ["grass", "poison"], +"paras": ["bug", "grass"], +"parasect": ["bug", "grass"], +"venonat": ["bug", "poison"], +"venomoth": ["bug", "poison"], +"diglett": ["ground", "ground"], +"dugtrio": ["ground", "ground"], +"meowth": ["normal", "normal"], +"persian": ["normal", "normal"], +"psyduck": ["water", "water"], +"golduck": ["water", "water"], +"mankey": ["fighting", "fighting"], +"primeape": ["fighting", "fighting"], +"growlithe": ["fire", "fire"], +"arcanine": ["fire", "fire"], +"poliwag": ["water", "water"], +"poliwhirl": ["water", "water"], +"poliwrath": ["water", "fighting"], +"abra": ["psychic", "psychic"], +"kadabra": ["psychic", "psychic"], +"alakazam": ["psychic", "psychic"], +"machop": ["fighting", "fighting"], +"machoke": ["fighting", "fighting"], +"machamp": ["fighting", "fighting"], +"bellsprout": ["grass", "poison"], +"weepinbell": ["grass", "poison"], +"victreebel": ["grass", "poison"], +"tentacool": ["water", "poison"], +"tentacruel": ["water", "poison"], +"geodude": ["rock", "ground"], +"graveler": ["rock", "ground"], +"golem": ["rock", "ground"], +"ponyta": ["fire", "fire"], +"rapidash": ["fire", "fire"], +"slowpoke": ["water", "psychic"], +"slowbro": ["water", "psychic"], +"magnemite": ["electric", "steel"], +"magneton": ["electric", "steel"], +"farfetch-d": ["normal", "flying"], +"doduo": ["normal", "flying"], +"dodrio": ["normal", "flying"], +"seel": ["water", "water"], +"dewgong": ["water", "ice"], +"grimer": ["poison", "poison"], +"muk": ["poison", "poison"], +"shellder": ["water", "water"], +"cloyster": ["water", "ice"], +"gastly": ["ghost", "poison"], +"haunter": ["ghost", "poison"], +"gengar": ["ghost", "poison"], +"onix": ["rock", "ground"], +"drowzee": ["psychic", "psychic"], +"hypno": ["psychic", "psychic"], +"krabby": ["water", "water"], +"kingler": ["water", "water"], +"voltorb": ["electric", "electric"], +"electrode": ["electric", "electric"], +"exeggcute": ["grass", "psychic"], +"exeggutor": ["grass", "psychic"], +"cubone": ["ground", "ground"], +"marowak": ["ground", "ground"], +"hitmonlee": ["fighting", "fighting"], +"hitmonchan": ["fighting", "fighting"], +"lickitung": ["normal", "normal"], +"koffing": ["poison", "poison"], +"weezing": ["poison", "poison"], +"rhyhorn": ["ground", "rock"], +"rhydon": ["ground", "rock"], +"chansey": ["normal", "normal"], +"tangela": ["grass", "grass"], +"kangaskhan": ["normal", "normal"], +"horsea": ["water", "water"], +"seadra": ["water", "water"], +"goldeen": ["water", "water"], +"seaking": ["water", "water"], +"staryu": ["water", "water"], +"starmie": ["water", "psychic"], +"mr-mime": ["psychic", "psychic"], +"scyther": ["bug", "flying"], +"jynx": ["ice", "psychic"], +"electabuzz": ["electric", "electric"], +"magmar": ["fire", "fire"], +"pinsir": ["bug", "bug"], +"tauros": ["normal", "normal"], +"magikarp": ["water", "water"], +"gyarados": ["water", "flying"], +"lapras": ["water", "ice"], +"ditto": ["normal", "normal"], +"eevee": ["normal", "normal"], +"vaporeon": ["water", "water"], +"jolteon": ["electric", "electric"], +"flareon": ["fire", "fire"], +"porygon": ["normal", "normal"], +"omanyte": ["rock", "water"], +"omastar": ["rock", "water"], +"kabuto": ["rock", "water"], +"kabutops": ["rock", "water"], +"aerodactyl": ["rock", "flying"], +"snorlax": ["normal", "normal"], +"articuno": ["ice", "flying"], +"zapdos": ["electric", "flying"], +"moltres": ["fire", "flying"], +"dratini": ["dragon", "dragon"], +"dragonair": ["dragon", "dragon"], +"dragonite": ["dragon", "flying"], +"mewtwo": ["psychic", "psychic"], +"mew": ["psychic", "psychic"], +"chikorita": ["grass", "grass"], +"bayleef": ["grass", "grass"], +"meganium": ["grass", "grass"], +"cyndaquil": ["fire", "fire"], +"quilava": ["fire", "fire"], +"typhlosion": ["fire", "fire"], +"totodile": ["water", "water"], +"croconaw": ["water", "water"], +"feraligatr": ["water", "water"], +"sentret": ["normal", "normal"], +"furret": ["normal", "normal"], +"hoothoot": ["normal", "flying"], +"noctowl": ["normal", "flying"], +"ledyba": ["bug", "flying"], +"ledian": ["bug", "flying"], +"spinarak": ["bug", "poison"], +"ariados": ["bug", "poison"], +"crobat": ["poison", "flying"], +"chinchou": ["water", "electric"], +"lanturn": ["water", "electric"], +"pichu": ["electric", "electric"], +"cleffa": ["normal", "normal"], +"igglybuff": ["normal", "normal"], +"togepi": ["normal", "normal"], +"togetic": ["normal", "flying"], +"natu": ["psychic", "flying"], +"xatu": ["psychic", "flying"], +"mareep": ["electric", "electric"], +"flaaffy": ["electric", "electric"], +"ampharos": ["electric", "electric"], +"bellossom": ["grass", "grass"], +"marill": ["water", "water"], +"azumarill": ["water", "water"], +"sudowoodo": ["rock", "rock"], +"politoed": ["water", "water"], +"hoppip": ["grass", "flying"], +"skiploom": ["grass", "flying"], +"jumpluff": ["grass", "flying"], +"aipom": ["normal", "normal"], +"sunkern": ["grass", "grass"], +"sunflora": ["grass", "grass"], +"yanma": ["bug", "flying"], +"wooper": ["water", "ground"], +"quagsire": ["water", "ground"], +"espeon": ["psychic", "psychic"], +"umbreon": ["dark", "dark"], +"murkrow": ["dark", "flying"], +"slowking": ["water", "psychic"], +"misdreavus": ["ghost", "ghost"], +"unown": ["psychic", "psychic"], +"wobbuffet": ["psychic", "psychic"], +"girafarig": ["normal", "psychic"], +"pineco": ["bug", "bug"], +"forretress": ["bug", "steel"], +"dunsparce": ["normal", "normal"], +"gligar": ["ground", "flying"], +"steelix": ["steel", "ground"], +"snubbull": ["normal", "normal"], +"granbull": ["normal", "normal"], +"qwilfish": ["water", "poison"], +"scizor": ["bug", "steel"], +"shuckle": ["bug", "rock"], +"heracross": ["bug", "fighting"], +"sneasel": ["dark", "ice"], +"teddiursa": ["normal", "normal"], +"ursaring": ["normal", "normal"], +"slugma": ["fire", "fire"], +"magcargo": ["fire", "rock"], +"swinub": ["ice", "ground"], +"piloswine": ["ice", "ground"], +"corsola": ["water", "rock"], +"remoraid": ["water", "water"], +"octillery": ["water", "water"], +"delibird": ["ice", "flying"], +"mantine": ["water", "flying"], +"skarmory": ["steel", "flying"], +"houndour": ["dark", "fire"], +"houndoom": ["dark", "fire"], +"kingdra": ["water", "dragon"], +"phanpy": ["ground", "ground"], +"donphan": ["ground", "ground"], +"porygon2": ["normal", "normal"], +"stantler": ["normal", "normal"], +"smeargle": ["normal", "normal"], +"tyrogue": ["fighting", "fighting"], +"hitmontop": ["fighting", "fighting"], +"smoochum": ["ice", "psychic"], +"elekid": ["electric", "electric"], +"magby": ["fire", "fire"], +"miltank": ["normal", "normal"], +"blissey": ["normal", "normal"], +"raikou": ["electric", "electric"], +"entei": ["fire", "fire"], +"suicune": ["water", "water"], +"larvitar": ["rock", "ground"], +"pupitar": ["rock", "ground"], +"tyranitar": ["rock", "dark"], +"lugia": ["psychic", "flying"], +"ho-oh": ["fire", "flying"], +"celebi": ["psychic", "grass"], +"treecko": ["grass", "grass"], +"grovyle": ["grass", "grass"], +"sceptile": ["grass", "grass"], +"torchic": ["fire", "fire"], +"combusken": ["fire", "fighting"], +"blaziken": ["fire", "fighting"], +"mudkip": ["water", "water"], +"marshtomp": ["water", "ground"], +"swampert": ["water", "ground"], +"poochyena": ["dark", "dark"], +"mightyena": ["dark", "dark"], +"zigzagoon": ["normal", "normal"], +"linoone": ["normal", "normal"], +"wurmple": ["bug", "bug"], +"silcoon": ["bug", "bug"], +"beautifly": ["bug", "flying"], +"cascoon": ["bug", "bug"], +"dustox": ["bug", "poison"], +"lotad": ["water", "grass"], +"lombre": ["water", "grass"], +"ludicolo": ["water", "grass"], +"seedot": ["grass", "grass"], +"nuzleaf": ["grass", "dark"], +"shiftry": ["grass", "dark"], +"nincada": ["bug", "ground"], +"ninjask": ["bug", "flying"], +"shedinja": ["bug", "ghost"], +"taillow": ["normal", "flying"], +"swellow": ["normal", "flying"], +"shroomish": ["grass", "grass"], +"breloom": ["grass", "fighting"], +"spinda": ["normal", "normal"], +"wingull": ["water", "flying"], +"pelipper": ["water", "flying"], +"surskit": ["bug", "water"], +"masquerain": ["bug", "flying"], +"wailmer": ["water", "water"], +"wailord": ["water", "water"], +"skitty": ["normal", "normal"], +"delcatty": ["normal", "normal"], +"kecleon": ["normal", "normal"], +"baltoy": ["ground", "psychic"], +"claydol": ["ground", "psychic"], +"nosepass": ["rock", "rock"], +"torkoal": ["fire", "fire"], +"sableye": ["dark", "ghost"], +"barboach": ["water", "ground"], +"whiscash": ["water", "ground"], +"luvdisc": ["water", "water"], +"corphish": ["water", "water"], +"crawdaunt": ["water", "dark"], +"feebas": ["water", "water"], +"milotic": ["water", "water"], +"carvanha": ["water", "dark"], +"sharpedo": ["water", "dark"], +"trapinch": ["ground", "ground"], +"vibrava": ["ground", "dragon"], +"flygon": ["ground", "dragon"], +"makuhita": ["fighting", "fighting"], +"hariyama": ["fighting", "fighting"], +"electrike": ["electric", "electric"], +"manectric": ["electric", "electric"], +"numel": ["fire", "ground"], +"camerupt": ["fire", "ground"], +"spheal": ["ice", "water"], +"sealeo": ["ice", "water"], +"walrein": ["ice", "water"], +"cacnea": ["grass", "grass"], +"cacturne": ["grass", "dark"], +"snorunt": ["ice", "ice"], +"glalie": ["ice", "ice"], +"lunatone": ["rock", "psychic"], +"solrock": ["rock", "psychic"], +"azurill": ["normal", "normal"], +"spoink": ["psychic", "psychic"], +"grumpig": ["psychic", "psychic"], +"plusle": ["electric", "electric"], +"minun": ["electric", "electric"], +"mawile": ["steel", "steel"], +"meditite": ["fighting", "psychic"], +"medicham": ["fighting", "psychic"], +"swablu": ["normal", "flying"], +"altaria": ["dragon", "flying"], +"wynaut": ["psychic", "psychic"], +"duskull": ["ghost", "ghost"], +"dusclops": ["ghost", "ghost"], +"roselia": ["grass", "poison"], +"slakoth": ["normal", "normal"], +"vigoroth": ["normal", "normal"], +"slaking": ["normal", "normal"], +"gulpin": ["poison", "poison"], +"swalot": ["poison", "poison"], +"tropius": ["grass", "flying"], +"whismur": ["normal", "normal"], +"loudred": ["normal", "normal"], +"exploud": ["normal", "normal"], +"clamperl": ["water", "water"], +"huntail": ["water", "water"], +"gorebyss": ["water", "water"], +"absol": ["dark", "dark"], +"shuppet": ["ghost", "ghost"], +"banette": ["ghost", "ghost"], +"seviper": ["poison", "poison"], +"zangoose": ["normal", "normal"], +"relicanth": ["water", "rock"], +"aron": ["steel", "rock"], +"lairon": ["steel", "rock"], +"aggron": ["steel", "rock"], +"castform": ["normal", "normal"], +"volbeat": ["bug", "bug"], +"illumise": ["bug", "bug"], +"lileep": ["rock", "grass"], +"cradily": ["rock", "grass"], +"anorith": ["rock", "bug"], +"armaldo": ["rock", "bug"], +"ralts": ["psychic", "psychic"], +"kirlia": ["psychic", "psychic"], +"gardevoir": ["psychic", "psychic"], +"bagon": ["dragon", "dragon"], +"shelgon": ["dragon", "dragon"], +"salamence": ["dragon", "flying"], +"beldum": ["steel", "psychic"], +"metang": ["steel", "psychic"], +"metagross": ["steel", "psychic"], +"regirock": ["rock", "rock"], +"regice": ["ice", "ice"], +"registeel": ["steel", "steel"], +"kyogre": ["water", "water"], +"groudon": ["ground", "ground"], +"rayquaza": ["dragon", "flying"], +"latias": ["dragon", "psychic"], +"latios": ["dragon", "psychic"], +"jirachi": ["steel", "psychic"], +"deoxys": ["psychic", "psychic"], +"chimecho": ["psychic", "psychic"] } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json deleted file mode 100644 index 3877817c87..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json +++ /dev/null @@ -1,641 +0,0 @@ -{ -"TRAINER_YOUNGSTER_BEN": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 11, 0, 8, ["tackle", "tail-whip", "quick-attack"]], ["ekans", 11, 0, 12, ["wrap", "leer", "poison-sting"]]]}, -"TRAINER_YOUNGSTER_CALVIN": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 14, 0, 17, ["peck", "growl", "leer", "fury-attack"]]]}, -"TRAINER_YOUNGSTER_JOSH": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 10, 0, 10, ["tackle", "tail-whip", "quick-attack"]], ["rattata", 10, 0, 9, ["tackle", "tail-whip", "quick-attack"]], ["zubat", 10, 0, 10, ["leech-life", "astonish"]]]}, -"TRAINER_YOUNGSTER_TIMMY": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 14, 0, 6, ["scratch", "defense-curl", "sand-attack"]], ["ekans", 14, 0, 21, ["wrap", "leer", "poison-sting", "bite"]]]}, -"TRAINER_YOUNGSTER_JOEY": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 15, 0, 3, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["spearow", 15, 0, 16, ["peck", "growl", "leer", "fury-attack"]]]}, -"TRAINER_YOUNGSTER_DAN": {"ai": ["check-bad-move"], "items": [], "party": [["slowpoke", 17, 0, 22, ["tackle", "growl", "water-gun", "confusion"]]]}, -"TRAINER_YOUNGSTER_CHAD": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 14, 0, 1, ["wrap", "leer", "poison-sting", "bite"]], ["sandshrew", 14, 0, 21, ["scratch", "defense-curl", "sand-attack"]]]}, -"TRAINER_YOUNGSTER_TYLER": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 21, 0, 19, ["focus-energy", "double-kick", "poison-sting", "horn-attack"]]]}, -"TRAINER_YOUNGSTER_EDDIE": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 21, 0, 8, ["leer", "poison-sting", "bite", "glare"]]]}, -"TRAINER_YOUNGSTER_DILLON": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 19, 0, 13, ["scratch", "defense-curl", "sand-attack", "poison-sting"]], ["zubat", 19, 0, 5, ["leech-life", "astonish", "supersonic", "bite"]]]}, -"TRAINER_YOUNGSTER_YASU": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 17, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["rattata", 17, 0, 2, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["raticate", 17, 0, 2, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]]]}, -"TRAINER_YOUNGSTER_DAVE": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 18, 0, 15, ["peck", "focus-energy", "double-kick", "poison-sting"]], ["nidorino", 18, 0, 12, ["peck", "focus-energy", "double-kick", "poison-sting"]]]}, -"TRAINER_YOUNGSTER_BEN_2": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 17, 20, 8, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["ekans", 17, 20, 12, ["wrap", "leer", "poison-sting", "bite"]]]}, -"TRAINER_BUG_CATCHER_RICK": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 6, 0, 16, ["poison-sting", "string-shot"]], ["caterpie", 6, 0, 16, ["tackle", "string-shot"]]]}, -"TRAINER_BUG_CATCHER_DOUG": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 7, 0, 2, ["poison-sting", "string-shot"]], ["kakuna", 7, 0, 23, ["harden"]], ["weedle", 7, 0, 14, ["poison-sting", "string-shot"]]]}, -"TRAINER_BUG_CATCHER_SAMMY": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 9, 0, 12, ["poison-sting", "string-shot"]]]}, -"TRAINER_BUG_CATCHER_COLTON": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 10, 0, 21, ["tackle", "string-shot"]], ["weedle", 10, 0, 11, ["poison-sting", "string-shot"]], ["caterpie", 10, 0, 21, ["tackle", "string-shot"]]]}, -"TRAINER_BUG_CATCHER_GREG": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 9, 0, 17, ["poison-sting", "string-shot"]], ["kakuna", 9, 0, 3, ["harden"]], ["caterpie", 9, 0, 4, ["tackle", "string-shot"]], ["metapod", 9, 0, 21, ["harden"]]]}, -"TRAINER_BUG_CATCHER_JAMES": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 11, 0, 19, ["tackle", "string-shot"]], ["metapod", 11, 0, 18, ["harden"]]]}, -"TRAINER_BUG_CATCHER_KENT": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 11, 0, 20, ["poison-sting", "string-shot"]], ["kakuna", 11, 0, 9, ["harden"]]]}, -"TRAINER_BUG_CATCHER_ROBBY": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 10, 0, 3, ["tackle", "string-shot"]], ["metapod", 10, 0, 11, ["harden"]], ["caterpie", 10, 0, 3, ["tackle", "string-shot"]]]}, -"TRAINER_BUG_CATCHER_CALE": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 10, 0, 16, ["tackle", "string-shot"]], ["weedle", 10, 0, 1, ["poison-sting", "string-shot"]], ["metapod", 10, 0, 22, ["harden"]], ["kakuna", 10, 0, 12, ["harden"]]]}, -"TRAINER_BUG_CATCHER_KEIGO": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 16, 0, 18, ["poison-sting", "string-shot"]], ["caterpie", 16, 0, 20, ["tackle", "string-shot"]], ["weedle", 16, 0, 2, ["poison-sting", "string-shot"]]]}, -"TRAINER_BUG_CATCHER_ELIJAH": {"ai": ["check-bad-move"], "items": [], "party": [["butterfree", 20, 0, 7, ["poison-powder", "stun-spore", "sleep-powder", "supersonic"]]]}, -"TRAINER_BUG_CATCHER_2": {"ai": ["check-bad-move"], "items": [], "party": [["metapod", 18, 0, 17, ["harden"]], ["caterpie", 18, 0, 7, ["tackle", "string-shot"]], ["venonat", 18, 0, 15, ["disable", "foresight", "supersonic", "confusion"]]]}, -"TRAINER_BUG_CATCHER_BRENT": {"ai": ["check-bad-move"], "items": [], "party": [["beedrill", 19, 0, 0, ["fury-attack", "focus-energy"]], ["beedrill", 19, 0, 14, ["fury-attack", "focus-energy"]]]}, -"TRAINER_BUG_CATCHER_CONNER": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 20, 0, 11, ["tackle", "string-shot"]], ["weedle", 20, 0, 16, ["poison-sting", "string-shot"]], ["venonat", 20, 0, 9, ["foresight", "supersonic", "confusion", "poison-powder"]]]}, -"TRAINER_LASS_JANICE": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 9, 0, 10, ["tackle", "sand-attack", "gust"]], ["pidgey", 9, 0, 0, ["tackle", "sand-attack", "gust"]]]}, -"TRAINER_LASS_SALLY": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 10, 0, 12, ["tackle", "tail-whip", "quick-attack"]], ["nidoran-f", 10, 0, 10, ["growl", "scratch", "tail-whip"]]]}, -"TRAINER_LASS_ROBIN": {"ai": ["check-bad-move"], "items": [], "party": [["jigglypuff", 14, 0, 22, ["sing", "defense-curl", "pound", "disable"]]]}, -"TRAINER_LASS_CRISSY": {"ai": ["check-bad-move"], "items": [], "party": [["paras", 31, 0, 9, ["poison-powder", "leech-life", "spore", "slash"]], ["paras", 31, 0, 23, ["poison-powder", "leech-life", "spore", "slash"]], ["parasect", 31, 0, 3, ["stun-spore", "poison-powder", "leech-life", "spore"]]]}, -"TRAINER_LASS_MIRIAM": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 11, 0, 19, ["absorb", "sweet-scent"]], ["bellsprout", 11, 0, 18, ["vine-whip", "growth", "wrap"]]]}, -"TRAINER_LASS_IRIS": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 14, 0, 16, ["growl", "encore", "sing", "double-slap"]]]}, -"TRAINER_LASS_RELI": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 16, 0, 21, ["leer", "peck", "focus-energy", "double-kick"]], ["nidoran-f", 16, 0, 3, ["growl", "scratch", "tail-whip", "double-kick"]]]}, -"TRAINER_LASS_ALI": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 12, 0, 17, ["tackle", "sand-attack", "gust"]], ["oddish", 12, 0, 22, ["absorb", "sweet-scent"]], ["bellsprout", 12, 0, 2, ["vine-whip", "growth", "wrap"]]]}, -"TRAINER_LASS_2": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 15, 0, 18, ["leer", "peck", "focus-energy", "double-kick"]], ["nidoran-f", 15, 0, 22, ["growl", "scratch", "tail-whip", "double-kick"]]]}, -"TRAINER_LASS_HALEY": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 13, 0, 6, ["absorb", "sweet-scent"]], ["pidgey", 13, 0, 9, ["tackle", "sand-attack", "gust", "quick-attack"]], ["oddish", 13, 0, 20, ["absorb", "sweet-scent"]]]}, -"TRAINER_LASS_ANN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 18, 0, 9, ["tackle", "sand-attack", "gust", "quick-attack"]], ["nidoran-f", 18, 0, 10, ["scratch", "tail-whip", "double-kick", "poison-sting"]]]}, -"TRAINER_LASS_DAWN": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 18, 0, 9, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["pikachu", 18, 0, 1, ["tail-whip", "thunder-wave", "quick-attack", "double-team"]]]}, -"TRAINER_LASS_PAIGE": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-f", 23, 0, 7, ["double-kick", "poison-sting", "bite", "helping-hand"]], ["nidorina", 23, 0, 22, ["tail-whip", "double-kick", "poison-sting", "bite"]]]}, -"TRAINER_LASS_ANDREA": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 24, 0, 24, ["scratch", "growl", "bite", "pay-day"]], ["meowth", 24, 0, 3, ["scratch", "growl", "bite", "pay-day"]], ["meowth", 24, 0, 7, ["scratch", "growl", "bite", "pay-day"]]]}, -"TRAINER_LASS_MEGAN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 19, 0, 7, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["rattata", 19, 0, 0, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["nidoran-m", 19, 0, 18, ["peck", "focus-energy", "double-kick", "poison-sting"]], ["meowth", 19, 0, 13, ["scratch", "growl", "bite", "pay-day"]], ["pikachu", 19, 0, 9, ["tail-whip", "thunder-wave", "quick-attack", "double-team"]]]}, -"TRAINER_LASS_JULIA": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 22, 0, 20, ["sing", "double-slap", "follow-me", "minimize"]], ["clefairy", 22, 0, 20, ["sing", "double-slap", "follow-me", "minimize"]]]}, -"TRAINER_LASS_KAY": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 23, 0, 15, ["sleep-powder", "poison-powder", "stun-spore", "acid"]], ["weepinbell", 23, 0, 13, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]]]}, -"TRAINER_LASS_LISA": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 23, 0, 5, ["poison-powder", "stun-spore", "sleep-powder", "acid"]], ["gloom", 23, 0, 17, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]]]}, -"TRAINER_SAILOR_EDMOND": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 18, 0, 19, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["shellder", 18, 0, 21, ["tackle", "withdraw", "icicle-spear", "supersonic"]]]}, -"TRAINER_SAILOR_TREVOR": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 17, 0, 2, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["tentacool", 17, 0, 10, ["poison-sting", "supersonic", "constrict"]]]}, -"TRAINER_SAILOR_LEONARD": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 21, 0, 13, ["tackle", "withdraw", "icicle-spear", "supersonic"]]]}, -"TRAINER_SAILOR_DUNCAN": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 17, 0, 16, ["bubble", "smokescreen", "leer"]], ["shellder", 17, 0, 5, ["tackle", "withdraw", "icicle-spear", "supersonic"]], ["tentacool", 17, 0, 17, ["poison-sting", "supersonic", "constrict"]]]}, -"TRAINER_SAILOR_HUEY": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 18, 0, 3, ["poison-sting", "supersonic", "constrict"]], ["staryu", 18, 0, 16, ["harden", "water-gun", "rapid-spin", "recover"]]]}, -"TRAINER_SAILOR_DYLAN": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 17, 0, 19, ["bubble", "smokescreen", "leer"]], ["horsea", 17, 0, 2, ["bubble", "smokescreen", "leer"]], ["horsea", 17, 0, 10, ["bubble", "smokescreen", "leer"]]]}, -"TRAINER_SAILOR_PHILLIP": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 20, 0, 22, ["leer", "focus-energy", "karate-chop", "seismic-toss"]]]}, -"TRAINER_SAILOR_DWAYNE": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 21, 0, 15, ["thunder-wave", "quick-attack", "double-team", "slam"]], ["pikachu", 21, 0, 19, ["thunder-wave", "quick-attack", "double-team", "slam"]]]}, -"TRAINER_CAMPER_LIAM": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 10, 0, 13, ["tackle", "defense-curl"]], ["sandshrew", 11, 0, 22, ["scratch", "defense-curl", "sand-attack"]]]}, -"TRAINER_CAMPER_SHANE": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 14, 0, 21, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["ekans", 14, 0, 13, ["wrap", "leer", "poison-sting", "bite"]]]}, -"TRAINER_CAMPER_ETHAN": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 18, 0, 14, ["leer", "low-kick", "karate-chop", "fury-swipes"]]]}, -"TRAINER_CAMPER_RICKY": {"ai": ["check-bad-move"], "items": [], "party": [["squirtle", 20, 0, 16, ["bubble", "withdraw", "water-gun", "bite"]]]}, -"TRAINER_CAMPER_JEFF": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 16, 0, 6, ["peck", "growl", "leer", "fury-attack"]], ["raticate", 16, 0, 22, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]]]}, -"TRAINER_CAMPER_CHRIS": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 21, 0, 4, ["roar", "ember", "leer", "odor-sleuth"]], ["charmander", 21, 0, 21, ["growl", "ember", "metal-claw", "smokescreen"]]]}, -"TRAINER_CAMPER_DREW": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 19, 0, 23, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["sandshrew", 19, 0, 22, ["scratch", "defense-curl", "sand-attack", "poison-sting"]], ["ekans", 19, 0, 16, ["wrap", "leer", "poison-sting", "bite"]], ["sandshrew", 19, 0, 15, ["scratch", "defense-curl", "sand-attack", "poison-sting"]]]}, -"TRAINER_PICNICKER_DIANA": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 19, 0, 8, ["tail-whip", "water-sport", "supersonic", "horn-attack"]]]}, -"TRAINER_PICNICKER_NANCY": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 16, 0, 15, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["pikachu", 16, 0, 13, ["tail-whip", "thunder-wave", "quick-attack", "double-team"]]]}, -"TRAINER_PICNICKER_ISABELLE": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 16, 0, 5, ["tackle", "sand-attack", "gust", "quick-attack"]], ["pidgey", 16, 0, 15, ["tackle", "sand-attack", "gust", "quick-attack"]], ["pidgey", 16, 0, 0, ["tackle", "sand-attack", "gust", "quick-attack"]]]}, -"TRAINER_PICNICKER_KELSEY": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 15, 0, 1, ["leer", "peck", "focus-energy", "double-kick"]], ["nidoran-f", 15, 0, 13, ["growl", "scratch", "tail-whip", "double-kick"]]]}, -"TRAINER_PICNICKER_ALICIA": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 18, 0, 1, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bellsprout", 18, 0, 7, ["growth", "wrap", "sleep-powder", "poison-powder"]], ["oddish", 18, 0, 13, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bellsprout", 18, 0, 19, ["growth", "wrap", "sleep-powder", "poison-powder"]]]}, -"TRAINER_PICNICKER_CAITLIN": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 23, 0, 15, ["scratch", "growl", "bite", "pay-day"]]]}, -"TRAINER_PICNICKER_HEIDI": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 20, 0, 11, ["thunder-wave", "quick-attack", "double-team", "slam"]], ["clefairy", 20, 0, 3, ["encore", "sing", "double-slap", "follow-me"]]]}, -"TRAINER_PICNICKER_CAROL": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 21, 0, 11, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["pidgeotto", 21, 0, 20, ["sand-attack", "gust", "quick-attack", "whirlwind"]]]}, -"TRAINER_PICNICKER_SOFIA": {"ai": ["check-bad-move"], "items": [], "party": [["jigglypuff", 21, 0, 24, ["defense-curl", "pound", "disable", "rollout"]], ["pidgey", 21, 0, 21, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["meowth", 21, 0, 1, ["scratch", "growl", "bite", "pay-day"]]]}, -"TRAINER_PICNICKER_MARTHA": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 22, 0, 7, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bulbasaur", 22, 0, 20, ["vine-whip", "poison-powder", "sleep-powder", "razor-leaf"]]]}, -"TRAINER_PICNICKER_TINA": {"ai": ["check-bad-move"], "items": [], "party": [["bulbasaur", 24, 0, 24, ["vine-whip", "poison-powder", "sleep-powder", "razor-leaf"]], ["ivysaur", 24, 0, 4, ["vine-whip", "poison-powder", "sleep-powder", "razor-leaf"]]]}, -"TRAINER_PICNICKER_HANNAH": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 24, 0, 9, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["meowth", 24, 0, 6, ["scratch", "growl", "bite", "pay-day"]], ["rattata", 24, 0, 1, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["pikachu", 24, 0, 24, ["thunder-wave", "quick-attack", "double-team", "slam"]], ["meowth", 24, 0, 21, ["scratch", "growl", "bite", "pay-day"]]]}, -"TRAINER_POKEMANIAC_MARK": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 29, 30, 6, ["stomp", "fury-attack", "scary-face", "rock-blast"]], ["lickitung", 29, 30, 8, ["defense-curl", "knock-off", "stomp", "wrap"]]]}, -"TRAINER_POKEMANIAC_HERMAN": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 20, 30, 17, ["tail-whip", "bone-club", "headbutt", "leer"]], ["slowpoke", 20, 30, 16, ["tackle", "growl", "water-gun", "confusion"]]]}, -"TRAINER_POKEMANIAC_COOPER": {"ai": ["check-bad-move"], "items": [], "party": [["slowpoke", 20, 30, 13, ["tackle", "growl", "water-gun", "confusion"]], ["slowpoke", 20, 30, 15, ["tackle", "growl", "water-gun", "confusion"]], ["slowpoke", 20, 30, 17, ["tackle", "growl", "water-gun", "confusion"]]]}, -"TRAINER_POKEMANIAC_STEVE": {"ai": ["check-bad-move"], "items": [], "party": [["charmander", 22, 30, 12, ["growl", "ember", "metal-claw", "smokescreen"]], ["cubone", 22, 30, 24, ["bone-club", "headbutt", "leer", "focus-energy"]]]}, -"TRAINER_POKEMANIAC_WINSTON": {"ai": ["check-bad-move"], "items": [], "party": [["slowpoke", 25, 30, 6, ["growl", "water-gun", "confusion", "disable"]]]}, -"TRAINER_POKEMANIAC_DAWSON": {"ai": ["check-bad-move"], "items": [], "party": [["charmeleon", 40, 30, 12, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]], ["lapras", 40, 30, 12, ["confuse-ray", "perish-song", "ice-beam", "rain-dance"]], ["lickitung", 40, 30, 19, ["stomp", "wrap", "disable", "slam"]]]}, -"TRAINER_POKEMANIAC_ASHTON": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 23, 30, 0, ["bone-club", "headbutt", "leer", "focus-energy"]], ["slowpoke", 23, 30, 7, ["tackle", "growl", "water-gun", "confusion"]]]}, -"TRAINER_SUPER_NERD_JOVAN": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 11, 0, 4, ["metal-sound", "tackle", "thunder-shock", "supersonic"]], ["voltorb", 11, 0, 17, ["charge", "tackle", "screech"]]]}, -"TRAINER_SUPER_NERD_MIGUEL": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 12, 0, 0, ["poison-gas", "pound", "harden", "disable"]], ["voltorb", 12, 0, 9, ["charge", "tackle", "screech"]], ["koffing", 12, 0, 2, ["poison-gas", "tackle", "smog"]]]}, -"TRAINER_SUPER_NERD_AIDAN": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 20, 0, 1, ["sonic-boom", "screech", "tackle", "charge"]], ["koffing", 20, 0, 0, ["sludge", "smog", "tackle", "poison-gas"]], ["voltorb", 20, 0, 15, ["sonic-boom", "screech", "tackle", "charge"]], ["magnemite", 20, 0, 10, ["sonic-boom", "supersonic", "thunder-shock", "tackle"]]]}, -"TRAINER_SUPER_NERD_GLENN": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 22, 0, 19, ["harden", "disable", "sludge", "minimize"]], ["muk", 22, 0, 4, ["harden", "disable", "sludge", "minimize"]], ["grimer", 22, 0, 12, ["harden", "disable", "sludge", "minimize"]]]}, -"TRAINER_SUPER_NERD_LESLIE": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 26, 0, 24, ["sludge", "smokescreen", "smog", "self-destruct"]]]}, -"TRAINER_SUPER_NERD_1": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 22, 0, 6, ["tackle", "smog", "self-destruct", "sludge"]], ["magnemite", 22, 0, 22, ["thunder-shock", "supersonic", "sonic-boom", "thunder-wave"]], ["weezing", 22, 0, 18, ["tackle", "smog", "self-destruct", "sludge"]]]}, -"TRAINER_SUPER_NERD_2": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 20, 0, 2, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["magnemite", 20, 0, 18, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["koffing", 20, 0, 13, ["poison-gas", "tackle", "smog", "self-destruct"]], ["magnemite", 20, 0, 4, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]]]}, -"TRAINER_SUPER_NERD_3": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 24, 0, 2, ["thunder-shock", "supersonic", "sonic-boom", "thunder-wave"]], ["voltorb", 24, 0, 13, ["tackle", "screech", "sonic-boom", "spark"]]]}, -"TRAINER_SUPER_NERD_ERIK": {"ai": ["check-bad-move"], "items": [], "party": [["vulpix", 36, 0, 3, ["confuse-ray", "imprison", "flamethrower", "safeguard"]], ["vulpix", 36, 0, 20, ["confuse-ray", "imprison", "flamethrower", "safeguard"]], ["ninetales", 36, 0, 5, ["ember", "quick-attack", "confuse-ray", "safeguard"]]]}, -"TRAINER_SUPER_NERD_AVERY": {"ai": ["check-bad-move"], "items": [], "party": [["ponyta", 34, 0, 9, ["ember", "stomp", "fire-spin", "take-down"]], ["charmander", 34, 0, 10, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]], ["vulpix", 34, 0, 11, ["confuse-ray", "imprison", "flamethrower", "safeguard"]], ["growlithe", 34, 0, 13, ["leer", "odor-sleuth", "take-down", "flame-wheel"]]]}, -"TRAINER_SUPER_NERD_DEREK": {"ai": ["check-bad-move"], "items": [], "party": [["rapidash", 41, 0, 8, ["fire-spin", "take-down", "agility", "fury-attack"]]]}, -"TRAINER_SUPER_NERD_ZAC": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 37, 0, 10, ["odor-sleuth", "take-down", "flame-wheel", "helping-hand"]], ["vulpix", 37, 0, 8, ["imprison", "flamethrower", "safeguard", "grudge"]]]}, -"TRAINER_HIKER_MARCOS": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 10, 0, 24, ["tackle", "defense-curl", "mud-sport"]], ["geodude", 10, 0, 12, ["tackle", "defense-curl", "mud-sport"]], ["onix", 10, 0, 8, ["tackle", "screech", "bind"]]]}, -"TRAINER_HIKER_FRANKLIN": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 15, 0, 6, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["geodude", 15, 0, 22, ["tackle", "defense-curl", "mud-sport", "rock-throw"]]]}, -"TRAINER_HIKER_NOB": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 13, 0, 23, ["tackle", "defense-curl", "mud-sport", "rock-throw"]], ["geodude", 13, 0, 10, ["tackle", "defense-curl", "mud-sport", "rock-throw"]], ["machop", 13, 0, 1, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["geodude", 13, 0, 13, ["tackle", "defense-curl", "mud-sport", "rock-throw"]]]}, -"TRAINER_HIKER_WAYNE": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 17, 0, 10, ["tackle", "screech", "bind", "rock-throw"]]]}, -"TRAINER_HIKER_ALAN": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 21, 0, 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["onix", 21, 0, 14, ["harden", "rock-throw", "bind", "screech"]]]}, -"TRAINER_HIKER_BRICE": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 20, 0, 16, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]], ["machop", 20, 0, 0, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["geodude", 20, 0, 5, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]]]}, -"TRAINER_HIKER_CLARK": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 21, 0, 14, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["onix", 21, 0, 0, ["harden", "rock-throw", "bind", "screech"]]]}, -"TRAINER_HIKER_TRENT": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 19, 0, 14, ["screech", "bind", "rock-throw", "harden"]], ["graveler", 19, 0, 12, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]]]}, -"TRAINER_HIKER_DUDLEY": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 21, 0, 11, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["geodude", 21, 0, 11, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["graveler", 21, 0, 14, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]]}, -"TRAINER_HIKER_ALLEN": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 25, 0, 8, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]]}, -"TRAINER_HIKER_ERIC": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 20, 0, 17, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["onix", 20, 0, 2, ["screech", "bind", "rock-throw", "harden"]]]}, -"TRAINER_HIKER_LENNY": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 19, 0, 14, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]], ["machop", 19, 0, 21, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["geodude", 19, 0, 24, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]], ["geodude", 19, 0, 2, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]]]}, -"TRAINER_HIKER_OLIVER": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 20, 0, 4, ["screech", "bind", "rock-throw", "harden"]], ["onix", 20, 0, 22, ["screech", "bind", "rock-throw", "harden"]], ["geodude", 20, 0, 7, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]]]}, -"TRAINER_HIKER_LUCAS": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 21, 0, 5, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["graveler", 21, 0, 2, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]]}, -"TRAINER_BIKER_JARED": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 28, 0, 14, ["smokescreen", "sludge", "smog", "poison-gas"]], ["koffing", 28, 0, 17, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, 0, 20, ["smokescreen", "sludge", "smog", "tackle"]]]}, -"TRAINER_BIKER_MALIK": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 29, 0, 12, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 29, 0, 9, ["screech", "minimize", "sludge", "disable"]]]}, -"TRAINER_BIKER_ERNEST": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 25, 0, 13, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, 0, 15, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, 0, 18, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, 0, 20, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 25, 0, 18, ["minimize", "sludge", "disable", "pound"]]]}, -"TRAINER_BIKER_ALEX": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 28, 0, 22, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 28, 0, 4, ["screech", "minimize", "sludge", "disable"]], ["weezing", 28, 0, 16, ["smokescreen", "sludge", "smog", "tackle"]]]}, -"TRAINER_BIKER_LAO": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 29, 0, 18, ["screech", "minimize", "sludge", "disable"]], ["koffing", 29, 0, 4, ["smokescreen", "sludge", "smog", "tackle"]]]}, -"TRAINER_BIKER_HIDEO": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 33, 0, 8, ["self-destruct", "sludge", "smokescreen", "haze"]]]}, -"TRAINER_BIKER_RUBEN": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 28, 0, 22, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, 0, 7, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 28, 0, 18, ["smokescreen", "sludge", "smog", "tackle"]]]}, -"TRAINER_BIKER_BILLY": {"ai": ["check-bad-move"], "items": [], "party": [["muk", 33, 0, 19, ["disable", "sludge", "minimize", "screech"]]]}, -"TRAINER_BIKER_NIKOLAS": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 29, 0, 20, ["spark", "sonic-boom", "screech", "charge"]], ["voltorb", 29, 0, 4, ["spark", "sonic-boom", "screech", "charge"]]]}, -"TRAINER_BIKER_JAXON": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 29, 0, 21, ["sludge", "smokescreen", "smog", "tackle"]], ["muk", 29, 0, 3, ["screech", "minimize", "sludge", "disable"]]]}, -"TRAINER_BIKER_WILLIAM": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 25, 0, 17, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, 0, 24, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, 0, 5, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, 0, 11, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, 0, 18, ["smokescreen", "sludge", "self-destruct", "tackle"]]]}, -"TRAINER_BIKER_LUKAS": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 26, 0, 20, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 26, 0, 4, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 26, 0, 9, ["screech", "minimize", "sludge", "disable"]], ["koffing", 26, 0, 18, ["smokescreen", "sludge", "smog", "tackle"]]]}, -"TRAINER_BIKER_ISAAC": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 28, 0, 5, ["screech", "minimize", "sludge", "disable"]], ["grimer", 28, 0, 24, ["screech", "minimize", "sludge", "disable"]], ["koffing", 28, 0, 22, ["smokescreen", "sludge", "smog", "tackle"]]]}, -"TRAINER_BIKER_GERALD": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 29, 0, 9, ["smokescreen", "sludge", "smog", "tackle"]], ["muk", 29, 0, 5, ["screech", "minimize", "sludge", "disable"]]]}, -"TRAINER_BURGLAR_1": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 29, 0, 7, ["ember", "leer", "odor-sleuth", "take-down"]], ["vulpix", 29, 0, 2, ["will-o-wisp", "confuse-ray", "imprison", "flamethrower"]]]}, -"TRAINER_BURGLAR_2": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 33, 0, 7, ["leer", "odor-sleuth", "take-down", "flame-wheel"]]]}, -"TRAINER_BURGLAR_3": {"ai": ["check-bad-move"], "items": [], "party": [["vulpix", 28, 0, 6, ["quick-attack", "will-o-wisp", "confuse-ray", "imprison"]], ["charmander", 28, 0, 1, ["ember", "metal-claw", "smokescreen", "scary-face"]], ["ponyta", 28, 0, 18, ["tail-whip", "ember", "stomp", "fire-spin"]]]}, -"TRAINER_BURGLAR_QUINN": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 36, 0, 12, ["leer", "odor-sleuth", "take-down", "flame-wheel"]], ["vulpix", 36, 0, 12, ["confuse-ray", "imprison", "flamethrower", "safeguard"]], ["ninetales", 36, 0, 5, ["ember", "quick-attack", "confuse-ray", "safeguard"]]]}, -"TRAINER_BURGLAR_RAMON": {"ai": ["check-bad-move"], "items": [], "party": [["ponyta", 41, 0, 24, ["stomp", "fire-spin", "take-down", "agility"]]]}, -"TRAINER_BURGLAR_DUSTY": {"ai": ["check-bad-move"], "items": [], "party": [["vulpix", 37, 0, 20, ["imprison", "flamethrower", "safeguard", "grudge"]], ["growlithe", 37, 0, 5, ["odor-sleuth", "take-down", "flame-wheel", "helping-hand"]]]}, -"TRAINER_BURGLAR_ARNIE": {"ai": ["check-bad-move"], "items": [], "party": [["charmander", 34, 0, 18, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]], ["charmeleon", 34, 0, 4, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]]]}, -"TRAINER_BURGLAR_4": {"ai": ["check-bad-move"], "items": [], "party": [["charmander", 34, 0, 6, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]], ["charmeleon", 34, 0, 5, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]]]}, -"TRAINER_BURGLAR_SIMON": {"ai": ["check-bad-move"], "items": [], "party": [["ninetales", 38, 0, 24, ["ember", "quick-attack", "confuse-ray", "safeguard"]]]}, -"TRAINER_BURGLAR_LEWIS": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 34, 0, 20, ["leer", "odor-sleuth", "take-down", "flame-wheel"]], ["ponyta", 34, 0, 0, ["ember", "stomp", "fire-spin", "take-down"]]]}, -"TRAINER_ENGINEER_BAILY": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 21, 0, 21, ["tackle", "screech", "sonic-boom", "spark"]], ["magnemite", 21, 0, 11, ["thunder-shock", "supersonic", "sonic-boom", "thunder-wave"]]]}, -"TRAINER_ENGINEER_BRAXTON": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 21, 0, 3, ["thunder-shock", "supersonic", "sonic-boom", "thunder-wave"]]]}, -"TRAINER_ENGINEER_BERNIE": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 18, 0, 16, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["magnemite", 18, 0, 21, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["magneton", 18, 0, 22, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]]]}, -"TRAINER_FISHERMAN_DALE": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 17, 0, 16, ["tail-whip", "water-sport", "supersonic", "horn-attack"]], ["tentacool", 17, 0, 11, ["poison-sting", "supersonic", "constrict"]], ["goldeen", 17, 0, 16, ["tail-whip", "water-sport", "supersonic", "horn-attack"]]]}, -"TRAINER_FISHERMAN_BARNY": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 17, 0, 0, ["poison-sting", "supersonic", "constrict"]], ["staryu", 17, 0, 10, ["harden", "water-gun", "rapid-spin", "recover"]], ["shellder", 17, 0, 1, ["tackle", "withdraw", "icicle-spear", "supersonic"]]]}, -"TRAINER_FISHERMAN_NED": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 22, 0, 6, ["tail-whip", "water-sport", "supersonic", "horn-attack"]], ["poliwag", 22, 0, 2, ["bubble", "hypnosis", "water-gun", "double-slap"]], ["goldeen", 22, 0, 22, ["tail-whip", "water-sport", "supersonic", "horn-attack"]]]}, -"TRAINER_FISHERMAN_CHIP": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 24, 0, 15, ["poison-sting", "supersonic", "constrict", "acid"]], ["goldeen", 24, 0, 4, ["water-sport", "supersonic", "horn-attack", "flail"]]]}, -"TRAINER_FISHERMAN_HANK": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 27, 0, 13, ["water-sport", "supersonic", "horn-attack", "flail"]]]}, -"TRAINER_FISHERMAN_ELLIOT": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 21, 0, 5, ["bubble", "hypnosis", "water-gun", "double-slap"]], ["shellder", 21, 0, 15, ["tackle", "withdraw", "icicle-spear", "supersonic"]], ["goldeen", 21, 0, 8, ["tail-whip", "water-sport", "supersonic", "horn-attack"]], ["horsea", 21, 0, 9, ["bubble", "smokescreen", "leer"]]]}, -"TRAINER_FISHERMAN_RONALD": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 28, 0, 24, ["water-sport", "supersonic", "horn-attack", "flail"]], ["goldeen", 28, 0, 13, ["water-sport", "supersonic", "horn-attack", "flail"]], ["seaking", 28, 0, 1, ["water-sport", "supersonic", "horn-attack", "flail"]], ["seaking", 28, 0, 14, ["water-sport", "supersonic", "horn-attack", "flail"]]]}, -"TRAINER_FISHERMAN_CLAUDE": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 31, 0, 9, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["cloyster", 31, 0, 11, ["withdraw", "supersonic", "aurora-beam", "protect"]]]}, -"TRAINER_FISHERMAN_WADE": {"ai": ["check-bad-move"], "items": [], "party": [["magikarp", 27, 0, 7, ["splash", "tackle"]], ["magikarp", 27, 0, 3, ["splash", "tackle"]], ["magikarp", 27, 0, 24, ["splash", "tackle"]], ["magikarp", 27, 0, 20, ["splash", "tackle"]], ["magikarp", 27, 0, 16, ["splash", "tackle"]], ["magikarp", 27, 0, 12, ["splash", "tackle"]]]}, -"TRAINER_FISHERMAN_NOLAN": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 33, 0, 10, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["goldeen", 33, 0, 10, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, -"TRAINER_FISHERMAN_ANDREW": {"ai": ["check-bad-move"], "items": [], "party": [["magikarp", 24, 0, 6, ["splash", "tackle"]], ["magikarp", 24, 0, 1, ["splash", "tackle"]]]}, -"TRAINER_SWIMMER_MALE_LUIS": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 16, 0, 8, ["bubble", "smokescreen", "leer"]], ["shellder", 16, 0, 14, ["tackle", "withdraw", "icicle-spear", "supersonic"]]]}, -"TRAINER_SWIMMER_MALE_RICHARD": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 30, 0, 13, ["constrict", "acid", "bubble-beam", "wrap"]], ["shellder", 30, 0, 17, ["icicle-spear", "supersonic", "aurora-beam", "protect"]]]}, -"TRAINER_SWIMMER_MALE_REECE": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 29, 0, 16, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["horsea", 29, 0, 4, ["smokescreen", "leer", "water-gun", "twister"]], ["staryu", 29, 0, 20, ["recover", "camouflage", "swift", "bubble-beam"]]]}, -"TRAINER_SWIMMER_MALE_MATTHEW": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 30, 0, 23, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["poliwhirl", 30, 0, 1, ["hypnosis", "water-gun", "double-slap", "rain-dance"]]]}, -"TRAINER_SWIMMER_MALE_DOUGLAS": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 27, 0, 14, ["bubble", "smokescreen", "leer", "water-gun"]], ["tentacool", 27, 0, 24, ["supersonic", "constrict", "acid", "bubble-beam"]], ["tentacool", 27, 0, 9, ["supersonic", "constrict", "acid", "bubble-beam"]], ["goldeen", 27, 0, 4, ["water-sport", "supersonic", "horn-attack", "flail"]]]}, -"TRAINER_SWIMMER_MALE_DAVID": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 29, 0, 15, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["shellder", 29, 0, 11, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["seaking", 29, 0, 14, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, -"TRAINER_SWIMMER_MALE_TONY": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 30, 0, 11, ["smokescreen", "leer", "water-gun", "twister"]], ["horsea", 30, 0, 11, ["smokescreen", "leer", "water-gun", "twister"]]]}, -"TRAINER_SWIMMER_MALE_AXLE": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 27, 0, 1, ["supersonic", "constrict", "acid", "bubble-beam"]], ["tentacool", 27, 0, 16, ["supersonic", "constrict", "acid", "bubble-beam"]], ["staryu", 27, 0, 2, ["rapid-spin", "recover", "camouflage", "swift"]], ["horsea", 27, 0, 10, ["bubble", "smokescreen", "leer", "water-gun"]], ["tentacruel", 27, 0, 0, ["supersonic", "constrict", "acid", "bubble-beam"]]]}, -"TRAINER_SWIMMER_MALE_BARRY": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 31, 0, 1, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["cloyster", 31, 0, 20, ["withdraw", "supersonic", "aurora-beam", "protect"]]]}, -"TRAINER_SWIMMER_MALE_DEAN": {"ai": ["check-bad-move"], "items": [], "party": [["staryu", 35, 0, 14, ["camouflage", "swift", "bubble-beam", "minimize"]]]}, -"TRAINER_SWIMMER_MALE_DARRIN": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 28, 0, 8, ["bubble", "smokescreen", "leer", "water-gun"]], ["horsea", 28, 0, 5, ["bubble", "smokescreen", "leer", "water-gun"]], ["seadra", 28, 0, 19, ["bubble", "smokescreen", "leer", "water-gun"]], ["horsea", 28, 0, 16, ["bubble", "smokescreen", "leer", "water-gun"]]]}, -"TRAINER_SWIMMER_MALE_SPENCER": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 33, 0, 12, ["smokescreen", "leer", "water-gun", "twister"]], ["tentacruel", 33, 0, 3, ["constrict", "acid", "bubble-beam", "wrap"]]]}, -"TRAINER_SWIMMER_MALE_JACK": {"ai": ["check-bad-move"], "items": [], "party": [["starmie", 37, 0, 22, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, -"TRAINER_SWIMMER_MALE_JEROME": {"ai": ["check-bad-move"], "items": [], "party": [["staryu", 33, 0, 23, ["camouflage", "swift", "bubble-beam", "minimize"]], ["wartortle", 33, 0, 1, ["water-gun", "bite", "rapid-spin", "protect"]]]}, -"TRAINER_SWIMMER_MALE_ROLAND": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 32, 0, 17, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["tentacool", 32, 0, 21, ["constrict", "acid", "bubble-beam", "wrap"]], ["seadra", 32, 0, 10, ["smokescreen", "leer", "water-gun", "twister"]]]}, -"TRAINER_CUE_BALL_KOJI": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 28, 0, 2, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["mankey", 28, 0, 21, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["machop", 28, 0, 12, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, -"TRAINER_CUE_BALL_LUKE": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 29, 0, 4, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["machop", 29, 0, 19, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, -"TRAINER_CUE_BALL_CAMRON": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 29, 0, 1, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["machop", 29, 0, 13, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, -"TRAINER_CUE_BALL_RAUL": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 29, 0, 22, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["primeape", 29, 0, 24, ["fury-swipes", "focus-energy", "seismic-toss", "rage"]]]}, -"TRAINER_CUE_BALL_ISAIAH": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 29, 0, 21, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["machamp", 29, 0, 16, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, -"TRAINER_CUE_BALL_ZEEK": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 33, 0, 5, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, -"TRAINER_CUE_BALL_JAMAL": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 26, 0, 23, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["mankey", 26, 0, 10, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["machamp", 26, 0, 4, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["machop", 26, 0, 13, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, -"TRAINER_CUE_BALL_COREY": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 29, 0, 13, ["fury-swipes", "focus-energy", "seismic-toss", "rage"]], ["machoke", 29, 0, 12, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, -"TRAINER_CUE_BALL_CHASE": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 31, 0, 6, ["constrict", "acid", "bubble-beam", "wrap"]], ["tentacool", 31, 0, 1, ["constrict", "acid", "bubble-beam", "wrap"]], ["tentacruel", 31, 0, 21, ["constrict", "acid", "bubble-beam", "wrap"]]]}, -"TRAINER_GAMER_HUGO": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 18, 0, 16, ["bubble", "hypnosis", "water-gun"]], ["horsea", 18, 0, 3, ["bubble", "smokescreen", "leer"]]]}, -"TRAINER_GAMER_JASPER": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 18, 0, 21, ["growth", "wrap", "sleep-powder", "poison-powder"]], ["oddish", 18, 0, 6, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]]]}, -"TRAINER_GAMER_DIRK": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 18, 0, 13, ["charge", "tackle", "screech", "sonic-boom"]], ["magnemite", 18, 0, 20, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]]]}, -"TRAINER_GAMER_DARIAN": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 18, 0, 10, ["bite", "roar", "ember", "leer"]], ["vulpix", 18, 0, 8, ["tail-whip", "roar", "quick-attack", "will-o-wisp"]]]}, -"TRAINER_GAMER_STAN": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 22, 0, 9, ["bubble", "hypnosis", "water-gun", "double-slap"]], ["poliwag", 22, 0, 7, ["bubble", "hypnosis", "water-gun", "double-slap"]], ["poliwhirl", 22, 0, 21, ["bubble", "hypnosis", "water-gun", "double-slap"]]]}, -"TRAINER_GAMER_RICH": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 24, 0, 24, ["roar", "ember", "leer", "odor-sleuth"]], ["vulpix", 24, 0, 11, ["roar", "quick-attack", "will-o-wisp", "confuse-ray"]]]}, -"TRAINER_BEAUTY_BRIDGET": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 21, 0, 22, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bellsprout", 21, 0, 24, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]], ["oddish", 21, 0, 1, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bellsprout", 21, 0, 3, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]]]}, -"TRAINER_BEAUTY_TAMIA": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 24, 0, 14, ["sleep-powder", "poison-powder", "stun-spore", "acid"]], ["bellsprout", 24, 0, 8, ["sleep-powder", "poison-powder", "stun-spore", "acid"]]]}, -"TRAINER_BEAUTY_LORI": {"ai": ["check-bad-move"], "items": [], "party": [["exeggcute", 24, 0, 9, ["hypnosis", "reflect", "leech-seed", "confusion"]]]}, -"TRAINER_BEAUTY_LOLA": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 27, 0, 22, ["quick-attack", "hyper-fang", "focus-energy", "pursuit"]], ["pikachu", 27, 0, 2, ["quick-attack", "double-team", "slam", "thunderbolt"]], ["rattata", 27, 0, 4, ["quick-attack", "hyper-fang", "focus-energy", "pursuit"]]]}, -"TRAINER_BEAUTY_SHEILA": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 29, 0, 17, ["follow-me", "minimize", "defense-curl", "metronome"]], ["meowth", 29, 0, 12, ["growl", "bite", "pay-day", "feint-attack"]]]}, -"TRAINER_SWIMMER_FEMALE_TIFFANY": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 35, 0, 1, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, -"TRAINER_SWIMMER_FEMALE_NORA": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 30, 0, 23, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["shellder", 30, 0, 1, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["cloyster", 30, 0, 8, ["withdraw", "supersonic", "aurora-beam", "protect"]]]}, -"TRAINER_SWIMMER_FEMALE_MELISSA": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 31, 0, 10, ["water-gun", "double-slap", "rain-dance", "body-slam"]], ["seaking", 31, 0, 23, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, -"TRAINER_BEAUTY_GRACE": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 29, 0, 14, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["wigglytuff", 29, 0, 24, ["sing", "disable", "defense-curl", "double-slap"]]]}, -"TRAINER_BEAUTY_OLIVIA": {"ai": ["check-bad-move"], "items": [], "party": [["bulbasaur", 29, 0, 0, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]], ["ivysaur", 29, 0, 6, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]]]}, -"TRAINER_BEAUTY_LAUREN": {"ai": ["check-bad-move"], "items": [], "party": [["weepinbell", 33, 0, 20, ["poison-powder", "stun-spore", "acid", "sweet-scent"]], ["bellsprout", 33, 0, 17, ["poison-powder", "stun-spore", "acid", "sweet-scent"]], ["weepinbell", 33, 0, 17, ["poison-powder", "stun-spore", "acid", "sweet-scent"]]]}, -"TRAINER_SWIMMER_FEMALE_ANYA": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 27, 0, 15, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["goldeen", 27, 0, 9, ["water-sport", "supersonic", "horn-attack", "flail"]], ["seaking", 27, 0, 2, ["water-sport", "supersonic", "horn-attack", "flail"]], ["goldeen", 27, 0, 21, ["water-sport", "supersonic", "horn-attack", "flail"]], ["poliwag", 27, 0, 16, ["hypnosis", "water-gun", "double-slap", "rain-dance"]]]}, -"TRAINER_SWIMMER_FEMALE_ALICE": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 30, 0, 14, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 30, 0, 7, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, -"TRAINER_SWIMMER_FEMALE_CONNIE": {"ai": ["check-bad-move"], "items": [], "party": [["staryu", 29, 0, 21, ["recover", "camouflage", "swift", "bubble-beam"]], ["staryu", 29, 0, 22, ["recover", "camouflage", "swift", "bubble-beam"]], ["staryu", 29, 0, 23, ["recover", "camouflage", "swift", "bubble-beam"]]]}, -"TRAINER_SWIMMER_FEMALE_SHIRLEY": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 30, 0, 17, ["smokescreen", "leer", "water-gun", "twister"]], ["horsea", 30, 0, 22, ["smokescreen", "leer", "water-gun", "twister"]], ["seadra", 30, 0, 19, ["smokescreen", "leer", "water-gun", "twister"]]]}, -"TRAINER_PSYCHIC_JOHAN": {"ai": ["check-bad-move"], "items": [], "party": [["kadabra", 31, 50, 19, ["psybeam", "reflect", "recover", "future-sight"]], ["slowpoke", 31, 50, 11, ["water-gun", "confusion", "disable", "headbutt"]], ["mr-mime", 31, 50, 14, ["reflect", "magical-leaf", "encore", "psybeam"]], ["kadabra", 31, 50, 22, ["psybeam", "reflect", "recover", "future-sight"]]]}, -"TRAINER_PSYCHIC_TYRON": {"ai": ["check-bad-move"], "items": [], "party": [["mr-mime", 34, 50, 3, ["magical-leaf", "encore", "psybeam", "recycle"]], ["kadabra", 34, 50, 0, ["reflect", "recover", "future-sight", "role-play"]]]}, -"TRAINER_PSYCHIC_CAMERON": {"ai": ["check-bad-move"], "items": [], "party": [["slowpoke", 33, 50, 11, ["water-gun", "confusion", "disable", "headbutt"]], ["slowpoke", 33, 50, 11, ["water-gun", "confusion", "disable", "headbutt"]], ["slowbro", 33, 50, 23, ["water-gun", "confusion", "disable", "headbutt"]]]}, -"TRAINER_PSYCHIC_PRESTON": {"ai": ["check-bad-move"], "items": [], "party": [["slowbro", 38, 50, 1, ["disable", "headbutt", "amnesia", "withdraw"]]]}, -"TRAINER_ROCKER_RANDALL": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 20, 0, 6, ["charge", "tackle", "screech", "sonic-boom"]], ["magnemite", 20, 0, 6, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["voltorb", 20, 0, 1, ["charge", "tackle", "screech", "sonic-boom"]]]}, -"TRAINER_ROCKER_LUCA": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 29, 0, 8, ["screech", "sonic-boom", "spark", "self-destruct"]], ["electrode", 29, 0, 10, ["screech", "sonic-boom", "spark", "self-destruct"]]]}, -"TRAINER_JUGGLER_DALTON": {"ai": ["check-bad-move"], "items": [], "party": [["kadabra", 29, 0, 18, ["disable", "psybeam", "reflect", "recover"]], ["mr-mime", 29, 0, 20, ["reflect", "magical-leaf", "encore", "psybeam"]]]}, -"TRAINER_JUGGLER_NELSON": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 41, 0, 19, ["meditate", "psychic", "psych-up", "swagger"]], ["hypno", 41, 0, 12, ["headbutt", "poison-gas", "meditate", "psychic"]], ["kadabra", 41, 0, 22, ["recover", "future-sight", "role-play", "psychic"]], ["kadabra", 41, 0, 7, ["recover", "future-sight", "role-play", "psychic"]]]}, -"TRAINER_JUGGLER_KIRK": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 31, 0, 7, ["headbutt", "poison-gas", "meditate", "psychic"]], ["drowzee", 31, 0, 3, ["headbutt", "poison-gas", "meditate", "psychic"]], ["kadabra", 31, 0, 1, ["psybeam", "reflect", "recover", "future-sight"]], ["drowzee", 31, 0, 22, ["headbutt", "poison-gas", "meditate", "psychic"]]]}, -"TRAINER_JUGGLER_SHAWN": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 34, 0, 19, ["headbutt", "poison-gas", "meditate", "psychic"]], ["hypno", 34, 0, 12, ["confusion", "headbutt", "poison-gas", "meditate"]]]}, -"TRAINER_JUGGLER_GREGORY": {"ai": ["check-bad-move"], "items": [], "party": [["mr-mime", 48, 0, 3, ["psychic", "role-play", "double-slap", "encore"]]]}, -"TRAINER_JUGGLER_EDWARD": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 46, 0, 23, ["swift", "light-screen", "spark", "sonic-boom"]], ["voltorb", 46, 0, 10, ["swift", "light-screen", "spark", "sonic-boom"]], ["electrode", 47, 0, 2, ["swift", "spark", "self-destruct", "sonic-boom"]], ["mr-mime", 48, 0, 13, ["psychic", "role-play", "reflect", "encore"]]]}, -"TRAINER_JUGGLER_KAYDEN": {"ai": ["check-bad-move"], "items": [], "party": [["hypno", 38, 0, 15, ["headbutt", "poison-gas", "meditate", "psychic"]]]}, -"TRAINER_JUGGLER_NATE": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 34, 0, 3, ["headbutt", "poison-gas", "meditate", "psychic"]], ["kadabra", 34, 0, 22, ["reflect", "recover", "future-sight", "role-play"]]]}, -"TRAINER_TAMER_PHIL": {"ai": ["check-bad-move"], "items": [], "party": [["sandslash", 34, 40, 21, ["sand-attack", "poison-sting", "slash", "swift"]], ["arbok", 34, 40, 17, ["poison-sting", "bite", "glare", "screech"]]]}, -"TRAINER_TAMER_EDGAR": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 33, 40, 13, ["poison-sting", "bite", "glare", "screech"]], ["sandslash", 33, 40, 4, ["sand-attack", "poison-sting", "slash", "swift"]], ["arbok", 33, 40, 6, ["poison-sting", "bite", "glare", "screech"]]]}, -"TRAINER_TAMER_JASON": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 43, 40, 18, ["scary-face", "rock-blast", "horn-drill", "take-down"]]]}, -"TRAINER_TAMER_COLE": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 39, 40, 22, ["bite", "glare", "screech", "acid"]], ["tauros", 39, 40, 6, ["scary-face", "pursuit", "swagger", "rest"]]]}, -"TRAINER_TAMER_VINCENT": {"ai": ["check-bad-move"], "items": [], "party": [["persian", 44, 40, 24, ["pay-day", "feint-attack", "screech", "fury-swipes"]], ["golduck", 44, 40, 8, ["confusion", "screech", "psych-up", "fury-swipes"]]]}, -"TRAINER_TAMER_JOHN": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 42, 40, 5, ["fury-attack", "scary-face", "rock-blast", "horn-drill"]], ["primeape", 42, 40, 2, ["focus-energy", "seismic-toss", "rage", "cross-chop"]], ["arbok", 42, 40, 10, ["bite", "glare", "screech", "acid"]], ["tauros", 42, 40, 16, ["scary-face", "pursuit", "swagger", "rest"]]]}, -"TRAINER_BIRD_KEEPER_SEBASTIAN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 29, 0, 12, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 29, 0, 6, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, -"TRAINER_BIRD_KEEPER_PERRY": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 25, 0, 2, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["pidgey", 25, 0, 16, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgey", 25, 0, 5, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["spearow", 25, 0, 21, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["spearow", 25, 0, 12, ["leer", "fury-attack", "pursuit", "aerial-ace"]]]}, -"TRAINER_BIRD_KEEPER_ROBERT": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 26, 0, 17, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 26, 0, 16, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["spearow", 26, 0, 24, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 26, 0, 17, ["growl", "leer", "fury-attack", "pursuit"]]]}, -"TRAINER_BIRD_KEEPER_DONALD": {"ai": ["check-bad-move"], "items": [], "party": [["farfetch-d", 33, 0, 7, ["fury-attack", "knock-off", "fury-cutter", "swords-dance"]]]}, -"TRAINER_BIRD_KEEPER_BENNY": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 29, 0, 20, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 29, 0, 14, ["growl", "leer", "fury-attack", "pursuit"]]]}, -"TRAINER_BIRD_KEEPER_EDWIN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 26, 0, 6, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["farfetch-d", 26, 0, 16, ["leer", "fury-attack", "knock-off", "fury-cutter"]], ["doduo", 26, 0, 10, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["pidgey", 26, 0, 12, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, -"TRAINER_BIRD_KEEPER_CHESTER": {"ai": ["check-bad-move"], "items": [], "party": [["dodrio", 28, 0, 2, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["doduo", 28, 0, 16, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["doduo", 28, 0, 5, ["pursuit", "fury-attack", "tri-attack", "rage"]]]}, -"TRAINER_BIRD_KEEPER_WILTON": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 29, 0, 9, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 29, 0, 17, ["growl", "leer", "fury-attack", "pursuit"]]]}, -"TRAINER_BIRD_KEEPER_RAMIRO": {"ai": ["check-bad-move"], "items": [], "party": [["dodrio", 34, 0, 12, ["pursuit", "fury-attack", "tri-attack", "rage"]]]}, -"TRAINER_BIRD_KEEPER_JACOB": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 26, 0, 21, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["spearow", 26, 0, 6, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 26, 0, 1, ["growl", "leer", "fury-attack", "pursuit"]], ["spearow", 26, 0, 11, ["leer", "fury-attack", "pursuit", "aerial-ace"]]]}, -"TRAINER_BIRD_KEEPER_ROGER": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 30, 0, 23, ["growl", "leer", "fury-attack", "pursuit"]], ["fearow", 30, 0, 10, ["growl", "leer", "fury-attack", "pursuit"]], ["pidgeotto", 30, 0, 3, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, -"TRAINER_BIRD_KEEPER_REED": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 39, 0, 2, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["pidgeotto", 39, 0, 18, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["pidgey", 39, 0, 16, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["pidgeotto", 39, 0, 7, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]]]}, -"TRAINER_BIRD_KEEPER_KEITH": {"ai": ["check-bad-move"], "items": [], "party": [["farfetch-d", 39, 0, 9, ["knock-off", "fury-cutter", "swords-dance", "agility"]], ["fearow", 39, 0, 11, ["leer", "fury-attack", "pursuit", "mirror-move"]]]}, -"TRAINER_BIRD_KEEPER_CARTER": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 28, 0, 14, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["doduo", 28, 0, 9, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["pidgeotto", 28, 0, 5, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, -"TRAINER_BIRD_KEEPER_MITCH": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 26, 0, 1, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["spearow", 26, 0, 18, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["pidgey", 26, 0, 8, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["fearow", 26, 0, 10, ["growl", "leer", "fury-attack", "pursuit"]]]}, -"TRAINER_BIRD_KEEPER_BECK": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 29, 0, 11, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["fearow", 29, 0, 5, ["growl", "leer", "fury-attack", "pursuit"]]]}, -"TRAINER_BIRD_KEEPER_MARLON": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 28, 0, 14, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["doduo", 28, 0, 7, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["fearow", 28, 0, 20, ["growl", "leer", "fury-attack", "pursuit"]]]}, -"TRAINER_BLACK_BELT_KOICHI": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonlee", 37, 100, 12, ["focus-energy", "high-jump-kick", "mind-reader", "foresight"]], ["hitmonchan", 37, 100, 3, ["thunder-punch", "ice-punch", "fire-punch", "sky-uppercut"]]]}, -"TRAINER_BLACK_BELT_MIKE": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 31, 100, 13, ["fury-swipes", "focus-energy", "seismic-toss", "cross-chop"]], ["mankey", 31, 100, 15, ["fury-swipes", "focus-energy", "seismic-toss", "cross-chop"]], ["primeape", 31, 100, 8, ["fury-swipes", "focus-energy", "seismic-toss", "rage"]]]}, -"TRAINER_BLACK_BELT_HIDEKI": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 32, 100, 15, ["seismic-toss", "foresight", "revenge", "vital-throw"]], ["machoke", 32, 100, 10, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, -"TRAINER_BLACK_BELT_AARON": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 36, 100, 11, ["focus-energy", "seismic-toss", "rage", "cross-chop"]]]}, -"TRAINER_BLACK_BELT_HITOSHI": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 31, 100, 8, ["seismic-toss", "foresight", "revenge", "vital-throw"]], ["mankey", 31, 100, 8, ["fury-swipes", "focus-energy", "seismic-toss", "cross-chop"]], ["primeape", 31, 100, 24, ["fury-swipes", "focus-energy", "seismic-toss", "rage"]]]}, -"TRAINER_BLACK_BELT_ATSUSHI": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 40, 100, 12, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machoke", 40, 100, 4, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, -"TRAINER_BLACK_BELT_KIYO": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 43, 100, 8, ["foresight", "revenge", "vital-throw", "submission"]]]}, -"TRAINER_BLACK_BELT_TAKASHI": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 38, 100, 10, ["seismic-toss", "foresight", "revenge", "vital-throw"]], ["machop", 38, 100, 18, ["foresight", "revenge", "vital-throw", "submission"]], ["machoke", 38, 100, 17, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, -"TRAINER_BLACK_BELT_DAISUKE": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 43, 100, 16, ["foresight", "revenge", "vital-throw", "submission"]], ["machop", 43, 100, 5, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machoke", 43, 100, 10, ["foresight", "revenge", "vital-throw", "submission"]]]}, -"TRAINER_RIVAL_OAKS_LAB_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["squirtle", 5, 0, 11, ["tackle", "tail-whip"]]]}, -"TRAINER_RIVAL_OAKS_LAB_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["bulbasaur", 5, 0, 8, ["tackle", "growl"]]]}, -"TRAINER_RIVAL_OAKS_LAB_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["charmander", 5, 0, 2, ["scratch", "growl"]]]}, -"TRAINER_RIVAL_ROUTE22_EARLY_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgey", 9, 50, 24, ["tackle", "sand-attack"]], ["squirtle", 9, 50, 24, ["tackle", "tail-whip"]]]}, -"TRAINER_RIVAL_ROUTE22_EARLY_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgey", 9, 50, 24, ["tackle", "sand-attack"]], ["bulbasaur", 9, 50, 21, ["tackle", "growl"]]]}, -"TRAINER_RIVAL_ROUTE22_EARLY_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgey", 9, 50, 24, ["tackle", "sand-attack"]], ["charmander", 9, 50, 15, ["scratch", "growl"]]]}, -"TRAINER_RIVAL_CERULEAN_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 17, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, 50, 9, ["teleport"]], ["rattata", 15, 50, 3, ["tackle", "tail-whip", "quick-attack"]], ["squirtle", 18, 100, 3, ["tackle", "tail-whip", "withdraw", "water-gun"]]]}, -"TRAINER_RIVAL_CERULEAN_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 17, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, 50, 9, ["teleport"]], ["rattata", 15, 50, 3, ["tackle", "tail-whip", "quick-attack"]], ["bulbasaur", 18, 100, 0, ["sleep-powder", "poison-powder", "vine-whip", "leech-seed"]]]}, -"TRAINER_RIVAL_CERULEAN_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 17, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, 50, 9, ["teleport"]], ["rattata", 15, 50, 3, ["tackle", "tail-whip", "quick-attack"]], ["charmander", 18, 100, 19, ["metal-claw", "ember", "growl", "scratch"]]]}, -"TRAINER_SCIENTIST_TED": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 29, 0, 24, ["screech", "sonic-boom", "spark", "self-destruct"]], ["weezing", 29, 0, 17, ["smog", "self-destruct", "sludge", "smokescreen"]]]}, -"TRAINER_SCIENTIST_CONNOR": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 26, 0, 22, ["screech", "minimize", "sludge", "disable"]], ["weezing", 26, 0, 13, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 26, 0, 3, ["smokescreen", "sludge", "smog", "self-destruct"]], ["weezing", 26, 0, 19, ["smokescreen", "sludge", "smog", "tackle"]]]}, -"TRAINER_SCIENTIST_JERRY": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 28, 0, 13, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["voltorb", 28, 0, 10, ["screech", "sonic-boom", "spark", "self-destruct"]], ["magneton", 28, 0, 8, ["supersonic", "sonic-boom", "thunder-wave", "spark"]]]}, -"TRAINER_SCIENTIST_JOSE": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 29, 0, 10, ["spark", "sonic-boom", "screech", "tackle"]], ["weezing", 29, 0, 14, ["smokescreen", "sludge", "smog", "tackle"]]]}, -"TRAINER_SCIENTIST_RODNEY": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 33, 0, 9, ["screech", "sonic-boom", "spark", "self-destruct"]]]}, -"TRAINER_SCIENTIST_BEAU": {"ai": ["check-bad-move"], "items": [], "party": [["magneton", 26, 0, 11, ["spark", "thunder-wave", "sonic-boom", "supersonic"]], ["koffing", 26, 0, 19, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 26, 0, 3, ["smokescreen", "sludge", "smog", "tackle"]], ["magnemite", 26, 0, 7, ["spark", "thunder-wave", "sonic-boom", "supersonic"]]]}, -"TRAINER_SCIENTIST_TAYLOR": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 25, 0, 14, ["spark", "sonic-boom", "screech", "tackle"]], ["koffing", 25, 0, 1, ["smokescreen", "sludge", "smog", "tackle"]], ["magneton", 25, 0, 5, ["thunder-wave", "sonic-boom", "supersonic", "thunder-shock"]], ["magnemite", 25, 0, 13, ["thunder-wave", "sonic-boom", "supersonic", "thunder-shock"]], ["koffing", 25, 0, 0, ["smokescreen", "sludge", "smog", "self-destruct"]]]}, -"TRAINER_SCIENTIST_JOSHUA": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 29, 0, 17, ["screech", "sonic-boom", "spark", "self-destruct"]], ["muk", 29, 0, 0, ["disable", "sludge", "minimize", "screech"]]]}, -"TRAINER_SCIENTIST_PARKER": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 29, 0, 12, ["disable", "sludge", "minimize", "screech"]], ["electrode", 29, 0, 13, ["screech", "sonic-boom", "spark", "self-destruct"]]]}, -"TRAINER_SCIENTIST_ED": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 28, 0, 8, ["spark", "sonic-boom", "screech", "tackle"]], ["koffing", 28, 0, 14, ["smokescreen", "sludge", "tackle", "smog"]], ["magneton", 28, 0, 12, ["spark", "thunder-wave", "sonic-boom", "supersonic"]]]}, -"TRAINER_SCIENTIST_TRAVIS": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 29, 0, 7, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["koffing", 29, 0, 7, ["smog", "self-destruct", "sludge", "smokescreen"]]]}, -"TRAINER_SCIENTIST_BRAYDON": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 33, 0, 13, ["sonic-boom", "thunder-wave", "spark", "lock-on"]], ["magneton", 33, 0, 11, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["voltorb", 33, 0, 8, ["sonic-boom", "spark", "self-destruct", "rollout"]]]}, -"TRAINER_SCIENTIST_IVAN": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 34, 0, 17, ["sonic-boom", "thunder-wave", "spark", "lock-on"]], ["electrode", 34, 0, 23, ["sonic-boom", "spark", "self-destruct", "rollout"]]]}, -"TRAINER_BOSS_GIOVANNI": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 25, 250, 21, ["bind", "rock-throw", "harden", "rage"]], ["rhyhorn", 24, 250, 18, ["tail-whip", "stomp", "fury-attack", "scary-face"]], ["kangaskhan", 29, 250, 24, ["bite", "tail-whip", "fake-out", "mega-punch"]]]}, -"TRAINER_BOSS_GIOVANNI_2": {"ai": ["check-bad-move"], "items": [], "party": [["nidorino", 37, 250, 1, ["poison-sting", "horn-attack", "helping-hand", "fury-attack"]], ["kangaskhan", 35, 250, 7, ["tail-whip", "fake-out", "mega-punch", "rage"]], ["rhyhorn", 37, 250, 4, ["stomp", "fury-attack", "scary-face", "rock-blast"]], ["nidoqueen", 41, 250, 21, ["tail-whip", "double-kick", "poison-sting", "body-slam"]]]}, -"TRAINER_LEADER_GIOVANNI": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "hyper-potion", "full-heal"], "party": [["rhyhorn", 45, 0, 8, ["take-down", "rock-blast", "scary-face", "earthquake"]], ["dugtrio", 42, 0, 8, ["slash", "sand-tomb", "mud-slap", "earthquake"]], ["nidoqueen", 44, 0, 0, ["body-slam", "double-kick", "poison-sting", "earthquake"]], ["nidoking", 45, 0, 0, ["thrash", "double-kick", "poison-sting", "earthquake"]], ["rhyhorn", 50, 0, 22, ["take-down", "rock-blast", "scary-face", "earthquake"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 13, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["zubat", 13, 0, 4, ["leech-life", "astonish", "supersonic"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_2": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 11, 0, 6, ["scratch", "defense-curl", "sand-attack"]], ["rattata", 11, 0, 14, ["tackle", "tail-whip", "quick-attack"]], ["zubat", 11, 0, 24, ["leech-life", "astonish", "supersonic"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_3": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 11, 0, 21, ["leech-life", "astonish", "supersonic"]], ["ekans", 11, 0, 11, ["wrap", "leer", "poison-sting"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_4": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 13, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["sandshrew", 13, 0, 14, ["scratch", "defense-curl", "sand-attack"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_5": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 17, 0, 3, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["drowzee", 17, 0, 1, ["hypnosis", "disable", "confusion", "headbutt"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_6": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 15, 0, 1, ["wrap", "leer", "poison-sting", "bite"]], ["zubat", 15, 0, 11, ["leech-life", "astonish", "supersonic"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_7": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 20, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["zubat", 20, 0, 21, ["leech-life", "astonish", "supersonic", "bite"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_8": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 21, 0, 9, ["disable", "confusion", "headbutt", "poison-gas"]], ["machop", 21, 0, 1, ["leer", "focus-energy", "karate-chop", "seismic-toss"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_9": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 21, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["raticate", 21, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_10": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 20, 0, 12, ["minimize", "sludge", "disable", "harden"]], ["koffing", 20, 0, 17, ["smog", "tackle", "poison-gas"]], ["koffing", 20, 0, 22, ["smog", "tackle", "poison-gas"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_11": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 19, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["raticate", 19, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["raticate", 19, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["rattata", 19, 0, 2, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_12": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 22, 0, 12, ["minimize", "sludge", "disable", "harden"]], ["koffing", 22, 0, 17, ["sludge", "smog", "tackle", "poison-gas"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_13": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 17, 0, 21, ["bite", "astonish", "supersonic", "leech-life"]], ["koffing", 17, 0, 1, ["smog", "tackle", "poison-gas"]], ["grimer", 17, 0, 2, ["sludge", "disable", "harden", "pound"]], ["zubat", 17, 0, 12, ["bite", "astonish", "supersonic", "leech-life"]], ["raticate", 17, 0, 12, ["hyper-fang", "quick-attack", "tail-whip", "tackle"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_14": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 20, 0, 19, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["raticate", 20, 0, 19, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["drowzee", 20, 0, 17, ["hypnosis", "disable", "confusion", "headbutt"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_15": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 21, 0, 3, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["machop", 21, 0, 20, ["leer", "focus-energy", "karate-chop", "seismic-toss"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_16": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 23, 0, 6, ["defense-curl", "sand-attack", "poison-sting", "slash"]], ["ekans", 23, 0, 21, ["leer", "poison-sting", "bite", "glare"]], ["sandslash", 23, 0, 7, ["scratch", "defense-curl", "sand-attack", "poison-sting"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_17": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 23, 0, 1, ["leer", "poison-sting", "bite", "glare"]], ["sandshrew", 23, 0, 21, ["defense-curl", "sand-attack", "poison-sting", "slash"]], ["arbok", 23, 0, 18, ["leer", "poison-sting", "bite", "glare"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_18": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 21, 0, 16, ["tackle", "smog", "self-destruct", "sludge"]], ["zubat", 21, 0, 1, ["astonish", "supersonic", "bite", "wing-attack"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_19": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 25, 0, 21, ["astonish", "supersonic", "bite", "wing-attack"]], ["zubat", 25, 0, 6, ["astonish", "supersonic", "bite", "wing-attack"]], ["golbat", 25, 0, 4, ["astonish", "supersonic", "bite", "wing-attack"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_20": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 26, 0, 16, ["smog", "self-destruct", "sludge", "smokescreen"]], ["drowzee", 26, 0, 14, ["disable", "confusion", "headbutt", "poison-gas"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_21": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 23, 0, 21, ["astonish", "supersonic", "bite", "wing-attack"]], ["rattata", 23, 0, 4, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["raticate", 23, 0, 4, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["zubat", 23, 0, 14, ["astonish", "supersonic", "bite", "wing-attack"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_22": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 26, 0, 9, ["disable", "confusion", "headbutt", "poison-gas"]], ["koffing", 26, 0, 14, ["smog", "self-destruct", "sludge", "smokescreen"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_23": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 29, 0, 2, ["leer", "focus-energy", "bonemerang", "rage"]], ["zubat", 29, 0, 12, ["supersonic", "bite", "wing-attack", "confuse-ray"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_24": {"ai": ["check-bad-move"], "items": [], "party": [["golbat", 25, 0, 9, ["astonish", "supersonic", "bite", "wing-attack"]], ["zubat", 25, 0, 19, ["astonish", "supersonic", "bite", "wing-attack"]], ["zubat", 25, 0, 4, ["astonish", "supersonic", "bite", "wing-attack"]], ["raticate", 25, 0, 4, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["zubat", 25, 0, 14, ["astonish", "supersonic", "bite", "wing-attack"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_25": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 28, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["hypno", 28, 0, 19, ["disable", "confusion", "headbutt", "poison-gas"]], ["raticate", 28, 0, 19, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_26": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 29, 0, 3, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["drowzee", 29, 0, 1, ["confusion", "headbutt", "poison-gas", "meditate"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_27": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 28, 0, 1, ["poison-sting", "bite", "glare", "screech"]], ["zubat", 28, 0, 11, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["cubone", 28, 0, 2, ["headbutt", "leer", "focus-energy", "bonemerang"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_28": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 33, 0, 8, ["poison-sting", "bite", "glare", "screech"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_29": {"ai": ["check-bad-move"], "items": [], "party": [["hypno", 33, 0, 19, ["confusion", "headbutt", "poison-gas", "meditate"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_30": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 29, 0, 3, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["machoke", 29, 0, 11, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_31": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 28, 0, 21, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["zubat", 28, 0, 6, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["golbat", 28, 0, 4, ["supersonic", "bite", "wing-attack", "confuse-ray"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_32": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 26, 0, 11, ["scary-face", "hyper-fang", "quick-attack", "tail-whip"]], ["arbok", 26, 0, 8, ["glare", "bite", "poison-sting", "leer"]], ["koffing", 26, 0, 13, ["smokescreen", "sludge", "smog", "tackle"]], ["golbat", 26, 0, 11, ["wing-attack", "bite", "astonish", "supersonic"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_33": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 29, 0, 2, ["leer", "focus-energy", "bonemerang", "rage"]], ["cubone", 29, 0, 18, ["leer", "focus-energy", "bonemerang", "rage"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_34": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 29, 0, 6, ["defense-curl", "sand-attack", "poison-sting", "slash"]], ["sandslash", 29, 0, 17, ["defense-curl", "sand-attack", "poison-sting", "slash"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_35": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 26, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["zubat", 26, 0, 21, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["golbat", 26, 0, 19, ["astonish", "supersonic", "bite", "wing-attack"]], ["rattata", 26, 0, 2, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_36": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 28, 0, 17, ["smog", "self-destruct", "sludge", "smokescreen"]], ["golbat", 28, 0, 15, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["koffing", 28, 0, 20, ["smog", "self-destruct", "sludge", "smokescreen"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_37": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 28, 0, 9, ["confusion", "headbutt", "poison-gas", "meditate"]], ["grimer", 28, 0, 10, ["disable", "sludge", "minimize", "screech"]], ["machop", 28, 0, 2, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_38": {"ai": ["check-bad-move"], "items": [], "party": [["golbat", 28, 0, 9, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["drowzee", 28, 0, 7, ["confusion", "headbutt", "poison-gas", "meditate"]], ["hypno", 28, 0, 15, ["disable", "confusion", "headbutt", "poison-gas"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_39": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 33, 0, 19, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_40": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 25, 0, 19, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["rattata", 25, 0, 2, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["zubat", 25, 0, 12, ["astonish", "supersonic", "bite", "wing-attack"]], ["rattata", 25, 0, 20, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["ekans", 25, 0, 10, ["poison-sting", "bite", "glare", "screech"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_41": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 32, 0, 2, ["leer", "focus-energy", "bonemerang", "rage"]], ["drowzee", 32, 0, 0, ["headbutt", "poison-gas", "meditate", "psychic"]], ["marowak", 32, 0, 14, ["leer", "focus-energy", "bonemerang", "rage"]]]}, -"TRAINER_COOLTRAINER_SAMUEL": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["super-potion"], "party": [["sandslash", 37, 100, 9, ["slash", "swift", "sand-attack", "poison-sting"]], ["sandslash", 37, 100, 7, ["slash", "swift", "sand-attack", "poison-sting"]], ["rhyhorn", 38, 100, 2, ["take-down", "rock-blast", "fury-attack", "scary-face"]], ["nidorino", 39, 100, 15, ["fury-attack", "horn-attack", "poison-sting", "double-kick"]], ["nidoking", 39, 100, 13, ["thrash", "double-kick", "poison-sting", "focus-energy"]]]}, -"TRAINER_COOLTRAINER_GEORGE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["exeggutor", 42, 100, 0, ["egg-bomb", "confusion", "stun-spore", "sleep-powder"]], ["sandslash", 42, 100, 14, ["fury-swipes", "swift", "poison-sting", "sand-attack"]], ["cloyster", 42, 100, 7, ["spike-cannon", "spikes", "aurora-beam", "supersonic"]], ["electrode", 42, 100, 11, ["spark", "sonic-boom", "screech", "light-screen"]], ["arcanine", 42, 100, 17, ["flame-wheel", "roar", "bite", "take-down"]]]}, -"TRAINER_COOLTRAINER_COLBY": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["kingler", 41, 100, 1, ["guillotine", "stomp", "mud-shot", "bubble"]], ["poliwhirl", 42, 100, 24, ["body-slam", "double-slap", "water-gun", "hypnosis"]], ["tentacruel", 42, 100, 20, ["barrier", "wrap", "bubble-beam", "acid"]], ["seadra", 42, 100, 1, ["water-gun", "smokescreen", "twister", "leer"]], ["blastoise", 43, 100, 4, ["water-gun", "bite", "rapid-spin", "rain-dance"]]]}, -"TRAINER_COOLTRAINER_PAUL": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["slowpoke", 42, 100, 24, ["headbutt", "confusion", "water-gun", "disable"]], ["shellder", 42, 100, 14, ["aurora-beam", "clamp", "supersonic", "leer"]], ["kingler", 42, 100, 21, ["guillotine", "stomp", "mud-shot", "bubble"]], ["starmie", 42, 100, 7, ["bubble-beam", "swift", "recover", "rapid-spin"]], ["golduck", 42, 100, 21, ["confusion", "scratch", "screech", "disable"]]]}, -"TRAINER_COOLTRAINER_ROLANDO": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["raticate", 42, 100, 12, ["super-fang", "pursuit", "scary-face", "quick-attack"]], ["ivysaur", 42, 100, 0, ["razor-leaf", "sleep-powder", "sweet-scent", "synthesis"]], ["wartortle", 42, 100, 22, ["water-gun", "bite", "rapid-spin", "tail-whip"]], ["charmeleon", 42, 100, 7, ["flamethrower", "slash", "smokescreen", "scary-face"]], ["charizard", 42, 100, 15, ["flamethrower", "wing-attack", "smokescreen", "scary-face"]]]}, -"TRAINER_COOLTRAINER_GILBERT": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["pidgeotto", 42, 100, 21, ["wing-attack", "feather-dance", "whirlwind", "quick-attack"]], ["fearow", 42, 100, 0, ["drill-peck", "mirror-move", "pursuit", "leer"]], ["persian", 42, 100, 4, ["pay-day", "feint-attack", "screech", "bite"]], ["lickitung", 42, 100, 9, ["slam", "disable", "wrap", "supersonic"]], ["tauros", 42, 100, 19, ["horn-attack", "scary-face", "swagger", "tail-whip"]]]}, -"TRAINER_COOLTRAINER_OWEN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["nidorino", 42, 100, 8, ["scratch", "poison-sting", "double-kick", "bite"]], ["nidorina", 42, 100, 21, ["horn-attack", "poison-sting", "double-kick", "leer"]], ["raticate", 42, 100, 17, ["super-fang", "pursuit", "scary-face", "quick-attack"]], ["sandslash", 42, 100, 24, ["fury-swipes", "swift", "slash", "poison-sting"]], ["rhyhorn", 42, 100, 3, ["rock-blast", "scary-face", "stomp", "tail-whip"]]]}, -"TRAINER_COOLTRAINER_BERKE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["seel", 42, 100, 22, ["take-down", "aurora-beam", "icy-wind", "growl"]], ["graveler", 42, 100, 4, ["rock-blast", "magnitude", "rock-throw", "mud-sport"]], ["kingler", 42, 100, 23, ["guillotine", "stomp", "mud-shot", "bubble"]], ["onix", 42, 100, 10, ["slam", "sandstorm", "dragon-breath", "rock-throw"]], ["cloyster", 42, 100, 16, ["spike-cannon", "aurora-beam", "supersonic", "protect"]]]}, -"TRAINER_COOLTRAINER_YUJI": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["sandslash", 38, 100, 16, ["slash", "swift", "sand-attack", "poison-sting"]], ["graveler", 38, 100, 1, ["rock-blast", "magnitude", "mud-sport", "defense-curl"]], ["onix", 38, 100, 16, ["dragon-breath", "sandstorm", "rock-throw", "bind"]], ["graveler", 38, 100, 1, ["rock-blast", "magnitude", "rollout", "defense-curl"]], ["marowak", 38, 100, 9, ["bonemerang", "headbutt", "leer", "growl"]]]}, -"TRAINER_COOLTRAINER_WARREN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["marowak", 37, 100, 10, ["bonemerang", "headbutt", "leer", "growl"]], ["marowak", 37, 100, 9, ["bonemerang", "headbutt", "leer", "growl"]], ["rhyhorn", 38, 100, 2, ["take-down", "rock-blast", "fury-attack", "scary-face"]], ["nidorina", 39, 100, 4, ["fury-swipes", "bite", "poison-sting", "double-kick"]], ["nidoqueen", 39, 100, 17, ["body-slam", "bite", "poison-sting", "double-kick"]]]}, -"TRAINER_COOLTRAINER_MARY": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["super-potion"], "party": [["bellsprout", 22, 100, 1, ["wrap", "stun-spore", "poison-powder", "growth"]], ["oddish", 22, 100, 7, ["poison-powder", "stun-spore", "absorb", "sweet-scent"]], ["weepinbell", 22, 100, 16, ["vine-whip", "stun-spore", "poison-powder", "growth"]], ["gloom", 22, 100, 24, ["absorb", "stun-spore", "poison-powder", "sweet-scent"]], ["ivysaur", 22, 100, 7, ["razor-leaf", "sleep-powder", "vine-whip", "leech-seed"]]]}, -"TRAINER_COOLTRAINER_CAROLINE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["bellsprout", 42, 100, 10, ["razor-leaf", "acid", "stun-spore", "poison-powder"]], ["weepinbell", 42, 100, 3, ["razor-leaf", "acid", "sleep-powder", "poison-powder"]], ["victreebel", 42, 100, 9, ["razor-leaf", "acid", "stun-spore", "sleep-powder"]], ["paras", 42, 100, 9, ["growth", "slash", "leech-life", "stun-spore"]], ["parasect", 42, 100, 0, ["spore", "slash", "leech-life", "poison-powder"]]]}, -"TRAINER_COOLTRAINER_ALEXA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["clefairy", 42, 100, 10, ["light-screen", "cosmic-power", "double-slap", "encore"]], ["jigglypuff", 42, 100, 22, ["sing", "body-slam", "rollout", "disable"]], ["persian", 42, 100, 14, ["pay-day", "feint-attack", "bite", "screech"]], ["dewgong", 42, 100, 14, ["sheer-cold", "take-down", "rest", "aurora-beam"]], ["chansey", 42, 100, 14, ["sing", "egg-bomb", "soft-boiled", "minimize"]]]}, -"TRAINER_COOLTRAINER_SHANNON": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["beedrill", 42, 100, 22, ["pin-missile", "twineedle", "agility", "pursuit"]], ["butterfree", 42, 100, 24, ["safeguard", "psybeam", "gust", "supersonic"]], ["parasect", 42, 100, 22, ["spore", "leech-life", "slash", "growth"]], ["venonat", 42, 100, 2, ["psybeam", "stun-spore", "leech-life", "disable"]], ["venomoth", 42, 100, 24, ["psybeam", "gust", "supersonic", "leech-life"]]]}, -"TRAINER_COOLTRAINER_NAOMI": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["persian", 42, 100, 16, ["fury-swipes", "screech", "feint-attack", "pay-day"]], ["ponyta", 42, 100, 0, ["agility", "take-down", "fire-spin", "stomp"]], ["rapidash", 42, 100, 1, ["fury-attack", "fire-spin", "stomp", "growl"]], ["vulpix", 42, 100, 13, ["flamethrower", "confuse-ray", "quick-attack", "imprison"]], ["ninetales", 42, 100, 18, ["safeguard", "will-o-wisp", "confuse-ray", "fire-spin"]]]}, -"TRAINER_COOLTRAINER_BROOKE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["tangela", 42, 100, 9, ["slam", "bind", "mega-drain", "ingrain"]], ["gloom", 42, 100, 3, ["acid", "moonlight", "sleep-powder", "stun-spore"]], ["vileplume", 42, 100, 4, ["mega-drain", "acid", "stun-spore", "aromatherapy"]], ["ivysaur", 42, 100, 23, ["razor-leaf", "sweet-scent", "growl", "leech-seed"]], ["venusaur", 42, 100, 19, ["razor-leaf", "growth", "sleep-powder", "poison-powder"]]]}, -"TRAINER_COOLTRAINER_AUSTINA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["rhyhorn", 42, 100, 15, ["horn-drill", "rock-blast", "scary-face", "stomp"]], ["nidorina", 42, 100, 19, ["double-kick", "fury-swipes", "bite", "flatter"]], ["nidoqueen", 42, 100, 9, ["body-slam", "double-kick", "bite", "growl"]], ["nidorino", 42, 100, 22, ["horn-attack", "poison-sting", "focus-energy", "leer"]], ["nidoking", 42, 100, 20, ["thrash", "double-kick", "poison-sting", "peck"]]]}, -"TRAINER_COOLTRAINER_JULIE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["persian", 42, 100, 21, ["fury-swipes", "bite", "screech", "feint-attack"]], ["ninetales", 42, 100, 6, ["flamethrower", "will-o-wisp", "confuse-ray", "grudge"]], ["rapidash", 42, 100, 12, ["fury-attack", "fire-spin", "take-down", "agility"]], ["pikachu", 42, 100, 10, ["thunderbolt", "thunder-wave", "double-team", "quick-attack"]], ["raichu", 42, 100, 13, ["thunder", "thunder-wave", "slam", "double-team"]]]}, -"TRAINER_ELITE_FOUR_LORELEI": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["dewgong", 52, 250, 0, ["ice-beam", "surf", "hail", "safeguard"]], ["cloyster", 51, 250, 23, ["spikes", "protect", "hail", "dive"]], ["slowbro", 52, 250, 2, ["ice-beam", "surf", "amnesia", "yawn"]], ["jynx", 54, 250, 22, ["ice-punch", "double-slap", "lovely-kiss", "attract"]], ["lapras", 54, 250, 13, ["confuse-ray", "ice-beam", "surf", "body-slam"]]]}, -"TRAINER_ELITE_FOUR_BRUNO": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["onix", 51, 250, 22, ["earthquake", "rock-tomb", "iron-tail", "roar"]], ["hitmonchan", 53, 250, 12, ["sky-uppercut", "mach-punch", "rock-tomb", "counter"]], ["hitmonlee", 53, 250, 12, ["mega-kick", "foresight", "brick-break", "facade"]], ["onix", 54, 250, 23, ["double-edge", "earthquake", "iron-tail", "sand-tomb"]], ["machamp", 56, 250, 15, ["cross-chop", "bulk-up", "scary-face", "rock-tomb"]]]}, -"TRAINER_ELITE_FOUR_AGATHA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["gengar", 54, 250, 2, ["shadow-punch", "confuse-ray", "toxic", "double-team"]], ["golbat", 54, 250, 14, ["confuse-ray", "poison-fang", "air-cutter", "bite"]], ["haunter", 53, 250, 22, ["hypnosis", "dream-eater", "curse", "mean-look"]], ["arbok", 56, 250, 8, ["sludge-bomb", "screech", "iron-tail", "bite"]], ["gengar", 58, 250, 15, ["shadow-ball", "sludge-bomb", "hypnosis", "nightmare"]]]}, -"TRAINER_ELITE_FOUR_LANCE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["gyarados", 56, 250, 19, ["hyper-beam", "dragon-rage", "twister", "bite"]], ["dragonair", 54, 250, 0, ["hyper-beam", "safeguard", "dragon-rage", "outrage"]], ["dragonair", 54, 250, 6, ["hyper-beam", "safeguard", "thunder-wave", "outrage"]], ["aerodactyl", 58, 250, 5, ["hyper-beam", "ancient-power", "wing-attack", "scary-face"]], ["dragonite", 60, 250, 22, ["hyper-beam", "safeguard", "outrage", "wing-attack"]]]}, -"TRAINER_LEADER_BROCK": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["geodude", 12, 0, 13, ["tackle", "defense-curl"]], ["onix", 14, 0, 23, ["tackle", "bind", "rock-tomb"]]]}, -"TRAINER_LEADER_MISTY": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["super-potion"], "party": [["staryu", 18, 0, 11, ["tackle", "harden", "recover", "water-pulse"]], ["starmie", 21, 0, 4, ["swift", "recover", "rapid-spin", "water-pulse"]]]}, -"TRAINER_LEADER_LT_SURGE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["super-potion", "full-heal"], "party": [["voltorb", 21, 0, 9, ["sonic-boom", "tackle", "screech", "shock-wave"]], ["pikachu", 18, 0, 22, ["quick-attack", "thunder-wave", "double-team", "shock-wave"]], ["raichu", 24, 0, 15, ["quick-attack", "thunder-wave", "double-team", "shock-wave"]]]}, -"TRAINER_LEADER_ERIKA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "full-heal"], "party": [["victreebel", 29, 0, 5, ["stun-spore", "acid", "poison-powder", "giga-drain"]], ["tangela", 24, 0, 21, ["poison-powder", "constrict", "ingrain", "giga-drain"]], ["vileplume", 29, 0, 24, ["sleep-powder", "acid", "stun-spore", "giga-drain"]]]}, -"TRAINER_LEADER_KOGA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "hyper-potion", "full-heal"], "party": [["koffing", 37, 0, 24, ["self-destruct", "sludge", "smokescreen", "toxic"]], ["muk", 39, 0, 10, ["minimize", "sludge", "acid-armor", "toxic"]], ["koffing", 37, 0, 23, ["self-destruct", "sludge", "smokescreen", "toxic"]], ["weezing", 43, 0, 12, ["tackle", "sludge", "smokescreen", "toxic"]]]}, -"TRAINER_LEADER_BLAINE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "hyper-potion", "full-heal"], "party": [["growlithe", 42, 0, 11, ["bite", "roar", "take-down", "fire-blast"]], ["ponyta", 40, 0, 7, ["stomp", "bounce", "fire-spin", "fire-blast"]], ["rapidash", 42, 0, 20, ["stomp", "bounce", "fire-spin", "fire-blast"]], ["arcanine", 47, 0, 17, ["bite", "roar", "take-down", "fire-blast"]]]}, -"TRAINER_LEADER_SABRINA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "hyper-potion", "full-heal"], "party": [["kadabra", 38, 0, 6, ["psybeam", "reflect", "future-sight", "calm-mind"]], ["mr-mime", 37, 0, 12, ["barrier", "psybeam", "baton-pass", "calm-mind"]], ["venomoth", 38, 0, 8, ["psybeam", "gust", "leech-life", "supersonic"]], ["alakazam", 43, 0, 3, ["psychic", "recover", "future-sight", "calm-mind"]]]}, -"TRAINER_GENTLEMAN_THOMAS": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 18, 0, 9, ["bite", "roar", "ember", "leer"]], ["growlithe", 18, 0, 7, ["bite", "roar", "ember", "leer"]]]}, -"TRAINER_GENTLEMAN_ARTHUR": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 19, 0, 21, ["peck", "focus-energy", "double-kick", "poison-sting"]], ["nidoran-f", 19, 0, 12, ["scratch", "tail-whip", "double-kick", "poison-sting"]]]}, -"TRAINER_GENTLEMAN_TUCKER": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 23, 0, 1, ["thunder-wave", "quick-attack", "double-team", "slam"]]]}, -"TRAINER_GENTLEMAN_NORTON": {"ai": ["check-bad-move"], "items": [], "party": [["persian", 48, 0, 12, ["pay-day", "feint-attack", "screech", "fury-swipes"]]]}, -"TRAINER_GENTLEMAN_WALTER": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 17, 0, 2, ["bite", "roar", "ember", "leer"]], ["ponyta", 17, 0, 14, ["quick-attack", "growl", "tail-whip", "ember"]]]}, -"TRAINER_RIVAL_SS_ANNE_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 19, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["raticate", 16, 50, 3, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["kadabra", 18, 50, 14, ["teleport", "kinesis", "confusion", "disable"]], ["wartortle", 20, 100, 21, ["bubble", "withdraw", "water-gun", "bite"]]]}, -"TRAINER_RIVAL_SS_ANNE_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 19, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["raticate", 16, 50, 3, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["kadabra", 18, 50, 14, ["teleport", "kinesis", "confusion", "disable"]], ["ivysaur", 20, 100, 12, ["leech-seed", "vine-whip", "poison-powder", "sleep-powder"]]]}, -"TRAINER_RIVAL_SS_ANNE_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 19, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["raticate", 16, 50, 3, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["kadabra", 18, 50, 14, ["teleport", "kinesis", "confusion", "disable"]], ["charmeleon", 20, 100, 9, ["growl", "ember", "metal-claw", "smokescreen"]]]}, -"TRAINER_RIVAL_POKEMON_TOWER_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 25, 100, 17, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["growlithe", 23, 100, 9, ["roar", "ember", "leer", "odor-sleuth"]], ["exeggcute", 22, 100, 6, ["hypnosis", "reflect", "leech-seed", "confusion"]], ["kadabra", 20, 100, 17, ["teleport", "kinesis", "confusion", "disable"]], ["wartortle", 25, 100, 24, ["withdraw", "water-gun", "bite", "rapid-spin"]]]}, -"TRAINER_RIVAL_POKEMON_TOWER_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 25, 100, 17, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["gyarados", 23, 100, 6, ["thrash", "bite"]], ["growlithe", 22, 100, 23, ["roar", "ember", "leer", "odor-sleuth"]], ["kadabra", 20, 100, 9, ["teleport", "kinesis", "confusion", "disable"]], ["ivysaur", 25, 100, 7, ["vine-whip", "poison-powder", "sleep-powder", "razor-leaf"]]]}, -"TRAINER_RIVAL_POKEMON_TOWER_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 25, 100, 17, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["exeggcute", 23, 100, 14, ["hypnosis", "reflect", "leech-seed", "confusion"]], ["gyarados", 22, 100, 3, ["thrash", "bite"]], ["kadabra", 20, 100, 14, ["teleport", "kinesis", "confusion", "disable"]], ["charmeleon", 25, 100, 9, ["growl", "ember", "metal-claw", "smokescreen"]]]}, -"TRAINER_RIVAL_SILPH_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 37, 100, 0, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["growlithe", 38, 100, 17, ["odor-sleuth", "take-down", "flame-wheel", "helping-hand"]], ["exeggcute", 35, 100, 14, ["leech-seed", "confusion", "stun-spore", "poison-powder"]], ["alakazam", 35, 100, 9, ["reflect", "recover", "future-sight", "calm-mind"]], ["blastoise", 40, 150, 11, ["water-gun", "bite", "rapid-spin", "protect"]]]}, -"TRAINER_RIVAL_SILPH_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 37, 100, 0, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["gyarados", 38, 100, 14, ["bite", "dragon-rage", "leer", "twister"]], ["growlithe", 35, 100, 6, ["leer", "odor-sleuth", "take-down", "flame-wheel"]], ["alakazam", 35, 100, 1, ["reflect", "recover", "future-sight", "calm-mind"]], ["venusaur", 40, 150, 1, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]]]}, -"TRAINER_RIVAL_SILPH_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 37, 100, 0, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["exeggcute", 38, 100, 22, ["confusion", "stun-spore", "poison-powder", "sleep-powder"]], ["gyarados", 35, 100, 11, ["bite", "dragon-rage", "leer", "twister"]], ["alakazam", 35, 100, 6, ["reflect", "recover", "future-sight", "calm-mind"]], ["charizard", 40, 150, 24, ["smokescreen", "scary-face", "flamethrower", "wing-attack"]]]}, -"TRAINER_RIVAL_ROUTE22_LATE_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 47, 150, 0, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, 150, 19, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["growlithe", 45, 150, 11, ["flame-wheel", "take-down", "leer", "agility"]], ["exeggcute", 45, 150, 8, ["solar-beam", "sleep-powder", "poison-powder", "stun-spore"]], ["alakazam", 47, 150, 3, ["psychic", "calm-mind", "future-sight", "disable"]], ["blastoise", 53, 250, 5, ["water-gun", "rain-dance", "bite", "rapid-spin"]]]}, -"TRAINER_RIVAL_ROUTE22_LATE_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 47, 150, 0, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, 150, 19, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["gyarados", 45, 150, 8, ["hydro-pump", "twister", "leer", "rain-dance"]], ["growlithe", 45, 150, 0, ["flame-wheel", "take-down", "leer", "agility"]], ["alakazam", 47, 150, 20, ["psychic", "calm-mind", "future-sight", "disable"]], ["venusaur", 53, 250, 20, ["razor-leaf", "sweet-scent", "growth", "synthesis"]]]}, -"TRAINER_RIVAL_ROUTE22_LATE_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 47, 150, 0, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, 150, 19, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["exeggcute", 45, 150, 16, ["solar-beam", "sleep-powder", "poison-powder", "stun-spore"]], ["gyarados", 45, 150, 5, ["hydro-pump", "twister", "leer", "rain-dance"]], ["alakazam", 47, 150, 0, ["psychic", "calm-mind", "future-sight", "disable"]], ["charizard", 53, 250, 18, ["flamethrower", "wing-attack", "slash", "scary-face"]]]}, -"TRAINER_CHAMPION_FIRST_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["pidgeot", 59, 255, 0, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, 255, 20, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, 255, 16, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["arcanine", 59, 255, 5, ["extreme-speed", "flamethrower", "roar", "bite"]], ["exeggutor", 61, 255, 2, ["giga-drain", "egg-bomb", "sleep-powder", "light-screen"]], ["blastoise", 63, 255, 4, ["hydro-pump", "rain-dance", "skull-bash", "bite"]]]}, -"TRAINER_CHAMPION_FIRST_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["pidgeot", 59, 255, 0, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, 255, 20, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, 255, 16, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["gyarados", 59, 255, 5, ["hydro-pump", "dragon-rage", "bite", "thrash"]], ["arcanine", 61, 255, 19, ["extreme-speed", "flamethrower", "roar", "bite"]], ["venusaur", 63, 255, 19, ["solar-beam", "synthesis", "sunny-day", "growth"]]]}, -"TRAINER_CHAMPION_FIRST_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["pidgeot", 59, 255, 0, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, 255, 20, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, 255, 16, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["exeggutor", 59, 255, 13, ["giga-drain", "egg-bomb", "sleep-powder", "light-screen"]], ["gyarados", 61, 255, 2, ["hydro-pump", "dragon-rage", "bite", "thrash"]], ["charizard", 63, 255, 20, ["fire-blast", "aerial-ace", "slash", "fire-spin"]]]}, -"TRAINER_CHANNELER_PATRICIA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 10, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_CARLY": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 4, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_HOPE": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 23, 0, 23, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_PAULA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 6, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_LAUREL": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 23, 0, 5, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 23, 0, 15, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_JODY": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 8, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_TAMMY": {"ai": ["check-bad-move"], "items": [], "party": [["haunter", 23, 0, 16, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_RUTH": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 11, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_KARINA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 15, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_JANAE": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 11, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_ANGELICA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 10, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 22, 0, 0, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 22, 0, 15, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_EMILIA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 10, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_JENNIFER": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 9, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_1": {"ai": ["check-bad-move"], "items": [], "party": [["haunter", 23, 0, 4, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_2": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_3": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_4": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_5": {"ai": ["check-bad-move"], "items": [], "party": [["haunter", 22, 0, 4, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_6": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 22, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 22, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_7": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_8": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, -"TRAINER_CHANNELER_AMANDA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 34, 0, 20, ["night-shade", "confuse-ray", "dream-eater", "destiny-bond"]], ["haunter", 34, 0, 4, ["night-shade", "confuse-ray", "shadow-punch", "dream-eater"]]]}, -"TRAINER_CHANNELER_STACY": {"ai": ["check-bad-move"], "items": [], "party": [["haunter", 38, 0, 17, ["night-shade", "confuse-ray", "shadow-punch", "dream-eater"]]]}, -"TRAINER_CHANNELER_TASHA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 33, 0, 19, ["night-shade", "confuse-ray", "dream-eater", "destiny-bond"]], ["gastly", 33, 0, 18, ["night-shade", "confuse-ray", "dream-eater", "destiny-bond"]], ["haunter", 33, 0, 1, ["night-shade", "confuse-ray", "shadow-punch", "dream-eater"]]]}, -"TRAINER_HIKER_JEREMY": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 20, 0, 20, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["onix", 20, 0, 8, ["screech", "bind", "rock-throw", "harden"]]]}, -"TRAINER_PICNICKER_ALMA": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 28, 0, 5, ["water-sport", "supersonic", "horn-attack", "flail"]], ["poliwag", 28, 0, 16, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["horsea", 28, 0, 9, ["bubble", "smokescreen", "leer", "water-gun"]]]}, -"TRAINER_PICNICKER_SUSIE": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 24, 0, 5, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["meowth", 24, 0, 23, ["scratch", "growl", "bite", "pay-day"]], ["rattata", 24, 0, 14, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["pikachu", 24, 0, 8, ["thunder-wave", "quick-attack", "double-team", "slam"]], ["meowth", 24, 0, 1, ["scratch", "growl", "bite", "pay-day"]]]}, -"TRAINER_PICNICKER_VALERIE": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 30, 0, 24, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["poliwag", 30, 0, 3, ["hypnosis", "water-gun", "double-slap", "rain-dance"]]]}, -"TRAINER_PICNICKER_GWEN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 27, 0, 20, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["meowth", 27, 0, 3, ["growl", "bite", "pay-day", "feint-attack"]], ["pidgey", 27, 0, 3, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 27, 0, 21, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, -"TRAINER_BIKER_VIRGIL": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 28, 0, 15, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, 0, 18, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 28, 0, 22, ["smokescreen", "sludge", "smog", "tackle"]]]}, -"TRAINER_CAMPER_FLINT": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 14, 0, 5, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["ekans", 14, 0, 6, ["wrap", "leer", "poison-sting", "bite"]]]}, -"TRAINER_PICNICKER_MISSY": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 31, 0, 19, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 31, 0, 17, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, -"TRAINER_PICNICKER_IRENE": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 30, 0, 5, ["constrict", "acid", "bubble-beam", "wrap"]], ["horsea", 30, 0, 8, ["smokescreen", "leer", "water-gun", "twister"]], ["seel", 30, 0, 4, ["growl", "icy-wind", "aurora-beam", "rest"]]]}, -"TRAINER_PICNICKER_DANA": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 20, 0, 4, ["scratch", "growl", "bite", "pay-day"]], ["oddish", 20, 0, 13, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["pidgey", 20, 0, 14, ["sand-attack", "gust", "quick-attack", "whirlwind"]]]}, -"TRAINER_PICNICKER_ARIANA": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 19, 0, 22, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["rattata", 19, 0, 5, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["rattata", 19, 0, 13, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["bellsprout", 19, 0, 23, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]]]}, -"TRAINER_PICNICKER_LEAH": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 22, 0, 15, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]], ["clefairy", 22, 0, 12, ["sing", "double-slap", "follow-me", "minimize"]]]}, -"TRAINER_CAMPER_JUSTIN": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 29, 0, 13, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]], ["nidorino", 29, 0, 8, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]]]}, -"TRAINER_PICNICKER_YAZMIN": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 29, 0, 19, ["sleep-powder", "poison-powder", "stun-spore", "acid"]], ["oddish", 29, 0, 18, ["poison-powder", "stun-spore", "sleep-powder", "acid"]], ["tangela", 29, 0, 14, ["growth", "poison-powder", "vine-whip", "bind"]]]}, -"TRAINER_PICNICKER_KINDRA": {"ai": ["check-bad-move"], "items": [], "party": [["gloom", 28, 0, 10, ["poison-powder", "stun-spore", "sleep-powder", "acid"]], ["oddish", 28, 0, 23, ["poison-powder", "stun-spore", "sleep-powder", "acid"]], ["oddish", 28, 0, 11, ["poison-powder", "stun-spore", "sleep-powder", "acid"]]]}, -"TRAINER_PICNICKER_BECKY": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 29, 0, 2, ["quick-attack", "double-team", "slam", "thunderbolt"]], ["raichu", 29, 0, 14, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, -"TRAINER_PICNICKER_CELIA": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 33, 0, 7, ["minimize", "defense-curl", "metronome", "cosmic-power"]]]}, -"TRAINER_GENTLEMAN_BROOKS": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 23, 0, 13, ["thunder-wave", "quick-attack", "double-team", "slam"]]]}, -"TRAINER_GENTLEMAN_LAMAR": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 17, 0, 7, ["bite", "roar", "ember", "leer"]], ["ponyta", 17, 0, 24, ["quick-attack", "growl", "tail-whip", "ember"]]]}, -"TRAINER_TWINS_ELI_ANNE": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 22, 0, 22, ["sing", "double-slap", "follow-me", "minimize"]], ["jigglypuff", 22, 0, 13, ["defense-curl", "pound", "disable", "rollout"]]]}, -"TRAINER_COOL_COUPLE_RAY_TYRA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["nidoqueen", 45, 100, 1, ["superpower", "body-slam", "double-kick", "poison-sting"]], ["nidoking", 45, 100, 7, ["megahorn", "thrash", "double-kick", "poison-sting"]]]}, -"TRAINER_YOUNG_COUPLE_GIA_JES": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 24, 0, 23, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]], ["nidoran-f", 24, 0, 24, ["double-kick", "poison-sting", "bite", "helping-hand"]]]}, -"TRAINER_TWINS_KIRI_JAN": {"ai": ["check-bad-move"], "items": [], "party": [["charmander", 29, 0, 12, ["ember", "metal-claw", "smokescreen", "scary-face"]], ["squirtle", 29, 0, 5, ["water-gun", "bite", "rapid-spin", "protect"]]]}, -"TRAINER_CRUSH_KIN_RON_MYA": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 29, 50, 0, ["mach-punch", "thunder-punch", "ice-punch", "fire-punch"]], ["hitmonlee", 29, 50, 7, ["jump-kick", "brick-break", "focus-energy", "high-jump-kick"]]]}, -"TRAINER_YOUNG_COUPLE_LEA_JED": {"ai": ["check-bad-move"], "items": [], "party": [["rapidash", 29, 0, 0, ["tail-whip", "ember", "stomp", "fire-spin"]], ["ninetales", 29, 0, 1, ["ember", "quick-attack", "confuse-ray", "safeguard"]]]}, -"TRAINER_SIS_AND_BRO_LIA_LUC": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 30, 0, 1, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 30, 0, 23, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, -"TRAINER_SIS_AND_BRO_LIL_IAN": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 33, 0, 20, ["smokescreen", "leer", "water-gun", "twister"]], ["starmie", 33, 0, 0, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, -"TRAINER_YOUNGSTER_BEN_3": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 28, 60, 0, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["ekans", 28, 60, 4, ["poison-sting", "bite", "glare", "screech"]]]}, -"TRAINER_YOUNGSTER_BEN_4": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 48, 120, 0, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["arbok", 48, 120, 11, ["acid", "stockpile", "swallow", "spit-up"]]]}, -"TRAINER_YOUNGSTER_CHAD_2": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 20, 20, 1, ["leer", "poison-sting", "bite", "glare"]], ["sandshrew", 20, 20, 21, ["scratch", "defense-curl", "sand-attack", "poison-sting"]]]}, -"TRAINER_LASS_RELI_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 20, 20, 15, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["nidoran-f", 20, 20, 22, ["tail-whip", "double-kick", "poison-sting", "bite"]]]}, -"TRAINER_LASS_RELI_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 28, 60, 8, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["nidorina", 28, 60, 18, ["double-kick", "poison-sting", "bite", "helping-hand"]]]}, -"TRAINER_YOUNGSTER_TIMMY_2": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 19, 20, 11, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["ekans", 19, 20, 1, ["wrap", "leer", "poison-sting", "bite"]], ["zubat", 19, 20, 11, ["leech-life", "astonish", "supersonic", "bite"]]]}, -"TRAINER_YOUNGSTER_TIMMY_3": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 27, 60, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["ekans", 27, 60, 1, ["poison-sting", "bite", "glare", "screech"]], ["golbat", 27, 60, 24, ["astonish", "supersonic", "bite", "wing-attack"]]]}, -"TRAINER_YOUNGSTER_TIMMY_4": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 52, 120, 11, ["scary-face", "pursuit", "super-fang", "endeavor"]], ["arbok", 52, 120, 8, ["acid", "stockpile", "swallow", "spit-up"]], ["golbat", 52, 120, 6, ["confuse-ray", "air-cutter", "mean-look", "poison-fang"]]]}, -"TRAINER_YOUNGSTER_CHAD_3": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 28, 60, 8, ["poison-sting", "bite", "glare", "screech"]], ["sandshrew", 28, 60, 3, ["defense-curl", "sand-attack", "poison-sting", "slash"]]]}, -"TRAINER_LASS_JANICE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 20, 20, 3, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["pidgeotto", 20, 20, 11, ["sand-attack", "gust", "quick-attack", "whirlwind"]]]}, -"TRAINER_LASS_JANICE_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 28, 60, 3, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 28, 60, 11, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, -"TRAINER_YOUNGSTER_CHAD_4": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 48, 80, 8, ["acid", "stockpile", "swallow", "spit-up"]], ["sandslash", 48, 80, 19, ["poison-sting", "slash", "swift", "fury-swipes"]]]}, -"TRAINER_HIKER_FRANKLIN_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 25, 40, 22, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["graveler", 25, 40, 16, ["mud-sport", "rock-throw", "magnitude", "self-destruct"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_42": {"ai": ["check-bad-move"], "items": [], "party": [["houndour", 49, 0, 20, ["odor-sleuth", "feint-attack", "flamethrower", "crunch"]], ["houndour", 49, 0, 4, ["odor-sleuth", "feint-attack", "flamethrower", "crunch"]]]}, -"TRAINER_PSYCHIC_JACLYN": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 48, 100, 6, ["night-shade", "confuse-ray", "future-sight", "wish"]], ["slowbro", 48, 100, 3, ["psychic", "headbutt", "amnesia", "yawn"]], ["kadabra", 49, 100, 4, ["psychic", "future-sight", "recover", "reflect"]]]}, -"TRAINER_CRUSH_GIRL_SHARON": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 37, 50, 17, ["focus-energy", "seismic-toss", "cross-chop", "swagger"]], ["primeape", 37, 50, 14, ["focus-energy", "seismic-toss", "rage", "cross-chop"]]]}, -"TRAINER_TUBER_AMIRA": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 34, 0, 3, ["water-gun", "double-slap", "rain-dance", "body-slam"]], ["poliwhirl", 35, 0, 11, ["water-gun", "double-slap", "rain-dance", "body-slam"]], ["poliwag", 34, 0, 3, ["water-gun", "double-slap", "rain-dance", "body-slam"]]]}, -"TRAINER_PKMN_BREEDER_ALIZE": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 48, 30, 10, ["slam", "thunderbolt", "agility", "thunder"]], ["clefairy", 48, 30, 10, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["marill", 48, 30, 19, ["bubble-beam", "double-edge", "rain-dance", "hydro-pump"]]]}, -"TRAINER_PKMN_RANGER_NICOLAS": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["weepinbell", 51, 100, 14, ["razor-leaf", "acid", "sweet-scent", "wrap"]], ["victreebel", 51, 100, 5, ["razor-leaf", "acid", "sleep-powder", "stun-spore"]]]}, -"TRAINER_PKMN_RANGER_MADELINE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["gloom", 51, 100, 3, ["petal-dance", "acid", "sweet-scent", "poison-powder"]], ["vileplume", 51, 100, 18, ["petal-dance", "moonlight", "acid", "stun-spore"]]]}, -"TRAINER_AROMA_LADY_NIKKI": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 37, 0, 24, ["stun-spore", "acid", "sweet-scent", "razor-leaf"]], ["weepinbell", 37, 0, 6, ["poison-powder", "stun-spore", "acid", "sweet-scent"]]]}, -"TRAINER_RUIN_MANIAC_STANLY": {"ai": ["check-bad-move"], "items": [], "party": [["graveler", 48, 0, 9, ["self-destruct", "rollout", "rock-blast", "earthquake"]], ["onix", 48, 0, 12, ["dragon-breath", "sandstorm", "slam", "iron-tail"]], ["graveler", 48, 0, 10, ["self-destruct", "rollout", "rock-blast", "earthquake"]]]}, -"TRAINER_LADY_JACKI": {"ai": ["check-bad-move"], "items": ["full-restore"], "party": [["hoppip", 48, 0, 21, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]], ["skiploom", 50, 0, 18, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]]]}, -"TRAINER_PAINTER_DAISY": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 50, 50, 22, ["dynamic-punch", "dizzy-punch", "focus-punch", "mega-punch"]]]}, -"TRAINER_BIKER_GOON": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 37, 0, 1, ["haze", "smokescreen", "sludge", "tackle"]], ["grimer", 37, 0, 12, ["acid-armor", "screech", "minimize", "sludge"]]]}, -"TRAINER_BIKER_GOON_2": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 38, 0, 1, ["haze", "smokescreen", "sludge", "tackle"]]]}, -"TRAINER_BIKER_GOON_3": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 38, 0, 22, ["sludge", "minimize", "screech", "acid-armor"]]]}, -"TRAINER_BUG_CATCHER_ANTHONY": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 7, 0, 20, ["tackle", "string-shot"]], ["caterpie", 8, 0, 4, ["tackle", "string-shot"]]]}, -"TRAINER_BUG_CATCHER_CHARLIE": {"ai": ["check-bad-move"], "items": [], "party": [["metapod", 7, 0, 15, ["harden"]], ["caterpie", 7, 0, 3, ["tackle", "string-shot"]], ["metapod", 7, 0, 7, ["harden"]]]}, -"TRAINER_TWINS_ELI_ANNE_2": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 28, 60, 22, ["double-slap", "follow-me", "minimize", "defense-curl"]], ["jigglypuff", 28, 60, 13, ["pound", "disable", "rollout", "double-slap"]]]}, -"TRAINER_YOUNGSTER_JOHNSON": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 33, 0, 23, ["bite", "glare", "screech", "acid"]], ["ekans", 33, 0, 10, ["bite", "glare", "screech", "acid"]], ["raticate", 34, 0, 7, ["quick-attack", "hyper-fang", "scary-face", "pursuit"]]]}, -"TRAINER_BIKER_RICARDO": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 22, 0, 1, ["sludge", "smog", "tackle", "poison-gas"]], ["koffing", 22, 0, 16, ["sludge", "smog", "tackle", "poison-gas"]], ["grimer", 23, 0, 2, ["minimize", "sludge", "disable", "pound"]]]}, -"TRAINER_BIKER_JAREN": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 24, 0, 20, ["harden", "disable", "sludge", "minimize"]], ["grimer", 24, 0, 4, ["harden", "disable", "sludge", "minimize"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_43": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 37, 0, 2, ["bonemerang", "rage", "false-swipe", "thrash"]], ["marowak", 37, 0, 16, ["leer", "focus-energy", "bonemerang", "rage"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_44": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 35, 0, 19, ["hyper-fang", "focus-energy", "pursuit", "super-fang"]], ["raticate", 35, 0, 19, ["quick-attack", "hyper-fang", "scary-face", "pursuit"]], ["sandshrew", 35, 0, 14, ["sand-attack", "poison-sting", "slash", "swift"]], ["sandslash", 35, 0, 0, ["sand-attack", "poison-sting", "slash", "swift"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_45": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 38, 0, 21, ["wing-attack", "confuse-ray", "air-cutter", "mean-look"]], ["zubat", 38, 0, 6, ["wing-attack", "confuse-ray", "air-cutter", "mean-look"]], ["golbat", 38, 0, 4, ["bite", "wing-attack", "confuse-ray", "air-cutter"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_46": {"ai": ["check-bad-move"], "items": [], "party": [["muk", 48, 0, 14, ["minimize", "screech", "acid-armor", "sludge-bomb"]], ["golbat", 48, 0, 12, ["wing-attack", "confuse-ray", "air-cutter", "mean-look"]], ["raticate", 48, 0, 12, ["hyper-fang", "scary-face", "pursuit", "super-fang"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_47": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 48, 0, 3, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machop", 48, 0, 20, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machoke", 48, 0, 3, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_48": {"ai": ["check-bad-move"], "items": [], "party": [["hypno", 49, 0, 19, ["meditate", "psychic", "psych-up", "swagger"]], ["hypno", 49, 0, 2, ["meditate", "psychic", "psych-up", "swagger"]]]}, -"TRAINER_TEAM_ROCKET_ADMIN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["muk", 52, 150, 5, ["sludge-bomb", "screech", "minimize", "rock-tomb"]], ["arbok", 53, 150, 18, ["sludge-bomb", "bite", "earthquake", "iron-tail"]], ["vileplume", 54, 150, 3, ["sludge-bomb", "giga-drain", "sleep-powder", "stun-spore"]]]}, -"TRAINER_TEAM_ROCKET_ADMIN_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["golbat", 53, 200, 0, ["confuse-ray", "sludge-bomb", "air-cutter", "shadow-ball"]], ["weezing", 54, 200, 22, ["sludge-bomb", "thunderbolt", "explosion", "shadow-ball"]], ["houndoom", 55, 200, 6, ["flamethrower", "crunch", "iron-tail", "shadow-ball"]]]}, -"TRAINER_SCIENTIST_GIDEON": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 46, 0, 17, ["swift", "screech", "spark", "sonic-boom"]], ["electrode", 46, 0, 3, ["spark", "sonic-boom", "screech", "charge"]], ["magnemite", 46, 0, 14, ["screech", "swift", "spark", "thunder-wave"]], ["magneton", 46, 0, 21, ["tri-attack", "spark", "thunder-wave", "sonic-boom"]], ["porygon", 46, 0, 13, ["tri-attack", "conversion", "recover", "psybeam"]]]}, -"TRAINER_SWIMMER_FEMALE_AMARA": {"ai": ["check-bad-move"], "items": [], "party": [["seel", 36, 0, 14, ["growl", "icy-wind", "aurora-beam", "rest"]], ["seel", 36, 0, 8, ["growl", "icy-wind", "aurora-beam", "rest"]], ["dewgong", 36, 0, 4, ["icy-wind", "aurora-beam", "rest", "sheer-cold"]]]}, -"TRAINER_SWIMMER_FEMALE_MARIA": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 37, 0, 11, ["smokescreen", "leer", "water-gun", "twister"]], ["seadra", 37, 0, 2, ["smokescreen", "leer", "water-gun", "twister"]]]}, -"TRAINER_SWIMMER_FEMALE_ABIGAIL": {"ai": ["check-bad-move"], "items": [], "party": [["psyduck", 35, 0, 9, ["disable", "confusion", "screech", "psych-up"]], ["psyduck", 36, 0, 23, ["disable", "confusion", "screech", "psych-up"]], ["golduck", 37, 0, 6, ["disable", "confusion", "screech", "psych-up"]]]}, -"TRAINER_SWIMMER_MALE_FINN": {"ai": ["check-bad-move"], "items": [], "party": [["starmie", 38, 0, 5, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, -"TRAINER_SWIMMER_MALE_GARRETT": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 35, 0, 8, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["cloyster", 35, 0, 9, ["withdraw", "supersonic", "aurora-beam", "protect"]], ["wartortle", 38, 0, 16, ["bite", "rapid-spin", "protect", "rain-dance"]]]}, -"TRAINER_FISHERMAN_TOMMY": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 33, 0, 16, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["goldeen", 33, 0, 21, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 35, 0, 0, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 35, 0, 4, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 35, 0, 8, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, -"TRAINER_CRUSH_GIRL_TANYA": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonlee", 38, 50, 7, ["focus-energy", "high-jump-kick", "mind-reader", "foresight"]], ["hitmonchan", 38, 50, 18, ["ice-punch", "fire-punch", "sky-uppercut", "mega-punch"]]]}, -"TRAINER_BLACK_BELT_SHEA": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 38, 100, 5, ["foresight", "revenge", "vital-throw", "submission"]], ["machoke", 38, 100, 15, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, -"TRAINER_BLACK_BELT_HUGH": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 37, 100, 21, ["foresight", "revenge", "vital-throw", "submission"]], ["machoke", 37, 100, 22, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, -"TRAINER_CAMPER_BRYCE": {"ai": ["check-bad-move"], "items": [], "party": [["nidorino", 36, 0, 0, ["poison-sting", "horn-attack", "helping-hand", "fury-attack"]], ["raticate", 36, 0, 13, ["quick-attack", "hyper-fang", "scary-face", "pursuit"]], ["sandslash", 36, 0, 12, ["sand-attack", "poison-sting", "slash", "swift"]]]}, -"TRAINER_PICNICKER_CLAIRE": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 35, 0, 4, ["bite", "pay-day", "feint-attack", "screech"]], ["meowth", 35, 0, 13, ["bite", "pay-day", "feint-attack", "screech"]], ["pikachu", 35, 0, 23, ["double-team", "slam", "thunderbolt", "agility"]], ["clefairy", 35, 0, 9, ["minimize", "defense-curl", "metronome", "cosmic-power"]]]}, -"TRAINER_CRUSH_KIN_MIK_KIA": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 39, 50, 16, ["seismic-toss", "foresight", "revenge", "vital-throw"]], ["primeape", 39, 50, 7, ["focus-energy", "seismic-toss", "rage", "cross-chop"]]]}, -"TRAINER_AROMA_LADY_VIOLET": {"ai": ["check-bad-move"], "items": [], "party": [["bulbasaur", 36, 0, 15, ["sleep-powder", "razor-leaf", "sweet-scent", "growth"]], ["ivysaur", 36, 0, 11, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]], ["ivysaur", 36, 0, 7, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]]]}, -"TRAINER_TUBER_ALEXIS": {"ai": ["check-bad-move"], "items": [], "party": [["staryu", 34, 0, 22, ["camouflage", "swift", "bubble-beam", "minimize"]], ["staryu", 34, 0, 8, ["camouflage", "swift", "bubble-beam", "minimize"]], ["krabby", 34, 0, 24, ["harden", "mud-shot", "stomp", "guillotine"]], ["krabby", 34, 0, 15, ["harden", "mud-shot", "stomp", "guillotine"]]]}, -"TRAINER_TWINS_JOY_MEG": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 37, 0, 21, ["defense-curl", "metronome", "cosmic-power", "moonlight"]], ["clefairy", 37, 0, 14, ["defense-curl", "metronome", "cosmic-power", "moonlight"]]]}, -"TRAINER_SWIMMER_FEMALE_TISHA": {"ai": ["check-bad-move"], "items": [], "party": [["kingler", 38, 0, 10, ["harden", "mud-shot", "stomp", "guillotine"]]]}, -"TRAINER_PAINTER_CELINA": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 50, 50, 4, ["fly", "dig", "dive", "bounce"]]]}, -"TRAINER_PAINTER_RAYNA": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 50, 50, 3, ["cross-chop", "megahorn", "double-edge", "self-destruct"]]]}, -"TRAINER_LADY_GILLIAN": {"ai": ["check-bad-move"], "items": ["full-restore"], "party": [["mareep", 47, 0, 1, ["thunder-wave", "cotton-spore", "light-screen", "thunder"]], ["mareep", 48, 0, 16, ["thunder-wave", "cotton-spore", "light-screen", "thunder"]], ["flaaffy", 49, 0, 16, ["thunder-wave", "cotton-spore", "light-screen", "thunder"]]]}, -"TRAINER_YOUNGSTER_DESTIN": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 48, 0, 23, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["pidgeotto", 48, 0, 5, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, -"TRAINER_SWIMMER_MALE_TOBY": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 48, 0, 23, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["tentacool", 48, 0, 8, ["bubble-beam", "wrap", "barrier", "screech"]], ["tentacruel", 48, 0, 18, ["bubble-beam", "wrap", "barrier", "screech"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_49": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 48, 0, 19, ["focus-energy", "pursuit", "super-fang", "endeavor"]], ["grimer", 48, 0, 20, ["minimize", "screech", "acid-armor", "sludge-bomb"]], ["muk", 48, 0, 23, ["minimize", "screech", "acid-armor", "sludge-bomb"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_50": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 49, 0, 16, ["memento", "haze", "smokescreen", "sludge"]], ["weezing", 49, 0, 22, ["haze", "smokescreen", "sludge", "self-destruct"]]]}, -"TRAINER_TEAM_ROCKET_GRUNT_51": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 48, 50, 1, ["stockpile", "swallow", "spit-up", "haze"]], ["gloom", 48, 50, 13, ["sleep-powder", "acid", "moonlight", "petal-dance"]], ["gloom", 48, 50, 0, ["sleep-powder", "acid", "moonlight", "petal-dance"]]]}, -"TRAINER_BIRD_KEEPER_MILO": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 47, 0, 11, ["wing-attack", "feather-dance", "agility", "mirror-move"]], ["pidgeotto", 49, 0, 4, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, -"TRAINER_BIRD_KEEPER_CHAZ": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 47, 0, 22, ["aerial-ace", "mirror-move", "drill-peck", "agility"]], ["fearow", 49, 0, 18, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, -"TRAINER_BIRD_KEEPER_HAROLD": {"ai": ["check-bad-move"], "items": [], "party": [["hoothoot", 47, 0, 4, ["hypnosis", "reflect", "take-down", "confusion"]], ["noctowl", 49, 0, 22, ["hypnosis", "reflect", "take-down", "confusion"]]]}, -"TRAINER_FISHERMAN_TYLOR": {"ai": ["check-bad-move"], "items": [], "party": [["qwilfish", 49, 0, 2, ["revenge", "take-down", "hydro-pump", "destiny-bond"]], ["qwilfish", 49, 0, 18, ["revenge", "take-down", "hydro-pump", "destiny-bond"]]]}, -"TRAINER_SWIMMER_MALE_MYMO": {"ai": ["check-bad-move"], "items": [], "party": [["kingler", 49, 0, 14, ["mud-shot", "stomp", "guillotine", "protect"]], ["wartortle", 49, 0, 10, ["rapid-spin", "protect", "rain-dance", "skull-bash"]]]}, -"TRAINER_SWIMMER_FEMALE_NICOLE": {"ai": ["check-bad-move"], "items": [], "party": [["marill", 50, 0, 0, ["bubble-beam", "double-edge", "rain-dance", "hydro-pump"]]]}, -"TRAINER_SIS_AND_BRO_AVA_GEB": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 50, 0, 23, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["starmie", 50, 0, 14, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, -"TRAINER_AROMA_LADY_ROSE": {"ai": ["check-bad-move"], "items": [], "party": [["sunkern", 49, 0, 0, ["endeavor", "sunny-day", "synthesis", "giga-drain"]], ["sunflora", 49, 0, 20, ["bullet-seed", "sunny-day", "petal-dance", "solar-beam"]]]}, -"TRAINER_SWIMMER_MALE_SAMIR": {"ai": ["check-bad-move"], "items": [], "party": [["gyarados", 50, 0, 19, ["twister", "hydro-pump", "rain-dance", "dragon-dance"]]]}, -"TRAINER_SWIMMER_FEMALE_DENISE": {"ai": ["check-bad-move"], "items": [], "party": [["chinchou", 49, 0, 16, ["confuse-ray", "take-down", "hydro-pump", "charge"]], ["lanturn", 49, 0, 10, ["water-gun", "spark", "confuse-ray", "take-down"]]]}, -"TRAINER_TWINS_MIU_MIA": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 50, 0, 16, ["thunderbolt", "agility", "thunder", "light-screen"]], ["pikachu", 50, 0, 4, ["thunderbolt", "agility", "thunder", "light-screen"]]]}, -"TRAINER_HIKER_EARL": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 49, 0, 2, ["dragon-breath", "sandstorm", "slam", "iron-tail"]], ["machoke", 49, 0, 5, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, -"TRAINER_RUIN_MANIAC_FOSTER": {"ai": ["check-bad-move"], "items": [], "party": [["golem", 50, 0, 22, ["self-destruct", "rollout", "rock-blast", "earthquake"]]]}, -"TRAINER_RUIN_MANIAC_LARRY": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 49, 0, 8, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machoke", 49, 0, 5, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, -"TRAINER_HIKER_DARYL": {"ai": ["check-bad-move"], "items": [], "party": [["sudowoodo", 50, 0, 6, ["rock-slide", "block", "feint-attack", "slam"]]]}, -"TRAINER_POKEMANIAC_HECTOR": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 49, 30, 19, ["scary-face", "rock-blast", "horn-drill", "take-down"]], ["kangaskhan", 49, 30, 11, ["rage", "endure", "dizzy-punch", "reversal"]]]}, -"TRAINER_PSYCHIC_DARIO": {"ai": ["check-bad-move"], "items": [], "party": [["girafarig", 52, 100, 23, ["crunch", "psybeam", "odor-sleuth", "agility"]]]}, -"TRAINER_PSYCHIC_RODETTE": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 48, 100, 4, ["night-shade", "confuse-ray", "wish", "future-sight"]], ["drowzee", 48, 100, 1, ["psychic", "disable", "psych-up", "future-sight"]], ["hypno", 50, 100, 8, ["psychic", "hypnosis", "psych-up", "future-sight"]]]}, -"TRAINER_AROMA_LADY_MIAH": {"ai": ["check-bad-move"], "items": [], "party": [["bellossom", 50, 0, 11, ["sweet-scent", "stun-spore", "magical-leaf", "petal-dance"]], ["bellossom", 50, 0, 2, ["sweet-scent", "stun-spore", "magical-leaf", "petal-dance"]]]}, -"TRAINER_YOUNG_COUPLE_EVE_JON": {"ai": ["check-bad-move"], "items": [], "party": [["golduck", 50, 0, 20, ["confusion", "screech", "psych-up", "fury-swipes"]], ["psyduck", 50, 0, 18, ["screech", "psych-up", "fury-swipes", "hydro-pump"]]]}, -"TRAINER_JUGGLER_MASON": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 47, 0, 24, ["swift", "light-screen", "spark", "sonic-boom"]], ["pineco", 47, 0, 19, ["spikes", "bide", "rapid-spin", "take-down"]], ["voltorb", 47, 0, 7, ["swift", "light-screen", "spark", "sonic-boom"]], ["pineco", 47, 0, 2, ["spikes", "bide", "rapid-spin", "explosion"]]]}, -"TRAINER_CRUSH_GIRL_CYNDY": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 48, 50, 18, ["seismic-toss", "rage", "cross-chop", "swagger"]], ["hitmontop", 48, 50, 23, ["rapid-spin", "counter", "agility", "detect"]], ["machoke", 48, 50, 2, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, -"TRAINER_CRUSH_GIRL_JOCELYN": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 38, 50, 17, ["ice-punch", "fire-punch", "sky-uppercut", "mega-punch"]], ["hitmonchan", 38, 50, 23, ["ice-punch", "fire-punch", "sky-uppercut", "mega-punch"]]]}, -"TRAINER_TAMER_EVAN": {"ai": ["check-bad-move"], "items": [], "party": [["sandslash", 48, 40, 3, ["poison-sting", "slash", "swift", "fury-swipes"]], ["lickitung", 48, 40, 24, ["wrap", "disable", "slam", "screech"]], ["ursaring", 49, 40, 10, ["rest", "slash", "snore", "thrash"]]]}, -"TRAINER_POKEMANIAC_MARK_2": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 33, 90, 6, ["stomp", "fury-attack", "scary-face", "rock-blast"]], ["lickitung", 33, 90, 8, ["defense-curl", "knock-off", "stomp", "wrap"]]]}, -"TRAINER_PKMN_RANGER_LOGAN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["exeggcute", 37, 100, 11, ["sleep-powder", "poison-powder", "stun-spore", "confusion"]], ["exeggutor", 40, 100, 11, ["egg-bomb", "stomp", "confusion", "hypnosis"]]]}, -"TRAINER_PKMN_RANGER_JACKSON": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["tangela", 49, 100, 8, ["slam", "mega-drain", "bind", "ingrain"]], ["exeggcute", 49, 100, 9, ["confusion", "poison-powder", "barrage", "reflect"]], ["exeggutor", 49, 100, 10, ["confusion", "egg-bomb", "sleep-powder", "stomp"]]]}, -"TRAINER_PKMN_RANGER_BETH": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["bellsprout", 38, 100, 19, ["stun-spore", "acid", "sweet-scent", "razor-leaf"]], ["gloom", 38, 100, 20, ["stun-spore", "sleep-powder", "acid", "moonlight"]], ["gloom", 38, 100, 21, ["stun-spore", "sleep-powder", "acid", "moonlight"]]]}, -"TRAINER_PKMN_RANGER_KATELYN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["chansey", 52, 100, 22, ["egg-bomb", "defense-curl", "minimize", "soft-boiled"]]]}, -"TRAINER_COOLTRAINER_LEROY": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["rhydon", 47, 100, 16, ["take-down", "horn-drill", "rock-blast", "scary-face"]], ["slowbro", 48, 100, 7, ["psychic", "headbutt", "amnesia", "disable"]], ["kangaskhan", 47, 100, 19, ["dizzy-punch", "bite", "endure", "reversal"]], ["machoke", 48, 100, 22, ["cross-chop", "vital-throw", "revenge", "seismic-toss"]], ["ursaring", 50, 100, 22, ["slash", "feint-attack", "snore", "rest"]]]}, -"TRAINER_COOLTRAINER_MICHELLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["persian", 47, 100, 4, ["slash", "screech", "feint-attack", "bite"]], ["dewgong", 47, 100, 21, ["ice-beam", "take-down", "icy-wind", "growl"]], ["ninetales", 48, 100, 14, ["flamethrower", "confuse-ray", "will-o-wisp", "grudge"]], ["rapidash", 48, 100, 3, ["bounce", "agility", "fire-spin", "take-down"]], ["girafarig", 50, 100, 8, ["crunch", "psybeam", "stomp", "odor-sleuth"]]]}, -"TRAINER_COOL_COUPLE_LEX_NYA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["miltank", 52, 100, 22, ["body-slam", "milk-drink", "growl", "defense-curl"]], ["tauros", 52, 100, 9, ["thrash", "horn-attack", "pursuit", "swagger"]]]}, -"TRAINER_RUIN_MANIAC_BRANDON": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 50, 0, 17, ["dragon-breath", "sandstorm", "slam", "iron-tail"]]]}, -"TRAINER_RUIN_MANIAC_BENJAMIN": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 48, 0, 0, ["earthquake", "rock-blast", "rollout", "self-destruct"]], ["graveler", 48, 0, 17, ["earthquake", "rock-blast", "rock-throw", "self-destruct"]], ["graveler", 48, 0, 9, ["earthquake", "rock-blast", "rock-throw", "self-destruct"]]]}, -"TRAINER_PAINTER_EDNA": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 50, 50, 2, ["fake-out", "extreme-speed", "protect", "quick-attack"]]]}, -"TRAINER_GENTLEMAN_CLIFFORD": {"ai": ["check-bad-move"], "items": [], "party": [["marowak", 49, 0, 6, ["bonemerang", "rage", "false-swipe", "thrash"]], ["golduck", 49, 0, 22, ["confusion", "screech", "psych-up", "fury-swipes"]]]}, -"TRAINER_LADY_SELPHY": {"ai": ["check-bad-move"], "items": ["full-restore"], "party": [["persian", 49, 0, 21, ["pay-day", "bite", "taunt", "torment"]], ["persian", 49, 0, 6, ["pay-day", "scratch", "torment", "taunt"]]]}, -"TRAINER_RUIN_MANIAC_LAWSON": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 47, 0, 22, ["dragon-breath", "sandstorm", "slam", "iron-tail"]], ["graveler", 48, 0, 3, ["self-destruct", "rollout", "rock-blast", "earthquake"]], ["marowak", 49, 0, 7, ["bonemerang", "rage", "false-swipe", "thrash"]]]}, -"TRAINER_PSYCHIC_LAURA": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 48, 100, 18, ["teleport", "wish", "future-sight", "confuse-ray"]], ["natu", 48, 100, 16, ["teleport", "wish", "future-sight", "confuse-ray"]], ["xatu", 49, 100, 24, ["night-shade", "teleport", "wish", "future-sight"]]]}, -"TRAINER_PKMN_BREEDER_BETHANY": {"ai": ["check-bad-move"], "items": [], "party": [["chansey", 50, 30, 10, ["sing", "egg-bomb", "defense-curl", "light-screen"]]]}, -"TRAINER_PKMN_BREEDER_ALLISON": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 48, 30, 17, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["clefairy", 48, 30, 23, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["clefable", 48, 30, 6, ["sing", "double-slap", "minimize", "metronome"]]]}, -"TRAINER_BUG_CATCHER_GARRET": {"ai": ["check-bad-move"], "items": [], "party": [["heracross", 49, 0, 1, ["brick-break", "counter", "take-down", "reversal"]]]}, -"TRAINER_BUG_CATCHER_JONAH": {"ai": ["check-bad-move"], "items": [], "party": [["yanma", 45, 0, 8, ["detect", "uproar", "wing-attack", "supersonic"]], ["beedrill", 45, 0, 6, ["pursuit", "pin-missile", "agility", "endeavor"]], ["yanma", 46, 0, 3, ["detect", "uproar", "wing-attack", "supersonic"]], ["beedrill", 47, 0, 1, ["pursuit", "pin-missile", "agility", "endeavor"]]]}, -"TRAINER_BUG_CATCHER_VANCE": {"ai": ["check-bad-move"], "items": [], "party": [["venonat", 48, 0, 19, ["stun-spore", "psybeam", "sleep-powder", "psychic"]], ["venomoth", 48, 0, 19, ["stun-spore", "gust", "psybeam", "sleep-powder"]]]}, -"TRAINER_YOUNGSTER_NASH": {"ai": ["check-bad-move"], "items": [], "party": [["weepinbell", 47, 0, 5, ["stun-spore", "acid", "sweet-scent", "razor-leaf"]], ["weepinbell", 47, 0, 24, ["stun-spore", "acid", "sweet-scent", "razor-leaf"]], ["victreebel", 49, 0, 6, ["vine-whip", "sleep-powder", "sweet-scent", "razor-leaf"]]]}, -"TRAINER_YOUNGSTER_CORDELL": {"ai": ["check-bad-move"], "items": [], "party": [["farfetch-d", 48, 0, 12, ["swords-dance", "agility", "slash", "false-swipe"]], ["farfetch-d", 48, 0, 13, ["swords-dance", "agility", "slash", "false-swipe"]]]}, -"TRAINER_LASS_DALIA": {"ai": ["check-bad-move"], "items": [], "party": [["hoppip", 46, 0, 13, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]], ["hoppip", 47, 0, 6, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]], ["skiploom", 47, 0, 11, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]], ["skiploom", 48, 0, 16, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]]]}, -"TRAINER_LASS_JOANA": {"ai": ["check-bad-move"], "items": [], "party": [["snubbull", 49, 0, 17, ["lick", "roar", "rage", "take-down"]]]}, -"TRAINER_CAMPER_RILEY": {"ai": ["check-bad-move"], "items": [], "party": [["pinsir", 49, 0, 11, ["brick-break", "guillotine", "submission", "swords-dance"]], ["heracross", 50, 0, 10, ["brick-break", "counter", "take-down", "reversal"]]]}, -"TRAINER_PICNICKER_MARCY": {"ai": ["check-bad-move"], "items": [], "party": [["paras", 48, 0, 20, ["spore", "slash", "growth", "giga-drain"]], ["paras", 48, 0, 20, ["spore", "slash", "growth", "giga-drain"]], ["parasect", 49, 0, 11, ["leech-life", "spore", "slash", "growth"]]]}, -"TRAINER_RUIN_MANIAC_LAYTON": {"ai": ["check-bad-move"], "items": [], "party": [["sandslash", 48, 0, 5, ["poison-sting", "slash", "swift", "fury-swipes"]], ["onix", 48, 0, 9, ["dragon-breath", "sandstorm", "slam", "iron-tail"]], ["sandslash", 48, 0, 3, ["poison-sting", "slash", "swift", "fury-swipes"]]]}, -"TRAINER_PICNICKER_KELSEY_2": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 21, 20, 1, ["focus-energy", "double-kick", "poison-sting", "horn-attack"]], ["nidoran-f", 21, 20, 13, ["tail-whip", "double-kick", "poison-sting", "bite"]]]}, -"TRAINER_PICNICKER_KELSEY_3": {"ai": ["check-bad-move"], "items": [], "party": [["nidorino", 29, 60, 19, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]], ["nidorina", 29, 60, 9, ["double-kick", "poison-sting", "bite", "helping-hand"]]]}, -"TRAINER_PICNICKER_KELSEY_4": {"ai": ["check-bad-move"], "items": [], "party": [["nidorino", 49, 80, 19, ["horn-attack", "helping-hand", "fury-attack", "flatter"]], ["nidorina", 49, 80, 9, ["bite", "helping-hand", "fury-swipes", "flatter"]]]}, -"TRAINER_CAMPER_RICKY_2": {"ai": ["check-bad-move"], "items": [], "party": [["squirtle", 22, 20, 16, ["bubble", "withdraw", "water-gun", "bite"]]]}, -"TRAINER_CAMPER_RICKY_3": {"ai": ["check-bad-move"], "items": [], "party": [["wartortle", 30, 60, 23, ["withdraw", "water-gun", "bite", "rapid-spin"]]]}, -"TRAINER_CAMPER_RICKY_4": {"ai": ["check-bad-move"], "items": [], "party": [["wartortle", 55, 120, 23, ["protect", "rain-dance", "skull-bash", "hydro-pump"]]]}, -"TRAINER_CAMPER_JEFF_2": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 21, 20, 6, ["growl", "leer", "fury-attack", "pursuit"]], ["raticate", 21, 20, 22, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, -"TRAINER_CAMPER_JEFF_3": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 29, 60, 16, ["growl", "leer", "fury-attack", "pursuit"]], ["raticate", 29, 60, 7, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, -"TRAINER_CAMPER_JEFF_4": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 54, 120, 16, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["raticate", 54, 120, 7, ["scary-face", "pursuit", "super-fang", "endeavor"]]]}, -"TRAINER_PICNICKER_ISABELLE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 21, 20, 23, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["pidgeotto", 21, 20, 1, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["pidgey", 18, 20, 11, ["tackle", "sand-attack", "gust", "quick-attack"]]]}, -"TRAINER_PICNICKER_ISABELLE_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 29, 60, 23, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 29, 60, 1, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 26, 60, 4, ["sand-attack", "gust", "quick-attack", "whirlwind"]]]}, -"TRAINER_PICNICKER_ISABELLE_4": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 47, 80, 23, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["pidgeotto", 47, 80, 1, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["pidgeot", 50, 80, 12, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, -"TRAINER_YOUNGSTER_YASU_2": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 22, 40, 19, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["raticate", 22, 40, 19, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["raticate", 22, 40, 19, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, -"TRAINER_YOUNGSTER_YASU_3": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 47, 80, 11, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["raticate", 47, 80, 11, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["raticate", 47, 80, 11, ["hyper-fang", "scary-face", "pursuit", "super-fang"]]]}, -"TRAINER_ENGINEER_BERNIE_2": {"ai": ["check-bad-move"], "items": [], "party": [["magneton", 28, 60, 12, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["magneton", 28, 60, 13, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["magneton", 28, 60, 14, ["supersonic", "sonic-boom", "thunder-wave", "spark"]]]}, -"TRAINER_GAMER_DARIAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 29, 60, 10, ["ember", "leer", "odor-sleuth", "take-down"]], ["vulpix", 29, 60, 8, ["will-o-wisp", "confuse-ray", "imprison", "flamethrower"]]]}, -"TRAINER_CAMPER_CHRIS_2": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 24, 40, 4, ["roar", "ember", "leer", "odor-sleuth"]], ["charmander", 24, 40, 21, ["growl", "ember", "metal-claw", "smokescreen"]]]}, -"TRAINER_CAMPER_CHRIS_3": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 29, 60, 4, ["ember", "leer", "odor-sleuth", "take-down"]], ["charmeleon", 29, 60, 0, ["ember", "metal-claw", "smokescreen", "scary-face"]]]}, -"TRAINER_CAMPER_CHRIS_4": {"ai": ["check-bad-move"], "items": [], "party": [["arcanine", 54, 120, 1, ["roar", "ember", "odor-sleuth", "extreme-speed"]], ["charmeleon", 54, 120, 22, ["scary-face", "flamethrower", "slash", "dragon-rage"]]]}, -"TRAINER_PICNICKER_ALICIA_2": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 25, 40, 1, ["growl", "bite", "pay-day", "feint-attack"]]]}, -"TRAINER_PICNICKER_ALICIA_3": {"ai": ["check-bad-move"], "items": [], "party": [["persian", 30, 60, 5, ["growl", "bite", "pay-day", "feint-attack"]]]}, -"TRAINER_PICNICKER_ALICIA_4": {"ai": ["check-bad-move"], "items": [], "party": [["persian", 55, 120, 5, ["screech", "fury-swipes", "slash", "fake-out"]]]}, -"TRAINER_HIKER_JEREMY_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 30, 60, 11, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["onix", 28, 60, 24, ["bind", "rock-throw", "harden", "rage"]]]}, -"TRAINER_POKEMANIAC_MARK_3": {"ai": ["check-bad-move"], "items": [], "party": [["rhydon", 54, 150, 8, ["scary-face", "rock-blast", "horn-drill", "take-down"]], ["lickitung", 54, 150, 10, ["disable", "slam", "screech", "refresh"]]]}, -"TRAINER_POKEMANIAC_HERMAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["marowak", 29, 90, 15, ["headbutt", "leer", "focus-energy", "bonemerang"]], ["slowbro", 29, 90, 1, ["water-gun", "confusion", "disable", "headbutt"]]]}, -"TRAINER_POKEMANIAC_HERMAN_3": {"ai": ["check-bad-move"], "items": [], "party": [["marowak", 54, 150, 15, ["rage", "false-swipe", "thrash", "bone-rush"]], ["slowbro", 54, 150, 1, ["headbutt", "amnesia", "withdraw", "psychic"]]]}, -"TRAINER_HIKER_TRENT_2": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 31, 60, 14, ["rock-throw", "harden", "rage", "dragon-breath"]], ["graveler", 31, 60, 12, ["rock-throw", "magnitude", "self-destruct", "rollout"]]]}, -"TRAINER_LASS_MEGAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 22, 40, 0, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["raticate", 22, 40, 10, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["nidoran-m", 23, 40, 3, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]], ["meowth", 21, 40, 23, ["scratch", "growl", "bite", "pay-day"]], ["pikachu", 22, 40, 19, ["thunder-wave", "quick-attack", "double-team", "slam"]]]}, -"TRAINER_LASS_MEGAN_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeot", 46, 80, 8, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["raticate", 47, 80, 18, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["nidorino", 47, 80, 4, ["horn-attack", "helping-hand", "fury-attack", "flatter"]], ["persian", 47, 80, 3, ["pay-day", "feint-attack", "screech", "fury-swipes"]], ["raichu", 48, 80, 4, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, -"TRAINER_SUPER_NERD_GLENN_2": {"ai": ["check-bad-move"], "items": [], "party": [["muk", 28, 60, 21, ["disable", "sludge", "minimize", "screech"]], ["muk", 28, 60, 6, ["disable", "sludge", "minimize", "screech"]], ["muk", 28, 60, 16, ["disable", "sludge", "minimize", "screech"]]]}, -"TRAINER_GAMER_RICH_2": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 30, 60, 24, ["ember", "leer", "odor-sleuth", "take-down"]], ["vulpix", 30, 60, 11, ["will-o-wisp", "confuse-ray", "imprison", "flamethrower"]]]}, -"TRAINER_BIKER_JAREN_2": {"ai": ["check-bad-move"], "items": [], "party": [["muk", 28, 60, 22, ["disable", "sludge", "minimize", "screech"]], ["muk", 30, 60, 8, ["disable", "sludge", "minimize", "screech"]]]}, -"TRAINER_FISHERMAN_ELLIOT_2": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 28, 60, 21, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["cloyster", 28, 60, 10, ["withdraw", "supersonic", "aurora-beam", "protect"]], ["seaking", 28, 60, 2, ["water-sport", "supersonic", "horn-attack", "flail"]], ["seadra", 28, 60, 20, ["bubble", "smokescreen", "leer", "water-gun"]]]}, -"TRAINER_ROCKER_LUCA_2": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 33, 60, 13, ["screech", "sonic-boom", "spark", "self-destruct"]], ["electrode", 33, 60, 15, ["screech", "sonic-boom", "spark", "self-destruct"]]]}, -"TRAINER_BEAUTY_SHEILA_2": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 49, 80, 17, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["persian", 49, 80, 16, ["feint-attack", "screech", "fury-swipes", "slash"]]]}, -"TRAINER_BIRD_KEEPER_ROBERT_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 28, 60, 10, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 28, 60, 9, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["fearow", 28, 60, 2, ["growl", "leer", "fury-attack", "pursuit"]], ["fearow", 28, 60, 20, ["growl", "leer", "fury-attack", "pursuit"]]]}, -"TRAINER_BIRD_KEEPER_ROBERT_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeot", 47, 80, 18, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["pidgeot", 47, 80, 0, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["fearow", 47, 80, 18, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 47, 80, 11, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, -"TRAINER_PICNICKER_SUSIE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 27, 60, 23, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["meowth", 27, 60, 16, ["growl", "bite", "pay-day", "feint-attack"]], ["raticate", 27, 60, 24, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["pikachu", 27, 60, 18, ["quick-attack", "double-team", "slam", "thunderbolt"]], ["meowth", 27, 60, 11, ["growl", "bite", "pay-day", "feint-attack"]]]}, -"TRAINER_PICNICKER_SUSIE_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 47, 80, 23, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["persian", 47, 80, 20, ["pay-day", "feint-attack", "screech", "fury-swipes"]], ["raticate", 47, 80, 3, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["pikachu", 47, 80, 22, ["slam", "thunderbolt", "agility", "thunder"]], ["persian", 47, 80, 19, ["pay-day", "feint-attack", "screech", "fury-swipes"]]]}, -"TRAINER_PICNICKER_SUSIE_4": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeot", 52, 120, 6, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["persian", 52, 120, 3, ["feint-attack", "screech", "fury-swipes", "slash"]], ["raticate", 52, 120, 11, ["scary-face", "pursuit", "super-fang", "endeavor"]], ["raichu", 52, 120, 10, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]], ["persian", 52, 120, 7, ["feint-attack", "screech", "fury-swipes", "slash"]]]}, -"TRAINER_BIKER_LUKAS_2": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 47, 80, 20, ["smokescreen", "haze", "explosion", "destiny-bond"]], ["koffing", 47, 80, 4, ["smokescreen", "haze", "explosion", "destiny-bond"]], ["muk", 47, 80, 11, ["minimize", "screech", "acid-armor", "sludge-bomb"]], ["weezing", 47, 80, 21, ["sludge", "smokescreen", "haze", "explosion"]]]}, -"TRAINER_BIRD_KEEPER_BENNY_2": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 32, 60, 5, ["leer", "fury-attack", "pursuit", "mirror-move"]], ["fearow", 32, 60, 24, ["leer", "fury-attack", "pursuit", "mirror-move"]]]}, -"TRAINER_BIRD_KEEPER_BENNY_3": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 49, 80, 5, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 49, 80, 24, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, -"TRAINER_BIRD_KEEPER_MARLON_2": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 30, 60, 24, ["growl", "leer", "fury-attack", "pursuit"]], ["doduo", 30, 60, 17, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["fearow", 30, 60, 5, ["growl", "leer", "fury-attack", "pursuit"]]]}, -"TRAINER_BIRD_KEEPER_MARLON_3": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 48, 80, 24, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["dodrio", 48, 80, 19, ["tri-attack", "rage", "uproar", "drill-peck"]], ["fearow", 48, 80, 7, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, -"TRAINER_BEAUTY_GRACE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeot", 49, 80, 22, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["wigglytuff", 49, 80, 7, ["sing", "disable", "defense-curl", "double-slap"]]]}, -"TRAINER_BIRD_KEEPER_CHESTER_2": {"ai": ["check-bad-move"], "items": [], "party": [["dodrio", 30, 60, 2, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["dodrio", 30, 60, 18, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["doduo", 30, 60, 7, ["pursuit", "fury-attack", "tri-attack", "rage"]]]}, -"TRAINER_BIRD_KEEPER_CHESTER_3": {"ai": ["check-bad-move"], "items": [], "party": [["dodrio", 48, 80, 2, ["tri-attack", "rage", "uproar", "drill-peck"]], ["dodrio", 48, 80, 18, ["tri-attack", "rage", "uproar", "drill-peck"]], ["dodrio", 48, 80, 9, ["tri-attack", "rage", "uproar", "drill-peck"]]]}, -"TRAINER_PICNICKER_BECKY_2": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 32, 60, 2, ["quick-attack", "double-team", "slam", "thunderbolt"]], ["raichu", 32, 60, 14, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, -"TRAINER_PICNICKER_BECKY_3": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 49, 80, 2, ["slam", "thunderbolt", "agility", "thunder"]], ["raichu", 49, 80, 14, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, -"TRAINER_PICNICKER_BECKY_4": {"ai": ["check-bad-move"], "items": [], "party": [["raichu", 54, 120, 7, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]], ["raichu", 54, 120, 19, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, -"TRAINER_CRUSH_KIN_RON_MYA_2": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 33, 110, 0, ["thunder-punch", "ice-punch", "fire-punch", "sky-uppercut"]], ["hitmonlee", 33, 110, 7, ["brick-break", "focus-energy", "high-jump-kick", "mind-reader"]]]}, -"TRAINER_CRUSH_KIN_RON_MYA_3": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 51, 130, 0, ["sky-uppercut", "mega-punch", "detect", "counter"]], ["hitmonlee", 51, 130, 7, ["foresight", "endure", "mega-kick", "reversal"]]]}, -"TRAINER_CRUSH_KIN_RON_MYA_4": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 56, 170, 0, ["sky-uppercut", "mega-punch", "detect", "counter"]], ["hitmonlee", 56, 170, 7, ["foresight", "endure", "mega-kick", "reversal"]]]}, -"TRAINER_BIKER_RUBEN_2": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 48, 80, 22, ["sludge", "smokescreen", "haze", "explosion"]], ["weezing", 48, 80, 8, ["sludge", "smokescreen", "haze", "explosion"]], ["weezing", 48, 80, 19, ["sludge", "smokescreen", "haze", "explosion"]]]}, -"TRAINER_CUE_BALL_CAMRON_2": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 49, 80, 17, ["seismic-toss", "rage", "cross-chop", "swagger"]], ["machoke", 49, 80, 20, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, -"TRAINER_BIKER_JAXON_2": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 49, 80, 21, ["sludge", "smokescreen", "haze", "explosion"]], ["muk", 49, 80, 3, ["minimize", "screech", "acid-armor", "sludge-bomb"]]]}, -"TRAINER_CUE_BALL_ISAIAH_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 49, 80, 12, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machamp", 49, 80, 7, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, -"TRAINER_CUE_BALL_COREY_2": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 49, 80, 13, ["seismic-toss", "rage", "cross-chop", "swagger"]], ["machamp", 49, 80, 6, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, -"TRAINER_BIRD_KEEPER_JACOB_2": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 28, 60, 6, ["growl", "leer", "fury-attack", "pursuit"]], ["spearow", 28, 60, 16, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 28, 60, 11, ["growl", "leer", "fury-attack", "pursuit"]], ["spearow", 28, 60, 21, ["leer", "fury-attack", "pursuit", "aerial-ace"]]]}, -"TRAINER_BIRD_KEEPER_JACOB_3": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 47, 80, 6, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 47, 80, 1, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 47, 80, 21, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 47, 80, 16, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, -"TRAINER_SWIMMER_FEMALE_ALICE_2": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 49, 80, 13, ["flail", "fury-attack", "waterfall", "horn-drill"]], ["seaking", 49, 80, 6, ["flail", "fury-attack", "waterfall", "horn-drill"]]]}, -"TRAINER_SWIMMER_MALE_DARRIN_2": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 52, 120, 0, ["water-gun", "twister", "agility", "hydro-pump"]], ["seadra", 52, 120, 14, ["water-gun", "twister", "agility", "hydro-pump"]], ["seadra", 52, 120, 3, ["water-gun", "twister", "agility", "hydro-pump"]], ["seadra", 52, 120, 17, ["water-gun", "twister", "agility", "hydro-pump"]]]}, -"TRAINER_PICNICKER_MISSY_2": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 49, 80, 18, ["flail", "fury-attack", "waterfall", "horn-drill"]], ["seaking", 49, 80, 16, ["flail", "fury-attack", "waterfall", "horn-drill"]]]}, -"TRAINER_PICNICKER_MISSY_3": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 54, 120, 18, ["flail", "fury-attack", "waterfall", "horn-drill"]], ["seaking", 54, 120, 16, ["flail", "fury-attack", "waterfall", "horn-drill"]]]}, -"TRAINER_FISHERMAN_WADE_2": {"ai": ["check-bad-move"], "items": [], "party": [["magikarp", 47, 80, 7, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 3, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 24, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 20, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 16, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 12, ["splash", "tackle", "flail"]]]}, -"TRAINER_SWIMMER_MALE_JACK_2": {"ai": ["check-bad-move"], "items": [], "party": [["starmie", 50, 80, 22, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, -"TRAINER_SIS_AND_BRO_LIL_IAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 50, 80, 20, ["leer", "water-gun", "twister", "agility"]], ["starmie", 50, 80, 0, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, -"TRAINER_SIS_AND_BRO_LIL_IAN_3": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 55, 120, 20, ["water-gun", "twister", "agility", "hydro-pump"]], ["starmie", 55, 120, 0, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, -"TRAINER_SWIMMER_MALE_FINN_2": {"ai": ["check-bad-move"], "items": [], "party": [["starmie", 50, 80, 5, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, -"TRAINER_CRUSH_GIRL_SHARON_2": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 50, 130, 17, ["cross-chop", "swagger", "screech", "thrash"]], ["primeape", 50, 130, 14, ["seismic-toss", "rage", "cross-chop", "swagger"]]]}, -"TRAINER_CRUSH_GIRL_SHARON_3": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 55, 170, 8, ["rage", "cross-chop", "swagger", "screech"]], ["primeape", 55, 170, 5, ["rage", "cross-chop", "swagger", "screech"]]]}, -"TRAINER_CRUSH_GIRL_TANYA_2": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonlee", 50, 130, 7, ["mind-reader", "foresight", "endure", "mega-kick"]], ["hitmonchan", 50, 130, 18, ["sky-uppercut", "mega-punch", "detect", "counter"]]]}, -"TRAINER_CRUSH_GIRL_TANYA_3": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonlee", 55, 170, 7, ["foresight", "endure", "mega-kick", "reversal"]], ["hitmonchan", 55, 170, 18, ["sky-uppercut", "mega-punch", "detect", "counter"]]]}, -"TRAINER_BLACK_BELT_SHEA_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 50, 180, 21, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machoke", 50, 180, 6, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, -"TRAINER_BLACK_BELT_SHEA_3": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 55, 220, 21, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machamp", 55, 220, 0, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, -"TRAINER_BLACK_BELT_HUGH_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 50, 180, 12, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machoke", 50, 180, 13, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, -"TRAINER_BLACK_BELT_HUGH_3": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 55, 220, 12, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machamp", 55, 220, 7, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, -"TRAINER_CRUSH_KIN_MIK_KIA_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 51, 130, 16, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["primeape", 51, 130, 7, ["seismic-toss", "rage", "cross-chop", "swagger"]]]}, -"TRAINER_CRUSH_KIN_MIK_KIA_3": {"ai": ["check-bad-move"], "items": [], "party": [["machamp", 56, 170, 10, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["primeape", 56, 170, 1, ["rage", "cross-chop", "swagger", "screech"]]]}, -"TRAINER_TUBER_AMIRA_2": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 47, 80, 19, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["poliwhirl", 47, 80, 2, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["poliwhirl", 47, 80, 10, ["double-slap", "rain-dance", "body-slam", "belly-drum"]]]}, -"TRAINER_TWINS_JOY_MEG_2": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 49, 80, 21, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["clefairy", 49, 80, 14, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]]]}, -"TRAINER_PAINTER_RAYNA_2": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 54, 120, 3, ["cross-chop", "megahorn", "double-edge", "self-destruct"]]]}, -"TRAINER_YOUNGSTER_DESTIN_2": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 53, 120, 23, ["scary-face", "pursuit", "super-fang", "endeavor"]], ["pidgeot", 53, 120, 13, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, -"TRAINER_PKMN_BREEDER_ALIZE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 53, 150, 10, ["thunderbolt", "agility", "thunder", "light-screen"]], ["clefairy", 53, 150, 10, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["marill", 53, 150, 19, ["bubble-beam", "double-edge", "rain-dance", "hydro-pump"]]]}, -"TRAINER_YOUNG_COUPLE_GIA_JES_2": {"ai": ["check-bad-move"], "items": [], "party": [["nidorina", 30, 60, 7, ["double-kick", "poison-sting", "bite", "helping-hand"]], ["nidorino", 30, 60, 20, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]]]}, -"TRAINER_YOUNG_COUPLE_GIA_JES_3": {"ai": ["check-bad-move"], "items": [], "party": [["nidoking", 55, 120, 1, ["double-kick", "poison-sting", "thrash", "megahorn"]], ["nidoqueen", 55, 120, 16, ["double-kick", "poison-sting", "body-slam", "superpower"]]]}, -"TRAINER_BIRD_KEEPER_MILO_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 53, 120, 4, ["wing-attack", "feather-dance", "agility", "mirror-move"]], ["pidgeot", 55, 120, 5, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, -"TRAINER_BIRD_KEEPER_CHAZ_2": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 53, 120, 7, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 55, 120, 3, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, -"TRAINER_BIRD_KEEPER_HAROLD_2": {"ai": ["check-bad-move"], "items": [], "party": [["noctowl", 53, 120, 4, ["hypnosis", "reflect", "take-down", "confusion"]], ["noctowl", 55, 120, 22, ["hypnosis", "reflect", "take-down", "confusion"]]]}, -"TRAINER_SWIMMER_FEMALE_NICOLE_2": {"ai": ["check-bad-move"], "items": [], "party": [["marill", 54, 120, 0, ["bubble-beam", "double-edge", "rain-dance", "hydro-pump"]]]}, -"TRAINER_PSYCHIC_JACLYN_2": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 52, 220, 6, ["psychic", "confuse-ray", "future-sight", "wish"]], ["slowbro", 52, 220, 3, ["psychic", "headbutt", "amnesia", "yawn"]], ["kadabra", 54, 220, 4, ["psychic", "future-sight", "recover", "reflect"]]]}, -"TRAINER_SWIMMER_MALE_SAMIR_2": {"ai": ["check-bad-move"], "items": [], "party": [["gyarados", 55, 120, 19, ["hydro-pump", "rain-dance", "dragon-dance", "hyper-beam"]]]}, -"TRAINER_HIKER_EARL_2": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 54, 120, 2, ["sandstorm", "slam", "iron-tail", "sand-tomb"]], ["machamp", 54, 120, 24, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, -"TRAINER_RUIN_MANIAC_LARRY_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 54, 120, 8, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machoke", 54, 120, 5, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, -"TRAINER_POKEMANIAC_HECTOR_2": {"ai": ["check-bad-move"], "items": [], "party": [["rhydon", 55, 150, 21, ["scary-face", "rock-blast", "horn-drill", "take-down"]], ["kangaskhan", 55, 150, 13, ["rage", "endure", "dizzy-punch", "reversal"]]]}, -"TRAINER_PSYCHIC_DARIO_2": {"ai": ["check-bad-move"], "items": [], "party": [["girafarig", 56, 220, 23, ["crunch", "psybeam", "odor-sleuth", "agility"]]]}, -"TRAINER_PSYCHIC_RODETTE_2": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 53, 220, 4, ["psychic", "confuse-ray", "wish", "future-sight"]], ["hypno", 53, 220, 11, ["psychic", "disable", "psych-up", "future-sight"]], ["hypno", 53, 220, 18, ["psychic", "hypnosis", "psych-up", "future-sight"]]]}, -"TRAINER_JUGGLER_MASON_2": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 52, 120, 4, ["self-destruct", "rollout", "light-screen", "swift"]], ["pineco", 52, 120, 24, ["bide", "explosion", "spikes", "double-edge"]], ["electrode", 52, 120, 17, ["self-destruct", "rollout", "light-screen", "swift"]], ["pineco", 52, 120, 12, ["bide", "explosion", "spikes", "double-edge"]]]}, -"TRAINER_PKMN_RANGER_NICOLAS_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["victreebel", 55, 220, 2, ["razor-leaf", "acid", "stun-spore", "wrap"]], ["victreebel", 55, 220, 18, ["razor-leaf", "acid", "sleep-powder", "slam"]]]}, -"TRAINER_PKMN_RANGER_MADELINE_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["vileplume", 55, 220, 10, ["petal-dance", "moonlight", "acid", "sleep-powder"]], ["vileplume", 55, 220, 0, ["petal-dance", "moonlight", "acid", "stun-spore"]]]}, -"TRAINER_CRUSH_GIRL_CYNDY_2": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 54, 170, 18, ["rage", "cross-chop", "swagger", "screech"]], ["hitmontop", 54, 170, 23, ["counter", "agility", "detect", "endeavor"]], ["machamp", 54, 170, 21, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, -"TRAINER_TAMER_EVAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["sandslash", 52, 160, 3, ["slash", "swift", "fury-swipes", "sand-tomb"]], ["lickitung", 52, 160, 24, ["disable", "slam", "screech", "refresh"]], ["ursaring", 55, 160, 10, ["rest", "slash", "snore", "thrash"]]]}, -"TRAINER_PKMN_RANGER_JACKSON_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["tangela", 53, 220, 8, ["slam", "mega-drain", "bind", "ingrain"]], ["exeggutor", 54, 220, 9, ["confusion", "egg-bomb", "stun-spore", "reflect"]], ["exeggutor", 55, 220, 10, ["confusion", "egg-bomb", "sleep-powder", "stomp"]]]}, -"TRAINER_PKMN_RANGER_KATELYN_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["chansey", 56, 220, 22, ["egg-bomb", "defense-curl", "minimize", "soft-boiled"]]]}, -"TRAINER_COOLTRAINER_LEROY_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["rhydon", 52, 220, 16, ["earthquake", "horn-drill", "rock-blast", "scary-face"]], ["slowbro", 54, 220, 7, ["psychic", "headbutt", "amnesia", "disable"]], ["kangaskhan", 52, 220, 19, ["dizzy-punch", "bite", "endure", "reversal"]], ["machamp", 52, 220, 16, ["cross-chop", "vital-throw", "revenge", "seismic-toss"]], ["ursaring", 55, 220, 16, ["slash", "feint-attack", "snore", "rest"]]]}, -"TRAINER_COOLTRAINER_MICHELLE_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["persian", 53, 220, 4, ["slash", "screech", "feint-attack", "bite"]], ["dewgong", 53, 220, 21, ["ice-beam", "take-down", "icy-wind", "sheer-cold"]], ["ninetales", 54, 220, 14, ["flamethrower", "confuse-ray", "will-o-wisp", "grudge"]], ["rapidash", 54, 220, 3, ["bounce", "agility", "fire-spin", "take-down"]], ["girafarig", 56, 220, 8, ["crunch", "psybeam", "stomp", "odor-sleuth"]]]}, -"TRAINER_COOL_COUPLE_LEX_NYA_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["miltank", 57, 220, 22, ["body-slam", "milk-drink", "growl", "defense-curl"]], ["tauros", 57, 220, 9, ["take-down", "scary-face", "pursuit", "swagger"]]]}, -"TRAINER_BUG_CATCHER_COLTON_2": {"ai": ["check-bad-move"], "items": [], "party": [["metapod", 19, 20, 12, ["harden"]], ["weedle", 19, 20, 2, ["poison-sting", "string-shot"]], ["metapod", 19, 20, 3, ["harden"]]]}, -"TRAINER_BUG_CATCHER_COLTON_3": {"ai": ["check-bad-move"], "items": [], "party": [["butterfree", 27, 60, 11, ["stun-spore", "sleep-powder", "supersonic", "whirlwind"]], ["kakuna", 27, 60, 6, ["harden"]], ["butterfree", 27, 60, 6, ["stun-spore", "sleep-powder", "supersonic", "whirlwind"]]]}, -"TRAINER_BUG_CATCHER_COLTON_4": {"ai": ["check-bad-move"], "items": [], "party": [["butterfree", 51, 120, 11, ["gust", "psybeam", "safeguard", "silver-wind"]], ["beedrill", 54, 120, 11, ["pursuit", "pin-missile", "agility", "endeavor"]], ["butterfree", 51, 120, 11, ["gust", "psybeam", "safeguard", "silver-wind"]]]}, -"TRAINER_SWIMMER_MALE_MATTHEW_2": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 49, 80, 14, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["poliwrath", 49, 80, 17, ["water-gun", "hypnosis", "double-slap", "submission"]]]}, -"TRAINER_SWIMMER_MALE_TONY_2": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 49, 80, 3, ["leer", "water-gun", "twister", "agility"]], ["seadra", 49, 80, 20, ["leer", "water-gun", "twister", "agility"]]]}, -"TRAINER_SWIMMER_FEMALE_MELISSA_2": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 49, 80, 1, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["seaking", 49, 80, 14, ["flail", "fury-attack", "waterfall", "horn-drill"]]]}, -"TRAINER_ELITE_FOUR_LORELEI_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["dewgong", 64, 255, 16, ["ice-beam", "surf", "signal-beam", "double-team"]], ["cloyster", 63, 255, 14, ["ice-beam", "surf", "supersonic", "rain-dance"]], ["piloswine", 63, 255, 8, ["blizzard", "earthquake", "double-edge", "rock-slide"]], ["jynx", 66, 255, 3, ["ice-beam", "psychic", "lovely-kiss", "attract"]], ["lapras", 66, 255, 19, ["ice-beam", "surf", "psychic", "thunder"]]]}, -"TRAINER_ELITE_FOUR_BRUNO_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["steelix", 65, 255, 12, ["earthquake", "iron-tail", "crunch", "rock-tomb"]], ["hitmonchan", 65, 255, 2, ["sky-uppercut", "mach-punch", "rock-slide", "counter"]], ["hitmonlee", 65, 255, 2, ["mega-kick", "foresight", "earthquake", "rock-slide"]], ["steelix", 66, 255, 3, ["earthquake", "iron-tail", "crunch", "dragon-breath"]], ["machamp", 68, 255, 20, ["cross-chop", "earthquake", "brick-break", "rock-slide"]]]}, -"TRAINER_ELITE_FOUR_AGATHA_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["gengar", 66, 255, 18, ["shadow-ball", "psychic", "confuse-ray", "hypnosis"]], ["crobat", 66, 255, 17, ["sludge-bomb", "air-cutter", "shadow-ball", "confuse-ray"]], ["misdreavus", 65, 255, 12, ["shadow-ball", "psychic", "thunderbolt", "attract"]], ["arbok", 68, 255, 23, ["sludge-bomb", "earthquake", "giga-drain", "double-team"]], ["gengar", 70, 255, 5, ["shadow-ball", "psychic", "thunderbolt", "sludge-bomb"]]]}, -"TRAINER_ELITE_FOUR_LANCE_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["gyarados", 68, 255, 19, ["hyper-beam", "dragon-dance", "earthquake", "thunder-wave"]], ["dragonite", 66, 255, 11, ["hyper-beam", "earthquake", "dragon-claw", "flamethrower"]], ["kingdra", 66, 255, 22, ["hyper-beam", "dragon-dance", "surf", "ice-beam"]], ["aerodactyl", 70, 255, 21, ["hyper-beam", "ancient-power", "aerial-ace", "earthquake"]], ["dragonite", 72, 255, 13, ["hyper-beam", "outrage", "thunderbolt", "ice-beam"]]]}, -"TRAINER_CHAMPION_REMATCH_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["heracross", 72, 255, 12, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, 255, 7, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, 255, 3, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["arcanine", 73, 255, 17, ["extreme-speed", "overheat", "aerial-ace", "iron-tail"]], ["exeggutor", 73, 255, 14, ["giga-drain", "psychic", "sleep-powder", "light-screen"]], ["blastoise", 75, 255, 16, ["hydro-pump", "ice-beam", "earthquake", "rain-dance"]]]}, -"TRAINER_CHAMPION_REMATCH_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["heracross", 72, 255, 12, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, 255, 7, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, 255, 3, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["gyarados", 73, 255, 17, ["hydro-pump", "dragon-dance", "earthquake", "hyper-beam"]], ["arcanine", 73, 255, 6, ["extreme-speed", "overheat", "aerial-ace", "iron-tail"]], ["venusaur", 75, 255, 6, ["solar-beam", "sludge-bomb", "earthquake", "sunny-day"]]]}, -"TRAINER_CHAMPION_REMATCH_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["heracross", 72, 255, 12, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, 255, 7, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, 255, 3, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["exeggutor", 73, 255, 0, ["giga-drain", "psychic", "sleep-powder", "light-screen"]], ["gyarados", 73, 255, 14, ["hydro-pump", "dragon-dance", "earthquake", "hyper-beam"]], ["charizard", 75, 255, 7, ["fire-blast", "dragon-claw", "aerial-ace", "earthquake"]]]}, -"TRAINER_CUE_BALL_PAXTON": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 39, 50, 18, ["self-destruct", "sludge", "smokescreen", "haze"]], ["muk", 39, 50, 22, ["sludge", "minimize", "screech", "acid-armor"]]]} -} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp index 1f9db71d35..fda6bae066 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp @@ -5,10 +5,10 @@ */ #include +#include #include #include #include -#include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" @@ -23,39 +23,6 @@ namespace PokemonFRLG{ namespace{ -// The trainer each of the story's battle steps fights, by the map the -// step leaves the player on and the step's name. The rival's teams are -// those against a player who took Squirtle. On a map with more than one -// trainer of a kind, the object's tile and script (pret -// data/maps//map.json, scripts.inc) say which. A row's `risk`, when -// set, overrides its trainer's default_battle_risk(): tune it here. -struct StoryTrainer{ - std::string_view map; - std::string_view battle; - std::string_view trainer; - std::optional risk = std::nullopt; -}; -constexpr StoryTrainer STORY_TRAINERS[] = { - {.map = "PalletTown_ProfessorOaksLab", .battle = "rival_battle", .trainer = "TRAINER_RIVAL_OAKS_LAB_BULBASAUR"}, - {.map = "PewterCity_Gym", .battle = "camper_liam", .trainer = "TRAINER_CAMPER_LIAM"}, - {.map = "PewterCity_Gym", .battle = "brock", .trainer = "TRAINER_LEADER_BROCK"}, - {.map = "Route3", .battle = "bug_catcher_colton", .trainer = "TRAINER_BUG_CATCHER_COLTON"}, - {.map = "Route3", .battle = "bug_catcher_greg", .trainer = "TRAINER_BUG_CATCHER_GREG"}, - {.map = "Route3", .battle = "bug_catcher_james", .trainer = "TRAINER_BUG_CATCHER_JAMES"}, - // Grunt1 at (12, 20), MtMoon_B2F_EventScript_Grunt1. - {.map = "MtMoon_B2F", .battle = "rocket_grunt", .trainer = "TRAINER_TEAM_ROCKET_GRUNT"}, - {.map = "MtMoon_B2F", .battle = "super_nerd_miguel", .trainer = "TRAINER_SUPER_NERD_MIGUEL"}, - {.map = "CeruleanCity", .battle = "rival_cerulean", .trainer = "TRAINER_RIVAL_CERULEAN_BULBASAUR"}, - {.map = "Route24", .battle = "bug_catcher_cale", .trainer = "TRAINER_BUG_CATCHER_CALE"}, - {.map = "Route24", .battle = "lass_ali", .trainer = "TRAINER_LASS_ALI"}, - {.map = "Route24", .battle = "youngster_timmy", .trainer = "TRAINER_YOUNGSTER_TIMMY"}, - {.map = "Route24", .battle = "lass_reli", .trainer = "TRAINER_LASS_RELI"}, - {.map = "Route24", .battle = "camper_ethan", .trainer = "TRAINER_CAMPER_ETHAN"}, - // The Nugget Bridge Rocket, Route24_EventScript_Rocket. - {.map = "Route24", .battle = "rocket_grunt", .trainer = "TRAINER_TEAM_ROCKET_GRUNT_6"}, - {.map = "CeruleanCity_Gym", .battle = "misty", .trainer = "TRAINER_LEADER_MISTY"}, -}; - using JsonTable = std::map>; const JsonValue& file_json(std::string_view name){ @@ -68,7 +35,7 @@ const JsonValue& file_json(std::string_view name){ }(); const auto it = FILES.find(name); if (it == FILES.end()){ - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "BattleData/" + std::string(name) + ".json is not built into the program."); + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("BattleData/{}.json is not built into the program.", name)); } return it->second; } @@ -84,16 +51,14 @@ uint8_t byte_of(const JsonValue& value){ template using Table = std::map>; -// [power, type, pp, accuracy, priority, effect, chance] +// [type, damaging (0 or 1), pp] const Table& moves(){ static const Table MOVES = []{ Table moves; for (const auto& [name, value] : file_json("moves").to_object_throw()){ const JsonArray& entry = value.to_array_throw(); moves.emplace(name, MoveData{ - .power = byte_of(entry[0]), .type = type_of(entry[1]), .pp = byte_of(entry[2]), - .accuracy = byte_of(entry[3]), .priority = static_cast(entry[4].to_integer_throw()), - .effect = entry[5].to_string_throw(), .effect_chance = byte_of(entry[6]), + .type = type_of(entry[0]), .damaging = entry[1].to_integer_throw() != 0, .pp = byte_of(entry[2]), }); } return moves; @@ -101,50 +66,19 @@ const Table& moves(){ return MOVES; } -// [type, type, HP, Attack, Defense, Sp. Atk, Sp. Def, Speed] +// [type, type] const Table& species(){ static const Table SPECIES = []{ Table species; for (const auto& [name, value] : file_json("species").to_object_throw()){ const JsonArray& entry = value.to_array_throw(); - species.emplace(name, SpeciesData{ - .first = type_of(entry[0]), .second = type_of(entry[1]), - .base = BaseStats{ - .hp = byte_of(entry[2]), .attack = byte_of(entry[3]), .defense = byte_of(entry[4]), - .sp_attack = byte_of(entry[5]), .sp_defense = byte_of(entry[6]), .speed = byte_of(entry[7]), - }, - }); + species.emplace(name, SpeciesData{.first = type_of(entry[0]), .second = type_of(entry[1])}); } return species; }(); return SPECIES; } -std::vector strings_of(const JsonValue& value){ - std::vector strings; - for (const JsonValue& item : value.to_array_throw()){ - strings.push_back(item.to_string_throw()); - } - return strings; -} - -// [species, level, iv, nature, [moves]] -TrainerMon trainer_mon(const JsonArray& entry){ - return TrainerMon{ - .species = entry[0].to_string_throw(), .level = byte_of(entry[1]), - .iv = byte_of(entry[2]), .nature = byte_of(entry[3]), .moves = strings_of(entry[4]), - }; -} - -// {"ai": [...], "items": [...], "party": [...]} -TrainerData trainer_entry(const JsonObject& entry){ - TrainerData data{.ai = strings_of(entry.get_value_throw("ai")), .items = strings_of(entry.get_value_throw("items")), .party = {}}; - for (const JsonValue& value : entry.get_value_throw("party").to_array_throw()){ - data.party.push_back(trainer_mon(value.to_array_throw())); - } - return data; -} - bool starts_with_any(std::string_view text, std::initializer_list prefixes){ return std::ranges::any_of(prefixes, [text](std::string_view prefix){ return text.starts_with(prefix); @@ -190,7 +124,7 @@ std::vector read_wild_foes(Logger& logger, Language language, const std::vector foes = wild_foes(species); logger.log(foes.empty() ? "Battle: the wild Pokemon wasn't read; attacks in the plan's order." - : "Battle: a wild " + species + "; attacks are chosen against it." + : std::format("Battle: a wild {}; attacks are chosen against it.", species) ); return foes; } @@ -208,36 +142,6 @@ size_t type_effectiveness(PokemonType attack, PokemonType defend){ return it == CHART.end() ? 10 : it->second; } -bool special_type(PokemonType type){ - switch (type){ - case PokemonType::FIRE: - case PokemonType::WATER: - case PokemonType::GRASS: - case PokemonType::ELECTRIC: - case PokemonType::PSYCHIC: - case PokemonType::ICE: - case PokemonType::DRAGON: - case PokemonType::DARK: - return true; - default: - return false; - } -} - -std::vector trainer_mons(std::string_view trainer){ - std::optional data = trainer_data(trainer); - return data ? std::move(data->party) : std::vector{}; -} - -std::optional trainer_data(std::string_view trainer){ - const JsonObject& trainers = file_json("trainers").to_object_throw(); - const auto it = trainers.find(std::string(trainer)); - if (it == trainers.end()){ - return std::nullopt; - } - return trainer_entry(it->second.to_object_throw()); -} - std::string read_trainer_foe(Logger& logger, Language language, const ImageViewRGB32& screen, const std::vector& party){ if (language == Language::None || party.empty()){ return ""; @@ -247,19 +151,10 @@ std::string read_trainer_foe(Logger& logger, Language language, const ImageViewR if (!species.contains(read)){ read.clear(); } - logger.log(read.empty() ? "Battle: the trainer's Pokemon wasn't read." : "Battle: the trainer's " + read + " is out."); + logger.log(read.empty() ? "Battle: the trainer's Pokemon wasn't read." : std::format("Battle: the trainer's {} is out.", read)); return read; } -std::optional story_trainer(std::string_view map, std::string_view battle){ - for (const StoryTrainer& entry : STORY_TRAINERS){ - if (entry.map == map && entry.battle == battle){ - return entry.trainer; - } - } - return std::nullopt; -} - std::string_view battle_risk_name(BattleRisk risk){ return risk == BattleRisk::HIGH ? "high" : "low"; } @@ -271,15 +166,6 @@ BattleRisk default_battle_risk(std::string_view trainer){ return big ? BattleRisk::HIGH : BattleRisk::LOW; } -BattleRisk story_battle_risk(std::string_view map, std::string_view battle){ - for (const StoryTrainer& entry : STORY_TRAINERS){ - if (entry.map == map && entry.battle == battle){ - return entry.risk ? *entry.risk : default_battle_risk(entry.trainer); - } - } - return BattleRisk::LOW; -} - } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h index 39822363d2..5b67ace4d7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h @@ -2,16 +2,12 @@ * * From: https://github.com/PokemonAutomation/ * - * The game's data the story's attacks are chosen from, generated from - * pret/pokefirered by devtools/maps/frlg_battle_data.py into BattleData/ - * and built into the program: the type chart, every species' types and - * base stats, every move's power, type, PP, accuracy, priority and - * effect, and every trainer's AI flags, items and party. Also which - * trainer each of the story's battle steps fights, and how carefully - * (BattleRisk). + * The game's data the story's attacks are chosen from when the plan has + * none, built into the program from BattleData/: the type chart, each + * species' types, and each move's type, whether it does damage and its + * PP. A battle's foes come from its step in the checkpoint's plan. * - * Names are the program's slugs ("water-gun", "mr-mime"); trainers are - * pret's constants ("TRAINER_SUPER_NERD_MIGUEL"). + * Names are the program's slugs ("water-gun", "mr-mime"). * */ @@ -19,8 +15,6 @@ #define PokemonAutomation_PokemonFRLG_AutoStoryBattleData_H #include -#include -#include #include #include #include @@ -30,8 +24,8 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "CommonFramework/Language.h" -#include "Pokemon/Pokemon_Types.h" -#include "PokemonFRLG_AutoStoryStoryTrainers.h" +#include "PokemonFRLG_AutoStoryBattleRisk.h" +#include "PokemonFRLG_AutoStoryMoveData.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -51,6 +45,11 @@ std::vector wild_foes(std::string_view species); // wild_foes() takes it. Logs what it read. std::vector read_wild_foes(Logger& logger, Language language, const ImageViewRGB32& screen); +// The Pokemon a trainer's battle shows on `screen`, a battle menu: the +// name its HP box shows (WildEncounterReader), among `party`'s species. +// Empty if not read. Logs what it read. +std::string read_trainer_foe(Logger& logger, Language language, const ImageViewRGB32& screen, const std::vector& party); + // (name, JSON text) of each file in BattleData/, sorted by name. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp index 77bbf0a6ca..379d270595 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp @@ -2,7 +2,7 @@ * * From: https://github.com/PokemonAutomation/ * - * The generated battle data, the trainer each story battle fights, and the + * The battle data, the foes each story battle's plan lists, and the * attacks chosen against trainers' parties and wild Pokemon from it. * */ @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" @@ -47,14 +47,14 @@ struct AutoStoryBattleDataTestCase{ class Test_AutoStoryBattleData : public UnitTest{ public: explicit Test_AutoStoryBattleData(AutoStoryBattleDataTestCase scenario) - : UnitTest("PokemonFRLG::AutoStoryBattleData - " + scenario.input.name) + : UnitTest(std::format("PokemonFRLG::AutoStoryBattleData - {}", scenario.input.name)) , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ try{ return m_scenario.input.body(); }catch (Exception& e){ - return std::string(e.name()) + ": " + e.message(); + return std::format("{}: {}", e.name(), e.message()); } } @@ -84,8 +84,8 @@ size_t wild_turn(const PartyMember& lead, std::string_view species){ } -// Spot checks against pret: the type chart, Bite, and species' types and -// stats. +// Spot checks against pret: the type chart, Bite, Growl and species' +// types. UnitTestResult test_data(){ if (type_effectiveness(PokemonType::WATER, PokemonType::FIRE) != 20 || type_effectiveness(PokemonType::DARK, PokemonType::PSYCHIC) != 20 @@ -95,12 +95,16 @@ UnitTestResult test_data(){ return "Expected Water 2x on Fire, Dark 2x on Psychic, Normal 0x on Ghost, Water 1x on Normal."; } const MoveData* bite = move_data("bite"); - if (bite == nullptr || bite->power != 60 || bite->type != PokemonType::DARK || bite->pp != 25 || !special_type(bite->type)){ - return "Expected Bite: 60 power, Dark (special in Gen 3), 25 PP."; + if (bite == nullptr || !bite->damaging || bite->type != PokemonType::DARK || bite->pp != 25){ + return "Expected Bite: damaging, Dark, 25 PP."; + } + const MoveData* growl = move_data("growl"); + if (growl == nullptr || growl->damaging || growl->pp != 40){ + return "Expected Growl: no damage, 40 PP."; } const SpeciesData* starmie = species_data("starmie"); - if (starmie == nullptr || starmie->first != PokemonType::WATER || starmie->second != PokemonType::PSYCHIC || starmie->base.sp_attack != 100){ - return "Expected Starmie: Water, Psychic, base Sp. Atk 100."; + if (starmie == nullptr || starmie->first != PokemonType::WATER || starmie->second != PokemonType::PSYCHIC){ + return "Expected Starmie: Water, Psychic."; } if (battle_species().size() != 386 || species_data("farfetch-d") == nullptr || species_data("missingno") != nullptr){ return std::format("Expected the 386 species by the program's slugs, got {}.", battle_species().size()); @@ -108,7 +112,8 @@ UnitTestResult test_data(){ return true; } -// Every battle step in the table fights a trainer with a party. +// Every battle step in the table names its trainer and that trainer's +// party, each species one the data has. UnitTestResult test_story_trainers(){ size_t battles = 0; for (const StoryCheckpoint& checkpoint : story_checkpoints()){ @@ -117,36 +122,32 @@ UnitTestResult test_story_trainers(){ continue; } battles++; - const std::string map = step.pose_after ? step.pose_after->map : ""; - const std::optional trainer = story_trainer(map, step.name); - if (!trainer){ - return std::format("{}, {} on {}: no trainer.", checkpoint.id, step.name, map); + const std::string& trainer = Pokemon::story_arg(step.args, "trainer"); + const std::vector& foes = Pokemon::story_arg>(step.args, "foes"); + if (trainer.empty() || foes.empty()){ + return std::format("{}, {}: no trainer or no foes.", checkpoint.id, step.name); } - if (trainer_party(*trainer).empty()){ - return std::format("{} on {}: {} has no party.", step.name, map, *trainer); + for (const std::string& foe : foes){ + if (species_data(foe) == nullptr){ + return std::format("{}, {}: unknown foe {}.", checkpoint.id, step.name, foe); + } } } } if (battles == 0){ return "Expected battle steps in the table."; } - if (trainer_party(*story_trainer("CeruleanCity_Gym", "misty")) != std::vector{"staryu", "starmie"}){ - return "Expected Misty's Staryu and Starmie."; - } return true; } // Mt. Moon: Super Nerd Miguel's Grimer (Poison) takes Water Gun, with or -// without Bite known: Bite (60, Dark) ties Water Gun (40 x 1.5 STAB), both -// special, and the tie goes to the plan's Water Gun. +// without Bite known: Water Gun and Bite both hit his party 1x, and the +// tie goes to the plan's Water Gun. UnitTestResult test_miguel_grimer(){ - const std::optional miguel = story_trainer("MtMoon_B2F", "super_nerd_miguel"); - if (!miguel || trainer_party(*miguel) != std::vector{"grimer", "voltorb", "koffing"}){ - return "Expected Miguel's Grimer, Voltorb and Koffing (pret's sParty_SuperNerdMiguel)."; - } + const std::vector miguel{"grimer", "voltorb", "koffing"}; const std::vector leads{grown_to(new_member("squirtle", 5), 17), grown_to(new_member("squirtle", 5), 20)}; for (const PartyMember& lead : leads){ - for (const std::vector& foes : {std::vector{"grimer"}, trainer_party(*miguel)}){ + for (const std::vector& foes : {std::vector{"grimer"}, miguel}){ const std::optional slot = attack_slot_against(lead, foes); if (slot != WATER_GUN){ return std::format("{} against {} foes: expected Water Gun, got slot {}.", lead.species, foes.size(), slot_name(slot)); @@ -156,9 +157,9 @@ UnitTestResult test_miguel_grimer(){ return true; } -// Bite where it does more than Water Gun: on a Psychic or Ghost foe (2x), -// and on one that resists Water, where Bite's 1x beats Water Gun's -// 0.5 x 1.5 STAB. Against a wild Pokemon as read, and a trainer's party. +// Bite where it hits better than Water Gun: on a Psychic or Ghost foe +// (2x), and on one that resists Water, where Bite's 1x beats Water Gun's +// 0.5x. Against a wild Pokemon as read, and a trainer's party. UnitTestResult test_bite_wins(){ const PartyMember wartortle = grown_to(new_member("squirtle", 5), 20); for (std::string_view foe : {"abra", "starmie", "gastly", "staryu", "oddish", "dratini"}){ @@ -173,26 +174,26 @@ UnitTestResult test_bite_wins(){ return std::format("A wild {}: expected Water Gun, got slot {}.", foe, slot); } } - if (attack_slot_against(wartortle, trainer_party(*story_trainer("CeruleanCity_Gym", "misty"))) != BITE){ + if (attack_slot_against(wartortle, {"staryu", "starmie"}) != BITE){ return "Expected Bite against Misty's party."; } return true; } -// The default risks: the rival and gym leaders HIGH, route trainers and -// grunts LOW. +// The default risks: the rival and gym leaders HIGH, route trainers, +// grunts and a battle that names no trainer LOW. UnitTestResult test_risks(){ - const std::vector> cases = { - {"CeruleanCity", "rival_cerulean", BattleRisk::HIGH}, - {"CeruleanCity_Gym", "misty", BattleRisk::HIGH}, - {"PewterCity_Gym", "brock", BattleRisk::HIGH}, - {"Route24", "lass_ali", BattleRisk::LOW}, - {"MtMoon_B2F", "rocket_grunt", BattleRisk::LOW}, - {"Route1", "nobody", BattleRisk::LOW}, + const std::vector> cases = { + {"TRAINER_RIVAL_CERULEAN_BULBASAUR", BattleRisk::HIGH}, + {"TRAINER_LEADER_MISTY", BattleRisk::HIGH}, + {"TRAINER_LEADER_BROCK", BattleRisk::HIGH}, + {"TRAINER_LASS_ALI", BattleRisk::LOW}, + {"TRAINER_TEAM_ROCKET_GRUNT", BattleRisk::LOW}, + {"", BattleRisk::LOW}, }; - for (const auto& [map, battle, risk] : cases){ - if (story_battle_risk(map, battle) != risk){ - return std::format("{} on {}: expected {}.", battle, map, battle_risk_name(risk)); + for (const auto& [trainer, risk] : cases){ + if (default_battle_risk(trainer) != risk){ + return std::format("\"{}\": expected {}.", trainer, battle_risk_name(risk)); } } return true; @@ -220,8 +221,8 @@ const AutoStoryBattleDataTestCase AUTO_STORY_BATTLE_DATA_CASES[] = { .expectation = {.description = "validates decompiled type charts, moves, and species"}, }, { - .input = {.name = "every story battle fights a trainer with a party", .body = test_story_trainers}, - .expectation = {.description = "ensures all scripted story battles encounter valid teams"}, + .input = {.name = "every story battle's plan names a trainer and its party", .body = test_story_trainers}, + .expectation = {.description = "ensures all scripted story battles list known foes"}, }, { .input = {.name = "Miguel's Grimer: Water Gun", .body = test_miguel_grimer}, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp index 4cff39ebe1..5b60553788 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -50,9 +50,9 @@ constexpr int MOVE_PROMPTS = 4; // The HP a Potion heals (pret src/data/items.h). constexpr double POTION_HP = 20; -// A trainer's battle, until the checkpoint carries the simulation's plan: -// the strongest move (attack_slot_against()) against the foe out as read -// at the battle menu, else against the whole party. +// A trainer's battle: the plan's attack, else the best type matchup +// (attack_slot_against()) against the foe out as read at the battle +// menu, else against the whole party its plan lists. std::optional trainer_attack_slot(const PartyMember& usable, const Supplies& supplies){ if (!supplies.foe_out.empty()){ return attack_slot_against(usable, std::vector{supplies.foe_out}); @@ -162,7 +162,7 @@ void BattleDecisions::see_hit(const PartyStatus& status){ } // The plan's attack with PP left, or against known foes (a trainer's -// party, the wild Pokemon read), the one that does them most damage. While the story doesn't know +// party, the wild Pokemon read), the best type matchup. While the story doesn't know // all four moves, the bottom left one (Bubble from Lv7), which the cursor // can't reach while that slot is empty, so before Bubble it stays on // Tackle. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleRisk.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleRisk.h new file mode 100644 index 0000000000..a71b3e6c12 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleRisk.h @@ -0,0 +1,43 @@ +/* AutoStory Battle Risk + * + * From: https://github.com/PokemonAutomation/ + * + * How carefully a story battle is fought, by the trainer its plan names. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattleRisk_H +#define PokemonAutomation_PokemonFRLG_AutoStoryBattleRisk_H + +#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + + +// How carefully a battle step is fought. +enum class BattleRisk{ + // The plan's attacks, else the best type matchup against the foe out. + LOW, + // The battles the simulation's plan is for (the rival, gym leaders, + // bosses); fought as LOW until the checkpoint carries a plan. + HIGH, +}; + +// String representation of battle risk level. +std::string_view battle_risk_name(BattleRisk risk); + +// A trainer's risk by its kind, from pret's constant the battle step's +// plan names ("TRAINER_LEADER_BROCK"): HIGH for the rival, gym leaders, +// bosses (Giovanni, the Rocket admins), the Elite Four and the Champion; +// LOW for the rest and for a battle that names no trainer. +BattleRisk default_battle_risk(std::string_view trainer); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 92f07baf91..294b23ea7b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -169,18 +169,17 @@ Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ } Outcome battle(StoryEnv& env, const StoryStep& step){ - const std::optional trainer = step.pose_after ? story_trainer(step.pose_after->map, step.name) : std::nullopt; - env.supplies.trainer = trainer ? std::string(*trainer) : ""; - env.supplies.risk = trainer ? story_battle_risk(step.pose_after->map, step.name) : BattleRisk::LOW; + env.supplies.trainer = arg(step, "trainer"); + env.supplies.risk = default_battle_risk(env.supplies.trainer); env.supplies.foe_out.clear(); if (advance_text(env.console, env.context, BATTLE_TEXT_TIMEOUT, true) != TextEnd::BATTLE){ return Pokemon::outcome_failed("no_battle"); } - env.supplies.foes = trainer ? trainer_party(*trainer) : std::vector{}; + env.supplies.foes = arg>(step, "foes"); if (!env.supplies.foes.empty()){ env.console.log(std::format( "Story: {} is {}, risk {}; attacks are chosen against the foe out.", - step.name, *trainer, battle_risk_name(env.supplies.risk) + step.name, env.supplies.trainer, battle_risk_name(env.supplies.risk) )); } const BattleEnd end = fight_battle(env.console, env.context, env.supplies, BattleKind::TRAINER, env.checks, env.language); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMoveData.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMoveData.h index a96840949f..e9723e3d4c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMoveData.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMoveData.h @@ -2,8 +2,10 @@ * * From: https://github.com/PokemonAutomation/ * - * Moves, species and the type chart, as pret/pokefirered has them - * (BattleData/moves.json, species.json, type_chart.json). + * What the story needs of moves, species and the type chart to choose an + * attack when the plan has none: each move's type, whether it does damage + * and its PP; each species' types (BattleData/moves.json, species.json, + * type_chart.json, from pret/pokefirered). * */ @@ -12,16 +14,7 @@ #include #include -#include -#include -#include #include -#include -#include -#include "Common/Cpp/Logging/AbstractLogger.h" -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" -#include "CommonFramework/ImageTypes/ImageViewRGB32.h" -#include "CommonFramework/Language.h" #include "Pokemon/Pokemon_Types.h" namespace PokemonAutomation{ @@ -29,55 +22,36 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Type enum imported from Pokemon navigation. + +// The type enum, from the shared Pokemon code. using Pokemon::PokemonType; -// Data attributes of a battle move. +// A move, as far as choosing an attack and tracking PP needs it. struct MoveData{ - // Moves whose damage doesn't come from their power (Flail, Dragon - // Rage) have 1; moves that do no damage 0. - uint8_t power = 0; // NONE for Curse's "???". PokemonType type = PokemonType::NONE; + // It does damage: any power, including moves whose damage doesn't + // come from their power (Flail, Dragon Rage). + bool damaging = false; + // Full PP. uint8_t pp = 0; - // In percent; 0 never misses. - uint8_t accuracy = 0; - int8_t priority = 0; - // pret's EFFECT_X as a slug: "hit", "flinch-hit", "sleep", - // "attack-down", "dragon-rage". - std::string effect = {}; - // The secondary effect's chance in percent (Bite's flinch: 30). - uint8_t effect_chance = 0; -}; - -// The base stats, in the game's order. -struct BaseStats{ - uint8_t hp = 0; - uint8_t attack = 0; - uint8_t defense = 0; - uint8_t sp_attack = 0; - uint8_t sp_defense = 0; - uint8_t speed = 0; }; -// Species battle base attributes and typing. +// A species' types; the same type twice for a species with one. struct SpeciesData{ - // The same type twice for a species with one. PokemonType first = PokemonType::NONE; PokemonType second = PokemonType::NONE; - BaseStats base = {}; }; -// None for a move or species the data doesn't have. + +// None for a move the data doesn't have. const MoveData* move_data(std::string_view move); -// Base stats and typing for species; nullptr if unknown. + +// None for a species the data doesn't have. const SpeciesData* species_data(std::string_view species); + // How well `attack` hits `defend`, in tenths: 20 is 2x, 5 is 0.5x. size_t type_effectiveness(PokemonType attack, PokemonType defend); -// Gen 3 splits physical and special by type: Fire, Water, Grass, -// Electric, Psychic, Ice, Dragon and Dark are special. -bool special_type(PokemonType type); - } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp index 76c639f2a7..204411b5f8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp @@ -6,7 +6,7 @@ #include #include -#include "PokemonFRLG_AutoStoryBattleData.h" +#include "PokemonFRLG_AutoStoryMoveData.h" #include "PokemonFRLG_AutoStoryParty.h" namespace PokemonAutomation{ @@ -193,13 +193,7 @@ void take_level(PartyMember& member, uint8_t level){ member.moves_through_level = level; } -// The base stat `attacker` uses `move` with: Attack or Sp. Atk, by the -// move's type. -uint8_t attacking_stat(const SpeciesData& attacker, const MoveData& move){ - return special_type(move.type) ? attacker.base.sp_attack : attacker.base.attack; -} - -// In tenths. +// How well `move` hits `defender`, in tenths: 40 is 4x, 5 is 0.5x. size_t effectiveness(const MoveData& move, const SpeciesData& defender){ size_t tenths = type_effectiveness(move.type, defender.first); if (defender.second != defender.first){ @@ -208,24 +202,18 @@ size_t effectiveness(const MoveData& move, const SpeciesData& defender){ return tenths; } -// `move`'s expected damage, summed over `foes`: its power times STAB -// times its effectiveness times the lead's base attacking stat for it, -// times its accuracy (a move that never misses as 100%). The foe's -// Defense and Sp. Def, levels, IVs, EVs and natures are left out. Each -// foe must be in species_data(). -size_t expected_damage(const PartyMember& member, std::string_view move, const std::vector& foes){ +// `move`'s type multiplier, in tenths, summed over `foes`; 0 for a move +// that does no damage. Each foe must be in species_data(). +size_t matchup(std::string_view move, const std::vector& foes){ const MoveData* data = move_data(move); - const SpeciesData* own = species_data(member.species); - if (data == nullptr || own == nullptr){ + if (data == nullptr || !data->damaging){ return 0; } - const bool stab = own->first == data->type || own->second == data->type; - const size_t accuracy = data->accuracy == 0 ? 100 : data->accuracy; - size_t damage = 0; + size_t total = 0; for (const std::string& foe : foes){ - damage += (size_t)data->power * (stab ? 15 : 10) * effectiveness(*data, *species_data(foe)) * attacking_stat(*own, *data) * accuracy; + total += effectiveness(*data, *species_data(foe)); } - return damage; + return total; } // The member's slots in the plan's order: its line's attacks first, as @@ -264,9 +252,9 @@ uint8_t max_pp(std::string_view move){ return data == nullptr ? 0 : data->pp; } -uint8_t move_power(std::string_view move){ +bool does_damage(std::string_view move){ const MoveData* data = move_data(move); - return data == nullptr ? 0 : data->power; + return data != nullptr && data->damaging; } PartyMember new_member(std::string_view species, uint8_t level){ @@ -365,16 +353,11 @@ std::optional attack_slot(const PartyMember& member){ return slot; } } - std::optional strongest; for (size_t slot = 0; slot < member.moves.size(); slot++){ - const uint8_t power = move_power(member.moves[slot].move); - if (power > 0 && member.moves[slot].pp > 0 && (!strongest || power > move_power(member.moves[*strongest].move))){ - strongest = slot; + if (does_damage(member.moves[slot].move) && member.moves[slot].pp > 0){ + return slot; } } - if (strongest){ - return strongest; - } for (size_t slot = 0; slot < member.moves.size(); slot++){ if (member.moves[slot].pp > 0){ return slot; @@ -383,14 +366,6 @@ std::optional attack_slot(const PartyMember& member){ return TOP_LEFT_MOVE; } -std::vector trainer_party(std::string_view trainer){ - std::vector party; - for (const TrainerMon& mon : trainer_mons(trainer)){ - party.push_back(mon.species); - } - return party; -} - std::optional attack_slot_against(const PartyMember& member, const std::vector& foes){ const std::optional plan = attack_slot(member); std::vector known; @@ -401,12 +376,12 @@ std::optional attack_slot_against(const PartyMember& member, const std:: return plan; } std::optional best; - size_t best_damage = 0; + size_t best_matchup = 0; for (size_t slot : attack_order(member)){ - const size_t damage = expected_damage(member, member.moves[slot].move, known); - if (member.moves[slot].pp > 0 && damage > best_damage){ + const size_t tenths = matchup(member.moves[slot].move, known); + if (member.moves[slot].pp > 0 && tenths > best_matchup){ best = slot; - best_damage = damage; + best_matchup = tenths; } } return best ? best : plan; @@ -415,7 +390,7 @@ std::optional attack_slot_against(const PartyMember& member, const std:: size_t attack_pp(const PartyMember& member){ size_t pp = 0; for (const KnownMove& known : member.moves){ - if (move_power(known.move) > 0){ + if (does_damage(known.move)){ pp += known.pp; } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h index 95ea011756..9c0a85a982 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h @@ -42,27 +42,16 @@ namespace PokemonFRLG{ // The slot to attack with: the first of the plan's attacks for its line -// that it knows with PP left, else its strongest damaging move with PP -// left, else any move with PP left, else the top left (Struggle). None -// while the story doesn't know all its moves (fewer than four, not read). +// that it knows with PP left, else its first damaging move with PP left, +// else any move with PP left, else the top left (Struggle). None while the +// story doesn't know all its moves (fewer than four, not read). std::optional attack_slot(const PartyMember& member); -// The species of `trainer`'s party, in order: pret's constant -// ("TRAINER_LEADER_MISTY", see story_trainer()), from pret/pokefirered -// src/data/trainer_parties.h. Empty for a trainer the data doesn't have. -std::vector trainer_party(std::string_view trainer); - // The slot to attack `foes` with, any of them as likely to be out: the -// move with PP left that does the most expected damage, ties going to -// attack_slot()'s order. Expected damage, summed over the foes, is power -// times STAB times the type chart times accuracy, times the lead's base -// Attack or Sp. Atk, whichever the move's type uses (Gen 3: Fire, Water, Grass, -// Electric, Psychic, Ice, Dragon and Dark are special): Water Gun and Bite -// compare on Sp. Atk, Tackle on Attack. The foe's defenses are left out, -// so a frail foe's low Defense doesn't pull Tackle ahead of a type -// advantage. A foe the data doesn't -// have is left out; with none left, or while the story doesn't know all -// the lead's moves, attack_slot() itself (the plan's order). +// damaging move with PP left whose type multiplier, summed over the foes, +// is best; ties go to the plan's attacks, then slot order. A foe the data +// doesn't have is left out; with none left, or while the story doesn't +// know all the lead's moves, attack_slot() itself. std::optional attack_slot_against(const PartyMember& member, const std::vector& foes); // The PP left in the damaging moves it knows. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPartyMember.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPartyMember.h index 0751cfcf68..20e9bc5c15 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPartyMember.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPartyMember.h @@ -64,9 +64,8 @@ uint8_t battle_level(const PartyMember& member); // A move's full PP; 0 for a move the table doesn't have. uint8_t max_pp(std::string_view move); -// A move's power; 0 for one that does no damage, or that the table -// doesn't have. -uint8_t move_power(std::string_view move); +// The move does damage; false for one the table doesn't have. +bool does_damage(std::string_view move); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp index 72163a9cfc..cf77964002 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp @@ -331,7 +331,7 @@ UnitTestResult test_moves_from_summary(Logger&){ // Moves read off a summary: all it knows even when fewer than four, a PP // not read taken as half the full PP (the game colors it from half down), -// and the strongest damaging move once the plan's attacks are gone. +// and the first damaging move once the plan's attacks are gone. UnitTestResult test_summary_members(Logger&){ struct Case{ std::string name; @@ -362,7 +362,7 @@ UnitTestResult test_summary_members(Logger&){ {.move = "tail-whip", .pp = 30, .max_pp = 30}, {.move = "rapid-spin", .pp = 40, .max_pp = 40}, {.move = "skull-bash", .pp = 15, .max_pp = 15}, {.move = "withdraw", .pp = 40, .max_pp = 40}, }), - .slot = 2, .pp = 55, + .slot = 1, .pp = 55, }, { .name = "four moves not read, fewer known", @@ -387,8 +387,8 @@ UnitTestResult test_summary_members(Logger&){ // #211: Bite, not Water Gun, against the trainers whose parties resist // Water Gun: the Cerulean rival's Bulbasaur, and Misty's Staryu and // Starmie (Water, Psychic: Bite does twice). Once Bite is out of PP, -// Tackle (35, on Bulbasaur's lower Defense) over the resisted Water Gun -// (40 x 1.5 x 0.5); and the battle loop picks Bite against a known party, +// Tackle (1x) over the resisted Water Gun (0.5x); and the battle loop +// picks Bite against a known party, // but not in a wild battle, which has its own foes (BattleData tests). UnitTestResult test_attack_by_matchup(Logger&){ PartyMember wartortle = grown_to(new_member("squirtle", 5), 20); @@ -396,7 +396,7 @@ UnitTestResult test_attack_by_matchup(Logger&){ const std::optional bite = 1; const std::optional water_gun = BOTTOM_LEFT_MOVE; if (move_names(wartortle) != std::vector{"tackle", "bite", "water-gun", "withdraw"}){ - return "Expected Wartortle Lv20 with Tackle, Bite, Water Gun, Withdraw, got " + joined(move_names(wartortle)) + "."; + return std::format("Expected Wartortle Lv20 with Tackle, Bite, Water Gun, Withdraw, got {}.", joined(move_names(wartortle))); } struct Case{ std::string name; @@ -404,8 +404,8 @@ UnitTestResult test_attack_by_matchup(Logger&){ }; const std::vector cases{ {.name = "the rival's Bulbasaur", .foes = bulbasaur}, - {.name = "the Cerulean rival's party", .foes = trainer_party("TRAINER_RIVAL_CERULEAN_BULBASAUR")}, - {.name = "Misty's party", .foes = trainer_party("TRAINER_LEADER_MISTY")}, + {.name = "the Cerulean rival's party", .foes = {"pidgeotto", "abra", "rattata", "bulbasaur"}}, + {.name = "Misty's party", .foes = {"staryu", "starmie"}}, }; for (const Case& c : cases){ const std::optional slot = attack_slot_against(wartortle, c.foes); @@ -413,11 +413,6 @@ UnitTestResult test_attack_by_matchup(Logger&){ return std::format("{} ({}): expected Bite (slot 1), got slot {}.", c.name, joined(c.foes), slot ? std::to_string(*slot) : "none"); } } - const std::vector rival = trainer_party(story_trainer("CeruleanCity", "rival_cerulean").value_or("")); - if (rival != std::vector{"pidgeotto", "abra", "rattata", "bulbasaur"}){ - return "Expected the Cerulean rival's party from pret's sParty_RivalCeruleanBulbasaur, got " + joined(rival) + "."; - } - PartyMember no_bite = wartortle; no_bite.moves[1].pp = 0; if (attack_slot_against(no_bite, bulbasaur) != TOP_LEFT_MOVE || attack_slot_against(no_bite, {"pidgeotto"}) != water_gun){ @@ -439,17 +434,14 @@ UnitTestResult test_attack_by_matchup(Logger&){ return true; } -// A trainer the data doesn't have, a species it doesn't have, and no foes -// at all get the plan's order: Water Gun first. +// A species the data doesn't have, and no foes at all, get the plan's +// order: Water Gun first. UnitTestResult test_attack_unknown_foe(Logger&){ const PartyMember wartortle = grown_to(new_member("squirtle", 5), 20); - if (!trainer_party("TRAINER_NOBODY").empty() || story_trainer("Route24", "nobody")){ - return "Expected no party for a trainer the data doesn't have."; - } - const std::vector> unknown{{}, {"missingno"}, trainer_party("TRAINER_NOBODY")}; + const std::vector> unknown{{}, {"missingno"}}; for (const std::vector& foes : unknown){ if (attack_slot_against(wartortle, foes) != attack_slot(wartortle) || attack_slot(wartortle) != BOTTOM_LEFT_MOVE){ - return "Expected the plan's order (Water Gun) against " + joined(foes) + "."; + return std::format("Expected the plan's order (Water Gun) against {}.", joined(foes)); } } return true; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp index cfc635dc87..b628fbcb5b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp @@ -56,6 +56,20 @@ std::span story_action_specs(){ static const std::vector SPECS = []{ const std::span builtin = Pokemon::builtin_story_actions(); std::vector specs(builtin.begin(), builtin.end()); + // A trainer battle's plan names the trainer and its party. + for (Pokemon::StoryActionSpec& spec : specs){ + if (spec.kind != StoryStepKind::BATTLE){ + continue; + } + spec.args.push_back(Pokemon::StoryArgSpec{ + .key = "trainer", .type = Pokemon::StoryArgType::WORD, .required = false, .fallback = std::string(), + .why = "pret's constant for the trainer (\"TRAINER_LEADER_BROCK\"); sets the battle's risk", + }); + spec.args.push_back(Pokemon::StoryArgSpec{ + .key = "foes", .type = Pokemon::StoryArgType::WORDS, .required = false, .fallback = std::vector(), + .why = "the trainer's party in order; attacks are chosen against the one out", + }); + } for (StoryStepKind kind : {StoryStepKind::ROUTE, StoryStepKind::LEGS}){ Pokemon::StoryActionSpec run = *Pokemon::find_story_action(builtin, kind, ""); run.name = "run"; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStoryTrainers.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStoryTrainers.h deleted file mode 100644 index ec7f9be1cb..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStoryTrainers.h +++ /dev/null @@ -1,62 +0,0 @@ -/* AutoStory Story Trainers - * - * From: https://github.com/PokemonAutomation/ - * - * Which trainer each of the story's battle steps fights, and how - * carefully (BattleRisk). - * - */ - -#ifndef PokemonAutomation_PokemonFRLG_AutoStoryStoryTrainers_H -#define PokemonAutomation_PokemonFRLG_AutoStoryStoryTrainers_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include "Common/Cpp/Logging/AbstractLogger.h" -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" -#include "CommonFramework/ImageTypes/ImageViewRGB32.h" -#include "CommonFramework/Language.h" -#include "Pokemon/Pokemon_Types.h" -#include "PokemonFRLG_AutoStoryTrainerData.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -// The trainer the story's battle step `battle` fights on `map` (the map -// it leaves the player on). None for a battle the table doesn't name. -std::optional story_trainer(std::string_view map, std::string_view battle); - -// How carefully a battle step is fought. -enum class BattleRisk{ - // The move with the best expected damage against the foe out. - LOW, - // The battles the simulation's plan is for (the rival, gym leaders, - // bosses); fought as LOW until the checkpoint carries a plan. - HIGH, -}; -// String representation of battle risk level. -std::string_view battle_risk_name(BattleRisk risk); - -// A trainer's risk by its kind: HIGH for the rival, gym leaders, bosses -// (Giovanni, the Rocket admins), the Elite Four and the Champion; LOW -// for the rest. -BattleRisk default_battle_risk(std::string_view trainer); - -// The risk of the story's battle step `battle` on `map`: its table row's, -// else its trainer's default. LOW for a battle the table doesn't name. -BattleRisk story_battle_risk(std::string_view map, std::string_view battle); - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h index 47b38ae261..b02d288b9a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h @@ -68,14 +68,14 @@ struct Supplies{ // faints, so they gain no EXP and learn or evolve nothing: a member // kept for later, or one the user keeps for a trade. std::vector protected_slots = {}; - // The party of the trainer the table's battle step fights, when the - // story knows it (trainer_party()): the lead's attacks are chosen - // against it while the one out isn't known. Empty otherwise; wild - // battles never use it. + // The party of the trainer the battle step fights, as its plan lists + // it (the step's "foes"): the lead's attacks are chosen against it + // while the one out isn't known. Empty otherwise; wild battles never + // use it. std::vector foes = {}; - // That trainer (story_trainer()), "" otherwise. + // That trainer, as its plan names it (the step's "trainer"), "" otherwise. std::string trainer = {}; - // How carefully that battle is fought (story_battle_risk()). + // How carefully that battle is fought (default_battle_risk()). BattleRisk risk = BattleRisk::LOW; // The species of the trainer's Pokemon out, as read at the last battle // menu (read_trainer_foe()), "" if not read: the lead's attacks are diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerData.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerData.h deleted file mode 100644 index 4e3d57bffa..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerData.h +++ /dev/null @@ -1,70 +0,0 @@ -/* AutoStory Trainer Data - * - * From: https://github.com/PokemonAutomation/ - * - * Trainers' parties, items and AI flags as pret/pokefirered has them - * (BattleData/trainers.json), and the trainer's Pokemon out as read. - * - */ - -#ifndef PokemonAutomation_PokemonFRLG_AutoStoryTrainerData_H -#define PokemonAutomation_PokemonFRLG_AutoStoryTrainerData_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include "Common/Cpp/Logging/AbstractLogger.h" -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" -#include "CommonFramework/ImageTypes/ImageViewRGB32.h" -#include "CommonFramework/Language.h" -#include "Pokemon/Pokemon_Types.h" -#include "PokemonFRLG_AutoStoryMoveData.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -// A trainer party Pokemon entry. -struct TrainerMon{ - std::string species; - uint8_t level = 0; - // pret's iv, 0 to 255: every IV is iv * 31 / 255 (CreateNPCTrainerParty). - uint8_t iv = 0; - // The nature's index (0 Hardy, 1 Lonely, ... 24 Quirky): the one the - // game's personality gives it (see frlg_battle_data.py). - uint8_t nature = 0; - // The moves the party gives it, else the level-up moves the game gives. - std::vector moves; -}; - -// Trainer AI flags and team definition. -struct TrainerData{ - // pret's AI flags as slugs: "check-bad-move", "try-to-faint", ... - std::vector ai = {}; - // The items the trainer can use, in order, each once ("super-potion"). - std::vector items = {}; - std::vector party = {}; -}; -// A trainer's party in order; empty for a trainer the data doesn't have. -std::vector trainer_mons(std::string_view trainer); - -// A trainer's AI flags, items and party; none for one the data doesn't have. -std::optional trainer_data(std::string_view trainer); - -// The Pokemon a trainer's battle shows on `screen`, a battle menu: the -// name its HP box shows (WildEncounterReader), among `party`'s species. -// Empty if not read. Logs what it read. -std::string read_trainer_foe(Logger& logger, Language language, const ImageViewRGB32& screen, const std::vector& party); - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 60d71e3ac5..30463c0eda 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -21,6 +21,7 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" namespace PokemonAutomation{ @@ -482,8 +483,12 @@ UnitTestResult test_save_dialog(){ } UnitTestResult test_lint(){ + // FRLG's own action args (a battle's trainer and foes), with no console. + const Pokemon::StoryActionTable table = make_story_action_table([](StoryActionId){ + return Pokemon::StoryAction{}; + }); for (const StoryCheckpoint& checkpoint : story_checkpoints()){ - const std::vector problems = Pokemon::lint_story_checkpoint(checkpoint); + const std::vector problems = Pokemon::lint_story_checkpoint(checkpoint, table); if (!problems.empty()){ return problems[0]; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json index 54ca333a84..db5ea566e7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json @@ -58,7 +58,9 @@ "id": "rival_battle", "kind": "battle", "args": { - "may_lose": true + "may_lose": true, + "trainer": "TRAINER_RIVAL_OAKS_LAB_BULBASAUR", + "foes": ["bulbasaur"] }, "declared_after": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[7, 8]], "facing": "south"}, "why": "the tutorial battle; losing goes on too" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json index c756fe3bec..103deb8066 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json @@ -25,6 +25,10 @@ { "id": "camper_liam", "kind": "battle", + "args": { + "trainer": "TRAINER_CAMPER_LIAM", + "foes": ["geodude", "sandshrew"] + }, "declared_after": {"map": "PewterCity_Gym", "tiles": [[6, 8]], "facing": "north"}, "why": "Geodude and Sandshrew; EXP before Brock" }, @@ -52,6 +56,10 @@ { "id": "brock", "kind": "battle", + "args": { + "trainer": "TRAINER_LEADER_BROCK", + "foes": ["geodude", "onix"] + }, "declared_after": {"map": "PewterCity_Gym", "tiles": [[6, 6]], "facing": "north"}, "why": "Geodude and Onix, with Bubble; Boulder Badge and TM39" } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index d9f72f295d..c5a6ee9dbe 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1938,6 +1938,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleRisk.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCheckpoints.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -1959,7 +1960,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameCompare.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameStore.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartMenu.h - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStoryTrainers.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp @@ -2002,7 +2002,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerData.h Source/VideoGames/PokemonFRLG/Programs/PokemonFRLG_BattleMenuNavigation.cpp Source/VideoGames/PokemonFRLG/Programs/PokemonFRLG_BattleMenuNavigation.h Source/VideoGames/PokemonFRLG/Programs/PokemonFRLG_SafariOptimalAction.cpp diff --git a/devtools/maps/RESOURCE_MAPS.md b/devtools/maps/RESOURCE_MAPS.md index 7d314b00e4..0628e74586 100644 --- a/devtools/maps/RESOURCE_MAPS.md +++ b/devtools/maps/RESOURCE_MAPS.md @@ -33,10 +33,11 @@ modified, extra or unapproved resource data fails before compilation. The pack includes pinned license/provenance. Generated resources and external caches are ignored; the resource lock is checked in. -The duplicate FRLG builder and Python tests are removed. `frlg_battle_data.py` -is a thin CLI forwarder to `pokesim.games.frlg.battle_data_export`; set -`PYTHONPATH=/src` when running it. All five existing battle-data -outputs reproduced byte-for-byte after the move. Map-builder tests already live +The duplicate FRLG builder and Python tests are removed. The battle data in +`Programs/AutoStory/BattleData` is cut to what the program reads (each species' +types, each move's type, whether it does damage and its PP, and the type +chart) and has no generator here; a battle's foes come from its step in the +checkpoint's plan. Map-builder tests already live beside their source in PokemonSimulation. Native game tests remain here. The shared Sinnoh decomp CLI remains a separate consumer migration. diff --git a/devtools/maps/frlg_battle_data.py b/devtools/maps/frlg_battle_data.py deleted file mode 100644 index b46a637431..0000000000 --- a/devtools/maps/frlg_battle_data.py +++ /dev/null @@ -1,15 +0,0 @@ -"""Forward native battle-data generation to the pinned PokemonSimulation tools. - -Example: - PYTHONPATH=/path/to/pokesim/src python3 devtools/maps/frlg_battle_data.py \ - --out SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData --check - -The implementation and FireRed source pin belong to PokemonSimulation. Use the -same tools checkout documented in RESOURCE_MAPS.md; no map-builder copy is needed. -""" - -from pokesim.games.frlg.battle_data_export import main - - -if __name__ == '__main__': - main()