1 /**
2  * @file
3  * @brief Misc functions.
4 **/
5 
6 #pragma once
7 
8 #include <set>
9 
10 #include "equipment-type.h"
11 #include "item-prop-enum.h"
12 #include "reach-type.h"
13 #include "size-type.h"
14 #include "tag-version.h"
15 
16 struct bolt;
17 
18 void init_properties();
19 
20 
21 typedef uint32_t armflags_t;
22 #define ard(flg, lev) (armflags_t)((flg) * ((lev) & 7))
23 
24 enum armour_flag
25 {
26     ARMF_NO_FLAGS           = 0,
27     // multilevel resistances
28     ARMF_RES_FIRE           = 1 << 0,
29     ARMF_RES_COLD           = 1 << 3,
30     ARMF_RES_NEG            = 1 << 6,
31     // misc (multilevel)
32     ARMF_STEALTH            = 1 << 9,
33     ARMF_REGENERATION       = 1 << 13,
34 
35     ARMF_LAST_MULTI, // must be >= any multi, < any boolean, exact value doesn't matter
36 
37     // boolean resists
38     ARMF_WILLPOWER          = 1 << 17,
39     ARMF_RES_ELEC           = 1 << 18,
40     ARMF_RES_POISON         = 1 << 19,
41     ARMF_RES_CORR           = 1 << 20,
42     ARMF_RES_STEAM          = 1 << 21,
43     // vulnerabilities
44     ARMF_VUL_FIRE           = ard(ARMF_RES_FIRE, -1),
45     ARMF_VUL_COLD           = ard(ARMF_RES_COLD, -1),
46 };
47 
48 #define AMU_REFLECT_SH 5*2
49 
50 /// Removed items that have item knowledge.
51 extern const set<pair<object_class_type, int> > removed_items;
52 /// Check for membership in removed_items.
53 bool item_type_removed(object_class_type base, int subtype);
54 
55 // cursed:
56 bool item_is_cursable(const item_def &item);
item_type_has_curses(object_class_type base_type)57 inline constexpr bool item_type_has_curses(object_class_type base_type)
58 {
59         return base_type == OBJ_WEAPONS || base_type == OBJ_ARMOUR
60                || base_type == OBJ_JEWELLERY || base_type == OBJ_STAVES;
61 }
62 
63 // stationary:
64 void set_net_stationary(item_def &item);
65 bool item_is_stationary(const item_def &item) PURE;
66 bool item_is_stationary_net(const item_def &item) PURE;
67 
68 // ident:
69 bool item_ident(const item_def &item, iflags_t flags) PURE;
70 void set_ident_flags(item_def &item, iflags_t flags);
71 void unset_ident_flags(item_def &item, iflags_t flags);
72 bool fully_identified(const item_def &item) PURE;
73 
74 // item descriptions:
75 void     set_equip_desc(item_def &item, iflags_t flags);
76 iflags_t get_equip_desc(const item_def &item) PURE;
77 
78 bool  is_helmet(const item_def &item) PURE;
79 bool  is_hard_helmet(const item_def &item) PURE;
80 
81 // ego items:
82 brand_type choose_weapon_brand(weapon_type wpn_type);
83 bool set_item_ego_type(item_def &item, object_class_type item_type,
84                        int ego_type);
85 brand_type get_weapon_brand(const item_def &item) PURE;
86 special_armour_type get_armour_ego_type(const item_def &item) PURE;
87 special_missile_type get_ammo_brand(const item_def &item) PURE;
88 
89 // armour functions:
90 bool armour_is_enchantable(const item_def &item) PURE;
91 int armour_max_enchant(const item_def &item) PURE;
92 bool armour_type_is_hide(armour_type type) PURE;
93 bool armour_is_hide(const item_def &item) PURE;
94 bool armour_is_special(const item_def &item) PURE;
95 int armour_acq_weight(const armour_type armour) PURE;
96 
97 equipment_type get_armour_slot(const item_def &item) PURE;
98 equipment_type get_armour_slot(armour_type arm) IMMUTABLE;
99 
100 bool jewellery_is_amulet(const item_def &item) PURE;
101 bool jewellery_is_amulet(int sub_type) IMMUTABLE;
102 
103 armour_type hide_for_monster(monster_type mc) PURE;
104 monster_type monster_for_hide(armour_type arm) PURE;
105 
106 int fit_armour_size(const item_def &item, size_type size) PURE;
107 bool check_armour_size(const item_def &item, size_type size) PURE;
108 bool check_armour_size(armour_type sub_type, size_type size) PURE;
109 
110 int wand_charge_value(int type) PURE;
111 #if TAG_MAJOR_VERSION == 34
112 bool is_known_empty_wand(const item_def &item) PURE;
113 #endif
114 bool is_offensive_wand(const item_def &item) PURE;
115 bool is_enchantable_armour(const item_def &arm, bool unknown = false) PURE;
116 
117 bool is_shield(const item_def &item) PURE;
118 bool is_shield_incompatible(const item_def &weapon,
119                             const item_def *shield = nullptr) PURE;
120 bool shield_reflects(const item_def &shield) PURE;
121 void ident_reflector(item_def *item);
122 
123 // Only works for armour/weapons/missiles
124 // weapon functions:
125 int weapon_rarity(int w_type) IMMUTABLE;
126 
127 bool  is_weapon_wieldable(const item_def &item, size_type size) PURE;
128 
129 hands_reqd_type basic_hands_reqd(const item_def &item, size_type size) PURE;
130 hands_reqd_type hands_reqd(const actor* ac, object_class_type base_type, int sub_type);
131 
132 bool is_giant_club_type(int wpn_type) IMMUTABLE;
133 bool is_ranged_weapon_type(int wpn_type) IMMUTABLE;
134 bool is_blessed_weapon_type(int wpn_type) IMMUTABLE;
135 bool is_demonic_weapon_type(int wpn_type) IMMUTABLE;
136 
137 bool is_melee_weapon(const item_def &weapon) PURE;
138 bool is_demonic(const item_def &item) PURE;
139 bool is_blessed(const item_def &item) PURE;
140 bool is_blessed_convertible(const item_def &item) PURE;
141 bool convert2good(item_def &item);
142 bool convert2bad(item_def &item);
143 
144 int get_vorpal_type(const item_def &item) PURE;
145 int get_damage_type(const item_def &item) PURE;
146 int single_damage_type(const item_def &item) PURE;
147 
148 bool is_brandable_weapon(const item_def &wpn, bool allow_ranged, bool divine = false);
149 
150 skill_type item_attack_skill(const item_def &item) PURE;
151 skill_type item_attack_skill(object_class_type wclass, int wtype) IMMUTABLE;
152 
153 bool staff_uses_evocations(const item_def &item);
154 skill_type staff_skill(stave_type s);
155 bool item_skills(const item_def &item, set<skill_type> &skills);
156 
157 // launcher and ammo functions:
158 bool is_range_weapon(const item_def &item) PURE;
159 missile_type fires_ammo_type(const item_def &item) PURE;
160 const char *ammo_name(missile_type ammo) IMMUTABLE;
161 const char *ammo_name(const item_def &bow) PURE;
162 const char *ammo_name(const weapon_type bow) PURE;
163 bool has_launcher(const item_def &ammo) PURE;
164 bool is_throwable(const actor *actor, const item_def &wpn) PURE;
165 launch_retval is_launched(const actor *actor, const item_def *launcher,
166                           const item_def &missile) PURE;
167 
168 bool ammo_always_destroyed(const item_def &missile) PURE;
169 bool ammo_never_destroyed(const item_def &missile) PURE;
170 int  ammo_type_destroy_chance(int missile_type) PURE;
171 int  ammo_type_damage(int missile_type) PURE;
172 
173 
174 reach_type weapon_reach(const item_def &item) PURE;
175 
176 // Macguffins
177 bool item_is_unique_rune(const item_def &item) PURE;
178 bool item_is_orb(const item_def &orb) PURE;
179 bool item_is_horn_of_geryon(const item_def &item) PURE;
180 bool item_is_spellbook(const item_def &item) PURE;
181 
182 bool is_xp_evoker(const item_def &item);
183 int &evoker_debt(int evoker_type);
184 void expend_xp_evoker(int evoker_type);
185 int evoker_charge_xp_debt(int evoker_type);
186 int evoker_charges(int evoker_type);
187 int evoker_max_charges(int evoker_type);
188 
189 // ring functions:
190 bool jewellery_type_has_plusses(int jewel_type) PURE;
191 bool jewellery_has_pluses(const item_def &item) PURE;
192 bool ring_has_stackable_effect(const item_def &item) PURE;
193 #if TAG_MAJOR_VERSION == 34
194 
195 // food functions:
196 bool is_real_food(food_type food) PURE;
197 #endif
198 
199 // generic item property functions:
200 int armour_type_prop(const uint8_t arm, const armour_flag prop) PURE;
201 
202 int get_armour_res_fire(const item_def &arm, bool check_artp) PURE;
203 int get_armour_res_cold(const item_def &arm, bool check_artp) PURE;
204 int get_armour_res_poison(const item_def &arm, bool check_artp) PURE;
205 int get_armour_res_elec(const item_def &arm, bool check_artp) PURE;
206 int get_armour_life_protection(const item_def &arm, bool check_artp) PURE;
207 int get_armour_willpower(const item_def &arm, bool check_artp) PURE;
208 int get_armour_res_corr(const item_def &arm) PURE;
209 int get_armour_repel_missiles(const item_def &arm, bool check_artp) PURE;
210 bool get_armour_see_invisible(const item_def &arm, bool check_artp) PURE;
211 bool get_armour_rampaging(const item_def &arm, bool check_artp) PURE;
212 
213 int get_jewellery_res_fire(const item_def &ring, bool check_artp) PURE;
214 int get_jewellery_res_cold(const item_def &ring, bool check_artp) PURE;
215 int get_jewellery_res_poison(const item_def &ring, bool check_artp) PURE;
216 int get_jewellery_res_elec(const item_def &ring, bool check_artp) PURE;
217 int get_jewellery_life_protection(const item_def &ring, bool check_artp) PURE;
218 int get_jewellery_willpower(const item_def &ring, bool check_artp) PURE;
219 bool get_jewellery_see_invisible(const item_def &ring, bool check_artp) PURE;
220 
221 int property(const item_def &item, int prop_type) PURE;
222 int armour_prop(int armour, int prop_type) PURE;
223 bool gives_ability(const item_def &item) PURE;
224 bool gives_resistance(const item_def &item) PURE;
225 bool item_is_jelly_edible(const item_def &item);
226 equipment_type get_item_slot(object_class_type type, int sub_type) IMMUTABLE;
227 equipment_type get_item_slot(const item_def &item) PURE;
228 
229 int weapon_base_price(weapon_type type) PURE;
230 int missile_base_price(missile_type type) PURE;
231 int armour_base_price(armour_type type) PURE;
232 
233 string item_base_name(const item_def &item);
234 string item_base_name(object_class_type type, int sub_type);
235 const char *weapon_base_name(weapon_type subtype) IMMUTABLE;
236 weapon_type name_nospace_to_weapon(string name_nospace);
237 
238 void seen_item(const item_def &item);
239 
is_weapon(const item_def & item)240 static inline bool is_weapon(const item_def &item)
241 {
242     return item.base_type == OBJ_WEAPONS || item.base_type == OBJ_STAVES;
243 }
244 
item_type_is_equipment(object_class_type base_type)245 inline constexpr bool item_type_is_equipment(object_class_type base_type)
246 {
247         return base_type == OBJ_WEAPONS || base_type == OBJ_ARMOUR
248                || base_type == OBJ_JEWELLERY || base_type == OBJ_STAVES;
249 }
250 
251 void remove_whitespace(string &str);
252 
253 void auto_id_inventory();
254