Set reasonable defaults for wild encounter rates
This commit is contained in:
parent
6a8d3a8197
commit
945201026e
3 changed files with 28 additions and 2 deletions
|
@ -29,6 +29,7 @@ struct EncounterField {
|
||||||
|
|
||||||
typedef QVector<EncounterField> EncounterFields;
|
typedef QVector<EncounterField> EncounterFields;
|
||||||
|
|
||||||
|
void setDefaultEncounterRate(QString fieldName, int rate);
|
||||||
WildMonInfo getDefaultMonInfo(EncounterField field);
|
WildMonInfo getDefaultMonInfo(EncounterField field);
|
||||||
void combineEncounters(WildMonInfo &to, WildMonInfo from);
|
void combineEncounters(WildMonInfo &to, WildMonInfo from);
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
#include "wildmoninfo.h"
|
#include "wildmoninfo.h"
|
||||||
#include "montabwidget.h"
|
#include "montabwidget.h"
|
||||||
|
|
||||||
|
QMap<QString, int> defaultEncounterRates;
|
||||||
|
void setDefaultEncounterRate(QString fieldName, int rate) {
|
||||||
|
defaultEncounterRates[fieldName] = rate;
|
||||||
|
}
|
||||||
|
|
||||||
WildMonInfo getDefaultMonInfo(EncounterField field) {
|
WildMonInfo getDefaultMonInfo(EncounterField field) {
|
||||||
WildMonInfo newInfo;
|
WildMonInfo newInfo;
|
||||||
newInfo.active = true;
|
newInfo.active = true;
|
||||||
newInfo.encounterRate = 0;
|
newInfo.encounterRate = defaultEncounterRates.value(field.name, 1);
|
||||||
|
|
||||||
int size = field.encounterRates.size();
|
int size = field.encounterRates.size();
|
||||||
while (size--)
|
while (size--)
|
||||||
|
|
|
@ -1625,6 +1625,10 @@ bool Project::readWildMonData() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For each encounter type, count the number of times each encounter rate value occurs.
|
||||||
|
// The most common value will be used as the default for new groups.
|
||||||
|
QMap<QString, QMap<int, int>> encounterRateFrequencyMaps;
|
||||||
|
|
||||||
for (OrderedJson subObjectRef : wildMonObj["wild_encounter_groups"].array_items()) {
|
for (OrderedJson subObjectRef : wildMonObj["wild_encounter_groups"].array_items()) {
|
||||||
OrderedJson::object subObject = subObjectRef.object_items();
|
OrderedJson::object subObject = subObjectRef.object_items();
|
||||||
if (!subObject["for_maps"].bool_value()) {
|
if (!subObject["for_maps"].bool_value()) {
|
||||||
|
@ -1650,6 +1654,7 @@ bool Project::readWildMonData() {
|
||||||
encounterField.groups[group].append(slotNum.int_value());
|
encounterField.groups[group].append(slotNum.int_value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
encounterRateFrequencyMaps.insert(encounterField.name, QMap<int, int>());
|
||||||
wildMonFields.append(encounterField);
|
wildMonFields.append(encounterField);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1666,6 +1671,7 @@ bool Project::readWildMonData() {
|
||||||
OrderedJson::object encounterFieldObj = encounterObj[field].object_items();
|
OrderedJson::object encounterFieldObj = encounterObj[field].object_items();
|
||||||
header.wildMons[field].active = true;
|
header.wildMons[field].active = true;
|
||||||
header.wildMons[field].encounterRate = encounterFieldObj["encounter_rate"].int_value();
|
header.wildMons[field].encounterRate = encounterFieldObj["encounter_rate"].int_value();
|
||||||
|
encounterRateFrequencyMaps[field][header.wildMons[field].encounterRate]++;
|
||||||
for (auto mon : encounterFieldObj["mons"].array_items()) {
|
for (auto mon : encounterFieldObj["mons"].array_items()) {
|
||||||
WildPokemon newMon;
|
WildPokemon newMon;
|
||||||
OrderedJson::object monObj = mon.object_items();
|
OrderedJson::object monObj = mon.object_items();
|
||||||
|
@ -1686,6 +1692,22 @@ bool Project::readWildMonData() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For each encounter type, set default encounter rate to most common value.
|
||||||
|
// Iterate over map of encounter type names to frequency maps...
|
||||||
|
for (auto i = encounterRateFrequencyMaps.cbegin(), i_end = encounterRateFrequencyMaps.cend(); i != i_end; i++) {
|
||||||
|
int frequency = 0;
|
||||||
|
int rate = 1;
|
||||||
|
const QMap<int, int> frequencyMap = i.value();
|
||||||
|
// Iterate over frequency map (encounter rate to number of occurrences)...
|
||||||
|
for (auto j = frequencyMap.cbegin(), j_end = frequencyMap.cend(); j != j_end; j++) {
|
||||||
|
if (j.value() > frequency) {
|
||||||
|
frequency = j.value();
|
||||||
|
rate = j.key();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setDefaultEncounterRate(i.key(), rate);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue