OSDN Git Service

[Refactor] #2645 strip_name() の戻り値をvoid からstd::string に変更し、引数からchar* を消した
[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 "object/object-kind.h"
14 #include "player-info/class-info.h"
15 #include "player/player-skill.h"
16 #include "player/player-status.h"
17 #include "realm/realm-names-table.h"
18 #include "spell/spells-execution.h"
19 #include "spell/technic-info-table.h"
20 #include "sv-definition/sv-bow-types.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             for (const auto &k_ref : k_info) {
38                 if ((k_ref.tval != tval) || (k_ref.sval != num)) {
39                     continue;
40                 }
41                 if ((k_ref.tval == ItemKindType::BOW) && (k_ref.sval == SV_CRIMSON || k_ref.sval == SV_HARP)) {
42                     continue;
43                 }
44
45                 SUB_EXP weapon_exp = player_ptr->weapon_exp[tval][num];
46                 SUB_EXP weapon_max = player_ptr->weapon_exp_max[tval][num];
47                 const auto tmp = strip_name(k_ref.idx);
48                 fprintf(fff, "%-25s ", tmp.data());
49                 if (show_actual_value) {
50                     fprintf(fff, "%4d/%4d ", weapon_exp, weapon_max);
51                 }
52                 if (weapon_exp >= weapon_max) {
53                     fprintf(fff, "!");
54                 } else {
55                     fprintf(fff, " ");
56                 }
57                 auto skill_rank = PlayerSkill::weapon_skill_rank(weapon_exp);
58                 fprintf(fff, "%s", PlayerSkill::skill_rank_str(skill_rank));
59                 if (cheat_xtra) {
60                     fprintf(fff, " %d", weapon_exp);
61                 }
62                 fprintf(fff, "\n");
63                 break;
64             }
65         }
66     }
67
68     angband_fclose(fff);
69     (void)show_file(player_ptr, true, file_name, _("武器の経験値", "Weapon Proficiency"), 0, 0);
70     fd_kill(file_name);
71 }
72
73 /*!
74  * @brief 魔法の経験値を表示するコマンドのメインルーチン
75  * Display spell-exp
76  */
77 void do_cmd_knowledge_spell_exp(PlayerType *player_ptr)
78 {
79     FILE *fff = nullptr;
80     GAME_TEXT file_name[FILE_NAME_SIZE];
81     if (!open_temporary_file(&fff, file_name)) {
82         return;
83     }
84
85     if (player_ptr->realm1 != REALM_NONE) {
86         fprintf(fff, _("%sの魔法書\n", "%s Spellbook\n"), realm_names[player_ptr->realm1]);
87         for (SPELL_IDX i = 0; i < 32; i++) {
88             const magic_type *s_ptr;
89             if (!is_magic(player_ptr->realm1)) {
90                 s_ptr = &technic_info[player_ptr->realm1 - MIN_TECHNIC][i];
91             } else {
92                 s_ptr = &mp_ptr->info[player_ptr->realm1 - 1][i];
93             }
94
95             if (s_ptr->slevel >= 99) {
96                 continue;
97             }
98             SUB_EXP spell_exp = player_ptr->spell_exp[i];
99             auto skill_rank = PlayerSkill::spell_skill_rank(spell_exp);
100             fprintf(fff, "%-25s ", exe_spell(player_ptr, player_ptr->realm1, i, SpellProcessType::NAME));
101             if (player_ptr->realm1 == REALM_HISSATSU) {
102                 if (show_actual_value) {
103                     fprintf(fff, "----/---- ");
104                 }
105                 fprintf(fff, "[--]");
106             } else {
107                 if (show_actual_value) {
108                     fprintf(fff, "%4d/%4d ", spell_exp, PlayerSkill::spell_exp_at(PlayerSkillRank::MASTER));
109                 }
110                 if (skill_rank >= PlayerSkillRank::MASTER) {
111                     fprintf(fff, "!");
112                 } else {
113                     fprintf(fff, " ");
114                 }
115                 fprintf(fff, "%s", PlayerSkill::skill_rank_str(skill_rank));
116             }
117
118             if (cheat_xtra) {
119                 fprintf(fff, " %d", spell_exp);
120             }
121             fprintf(fff, "\n");
122         }
123     }
124
125     if (player_ptr->realm2 != REALM_NONE) {
126         fprintf(fff, _("%sの魔法書\n", "\n%s Spellbook\n"), realm_names[player_ptr->realm2]);
127         for (SPELL_IDX i = 0; i < 32; i++) {
128             const magic_type *s_ptr;
129             if (!is_magic(player_ptr->realm1)) {
130                 s_ptr = &technic_info[player_ptr->realm2 - MIN_TECHNIC][i];
131             } else {
132                 s_ptr = &mp_ptr->info[player_ptr->realm2 - 1][i];
133             }
134
135             if (s_ptr->slevel >= 99) {
136                 continue;
137             }
138
139             SUB_EXP spell_exp = player_ptr->spell_exp[i + 32];
140             auto skill_rank = PlayerSkill::spell_skill_rank(spell_exp);
141             fprintf(fff, "%-25s ", exe_spell(player_ptr, player_ptr->realm2, i, SpellProcessType::NAME));
142             if (show_actual_value) {
143                 fprintf(fff, "%4d/%4d ", spell_exp, PlayerSkill::spell_exp_at(PlayerSkillRank::MASTER));
144             }
145             if (skill_rank >= PlayerSkillRank::EXPERT) {
146                 fprintf(fff, "!");
147             } else {
148                 fprintf(fff, " ");
149             }
150             fprintf(fff, "%s", PlayerSkill::skill_rank_str(skill_rank));
151             if (cheat_xtra) {
152                 fprintf(fff, " %d", spell_exp);
153             }
154             fprintf(fff, "\n");
155         }
156     }
157
158     angband_fclose(fff);
159     (void)show_file(player_ptr, true, file_name, _("魔法の経験値", "Spell Proficiency"), 0, 0);
160     fd_kill(file_name);
161 }
162
163 /*!
164  * @brief スキル情報を表示するコマンドのメインルーチン /
165  * Display skill-exp
166  */
167 void do_cmd_knowledge_skill_exp(PlayerType *player_ptr)
168 {
169     FILE *fff = nullptr;
170     char file_name[FILE_NAME_SIZE];
171     if (!open_temporary_file(&fff, file_name)) {
172         return;
173     }
174
175     for (auto i : PLAYER_SKILL_KIND_TYPE_RANGE) {
176         SUB_EXP skill_exp = player_ptr->skill_exp[i];
177         SUB_EXP skill_max = s_info[enum2i(player_ptr->pclass)].s_max[i];
178         fprintf(fff, "%-20s ", PlayerSkill::skill_name(i));
179         if (show_actual_value) {
180             fprintf(fff, "%4d/%4d ", std::min(skill_exp, skill_max), skill_max);
181         }
182         if (skill_exp >= skill_max) {
183             fprintf(fff, "!");
184         } else {
185             fprintf(fff, " ");
186         }
187         auto skill_rank = (i == PlayerSkillKindType::RIDING) ? PlayerSkill::riding_skill_rank(skill_exp) : PlayerSkill::weapon_skill_rank(skill_exp);
188         fprintf(fff, "%s", PlayerSkill::skill_rank_str(skill_rank));
189         if (cheat_xtra) {
190             fprintf(fff, " %d", skill_exp);
191         }
192         fprintf(fff, "\n");
193     }
194
195     angband_fclose(fff);
196     (void)show_file(player_ptr, true, file_name, _("技能の経験値", "Miscellaneous Proficiency"), 0, 0);
197     fd_kill(file_name);
198 }