OSDN Git Service

Merge pull request #3005 from sikabane-works/release/3.0.0Alpha73
[hengbandforosx/hengbandosx.git] / src / cmd-io / cmd-lore.cpp
1 #include "cmd-io/cmd-lore.h"
2 #include "core/asking-player.h"
3 #include "core/stuff-handler.h"
4 #include "game-option/cheat-options.h"
5 #include "game-option/game-play-options.h"
6 #include "io/input-key-acceptor.h"
7 #include "lore/lore-util.h"
8 #include "monster-race/monster-race.h"
9 #include "monster-race/race-flags1.h"
10 #include "monster-race/race-flags7.h"
11 #include "system/monster-race-info.h"
12 #include "system/player-type-definition.h"
13 #include "term/gameterm.h"
14 #include "term/screen-processor.h"
15 #include "term/term-color-types.h"
16 #include "term/z-form.h"
17 #include "util/int-char-converter.h"
18 #include "util/sort.h"
19 #include "util/string-processor.h"
20 #include "view/display-lore.h"
21
22 /*!
23  * @brief モンスターの思い出を見るコマンドのメインルーチン
24  * Identify a character, allow recall of monsters
25  * @param player_ptr プレイヤーへの参照ポインタ
26  * @details
27  * <pre>
28  * Several "special" responses recall "multiple" monsters:
29  *   ^A (all monsters)
30  *   ^U (all unique monsters)
31  *   ^N (all non-unique monsters)
32  *
33  * The responses may be sorted in several ways, see below.
34  *
35  * Note that the player ghosts are ignored.
36  * </pre>
37  */
38 void do_cmd_query_symbol(PlayerType *player_ptr)
39 {
40     char sym, query;
41
42     bool all = false;
43     bool uniq = false;
44     bool norm = false;
45     bool ride = false;
46     char temp[MAX_MONSTER_NAME] = "";
47
48     bool recall = false;
49
50     uint16_t why = 0;
51
52     if (!get_com(_("知りたい文字を入力して下さい(記号 or ^A全,^Uユ,^N非ユ,^R乗馬,^M名前): ",
53                      "Enter character to be identified(^A:All,^U:Uniqs,^N:Non uniqs,^M:Name): "),
54             &sym, false)) {
55         return;
56     }
57
58     int ident_i;
59     for (ident_i = 0; ident_info[ident_i]; ++ident_i) {
60         if (sym == ident_info[ident_i][0]) {
61             break;
62         }
63     }
64
65     std::string buf;
66     if (sym == KTRL('A')) {
67         all = true;
68         buf = _("全モンスターのリスト", "Full monster list.");
69     } else if (sym == KTRL('U')) {
70         all = uniq = true;
71         buf = _("ユニーク・モンスターのリスト", "Unique monster list.");
72     } else if (sym == KTRL('N')) {
73         all = norm = true;
74         buf = _("ユニーク外モンスターのリスト", "Non-unique monster list.");
75     } else if (sym == KTRL('R')) {
76         all = ride = true;
77         buf = _("乗馬可能モンスターのリスト", "Ridable monster list.");
78     } else if (sym == KTRL('M')) {
79         all = true;
80         if (!get_string(_("名前(英語の場合小文字で可)", "Enter name:"), temp, 70)) {
81             temp[0] = 0;
82             return;
83         }
84         buf = format(_("名前:%sにマッチ", "Monsters' names with \"%s\""), temp);
85     } else if (ident_info[ident_i]) {
86         buf = format("%c - %s.", sym, ident_info[ident_i] + 2);
87     } else {
88         buf = format("%c - %s", sym, _("無効な文字", "Unknown Symbol"));
89     }
90
91     prt(buf, 0, 0);
92     std::vector<MonsterRaceId> who;
93     for (const auto &[r_idx, r_ref] : monraces_info) {
94         if (!cheat_know && !r_ref.r_sights) {
95             continue;
96         }
97
98         if (norm && r_ref.kind_flags.has(MonsterKindType::UNIQUE)) {
99             continue;
100         }
101
102         if (uniq && r_ref.kind_flags.has_not(MonsterKindType::UNIQUE)) {
103             continue;
104         }
105
106         if (ride && !(r_ref.flags7 & (RF7_RIDING))) {
107             continue;
108         }
109
110         if (temp[0]) {
111             TERM_LEN xx;
112             char temp2[MAX_MONSTER_NAME];
113
114             for (xx = 0; temp[xx] && xx < MAX_MONSTER_NAME; xx++) {
115 #ifdef JP
116                 if (iskanji(temp[xx])) {
117                     xx++;
118                     continue;
119                 }
120 #endif
121                 if (isupper(temp[xx])) {
122                     temp[xx] = (char)tolower(temp[xx]);
123                 }
124             }
125
126 #ifdef JP
127             strcpy(temp2, r_ref.E_name.data());
128 #else
129             strcpy(temp2, r_ref.name.data());
130 #endif
131             for (xx = 0; temp2[xx] && xx < MAX_MONSTER_NAME; xx++) {
132                 if (isupper(temp2[xx])) {
133                     temp2[xx] = (char)tolower(temp2[xx]);
134                 }
135             }
136
137 #ifdef JP
138             if (angband_strstr(temp2, temp) || angband_strstr(r_ref.name.data(), temp))
139 #else
140             if (angband_strstr(temp2, temp))
141 #endif
142                 who.push_back(r_ref.idx);
143         }
144
145         else if (all || (r_ref.d_char == sym)) {
146             who.push_back(r_ref.idx);
147         }
148     }
149
150     if (who.empty()) {
151         return;
152     }
153
154     put_str(_("思い出を見ますか? (k:殺害順/y/n): ", "Recall details? (k/y/n): "), 0, _(36, 40));
155     query = inkey();
156     prt(buf, 0, 0);
157     why = 2;
158     ang_sort(player_ptr, who.data(), &why, who.size(), ang_sort_comp_hook, ang_sort_swap_hook);
159     if (query == 'k') {
160         why = 4;
161         query = 'y';
162     }
163
164     if (query != 'y') {
165         return;
166     }
167
168     if (why == 4) {
169         ang_sort(player_ptr, who.data(), &why, who.size(), ang_sort_comp_hook, ang_sort_swap_hook);
170     }
171
172     auto i = who.size() - 1;
173     while (true) {
174         auto r_idx = who[i];
175         monster_race_track(player_ptr, r_idx);
176         handle_stuff(player_ptr);
177         while (true) {
178             if (recall) {
179                 screen_save();
180                 screen_roff(player_ptr, who[i], MONSTER_LORE_NORMAL);
181             }
182
183             roff_top(r_idx);
184             term_addstr(-1, TERM_WHITE, _(" ['r'思い出, ESC]", " [(r)ecall, ESC]"));
185             query = inkey();
186             if (recall) {
187                 screen_load();
188             }
189
190             if (query != 'r') {
191                 break;
192             }
193             recall = !recall;
194         }
195
196         if (query == ESCAPE) {
197             break;
198         }
199
200         if (query == '-') {
201             if (++i == who.size()) {
202                 i = 0;
203                 if (!expand_list) {
204                     break;
205                 }
206             }
207         } else {
208             if (i-- == 0) {
209                 i = who.size() - 1;
210                 if (!expand_list) {
211                     break;
212                 }
213             }
214         }
215     }
216
217     prt(buf, 0, 0);
218 }