Beispiel #1
0
void stomach_contents::ingest( player &p, item &food, int charges = 1 )
{
    item comest;
    if( food.is_container() ) {
        comest = food.get_contained();
    } else {
        comest = food;
    }
    if( charges == 0 ) {
        // if charges is 0, it means the item is not count_by_charges
        charges = 1;
    }
    // maybe move tapeworm to digestion
    for( const auto &v : p.vitamins_from( comest ) ) {
        vitamins[v.first] += p.has_effect( efftype_id( "tapeworm" ) ) ? v.second / 2 : v.second;
    }
    auto &comest_t = comest.type->comestible;
    const units::volume add_water = std::max( 0_ml, comest_t->quench * 5_ml );
    // if this number is negative, we decrease the quench/increase the thirst of the player
    if( comest_t->quench < 0 ) {
        p.mod_thirst( -comest_t->quench );
    } else {
        mod_quench( comest_t->quench );
    }
    // @TODO: Move quench values to mL and remove the magic number here
    mod_contents( ( comest.base_volume() * charges ) - add_water );

    last_ate = calendar::turn;

    mod_calories( comest_t->get_calories() );
}
Beispiel #2
0
bool trap::detect_trap( const tripoint &pos, const player &p ) const
{
    // Some decisions are based around:
    // * Starting, and thus average perception, is 8.
    // * Buried landmines, the silent killer, has a visibility of 10.
    // * There will always be a distance malus of 1 unless you're on top of the trap.
    // * ...and an average character should at least have a minor chance of
    //   noticing a buried landmine if standing right next to it.
    // Effective Perception...
    ///\EFFECT_PER increases chance of detecting a trap
    return ( p.per_cur - ( p.encumb( bp_eyes ) / 10 ) ) +
           // ...small bonus from stimulants...
           ( p.stim > 10 ? rng( 1, 2 ) : 0 ) +
           // ...bonus from trap skill...
           ///\EFFECT_TRAPS increases chance of detecting a trap
           ( p.get_skill_level( skill_traps ) * 2 ) +
           // ...luck, might be good, might be bad...
           rng( -4, 4 ) -
           // ...malus if we are tired...
           ( p.has_effect( effect_lack_sleep ) ? rng( 1, 5 ) : 0 ) -
           // ...malus farther we are from trap...
           rl_dist( p.pos(), pos ) +
           // Police are trained to notice Something Wrong.
           ( p.has_trait( trait_id( "PROF_POLICE" ) ) ? 1 : 0 ) +
           ( p.has_trait( trait_id( "PROF_PD_DET" ) ) ? 2 : 0 ) >
           // ...must all be greater than the trap visibility.
           visibility;
}
Beispiel #3
0
void map::apply_character_light( player &p )
{
    if( p.has_effect( effect_onfire ) ) {
        apply_light_source( p.pos(), 8 );
    } else if( p.has_effect( effect_haslight ) ) {
        apply_light_source( p.pos(), 4 );
    }

    float const held_luminance = p.active_light();
    if( held_luminance > LIGHT_AMBIENT_LOW ) {
        apply_light_source( p.pos(), held_luminance );
    }

    if( held_luminance >= 4 && held_luminance > ambient_light_at( p.pos() ) - 0.5f ) {
        p.add_effect( effect_haslight, 1 );
    }
}
void addict_effect( player &u, addiction &add )
{
    const int in = std::min( 20, add.intensity );

    switch( add.type ) {
        case ADD_CIG:
            if( !one_in( 2000 - 20 * in ) ) {
                break;
            }

            u.add_msg_if_player( rng( 0, 6 ) < in ?
                                 _( "You need some nicotine." ) :
                                 _( "You could use some nicotine." ) );
            u.add_morale( MORALE_CRAVING_NICOTINE, -15, -3 * in );
            if( one_in( 800 - 50 * in ) ) {
                u.mod_fatigue( 1 );
            }
            if( u.stim > -5 * in && one_in( 400 - 20 * in ) ) {
                u.stim--;
            }
            break;

        case ADD_CAFFEINE:
            if( !one_in( 2000 - 20 * in ) ) {
                break;
            }

            u.add_msg_if_player( m_warning, _( "You want some caffeine." ) );
            u.add_morale( MORALE_CRAVING_CAFFEINE, -5, -30 );
            if( u.stim > -10 * in && rng( 0, 10 ) < in ) {
                u.stim--;
            }
            if( rng( 8, 400 ) < in ) {
                u.add_msg_if_player( m_bad, _( "Your hands start shaking... you need it bad!" ) );
                u.add_effect( effect_shakes, 20 );
            }
            break;

        case ADD_ALCOHOL:
        case ADD_DIAZEPAM: {
            static const std::string alc_1 = _( "You could use a drink. " );
            static const std::string alc_2 = _( "Your hands start shaking... you need a drink bad!" ) ;
            static const std::string dia_1 = _( "You could use some diazepam." );
            static const std::string dia_2 = _( "You're shaking... you need some diazepam!" );

            const std::string &msg_1 = add.type == ADD_ALCOHOL ? alc_1 : dia_1;
            const std::string &msg_2 = add.type == ADD_ALCOHOL ? alc_2 : dia_2;

            const auto morale_type = add.type == ADD_ALCOHOL ? MORALE_CRAVING_ALCOHOL : MORALE_CRAVING_DIAZEPAM;

            u.mod_per_bonus( -1 );
            u.mod_int_bonus( -1 );
            if( x_in_y( in, HOURS( 2 ) ) ) {
                u.mod_healthy_mod( -1, -in * 10 );
            }
            if( one_in( 20 ) && rng( 0, 20 ) < in ) {
                u.add_msg_if_player( m_warning, msg_1.c_str() );
                u.add_morale( morale_type, -35, -10 * in );
            } else if( rng( 8, 300 ) < in ) {
                u.add_msg_if_player( m_bad, msg_2.c_str() );
                u.add_morale( morale_type, -35, -10 * in );
                u.add_effect( effect_shakes, 50 );
            } else if( !u.has_effect( effect_hallu ) && rng( 10, 1600 ) < in ) {
                u.add_effect( effect_hallu, 3600 );
            }
            break;
        }

        case ADD_SLEEP:
            // No effects here--just in player::can_sleep()
            // EXCEPT!  Prolong this addiction longer than usual.
            if( one_in( 2 ) && add.sated < 0 ) {
                add.sated++;
            }
            break;

        case ADD_PKILLER:
            if( calendar::once_every( 100 - in * 4 ) && u.get_painkiller() > 20 - in ) {
                u.mod_painkiller( -1 );    // Tolerance increases!
            }
            if( u.get_painkiller() >= 35 ) { // No further effects if we're doped up.
                add.sated = 0;
                break;
            }

            u.mod_str_bonus( -1 );
            u.mod_per_bonus( -1 );
            u.mod_dex_bonus( -1 );
            if( u.get_pain() < in * 2 ) {
                u.mod_pain( 1 );
            }
            if( one_in( 1200 - 30 * in ) ) {
                u.mod_healthy_mod( -1, -in * 30 );
            }
            if( one_in( 20 ) && dice( 2, 20 ) < in ) {
                u.add_msg_if_player( m_bad, _( "Your hands start shaking... you need some painkillers." ) );
                u.add_morale( MORALE_CRAVING_OPIATE, -40, -10 * in );
                u.add_effect( effect_shakes, 20 + in * 5 );
            } else if( one_in( 20 ) && dice( 2, 30 ) < in ) {
                u.add_msg_if_player( m_bad, _( "You feel anxious.  You need your painkillers!" ) );
                u.add_morale( MORALE_CRAVING_OPIATE, -30, -10 * in );
            } else if( one_in( 50 ) && dice( 3, 50 ) < in ) {
                u.vomit();
            }
            break;

        case ADD_SPEED: {
            u.mod_int_bonus( -1 );
            u.mod_str_bonus( -1 );
            if( u.stim > -100 && x_in_y( in, 20 ) ) {
                u.stim--;
            }
            if( rng( 0, 150 ) <= in ) {
                u.mod_healthy_mod( -1, -in );
            }
            if( dice( 2, 100 ) < in ) {
                u.add_msg_if_player( m_warning, _( "You feel depressed.  Speed would help." ) );
                u.add_morale( MORALE_CRAVING_SPEED, -25, -20 * in );
            } else if( one_in( 10 ) && dice( 2, 80 ) < in ) {
                u.add_msg_if_player( m_bad, _( "Your hands start shaking... you need a pick-me-up." ) );
                u.add_morale( MORALE_CRAVING_SPEED, -25, -20 * in );
                u.add_effect( effect_shakes, in * 20 );
            } else if( one_in( 50 ) && dice( 2, 100 ) < in ) {
                u.add_msg_if_player( m_bad, _( "You stop suddenly, feeling bewildered." ) );
                u.moves -= 300;
            } else if( !u.has_effect( effect_hallu ) && one_in( 20 ) && 8 + dice( 2, 80 ) < in ) {
                u.add_effect( effect_hallu, 3600 );
            }
        }
        break;

        case ADD_COKE:
        case ADD_CRACK: {
            static const std::string coke_msg = _( "You feel like you need a bump." );
            static const std::string crack_msg = _( "You're shivering, you need some crack." );
            const std::string &cur_msg = add.type == ADD_COKE ? coke_msg : crack_msg;
            const auto morale_type = add.type == ADD_COKE ? MORALE_CRAVING_COCAINE : MORALE_CRAVING_CRACK;
            u.mod_int_bonus( -1 );
            u.mod_per_bonus( -1 );
            if( one_in( 900 - 30 * in ) ) {
                u.add_msg_if_player( m_warning, cur_msg.c_str() );
                u.add_morale( morale_type, -20, -15 * in );
            }
            if( dice( 2, 80 ) <= in ) {
                u.add_msg_if_player( m_warning, cur_msg.c_str() );
                u.add_morale( morale_type, -20, -15 * in );
                if( u.stim > -150 ) {
                    u.stim -= 3;
                }
            }
            break;
        }

        case ADD_MUTAGEN:
            if( u.has_trait( "MUT_JUNKIE" ) ) {
                if( one_in( 600 - 50 * in ) ) {
                    u.add_msg_if_player( m_warning, rng( 0,
                                                         6 ) < in ? _( "You so miss the exquisite rainbow of post-humanity." ) :
                                         _( "Your body is SOO booorrrring.  Just a little sip to liven things up?" ) );
                    u.add_morale( MORALE_CRAVING_MUTAGEN, -20, -200 );
                }
                if( u.focus_pool > 40 && one_in( 800 - 20 * in ) ) {
                    u.focus_pool -= ( in );
                    u.add_msg_if_player( m_warning,
                                         _( "You daydream what it'd be like if you were *different*.  Different is good." ) );
                }
            } else if( in > 5 || one_in( ( 500 - 15 * in ) ) ) {
                u.add_msg_if_player( m_warning, rng( 0, 6 ) < in ? _( "You haven't had any mutagen lately." ) :
                                     _( "You could use some new parts..." ) );
                u.add_morale( MORALE_CRAVING_MUTAGEN, -5, -50 );
            }
            break;
        case ADD_MARLOSS_R:
            marloss_add( u, in, _( "You daydream about luscious pink berries as big as your fist." ) );
            break;
        case ADD_MARLOSS_B:
            marloss_add( u, in, _( "You daydream about nutty cyan seeds as big as your hand." ) );
            break;
        case ADD_MARLOSS_Y:
            marloss_add( u, in, _( "You daydream about succulent, pale golden gel, sweet but light." ) );
            break;
        case ADD_NULL:
            break;
    }
}
Beispiel #5
0
void addict_effect(player &u, addiction &add,
                   std::function<void (char const*)> const &cancel_activity)
{
    int const in = add.intensity;

    switch (add.type) {
    case ADD_CIG:
        if (in > 20 || one_in((500 - 20 * in))) {
            u.add_msg_if_player(rng(0, 6) < in ? _("You need some nicotine.") :
                    _("You could use some nicotine."));
            u.add_morale(MORALE_CRAVING_NICOTINE, -15, -50);
            if (one_in(800 - 50 * in)) {
                u.fatigue++;
            }
            if (u.stim > -50 && one_in(400 - 20 * in)) {
                u.stim--;
            }
        }
        break;

    case ADD_CAFFEINE:
        u.moves -= 2;
        if (in > 20 || one_in((500 - 20 * in))) {
            u.add_msg_if_player(m_warning, _("You want some caffeine."));
            u.add_morale(MORALE_CRAVING_CAFFEINE, -5, -30);
            if (u.stim > -150 && rng(0, 10) < in) {
                u.stim--;
            }
            if (rng(8, 400) < in) {
                u.add_msg_if_player(m_bad, _("Your hands start shaking... you need it bad!"));
                u.add_effect("shakes", 20);
            }
        }
        break;

    case ADD_ALCOHOL:
        u.mod_per_bonus(-1);
        u.mod_int_bonus(-1);
        if (rng(40, 1200) <= in * 10) {
            u.mod_healthy_mod(-1, -in * 10);
        }
        if (one_in(20) && rng(0, 20) < in) {
            u.add_msg_if_player(m_warning, _("You could use a drink."));
            u.add_morale(MORALE_CRAVING_ALCOHOL, -35, -120);
        } else if (rng(8, 300) < in) {
            u.add_msg_if_player(m_bad, _("Your hands start shaking... you need a drink bad!"));
            u.add_morale(MORALE_CRAVING_ALCOHOL, -35, -120);
            u.add_effect("shakes", 50);
        } else if (!u.has_effect("hallu") && rng(10, 1600) < in) {
            u.add_effect("hallu", 3600);
        }
        break;

    case ADD_SLEEP:
        // No effects here--just in player::can_sleep()
        // EXCEPT!  Prolong this addiction longer than usual.
        if (one_in(2) && add.sated < 0) {
            add.sated++;
        }
        break;

    case ADD_PKILLER:
        if ((in >= 25 || int(calendar::turn) % (100 - in * 4) == 0) && u.pkill > 0) {
            u.pkill--;    // Tolerance increases!
        }
        if (u.pkill >= 35) { // No further effects if we're doped up.
            add.sated = 0;
        } else {
            u.mod_str_bonus(-(1 + int(in / 7)));
            u.mod_per_bonus(-1);
            u.mod_dex_bonus(-1);
            if (u.pain < in * 3) {
                u.mod_pain(1);
            }
            if (in >= 40 || one_in(1200 - 30 * in)) {
                u.mod_healthy_mod(-1, -in * 30);
            }
            if (one_in(20) && dice(2, 20) < in) {
                u.add_msg_if_player(m_bad, _("Your hands start shaking... you need some painkillers."));
                u.add_morale(MORALE_CRAVING_OPIATE, -40, -200);
                u.add_effect("shakes", 20 + in * 5);
            } else if (one_in(20) && dice(2, 30) < in) {
                u.add_msg_if_player(m_bad, _("You feel anxious.  You need your painkillers!"));
                u.add_morale(MORALE_CRAVING_OPIATE, -30, -200);
            } else if (one_in(50) && dice(3, 50) < in) {
                u.add_msg_if_player(m_bad, _("You throw up heavily!"));
                cancel_activity(_("Throwing up."));
                u.vomit();
            }
        }
        break;

    case ADD_SPEED: {
        // Minimal speed of PC is 0.25 * base speed, that is
        // usually 25 moves, this ensures that even at minimal speed
        // the PC gets 5 moves per turn.
        int move_pen = std::min(in * 5, 20);
        u.moves -= move_pen;
        u.mod_int_bonus(-1);
        u.mod_str_bonus(-1);
        if (u.stim > -100 && (in >= 20 || int(calendar::turn) % (100 - in * 5) == 0)) {
            u.stim--;
        }
        if (rng(0, 150) <= in) {
            u.mod_healthy_mod(-1, -in);
        }
        if (dice(2, 100) < in) {
            u.add_msg_if_player(m_warning, _("You feel depressed.  Speed would help."));
            u.add_morale(MORALE_CRAVING_SPEED, -25, -200);
        } else if (one_in(10) && dice(2, 80) < in) {
            u.add_msg_if_player(m_bad, _("Your hands start shaking... you need a pick-me-up."));
            u.add_morale(MORALE_CRAVING_SPEED, -25, -200);
            u.add_effect("shakes", in * 20);
        } else if (one_in(50) && dice(2, 100) < in) {
            u.add_msg_if_player(m_bad, _("You stop suddenly, feeling bewildered."));
            cancel_activity(nullptr);
            u.moves -= 300;
        } else if (!u.has_effect("hallu") && one_in(20) && 8 + dice(2, 80) < in) {
            u.add_effect("hallu", 3600);
        }
    }
    break;

    case ADD_COKE:
        u.mod_int_bonus(-1);
        u.mod_per_bonus(-1);
        if (in >= 30 || one_in((900 - 30 * in))) {
            u.add_msg_if_player(m_warning, _("You feel like you need a bump."));
            u.add_morale(MORALE_CRAVING_COCAINE, -20, -250);
        }
        if (dice(2, 80) <= in) {
            u.add_msg_if_player(m_warning, _("You feel like you need a bump."));
            u.add_morale(MORALE_CRAVING_COCAINE, -20, -250);
            if (u.stim > -150) {
                u.stim -= 3;
            }
        }
        break;

    case ADD_CRACK:
        u.mod_int_bonus(-1);
        u.mod_per_bonus(-1);
        if (in >= 30 || one_in((900 - 30 * in))) {
            u.add_msg_if_player(m_bad, _("You're shivering, you need some crack."));
            u.add_morale(MORALE_CRAVING_CRACK, -80, -250);
        }
        if (dice(2, 80) <= in) {
            u.add_msg_if_player(m_bad, _("You're shivering, you need some crack."));
            u.add_morale(MORALE_CRAVING_CRACK, -80, -250);
            if (u.stim > -150) {
                u.stim -= 3;
            }
        }
        break;

    case ADD_MUTAGEN:
        if (u.has_trait("MUT_JUNKIE")) {
            if (one_in(600 - 50 * in)) {
                u.add_msg_if_player(m_warning, rng(0, 6) < in ? _("You so miss the exquisite rainbow of post-humanity.") :
                        _("Your body is SOO booorrrring.  Just a little sip to liven things up?"));
                u.add_morale(MORALE_CRAVING_MUTAGEN, -20, -200);
            }
            if (u.focus_pool > 40 && one_in(800 - 20 * in)) {
                u.focus_pool -= (in);
                u.add_msg_if_player(m_warning,
                        _("You daydream what it'd be like if you were *different*.  Different is good."));
            }
        } else if (in > 5 || one_in((500 - 15 * in))) {
            u.add_msg_if_player(m_warning, rng(0, 6) < in ? _("You haven't had any mutagen lately.") :
                    _("You could use some new parts..."));
            u.add_morale(MORALE_CRAVING_MUTAGEN, -5, -50);
        }
        break;

    case ADD_DIAZEPAM:
        u.mod_per_bonus(-1);
        u.mod_int_bonus(-1);
        if (rng(40, 1200) <= in * 10) {
            u.mod_healthy_mod(-1, -in * 10);
        }
        if (one_in(20) && rng(0, 20) < in) {
            u.add_msg_if_player(m_warning, _("You could use some diazepam."));
            u.add_morale(MORALE_CRAVING_DIAZEPAM, -35, -120);
        } else if (rng(8, 200) < in) {
            u.add_msg_if_player(m_bad, _("You're shaking... you need some diazepam!"));
            u.add_morale(MORALE_CRAVING_DIAZEPAM, -35, -120);
            u.add_effect("shakes", 50);
        } else if (!u.has_effect("hallu") && rng(10, 3200) < in) {
            u.add_effect("hallu", 3600);
        } else if (one_in(50) && dice(3, 50) < in) {
            u.add_msg_if_player(m_bad, _("You throw up heavily!"));
            cancel_activity(_("Throwing up."));
            u.vomit();
        }
        break;
    case ADD_MARLOSS_R:
        if (one_in(800 - 20 * in)) {
            u.add_morale(MORALE_CRAVING_MARLOSS, -5, -25);
            u.add_msg_if_player(m_info, _("You daydream about luscious pink berries as big as your fist."));
            if (u.focus_pool > 40) {
                u.focus_pool -= (in);
            }
        }
        break;
    case ADD_MARLOSS_B:
        if (one_in(800 - 20 * in)) {
            u.add_morale(MORALE_CRAVING_MARLOSS, -5, -25);
            u.add_msg_if_player(m_info, _("You daydream about nutty cyan seeds as big as your hand."));
            if (u.focus_pool > 40) {
                u.focus_pool -= (in);
            }
        }
        break;
    case ADD_MARLOSS_Y:
        if (one_in(800 - 20 * in)) {
            u.add_morale(MORALE_CRAVING_MARLOSS, -5, -25);
            u.add_msg_if_player(m_info, _("You daydream about succulent, pale golden gel, sweet but light."));
            if (u.focus_pool > 40) {
                u.focus_pool -= (in);
            }
        }
        break;

    //for any other unhandled cases
    default:
        break;

    }
}