OSDN Git Service

[Refactor] #2679 モンスターの速度をスポイルする処理を加速の正負にかかわらないよう統一した
[hengbandforosx/hengbandosx.git] / src / wizard / monster-info-spoiler.cpp
1 #include "wizard/monster-info-spoiler.h"
2 #include "io/files-util.h"
3 #include "monster-race/monster-race.h"
4 #include "monster-race/race-flags1.h"
5 #include "monster-race/race-flags7.h"
6 #include "monster-race/race-flags8.h"
7 #include "system/angband-version.h"
8 #include "system/monster-race-definition.h"
9 #include "term/term-color-types.h"
10 #include "util/angband-files.h"
11 #include "util/bit-flags-calculator.h"
12 #include "util/sort.h"
13 #include "util/string-processor.h"
14 #include "view/display-lore.h"
15 #include "view/display-messages.h"
16
17 /*!
18  * @brief シンボル職の記述名を返す /
19  * Extract a textual representation of an attribute
20  * @param r_ptr モンスター種族の構造体ポインタ
21  * @return シンボル職の記述名
22  */
23 static concptr attr_to_text(monster_race *r_ptr)
24 {
25     if (r_ptr->visual_flags.has(MonsterVisualType::CLEAR_COLOR)) {
26         return _("透明な", "Clear");
27     }
28
29     if (r_ptr->visual_flags.has(MonsterVisualType::MULTI_COLOR)) {
30         return _("万色の", "Multi");
31     }
32
33     if (r_ptr->visual_flags.has(MonsterVisualType::RANDOM_COLOR)) {
34         return _("準ランダムな", "S.Rand");
35     }
36
37     switch (r_ptr->d_attr) {
38     case TERM_DARK:
39         return _("黒い", "Dark");
40     case TERM_WHITE:
41         return _("白い", "White");
42     case TERM_SLATE:
43         return _("青灰色の", "Slate");
44     case TERM_ORANGE:
45         return _("オレンジの", "Orange");
46     case TERM_RED:
47         return _("赤い", "Red");
48     case TERM_GREEN:
49         return _("緑の", "Green");
50     case TERM_BLUE:
51         return _("青い", "Blue");
52     case TERM_UMBER:
53         return _("琥珀色の", "Umber");
54     case TERM_L_DARK:
55         return _("灰色の", "L.Dark");
56     case TERM_L_WHITE:
57         return _("明るい青灰色の", "L.Slate");
58     case TERM_VIOLET:
59         return _("紫の", "Violet");
60     case TERM_YELLOW:
61         return _("黄色の", "Yellow");
62     case TERM_L_RED:
63         return _("明るい赤の", "L.Red");
64     case TERM_L_GREEN:
65         return _("明るい緑の", "L.Green");
66     case TERM_L_BLUE:
67         return _("明るい青の", "L.Blue");
68     case TERM_L_UMBER:
69         return _("明るい琥珀色の", "L.Umber");
70     }
71
72     return _("変な色の", "Icky");
73 }
74
75 SpoilerOutputResultType spoil_mon_desc(concptr fname, std::function<bool(const monster_race *)> filter_monster)
76 {
77     PlayerType dummy;
78     uint16_t why = 2;
79     char buf[1024];
80     char nam[MAX_MONSTER_NAME + 10]; // ユニークには[U] が付くので少し伸ばす
81     char lev[80];
82     char rar[80];
83     char spd[80];
84     char ac[80];
85     char hp[80];
86     char symbol[80];
87     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
88     spoiler_file = angband_fopen(buf, "w");
89     if (!spoiler_file) {
90         return SpoilerOutputResultType::FILE_OPEN_FAILED;
91     }
92
93     char title[200];
94     put_version(title);
95
96     fprintf(spoiler_file, "Monster Spoilers for %s\n", title);
97     fprintf(spoiler_file, "------------------------------------------\n\n");
98     fprintf(spoiler_file, "%-45.45s%4s %4s %4s %7s %7s  %19.19s\n", "Name", "Lev", "Rar", "Spd", "Hp", "Ac", "Visual Info");
99     fprintf(spoiler_file, "%-45.45s%4s %4s %4s %7s %7s  %4.19s\n",
100         "---------------------------------------------"
101         "----"
102         "----------",
103         "---", "---", "---", "-----", "-----", "-------------------");
104
105     std::vector<MonsterRaceId> who;
106     for (const auto &[r_idx, r_ref] : r_info) {
107         if (MonsterRace(r_ref.idx).is_valid() && !r_ref.name.empty()) {
108             who.push_back(r_ref.idx);
109         }
110     }
111
112     ang_sort(&dummy, who.data(), &why, who.size(), ang_sort_comp_hook, ang_sort_swap_hook);
113     for (auto r_idx : who) {
114         auto *r_ptr = &r_info[r_idx];
115         concptr name = r_ptr->name.c_str();
116         if (filter_monster && !filter_monster(r_ptr)) {
117             continue;
118         }
119
120         char name_buf[41];
121         angband_strcpy(name_buf, name, sizeof(name_buf));
122         name += strlen(name_buf);
123
124         if (any_bits(r_ptr->flags7, RF7_KAGE)) {
125             continue;
126         }
127
128         if (r_ptr->kind_flags.has(MonsterKindType::UNIQUE)) {
129             sprintf(nam, "[U] %s", name_buf);
130         } else if (r_ptr->population_flags.has(MonsterPopulationType::NAZGUL)) {
131             sprintf(nam, "[N] %s", name_buf);
132         } else {
133             sprintf(nam, _("    %s", "The %s"), name_buf);
134         }
135
136         sprintf(lev, "%d", (int)r_ptr->level);
137         sprintf(rar, "%d", (int)r_ptr->rarity);
138         sprintf(spd, "%+d", r_ptr->speed - STANDARD_SPEED);
139         sprintf(ac, "%d", r_ptr->ac);
140         if (any_bits(r_ptr->flags1, RF1_FORCE_MAXHP) || (r_ptr->hside == 1)) {
141             sprintf(hp, "%d", r_ptr->hdice * r_ptr->hside);
142         } else {
143             sprintf(hp, "%dd%d", r_ptr->hdice, r_ptr->hside);
144         }
145
146         sprintf(symbol, "%ld", (long)(r_ptr->mexp));
147         sprintf(symbol, "%s '%c'", attr_to_text(r_ptr), r_ptr->d_char);
148         fprintf(spoiler_file, "%-45.45s%4s %4s %4s %7s %7s  %19.19s\n", nam, lev, rar, spd, hp, ac, symbol);
149
150         while (*name != '\0') {
151             angband_strcpy(name_buf, name, sizeof(name_buf));
152             name += strlen(name_buf);
153             fprintf(spoiler_file, "    %s\n", name_buf);
154         }
155     }
156
157     fprintf(spoiler_file, "\n");
158     return ferror(spoiler_file) || angband_fclose(spoiler_file) ? SpoilerOutputResultType::FILE_CLOSE_FAILED
159                                                                 : SpoilerOutputResultType::SUCCESSFUL;
160 }
161
162 /*!
163  * @brief 関数ポインタ用の出力関数 /
164  * Hook function used in spoil_mon_info()
165  * @param attr 未使用
166  * @param str 文字列参照ポインタ
167  */
168 static void roff_func(TERM_COLOR attr, concptr str)
169 {
170     (void)attr;
171     spoil_out(str);
172 }
173
174 /*!
175  * @brief モンスター詳細情報をスポイラー出力するメインルーチン /
176  * Create a spoiler file for monsters (-SHAWN-)
177  * @param fname ファイル名
178  */
179 SpoilerOutputResultType spoil_mon_info(concptr fname)
180 {
181     PlayerType dummy;
182     char buf[1024];
183     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
184     spoiler_file = angband_fopen(buf, "w");
185     if (!spoiler_file) {
186         return SpoilerOutputResultType::FILE_OPEN_FAILED;
187     }
188
189     char title[200];
190     put_version(title);
191     sprintf(buf, "Monster Spoilers for %s\n", title);
192     spoil_out(buf);
193     spoil_out("------------------------------------------\n\n");
194
195     std::vector<MonsterRaceId> who;
196     for (const auto &[r_idx, r_ref] : r_info) {
197         if (MonsterRace(r_ref.idx).is_valid() && !r_ref.name.empty()) {
198             who.push_back(r_ref.idx);
199         }
200     }
201
202     uint16_t why = 2;
203     ang_sort(&dummy, who.data(), &why, who.size(), ang_sort_comp_hook, ang_sort_swap_hook);
204     for (auto r_idx : who) {
205         auto *r_ptr = &r_info[r_idx];
206         if (r_ptr->kind_flags.has(MonsterKindType::UNIQUE)) {
207             spoil_out("[U] ");
208         } else if (r_ptr->population_flags.has(MonsterPopulationType::NAZGUL)) {
209             spoil_out("[N] ");
210         }
211
212         sprintf(buf, _("%s/%s  (", "%s%s ("), r_ptr->name.c_str(), _(r_ptr->E_name.c_str(), "")); /* ---)--- */
213         spoil_out(buf);
214         spoil_out(attr_to_text(r_ptr));
215         sprintf(buf, " '%c')\n", r_ptr->d_char);
216         spoil_out(buf);
217         sprintf(buf, "=== ");
218         spoil_out(buf);
219         sprintf(buf, "Num:%d  ", enum2i(r_idx));
220         spoil_out(buf);
221         sprintf(buf, "Lev:%d  ", (int)r_ptr->level);
222         spoil_out(buf);
223         sprintf(buf, "Rar:%d  ", r_ptr->rarity);
224         spoil_out(buf);
225         sprintf(buf, "%+d", r_ptr->speed - STANDARD_SPEED);
226         spoil_out(buf);
227         if (any_bits(r_ptr->flags1, RF1_FORCE_MAXHP) || (r_ptr->hside == 1)) {
228             sprintf(buf, "Hp:%d  ", r_ptr->hdice * r_ptr->hside);
229         } else {
230             sprintf(buf, "Hp:%dd%d  ", r_ptr->hdice, r_ptr->hside);
231         }
232
233         spoil_out(buf);
234         sprintf(buf, "Ac:%d  ", r_ptr->ac);
235         spoil_out(buf);
236         sprintf(buf, "Exp:%ld\n", (long)(r_ptr->mexp));
237         spoil_out(buf);
238         output_monster_spoiler(r_idx, roff_func);
239         spoil_out(nullptr);
240     }
241
242     return ferror(spoiler_file) || angband_fclose(spoiler_file) ? SpoilerOutputResultType::FILE_CLOSE_FAILED
243                                                                 : SpoilerOutputResultType::SUCCESSFUL;
244 }