OSDN Git Service

[Refactor] #39962 display_player_middle() からdisplay_left_hand() を分離 / Separated displ...
[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 "term.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 "player-skill.h"
20 #include "player-effects.h"
21 #include "realm-song.h"
22 #include "object-hook.h"
23 #include "shoot.h"
24 #include "dungeon-file.h"
25 #include "objectkind.h"
26 #include "view/display-util.h"
27 #include "view/display-characteristic.h"
28 #include "view/display-player-stat-info.h"
29 #include "view/display-player-misc-info.h"
30
31 /*!
32  * @brief プレイヤーの打撃能力修正を表示する
33  * @param creature_ptr プレーヤーへの参照ポインタ
34  * @param hand 武器の装備部位ID
35  * @param hand_entry 項目ID
36  * @return なし
37  */
38 static void display_player_melee_bonus(player_type *creature_ptr, int hand, int hand_entry)
39 {
40         HIT_PROB show_tohit = creature_ptr->dis_to_h[hand];
41         HIT_POINT show_todam = creature_ptr->dis_to_d[hand];
42         object_type *o_ptr = &creature_ptr->inventory_list[INVEN_RARM + hand];
43
44         if (object_is_known(o_ptr)) show_tohit += o_ptr->to_h;
45         if (object_is_known(o_ptr)) show_todam += o_ptr->to_d;
46
47         show_tohit += creature_ptr->skill_thn / BTH_PLUS_ADJ;
48
49         char buf[160];
50         sprintf(buf, "(%+d,%+d)", (int)show_tohit, (int)show_todam);
51
52         if (!has_melee_weapon(creature_ptr, INVEN_RARM) && !has_melee_weapon(creature_ptr, INVEN_LARM))
53                 display_player_one_line(ENTRY_BARE_HAND, buf, TERM_L_BLUE);
54         else if (creature_ptr->ryoute)
55                 display_player_one_line(ENTRY_TWO_HANDS, buf, TERM_L_BLUE);
56         else
57                 display_player_one_line(hand_entry, buf, TERM_L_BLUE);
58 }
59
60
61 /*!
62  * @brief 右手に比べて左手の表示ルーチンが複雑なので分離
63  * @param creature_ptr プレーヤーへの参照ポインタ
64  * @return なし
65  */
66 static void display_left_hand(player_type *creature_ptr)
67 {
68         if (creature_ptr->hidarite)
69         {
70                 display_player_melee_bonus(creature_ptr, 1, left_hander ? ENTRY_RIGHT_HAND2 : ENTRY_LEFT_HAND2);
71                 return;
72         }
73         
74         if ((creature_ptr->pclass != CLASS_MONK) || ((empty_hands(creature_ptr, TRUE) & EMPTY_HAND_RARM) == 0))
75                 return;
76
77         if ((creature_ptr->special_defense & KAMAE_MASK) == 0)
78         {
79                 display_player_one_line(ENTRY_POSTURE, _("構えなし", "none"), TERM_YELLOW);
80                 return;
81         }
82
83         int kamae_num;
84         for (kamae_num = 0; kamae_num < MAX_KAMAE; kamae_num++)
85         {
86                 if ((creature_ptr->special_defense >> kamae_num) & KAMAE_GENBU)
87                         break;
88         }
89
90         if (kamae_num < MAX_KAMAE)
91         {
92                 display_player_one_line(ENTRY_POSTURE, format(_("%sの構え", "%s form"), kamae_shurui[kamae_num].desc), TERM_YELLOW);
93         }
94 }
95
96
97 /*!
98  * @brief プレイヤーステータス表示の中央部分を表示するサブルーチン
99  * @param creature_ptr プレーヤーへの参照ポインタ
100  * Prints the following information on the screen.
101  * @return なし
102  */
103 static void display_player_middle(player_type *creature_ptr)
104 {
105         if (creature_ptr->migite)
106         {
107                 display_player_melee_bonus(creature_ptr, 0, left_hander ? ENTRY_LEFT_HAND1 : ENTRY_RIGHT_HAND1);
108         }
109
110         display_left_hand(creature_ptr);
111         object_type *o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
112         HIT_PROB show_tohit = creature_ptr->dis_to_h_b;
113         HIT_POINT show_todam = 0;
114         if (object_is_known(o_ptr)) show_tohit += o_ptr->to_h;
115         if (object_is_known(o_ptr)) show_todam += o_ptr->to_d;
116
117         if ((o_ptr->sval == SV_LIGHT_XBOW) || (o_ptr->sval == SV_HEAVY_XBOW))
118                 show_tohit += creature_ptr->weapon_exp[0][o_ptr->sval] / 400;
119         else
120                 show_tohit += (creature_ptr->weapon_exp[0][o_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200;
121
122         show_tohit += creature_ptr->skill_thb / BTH_PLUS_ADJ;
123
124         display_player_one_line(ENTRY_SHOOT_HIT_DAM, format("(%+d,%+d)", show_tohit, show_todam), TERM_L_BLUE);
125         int tmul = 0;
126         if (creature_ptr->inventory_list[INVEN_BOW].k_idx)
127         {
128                 tmul = bow_tmul(creature_ptr->inventory_list[INVEN_BOW].sval);
129                 if (creature_ptr->xtra_might) tmul++;
130
131                 tmul = tmul * (100 + (int)(adj_str_td[creature_ptr->stat_ind[A_STR]]) - 128);
132         }
133
134         display_player_one_line(ENTRY_SHOOT_POWER, format("x%d.%02d", tmul / 100, tmul % 100), TERM_L_BLUE);
135         display_player_one_line(ENTRY_BASE_AC, format("[%d,%+d]", creature_ptr->dis_ac, creature_ptr->dis_to_a), TERM_L_BLUE);
136
137         int i = creature_ptr->pspeed - 110;
138         if (creature_ptr->action == ACTION_SEARCH) i += 10;
139
140         TERM_COLOR attr;
141         if (i > 0)
142         {
143                 if (!creature_ptr->riding)
144                         attr = TERM_L_GREEN;
145                 else
146                         attr = TERM_GREEN;
147         }
148         else if (i == 0)
149         {
150                 if (!creature_ptr->riding)
151                         attr = TERM_L_BLUE;
152                 else
153                         attr = TERM_GREEN;
154         }
155         else
156         {
157                 if (!creature_ptr->riding)
158                         attr = TERM_L_UMBER;
159                 else
160                         attr = TERM_RED;
161         }
162
163         int tmp_speed = 0;
164         if (!creature_ptr->riding)
165         {
166                 if (IS_FAST(creature_ptr)) tmp_speed += 10;
167                 if (creature_ptr->slow) tmp_speed -= 10;
168                 if (creature_ptr->lightspeed) tmp_speed = 99;
169         }
170         else
171         {
172                 if (MON_FAST(&creature_ptr->current_floor_ptr->m_list[creature_ptr->riding])) tmp_speed += 10;
173                 if (MON_SLOW(&creature_ptr->current_floor_ptr->m_list[creature_ptr->riding])) tmp_speed -= 10;
174         }
175
176         char buf[160];
177         if (tmp_speed)
178         {
179                 if (!creature_ptr->riding)
180                         sprintf(buf, "(%+d%+d)", i - tmp_speed, tmp_speed);
181                 else
182                         sprintf(buf, _("乗馬中 (%+d%+d)", "Riding (%+d%+d)"), i - tmp_speed, tmp_speed);
183
184                 if (tmp_speed > 0)
185                         attr = TERM_YELLOW;
186                 else
187                         attr = TERM_VIOLET;
188         }
189         else
190         {
191                 if (!creature_ptr->riding)
192                         sprintf(buf, "(%+d)", i);
193                 else
194                         sprintf(buf, _("乗馬中 (%+d)", "Riding (%+d)"), i);
195         }
196
197         display_player_one_line(ENTRY_SPEED, buf, attr);
198         display_player_one_line(ENTRY_LEVEL, format("%d", creature_ptr->lev), TERM_L_GREEN);
199
200         int e = (creature_ptr->prace == RACE_ANDROID) ? ENTRY_EXP_ANDR : ENTRY_CUR_EXP;
201         if (creature_ptr->exp >= creature_ptr->max_exp)
202                 display_player_one_line(e, format("%ld", creature_ptr->exp), TERM_L_GREEN);
203         else
204                 display_player_one_line(e, format("%ld", creature_ptr->exp), TERM_YELLOW);
205
206         if (creature_ptr->prace != RACE_ANDROID)
207                 display_player_one_line(ENTRY_MAX_EXP, format("%ld", creature_ptr->max_exp), TERM_L_GREEN);
208
209         e = (creature_ptr->prace == RACE_ANDROID) ? ENTRY_EXP_TO_ADV_ANDR : ENTRY_EXP_TO_ADV;
210
211         if (creature_ptr->lev >= PY_MAX_LEVEL)
212                 display_player_one_line(e, "*****", TERM_L_GREEN);
213         else if (creature_ptr->prace == RACE_ANDROID)
214                 display_player_one_line(e, format("%ld", (s32b)(player_exp_a[creature_ptr->lev - 1] * creature_ptr->expfact / 100L)), TERM_L_GREEN);
215         else
216                 display_player_one_line(e, format("%ld", (s32b)(player_exp[creature_ptr->lev - 1] * creature_ptr->expfact / 100L)), TERM_L_GREEN);
217
218         display_player_one_line(ENTRY_GOLD, format("%ld", creature_ptr->au), TERM_L_GREEN);
219
220         int day, hour, min;
221         extract_day_hour_min(creature_ptr, &day, &hour, &min);
222
223         if (day < MAX_DAYS)
224                 sprintf(buf, _("%d日目 %2d:%02d", "Day %d %2d:%02d"), day, hour, min);
225         else
226                 sprintf(buf, _("*****日目 %2d:%02d", "Day ***** %2d:%02d"), hour, min);
227
228         display_player_one_line(ENTRY_DAY, buf, TERM_L_GREEN);
229
230         if (creature_ptr->chp >= creature_ptr->mhp)
231                 display_player_one_line(ENTRY_HP, format("%4d/%4d", creature_ptr->chp, creature_ptr->mhp), TERM_L_GREEN);
232         else if (creature_ptr->chp > (creature_ptr->mhp * hitpoint_warn) / 10)
233                 display_player_one_line(ENTRY_HP, format("%4d/%4d", creature_ptr->chp, creature_ptr->mhp), TERM_YELLOW);
234         else
235                 display_player_one_line(ENTRY_HP, format("%4d/%4d", creature_ptr->chp, creature_ptr->mhp), TERM_RED);
236
237         if (creature_ptr->csp >= creature_ptr->msp)
238                 display_player_one_line(ENTRY_SP, format("%4d/%4d", creature_ptr->csp, creature_ptr->msp), TERM_L_GREEN);
239         else if (creature_ptr->csp > (creature_ptr->msp * mana_warn) / 10)
240                 display_player_one_line(ENTRY_SP, format("%4d/%4d", creature_ptr->csp, creature_ptr->msp), TERM_YELLOW);
241         else
242                 display_player_one_line(ENTRY_SP, format("%4d/%4d", creature_ptr->csp, creature_ptr->msp), TERM_RED);
243
244         u32b play_hour = current_world_ptr->play_time / (60 * 60);
245         u32b play_min = (current_world_ptr->play_time / 60) % 60;
246         u32b play_sec = current_world_ptr->play_time % 60;
247         display_player_one_line(ENTRY_PLAY_TIME, format("%.2lu:%.2lu:%.2lu", play_hour, play_min, play_sec), TERM_L_GREEN);
248 }
249
250
251 /*!
252  * @brief プレイヤーのステータス表示メイン処理
253  * Display the character on the screen (various modes)
254  * @param creature_ptr プレーヤーへの参照ポインタ
255  * @param mode 表示モードID
256  * @return なし
257  * @details
258  * <pre>
259  * The top one and bottom two lines are left blank.
260  * Mode 0 = standard display with skills
261  * Mode 1 = standard display with history
262  * Mode 2 = summary of various things
263  * Mode 3 = summary of various things (part 2)
264  * Mode 4 = mutations
265  * </pre>
266  */
267 void display_player(player_type *creature_ptr, int mode, map_name_pf map_name)
268 {
269         if ((creature_ptr->muta1 || creature_ptr->muta2 || creature_ptr->muta3) && display_mutations)
270                 mode = (mode % 5);
271         else
272                 mode = (mode % 4);
273
274         clear_from(0);
275
276         if (mode == 2)
277         {
278                 display_player_misc_info(creature_ptr);
279                 display_player_stat_info(creature_ptr);
280                 display_player_flag_info_1(creature_ptr, display_player_equippy);
281                 return;
282         }
283
284         if (mode == 3)
285         {
286                 display_player_flag_info_2(creature_ptr, display_player_equippy);
287                 return;
288         }
289
290         if (mode == 4)
291         {
292                 do_cmd_knowledge_mutations(creature_ptr);
293                 return;
294         }
295
296         char tmp[64];
297         if ((mode != 0) && (mode != 1)) return;
298
299         /* Name, Sex, Race, Class */
300 #ifdef JP
301         sprintf(tmp, "%s%s%s", ap_ptr->title, ap_ptr->no == 1 ? "の" : "", creature_ptr->name);
302 #else
303         sprintf(tmp, "%s %s", ap_ptr->title, creature_ptr->name);
304 #endif
305
306         display_player_one_line(ENTRY_NAME, tmp, TERM_L_BLUE);
307         display_player_one_line(ENTRY_SEX, sp_ptr->title, TERM_L_BLUE);
308         display_player_one_line(ENTRY_RACE, (creature_ptr->mimic_form ? mimic_info[creature_ptr->mimic_form].title : rp_ptr->title), TERM_L_BLUE);
309         display_player_one_line(ENTRY_CLASS, cp_ptr->title, TERM_L_BLUE);
310
311         if (creature_ptr->realm1)
312         {
313                 if (creature_ptr->realm2)
314                         sprintf(tmp, "%s, %s", realm_names[creature_ptr->realm1], realm_names[creature_ptr->realm2]);
315                 else
316                         strcpy(tmp, realm_names[creature_ptr->realm1]);
317                 display_player_one_line(ENTRY_REALM, tmp, TERM_L_BLUE);
318         }
319
320         if ((creature_ptr->pclass == CLASS_CHAOS_WARRIOR) || (creature_ptr->muta2 & MUT2_CHAOS_GIFT))
321                 display_player_one_line(ENTRY_PATRON, chaos_patrons[creature_ptr->chaos_patron], TERM_L_BLUE);
322
323         /* Age, Height, Weight, Social */
324         /* 身長はセンチメートルに、体重はキログラムに変更してあります */
325 #ifdef JP
326         display_player_one_line(ENTRY_AGE, format("%d才", (int)creature_ptr->age), TERM_L_BLUE);
327         display_player_one_line(ENTRY_HEIGHT, format("%dcm", (int)((creature_ptr->ht * 254) / 100)), TERM_L_BLUE);
328         display_player_one_line(ENTRY_WEIGHT, format("%dkg", (int)((creature_ptr->wt * 4536) / 10000)), TERM_L_BLUE);
329         display_player_one_line(ENTRY_SOCIAL, format("%d  ", (int)creature_ptr->sc), TERM_L_BLUE);
330 #else
331         display_player_one_line(ENTRY_AGE, format("%d", (int)creature_ptr->age), TERM_L_BLUE);
332         display_player_one_line(ENTRY_HEIGHT, format("%d", (int)creature_ptr->ht), TERM_L_BLUE);
333         display_player_one_line(ENTRY_WEIGHT, format("%d", (int)creature_ptr->wt), TERM_L_BLUE);
334         display_player_one_line(ENTRY_SOCIAL, format("%d", (int)creature_ptr->sc), TERM_L_BLUE);
335 #endif
336         display_player_one_line(ENTRY_ALIGN, format("%s", your_alignment(creature_ptr)), TERM_L_BLUE);
337
338         char buf[80];
339         for (int i = 0; i < A_MAX; i++)
340         {
341                 if (creature_ptr->stat_cur[i] < creature_ptr->stat_max[i])
342                 {
343                         put_str(stat_names_reduced[i], 3 + i, 53);
344                         int value = creature_ptr->stat_use[i];
345                         cnv_stat(value, buf);
346                         c_put_str(TERM_YELLOW, buf, 3 + i, 60);
347                         value = creature_ptr->stat_top[i];
348                         cnv_stat(value, buf);
349                         c_put_str(TERM_L_GREEN, buf, 3 + i, 67);
350                 }
351                 else
352                 {
353                         put_str(stat_names[i], 3 + i, 53);
354                         cnv_stat(creature_ptr->stat_use[i], buf);
355                         c_put_str(TERM_L_GREEN, buf, 3 + i, 60);
356                 }
357
358                 if (creature_ptr->stat_max[i] == creature_ptr->stat_max_max[i])
359                 {
360                         c_put_str(TERM_WHITE, "!", 3 + i, _(58, 58 - 2));
361                 }
362         }
363
364         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
365         if (mode == 0)
366         {
367                 display_player_middle(creature_ptr);
368                 display_player_various(creature_ptr);
369                 return;
370         }
371
372         char statmsg[1000];
373         put_str(_("(キャラクターの生い立ち)", "(Character Background)"), 11, 25);
374
375         for (int i = 0; i < 4; i++)
376         {
377                 put_str(creature_ptr->history[i], i + 12, 10);
378         }
379
380         *statmsg = '\0';
381
382         if (creature_ptr->is_dead)
383         {
384                 if (current_world_ptr->total_winner)
385                 {
386 #ifdef JP
387                         sprintf(statmsg, "…あなたは勝利の後%sした。", streq(creature_ptr->died_from, "Seppuku") ? "切腹" : "引退");
388 #else
389                         sprintf(statmsg, "...You %s after winning.", streq(creature_ptr->died_from, "Seppuku") ? "committed seppuku" : "retired from the adventure");
390 #endif
391                 }
392                 else if (!floor_ptr->dun_level)
393                 {
394 #ifdef JP
395                         sprintf(statmsg, "…あなたは%sで%sに殺された。", (*map_name)(creature_ptr), creature_ptr->died_from);
396 #else
397                         sprintf(statmsg, "...You were killed by %s in %s.", creature_ptr->died_from, map_name(creature_ptr));
398 #endif
399                 }
400                 else if (floor_ptr->inside_quest && is_fixed_quest_idx(floor_ptr->inside_quest))
401                 {
402                         /* Get the quest text */
403                         /* Bewere that INIT_ASSIGN resets the cur_num. */
404                         init_flags = INIT_NAME_ONLY;
405
406                         process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
407
408 #ifdef JP
409                         sprintf(statmsg, "…あなたは、クエスト「%s」で%sに殺された。", quest[floor_ptr->inside_quest].name, creature_ptr->died_from);
410 #else
411                         sprintf(statmsg, "...You were killed by %s in the quest '%s'.", creature_ptr->died_from, quest[floor_ptr->inside_quest].name);
412 #endif
413                 }
414                 else
415                 {
416 #ifdef JP
417                         sprintf(statmsg, "…あなたは、%sの%d階で%sに殺された。", (*map_name)(creature_ptr), (int)floor_ptr->dun_level, creature_ptr->died_from);
418 #else
419                         sprintf(statmsg, "...You were killed by %s on level %d of %s.", creature_ptr->died_from, floor_ptr->dun_level, map_name(creature_ptr));
420 #endif
421                 }
422         }
423         else if (current_world_ptr->character_dungeon)
424         {
425                 if (!floor_ptr->dun_level)
426                 {
427                         sprintf(statmsg, _("…あなたは現在、 %s にいる。", "...Now, you are in %s."), map_name(creature_ptr));
428                 }
429                 else if (floor_ptr->inside_quest && is_fixed_quest_idx(floor_ptr->inside_quest))
430                 {
431                         /* Clear the text */
432                         /* Must be done before doing INIT_SHOW_TEXT */
433                         for (int i = 0; i < 10; i++)
434                         {
435                                 quest_text[i][0] = '\0';
436                         }
437
438                         quest_text_line = 0;
439                         init_flags = INIT_NAME_ONLY;
440                         process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
441                         sprintf(statmsg, _("…あなたは現在、 クエスト「%s」を遂行中だ。", "...Now, you are in the quest '%s'."), quest[floor_ptr->inside_quest].name);
442                 }
443                 else
444                 {
445 #ifdef JP
446                         sprintf(statmsg, "…あなたは現在、 %s の %d 階で探索している。", map_name(creature_ptr), (int)floor_ptr->dun_level);
447 #else
448                         sprintf(statmsg, "...Now, you are exploring level %d of %s.", floor_ptr->dun_level, map_name(creature_ptr));
449 #endif
450                 }
451         }
452
453         if (!*statmsg) return;
454
455         char temp[64 * 2];
456         roff_to_buf(statmsg, 60, temp, sizeof(temp));
457         char  *t;
458         t = temp;
459         for (int i = 0; i < 2; i++)
460         {
461                 if (t[0] == 0) return;
462
463                 put_str(t, i + 5 + 12, 10);
464                 t += strlen(t) + 1;
465         }
466 }
467
468
469 /*!
470  * todo y = 6、x = 0、mode = 0で固定。何とかする
471  * @brief プレイヤーの装備一覧をシンボルで並べる
472  * Equippy chars
473  * @param creature_ptr プレーヤーへの参照ポインタ
474  * @param y 表示するコンソールの行
475  * @param x 表示するコンソールの列
476  * @param mode オプション
477  * @return なし
478  */
479 void display_player_equippy(player_type *creature_ptr, TERM_LEN y, TERM_LEN x, BIT_FLAGS16 mode)
480 {
481         int max_i = (mode & DP_WP) ? INVEN_LARM + 1 : INVEN_TOTAL;
482         for (int i = INVEN_RARM; i < max_i; i++)
483         {
484                 object_type *o_ptr;
485                 o_ptr = &creature_ptr->inventory_list[i];
486
487                 TERM_COLOR a = object_attr(o_ptr);
488                 char c = object_char(o_ptr);
489
490                 if (!equippy_chars || !o_ptr->k_idx)
491                 {
492                         c = ' ';
493                         a = TERM_DARK;
494                 }
495
496                 Term_putch(x + i - INVEN_RARM, y, a, c);
497         }
498 }