OSDN Git Service

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