OSDN Git Service

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