OSDN Git Service

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