|
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 | + |
10 | 3 | #include "modules/Maps.h" |
11 | 4 | #include "modules/Screen.h" |
12 | | -#include "df/world.h" |
| 5 | + |
| 6 | +#include "Debug.h" |
| 7 | +#include "LuaTools.h" |
| 8 | +#include "PluginManager.h" |
13 | 9 |
|
14 | 10 | using namespace DFHack; |
15 | 11 |
|
16 | 12 | DFHACK_PLUGIN("pathable"); |
17 | | -REQUIRE_GLOBAL(world); |
| 13 | + |
| 14 | +REQUIRE_GLOBAL(gps); |
18 | 15 | REQUIRE_GLOBAL(window_x); |
19 | 16 | REQUIRE_GLOBAL(window_y); |
20 | 17 | REQUIRE_GLOBAL(window_z); |
| 18 | +REQUIRE_GLOBAL(world); |
| 19 | + |
| 20 | +namespace DFHack { |
| 21 | + DBG_DECLARE(pathable, log, DebugCategory::LINFO); |
| 22 | +} |
21 | 23 |
|
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) { |
24 | 25 | return CR_OK; |
25 | 26 | } |
26 | 27 |
|
27 | | -DFhackCExport command_result plugin_shutdown(color_ostream &out) |
28 | | -{ |
| 28 | +DFhackCExport command_result plugin_shutdown(color_ostream &out) { |
29 | 29 | return CR_OK; |
30 | 30 | } |
31 | 31 |
|
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(); |
42 | 36 |
|
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); |
48 | 42 |
|
49 | | - // Keep yellow cursor |
50 | | - if (map_pos == cursor) |
| 43 | + if (!Maps::isValidTilePos(map_pos)) |
51 | 44 | continue; |
52 | 45 |
|
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"); |
57 | 49 | continue; |
58 | 50 | } |
59 | 51 |
|
60 | | - if (skip_unrevealed && !Maps::isTileVisible(map_pos)) |
| 52 | + if (skip_unrevealed && !Maps::isTileVisible(map_pos)) { |
| 53 | + TRACE(log).print("skipping hidden tile\n"); |
61 | 54 | continue; |
| 55 | + } |
62 | 56 |
|
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); |
64 | 63 |
|
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; |
74 | 67 | } |
75 | 68 |
|
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 | + } |
77 | 88 |
|
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 | + } |
80 | 94 |
|
81 | 95 | Screen::paintTile(cur_tile, x, y, true); |
82 | 96 | } |
|
0 commit comments