Implement feature as a script, add magma option

Functionality is exactly equivalent to the plugin, but with a new option
for players who want to enable magma furnaces without spoilers.
develop
PeridexisErrant 2015-11-17 16:43:56 +09:30
parent 2ba9ef04e3
commit 842b9c5191
5 changed files with 61 additions and 133 deletions

@ -36,9 +36,10 @@ Fixes
-----
- confirm haul-delete: Fixed issue preventing deletion of stop conditions or using "x" in route names
New Scripts
-----------
Misc Improvements
-----------------
- `fix/dry-buckets`: replaces the ``drybuckets`` plugin
- `feature`: now implemented by a script
DFHack 0.40.24-r4
=================

@ -1787,23 +1787,6 @@ Usage:
:digFlood digAll1: ignore the monitor list and dig any vein
:digFlood digAll0: disable digAll mode
.. _feature:
feature
=======
Enables management of map features.
* Discovering a magma feature (magma pool, volcano, magma sea, or curious
underground structure) permits magma workshops and furnaces to be built.
* Discovering a cavern layer causes plants (trees, shrubs, and grass) from
that cavern to grow within your fortress.
Options:
:list: Lists all map features in your current embark by index.
:show X: Marks the selected map feature as discovered.
:hide X: Marks the selected map feature as undiscovered.
.. _filltraffic:
filltraffic

@ -119,7 +119,6 @@ if (BUILD_SUPPORTED)
DFHACK_PLUGIN(embark-tools embark-tools.cpp)
DFHACK_PLUGIN(eventful eventful.cpp LINK_LIBRARIES lua)
DFHACK_PLUGIN(fastdwarf fastdwarf.cpp)
DFHACK_PLUGIN(feature feature.cpp)
DFHACK_PLUGIN(filltraffic filltraffic.cpp)
DFHACK_PLUGIN(fix-armory fix-armory.cpp)
DFHACK_PLUGIN(fixpositions fixpositions.cpp)

@ -1,113 +0,0 @@
// 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;
DFHACK_PLUGIN("feature");
REQUIRE_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->features.map_features.size(); i++)
{
df::feature_init *feature_init = world->features.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()).c_str(),
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->features.map_features.size()))
{
out.print("No such feature!\n");
return CR_FAILURE;
}
df::feature_init *feature_init = world->features.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()).c_str());
}
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->features.map_features.size()))
{
out.print("No such feature!\n");
return CR_FAILURE;
}
df::feature_init *feature_init = world->features.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()).c_str());
}
else return CR_WRONG_USAGE;
return CR_OK;
}
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
{
commands.push_back(PluginCommand(
"feature", "List or manage map features.", feature, 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;
}

@ -0,0 +1,58 @@
-- List or manage map features & enable magma furnaces
local help = [[=begin
feature
=======
Enables management of map features.
* Discovering a magma feature (magma pool, volcano, magma sea, or curious
underground structure) permits magma workshops and furnaces to be built.
* Discovering a cavern layer causes plants (trees, shrubs, and grass) from
that cavern to grow within your fortress.
Options:
:list: Lists all map features in your current embark by index.
:magma: Enable magma furnaces (discovers a random magma feature).
:show X: Marks the selected map feature as discovered.
:hide X: Marks the selected map feature as undiscovered.
=end]]
local map_features = df.global.world.features.map_features
function toggle_feature(idx, discovered)
map_features[tonumber(idx)].flags.Discovered = discovered
end
function list_features()
for idx, feat in ipairs(map_features) do
local kind = df.feature_type[feat:getType()]:gsub('_', ' ')
local discovered = feat.flags.Discovered and 'shown. ' or 'hidden.'
print('Feature #'..idx..' is '..discovered..' It is a "'..kind..'".')
end
end
function enable_magma_funaces()
for idx, feat in ipairs(map_features) do
if tostring(feat):find('magma') ~= nil then
toggle_feature(idx, true)
print('Enabled magma furnaces.')
return
end
end
dfhack.printerr('Could not find a magma-bearing feature.')
end
local args = {...}
if args[1] == 'list' then
list_features()
elseif args[1] == 'magma' then
enable_magma_funaces()
elseif args[1] == 'show' then
toggle_feature(args[2], true)
elseif args[1] == 'hide' then
toggle_feature(args[2], false)
else
print(help)
end