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