Skip to content

Commit

Permalink
Default collapse of container contents (CleverRaven#51434)
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyBerube authored Sep 21, 2021
1 parent f95cb33 commit 99dc03c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
5 changes: 5 additions & 0 deletions data/json/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
"type": "json_flag",
"info": "This clothing has a <info>wide collar</info> that can keep your mouth warm if it is unencumbered."
},
{
"id": "COLLAPSE_CONTENTS",
"type": "json_flag",
"info": "Contents are hidden by default in inventory view."
},
{
"id": "DEAF",
"type": "json_flag",
Expand Down
3 changes: 3 additions & 0 deletions data/json/items/containers.json
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,7 @@
"price_postapoc": 0,
"to_hit": -2,
"material": [ "plastic" ],
"flags": [ "COLLAPSE_CONTENTS" ],
"pocket_data": [
{
"pocket_type": "CONTAINER",
Expand All @@ -1782,6 +1783,7 @@
"price_postapoc": 10,
"to_hit": -2,
"material": [ "cotton", "neoprene" ],
"flags": [ "COLLAPSE_CONTENTS" ],
"pocket_data": [
{
"pocket_type": "CONTAINER",
Expand Down Expand Up @@ -1896,6 +1898,7 @@
}
],
"material": [ "plastic", "aluminum" ],
"flags": [ "COLLAPSE_CONTENTS" ],
"symbol": ")",
"color": "light_gray"
},
Expand Down
3 changes: 2 additions & 1 deletion data/json/items/generic.json
Original file line number Diff line number Diff line change
Expand Up @@ -3279,6 +3279,7 @@
"price": 1,
"price_postapoc": 10,
"material": [ "plastic" ],
"flags": [ "COLLAPSE_CONTENTS" ],
"symbol": ")",
"color": "dark_gray",
"pocket_data": [
Expand Down Expand Up @@ -3485,7 +3486,7 @@
"price": 15000,
"price_postapoc": 250,
"material": [ "plastic", "leather" ],
"flags": [ "OVERSIZE", "BELTED", "ALLOWS_NATURAL_ATTACKS", "TARDIS" ],
"flags": [ "OVERSIZE", "BELTED", "ALLOWS_NATURAL_ATTACKS", "TARDIS", "COLLAPSE_CONTENTS" ],
"weight": "708 g",
"volume": "500 ml",
"bashing": 1,
Expand Down
1 change: 1 addition & 0 deletions src/flag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const flag_id flag_CITY_START( "CITY_START" );
const flag_id flag_CLIMATE_CONTROL( "CLIMATE_CONTROL" );
const flag_id flag_COLD( "COLD" );
const flag_id flag_COLD_IMMUNE( "COLD_IMMUNE" );
const flag_id flag_COLLAPSE_CONTENTS( "COLLAPSE_CONTENTS" );
const flag_id flag_COLLAPSIBLE_STOCK( "COLLAPSIBLE_STOCK" );
const flag_id flag_COLLAR( "COLLAR" );
const flag_id flag_CONDUCTIVE( "CONDUCTIVE" );
Expand Down
1 change: 1 addition & 0 deletions src/flag.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extern const flag_id flag_CITY_START;
extern const flag_id flag_CLIMATE_CONTROL;
extern const flag_id flag_COLD;
extern const flag_id flag_COLD_IMMUNE;
extern const flag_id flag_COLLAPSE_CONTENTS;
extern const flag_id flag_COLLAPSIBLE_STOCK;
extern const flag_id flag_COLLAR;
extern const flag_id flag_CONDUCTIVE;
Expand Down
6 changes: 6 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ item::item( const itype *type, time_point turn, int qty ) : type( type ), bday(
activate();
}

if( has_flag( flag_COLLAPSE_CONTENTS ) ) {
for( item_pocket *pocket : contents.get_all_contained_pockets().value() ) {
pocket->settings.set_collapse( true );
}
}

if( has_flag( flag_NANOFAB_TEMPLATE ) ) {
itype_id nanofab_recipe =
item_group::item_from( type->nanofab_template_group ).typeId();
Expand Down
28 changes: 19 additions & 9 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,20 +1197,24 @@ bool Item_factory::check_ammo_type( std::string &msg, const ammotype &ammo ) con

void Item_factory::check_definitions() const
{
auto is_container = []( const itype * t ) {
bool am_container = false;
for( const pocket_data &pocket : t->pockets ) {
if( pocket.type == item_pocket::pocket_type::CONTAINER ) {
am_container = true;
// no need to look further
break;
}
}
return am_container;
};

for( const auto &elem : m_templates ) {
std::string msg;
const itype *type = &elem.second;

if( !type->has_flag( flag_TARDIS ) ) {
bool is_container = false;
for( const pocket_data &pocket : type->pockets ) {
if( pocket.type == item_pocket::pocket_type::CONTAINER ) {
is_container = true;
// no need to look further
break;
}
}
if( is_container ) {
if( is_container( type ) ) {
units::volume volume = type->volume;
if( type->count_by_charges() ) {
volume /= type->charges_default();
Expand All @@ -1221,6 +1225,12 @@ void Item_factory::check_definitions() const
}
}

if( type->has_flag( flag_COLLAPSE_CONTENTS ) ) {
if( !is_container( type ) ) {
msg += "is not a container so COLLAPSE_CONTENTS is unnecessary.\n";
}
}

if( !type->picture_id.is_empty() && !type->picture_id.is_valid() ) {
msg += "item has unknown ascii_picture.";
}
Expand Down

0 comments on commit 99dc03c

Please sign in to comment.