From ea9a6deed4ab4099a8f5bf57ba7cb5111c45c002 Mon Sep 17 00:00:00 2001 From: Matthew Cline Date: Sun, 10 Jul 2011 17:29:34 -0700 Subject: [PATCH] playground/blockflags: toggle block flag bits Invert/toggle all block flag bits, to investigate what they do. Strangely, they don't seem to do anyting. --- tools/playground/CMakeLists.txt | 5 +++ tools/playground/blockflags.cpp | 66 +++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tools/playground/blockflags.cpp diff --git a/tools/playground/CMakeLists.txt b/tools/playground/CMakeLists.txt index e8c92fe4b..dba69d21c 100644 --- a/tools/playground/CMakeLists.txt +++ b/tools/playground/CMakeLists.txt @@ -85,6 +85,11 @@ DFHACK_TOOL(dfdigpattern digpattern.cpp) DFHACK_TOOL(dffixbug-3708 fix-3708.cpp) +# blockflags +# Author: matthew cline +# Invert/toggle all block flags, to see what they do. +DFHACK_TOOL(dfblockflags blockflags.cpp) + # this needs the C bindings IF(BUILD_DFHACK_C_BINDINGS) # The C bindings won't be real C bindings until this compiles. diff --git a/tools/playground/blockflags.cpp b/tools/playground/blockflags.cpp new file mode 100644 index 000000000..f46f66407 --- /dev/null +++ b/tools/playground/blockflags.cpp @@ -0,0 +1,66 @@ +// Invert/toggle all block flags, to see what they do. +// Seems like they don't do anything... + +#include +#include + +using namespace std; +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + bool temporary_terminal = TemporaryTerminal(); + + uint32_t x_max = 0, y_max = 0, z_max = 0; + DFHack::ContextManager manager("Memory.xml"); + + DFHack::Context *context = manager.getSingleContext(); + if (!context->Attach()) + { + std::cerr << "Unable to attach to DF!" << std::endl; + if(temporary_terminal) + std::cin.ignore(); + return 1; + } + + DFHack::Maps *maps = context->getMaps(); + if (!maps->Start()) + { + std::cerr << "Cannot get map info!" << std::endl; + context->Detach(); + if(temporary_terminal) + std::cin.ignore(); + return 1; + } + maps->getSize(x_max, y_max, z_max); + MapExtras::MapCache map(maps); + + for(uint32_t z = 0; z < z_max; z++) + { + for(uint32_t b_y = 0; b_y < y_max; b_y++) + { + for(uint32_t b_x = 0; b_x < x_max; b_x++) + { + // Get the map block + DFHack::DFCoord blockCoord(b_x, b_y); + MapExtras::Block *b = map.BlockAt(DFHack::DFCoord(b_x, b_y, z)); + if (!b || !b->valid) + { + continue; + } + + DFHack::t_blockflags flags = b->BlockFlags(); + flags.whole = flags.whole ^ 0xFFFFFFFF; + b->setBlockFlags(flags); + b->Write(); + } // block x + } // block y + } // z + + maps->Finish(); + context->Detach(); + return 0; +}