OSDN Git Service

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