From e948b7be31bcb08198cb21836950e5cd035dedde Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Tue, 30 Jul 2024 22:24:43 -0700 Subject: [PATCH] Autodump in fortifications; fixes * Update changelog.txt * Update Items.cpp * Update MapCache.cpp * Update autodump.cpp * Update autodump.rst --- docs/changelog.txt | 2 +- docs/plugins/autodump.rst | 5 +++-- library/modules/Items.cpp | 29 +++-------------------------- library/modules/MapCache.cpp | 6 +----- plugins/autodump.cpp | 6 +++--- 5 files changed, 11 insertions(+), 37 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 417c723fac..6ba928cac2 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -75,7 +75,6 @@ Template for new versions: - ``Units::getRaceChildName``, ``getRaceChildNameById``, ``getRaceBabyName``, ``getRaceBabyNameById``: bool ``plural`` to get plural form - ``Units::getProfessionName``: bool ``land_title`` to append "of Sitename" where applicable, use Prisoner/Slave and noble spouse titles (controlled by ``ignore_noble``) - `plant`: detect trees via branches/leaves for cuboid selection -- ``Items``: module no longer dependent on MapCache. No longer need to pass MapCache parameter to ``moveToGround``, ``moveToContainer``, ``moveToBuilding``, ``moveToInventory``, ``makeProjectile``, or ``Items::remove`` - `autodump`: allow dumping items into air, converting into projectile like ``gui/autodump`` ## Documentation @@ -90,6 +89,7 @@ Template for new versions: - ``Units::getCasteRaw``: get a caste_raw from a unit or race and caste - ``cuboid``: construct from ``df::map_block*``, ``forBlock`` iterator to access map blocks in cuboid - ``cuboid``: ``clamp(cuboid other)``, ``clampNew(cuboid other)`` for cuboid intersection. ``clampNew`` returns new cuboid instead of modifying. +- ``Items``: module no longer dependent on MapCache. No longer need to pass MapCache parameter to ``moveToGround``, ``moveToContainer``, ``moveToBuilding``, ``moveToInventory``, ``makeProjectile``, or ``Items::remove`` ## Lua - ``ZScreen``: new ``defocused`` property for starting screens without keyboard focus diff --git a/docs/plugins/autodump.rst b/docs/plugins/autodump.rst index 273d830424..adb344319b 100644 --- a/docs/plugins/autodump.rst +++ b/docs/plugins/autodump.rst @@ -10,11 +10,12 @@ autodump This tool can instantly move all unforbidden items marked for dumping to the tile under the keyboard cursor. After moving the items, the dump flag is unset -and the forbid flag is set, just as if it had been dumped normally. +and the forbid flag is set, just as if it had been dumped normally. See +``gui/autodump`` for an interactive version of this tool. The keyboard cursor can be placed on a floor tile or in the air. If in air, the items will be converted into projectiles and fall. Items cannot be dumped -inside of walls nor fortifications. +inside of walls. Usage ----- diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index 582e921f13..ff4ed922dd 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -907,10 +907,7 @@ static bool removeItemOnGround(df::item *item) if (!block) return false; - int idx = binsearch_index(block->items, item->id); - if (idx < 0) - return false; - vector_erase_at(block->items, idx); + erase_from_vector(block->items, item->id); for (auto b_item : block->items) { auto other_item = df::item::find(b_item); @@ -1005,33 +1002,13 @@ static bool detachItem(df::item *item) case general_ref_type::CONTAINED_IN_ITEM: if (auto item2 = ref->getItem()) { - /* TODO: understand how this changes for v50 - // Viewscreens hold general_ref_contains_itemst pointers - for (auto screen = Core::getTopViewscreen(); screen; screen = screen->parent) - { - auto vsitem = strict_virtual_cast(screen); - if (vsitem && vsitem->item == item2) - return false; - } - */ item2->flags.bits.weight_computed = false; - DFHack::removeRef(item2->general_refs, general_ref_type::CONTAINS_ITEM, item->id); } break; case general_ref_type::UNIT_HOLDER: - if (auto unit = ref->getUnit()) - { - /* TODO: understand how this changes for v50 - // Unit view sidebar holds inventory item pointers - if (plotinfo->main.mode == ui_sidebar_mode::ViewUnits && - (!ui_selected_unit || - vector_get(world->units.active, *ui_selected_unit) == unit)) - return false; - */ - - for (int i = unit->inventory.size()-1; i >= 0; i--) - { + if (auto unit = ref->getUnit()) { + for (int i = unit->inventory.size()-1; i >= 0; i--) { df::unit_inventory_item *inv_item = unit->inventory[i]; if (inv_item->item != item) continue; diff --git a/library/modules/MapCache.cpp b/library/modules/MapCache.cpp index 33bda7a011..c01f5bf576 100644 --- a/library/modules/MapCache.cpp +++ b/library/modules/MapCache.cpp @@ -1207,11 +1207,7 @@ bool MapExtras::Block::removeItemOnGround(df::item *item) init_item_counts(); - int idx = binsearch_index(block->items, item->id); - if (idx < 0) - return false; - - vector_erase_at(block->items, idx); + erase_from_vector(block->items,item->id); int &count = index_tile(item_counts,item->pos); diff --git a/plugins/autodump.cpp b/plugins/autodump.cpp index 149a2d5324..f425707faa 100644 --- a/plugins/autodump.cpp +++ b/plugins/autodump.cpp @@ -125,10 +125,10 @@ static command_result autodump_main(color_ostream &out, vector ¶mete out.printerr("Cursor is in an invalid/uninitialized area.\n"); return CR_FAILURE; } - else if(!isWalkable(*ttype)) - { // Not floor, stair, nor ramp. + else if(!isWalkable(*ttype) && tileShape(*ttype) != tiletype_shape::FORTIFICATION) + { // Not floor, stair, ramp, nor fortification. if (tileShapeBasic(tileShape(*ttype)) == tiletype_shape_basic::Wall) { - out.printerr("Can't dump inside walls or fortifications.\n"); + out.printerr("Can't dump inside walls.\n"); return CR_FAILURE; } make_projectile = true;