diff --git a/dfhack.init-example b/dfhack.init-example index 525e823a3..8c8289595 100644 --- a/dfhack.init-example +++ b/dfhack.init-example @@ -147,6 +147,9 @@ keybinding add Shift-B@pet/List/Unit "gui/autobutcher" # assign weapon racks to squads so that they can be used 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 # ############################ diff --git a/docs/Plugins.rst b/docs/Plugins.rst index eec37960a..6137d080b 100644 --- a/docs/Plugins.rst +++ b/docs/Plugins.rst @@ -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 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 diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index f7586f03d..a197364ff 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -136,6 +136,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(misery misery.cpp) DFHACK_PLUGIN(mode mode.cpp) DFHACK_PLUGIN(mousequery mousequery.cpp) + DFHACK_PLUGIN(pathable pathable.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(petcapRemover petcapRemover.cpp) DFHACK_PLUGIN(plants plants.cpp) DFHACK_PLUGIN(probe probe.cpp) diff --git a/plugins/lua/pathable.lua b/plugins/lua/pathable.lua new file mode 100644 index 000000000..b5f5addfc --- /dev/null +++ b/plugins/lua/pathable.lua @@ -0,0 +1,11 @@ +local _ENV = mkmodule('plugins.pathable') + +--[[ + +Native functions: (see Plugins.rst for details) + +- paintScreen(cursor[,skip_unrevealed]) + +]] + +return _ENV diff --git a/plugins/pathable.cpp b/plugins/pathable.cpp new file mode 100644 index 000000000..6007d8401 --- /dev/null +++ b/plugins/pathable.cpp @@ -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 &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 +}; + diff --git a/scripts b/scripts index 2840996c5..3baa24fec 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 2840996c5f39917713cfb0e7ce1c6dca779177e1 +Subproject commit 3baa24fec93461218b5b658de94884ebff0a0b23