Skip to content

Commit

Permalink
Autodump in fortifications; fixes
Browse files Browse the repository at this point in the history
* Update changelog.txt
* Update Items.cpp
* Update MapCache.cpp
* Update autodump.cpp
* Update autodump.rst
  • Loading branch information
Bumber64 authored Jul 31, 2024
1 parent 171af64 commit e948b7b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 37 deletions.
2 changes: 1 addition & 1 deletion docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions docs/plugins/autodump.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
29 changes: 3 additions & 26 deletions library/modules/Items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<df::viewscreen_itemst>(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;
Expand Down
6 changes: 1 addition & 5 deletions library/modules/MapCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions plugins/autodump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ static command_result autodump_main(color_ostream &out, vector<string> &paramete
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;
Expand Down

0 comments on commit e948b7b

Please sign in to comment.