OSDN Git Service

[Fix] #963 Resolved the indication that unique_ptr<PlayerEnergy> should be PlayerEnergy
[hengbandforosx/hengbandosx.git] / src / player / player-race.cpp
1 #include "player/player-race.h"
2 #include "core/player-redraw-types.h"
3 #include "inventory/inventory-slot-types.h"
4 #include "player/player-race-types.h"
5 #include "system/object-type-definition.h"
6 #include "mimic-info-table.h"
7 #include "player/race-info-table.h"
8 #include "system/player-type-definition.h"
9 #include "util/bit-flags-calculator.h"
10
11 const player_race *rp_ptr;
12
13 const player_race *get_player_race_info(player_type* creature_ptr, bool base_race = false)
14 {
15     if (base_race)
16         return &race_info[creature_ptr->prace];
17
18     switch (creature_ptr->mimic_form) {
19     case MIMIC_DEMON:
20     case MIMIC_DEMON_LORD:
21     case MIMIC_VAMPIRE:
22         return &mimic_info[creature_ptr->mimic_form];
23     default: // MIMIC_NONE or undefined
24         return &race_info[creature_ptr->prace];
25     }
26 }
27
28 /*!
29  * @brief 救援召喚時のモンスターシンボルを返す
30  * @param creature_ptr プレイヤー情報への参照ポインタ
31  * @return シンボル文字
32  */
33 SYMBOL_CODE get_summon_symbol_from_player(player_type *creature_ptr)
34 {
35     SYMBOL_CODE symbol = 'N';
36     auto mmc_ptr = get_player_race_info(creature_ptr);
37
38     auto l = strlen(mmc_ptr->symbol);
39     auto mul = 1;
40     for (size_t i = 0; i < l; i++) {
41         if (one_in_(mul))
42             symbol = mmc_ptr->symbol[i];
43         mul *= 13;
44     }
45     return symbol;
46 }
47
48 bool is_specific_player_race(player_type *creature_ptr, player_race_type prace) { return (!creature_ptr->mimic_form && (creature_ptr->prace == prace)); }
49
50 /*!
51  * @brief 種族が指定の耐性/能力フラグを持つか判定する
52  * @param creature_ptr プレイヤー情報への参照ポインタ
53  * @param flag 判定するフラグ
54  * @param base_race ベース種族の情報を返すならtrue、ミミック擬態中の種族を返すならfalse
55  * @return 持つならtrue、持たないならfalse
56  */
57 bool player_race_has_flag(player_type *creature_ptr, tr_type flag, bool base_race)
58 {
59     auto race_ptr = get_player_race_info(creature_ptr, base_race);
60
61     for (auto& cond : race_ptr->extra_flags) {
62         if (cond.type != flag)
63             continue;
64         if (creature_ptr->lev < cond.level)
65             continue;
66         if (cond.pclass != std::nullopt) {
67             if (cond.not_class && creature_ptr->pclass == cond.pclass)
68                 continue;
69             if (!cond.not_class && creature_ptr->pclass != cond.pclass)
70                 continue;
71         }
72
73         return true;
74     }
75
76     return false;
77 }
78
79 /*!
80  * @brief 種族固有の耐性/能力フラグをセットする
81  * @param creature_ptr プレイヤー情報への参照ポインタ
82  * @param flags フラグ配列へのポインタ
83  * @param base_race ベース種族の情報を返すならtrue、ミミック擬態中の種族を返すならfalse
84  * @return なし
85  */
86 void add_player_race_flags(player_type *creature_ptr, BIT_FLAGS *flags, bool base_race)
87 {
88     auto race_ptr = get_player_race_info(creature_ptr, base_race);
89     if (race_ptr->infra > 0)
90         add_flag(flags, TR_INFRA);
91
92     for (auto &cond : race_ptr->extra_flags) {
93         if (creature_ptr->lev < cond.level)
94             continue;
95         if (cond.pclass != std::nullopt) {
96             if (cond.not_class && creature_ptr->pclass == cond.pclass)
97                 continue;
98             if (!cond.not_class && creature_ptr->pclass != cond.pclass)
99                 continue;
100         }
101
102         add_flag(flags, cond.type);
103     }
104 }
105
106 /*!
107  * @brief 種族の生命形態を返す
108  * @param creature_ptr プレイヤー情報への参照ポインタ
109  * @return 生命形態
110  */
111 PlayerRaceLife player_race_life(player_type *creature_ptr, bool base_race)
112 {
113     auto race_ptr = get_player_race_info(creature_ptr, base_race);
114     return race_ptr->life;
115 }