2023-01-01 00:20:46 -07:00
|
|
|
#include "modules/Gui.h"
|
2017-07-05 21:54:55 -06:00
|
|
|
#include "modules/Maps.h"
|
|
|
|
#include "modules/Screen.h"
|
2023-01-29 01:35:12 -07:00
|
|
|
#include "modules/Textures.h"
|
2022-12-31 22:05:03 -07:00
|
|
|
|
|
|
|
#include "Debug.h"
|
|
|
|
#include "LuaTools.h"
|
|
|
|
#include "PluginManager.h"
|
2017-07-05 21:54:55 -06:00
|
|
|
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
DFHACK_PLUGIN("pathable");
|
2022-12-31 22:05:03 -07:00
|
|
|
|
|
|
|
REQUIRE_GLOBAL(gps);
|
2017-07-05 21:54:55 -06:00
|
|
|
REQUIRE_GLOBAL(window_x);
|
|
|
|
REQUIRE_GLOBAL(window_y);
|
|
|
|
REQUIRE_GLOBAL(window_z);
|
2022-12-31 22:05:03 -07:00
|
|
|
REQUIRE_GLOBAL(world);
|
|
|
|
|
|
|
|
namespace DFHack {
|
|
|
|
DBG_DECLARE(pathable, log, DebugCategory::LINFO);
|
|
|
|
}
|
2017-07-05 21:54:55 -06:00
|
|
|
|
2022-12-31 22:05:03 -07:00
|
|
|
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands) {
|
2017-07-05 21:54:55 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2022-12-31 22:05:03 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown(color_ostream &out) {
|
2017-07-05 21:54:55 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2022-12-31 22:05:03 -07:00
|
|
|
static void paintScreen(df::coord target, bool skip_unrevealed = false) {
|
|
|
|
DEBUG(log).print("entering paintScreen\n");
|
|
|
|
|
|
|
|
bool use_graphics = Screen::inGraphicsMode();
|
2017-07-05 21:54:55 -06:00
|
|
|
|
2023-01-03 13:08:09 -07:00
|
|
|
int selected_tile_texpos = 0;
|
|
|
|
Screen::findGraphicsTile("CURSORS", 4, 3, &selected_tile_texpos);
|
|
|
|
|
2023-01-12 15:43:46 -07:00
|
|
|
long pathable_tile_texpos = 779;
|
|
|
|
long unpathable_tile_texpos = 782;
|
2023-01-29 01:35:12 -07:00
|
|
|
long on_off_texpos = Textures::getOnOffTexposStart();
|
|
|
|
if (on_off_texpos > 0) {
|
|
|
|
pathable_tile_texpos = on_off_texpos + 0;
|
|
|
|
unpathable_tile_texpos = on_off_texpos + 1;
|
|
|
|
}
|
2023-01-12 15:43:46 -07:00
|
|
|
|
2023-01-01 00:20:46 -07:00
|
|
|
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) {
|
2022-12-31 22:05:03 -07:00
|
|
|
df::coord map_pos(*window_x + x, *window_y + y, *window_z);
|
2017-07-05 21:54:55 -06:00
|
|
|
|
2022-12-31 22:05:03 -07:00
|
|
|
if (!Maps::isValidTilePos(map_pos))
|
2017-07-05 21:54:55 -06:00
|
|
|
continue;
|
|
|
|
|
2022-12-31 22:05:03 -07:00
|
|
|
// don't overwrite the target tile
|
|
|
|
if (!use_graphics && map_pos == target) {
|
|
|
|
TRACE(log).print("skipping target tile\n");
|
2017-07-05 21:54:55 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-12-31 22:05:03 -07:00
|
|
|
if (skip_unrevealed && !Maps::isTileVisible(map_pos)) {
|
|
|
|
TRACE(log).print("skipping hidden tile\n");
|
2017-07-05 21:54:55 -06:00
|
|
|
continue;
|
2022-12-31 22:05:03 -07:00
|
|
|
}
|
2017-07-05 21:54:55 -06:00
|
|
|
|
2022-12-31 22:05:03 -07:00
|
|
|
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);
|
2017-07-05 21:54:55 -06:00
|
|
|
|
2022-12-31 22:05:03 -07:00
|
|
|
if (!cur_tile.valid()) {
|
|
|
|
DEBUG(log).print("cannot read tile at offset %d, %d\n", x, y);
|
|
|
|
continue;
|
2017-07-05 21:54:55 -06:00
|
|
|
}
|
|
|
|
|
2022-12-31 22:05:03 -07:00
|
|
|
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) {
|
2023-01-03 13:08:09 -07:00
|
|
|
cur_tile.tile = selected_tile_texpos;
|
2022-12-31 22:05:03 -07:00
|
|
|
} else{
|
2023-01-12 15:43:46 -07:00
|
|
|
cur_tile.tile = can_walk ?
|
|
|
|
pathable_tile_texpos : unpathable_tile_texpos;
|
2022-12-31 22:05:03 -07:00
|
|
|
}
|
|
|
|
} 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;
|
|
|
|
}
|
2017-07-05 21:54:55 -06:00
|
|
|
|
2022-12-31 22:05:03 -07:00
|
|
|
cur_tile.bold = false;
|
|
|
|
|
|
|
|
if (cur_tile.tile)
|
|
|
|
cur_tile.tile_mode = Screen::Pen::CharColor;
|
|
|
|
}
|
2017-07-05 21:54:55 -06:00
|
|
|
|
|
|
|
Screen::paintTile(cur_tile, x, y, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DFHACK_PLUGIN_LUA_FUNCTIONS {
|
|
|
|
DFHACK_LUA_FUNCTION(paintScreen),
|
|
|
|
DFHACK_LUA_END
|
|
|
|
};
|