-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
player.h
1864 lines (1656 loc) · 87.6 KB
/
player.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 PLAYER_H
#define PLAYER_H
#include <climits>
#include <array>
#include <memory>
#include <functional>
#include <iosfwd>
#include <list>
#include <map>
#include <set>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
#include "calendar.h"
#include "cata_utility.h"
#include "character.h"
#include "damage.h"
#include "game_constants.h"
#include "item.h"
#include "optional.h"
#include "pimpl.h"
#include "player_activity.h"
#include "ret_val.h"
#include "weighted_list.h"
#include "bodypart.h"
#include "color.h"
#include "creature.h"
#include "cursesdef.h"
#include "inventory.h"
#include "item_location.h"
#include "pldata.h"
#include "type_id.h"
#include "magic.h"
#include "monster.h"
#include "craft_command.h"
#include "point.h"
class basecamp;
class effect;
class faction;
class map;
class npc;
struct pathfinding_settings;
class recipe;
struct islot_comestible;
struct itype;
class monster;
static const std::string DEFAULT_HOTKEYS( "1234567890abcdefghijklmnopqrstuvwxyz" );
class recipe_subset;
enum action_id : int;
struct bionic;
class JsonObject;
class JsonIn;
class JsonOut;
struct dealt_projectile_attack;
class dispersion_sources;
using itype_id = std::string;
using faction_id = string_id<faction>;
struct trap;
class profession;
nc_color encumb_color( int level );
enum game_message_type : int;
class ma_technique;
class martialart;
struct item_comp;
struct tool_comp;
class vehicle;
struct w_point;
struct targeting_data;
// This tries to represent both rating and
// player's decision to respect said rating
enum edible_rating {
// Edible or we pretend it is
EDIBLE,
// Not food at all
INEDIBLE,
// Not food because mutated mouth/system
INEDIBLE_MUTATION,
// You can eat it, but it will hurt morale
ALLERGY,
// Smaller allergy penalty
ALLERGY_WEAK,
// Cannibalism (unless psycho/cannibal)
CANNIBALISM,
// Rotten or not rotten enough (for saprophages)
ROTTEN,
// Can provoke vomiting if you already feel nauseous.
NAUSEA,
// We can eat this, but we'll overeat
TOO_FULL,
// Some weird stuff that requires a tool we don't have
NO_TOOL
};
/** @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> {};
enum class rechargeable_cbm {
none = 0,
battery,
reactor,
furnace,
other
};
enum class comfort_level {
uncomfortable = -999,
neutral = 0,
slightly_comfortable = 3,
comfortable = 5,
very_comfortable = 10
};
struct special_attack {
std::string text;
damage_instance damage;
};
class player_morale;
// The maximum level recoil will ever reach.
// This corresponds to the level of accuracy of a "snap" or "hip" shot.
extern const double MAX_RECOIL;
struct stat_mod {
int strength = 0;
int dexterity = 0;
int intelligence = 0;
int perception = 0;
int speed = 0;
};
struct needs_rates {
float thirst;
float hunger;
float fatigue;
float recovery;
float kcal = 0.0f;
};
enum player_movemode : unsigned char {
PMM_WALK = 0,
PMM_RUN = 1,
PMM_CROUCH = 2,
PMM_COUNT
};
static const std::array< std::string, PMM_COUNT > player_movemode_str = { {
"walk",
"run",
"crouch"
}
};
class player : public Character
{
public:
player();
player( const player & ) = delete;
player( player && );
~player() override;
player &operator=( const player & ) = delete;
player &operator=( player && );
/** Calls Character::normalize()
* normalizes HP and body temperature
*/
void normalize() override;
bool is_player() const override {
return true;
}
player *as_player() override {
return this;
}
const player *as_player() const override {
return this;
}
/** Processes human-specific effects of effects before calling Creature::process_effects(). */
void process_effects() override;
/** Handles the still hard-coded effects. */
void hardcoded_effects( effect &it );
/** Returns the modifier value used for vomiting effects. */
double vomit_mod();
bool in_sleep_state() const override {
return Creature::in_sleep_state() || activity.id() == "ACT_TRY_SLEEP";
}
bool is_npc() const override {
return false; // Overloaded for NPCs in npc.h
}
bool can_mount( const monster &critter ) const;
void mount_creature( monster &z );
/** Returns what color the player should be drawn as */
nc_color basic_symbol_color() const override;
/** Returns an enumeration of visible mutations with colors */
std::string visible_mutations( int visibility_cap ) const;
std::vector<std::string> short_description_parts() const;
std::string short_description() const;
int print_info( const catacurses::window &w, int vStart, int vLines, int column ) const override;
// populate variables, inventory items, and misc from json object
virtual void deserialize( JsonIn &jsin ) = 0;
// by default save all contained info
virtual void serialize( JsonOut &jsout ) const = 0;
/** Handles and displays detailed character info for the '@' screen */
void disp_info();
/**Estimate effect duration based on player relevant skill*/
time_duration estimate_effect_dur( const skill_id &relevant_skill, const efftype_id &effect,
const time_duration &error_magnitude,
int threshold, const Creature &target ) const;
/** Resets movement points and applies other non-idempotent changes */
void process_turn() override;
/** Calculates the various speed bonuses we will get from mutations, etc. */
void recalc_speed_bonus();
/** Called after every action, invalidates player caches */
void action_taken();
/** Ticks down morale counters and removes them */
void update_morale();
/** Ensures persistent morale effects are up-to-date */
void apply_persistent_morale();
/** Maintains body temperature */
void update_bodytemp();
/** Define color for displaying the body temperature */
nc_color bodytemp_color( int bp ) const;
/** Returns the player's modified base movement cost */
int run_cost( int base_cost, bool diag = false ) const;
/** Returns the player's speed for swimming across water tiles */
int swim_speed() const;
/** Maintains body wetness and handles the rate at which the player dries */
void update_body_wetness( const w_point &weather );
/** 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 );
/** 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();
/** Set vitamin deficiency/excess disease states dependent upon current vitamin levels */
void update_vitamins( const vitamin_id &vit );
/**
* Handles passive regeneration of pain and maybe hp.
*/
void regen( int rate_multiplier );
// 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();
/** Regenerates stamina */
void update_stamina( int turns );
/** Kills the player if too hungry, stimmed up etc., forces tired player to sleep and prints warnings. */
void check_needs_extremes();
/** Returns if the player has hibernation mutation and is asleep and well fed */
bool is_hibernating() const;
/** Returns true if the player has a conflicting trait to the entered trait
* Uses has_opposite_trait(), has_lower_trait(), and has_higher_trait() to determine conflicts.
*/
bool has_conflicting_trait( const trait_id &flag ) const;
/** Returns true if the player has a trait which cancels the entered trait */
bool has_opposite_trait( const trait_id &flag ) const;
/** Returns true if the player has a trait which upgrades into the entered trait */
bool has_lower_trait( const trait_id &flag ) const;
/** Returns true if the player has a trait which is an upgrade of the entered trait */
bool has_higher_trait( const trait_id &flag ) const;
/** Returns true if the player has a trait that shares a type with the entered trait */
bool has_same_type_trait( const trait_id &flag ) const;
/** Returns true if the player has crossed a mutation threshold
* Player can only cross one mutation threshold.
*/
bool crossed_threshold() const;
/** Returns true if the entered trait may be purified away
* Defaults to true
*/
bool purifiable( const trait_id &flag ) const;
/** Returns a dream's description selected randomly from the player's highest mutation category */
std::string get_category_dream( const std::string &cat, int strength ) const;
/** Returns true if the player is in a climate controlled area or armor */
bool in_climate_control();
/** Handles process of introducing patient into anesthesia during Autodoc operations. Requires anesthetic kits or NOPAIN mutation */
void introduce_into_anesthesia( const time_duration &duration, player &installer,
bool needs_anesthesia );
/** Returns true if the player is wearing an active optical cloak */
bool has_active_optcloak() const;
/** Adds a bionic to my_bionics[] */
void add_bionic( const bionic_id &b );
/** Removes a bionic from my_bionics[] */
void remove_bionic( const bionic_id &b );
/** Calculate skill for (un)installing bionics */
float bionics_adjusted_skill( const skill_id &most_important_skill,
const skill_id &important_skill,
const skill_id &least_important_skill,
int skill_level = -1 );
/** Calculate non adjusted skill for (un)installing bionics */
int bionics_pl_skill( const skill_id &most_important_skill,
const skill_id &important_skill,
const skill_id &least_important_skill,
int skill_level = -1 );
/**Is the installation possible*/
bool can_install_bionics( const itype &type, player &installer, bool autodoc = false,
int skill_level = -1 );
/** Initialize all the values needed to start the operation player_activity */
bool install_bionics( const itype &type, player &installer, bool autodoc = false,
int skill_level = -1 );
/**Success or failure of installation happens here*/
void perform_install( bionic_id bid, bionic_id upbid, int difficulty, int success,
int pl_skill, std::string installer_name,
std::vector<trait_id> trait_to_rem, tripoint patient_pos );
void bionics_install_failure( bionic_id bid, std::string installer, int difficulty, int success,
float adjusted_skill, tripoint patient_pos );
/**Is The uninstallation possible*/
bool can_uninstall_bionic( const bionic_id &b_id, player &installer, bool autodoc = false,
int skill_level = -1 );
/** Initialize all the values needed to start the operation player_activity */
bool uninstall_bionic( const bionic_id &b_id, player &installer, bool autodoc = false,
int skill_level = -1 );
/**Succes or failure of removal happens here*/
void perform_uninstall( bionic_id bid, int difficulty, int success, int power_lvl, int pl_skill );
/**Used by monster to perform surgery*/
bool uninstall_bionic( const bionic &target_cbm, monster &installer, player &patient,
float adjusted_skill, bool autodoc = false );
/**When a player fails the surgery*/
void bionics_uninstall_failure( int difficulty, int success,
float adjusted_skill );
/**When a monster fails the surgery*/
void bionics_uninstall_failure( monster &installer, player &patient, int difficulty, int success,
float adjusted_skill );
/**Has enough anesthetic for surgery*/
bool has_enough_anesth( const itype *cbm, player &patient );
/** Adds the entered amount to the player's bionic power_level */
void charge_power( int amount );
/** Generates and handles the UI for player interaction with installed bionics */
void power_bionics();
void power_mutations();
/** Handles bionic activation effects of the entered bionic, returns if anything activated */
bool activate_bionic( int b, bool eff_only = false );
/** Handles bionic deactivation effects of the entered bionic, returns if anything deactivated */
bool deactivate_bionic( int b, bool eff_only = false );
/**Convert fuel to bionic power*/
bool burn_fuel( int b, bool start = false );
/** Handles bionic effects over time of the entered bionic */
void process_bionic( int b );
/** Randomly removes a bionic from my_bionics[] */
bool remove_random_bionic();
/** Remove all bionics */
void clear_bionics();
/** Returns the size of my_bionics[] */
int num_bionics() const;
/** Returns amount of Storage CBMs in the corpse **/
std::pair<int, int> amount_of_storage_bionics() const;
/** Returns the bionic at a given index in my_bionics[] */
bionic &bionic_at_index( int i );
/** Returns the bionic with the given invlet, or NULL if no bionic has that invlet */
bionic *bionic_by_invlet( int ch );
/** Returns player luminosity based on the brightest active item they are carrying */
float active_light() const;
const tripoint &pos() 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 &omt, int sight_points );
/** 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 has two functioning arms */
bool has_two_arms() const;
/** Calculates melee weapon wear-and-tear through use, returns true if item is destroyed. */
bool handle_melee_wear( item &shield, float wear_multiplier = 1.0f );
/** True if unarmed or wielding a weapon with the UNARMED_WEAPON flag */
bool unarmed_attack() const;
/** Called when a player triggers a trap, returns true if they don't set it off */
bool avoid_trap( const tripoint &pos, const trap &tr ) const override;
/** 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;
// see Creature::sees
bool sees( const tripoint &t, bool is_player = false, int range_mod = 0 ) const override;
// see Creature::sees
bool sees( const Creature &critter ) const override;
/**
* Get all hostile creatures currently visible to this player.
*/
std::vector<Creature *> get_hostile_creatures( int range ) const;
/**
* Returns all creatures that this player can see and that are in the given
* range. This player object itself is never included.
* The player character (g->u) is checked and might be included (if applicable).
* @param range The maximal distance (@ref rl_dist), creatures at this distance or less
* are included.
*/
std::vector<Creature *> get_visible_creatures( int range ) const;
/**
* As above, but includes all creatures the player can detect well enough to target
* with ranged weapons, e.g. with infrared vision.
*/
std::vector<Creature *> get_targetable_creatures( int range ) const;
/**
* Check whether the this player can see the other creature with infrared. This implies
* this player can see infrared and the target is visible with infrared (is warm).
* And of course a line of sight exists.
*/
bool sees_with_infrared( const Creature &critter ) const;
Attitude attitude_to( const Creature &other ) const override;
void pause(); // '.' command; pauses & reduces recoil
void set_movement_mode( player_movemode mode );
bool movement_mode_is( player_movemode mode ) const;
void cycle_move_mode(); // Cycles to the next move mode.
void reset_move_mode(); // Resets to walking.
void toggle_run_mode(); // Toggles running on/off.
void toggle_crouch_mode(); // Toggles crouching on/off.
// martialarts.cpp
/** Fires all non-triggered martial arts events */
void ma_static_effects();
/** Fires all move-triggered martial arts events */
void ma_onmove_effects();
/** Fires all pause-triggered martial arts events */
void ma_onpause_effects();
/** Fires all hit-triggered martial arts events */
void ma_onhit_effects();
/** Fires all attack-triggered martial arts events */
void ma_onattack_effects();
/** Fires all dodge-triggered martial arts events */
void ma_ondodge_effects();
/** Fires all block-triggered martial arts events */
void ma_onblock_effects();
/** Fires all get hit-triggered martial arts events */
void ma_ongethit_effects();
/** Fires all miss-triggered martial arts events */
void ma_onmiss_effects();
/** Fires all crit-triggered martial arts events */
void ma_oncrit_effects();
/** Fires all kill-triggered martial arts events */
void ma_onkill_effects();
/** Returns true if the player has any martial arts buffs attached */
bool has_mabuff( const mabuff_id &buff_id ) const;
/** Returns true if the player has access to the entered martial art */
bool has_martialart( const matype_id &ma_id ) const;
/** Adds the entered martial art to the player's list */
void add_martialart( const matype_id &ma_id );
/** Returns true if the player can learn the entered martial art */
bool can_autolearn( const matype_id &ma_id ) const;
/** Displays a message if the player can or cannot use the martial art */
void martialart_use_message() const;
/** Returns the to hit bonus from martial arts buffs */
float mabuff_tohit_bonus() const;
/** Returns the dodge bonus from martial arts buffs */
float mabuff_dodge_bonus() const;
/** Returns the block bonus from martial arts buffs */
int mabuff_block_bonus() const;
/** Returns the speed bonus from martial arts buffs */
int mabuff_speed_bonus() const;
/** Returns the armor bonus against given type from martial arts buffs */
int mabuff_armor_bonus( damage_type type ) const;
/** Returns the damage multiplier to given type from martial arts buffs */
float mabuff_damage_mult( damage_type type ) const;
/** Returns the flat damage bonus to given type from martial arts buffs, applied after the multiplier */
int mabuff_damage_bonus( damage_type type ) const;
/** Returns the flat penalty to move cost of attacks. If negative, that's a bonus. Applied after multiplier. */
int mabuff_attack_cost_penalty() const;
/** Returns the multiplier on move cost of attacks. */
float mabuff_attack_cost_mult() const;
/** Returns true if the player is immune to throws */
bool is_throw_immune() const;
/** Returns value of player's stable footing */
float stability_roll() const override;
/** Returns true if the player has quiet melee attacks */
bool is_quiet() const;
/** Returns true if the player has stealthy movement */
bool is_stealthy() const;
/** Returns true if the current martial art works with the player's current weapon */
bool can_melee() const;
/** Always returns false, since players can't dig currently */
bool digging() const override;
/** Returns true if the player is knocked over or has broken legs */
bool is_on_ground() const override;
/** Returns true if the player should be dead */
bool is_dead_state() const override;
/** Returns true is the player is protected from electric shocks */
bool is_elec_immune() const override;
/** Returns true if the player is immune to this kind of effect */
bool is_immune_effect( const efftype_id & ) const override;
/** Returns true if the player is immune to this kind of damage */
bool is_immune_damage( damage_type ) const override;
/** Returns true if the player is protected from radiation */
bool is_rad_immune() const;
/** Returns true if the player has technique-based miss recovery */
bool has_miss_recovery_tec( const item &weap ) const;
/** Returns the technique used for miss recovery */
ma_technique get_miss_recovery_tec( const item &weap ) const;
/** Returns true if the player has a grab breaking technique available */
bool has_grab_break_tec() const override;
/** Returns the grab breaking technique if available */
ma_technique get_grab_break_tec() const;
/** Returns true if the player is able to use a grab breaking technique */
bool can_grab_break() const;
/** Returns true if the player is able to use a miss recovery technique */
bool can_miss_recovery( const item &weap ) const;
/** Returns true if the player has the leg block technique available */
bool can_leg_block() const;
/** Returns true if the player has the arm block technique available */
bool can_arm_block() const;
/** Returns true if either can_leg_block() or can_arm_block() returns true */
bool can_limb_block() const;
/** Returns true if the current style forces unarmed attack techniques */
bool is_force_unarmed() const;
// melee.cpp
/** Returns the best item for blocking with */
item &best_shield();
/**
* 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
*/
void melee_attack( Creature &t, bool allow_special, const matec_id &force_technique,
bool allow_unarmed = true );
/**
* Calls the to other melee_attack function with an empty technique id (meaning no specific
* technique should be used).
*/
void melee_attack( Creature &t, bool allow_special );
/**
* Returns a weapon's modified dispersion value.
* @param obj Weapon to check dispersion on
*/
dispersion_sources get_weapon_dispersion( const item &obj ) const;
/** Returns true if a gun misfires, jams, or has other problems, else returns false */
bool handle_gun_damage( item &it );
/** Get maximum recoil penalty due to vehicle motion */
double recoil_vehicle() const;
/** Current total maximum recoil penalty from all sources */
double recoil_total() const;
/** How many moves does it take to aim gun to the target accuracy. */
int gun_engagement_moves( const item &gun, int target = 0, int start = MAX_RECOIL ) const;
/**
* Fires a gun or auxiliary gunmod (ignoring any current mode)
* @param target where the first shot is aimed at (may vary for later shots)
* @param shots maximum number of shots to fire (less may be fired in some circumstances)
* @return number of shots actually fired
*/
int fire_gun( const tripoint &target, int shots = 1 );
/**
* Fires a gun or auxiliary gunmod (ignoring any current mode)
* @param target where the first shot is aimed at (may vary for later shots)
* @param shots maximum number of shots to fire (less may be fired in some circumstances)
* @param gun item to fire (which does not necessary have to be in the players possession)
* @return number of shots actually fired
*/
int fire_gun( const tripoint &target, int shots, item &gun );
/** Handles reach melee attacks */
void reach_attack( const tripoint &p );
/** Checks for valid block abilities and reduces damage accordingly. Returns true if the player blocks */
bool block_hit( Creature *source, body_part &bp_hit, damage_instance &dam ) override;
/**
* Reduces and mutates du, prints messages about armor taking damage.
* @return true if the armor was completely destroyed (and the item must be deleted).
*/
bool armor_absorb( damage_unit &du, item &armor );
/**
* Check for passive bionics that provide armor, and returns the armor bonus
* This is called from player::passive_absorb_hit
*/
float bionic_armor_bonus( body_part bp, damage_type dt ) const;
/**
* Check for relevant passive, non-clothing that can absorb damage, and reduce by specified
* damage unit. Only flat bonuses are checked here. Multiplicative ones are checked in
* @ref player::absorb_hit. The damage amount will never be reduced to less than 0.
* This is called from @ref player::absorb_hit
*/
void passive_absorb_hit( body_part bp, damage_unit &du ) const;
/** Runs through all bionics and armor on a part and reduces damage through their armor_absorb */
void absorb_hit( body_part bp, damage_instance &dam ) override;
/** Called after the player has successfully dodged an attack */
void on_dodge( Creature *source, float difficulty ) override;
/** Handles special defenses from an attack that hit us (source can be null) */
void on_hit( Creature *source, body_part bp_hit = num_bp,
float difficulty = INT_MIN, dealt_projectile_attack const *proj = nullptr ) override;
/** Handles effects that happen when the player is damaged and aware of the fact. */
void on_hurt( Creature *source, bool disturb = true );
/** Returns the bonus bashing damage the player deals based on their stats */
float bonus_damage( bool random ) const;
/** Returns weapon skill */
float get_hit_base() const override;
/** 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;
/** Gets melee accuracy component from weapon+skills */
float get_hit_weapon( const item &weap ) const;
/** 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!
// 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 ) 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 ) 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 ) 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 ) const;
std::vector<matec_id> get_all_techniques( const item &weap ) const;
/** Returns true if the player has a weapon or martial arts skill available with the entered technique */
bool has_technique( const matec_id &id, const item &weap ) const;
/** Returns a random valid technique */
matec_id pick_technique( Creature &t, const item &weap,
bool crit, bool dodge_counter, bool block_counter );
void perform_technique( const ma_technique &technique, Creature &t, damage_instance &di,
int &move_cost );
/** Performs special attacks and their effects (poisonous, stinger, etc.) */
void perform_special_attacks( Creature &t );
/** Returns a vector of valid mutation attacks */
std::vector<special_attack> mutation_attacks( Creature &t ) const;
/** Handles combat effects, returns a string of any valid combat effect messages */
std::string melee_special_effects( Creature &t, damage_instance &d, item &weap );
/** Returns Creature::get_dodge_base modified by the player's skill level */
float get_dodge_base() const override; // Returns the players's dodge, modded by clothing etc
/** Returns Creature::get_dodge() modified by any player effects */
float get_dodge() const override;
/** Returns the player's dodge_roll to be compared against an aggressor's hit_roll() */
float dodge_roll() override;
/** Returns melee skill level, to be used to throttle dodge practice. **/
float get_melee() const override;
/**
* Adds a reason for why the player would miss a melee attack.
*
* 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 the uncanny dodge bionic and effects, returns true if the player successfully dodges */
bool uncanny_dodge() override;
/**
* Checks both the neighborhoods of from and to for climbable surfaces,
* returns move cost of climbing from `from` to `to`.
* 0 means climbing is not possible.
* Return value can depend on the orientation of the terrain.
*/
int climbing_cost( const tripoint &from, const tripoint &to ) const;
// ranged.cpp
/** Execute a throw */
dealt_projectile_attack throw_item( const tripoint &target, const item &to_throw,
const cata::optional<tripoint> &blind_throw_from_pos = cata::nullopt );
// Mental skills and stats
/** Returns the player's reading speed */
int read_speed( bool return_stat_effect = true ) const;
/** Returns the player's skill rust rate */
int rust_rate( bool return_stat_effect = true ) const;
/** Returns a value used when attempting to convince NPC's of something */
int talk_skill() const;
/** Returns a value used when attempting to intimidate NPC's */
int intimidation() const;
/**
* Check if a given body part is immune to a given damage type
*
* This function checks whether a given body part cannot be damaged by a given
* damage_unit. Note that this refers only to reduction of hp on that part. It
* does not account for clothing damage, pain, status effects, etc.
*
* @param bp: Body part to perform the check on
* @param dam: Type of damage to check for
* @returns true if given damage can not reduce hp of given body part
*/
bool immune_to( body_part bp, damage_unit dam ) const;
/** Calls Creature::deal_damage and handles damaged effects (waking up, etc.) */
dealt_damage_instance deal_damage( Creature *source, body_part bp,
const damage_instance &d ) override;
/** Reduce healing effect intensity, return initial intensity of the effect */
int reduce_healing_effect( const efftype_id &eff_id, int remove_med, body_part hurt );
/** Actually hurt the player, hurts a body_part directly, no armor reduction */
void apply_damage( Creature *source, body_part hurt, int dam,
bool bypass_med = false ) override;
/** Modifies a pain value by player traits before passing it to Creature::mod_pain() */
void mod_pain( int npain ) override;
/** Sets new intensity of pain an reacts to it */
void set_pain( int npain ) override;
/** Returns perceived pain (reduced with painkillers)*/
int get_perceived_pain() const override;
void cough( bool harmful = false, int loudness = 4 );
void add_pain_msg( int val, body_part bp ) const;
/** Modifies intensity of painkillers */
void mod_painkiller( int npkill );
/** Sets intensity of painkillers */
void set_painkiller( int npkill );
/** Returns intensity of painkillers */
int get_painkiller() const;
/** Heals a body_part for dam */
void heal( body_part healed, int dam );
/** Heals an hp_part for dam */
void heal( hp_part healed, int dam );
/** Heals all body parts for dam */
void healall( int dam );
/** Hurts all body parts for dam, no armor reduction */
void hurtall( int dam, Creature *source, bool disturb = true );
/** Harms all body parts for dam, with armor reduction. If vary > 0 damage to parts are random within vary % (1-100) */
int hitall( int dam, int vary, Creature *source );
/** Knocks the player to a specified tile */
void knock_back_to( const tripoint &to ) override;
/** Returns multiplier on fall damage at low velocity (knockback/pit/1 z-level, not 5 z-levels) */
float fall_damage_mod() const override;
/** Deals falling/collision damage with terrain/creature at pos */
int impact( int force, const tripoint &pos ) override;
/** Returns overall % of HP remaining */
int hp_percentage() const override;
/** Handles the chance to be infected by random diseases */
void get_sick();
/** Returns list of rc items in player inventory. **/
std::list<item *> get_radio_items();
/** Returns list of artifacts in player inventory. **/
std::list<item *> get_artifact_items();
/** Adds an addiction to the player */
void add_addiction( add_type type, int strength );
/** Removes an addition from the player */
void rem_addiction( add_type type );
/** Returns true if the player has an addiction of the specified type */
bool has_addiction( add_type type ) const;
/** Returns the intensity of the specified addiction */
int addiction_level( add_type type ) const;
/** Siphons fuel (if available) from the specified vehicle into container or
* similar via @ref game::handle_liquid. May start a player activity.
*/
void siphon( vehicle &veh, const itype_id &desired_liquid );
/** Handles a large number of timers decrementing and other randomized effects */
void suffer();
/** Handles mitigation and application of radiation */
bool irradiate( float rads, bool bypass = false );
/** Handles the chance for broken limbs to spontaneously heal to 1 HP */
void mend( int rate_multiplier );
/** Creates an auditory hallucination */
void sound_hallu();
/** Drenches the player with water, saturation is the percent gotten wet */
void drench( int saturation, const body_part_set &flags, bool ignore_waterproof );
/** Recalculates morale penalty/bonus from wetness based on mutations, equipment and temperature */
void apply_wetness_morale( int temperature );
/** used for drinking from hands, returns how many charges were consumed */
int drink_from_hands( item &water );
/** Used for eating object at pos, returns true if object is removed from inventory (last charge was consumed) */
bool consume( int target_position );
/** Used for eating a particular item that doesn't need to be in inventory.
* Returns true if the item is to be removed (doesn't remove). */
bool consume_item( item &target );
/** Returns allergy type or MORALE_NULL if not allergic for this player */
morale_type allergy_type( const item &food ) const;
/** Used for eating entered comestible, returns true if comestible is successfully eaten */
bool eat( item &food, bool force = false );
/** Used to apply health modifications from food and medication **/
void modify_health( const islot_comestible &comest );
/** Used to apply stimulation modifications from food and medication **/
void modify_stimulation( const islot_comestible &comest );
/** Used to apply addiction modifications from food and medication **/
void modify_addiction( const islot_comestible &comest );
/** Used to apply morale modifications from food and medication **/
void modify_morale( item &food, int nutr = 0 );
/** Can the food be [theoretically] eaten no matter the consequences? */
ret_val<edible_rating> can_eat( const item &food ) const;
/**
* Same as @ref can_eat, but takes consequences into account.
* Asks about them if @param interactive is true, refuses otherwise.
*/
ret_val<edible_rating> will_eat( const item &food, bool interactive = false ) const;
// TODO: Move these methods out of the class.
rechargeable_cbm get_cbm_rechargeable_with( const item &it ) const;
int get_acquirable_energy( const item &it, rechargeable_cbm cbm ) const;
int get_acquirable_energy( const item &it ) const;
/** Gets player's minimum hunger and thirst */
int stomach_capacity() const;
/** Handles the kcal value for a comestible **/
int kcal_for( const item &comest ) const;
/** Handles the nutrition value for a comestible **/
int nutrition_for( const item &comest ) const;
/** Handles the enjoyability value for a comestible. First value is enjoyability, second is cap. **/
std::pair<int, int> fun_for( const item &comest ) const;
/** Handles the enjoyability value for a book. **/
int book_fun_for( const item &book, const player &p ) const;
/**
* Returns a reference to the item itself (if it's consumable),
* the first of its contents (if it's consumable) or null item otherwise.
* WARNING: consumable does not necessarily guarantee the comestible type.
*/
item &get_consumable_from( item &it ) const;
std::pair<std::string, nc_color> get_hunger_description() const override;
std::pair<std::string, nc_color> get_pain_description() const override;
/** Get vitamin contents for a comestible */
std::map<vitamin_id, int> vitamins_from( const item &it ) const;
std::map<vitamin_id, int> vitamins_from( const itype_id &id ) const;
/** Get vitamin usage rate (minutes per unit) accounting for bionics, mutations and effects */
time_duration vitamin_rate( const vitamin_id &vit ) const;
/**
* Add or subtract vitamins from player storage pools
* @param vit ID of vitamin to modify
* @param qty amount by which to adjust vitamin (negative values are permitted)
* @param capped if true prevent vitamins which can accumulate in excess from doing so
* @return adjusted level for the vitamin or zero if vitamin does not exist
*/
int vitamin_mod( const vitamin_id &vit, int qty, bool capped = true );
void vitamins_mod( const std::map<vitamin_id, int> &, bool capped = true );
/**
* Check current level of a vitamin
*
* Accesses level of a given vitamin. If the vitamin_id specified does not
* exist then this function simply returns 0.
*
* @param vit ID of vitamin to check level for.
* @returns current level for specified vitamin
*/
int vitamin_get( const vitamin_id &vit ) const;
/**
* Sets level of a vitamin or returns false if id given in vit does not exist
*
* @note status effects are still set for deficiency/excess
*
* @param[in] vit ID of vitamin to adjust quantity for
* @param[in] qty Quantity to set level to
* @returns false if given vitamin_id does not exist, otherwise true
*/
bool vitamin_set( const vitamin_id &vit, int qty );
/** Current metabolic rate due to traits, hunger, speed, etc. */
float metabolic_rate() const;
/** Handles the effects of consuming an item */
bool consume_effects( item &food );
/** Handles rooting effects */
void rooted_message() const;
void rooted();
int get_lift_assist() const;
bool list_ammo( const item &base, std::vector<item::reload_option> &ammo_list,
bool empty = true ) const;
/**
* Select suitable ammo with which to reload the item
* @param base Item to select ammo for
* @param prompt force display of the menu even if only one choice
* @param empty allow selection of empty magazines
*/
item::reload_option select_ammo( const item &base, bool prompt = false,
bool empty = true ) const;
/** Select ammo from the provided options */
item::reload_option select_ammo( const item &base, std::vector<item::reload_option> opts ) const;
/** Check player strong enough to lift an object unaided by equipment (jacks, levers etc) */
template <typename T>
bool can_lift( const T &obj ) const {
// avoid comparing by weight as different objects use differing scales (grams vs kilograms etc)
int str = get_str();
if( mounted_creature ) {
auto mons = mounted_creature.get();
str = mons->mech_str_addition() == 0 ? str : mons->mech_str_addition();
}
const int npc_str = get_lift_assist();
if( has_trait( trait_id( "STRONGBACK" ) ) ) {
str *= 1.35;
} else if( has_trait( trait_id( "BADBACK" ) ) ) {
str /= 1.35;
}
return str + npc_str >= obj.lift_strength();
}
/**
* Check player capable of wearing an item.
* @param it Thing to be worn
*/
ret_val<bool> can_wear( const item &it ) const;
/**
* 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 ) const;
/**
* Check player capable of wielding an item.
* @param it Thing to be wielded
*/
ret_val<bool> can_wield( const item &it ) const;
/**
* Check player capable of unwielding an item.
* @param it Thing to be unwielded
*/
ret_val<bool> can_unwield( const item &it ) const;
/** Check player's capability of consumption overall */
bool can_consume( const item &it ) const;
/** True if the player has enough skill (in cooking or survival) to estimate time to rot */
bool can_estimate_rot() const;
bool is_wielding( const item &target ) const;
/**
* Removes currently wielded item (if any) and replaces it with the target item.