예제 #1
0
// Returns a random sound effect matching given id and variant or `nullptr` if there is no
// matching sound effect.
const sound_effect *find_random_effect( const id_and_variant &id_variants_pair )
{
    const auto iter = sfx_resources.sound_effects.find( id_variants_pair );
    if( iter == sfx_resources.sound_effects.end() ) {
        return nullptr;
    }
    return &random_entry_ref( iter->second );
}
예제 #2
0
void faction::randomize()
{
    // Set up values
    // TODO: Not always in overmap 0,0
    mapx = rng( OMAPX / 10, OMAPX - OMAPX / 10 );
    mapy = rng( OMAPY / 10, OMAPY - OMAPY / 10 );
    // Pick an overall goal.
    goal = faction_goal( rng( 1, NUM_FACGOALS - 1 ) );
    if( one_in( 4 ) ) {
        goal = FACGOAL_NONE;    // Slightly more likely to not have a real goal
    }
    good     = facgoal_data[goal].good;
    strength = facgoal_data[goal].strength;
    sneak    = facgoal_data[goal].sneak;
    crime    = facgoal_data[goal].crime;
    cult     = facgoal_data[goal].cult;
    job1 = faction_job( rng( 1, NUM_FACJOBS - 1 ) );
    do {
        job2 = faction_job( rng( 0, NUM_FACJOBS - 1 ) );
    } while( job2 == job1 );
    good     += facjob_data[job1].good     + facjob_data[job2].good;
    strength += facjob_data[job1].strength + facjob_data[job2].strength;
    sneak    += facjob_data[job1].sneak    + facjob_data[job2].sneak;
    crime    += facjob_data[job1].crime    + facjob_data[job2].crime;
    cult     += facjob_data[job1].cult     + facjob_data[job2].cult;

    int num_values = 0;
    int tries = 0;
    values = 0;
    do {
        int v = rng( 1, NUM_FACVALS - 1 );
        if( !has_value( faction_value( v ) ) && matches_us( faction_value( v ) ) ) {
            values |= mfb( v );
            tries = 0;
            num_values++;
            good     += facval_data[v].good;
            strength += facval_data[v].strength;
            sneak    += facval_data[v].sneak;
            crime    += facval_data[v].crime;
            cult     += facval_data[v].cult;
        } else {
            tries++;
        }
    } while( ( one_in( num_values ) || one_in( num_values ) ) && tries < 15 );

    std::string noun;
    int sel = 1;
    int best = strength;
    if( sneak > best ) {
        sel = 2;
        best = sneak;
    }
    if( crime > best ) {
        sel = 3;
        best = crime;
    }
    if( cult > best ) {
        sel = 4;
    }
    if( strength <= 0 && sneak <= 0 && crime <= 0 && cult <= 0 ) {
        sel = 0;
    }

    switch( sel ) {
        case 1:
            noun  = pgettext( "faction_adj", random_entry_ref( faction_noun_strong ).c_str() );
            power = dice( 5, 20 );
            size  = dice( 5, 6 );
            break;
        case 2:
            noun  = pgettext( "faction_adj", random_entry_ref( faction_noun_sneak ).c_str() );
            power = dice( 5, 8 );
            size  = dice( 5, 8 );
            break;
        case 3:
            noun  = pgettext( "faction_adj", random_entry_ref( faction_noun_crime ).c_str() );
            power = dice( 5, 16 );
            size  = dice( 5, 8 );
            break;
        case 4:
            noun  = pgettext( "faction_adj", random_entry_ref( faction_noun_cult ).c_str() );
            power = dice( 8, 8 );
            size  = dice( 4, 6 );
            break;
        default:
            noun  = pgettext( "faction_adj", random_entry_ref( faction_noun_none ).c_str() );
            power = dice( 6, 8 );
            size  = dice( 6, 6 );
    }

    if( one_in( 4 ) ) {
        do {
            name = string_format( _( "The %1$s of %2$s" ), noun.c_str(), invent_name().c_str() );
        } while( utf8_width( name ) > MAX_FAC_NAME_SIZE );
    } else if( one_in( 2 ) ) {
        do {
            name = string_format( _( "The %1$s %2$s" ), invent_adj().c_str(), noun.c_str() );
        } while( utf8_width( name ) > MAX_FAC_NAME_SIZE );
    } else {
        do {
            std::string adj;
            if( good >= 3 ) {
                adj = _( random_entry_ref( faction_adj_pos ).c_str() );
            } else if( good <= -3 ) {
                adj = _( random_entry_ref( faction_adj_bad ).c_str() );
            } else {
                adj = _( random_entry_ref( faction_adj_neu ).c_str() );
            }
            name = string_format( _( "The %1$s %2$s" ), adj.c_str(), noun.c_str() );
            if( one_in( 4 ) ) {
                name = string_format( _( "%1$s of %2$s" ), name.c_str(), invent_name().c_str() );
            }
        } while( utf8_width( name ) > MAX_FAC_NAME_SIZE );
    }
}
예제 #3
0
skill_id Skill::random_skill()
{
    return random_entry_ref( skills ).ident();
}