OSDN Git Service

Merge pull request #2827 from Hourier/Prepare-Replace-ItemEntity-TvalSval-to-Baseitem...
[hengbandforosx/hengbandosx.git] / src / system / baseitem-info.cpp
1 /*!
2  * @brief ベースアイテム情報の構造体 / Information about object "kinds", including player knowledge.
3  * @date 2019/05/01
4  * @author deskull
5  * @details
6  * ゲーム進行用のセーブファイル上では aware と tried のみ保存対象とすること。と英文ではあるが実際はもっとある様子である。 /
7  * Only "aware" and "tried" are saved in the savefile
8  */
9
10 #include "system/baseitem-info.h"
11 #include "object/tval-types.h"
12 #include "sv-definition/sv-bow-types.h"
13 #include "sv-definition/sv-food-types.h"
14
15 BaseitemKey::BaseitemKey(const ItemKindType type_value, const std::optional<int> &subtype_value)
16     : type_value(type_value)
17     , subtype_value(subtype_value)
18 {
19 }
20
21 bool BaseitemKey::operator==(const BaseitemKey &other) const
22 {
23     return (this->type_value == other.type_value) && (this->subtype_value == other.subtype_value);
24 }
25
26 // @details type_valueに大小があればそれを判定し、同一ならばsubtype_valueの大小を判定する.
27 bool BaseitemKey::operator<(const BaseitemKey &other) const
28 {
29     if (this->type_value < other.type_value) {
30         return true;
31     }
32
33     if (this->type_value > other.type_value) {
34         return false;
35     }
36
37     return this->subtype_value < other.subtype_value;
38 }
39
40 ItemKindType BaseitemKey::tval() const
41 {
42     return this->type_value;
43 }
44
45 std::optional<int> BaseitemKey::sval() const
46 {
47     return this->subtype_value;
48 }
49
50 /*!
51  * @brief 射撃武器に対応する矢/弾薬のベースアイテムIDを返す
52  * @return 対応する矢/弾薬のベースアイテムID
53  */
54 ItemKindType BaseitemKey::get_arrow_kind() const
55 {
56     if (this->type_value != ItemKindType::BOW) {
57         return ItemKindType::NONE;
58     }
59
60     if (!this->subtype_value.has_value()) {
61         return ItemKindType::NONE;
62     }
63
64     switch (this->subtype_value.value()) {
65     case SV_SLING:
66         return ItemKindType::SHOT;
67     case SV_SHORT_BOW:
68     case SV_LONG_BOW:
69     case SV_NAMAKE_BOW:
70         return ItemKindType::ARROW;
71     case SV_LIGHT_XBOW:
72     case SV_HEAVY_XBOW:
73         return ItemKindType::BOLT;
74     case SV_CRIMSON:
75     case SV_HARP:
76         return ItemKindType::NO_AMMO;
77     default:
78         return ItemKindType::NONE;
79     }
80 }
81
82 bool BaseitemKey::is_spell_book() const
83 {
84     switch (this->type_value) {
85     case ItemKindType::LIFE_BOOK:
86     case ItemKindType::SORCERY_BOOK:
87     case ItemKindType::NATURE_BOOK:
88     case ItemKindType::CHAOS_BOOK:
89     case ItemKindType::DEATH_BOOK:
90     case ItemKindType::TRUMP_BOOK:
91     case ItemKindType::ARCANE_BOOK:
92     case ItemKindType::CRAFT_BOOK:
93     case ItemKindType::DEMON_BOOK:
94     case ItemKindType::CRUSADE_BOOK:
95     case ItemKindType::MUSIC_BOOK:
96     case ItemKindType::HISSATSU_BOOK:
97     case ItemKindType::HEX_BOOK:
98         return true;
99     default:
100         return false;
101     }
102 }
103
104 bool BaseitemKey::is_high_level_book() const
105 {
106     if (!this->is_spell_book()) {
107         return false;
108     }
109
110     if (this->type_value == ItemKindType::ARCANE_BOOK) {
111         return false;
112     }
113
114     return this->subtype_value >= 2;
115 }
116
117 bool BaseitemKey::is_melee_weapon() const
118 {
119     switch (this->type_value) {
120     case ItemKindType::POLEARM:
121     case ItemKindType::SWORD:
122     case ItemKindType::DIGGING:
123     case ItemKindType::HAFTED:
124         return true;
125     default:
126         return false;
127     }
128 }
129
130 bool BaseitemKey::is_ammo() const
131 {
132     switch (this->type_value) {
133     case ItemKindType::SHOT:
134     case ItemKindType::ARROW:
135     case ItemKindType::BOLT:
136         return true;
137     default:
138         return false;
139     }
140 }
141
142 /*
143  * @brief 未鑑定名を持つか否かの判定
144  * @details FOODはキノコが該当する
145  */
146 bool BaseitemKey::has_unidentified_name() const
147 {
148     switch (this->type_value) {
149     case ItemKindType::AMULET:
150     case ItemKindType::RING:
151     case ItemKindType::STAFF:
152     case ItemKindType::WAND:
153     case ItemKindType::ROD:
154     case ItemKindType::SCROLL:
155     case ItemKindType::POTION:
156         return true;
157     case ItemKindType::FOOD:
158         return this->is_mushrooms();
159     default:
160         return false;
161     }
162 }
163
164 bool BaseitemKey::is_mushrooms() const
165 {
166     if (!this->subtype_value.has_value()) {
167         return false;
168     }
169
170     switch (this->subtype_value.value()) {
171     case SV_FOOD_POISON:
172     case SV_FOOD_BLINDNESS:
173     case SV_FOOD_PARANOIA:
174     case SV_FOOD_CONFUSION:
175     case SV_FOOD_HALLUCINATION:
176     case SV_FOOD_PARALYSIS:
177     case SV_FOOD_WEAKNESS:
178     case SV_FOOD_SICKNESS:
179     case SV_FOOD_STUPIDITY:
180     case SV_FOOD_NAIVETY:
181     case SV_FOOD_UNHEALTH:
182     case SV_FOOD_DISEASE:
183     case SV_FOOD_CURE_POISON:
184     case SV_FOOD_CURE_BLINDNESS:
185     case SV_FOOD_CURE_PARANOIA:
186     case SV_FOOD_CURE_CONFUSION:
187     case SV_FOOD_CURE_SERIOUS:
188     case SV_FOOD_RESTORE_STR:
189     case SV_FOOD_RESTORE_CON:
190     case SV_FOOD_RESTORING:
191         return true;
192     default:
193         return false;
194     }
195 }
196
197 BaseitemInfo::BaseitemInfo()
198     : bi_key(ItemKindType::NONE)
199 {
200 }
201
202 std::vector<BaseitemInfo> baseitems_info;