OSDN Git Service

[Refactor] #40413 Separated int-char-converter.h
[hengband/hengband.git] / src / market / building-monster.c
1 #include "market/building-monster.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 "io/input-key-acceptor.h"
7 #include "monster-race/race-flags1.h"
8 #include "lore/lore-store.h"
9 #include "term/gameterm.h"
10 #include "term/screen-processor.h"
11 #include "term/term-color-types.h"
12 #include "util/int-char-converter.h"
13 #include "view/display-main-window.h"
14 #include "view/display-lore.h"
15
16 /*!
17  * @brief 施設でモンスターの情報を知るメインルーチン / research_mon -KMW-
18  * @param player_ptr プレーヤーへの参照ポインタ
19  * @return 常にTRUEを返す。
20  * @todo 返り値が意味不明なので直した方が良いかもしれない。
21  */
22 bool research_mon(player_type *player_ptr)
23 {
24     char buf[128];
25     bool notpicked;
26     bool recall = FALSE;
27     u16b why = 0;
28     MONSTER_IDX *who;
29
30     bool all = FALSE;
31     bool uniq = FALSE;
32     bool norm = FALSE;
33     char temp[80] = "";
34
35     static int old_sym = '\0';
36     static IDX old_i = 0;
37     screen_save();
38
39     char sym;
40     if (!get_com(
41             _("モンスターの文字を入力して下さい(記号 or ^A全,^Uユ,^N非ユ,^M名前):", "Enter character to be identified(^A:All,^U:Uniqs,^N:Non uniqs,^M:Name): "),
42             &sym, FALSE))
43
44     {
45         screen_load();
46         return FALSE;
47     }
48
49     IDX i;
50     for (i = 0; ident_info[i]; ++i) {
51         if (sym == ident_info[i][0])
52             break;
53     }
54
55     /* XTRA HACK WHATSEARCH */
56     if (sym == KTRL('A')) {
57         all = TRUE;
58         strcpy(buf, _("全モンスターのリスト", "Full monster list."));
59     } else if (sym == KTRL('U')) {
60         all = uniq = TRUE;
61         strcpy(buf, _("ユニーク・モンスターのリスト", "Unique monster list."));
62     } else if (sym == KTRL('N')) {
63         all = norm = TRUE;
64         strcpy(buf, _("ユニーク外モンスターのリスト", "Non-unique monster list."));
65     } else if (sym == KTRL('M')) {
66         all = TRUE;
67         if (!get_string(_("名前(英語の場合小文字で可)", "Enter name:"), temp, 70)) {
68             temp[0] = 0;
69             screen_load();
70
71             return FALSE;
72         }
73
74         sprintf(buf, _("名前:%sにマッチ", "Monsters with a name \"%s\""), temp);
75     } else if (ident_info[i]) {
76         sprintf(buf, "%c - %s.", sym, ident_info[i] + 2);
77     } else {
78         sprintf(buf, "%c - %s", sym, _("無効な文字", "Unknown Symbol"));
79     }
80
81     /* Display the result */
82     prt(buf, 16, 10);
83
84     /* Allocate the "who" array */
85     C_MAKE(who, max_r_idx, MONRACE_IDX);
86
87     /* Collect matching monsters */
88     int n = 0;
89     for (i = 1; i < max_r_idx; i++) {
90         monster_race *r_ptr = &r_info[i];
91
92         /* Empty monster */
93         if (!r_ptr->name)
94             continue;
95
96         /* XTRA HACK WHATSEARCH */
97         /* Require non-unique monsters if needed */
98         if (norm && (r_ptr->flags1 & (RF1_UNIQUE)))
99             continue;
100
101         /* Require unique monsters if needed */
102         if (uniq && !(r_ptr->flags1 & (RF1_UNIQUE)))
103             continue;
104
105         /* 名前検索 */
106         if (temp[0]) {
107             for (int xx = 0; temp[xx] && xx < 80; xx++) {
108 #ifdef JP
109                 if (iskanji(temp[xx])) {
110                     xx++;
111                     continue;
112                 }
113 #endif
114                 if (isupper(temp[xx]))
115                     temp[xx] = (char)tolower(temp[xx]);
116             }
117
118             char temp2[80];
119 #ifdef JP
120             strcpy(temp2, r_name + r_ptr->E_name);
121 #else
122             strcpy(temp2, r_name + r_ptr->name);
123 #endif
124             for (int xx = 0; temp2[xx] && xx < 80; xx++) {
125                 if (isupper(temp2[xx]))
126                     temp2[xx] = (char)tolower(temp2[xx]);
127             }
128
129 #ifdef JP
130             if (angband_strstr(temp2, temp) || angband_strstr(r_name + r_ptr->name, temp))
131 #else
132             if (angband_strstr(temp2, temp))
133 #endif
134                 who[n++] = i;
135         } else if (all || (r_ptr->d_char == sym)) {
136             who[n++] = i;
137         }
138     }
139
140     if (n == 0) {
141         C_KILL(who, max_r_idx, MONRACE_IDX);
142         screen_load();
143
144         return FALSE;
145     }
146
147     why = 2;
148     char query = 'y';
149
150     if (why) {
151         ang_sort(who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook);
152     }
153
154     if (old_sym == sym && old_i < n)
155         i = old_i;
156     else
157         i = n - 1;
158
159     notpicked = TRUE;
160     MONRACE_IDX r_idx;
161     while (notpicked) {
162         r_idx = who[i];
163         roff_top(r_idx);
164         Term_addstr(-1, TERM_WHITE, _(" ['r'思い出, ' 'で続行, ESC]", " [(r)ecall, ESC, space to continue]"));
165         while (TRUE) {
166             if (recall) {
167                 lore_do_probe(player_ptr, r_idx);
168                 monster_race_track(player_ptr, r_idx);
169                 handle_stuff(player_ptr);
170                 screen_roff(player_ptr, r_idx, 0x01);
171                 notpicked = FALSE;
172                 old_sym = sym;
173                 old_i = i;
174             }
175
176             query = inkey();
177             if (query != 'r')
178                 break;
179
180             recall = !recall;
181         }
182
183         if (query == ESCAPE)
184             break;
185
186         if (query == '-') {
187             if (++i == n) {
188                 i = 0;
189                 if (!expand_list)
190                     break;
191             }
192
193             continue;
194         }
195
196         if (i-- == 0) {
197             i = n - 1;
198             if (!expand_list)
199                 break;
200         }
201     }
202
203     C_KILL(who, max_r_idx, MONRACE_IDX);
204     screen_load();
205     return !notpicked;
206 }