1 #pragma once
2 #ifndef CATA_SRC_ITEM_H
3 #define CATA_SRC_ITEM_H
4 
5 #include <algorithm>
6 #include <climits>
7 #include <cstdint>
8 #include <functional>
9 #include <iosfwd>
10 #include <list>
11 #include <map>
12 #include <new>
13 #include <set>
14 #include <type_traits>
15 #include <utility>
16 #include <vector>
17 
18 #include "calendar.h"
19 #include "cata_utility.h"
20 #include "craft_command.h"
21 #include "enums.h"
22 #include "gun_mode.h"
23 #include "io_tags.h"
24 #include "item_contents.h"
25 #include "item_location.h"
26 #include "item_pocket.h"
27 #include "material.h"
28 #include "optional.h"
29 #include "requirements.h"
30 #include "safe_reference.h"
31 #include "type_id.h"
32 #include "units.h"
33 #include "value_ptr.h"
34 #include "visitable.h"
35 
36 class Character;
37 class JsonIn;
38 class JsonObject;
39 class JsonOut;
40 class book_proficiency_bonuses;
41 class enchantment;
42 class faction;
43 class gun_type_type;
44 class gunmod_location;
45 class item;
46 class iteminfo_query;
47 class monster;
48 class nc_color;
49 class player;
50 class recipe;
51 class relic;
52 struct armor_portion_data;
53 struct islot_comestible;
54 struct itype;
55 struct mtype;
56 struct tripoint;
57 template<typename T>
58 class ret_val;
59 template <typename T> struct enum_traits;
60 
61 namespace enchant_vals
62 {
63 enum class mod : int;
64 } // namespace enchant_vals
65 
66 using bodytype_id = std::string;
67 using faction_id = string_id<faction>;
68 class item_category;
69 struct islot_armor;
70 struct use_function;
71 
72 enum art_effect_passive : int;
73 enum class side : int;
74 class body_part_set;
75 class map;
76 struct damage_instance;
77 struct damage_unit;
78 struct fire_data;
79 
80 enum class damage_type : int;
81 enum clothing_mod_type : int;
82 
83 std::string rad_badge_color( int rad );
84 
85 struct light_emission {
86     unsigned short luminance;
87     short width;
88     short direction;
89 };
90 extern light_emission nolight;
91 
92 /**
93  *  Value and metadata for one property of an item
94  *
95  *  Contains the value of one property of an item, as well as various metadata items required to
96  *  output that value.  This is used primarily for user output of information about an item, for
97  *  example in the various inventory menus.  See @ref item::info() for the main example of how a
98  *  class desiring to provide user output might obtain a class of this type.
99  *
100  *  As an example, if the item being queried was a piece of clothing, then several properties might
101  *  be returned.  All would have sType "ARMOR".  There would be one for the coverage stat with
102  *  sName "Coverage: ", another for the warmth stat with sName "Warmth: ", etc.
103  */
104 struct iteminfo {
105     public:
106         /** Category of item that owns this iteminfo.  See @ref item_category. */
107         std::string sType;
108 
109         /** Main text of this property's name */
110         std::string sName;
111 
112         /** Formatting text to be placed between the name and value of this item. */
113         std::string sFmt;
114 
115         /** Numerical value of this property. Set to -999 if no compare value is present */
116         std::string sValue;
117 
118         /** Internal double floating point version of value, for numerical comparisons */
119         double dValue;
120 
121         /** Flag indicating type of sValue.  True if integer, false if single decimal */
122         bool is_int;
123 
124         /** Flag indicating whether a newline should be printed after printing this item */
125         bool bNewLine;
126 
127         /** Reverses behavior of red/green text coloring; smaller values are green if true */
128         bool bLowerIsBetter;
129 
130         /** Whether to print sName.  If false, use for comparisons but don't print for user. */
131         bool bDrawName;
132 
133         /** Whether to print a sign on positive values */
134         bool bShowPlus;
135 
136         /** Flag indicating decimal with three points of precision.  */
137         bool three_decimal;
138 
139         enum flags {
140             no_flags = 0,
141             is_decimal = 1 << 0, ///< Print as decimal rather than integer
142             is_three_decimal = 1 << 1, ///< Print as decimal with three points of precision
143             no_newline = 1 << 2, ///< Do not follow with a newline
144             lower_is_better = 1 << 3, ///< Lower values are better for this stat
145             no_name = 1 << 4, ///< Do not print the name
146             show_plus = 1 << 5, ///< Use a + sign for positive values
147         };
148 
149         /**
150          *  @param Type The item type of the item this iteminfo belongs to.
151          *  @param Name The name of the property this iteminfo describes.
152          *  @param Fmt Formatting text desired between item name and value
153          *  @param Flags Additional flags to customize this entry
154          *  @param Value Numerical value of this property, -999 for none.
155          */
156         iteminfo( const std::string &Type, const std::string &Name, const std::string &Fmt = "",
157                   flags Flags = no_flags, double Value = -999 );
158         iteminfo( const std::string &Type, const std::string &Name, flags Flags );
159         iteminfo( const std::string &Type, const std::string &Name, double Value );
160 };
161 
162 template<>
163 struct enum_traits<iteminfo::flags> {
164     static constexpr bool is_flag_enum = true;
165 };
166 
167 iteminfo vol_to_info( const std::string &type, const std::string &left,
168                       const units::volume &vol, int decimal_places = 2 );
169 iteminfo weight_to_info( const std::string &type, const std::string &left,
170                          const units::mass &weight, int decimal_places = 2 );
171 
172 inline bool is_crafting_component( const item &component );
173 
174 class item : public visitable
175 {
176     public:
177         using FlagsSetType = std::set<flag_id>;
178 
179         item();
180 
181         item( item && );
182         item( const item & );
183         item &operator=( item && );
184         item &operator=( const item & );
185 
186         explicit item( const itype_id &id, time_point turn = calendar::turn, int qty = -1 );
187         explicit item( const itype *type, time_point turn = calendar::turn, int qty = -1 );
188 
189         /** Suppress randomization and always start with default quantity of charges */
190         struct default_charges_tag {};
191         item( const itype_id &id, time_point turn, default_charges_tag );
192         item( const itype *type, time_point turn, default_charges_tag );
193 
194         /** Default (or randomized) charges except if counted by charges then only one charge */
195         struct solitary_tag {};
196         item( const itype_id &id, time_point turn, solitary_tag );
197         item( const itype *type, time_point turn, solitary_tag );
198 
199         /** For constructing in-progress crafts */
200         item( const recipe *rec, int qty, std::list<item> items, std::vector<item_comp> selections );
201 
202         /** For constructing in-progress disassemblies */
203         item( const recipe *rec, item &component );
204 
205         // Legacy constructor for constructing from string rather than itype_id
206         // TODO: remove this and migrate code using it.
207         template<typename... Args>
208         explicit item( const std::string &itype, Args &&... args ) :
209             item( itype_id( itype ), std::forward<Args>( args )... )
210         {}
211 
212         ~item() override;
213 
214         /** Return a pointer-like type that's automatically invalidated if this
215          * item is destroyed or assigned-to */
216         safe_reference<item> get_safe_reference();
217 
218         /**
219          * Filter converting this instance to another type preserving all other aspects
220          * @param new_type the type id to convert to
221          * @return same instance to allow method chaining
222          */
223         item &convert( const itype_id &new_type );
224 
225         /**
226          * Filter converting this instance to the inactive type
227          * If the item is either inactive or cannot be deactivated is a no-op
228          * @param ch character currently possessing or acting upon the item (if any)
229          * @param alert whether to display any messages
230          * @return same instance to allow method chaining
231          */
232         item &deactivate( const Character *ch = nullptr, bool alert = true );
233 
234         /** Filter converting instance to active state */
235         item &activate();
236 
237         /**
238          * Invoke use function on a thrown item that had "ACT_ON_RANGED_HIT" flag.
239          * The function is called on the spot where the item landed.
240          * @param pos position
241          * @return true if the item was destroyed (exploded)
242          */
243         bool activate_thrown( const tripoint &pos );
244 
245         /**
246          * Add or remove energy from a battery.
247          * If adding the specified energy quantity would go over the battery's capacity fill
248          * the battery and ignore the remainder.
249          * If adding the specified energy quantity would reduce the battery's charge level
250          * below 0 do nothing and return how far below 0 it would have gone.
251          * @param qty energy quantity to add (can be negative)
252          * @return 0 valued energy quantity on success
253          */
254         units::energy set_energy( const units::energy &qty );
255 
256         /**
257          * Filter setting the ammo for this instance
258          * Any existing ammo is removed. If necessary a magazine is also added.
259          * @param ammo specific type of ammo (must be compatible with item ammo type)
260          * @param qty maximum ammo (capped by item capacity) or negative to fill to capacity
261          * @return same instance to allow method chaining
262          */
263         item &ammo_set( const itype_id &ammo, int qty = -1 );
264 
265         /**
266          * Filter removing all ammo from this instance
267          * If the item is neither a tool, gun nor magazine is a no-op
268          * For items reloading using magazines any empty magazine remains present.
269          */
270         item &ammo_unset();
271 
272         /**
273          * Filter setting damage constrained by @ref min_damage and @ref max_damage
274          * @note this method does not invoke the @ref on_damage callback
275          * @return same instance to allow method chaining
276          */
277         item &set_damage( int qty );
278 
279         /**
280          * Splits a count-by-charges item always leaving source item with minimum of 1 charge
281          * @param qty number of required charges to split from source
282          * @return new instance containing exactly qty charges or null item if splitting failed
283          */
284         item split( int qty );
285 
286         /**
287          * Make a corpse of the given monster type.
288          * The monster type id must be valid (see @ref MonsterGenerator::get_all_mtypes).
289          *
290          * The turn parameter sets the birthday of the corpse, in other words: the turn when the
291          * monster died. Because corpses are removed from the map when they reach a certain age,
292          * one has to be careful when placing corpses with a birthday of 0. They might be
293          * removed immediately when the map is loaded without been seen by the player.
294          *
295          * The name parameter can be used to give the corpse item a name. This is
296          * used instead of the monster type name ("corpse of X" instead of "corpse of bear").
297          *
298          * With the default parameters it makes a human corpse, created at the current turn.
299          */
300         /*@{*/
301         static item make_corpse( const mtype_id &mt = string_id<mtype>::NULL_ID(),
302                                  time_point turn = calendar::turn, const std::string &name = "", int upgrade_time = -1 );
303         /*@}*/
304         /**
305          * @return The monster type associated with this item (@ref corpse). It is usually the
306          * type that this item is made of (e.g. corpse, meat or blood of the monster).
307          * May return a null-pointer.
308          */
309         const mtype *get_mtype() const;
310         /**
311          * Sets the monster type associated with this item (@ref corpse). You must not pass a
312          * null pointer.
313          * TODO: change this to take a reference instead.
314          */
315         void set_mtype( const mtype *m );
316         /**
317          * Whether this is a corpse item. Corpses always have valid monster type (@ref corpse)
318          * associated (@ref get_mtype return a non-null pointer) and have been created
319          * with @ref make_corpse.
320          */
321         bool is_corpse() const;
322         /**
323          * Whether this is a corpse that can be revived.
324          */
325         bool can_revive() const;
326         /**
327          * Whether this corpse should revive now. Note that this function includes some randomness,
328          * the return value can differ on successive calls.
329          * @param pos The location of the item (see REVIVE_SPECIAL flag).
330          */
331         bool ready_to_revive( const tripoint &pos ) const;
332 
333         bool is_money() const;
334         bool is_software() const;
335         bool is_software_storage() const;
336 
337         /**
338          * Returns a symbol for indicating the current dirt or fouling level for a gun.
339          */
340         std::string dirt_symbol() const;
341 
342         /**
343          * Returns the default color of the item (e.g. @ref itype::color).
344          */
345         nc_color color() const;
346         /**
347          * Returns the color of the item depending on usefulness for the player character,
348          * e.g. differently if it its an unread book or a spoiling food item etc.
349          * This should only be used for displaying data, it should not affect game play.
350          */
351         nc_color color_in_inventory() const;
352         /**
353          * Return the (translated) item name.
354          * @param quantity used for translation to the proper plural form of the name, e.g.
355          * returns "rock" for quantity 1 and "rocks" for quantity > 0.
356          * @param with_prefix determines whether to include more item properties, such as
357          * the extent of damage and burning (was created to sort by name without prefix
358          * in additional inventory)
359          * @param with_contents determines whether to add a suffix with the full name of the contents
360          * of this item (if with_contents = false and item is not empty, "n items" will be added)
361          */
362         std::string tname( unsigned int quantity = 1, bool with_prefix = true,
363                            unsigned int truncate = 0, bool with_contents = true ) const;
364         std::string display_money( unsigned int quantity, unsigned int total,
365                                    const cata::optional<unsigned int> &selected = cata::nullopt ) const;
366         /**
367          * Returns the item name and the charges or contained charges (if the item can have
368          * charges at all). Calls @ref tname with given quantity and with_prefix being true.
369          */
370         std::string display_name( unsigned int quantity = 1 ) const;
371         /**
372          * Return all the information about the item and its type.
373          *
374          * This includes the different
375          * properties of the @ref itype (if they are visible to the player). The returned string
376          * is already translated and can be *very* long.
377          * @param showtext If true, shows the item description, otherwise only the properties item type.
378          */
379         std::string info( bool showtext = false ) const;
380 
381         /**
382          * Return all the information about the item and its type, and dump to vector.
383          *
384          * This includes the different
385          * properties of the @ref itype (if they are visible to the player). The returned string
386          * is already translated and can be *very* long.
387          * @param showtext If true, shows the item description, otherwise only the properties item type.
388          * @param iteminfo The properties (encapsulated into @ref iteminfo) are added to this vector,
389          * the vector can be used to compare them to properties of another item.
390          */
391         std::string info( bool showtext, std::vector<iteminfo> &iteminfo ) const;
392 
393         /**
394         * Return all the information about the item and its type, and dump to vector.
395         *
396         * This includes the different
397         * properties of the @ref itype (if they are visible to the player). The returned string
398         * is already translated and can be *very* long.
399         * @param showtext If true, shows the item description, otherwise only the properties item type.
400         * @param iteminfo The properties (encapsulated into @ref iteminfo) are added to this vector,
401         * the vector can be used to compare them to properties of another item.
402         * @param batch The batch crafting number to multiply data by
403         */
404         std::string info( bool showtext, std::vector<iteminfo> &iteminfo, int batch ) const;
405 
406         /**
407         * Return all the information about the item and its type, and dump to vector.
408         *
409         * This includes the different
410         * properties of the @ref itype (if they are visible to the player). The returned string
411         * is already translated and can be *very* long.
412         * @param parts controls which parts of the iteminfo to return.
413         * @param info The properties (encapsulated into @ref iteminfo) are added to this vector,
414         * the vector can be used to compare them to properties of another item.
415         * @param batch The batch crafting number to multiply data by
416         */
417         std::string info( std::vector<iteminfo> &info, const iteminfo_query *parts = nullptr,
418                           int batch = 1 ) const;
419         /* type specific helper functions for info() that should probably be in itype() */
420         void basic_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
421                          bool debug ) const;
422         void debug_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
423                          bool debug ) const;
424         void med_info( const item *med_item, std::vector<iteminfo> &info, const iteminfo_query *parts,
425                        int batch, bool debug ) const;
426         void food_info( const item *food_item, std::vector<iteminfo> &info, const iteminfo_query *parts,
427                         int batch, bool debug ) const;
428         void magazine_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
429                             bool debug ) const;
430         void ammo_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
431                         bool debug ) const;
432         void gun_info( const item *mod, std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
433                        bool debug ) const;
434         void gunmod_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
435                           bool debug ) const;
436         void armor_protection_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
437                                     bool debug ) const;
438         void armor_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
439                          bool debug ) const;
440         void animal_armor_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
441                                 bool debug ) const;
442         void armor_fit_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
443                              bool debug ) const;
444         void book_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
445                         bool debug ) const;
446         void battery_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
447                            bool debug ) const;
448         void tool_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
449                         bool debug ) const;
450         void component_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
451                              bool debug ) const;
452         void repair_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
453                           bool debug ) const;
454         void disassembly_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
455                                bool debug ) const;
456         void qualities_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
457                              bool debug ) const;
458         void bionic_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
459                           bool debug ) const;
460         void combat_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
461                           bool debug ) const;
462         void contents_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
463                             bool debug ) const;
464         void final_info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch,
465                          bool debug ) const;
466 
467         /**
468          * Calculate all burning calculations, but don't actually apply them to item.
469          * DO apply them to @ref fire_data argument, though.
470          * @return Amount of "burn" that would be applied to the item.
471          */
472         float simulate_burn( fire_data &frd ) const;
473         /** Burns the item. Returns true if the item was destroyed. */
474         bool burn( fire_data &frd );
475 
476         // Returns the category of this item, regardless of contents.
477         const item_category &get_category_shallow() const;
478         // Returns the category of item inside this item.
479         // "can of meat" would be food, instead of container.
480         // If there are multiple items/stacks or none then it defaults to category of this item.
481         const item_category &get_category_of_contents() const;
482 
483         class reload_option
484         {
485             public:
486                 reload_option() = default;
487 
488                 reload_option( const reload_option & );
489                 reload_option &operator=( const reload_option & );
490 
491                 reload_option( const player *who, const item *target, const item *parent,
492                                const item_location &ammo );
493 
494                 const player *who = nullptr;
495                 const item *target = nullptr;
496                 item_location ammo;
497 
498                 int qty() const {
499                     return qty_;
500                 }
501                 void qty( int val );
502 
503                 int moves() const;
504 
505                 explicit operator bool() const {
506                     return who && target && ammo && qty_ > 0;
507                 }
508 
509             private:
510                 int qty_ = 0;
511                 int max_qty = INT_MAX;
512                 const item *parent = nullptr;
513         };
514 
515         /**
516          * Reload item using ammo from location returning true if successful
517          * @param u Player doing the reloading
518          * @param ammo Location of ammo to be reloaded
519          * @param qty caps reloading to this (or fewer) units
520          */
521         bool reload( Character &u, item_location ammo, int qty );
522         // is this speedloader compatible with this item?
523         bool allows_speedloader( const itype_id &speedloader_id ) const;
524 
525         template<typename Archive>
526         void io( Archive & );
527         using archive_type_tag = io::object_archive_tag;
528 
529         void serialize( JsonOut &json ) const;
530         void deserialize( JsonIn &jsin );
531 
532         const std::string &symbol() const;
533         /**
534          * Returns the monetary value of an item.
535          * If `practical` is false, returns pre-cataclysm market value,
536          * otherwise returns approximate post-cataclysm value.
537          */
538         int price( bool practical ) const;
539 
540         /**
541          * Whether two items should stack when displayed in a inventory menu.
542          * This is different from stacks_with, when two previously non-stackable
543          * items are now stackable and mergeable because, for example, they
544          * reaches the same temperature. This is necessary to avoid misleading
545          * stacks like "3 items-count-by-charge (5)".
546          */
547         bool display_stacked_with( const item &rhs, bool check_components = false ) const;
548         bool stacks_with( const item &rhs, bool check_components = false,
549                           bool combine_liquid = false ) const;
550         /**
551          * Whether item is the same as `rhs` for RLE compression purposes.
552          * Essentially a stricter version of `stacks_with`.
553          * @return true if items are same, i.e. *this is "equal" to `item(rhs)`
554          * @note false negative results are OK
555          * @note must be transitive
556          */
557         bool same_for_rle( const item &rhs ) const;
558         /** combines two items together if possible. returns false if it fails. */
559         bool combine( const item &rhs );
560         bool can_combine( const item &rhs ) const;
561         /**
562          * Merge charges of the other item into this item.
563          * @return true if the items have been merged, otherwise false.
564          * Merging is only done for items counted by charges (@ref count_by_charges) and
565          * items that stack together (@ref stacks_with).
566          */
567         bool merge_charges( const item &rhs );
568 
569         units::mass weight( bool include_contents = true, bool integral = false ) const;
570 
571         /**
572          * Total volume of an item accounting for all contained/integrated items
573          * NOTE: Result is rounded up to next nearest milliliter when working with stackable (@ref count_by_charges) items that have fractional volume per charge.
574          * If trying to determine how many of an item can fit in a given space, @ref charges_per_volume should be used instead.
575          * @param integral if true return effective volume if this item was integrated into another
576          * @param ignore_contents if true return effective volume for the item alone, ignoring its contents
577          */
578         units::volume volume( bool integral = false, bool ignore_contents = false ) const;
579 
580         units::length length() const;
581 
582         /**
583          * Simplified, faster volume check for when processing time is important and exact volume is not.
584          * NOTE: Result is rounded up to next nearest milliliter when working with stackable (@ref count_by_charges) items that have fractional volume per charge.
585          * If trying to determine how many of an item can fit in a given space, @ref charges_per_volume should be used instead.
586          */
587         units::volume base_volume() const;
588 
589         /** Volume check for corpses, helper for base_volume(). */
590         units::volume corpse_volume( const mtype *corpse ) const;
591 
592         /**
593          * Volume to subtract when the item is collapsed or folded.
594          * @result positive value when the item increases in volume when wielded and 0 if no change.
595          */
596         units::volume collapsed_volume_delta() const;
597 
598         /** Required strength to be able to successfully lift the item unaided by equipment */
599         int lift_strength() const;
600 
601         /**
602          * @name Melee
603          *
604          * The functions here assume the item is used in melee, even if's a gun or not a weapon at
605          * all. Because the functions apply to all types of items, several of the is_* functions here
606          * may return true for the same item. This only indicates that it can be used in various ways.
607          */
608         /*@{*/
609         /**
610          * Base number of moves (@ref Creature::moves) that a single melee attack with this items
611          * takes. The actual time depends heavily on the attacker, see melee.cpp.
612          */
613         int attack_time() const;
614 
615         /** Damage of given type caused when this item is used as melee weapon */
616         int damage_melee( damage_type dt ) const;
617 
618         /** All damage types this item deals when used in melee (no skill modifiers etc. applied). */
619         damage_instance base_damage_melee() const;
620         /** All damage types this item deals when thrown (no skill modifiers etc. applied). */
621         damage_instance base_damage_thrown() const;
622 
623         /**
624         * Calculate the item's effective damage per second past armor when wielded by a
625          * character against a monster.
626          */
627         double effective_dps( const Character &guy, monster &mon ) const;
628         /**
629          * calculate effective dps against a stock set of monsters.  by default, assume g->u
630          * is wielding
631         * for_display - include monsters intended for display purposes
632          * for_calc - include monsters intended for evaluation purposes
633          * for_display and for_calc are inclusive
634                */
635         std::map<std::string, double> dps( bool for_display, bool for_calc, const Character &guy ) const;
636         std::map<std::string, double> dps( bool for_display, bool for_calc ) const;
637         /** return the average dps of the weapon against evaluation monsters */
638         double average_dps( const Character &guy ) const;
639 
640         /**
641          * Whether the character needs both hands to wield this item.
642          */
643         bool is_two_handed( const Character &guy ) const;
644 
645         /** Is this item an effective melee weapon for the given damage type? */
646         bool is_melee( damage_type dt ) const;
647 
648         /**
649          *  Is this item an effective melee weapon for any damage type?
650          *  @see item::is_gun()
651          *  @note an item can be both a gun and melee weapon concurrently
652          */
653         bool is_melee() const;
654 
655         /**
656          * The most relevant skill used with this melee weapon. Can be "null" if this is not a weapon.
657          * Note this function returns null if the item is a gun for which you can use gun_skill() instead.
658          */
659         skill_id melee_skill() const;
660         /*@}*/
661 
662         /*
663          * Max range of melee attack this weapon can be used for.
664          * Accounts for character's abilities and installed gun mods.
665          * Guaranteed to be at least 1
666          */
667         int reach_range( const Character &guy ) const;
668 
669         /*
670          * Max range of melee attack this weapon can be used for in its current state.
671          * Accounts for character's abilities and installed gun mods.
672          * Guaranteed to be at least 1
673          */
674         int current_reach_range( const Character &guy ) const;
675 
676         /**
677          * Sets time until activation for an item that will self-activate in the future.
678          **/
679         void set_countdown( int num_turns );
680 
681         /**
682          * Consumes specified charges (or fewer) from this and any contained items
683          * @param what specific type of charge required, e.g. 'battery'
684          * @param qty maximum charges to consume. On return set to number of charges not found (or zero)
685          * @param used filled with duplicates of each item that provided consumed charges
686          * @param pos position at which the charges are being consumed
687          * @param filter Must return true for use to occur.
688          * @return true if this item should be deleted (count-by-charges items with no remaining charges)
689          */
690         bool use_charges( const itype_id &what, int &qty, std::list<item> &used, const tripoint &pos,
691                           const std::function<bool( const item & )> &filter = return_true<item> );
692 
693         /**
694          * Invokes item type's @ref itype::drop_action.
695          * This function can change the item.
696          * @param pos Where is the item being placed. Note: the item isn't there yet.
697          * @return true if the item was destroyed during placement.
698          */
699         bool on_drop( const tripoint &pos );
700 
701         /**
702          * Invokes item type's @ref itype::drop_action.
703          * This function can change the item.
704          * @param pos Where is the item being placed. Note: the item isn't there yet.
705          * @param map A map object associated with that position.
706          * @return true if the item was destroyed during placement.
707          */
708         bool on_drop( const tripoint &pos, map &map );
709 
710         /**
711          * Consume a specific amount of items of a specific type.
712          * This includes this item, and any of its contents (recursively).
713          * @see item::use_charges - this is similar for items, not charges.
714          * @param it Type of consumable item.
715          * @param quantity How much to consumed.
716          * @param used On success all consumed items will be stored here.
717          * @param filter Must return true for use to occur.
718          */
719         bool use_amount( const itype_id &it, int &quantity, std::list<item> &used,
720                          const std::function<bool( const item & )> &filter = return_true<item> );
721 
722         /** Permits filthy components, should only be used as a helper in creating filters */
723         bool allow_crafting_component() const;
724 
725         // seal the item's pockets. used for crafting and spawning items.
726         bool seal();
727         /** Whether this is container. Note that container does not necessarily means it's
728          * suitable for liquids. */
729         bool is_container() const;
730 
731         /**
732          * Updates the pockets of this item to be correct based on the mods that are installed.
733          * Pockets which are modified that contain an item will be spilled
734          * NOTE: This assumes that there is always one and only one pocket where ammo goes (mag or mag well)
735          */
736         void update_modified_pockets();
737         // for pocket update stuff, which pocket is @contained in?
738         // returns a nullptr if the item is not contained, and prints a debug message
739         item_pocket *contained_where( const item &contained );
740         const item_pocket *contained_where( const item &contained ) const;
741         /** Whether this is a container which can be used to store liquids. */
742         bool is_watertight_container() const;
743         /** Whether this item has no contents at all. */
744         bool is_container_empty() const;
745         /**
746          * Whether this item has no more free capacity for its current content.
747          * @param allow_bucket Allow filling non-sealable containers
748          */
749         bool is_container_full( bool allow_bucket = false ) const;
750         /**
751          * Fill item with an item up to @amount number of items. This works for any item with container pockets.
752          * @param contained item to fill the container with.
753          * @param amount Amount to fill item with, capped by remaining capacity
754          * @returns amount of contained that was put into it
755          */
756         int fill_with( const item &contained, int amount = INFINITE_CHARGES,
757                        bool unseal_pockets = false,
758                        bool allow_sealed = false );
759 
760         /**
761          * How much more of this liquid (in charges) can be put in this container.
762          * If this is not a container (or not suitable for the liquid), it returns 0.
763          * Note that mixing different types of liquid is not possible.
764          * Also note that this works for guns and tools that accept liquid ammo.
765          * @param liquid Liquid to check capacity for
766          * @param allow_bucket Allow filling non-sealable containers
767          * @param err Message to print if no more material will fit
768          */
769         int get_remaining_capacity_for_liquid( const item &liquid, bool allow_bucket = false,
770                                                std::string *err = nullptr ) const;
771         int get_remaining_capacity_for_liquid( const item &liquid, const Character &p,
772                                                std::string *err = nullptr ) const;
773         /**
774          * It returns the maximum volume of any contents, including liquids,
775          * ammo, magazines, weapons, etc.
776          */
777         units::volume get_total_capacity() const;
778         units::mass get_total_weight_capacity() const;
779 
780         // recursive function that checks pockets for remaining free space
781         units::volume check_for_free_space() const;
782         units::volume get_selected_stack_volume( const std::map<const item *, int> &without ) const;
783         // checks if the item can have things placed in it
784         bool has_pockets() const {
785             // what has it gots in them, precious
786             return contents.has_pocket_type( item_pocket::pocket_type::CONTAINER );
787         }
788         /**
789          * Puts the given item into this one.
790          */
791         ret_val<bool> put_in( const item &payload, item_pocket::pocket_type pk_type,
792                               bool unseal_pockets = false );
793 
794         /**
795          * Returns this item into its default container. If it does not have a default container,
796          * returns this. It's intended to be used like \code newitem = newitem.in_its_container();\endcode
797          */
798         item in_its_container( int qty = INFINITE_CHARGES ) const;
799         item in_container( const itype_id &container_type, int qty = INFINITE_CHARGES,
800                            bool sealed = true ) const;
801 
802         bool item_has_uses_recursive() const;
803 
804         /*@{*/
805         /**
806          * Funnel related functions. See weather.cpp for their usage.
807          */
808         bool is_funnel_container( units::volume &bigger_than ) const;
809         void add_rain_to_container( bool acid, int charges = 1 );
810         /*@}*/
811 
812         int get_quality( const quality_id &id ) const;
813         bool count_by_charges() const;
814 
815         /**
816          * If count_by_charges(), returns charges, otherwise 1
817          */
818         int count() const;
819         bool craft_has_charges();
820 
821         /**
822          * Modify the charges of this item, only use for items counted by charges!
823          * The item must have enough charges for this (>= quantity) and be counted
824          * by charges.
825          * @param mod How many charges should be removed.
826          */
827         void mod_charges( int mod );
828 
829         /**
830          * Accumulate rot of the item since last rot calculation.
831          * This function should not be called directly. since it does not have all the needed checks or temperature calculations.
832          * If you need to calc rot of item call process_temperature_rot instead.
833          * @param time Time point to which rot is calculated
834          * @param temp Temperature at which the rot is calculated
835          */
836         void calc_rot( int temp, float spoil_modifier, const time_duration &time_delta );
837 
838         /**
839          * This is part of a workaround so that items don't rot away to nothing if the smoking rack
840          * is outside the reality bubble.
841          * @param processing_duration
842          */
843         void calc_rot_while_processing( time_duration processing_duration );
844 
845         /**
846          * Update temperature for things like food
847          * Update rot for things that perish
848          * All items that rot also have temperature
849          * @param insulation Amount of insulation item has from surroundings
850          * @param pos The current position
851          * @param carrier The current carrier
852          * @param flag to specify special temperature situations
853          * @return true if the item is fully rotten and is ready to be removed
854          */
855         bool process_temperature_rot( float insulation, const tripoint &pos, player *carrier,
856                                       temperature_flag flag = temperature_flag::NORMAL, float spoil_modifier = 1.0f );
857 
858         /** Set the item to HOT and resets last_temp_check */
859         void heat_up();
860 
861         /** Set the item to COLD and resets last_temp_check*/
862         void cold_up();
863 
864         /** Sets the item temperature and item energy from new temperature (K) and resets last_temp_check */
865         void set_item_temperature( float new_temperature );
866 
867         /** Sets the item to new temperature and energy based new specific energy (J/g) and resets last_temp_check*/
868         void set_item_specific_energy( float specific_energy );
869 
870         /** reset the last_temp_check used when crafting new items and the like */
871         void reset_temp_check();
872 
873         int get_comestible_fun() const;
874 
875         /** whether an item is perishable (can rot) */
876         bool goes_bad() const;
877 
878         /** Get the shelf life of the item*/
879         time_duration get_shelf_life() const;
880 
881         /** Get @ref rot value relative to shelf life (or 0 if item does not spoil) */
882         double get_relative_rot() const;
883 
884         /** Set current item @ref rot relative to shelf life (no-op if item does not spoil) */
885         void set_relative_rot( double val );
886 
887         void set_rot( time_duration val );
888 
889         /**
890          * Get minimum time for this item or any of its contents to rot, ignoring
891          * fridge. If this item is a container, its spoil multiplier is taken into
892          * account, but the spoil multiplier of the parent container of this item,
893          * if any, is not.
894          *
895          * If this item does not rot and none of its contents rot either, the function
896          * returns INT_MAX - N,
897          *
898          * where N is
899          * 3 for food,
900          * 2 for medication,
901          * 1 for other comestibles,
902          * 0 otherwise.
903          */
904         int spoilage_sort_order() const;
905 
906         /** an item is fresh if it is capable of rotting but still has a long shelf life remaining */
907         bool is_fresh() const {
908             return goes_bad() && get_relative_rot() < 0.1;
909         }
910 
911         /** an item is about to become rotten when shelf life has nearly elapsed */
912         bool is_going_bad() const {
913             return get_relative_rot() > 0.9;
914         }
915 
916         /** returns true if item is now rotten after all shelf life has elapsed */
917         bool rotten() const {
918             return get_relative_rot() > 1.0;
919         }
920 
921         /**
922          * Whether the item has enough rot that it should get removed.
923          * Regular shelf life perishable foods rot away completely at 2x shelf life. Corpses last 10 days
924          * @return true if the item has enough rot to be removed, false otherwise.
925          */
926         bool has_rotten_away() const;
927 
928         /** remove frozen tag and if it takes freezerburn, applies mushy/rotten */
929         void apply_freezerburn();
930 
931         time_duration get_rot() const {
932             return rot;
933         }
934         void mod_rot( const time_duration &val ) {
935             rot += val;
936         }
937 
938         /** Time for this item to be fully fermented. */
939         time_duration brewing_time() const;
940         /** The results of fermenting this item. */
941         const std::vector<itype_id> &brewing_results() const;
942 
943         /**
944          * Detonates the item and adds remains (if any) to drops.
945          * Returns true if the item actually detonated,
946          * potentially destroying other items and invalidating iterators.
947          * Should NOT be called on an item on the map, but on a local copy.
948          */
949         bool detonate( const tripoint &p, std::vector<item> &drops );
950 
951         bool will_explode_in_fire() const;
952 
953         /**
954          * @name Material(s) of the item
955          *
956          * Each item is made of one or more materials (@ref material_type). Materials have
957          * properties that affect properties of the item (e.g. resistance against certain
958          * damage types).
959          *
960          * Additionally, items have a phase property (@ref phase_id). This is independent of
961          * the material types (there can be solid items made of X and liquid items made of the same
962          * material).
963          *
964          * Corpses inherit the material of the monster type.
965          */
966         /*@{*/
967         /**
968          * Get a material reference to a random material that this item is made of.
969          * This might return the null-material, you may check this with @ref material_type::ident.
970          * Note that this may also return a different material each time it's invoked (if the
971          * item is made from several materials).
972          */
973         const material_type &get_random_material() const;
974         /**
975          * Get the basic (main) material of this item. May return the null-material.
976          */
977         const material_type &get_base_material() const;
978         /**
979          * The ids of all the materials this is made of.
980          * This may return an empty vector.
981          * The returned vector does not contain the null id.
982          */
983         const std::vector<material_id> &made_of() const;
984         /**
985         * The ids of all the qualities this contains.
986         */
987         const std::map<quality_id, int> &quality_of() const;
988         /**
989          * Same as @ref made_of(), but returns the @ref material_type directly.
990          */
991         std::vector<const material_type *> made_of_types() const;
992         /**
993          * Check we are made of at least one of a set (e.g. true if at least
994          * one item of the passed in set matches any material).
995          * @param mat_idents Set of material ids.
996          */
997         bool made_of_any( const std::set<material_id> &mat_idents ) const;
998         /**
999          * Check we are made of only the materials (e.g. false if we have
1000          * one material not in the set or no materials at all).
1001          * @param mat_idents Set of material ids.
1002          */
1003         bool only_made_of( const std::set<material_id> &mat_idents ) const;
1004         /**
1005          * Check we are made of this material (e.g. matches at least one
1006          * in our set.)
1007          */
1008         bool made_of( const material_id &mat_ident ) const;
1009         /**
1010          * Are we solid, liquid, gas, plasma?
1011          */
1012         bool made_of( phase_id phase ) const;
1013         bool made_of_from_type( phase_id phase ) const;
1014         /**
1015          * Returns a list of components used to craft this item or the default
1016          * components if it wasn't player-crafted.
1017          */
1018         std::vector<item_comp> get_uncraft_components() const;
1019         /**
1020          * Whether the items is conductive.
1021          */
1022         bool conductive() const;
1023         /**
1024          * Whether the items is flammable. (Make sure to keep this in sync with
1025          * fire code in fields.cpp)
1026          * @param threshold Item is flammable if it provides more fuel than threshold.
1027          */
1028         bool flammable( int threshold = 0 ) const;
1029         /**
1030         * Whether the item can be repaired beyond normal health.
1031         */
1032         bool reinforceable() const;
1033         /*@}*/
1034 
1035         /**
1036          * Resistance against different damage types (@ref damage_type).
1037          * Larger values means more resistance are thereby better, but there is no absolute value to
1038          * compare them to. The values can be interpreted as chance (@ref one_in) of damaging the item
1039          * when exposed to the type of damage.
1040          * @param to_self If this is true, it returns item's own resistance, not one it gives to wearer.
1041          * @param base_env_resist Will override the base environmental
1042          * resistance (to allow hypothetical calculations for gas masks).
1043          */
1044         /*@{*/
1045         float acid_resist( bool to_self = false, int base_env_resist = 0 ) const;
1046         float fire_resist( bool to_self = false, int base_env_resist = 0 ) const;
1047         float bash_resist( bool to_self = false ) const;
1048         float cut_resist( bool to_self = false )  const;
1049         float stab_resist( bool to_self = false ) const;
1050         float bullet_resist( bool to_self = false ) const;
1051         /*@}*/
1052 
1053         /**
1054          * Assuming that specified du hit the armor, reduce du based on the item's resistance to the
1055          * damage type. This will never reduce du.amount below 0.
1056          */
1057         void mitigate_damage( damage_unit &du ) const;
1058         /**
1059          * Resistance provided by this item against damage type given by an enum.
1060          */
1061         float damage_resist( damage_type dt, bool to_self = false ) const;
1062 
1063         /**
1064          * Returns resistance to being damaged by attack against the item itself.
1065          * Calculated from item's materials.
1066          * @param worst If this is true, the worst resistance is used. Otherwise the best one.
1067          */
1068         int chip_resistance( bool worst = false ) const;
1069 
1070         /** How much damage has the item sustained? */
1071         int damage() const;
1072 
1073         /**
1074          * Scale item damage to the given number of levels. This function is
1075          * here mostly for back-compatibility. It should not be used when
1076          * doing continuous math with the damage value: use damage() instead.
1077          *
1078          * For example, for min_damage = -1000, max_damage = 4000
1079          *   damage       level
1080          *   -1000 ~   -1    -1
1081          *              0     0
1082          *       1 ~ 1333     1
1083          *    1334 ~ 2666     2
1084          *    2667 ~ 3999     3
1085          *           4000     4
1086          */
1087         int damage_level() const;
1088 
1089         /** Minimum amount of damage to an item (state of maximum repair) */
1090         int min_damage() const;
1091 
1092         /** Maximum amount of damage to an item (state before destroyed) */
1093         int max_damage() const;
1094 
1095         /**
1096          * Relative item health.
1097          * Returns 1 for undamaged ||items, values in the range (0, 1) for damaged items
1098          * and values above 1 for reinforced ++items.
1099          */
1100         float get_relative_health() const;
1101 
1102         /**
1103          * Apply damage to const itemrained by @ref min_damage and @ref max_damage
1104          * @param qty maximum amount by which to adjust damage (negative permissible)
1105          * @param dt type of damage which may be passed to @ref on_damage callback
1106          * @return whether item should be destroyed
1107          */
1108         bool mod_damage( int qty, damage_type dt );
1109         /// same as other mod_damage, but uses @ref damage_type::NONE as damage type.
1110         bool mod_damage( int qty );
1111 
1112         /**
1113          * Increment item damage by @ref itype::damage_scale constrained by @ref max_damage
1114          * @param dt type of damage which may be passed to @ref on_damage callback
1115          * @return whether item should be destroyed
1116          */
1117         bool inc_damage( damage_type dt );
1118         /// same as other inc_damage, but uses @ref damage_type::NONE as damage type.
1119         bool inc_damage();
1120 
1121         /** Provide color for UI display dependent upon current item damage level */
1122         nc_color damage_color() const;
1123 
1124         /** Provide prefix symbol for UI display dependent upon current item damage level */
1125         std::string damage_symbol() const;
1126 
1127         /**
1128          * Provides a prefix for the durability state of the item. with ITEM_HEALTH_BAR enabled,
1129          * returns a symbol with color tag already applied. Otherwise, returns an adjective.
1130          * if include_intact is true, this provides a string for the corner case of a player
1131          * with ITEM_HEALTH_BAR disabled, but we need still a string for some reason.
1132          */
1133         std::string durability_indicator( bool include_intact = false ) const;
1134 
1135         /** If possible to repair this item what tools could potentially be used for this purpose? */
1136         const std::set<itype_id> &repaired_with() const;
1137 
1138         /**
1139          * Check whether the item has been marked (by calling mark_as_used_by_player)
1140          * as used by this specific player.
1141          */
1142         bool already_used_by_player( const Character &p ) const;
1143         /**
1144          * Marks the item as being used by this specific player, it remains unmarked
1145          * for other players. The player is identified by its id.
1146          */
1147         void mark_as_used_by_player( const player &p );
1148         /** Marks the item as filthy, so characters with squeamish trait can't wear it.
1149         */
1150         bool is_filthy() const;
1151         /**
1152          * This is called once each turn. It's usually only useful for active items,
1153          * but can be called for inactive items without problems.
1154          * It is recursive, and calls process on any contained items.
1155          * @param carrier The player / npc that carries the item. This can be null when
1156          * the item is not carried by anyone (laying on ground)!
1157          * @param pos The location of the item on the map, same system as
1158          * @ref player::pos used. If the item is carried, it should be the
1159          * location of the carrier.
1160          * @param activate Whether the item should be activated (true), or
1161          * processed as an active item.
1162          * @param spoil_multiplier_parent is the spoilage multiplier passed down from any parent item
1163          * @return true if the item has been destroyed by the processing. The caller
1164          * should than delete the item wherever it was stored.
1165          * Returns false if the item is not destroyed.
1166          */
1167         bool process( player *carrier, const tripoint &pos, float insulation = 1,
1168                       temperature_flag flag = temperature_flag::NORMAL, float spoil_multiplier_parent = 1.0f );
1169 
1170         /**
1171          * Gets the point (vehicle tile) the cable is connected to.
1172          * Returns nothing if not connected to anything.
1173          */
1174         cata::optional<tripoint> get_cable_target( Character *p, const tripoint &pos ) const;
1175         /**
1176          * Helper to bring a cable back to its initial state.
1177          */
1178         void reset_cable( player *p );
1179 
1180         /**
1181          * Whether the item should be processed (by calling @ref process).
1182          */
1183         bool needs_processing() const;
1184         /**
1185          * The rate at which an item should be processed, in number of turns between updates.
1186          */
1187         int processing_speed() const;
1188         /**
1189          * Process and apply artifact effects. This should be called exactly once each turn, it may
1190          * modify character stats (like speed, strength, ...), so call it after those have been reset.
1191          * @param carrier The character carrying the artifact, can be null.
1192          * @param pos The location of the artifact (should be the player location if carried).
1193          */
1194         void process_relic( Character *carrier, const tripoint &pos );
1195 
1196         void overwrite_relic( const relic &nrelic );
1197 
1198         bool destroyed_at_zero_charges() const;
1199         // Most of the is_whatever() functions call the same function in our itype
1200         bool is_null() const; // True if type is NULL, or points to the null item (id == 0)
1201         bool is_comestible() const;
1202         bool is_food() const;                // Ignoring the ability to eat batteries, etc.
1203         bool is_food_container() const;      // Ignoring the ability to eat batteries, etc.
1204         bool is_ammo_container() const; // does this item contain ammo? (excludes magazines)
1205         bool is_medication() const;            // Is it a medication that only pretends to be food?
1206         bool is_bionic() const;
1207         bool is_magazine() const;
1208         bool is_battery() const;
1209         bool is_ammo_belt() const;
1210         bool is_holster() const;
1211         bool is_ammo() const;
1212         // is this armor for a pet creature?  if on_pet is true, returns false if a pet isn't
1213         // wearing it
1214         bool is_pet_armor( bool on_pet = false ) const;
1215         bool is_armor() const;
1216         bool is_book() const;
1217         bool is_map() const;
1218         bool is_salvageable() const;
1219         bool is_disassemblable() const;
1220         bool is_craft() const;
1221 
1222         bool is_deployable() const;
1223         bool is_tool() const;
1224         bool is_transformable() const;
1225         bool is_relic() const;
1226         bool is_bucket_nonempty() const;
1227 
1228         bool is_brewable() const;
1229         bool is_engine() const;
1230         bool is_wheel() const;
1231         bool is_fuel() const;
1232         bool is_toolmod() const;
1233 
1234         bool is_faulty() const;
1235         bool is_irremovable() const;
1236 
1237         bool is_unarmed_weapon() const; //Returns true if the item should be considered unarmed
1238 
1239         bool has_temperature() const;
1240 
1241         /** Returns true if the item is A: is SOLID and if it B: is of type LIQUID */
1242         bool is_frozen_liquid() const;
1243 
1244         float get_specific_heat_liquid() const;
1245         float get_specific_heat_solid() const;
1246         float get_latent_heat() const;
1247         float get_freeze_point() const; // Fahrenheit
1248 
1249         // If this is food, returns itself.  If it contains food, return that
1250         // contents.  Otherwise, returns nullptr.
1251         item *get_food();
1252         const item *get_food() const;
1253 
1254         void set_last_temp_check( const time_point &pt );
1255 
1256         /** What faults can potentially occur with this item? */
1257         std::set<fault_id> faults_potential() const;
1258 
1259         /** Returns the total area of this wheel or 0 if it isn't one. */
1260         int wheel_area() const;
1261 
1262         /** Returns energy of one charge of this item as fuel for an engine. */
1263         float fuel_energy() const;
1264         /** Returns the string of the id of the terrain that pumps this fuel, if any. */
1265         std::string fuel_pump_terrain() const;
1266         bool has_explosion_data() const;
1267         fuel_explosion_data get_explosion_data();
1268 
1269         /**
1270          * Can this item have given item/itype as content?
1271          *
1272          * For example, airtight for gas, acidproof for acid etc.
1273          */
1274         /*@{*/
1275         bool can_contain( const item &it ) const;
1276         bool can_contain( const itype &tp ) const;
1277         bool can_contain_partial( const item &it ) const;
1278         /*@}*/
1279         std::pair<item_location, item_pocket *> best_pocket( const item &it, item_location &parent,
1280                 bool allow_sealed = false );
1281 
1282         units::length max_containable_length() const;
1283         units::volume max_containable_volume() const;
1284 
1285         /**
1286          * Is it ever possible to reload this item?
1287          * Only the base item is considered with any mods ignored
1288          * @see player::can_reload()
1289          */
1290         bool is_reloadable() const;
1291         /** Returns true if this item can be reloaded with specified ammo type, ignoring capacity. */
1292         bool can_reload_with( const itype_id &ammo ) const;
1293         /** Returns true if this item can be reloaded with specified ammo type at this moment. */
1294         bool is_reloadable_with( const itype_id &ammo ) const;
1295         /**
1296           * Returns true if any of the contents are not frozen or not empty if it's liquid
1297           */
1298         bool can_unload_liquid() const;
1299 
1300         bool is_dangerous() const; // Is it an active grenade or something similar that will hurt us?
1301 
1302         /** Is item derived from a zombie? */
1303         bool is_tainted() const;
1304 
1305         /**
1306          * Is this item flexible enough to be worn on body parts like antlers?
1307          */
1308         bool is_soft() const;
1309 
1310         /**
1311          * Set the snippet text (description) of this specific item, using the snippet library.
1312          * @see snippet_library.
1313          */
1314         void set_snippet( const snippet_id &id );
1315 
1316         bool operator<( const item &other ) const;
1317         /** List of all @ref components in printable form, empty if this item has
1318          * no components */
1319         std::string components_to_string() const;
1320 
1321         /** Creates a hash from the itype_ids of this item's @ref components. */
1322         uint64_t make_component_hash() const;
1323 
1324         /** return the unique identifier of the items underlying type */
1325         itype_id typeId() const;
1326 
1327         /**
1328           * if the item will spill if placed into a container
1329           */
1330         bool will_spill() const;
1331         bool will_spill_if_unsealed() const;
1332         /**
1333          * Unloads the item's contents.
1334          * @param c Character who receives the contents.
1335          *          If c is the player, liquids will be handled, otherwise they will be spilled.
1336          * @return If the item is now empty.
1337          */
1338         bool spill_contents( Character &c );
1339         /**
1340          * Unloads the item's contents.
1341          * @param pos Position to dump the contents on.
1342          * @return If the item is now empty.
1343          */
1344         bool spill_contents( const tripoint &pos );
1345 
1346         /** Checks if item is a holster and currently capable of storing obj
1347          *  @param obj object that we want to holster
1348          *  @param ignore only check item is compatible and ignore any existing contents
1349          */
1350         bool can_holster( const item &obj, bool ignore = false ) const;
1351 
1352         /**
1353          * Callback when a character starts wearing the item. The item is already in the worn
1354          * items vector and is called from there.
1355          */
1356         void on_wear( Character &p );
1357         /**
1358          * Callback when a character takes off an item. The item is still in the worn items
1359          * vector but will be removed immediately after the function returns
1360          */
1361         void on_takeoff( Character &p );
1362 
1363         /**
1364          * Calculate (but do not deduct) the number of moves required to wield this weapon
1365          */
1366         int on_wield_cost( const player &p ) const;
1367 
1368         /**
1369          * Callback when a player starts wielding the item. The item is already in the weapon
1370          * slot and is called from there.
1371          * @param p player that has started wielding item
1372          * @param mv number of moves *already* spent wielding the weapon
1373          */
1374         void on_wield( player &p );
1375         /**
1376          * Callback when a player starts carrying the item. The item is already in the inventory
1377          * and is called from there. This is not called when the item is added to the inventory
1378          * from worn vector or weapon slot. The item is considered already carried.
1379          */
1380         void on_pickup( Character &p );
1381         /**
1382          * Callback when contents of the item are affected in any way other than just processing.
1383          */
1384         void on_contents_changed();
1385 
1386         /**
1387          * Callback immediately **before** an item is damaged
1388          * @param qty maximum damage that will be applied (constrained by @ref max_damage)
1389          * @param dt type of damage (or damage_type::NONE)
1390          */
1391         void on_damage( int qty, damage_type dt );
1392 
1393         bool use_relic( Character &guy, const tripoint &pos );
1394         bool has_relic_recharge() const;
1395         bool has_relic_activation() const;
1396         std::vector<trait_id> mutations_from_wearing( const Character &guy ) const;
1397 
1398         /**
1399          * Name of the item type (not the item), with proper plural.
1400          * This is only special when the item itself has a special name ("name" entry in
1401          * @ref item_tags) or is a named corpse.
1402          * It's effectively the same as calling @ref nname with the item type id. Use this when
1403          * the actual item is not meant, for example "The shovel" instead of "Your shovel".
1404          * Or "The jacket is too small", when it applies to all jackets, not just the one the
1405          * character tried to wear).
1406          */
1407         std::string type_name( unsigned int quantity = 1 ) const;
1408 
1409         /**
1410          * Number of (charges of) this item that fit into the given volume.
1411          * May return 0 if not even one charge fits into the volume. Only depends on the *type*
1412          * of this item not on its current charge count.
1413          *
1414          * For items not counted by charges, this returns vol / this->volume().
1415          */
1416         int charges_per_volume( const units::volume &vol ) const;
1417         int charges_per_weight( const units::mass &m ) const;
1418 
1419         /**
1420          * @name Item variables
1421          *
1422          * Item variables can be used to store any value in the item. The storage is persistent,
1423          * it remains through saving & loading, it is copied when the item is moved etc.
1424          * Each item variable is referred to by its name, so make sure you use a name that is not
1425          * already used somewhere.
1426          * You can directly store integer, floating point and string values. Data of other types
1427          * must be converted to one of those to be stored.
1428          * The set_var functions override the existing value.
1429          * The get_var function return the value (if the variable exists), or the default value
1430          * otherwise.  The type of the default value determines which get_var function is used.
1431          * All numeric values are returned as doubles and may be cast to the desired type.
1432          * <code>
1433          * int v = itm.get_var("v", 0); // v will be an int
1434          * double d = itm.get_var("v", 0.0); // d will be a double
1435          * std::string s = itm.get_var("v", ""); // s will be a std::string
1436          * // no default means empty string as default:
1437          * auto n = itm.get_var("v"); // v will be a std::string
1438          * </code>
1439          */
1440         /*@{*/
1441         void set_var( const std::string &name, int value );
1442         void set_var( const std::string &name, long long value );
1443         // Acceptable to use long as part of overload set
1444         // NOLINTNEXTLINE(cata-no-long)
1445         void set_var( const std::string &name, long value );
1446         void set_var( const std::string &name, double value );
1447         double get_var( const std::string &name, double default_value ) const;
1448         void set_var( const std::string &name, const tripoint &value );
1449         tripoint get_var( const std::string &name, const tripoint &default_value ) const;
1450         void set_var( const std::string &name, const std::string &value );
1451         std::string get_var( const std::string &name, const std::string &default_value ) const;
1452         /** Get the variable, if it does not exists, returns an empty string. */
1453         std::string get_var( const std::string &name ) const;
1454         /** Whether the variable is defined at all. */
1455         bool has_var( const std::string &name ) const;
1456         /** Erase the value of the given variable. */
1457         void erase_var( const std::string &name );
1458         /** Removes all item variables. */
1459         void clear_vars();
1460         /*@}*/
1461 
1462         /**
1463          * @name Item flags
1464          *
1465          * If you use any new flags, add them to `flags.json`,
1466          * add a comment to doc/JSON_FLAGS.md and make sure your new
1467          * flag does not conflict with any existing flag.
1468          *
1469          * Item flags are taken from the item type (@ref itype::item_tags), but also from the
1470          * item itself (@ref item_tags). The item has the flag if it appears in either set.
1471          *
1472          * Gun mods that are attached to guns also contribute their flags to the gun item.
1473          */
1474         /*@{*/
1475         bool has_flag( const flag_id &flag ) const;
1476 
1477         template<typename Container, typename T = std::decay_t<decltype( *std::declval<const Container &>().begin() )>>
1478         bool has_any_flag( const Container &flags ) const {
1479             return std::any_of( flags.begin(), flags.end(), [&]( const T & flag ) {
1480                 return has_flag( flag );
1481             } );
1482         }
1483 
1484         /**
1485          * Checks whether item itself has given flag (doesn't check item type or gunmods).
1486          * Essentially get_flags().count(f).
1487          * Works faster than `has_flag`
1488         */
1489         bool has_own_flag( const flag_id &f ) const;
1490 
1491         /** returs read-only set of flags of this item (not including flags from item type or gunmods) */
1492         const FlagsSetType &get_flags() const;
1493 
1494         /** Idempotent filter setting an item specific flag. */
1495         item &set_flag( const flag_id &flag );
1496 
1497         /** Idempotent filter removing an item specific flag */
1498         item &unset_flag( const flag_id &flag );
1499 
1500         /** Idempotent filter recursively setting an item specific flag on this item and its components. */
1501         item &set_flag_recursive( const flag_id &flag );
1502 
1503         /** Removes all item specific flags. */
1504         void unset_flags();
1505         /*@}*/
1506 
1507         /**Does this item have the specified fault*/
1508         bool has_fault( const fault_id &fault ) const;
1509 
1510         /** Does this item part have a fault with this flag */
1511         bool has_fault_flag( const std::string &searched_flag ) const;
1512 
1513         /**
1514          * @name Item properties
1515          *
1516          * Properties are specific to an item type so unlike flags the meaning of a property
1517          * may not be the same for two different item types. Each item type can have multiple
1518          * properties however duplicate property names are not permitted.
1519          *
1520          */
1521         /*@{*/
1522         bool has_property( const std::string &prop ) const;
1523         /**
1524           * Get typed property for item.
1525           * Return same type as the passed default value, or string where no default provided
1526           */
1527         std::string get_property_string( const std::string &prop, const std::string &def = "" ) const;
1528         int64_t get_property_int64_t( const std::string &prop, int64_t def = 0 ) const;
1529         /*@}*/
1530 
1531         /**
1532          * @name Light emitting items
1533          *
1534          * Items can emit light either through the definition of their type
1535          * (@ref itype::light_emission) or through an item specific light data (@ref light).
1536          */
1537         /*@{*/
1538         /**
1539          * Directional light emission of the item.
1540          * @param luminance The amount of light (see lightmap.cpp)
1541          * @param width If greater 0, the light is emitted in an arc, this is the angle of it.
1542          * @param direction The direction of the light arc. In degrees.
1543          */
1544         bool getlight( float &luminance, units::angle &width, units::angle &direction ) const;
1545         /**
1546          * How much light (see lightmap.cpp) the item emits (it's assumed to be circular).
1547          */
1548         int getlight_emit() const;
1549         /**
1550          * Whether the item emits any light at all.
1551          */
1552         bool is_emissive() const;
1553         /*@}*/
1554 
1555         /**
1556          * @name Seed data.
1557          */
1558         /*@{*/
1559         /**
1560          * Whether this is actually a seed, the seed functions won't be of much use for non-seeds.
1561          */
1562         bool is_seed() const;
1563         /**
1564          * Time it takes to grow from one stage to another. There are 4 plant stages:
1565          * seed, seedling, mature and harvest. Non-seed items return 0.
1566          */
1567         time_duration get_plant_epoch() const;
1568         /**
1569          * The name of the plant as it appears in the various informational menus. This should be
1570          * translated. Returns an empty string for non-seed items.
1571          */
1572         std::string get_plant_name() const;
1573         /*@}*/
1574 
1575         /**
1576          * @name Armor related functions.
1577          *
1578          * The functions here refer to values from @ref islot_armor. They only apply to armor items,
1579          * those items can be worn. The functions are safe to call for any item, for non-armor they
1580          * return a default value.
1581          */
1582         /*@{*/
1583         /**
1584          * Whether this item (when worn) covers the given body part.
1585          */
1586         bool covers( const bodypart_id &bp ) const;
1587         /**
1588          * Bitset of all covered body parts.
1589          *
1590          * If the bit is set, the body part is covered by this
1591          * item (when worn). The index of the bit should be a body part, for example:
1592          * @code if( some_armor.get_covered_body_parts().test( bp_head ) ) { ... } @endcode
1593          * For testing only a single body part, use @ref covers instead. This function allows you
1594          * to get the whole covering data in one call.
1595          */
1596         body_part_set get_covered_body_parts() const;
1597         /**
1598         * Bitset of all covered body parts, from a specific side.
1599         *
1600         * If the bit is set, the body part is covered by this
1601         * item (when worn). The index of the bit should be a body part, for example:
1602         * @code if( some_armor.get_covered_body_parts().test( bp_head ) ) { ... } @endcode
1603         * For testing only a single body part, use @ref covers instead. This function allows you
1604         * to get the whole covering data in one call.
1605         *
1606         * @param s Specifies the side. Will be ignored for non-sided items.
1607         */
1608         body_part_set get_covered_body_parts( side s ) const;
1609         /**
1610           * Returns true if item is armor and can be worn on different sides of the body
1611           */
1612         bool is_sided() const;
1613         /**
1614          *  Returns side item currently worn on. Returns BOTH if item is not sided or no side currently set
1615          */
1616         side get_side() const;
1617         /**
1618           * Change the side on which the item is worn. Returns false if the item is not sided
1619           */
1620         bool set_side( side s );
1621 
1622         /**
1623          * Swap the side on which the item is worn. Returns false if the item is not sided
1624          */
1625         bool swap_side();
1626         /**
1627          * Returns the warmth value that this item has when worn. See player class for temperature
1628          * related code, or @ref player::warmth. Returned values should be positive. A value
1629          * of 0 indicates no warmth from this item at all (this is also the default for non-armor).
1630          */
1631         int get_warmth() const;
1632         /**
1633          * Returns the @ref islot_armor::thickness value, or 0 for non-armor. Thickness is are
1634          * relative value that affects the items resistance against bash / cutting / bullet damage.
1635          */
1636         float get_thickness() const;
1637         /**
1638          * Returns clothing layer for item.
1639          */
1640         layer_level get_layer() const;
1641 
1642         /*
1643          * Returns the average coverage of each piece of data this item
1644          */
1645         int get_avg_coverage() const;
1646         /**
1647          * Returns the highest coverage that any piece of data that this item has that covers the bodypart.
1648          * Values range from 0 (not covering anything) to 100 (covering the whole body part).
1649          * Items that cover more are more likely to absorb damage from attacks.
1650          */
1651         int get_coverage( const bodypart_id &bodypart ) const;
1652 
1653         enum class encumber_flags : int {
1654             none = 0,
1655             assume_full = 1,
1656         };
1657 
1658         const armor_portion_data *portion_for_bodypart( const bodypart_id &bodypart ) const;
1659 
1660         /**
1661          * Returns the average encumbrance value that this item across all portions
1662          * Returns 0 if this is can not be worn at all.
1663          */
1664         int get_avg_encumber( const Character &, encumber_flags = encumber_flags::none ) const;
1665 
1666         /**
1667          * Returns the encumbrance value that this item has when worn by given
1668          * player.
1669          * Returns 0 if this is can not be worn at all.
1670          */
1671         int get_encumber( const Character &, const bodypart_id &bodypart,
1672                           encumber_flags = encumber_flags::none ) const;
1673 
1674         /**
1675          * Returns the weight capacity modifier (@ref islot_armor::weight_capacity_modifier) that this item provides when worn.
1676          * For non-armor it returns 1. The modifier is multiplied with the weight capacity of the character that wears the item.
1677          */
1678         float get_weight_capacity_modifier() const;
1679         /**
1680          * Returns the weight capacity bonus (@ref islot_armor::weight_capacity_modifier) that this item provides when worn.
1681          * For non-armor it returns 0. The bonus is added to the total weight capacity of the character that wears the item.
1682          */
1683         units::mass get_weight_capacity_bonus() const;
1684         /**
1685          * Returns the resistance to environmental effects (@ref islot_armor::env_resist) that this
1686          * item provides when worn. See @ref player::get_env_resist. Higher values are better.
1687          * For non-armor it returns 0.
1688          *
1689          * @param override_base_resist Pass this to artificially increase the
1690          * base resistance, so that the function can take care of other
1691          * modifications to resistance for you. Note that this parameter will
1692          * never decrease base resistance.
1693          */
1694         int get_env_resist( int override_base_resist = 0 ) const;
1695         /**
1696          * Returns the base resistance to environmental effects if an item (for example a gas mask)
1697          * requires a gas filter to operate and this filter is installed. Used in iuse::gasmask to
1698          * change protection of a gas mask if it has (or don't has) filters. For other applications
1699          * use get_env_resist() above.
1700          */
1701         int get_base_env_resist_w_filter() const;
1702         /**
1703          * Whether this is a power armor item. Not necessarily the main armor, it could be a helmet
1704          * or similar.
1705          */
1706         bool is_power_armor() const;
1707         /**
1708          * If this is an armor item, return its armor data. You should probably not use this function,
1709          * use the various functions above (like @ref get_storage) to access armor data directly.
1710          */
1711         const islot_armor *find_armor_data() const;
1712         /**
1713          * Returns true whether this item can be worn only when @param it is worn.
1714          */
1715         bool is_worn_only_with( const item &it ) const;
1716 
1717         /**
1718          * @name Pet armor related functions.
1719          *
1720          * The functions here refer to values from @ref islot_pet_armor. They only apply to pet
1721          * armor items, those items can be worn by pets. The functions are safe to call for any
1722          * item, for non-pet armor they return a default value.
1723          */
1724         units::volume get_pet_armor_max_vol() const;
1725         units::volume get_pet_armor_min_vol() const;
1726         bodytype_id get_pet_armor_bodytype() const;
1727         /*@}*/
1728 
1729         /**
1730          * @name Books
1731          *
1732          * Book specific functions, apply to items that are books.
1733          */
1734         /*@{*/
1735         /**
1736          * translates the vector of proficiency bonuses into the container. returns an empty object if it's not a book
1737          */
1738         book_proficiency_bonuses get_book_proficiency_bonuses() const;
1739         /**
1740          * How many chapters the book has (if any). Will be 0 if the item is not a book, or if it
1741          * has no chapters at all.
1742          * Each reading will "consume" a chapter, if the book has no unread chapters, it's less fun.
1743          */
1744         int get_chapters() const;
1745         /**
1746          * Get the number of unread chapters. If the item is no book or has no chapters, it returns 0.
1747          * This is a per-character setting, different characters may have different number of
1748          * unread chapters.
1749          */
1750         int get_remaining_chapters( const Character &u ) const;
1751         /**
1752          * Mark one chapter of the book as read by the given player. May do nothing if the book has
1753          * no unread chapters. This is a per-character setting, see @ref get_remaining_chapters.
1754          */
1755         void mark_chapter_as_read( const Character &u );
1756         /**
1757          * Enumerates recipes available from this book and the skill level required to use them.
1758          */
1759         std::vector<std::pair<const recipe *, int>> get_available_recipes( const Character &u ) const;
1760         /*@}*/
1761 
1762         /**
1763          * @name Martial art techniques
1764          *
1765          * See martialarts.h for further info.
1766          */
1767         /*@{*/
1768         /**
1769          * Whether the item supports a specific martial art technique (either through its type, or
1770          * through its individual @ref techniques).
1771          */
1772         bool has_technique( const matec_id &tech ) const;
1773         /**
1774          * Returns all the martial art techniques that this items supports.
1775          */
1776         std::set<matec_id> get_techniques() const;
1777         /**
1778          * Add the given technique to the item specific @ref techniques. Note that other items of
1779          * the same type are not affected by this.
1780          */
1781         void add_technique( const matec_id &tech );
1782         /*@}*/
1783 
1784         /** Returns all toolmods currently attached to this item (always empty if item not a tool) */
1785         std::vector<item *> toolmods();
1786         std::vector<const item *> toolmods() const;
1787 
1788         /**
1789          * @name Gun and gunmod functions
1790          *
1791          * Gun and gun mod functions. Anything stated to apply to guns, applies to auxiliary gunmods
1792          * as well (they are some kind of gun). Non-guns are items that are neither gun nor
1793          * auxiliary gunmod.
1794          */
1795         /*@{*/
1796         bool is_gunmod() const;
1797 
1798         /**
1799          *  Can this item be used to perform a ranged attack?
1800          *  @see item::is_melee()
1801          *  @note an item can be both a gun and melee weapon concurrently
1802          */
1803         bool is_gun() const;
1804 
1805         /** Quantity of energy currently loaded in tool or battery */
1806         units::energy energy_remaining() const;
1807 
1808         /** Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod */
1809         int ammo_remaining() const;
1810         /**
1811          * ammo capacity for a specific ammo
1812          */
1813         int ammo_capacity( const ammotype &ammo ) const;
1814         /**
1815          * how much more ammo can fit into this item
1816          * if this item is not loaded, gives remaining capacity of its default ammo
1817          */
1818         int remaining_ammo_capacity() const;
1819         /** Quantity of ammunition consumed per usage of tool or with each shot of gun */
1820         int ammo_required() const;
1821 
1822         /**
1823          * Check if sufficient ammo is loaded for given number of uses.
1824          *
1825          * Check if there is enough ammo loaded in a tool for the given number of uses
1826          * or given number of gun shots.  Using this function for this check is preferred
1827          * because we expect to add support for items consuming multiple ammo types in
1828          * the future.  Users of this function will not need to be refactored when this
1829          * happens.
1830          *
1831          * @param[in] qty Number of uses
1832          * @returns true if ammo sufficient for number of uses is loaded, false otherwise
1833          */
1834         bool ammo_sufficient( int qty = 1 ) const;
1835 
1836         /**
1837          * Consume ammo (if available) and return the amount of ammo that was consumed
1838          * @param qty maximum amount of ammo that should be consumed
1839          * @param pos current location of item, used for ejecting magazines and similar effects
1840          * @return amount of ammo consumed which will be between 0 and qty
1841          */
1842         int ammo_consume( int qty, const tripoint &pos );
1843 
1844         /** Specific ammo data, returns nullptr if item is neither ammo nor loaded with any */
1845         const itype *ammo_data() const;
1846         /** Specific ammo type, returns "null" if item is neither ammo nor loaded with any */
1847         itype_id ammo_current() const;
1848         /** Get currently loaded ammo, if any.
1849          * @return item reference or null item if not loaded. */
1850         const item &loaded_ammo() const;
1851         /** Ammo type of an ammo item
1852          *  @return ammotype of ammo item or a null id if the item is not ammo */
1853         ammotype ammo_type() const;
1854 
1855         /** Ammo types (@ref ammunition_type) the item magazine pocket can contain.
1856          *  @param conversion whether to include the effect of any flags or mods which convert the type
1857          *  @return empty set if item does not have a magazine for a specific ammo type */
1858         std::set<ammotype> ammo_types( bool conversion = true ) const;
1859         /** Default ammo for the the item magazine pocket, if item has ammo_types().
1860          *  @param conversion whether to include the effect of any flags or mods which convert the type
1861          *  @return itype_id::NULL_ID() if item does have a magazine for a specific ammo type */
1862         itype_id ammo_default( bool conversion = true ) const;
1863 
1864         /** Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists
1865          * @param conversion whether to include the effect of any flags or mods which convert the type
1866          * @return itype_id of default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists */
1867         itype_id common_ammo_default( bool conversion = true ) const;
1868 
1869         /** Get ammo effects for item optionally inclusive of any resulting from the loaded ammo */
1870         std::set<std::string> ammo_effects( bool with_ammo = true ) const;
1871 
1872         /* Get the name to be used when sorting this item by ammo type */
1873         std::string ammo_sort_name() const;
1874 
1875         /** How many spent casings are contained within this item? */
1876         int casings_count() const;
1877 
1878         /** Apply predicate to each contained spent casing removing it if predicate returns true */
1879         void casings_handle( const std::function<bool( item & )> &func );
1880 
1881         /** Does item have an integral magazine (as opposed to allowing detachable magazines) */
1882         bool magazine_integral() const;
1883 
1884         /** Get the default magazine type (if any) for the current effective ammo type
1885          *  @param conversion whether to include the effect of any flags or mods which convert item's ammo type
1886          *  @return magazine type or "null" if item has integral magazine or no magazines for current ammo type */
1887         itype_id magazine_default( bool conversion = true ) const;
1888 
1889         /** Get compatible magazines (if any) for this item
1890          *  @param conversion whether to include the effect of any flags or mods which convert item's ammo type
1891          *  @return magazine compatibility which is always empty if item has integral magazine
1892          *  @see item::magazine_integral
1893          */
1894         std::set<itype_id> magazine_compatible( bool conversion = true ) const;
1895 
1896         /** Currently loaded magazine (if any)
1897          *  @return current magazine or nullptr if either no magazine loaded or item has integral magazine
1898          *  @see item::magazine_integral
1899          */
1900         item *magazine_current();
1901         const item *magazine_current() const;
1902 
1903         /** Returns all gunmods currently attached to this item (always empty if item not a gun) */
1904         std::vector<item *> gunmods();
1905         std::vector<const item *> gunmods() const;
1906 
1907         std::vector<const item *> mods() const;
1908 
1909         std::vector<const item *> softwares() const;
1910 
1911         /** Get first attached gunmod matching type or nullptr if no such mod or item is not a gun */
1912         item *gunmod_find( const itype_id &mod );
1913         const item *gunmod_find( const itype_id &mod ) const;
1914         /** Get first attached gunmod with flag or nullptr if no such mod or item is not a gun */
1915         item *gunmod_find_by_flag( const flag_id &flag );
1916 
1917         /*
1918          * Checks if mod can be applied to this item considering any current state (jammed, loaded etc.)
1919          * @param msg message describing reason for any incompatibility
1920          */
1921         ret_val<bool> is_gunmod_compatible( const item &mod ) const;
1922 
1923         /** Get all possible modes for this gun inclusive of any attached gunmods */
1924         std::map<gun_mode_id, gun_mode> gun_all_modes() const;
1925 
1926         /** Check if gun supports a specific mode returning an invalid/empty mode if not */
1927         gun_mode gun_get_mode( const gun_mode_id &mode ) const;
1928 
1929         /** Get the current mode for this gun (or an invalid mode if item is not a gun) */
1930         gun_mode gun_current_mode() const;
1931 
1932         /** Get id of mode a gun is currently set to, e.g. DEFAULT, AUTO, BURST */
1933         gun_mode_id gun_get_mode_id() const;
1934 
1935         /** Try to set the mode for a gun, returning false if no such mode is possible */
1936         bool gun_set_mode( const gun_mode_id &mode );
1937 
1938         /** Switch to the next available firing mode */
1939         void gun_cycle_mode();
1940 
1941         /** Get lowest dispersion of either integral or any attached sights */
1942         int sight_dispersion() const;
1943 
1944         struct sound_data {
1945             /** Volume of the sound. Can be 0 if the gun is silent (or not a gun at all). */
1946             int volume;
1947             /** Sound description, can be used with @ref sounds::sound, it is already translated. */
1948             std::string sound;
1949         };
1950         /**
1951          * Returns the sound of the gun being fired.
1952          * @param burst Whether the gun was fired in burst mode (the sound string is usually different).
1953          */
1954         sound_data gun_noise( bool burst = false ) const;
1955         /** Whether this is a (nearly) silent gun (a tiny bit of sound is allowed). Non-guns are always silent. */
1956         bool is_silent() const;
1957 
1958         /**
1959          * The weapons range in map squares. If the item has an active gunmod, it returns the range
1960          * of that gunmod, the guns range is returned only when the item has no active gunmod.
1961          * This function applies to guns and auxiliary gunmods. For other items, 0 is returned.
1962          * It includes the range given by the ammo.
1963          * @param p The player that uses the weapon, their strength might affect this.
1964          * It's optional and can be null.
1965          */
1966         int gun_range( const player *p ) const;
1967         /**
1968          * Summed range value of a gun, including values from mods. Returns 0 on non-gun items.
1969          */
1970         int gun_range( bool with_ammo = true ) const;
1971 
1972         /**
1973          *  Get effective recoil considering handling, loaded ammo and effects of attached gunmods
1974          *  @param p player stats such as STR can alter effective recoil
1975          *  @param bipod whether any bipods should be considered
1976          *  @return effective recoil (per shot) or zero if gun uses ammo and none is loaded
1977          */
1978         int gun_recoil( const player &p, bool bipod = false ) const;
1979 
1980         /**
1981          * Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods.
1982          * Returns empty instance on non-gun items.
1983          */
1984         damage_instance gun_damage( bool with_ammo = true ) const;
1985         /**
1986          * Summed dispersion of a gun, including values from mods. Returns 0 on non-gun items.
1987          */
1988         int gun_dispersion( bool with_ammo = true, bool with_scaling = true ) const;
1989         /**
1990          * The skill used to operate the gun. Can be "null" if this is not a gun.
1991          */
1992         skill_id gun_skill() const;
1993 
1994         /** Get the type of a ranged weapon (e.g. "rifle", "crossbow"), or empty string if non-gun */
1995         gun_type_type gun_type() const;
1996 
1997         /** Get mod locations, including those added by other mods */
1998         std::map<gunmod_location, int> get_mod_locations() const;
1999         /**
2000          * Number of mods that can still be installed into the given mod location,
2001          * for non-guns it always returns 0.
2002          */
2003         int get_free_mod_locations( const gunmod_location &location ) const;
2004         /**
2005          * Does it require gunsmithing tools to repair.
2006          */
2007         bool is_firearm() const;
2008         /**
2009          * Returns the reload time of the gun. Returns 0 if not a gun.
2010          */
2011         int get_reload_time() const;
2012         /*@}*/
2013 
2014         /**
2015          * @name Vehicle parts
2016          *
2017          *@{*/
2018 
2019         /** for combustion engines the displacement (cc) */
2020         int engine_displacement() const;
2021         /*@}*/
2022 
2023         /**
2024          * @name Bionics / CBMs
2025          * Functions specific to CBMs
2026          */
2027         /*@{*/
2028         /**
2029          * Whether the CBM is an upgrade to another bionic module
2030          */
2031         bool is_upgrade() const;
2032         /*@}*/
2033 
2034         /**
2035          * Returns the pointer to use_function with name use_name assigned to the type of
2036          * this item or any of its contents. Checks contents recursively.
2037          * Returns nullptr if not found.
2038          */
2039         const use_function *get_use( const std::string &use_name ) const;
2040         /**
2041          * Checks this item and its contents (recursively) for types that have
2042          * use_function with type use_name. Returns the first item that does have
2043          * such type or nullptr if none found.
2044          */
2045         item *get_usable_item( const std::string &use_name );
2046 
2047         /**
2048          * How many units (ammo or charges) are remaining?
2049          * @param ch character responsible for invoking the item
2050          * @param limit stop searching after this many units found
2051          * @note also checks availability of UPS charges if applicable
2052          */
2053         int units_remaining( const Character &ch, int limit = INT_MAX ) const;
2054 
2055         /**
2056          * Check if item has sufficient units (ammo or charges) remaining
2057          * @param ch Character to check (used if ammo is UPS charges)
2058          * @param qty units required, if unspecified use item default
2059          */
2060         bool units_sufficient( const Character &ch, int qty = -1 ) const;
2061         /**
2062          * Returns name of deceased being if it had any or empty string if not
2063          **/
2064         std::string get_corpse_name();
2065         /**
2066          * Returns the translated item name for the item with given id.
2067          * The name is in the proper plural form as specified by the
2068          * quantity parameter. This is roughly equivalent to creating an item instance and calling
2069          * @ref tname, however this function does not include strings like "(fresh)".
2070          */
2071         static std::string nname( const itype_id &id, unsigned int quantity = 1 );
2072         /**
2073          * Returns the item type of the given identifier. Never returns null.
2074          */
2075         static const itype *find_type( const itype_id &type );
2076         /**
2077          * Whether the item is counted by charges, this is a static wrapper
2078          * around @ref count_by_charges, that does not need an items instance.
2079          */
2080         static bool count_by_charges( const itype_id &id );
2081         /**
2082          * Check whether the type id refers to a known type.
2083          * This should be used either before instantiating an item when it's possible
2084          * that the item type is unknown and the caller can do something about it (e.g. the
2085          * uninstall-bionics function checks this to see if there is a CBM item type and has
2086          * logic to handle the case when that item type does not exist).
2087          * Or one can use this to check that type ids from json refer to valid items types (e.g.
2088          * the items that make up the vehicle parts must be defined somewhere, or the result of
2089          * crafting recipes must be valid type ids).
2090          */
2091         static bool type_is_defined( const itype_id &id );
2092 
2093         /**
2094         * Returns true if item has "item_label" itemvar
2095         */
2096         bool has_label() const;
2097         /**
2098         * Returns label from "item_label" itemvar and quantity
2099         */
2100         std::string label( unsigned int quantity = 0 ) const;
2101 
2102         bool has_infinite_charges() const;
2103 
2104         /** Puts the skill in context of the item */
2105         skill_id contextualize_skill( const skill_id &id ) const;
2106 
2107         /* Remove a monster from this item and spawn it.
2108          * See @game::place_critter for meaning of @p target and @p pos.
2109          * @return Whether the monster has been spawned (may fail if no space available).
2110          */
2111         bool release_monster( const tripoint &target, int radius = 0 );
2112         /* add the monster at target to this item, despawning it */
2113         int contain_monster( const tripoint &target );
2114 
2115         time_duration age() const;
2116         void set_age( const time_duration &age );
2117         time_point birthday() const;
2118         void set_birthday( const time_point &bday );
2119         void handle_pickup_ownership( Character &c );
2120         int get_gun_ups_drain() const;
2121         void validate_ownership() const;
2122         inline void set_old_owner( const faction_id &temp_owner ) {
2123             old_owner = temp_owner;
2124         }
2125         inline void remove_old_owner() const {
2126             old_owner = faction_id::NULL_ID();
2127         }
2128         inline void set_owner( const faction_id &new_owner ) {
2129             owner = new_owner;
2130         }
2131         void set_owner( const Character &c );
2132         inline void remove_owner() const {
2133             owner = faction_id::NULL_ID();
2134         }
2135         faction_id get_owner() const;
2136         faction_id get_old_owner() const;
2137         bool is_owned_by( const Character &c, bool available_to_take = false ) const;
2138         bool is_old_owner( const Character &c, bool available_to_take = false ) const;
2139         std::string get_old_owner_name() const;
2140         std::string get_owner_name() const;
2141         int get_min_str() const;
2142 
2143         const cata::value_ptr<islot_comestible> &get_comestible() const;
2144 
2145         /**
2146          * Get the stored recipe for in progress crafts.
2147          * Causes a debugmsg if called on a non-craft and returns the null recipe.
2148          * @return the recipe in progress
2149          */
2150         const recipe &get_making() const;
2151 
2152         /**
2153          * Get the failure point stored in this item.
2154          * returns INT_MAX if the failure point is unset.
2155          * Causes a debugmsg and returns INT_MAX if called on a non-craft.
2156          * @return an integer >= 0 representing a percent to 5 decimal places.
2157          *         67.32 percent would be represented as 6732000
2158          */
2159         int get_next_failure_point() const;
2160 
2161         /**
2162          * Calculates and sets the next failure point for an in progress craft.
2163          * Causes a debugmsg if called on non-craft.
2164          * @param crafter the crafting player
2165          */
2166         void set_next_failure_point( const Character &crafter );
2167 
2168         /**
2169          * Handle failure during crafting.
2170          * Destroy components, lose progress, and set a new failure point.
2171          * @param crafter the crafting player.
2172          * @return whether the craft being worked on should be entirely destroyed
2173          */
2174         bool handle_craft_failure( Character &crafter );
2175 
2176         /**
2177          * Returns requirement data representing what is needed to resume work on an in progress craft.
2178          * Causes a debugmsg and returns empty requirement data if called on a non-craft
2179          * @return what is needed to continue craft, may be empty requirement data
2180          */
2181         requirement_data get_continue_reqs() const;
2182 
2183         /**
2184          * @brief Inherit applicable flags from the given parent item.
2185          *
2186          * @param parent Item to inherit from
2187          */
2188         void inherit_flags( const item &parent, const recipe &making );
2189 
2190         /**
2191          * @brief Inherit applicable flags from the given list of parent items.
2192          *
2193          * @param parents Items to inherit from
2194          */
2195         void inherit_flags( const std::list<item> &parents, const recipe &making );
2196 
2197         void set_tools_to_continue( bool value );
2198         bool has_tools_to_continue() const;
2199         void set_cached_tool_selections( const std::vector<comp_selection<tool_comp>> &selections );
2200         const std::vector<comp_selection<tool_comp>> &get_cached_tool_selections() const;
2201 
2202         std::vector<enchantment> get_enchantments() const;
2203         double calculate_by_enchantment( const Character &owner, double modify, enchant_vals::mod value,
2204                                          bool round_value = false ) const;
2205         // calculates the enchantment value as if this item were wielded.
2206         double calculate_by_enchantment_wield( double modify, enchant_vals::mod value,
2207                                                bool round_value = false ) const;
2208 
2209         /**
2210          * Compute the number of moves needed to disassemble this item and its components
2211          * @param guy The character performing the disassembly
2212          * @return The number of moves to recursively disassemble this item
2213          */
2214         int get_recursive_disassemble_moves( const Character &guy ) const;
2215 
2216         // inherited from visitable
2217         VisitResponse visit_items( const std::function<VisitResponse( item *, item * )> &func ) const
2218         override;
2219         std::list<item> remove_items_with( const std::function<bool( const item & )> &filter,
2220                                            int count = INT_MAX ) override;
2221 
2222     private:
2223         /** migrates an item into this item. */
2224         void migrate_content_item( const item &contained );
2225 
2226         bool use_amount_internal( const itype_id &it, int &quantity, std::list<item> &used,
2227                                   const std::function<bool( const item & )> &filter = return_true<item> );
2228         const use_function *get_use_internal( const std::string &use_name ) const;
2229         bool process_internal( player *carrier, const tripoint &pos, float insulation = 1,
2230                                temperature_flag flag = temperature_flag::NORMAL, float spoil_modifier = 1.0f );
2231         void iterate_covered_body_parts_internal( side s,
2232                 std::function<void( const bodypart_str_id & )> cb ) const;
2233         /**
2234          * Calculate the thermal energy and temperature change of the item
2235          * @param temp Temperature of surroundings
2236          * @param insulation Amount of insulation item has
2237          * @param time_delta time duration from previous temperature calculation
2238          */
2239         void calc_temp( int temp, float insulation, const time_duration &time_delta );
2240 
2241         /**
2242          * Get the thermal energy of the item in Joules.
2243          */
2244         float get_item_thermal_energy() const;
2245 
2246         /** Calculates item specific energy (J/g) from temperature (K)*/
2247         float get_specific_energy_from_temperature( float new_temperature );
2248 
2249         /** Helper for checking reloadability. **/
2250         bool is_reloadable_helper( const itype_id &ammo, bool now ) const;
2251 
2252     public:
2253         enum class sizing : int {
2254             human_sized_human_char = 0,
2255             big_sized_human_char,
2256             small_sized_human_char,
2257             big_sized_big_char,
2258             human_sized_big_char,
2259             small_sized_big_char,
2260             small_sized_small_char,
2261             human_sized_small_char,
2262             big_sized_small_char,
2263             ignore
2264         };
2265 
2266         sizing get_sizing( const Character & ) const;
2267 
2268     protected:
2269         // Sub-functions of @ref process, they handle the processing for different
2270         // processing types, just to make the process function cleaner.
2271         // The interface is the same as for @ref process.
2272         bool process_corpse( player *carrier, const tripoint &pos );
2273         bool process_wet( player *carrier, const tripoint &pos );
2274         bool process_litcig( player *carrier, const tripoint &pos );
2275         bool process_extinguish( player *carrier, const tripoint &pos );
2276         // Place conditions that should remove fake smoke item in this sub-function
2277         bool process_fake_smoke( player *carrier, const tripoint &pos );
2278         bool process_fake_mill( player *carrier, const tripoint &pos );
2279         bool process_cable( player *carrier, const tripoint &pos );
2280         bool process_UPS( player *carrier, const tripoint &pos );
2281         bool process_blackpowder_fouling( player *carrier );
2282         bool process_tool( player *carrier, const tripoint &pos );
2283 
2284     public:
2285         static const int INFINITE_CHARGES;
2286 
2287         const itype *type;
2288         item_contents contents;
2289         std::list<item> components;
2290         /** What faults (if any) currently apply to this item */
2291         std::set<fault_id> faults;
2292 
2293     private:
2294         /** `true` if item has any of the flags that require processing in item::process_internal.
2295          * This flag is reset to `true` if item tags are changed.
2296          */
2297         bool requires_tags_processing = true;
2298         FlagsSetType item_tags; // generic item specific flags
2299         safe_reference_anchor anchor;
2300         const itype *curammo = nullptr;
2301         std::map<std::string, std::string> item_vars;
2302         const mtype *corpse = nullptr;
2303         std::string corpse_name;       // Name of the late lamented
2304         std::set<matec_id> techniques; // item specific techniques
2305 
2306         /**
2307          * Data for items that represent in-progress crafts.
2308          */
2309         class craft_data
2310         {
2311             public:
2312                 const recipe *making = nullptr;
2313                 int next_failure_point = -1;
2314                 std::vector<item_comp> comps_used;
2315                 // If the crafter has insufficient tools to continue to the next 5% progress step
2316                 bool tools_to_continue = false;
2317                 std::vector<comp_selection<tool_comp>> cached_tool_selections;
2318                 cata::optional<units::mass> cached_weight;
2319                 cata::optional<units::volume> cached_volume;
2320 
2321                 // if this is an in progress disassembly as opposed to craft
2322                 bool disassembly = false;
2323                 void serialize( JsonOut &jsout ) const;
2324                 void deserialize( JsonIn &jsin );
2325                 void deserialize( const JsonObject &obj );
2326         };
2327 
2328         cata::value_ptr<craft_data> craft_data_;
2329 
2330         // any relic data specific to this item
2331         cata::value_ptr<relic> relic_data;
2332     public:
2333         int charges = 0;
2334         units::energy energy = 0_mJ; // Amount of energy currently stored in a battery
2335 
2336         int recipe_charges = 1;    // The number of charges a recipe creates.
2337         int burnt = 0;             // How badly we're burnt
2338         int poison = 0;            // How badly poisoned is it?
2339         int frequency = 0;         // Radio frequency
2340         snippet_id snip_id = snippet_id::NULL_ID(); // Associated dynamic text snippet id.
2341         int irradiation = 0;       // Tracks radiation dosage.
2342         int item_counter = 0;      // generic counter to be used with item flags
2343         int specific_energy = -10; // Specific energy (0.00001 J/g). Negative value for unprocessed.
2344         int temperature = 0;       // Temperature of the item (in 0.00001 K).
2345         int mission_id = -1;       // Refers to a mission in game's master list
2346         int player_id = -1;        // Only give a mission to the right player!
2347         bool ethereal = false;
2348 
2349         // Set when the item / its content changes. Used for worn item with
2350         // encumbrance depending on their content.
2351         // This not part serialized or compared on purpose!
2352         bool encumbrance_update_ = false;
2353 
2354     private:
2355         /**
2356          * Accumulated rot, expressed as time the item has been in standard temperature.
2357          * It is compared to shelf life (@ref islot_comestible::spoils) to decide if
2358          * the item is rotten.
2359          */
2360         time_duration rot = 0_turns;
2361         /** the last time the temperature was updated for this item */
2362         time_point last_temp_check = calendar::turn_zero;
2363         /// The time the item was created.
2364         time_point bday;
2365         /**
2366          * Current phase state, inherits a default at room temperature from
2367          * itype and can be changed through item processing.  This is a static
2368          * cast to avoid importing the entire enums.h header here, zero is
2369          * PNULL.
2370          */
2371         phase_id current_phase = static_cast<phase_id>( 0 );
2372         // The faction that owns this item.
2373         mutable faction_id owner = faction_id::NULL_ID();
2374         // The faction that previously owned this item
2375         mutable faction_id old_owner = faction_id::NULL_ID();
2376         int damage_ = 0;
2377         light_emission light = nolight;
2378         mutable cata::optional<float> cached_relative_encumbrance;
2379 
2380     public:
2381         char invlet = 0;      // Inventory letter
2382         bool active = false; // If true, it has active effects to be processed
2383         bool is_favorite = false;
2384 
2385         void set_favorite( bool favorite );
2386         bool has_clothing_mod() const;
2387         float get_clothing_mod_val( clothing_mod_type type ) const;
2388         void update_clothing_mod_val();
2389 };
2390 
2391 template<>
2392 struct enum_traits<item::encumber_flags> {
2393     static constexpr bool is_flag_enum = true;
2394 };
2395 
2396 bool item_compare_by_charges( const item &left, const item &right );
2397 bool item_ptr_compare_by_charges( const item *left, const item *right );
2398 
2399 /**
2400  * Hint value used for item examination screen and filtering items by action.
2401  * Represents whether an item permits given action (reload, wear, read, etc.).
2402  */
2403 enum class hint_rating {
2404     /** Item permits this action */
2405     good,
2406     /** Item permits this action, but circumstances don't */
2407     iffy,
2408     /** Item does not permit this action */
2409     cant
2410 };
2411 
2412 // Weight per level of LIFT/JACK tool quality
2413 static constexpr units::mass TOOL_LIFT_FACTOR = 500_kilogram;
2414 
2415 inline units::mass lifting_quality_to_mass( int quality_level )
2416 {
2417     return TOOL_LIFT_FACTOR * quality_level;
2418 }
2419 
2420 /**
2421  * Returns a reference to a null item (see @ref item::is_null). The reference is always valid
2422  * and stays valid until the program ends.
2423  */
2424 item &null_item_reference();
2425 
2426 /**
2427  * Default filter for crafting component searches
2428  */
2429 inline bool is_crafting_component( const item &component )
2430 {
2431     return ( component.allow_crafting_component() || component.count_by_charges() ) &&
2432            !component.is_filthy();
2433 }
2434 
2435 #endif // CATA_SRC_ITEM_H
2436