OSDN Git Service

Merge pull request #867 from shimitei/feature/refactor_bg_menu
[hengbandforosx/hengbandosx.git] / src / io-dump / special-class-dump.cpp
1 /*!
2  * @brief 一部職業でのみダンプする能力の出力処理
3  * @date 2020/03/07
4  * @author Hourier
5  */
6
7 #include "io-dump/special-class-dump.h"
8 #include "blue-magic/blue-magic-checker.h"
9 #include "cmd-item/cmd-magiceat.h"
10 #include "cmd-item/cmd-smith.h"
11 #include "mind/mind-blue-mage.h"
12 #include "monster-race/race-ability-flags.h"
13 #include "mspell/monster-power-table.h"
14 #include "object/object-kind-hook.h"
15 #include "object/object-kind.h"
16 #include "util/flag-group.h"
17
18 #include <vector>
19
20 typedef struct {
21     EnumClassFlagGroup<RF_ABILITY> ability_flags;
22 } learnt_spell_table;
23
24 /*!
25  * @brief 魔力喰いを持つクラスの情報をダンプする
26  * @param creature_ptr プレーヤーへの参照ポインタ
27  * @param fff ファイルポインタ
28  * @return なし
29  */
30 static void dump_magic_eater(player_type *creature_ptr, FILE *fff)
31 {
32     char s[EATER_EXT][MAX_NLEN];
33     fprintf(fff, _("\n\n  [取り込んだ魔法道具]\n", "\n\n  [Magic devices eaten]\n"));
34
35     for (int ext = 0; ext < 3; ext++) {
36         tval_type tval = TV_NONE;
37         switch (ext) {
38         case 0:
39             tval = TV_STAFF;
40             fprintf(fff, _("\n[杖]\n", "\n[Staffs]\n"));
41             break;
42         case 1:
43             tval = TV_WAND;
44             fprintf(fff, _("\n[魔法棒]\n", "\n[Wands]\n"));
45             break;
46         case 2:
47             tval = TV_ROD;
48             fprintf(fff, _("\n[ロッド]\n", "\n[Rods]\n"));
49             break;
50         }
51
52         int eat_num = 0;
53         for (OBJECT_SUBTYPE_VALUE i = 0; i < EATER_EXT; i++) {
54             int idx = EATER_EXT * ext + i;
55             int magic_num = creature_ptr->magic_num2[idx];
56             if (!magic_num)
57                 continue;
58
59             KIND_OBJECT_IDX k_idx = lookup_kind(tval, i);
60             if (!k_idx)
61                 continue;
62             sprintf(s[eat_num], "%23s (%2d)", k_info[k_idx].name.c_str(), magic_num);
63             eat_num++;
64         }
65
66         if (eat_num <= 0) {
67             fputs(_("  (なし)\n", "  (none)\n"), fff);
68             continue;
69         }
70
71         OBJECT_SUBTYPE_VALUE i;
72         for (i = 0; i < eat_num; i++) {
73             fputs(s[i], fff);
74             if (i % 3 < 2)
75                 fputs("    ", fff);
76             else
77                 fputs("\n", fff);
78         }
79
80         if (i % 3 > 0)
81             fputs("\n", fff);
82     }
83 }
84
85 /*!
86  * @brief 鍛冶師のエッセンス情報をダンプする
87  * @param creature_ptr プレーヤーへの参照ポインタ
88  * @param fff ファイルポインタ
89  * @return なし
90  */
91 static void dump_smith(player_type *creature_ptr, FILE *fff)
92 {
93     int i, id[250], n = 0, row;
94     fprintf(fff, _("\n\n  [手に入れたエッセンス]\n\n", "\n\n  [Get Essence]\n\n"));
95     fprintf(fff, _("エッセンス   個数     エッセンス   個数     エッセンス   個数", "Essence      Num      Essence      Num      Essence      Num "));
96     for (i = 0; essence_name[i]; i++) {
97         if (!essence_name[i][0])
98             continue;
99         id[n] = i;
100         n++;
101     }
102
103     row = n / 3 + 1;
104     for (i = 0; i < row; i++) {
105         fprintf(fff, "\n");
106         fprintf(fff, "%-11s %5d     ", essence_name[id[i]], (int)creature_ptr->magic_num1[id[i]]);
107         if (i + row < n)
108             fprintf(fff, "%-11s %5d     ", essence_name[id[i + row]], (int)creature_ptr->magic_num1[id[i + row]]);
109         if (i + row * 2 < n)
110             fprintf(fff, "%-11s %5d", essence_name[id[i + row * 2]], (int)creature_ptr->magic_num1[id[i + row * 2]]);
111     }
112
113     fputs("\n", fff);
114 }
115
116 /*!
117  * @brief ダンプする情報に学習済魔法の種類を追加する
118  * @param p ダンプ用のバッファ
119  * @param col 行数
120  * @param spell_type 魔法の種類
121  * @param learnt_spell_ptr 学習済魔法のテーブル
122  * @return なし
123  */
124 static void add_monster_spell_type(char p[][80], int col, blue_magic_type spell_type, learnt_spell_table *learnt_spell_ptr)
125 {
126     learnt_spell_ptr->ability_flags.clear();
127     set_rf_masks(learnt_spell_ptr->ability_flags, spell_type);
128     switch (spell_type) {
129     case MONSPELL_TYPE_BOLT:
130         strcat(p[col], _("\n     [ボルト型]\n", "\n     [Bolt  Type]\n"));
131         break;
132
133     case MONSPELL_TYPE_BALL:
134         strcat(p[col], _("\n     [ボール型]\n", "\n     [Ball  Type]\n"));
135         break;
136
137     case MONSPELL_TYPE_BREATH:
138         strcat(p[col], _("\n     [ブレス型]\n", "\n     [  Breath  ]\n"));
139         break;
140
141     case MONSPELL_TYPE_SUMMON:
142         strcat(p[col], _("\n     [召喚魔法]\n", "\n     [Summonning]\n"));
143         break;
144
145     case MONSPELL_TYPE_OTHER:
146         strcat(p[col], _("\n     [ その他 ]\n", "\n     [Other Type]\n"));
147         break;
148     }
149 }
150
151 /*!
152  * @brief 青魔道士の学習済魔法をダンプする
153  * @param creature_ptr プレーヤーへの参照ポインタ
154  * @param fff ファイルポインタ
155  * @return なし
156  */
157 static void dump_blue_mage(player_type *creature_ptr, FILE *fff)
158 {
159     char p[60][80];
160     for (int i = 0; i < 60; i++) {
161         p[i][0] = '\0';
162     }
163
164     int col = 0;
165     strcat(p[col], _("\n\n  [学習済みの青魔法]\n", "\n\n  [Learned Blue Magic]\n"));
166
167     for (int spell_type = 1; spell_type < 6; spell_type++) {
168         col++;
169         learnt_spell_table learnt_magic;
170         add_monster_spell_type(p, col, static_cast<blue_magic_type>(spell_type), &learnt_magic);
171
172         std::vector<RF_ABILITY> learnt_spells;
173         EnumClassFlagGroup<RF_ABILITY>::get_flags(learnt_magic.ability_flags, std::back_inserter(learnt_spells));
174
175         col++;
176         bool pcol = FALSE;
177         strcat(p[col], "       ");
178
179         for (auto spell : learnt_spells) {
180             const int spellnum = static_cast<int>(spell);
181             if (creature_ptr->magic_num2[spellnum] == 0)
182                 continue;
183
184             pcol = TRUE;
185             int l1 = strlen(p[col]);
186             int l2 = strlen(monster_powers_short[spellnum]);
187             if ((l1 + l2) >= 75) {
188                 strcat(p[col], "\n");
189                 col++;
190                 strcat(p[col], "       ");
191             }
192
193             strcat(p[col], monster_powers_short[spellnum]);
194             strcat(p[col], ", ");
195         }
196
197         if (!pcol) {
198             strcat(p[col], _("なし", "None"));
199             strcat(p[col], "\n");
200             continue;
201         }
202
203         if (p[col][strlen(p[col]) - 2] == ',') {
204             p[col][strlen(p[col]) - 2] = '\0';
205         } else {
206             p[col][strlen(p[col]) - 10] = '\0';
207         }
208
209         strcat(p[col], "\n");
210     }
211
212     for (int i = 0; i <= col; i++) {
213         fputs(p[i], fff);
214     }
215 }
216
217 /*!
218  * @brief プレイヤーの職業能力情報をファイルにダンプする
219  * @param creature_ptr プレーヤーへの参照ポインタ
220  * @param fff ファイルポインタ
221  * @return なし
222  */
223 void dump_aux_class_special(player_type *creature_ptr, FILE *fff)
224 {
225     switch (creature_ptr->pclass) {
226     case CLASS_MAGIC_EATER: {
227         dump_magic_eater(creature_ptr, fff);
228         return;
229     }
230     case CLASS_SMITH: {
231         dump_smith(creature_ptr, fff);
232         return;
233     }
234     case CLASS_BLUE_MAGE: {
235         dump_blue_mage(creature_ptr, fff);
236         return;
237     }
238     default:
239         return;
240     }
241 }