/
item.h
2128 lines (1887 loc) · 89.3 KB
/
item.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#ifndef ITEM_H
#define ITEM_H
#include <stdint.h>
#include <climits>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <functional>
#include <memory>
#include <type_traits>
#include <utility>
#include "calendar.h"
#include "cata_utility.h"
#include "craft_command.h"
#include "debug.h"
#include "enums.h"
#include "flat_set.h"
#include "io_tags.h"
#include "item_location.h"
#include "requirements.h"
#include "safe_reference.h"
#include "string_id.h"
#include "type_id.h"
#include "units.h"
#include "visitable.h"
#include "gun_mode.h"
#include "point.h"
class item;
class material_type;
struct mtype;
class faction;
namespace cata
{
template<typename T>
class optional;
} // namespace cata
class nc_color;
class JsonIn;
class JsonOut;
class iteminfo_query;
template<typename T>
class ret_val;
class gun_type_type;
class gunmod_location;
class Character;
class player;
class recipe;
struct itype;
struct islot_comestible;
using bodytype_id = std::string;
struct islot_armor;
struct use_function;
class item_category;
enum art_effect_passive : int;
enum phase_id : int;
enum body_part : int;
enum m_size : int;
enum class side : int;
class body_part_set;
using itype_id = std::string;
struct fire_data;
struct damage_instance;
struct damage_unit;
class map;
enum damage_type : int;
enum clothing_mod_type : int;
const std::string &rad_badge_color( int rad );
struct light_emission {
unsigned short luminance;
short width;
short direction;
};
extern light_emission nolight;
/**
* Value and metadata for one property of an item
*
* Contains the value of one property of an item, as well as various metadata items required to
* output that value. This is used primarily for user output of information about an item, for
* example in the various inventory menus. See @ref item::info() for the main example of how a
* class desiring to provide user output might obtain a class of this type.
*
* As an example, if the item being queried was a piece of clothing, then several properties might
* be returned. All would have sType "ARMOR". There would be one for the coverage stat with
* sName "Coverage: ", another for the warmth stat with sName "Warmth: ", etc.
*/
struct iteminfo {
public:
/** Category of item that owns this iteminfo. See @ref item_category. */
std::string sType;
/** Main text of this property's name */
std::string sName;
/** Formatting text to be placed between the name and value of this item. */
std::string sFmt;
/** Numerical value of this property. Set to -999 if no compare value is present */
std::string sValue;
/** Internal double floating point version of value, for numerical comparisons */
double dValue;
/** Flag indicating type of sValue. True if integer, false if single decimal */
bool is_int;
/** Flag indicating whether a newline should be printed after printing this item */
bool bNewLine;
/** Reverses behavior of red/green text coloring; smaller values are green if true */
bool bLowerIsBetter;
/** Whether to print sName. If false, use for comparisons but don't print for user. */
bool bDrawName;
/** Whether to print a sign on positive values */
bool bShowPlus;
enum flags {
no_flags = 0,
is_decimal = 1 << 0, ///< Print as decimal rather than integer
no_newline = 1 << 1, ///< Do not follow with a newline
lower_is_better = 1 << 2, ///< Lower values are better for this stat
no_name = 1 << 3, ///< Do not print the name
show_plus = 1 << 4, ///< Use a + sign for positive values
};
/**
* @param Type The item type of the item this iteminfo belongs to.
* @param Name The name of the property this iteminfo describes.
* @param Fmt Formatting text desired between item name and value
* @param Flags Additional flags to customize this entry
* @param Value Numerical value of this property, -999 for none.
*/
iteminfo( const std::string &Type, const std::string &Name, const std::string &Fmt = "",
flags Flags = no_flags, double Value = -999 );
iteminfo( const std::string &Type, const std::string &Name, double Value );
};
inline iteminfo::flags operator|( iteminfo::flags l, iteminfo::flags r )
{
using I = std::underlying_type<iteminfo::flags>::type;
return static_cast<iteminfo::flags>( static_cast<I>( l ) | r );
}
inline iteminfo::flags &operator|=( iteminfo::flags &l, iteminfo::flags r )
{
return l = l | r;
}
inline bool is_crafting_component( const item &component );
class item : public visitable<item>
{
public:
item();
item( item && ) = default;
item( const item & ) = default;
item &operator=( item && ) = default;
item &operator=( const item & ) = default;
explicit item( const itype_id &id, time_point turn = calendar::turn, int qty = -1 );
explicit item( const itype *type, time_point turn = calendar::turn, int qty = -1 );
/** Suppress randomization and always start with default quantity of charges */
struct default_charges_tag {};
item( const itype_id &id, time_point turn, default_charges_tag );
item( const itype *type, time_point turn, default_charges_tag );
/** Default (or randomized) charges except if counted by charges then only one charge */
struct solitary_tag {};
item( const itype_id &id, time_point turn, solitary_tag );
item( const itype *type, time_point turn, solitary_tag );
/** For constructing in-progress crafts */
item( const recipe *rec, int qty, std::list<item> items, std::vector<item_comp> selections );
/** Return a pointer-like type that's automatically invalidated if this
* item is destroyed or assigned-to */
safe_reference<item> get_safe_reference();
/**
* Filter converting this instance to another type preserving all other aspects
* @param new_type the type id to convert to
* @return same instance to allow method chaining
*/
item &convert( const itype_id &new_type );
/**
* Filter converting this instance to the inactive type
* If the item is either inactive or cannot be deactivated is a no-op
* @param ch character currently possessing or acting upon the item (if any)
* @param alert whether to display any messages
* @return same instance to allow method chaining
*/
item &deactivate( const Character *ch = nullptr, bool alert = true );
/** Filter converting instance to active state */
item &activate();
/**
* Add or remove energy from a battery.
* If adding the specified energy quantity would go over the battery's capacity fill
* the battery and ignore the remainder.
* If adding the specified energy quantity would reduce the battery's charge level
* below 0 do nothing and return how far below 0 it would have gone.
* @param qty energy quantity to add (can be negative)
* @return 0 valued energy quantity on success
*/
units::energy set_energy( const units::energy &qty );
/**
* Filter setting the ammo for this instance
* Any existing ammo is removed. If necessary a magazine is also added.
* @param ammo specific type of ammo (must be compatible with item ammo type)
* @param qty maximum ammo (capped by item capacity) or negative to fill to capacity
* @return same instance to allow method chaining
*/
item &ammo_set( const itype_id &ammo, int qty = -1 );
/**
* Filter removing all ammo from this instance
* If the item is neither a tool, gun nor magazine is a no-op
* For items reloading using magazines any empty magazine remains present.
*/
item &ammo_unset();
/**
* Filter setting damage constrained by @ref min_damage and @ref max_damage
* @note this method does not invoke the @ref on_damage callback
* @return same instance to allow method chaining
*/
item &set_damage( int qty );
/**
* Splits a count-by-charges item always leaving source item with minimum of 1 charge
* @param qty number of required charges to split from source
* @return new instance containing exactly qty charges or null item if splitting failed
*/
item split( int qty );
/**
* Make a corpse of the given monster type.
* The monster type id must be valid (see @ref MonsterGenerator::get_all_mtypes).
*
* The turn parameter sets the birthday of the corpse, in other words: the turn when the
* monster died. Because corpses are removed from the map when they reach a certain age,
* one has to be careful when placing corpses with a birthday of 0. They might be
* removed immediately when the map is loaded without been seen by the player.
*
* The name parameter can be used to give the corpse item a name. This is
* used instead of the monster type name ("corpse of X" instead of "corpse of bear").
*
* With the default parameters it makes a human corpse, created at the current turn.
*/
/*@{*/
static item make_corpse( const mtype_id &mt = string_id<mtype>::NULL_ID(),
time_point turn = calendar::turn, const std::string &name = "" );
/*@}*/
/**
* @return The monster type associated with this item (@ref corpse). It is usually the
* type that this item is made of (e.g. corpse, meat or blood of the monster).
* May return a null-pointer.
*/
const mtype *get_mtype() const;
/**
* Sets the monster type associated with this item (@ref corpse). You must not pass a
* null pointer.
* TODO: change this to take a reference instead.
*/
void set_mtype( const mtype *corpse );
/**
* Whether this is a corpse item. Corpses always have valid monster type (@ref corpse)
* associated (@ref get_mtype return a non-null pointer) and have been created
* with @ref make_corpse.
*/
bool is_corpse() const;
/**
* Whether this is a corpse that can be revived.
*/
bool can_revive() const;
/**
* Whether this corpse should revive now. Note that this function includes some randomness,
* the return value can differ on successive calls.
* @param pos The location of the item (see REVIVE_SPECIAL flag).
*/
bool ready_to_revive( const tripoint &pos ) const;
bool is_money() const;
/**
* Returns the default color of the item (e.g. @ref itype::color).
*/
nc_color color() const;
/**
* Returns the color of the item depending on usefulness for the player character,
* e.g. differently if it its an unread book or a spoiling food item etc.
* This should only be used for displaying data, it should not affect game play.
*/
nc_color color_in_inventory() const;
/**
* Return the (translated) item name.
* @param quantity used for translation to the proper plural form of the name, e.g.
* returns "rock" for quantity 1 and "rocks" for quantity > 0.
* @param with_prefix determines whether to include more item properties, such as
* the extent of damage and burning (was created to sort by name without prefix
* in additional inventory)
*/
std::string tname( unsigned int quantity = 1, bool with_prefix = true,
unsigned int truncate = 0 ) const;
std::string display_money( unsigned int quantity, unsigned int charge ) const;
/**
* Returns the item name and the charges or contained charges (if the item can have
* charges at all). Calls @ref tname with given quantity and with_prefix being true.
*/
std::string display_name( unsigned int quantity = 1 ) const;
/**
* Return all the information about the item and its type.
*
* This includes the different
* properties of the @ref itype (if they are visible to the player). The returned string
* is already translated and can be *very* long.
* @param showtext If true, shows the item description, otherwise only the properties item type.
*/
std::string info( bool showtext = false ) const;
/**
* Return all the information about the item and its type, and dump to vector.
*
* This includes the different
* properties of the @ref itype (if they are visible to the player). The returned string
* is already translated and can be *very* long.
* @param showtext If true, shows the item description, otherwise only the properties item type.
* @param dump The properties (encapsulated into @ref iteminfo) are added to this vector,
* the vector can be used to compare them to properties of another item.
*/
std::string info( bool showtext, std::vector<iteminfo> &dump ) const;
/**
* Return all the information about the item and its type, and dump to vector.
*
* This includes the different
* properties of the @ref itype (if they are visible to the player). The returned string
* is already translated and can be *very* long.
* @param showtext If true, shows the item description, otherwise only the properties item type.
* @param dump The properties (encapsulated into @ref iteminfo) are added to this vector,
* the vector can be used to compare them to properties of another item.
* @param batch The batch crafting number to multiply data by
*/
std::string info( bool showtext, std::vector<iteminfo> &dump, int batch ) const;
/**
* Return all the information about the item and its type, and dump to vector.
*
* This includes the different
* properties of the @ref itype (if they are visible to the player). The returned string
* is already translated and can be *very* long.
* @param parts controls which parts of the iteminfo to return.
* @param dump The properties (encapsulated into @ref iteminfo) are added to this vector,
* the vector can be used to compare them to properties of another item.
* @param batch The batch crafting number to multiply data by
*/
std::string info( std::vector<iteminfo> &dump, const iteminfo_query *parts = nullptr,
int batch = 1 ) const;
/**
* Calculate all burning calculations, but don't actually apply them to item.
* DO apply them to @ref fire_data argument, though.
* @return Amount of "burn" that would be applied to the item.
*/
float simulate_burn( fire_data &bd ) const;
/** Burns the item. Returns true if the item was destroyed. */
bool burn( fire_data &bd );
// Returns the category of this item.
const item_category &get_category() const;
class reload_option
{
public:
reload_option() = default;
reload_option( const reload_option & );
reload_option &operator=( const reload_option & );
reload_option( const player *who, const item *target, const item *parent,
const item_location &ammo );
const player *who = nullptr;
const item *target = nullptr;
item_location ammo;
int qty() const {
return qty_;
}
void qty( int val );
int moves() const;
explicit operator bool() const {
return who && target && ammo && qty_ > 0;
}
private:
int qty_ = 0;
int max_qty = INT_MAX;
const item *parent = nullptr;
};
/**
* Reload item using ammo from location returning true if successful
* @param u Player doing the reloading
* @param loc Location of ammo to be reloaded
* @param qty caps reloading to this (or fewer) units
*/
bool reload( player &u, item_location loc, int qty );
template<typename Archive>
void io( Archive & );
using archive_type_tag = io::object_archive_tag;
void serialize( JsonOut &jsout ) const;
void deserialize( JsonIn &jsin );
const std::string &symbol() const;
/**
* Returns the monetary value of an item.
* If `practical` is false, returns pre-cataclysm market value,
* otherwise returns approximate post-cataclysm value.
*/
int price( bool practical ) const;
/**
* Whether two items should stack when displayed in a inventory menu.
* This is different from stacks_with, when two previously non-stackable
* items are now stackable and mergeable because, for example, they
* reaches the same temperature. This is necessary to avoid misleading
* stacks like "3 items-count-by-charge (5)".
*/
bool display_stacked_with( const item &rhs, bool check_components = false ) const;
bool stacks_with( const item &rhs, bool check_components = false ) const;
/**
* Merge charges of the other item into this item.
* @return true if the items have been merged, otherwise false.
* Merging is only done for items counted by charges (@ref count_by_charges) and
* items that stack together (@ref stacks_with).
*/
bool merge_charges( const item &rhs );
units::mass weight( bool include_contents = true, bool integral = false ) const;
/**
* Total volume of an item accounting for all contained/integrated items
* NOTE: Result is rounded up to next nearest milliliter when working with stackable (@ref count_by_charges) items that have fractional volume per charge.
* If trying to determine how many of an item can fit in a given space, @ref charges_per_volume should be used instead.
* @param integral if true return effective volume if this item was integrated into another
*/
units::volume volume( bool integral = false ) const;
/**
* Simplified, faster volume check for when processing time is important and exact volume is not.
* NOTE: Result is rounded up to next nearest milliliter when working with stackable (@ref count_by_charges) items that have fractional volume per charge.
* If trying to determine how many of an item can fit in a given space, @ref charges_per_volume should be used instead.
*/
units::volume base_volume() const;
/** Volume check for corpses, helper for base_volume(). */
units::volume corpse_volume( const mtype *corpse ) const;
/** Required strength to be able to successfully lift the item unaided by equipment */
int lift_strength() const;
/**
* @name Melee
*
* The functions here assume the item is used in melee, even if's a gun or not a weapon at
* all. Because the functions apply to all types of items, several of the is_* functions here
* may return true for the same item. This only indicates that it can be used in various ways.
*/
/*@{*/
/**
* Base number of moves (@ref Creature::moves) that a single melee attack with this items
* takes. The actual time depends heavily on the attacker, see melee.cpp.
*/
int attack_time() const;
/** Damage of given type caused when this item is used as melee weapon */
int damage_melee( damage_type dt ) const;
/** All damage types this item deals when used in melee (no skill modifiers etc. applied). */
damage_instance base_damage_melee() const;
/** All damage types this item deals when thrown (no skill modifiers etc. applied). */
damage_instance base_damage_thrown() const;
/**
* Whether the character needs both hands to wield this item.
*/
bool is_two_handed( const Character &guy ) const;
/** Is this item an effective melee weapon for the given damage type? */
bool is_melee( damage_type dt ) const;
/**
* Is this item an effective melee weapon for any damage type?
* @see item::is_gun()
* @note an item can be both a gun and melee weapon concurrently
*/
bool is_melee() const;
/**
* The most relevant skill used with this melee weapon. Can be "null" if this is not a weapon.
* Note this function returns null if the item is a gun for which you can use gun_skill() instead.
*/
skill_id melee_skill() const;
/*@}*/
/** Max range weapon usable for melee attack accounting for player/NPC abilities */
int reach_range( const player &p ) const;
/**
* Sets time until activation for an item that will self-activate in the future.
**/
void set_countdown( int num_turns );
/**
* Consumes specified charges (or fewer) from this and any contained items
* @param what specific type of charge required, e.g. 'battery'
* @param qty maximum charges to consume. On return set to number of charges not found (or zero)
* @param used filled with duplicates of each item that provided consumed charges
* @param pos position at which the charges are being consumed
* @param filter Must return true for use to occur.
* @return true if this item should be deleted (count-by-charges items with no remaining charges)
*/
bool use_charges( const itype_id &what, int &qty, std::list<item> &used, const tripoint &pos,
const std::function<bool( const item & )> &filter = return_true<item> );
/**
* Invokes item type's @ref itype::drop_action.
* This function can change the item.
* @param pos Where is the item being placed. Note: the item isn't there yet.
* @return true if the item was destroyed during placement.
*/
bool on_drop( const tripoint &pos );
/**
* Invokes item type's @ref itype::drop_action.
* This function can change the item.
* @param pos Where is the item being placed. Note: the item isn't there yet.
* @param map A map object associated with that position.
* @return true if the item was destroyed during placement.
*/
bool on_drop( const tripoint &pos, map &map );
/**
* Consume a specific amount of items of a specific type.
* This includes this item, and any of its contents (recursively).
* @see item::use_charges - this is similar for items, not charges.
* @param it Type of consumable item.
* @param quantity How much to consumed.
* @param used On success all consumed items will be stored here.
* @param filter Must return true for use to occur.
*/
bool use_amount( const itype_id &it, int &quantity, std::list<item> &used,
const std::function<bool( const item & )> &filter = return_true<item> );
/** Permits filthy components, should only be used as a helper in creating filters */
bool allow_crafting_component() const;
/**
* @name Containers
*
* Containers come in two flavors:
* - suitable for liquids (@ref is_watertight_container),
* - and the remaining one (they are for currently only for flavor).
*/
/*@{*/
/** Whether this is container. Note that container does not necessarily means it's
* suitable for liquids. */
bool is_container() const;
/** Whether this is a container which can be used to store liquids. */
bool is_watertight_container() const;
/** Whether this item has no contents at all. */
bool is_container_empty() const;
/** Whether removing this item's contents will permanently alter it. */
bool is_non_resealable_container() const;
/**
* Whether this item has no more free capacity for its current content.
* @param allow_bucket Allow filling non-sealable containers
*/
bool is_container_full( bool allow_bucket = false ) const;
/**
* Fill item with liquid up to its capacity. This works for guns and tools that accept
* liquid ammo.
* @param liquid Liquid to fill the container with.
* @param amount Amount to fill item with, capped by remaining capacity
*/
void fill_with( item &liquid, int amount = INFINITE_CHARGES );
/**
* How much more of this liquid (in charges) can be put in this container.
* If this is not a container (or not suitable for the liquid), it returns 0.
* Note that mixing different types of liquid is not possible.
* Also note that this works for guns and tools that accept liquid ammo.
* @param liquid Liquid to check capacity for
* @param allow_bucket Allow filling non-sealable containers
* @param err Message to print if no more material will fit
*/
int get_remaining_capacity_for_liquid( const item &liquid, bool allow_bucket = false,
std::string *err = nullptr ) const;
int get_remaining_capacity_for_liquid( const item &liquid, const Character &p,
std::string *err = nullptr ) const;
/**
* It returns the total capacity (volume) of the container for liquids.
*/
units::volume get_container_capacity() const;
/**
* It returns the maximum volume of any contents, including liquids,
* ammo, magazines, weapons, etc.
*/
units::volume get_total_capacity() const;
/**
* Puts the given item into this one, no checks are performed.
*/
void put_in( const item &payload );
/** Stores a newly constructed item at the end of this item's contents */
template<typename ... Args>
item &emplace_back( Args &&... args ) {
contents.emplace_back( std::forward<Args>( args )... );
if( contents.back().is_null() ) {
debugmsg( "Tried to emplace null item" );
}
return contents.back();
}
/**
* Returns this item into its default container. If it does not have a default container,
* returns this. It's intended to be used like \code newitem = newitem.in_its_container();\endcode
*/
item in_its_container() const;
item in_container( const itype_id &container_type ) const;
/*@}*/
/*@{*/
/**
* Funnel related functions. See weather.cpp for their usage.
*/
bool is_funnel_container( units::volume &bigger_than ) const;
void add_rain_to_container( bool acid, int charges = 1 );
/*@}*/
int get_quality( const quality_id &id ) const;
bool count_by_charges() const;
/**
* If count_by_charges(), returns charges, otherwise 1
*/
int count() const;
bool craft_has_charges();
/**
* Modify the charges of this item, only use for items counted by charges!
* The item must have enough charges for this (>= quantity) and be counted
* by charges.
* @param mod How many charges should be removed.
*/
void mod_charges( int mod );
/**
* Accumulate rot of the item since last rot calculation.
* This function should not be called directly. since it does not have all the needed checks or temperature calculations.
* If you need to calc rot of item call process_temperature_rot instead.
* @param time Time point to which rot is calculated
* @param temp Temperature at which the rot is calculated
*/
void calc_rot( time_point time, int temp );
/**
* This is part of a workaround so that items don't rot away to nothing if the smoking rack
* is outside the reality bubble.
* @param smoking_duration
*/
void calc_rot_while_processing( time_duration smoking_duration );
/**
* Update temperature for things like food
* Update rot for things that perish
* All items that rot also have temperature
* @param temp Temperature at which item is current exposed
* @param insulation Amount of insulation item has from surroundings
* @param pos The current position
* @param carrier The current carrier
* @param flag to specify special temperature situations
*/
void process_temperature_rot( float insulation, const tripoint &pos, player *carrier,
const temperature_flag flag = temperature_flag::TEMP_NORMAL );
/** Set the item to HOT */
void heat_up();
/** Set the item to COLD */
void cold_up();
/** Sets the item temperature and item energy from new temperature (K)*/
void set_item_temperature( float new_temperature );
/** Sets the item to new temperature and energy based new specific energy (J/g)*/
void set_item_specific_energy( const float specific_energy );
/** reset the last_temp_check used when crafting new items and the like */
void reset_temp_check();
/** whether an item is perishable (can rot) */
bool goes_bad() const;
/** Get the shelf life of the item*/
time_duration get_shelf_life() const;
/** Get @ref rot value relative to shelf life (or 0 if item does not spoil) */
double get_relative_rot() const;
/** Set current item @ref rot relative to shelf life (no-op if item does not spoil) */
void set_relative_rot( double val );
void set_rot( time_duration val );
/**
* Get time left to rot, ignoring fridge.
* Returns time to rot if item is able to, max int - N otherwise,
* where N is
* 3 for food,
* 2 for medication,
* 1 for other comestibles,
* 0 otherwise.
*/
int spoilage_sort_order();
/** an item is fresh if it is capable of rotting but still has a long shelf life remaining */
bool is_fresh() const {
return goes_bad() && get_relative_rot() < 0.1;
}
/** an item is about to become rotten when shelf life has nearly elapsed */
bool is_going_bad() const {
return get_relative_rot() > 0.9;
}
/** returns true if item is now rotten after all shelf life has elapsed */
bool rotten() const {
return get_relative_rot() > 1.0;
}
/** at twice regular shelf life perishable foods rot away completely. Corpses last longer */
bool has_rotten_away() const {
return is_food() && get_relative_rot() > 2.0;
}
/** remove frozen tag and if it takes freezerburn, applies mushy/rotten */
void apply_freezerburn();
time_duration get_rot() const {
return rot;
}
void mod_rot( const time_duration &val ) {
rot += val;
}
/** Time for this item to be fully fermented. */
time_duration brewing_time() const;
/** The results of fermenting this item. */
const std::vector<itype_id> &brewing_results() const;
/**
* Detonates the item and adds remains (if any) to drops.
* Returns true if the item actually detonated,
* potentially destroying other items and invalidating iterators.
* Should NOT be called on an item on the map, but on a local copy.
*/
bool detonate( const tripoint &p, std::vector<item> &drops );
bool will_explode_in_fire() const;
/**
* @name Material(s) of the item
*
* Each item is made of one or more materials (@ref material_type). Materials have
* properties that affect properties of the item (e.g. resistance against certain
* damage types).
*
* Additionally, items have a phase property (@ref phase_id). This is independent of
* the material types (there can be solid items made of X and liquid items made of the same
* material).
*
* Corpses inherit the material of the monster type.
*/
/*@{*/
/**
* Get a material reference to a random material that this item is made of.
* This might return the null-material, you may check this with @ref material_type::ident.
* Note that this may also return a different material each time it's invoked (if the
* item is made from several materials).
*/
const material_type &get_random_material() const;
/**
* Get the basic (main) material of this item. May return the null-material.
*/
const material_type &get_base_material() const;
/**
* The ids of all the materials this is made of.
* This may return an empty vector.
* The returned vector does not contain the null id.
*/
const std::vector<material_id> &made_of() const;
/**
* The ids of all the qualities this contains.
*/
const std::map<quality_id, int> &quality_of() const;
/**
* Same as @ref made_of(), but returns the @ref material_type directly.
*/
std::vector<const material_type *> made_of_types() const;
/**
* Check we are made of at least one of a set (e.g. true if at least
* one item of the passed in set matches any material).
* @param mat_idents Set of material ids.
*/
bool made_of_any( const std::set<material_id> &mat_idents ) const;
/**
* Check we are made of only the materials (e.g. false if we have
* one material not in the set or no materials at all).
* @param mat_idents Set of material ids.
*/
bool only_made_of( const std::set<material_id> &mat_idents ) const;
/**
* Check we are made of this material (e.g. matches at least one
* in our set.)
*/
bool made_of( const material_id &mat_ident ) const;
/**
* If contents nonempty, return true if item phase is same, else false
*/
bool contents_made_of( const phase_id phase ) const;
/**
* Are we solid, liquid, gas, plasma?
*/
bool made_of( phase_id phase ) const;
bool made_of_from_type( phase_id phase ) const;
/**
* Returns a list of components used to craft this item or the default
* components if it wasn't player-crafted.
*/
std::vector<item_comp> get_uncraft_components() const;
/**
* Whether the items is conductive.
*/
bool conductive() const;
/**
* Whether the items is flammable. (Make sure to keep this in sync with
* fire code in fields.cpp)
* @param threshold Item is flammable if it provides more fuel than threshold.
*/
bool flammable( int threshold = 0 ) const;
/**
* Whether the item can be repaired beyond normal health.
*/
bool reinforceable() const;
/*@}*/
/**
* Resistance against different damage types (@ref damage_type).
* Larger values means more resistance are thereby better, but there is no absolute value to
* compare them to. The values can be interpreted as chance (@ref one_in) of damaging the item
* when exposed to the type of damage.
* @param to_self If this is true, it returns item's own resistance, not one it gives to wearer.
* @param base_env_resist Will override the base environmental
* resistance (to allow hypothetical calculations for gas masks).
*/
/*@{*/
int bash_resist( bool to_self = false ) const;
int cut_resist( bool to_self = false ) const;
int stab_resist( bool to_self = false ) const;
int acid_resist( bool to_self = false, int base_env_resist = 0 ) const;
int fire_resist( bool to_self = false, int base_env_resist = 0 ) const;
/*@}*/
/**
* Assuming that specified du hit the armor, reduce du based on the item's resistance to the
* damage type. This will never reduce du.amount below 0.
*/
void mitigate_damage( damage_unit &du ) const;
/**
* Resistance provided by this item against damage type given by an enum.
*/
int damage_resist( damage_type dt, bool to_self = false ) const;
/**
* Returns resistance to being damaged by attack against the item itself.
* Calculated from item's materials.
* @param worst If this is true, the worst resistance is used. Otherwise the best one.
*/
int chip_resistance( bool worst = false ) const;
/** How much damage has the item sustained? */
int damage() const;
/**
* Scale item damage to the given number of levels. This function is
* here mostly for back-compatibility. It should not be used when
* doing continuous math with the damage value: use damage() instead.
*
* For example, for max = 4, min_damage = -1000, max_damage = 4000
* damage level
* -1000 ~ -1 -1
* 0 0
* 1 ~ 1333 1
* 1334 ~ 2666 2
* 2667 ~ 3999 3
* 4000 4
*
* @param max Maximum number of levels
*/
int damage_level( int max ) const;
/** Minimum amount of damage to an item (state of maximum repair) */
int min_damage() const;
/** Maximum amount of damage to an item (state before destroyed) */
int max_damage() const;
/**
* Relative item health.
* Returns 1 for undamaged ||items, values in the range (0, 1) for damaged items
* and values above 1 for reinforced ++items.
*/
float get_relative_health() const;
/**
* Apply damage to const itemrained by @ref min_damage and @ref max_damage
* @param qty maximum amount by which to adjust damage (negative permissible)
* @param dt type of damage which may be passed to @ref on_damage callback
* @return whether item should be destroyed
*/
bool mod_damage( int qty, damage_type dt );
/// same as other mod_damage, but uses @ref DT_NULL as damage type.
bool mod_damage( int qty );
/**
* Increment item damage by @ref itype::damage_scale constrained by @ref max_damage
* @param dt type of damage which may be passed to @ref on_damage callback
* @return whether item should be destroyed
*/
bool inc_damage( const damage_type dt );
/// same as other inc_damage, but uses @ref DT_NULL as damage type.
bool inc_damage();
/** Provide color for UI display dependent upon current item damage level */
nc_color damage_color() const;
/** Provide prefix symbol for UI display dependent upon current item damage level */
std::string damage_symbol() const;
/**
* Provides a prefix for the durability state of the item. with ITEM_HEALTH_BAR enabled,
* returns a symbol with color tag already applied. Otherwise, returns an adjective.
* if include_intact is true, this provides a string for the corner case of a player
* with ITEM_HEALTH_BAR disabled, but we need still a string for some reason.
*/
std::string durability_indicator( bool include_intact = false ) const;
/** If possible to repair this item what tools could potentially be used for this purpose? */
const std::set<itype_id> &repaired_with() const;
/**
* Check whether the item has been marked (by calling mark_as_used_by_player)
* as used by this specific player.
*/
bool already_used_by_player( const player &p ) const;
/**
* Marks the item as being used by this specific player, it remains unmarked
* for other players. The player is identified by its id.
*/
void mark_as_used_by_player( const player &p );
/** Marks the item as filthy, so characters with squeamish trait can't wear it.
*/
bool is_filthy() const;
/**
* This is called once each turn. It's usually only useful for active items,