From bca78088e208b27c83fa5fca5123286e986157d1 Mon Sep 17 00:00:00 2001 From: Quietust Date: Fri, 24 Feb 2012 14:07:04 -0600 Subject: [PATCH] Add "changevein" plugin, lets you change what mineral inclusions are made of --- plugins/CMakeLists.txt | 1 + plugins/changevein.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 plugins/changevein.cpp diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 638e5aca4..453a95e9d 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -79,6 +79,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(fixveins fixveins.cpp) DFHACK_PLUGIN(fixpositions fixpositions.cpp) DFHACK_PLUGIN(follow follow.cpp) + DFHACK_PLUGIN(changevein changevein.cpp) #DFHACK_PLUGIN(versionosd versionosd.cpp) endif() diff --git a/plugins/changevein.cpp b/plugins/changevein.cpp new file mode 100644 index 000000000..6b2767d5a --- /dev/null +++ b/plugins/changevein.cpp @@ -0,0 +1,96 @@ +// Allow changing the material of a mineral inclusion + +#include "Core.h" +#include "Console.h" +#include "Export.h" +#include "PluginManager.h" + +#include "DataDefs.h" +#include "modules/Maps.h" +#include "modules/Materials.h" +#include "TileTypes.h" + +using std::vector; +using std::string; +using namespace DFHack; +using namespace DFHack::Simple; +using namespace df::enums; + +using df::global::world; +using df::global::cursor; + +command_result df_changevein (Core * c, vector & parameters) +{ + if (parameters.size() != 1) + return CR_WRONG_USAGE; + + CoreSuspender suspend(c); + + if (!Maps::IsValid()) + { + c->con.printerr("Map is not available!\n"); + return CR_FAILURE; + } + if (!cursor || cursor->x == -30000) + { + c->con.printerr("No cursor detected - please place the cursor over a mineral vein.\n"); + return CR_FAILURE; + } + + MaterialInfo mi; + if (!mi.findInorganic(parameters[0])) + { + c->con.printerr("No such material!\n"); + return CR_FAILURE; + } + if (mi.inorganic->material.flags.is_set(material_flags::IS_METAL) || + mi.inorganic->material.flags.is_set(material_flags::NO_STONE_STOCKPILE) || + mi.inorganic->flags.is_set(inorganic_flags::SOIL_ANY)) + { + c->con.printerr("Invalid material - you must select a type of stone or gem\n"); + return CR_FAILURE; + } + + df::map_block *block = Maps::getBlockAbs(cursor->x, cursor->y, cursor->z); + if (!block) + { + c->con.printerr("Invalid tile selected.\n"); + return CR_FAILURE; + } + df::block_square_event_mineralst *mineral = NULL; + int tx = cursor->x % 16, ty = cursor->y % 16; + for (size_t j = 0; j < block->block_events.size(); j++) + { + df::block_square_event *evt = block->block_events[j]; + if (evt->getType() != block_square_event_type::mineral) + continue; + mineral = (df::block_square_event_mineralst *)evt; + if (mineral->getassignment(tx, ty)) + break; + mineral = NULL; + } + if (!mineral) + { + c->con.printerr("Selected tile does not contain a mineral vein.\n"); + return CR_FAILURE; + } + mineral->inorganic_mat = mi.index; + + return CR_OK; +} + +DFHACK_PLUGIN("changevein"); + +DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) +{ + commands.push_back(PluginCommand("changevein", + "Changes the material of a mineral inclusion.", + df_changevein, false, + "Syntax: changevein \n")); + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + return CR_OK; +}