Add tree product exclusions to autochop

develop
David Timm 2017-10-17 13:43:20 -06:00
parent 0ee421a9d4
commit d009022311
1 changed files with 112 additions and 50 deletions

@ -16,6 +16,7 @@
#include "df/items_other_id.h" #include "df/items_other_id.h"
#include "df/job.h" #include "df/job.h"
#include "df/map_block.h" #include "df/map_block.h"
#include "df/material.h"
#include "df/plant.h" #include "df/plant.h"
#include "df/plant_raw.h" #include "df/plant_raw.h"
#include "df/tile_dig_designation.h" #include "df/tile_dig_designation.h"
@ -48,6 +49,9 @@ static bool autochop_enabled = false;
static int min_logs, max_logs; static int min_logs, max_logs;
static const int LOG_CAP_MAX = 99999; static const int LOG_CAP_MAX = 99999;
static bool wait_for_threshold; static bool wait_for_threshold;
static bool skip_fruit_trees;
static bool skip_food_trees;
static bool skip_cook_trees;
static PersistentDataItem config_autochop; static PersistentDataItem config_autochop;
@ -179,6 +183,9 @@ static void save_config()
config_autochop.ival(1) = min_logs; config_autochop.ival(1) = min_logs;
config_autochop.ival(2) = max_logs; config_autochop.ival(2) = max_logs;
config_autochop.ival(3) = wait_for_threshold; config_autochop.ival(3) = wait_for_threshold;
config_autochop.ival(5) = skip_fruit_trees;
config_autochop.ival(6) = skip_food_trees;
config_autochop.ival(7) = skip_cook_trees;
} }
static void initialize() static void initialize()
@ -188,6 +195,9 @@ static void initialize()
min_logs = 80; min_logs = 80;
max_logs = 100; max_logs = 100;
wait_for_threshold = false; wait_for_threshold = false;
skip_fruit_trees = false;
skip_food_trees = false;
skip_cook_trees = false;
config_autochop = World::GetPersistentData("autochop/config"); config_autochop = World::GetPersistentData("autochop/config");
if (config_autochop.isValid()) if (config_autochop.isValid())
@ -197,6 +207,9 @@ static void initialize()
min_logs = config_autochop.ival(1); min_logs = config_autochop.ival(1);
max_logs = config_autochop.ival(2); max_logs = config_autochop.ival(2);
wait_for_threshold = config_autochop.ival(3); wait_for_threshold = config_autochop.ival(3);
skip_fruit_trees = config_autochop.ival(4);
skip_food_trees = config_autochop.ival(5);
skip_cook_trees = config_autochop.ival(6);
} }
else else
{ {
@ -206,25 +219,59 @@ static void initialize()
} }
} }
static int do_chop_designation(bool chop, bool count_only) static bool skip_plant(const df::plant * plant)
{
int count = 0;
for (size_t i = 0; i < world->plants.all.size(); i++)
{ {
const df::plant *plant = world->plants.all[i]; // Skip all non-trees immediately.
if (plant->flags.bits.is_shrub)
return true;
// Skip plants with invalid tile.
df::map_block *cur = Maps::getTileBlock(plant->pos); df::map_block *cur = Maps::getTileBlock(plant->pos);
if (!cur) if (!cur)
continue; return true;
int x = plant->pos.x % 16; int x = plant->pos.x % 16;
int y = plant->pos.y % 16; int y = plant->pos.y % 16;
if (plant->flags.bits.is_shrub) // Skip all unrevealed plants.
continue;
if (cur->designation[x][y].bits.hidden) if (cur->designation[x][y].bits.hidden)
continue; return true;
const df::plant_raw *plant_raw = df::plant_raw::find(plant->material);
// Skip fruit trees if set.
if (skip_fruit_trees && plant_raw->material_defs.type_drink != -1)
return true;
if (skip_food_trees || skip_cook_trees)
{
df::material * mat;
for (int idx = 0; idx < plant_raw->material.size(); idx++)
{
mat = plant_raw->material[idx];
if (skip_food_trees && mat->flags.is_set(material_flags::EDIBLE_RAW))
return true;
if (skip_cook_trees && mat->flags.is_set(material_flags::EDIBLE_COOKED))
return true;
}
}
df::tiletype_material material = tileMaterial(cur->tiletype[x][y]); df::tiletype_material material = tileMaterial(cur->tiletype[x][y]);
if (material != tiletype_material::TREE) if (material != tiletype_material::TREE)
return true;
return false;
}
static int do_chop_designation(bool chop, bool count_only)
{
int count = 0;
for (size_t i = 0; i < world->plants.all.size(); i++)
{
const df::plant *plant = world->plants.all[i];
if (skip_plant(plant))
continue; continue;
if (!count_only && !watchedBurrows.isValidPos(plant->pos)) if (!count_only && !watchedBurrows.isValidPos(plant->pos))
@ -554,6 +601,18 @@ public:
{ {
change_max_logs(10); change_max_logs(10);
} }
else if (input->count(interface_key::CUSTOM_F))
{
skip_fruit_trees = !skip_fruit_trees;
}
else if (input->count(interface_key::CUSTOM_E))
{
skip_food_trees = !skip_food_trees;
}
else if (input->count(interface_key::CUSTOM_C))
{
skip_cook_trees = !skip_cook_trees;
}
else if (enabler->tracking_on && enabler->mouse_lbut) else if (enabler->tracking_on && enabler->mouse_lbut)
{ {
if (burrows_column.setHighlightByMouse()) if (burrows_column.setHighlightByMouse())
@ -636,6 +695,9 @@ public:
OutputString(COLOR_WHITE, x, y, "", true, left_margin); OutputString(COLOR_WHITE, x, y, "", true, left_margin);
} }
OutputHotkeyString(x, y, "No limit", CUSTOM_SHIFT_N, true, left_margin); OutputHotkeyString(x, y, "No limit", CUSTOM_SHIFT_N, true, left_margin);
OutputToggleString(x, y, "Skip Fruit Trees: ", "f", skip_fruit_trees, true, left_margin);
OutputToggleString(x, y, "Skip Edible Product Trees: ", "e", skip_food_trees, true, left_margin);
OutputToggleString(x, y, "Skip Cookable Product Trees: ", "c", skip_cook_trees, true, left_margin);
} }
++y; ++y;