Beispiel #1
0
    void remove_item() override
    {
        if( what == nullptr ) {
            return;
        }

        const auto parts = veh->parts_at_relative( local_coords.x, local_coords.y );
        for( const int i : parts ) {
            if( veh->remove_item( i, what ) ) {
                what = nullptr;
                return;
            }
        }

        debugmsg( "Tried to remove an item from vehicle %s, tile %d:%d, but it wasn't there",
                  veh->name.c_str(), local_coords.x, local_coords.y );
    }
Beispiel #2
0
    item_on_vehicle( vehicle &v, const point &where, const item *which )
    {
        veh = &v;
        local_coords = where;
        for( const int i : v.parts_at_relative( where.x, where.y ) ) {
            for( item &it : v.get_items( i ) ) {
                if( &it == which ) {
                    partnum = i;
                    what = ⁢
                    return;
                }
            }
        }

        debugmsg( "Tried to find an item on vehicle %s, tile %d:%d, but it wasn't there",
                  veh->name.c_str(), local_coords.x, local_coords.y );
        what = nullptr;
    }
Beispiel #3
0
static int max_quality_from_vpart( const vehicle& veh, int part, const quality_id& qual )
{
    int res = INT_MIN;

    auto pos = veh.parts[ part ].mount;
    for( const auto &n : veh.parts_at_relative( pos.x, pos.y ) ) {

        // only unbroken parts can provide tool qualities
        if( !veh.parts[ n ].is_broken() ) {
            auto tq = veh.part_info( n ).qualities;
            auto iter = tq.find( qual );

            // does the part provide this quality?
            if( iter != tq.end() ) {
                res = std::max( res, iter->second );
            }
        }
    }
    return res;
}
Beispiel #4
0
    item *get_item() override
    {
        if( what == nullptr ) {
            return nullptr;
        }

        const auto parts = veh->parts_at_relative( local_coords.x, local_coords.y );
        for( const int i : parts ) {
            for( item &it : veh->get_items( i ) ) {
                if( &it == what ) {
                    return ⁢
                }
            }
        }

        debugmsg( "Tried to find an item on vehicle %s, tile %d:%d, but it wasn't there",
                  veh->name.c_str(), local_coords.x, local_coords.y );
        what = nullptr;
        return nullptr;
    }
Beispiel #5
0
static int has_quality_from_vpart( const vehicle& veh, int part, const quality_id& qual, int level, int limit )
{
    int qty = 0;

    auto pos = veh.parts[ part ].mount;
    for( const auto &n : veh.parts_at_relative( pos.x, pos.y ) ) {

        // only unbroken parts can provide tool qualities
        if( !veh.parts[ n ].is_broken() ) {
            auto tq = veh.part_info( n ).qualities;
            auto iter = tq.find( qual );

            // does the part provide this quality?
            if( iter != tq.end() && iter->second >= level ) {
                if( ++qty >= limit ) {
                    break;
                }
            }
        }
    }
    return std::min( qty, limit );
}