OSDN Git Service

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