dfhack/tools/supported/cleanmap.cpp

85 lines
2.1 KiB
C++

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 <integers.h>
2009-09-13 18:02:46 -06:00
#include <vector>
2010-05-23 15:06:10 -06:00
#include <map>
2009-09-13 18:02:46 -06:00
using namespace std;
#include <DFTypes.h>
2010-05-23 15:06:10 -06:00
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFMemInfo.h>
#include <DFTypes.h>
#include <stddef.h>
#include <modules/Maps.h>
2009-09-13 18:02:46 -06:00
int main (void)
{
uint32_t x_max,y_max,z_max;
uint32_t num_blocks = 0;
uint32_t bytes_read = 0;
vector<DFHack::t_spattervein> splatter;
2009-09-13 18:02:46 -06:00
2010-05-23 15:06:10 -06:00
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF = DFMgr.getSingleContext();
try
2009-09-13 18:02:46 -06:00
{
2010-05-23 15:06:10 -06:00
DF->Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
2009-09-13 18:02:46 -06:00
return 1;
}
2010-05-23 15:06:10 -06:00
DFHack::Maps *Mapz = DF->getMaps();
// init the map
if(!Mapz->Start())
{
cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
Mapz->getSize(x_max,y_max,z_max);
uint8_t zeroes [16][16] = {0};
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++)
{
if(Mapz->isValidBlock(x,y,z))
2009-09-13 18:02:46 -06:00
{
Mapz->ReadVeins(x,y,z,0,0,&splatter);
for(uint32_t i = 0; i < splatter.size(); i++)
{
DFHack::t_spattervein & vein = splatter[i];
2010-04-18 21:00:32 -06:00
if(vein.mat1 != 0xC)
{
uint32_t addr = vein.address_of;
uint32_t offset = offsetof(DFHack::t_spattervein, intensity);
2010-05-23 15:06:10 -06:00
DF->WriteRaw(addr + offset,sizeof(zeroes),(uint8_t *) zeroes);
}
}
2009-09-13 18:02:46 -06:00
}
}
}
}
2010-05-23 15:06:10 -06:00
DF->Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
2009-09-13 18:02:46 -06:00
return 0;
}