From b3fd50e2a858596862f8cf761bdeb7cad3dd24fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 26 May 2011 05:48:56 +0200 Subject: [PATCH] Fix cleanmap. Now it treats mud and snow properly. --- tools/supported/cleanmap.cpp | 48 +++++++++++------------------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/tools/supported/cleanmap.cpp b/tools/supported/cleanmap.cpp index 4557eaea1..fa07a225e 100644 --- a/tools/supported/cleanmap.cpp +++ b/tools/supported/cleanmap.cpp @@ -10,6 +10,10 @@ using namespace std; #include #include +// magic globals. +const uint32_t water_idx = 6; +const uint32_t mud_idx = 12; + int main (int argc, char** argv) { bool temporary_terminal = TemporaryTerminal(); @@ -40,31 +44,6 @@ int main (int argc, char** argv) return 1; } DFHack::Maps *Mapz = DF->getMaps(); - DFHack::Materials *Mats = DF->getMaterials(); - uint32_t water_idx = (uint32_t) int32_t(-1); - uint32_t mud_idx = (uint32_t) int32_t(-1); - if(Mats->ReadOthers()) - { - vector & main_mats = Mats->other; - for(size_t i = 0; i < main_mats.size();i++) - { - if(strcmp(main_mats[i].rawname, "MUD")) - { - mud_idx = i; - } - else if(strcmp(main_mats[i].rawname, "WATER")) - { - water_idx = i; - } - } - } - else - { - cerr << "Can't init materials." << endl; - if(temporary_terminal) - cin.ignore(); - return 1; - } // init the map if(!Mapz->Start()) @@ -97,17 +76,20 @@ int main (int argc, char** argv) occ[i][j].bits.broken_arrows_variant = 0; } Mapz->WriteOccupancy(x,y,z,&occ); - // TODO: make this actually destroy the objects/remove them from the vector? for(uint32_t i = 0; i < splatter.size(); i++) { DFHack::t_spattervein & vein = splatter[i]; - // filter *solid* away water and mud - if(vein.mat1 != mud_idx && vein.mat2 != water_idx || vein.matter_state != DFHack::state_solid) - { - uint32_t addr = vein.address_of; - uint32_t offset = offsetof(DFHack::t_spattervein, intensity); - DF->WriteRaw(addr + offset,sizeof(zeroes),(uint8_t *) zeroes); - } + // 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); } } }