OSDN Git Service

[Refactor] #40392 Moved dump_yourself() from birth.c to knowledge-self.c
[hengband/hengband.git] / src / knowledge / knowledge-self.c
1 /*!
2  * @brief 自己に関する情報を表示する
3  * @date 2020/04/24
4  * @author Hourier
5  */
6
7 #include "system/angband.h"
8 #include "knowledge-self.h"
9 #include "cmd/dump-util.h"
10 #include "player/avatar.h"
11 #include "core/show-file.h"
12 #include "dungeon/dungeon-file.h"
13 #include "world/world.h"
14 #include "market/store-util.h"
15 #include "floor/floor-town.h"
16 #include "object/object-flavor.h"
17 #include "birth/birth-explanations-table.h"
18
19 /*
20  * List virtues & status
21  */
22 void do_cmd_knowledge_virtues(player_type *creature_ptr)
23 {
24         FILE *fff = NULL;
25         GAME_TEXT file_name[FILE_NAME_SIZE];
26         if (!open_temporary_file(&fff, file_name)) return;
27
28         fprintf(fff, _("現在の属性 : %s\n\n", "Your alignment : %s\n\n"), your_alignment(creature_ptr));
29         dump_virtues(creature_ptr, fff);
30         my_fclose(fff);
31         (void)show_file(creature_ptr, TRUE, file_name, _("八つの徳", "Virtues"), 0, 0);
32         fd_kill(file_name);
33 }
34
35
36 /*!
37  * @brief 自分に関する情報を画面に表示する
38  * @param creature_ptr プレーヤーへの参照ポインタ
39  * @param fff ファイルポインタ
40  * @return なし
41  */
42 static void dump_yourself(player_type *creature_ptr, FILE *fff)
43 {
44     if (!fff)
45         return;
46
47     char temp[80 * 10];
48     roff_to_buf(race_explanations[creature_ptr->prace], 78, temp, sizeof(temp));
49     fprintf(fff, "\n\n");
50     fprintf(fff, _("種族: %s\n", "Race: %s\n"), race_info[creature_ptr->prace].title);
51     concptr t = temp;
52
53     for (int i = 0; i < 10; i++) {
54         if (t[0] == 0)
55             break;
56         fprintf(fff, "%s\n", t);
57         t += strlen(t) + 1;
58     }
59
60     roff_to_buf(class_explanations[creature_ptr->pclass], 78, temp, sizeof(temp));
61     fprintf(fff, "\n");
62     fprintf(fff, _("職業: %s\n", "Class: %s\n"), class_info[creature_ptr->pclass].title);
63
64     t = temp;
65     for (int i = 0; i < 10; i++) {
66         if (t[0] == 0)
67             break;
68         fprintf(fff, "%s\n", t);
69         t += strlen(t) + 1;
70     }
71
72     roff_to_buf(personality_explanations[creature_ptr->pseikaku], 78, temp, sizeof(temp));
73     fprintf(fff, "\n");
74     fprintf(fff, _("性格: %s\n", "Pesonality: %s\n"), seikaku_info[creature_ptr->pseikaku].title);
75
76     t = temp;
77     for (int i = 0; i < A_MAX; i++) {
78         if (t[0] == 0)
79             break;
80         fprintf(fff, "%s\n", t);
81         t += strlen(t) + 1;
82     }
83
84     fprintf(fff, "\n");
85     if (creature_ptr->realm1) {
86         roff_to_buf(realm_explanations[technic2magic(creature_ptr->realm1) - 1], 78, temp, sizeof(temp));
87         fprintf(fff, _("魔法: %s\n", "Realm: %s\n"), realm_names[creature_ptr->realm1]);
88
89         t = temp;
90         for (int i = 0; i < A_MAX; i++) {
91             if (t[0] == 0)
92                 break;
93
94             fprintf(fff, "%s\n", t);
95             t += strlen(t) + 1;
96         }
97     }
98
99     fprintf(fff, "\n");
100     if (creature_ptr->realm2) {
101         roff_to_buf(realm_explanations[technic2magic(creature_ptr->realm2) - 1], 78, temp, sizeof(temp));
102         fprintf(fff, _("魔法: %s\n", "Realm: %s\n"), realm_names[creature_ptr->realm2]);
103
104         t = temp;
105         for (int i = 0; i < A_MAX; i++) {
106             if (t[0] == 0)
107                 break;
108
109             fprintf(fff, "%s\n", t);
110             t += strlen(t) + 1;
111         }
112     }
113 }
114
115 /*
116 * List virtues & status
117 *
118 */
119 void do_cmd_knowledge_stat(player_type *creature_ptr)
120 {
121         FILE *fff = NULL;
122         GAME_TEXT file_name[FILE_NAME_SIZE];
123         if (!open_temporary_file(&fff, file_name)) return;
124
125         int percent = (int)(((long)creature_ptr->player_hp[PY_MAX_LEVEL - 1] * 200L) /
126                 (2 * creature_ptr->hitdie +
127                 ((PY_MAX_LEVEL - 1 + 3) * (creature_ptr->hitdie + 1))));
128
129         if (creature_ptr->knowledge & KNOW_HPRATE)
130                 fprintf(fff, _("現在の体力ランク : %d/100\n\n", "Your current Life Rating is %d/100.\n\n"), percent);
131         else fprintf(fff, _("現在の体力ランク : ???\n\n", "Your current Life Rating is ???.\n\n"));
132
133         fprintf(fff, _("能力の最大値\n\n", "Limits of maximum stats\n\n"));
134         for (int v_nr = 0; v_nr < A_MAX; v_nr++)
135         {
136                 if ((creature_ptr->knowledge & KNOW_STAT) || creature_ptr->stat_max[v_nr] == creature_ptr->stat_max_max[v_nr])
137                         fprintf(fff, "%s 18/%d\n", stat_names[v_nr], creature_ptr->stat_max_max[v_nr] - 18);
138                 else
139                         fprintf(fff, "%s ???\n", stat_names[v_nr]);
140         }
141
142         dump_yourself(creature_ptr, fff);
143         my_fclose(fff);
144         (void)show_file(creature_ptr, TRUE, file_name, _("自分に関する情報", "HP-rate & Max stat"), 0, 0);
145         fd_kill(file_name);
146 }
147
148
149 /*
150  * List my home
151  * @param player_ptr プレーヤーへの参照ポインタ
152  * @return なし
153  */
154 void do_cmd_knowledge_home(player_type *player_ptr)
155 {
156         process_dungeon_file(player_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
157
158         FILE *fff = NULL;
159         GAME_TEXT file_name[FILE_NAME_SIZE];
160         if (!open_temporary_file(&fff, file_name)) return;
161
162         store_type *store_ptr;
163         store_ptr = &town_info[1].store[STORE_HOME];
164
165         if (store_ptr->stock_num)
166         {
167 #ifdef JP
168                 TERM_LEN x = 1;
169 #endif
170                 fprintf(fff, _("  [ 我が家のアイテム ]\n", "  [Home Inventory]\n"));
171                 concptr paren = ")";
172                 GAME_TEXT o_name[MAX_NLEN];
173                 for (int i = 0; i < store_ptr->stock_num; i++)
174                 {
175 #ifdef JP
176                         if ((i % 12) == 0) fprintf(fff, "\n ( %d ページ )\n", x++);
177                         object_desc(player_ptr, o_name, &store_ptr->stock[i], 0);
178                         if (strlen(o_name) <= 80 - 3)
179                         {
180                                 fprintf(fff, "%c%s %s\n", I2A(i % 12), paren, o_name);
181                         }
182                         else
183                         {
184                                 int n;
185                                 char *t;
186                                 for (n = 0, t = o_name; n < 80 - 3; n++, t++)
187                                         if (iskanji(*t)) { t++; n++; }
188                                 if (n == 81 - 3) n = 79 - 3; /* 最後が漢字半分 */
189
190                                 fprintf(fff, "%c%s %.*s\n", I2A(i % 12), paren, n, o_name);
191                                 fprintf(fff, "   %.77s\n", o_name + n);
192                         }
193 #else
194                         object_desc(player_ptr, o_name, &store_ptr->stock[i], 0);
195                         fprintf(fff, "%c%s %s\n", I2A(i % 12), paren, o_name);
196 #endif
197                 }
198
199                 fprintf(fff, "\n\n");
200         }
201
202         my_fclose(fff);
203         (void)show_file(player_ptr, TRUE, file_name, _("我が家のアイテム", "Home Inventory"), 0, 0);
204         fd_kill(file_name);
205 }