forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bionics.cpp
3733 lines (3333 loc) · 141 KB
/
bionics.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 "bionics.h"
#include <algorithm> //std::min
#include <climits>
#include <cmath>
#include <cstdlib>
#include <forward_list>
#include <functional>
#include <iterator>
#include <list>
#include <memory>
#include <string>
#include <utility>
#include "action.h"
#include "activity_actor_definitions.h"
#include "activity_type.h"
#include "assign.h"
#include "avatar.h"
#include "avatar_action.h"
#include "ballistics.h"
#include "bodypart.h"
#include "calendar.h"
#include "cata_utility.h"
#include "character.h"
#include "character_martial_arts.h"
#include "colony.h"
#include "color.h"
#include "damage.h"
#include "debug.h"
#include "dispersion.h"
#include "effect.h"
#include "effect_on_condition.h"
#include "enum_conversions.h"
#include "enums.h"
#include "event.h"
#include "event_bus.h"
#include "explosion.h"
#include "field_type.h"
#include "flag.h"
#include "game.h"
#include "generic_factory.h"
#include "handle_liquid.h"
#include "inventory.h"
#include "item.h"
#include "item_location.h"
#include "itype.h"
#include "json.h"
#include "line.h"
#include "make_static.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "material.h"
#include "memorial_logger.h"
#include "messages.h"
#include "monster.h"
#include "morale_types.h"
#include "mutation.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 "projectile.h"
#include "requirements.h"
#include "ret_val.h"
#include "rng.h"
#include "sounds.h"
#include "string_formatter.h"
#include "teleport.h"
#include "translations.h"
#include "ui.h"
#include "units.h"
#include "value_ptr.h"
#include "vehicle.h"
#include "viewer.h"
#include "vpart_position.h"
#include "weather.h"
#include "weather_gen.h"
static const activity_id ACT_OPERATION( "ACT_OPERATION" );
static const bionic_id afs_bio_dopamine_stimulators( "afs_bio_dopamine_stimulators" );
static const bionic_id bio_adrenaline( "bio_adrenaline" );
static const bionic_id bio_blood_anal( "bio_blood_anal" );
static const bionic_id bio_blood_filter( "bio_blood_filter" );
static const bionic_id bio_cqb( "bio_cqb" );
static const bionic_id bio_emp( "bio_emp" );
static const bionic_id bio_evap( "bio_evap" );
static const bionic_id bio_flashbang( "bio_flashbang" );
static const bionic_id bio_geiger( "bio_geiger" );
static const bionic_id bio_gills( "bio_gills" );
static const bionic_id bio_hydraulics( "bio_hydraulics" );
static const bionic_id bio_jointservo( "bio_jointservo" );
static const bionic_id bio_lighter( "bio_lighter" );
static const bionic_id bio_lockpick( "bio_lockpick" );
static const bionic_id bio_magnet( "bio_magnet" );
static const bionic_id bio_meteorologist( "bio_meteorologist" );
static const bionic_id bio_nanobots( "bio_nanobots" );
static const bionic_id bio_painkiller( "bio_painkiller" );
static const bionic_id bio_radscrubber( "bio_radscrubber" );
static const bionic_id bio_remote( "bio_remote" );
static const bionic_id bio_resonator( "bio_resonator" );
static const bionic_id bio_shockwave( "bio_shockwave" );
static const bionic_id bio_teleport( "bio_teleport" );
static const bionic_id bio_time_freeze( "bio_time_freeze" );
static const bionic_id bio_torsionratchet( "bio_torsionratchet" );
static const bionic_id bio_water_extractor( "bio_water_extractor" );
static const efftype_id effect_adrenaline( "adrenaline" );
static const efftype_id effect_antifungal( "antifungal" );
static const efftype_id effect_assisted( "assisted" );
static const efftype_id effect_asthma( "asthma" );
static const efftype_id effect_badpoison( "badpoison" );
static const efftype_id effect_bleed( "bleed" );
static const efftype_id effect_bloodworms( "bloodworms" );
static const efftype_id effect_cig( "cig" );
static const efftype_id effect_datura( "datura" );
static const efftype_id effect_dermatik( "dermatik" );
static const efftype_id effect_drunk( "drunk" );
static const efftype_id effect_fungus( "fungus" );
static const efftype_id effect_hallu( "hallu" );
static const efftype_id effect_heating_bionic( "heating_bionic" );
static const efftype_id effect_high( "high" );
static const efftype_id effect_iodine( "iodine" );
static const efftype_id effect_meth( "meth" );
static const efftype_id effect_narcosis( "narcosis" );
static const efftype_id effect_operating( "operating" );
static const efftype_id effect_paralyzepoison( "paralyzepoison" );
static const efftype_id effect_pblue( "pblue" );
static const efftype_id effect_pkill1( "pkill1" );
static const efftype_id effect_pkill2( "pkill2" );
static const efftype_id effect_pkill3( "pkill3" );
static const efftype_id effect_pkill_l( "pkill_l" );
static const efftype_id effect_poison( "poison" );
static const efftype_id effect_sleep( "sleep" );
static const efftype_id effect_stung( "stung" );
static const efftype_id effect_teleglow( "teleglow" );
static const efftype_id effect_tetanus( "tetanus" );
static const efftype_id effect_took_flumed( "took_flumed" );
static const efftype_id effect_took_prozac( "took_prozac" );
static const efftype_id effect_took_prozac_bad( "took_prozac_bad" );
static const efftype_id effect_took_xanax( "took_xanax" );
static const efftype_id effect_under_operation( "under_operation" );
static const efftype_id effect_venom_dmg( "venom_dmg" );
static const efftype_id effect_venom_weaken( "venom_weaken" );
static const efftype_id effect_visuals( "visuals" );
static const fault_id fault_bionic_salvaged( "fault_bionic_salvaged" );
static const itype_id itype_anesthetic( "anesthetic" );
static const itype_id itype_battery( "battery" );
static const itype_id itype_radiocontrol( "radiocontrol" );
static const itype_id itype_remotevehcontrol( "remotevehcontrol" );
static const itype_id itype_water_clean( "water_clean" );
static const json_character_flag json_flag_BIONIC_GUN( "BIONIC_GUN" );
static const json_character_flag json_flag_BIONIC_NPC_USABLE( "BIONIC_NPC_USABLE" );
static const json_character_flag json_flag_BIONIC_TOGGLED( "BIONIC_TOGGLED" );
static const json_character_flag json_flag_BIONIC_WEAPON( "BIONIC_WEAPON" );
static const json_character_flag json_flag_ENHANCED_VISION( "ENHANCED_VISION" );
static const material_id fuel_type_battery( "battery" );
static const material_id fuel_type_metabolism( "metabolism" );
static const material_id fuel_type_muscle( "muscle" );
static const material_id fuel_type_sun_light( "sunlight" );
static const material_id fuel_type_wind( "wind" );
static const material_id material_budget_steel( "budget_steel" );
static const material_id material_ch_steel( "ch_steel" );
static const material_id material_hc_steel( "hc_steel" );
static const material_id material_iron( "iron" );
static const material_id material_lc_steel( "lc_steel" );
static const material_id material_mc_steel( "mc_steel" );
static const material_id material_qt_steel( "qt_steel" );
static const material_id material_steel( "steel" );
static const requirement_id requirement_data_anesthetic( "anesthetic" );
static const skill_id skill_computer( "computer" );
static const skill_id skill_electronics( "electronics" );
static const skill_id skill_firstaid( "firstaid" );
static const skill_id skill_mechanics( "mechanics" );
static const trait_id trait_CENOBITE( "CENOBITE" );
static const trait_id trait_DEBUG_BIONICS( "DEBUG_BIONICS" );
static const trait_id trait_MASOCHIST( "MASOCHIST" );
static const trait_id trait_MASOCHIST_MED( "MASOCHIST_MED" );
static const trait_id trait_NONE( "NONE" );
static const trait_id trait_NOPAIN( "NOPAIN" );
static const trait_id trait_PROF_AUTODOC( "PROF_AUTODOC" );
static const trait_id trait_PROF_MED( "PROF_MED" );
static const trait_id trait_PYROMANIA( "PYROMANIA" );
static const trait_id trait_THRESH_MEDICAL( "THRESH_MEDICAL" );
struct Character::auto_toggle_bionic_result {
bool can_burn_fuel = false;
bool has_burnable_fuel = false;
material_id burnable_fuel_id;
enum class fuel_type_t {
metabolism,
perpetual,
remote,
other
};
fuel_type_t fuel_type = fuel_type_t::other;
int fuel_energy = 0;
float effective_efficiency = 0.0f;
int current_fuel_stock = 0;
};
namespace
{
generic_factory<bionic_data> bionic_factory( "bionic" );
std::vector<bionic_id> faulty_bionics;
} //namespace
void bionic::initialize_pseudo_items( bool create_weapon )
{
bionic_data bid( info() );
bool inherit_use_bionic_power = bid.has_flag( flag_USES_BIONIC_POWER );
toggled_pseudo_items.clear();
passive_pseudo_items.clear();
if( bid.has_flag( json_flag_BIONIC_GUN ) || bid.has_flag( json_flag_BIONIC_WEAPON ) ) {
if( create_weapon && !id->fake_weapon.is_empty() && id->fake_weapon.is_valid() ) {
item new_weapon = item( id->fake_weapon );
install_weapon( new_weapon, true );
} else {
update_weapon_flags();
}
} else if( bid.has_flag( json_flag_BIONIC_TOGGLED ) ) {
for( const itype_id &id : bid.toggled_pseudo_items ) {
if( !id.is_empty() && id.is_valid() ) {
toggled_pseudo_items.emplace_back( id );
}
}
}
for( const itype_id &id : bid.passive_pseudo_items ) {
if( !id.is_empty() && id.is_valid() ) {
item pseudo( id );
pseudo.set_flag( flag_PSEUDO );
passive_pseudo_items.emplace_back( pseudo );
}
}
if( inherit_use_bionic_power ) {
for( item &pseudo : passive_pseudo_items ) {
pseudo.set_flag( flag_USES_BIONIC_POWER );
}
for( item &pseudo : toggled_pseudo_items ) {
pseudo.set_flag( flag_USES_BIONIC_POWER );
}
}
}
void bionic::update_weapon_flags()
{
if( has_weapon() ) {
if( id->has_flag( flag_USES_BIONIC_POWER ) ) {
weapon.set_flag( flag_USES_BIONIC_POWER );
}
weapon.set_flag( flag_NO_UNWIELD );
}
}
/** @relates string_id */
template<>
const bionic_data &string_id<bionic_data>::obj() const
{
return bionic_factory.obj( *this );
}
/** @relates string_id */
template<>
bool string_id<bionic_data>::is_valid() const
{
return bionic_factory.is_valid( *this );
}
std::vector<bodypart_id> get_occupied_bodyparts( const bionic_id &bid )
{
std::vector<bodypart_id> parts;
for( const std::pair<const string_id<body_part_type>, size_t> &element : bid->occupied_bodyparts ) {
if( element.second > 0 ) {
parts.push_back( element.first.id() );
}
}
return parts;
}
bool bionic_data::has_flag( const json_character_flag &flag ) const
{
return flags.count( flag ) > 0;
}
bool bionic_data::has_active_flag( const json_character_flag &flag ) const
{
return active_flags.count( flag ) > 0;
}
bool bionic_data::has_inactive_flag( const json_character_flag &flag ) const
{
return inactive_flags.count( flag ) > 0;
}
itype_id bionic_data::itype() const
{
// For now we just assume that the bionic id matches the corresponding item
// id (as strings).
return itype_id( id.str() );
}
static social_modifiers load_bionic_social_mods( const JsonObject &jo )
{
social_modifiers ret;
jo.read( "lie", ret.lie );
jo.read( "persuade", ret.persuade );
jo.read( "intimidate", ret.intimidate );
return ret;
}
void bionic_data::load( const JsonObject &jsobj, const std::string & )
{
mandatory( jsobj, was_loaded, "id", id );
mandatory( jsobj, was_loaded, "name", name );
mandatory( jsobj, was_loaded, "description", description );
optional( jsobj, was_loaded, "cant_remove_reason", cant_remove_reason );
// uses assign because optional doesn't handle loading units as strings
assign( jsobj, "react_cost", power_over_time, false, 0_kJ );
assign( jsobj, "capacity", capacity, false );
assign( jsobj, "weight_capacity_bonus", weight_capacity_bonus, false );
assign( jsobj, "act_cost", power_activate, false, 0_kJ );
assign( jsobj, "deact_cost", power_deactivate, false, 0_kJ );
assign( jsobj, "trigger_cost", power_trigger, false, 0_kJ );
assign( jsobj, "power_trickle", power_trickle, false, 0_kJ );
optional( jsobj, was_loaded, "time", charge_time, 0_turns );
optional( jsobj, was_loaded, "flags", flags );
optional( jsobj, was_loaded, "active_flags", active_flags );
optional( jsobj, was_loaded, "inactive_flags", inactive_flags );
optional( jsobj, was_loaded, "fuel_efficiency", fuel_efficiency, 0 );
optional( jsobj, was_loaded, "passive_fuel_efficiency", passive_fuel_efficiency, 0 );
optional( jsobj, was_loaded, "passive_pseudo_items", passive_pseudo_items );
optional( jsobj, was_loaded, "toggled_pseudo_items", toggled_pseudo_items );
optional( jsobj, was_loaded, "fake_weapon", fake_weapon, itype_id() );
optional( jsobj, was_loaded, "installable_weapon_flags", installable_weapon_flags );
optional( jsobj, was_loaded, "spell_on_activation", spell_on_activate );
optional( jsobj, was_loaded, "weight_capacity_modifier", weight_capacity_modifier, 1.0f );
optional( jsobj, was_loaded, "exothermic_power_gen", exothermic_power_gen );
optional( jsobj, was_loaded, "power_gen_emission", power_gen_emission );
optional( jsobj, was_loaded, "coverage_power_gen_penalty", coverage_power_gen_penalty );
optional( jsobj, was_loaded, "is_remote_fueled", is_remote_fueled );
optional( jsobj, was_loaded, "known_ma_styles", ma_styles );
optional( jsobj, was_loaded, "learned_spells", learned_spells );
optional( jsobj, was_loaded, "learned_proficiencies", proficiencies );
optional( jsobj, was_loaded, "canceled_mutations", canceled_mutations );
optional( jsobj, was_loaded, "mutation_conflicts", mutation_conflicts );
optional( jsobj, was_loaded, "included_bionics", included_bionics );
optional( jsobj, was_loaded, "included", included );
optional( jsobj, was_loaded, "upgraded_bionic", upgraded_bionic );
optional( jsobj, was_loaded, "fuel_options", fuel_opts );
optional( jsobj, was_loaded, "fuel_capacity", fuel_capacity );
optional( jsobj, was_loaded, "activated_on_install", activated_on_install, false );
optional( jsobj, was_loaded, "available_upgrades", available_upgrades );
optional( jsobj, was_loaded, "installation_requirement", installation_requirement );
optional( jsobj, was_loaded, "vitamin_absorb_mod", vitamin_absorb_mod, 1.0f );
optional( jsobj, was_loaded, "dupes_allowed", dupes_allowed, false );
optional( jsobj, was_loaded, "auto_deactivates", autodeactivated_bionics );
optional( jsobj, was_loaded, "activated_close_ui", activated_close_ui, false );
optional( jsobj, was_loaded, "deactivated_close_ui", deactivated_close_ui, false );
for( JsonValue jv : jsobj.get_array( "activated_eocs" ) ) {
activated_eocs.push_back( effect_on_conditions::load_inline_eoc( jv, "" ) );
}
for( JsonValue jv : jsobj.get_array( "processed_eocs" ) ) {
processed_eocs.push_back( effect_on_conditions::load_inline_eoc( jv, "" ) );
}
for( JsonValue jv : jsobj.get_array( "deactivated_eocs" ) ) {
deactivated_eocs.push_back( effect_on_conditions::load_inline_eoc( jv, "" ) );
}
int enchant_num = 0;
for( JsonValue jv : jsobj.get_array( "enchantments" ) ) {
std::string enchant_name = "INLINE_ENCH_" + name + "_" + std::to_string( enchant_num++ );
enchantments.push_back( enchantment::load_inline_enchantment( jv, "", enchant_name ) );
}
if( jsobj.has_array( "stat_bonus" ) ) {
// clear data first so that copy-from can override it
stat_bonus.clear();
for( JsonArray ja : jsobj.get_array( "stat_bonus" ) ) {
stat_bonus.emplace( io::string_to_enum<character_stat>( ja.get_string( 0 ) ),
ja.get_int( 1 ) );
}
}
if( jsobj.has_array( "encumbrance" ) ) {
// clear data first so that copy-from can override it
encumbrance.clear();
for( JsonArray ja : jsobj.get_array( "encumbrance" ) ) {
encumbrance.emplace( bodypart_str_id( ja.get_string( 0 ) ),
ja.get_int( 1 ) );
}
}
if( jsobj.has_array( "occupied_bodyparts" ) ) {
// clear data first so that copy-from can override it
occupied_bodyparts.clear();
for( JsonArray ja : jsobj.get_array( "occupied_bodyparts" ) ) {
occupied_bodyparts.emplace( bodypart_str_id( ja.get_string( 0 ) ),
ja.get_int( 1 ) );
}
}
if( jsobj.has_array( "env_protec" ) ) {
// clear data first so that copy-from can override it
env_protec.clear();
for( JsonArray ja : jsobj.get_array( "env_protec" ) ) {
env_protec.emplace( bodypart_str_id( ja.get_string( 0 ) ), ja.get_int( 1 ) );
}
}
if( jsobj.has_array( "bash_protec" ) ) {
// clear data first so that copy-from can override it
bash_protec.clear();
for( JsonArray ja : jsobj.get_array( "bash_protec" ) ) {
bash_protec.emplace( bodypart_str_id( ja.get_string( 0 ) ),
ja.get_int( 1 ) );
}
}
if( jsobj.has_array( "cut_protec" ) ) {
// clear data first so that copy-from can override it
cut_protec.clear();
for( JsonArray ja : jsobj.get_array( "cut_protec" ) ) {
cut_protec.emplace( bodypart_str_id( ja.get_string( 0 ) ),
ja.get_int( 1 ) );
}
}
if( jsobj.has_array( "bullet_protec" ) ) {
// clear data first so that copy-from can override it
bullet_protec.clear();
for( JsonArray ja : jsobj.get_array( "bullet_protec" ) ) {
bullet_protec.emplace( bodypart_str_id( ja.get_string( 0 ) ),
ja.get_int( 1 ) );
}
}
if( jsobj.has_object( "social_modifiers" ) ) {
JsonObject sm = jsobj.get_object( "social_modifiers" );
social_mods = load_bionic_social_mods( sm );
}
activated = has_flag( STATIC( json_character_flag( json_flag_BIONIC_TOGGLED ) ) ) ||
power_activate > 0_kJ ||
charge_time > 0_turns;
if( has_flag( STATIC( json_character_flag( "BIONIC_FAULTY" ) ) ) ) {
faulty_bionics.push_back( id );
}
}
void bionic_data::load_bionic( const JsonObject &jo, const std::string &src )
{
bionic_factory.load( jo, src );
}
const std::vector<bionic_data> &bionic_data::get_all()
{
return bionic_factory.get_all();
}
void bionic_data::check_bionic_consistency()
{
for( const bionic_data &bio : get_all() ) {
if( !bio.installation_requirement.is_empty() && !bio.installation_requirement.is_valid() ) {
debugmsg( "Bionic %s uses undefined requirement_id %s", bio.id.c_str(),
bio.installation_requirement.c_str() );
}
if( bio.has_flag( json_flag_BIONIC_GUN ) && bio.has_flag( json_flag_BIONIC_WEAPON ) ) {
debugmsg( "Bionic %s specified as both gun and weapon bionic", bio.id.c_str() );
}
if( ( bio.has_flag( json_flag_BIONIC_GUN ) || bio.has_flag( json_flag_BIONIC_WEAPON ) ) &&
bio.fake_weapon.is_empty() ) {
debugmsg( "Bionic %s specified as gun or weapon bionic is missing its fake_weapon id",
bio.id.c_str() );
}
if( bio.has_flag( json_flag_BIONIC_WEAPON ) && !bio.has_flag( flag_BIONIC_TOGGLED ) ) {
debugmsg( "Bionic \"%s\" specified as weapon bionic is not flagged as \"BIONIC_TOGGLED\"",
bio.id.c_str() );
}
for( const itype_id &pseudo : bio.passive_pseudo_items ) {
if( pseudo.is_empty() ) {
debugmsg( "Bionic \"%s\" has an empty passive_pseudo_item",
bio.id.c_str() );
} else if( !item::type_is_defined( pseudo ) ) {
debugmsg( "Bionic \"%s\" has unknown passive_pseudo_item \"%s\"",
bio.id.c_str(), pseudo.c_str() );
}
}
for( const itype_id &pseudo : bio.toggled_pseudo_items ) {
if( pseudo.is_empty() ) {
debugmsg( "Bionic %s has an empty toggled_pseudo_item",
bio.id.c_str() );
} else if( !item::type_is_defined( pseudo ) ) {
debugmsg( "Bionic \"%s\" has unknown toggled_pseudo_item \"%s\"",
bio.id.c_str(), pseudo.c_str() );
}
}
for( const trait_id &mid : bio.canceled_mutations ) {
if( !mid.is_valid() ) {
debugmsg( "Bionic %s cancels undefined mutation %s",
bio.id.c_str(), mid.c_str() );
}
}
for( const enchantment_id &eid : bio.id->enchantments ) {
if( !eid.is_valid() ) {
debugmsg( "Bionic %s uses undefined enchantment %s", bio.id.c_str(), eid.c_str() );
}
}
for( const bionic_id &bid : bio.included_bionics ) {
if( !bid.is_valid() ) {
debugmsg( "Bionic %s includes undefined bionic %s",
bio.id.c_str(), bid.c_str() );
}
if( !bid->occupied_bodyparts.empty() ) {
debugmsg( "Bionic %s (included by %s) consumes slots, those should be part of the containing bionic instead.",
bid.c_str(), bio.id.c_str() );
}
}
for( const bionic_id &bid : bio.autodeactivated_bionics ) {
if( !bid.is_valid() ) {
debugmsg( "Bionic \"%s\" has auto_deactivated bionic with invalid id \"%s\"", bio.id.c_str(),
bid.c_str() );
}
}
if( bio.upgraded_bionic ) {
if( bio.upgraded_bionic == bio.id ) {
debugmsg( "Bionic %s is upgraded with itself", bio.id.c_str() );
} else if( !bio.upgraded_bionic.is_valid() ) {
debugmsg( "Bionic %s upgrades undefined bionic %s",
bio.id.c_str(), bio.upgraded_bionic.c_str() );
}
}
if( !item::type_is_defined( bio.itype() ) && !bio.included ) {
debugmsg( "Bionic %s has no defined item version", bio.id.c_str() );
}
}
}
bionic_data::bionic_data() : name( no_translation( "bad bionic" ) ),
description( no_translation( "This bionic was not set up correctly, this is a bug" ) )
{
}
static void force_comedown( effect &eff )
{
if( eff.is_null() || eff.get_effect_type() == nullptr || eff.get_duration() <= 1_turns ) {
return;
}
eff.set_duration( std::min( eff.get_duration(), eff.get_int_dur_factor() ) );
}
void npc::discharge_cbm_weapon()
{
if( !is_using_bionic_weapon() ) {
return;
}
cata::optional<bionic *> bio_opt = find_bionic_by_uid( get_weapon_bionic_uid() );
if( !bio_opt ) {
debugmsg( "NPC tried to use a non-existent gun bionic with UID %d", weapon_bionic_uid );
return;
}
bionic &bio = **bio_opt;
mod_power_level( -bio.info().power_activate );
set_wielded_item( real_weapon );
weapon_bionic_uid = 0;
}
void npc::check_or_use_weapon_cbm( const bionic_id &cbm_id )
{
// if we're already using a bio_weapon, keep using it
if( is_using_bionic_weapon() ) {
return;
}
const float allowed_ratio = static_cast<int>( rules.cbm_reserve ) / 100.0f;
const units::energy free_power = get_power_level() - get_max_power_level() * allowed_ratio;
if( free_power <= 0_mJ ) {
return;
}
int index = 0;
bool found = false;
for( bionic &i : *my_bionics ) {
if( i.id == cbm_id && !i.powered ) {
found = true;
break;
}
index += 1;
}
if( !found ) {
return;
}
bionic &bio = ( *my_bionics )[index];
item_location weapon = get_wielded_item();
item weap = weapon ? *weapon : item();
if( bio.info().has_flag( json_flag_BIONIC_GUN ) ) {
if( !bio.has_weapon() ) {
debugmsg( "NPC tried to activate gun bionic \"%s\" without fake_weapon",
bio.info().id.str() );
return;
}
const item cbm_weapon = bio.get_weapon();
bool not_allowed = !rules.has_flag( ally_rule::use_guns ) ||
( rules.has_flag( ally_rule::use_silent ) && !cbm_weapon.is_silent() );
if( is_player_ally() && not_allowed ) {
return;
}
int ammo_count = weap.ammo_remaining( this );
const int ups_drain = weap.get_gun_ups_drain();
if( ups_drain > 0 ) {
ammo_count = ammo_count / ups_drain;
}
const int cbm_ammo = free_power / bio.info().power_activate;
if( weapon_value( weap, ammo_count ) < weapon_value( cbm_weapon, cbm_ammo ) ) {
if( real_weapon.is_null() ) {
// Prevent replacing real weapon when migrating saves
real_weapon = weap;
}
set_wielded_item( cbm_weapon );
weapon_bionic_uid = bio.get_uid();
}
} else if( bio.info().has_flag( json_flag_BIONIC_WEAPON ) && !weap.has_flag( flag_NO_UNWIELD ) &&
free_power > bio.info().power_activate ) {
if( !bio.has_weapon() ) {
debugmsg( "NPC tried to activate weapon bionic \"%s\" without fake_weapon",
bio.info().id.str() );
return;
}
if( is_armed() ) {
stow_item( *weapon );
}
add_msg_if_player_sees( pos(), m_info, _( "%s activates their %s." ),
disp_name(), bio.info().name );
set_wielded_item( bio.get_weapon() );
mod_power_level( -bio.info().power_activate );
bio.powered = true;
weapon_bionic_uid = bio.get_uid();
}
}
// Why put this in a Big Switch? Why not let bionics have pointers to
// functions, much like monsters and items?
//
// Well, because like diseases, which are also in a Big Switch, bionics don't
// share functions....
bool Character::activate_bionic( bionic &bio, bool eff_only, bool *close_bionics_ui )
{
const bool mounted = is_mounted();
if( bio.incapacitated_time > 0_turns ) {
add_msg( m_info, _( "Your %s is shorting out and can't be activated." ),
bio.info().name );
return false;
}
// eff_only means only do the effect without messing with stats or displaying messages
if( !eff_only ) {
if( bio.powered ) {
// It's already on!
return false;
}
if( !enough_power_for( bio.id ) ) {
add_msg_if_player( m_info, _( "You don't have the power to activate your %s." ),
bio.info().name );
return false;
}
const auto_toggle_bionic_result result = auto_toggle_bionic( bio, true );
if( result.can_burn_fuel && !result.has_burnable_fuel ) {
return false;
}
if( !bio.activate_spell( *this ) ) {
// the spell this bionic uses was unable to be cast
return false;
}
// We can actually activate now, do activation-y things
mod_power_level( -bio.info().power_activate );
bio.powered = bio.info().has_flag( json_flag_BIONIC_TOGGLED ) || bio.info().charge_time > 0_turns;
if( bio.info().charge_time > 0_turns ) {
bio.charge_timer = bio.info().charge_time;
}
if( !bio.id->enchantments.empty() ) {
recalculate_enchantment_cache();
}
}
auto add_msg_activate = [&]() {
if( !eff_only ) {
add_msg_if_player( m_info, _( "You activate your %s." ), bio.info().name );
}
};
auto refund_power = [&]() {
if( !eff_only ) {
mod_power_level( bio.info().power_activate );
}
};
for( const effect_on_condition_id &eoc : bio.id->activated_eocs ) {
dialogue d( get_talker_for( *this ), nullptr );
if( eoc->type == eoc_type::ACTIVATION ) {
eoc->activate( d );
} else {
debugmsg( "Must use an activation eoc for a bionic activation. If you don't want the effect_on_condition to happen on its own (without the bionic being activated), remove the recurrence min and max. Otherwise, create a non-recurring effect_on_condition for this bionic with its condition and effects, then have a recurring one queue it." );
}
}
item tmp_item;
avatar &player_character = get_avatar();
map &here = get_map();
// On activation effects go here
if( bio.info().has_flag( json_flag_BIONIC_GUN ) ) {
if( !bio.has_weapon() ) {
debugmsg( "tried to activate gun bionic \"%s\" without fake_weapon",
bio.info().id.str() );
return false;
}
add_msg_activate();
refund_power(); // Power usage calculated later, in avatar_action::fire
if( close_bionics_ui ) {
*close_bionics_ui = true;
}
avatar_action::fire_ranged_bionic( player_character, bio.get_weapon(),
bio.info().power_activate );
} else if( bio.info().has_flag( json_flag_BIONIC_WEAPON ) ) {
if( !bio.has_weapon() ) {
debugmsg( "tried to activate weapon bionic \"%s\" without fake_weapon",
bio.info().id.str() );
refund_power();
bio.powered = false;
return false;
}
if( weapon.has_flag( flag_NO_UNWIELD ) ) {
if( get_weapon_bionic_uid() ) {
if( cata::optional<bionic *> bio_opt = find_bionic_by_uid( get_weapon_bionic_uid() ) ) {
if( deactivate_bionic( **bio_opt, eff_only ) ) {
// restore state and try again
refund_power();
bio.powered = false;
// note: deep recursion is not possible, as `deactivate_bionic` won't return true second time
return activate_bionic( bio, eff_only, close_bionics_ui );
}
} else {
debugmsg( "Can't find currently activated weapon bionic with UID %d", get_weapon_bionic_uid() );
weapon_bionic_uid = 0;
set_wielded_item( item() );
refund_power();
bio.powered = false;
return false;
}
}
add_msg_if_player( m_info, _( "Deactivate your %s first!" ), weapon.tname() );
refund_power();
bio.powered = false;
return false;
}
if( !weapon.is_null() ) {
const std::string query = string_format( _( "Stop wielding %s?" ), weapon.tname() );
if( !dispose_item( item_location( *this, &weapon ), query ) ) {
refund_power();
bio.powered = false;
return false;
}
}
add_msg_activate();
set_wielded_item( bio.get_weapon() );
get_wielded_item()->invlet = '#';
weapon_bionic_uid = bio.get_uid();
} else if( bio.id == bio_evap ) {
add_msg_activate();
const w_point weatherPoint = *get_weather().weather_precise;
int humidity = get_local_humidity( weatherPoint.humidity, get_weather().weather_id,
g->is_sheltered( player_character.pos() ) );
// thirst units = 5 mL
int water_available = std::lround( humidity * 3.0 / 100.0 );
if( water_available == 0 ) {
bio.powered = false;
add_msg_if_player( m_bad, _( "There is not enough humidity in the air for your %s to function." ),
bio.info().name );
return false;
} else if( water_available == 1 ) {
add_msg_if_player( m_mixed,
_( "Your %s issues a low humidity warning. Efficiency will be reduced." ),
bio.info().name );
}
} else if( bio.id == bio_cqb ) {
add_msg_activate();
const avatar *you = as_avatar();
if( you && !martial_arts_data->pick_style( *you ) ) {
bio.powered = false;
add_msg_if_player( m_info, _( "You change your mind and turn it off." ) );
return false;
}
} else if( bio.id == bio_resonator ) {
add_msg_activate();
//~Sound of a bionic sonic-resonator shaking the area
sounds::sound( pos(), 30, sounds::sound_t::combat, _( "VRRRRMP!" ), false, "bionic",
static_cast<std::string>( bio_resonator ) );
for( const tripoint &bashpoint : here.points_in_radius( pos(), 1 ) ) {
here.bash( bashpoint, 110 );
// Multibash effect, so that doors &c will fall
here.bash( bashpoint, 110 );
here.bash( bashpoint, 110 );
}
mod_moves( -100 );
} else if( bio.id == bio_time_freeze ) {
if( mounted ) {
refund_power();
add_msg_if_player( m_info, _( "You cannot activate %s while mounted." ), bio.info().name );
return false;
}
add_msg_activate();
mod_moves( units::to_kilojoule( get_power_level() ) );
set_power_level( 0_kJ );
add_msg_if_player( m_good, _( "Your speed suddenly increases!" ) );
if( one_in( 3 ) ) {
add_msg_if_player( m_bad, _( "Your muscles tear with the strain." ) );
apply_damage( nullptr, bodypart_id( "arm_l" ), rng( 5, 10 ) );
apply_damage( nullptr, bodypart_id( "arm_r" ), rng( 5, 10 ) );
apply_damage( nullptr, bodypart_id( "leg_l" ), rng( 7, 12 ) );
apply_damage( nullptr, bodypart_id( "leg_r" ), rng( 7, 12 ) );
apply_damage( nullptr, bodypart_id( "torso" ), rng( 5, 15 ) );
}
if( one_in( 5 ) ) {
add_effect( effect_teleglow, rng( 5_minutes, 40_minutes ) );
}
} else if( bio.id == bio_teleport ) {
if( mounted ) {
refund_power();
add_msg_if_player( m_info, _( "You cannot activate %s while mounted." ), bio.info().name );
return false;
}
add_msg_activate();
teleport::teleport( *this );
mod_moves( -100 );
} else if( bio.id == bio_blood_anal ) {
add_msg_activate();
conduct_blood_analysis();
} else if( bio.id == bio_blood_filter ) {
add_msg_activate();
static const std::vector<efftype_id> removable = {{
effect_fungus, effect_dermatik, effect_bloodworms,
effect_tetanus, effect_poison, effect_badpoison, effect_stung,
effect_pkill1, effect_pkill2, effect_pkill3, effect_pkill_l,
effect_drunk, effect_cig, effect_high, effect_hallu, effect_visuals,
effect_pblue, effect_iodine, effect_datura,
effect_took_xanax, effect_took_prozac, effect_took_prozac_bad,
effect_took_flumed, effect_antifungal, effect_venom_weaken,
effect_venom_dmg, effect_paralyzepoison
}
};
for( const string_id<effect_type> &eff : removable ) {
remove_effect( eff );
}
// Purging the substance won't remove the fatigue it caused
force_comedown( get_effect( effect_adrenaline ) );
force_comedown( get_effect( effect_meth ) );
set_painkiller( 0 );
set_stim( 0 );
mod_moves( -100 );
} else if( bio.id == bio_torsionratchet ) {
add_msg_activate();
add_msg_if_player( m_info, _( "Your torsion ratchet locks onto your joints." ) );
} else if( bio.id == bio_jointservo ) {
add_msg_activate();
add_msg_if_player( m_info, _( "You can now run faster, assisted by joint servomotors." ) );
} else if( bio.id == bio_lighter ) {
const cata::optional<tripoint> pnt = choose_adjacent( _( "Start a fire where?" ) );
if( pnt && here.is_flammable( *pnt ) ) {
add_msg_activate();
here.add_field( *pnt, fd_fire, 1 );
if( has_trait( trait_PYROMANIA ) ) {
add_morale( MORALE_PYROMANIA_STARTFIRE, 5, 10, 3_hours, 2_hours );
rem_morale( MORALE_PYROMANIA_NOFIRE );
add_msg_if_player( m_good, _( "You happily light a fire." ) );
}
mod_moves( -100 );
} else {
refund_power();
add_msg_if_player( m_info, _( "There's nothing to light there." ) );
return false;
}
} else if( bio.id == bio_geiger ) {
add_msg_activate();
add_msg_if_player( m_info, _( "Your radiation level: %d" ), get_rad() );
} else if( bio.id == bio_radscrubber ) {
add_msg_activate();
if( get_rad() > 4 ) {
mod_rad( -5 );
} else {
set_rad( 0 );
}
} else if( bio.id == bio_adrenaline ) {
add_msg_activate();
if( has_effect( effect_adrenaline ) ) {
add_msg_if_player( m_bad, _( "Safeguards kick in, and the bionic refuses to activate!" ) );
refund_power();
return false;
} else {
add_msg_activate();
add_effect( effect_adrenaline, 20_minutes );
}
} else if( bio.id == bio_emp ) {
if( const cata::optional<tripoint> pnt = choose_adjacent( _( "Create an EMP where?" ) ) ) {
add_msg_activate();
explosion_handler::emp_blast( *pnt );
mod_moves( -100 );
} else {
refund_power();
return false;
}
} else if( bio.id == bio_hydraulics ) {
add_msg_activate();
add_msg_if_player( m_good, _( "Your muscles hiss as hydraulic strength fills them!" ) );
//~ Sound of hissing hydraulic muscle! (not quite as loud as a car horn)
sounds::sound( pos(), 19, sounds::sound_t::activity, _( "HISISSS!" ), false, "bionic",
static_cast<std::string>( bio_hydraulics ) );
} else if( bio.id == bio_water_extractor ) {
bool no_target = true;
bool extracted = false;
for( item &it : here.i_at( pos() ) ) {
static const units::volume volume_per_water_charge = 500_ml;
if( it.is_corpse() ) {
const int avail = it.get_var( "remaining_water", it.volume() / volume_per_water_charge );
if( avail > 0 ) {
no_target = false;
if( query_yn( _( "Extract water from the %s" ),
colorize( it.tname(), it.color_in_inventory() ) ) ) {
item water( itype_water_clean, calendar::turn, avail );
water.set_item_temperature( it.temperature );
if( liquid_handler::consume_liquid( water ) ) {
add_msg_activate();
extracted = true;
it.set_var( "remaining_water", static_cast<int>( water.charges ) );
}
break;
}
}
}
}
if( no_target ) {
add_msg_if_player( m_bad, _( "There is no suitable corpse on this tile." ) );
}
if( !extracted ) {