Read MAX_ENCOUNTER_RATE from project

This commit is contained in:
GriffinR 2024-08-27 16:14:02 -04:00
parent a7272191f4
commit 0e9dacd159
6 changed files with 44 additions and 22 deletions

View file

@ -67,6 +67,7 @@ The filepath that Porymap expects for each file can be overridden on the ``Files
include/fieldmap.h, yes, no, ``constants_fieldmap``, reads tileset related constants include/fieldmap.h, yes, no, ``constants_fieldmap``, reads tileset related constants
src/fieldmap.c, yes, no, ``fieldmap``, reads ``symbol_attribute_table`` src/fieldmap.c, yes, no, ``fieldmap``, reads ``symbol_attribute_table``
src/event_object_movement.c, yes, no, ``initial_facing_table``, reads ``symbol_facing_directions`` src/event_object_movement.c, yes, no, ``initial_facing_table``, reads ``symbol_facing_directions``
src/wild_encounter.c, yes, no, ``wild_encounter``, reads ``define_max_encounter_rate``
src/pokemon_icon.c, yes, no, ``pokemon_icon_table``, reads files in ``symbol_pokemon_icon_table`` src/pokemon_icon.c, yes, no, ``pokemon_icon_table``, reads files in ``symbol_pokemon_icon_table``
graphics/pokemon/\*/icon.png, yes, no, ``pokemon_gfx``, to search for Pokémon icons if they aren't found in ``symbol_pokemon_icon_table`` graphics/pokemon/\*/icon.png, yes, no, ``pokemon_gfx``, to search for Pokémon icons if they aren't found in ``symbol_pokemon_icon_table``
@ -96,6 +97,7 @@ In addition to these files, there are some specific symbol and macro names that
``define_obj_event_count``, ``OBJECT_EVENT_TEMPLATES_COUNT``, to limit total Object Events ``define_obj_event_count``, ``OBJECT_EVENT_TEMPLATES_COUNT``, to limit total Object Events
``define_min_level``, ``MIN_LEVEL``, minimum wild encounters level ``define_min_level``, ``MIN_LEVEL``, minimum wild encounters level
``define_max_level``, ``MAX_LEVEL``, maximum wild encounters level ``define_max_level``, ``MAX_LEVEL``, maximum wild encounters level
``define_max_encounter_rate``, ``MAX_ENCOUNTER_RATE``, this value / 16 will be the maximum encounter rate on the ``Wild Pokémon`` tab
``define_tiles_primary``, ``NUM_TILES_IN_PRIMARY``, ``define_tiles_primary``, ``NUM_TILES_IN_PRIMARY``,
``define_tiles_total``, ``NUM_TILES_TOTAL``, ``define_tiles_total``, ``NUM_TILES_TOTAL``,
``define_metatiles_primary``, ``NUM_METATILES_IN_PRIMARY``, total metatiles are calculated using metatile ID mask ``define_metatiles_primary``, ``NUM_METATILES_IN_PRIMARY``, total metatiles are calculated using metatile ID mask

View file

@ -194,6 +194,7 @@ enum ProjectIdentifier {
define_obj_event_count, define_obj_event_count,
define_min_level, define_min_level,
define_max_level, define_max_level,
define_max_encounter_rate,
define_tiles_primary, define_tiles_primary,
define_tiles_total, define_tiles_total,
define_metatiles_primary, define_metatiles_primary,
@ -281,6 +282,7 @@ enum ProjectFilePath {
global_fieldmap, global_fieldmap,
fieldmap, fieldmap,
initial_facing_table, initial_facing_table,
wild_encounter,
pokemon_icon_table, pokemon_icon_table,
pokemon_gfx, pokemon_gfx,
}; };

View file

@ -39,7 +39,6 @@ public:
QMap<QString, int> mapGroups; QMap<QString, int> mapGroups;
QList<QStringList> groupedMapNames; QList<QStringList> groupedMapNames;
QStringList mapNames; QStringList mapNames;
QMap<QString, QVariant> miscConstants;
QList<HealLocation> healLocations; QList<HealLocation> healLocations;
QMap<QString, int> healLocationNameToValue; QMap<QString, int> healLocationNameToValue;
QMap<QString, QString> mapConstantsToMapNames; QMap<QString, QString> mapConstantsToMapNames;
@ -79,6 +78,9 @@ public:
bool usingAsmTilesets; bool usingAsmTilesets;
QString importExportPath; QString importExportPath;
QSet<QString> disabledSettingsNames; QSet<QString> disabledSettingsNames;
int pokemonMinLevel;
int pokemonMaxLevel;
int maxEncounterRate;
bool wildEncountersLoaded; bool wildEncountersLoaded;
void set_root(QString); void set_root(QString);

View file

@ -85,6 +85,7 @@ const QMap<ProjectIdentifier, QPair<QString, QString>> ProjectConfig::defaultIde
{ProjectIdentifier::define_obj_event_count, {"define_obj_event_count", "OBJECT_EVENT_TEMPLATES_COUNT"}}, {ProjectIdentifier::define_obj_event_count, {"define_obj_event_count", "OBJECT_EVENT_TEMPLATES_COUNT"}},
{ProjectIdentifier::define_min_level, {"define_min_level", "MIN_LEVEL"}}, {ProjectIdentifier::define_min_level, {"define_min_level", "MIN_LEVEL"}},
{ProjectIdentifier::define_max_level, {"define_max_level", "MAX_LEVEL"}}, {ProjectIdentifier::define_max_level, {"define_max_level", "MAX_LEVEL"}},
{ProjectIdentifier::define_max_encounter_rate, {"define_max_encounter_rate", "MAX_ENCOUNTER_RATE"}},
{ProjectIdentifier::define_tiles_primary, {"define_tiles_primary", "NUM_TILES_IN_PRIMARY"}}, {ProjectIdentifier::define_tiles_primary, {"define_tiles_primary", "NUM_TILES_IN_PRIMARY"}},
{ProjectIdentifier::define_tiles_total, {"define_tiles_total", "NUM_TILES_TOTAL"}}, {ProjectIdentifier::define_tiles_total, {"define_tiles_total", "NUM_TILES_TOTAL"}},
{ProjectIdentifier::define_metatiles_primary, {"define_metatiles_primary", "NUM_METATILES_IN_PRIMARY"}}, {ProjectIdentifier::define_metatiles_primary, {"define_metatiles_primary", "NUM_METATILES_IN_PRIMARY"}},
@ -174,6 +175,7 @@ const QMap<ProjectFilePath, QPair<QString, QString>> ProjectConfig::defaultPaths
{ProjectFilePath::fieldmap, { "fieldmap", "src/fieldmap.c"}}, {ProjectFilePath::fieldmap, { "fieldmap", "src/fieldmap.c"}},
{ProjectFilePath::pokemon_icon_table, { "pokemon_icon_table", "src/pokemon_icon.c"}}, {ProjectFilePath::pokemon_icon_table, { "pokemon_icon_table", "src/pokemon_icon.c"}},
{ProjectFilePath::initial_facing_table, { "initial_facing_table", "src/event_object_movement.c"}}, {ProjectFilePath::initial_facing_table, { "initial_facing_table", "src/event_object_movement.c"}},
{ProjectFilePath::wild_encounter, { "wild_encounter", "src/wild_encounter.c"}},
{ProjectFilePath::pokemon_gfx, { "pokemon_gfx", "graphics/pokemon/"}}, {ProjectFilePath::pokemon_gfx, { "pokemon_gfx", "graphics/pokemon/"}},
}; };

View file

@ -1654,15 +1654,43 @@ void Project::deleteFile(QString path) {
} }
bool Project::readWildMonData() { bool Project::readWildMonData() {
extraEncounterGroups.clear(); this->extraEncounterGroups.clear();
wildMonFields.clear(); this->wildMonFields.clear();
wildMonData.clear(); this->wildMonData.clear();
encounterGroupLabels.clear(); this->encounterGroupLabels.clear();
this->pokemonMinLevel = 0;
this->pokemonMaxLevel = 100;
this->maxEncounterRate = 2880/16;
this->wildEncountersLoaded = false; this->wildEncountersLoaded = false;
if (!userConfig.useEncounterJson) { if (!userConfig.useEncounterJson) {
return true; return true;
} }
// Read max encounter rate. The games multiply the encounter rate value in the map data by 16, so our input limit is the max/16.
const QString encounterRateFile = projectConfig.getFilePath(ProjectFilePath::wild_encounter);
const QString maxEncounterRateName = projectConfig.getIdentifier(ProjectIdentifier::define_max_encounter_rate);
fileWatcher.addPath(QString("%1/%2").arg(root).arg(encounterRateFile));
auto defines = parser.readCDefinesByName(encounterRateFile, {maxEncounterRateName});
if (defines.contains(maxEncounterRateName))
this->maxEncounterRate = defines.value(maxEncounterRateName)/16;
// Read min/max level
const QString levelRangeFile = projectConfig.getFilePath(ProjectFilePath::constants_pokemon);
const QString minLevelName = projectConfig.getIdentifier(ProjectIdentifier::define_min_level);
const QString maxLevelName = projectConfig.getIdentifier(ProjectIdentifier::define_max_level);
fileWatcher.addPath(QString("%1/%2").arg(root).arg(levelRangeFile));
defines = parser.readCDefinesByName(levelRangeFile, {minLevelName, maxLevelName});
if (defines.contains(minLevelName))
this->pokemonMinLevel = defines.value(minLevelName);
if (defines.contains(maxLevelName))
this->pokemonMaxLevel = defines.value(maxLevelName);
this->pokemonMinLevel = qMin(this->pokemonMinLevel, this->pokemonMaxLevel);
this->pokemonMaxLevel = qMax(this->pokemonMinLevel, this->pokemonMaxLevel);
// Read encounter data
QString wildMonJsonFilepath = QString("%1/%2").arg(root).arg(projectConfig.getFilePath(ProjectFilePath::json_wild_encounters)); QString wildMonJsonFilepath = QString("%1/%2").arg(root).arg(projectConfig.getFilePath(ProjectFilePath::json_wild_encounters));
fileWatcher.addPath(wildMonJsonFilepath); fileWatcher.addPath(wildMonJsonFilepath);
@ -2412,17 +2440,6 @@ bool Project::readObjEventGfxConstants() {
} }
bool Project::readMiscellaneousConstants() { bool Project::readMiscellaneousConstants() {
miscConstants.clear();
if (userConfig.useEncounterJson) {
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_pokemon);
const QString minLevelName = projectConfig.getIdentifier(ProjectIdentifier::define_min_level);
const QString maxLevelName = projectConfig.getIdentifier(ProjectIdentifier::define_max_level);
fileWatcher.addPath(root + "/" + filename);
QMap<QString, int> pokemonDefines = parser.readCDefinesByName(filename, {minLevelName, maxLevelName});
miscConstants.insert("max_level_define", pokemonDefines.value(maxLevelName) > pokemonDefines.value(minLevelName) ? pokemonDefines.value(maxLevelName) : 100);
miscConstants.insert("min_level_define", pokemonDefines.value(minLevelName) < pokemonDefines.value(maxLevelName) ? pokemonDefines.value(minLevelName) : 1);
}
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_global); const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_global);
const QString maxObjectEventsName = projectConfig.getIdentifier(ProjectIdentifier::define_obj_event_count); const QString maxObjectEventsName = projectConfig.getIdentifier(ProjectIdentifier::define_obj_event_count);
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);

View file

@ -75,15 +75,12 @@ QWidget *SpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewIt
int col = index.column(); int col = index.column();
if (col == EncounterTableModel::ColumnType::MinLevel || col == EncounterTableModel::ColumnType::MaxLevel) { if (col == EncounterTableModel::ColumnType::MinLevel || col == EncounterTableModel::ColumnType::MaxLevel) {
editor->setMinimum(this->project->miscConstants.value("min_level_define").toInt()); editor->setMinimum(this->project->pokemonMinLevel);
editor->setMaximum(this->project->miscConstants.value("max_level_define").toInt()); editor->setMaximum(this->project->pokemonMaxLevel);
} }
else if (col == EncounterTableModel::ColumnType::EncounterRate) { else if (col == EncounterTableModel::ColumnType::EncounterRate) {
// The games multiply the encounter rate value provided here by 16, so the input limit is the max/16.
// TODO: Read MAX_ENCOUNTER_RATE?
static const int maxEncounterRate = 2880;
editor->setMinimum(0); editor->setMinimum(0);
editor->setMaximum(maxEncounterRate / 16); editor->setMaximum(this->project->maxEncounterRate);
} }
return editor; return editor;