seedwatch: rewrite configuration cleaning

develop
Kelly Kinkade 2023-08-30 00:07:30 -05:00
parent fa9d2e2175
commit c5d30763b9
1 changed files with 15 additions and 5 deletions

@ -96,6 +96,20 @@ static void remove_seed_config(color_ostream &out, int id) {
watched_seeds.erase(id);
}
// this validation removes configuration data from versions prior to 50.09-r3
// it can be removed once saves from 50.09 are no longer loadable
static bool validate_seed_config(color_ostream& out, PersistentDataItem c)
{
int seed_id = get_config_val(c, SEED_CONFIG_ID);
auto plant = binsearch_in_vector(world->raws.plants.all, &df::plant_raw::index, seed_id);
bool valid = (!plant->flags.is_set(df::enums::plant_raw_flags::TREE));
if (!valid) {
DEBUG(config, out).print("invalid configuration for %s discarded\n", plant->id.c_str());
}
return valid;
}
static const int32_t CYCLE_TICKS = 1200;
static int32_t cycle_timestamp = 0; // world->frame_counter at last cycle
@ -182,12 +196,8 @@ DFhackCExport command_result plugin_load_data (color_ostream &out) {
const size_t num_seed_configs = seed_configs.size();
for (size_t idx = 0; idx < num_seed_configs; ++idx) {
auto& c = seed_configs[idx];
int seed_id = get_config_val(c, SEED_CONFIG_ID);
auto plant = binsearch_in_vector(world->raws.plants.all, &df::plant_raw::index, seed_id);
if (!plant->flags.is_set(df::enums::plant_raw_flags::TREE))
if (validate_seed_config(out, c))
watched_seeds.emplace(get_config_val(c, SEED_CONFIG_ID), c);
else
DEBUG(config, out).print("reference to tree seed in saved config discarded\n");
}
config = World::GetPersistentData(CONFIG_KEY);