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

feat: allow reloading non-watertight containers with solids #4893

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,7 @@ void activity_handlers::reload_finish( player_activity *act, player *p )
sounds::ambient_sound( p->pos(), reloadable.type->gun->reload_noise_volume,
sounds::sound_t::activity, reloadable.type->gun->reload_noise );
}
} else if( reloadable.is_watertight_container() ) {
} else if( reloadable.is_container() ) {
msg = _( "You refill the %s." );
}
add_msg( m_neutral, msg, reloadable.tname(), ammo_name );
Expand Down
2 changes: 1 addition & 1 deletion src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ void avatar_action::reload( item &loc, bool prompt, bool empty )
return;
}
}
if( it->is_watertight_container() && it->is_container_full() ) {
if( it->is_container() && it->is_container_full() ) {
add_msg( m_info, _( "The %s is already full!" ), it->tname() );
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11671,7 +11671,7 @@ int Character::item_reload_cost( const item &it, item &ammo, int qty ) const
{
if( ammo.is_ammo() ) {
qty = std::max( std::min( ammo.charges, qty ), 1 );
} else if( ammo.is_ammo_container() || ammo.is_container() ) {
} else if( ammo.is_ammo_container() || ammo.is_container() || ammo.is_comestible() ) {
qty = clamp( qty, ammo.contents.front().charges, 1 );
} else if( ammo.is_magazine() ) {
qty = 1;
Expand Down
18 changes: 9 additions & 9 deletions src/character_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,6 @@ bool list_ammo( const Character &who, item &base, std::vector<item_reload_option
for( item *e : opts ) {
for( item *ammo : find_ammo_items_or_mags( who, *e, include_empty_mags,
ammo_search_range ) ) {
// don't try to unload frozen liquids
if( ammo->is_watertight_container() && ammo->contents_made_of( SOLID ) ) {
continue;
}
auto id = ( ammo->is_ammo_container() || ammo->is_container() )
? ammo->contents.front().typeId()
: ammo->typeId();
Expand Down Expand Up @@ -791,7 +787,7 @@ item_reload_option select_ammo( const Character &who, item &base,
}

uilist menu;
menu.text = string_format( base.is_watertight_container() ? _( "Refill %s" ) :
menu.text = string_format( base.is_container() ? _( "Refill %s" ) :
base.has_flag( flag_RELOAD_AND_SHOOT ) ? _( "Select ammo for %s" ) : _( "Reload %s" ),
base.tname() );

Expand All @@ -816,7 +812,7 @@ item_reload_option select_ammo( const Character &who, item &base,
e.ammo->type_name(), e.ammo->ammo_data()->nname( e.ammo->ammo_remaining() ),
e.ammo->ammo_remaining() ) );
}
} else if( e.ammo->is_watertight_container() ||
} else if( e.ammo->is_container() ||
( e.ammo->is_ammo_container() && who.is_worn( *e.ammo ) ) ) {
// worn ammo containers should be named by their contents with their location also updated below
return e.ammo->contents.front().display_name();
Expand Down Expand Up @@ -1042,6 +1038,8 @@ item_reload_option select_ammo( const Character &who, item &base, bool prompt,
name = base.ammo_data()->nname( 1 );
} else if( base.is_watertight_container() ) {
name = base.is_container_empty() ? "liquid" : base.contents.front().tname();
} else if( base.is_container() ) {
name = base.is_container_empty() ? "items" : base.contents.front().tname();
} else {
name = enumerate_as_string( base.ammo_types().begin(),
base.ammo_types().end(), []( const ammotype & at ) {
Expand Down Expand Up @@ -1087,7 +1085,7 @@ std::vector<item *> get_ammo_items( const Character &who, const ammotype &at )
template <typename T, typename Output>
void find_ammo_helper( T &src, const item &obj, bool empty, Output out, bool nested )
{
if( obj.is_watertight_container() ) {
if( obj.is_container() ) {
if( !obj.is_container_empty() ) {
auto contents_id = obj.contents.front().typeId();

Expand All @@ -1105,9 +1103,11 @@ void find_ammo_helper( T &src, const item &obj, bool empty, Output out, bool nes
return nested ? VisitResponse::NEXT : VisitResponse::SKIP;
} );
} else {
// Look for containers with any liquid
// Look for any contents we can hold
src.visit_items( [&nested, &out]( item * node ) {
if( node->is_container() && node->contents_made_of( LIQUID ) ) {
if( ( node->is_watertight_container() && node->contents_made_of( LIQUID ) ) ||
( ( node->is_ammo() || node->is_comestible() ) && node->made_of( SOLID ) ) ||
( node->is_container() && node->contents_made_of( SOLID ) ) ) {
out = node;
}
return nested ? VisitResponse::NEXT : VisitResponse::SKIP;
Expand Down
19 changes: 10 additions & 9 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7014,7 +7014,13 @@ bool item::is_reloadable_helper( const itype_id &ammo, bool now ) const
} else if( is_watertight_container() ) {
if( ammo.is_empty() ) {
return now ? !is_container_full() : true;
} else if( ammo->phase != LIQUID ) {
} else {
return now ? ( is_container_empty() || contents.front().typeId() == ammo ) : true;
}
} else if( is_container() ) {
if( ammo.is_empty() ) {
return now ? !is_container_full() : true;
} else if( ammo->phase == LIQUID ) {
return false;
} else {
return now ? ( is_container_empty() || contents.front().typeId() == ammo ) : true;
Expand Down Expand Up @@ -8208,8 +8214,7 @@ void item_reload_option::qty( int val )
item &ammo_obj = ( ammo_in_container || ammo_in_liquid_container ) ?
ammo->contents.front() : *ammo;

if( ( ammo_in_container && !ammo_obj.is_ammo() ) ||
( ammo_in_liquid_container && !ammo_obj.made_of( LIQUID ) ) ) {
if( ammo_in_container && !ammo_obj.is_ammo() ) {
debugmsg( "Invalid reload option: %s", ammo_obj.tname() );
return;
}
Expand Down Expand Up @@ -8321,11 +8326,7 @@ bool item::reload( player &u, item &loc, int qty )
// NOLINTNEXTLINE(bugprone-use-after-move)
put_in( std::move( to_reload ) );
}
} else if( is_watertight_container() ) {
if( !ammo->made_of( LIQUID ) ) {
debugmsg( "Tried to reload liquid container with non-liquid." );
return false;
}
} else if( is_container() ) {
if( container ) {
container->on_contents_changed();
}
Expand Down Expand Up @@ -8600,7 +8601,7 @@ int item::get_remaining_capacity_for_liquid( const item &liquid, bool allow_buck
}
remaining_capacity = ammo_capacity() - ammo_remaining();
} else if( is_container() ) {
if( !type->container->watertight ) {
if( !type->container->watertight && liquid.made_of( LIQUID ) ) {
return error( string_format( _( "That %s isn't water-tight." ), tname() ) );
} else if( !type->container->seals && ( !allow_bucket || !is_bucket() ) ) {
return error( string_format( is_bucket() ?
Expand Down
Loading