OSDN Git Service

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