std::list<item> obtain_activity_items( player_activity &act, player &p ) { std::list<item> res; auto items = reorder_for_dropping( p, convert_to_indexes( act ) ); debug_drop_list( items ); while( !items.empty() && ( p.is_npc() || p.moves > 0 || items.front().consumed_moves == 0 ) ) { const auto &ait = items.front(); p.mod_moves( -ait.consumed_moves ); if( p.is_worn( *ait.it ) ) { p.takeoff( *ait.it, &res ); } else if( ait.it->count_by_charges() ) { res.push_back( p.reduce_charges( const_cast<item *>( ait.it ), ait.count ) ); } else { res.push_back( p.i_rem( ait.it ) ); } items.pop_front(); } // Avoid tumbling to the ground. Unload cleanly. const units::volume excessive_volume = p.volume_carried() - p.volume_capacity(); if( excessive_volume > 0_ml ) { const auto excess = p.inv.remove_randomly_by_volume( excessive_volume ); res.insert( res.begin(), excess.begin(), excess.end() ); } // Load anything that remains (if any) into the activity act.values.clear(); if( !items.empty() ) { for( const auto &drop : convert_to_indexes( p, items ) ) { act.values.push_back( drop.first ); act.values.push_back( drop.second ); } } // And cancel if its empty. If its not, we modified in place and we will continue // to resolve the drop next turn. This is different from the pickup logic which // creates a brand new activity every turn and cancels the old activity if( act.values.empty() ) { p.cancel_activity(); } return res; }
std::list<item> obtain_activity_items( player_activity &act, player &p ) { std::list<item> res; auto items = reorder_for_dropping( p, convert_to_indexes( act ) ); debug_drop_list( items ); while( !items.empty() && ( p.is_npc() || p.moves > 0 || items.front().consumed_moves == 0 ) ) { const auto &ait = items.front(); p.mod_moves( -ait.consumed_moves ); if( p.is_worn( *ait.it ) ) { p.takeoff( *ait.it, &res ); } else if( ait.it->count_by_charges() ) { res.push_back( p.reduce_charges( const_cast<item *>( ait.it ), ait.count ) ); } else { res.push_back( p.i_rem( ait.it ) ); } items.pop_front(); } // Avoid tumbling to the ground. Unload cleanly. const units::volume excessive_volume = p.volume_carried() - p.volume_capacity(); if( excessive_volume > 0 ) { const auto excess = p.inv.remove_randomly_by_volume( excessive_volume ); res.insert( res.begin(), excess.begin(), excess.end() ); } // Load anything that remains (if any) into the activity act.values.clear(); if( !items.empty() ) { for( const auto &drop : convert_to_indexes( p, items ) ) { act.values.push_back( drop.first ); act.values.push_back( drop.second ); } } // And either cancel if it's empty, or restart if it's not. if( act.values.empty() ) { p.cancel_activity(); } else { p.assign_activity( act ); } return res; }