OSDN Git Service

[Refactor] enum classの型名変更 MUTA -> PlayerMutationType
[hengbandforosx/hengbandosx.git] / src / view / display-player-stat-info.cpp
1 /*!
2  * @brief プレイヤーの耐性と能力値を表示する
3  * @date 2020/02/27
4  * @author Hourier
5  * @details
6  * ここにこれ以上関数を引っ越してくるのは禁止。何ならここから更に分割していく
7  */
8
9 #include "display-player-stat-info.h"
10 #include "inventory/inventory-slot-types.h"
11 #include "mutation/mutation-flag-types.h"
12 #include "object-enchant/tr-types.h"
13 #include "object/object-flags.h"
14 #include "player-base/player-race.h"
15 #include "player-info/class-info.h"
16 #include "player-info/mimic-info-table.h"
17 #include "player/permanent-resistances.h"
18 #include "player/player-personality.h"
19 #include "player/player-status-table.h"
20 #include "player/player-status.h"
21 #include "system/object-type-definition.h"
22 #include "system/player-type-definition.h"
23 #include "term/screen-processor.h"
24 #include "term/term-color-types.h"
25 #include "util/bit-flags-calculator.h"
26
27 /*!
28  * @brief プレイヤーのパラメータ基礎値 (腕力等)を18以下になるようにして返す
29  * @param player_ptr プレイヤーへの参照ポインタ
30  * @param stat_num 能力値番号
31  * @return 基礎値
32  * @details 最大が18になるのはD&D由来
33  */
34 static int calc_basic_stat(player_type *player_ptr, int stat_num)
35 {
36     int e_adj = 0;
37     if ((player_ptr->stat_max[stat_num] > 18) && (player_ptr->stat_top[stat_num] > 18))
38         e_adj = (player_ptr->stat_top[stat_num] - player_ptr->stat_max[stat_num]) / 10;
39
40     if ((player_ptr->stat_max[stat_num] <= 18) && (player_ptr->stat_top[stat_num] <= 18))
41         e_adj = player_ptr->stat_top[stat_num] - player_ptr->stat_max[stat_num];
42
43     if ((player_ptr->stat_max[stat_num] <= 18) && (player_ptr->stat_top[stat_num] > 18))
44         e_adj = (player_ptr->stat_top[stat_num] - 18) / 10 - player_ptr->stat_max[stat_num] + 18;
45
46     if ((player_ptr->stat_max[stat_num] > 18) && (player_ptr->stat_top[stat_num] <= 18))
47         e_adj = player_ptr->stat_top[stat_num] - (player_ptr->stat_max[stat_num] - 19) / 10 - 19;
48
49     return e_adj;
50 }
51
52 /*!
53  * @brief 特殊な種族の時、腕力等の基礎パラメータを変動させる
54  * @param player_ptr プレイヤーへの参照ポインタ
55  * @param stat_num 能力値番号
56  * @return 補正後の基礎パラメータ
57  */
58 static int compensate_special_race(player_type *player_ptr, int stat_num)
59 {
60     if (!PlayerRace(player_ptr).equals(PlayerRaceType::ENT))
61         return 0;
62
63     int r_adj = 0;
64     switch (stat_num) {
65     case A_STR:
66     case A_CON:
67         if (player_ptr->lev > 25)
68             r_adj++;
69         if (player_ptr->lev > 40)
70             r_adj++;
71         if (player_ptr->lev > 45)
72             r_adj++;
73         break;
74     case A_DEX:
75         if (player_ptr->lev > 25)
76             r_adj--;
77         if (player_ptr->lev > 40)
78             r_adj--;
79         if (player_ptr->lev > 45)
80             r_adj--;
81         break;
82     }
83
84     return r_adj;
85 }
86
87 /*!
88  * @brief 能力値名を(もし一時的減少なら'x'を付けて)表示する
89  * @param player_ptr プレイヤーへの参照ポインタ
90  * @param stat_num 能力値番号
91  * @param row 行数
92  * @param stat_col 列数
93  */
94 static void display_basic_stat_name(player_type *player_ptr, int stat_num, int row, int stat_col)
95 {
96     if (player_ptr->stat_cur[stat_num] < player_ptr->stat_max[stat_num])
97         c_put_str(TERM_WHITE, stat_names_reduced[stat_num], row + stat_num + 1, stat_col + 1);
98     else
99         c_put_str(TERM_WHITE, stat_names[stat_num], row + stat_num + 1, stat_col + 1);
100 }
101
102 /*!
103  * @brief 能力値を、基本・種族補正・職業補正・性格補正・装備補正・合計・現在 (一時的減少のみ) の順で表示する
104  * @param player_ptr プレイヤーへの参照ポインタ
105  * @param stat_num 能力値番号
106  * @param r_adj 補正後の基礎パラメータ
107  * @param e_adj 種族補正値
108  * @param row 行数
109  * @param stat_col 列数
110  * @param buf 能力値の数値
111  */
112 static void display_basic_stat_value(player_type *player_ptr, int stat_num, int r_adj, int e_adj, int row, int stat_col, char *buf)
113 {
114     (void)sprintf(buf, "%3d", r_adj);
115     c_put_str(TERM_L_BLUE, buf, row + stat_num + 1, stat_col + 13);
116
117     (void)sprintf(buf, "%3d", (int)cp_ptr->c_adj[stat_num]);
118     c_put_str(TERM_L_BLUE, buf, row + stat_num + 1, stat_col + 16);
119
120     (void)sprintf(buf, "%3d", (int)ap_ptr->a_adj[stat_num]);
121     c_put_str(TERM_L_BLUE, buf, row + stat_num + 1, stat_col + 19);
122
123     (void)sprintf(buf, "%3d", (int)e_adj);
124     c_put_str(TERM_L_BLUE, buf, row + stat_num + 1, stat_col + 22);
125
126     cnv_stat(player_ptr->stat_top[stat_num], buf);
127     c_put_str(TERM_L_GREEN, buf, row + stat_num + 1, stat_col + 26);
128
129     if (player_ptr->stat_use[stat_num] < player_ptr->stat_top[stat_num]) {
130         cnv_stat(player_ptr->stat_use[stat_num], buf);
131         c_put_str(TERM_YELLOW, buf, row + stat_num + 1, stat_col + 33);
132     }
133 }
134
135 /*!
136  * @brief 能力値を補正しつつ表示する
137  * @param player_ptr プレイヤーへの参照ポインタ
138  * @param row 行数
139  * @param stat_col 列数
140  */
141 static void process_stats(player_type *player_ptr, int row, int stat_col)
142 {
143     char buf[80];
144     for (int i = 0; i < A_MAX; i++) {
145         int r_adj = player_ptr->mimic_form ? mimic_info[player_ptr->mimic_form].r_adj[i] : rp_ptr->r_adj[i];
146         int e_adj = calc_basic_stat(player_ptr, i);
147         r_adj += compensate_special_race(player_ptr, i);
148         e_adj -= r_adj;
149         e_adj -= cp_ptr->c_adj[i];
150         e_adj -= ap_ptr->a_adj[i];
151
152         display_basic_stat_name(player_ptr, i, row, stat_col);
153         cnv_stat(player_ptr->stat_max[i], buf);
154         if (player_ptr->stat_max[i] == player_ptr->stat_max_max[i])
155             c_put_str(TERM_WHITE, "!", row + i + 1, _(stat_col + 6, stat_col + 4));
156
157         c_put_str(TERM_BLUE, buf, row + i + 1, stat_col + 13 - strlen(buf));
158
159         display_basic_stat_value(player_ptr, i, r_adj, e_adj, row, stat_col, buf);
160     }
161 }
162
163 /*!
164  * @brief pval付きの装備に依るステータス補正を表示する
165  * @param c 補正後の表示記号
166  * @param a 表示色
167  * @param o_ptr 装備品への参照ポインタ
168  * @param stat 能力値番号
169  * @param flags 装備品に立っているフラグ
170  */
171 static void compensate_stat_by_weapon(char *c, TERM_COLOR *a, object_type *o_ptr, tr_type tr_flag, const TrFlags &flags)
172 {
173     *c = '*';
174
175     if (o_ptr->pval > 0) {
176         *a = TERM_L_GREEN;
177         if (o_ptr->pval < 10)
178             *c = '0' + o_ptr->pval;
179     }
180
181     if (flags.has(tr_flag)) {
182         *a = TERM_GREEN;
183     }
184
185     if (o_ptr->pval < 0) {
186         *a = TERM_RED;
187         if (o_ptr->pval > -10)
188             *c = '0' - o_ptr->pval;
189     }
190 }
191
192 /*!
193  * @brief 装備品を走査してpval付きのものをそれと分かるように表示する
194  * @param player_ptr プレイヤーへの参照ポインタ
195  * @param flags 装備品に立っているフラグ
196  * @param row 行数
197  * @param col 列数
198  */
199 static void display_equipments_compensation(player_type *player_ptr, int row, int *col)
200 {
201     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
202         object_type *o_ptr;
203         o_ptr = &player_ptr->inventory_list[i];
204         auto flags = object_flags_known(o_ptr);
205         for (int stat = 0; stat < A_MAX; stat++) {
206             TERM_COLOR a = TERM_SLATE;
207             char c = '.';
208             if (flags.has(TR_STATUS_LIST[stat])) {
209                 compensate_stat_by_weapon(&c, &a, o_ptr, TR_SUST_STATUS_LIST[stat], flags);
210             } else if (flags.has(TR_SUST_STATUS_LIST[stat])) {
211                 a = TERM_GREEN;
212                 c = 's';
213             }
214
215             term_putch(*col, row + stat + 1, a, c);
216         }
217
218         (*col)++;
219     }
220 }
221
222 /*!
223  * @brief 各能力値の補正
224  * @param player_ptr プレイヤーへの参照ポインタ
225  * @param stat 能力値番号
226  */
227 static int compensation_stat_by_mutation(player_type *player_ptr, int stat)
228 {
229     int compensation = 0;
230     if (stat == A_STR) {
231         if (player_ptr->muta.has(PlayerMutationType::HYPER_STR))
232             compensation += 4;
233         if (player_ptr->muta.has(PlayerMutationType::PUNY))
234             compensation -= 4;
235         if (player_ptr->tsuyoshi)
236             compensation += 4;
237         return compensation;
238     }
239
240     if (stat == A_WIS || stat == A_INT) {
241         if (player_ptr->muta.has(PlayerMutationType::HYPER_INT))
242             compensation += 4;
243         if (player_ptr->muta.has(PlayerMutationType::MORONIC))
244             compensation -= 4;
245         return compensation;
246     }
247
248     if (stat == A_DEX) {
249         if (player_ptr->muta.has(PlayerMutationType::IRON_SKIN))
250             compensation -= 1;
251         if (player_ptr->muta.has(PlayerMutationType::LIMBER))
252             compensation += 3;
253         if (player_ptr->muta.has(PlayerMutationType::ARTHRITIS))
254             compensation -= 3;
255         return compensation;
256     }
257
258     if (stat == A_CON) {
259         if (player_ptr->muta.has(PlayerMutationType::RESILIENT))
260             compensation += 4;
261         if (player_ptr->muta.has(PlayerMutationType::XTRA_FAT))
262             compensation += 2;
263         if (player_ptr->muta.has(PlayerMutationType::ALBINO))
264             compensation -= 4;
265         if (player_ptr->muta.has(PlayerMutationType::FLESH_ROT))
266             compensation -= 2;
267         if (player_ptr->tsuyoshi)
268             compensation += 4;
269         return compensation;
270     }
271
272     if (stat == A_CHR) {
273         if (player_ptr->muta.has(PlayerMutationType::SILLY_VOI))
274             compensation -= 4;
275         if (player_ptr->muta.has(PlayerMutationType::BLANK_FAC))
276             compensation -= 1;
277         if (player_ptr->muta.has(PlayerMutationType::FLESH_ROT))
278             compensation -= 1;
279         if (player_ptr->muta.has(PlayerMutationType::SCALES))
280             compensation -= 1;
281         if (player_ptr->muta.has(PlayerMutationType::WART_SKIN))
282             compensation -= 2;
283         if (player_ptr->muta.has(PlayerMutationType::ILL_NORM))
284             compensation = 0;
285         return compensation;
286     }
287
288     return 0;
289 }
290
291 /*!
292  * @brief 突然変異 (と、つよしスペシャル)による能力値の補正有無で表示する記号を変える
293  * @param player_ptr プレイヤーへの参照ポインタ
294  * @param stat 能力値番号
295  * @param c 補正後の表示記号
296  * @param a 表示色
297  */
298 static void change_display_by_mutation(player_type *player_ptr, int stat, char *c, TERM_COLOR *a)
299 {
300     int compensation = compensation_stat_by_mutation(player_ptr, stat);
301     if (compensation == 0)
302         return;
303
304     *c = '*';
305     if (compensation > 0) {
306         *a = TERM_L_GREEN;
307         if (compensation < 10)
308             *c = '0' + compensation;
309     }
310
311     if (compensation < 0) {
312         *a = TERM_RED;
313         if (compensation > -10)
314             *c = '0' - compensation;
315     }
316 }
317
318 /*!
319  * @brief 能力値を走査し、突然変異 (と、つよしスペシャル)で補正をかける必要があればかける
320  * @param player_ptr プレイヤーへの参照ポインタ
321  * @param col 列数
322  * @param row 行数
323  */
324 static void display_mutation_compensation(player_type *player_ptr, int row, int col)
325 {
326     TrFlags flags;
327     player_flags(player_ptr, flags);
328
329     for (int stat = 0; stat < A_MAX; stat++) {
330         byte a = TERM_SLATE;
331         char c = '.';
332         change_display_by_mutation(player_ptr, stat, &c, &a);
333
334         if (flags.has(TR_SUST_STATUS_LIST[stat])) {
335             a = TERM_GREEN;
336             c = 's';
337         }
338
339         term_putch(col, row + stat + 1, a, c);
340     }
341 }
342
343 /*!
344  * @brief プレイヤーの特性フラグ一覧表示2b /
345  * Special display, part 2b
346  * @param player_ptr プレイヤーへの参照ポインタ
347  * @details
348  * <pre>
349  * How to print out the modifications and sustains.
350  * Positive mods with no sustain will be light green.
351  * Positive mods with a sustain will be dark green.
352  * Sustains (with no modification) will be a dark green 's'.
353  * Negative mods (from a curse) will be red.
354  * Huge mods (>9), like from MICoMorgoth, will be a '*'
355  * No mod, no sustain, will be a slate '.'
356  * </pre>
357  */
358 void display_player_stat_info(player_type *player_ptr)
359 {
360     int stat_col = 22;
361     int row = 3;
362     c_put_str(TERM_WHITE, _("能力", "Stat"), row, stat_col + 1);
363     c_put_str(TERM_BLUE, _("  基本", "  Base"), row, stat_col + 7);
364     c_put_str(TERM_L_BLUE, _(" 種 職 性 装 ", "RacClaPerMod"), row, stat_col + 13);
365     c_put_str(TERM_L_GREEN, _("合計", "Actual"), row, stat_col + 28);
366     c_put_str(TERM_YELLOW, _("現在", "Current"), row, stat_col + 35);
367     process_stats(player_ptr, row, stat_col);
368
369     int col = stat_col + 41;
370     c_put_str(TERM_WHITE, "abcdefghijkl@", row, col);
371     c_put_str(TERM_L_GREEN, _("能力修正", "Modification"), row - 1, col);
372
373     display_equipments_compensation(player_ptr, row, &col);
374     display_mutation_compensation(player_ptr, row, col);
375 }