From ec7f97bb7a85a1d317c5fdba602e8bbc43eb44cd Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Sat, 2 May 2020 17:37:10 +0200 Subject: [PATCH 1/4] adapted to enum value name change --- library/modules/Units.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index c4b9e60fa..43eb9026c 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -209,7 +209,7 @@ void Units::setNickname(df::unit *unit, std::string nick) case df::identity_type::FalseIdentity: break; // We want the nickname to end up in the identity - case df::identity_type::Unk_1: // Guess, but that's how it worked in the past + case df::identity_type::Impersonating: case df::identity_type::TrueName: case df::identity_type::Unk_4: // Pure guess, as this is a new case, still unseen id_hfig = df::historical_figure::find(identity->histfig_id); From d5b5b81450fca0394e378420c13be64a02828f78 Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Tue, 2 Jun 2020 15:03:59 +0200 Subject: [PATCH 2/4] changes --- library/modules/Units.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index 43eb9026c..458a09ea3 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -204,14 +204,15 @@ void Units::setNickname(df::unit *unit, std::string nick) df::historical_figure *id_hfig = NULL; switch (identity->type) { + case df::identity_type::None: case df::identity_type::HidingCurse: - case df::identity_type::Identity: case df::identity_type::FalseIdentity: + case df::identity_type::InfiltrationIdentity: + case df::identity_type::Identity: break; // We want the nickname to end up in the identity case df::identity_type::Impersonating: case df::identity_type::TrueName: - case df::identity_type::Unk_4: // Pure guess, as this is a new case, still unseen id_hfig = df::historical_figure::find(identity->histfig_id); break; } From a04c609980ae5205dc11c7c4748b1b71a0ae4c40 Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Fri, 3 Jul 2020 13:46:32 +0200 Subject: [PATCH 3/4] fixed getplants, issue #1479 --- plugins/getplants.cpp | 109 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/plugins/getplants.cpp b/plugins/getplants.cpp index d1ee79a04..b722776c0 100644 --- a/plugins/getplants.cpp +++ b/plugins/getplants.cpp @@ -9,11 +9,16 @@ #include "TileTypes.h" #include "df/map_block.h" +#include "df/map_block_column.h" #include "df/plant.h" #include "df/plant_growth.h" #include "df/plant_raw.h" #include "df/tile_dig_designation.h" +#include "df/ui.h" #include "df/world.h" +#include "df/world_data.h" +#include "df/world_object_data.h" +#include "df/world_site.h" #include "modules/Designations.h" #include "modules/Maps.h" @@ -27,7 +32,9 @@ using namespace DFHack; using namespace df::enums; DFHACK_PLUGIN("getplants"); +REQUIRE_GLOBAL(ui); REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cur_year); REQUIRE_GLOBAL(cur_year_tick); enum class selectability { @@ -224,6 +231,106 @@ selectability selectablePlant(const df::plant_raw *plant, bool farming) } } +// Formula for determination of the variance in plant growth maturation time, determined via disassembly. +// The x and y parameters are in tiles relative to the embark. +bool ripe(int32_t x, int32_t y, int32_t start, int32_t end) { + int32_t time = ((435522653 - (((y + 3) * x + 5) * ((y + 7) * y * 400181475 + 289700012))) & 0x3FFFFFFF) % 2000 + (*cur_year_tick % 403200); + + return time >= start && (end == -1 || time <= end); +} + +// Looks in the picked growths vector to see if a matching growth has been marked as picked. +bool picked(const df::plant *plant, int32_t growth_subtype) { + df::world_data *world_data = world->world_data; + df::world_site *site = df::world_site::find(ui->site_id); + int32_t pos_x = site->global_min_x + plant->pos.x / 48; + int32_t pos_y = site->global_min_y + plant->pos.y / 48; + size_t id = pos_x + pos_y * 16 * world_data->world_width; + df::world_object_data *object_data = df::world_object_data::find(id); + df::map_block_column *column = world->map.map_block_columns[(plant->pos.x / 16) * world->map.x_count_block + (plant->pos.y / 16)]; + + for (size_t i = 0; i < object_data->picked_growths.x.size(); i++) { + if (object_data->picked_growths.x[i] == plant->pos.x && + object_data->picked_growths.y[i] == plant->pos.y && + object_data->picked_growths.z[i] - column->z_base == plant->pos.z && + object_data->picked_growths.subtype[i] == growth_subtype && + object_data->picked_growths.year[i] == *cur_year) { + return true; + } + } + + return false; +} + +bool designate(const df::plant *plant, bool farming) { + df::plant_raw *plant_raw = world->raws.plants.all[plant->material]; + const DFHack::MaterialInfo basic_mat = DFHack::MaterialInfo(plant_raw->material_defs.type_basic_mat, plant_raw->material_defs.idx_basic_mat); + + if (basic_mat.material->flags.is_set(material_flags::EDIBLE_RAW) || + basic_mat.material->flags.is_set(material_flags::EDIBLE_COOKED)) + { + return Designations::markPlant(plant); + } + + if (plant_raw->flags.is_set(plant_raw_flags::THREAD) || + plant_raw->flags.is_set(plant_raw_flags::MILL) || + plant_raw->flags.is_set(plant_raw_flags::EXTRACT_VIAL) || + plant_raw->flags.is_set(plant_raw_flags::EXTRACT_BARREL) || + plant_raw->flags.is_set(plant_raw_flags::EXTRACT_STILL_VIAL)) + { + if (!farming) { + return Designations::markPlant(plant); + } + } + + if (basic_mat.material->reaction_product.id.size() > 0 || + basic_mat.material->reaction_class.size() > 0) + { + if (!farming) { + return Designations::markPlant(plant); + } + } + + for (size_t i = 0; i < plant_raw->growths.size(); i++) + { + if (plant_raw->growths[i]->item_type == df::item_type::SEEDS || // Only trees have seed growths in vanilla, but raws can be modded... + plant_raw->growths[i]->item_type == df::item_type::PLANT_GROWTH) + { + const DFHack::MaterialInfo growth_mat = DFHack::MaterialInfo(plant_raw->growths[i]->mat_type, plant_raw->growths[i]->mat_index); + if ((plant_raw->growths[i]->item_type == df::item_type::SEEDS && + (growth_mat.material->flags.is_set(material_flags::EDIBLE_COOKED) || + growth_mat.material->flags.is_set(material_flags::EDIBLE_RAW))) || + (plant_raw->growths[i]->item_type == df::item_type::PLANT_GROWTH && + growth_mat.material->flags.is_set(material_flags::LEAF_MAT))) // Will change name to STOCKPILE_PLANT_GROWTH any day now... + { + bool seedSource = plant_raw->growths[i]->item_type == df::item_type::SEEDS; + + if (plant_raw->growths[i]->item_type == df::item_type::PLANT_GROWTH) + { + for (size_t k = 0; growth_mat.material->reaction_product.material.mat_type.size(); k++) + { + if (growth_mat.material->reaction_product.material.mat_type[k] == plant_raw->material_defs.type_seed && + growth_mat.material->reaction_product.material.mat_index[k] == plant_raw->material_defs.idx_seed) + { + seedSource = true; + break; + } + } + } + + if ((!farming || seedSource) && + ripe(plant->pos.x, plant->pos.y, plant_raw->growths[i]->timing_1, plant_raw->growths[i]->timing_2) && + !picked(plant, i)) + { + return Designations::markPlant(plant); + } + } + } + } + + return false; +} + command_result df_getplants (color_ostream &out, vector & parameters) { string plantMatStr = ""; @@ -448,7 +555,7 @@ command_result df_getplants (color_ostream &out, vector & parameters) collectionCount[plant->material]++; ++count; } - if (!deselect && Designations::markPlant(plant)) + if (!deselect && designate(plant, farming)) { // out.print("Designated %s at (%i, %i, %i), %d\n", world->raws.plants.all[plant->material]->id.c_str(), plant->pos.x, plant->pos.y, plant->pos.z, (int)i); collectionCount[plant->material]++; From 0a2a16d29c401a7fbf606b9cf842385104c0cb30 Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Fri, 3 Jul 2020 15:50:18 +0200 Subject: [PATCH 4/4] corrected ripeness calculation --- plugins/getplants.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/getplants.cpp b/plugins/getplants.cpp index b722776c0..db283d808 100644 --- a/plugins/getplants.cpp +++ b/plugins/getplants.cpp @@ -234,7 +234,7 @@ selectability selectablePlant(const df::plant_raw *plant, bool farming) // Formula for determination of the variance in plant growth maturation time, determined via disassembly. // The x and y parameters are in tiles relative to the embark. bool ripe(int32_t x, int32_t y, int32_t start, int32_t end) { - int32_t time = ((435522653 - (((y + 3) * x + 5) * ((y + 7) * y * 400181475 + 289700012))) & 0x3FFFFFFF) % 2000 + (*cur_year_tick % 403200); + int32_t time = (((435522653 - (((y + 3) * x + 5) * ((y + 7) * y * 400181475 + 289700012))) & 0x3FFFFFFF) % 2000 + *cur_year_tick) % 403200; return time >= start && (end == -1 || time <= end); }