Beispiel #1
0
item Character::i_rem(int pos)
{
 item tmp;
 if (pos == -1) {
     tmp = weapon;
     weapon = ret_null;
     return tmp;
 } else if (pos < -1 && pos > worn_position_to_index(worn.size())) {
     tmp = worn[worn_position_to_index(pos)];
     worn.erase(worn.begin() + worn_position_to_index(pos));
     return tmp;
 }
 return inv.remove_item(pos);
}
Beispiel #2
0
item Character::i_rem(int pos)
{
 item tmp;
 if (pos == -1) {
     tmp = weapon;
     weapon = ret_null;
     return tmp;
 } else if (pos < -1 && pos > worn_position_to_index(worn.size())) {
     auto iter = worn.begin();
     std::advance( iter, worn_position_to_index( pos ) );
     tmp = *iter;
     worn.erase( iter );
     return tmp;
 }
 return inv.remove_item(pos);
}
Beispiel #3
0
int Character::get_item_position( const item *it ) const
{
    if( weapon.contains( it ) ) {
        return -1;
    }

    int p = 0;
    for( const auto &e : worn ) {
        if( e.contains( it ) ) {
            return worn_position_to_index( p );
        }
        p++;
    }

    return inv.position_by_item( it );
}
Beispiel #4
0
// Negative positions indicate weapon/clothing, 0 & positive indicate inventory
const item& Character::i_at(int position) const
{
    if( position == -1 ) {
        return weapon;
    }
    if( position < -1 ) {
        int worn_index = worn_position_to_index(position);
        if (size_t(worn_index) < worn.size()) {
            auto iter = worn.begin();
            std::advance( iter, worn_index );
            return *iter;
        }
    }

    return inv.find_item(position);
}
Beispiel #5
0
int Character::get_item_position( const item *it ) const
{
    const auto filter = [it]( const item & i ) {
        return &i == it;
    };
    if( inventory::has_item_with_recursive( weapon, filter ) ) {
        return -1;
    }
    auto iter = worn.begin();
    for( size_t i = 0; i < worn.size(); i++, iter++ ) {
        if( inventory::has_item_with_recursive( *iter, filter ) ) {
            return worn_position_to_index( i );
        }
    }
    return inv.position_by_item( it );
}
Beispiel #6
0
int Character::get_item_position( const item *it ) const
{
    const auto filter = [it]( const item & i ) {
        return &i == it;
    };
    if( inventory::has_item_with_recursive( weapon, filter ) ) {
        return -1;
    }
    int i = 0;
    for( auto &iter : worn ) {
        if( inventory::has_item_with_recursive( iter, filter ) ) {
            return worn_position_to_index( i );
        }
        i++;
    }
    return inv.position_by_item( it );
}