forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutation.cpp
1934 lines (1741 loc) · 66.7 KB
/
mutation.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 "mutation.h"
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <memory>
#include <unordered_set>
#include "activity_type.h"
#include "avatar_action.h"
#include "avatar.h"
#include "bionics.h"
#include "character.h"
#include "color.h"
#include "condition.h"
#include "creature.h"
#include "debug.h"
#include "enums.h"
#include "event.h"
#include "event_bus.h"
#include "field_type.h"
#include "game.h"
#include "item.h"
#include "itype.h"
#include "magic_enchantment.h"
#include "make_static.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "memorial_logger.h"
#include "messages.h"
#include "monster.h"
#include "omdata.h"
#include "output.h"
#include "overmapbuffer.h"
#include "pimpl.h"
#include "player_activity.h"
#include "rng.h"
#include "text_snippets.h"
#include "translations.h"
#include "units.h"
static const activity_id ACT_PULL_CREATURE( "ACT_PULL_CREATURE" );
static const activity_id ACT_TREE_COMMUNION( "ACT_TREE_COMMUNION" );
static const efftype_id effect_stunned( "stunned" );
static const itype_id itype_fake_burrowing( "fake_burrowing" );
static const json_character_flag json_flag_HUGE( "HUGE" );
static const json_character_flag json_flag_LARGE( "LARGE" );
static const json_character_flag json_flag_SMALL( "SMALL" );
static const json_character_flag json_flag_TINY( "TINY" );
static const mtype_id mon_player_blob( "mon_player_blob" );
static const mutation_category_id mutation_category_ALPHA( "ALPHA" );
static const mutation_category_id mutation_category_ANY( "ANY" );
static const mutation_category_id mutation_category_URSINE( "URSINE" );
static const trait_id trait_BURROW( "BURROW" );
static const trait_id trait_BURROWLARGE( "BURROWLARGE" );
static const trait_id trait_CARNIVORE( "CARNIVORE" );
static const trait_id trait_CHAOTIC_BAD( "CHAOTIC_BAD" );
static const trait_id trait_DEBUG_BIONIC_POWER( "DEBUG_BIONIC_POWER" );
static const trait_id trait_DEBUG_BIONIC_POWERGEN( "DEBUG_BIONIC_POWERGEN" );
static const trait_id trait_DEX_ALPHA( "DEX_ALPHA" );
static const trait_id trait_GASTROPOD_EXTREMITY2( "GASTROPOD_EXTREMITY2" );
static const trait_id trait_GASTROPOD_EXTREMITY3( "GASTROPOD_EXTREMITY3" );
static const trait_id trait_GLASSJAW( "GLASSJAW" );
static const trait_id trait_INT_ALPHA( "INT_ALPHA" );
static const trait_id trait_INT_SLIME( "INT_SLIME" );
static const trait_id trait_LONG_TONGUE2( "LONG_TONGUE2" );
static const trait_id trait_MUTAGEN_AVOID( "MUTAGEN_AVOID" );
static const trait_id trait_M_BLOOM( "M_BLOOM" );
static const trait_id trait_M_BLOSSOMS( "M_BLOSSOMS" );
static const trait_id trait_M_FERTILE( "M_FERTILE" );
static const trait_id trait_M_PROVENANCE( "M_PROVENANCE" );
static const trait_id trait_M_SPORES( "M_SPORES" );
static const trait_id trait_NAUSEA( "NAUSEA" );
static const trait_id trait_NOPAIN( "NOPAIN" );
static const trait_id trait_PER_ALPHA( "PER_ALPHA" );
static const trait_id trait_ROBUST( "ROBUST" );
static const trait_id trait_ROOTS2( "ROOTS2" );
static const trait_id trait_ROOTS3( "ROOTS3" );
static const trait_id trait_SLIMESPAWNER( "SLIMESPAWNER" );
static const trait_id trait_SNAIL_TRAIL( "SNAIL_TRAIL" );
static const trait_id trait_STR_ALPHA( "STR_ALPHA" );
static const trait_id trait_THRESH_MARLOSS( "THRESH_MARLOSS" );
static const trait_id trait_THRESH_MYCUS( "THRESH_MYCUS" );
static const trait_id trait_TREE_COMMUNION( "TREE_COMMUNION" );
static const trait_id trait_VOMITOUS( "VOMITOUS" );
static const trait_id trait_WEB_WEAVER( "WEB_WEAVER" );
namespace io
{
template<>
std::string enum_to_string<mutagen_technique>( mutagen_technique data )
{
switch( data ) {
// *INDENT-OFF*
case mutagen_technique::consumed_mutagen: return "consumed_mutagen";
case mutagen_technique::injected_mutagen: return "injected_mutagen";
case mutagen_technique::consumed_purifier: return "consumed_purifier";
case mutagen_technique::injected_purifier: return "injected_purifier";
case mutagen_technique::injected_smart_purifier: return "injected_smart_purifier";
// *INDENT-ON*
case mutagen_technique::num_mutagen_techniques:
break;
}
cata_fatal( "Invalid mutagen_technique" );
}
} // namespace io
bool Character::has_trait( const trait_id &b ) const
{
return my_mutations.count( b ) || enchantment_cache->get_mutations().count( b );
}
bool Character::has_trait_flag( const json_character_flag &b ) const
{
// UGLY, SLOW, should be cached as my_mutation_flags or something
for( const trait_id &mut : get_mutations() ) {
const mutation_branch &mut_data = mut.obj();
if( mut_data.flags.count( b ) > 0 ) {
return true;
} else if( mut_data.activated ) {
Character &player = get_player_character();
if( ( mut_data.active_flags.count( b ) > 0 && player.has_active_mutation( mut ) ) ||
( mut_data.inactive_flags.count( b ) > 0 && !player.has_active_mutation( mut ) ) ) {
return true;
}
}
}
return false;
}
bool Character::has_base_trait( const trait_id &b ) const
{
// Look only at base traits
return my_traits.find( b ) != my_traits.end();
}
void Character::toggle_trait( const trait_id &trait_ )
{
// Take copy of argument because it might be a reference into a container
// we're about to erase from.
// NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
const trait_id trait = trait_;
const auto titer = my_traits.find( trait );
const auto miter = my_mutations.find( trait );
const bool not_found_in_traits = titer == my_traits.end();
const bool not_found_in_mutations = miter == my_mutations.end();
if( not_found_in_traits ) {
my_traits.insert( trait );
} else {
my_traits.erase( titer );
}
// Checking this after toggling my_traits, if we exit the two are now consistent.
if( not_found_in_traits != not_found_in_mutations ) {
debugmsg( "my_traits and my_mutations were out of sync for %s\n", trait.str() );
return;
}
if( not_found_in_mutations ) {
set_mutation( trait );
} else {
unset_mutation( trait );
}
}
void Character::set_mutation_unsafe( const trait_id &trait )
{
const auto iter = my_mutations.find( trait );
if( iter != my_mutations.end() ) {
return;
}
my_mutations.emplace( trait, trait_data{} );
cached_mutations.push_back( &trait.obj() );
mutation_effect( trait, false );
}
void Character::do_mutation_updates()
{
recalc_sight_limits();
calc_encumbrance();
// If the stamina is higher than the max (Languorous), set it back to max
if( get_stamina() > get_stamina_max() ) {
set_stamina( get_stamina_max() );
}
}
void Character::set_mutations( const std::vector<trait_id> &traits )
{
for( const trait_id &trait : traits ) {
set_mutation_unsafe( trait );
}
do_mutation_updates();
}
void Character::set_mutation( const trait_id &trait )
{
set_mutation_unsafe( trait );
do_mutation_updates();
}
void Character::unset_mutation( const trait_id &trait_ )
{
// Take copy of argument because it might be a reference into a container
// we're about to erase from.
// NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
const trait_id trait = trait_;
const auto iter = my_mutations.find( trait );
if( iter == my_mutations.end() ) {
return;
}
const mutation_branch &mut = *trait;
cached_mutations.erase( std::remove( cached_mutations.begin(), cached_mutations.end(), &mut ),
cached_mutations.end() );
my_mutations.erase( iter );
mutation_loss_effect( trait );
recalc_sight_limits();
calc_encumbrance();
}
void Character::switch_mutations( const trait_id &switched, const trait_id &target,
bool start_powered )
{
unset_mutation( switched );
set_mutation( target );
my_mutations[target].powered = start_powered;
}
bool Character::can_power_mutation( const trait_id &mut )
{
bool hunger = mut->hunger && get_kcal_percent() < 0.5f;
bool thirst = mut->thirst && get_thirst() >= 260;
bool fatigue = mut->fatigue && get_fatigue() >= fatigue_levels::EXHAUSTED;
return !hunger && !fatigue && !thirst;
}
void Character::mutation_reflex_trigger( const trait_id &mut )
{
if( mut->trigger_list.empty() || !can_power_mutation( mut ) ) {
return;
}
bool activate = false;
std::pair<translation, game_message_type> msg_on;
std::pair<translation, game_message_type> msg_off;
for( const std::vector<reflex_activation_data> &vect_rdata : mut->trigger_list ) {
activate = false;
// OR conditions: if any trigger is true then this condition is true
for( const reflex_activation_data &rdata : vect_rdata ) {
if( rdata.is_trigger_true( *this ) ) {
activate = true;
msg_on = rdata.msg_on;
break;
}
msg_off = rdata.msg_off;
}
// AND conditions: if any OR condition is false then this is false
if( !activate ) {
break;
}
}
if( activate && !has_active_mutation( mut ) ) {
activate_mutation( mut );
if( !msg_on.first.empty() ) {
add_msg_if_player( msg_on.second, msg_on.first );
}
} else if( !activate && has_active_mutation( mut ) ) {
deactivate_mutation( mut );
if( !msg_off.first.empty() ) {
add_msg_if_player( msg_off.second, msg_off.first );
}
}
}
bool reflex_activation_data::is_trigger_true( const Character &guy ) const
{
dialogue d( get_talker_for( guy ), nullptr );
return trigger( d );
}
int Character::get_mod( const trait_id &mut, const std::string &arg ) const
{
const auto &mod_data = mut->mods;
int ret = 0;
auto found = mod_data.find( std::make_pair( false, arg ) );
if( found != mod_data.end() ) {
ret += found->second;
}
return ret;
}
void Character::apply_mods( const trait_id &mut, bool add_remove )
{
int sign = add_remove ? 1 : -1;
int str_change = get_mod( mut, "STR" );
str_max += sign * str_change;
per_max += sign * get_mod( mut, "PER" );
dex_max += sign * get_mod( mut, "DEX" );
int_max += sign * get_mod( mut, "INT" );
if( str_change != 0 ) {
recalc_hp();
}
}
bool mutation_branch::conflicts_with_item( const item &it ) const
{
if( allow_soft_gear && it.is_soft() ) {
return false;
}
for( const flag_id &allowed : allowed_items ) {
if( it.has_flag( allowed ) ) {
return false;
}
}
for( const bodypart_str_id &bp : restricts_gear ) {
if( it.covers( bp.id() ) ) {
return true;
}
}
return false;
}
const resistances &mutation_branch::damage_resistance( const bodypart_id &bp ) const
{
const auto iter = armor.find( bp.id() );
if( iter == armor.end() ) {
static const resistances nulres;
return nulres;
}
return iter->second;
}
void Character::recalculate_size()
{
if( has_trait_flag( json_flag_TINY ) ) {
size_class = creature_size::tiny;
} else if( has_trait_flag( json_flag_SMALL ) ) {
size_class = creature_size::small;
} else if( has_trait_flag( json_flag_LARGE ) ) {
size_class = creature_size::large;
} else if( has_trait_flag( json_flag_HUGE ) ) {
size_class = creature_size::huge;
} else {
size_class = creature_size::medium;
}
}
void Character::mutation_effect( const trait_id &mut, const bool worn_destroyed_override )
{
if( mut == trait_GLASSJAW ) {
recalc_hp();
} else if( mut == trait_STR_ALPHA ) {
if( str_max < 16 ) {
str_max = 8 + str_max / 2;
}
apply_mods( mut, true );
recalc_hp();
} else if( mut == trait_DEX_ALPHA ) {
if( dex_max < 16 ) {
dex_max = 8 + dex_max / 2;
}
apply_mods( mut, true );
} else if( mut == trait_INT_ALPHA ) {
if( int_max < 16 ) {
int_max = 8 + int_max / 2;
}
apply_mods( mut, true );
} else if( mut == trait_INT_SLIME ) {
int_max *= 2; // Now, can you keep it? :-)
} else if( mut == trait_PER_ALPHA ) {
if( per_max < 16 ) {
per_max = 8 + per_max / 2;
}
apply_mods( mut, true );
} else {
apply_mods( mut, true );
}
recalculate_size();
const auto &branch = mut.obj();
if( branch.hp_modifier.has_value() || branch.hp_modifier_secondary.has_value() ||
branch.hp_adjustment.has_value() ) {
recalc_hp();
}
remove_worn_items_with( [&]( item & armor ) {
if( armor.has_flag( STATIC( flag_id( "OVERSIZE" ) ) ) ) {
return false;
}
if( !branch.conflicts_with_item( armor ) ) {
return false;
}
if( !worn_destroyed_override && branch.destroys_gear ) {
add_msg_player_or_npc( m_bad,
_( "Your %s is destroyed!" ),
_( "<npcname>'s %s is destroyed!" ),
armor.tname() );
armor.spill_contents( pos() );
} else {
add_msg_player_or_npc( m_bad,
_( "Your %s is pushed off!" ),
_( "<npcname>'s %s is pushed off!" ),
armor.tname() );
get_map().add_item_or_charges( pos(), armor );
}
return true;
} );
if( branch.starts_active ) {
my_mutations[mut].powered = true;
}
on_mutation_gain( mut );
}
void Character::mutation_loss_effect( const trait_id &mut )
{
if( mut == trait_GLASSJAW ) {
recalc_hp();
} else if( mut == trait_STR_ALPHA ) {
apply_mods( mut, false );
if( str_max < 16 ) {
str_max = 2 * ( str_max - 8 );
}
recalc_hp();
} else if( mut == trait_DEX_ALPHA ) {
apply_mods( mut, false );
if( dex_max < 16 ) {
dex_max = 2 * ( dex_max - 8 );
}
} else if( mut == trait_INT_ALPHA ) {
apply_mods( mut, false );
if( int_max < 16 ) {
int_max = 2 * ( int_max - 8 );
}
} else if( mut == trait_INT_SLIME ) {
int_max /= 2; // In case you have a freak accident with the debug menu ;-)
} else if( mut == trait_PER_ALPHA ) {
apply_mods( mut, false );
if( per_max < 16 ) {
per_max = 2 * ( per_max - 8 );
}
} else {
apply_mods( mut, false );
}
recalculate_size();
const auto &branch = mut.obj();
if( branch.hp_modifier.has_value() || branch.hp_modifier_secondary.has_value() ||
branch.hp_adjustment.has_value() ) {
recalc_hp();
}
if( !branch.enchantments.empty() ) {
recalculate_enchantment_cache();
recalculate_bodyparts();
}
on_mutation_loss( mut );
}
bool Character::has_active_mutation( const trait_id &b ) const
{
const auto iter = my_mutations.find( b );
return iter != my_mutations.end() && iter->second.powered;
}
int Character::get_cost_timer( const trait_id &mut ) const
{
const auto iter = my_mutations.find( mut );
if( iter != my_mutations.end() ) {
return iter->second.charge;
} else {
debugmsg( "Tried to get cost timer of %s but doesn't have this mutation.", mut.c_str() );
}
return 0;
}
void Character::set_cost_timer( const trait_id &mut, int set )
{
const auto iter = my_mutations.find( mut );
if( iter != my_mutations.end() ) {
iter->second.charge = set;
} else {
debugmsg( "Tried to set cost timer of %s but doesn't have this mutation.", mut.c_str() );
}
}
void Character::mod_cost_timer( const trait_id &mut, int mod )
{
set_cost_timer( mut, get_cost_timer( mut ) + mod );
}
bool Character::is_category_allowed( const std::vector<mutation_category_id> &category ) const
{
bool allowed = false;
bool restricted = false;
for( const trait_id &mut : get_mutations() ) {
if( !mut.obj().allowed_category.empty() ) {
restricted = true;
}
for( const mutation_category_id &Mu_cat : category ) {
if( mut.obj().allowed_category.count( Mu_cat ) ) {
allowed = true;
break;
}
}
}
if( !restricted ) {
allowed = true;
}
return allowed;
}
bool Character::is_category_allowed( const mutation_category_id &category ) const
{
bool allowed = false;
bool restricted = false;
for( const trait_id &mut : get_mutations() ) {
for( const mutation_category_id &Ch_cat : mut.obj().allowed_category ) {
restricted = true;
if( Ch_cat == category ) {
allowed = true;
}
}
}
if( !restricted ) {
allowed = true;
}
return allowed;
}
bool Character::is_weak_to_water() const
{
for( const trait_id &mut : get_mutations() ) {
if( mut.obj().weakness_to_water > 0 ) {
return true;
}
}
return false;
}
bool Character::can_use_heal_item( const item &med ) const
{
const itype_id heal_id = med.typeId();
bool can_use = false;
bool got_restriction = false;
for( const trait_id &mut : get_mutations() ) {
if( !mut.obj().can_only_heal_with.empty() ) {
got_restriction = true;
}
if( mut.obj().can_only_heal_with.count( heal_id ) ) {
can_use = true;
break;
}
}
if( !got_restriction ) {
can_use = !med.has_flag( STATIC( flag_id( "CANT_HEAL_EVERYONE" ) ) );
}
if( !can_use ) {
for( const trait_id &mut : get_mutations() ) {
if( mut.obj().can_heal_with.count( heal_id ) ) {
can_use = true;
break;
}
}
}
return can_use;
}
bool Character::can_install_cbm_on_bp( const std::vector<bodypart_id> &bps ) const
{
bool can_install = true;
for( const trait_id &mut : get_mutations() ) {
for( const bodypart_id &bp : bps ) {
if( mut.obj().no_cbm_on_bp.count( bp.id() ) ) {
can_install = false;
break;
}
}
}
return can_install;
}
void Character::activate_mutation( const trait_id &mut )
{
const mutation_branch &mdata = mut.obj();
trait_data &tdata = my_mutations[mut];
int cost = mdata.cost;
// You can take yourself halfway to Near Death levels of hunger/thirst.
// Fatigue can go to Exhausted.
if( !can_power_mutation( mut ) ) {
// Insufficient Foo to *maintain* operation is handled in player::suffer
add_msg_if_player( m_warning, _( "You feel like using your %s would kill you!" ),
mdata.name() );
return;
}
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.charge = mdata.cooldown - 1;
}
if( mdata.hunger ) {
// burn some energy
mod_stored_nutr( cost );
}
if( mdata.thirst ) {
mod_thirst( cost );
}
if( mdata.fatigue ) {
mod_fatigue( cost );
}
tdata.powered = true;
recalc_sight_limits();
}
if( !mut->enchantments.empty() ) {
recalculate_enchantment_cache();
}
if( mdata.transform ) {
const cata::value_ptr<mut_transform> trans = mdata.transform;
mod_moves( - trans->moves );
switch_mutations( mut, trans->target, trans->active );
if( !mdata.transform->msg_transform.empty() ) {
add_msg_if_player( m_neutral, mdata.transform->msg_transform );
}
return;
}
if( mut == trait_WEB_WEAVER ) {
get_map().add_field( pos(), fd_web, 1 );
add_msg_if_player( _( "You start spinning web with your spinnerets!" ) );
} else if( mut == trait_LONG_TONGUE2 ||
mut == trait_GASTROPOD_EXTREMITY2 ||
mut == trait_GASTROPOD_EXTREMITY3 ) {
tdata.powered = false;
assign_activity( ACT_PULL_CREATURE, to_moves<int>( 1_seconds ), 0, 0, mut->name() );
return;
} else if( mut == trait_SNAIL_TRAIL ) {
get_map().add_field( pos(), fd_sludge, 1 );
add_msg_if_player( _( "You start leaving a trail of sludge as you go." ) );
} else if( mut == trait_BURROW || mut == trait_BURROWLARGE ) {
tdata.powered = false;
item burrowing_item( itype_fake_burrowing );
invoke_item( &burrowing_item );
return; // handled when the activity finishes
} else if( mut == trait_SLIMESPAWNER ) {
monster *const slime = g->place_critter_around( mon_player_blob, pos(), 1 );
if( !slime ) {
// Oops, no room to divide!
add_msg_if_player( m_bad, _( "You focus, but are too hemmed in to birth a new slimespring!" ) );
tdata.powered = false;
return;
}
add_msg_if_player( m_good,
_( "You focus, and with a pleasant splitting feeling, birth a new slimespring!" ) );
slime->friendly = -1;
add_msg_if_player( m_good, SNIPPET.random_from_category( "slime_generate" ).value_or(
translation() ).translated() );
tdata.powered = false;
return;
} else if( mut == trait_NAUSEA || mut == trait_VOMITOUS ) {
vomit();
tdata.powered = false;
return;
} else if( mut == trait_M_FERTILE ) {
spores();
tdata.powered = false;
return;
} else if( mut == trait_M_BLOOM ) {
blossoms();
tdata.powered = false;
return;
} else if( mut == trait_M_PROVENANCE ) {
spores(); // double trouble!
blossoms();
tdata.powered = false;
return;
} else if( mut == trait_TREE_COMMUNION ) {
tdata.powered = false;
if( !overmap_buffer.ter( global_omt_location() ).obj().is_wooded() ) {
add_msg_if_player( m_info, _( "You can only do that in a wooded area." ) );
return;
}
// Check for adjacent trees.
bool adjacent_tree = false;
map &here = get_map();
for( const tripoint &p2 : here.points_in_radius( pos(), 1 ) ) {
if( here.has_flag( ter_furn_flag::TFLAG_TREE, p2 ) ) {
adjacent_tree = true;
}
}
if( !adjacent_tree ) {
add_msg_if_player( m_info, _( "You can only do that next to a tree." ) );
return;
}
if( has_trait( trait_ROOTS2 ) || has_trait( trait_ROOTS3 ) ) {
add_msg_if_player( _( "You reach out to the trees with your roots." ) );
} else {
add_msg_if_player(
_( "You lay next to the trees letting your hair roots tangle with the trees." ) );
}
assign_activity( ACT_TREE_COMMUNION );
if( has_trait( trait_ROOTS2 ) || has_trait( trait_ROOTS3 ) ) {
const time_duration startup_time = has_trait( trait_ROOTS3 ) ? rng( 15_minutes,
30_minutes ) : rng( 60_minutes, 90_minutes );
activity.values.push_back( to_turns<int>( startup_time ) );
return;
} else {
const time_duration startup_time = rng( 120_minutes, 180_minutes );
activity.values.push_back( to_turns<int>( startup_time ) );
return;
}
} else if( mut == trait_DEBUG_BIONIC_POWER ) {
mod_max_power_level_modifier( 100_kJ );
add_msg_if_player( m_good, _( "Bionic power storage increased by 100." ) );
tdata.powered = false;
return;
} else if( mut == trait_DEBUG_BIONIC_POWERGEN ) {
int npower;
if( query_int( npower, "Modify bionic power by how much? (Values are in millijoules)" ) ) {
mod_power_level( units::from_millijoule( npower ) );
add_msg_if_player( m_good, _( "Bionic power increased by %dmJ." ), npower );
tdata.powered = false;
}
return;
} else if( !mdata.spawn_item.is_empty() ) {
item tmpitem( mdata.spawn_item );
i_add_or_drop( tmpitem );
add_msg_if_player( mdata.spawn_item_message() );
tdata.powered = false;
return;
} else if( !mdata.ranged_mutation.is_empty() ) {
add_msg_if_player( mdata.ranged_mutation_message() );
avatar_action::fire_ranged_mutation( *this, item( mdata.ranged_mutation ) );
tdata.powered = false;
return;
}
}
void Character::deactivate_mutation( const trait_id &mut )
{
my_mutations[mut].powered = false;
// Handle stat changes from deactivation
apply_mods( mut, false );
recalc_sight_limits();
const mutation_branch &mdata = mut.obj();
if( mdata.transform ) {
const cata::value_ptr<mut_transform> trans = mdata.transform;
mod_moves( -trans->moves );
switch_mutations( mut, trans->target, trans->active );
}
if( mdata.transform && !mdata.transform->msg_transform.empty() ) {
add_msg_if_player( m_neutral, mdata.transform->msg_transform );
}
if( !mut->enchantments.empty() ) {
recalculate_enchantment_cache();
}
}
trait_id Character::trait_by_invlet( const int ch ) const
{
for( const std::pair<const trait_id, trait_data> &mut : my_mutations ) {
if( mut.second.key == ch ) {
return mut.first;
}
}
return trait_id::NULL_ID();
}
bool Character::mutation_ok( const trait_id &mutation, bool force_good, bool force_bad ) const
{
if( !is_category_allowed( mutation->category ) ) {
return false;
}
if( mutation_branch::trait_is_blacklisted( mutation ) ) {
return false;
}
if( has_trait( mutation ) || has_child_flag( mutation ) ) {
// We already have this mutation or something that replaces it.
return false;
}
for( const bionic_id &bid : get_bionics() ) {
for( const trait_id &mid : bid->canceled_mutations ) {
if( mid == mutation ) {
return false;
}
}
if( bid->mutation_conflicts.count( mutation ) != 0 ) {
return false;
}
}
const mutation_branch &mdata = mutation.obj();
if( force_bad && mdata.points > 0 ) {
// This is a good mutation, and we're due for a bad one.
return false;
}
if( force_good && mdata.points < 0 ) {
// This is a bad mutation, and we're due for a good one.
return false;
}
return true;
}
void Character::mutate()
{
bool force_bad = one_in( 3 );
bool force_good = false;
if( has_trait( trait_ROBUST ) && force_bad ) {
// Robust Genetics gives you a 33% chance for a good mutation,
// instead of the 33% chance of a bad one.
force_bad = false;
force_good = true;
}
if( has_trait( trait_CHAOTIC_BAD ) ) {
force_bad = true;
force_good = false;
}
// Determine the highest mutation category
mutation_category_id cat = get_highest_category();
if( !is_category_allowed( cat ) ) {
cat = mutation_category_id();
}
// See if we should upgrade/extend an existing mutation...
std::vector<trait_id> upgrades;
// ... or remove one that is not in our highest category
std::vector<trait_id> downgrades;
// For each mutation...
for( const mutation_branch &traits_iter : mutation_branch::get_all() ) {
const trait_id &base_mutation = traits_iter.id;
const mutation_branch &base_mdata = traits_iter;
bool thresh_save = base_mdata.threshold;
bool prof_save = base_mdata.profession;
// are we unpurifiable? (saved from mutating away)
bool purify_save = !base_mdata.purifiable;
// ...that we have...
if( has_trait( base_mutation ) ) {
// ...consider the mutations that replace it.
for( const trait_id &mutation : base_mdata.replacements ) {
bool valid_ok = mutation->valid;
if( mutation_ok( mutation, force_good, force_bad ) &&
valid_ok ) {
upgrades.push_back( mutation );
}
}
// ...consider the mutations that add to it.
for( const trait_id &mutation : base_mdata.additions ) {
bool valid_ok = mutation->valid;
if( mutation_ok( mutation, force_good, force_bad ) &&
valid_ok ) {
upgrades.push_back( mutation );
}
}
// ...consider whether its in our highest category
if( has_trait( base_mutation ) && !has_base_trait( base_mutation ) ) {
// Starting traits don't count toward categories
std::vector<trait_id> group = mutations_category[cat];
bool in_cat = false;
for( const trait_id &elem : group ) {
if( elem == base_mutation ) {
in_cat = true;
break;
}
}
// mark for removal
// no removing Thresholds/Professions this way!
// unpurifiable traits also cannot be purified
if( !in_cat && !thresh_save && !prof_save && !purify_save ) {
if( one_in( 4 ) ) {
downgrades.push_back( base_mutation );
}
}
}
}
}
// Preliminary round to either upgrade or remove existing mutations
if( one_in( 2 ) ) {
if( !upgrades.empty() ) {
// (upgrade count) chances to pick an upgrade, 4 chances to pick something else.
size_t roll = rng( 0, upgrades.size() + 4 );
if( roll < upgrades.size() ) {
// We got a valid upgrade index, so use it and return.
mutate_towards( upgrades[roll] );
return;
}
}
} else {
// Remove existing mutations that don't fit into our category
if( !downgrades.empty() && !cat.str().empty() ) {
size_t roll = rng( 0, downgrades.size() + 4 );
if( roll < downgrades.size() ) {
remove_mutation( downgrades[roll] );
return;
}
}
}
std::vector<trait_id> valid; // Valid mutations
bool first_pass = true;
do {
// If we tried once with a non-NULL category, and couldn't find anything valid
// there, try again with empty category
// CHAOTIC_BAD lets the game pull from any category by default
if( !first_pass || has_trait( trait_CHAOTIC_BAD ) ) {
cat = mutation_category_id();
}
if( cat.str().empty() ) {
// Pull the full list
for( const mutation_branch &traits_iter : mutation_branch::get_all() ) {
if( traits_iter.valid && is_category_allowed( traits_iter.category ) ) {
valid.push_back( traits_iter.id );
}
}
} else {
// Pull the category's list
valid = mutations_category[cat];
}
// Remove anything we already have, that we have a child of, or that
// goes against our intention of a good/bad mutation
for( size_t i = 0; i < valid.size(); i++ ) {
if( ( !mutation_ok( valid[i], force_good, force_bad ) ) ||
( !valid[i]->valid ) ) {
valid.erase( valid.begin() + i );
i--;
}
}
if( valid.empty() ) {
// So we won't repeat endlessly
first_pass = false;
}
} while( valid.empty() && !cat.str().empty() );
if( valid.empty() ) {
// Couldn't find anything at all!
return;
}
if( mutate_towards( random_entry( valid ) ) ) {
return;