OSDN Git Service

[Refactor] #2798 bow_tval_ammo() をBaseitemKey::get_arrow_kind() として再定義した
[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
14 BaseitemKey::BaseitemKey(const ItemKindType type_value, const std::optional<int> &subtype_value)
15     : type_value(type_value)
16     , subtype_value(subtype_value)
17 {
18 }
19
20 bool BaseitemKey::operator==(const BaseitemKey &other) const
21 {
22     return (this->type_value == other.type_value) && (this->subtype_value == other.subtype_value);
23 }
24
25 // @details type_valueに大小があればそれを判定し、同一ならばsubtype_valueの大小を判定する.
26 bool BaseitemKey::operator<(const BaseitemKey &other) const
27 {
28     if (this->type_value < other.type_value) {
29         return true;
30     }
31
32     if (this->type_value > other.type_value) {
33         return false;
34     }
35
36     return this->subtype_value < other.subtype_value;
37 }
38
39 ItemKindType BaseitemKey::tval() const
40 {
41     return this->type_value;
42 }
43
44 std::optional<int> BaseitemKey::sval() const
45 {
46     return this->subtype_value;
47 }
48
49 /*!
50  * @brief 射撃武器に対応する矢/弾薬のベースアイテムIDを返す
51  * @return 対応する矢/弾薬のベースアイテムID
52  */
53 ItemKindType BaseitemKey::get_arrow_kind() const
54 {
55     if (this->type_value != ItemKindType::BOW) {
56         return ItemKindType::NONE;
57     }
58
59     if (!this->subtype_value.has_value()) {
60         return ItemKindType::NONE;
61     }
62
63     switch (this->subtype_value.value()) {
64     case SV_SLING:
65         return ItemKindType::SHOT;
66     case SV_SHORT_BOW:
67     case SV_LONG_BOW:
68     case SV_NAMAKE_BOW:
69         return ItemKindType::ARROW;
70     case SV_LIGHT_XBOW:
71     case SV_HEAVY_XBOW:
72         return ItemKindType::BOLT;
73     case SV_CRIMSON:
74     case SV_HARP:
75         return ItemKindType::NO_AMMO;
76     default:
77         return ItemKindType::NONE;
78     }
79 }
80
81 BaseitemInfo::BaseitemInfo()
82     : bi_key(ItemKindType::NONE)
83 {
84 }
85
86 std::vector<BaseitemInfo> baseitems_info;