OSDN Git Service

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