Ejemplo n.º 1
0
std::string defense_game::special_wave_message(std::string name)
{
 std::stringstream ret;
 ret << string_format(_("Wave %d: "), current_wave);

 // Capitalize
 capitalize_letter(name);
 for (int i = 2; i < name.size(); i++) {
  if (name[i - 1] == ' ') {
    capitalize_letter(name, i);
  }
 }

 switch (rng(1, 6)) {
  case 1: ret << string_format(_("%s Invasion!"), name.c_str()); break;
  case 2: ret << string_format(_("Attack of the %ss!"), name.c_str()); break;
  case 3: ret << string_format(_("%s Attack!"), name.c_str()); break;
  case 4: ret << string_format(_("%s from Hell!"), name.c_str()); break;
  case 5: ret << string_format(_("Beware! %s!"), name.c_str()); break;
  case 6: ret << string_format(_("The Day of the %s!"), name.c_str()); break;
  case 7: ret << string_format(_("%s Party!"), name.c_str()); break;
  case 8: ret << string_format(_("Revenge of the %ss!"), name.c_str()); break;
  case 9: ret << string_format(_("Rise of the %ss!"), name.c_str()); break;
 }

 return ret.str();
}
Ejemplo n.º 2
0
void monster::add_msg_if_npc(game_message_type type, const char *msg, ...)
{
    va_list ap;
    va_start(ap, msg);
    std::string processed_npc_string = vstring_format(msg, ap);
    // These strings contain the substring <npcname>,
    // if present replace it with the actual monster name.
    size_t offset = processed_npc_string.find("<npcname>");
    if (offset != std::string::npos) {
        processed_npc_string.replace(offset, 9, disp_name());
        if (offset == 0 && !processed_npc_string.empty()) {
            capitalize_letter(processed_npc_string, 0);
        }
    }
    add_msg(type, processed_npc_string.c_str());
    va_end(ap);
}
Ejemplo n.º 3
0
void monster::add_msg_player_or_npc(const char *, const char* npc_str, ...)
{
    va_list ap;
    va_start(ap, npc_str);
    if (g->u_see(this)) {
        std::string processed_npc_string = vstring_format(npc_str, ap);
        // These strings contain the substring <npcname>,
        // if present replace it with the actual monster name.
        size_t offset = processed_npc_string.find("<npcname>");
        if (offset != std::string::npos) {
            processed_npc_string.replace(offset, 9, disp_name());
            if (offset == 0 && !processed_npc_string.empty()) {
                capitalize_letter(processed_npc_string, 0);
            }
        }
        add_msg(processed_npc_string.c_str());
    }
    va_end(ap);
}
Ejemplo n.º 4
0
std::string invent_name()
{
 std::string ret = "";
 std::string tmp;
 int syllables = rng(2, 3);
 for (int i = 0; i < syllables; i++) {
  switch (rng(0, 25)) {
   case  0: tmp = _("<fac_name>ab");  break;
   case  1: tmp = _("<fac_name>bon"); break;
   case  2: tmp = _("<fac_name>cor"); break;
   case  3: tmp = _("<fac_name>den"); break;
   case  4: tmp = _("<fac_name>el");  break;
   case  5: tmp = _("<fac_name>fes"); break;
   case  6: tmp = _("<fac_name>gun"); break;
   case  7: tmp = _("<fac_name>hit"); break;
   case  8: tmp = _("<fac_name>id");  break;
   case  9: tmp = _("<fac_name>jan"); break;
   case 10: tmp = _("<fac_name>kal"); break;
   case 11: tmp = _("<fac_name>ler"); break;
   case 12: tmp = _("<fac_name>mal"); break;
   case 13: tmp = _("<fac_name>nor"); break;
   case 14: tmp = _("<fac_name>or");  break;
   case 15: tmp = _("<fac_name>pan"); break;
   case 16: tmp = _("<fac_name>qua"); break;
   case 17: tmp = _("<fac_name>ros"); break;
   case 18: tmp = _("<fac_name>sin"); break;
   case 19: tmp = _("<fac_name>tor"); break;
   case 20: tmp = _("<fac_name>urr"); break;
   case 21: tmp = _("<fac_name>ven"); break;
   case 22: tmp = _("<fac_name>wel"); break;
   case 23: tmp = _("<fac_name>oxo");  break;
   case 24: tmp = _("<fac_name>yen"); break;
   case 25: tmp = _("<fac_name>zu");  break;
  }
  ret += rm_prefix(tmp);
 }

 return capitalize_letter(ret);
}
Ejemplo n.º 5
0
void sounds::process_sound_markers( player *p )
{
    bool is_deaf = p->is_deaf();
    const float volume_multiplier = p->hearing_ability();
    const int weather_vol = weather_data( g->weather ).sound_attn;
    for( const auto &sound_event_pair : sounds_since_last_turn ) {
        const int volume = sound_event_pair.second.volume * volume_multiplier;
        const std::string& sfx_id = sound_event_pair.second.id;
        const std::string& sfx_variant = sound_event_pair.second.variant;
        const int max_volume = std::max( volume, sound_event_pair.second.volume );  // For deafness checks
        int dist = rl_dist( p->pos(), sound_event_pair.first );
        bool ambient = sound_event_pair.second.ambient;
        // Too far away, we didn't hear it!
        if( dist > volume ) {
            continue;
        }
        if( is_deaf ) {
            // Has to be here as well to work for stacking deafness (loud noises prolong deafness)
            if( !p->is_immune_effect( effect_deaf )
                    && rng( ( max_volume - dist ) / 2, ( max_volume - dist ) ) >= 150 ) {
                // Prolong deafness, but not as much as if it was freshly applied
                int duration = std::min( 40, ( max_volume - dist - 130 ) / 8 );
                p->add_effect( effect_deaf, duration );
                if( !p->has_trait( "DEADENED" ) ) {
                    p->add_msg_if_player( m_bad, _( "Your eardrums suddenly ache!" ) );
                    if( p->pain < 10 ) {
                        p->mod_pain( rng( 0, 2 ) );
                    }
                }
            }
            // We're deaf, skip rest of processing.
            continue;
        }
        // Player volume meter includes all sounds from their tile and adjacent tiles
        // TODO: Add noises from vehicle player is in.
        if( dist <= 1 ) {
            p->volume = std::max( p->volume, volume );
        }
        // Check for deafness
        if( !p->is_immune_effect( effect_deaf ) && rng((max_volume - dist) / 2, (max_volume - dist)) >= 150 ) {
            int duration = (max_volume - dist - 130) / 4;
            p->add_effect( effect_deaf, duration );
            if( p->is_deaf() ) {
                // Need to check for actual deafness
                is_deaf = true;
                sfx::do_hearing_loss( duration );
                continue;
            }
        }
        // At this point we are dealing with attention (as opposed to physical effects)
        // so reduce volume by the amount of ambient noise from the weather.
        const int mod_vol = ( sound_event_pair.second.volume - weather_vol ) * volume_multiplier;
        // The noise was drowned out by the surroundings.
        if( mod_vol - dist < 0 ) {
            continue;
        }
        // See if we need to wake someone up
        if( p->has_effect( effect_sleep ) ) {
            if( ( !( p->has_trait( "HEAVYSLEEPER" ) ||
                     p->has_trait( "HEAVYSLEEPER2" ) ) && dice( 2, 15 ) < mod_vol - dist ) ||
                    ( p->has_trait( "HEAVYSLEEPER" ) && dice( 3, 15 ) < mod_vol - dist ) ||
                    ( p->has_trait( "HEAVYSLEEPER2" ) && dice( 6, 15 ) < mod_vol - dist ) ) {
                //Not kidding about sleep-thru-firefight
                p->wake_up();
                add_msg( m_warning, _( "Something is making noise." ) );
            } else {
                continue;
            }
        }
        const tripoint &pos = sound_event_pair.first;
        const std::string &description = sound_event_pair.second.description;
        if( !ambient && ( pos != p->pos() ) && !g->m.pl_sees( pos, dist ) ) {
            if( p->activity.ignore_trivial != true ) {
                std::string query;
                if( description.empty() ) {
                    query = _( "Heard a noise!" );
                } else {
                    query = string_format( _( "Heard %s!" ),
                                           sound_event_pair.second.description.c_str() );
                }
                if( g->cancel_activity_or_ignore_query( query.c_str() ) ) {
                    p->activity.ignore_trivial = true;
                    for( auto activity : p->backlog ) {
                        activity.ignore_trivial = true;
                    }
                }
            }
        }
        // Only print a description if it exists
        if( !description.empty() ) {
            // If it came from us, don't print a direction
            if( pos == p->pos() ) {
                std::string uppercased = description;
                capitalize_letter( uppercased, 0 );
                add_msg( "%s", uppercased.c_str() );
            } else {
                // Else print a direction as well
                std::string direction = direction_name( direction_from( p->pos(), pos ) );
                add_msg( m_warning, _( "From the %s you hear %s" ), direction.c_str(), description.c_str() );
            }
        }
        // Play the sound effect, if any.
        if( !sfx_id.empty() ) {
            // for our sfx API, 100 is "normal" volume, so scale accordingly
            int heard_volume = sfx::get_heard_volume( pos );
            sfx::play_variant_sound( sfx_id, sfx_variant, heard_volume );
            //add_msg("Playing sound effect %s, %s, %d", sfx_id.c_str(), sfx_variant.c_str(), heard_volume);
        }
        // If Z coord is different, draw even when you can see the source
        const bool diff_z = pos.z != p->posz();
        // Place footstep markers.
        if( pos == p->pos() || p->sees( pos ) ) {
            // If we are or can see the source, don't draw a marker.
            continue;
        }
        int err_offset;
        if( mod_vol / dist < 2 ) {
            err_offset = 3;
        } else if( mod_vol / dist < 3 ) {
            err_offset = 2;
        } else {
            err_offset = 1;
        }
        // Enumerate the valid points the player *cannot* see.
        // Unless the source is on a different z-level, then any point is fine
        std::vector<tripoint> unseen_points;
        tripoint newp = pos;
        int &newx = newp.x;
        int &newy = newp.y;
        for( newx = pos.x - err_offset; newx <= pos.x + err_offset; newx++ ) {
            for( newy = pos.y - err_offset; newy <= pos.y + err_offset; newy++ ) {
                if( diff_z || !p->sees( newp ) ) {
                    unseen_points.emplace_back( newp );
                }
            }
        }
        // Then place the sound marker in a random one.
        if( !unseen_points.empty() ) {
            sound_markers.emplace( random_entry( unseen_points ),
                                   sound_event_pair.second );
        }
    }
    sounds_since_last_turn.clear();
}
Ejemplo n.º 6
0
std::string invent_name()
{
    std::string ret;
    std::string tmp;
    int syllables = rng( 2, 3 );
    for( int i = 0; i < syllables; i++ ) {
        switch( rng( 0, 25 ) ) {
            case  0:
                tmp = pgettext( "faction name", "ab" );
                break;
            case  1:
                tmp = pgettext( "faction name", "bon" );
                break;
            case  2:
                tmp = pgettext( "faction name", "cor" );
                break;
            case  3:
                tmp = pgettext( "faction name", "den" );
                break;
            case  4:
                tmp = pgettext( "faction name", "el" );
                break;
            case  5:
                tmp = pgettext( "faction name", "fes" );
                break;
            case  6:
                tmp = pgettext( "faction name", "gun" );
                break;
            case  7:
                tmp = pgettext( "faction name", "hit" );
                break;
            case  8:
                tmp = pgettext( "faction name", "id" );
                break;
            case  9:
                tmp = pgettext( "faction name", "jan" );
                break;
            case 10:
                tmp = pgettext( "faction name", "kal" );
                break;
            case 11:
                tmp = pgettext( "faction name", "ler" );
                break;
            case 12:
                tmp = pgettext( "faction name", "mal" );
                break;
            case 13:
                tmp = pgettext( "faction name", "nor" );
                break;
            case 14:
                tmp = pgettext( "faction name", "or" );
                break;
            case 15:
                tmp = pgettext( "faction name", "pan" );
                break;
            case 16:
                tmp = pgettext( "faction name", "qua" );
                break;
            case 17:
                tmp = pgettext( "faction name", "ros" );
                break;
            case 18:
                tmp = pgettext( "faction name", "sin" );
                break;
            case 19:
                tmp = pgettext( "faction name", "tor" );
                break;
            case 20:
                tmp = pgettext( "faction name", "urr" );
                break;
            case 21:
                tmp = pgettext( "faction name", "ven" );
                break;
            case 22:
                tmp = pgettext( "faction name", "wel" );
                break;
            case 23:
                tmp = pgettext( "faction name", "oxo" );
                break;
            case 24:
                tmp = pgettext( "faction name", "yen" );
                break;
            case 25:
                tmp = pgettext( "faction name", "zu" );
                break;
        }
        ret += tmp;
    }

    return capitalize_letter( ret );
}
Ejemplo n.º 7
0
// yn to make an immediate selection
// esc to cancel, returns false
// enter or space to accept, any other key to toggle
bool query_yn(const char *mes, ...)
{
    va_list ap;
    va_start(ap, mes);
    const std::string text = vstring_format(mes, ap);
    va_end(ap);

    bool force_uc = OPTIONS["FORCE_CAPITAL_YN"];

    // localizes the selectors, requires translation to use lower case
    std::string selectors = _("yn");
    if (selectors.length()<2) {
        selectors = "yn";
    }
    std::string ucselectors = selectors;
    capitalize_letter(ucselectors, 0);
    capitalize_letter(ucselectors, 1);

    std::string ucwarning = "";
    std::string *dispkeys = &selectors;
    if (force_uc) {
        ucwarning = _("Case Sensitive");
        ucwarning = " (" + ucwarning +")";
        dispkeys = &ucselectors;
    }

    // figures the length of the combined texts
    // width needed for text +2 for the border. + (/) 4 for the symbols and a space
    int win_width = utf8_width(text.c_str()) + utf8_width(selectors.c_str()) + utf8_width(ucwarning.c_str()) + 2 + 4;
    win_width = (win_width < FULL_SCREEN_WIDTH - 2 ? win_width : FULL_SCREEN_WIDTH - 2);

    WINDOW *w = NULL;
    std::vector<std::string> textformatted;

    std::string query;
    std::string color_on = "<color_white>";
    std::string color_off = "</color>";

    char ch ='?';
    bool result = true;
    bool gotkey = false;

    while (ch != '\n' && ch != ' ' && ch != KEY_ESCAPE) {

        gotkey= (force_uc && ((ch == ucselectors[0]) || (ch == ucselectors[1])))
            || (!force_uc && ((ch == selectors[0]) || (ch == selectors[1])));

        if (gotkey) {
            result = (!force_uc && (ch == selectors[0])) || (force_uc && (ch == ucselectors[0]));
            break; // could move break past render to flash final choice once.
        } else
        if ((!force_uc && (ch != ucselectors[0]) && (ch != ucselectors[1]))
            || (force_uc && ((ch != selectors[0]) && (ch != selectors[1])))) {
            result = !result;
        }

        if (result) {
            query = " (" + color_on + dispkeys->substr(0,1) + color_off + "/" + dispkeys->substr(1,1) + ")";
        } else {
            query = " (" + dispkeys->substr(0,1) + "/" + color_on + dispkeys->substr(1,1) + color_off + ")";
        }
        if (force_uc) {
            query += ucwarning;
        }

        if (!w) {
            textformatted = foldstring(text + query, win_width);
            w = newwin(textformatted.size() + 2, win_width, (TERMY - 3) / 2,
                (TERMX > win_width) ? (TERMX - win_width) / 2 : 0);
            draw_border(w);
        }
        fold_and_print(w, 1, 1, win_width, c_ltred, text + query);
        wrefresh(w);

        ch = getch();
    };

    werase(w);
    wrefresh(w);
    delwin(w);
    refresh();
    return ((ch != KEY_ESCAPE) && result);
}