Add new "pathable" plugin

develop
lethosor 2017-07-05 23:54:55 -04:00
parent d6c4aa823a
commit 2d07e5edea
6 changed files with 119 additions and 1 deletions

@ -147,6 +147,9 @@ keybinding add Shift-B@pet/List/Unit "gui/autobutcher"
# assign weapon racks to squads so that they can be used # assign weapon racks to squads so that they can be used
keybinding add P@dwarfmode/QueryBuilding/Some/Weaponrack gui/assign-rack keybinding add P@dwarfmode/QueryBuilding/Some/Weaponrack gui/assign-rack
# view pathable tiles from active cursor
keybinding add Alt-Shift-P@dwarfmode/LookAround gui/pathable
############################ ############################
# UI and game logic tweaks # # UI and game logic tweaks #
############################ ############################

@ -109,6 +109,19 @@ A tool for checking how many tiles contain flowing liquids. If you suspect that
your magma sea leaks into HFS, you can use this tool to be sure without your magma sea leaks into HFS, you can use this tool to be sure without
revealing the map. revealing the map.
.. _pathable:
pathable
========
This plugin implements the back end of the `gui/pathable` script. It exports a
single Lua function, in ``hack/lua/plugins/pathable.lua``:
* ``paintScreen(cursor[,skip_unrevealed])``: Paint each visible of the screen
green or red, depending on whether it can be pathed to from the tile at
``cursor``. If ``skip_unrevealed`` is specified and true, do not draw
unrevealed tiles.
.. _probe: .. _probe:
probe probe

@ -136,6 +136,7 @@ if (BUILD_SUPPORTED)
DFHACK_PLUGIN(misery misery.cpp) DFHACK_PLUGIN(misery misery.cpp)
DFHACK_PLUGIN(mode mode.cpp) DFHACK_PLUGIN(mode mode.cpp)
DFHACK_PLUGIN(mousequery mousequery.cpp) DFHACK_PLUGIN(mousequery mousequery.cpp)
DFHACK_PLUGIN(pathable pathable.cpp LINK_LIBRARIES lua)
DFHACK_PLUGIN(petcapRemover petcapRemover.cpp) DFHACK_PLUGIN(petcapRemover petcapRemover.cpp)
DFHACK_PLUGIN(plants plants.cpp) DFHACK_PLUGIN(plants plants.cpp)
DFHACK_PLUGIN(probe probe.cpp) DFHACK_PLUGIN(probe probe.cpp)

@ -0,0 +1,11 @@
local _ENV = mkmodule('plugins.pathable')
--[[
Native functions: (see Plugins.rst for details)
- paintScreen(cursor[,skip_unrevealed])
]]
return _ENV

@ -0,0 +1,90 @@
#include "Console.h"
#include "Core.h"
#include "DataDefs.h"
#include "DataFuncs.h"
#include "DataIdentity.h"
#include "Export.h"
#include "LuaTools.h"
#include "PluginManager.h"
#include "modules/Gui.h"
#include "modules/Maps.h"
#include "modules/Screen.h"
#include "df/world.h"
using namespace DFHack;
DFHACK_PLUGIN("pathable");
REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(window_x);
REQUIRE_GLOBAL(window_y);
REQUIRE_GLOBAL(window_z);
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands)
{
return CR_OK;
}
DFhackCExport command_result plugin_shutdown(color_ostream &out)
{
return CR_OK;
}
static void paintScreen(df::coord cursor, bool skip_unrevealed = false)
{
auto dims = Gui::getDwarfmodeViewDims();
for (int y = dims.map_y1; y <= dims.map_y2; y++)
{
for (int x = dims.map_x1; x <= dims.map_x2; x++)
{
Screen::Pen cur_tile = Screen::readTile(x, y, true);
if (!cur_tile.valid())
continue;
df::coord map_pos(
*window_x + x - dims.map_x1,
*window_y + y - dims.map_y1,
*window_z
);
// Keep yellow cursor
if (map_pos == cursor)
continue;
if (map_pos.x < 0 || map_pos.x >= world->map.x_count ||
map_pos.y < 0 || map_pos.y >= world->map.y_count ||
map_pos.z < 0 || map_pos.z >= world->map.z_count)
{
continue;
}
if (skip_unrevealed && !Maps::isTileVisible(map_pos))
continue;
int color = Maps::canWalkBetween(cursor, map_pos) ? COLOR_GREEN : COLOR_RED;
if (cur_tile.fg && cur_tile.ch != ' ')
{
cur_tile.fg = color;
cur_tile.bg = 0;
}
else
{
cur_tile.fg = 0;
cur_tile.bg = color;
}
cur_tile.bold = false;
if (cur_tile.tile)
cur_tile.tile_mode = Screen::Pen::CharColor;
Screen::paintTile(cur_tile, x, y, true);
}
}
}
DFHACK_PLUGIN_LUA_FUNCTIONS {
DFHACK_LUA_FUNCTION(paintScreen),
DFHACK_LUA_END
};

@ -1 +1 @@
Subproject commit 2840996c5f39917713cfb0e7ce1c6dca779177e1 Subproject commit 3baa24fec93461218b5b658de94884ebff0a0b23