Skip to content

Commit

Permalink
Modified functions and doc about open_container. (CleverRaven#73805)
Browse files Browse the repository at this point in the history
* Modified functions and doc about open_container.

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
osuphobia and github-actions[bot] authored May 16, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent a2efbb9 commit e8cc926
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion doc/JSON_INFO.md
Original file line number Diff line number Diff line change
@@ -4015,7 +4015,7 @@ Any Item can be a container. To add the ability to contain things to an item, yo
"airtight": false, // Default false. If true, can contain gas.
"ablative": false, // Default false. If true, this item holds a single ablative plate. Make sure to include a flag_restriction on the type of plate that can be added.
"holster": false, // Default false. If true, only one stack of items can be placed inside this pocket, or one item if that item is not count_by_charges.
"open_container": false, // Default false. If true, the contents of this pocket will spill if this item is placed into another item.
"open_container": false, // Default false. If true, the contents of this pocket will spill if this item is worn by a character or placed into another item.
"fire_protection": false, // Default false. If true, the pocket protects the contained items from exploding if tossed into a fire.
"transparent": false // Default false. If true, the pocket is transparent, as you can see items inside it afar; in the future this would be used for light also
"extra_encumbrance": 3, // Additional encumbrance given to character, if this pocket is used
6 changes: 4 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
@@ -10218,7 +10218,8 @@ std::pair<item_location, item_pocket *> item::best_pocket( const item &it, item_

bool item::spill_contents( Character &c )
{
if( !is_container() || is_container_empty() ) {
if( ( !is_container() && !is_magazine() && !uses_magazine() ) ||
is_container_empty() ) {
return true;
}

@@ -10234,7 +10235,8 @@ bool item::spill_contents( Character &c )

bool item::spill_contents( const tripoint &pos )
{
if( !is_container() || is_container_empty() ) {
if( ( !is_container() && !is_magazine() && !uses_magazine() ) ||
is_container_empty() ) {
return true;
}
return contents.spill_contents( pos );
9 changes: 4 additions & 5 deletions src/item_contents.cpp
Original file line number Diff line number Diff line change
@@ -1374,7 +1374,7 @@ const item &item_contents::first_ammo() const
bool item_contents::will_spill() const
{
for( const item_pocket &pocket : contents ) {
if( pocket.is_type( pocket_type::CONTAINER ) && pocket.will_spill() ) {
if( pocket.is_standard_type() && pocket.will_spill() ) {
return true;
}
}
@@ -1384,8 +1384,7 @@ bool item_contents::will_spill() const
bool item_contents::will_spill_if_unsealed() const
{
for( const item_pocket &pocket : contents ) {
if( pocket.is_type( pocket_type::CONTAINER )
&& pocket.will_spill_if_unsealed() ) {
if( pocket.is_standard_type() && pocket.will_spill_if_unsealed() ) {
return true;
}
}
@@ -1395,7 +1394,7 @@ bool item_contents::will_spill_if_unsealed() const
bool item_contents::spill_open_pockets( Character &guy, const item *avoid )
{
for( item_pocket &pocket : contents ) {
if( pocket.is_type( pocket_type::CONTAINER ) && pocket.will_spill() ) {
if( pocket.is_standard_type() && pocket.will_spill() ) {
pocket.handle_liquid_or_spill( guy, avoid );
if( !pocket.empty() ) {
return false;
@@ -1408,7 +1407,7 @@ bool item_contents::spill_open_pockets( Character &guy, const item *avoid )
void item_contents::handle_liquid_or_spill( Character &guy, const item *const avoid )
{
for( item_pocket &pocket : contents ) {
if( pocket.is_type( pocket_type::CONTAINER ) ) {
if( pocket.is_standard_type() ) {
pocket.handle_liquid_or_spill( guy, avoid );
}
}

0 comments on commit e8cc926

Please sign in to comment.