OSDN Git Service

[Refactor] #39962 display_player() からdisplay_player_info() を分離 / Separated display_pl...
[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 "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  * Display the character on the screen (various modes)
62  * @param creature_ptr プレーヤーへの参照ポインタ
63  * @param mode 表示モードID
64  * @return なし
65  * @details
66  * <pre>
67  * The top one and bottom two lines are left blank.
68  * Mode 0 = standard display with skills
69  * Mode 1 = standard display with history
70  * Mode 2 = summary of various things
71  * Mode 3 = summary of various things (part 2)
72  * Mode 4 = mutations
73  * </pre>
74  */
75 void display_player(player_type *creature_ptr, int mode, map_name_pf map_name)
76 {
77         if ((creature_ptr->muta1 || creature_ptr->muta2 || creature_ptr->muta3) && display_mutations)
78                 mode = (mode % 5);
79         else
80                 mode = (mode % 4);
81
82         clear_from(0);
83         if (display_player_info(creature_ptr, mode)) return;
84
85         /* Name, Sex, Race, Class */
86         char tmp[64];
87 #ifdef JP
88         sprintf(tmp, "%s%s%s", ap_ptr->title, ap_ptr->no == 1 ? "の" : "", creature_ptr->name);
89 #else
90         sprintf(tmp, "%s %s", ap_ptr->title, creature_ptr->name);
91 #endif
92
93         display_player_one_line(ENTRY_NAME, tmp, TERM_L_BLUE);
94         display_player_one_line(ENTRY_SEX, sp_ptr->title, TERM_L_BLUE);
95         display_player_one_line(ENTRY_RACE, (creature_ptr->mimic_form ? mimic_info[creature_ptr->mimic_form].title : rp_ptr->title), TERM_L_BLUE);
96         display_player_one_line(ENTRY_CLASS, cp_ptr->title, TERM_L_BLUE);
97
98         if (creature_ptr->realm1)
99         {
100                 if (creature_ptr->realm2)
101                         sprintf(tmp, "%s, %s", realm_names[creature_ptr->realm1], realm_names[creature_ptr->realm2]);
102                 else
103                         strcpy(tmp, realm_names[creature_ptr->realm1]);
104                 display_player_one_line(ENTRY_REALM, tmp, TERM_L_BLUE);
105         }
106
107         if ((creature_ptr->pclass == CLASS_CHAOS_WARRIOR) || (creature_ptr->muta2 & MUT2_CHAOS_GIFT))
108                 display_player_one_line(ENTRY_PATRON, chaos_patrons[creature_ptr->chaos_patron], TERM_L_BLUE);
109
110         /* Age, Height, Weight, Social */
111         /* 身長はセンチメートルに、体重はキログラムに変更してあります */
112 #ifdef JP
113         display_player_one_line(ENTRY_AGE, format("%d才", (int)creature_ptr->age), TERM_L_BLUE);
114         display_player_one_line(ENTRY_HEIGHT, format("%dcm", (int)((creature_ptr->ht * 254) / 100)), TERM_L_BLUE);
115         display_player_one_line(ENTRY_WEIGHT, format("%dkg", (int)((creature_ptr->wt * 4536) / 10000)), TERM_L_BLUE);
116         display_player_one_line(ENTRY_SOCIAL, format("%d  ", (int)creature_ptr->sc), TERM_L_BLUE);
117 #else
118         display_player_one_line(ENTRY_AGE, format("%d", (int)creature_ptr->age), TERM_L_BLUE);
119         display_player_one_line(ENTRY_HEIGHT, format("%d", (int)creature_ptr->ht), TERM_L_BLUE);
120         display_player_one_line(ENTRY_WEIGHT, format("%d", (int)creature_ptr->wt), TERM_L_BLUE);
121         display_player_one_line(ENTRY_SOCIAL, format("%d", (int)creature_ptr->sc), TERM_L_BLUE);
122 #endif
123         display_player_one_line(ENTRY_ALIGN, format("%s", your_alignment(creature_ptr)), TERM_L_BLUE);
124
125         char buf[80];
126         for (int i = 0; i < A_MAX; i++)
127         {
128                 if (creature_ptr->stat_cur[i] < creature_ptr->stat_max[i])
129                 {
130                         put_str(stat_names_reduced[i], 3 + i, 53);
131                         int value = creature_ptr->stat_use[i];
132                         cnv_stat(value, buf);
133                         c_put_str(TERM_YELLOW, buf, 3 + i, 60);
134                         value = creature_ptr->stat_top[i];
135                         cnv_stat(value, buf);
136                         c_put_str(TERM_L_GREEN, buf, 3 + i, 67);
137                 }
138                 else
139                 {
140                         put_str(stat_names[i], 3 + i, 53);
141                         cnv_stat(creature_ptr->stat_use[i], buf);
142                         c_put_str(TERM_L_GREEN, buf, 3 + i, 60);
143                 }
144
145                 if (creature_ptr->stat_max[i] == creature_ptr->stat_max_max[i])
146                 {
147                         c_put_str(TERM_WHITE, "!", 3 + i, _(58, 58 - 2));
148                 }
149         }
150
151         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
152         if (mode == 0)
153         {
154                 display_player_middle(creature_ptr);
155                 display_player_various(creature_ptr);
156                 return;
157         }
158
159         char statmsg[1000];
160         put_str(_("(キャラクターの生い立ち)", "(Character Background)"), 11, 25);
161
162         for (int i = 0; i < 4; i++)
163         {
164                 put_str(creature_ptr->history[i], i + 12, 10);
165         }
166
167         *statmsg = '\0';
168
169         if (creature_ptr->is_dead)
170         {
171                 if (current_world_ptr->total_winner)
172                 {
173 #ifdef JP
174                         sprintf(statmsg, "…あなたは勝利の後%sした。", streq(creature_ptr->died_from, "Seppuku") ? "切腹" : "引退");
175 #else
176                         sprintf(statmsg, "...You %s after winning.", streq(creature_ptr->died_from, "Seppuku") ? "committed seppuku" : "retired from the adventure");
177 #endif
178                 }
179                 else if (!floor_ptr->dun_level)
180                 {
181 #ifdef JP
182                         sprintf(statmsg, "…あなたは%sで%sに殺された。", (*map_name)(creature_ptr), creature_ptr->died_from);
183 #else
184                         sprintf(statmsg, "...You were killed by %s in %s.", creature_ptr->died_from, map_name(creature_ptr));
185 #endif
186                 }
187                 else if (floor_ptr->inside_quest && is_fixed_quest_idx(floor_ptr->inside_quest))
188                 {
189                         /* Get the quest text */
190                         /* Bewere that INIT_ASSIGN resets the cur_num. */
191                         init_flags = INIT_NAME_ONLY;
192
193                         process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
194
195 #ifdef JP
196                         sprintf(statmsg, "…あなたは、クエスト「%s」で%sに殺された。", quest[floor_ptr->inside_quest].name, creature_ptr->died_from);
197 #else
198                         sprintf(statmsg, "...You were killed by %s in the quest '%s'.", creature_ptr->died_from, quest[floor_ptr->inside_quest].name);
199 #endif
200                 }
201                 else
202                 {
203 #ifdef JP
204                         sprintf(statmsg, "…あなたは、%sの%d階で%sに殺された。", (*map_name)(creature_ptr), (int)floor_ptr->dun_level, creature_ptr->died_from);
205 #else
206                         sprintf(statmsg, "...You were killed by %s on level %d of %s.", creature_ptr->died_from, floor_ptr->dun_level, map_name(creature_ptr));
207 #endif
208                 }
209         }
210         else if (current_world_ptr->character_dungeon)
211         {
212                 if (!floor_ptr->dun_level)
213                 {
214                         sprintf(statmsg, _("…あなたは現在、 %s にいる。", "...Now, you are in %s."), map_name(creature_ptr));
215                 }
216                 else if (floor_ptr->inside_quest && is_fixed_quest_idx(floor_ptr->inside_quest))
217                 {
218                         /* Clear the text */
219                         /* Must be done before doing INIT_SHOW_TEXT */
220                         for (int i = 0; i < 10; i++)
221                         {
222                                 quest_text[i][0] = '\0';
223                         }
224
225                         quest_text_line = 0;
226                         init_flags = INIT_NAME_ONLY;
227                         process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
228                         sprintf(statmsg, _("…あなたは現在、 クエスト「%s」を遂行中だ。", "...Now, you are in the quest '%s'."), quest[floor_ptr->inside_quest].name);
229                 }
230                 else
231                 {
232 #ifdef JP
233                         sprintf(statmsg, "…あなたは現在、 %s の %d 階で探索している。", map_name(creature_ptr), (int)floor_ptr->dun_level);
234 #else
235                         sprintf(statmsg, "...Now, you are exploring level %d of %s.", floor_ptr->dun_level, map_name(creature_ptr));
236 #endif
237                 }
238         }
239
240         if (!*statmsg) return;
241
242         char temp[64 * 2];
243         roff_to_buf(statmsg, 60, temp, sizeof(temp));
244         char  *t;
245         t = temp;
246         for (int i = 0; i < 2; i++)
247         {
248                 if (t[0] == 0) return;
249
250                 put_str(t, i + 5 + 12, 10);
251                 t += strlen(t) + 1;
252         }
253 }
254
255
256 /*!
257  * todo y = 6、x = 0、mode = 0で固定。何とかする
258  * @brief プレイヤーの装備一覧をシンボルで並べる
259  * Equippy chars
260  * @param creature_ptr プレーヤーへの参照ポインタ
261  * @param y 表示するコンソールの行
262  * @param x 表示するコンソールの列
263  * @param mode オプション
264  * @return なし
265  */
266 void display_player_equippy(player_type *creature_ptr, TERM_LEN y, TERM_LEN x, BIT_FLAGS16 mode)
267 {
268         int max_i = (mode & DP_WP) ? INVEN_LARM + 1 : INVEN_TOTAL;
269         for (int i = INVEN_RARM; i < max_i; i++)
270         {
271                 object_type *o_ptr;
272                 o_ptr = &creature_ptr->inventory_list[i];
273
274                 TERM_COLOR a = object_attr(o_ptr);
275                 char c = object_char(o_ptr);
276
277                 if (!equippy_chars || !o_ptr->k_idx)
278                 {
279                         c = ' ';
280                         a = TERM_DARK;
281                 }
282
283                 Term_putch(x + i - INVEN_RARM, y, a, c);
284         }
285 }