OSDN Git Service

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