Changes as per GH suggestions. Doc updates.

develop
eamondo2 2023-01-23 01:56:33 -05:00
parent 8f7788ec20
commit 78c6b3683e
3 changed files with 71 additions and 20 deletions

@ -17,21 +17,28 @@ Usage
enable automelt enable automelt
automelt [status] automelt [status]
automelt (designate) automelt designate
automelt (monitor|nomonitor) <stockpile> automelt (monitor|nomonitor) <stockpile>[,<stockpile>...]
Examples Examples
-------- --------
Automatically designate all meltable items in the stockpile ("melt") for melting. :: Automatically monitor stockpile ("melt"), marking new valid items for melting. This also immediately marks all present items for melting::
enable automelt enable automelt
automelt monitor melt automelt monitor melt
Enable monitoring for the stockpile ("melt"), and mmediately designate all meltable items in monitored stockpiles for melting. :: Enable monitoring for ("Stockpile #52"), which has not been given a custom name::
automelt monitor melt automelt monitor "Stockpile #52"
automelt designate
Enable monitoring for ("Stockpile #52"), which has not been given a custom name::
automelt monitor 52
Enable monitoring for multiple stockpiles ("Stockpile #52", "Stockpile #35", and "melt")::
automelt monitor 52,"Stockpile #35",melt
Commands Commands
-------- --------
@ -43,4 +50,6 @@ Commands
Designates items in monitored stockpiles for melting right now. This works even if ``automelt`` is not currently enabled. Designates items in monitored stockpiles for melting right now. This works even if ``automelt`` is not currently enabled.
``(no)monitor <stockpile>`` ``(no)monitor <stockpile>``
Enable/disable monitoring of a given stockpile. Requires the stockpile to have a name set. Enable/disable monitoring of a given stockpile. Works with either the stockpile's name (if set) or ID.
If the stockpile has no custom name set, you may designate it by either the full name as reported by
the status command, or by just the number.

@ -276,7 +276,8 @@ struct BadFlagsCanMelt {
#define F(x) flags.bits.x = true; #define F(x) flags.bits.x = true;
F(dump); F(forbid); F(garbage_collect); F(dump); F(forbid); F(garbage_collect);
F(hostile); F(on_fire); F(rotten); F(trader); F(hostile); F(on_fire); F(rotten); F(trader);
F(in_building); F(construction); F(in_job); F(in_building); F(construction); F(artifact);
F(spider_web); F(owned); F(in_job);
#undef F #undef F
whole = flags.whole; whole = flags.whole;
} }
@ -361,7 +362,6 @@ static int mark_item(color_ostream &out, df::item *item, BadFlagsMarkItem bad_fl
if (item->flags.whole & bad_flags.whole){ if (item->flags.whole & bad_flags.whole){
DEBUG(perf,out).print("rejected flag check\n"); DEBUG(perf,out).print("rejected flag check\n");
item_count++;
return 0; return 0;
} }
@ -392,7 +392,6 @@ static int mark_item(color_ostream &out, df::item *item, BadFlagsMarkItem bad_fl
if (!can_melt(item)) { if (!can_melt(item)) {
DEBUG(perf,out).print("cannot melt\n"); DEBUG(perf,out).print("cannot melt\n");
item_count++;
return 0; return 0;
} }
@ -588,7 +587,6 @@ static void push_stockpile_config(lua_State *L, int id, bool monitored) {
map<string, int32_t> stockpile_config; map<string, int32_t> stockpile_config;
stockpile_config.emplace("id", id); stockpile_config.emplace("id", id);
stockpile_config.emplace("monitored", monitored); stockpile_config.emplace("monitored", monitored);
Lua::Push(L, stockpile_config); Lua::Push(L, stockpile_config);
} }
@ -625,13 +623,18 @@ static void automelt_printStatus(color_ostream &out) {
int name_width = 11; int name_width = 11;
for (auto &stockpile : world->buildings.other.STOCKPILE) { for (auto &stockpile : world->buildings.other.STOCKPILE) {
if (!isStockpile(stockpile)) continue; if (!isStockpile(stockpile)) continue;
name_width = std::max(name_width, (int)stockpile->name.size()); if (stockpile->name.empty()) {
string stock_name = "Stockpile #" + int_to_string(stockpile->stockpile_number);
name_width = std::max(name_width, (int)(stock_name.size()));
} else {
name_width = std::max(name_width, (int)stockpile->name.size());
}
} }
name_width = -name_width; name_width = -name_width;
const char *fmt = "%*s %4s %4s %5s %5s\n"; const char *fmt = "%*s %9s %5s %6s\n";
out.print(fmt, name_width, "name", " id ", "monitored", "items", "marked"); out.print(fmt, name_width, "name", "monitored", "items", "marked");
out.print(fmt, name_width, "----", "----", "---------", "-----", "------"); out.print(fmt, name_width, "----", "---------", "-----", "------");
for (auto &stockpile : world->buildings.other.STOCKPILE) { for (auto &stockpile : world->buildings.other.STOCKPILE) {
if (!isStockpile(stockpile)) continue; if (!isStockpile(stockpile)) continue;
@ -644,11 +647,19 @@ static void automelt_printStatus(color_ostream &out) {
int id = get_config_val(c, STOCKPILE_CONFIG_ID); int id = get_config_val(c, STOCKPILE_CONFIG_ID);
item_count = item_count_piles[id]; item_count = item_count_piles[id];
marked_item_count = premarked_item_count_piles[id]; marked_item_count = premarked_item_count_piles[id];
}
int32_t stockpile_number = stockpile->stockpile_number;
if (stockpile->name.empty()) {
string stock_name = "Stockpile #" + int_to_string(stockpile->stockpile_number);
out.print(fmt, name_width, stock_name, monitored ? "[x]": "[ ]",
int_to_string(item_count).c_str(), int_to_string(marked_item_count).c_str());
} else {
out.print(fmt, name_width, stockpile->name.c_str(), monitored ? "[x]": "[ ]",
int_to_string(item_count).c_str(), int_to_string(marked_item_count).c_str());
} }
out.print(fmt, name_width, stockpile->name.c_str(), int_to_string(stockpile->id).c_str(), monitored ? "[x]": "[ ]",
int_to_string(item_count).c_str(), int_to_string(marked_item_count).c_str());
} }
DEBUG(status,out).print("exiting automelt_printStatus\n"); DEBUG(status,out).print("exiting automelt_printStatus\n");
@ -667,6 +678,11 @@ static void automelt_setStockpileConfig(color_ostream &out, int id, bool monitor
PersistentDataItem &c = ensure_stockpile_config(out, id); PersistentDataItem &c = ensure_stockpile_config(out, id);
set_config_val(c, STOCKPILE_CONFIG_ID, id); set_config_val(c, STOCKPILE_CONFIG_ID, id);
set_config_bool(c, STOCKPILE_CONFIG_MONITORED, monitored); set_config_bool(c, STOCKPILE_CONFIG_MONITORED, monitored);
//If we're marking something as monitored, go ahead and designate contents.
if (monitored) {
automelt_designate(out);
}
} }
static int automelt_getStockpileConfig(lua_State *L) { static int automelt_getStockpileConfig(lua_State *L) {
@ -678,10 +694,23 @@ static int automelt_getStockpileConfig(lua_State *L) {
int id; int id;
if (lua_isnumber(L, -1)) { if (lua_isnumber(L, -1)) {
bool found = false;
id = lua_tointeger(L, -1); id = lua_tointeger(L, -1);
if (!df::building::find(id))
for (auto &stockpile : world->buildings.other.STOCKPILE) {
if (!isStockpile(stockpile)) continue;
if (id == stockpile->stockpile_number){
id = stockpile->id;
found = true;
break;
}
}
if (!found)
return 0; return 0;
} else { } else {
const char * name = lua_tostring(L, -1); const char * name = lua_tostring(L, -1);
if (!name) if (!name)
@ -694,8 +723,16 @@ static int automelt_getStockpileConfig(lua_State *L) {
id = stockpile->id; id = stockpile->id;
found = true; found = true;
break; break;
} else {
string stock_name = "Stockpile #" + int_to_string(stockpile->stockpile_number);
if (stock_name == nameStr) {
id = stockpile->id;
found = true;
break;
}
} }
} }
if (!found) if (!found)
return 0; return 0;

@ -38,7 +38,7 @@ function parse_commandline(...)
automelt_designate() automelt_designate()
elseif command == 'monitor' then elseif command == 'monitor' then
do_set_stockpile_config('monitor', true, args[2]) do_set_stockpile_config('monitor', true, args[2])
elseif command == 'nomonitor'then elseif command == 'nomonitor' or command == 'unmonitor' then
do_set_stockpile_config('monitor', false, args[2]) do_set_stockpile_config('monitor', false, args[2])
else else
return false return false
@ -47,12 +47,13 @@ function parse_commandline(...)
return true return true
end end
-- used by gui/auomelt -- used by gui/automelt
function setStockpileConfig(config) function setStockpileConfig(config)
automelt_setStockpileConfig(config.id, config.monitored) automelt_setStockpileConfig(config.id, config.monitored)
end end
function getItemCountsAndStockpileConfigs() function getItemCountsAndStockpileConfigs()
local fmt = 'Stockpile #%-5s'
local data = {automelt_getItemCountsAndStockpileConfigs()} local data = {automelt_getItemCountsAndStockpileConfigs()}
local ret = {} local ret = {}
ret.summary = table.remove(data, 1) ret.summary = table.remove(data, 1)
@ -62,6 +63,10 @@ function getItemCountsAndStockpileConfigs()
ret.stockpile_configs = data ret.stockpile_configs = data
for _,c in ipairs(ret.stockpile_configs) do for _,c in ipairs(ret.stockpile_configs) do
c.name = df.building.find(c.id).name c.name = df.building.find(c.id).name
if not c.name or c.name == '' then
c.name = (fmt):format(tostring(df.building.find(c.id).stockpile_number))
c.name = c.name.gsub(c.name, '^%s*(.-)%s*$', '%1')
end
c.monitored = c.monitored ~= 0 c.monitored = c.monitored ~= 0
end end
return ret return ret