From bc1869c1a3334676d5cc99df90f7f9b24426274d Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Tue, 20 Mar 2007 12:12:03 +0000 Subject: Added a funtion for formatted message history, and, while I was at it, moved some overlapping parts of base_mpr and formatted_mpr into separate functions. This makes them more readable and avoids code duplication. I'm uncertain as to whether translating every string in replay_messages into a formatted string (just in case) would be overkill - so for now that only happens for messages of MSGCH_TUTORIAL. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1071 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/tutorial.cc | 140 ++++++++++++++++++++++++++++++++----------- 1 file changed, 105 insertions(+), 35 deletions(-) (limited to 'crawl-ref/source/tutorial.cc') diff --git a/crawl-ref/source/tutorial.cc b/crawl-ref/source/tutorial.cc index 6cbe6f8a47..3c3b04cbc2 100644 --- a/crawl-ref/source/tutorial.cc +++ b/crawl-ref/source/tutorial.cc @@ -22,7 +22,7 @@ //#define TUTORIAL_DEBUG #define TUTORIAL_VERSION 110 -int COLS = get_number_of_cols(); +int COLS = (get_number_of_cols() > 80) ? 80 : get_number_of_cols(); void save_tutorial( FILE* fp ) { @@ -226,7 +226,7 @@ static formatted_string tut_starting_info(unsigned int width) linebreak_string2(text, width); result += formatted_string::parse_string(text); - result += "For the moment, just remember the following two keys and their functions:" EOL; + 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; @@ -257,7 +257,7 @@ static std::string tut_debug_list(int event) case TUT_SEEN_FIRST_OBJECT: return "seen first object"; case TUT_SEEN_POTION: - return "seen first potion"; + return "seen first potion"; case TUT_SEEN_SCROLL: return "seen first scroll"; case TUT_SEEN_WAND: @@ -781,23 +781,84 @@ void taken_new_item(unsigned char item_type) } } +static std::string colour_to_tag(int col, bool closed = false) +{ + std::string tag = "<"; + if (closed) + tag += "/"; + switch(col) + { + case WHITE: + tag += "w"; + break; + case YELLOW: + tag += "yellow"; + break; + case RED: + tag += "red"; + break; + case LIGHTRED: + tag += "lightred"; + break; + case MAGENTA: + tag += "magenta"; + break; + case LIGHTMAGENTA: + tag += "lightmagenta"; + break; + case GREEN: + tag += "green"; + break; + case LIGHTGREEN: + tag += "lightgreen"; + break; + case BLUE: + tag += "blue"; + break; + case LIGHTBLUE: + tag += "lightblue"; + break; + case CYAN: + tag += "cyan"; + break; + case LIGHTCYAN: + tag += "lightcyan"; + break; + case BLACK: + tag += "black"; + break; + case BROWN: + tag += "brown"; + break; + case DARKGREY: + tag += "darkgrey"; + break; + default: + tag += "lightgrey"; + } + tag += ">"; + + return tag; + +} + void tutorial_first_monster(monsters mon) { if (!Options.tutorial_events[TUT_SEEN_MONSTER]) return; + unsigned short ch, col; + get_mons_glyph(&mon, &ch, &col); + std::string text = "That "; - formatted_string st = formatted_string::parse_string(text); - st.formatted_string::textcolor(channel_to_colour(MSGCH_TUTORIAL)); - st.formatted_string::add_glyph(&mon); - text = " is a monster, usually depicted by a letter. Some typical early monsters "; - st += formatted_string::parse_string(text); - formatted_mpr(st, MSGCH_TUTORIAL); - - text = "look like r, g, b or " - "K. You can gain information about it by pressing " - "x, moving the cursor on the monster and then pressing " - "v. To attack it with your wielded weapon, just move into it."; + text += colour_to_tag(col); + text += ch; + text += " is a monster, usually depicted by a letter. Some typical " + "early monsters look like r, g, " + "b or K. You can gain " + "information about it by pressing x, moving the cursor " + "on the monster and then pressing v. To attack it with " + "your wielded weapon, just move into it."; print_formatted_paragraph(text, COLS, MSGCH_TUTORIAL); more(); @@ -836,19 +897,17 @@ void tutorial_first_item(item_def item) if (!Options.tutorial_events[TUT_SEEN_FIRST_OBJECT] || Options.tut_just_triggered) return; + unsigned short ch, col; + get_item_glyph(&item, &ch, &col); + std::string text = "That "; - formatted_string st = formatted_string::parse_string(text); - st.formatted_string::textcolor(channel_to_colour(MSGCH_TUTORIAL)); - st.formatted_string::add_glyph(&item); - text = " is an item. If you move there and press g or " - ", you will pick it up."; - st += formatted_string::parse_string(text); - formatted_mpr(st, MSGCH_TUTORIAL); - - text = "Generally, items are shown by non-letter symbols like " - "%%?!\"=()[. Once it is in your inventory, you can drop " - "it again with d. Several types of objects will usually " - "be picked up automatically."; + text += colour_to_tag(col); + text += ch; + text += " is an item. If you move there and press g or " + ", you will pick it up. Generally, items are shown by " + "non-letter symbols like %%?!\"=()[. Once it is in your " + "inventory, you can drop it again with d. Several types " + "of objects will usually be picked up automatically."; print_formatted_paragraph(text, COLS, MSGCH_TUTORIAL); Options.tutorial_events[TUT_SEEN_FIRST_OBJECT] = 0; @@ -869,6 +928,9 @@ void learned_something_new(unsigned int seen_what, int x, int y) std::string text; unsigned short ch, colour; + const int ex = x - you.x_pos + 9; + const int ey = y - you.y_pos + 9; + int object; switch(seen_what) { @@ -886,9 +948,8 @@ void learned_something_new(unsigned int seen_what, int x, int y) break; case TUT_SEEN_SPBOOK: get_item_symbol(DNGN_ITEM_BOOK, &ch, &colour); - snprintf(info, INFO_SIZE, "%c", ch); text = "You have picked up a spellbook ('"; - text += info; + text += ch; text += "'). You can read it by typing r, " "memorise spells via M and cast a memorised spell " "with Z."; @@ -982,10 +1043,9 @@ void learned_something_new(unsigned int seen_what, int x, int y) break; case TUT_SEEN_STAFF: get_item_symbol(DNGN_ITEM_STAVE, &ch, &colour); - snprintf(info, INFO_SIZE, "%c", ch); text = "You have picked up a magic staff or a rod, both of which are " "represented by '"; - text += info; + text += ch; text += "'. 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 " @@ -997,8 +1057,13 @@ void learned_something_new(unsigned int seen_what, int x, int y) if (you.num_turns < 1) return; + object = env.show[ex][ey]; + colour = env.show_col[ex][ey]; + get_item_symbol( object, &ch, &colour ); + text = "The "; - text += get_screen_glyph(x,y); + text += colour_to_tag(colour); + text += ch; text += " 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 " @@ -1013,8 +1078,13 @@ void learned_something_new(unsigned int seen_what, int x, int y) "effects, like teleportation."; break; case TUT_SEEN_ALTAR: - text = "The "; - text += get_screen_glyph(x,y); + object = env.show[ex][ey]; + 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 " "p while standing on the square. Before taking up " "the responding faith you'll be asked for confirmation."; @@ -1103,7 +1173,7 @@ void learned_something_new(unsigned int seen_what, int x, int y) 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." + "sharp implement. Your starting weapon will do nicely. " "Try to dine on chunks in order to save permanent food."; break; case TUT_YOU_STARVING: @@ -1217,7 +1287,7 @@ void learned_something_new(unsigned int seen_what, int x, int y) "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) { -- cgit v1.2.3-54-g00ecf