Skip to content
Merged
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
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 19 additions & 3 deletions plugins/seedwatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
}

Expand All @@ -180,8 +195,9 @@ DFhackCExport command_result plugin_load_data (color_ostream &out) {
World::GetPersistentData(&seed_configs, SEED_CONFIG_KEY_PREFIX, true);
const size_t num_seed_configs = seed_configs.size();
for (size_t idx = 0; idx < num_seed_configs; ++idx) {
auto &c = seed_configs[idx];
watched_seeds.emplace(get_config_val(c, SEED_CONFIG_ID), c);
auto& c = seed_configs[idx];
if (validate_seed_config(out, c))
watched_seeds.emplace(get_config_val(c, SEED_CONFIG_ID), c);
}

config = World::GetPersistentData(CONFIG_KEY);
Expand Down