|
|
@ -7,6 +7,7 @@
|
|
|
|
#include "df/building_def.h"
|
|
|
|
#include "df/building_def.h"
|
|
|
|
#include "df/viewscreen_dwarfmodest.h"
|
|
|
|
#include "df/viewscreen_dwarfmodest.h"
|
|
|
|
#include "df/building_stockpilest.h"
|
|
|
|
#include "df/building_stockpilest.h"
|
|
|
|
|
|
|
|
#include "modules/Buildings.h"
|
|
|
|
#include "modules/Items.h"
|
|
|
|
#include "modules/Items.h"
|
|
|
|
#include "df/ui.h"
|
|
|
|
#include "df/ui.h"
|
|
|
|
#include "modules/Maps.h"
|
|
|
|
#include "modules/Maps.h"
|
|
|
@ -23,10 +24,36 @@ DFHACK_PLUGIN("automelt");
|
|
|
|
|
|
|
|
|
|
|
|
static const string PERSISTENCE_KEY = "automelt/stockpiles";
|
|
|
|
static const string PERSISTENCE_KEY = "automelt/stockpiles";
|
|
|
|
|
|
|
|
|
|
|
|
static void mark_all_in_stockpiles(vector<PersistentStockpileInfo> &stockpiles)
|
|
|
|
static int mark_item(df::item *item, df::item_flags bad_flags, int32_t stockpile_id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (item->flags.whole & bad_flags.whole)
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item->isAssignedToThisStockpile(stockpile_id)) {
|
|
|
|
|
|
|
|
size_t marked_count = 0;
|
|
|
|
|
|
|
|
std::vector<df::item*> contents;
|
|
|
|
|
|
|
|
Items::getContainedItems(item, &contents);
|
|
|
|
|
|
|
|
for (auto child = contents.begin(); child != contents.end(); child++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::vector<df::item*> &items = world->items.other[items_other_id::IN_PLAY];
|
|
|
|
marked_count += mark_item(*child, bad_flags, stockpile_id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return marked_count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!can_melt(item))
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (is_set_to_melt(item))
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
insert_into_vector(world->items.other[items_other_id::ANY_MELT_DESIGNATED], &df::item::id, item);
|
|
|
|
|
|
|
|
item->flags.bits.melt = true;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void mark_all_in_stockpiles(vector<PersistentStockpileInfo> &stockpiles)
|
|
|
|
|
|
|
|
{
|
|
|
|
// Precompute a bitmask with the bad flags
|
|
|
|
// Precompute a bitmask with the bad flags
|
|
|
|
df::item_flags bad_flags;
|
|
|
|
df::item_flags bad_flags;
|
|
|
|
bad_flags.whole = 0;
|
|
|
|
bad_flags.whole = 0;
|
|
|
@ -39,27 +66,16 @@ static void mark_all_in_stockpiles(vector<PersistentStockpileInfo> &stockpiles)
|
|
|
|
#undef F
|
|
|
|
#undef F
|
|
|
|
|
|
|
|
|
|
|
|
size_t marked_count = 0;
|
|
|
|
size_t marked_count = 0;
|
|
|
|
for (size_t i = 0; i < items.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
df::item *item = items[i];
|
|
|
|
|
|
|
|
if (item->flags.whole & bad_flags.whole)
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!can_melt(item))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (is_set_to_melt(item))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto &melting_items = world->items.other[items_other_id::ANY_MELT_DESIGNATED];
|
|
|
|
|
|
|
|
for (auto it = stockpiles.begin(); it != stockpiles.end(); it++)
|
|
|
|
for (auto it = stockpiles.begin(); it != stockpiles.end(); it++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!it->inStockpile(item))
|
|
|
|
if (!it->isValid())
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
++marked_count;
|
|
|
|
auto spid = it->getId();
|
|
|
|
insert_into_vector(melting_items, &df::item::id, item);
|
|
|
|
Buildings::StockpileIterator stored;
|
|
|
|
item->flags.bits.melt = true;
|
|
|
|
for (stored.begin(it->getStockpile()); !stored.done(); ++stored)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
marked_count += mark_item(*stored, bad_flags, spid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|