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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ pa_pokesim_map_directory(BDSP_MAP_DIRECTORY bdsp "${POKESIM_CONSUMER}" "${POKESI
file(RELATIVE_PATH BDSP_MAP_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}" "${BDSP_MAP_DIRECTORY}")
pa_embed_text_files(SerialProgramsLib "${BDSP_MAP_RESOURCES}"
PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h PokemonAutomation::NintendoSwitch::PokemonBDSP bdsp_map_json)
# TODO: Move JSON syntax preflight into pa_embed_text_files so map and story
# resources share it. Keep game/schema/semantic checks in their native tests.
# Catch JSON syntax errors during a lab build, before static table initialization.
# Native tests still validate the schema, game policy and execution semantics.
file(GLOB BDSP_STORY_FILES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/Source/PokemonBDSP/Programs/AutoStory/StoryData/*.json")
foreach(BDSP_STORY_FILE IN LISTS BDSP_STORY_FILES)
file(READ "${BDSP_STORY_FILE}" BDSP_STORY_TEXT)
string(JSON BDSP_STORY_TYPE ERROR_VARIABLE BDSP_STORY_ERROR TYPE "${BDSP_STORY_TEXT}")
if(BDSP_STORY_ERROR OR NOT BDSP_STORY_TYPE STREQUAL "OBJECT")
message(FATAL_ERROR "Invalid authored checkpoint ${BDSP_STORY_FILE}: ${BDSP_STORY_ERROR}")
endif()
endforeach()
pa_embed_text_files(SerialProgramsLib Source/PokemonBDSP/Programs/AutoStory/StoryData
PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.h PokemonAutomation::NintendoSwitch::PokemonBDSP bdsp_checkpoint_json)


# Create binary target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <string>
#include <utility>
#include <vector>
#include "CommonFramework/GlobalAutoPaths.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
Expand Down Expand Up @@ -42,9 +43,14 @@ const PlayerModelIcons& PLAYER_MODEL_ICONS(){


PlayerModelOption::PlayerModelOption()
: StringSelectOption(
: PlayerModelOption(
"<b>Character model:</b><br>The appearance chosen for the player character. "
"Each one is watched through a different eye template.",
"Each one is watched through a different eye template."
)
{}
PlayerModelOption::PlayerModelOption(std::string label)
: StringSelectOption(
std::move(label),
PLAYER_MODEL_ICONS().database,
LockMode::LOCK_WHILE_RUNNING,
"model-1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define PokemonAutomation_PokemonBDSP_PlayerModelOption_H

#include <stdint.h>
#include <string>
#include "CommonTools/Options/StringSelectOption.h"

namespace PokemonAutomation{
Expand All @@ -22,6 +23,8 @@ const uint8_t BDSP_PLAYER_MODEL_COUNT = 8;
class PlayerModelOption : public StringSelectOption{
public:
PlayerModelOption();
// The same choices, under another label.
explicit PlayerModelOption(std::string label);
uint8_t model_number() const{ return (uint8_t)(index() + 1); }
};

Expand Down
220 changes: 220 additions & 0 deletions SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
/* BDSP RNG Filter
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/Logging/Logger.h"
#include "PokemonBDSP_RngFilter.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{

using namespace Pokemon;


const uint8_t BDSP_HEIGHT_MIN = 0;
const uint8_t BDSP_HEIGHT_MAX = 255;


BdspRngFilterRow::BdspRngFilterRow(EditableTableOption& parent_table)

Check warning on line 21 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonBDSP::BdspRngFilterRow::BdspRngFilterRow( EditableTableOption & parent_table): function_lines=35 (advisory above 25, limit 50)
: EditableTableRow(parent_table)
, misc(static_cast<const BdspRngFilterTable&>(parent_table).feature_flags)
, height(
LockMode::UNLOCK_WHILE_RUNNING,
BDSP_HEIGHT_MIN, BDSP_HEIGHT_MAX, BDSP_HEIGHT_MIN, BDSP_HEIGHT_MIN,
BDSP_HEIGHT_MIN, BDSP_HEIGHT_MAX, BDSP_HEIGHT_MAX, BDSP_HEIGHT_MAX
)
, iv_hp(LockMode::UNLOCK_WHILE_RUNNING, 0, 31, 0, 0, 0, 31, 31, 31)
, iv_atk(LockMode::UNLOCK_WHILE_RUNNING, 0, 31, 0, 0, 0, 31, 31, 31)
, iv_def(LockMode::UNLOCK_WHILE_RUNNING, 0, 31, 0, 0, 0, 31, 31, 31)
, iv_spatk(LockMode::UNLOCK_WHILE_RUNNING, 0, 31, 0, 0, 0, 31, 31, 31)
, iv_spdef(LockMode::UNLOCK_WHILE_RUNNING, 0, 31, 0, 0, 0, 31, 31, 31)
, iv_speed(LockMode::UNLOCK_WHILE_RUNNING, 0, 31, 0, 0, 0, 31, 31, 31)
{
if (misc.feature_flags.action){
PA_ADD_OPTION(misc.action);
}
if (misc.feature_flags.shiny){
PA_ADD_OPTION(misc.shiny);
}
if (misc.feature_flags.gender){
PA_ADD_OPTION(misc.gender);
}
if (misc.feature_flags.nature){
PA_ADD_OPTION(misc.nature);
}
PA_ADD_OPTION(height);
PA_ADD_OPTION(iv_hp);
PA_ADD_OPTION(iv_atk);
PA_ADD_OPTION(iv_def);
PA_ADD_OPTION(iv_spatk);
PA_ADD_OPTION(iv_spdef);
PA_ADD_OPTION(iv_speed);
}
std::unique_ptr<EditableTableRow> BdspRngFilterRow::clone() const{
std::unique_ptr<BdspRngFilterRow> ret(new BdspRngFilterRow(parent()));

Check failure on line 57 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

style: no new/delete outside allocators; use std::make_unique / std::make_shared (TotW #126)
ret->misc.set(misc);
ret->height.set(height);
ret->iv_hp.set(iv_hp);
ret->iv_atk.set(iv_atk);
ret->iv_def.set(iv_def);
ret->iv_spatk.set(iv_spatk);
ret->iv_spdef.set(iv_spdef);
ret->iv_speed.set(iv_speed);
return ret;
}
bool BdspRngFilterRow::match_iv(
const IntegerRangeCell<uint8_t>& desired, const IvRange& actual
){
uint8_t lo, hi;
desired.current_values(lo, hi);
if (lo == 0 && hi == 31){
return true;
}
if (actual.high < (int8_t)lo){
return false;
}
if ((int8_t)hi < actual.low){
return false;
}
return true;
}
bool BdspRngFilterRow::matches(

Check warning on line 84 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonBDSP::BdspRngFilterRow::matches( bool shiny , StatsHuntGenderFilter gender , NatureCheckerValue nature , uint8_t height , const IvRanges & ivs) const: function_lines=38 (advisory above 25, limit 50)
bool shiny,
StatsHuntGenderFilter gender,
NatureCheckerValue nature,
uint8_t height,
const IvRanges& ivs
) const{
if (!misc.matches(shiny, gender, nature)){
return false;
}

uint8_t height_lo, height_hi;
this->height.current_values(height_lo, height_hi);
if (height < height_lo || height_hi < height){
return false;
}

if (!match_iv(iv_hp, ivs.hp)){
return false;
}
if (!match_iv(iv_atk, ivs.attack)){
return false;
}
if (!match_iv(iv_def, ivs.defense)){
return false;
}
if (!match_iv(iv_spatk, ivs.spatk)){
return false;
}
if (!match_iv(iv_spdef, ivs.spdef)){
return false;
}
if (!match_iv(iv_speed, ivs.speed)){
return false;
}

return true;
}


BdspRngFilterTable::BdspRngFilterTable(
const std::string& label,
const StatsHuntMiscFeatureFlags& p_feature_flags
)
: EditableTableOption_t<BdspRngFilterRow>(label, LockMode::UNLOCK_WHILE_RUNNING)
, feature_flags(p_feature_flags)
{}
std::vector<std::string> BdspRngFilterTable::make_header() const{

Check warning on line 131 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonBDSP::BdspRngFilterTable::make_header() const: function_lines=26 (advisory above 25, limit 50)
std::vector<std::string> ret;
if (feature_flags.action){
ret.emplace_back("Action");
}
if (feature_flags.shiny){
ret.emplace_back("Shininess");
}
if (feature_flags.gender){
ret.emplace_back("Gender");
}
if (feature_flags.nature){
ret.emplace_back("Nature");
}

ret.emplace_back("Height");

ret.emplace_back("HP");
ret.emplace_back("Atk");
ret.emplace_back("Def");
ret.emplace_back("SpAtk");
ret.emplace_back("SpDef");
ret.emplace_back("Spd");

return ret;
}
BdspRngFilterSnapshot BdspRngFilterTable::make_snapshot() const{
return BdspRngFilterSnapshot(copy_snapshot());
}
void set_default_shiny_row(BdspRngFilterTable& table){
std::vector<std::unique_ptr<EditableTableRow>> defaults;
auto row = std::make_unique<BdspRngFilterRow>(table);
row->misc.shiny.set(StatsHuntShinyFilter::Shiny);
defaults.emplace_back(std::move(row));
table.set_default(std::move(defaults));
table.restore_defaults();
}
StatsHuntAction BdspRngFilterTable::get_action(
bool shiny,
StatsHuntGenderFilter gender,
NatureCheckerValue nature,
uint8_t height,
const IvRanges& ivs
) const{
return make_snapshot().get_action(shiny, gender, nature, height, ivs);
}


BdspRngFilterSnapshot::BdspRngFilterSnapshot(std::vector<std::unique_ptr<BdspRngFilterRow>> rows)
: m_rows(std::move(rows))
{}
StatsHuntAction BdspRngFilterSnapshot::get_action(

Check warning on line 182 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonBDSP::BdspRngFilterSnapshot::get_action( bool shiny , StatsHuntGenderFilter gender , NatureCheckerValue nature , uint8_t height , const IvRanges & ivs) const: function_lines=34 (advisory above 25, limit 50)
bool shiny,
StatsHuntGenderFilter gender,
NatureCheckerValue nature,
uint8_t height,
const IvRanges& ivs
) const{
StatsHuntAction action = StatsHuntAction::Discard;
for (size_t c = 0; c < m_rows.size(); c++){
const BdspRngFilterRow& filter = *m_rows[c];

if (!filter.matches(shiny, gender, nature, height, ivs)){
continue;
}

StatsHuntAction filter_action = filter.misc.action;

// No action matched so far. Take the current action and continue.
if (action == StatsHuntAction::Discard){
action = filter_action;
continue;
}

// Conflicting actions.
if (action != filter_action){
global_logger_tagged().log(
"Multiple filters matched with conflicting actions. Stopping program...",
COLOR_RED
);
return StatsHuntAction::StopProgram;
}
}
return action;
}


}

Check failure on line 218 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace PokemonBDSP
}

Check failure on line 219 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace NintendoSwitch
}

Check failure on line 220 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace PokemonAutomation
106 changes: 106 additions & 0 deletions SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* BDSP RNG Filter
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonBDSP_RngFilter_H
#define PokemonAutomation_PokemonBDSP_RngFilter_H

#include <stdint.h>
#include <string>
#include <vector>
#include "Common/Cpp/Options/EditableTableOption.h"
#include "Common/Cpp/Options/IntegerRangeOption.h"
#include "Pokemon/Pokemon_NatureChecker.h"
#include "Pokemon/Pokemon_StatsCalculation.h"
#include "Pokemon/Options/Pokemon_StatsHuntFilter.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{


class BdspRngFilterTable;

Check failure on line 24 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

header-comment: document each namespace-scope header symbol
class BdspRngFilterRow : public EditableTableRow{

Check failure on line 25 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

header-comment: document each namespace-scope header symbol
public:
BdspRngFilterRow(EditableTableOption& parent_table);
virtual std::unique_ptr<EditableTableRow> clone() const override;

bool matches(
bool shiny,
Pokemon::StatsHuntGenderFilter gender,
Pokemon::NatureCheckerValue nature,
uint8_t height,
const Pokemon::IvRanges& ivs
) const;

private:
static bool match_iv(const IntegerRangeCell<uint8_t>& desired, const Pokemon::IvRange& actual);

public:
Pokemon::StatsHuntRowMisc misc;

IntegerRangeCell<uint8_t> height;

IntegerRangeCell<uint8_t> iv_hp;
IntegerRangeCell<uint8_t> iv_atk;
IntegerRangeCell<uint8_t> iv_def;
IntegerRangeCell<uint8_t> iv_spatk;
IntegerRangeCell<uint8_t> iv_spdef;
IntegerRangeCell<uint8_t> iv_speed;
};


// The table copied once. Calling get_action() on the table itself clones every row on
// every call, which is far too slow for a scan running over millions of advances.
class BdspRngFilterSnapshot{
public:
explicit BdspRngFilterSnapshot(std::vector<std::unique_ptr<BdspRngFilterRow>> rows);

Pokemon::StatsHuntAction get_action(
bool shiny,
Pokemon::StatsHuntGenderFilter gender,
Pokemon::NatureCheckerValue nature,
uint8_t height,
const Pokemon::IvRanges& ivs
) const;

private:
std::vector<std::unique_ptr<BdspRngFilterRow>> m_rows;
};


class BdspRngFilterTable : public EditableTableOption_t<BdspRngFilterRow>{

Check failure on line 74 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

header-comment: document each namespace-scope header symbol
public:
BdspRngFilterTable(
const std::string& label,
const Pokemon::StatsHuntMiscFeatureFlags& p_feature_flags
);
virtual std::vector<std::string> make_header() const override;

BdspRngFilterSnapshot make_snapshot() const;

Pokemon::StatsHuntAction get_action(
bool shiny,
Pokemon::StatsHuntGenderFilter gender,
Pokemon::NatureCheckerValue nature,
uint8_t height,
const Pokemon::IvRanges& ivs
) const;

public:
const Pokemon::StatsHuntMiscFeatureFlags feature_flags;
};


// Makes the table's default, and its current content, one row: a shiny of
// any nature, gender and IVs. An empty table matches nothing, so a program
// that stops on a match must seed its table with this.
void set_default_shiny_row(BdspRngFilterTable& table);


}

Check failure on line 103 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace PokemonBDSP
}

Check failure on line 104 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace NintendoSwitch
}

Check failure on line 105 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace PokemonAutomation
#endif
Loading
Loading