2011-04-10 13:25:41 -06:00
|
|
|
/*
|
|
|
|
* Confiscates and dumps garbage owned by dwarfs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <climits>
|
|
|
|
#include <vector>
|
2011-08-04 16:41:31 -06:00
|
|
|
#include <set>
|
2011-04-10 13:25:41 -06:00
|
|
|
using namespace std;
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
2011-08-04 16:41:31 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "modules/Items.h"
|
|
|
|
#include "modules/Units.h"
|
|
|
|
#include "modules/Translation.h"
|
2012-01-16 21:12:58 -07:00
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "df/world.h"
|
|
|
|
|
2012-01-21 17:31:15 -07:00
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
|
2014-12-02 19:44:20 -07:00
|
|
|
DFHACK_PLUGIN("cleanowned");
|
|
|
|
REQUIRE_GLOBAL(world);
|
2011-08-04 16:41:31 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result df_cleanowned (color_ostream &out, vector <string> & parameters);
|
2011-08-04 16:41:31 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
2011-08-04 16:41:31 -06:00
|
|
|
{
|
2012-01-28 05:03:56 -07:00
|
|
|
commands.push_back(PluginCommand(
|
2022-07-20 15:51:06 -06:00
|
|
|
"cleanowned",
|
|
|
|
"Confiscates and dumps garbage owned by dwarves.",
|
|
|
|
df_cleanowned));
|
2011-08-04 16:41:31 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2011-04-10 13:25:41 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2011-08-04 16:41:31 -06:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result df_cleanowned (color_ostream &out, vector <string> & parameters)
|
2011-04-10 13:25:41 -06:00
|
|
|
{
|
|
|
|
bool dump_scattered = false;
|
2011-04-11 04:33:30 -06:00
|
|
|
bool confiscate_all = false;
|
|
|
|
bool dry_run = false;
|
2011-04-10 13:25:41 -06:00
|
|
|
int wear_dump_level = 65536;
|
2011-04-11 04:33:30 -06:00
|
|
|
|
2011-08-04 21:02:36 -06:00
|
|
|
for(std::size_t i = 0; i < parameters.size(); i++)
|
2011-04-10 13:25:41 -06:00
|
|
|
{
|
2011-08-04 16:41:31 -06:00
|
|
|
string & param = parameters[i];
|
|
|
|
if(param == "dryrun")
|
|
|
|
dry_run = true;
|
|
|
|
else if(param == "scattered")
|
|
|
|
dump_scattered = true;
|
|
|
|
else if(param == "all")
|
|
|
|
confiscate_all = true;
|
|
|
|
else if(param == "x")
|
|
|
|
wear_dump_level = 1;
|
|
|
|
else if(param == "X")
|
2011-08-04 21:02:36 -06:00
|
|
|
wear_dump_level = 2;
|
2011-08-04 16:41:31 -06:00
|
|
|
else
|
2012-01-28 05:03:56 -07:00
|
|
|
return CR_WRONG_USAGE;
|
2011-04-10 13:25:41 -06:00
|
|
|
}
|
2012-01-21 17:31:15 -07:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
CoreSuspender suspend;
|
2012-01-21 17:31:15 -07:00
|
|
|
|
2012-01-27 21:02:25 -07:00
|
|
|
if (!Translation::IsValid())
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Translation data unavailable!\n");
|
2012-01-27 21:02:25 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2011-08-04 16:41:31 -06:00
|
|
|
|
2012-01-16 21:12:58 -07:00
|
|
|
for (std::size_t i=0; i < world->items.all.size(); i++)
|
2011-04-10 13:25:41 -06:00
|
|
|
{
|
2012-01-16 21:12:58 -07:00
|
|
|
df::item * item = world->items.all[i];
|
2011-04-10 13:25:41 -06:00
|
|
|
bool confiscate = false;
|
|
|
|
bool dump = false;
|
2011-04-11 04:33:30 -06:00
|
|
|
|
2012-01-16 19:16:16 -07:00
|
|
|
if (!item->flags.bits.owned)
|
2011-08-04 16:41:31 -06:00
|
|
|
{
|
2012-04-11 10:10:31 -06:00
|
|
|
if (Items::getOwner(item))
|
2011-08-04 16:41:31 -06:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Fixing a misflagged item: \t");
|
2011-05-12 11:09:49 -06:00
|
|
|
confiscate = true;
|
|
|
|
}
|
|
|
|
else
|
2011-08-04 16:41:31 -06:00
|
|
|
{
|
2011-05-12 11:09:49 -06:00
|
|
|
continue;
|
2011-08-04 16:41:31 -06:00
|
|
|
}
|
2011-05-12 11:09:49 -06:00
|
|
|
}
|
|
|
|
|
2012-01-16 19:16:16 -07:00
|
|
|
if (item->flags.bits.rotten)
|
2011-04-10 13:25:41 -06:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Confiscating a rotten item: \t");
|
2011-04-10 13:25:41 -06:00
|
|
|
confiscate = true;
|
|
|
|
}
|
2012-01-16 19:16:16 -07:00
|
|
|
else if (item->flags.bits.on_ground)
|
2011-04-14 10:06:36 -06:00
|
|
|
{
|
2012-09-13 13:42:17 -06:00
|
|
|
df::item_type type = item->getType();
|
2012-11-16 14:33:36 -07:00
|
|
|
if(type == item_type::MEAT ||
|
2012-09-13 13:42:17 -06:00
|
|
|
type == item_type::FISH ||
|
|
|
|
type == item_type::VERMIN ||
|
|
|
|
type == item_type::PET ||
|
|
|
|
type == item_type::PLANT ||
|
|
|
|
type == item_type::CHEESE ||
|
|
|
|
type == item_type::FOOD
|
2011-10-26 15:12:20 -06:00
|
|
|
)
|
|
|
|
{
|
|
|
|
confiscate = true;
|
2011-11-02 19:40:37 -06:00
|
|
|
if(dump_scattered)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Dumping a dropped item: \t");
|
2011-11-02 19:40:37 -06:00
|
|
|
dump = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Confiscating a dropped item: \t");
|
2011-11-02 19:40:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(dump_scattered)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Confiscating and dumping litter: \t");
|
2011-11-02 19:40:37 -06:00
|
|
|
confiscate = true;
|
|
|
|
dump = true;
|
2011-10-26 15:12:20 -06:00
|
|
|
}
|
2011-04-14 10:06:36 -06:00
|
|
|
}
|
2011-10-26 14:18:13 -06:00
|
|
|
else if (item->getWear() >= wear_dump_level)
|
2011-04-10 13:25:41 -06:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Confiscating and dumping a worn item: \t");
|
2011-04-10 13:25:41 -06:00
|
|
|
confiscate = true;
|
|
|
|
dump = true;
|
|
|
|
}
|
2011-04-11 04:33:30 -06:00
|
|
|
else if (confiscate_all)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Confiscating: \t");
|
2011-04-11 04:33:30 -06:00
|
|
|
confiscate = true;
|
|
|
|
}
|
|
|
|
|
2011-04-10 13:25:41 -06:00
|
|
|
if (confiscate)
|
|
|
|
{
|
2011-10-25 05:30:41 -06:00
|
|
|
std::string description;
|
2011-10-26 14:18:13 -06:00
|
|
|
item->getItemDescription(&description, 0);
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print(
|
2022-11-20 17:03:08 -07:00
|
|
|
"[%d] %s (wear level %d)",
|
|
|
|
item->id,
|
2011-10-25 05:30:41 -06:00
|
|
|
description.c_str(),
|
2011-10-26 14:18:13 -06:00
|
|
|
item->getWear()
|
2011-04-11 04:33:30 -06:00
|
|
|
);
|
|
|
|
|
2012-04-11 10:10:31 -06:00
|
|
|
df::unit *owner = Items::getOwner(item);
|
2011-04-11 04:33:30 -06:00
|
|
|
|
2012-01-24 10:32:34 -07:00
|
|
|
if (owner)
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print(", owner %s", Translation::TranslateName(&owner->name,false).c_str());
|
2011-04-11 04:33:30 -06:00
|
|
|
|
2011-08-05 07:05:57 -06:00
|
|
|
if (!dry_run)
|
|
|
|
{
|
2012-04-11 10:10:31 -06:00
|
|
|
if (!Items::setOwner(item,NULL))
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("(unsuccessfully) ");
|
2011-08-05 07:05:57 -06:00
|
|
|
if (dump)
|
2012-01-16 19:16:16 -07:00
|
|
|
item->flags.bits.dump = 1;
|
2011-08-05 07:05:57 -06:00
|
|
|
}
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("\n");
|
2011-04-10 13:25:41 -06:00
|
|
|
}
|
2011-04-11 04:33:30 -06:00
|
|
|
}
|
2011-08-04 16:41:31 -06:00
|
|
|
return CR_OK;
|
2011-04-10 13:25:41 -06:00
|
|
|
}
|