OSDN Git Service

[Refactor] #1951 新定義に合わせて置き換え
[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(PlayerType *player_ptr)
26 {
27     char buf[256];
28     bool notpicked;
29     bool recall = false;
30     uint16_t why = 0;
31
32     bool all = false;
33     bool uniq = false;
34     bool norm = false;
35     char temp[MAX_MONSTER_NAME] = "";
36
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 ident_i;
50     for (ident_i = 0; ident_info[ident_i]; ++ident_i) {
51         if (sym == ident_info[ident_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' names with \"%s\""), temp);
75     } else if (ident_info[ident_i]) {
76         sprintf(buf, "%c - %s.", sym, ident_info[ident_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     std::vector<MONRACE_IDX> who;
86
87     /* Collect matching monsters */
88     for (const auto &r_ref : r_info) {
89         /* Empty monster */
90         if (r_ref.idx == 0 || r_ref.name.empty())
91             continue;
92
93         /* XTRA HACK WHATSEARCH */
94         /* Require non-unique monsters if needed */
95         if (norm && r_ref.kind_flags.has(MonsterKindType::UNIQUE))
96             continue;
97
98         /* Require unique monsters if needed */
99         if (uniq && r_ref.kind_flags.has_not(MonsterKindType::UNIQUE))
100             continue;
101
102         /* 名前検索 */
103         if (temp[0]) {
104             for (int xx = 0; temp[xx] && xx < 80; xx++) {
105 #ifdef JP
106                 if (iskanji(temp[xx])) {
107                     xx++;
108                     continue;
109                 }
110 #endif
111                 if (isupper(temp[xx]))
112                     temp[xx] = (char)tolower(temp[xx]);
113             }
114
115             char temp2[MAX_MONSTER_NAME];
116 #ifdef JP
117             strcpy(temp2, r_ref.E_name.c_str());
118 #else
119             strcpy(temp2, r_ref.name.c_str());
120 #endif
121             for (int xx = 0; temp2[xx] && xx < 80; xx++) {
122                 if (isupper(temp2[xx]))
123                     temp2[xx] = (char)tolower(temp2[xx]);
124             }
125
126 #ifdef JP
127             if (angband_strstr(temp2, temp) || angband_strstr(r_ref.name.c_str(), temp))
128 #else
129             if (angband_strstr(temp2, temp))
130 #endif
131                 who.push_back(r_ref.idx);
132         } else if (all || (r_ref.d_char == sym)) {
133             who.push_back(r_ref.idx);
134         }
135     }
136
137     if (who.empty()) {
138         screen_load();
139
140         return false;
141     }
142
143     why = 2;
144     char query = 'y';
145
146     if (why) {
147         ang_sort(player_ptr, who.data(), &why, who.size(), ang_sort_comp_hook, ang_sort_swap_hook);
148     }
149
150     uint i;
151     static int old_sym = '\0';
152     static uint old_i = 0;
153     if (old_sym == sym && old_i < who.size())
154         i = old_i;
155     else
156         i = who.size() - 1;
157
158     notpicked = true;
159     while (notpicked) {
160         auto r_idx = who[i];
161         roff_top(r_idx);
162         term_addstr(-1, TERM_WHITE, _(" ['r'思い出, ' 'で続行, ESC]", " [(r)ecall, ESC, space to continue]"));
163         while (true) {
164             if (recall) {
165                 lore_do_probe(player_ptr, r_idx);
166                 monster_race_track(player_ptr, r_idx);
167                 handle_stuff(player_ptr);
168                 screen_roff(player_ptr, r_idx, MONSTER_LORE_RESEARCH);
169                 notpicked = false;
170                 old_sym = sym;
171                 old_i = i;
172             }
173
174             query = inkey();
175             if (query != 'r')
176                 break;
177
178             recall = !recall;
179         }
180
181         if (query == ESCAPE)
182             break;
183
184         if (query == '-') {
185             if (++i == who.size()) {
186                 i = 0;
187                 if (!expand_list)
188                     break;
189             }
190
191             continue;
192         }
193
194         if (i-- == 0) {
195             i = who.size() - 1;
196             if (!expand_list)
197                 break;
198         }
199     }
200
201     screen_load();
202     return !notpicked;
203 }