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

implement pocket max item size #40214

Merged
merged 1 commit into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/json/items/containers.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@
"watertight": true,
"rigid": true,
"max_contains_volume": "2 L",
"max_item_volume": "17 ml",
"max_contains_weight": "3 kg",
"moves": 400
}
Expand Down
19 changes: 19 additions & 0 deletions src/item_pocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ void pocket_data::load( const JsonObject &jo )
// putting it in an if statement like this should allow for report_unvisited_member to work here
if( ammo_restriction.empty() ) {
optional( jo, was_loaded, "min_item_volume", min_item_volume, volume_reader(), 0_ml );
units::volume temp = -1_ml;
optional( jo, was_loaded, "max_item_volume", temp, volume_reader(), temp );
if( temp != -1_ml ) {
max_item_volume = temp;
}
mandatory( jo, was_loaded, "max_contains_volume", max_contains_volume, volume_reader() );
mandatory( jo, was_loaded, "max_contains_weight", max_contains_weight, mass_reader() );
}
Expand Down Expand Up @@ -600,6 +605,11 @@ void item_pocket::general_info( std::vector<iteminfo> &info, int pocket_number,
string_format( _( "Minimum volume of item allowed: <neutral>%s</neutral>" ),
vol_to_string( data->min_item_volume ) ) );
}
if( data->max_item_volume ) {
info.emplace_back( "DESCRIPTION",
string_format( _( "Maximum volume of item allowed: <neutral>%s</neutral>" ),
vol_to_string( *data->max_item_volume ) ) );
}

info.emplace_back( "DESCRIPTION", string_format( _( "Volume Capacity: <neutral>%s</neutral>" ),
vol_to_string( data->max_contains_volume ) ) );
Expand Down Expand Up @@ -793,6 +803,15 @@ ret_val<item_pocket::contain_code> item_pocket::can_contain( const item &it ) co
return ret_val<item_pocket::contain_code>::make_success();
}

// liquids and gases avoid the size limit altogether
// soft items also avoid the size limit
if( !it.made_of( LIQUID ) && !it.made_of( GAS ) &&
!it.is_soft() && data->max_item_volume &&
it.volume() > *data->max_item_volume ) {
return ret_val<item_pocket::contain_code>::make_failure(
contain_code::ERR_TOO_BIG, _( "item too big" ) );
}

if( it.volume() < data->min_item_volume ) {
return ret_val<item_pocket::contain_code>::make_failure(
contain_code::ERR_TOO_SMALL, _( "item is too small" ) );
Expand Down
2 changes: 2 additions & 0 deletions src/item_pocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ class pocket_data
item_pocket::pocket_type type = item_pocket::pocket_type::CONTAINER;
// max volume of stuff the pocket can hold
units::volume max_contains_volume = 0_ml;
// max volume of item that can be contained, otherwise it spills
cata::optional<units::volume> max_item_volume = cata::nullopt;
// min volume of item that can be contained, otherwise it spills
units::volume min_item_volume = 0_ml;
// max weight of stuff the pocket can hold
Expand Down