forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
character_turn.cpp
1100 lines (997 loc) · 40.2 KB
/
character_turn.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_turn.h"
#include "bionics.h"
#include "calendar.h"
#include "character_effects.h"
#include "character_functions.h"
#include "character_stat.h"
#include "character_martial_arts.h"
#include "character.h"
#include "creature.h"
#include "game.h"
#include "handle_liquid.h"
#include "itype.h"
#include "magic_enchantment.h"
#include "mutation.h"
#include "overmapbuffer.h"
#include "make_static.h"
#include "map_iterator.h"
#include "morale.h"
#include "player.h"
#include "rng.h"
#include "submap.h"
#include "trap.h"
#include "veh_type.h"
#include "vehicle.h"
#include "vpart_position.h"
#include "weather_gen.h"
#include "weather.h"
static const trait_id trait_ACIDBLOOD( "ACIDBLOOD" );
static const trait_id trait_ARACHNID_ARMS_OK( "ARACHNID_ARMS_OK" );
static const trait_id trait_ARACHNID_ARMS( "ARACHNID_ARMS" );
static const trait_id trait_CHITIN_FUR( "CHITIN_FUR" );
static const trait_id trait_CHITIN_FUR2( "CHITIN_FUR2" );
static const trait_id trait_CHITIN_FUR3( "CHITIN_FUR3" );
static const trait_id trait_CHITIN2( "CHITIN2" );
static const trait_id trait_CHITIN3( "CHITIN3" );
static const trait_id trait_COLDBLOOD4( "COLDBLOOD4" );
static const trait_id trait_COMPOUND_EYES( "COMPOUND_EYES" );
static const trait_id trait_EATHEALTH( "EATHEALTH" );
static const trait_id trait_FAT( "FAT" );
static const trait_id trait_FELINE_FUR( "FELINE_FUR" );
static const trait_id trait_FUR( "FUR" );
static const trait_id trait_INSECT_ARMS_OK( "INSECT_ARMS_OK" );
static const trait_id trait_INSECT_ARMS( "INSECT_ARMS" );
static const trait_id trait_LIGHTFUR( "LIGHTFUR" );
static const trait_id trait_LUPINE_FUR( "LUPINE_FUR" );
static const trait_id trait_M_IMMUNE( "M_IMMUNE" );
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_PARAIMMUNE( "PARAIMMUNE" );
static const trait_id trait_SLIMY( "SLIMY" );
static const trait_id trait_STIMBOOST( "STIMBOOST" );
static const trait_id trait_SUNLIGHT_DEPENDENT( "SUNLIGHT_DEPENDENT" );
static const trait_id trait_THICK_SCALES( "THICK_SCALES" );
static const trait_id trait_URSINE_FUR( "URSINE_FUR" );
static const trait_id trait_WEBBED( "WEBBED" );
static const trait_id trait_WHISKERS_RAT( "WHISKERS_RAT" );
static const trait_id trait_WHISKERS( "WHISKERS" );
static const efftype_id effect_bloodworms( "bloodworms" );
static const efftype_id effect_brainworms( "brainworms" );
static const efftype_id effect_darkness( "darkness" );
static const efftype_id effect_depressants( "depressants" );
static const efftype_id effect_dermatik( "dermatik" );
static const efftype_id effect_downed( "downed" );
static const efftype_id effect_fungus( "fungus" );
static const efftype_id effect_happy( "happy" );
static const efftype_id effect_irradiated( "irradiated" );
static const efftype_id effect_masked_scent( "masked_scent" );
static const efftype_id effect_narcosis( "narcosis" );
static const efftype_id effect_onfire( "onfire" );
static const efftype_id effect_paincysts( "paincysts" );
static const efftype_id effect_pkill( "pkill" );
static const efftype_id effect_sad( "sad" );
static const efftype_id effect_sleep_deprived( "sleep_deprived" );
static const efftype_id effect_sleep( "sleep" );
static const efftype_id effect_stim_overdose( "stim_overdose" );
static const efftype_id effect_stim( "stim" );
static const efftype_id effect_tapeworm( "tapeworm" );
static const efftype_id effect_thirsty( "thirsty" );
static const skill_id skill_swimming( "swimming" );
static const bionic_id bio_ground_sonar( "bio_ground_sonar" );
static const bionic_id bio_hydraulics( "bio_hydraulics" );
static const bionic_id bio_speed( "bio_speed" );
static const itype_id itype_adv_UPS_off( "adv_UPS_off" );
static const itype_id itype_UPS_off( "UPS_off" );
static const itype_id itype_UPS( "UPS" );
void Character::recalc_speed_bonus()
{
// Minus some for weight...
int carry_penalty = 0;
if( weight_carried() > weight_capacity() && !has_trait( trait_id( "DEBUG_STORAGE" ) ) ) {
carry_penalty = 25 * ( weight_carried() - weight_capacity() ) / ( weight_capacity() );
}
mod_speed_bonus( -carry_penalty );
mod_speed_bonus( -character_effects::get_pain_penalty( *this ).speed );
if( get_thirst() > thirst_levels::very_thirsty ) {
mod_speed_bonus( character_effects::get_thirst_speed_penalty( get_thirst() ) );
}
// when underweight, you get slower. cumulative with hunger
mod_speed_bonus( character_effects::get_kcal_speed_penalty( get_kcal_percent() ) );
for( const auto &maps : *effects ) {
for( auto &i : maps.second ) {
if( i.second.is_removed() ) {
continue;
}
bool reduced = resists_effect( i.second );
mod_speed_bonus( i.second.get_mod( "SPEED", reduced ) );
}
}
// add martial arts speed bonus
mod_speed_bonus( mabuff_speed_bonus() );
// Not sure why Sunlight Dependent is here, but OK
// Ectothermic/COLDBLOOD4 is intended to buff folks in the Summer
// Threshold-crossing has its charms ;-)
if( g != nullptr ) {
if( has_trait( trait_SUNLIGHT_DEPENDENT ) && !g->is_in_sunlight( pos() ) ) {
mod_speed_bonus( -( g->light_level( posz() ) >= 12 ? 5 : 10 ) );
}
const float temperature_speed_modifier = mutation_value( "temperature_speed_modifier" );
if( temperature_speed_modifier != 0 ) {
const auto player_local_temp = get_weather().get_temperature( pos() );
if( has_trait( trait_COLDBLOOD4 ) || player_local_temp < 65 ) {
mod_speed_bonus( ( player_local_temp - 65 ) * temperature_speed_modifier );
}
}
}
if( has_artifact_with( AEP_SPEED_UP ) ) {
mod_speed_bonus( 20 );
}
if( has_artifact_with( AEP_SPEED_DOWN ) ) {
mod_speed_bonus( -20 );
}
mod_speed_bonus( get_speedydex_bonus( get_dex() ) );
float speed_modifier = Character::mutation_value( "speed_modifier" );
mod_speed_mult( speed_modifier - 1 );
if( has_bionic( bio_speed ) ) { // add 10% speed bonus
mod_speed_mult( 0.1 );
}
double ench_bonus = enchantment_cache->calc_bonus( enchant_vals::mod::SPEED, get_speed() );
mod_speed_bonus( ench_bonus );
}
void Character::process_turn()
{
// Has to happen before reset_stats
clear_miss_reasons();
for( bionic &i : *my_bionics ) {
if( i.incapacitated_time > 0_turns ) {
i.incapacitated_time -= 1_turns;
if( i.incapacitated_time == 0_turns ) {
add_msg_if_player( m_bad, _( "Your %s bionic comes back online." ), i.info().name );
}
}
}
Creature::process_turn();
// If we're actively handling something we can't just drop it on the ground
// in the middle of handling it
if( activity.targets.empty() ) {
drop_invalid_inventory();
}
process_items();
// Didn't just pick something up
last_item = itype_id( "null" );
visit_items( [this]( item * e ) {
e->process_artifact( as_player(), pos() );
e->process_relic( *this );
return VisitResponse::NEXT;
} );
suffer();
// NPCs currently don't make any use of their scent, pointless to calculate it
// TODO: make use of NPC scent.
if( !is_npc() ) {
if( !has_effect( effect_masked_scent ) ) {
restore_scent();
}
const int mask_intensity = get_effect_int( effect_masked_scent );
// Set our scent towards the norm
int norm_scent = 500;
int temp_norm_scent = INT_MIN;
bool found_intensity = false;
for( const trait_id &mut : get_mutations() ) {
const std::optional<int> &scent_intensity = mut->scent_intensity;
if( scent_intensity ) {
found_intensity = true;
temp_norm_scent = std::max( temp_norm_scent, *scent_intensity );
}
}
if( found_intensity ) {
norm_scent = temp_norm_scent;
}
for( const trait_id &mut : get_mutations() ) {
const std::optional<int> &scent_mask = mut->scent_mask;
if( scent_mask ) {
norm_scent += *scent_mask;
}
}
//mask from scent altering items;
norm_scent += mask_intensity;
// Scent increases fast at first, and slows down as it approaches normal levels.
// Estimate it will take about norm_scent * 2 turns to go from 0 - norm_scent / 2
// Without smelly trait this is about 1.5 hrs. Slows down significantly after that.
if( scent < rng( 0, norm_scent ) ) {
scent++;
}
// Unusually high scent decreases steadily until it reaches normal levels.
if( scent > norm_scent ) {
scent--;
}
for( const trait_id &mut : get_mutations() ) {
scent *= mut.obj().scent_modifier;
}
}
// We can dodge again! Assuming we can actually move...
if( in_sleep_state() ) {
blocks_left = 0;
dodges_left = 0;
} else if( moves > 0 ) {
blocks_left = get_num_blocks();
dodges_left = get_num_dodges();
}
// auto-learning. This is here because skill-increases happens all over the place:
// SkillLevel::readBook (has no connection to the skill or the player),
// player::read, player::practice, ...
// Check for spontaneous discovery of martial art styles
for( auto &style : autolearn_martialart_types() ) {
const matype_id &ma( style );
if( !martial_arts_data->has_martialart( ma ) && can_autolearn_martial_art( *this, ma ) ) {
martial_arts_data->add_martialart( ma );
add_msg_if_player( m_info, _( "You have learned a new style: %s!" ), ma.obj().name );
}
}
// Update time spent conscious in this overmap tile for the Nomad traits.
if( !is_npc() && ( has_trait( trait_NOMAD ) || has_trait( trait_NOMAD2 ) ||
has_trait( trait_NOMAD3 ) ) &&
!has_effect( effect_sleep ) && !has_effect( effect_narcosis ) ) {
const tripoint_abs_omt ompos = global_omt_location();
const point_abs_omt pos = ompos.xy();
if( overmap_time.find( pos ) == overmap_time.end() ) {
overmap_time[pos] = 1_turns;
} else {
overmap_time[pos] += 1_turns;
}
}
// Decay time spent in other overmap tiles.
if( !is_npc() && calendar::once_every( 1_hours ) ) {
const tripoint_abs_omt ompos = global_omt_location();
const time_point now = calendar::turn;
time_duration decay_time = 0_days;
if( has_trait( trait_NOMAD ) ) {
decay_time = 7_days;
} else if( has_trait( trait_NOMAD2 ) ) {
decay_time = 14_days;
} else if( has_trait( trait_NOMAD3 ) ) {
decay_time = 28_days;
}
auto it = overmap_time.begin();
while( it != overmap_time.end() ) {
if( it->first == ompos.xy() ) {
it++;
continue;
}
// Find the amount of time passed since the player touched any of the overmap tile's submaps.
const tripoint_abs_omt tpt( it->first, 0 );
const time_point last_touched = overmap_buffer.scent_at( tpt ).creation_time;
const time_duration since_visit = now - last_touched;
// If the player has spent little time in this overmap tile, let it decay after just an hour instead of the usual extended decay time.
const time_duration modified_decay_time = it->second > 5_minutes ? decay_time : 1_hours;
if( since_visit > modified_decay_time ) {
// Reduce the tracked time spent in this overmap tile.
const time_duration decay_amount = std::min( since_visit - modified_decay_time, 1_hours );
const time_duration updated_value = it->second - decay_amount;
if( updated_value <= 0_turns ) {
// We can stop tracking this tile if there's no longer any time recorded there.
it = overmap_time.erase( it );
continue;
} else {
it->second = updated_value;
}
}
it++;
}
}
}
void Character::process_one_effect( effect &it, bool is_new )
{
bool reduced = resists_effect( it );
double mod = 1;
body_part bp = it.get_bp()->token;
int val = 0;
// Still hardcoded stuff, do this first since some modify their other traits
hardcoded_effects( it );
const auto get_effect = [&it, is_new]( const std::string & arg, bool reduced ) {
if( is_new ) {
return it.get_amount( arg, reduced );
}
return it.get_mod( arg, reduced );
};
// Handle miss messages
auto msgs = it.get_miss_msgs();
if( !msgs.empty() ) {
for( const auto &i : msgs ) {
add_miss_reason( _( i.first ), static_cast<unsigned>( i.second ) );
}
}
// Handle health mod
val = get_effect( "H_MOD", reduced );
if( val != 0 ) {
mod = 1;
if( is_new || it.activated( calendar::turn, "H_MOD", val, reduced, mod ) ) {
int bounded = bound_mod_to_vals(
get_healthy_mod(), val, it.get_max_val( "H_MOD", reduced ),
it.get_min_val( "H_MOD", reduced ) );
// This already applies bounds, so we pass them through.
mod_healthy_mod( bounded, get_healthy_mod() + bounded );
}
}
// Handle health
val = get_effect( "HEALTH", reduced );
if( val != 0 ) {
mod = 1;
if( is_new || it.activated( calendar::turn, "HEALTH", val, reduced, mod ) ) {
mod_healthy( bound_mod_to_vals( get_healthy(), val,
it.get_max_val( "HEALTH", reduced ), it.get_min_val( "HEALTH", reduced ) ) );
}
}
// Handle stim
val = get_effect( "STIM", reduced );
if( val != 0 ) {
mod = 1;
if( is_new || it.activated( calendar::turn, "STIM", val, reduced, mod ) ) {
mod_stim( bound_mod_to_vals( get_stim(), val, it.get_max_val( "STIM", reduced ),
it.get_min_val( "STIM", reduced ) ) );
}
}
// Handle hunger
val = get_effect( "HUNGER", reduced );
if( val != 0 ) {
mod = 1;
if( is_new || it.activated( calendar::turn, "HUNGER", val, reduced, mod ) ) {
mod_stored_kcal( -10 * bound_mod_to_vals( ( max_stored_kcal() - get_stored_kcal() ) / 10,
val, it.get_max_val( "HUNGER", reduced ), it.get_min_val( "HUNGER", reduced ) ) );
}
}
// Handle thirst
val = get_effect( "THIRST", reduced );
if( val != 0 ) {
mod = 1;
if( is_new || it.activated( calendar::turn, "THIRST", val, reduced, mod ) ) {
mod_thirst( bound_mod_to_vals( get_thirst(), val, it.get_max_val( "THIRST", reduced ),
it.get_min_val( "THIRST", reduced ) ) );
}
}
// Handle fatigue
val = get_effect( "FATIGUE", reduced );
// Prevent ongoing fatigue effects while asleep.
// These are meant to change how fast you get tired, not how long you sleep.
if( val != 0 && !in_sleep_state() ) {
mod = 1;
if( is_new || it.activated( calendar::turn, "FATIGUE", val, reduced, mod ) ) {
mod_fatigue( bound_mod_to_vals( get_fatigue(), val, it.get_max_val( "FATIGUE", reduced ),
it.get_min_val( "FATIGUE", reduced ) ) );
}
}
// Handle Radiation
val = get_effect( "RAD", reduced );
if( val != 0 ) {
mod = 1;
if( is_new || it.activated( calendar::turn, "RAD", val, reduced, mod ) ) {
mod_rad( bound_mod_to_vals( get_rad(), val, it.get_max_val( "RAD", reduced ), 0 ) );
// Radiation can't go negative
if( get_rad() < 0 ) {
set_rad( 0 );
}
}
}
// Handle Pain
val = get_effect( "PAIN", reduced );
if( val != 0 ) {
mod = 1;
if( it.get_sizing( "PAIN" ) ) {
if( has_trait( trait_FAT ) ) {
mod *= 1.5;
}
if( get_size() == MS_LARGE ) {
mod *= 2;
}
if( get_size() == MS_HUGE ) {
mod *= 3;
}
}
if( is_new || it.activated( calendar::turn, "PAIN", val, reduced, mod ) ) {
int pain_inc = bound_mod_to_vals( get_pain(), val, it.get_max_val( "PAIN", reduced ), 0 );
mod_pain( pain_inc );
if( pain_inc > 0 ) {
character_funcs::add_pain_msg( *this, val, bp );
}
}
}
// Handle Damage
val = get_effect( "HURT", reduced );
if( val != 0 ) {
mod = 1;
if( it.get_sizing( "HURT" ) ) {
if( has_trait( trait_FAT ) ) {
mod *= 1.5;
}
if( get_size() == MS_LARGE ) {
mod *= 2;
}
if( get_size() == MS_HUGE ) {
mod *= 3;
}
}
if( is_new || it.activated( calendar::turn, "HURT", val, reduced, mod ) ) {
if( bp == num_bp ) {
if( val > 5 ) {
add_msg_if_player( _( "Your %s HURTS!" ), body_part_name_accusative( bp_torso ) );
} else {
add_msg_if_player( _( "Your %s hurts!" ), body_part_name_accusative( bp_torso ) );
}
apply_damage( nullptr, bodypart_id( "torso" ), val, true );
} else {
if( val > 5 ) {
add_msg_if_player( _( "Your %s HURTS!" ), body_part_name_accusative( bp ) );
} else {
add_msg_if_player( _( "Your %s hurts!" ), body_part_name_accusative( bp ) );
}
apply_damage( nullptr, convert_bp( bp ).id(), val, true );
}
}
}
// Handle Sleep
val = get_effect( "SLEEP", reduced );
if( val != 0 ) {
mod = 1;
if( ( is_new || it.activated( calendar::turn, "SLEEP", val, reduced, mod ) ) &&
!has_effect( efftype_id( "sleep" ) ) ) {
add_msg_if_player( _( "You pass out!" ) );
fall_asleep( time_duration::from_turns( val ) );
}
}
// Handle painkillers
val = get_effect( "PKILL", reduced );
if( val != 0 ) {
mod = it.get_addict_mod( "PKILL", addiction_level( add_type::PKILLER ) );
if( is_new || it.activated( calendar::turn, "PKILL", val, reduced, mod ) ) {
mod_painkiller( bound_mod_to_vals( get_painkiller(), val, it.get_max_val( "PKILL", reduced ), 0 ) );
}
}
// Handle coughing
mod = 1;
val = 0;
if( it.activated( calendar::turn, "COUGH", val, reduced, mod ) ) {
cough( it.get_harmful_cough() );
}
// Handle vomiting
mod = character_effects::vomit_mod( *this );
val = 0;
if( it.activated( calendar::turn, "VOMIT", val, reduced, mod ) ) {
vomit();
}
// Handle stamina
val = get_effect( "STAMINA", reduced );
if( val != 0 ) {
mod = 1;
if( is_new || it.activated( calendar::turn, "STAMINA", val, reduced, mod ) ) {
mod_stamina( bound_mod_to_vals( get_stamina(), val,
it.get_max_val( "STAMINA", reduced ),
it.get_min_val( "STAMINA", reduced ) ) );
}
}
// Speed and stats are handled in recalc_speed_bonus and reset_stats respectively
}
void Character::process_effects_internal()
{
//Special Removals
if( has_effect( effect_darkness ) && g->is_in_sunlight( pos() ) ) {
remove_effect( effect_darkness );
}
if( has_trait( trait_M_IMMUNE ) && has_effect( effect_fungus ) ) {
vomit();
remove_effect( effect_fungus );
add_msg_if_player( m_bad, _( "We have mistakenly colonized a local guide! Purging now." ) );
}
if( has_trait( trait_PARAIMMUNE ) && ( has_effect( effect_dermatik ) ||
has_effect( effect_tapeworm ) ||
has_effect( effect_bloodworms ) ||
has_effect( effect_brainworms ) ||
has_effect( effect_paincysts ) ) ) {
remove_effect( effect_dermatik );
remove_effect( effect_tapeworm );
remove_effect( effect_bloodworms );
remove_effect( effect_brainworms );
remove_effect( effect_paincysts );
add_msg_if_player( m_good, _( "Something writhes and inside of you as it dies." ) );
}
if( has_trait( trait_ACIDBLOOD ) && ( has_effect( effect_dermatik ) ||
has_effect( effect_bloodworms ) ||
has_effect( effect_brainworms ) ) ) {
remove_effect( effect_dermatik );
remove_effect( effect_bloodworms );
remove_effect( effect_brainworms );
}
if( has_trait( trait_EATHEALTH ) && has_effect( effect_tapeworm ) ) {
remove_effect( effect_tapeworm );
add_msg_if_player( m_good, _( "Your bowels gurgle as something inside them dies." ) );
}
//Human only effects
for( auto &elem : *effects ) {
for( auto &_effect_it : elem.second ) {
if( !_effect_it.second.is_removed() ) {
process_one_effect( _effect_it.second, false );
}
}
}
}
void Character::reset_stats()
{
const int current_stim = get_stim();
// Trait / mutation buffs
if( has_trait( trait_THICK_SCALES ) ) {
add_miss_reason( _( "Your thick scales get in the way." ), 2 );
}
if( has_trait( trait_CHITIN2 ) || has_trait( trait_CHITIN3 ) || has_trait( trait_CHITIN_FUR3 ) ) {
add_miss_reason( _( "Your chitin gets in the way." ), 1 );
}
if( has_trait( trait_COMPOUND_EYES ) && !wearing_something_on( bodypart_id( "eyes" ) ) ) {
mod_per_bonus( 2 );
}
if( has_trait( trait_INSECT_ARMS ) ) {
add_miss_reason( _( "Your insect limbs get in the way." ), 2 );
}
if( has_trait( trait_INSECT_ARMS_OK ) ) {
if( !wearing_something_on( bodypart_id( "torso" ) ) ) {
mod_dex_bonus( 1 );
} else {
mod_dex_bonus( -1 );
add_miss_reason( _( "Your clothing restricts your insect arms." ), 1 );
}
}
if( has_trait( trait_WEBBED ) ) {
add_miss_reason( _( "Your webbed hands get in the way." ), 1 );
}
if( has_trait( trait_ARACHNID_ARMS ) ) {
add_miss_reason( _( "Your arachnid limbs get in the way." ), 4 );
}
if( has_trait( trait_ARACHNID_ARMS_OK ) ) {
if( !wearing_something_on( bodypart_id( "torso" ) ) ) {
mod_dex_bonus( 2 );
} else if( !exclusive_flag_coverage( "OVERSIZE" ).test( bp_torso ) ) {
mod_dex_bonus( -2 );
add_miss_reason( _( "Your clothing constricts your arachnid limbs." ), 2 );
}
}
const auto set_fake_effect_dur = [this]( const efftype_id & type, const time_duration & dur ) {
effect &eff = get_effect( type );
if( eff.get_duration() == dur ) {
return;
}
if( eff.is_null() && dur > 0_turns ) {
add_effect( type, dur, num_bp );
} else if( dur > 0_turns ) {
eff.set_duration( dur );
} else {
remove_effect( type, num_bp );
}
};
// Painkiller
set_fake_effect_dur( effect_pkill, 1_turns * get_painkiller() );
// Pain
if( get_perceived_pain() > 0 ) {
const stat_mod ppen = character_effects::get_pain_penalty( *this );
mod_str_bonus( -ppen.strength );
mod_dex_bonus( -ppen.dexterity );
mod_int_bonus( -ppen.intelligence );
mod_per_bonus( -ppen.perception );
if( ppen.dexterity > 0 ) {
add_miss_reason( _( "Your pain distracts you!" ), static_cast<unsigned>( ppen.dexterity ) );
}
}
// Radiation
set_fake_effect_dur( effect_irradiated, 1_turns * get_rad() );
// Morale
const int morale = get_morale_level();
set_fake_effect_dur( effect_happy, 1_turns * morale );
set_fake_effect_dur( effect_sad, 1_turns * -morale );
// Stimulants
set_fake_effect_dur( effect_stim, 1_turns * current_stim );
set_fake_effect_dur( effect_depressants, 1_turns * -current_stim );
if( has_trait( trait_STIMBOOST ) ) {
set_fake_effect_dur( effect_stim_overdose, 1_turns * ( current_stim - 60 ) );
} else {
set_fake_effect_dur( effect_stim_overdose, 1_turns * ( current_stim - 30 ) );
}
// Starvation
if( get_kcal_percent() < 0.95f ) {
// kcal->percentage of base str
static const std::vector<std::pair<float, float>> starv_thresholds = { {
std::make_pair( 0.0f, 0.5f ),
std::make_pair( 0.8f, 0.1f ),
std::make_pair( 0.95f, 0.0f )
}
};
const int str_penalty = std::floor( multi_lerp( starv_thresholds, get_kcal_percent() ) );
add_miss_reason( _( "You're weak from hunger." ),
static_cast<unsigned>( str_penalty / 2 ) );
mod_str_bonus( -str_penalty );
mod_dex_bonus( -( str_penalty / 2 ) );
mod_int_bonus( -( str_penalty / 2 ) );
}
// Thirst
set_fake_effect_dur( effect_thirsty, 1_turns * ( get_thirst() - thirst_levels::very_thirsty ) );
if( get_sleep_deprivation() >= sleep_deprivation_levels::harmless ) {
set_fake_effect_dur( effect_sleep_deprived, 1_turns * get_sleep_deprivation() );
} else if( has_effect( effect_sleep_deprived ) ) {
remove_effect( effect_sleep_deprived );
}
// Dodge-related effects
mod_dodge_bonus( mabuff_dodge_bonus() -
( encumb( bp_leg_l ) + encumb( bp_leg_r ) ) / 20.0f - encumb( bp_torso ) / 10.0f );
// Whiskers don't work so well if they're covered
if( has_trait( trait_WHISKERS ) && !wearing_something_on( bodypart_id( "mouth" ) ) ) {
mod_dodge_bonus( 1.5 );
}
if( has_trait( trait_WHISKERS_RAT ) && !wearing_something_on( bodypart_id( "mouth" ) ) ) {
mod_dodge_bonus( 3 );
}
// depending on mounts size, attacks will hit the mount and use their dodge rating.
// if they hit the player, the player cannot dodge as effectively.
if( is_mounted() ) {
mod_dodge_bonus( -4 );
}
// Spider hair is basically a full-body set of whiskers, once you get the brain for it
if( has_trait( trait_CHITIN_FUR3 ) ) {
static const std::array<bodypart_id, 5> parts{ { bodypart_id( "head" ), bodypart_id( "arm_r" ), bodypart_id( "arm_l" ), bodypart_id( "leg_r" ), bodypart_id( "leg_l" ) } };
for( const bodypart_id &bp : parts ) {
if( !wearing_something_on( bp ) ) {
mod_dodge_bonus( +1 );
}
}
// Torso handled separately, bigger bonus
if( !wearing_something_on( bodypart_id( "torso" ) ) ) {
mod_dodge_bonus( 4 );
}
}
// Apply static martial arts buffs
martial_arts_data->ma_static_effects( *this );
if( calendar::once_every( 1_minutes ) ) {
character_funcs::update_mental_focus( *this );
}
// Effects
for( const auto &maps : *effects ) {
for( auto i : maps.second ) {
const auto &it = i.second;
if( it.is_removed() ) {
continue;
}
bool reduced = resists_effect( it );
mod_str_bonus( it.get_mod( "STR", reduced ) );
mod_dex_bonus( it.get_mod( "DEX", reduced ) );
mod_per_bonus( it.get_mod( "PER", reduced ) );
mod_int_bonus( it.get_mod( "INT", reduced ) );
}
}
// Bionic buffs
if( has_active_bionic( bio_hydraulics ) ) {
mod_str_bonus( 20 );
}
mod_str_bonus( get_mod_stat_from_bionic( character_stat::STRENGTH ) );
mod_dex_bonus( get_mod_stat_from_bionic( character_stat::DEXTERITY ) );
mod_per_bonus( get_mod_stat_from_bionic( character_stat::PERCEPTION ) );
mod_int_bonus( get_mod_stat_from_bionic( character_stat::INTELLIGENCE ) );
// Trait / mutation buffs
mod_str_bonus( std::floor( mutation_value( "str_modifier" ) ) );
mod_dodge_bonus( std::floor( mutation_value( "dodge_modifier" ) ) );
apply_skill_boost();
nv_cached = false;
// Reset our stats to normal levels
// Any persistent buffs/debuffs will take place in effects,
// player::suffer(), etc.
// repopulate the stat fields
str_cur = str_max + get_str_bonus();
dex_cur = dex_max + get_dex_bonus();
per_cur = per_max + get_per_bonus();
int_cur = int_max + get_int_bonus();
// Floor for our stats. No stat changes should occur after this!
if( dex_cur < 0 ) {
dex_cur = 0;
}
if( str_cur < 0 ) {
str_cur = 0;
}
if( per_cur < 0 ) {
per_cur = 0;
}
if( int_cur < 0 ) {
int_cur = 0;
}
recalc_sight_limits();
recalc_speed_bonus();
}
void Character::environmental_revert_effect()
{
addictions.clear();
morale->clear();
set_all_parts_hp_to_max();
set_stored_kcal( max_stored_kcal() );
set_thirst( 0 );
set_fatigue( 0 );
set_healthy( 0 );
set_healthy_mod( 0 );
set_stim( 0 );
set_pain( 0 );
set_painkiller( 0 );
set_rad( 0 );
set_sleep_deprivation( 0 );
recalc_sight_limits();
reset_encumbrance();
}
void Character::process_items()
{
if( weapon.needs_processing() && weapon.process( as_player(), pos(), false ) ) {
weapon = item();
}
std::vector<item *> inv_active = inv.active_items();
for( item *tmp_it : inv_active ) {
if( tmp_it->process( as_player(), pos(), false ) ) {
inv.remove_item( tmp_it );
}
}
// worn items
remove_worn_items_with( [this]( item & itm ) {
return itm.needs_processing() && itm.process( as_player(), pos(), false );
} );
// Active item processing done, now we're recharging.
std::vector<item *> active_worn_items;
bool weapon_active = weapon.has_flag( "USE_UPS" ) &&
weapon.charges < weapon.type->maximum_charges();
std::vector<size_t> active_held_items;
int ch_UPS = 0;
for( size_t index = 0; index < inv.size(); index++ ) {
item &it = inv.find_item( index );
itype_id identifier = it.type->get_id();
if( identifier == itype_UPS_off ) {
ch_UPS += it.ammo_remaining();
} else if( identifier == itype_adv_UPS_off ) {
ch_UPS += it.ammo_remaining() / 0.6;
}
if( it.has_flag( "USE_UPS" ) && it.charges < it.type->maximum_charges() ) {
active_held_items.push_back( index );
}
}
bool update_required = get_check_encumbrance();
for( item &w : worn ) {
if( w.has_flag( "USE_UPS" ) &&
w.charges < w.type->maximum_charges() ) {
active_worn_items.push_back( &w );
}
// Necessary for UPS in Aftershock - check worn items for charge
const itype_id &identifier = w.typeId();
if( identifier == itype_UPS_off ) {
ch_UPS += w.ammo_remaining();
} else if( identifier == itype_adv_UPS_off ) {
ch_UPS += w.ammo_remaining() / 0.6;
}
if( !update_required && w.encumbrance_update_ ) {
update_required = true;
}
w.encumbrance_update_ = false;
}
if( update_required ) {
reset_encumbrance();
}
if( has_active_bionic( bionic_id( "bio_ups" ) ) ) {
ch_UPS += units::to_kilojoule( get_power_level() );
}
int ch_UPS_used = 0;
// Load all items that use the UPS to their minimal functional charge,
// The tool is not really useful if its charges are below charges_to_use
for( size_t index : active_held_items ) {
if( ch_UPS_used >= ch_UPS ) {
break;
}
item &it = inv.find_item( index );
ch_UPS_used++;
it.charges++;
}
if( weapon_active && ch_UPS_used < ch_UPS ) {
ch_UPS_used++;
weapon.charges++;
}
for( item *worn_item : active_worn_items ) {
if( ch_UPS_used >= ch_UPS ) {
break;
}
ch_UPS_used++;
worn_item->charges++;
}
if( ch_UPS_used > 0 ) {
use_charges( itype_UPS, ch_UPS_used );
}
}
namespace character_funcs
{
void update_body_wetness( Character &who, const w_point &weather )
{
// Average number of turns to go from completely soaked to fully dry
// assuming average temperature and humidity
constexpr time_duration average_drying = 2_hours;
// A modifier on drying time
double delay = 1.0;
// Weather slows down drying
delay += ( ( weather.humidity - 66 ) - ( units::to_fahrenheit( weather.temperature ) - 65 ) ) / 100;
delay = std::max( 0.1, delay );
// Fur/slime retains moisture
if( who.has_trait( trait_LIGHTFUR ) ||
who.has_trait( trait_FUR ) ||
who.has_trait( trait_FELINE_FUR ) ||
who.has_trait( trait_LUPINE_FUR ) ||
who.has_trait( trait_CHITIN_FUR ) ||
who.has_trait( trait_CHITIN_FUR2 ) ||
who.has_trait( trait_CHITIN_FUR3 ) ) {
delay = delay * 6 / 5;
}
if( who.has_trait( trait_URSINE_FUR ) || who.has_trait( trait_SLIMY ) ) {
delay *= 1.5;
}
if( !x_in_y( 1, to_turns<int>( average_drying * delay / 100.0 ) ) ) {
// No drying this turn
return;
}
// Now per-body-part stuff
// To make drying uniform, make just one roll and reuse it
const int drying_roll = rng( 1, 80 );
for( const body_part bp : all_body_parts ) {
if( who.body_wetness[bp] == 0 ) {
continue;
}
// This is to normalize drying times
int drying_chance = who.drench_capacity[bp];
// Body temperature affects duration of wetness
// Note: Using temp_conv rather than temp_cur, to better approximate environment
if( who.temp_conv[bp] >= BODYTEMP_SCORCHING ) {
drying_chance *= 2;
} else if( who.temp_conv[bp] >= BODYTEMP_VERY_HOT ) {
drying_chance = drying_chance * 3 / 2;
} else if( who.temp_conv[bp] >= BODYTEMP_HOT ) {
drying_chance = drying_chance * 4 / 3;
} else if( who.temp_conv[bp] > BODYTEMP_COLD ) {
// Comfortable, doesn't need any changes
} else {
// Evaporation doesn't change that much at lower temp
drying_chance = drying_chance * 3 / 4;
}
if( drying_chance < 1 ) {
drying_chance = 1;
}
// TODO: Make evaporation reduce body heat
if( drying_chance >= drying_roll ) {
who.body_wetness[bp] -= 1;
if( who.body_wetness[bp] < 0 ) {
who.body_wetness[bp] = 0;
}
}
}
// TODO: Make clothing slow down drying
}
void do_pause( Character &who )
{
map &here = get_map();
who.moves = 0;
who.recoil = MAX_RECOIL;
// Train swimming if underwater
if( !who.in_vehicle ) {
if( who.is_underwater() ) {
who.as_player()->practice( skill_swimming, 1 );
who.drench( 100, { {
bp_leg_l, bp_leg_r, bp_torso, bp_arm_l,
bp_arm_r, bp_head, bp_eyes, bp_mouth,
bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r
}
}, true );
} else if( here.has_flag( TFLAG_DEEP_WATER, who.pos() ) ) {
who.as_player()->practice( skill_swimming, 1 );
// Same as above, except no head/eyes/mouth
who.drench( 100, { {
bp_leg_l, bp_leg_r, bp_torso, bp_arm_l,
bp_arm_r, bp_foot_l, bp_foot_r, bp_hand_l,
bp_hand_r
}
}, true );
} else if( here.has_flag( "SWIMMABLE", who.pos() ) ) {
who.drench( 40, { { bp_foot_l, bp_foot_r, bp_leg_l, bp_leg_r } }, false );
}
}
// Try to put out clothing/hair fire
if( who.has_effect( effect_onfire ) ) {
time_duration total_removed = 0_turns;
time_duration total_left = 0_turns;
bool on_ground = who.has_effect( effect_downed );
for( const body_part bp : all_body_parts ) {
effect &eff = who.get_effect( effect_onfire, bp );
if( eff.is_null() ) {
continue;
}
// TODO: Tools and skills