OSDN Git Service

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