Skip to content

Commit 11333e3

Browse files
committed
update pathable plugin to support v50 maps
1 parent a53e943 commit 11333e3

3 files changed

Lines changed: 66 additions & 52 deletions

File tree

plugins/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ dfhack_plugin(hotkeys hotkeys.cpp LINK_LIBRARIES lua)
141141
#dfhack_plugin(nestboxes nestboxes.cpp)
142142
#dfhack_plugin(orders orders.cpp LINK_LIBRARIES jsoncpp_static)
143143
dfhack_plugin(overlay overlay.cpp LINK_LIBRARIES lua)
144-
#dfhack_plugin(pathable pathable.cpp LINK_LIBRARIES lua)
144+
dfhack_plugin(pathable pathable.cpp LINK_LIBRARIES lua)
145145
#dfhack_plugin(petcapRemover petcapRemover.cpp)
146146
#dfhack_plugin(plants plants.cpp)
147147
#dfhack_plugin(probe probe.cpp)

plugins/lua/pathable.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local _ENV = mkmodule('plugins.pathable')
22

33
--[[
44
5-
Native functions: (see Plugins.rst for details)
5+
Native functions: (see docs/dev/Lua API.rst for details)
66
77
- paintScreen(cursor[,skip_unrevealed])
88

plugins/pathable.cpp

Lines changed: 64 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,96 @@
1-
#include "Console.h"
2-
#include "Core.h"
3-
#include "DataDefs.h"
4-
#include "DataFuncs.h"
5-
#include "DataIdentity.h"
6-
#include "Export.h"
7-
#include "LuaTools.h"
8-
#include "PluginManager.h"
9-
#include "modules/Gui.h"
1+
#include "df/graphic_viewportst.h"
2+
103
#include "modules/Maps.h"
114
#include "modules/Screen.h"
12-
#include "df/world.h"
5+
6+
#include "Debug.h"
7+
#include "LuaTools.h"
8+
#include "PluginManager.h"
139

1410
using namespace DFHack;
1511

1612
DFHACK_PLUGIN("pathable");
17-
REQUIRE_GLOBAL(world);
13+
14+
REQUIRE_GLOBAL(gps);
1815
REQUIRE_GLOBAL(window_x);
1916
REQUIRE_GLOBAL(window_y);
2017
REQUIRE_GLOBAL(window_z);
18+
REQUIRE_GLOBAL(world);
19+
20+
namespace DFHack {
21+
DBG_DECLARE(pathable, log, DebugCategory::LINFO);
22+
}
2123

22-
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands)
23-
{
24+
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands) {
2425
return CR_OK;
2526
}
2627

27-
DFhackCExport command_result plugin_shutdown(color_ostream &out)
28-
{
28+
DFhackCExport command_result plugin_shutdown(color_ostream &out) {
2929
return CR_OK;
3030
}
3131

32-
static void paintScreen(df::coord cursor, bool skip_unrevealed = false)
33-
{
34-
auto dims = Gui::getDwarfmodeViewDims();
35-
for (int y = dims.map_y1; y <= dims.map_y2; y++)
36-
{
37-
for (int x = dims.map_x1; x <= dims.map_x2; x++)
38-
{
39-
Screen::Pen cur_tile = Screen::readTile(x, y, true);
40-
if (!cur_tile.valid())
41-
continue;
32+
static void paintScreen(df::coord target, bool skip_unrevealed = false) {
33+
DEBUG(log).print("entering paintScreen\n");
34+
35+
bool use_graphics = Screen::inGraphicsMode();
4236

43-
df::coord map_pos(
44-
*window_x + x - dims.map_x1,
45-
*window_y + y - dims.map_y1,
46-
*window_z
47-
);
37+
auto dimx = use_graphics ? gps->main_viewport->dim_x : gps->dimx;
38+
auto dimy = use_graphics ? gps->main_viewport->dim_y : gps->dimy;
39+
for (int y = 0; y < dimy; ++y) {
40+
for (int x = 0; x < dimx; ++x) {
41+
df::coord map_pos(*window_x + x, *window_y + y, *window_z);
4842

49-
// Keep yellow cursor
50-
if (map_pos == cursor)
43+
if (!Maps::isValidTilePos(map_pos))
5144
continue;
5245

53-
if (map_pos.x < 0 || map_pos.x >= world->map.x_count ||
54-
map_pos.y < 0 || map_pos.y >= world->map.y_count ||
55-
map_pos.z < 0 || map_pos.z >= world->map.z_count)
56-
{
46+
// don't overwrite the target tile
47+
if (!use_graphics && map_pos == target) {
48+
TRACE(log).print("skipping target tile\n");
5749
continue;
5850
}
5951

60-
if (skip_unrevealed && !Maps::isTileVisible(map_pos))
52+
if (skip_unrevealed && !Maps::isTileVisible(map_pos)) {
53+
TRACE(log).print("skipping hidden tile\n");
6154
continue;
55+
}
6256

63-
int color = Maps::canWalkBetween(cursor, map_pos) ? COLOR_GREEN : COLOR_RED;
57+
DEBUG(log).print("scanning map tile at offset %d, %d\n", x, y);
58+
Screen::Pen cur_tile = Screen::readTile(x, y, true);
59+
DEBUG(log).print("tile data: ch=%d, fg=%d, bg=%d, bold=%s\n",
60+
cur_tile.ch, cur_tile.fg, cur_tile.bg, cur_tile.bold ? "true" : "false");
61+
DEBUG(log).print("tile data: tile=%d, tile_mode=%d, tile_fg=%d, tile_bg=%d\n",
62+
cur_tile.tile, cur_tile.tile_mode, cur_tile.tile_fg, cur_tile.tile_bg);
6463

65-
if (cur_tile.fg && cur_tile.ch != ' ')
66-
{
67-
cur_tile.fg = color;
68-
cur_tile.bg = 0;
69-
}
70-
else
71-
{
72-
cur_tile.fg = 0;
73-
cur_tile.bg = color;
64+
if (!cur_tile.valid()) {
65+
DEBUG(log).print("cannot read tile at offset %d, %d\n", x, y);
66+
continue;
7467
}
7568

76-
cur_tile.bold = false;
69+
bool can_walk = Maps::canWalkBetween(target, map_pos);
70+
DEBUG(log).print("tile is %swalkable at offset %d, %d\n",
71+
can_walk ? "" : "not ", x, y);
72+
73+
if (use_graphics) {
74+
if (map_pos == target) {
75+
cur_tile.tile = 100711; // highlighted selection
76+
} else{
77+
cur_tile.tile = can_walk ? 779 : 782;
78+
}
79+
} else {
80+
int color = can_walk ? COLOR_GREEN : COLOR_RED;
81+
if (cur_tile.fg && cur_tile.ch != ' ') {
82+
cur_tile.fg = color;
83+
cur_tile.bg = 0;
84+
} else {
85+
cur_tile.fg = 0;
86+
cur_tile.bg = color;
87+
}
7788

78-
if (cur_tile.tile)
79-
cur_tile.tile_mode = Screen::Pen::CharColor;
89+
cur_tile.bold = false;
90+
91+
if (cur_tile.tile)
92+
cur_tile.tile_mode = Screen::Pen::CharColor;
93+
}
8094

8195
Screen::paintTile(cur_tile, x, y, true);
8296
}

0 commit comments

Comments
 (0)