-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
suffer.cpp
2233 lines (2029 loc) · 86.6 KB
/
suffer.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 <cctype>
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <iosfwd>
#include <list>
#include <map>
#include <memory>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "activity_handlers.h"
#include "addiction.h"
#include "bionics.h"
#include "bodypart.h"
#include "calendar.h"
#include "cata_utility.h"
#include "character.h"
#include "creature.h"
#include "debug.h"
#include "display.h"
#include "effect.h"
#include "enums.h"
#include "event.h"
#include "event_bus.h"
#include "field_type.h"
#include "flag.h"
#include "game.h"
#include "game_constants.h"
#include "inventory.h"
#include "item.h"
#include "item_location.h"
#include "magic_enchantment.h"
#include "map.h"
#include "memory_fast.h"
#include "messages.h"
#include "monster.h"
#include "morale_types.h"
#include "mtype.h"
#include "mutation.h"
#include "name.h"
#include "npc.h"
#include "optional.h"
#include "options.h"
#include "output.h"
#include "overmapbuffer.h"
#include "pimpl.h"
#include "player_activity.h"
#include "point.h"
#include "rng.h"
#include "skill.h"
#include "sounds.h"
#include "stomach.h"
#include "string_formatter.h"
#include "text_snippets.h"
#include "translations.h"
#include "type_id.h"
#include "units.h"
#include "weather.h"
#include "weather_type.h"
static const addiction_id addiction_alcohol( "alcohol" );
static const addiction_id addiction_nicotine( "nicotine" );
static const bionic_id bio_dis_acid( "bio_dis_acid" );
static const bionic_id bio_dis_shock( "bio_dis_shock" );
static const bionic_id bio_geiger( "bio_geiger" );
static const bionic_id bio_gills( "bio_gills" );
static const bionic_id bio_power_weakness( "bio_power_weakness" );
static const bionic_id bio_radleak( "bio_radleak" );
static const bionic_id bio_sleep_shutdown( "bio_sleep_shutdown" );
static const efftype_id effect_adrenaline( "adrenaline" );
static const efftype_id effect_asthma( "asthma" );
static const efftype_id effect_bleed( "bleed" );
static const efftype_id effect_blind( "blind" );
static const efftype_id effect_cig( "cig" );
static const efftype_id effect_datura( "datura" );
static const efftype_id effect_deaf( "deaf" );
static const efftype_id effect_disabled( "disabled" );
static const efftype_id effect_downed( "downed" );
static const efftype_id effect_drunk( "drunk" );
static const efftype_id effect_fearparalyze( "fearparalyze" );
static const efftype_id effect_formication( "formication" );
static const efftype_id effect_grabbed( "grabbed" );
static const efftype_id effect_hallu( "hallu" );
static const efftype_id effect_incorporeal( "incorporeal" );
static const efftype_id effect_iodine( "iodine" );
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_onfire( "onfire" );
static const efftype_id effect_shakes( "shakes" );
static const efftype_id effect_sleep( "sleep" );
static const efftype_id effect_took_antiasthmatic( "took_antiasthmatic" );
static const efftype_id effect_took_thorazine( "took_thorazine" );
static const efftype_id effect_took_xanax( "took_xanax" );
static const efftype_id effect_valium( "valium" );
static const efftype_id effect_visuals( "visuals" );
static const efftype_id effect_weary_0( "weary_0" );
static const efftype_id effect_weary_1( "weary_1" );
static const efftype_id effect_weary_2( "weary_2" );
static const efftype_id effect_weary_3( "weary_3" );
static const efftype_id effect_weary_4( "weary_4" );
static const efftype_id effect_weary_5( "weary_5" );
static const efftype_id effect_weary_6( "weary_6" );
static const efftype_id effect_weary_7( "weary_7" );
static const efftype_id effect_weary_8( "weary_8" );
static const efftype_id effect_winded( "winded" );
static const itype_id itype_e_handcuffs( "e_handcuffs" );
static const itype_id itype_inhaler( "inhaler" );
static const itype_id itype_oxygen_tank( "oxygen_tank" );
static const itype_id itype_smoxygen_tank( "smoxygen_tank" );
static const json_character_flag json_flag_GILLS( "GILLS" );
static const json_character_flag json_flag_GLARE_RESIST( "GLARE_RESIST" );
static const json_character_flag json_flag_MEND_ALL( "MEND_ALL" );
static const json_character_flag json_flag_MEND_LIMB( "MEND_LIMB" );
static const json_character_flag json_flag_NYCTOPHOBIA( "NYCTOPHOBIA" );
static const json_character_flag json_flag_RAD_DETECT( "RAD_DETECT" );
static const mtype_id mon_zombie( "mon_zombie" );
static const mtype_id mon_zombie_cop( "mon_zombie_cop" );
static const mtype_id mon_zombie_fat( "mon_zombie_fat" );
static const mtype_id mon_zombie_fireman( "mon_zombie_fireman" );
static const mtype_id mon_zombie_soldier( "mon_zombie_soldier" );
static const trait_id trait_ADDICTIVE( "ADDICTIVE" );
static const trait_id trait_ALBINO( "ALBINO" );
static const trait_id trait_ASTHMA( "ASTHMA" );
static const trait_id trait_CHAOTIC( "CHAOTIC" );
static const trait_id trait_CHAOTIC_BAD( "CHAOTIC_BAD" );
static const trait_id trait_CHEMIMBALANCE( "CHEMIMBALANCE" );
static const trait_id trait_DEBUG_NOTEMP( "DEBUG_NOTEMP" );
static const trait_id trait_FRESHWATEROSMOSIS( "FRESHWATEROSMOSIS" );
static const trait_id trait_HAS_NEMESIS( "HAS_NEMESIS" );
static const trait_id trait_JITTERY( "JITTERY" );
static const trait_id trait_KILLER( "KILLER" );
static const trait_id trait_LEAVES( "LEAVES" );
static const trait_id trait_LEAVES2( "LEAVES2" );
static const trait_id trait_LEAVES3( "LEAVES3" );
static const trait_id trait_MOODSWINGS( "MOODSWINGS" );
static const trait_id trait_MUCUS_SECRETION( "MUCUS_SECRETION" );
static const trait_id trait_M_BLOSSOMS( "M_BLOSSOMS" );
static const trait_id trait_M_SPORES( "M_SPORES" );
static const trait_id trait_NARCOLEPTIC( "NARCOLEPTIC" );
static const trait_id trait_NONADDICTIVE( "NONADDICTIVE" );
static const trait_id trait_NOPAIN( "NOPAIN" );
static const trait_id trait_PAINREC1( "PAINREC1" );
static const trait_id trait_PAINREC2( "PAINREC2" );
static const trait_id trait_PAINREC3( "PAINREC3" );
static const trait_id trait_PER_SLIME( "PER_SLIME" );
static const trait_id trait_PYROMANIA( "PYROMANIA" );
static const trait_id trait_RADIOACTIVE1( "RADIOACTIVE1" );
static const trait_id trait_RADIOACTIVE2( "RADIOACTIVE2" );
static const trait_id trait_RADIOACTIVE3( "RADIOACTIVE3" );
static const trait_id trait_RADIOGENIC( "RADIOGENIC" );
static const trait_id trait_SCHIZOPHRENIC( "SCHIZOPHRENIC" );
static const trait_id trait_SHARKTEETH( "SHARKTEETH" );
static const trait_id trait_SHELL2( "SHELL2" );
static const trait_id trait_SHELL3( "SHELL3" );
static const trait_id trait_SHOUT1( "SHOUT1" );
static const trait_id trait_SHOUT2( "SHOUT2" );
static const trait_id trait_SHOUT3( "SHOUT3" );
static const trait_id trait_SNAIL_TRAIL( "SNAIL_TRAIL" );
static const trait_id trait_SORES( "SORES" );
static const trait_id trait_SUNBURN( "SUNBURN" );
static const trait_id trait_TROGLO( "TROGLO" );
static const trait_id trait_TROGLO2( "TROGLO2" );
static const trait_id trait_TROGLO3( "TROGLO3" );
static const trait_id trait_UNSTABLE( "UNSTABLE" );
static const trait_id trait_VOMITOUS( "VOMITOUS" );
static const trait_id trait_WEB_SPINNER( "WEB_SPINNER" );
static const trait_id trait_WEB_WEAVER( "WEB_WEAVER" );
static const trait_id trait_WINGS_INSECT( "WINGS_INSECT" );
static const vitamin_id vitamin_vitC( "vitC" );
namespace suffer
{
static void from_sunburn( Character &you, bool severe );
static void in_sunlight( Character &you );
static void water_damage( Character &you, const trait_id &mut_id );
static void mutation_power( Character &you, const trait_id &mut_id );
static void while_underwater( Character &you );
static void while_grabbed( Character &you );
static void from_addictions( Character &you );
static void while_awake( Character &you, int current_stim );
static void from_chemimbalance( Character &you );
static void from_schizophrenia( Character &you );
static void from_asthma( Character &you, int current_stim );
static void from_item_dropping( Character &you );
static void from_other_mutations( Character &you );
static void from_radiation( Character &you );
static void from_bad_bionics( Character &you );
static void from_stimulants( Character &you, int current_stim );
static void from_exertion( Character &you );
static void without_sleep( Character &you, int sleep_deprivation );
static void from_tourniquet( Character &you );
static void from_pain( Character &you );
static void from_nyctophobia( Character &you );
} // namespace suffer
static float addiction_scaling( float at_min, float at_max, float add_lvl )
{
// Not addicted
if( add_lvl < MIN_ADDICTION_LEVEL ) {
return 1.0f;
}
return lerp( at_min, at_max, ( add_lvl - MIN_ADDICTION_LEVEL ) / MAX_ADDICTION_LEVEL );
}
void suffer::water_damage( Character &you, const trait_id &mut_id )
{
for( const std::pair<const bodypart_str_id, bodypart> &elem : you.get_body() ) {
const float wetness_percentage = elem.second.get_wetness_percentage();
const int dmg = mut_id->weakness_to_water * wetness_percentage;
if( dmg > 0 ) {
you.apply_damage( nullptr, elem.first, dmg );
you.add_msg_player_or_npc( m_bad, _( "Your %s is damaged by the water." ),
_( "<npcname>'s %s is damaged by the water." ),
body_part_name( elem.first ) );
} else if( dmg < 0 && elem.second.is_at_max_hp() ) {
you.heal( elem.first, std::abs( dmg ) );
you.add_msg_player_or_npc( m_good, _( "Your %s is healed by the water." ),
_( "<npcname>'s %s is healed by the water." ),
body_part_name( elem.first ) );
}
}
}
void suffer::mutation_power( Character &you, const trait_id &mut_id )
{
if( you.get_cost_timer( mut_id ) > 0_turns ) {
// Not ready to consume cost yet, the timer ticks on
you.mod_cost_timer( mut_id, -1_turns );
} else {
// Ready to consume cost: pay the power cost and reset timer
if( mut_id->cooldown > 0_turns ) {
you.set_cost_timer( mut_id, mut_id->cooldown - 1_turns );
}
if( mut_id->hunger ) {
if( you.get_bmi() < character_weight_category::underweight ) {
you.add_msg_if_player( m_warning,
_( "You're too malnourished to keep your %s going." ),
you.mutation_name( mut_id ) );
you.deactivate_mutation( mut_id );
} else {
// does not directly modify hunger, but burns kcal
you.mod_stored_kcal( -mut_id->cost );
}
}
if( mut_id->thirst ) {
// Well into Dehydrated
if( you.get_thirst() >= 260 ) {
you.add_msg_if_player( m_warning,
_( "You're too dehydrated to keep your %s going." ),
you.mutation_name( mut_id ) );
you.deactivate_mutation( mut_id );
} else {
you.mod_thirst( mut_id->cost );
}
}
if( mut_id->fatigue ) {
// Exhausted
if( you.get_fatigue() >= fatigue_levels::EXHAUSTED ) {
you.add_msg_if_player( m_warning,
_( "You're too exhausted to keep your %s going." ),
you.mutation_name( mut_id ) );
you.deactivate_mutation( mut_id );
} else {
you.mod_fatigue( mut_id->cost );
}
}
}
}
void suffer::while_underwater( Character &you )
{
if( !you.has_flag( json_flag_GILLS ) ) {
you.oxygen--;
}
if( you.oxygen < 12 && you.worn_with_flag( flag_REBREATHER ) ) {
you.oxygen += 12;
}
if( you.oxygen <= 5 ) {
if( you.has_bionic( bio_gills ) && you.get_power_level() >= bio_gills->power_trigger ) {
you.oxygen += 5;
you.mod_power_level( -bio_gills->power_trigger );
} else {
you.add_msg_if_player( m_bad, _( "You're drowning!" ) );
you.apply_damage( nullptr, bodypart_id( "torso" ), rng( 1, 4 ) );
}
}
if( you.has_trait( trait_FRESHWATEROSMOSIS ) &&
!get_map().has_flag_ter( ter_furn_flag::TFLAG_SALT_WATER, you.pos() ) &&
you.get_thirst() > -60 ) {
you.mod_thirst( -1 );
}
}
void suffer::while_grabbed( Character &you )
{
// get the intensity of the current grab
int grab_intensity = you.get_effect_int( effect_grabbed, body_part_torso );
// you should have trouble breathing as you get swarmed by zombies grabbing you
if( grab_intensity <= 2 ) {
// only a chance to lose breath at low grab chance
you.oxygen -= rng( 0, 1 );
} else if( grab_intensity <= 4 ) {
you.oxygen -= 1;
} else if( grab_intensity <= 6 ) {
you.oxygen -= rng( 1, 2 );
} else if( grab_intensity <= 8 ) {
you.oxygen -= 2;
}
// a few warnings before starting to take damage
if( you.oxygen <= 5 ) {
you.add_msg_if_player( m_bad, _( "You're suffocating!" ) );
// your characters chest is being crushed and you are dying
you.apply_damage( nullptr, bodypart_id( "torso" ), rng( 1, 4 ) );
} else if( you.oxygen <= 15 ) {
you.add_msg_if_player( m_bad, _( "You can't breathe with all this weight!" ) );
} else if( you.oxygen <= 25 ) {
you.add_msg_if_player( m_bad, _( "You're having difficulty breathing!" ) );
}
}
void suffer::from_addictions( Character &you )
{
time_duration timer = -6_hours;
if( you.has_trait( trait_ADDICTIVE ) ) {
timer = -10_hours;
} else if( you.has_trait( trait_NONADDICTIVE ) ) {
timer = -3_hours;
}
for( addiction &cur_addiction : you.addictions ) {
if( cur_addiction.sated <= 0_turns &&
cur_addiction.intensity >= MIN_ADDICTION_LEVEL ) {
cur_addiction.run_effect( you );
}
cur_addiction.sated -= 1_turns;
// Higher intensity addictions heal faster
if( cur_addiction.sated - 10_minutes * cur_addiction.intensity < timer ) {
if( cur_addiction.intensity <= 2 ) {
you.rem_addiction( cur_addiction.type );
break;
} else {
cur_addiction.intensity--;
cur_addiction.sated = 0_turns;
}
}
}
}
void suffer::while_awake( Character &you, const int current_stim )
{
if( you.weight_carried() > 4 * you.weight_capacity() ) {
if( you.has_effect( effect_downed ) ) {
you.add_effect( effect_downed, 1_turns, false, 0, true );
} else {
you.add_effect( effect_downed, 2_turns, false, 0, true );
}
}
if( you.has_flag( json_flag_NYCTOPHOBIA ) && !you.has_effect( effect_took_xanax ) ) {
suffer::from_nyctophobia( you );
}
if( you.has_trait( trait_CHEMIMBALANCE ) ) {
suffer::from_chemimbalance( you );
}
if( you.has_trait( trait_SCHIZOPHRENIC ) &&
!you.has_effect( effect_took_thorazine ) ) {
suffer::from_schizophrenia( you );
}
if( you.has_trait( trait_NARCOLEPTIC ) ) {
if( one_turn_in( 8_hours ) ) {
you.add_msg_if_player( m_bad,
_( "You're suddenly overcome with the urge to sleep and you pass out." ) );
you.fall_asleep( 20_minutes );
}
}
if( you.has_trait( trait_JITTERY ) && !you.has_effect( effect_shakes ) ) {
if( current_stim > 50 && one_in( to_turns<int>( 30_minutes ) - ( current_stim * 6 ) ) ) {
you.add_effect( effect_shakes, 30_minutes + 1_turns * current_stim );
} else if( ( you.get_hunger() > 80 || you.get_kcal_percent() < 1.0f ) && you.get_hunger() > 0 &&
one_in( to_turns<int>( 50_minutes ) - ( you.get_hunger() * 6 ) ) ) {
you.add_effect( effect_shakes, 40_minutes );
}
}
if( you.has_trait( trait_MOODSWINGS ) && one_turn_in( 6_hours ) ) {
if( rng( 1, 20 ) > 9 ) {
// 55% chance
you.add_morale( MORALE_MOODSWING, -20, -100 );
} else {
// 45% chance
you.add_morale( MORALE_MOODSWING, 20, 100 );
}
}
if( you.has_trait( trait_VOMITOUS ) && one_turn_in( 7_hours ) ) {
you.vomit();
}
if( you.has_trait( trait_HAS_NEMESIS ) && one_turn_in( 2_minutes ) ) {
you.signal_nemesis();
}
if( you.has_trait( trait_SHOUT1 ) && one_turn_in( 6_hours ) ) {
you.shout();
}
if( you.has_trait( trait_SHOUT2 ) && one_turn_in( 4_hours ) ) {
you.shout();
}
if( you.has_trait( trait_SHOUT3 ) && one_turn_in( 3_hours ) ) {
you.shout();
}
if( you.has_trait( trait_M_SPORES ) && one_turn_in( 4_hours ) ) {
you.spores();
}
if( you.has_trait( trait_M_BLOSSOMS ) && one_turn_in( 3_hours ) ) {
you.blossoms();
}
}
void suffer::from_chemimbalance( Character &you )
{
if( one_turn_in( 6_hours ) && !you.has_trait( trait_NOPAIN ) ) {
you.add_msg_if_player( m_bad, _( "You suddenly feel sharp pain for no reason." ) );
you.mod_pain( 3 * rng( 1, 3 ) );
}
if( one_turn_in( 6_hours ) ) {
int pkilladd = 5 * rng( -1, 2 );
if( pkilladd > 0 ) {
you.add_msg_if_player( m_bad, _( "You suddenly feel numb." ) );
} else if( ( pkilladd < 0 ) && ( !you.has_trait( trait_NOPAIN ) ) ) {
you.add_msg_if_player( m_bad, _( "You suddenly ache." ) );
}
you.mod_painkiller( pkilladd );
}
if( one_turn_in( 6_hours ) && !you.has_effect( effect_sleep ) ) {
you.add_msg_if_player( m_bad, _( "You feel dizzy for a moment." ) );
you.moves -= rng( 10, 30 );
}
if( one_turn_in( 6_hours ) ) {
int hungadd = 5 * rng( -1, 3 );
if( hungadd > 0 ) {
you.add_msg_if_player( m_bad, _( "You suddenly feel hungry." ) );
} else {
you.add_msg_if_player( m_good, _( "You suddenly feel a little full." ) );
}
you.mod_hunger( hungadd );
}
if( one_turn_in( 6_hours ) ) {
you.add_msg_if_player( m_bad, _( "You suddenly feel thirsty." ) );
you.mod_thirst( 5 * rng( 1, 3 ) );
}
if( one_turn_in( 6_hours ) ) {
you.add_msg_if_player( m_good, _( "You feel fatigued all of a sudden." ) );
you.mod_fatigue( 10 * rng( 2, 4 ) );
}
if( one_turn_in( 8_hours ) ) {
if( one_in( 3 ) ) {
you.add_morale( MORALE_FEELING_GOOD, 20, 100 );
} else {
you.add_morale( MORALE_FEELING_BAD, -20, -100 );
}
}
if( one_turn_in( 6_hours ) ) {
if( one_in( 3 ) ) {
you.add_msg_if_player( m_bad, _( "You suddenly feel very cold." ) );
you.set_all_parts_temp_cur( BODYTEMP_VERY_COLD );
} else {
you.add_msg_if_player( m_bad, _( "You suddenly feel cold." ) );
you.set_all_parts_temp_cur( BODYTEMP_COLD );
}
}
if( one_turn_in( 6_hours ) ) {
if( one_in( 3 ) ) {
you.add_msg_if_player( m_bad, _( "You suddenly feel very hot." ) );
you.set_all_parts_temp_cur( BODYTEMP_VERY_HOT );
} else {
you.add_msg_if_player( m_bad, _( "You suddenly feel hot." ) );
you.set_all_parts_temp_cur( BODYTEMP_HOT );
}
}
}
void suffer::from_schizophrenia( Character &you )
{
std::string i_name_w;
item_location weap = you.get_wielded_item();
if( weap ) {
i_name_w = weap->has_var( "item_label" ) ?
weap->get_var( "item_label" ) :
//~ %1$s: weapon name
string_format( _( "your %1$s" ), weap->type_name() );
}
// Start with the effects that both NPCs and avatars can suffer from
// Delusions
if( one_turn_in( 8_hours ) ) {
if( rng( 1, 20 ) > 5 ) { // 75% chance
const translation snip = SNIPPET.random_from_category( "schizo_delusion_paranoid" ).value_or(
translation() );
you.add_msg_if_player( m_warning, "%s", snip );
you.add_morale( MORALE_FEELING_BAD, -20, -100 );
} else { // 25% chance
const translation snip = SNIPPET.random_from_category( "schizo_delusion_grandiose" ).value_or(
translation() );
you.add_msg_if_player( m_good, "%s", snip );
you.add_morale( MORALE_FEELING_GOOD, 20, 100 );
}
return;
}
// Formication
if( one_turn_in( 6_hours ) ) {
const translation snip = SNIPPET.random_from_category( "schizo_formication" ).value_or(
translation() );
const bodypart_id &bp = you.random_body_part( true );
you.add_effect( effect_formication, 45_minutes, bp );
you.add_msg_if_player( m_bad, "%s", snip );
return;
}
// Numbness
if( one_turn_in( 4_hours ) ) {
you.add_msg_if_player( m_bad, _( "You suddenly feel so numb…" ) );
you.mod_painkiller( 25 );
return;
}
// Hallucination
if( one_turn_in( 6_hours ) ) {
you.add_effect( effect_hallu, 6_hours );
return;
}
// Visuals
if( one_turn_in( 2_hours ) ) {
you.add_effect( effect_visuals, rng( 15_turns, 60_turns ) );
return;
}
// Shaking
if( !you.has_effect( effect_valium ) && one_turn_in( 4_hours ) ) {
you.add_msg_player_or_npc( m_bad, _( "You start to shake uncontrollably." ),
_( "<npcname> starts to shake uncontrollably." ) );
you.add_effect( effect_shakes, rng( 2_minutes, 5_minutes ) );
return;
}
// Shout
if( one_turn_in( 4_hours ) ) {
you.shout( SNIPPET.random_from_category( "schizo_self_shout" ).value_or(
translation() ).translated() );
return;
}
// Drop weapon
if( one_turn_in( 2_days ) && weap ) {
const translation snip = SNIPPET.random_from_category( "schizo_weapon_drop" ).value_or(
translation() );
you.add_msg_if_player( m_bad, "%s", uppercase_first_letter( string_format( snip, i_name_w ) ) );
you.drop( weap, you.pos() );
return;
}
// Talk to self
if( one_turn_in( 4_hours ) ) {
const translation snip = SNIPPET.random_from_category( "schizo_self_talk" ).value_or(
translation() );
you.add_msg_if_player( _( "%1$s says: \"%2$s\"" ), you.get_name(), snip );
return;
}
// effects of this point are entirely internal, so NPCs can't suffer from them
if( you.is_npc() ) {
return;
}
// Sound
if( one_turn_in( 4_hours ) ) {
you.sound_hallu();
}
// Follower turns hostile
if( one_turn_in( 4_hours ) ) {
std::vector<shared_ptr_fast<npc>> followers = overmap_buffer.get_npcs_near_player( 12 );
std::string who_gets_angry = you.get_name();
if( !followers.empty() ) {
who_gets_angry = random_entry_ref( followers )->get_name();
}
you.add_msg_if_player( m_bad, _( "%1$s gets angry!" ), who_gets_angry );
return;
}
// Monster dies
if( one_turn_in( 6_hours ) ) {
// TODO: move to monster group json
static const std::array<mtype_id, 5> monsters = { {
mon_zombie, mon_zombie_fat, mon_zombie_fireman, mon_zombie_cop, mon_zombie_soldier
}
};
you.add_msg_if_player( _( "%s dies!" ), random_entry_ref( monsters )->nname() );
return;
}
// Limb Breaks
if( one_turn_in( 4_hours ) ) {
const translation snip = SNIPPET.random_from_category( "broken_limb" ).value_or( translation() );
you.add_msg_if_player( m_bad, "%s", snip );
return;
}
// NPC chat
if( one_turn_in( 4_hours ) ) {
std::string i_name = Name::generate( one_in( 2 ) );
std::string i_talk = SNIPPET.expand( SNIPPET.random_from_category( "<lets_talk>" ).value_or(
translation() ).translated() );
parse_tags( i_talk, you, you );
you.add_msg_if_player( _( "%1$s says: \"%2$s\"" ), i_name, i_talk );
return;
}
// Skill raise
if( one_turn_in( 12_hours ) ) {
const skill_id raised_skill = Skill::random_skill();
const SkillLevel level = you.get_all_skills().get_skill_level_object( raised_skill );
if( level.level() == level.knowledgeLevel() && one_in( 2 ) ) {
you.add_msg_if_player( m_good, _( "Your practical skill in %s has increased to %d!" ),
raised_skill->name(), level.level() + 1 );
}
you.add_msg_if_player( m_good, _( "Your theoretical understanding of %s has increased to %d!" ),
raised_skill->name(), level.knowledgeLevel() + 1 );
return;
}
// Talking weapon
if( weap ) {
// If player has a weapon, picks a message from said weapon
// Weapon tells player to kill a monster if any are nearby
// Weapon is concerned for player if bleeding
// Weapon is concerned for itself if damaged
// Otherwise random chit-chat
std::vector<weak_ptr_fast<monster>> mons = g->all_monsters().items;
std::string i_talk_w;
bool does_talk = false;
if( !mons.empty() && one_turn_in( 12_minutes ) ) {
std::vector<std::string> seen_mons;
for( weak_ptr_fast<monster> &n : mons ) {
if( you.sees( *n.lock() ) ) {
seen_mons.emplace_back( n.lock()->get_name() );
}
}
if( !seen_mons.empty() ) {
const translation talk_w = SNIPPET.random_from_category( "schizo_weapon_talk_monster" ).value_or(
translation() );
i_talk_w = string_format( talk_w, random_entry_ref( seen_mons ) );
does_talk = true;
}
}
if( !does_talk && you.has_effect( effect_bleed ) && one_turn_in( 5_minutes ) ) {
i_talk_w = SNIPPET.random_from_category( "schizo_weapon_talk_bleeding" ).value_or(
translation() ).translated();
does_talk = true;
} else if( weap->damage() >= ( weap->max_damage() - weap->damage_floor( false ) ) / 3 +
weap->damage_floor( false ) && one_turn_in( 1_hours ) ) {
i_talk_w = SNIPPET.random_from_category( "schizo_weapon_talk_damaged" ).value_or(
translation() ).translated();
does_talk = true;
} else if( one_turn_in( 4_hours ) ) {
i_talk_w = SNIPPET.random_from_category( "schizo_weapon_talk_misc" ).value_or(
translation() ).translated();
does_talk = true;
}
if( does_talk ) {
add_msg( _( "%1$s says: \"%2$s\"" ), i_name_w, i_talk_w );
return;
}
}
}
void suffer::from_asthma( Character &you, const int current_stim )
{
if( you.has_effect( effect_adrenaline ) ||
you.has_effect( effect_datura ) ||
you.has_effect( effect_took_antiasthmatic ) ) {
return;
}
//cap asthma attacks to 1 per minute (or risk instantly killing players that rely on oxygen tanks)
if( !one_in( std::max( to_turns<int>( 1_minutes ),
( to_turns<int>( 6_hours ) - current_stim * 300 ) ) *
( you.has_effect( effect_sleep ) ? 10 : 1 ) ) ) {
return;
}
bool auto_use = you.has_charges( itype_inhaler, 1 ) || you.has_charges( itype_oxygen_tank, 1 ) ||
you.has_charges( itype_smoxygen_tank, 1 );
bool oxygenator = you.has_bionic( bio_gills ) &&
you.get_power_level() >= ( bio_gills->power_trigger / 8 );
if( you.underwater ) {
you.oxygen = you.oxygen / 2;
auto_use = false;
}
you.add_msg_player_or_npc( m_bad, _( "You have an asthma attack!" ),
"<npcname> starts wheezing and coughing." );
map &here = get_map();
if( you.in_sleep_state() && !you.has_effect( effect_narcosis ) ) {
inventory map_inv;
map_inv.form_from_map( you.pos(), 2, &you );
// check if an inhaler is somewhere near
bool nearby_use = auto_use || oxygenator || map_inv.has_charges( itype_inhaler, 1 ) ||
map_inv.has_charges( itype_oxygen_tank, 1 ) ||
map_inv.has_charges( itype_smoxygen_tank, 1 );
// check if character has an oxygenator first
if( oxygenator ) {
you.mod_power_level( -bio_gills->power_trigger / 8 );
you.add_msg_if_player( m_info, _( "You use your Oxygenator to clear it up, "
"then go back to sleep." ) );
} else if( auto_use && !you.has_bionic( bio_sleep_shutdown ) ) {
if( you.use_charges_if_avail( itype_inhaler, 1 ) ) {
you.add_msg_if_player( m_info, _( "You use your inhaler and go back to sleep." ) );
you.add_effect( effect_took_antiasthmatic, rng( 6_hours, 12_hours ) );
} else if( you.use_charges_if_avail( itype_oxygen_tank, 1 ) ||
you.use_charges_if_avail( itype_smoxygen_tank, 1 ) ) {
you.add_msg_if_player( m_info, _( "You take a deep breath from your oxygen tank "
"and go back to sleep." ) );
}
} else if( nearby_use && !you.has_bionic( bio_sleep_shutdown ) ) {
// create new variable to resolve a reference issue
int amount = 1;
if( !here.use_charges( you.pos(), 2, itype_inhaler, amount ).empty() ) {
you.add_msg_if_player( m_info, _( "You use your inhaler and go back to sleep." ) );
you.add_effect( effect_took_antiasthmatic, rng( 6_hours, 12_hours ) );
} else if( !here.use_charges( you.pos(), 2, itype_oxygen_tank, amount ).empty() ||
!here.use_charges( you.pos(), 2, itype_smoxygen_tank, amount ).empty() ) {
you.add_msg_if_player( m_info, _( "You take a deep breath from your oxygen tank "
"and go back to sleep." ) );
}
} else {
you.add_effect( effect_asthma, rng( 5_minutes, 20_minutes ) );
if( you.has_effect( effect_sleep ) ) {
if( !you.has_bionic( bio_sleep_shutdown ) ) {
you.wake_up();
}
} else {
if( uistate.distraction_asthma && !you.is_npc() ) {
g->cancel_activity_or_ignore_query( distraction_type::asthma,
_( "You can't focus while choking!" ) );
}
}
}
} else if( auto_use ) {
int charges = 0;
if( you.use_charges_if_avail( itype_inhaler, 1 ) ) {
you.moves -= 40;
charges = you.charges_of( itype_inhaler );
if( charges == 0 ) {
you.add_msg_if_player( m_bad, _( "You use your last inhaler charge." ) );
} else {
you.add_msg_if_player( m_info, n_gettext( "You use your inhaler; "
"only %d charge left.",
"You use your inhaler; "
"only %d charges left.", charges ),
charges );
}
you.add_effect( effect_took_antiasthmatic, rng( 6_hours, 12_hours ) );
} else if( you.use_charges_if_avail( itype_oxygen_tank, 1 ) ||
you.use_charges_if_avail( itype_smoxygen_tank, 1 ) ) {
you.moves -= 500; // synched with use action
charges = you.charges_of( itype_oxygen_tank ) + you.charges_of( itype_smoxygen_tank );
if( charges == 0 ) {
you.add_msg_if_player( m_bad, _( "You breathe in the last bit of oxygen "
"from the tank." ) );
} else {
you.add_msg_if_player( m_info, n_gettext( "You take a deep breath from your oxygen "
"tank; only %d charge left.",
"You take a deep breath from your oxygen "
"tank; only %d charges left.", charges ),
charges );
}
}
} else {
you.add_effect( effect_asthma, rng( 5_minutes, 20_minutes ) );
if( uistate.distraction_asthma && !you.is_npc() ) {
g->cancel_activity_or_ignore_query( distraction_type::asthma,
_( "You can't focus while choking!" ) );
}
}
}
void suffer::in_sunlight( Character &you )
{
const tripoint position = you.pos();
if( !g->is_in_sunlight( position ) ) {
return;
}
const bool leafy = you.has_trait( trait_LEAVES ) ||
you.has_trait( trait_LEAVES2 ) ||
you.has_trait( trait_LEAVES3 );
int sunlight_nutrition = 0;
if( leafy ) {
const bool leafier = you.has_trait( trait_LEAVES2 );
const bool leafiest = you.has_trait( trait_LEAVES3 );
const double sleeve_factor = you.armwear_factor();
const bool has_hat = you.wearing_something_on( bodypart_id( "head" ) );
const float weather_factor = ( get_weather().weather_id->sun_intensity >=
sun_intensity_type::normal ) ? 1.0 : 0.5;
const int player_local_temp = units::to_fahrenheit( get_weather().get_temperature( position ) );
const int flux = ( player_local_temp - 65 ) / 2;
if( !has_hat ) {
sunlight_nutrition += ( 100 + flux ) * weather_factor;
}
if( leafier || leafiest ) {
const int rate = ( 100 * sleeve_factor + flux ) * 2;
sunlight_nutrition += rate * ( leafiest ? 2 : 1 ) * weather_factor;
}
}
if( x_in_y( sunlight_nutrition, 18000 ) ) {
you.vitamin_mod( vitamin_vitC, 1 );
}
if( you.has_trait( trait_SUNBURN ) ) {
suffer::from_sunburn( you, true );
}
// Albinism and datura have the same effects and do not stack with each other or sunburn.
if( !you.has_trait( trait_SUNBURN ) &&
( you.has_trait( trait_ALBINO ) || you.has_effect( effect_datura ) ) ) {
suffer::from_sunburn( you, false );
}
if( ( you.has_trait( trait_TROGLO ) || you.has_trait( trait_TROGLO2 ) ) &&
get_weather().weather_id->sun_intensity >= sun_intensity_type::high ) {
you.mod_str_bonus( -1 );
you.mod_dex_bonus( -1 );
you.add_miss_reason( _( "The sunlight distracts you." ), 1 );
you.mod_int_bonus( -1 );
you.mod_per_bonus( -1 );
}
if( you.has_trait( trait_TROGLO2 ) ) {
you.mod_str_bonus( -1 );
you.mod_dex_bonus( -1 );
you.add_miss_reason( _( "The sunlight distracts you." ), 1 );
you.mod_int_bonus( -1 );
you.mod_per_bonus( -1 );
}
if( you.has_trait( trait_TROGLO3 ) ) {
you.mod_str_bonus( -4 );
you.mod_dex_bonus( -4 );
you.add_miss_reason( _( "You can't stand the sunlight!" ), 4 );
you.mod_int_bonus( -4 );
you.mod_per_bonus( -4 );
}
}
std::map<bodypart_id, float> Character::bodypart_exposure()
{
std::map<bodypart_id, float> bp_exposure;
// May need to iterate over all body parts several times, so make a copy
const std::vector<bodypart_id> all_body_parts = get_all_body_parts();
// Initially, all parts are assumed to be fully exposed
for( const bodypart_id &bp : all_body_parts ) {
bp_exposure[bp] = 1.0f;
}
// For every item worn, for every body part, adjust coverage
worn.bodypart_exposure( bp_exposure, all_body_parts );
return bp_exposure;
}
// Linear interpolation between start and end values.
// Constant outside of interval (x_start; x_end)
static float linear_interpolation( float x_start, float y_start, float x_end, float y_end, float x )
{
if( x < x_start ) {
return y_start;
}
if( x > x_end ) {
return y_end;
}
float interval = x_end - x_start;
float perc_to_end = ( x - x_start ) / interval;
return ( 1 - perc_to_end ) * y_start + perc_to_end * y_end;
}
static float light_eff_chance( float exp )
{
// Sharp increase until 5%
return linear_interpolation( 0.01, 0.0, 0.05, 1.0, exp );
}
static float medium_eff_chance( float exp )
{
// Starts at 5%, peaks at 30%
return linear_interpolation( 0.05, 0.0, 0.55, 0.25, exp );
}
static float heavy_eff_chance( float exp )
{
// Starts at 15%, increases to 0.1 at 100%
return linear_interpolation( 0.15, 0.0, 1.0, 0.1, exp );
}
void suffer::from_sunburn( Character &you, bool severe )
{
// Sunburn effects and albinism/datura occur about once per minute
if( !one_turn_in( 1_minutes ) ) {
return;
}
// TODO: Could factor bodypart_exposure out of Character too
std::map<bodypart_id, float> bp_exposure = you.bodypart_exposure();
enum Sunburn { None, Focus_Loss, Pain, Damage };
auto heavy_sunburn = [severe, &you]( bodypart_id bp ) {
if( severe ) {
// Because hands and feet share an HP pool with arms and legs, and the mouth shares
// an HP pool with the head, those parts take an unfair share of damage in relation
// to the torso, which only has one part. Increase torso damage to balance this.
if( bp == bodypart_id( "torso" ) ) {
you.apply_damage( nullptr, bp, 2 );
} else {
you.apply_damage( nullptr, bp, 1 );
}
return Damage;
} else {
you.mod_pain( 1 );
return Pain;
}
};
auto medium_sunburn = [severe, &you] {
if( severe )
{
you.mod_pain( 1 );
return Pain;
} else
{
you.mod_focus( -1 );
return Focus_Loss;
}
};
auto light_sunburn = [severe, &you] {
if( severe )
{
you.mod_focus( -1 );
return Focus_Loss;
} else
{
return None;
}
};
// Track body parts above the threshold
std::map<bodypart_id, Sunburn> affected_bodyparts;
for( auto &bp_exp : bp_exposure ) {
bodypart_id bp = bp_exp.first;
float exposure = bp_exp.second;
if( bp == bodypart_id( "eyes" ) ) {
// Sunglasses can keep the sun off the eyes.
if( you.has_flag( json_flag_GLARE_RESIST )
|| you.worn_with_flag( flag_SUN_GLASSES )
|| you.worn_with_flag( flag_BLIND ) ) {
continue;
}
// If no UV-/glare-protection gear is worn the eyes should be treated as unprotected
exposure = 1.0;
} else if( ( you.get_wielded_item() && you.get_wielded_item()->has_flag( flag_RAIN_PROTECT ) )
|| ( ( bp == body_part_hand_l || bp == body_part_hand_r )
&& you.worn_with_flag( flag_POCKETS )
&& you.can_use_pockets() )
|| ( bp == body_part_head
&& you.worn_with_flag( flag_HOOD )
&& you.can_use_hood() )
|| ( bp == body_part_mouth
&& you.worn_with_flag( flag_COLLAR )
&& you.can_use_collar() ) ) {
// Eyes suffer even in the presence of the checks in this branch!
// Umbrellas can keep the sun off all bodyparts
// Pockets can keep the sun off your hands if you don't wield a too large item
// Hoods can keep the sun off your unencumbered head
// Collars can keep the sun off your unencumbered mouth
continue;
}