OSDN Git Service

Merge pull request #2829 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::can_recharge() const
165 {
166     switch (this->type_value) {
167     case ItemKindType::STAFF:
168     case ItemKindType::WAND:
169     case ItemKindType::ROD:
170         return true;
171     default:
172         return false;
173     }
174 }
175
176 bool BaseitemKey::is_wand_rod() const
177 {
178     switch (this->type_value) {
179     case ItemKindType::WAND:
180     case ItemKindType::ROD:
181         return true;
182     default:
183         return false;
184     }
185 }
186
187 bool BaseitemKey::is_wand_staff() const
188 {
189     switch (this->type_value) {
190     case ItemKindType::WAND:
191     case ItemKindType::STAFF:
192         return true;
193     default:
194         return false;
195     }
196 }
197
198 bool BaseitemKey::is_protector() const
199 {
200     switch (this->type_value) {
201     case ItemKindType::BOOTS:
202     case ItemKindType::GLOVES:
203     case ItemKindType::HELM:
204     case ItemKindType::CROWN:
205     case ItemKindType::SHIELD:
206     case ItemKindType::CLOAK:
207     case ItemKindType::SOFT_ARMOR:
208     case ItemKindType::HARD_ARMOR:
209     case ItemKindType::DRAG_ARMOR:
210         return true;
211     default:
212         return false;
213     }
214 }
215
216 bool BaseitemKey::can_be_aura_protector() const
217 {
218     switch (this->type_value) {
219     case ItemKindType::CLOAK:
220     case ItemKindType::SOFT_ARMOR:
221     case ItemKindType::HARD_ARMOR:
222         return true;
223     default:
224         return false;
225     }
226 }
227
228 bool BaseitemKey::is_wearable() const
229 {
230     switch (this->type_value) {
231     case ItemKindType::BOW:
232     case ItemKindType::DIGGING:
233     case ItemKindType::HAFTED:
234     case ItemKindType::POLEARM:
235     case ItemKindType::SWORD:
236     case ItemKindType::BOOTS:
237     case ItemKindType::GLOVES:
238     case ItemKindType::HELM:
239     case ItemKindType::CROWN:
240     case ItemKindType::SHIELD:
241     case ItemKindType::CLOAK:
242     case ItemKindType::SOFT_ARMOR:
243     case ItemKindType::HARD_ARMOR:
244     case ItemKindType::DRAG_ARMOR:
245     case ItemKindType::LITE:
246     case ItemKindType::AMULET:
247     case ItemKindType::RING:
248     case ItemKindType::CARD:
249         return true;
250     default:
251         return false;
252     }
253 }
254
255 bool BaseitemKey::is_mushrooms() const
256 {
257     if (!this->subtype_value.has_value()) {
258         return false;
259     }
260
261     switch (this->subtype_value.value()) {
262     case SV_FOOD_POISON:
263     case SV_FOOD_BLINDNESS:
264     case SV_FOOD_PARANOIA:
265     case SV_FOOD_CONFUSION:
266     case SV_FOOD_HALLUCINATION:
267     case SV_FOOD_PARALYSIS:
268     case SV_FOOD_WEAKNESS:
269     case SV_FOOD_SICKNESS:
270     case SV_FOOD_STUPIDITY:
271     case SV_FOOD_NAIVETY:
272     case SV_FOOD_UNHEALTH:
273     case SV_FOOD_DISEASE:
274     case SV_FOOD_CURE_POISON:
275     case SV_FOOD_CURE_BLINDNESS:
276     case SV_FOOD_CURE_PARANOIA:
277     case SV_FOOD_CURE_CONFUSION:
278     case SV_FOOD_CURE_SERIOUS:
279     case SV_FOOD_RESTORE_STR:
280     case SV_FOOD_RESTORE_CON:
281     case SV_FOOD_RESTORING:
282         return true;
283     default:
284         return false;
285     }
286 }
287
288 BaseitemInfo::BaseitemInfo()
289     : bi_key(ItemKindType::NONE)
290 {
291 }
292
293 std::vector<BaseitemInfo> baseitems_info;