1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
From db0b41135105d165ead640d4d4d46d220491c873 Mon Sep 17 00:00:00 2001
From: joveeater <joveasarus@gmail.com>
Date: Sat, 13 Jan 2024 12:21:59 +0000
Subject: [PATCH] fix: Prevents reloading from deleting containers (#4104)
* Prevents reloading from deleting containers
* style(autofix.ci): automated formatting
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
---
src/item.cpp | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/src/item.cpp b/src/item.cpp
index 25051aeb76c..b4667994e17 100644
--- a/src/item.cpp
+++ b/src/item.cpp
@@ -8186,9 +8186,7 @@ bool item::reload( player &u, item &loc, int qty )
}
}
- detached_ptr<item> to_reload = item::spawn( *ammo );
- to_reload->charges = qty;
- ammo->charges -= qty;
+ detached_ptr<item> to_reload = ammo->split( qty );
bool merged = false;
for( item *it : contents.all_items_top() ) {
if( it->merge_charges( std::move( to_reload ) ) ) {
@@ -8246,19 +8244,17 @@ bool item::reload( player &u, item &loc, int qty )
ammo->charges -= qty;
charges += qty;
}
- }
-
- // we have transfered ammo from the container to the item
- // therefore, we erase the 0-charge item inside container
- // TODO: why don't we just remove 0-charge items?
- if( ammo->charges == 0 && !ammo->has_flag( flag_SPEEDLOADER ) ) {
- if( container != nullptr && !container->contents.empty() ) {
- container->remove_item( container->contents.front() );
- u.inv_restack( ); // emptied containers do not stack with non-empty ones
- } else {
- loc.detach();
+ // we have transfered ammo from the container to the item
+ // therefore, we erase the 0-charge item inside container
+ // TODO: why don't we just remove 0-charge items?
+ if( ammo->charges == 0 && !ammo->has_flag( flag_SPEEDLOADER ) ) {
+ ammo->detach();
+ if( container != nullptr ) {
+ u.inv_restack();
+ }
}
}
+
return true;
}
--
2.43.0
|