OSDN Git Service

[Refactor] #40521 Moved toggle_inventory_equipment() from player-inventory.c/h to...
[hengband/hengband.git] / src / view / status-first-page.c
1 /*!
2  * @file status-first-page.c
3  * @brief キャラ基本情報及び技能値の表示
4  * @date 2020/02/23
5  * @author Hourier
6  */
7
8 #include "view/status-first-page.h"
9 #include "art-definition/art-bow-types.h"
10 #include "art-definition/art-sword-types.h"
11 #include "combat/attack-power-table.h"
12 #include "combat/shoot.h"
13 #include "display-util.h"
14 #include "game-option/text-display-options.h"
15 #include "object-enchant/special-object-flags.h"
16 #include "object-enchant/tr-types.h"
17 #include "object/object-flags.h"
18 #include "perception/object-perception.h"
19 #include "player/special-defense-types.h"
20 #include "sv-definition/sv-weapon-types.h"
21 #include "term/term-color-types.h"
22 #include "util/bit-flags-calculator.h"
23
24 static TERM_COLOR likert_color = TERM_WHITE;
25
26 /*!
27  * @brief 
28  * @param creature_ptr プレーヤーへの参照ポインタ
29  * @param o_ptr 装備中の弓への参照ポインタ
30  * @param shots 射撃回数
31  * @param shot_frac 射撃速度
32  * @return なし
33  */
34 static void calc_shot_params(player_type *creature_ptr, object_type *o_ptr, int *shots, int *shot_frac)
35 {
36         if (o_ptr->k_idx == 0) return;
37
38         ENERGY energy_fire = bow_energy(o_ptr->sval);
39         *shots = creature_ptr->num_fire * 100;
40         *shot_frac = ((*shots) * 100 / energy_fire) % 100;
41         *shots = (*shots) / energy_fire;
42         if (o_ptr->name1 != ART_CRIMSON) return;
43
44         *shots = 1;
45         *shot_frac = 0;
46         if (creature_ptr->pclass != CLASS_ARCHER) return;
47
48         if (creature_ptr->lev >= 10) (*shots)++;
49         if (creature_ptr->lev >= 30) (*shots)++;
50         if (creature_ptr->lev >= 45) (*shots)++;
51 }
52
53
54 /*!
55  * @brief 武器装備に制限のあるクラスで、直接攻撃のダメージを計算する
56  * @param creature_ptr プレーヤーへの参照ポインタ
57  * @param hand 手 (利き手が0、反対の手が1…のはず)
58  * @param damage 直接攻撃のダメージ
59  * @param basedam 素手における直接攻撃のダメージ
60  * @param o_ptr 装備中の武器への参照ポインタ
61  * @return 利き手ならTRUE、反対の手ならFALSE
62  */
63 static bool calc_weapon_damage_limit(player_type *creature_ptr, int hand, int *damage, int *basedam, object_type *o_ptr)
64 {
65         PLAYER_LEVEL level = creature_ptr->lev;
66         if (hand > 0)
67         {
68                 damage[hand] = 0;
69                 return FALSE;
70         }
71
72         if (creature_ptr->pclass == CLASS_FORCETRAINER) level = MAX(1, level - 3);
73         if (creature_ptr->special_defense & KAMAE_BYAKKO)
74                 *basedam = monk_ave_damage[level][1];
75         else if (creature_ptr->special_defense & (KAMAE_GENBU | KAMAE_SUZAKU))
76                 *basedam = monk_ave_damage[level][2];
77         else
78                 *basedam = monk_ave_damage[level][0];
79
80         damage[hand] += *basedam;
81         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) damage[hand] = 1;
82         if (damage[hand] < 0) damage[hand] = 0;
83
84         return TRUE;
85 }
86
87
88 /*!
89  * @brief 片手あたりのダメージ量を計算する
90  * @param o_ptr 装備中の武器への参照ポインタ
91  * @param hand 手
92  * @param damage 直接攻撃のダメージ
93  * @param basedam 素手における直接攻撃のダメージ
94  * @return 素手ならFALSE、武器を持っていればTRUE
95  */
96 static bool calc_weapon_one_hand(object_type *o_ptr, int hand, int *damage, int *basedam)
97 {
98         if (o_ptr->k_idx == 0) return FALSE;
99
100         *basedam = 0;
101         damage[hand] += *basedam;
102         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE))
103                 damage[hand] = 1;
104
105         if (damage[hand] < 0)
106                 damage[hand] = 0;
107
108         return TRUE;
109 }
110
111
112 /*!
113  * @brief ヴォーパル武器等によるダメージ強化
114  * @param creature_ptr プレーヤーへの参照ポインタ
115  * @param o_ptr 装備中の武器への参照ポインタ
116  * @param basedam 素手における直接攻撃のダメージ
117  * @param flgs オブジェクトフラグ群
118  * @return 強化後の素手ダメージ
119  */
120 static int strengthen_basedam(player_type *creature_ptr, object_type *o_ptr, int basedam, BIT_FLAGS *flgs)
121 {
122         if (object_is_fully_known(o_ptr) && ((o_ptr->name1 == ART_VORPAL_BLADE) || (o_ptr->name1 == ART_CHAINSWORD)))
123         {
124                 /* vorpal blade */
125                 basedam *= 5;
126                 basedam /= 3;
127         }
128         else if (have_flag(flgs, TR_VORPAL))
129         {
130                 /* vorpal flag only */
131                 basedam *= 11;
132                 basedam /= 9;
133         }
134
135         // 理力
136         bool is_force = creature_ptr->pclass != CLASS_SAMURAI;
137         is_force &= have_flag(flgs, TR_FORCE_WEAPON);
138         is_force &= creature_ptr->csp > (o_ptr->dd * o_ptr->ds / 5);
139         if (is_force) basedam = basedam * 7 / 2;
140
141         return basedam;
142 }
143
144
145 /*!
146  * @brief 技能ランクの表示基準を定める
147  * Returns a "rating" of x depending on y
148  * @param x 技能値
149  * @param y 技能値に対するランク基準比
150  * @return なし
151  */
152 static concptr likert(int x, int y)
153 {
154         static char dummy[20] = "", dummy2[20] = "";
155         memset(dummy, 0, strlen(dummy));
156         memset(dummy2, 0, strlen(dummy2));
157         if (y <= 0) y = 1;
158
159         if (show_actual_value)
160                 sprintf(dummy, "%3d-", x);
161
162         if (x < 0)
163         {
164                 likert_color = TERM_L_DARK;
165                 strcat(dummy, _("最低", "Very Bad"));
166                 return dummy;
167         }
168
169         switch ((x / y))
170         {
171         case 0:
172         case 1:
173         {
174                 likert_color = TERM_RED;
175                 strcat(dummy, _("悪い", "Bad"));
176                 break;
177
178         }
179         case 2:
180         {
181                 likert_color = TERM_L_RED;
182                 strcat(dummy, _("劣る", "Poor"));
183                 break;
184         }
185         case 3:
186         case 4:
187         {
188                 likert_color = TERM_ORANGE;
189                 strcat(dummy, _("普通", "Fair"));
190                 break;
191         }
192         case 5:
193         {
194                 likert_color = TERM_YELLOW;
195                 strcat(dummy, _("良い", "Good"));
196                 break;
197         }
198         case 6:
199         {
200                 likert_color = TERM_YELLOW;
201                 strcat(dummy, _("大変良い", "Very Good"));
202                 break;
203         }
204         case 7:
205         case 8:
206         {
207                 likert_color = TERM_L_GREEN;
208                 strcat(dummy, _("卓越", "Excellent"));
209                 break;
210         }
211         case 9:
212         case 10:
213         case 11:
214         case 12:
215         case 13:
216         {
217                 likert_color = TERM_GREEN;
218                 strcat(dummy, _("超越", "Superb"));
219                 break;
220         }
221         case 14:
222         case 15:
223         case 16:
224         case 17:
225         {
226                 likert_color = TERM_BLUE;
227                 strcat(dummy, _("英雄的", "Heroic"));
228                 break;
229         }
230         default:
231         {
232                 likert_color = TERM_VIOLET;
233                 sprintf(dummy2, _("伝説的[%d]", "Legendary[%d]"), (int)((((x / y) - 17) * 5) / 2));
234                 strcat(dummy, dummy2);
235                 break;
236         }
237         }
238
239         return dummy;
240 }
241
242
243 /*!
244  * @brief 弓+両手の武器それぞれについてダメージを計算する
245  * @param creature_ptr プレーヤーへの参照ポインタ
246  * @param damage 直接攻撃のダメージ
247  * @param to_h 命中補正
248  * @return なし
249  */
250 static void calc_two_hands(player_type *creature_ptr, int *damage, int *to_h)
251 {
252         object_type *o_ptr;
253         o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
254         BIT_FLAGS flgs[TR_FLAG_SIZE];
255         for (int i = 0; i < 2; i++)
256         {
257                 int basedam;
258                 damage[i] = creature_ptr->dis_to_d[i] * 100;
259                 if (((creature_ptr->pclass == CLASS_MONK) || (creature_ptr->pclass == CLASS_FORCETRAINER)) && (empty_hands(creature_ptr, TRUE) & EMPTY_HAND_RARM))
260                 {
261                         if (!calc_weapon_damage_limit(creature_ptr, i, damage, &basedam, o_ptr))
262                                 break;
263
264                         continue;
265                 }
266
267                 o_ptr = &creature_ptr->inventory_list[INVEN_RARM + i];
268                 if (!calc_weapon_one_hand(o_ptr, i, damage, &basedam)) continue;
269
270                 to_h[i] = 0;
271                 bool poison_needle = FALSE;
272                 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) poison_needle = TRUE;
273                 if (object_is_known(o_ptr))
274                 {
275                         damage[i] += o_ptr->to_d * 100;
276                         to_h[i] += o_ptr->to_h;
277                 }
278
279                 basedam = ((o_ptr->dd + creature_ptr->to_dd[i]) * (o_ptr->ds + creature_ptr->to_ds[i] + 1)) * 50;
280                 object_flags_known(creature_ptr, o_ptr, flgs);
281
282                 basedam = calc_expect_crit(creature_ptr, o_ptr->weight, to_h[i], basedam, creature_ptr->dis_to_h[i], poison_needle);
283                 basedam = strengthen_basedam(creature_ptr, o_ptr, basedam, flgs);
284                 damage[i] += basedam;
285                 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) damage[i] = 1;
286                 if (damage[i] < 0) damage[i] = 0;
287         }
288 }
289
290
291 /*!
292  * @brief キャラ基本情報及び技能値をメインウィンドウに表示する
293  * @param creature_ptr プレーヤーへの参照ポインタ
294  * @param xthb 武器等を含めた最終命中率
295  * @param damage 打撃修正
296  * @param shots 射撃回数
297  * @param shot_frac 射撃速度
298  * @param display_player_one_line 1行表示用のコールバック関数
299  * @return なし
300  */
301 static void display_first_page(player_type *creature_ptr, int xthb, int *damage, int shots, int shot_frac)
302 {
303         int xthn = creature_ptr->skill_thn + (creature_ptr->to_h_m * BTH_PLUS_ADJ);
304
305         int muta_att = 0;
306         if (creature_ptr->muta2 & MUT2_HORNS) muta_att++;
307         if (creature_ptr->muta2 & MUT2_SCOR_TAIL) muta_att++;
308         if (creature_ptr->muta2 & MUT2_BEAK) muta_att++;
309         if (creature_ptr->muta2 & MUT2_TRUNK) muta_att++;
310         if (creature_ptr->muta2 & MUT2_TENTACLES) muta_att++;
311
312         int blows1 = creature_ptr->migite ? creature_ptr->num_blow[0] : 0;
313         int blows2 = creature_ptr->hidarite ? creature_ptr->num_blow[1] : 0;
314         int xdis = creature_ptr->skill_dis;
315         int xdev = creature_ptr->skill_dev;
316         int xsav = creature_ptr->skill_sav;
317         int xstl = creature_ptr->skill_stl;
318         int     xsrh = creature_ptr->skill_srh;
319         int     xfos = creature_ptr->skill_fos;
320         int xdig = creature_ptr->skill_dig;
321
322         concptr desc = likert(xthn, 12);
323         display_player_one_line(ENTRY_SKILL_FIGHT, desc, likert_color);
324
325         desc = likert(xthb, 12);
326         display_player_one_line(ENTRY_SKILL_SHOOT, desc, likert_color);
327
328         desc = likert(xsav, 7);
329         display_player_one_line(ENTRY_SKILL_SAVING, desc, likert_color);
330
331         desc = likert((xstl > 0) ? xstl : -1, 1);
332         display_player_one_line(ENTRY_SKILL_STEALTH, desc, likert_color);
333
334         desc = likert(xfos, 6);
335         display_player_one_line(ENTRY_SKILL_PERCEP, desc, likert_color);
336
337         desc = likert(xsrh, 6);
338         display_player_one_line(ENTRY_SKILL_SEARCH, desc, likert_color);
339
340         desc = likert(xdis, 8);
341         display_player_one_line(ENTRY_SKILL_DISARM, desc, likert_color);
342
343         desc = likert(xdev, 6);
344         display_player_one_line(ENTRY_SKILL_DEVICE, desc, likert_color);
345
346         desc = likert(xdev, 6);
347         display_player_one_line(ENTRY_SKILL_DEVICE, desc, likert_color);
348
349         desc = likert(xdig, 4);
350         display_player_one_line(ENTRY_SKILL_DIG, desc, likert_color);
351
352         if (!muta_att)
353                 display_player_one_line(ENTRY_BLOWS, format("%d+%d", blows1, blows2), TERM_L_BLUE);
354         else
355                 display_player_one_line(ENTRY_BLOWS, format("%d+%d+%d", blows1, blows2, muta_att), TERM_L_BLUE);
356
357         display_player_one_line(ENTRY_SHOTS, format("%d.%02d", shots, shot_frac), TERM_L_BLUE);
358
359         if ((damage[0] + damage[1]) == 0)
360                 desc = "nil!";
361         else
362                 desc = format("%d+%d", blows1 * damage[0] / 100, blows2 * damage[1] / 100);
363
364         display_player_one_line(ENTRY_AVG_DMG, desc, TERM_L_BLUE);
365         display_player_one_line(ENTRY_INFRA, format("%d feet", creature_ptr->see_infra * 10), TERM_WHITE);
366 }
367
368
369 /*!
370  * @brief プレイヤーステータスの1ページ目各種詳細をまとめて表示する
371  * Prints ratings on certain abilities
372  * @param creature_ptr プレーヤーへの参照ポインタ
373  * @param display_player_one_line 1行表示用のコールバック関数
374  * @return なし
375  * @details
376  * This code is "imitated" elsewhere to "dump" a character sheet.
377  */
378 void display_player_various(player_type *creature_ptr)
379 {
380         object_type *o_ptr;
381         o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
382         int tmp = creature_ptr->to_h_b + o_ptr->to_h;
383         int     xthb = creature_ptr->skill_thb + (tmp * BTH_PLUS_ADJ);
384         int     shots = 0;
385         int shot_frac = 0;
386         calc_shot_params(creature_ptr, o_ptr, &shots, &shot_frac);
387
388         int damage[2];
389         int to_h[2];
390         calc_two_hands(creature_ptr, damage, to_h);
391         display_first_page(creature_ptr, xthb, damage, shots, shot_frac);
392 }