Update cleanmap to optionally also clean up item spatters such as leaves

develop
Quietust 2014-08-20 10:54:00 -05:00
parent deee486b81
commit 33f4f9fdcb
1 changed files with 29 additions and 16 deletions

@ -13,6 +13,7 @@
#include "df/builtin_mats.h"
#include "df/contaminant.h"
#include "df/plant.h"
#include "df/plant_spatter.h"
using std::vector;
using std::string;
@ -24,7 +25,7 @@ using df::global::cursor;
DFHACK_PLUGIN("cleaners");
command_result cleanmap (color_ostream &out, bool snow, bool mud)
command_result cleanmap (color_ostream &out, bool snow, bool mud, bool item_spatter)
{
// Invoked from clean(), already suspended
int num_blocks = 0, blocks_total = world->map.map_blocks.size();
@ -43,8 +44,8 @@ command_result cleanmap (color_ostream &out, bool snow, bool mud)
for (size_t j = 0; j < block->block_events.size(); j++)
{
df::block_square_event *evt = block->block_events[j];
if (evt->getType() != block_square_event_type::material_spatter)
continue;
if (evt->getType() == block_square_event_type::material_spatter)
{
// type verified - recast to subclass
df::block_square_event_material_spatterst *spatter = (df::block_square_event_material_spatterst *)evt;
@ -58,6 +59,14 @@ command_result cleanmap (color_ostream &out, bool snow, bool mud)
&& spatter->mat_type == builtin_mats::MUD
&& spatter->mat_state == (short)matter_state::Solid)
continue;
}
else if (evt->getType() == block_square_event_type::item_spatter)
{
if (!item_spatter)
continue;
}
else
continue;
delete evt;
block->block_events.erase(block->block_events.begin() + j);
@ -181,6 +190,7 @@ command_result clean (color_ostream &out, vector <string> & parameters)
bool map = false;
bool snow = false;
bool mud = false;
bool item_spatter = false;
bool units = false;
bool items = false;
bool plants = false;
@ -205,6 +215,8 @@ command_result clean (color_ostream &out, vector <string> & parameters)
snow = true;
else if(parameters[i] == "mud")
mud = true;
else if(parameters[i] == "item")
item_spatter = true;
else
return CR_WRONG_USAGE;
}
@ -214,7 +226,7 @@ command_result clean (color_ostream &out, vector <string> & parameters)
CoreSuspender suspend;
if(map)
cleanmap(out,snow,mud);
cleanmap(out,snow,mud,item_spatter);
if(units)
cleanunits(out);
if(items)
@ -239,8 +251,9 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <Plug
"More options for 'map':\n"
" snow - also remove snow\n"
" mud - also remove mud\n"
" item - also remove item spatters (e.g. leaves and flowers)\n"
"Example:\n"
" clean all mud snow\n"
" clean all mud snow item\n"
" Removes all spatter, including mud and snow from map tiles.\n"
));
commands.push_back(PluginCommand(