diff --git a/NEWS b/NEWS index 65339ad64..e066b7431 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,9 @@ DFHack future - Nothing yet! + Internals: + - support for displaying active keybindings properly. + Misc improvements: + - fastdwarf: new mode using debug flags, and some internal consistency fixes. DFHack v0.34.11-r2 diff --git a/library/include/df/custom/coord_path.methods.inc b/library/include/df/custom/coord_path.methods.inc index 9acebb82a..5421796e3 100644 --- a/library/include/df/custom/coord_path.methods.inc +++ b/library/include/df/custom/coord_path.methods.inc @@ -1,5 +1,12 @@ +bool empty() const { return x.empty(); } unsigned size() const { return x.size(); } +void clear() { + x.clear(); + y.clear(); + z.clear(); +} + coord operator[] (unsigned idx) const { if (idx >= x.size()) return coord(); diff --git a/library/include/modules/MapCache.h b/library/include/modules/MapCache.h index ac083075f..c1c478bc6 100644 --- a/library/include/modules/MapCache.h +++ b/library/include/modules/MapCache.h @@ -47,14 +47,6 @@ namespace MapExtras class DFHACK_EXPORT MapCache; -template inline R index_tile(T &v, df::coord2d p) { - return v[p.x&15][p.y&15]; -} - -inline bool is_valid_tile_coord(df::coord2d p) { - return (p.x & ~15) == 0 && (p.y & ~15) == 0; -} - class Block; class BlockInfo diff --git a/library/include/modules/Maps.h b/library/include/modules/Maps.h index 3150acccf..632e8ec13 100644 --- a/library/include/modules/Maps.h +++ b/library/include/modules/Maps.h @@ -151,6 +151,21 @@ typedef uint8_t biome_indices40d [9]; */ typedef uint16_t t_temperatures [16][16]; +/** + * Index a tile array by a 2D coordinate, clipping it to mod 16 + */ +template inline R index_tile(T &v, df::coord2d p) { + return v[p.x&15][p.y&15]; +} + +/** + * Check if a 2D coordinate is in the 0-15 range. + */ +inline bool is_valid_tile_coord(df::coord2d p) { + return (p.x & ~15) == 0 && (p.y & ~15) == 0; +} + + /** * The Maps module * \ingroup grp_modules diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 5ef4ce829..482b950ba 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -454,7 +454,7 @@ df::coord2d Maps::getBlockTileBiomeRgn(df::map_block *block, df::coord2d pos) if (!block || !world->world_data) return df::coord2d(); - auto des = MapExtras::index_tile(block->designation,pos); + auto des = index_tile(block->designation,pos); unsigned idx = des.bits.biome; if (idx < 9) { @@ -529,8 +529,8 @@ bool Maps::canWalkBetween(df::coord pos1, df::coord pos2) if (!block1 || !block2) return false; - auto tile1 = MapExtras::index_tile(block1->walkable, pos1); - auto tile2 = MapExtras::index_tile(block2->walkable, pos2); + auto tile1 = index_tile(block1->walkable, pos1); + auto tile2 = index_tile(block2->walkable, pos2); return tile1 && tile1 == tile2; } diff --git a/plugins/fastdwarf.cpp b/plugins/fastdwarf.cpp index 3f3905ecc..28104b909 100644 --- a/plugins/fastdwarf.cpp +++ b/plugins/fastdwarf.cpp @@ -60,7 +60,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if (enable_teledwarf) do { // don't do anything if the dwarf isn't going anywhere - if (unit->path.dest.x == -30000) + if (!unit->path.dest.isValid()) break; // skip dwarves that are dragging creatures or being dragged @@ -71,33 +71,36 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if (unit->relations.following != 0) break; - old_block = Maps::getTileBlock(unit->pos.x, unit->pos.y, unit->pos.z); - new_block = Maps::getTileBlock(unit->path.dest.x, unit->path.dest.y, unit->path.dest.z); + // skip unconscious units + if (unit->counters.unconscious > 0) + break; + // make sure source and dest map blocks are valid - if (!old_block || !new_block) + auto old_occ = Maps::getTileOccupancy(unit->pos); + auto new_occ = Maps::getTileOccupancy(unit->path.dest); + if (!old_occ || !new_occ) break; // clear appropriate occupancy flags at old tile if (unit->flags1.bits.on_ground) // this is technically wrong, but the game will recompute this as needed - old_block->occupancy[unit->pos.x & 0xF][unit->pos.y & 0xF].bits.unit_grounded = 0; + old_occ->bits.unit_grounded = 0; else - old_block->occupancy[unit->pos.x & 0xF][unit->pos.y & 0xF].bits.unit = 0; + old_occ->bits.unit = 0; // if there's already somebody standing at the destination, then force the unit to lay down - if (new_block->occupancy[unit->path.dest.x & 0xF][unit->path.dest.y & 0xF].bits.unit) + if (new_occ->bits.unit) unit->flags1.bits.on_ground = 1; // set appropriate occupancy flags at new tile if (unit->flags1.bits.on_ground) - new_block->occupancy[unit->path.dest.x & 0xF][unit->path.dest.y & 0xF].bits.unit_grounded = 1; + new_occ->bits.unit_grounded = 1; else - new_block->occupancy[unit->path.dest.x & 0xF][unit->path.dest.y & 0xF].bits.unit = 1; + new_occ->bits.unit = 1; // move unit to destination - unit->pos.x = unit->path.dest.x; - unit->pos.y = unit->path.dest.y; - unit->pos.z = unit->path.dest.z; + unit->pos = unit->path.dest; + unit->path.path.clear(); } while (0); } return CR_OK;