Merge pull request #2541 from myk002/myk_pathable

Update pathable plugin to support v50 maps
develop
Myk 2023-01-02 20:42:12 -08:00 committed by GitHub
commit 3b572b9a9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 51 deletions

@ -141,7 +141,7 @@ dfhack_plugin(hotkeys hotkeys.cpp LINK_LIBRARIES lua)
#dfhack_plugin(nestboxes nestboxes.cpp)
#dfhack_plugin(orders orders.cpp LINK_LIBRARIES jsoncpp_static)
dfhack_plugin(overlay overlay.cpp LINK_LIBRARIES lua)
#dfhack_plugin(pathable pathable.cpp LINK_LIBRARIES lua)
dfhack_plugin(pathable pathable.cpp LINK_LIBRARIES lua)
#dfhack_plugin(petcapRemover petcapRemover.cpp)
#dfhack_plugin(plants plants.cpp)
#dfhack_plugin(probe probe.cpp)

@ -2,7 +2,7 @@ local _ENV = mkmodule('plugins.pathable')
--[[
Native functions: (see Plugins.rst for details)
Native functions: (see docs/dev/Lua API.rst for details)
- paintScreen(cursor[,skip_unrevealed])

@ -1,82 +1,94 @@
#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"
#include "Debug.h"
#include "LuaTools.h"
#include "PluginManager.h"
using namespace DFHack;
DFHACK_PLUGIN("pathable");
REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(gps);
REQUIRE_GLOBAL(window_x);
REQUIRE_GLOBAL(window_y);
REQUIRE_GLOBAL(window_z);
REQUIRE_GLOBAL(world);
namespace DFHack {
DBG_DECLARE(pathable, log, DebugCategory::LINFO);
}
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands)
{
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands) {
return CR_OK;
}
DFhackCExport command_result plugin_shutdown(color_ostream &out)
{
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;
static void paintScreen(df::coord target, bool skip_unrevealed = false) {
DEBUG(log).print("entering paintScreen\n");
bool use_graphics = Screen::inGraphicsMode();
df::coord map_pos(
*window_x + x - dims.map_x1,
*window_y + y - dims.map_y1,
*window_z
);
auto dims = Gui::getDwarfmodeViewDims().map();
for (int y = dims.first.y; y <= dims.second.y; ++y) {
for (int x = dims.first.x; x <= dims.second.x; ++x) {
df::coord map_pos(*window_x + x, *window_y + y, *window_z);
// Keep yellow cursor
if (map_pos == cursor)
if (!Maps::isValidTilePos(map_pos))
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)
{
// don't overwrite the target tile
if (!use_graphics && map_pos == target) {
TRACE(log).print("skipping target tile\n");
continue;
}
if (skip_unrevealed && !Maps::isTileVisible(map_pos))
if (skip_unrevealed && !Maps::isTileVisible(map_pos)) {
TRACE(log).print("skipping hidden tile\n");
continue;
}
int color = Maps::canWalkBetween(cursor, map_pos) ? COLOR_GREEN : COLOR_RED;
DEBUG(log).print("scanning map tile at offset %d, %d\n", x, y);
Screen::Pen cur_tile = Screen::readTile(x, y, true);
DEBUG(log).print("tile data: ch=%d, fg=%d, bg=%d, bold=%s\n",
cur_tile.ch, cur_tile.fg, cur_tile.bg, cur_tile.bold ? "true" : "false");
DEBUG(log).print("tile data: tile=%d, tile_mode=%d, tile_fg=%d, tile_bg=%d\n",
cur_tile.tile, cur_tile.tile_mode, cur_tile.tile_fg, cur_tile.tile_bg);
if (cur_tile.fg && cur_tile.ch != ' ')
{
cur_tile.fg = color;
cur_tile.bg = 0;
}
else
{
cur_tile.fg = 0;
cur_tile.bg = color;
if (!cur_tile.valid()) {
DEBUG(log).print("cannot read tile at offset %d, %d\n", x, y);
continue;
}
cur_tile.bold = false;
bool can_walk = Maps::canWalkBetween(target, map_pos);
DEBUG(log).print("tile is %swalkable at offset %d, %d\n",
can_walk ? "" : "not ", x, y);
if (use_graphics) {
if (map_pos == target) {
cur_tile.tile = 100711; // highlighted selection
} else{
cur_tile.tile = can_walk ? 779 : 782;
}
} else {
int color = can_walk ? 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;
}
if (cur_tile.tile)
cur_tile.tile_mode = Screen::Pen::CharColor;
cur_tile.bold = false;
if (cur_tile.tile)
cur_tile.tile_mode = Screen::Pen::CharColor;
}
Screen::paintTile(cur_tile, x, y, true);
}