-
Notifications
You must be signed in to change notification settings - Fork 277
/
character.cpp
10130 lines (9010 loc) · 354 KB
/
character.cpp
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
#include "character.h"
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iterator>
#include <memory>
#include <numeric>
#include <ostream>
#include <type_traits>
#include "action.h"
#include "activity_handlers.h"
#include "anatomy.h"
#include "avatar.h"
#include "bionics.h"
#include "cata_utility.h"
#include "catacharset.h"
#include "character_martial_arts.h"
#include "clzones.h"
#include "colony.h"
#include "construction.h"
#include "coordinate_conversions.h"
#include "debug.h"
#include "disease.h"
#include "effect.h"
#include "event.h"
#include "event_bus.h"
#include "field.h"
#include "field_type.h"
#include "fire.h"
#include "fungal_effects.h"
#include "game.h"
#include "game_constants.h"
#include "int_id.h"
#include "item_contents.h"
#include "item_location.h"
#include "itype.h"
#include "iuse.h"
#include "iuse_actor.h"
#include "lightmap.h"
#include "line.h"
#include "magic_enchantment.h"
#include "map.h"
#include "map_iterator.h"
#include "map_selector.h"
#include "mapdata.h"
#include "material.h"
#include "math_defines.h"
#include "memorial_logger.h"
#include "messages.h"
#include "mission.h"
#include "monster.h"
#include "morale.h"
#include "morale_types.h"
#include "mtype.h"
#include "mutation.h"
#include "npc.h"
#include "omdata.h"
#include "options.h"
#include "output.h"
#include "overlay_ordering.h"
#include "overmapbuffer.h"
#include "pathfinding.h"
#include "player.h"
#include "ret_val.h"
#include "rng.h"
#include "scent_map.h"
#include "skill.h"
#include "skill_boost.h"
#include "sounds.h"
#include "stomach.h"
#include "string_formatter.h"
#include "string_id.h"
#include "string_utils.h"
#include "submap.h"
#include "text_snippets.h"
#include "translations.h"
#include "trap.h"
#include "ui.h"
#include "units_utility.h"
#include "value_ptr.h"
#include "veh_interact.h"
#include "veh_type.h"
#include "vehicle.h"
#include "vehicle_selector.h"
#include "vitamin.h"
#include "vpart_position.h"
#include "vpart_range.h"
#include "weather.h"
#include "weather_gen.h"
struct dealt_projectile_attack;
static const activity_id ACT_DROP( "ACT_DROP" );
static const activity_id ACT_MOVE_ITEMS( "ACT_MOVE_ITEMS" );
static const activity_id ACT_STASH( "ACT_STASH" );
static const activity_id ACT_TRAVELLING( "ACT_TRAVELLING" );
static const activity_id ACT_TREE_COMMUNION( "ACT_TREE_COMMUNION" );
static const activity_id ACT_TRY_SLEEP( "ACT_TRY_SLEEP" );
static const activity_id ACT_WAIT_STAMINA( "ACT_WAIT_STAMINA" );
static const bionic_id bio_eye_optic( "bio_eye_optic" );
static const bionic_id bio_watch( "bio_watch" );
static const efftype_id effect_adrenaline( "adrenaline" );
static const efftype_id effect_ai_waiting( "ai_waiting" );
static const efftype_id effect_alarm_clock( "alarm_clock" );
static const efftype_id effect_bandaged( "bandaged" );
static const efftype_id effect_beartrap( "beartrap" );
static const efftype_id effect_bite( "bite" );
static const efftype_id effect_bleed( "bleed" );
static const efftype_id effect_blind( "blind" );
static const efftype_id effect_blisters( "blisters" );
static const efftype_id effect_bloated( "bloated" );
static const efftype_id effect_boomered( "boomered" );
static const efftype_id effect_cold( "cold" );
static const efftype_id effect_contacts( "contacts" );
static const efftype_id effect_corroding( "corroding" );
static const efftype_id effect_cough_suppress( "cough_suppress" );
static const efftype_id effect_crushed( "crushed" );
static const efftype_id effect_darkness( "darkness" );
static const efftype_id effect_deaf( "deaf" );
static const efftype_id effect_disinfected( "disinfected" );
static const efftype_id effect_downed( "downed" );
static const efftype_id effect_drunk( "drunk" );
static const efftype_id effect_earphones( "earphones" );
static const efftype_id effect_foodpoison( "foodpoison" );
static const efftype_id effect_frostbite( "frostbite" );
static const efftype_id effect_frostbite_recovery( "frostbite_recovery" );
static const efftype_id effect_fungus( "fungus" );
static const efftype_id effect_glowing( "glowing" );
static const efftype_id effect_glowy_led( "glowy_led" );
static const efftype_id effect_got_checked( "got_checked" );
static const efftype_id effect_grabbed( "grabbed" );
static const efftype_id effect_grabbing( "grabbing" );
static const efftype_id effect_harnessed( "harnessed" );
static const efftype_id effect_heating_bionic( "heating_bionic" );
static const efftype_id effect_heavysnare( "heavysnare" );
static const efftype_id effect_hot( "hot" );
static const efftype_id effect_hot_speed( "hot_speed" );
static const efftype_id effect_in_pit( "in_pit" );
static const efftype_id effect_infected( "infected" );
static const efftype_id effect_jetinjector( "jetinjector" );
static const efftype_id effect_lack_sleep( "lack_sleep" );
static const efftype_id effect_lightsnare( "lightsnare" );
static const efftype_id effect_lying_down( "lying_down" );
static const efftype_id effect_melatonin_supplements( "melatonin" );
static const efftype_id effect_meth( "meth" );
static const efftype_id effect_masked_scent( "masked_scent" );
static const efftype_id effect_mending( "mending" );
static const efftype_id effect_narcosis( "narcosis" );
static const efftype_id effect_nausea( "nausea" );
static const efftype_id effect_no_sight( "no_sight" );
static const efftype_id effect_onfire( "onfire" );
static const efftype_id effect_pkill1( "pkill1" );
static const efftype_id effect_pkill2( "pkill2" );
static const efftype_id effect_pkill3( "pkill3" );
static const efftype_id effect_recently_coughed( "recently_coughed" );
static const efftype_id effect_ridden( "ridden" );
static const efftype_id effect_riding( "riding" );
static const efftype_id effect_saddled( "monster_saddled" );
static const efftype_id effect_sleep( "sleep" );
static const efftype_id effect_slept_through_alarm( "slept_through_alarm" );
static const efftype_id effect_tied( "tied" );
static const efftype_id effect_took_prozac( "took_prozac" );
static const efftype_id effect_took_xanax( "took_xanax" );
static const efftype_id effect_webbed( "webbed" );
static const skill_id skill_archery( "archery" );
static const skill_id skill_dodge( "dodge" );
static const skill_id skill_pistol( "pistol" );
static const skill_id skill_rifle( "rifle" );
static const skill_id skill_shotgun( "shotgun" );
static const skill_id skill_smg( "smg" );
static const skill_id skill_swimming( "swimming" );
static const skill_id skill_throw( "throw" );
static const species_id HUMAN( "HUMAN" );
static const species_id ROBOT( "ROBOT" );
static const trait_id trait_ACIDBLOOD( "ACIDBLOOD" );
static const trait_id trait_ACIDPROOF( "ACIDPROOF" );
static const trait_id trait_ADRENALINE( "ADRENALINE" );
static const trait_id trait_ANTENNAE( "ANTENNAE" );
static const trait_id trait_ANTLERS( "ANTLERS" );
static const trait_id trait_BADBACK( "BADBACK" );
static const trait_id trait_DEBUG_NODMG( "DEBUG_NODMG" );
static const trait_id trait_EATHEALTH( "EATHEALTH" );
static const trait_id trait_SQUEAMISH( "SQUEAMISH" );
static const trait_id trait_WOOLALLERGY( "WOOLALLERGY" );
static const bionic_id bio_ads( "bio_ads" );
static const bionic_id bio_blaster( "bio_blaster" );
static const bionic_id bio_blindfold( "bio_blindfold" );
static const bionic_id bio_climate( "bio_climate" );
static const bionic_id bio_earplugs( "bio_earplugs" );
static const bionic_id bio_ears( "bio_ears" );
static const bionic_id bio_faraday( "bio_faraday" );
static const bionic_id bio_flashlight( "bio_flashlight" );
static const bionic_id bio_gills( "bio_gills" );
static const bionic_id bio_ground_sonar( "bio_ground_sonar" );
static const bionic_id bio_heatsink( "bio_heatsink" );
static const bionic_id bio_hydraulics( "bio_hydraulics" );
static const bionic_id bio_infrared( "bio_infrared" );
static const bionic_id bio_jointservo( "bio_jointservo" );
static const bionic_id bio_laser( "bio_laser" );
static const bionic_id bio_leukocyte( "bio_leukocyte" );
static const bionic_id bio_lighter( "bio_lighter" );
static const bionic_id bio_membrane( "bio_membrane" );
static const bionic_id bio_memory( "bio_memory" );
static const bionic_id bio_night_vision( "bio_night_vision" );
static const bionic_id bio_railgun( "bio_railgun" );
static const bionic_id bio_recycler( "bio_recycler" );
static const bionic_id bio_shock_absorber( "bio_shock_absorber" );
static const bionic_id bio_storage( "bio_storage" );
static const bionic_id bio_synaptic_regen( "bio_synaptic_regen" );
static const bionic_id bio_tattoo_led( "bio_tattoo_led" );
static const bionic_id bio_tools( "bio_tools" );
static const bionic_id bio_ups( "bio_ups" );
static const bionic_id str_bio_night( "bio_night" );
// Aftershock stuff!
static const bionic_id afs_bio_linguistic_coprocessor( "afs_bio_linguistic_coprocessor" );
static const trait_id trait_BARK( "BARK" );
static const trait_id trait_BIRD_EYE( "BIRD_EYE" );
static const trait_id trait_CEPH_EYES( "CEPH_EYES" );
static const trait_id trait_CHLOROMORPH( "CHLOROMORPH" );
static const trait_id trait_DEAF( "DEAF" );
static const trait_id trait_DEBUG_CLOAK( "DEBUG_CLOAK" );
static const trait_id trait_DEBUG_LS( "DEBUG_LS" );
static const trait_id trait_DEBUG_NIGHTVISION( "DEBUG_NIGHTVISION" );
static const trait_id trait_DEBUG_NOTEMP( "DEBUG_NOTEMP" );
static const trait_id trait_DEBUG_STORAGE( "DEBUG_STORAGE" );
static const trait_id trait_DISORGANIZED( "DISORGANIZED" );
static const trait_id trait_DOWN( "DOWN" );
static const trait_id trait_ELECTRORECEPTORS( "ELECTRORECEPTORS" );
static const trait_id trait_FASTLEARNER( "FASTLEARNER" );
static const trait_id trait_GILLS( "GILLS" );
static const trait_id trait_GILLS_CEPH( "GILLS_CEPH" );
static const trait_id trait_HEAVYSLEEPER( "HEAVYSLEEPER" );
static const trait_id trait_HEAVYSLEEPER2( "HEAVYSLEEPER2" );
static const trait_id trait_HIBERNATE( "HIBERNATE" );
static const trait_id trait_HOARDER( "HOARDER" );
static const trait_id trait_HOLLOW_BONES( "HOLLOW_BONES" );
static const trait_id trait_HOOVES( "HOOVES" );
static const trait_id trait_HORNS_POINTED( "HORNS_POINTED" );
static const trait_id trait_INFRARED( "INFRARED" );
static const trait_id trait_LEG_TENT_BRACE( "LEG_TENT_BRACE" );
static const trait_id trait_LEG_TENTACLES( "LEG_TENTACLES" );
static const trait_id trait_LIGHT_BONES( "LIGHT_BONES" );
static const trait_id trait_LIZ_IR( "LIZ_IR" );
static const trait_id trait_M_DEPENDENT( "M_DEPENDENT" );
static const trait_id trait_M_IMMUNE( "M_IMMUNE" );
static const trait_id trait_M_SKIN2( "M_SKIN2" );
static const trait_id trait_M_SKIN3( "M_SKIN3" );
static const trait_id trait_MEMBRANE( "MEMBRANE" );
static const trait_id trait_MYOPIC( "MYOPIC" );
static const trait_id trait_NO_THIRST( "NO_THIRST" );
static const trait_id trait_NOMAD( "NOMAD" );
static const trait_id trait_NOMAD2( "NOMAD2" );
static const trait_id trait_NOMAD3( "NOMAD3" );
static const trait_id trait_NOPAIN( "NOPAIN" );
static const trait_id trait_PACKMULE( "PACKMULE" );
static const trait_id trait_PADDED_FEET( "PADDED_FEET" );
static const trait_id trait_PAWS( "PAWS" );
static const trait_id trait_PAWS_LARGE( "PAWS_LARGE" );
static const trait_id trait_PER_SLIME( "PER_SLIME" );
static const trait_id trait_PER_SLIME_OK( "PER_SLIME_OK" );
static const trait_id trait_PROF_FOODP( "PROF_FOODP" );
static const trait_id trait_PYROMANIA( "PYROMANIA" );
static const trait_id trait_RADIOGENIC( "RADIOGENIC" );
static const trait_id trait_ROOTS2( "ROOTS2" );
static const trait_id trait_ROOTS3( "ROOTS3" );
static const trait_id trait_SEESLEEP( "SEESLEEP" );
static const trait_id trait_SELFAWARE( "SELFAWARE" );
static const trait_id trait_SHELL( "SHELL" );
static const trait_id trait_SHELL2( "SHELL2" );
static const trait_id trait_SHOUT2( "SHOUT2" );
static const trait_id trait_SHOUT3( "SHOUT3" );
static const trait_id trait_SLIMESPAWNER( "SLIMESPAWNER" );
static const trait_id trait_SLIMY( "SLIMY" );
static const trait_id trait_SLOWLEARNER( "SLOWLEARNER" );
static const trait_id trait_STRONGSTOMACH( "STRONGSTOMACH" );
static const trait_id trait_THRESH_CEPHALOPOD( "THRESH_CEPHALOPOD" );
static const trait_id trait_THRESH_INSECT( "THRESH_INSECT" );
static const trait_id trait_THRESH_PLANT( "THRESH_PLANT" );
static const trait_id trait_THRESH_SPIDER( "THRESH_SPIDER" );
static const trait_id trait_TOUGH_FEET( "TOUGH_FEET" );
static const trait_id trait_TRANSPIRATION( "TRANSPIRATION" );
static const trait_id trait_URSINE_EYE( "URSINE_EYE" );
static const trait_id trait_VISCOUS( "VISCOUS" );
static const trait_id trait_WATERSLEEP( "WATERSLEEP" );
static const trait_id trait_WEBBED( "WEBBED" );
static const trait_id trait_WEB_SPINNER( "WEB_SPINNER" );
static const trait_id trait_WEB_WALKER( "WEB_WALKER" );
static const trait_id trait_WEB_WEAVER( "WEB_WEAVER" );
static const std::string flag_ACTIVE_CLOAKING( "ACTIVE_CLOAKING" );
static const std::string flag_ALLOWS_NATURAL_ATTACKS( "ALLOWS_NATURAL_ATTACKS" );
static const std::string flag_AURA( "AURA" );
static const std::string flag_BELTED( "BELTED" );
static const std::string flag_BLIND( "BLIND" );
static const std::string flag_DEAF( "DEAF" );
static const std::string flag_DISABLE_SIGHTS( "DISABLE_SIGHTS" );
static const std::string flag_EFFECT_INVISIBLE( "EFFECT_INVISIBLE" );
static const std::string flag_EFFECT_NIGHT_VISION( "EFFECT_NIGHT_VISION" );
static const std::string flag_FIX_NEARSIGHT( "FIX_NEARSIGHT" );
static const std::string flag_FUNGUS( "FUNGUS" );
static const std::string flag_GNV_EFFECT( "GNV_EFFECT" );
static const std::string flag_HELMET_COMPAT( "HELMET_COMPAT" );
static const std::string flag_IR_EFFECT( "IR_EFFECT" );
static const std::string flag_ONLY_ONE( "ONLY_ONE" );
static const std::string flag_OUTER( "OUTER" );
static const std::string flag_OVERSIZE( "OVERSIZE" );
static const std::string flag_PARTIAL_DEAF( "PARTIAL_DEAF" );
static const std::string flag_PERPETUAL( "PERPETUAL" );
static const std::string flag_PERSONAL( "PERSONAL" );
static const std::string flag_PLOWABLE( "PLOWABLE" );
static const std::string flag_POWERARMOR_COMPATIBLE( "POWERARMOR_COMPATIBLE" );
static const std::string flag_RESTRICT_HANDS( "RESTRICT_HANDS" );
static const std::string flag_SEMITANGIBLE( "SEMITANGIBLE" );
static const std::string flag_SKINTIGHT( "SKINTIGHT" );
static const std::string flag_SPEEDLOADER( "SPEEDLOADER" );
static const std::string flag_SPLINT( "SPLINT" );
static const std::string flag_STURDY( "STURDY" );
static const std::string flag_SWIMMABLE( "SWIMMABLE" );
static const std::string flag_SWIM_GOGGLES( "SWIM_GOGGLES" );
static const std::string flag_UNDERSIZE( "UNDERSIZE" );
static const std::string flag_USE_UPS( "USE_UPS" );
static const mtype_id mon_player_blob( "mon_player_blob" );
static const mtype_id mon_shadow_snake( "mon_shadow_snake" );
namespace io
{
template<>
std::string enum_to_string<character_movemode>( character_movemode data )
{
switch( data ) {
// *INDENT-OFF*
case character_movemode::CMM_WALK: return "walk";
case character_movemode::CMM_RUN: return "run";
case character_movemode::CMM_CROUCH: return "crouch";
// *INDENT-ON*
case character_movemode::CMM_COUNT:
break;
}
debugmsg( "Invalid character_movemode" );
abort();
}
} // namespace io
Character &get_player_character()
{
return g->u;
}
// *INDENT-OFF*
Character::Character() :
visitable<Character>(),
damage_bandaged( {{ 0 }} ),
damage_disinfected( {{ 0 }} ),
cached_time( calendar::before_time_starts ),
id( -1 ),
next_climate_control_check( calendar::before_time_starts ),
last_climate_control_ret( false )
{
str_max = 0;
dex_max = 0;
per_max = 0;
int_max = 0;
str_cur = 0;
dex_cur = 0;
per_cur = 0;
int_cur = 0;
str_bonus = 0;
dex_bonus = 0;
per_bonus = 0;
int_bonus = 0;
healthy = 0;
healthy_mod = 0;
thirst = 0;
fatigue = 0;
sleep_deprivation = 0;
set_rad( 0 );
tank_plut = 0;
reactor_plut = 0;
slow_rad = 0;
set_stim( 0 );
set_stamina( 10000 ); //Temporary value for stamina. It will be reset later from external json option.
set_anatomy( anatomy_id("human_anatomy") );
update_type_of_scent( true );
pkill = 0;
stored_calories = max_stored_calories() - 100;
initialize_stomach_contents();
healed_total = { { 0, 0, 0, 0, 0, 0 } };
name.clear();
custom_profession.clear();
*path_settings = pathfinding_settings{ 0, 1000, 1000, 0, true, true, true, false, true };
move_mode = CMM_WALK;
next_expected_position = cata::nullopt;
temp_cur.fill( BODYTEMP_NORM );
frostbite_timer.fill( 0 );
temp_conv.fill( BODYTEMP_NORM );
body_wetness.fill( 0 );
drench_capacity[bp_eyes] = 1;
drench_capacity[bp_mouth] = 1;
drench_capacity[bp_head] = 7;
drench_capacity[bp_leg_l] = 11;
drench_capacity[bp_leg_r] = 11;
drench_capacity[bp_foot_l] = 3;
drench_capacity[bp_foot_r] = 3;
drench_capacity[bp_arm_l] = 10;
drench_capacity[bp_arm_r] = 10;
drench_capacity[bp_hand_l] = 3;
drench_capacity[bp_hand_r] = 3;
drench_capacity[bp_torso] = 40;
}
// *INDENT-ON*
Character::~Character() = default;
Character::Character( Character && ) = default;
Character &Character::operator=( Character && ) = default;
void Character::setID( character_id i, bool force )
{
if( id.is_valid() && !force ) {
debugmsg( "tried to set id of a npc/player, but has already a id: %d", id.get_value() );
} else if( !i.is_valid() && !force ) {
debugmsg( "tried to set invalid id of a npc/player: %d", i.get_value() );
} else {
id = i;
}
}
character_id Character::getID() const
{
return this->id;
}
field_type_id Character::bloodType() const
{
if( has_trait( trait_ACIDBLOOD ) ) {
return fd_acid;
}
if( has_trait( trait_THRESH_PLANT ) ) {
return fd_blood_veggy;
}
if( has_trait( trait_THRESH_INSECT ) || has_trait( trait_THRESH_SPIDER ) ) {
return fd_blood_insect;
}
if( has_trait( trait_THRESH_CEPHALOPOD ) ) {
return fd_blood_invertebrate;
}
return fd_blood;
}
field_type_id Character::gibType() const
{
return fd_gibs_flesh;
}
bool Character::in_species( const species_id &spec ) const
{
return spec == HUMAN;
}
bool Character::is_warm() const
{
// TODO: is there a mutation (plant?) that makes a npc not warm blooded?
return true;
}
const std::string &Character::symbol() const
{
static const std::string character_symbol( "@" );
return character_symbol;
}
void Character::mod_stat( const std::string &stat, float modifier )
{
if( stat == "str" ) {
mod_str_bonus( modifier );
} else if( stat == "dex" ) {
mod_dex_bonus( modifier );
} else if( stat == "per" ) {
mod_per_bonus( modifier );
} else if( stat == "int" ) {
mod_int_bonus( modifier );
} else if( stat == "healthy" ) {
mod_healthy( modifier );
} else if( stat == "hunger" ) {
mod_hunger( modifier );
} else {
Creature::mod_stat( stat, modifier );
}
}
m_size Character::get_size() const
{
return size_class;
}
std::string Character::disp_name( bool possessive, bool capitalize_first ) const
{
if( !possessive ) {
if( is_player() ) {
return capitalize_first ? _( "You" ) : _( "you" );
}
return name;
} else {
if( is_player() ) {
return capitalize_first ? _( "Your" ) : _( "your" );
}
return string_format( _( "%s's" ), name );
}
}
std::string Character::skin_name() const
{
// TODO: Return actual deflecting layer name
return _( "armor" );
}
int Character::effective_dispersion( int dispersion ) const
{
/** @EFFECT_PER penalizes sight dispersion when low. */
dispersion += ranged_per_mod();
dispersion += encumb( bp_eyes ) / 2;
return std::max( dispersion, 0 );
}
std::pair<int, int> Character::get_fastest_sight( const item &gun, double recoil ) const
{
// Get fastest sight that can be used to improve aim further below @ref recoil.
int sight_speed_modifier = INT_MIN;
int limit = 0;
if( effective_dispersion( gun.type->gun->sight_dispersion ) < recoil ) {
sight_speed_modifier = gun.has_flag( flag_DISABLE_SIGHTS ) ? 0 : 6;
limit = effective_dispersion( gun.type->gun->sight_dispersion );
}
for( const auto e : gun.gunmods() ) {
const islot_gunmod &mod = *e->type->gunmod;
if( mod.sight_dispersion < 0 || mod.aim_speed < 0 ) {
continue; // skip gunmods which don't provide a sight
}
if( effective_dispersion( mod.sight_dispersion ) < recoil &&
mod.aim_speed > sight_speed_modifier ) {
sight_speed_modifier = mod.aim_speed;
limit = effective_dispersion( mod.sight_dispersion );
}
}
return std::make_pair( sight_speed_modifier, limit );
}
int Character::get_most_accurate_sight( const item &gun ) const
{
if( !gun.is_gun() ) {
return 0;
}
int limit = effective_dispersion( gun.type->gun->sight_dispersion );
for( const auto e : gun.gunmods() ) {
const islot_gunmod &mod = *e->type->gunmod;
if( mod.aim_speed >= 0 ) {
limit = std::min( limit, effective_dispersion( mod.sight_dispersion ) );
}
}
return limit;
}
double Character::aim_speed_skill_modifier( const skill_id &gun_skill ) const
{
double skill_mult = 1.0;
if( gun_skill == skill_pistol ) {
skill_mult = 2.0;
} else if( gun_skill == skill_rifle ) {
skill_mult = 0.9;
}
/** @EFFECT_PISTOL increases aiming speed for pistols */
/** @EFFECT_SMG increases aiming speed for SMGs */
/** @EFFECT_RIFLE increases aiming speed for rifles */
/** @EFFECT_SHOTGUN increases aiming speed for shotguns */
/** @EFFECT_LAUNCHER increases aiming speed for launchers */
return skill_mult * std::min( MAX_SKILL, get_skill_level( gun_skill ) );
}
double Character::aim_speed_dex_modifier() const
{
return get_dex() - 8;
}
double Character::aim_speed_encumbrance_modifier() const
{
return ( encumb( bp_hand_l ) + encumb( bp_hand_r ) ) / 10.0;
}
double Character::aim_cap_from_volume( const item &gun ) const
{
skill_id gun_skill = gun.gun_skill();
double aim_cap = std::min( 49.0, 49.0 - static_cast<float>( gun.volume() / 75_ml ) );
// TODO: also scale with skill level.
if( gun_skill == skill_smg ) {
aim_cap = std::max( 12.0, aim_cap );
} else if( gun_skill == skill_shotgun ) {
aim_cap = std::max( 12.0, aim_cap );
} else if( gun_skill == skill_pistol ) {
aim_cap = std::max( 15.0, aim_cap * 1.25 );
} else if( gun_skill == skill_rifle ) {
aim_cap = std::max( 7.0, aim_cap - 5.0 );
} else if( gun_skill == skill_archery ) {
aim_cap = std::max( 13.0, aim_cap );
} else { // Launchers, etc.
aim_cap = std::max( 10.0, aim_cap );
}
return aim_cap;
}
double Character::aim_per_move( const item &gun, double recoil ) const
{
if( !gun.is_gun() ) {
return 0.0;
}
std::pair<int, int> best_sight = get_fastest_sight( gun, recoil );
int sight_speed_modifier = best_sight.first;
int limit = best_sight.second;
if( sight_speed_modifier == INT_MIN ) {
// No suitable sights (already at maximum aim).
return 0;
}
// Overall strategy for determining aim speed is to sum the factors that contribute to it,
// then scale that speed by current recoil level.
// Player capabilities make aiming faster, and aim speed slows down as it approaches 0.
// Base speed is non-zero to prevent extreme rate changes as aim speed approaches 0.
double aim_speed = 10.0;
skill_id gun_skill = gun.gun_skill();
// Ranges [0 - 10]
aim_speed += aim_speed_skill_modifier( gun_skill );
// Range [0 - 12]
/** @EFFECT_DEX increases aiming speed */
aim_speed += aim_speed_dex_modifier();
// Range [0 - 10]
aim_speed += sight_speed_modifier;
// Each 5 points (combined) of hand encumbrance decreases aim speed by one unit.
aim_speed -= aim_speed_encumbrance_modifier();
aim_speed = std::min( aim_speed, aim_cap_from_volume( gun ) );
// Just a raw scaling factor.
aim_speed *= 6.5;
// Scale rate logistically as recoil goes from MAX_RECOIL to 0.
aim_speed *= 1.0 - logarithmic_range( 0, MAX_RECOIL, recoil );
// Minimum improvement is 5MoA. This mostly puts a cap on how long aiming for sniping takes.
aim_speed = std::max( aim_speed, 5.0 );
// Never improve by more than the currently used sights permit.
return std::min( aim_speed, recoil - limit );
}
const tripoint &Character::pos() const
{
return position;
}
int Character::sight_range( int light_level ) const
{
if( light_level == 0 ) {
return 1;
}
/* Via Beer-Lambert we have:
* light_level * (1 / exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance) ) <= LIGHT_AMBIENT_LOW
* Solving for distance:
* 1 / exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance ) <= LIGHT_AMBIENT_LOW / light_level
* 1 <= exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance ) * LIGHT_AMBIENT_LOW / light_level
* light_level <= exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance ) * LIGHT_AMBIENT_LOW
* log(light_level) <= LIGHT_TRANSPARENCY_OPEN_AIR * distance + log(LIGHT_AMBIENT_LOW)
* log(light_level) - log(LIGHT_AMBIENT_LOW) <= LIGHT_TRANSPARENCY_OPEN_AIR * distance
* log(LIGHT_AMBIENT_LOW / light_level) <= LIGHT_TRANSPARENCY_OPEN_AIR * distance
* log(LIGHT_AMBIENT_LOW / light_level) * (1 / LIGHT_TRANSPARENCY_OPEN_AIR) <= distance
*/
int range = static_cast<int>( -std::log( get_vision_threshold( static_cast<int>
( g->m.ambient_light_at( pos() ) ) ) / static_cast<float>( light_level ) ) *
( 1.0 / LIGHT_TRANSPARENCY_OPEN_AIR ) );
// Clamp to [1, sight_max].
return clamp( range, 1, sight_max );
}
int Character::unimpaired_range() const
{
return std::min( sight_max, 60 );
}
bool Character::overmap_los( const tripoint &omt, int sight_points )
{
const tripoint ompos = global_omt_location();
if( omt.x < ompos.x - sight_points || omt.x > ompos.x + sight_points ||
omt.y < ompos.y - sight_points || omt.y > ompos.y + sight_points ) {
// Outside maximum sight range
return false;
}
const std::vector<tripoint> line = line_to( ompos, omt, 0, 0 );
for( size_t i = 0; i < line.size() && sight_points >= 0; i++ ) {
const tripoint &pt = line[i];
const oter_id &ter = overmap_buffer.ter( pt );
sight_points -= static_cast<int>( ter->get_see_cost() );
if( sight_points < 0 ) {
return false;
}
}
return true;
}
int Character::overmap_sight_range( int light_level ) const
{
int sight = sight_range( light_level );
if( sight < SEEX ) {
return 0;
}
if( sight <= SEEX * 4 ) {
return ( sight / ( SEEX / 2 ) );
}
sight = 6;
// The higher your perception, the farther you can see.
sight += static_cast<int>( get_per() / 2 );
// The higher up you are, the farther you can see.
sight += std::max( 0, posz() ) * 2;
// Mutations like Scout and Topographagnosia affect how far you can see.
sight += mutation_value( "overmap_sight" );
float multiplier = mutation_value( "overmap_multiplier" );
// Binoculars double your sight range.
const bool has_optic = ( has_item_with_flag( "ZOOM" ) || has_bionic( bio_eye_optic ) ||
( is_mounted() &&
mounted_creature->has_flag( MF_MECH_RECON_VISION ) ) );
if( has_optic ) {
multiplier += 1;
}
sight = std::round( sight * multiplier );
return std::max( sight, 3 );
}
int Character::clairvoyance() const
{
if( vision_mode_cache[VISION_CLAIRVOYANCE_SUPER] ) {
return MAX_CLAIRVOYANCE;
}
if( vision_mode_cache[VISION_CLAIRVOYANCE_PLUS] ) {
return 8;
}
if( vision_mode_cache[VISION_CLAIRVOYANCE] ) {
return 3;
}
// 0 would mean we have clairvoyance of own tile
return -1;
}
bool Character::sight_impaired() const
{
return ( ( ( has_effect( effect_boomered ) || has_effect( effect_no_sight ) ||
has_effect( effect_darkness ) ) &&
( !( has_trait( trait_PER_SLIME_OK ) ) ) ) ||
( underwater && !has_bionic( bio_membrane ) && !has_trait( trait_MEMBRANE ) &&
!worn_with_flag( "SWIM_GOGGLES" ) && !has_trait( trait_PER_SLIME_OK ) &&
!has_trait( trait_CEPH_EYES ) && !has_trait( trait_SEESLEEP ) ) ||
( ( has_trait( trait_MYOPIC ) || has_trait( trait_URSINE_EYE ) ) &&
!worn_with_flag( "FIX_NEARSIGHT" ) &&
!has_effect( effect_contacts ) &&
!has_bionic( bio_eye_optic ) ) ||
has_trait( trait_PER_SLIME ) );
}
bool Character::has_alarm_clock() const
{
return ( has_item_with_flag( "ALARMCLOCK", true ) ||
( g->m.veh_at( pos() ) &&
!empty( g->m.veh_at( pos() )->vehicle().get_avail_parts( "ALARMCLOCK" ) ) ) ||
has_bionic( bio_watch ) );
}
bool Character::has_watch() const
{
return ( has_item_with_flag( "WATCH", true ) ||
( g->m.veh_at( pos() ) &&
!empty( g->m.veh_at( pos() )->vehicle().get_avail_parts( "WATCH" ) ) ) ||
has_bionic( bio_watch ) );
}
void Character::react_to_felt_pain( int intensity )
{
if( intensity <= 0 ) {
return;
}
if( is_player() && intensity >= 2 ) {
g->cancel_activity_or_ignore_query( distraction_type::pain, _( "Ouch, something hurts!" ) );
}
// Only a large pain burst will actually wake people while sleeping.
if( has_effect( effect_sleep ) && !has_effect( effect_narcosis ) ) {
int pain_thresh = rng( 3, 5 );
if( has_trait( trait_HEAVYSLEEPER ) ) {
pain_thresh += 2;
} else if( has_trait( trait_HEAVYSLEEPER2 ) ) {
pain_thresh += 5;
}
if( intensity >= pain_thresh ) {
wake_up();
}
}
}
void Character::action_taken()
{
nv_cached = false;
}
int Character::swim_speed() const
{
int ret;
if( is_mounted() ) {
monster *mon = mounted_creature.get();
// no difference in swim speed by monster type yet.
// TODO: difference in swim speed by monster type.
// No monsters are currently mountable and can swim, though mods may allow this.
if( mon->swims() ) {
ret = 25;
ret += get_weight() / 120_gram - 50 * ( mon->get_size() - 1 );
return ret;
}
}
const auto usable = exclusive_flag_coverage( "ALLOWS_NATURAL_ATTACKS" );
float hand_bonus_mult = ( usable.test( bp_hand_l ) ? 0.5f : 0.0f ) +
( usable.test( bp_hand_r ) ? 0.5f : 0.0f );
// base swim speed.
ret = ( 440 * mutation_value( "movecost_swim_modifier" ) ) + weight_carried() /
( 60_gram / mutation_value( "movecost_swim_modifier" ) ) - 50 * get_skill_level( skill_swimming );
/** @EFFECT_STR increases swim speed bonus from PAWS */
if( has_trait( trait_PAWS ) ) {
ret -= hand_bonus_mult * ( 20 + str_cur * 3 );
}
/** @EFFECT_STR increases swim speed bonus from PAWS_LARGE */
if( has_trait( trait_PAWS_LARGE ) ) {
ret -= hand_bonus_mult * ( 20 + str_cur * 4 );
}
/** @EFFECT_STR increases swim speed bonus from swim_fins */
if( worn_with_flag( "FIN", bodypart_id( "foot_l" ) ) ||
worn_with_flag( "FIN", bodypart_id( "foot_r" ) ) ) {
if( worn_with_flag( "FIN", bodypart_id( "foot_l" ) ) &&
worn_with_flag( "FIN", bodypart_id( "foot_r" ) ) ) {
ret -= ( 15 * str_cur );
} else {
ret -= ( 15 * str_cur ) / 2;
}
}
/** @EFFECT_STR increases swim speed bonus from WEBBED */
if( has_trait( trait_WEBBED ) ) {
ret -= hand_bonus_mult * ( 60 + str_cur * 5 );
}
/** @EFFECT_SWIMMING increases swim speed */
ret += ( 50 - get_skill_level( skill_swimming ) * 2 ) * ( ( encumb( bp_leg_l ) + encumb(
bp_leg_r ) ) / 10 );
ret += ( 80 - get_skill_level( skill_swimming ) * 3 ) * ( encumb( bp_torso ) / 10 );
if( get_skill_level( skill_swimming ) < 10 ) {
for( auto &i : worn ) {
ret += i.volume() / 125_ml * ( 10 - get_skill_level( skill_swimming ) );
}
}
/** @EFFECT_STR increases swim speed */
/** @EFFECT_DEX increases swim speed */
ret -= str_cur * 6 + dex_cur * 4;
if( worn_with_flag( "FLOTATION" ) ) {
ret = std::min( ret, 400 );
ret = std::max( ret, 200 );
}
// If (ret > 500), we can not swim; so do not apply the underwater bonus.
if( underwater && ret < 500 ) {
ret -= 50;
}
// Running movement mode while swimming means faster swim style, like crawlstroke
if( move_mode == CMM_RUN ) {
ret -= 80;
}
// Crouching movement mode while swimming means slower swim style, like breaststroke
if( move_mode == CMM_CROUCH ) {
ret += 50;
}
if( ret < 30 ) {
ret = 30;
}
return ret;
}
bool Character::is_on_ground() const
{
return get_working_leg_count() < 2 || has_effect( effect_downed );
}
void Character::cancel_stashed_activity()
{
stashed_outbounds_activity = player_activity();
stashed_outbounds_backlog = player_activity();
}
player_activity Character::get_stashed_activity() const
{
return stashed_outbounds_activity;
}
void Character::set_stashed_activity( const player_activity &act, const player_activity &act_back )
{
stashed_outbounds_activity = act;
stashed_outbounds_backlog = act_back;
}
bool Character::has_stashed_activity() const
{
return static_cast<bool>( stashed_outbounds_activity );
}
void Character::assign_stashed_activity()
{
activity = stashed_outbounds_activity;
backlog.push_front( stashed_outbounds_backlog );
cancel_stashed_activity();
}
bool Character::check_outbounds_activity( const player_activity &act, bool check_only )
{
if( ( act.placement != tripoint_zero && act.placement != tripoint_min &&
!g->m.inbounds( g->m.getlocal( act.placement ) ) ) || ( !act.coords.empty() &&
!g->m.inbounds( g->m.getlocal( act.coords.back() ) ) ) ) {
if( is_npc() && !check_only ) {
// stash activity for when reloaded.
stashed_outbounds_activity = act;
if( !backlog.empty() ) {
stashed_outbounds_backlog = backlog.front();
}
activity = player_activity();
}
add_msg( m_debug,
"npc %s at pos %d %d, activity target is not inbounds at %d %d therefore activity was stashed",
disp_name(), pos().x, pos().y, act.placement.x, act.placement.y );
return true;
}
return false;
}
void Character::set_destination_activity( const player_activity &new_destination_activity )
{
destination_activity = new_destination_activity;
}
void Character::clear_destination_activity()
{
destination_activity = player_activity();
}
player_activity Character::get_destination_activity() const
{
return destination_activity;
}
void Character::mount_creature( monster &z )
{
tripoint pnt = z.pos();
shared_ptr_fast<monster> mons = g->shared_from( z );