OSDN Git Service

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