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

No more corpse of holding #61575

Merged
merged 10 commits into from
Nov 14, 2022
1 change: 1 addition & 0 deletions data/json/items/corpses/corpses.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"max_item_volume": "150 L",
"max_item_length": "60 meter",
"rigid": false,
"forbidden": true,
"transparent": true
}
]
Expand Down
1 change: 1 addition & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3432,6 +3432,7 @@ Any Item can be a container. To add the ability to contain things to an item, yo
"weight_multiplier": 1.0, // The items in this pocket magically weigh less inside than outside. Nothing in vanilla should have a weight_multiplier.
"moves": 100, // Indicates the number of moves it takes to remove an item from this pocket, assuming best conditions.
"rigid": false, // Default false. If true, this pocket's size is fixed, and does not expand when filled. A glass jar would be rigid, while a plastic bag is not.
"forbidden": true, // Default false. If true, this pocket cannot be used by players.
"magazine_well": "0 ml", // Amount of space you can put items in the pocket before it starts expanding. Only works if rigid = false.
"watertight": false, // Default false. If true, can contain liquid.
"airtight": false, // Default false. If true, can contain gas.
Expand Down
2 changes: 1 addition & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5286,7 +5286,7 @@ void item::properties_info( std::vector<iteminfo> &info, const iteminfo_query *p
not_rigid = true;
}
}
if( !not_rigid && !all_pockets_rigid() ) {
if( !not_rigid && !all_pockets_rigid() && !is_corpse() ) {
info.emplace_back( "BASE",
_( "* This items pockets are <info>not rigid</info>. Its"
" volume increases with contents." ) );
Expand Down
27 changes: 24 additions & 3 deletions src/item_contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void pocket_favorite_callback::refresh( uilist *menu )
++i;
}

if( selected_pocket != nullptr && selected_pocket->is_allowed() ) {
if( selected_pocket != nullptr && !selected_pocket->is_forbidden() ) {
std::vector<iteminfo> info;
int starty = 5;
const int startx = menu->w_width - menu->pad_right;
Expand Down Expand Up @@ -724,7 +724,7 @@ ret_val<item_pocket *> item_contents::insert_item( const item &it,
if( !pocket.success() ) {
return pocket;
}
if( !pocket.value()->is_allowed() ) {
if( pocket.value()->is_forbidden() ) {
return ret_val<item_pocket *>::make_failure( nullptr, _( "Can't store anything in this." ) );
}

Expand Down Expand Up @@ -819,6 +819,9 @@ units::length item_contents::max_containable_length( const bool unrestricted_poc
{
units::length ret = 0_mm;
for( const item_pocket &pocket : contents ) {
if( pocket.is_forbidden() ) {
continue;
}
bool restriction_condition = !pocket.is_type( item_pocket::pocket_type::CONTAINER ) ||
pocket.is_ablative() || pocket.holster_full();
if( unrestricted_pockets_only ) {
Expand Down Expand Up @@ -866,6 +869,9 @@ units::volume item_contents::max_containable_volume( const bool unrestricted_poc
{
units::volume ret = 0_ml;
for( const item_pocket &pocket : contents ) {
if( pocket.is_forbidden() ) {
continue;
}
bool restriction_condition = !pocket.is_type( item_pocket::pocket_type::CONTAINER ) ||
pocket.is_ablative() || pocket.holster_full() ||
pocket.volume_capacity() >= pocket_data::max_volume_for_container;
Expand Down Expand Up @@ -933,6 +939,9 @@ ret_val<void> item_contents::can_contain( const item &it, const bool ignore_pkt_
{
ret_val<void> ret = ret_val<void>::make_failure( _( "is not a container" ) );
for( const item_pocket &pocket : contents ) {
if( pocket.is_forbidden() ) {
continue;
}
// mod, migration, corpse, and software aren't regular pockets.
if( !pocket.is_standard_type() ) {
continue;
Expand Down Expand Up @@ -1704,6 +1713,9 @@ const
units::mass total_weight = 0_gram;

for( const item_pocket &pocket : contents ) {
if( pocket.is_forbidden() ) {
continue;
}
bool restriction_condition = pocket.is_type( item_pocket::pocket_type::CONTAINER ) &&
!pocket.is_ablative() && pocket.weight_capacity() < pocket_data::max_weight_for_container;
if( unrestricted_pockets_only ) {
Expand Down Expand Up @@ -1952,6 +1964,9 @@ units::volume item_contents::total_container_capacity( const bool unrestricted_p
{
units::volume total_vol = 0_ml;
for( const item_pocket &pocket : contents ) {
if( pocket.is_forbidden() ) {
continue;
}
bool restriction_condition = pocket.is_type( item_pocket::pocket_type::CONTAINER );
if( unrestricted_pockets_only ) {
restriction_condition = restriction_condition && !pocket.is_restricted();
Expand Down Expand Up @@ -1991,6 +2006,9 @@ const
{
units::volume total_vol = 0_ml;
for( const item_pocket &pocket : contents ) {
if( pocket.is_forbidden() ) {
continue;
}
bool restriction_condition = pocket.is_type( item_pocket::pocket_type::CONTAINER );
if( unrestricted_pockets_only ) {
restriction_condition = restriction_condition && !pocket.is_restricted();
Expand Down Expand Up @@ -2022,6 +2040,9 @@ units::mass item_contents::remaining_container_capacity_weight( const bool
{
units::mass total_weight = 0_gram;
for( const item_pocket &pocket : contents ) {
if( pocket.is_forbidden() ) {
continue;
}
bool restriction_condition = pocket.is_type( item_pocket::pocket_type::CONTAINER );
if( unrestricted_pockets_only ) {
restriction_condition = restriction_condition && !pocket.is_restricted();
Expand Down Expand Up @@ -2284,7 +2305,7 @@ void item_contents::info( std::vector<iteminfo> &info, const iteminfo_query *par

int idx = 0;
for( const item_pocket &pocket : found_pockets ) {
if( !pocket.is_allowed() ) {
if( pocket.is_forbidden() ) {
continue;
}
insert_separation_line( info );
Expand Down
3 changes: 3 additions & 0 deletions src/item_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ static void put_into_container(
if( ctr.can_contain( *it ).success() ) {
const item_pocket::pocket_type pk_type = guess_pocket_for( ctr, *it );
ctr.put_in( *it, pk_type );
} else if( ctr.is_corpse() ) {
const item_pocket::pocket_type pk_type = guess_pocket_for( ctr, *it );
ctr.force_insert_item( *it, pk_type );
} else {
switch( on_overflow ) {
case Item_spawn_data::overflow_behaviour::none:
Expand Down
13 changes: 6 additions & 7 deletions src/item_pocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ void pocket_data::load( const JsonObject &jo )
optional( jo, was_loaded, "open_container", open_container, false );
optional( jo, was_loaded, "transparent", transparent, false );
optional( jo, was_loaded, "rigid", rigid, false );
optional( jo, was_loaded, "forbidden", forbidden, false );
optional( jo, was_loaded, "holster", holster );
optional( jo, was_loaded, "ablative", ablative );
optional( jo, was_loaded, "inherits_flags", inherits_flags );
Expand Down Expand Up @@ -1125,6 +1126,9 @@ void item_pocket::general_info( std::vector<iteminfo> &info, int pocket_number,
void item_pocket::contents_info( std::vector<iteminfo> &info, int pocket_number,
bool disp_pocket_number ) const
{
if( is_forbidden() ) {
return;
}
const std::string space = " ";

insert_separation_line( info );
Expand Down Expand Up @@ -1828,14 +1832,9 @@ bool item_pocket::is_standard_type() const
data->type == pocket_type::MAGAZINE_WELL;
}

bool item_pocket::is_allowed() const
{
return allowed;
}

void item_pocket::set_usability( bool show )
bool item_pocket::is_forbidden() const
{
allowed = show;
return data->forbidden;
}

bool item_pocket::airtight() const
Expand Down
7 changes: 3 additions & 4 deletions src/item_pocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ class item_pocket
// exceptions are MOD, CORPSE, SOFTWARE, MIGRATION, etc.
bool is_standard_type() const;

bool is_allowed() const;
void set_usability( bool show );
bool is_forbidden() const;

const translation &get_description() const;
const translation &get_name() const;
Expand Down Expand Up @@ -394,8 +393,6 @@ class item_pocket
// the items inside the pocket
std::list<item> contents;
bool _sealed = false;

bool allowed = true; // is it possible to put things in this pocket
};

/**
Expand Down Expand Up @@ -525,6 +522,8 @@ class pocket_data
itype_id default_magazine = itype_id::NULL_ID();
// container's size and encumbrance does not change based on contents.
bool rigid = false;
// if true, the pocket cannot be used by the player
bool forbidden = false;

bool operator==( const pocket_data &rhs ) const;

Expand Down
11 changes: 3 additions & 8 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2635,7 +2635,7 @@ void monster::die( Creature *nkiller )
if( death_drops && !is_hallucination() ) {
for( const item &it : inv ) {
if( corpse ) {
corpse->put_in( it, item_pocket::pocket_type::CONTAINER );
corpse->force_insert_item( it, item_pocket::pocket_type::CONTAINER );
} else {
get_map().add_item_or_charges( pos(), it );
}
Expand All @@ -2647,11 +2647,6 @@ void monster::die( Creature *nkiller )
get_map().add_item( pos(), it );
}
}
if( corpse ) {
for( item_pocket *pocket : corpse->get_all_contained_pockets() ) {
pocket->set_usability( false );
}
}
}
if( death_drops ) {
// Drop items stored in optionals
Expand Down Expand Up @@ -2797,7 +2792,7 @@ void monster::drop_items_on_death( item *corpse )

// add stuff that could be worn or strapped to the creature
if( it.is_armor() ) {
corpse->put_in( it, item_pocket::pocket_type::CONTAINER );
corpse->force_insert_item( it, item_pocket::pocket_type::CONTAINER );
}
}

Expand All @@ -2820,7 +2815,7 @@ void monster::drop_items_on_death( item *corpse )
if( current_best.second != nullptr ) {
current_best.second->insert_item( it );
} else {
corpse->put_in( it, item_pocket::pocket_type::CONTAINER );
corpse->force_insert_item( it, item_pocket::pocket_type::CONTAINER );
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ void item_pocket::serialize( JsonOut &json ) const
json.member( "pocket_type", data->type );
json.member( "contents", contents );
json.member( "_sealed", _sealed );
json.member( "allowed", allowed );
if( !this->settings.is_null() ) {
json.member( "favorite_settings", this->settings );
}
Expand All @@ -262,7 +261,6 @@ void item_pocket::deserialize( const JsonObject &data )
_saved_type = static_cast<item_pocket::pocket_type>( saved_type_int );
data.read( "_sealed", _sealed );
_saved_sealed = _sealed;
data.read( "allowed", allowed );
if( data.has_member( "favorite_settings" ) ) {
data.read( "favorite_settings", this->settings );
} else {
Expand Down