From 90629939ac4ba4ba84acf7b768c8673d4188c108 Mon Sep 17 00:00:00 2001 From: haranp Date: Sat, 28 Apr 2007 13:49:28 +0000 Subject: Some code review and cleanup. extern char info[] is almost gone. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1387 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/command.cc | 106 +++++---- crawl-ref/source/direct.cc | 33 +-- crawl-ref/source/effects.cc | 82 +++---- crawl-ref/source/externs.h | 2 +- crawl-ref/source/food.cc | 34 +-- crawl-ref/source/it_use2.cc | 24 +- crawl-ref/source/it_use3.cc | 55 ++--- crawl-ref/source/item_use.cc | 29 +-- crawl-ref/source/misc.cc | 18 +- crawl-ref/source/monplace.cc | 29 ++- crawl-ref/source/monstuff.cc | 22 +- crawl-ref/source/mstuff2.cc | 43 ++-- crawl-ref/source/newgame.cc | 8 +- crawl-ref/source/player.cc | 15 +- crawl-ref/source/religion.cc | 6 +- crawl-ref/source/shopping.cc | 10 +- crawl-ref/source/spells2.cc | 56 +++-- crawl-ref/source/spells4.cc | 16 +- crawl-ref/source/spl-book.cc | 1 - crawl-ref/source/stash.cc | 26 +-- crawl-ref/source/tutorial.cc | 521 ++++++++++++++++++++++--------------------- crawl-ref/source/tutorial.h | 2 - crawl-ref/source/view.cc | 35 ++- 23 files changed, 544 insertions(+), 629 deletions(-) diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc index 6a8e953b99..865d1148d1 100644 --- a/crawl-ref/source/command.cc +++ b/crawl-ref/source/command.cc @@ -412,65 +412,58 @@ static void adjust_ability(void) mprf("%c - %s", input_1, get_ability_name_by_index( index_2 ) ); } // end adjust_ability() -void list_armour(void) -{ +void list_armour() +{ + std::ostringstream estr; for (int i = EQ_CLOAK; i <= EQ_BODY_ARMOUR; i++) - { - int armour_id = you.equip[i]; - - strcpy( info, - (i == EQ_CLOAK) ? "Cloak " : - (i == EQ_HELMET) ? "Helmet " : - (i == EQ_GLOVES) ? "Gloves " : - (i == EQ_SHIELD) ? "Shield " : - (i == EQ_BODY_ARMOUR) ? "Armour " : - - (i == EQ_BOOTS - && !(you.species == SP_CENTAUR || you.species == SP_NAGA)) - ? "Boots " : - (i == EQ_BOOTS - && (you.species == SP_CENTAUR || you.species == SP_NAGA)) - ? "Barding" - : "unknown" ); - - strcat(info, " : "); + { + const int armour_id = you.equip[i]; + + estr.str(""); + estr.clear(); + + estr << ((i == EQ_CLOAK) ? "Cloak " : + (i == EQ_HELMET) ? "Helmet " : + (i == EQ_GLOVES) ? "Gloves " : + (i == EQ_SHIELD) ? "Shield " : + (i == EQ_BODY_ARMOUR) ? "Armour " : + (i == EQ_BOOTS) ? + ((you.species == SP_CENTAUR || you.species == SP_NAGA) ? + "Barding" : "Boots ") : "unknown") + << " : "; if (armour_id != -1) - { - strcat(info, you.inv[armour_id].name(DESC_INVENTORY).c_str()); - } + estr << you.inv[armour_id].name(DESC_INVENTORY); else - { - strcat(info, " none"); - } + estr << " none"; - mpr( info, MSGCH_EQUIPMENT, menu_colour(info) ); + mpr( estr.str().c_str(), MSGCH_EQUIPMENT, menu_colour(estr.str()) ); } } // end list_armour() void list_jewellery(void) { + std::ostringstream jstr; + for (int i = EQ_LEFT_RING; i <= EQ_AMULET; i++) { - int jewellery_id = you.equip[i]; + const int jewellery_id = you.equip[i]; - strcpy( info, (i == EQ_LEFT_RING) ? "Left ring " : - (i == EQ_RIGHT_RING) ? "Right ring" : - (i == EQ_AMULET) ? "Amulet " - : "unknown " ); + jstr.str(""); + jstr.clear(); - strcat(info, " : "); + jstr << ((i == EQ_LEFT_RING) ? "Left ring " : + (i == EQ_RIGHT_RING) ? "Right ring" : + (i == EQ_AMULET) ? "Amulet " + : "unknown ") + << " : "; if (jewellery_id != -1) - { - strcat(info, you.inv[jewellery_id].name(DESC_INVENTORY).c_str()); - } + jstr << you.inv[jewellery_id].name(DESC_INVENTORY); else - { - strcat(info, " none"); - } + jstr << " none"; - mpr( info, MSGCH_EQUIPMENT, menu_colour(info) ); + mpr( jstr.str().c_str(), MSGCH_EQUIPMENT, menu_colour(jstr.str()) ); } } // end list_jewellery() @@ -482,21 +475,21 @@ void list_weapons(void) // // Yes, this is already on the screen... I'm outputing it // for completeness and to avoid confusion. - strcpy(info, "Current : "); + std::string wstring = "Current : "; if (weapon_id != -1) { - strcat(info, you.inv[weapon_id].name(DESC_INVENTORY_EQUIP).c_str()); + wstring += you.inv[weapon_id].name(DESC_INVENTORY_EQUIP); } else { if (you.attribute[ATTR_TRANSFORMATION] == TRAN_BLADE_HANDS) - strcat(info, " blade hands"); + wstring += " blade hands"; else - strcat(info, " empty hands"); + wstring += " empty hands"; } - mpr(info, MSGCH_EQUIPMENT, menu_colour(info)); + mpr(wstring.c_str(), MSGCH_EQUIPMENT, menu_colour(wstring)); // Print out the swap slots for (int i = 0; i <= 1; i++) @@ -506,29 +499,30 @@ void list_weapons(void) if (weapon_id == i) continue; - strcpy(info, (i == 0) ? "Primary : " : "Secondary : "); + if ( i == 0 ) + wstring = "Primary : "; + else + wstring = "Secondary : "; if (is_valid_item( you.inv[i] )) - { - strcat(info, you.inv[i].name(DESC_INVENTORY_EQUIP).c_str()); - } + wstring += you.inv[i].name(DESC_INVENTORY_EQUIP); else - strcat(info, " none"); + wstring += " none"; - mpr(info, MSGCH_EQUIPMENT, menu_colour(info)); // Output slot + mpr(wstring.c_str(), MSGCH_EQUIPMENT, menu_colour(wstring)); } // Now we print out the current default fire weapon - strcpy(info, "Firing : "); + wstring = "Firing : "; const int item = get_fire_item_index(); if (item == ENDOFPACK) - strcat(info, " nothing"); + wstring += " nothing"; else - strcat(info, you.inv[item].name(DESC_INVENTORY_EQUIP).c_str()); + wstring += you.inv[item].name(DESC_INVENTORY_EQUIP); - mpr( info, MSGCH_EQUIPMENT, menu_colour(info) ); + mpr( wstring.c_str(), MSGCH_EQUIPMENT, menu_colour(wstring) ); } // end list_weapons() static bool cmdhelp_textfilter(const std::string &tag) diff --git a/crawl-ref/source/direct.cc b/crawl-ref/source/direct.cc index e3a72439f0..a532953eda 100644 --- a/crawl-ref/source/direct.cc +++ b/crawl-ref/source/direct.cc @@ -1410,50 +1410,51 @@ static void describe_mons_enchantment(const monsters &mons, if (ench.ench == ENCH_HASTE && mons.has_ench(ENCH_BERSERK)) return; - - strcpy(info, mons_pronoun(mons.type, PRONOUN_CAP)); + + std::string msg = mons_pronoun(mons.type, PRONOUN_CAP); switch (ench.ench) { case ENCH_POISON: - strcat(info, " is poisoned."); + msg += " is poisoned."; break; case ENCH_SICK: - strcat(info, " is sick."); + msg += " is sick."; break; case ENCH_ROT: - strcat(info, " is rotting away."); //jmf: "covered in sores"? + msg += " is rotting away."; //jmf: "covered in sores"? break; case ENCH_BACKLIGHT: - strcat(info, " is softly glowing."); + msg += " is softly glowing."; break; case ENCH_SLOW: - strcat(info, " is moving slowly."); + msg += " is moving slowly."; break; case ENCH_BERSERK: - strcat(info, " is berserk!"); + msg += " is berserk!"; break; case ENCH_HASTE: - strcat(info, " is moving very quickly."); + msg += " is moving very quickly."; break; case ENCH_CONFUSION: - strcat(info, " appears to be bewildered and confused."); + msg += " appears to be bewildered and confused."; break; case ENCH_INVIS: - strcat(info, " is slightly transparent."); + msg += " is slightly transparent."; break; case ENCH_CHARM: - strcat(info, " is in your thrall."); + msg += " is in your thrall."; break; case ENCH_STICKY_FLAME: - strcat(info, " is covered in liquid flames."); + msg += " is covered in liquid flames."; break; default: - info[0] = 0; + msg.clear(); break; } // end switch - if (info[0]) - mpr(info); + + if (!msg.empty()) + mpr(msg.c_str()); } static void describe_cell(int mx, int my) diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc index dbca2a05d7..2427959694 100644 --- a/crawl-ref/source/effects.cc +++ b/crawl-ref/source/effects.cc @@ -194,7 +194,7 @@ bool lose_stat(unsigned char which_stat, unsigned char stat_loss, bool force) char newValue = 0; // holds new value, for comparison to old {dlb} // begin outputing message: {dlb} - strcpy(info, "You feel "); + std::string msg = "You feel "; // set pointers to appropriate variables: {dlb} if (which_stat == STAT_RANDOM) @@ -203,19 +203,19 @@ bool lose_stat(unsigned char which_stat, unsigned char stat_loss, bool force) switch (which_stat) { case STAT_STRENGTH: - strcat(info, "weakened"); + msg += "weakened"; ptr_stat = &you.strength; ptr_redraw = &you.redraw_strength; break; case STAT_DEXTERITY: - strcat(info, "clumsy"); + msg += "clumsy"; ptr_stat = &you.dex; ptr_redraw = &you.redraw_dexterity; break; case STAT_INTELLIGENCE: - strcat(info, "dopey"); + msg += "dopey"; ptr_stat = &you.intel; ptr_redraw = &you.redraw_intelligence; break; @@ -255,11 +255,11 @@ bool lose_stat(unsigned char which_stat, unsigned char stat_loss, bool force) // a warning to player that s/he cut it close: {dlb} if (!statLowered) - strcat(info, " for a moment"); + msg += " for a moment"; // finish outputting message: {dlb} - strcat(info, "."); - mpr(info); + msg += "."; + mpr(msg.c_str()); return (statLowered); } // end lose_stat() @@ -399,39 +399,31 @@ void random_uselessness(unsigned char ru, unsigned char sc_read_2) break; case 3: - strcpy(info, "You hear the distant roaring of an enraged "); - temp_rand = random2(8); - - strcat(info, (temp_rand == 0) ? "frog" : - (temp_rand == 1) ? "pill bug" : - (temp_rand == 2) ? "millipede" : - (temp_rand == 3) ? "eggplant" : - (temp_rand == 4) ? "albino dragon" : - (temp_rand == 5) ? "dragon" : - (temp_rand == 6) ? "human" - : "slug"); - - strcat(info, "!"); - mpr(info); + mprf("You hear the distant roaring of an enraged %s!", + (temp_rand == 0) ? "frog" : + (temp_rand == 1) ? "pill bug" : + (temp_rand == 2) ? "millipede" : + (temp_rand == 3) ? "eggplant" : + (temp_rand == 4) ? "albino dragon" : + (temp_rand == 5) ? "dragon" : + (temp_rand == 6) ? "human" + : "slug"); break; case 4: if (player_can_smell()) { - strcpy(info, "You smell "); - temp_rand = random2(8); - - strcat(info, (temp_rand == 0) ? "coffee." : - (temp_rand == 1) ? "salt." : - (temp_rand == 2) ? "burning hair!" : - (temp_rand == 3) ? "baking bread." : - (temp_rand == 4) ? "something weird." : - (temp_rand == 5) ? "wet wool." : - (temp_rand == 6) ? "sulphur." - : "fire and brimstone!"); - mpr(info); + mprf("You smell %s", + (temp_rand == 0) ? "coffee." : + (temp_rand == 1) ? "salt." : + (temp_rand == 2) ? "burning hair!" : + (temp_rand == 3) ? "baking bread." : + (temp_rand == 4) ? "something weird." : + (temp_rand == 5) ? "wet wool." : + (temp_rand == 6) ? "sulphur." + : "fire and brimstone!"); } break; @@ -453,21 +445,17 @@ void random_uselessness(unsigned char ru, unsigned char sc_read_2) break; case 8: - strcpy(info, "You hear "); - temp_rand = random2(9); - - strcat(info, (temp_rand == 0) ? "snatches of song" : - (temp_rand == 1) ? "a voice call someone else's name" : - (temp_rand == 2) ? "a very strange noise" : - (temp_rand == 3) ? "roaring flame" : - (temp_rand == 4) ? "a very strange noise indeed" : - (temp_rand == 5) ? "the chiming of a distant gong" : - (temp_rand == 6) ? "the bellowing of a yak" : - (temp_rand == 7) ? "a crunching sound" - : "the tinkle of an enormous bell"); - strcat(info, "."); - mpr(info); + mprf("You hear %s.", + (temp_rand == 0) ? "snatches of song" : + (temp_rand == 1) ? "a voice call someone else's name" : + (temp_rand == 2) ? "a very strange noise" : + (temp_rand == 3) ? "roaring flame" : + (temp_rand == 4) ? "a very strange noise indeed" : + (temp_rand == 5) ? "the chiming of a distant gong" : + (temp_rand == 6) ? "the bellowing of a yak" : + (temp_rand == 7) ? "a crunching sound" + : "the tinkle of an enormous bell"); break; } diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 0fe7bf50ae..4ae9f482c7 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -1485,7 +1485,7 @@ public: unsigned int tut_throw_counter; unsigned int tut_berserk_counter; unsigned int tut_melee_counter; - unsigned tut_last_healed; + unsigned int tut_last_healed; bool tut_just_triggered; unsigned int tutorial_type; diff --git a/crawl-ref/source/food.cc b/crawl-ref/source/food.cc index 4f81eb3ee5..49513143f8 100644 --- a/crawl-ref/source/food.cc +++ b/crawl-ref/source/food.cc @@ -529,23 +529,27 @@ static bool food_change(bool suppress_message) static void describe_food_change(int food_increment) { int magnitude = (food_increment > 0)?food_increment:(-food_increment); + std::string msg; if (magnitude == 0) return; - strcpy(info, (magnitude <= 100) ? "You feel slightly " : - (magnitude <= 350) ? "You feel somewhat " : - (magnitude <= 800) ? "You feel a quite a bit " - : "You feel a lot "); + if ( magnitude <= 100 ) + msg = "You feel slightly "; + else if (magnitude <= 350) + msg = "You feel somewhat "; + else if (magnitude <= 800) + msg = "You feel a quite a bit "; + else + msg = "You feel a lot "; if ((you.hunger_state > HS_SATIATED) ^ (food_increment < 0)) - strcat(info, "more "); + msg += "more "; else - strcat(info, "less "); + msg += "less "; - strcat(info, (you.hunger_state > HS_SATIATED) ? "full." - : "hungry."); - mpr(info); + msg += ((you.hunger_state > HS_SATIATED) ? "full." : "hungry."); + mpr(msg.c_str()); } // end describe_food_change() void eat_from_inventory(int which_inventory_slot) @@ -976,16 +980,12 @@ static void eating(unsigned char item_class, int item_type) mpr("That snozzcumber tasted truly putrid!"); break; case FOOD_ORANGE: - strcpy(info, "That orange was delicious!"); - if (one_chance_in(8)) - strcat(info, " Even the peel tasted good!"); - mpr(info); + mprf("That orange was delicious!%s", + one_chance_in(8) ? " Even the peel tasted good!" : ""); break; case FOOD_BANANA: - strcpy(info, "That banana was delicious!"); - if (one_chance_in(8)) - strcat(info, " Even the peel tasted good!"); - mpr(info); + mprf("That banana was delicious!%s", + one_chance_in(8) ? " Even the peel tasted good!" : ""); break; case FOOD_STRAWBERRY: mpr("That strawberry was delicious!"); diff --git a/crawl-ref/source/it_use2.cc b/crawl-ref/source/it_use2.cc index 299138338a..460934c5b5 100644 --- a/crawl-ref/source/it_use2.cc +++ b/crawl-ref/source/it_use2.cc @@ -317,42 +317,30 @@ void unwield_item(char unw, bool showMsgs) if (brand != SPWPN_NORMAL) { - strcpy(info, you.inv[unw].name(DESC_CAP_YOUR).c_str()); + std::string msg = you.inv[unw].name(DESC_CAP_YOUR); switch (brand) { case SPWPN_SWORD_OF_CEREBOV: case SPWPN_FLAMING: if (showMsgs) - { - strcat(info, " stops flaming."); - mpr(info); - } + mprf("%s stops flaming.", msg.c_str()); break; case SPWPN_FREEZING: case SPWPN_HOLY_WRATH: if (showMsgs) - { - strcat(info, " stops glowing."); - mpr(info); - } + mprf("%s stops glowing.", msg.c_str()); break; case SPWPN_ELECTROCUTION: if (showMsgs) - { - strcat(info, " stops crackling."); - mpr(info); - } + mprf("%s stops crackling.", msg.c_str()); break; case SPWPN_VENOM: if (showMsgs) - { - strcat(info, " stops dripping with poison."); - mpr(info); - } + mprf("%s stops dripping with poison.", msg.c_str()); break; case SPWPN_PROTECTION: @@ -399,7 +387,7 @@ void unwield_item(char unw, bool showMsgs) if (player_equip( EQ_STAFF, STAFF_POWER )) { - // XXX: Ugly hack so that thhis currently works (don't want to + // XXX: Ugly hack so that this currently works (don't want to // mess with the fact that currently this function doesn't // actually unwield the item, but we need it out of the player's // hand for this to work. -- bwr diff --git a/crawl-ref/source/it_use3.cc b/crawl-ref/source/it_use3.cc index fcecb7992f..3ced683d07 100644 --- a/crawl-ref/source/it_use3.cc +++ b/crawl-ref/source/it_use3.cc @@ -55,14 +55,13 @@ static bool box_of_beasts(void); static bool disc_of_storms(void); static bool efreet_flask(void); -void special_wielded(void) +void special_wielded() { const int wpn = you.equip[EQ_WEAPON]; const int old_plus = you.inv[wpn].plus; const int old_plus2 = you.inv[wpn].plus2; const char old_colour = you.inv[wpn].colour; - int temp_rand = 0; // for probability determination {dlb} bool makes_noise = (one_chance_in(20) && !silenced(you.x_pos, you.y_pos)); switch (you.special_wield) @@ -70,42 +69,22 @@ void special_wielded(void) case SPWLD_SING: if (makes_noise) { - strcpy(info, "The Singing Sword "); - temp_rand = random2(32); - strcat(info, - (temp_rand == 0) ? "hums a little tune." : - (temp_rand == 1) ? "breaks into glorious song!" : - (temp_rand == 2) ? "sings." : - (temp_rand == 3) ? "sings loudly." : - (temp_rand == 4) ? "chimes melodiously." : - (temp_rand == 5) ? "makes a horrible noise." : - (temp_rand == 6) ? "sings off-key." : - (temp_rand == 7) ? "sings 'tra-la-la'." : - (temp_rand == 8) ? "burbles away merrily." : - (temp_rand == 9) ? "gurgles." : - (temp_rand == 10) ? "suddenly shrieks!" : - (temp_rand == 11) ? "cackles." : - (temp_rand == 12) ? "warbles." : - (temp_rand == 13) ? "chimes harmoniously." : - (temp_rand == 14) ? "makes beautiful music." : - (temp_rand == 15) ? "produces a loud orchestral chord." : - (temp_rand == 16) ? "whines plaintively." : - (temp_rand == 17) ? "tinkles." : - (temp_rand == 18) ? "rings like a bell." : - (temp_rand == 19) ? "wails mournfully." : - (temp_rand == 20) ? "practices its scales." : - (temp_rand == 21) ? "lilts tunefully." : - (temp_rand == 22) ? "hums tunelessly." : - (temp_rand == 23) ? "sighs." : - (temp_rand == 24) ? "makes a deep moaning sound." : - (temp_rand == 25) ? "makes a popping sound." : - (temp_rand == 26) ? "sings a sudden staccato note." : - (temp_rand == 27) ? "says 'Hi! I'm the Singing Sword!'." : - (temp_rand == 28) ? "whispers something." : - (temp_rand == 29) ? "speaks gibberish." : - (temp_rand == 30) ? "raves incoherently." - : "yells in some weird language."); - mpr(info, MSGCH_SOUND); + const char* suffixes[32] = { + "hums a little tune.", "breaks into glorious song!", + "sings.", "sings loudly.", "chimes melodiously.", + "makes a horrible noise.", "sings off-key.", + "sings 'tra-la-la'.", "burbles away merrily.", + "gurgles.", "suddenly shrieks!", "cackles.", "warbles.", + "chimes harmoniously.", "makes beautiful music.", + "produces a loud orchestral chord.", "whines plaintively.", + "tinkles.", "rings like a bell.", "wails mournfully.", + "practices its scales.", "lilts tunefully.", + "hums tunelessly.", "sighs.", "makes a deep moaning sound.", + "makes a popping sound.", "sings a sudden staccato note.", + "says 'Hi! I'm the Singing Sword!'.", "whispers something.", + "speaks gibberish.", "raves incoherently", + "yells in some weird language." }; + mprf("The Singing Sword %s", suffixes[random2(32)]); } break; diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index c47b373102..7c268236a8 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -2834,25 +2834,19 @@ static bool affix_weapon_enchantment() if (wpn == -1 || !you.duration[ DUR_WEAPON_BRAND ]) return (false); - strcpy(info, you.inv[wpn].name(DESC_CAP_YOUR).c_str()); + std::string itname = you.inv[wpn].name(DESC_CAP_YOUR); switch (get_weapon_brand( you.inv[wpn] )) { case SPWPN_VORPAL: if (get_vorpal_type( you.inv[wpn] ) != DVORP_CRUSHING) - { - strcat(info, "'s sharpness seems more permanent."); - } + mprf("%s's sharpness seems more permanent.", itname.c_str()); else - { - strcat(info, "'s heaviness feels very stable."); - } - mpr(info); + mprf("%s's heaviness feels very stable.", itname.c_str()); break; case SPWPN_FLAMING: - strcat(info," is engulfed in an explosion of flames!"); - mpr(info); + mprf("%s is engulfed in an explosion of flames!", itname.c_str()); beam.type = SYM_BURST; beam.damage = dice_def( 3, 10 ); @@ -2871,27 +2865,23 @@ static bool affix_weapon_enchantment() break; case SPWPN_FREEZING: - strcat(info," glows brilliantly blue for a moment."); - mpr(info); + mprf("%s glows brilliantly blue for a moment.", itname.c_str()); cast_refrigeration(60); break; case SPWPN_DRAINING: - strcat(info," thirsts for the lives of mortals!"); - mpr(info); + mprf("%s thirsts for the lives of mortals!", itname.c_str()); drain_exp(); break; case SPWPN_VENOM: - strcat(info, " seems more permanently poisoned."); - mpr(info); + mprf("%s seems more permanently poisoned.", itname.c_str()); cast_toxic_radiance(); break; case SPWPN_PAIN: // Can't fix pain brand (balance)...you just get tormented. - strcat(info, " shrieks out in agony!"); - mpr(info); + mprf("%s shrieks out in agony!", itname.c_str()); torment_monsters(you.x_pos, you.y_pos, 0, TORMENT_GENERIC); success = false; @@ -2905,8 +2895,7 @@ static bool affix_weapon_enchantment() case SPWPN_DISTORTION: // [dshaligram] Attempting to fix a distortion brand gets you a free // distortion effect, and no permabranding. Sorry, them's the breaks. - strcat(info, " twongs alarmingly."); - mpr(info); + mprf("%s twongs alarmingly.", itname.c_str()); // from unwield_item miscast_effect( SPTYP_TRANSLOCATION, 9, 90, 100, diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc index eff23623b0..f742e073da 100644 --- a/crawl-ref/source/misc.cc +++ b/crawl-ref/source/misc.cc @@ -1191,6 +1191,8 @@ static void dart_trap( bool trap_known, int trapped, struct bolt &pbolt, int damage_taken = 0; int trap_hit, your_dodge; + std::string msg; + if (random2(10) < 2 || (trap_known && !one_chance_in(4))) { mprf( "You avoid triggering a%s trap.", pbolt.name.c_str() ); @@ -1200,14 +1202,16 @@ static void dart_trap( bool trap_known, int trapped, struct bolt &pbolt, if (you.equip[EQ_SHIELD] != -1 && one_chance_in(3)) exercise( SK_SHIELDS, 1 ); - snprintf( info, INFO_SIZE, "A%s shoots out and ", pbolt.name.c_str() ); + msg = "A"; + msg += pbolt.name; + msg += " shoots out and "; if (random2( 20 + 5 * you.shield_blocks * you.shield_blocks ) < player_shield_class()) { you.shield_blocks++; - strcat( info, "hits your shield." ); - mpr(info); + msg += "hits your shield."; + mpr(msg.c_str()); goto out_of_trap; } @@ -1219,8 +1223,8 @@ static void dart_trap( bool trap_known, int trapped, struct bolt &pbolt, if (trap_hit >= your_dodge && you.duration[DUR_DEFLECT_MISSILES] == 0) { - strcat( info, "hits you!" ); - mpr(info); + msg += "hits you!"; + mpr(msg.c_str()); if (poison && random2(100) < 50 - (3 * player_AC()) / 2 && !player_res_poison()) @@ -1236,8 +1240,8 @@ static void dart_trap( bool trap_known, int trapped, struct bolt &pbolt, } else { - strcat( info, "misses you." ); - mpr(info); + msg += "misses you."; + mpr(msg.c_str()); } if (player_light_armour(true) && coinflip()) diff --git a/crawl-ref/source/monplace.cc b/crawl-ref/source/monplace.cc index 23e366ac49..bb22598a7c 100644 --- a/crawl-ref/source/monplace.cc +++ b/crawl-ref/source/monplace.cc @@ -392,26 +392,31 @@ bool place_monster(int &id, int mon_type, int power, char behaviour, // message to player from stairwell/gate appearance? if (see_grid(px, py) && proximity == PROX_NEAR_STAIRS) { - info[0] = 0; + std::string msg; if (player_monster_visible( &menv[id] )) - strcpy(info, ptr_monam( &menv[id], DESC_CAP_A )); + msg = ptr_monam( &menv[id], DESC_CAP_A ); else if (shoved) - strcpy(info, "Something"); + msg = "Something"; if (shoved) { - strcat(info, " shoves you out of the "); - strcat(info, (stair_gfx == '>' || stair_gfx == '<') ? "stairwell!" - : "gateway!"); - mpr(info); + msg += " shoves you out of the "; + if (stair_gfx == '>' || stair_gfx == '<') + msg += "stairwell!"; + else + msg += "gateway!"; + mpr(msg.c_str()); } - else if (info[0] != '\0') + else if (!msg.empty()) { - strcat(info, (stair_gfx == '>') ? " comes up the stairs." : - (stair_gfx == '<') ? " comes down the stairs." - : " comes through the gate."); - mpr(info); + if ( stair_gfx == '>' ) + msg += " comes up the stairs."; + else if (stair_gfx == '<') + msg += " comes down the stairs."; + else + msg += " comes through the gate."; + mpr(msg.c_str()); } // special case: must update the view for monsters created in player LOS diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 478f2958cc..b8d6467fda 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -518,11 +518,9 @@ void monster_die(monsters *monster, char killer, int i, bool silent) if (death_message) { - snprintf(info, INFO_SIZE, - "You %s %s!", - wounded_damaged(monster->type) ? "destroy" : "kill", - ptr_monam(monster, DESC_NOCAP_THE)); - mpr(info, MSGCH_MONSTER_DAMAGE, MDAM_DEAD); + mprf(MSGCH_MONSTER_DAMAGE, MDAM_DEAD, "You %s %s!", + wounded_damaged(monster->type) ? "destroy" : "kill", + ptr_monam(monster, DESC_NOCAP_THE)); } if (!created_friendly) @@ -3881,11 +3879,8 @@ static bool handle_pickup(monsters *monster) if (!silenced(you.x_pos, you.y_pos) && !silenced(monster->x, monster->y)) { - strcpy(info, "You hear a"); - if (!monsterNearby) - strcat(info, " distant"); - strcat(info, " slurping noise."); - mpr(info, MSGCH_SOUND); + mprf(MSGCH_SOUND, "You hear a%s slurping noise.", + monsterNearby ? "" : " distant"); } if (mons_class_flag( monster->type, M_SPLITS )) @@ -4076,11 +4071,8 @@ static void jelly_grows(monsters *monster) if (!silenced(you.x_pos, you.y_pos) && !silenced(monster->x, monster->y)) { - strcpy(info, "You hear a"); - if (!mons_near(monster)) - strcat(info, " distant"); - strcat(info, " slurping noise."); - mpr(info, MSGCH_SOUND); + mprf(MSGCH_SOUND, "You hear a%s slurping noise.", + mons_near(monster) ? "" : " distant"); } monster->hit_points += 5; diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc index f4b073af07..ede520732b 100644 --- a/crawl-ref/source/mstuff2.cc +++ b/crawl-ref/source/mstuff2.cc @@ -177,16 +177,14 @@ void mons_trap(struct monsters *monster) { if (monsterNearby) { - strcpy(info, "A huge blade swings out"); - + std::string msg = "A huge blade swings out"; if (player_monster_visible( monster )) { - strcat(info, " and slices into "); - strcat(info, ptr_monam( monster, DESC_NOCAP_THE )); + msg += " and slices into "; + msg += ptr_monam( monster, DESC_NOCAP_THE ); } - - strcat(info, "!"); - mpr(info); + msg += "!"; + mpr(msg.c_str()); } damage_taken = 10 + random2avg(29, 2); @@ -1227,26 +1225,24 @@ bool mons_throw(struct monsters *monster, struct bolt &pbolt, int hand_used) // now, if a monster is, for some reason, throwing something really // stupid, it will have baseHit of 0 and damage of 0. Ah well. - strcpy(info, ptr_monam( monster, DESC_CAP_THE) ); - - strcat(info, (launched) ? " shoots " : " throws "); + std::string msg = ptr_monam( monster, DESC_CAP_THE); + msg += ((launched) ? " shoots " : " throws "); - if (pbolt.name.length()) + if (!pbolt.name.empty()) { - strcat(info, "a "); - strcat(info, pbolt.name.c_str()); + msg += "a "; + msg += pbolt.name; } else { // build shoot message - strcat(info, item.name(DESC_NOCAP_A).c_str()); + msg += item.name(DESC_NOCAP_A); // build beam name pbolt.name = item.name(DESC_PLAIN); } - - strcat(info, "."); - mpr(info); + msg += "."; + mpr(msg.c_str()); // [dshaligram] When changing bolt names here, you must edit // hiscores.cc (scorefile_entry::terse_missile_cause()) to match. @@ -1306,6 +1302,8 @@ void spore_goes_pop(struct monsters *monster) beam.thrower = KILL_MON; // someone else's explosion beam.aux_source.clear(); + const char* msg = ""; + if (type == MONS_GIANT_SPORE) { beam.flavour = BEAM_SPORE; @@ -1313,7 +1311,7 @@ void spore_goes_pop(struct monsters *monster) beam.colour = LIGHTGREY; beam.damage = dice_def( 3, 15 ); beam.ex_size = 2; - strcpy( info, "The giant spore explodes!" ); + msg = "The giant spore explodes!"; } else { @@ -1322,13 +1320,13 @@ void spore_goes_pop(struct monsters *monster) beam.colour = LIGHTCYAN; beam.damage = dice_def( 3, 20 ); beam.ex_size = coinflip() ? 3 : 2; - strcpy( info, "The ball lightning explodes!" ); + msg = "The ball lightning explodes!"; } if (mons_near(monster)) { viewwindow(1, false); - mpr(info); + mpr(msg); } explosion(beam); @@ -1980,8 +1978,9 @@ bool silver_statue_effects(monsters *mons) char wc[30]; weird_colours( random2(256), wc ); - snprintf(info, INFO_SIZE, "'s eyes glow %s.", wc); - simple_monster_message(mons, info, MSGCH_WARN); + std::string msg = "'s eyes glow "; + msg += wc; + simple_monster_message(mons, msg.c_str(), MSGCH_WARN); create_monster( summon_any_demon((coinflip() ? DEMON_COMMON : DEMON_LESSER)), diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc index 6a7d6e0bcf..185a76dbeb 100644 --- a/crawl-ref/source/newgame.cc +++ b/crawl-ref/source/newgame.cc @@ -748,11 +748,9 @@ bool new_game(void) strncpy(spec_buff, species_name(you.species, you.experience_level), 80); - snprintf( info, INFO_SIZE, "You are a%s %s %s." EOL, - (is_vowel( spec_buff[0] )) ? "n" : "", spec_buff, - you.class_name ); - - cprintf( info ); + cprintf( "You are a%s %s %s." EOL, + (is_vowel( spec_buff[0] )) ? "n" : "", spec_buff, + you.class_name ); enter_player_name(false); diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index 048f262a93..7a96a7921f 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -3709,6 +3709,7 @@ void modify_stat(unsigned char which_stat, char amount, bool suppress_msg) char *ptr_stat_max = NULL; char *ptr_redraw = NULL; + // sanity - is non-zero amount? if (amount == 0) return; @@ -3717,8 +3718,7 @@ void modify_stat(unsigned char which_stat, char amount, bool suppress_msg) if (amount < 0) interrupt_activity( AI_STAT_CHANGE ); - if (!suppress_msg) - strcpy(info, "You feel "); + std::string msg = "You feel "; if (which_stat == STAT_RANDOM) which_stat = random2(NUM_STATS); @@ -3729,29 +3729,26 @@ void modify_stat(unsigned char which_stat, char amount, bool suppress_msg) ptr_stat = &you.strength; ptr_stat_max = &you.max_strength; ptr_redraw = &you.redraw_strength; - if (!suppress_msg) - strcat(info, (amount > 0) ? "stronger." : "weaker."); + msg += ((amount > 0) ? "stronger." : "weaker."); break; case STAT_DEXTERITY: ptr_stat = &you.dex; ptr_stat_max = &you.max_dex; ptr_redraw = &you.redraw_dexterity; - if (!suppress_msg) - strcat(info, (amount > 0) ? "agile." : "clumsy."); + msg += ((amount > 0) ? "agile." : "clumsy."); break; case STAT_INTELLIGENCE: ptr_stat = &you.intel; ptr_stat_max = &you.max_intel; ptr_redraw = &you.redraw_intelligence; - if (!suppress_msg) - strcat(info, (amount > 0) ? "clever." : "stupid."); + msg += ((amount > 0) ? "clever." : "stupid."); break; } if (!suppress_msg) - mpr( info, (amount > 0) ? MSGCH_INTRINSIC_GAIN : MSGCH_WARN ); + mpr( msg.c_str(), (amount > 0) ? MSGCH_INTRINSIC_GAIN : MSGCH_WARN ); *ptr_stat += amount; *ptr_stat_max += amount; diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc index 79159d6682..3235fd749a 100644 --- a/crawl-ref/source/religion.cc +++ b/crawl-ref/source/religion.cc @@ -1890,9 +1890,9 @@ void divine_retribution( int god ) if (!player_under_penance() && you.piety > random2(400)) { - strcpy(info, "Mortal, I have averted the wrath of " - "the Shining One... this time."); - god_speaks(you.religion, info); + god_speaks(you.religion, + "Mortal, I have averted the wrath of " + "the Shining One... this time."); } else { diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc index 7644b93220..c89990d03e 100644 --- a/crawl-ref/source/shopping.cc +++ b/crawl-ref/source/shopping.cc @@ -124,10 +124,12 @@ static void in_a_shop( char shoppy ) ShopInfo &si = stashes.get_shop(the_shop.x, the_shop.y); - snprintf(info, INFO_SIZE, "Welcome to %s!", - shop_name(the_shop.x, the_shop.y) ); - - shop_print(info, 20); + { + std::string welcome_message = "Welcome to "; + welcome_message += shop_name(the_shop.x, the_shop.y); + welcome_message += "!"; + shop_print(welcome_message.c_str(), 20); + } more3(); diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc index 0f082c1319..5387da46f2 100644 --- a/crawl-ref/source/spells2.cc +++ b/crawl-ref/source/spells2.cc @@ -550,19 +550,19 @@ bool brand_weapon(int which_brand, int power) return false; } - strcpy( info, you.inv[wpn].name(DESC_CAP_YOUR).c_str() ); + std::string msg = you.inv[wpn].name(DESC_CAP_YOUR); const int wpn_type = get_vorpal_type(you.inv[wpn]); switch (which_brand) // use SPECIAL_WEAPONS here? { case SPWPN_FLAMING: - strcat(info, " bursts into flame!"); + msg += " bursts into flame!"; duration_affected = 7; break; case SPWPN_FREEZING: - strcat(info, " glows blue."); + msg += " glows blue."; duration_affected = 7; break; @@ -570,12 +570,12 @@ bool brand_weapon(int which_brand, int power) if (wpn_type == DVORP_CRUSHING) return false; - strcat(info, " starts dripping with poison."); + msg += " starts dripping with poison."; duration_affected = 15; break; case SPWPN_DRAINING: - strcat(info, " crackles with unholy energy."); + msg += " crackles with unholy energy."; duration_affected = 12; break; @@ -583,22 +583,22 @@ bool brand_weapon(int which_brand, int power) if (wpn_type != DVORP_SLICING) return false; - strcat(info, " glows silver and looks extremely sharp."); + msg += " glows silver and looks extremely sharp."; duration_affected = 10; break; case SPWPN_DISTORTION: //jmf: added for Warp Weapon - strcat(info, " seems to "); + msg += " seems to "; temp_rand = random2(6); - strcat(info, (temp_rand == 0) ? "twist" : - (temp_rand == 1) ? "bend" : - (temp_rand == 2) ? "vibrate" : - (temp_rand == 3) ? "flex" : - (temp_rand == 4) ? "wobble" - : "twang"); - - strcat( info, coinflip() ? " oddly." : " strangely." ); + msg += ((temp_rand == 0) ? "twist" : + (temp_rand == 1) ? "bend" : + (temp_rand == 2) ? "vibrate" : + (temp_rand == 3) ? "flex" : + (temp_rand == 4) ? "wobble" + : "twang"); + + msg += (coinflip() ? " oddly." : " strangely."); duration_affected = 5; // [dshaligram] Clamping power to 2. @@ -616,7 +616,7 @@ bool brand_weapon(int which_brand, int power) case SPWPN_PAIN: // well, in theory, we could be silenced, but then how are // we casting the brand spell? - strcat(info, " shrieks in agony."); + msg += " shrieks in agony."; noisy( 15, you.x_pos, you.y_pos ); duration_affected = 8; break; @@ -626,14 +626,14 @@ bool brand_weapon(int which_brand, int power) return false; which_brand = SPWPN_VORPAL; - strcat(info, " glows silver and feels heavier."); + msg += " glows silver and feels heavier."; duration_affected = 7; break; } set_item_ego_type( you.inv[wpn], OBJ_WEAPONS, which_brand ); - mpr(info); + mpr(msg.c_str()); you.wield_change = true; int dur_change = duration_affected + roll_dice( 2, power ); @@ -667,8 +667,7 @@ bool restore_stat(unsigned char which_stat, bool suppress_msg) char *ptr_stat_max = 0; // NULL {dlb} char *ptr_redraw = 0; // NULL {dlb} - if (!suppress_msg) - strcpy(info, "You feel your "); + std::string msg = "You feel your "; if (which_stat == STAT_RANDOM) which_stat = random2(NUM_STATS); @@ -676,8 +675,7 @@ bool restore_stat(unsigned char which_stat, bool suppress_msg) switch (which_stat) { case STAT_STRENGTH: - if (!suppress_msg) - strcat(info, "strength"); + msg += "strength"; ptr_stat = &you.strength; ptr_stat_max = &you.max_strength; @@ -685,8 +683,7 @@ bool restore_stat(unsigned char which_stat, bool suppress_msg) break; case STAT_DEXTERITY: - if (!suppress_msg) - strcat(info, "dexterity"); + msg += "dexterity"; ptr_stat = &you.dex; ptr_stat_max = &you.max_dex; @@ -694,8 +691,7 @@ bool restore_stat(unsigned char which_stat, bool suppress_msg) break; case STAT_INTELLIGENCE: - if (!suppress_msg) - strcat(info, "intelligence"); + msg += "intelligence"; ptr_stat = &you.intel; ptr_stat_max = &you.max_intel; @@ -705,11 +701,9 @@ bool restore_stat(unsigned char which_stat, bool suppress_msg) if (*ptr_stat < *ptr_stat_max) { - if (!suppress_msg) - { - strcat(info, " returning."); - mpr(info); - } + msg += " returning."; + if ( !suppress_msg ) + mpr(msg.c_str()); *ptr_stat = *ptr_stat_max; *ptr_redraw = 1; diff --git a/crawl-ref/source/spells4.cc b/crawl-ref/source/spells4.cc index 2c1eaad153..11e4cead85 100644 --- a/crawl-ref/source/spells4.cc +++ b/crawl-ref/source/spells4.cc @@ -1775,28 +1775,28 @@ static int glamour_monsters(int x, int y, int pow, int garbage) // why no, there's no message as to which effect happened >:^) if (!one_chance_in(4)) { - strcpy(info, ptr_monam( &(menv[mon]), DESC_CAP_THE)); + std::string msg = ptr_monam( &(menv[mon]), DESC_CAP_THE); switch (random2(4)) { case 0: - strcat(info, " looks dazed."); + msg += " looks dazed."; break; case 1: - strcat(info, " blinks several times."); + msg += " blinks several times."; break; case 2: - strcat(info, " rubs its eye"); + msg += " rubs its eye"; if (menv[mon].type != MONS_CYCLOPS) - strcat(info, "s"); - strcat(info, "."); + msg += "s"; + msg += "."; break; case 4: - strcat(info, " tilts its head."); + msg += " tilts its head."; break; } - mpr(info); + mpr(msg.c_str()); } return (1); diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc index 33c201f6f2..5db4bbaf06 100644 --- a/crawl-ref/source/spl-book.cc +++ b/crawl-ref/source/spl-book.cc @@ -1381,7 +1381,6 @@ int staff_spell( int staff ) "Evoke which spell from the rod ([a-%c] spell [?*] list)? ", 'a' + num_spells - 1 ); - mpr( info, MSGCH_PROMPT ); spell = get_ch(); if (spell == '?' || spell == '*') diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc index 3d874cd044..4a90487dff 100644 --- a/crawl-ref/source/stash.cc +++ b/crawl-ref/source/stash.cc @@ -31,6 +31,7 @@ #include #include #include +#include #include #define ST_MAJOR_VER ((unsigned char) 4) @@ -1461,26 +1462,13 @@ void StashTracker::display_search_results( for (unsigned i = 0; i < results.size(); ++i, ++hotkey) { stash_search_result &res = results[i]; - char matchtitle[ITEMNAME_SIZE]; - std::string place = short_place_name(res.pos.id); + std::ostringstream matchtitle; + matchtitle << "[" << short_place_name(res.pos.id) << "] " + << res.match; if (res.matches > 1 && res.count > 1) - { - snprintf(matchtitle, sizeof matchtitle, - "[%s] %s (%d)", - place.c_str(), - res.match.c_str(), - res.matches); - } - else - { - snprintf(matchtitle, sizeof matchtitle, - "[%s] %s", - place.c_str(), - res.match.c_str()); - } - std::string mename = matchtitle; - - MenuEntry *me = new MenuEntry(mename, MEL_ITEM, 1, hotkey); + matchtitle << " (" << res.matches << ")"; + + MenuEntry *me = new MenuEntry(matchtitle.str(), MEL_ITEM, 1, hotkey); me->data = &res; if (res.shop && !res.shop->is_visited()) me->colour = CYAN; diff --git a/crawl-ref/source/tutorial.cc b/crawl-ref/source/tutorial.cc index a616a53de1..b338cbf380 100644 --- a/crawl-ref/source/tutorial.cc +++ b/crawl-ref/source/tutorial.cc @@ -2,8 +2,10 @@ * Created for Crawl Reference by JPEG on $Date: 2007-01-11$ */ -#include "tutorial.h" #include +#include + +#include "tutorial.h" #include "command.h" #include "files.h" @@ -20,6 +22,10 @@ #include "stuff.h" #include "view.h" +static species_type get_tutorial_species(unsigned int type); +static job_type get_tutorial_job(unsigned int type); + + //#define TUTORIAL_DEBUG #define TUTORIAL_VERSION 110 @@ -65,94 +71,88 @@ void init_tutorial_options() // tutorial selection screen and choice bool pick_tutorial() { - char keyn; - bool printed = false; + clrscr(); + + gotoxy(1,1); + formatted_string::parse_string( + "You must be new here indeed!" + EOL EOL + "You can be:" + EOL EOL).display(); -tut_query: - if (!printed) - { - clrscr(); - - textcolor( WHITE ); - cprintf("You must be new here indeed!"); - - cprintf(EOL EOL); - textcolor( CYAN ); - cprintf("You can be:"); - cprintf(EOL EOL); - - textcolor( LIGHTGREY ); - - for (int i = 0; i < TUT_TYPES_NUM; i++) - print_tutorial_menu(i); - - textcolor( BROWN ); - cprintf(EOL "SPACE - Back to class selection; Bksp - Back to race selection; X - Quit" - EOL "* - Random tutorial" - EOL); - printed = true; - } - keyn = c_getch(); + textcolor( LIGHTGREY ); + + for (int i = 0; i < TUT_TYPES_NUM; i++) + print_tutorial_menu(i); - if (keyn == '*') - keyn = 'a' + random2(TUT_TYPES_NUM); + formatted_string::parse_string( + EOL + "SPACE - Back to class selection; " + "Bksp - Back to race selection; X - Quit" + EOL "* - Random tutorial" + "" EOL).display(); - // choose character for tutorial game and set starting values - if (keyn >= 'a' && keyn <= 'a' + TUT_TYPES_NUM - 1) + while (1) { - Options.tutorial_type = keyn - 'a'; - you.species = get_tutorial_species(Options.tutorial_type); - you.char_class = get_tutorial_job(Options.tutorial_type); - - // activate all triggers - for (int i = 0; i < TUT_EVENTS_NUM; i++) - Options.tutorial_events[i] = 1; - Options.tutorial_left = TUT_EVENTS_NUM; - - // store whether explore, stash search or travelling was used - Options.tut_explored = 1; - Options.tut_stashes = 1; - Options.tut_travel = 1; - - // used to compare which fighting means was used most often - Options.tut_spell_counter = 0; - Options.tut_throw_counter = 0; - Options.tut_berserk_counter = 0; - Options.tut_melee_counter = 0; - - // for occasional healing reminders - Options.tut_last_healed = 0; + char keyn = c_getch(); - Options.random_pick = true; // random choice of starting spellbook - Options.weapon = WPN_HAND_AXE; // easiest choice for fighters - return true; - } + if (keyn == '*') + keyn = 'a' + random2(TUT_TYPES_NUM); + + // choose character for tutorial game and set starting values + if (keyn >= 'a' && keyn <= 'a' + TUT_TYPES_NUM - 1) + { + Options.tutorial_type = keyn - 'a'; + you.species = get_tutorial_species(Options.tutorial_type); + you.char_class = get_tutorial_job(Options.tutorial_type); + + // activate all triggers + Options.tutorial_events.init(true); + Options.tutorial_left = TUT_EVENTS_NUM; + + // store whether explore, stash search or travelling was used + Options.tut_explored = true; + Options.tut_stashes = true; + Options.tut_travel = true; + + // used to compare which fighting means was used most often + Options.tut_spell_counter = 0; + Options.tut_throw_counter = 0; + Options.tut_berserk_counter = 0; + Options.tut_melee_counter = 0; + + // for occasional healing reminders + Options.tut_last_healed = 0; + + Options.random_pick = true; // random choice of starting spellbook + Options.weapon = WPN_HAND_AXE; // easiest choice for fighters + return true; + } - if (keyn == CK_BKSP || keyn == ' ') - { - // in this case, undo previous choices -// set_startup_options(); - you.species = 0; you.char_class = JOB_UNKNOWN; - Options.race = 0; Options.cls = 0; - } + if (keyn == CK_BKSP || keyn == ' ') + { + // in this case, undo previous choices + // set_startup_options(); + you.species = 0; + you.char_class = JOB_UNKNOWN; + Options.race = 0; + Options.cls = 0; + } - switch (keyn) - { - case CK_BKSP: - choose_race(); - break; - case ' ': - choose_class(); - break; - case 'X': - cprintf(EOL "Goodbye!"); - end(0); - break; - default: - printed = false; - goto tut_query; + switch (keyn) + { + case CK_BKSP: + choose_race(); + return false; + case ' ': + choose_class(); + return false; + case 'X': + cprintf(EOL "Goodbye!"); + end(0); + return false; // as if + } } - return false; } @@ -181,7 +181,7 @@ void print_tutorial_menu(unsigned int type) get_class_name(get_tutorial_job(type)), desc); } -unsigned int get_tutorial_species(unsigned int type) +static species_type get_tutorial_species(unsigned int type) { switch(type) { @@ -197,7 +197,7 @@ unsigned int get_tutorial_species(unsigned int type) } // TO DO: check whether job and species are compatible... -unsigned int get_tutorial_job(unsigned int type) +static job_type get_tutorial_job(unsigned int type) { switch(type) { @@ -215,43 +215,42 @@ unsigned int get_tutorial_job(unsigned int type) // the tutorial welcome screen static formatted_string tut_starting_info(unsigned int width) { - std::string result; // the entire page - std::string text; // one paragraph - - result += "Welcome to Dungeon Crawl!" EOL EOL; + std::ostringstream istr; - text += "Your object is to lead a "; - snprintf(info, INFO_SIZE, "%s %s ", species_name(get_tutorial_species(Options.tutorial_type), 1), - get_class_name(get_tutorial_job(Options.tutorial_type))); - text += info; - text += "safely through the depths of the dungeon, retrieving the fabled orb of Zot and " - "returning it to the surface. In the beginning, however, let discovery be your " - "main goal. Try to delve as deeply as possible but beware; death lurks around " - "every corner." EOL EOL; - linebreak_string2(text, width); - result += formatted_string::parse_string(text); - - result += "For the moment, just remember the following keys and their functions:" EOL; - result += " ? - shows the items and the commands" EOL; - result += " S - saves the game, to be resumed later (but note that death is permanent)" EOL; - result += " x - examine something in your vicinity" EOL EOL; - - text = "This tutorial will help you play Crawl without reading any documentation. " - "If you feel intrigued, there is more information available in these files " - "(all of which can also be read in-game):" EOL; - linebreak_string2(text, width); - result += formatted_string::parse_string(text); - - result += " readme.txt - A very short guide to Crawl." EOL; - result += " manual.txt - This contains all details on races, magic, skills, etc." EOL; - result += " crawl_options.txt - Crawl's interface is highly configurable. This document " EOL; - result += " explains all the options." EOL; - result += EOL; - result += "Press Space to proceed to the basics (the screen division and movement)." EOL; - result += "Press Esc to fast forward to the game start."; - - - return formatted_string::parse_block(result); + istr << "Welcome to Dungeon Crawl!" EOL EOL + << "Your object is to lead a " + << species_name(get_tutorial_species(Options.tutorial_type), 1) + << " " << get_class_name(get_tutorial_job(Options.tutorial_type)) + << + " safely through the depths of the dungeon, retrieving the " + "fabled orb of Zot and returning it to the surface. " + " In the beginning, however, let discovery be your " + "main goal. Try to delve as deeply as possible but beware; " + "death lurks around every corner." EOL EOL + "For the moment, just remember the following keys " + "and their functions:" EOL + " ? - shows the items and the commands" EOL + " S - saves the game, to be resumed later " + "(but note that death is permanent)" EOL + " x - examine something in your vicinity" EOL EOL + "This tutorial will help you play Crawl without reading any " + "documentation. If you feel intrigued, there is more information " + "available in these files (all of which can also be read in-game):" + EOL + " readme.txt - " + "A very short guide to Crawl." EOL + " manual.txt - " + "This contains all details on races, magic, skills, etc." EOL + " crawl_options.txt - " + "Crawl's interface is highly configurable. This document " EOL + " explains all the options." EOL + EOL + "Press Space to proceed to the basics " + "(the screen division and movement)." EOL + "Press Esc to fast forward to the game start."; + std::string broken = istr.str(); + linebreak_string2(broken, width); + return formatted_string::parse_block(broken); } #ifdef TUTORIAL_DEBUG @@ -399,12 +398,12 @@ static formatted_string tutorial_map_intro() { std::string result; - result = "" - "What you see here is the typical Crawl screen. The upper left map " - "shows your hero as the @ in the center. The parts " - "of the map you remember but cannot currently see, will be greyed " - "out." - "" EOL; + result = "" + "What you see here is the typical Crawl screen. The upper left map " + "shows your hero as the @ in the center. The parts " + "of the map you remember but cannot currently see, will be greyed " + "out." + "" EOL; result += " --more-- Press Escape to skip the basics"; linebreak_string2(result,get_tutorial_cols()); @@ -413,37 +412,37 @@ static formatted_string tutorial_map_intro() static formatted_string tutorial_stats_intro() { - std::string result; - result += ""; - - result += "To the right, important properties of \n"; - result += "the character are displayed. The most \n"; - result += "basic one is your health, measured as \n"; - snprintf(info, INFO_SIZE, "HP: %d/%d. ", - you.hp, you.hp_max); - result += info; - if (Options.tutorial_type==TUT_MAGIC_CHAR) - result += " "; - result += "These are your current out \n"; - result += "of maximum health points. When health \n"; - result += "drops to zero, you die. \n"; - snprintf(info, INFO_SIZE, "Magic: %d/%d", you.magic_points, you.max_magic_points); - result += info; - result += " is your energy for casting \n"; - result += "spells, although more mundane actions \n"; - result += "often draw from Magic, too. \n"; - result += "Further down, Strength, Dexterity and \n"; - result += "Intelligence are shown and provide an \n"; - result += "all-around account of the character's \n"; - result += "attributes. \n"; - - result += ""; - result += " \n"; - result += " --more-- Press Escape to skip the basics\n"; - result += " \n"; - result += " \n"; + std::ostringstream istr; - return formatted_string::parse_block(result, false); + // Note: must fill up everything to override the map + istr << "" + "To the right, important properties of \n" + "the character are displayed. The most \n" + "basic one is your health, measured as \n" + "HP: " << you.hp << "/" << you.hp_max << ". "; + + if (Options.tutorial_type==TUT_MAGIC_CHAR) + istr << " "; + + istr << + "These are your current out \n" + "of maximum health points. When health \n" + "drops to zero, you die. \n" + "Magic: " + << you.magic_points << "/" << you.max_magic_points << + " is your energy for casting \n" + "spells, although more mundane actions \n" + "often draw from Magic, too. \n" + "Further down, Strength, Dexterity and \n" + "Intelligence are shown and provide an \n" + "all-around account of the character's \n" + "attributes. \n" + "" + " \n" + " --more-- Press Escape to skip the basics\n" + " \n" + " \n"; + return formatted_string::parse_block(istr.str(), false); } static formatted_string tutorial_message_intro() @@ -883,7 +882,7 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) if (Options.tut_just_triggered) return; - std::string text; + std::ostringstream text; unsigned short ch, colour; const int ex = x - you.x_pos + 9; const int ey = y - you.y_pos + 9; @@ -891,119 +890,123 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) switch(seen_what) { - case TUT_SEEN_POTION: - text = "You have picked up your first potion ('!'). Use " - "q to drink (quaff) it."; + case TUT_SEEN_POTION: + text << "You have picked up your first potion ('!'). " + "Use q to drink (quaff) it."; break; case TUT_SEEN_SCROLL: - text = "You have picked up your first scroll ('?'). Type " - "r to read it."; + text << "You have picked up your first scroll ('?'). " + "Type r to read it."; break; case TUT_SEEN_WAND: - text = "You have picked up your first wand ('/'). Type " - "z to zap it."; + text << "You have picked up your first wand ('/'). " + "Type z to zap it."; break; case TUT_SEEN_SPBOOK: get_item_symbol(DNGN_ITEM_BOOK, &ch, &colour); - text = "You have picked up a spellbook ('"; - text += ch; - text += "'). You can read it by typing r, " - "memorise spells via M and cast a memorised spell " - "with Z."; - + text << "You have picked up a spellbook ('" + << static_cast(ch) + << + "'). You can read it by typing r, " + "memorise spells via M and cast a memorised " + "spell with Z."; + if (!you.skills[SK_SPELLCASTING]) { - text += "\nHowever, first you will have to get accustomed to " + text << "\nHowever, first you will have to get accustomed to " "spellcasting by reading lots of scrolls."; } break; case TUT_SEEN_WEAPON: - text = "This is the first weapon ('(') you've picked up. " - "Use w to wield it, but be aware that this weapon " - "might train a different skill from your current one. You can " - "view the weapon's properties with v."; + text << + "This is the first weapon ('(') you've picked up. " + "Use w to wield it, but be aware that this weapon " + "might train a different skill from your current one. You can " + "view the weapon's properties with v."; + if (Options.tutorial_type == TUT_BERSERK_CHAR) { - text += "\nAs you're already trained in Axes you should stick with " - "these. Checking other axes can be worthwhile."; + text << + "\nAs you're already trained in Axes you should stick " + "with these. Checking other axes can be worthwhile."; } break; case TUT_SEEN_MISSILES: - text = "This is the first stack of missiles (')') you've " + text << "This is the first stack of missiles (')') you've " "picked up. Darts can be thrown by hand, but other missile types " "like arrows and needles require a launcher and training in " "using it to be really effective. v gives more " "information about both missiles and launcher."; if (Options.tutorial_type == TUT_RANGER_CHAR) { - text += "\nAs you're already trained in Bows you should stick with " + text << "\nAs you're already trained in Bows you should stick with " "arrows and collect more of them in the dungeon."; } else if (Options.tutorial_type == TUT_MAGIC_CHAR) { - text += "\nHowever, as a spellslinger you don't really need another " + text << "\nHowever, as a spellslinger you don't really need another " "type of ranged attack, unless there's another effect in " "addition to damage."; } else { - text += "\nFor now you might be best off with sticking to darts or " + text << "\nFor now you might be best off with sticking to darts or " "stones for ranged attacks."; } break; case TUT_SEEN_ARMOUR: - text = "This is the first piece of armour ('[') you've " + text << "This is the first piece of armour ('[') you've " "picked up. Use W to wear it and T to " "take it off again. You can view its properties with " "v."; if (you.species == SP_CENTAUR || you.species == SP_MINOTAUR) { - snprintf( info, INFO_SIZE, "\nNote that as a %s, you will be unable to wear %s.", - species_name(you.species, 1), you.species == SP_CENTAUR ? "boots" : "helmets"); - text += info; + text << "\nNote that as a " << species_name(you.species, 1) + << "you will be unable to wear " + << (you.species == SP_CENTAUR ? "boots" : "helmets"); } break; case TUT_SEEN_RANDART: - text = "Weapons and armour that have unusual descriptions like this " + text << "Weapons and armour that have unusual descriptions like this " "are much more likely to be of higher enchantment or have " "special properties, good or bad. The rarer the description, " "the greater the potential value of an item."; break; case TUT_SEEN_FOOD: - text = "You have picked up some food ('%'). You can eat it " + text << "You have picked up some food ('%'). You can eat it " "by typing e."; break; case TUT_SEEN_CARRION: - text = "You have picked up a corpse ('%'). When a corpse " + text << "You have picked up a corpse ('%'). When a corpse " "is lying on the ground, you can Dissect with a " "sharp implement. Once hungry you can eat the " "resulting chunks (though they may not be healthy)."; if (Options.tutorial_type == TUT_BERSERK_CHAR) { - text += " During prayer you can offer corpses to "; - text += god_name(you.religion); - text += " by dissecting them, as well."; + text << " During prayer you can offer corpses to " + << god_name(you.religion) + << " by dissecting them, as well."; } break; case TUT_SEEN_JEWELLERY: - text = "You have picked up a a piece of jewellery, either a ring " + text << "You have picked up a a piece of jewellery, either a ring " "('=') or an amulet ('\"'). Type " "P to put it on and R to remove it. You " "can view it with v although often magic is " "necessary to reveal its true nature."; break; case TUT_SEEN_MISC: - text = "This is a curious object indeed. You can play around with it " + text << "This is a curious object indeed. You can play around with it " "to find out what it does by wielding and " "Evoking it."; break; case TUT_SEEN_STAFF: get_item_symbol(DNGN_ITEM_STAVE, &ch, &colour); - text = "You have picked up a magic staff or a rod, both of which are " - "represented by '"; - text += ch; - text += "'. Both must be ielded to be of use. " + text << "You have picked up a magic staff or a rod, both of which are " + "represented by '" + << static_cast(ch) + << "'. Both must be ielded to be of use. " "Magicians use staves to increase their power in certain spell " "schools. By contrast, a rod allows the casting of certain " "spells even without magic knowledge simply by " @@ -1018,17 +1021,15 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) colour = env.show_col[ex][ey]; get_item_symbol( object, &ch, &colour ); - text = "The "; - text += colour_to_tag(colour); - text += ch; - text += " are some downstairs. You can enter the next (deeper) " + text << "The " << colour_to_tag(colour) << static_cast(ch) + << " are some downstairs. You can enter the next (deeper) " "level by following them down (>). To get back to " "this level again, press << while standing on the " "upstairs."; break; case TUT_SEEN_TRAPS: - text = "Oops... you just triggered a trap. An unwary adventurer will " + text << "Oops... you just triggered a trap. An unwary adventurer will " "occasionally stumble into one of these nasty constructions " "depicted by ^. They can do physical damage (with " "darts or needles, for example) or have other, more magical " @@ -1039,56 +1040,53 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) colour = env.show_col[ex][ey]; get_item_symbol( object, &ch, &colour ); - text = "The "; - text += colour_to_tag(colour); - text += ch; - text += " is an altar. You can get information about it by pressing " + text << "The " << colour_to_tag(colour) << static_cast(ch) + << " is an altar. You can get information about it by pressing " "p while standing on the square. Before taking up " "the responding faith you'll be asked for confirmation."; break; case TUT_SEEN_SHOP: - text = "The "; - text += get_screen_glyph(x,y); - text += " is a shop. You can enter it by typing <<."; + text << "The " << static_cast(get_screen_glyph(x,y)) + << " is a shop. You can enter it by typing " + "<<."; break; case TUT_SEEN_DOOR: if (you.num_turns < 1) return; - text = "The "; - text += get_screen_glyph(x,y); - text += " is a closed door. You can open it by walking into it. " + text << "The " << static_cast(get_screen_glyph(x,y)) + << " is a closed door. You can open it by walking into it. " "Sometimes it is useful to close a door. Do so by pressing " "c, followed by the direction."; break; case TUT_KILLED_MONSTER: - text = "Congratulations, your character just gained some experience by " + text << "Congratulations, your character just gained some experience by " "killing this monster! Every action will use up some of it to " "train certain skills. For example, fighting monsters "; if (Options.tutorial_type == TUT_BERSERK_CHAR) - text += "in melee battle will raise your Axes and Fighting skills."; + text << "in melee battle will raise your Axes and Fighting skills."; else if (Options.tutorial_type == TUT_RANGER_CHAR) - text += "using bow and arrows will raise your Bows and Ranged Combat " + text << "using bow and arrows will raise your Bows and Ranged Combat " "skills."; else // if (Options.tutorial_type == TUT_MAGIC_CHAR) - text += "with offensive magic will raise your Conjurations and " + text << "with offensive magic will raise your Conjurations and " "Spellcasting skills."; if (you.religion != GOD_NO_GOD) { - text += "\nTo dedicate your kills to "; - text += god_name(you.religion); - text += " pray before battle. Not all gods will be " + text << "\nTo dedicate your kills to " + << god_name(you.religion) + << " pray before battle. Not all gods will be " "pleased by doing this."; } break; case TUT_NEW_LEVEL: - text = "Well done! Reaching a new experience level is always a nice " + text << "Well done! Reaching a new experience level is always a nice " "event: you get more health and magic points, and occasionally " "increases to your attributes (strength, dexterity, intelligence)."; if (Options.tutorial_type == TUT_MAGIC_CHAR) { - text += "\nAlso, new experience levels let you learn more spells " + text << "\nAlso, new experience levels let you learn more spells " "(the Spellcasting skill also does this). For now, " "you should try to memorise the second spell of your " "starting book with Mcb, which can then be " @@ -1096,18 +1094,18 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) } break; case TUT_SKILL_RAISE: - text = "One of your skills just got raised. Type m to take " + text << "One of your skills just got raised. Type m to take " "a look at your skills screen."; break; case TUT_YOU_ENCHANTED: - text = "Enchantments of all types can befall you temporarily. " + text << "Enchantments of all types can befall you temporarily. " "Brief descriptions of these appear at the lower end of the stats " "area. Press @ for more details. A list of all " "possible enchantments is in the manual."; break; case TUT_YOU_SICK: learned_something_new(TUT_YOU_ENCHANTED); - text = "Corpses can be spoiled or inedible, making you sick. " + text << "Corpses can be spoiled or inedible, making you sick. " "Also, some monsters' flesh is less palatable than others'. " "While sick, your hitpoints won't regenerate and sometimes " "an attribute may decrease. It wears off with time (wait with " @@ -1115,32 +1113,32 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) break; case TUT_YOU_POISON: learned_something_new(TUT_YOU_ENCHANTED); - text = "Poison will slowly reduce your hp. It wears off with time " + text << "Poison will slowly reduce your hp. It wears off with time " "(wait with 5) or you could quaff a potion of " "healing."; break; case TUT_YOU_CURSED: - text = "Curses are comparatively harmless, but they do mean that you " + text << "Curses are comparatively harmless, but they do mean that you " "cannot remove cursed equipment and will have to suffer the " "(possibly) bad effects until you find and read a scroll of " "remove curse. Weapons can also be uncursed using enchanting " "scrolls."; break; case TUT_YOU_HUNGRY: - text = "There are two ways to overcome hunger: food you started " + text << "There are two ways to overcome hunger: food you started " "with or found, and selfmade chunks from corpses. To get the " "latter, all you need to do is D a corpse with a " "sharp implement. Your starting weapon will do nicely. " "Try to dine on chunks in order to save permanent food."; break; case TUT_YOU_STARVING: - text = "You are now suffering from terrible hunger. You'll need to " + text << "You are now suffering from terrible hunger. You'll need to " "eat something quickly, or you'll die. The safest " "way to deal with this is to simply eat something from your " "inventory rather than wait for a monster to leave a corpse."; break; case TUT_MULTI_PICKUP: - text = "There's a more comfortable way to pick up several items at the " + text << "There's a more comfortable way to pick up several items at the " "same time. If you press , or g twice " "you can choose items from a menu. This takes less keystrokes " "but has no influence on the number of turns needed. Multi-pickup " @@ -1148,32 +1146,32 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) break; case TUT_HEAVY_LOAD: if (you.burden_state != BS_UNENCUMBERED) - text = "It is not usually a good idea to run around encumbered; it " + text << "It is not usually a good idea to run around encumbered; it " "slows you down and increases your hunger."; else - text = "Sadly, your inventory is limited to 52 items, and it appears " + text << "Sadly, your inventory is limited to 52 items, and it appears " "your knapsack is full."; - text += " However, this is easy enough to rectify: simply drop " + text << " However, this is easy enough to rectify: simply drop " "some of the stuff you don't need or that's too heavy to lug " "around permanently."; break; case TUT_ROTTEN_FOOD: - text = "One or more of the chunks or corpses you carry has started to " + text << "One or more of the chunks or corpses you carry has started to " "rot. Few races can digest these safely, so you might just as " "well drop them now."; if (you.religion == GOD_TROG || you.religion == GOD_MAKHLEB || you.religion == GOD_OKAWARU) { - text += "\nIf it is a rotting corpse you carry now might be a good " + text << "\nIf it is a rotting corpse you carry now might be a good " "time to drop and Dissect it during " - "prayer (p) as an offer to "; - text += god_name(you.religion); - text += "."; + "prayer (p) as an offer to " + << god_name(you.religion) + << "."; } break; case TUT_MAKE_CHUNKS: - text = "How lucky! That monster left a corpse which you can now " + text << "How lucky! That monster left a corpse which you can now " "Dissect. One or more chunks will appear that you can " "then eat. Beware that some chunks may be, " "sometimes or always, hazardous. Only experience can help " @@ -1183,19 +1181,19 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) (you.religion == GOD_OKAWARU || you.religion == GOD_MAKHLEB || you.religion == GOD_TROG || you.religion == GOD_ELYVILON)) { - text += "\nNote that dissection under prayer offers the corpse to "; - text += god_name(you.religion); - text += " - check your god's attitude about this with ^."; + text << "\nNote that dissection under prayer offers the corpse to " + << god_name(you.religion) + << " - check your god's attitude about this with ^."; } break; case TUT_SHIFT_RUN: - text = "Walking around takes less keystrokes if you press " + text << "Walking around takes less keystrokes if you press " "Shift-direction or / direction. " "That will let you run until a monster comes into sight or " "your character sees something interesting."; break; case TUT_MAP_VIEW: - text = "As you explore a level, orientation can become difficult. " + text << "As you explore a level, orientation can become difficult. " "Press X to bring up the level map. Typing " "? shows the list of level map commands. " "Most importantly, moving the cursor to a spot and pressing " @@ -1203,19 +1201,19 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) "there on its own."; break; case TUT_DONE_EXPLORE: - text = "You have explored the dungeon on this level. The downstairs look " + text << "You have explored the dungeon on this level. The downstairs look " "like '>'. Proceed there and press > to " "go down. "; if (Options.tutorial_events[TUT_SEEN_STAIRS]) { - text += "In rare cases, you may have found no downstairs at all. " + text << "In rare cases, you may have found no downstairs at all. " "Try searching for secret doors in suspicious looking spots; " "use s, . or 5 to do so."; } else { - text += "Each level of Crawl has three white up and three white down " + text << "Each level of Crawl has three white up and three white down " "stairs. Unexplored parts can often be accessed via another " "level or through secret doors. To find the latter, search " "the adjacent squares of walls for one turn with s " @@ -1224,38 +1222,38 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) } break; case TUT_NEED_HEALING: - text = "If you're low on hitpoints or magic and there's no urgent need " + text << "If you're low on hitpoints or magic and there's no urgent need " "to move, you can rest for a bit. Press 5 or " "shift-numpad-5 to do so."; break; case TUT_NEED_POISON_HEALING: - text = "Your poisoning could easily kill you, so now would be a good " + text << "Your poisoning could easily kill you, so now would be a good " "time to quaff a potion of heal wounds or, better " "yet, a potion of healing. If you have seen neither of these so " "far, try unknown ones in your inventory. Good luck!"; break; case TUT_POSTBERSERK: - text = "Berserking is extremely exhausting! It burns a lot of nutrition, " + text << "Berserking is extremely exhausting! It burns a lot of nutrition, " "and afterwards you are slowed down and occasionally even pass " "out."; break; case TUT_RUN_AWAY: - text = "Whenever you've got only a few hitpoints left and you're in " + text << "Whenever you've got only a few hitpoints left and you're in " "danger of dying, check your options carefully. Often, retreat or " "use of some item might be a viable alternative to fighting on."; if (you.species == SP_CENTAUR) - text += " As a four-legged centaur you are particularly quick - " + text << " As a four-legged centaur you are particularly quick - " "running is an option! "; if (Options.tutorial_type == TUT_BERSERK_CHAR && !you.berserker) { - text += "\nAlso, with "; - text += god_name(you.religion); - text += "'s support you can use your Berserk ability (a) " + text << "\nAlso, with " + << god_name(you.religion) + << "'s support you can use your Berserk ability (a) " "to temporarily gain more hitpoints and greater strength. "; } break; case TUT_YOU_MUTATED: - text = "Mutations can be obtained from several sources, among them " + text << "Mutations can be obtained from several sources, among them " "potions, spell miscasts, and overuse of strong enchantments " "like Invisibility. The only reliable way to get rid of mutations " "is with potions of cure mutation. There are about as many " @@ -1263,16 +1261,16 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) "levels. Check your mutations with A."; break; case TUT_NEW_ABILITY: - text = "You just gained a new ability. Press a to take a " + text << "You just gained a new ability. Press a to take a " "look at your abilities or to use one of them."; break; case TUT_WIELD_WEAPON: - text = "You might want to wield a more suitable implement " + text << "You might want to wield a more suitable implement " "when attacking monsters."; if (Options.tutorial_type == TUT_RANGER_CHAR && you.inv[ you.equip[EQ_WEAPON] ].sub_type == WPN_BOW) { - text += "You can easily switch between weapons in slots a and " + text << "You can easily switch between weapons in slots a and " "b by pressing '."; } break; @@ -1280,11 +1278,14 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) case TUT_SEEN_FIRST_OBJECT: break; case TUT_EVENTS_NUM: - text += "You've found something new (but I don't know what)!"; + text << "You've found something new (but I don't know what)!"; } - if ( !text.empty() ) - print_formatted_paragraph(text, get_tutorial_cols(), MSGCH_TUTORIAL); + if ( !text.str().empty() ) + { + std::string s = text.str(); + print_formatted_paragraph(s, get_tutorial_cols(), MSGCH_TUTORIAL); + } Options.tut_just_triggered = true; Options.tutorial_events[seen_what] = 0; diff --git a/crawl-ref/source/tutorial.h b/crawl-ref/source/tutorial.h index f78eef61e7..78cac89612 100644 --- a/crawl-ref/source/tutorial.h +++ b/crawl-ref/source/tutorial.h @@ -23,8 +23,6 @@ void init_tutorial_options(void); bool pick_tutorial(void); void print_tutorial_menu(unsigned int type); -unsigned int get_tutorial_species(unsigned int type); -unsigned int get_tutorial_job(unsigned int type); formatted_string tut_starting_info2(); void tut_starting_screen(); diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index 5207d3efed..74d871bf9c 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -588,62 +588,61 @@ void monster_grid(bool do_updates) } else { - strcpy(info, "You hear "); + std::string msg = "You hear "; switch (mons_shouts(monster->type)) { case S_SILENT: default: - strcat(info, "buggy behaviour!"); + msg += "buggy behaviour!"; break; case S_SHOUT: - strcat(info, "a shout!"); + msg += "a shout!"; break; case S_BARK: - strcat(info, "a bark!"); + msg += "a bark!"; break; case S_SHOUT2: - strcat(info, "two shouts!"); + msg += "two shouts!"; noise_level = 12; break; case S_ROAR: - strcat(info, "a roar!"); + msg += "a roar!"; noise_level = 12; break; case S_SCREAM: - strcat(info, "a hideous shriek!"); + msg += "a hideous shriek!"; break; case S_BELLOW: - strcat(info, "a bellow!"); + msg += "a bellow!"; break; case S_SCREECH: - strcat(info, "a screech!"); + msg += "a screech!"; break; case S_BUZZ: - strcat(info, "an angry buzzing noise."); + msg += "an angry buzzing noise."; break; case S_MOAN: - strcat(info, "a chilling moan."); + msg += "a chilling moan."; break; case S_WHINE: - strcat(info, - "an irritating high-pitched whine."); + msg += "an irritating high-pitched whine."; break; case S_CROAK: if (coinflip()) - strcat(info, "a loud, deep croak!"); + msg += "a loud, deep croak!"; else - strcat(info, "a croak."); + msg += "a croak."; break; case S_GROWL: - strcat(info, "an angry growl!"); + msg += "an angry growl!"; break; case S_HISS: - strcat(info, "an angry hiss!"); + msg += "an angry hiss!"; noise_level = 4; // not very loud -- bwr break; } - mpr(info, MSGCH_SOUND); + mpr(msg.c_str(), MSGCH_SOUND); } } -- cgit v1.2.3-54-g00ecf