Add map feature manager - allows enabling/disabling magma workshops as well as halting subterranean plant growth outside the caverns

develop
Quietust 2012-03-10 13:40:55 -06:00
parent 32cc4c8928
commit 1124ab25fb
2 changed files with 112 additions and 0 deletions

@ -80,6 +80,7 @@ if (BUILD_SUPPORTED)
DFHACK_PLUGIN(changevein changevein.cpp)
DFHACK_PLUGIN(advtools advtools.cpp)
DFHACK_PLUGIN(tweak tweak.cpp)
DFHACK_PLUGIN(feature feature.cpp)
#DFHACK_PLUGIN(versionosd versionosd.cpp)
endif()

@ -0,0 +1,111 @@
// Map feature manager - list features and discover/undiscover individual ones
#include "Core.h"
#include "Console.h"
#include "Export.h"
#include "PluginManager.h"
#include "DataDefs.h"
#include "df/world.h"
#include "df/feature_init.h"
#include <stdlib.h>
using std::vector;
using std::string;
using std::endl;
using namespace DFHack;
using namespace df::enums;
using df::global::world;
static command_result feature(color_ostream &out, vector <string> &parameters)
{
CoreSuspender suspend;
if (parameters.empty())
return CR_WRONG_USAGE;
string cmd = parameters[0];
if (cmd == "list")
{
if (parameters.size() != 1)
return CR_WRONG_USAGE;
for (size_t i = 0; i < world->unk_192bd8.map_features.size(); i++)
{
df::feature_init *feature_init = world->unk_192bd8.map_features[i];
string name;
feature_init->getName(&name);
out.print("Feature #%i (\"%s\", type %s) is %s\n", i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType()), feature_init->flags.is_set(feature_init_flags::Discovered) ? "discovered" : "hidden");
}
}
else if(cmd == "show")
{
if (parameters.size() != 2)
return CR_WRONG_USAGE;
size_t i = atoi(parameters[1].c_str());
if ((i < 0) || (i >= world->unk_192bd8.map_features.size()))
{
out.print("No such feature!\n");
return CR_FAILURE;
}
df::feature_init *feature_init = world->unk_192bd8.map_features[i];
if (feature_init->flags.is_set(feature_init_flags::Discovered))
{
out.print("Selected feature is already discovered!\n");
return CR_OK;
}
feature_init->flags.set(feature_init_flags::Discovered);
string name;
feature_init->getName(&name);
out.print("Feature #%i (\"%s\", type %s) is now discovered\n", i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType()));
}
else if(cmd == "hide")
{
if (parameters.size() != 2)
return CR_WRONG_USAGE;
size_t i = atoi(parameters[1].c_str());
if ((i < 0) || (i >= world->unk_192bd8.map_features.size()))
{
out.print("No such feature!\n");
return CR_FAILURE;
}
df::feature_init *feature_init = world->unk_192bd8.map_features[i];
if (!feature_init->flags.is_set(feature_init_flags::Discovered))
{
out.print("Selected feature is already hidden!\n");
return CR_OK;
}
feature_init->flags.clear(feature_init_flags::Discovered);
string name;
feature_init->getName(&name);
out.print("Feature #%i (\"%s\", type %s) is now hidden\n", i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType()));
}
else return CR_WRONG_USAGE;
return CR_OK;
}
DFHACK_PLUGIN("feature");
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand(
"feature", "List or manage map features.", features, false,
" feature list\n"
" Lists all map features in the region.\n"
" feature show <ID>\n"
" Marks the specified map feature as discovered.\n"
" feature hide <ID>\n"
" Marks the specified map feature as undiscovered.\n"
));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown (color_ostream &out)
{
return CR_OK;
}