Skip to content

Commit

Permalink
Fix invalidation of soft container nested in a holster
Browse files Browse the repository at this point in the history
  • Loading branch information
wwkk222208 committed Mar 16, 2024
1 parent 1c1c08a commit 9f92b0f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 39 deletions.
30 changes: 0 additions & 30 deletions data/mods/MindOverMatter/items/psions_summon_items.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -540,7 +539,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -568,7 +566,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -596,7 +593,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -624,7 +620,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -652,7 +647,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -680,7 +674,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -708,7 +701,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -736,7 +728,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -764,7 +755,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -792,7 +782,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -820,7 +809,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -848,7 +836,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -876,7 +863,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -904,7 +890,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -932,7 +917,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -960,7 +944,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -988,7 +971,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -1016,7 +998,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -1044,7 +1025,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -1072,7 +1052,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -1100,7 +1079,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -1128,7 +1106,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -1156,7 +1133,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -1184,7 +1160,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -1212,7 +1187,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -1240,7 +1214,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -1268,7 +1241,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -1296,7 +1268,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down Expand Up @@ -1324,7 +1295,6 @@
"max_item_length": "2000 cm",
"moves": 10,
"weight_multiplier": 0.0,
"volume_multiplier": 0.0,
"volume_encumber_modifier": 0
}
]
Expand Down
4 changes: 2 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10077,11 +10077,11 @@ ret_val<void> item::can_contain( const item &it, int &copies_remaining, const bo
continue;
}

// If the current pocket has restrictions or blacklists the item,
// If the current pocket has restrictions or blacklists the item or is a holster,
// try the nested pocket regardless of whether it's soft or rigid.
const bool ignore_nested_rigidity =
!pkt->settings.accepts_item( it ) ||
!pkt->get_pocket_data()->get_flag_restrictions().empty();
!pkt->get_pocket_data()->get_flag_restrictions().empty() || pkt->is_holster();
for( const item *internal_it : pkt->all_items_top() ) {
if( parent_it.where() != item_location::type::invalid && internal_it == parent_it.get_item() ) {
continue;
Expand Down
21 changes: 16 additions & 5 deletions src/item_contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2260,11 +2260,22 @@ units::volume item_contents::total_container_capacity( const bool unrestricted_p
restriction_condition = restriction_condition && !pocket.is_restricted();
}
if( restriction_condition ) {
// if the pocket has default volume or is a holster that has an
// item in it or is a pocket that has normal pickup disabled
// instead of returning the volume return the volume of things contained
if( pocket.volume_capacity() >= pocket_data::max_volume_for_container ||
pocket.settings.is_disabled() || pocket.holster_full() ) {
// If the pocket is a holster that has an item return the volume when it is full (not larger than capacity).
// If the pocket has default volume or is a pocket that has normal pickup disabled return the volume of things contained.
// Otherwise, return the capacity.
if( pocket.holster_full() ) {
units::volume add_volume = pocket.front().volume();
for( const item_pocket *it_pocket : pocket.front().get_all_contained_pockets() ) {
// Here, the case where the pocket is not empty for the holster is not considered, which will lead to higher results.
// To obtain accurate results, a recursive function may be required. Since in the actual game,
// the situation of holster nested in the holster is very rare, from a performance perspective, it seems not worth it to do so.
if( it_pocket->is_valid() && !it_pocket->rigid() ) {
add_volume += it_pocket->remaining_volume();
}
}
total_vol += std::min( pocket.volume_capacity(), add_volume );
} else if( pocket.volume_capacity() >= pocket_data::max_volume_for_container ||
pocket.settings.is_disabled() ) {
total_vol += pocket.contains_volume();
} else {
total_vol += pocket.volume_capacity();
Expand Down
4 changes: 2 additions & 2 deletions src/item_pocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2222,12 +2222,12 @@ std::pair<item_location, item_pocket *> item_pocket::best_pocket_in_contents(
const bool allow_sealed, const bool ignore_settings )
{
std::pair<item_location, item_pocket *> ret( this_loc, nullptr );
// If the current pocket has restrictions or blacklists the item,
// If the current pocket has restrictions or blacklists the item or is a holster,
// try the nested pocket regardless of whether it's soft or rigid.
const bool ignore_rigidity =
!settings.accepts_item( it ) ||
!get_pocket_data()->get_flag_restrictions().empty() ||
settings.priority() > 0;
settings.priority() > 0 || is_holster();

for( item &contained_item : contents ) {
if( &contained_item == &it || &contained_item == avoid ) {
Expand Down

0 comments on commit 9f92b0f

Please sign in to comment.