diff options
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/acr.cc | 3 | ||||
-rw-r--r-- | crawl-ref/source/clua.cc | 3 | ||||
-rw-r--r-- | crawl-ref/source/debug.cc | 20 | ||||
-rw-r--r-- | crawl-ref/source/hiscores.cc | 26 | ||||
-rw-r--r-- | crawl-ref/source/newgame.cc | 15 | ||||
-rw-r--r-- | crawl-ref/source/output.cc | 13 | ||||
-rw-r--r-- | crawl-ref/source/player.cc | 45 | ||||
-rw-r--r-- | crawl-ref/source/player.h | 5 | ||||
-rw-r--r-- | crawl-ref/source/skills2.cc | 8 | ||||
-rw-r--r-- | crawl-ref/source/skills2.h | 9 | ||||
-rw-r--r-- | crawl-ref/source/tutorial.cc | 3 | ||||
-rw-r--r-- | crawl-ref/source/view.cc | 5 |
12 files changed, 80 insertions, 75 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index e933640067..7225fb98be 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -1502,7 +1502,8 @@ static void go_downstairs() static void experience_check() { mprf("You are a level %d %s %s.", - you.experience_level, species_name(you.species,you.experience_level), + you.experience_level, + species_name(you.species,you.experience_level).c_str(), you.class_name); if (you.experience_level < 27) diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc index 3094ef8d71..9feb395618 100644 --- a/crawl-ref/source/clua.cc +++ b/crawl-ref/source/clua.cc @@ -707,7 +707,8 @@ static const char *transform_name() LUARET1(you_turn_is_over, boolean, you.turn_is_over) LUARET1(you_name, string, you.your_name) -LUARET1(you_race, string, species_name(you.species, you.experience_level)) +LUARET1(you_race, string, + species_name(you.species, you.experience_level).c_str()) LUARET1(you_class, string, get_class_name(you.char_class)) LUARET1(you_god, string, god_name(you.religion)) LUARET2(you_hp, number, you.hp, you.hp_max) diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc index b6510b05ce..e33ce47ca9 100644 --- a/crawl-ref/source/debug.cc +++ b/crawl-ref/source/debug.cc @@ -242,18 +242,19 @@ void debug_change_species( void ) if (specs[0] == '\0') return; + strlwr(specs); species_type sp = SP_UNKNOWN; for (i = SP_HUMAN; i < NUM_SPECIES; i++) { - char sp_name[80]; - strncpy( sp_name, species_name(i, you.experience_level), sizeof( sp_name ) ); + const std::string sp_name = + lowercase_string(species_name(i, you.experience_level)); - char *ptr = strstr( strlwr(sp_name), strlwr(specs) ); - if (ptr != NULL) + std::string::size_type pos = sp_name.find(specs); + if (pos != std::string::npos) { - if (ptr == sp_name && strlen(specs) > 0) + if (pos == 0 && *specs) { // we prefer prefixes over partial matches sp = static_cast<species_type>(i); @@ -276,8 +277,9 @@ void debug_change_species( void ) you.species = sp; you.is_undead = ((you.species == SP_MUMMY) ? US_UNDEAD : - (you.species == SP_GHOUL || you.species == SP_VAMPIRE) ? US_HUNGRY_DEAD : US_ALIVE); - + (you.species == SP_GHOUL + || you.species == SP_VAMPIRE) ? US_HUNGRY_DEAD + : US_ALIVE); redraw_screen(); } } @@ -2367,7 +2369,7 @@ static void fsim_title(FILE *o, int mon, int ms) { fprintf(o, CRAWL " version " VERSION "\n\n"); fprintf(o, "Combat simulation: %s %s vs. %s (%ld rounds) (%s)\n", - species_name(you.species, you.experience_level), + species_name(you.species, you.experience_level).c_str(), you.class_name, menv[mon].name(DESC_PLAIN, true).c_str(), Options.fsim_rounds, @@ -2391,7 +2393,7 @@ static void fsim_defence_title(FILE *o, int mon) fprintf(o, CRAWL " version " VERSION "\n\n"); fprintf(o, "Combat simulation: %s vs. %s %s (%ld rounds) (%s)\n", menv[mon].name(DESC_PLAIN).c_str(), - species_name(you.species, you.experience_level), + species_name(you.species, you.experience_level).c_str(), you.class_name, Options.fsim_rounds, fsim_time_string().c_str()); diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc index 830fa9f0f4..80228016fc 100644 --- a/crawl-ref/source/hiscores.cc +++ b/crawl-ref/source/hiscores.cc @@ -659,7 +659,7 @@ void scorefile_entry::set_base_xlog_fields() const fields->add_field("lv", SCORE_VERSION); fields->add_field("name", "%s", name.c_str()); fields->add_field("uid", "%d", uid); - fields->add_field("race", "%s", species_name(race, lvl)); + fields->add_field("race", "%s", species_name(race, lvl).c_str()); fields->add_field("cls", "%s", get_class_name(cls)); fields->add_field("char", "%s%s", get_species_abbrev(race), @@ -667,8 +667,9 @@ void scorefile_entry::set_base_xlog_fields() const fields->add_field("xl", "%d", lvl); fields->add_field("sk", "%s", skill_name(best_skill)); fields->add_field("sklev", "%d", best_skill_lvl); - fields->add_field("title", "%s", skill_title( best_skill, best_skill_lvl, - race, str, dex, god ) ); + fields->add_field("title", "%s", + skill_title( best_skill, best_skill_lvl, + race, str, dex, god ).c_str() ); fields->add_field("place", "%s", place_name(get_packed_place(branch, dlvl, level_type), @@ -1201,19 +1202,17 @@ scorefile_entry::character_description(death_desc_verbosity verbosity) const // Please excuse the following bit of mess in the name of flavour ;) if (verbose) { - strncpy( scratch, skill_title( best_skill, best_skill_lvl, - race, str, dex, god ), - INFO_SIZE ); - snprintf( buf, HIGHSCORE_SIZE, "%8ld %s the %s (level %d", - points, name.c_str(), scratch, lvl ); - + points, name.c_str(), + skill_title( best_skill, best_skill_lvl, + race, str, dex, god ).c_str(), + lvl ); desc = buf; } else { snprintf( buf, HIGHSCORE_SIZE, "%8ld %s the %s %s (level %d", - points, name.c_str(), species_name(race, lvl), + points, name.c_str(), species_name(race, lvl).c_str(), get_class_name(cls), lvl ); desc = buf; } @@ -1237,10 +1236,11 @@ scorefile_entry::character_description(death_desc_verbosity verbosity) const if (verbose) { - const char *const srace = species_name( race, lvl ); - + std::string srace = species_name( race, lvl ); snprintf( scratch, INFO_SIZE, "Began as a%s %s %s", - is_vowel(*srace) ? "n" : "", srace, get_class_name(cls) ); + is_vowel(srace[0]) ? "n" : "", + srace.c_str(), + get_class_name(cls) ); desc += scratch; if (birth_time > 0) diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc index 3a88d2a863..5496ff06e3 100644 --- a/crawl-ref/source/newgame.cc +++ b/crawl-ref/source/newgame.cc @@ -777,12 +777,12 @@ game_start: { clrscr(); - char spec_buff[80]; - strncpy(spec_buff, - species_name(you.species, you.experience_level), 80); + std::string specs = species_name(you.species, you.experience_level); + if (specs.length() > 79) + specs = specs.substr(0, 79); cprintf( "You are a%s %s %s." EOL, - (is_vowel( spec_buff[0] )) ? "n" : "", spec_buff, + (is_vowel( specs[0] )) ? "n" : "", specs.c_str(), you.class_name ); enter_player_name(false); @@ -3099,8 +3099,8 @@ spec_query: char buf[100]; char sletter = species_to_letter(i); snprintf(buf, sizeof buf, "%c - %-26s", - sletter, - species_name(i, 1)); + sletter, + species_name(i, 1).c_str()); if (sletter == Options.prev_race) prevraceok = true; strncat(linebuf, buf, sizeof linebuf); @@ -3266,7 +3266,8 @@ job_query: textcolor( YELLOW ); if (you.your_name[0]) cprintf("%s the ", you.your_name); - cprintf("%s.", species_name(you.species,you.experience_level)); + cprintf("%s.", + species_name(you.species,you.experience_level).c_str()); } else { diff --git a/crawl-ref/source/output.cc b/crawl-ref/source/output.cc index 745f6881b3..a6aac29f88 100644 --- a/crawl-ref/source/output.cc +++ b/crawl-ref/source/output.cc @@ -726,11 +726,13 @@ std::vector<formatted_string> get_full_detail(bool calc_unid, long sc) "Worship : %s%s\n" "Level : %7d\n" "Exp : %7lu\n", - you.your_name, player_title(), + you.your_name, + player_title().c_str(), score.c_str(), - species_name(you.species,you.experience_level), + species_name(you.species,you.experience_level).c_str(), you.class_name, - god_colour_tag, godpowers.c_str(), + god_colour_tag, + godpowers.c_str(), you.experience_level, you.experience); cols.add_formatted(0, buf, false); @@ -993,12 +995,13 @@ void print_overview_screen() std::string text; char title[50]; - snprintf(title, sizeof title, " the %s ", player_title()); + snprintf(title, sizeof title, " the %s ", player_title().c_str()); char race_class[50]; snprintf(race_class, sizeof race_class, "(%s %s)", - species_name(you.species, you.experience_level), you.class_name); + species_name(you.species, you.experience_level).c_str(), + you.class_name); char time_turns[50] = ""; diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index e6e36f69be..237f8da703 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -3517,40 +3517,31 @@ void display_char_status() #endif } // end display_char_status() -void redraw_skill(const char your_name[kNameLen], const char class_name[80]) +void redraw_skill(const std::string &your_name, const std::string &class_name) { - char print_it[80]; + std::string title = your_name + " the " + class_name; - snprintf( print_it, sizeof(print_it), "%s the %s", your_name, class_name ); - - int in_len = strlen( print_it ); + int in_len = title.length(); if (in_len > 40) { in_len -= 3; // what we're getting back from removing "the" - const int name_len = strlen(your_name); - char name_buff[kNameLen]; - strncpy( name_buff, your_name, kNameLen ); + const int name_len = your_name.length(); + std::string trimmed_name = your_name; - // squeeze name if required, the "- 8" is too not squeeze too much + // squeeze name if required, the "- 8" is to not squeeze too much if (in_len > 40 && (name_len - 8) > (in_len - 40)) - name_buff[ name_len - (in_len - 40) - 1 ] = 0; - else - name_buff[ kNameLen - 1 ] = 0; + trimmed_name = + trimmed_name.substr(0, name_len - (in_len - 40) - 1); - snprintf( print_it, sizeof(print_it), "%s, %s", name_buff, class_name ); + title = trimmed_name + ", " + class_name; } - for (int i = strlen(print_it); i < 41; i++) - print_it[i] = ' '; - - print_it[40] = 0; - gotoxy(crawl_view.hudp.x, 1); textcolor( LIGHTGREY ); - cprintf( "%s", print_it ); -} // end redraw_skill() + cprintf( "%-41s", title.c_str() ); +} // Does a case-sensitive lookup of the species name supplied. int str_to_species(const std::string &species) @@ -3575,7 +3566,8 @@ int str_to_species(const std::string &species) // Note that this function only has the one static buffer, so if you // want to use the results, you'll want to make a copy. -char *species_name( int speci, int level, bool genus, bool adj, bool cap ) +std::string species_name( int speci, int level, bool genus, + bool adj, bool cap ) // defaults: false false true { static char species_buff[80]; @@ -4498,7 +4490,7 @@ int get_species_index_by_name( const char *name ) int i; int sp = -1; - char *ptr; + std::string::size_type pos = std::string::npos; char lowered_buff[80]; strncpy( lowered_buff, name, sizeof( lowered_buff ) ); @@ -4506,12 +4498,13 @@ int get_species_index_by_name( const char *name ) for (i = SP_HUMAN; i < NUM_SPECIES; i++) { - char *lowered_species = species_name( i, 0, false, false, false ); - ptr = strstr( lowered_species, lowered_buff ); - if (ptr != NULL) + std::string lowered_species = + lowercase_string( species_name( i, 0, false, false, false ) ); + pos = lowered_species.find( lowered_buff ); + if (pos != std::string::npos) { sp = i; - if (ptr == lowered_species) // prefix takes preference + if (pos == 0) // prefix takes preference break; } } diff --git a/crawl-ref/source/player.h b/crawl-ref/source/player.h index c9e9ba6d99..390ce4e505 100644 --- a/crawl-ref/source/player.h +++ b/crawl-ref/source/player.h @@ -79,7 +79,8 @@ bool wearing_amulet(char which_am, bool calc_unid = true); /* *********************************************************************** * called from: acr - chardump - describe - newgame - view * *********************************************************************** */ -char *species_name( int speci, int level, bool genus = false, bool adj = false, bool cap = true ); +std::string species_name( int speci, int level, bool genus = false, + bool adj = false, bool cap = true ); int str_to_species(const std::string &species); /* *********************************************************************** @@ -313,7 +314,7 @@ void level_change(bool skip_ability_increase = false); /* *********************************************************************** * called from: skills * *********************************************************************** */ -void redraw_skill(const char your_name[kNameLen], const char class_name[80]); +void redraw_skill(const std::string &your_name, const std::string &class_name); /* *********************************************************************** diff --git a/crawl-ref/source/skills2.cc b/crawl-ref/source/skills2.cc index 91bfaca21c..caebff81da 100644 --- a/crawl-ref/source/skills2.cc +++ b/crawl-ref/source/skills2.cc @@ -1997,7 +1997,7 @@ int str_to_skill(const std::string &skill) return (SK_FIGHTING); } -const char *skill_title( unsigned char best_skill, unsigned char skill_lev, +std::string skill_title( unsigned char best_skill, unsigned char skill_lev, int species, int str, int dex, int god ) { unsigned char skill_rank; @@ -2067,7 +2067,8 @@ const char *skill_title( unsigned char best_skill, unsigned char skill_lev, // need species name snprintf( title_buff, sizeof(title_buff), tempstr, species_name(species, 0, true, - (ptr == tempstr && best_skill != SK_NECROMANCY)) ); + (ptr == tempstr + && best_skill != SK_NECROMANCY)).c_str() ); // The above code only capitalises start-of-string racenames tempstr = title_buff; } @@ -2075,10 +2076,9 @@ const char *skill_title( unsigned char best_skill, unsigned char skill_lev, return ((tempstr == NULL) ? "Invalid Title" : tempstr); } // end skill_title() -const char *player_title( void ) +std::string player_title( void ) { const unsigned char best = best_skill( SK_FIGHTING, (NUM_SKILLS - 1), 99 ); - return (skill_title( best, you.skills[ best ] )); } // end player_title() diff --git a/crawl-ref/source/skills2.h b/crawl-ref/source/skills2.h index 8618d6ee76..fe737bba7a 100644 --- a/crawl-ref/source/skills2.h +++ b/crawl-ref/source/skills2.h @@ -30,15 +30,16 @@ int str_to_skill(const std::string &skill); /* *********************************************************************** * called from: describe * *********************************************************************** */ -const char * skill_title( unsigned char best_skill, unsigned char skill_lev, - // these used for ghosts and hiscores: - int species = -1, int str = -1, int dex = -1, int god = -1 ); +std::string skill_title( + unsigned char best_skill, unsigned char skill_lev, + // these used for ghosts and hiscores: + int species = -1, int str = -1, int dex = -1, int god = -1 ); // last_updated Sept 20 -- bwr /* *********************************************************************** * called from: acr - chardump - player - skills - stuff * *********************************************************************** */ -const char *player_title( void ); +std::string player_title( void ); // last_updated 24may2000 {dlb} diff --git a/crawl-ref/source/tutorial.cc b/crawl-ref/source/tutorial.cc index efde782355..73ae84b49f 100644 --- a/crawl-ref/source/tutorial.cc +++ b/crawl-ref/source/tutorial.cc @@ -188,7 +188,8 @@ void print_tutorial_menu(unsigned int type) break; } - cprintf("%c - %s %s %s" EOL, letter, species_name(get_tutorial_species(type), 1), + cprintf("%c - %s %s %s" EOL, + letter, species_name(get_tutorial_species(type), 1).c_str(), get_class_name(get_tutorial_job(type)), desc); } diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index 0fd01f982c..de20a9dd85 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -2377,8 +2377,9 @@ void draw_border(void) const int xcol = crawl_view.hudp.x; gotoxy(xcol, 2); - cprintf( "%s %s", species_name( you.species, you.experience_level ), - (you.wizard ? "*WIZARD*" : "" ) ); + cprintf( "%s %s", + species_name( you.species, you.experience_level ).c_str(), + (you.wizard ? "*WIZARD*" : "" ) ); gotoxy(xcol, 3); cprintf("HP:"); gotoxy(xcol, 4); cprintf("Magic:"); |