1 #pragma once
2 #ifndef CATA_SRC_CHARACTER_H
3 #define CATA_SRC_CHARACTER_H
4 
5 #include <functional>
6 #include <algorithm>
7 #include <bitset>
8 #include <climits>
9 #include <cstdint>
10 #include <functional>
11 #include <iosfwd>
12 #include <limits>
13 #include <list>
14 #include <map>
15 #include <new>
16 #include <set>
17 #include <string>
18 #include <type_traits>
19 #include <unordered_map>
20 #include <unordered_set>
21 #include <utility>
22 #include <vector>
23 
24 #include "activity_tracker.h"
25 #include "activity_type.h"
26 #include "bodypart.h"
27 #include "calendar.h"
28 #include "cata_utility.h"
29 #include "character_id.h"
30 #include "coordinates.h"
31 #include "craft_command.h"
32 #include "creature.h"
33 #include "damage.h"
34 #include "enums.h"
35 #include "flat_set.h"
36 #include "game_constants.h"
37 #include "item.h"
38 #include "item_contents.h"
39 #include "item_location.h"
40 #include "item_pocket.h"
41 #include "magic_enchantment.h"
42 #include "memory_fast.h"
43 #include "optional.h"
44 #include "pimpl.h"
45 #include "player_activity.h"
46 #include "pldata.h"
47 #include "point.h"
48 #include "recipe.h"
49 #include "ret_val.h"
50 #include "stomach.h"
51 #include "string_formatter.h"
52 #include "type_id.h"
53 #include "units_fwd.h"
54 #include "visitable.h"
55 #include "weighted_list.h"
56 
57 class Character;
58 class JsonIn;
59 class JsonObject;
60 class JsonOut;
61 class SkillLevel;
62 class SkillLevelMap;
63 class basecamp;
64 class bionic_collection;
65 class character_martial_arts;
66 class dispersion_sources;
67 class effect;
68 class effect_source;
69 class faction;
70 class inventory;
71 class known_magic;
72 class ma_technique;
73 class map;
74 class monster;
75 class nc_color;
76 class npc;
77 class player;
78 class player_morale;
79 class proficiency_set;
80 class recipe_subset;
81 class spell;
82 class vpart_reference;
83 struct bionic;
84 struct construction;
85 struct dealt_projectile_attack;
86 struct display_proficiency;
87 /// @brief Item slot used to apply modifications from food and meds
88 struct islot_comestible;
89 struct item_comp;
90 struct itype;
91 struct mutation_branch;
92 struct needs_rates;
93 struct pathfinding_settings;
94 struct points_left;
95 struct requirement_data;
96 struct tool_comp;
97 struct trap;
98 struct w_point;
99 template <typename E> struct enum_traits;
100 
101 enum npc_attitude : int;
102 enum action_id : int;
103 enum class steed_type : int;
104 
105 using drop_location = std::pair<item_location, int>;
106 using drop_locations = std::list<drop_location>;
107 
108 constexpr int MAX_CLAIRVOYANCE = 40;
109 
110 /// @brief type of conditions that effect vision
111 /// @note vision modes do not necessarily match json ids or flags
112 enum vision_modes {
113     DEBUG_NIGHTVISION,
114     NV_GOGGLES,
115     NIGHTVISION_1,
116     NIGHTVISION_2,
117     NIGHTVISION_3,
118     FULL_ELFA_VISION,
119     ELFA_VISION,
120     CEPH_VISION,
121     /// mutate w/ id "FEL_NV" & name "Feline Vision" see pretty well at night
122     FELINE_VISION,
123     /// Bird mutation named "Avian Eyes": Perception +4
124     BIRD_EYE,
125     /// mutate w/ id "URSINE_EYE" & name "Ursine Vision" see better in dark, nearsight in light
126     URSINE_VISION,
127     BOOMERED,
128     DARKNESS,
129     IR_VISION,
130     VISION_CLAIRVOYANCE,
131     VISION_CLAIRVOYANCE_PLUS,
132     VISION_CLAIRVOYANCE_SUPER,
133     NUM_VISION_MODES
134 };
135 
136 enum class fatigue_levels : int {
137     TIRED = 191,
138     DEAD_TIRED = 383,
139     EXHAUSTED = 575,
140     MASSIVE_FATIGUE = 1000
141 };
142 const std::unordered_map<std::string, fatigue_levels> fatigue_level_strs = { {
143         { "TIRED", fatigue_levels::TIRED },
144         { "DEAD_TIRED", fatigue_levels::DEAD_TIRED },
145         { "EXHAUSTED", fatigue_levels::EXHAUSTED },
146         { "MASSIVE_FATIGUE", fatigue_levels::MASSIVE_FATIGUE }
147     }
148 };
149 
150 constexpr inline bool operator>=( const fatigue_levels &lhs, const fatigue_levels &rhs )
151 {
152     return static_cast<int>( lhs ) >= static_cast<int>( rhs );
153 }
154 
155 constexpr inline bool operator<( const fatigue_levels &lhs, const fatigue_levels &rhs )
156 {
157     return static_cast<int>( lhs ) < static_cast<int>( rhs );
158 }
159 
160 template<typename T>
161 constexpr inline bool operator>=( const T &lhs, const fatigue_levels &rhs )
162 {
163     return lhs >= static_cast<T>( rhs );
164 }
165 
166 template<typename T>
167 constexpr inline bool operator>( const T &lhs, const fatigue_levels &rhs )
168 {
169     return lhs > static_cast<T>( rhs );
170 }
171 
172 template<typename T>
173 constexpr inline bool operator<=( const T &lhs, const fatigue_levels &rhs )
174 {
175     return lhs <= static_cast<T>( rhs );
176 }
177 
178 template<typename T>
179 constexpr inline bool operator<( const T &lhs, const fatigue_levels &rhs )
180 {
181     return lhs < static_cast<T>( rhs );
182 }
183 
184 template<typename T>
185 constexpr inline int operator/( const fatigue_levels &lhs, const T &rhs )
186 {
187     return static_cast<T>( lhs ) / rhs;
188 }
189 
190 template<typename T>
191 constexpr inline int operator+( const fatigue_levels &lhs, const T &rhs )
192 {
193     return static_cast<T>( lhs ) + rhs;
194 }
195 
196 template<typename T>
197 constexpr inline int operator-( const fatigue_levels &lhs, const T &rhs )
198 {
199     return static_cast<T>( lhs ) - rhs;
200 }
201 
202 template<typename T>
203 constexpr inline int operator-( const T &lhs, const fatigue_levels &rhs )
204 {
205     return lhs - static_cast<T>( rhs );
206 }
207 
208 /** @brief five levels of consequences for days without sleep
209     @details Sleep deprivation, distinct from fatigue, is defined in minutes. Although most
210     calculations scale linearly, malus is bestowed only upon reaching the tiers defined below.
211     @note Sleep deprivation increases fatigue. Fatigue increase scales with the severity of sleep
212     deprivation.
213     @note Sleep deprivation kicks in if lack of sleep is avoided with stimulants or otherwise for
214     long periods of time
215     @see https://github.com/CleverRaven/Cataclysm-DDA/blob/master/src/character.cpp#L5566
216 */
217 enum sleep_deprivation_levels {
218     /// 2 days
219     SLEEP_DEPRIVATION_HARMLESS = 2 * 24 * 60,
220     /// 4 days
221     SLEEP_DEPRIVATION_MINOR = 4 * 24 * 60,
222     /// 7 days
223     SLEEP_DEPRIVATION_SERIOUS = 7 * 24 * 60,
224     /// 10 days
225     SLEEP_DEPRIVATION_MAJOR = 10 * 24 * 60,
226     /// 14 days
227     SLEEP_DEPRIVATION_MASSIVE = 14 * 24 * 60
228 };
229 
230 enum class blood_type {
231     blood_O,
232     blood_A,
233     blood_B,
234     blood_AB,
235     num_bt
236 };
237 
238 template<>
239 struct enum_traits<blood_type> {
240     static constexpr blood_type last = blood_type::num_bt;
241 };
242 
243 /// @brief how digestible or palatable an item is
244 /// @details This tries to represent both rating and character's decision to respect said rating
245 /// (ie "they can eat it, though they are disgusted by it")
246 enum edible_rating {
247     /// Edible or we pretend it is
248     EDIBLE,
249     /// Not food at all
250     INEDIBLE,
251     /// Not food because character has mutated mouth/system
252     INEDIBLE_MUTATION,
253     /// You can eat it, but it will hurt morale because of negative trait such as Hates Fruit
254     ALLERGY,
255     /// Smaller allergy penalty
256     ALLERGY_WEAK,
257     /// Penalty for eating human flesh (unless psycho/cannibal)
258     CANNIBALISM,
259     /// Comestible has parasites
260     PARASITES,
261     /// Rotten (or, for saprophages, not rotten enough)
262     ROTTEN,
263     /// Can provoke vomiting if you already feel nauseous.
264     NAUSEA,
265     /// We can eat this, but we'll suffer from overeat
266     TOO_FULL,
267     /// Some weird stuff that requires a tool we don't have
268     NO_TOOL
269 };
270 
271 struct aim_type {
272     std::string name;
273     std::string action;
274     std::string help;
275     bool has_threshold;
276     int threshold;
277 };
278 
279 struct special_attack {
280     std::string text;
281     damage_instance damage;
282 };
283 
284 struct consumption_event {
285     time_point time;
286     itype_id type_id;
287     uint64_t component_hash;
288 
289     consumption_event() = default;
290     explicit consumption_event( const item &food ) : time( calendar::turn ) {
291         type_id = food.typeId();
292         component_hash = food.make_component_hash();
293     }
294     void serialize( JsonOut &json ) const;
295     void deserialize( JsonIn &jsin );
296 };
297 
298 inline social_modifiers operator+( social_modifiers lhs, const social_modifiers &rhs )
299 {
300     lhs += rhs;
301     return lhs;
302 }
303 
304 /// @brief Four ability stats available on character creation
305 /// @details  Default is 8. Minimum value is 4 and 14 is considered to be max human value.
306 enum class character_stat : char {
307     STRENGTH,
308     DEXTERITY,
309     INTELLIGENCE,
310     PERCEPTION,
311     DUMMY_STAT
312 };
313 
314 /**
315  * Records a batch of unsealed containers and handles spilling at once. This
316  * is preferred over handling containers right after unsealing because the latter
317  * can cause items to be invalidated when later code still needs to access them.
318  * See @ref `Character::handle_contents_changed` for more detail.
319  */
320 class contents_change_handler
321 {
322     public:
323         contents_change_handler() = default;
324         /**
325          * Add an already unsealed container to the list. This item location
326          * should remain valid when `handle_by` is called.
327          */
328         void add_unsealed( const item_location &loc );
329         /**
330          * Unseal the pocket containing `loc` and add `loc`'s parent to the list.
331          * Does nothing if `loc` does not have a parent container. The parent of
332          * `loc` should remain valid when `handle_by` is called, but `loc` only
333          * needs to be valid here (for example, the item may be consumed afterwards).
334          */
335         void unseal_pocket_containing( const item_location &loc );
336         /**
337          * Let the guy handle any container that needs spilling. This may invalidate
338          * items in and out of the list of containers. The list is cleared after handling.
339          */
340         void handle_by( Character &guy );
341         /**
342          * Serialization for activities
343          */
344         void serialize( JsonOut &jsout ) const;
345         /**
346          * Deserialization for activities
347          */
348         void deserialize( JsonIn &jsin );
349     private:
350         std::vector<item_location> unsealed;
351 };
352 
353 enum class book_mastery {
354     CANT_DETERMINE, // book not yet identified, so you don't know yet
355     CANT_UNDERSTAND, // does not have enough skill to read
356     LEARNING,
357     MASTERED // can no longer increase skill by reading
358 };
359 
360 class Character : public Creature, public visitable
361 {
362     public:
363         Character( const Character & ) = delete;
364         Character &operator=( const Character & ) = delete;
365         ~Character() override;
366 
367         Character *as_character() override {
368             return this;
369         }
370         const Character *as_character() const override {
371             return this;
372         }
373 
374         character_id getID() const;
375         /// sets the ID, will *only* succeed when the current id is not valid
376         /// allows forcing a -1 id which is required for templates to not throw errors
377         void setID( character_id i, bool force = false );
378 
379         field_type_id bloodType() const override;
380         field_type_id gibType() const override;
381         bool is_warm() const override;
382         bool in_species( const species_id &spec ) const override;
383         /// Turned to false for simulating NPCs on distant missions so they don't drop all their gear in sight
384         bool death_drops;
385         /// Is currently in control of a vehicle
386         bool controlling_vehicle = false;
387 
388         enum class comfort_level : int {
389             impossible = -999,
390             uncomfortable = -7,
391             neutral = 0,
392             slightly_comfortable = 3,
393             comfortable = 5,
394             very_comfortable = 10
395         };
396 
397         /// @brief Character stats
398         /// @todo Make those protected
399         int str_max;
400         int dex_max;
401         int int_max;
402         int per_max;
403 
404         int str_cur;
405         int dex_cur;
406         int int_cur;
407         int per_cur;
408 
409         // The prevalence of getter, setter, and mutator functions here is partially
410         // a result of the slow, piece-wise migration of the player class upwards into
411         // the character class. As enough logic is moved upwards to fully separate
412         // utility upwards out of the player class, as many of these as possible should
413         // be eliminated to allow for proper code separation. (Note: Not "all", many").
414         /** Getters for stats exclusive to characters */
415         virtual int get_str() const;
416         virtual int get_dex() const;
417         virtual int get_per() const;
418         virtual int get_int() const;
419 
420         virtual int get_str_base() const;
421         virtual int get_dex_base() const;
422         virtual int get_per_base() const;
423         virtual int get_int_base() const;
424 
425         virtual int get_str_bonus() const;
426         virtual int get_dex_bonus() const;
427         virtual int get_per_bonus() const;
428         virtual int get_int_bonus() const;
429 
430         int get_speed() const override;
431 
432         // Penalty modifiers applied for ranged attacks due to low stats
433         virtual int ranged_dex_mod() const;
434         virtual int ranged_per_mod() const;
435 
436         /** Setters for stats exclusive to characters */
437         virtual void set_str_bonus( int nstr );
438         virtual void set_dex_bonus( int ndex );
439         virtual void set_per_bonus( int nper );
440         virtual void set_int_bonus( int nint );
441         virtual void mod_str_bonus( int nstr );
442         virtual void mod_dex_bonus( int ndex );
443         virtual void mod_per_bonus( int nper );
444         virtual void mod_int_bonus( int nint );
445 
446         // Prints message(s) about current health
447         void print_health() const;
448 
449         /** Getters for health values exclusive to characters */
450         virtual int get_healthy() const;
451         virtual int get_healthy_mod() const;
452 
453         /** Modifiers for health values exclusive to characters */
454         virtual void mod_healthy( int nhealthy );
455         virtual void mod_healthy_mod( int nhealthy_mod, int cap );
456 
457         /** Setters for health values exclusive to characters */
458         virtual void set_healthy( int nhealthy );
459         virtual void set_healthy_mod( int nhealthy_mod );
460 
461         /** Getter for need values exclusive to characters */
462         virtual int get_stored_kcal() const;
463         virtual int get_healthy_kcal() const;
464         virtual float get_kcal_percent() const;
465         virtual int get_hunger() const;
466         virtual int get_starvation() const;
467         virtual int get_thirst() const;
468 
469         std::pair<std::string, nc_color> get_thirst_description() const;
470         std::pair<std::string, nc_color> get_hunger_description() const;
471         std::pair<std::string, nc_color> get_fatigue_description() const;
472         std::pair<std::string, nc_color> get_weight_description() const;
473         int get_fatigue() const;
474         int get_sleep_deprivation() const;
475 
476         std::pair<std::string, nc_color> get_pain_description() const override;
477 
478         /** Modifiers for need values exclusive to characters */
479         virtual void mod_stored_kcal( int nkcal, bool ignore_weariness = false );
480         virtual void mod_stored_nutr( int nnutr );
481         virtual void mod_hunger( int nhunger );
482         virtual void mod_thirst( int nthirst );
483         virtual void mod_fatigue( int nfatigue );
484         virtual void mod_sleep_deprivation( int nsleep_deprivation );
485 
486         /** Setters for need values exclusive to characters */
487         virtual void set_stored_kcal( int kcal );
488         virtual void set_hunger( int nhunger );
489         virtual void set_thirst( int nthirst );
490         virtual void set_fatigue( int nfatigue );
491         virtual void set_fatigue( fatigue_levels nfatigue );
492         virtual void set_sleep_deprivation( int nsleep_deprivation );
493 
494     protected:
495 
496         // These accept values in calories, 1/1000s of kcals (or Calories)
497         virtual void mod_stored_calories( int ncal, bool ignore_weariness = false );
498         virtual void set_stored_calories( int cal );
499 
500     public:
501 
502         void mod_stat( const std::string &stat, float modifier ) override;
503 
504         int get_standard_stamina_cost( item *thrown_item = nullptr );
505 
506         /**Get bonus to max_hp from excess stored fat*/
507         int get_fat_to_hp() const;
508 
509         /** Get size class of character **/
510         creature_size get_size() const override;
511         /** Recalculate size class of character **/
512         void recalculate_size();
513 
514         /** Returns either "you" or the player's name. capitalize_first assumes
515             that the character's name is already upper case and uses it only for
516             possessive "your" and "you"
517         **/
518         std::string disp_name( bool possessive = false, bool capitalize_first = false ) const override;
519         /** Returns the name of the player's outer layer, e.g. "armor plates" */
520         std::string skin_name() const override;
521 
522         /* returns the character's faction */
523         virtual faction *get_faction() const {
524             return nullptr;
525         }
526         void set_fac_id( const std::string &my_fac_id );
527 
528         // Has item with mission_id
529         bool has_mission_item( int mission_id ) const;
530 
531         /* Adjusts provided sight dispersion to account for player stats */
532         int effective_dispersion( int dispersion ) const;
533 
534         /* Accessors for aspects of aim speed. */
535         std::vector<aim_type> get_aim_types( const item &gun ) const;
536         std::pair<int, int> get_fastest_sight( const item &gun, double recoil ) const;
537         int get_most_accurate_sight( const item &gun ) const;
538         double aim_speed_skill_modifier( const skill_id &gun_skill ) const;
539         double aim_speed_dex_modifier() const;
540         double aim_speed_encumbrance_modifier() const;
541         double aim_cap_from_volume( const item &gun ) const;
542 
543         /* Gun stuff */
544         /**
545          * Check whether the player has a gun that uses the given type of ammo.
546          */
547         bool has_gun_for_ammo( const ammotype &at ) const;
548         bool has_magazine_for_ammo( const ammotype &at ) const;
549 
550         /* Calculate aim improvement per move spent aiming at a given @ref recoil */
551         double aim_per_move( const item &gun, double recoil ) const;
552 
553         /** Called after the player has successfully dodged an attack */
554         void on_dodge( Creature *source, float difficulty ) override;
555 
556         /** Combat getters */
557         float get_dodge_base() const override;
558         /** Returns the player's dodge_roll to be compared against an aggressor's hit_roll() */
559         float dodge_roll() const override;
560         /** Returns Creature::get_dodge() modified by any Character effects */
561         float get_dodge() const override;
562         /** Handles the uncanny dodge bionic and effects, returns true if the player successfully dodges */
563         bool uncanny_dodge() override;
564         float get_hit_base() const override;
565 
566         const tripoint &pos() const override;
567         /** Returns the player's sight range */
568         int sight_range( int light_level ) const override;
569         /** Returns the player maximum vision range factoring in mutations, diseases, and other effects */
570         int  unimpaired_range() const;
571         /** Returns true if overmap tile is within player line-of-sight */
572         bool overmap_los( const tripoint_abs_omt &omt, int sight_points );
573         /** Returns the distance the player can see on the overmap */
574         int  overmap_sight_range( int light_level ) const;
575         /** Returns the distance the player can see through walls */
576         int  clairvoyance() const;
577         /** Returns true if the player has some form of impaired sight */
578         bool sight_impaired() const;
579         /** Returns true if the player or their vehicle has an alarm clock */
580         bool has_alarm_clock() const;
581         /** Returns true if the player or their vehicle has a watch */
582         bool has_watch() const;
583         /** Called after every action, invalidates player caches */
584         void action_taken();
585         /** Returns true if the player is knocked over or has broken legs */
586         bool is_on_ground() const override;
587         /** Returns the player's speed for swimming across water tiles */
588         int  swim_speed() const;
589         /** Returns melee skill level, to be used to throttle dodge practice. **/
590         float get_melee() const override;
591         /**
592          * @brief Adds a reason for why the player would miss a melee attack.
593          *
594          * @details To possibly be messaged to the player when he misses a melee attack.
595          * @param reason A message for the player that gives a reason for him missing.
596          * @param weight The weight used when choosing what reason to pick when the
597          * player misses.
598          */
599         void add_miss_reason( const std::string &reason, unsigned int weight );
600         /** Clears the list of reasons for why the player would miss a melee attack. */
601         void clear_miss_reasons();
602         /**
603          * Returns an explanation for why the player would miss a melee attack.
604          */
605         std::string get_miss_reason();
606 
607         /**
608           * Handles passive regeneration of pain and maybe hp.
609           */
610         void regen( int rate_multiplier );
611         /// called once per 24 hours to enforce the minimum of 1 hp healed per day
612         /// @todo Move to Character once heal() is moved
613         void enforce_minimum_healing();
614         /** get best quality item that this character has */
615         item *best_quality_item( const quality_id &qual );
616         /** Handles health fluctuations over time */
617         virtual void update_health( int external_modifiers = 0 );
618         /** Updates all "biology" by one turn. Should be called once every turn. */
619         void update_body();
620         /** Updates all "biology" as if time between `from` and `to` passed. */
621         void update_body( const time_point &from, const time_point &to );
622         /** Updates the stomach to give accurate hunger messages */
623         void update_stomach( const time_point &from, const time_point &to );
624         /** Increases hunger, thirst, fatigue and stimulants wearing off. `rate_multiplier` is for retroactive updates. */
625         void update_needs( int rate_multiplier );
626         needs_rates calc_needs_rates() const;
627         /** Kills the player if too hungry, stimmed up etc., forces tired player to sleep and prints warnings. */
628         void check_needs_extremes();
629         /** Handles the chance to be infected by random diseases */
630         void get_sick();
631         /** Returns if the player has hibernation mutation and is asleep and well fed */
632         bool is_hibernating() const;
633         /** Maintains body temperature */
634         void update_bodytemp();
635         void update_frostbite( const bodypart_id &bp, int FBwindPower );
636         /** Equalizes heat between body parts */
637         void temp_equalizer( const bodypart_id &bp1, const bodypart_id &bp2 );
638 
639         struct comfort_response_t {
640             comfort_level level = comfort_level::neutral;
641             const item *aid = nullptr;
642         };
643         /** Rate point's ability to serve as a bed. Only takes certain mutations into account, and not fatigue nor stimulants. */
644         comfort_response_t base_comfort_value( const tripoint &p ) const;
645 
646         /** Define blood loss (in percents) */
647         int blood_loss( const bodypart_id &bp ) const;
648 
649         /** Resets the value of all bonus fields to 0. */
650         void reset_bonuses() override;
651         /** Resets stats, and applies effects in an idempotent manner */
652         void reset_stats() override;
653         /** Handles stat and bonus reset. */
654         void reset() override;
655 
656         /** Returns ENC provided by armor, etc. */
657         int encumb( const bodypart_id &bp ) const;
658 
659         /** Returns body weight plus weight of inventory and worn/wielded items */
660         units::mass get_weight() const override;
661 
662         /** Returns true if the character is wearing power armor */
663         bool is_wearing_power_armor( bool *hasHelmet = nullptr ) const;
664         /** Returns true if the character is wearing active power */
665         bool is_wearing_active_power_armor() const;
666         /** Returns true if the player is wearing an active optical cloak */
667         bool is_wearing_active_optcloak() const;
668 
669         /** Returns true if the player is in a climate controlled area or armor */
670         bool in_climate_control();
671 
672         /** Returns wind resistance provided by armor, etc **/
673         int get_wind_resistance( const bodypart_id &bp ) const;
674 
675         /** Returns true if the player isn't able to see */
676         bool is_blind() const;
677 
678         bool is_invisible() const;
679         /** Checks is_invisible() as well as other factors */
680         int visibility( bool check_color = false, int stillness = 0 ) const;
681 
682         /** Returns character luminosity based on the brightest active item they are carrying */
683         float active_light() const;
684 
685         bool sees_with_specials( const Creature &critter ) const;
686 
687         /** Bitset of all the body parts covered only with items with `flag` (or nothing) */
688         body_part_set exclusive_flag_coverage( const flag_id &flag ) const;
689 
690         /** Processes effects which may prevent the Character from moving (bear traps, crushed, etc.).
691          *  Returns false if movement is stopped. */
692         bool move_effects( bool attacking ) override;
693 
694         void wait_effects( bool attacking = false );
695 
696         /** Series of checks to remove effects for waiting or moving */
697         bool try_remove_grab();
698         void try_remove_downed();
699         void try_remove_bear_trap();
700         void try_remove_lightsnare();
701         void try_remove_heavysnare();
702         void try_remove_crushed();
703         void try_remove_webs();
704         void try_remove_impeding_effect();
705 
706         /** Check against the character's current movement mode */
707         bool movement_mode_is( const move_mode_id &mode ) const;
708         move_mode_id current_movement_mode() const;
709 
710         bool is_running() const;
711         bool is_walking() const;
712         bool is_crouching() const;
713 
714         bool can_switch_to( const move_mode_id &mode ) const;
715         steed_type get_steed_type() const;
716         virtual void set_movement_mode( const move_mode_id &mode ) = 0;
717 
718         /**Determine if character is susceptible to dis_type and if so apply the symptoms*/
719         void expose_to_disease( const diseasetype_id &dis_type );
720         /**
721          * Handles end-of-turn processing.
722          */
723         void process_turn() override;
724 
725         /** Recalculates HP after a change to max strength */
726         void recalc_hp();
727         int get_part_hp_max( const bodypart_id &id ) const;
728         /** Modifies the player's sight values
729          *  Must be called when any of the following change:
730          *  This must be called when any of the following change:
731          * - effects
732          * - bionics
733          * - traits
734          * - underwater
735          * - clothes
736          */
737 
738         /** Maintains body wetness and handles the rate at which the player dries */
739         void update_body_wetness( const w_point &weather );
740 
741         void recalc_sight_limits();
742         /**
743          * Returns the apparent light level at which the player can see.
744          * This is adjusted by the light level at the *character's* position
745          * to simulate glare, etc, night vision only works if you are in the dark.
746          */
747         float get_vision_threshold( float light_level ) const;
748         /**
749          * Flag encumbrance for updating.
750         */
751         void flag_encumbrance();
752         /**
753          * Checks worn items for the "RESET_ENCUMBRANCE" flag, which indicates
754          * that encumbrance may have changed and require recalculating.
755          */
756         void check_item_encumbrance_flag();
757 
758         /** Returns true if the character is wearing something on the entered body_part, ignoring items with the ALLOWS_NATURAL_ATTACKS flag */
759         bool natural_attack_restricted_on( const bodypart_id &bp ) const;
760 
761         int blocks_left;
762         int dodges_left;
763 
764         double recoil = MAX_RECOIL;
765 
766         std::string custom_profession;
767 
768         /** Returns true if the player is able to use a miss recovery technique */
769         bool can_miss_recovery( const item &weap ) const;
770         /** Returns true if the player has quiet melee attacks */
771         bool is_quiet() const;
772 
773         // melee.cpp
774         /** Checks for valid block abilities and reduces damage accordingly. Returns true if the player blocks */
775         bool block_hit( Creature *source, bodypart_id &bp_hit, damage_instance &dam ) override;
776         /** Returns the best item for blocking with */
777         item &best_shield();
778         /** Calculates melee weapon wear-and-tear through use, returns true if item is destroyed. */
779         bool handle_melee_wear( item &shield, float wear_multiplier = 1.0f );
780         /** Returns a random valid technique */
781         matec_id pick_technique( Creature &t, const item &weap,
782                                  bool crit, bool dodge_counter, bool block_counter );
783         void perform_technique( const ma_technique &technique, Creature &t, damage_instance &di,
784                                 int &move_cost );
785 
786         // modifies the damage dealt based on the character's enchantments
787         damage_instance modify_damage_dealt_with_enchantments( const damage_instance &dam ) const override;
788         /**
789          * Sets up a melee attack and handles melee attack function calls
790          * @param t Creature to attack
791          * @param allow_special whether non-forced martial art technique or mutation attack should be
792          *   possible with this attack.
793          * @param force_technique special technique to use in attack.
794          * @param allow_unarmed always uses the wielded weapon regardless of martialarts style
795          */
796         bool melee_attack( Creature &t, bool allow_special, const matec_id &force_technique,
797                            bool allow_unarmed = true );
798         bool melee_attack_abstract( Creature &t, bool allow_special, const matec_id &force_technique,
799                                     bool allow_unarmed = true );
800 
801         /** Handles reach melee attacks */
802         void reach_attack( const tripoint &p );
803 
804         /**
805          * Calls the to other melee_attack function with an empty technique id (meaning no specific
806          * technique should be used).
807          */
808         bool melee_attack( Creature &t, bool allow_special );
809         /** Handles combat effects, returns a string of any valid combat effect messages */
810         std::string melee_special_effects( Creature &t, damage_instance &d, item &weap );
811         /** Performs special attacks and their effects (poisonous, stinger, etc.) */
812         void perform_special_attacks( Creature &t, dealt_damage_instance &dealt_dam );
813         bool reach_attacking = false;
814 
815         /** Returns a vector of valid mutation attacks */
816         std::vector<special_attack> mutation_attacks( Creature &t ) const;
817         /** Returns the bonus bashing damage the player deals based on their stats */
818         float bonus_damage( bool random ) const;
819         /** Returns weapon skill */
820         float get_melee_hit_base() const;
821         /** Returns the player's basic hit roll that is compared to the target's dodge roll */
822         float hit_roll() const override;
823         /** Returns the chance to critical given a hit roll and target's dodge roll */
824         double crit_chance( float roll_hit, float target_dodge, const item &weap ) const;
825         /** Returns true if the player scores a critical hit */
826         bool scored_crit( float target_dodge, const item &weap ) const;
827         /** Returns cost (in moves) of attacking with given item (no modifiers, like stuck) */
828         int attack_speed( const item &weap ) const;
829         /** Gets melee accuracy component from weapon+skills */
830         float get_hit_weapon( const item &weap ) const;
831 
832         /** NPC-related item rating functions */
833         double weapon_value( const item &weap, int ammo = 10 ) const; // Evaluates item as a weapon
834         double gun_value( const item &weap, int ammo = 10 ) const; // Evaluates item as a gun
835         double melee_value( const item &weap ) const; // As above, but only as melee
836         double unarmed_value() const; // Evaluate yourself!
837         /**
838          * Returns a weapon's modified dispersion value.
839          * @param obj Weapon to check dispersion on
840          */
841         dispersion_sources get_weapon_dispersion( const item &obj ) const;
842 
843         // If average == true, adds expected values of random rolls instead of rolling.
844         /** Adds all 3 types of physical damage to instance */
845         void roll_all_damage( bool crit, damage_instance &di, bool average, const item &weap ) const;
846         /** Adds player's total bash damage to the damage instance */
847         void roll_bash_damage( bool crit, damage_instance &di, bool average, const item &weap ) const;
848         /** Adds player's total cut damage to the damage instance */
849         void roll_cut_damage( bool crit, damage_instance &di, bool average, const item &weap ) const;
850         /** Adds player's total stab damage to the damage instance */
851         void roll_stab_damage( bool crit, damage_instance &di, bool average, const item &weap ) const;
852         /** Adds player's total non-bash, non-cut, non-stab damage to the damage instance */
853         void roll_other_damage( bool crit, damage_instance &di, bool average, const item &weap ) const;
854 
855         /** Returns true if the player should be dead */
856         bool is_dead_state() const override;
857         /** Returns true if the player has stealthy movement */
858         bool is_stealthy() const;
859         /** Returns true if the current martial art works with the player's current weapon */
860         bool can_melee() const;
861         /** Returns value of player's stable footing */
862         float stability_roll() const override;
863         /** Returns true if the player can learn the entered martial art */
864         bool can_autolearn( const matype_id &ma_id ) const;
865         /** Returns true if the player is able to use a grab breaking technique */
866         bool can_grab_break( const item &weap ) const;
867     private:
868         /** Check if an area-of-effect technique has valid targets */
869         bool valid_aoe_technique( Creature &t, const ma_technique &technique );
870         bool valid_aoe_technique( Creature &t, const ma_technique &technique,
871                                   std::vector<Creature *> &targets );
872     public:
873 
874         /** This handles giving xp for a skill */
875         void practice( const skill_id &id, int amount, int cap = 99, bool suppress_warning = false );
876         /** This handles warning the player that there current activity will not give them xp */
877         void handle_skill_warning( const skill_id &id, bool force_warning = false );
878 
879         /**
880          * Check player capable of wielding an item.
881          * @param it Thing to be wielded
882          */
883         ret_val<bool> can_wield( const item &it ) const;
884 
885         bool unwield();
886 
887         /** Get the formatted name of the currently wielded item (if any) with current gun mode (if gun) */
888         std::string weapname() const;
889 
890         // any side effects that might happen when the Character is hit
891         /** Handles special defenses from an attack that hit us (source can be null) */
892         void on_hit( Creature *source, bodypart_id bp_hit,
893                      float difficulty = INT_MIN, dealt_projectile_attack const *proj = nullptr ) override;
894         // any side effects that might happen when the Character hits a Creature
895         void did_hit( Creature &target );
896 
897         /** Actually hurt the player, hurts a body_part directly, no armor reduction */
898         void apply_damage( Creature *source, bodypart_id hurt, int dam,
899                            bool bypass_med = false ) override;
900         /** Calls Creature::deal_damage and handles damaged effects (waking up, etc.) */
901         dealt_damage_instance deal_damage( Creature *source, bodypart_id bp,
902                                            const damage_instance &d ) override;
903         /** Reduce healing effect intensity, return initial intensity of the effect */
904         int reduce_healing_effect( const efftype_id &eff_id, int remove_med, const bodypart_id &hurt );
905 
906         void cough( bool harmful = false, int loudness = 4 );
907         /**
908          * Check for relevant passive, non-clothing that can absorb damage, and reduce by specified
909          * damage unit.  Only flat bonuses are checked here.  Multiplicative ones are checked in
910          * @ref player::absorb_hit.  The damage amount will never be reduced to less than 0.
911          * This is called from @ref player::absorb_hit
912          */
913         void passive_absorb_hit( const bodypart_id &bp, damage_unit &du ) const;
914         /** Runs through all bionics and armor on a part and reduces damage through their armor_absorb */
915         void absorb_hit( const bodypart_id &bp, damage_instance &dam ) override;
916         /**
917          * Reduces and mutates du, prints messages about armor taking damage.
918          * @return true if the armor was completely destroyed (and the item must be deleted).
919          */
920         bool armor_absorb( damage_unit &du, item &armor, const bodypart_id &bp );
921         /**
922          * Check for passive bionics that provide armor, and returns the armor bonus
923          * This is called from player::passive_absorb_hit
924          */
925         float bionic_armor_bonus( const bodypart_id &bp, damage_type dt ) const;
926         /** Returns the armor bonus against given type from martial arts buffs */
927         int mabuff_armor_bonus( damage_type type ) const;
928         /** Returns overall fire resistance for the body part */
929         int get_armor_fire( const bodypart_id &bp ) const;
930         // --------------- Mutation Stuff ---------------
931         // In newcharacter.cpp
932         /** Returns the id of a random starting trait that costs >= 0 points */
933         trait_id random_good_trait();
934         /** Returns the id of a random starting trait that costs < 0 points */
935         trait_id random_bad_trait();
936         /** Returns the id of a random trait matching the given predicate */
937         trait_id get_random_trait( const std::function<bool( const mutation_branch & )> &func );
938         void randomize_cosmetic_trait( std::string mutation_type );
939 
940         // In mutation.cpp
941         /** Returns true if the player has a conflicting trait to the entered trait
942          *  Uses has_opposite_trait(), has_lower_trait(), and has_higher_trait() to determine conflicts.
943          */
944         bool has_conflicting_trait( const trait_id &flag ) const;
945         /** Returns true if the player has a trait which upgrades into the entered trait */
946         bool has_lower_trait( const trait_id &flag ) const;
947         /** Returns true if the player has a trait which is an upgrade of the entered trait */
948         bool has_higher_trait( const trait_id &flag ) const;
949         /** Returns true if the player has a trait that shares a type with the entered trait */
950         bool has_same_type_trait( const trait_id &flag ) const;
951         /** Returns true if the entered trait may be purified away
952          *  Defaults to true
953          */
954         bool purifiable( const trait_id &flag ) const;
955         /** Returns a dream's description selected randomly from the player's highest mutation category */
956         std::string get_category_dream( const mutation_category_id &cat, int strength ) const;
957         /** Returns true if the player has the entered trait */
958         bool has_trait( const trait_id &b ) const override;
959         /** Returns true if the player has the entered starting trait */
960         bool has_base_trait( const trait_id &b ) const;
961         /** Returns true if player has a trait with a flag */
962         bool has_trait_flag( const json_character_flag &b ) const;
963         /** Returns true if player has a bionic with a flag */
964         bool has_bionic_with_flag( const json_character_flag &flag ) const;
965         /** This is to prevent clang complaining about overloading a virtual function, the creature version uses monster flags so confusion is unlikely. */
966         using Creature::has_flag;
967         /** Returns true if player has a trait or bionic with a flag */
968         bool has_flag( const json_character_flag &flag ) const;
969         /** Returns the trait id with the given invlet, or an empty string if no trait has that invlet */
970         trait_id trait_by_invlet( int ch ) const;
971 
972         /** Toggles a trait on the player and in their mutation list */
973         void toggle_trait( const trait_id & );
974         /** Add or removes a mutation on the player, but does not trigger mutation loss/gain effects. */
975         void set_mutations( const std::vector<trait_id> &traits );
976         void set_mutation( const trait_id & );
977         void unset_mutation( const trait_id & );
978         /**Unset switched mutation and set target mutation instead*/
979         void switch_mutations( const trait_id &switched, const trait_id &target, bool start_powered );
980 
981         bool can_power_mutation( const trait_id &mut );
982         /** Generates and handles the UI for player interaction with installed bionics */
983         virtual void power_bionics() {}
984         /**
985         * Check whether player has a bionic power armor interface.
986         * @return true if player has an active bionic capable of powering armor, false otherwise.
987         */
988         bool can_interface_armor() const;
989         // TODO: Implement NPCs activating mutations
990         virtual void power_mutations() {}
991 
992         /**Trigger reflex activation if the mutation has one*/
993         void mutation_reflex_trigger( const trait_id &mut );
994 
995         // Trigger and disable mutations that can be so toggled.
996         void activate_mutation( const trait_id &mutation );
997         void deactivate_mutation( const trait_id &mut );
998 
999         bool can_mount( const monster &critter ) const;
1000         void mount_creature( monster &z );
1001         bool is_mounted() const;
1002         bool check_mount_will_move( const tripoint &dest_loc );
1003         bool check_mount_is_spooked();
1004         void dismount();
1005         void forced_dismount();
1006 
1007         bool is_deaf() const;
1008         bool is_mute() const;
1009         /** Returns true if the player has two functioning arms */
1010         bool has_two_arms() const;
1011         /** Returns the number of functioning arms */
1012         int get_working_arm_count() const;
1013         /** Returns the number of functioning legs */
1014         int get_working_leg_count() const;
1015         /** Returns true if the limb is disabled(12.5% or less hp)*/
1016         bool is_limb_disabled( const bodypart_id &limb ) const;
1017         /** Returns true if the limb is broken */
1018         bool is_limb_broken( const bodypart_id &limb ) const;
1019         /** source of truth of whether a Character can run */
1020         bool can_run() const;
1021         /** Hurts all body parts for dam, no armor reduction */
1022         void hurtall( int dam, Creature *source, bool disturb = true );
1023         /** Harms all body parts for dam, with armor reduction. If vary > 0 damage to parts are random within vary % (1-100) */
1024         int hitall( int dam, int vary, Creature *source );
1025         /** Handles effects that happen when the player is damaged and aware of the fact. */
1026         void on_hurt( Creature *source, bool disturb = true );
1027         /** Heals a body_part for dam */
1028         void heal_bp( bodypart_id bp, int dam ) override;
1029         /** Heals an part for dam */
1030         void heal( const bodypart_id &healed, int dam );
1031         /** Heals all body parts for dam */
1032         void healall( int dam );
1033 
1034         /** used for profession spawning and save migration for nested containers. remove after 0.F */
1035         void migrate_items_to_storage( bool disintegrate );
1036 
1037         /**
1038          * Displays menu with body part hp, optionally with hp estimation after healing.
1039          * Returns selected part.
1040          * menu_header - name of item that triggers this menu
1041          * show_all - show and enable choice of all limbs, not only healable
1042          * precise - show numerical hp
1043          * normal_bonus - heal normal limb
1044          * head_bonus - heal head
1045          * torso_bonus - heal torso
1046          * bleed - chance to stop bleeding
1047          * bite - chance to remove bite
1048          * infect - chance to remove infection
1049          * bandage_power - quality of bandage
1050          * disinfectant_power - quality of disinfectant
1051          */
1052         bodypart_id body_window( const std::string &menu_header,
1053                                  bool show_all, bool precise,
1054                                  int normal_bonus, int head_bonus, int torso_bonus,
1055                                  int bleed, float bite, float infect, float bandage_power, float disinfectant_power ) const;
1056 
1057         // Returns color which this limb would have in healing menus
1058         nc_color limb_color( const bodypart_id &bp, bool bleed, bool bite, bool infect ) const;
1059 
1060         static const std::vector<material_id> fleshy;
1061         bool made_of( const material_id &m ) const override;
1062         bool made_of_any( const std::set<material_id> &ms ) const override;
1063 
1064         inline int posx() const override {
1065             return position.x;
1066         }
1067         inline int posy() const override {
1068             return position.y;
1069         }
1070         inline int posz() const override {
1071             return position.z;
1072         }
1073         inline void setx( int x ) {
1074             setpos( tripoint( x, position.y, position.z ) );
1075         }
1076         inline void sety( int y ) {
1077             setpos( tripoint( position.x, y, position.z ) );
1078         }
1079         inline void setz( int z ) {
1080             setpos( tripoint( position.xy(), z ) );
1081         }
1082         inline void setpos( const tripoint &p ) override {
1083             position = p;
1084             // In case we've moved out of range of lifting assist.
1085             invalidate_weight_carried_cache();
1086         }
1087 
1088         /**
1089          * Global position, expressed in map square coordinate system
1090          * (the most detailed coordinate system), used by the @ref map.
1091          */
1092         virtual tripoint global_square_location() const;
1093         /**
1094         * Returns the location of the player in global submap coordinates.
1095         */
1096         tripoint global_sm_location() const;
1097         /**
1098         * Returns the location of the player in global overmap terrain coordinates.
1099         */
1100         tripoint_abs_omt global_omt_location() const;
1101 
1102     private:
1103         /** Retrieves a stat mod of a mutation. */
1104         int get_mod( const trait_id &mut, const std::string &arg ) const;
1105         /** Applies skill-based boosts to stats **/
1106         void apply_skill_boost();
1107         /**
1108           * What is the best pocket to put @it into?
1109           * the pockets in @avoid do not count
1110           */
1111         std::pair<item_location, item_pocket *> best_pocket( const item &it, const item *avoid );
1112     protected:
1113 
1114         void do_skill_rust();
1115         /** Applies stat mods to character. */
1116         void apply_mods( const trait_id &mut, bool add_remove );
1117 
1118         /** Applies encumbrance from mutations and bionics only */
1119         void mut_cbm_encumb( std::map<bodypart_id, encumbrance_data> &vals ) const;
1120 
1121         void apply_mut_encumbrance( std::map<bodypart_id, encumbrance_data> &vals ) const;
1122 
1123         /** Return the position in the worn list where new_item would be
1124          * put by default */
1125         std::list<item>::iterator position_to_wear_new_item( const item &new_item );
1126 
1127         /** Applies encumbrance from items only
1128          * If new_item is not null, then calculate under the asumption that it
1129          * is added to existing work items. */
1130         void item_encumb( std::map<bodypart_id, encumbrance_data> &vals, const item &new_item ) const;
1131 
1132     public:
1133         /** Recalculate encumbrance for all body parts. */
1134         void calc_encumbrance();
1135         /** Recalculate encumbrance for all body parts as if `new_item` was also worn. */
1136         void calc_encumbrance( const item &new_item );
1137 
1138         // recalculates enchantment cache by iterating through all held, worn, and wielded items
1139         void recalculate_enchantment_cache();
1140         // gets add and mult value from enchantment cache
1141         double calculate_by_enchantment( double modify, enchant_vals::mod value,
1142                                          bool round_output = false ) const;
1143 
1144         /** Returns true if the player has any martial arts buffs attached */
1145         bool has_mabuff( const mabuff_id &buff_id ) const;
1146         /** Returns true if the player has a grab breaking technique available */
1147         bool has_grab_break_tec() const override;
1148 
1149         /** Returns the to hit bonus from martial arts buffs */
1150         float mabuff_tohit_bonus() const;
1151         /** Returns the critical hit chance bonus from martial arts buffs */
1152         float mabuff_critical_hit_chance_bonus() const;
1153         /** Returns the dodge bonus from martial arts buffs */
1154         float mabuff_dodge_bonus() const;
1155         /** Returns the blocking effectiveness bonus from martial arts buffs */
1156         int mabuff_block_effectiveness_bonus() const;
1157         /** Returns the block bonus from martial arts buffs */
1158         int mabuff_block_bonus() const;
1159         /** Returns the speed bonus from martial arts buffs */
1160         int mabuff_speed_bonus() const;
1161         /** Returns the damage multiplier to given type from martial arts buffs */
1162         float mabuff_damage_mult( damage_type type ) const;
1163         /** Returns the flat damage bonus to given type from martial arts buffs, applied after the multiplier */
1164         int mabuff_damage_bonus( damage_type type ) const;
1165         /** Returns the flat penalty to move cost of attacks. If negative, that's a bonus. Applied after multiplier. */
1166         int mabuff_attack_cost_penalty() const;
1167         /** Returns the multiplier on move cost of attacks. */
1168         float mabuff_attack_cost_mult() const;
1169 
1170         /** Handles things like destruction of armor, etc. */
1171         void mutation_effect( const trait_id &mut, bool worn_destroyed_override );
1172         /** Handles what happens when you lose a mutation. */
1173         void mutation_loss_effect( const trait_id &mut );
1174 
1175         bool has_active_mutation( const trait_id &b ) const;
1176 
1177         int get_cost_timer( const trait_id &mut_id ) const;
1178         void set_cost_timer( const trait_id &mut, int set );
1179         void mod_cost_timer( const trait_id &mut, int mod );
1180 
1181         /** Picks a random valid mutation and gives it to the Character, possibly removing/changing others along the way */
1182         void mutate();
1183         /** Returns true if the player doesn't have the mutation or a conflicting one and it complies with the force typing */
1184         bool mutation_ok( const trait_id &mutation, bool force_good, bool force_bad ) const;
1185         /** Picks a random valid mutation in a category and mutate_towards() it */
1186         void mutate_category( const mutation_category_id &mut_cat );
1187         /** Mutates toward one of the given mutations, upgrading or removing conflicts if necessary */
1188         bool mutate_towards( std::vector<trait_id> muts, int num_tries = INT_MAX );
1189         /** Mutates toward the entered mutation, upgrading or removing conflicts if necessary */
1190         bool mutate_towards( const trait_id &mut );
1191         /** Removes a mutation, downgrading to the previous level if possible */
1192         void remove_mutation( const trait_id &mut, bool silent = false );
1193         /** Returns true if the player has the entered mutation child flag */
1194         bool has_child_flag( const trait_id &flag ) const;
1195         /** Removes the mutation's child flag from the player's list */
1196         void remove_child_flag( const trait_id &flag );
1197         /** Recalculates mutation_category_level[] values for the player */
1198         void set_highest_cat_level();
1199         /** Returns the highest mutation category */
1200         mutation_category_id get_highest_category() const;
1201         /** Recalculates mutation drench protection for all bodyparts (ignored/good/neutral stats) */
1202         void drench_mut_calc();
1203         /** Recursively traverses the mutation's prerequisites and replacements, building up a map */
1204         void build_mut_dependency_map( const trait_id &mut,
1205                                        std::unordered_map<trait_id, int> &dependency_map, int distance );
1206 
1207         /**
1208         * Returns true if this category of mutation is allowed.
1209         */
1210         bool is_category_allowed( const std::vector<mutation_category_id> &category ) const;
1211         bool is_category_allowed( const mutation_category_id &category ) const;
1212 
1213         bool is_weak_to_water() const;
1214 
1215         /**Check for mutation disallowing the use of an healing item*/
1216         bool can_use_heal_item( const item &med ) const;
1217 
1218         bool can_install_cbm_on_bp( const std::vector<bodypart_id> &bps ) const;
1219 
1220         /// @brief Returns resistances on a body part provided by mutations
1221         /// @todo Cache this, it's kinda expensive to compute
1222         resistances mutation_armor( bodypart_id bp ) const;
1223         float mutation_armor( bodypart_id bp, damage_type dt ) const;
1224         float mutation_armor( bodypart_id bp, const damage_unit &du ) const;
1225 
1226         // --------------- Bionic Stuff ---------------
1227         /** Handles bionic activation effects of the entered bionic, returns if anything activated */
1228         bool activate_bionic( int b, bool eff_only = false, bool *close_bionics_ui = nullptr );
1229         std::vector<bionic_id> get_bionics() const;
1230         /** Returns amount of Storage CBMs in the corpse **/
1231         std::pair<int, int> amount_of_storage_bionics() const;
1232         /** Returns true if the player has the entered bionic id */
1233         bool has_bionic( const bionic_id &b ) const;
1234         /** Returns true if the player has the entered bionic id and it is powered on */
1235         bool has_active_bionic( const bionic_id &b ) const;
1236         /**Returns true if the player has any bionic*/
1237         bool has_any_bionic() const;
1238         /**Returns true if the character can fuel a bionic with the item*/
1239         bool can_fuel_bionic_with( const item &it ) const;
1240         /**Return bionic_id of bionics able to use it as fuel*/
1241         std::vector<bionic_id> get_bionic_fueled_with( const item &it ) const;
1242         std::vector<bionic_id> get_bionic_fueled_with( const material_id &mat ) const;
1243         /**Return bionic_id of fueled bionics*/
1244         std::vector<bionic_id> get_fueled_bionics() const;
1245         /**Returns bionic_id of first remote fueled bionic found*/
1246         bionic_id get_remote_fueled_bionic() const;
1247         /**Return bionic_id of bionic of most fuel efficient bionic*/
1248         bionic_id get_most_efficient_bionic( const std::vector<bionic_id> &bids ) const;
1249         /**Return list of available fuel for this bionic*/
1250         std::vector<material_id> get_fuel_available( const bionic_id &bio ) const;
1251         /**Return available space to store specified fuel*/
1252         int get_fuel_capacity( const material_id &fuel ) const;
1253         /**Return total space to store specified fuel*/
1254         int get_total_fuel_capacity( const material_id &fuel ) const;
1255         /**Updates which bionic contain fuel and which is empty*/
1256         void update_fuel_storage( const material_id &fuel );
1257         /**Get stat bonus from bionic*/
1258         int get_mod_stat_from_bionic( const character_stat &Stat ) const;
1259         // route for overmap-scale traveling
1260         std::vector<tripoint_abs_omt> omt_path;
1261 
1262         /** Handles bionic effects over time of the entered bionic */
1263         void process_bionic( int b );
1264         /** finds the index of the bionic that corresponds to the currently wielded fake item
1265          *  i.e. bionic is `BIONIC_WEAPON` and weapon.typeId() == bio.info().fake_item */
1266         cata::optional<int> active_bionic_weapon_index() const;
1267         /** Checks if bionic can be deactivated (e.g. it's not incapacitated and power level is sufficient)
1268          *  returns either success or failure with log message */
1269         ret_val<bool> can_deactivate_bionic( int b, bool eff_only = false ) const;
1270         /** Handles bionic deactivation effects of the entered bionic, returns if anything
1271          *  deactivated */
1272         bool deactivate_bionic( int b, bool eff_only = false );
1273         /** Returns the size of my_bionics[] */
1274         int num_bionics() const;
1275         /** Returns the bionic at a given index in my_bionics[] */
1276         bionic &bionic_at_index( int i );
1277         /** Remove all bionics */
1278         void clear_bionics();
1279         int get_used_bionics_slots( const bodypart_id &bp ) const;
1280         int get_total_bionics_slots( const bodypart_id &bp ) const;
1281         int get_free_bionics_slots( const bodypart_id &bp ) const;
1282 
1283         /**Has enough anesthetic for surgery*/
1284         bool has_enough_anesth( const itype &cbm, player &patient );
1285         bool has_enough_anesth( const itype &cbm );
1286         void consume_anesth_requirement( const itype &cbm, player &patient );
1287         /**Has the required equipment for manual installation*/
1288         bool has_installation_requirement( const bionic_id &bid );
1289         void consume_installation_requirement( const bionic_id &bid );
1290         /** Handles process of introducing patient into anesthesia during Autodoc operations. Requires anesthesia kits or NOPAIN mutation */
1291         void introduce_into_anesthesia( const time_duration &duration, player &installer,
1292                                         bool needs_anesthesia );
1293         /** Removes a bionic from my_bionics[] */
1294         void remove_bionic( const bionic_id &b );
1295         /** Adds a bionic to my_bionics[] */
1296         void add_bionic( const bionic_id &b );
1297         /**Calculate skill bonus from tiles in radius*/
1298         float env_surgery_bonus( int radius ) const;
1299         /** Calculate skill for (un)installing bionics */
1300         float bionics_adjusted_skill( bool autodoc, int skill_level = -1 ) const;
1301         /** Calculate non adjusted skill for (un)installing bionics */
1302         int bionics_pl_skill( bool autodoc, int skill_level = -1 ) const;
1303         /**Is the installation possible*/
1304         bool can_install_bionics( const itype &type, Character &installer, bool autodoc = false,
1305                                   int skill_level = -1 );
1306         std::map<bodypart_id, int> bionic_installation_issues( const bionic_id &bioid );
1307         /** Initialize all the values needed to start the operation player_activity */
1308         bool install_bionics( const itype &type, player &installer, bool autodoc = false,
1309                               int skill_level = -1 );
1310         /**Success or failure of installation happens here*/
1311         void perform_install( const bionic_id &bid, const bionic_id &upbid, int difficulty, int success,
1312                               int pl_skill, const std::string &installer_name,
1313                               const std::vector<trait_id> &trait_to_rem, const tripoint &patient_pos );
1314         void bionics_install_failure( const bionic_id &bid, const std::string &installer, int difficulty,
1315                                       int success, float adjusted_skill, const tripoint &patient_pos );
1316 
1317         /**Is The uninstallation possible*/
1318         bool can_uninstall_bionic( const bionic_id &b_id, player &installer, bool autodoc = false,
1319                                    int skill_level = -1 );
1320         /** Initialize all the values needed to start the operation player_activity */
1321         bool uninstall_bionic( const bionic_id &b_id, player &installer, bool autodoc = false,
1322                                int skill_level = -1 );
1323         /**Success or failure of removal happens here*/
1324         void perform_uninstall( const bionic_id &bid, int difficulty, int success,
1325                                 const units::energy &power_lvl, int pl_skill );
1326         /**When a player fails the surgery*/
1327         void bionics_uninstall_failure( int difficulty, int success, float adjusted_skill );
1328 
1329         /**When a critical failure occurs*/
1330         void roll_critical_bionics_failure( const bodypart_id &bp );
1331 
1332         /**Used by monster to perform surgery*/
1333         bool uninstall_bionic( const bionic &target_cbm, monster &installer, player &patient,
1334                                float adjusted_skill );
1335         /**When a monster fails the surgery*/
1336         void bionics_uninstall_failure( monster &installer, player &patient, int difficulty, int success,
1337                                         float adjusted_skill );
1338 
1339         /**Passively produce power from PERPETUAL fuel*/
1340         void passive_power_gen( int b );
1341         /**Find fuel used by remote powered bionic*/
1342         material_id find_remote_fuel( bool look_only = false );
1343         /**Consume fuel used by remote powered bionic, return amount of request unfulfilled (0 if totally successful).*/
1344         int consume_remote_fuel( int amount );
1345         void reset_remote_fuel();
1346         /**Handle heat from exothermic power generation*/
1347         void heat_emission( int b, int fuel_energy );
1348         /**Applies modifier to fuel_efficiency and returns the resulting efficiency*/
1349         float get_effective_efficiency( int b, float fuel_efficiency );
1350 
1351         units::energy get_power_level() const;
1352         units::energy get_max_power_level() const;
1353         void mod_power_level( const units::energy &npower );
1354         void mod_max_power_level( const units::energy &npower_max );
1355         void set_power_level( const units::energy &npower );
1356         void set_max_power_level( const units::energy &npower_max );
1357         bool is_max_power() const;
1358         bool has_power() const;
1359         bool has_max_power() const;
1360         bool enough_power_for( const bionic_id &bid ) const;
1361 
1362         void conduct_blood_analysis();
1363         // --------------- Generic Item Stuff ---------------
1364 
1365         struct has_mission_item_filter {
1366             int mission_id;
1367             bool operator()( const item &it ) {
1368                 return it.mission_id == mission_id || it.contents.has_any_with( [&]( const item & it ) {
1369                     return it.mission_id == mission_id;
1370                 }, item_pocket::pocket_type::SOFTWARE );
1371             }
1372         };
1373 
1374         // -2 position is 0 worn index, -3 position is 1 worn index, etc
1375         static int worn_position_to_index( int position ) {
1376             return -2 - position;
1377         }
1378 
1379         // checks to see if an item is worn
1380         bool is_worn( const item &thing ) const {
1381             for( const auto &elem : worn ) {
1382                 if( &thing == &elem ) {
1383                     return true;
1384                 }
1385             }
1386             return false;
1387         }
1388 
1389         /**
1390          * Asks how to use the item (if it has more than one use_method) and uses it.
1391          * Returns true if it destroys the item. Consumes charges from the item.
1392          * Multi-use items are ONLY supported when all use_methods are iuse_actor!
1393          */
1394         virtual bool invoke_item( item *, const tripoint &pt, int pre_obtain_moves = -1 );
1395         /** As above, but with a pre-selected method. Debugmsg if this item doesn't have this method. */
1396         virtual bool invoke_item( item *, const std::string &, const tripoint &pt,
1397                                   int pre_obtain_moves = -1 );
1398         /** As above two, but with position equal to current position */
1399         virtual bool invoke_item( item * );
1400         virtual bool invoke_item( item *, const std::string & );
1401 
1402         /**
1403          * Drop, wear, stash or otherwise try to dispose of an item consuming appropriate moves
1404          * @param obj item to dispose of
1405          * @param prompt optional message to display in any menu
1406          * @return whether the item was successfully disposed of
1407          */
1408         virtual bool dispose_item( item_location &&obj, const std::string &prompt = std::string() );
1409 
1410         /**
1411          * Has the item enough charges to invoke its use function?
1412          * Also checks if UPS from this player is used instead of item charges.
1413          */
1414         bool has_enough_charges( const item &it, bool show_msg ) const;
1415 
1416         /** Consume charges of a tool or comestible item, potentially destroying it in the process
1417          *  @param used item consuming the charges
1418          *  @param qty number of charges to consume which must be non-zero
1419          *  @return true if item was destroyed */
1420         bool consume_charges( item &used, int qty );
1421         /**
1422          * Remove charges from a specific item.
1423          * The item must exist and it must be counted by charges.
1424          * @param it A pointer to the item, it *must* exist.
1425          * @param quantity The number of charges to remove, must not be larger than
1426          * the current charges of the item.
1427          * @return An item that contains the removed charges, it's effectively a
1428          * copy of the item with the proper charges.
1429          */
1430         item reduce_charges( item *it, int quantity );
1431 
1432         /**
1433          * Calculate (but do not deduct) the number of moves required when handling (e.g. storing, drawing etc.) an item
1434          * @param it Item to calculate handling cost for
1435          * @param penalties Whether item volume and temporary effects (e.g. GRABBED, DOWNED) should be considered.
1436          * @param base_cost Cost due to storage type.
1437          * @return cost in moves ranging from 0 to MAX_HANDLING_COST
1438          */
1439         int item_handling_cost( const item &it, bool penalties = true,
1440                                 int base_cost = INVENTORY_HANDLING_PENALTY ) const;
1441 
1442         /**
1443          * Calculate (but do not deduct) the number of moves required when storing an item in a container
1444          * @param it Item to calculate storage cost for
1445          * @param container Container to store item in
1446          * @param penalties Whether item volume and temporary effects (e.g. GRABBED, DOWNED) should be considered.
1447          * @param base_cost Cost due to storage type.
1448          * @return cost in moves ranging from 0 to MAX_HANDLING_COST
1449          */
1450         int item_store_cost( const item &it, const item &container, bool penalties = true,
1451                              int base_cost = INVENTORY_HANDLING_PENALTY ) const;
1452 
1453         /**
1454          * Calculate (but do not deduct) the number of moves required when drawing a weapon from an holster or sheathe
1455          * @param it Item to calculate retrieve cost for
1456          * @param container Container where the item is
1457          * @param penalties Whether item volume and temporary effects (e.g. GRABBED, DOWNED) should be considered.
1458          * @param base_cost Cost due to storage type.
1459          * @return cost in moves ranging from 0 to MAX_HANDLING_COST
1460          */
1461         int item_retrieve_cost( const item &it, const item &container, bool penalties = true,
1462                                 int base_cost = INVENTORY_HANDLING_PENALTY ) const;
1463 
1464         /** Calculate (but do not deduct) the number of moves required to wear an item */
1465         int item_wear_cost( const item &it ) const;
1466 
1467         /** Wear item; returns nullopt on fail, or pointer to newly worn item on success.
1468          * If interactive is false, don't alert the player or drain moves on completion.
1469          * If do_calc_encumbrance is false, don't recalculate encumbrance, caller must call it eventually.
1470          */
1471         cata::optional<std::list<item>::iterator>
1472         wear_item( const item &to_wear, bool interactive = true, bool do_calc_encumbrance = true );
1473 
1474         /** Returns the amount of item `type' that is currently worn */
1475         int  amount_worn( const itype_id &id ) const;
1476 
1477         /** Returns the amount of software `type' that are in the inventory */
1478         int count_softwares( const itype_id &id );
1479 
1480         /** Returns nearby items which match the provided predicate */
1481         std::vector<item_location> nearby( const std::function<bool( const item *, const item * )> &func,
1482                                            int radius = 1 ) const;
1483 
1484         /**
1485          * Similar to @ref remove_items_with, but considers only worn items and not their
1486          * content (@ref item::contents is not checked).
1487          * If the filter function returns true, the item is removed.
1488          */
1489         std::list<item> remove_worn_items_with( const std::function<bool( item & )> &filter );
1490 
1491         // returns a list of all item_location the character has, including items contained in other items.
1492         // only for CONTAINER pocket type; does not look for magazines
1493         std::vector<item_location> all_items_loc();
1494         // Returns list of all the top level item_lodation the character has. Includes worn items but excludes items held on hand.
1495         std::vector<item_location> top_items_loc();
1496         /** Return the item pointer of the item with given invlet, return nullptr if
1497          * the player does not have such an item with that invlet. Don't use this on npcs.
1498          * Only use the invlet in the user interface, otherwise always use the item position. */
1499         item *invlet_to_item( int invlet );
1500 
1501         // Returns the item with a given inventory position.
1502         item &i_at( int position );
1503         const item &i_at( int position ) const;
1504         /**
1505          * Returns the item position (suitable for @ref i_at or similar) of a
1506          * specific item. Returns INT_MIN if the item is not found.
1507          * Note that this may lose some information, for example the returned position is the
1508          * same when the given item points to the container and when it points to the item inside
1509          * the container. All items that are part of the same stack have the same item position.
1510          */
1511         int get_item_position( const item *it ) const;
1512 
1513         /**
1514          * Returns a reference to the item which will be used to make attacks.
1515          * At the moment it's always @ref weapon or a reference to a null item.
1516          */
1517         /*@{*/
1518         const item &used_weapon() const;
1519         item &used_weapon();
1520         /*@}*/
1521 
1522         /**
1523          * Adds the item to the character's worn items or wields it, or prompts if the Character cannot pick it up.
1524          * @avoid is the item to not put @it into
1525          */
1526         item &i_add( item it, bool should_stack = true, const item *avoid = nullptr, bool allow_drop = true,
1527                      bool allow_wield = true );
1528         /** tries to add to the character's inventory without a popup. returns nullptr if it fails. */
1529         item *try_add( item it, const item *avoid = nullptr, bool allow_wield = true );
1530 
1531         /**
1532          * Try to pour the given liquid into the given container/vehicle. The transferred charges are
1533          * removed from the liquid item. Check the charges of afterwards to see if anything has
1534          * been transferred at all.
1535          * The functions do not consume any move points.
1536          * @return Whether anything has been moved at all. `false` indicates the transfer is not
1537          * possible at all. `true` indicates at least some of the liquid has been moved.
1538          */
1539         /**@{*/
1540         bool pour_into( item &container, item &liquid );
1541         bool pour_into( const vpart_reference &vp, item &liquid ) const;
1542         /**@}*/
1543 
1544         /**
1545          * Remove a specific item from player possession. The item is compared
1546          * by pointer. Contents of the item are removed as well.
1547          * @param it A pointer to the item to be removed. The item *must* exists
1548          * in the players possession (one can use @ref has_item to check for this).
1549          * @return A copy of the removed item.
1550          */
1551         item i_rem( const item *it );
1552         void i_rem_keep_contents( const item *it );
1553         /** Sets invlet and adds to inventory if possible, drops otherwise, returns true if either succeeded.
1554          *  An optional qty can be provided (and will perform better than separate calls). */
1555         bool i_add_or_drop( item &it, int qty = 1, const item *avoid = nullptr );
1556 
1557         /**
1558          * Check any already unsealed pockets in items pointed to by `containers`
1559          * and propagate the unsealed status through the container tree. In the
1560          * process the player may be asked to handle containers or spill contents,
1561          * so make sure all unsealed containers are passed to this fucntion in a
1562          * single batch; items (not limited to the ones listed in `containers` and
1563          * their contents) may be invalidated or moved after a call to this function.
1564          *
1565          * @param containers Item locations pointing to containers. Item locations
1566          *        in this vector can contain each other, but should always be valid
1567          *        (i.e. if A contains B and B contains C, A and C can be in the vector
1568          *        at the same time and should be valid, but B shouldn't be invalidated
1569          *        either, otherwise C is invalidated). Item location in this vector
1570          *        should be unique.
1571          */
1572         void handle_contents_changed( const std::vector<item_location> &containers );
1573 
1574         /** Only use for UI things. Returns all invlets that are currently used in
1575          * the player inventory, the weapon slot and the worn items. */
1576         std::bitset<std::numeric_limits<char>::max()> allocated_invlets() const;
1577 
1578         /**
1579          * Whether the player carries an active item of the given item type.
1580          */
1581         bool has_active_item( const itype_id &id ) const;
1582         item remove_weapon();
1583         void remove_mission_items( int mission_id );
1584 
1585         /**
1586          * Returns the items that are ammo and have the matching ammo type.
1587          */
1588         std::vector<const item *> get_ammo( const ammotype &at ) const;
1589 
1590         /**
1591          * Searches for ammo or magazines that can be used to reload obj
1592          * @param obj item to be reloaded. By design any currently loaded ammunition or magazine is ignored
1593          * @param empty whether empty magazines should be considered as possible ammo
1594          * @param radius adjacent map/vehicle tiles to search. 0 for only player tile, -1 for only inventory
1595          */
1596         std::vector<item_location> find_ammo( const item &obj, bool empty = true, int radius = 1 ) const;
1597 
1598         /**
1599          * Searches for weapons and magazines that can be reloaded.
1600          */
1601         std::vector<item_location> find_reloadables();
1602         /**
1603          * Counts ammo and UPS charges (lower of) for a given gun on the character.
1604          */
1605         int ammo_count_for( const item &gun );
1606 
1607         /**
1608          * Whether a tool or gun is potentially reloadable (optionally considering a specific ammo)
1609          * @param it Thing to be reloaded
1610          * @param ammo if set also check item currently compatible with this specific ammo or magazine
1611          * @note items currently loaded with a detachable magazine are considered reloadable
1612          * @note items with integral magazines are reloadable if free capacity permits (+/- ammo matches)
1613          */
1614         bool can_reload( const item &it, const itype_id &ammo = itype_id() ) const;
1615 
1616         /** Same as `Character::can_reload`, but checks for attached gunmods as well. */
1617         hint_rating rate_action_reload( const item &it ) const;
1618         /** Whether a tool or a gun can be unloaded. */
1619         hint_rating rate_action_unload( const item &it ) const;
1620         /**
1621           * So far only called by unload() from game.cpp
1622           * @avoid - do not put @it into @avoid
1623           */
1624         bool add_or_drop_with_msg( item &it, bool unloading = false, const item *avoid = nullptr );
1625         /**
1626          * Unload item.
1627          * @param bypass_activity If item requires an activity for its unloading, unload item immediately instead.
1628          */
1629         bool unload( item_location &loc, bool bypass_activity = false );
1630         /**
1631          * Calculate (but do not deduct) the number of moves required to reload an item with specified quantity of ammo
1632          * @param it Item to calculate reload cost for
1633          * @param ammo either ammo or magazine to use when reloading the item
1634          * @param qty maximum units of ammo to reload. Capped by remaining capacity and ignored if reloading using a magazine.
1635          */
1636         int item_reload_cost( const item &it, const item &ammo, int qty ) const;
1637 
1638         /** Maximum thrown range with a given item, taking all active effects into account. */
1639         int throw_range( const item & ) const;
1640         /** Dispersion of a thrown item, against a given target, taking into account whether or not the throw was blind. */
1641         int throwing_dispersion( const item &to_throw, Creature *critter = nullptr,
1642                                  bool is_blind_throw = false ) const;
1643         /** How much dispersion does one point of target's dodge add when throwing at said target? */
1644         int throw_dispersion_per_dodge( bool add_encumbrance = true ) const;
1645 
1646         /** True if unarmed or wielding a weapon with the UNARMED_WEAPON flag */
1647         bool unarmed_attack() const;
1648         /// Checks for items, tools, and vehicles with the Lifting quality near the character
1649         /// returning the largest weight liftable by an item in range.
1650         units::mass best_nearby_lifting_assist() const;
1651 
1652         /// Alternate version if you need to specify a different origin point for nearby vehicle sources of lifting
1653         /// used for operations on distant objects (e.g. vehicle installation/uninstallation)
1654         units::mass best_nearby_lifting_assist( const tripoint &world_pos ) const;
1655 
1656         // Inventory + weapon + worn (for death, etc)
1657         std::vector<item *> inv_dump();
1658 
1659         units::mass weight_carried() const;
1660         units::volume volume_carried() const;
1661 
1662         units::length max_single_item_length() const;
1663         units::volume max_single_item_volume() const;
1664 
1665         /// Sometimes we need to calculate hypothetical volume or weight.  This
1666         /// struct offers two possible tweaks: a collection of items and
1667         /// counts to remove, or an entire replacement inventory.
1668         struct item_tweaks {
1669             item_tweaks() = default;
1670             explicit item_tweaks( const std::map<const item *, int> &w ) :
1671                 without_items( std::cref( w ) )
1672             {}
1673             explicit item_tweaks( const inventory &r ) :
1674                 replace_inv( std::cref( r ) )
1675             {}
1676             const cata::optional<std::reference_wrapper<const std::map<const item *, int>>> without_items;
1677             const cata::optional<std::reference_wrapper<const inventory>> replace_inv;
1678         };
1679 
1680         units::mass weight_carried_with_tweaks( const item_tweaks &tweaks ) const;
1681         units::mass weight_carried_with_tweaks( const std::vector<std::pair<item_location, int>>
1682                                                 &locations ) const;
1683         units::mass get_selected_stack_weight( const item *i,
1684                                                const std::map<const item *, int> &without ) const;
1685         units::volume volume_carried_with_tweaks( const item_tweaks &tweaks ) const;
1686         units::volume volume_carried_with_tweaks( const std::vector<std::pair<item_location, int>>
1687                 &locations ) const;
1688         units::mass weight_capacity() const override;
1689         units::volume volume_capacity() const;
1690         units::volume volume_capacity_with_tweaks( const item_tweaks &tweaks ) const;
1691         units::volume volume_capacity_with_tweaks( const std::vector<std::pair<item_location, int>>
1692                 &locations ) const;
1693         units::volume free_space() const;
1694 
1695         /** Note that we've read a book at least once. **/
1696         virtual bool has_identified( const itype_id &item_id ) const = 0;
1697         book_mastery get_book_mastery( const item &book ) const;
1698         virtual void identify( const item &item ) = 0;
1699         /** Calculates the total fun bonus relative to this character's traits and chapter progress */
1700         bool fun_to_read( const item &book ) const;
1701         int book_fun_for( const item &book, const Character &p ) const;
1702 
1703         bool can_pickVolume( const item &it, bool safe = false, const item *avoid = nullptr ) const;
1704         bool can_pickWeight( const item &it, bool safe = true ) const;
1705         bool can_pickWeight_partial( const item &it, bool safe = true ) const;
1706         /**
1707          * Checks if character stats and skills meet minimum requirements for the item.
1708          * Prints an appropriate message if requirements not met.
1709          * @param it Item we are checking
1710          * @param context optionally override effective item when checking contextual skills
1711          */
1712         bool can_use( const item &it, const item &context = item() ) const;
1713         /**
1714          * Check character capable of wearing an item.
1715          * @param it Thing to be worn
1716          * @param with_equip_change If true returns if it could be worn if things were taken off
1717          */
1718         ret_val<bool> can_wear( const item &it, bool with_equip_change = false ) const;
1719         /**
1720          * Returns true if the character is wielding something.
1721          * Note: this item may not actually be used to attack.
1722          */
1723         bool is_armed() const;
1724 
1725         /**
1726         * Returns true if the character is wielding something and it can't be combined with the item
1727         * passed as a parameter
1728         */
1729         bool has_wield_conflicts( const item &it ) const;
1730 
1731         /**
1732          * Removes currently wielded item (if any) and replaces it with the target item.
1733          * @param target replacement item to wield or null item to remove existing weapon without replacing it
1734          * @return whether both removal and replacement were successful (they are performed atomically)
1735          */
1736         virtual bool wield( item &target ) = 0;
1737         /**
1738          * Check player capable of unwielding an item.
1739          * @param it Thing to be unwielded
1740          */
1741         ret_val<bool> can_unwield( const item &it ) const;
1742         /**
1743          * Check player capable of dropping an item.
1744          * @param it Thing to be unwielded
1745          */
1746         ret_val<bool> can_drop( const item &it ) const;
1747 
1748         void drop_invalid_inventory();
1749         // this cache is for checking if items in the character's inventory can't actually fit into other items they are inside of
1750         void invalidate_inventory_validity_cache();
1751 
1752         void invalidate_weight_carried_cache();
1753         /** Returns all items that must be taken off before taking off this item */
1754         std::list<item *> get_dependent_worn_items( const item &it );
1755         /** Drops an item to the specified location */
1756         void drop( item_location loc, const tripoint &where );
1757         virtual void drop( const drop_locations &what, const tripoint &target, bool stash = false );
1758 
1759         bool is_wielding( const item &target ) const;
1760 
1761         bool covered_with_flag( const flag_id &flag, const body_part_set &parts ) const;
1762         bool is_waterproof( const body_part_set &parts ) const;
1763         // Carried items may leak radiation or chemicals
1764         int leak_level( const flag_id &flag ) const;
1765 
1766         // --------------- Clothing Stuff ---------------
1767         /** Returns true if the player is wearing the item. */
1768         bool is_wearing( const itype_id &it ) const;
1769         /** Returns true if the player is wearing the item on the given body part. */
1770         bool is_wearing_on_bp( const itype_id &it, const bodypart_id &bp ) const;
1771         /** Returns true if the player is wearing an item with the given flag. */
1772         bool worn_with_flag( const flag_id &flag, const bodypart_id &bp ) const;
1773         bool worn_with_flag( const flag_id &flag ) const;
1774         /** Returns the first worn item with a given flag. */
1775         item item_worn_with_flag( const flag_id &flag, const bodypart_id &bp ) const;
1776         item item_worn_with_flag( const flag_id &flag ) const;
1777 
1778         // drawing related stuff
1779         /**
1780          * Returns a list of the IDs of overlays on this character,
1781          * sorted from "lowest" to "highest".
1782          *
1783          * Only required for rendering.
1784          */
1785         std::vector<std::string> get_overlay_ids() const;
1786 
1787         // --------------- Skill Stuff ---------------
1788         int get_skill_level( const skill_id &ident ) const;
1789         int get_skill_level( const skill_id &ident, const item &context ) const;
1790 
1791         const SkillLevelMap &get_all_skills() const;
1792         SkillLevel &get_skill_level_object( const skill_id &ident );
1793         const SkillLevel &get_skill_level_object( const skill_id &ident ) const;
1794 
1795         void set_skill_level( const skill_id &ident, int level );
1796         void mod_skill_level( const skill_id &ident, int delta );
1797         /** Checks whether the character's skills meet the required */
1798         bool meets_skill_requirements( const std::map<skill_id, int> &req,
1799                                        const item &context = item() ) const;
1800         /** Checks whether the character's skills meet the required */
1801         bool meets_skill_requirements( const construction &con ) const;
1802         /** Checks whether the character's stats meets the stats required by the item */
1803         bool meets_stat_requirements( const item &it ) const;
1804         /** Checks whether the character meets overall requirements to be able to use the item */
1805         bool meets_requirements( const item &it, const item &context = item() ) const;
1806         /** Returns a string of missed requirements (both stats and skills) */
1807         std::string enumerate_unmet_requirements( const item &it, const item &context = item() ) const;
1808 
1809         /** Returns the player's skill rust rate */
1810         int rust_rate() const;
1811 
1812         // Mental skills and stats
1813         /** Returns the player's reading speed */
1814         int read_speed( bool return_stat_effect = true ) const;
1815         /** Returns a value used when attempting to convince NPC's of something */
1816         int talk_skill() const;
1817         /** Returns a value used when attempting to intimidate NPC's */
1818         int intimidation() const;
1819 
1820         // --------------- Proficiency Stuff ----------------
1821         bool has_proficiency( const proficiency_id &prof ) const;
1822         bool has_prof_prereqs( const proficiency_id &prof ) const;
1823         void add_proficiency( const proficiency_id &prof, bool ignore_requirements = false );
1824         void lose_proficiency( const proficiency_id &prof, bool ignore_requirements = false );
1825         void practice_proficiency( const proficiency_id &prof, const time_duration &amount,
1826                                    const cata::optional<time_duration> &max = cata::nullopt );
1827         time_duration proficiency_training_needed( const proficiency_id &prof ) const;
1828         std::vector<display_proficiency> display_proficiencies() const;
1829         std::vector<proficiency_id> known_proficiencies() const;
1830         std::vector<proficiency_id> learning_proficiencies() const;
1831 
1832         // --------------- Other Stuff ---------------
1833 
1834         /** return the calendar::turn the character expired */
1835         time_point get_time_died() const {
1836             return time_died;
1837         }
1838         /** set the turn the turn the character died if not already done */
1839         void set_time_died( const time_point &time ) {
1840             if( time_died != calendar::before_time_starts ) {
1841                 time_died = time;
1842             }
1843         }
1844         // magic mod
1845         pimpl<known_magic> magic;
1846 
1847         // gets all the spells known by this character that have this spell class
1848         // spells returned are a copy, do not try to edit them from here, instead use known_magic::get_spell
1849         std::vector<spell> spells_known_of_class( const trait_id &spell_class ) const;
1850 
1851         void make_bleed( const effect_source &source, const bodypart_id &bp, time_duration duration,
1852                          int intensity = 1, bool permanent = false, bool force = false, bool defferred = false );
1853 
1854         /** Calls Creature::normalize()
1855          *  nulls out the player's weapon
1856          *  Should only be called through player::normalize(), not on it's own!
1857          */
1858         void normalize() override;
1859         void die( Creature *nkiller ) override;
1860 
1861         std::string get_name() const override;
1862 
1863         std::vector<std::string> get_grammatical_genders() const override;
1864 
1865         /**
1866          * It is supposed to hide the query_yn to simplify player vs. npc code.
1867          */
1868         template<typename ...Args>
1869         bool query_yn( const char *const msg, Args &&... args ) const {
1870             return query_yn( string_format( msg, std::forward<Args>( args ) ... ) );
1871         }
1872         virtual bool query_yn( const std::string &msg ) const = 0;
1873 
1874         bool is_immune_field( const field_type_id &fid ) const override;
1875         /** Returns true is the player is protected from electric shocks */
1876         bool is_elec_immune() const override;
1877         /** Returns true if the player is immune to this kind of effect */
1878         bool is_immune_effect( const efftype_id & ) const override;
1879         /** Returns true if the player is immune to this kind of damage */
1880         bool is_immune_damage( damage_type ) const override;
1881         /** Returns true if the player is protected from radiation */
1882         bool is_rad_immune() const;
1883         /** Returns true if the player is immune to throws */
1884         bool is_throw_immune() const;
1885 
1886         /** Returns true if the player has some form of night vision */
1887         bool has_nv();
1888 
1889         /**
1890          * Returns >0 if character is sitting/lying and relatively inactive.
1891          * 1 represents sleep on comfortable bed, so anything above that should be rare.
1892          */
1893         float rest_quality() const;
1894         /**
1895          * Average hit points healed per turn.
1896          */
1897         float healing_rate( float at_rest_quality ) const;
1898         /**
1899          * Average hit points healed per turn from healing effects.
1900          */
1901         float healing_rate_medicine( float at_rest_quality, const bodypart_id &bp ) const;
1902 
1903         /**
1904          * Goes over all mutations, gets min and max of a value with given name
1905          * @return min( 0, lowest ) + max( 0, highest )
1906          */
1907         float mutation_value( const std::string &val ) const;
1908 
1909         /**
1910          * Goes over all mutations/bionics, returning the sum of the social modifiers
1911          */
1912         social_modifiers get_mutation_bionic_social_mods() const;
1913 
1914         // Display
1915         nc_color symbol_color() const override;
1916         const std::string &symbol() const override;
1917 
1918         std::string extended_description() const override;
1919 
1920         // In newcharacter.cpp
1921         void empty_skills();
1922         /** Returns a random name from NAMES_* */
1923         void pick_name( bool bUseDefault = false );
1924         /** Get the idents of all base traits. */
1925         std::vector<trait_id> get_base_traits() const;
1926         /** Get the idents of all traits/mutations. */
1927         std::vector<trait_id> get_mutations( bool include_hidden = true ) const;
1928         const std::bitset<NUM_VISION_MODES> &get_vision_modes() const {
1929             return vision_mode_cache;
1930         }
1931         /** Empties the trait and mutations lists */
1932         void clear_mutations();
1933         /**
1934          * Adds mandatory scenario and profession traits unless you already have them
1935          * And if you do already have them, refunds the points for the trait
1936          */
1937         void add_traits();
1938         void add_traits( points_left &points );
1939         /** Returns true if the player has crossed a mutation threshold
1940          *  Player can only cross one mutation threshold.
1941          */
1942         bool crossed_threshold() const;
1943 
1944         // --------------- Values ---------------
1945         std::string name;
1946         bool male = false;
1947 
1948         std::list<item> worn;
1949         bool nv_cached = false;
1950         // Means player sit inside vehicle on the tile he is now
1951         bool in_vehicle = false;
1952         bool hauling = false;
1953 
1954         player_activity stashed_outbounds_activity;
1955         player_activity stashed_outbounds_backlog;
1956         player_activity activity;
1957         std::list<player_activity> backlog;
1958         cata::optional<tripoint> destination_point;
1959         pimpl<inventory> inv;
1960         itype_id last_item;
1961         item weapon;
1962 
1963         int scent = 0;
1964         pimpl<bionic_collection> my_bionics;
1965         pimpl<character_martial_arts> martial_arts_data;
1966 
1967         stomach_contents stomach;
1968         stomach_contents guts;
1969         std::list<consumption_event> consumption_history;
1970 
1971         int oxygen = 0;
1972         int slow_rad = 0;
1973         blood_type my_blood_type;
1974         bool blood_rh_factor = false;
1975         // Randomizes characters' blood type and Rh
1976         void randomize_blood();
1977 
1978         int get_focus() const {
1979             return std::max( 1, focus_pool / 1000 );
1980         }
1981         void mod_focus( int amount ) {
1982             focus_pool += amount * 1000;
1983             focus_pool = std::max( focus_pool, 0 );
1984         }
1985         // Set the focus pool directly, only use for debugging.
1986         void set_focus( int amount ) {
1987             focus_pool = amount * 1000;
1988         }
1989     protected:
1990         int focus_pool = 0;
1991     public:
1992         int cash = 0;
1993         std::set<character_id> follower_ids;
1994         weak_ptr_fast<Creature> last_target;
1995         cata::optional<tripoint> last_target_pos;
1996         // Save favorite ammo location
1997         item_location ammo_location;
1998         std::set<tripoint_abs_omt> camps;
1999 
2000         std::vector <addiction> addictions;
2001         /** Adds an addiction to the player */
2002         void add_addiction( add_type type, int strength );
2003         /** Removes an addition from the player */
2004         void rem_addiction( add_type type );
2005         /** Returns true if the player has an addiction of the specified type */
2006         bool has_addiction( add_type type ) const;
2007         /** Returns the intensity of the specified addiction */
2008         int addiction_level( add_type type ) const;
2009 
2010         shared_ptr_fast<monster> mounted_creature;
2011         // for loading NPC mounts
2012         int mounted_creature_id = 0;
2013         // for vehicle work
2014         int activity_vehicle_part_index = -1;
2015 
2016         // Hauling items on the ground
2017         void start_hauling();
2018         void stop_hauling();
2019         bool is_hauling() const;
2020 
2021         // Has a weapon, inventory item or worn item with flag
2022         bool has_item_with_flag( const flag_id &flag, bool need_charges = false ) const;
2023         /**
2024          * All items that have the given flag (@ref item::has_flag).
2025          */
2026         std::vector<const item *> all_items_with_flag( const flag_id &flag ) const;
2027 
2028         bool has_charges( const itype_id &it, int quantity,
2029                           const std::function<bool( const item & )> &filter = return_true<item> ) const override;
2030 
2031         // has_amount works ONLY for quantity.
2032         // has_charges works ONLY for charges.
2033         std::list<item> use_amount( const itype_id &it, int quantity,
2034                                     const std::function<bool( const item & )> &filter = return_true<item> );
2035         // Uses up charges
2036         bool use_charges_if_avail( const itype_id &it, int quantity );
2037 
2038         /**
2039         * Use charges in character inventory.
2040         * @param what itype_id of item using charges
2041         * @param qty Number of charges
2042         * @param filter Filter
2043         * @return List of items used
2044         */
2045         std::list<item> use_charges( const itype_id &what, int qty,
2046                                      const std::function<bool( const item & )> &filter = return_true<item> );
2047         /**
2048         * Use charges within a radius. Includes character inventory.
2049         * @param what itype_id of item using charges
2050         * @param qty Number of charges
2051         * @param radius Radius from the character. Use -1 to use from character inventory only.
2052         * @param filter Filter
2053         * @return List of items used
2054         */
2055         std::list<item> use_charges( const itype_id &what, int qty, int radius,
2056                                      const std::function<bool( const item & )> &filter = return_true<item> );
2057 
2058         const item *find_firestarter_with_charges( int quantity ) const;
2059         bool has_fire( int quantity ) const;
2060         void use_fire( int quantity );
2061         void assign_stashed_activity();
2062         bool check_outbounds_activity( const player_activity &act, bool check_only = false );
2063         /// @warning Legacy activity assignment, does not work for any activities using
2064         /// the new activity_actor class and may cause issues with resuming.
2065         /// @todo delete this once migration of activities to the activity_actor system is complete
2066         void assign_activity( const activity_id &type, int moves = calendar::INDEFINITELY_LONG,
2067                               int index = -1, int pos = INT_MIN,
2068                               const std::string &name = "" );
2069         /** Assigns activity to player, possibly resuming old activity if it's similar enough. */
2070         void assign_activity( const player_activity &act, bool allow_resume = true );
2071         /** Check if player currently has a given activity */
2072         bool has_activity( const activity_id &type ) const;
2073         /** Check if player currently has any of the given activities */
2074         bool has_activity( const std::vector<activity_id> &types ) const;
2075         void resume_backlog_activity();
2076         void cancel_activity();
2077         void cancel_stashed_activity();
2078         player_activity get_stashed_activity() const;
2079         void set_stashed_activity( const player_activity &act,
2080                                    const player_activity &act_back = player_activity() );
2081         bool has_stashed_activity() const;
2082         bool can_stash( const item &it );
2083         bool can_stash_partial( const item &it );
2084         void initialize_stomach_contents();
2085 
2086         /** Stable base metabolic rate due to traits */
2087         float metabolic_rate_base() const;
2088         /** Current metabolic rate due to traits, hunger, speed, etc. */
2089         float metabolic_rate() const;
2090         // gets the max value healthy you can be, related to your weight
2091         int get_max_healthy() const;
2092         // gets the string that describes your weight
2093         std::string get_weight_string() const;
2094         // gets the description, printed in player_display, related to your current bmi
2095         std::string get_weight_long_description() const;
2096         // calculates the BMI
2097         float get_bmi() const;
2098         // returns amount of calories burned in a day given various metabolic factors
2099         int get_bmr() const;
2100         // add spent calories to calorie diary (if avatar)
2101         virtual void add_spent_calories( int /* cal */ ) {}
2102         // add gained calories to calorie diary (if avatar)
2103         virtual void add_gained_calories( int /* gained */ ) {}
2104         // log the activity level in the calorie diary (if avatar)
2105         virtual void log_activity_level( float /*level*/ ) {}
2106         // Reset age and height to defaults for consistent test results
2107         void reset_chargen_attributes();
2108         // age in years, determined at character creation
2109         int base_age() const;
2110         void set_base_age( int age );
2111         void mod_base_age( int mod );
2112         // age in years
2113         int age() const;
2114         std::string age_string() const;
2115         // returns the height in cm
2116         int base_height() const;
2117         void set_base_height( int height );
2118         void mod_base_height( int mod );
2119         std::string height_string() const;
2120         // returns the height of the player character in cm
2121         int height() const;
2122         // returns bodyweight of the Character
2123         units::mass bodyweight() const;
2124         // returns total weight of installed bionics
2125         units::mass bionics_weight() const;
2126         // increases the activity level to the specified level
2127         // does not decrease activity level
2128         void set_activity_level( float new_level );
2129         // decreases activity level to the specified level
2130         // does not increase activity level
2131         void decrease_activity_level( float new_level );
2132         // sets activity level to NO_EXERCISE
2133         void reset_activity_level();
2134         // outputs player activity level to a printable string
2135         std::string activity_level_str() const;
2136 
2137         /** Returns overall bashing resistance for the body_part */
2138         int get_armor_bash( bodypart_id bp ) const override;
2139         /** Returns overall cutting resistance for the body_part */
2140         int get_armor_cut( bodypart_id bp ) const override;
2141         /** Returns overall bullet resistance for the body_part */
2142         int get_armor_bullet( bodypart_id bp ) const override;
2143         /** Returns bashing resistance from the creature and armor only */
2144         int get_armor_bash_base( bodypart_id bp ) const override;
2145         /** Returns cutting resistance from the creature and armor only */
2146         int get_armor_cut_base( bodypart_id bp ) const override;
2147         /** Returns cutting resistance from the creature and armor only */
2148         int get_armor_bullet_base( bodypart_id bp ) const override;
2149         /** Returns overall env_resist on a body_part */
2150         int get_env_resist( bodypart_id bp ) const override;
2151         /** Returns overall acid resistance for the body part */
2152         int get_armor_acid( bodypart_id bp ) const;
2153         /** Returns overall resistance to given type on the bod part */
2154         int get_armor_type( damage_type dt, bodypart_id bp ) const override;
2155 
2156         int get_stim() const;
2157         void set_stim( int new_stim );
2158         void mod_stim( int mod );
2159 
2160         int get_rad() const;
2161         void set_rad( int new_rad );
2162         void mod_rad( int mod );
2163 
2164         int get_stamina() const;
2165         int get_stamina_max() const;
2166         void set_stamina( int new_stamina );
2167         void mod_stamina( int mod );
2168         void burn_move_stamina( int moves );
2169         float stamina_move_cost_modifier() const;
2170         /** Regenerates stamina */
2171         void update_stamina( int turns );
2172 
2173     protected:
2174         void on_damage_of_type( int adjusted_damage, damage_type type, const bodypart_id &bp ) override;
2175     public:
2176         /** Called when an item is worn */
2177         void on_item_wear( const item &it );
2178         /** Called when an item is taken off */
2179         void on_item_takeoff( const item &it );
2180         /** Called when an item is washed */
2181         void on_worn_item_washed( const item &it );
2182         /** Called when effect intensity has been changed */
2183         void on_effect_int_change( const efftype_id &eid, int intensity,
2184                                    const bodypart_id &bp = bodypart_id( "bp_null" ) ) override;
2185         /** Called when a mutation is gained */
2186         void on_mutation_gain( const trait_id &mid );
2187         /** Called when a mutation is lost */
2188         void on_mutation_loss( const trait_id &mid );
2189         /** Called when a stat is changed */
2190         void on_stat_change( const std::string &stat, int value ) override;
2191         /** Returns an unoccupied, safe adjacent point. If none exists, returns player position. */
2192         tripoint adjacent_tile() const;
2193         /** Returns true if the player has a trait which cancels the entered trait */
2194         bool has_opposite_trait( const trait_id &flag ) const;
2195         /** Removes "sleep" and "lying_down" */
2196         void wake_up();
2197         // how loud a character can shout. based on mutations and clothing
2198         int get_shout_volume() const;
2199         // shouts a message
2200         void shout( std::string msg = "", bool order = false );
2201         /** Handles Character vomiting effects */
2202         void vomit();
2203 
2204         std::map<mutation_category_id, int> mutation_category_level;
2205 
2206         int adjust_for_focus( int amount ) const;
2207         void update_type_of_scent( bool init = false );
2208         void update_type_of_scent( const trait_id &mut, bool gain = true );
2209         void set_type_of_scent( const scenttype_id &id );
2210         scenttype_id get_type_of_scent() const;
2211         /**restore scent after masked_scent effect run out or is removed by water*/
2212         void restore_scent();
2213         /** Modifies intensity of painkillers  */
2214         void mod_painkiller( int npkill );
2215         /** Sets intensity of painkillers  */
2216         void set_painkiller( int npkill );
2217         /** Returns intensity of painkillers  */
2218         int get_painkiller() const;
2219         void react_to_felt_pain( int intensity );
2220 
2221         void spores();
2222         void blossoms();
2223 
2224         /** Handles rooting effects */
2225         void rooted_message() const;
2226         void rooted();
2227 
2228         /** Adds "sleep" to the player */
2229         void fall_asleep();
2230         void fall_asleep( const time_duration &duration );
2231         /** Checks to see if the player is using floor items to keep warm, and return the name of one such item if so */
2232         std::string is_snuggling() const;
2233 
2234         /** Prompts user about crushing item at item_location loc, for harvesting of frozen liquids
2235         * @param loc Location for item to crush */
2236         bool crush_frozen_liquid( item_location loc );
2237 
2238         float power_rating() const override;
2239         float speed_rating() const override;
2240 
2241         /** Returns the item in the player's inventory with the highest of the specified quality*/
2242         item &item_with_best_of_quality( const quality_id &qid );
2243         /**
2244          * Check whether the this player can see the other creature with infrared. This implies
2245          * this player can see infrared and the target is visible with infrared (is warm).
2246          * And of course a line of sight exists.
2247         */
2248         bool sees_with_infrared( const Creature &critter ) const;
2249         // Put corpse+inventory on map at the place where this is.
2250         void place_corpse();
2251         // Put corpse+inventory on defined om tile
2252         void place_corpse( const tripoint_abs_omt &om_target );
2253 
2254         /** Returns the player's modified base movement cost */
2255         int  run_cost( int base_cost, bool diag = false ) const;
2256         const pathfinding_settings &get_pathfinding_settings() const override;
2257         std::set<tripoint> get_path_avoid() const override;
2258         /**
2259          * Get all hostile creatures currently visible to this player.
2260          */
2261         std::vector<Creature *> get_hostile_creatures( int range ) const;
2262 
2263         /**
2264          * Returns all creatures that this player can see and that are in the given
2265          * range. This player object itself is never included.
2266          * The player character (g->u) is checked and might be included (if applicable).
2267          * @param range The maximal distance (@ref rl_dist), creatures at this distance or less
2268          * are included.
2269          */
2270         std::vector<Creature *> get_visible_creatures( int range ) const;
2271         /**
2272          * As above, but includes all creatures the player can detect well enough to target
2273          * with ranged weapons, e.g. with infrared vision.
2274          */
2275         std::vector<Creature *> get_targetable_creatures( int range, bool melee ) const;
2276         /** Returns an enumeration of visible mutations with colors */
2277         std::string visible_mutations( int visibility_cap ) const;
2278         player_activity get_destination_activity() const;
2279         void set_destination_activity( const player_activity &new_destination_activity );
2280         void clear_destination_activity();
2281         /** Returns warmth provided by armor, etc. */
2282         int warmth( const bodypart_id &bp ) const;
2283         /** Returns warmth provided by an armor's bonus, like hoods, pockets, etc. */
2284         int bonus_item_warmth( const bodypart_id &bp ) const;
2285         /** Can the player lie down and cover self with blankets etc. **/
2286         bool can_use_floor_warmth() const;
2287         /**
2288          * Warmth from terrain, furniture, vehicle furniture and traps.
2289          * Can be negative.
2290          **/
2291         static int floor_bedding_warmth( const tripoint &pos );
2292         /** Warmth from clothing on the floor **/
2293         static int floor_item_warmth( const tripoint &pos );
2294         /** Final warmth from the floor **/
2295         int floor_warmth( const tripoint &pos ) const;
2296 
2297         /** Correction factor of the body temperature due to traits and mutations **/
2298         int bodytemp_modifier_traits( bool overheated ) const;
2299         /** Correction factor of the body temperature due to traits and mutations for player lying on the floor **/
2300         int bodytemp_modifier_traits_floor() const;
2301         /** Value of the body temperature corrected by climate control **/
2302         int temp_corrected_by_climate_control( int temperature ) const;
2303 
2304         bool in_sleep_state() const override;
2305         /** Set vitamin deficiency/excess disease states dependent upon current vitamin levels */
2306         void update_vitamins( const vitamin_id &vit );
2307         /**
2308          * @brief Check current level of a vitamin
2309          *
2310          * @details Accesses level of a given vitamin.  If the vitamin_id specified does not
2311          * exist then this function simply returns 0.
2312          *
2313          * @param vit ID of vitamin to check level for (ie "vitA", "vitB").
2314          * @returns character's current level for specified vitamin
2315          */
2316         int vitamin_get( const vitamin_id &vit ) const;
2317         /**
2318          * Sets level of a vitamin or returns false if id given in vit does not exist
2319          *
2320          * @note status effects are still set for deficiency/excess
2321          *
2322          * @param[in] vit ID of vitamin to adjust quantity for
2323          * @param[in] qty Quantity to set level to
2324          * @returns false if given vitamin_id does not exist, otherwise true
2325          */
2326         bool vitamin_set( const vitamin_id &vit, int qty );
2327         /**
2328           * Add or subtract vitamins from character storage pools
2329          * @param vit ID of vitamin to modify
2330          * @param qty amount by which to adjust vitamin (negative values are permitted)
2331          * @param capped if true prevent vitamins which can accumulate in excess from doing so
2332          * @return adjusted level for the vitamin or zero if vitamin does not exist
2333          */
2334         int vitamin_mod( const vitamin_id &vit, int qty, bool capped = true );
2335         void vitamins_mod( const std::map<vitamin_id, int> &, bool capped = true );
2336         /** Get vitamin usage rate (minutes per unit) accounting for bionics, mutations and effects */
2337         time_duration vitamin_rate( const vitamin_id &vit ) const;
2338 
2339         /** Handles the nutrition value for a comestible **/
2340         int nutrition_for( const item &comest ) const;
2341         /** Can the food be [theoretically] eaten no matter the consequences? */
2342         ret_val<edible_rating> can_eat( const item &food ) const;
2343         /**
2344          * Same as @ref can_eat, but takes consequences into account.
2345          * Asks about them if @param interactive is true, refuses otherwise.
2346          */
2347         ret_val<edible_rating> will_eat( const item &food, bool interactive = false ) const;
2348         /** Determine character's capability of recharging their CBMs. */
2349         int get_acquirable_energy( const item &it ) const;
2350 
2351         /**
2352         * Recharge CBMs whenever possible.
2353         * @return true when recharging was successful.
2354         */
2355         bool fuel_bionic_with( item &it );
2356         /** Used to apply stimulation modifications from food and medication **/
2357         void modify_stimulation( const islot_comestible &comest );
2358         /** Used to apply fatigue modifications from food and medication **/
2359         /** Used to apply radiation from food and medication **/
2360         void modify_fatigue( const islot_comestible &comest );
2361         void modify_radiation( const islot_comestible &comest );
2362         /** Used to apply addiction modifications from food and medication **/
2363         void modify_addiction( const islot_comestible &comest );
2364         /** Used to apply health modifications from food and medication **/
2365         void modify_health( const islot_comestible &comest );
2366         /** Used to compute how filling a food is.*/
2367         double compute_effective_food_volume_ratio( const item &food ) const;
2368         /** Used to calculate dry volume of a chewed food **/
2369         units::volume masticated_volume( const item &food ) const;
2370         /** Used to to display how filling a food is. */
2371         int compute_calories_per_effective_volume( const item &food,
2372                 const nutrients *nutrient = nullptr ) const;
2373         /** Handles the effects of consuming an item */
2374         bool consume_effects( item &food );
2375         /** Check whether the character can consume this very item */
2376         bool can_consume_as_is( const item &it ) const;
2377         /** Check whether the character can consume this item or any of its contents */
2378         bool can_consume( const item &it ) const;
2379         /** True if the character has enough skill (in cooking or survival) to estimate time to rot */
2380         bool can_estimate_rot() const;
2381         /**
2382          * Returns a reference to the item itself (if it's consumable),
2383          * the first of its contents (if it's consumable) or null item otherwise.
2384          * WARNING: consumable does not necessarily guarantee the comestible type.
2385          */
2386         item &get_consumable_from( item &it ) const;
2387 
2388         /** Get calorie & vitamin contents for a comestible, taking into
2389          * account character traits */
2390         /** Get range of possible nutrient content, for a particular recipe,
2391          * depending on choice of ingredients */
2392         std::pair<nutrients, nutrients> compute_nutrient_range(
2393             const item &, const recipe_id &,
2394             const cata::flat_set<flag_id> &extra_flags = {} ) const;
2395         /** Same, but across arbitrary recipes */
2396         std::pair<nutrients, nutrients> compute_nutrient_range(
2397             const itype_id &, const cata::flat_set<flag_id> &extra_flags = {} ) const;
2398         /** Returns allergy type or MORALE_NULL if not allergic for this character */
2399         morale_type allergy_type( const item &food ) const;
2400         nutrients compute_effective_nutrients( const item & ) const;
2401         /** Returns true if the character is wearing something on the entered body part */
2402         bool wearing_something_on( const bodypart_id &bp ) const;
2403         /** Returns true if the character is wearing something occupying the helmet slot */
2404         bool is_wearing_helmet() const;
2405         /** Returns the total encumbrance of all SKINTIGHT and HELMET_COMPAT items covering
2406          *  the head */
2407         int head_cloth_encumbrance() const;
2408         /** Same as footwear factor, but for arms */
2409         double armwear_factor() const;
2410         /** Returns 1 if the player is wearing an item of that count on one foot, 2 if on both,
2411          *  and zero if on neither */
2412         int shoe_type_count( const itype_id &it ) const;
2413         /** Returns 1 if the player is wearing footwear on both feet, .5 if on one,
2414          *  and 0 if on neither */
2415         double footwear_factor() const;
2416         /** Returns true if the player is wearing something on their feet that is not SKINTIGHT */
2417         bool is_wearing_shoes( const side &which_side = side::BOTH ) const;
2418 
2419         /** Swap side on which item is worn; returns false on fail. If interactive is false, don't alert player or drain moves */
2420         bool change_side( item &it, bool interactive = true );
2421         bool change_side( item_location &loc, bool interactive = true );
2422 
2423         bool get_check_encumbrance() const {
2424             return check_encumbrance;
2425         }
2426         void set_check_encumbrance( bool new_check ) {
2427             check_encumbrance = new_check;
2428         }
2429         /** Ticks down morale counters and removes them */
2430         void update_morale();
2431         /** Ensures persistent morale effects are up-to-date */
2432         void apply_persistent_morale();
2433         // the morale penalty for hoarders
2434         void hoarder_morale_penalty();
2435         /** Used to apply morale modifications from food and medication **/
2436         void modify_morale( item &food, int nutr = 0 );
2437         // Modified by traits, &c
2438         int get_morale_level() const;
2439         void add_morale( const morale_type &type, int bonus, int max_bonus = 0,
2440                          const time_duration &duration = 1_hours,
2441                          const time_duration &decay_start = 30_minutes, bool capped = false,
2442                          const itype *item_type = nullptr );
2443         int has_morale( const morale_type &type ) const;
2444         void rem_morale( const morale_type &type, const itype *item_type = nullptr );
2445         void clear_morale();
2446         bool has_morale_to_read() const;
2447         bool has_morale_to_craft() const;
2448         const inventory &crafting_inventory( bool clear_path ) const;
2449         /**
2450         * Returns items that can be used to craft with. Always includes character inventory.
2451         * @param src_pos Character position.
2452         * @param radius Radius from src_pos. -1 to return items in character inventory only.
2453         * @param clear_path True to select only items within view. False to select all within the radius.
2454         * @returns Craftable inventory items found.
2455         * */
2456         const inventory &crafting_inventory( const tripoint &src_pos = tripoint_zero,
2457                                              int radius = PICKUP_RANGE, bool clear_path = true ) const;
2458         void invalidate_crafting_inventory();
2459 
2460         /** Returns a value from 1.0 to 11.0 that acts as a multiplier
2461          * for the time taken to perform tasks that require detail vision,
2462          * above 4.0 means these activities cannot be performed.
2463          * takes pos as a parameter so that remote spots can be judged
2464          * if they will potentially have enough light when player gets there */
2465         float fine_detail_vision_mod( const tripoint &p = tripoint_zero ) const;
2466 
2467         // ---- CRAFTING ----
2468         void make_craft_with_command( const recipe_id &id_to_make, int batch_size, bool is_long,
2469                                       const cata::optional<tripoint> &loc );
2470         pimpl<craft_command> last_craft;
2471 
2472         recipe_id lastrecipe;
2473         int last_batch;
2474         itype_id lastconsumed;        //used in crafting.cpp and construction.cpp
2475 
2476         // Checks crafting inventory for books providing the requested recipe.
2477         // Then checks nearby NPCs who could provide it too.
2478         // Returns -1 to indicate recipe not found, otherwise difficulty to learn.
2479         int has_recipe( const recipe *r, const inventory &crafting_inv,
2480                         const std::vector<npc *> &helpers ) const;
2481         bool knows_recipe( const recipe *rec ) const;
2482         void learn_recipe( const recipe *rec );
2483         int exceeds_recipe_requirements( const recipe &rec ) const;
2484         bool has_recipe_requirements( const recipe &rec ) const;
2485         bool can_decomp_learn( const recipe &rec ) const;
2486 
2487         bool studied_all_recipes( const itype &book ) const;
2488 
2489         /** Returns all known recipes. */
2490         const recipe_subset &get_learned_recipes() const;
2491         /** Returns all recipes that are known from the books (either in inventory or nearby). */
2492         recipe_subset get_recipes_from_books( const inventory &crafting_inv ) const;
2493         /**
2494           * Returns all available recipes (from books and npc companions)
2495           * @param crafting_inv Current available items to craft
2496           * @param helpers List of NPCs that could help with crafting.
2497           */
2498         recipe_subset get_available_recipes( const inventory &crafting_inv,
2499                                              const std::vector<npc *> *helpers = nullptr ) const;
2500         /**
2501           * Returns the set of book types in crafting_inv that provide the
2502           * given recipe.
2503           * @param crafting_inv Current available items that may contain readable books
2504           * @param r Recipe to search for in the available books
2505           */
2506         std::set<itype_id> get_books_for_recipe( const inventory &crafting_inv,
2507                 const recipe *r ) const;
2508 
2509         // crafting.cpp
2510         float morale_crafting_speed_multiplier( const recipe &rec ) const;
2511         float lighting_craft_speed_multiplier( const recipe &rec ) const;
2512         float crafting_speed_multiplier( const recipe &rec, bool in_progress = false ) const;
2513         /** For use with in progress crafts */
2514         float crafting_speed_multiplier( const item &craft, const cata::optional<tripoint> &loc ) const;
2515         int available_assistant_count( const recipe &rec ) const;
2516         /**
2517          * Expected time to craft a recipe, with assumption that multipliers stay constant.
2518          */
2519         int64_t expected_time_to_craft( const recipe &rec, int batch_size = 1 ) const;
2520         std::vector<const item *> get_eligible_containers_for_crafting() const;
2521         bool check_eligible_containers_for_crafting( const recipe &rec, int batch_size = 1 ) const;
2522         bool can_make( const recipe *r, int batch_size = 1 );  // have components?
2523         /**
2524          * Returns true if the player can start crafting the recipe with the given batch size
2525          * The player is not required to have enough tool charges to finish crafting, only to
2526          * complete the first step (total / 20 + total % 20 charges)
2527          */
2528         bool can_start_craft( const recipe *rec, recipe_filter_flags, int batch_size = 1 );
2529         bool making_would_work( const recipe_id &id_to_make, int batch_size );
2530 
2531         /**
2532          * Start various types of crafts
2533          * @param loc the location of the workbench. cata::nullopt indicates crafting from inventory.
2534          */
2535         void craft( const cata::optional<tripoint> &loc = cata::nullopt );
2536         void recraft( const cata::optional<tripoint> &loc = cata::nullopt );
2537         void long_craft( const cata::optional<tripoint> &loc = cata::nullopt );
2538         void make_craft( const recipe_id &id, int batch_size,
2539                          const cata::optional<tripoint> &loc = cata::nullopt );
2540         void make_all_craft( const recipe_id &id, int batch_size,
2541                              const cata::optional<tripoint> &loc );
2542         /** consume components and create an active, in progress craft containing them */
2543         void start_craft( craft_command &command, const cata::optional<tripoint> &loc );
2544         /**
2545          * Calculate a value representing the success of the player at crafting the given recipe,
2546          * taking player skill, recipe difficulty, npc helpers, and player mutations into account.
2547          * @param making the recipe for which to calculate
2548          * @return a value >= 0.0 with >= 1.0 representing unequivocal success
2549          */
2550         double crafting_success_roll( const recipe &making ) const;
2551         void complete_craft( item &craft, const cata::optional<tripoint> &loc );
2552         /**
2553          * Check if the player meets the requirements to continue the in progress craft and if
2554          * unable to continue print messages explaining the reason.
2555          * If the craft is missing components due to messing up, prompt to consume new ones to
2556          * allow the craft to be continued.
2557          * @param craft the currently in progress craft
2558          * @return if the craft can be continued
2559          */
2560         bool can_continue_craft( item &craft );
2561         bool can_continue_craft( item &craft, const requirement_data &continue_reqs );
2562         /** Returns nearby NPCs ready and willing to help with crafting. */
2563         std::vector<npc *> get_crafting_helpers() const;
2564         int get_num_crafting_helpers( int max ) const;
2565         /**
2566          * Handle skill gain for player and followers during crafting
2567          * @param craft the currently in progress craft
2568          * @param num_practice_ticks to trigger.  This is used to apply
2569          * multiple steps of incremental skill gain simultaneously if needed.
2570          */
2571         void craft_skill_gain( const item &craft, const int &num_practice_ticks );
2572         /**
2573          * Handle proficiency practice for player and followers while crafting
2574          * @param craft - the in progress craft
2575          * @param time - the amount of time since the last practice tick
2576          */
2577         void craft_proficiency_gain( const item &craft, const time_duration &time );
2578         /**
2579          * Check if the player can disassemble an item using the current crafting inventory
2580          * @param obj Object to check for disassembly
2581          * @param inv current crafting inventory
2582          */
2583         ret_val<bool> can_disassemble( const item &obj, const read_only_visitable &inv ) const;
2584         item_location create_in_progress_disassembly( item_location target );
2585 
2586         bool disassemble();
2587         bool disassemble( item_location target, bool interactive = true );
2588         void disassemble_all( bool one_pass ); // Disassemble all items on the tile
2589         void complete_disassemble( item_location target );
2590         void complete_disassemble( item_location &target, const recipe &dis );
2591 
2592         const requirement_data *select_requirements(
2593             const std::vector<const requirement_data *> &, int batch, const read_only_visitable &,
2594             const std::function<bool( const item & )> &filter ) const;
2595         comp_selection<item_comp>
2596         select_item_component( const std::vector<item_comp> &components,
2597                                int batch, read_only_visitable &map_inv, bool can_cancel = false,
2598                                const std::function<bool( const item & )> &filter = return_true<item>, bool player_inv = true );
2599         std::list<item> consume_items( const comp_selection<item_comp> &is, int batch,
2600                                        const std::function<bool( const item & )> &filter = return_true<item> );
2601         std::list<item> consume_items( map &m, const comp_selection<item_comp> &is, int batch,
2602                                        const std::function<bool( const item & )> &filter = return_true<item>,
2603                                        const tripoint &origin = tripoint_zero, int radius = PICKUP_RANGE );
2604         std::list<item> consume_items( const std::vector<item_comp> &components, int batch = 1,
2605                                        const std::function<bool( const item & )> &filter = return_true<item> );
2606         bool consume_software_container( const itype_id &software_id );
2607         comp_selection<tool_comp>
2608         select_tool_component( const std::vector<tool_comp> &tools, int batch, read_only_visitable &map_inv,
2609                                bool can_cancel = false, bool player_inv = true,
2610         const std::function<int( int )> &charges_required_modifier = []( int i ) {
2611             return i;
2612         } );
2613         /** Consume tools for the next multiplier * 5% progress of the craft */
2614         bool craft_consume_tools( item &craft, int multiplier, bool start_craft );
2615         void consume_tools( const comp_selection<tool_comp> &tool, int batch );
2616         void consume_tools( map &m, const comp_selection<tool_comp> &tool, int batch,
2617                             const tripoint &origin = tripoint_zero, int radius = PICKUP_RANGE,
2618                             basecamp *bcp = nullptr );
2619         void consume_tools( const std::vector<tool_comp> &tools, int batch = 1 );
2620 
2621         /** Checks permanent morale for consistency and recovers it when an inconsistency is found. */
2622         void check_and_recover_morale();
2623 
2624         /** Handles the enjoyability value for a comestible. First value is enjoyability, second is cap. **/
2625         std::pair<int, int> fun_for( const item &comest ) const;
2626 
2627         /** Handles a large number of timers decrementing and other randomized effects */
2628         void suffer();
2629         /** Handles mitigation and application of radiation */
2630         bool irradiate( float rads, bool bypass = false );
2631         /** Handles the chance for broken limbs to spontaneously heal to 1 HP */
2632         void mend( int rate_multiplier );
2633 
2634         /** Creates an auditory hallucination */
2635         void sound_hallu();
2636 
2637         /** Drenches the player with water, saturation is the percent gotten wet */
2638         void drench( int saturation, const body_part_set &flags, bool ignore_waterproof );
2639         /** Recalculates morale penalty/bonus from wetness based on mutations, equipment and temperature */
2640         void apply_wetness_morale( int temperature );
2641         int heartrate_bpm() const;
2642         std::vector<std::string> short_description_parts() const;
2643         std::string short_description() const;
2644         // Checks whether a player can hear a sound at a given volume and location.
2645         bool can_hear( const tripoint &source, int volume ) const;
2646         // Returns a multiplier indicating the keenness of a player's hearing.
2647         float hearing_ability() const;
2648 
2649         using trap_map = std::map<tripoint, std::string>;
2650         // Use @ref trap::can_see to check whether a character knows about a
2651         // specific trap - it will consider visibile and known traps.
2652         bool knows_trap( const tripoint &pos ) const;
2653         void add_known_trap( const tripoint &pos, const trap &t );
2654         /** Define color for displaying the body temperature */
2655         nc_color bodytemp_color( const bodypart_id &bp ) const;
2656 
2657         // see Creature::sees
2658         bool sees( const tripoint &t, bool is_player = false, int range_mod = 0 ) const override;
2659         // see Creature::sees
2660         bool sees( const Creature &critter ) const override;
2661         Attitude attitude_to( const Creature &other ) const override;
2662         virtual npc_attitude get_attitude() const;
2663 
2664         // used in debugging all health
2665         int get_lowest_hp() const;
2666         bool has_weapon() const override;
2667         void shift_destination( const point &shift );
2668         // Auto move methods
2669         void set_destination( const std::vector<tripoint> &route,
2670                               const player_activity &new_destination_activity = player_activity() );
2671         void clear_destination();
2672         bool has_distant_destination() const;
2673 
2674         // true if the player is auto moving, or if the player is going to finish
2675         // auto moving but the destination is not yet reset, such as in avatar_action::move
2676         bool is_auto_moving() const;
2677         // true if there are further moves in the auto move route
2678         bool has_destination() const;
2679         // true if player has destination activity AND is standing on destination tile
2680         bool has_destination_activity() const;
2681         // starts destination activity and cleans up to ensure it is called only once
2682         void start_destination_activity();
2683         std::vector<tripoint> &get_auto_move_route();
2684         action_id get_next_auto_move_direction();
2685         bool defer_move( const tripoint &next );
2686         time_duration get_consume_time( const item &it );
2687 
2688         // For display purposes mainly, how far we are from the next level of weariness
2689         std::pair<int, int> weariness_transition_progress() const;
2690         int weariness_level() const;
2691         int weary_threshold() const;
2692         int weariness() const;
2693         float activity_level() const;
2694         float instantaneous_activity_level() const;
2695         float exertion_adjusted_move_multiplier( float level = -1.0f ) const;
2696         float maximum_exertion_level() const;
2697         std::string activity_level_str( float level ) const;
2698         std::string debug_weary_info() const;
2699         // returns empty because this is avatar specific
2700         void add_pain_msg( int, const bodypart_id & ) const {}
2701         /** Returns the modifier value used for vomiting effects. */
2702         double vomit_mod();
2703         /** Checked each turn during "lying_down", returns true if the player falls asleep */
2704         bool can_sleep();
2705         /** Rate point's ability to serve as a bed. Takes all mutations, fatigue and stimulants into account. */
2706         int sleep_spot( const tripoint &p ) const;
2707         /** Processes human-specific effects of effects before calling Creature::process_effects(). */
2708         void process_effects() override;
2709         /** Handles the still hard-coded effects. */
2710         void hardcoded_effects( effect &it );
2711 
2712         // inherited from visitable
2713         bool has_quality( const quality_id &qual, int level = 1, int qty = 1 ) const override;
2714         int max_quality( const quality_id &qual ) const override;
2715         VisitResponse visit_items( const std::function<VisitResponse( item *, item * )> &func ) const
2716         override;
2717         std::list<item> remove_items_with( const std::function<bool( const item & )> &filter,
2718                                            int count = INT_MAX ) override;
2719         int charges_of( const itype_id &what, int limit = INT_MAX,
2720                         const std::function<bool( const item & )> &filter = return_true<item>,
2721                         const std::function<void( int )> &visitor = nullptr ) const override;
2722         int amount_of( const itype_id &what, bool pseudo = true,
2723                        int limit = INT_MAX,
2724                        const std::function<bool( const item & )> &filter = return_true<item> ) const override;
2725 
2726     protected:
2727         Character();
2728         Character( Character && );
2729         Character &operator=( Character && );
2730         struct trait_data {
2731             /** Whether the mutation is activated. */
2732             bool powered = false;
2733             /** Key to select the mutation in the UI. */
2734             char key = ' ';
2735             /**
2736              * Time (in turns) until the mutation increase hunger/thirst/fatigue according
2737              * to its cost (@ref mutation_branch::cost). When those costs have been paid, this
2738              * is reset to @ref mutation_branch::cooldown.
2739              */
2740             int charge = 0;
2741             void serialize( JsonOut &json ) const;
2742             void deserialize( JsonIn &jsin );
2743         };
2744 
2745         // The player's position on the local map.
2746         tripoint position;
2747 
2748         /** Bonuses to stats, calculated each turn */
2749         int str_bonus = 0;
2750         int dex_bonus = 0;
2751         int per_bonus = 0;
2752         int int_bonus = 0;
2753 
2754         /** How healthy the character is. */
2755         int healthy = 0;
2756         int healthy_mod = 0;
2757 
2758         // Our bmr at no activity level
2759         int base_bmr() const;
2760 
2761         /** age in years at character creation */
2762         int init_age = 25;
2763         /**height at character creation*/
2764         int init_height = 175;
2765         /** Size class of character. */
2766         creature_size size_class = creature_size::medium;
2767 
2768         // the player's activity level for metabolism calculations
2769         activity_tracker activity_history;
2770 
2771         trap_map known_traps;
2772         mutable std::map<std::string, double> cached_info;
2773         bool bio_soporific_powered_at_last_sleep_check = false;
2774         /** last time we checked for sleep */
2775         time_point last_sleep_check = calendar::turn_zero;
2776         /** warnings from a faction about bad behavior */
2777         std::map<faction_id, std::pair<int, time_point>> warning_record;
2778         /**
2779          * Traits / mutations of the character. Key is the mutation id (it's also a valid
2780          * key into @ref mutation_data), the value describes the status of the mutation.
2781          * If there is not entry for a mutation, the character does not have it. If the map
2782          * contains the entry, the character has the mutation.
2783          */
2784         std::unordered_map<trait_id, trait_data> my_mutations;
2785         /**
2786          * Contains mutation ids of the base traits.
2787          */
2788         std::unordered_set<trait_id> my_traits;
2789         /**
2790          * Pointers to mutation branches in @ref my_mutations.
2791          */
2792         std::vector<const mutation_branch *> cached_mutations;
2793         /**
2794          * The amount of weight the Character is carrying.
2795          * If it is nullopt, needs to be recalculated
2796          */
2797         mutable cata::optional<units::mass> cached_weight_carried = cata::nullopt;
2798 
2799         void store( JsonOut &json ) const;
2800         void load( const JsonObject &data );
2801 
2802         // --------------- Values ---------------
2803         pimpl<SkillLevelMap> _skills;
2804 
2805         pimpl<proficiency_set> _proficiencies;
2806 
2807         // Cached vision values.
2808         std::bitset<NUM_VISION_MODES> vision_mode_cache;
2809         int sight_max = 0;
2810 
2811         /// turn the character expired, if calendar::before_time_starts it has not been set yet.
2812         /// @todo change into an optional<time_point>
2813         time_point time_died = calendar::before_time_starts;
2814 
2815         /**
2816          * Cache for pathfinding settings.
2817          * Most of it isn't changed too often, hence mutable.
2818          */
2819         mutable pimpl<pathfinding_settings> path_settings;
2820 
2821         // faction API versions
2822         // 2 - allies are in your_followers faction; NPCATT_FOLLOW is follower but not an ally
2823         // 0 - allies may be in your_followers faction; NPCATT_FOLLOW is an ally (legacy)
2824         // faction API versioning
2825         int faction_api_version = 2;
2826         // A temp variable used to inform the game which faction to link
2827         faction_id fac_id;
2828         faction *my_fac = nullptr;
2829 
2830         move_mode_id move_mode;
2831         /** Current deficiency/excess quantity for each vitamin */
2832         std::map<vitamin_id, int> vitamin_levels;
2833 
2834         pimpl<player_morale> morale;
2835         /** Processes human-specific effects of an effect. */
2836         void process_one_effect( effect &it, bool is_new ) override;
2837 
2838     public:
2839         /**
2840          * Map body parts to their total exposure, from 0.0 (fully covered) to 1.0 (buck naked).
2841          * Clothing layers are multiplied, ex. two layers of 50% coverage will leave only 25% exposed.
2842          * Used to determine suffering effects of albinism and solar sensitivity.
2843          */
2844         std::map<bodypart_id, float> bodypart_exposure();
2845     private:
2846         /** suffer() subcalls */
2847         void suffer_water_damage( const trait_id &mut_id );
2848         void suffer_mutation_power( const trait_id &mut_id );
2849         void suffer_while_underwater();
2850         void suffer_from_addictions();
2851         void suffer_while_awake( int current_stim );
2852         void suffer_from_chemimbalance();
2853         void suffer_from_schizophrenia();
2854         void suffer_from_asthma( int current_stim );
2855         void suffer_from_pain();
2856         void suffer_in_sunlight();
2857         void suffer_from_sunburn();
2858         void suffer_from_other_mutations();
2859         void suffer_from_item_dropping();
2860         void suffer_from_radiation();
2861         void suffer_from_bad_bionics();
2862         void suffer_from_stimulants( int current_stim );
2863         void suffer_from_exertion();
2864         void suffer_without_sleep( int sleep_deprivation );
2865         void suffer_from_tourniquet();
2866         /**
2867          * Check whether the other creature is in range and can be seen by this creature.
2868          * @param critter Creature to check for visibility
2869          * @param range The maximal distance (@ref rl_dist), creatures at this distance or less
2870          * are included.
2871          */
2872         bool is_visible_in_range( const Creature &critter, int range ) const;
2873 
2874         struct auto_toggle_bionic_result;
2875 
2876         /**
2877          * Automatically turn bionic on or off according to remaining fuel and
2878          * user settings, and return info of the first burnable fuel.
2879          */
2880         auto_toggle_bionic_result auto_toggle_bionic( int b, bool start );
2881         /**
2882          *Convert fuel to bionic power
2883          */
2884         void burn_fuel( int b, const auto_toggle_bionic_result &result );
2885 
2886         // a cache of all active enchantment values.
2887         // is recalculated every turn in Character::recalculate_enchantment_cache
2888         pimpl<enchantment> enchantment_cache;
2889         player_activity destination_activity;
2890         /// A unique ID number, assigned by the game class. Values should never be reused.
2891         character_id id;
2892 
2893         units::energy power_level;
2894         units::energy max_power_level;
2895 
2896         // Our weariness level last turn, so we know when we transition
2897         int old_weary_level = 0;
2898 
2899         /// @brief Needs (hunger, starvation, thirst, fatigue, etc.)
2900         // Stored calories is a value in 'calories' - 1/1000s of kcals (or Calories)
2901         int stored_calories;
2902         int healthy_calories;
2903 
2904         int hunger;
2905         int thirst;
2906         int stamina;
2907 
2908         int fatigue;
2909         int sleep_deprivation;
2910         bool check_encumbrance = true;
2911         bool cache_inventory_is_valid = false;
2912 
2913         int stim;
2914         int pkill;
2915 
2916         int radiation;
2917 
2918         std::vector<tripoint> auto_move_route;
2919         // Used to make sure auto move is canceled if we stumble off course
2920         cata::optional<tripoint> next_expected_position;
2921         scenttype_id type_of_scent;
2922 
2923         struct weighted_int_list<std::string> melee_miss_reasons;
2924 
2925         struct crafting_cache_type {
2926             time_point time;
2927             int moves;
2928             tripoint position;
2929             int radius;
2930             pimpl<inventory> crafting_inventory;
2931         };
2932         mutable crafting_cache_type crafting_cache;
2933 
2934     protected:
2935         /** Subset of learned recipes. Needs to be mutable for lazy initialization. */
2936         mutable pimpl<recipe_subset> learned_recipes;
2937 
2938         /** Stamp of skills. @ref learned_recipes are valid only with this set of skills. */
2939         mutable decltype( _skills ) valid_autolearn_skills;
2940 
2941         /** Amount of time the player has spent in each overmap tile. */
2942         std::unordered_map<point_abs_omt, time_duration> overmap_time;
2943 
2944     public:
2945         time_point next_climate_control_check;
2946         bool last_climate_control_ret;
2947 };
2948 
2949 Character &get_player_character();
2950 
2951 template<>
2952 struct enum_traits<character_stat> {
2953     static constexpr character_stat last = character_stat::DUMMY_STAT;
2954 };
2955 /// Get translated name of a stat
2956 std::string get_stat_name( character_stat Stat );
2957 #endif // CATA_SRC_CHARACTER_H
2958