Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AIM] Show loot in corpse pockets #53374

Merged
merged 1 commit into from
Dec 13, 2021

Conversation

GoLoT
Copy link
Contributor

@GoLoT GoLoT commented Dec 11, 2021

Summary

Interface "AIM: Show loot in corpse pockets"

Purpose of change

Fixes #53352

Describe the solution

Quick bandaid fix for the issue. If there is a better solution in the works this can be discarded. Or merged for now and reverted when the proper solution is ready.

Describe alternatives you've considered

Not doing it.

Testing

Tried moving some items back and forth between a tile with a corpse and an empty tile.

Additional context

AIMCorpseContents

@github-actions github-actions bot added json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Dec 11, 2021
@dseguin
Copy link
Member

dseguin commented Dec 11, 2021

I think this is an good solution for now.

Not for this PR, but I thought of an idea for containers in AIM:
For a more general fix, it might be good to add a new pane area for containers. We have C, but it only works for liquid containers (and appears to be broken at the moment?):
aim_liq_only

The liquid container area could be moved to something like L and C could be used for general containers (including loot from corpses):
aim_container

(Expand) Here's a rough diff that would accomplish some of that:
diff --git a/data/raw/keybindings.json b/data/raw/keybindings.json
index b1b3dd8a34..8b868ab9c3 100644
--- a/data/raw/keybindings.json
+++ b/data/raw/keybindings.json
@@ -3243,6 +3243,16 @@
     "name": "Examine items in container",
     "bindings": [ { "input_method": "keyboard_char", "key": "o" } ]
   },
+  {
+    "type": "keybinding",
+    "id": "ITEMS_LIQUID",
+    "category": "ADVANCED_INVENTORY",
+    "name": "Select items in container",
+    "bindings": [
+      { "input_method": "keyboard_char", "key": "L" },
+      { "input_method": "keyboard_code", "key": "l", "mod": [ "shift" ] }
+    ]
+  },
   {
     "type": "keybinding",
     "id": "ITEMS_CONTAINER",
diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp
index 79f8282f85..ba6da7e672 100644
--- a/src/advanced_inv.cpp
+++ b/src/advanced_inv.cpp
@@ -131,7 +131,8 @@ advanced_inventory::advanced_inventory()
         { AIM_NORTHEAST, point( 36, 1 ), tripoint_north_east, _( "North East" ),         _( "NE" ),  "9", "ITEMS_NE",        AIM_EAST},
         { AIM_DRAGGED,   point( 25, 1 ), tripoint_zero,       _( "Grabbed Vehicle" ),    _( "GR" ),  "D", "ITEMS_DRAGGED_CONTAINER", AIM_DRAGGED},
         { AIM_ALL,       point( 22, 3 ), tripoint_zero,       _( "Surrounding area" ),   _( "AL" ),  "A", "ITEMS_AROUND",    AIM_ALL},
-        { AIM_CONTAINER, point( 22, 1 ), tripoint_zero,       _( "Container" ),          _( "CN" ),  "C", "ITEMS_CONTAINER", AIM_CONTAINER},
+        { AIM_LIQUID,    point( 22, 1 ), tripoint_zero,       _( "Liquid" ),             _( "LQ" ),  "L", "ITEMS_LIQUID",    AIM_LIQUID},
+        { AIM_CONTAINER, point( 22, 2 ), tripoint_zero,       _( "Container" ),          _( "CN" ),  "C", "ITEMS_CONTAINER", AIM_CONTAINER},
         { AIM_WORN,      point( 25, 3 ), tripoint_zero,       _( "Worn Items" ),         _( "WR" ),  "W", "ITEMS_WORN",      AIM_WORN}
     }
 } )
@@ -296,7 +297,7 @@ void advanced_inventory::print_items( const advanced_inventory_pane &pane, bool
         } else {
             units::volume maxvolume = 0_ml;
             advanced_inv_area &s = squares[pane.get_area()];
-            if( pane.get_area() == AIM_CONTAINER && s.get_container( pane.in_vehicle() ) ) {
+            if( ( pane.get_area() == AIM_CONTAINER || pane.get_area() == AIM_LIQUID ) && s.get_container( pane.in_vehicle() ) ) {
                 maxvolume = s.get_container( pane.in_vehicle() )->get_total_capacity();
             } else if( pane.in_vehicle() ) {
                 maxvolume = s.veh->max_volume( s.vstor );
@@ -896,7 +897,7 @@ bool advanced_inventory::move_all_items()
             // TODO: implement this
             popup( _( "Putting on everything from your inventory would be tricky." ) );
             return false;
-        } else if( dpane.get_area() == AIM_CONTAINER ) {
+        } else if( dpane.get_area() == AIM_CONTAINER || dpane.get_area() == AIM_LIQUID ) {
             // TODO: implement this
             popup( _( "Putting everything into the container would be tricky." ) );
             return false;
@@ -1183,6 +1184,7 @@ input_context advanced_inventory::register_ctxt() const
     ctxt.register_action( "ITEMS_WORN" );
     ctxt.register_action( "ITEMS_AROUND" );
     ctxt.register_action( "ITEMS_DRAGGED_CONTAINER" );
+    ctxt.register_action( "ITEMS_LIQUID" );
     ctxt.register_action( "ITEMS_CONTAINER" );
 
     ctxt.register_action( "ITEMS_DEFAULT" );
@@ -1237,9 +1239,9 @@ void advanced_inventory::change_square( const aim_location changeSquare,
         // we need to check the original area if we can place items in vehicle storage
     } else if( squares[changeSquare].canputitems( spane.get_cur_item_ptr() ) ) {
         bool in_vehicle_cargo = false;
-        if( changeSquare == AIM_CONTAINER ) {
+        if( changeSquare == AIM_CONTAINER || changeSquare == AIM_LIQUID ) {
             squares[changeSquare].set_container( spane.get_cur_item_ptr() );
-        } else if( spane.get_area() == AIM_CONTAINER ) {
+        } else if( spane.get_area() == AIM_CONTAINER || spane.get_area() == AIM_LIQUID ) {
             squares[changeSquare].set_container( nullptr );
             // auto select vehicle if items exist at said square, or both are empty
         } else if( squares[changeSquare].can_store_in_vehicle() && spane.get_area() != changeSquare ) {
@@ -1366,7 +1368,7 @@ bool advanced_inventory::action_move_item( advanced_inv_listitem *sitem,
     // but are potentially at a different place).
     recalc = true;
     cata_assert( amount_to_move > 0 );
-    if( destarea == AIM_CONTAINER ) {
+    if( destarea == AIM_LIQUID ) {
         if( !move_content( *sitem->items.front(),
                            *squares[destarea].get_container( to_vehicle ) ) ) {
             return false;
@@ -1435,6 +1437,17 @@ bool advanced_inventory::action_move_item( advanced_inv_listitem *sitem,
             popup( _( "You have no space for %s" ), sitem->items.front()->tname() );
             return false;
         }
+        if( destarea == AIM_CONTAINER ) {
+            item_location cont_it = squares[destarea].get_container( to_vehicle );
+            if( cont_it.get_item() == nullptr ) {
+                debugmsg( "Tried to insert item \"%s\" into non-container \"%s\"", sitem->items.front()->typeId().str(), squares[destarea].name );
+                return false;
+            }
+            if( !cont_it->can_contain( *sitem->items.front() ).success() ) {
+                popup( _( "%1$s can't contain %2$s" ), cont_it->tname(), sitem->items.front()->tname() );
+                return false;
+            }
+        }
         // from map/vehicle: start ACT_PICKUP or ACT_MOVE_ITEMS as necessary
         // Make sure advanced inventory is reopened after activity completion.
         do_return_entry();
@@ -1905,7 +1918,8 @@ bool advanced_inventory::query_charges( aim_location destarea, const advanced_in
     // Map and vehicles have a maximal item count, check that. Inventory does not have this.
     if( destarea != AIM_INVENTORY &&
         destarea != AIM_WORN &&
-        destarea != AIM_CONTAINER ) {
+        destarea != AIM_CONTAINER &&
+        destarea != AIM_LIQUID ) {
         const int cntmax = p.max_size - p.get_item_count();
         // For items counted by charges, adding it adds 0 items if something there stacks with it.
         const bool adds0 = by_charges && std::any_of( panes[dest].items.begin(), panes[dest].items.end(),
diff --git a/src/advanced_inv_area.cpp b/src/advanced_inv_area.cpp
index 9fa7524ca9..c8905fb2e0 100644
--- a/src/advanced_inv_area.cpp
+++ b/src/advanced_inv_area.cpp
@@ -109,6 +109,7 @@ void advanced_inv_area::init()
             }
             break;
         case AIM_CONTAINER:
+        case AIM_LIQUID:
             // set container position based on location
             set_container_position();
             // location always valid, actual check is done in canputitems()
@@ -206,7 +207,8 @@ bool advanced_inv_area::is_same( const advanced_inv_area &other ) const
     // e.g. dragged vehicle (to the south) and AIM_SOUTH are the same.
     if( id != AIM_INVENTORY && other.id != AIM_INVENTORY &&
         id != AIM_WORN && other.id != AIM_WORN &&
-        id != AIM_CONTAINER && other.id != AIM_CONTAINER ) {
+        id != AIM_CONTAINER && other.id != AIM_CONTAINER &&
+        id != AIM_LIQUID && other.id != AIM_LIQUID ) {
         //     have a vehicle?...     ...do the cargo index and pos match?...    ...at least pos?
         return veh == other.veh ? pos == other.pos && vstor == other.vstor : pos == other.pos;
     }
@@ -218,21 +220,27 @@ bool advanced_inv_area::canputitems( const advanced_inv_listitem *advitem )
 {
     bool canputitems = false;
     bool from_vehicle = false;
+    item_location it;
+    if( advitem != nullptr ) {
+        it = advitem->items.front();
+        from_vehicle = advitem->from_vehicle;
+    }
+    if( get_container( from_vehicle ) ) {
+        it = get_container( from_vehicle );
+    }
     switch( id ) {
-        case AIM_CONTAINER: {
-            item_location it;
-            if( advitem != nullptr ) {
-                it = advitem->items.front();
-                from_vehicle = advitem->from_vehicle;
-            }
-            if( get_container( from_vehicle ) ) {
-                it = get_container( from_vehicle );
-            }
+        case AIM_LIQUID:
             if( it ) {
                 canputitems = it->is_watertight_container();
             }
             break;
-        }
+        case AIM_CONTAINER:
+            if( it ) {
+                canputitems = it->is_container() && !it->is_watertight_container();
+            } else if( !advitem ) {
+                canputitems = canputitemsloc;
+            }
+            break;
         default:
             canputitems = canputitemsloc;
             break;
diff --git a/src/advanced_inv_area.h b/src/advanced_inv_area.h
index cb326c0120..de088786df 100644
--- a/src/advanced_inv_area.h
+++ b/src/advanced_inv_area.h
@@ -23,6 +23,7 @@ enum aim_location : char {
     AIM_NORTHEAST,
     AIM_DRAGGED,
     AIM_ALL,
+    AIM_LIQUID,
     AIM_CONTAINER,
     AIM_WORN,
     NUM_AIM_LOCATIONS,
diff --git a/src/advanced_inv_pane.cpp b/src/advanced_inv_pane.cpp
index fe5b399dcd..6f45c1071e 100644
--- a/src/advanced_inv_pane.cpp
+++ b/src/advanced_inv_pane.cpp
@@ -201,7 +201,7 @@ void advanced_inventory_pane::add_items_from_area( advanced_inv_area &square,
             square.weight += it.weight;
             items.push_back( it );
         }
-    } else if( square.id == AIM_CONTAINER ) {
+    } else if( square.id == AIM_CONTAINER || square.id == AIM_LIQUID ) {
         square.volume = 0_ml;
         square.weight = 0_gram;
         const item_location cont = square.get_container( in_vehicle() );

@Maleclypse Maleclypse added the Controls / Input Keyboard, mouse, keybindings, input UI, etc. label Dec 12, 2021
@l29ah
Copy link
Contributor

l29ah commented Dec 12, 2021

Works great, thanks!

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Dec 12, 2021
@kevingranade kevingranade merged commit e423864 into CleverRaven:master Dec 13, 2021
@wapcaplet wapcaplet added <Bugfix> This is a fix for a bug (or closes open issue) Inventory / AIM / Zones Inventory, Advanced Inventory Management or Zones labels Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) Controls / Input Keyboard, mouse, keybindings, input UI, etc. Inventory / AIM / Zones Inventory, Advanced Inventory Management or Zones json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No way to undress a corpse in AIM
6 participants