OSDN Git Service

[Chore] UTF-8エンコーディングのファイルからBOMを削除
[hengbandforosx/hengbandosx.git] / src / knowledge / knowledge-experiences.cpp
1 /*!
2  * @brief 技能の経験を表示する
3  * @date 2020/04/23
4  * @author Hourier
5  */
6
7 #include "knowledge/knowledge-experiences.h"
8 #include "core/show-file.h"
9 #include "flavor/object-flavor.h"
10 #include "game-option/cheat-options.h"
11 #include "game-option/text-display-options.h"
12 #include "io-dump/dump-util.h"
13 #include "player-info/class-info.h"
14 #include "player/player-skill.h"
15 #include "player/player-status.h"
16 #include "realm/realm-names-table.h"
17 #include "spell/spells-execution.h"
18 #include "spell/technic-info-table.h"
19 #include "sv-definition/sv-bow-types.h"
20 #include "system/baseitem-info.h"
21 #include "system/player-type-definition.h"
22 #include "util/angband-files.h"
23
24 /*
25  * Display weapon-exp
26  */
27 void do_cmd_knowledge_weapon_exp(PlayerType *player_ptr)
28 {
29     FILE *fff = nullptr;
30     GAME_TEXT file_name[FILE_NAME_SIZE];
31     if (!open_temporary_file(&fff, file_name)) {
32         return;
33     }
34
35     for (auto tval : { ItemKindType::SWORD, ItemKindType::POLEARM, ItemKindType::HAFTED, ItemKindType::DIGGING, ItemKindType::BOW }) {
36         for (int num = 0; num < 64; num++) {
37             BaseitemKey bi_key(tval, num);
38             for (const auto &baseitem : baseitems_info) {
39                 if (baseitem.bi_key != bi_key) {
40                     continue;
41                 }
42
43                 const auto sval = baseitem.bi_key.sval();
44                 if ((baseitem.bi_key.tval() == ItemKindType::BOW) && (sval == SV_CRIMSON || sval == SV_HARP)) {
45                     continue;
46                 }
47
48                 SUB_EXP weapon_exp = player_ptr->weapon_exp[tval][num];
49                 SUB_EXP weapon_max = player_ptr->weapon_exp_max[tval][num];
50                 const auto tmp = strip_name(baseitem.idx);
51                 fprintf(fff, "%-25s ", tmp.data());
52                 if (show_actual_value) {
53                     fprintf(fff, "%4d/%4d ", weapon_exp, weapon_max);
54                 }
55                 if (weapon_exp >= weapon_max) {
56                     fprintf(fff, "!");
57                 } else {
58                     fprintf(fff, " ");
59                 }
60                 auto skill_rank = PlayerSkill::weapon_skill_rank(weapon_exp);
61                 fprintf(fff, "%s", PlayerSkill::skill_rank_str(skill_rank));
62                 if (cheat_xtra) {
63                     fprintf(fff, " %d", weapon_exp);
64                 }
65                 fprintf(fff, "\n");
66                 break;
67             }
68         }
69     }
70
71     angband_fclose(fff);
72     (void)show_file(player_ptr, true, file_name, 0, 0, _("武器の経験値", "Weapon Proficiency"));
73     fd_kill(file_name);
74 }
75
76 /*!
77  * @brief 魔法の経験値を表示するコマンドのメインルーチン
78  * Display spell-exp
79  */
80 void do_cmd_knowledge_spell_exp(PlayerType *player_ptr)
81 {
82     FILE *fff = nullptr;
83     GAME_TEXT file_name[FILE_NAME_SIZE];
84     if (!open_temporary_file(&fff, file_name)) {
85         return;
86     }
87
88     if (player_ptr->realm1 != REALM_NONE) {
89         fprintf(fff, _("%sの魔法書\n", "%s Spellbook\n"), realm_names[player_ptr->realm1]);
90         for (SPELL_IDX i = 0; i < 32; i++) {
91             const magic_type *s_ptr;
92             if (!is_magic(player_ptr->realm1)) {
93                 s_ptr = &technic_info[player_ptr->realm1 - MIN_TECHNIC][i];
94             } else {
95                 s_ptr = &mp_ptr->info[player_ptr->realm1 - 1][i];
96             }
97
98             if (s_ptr->slevel >= 99) {
99                 continue;
100             }
101             SUB_EXP spell_exp = player_ptr->spell_exp[i];
102             auto skill_rank = PlayerSkill::spell_skill_rank(spell_exp);
103             const auto spell_name = exe_spell(player_ptr, player_ptr->realm1, i, SpellProcessType::NAME);
104             fprintf(fff, "%-25s ", spell_name->data());
105             if (player_ptr->realm1 == REALM_HISSATSU) {
106                 if (show_actual_value) {
107                     fprintf(fff, "----/---- ");
108                 }
109                 fprintf(fff, "[--]");
110             } else {
111                 if (show_actual_value) {
112                     fprintf(fff, "%4d/%4d ", spell_exp, PlayerSkill::spell_exp_at(PlayerSkillRank::MASTER));
113                 }
114                 if (skill_rank >= PlayerSkillRank::MASTER) {
115                     fprintf(fff, "!");
116                 } else {
117                     fprintf(fff, " ");
118                 }
119                 fprintf(fff, "%s", PlayerSkill::skill_rank_str(skill_rank));
120             }
121
122             if (cheat_xtra) {
123                 fprintf(fff, " %d", spell_exp);
124             }
125             fprintf(fff, "\n");
126         }
127     }
128
129     if (player_ptr->realm2 != REALM_NONE) {
130         fprintf(fff, _("%sの魔法書\n", "\n%s Spellbook\n"), realm_names[player_ptr->realm2]);
131         for (SPELL_IDX i = 0; i < 32; i++) {
132             const magic_type *s_ptr;
133             if (!is_magic(player_ptr->realm1)) {
134                 s_ptr = &technic_info[player_ptr->realm2 - MIN_TECHNIC][i];
135             } else {
136                 s_ptr = &mp_ptr->info[player_ptr->realm2 - 1][i];
137             }
138
139             if (s_ptr->slevel >= 99) {
140                 continue;
141             }
142
143             SUB_EXP spell_exp = player_ptr->spell_exp[i + 32];
144             auto skill_rank = PlayerSkill::spell_skill_rank(spell_exp);
145             const auto spell_name = exe_spell(player_ptr, player_ptr->realm2, i, SpellProcessType::NAME);
146             fprintf(fff, "%-25s ", spell_name->data());
147             if (show_actual_value) {
148                 fprintf(fff, "%4d/%4d ", spell_exp, PlayerSkill::spell_exp_at(PlayerSkillRank::MASTER));
149             }
150             if (skill_rank >= PlayerSkillRank::EXPERT) {
151                 fprintf(fff, "!");
152             } else {
153                 fprintf(fff, " ");
154             }
155             fprintf(fff, "%s", PlayerSkill::skill_rank_str(skill_rank));
156             if (cheat_xtra) {
157                 fprintf(fff, " %d", spell_exp);
158             }
159             fprintf(fff, "\n");
160         }
161     }
162
163     angband_fclose(fff);
164     (void)show_file(player_ptr, true, file_name, 0, 0, _("魔法の経験値", "Spell Proficiency"));
165     fd_kill(file_name);
166 }
167
168 /*!
169  * @brief スキル情報を表示するコマンドのメインルーチン /
170  * Display skill-exp
171  */
172 void do_cmd_knowledge_skill_exp(PlayerType *player_ptr)
173 {
174     FILE *fff = nullptr;
175     char file_name[FILE_NAME_SIZE];
176     if (!open_temporary_file(&fff, file_name)) {
177         return;
178     }
179
180     for (auto i : PLAYER_SKILL_KIND_TYPE_RANGE) {
181         SUB_EXP skill_exp = player_ptr->skill_exp[i];
182         SUB_EXP skill_max = class_skills_info[enum2i(player_ptr->pclass)].s_max[i];
183         fprintf(fff, "%-20s ", PlayerSkill::skill_name(i));
184         if (show_actual_value) {
185             fprintf(fff, "%4d/%4d ", std::min(skill_exp, skill_max), skill_max);
186         }
187         if (skill_exp >= skill_max) {
188             fprintf(fff, "!");
189         } else {
190             fprintf(fff, " ");
191         }
192         auto skill_rank = (i == PlayerSkillKindType::RIDING) ? PlayerSkill::riding_skill_rank(skill_exp) : PlayerSkill::weapon_skill_rank(skill_exp);
193         fprintf(fff, "%s", PlayerSkill::skill_rank_str(skill_rank));
194         if (cheat_xtra) {
195             fprintf(fff, " %d", skill_exp);
196         }
197         fprintf(fff, "\n");
198     }
199
200     angband_fclose(fff);
201     (void)show_file(player_ptr, true, file_name, 0, 0, _("技能の経験値", "Miscellaneous Proficiency"));
202     fd_kill(file_name);
203 }