Further updates from comments/review.

develop
eamondo2 2023-01-22 04:39:41 -05:00
parent 6585055ed2
commit 969f8162a8
2 changed files with 46 additions and 49 deletions

@ -268,27 +268,40 @@ static bool isStockpile(df::building * building) {
return building->getType() == df::building_type::Stockpile; return building->getType() == df::building_type::Stockpile;
} }
struct BadFlagsCanMelt {
uint32_t whole;
BadFlagsCanMelt() {
df::item_flags flags;
#define F(x) flags.bits.x = true;
F(dump); F(forbid); F(garbage_collect);
F(hostile); F(on_fire); F(rotten); F(trader);
F(in_building); F(construction); F(in_job);
#undef F
whole = flags.whole;
}
};
struct BadFlagsMarkItem {
uint32_t whole;
BadFlagsMarkItem() {
df::item_flags flags;
#define F(x) flags.bits.x = true;
F(dump); F(forbid); F(garbage_collect);
F(hostile); F(on_fire); F(rotten); F(trader);
F(in_building); F(construction); F(artifact);
F(spider_web); F(owned);
#undef F
whole = flags.whole;
}
};
// Copied from Kelly Martin's code // Copied from Kelly Martin's code
static inline bool can_melt(df::item *item) static inline bool can_melt(df::item *item)
{ {
df::item_flags bad_flags; static const BadFlagsCanMelt bad_flags;
bad_flags.whole = 0;
#define F(x) bad_flags.bits.x = true;
F(dump);
F(forbid);
F(garbage_collect);
F(in_job);
F(hostile);
F(on_fire);
F(rotten);
F(trader);
F(in_building);
F(construction);
F(artifact);
F(melt);
#undef F
if (item->flags.whole & bad_flags.whole) if (item->flags.whole & bad_flags.whole)
return false; return false;
@ -301,9 +314,9 @@ static inline bool can_melt(df::item *item)
if (!is_metal_item(item)) if (!is_metal_item(item))
return false; return false;
for (auto g = item->general_refs.begin(); g != item->general_refs.end(); g++) for (auto &g : item->general_refs)
{ {
switch ((*g)->getType()) switch (g->getType())
{ {
case general_ref_type::CONTAINS_ITEM: case general_ref_type::CONTAINS_ITEM:
case general_ref_type::UNIT_HOLDER: case general_ref_type::UNIT_HOLDER:
@ -311,10 +324,10 @@ static inline bool can_melt(df::item *item)
return false; return false;
case general_ref_type::CONTAINED_IN_ITEM: case general_ref_type::CONTAINED_IN_ITEM:
{ {
df::item *c = (*g)->getItem(); df::item *c = g->getItem();
for (auto gg = c->general_refs.begin(); gg != c->general_refs.end(); gg++) for (auto &gg : c->general_refs)
{ {
if ((*gg)->getType() == general_ref_type::UNIT_HOLDER) if (gg->getType() == general_ref_type::UNIT_HOLDER)
return false; return false;
} }
} }
@ -335,17 +348,17 @@ static inline bool is_set_to_melt(df::item *item)
return item->flags.bits.melt; return item->flags.bits.melt;
} }
static inline bool is_in_job(df::item *item) { static int mark_item(color_ostream &out, df::item *item, BadFlagsMarkItem bad_flags, int32_t stockpile_id,
return item->flags.bits.in_job;
}
static int mark_item(color_ostream &out, df::item *item, df::item_flags bad_flags, int32_t stockpile_id,
int32_t &premarked_item_count, int32_t &item_count, map<int32_t, bool> &tracked_item_map, bool should_melt) int32_t &premarked_item_count, int32_t &item_count, map<int32_t, bool> &tracked_item_map, bool should_melt)
{ {
DEBUG(perf,out).print("%s running mark_item\nshould_melt=%d\n", plugin_name,should_melt); DEBUG(perf,out).print("%s running mark_item\nshould_melt=%d\n", plugin_name,should_melt);
if (DBG_NAME(perf).isEnabled(DebugCategory::LDEBUG)) {
string name = ""; string name = "";
item->getItemDescription(&name, 0); item->getItemDescription(&name, 0);
DEBUG(perf,out).print("item %s %d\n", name.c_str(), item->id); DEBUG(perf,out).print("item %s %d\n", name.c_str(), item->id);
}
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++; item_count++;
@ -403,24 +416,8 @@ static int mark_item(color_ostream &out, df::item *item, df::item_flags bad_flag
static int32_t mark_all_in_stockpile(color_ostream &out, PersistentDataItem & stockpile, int32_t &premarked_item_count, int32_t &item_count, map<int32_t, bool> &tracked_item_map, bool should_melt) static int32_t mark_all_in_stockpile(color_ostream &out, PersistentDataItem & stockpile, int32_t &premarked_item_count, int32_t &item_count, map<int32_t, bool> &tracked_item_map, bool should_melt)
{ {
DEBUG(perf,out).print("%s running mark_all_in_stockpile\nshould_melt=%d\n", plugin_name, should_melt); DEBUG(perf,out).print("%s running mark_all_in_stockpile\nshould_melt=%d\n", plugin_name, should_melt);
// Precompute a bitmask with the bad flags
df::item_flags bad_flags; static const BadFlagsMarkItem bad_flags;
bad_flags.whole = 0;
#define F(x) bad_flags.bits.x = true;
F(dump);
F(forbid);
F(garbage_collect);
F(hostile);
F(on_fire);
F(rotten);
F(trader);
F(in_building);
F(construction);
F(artifact);
F(spider_web);
F(owned);
#undef F
int32_t marked_count = 0; int32_t marked_count = 0;

@ -47,7 +47,7 @@ function parse_commandline(...)
return true return true
end end
-- used by gui/autochop -- used by gui/auomelt
function setStockpileConfig(config) function setStockpileConfig(config)
automelt_setStockpileConfig(config.id, config.monitored) automelt_setStockpileConfig(config.id, config.monitored)
end end