Merge pull request #3708 from ab9rf/5009-treeseedwatch

seedwatch: ignore tree seeds
develop
Myk 2023-08-29 22:42:33 -07:00 committed by GitHub
commit db50dd6f53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

@ -30,6 +30,7 @@ Template for new versions:
## Fixes
- `tailor`: remove crash caused by clothing items with an invalid ``maker_race``
- `seedwatch`: seedwatch will now ignore (unplantable) tree seeds entirely
## Misc Improvements

@ -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
@ -171,7 +185,8 @@ DFhackCExport command_result plugin_load_data (color_ostream &out) {
world_plant_ids.clear();
for (size_t i = 0; i < world->raws.plants.all.size(); ++i) {
auto & plant = world->raws.plants.all[i];
if (plant->material_defs.type[plant_material_def::seed] != -1)
if (plant->material_defs.type[plant_material_def::seed] != -1 &&
!plant->flags.is_set(df::enums::plant_raw_flags::TREE))
world_plant_ids[plant->id] = i;
}
@ -181,6 +196,7 @@ 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];
if (validate_seed_config(out, c))
watched_seeds.emplace(get_config_val(c, SEED_CONFIG_ID), c);
}