pickup_answer handle_problematic_pickup( const item &it, bool &offered_swap, const std::string &explain ) { player &u = g->u; uimenu amenu; amenu.return_invalid = true; amenu.selected = 0; amenu.text = explain; offered_swap = true; // @todo Gray out if not enough hands amenu.addentry( WIELD, !u.weapon.has_flag( "NO_UNWIELD" ), 'w', _("Dispose of %s and wield %s"), u.weapon.display_name().c_str(), it.display_name().c_str() ); if( it.is_armor() ) { amenu.addentry( WEAR, u.can_wear( it ), 'W', _("Wear %s"), it.display_name().c_str() ); } if( !it.is_container_empty() && u.can_pickVolume( it.volume() ) ) { amenu.addentry( SPILL, true, 's', _("Spill %s, then pick up %s"), it.contents.front().tname().c_str(), it.display_name().c_str() ); } amenu.query(); int choice = amenu.ret; if( choice <= CANCEL || choice >= NUM_ANSWERS ) { return CANCEL; } return static_cast<pickup_answer>( choice ); }
bool Pickup::handle_spillable_contents( Character &c, item &it, map &m ) { if( it.is_bucket_nonempty() ) { const item &it_cont = it.contents.front(); int num_charges = it_cont.charges; while( !it.spill_contents( c ) ) { if( num_charges > it_cont.charges ) { num_charges = it_cont.charges; } else { break; } } // If bucket is still not empty then player opted not to handle the // rest of the contents if( it.is_bucket_nonempty() ) { c.add_msg_player_or_npc( _( "To avoid spilling its contents, you set your %1$s on the %2$s." ), _( "To avoid spilling its contents, <npcname> sets their %1$s on the %2$s." ), it.display_name(), m.name( c.pos() ) ); m.add_item_or_charges( c.pos(), it ); return true; } } return false; }
pickup_answer handle_problematic_pickup( const item &it, bool &offered_swap, const std::string &explain ) { if( offered_swap ) { return CANCEL; } player &u = g->u; uilist amenu; amenu.text = explain; offered_swap = true; // TODO: Gray out if not enough hands if( u.is_armed() ) { amenu.addentry( WIELD, !u.weapon.has_flag( "NO_UNWIELD" ), 'w', _( "Dispose of %s and wield %s" ), u.weapon.display_name(), it.display_name() ); } else { amenu.addentry( WIELD, true, 'w', _( "Wield %s" ), it.display_name() ); } if( it.is_armor() ) { amenu.addentry( WEAR, u.can_wear( it ).success(), 'W', _( "Wear %s" ), it.display_name() ); } if( it.is_bucket_nonempty() ) { amenu.addentry( SPILL, u.can_pickVolume( it ), 's', _( "Spill %s, then pick up %s" ), it.contents.front().tname(), it.display_name() ); } amenu.query(); int choice = amenu.ret; if( choice <= CANCEL || choice >= NUM_ANSWERS ) { return CANCEL; } return static_cast<pickup_answer>( choice ); }
item_location game_menus::inv::container_for( player &p, const item &liquid, int radius ) { const auto filter = [ &liquid ]( const item_location & location ) { if( location.where() == item_location::type::character ) { Character *character = dynamic_cast<Character *>( g->critter_at( location.position() ) ); if( character == nullptr ) { debugmsg( "Invalid location supplied to the liquid filter: no character found." ); return false; } return location->get_remaining_capacity_for_liquid( liquid, *character ) > 0; } const bool allow_buckets = location.where() == item_location::type::map; return location->get_remaining_capacity_for_liquid( liquid, allow_buckets ) > 0; }; return inv_internal( p, inventory_filter_preset( filter ), string_format( _( "Container for %s" ), liquid.display_name( liquid.charges ).c_str() ), radius, string_format( _( "You don't have a suitable container for carrying %s." ), liquid.tname().c_str() ) ); }
void Pickup::pick_one_up( const tripoint &pickup_target, item &newit, vehicle *veh, int cargo_part, int index, int quantity, bool &got_water, bool &offered_swap, PickupMap &mapPickup, bool autopickup ) { player &u = g->u; int moves_taken = 100; bool picked_up = false; pickup_answer option = CANCEL; item leftovers = newit; if( newit.invlet != '\0' && u.invlet_to_position( newit.invlet ) != INT_MIN ) { // Existing invlet is not re-usable, remove it and let the code in player.cpp/inventory.cpp // add a new invlet, otherwise keep the (usable) invlet. newit.invlet = '\0'; } if( quantity != 0 && newit.count_by_charges() ) { // Reinserting leftovers happens after item removal to avoid stacking issues. leftovers.charges = newit.charges - quantity; if( leftovers.charges > 0 ) { newit.charges = quantity; } } else { leftovers.charges = 0; } if( newit.made_of( LIQUID ) ) { got_water = true; } else if( !u.can_pickWeight( newit, false ) ) { add_msg( m_info, _( "The %s is too heavy!" ), newit.display_name().c_str() ); } else if( newit.is_ammo() && ( newit.ammo_type() == ammotype( "arrow" ) || newit.ammo_type() == ammotype( "bolt" ) ) ) { // @todo Make quiver code generic so that ammo pouches can use it too //add ammo to quiver int quivered = handle_quiver_insertion( newit, moves_taken, picked_up ); if( quivered > 0 ) { quantity = quivered; //already picked up some for quiver so use special case handling picked_up = true; option = NUM_ANSWERS; } if( newit.charges > 0 ) { if( !u.can_pickVolume( newit ) ) { if( !autopickup ) { // Silence some messaging if we're doing autopickup. add_msg( m_info, ngettext( "There's no room in your inventory for the %s.", "There's no room in your inventory for the %s.", newit.charges ), newit.tname( newit.charges ).c_str() ); } } else { // Add to inventory instead option = STASH; } } if( option == NUM_ANSWERS ) { //not picking up the rest so //update the charges for the item that gets re-added to the game map leftovers.charges = newit.charges; } } else if( newit.is_bucket() && !newit.is_container_empty() ) { if( !autopickup ) { const std::string &explain = string_format( _( "Can't stash %s while it's not empty" ), newit.display_name().c_str() ); option = handle_problematic_pickup( newit, offered_swap, explain ); } else { option = CANCEL; } } else if( !u.can_pickVolume( newit ) ) { if( !autopickup ) { const std::string &explain = string_format( _( "Not enough capacity to stash %s" ), newit.display_name().c_str() ); option = handle_problematic_pickup( newit, offered_swap, explain ); } else { option = CANCEL; } } else { option = STASH; } switch( option ) { case NUM_ANSWERS: // Some other option break; case CANCEL: picked_up = false; break; case WEAR: picked_up = u.wear_item( newit ); break; case WIELD: picked_up = u.wield( newit ); if( !picked_up ) { break; } if( u.weapon.invlet ) { add_msg( m_info, _( "Wielding %c - %s" ), u.weapon.invlet, u.weapon.display_name().c_str() ); } else { add_msg( m_info, _( "Wielding - %s" ), u.weapon.display_name().c_str() ); } break; case SPILL: if( newit.is_container_empty() ) { debugmsg( "Tried to spill contents from an empty container" ); break; } picked_up = newit.spill_contents( u ); if( !picked_up ) { break; } // Intentional fallthrough case STASH: auto &entry = mapPickup[newit.tname()]; entry.second += newit.count_by_charges() ? newit.charges : 1; entry.first = u.i_add( newit ); picked_up = true; break; } if( picked_up ) { Pickup::remove_from_map_or_vehicle( pickup_target, veh, cargo_part, moves_taken, index ); } if( leftovers.charges > 0 ) { bool to_map = veh == nullptr; if( !to_map ) { to_map = !veh->add_item( cargo_part, leftovers ); } if( to_map ) { g->m.add_item_or_charges( pickup_target, leftovers ); } } }
void Pickup::pick_one_up( const tripoint &pickup_target, item &newit, vehicle *veh, int cargo_part, int index, int quantity, bool &got_water, bool &offered_swap, PickupMap &mapPickup, bool autopickup ) { int moves_taken = 100; bool picked_up = false; item leftovers = newit; if( newit.invlet != '\0' && g->u.invlet_to_position( newit.invlet ) != INT_MIN ) { // Existing invlet is not re-usable, remove it and let the code in player.cpp/inventory.cpp // add a new invlet, otherwise keep the (usable) invlet. newit.invlet = '\0'; } if( quantity != 0 && newit.count_by_charges() ) { // Reinserting leftovers happens after item removal to avoid stacking issues. leftovers.charges = newit.charges - quantity; if( leftovers.charges > 0 ) { newit.charges = quantity; } } else { leftovers.charges = 0; } if( newit.made_of(LIQUID) ) { got_water = true; } else if (!g->u.can_pickWeight(newit.weight(), false)) { add_msg(m_info, _("The %s is too heavy!"), newit.display_name().c_str()); } else if( newit.is_ammo() && (newit.ammo_type() == "arrow" || newit.ammo_type() == "bolt")) { //add ammo to quiver int quivered = handle_quiver_insertion( newit, moves_taken, picked_up); if( newit.charges > 0) { if(!g->u.can_pickVolume( newit.volume())) { if(quivered > 0) { //update the charges for the item that gets re-added to the game map quantity = quivered; leftovers.charges = newit.charges; } if( !autopickup ) { // Silence some messaging if we're doing autopickup. add_msg(m_info, ngettext("There's no room in your inventory for the %s.", "There's no room in your inventory for the %s.", newit.charges), newit.tname(newit.charges).c_str()); } } else { //add to inventory instead item &it = g->u.i_add(newit); picked_up = true; //display output message PickupMap map_pickup; int charges = (newit.count_by_charges()) ? newit.charges : 1; map_pickup.insert(std::pair<std::string, ItemCount>(newit.tname(), ItemCount(it, charges))); show_pickup_message(map_pickup); } } } else if (!g->u.can_pickVolume(newit.volume())) { if( !autopickup ) { // Armor can be instantly worn if (newit.is_armor() && query_yn(_("Put on the %s?"), newit.display_name().c_str())) { if (g->u.wear_item(newit)) { picked_up = true; } } else if (g->u.is_armed()) { if (!g->u.weapon.has_flag("NO_UNWIELD")) { if( !offered_swap ) { offered_swap = true; if ( g->u.weapon.type->id != newit.type->id && query_yn(_("No space for %1$s; wield instead? (drops %2$s)"), newit.display_name().c_str(), g->u.weapon.display_name().c_str()) ) { picked_up = true; g->m.add_item_or_charges( pickup_target, g->u.remove_weapon(), 1 ); g->u.inv.assign_empty_invlet( newit, true ); // force getting an invlet. g->u.wield( &( g->u.i_add(newit) ) ); if (newit.invlet) { add_msg(m_info, _("Wielding %c - %s"), newit.invlet, newit.display_name().c_str()); } else { add_msg(m_info, _("Wielding - %s"), newit.display_name().c_str()); } } } } else { add_msg(m_info, _("There's no room in your inventory for the %s " "and you can't unwield your %s."), newit.display_name().c_str(), g->u.weapon.display_name().c_str()); } } else if( !g->u.is_armed() ) { if (g->u.keep_hands_free) { add_msg(m_info, _("There's no room in your inventory for the %s " "and you have decided to keep your hands free."), newit.display_name().c_str()); } else { g->u.inv.assign_empty_invlet(newit, true); // force getting an invlet. g->u.wield(&(g->u.i_add(newit))); picked_up = true; if (newit.invlet) { add_msg(m_info, _("Wielding %c - %s"), newit.invlet, newit.display_name().c_str()); } else { add_msg(m_info, _("Wielding - %s"), newit.display_name().c_str()); } } } // end of if unarmed } // end of if !autopickup } else { auto &entry = mapPickup[newit.tname()]; entry.second += newit.count_by_charges() ? newit.charges : 1; entry.first = g->u.i_add(newit); picked_up = true; } if(picked_up) { Pickup::remove_from_map_or_vehicle(pickup_target, veh, cargo_part, moves_taken, index); } if( leftovers.charges > 0 ) { bool to_map = veh == nullptr; if( !to_map ) { to_map = !veh->add_item( cargo_part, leftovers ); } if( to_map ) { g->m.add_item_or_charges( pickup_target, leftovers ); } } }
void pick_one_up( const tripoint &pickup_target, item &newit, vehicle *veh, int cargo_part, int index, int quantity, bool &got_water, bool &offered_swap, PickupMap &mapPickup, bool autopickup ) { player &u = g->u; int moves_taken = 100; bool picked_up = false; pickup_answer option = CANCEL; item leftovers = newit; if( newit.invlet != '\0' && u.invlet_to_position( newit.invlet ) != INT_MIN ) { // Existing invlet is not re-usable, remove it and let the code in player.cpp/inventory.cpp // add a new invlet, otherwise keep the (usable) invlet. newit.invlet = '\0'; } if( quantity != 0 && newit.count_by_charges() ) { // Reinserting leftovers happens after item removal to avoid stacking issues. leftovers.charges = newit.charges - quantity; if( leftovers.charges > 0 ) { newit.charges = quantity; } } else { leftovers.charges = 0; } if( newit.made_of( LIQUID ) ) { got_water = true; } else if( !u.can_pickWeight( newit, false ) ) { add_msg( m_info, _( "The %s is too heavy!" ), newit.display_name().c_str() ); } else if( newit.is_bucket() && !newit.is_container_empty() ) { if( !autopickup ) { const std::string &explain = string_format( _( "Can't stash %s while it's not empty" ), newit.display_name().c_str() ); option = handle_problematic_pickup( newit, offered_swap, explain ); } else { option = CANCEL; } } else if( !u.can_pickVolume( newit ) ) { if( !autopickup ) { const std::string &explain = string_format( _( "Not enough capacity to stash %s" ), newit.display_name().c_str() ); option = handle_problematic_pickup( newit, offered_swap, explain ); } else { option = CANCEL; } } else { option = STASH; } switch( option ) { case NUM_ANSWERS: // Some other option break; case CANCEL: picked_up = false; break; case WEAR: picked_up = u.wear_item( newit ); break; case WIELD: picked_up = u.wield( newit ); if( !picked_up ) { break; } if( u.weapon.invlet ) { add_msg( m_info, _( "Wielding %c - %s" ), u.weapon.invlet, u.weapon.display_name().c_str() ); } else { add_msg( m_info, _( "Wielding - %s" ), u.weapon.display_name().c_str() ); } break; case SPILL: if( newit.is_container_empty() ) { debugmsg( "Tried to spill contents from an empty container" ); break; } picked_up = newit.spill_contents( u ); if( !picked_up ) { break; } // Intentional fallthrough case STASH: auto &entry = mapPickup[newit.tname()]; entry.second += newit.count_by_charges() ? newit.charges : 1; entry.first = u.i_add( newit ); picked_up = true; break; } if( picked_up ) { remove_from_map_or_vehicle( pickup_target, veh, cargo_part, moves_taken, index ); } if( leftovers.charges > 0 ) { bool to_map = veh == nullptr; if( !to_map ) { to_map = !veh->add_item( cargo_part, leftovers ); } if( to_map ) { g->m.add_item_or_charges( pickup_target, leftovers ); } } }