From 819327348b3c8f3274de22c52972c4f5d46a8486 Mon Sep 17 00:00:00 2001 From: Chris Dombroski Date: Wed, 7 Jan 2015 16:27:48 -0500 Subject: [PATCH] Blueprint plugin basic structure It should be able to load and make empty blueprint files. --- plugins/CMakeLists.txt | 1 + plugins/blueprint.cpp | 172 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+) create mode 100644 plugins/blueprint.cpp diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index b68fe61bc..f58c0182d 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -91,6 +91,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(automaterial automaterial.cpp) DFHACK_PLUGIN(automelt automelt.cpp) DFHACK_PLUGIN(autotrade autotrade.cpp) + DFHACK_PLUGIN(blueprint blueprint.cpp) DFHACK_PLUGIN(burrows burrows.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(building-hacks building-hacks.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(buildingplan buildingplan-lib.cpp buildingplan.cpp) diff --git a/plugins/blueprint.cpp b/plugins/blueprint.cpp new file mode 100644 index 000000000..987d6d0d8 --- /dev/null +++ b/plugins/blueprint.cpp @@ -0,0 +1,172 @@ +//Blueprint +//By cdombroski +//Translates a region of tiles specified by the cursor and arguments/prompts into a series of blueprint files suitable for digfort/buildingplan/quickfort + +#include +#include + +#include "modules/Gui.h" +#include "modules/MapCache.h" + +using std::string; +using std::endl; +using std::vector; +using std::ofstream; +using namespace DFHack; + +DFHACK_PLUGIN("blueprint"); + +#define swap(x, y)\ + x += y;\ + y = x - y;\ + x -= x + +enum phase {DIG, BUILD, PLACE, QUERY}; + +command_result blueprint(color_ostream &out, vector ¶meters); + +DFhackCExport command_result plugin_init(color_ostream &out, vector &commands) +{ + commands.push_back(PluginCommand("blueprint", "Convert map tiles into a blueprint", blueprint, false)); + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown(color_ostream &out) +{ + return CR_OK; +} + +command_result help(color_ostream &out) +{ + out << "blueprint width height depth name [dig [build [place [query]]]]" << endl + << " width, height, depth: area to translate in tiles" << endl + << " name: base name for blueprint files" << endl + << " dig: generate blueprints for digging" << endl + << " build: generate blueprints for building" << endl + << " place: generate blueprints for stockpiles" << endl + << " query: generate blueprints for querying (room designations)" << endl + << " defaults to generating all blueprints" << endl + << endl + << "blueprint translates a portion of your fortress into blueprints suitable for" << endl + << " digfort/fortplan/quickfort. Blueprints are created in the DF folder with names" << endl + << " following a \"name-phase.csv\" pattern. Translation starts at the current" << endl + << " cursor location and includes all tiles in the range specified." << endl; + return CR_OK; +} + + +command_result do_transform(DFCoord start, DFCoord range, string name, phase last_phase) +{ + ofstream dig, build, place, query; + switch (last_phase) + { + case QUERY: + query = ofstream(name + "-query.csv", ofstream::trunc); + query << "#query" << endl; + case PLACE: + place = ofstream(name + "-place.csv", ofstream::trunc); + place << "#place" << endl; + case BUILD: + build = ofstream(name + "-build.csv", ofstream::trunc); + build << "#build" << endl; + case DIG: + dig = ofstream(name + "-dig.csv", ofstream::trunc); + dig << "#dig" << endl; + } + DFCoord end = start + range; + if (start.x > end.x) + { + swap(start.x, end.x); + } + if (start.y > end.y) + { + swap(start.y, end.y); + } + if (start.z > end.z) + { + swap(start.z, end.z); + } + + MapExtras::MapCache mc; + for (auto z = start.z; z < end.z; z++) + { + for (auto y = start.y; y < end.y; y++) + { + for (auto x = start.x; x < end.x; x++) + { + switch (last_phase) { + case QUERY: + case PLACE: + case BUILD: + case DIG: + } + } + switch (last_phase) { + case QUERY: + query << "#" << endl; + case PLACE: + place << "#" << endl; + case BUILD: + place << "#" << endl; + case DIG: + dig << "#" << endl; + } + } + if (z < end.z - 1) + switch (last_phase) { + case QUERY: + query << "#>" << endl; + case PLACE: + place << "#>" << endl; + case BUILD: + place << "#>" << endl; + case DIG: + dig << "#>" << endl; + } + } + switch (last_phase) { + case QUERY: + query.close(); + case PLACE: + place.close(); + case BUILD: + place.close(); + case DIG: + dig.close(); + } + return CR_OK; +} + +command_result blueprint(color_ostream &out, vector ¶meters) +{ + if (parameters.size() < 4 || parameters.size() > 8) + return help(out); + CoreSuspender suspend; + if (!Maps::IsValid()) + { + out.printerr("Map is not available!\n"); + return CR_FAILURE; + } + int32_t x, y, z; + if (!Gui::getCursorCoords(x, y, z)) + { + out.printerr("Can't get cursor coords! Make sure you have an active cursor in DF.\n"); + return CR_FAILURE; + } + DFCoord start (x, y, z); + DFCoord range (stoi(parameters[0]), stoi(parameters[1]), stoi(parameters[2])); + switch(parameters.size()) + { + case 4: + case 8: + return do_transform(start, range, parameters[3], QUERY); + case 5: + return do_transform(start, range, parameters[3], DIG); + case 6: + return do_transform(start, range, parameters[3], BUILD); + case 7: + return do_transform(start, range, parameters[3], PLACE); + default: //wtf? + return CR_FAILURE; + } +} \ No newline at end of file