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"
|
2012-02-20 03:42:40 -07:00
|
|
|
#include "df/global_objects.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"
|
2013-01-02 09:26:30 -07:00
|
|
|
#include "df/plant.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-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
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("cleaners");
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result cleanmap (color_ostream &out, bool snow, bool mud)
|
2011-10-27 20:40:00 -06:00
|
|
|
{
|
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-31 09:55:38 -07:00
|
|
|
for (size_t j = 0; j < block->block_events.size(); j++)
|
2012-01-07 22:04:31 -07:00
|
|
|
{
|
|
|
|
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
|
2012-09-10 07:19:21 -06:00
|
|
|
&& spatter->mat_state == (short)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
|
2012-09-10 07:19:21 -06:00
|
|
|
&& spatter->mat_state == (short)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)
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Cleaned %d of %d map blocks.\n", num_blocks, blocks_total);
|
2011-10-27 20:40:00 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result cleanitems (color_ostream &out)
|
2011-10-27 20:40:00 -06:00
|
|
|
{
|
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-31 09:55:38 -07:00
|
|
|
for (size_t 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-09-17 11:15:51 -06:00
|
|
|
std::vector<df::contaminant*> saved;
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t j = 0; j < item->contaminants->size(); j++)
|
2012-09-17 11:15:51 -06:00
|
|
|
{
|
|
|
|
auto obj = (*item->contaminants)[j];
|
|
|
|
if (obj->flags.whole & 0x8000) // DFHack-generated contaminant
|
|
|
|
saved.push_back(obj);
|
|
|
|
else
|
|
|
|
delete obj;
|
|
|
|
}
|
2011-10-27 20:40:00 -06:00
|
|
|
cleaned_items++;
|
2012-09-17 11:15:51 -06:00
|
|
|
cleaned_total += item->contaminants->size() - saved.size();
|
|
|
|
item->contaminants->swap(saved);
|
2011-10-27 20:40:00 -06:00
|
|
|
}
|
|
|
|
}
|
2012-01-07 22:04:31 -07:00
|
|
|
if (cleaned_total)
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Removed %d contaminants from %d items.\n", cleaned_total, cleaned_items);
|
2011-10-27 20:40:00 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result cleanunits (color_ostream &out)
|
2011-10-27 20:40:00 -06:00
|
|
|
{
|
2012-01-07 22:04:31 -07:00
|
|
|
// Invoked from clean(), already suspended
|
2011-10-27 20:40:00 -06:00
|
|
|
int cleaned_units = 0, cleaned_total = 0;
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t i = 0; i < world->units.all.size(); 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-31 09:55:38 -07:00
|
|
|
for (size_t j = 0; j < unit->body.spatters.size(); j++)
|
2012-01-07 22:04:31 -07:00
|
|
|
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)
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Removed %d contaminants from %d creatures.\n", cleaned_total, cleaned_units);
|
2011-10-27 20:40:00 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-18 18:21:40 -06:00
|
|
|
command_result cleanplants (color_ostream &out)
|
|
|
|
{
|
|
|
|
// Invoked from clean(), already suspended
|
|
|
|
int cleaned_plants = 0, cleaned_total = 0;
|
|
|
|
for (size_t i = 0; i < world->plants.all.size(); i++)
|
|
|
|
{
|
|
|
|
df::plant *plant = world->plants.all[i];
|
|
|
|
|
|
|
|
if (plant->contaminants.size())
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < plant->contaminants.size(); j++)
|
|
|
|
delete plant->contaminants[j];
|
|
|
|
cleaned_plants++;
|
|
|
|
cleaned_total += plant->contaminants.size();
|
|
|
|
plant->contaminants.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cleaned_total)
|
|
|
|
out.print("Removed %d contaminants from %d plants.\n", cleaned_total, cleaned_plants);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result spotclean (color_ostream &out, vector <string> & parameters)
|
2011-10-27 23:35:42 -06:00
|
|
|
{
|
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-03-10 04:55:42 -07:00
|
|
|
out.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())
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Map is not available.\n");
|
2012-01-24 04:36:30 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-04-11 02:01:27 -06:00
|
|
|
df::map_block *block = Maps::getTileBlock(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-03-10 04:55:42 -07:00
|
|
|
out.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
|
|
|
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t 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;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result clean (color_ostream &out, vector <string> & parameters)
|
2011-10-27 20:40:00 -06:00
|
|
|
{
|
|
|
|
bool map = false;
|
|
|
|
bool snow = false;
|
|
|
|
bool mud = false;
|
|
|
|
bool units = false;
|
|
|
|
bool items = false;
|
2012-08-18 18:21:40 -06:00
|
|
|
bool plants = false;
|
2012-01-31 09:55:38 -07:00
|
|
|
for(size_t i = 0; i < parameters.size();i++)
|
2011-10-27 20:40:00 -06:00
|
|
|
{
|
|
|
|
if(parameters[i] == "map")
|
|
|
|
map = true;
|
|
|
|
else if(parameters[i] == "units")
|
|
|
|
units = true;
|
|
|
|
else if(parameters[i] == "items")
|
|
|
|
items = true;
|
2012-08-18 18:21:40 -06:00
|
|
|
else if(parameters[i] == "plants")
|
|
|
|
plants = true;
|
2011-10-27 20:40:00 -06:00
|
|
|
else if(parameters[i] == "all")
|
|
|
|
{
|
|
|
|
map = true;
|
|
|
|
items = true;
|
|
|
|
units = true;
|
2012-08-18 18:21:40 -06:00
|
|
|
plants = true;
|
2011-10-27 20:40:00 -06:00
|
|
|
}
|
2012-01-28 05:03:56 -07:00
|
|
|
else if(parameters[i] == "snow")
|
2011-10-27 20:40:00 -06:00
|
|
|
snow = true;
|
|
|
|
else if(parameters[i] == "mud")
|
|
|
|
mud = true;
|
2012-01-28 05:03:56 -07:00
|
|
|
else
|
|
|
|
return CR_WRONG_USAGE;
|
2011-10-27 20:40:00 -06:00
|
|
|
}
|
2012-08-18 18:21:40 -06:00
|
|
|
if(!map && !units && !items && !plants)
|
2012-01-28 05:03:56 -07:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
CoreSuspender suspend;
|
|
|
|
|
2011-10-27 20:40:00 -06:00
|
|
|
if(map)
|
2012-03-10 04:55:42 -07:00
|
|
|
cleanmap(out,snow,mud);
|
2011-10-27 20:40:00 -06:00
|
|
|
if(units)
|
2012-03-10 04:55:42 -07:00
|
|
|
cleanunits(out);
|
2011-10-27 20:40:00 -06:00
|
|
|
if(items)
|
2012-03-10 04:55:42 -07:00
|
|
|
cleanitems(out);
|
2012-08-18 18:21:40 -06:00
|
|
|
if(plants)
|
|
|
|
cleanplants(out);
|
2011-10-27 20:40:00 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-01-07 22:04:31 -07:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
2012-01-07 22:04:31 -07:00
|
|
|
{
|
2012-01-28 05:03:56 -07:00
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"clean","Removes contaminants from map tiles, items and creatures.",
|
|
|
|
clean, false,
|
|
|
|
" Removes contaminants from map tiles, items and creatures.\n"
|
|
|
|
"Options:\n"
|
|
|
|
" map - clean the map tiles\n"
|
|
|
|
" items - clean all items\n"
|
|
|
|
" units - clean all creatures\n"
|
2012-08-18 18:21:40 -06:00
|
|
|
" plants - clean all plants\n"
|
2012-01-28 05:03:56 -07:00
|
|
|
" all - clean everything.\n"
|
|
|
|
"More options for 'map':\n"
|
|
|
|
" snow - also remove snow\n"
|
|
|
|
" mud - also remove mud\n"
|
|
|
|
"Example:\n"
|
|
|
|
" clean all mud snow\n"
|
|
|
|
" Removes all spatter, including mud and snow from map tiles.\n"
|
|
|
|
));
|
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"spotclean","Cleans map tile under cursor.",
|
2012-03-03 06:38:24 -07:00
|
|
|
spotclean,Gui::cursor_hotkey
|
2012-01-28 05:03:56 -07:00
|
|
|
));
|
2012-01-07 22:04:31 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2012-01-07 22:04:31 -07:00
|
|
|
{
|
|
|
|
return CR_OK;
|
2012-01-15 13:54:14 -07:00
|
|
|
}
|