2012-05-01 09:58:12 -06:00
|
|
|
#include "Core.h"
|
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
|
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/ui.h"
|
|
|
|
#include "df/building_nest_boxst.h"
|
|
|
|
#include "df/building_type.h"
|
2018-08-16 10:33:59 -06:00
|
|
|
#include "df/buildings_other_id.h"
|
2012-05-01 09:58:12 -06:00
|
|
|
#include "df/global_objects.h"
|
|
|
|
#include "df/item.h"
|
|
|
|
#include "df/unit.h"
|
|
|
|
#include "df/building.h"
|
|
|
|
#include "df/items_other_id.h"
|
|
|
|
#include "df/creature_raw.h"
|
|
|
|
#include "modules/MapCache.h"
|
|
|
|
#include "modules/Items.h"
|
|
|
|
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using std::endl;
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
|
|
|
|
using df::global::world;
|
|
|
|
using df::global::ui;
|
|
|
|
|
|
|
|
static command_result nestboxes(color_ostream &out, vector <string> & parameters);
|
|
|
|
|
|
|
|
DFHACK_PLUGIN("nestboxes");
|
|
|
|
|
2013-09-30 03:19:51 -06:00
|
|
|
DFHACK_PLUGIN_IS_ENABLED(enabled);
|
2012-08-30 08:23:11 -06:00
|
|
|
|
|
|
|
static void eggscan(color_ostream &out)
|
|
|
|
{
|
2012-11-16 14:33:36 -07:00
|
|
|
CoreSuspender suspend;
|
|
|
|
|
2018-08-16 10:33:59 -06:00
|
|
|
for (df::building *build : world->buildings.other[df::buildings_other_id::NEST_BOX])
|
2012-11-16 14:33:36 -07:00
|
|
|
{
|
|
|
|
auto type = build->getType();
|
|
|
|
if (df::enums::building_type::NestBox == type)
|
|
|
|
{
|
2012-08-30 08:23:11 -06:00
|
|
|
bool fertile = false;
|
2012-11-16 14:33:36 -07:00
|
|
|
df::building_nest_boxst *nb = virtual_cast<df::building_nest_boxst>(build);
|
|
|
|
if (nb->claimed_by != -1)
|
2012-08-30 08:23:11 -06:00
|
|
|
{
|
|
|
|
df::unit* u = df::unit::find(nb->claimed_by);
|
2016-08-10 21:50:00 -06:00
|
|
|
if (u && u->pregnancy_timer > 0)
|
2012-08-30 08:23:11 -06:00
|
|
|
fertile = true;
|
|
|
|
}
|
2018-06-01 08:02:05 -06:00
|
|
|
for (size_t j = 1; j < nb->contained_items.size(); j++)
|
2012-08-30 08:23:11 -06:00
|
|
|
{
|
|
|
|
df::item* item = nb->contained_items[j]->item;
|
2012-11-16 14:33:36 -07:00
|
|
|
if (item->flags.bits.forbid != fertile)
|
|
|
|
{
|
|
|
|
item->flags.bits.forbid = fertile;
|
|
|
|
out << item->getStackSize() << " eggs " << (fertile ? "forbidden" : "unforbidden.") << endl;
|
|
|
|
}
|
2012-08-30 08:23:11 -06:00
|
|
|
}
|
2012-11-16 14:33:36 -07:00
|
|
|
}
|
2012-08-30 08:23:11 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-01 09:58:12 -06:00
|
|
|
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
if (world && ui) {
|
2012-11-16 14:33:36 -07:00
|
|
|
commands.push_back(
|
2018-08-16 09:21:44 -06:00
|
|
|
PluginCommand("nestboxes", "Automatically scan for and forbid fertile eggs incubating in a nestbox.",
|
2012-11-16 14:33:36 -07:00
|
|
|
nestboxes, false,
|
2018-08-16 09:21:44 -06:00
|
|
|
"To enable: nestboxes enable\n"
|
|
|
|
"To disable: nestboxes disable\n"
|
|
|
|
"There is no other configuration.\n"
|
2012-11-16 14:33:36 -07:00
|
|
|
)
|
|
|
|
);
|
2012-05-01 09:58:12 -06:00
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-30 08:23:11 -06:00
|
|
|
DFhackCExport command_result plugin_onupdate(color_ostream &out)
|
|
|
|
{
|
|
|
|
if (!enabled)
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
static unsigned cnt = 0;
|
|
|
|
if ((++cnt % 5) != 0)
|
|
|
|
return CR_OK;
|
|
|
|
|
2012-11-16 14:33:36 -07:00
|
|
|
eggscan(out);
|
2012-08-30 08:23:11 -06:00
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-05-01 09:58:12 -06:00
|
|
|
|
2013-09-30 03:19:51 -06:00
|
|
|
DFhackCExport command_result plugin_enable(color_ostream &out, bool enable)
|
|
|
|
{
|
|
|
|
enabled = enable;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-01 09:58:12 -06:00
|
|
|
static command_result nestboxes(color_ostream &out, vector <string> & parameters)
|
|
|
|
{
|
2012-11-16 14:33:36 -07:00
|
|
|
CoreSuspender suspend;
|
2012-05-01 09:58:12 -06:00
|
|
|
|
2012-11-16 14:33:36 -07:00
|
|
|
if (parameters.size() == 1) {
|
|
|
|
if (parameters[0] == "enable")
|
|
|
|
enabled = true;
|
|
|
|
else if (parameters[0] == "disable")
|
|
|
|
enabled = false;
|
|
|
|
else
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
} else {
|
|
|
|
out << "Plugin " << (enabled ? "enabled" : "disabled") << "." << endl;
|
|
|
|
}
|
|
|
|
return CR_OK;
|
2012-05-01 09:58:12 -06:00
|
|
|
}
|