forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
suffer.cpp
1948 lines (1778 loc) · 74.2 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 <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <list>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#include "addiction.h"
#include "avatar.h"
#include "bionics.h"
#include "bodypart.h"
#include "calendar.h"
#include "cata_utility.h"
#include "character.h"
#include "effect.h"
#include "enums.h"
#include "event.h"
#include "event_bus.h"
#include "field_type.h"
#include "game.h"
#include "game_constants.h"
#include "int_id.h"
#include "inventory.h"
#include "item.h"
#include "item_location.h"
#include "magic_enchantment.h"
#include "map.h"
#include "messages.h"
#include "monster.h"
#include "morale_types.h"
#include "mtype.h"
#include "mutation.h"
#include "name.h"
#include "npc.h"
#include "options.h"
#include "overmapbuffer.h"
#include "pldata.h"
#include "point.h"
#include "rng.h"
#include "skill.h"
#include "sounds.h"
#include "stomach.h"
#include "string_formatter.h"
#include "string_id.h"
#include "teleport.h"
#include "text_snippets.h"
#include "translations.h"
#include "type_id.h"
#include "units.h"
#include "weather.h"
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_drain( "bio_drain" );
static const bionic_id bio_geiger( "bio_geiger" );
static const bionic_id bio_gills( "bio_gills" );
static const bionic_id bio_glowy( "bio_glowy" );
static const bionic_id bio_itchy( "bio_itchy" );
static const bionic_id bio_leaky( "bio_leaky" );
static const bionic_id bio_noise( "bio_noise" );
static const bionic_id bio_power_weakness( "bio_power_weakness" );
static const bionic_id bio_reactor( "bio_reactor" );
static const bionic_id bio_advreactor( "bio_advreactor" );
static const bionic_id bio_reactoroverride( "bio_reactoroverride" );
static const bionic_id bio_shakes( "bio_shakes" );
static const bionic_id bio_sleepy( "bio_sleepy" );
static const bionic_id bio_spasm( "bio_spasm" );
static const bionic_id bio_sunglasses( "bio_sunglasses" );
static const bionic_id bio_trip( "bio_trip" );
static const efftype_id effect_accumulated_mutagen( "accumulated_mutagen" );
static const efftype_id effect_adrenaline( "adrenaline" );
static const efftype_id effect_asthma( "asthma" );
static const efftype_id effect_attention( "attention" );
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_formication( "formication" );
static const efftype_id effect_glowy_led( "glowy_led" );
static const efftype_id effect_hallu( "hallu" );
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_meth( "meth" );
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_stunned( "stunned" );
static const efftype_id effect_took_antiasthmatic( "took_antiasthmatic" );
static const efftype_id effect_took_thorazine( "took_thorazine" );
static const efftype_id effect_valium( "valium" );
static const efftype_id effect_visuals( "visuals" );
static const itype_id itype_e_handcuffs( "e_handcuffs" );
static const itype_id itype_inhaler( "inhaler" );
static const itype_id itype_smoxygen_tank( "smoxygen_tank" );
static const itype_id itype_oxygen_tank( "oxygen_tank" );
static const itype_id itype_rad_badge( "rad_badge" );
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_DEBUG_STORAGE( "DEBUG_STORAGE" );
static const trait_id trait_FRESHWATEROSMOSIS( "FRESHWATEROSMOSIS" );
static const trait_id trait_GILLS( "GILLS" );
static const trait_id trait_GILLS_CEPH( "GILLS_CEPH" );
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_M_BLOSSOMS( "M_BLOSSOMS" );
static const trait_id trait_M_SPORES( "M_SPORES" );
static const trait_id trait_MOODSWINGS( "MOODSWINGS" );
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_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_REGEN_LIZ( "REGEN_LIZ" );
static const trait_id trait_ROOTS3( "ROOTS3" );
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_SHOUT1( "SHOUT1" );
static const trait_id trait_SHOUT2( "SHOUT2" );
static const trait_id trait_SHOUT3( "SHOUT3" );
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 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 std::string flag_BLIND( "BLIND" );
static const std::string flag_PLOWABLE( "PLOWABLE" );
static const std::string flag_RAD_RESIST( "RAD_RESIST" );
static const std::string flag_SPLINT( "SPLINT" );
static const std::string flag_SUN_GLASSES( "SUN_GLASSES" );
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 Character::suffer_water_damage( const mutation_branch &mdata )
{
for( const std::pair<const bodypart_str_id, bodypart> &elem : get_body() ) {
const float wetness_percentage = static_cast<float>( body_wetness[elem.first->token] ) /
drench_capacity[elem.first->token];
const int dmg = mdata.weakness_to_water * wetness_percentage;
if( dmg > 0 ) {
apply_damage( nullptr, elem.first, dmg );
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() ) {
heal( elem.first, std::abs( dmg ) );
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 Character::suffer_mutation_power( const mutation_branch &mdata, char_trait_data &tdata )
{
if( tdata.powered && tdata.charge > 0 ) {
// Already-on units just lose a bit of charge
tdata.charge--;
} else {
// Not-on units, or those with zero charge, have to pay the power cost
if( mdata.cooldown > 0 ) {
tdata.powered = true;
tdata.charge = mdata.cooldown - 1;
}
if( mdata.hunger ) {
// does not directly modify hunger, but burns kcal
mod_stored_nutr( mdata.cost );
if( bmi() < character_weight_category::underweight ) {
add_msg_if_player( m_warning,
_( "You're too malnourished to keep your %s going." ),
mdata.name() );
tdata.powered = false;
}
}
if( mdata.thirst ) {
mod_thirst( mdata.cost );
// Well into Dehydrated
if( get_thirst() >= thirst_levels::dehydrated ) {
add_msg_if_player( m_warning,
_( "You're too dehydrated to keep your %s going." ),
mdata.name() );
tdata.powered = false;
}
}
if( mdata.fatigue ) {
mod_fatigue( mdata.cost );
// Exhausted
if( get_fatigue() >= fatigue_levels::exhausted ) {
add_msg_if_player( m_warning,
_( "You're too exhausted to keep your %s going." ),
mdata.name() );
tdata.powered = false;
}
}
if( !tdata.powered ) {
apply_mods( mdata.id, false );
}
}
}
void Character::suffer_while_underwater()
{
if( !has_trait( trait_GILLS ) && !has_trait( trait_GILLS_CEPH ) ) {
oxygen--;
}
if( oxygen < 12 && worn_with_flag( "REBREATHER" ) ) {
oxygen += 12;
}
if( oxygen <= 5 ) {
if( has_bionic( bio_gills ) && get_power_level() >= bio_gills->power_trigger ) {
oxygen += 5;
mod_power_level( -bio_gills->power_trigger );
} else {
add_msg_if_player( m_bad, _( "You're drowning!" ) );
apply_damage( nullptr, bodypart_id( "torso" ), rng( 1, 4 ) );
}
}
if( has_trait( trait_FRESHWATEROSMOSIS ) && !get_map().has_flag_ter( "SALT_WATER", pos() ) &&
get_thirst() > thirst_levels::turgid ) {
mod_thirst( -1 );
}
}
void Character::suffer_from_addictions()
{
time_duration timer = -6_hours;
if( has_trait( trait_ADDICTIVE ) ) {
timer = -10_hours;
} else if( has_trait( trait_NONADDICTIVE ) ) {
timer = -3_hours;
}
for( addiction &cur_addiction : addictions ) {
if( cur_addiction.sated <= 0_turns &&
cur_addiction.intensity >= MIN_ADDICTION_LEVEL ) {
addict_effect( *this, cur_addiction );
}
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 ) {
rem_addiction( cur_addiction.type );
break;
} else {
cur_addiction.intensity--;
cur_addiction.sated = 0_turns;
}
}
}
}
void Character::suffer_while_awake( const int current_stim )
{
if( !has_trait( trait_DEBUG_STORAGE ) &&
( weight_carried() > 4 * weight_capacity() ) ) {
if( has_effect( effect_downed ) ) {
add_effect( effect_downed, 1_turns, num_bp, 0 );
} else {
add_effect( effect_downed, 2_turns, num_bp, 0 );
}
}
if( has_trait( trait_CHEMIMBALANCE ) ) {
suffer_from_chemimbalance();
}
if( ( has_trait( trait_SCHIZOPHRENIC ) || has_artifact_with( AEP_SCHIZO ) ) &&
!has_effect( effect_took_thorazine ) ) {
suffer_from_schizophrenia();
}
if( ( has_trait( trait_NARCOLEPTIC ) || has_artifact_with( AEP_SCHIZO ) ) ) {
if( one_turn_in( 8_hours ) ) {
add_msg_player_or_npc( m_bad,
_( "You're suddenly overcome with the urge to sleep and you pass out." ),
_( "<npcname>'s suddenly passes out." ) );
fall_asleep( 20_minutes );
}
}
if( has_trait( trait_JITTERY ) && !has_effect( effect_shakes ) ) {
if( current_stim > 50 && one_in( to_turns<int>( 30_minutes ) - ( current_stim * 6 ) ) ) {
add_effect( effect_shakes, 30_minutes + 1_turns * current_stim );
} else if( ( get_kcal_percent() < 0.95f ) &&
one_turn_in( 60_minutes - 1_seconds * ( max_stored_kcal() - get_stored_kcal() ) ) ) {
add_effect( effect_shakes, 40_minutes );
}
}
if( has_trait( trait_MOODSWINGS ) && one_turn_in( 6_hours ) ) {
if( rng( 1, 20 ) > 9 ) {
// 55% chance
add_morale( MORALE_MOODSWING, -100, -500 );
} else {
// 45% chance
add_morale( MORALE_MOODSWING, 100, 500 );
}
}
if( has_trait( trait_VOMITOUS ) && one_turn_in( 7_hours ) ) {
vomit();
}
if( has_trait( trait_SHOUT1 ) && one_turn_in( 6_hours ) ) {
shout();
}
if( has_trait( trait_SHOUT2 ) && one_turn_in( 4_hours ) ) {
shout();
}
if( has_trait( trait_SHOUT3 ) && one_turn_in( 3_hours ) ) {
shout();
}
if( has_trait( trait_M_SPORES ) && one_turn_in( 4_hours ) ) {
spores();
}
if( has_trait( trait_M_BLOSSOMS ) && one_turn_in( 3_hours ) ) {
blossoms();
}
}
void Character::suffer_from_chemimbalance()
{
if( one_turn_in( 6_hours ) && !has_trait( trait_NOPAIN ) ) {
add_msg_if_player( m_bad, _( "You suddenly feel sharp pain for no reason." ) );
mod_pain( 3 * rng( 1, 3 ) );
}
if( one_turn_in( 6_hours ) ) {
int pkilladd = 5 * rng( -1, 2 );
if( pkilladd > 0 ) {
add_msg_if_player( m_bad, _( "You suddenly feel numb." ) );
} else if( ( pkilladd < 0 ) && ( !( has_trait( trait_NOPAIN ) ) ) ) {
add_msg_if_player( m_bad, _( "You suddenly ache." ) );
}
mod_painkiller( pkilladd );
}
if( one_turn_in( 6_hours ) && !has_effect( effect_sleep ) ) {
add_msg_if_player( m_bad, _( "You feel dizzy for a moment." ) );
moves -= rng( 10, 30 );
}
if( one_turn_in( 6_hours ) ) {
int hungadd = 5 * rng( -1, 3 );
if( hungadd > 0 ) {
add_msg_if_player( m_bad, _( "You suddenly feel hungry." ) );
} else {
add_msg_if_player( m_good, _( "You suddenly feel a little full." ) );
}
mod_stored_kcal( -10 * hungadd );
}
if( one_turn_in( 6_hours ) ) {
add_msg_if_player( m_bad, _( "You suddenly feel thirsty." ) );
mod_thirst( 5 * rng( 1, 3 ) );
}
if( one_turn_in( 6_hours ) ) {
add_msg_if_player( m_good, _( "You feel fatigued all of a sudden." ) );
mod_fatigue( 10 * rng( 2, 4 ) );
}
if( one_turn_in( 8_hours ) ) {
if( one_in( 3 ) ) {
add_morale( MORALE_FEELING_GOOD, 20, 100 );
} else {
add_morale( MORALE_FEELING_BAD, -20, -100 );
}
}
if( one_turn_in( 6_hours ) ) {
if( one_in( 3 ) ) {
add_msg_if_player( m_bad, _( "You suddenly feel very cold." ) );
temp_cur.fill( BODYTEMP_VERY_COLD );
} else {
add_msg_if_player( m_bad, _( "You suddenly feel cold." ) );
temp_cur.fill( BODYTEMP_COLD );
}
temp_cur[bp_eyes] = BODYTEMP_NORM;
}
if( one_turn_in( 6_hours ) ) {
if( one_in( 3 ) ) {
add_msg_if_player( m_bad, _( "You suddenly feel very hot." ) );
temp_cur.fill( BODYTEMP_VERY_HOT );
} else {
add_msg_if_player( m_bad, _( "You suddenly feel hot." ) );
temp_cur.fill( BODYTEMP_HOT );
}
temp_cur[bp_eyes] = BODYTEMP_NORM;
}
}
void Character::suffer_from_schizophrenia()
{
std::string i_name_w;
if( !weapon.is_null() ) {
i_name_w = weapon.has_var( "item_label" ) ? weapon.get_var( "item_label" ) :
//~ %1$s: weapon name
string_format( _( "your %1$s" ), weapon.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() );
add_msg_if_player( m_warning, "%s", snip );
add_morale( MORALE_FEELING_BAD, -20, -100 );
} else { // 25% chance
const translation snip = SNIPPET.random_from_category( "schizo_delusion_grandiose" ).value_or(
translation() );
add_msg_if_player( m_good, "%s", snip );
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() );
body_part bp = random_body_part( true );
add_effect( effect_formication, 45_minutes, bp );
add_msg_if_player( m_bad, "%s", snip );
return;
}
// Numbness
if( one_turn_in( 4_hours ) ) {
add_msg_if_player( m_bad, _( "You suddenly feel so numb…" ) );
mod_painkiller( 25 );
return;
}
// Hallucination
if( one_turn_in( 6_hours ) ) {
add_effect( effect_hallu, 6_hours );
return;
}
// Visuals
if( one_turn_in( 2_hours ) ) {
add_effect( effect_visuals, rng( 15_turns, 60_turns ) );
return;
}
// Shaking
if( !has_effect( effect_valium ) && one_turn_in( 4_hours ) ) {
add_msg_player_or_npc( m_bad, _( "You start to shake uncontrollably." ),
_( "<npcname> starts to shake uncontrollably." ) );
add_effect( effect_shakes, rng( 2_minutes, 5_minutes ) );
return;
}
// Shout
if( one_turn_in( 4_hours ) ) {
shout( SNIPPET.random_from_category( "schizo_self_shout" ).value_or( translation() ).translated() );
return;
}
// Drop weapon
if( one_turn_in( 2_days ) && !weapon.is_null() ) {
const translation snip = SNIPPET.random_from_category( "schizo_weapon_drop" ).value_or(
translation() );
std::string str = string_format( snip, i_name_w );
str[0] = toupper( str[0] );
add_msg_if_player( m_bad, "%s", str );
item_location loc( *this, &weapon );
drop( loc, pos() );
return;
}
// Talk to self
if( one_turn_in( 4_hours ) ) {
const translation snip = SNIPPET.random_from_category( "schizo_self_talk" ).value_or(
translation() );
add_msg( _( "%1$s says: \"%2$s\"" ), name, snip );
return;
}
// effects of this point are entirely internal, so NPCs can't suffer from them
if( is_npc() ) {
return;
}
// Sound
if( one_turn_in( 4_hours ) ) {
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 = name;
if( !followers.empty() ) {
who_gets_angry = random_entry_ref( followers )->name;
}
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
}
};
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() );
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, *this, *this );
add_msg_if_player( _( "%1$s says: \"%2$s\"" ), i_name, i_talk );
return;
}
// Skill raise
if( one_turn_in( 12_hours ) ) {
skill_id raised_skill = Skill::random_skill();
add_msg_if_player( m_good, _( "You increase %1$s to level %2$d." ), raised_skill.obj().name(),
get_skill_level( raised_skill ) + 1 );
return;
}
// Talking weapon
if( !weapon.is_null() ) {
// 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( 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 && 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( weapon.damage() >= weapon.max_damage() / 3 && 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_if_player( _( "%1$s says: \"%2$s\"" ), i_name_w, i_talk_w );
return;
}
}
}
void Character::suffer_from_asthma( const int current_stim )
{
if( has_effect( effect_adrenaline ) ||
has_effect( effect_datura ) ||
has_effect( effect_took_antiasthmatic ) ) {
return;
}
if( !one_in( ( to_turns<int>( 6_hours ) - current_stim * 300 ) *
( has_effect( effect_sleep ) ? 10 : 1 ) ) ) {
return;
}
bool auto_use = has_charges( itype_inhaler, 1 ) || has_charges( itype_oxygen_tank, 1 ) ||
has_charges( itype_smoxygen_tank, 1 );
bool oxygenator = has_bionic( bio_gills ) && get_power_level() >= ( bio_gills->power_trigger / 8 );
if( is_underwater() ) {
oxygen = oxygen / 2;
auto_use = false;
}
add_msg_player_or_npc( m_bad, _( "You have an asthma attack!" ),
"<npcname> starts wheezing and coughing." );
if( in_sleep_state() && !has_effect( effect_narcosis ) ) {
inventory map_inv;
map_inv.form_from_map( g->u.pos(), 2, &g->u );
// 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 ) {
mod_power_level( -bio_gills->power_trigger / 8 );
add_msg_if_player( m_info, _( "You use your Oxygenator to clear it up, "
"then go back to sleep." ) );
} else if( auto_use ) {
if( use_charges_if_avail( itype_inhaler, 1 ) ) {
add_msg_if_player( m_info, _( "You use your inhaler and go back to sleep." ) );
} else if( use_charges_if_avail( itype_oxygen_tank, 1 ) ||
use_charges_if_avail( itype_smoxygen_tank, 1 ) ) {
add_msg_if_player( m_info, _( "You take a deep breath from your oxygen tank "
"and go back to sleep." ) );
}
} else if( nearby_use ) {
// create new variable to resolve a reference issue
int amount = 1;
map &here = get_map();
if( !here.use_charges( g->u.pos(), 2, itype_inhaler, amount ).empty() ) {
add_msg_if_player( m_info, _( "You use your inhaler and go back to sleep." ) );
} else if( !here.use_charges( g->u.pos(), 2, itype_oxygen_tank, amount ).empty() ||
!here.use_charges( g->u.pos(), 2, itype_smoxygen_tank, amount ).empty() ) {
add_msg_if_player( m_info, _( "You take a deep breath from your oxygen tank "
"and go back to sleep." ) );
}
} else {
add_effect( effect_asthma, rng( 5_minutes, 20_minutes ) );
if( has_effect( effect_sleep ) ) {
wake_up();
} else {
if( !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( use_charges_if_avail( itype_inhaler, 1 ) ) {
moves -= 40;
charges = charges_of( itype_inhaler );
if( charges == 0 ) {
add_msg_if_player( m_bad, _( "You use your last inhaler charge." ) );
} else {
add_msg_if_player( m_info, vgettext( "You use your inhaler, "
"only %d charge left.",
"You use your inhaler, "
"only %d charges left.", charges ),
charges );
}
} else if( use_charges_if_avail( itype_oxygen_tank, 1 ) ||
use_charges_if_avail( itype_smoxygen_tank, 1 ) ) {
moves -= 500; // synched with use action
charges = charges_of( itype_oxygen_tank ) + charges_of( itype_smoxygen_tank );
if( charges == 0 ) {
add_msg_if_player( m_bad, _( "You breathe in last bit of oxygen "
"from the tank." ) );
} else {
add_msg_if_player( m_info, vgettext( "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 {
add_effect( effect_asthma, rng( 5_minutes, 20_minutes ) );
if( !is_npc() ) {
g->cancel_activity_or_ignore_query( distraction_type::asthma,
_( "You can't focus while choking!" ) );
}
}
}
void Character::suffer_in_sunlight()
{
double sleeve_factor = armwear_factor();
const bool has_hat = wearing_something_on( bodypart_id( "head" ) );
const bool leafy = has_trait( trait_LEAVES ) || has_trait( trait_LEAVES2 ) ||
has_trait( trait_LEAVES3 );
const bool leafier = has_trait( trait_LEAVES2 ) || has_trait( trait_LEAVES3 );
const bool leafiest = has_trait( trait_LEAVES3 );
int sunlight_nutrition = 0;
if( leafy && get_map().is_outside( pos() ) && ( g->light_level( pos().z ) >= 40 ) ) {
const float weather_factor = ( get_weather().weather_id->sun_intensity >=
sun_intensity_type::normal ) ? 1.0 : 0.5;
const int player_local_temp = get_weather().get_temperature( pos() );
int flux = ( player_local_temp - 65 ) / 2;
if( !has_hat ) {
sunlight_nutrition += ( 100 + flux ) * weather_factor;
}
if( leafier ) {
int rate = ( ( 100 * sleeve_factor ) + flux ) * 2;
sunlight_nutrition += ( rate * ( leafiest ? 2 : 1 ) ) * weather_factor;
}
}
if( x_in_y( sunlight_nutrition, 18000 ) ) {
vitamin_mod( vitamin_id( "vitA" ), 1, true );
vitamin_mod( vitamin_id( "vitC" ), 1, true );
}
if( x_in_y( sunlight_nutrition, 12000 ) ) {
mod_stored_kcal( 10 );
stomach.ate();
}
if( !g->is_in_sunlight( pos() ) ) {
return;
}
if( has_trait( trait_ALBINO ) || has_effect( effect_datura ) || has_trait( trait_SUNBURN ) ) {
suffer_from_sunburn();
}
if( ( has_trait( trait_TROGLO ) || has_trait( trait_TROGLO2 ) ) &&
get_weather().weather_id->sun_intensity >= sun_intensity_type::high ) {
mod_str_bonus( -1 );
mod_dex_bonus( -1 );
add_miss_reason( _( "The sunlight distracts you." ), 1 );
mod_int_bonus( -1 );
mod_per_bonus( -1 );
}
if( has_trait( trait_TROGLO2 ) ) {
mod_str_bonus( -1 );
mod_dex_bonus( -1 );
add_miss_reason( _( "The sunlight distracts you." ), 1 );
mod_int_bonus( -1 );
mod_per_bonus( -1 );
}
if( has_trait( trait_TROGLO3 ) ) {
mod_str_bonus( -4 );
mod_dex_bonus( -4 );
add_miss_reason( _( "You can't stand the sunlight!" ), 4 );
mod_int_bonus( -4 );
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.0;
}
// For every item worn, for every body part, adjust coverage
for( const item &it : worn ) {
// What body parts does this item cover?
body_part_set covered = it.get_covered_body_parts();
for( const bodypart_id &bp : all_body_parts ) {
if( bp->token != num_bp && !covered.test( bp->token ) ) {
continue;
}
// How much exposure does this item leave on this part? (1.0 == naked)
float part_exposure = 1.0 - it.get_coverage() / 100.0f;
// Coverage multiplies, so two layers with 50% coverage will together give 75%
bp_exposure[bp] = bp_exposure[bp] * part_exposure;
}
}
return bp_exposure;
}
void Character::suffer_from_sunburn()
{
if( !has_trait( trait_ALBINO ) && !has_effect( effect_datura ) && !has_trait( trait_SUNBURN ) ) {
return;
}
std::string sunlight_effect;
if( has_trait( trait_ALBINO ) || has_effect( effect_datura ) ) {
// Albinism and datura have the same effects, once per minute on average
if( !one_turn_in( 1_minutes ) ) {
return;
}
sunlight_effect = _( "The sunlight is really irritating" );
} else if( has_trait( trait_SUNBURN ) ) {
// Sunburn effects occur about 3 times per minute
if( !one_turn_in( 20_seconds ) ) {
return;
}
sunlight_effect = _( "The sunlight burns" );
}
// Sunglasses can keep the sun off the eyes.
if( !has_bionic( bio_sunglasses ) &&
!( wearing_something_on( bodypart_id( "eyes" ) ) &&
( worn_with_flag( flag_SUN_GLASSES ) || worn_with_flag( flag_BLIND ) ) ) ) {
add_msg_if_player( m_bad, _( "%s your eyes." ), sunlight_effect );
// Pain (1/60) or loss of focus (59/60)
if( one_turn_in( 1_minutes ) ) {
mod_pain( 1 );
} else {
focus_pool --;
}
}
// Umbrellas can keep the sun off the skin
if( weapon.has_flag( "RAIN_PROTECT" ) ) {
return;
}
std::map<bodypart_id, float> bp_exposure = bodypart_exposure();
// Minimum exposure threshold for pain
const float MIN_EXPOSURE = 0.01f;
// Count how many body parts are above the threshold
int count_affected_bp = 0;
// Get the most exposed body part, and how exposed it is. This is to tell the player what body
// part is most irritated by sun, so they know what needs to be covered up better.
bodypart_id most_exposed_bp;
float max_exposure = 0.0f;
// Check each bodypart with exposure above the minimum
for( const std::pair<const bodypart_id, float> &bp_exp : bp_exposure ) {
const float exposure = bp_exp.second;
// Skip minimally-exposed parts, and skip the eyes (handled by sunglasses)
if( exposure <= MIN_EXPOSURE || bp_exp.first == bodypart_id( "eyes" ) ) {
continue;
}
++count_affected_bp;
if( exposure > max_exposure ) {
max_exposure = exposure;
most_exposed_bp = bp_exp.first;
}
}
// If all body parts are protected, there is no suffering
if( count_affected_bp == 0 || !most_exposed_bp ) {
return;
}
// Check if both arms/legs are affected
int count_limbs = 1;
const bodypart_id &other_bp = most_exposed_bp->opposite_part;
const bodypart_id &other_bp_rev = other_bp->opposite_part;
// If these are different, we have a left/right part like a leg or arm.
// If same, it's a central body part with no opposite, like head or torso.
// Only used to generate a simpler message when both arms or both legs are affected.
if( other_bp != other_bp_rev ) {
const auto found = bp_exposure.find( other_bp );
// Is opposite part exposed?
if( found != bp_exposure.end() && found->second > MIN_EXPOSURE ) {
++count_limbs;
}
}
// Get singular or plural body part name; append "and other body parts" if appropriate
std::string bp_name = body_part_name( most_exposed_bp, count_limbs );
if( count_affected_bp == count_limbs ) {
add_msg_if_player( m_bad, _( "%s your %s." ), sunlight_effect, bp_name );
} else {
add_msg_if_player( m_bad, _( "%s your %s and other body parts." ), sunlight_effect,
bp_name );
}
// Wake up from skin irritation/burning
if( has_effect( effect_sleep ) ) {
wake_up();
}
// Solar Sensitivity (SUNBURN) trait causes injury to exposed parts
if( has_trait( trait_SUNBURN ) ) {
mod_pain( 1 );
// Check exposure of all body parts
for( const std::pair<const bodypart_id, float> &bp_exp : bp_exposure ) {
const bodypart_id &this_part = bp_exp.first;
const float exposure = bp_exp.second;
// Skip parts with adequate protection
if( exposure <= MIN_EXPOSURE ) {
continue;
}
// Don't damage eyes directly, since it takes from head HP (in other words, your head
// won't be destroyed if only your eyes are exposed).
if( this_part == bodypart_id( "eyes" ) ) {
continue;
}
// Exposure percentage determines likelihood of injury
// 10% exposure is 10% chance of injury, naked = 100% chance
if( x_in_y( exposure, 1.0 ) ) {
// 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( this_part == bodypart_id( "torso" ) ) {
apply_damage( nullptr, this_part, 2 );
} else {
apply_damage( nullptr, this_part, 1 );
}
}
}
} else {
// Albinism/datura causes pain (1/60) or focus loss (59/60)
if( one_turn_in( 1_minutes ) ) {
mod_pain( 1 );
} else {
focus_pool --;
}
}
}
void Character::suffer_from_other_mutations()
{
map &here = get_map();
if( has_trait( trait_SHARKTEETH ) && one_turn_in( 24_hours ) ) {
add_msg_if_player( m_neutral, _( "You shed a tooth!" ) );
here.spawn_item( pos(), "bone", 1 );
}
if( has_active_mutation( trait_WINGS_INSECT ) ) {
//~Sound of buzzing Insect Wings
sounds::sound( pos(), 10, sounds::sound_t::movement, _( "BZZZZZ" ), false, "misc",
"insect_wings" );
}
bool wearing_shoes = is_wearing_shoes( side::LEFT ) || is_wearing_shoes( side::RIGHT );
int root_vitamins = 0;
int root_water = 0;
if( has_trait( trait_ROOTS3 ) && here.has_flag( flag_PLOWABLE, pos() ) && !wearing_shoes ) {
root_vitamins += 1;
if( get_thirst() <= thirst_levels::turgid ) {
root_water += 51;
}
}
if( x_in_y( root_vitamins, 576 ) ) {
vitamin_mod( vitamin_id( "iron" ), 1, true );
vitamin_mod( vitamin_id( "calcium" ), 1, true );
mod_healthy_mod( 5, 50 );
}
if( x_in_y( root_water, 2550 ) ) {
// Plants draw some crazy amounts of water from the ground in real life,
// so these numbers try to reflect that uncertain but large amount
// this should take 12 hours to meet your daily needs with ROOTS2, and 8 with ROOTS3
mod_thirst( -1 );
}
if( has_trait( trait_SORES ) ) {
for( const body_part bp : all_body_parts ) {
if( bp == bp_head ) {
continue;
}
int sores_pain = 5 + 0.4 * std::abs( encumb( bp ) );
if( get_pain() < sores_pain ) {
set_pain( sores_pain );
}
}
}
//Web Weavers...weave web
if( has_active_mutation( trait_WEB_WEAVER ) && !in_vehicle ) {
// this adds intensity to if its not already there.
here.add_field( pos(), fd_web, 1 );
}