OSDN Git Service

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