std::list<act_item> convert_to_items( const player &p, const drop_indexes &drop,
                                      int min_pos, int max_pos )
{
    std::list<act_item> res;

    for( const auto &rec : drop ) {
        const auto pos = rec.first;
        const auto count = rec.second;

        if( pos < min_pos || pos > max_pos ) {
            continue;
        } else if( pos >= 0 ) {
            int obtained = 0;
            for( const auto &it : p.inv.const_stack( pos ) ) {
                if( obtained >= count ) {
                    break;
                }
                const int qty = it.count_by_charges() ? std::min<int>( it.charges, count - obtained ) : 1;
                obtained += qty;
                res.emplace_back( &it, qty, 100 ); // TODO: Use a calculated cost
            }
        } else {
            res.emplace_back( &p.i_at( pos ), count, ( pos == -1 ) ? 0 : 100 ); // TODO: Use a calculated cost
        }
    }

    return res;
}
Ejemplo n.º 2
0
void inventory_drop_selector::remove_dropping_items( player &dummy ) const
{
    std::map<item *, int> dummy_dropping;

    for( const auto &elem : dropping ) {
        dummy_dropping[&dummy.i_at( u.get_item_position( elem.first ) )] = elem.second;
    }
    for( auto &elem : dummy_dropping ) {
        if( elem.first->count_by_charges() ) {
            elem.first->mod_charges( -elem.second );
        } else {
            const int pos = dummy.get_item_position( elem.first );
            for( int i = 0; i < elem.second; ++i ) {
                dummy.i_rem( pos );
            }
        }
    }
}
Ejemplo n.º 3
0
void move_item( player &p, int pos, inventory_location from, inventory_location to )
{
    switch( from ) {
        case GROUND:
            switch( to ) {
                case GROUND:
                default:
                    FAIL( "unimplemented" );
                    break;
                case INVENTORY:
                    pick_up_from_feet( p, pos );
                    break;
                case WORN:
                    wear_from_feet( p, pos );
                    break;
                case WIELDED_OR_WORN:
                    if( p.weapon.is_null() ) {
                        wield_from_feet( p, pos );
                    } else {
                        // since we can only wield one item, wear the item instead
                        wear_from_feet( p, pos );
                    }
                    break;
            }
            break;
        case INVENTORY:
            switch( to ) {
                case GROUND:
                    drop_at_feet( p, pos );
                    break;
                case INVENTORY:
                default:
                    FAIL( "unimplemented" );
                    break;
                case WORN:
                    p.wear( pos, false );
                    break;
                case WIELDED_OR_WORN:
                    if( p.weapon.is_null() ) {
                        p.wield( p.i_at( pos ) );
                    } else {
                        // since we can only wield one item, wear the item instead
                        p.wear( pos, false );
                    }
                    break;
            }
            break;
        case WORN:
            switch( to ) {
                case GROUND:
                    drop_at_feet( p, -2 - pos );
                    break;
                case INVENTORY:
                    p.takeoff( -2 - pos );
                    break;
                case WORN:
                case WIELDED_OR_WORN:
                default:
                    FAIL( "unimplemented" );
                    break;
            }
            break;
        case WIELDED_OR_WORN:
            switch( to ) {
                case GROUND:
                    drop_at_feet( p, -1 - pos );
                    if( pos == 0 && !p.worn.empty() ) {
                        // wield the first worn item
                        p.wield( p.i_at( -2 ) );
                    }
                    break;
                case INVENTORY:
                    if( pos == 0 ) {
                        p.i_add( p.i_rem( -1 ) );
                    } else {
                        p.takeoff( -1 - pos );
                    }
                    if( pos == 0 && !p.worn.empty() ) {
                        // wield the first worn item
                        p.wield( p.i_at( -2 ) );
                    }
                    break;
                case WORN:
                case WIELDED_OR_WORN:
                default:
                    FAIL( "unimplemented" );
                    break;
            }
            break;
        default:
            FAIL( "unimplemented" );
            break;
    }
}