OSDN Git Service

Merge pull request #41491 (taotao/hengband/fix-impure_calc_num_blow into develop).
[hengband/hengband.git] / src / io-dump / special-class-dump.c
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 "mspell/monster-power-table.h"
13 #include "object/object-kind-hook.h"
14 #include "object/object-kind.h"
15
16 typedef struct {
17     BIT_FLAGS f4;
18     BIT_FLAGS f5;
19     BIT_FLAGS f6;
20 } learnt_spell_table;
21
22 /*!
23  * @brief 魔力喰いを持つクラスの情報をダンプする
24  * @param creature_ptr プレーヤーへの参照ポインタ
25  * @param fff ファイルポインタ
26  * @return なし
27  */
28 static void dump_magic_eater(player_type *creature_ptr, FILE *fff)
29 {
30     char s[EATER_EXT][MAX_NLEN];
31     fprintf(fff, _("\n\n  [取り込んだ魔法道具]\n", "\n\n  [Magic devices eaten]\n"));
32
33     for (int ext = 0; ext < 3; ext++) {
34         tval_type tval = 0;
35         switch (ext) {
36         case 0:
37             tval = TV_STAFF;
38             fprintf(fff, _("\n[杖]\n", "\n[Staffs]\n"));
39             break;
40         case 1:
41             tval = TV_WAND;
42             fprintf(fff, _("\n[魔法棒]\n", "\n[Wands]\n"));
43             break;
44         case 2:
45             tval = TV_ROD;
46             fprintf(fff, _("\n[ロッド]\n", "\n[Rods]\n"));
47             break;
48         }
49
50         int eat_num = 0;
51         for (OBJECT_SUBTYPE_VALUE i = 0; i < EATER_EXT; i++) {
52             int idx = EATER_EXT * ext + i;
53             int magic_num = creature_ptr->magic_num2[idx];
54             if (!magic_num)
55                 continue;
56
57             KIND_OBJECT_IDX k_idx = lookup_kind(tval, i);
58             if (!k_idx)
59                 continue;
60             sprintf(s[eat_num], "%23s (%2d)", (k_name + k_info[k_idx].name), magic_num);
61             eat_num++;
62         }
63
64         if (eat_num <= 0) {
65             fputs(_("  (なし)\n", "  (none)\n"), fff);
66             continue;
67         }
68
69         OBJECT_SUBTYPE_VALUE i;
70         for (i = 0; i < eat_num; i++) {
71             fputs(s[i], fff);
72             if (i % 3 < 2)
73                 fputs("    ", fff);
74             else
75                 fputs("\n", fff);
76         }
77
78         if (i % 3 > 0)
79             fputs("\n", fff);
80     }
81 }
82
83 /*!
84  * @brief 鍛冶師のエッセンス情報をダンプする
85  * @param creature_ptr プレーヤーへの参照ポインタ
86  * @param fff ファイルポインタ
87  * @return なし
88  */
89 static void dump_smith(player_type *creature_ptr, FILE *fff)
90 {
91     int i, id[250], n = 0, row;
92     fprintf(fff, _("\n\n  [手に入れたエッセンス]\n\n", "\n\n  [Get Essence]\n\n"));
93     fprintf(fff, _("エッセンス   個数     エッセンス   個数     エッセンス   個数", "Essence      Num      Essence      Num      Essence      Num "));
94     for (i = 0; essence_name[i]; i++) {
95         if (!essence_name[i][0])
96             continue;
97         id[n] = i;
98         n++;
99     }
100
101     row = n / 3 + 1;
102     for (i = 0; i < row; i++) {
103         fprintf(fff, "\n");
104         fprintf(fff, "%-11s %5d     ", essence_name[id[i]], (int)creature_ptr->magic_num1[id[i]]);
105         if (i + row < n)
106             fprintf(fff, "%-11s %5d     ", essence_name[id[i + row]], (int)creature_ptr->magic_num1[id[i + row]]);
107         if (i + row * 2 < n)
108             fprintf(fff, "%-11s %5d", essence_name[id[i + row * 2]], (int)creature_ptr->magic_num1[id[i + row * 2]]);
109     }
110
111     fputs("\n", fff);
112 }
113
114 /*!
115  * @brief ダンプする情報に学習済魔法の種類を追加する
116  * @param p ダンプ用のバッファ
117  * @param col 行数
118  * @param spell_type 魔法の種類
119  * @param learnt_spell_ptr 学習済魔法のテーブル
120  * @return なし
121  */
122 static void add_monster_spell_type(char p[][80], int col, blue_magic_type spell_type, learnt_spell_table *learnt_spell_ptr)
123 {
124     learnt_spell_ptr->f4 = 0;
125     learnt_spell_ptr->f5 = 0;
126     learnt_spell_ptr->f6 = 0;
127     set_rf_masks(&learnt_spell_ptr->f4, &learnt_spell_ptr->f5, &learnt_spell_ptr->f6, 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     int spellnum[MAX_MONSPELLS];
168     for (int spell_type = 1; spell_type < 6; spell_type++) {
169         col++;
170         learnt_spell_table learnt_magic;
171         add_monster_spell_type(p, col, spell_type, &learnt_magic);
172
173         int num = 0;
174         for (int i = 0; i < 32; i++) {
175             if ((0x00000001 << i) & learnt_magic.f4)
176                 spellnum[num++] = i;
177         }
178
179         for (int i = 32; i < 64; i++) {
180             if ((0x00000001 << (i - 32)) & learnt_magic.f5)
181                 spellnum[num++] = i;
182         }
183
184         for (int i = 64; i < 96; i++) {
185             if ((0x00000001 << (i - 64)) & learnt_magic.f6)
186                 spellnum[num++] = i;
187         }
188
189         col++;
190         bool pcol = FALSE;
191         strcat(p[col], "       ");
192
193         for (int i = 0; i < num; i++) {
194             if (creature_ptr->magic_num2[spellnum[i]] == 0)
195                 continue;
196
197             pcol = TRUE;
198             int l1 = strlen(p[col]);
199             int l2 = strlen(monster_powers_short[spellnum[i]]);
200             if ((l1 + l2) >= 75) {
201                 strcat(p[col], "\n");
202                 col++;
203                 strcat(p[col], "       ");
204             }
205
206             strcat(p[col], monster_powers_short[spellnum[i]]);
207             strcat(p[col], ", ");
208         }
209
210         if (!pcol) {
211             strcat(p[col], _("なし", "None"));
212             strcat(p[col], "\n");
213             continue;
214         }
215
216         if (p[col][strlen(p[col]) - 2] == ',') {
217             p[col][strlen(p[col]) - 2] = '\0';
218         } else {
219             p[col][strlen(p[col]) - 10] = '\0';
220         }
221
222         strcat(p[col], "\n");
223     }
224
225     for (int i = 0; i <= col; i++) {
226         fputs(p[i], fff);
227     }
228 }
229
230 /*!
231  * @brief プレイヤーの職業能力情報をファイルにダンプする
232  * @param creature_ptr プレーヤーへの参照ポインタ
233  * @param fff ファイルポインタ
234  * @return なし
235  */
236 void dump_aux_class_special(player_type *creature_ptr, FILE *fff)
237 {
238     switch (creature_ptr->pclass) {
239     case CLASS_MAGIC_EATER: {
240         dump_magic_eater(creature_ptr, fff);
241         return;
242     }
243     case CLASS_SMITH: {
244         dump_smith(creature_ptr, fff);
245         return;
246     }
247     case CLASS_BLUE_MAGE: {
248         dump_blue_mage(creature_ptr, fff);
249         return;
250     }
251     default:
252         return;
253     }
254 }