Ejemplo n.º 1
0
int player::vitamin_mod( const vitamin_id &vit, int qty, bool capped )
{
    auto it = vitamin_levels.find( vit );
    if( it == vitamin_levels.end() ) {
        return 0;
    }
    const auto &v = it->first.obj();

    if( qty > 0 ) {
        // accumulations can never occur from food sources
        it->second = std::min( it->second + qty, capped ? 0 : v.max() );
        update_vitamins( vit );

    } else if( qty < 0 ) {
        it->second = std::max( it->second + qty, v.min() );
        update_vitamins( vit );
    }

    return it->second;
}
Ejemplo n.º 2
0
void Character::unset_mutation(const std::string &flag)
{
    const auto iter = my_mutations.find( flag );
    if( iter == my_mutations.end() ) {
        debugmsg("Trying to unset %s mutation, but the character does not have it.", flag.c_str());
    } else {
        my_mutations.erase( iter );
    }
    recalc_sight_limits();
    reset_encumbrance();
    update_vitamins( *this );
}
Ejemplo n.º 3
0
void Character::set_mutation(const std::string &flag)
{
    const auto iter = my_mutations.find( flag );
    if( iter == my_mutations.end() ) {
        my_mutations[flag]; // Creates a new entry with default values
    } else {
        debugmsg("Trying to set %s mutation, but the character already has it.", flag.c_str());
    }
    recalc_sight_limits();
    reset_encumbrance();
    update_vitamins( *this );
}
Ejemplo n.º 4
0
void Character::toggle_trait(const std::string &flag)
{
    const auto titer = my_traits.find( flag );
    if( titer == my_traits.end() ) {
        my_traits.insert( flag );
    } else {
        my_traits.erase( titer );
    }
    const auto miter = my_mutations.find( flag );
    if( miter == my_mutations.end() ) {
        my_mutations[flag]; // Creates a new entry with default values
        mutation_effect(flag);
    } else {
        my_mutations.erase( miter );
        mutation_loss_effect(flag);
    }
    recalc_sight_limits();
    reset_encumbrance();
    update_vitamins( *this );
}