Merged the spatter clean plugins into one

develop
Petr Mrázek 2011-10-28 04:40:00 +02:00
parent 61be3413e3
commit fc6cb72f33
5 changed files with 213 additions and 269 deletions

@ -32,9 +32,7 @@ DFHACK_PLUGIN(getplants getplants.cpp)
DFHACK_PLUGIN(plants plants.cpp) DFHACK_PLUGIN(plants plants.cpp)
DFHACK_PLUGIN(fastdwarf fastdwarf.cpp) DFHACK_PLUGIN(fastdwarf fastdwarf.cpp)
DFHACK_PLUGIN(prospector prospector.cpp) DFHACK_PLUGIN(prospector prospector.cpp)
DFHACK_PLUGIN(cleanmap cleanmap.cpp) DFHACK_PLUGIN(cleaners cleaners.cpp)
DFHACK_PLUGIN(cleanitems cleanitems.cpp)
DFHACK_PLUGIN(cleanunits cleanunits.cpp)
DFHACK_PLUGIN(weather weather.cpp) DFHACK_PLUGIN(weather weather.cpp)
DFHACK_PLUGIN(vdig vdig.cpp) DFHACK_PLUGIN(vdig vdig.cpp)
DFHACK_PLUGIN(colonies colonies.cpp) DFHACK_PLUGIN(colonies colonies.cpp)

@ -0,0 +1,212 @@
#include <dfhack/Core.h>
#include <dfhack/Console.h>
#include <dfhack/Export.h>
#include <dfhack/PluginManager.h>
#include <dfhack/modules/Maps.h>
#include <dfhack/modules/Items.h>
#include <dfhack/modules/Creatures.h>
#include <vector>
#include <string>
#include <string.h>
using std::vector;
using std::string;
using namespace DFHack;
DFhackCExport command_result clean (Core * c, vector <string> & parameters);
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));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}
command_result cleanmap (Core * c, bool snow, bool mud)
{
const uint32_t water_idx = 6;
const uint32_t mud_idx = 12;
vector<DFHack::t_spattervein *> splatter;
DFHack::Maps *Mapz = c->getMaps();
// init the map
if(!Mapz->Start())
{
c->con << "Can't init map." << std::endl;
c->Resume();
return CR_FAILURE;
}
uint32_t x_max,y_max,z_max;
Mapz->getSize(x_max,y_max,z_max);
int num_blocks = 0;
int blocks_total = 0;
// walk the map
for(uint32_t x = 0; x< x_max;x++)
{
for(uint32_t y = 0; y< y_max;y++)
{
for(uint32_t z = 0; z< z_max;z++)
{
df_block * block = Mapz->getBlock(x,y,z);
if(block)
{
blocks_total ++;
bool cleaned = false;
Mapz->SortBlockEvents(x,y,z,0,0,&splatter);
for(int i = 0; i < 16; i++)
for(int j = 0; j < 16; j++)
{
block->occupancy[i][j].bits.arrow_color = 0;
block->occupancy[i][j].bits.broken_arrows_variant = 0;
}
for(uint32_t i = 0; i < splatter.size(); i++)
{
DFHack::t_spattervein * vein = splatter[i];
// filter snow
if(!snow && vein->mat1 == water_idx && vein->matter_state == DFHack::state_powder)
continue;
// filter mud
if(!mud && vein->mat1 == mud_idx && vein->matter_state == DFHack::state_solid)
continue;
Mapz->RemoveBlockEvent(x,y,z,(t_virtual *) vein);
cleaned = true;
}
num_blocks += cleaned;
}
}
}
}
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)
{
DFHack::Items * Items = c->getItems();
vector <df_item*> p_items;
if(!Items->readItemVector(p_items))
{
c->con.printerr("Can't access the item vector.\n");
c->Resume();
return CR_FAILURE;
}
std::size_t numItems = p_items.size();
int cleaned_items = 0, cleaned_total = 0;
for (std::size_t i = 0; i < numItems; i++)
{
df_item * itm = p_items[i];
if(!itm->contaminants)
continue;
if (itm->contaminants->size())
{
cleaned_items++;
cleaned_total += itm->contaminants->size();
itm->contaminants->clear();
}
}
if(cleaned_total)
c->con.print("Removed %d contaminants from %d items.\n", cleaned_total, cleaned_items);
return CR_OK;
}
command_result cleanunits (Core * c)
{
DFHack::Creatures * Creatures = c->getCreatures();
uint32_t num_creatures;
if (!Creatures->Start(num_creatures))
{
c->con.printerr("Can't read unit list!\n");
c->Resume();
return CR_FAILURE;
}
int cleaned_units = 0, cleaned_total = 0;
for (std::size_t i = 0; i < num_creatures; i++)
{
df_creature *unit = Creatures->creatures->at(i);
int num = unit->contaminants.size();
if (num)
{
cleaned_units++;
cleaned_total += num;
unit->contaminants.clear();
}
}
if(cleaned_total)
c->con.print("Removed %d contaminants from %d creatures.\n", cleaned_total, cleaned_units);
return CR_OK;
}
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"
"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"
"This removes all spatter, including mud and snow from map tiles."
);
return CR_OK;
}
c->Suspend();
if(map)
cleanmap(c,snow,mud);
if(units)
cleanunits(c);
if(items)
cleanitems(c);
c->Resume();
return CR_OK;
}

@ -1,79 +0,0 @@
// Clean Items : Remove contaminants from all objects
#include <iostream>
#include <iomanip>
#include <sstream>
#include <climits>
#include <vector>
#include <set>
using namespace std;
#include <dfhack/Core.h>
#include <dfhack/Console.h>
#include <dfhack/Export.h>
#include <dfhack/PluginManager.h>
#include <vector>
#include <string>
#include <algorithm>
#include <dfhack/modules/Items.h>
using namespace DFHack;
DFhackCExport command_result df_cleanitems (Core * c, vector <string> & parameters);
DFhackCExport const char * plugin_name ( void )
{
return "cleanitems";
}
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("cleanitems", "Removes contaminants from items.", df_cleanitems));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}
DFhackCExport command_result df_cleanitems (Core * c, vector <string> & parameters)
{
if(parameters.size() > 0)
{
string & p = parameters[0];
if(p == "?" || p == "help")
{
c->con.print("This utility removes all contaminants from all objects in your fortress.\n");
return CR_OK;
}
}
c->Suspend();
DFHack::Items * Items = c->getItems();
vector <df_item*> p_items;
if(!Items->readItemVector(p_items))
{
c->con.printerr("Can't access the item vector.\n");
c->Resume();
return CR_FAILURE;
}
std::size_t numItems = p_items.size();
int cleaned_items = 0, cleaned_total = 0;
for (std::size_t i = 0; i < numItems; i++)
{
df_item * itm = p_items[i];
if(!itm->contaminants)
continue;
if (itm->contaminants->size())
{
cleaned_items++;
cleaned_total += itm->contaminants->size();
itm->contaminants->clear();
}
}
c->Resume();
c->con.print("Done. %d items cleaned of %d contaminants.\n", cleaned_items, cleaned_total);
return CR_OK;
}

@ -1,110 +0,0 @@
#include <dfhack/Core.h>
#include <dfhack/Console.h>
#include <dfhack/Export.h>
#include <dfhack/PluginManager.h>
#include <dfhack/modules/Maps.h>
#include <vector>
#include <string>
#include <string.h>
using std::vector;
using std::string;
using namespace DFHack;
DFhackCExport command_result cleanmap (Core * c, vector <string> & parameters);
DFhackCExport const char * plugin_name ( void )
{
return "cleanmap";
}
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("cleanmap","Cleans the map from various substances.",cleanmap));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}
DFhackCExport command_result cleanmap (Core * c, vector <string> & parameters)
{
const uint32_t water_idx = 6;
const uint32_t mud_idx = 12;
bool snow = false;
bool mud = false;
bool help = false;
for(int i = 0; i < parameters.size();i++)
{
if(parameters[i] == "snow")
snow = true;
else if(parameters[i] == "mud")
mud = true;
else if(parameters[i] == "help" ||parameters[i] == "?")
{
help = true;
}
}
if(help)
{
c->con.print("This command cleans the coverings from the map. Snow and mud are ignored by default.\n"
"Options:\n"
"snow - also remove snow\n"
"mud - also remove mud\n"
);
return CR_OK;
}
c->Suspend();
vector<DFHack::t_spattervein *> splatter;
DFHack::Maps *Mapz = c->getMaps();
// init the map
if(!Mapz->Start())
{
c->con << "Can't init map." << std::endl;
c->Resume();
return CR_FAILURE;
}
uint32_t x_max,y_max,z_max;
Mapz->getSize(x_max,y_max,z_max);
// walk the map
for(uint32_t x = 0; x< x_max;x++)
{
for(uint32_t y = 0; y< y_max;y++)
{
for(uint32_t z = 0; z< z_max;z++)
{
df_block * block = Mapz->getBlock(x,y,z);
if(block)
{
Mapz->SortBlockEvents(x,y,z,0,0,&splatter);
for(int i = 0; i < 16; i++)
for(int j = 0; j < 16; j++)
{
block->occupancy[i][j].bits.arrow_color = 0;
block->occupancy[i][j].bits.broken_arrows_variant = 0;
}
for(uint32_t i = 0; i < splatter.size(); i++)
{
DFHack::t_spattervein * vein = splatter[i];
// filter snow
if(!snow && vein->mat1 == water_idx && vein->matter_state == DFHack::state_powder)
continue;
// filter mud
if(!mud && vein->mat1 == mud_idx && vein->matter_state == DFHack::state_solid)
continue;
Mapz->RemoveBlockEvent(x,y,z,(t_virtual *) vein);
}
}
}
}
}
c->Resume();
return CR_OK;
}

@ -1,77 +0,0 @@
// Clean Units : Remove contaminants from all creatures
#include <iostream>
#include <iomanip>
#include <sstream>
#include <climits>
#include <vector>
#include <set>
using namespace std;
#include <dfhack/Core.h>
#include <dfhack/Console.h>
#include <dfhack/Export.h>
#include <dfhack/PluginManager.h>
#include <vector>
#include <string>
#include <algorithm>
#include <dfhack/modules/Creatures.h>
using namespace DFHack;
DFhackCExport command_result df_cleanunits (Core * c, vector <string> & parameters);
DFhackCExport const char * plugin_name ( void )
{
return "cleanunits";
}
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("cleanunits", "Removes contaminants from creatures.", df_cleanunits));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}
DFhackCExport command_result df_cleanunits (Core * c, vector <string> & parameters)
{
if(parameters.size() > 0)
{
string & p = parameters[0];
if(p == "?" || p == "help")
{
c->con.print("This utility removes all contaminants from all creatures in your fortress.\n");
return CR_OK;
}
}
c->Suspend();
DFHack::Creatures * Creatures = c->getCreatures();
uint32_t num_creatures;
if (!Creatures->Start(num_creatures))
{
c->con.printerr("Can't read unit list!\n");
c->Resume();
return CR_FAILURE;
}
int cleaned_units = 0, cleaned_total = 0;
for (std::size_t i = 0; i < num_creatures; i++)
{
df_creature *unit = Creatures->creatures->at(i);
int num = unit->contaminants.size();
if (num)
{
cleaned_units++;
cleaned_total += num;
unit->contaminants.clear();
}
}
c->Resume();
c->con.print("Done. %d creatures cleaned of %d contaminants.\n", cleaned_units, cleaned_total);
return CR_OK;
}