forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpc.cpp
3883 lines (3493 loc) · 130 KB
/
npc.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 "npc.h"
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <limits>
#include <memory>
#include <ostream>
#include "activity_type.h"
#include "activity_actor_definitions.h"
#include "auto_pickup.h"
#include "basecamp.h"
#include "bodypart.h"
#include "catacharset.h"
#include "character.h"
#include "character_id.h"
#include "character_martial_arts.h"
#include "clzones.h"
#include "coordinate_conversions.h"
#include "creature_tracker.h"
#include "cursesdef.h"
#include "damage.h"
#include "debug.h"
#include "dialogue.h"
#include "dialogue_chatbin.h"
#include "effect.h"
#include "effect_on_condition.h"
#include "enums.h"
#include "event.h"
#include "event_bus.h"
#include "faction.h"
#include "flag.h"
#include "game.h"
#include "game_constants.h"
#include "game_inventory.h"
#include "item.h"
#include "item_group.h"
#include "itype.h"
#include "iuse.h"
#include "iuse_actor.h"
#include "json.h"
#include "magic.h"
#include "make_static.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "messages.h"
#include "mission.h"
#include "monster.h"
#include "morale_types.h"
#include "mtype.h"
#include "mutation.h"
#include "npc_class.h"
#include "npctrade.h"
#include "npctrade_utils.h"
#include "npctalk.h"
#include "options.h"
#include "output.h"
#include "overmap.h"
#include "overmapbuffer.h"
#include "pathfinding.h"
#include "player_activity.h"
#include "ret_val.h"
#include "rng.h"
#include "skill.h"
#include "sounds.h"
#include "stomach.h"
#include "string_formatter.h"
#include "talker.h"
#include "talker_npc.h"
#include "text_snippets.h"
#include "tileray.h"
#include "trait_group.h"
#include "translations.h"
#include "units.h"
#include "value_ptr.h"
#include "veh_type.h"
#include "vehicle.h"
#include "viewer.h"
#include "visitable.h"
#include "vpart_position.h"
#include "vpart_range.h"
#include "name.h"
static const efftype_id effect_bouldering( "bouldering" );
static const efftype_id effect_contacts( "contacts" );
static const efftype_id effect_controlled( "controlled" );
static const efftype_id effect_drunk( "drunk" );
static const efftype_id effect_high( "high" );
static const efftype_id effect_infection( "infection" );
static const efftype_id effect_mending( "mending" );
static const efftype_id effect_npc_flee_player( "npc_flee_player" );
static const efftype_id effect_npc_suspend( "npc_suspend" );
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_ridden( "ridden" );
static const efftype_id effect_riding( "riding" );
static const faction_id faction_amf( "amf" );
static const faction_id faction_no_faction( "no_faction" );
static const faction_id faction_your_followers( "your_followers" );
static const item_group_id Item_spawn_data_guns_pistol_common( "guns_pistol_common" );
static const item_group_id Item_spawn_data_guns_rifle_common( "guns_rifle_common" );
static const item_group_id Item_spawn_data_guns_shotgun_common( "guns_shotgun_common" );
static const item_group_id Item_spawn_data_guns_smg_common( "guns_smg_common" );
static const item_group_id Item_spawn_data_npc_eyes( "npc_eyes" );
static const item_group_id Item_spawn_data_survivor_bashing( "survivor_bashing" );
static const item_group_id Item_spawn_data_survivor_cutting( "survivor_cutting" );
static const item_group_id Item_spawn_data_survivor_stabbing( "survivor_stabbing" );
static const json_character_flag json_flag_HYPEROPIC( "HYPEROPIC" );
static const mfaction_str_id monfaction_bee( "bee" );
static const mfaction_str_id monfaction_human( "human" );
static const mfaction_str_id monfaction_player( "player" );
static const overmap_location_str_id overmap_location_source_of_ammo( "source_of_ammo" );
static const overmap_location_str_id overmap_location_source_of_anything( "source_of_anything" );
static const overmap_location_str_id overmap_location_source_of_drink( "source_of_drink" );
static const overmap_location_str_id overmap_location_source_of_food( "source_of_food" );
static const overmap_location_str_id overmap_location_source_of_guns( "source_of_guns" );
static const overmap_location_str_id overmap_location_source_of_safety( "source_of_safety" );
static const overmap_location_str_id overmap_location_source_of_weapons( "source_of_weapons" );
static const skill_id skill_archery( "archery" );
static const skill_id skill_bashing( "bashing" );
static const skill_id skill_cutting( "cutting" );
static const skill_id skill_pistol( "pistol" );
static const skill_id skill_rifle( "rifle" );
static const skill_id skill_shotgun( "shotgun" );
static const skill_id skill_smg( "smg" );
static const skill_id skill_speech( "speech" );
static const skill_id skill_stabbing( "stabbing" );
static const skill_id skill_throw( "throw" );
static const trait_id trait_BEE( "BEE" );
static const trait_id trait_CANNIBAL( "CANNIBAL" );
static const trait_id trait_DEBUG_MIND_CONTROL( "DEBUG_MIND_CONTROL" );
static const trait_id trait_HALLUCINATION( "HALLUCINATION" );
static const trait_id trait_ILLITERATE( "ILLITERATE" );
static const trait_id trait_MUTE( "MUTE" );
static const trait_id trait_PROF_DICEMASTER( "PROF_DICEMASTER" );
static const trait_id trait_PSYCHOPATH( "PSYCHOPATH" );
static const trait_id trait_SAPIOVORE( "SAPIOVORE" );
static const trait_id trait_SQUEAMISH( "SQUEAMISH" );
static const trait_id trait_TERRIFYING( "TERRIFYING" );
class monfaction;
static void starting_clothes( npc &who, const npc_class_id &type, bool male );
static void starting_inv( npc &who, const npc_class_id &type );
bool job_data::set_task_priority( const activity_id &task, int new_priority )
{
auto it = task_priorities.find( task );
if( it != task_priorities.end() ) {
task_priorities[task] = new_priority;
return true;
}
return false;
}
void job_data::clear_all_priorities()
{
for( auto &elem : task_priorities ) {
elem.second = 0;
}
}
bool job_data::has_job() const
{
for( const auto &elem : task_priorities ) {
if( elem.second > 0 ) {
return true;
}
}
return false;
}
int job_data::get_priority_of_job( const activity_id &req_job ) const
{
auto it = task_priorities.find( req_job );
if( it != task_priorities.end() ) {
return it->second;
} else {
return 0;
}
}
std::vector<activity_id> job_data::get_prioritised_vector() const
{
std::vector<std::pair<activity_id, int>> pairs( begin( task_priorities ), end( task_priorities ) );
std::vector<activity_id> ret;
sort( begin( pairs ), end( pairs ), []( const std::pair<activity_id, int> &a,
const std::pair<activity_id, int> &b ) {
return a.second > b.second;
} );
ret.reserve( pairs.size() );
for( const std::pair<activity_id, int> &elem : pairs ) {
ret.push_back( elem.first );
}
return ret;
}
npc::npc()
: restock( calendar::turn_zero )
, companion_mission_time( calendar::before_time_starts )
, companion_mission_time_ret( calendar::before_time_starts )
{
last_updated = calendar::turn;
last_player_seen_pos = cata::nullopt;
last_seen_player_turn = 999;
wanted_item_pos = tripoint_min;
guard_pos = cata::nullopt;
goal = tripoint_abs_omt( tripoint_min );
fetching_item = false;
has_new_items = true;
worst_item_value = 0;
str_max = 0;
dex_max = 0;
int_max = 0;
per_max = 0;
marked_for_death = false;
death_drops = true;
dead = false;
hit_by_player = false;
hallucination = false;
moves = 100;
mission = NPC_MISSION_NULL;
myclass = npc_class_id::NULL_ID();
fac_id = faction_id::NULL_ID();
patience = 0;
attitude = NPCATT_NULL;
*path_settings = pathfinding_settings( 0, 1000, 1000, 10, true, true, true, false, true );
for( direction threat_dir : npc_threat_dir ) {
ai_cache.threat_map[ threat_dir ] = 0.0f;
}
}
standard_npc::standard_npc( const std::string &name, const tripoint &pos,
const std::vector<std::string> &clothing,
int sk_lvl, int s_str, int s_dex, int s_int, int s_per )
{
this->name = name;
set_pos_only( pos );
str_cur = std::max( s_str, 0 );
str_max = std::max( s_str, 0 );
dex_cur = std::max( s_dex, 0 );
dex_max = std::max( s_dex, 0 );
per_cur = std::max( s_per, 0 );
per_max = std::max( s_per, 0 );
int_cur = std::max( s_int, 0 );
int_max = std::max( s_int, 0 );
set_body();
recalc_hp();
for( const Skill &e : Skill::skills ) {
set_skill_level( e.ident(), std::max( sk_lvl, 0 ) );
}
for( const std::string &e : clothing ) {
wear_item( item( e ), false );
}
worn.set_fitted();
}
npc::npc( npc && ) noexcept( map_is_noexcept ) = default;
npc &npc::operator=( npc && ) noexcept( list_is_noexcept ) = default;
static std::map<string_id<npc_template>, npc_template> npc_templates;
void npc_template::load( const JsonObject &jsobj )
{
npc_template tem;
npc &guy = tem.guy;
guy.idz = npc_class_id( jsobj.get_string( "id" ) );
guy.name.clear();
jsobj.read( "name_unique", tem.name_unique );
jsobj.read( "name_suffix", tem.name_suffix );
if( jsobj.has_string( "gender" ) ) {
if( jsobj.get_string( "gender" ) == "male" ) {
tem.gender_override = gender::male;
} else {
tem.gender_override = gender::female;
}
} else {
tem.gender_override = gender::random;
}
if( jsobj.has_string( "faction" ) ) {
guy.set_fac_id( jsobj.get_string( "faction" ) );
}
if( jsobj.has_int( "class" ) ) {
guy.myclass = npc_class::from_legacy_int( jsobj.get_int( "class" ) );
} else if( jsobj.has_string( "class" ) ) {
guy.myclass = npc_class_id( jsobj.get_string( "class" ) );
}
guy.set_attitude( static_cast<npc_attitude>( jsobj.get_int( "attitude" ) ) );
guy.mission = static_cast<npc_mission>( jsobj.get_int( "mission" ) );
guy.chatbin.first_topic = jsobj.get_string( "chat" );
if( jsobj.has_string( "mission_offered" ) ) {
guy.miss_ids.emplace_back( mission_type_id( jsobj.get_string( "mission_offered" ) ) );
} else if( jsobj.has_array( "mission_offered" ) ) {
for( const std::string line : jsobj.get_array( "mission_offered" ) ) {
guy.miss_ids.emplace_back( mission_type_id( line ) );
}
}
if( jsobj.has_string( "talk_radio" ) ) {
guy.chatbin.talk_radio = jsobj.get_string( "talk_radio" );
}
if( jsobj.has_string( "talk_leader" ) ) {
guy.chatbin.talk_leader = jsobj.get_string( "talk_leader" );
}
if( jsobj.has_string( "talk_friend" ) ) {
guy.chatbin.talk_friend = jsobj.get_string( "talk_friend" );
}
if( jsobj.has_string( "talk_stole_item" ) ) {
guy.chatbin.talk_stole_item = jsobj.get_string( "talk_stole_item" );
}
if( jsobj.has_string( "talk_wake_up" ) ) {
guy.chatbin.talk_wake_up = jsobj.get_string( "talk_wake_up" );
}
if( jsobj.has_string( "talk_mug" ) ) {
guy.chatbin.talk_mug = jsobj.get_string( "talk_mug" );
}
if( jsobj.has_string( "talk_stranger_aggressive" ) ) {
guy.chatbin.talk_stranger_aggressive = jsobj.get_string( "talk_stranger_aggressive" );
}
if( jsobj.has_string( "talk_stranger_scared" ) ) {
guy.chatbin.talk_stranger_scared = jsobj.get_string( "talk_stranger_scared" );
}
if( jsobj.has_string( "talk_stranger_wary" ) ) {
guy.chatbin.talk_stranger_wary = jsobj.get_string( "talk_stranger_wary" );
}
if( jsobj.has_string( "talk_stranger_friendly" ) ) {
guy.chatbin.talk_stranger_friendly = jsobj.get_string( "talk_stranger_friendly" );
}
if( jsobj.has_string( "talk_stranger_neutral" ) ) {
guy.chatbin.talk_stranger_neutral = jsobj.get_string( "talk_stranger_neutral" );
}
if( jsobj.has_string( "talk_friend_guard" ) ) {
guy.chatbin.talk_friend_guard = jsobj.get_string( "talk_friend_guard" );
}
if( jsobj.has_string( "<acknowledged>" ) ) {
guy.chatbin.snip_acknowledged = jsobj.get_string( "<acknowledged>" );
}
if( jsobj.has_string( "<camp_food_thanks>" ) ) {
guy.chatbin.snip_camp_food_thanks = jsobj.get_string( "<camp_food_thanks>" );
}
if( jsobj.has_string( "<camp_larder_empty>" ) ) {
guy.chatbin.snip_camp_larder_empty = jsobj.get_string( "<camp_larder_empty>" );
}
if( jsobj.has_string( "<camp_water_thanks>" ) ) {
guy.chatbin.snip_camp_water_thanks = jsobj.get_string( "<camp_water_thanks>" );
}
if( jsobj.has_string( "<cant_flee>" ) ) {
guy.chatbin.snip_cant_flee = jsobj.get_string( "<cant_flee>" );
}
if( jsobj.has_string( "<close_distance>" ) ) {
guy.chatbin.snip_close_distance = jsobj.get_string( "<close_distance>" );
}
if( jsobj.has_string( "<combat_noise_warning>" ) ) {
guy.chatbin.snip_combat_noise_warning = jsobj.get_string( "<combat_noise_warning>" );
}
if( jsobj.has_string( "<danger_close_distance>" ) ) {
guy.chatbin.snip_danger_close_distance = jsobj.get_string( "<danger_close_distance>" );
}
if( jsobj.has_string( "<done_mugging>" ) ) {
guy.chatbin.snip_done_mugging = jsobj.get_string( "<done_mugging>" );
}
if( jsobj.has_string( "<far_distance>" ) ) {
guy.chatbin.snip_far_distance = jsobj.get_string( "<far_distance>" );
}
if( jsobj.has_string( "<fire_bad>" ) ) {
guy.chatbin.snip_fire_bad = jsobj.get_string( "<fire_bad>" );
}
if( jsobj.has_string( "<fire_in_the_hole_h>" ) ) {
guy.chatbin.snip_fire_in_the_hole_h = jsobj.get_string( "<fire_in_the_hole_h>" );
}
if( jsobj.has_string( "<fire_in_the_hole>" ) ) {
guy.chatbin.snip_fire_in_the_hole = jsobj.get_string( "<fire_in_the_hole>" );
}
if( jsobj.has_string( "<general_danger_h>" ) ) {
guy.chatbin.snip_general_danger_h = jsobj.get_string( "<general_danger_h>" );
}
if( jsobj.has_string( "<general_danger>" ) ) {
guy.chatbin.snip_general_danger = jsobj.get_string( "<general_danger>" );
}
if( jsobj.has_string( "<heal_self>" ) ) {
guy.chatbin.snip_heal_self = jsobj.get_string( "<heal_self>" );
}
if( jsobj.has_string( "<hungry>" ) ) {
guy.chatbin.snip_hungry = jsobj.get_string( "<hungry>" );
}
if( jsobj.has_string( "<im_leaving_you>" ) ) {
guy.chatbin.snip_im_leaving_you = jsobj.get_string( "<im_leaving_you>" );
}
if( jsobj.has_string( "<its_safe_h>" ) ) {
guy.chatbin.snip_its_safe_h = jsobj.get_string( "<its_safe_h>" );
}
if( jsobj.has_string( "<its_safe>" ) ) {
guy.chatbin.snip_its_safe = jsobj.get_string( "<its_safe>" );
}
if( jsobj.has_string( "<keep_up>" ) ) {
guy.chatbin.snip_keep_up = jsobj.get_string( "<keep_up>" );
}
if( jsobj.has_string( "<kill_npc_h>" ) ) {
guy.chatbin.snip_kill_npc_h = jsobj.get_string( "<kill_npc_h>" );
}
if( jsobj.has_string( "<kill_npc>" ) ) {
guy.chatbin.snip_kill_npc = jsobj.get_string( "<kill_npc>" );
}
if( jsobj.has_string( "<kill_player_h>" ) ) {
guy.chatbin.snip_kill_player_h = jsobj.get_string( "<kill_player_h>" );
}
if( jsobj.has_string( "<let_me_pass>" ) ) {
guy.chatbin.snip_let_me_pass = jsobj.get_string( "<let_me_pass>" );
}
if( jsobj.has_string( "<lets_talk>" ) ) {
guy.chatbin.snip_lets_talk = jsobj.get_string( "<lets_talk>" );
}
if( jsobj.has_string( "<medium_distance>" ) ) {
guy.chatbin.snip_medium_distance = jsobj.get_string( "<medium_distance>" );
}
if( jsobj.has_string( "<monster_warning_h>" ) ) {
guy.chatbin.snip_monster_warning_h = jsobj.get_string( "<monster_warning_h>" );
}
if( jsobj.has_string( "<monster_warning>" ) ) {
guy.chatbin.snip_monster_warning = jsobj.get_string( "<monster_warning>" );
}
if( jsobj.has_string( "<movement_noise_warning>" ) ) {
guy.chatbin.snip_movement_noise_warning = jsobj.get_string( "<movement_noise_warning>" );
}
if( jsobj.has_string( "<need_batteries>" ) ) {
guy.chatbin.snip_need_batteries = jsobj.get_string( "<need_batteries>" );
}
if( jsobj.has_string( "<need_booze>" ) ) {
guy.chatbin.snip_need_booze = jsobj.get_string( "<need_booze>" );
}
if( jsobj.has_string( "<need_fuel>" ) ) {
guy.chatbin.snip_need_fuel = jsobj.get_string( "<need_fuel>" );
}
if( jsobj.has_string( "<no_to_thorazine>" ) ) {
guy.chatbin.snip_no_to_thorazine = jsobj.get_string( "<no_to_thorazine>" );
}
if( jsobj.has_string( "<run_away>" ) ) {
guy.chatbin.snip_run_away = jsobj.get_string( "<run_away>" );
}
if( jsobj.has_string( "<speech_warning>" ) ) {
guy.chatbin.snip_speech_warning = jsobj.get_string( "<speech_warning>" );
}
if( jsobj.has_string( "<thirsty>" ) ) {
guy.chatbin.snip_thirsty = jsobj.get_string( "<thirsty>" );
}
if( jsobj.has_string( "<wait>" ) ) {
guy.chatbin.snip_wait = jsobj.get_string( "<wait>" );
}
if( jsobj.has_string( "<warn_sleep>" ) ) {
guy.chatbin.snip_warn_sleep = jsobj.get_string( "<warn_sleep>" );
}
if( jsobj.has_string( "<yawn>" ) ) {
guy.chatbin.snip_yawn = jsobj.get_string( "<yawn>" );
}
if( jsobj.has_string( "<yes_to_lsd>" ) ) {
guy.chatbin.snip_yes_to_lsd = jsobj.get_string( "<yes_to_lsd>" );
}
if( jsobj.has_string( "snip_pulp_zombie" ) ) {
guy.chatbin.snip_pulp_zombie = jsobj.get_string( "snip_pulp_zombie" );
}
if( jsobj.has_string( "snip_heal_player" ) ) {
guy.chatbin.snip_heal_player = jsobj.get_string( "snip_heal_player" );
}
if( jsobj.has_string( "snip_mug_dontmove" ) ) {
guy.chatbin.snip_mug_dontmove = jsobj.get_string( "snip_mug_dontmove" );
}
if( jsobj.has_string( "snip_wound_infected" ) ) {
guy.chatbin.snip_wound_infected = jsobj.get_string( "snip_wound_infected" );
}
if( jsobj.has_string( "snip_wound_bite" ) ) {
guy.chatbin.snip_wound_bite = jsobj.get_string( "snip_wound_bite" );
}
if( jsobj.has_string( "snip_radiation_sickness" ) ) {
guy.chatbin.snip_radiation_sickness = jsobj.get_string( "snip_radiation_sickness" );
}
if( jsobj.has_string( "snip_bleeding" ) ) {
guy.chatbin.snip_bleeding = jsobj.get_string( "snip_bleeding" );
}
if( jsobj.has_string( "snip_bleeding_badly" ) ) {
guy.chatbin.snip_bleeding_badly = jsobj.get_string( "snip_bleeding_badly" );
}
if( jsobj.has_string( "snip_lost_blood" ) ) {
guy.chatbin.snip_lost_blood = jsobj.get_string( "snip_lost_blood" );
}
if( jsobj.has_string( "snip_bye" ) ) {
guy.chatbin.snip_bye = jsobj.get_string( "snip_bye" );
}
if( jsobj.has_string( "snip_consume_cant_accept" ) ) {
guy.chatbin.snip_consume_cant_accept = jsobj.get_string( "snip_consume_cant_accept" );
}
if( jsobj.has_string( "snip_consume_cant_consume" ) ) {
guy.chatbin.snip_consume_cant_consume = jsobj.get_string( "snip_consume_cant_consume" );
}
if( jsobj.has_string( "snip_consume_rotten" ) ) {
guy.chatbin.snip_consume_rotten = jsobj.get_string( "snip_consume_rotten" );
}
if( jsobj.has_string( "snip_consume_eat" ) ) {
guy.chatbin.snip_consume_eat = jsobj.get_string( "snip_consume_eat" );
}
if( jsobj.has_string( "snip_consume_need_item" ) ) {
guy.chatbin.snip_consume_need_item = jsobj.get_string( "snip_consume_need_item" );
}
if( jsobj.has_string( "snip_consume_med" ) ) {
guy.chatbin.snip_consume_med = jsobj.get_string( "snip_consume_med" );
}
if( jsobj.has_string( "snip_consume_nocharge" ) ) {
guy.chatbin.snip_consume_nocharge = jsobj.get_string( "snip_consume_nocharge" );
}
if( jsobj.has_string( "snip_consume_use_med" ) ) {
guy.chatbin.snip_consume_use_med = jsobj.get_string( "snip_consume_use_med" );
}
if( jsobj.has_string( "snip_give_nope" ) ) {
guy.chatbin.snip_give_nope = jsobj.get_string( "snip_give_nope" );
}
if( jsobj.has_string( "snip_give_to_hallucination" ) ) {
guy.chatbin.snip_give_to_hallucination = jsobj.get_string( "snip_give_to_hallucination" );
}
if( jsobj.has_string( "snip_give_cancel" ) ) {
guy.chatbin.snip_give_cancel = jsobj.get_string( "snip_give_cancel" );
}
if( jsobj.has_string( "snip_give_dangerous" ) ) {
guy.chatbin.snip_give_dangerous = jsobj.get_string( "snip_give_dangerous" );
}
if( jsobj.has_string( "snip_give_wield" ) ) {
guy.chatbin.snip_give_wield = jsobj.get_string( "snip_give_wield" );
}
if( jsobj.has_string( "snip_give_weapon_weak" ) ) {
guy.chatbin.snip_give_weapon_weak = jsobj.get_string( "snip_give_weapon_weak" );
}
if( jsobj.has_string( "snip_give_carry" ) ) {
guy.chatbin.snip_give_carry = jsobj.get_string( "snip_give_carry" );
}
if( jsobj.has_string( "snip_give_carry_cant" ) ) {
guy.chatbin.snip_give_carry_cant = jsobj.get_string( "snip_give_carry_cant" );
}
if( jsobj.has_string( "snip_give_carry_cant_few_space" ) ) {
guy.chatbin.snip_give_carry_cant_few_space = jsobj.get_string( "snip_give_carry_cant_few_space" );
}
if( jsobj.has_string( "snip_give_carry_cant_no_space" ) ) {
guy.chatbin.snip_give_carry_cant_no_space = jsobj.get_string( "snip_give_carry_cant_no_space" );
}
if( jsobj.has_string( "snip_give_carry_too_heavy" ) ) {
guy.chatbin.snip_give_carry_too_heavy = jsobj.get_string( "snip_give_carry_too_heavy" );
}
if( jsobj.has_string( "snip_wear" ) ) {
guy.chatbin.snip_wear = jsobj.get_string( "snip_wear" );
}
if( jsobj.has_int( "age" ) ) {
guy.set_base_age( jsobj.get_int( "age" ) );
}
if( jsobj.has_int( "height" ) ) {
guy.set_base_height( jsobj.get_int( "height" ) );
}
for( JsonValue jv : jsobj.get_array( "death_eocs" ) ) {
guy.death_eocs.emplace_back( effect_on_conditions::load_inline_eoc( jv, "" ) );
}
npc_templates.emplace( string_id<npc_template>( guy.idz.str() ), std::move( tem ) );
}
void npc_template::reset()
{
npc_templates.clear();
}
void npc_template::check_consistency()
{
for( const auto &e : npc_templates ) {
const npc &guy = e.second.guy;
if( !guy.myclass.is_valid() ) {
debugmsg( "Invalid NPC class %s", guy.myclass.c_str() );
}
std::string first_topic = guy.chatbin.first_topic;
if( const json_talk_topic *topic = get_talk_topic( first_topic ) ) {
cata::flat_set<std::string> reachable_topics =
topic->get_directly_reachable_topics( true );
if( reachable_topics.count( "TALK_MISSION_OFFER" ) ) {
debugmsg(
"NPC template \"%s\" has dialogue \"%s\" which leads unconditionally to "
"\"TALK_MISSION_OFFER\", which doesn't check for an available mission. "
"You should probably prefer \"TALK_MISSION_LIST\"",
e.first.str(), first_topic );
}
}
}
}
template<>
bool string_id<npc_template>::is_valid() const
{
return npc_templates.count( *this ) > 0;
}
template<>
const npc_template &string_id<npc_template>::obj() const
{
const auto found = npc_templates.find( *this );
if( found == npc_templates.end() ) {
debugmsg( "Tried to get invalid npc: %s", c_str() );
static const npc_template dummy{};
return dummy;
}
return found->second;
}
void npc::load_npc_template( const string_id<npc_template> &ident )
{
auto found = npc_templates.find( ident );
if( found == npc_templates.end() ) {
debugmsg( "Tried to get invalid npc: %s", ident.c_str() );
return;
}
const npc_template &tem = found->second;
const npc &tguy = tem.guy;
idz = tguy.idz;
myclass = npc_class_id( tguy.myclass );
randomize( myclass );
if( tem.gender_override != npc_template::gender::random ) {
male = tem.gender_override == npc_template::gender::male;
}
name = Name::generate( male );
if( !tem.name_unique.empty() ) {
name = tem.name_unique.translated();
}
if( !tem.name_suffix.empty() ) {
//~ %1$s: npc name, %2$s: name suffix
name = string_format( pgettext( "npc name", "%1$s, %2$s" ), name, tem.name_suffix );
}
fac_id = tguy.fac_id;
set_fac( fac_id );
attitude = tguy.attitude;
mission = tguy.mission;
chatbin.first_topic = tguy.chatbin.first_topic;
chatbin.talk_radio = tguy.chatbin.talk_radio;
chatbin.talk_leader = tguy.chatbin.talk_leader;
chatbin.talk_friend = tguy.chatbin.talk_friend;
chatbin.talk_stole_item = tguy.chatbin.talk_stole_item;
chatbin.talk_wake_up = tguy.chatbin.talk_wake_up;
chatbin.talk_mug = tguy.chatbin.talk_mug;
chatbin.talk_stranger_aggressive = tguy.chatbin.talk_stranger_aggressive;
chatbin.talk_stranger_scared = tguy.chatbin.talk_stranger_scared;
chatbin.talk_stranger_wary = tguy.chatbin.talk_stranger_wary;
chatbin.talk_stranger_friendly = tguy.chatbin.talk_stranger_friendly;
chatbin.talk_stranger_neutral = tguy.chatbin.talk_stranger_neutral;
chatbin.talk_friend_guard = tguy.chatbin.talk_friend_guard;
chatbin.snip_acknowledged = tguy.chatbin.snip_acknowledged;
chatbin.snip_camp_food_thanks = tguy.chatbin.snip_camp_food_thanks;
chatbin.snip_camp_larder_empty = tguy.chatbin.snip_camp_larder_empty;
chatbin.snip_camp_water_thanks = tguy.chatbin.snip_camp_water_thanks;
chatbin.snip_cant_flee = tguy.chatbin.snip_cant_flee;
chatbin.snip_close_distance = tguy.chatbin.snip_close_distance;
chatbin.snip_combat_noise_warning = tguy.chatbin.snip_combat_noise_warning;
chatbin.snip_danger_close_distance = tguy.chatbin.snip_danger_close_distance;
chatbin.snip_done_mugging = tguy.chatbin.snip_done_mugging;
chatbin.snip_far_distance = tguy.chatbin.snip_far_distance;
chatbin.snip_fire_bad = tguy.chatbin.snip_fire_bad;
chatbin.snip_fire_in_the_hole_h = tguy.chatbin.snip_fire_in_the_hole_h;
chatbin.snip_fire_in_the_hole = tguy.chatbin.snip_fire_in_the_hole;
chatbin.snip_general_danger_h = tguy.chatbin.snip_general_danger_h;
chatbin.snip_general_danger = tguy.chatbin.snip_general_danger;
chatbin.snip_heal_self = tguy.chatbin.snip_heal_self;
chatbin.snip_hungry = tguy.chatbin.snip_hungry;
chatbin.snip_im_leaving_you = tguy.chatbin.snip_im_leaving_you;
chatbin.snip_its_safe_h = tguy.chatbin.snip_its_safe_h;
chatbin.snip_its_safe = tguy.chatbin.snip_its_safe;
chatbin.snip_keep_up = tguy.chatbin.snip_keep_up;
chatbin.snip_kill_npc_h = tguy.chatbin.snip_kill_npc_h;
chatbin.snip_kill_npc = tguy.chatbin.snip_kill_npc;
chatbin.snip_kill_player_h = tguy.chatbin.snip_kill_player_h;
chatbin.snip_let_me_pass = tguy.chatbin.snip_let_me_pass;
chatbin.snip_lets_talk = tguy.chatbin.snip_lets_talk;
chatbin.snip_medium_distance = tguy.chatbin.snip_medium_distance;
chatbin.snip_monster_warning_h = tguy.chatbin.snip_monster_warning_h;
chatbin.snip_monster_warning = tguy.chatbin.snip_monster_warning;
chatbin.snip_movement_noise_warning = tguy.chatbin.snip_movement_noise_warning;
chatbin.snip_need_batteries = tguy.chatbin.snip_need_batteries;
chatbin.snip_need_booze = tguy.chatbin.snip_need_booze;
chatbin.snip_need_fuel = tguy.chatbin.snip_need_fuel;
chatbin.snip_no_to_thorazine = tguy.chatbin.snip_no_to_thorazine;
chatbin.snip_run_away = tguy.chatbin.snip_run_away;
chatbin.snip_speech_warning = tguy.chatbin.snip_speech_warning;
chatbin.snip_thirsty = tguy.chatbin.snip_thirsty;
chatbin.snip_wait = tguy.chatbin.snip_wait;
chatbin.snip_warn_sleep = tguy.chatbin.snip_warn_sleep;
chatbin.snip_yawn = tguy.chatbin.snip_yawn;
chatbin.snip_yes_to_lsd = tguy.chatbin.snip_yes_to_lsd;
chatbin.snip_pulp_zombie = tguy.chatbin.snip_pulp_zombie;
chatbin.snip_heal_player = tguy.chatbin.snip_heal_player;
chatbin.snip_mug_dontmove = tguy.chatbin.snip_mug_dontmove;
chatbin.snip_wound_infected = tguy.chatbin.snip_wound_infected;
chatbin.snip_wound_bite = tguy.chatbin.snip_wound_bite;
chatbin.snip_radiation_sickness = tguy.chatbin.snip_radiation_sickness;
chatbin.snip_bleeding = tguy.chatbin.snip_bleeding;
chatbin.snip_bleeding_badly = tguy.chatbin.snip_bleeding_badly;
chatbin.snip_lost_blood = tguy.chatbin.snip_lost_blood;
chatbin.snip_bye = tguy.chatbin.snip_bye;
chatbin.snip_consume_cant_accept = tguy.chatbin.snip_consume_cant_accept;
chatbin.snip_consume_cant_consume = tguy.chatbin.snip_consume_cant_consume;
chatbin.snip_consume_rotten = tguy.chatbin.snip_consume_rotten;
chatbin.snip_consume_eat = tguy.chatbin.snip_consume_eat;
chatbin.snip_consume_need_item = tguy.chatbin.snip_consume_need_item;
chatbin.snip_consume_med = tguy.chatbin.snip_consume_med;
chatbin.snip_consume_nocharge = tguy.chatbin.snip_consume_nocharge;
chatbin.snip_consume_use_med = tguy.chatbin.snip_consume_use_med;
chatbin.snip_give_nope = tguy.chatbin.snip_give_nope;
chatbin.snip_give_to_hallucination = tguy.chatbin.snip_give_to_hallucination;
chatbin.snip_give_cancel = tguy.chatbin.snip_give_cancel;
chatbin.snip_give_dangerous = tguy.chatbin.snip_give_dangerous;
chatbin.snip_give_wield = tguy.chatbin.snip_give_wield;
chatbin.snip_give_weapon_weak = tguy.chatbin.snip_give_weapon_weak;
chatbin.snip_give_carry = tguy.chatbin.snip_give_carry;
chatbin.snip_give_carry_cant = tguy.chatbin.snip_give_carry_cant;
chatbin.snip_give_carry_cant_few_space = tguy.chatbin.snip_give_carry_cant_few_space;
chatbin.snip_give_carry_cant_no_space = tguy.chatbin.snip_give_carry_cant_no_space;
chatbin.snip_give_carry_too_heavy = tguy.chatbin.snip_give_carry_too_heavy;
chatbin.snip_wear = tguy.chatbin.snip_wear;
set_base_age( tguy.base_age() );
set_base_height( tguy.base_height() );
for( const mission_type_id &miss_id : tguy.miss_ids ) {
add_new_mission( mission::reserve_new( miss_id, getID() ) );
}
death_eocs = tguy.death_eocs;
}
npc::~npc() = default;
void npc::randomize( const npc_class_id &type )
{
if( !getID().is_valid() ) {
setID( g->assign_npc_id() );
}
set_wielded_item( item( "null", calendar::turn_zero ) );
inv->clear();
personality.aggression = rng( -10, 10 );
personality.bravery = rng( -3, 10 );
personality.collector = rng( -1, 10 );
personality.altruism = rng( -10, 10 );
moves = 100;
mission = NPC_MISSION_NULL;
male = one_in( 2 );
pick_name();
if( !type.is_valid() ) {
debugmsg( "Invalid NPC class %s", type.c_str() );
myclass = npc_class_id::NULL_ID();
} else if( type.is_null() ) {
myclass = npc_class::random_common();
} else {
myclass = type;
}
const npc_class &the_class = myclass.obj();
str_max = the_class.roll_strength();
dex_max = the_class.roll_dexterity();
int_max = the_class.roll_intelligence();
per_max = the_class.roll_perception();
for( Skill &skill : Skill::skills ) {
int level = myclass->roll_skill( skill.ident() );
set_skill_level( skill.ident(), level );
}
if( type.is_null() ) { // Untyped; no particular specialization
} else if( type == NC_EVAC_SHOPKEEP || type == NC_BARTENDER || type == NC_JUNK_SHOPKEEP ) {
personality.collector += rng( 1, 5 );
} else if( type == NC_ARSONIST ) {
personality.aggression += rng( 0, 1 );
personality.collector += rng( 0, 2 );
} else if( type == NC_SOLDIER ) {
personality.aggression += rng( 1, 3 );
personality.bravery += rng( 0, 5 );
} else if( type == NC_HACKER ) {
personality.bravery -= rng( 1, 3 );
personality.aggression -= rng( 0, 2 );
} else if( type == NC_DOCTOR ) {
personality.aggression -= rng( 0, 4 );
cash += 10000 * rng( 0, 3 ) * rng( 0, 3 );
} else if( type == NC_TRADER ) {
personality.collector += rng( 1, 5 );
cash += 25000 * rng( 1, 10 );
} else if( type == NC_NINJA ) {
personality.bravery += rng( 0, 3 );
personality.collector -= rng( 1, 6 );
// TODO: give ninja his styles back
} else if( type == NC_COWBOY ) {
personality.aggression += rng( 0, 2 );
personality.bravery += rng( 1, 5 );
} else if( type == NC_SCIENTIST ) {
personality.aggression -= rng( 1, 5 );
personality.bravery -= rng( 2, 8 );
personality.collector += rng( 0, 2 );
} else if( type == NC_BOUNTY_HUNTER || type == NC_THUG ) {
personality.aggression += rng( 1, 6 );
personality.bravery += rng( 0, 5 );
} else if( type == NC_SCAVENGER ) {
personality.aggression += rng( 1, 3 );
personality.bravery += rng( 1, 4 );
}
//A universal barter boost to keep NPCs competitive with players
//The int boost from trade wasn't active... now that it is, most
//players will vastly outclass npcs in trade without a little help.
mod_skill_level( skill_speech, rng( 2, 4 ) );
set_body();
recalc_hp();
starting_weapon( myclass );
starting_clothes( *this, myclass, male );
starting_inv( *this, myclass );
has_new_items = true;
clear_mutations();
// Add fixed traits
for( const trait_and_var &cur : trait_group::traits_from( myclass->traits ) ) {
const trait_id &tid = cur.trait;
const std::string &var = cur.variant;
set_mutation( tid, tid->variant( var ) );
}
// Run mutation rounds
for( const auto &mr : type->mutation_rounds ) {
int rounds = mr.second.roll();
for( int i = 0; i < rounds; ++i ) {
mutate_category( mr.first );
}
}
// Add bionics
for( const auto &bl : type->bionic_list ) {
int chance = bl.second;
if( rng( 0, 100 ) <= chance ) {
add_bionic( bl.first );
}
}
// Add proficiencies
for( const proficiency_id &prof : type->_starting_proficiencies ) {
add_proficiency( prof );
}
// Add martial arts
learn_ma_styles_from_traits();
// Add spells for magiclysm mod
for( std::pair<spell_id, int> spell_pair : type->_starting_spells ) {
this->magic->learn_spell( spell_pair.first, *this, true );
spell &sp = this->magic->get_spell( spell_pair.first );
while( sp.get_level() < spell_pair.second && !sp.is_max_level() ) {
sp.gain_level();
}
}
// Add eocs
effect_on_conditions::load_new_character( *this );
}
void npc::learn_ma_styles_from_traits()
{
for( const trait_id &iter : get_mutations() ) {
if( !iter->initial_ma_styles.empty() ) {
std::vector<matype_id> shuffled_trait_styles = iter->initial_ma_styles;
std::shuffle( shuffled_trait_styles.begin(), shuffled_trait_styles.end(), rng_get_engine() );
for( const matype_id &style : shuffled_trait_styles ) {
if( !martial_arts_data->has_martialart( style ) ) {
martial_arts_data->learn_style( style, false );
break;
}
}
}
}
}
void npc::randomize_from_faction( faction *fac )
{
// Personality = aggression, bravery, altruism, collector
set_fac( fac->id );
randomize( npc_class_id::NULL_ID() );
}
void npc::set_fac( const faction_id &id )
{
if( my_fac ) {
my_fac->remove_member( getID() );
}
my_fac = g->faction_manager_ptr->get( id );
if( my_fac ) {
if( !is_fake() && !is_hallucination() ) {
my_fac->add_to_membership( getID(), disp_name(), known_to_u );
}
fac_id = my_fac->id;
} else {
return;
}
apply_ownership_to_inv();
}
void npc::apply_ownership_to_inv()
{
for( item *&e : inv_dump() ) {
e->set_owner( *this );
}
}
faction_id npc::get_fac_id() const
{
return fac_id;
}
faction *npc::get_faction() const
{
if( !my_fac ) {
return g->faction_manager_ptr->get( faction_no_faction );
}
return my_fac;
}
// item id from group "<class-name>_<what>" or from fallback group
// may still be a null item!
static item random_item_from( const npc_class_id &type, const std::string &what,
const item_group_id &fallback )
{
item result = item_group::item_from( item_group_id( type.str() + "_" + what ), calendar::turn );
if( result.is_null() ) {
result = item_group::item_from( fallback, calendar::turn );
}
return result;
}
// item id from "<class-name>_<what>" or from "npc_<what>"
static item random_item_from( const npc_class_id &type, const std::string &what )
{
return random_item_from( type, what, item_group_id( "npc_" + what ) );
}
// item id from "<class-name>_<what>_<gender>" or from "npc_<what>_<gender>"
static item get_clothing_item( const npc_class_id &type, const std::string &what, bool male )
{
item result;
//Check if class has gendered clothing
//Then check if it has an ungendered version
//Only if all that fails, grab from the default class.
if( male ) {
result = random_item_from( type, what + "_male", item_group_id::NULL_ID() );
} else {
result = random_item_from( type, what + "_female", item_group_id::NULL_ID() );
}
if( result.is_null() ) {
if( male ) {
result = random_item_from( type, what, item_group_id( "npc_" + what + "_male" ) );
} else {
result = random_item_from( type, what, item_group_id( "npc_" + what + "_female" ) );
}
}
return result;
}
void starting_clothes( npc &who, const npc_class_id &type, bool male )
{
std::vector<item> ret;
if( item_group::group_is_defined( type->worn_override ) ) {
ret = item_group::items_from( type->worn_override );
} else {
ret.push_back( get_clothing_item( type, "pants", male ) );
ret.push_back( get_clothing_item( type, "shirt", male ) );
ret.push_back( get_clothing_item( type, "underwear_top", male ) );
ret.push_back( get_clothing_item( type, "underwear_bottom", male ) );
ret.push_back( get_clothing_item( type, "underwear_feet", male ) );
ret.push_back( get_clothing_item( type, "shoes", male ) );