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"
|
2012-01-19 20:44:17 -07:00
|
|
|
#include "modules/Maps.h"
|
2011-10-27 23:35:42 -06:00
|
|
|
|
2012-01-07 22:04:31 -07:00
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "df/item_actual.h"
|
|
|
|
#include "df/unit.h"
|
2012-01-19 03:30:22 -07:00
|
|
|
#include "df/unit_spatter.h"
|
2012-01-07 22:04:31 -07:00
|
|
|
#include "df/matter_state.h"
|
|
|
|
#include "df/cursor.h"
|
2012-01-11 07:58:26 -07:00
|
|
|
#include "df/builtin_mats.h"
|
2012-01-11 09:49:42 -07:00
|
|
|
#include "df/contaminant.h"
|
2011-10-27 23:35:42 -06:00
|
|
|
|
2011-10-27 20:40:00 -06:00
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
2012-01-07 22:04:31 -07:00
|
|
|
using namespace DFHack;
|
2012-01-19 20:44:17 -07:00
|
|
|
using namespace DFHack::Simple;
|
2012-01-21 17:31:15 -07:00
|
|
|
using namespace df::enums;
|
2011-10-27 20:40:00 -06:00
|
|
|
|
2012-01-07 22:04:31 -07:00
|
|
|
using df::global::world;
|
|
|
|
using df::global::cursor;
|
2011-10-27 20:40:00 -06:00
|
|
|
|
|
|
|
command_result cleanmap (Core * c, bool snow, bool mud)
|
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
// Invoked from clean(), already suspended
|
|
|
|
int num_blocks = 0, blocks_total = world->map.map_blocks.size();
|
|
|
|
for (int i = 0; i < blocks_total; i++)
|
2011-10-27 20:40:00 -06:00
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
df::map_block *block = world->map.map_blocks[i];
|
|
|
|
bool cleaned = false;
|
|
|
|
for(int x = 0; x < 16; x++)
|
2011-10-27 20:40:00 -06:00
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
for(int y = 0; y < 16; y++)
|
2011-10-27 20:40:00 -06:00
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
block->occupancy[x][y].bits.arrow_color = 0;
|
|
|
|
block->occupancy[x][y].bits.arrow_variant = 0;
|
2011-10-27 20:40:00 -06:00
|
|
|
}
|
|
|
|
}
|
2012-01-07 22:04:31 -07:00
|
|
|
for (int j = 0; j < block->block_events.size(); j++)
|
|
|
|
{
|
|
|
|
df::block_square_event *evt = block->block_events[j];
|
2012-01-21 17:31:15 -07:00
|
|
|
if (evt->getType() != block_square_event_type::material_spatter)
|
2012-01-07 22:04:31 -07:00
|
|
|
continue;
|
|
|
|
// type verified - recast to subclass
|
|
|
|
df::block_square_event_material_spatterst *spatter = (df::block_square_event_material_spatterst *)evt;
|
|
|
|
|
|
|
|
// filter snow
|
|
|
|
if(!snow
|
2012-01-21 17:31:15 -07:00
|
|
|
&& spatter->mat_type == builtin_mats::WATER
|
|
|
|
&& spatter->mat_state == matter_state::Powder)
|
2012-01-07 22:04:31 -07:00
|
|
|
continue;
|
|
|
|
// filter mud
|
|
|
|
if(!mud
|
2012-01-21 17:31:15 -07:00
|
|
|
&& spatter->mat_type == builtin_mats::MUD
|
|
|
|
&& spatter->mat_state == matter_state::Solid)
|
2012-01-07 22:04:31 -07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
delete evt;
|
|
|
|
block->block_events.erase(block->block_events.begin() + j);
|
|
|
|
j--;
|
|
|
|
cleaned = true;
|
|
|
|
}
|
|
|
|
num_blocks += cleaned;
|
2011-10-27 20:40:00 -06:00
|
|
|
}
|
2012-01-07 22:04:31 -07:00
|
|
|
|
2011-10-27 20:40:00 -06:00
|
|
|
if(num_blocks)
|
|
|
|
c->con.print("Cleaned %d of %d map blocks.\n", num_blocks, blocks_total);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result cleanitems (Core * c)
|
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
// Invoked from clean(), already suspended
|
2011-10-27 20:40:00 -06:00
|
|
|
int cleaned_items = 0, cleaned_total = 0;
|
2012-01-07 22:04:31 -07:00
|
|
|
for (int i = 0; i < world->items.all.size(); i++)
|
2011-10-27 20:40:00 -06:00
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
// currently, all item classes extend item_actual, so this should be safe
|
|
|
|
df::item_actual *item = (df::item_actual *)world->items.all[i];
|
|
|
|
if (item->contaminants && item->contaminants->size())
|
2011-10-27 20:40:00 -06:00
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
for (int j = 0; j < item->contaminants->size(); j++)
|
|
|
|
delete item->contaminants->at(j);
|
2011-10-27 20:40:00 -06:00
|
|
|
cleaned_items++;
|
2012-01-07 22:04:31 -07:00
|
|
|
cleaned_total += item->contaminants->size();
|
|
|
|
item->contaminants->clear();
|
2011-10-27 20:40:00 -06:00
|
|
|
}
|
|
|
|
}
|
2012-01-07 22:04:31 -07:00
|
|
|
if (cleaned_total)
|
2011-10-27 20:40:00 -06:00
|
|
|
c->con.print("Removed %d contaminants from %d items.\n", cleaned_total, cleaned_items);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result cleanunits (Core * c)
|
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
// Invoked from clean(), already suspended
|
|
|
|
int num_units = world->units.all.size();
|
2011-10-27 20:40:00 -06:00
|
|
|
int cleaned_units = 0, cleaned_total = 0;
|
2012-01-07 22:04:31 -07:00
|
|
|
for (int i = 0; i < num_units; i++)
|
2011-10-27 20:40:00 -06:00
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
df::unit *unit = world->units.all[i];
|
|
|
|
if (unit->body.spatters.size())
|
2011-10-27 20:40:00 -06:00
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
for (int j = 0; j < unit->body.spatters.size(); j++)
|
|
|
|
delete unit->body.spatters[j];
|
2011-10-27 20:40:00 -06:00
|
|
|
cleaned_units++;
|
2012-01-07 22:04:31 -07:00
|
|
|
cleaned_total += unit->body.spatters.size();
|
|
|
|
unit->body.spatters.clear();
|
2011-10-27 20:40:00 -06:00
|
|
|
}
|
|
|
|
}
|
2012-01-07 22:04:31 -07:00
|
|
|
if (cleaned_total)
|
2011-10-27 20:40:00 -06:00
|
|
|
c->con.print("Removed %d contaminants from %d creatures.\n", cleaned_total, cleaned_units);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-27 23:35:42 -06:00
|
|
|
DFhackCExport command_result spotclean (Core * c, vector <string> & parameters)
|
|
|
|
{
|
2011-12-31 02:25:46 -07:00
|
|
|
// HOTKEY COMMAND: CORE ALREADY SUSPENDED
|
2012-01-07 22:04:31 -07:00
|
|
|
if (cursor->x == -30000)
|
2011-10-27 23:35:42 -06:00
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
c->con.printerr("The cursor is not active.\n");
|
2012-01-21 17:31:15 -07:00
|
|
|
return CR_WRONG_USAGE;
|
2011-10-27 23:35:42 -06:00
|
|
|
}
|
2012-01-24 04:36:30 -07:00
|
|
|
if (!Maps::IsValid())
|
|
|
|
{
|
|
|
|
c->con.printerr("Map is not available.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = Maps::getBlockAbs(cursor->x, cursor->y, cursor->z);
|
2012-01-07 22:04:31 -07:00
|
|
|
if (block == NULL)
|
2011-10-27 23:35:42 -06:00
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
c->con.printerr("Invalid map block selected!\n");
|
2011-10-27 23:35:42 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-01-07 22:04:31 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < block->block_events.size(); i++)
|
2011-10-27 23:35:42 -06:00
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
df::block_square_event *evt = block->block_events[i];
|
2012-01-21 17:31:15 -07:00
|
|
|
if (evt->getType() != block_square_event_type::material_spatter)
|
2012-01-07 22:04:31 -07:00
|
|
|
continue;
|
|
|
|
// type verified - recast to subclass
|
|
|
|
df::block_square_event_material_spatterst *spatter = (df::block_square_event_material_spatterst *)evt;
|
|
|
|
spatter->amount[cursor->x % 16][cursor->y % 16] = 0;
|
2011-10-27 23:35:42 -06:00
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-27 20:40:00 -06:00
|
|
|
DFhackCExport command_result clean (Core * c, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
bool help = false;
|
|
|
|
bool map = false;
|
|
|
|
bool snow = false;
|
|
|
|
bool mud = false;
|
|
|
|
bool units = false;
|
|
|
|
bool items = false;
|
|
|
|
for(int i = 0; i < parameters.size();i++)
|
|
|
|
{
|
|
|
|
if(parameters[i] == "map")
|
|
|
|
map = true;
|
|
|
|
else if(parameters[i] == "units")
|
|
|
|
units = true;
|
|
|
|
else if(parameters[i] == "items")
|
|
|
|
items = true;
|
|
|
|
else if(parameters[i] == "all")
|
|
|
|
{
|
|
|
|
map = true;
|
|
|
|
items = true;
|
|
|
|
units = true;
|
|
|
|
}
|
|
|
|
if(parameters[i] == "snow")
|
|
|
|
snow = true;
|
|
|
|
else if(parameters[i] == "mud")
|
|
|
|
mud = true;
|
|
|
|
else if(parameters[i] == "help" ||parameters[i] == "?")
|
|
|
|
{
|
|
|
|
help = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!map && !units && !items)
|
|
|
|
help = true;
|
|
|
|
if(help)
|
|
|
|
{
|
|
|
|
c->con.print("Removes contaminants from map tiles, items and creatures.\n"
|
2012-01-07 22:04:31 -07:00
|
|
|
"Options:\n"
|
|
|
|
"map - clean the map tiles\n"
|
|
|
|
"items - clean all items\n"
|
|
|
|
"units - clean all creatures\n"
|
|
|
|
"all - clean everything.\n"
|
|
|
|
"More options for 'map':\n"
|
|
|
|
"snow - also remove snow\n"
|
|
|
|
"mud - also remove mud\n"
|
|
|
|
"Example: clean all mud snow\n"
|
2012-01-11 10:04:06 -07:00
|
|
|
"This removes all spatter, including mud and snow from map tiles.\n"
|
2012-01-07 22:04:31 -07:00
|
|
|
);
|
2011-10-27 20:40:00 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-01-21 17:31:15 -07:00
|
|
|
CoreSuspender suspend(c);
|
2011-10-27 20:40:00 -06:00
|
|
|
if(map)
|
|
|
|
cleanmap(c,snow,mud);
|
|
|
|
if(units)
|
|
|
|
cleanunits(c);
|
|
|
|
if(items)
|
|
|
|
cleanitems(c);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-01-07 22:04:31 -07:00
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
return "cleaners";
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.clear();
|
|
|
|
commands.push_back(PluginCommand("clean","Removes contaminants from map tiles, items and creatures.",clean));
|
|
|
|
commands.push_back(PluginCommand("spotclean","Cleans map tile under cursor.",spotclean,cursor_hotkey));
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
2012-01-15 13:54:14 -07:00
|
|
|
}
|