00001
00002
00003
00004
00005
00006
00007
00008 #ifndef DESCRIBE_H
00009 #define DESCRIBE_H
00010
00011 #include <string>
00012 #include <sstream>
00013 #include "externs.h"
00014 #include "enum.h"
00015 #include "mon-info.h"
00016
00017
00018
00019 enum item_description_type
00020 {
00021 IDESC_WANDS = 0,
00022 IDESC_POTIONS,
00023 IDESC_SCROLLS,
00024 IDESC_RINGS,
00025 IDESC_SCROLLS_II,
00026 IDESC_STAVES,
00027 NUM_IDESC
00028 };
00029
00030 enum book_mem_or_forget
00031 {
00032 BOOK_MEM,
00033 BOOK_FORGET,
00034 BOOK_NEITHER
00035 };
00036
00037 struct describe_info
00038 {
00039 std::ostringstream body;
00040 std::string title;
00041 std::string prefix;
00042 std::string suffix;
00043 std::string footer;
00044 std::string quote;
00045 };
00046
00047 void append_spells(std::string &desc, const item_def &item);
00048
00049 bool is_dumpable_artefact(const item_def &item, bool verbose);
00050
00051 std::string get_item_description(const item_def &item, bool verbose,
00052 bool dump = false, bool noquote = false);
00053
00054 std::string god_title(god_type which_god, species_type which_species);
00055 void describe_god(god_type which_god, bool give_title);
00056
00057 void describe_feature_wide(const coord_def& pos);
00058 void get_feature_desc(const coord_def &gc, describe_info &inf);
00059
00060 void set_feature_desc_long(const std::string &raw_name,
00061 const std::string &desc);
00062
00063 void set_feature_quote(const std::string &raw_name,
00064 const std::string "e);
00065
00066 bool describe_item(item_def &item, bool allow_inscribe = false,
00067 bool shopping = false);
00068 void get_item_desc(const item_def &item, describe_info &inf,
00069 bool terse = false);
00070 void inscribe_item(item_def &item, bool msgwin);
00071
00072 void append_weapon_stats(std::string &description, const item_def &item);
00073 void append_armour_stats(std::string &description, const item_def &item);
00074 void append_missile_info(std::string &description);
00075
00076 void describe_monsters(const monster_info &mi, bool force_seen = false,
00077 const std::string &footer = "",
00078 bool wait_until_key_pressed = true);
00079
00080 void get_monster_db_desc(const monster_info &mi, describe_info &inf,
00081 bool &has_stat_desc, bool force_seen = false);
00082
00083 void get_spell_desc(const spell_type spell, describe_info &inf);
00084 void describe_spell(spell_type spelled, const item_def* item = NULL);
00085
00086 std::string short_ghost_description(const monster *mon, bool abbrev = false);
00087 std::string get_ghost_description(const monster_info &mi, bool concise = false);
00088
00089 std::string get_skill_description(skill_type skill, bool need_title = false);
00090
00091 void describe_skill(skill_type skill);
00092
00093 #ifdef USE_TILE
00094 std::string get_command_description(const command_type cmd,
00095 bool terse);
00096 #endif
00097
00098 void print_description(const std::string &desc);
00099 void print_description(const describe_info &inf);
00100
00101 template<class T> void process_description(T &proc, const describe_info &inf);
00102
00103 void trim_randart_inscrip(item_def& item);
00104 std::string artefact_auto_inscription(const item_def& item);
00105 void add_autoinscription(item_def &item, std::string ainscrip);
00106 void add_autoinscription(item_def &item);
00107 void add_inscription(item_def &item, std::string inscrip);
00108
00109 const char *trap_name(trap_type trap);
00110 int str_to_trap(const std::string &s);
00111
00112 int count_desc_lines(const std::string _desc, const int width);
00113
00114 class alt_desc_proc
00115 {
00116 public:
00117 alt_desc_proc(int _w, int _h) { w = _w; h = _h; }
00118
00119 int width() { return w; }
00120 int height() { return h; }
00121
00122 void nextline();
00123 void print(const std::string &str);
00124 static int count_newlines(const std::string &str);
00125
00126
00127 static void trim(std::string &str);
00128
00129 static bool chop(std::string &str);
00130
00131 void get_string(std::string &str);
00132
00133 protected:
00134 int w;
00135 int h;
00136 std::ostringstream ostr;
00137 };
00138
00139
00140
00141
00142
00143 template<class T>
00144 inline void process_description(T &proc, const describe_info &inf)
00145 {
00146 const unsigned int line_width = proc.width();
00147 const int height = proc.height();
00148
00149 std::string desc;
00150
00151
00152
00153 int num_lines = count_desc_lines(inf.title, line_width) + 1;
00154
00155 int body_lines = count_desc_lines(inf.body.str(), line_width);
00156 const int suffix_lines = count_desc_lines(inf.suffix, line_width);
00157 const int prefix_lines = count_desc_lines(inf.prefix, line_width);
00158 const int footer_lines = count_desc_lines(inf.footer, line_width)
00159 + (inf.footer.empty() ? 0 : 1);
00160 const int quote_lines = count_desc_lines(inf.quote, line_width);
00161
00162
00163 if (inf.title.empty())
00164 {
00165 desc = inf.body.str();
00166
00167 num_lines = body_lines + 1;
00168 }
00169 else if (body_lines + num_lines + 2 <= height)
00170 {
00171 desc = inf.title + "\n\n";
00172 desc += inf.body.str();
00173
00174 num_lines += body_lines + 2;
00175 }
00176 else
00177 desc = inf.title + "\n";
00178
00179
00180 if (num_lines + suffix_lines + footer_lines <= height)
00181 {
00182 desc = desc + inf.suffix;
00183 num_lines += suffix_lines;
00184 }
00185
00186
00187 if (num_lines + prefix_lines + footer_lines <= height)
00188 {
00189 desc = inf.prefix + desc;
00190 num_lines += prefix_lines;
00191 }
00192
00193
00194 if (num_lines + footer_lines + quote_lines + 1 <= height)
00195 {
00196 if (!desc.empty())
00197 {
00198 desc += "\n";
00199 num_lines++;
00200 }
00201 desc = desc + inf.quote;
00202 num_lines += quote_lines;
00203 }
00204
00205 if (!inf.footer.empty() && num_lines + footer_lines <= height)
00206 {
00207 const int bottom_line = std::min(std::max(24, num_lines + 2),
00208 height - footer_lines + 1);
00209 const int newlines = bottom_line - num_lines;
00210
00211 if (newlines >= 0)
00212 {
00213 desc.append(newlines, '\n');
00214 desc = desc + inf.footer;
00215 }
00216 }
00217
00218 std::string::size_type nextLine = std::string::npos;
00219 unsigned int currentPos = 0;
00220
00221 while (currentPos < desc.length())
00222 {
00223 if (currentPos != 0)
00224 proc.nextline();
00225
00226
00227 nextLine = desc.find('\n', currentPos);
00228
00229 if (nextLine >= currentPos && nextLine < currentPos + line_width)
00230 {
00231 proc.print(desc.substr(currentPos, nextLine-currentPos));
00232 currentPos = nextLine + 1;
00233 continue;
00234 }
00235
00236
00237
00238 nextLine = desc.find('\n', currentPos);
00239 if (nextLine >= currentPos && nextLine < currentPos + line_width)
00240 {
00241 proc.print(desc.substr(currentPos, nextLine-currentPos));
00242 currentPos = nextLine + 1;
00243 continue;
00244 }
00245
00246
00247 if (currentPos + line_width >= desc.length())
00248 {
00249 proc.print(desc.substr(currentPos));
00250 return;
00251 }
00252
00253
00254
00255 nextLine = desc.rfind(' ', currentPos + line_width);
00256
00257 if (nextLine > 0)
00258 {
00259 proc.print(desc.substr(currentPos, nextLine - currentPos));
00260 currentPos = nextLine + 1;
00261 continue;
00262 }
00263
00264
00265 nextLine = currentPos + line_width;
00266
00267 nextLine = std::min(inf.body.str().length(), nextLine);
00268
00269 proc.print(desc.substr(currentPos, nextLine - currentPos));
00270 currentPos = nextLine;
00271 }
00272 }
00273
00274
00275
00276
00277 #endif