forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
character.h
3575 lines (3172 loc) · 170 KB
/
character.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#ifndef CATA_SRC_CHARACTER_H
#define CATA_SRC_CHARACTER_H
#include <functional>
#include <algorithm>
#include <bitset>
#include <climits>
#include <cstdint>
#include <functional>
#include <iosfwd>
#include <limits>
#include <list>
#include <map>
#include <new>
#include <set>
#include <string>
#include <type_traits>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include "activity_tracker.h"
#include "activity_type.h"
#include "addiction.h"
#include "bodypart.h"
#include "calendar.h"
#include "cata_utility.h"
#include "character_attire.h"
#include "character_id.h"
#include "coordinates.h"
#include "craft_command.h"
#include "creature.h"
#include "damage.h"
#include "enums.h"
#include "flat_set.h"
#include "game_constants.h"
#include "item.h"
#include "item_location.h"
#include "item_pocket.h"
#include "magic_enchantment.h"
#include "memory_fast.h"
#include "optional.h"
#include "overmap.h"
#include "pimpl.h"
#include "player_activity.h"
#include "point.h"
#include "ranged.h"
#include "recipe.h"
#include "ret_val.h"
#include "stomach.h"
#include "string_formatter.h"
#include "type_id.h"
#include "units_fwd.h"
#include "visitable.h"
#include "weakpoint.h"
#include "weighted_list.h"
class Character;
class JsonIn;
class JsonObject;
class JsonOut;
class SkillLevel;
class SkillLevelMap;
class basecamp;
class bionic_collection;
class character_martial_arts;
class dispersion_sources;
class effect;
class effect_source;
class faction;
class inventory;
class known_magic;
class ma_technique;
class map;
class monster;
class nc_color;
class npc;
class player_morale;
class proficiency_set;
class recipe_subset;
class spell;
class vpart_reference;
class vehicle;
struct bionic;
struct construction;
struct dealt_projectile_attack;
struct display_proficiency;
/// @brief Item slot used to apply modifications from food and meds
struct islot_comestible;
struct item_comp;
struct itype;
struct mutation_branch;
struct mutation_variant;
struct needs_rates;
struct pathfinding_settings;
struct points_left;
struct requirement_data;
struct tool_comp;
struct trait_and_var;
struct trap;
struct w_point;
template <typename E> struct enum_traits;
enum npc_attitude : int;
enum action_id : int;
enum class steed_type : int;
enum class proficiency_bonus_type : int;
using drop_location = std::pair<item_location, int>;
using drop_locations = std::list<drop_location>;
using bionic_uid = unsigned int;
constexpr int MAX_CLAIRVOYANCE = 40;
/// @brief type of conditions that effect vision
/// @note vision modes do not necessarily match json ids or flags
enum vision_modes {
DEBUG_NIGHTVISION,
NV_GOGGLES,
NIGHTVISION_1,
NIGHTVISION_2,
NIGHTVISION_3,
FULL_ELFA_VISION,
ELFA_VISION,
CEPH_VISION,
/// mutate w/ id "FEL_NV" & name "Feline Vision" see pretty well at night
FELINE_VISION,
/// Bird mutation named "Avian Eyes": Perception +4
BIRD_EYE,
/// mutate w/ id "URSINE_EYE" & name "Ursine Vision" see better in dark, nearsight in light
URSINE_VISION,
BOOMERED,
DARKNESS,
IR_VISION,
VISION_CLAIRVOYANCE,
VISION_CLAIRVOYANCE_PLUS,
VISION_CLAIRVOYANCE_SUPER,
NUM_VISION_MODES
};
enum class fatigue_levels : int {
TIRED = 191,
DEAD_TIRED = 383,
EXHAUSTED = 575,
MASSIVE_FATIGUE = 1000
};
const std::unordered_map<std::string, fatigue_levels> fatigue_level_strs = { {
{ "TIRED", fatigue_levels::TIRED },
{ "DEAD_TIRED", fatigue_levels::DEAD_TIRED },
{ "EXHAUSTED", fatigue_levels::EXHAUSTED },
{ "MASSIVE_FATIGUE", fatigue_levels::MASSIVE_FATIGUE }
}
};
constexpr inline bool operator>=( const fatigue_levels &lhs, const fatigue_levels &rhs )
{
return static_cast<int>( lhs ) >= static_cast<int>( rhs );
}
constexpr inline bool operator<( const fatigue_levels &lhs, const fatigue_levels &rhs )
{
return static_cast<int>( lhs ) < static_cast<int>( rhs );
}
template<typename T>
constexpr inline bool operator>=( const T &lhs, const fatigue_levels &rhs )
{
return lhs >= static_cast<T>( rhs );
}
template<typename T>
constexpr inline bool operator>( const T &lhs, const fatigue_levels &rhs )
{
return lhs > static_cast<T>( rhs );
}
template<typename T>
constexpr inline bool operator<=( const T &lhs, const fatigue_levels &rhs )
{
return lhs <= static_cast<T>( rhs );
}
template<typename T>
constexpr inline bool operator<( const T &lhs, const fatigue_levels &rhs )
{
return lhs < static_cast<T>( rhs );
}
template<typename T>
constexpr inline int operator/( const fatigue_levels &lhs, const T &rhs )
{
return static_cast<T>( lhs ) / rhs;
}
template<typename T>
constexpr inline int operator+( const fatigue_levels &lhs, const T &rhs )
{
return static_cast<T>( lhs ) + rhs;
}
template<typename T>
constexpr inline int operator-( const fatigue_levels &lhs, const T &rhs )
{
return static_cast<T>( lhs ) - rhs;
}
template<typename T>
constexpr inline int operator-( const T &lhs, const fatigue_levels &rhs )
{
return lhs - static_cast<T>( rhs );
}
/** @brief five levels of consequences for days without sleep
@details Sleep deprivation, distinct from fatigue, is defined in minutes. Although most
calculations scale linearly, malus is bestowed only upon reaching the tiers defined below.
@note Sleep deprivation increases fatigue. Fatigue increase scales with the severity of sleep
deprivation.
@note Sleep deprivation kicks in if lack of sleep is avoided with stimulants or otherwise for
long periods of time
@see https://github.com/CleverRaven/Cataclysm-DDA/blob/master/src/character.cpp#L5566
*/
enum sleep_deprivation_levels {
/// 2 days
SLEEP_DEPRIVATION_HARMLESS = 2 * 24 * 60,
/// 4 days
SLEEP_DEPRIVATION_MINOR = 4 * 24 * 60,
/// 7 days
SLEEP_DEPRIVATION_SERIOUS = 7 * 24 * 60,
/// 10 days
SLEEP_DEPRIVATION_MAJOR = 10 * 24 * 60,
/// 14 days
SLEEP_DEPRIVATION_MASSIVE = 14 * 24 * 60
};
enum class blood_type {
blood_O,
blood_A,
blood_B,
blood_AB,
num_bt
};
template<>
struct enum_traits<blood_type> {
static constexpr blood_type last = blood_type::num_bt;
};
/// @brief how digestible or palatable an item is
/// @details This tries to represent both rating and character's decision to respect said rating
/// (ie "they can eat it, though they are disgusted by it")
enum edible_rating {
/// Edible or we pretend it is
EDIBLE,
/// Not food at all
INEDIBLE,
/// Not food because character has mutated mouth/system
INEDIBLE_MUTATION,
/// You can eat it, but it will hurt morale because of negative trait such as Hates Fruit
ALLERGY,
/// Smaller allergy penalty
ALLERGY_WEAK,
/// Penalty for eating human flesh (unless psycho/cannibal)
CANNIBALISM,
/// Comestible has parasites
PARASITES,
/// Rotten (or, for saprophages, not rotten enough)
ROTTEN,
/// Can provoke vomiting if you already feel nauseous.
NAUSEA,
/// We can eat this, but we'll suffer from overeat
TOO_FULL,
/// Some weird stuff that requires a tool we don't have
NO_TOOL
};
struct queued_eoc {
public:
effect_on_condition_id eoc;
time_point time;
};
struct eoc_compare {
bool operator()( const queued_eoc &lhs, const queued_eoc &rhs ) const {
return lhs.time > rhs.time;
}
};
struct aim_type {
std::string name;
std::string action;
std::string help;
bool has_threshold;
int threshold;
};
struct special_attack {
std::string text;
damage_instance damage;
};
struct consumption_event {
time_point time;
itype_id type_id;
uint64_t component_hash;
consumption_event() = default;
explicit consumption_event( const item &food ) : time( calendar::turn ) {
type_id = food.typeId();
component_hash = food.make_component_hash();
}
void serialize( JsonOut &json ) const;
void deserialize( const JsonObject &jo );
};
struct stat_mod {
int strength = 0;
int dexterity = 0;
int intelligence = 0;
int perception = 0;
int speed = 0;
};
inline social_modifiers operator+( social_modifiers lhs, const social_modifiers &rhs )
{
lhs += rhs;
return lhs;
}
/// @brief Four ability stats available on character creation
/// @details Default is 8. Minimum value is 4 and 14 is considered to be max human value.
enum class character_stat : char {
STRENGTH,
DEXTERITY,
INTELLIGENCE,
PERCEPTION,
DUMMY_STAT
};
enum class customize_appearance_choice : int {
EYES, // customize eye color
HAIR, // customize hair
HAIR_F, // customize facial hair
SKIN // customize skin color
};
enum class book_mastery {
CANT_DETERMINE, // book not yet identified, so you don't know yet
CANT_UNDERSTAND, // does not have enough skill to read
LEARNING,
MASTERED // can no longer increase skill by reading
};
/** @relates ret_val */
template<>
struct ret_val<edible_rating>::default_success : public
std::integral_constant<edible_rating, EDIBLE> {};
/** @relates ret_val */
template<>
struct ret_val<edible_rating>::default_failure : public
std::integral_constant<edible_rating, INEDIBLE> {};
struct needs_rates {
float thirst = 0.0f;
float hunger = 0.0f;
float fatigue = 0.0f;
float recovery = 0.0f;
float kcal = 0.0f;
};
class Character : public Creature, public visitable
{
public:
Character( const Character & ) = delete;
Character &operator=( const Character & ) = delete;
~Character() override;
Character *as_character() override {
return this;
}
const Character *as_character() const override {
return this;
}
bool is_npc() const override {
return false; // Overloaded for NPCs in npc.h
}
// populate variables, inventory items, and misc from json object
virtual void deserialize( const JsonObject &jsobj ) = 0;
// by default save all contained info
virtual void serialize( JsonOut &jsout ) const = 0;
character_id getID() const;
/// sets the ID, will *only* succeed when the current id is not valid
/// allows forcing a -1 id which is required for templates to not throw errors
void setID( character_id i, bool force = false );
field_type_id bloodType() const override;
field_type_id gibType() const override;
bool is_warm() const override;
bool in_species( const species_id &spec ) const override;
/// Turned to false for simulating NPCs on distant missions so they don't drop all their gear in sight
bool death_drops;
/// Is currently in control of a vehicle
bool controlling_vehicle = false;
enum class comfort_level : int {
impossible = -999,
uncomfortable = -7,
neutral = 0,
slightly_comfortable = 3,
comfortable = 5,
very_comfortable = 10
};
/// @brief Character stats
/// @todo Make those protected
int str_max;
int dex_max;
int int_max;
int per_max;
int str_cur;
int dex_cur;
int int_cur;
int per_cur;
int kill_xp = 0;
// Level-up points spent on Stats through Kills
int spent_upgrade_points = 0;
const profession *prof;
std::set<const profession *> hobbies;
// Relative direction of a grab, add to posx, posy to get the coordinates of the grabbed thing.
tripoint grab_point;
cata::optional<city> starting_city;
cata::optional<point_abs_om> world_origin;
bool random_start_location = true;
start_location_id start_location;
bool manual_examine = false;
int volume = 0;
// The prevalence of getter, setter, and mutator functions here is partially
// a result of the slow, piece-wise migration of the player class upwards into
// the character class. As enough logic is moved upwards to fully separate
// utility upwards out of the player class, as many of these as possible should
// be eliminated to allow for proper code separation. (Note: Not "all", many").
/** Getters for stats exclusive to characters */
int get_str() const;
int get_dex() const;
int get_per() const;
int get_int() const;
int get_str_base() const;
int get_dex_base() const;
int get_per_base() const;
int get_int_base() const;
int get_str_bonus() const;
int get_dex_bonus() const;
int get_per_bonus() const;
int get_int_bonus() const;
int get_speed() const override;
int get_enchantment_speed_bonus() const;
// Strength modified by limb lifting score
int get_arm_str() const;
// Defines distance from which CAMOUFLAGE mobs are visible
int get_eff_per() const override;
// Penalty modifiers applied for ranged attacks due to low stats
int ranged_dex_mod() const;
int ranged_per_mod() const;
/** Setters for stats exclusive to characters */
void set_str_bonus( int nstr );
void set_dex_bonus( int ndex );
void set_per_bonus( int nper );
void set_int_bonus( int nint );
void mod_str_bonus( int nstr );
void mod_dex_bonus( int ndex );
void mod_per_bonus( int nper );
void mod_int_bonus( int nint );
// Prints message(s) about current health
void print_health() const;
/** Getters for health values exclusive to characters */
int get_lifestyle() const;
int get_daily_health() const;
int get_health_tally() const;
/** Modifiers for health values exclusive to characters */
void mod_livestyle( int nhealthy );
void mod_daily_health( int nhealthy_mod, int cap );
void mod_health_tally( int mod );
/** Setters for health values exclusive to characters */
void set_lifestyle( int nhealthy );
void set_daily_health( int nhealthy_mod );
/** Getter for need values exclusive to characters */
int get_stored_kcal() const;
int get_healthy_kcal() const;
// Returns stored kcals as a proportion of "healthy" kcals (1.0 == healthy)
float get_kcal_percent() const;
int kcal_speed_penalty() const;
int get_hunger() const;
int get_starvation() const;
virtual int get_thirst() const;
virtual int get_instant_thirst() const;
time_duration get_daily_sleep() const;
void mod_daily_sleep( time_duration mod );
void reset_daily_sleep();
time_duration get_continuous_sleep() const;
void mod_continuous_sleep( time_duration mod );
void reset_continuous_sleep();
int get_fatigue() const;
int get_sleep_deprivation() const;
/** Modifiers for need values exclusive to characters */
void mod_stored_kcal( int nkcal, bool ignore_weariness = false );
void mod_hunger( int nhunger );
void mod_thirst( int nthirst );
void mod_fatigue( int nfatigue );
void mod_sleep_deprivation( int nsleep_deprivation );
/** Setters for need values exclusive to characters */
void set_stored_kcal( int kcal );
void set_hunger( int nhunger );
void set_thirst( int nthirst );
void set_fatigue( int nfatigue );
void set_fatigue( fatigue_levels nfatigue );
void set_sleep_deprivation( int nsleep_deprivation );
protected:
// These accept values in calories, 1/1000s of kcals (or Calories)
void mod_stored_calories( int ncal, bool ignore_weariness = false );
void set_stored_calories( int cal );
public:
void gravity_check();
void mod_stat( const std::string &stat, float modifier ) override;
int get_standard_stamina_cost( const item *thrown_item = nullptr ) const;
/**Get bonus to max_hp from excess stored fat*/
int get_fat_to_hp() const;
/** Get size class of character **/
creature_size get_size() const override;
/** Recalculate size class of character **/
void recalculate_size();
/** Returns either "you" or the player's name. capitalize_first assumes
that the character's name is already upper case and uses it only for
possessive "your" and "you"
**/
std::string disp_name( bool possessive = false, bool capitalize_first = false ) const override;
virtual std::string name_and_maybe_activity() const;
/** Returns the name of the player's outer layer, e.g. "armor plates" */
std::string skin_name() const override;
//message related stuff
using Creature::add_msg_if_player;
void add_msg_if_player( const std::string &msg ) const override;
void add_msg_if_player( const game_message_params ¶ms, const std::string &msg ) const override;
using Creature::add_msg_debug_if_player;
void add_msg_debug_if_player( debugmode::debug_filter type,
const std::string &msg ) const override;
using Creature::add_msg_player_or_npc;
void add_msg_player_or_npc( const std::string &player_msg,
const std::string &npc_str ) const override;
void add_msg_player_or_npc( const game_message_params ¶ms, const std::string &player_msg,
const std::string &npc_msg ) const override;
using Creature::add_msg_debug_player_or_npc;
void add_msg_debug_player_or_npc( debugmode::debug_filter type, const std::string &player_msg,
const std::string &npc_msg ) const override;
using Creature::add_msg_player_or_say;
void add_msg_player_or_say( const std::string &player_msg,
const std::string &npc_speech ) const override;
void add_msg_player_or_say( const game_message_params ¶ms, const std::string &player_msg,
const std::string &npc_speech ) const override;
/* returns the character's faction */
virtual faction *get_faction() const {
return nullptr;
}
void set_fac_id( const std::string &my_fac_id );
// Has item with mission_id
bool has_mission_item( int mission_id ) const;
/* Adjusts provided sight dispersion to account for player stats */
int effective_dispersion( int dispersion, bool zoom = false ) const;
int get_character_parallax( bool zoom = false ) const;
/* Accessors for aspects of aim speed. */
std::vector<aim_type> get_aim_types( const item &gun ) const;
int point_shooting_limit( const item &gun ) const;
double fastest_aiming_method_speed( const item &gun, double recoil,
Target_attributes target_attributes = Target_attributes() ) const;
int most_accurate_aiming_method_limit( const item &gun ) const;
double aim_factor_from_volume( const item &gun ) const;
double aim_factor_from_length( const item &gun ) const;
// Get the value of the specified character modifier.
// (some modifiers require a skill_id, ex: aim_speed_skill_mod)
float get_modifier( const character_modifier_id &mod,
const skill_id &skill = skill_id::NULL_ID() ) const;
/* Gun stuff */
/**
* Check whether the player has a gun that uses the given type of ammo.
*/
bool has_gun_for_ammo( const ammotype &at ) const;
bool has_magazine_for_ammo( const ammotype &at ) const;
/* Calculate aim improvement per move spent aiming at a given @ref recoil */
double aim_per_move( const item &gun, double recoil,
Target_attributes target_attributes = Target_attributes() ) const;
/** Called after the player has successfully dodged an attack */
void on_dodge( Creature *source, float difficulty ) override;
/** Combat getters */
float get_dodge_base() const override;
/** Returns the player's dodge_roll to be compared against an aggressor's hit_roll() */
float dodge_roll() const override;
/** Returns Creature::get_dodge() modified by any Character effects */
float get_dodge() const override;
/** in this case spell resistance is just the spellcraft skill for characters. */
int get_spell_resist() const override;
/** Handles the uncanny dodge bionic and effects, returns true if the player successfully dodges */
bool uncanny_dodge() override;
float get_hit_base() const override;
/** Returns the player's sight range */
int sight_range( int light_level ) const override;
/** Returns the player maximum vision range factoring in mutations, diseases, and other effects */
int unimpaired_range() const;
/** Returns true if overmap tile is within player line-of-sight */
bool overmap_los( const tripoint_abs_omt &omt, int sight_points ) const;
/** Returns the distance the player can see on the overmap */
int overmap_sight_range( int light_level ) const;
/** Returns the distance the player can see through walls */
int clairvoyance() const;
/** Returns true if the player has some form of impaired sight */
bool sight_impaired() const;
/** Returns true if the player or their vehicle has an alarm clock */
bool has_alarm_clock() const;
/** Returns true if the player or their vehicle has a watch */
bool has_watch() const;
/** Called after every action, invalidates player caches */
void action_taken();
/** Returns true if the player is knocked over, has broken legs or is lying down */
bool is_on_ground() const override;
/** Returns the player's movecost for swimming across water tiles. NOT SPEED! */
int swim_speed() const;
/** Returns melee skill level, to be used to throttle dodge practice. **/
float get_melee() const override;
/**
* @brief Adds a reason for why the player would miss a melee attack.
*
* @details To possibly be messaged to the player when he misses a melee attack.
* @param reason A message for the player that gives a reason for him missing.
* @param weight The weight used when choosing what reason to pick when the
* player misses.
*/
void add_miss_reason( const std::string &reason, unsigned int weight );
/** Clears the list of reasons for why the player would miss a melee attack. */
void clear_miss_reasons();
/**
* Returns an explanation for why the player would miss a melee attack.
*/
std::string get_miss_reason();
/**
* Handles passive regeneration of pain and maybe hp.
*/
void regen( int rate_multiplier );
/**
* Check player capable of taking off an item.
* @param it Thing to be taken off
*/
ret_val<bool> can_takeoff( const item &it, const std::list<item> *res = nullptr );
/** @return Odds for success (pair.first) and gunmod damage (pair.second) */
std::pair<int, int> gunmod_installation_odds( const item_location &gun, const item &mod ) const;
/// called once per 24 hours to enforce the minimum of 1 hp healed per day
/// @todo Move to Character once heal() is moved
void enforce_minimum_healing();
/** Calculates the various speed bonuses we will get from mutations, etc. */
void recalc_speed_bonus();
void set_underwater( bool );
bool is_hallucination() const override;
// true if the character produces electrical radiation
bool is_electrical() const override;
/** Returns the penalty to speed from thirst */
static int thirst_speed_penalty( int thirst );
/** Returns the effect of pain on stats */
stat_mod get_pain_penalty() const;
/** returns players strength adjusted by any traits that affect strength during lifting jobs */
int get_lift_str() const;
/** Takes off an item, returning false on fail. The taken off item is processed in the interact */
bool takeoff( item_location loc, std::list<item> *res = nullptr );
bool takeoff( int pos );
/** Returns list of rc items in player inventory. **/
std::list<item *> get_radio_items();
/** get best quality item that this character has */
item *best_quality_item( const quality_id &qual );
/** Handles health fluctuations over time */
virtual void update_health();
/** Updates all "biology" by one turn. Should be called once every turn. */
void update_body();
/** Updates all "biology" as if time between `from` and `to` passed. */
void update_body( const time_point &from, const time_point &to );
/** Updates the stomach to give accurate hunger messages */
void update_stomach( const time_point &from, const time_point &to );
/** Returns true if character needs food, false if character is an NPC with NO_NPC_FOOD set */
bool needs_food() const;
/** Increases hunger, thirst, fatigue and stimulants wearing off. `rate_multiplier` is for retroactive updates. */
void update_needs( int rate_multiplier );
needs_rates calc_needs_rates() const;
void calc_sleep_recovery_rate( needs_rates &rates ) const;
/** Kills the player if too hungry, stimmed up etc., forces tired player to sleep and prints warnings. */
void check_needs_extremes();
/** Handles the chance to be infected by random diseases */
void get_sick();
/** Returns if the player has hibernation mutation and is asleep and well fed */
bool is_hibernating() const;
/** Maintains body temperature */
void update_bodytemp();
void update_frostbite( const bodypart_id &bp, int FBwindPower,
const std::map<bodypart_id, int> &warmth_per_bp );
/** Equalizes heat between body parts */
void temp_equalizer( const bodypart_id &bp1, const bodypart_id &bp2 );
struct comfort_response_t {
comfort_level level = comfort_level::neutral;
const item *aid = nullptr;
};
/** Rate point's ability to serve as a bed. Only takes certain mutations into account, and not fatigue nor stimulants. */
comfort_response_t base_comfort_value( const tripoint &p ) const;
/** Returns focus equilibrium cap due to fatigue **/
int focus_equilibrium_fatigue_cap( int equilibrium ) const;
/** Uses morale and other factors to return the character's focus target goto value */
int calc_focus_equilibrium( bool ignore_pain = false ) const;
/** Calculates actual focus gain/loss value from focus equilibrium*/
int calc_focus_change() const;
/** Uses calc_focus_change to update the character's current focus */
void update_mental_focus();
/** Resets the value of all bonus fields to 0. */
void reset_bonuses() override;
/** Resets stats, and applies effects in an idempotent manner */
void reset_stats() override;
/** Handles stat and bonus reset. */
void reset() override;
/** Returns ENC provided by armor, etc. */
int encumb( const bodypart_id &bp ) const;
int avg_encumb_of_limb_type( body_part_type::type part_type ) const;
/** Returns body weight plus weight of inventory and worn/wielded items */
units::mass get_weight() const override;
// formats and prints encumbrance info to specified window
void print_encumbrance( const catacurses::window &win, int line = -1,
const item *selected_clothing = nullptr ) const;
/** Returns true if the character is wearing power armor */
bool is_wearing_power_armor( bool *hasHelmet = nullptr ) const;
/** Returns true if the character is wearing active power */
bool is_wearing_active_power_armor() const;
/** Returns true if the player is wearing an active optical cloak */
bool is_wearing_active_optcloak() const;
/** Returns true if the player is in a climate controlled area or armor */
bool in_climate_control();
/** Returns wind resistance provided by armor, etc **/
std::map<bodypart_id, int> get_wind_resistance( const
std::map<bodypart_id, std::vector<const item *>> &clothing_map ) const;
/** Returns true if the player isn't able to see */
bool is_blind() const;
bool is_invisible() const;
/** Checks is_invisible() as well as other factors */
int visibility( bool check_color = false, int stillness = 0 ) const;
/** Returns character luminosity based on the brightest active item they are carrying */
float active_light() const;
bool sees_with_specials( const Creature &critter ) const;
/** Bitset of all the body parts covered only with items with `flag` (or nothing) */
body_part_set exclusive_flag_coverage( const flag_id &flag ) const;
/** Processes effects which may prevent the Character from moving (bear traps, crushed, etc.).
* Returns false if movement is stopped. */
bool move_effects( bool attacking ) override;
void wait_effects( bool attacking = false );
/** Series of checks to remove effects for waiting or moving */
bool try_remove_grab();
void try_remove_downed();
void try_remove_bear_trap();
void try_remove_lightsnare();
void try_remove_heavysnare();
void try_remove_crushed();
void try_remove_webs();
void try_remove_impeding_effect();
// Calculate generic trap escape chance
bool can_escape_trap( int difficulty, bool manip );
/** Check against the character's current movement mode */
bool movement_mode_is( const move_mode_id &mode ) const;
move_mode_id current_movement_mode() const;
bool is_running() const;
bool is_walking() const;
bool is_crouching() const;
bool is_prone() const;
int footstep_sound() const;
// the sound clattering items dangling off you can make
int clatter_sound() const;
void make_footstep_noise() const;
void make_clatter_sound() const;
bool can_switch_to( const move_mode_id &mode ) const;
steed_type get_steed_type() const;
virtual void set_movement_mode( const move_mode_id &mode ) = 0;
/**Determine if character is susceptible to dis_type and if so apply the symptoms*/
void expose_to_disease( const diseasetype_id &dis_type );
/**
* Handles end-of-turn processing.
*/
void process_turn() override;
/** Recalculates HP after a change to max strength */
void recalc_hp();
int get_part_hp_max( const bodypart_id &id ) const;
/** Maintains body wetness and handles the rate at which the player dries */
void update_body_wetness( const w_point &weather );
/** Modifies the player's sight values
* Must be called when any of the following change:
* This must be called when any of the following change:
* - effects
* - bionics
* - traits
* - underwater
* - clothes
*/
void recalc_sight_limits();
/**
* Returns the apparent light level at which the player can see.
* This is adjusted by the light level at the *character's* position
* to simulate glare, etc, night vision only works if you are in the dark.
*/
float get_vision_threshold( float light_level ) const;
/**
* Flag encumbrance for updating.
*/
void flag_encumbrance();
/**
* Checks worn items for the "RESET_ENCUMBRANCE" flag, which indicates
* that encumbrance may have changed and require recalculating.
*/
void check_item_encumbrance_flag();
/** Returns true if the character is wearing something on the entered body_part, ignoring items with the ALLOWS_NATURAL_ATTACKS flag */
bool natural_attack_restricted_on( const bodypart_id &bp ) const;
int blocks_left;
int dodges_left;
double recoil = MAX_RECOIL;
std::string custom_profession;
/** Returns true if the player has quiet melee attacks */
bool is_quiet() const;
// melee.cpp
/** Checks for valid block abilities and reduces damage accordingly. Returns true if the player blocks */
bool block_hit( Creature *source, bodypart_id &bp_hit, damage_instance &dam ) override;
/** Returns the best item for blocking with */
item_location best_shield();
/** Calculates melee weapon wear-and-tear through use, returns true if item is destroyed. */
bool handle_melee_wear( item_location shield, float wear_multiplier = 1.0f );
/** Returns a random valid technique */
matec_id pick_technique( Creature &t, const item_location &weap,
bool crit, bool dodge_counter, bool block_counter );
void perform_technique( const ma_technique &technique, Creature &t, damage_instance &di,
int &move_cost, item &cur_weapon );
// modifies the damage dealt based on the character's enchantments
damage_instance modify_damage_dealt_with_enchantments( const damage_instance &dam ) const override;
/**
* Sets up a melee attack and handles melee attack function calls
* @param t Creature to attack
* @param allow_special whether non-forced martial art technique or mutation attack should be
* possible with this attack.
* @param force_technique special technique to use in attack.
* @param allow_unarmed always uses the wielded weapon regardless of martialarts style
*/
bool melee_attack( Creature &t, bool allow_special, const matec_id &force_technique,
bool allow_unarmed = true );
bool melee_attack_abstract( Creature &t, bool allow_special, const matec_id &force_technique,
bool allow_unarmed = true );
/** Handles reach melee attacks */
void reach_attack( const tripoint &p );
/**
* Calls the to other melee_attack function with an empty technique id (meaning no specific
* technique should be used).
*/
bool melee_attack( Creature &t, bool allow_special );
/** Handles combat effects, returns a string of any valid combat effect messages */
std::string melee_special_effects( Creature &t, damage_instance &d, item &weap );
/** Performs special attacks and their effects (poisonous, stinger, etc.) */
void perform_special_attacks( Creature &t, dealt_damage_instance &dealt_dam );
bool reach_attacking = false;
/** Returns a vector of valid mutation attacks */
std::vector<special_attack> mutation_attacks( Creature &t ) const;
/** Returns the bonus bashing damage the player deals based on their stats */
float bonus_damage( bool random ) const;
/** Returns weapon skill */
float get_melee_hit_base() const;
/** Returns the player's basic hit roll that is compared to the target's dodge roll */
float hit_roll() const override;
/** Returns the chance to critical given a hit roll and target's dodge roll */
double crit_chance( float roll_hit, float target_dodge, const item &weap ) const;
/** Returns true if the player scores a critical hit */
bool scored_crit( float target_dodge, const item &weap ) const;
/** Returns cost (in moves) of attacking with given item (no modifiers, like stuck) */
int attack_speed( const item &weap ) const;
/** Returns cost (in stamina) of attacking with given item, or wielded item if nullptr (no modifiers, worst possible is -50) */
int get_base_melee_stamina_cost( const item *weap = nullptr ) const;
/** Returns total cost (in stamina) of attacking with given item, or wielded item if nullptr (modified by skill and walk/crouch/prone, worst possible is -50) */
int get_total_melee_stamina_cost( const item *weap = nullptr ) const;
/** Gets melee accuracy component from weapon+skills */
float get_hit_weapon( const item &weap ) const;
/** Check if we can attack upper limbs **/
bool can_attack_high() const override;
/** NPC-related item rating functions */
double weapon_value( const item &weap, int ammo = 10 ) const; // Evaluates item as a weapon
double gun_value( const item &weap, int ammo = 10 ) const; // Evaluates item as a gun
double melee_value( const item &weap ) const; // As above, but only as melee
double unarmed_value() const; // Evaluate yourself!
/**
* Returns a weapon's modified dispersion value.
* @param obj Weapon to check dispersion on
*/
dispersion_sources get_weapon_dispersion( const item &obj ) const;
// If average == true, adds expected values of random rolls instead of rolling.
/** Adds all 3 types of physical damage to instance */
void roll_all_damage( bool crit, damage_instance &di, bool average, const item &weap,
std::string attack_vector,
const Creature *target, const bodypart_id &bp ) const;
/** Adds player's total bash damage to the damage instance */
void roll_bash_damage( bool crit, damage_instance &di, bool average, const item &weap,
std::string attack_vector,
float crit_mod ) const;
/** Adds player's total cut damage to the damage instance */
void roll_cut_damage( bool crit, damage_instance &di, bool average, const item &weap,
std::string attack_vector,
float crit_mod ) const;
/** Adds player's total stab damage to the damage instance */
void roll_stab_damage( bool crit, damage_instance &di, bool average, const item &weap,
std::string attack_vector,
float crit_mod ) const;
/** Adds player's total non-bash, non-cut, non-stab damage to the damage instance */