2009-09-13 18:02:46 -06:00
|
|
|
// Map cleaner. Removes all the snow, mud spills, blood and vomit from map tiles.
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
2010-05-23 15:06:10 -06:00
|
|
|
#include <map>
|
2010-05-25 22:48:23 -06:00
|
|
|
#include <stddef.h>
|
2011-05-25 18:14:42 -06:00
|
|
|
#include <cstring>
|
2009-09-13 18:02:46 -06:00
|
|
|
using namespace std;
|
|
|
|
|
2010-05-25 22:48:23 -06:00
|
|
|
#include <DFHack.h>
|
2011-05-17 00:36:38 -06:00
|
|
|
#include <dfhack/extra/termutil.h>
|
2009-09-13 18:02:46 -06:00
|
|
|
|
2011-05-25 21:48:56 -06:00
|
|
|
// magic globals.
|
|
|
|
const uint32_t water_idx = 6;
|
|
|
|
const uint32_t mud_idx = 12;
|
|
|
|
|
2010-11-10 18:09:43 -07:00
|
|
|
int main (int argc, char** argv)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2011-05-14 22:10:47 -06:00
|
|
|
bool temporary_terminal = TemporaryTerminal();
|
2010-11-10 18:09:43 -07:00
|
|
|
bool quiet = false;
|
|
|
|
for(int i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
string test = argv[i];
|
|
|
|
if(test == "-q")
|
|
|
|
{
|
|
|
|
quiet = true;
|
|
|
|
}
|
2010-11-10 18:32:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t x_max,y_max,z_max;
|
2010-04-09 18:12:45 -06:00
|
|
|
vector<DFHack::t_spattervein> splatter;
|
2010-11-10 18:32:33 -07:00
|
|
|
|
2010-05-23 15:06:10 -06:00
|
|
|
DFHack::ContextManager DFMgr("Memory.xml");
|
|
|
|
DFHack::Context *DF = DFMgr.getSingleContext();
|
2010-03-26 06:01:46 -06:00
|
|
|
try
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->Attach();
|
2010-03-26 06:01:46 -06:00
|
|
|
}
|
|
|
|
catch (exception& e)
|
|
|
|
{
|
|
|
|
cerr << e.what() << endl;
|
2011-05-14 22:10:47 -06:00
|
|
|
if(temporary_terminal)
|
2010-03-26 06:01:46 -06:00
|
|
|
cin.ignore();
|
2009-09-13 18:02:46 -06:00
|
|
|
return 1;
|
|
|
|
}
|
2010-05-23 15:06:10 -06:00
|
|
|
DFHack::Maps *Mapz = DF->getMaps();
|
2010-11-10 18:32:33 -07:00
|
|
|
|
2010-03-26 06:01:46 -06:00
|
|
|
// init the map
|
2010-04-09 18:12:45 -06:00
|
|
|
if(!Mapz->Start())
|
2010-03-26 06:01:46 -06:00
|
|
|
{
|
|
|
|
cerr << "Can't init map." << endl;
|
2011-05-14 22:10:47 -06:00
|
|
|
if(temporary_terminal)
|
2010-03-26 06:01:46 -06:00
|
|
|
cin.ignore();
|
|
|
|
return 1;
|
|
|
|
}
|
2010-11-10 18:32:33 -07:00
|
|
|
|
2010-04-09 18:12:45 -06:00
|
|
|
Mapz->getSize(x_max,y_max,z_max);
|
2010-11-10 18:32:33 -07:00
|
|
|
|
2011-03-01 15:18:55 -07:00
|
|
|
uint8_t zeroes [16][16] = {{0}};
|
2011-02-21 00:26:40 -07:00
|
|
|
DFHack::occupancies40d occ;
|
2009-09-13 18:02:46 -06:00
|
|
|
// 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++)
|
|
|
|
{
|
2010-04-09 18:12:45 -06:00
|
|
|
if(Mapz->isValidBlock(x,y,z))
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-04-10 18:08:21 -06:00
|
|
|
Mapz->ReadVeins(x,y,z,0,0,&splatter);
|
2011-02-21 00:26:40 -07:00
|
|
|
Mapz->ReadOccupancy(x,y,z,&occ);
|
|
|
|
for(int i = 0; i < 16; i++)
|
|
|
|
for(int j = 0; j < 16; j++)
|
|
|
|
{
|
2011-03-19 13:17:04 -06:00
|
|
|
occ[i][j].bits.arrow_color = 0;
|
|
|
|
occ[i][j].bits.broken_arrows_variant = 0;
|
2011-02-21 00:26:40 -07:00
|
|
|
}
|
2011-03-19 13:17:04 -06:00
|
|
|
Mapz->WriteOccupancy(x,y,z,&occ);
|
2010-04-09 18:12:45 -06:00
|
|
|
for(uint32_t i = 0; i < splatter.size(); i++)
|
|
|
|
{
|
|
|
|
DFHack::t_spattervein & vein = splatter[i];
|
2011-05-25 21:48:56 -06:00
|
|
|
// filter snow
|
|
|
|
if(vein.mat1 == water_idx && vein.matter_state == DFHack::state_powder)
|
|
|
|
continue;
|
|
|
|
// filter mud
|
|
|
|
if(vein.mat1 == mud_idx && vein.matter_state == DFHack::state_solid)
|
|
|
|
continue;
|
|
|
|
uint32_t addr = vein.address_of;
|
|
|
|
uint32_t offset = offsetof(DFHack::t_spattervein, intensity);
|
|
|
|
// TODO: make this actually destroy the objects/remove them from the vector?
|
|
|
|
// still, this is safe.
|
|
|
|
DF->WriteRaw(addr + offset,sizeof(zeroes),(uint8_t *) zeroes);
|
2010-04-09 18:12:45 -06:00
|
|
|
}
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->Detach();
|
2011-05-14 22:10:47 -06:00
|
|
|
if (!quiet && temporary_terminal)
|
|
|
|
{
|
|
|
|
cout << "Done. Press any key to continue" << endl;
|
|
|
|
cin.ignore();
|
|
|
|
}
|
2009-09-13 18:02:46 -06:00
|
|
|
return 0;
|
2009-12-13 14:03:19 -07:00
|
|
|
}
|