OSDN Git Service

[Fix] マージ後のVisualStudio上の警告を修正. / Fixed post-merge warning on Visual Studio.
[hengband/hengband.git] / src / view / display-player.c
1 /*!
2  * @brief プレーヤーのステータス表示メインルーチン群
3  * @date 2020/02/25
4  * @author Hourier
5  * @details
6  * ここにこれ以上関数を引っ越してくるのは禁止
7  */
8
9 #include "display-player.h"
10 #include "player-personality.h"
11 #include "gameterm.h"
12 #include "status-first-page.h"
13 #include "player-sex.h"
14 #include "patron.h"
15 #include "world.h"
16 #include "quest.h"
17 #include "core.h" // 暫定。後で消す
18 #include "mutation.h"
19 #include "dungeon-file.h"
20 #include "objectkind.h"
21 #include "view/display-util.h"
22 #include "view/display-characteristic.h"
23 #include "view/display-player-stat-info.h"
24 #include "view/display-player-misc-info.h"
25 #include "view/display-player-middle.h"
26
27 /*!
28  * @brief
29  * @param creature_ptr プレーヤーへの参照ポインタ
30  * @param mode ステータス表示モード
31  * @return どれかの処理をこなしたらTRUE、何もしなかったらFALSE
32  */
33 static bool display_player_info(player_type *creature_ptr, int mode)
34 {
35         if (mode == 2)
36         {
37                 display_player_misc_info(creature_ptr);
38                 display_player_stat_info(creature_ptr);
39                 display_player_flag_info_1(creature_ptr, display_player_equippy);
40                 return TRUE;
41         }
42
43         if (mode == 3)
44         {
45                 display_player_flag_info_2(creature_ptr, display_player_equippy);
46                 return TRUE;
47         }
48
49         if (mode == 4)
50         {
51                 do_cmd_knowledge_mutations(creature_ptr);
52                 return TRUE;
53         }
54
55         return FALSE;
56 }
57
58
59 /*!
60  * @brief 名前、性別、種族、職業を表示する
61  * @param creature_ptr プレーヤーへの参照ポインタ
62  */
63 static void display_player_basic_info(player_type *creature_ptr)
64 {
65         char tmp[64];
66 #ifdef JP
67         sprintf(tmp, "%s%s%s", ap_ptr->title, ap_ptr->no == 1 ? "の" : "", creature_ptr->name);
68 #else
69         sprintf(tmp, "%s %s", ap_ptr->title, creature_ptr->name);
70 #endif
71
72         display_player_one_line(ENTRY_NAME, tmp, TERM_L_BLUE);
73         display_player_one_line(ENTRY_SEX, sp_ptr->title, TERM_L_BLUE);
74         display_player_one_line(ENTRY_RACE, (creature_ptr->mimic_form ? mimic_info[creature_ptr->mimic_form].title : rp_ptr->title), TERM_L_BLUE);
75         display_player_one_line(ENTRY_CLASS, cp_ptr->title, TERM_L_BLUE);
76 }
77
78
79 /*!
80  * @brief 魔法領域を表示する
81  * @param creature_ptr プレーヤーへの参照ポインタ
82  * @return なし
83  */
84 static void display_magic_realms(player_type *creature_ptr)
85 {
86         if (creature_ptr->realm1 == 0) return;
87
88         char tmp[64];
89         if (creature_ptr->realm2)
90                 sprintf(tmp, "%s, %s", realm_names[creature_ptr->realm1], realm_names[creature_ptr->realm2]);
91         else
92                 strcpy(tmp, realm_names[creature_ptr->realm1]);
93
94         display_player_one_line(ENTRY_REALM, tmp, TERM_L_BLUE);
95 }
96
97
98 /*!
99  * @ brief 年齢、身長、体重、社会的地位を表示する
100  * @param creature_ptr プレーヤーへの参照ポインタ
101  * @return なし
102  * @details
103  * 日本語版では、身長はcmに、体重はkgに変更してある
104  */
105 static void display_phisique(player_type *creature_ptr)
106 {
107 #ifdef JP
108         display_player_one_line(ENTRY_AGE, format("%d才", (int)creature_ptr->age), TERM_L_BLUE);
109         display_player_one_line(ENTRY_HEIGHT, format("%dcm", (int)((creature_ptr->ht * 254) / 100)), TERM_L_BLUE);
110         display_player_one_line(ENTRY_WEIGHT, format("%dkg", (int)((creature_ptr->wt * 4536) / 10000)), TERM_L_BLUE);
111         display_player_one_line(ENTRY_SOCIAL, format("%d  ", (int)creature_ptr->sc), TERM_L_BLUE);
112 #else
113         display_player_one_line(ENTRY_AGE, format("%d", (int)creature_ptr->age), TERM_L_BLUE);
114         display_player_one_line(ENTRY_HEIGHT, format("%d", (int)creature_ptr->ht), TERM_L_BLUE);
115         display_player_one_line(ENTRY_WEIGHT, format("%d", (int)creature_ptr->wt), TERM_L_BLUE);
116         display_player_one_line(ENTRY_SOCIAL, format("%d", (int)creature_ptr->sc), TERM_L_BLUE);
117 #endif
118         display_player_one_line(ENTRY_ALIGN, format("%s", your_alignment(creature_ptr)), TERM_L_BLUE);
119 }
120
121
122 /*!
123  * @brief 能力値を (減少していたら色を変えて)表示する
124  * @param creature_ptr プレーヤーへの参照ポインタ
125  */
126 static void display_player_stats(player_type *creature_ptr)
127 {
128         char buf[80];
129         for (int i = 0; i < A_MAX; i++)
130         {
131                 if (creature_ptr->stat_cur[i] < creature_ptr->stat_max[i])
132                 {
133                         put_str(stat_names_reduced[i], 3 + i, 53);
134                         int value = creature_ptr->stat_use[i];
135                         cnv_stat(value, buf);
136                         c_put_str(TERM_YELLOW, buf, 3 + i, 60);
137                         value = creature_ptr->stat_top[i];
138                         cnv_stat(value, buf);
139                         c_put_str(TERM_L_GREEN, buf, 3 + i, 67);
140                 }
141                 else
142                 {
143                         put_str(stat_names[i], 3 + i, 53);
144                         cnv_stat(creature_ptr->stat_use[i], buf);
145                         c_put_str(TERM_L_GREEN, buf, 3 + i, 60);
146                 }
147
148                 if (creature_ptr->stat_max[i] == creature_ptr->stat_max_max[i])
149                         c_put_str(TERM_WHITE, "!", 3 + i, _(58, 58 - 2));
150         }
151 }
152
153
154 /*!
155  * @brief ゲームオーバーの原因を探る (生きていたら何もしない)
156  * @param creature_ptr プレーヤーへの参照ポインタ
157  * @param statmsg メッセージバッファ
158  * @param map_name マップ名へのコールバック
159  * @return 生きていたらFALSE、死んでいたらTRUE
160  */
161 static bool search_death_cause(player_type *creature_ptr, char *statmsg, map_name_pf map_name)
162 {
163         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
164         if (!creature_ptr->is_dead) return FALSE;
165
166         if (current_world_ptr->total_winner)
167         {
168                 sprintf(statmsg, _("…あなたは勝利の後%sした。", "...You %s after winning."),
169                         streq(creature_ptr->died_from, "Seppuku") ? _("切腹", "committed seppuku") : _("引退", "retired from the adventure"));
170
171                 return TRUE;
172         }
173         
174         if (!floor_ptr->dun_level)
175         {
176 #ifdef JP
177                 sprintf(statmsg, "…あなたは%sで%sに殺された。", (*map_name)(creature_ptr), creature_ptr->died_from);
178 #else
179                 sprintf(statmsg, "...You were killed by %s in %s.", creature_ptr->died_from, map_name(creature_ptr));
180 #endif
181                 return TRUE;
182         }
183         
184         if (floor_ptr->inside_quest && is_fixed_quest_idx(floor_ptr->inside_quest))
185         {
186                 /* Get the quest text */
187                 /* Bewere that INIT_ASSIGN resets the cur_num. */
188                 init_flags = INIT_NAME_ONLY;
189                 process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
190 #ifdef JP
191                 sprintf(statmsg, "…あなたは、クエスト「%s」で%sに殺された。", quest[floor_ptr->inside_quest].name, creature_ptr->died_from);
192 #else
193                 sprintf(statmsg, "...You were killed by %s in the quest '%s'.", creature_ptr->died_from, quest[floor_ptr->inside_quest].name);
194 #endif
195                 return TRUE;
196         }
197
198 #ifdef JP
199         sprintf(statmsg, "…あなたは、%sの%d階で%sに殺された。", (*map_name)(creature_ptr), (int)floor_ptr->dun_level, creature_ptr->died_from);
200 #else
201         sprintf(statmsg, "...You were killed by %s on level %d of %s.", creature_ptr->died_from, floor_ptr->dun_level, map_name(creature_ptr));
202 #endif
203
204         return TRUE;
205 }
206
207
208 /*!
209  * @brief クエストフロアで生きている場合、クエスト名をバッファに詰める
210  * @param creature_ptr プレーヤーへの参照ポインタ
211  * @param statmsg メッセージバッファ
212  * @return クエスト内であればTRUE、いなければFALSE
213  */
214 static bool decide_death_in_quest(player_type *creature_ptr, char *statmsg)
215 {
216         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
217         if (!floor_ptr->inside_quest || !is_fixed_quest_idx(floor_ptr->inside_quest))
218                 return FALSE;
219
220         for (int i = 0; i < 10; i++)
221                 quest_text[i][0] = '\0';
222
223         quest_text_line = 0;
224         init_flags = INIT_NAME_ONLY;
225         process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
226         sprintf(statmsg, _("…あなたは現在、 クエスト「%s」を遂行中だ。", "...Now, you are in the quest '%s'."), quest[floor_ptr->inside_quest].name);
227         return TRUE;
228 }
229
230
231 /*!
232  * @brief 現在いるフロアを、または死んでいたらどこでどう死んだかをバッファに詰める
233  * @param creature_ptr プレーヤーへの参照ポインタ
234  * @param statmsg メッセージバッファ
235  * @param map_name マップ名へのコールバック
236  * @return なし
237  */
238 static void decide_current_floor(player_type *creature_ptr, char *statmsg, map_name_pf map_name)
239 {
240         if (search_death_cause(creature_ptr, statmsg, map_name)) return;
241         if (!current_world_ptr->character_dungeon) return;
242
243         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
244         if (floor_ptr->dun_level == 0)
245         {
246                 sprintf(statmsg, _("…あなたは現在、 %s にいる。", "...Now, you are in %s."), map_name(creature_ptr));
247                 return;
248         }
249         
250         if (decide_death_in_quest(creature_ptr, statmsg)) return;
251
252 #ifdef JP
253         sprintf(statmsg, "…あなたは現在、 %s の %d 階で探索している。", map_name(creature_ptr), (int)floor_ptr->dun_level);
254 #else
255         sprintf(statmsg, "...Now, you are exploring level %d of %s.", (int)floor_ptr->dun_level, map_name(creature_ptr));
256 #endif
257 }
258
259
260 /*!
261  * @brief 今いる、または死亡した場所を表示する
262  * @param statmsg メッセージバッファ
263  * @return なし
264  */
265 static void display_current_floor(char *statmsg)
266 {
267         char temp[128];
268         roff_to_buf(statmsg, 60, temp, sizeof(temp));
269         char  *t;
270         t = temp;
271         for (int i = 0; i < 2; i++)
272         {
273                 if (t[0] == 0) return;
274
275                 put_str(t, i + 5 + 12, 10);
276                 t += strlen(t) + 1;
277         }
278 }
279
280
281 /*!
282  * @brief プレイヤーのステータス表示メイン処理
283  * Display the character on the screen (various modes)
284  * @param creature_ptr プレーヤーへの参照ポインタ
285  * @param mode 表示モードID
286  * @return なし
287  * @details
288  * <pre>
289  * The top one and bottom two lines are left blank.
290  * Mode 0 = standard display with skills
291  * Mode 1 = standard display with history
292  * Mode 2 = summary of various things
293  * Mode 3 = summary of various things (part 2)
294  * Mode 4 = mutations
295  * </pre>
296  */
297 void display_player(player_type *creature_ptr, int mode, map_name_pf map_name)
298 {
299         if ((creature_ptr->muta1 || creature_ptr->muta2 || creature_ptr->muta3) && display_mutations)
300                 mode = (mode % 5);
301         else
302                 mode = (mode % 4);
303
304         clear_from(0);
305         if (display_player_info(creature_ptr, mode)) return;
306
307         display_player_basic_info(creature_ptr);
308         display_magic_realms(creature_ptr);
309
310         if ((creature_ptr->pclass == CLASS_CHAOS_WARRIOR) || (creature_ptr->muta2 & MUT2_CHAOS_GIFT))
311                 display_player_one_line(ENTRY_PATRON, chaos_patrons[creature_ptr->chaos_patron], TERM_L_BLUE);
312
313         display_phisique(creature_ptr);
314         display_player_stats(creature_ptr);
315
316         if (mode == 0)
317         {
318                 display_player_middle(creature_ptr);
319                 display_player_various(creature_ptr);
320                 return;
321         }
322
323         char statmsg[1000];
324         put_str(_("(キャラクターの生い立ち)", "(Character Background)"), 11, 25);
325         for (int i = 0; i < 4; i++)
326                 put_str(creature_ptr->history[i], i + 12, 10);
327
328         *statmsg = '\0';
329         decide_current_floor(creature_ptr, statmsg, map_name);
330         if (!*statmsg) return;
331
332         display_current_floor(statmsg);
333 }
334
335
336 /*!
337  * todo y = 6、x = 0、mode = 0で固定。何とかする
338  * @brief プレイヤーの装備一覧をシンボルで並べる
339  * Equippy chars
340  * @param creature_ptr プレーヤーへの参照ポインタ
341  * @param y 表示するコンソールの行
342  * @param x 表示するコンソールの列
343  * @param mode オプション
344  * @return なし
345  */
346 void display_player_equippy(player_type *creature_ptr, TERM_LEN y, TERM_LEN x, BIT_FLAGS16 mode)
347 {
348         int max_i = (mode & DP_WP) ? INVEN_LARM + 1 : INVEN_TOTAL;
349         for (int i = INVEN_RARM; i < max_i; i++)
350         {
351                 object_type *o_ptr;
352                 o_ptr = &creature_ptr->inventory_list[i];
353
354                 TERM_COLOR a = object_attr(o_ptr);
355                 char c = object_char(o_ptr);
356
357                 if (!equippy_chars || !o_ptr->k_idx)
358                 {
359                         c = ' ';
360                         a = TERM_DARK;
361                 }
362
363                 Term_putch(x + i - INVEN_RARM, y, a, c);
364         }
365 }