OSDN Git Service

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