add api for getting the walkability group of a tile

develop
Myk Taylor 2023-10-29 16:36:02 -07:00
parent fd63e28f39
commit 19480f41ca
No known key found for this signature in database
6 changed files with 23 additions and 20 deletions

@ -67,9 +67,11 @@ Template for new versions:
## API ## API
- ``Gui::revealInDwarfmodeMap``: gained ``highlight`` parameter to control setting the tile highlight on the zoom target - ``Gui::revealInDwarfmodeMap``: gained ``highlight`` parameter to control setting the tile highlight on the zoom target
- ``Maps::getWalkableGroup``: get the walkability group of a tile
## Lua ## Lua
- ``dfhack.gui.revealInDwarfmodeMap``: gained ``highlight`` parameter to control setting the tile highlight on the zoom target - ``dfhack.gui.revealInDwarfmodeMap``: gained ``highlight`` parameter to control setting the tile highlight on the zoom target
- ``dfhack.maps.getWalkableGroup``: get the walkability group of a tile
## Removed ## Removed

@ -1912,10 +1912,11 @@ Maps module
Returns the plant struct that owns the tile at the specified position. Returns the plant struct that owns the tile at the specified position.
* ``dfhack.maps.canWalkBetween(pos1, pos2)`` * ``dfhack.maps.getWalkableGroup(pos)``
Checks if a dwarf may be able to walk between the two tiles, Returns the walkability group for the given tile position. A return value of
using a pathfinding cache maintained by the game. ``0`` indicates that the tile is not walkable. The data comes from a
pathfinding cache maintained by DF.
.. note:: .. note::
This cache is only updated when the game is unpaused, and thus This cache is only updated when the game is unpaused, and thus
@ -1924,6 +1925,10 @@ Maps module
take into account anything that depends on the actual units, like take into account anything that depends on the actual units, like
burrows, or the presence of invaders. burrows, or the presence of invaders.
* ``dfhack.maps.canWalkBetween(pos1, pos2)``
Checks if both positions are walkable and also share a walkability group.
* ``dfhack.maps.hasTileAssignment(tilemask)`` * ``dfhack.maps.hasTileAssignment(tilemask)``
Checks if the tile_bitmask object is not *nil* and contains any set bits; returns *true* or *false*. Checks if the tile_bitmask object is not *nil* and contains any set bits; returns *true* or *false*.

@ -2239,6 +2239,7 @@ static const LuaWrapper::FunctionReg dfhack_maps_module[] = {
WRAPM(Maps, enableBlockUpdates), WRAPM(Maps, enableBlockUpdates),
WRAPM(Maps, getGlobalInitFeature), WRAPM(Maps, getGlobalInitFeature),
WRAPM(Maps, getLocalInitFeature), WRAPM(Maps, getLocalInitFeature),
WRAPM(Maps, getWalkableGroup),
WRAPM(Maps, canWalkBetween), WRAPM(Maps, canWalkBetween),
WRAPM(Maps, spawnFlow), WRAPM(Maps, spawnFlow),
WRAPN(hasTileAssignment, hasTileAssignment), WRAPN(hasTileAssignment, hasTileAssignment),

@ -339,6 +339,7 @@ extern DFHACK_EXPORT bool SortBlockEvents(df::map_block *block,
extern DFHACK_EXPORT bool RemoveBlockEvent(int32_t x, int32_t y, int32_t z, df::block_square_event * which ); extern DFHACK_EXPORT bool RemoveBlockEvent(int32_t x, int32_t y, int32_t z, df::block_square_event * which );
extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which ); // todo: deprecate me extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which ); // todo: deprecate me
DFHACK_EXPORT uint16_t getWalkableGroup(df::coord pos);
DFHACK_EXPORT bool canWalkBetween(df::coord pos1, df::coord pos2); DFHACK_EXPORT bool canWalkBetween(df::coord pos1, df::coord pos2);
DFHACK_EXPORT bool canStepBetween(df::coord pos1, df::coord pos2); DFHACK_EXPORT bool canStepBetween(df::coord pos1, df::coord pos2);

@ -622,16 +622,15 @@ bool Maps::ReadGeology(vector<vector<int16_t> > *layer_mats, vector<df::coord2d>
return true; return true;
} }
uint16_t Maps::getWalkableGroup(df::coord pos) {
auto block = getTileBlock(pos);
return block ? index_tile(block->walkable, pos) : 0;
}
bool Maps::canWalkBetween(df::coord pos1, df::coord pos2) bool Maps::canWalkBetween(df::coord pos1, df::coord pos2)
{ {
auto block1 = getTileBlock(pos1); auto tile1 = getWalkableGroup(pos1);
auto block2 = getTileBlock(pos2); auto tile2 = getWalkableGroup(pos2);
if (!block1 || !block2)
return false;
auto tile1 = index_tile(block1->walkable, pos1);
auto tile2 = index_tile(block2->walkable, pos2);
return tile1 && tile1 == tile2; return tile1 && tile1 == tile2;
} }

@ -12,7 +12,6 @@
#include "df/item.h" #include "df/item.h"
#include "df/item_slabst.h" #include "df/item_slabst.h"
#include "df/job.h" #include "df/job.h"
#include "df/map_block.h"
#include "df/world.h" #include "df/world.h"
#include <unordered_map> #include <unordered_map>
@ -48,14 +47,10 @@ struct BadFlags {
// up or down (e.g. for stairs). For now, just return if the item is on a walkable tile. // up or down (e.g. for stairs). For now, just return if the item is on a walkable tile.
static bool isAccessible(color_ostream& out, df::item* item) { static bool isAccessible(color_ostream& out, df::item* item) {
df::coord item_pos = Items::getPosition(item); df::coord item_pos = Items::getPosition(item);
df::map_block* block = Maps::getTileBlock(item_pos); uint16_t walkability_group = Maps::getWalkableGroup(item_pos);
bool is_walkable = false; bool is_walkable = walkability_group != 0;
if (block) {
uint16_t walkability_group = index_tile(block->walkable, item_pos);
is_walkable = walkability_group != 0;
TRACE(cycle, out).print("item %d in walkability_group %u at (%d,%d,%d) is %saccessible from job site\n", TRACE(cycle, out).print("item %d in walkability_group %u at (%d,%d,%d) is %saccessible from job site\n",
item->id, walkability_group, item_pos.x, item_pos.y, item_pos.z, is_walkable ? "(probably) " : "not "); item->id, walkability_group, item_pos.x, item_pos.y, item_pos.z, is_walkable ? "(probably) " : "not ");
}
return is_walkable; return is_walkable;
} }