OSDN Git Service

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