OSDN Git Service

[Refactor] #40457 Moved object boosting/cursing/ego/artifact-related files from objec...
[hengband/hengband.git] / src / view / display-player-middle.c
1 #include "view/display-player-middle.h"
2 #include "floor/floor.h"
3 #include "object/object-appraiser.h"
4 #include "object-enchant/special-object-flags.h"
5 #include "sv-definition/sv-bow-types.h"
6 #include "player/player-effects.h"
7 #include "player/player-races-table.h"
8 #include "player/player-skill.h"
9 #include "realm/realm-song.h"
10 #include "shoot.h"
11 #include "term/gameterm.h"
12 #include "view/display-util.h"
13 #include "view/status-first-page.h"
14 #include "world/world.h"
15
16 /*!
17  * @brief プレイヤーの打撃能力修正を表示する
18  * @param creature_ptr プレーヤーへの参照ポインタ
19  * @param hand 武器の装備部位ID
20  * @param hand_entry 項目ID
21  * @return なし
22  */
23 static void display_player_melee_bonus(player_type *creature_ptr, int hand, int hand_entry)
24 {
25         HIT_PROB show_tohit = creature_ptr->dis_to_h[hand];
26         HIT_POINT show_todam = creature_ptr->dis_to_d[hand];
27         object_type *o_ptr = &creature_ptr->inventory_list[INVEN_RARM + hand];
28
29         if (object_is_known(o_ptr)) show_tohit += o_ptr->to_h;
30         if (object_is_known(o_ptr)) show_todam += o_ptr->to_d;
31
32         show_tohit += creature_ptr->skill_thn / BTH_PLUS_ADJ;
33
34         char buf[160];
35         sprintf(buf, "(%+d,%+d)", (int)show_tohit, (int)show_todam);
36
37         if (!has_melee_weapon(creature_ptr, INVEN_RARM) && !has_melee_weapon(creature_ptr, INVEN_LARM))
38                 display_player_one_line(ENTRY_BARE_HAND, buf, TERM_L_BLUE);
39         else if (creature_ptr->ryoute)
40                 display_player_one_line(ENTRY_TWO_HANDS, buf, TERM_L_BLUE);
41         else
42                 display_player_one_line(hand_entry, buf, TERM_L_BLUE);
43 }
44
45
46 /*!
47  * @brief 右手に比べて左手の表示ルーチンが複雑なので分離
48  * @param creature_ptr プレーヤーへの参照ポインタ
49  * @return なし
50  */
51 static void display_left_hand(player_type *creature_ptr)
52 {
53         if (creature_ptr->hidarite)
54         {
55                 display_player_melee_bonus(creature_ptr, 1, left_hander ? ENTRY_RIGHT_HAND2 : ENTRY_LEFT_HAND2);
56                 return;
57         }
58
59         if ((creature_ptr->pclass != CLASS_MONK) || ((empty_hands(creature_ptr, TRUE) & EMPTY_HAND_RARM) == 0))
60                 return;
61
62         if ((creature_ptr->special_defense & KAMAE_MASK) == 0)
63         {
64                 display_player_one_line(ENTRY_POSTURE, _("構えなし", "none"), TERM_YELLOW);
65                 return;
66         }
67
68         int kamae_num;
69         for (kamae_num = 0; kamae_num < MAX_KAMAE; kamae_num++)
70         {
71                 if ((creature_ptr->special_defense >> kamae_num) & KAMAE_GENBU)
72                         break;
73         }
74
75         if (kamae_num < MAX_KAMAE)
76         {
77                 display_player_one_line(ENTRY_POSTURE, format(_("%sの構え", "%s form"), kamae_shurui[kamae_num].desc), TERM_YELLOW);
78         }
79 }
80
81
82 /*!
83  * @brief 武器による命中率とダメージの補正を表示する
84  * @param creature_ptr プレーヤーへの参照ポインタ
85  * @return なし
86  */
87 static void display_hit_damage(player_type *creature_ptr)
88 {
89         object_type *o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
90         HIT_PROB show_tohit = creature_ptr->dis_to_h_b;
91         HIT_POINT show_todam = 0;
92         if (object_is_known(o_ptr)) show_tohit += o_ptr->to_h;
93         if (object_is_known(o_ptr)) show_todam += o_ptr->to_d;
94
95         if ((o_ptr->sval == SV_LIGHT_XBOW) || (o_ptr->sval == SV_HEAVY_XBOW))
96                 show_tohit += creature_ptr->weapon_exp[0][o_ptr->sval] / 400;
97         else
98                 show_tohit += (creature_ptr->weapon_exp[0][o_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200;
99
100         show_tohit += creature_ptr->skill_thb / BTH_PLUS_ADJ;
101
102         display_player_one_line(ENTRY_SHOOT_HIT_DAM, format("(%+d,%+d)", show_tohit, show_todam), TERM_L_BLUE);
103 }
104
105
106 /*!
107  * @brief 射撃武器倍率を表示する
108  * @param creature_ptr プレーヤーへの参照ポインタ
109  * @return なし
110  */
111 static void display_shoot_magnification(player_type *creature_ptr)
112 {
113         int tmul = 0;
114         if (creature_ptr->inventory_list[INVEN_BOW].k_idx)
115         {
116                 tmul = bow_tmul(creature_ptr->inventory_list[INVEN_BOW].sval);
117                 if (creature_ptr->xtra_might) tmul++;
118
119                 tmul = tmul * (100 + (int)(adj_str_td[creature_ptr->stat_ind[A_STR]]) - 128);
120         }
121
122         display_player_one_line(ENTRY_SHOOT_POWER, format("x%d.%02d", tmul / 100, tmul % 100), TERM_L_BLUE);
123 }
124
125
126 /*!
127  * @brief プレーヤーの速度から表示色を決める
128  * @param creature_ptr プレーヤーへの参照ポインタ
129  * @param base_speed プレーヤーの速度
130  */
131 static TERM_COLOR decide_speed_color(player_type *creature_ptr, const int base_speed)
132 {
133         TERM_COLOR attr;
134         if (base_speed > 0)
135         {
136                 if (!creature_ptr->riding)
137                         attr = TERM_L_GREEN;
138                 else
139                         attr = TERM_GREEN;
140         }
141         else if (base_speed == 0)
142         {
143                 if (!creature_ptr->riding)
144                         attr = TERM_L_BLUE;
145                 else
146                         attr = TERM_GREEN;
147         }
148         else
149         {
150                 if (!creature_ptr->riding)
151                         attr = TERM_L_UMBER;
152                 else
153                         attr = TERM_RED;
154         }
155
156         return attr;
157 }
158
159
160 /*!
161  * @brief 何らかの効果による一時的な速度変化を計算する
162  * @param creature_ptr プレーヤーへの参照ポインタ
163  * @return プレーヤーの速度
164  */
165 static int calc_temporary_speed(player_type *creature_ptr)
166 {
167         int tmp_speed = 0;
168         if (!creature_ptr->riding)
169         {
170                 if (IS_FAST(creature_ptr)) tmp_speed += 10;
171                 if (creature_ptr->slow) tmp_speed -= 10;
172                 if (creature_ptr->lightspeed) tmp_speed = 99;
173         }
174         else
175         {
176                 if (MON_FAST(&creature_ptr->current_floor_ptr->m_list[creature_ptr->riding])) tmp_speed += 10;
177                 if (MON_SLOW(&creature_ptr->current_floor_ptr->m_list[creature_ptr->riding])) tmp_speed -= 10;
178         }
179
180         return tmp_speed;
181 }
182
183
184 /*!
185  * @brief プレーヤーの最終的な速度を表示する
186  * @param creature_ptr プレーヤーへの参照ポインタ
187  * @param attr 表示色
188  * @param base_speed プレーヤーの素の速度
189  * @param tmp_speed アイテム等で一時的に変化した速度量
190  * @return なし
191  */
192 static void display_player_speed(player_type *creature_ptr, TERM_COLOR attr, int base_speed, int tmp_speed)
193 {
194         char buf[160];
195         if (tmp_speed)
196         {
197                 if (!creature_ptr->riding)
198                         sprintf(buf, "(%+d%+d)", base_speed - tmp_speed, tmp_speed);
199                 else
200                         sprintf(buf, _("乗馬中 (%+d%+d)", "Riding (%+d%+d)"), base_speed - tmp_speed, tmp_speed);
201
202                 if (tmp_speed > 0)
203                         attr = TERM_YELLOW;
204                 else
205                         attr = TERM_VIOLET;
206         }
207         else
208         {
209                 if (!creature_ptr->riding)
210                         sprintf(buf, "(%+d)", base_speed);
211                 else
212                         sprintf(buf, _("乗馬中 (%+d)", "Riding (%+d)"), base_speed);
213         }
214
215         display_player_one_line(ENTRY_SPEED, buf, attr);
216         display_player_one_line(ENTRY_LEVEL, format("%d", creature_ptr->lev), TERM_L_GREEN);
217 }
218
219
220 /*!
221  * @brief プレーヤーの現在経験値・最大経験値・次のレベルまでに必要な経験値を表示する
222  * @param creature_ptr プレーヤーへの参照ポインタ
223  * @return なし
224  */
225 static void display_player_exp(player_type *creature_ptr)
226 {
227         int e = (creature_ptr->prace == RACE_ANDROID) ? ENTRY_EXP_ANDR : ENTRY_CUR_EXP;
228         if (creature_ptr->exp >= creature_ptr->max_exp)
229                 display_player_one_line(e, format("%ld", creature_ptr->exp), TERM_L_GREEN);
230         else
231                 display_player_one_line(e, format("%ld", creature_ptr->exp), TERM_YELLOW);
232
233         if (creature_ptr->prace != RACE_ANDROID)
234                 display_player_one_line(ENTRY_MAX_EXP, format("%ld", creature_ptr->max_exp), TERM_L_GREEN);
235
236         e = (creature_ptr->prace == RACE_ANDROID) ? ENTRY_EXP_TO_ADV_ANDR : ENTRY_EXP_TO_ADV;
237
238         if (creature_ptr->lev >= PY_MAX_LEVEL)
239                 display_player_one_line(e, "*****", TERM_L_GREEN);
240         else if (creature_ptr->prace == RACE_ANDROID)
241                 display_player_one_line(e, format("%ld", (s32b)(player_exp_a[creature_ptr->lev - 1] * creature_ptr->expfact / 100L)), TERM_L_GREEN);
242         else
243                 display_player_one_line(e, format("%ld", (s32b)(player_exp[creature_ptr->lev - 1] * creature_ptr->expfact / 100L)), TERM_L_GREEN);
244 }
245
246
247 /*!
248  * @brief ゲーム内の経過時間を表示する
249  * @param creature_ptr プレーヤーへの参照ポインタ
250  * @return なし
251  */
252 static void display_playtime_in_game(player_type *creature_ptr)
253 {
254         int day, hour, min;
255         extract_day_hour_min(creature_ptr, &day, &hour, &min);
256
257         char buf[160];
258         if (day < MAX_DAYS)
259                 sprintf(buf, _("%d日目 %2d:%02d", "Day %d %2d:%02d"), day, hour, min);
260         else
261                 sprintf(buf, _("*****日目 %2d:%02d", "Day ***** %2d:%02d"), hour, min);
262
263         display_player_one_line(ENTRY_DAY, buf, TERM_L_GREEN);
264
265         if (creature_ptr->chp >= creature_ptr->mhp)
266                 display_player_one_line(ENTRY_HP, format("%4d/%4d", creature_ptr->chp, creature_ptr->mhp), TERM_L_GREEN);
267         else if (creature_ptr->chp > (creature_ptr->mhp * hitpoint_warn) / 10)
268                 display_player_one_line(ENTRY_HP, format("%4d/%4d", creature_ptr->chp, creature_ptr->mhp), TERM_YELLOW);
269         else
270                 display_player_one_line(ENTRY_HP, format("%4d/%4d", creature_ptr->chp, creature_ptr->mhp), TERM_RED);
271
272         if (creature_ptr->csp >= creature_ptr->msp)
273                 display_player_one_line(ENTRY_SP, format("%4d/%4d", creature_ptr->csp, creature_ptr->msp), TERM_L_GREEN);
274         else if (creature_ptr->csp > (creature_ptr->msp * mana_warn) / 10)
275                 display_player_one_line(ENTRY_SP, format("%4d/%4d", creature_ptr->csp, creature_ptr->msp), TERM_YELLOW);
276         else
277                 display_player_one_line(ENTRY_SP, format("%4d/%4d", creature_ptr->csp, creature_ptr->msp), TERM_RED);
278 }
279
280
281 /*!
282  * @brief 現実世界におけるプレイ時間を表示する
283  * @param なし
284  * @param なし
285  */
286 static void display_real_playtime(void)
287 {
288         u32b play_hour = current_world_ptr->play_time / (60 * 60);
289         u32b play_min = (current_world_ptr->play_time / 60) % 60;
290         u32b play_sec = current_world_ptr->play_time % 60;
291         display_player_one_line(ENTRY_PLAY_TIME, format("%.2lu:%.2lu:%.2lu", play_hour, play_min, play_sec), TERM_L_GREEN);
292 }
293
294
295 /*!
296  * @brief プレイヤーステータス表示の中央部分を表示するサブルーチン
297  * @param creature_ptr プレーヤーへの参照ポインタ
298  * Prints the following information on the screen.
299  * @return なし
300  */
301 void display_player_middle(player_type *creature_ptr)
302 {
303         if (creature_ptr->migite)
304                 display_player_melee_bonus(creature_ptr, 0, left_hander ? ENTRY_LEFT_HAND1 : ENTRY_RIGHT_HAND1);
305
306         display_left_hand(creature_ptr);
307         display_hit_damage(creature_ptr);
308         display_shoot_magnification(creature_ptr);
309         display_player_one_line(ENTRY_BASE_AC, format("[%d,%+d]", creature_ptr->dis_ac, creature_ptr->dis_to_a), TERM_L_BLUE);
310
311         int base_speed = creature_ptr->pspeed - 110;
312         if (creature_ptr->action == ACTION_SEARCH) base_speed += 10;
313
314         TERM_COLOR attr = decide_speed_color(creature_ptr, base_speed);
315         int tmp_speed = calc_temporary_speed(creature_ptr);
316         display_player_speed(creature_ptr, attr, base_speed, tmp_speed);
317         display_player_exp(creature_ptr);
318         display_player_one_line(ENTRY_GOLD, format("%ld", creature_ptr->au), TERM_L_GREEN);
319         display_playtime_in_game(creature_ptr);
320         display_real_playtime();
321 }