From d01bbb38601faacdf8108c3aaee7459fafe97333 Mon Sep 17 00:00:00 2001
From: bombasticSlacks <dillon.matchett@gmail.com>
Date: Thu, 28 Jul 2022 10:26:29 -0300
Subject: [PATCH] new mode with interrupts working correctly

---
 src/activity_actor.cpp           | 21 ++++++++++++++-------
 src/activity_actor_definitions.h |  2 +-
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp
index de4654fa1c8cc..6684fb34e1211 100644
--- a/src/activity_actor.cpp
+++ b/src/activity_actor.cpp
@@ -6038,11 +6038,6 @@ void unload_loot_activity_actor::start( player_activity &act, Character & )
     act.moves_left = moves;
 }
 
-void unload_loot_activity_actor::finish( player_activity &act, Character &who )
-{
-    act.set_to_null();
-}
-
 static void move_item( Character &you, item &it, const int quantity, const tripoint &src,
                        const tripoint &dest, vehicle *src_veh, int src_part )
 {
@@ -6096,7 +6091,7 @@ void unload_loot_activity_actor::do_turn( player_activity &act, Character &you )
     };
 
     faction const *fac = you.get_faction();
-    faction_id fac_id  = fac == nullptr ? faction_id() : fac->id;
+    faction_id fac_id = fac == nullptr ? faction_id() : fac->id;
 
     map &here = get_map();
     const tripoint_abs_ms abspos = you.get_location();
@@ -6261,16 +6256,18 @@ void unload_loot_activity_actor::do_turn( player_activity &act, Character &you )
 
         //Skip items that have already been processed
         for( auto it = items.begin() + num_processed; it < items.end(); ++it ) {
-            ++num_processed;
+
             item &thisitem = *it->first;
 
             // skip unpickable liquid
             if( thisitem.made_of_from_type( phase_id::LIQUID ) ) {
+                ++num_processed;
                 continue;
             }
 
             // skip favorite items in ignore favorite zones
             if( thisitem.is_favorite && mgr.has( zone_type_LOOT_IGNORE_FAVORITES, src, fac_id ) ) {
+                ++num_processed;
                 continue;
             }
 
@@ -6291,6 +6288,9 @@ void unload_loot_activity_actor::do_turn( player_activity &act, Character &you )
                             move_item( you, *contained, contained->count(), src_loc, src_loc, this_veh, this_part );
                             it->first->remove_item( *contained );
                         }
+                        if( you.moves <= 0 ) {
+                            return;
+                        }
                     }
                     for( item *contained : it->first->all_items_top( item_pocket::pocket_type::MAGAZINE ) ) {
                         // no liquids don't want to spill stuff
@@ -6298,6 +6298,9 @@ void unload_loot_activity_actor::do_turn( player_activity &act, Character &you )
                             move_item( you, *contained, contained->count(), src_loc, src_loc, this_veh, this_part );
                             it->first->remove_item( *contained );
                         }
+                        if( you.moves <= 0 ) {
+                            return;
+                        }
                     }
                     for( item *contained : it->first->all_items_top( item_pocket::pocket_type::MAGAZINE_WELL ) ) {
                         // no liquids don't want to spill stuff
@@ -6305,9 +6308,13 @@ void unload_loot_activity_actor::do_turn( player_activity &act, Character &you )
                             move_item( you, *contained, contained->count(), src_loc, src_loc, this_veh, this_part );
                             it->first->remove_item( *contained );
                         }
+                        if( you.moves <= 0 ) {
+                            return;
+                        }
                     }
                     // after dumping items go back to start of activity loop
                     // so that can re-assess the items in the tile
+                    ++num_processed;
                     return;
                 }
             }
diff --git a/src/activity_actor_definitions.h b/src/activity_actor_definitions.h
index 34a9905931e6f..35c0af68506eb 100644
--- a/src/activity_actor_definitions.h
+++ b/src/activity_actor_definitions.h
@@ -1855,7 +1855,7 @@ class unload_loot_activity_actor : public activity_actor
 
         void start( player_activity &act, Character &who ) override;
         void do_turn( player_activity &act, Character &you ) override;
-        void finish( player_activity &act, Character &who ) override;
+        void finish( player_activity &act, Character &who ) override {};
 
         std::unique_ptr<activity_actor> clone() const override {
             return std::make_unique<unload_loot_activity_actor>( *this );