OSDN Git Service

Merge pull request #3532 from sikabane-works/release/3.0.0.87-alpha
[hengbandforosx/hengbandosx.git] / src / flavor / object-flavor.cpp
1 /*!
2  *  @brief オブジェクトの記述処理 / Mbject flavor code
3  *  @date 2014/01/03
4  *  @author
5  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
6  *\n
7  * This software may be copied and distributed for educational, research,\n
8  * and not for profit purposes provided that this copyright and statement\n
9  * are included in all such copies.  Other copyrights may also apply.\n
10  */
11
12 #include "flavor/object-flavor.h"
13 #include "combat/shoot.h"
14 #include "flavor/flag-inscriptions-table.h"
15 #include "flavor/flavor-util.h"
16 #include "flavor/object-flavor-types.h"
17 #include "game-option/text-display-options.h"
18 #include "grid/trap.h"
19 #include "inventory/inventory-slot-types.h"
20 #include "io/files-util.h"
21 #include "locale/english.h"
22 #include "locale/japanese.h"
23 #include "mind/mind-sniper.h"
24 #include "mind/mind-weaponsmith.h"
25 #include "monster-race/monster-race.h"
26 #include "monster-race/race-flags1.h"
27 #include "object-enchant/object-ego.h"
28 #include "object-enchant/special-object-flags.h"
29 #include "object-enchant/tr-types.h"
30 #include "object-enchant/trg-types.h"
31 #include "object-hook/hook-quest.h"
32 #include "object/object-flags.h"
33 #include "object/object-info.h"
34 #include "perception/object-perception.h"
35 #include "player-info/class-info.h"
36 #include "player/player-status.h"
37 #include "sv-definition/sv-food-types.h"
38 #include "sv-definition/sv-lite-types.h"
39 #include "system/baseitem-info.h"
40 #include "util/bit-flags-calculator.h"
41 #include "util/string-processor.h"
42 #include <functional>
43 #include <sstream>
44 #include <utility>
45
46 /*!
47  * @brief 各種語彙からランダムな名前を作成する
48  * @return std::string 作成した名前
49  * @details 日本語の場合 aname_j.txt 英語の場合確率に応じて
50  * syllables 配列と elvish.txt を組み合わせる
51  */
52 std::string get_table_name_aux()
53 {
54     std::stringstream ss;
55 #ifdef JP
56     ss << get_random_line("aname_j.txt", 1).value();
57     ss << get_random_line("aname_j.txt", 2).value();
58     return ss.str();
59 #else
60     static const std::vector<std::string_view> syllables = {
61         "a", "ab", "ag", "aks", "ala", "an", "ankh", "app", "arg", "arze", "ash", "aus", "ban", "bar", "bat", "bek",
62         "bie", "bin", "bit", "bjor", "blu", "bot", "bu", "byt", "comp", "con", "cos", "cre", "dalf", "dan", "den", "der", "doe", "dok", "eep", "el", "eng",
63         "er", "ere", "erk", "esh", "evs", "fa", "fid", "flit", "for", "fri", "fu", "gan", "gar", "glen", "gop", "gre", "ha", "he", "hyd", "i", "ing", "ion",
64         "ip", "ish", "it", "ite", "iv", "jo", "kho", "kli", "klis", "la", "lech", "man", "mar", "me", "mi", "mic", "mik", "mon", "mung", "mur", "nag", "nej",
65         "nelg", "nep", "ner", "nes", "nis", "nih", "nin", "o", "od", "ood", "org", "orn", "ox", "oxy", "pay", "pet", "ple", "plu", "po", "pot", "prok", "re",
66         "rea", "rhov", "ri", "ro", "rog", "rok", "rol", "sa", "san", "sat", "see", "sef", "seh", "shu", "ski", "sna", "sne", "snik", "sno", "so", "sol", "sri",
67         "sta", "sun", "ta", "tab", "tem", "ther", "ti", "tox", "trol", "tue", "turs", "u", "ulk", "um", "un", "uni", "ur", "val", "viv", "vly", "vom", "wah",
68         "wed", "werg", "wex", "whon", "wun", "x", "yerg", "yp", "zun", "tri", "blaa", "jah", "bul", "on", "foo", "ju", "xuxu"
69     };
70
71     int testcounter = randint1(3) + 1;
72     if (randint1(3) == 2) {
73         while (testcounter--) {
74             ss << rand_choice(syllables);
75         }
76     } else {
77         testcounter = randint1(2) + 1;
78         while (testcounter--) {
79             ss << get_random_line("elvish.txt", 0).value();
80         }
81     }
82
83     auto name = ss.str();
84     name[0] = toupper(name[0]);
85     return name;
86 #endif
87 }
88
89 /*!
90  * @brief ランダムな名前をアーティファクト銘として整形する。 / Create a name from random parts with quotes.
91  * @return std::string 作成した名前
92  * @details get_table_name_aux()ほぼ完全に実装を依存している。
93  */
94 std::string get_table_name()
95 {
96     return std::string(_("『", "'")).append(get_table_name_aux()).append(_("』", "'"));
97 }
98
99 /*!
100  * @brief ランダムなシンダリン銘を作成する / Make random Sindarin name
101  * @return std::string 作成した名前
102  * @details sname.txtが語幹の辞書となっている。
103  */
104 std::string get_table_sindarin_aux()
105 {
106     std::stringstream ss;
107     ss << get_random_line("sname.txt", 1).value();
108     ss << get_random_line("sname.txt", 2).value();
109     auto name = ss.str();
110     return _(sindarin_to_kana(name), name);
111 }
112
113 /*!
114  * @brief シンダリン銘をアーティファクト用に整形する。 / Make random Sindarin name with quotes
115  * @param out_string 作成した名を保管する参照ポインタ
116  * @return std::string 作成した名前
117  * @details get_table_sindarin_aux()ほぼ完全に実装を依存している。
118  */
119 std::string get_table_sindarin()
120 {
121     return std::string(_("『", "'")).append(get_table_sindarin_aux()).append(_("』", "'"));
122 }
123
124 /*!
125  * @brief nameバッファ内からベースアイテム名を返す / Strip an "object name" into a buffer
126  * @param buf ベースアイテム格納先の参照ポインタ
127  * @param bi_id ベースアイテムID
128  */
129 std::string strip_name(short bi_id)
130 {
131     const auto &baseitem = baseitems_info[bi_id];
132     auto tok = str_split(baseitem.name, ' ');
133     std::stringstream name;
134     for (const auto &s : tok) {
135         if (s == "" || s == "~" || s == "&" || s == "#") {
136             continue;
137         }
138
139         auto offset = 0;
140         auto endpos = s.size();
141         auto is_kanji = false;
142
143         if (s[0] == '~' || s[0] == '#') {
144             offset++;
145         }
146 #ifdef JP
147         if (s.size() > 2) {
148             is_kanji = iskanji(s[endpos - 2]);
149         }
150
151 #endif
152         if (!is_kanji && (s[endpos - 1] == '~' || s[endpos - 1] == '#')) {
153             endpos--;
154         }
155
156         name << s.substr(offset, endpos);
157     }
158
159     name << " ";
160     return name.str();
161 }