Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cbf1e23

Browse files
committed
fix designation of non-fruit trees
1 parent 956918f commit cbf1e23

1 file changed

Lines changed: 41 additions & 25 deletions

File tree

plugins/getplants.cpp

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,15 @@ bool picked(const df::plant* plant, int32_t growth_subtype) {
236236
return false;
237237
}
238238

239-
bool designate(const df::plant* plant, bool farming) {
239+
bool designate(color_ostream& out, const df::plant* plant, bool farming) {
240+
TRACE(log, out).print("Attempting to designate %s at (%i, %i, %i)\n", world->raws.plants.all[plant->material]->id.c_str(), plant->pos.x, plant->pos.y, plant->pos.z);
241+
242+
if (!farming) {
243+
bool istree = (tileMaterial(Maps::getTileBlock(plant->pos)->tiletype[plant->pos.x % 16][plant->pos.y % 16]) == tiletype_material::TREE);
244+
if (istree)
245+
return Designations::markPlant(plant);
246+
}
247+
240248
df::plant_raw* plant_raw = world->raws.plants.all[plant->material];
241249
const DFHack::MaterialInfo basic_mat = DFHack::MaterialInfo(plant_raw->material_defs.type[plant_material_def::basic_mat], plant_raw->material_defs.idx[plant_material_def::basic_mat]);
242250

@@ -263,34 +271,40 @@ bool designate(const df::plant* plant, bool farming) {
263271
}
264272

265273
for (size_t i = 0; i < plant_raw->growths.size(); i++) {
266-
if (plant_raw->growths[i]->item_type == df::item_type::SEEDS || // Only trees have seed growths in vanilla, but raws can be modded...
267-
plant_raw->growths[i]->item_type == df::item_type::PLANT_GROWTH) {
268-
const DFHack::MaterialInfo growth_mat = DFHack::MaterialInfo(plant_raw->growths[i]->mat_type, plant_raw->growths[i]->mat_index);
269-
if ((plant_raw->growths[i]->item_type == df::item_type::SEEDS &&
270-
(growth_mat.material->flags.is_set(material_flags::EDIBLE_COOKED) ||
271-
growth_mat.material->flags.is_set(material_flags::EDIBLE_RAW))) ||
272-
(plant_raw->growths[i]->item_type == df::item_type::PLANT_GROWTH &&
273-
growth_mat.material->flags.is_set(material_flags::LEAF_MAT))) // Will change name to STOCKPILE_PLANT_GROWTH any day now...
274-
{
275-
bool seedSource = plant_raw->growths[i]->item_type == df::item_type::SEEDS;
274+
TRACE(log, out).print("growth item type=%d\n", plant_raw->growths[i]->item_type);
275+
// Only trees have seed growths in vanilla, but raws can be modded...
276+
if (plant_raw->growths[i]->item_type != df::item_type::SEEDS &&
277+
plant_raw->growths[i]->item_type != df::item_type::PLANT_GROWTH)
278+
continue;
276279

277-
if (plant_raw->growths[i]->item_type == df::item_type::PLANT_GROWTH) {
278-
for (size_t k = 0; growth_mat.material->reaction_product.material.mat_type.size(); k++) {
279-
if (growth_mat.material->reaction_product.material.mat_type[k] == plant_raw->material_defs.type[plant_material_def::seed] &&
280-
growth_mat.material->reaction_product.material.mat_index[k] == plant_raw->material_defs.idx[plant_material_def::seed]) {
281-
seedSource = true;
282-
break;
283-
}
284-
}
285-
}
280+
const DFHack::MaterialInfo growth_mat = DFHack::MaterialInfo(plant_raw->growths[i]->mat_type, plant_raw->growths[i]->mat_index);
281+
TRACE(log, out).print("edible_cooked=%d edible_raw=%d leaf_mat=%d\n",
282+
growth_mat.material->flags.is_set(material_flags::EDIBLE_COOKED),
283+
growth_mat.material->flags.is_set(material_flags::EDIBLE_RAW),
284+
growth_mat.material->flags.is_set(material_flags::LEAF_MAT));
285+
if (!(plant_raw->growths[i]->item_type == df::item_type::SEEDS &&
286+
(growth_mat.material->flags.is_set(material_flags::EDIBLE_COOKED) ||
287+
growth_mat.material->flags.is_set(material_flags::EDIBLE_RAW))) &&
288+
!(plant_raw->growths[i]->item_type == df::item_type::PLANT_GROWTH &&
289+
growth_mat.material->flags.is_set(material_flags::LEAF_MAT))) // Will change name to STOCKPILE_PLANT_GROWTH any day now...
290+
continue;
291+
292+
bool seedSource = plant_raw->growths[i]->item_type == df::item_type::SEEDS;
286293

287-
bool istree = (tileMaterial(Maps::getTileBlock(plant->pos)->tiletype[plant->pos.x % 16][plant->pos.y % 16]) == tiletype_material::TREE);
288-
bool isripe = ripe(plant->pos.x, plant->pos.y, plant_raw->growths[i]->timing_1, plant_raw->growths[i]->timing_2);
289-
if ((!farming || seedSource) && (istree || isripe) && !picked(plant, i)) {
290-
return Designations::markPlant(plant);
294+
if (plant_raw->growths[i]->item_type == df::item_type::PLANT_GROWTH) {
295+
for (size_t k = 0; growth_mat.material->reaction_product.material.mat_type.size(); k++) {
296+
if (growth_mat.material->reaction_product.material.mat_type[k] == plant_raw->material_defs.type[plant_material_def::seed] &&
297+
growth_mat.material->reaction_product.material.mat_index[k] == plant_raw->material_defs.idx[plant_material_def::seed]) {
298+
seedSource = true;
299+
break;
291300
}
292301
}
293302
}
303+
304+
if ((!farming || seedSource) &&
305+
ripe(plant->pos.x, plant->pos.y, plant_raw->growths[i]->timing_1, plant_raw->growths[i]->timing_2) &&
306+
!picked(plant, i))
307+
return Designations::markPlant(plant);
294308
}
295309

296310
return false;
@@ -460,6 +474,8 @@ command_result df_getplants(color_ostream& out, vector <string>& parameters) {
460474
const df::plant* plant = world->plants.all[i];
461475
df::map_block* cur = Maps::getTileBlock(plant->pos);
462476

477+
TRACE(log, out).print("Examining %s at (%i, %i, %i) [index=%d]\n", world->raws.plants.all[plant->material]->id.c_str(), plant->pos.x, plant->pos.y, plant->pos.z, (int)i);
478+
463479
int x = plant->pos.x % 16;
464480
int y = plant->pos.y % 16;
465481
if (plantSelections[plant->material] == selectability::OutOfSeason ||
@@ -487,7 +503,7 @@ command_result df_getplants(color_ostream& out, vector <string>& parameters) {
487503
collectionCount[plant->material]++;
488504
++count;
489505
}
490-
if (!deselect && designate(plant, farming)) {
506+
if (!deselect && designate(out, plant, farming)) {
491507
DEBUG(log, 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);
492508
collectionCount[plant->material]++;
493509
++count;

0 commit comments

Comments
 (0)