OSDN Git Service

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