Merge remote-tracking branch 'PeridexisErrant/new-scripts' into develop

develop
lethosor 2015-11-26 16:13:27 -05:00
commit df61233774
7 changed files with 91 additions and 188 deletions

@ -48,6 +48,11 @@ Misc Improvements
-----------------
- Unrecognized command feedback now includes more information about plugins
Misc Improvements
-----------------
- `fix/dry-buckets`: replaces the ``drybuckets`` plugin
- `feature`: now implemented by a script
DFHack 0.40.24-r4
=================

@ -182,10 +182,6 @@ Shows all items needed for the currently active strange mood.
Bugfixes
========
drybuckets
==========
Removes water from all buckets in your fortress, allowing them to be used for making lye.
fixdiplomats
============
Adds a Diplomat position to all Elven civilizations, allowing them to negotiate
@ -1798,23 +1794,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

@ -115,12 +115,10 @@ if (BUILD_SUPPORTED)
DFHACK_PLUGIN(dig dig.cpp)
DFHACK_PLUGIN(digFlood digFlood.cpp)
add_subdirectory(diggingInvaders)
DFHACK_PLUGIN(drybuckets drybuckets.cpp)
DFHACK_PLUGIN(dwarfmonitor dwarfmonitor.cpp LINK_LIBRARIES lua)
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,52 +0,0 @@
// Dry Buckets : Remove all "water" objects from buckets scattered around the fortress
#include "Core.h"
#include "Console.h"
#include "Export.h"
#include "PluginManager.h"
#include "DataDefs.h"
#include "df/world.h"
#include "df/item.h"
#include "df/builtin_mats.h"
using std::string;
using std::vector;
using namespace DFHack;
using namespace df::enums;
DFHACK_PLUGIN("drybuckets");
REQUIRE_GLOBAL(world);
command_result df_drybuckets (color_ostream &out, vector <string> & parameters)
{
if (!parameters.empty())
return CR_WRONG_USAGE;
CoreSuspender suspend;
int dried_total = 0;
for (size_t i = 0; i < world->items.all.size(); i++)
{
df::item *item = world->items.all[i];
if ((item->getType() == item_type::LIQUID_MISC) && (item->getMaterial() == builtin_mats::WATER))
{
item->flags.bits.garbage_collect = 1;
dried_total++;
}
}
if (dried_total)
out.print("Done. %d buckets of water marked for emptying.\n", dried_total);
return CR_OK;
}
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{
commands.push_back(PluginCommand("drybuckets", "Removes water from buckets.", df_drybuckets));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{
return CR_OK;
}

@ -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

@ -0,0 +1,28 @@
-- Removes water from buckets (for lye-making).
--[[=begin
fix/dry-buckets
===============
Removes water from all buckets in your fortress, allowing them
to be used for making lye. Skips buckets in buildings (eg a well),
being carried, or currently used by a job.
=end]]
local emptied = 0
local water_type = dfhack.matinfo.find('WATER').type
for _,item in ipairs(df.global.world.items.all) do
container = dfhack.items.getContainer(item)
if container ~= nil
and container:getType() == dfhack.item_type.BUCKET
and not (container.flags.in_job or container.flags.in_building)
and item:getMaterial() == water_type
and item:getType() == dfhack.item_type.LIQUID_MISC
and not (item.flags.in_job or item.flags.in_building) then
dfhack.items.remove(item)
emptied = emptied + 1
end
end
print('Emptied '..emptied..' buckets.')