forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
faction_camp.cpp
4089 lines (3823 loc) · 175 KB
/
faction_camp.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 "faction_camp.h" // IWYU pragma: associated
#include <algorithm>
#include <cstddef>
#include <list>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>
#include "activity_handlers.h"
#include "avatar.h"
#include "basecamp.h"
#include "calendar.h"
#include "cata_utility.h"
#include "catacharset.h"
#include "clzones.h"
#include "colony.h"
#include "color.h"
#include "coordinate_conversions.h"
#include "coordinates.h"
#include "cursesdef.h"
#include "debug.h"
#include "editmap.h"
#include "enums.h"
#include "faction.h"
#include "game.h"
#include "game_constants.h"
#include "iexamine.h"
#include "input.h"
#include "int_id.h"
#include "inventory.h"
#include "item.h"
#include "item_contents.h"
#include "item_group.h"
#include "item_stack.h"
#include "itype.h"
#include "kill_tracker.h"
#include "line.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "mapgen_functions.h"
#include "memory_fast.h"
#include "messages.h"
#include "mission.h"
#include "mission_companion.h"
#include "npc.h"
#include "npctalk.h"
#include "output.h"
#include "overmap.h"
#include "overmap_ui.h"
#include "overmapbuffer.h"
#include "player_activity.h"
#include "point.h"
#include "recipe.h"
#include "recipe_groups.h"
#include "requirements.h"
#include "rng.h"
#include "skill.h"
#include "stomach.h"
#include "string_formatter.h"
#include "string_id.h"
#include "string_input_popup.h"
#include "translations.h"
#include "type_id.h"
#include "ui.h"
#include "ui_manager.h"
#include "units.h"
#include "value_ptr.h"
#include "veh_type.h"
#include "vehicle.h"
#include "vpart_position.h"
#include "vpart_range.h"
#include "weather.h"
#include "weighted_list.h"
class character_id;
static const activity_id ACT_MOVE_LOOT( "ACT_MOVE_LOOT" );
static const itype_id itype_fungal_seeds( "fungal_seeds" );
static const itype_id itype_log( "log" );
static const itype_id itype_marloss_seed( "marloss_seed" );
static const std::string flag_PLOWABLE( "PLOWABLE" );
static const std::string flag_TREE( "TREE" );
static const zone_type_id zone_type_camp_food( "CAMP_FOOD" );
static const zone_type_id zone_type_camp_storage( "CAMP_STORAGE" );
static const skill_id skill_bashing( "bashing" );
static const skill_id skill_cutting( "cutting" );
static const skill_id skill_dodge( "dodge" );
static const skill_id skill_fabrication( "fabrication" );
static const skill_id skill_gun( "gun" );
static const skill_id skill_mechanics( "mechanics" );
static const skill_id skill_melee( "melee" );
static const skill_id skill_speech( "speech" );
static const skill_id skill_stabbing( "stabbing" );
static const skill_id skill_survival( "survival" );
static const skill_id skill_swimming( "swimming" );
static const skill_id skill_traps( "traps" );
static const skill_id skill_unarmed( "unarmed" );
static const mtype_id mon_bear( "mon_bear" );
static const mtype_id mon_beaver( "mon_beaver" );
static const mtype_id mon_black_rat( "mon_black_rat" );
static const mtype_id mon_chicken( "mon_chicken" );
static const mtype_id mon_chipmunk( "mon_chipmunk" );
static const mtype_id mon_cockatrice( "mon_cockatrice" );
static const mtype_id mon_cougar( "mon_cougar" );
static const mtype_id mon_cow( "mon_cow" );
static const mtype_id mon_coyote( "mon_coyote" );
static const mtype_id mon_deer( "mon_deer" );
static const mtype_id mon_duck( "mon_duck" );
static const mtype_id mon_fox_gray( "mon_fox_gray" );
static const mtype_id mon_fox_red( "mon_fox_red" );
static const mtype_id mon_groundhog( "mon_groundhog" );
static const mtype_id mon_grouse( "mon_grouse" );
static const mtype_id mon_hare( "mon_hare" );
static const mtype_id mon_lemming( "mon_lemming" );
static const mtype_id mon_mink( "mon_mink" );
static const mtype_id mon_moose( "mon_moose" );
static const mtype_id mon_muskrat( "mon_muskrat" );
static const mtype_id mon_opossum( "mon_opossum" );
static const mtype_id mon_otter( "mon_otter" );
static const mtype_id mon_pheasant( "mon_pheasant" );
static const mtype_id mon_pig( "mon_pig" );
static const mtype_id mon_rabbit( "mon_rabbit" );
static const mtype_id mon_squirrel( "mon_squirrel" );
static const mtype_id mon_turkey( "mon_turkey" );
static const mtype_id mon_weasel( "mon_weasel" );
static const mtype_id mon_wolf( "mon_wolf" );
static const trait_id trait_DEBUG_HS( "DEBUG_HS" );
struct mass_volume {
units::mass wgt;
units::volume vol;
int count;
};
namespace base_camps
{
// eventually this will include the start and return functions
struct miss_data {
std::string miss_id;
translation desc;
translation action;
std::string ret_miss_id;
translation ret_desc;
};
recipe_id select_camp_option( const std::map<recipe_id, translation> &pos_options,
const std::string &option );
// eventually this will move to JSON
std::map<std::string, miss_data> miss_info = {{
{
"_faction_upgrade_camp", {
"Upgrade Camp", to_translation( "Upgrade camp" ),
to_translation( "Working to expand your camp!\n" ),
"Recover Ally from Upgrading", to_translation( "Recover Ally from Upgrading" )
}
},
{
"_faction_camp_recall", {
"Emergency Recall", to_translation( "Emergency Recall" ),
to_translation( "Lost in the ether!\n" ),
"Emergency Recall", to_translation( "Emergency Recall" )
}
},
{
"_faction_camp_crafting_", {
"Craft Item", to_translation( "Craft Item" ),
to_translation( "Busy crafting!\n" ),
" (Finish) Crafting", to_translation( " (Finish) Crafting" )
}
},
{
"traveling", {
"Traveling", to_translation( "Traveling" ),
to_translation( "Busy traveling!\n" ),
"Recall ally from traveling", to_translation( "Recall ally from traveling" )
}
},
{
"_faction_camp_gathering", {
"Gather Materials", to_translation( "Gather Materials" ),
to_translation( "Searching for materials to upgrade the camp.\n" ),
"Recover Ally from Gathering", to_translation( "Recover Ally from Gathering" )
}
},
{
"_faction_camp_firewood", {
"Collect Firewood", to_translation( "Collect Firewood" ),
to_translation( "Searching for firewood.\n" ),
"Recover Firewood Gatherers", to_translation( "Recover Firewood Gatherers" )
}
},
{
"_faction_camp_menial", {
"Menial Labor", to_translation( "Menial Labor" ),
to_translation( "Performing menial labor…\n" ),
"Recover Menial Laborer", to_translation( "Recover Menial Laborer" )
}
},
{
"_faction_camp_expansion", {
"Expand Base", to_translation( "Expand Base" ),
to_translation( "Surveying for expansion…\n" ),
"Recover Surveyor", to_translation( "Recover Surveyor" )
}
},
{
"_faction_camp_cut_log", {
"Cut Logs", to_translation( "Cut Logs" ),
to_translation( "Cutting logs in the woods…\n" ),
"Recover Log Cutter", to_translation( "Recover Log Cutter" )
}
},
{
"_faction_camp_clearcut", {
"Clearcut", to_translation( "Clear a forest" ),
to_translation( "Clearing a forest…\n" ),
"Recover Clearcutter", to_translation( "Recover Clearcutter" )
}
},
{
"_faction_camp_hide_site", {
"Setup Hide Site", to_translation( "Setup Hide Site" ),
to_translation( "Setting up a hide site…\n" ),
"Recover Hide Setup", to_translation( "Recover Hide Setup" )
}
},
{
"_faction_camp_hide_trans", {
"Relay Hide Site", to_translation( "Relay Hide Site" ),
to_translation( "Transferring gear to a hide site…\n" ),
"Recover Hide Relay", to_translation( "Recover Hide Relay" )
}
},
{
"_faction_camp_foraging", {
"Camp Forage", to_translation( "Forage for plants" ),
to_translation( "Foraging for edible plants.\n" ),
"Recover Foragers", to_translation( "Recover Foragers" )
}
},
{
"_faction_camp_trapping", {
"Trap Small Game", to_translation( "Trap Small Game" ),
to_translation( "Trapping Small Game.\n" ),
"Recover Trappers", to_translation( "Recover Trappers" )
}
},
{
"_faction_camp_hunting", {
"Hunt Large Animals", to_translation( "Hunt Large Animals" ),
to_translation( "Hunting large animals.\n" ),
"Recover Hunter", to_translation( "Recover Hunter" )
}
},
{
"_faction_camp_om_fortifications", {
"Construct Map Fort", to_translation( "Construct Map Fortifications" ),
to_translation( "Constructing fortifications…\n" ),
"Finish Map Fort", to_translation( "Finish Map Fortifications" )
}
},
{
"_faction_camp_recruit_0", {
"Recruit Companions", to_translation( "Recruit Companions" ),
to_translation( "Searching for recruits.\n" ),
"Recover Recruiter", to_translation( "Recover Recruiter" )
}
},
{
"_faction_camp_scout_0", {
"Scout Mission", to_translation( "Scout Mission" ),
to_translation( "Scouting the region.\n" ),
"Recover Scout", to_translation( "Recover Scout" )
}
},
{
"_faction_camp_combat_0", {
"Combat Patrol", to_translation( "Combat Patrol" ),
to_translation( "Patrolling the region.\n" ),
"Recover Combat Patrol", to_translation( "Recover Combat Patrol" )
}
},
{
"_faction_upgrade_exp_", {
" Expansion Upgrade", to_translation( " Expansion Upgrade" ),
to_translation( "Working to upgrade your expansions!\n" ),
"Recover Ally", to_translation( "Recover Ally" )
}
},
{
"_faction_exp_chop_shop_", {
" Chop Shop", to_translation( " Chop Shop" ),
to_translation( "Working at the chop shop…\n" ),
" (Finish) Chop Shop", to_translation( " (Finish) Chop Shop" )
}
},
{
"_faction_exp_kitchen_cooking_", {
" Kitchen Cooking", to_translation( " Kitchen Cooking" ),
to_translation( "Working in your kitchen!\n" ),
" (Finish) Cooking", to_translation( " (Finish) Cooking" )
}
},
{
"_faction_exp_blacksmith_crafting_", {
" Blacksmithing", to_translation( " Blacksmithing" ),
to_translation( "Working in your blacksmith shop!\n" ),
" (Finish) Smithing", to_translation( " (Finish) Smithing" )
}
},
{
"_faction_exp_plow_", {
" Plow Fields", to_translation( " Plow Fields" ),
to_translation( "Working to plow your fields!\n" ),
" (Finish) Plow Fields", to_translation( " (Finish) Plow fields" )
}
},
{
"_faction_exp_plant_", {
" Plant Fields", to_translation( " Plant Fields" ),
to_translation( "Working to plant your fields!\n" ),
" (Finish) Plant Fields", to_translation( " (Finish) Plant Fields" )
}
},
{
"_faction_exp_harvest_", {
" Harvest Fields", to_translation( " Harvest Fields" ),
to_translation( "Working to harvest your fields!\n" ),
" (Finish) Harvest Fields", to_translation( " (Finish) Harvest Fields" )
}
},
{
"_faction_exp_farm_crafting_", {
" Farm Crafting", to_translation( " Farm Crafting" ),
to_translation( "Working on your farm!\n" ),
" (Finish) Crafting", to_translation( " (Finish) Crafting" )
}
}
}
};
} // namespace base_camps
/**** Forward declaration of utility functions */
/**
* Counts or destroys and drops the bash items of all furniture that matches @ref f in the map tile
* @param comp NPC companion
* @param omt_tgt the targeted OM tile
* @param f furniture you are looking for
* @param chance chance of destruction, 0 to 100
* @param estimate if true, non-destructive count of the furniture
* @param bring_back force the destruction of the furniture and bring back the drop items
*/
int om_harvest_furn( npc &comp, const tripoint &omt_tgt, const furn_id &f, int chance = 100,
bool estimate = false, bool bring_back = true );
// om_harvest_furn helper function that counts the furniture instances
int om_harvest_furn_est( npc &comp, const tripoint &omt_tgt, const furn_id &f, int chance = 100 );
int om_harvest_furn_break( npc &comp, const tripoint &omt_tgt, const furn_id &f,
int chance = 100 );
/// Exact same as om_harvest_furn but functions on terrain
int om_harvest_ter( npc &comp, const tripoint_abs_omt &omt_tgt, const ter_id &t, int chance = 100,
bool estimate = false, bool bring_back = true );
// om_harvest_furn helper function that counts the furniture instances
int om_harvest_ter_est( npc &comp, const tripoint_abs_omt &omt_tgt, const ter_id &t,
int chance = 100 );
int om_harvest_ter_break( npc &comp, const tripoint_abs_omt &omt_tgt, const ter_id &t,
int chance = 100 );
/// Collects all items in @ref omt_tgt with a @ref chance between 0 - 1.0, returns total
/// mass and volume
/// @ref take, whether you take the item or count it
mass_volume om_harvest_itm( npc_ptr comp, const tripoint_abs_omt &omt_tgt, int chance = 100,
bool take = true );
void apply_camp_ownership( const tripoint &camp_pos, int radius );
/*
* Counts or cuts trees into trunks and trunks into logs
* @param omt_tgt the targeted OM tile
* @param chance chance of destruction, 0 to 100
* @param estimate if true, non-destructive count of trees
* @force_cut_trunk if true and estimate is false, chop tree trunks into logs
*/
int om_cutdown_trees( const tripoint_abs_omt &omt_tgt, int chance = 100, bool estimate = false,
bool force_cut_trunk = true );
int om_cutdown_trees_est( const tripoint_abs_omt &omt_tgt, int chance = 100 );
int om_cutdown_trees_logs( const tripoint_abs_omt &omt_tgt, int chance = 100 );
int om_cutdown_trees_trunks( const tripoint_abs_omt &omt_tgt, int chance = 100 );
/// Creates an improvised shelter at @ref omt_tgt and dumps the @ref itms into the building
bool om_set_hide_site( npc &comp, const tripoint_abs_omt &omt_tgt, const std::vector<item *> &itms,
const std::vector<item *> &itms_rem = {} );
/**
* Opens the overmap so that you can select points for missions or constructions.
* @param omt_pos where your camp is, used for calculating travel distances
* @param min_range
* @param range max number of OM tiles the user can select
* @param possible_om_types requires the user to reselect if the OM picked isn't in the list
* @param must_see whether the user can select points in the unknown/fog of war
* @param popup_notice toggles if the user should be shown ranges before being allowed to pick
* @param source if you are selecting multiple points this is where the OM is centered to start
* @param bounce
*/
tripoint_abs_omt om_target_tile(
const tripoint_abs_omt &omt_pos, int min_range = 1, int range = 1,
const std::vector<std::string> &possible_om_types = {}, bool must_see = true,
bool popup_notice = true, const tripoint_abs_omt &source = tripoint_abs_omt( -999, -999, -999 ),
bool bounce = false );
void om_range_mark( const tripoint_abs_omt &origin, int range, bool add_notes = true,
const std::string &message = "Y;X: MAX RANGE" );
void om_line_mark(
const tripoint_abs_omt &origin, const tripoint_abs_omt &dest, bool add_notes = true,
const std::string &message = "R;X: PATH" );
std::vector<tripoint_abs_omt> om_companion_path(
const tripoint_abs_omt &start, int range_start = 90, bool bounce = true );
/**
* Can be used to calculate total trip time for an NPC mission or just the traveling portion.
* Doesn't use the pathingalgorithms yet.
* @param omt_pos start point
* @param omt_tgt target point
* @param work how much time the NPC will stay at the target
* @param trips how many trips back and forth the NPC will make
*/
time_duration companion_travel_time_calc( const tripoint_abs_omt &pos, const tripoint_abs_omt &tgt,
time_duration work, int trips = 1, int haulage = 0 );
time_duration companion_travel_time_calc(
const std::vector<tripoint_abs_omt> &journey, time_duration work, int trips = 1,
int haulage = 0 );
/// Determines how many round trips a given NPC @ref comp will take to move all of the
/// items @ref itms
int om_carry_weight_to_trips( const std::vector<item *> &itms, npc_ptr comp = nullptr );
/// Determines how many trips it takes to move @ref mass and @ref volume of items
/// with @ref carry_mass and @ref carry_volume moved per trip
int om_carry_weight_to_trips( units::mass mass, units::volume volume, units::mass carry_mass,
units::volume carry_volume );
/// Formats the variables into a standard looking description to be displayed in a ynquery window
std::string camp_trip_description( const time_duration &total_time,
const time_duration &working_time,
const time_duration &travel_time,
int distance, int trips, int need_food );
/// Returns a string for display of the selected car so you don't chop shop the wrong one
std::string camp_car_description( vehicle *car );
std::string camp_farm_act( const tripoint &omt_pos, size_t &plots_count, farm_ops operation );
/// Changes the faction food supply by @ref change, 0 returns total food supply, a negative
/// total food supply hurts morale
int camp_food_supply( int change = 0, bool return_days = false );
/// Same as above but takes a time_duration and consumes from faction food supply for that
/// duration of work
int camp_food_supply( time_duration work );
/// Returns the total charges of food time_duration @ref work costs
int time_to_food( time_duration work );
/// Changes the faction respect for you by @ref change, returns repect
int camp_discipline( int change = 0 );
/// Changes the faction opinion for you by @ref change, returns opinion
int camp_morale( int change = 0 );
/*
* check if a companion survives a random encounter
* @param comp the companion
* @param situation what the survivor is doing
* @param favor a number added to the survivor's skills to see if he can avoid the encounter
* @param threat a number indicating how dangerous the encounter is
* TODO: Convert to JSON basic on dynamic line type structure
*/
bool survive_random_encounter( npc &comp, std::string &situation, int favor, int threat );
static bool update_time_left( std::string &entry, const comp_list &npc_list )
{
bool avail = false;
for( auto &comp : npc_list ) {
if( comp->companion_mission_time_ret < calendar:: turn ) {
entry = entry + _( " [DONE]\n" );
avail = true;
} else {
entry = entry + " [" +
to_string( comp->companion_mission_time_ret - calendar::turn ) +
_( " left]\n" );
avail = g->u.has_trait( trait_DEBUG_HS );
}
}
entry = entry + _( "\n\nDo you wish to bring your allies back into your party?" );
return avail;
}
static bool update_time_fixed( std::string &entry, const comp_list &npc_list,
const time_duration &duration )
{
bool avail = false;
for( auto &comp : npc_list ) {
time_duration elapsed = calendar::turn - comp->companion_mission_time;
entry = entry + " " + comp->name + " [" + to_string( elapsed ) + "/" +
to_string( duration ) + "]\n";
avail |= elapsed >= duration;
}
entry = entry + _( "\n\nDo you wish to bring your allies back into your party?" );
return avail;
}
static std::optional<basecamp *> get_basecamp( npc &p, const std::string &camp_type = "default" )
{
tripoint_abs_omt omt_pos = p.global_omt_location();
std::optional<basecamp *> bcp = overmap_buffer.find_camp( omt_pos.xy() );
if( bcp ) {
return bcp;
}
get_map().add_camp( omt_pos, "faction_camp" );
bcp = overmap_buffer.find_camp( omt_pos.xy() );
if( !bcp ) {
return std::nullopt;
}
basecamp *temp_camp = *bcp;
temp_camp->define_camp( omt_pos, camp_type );
return temp_camp;
}
recipe_id base_camps::select_camp_option( const std::map<recipe_id, translation> &pos_options,
const std::string &option )
{
std::vector<recipe_id> pos_name_ids;
std::vector<std::string> pos_names;
for( const auto &it : pos_options ) {
pos_names.push_back( it.second.translated() );
pos_name_ids.push_back( it.first );
}
if( pos_name_ids.size() == 1 ) {
return pos_name_ids.front();
}
const int choice = uilist( _( option ), pos_names );
if( choice < 0 || static_cast<size_t>( choice ) >= pos_name_ids.size() ) {
popup( _( "You choose to wait…" ) );
return recipe_id::NULL_ID();
}
return pos_name_ids[choice];
}
void talk_function::start_camp( npc &p )
{
const tripoint_abs_omt omt_pos = p.global_omt_location();
const oter_id &omt_ref = overmap_buffer.ter( omt_pos );
const auto &pos_camps = recipe_group::get_recipes_by_id( "all_faction_base_types",
omt_ref.id().c_str() );
if( pos_camps.empty() ) {
popup( _( "You cannot build a camp here." ) );
return;
}
const recipe_id camp_type = base_camps::select_camp_option( pos_camps,
_( "Select a camp type:" ) );
if( !camp_type ) {
return;
}
std::vector<std::pair<std::string, tripoint_abs_omt>> om_region =
om_building_region( omt_pos, 1 );
int near_fields = 0;
for( const auto &om_near : om_region ) {
const oter_id &om_type = oter_id( om_near.first );
if( is_ot_match( "field", om_type, ot_match_type::contains ) ) {
near_fields += 1;
}
}
std::vector<std::pair<std::string, tripoint_abs_omt>> om_region_ext =
om_building_region( omt_pos, 3 );
int forests = 0;
int waters = 0;
for( const auto &om_near : om_region_ext ) {
const oter_id &om_type = oter_id( om_near.first );
if( is_ot_match( "faction_base", om_type, ot_match_type::contains ) ) {
popup( _( "You are too close to another camp!" ) );
return;
} else if( is_ot_match( "forest", om_type, ot_match_type::contains ) ) {
forests++;
} else if( is_ot_match( "river", om_type, ot_match_type::contains ) ) {
waters++;
}
}
bool display = false;
std::string buffer = _( "Warning, you have selected a region with the following issues:\n\n" );
if( forests < 3 ) {
display = true;
buffer += _( "There are few forests. Wood is your primary construction material.\n" );
}
if( waters == 0 ) {
display = true;
buffer += _( "There are few large clean-ish water sources.\n" );
}
if( near_fields < 4 ) {
display = true;
buffer += _( "There are few fields. Farming may be difficult.\n" );
}
if( display && !query_yn( _( "%s\nAre you sure you wish to continue?" ), buffer ) ) {
return;
}
const recipe &making = camp_type.obj();
if( !run_mapgen_update_func( making.get_blueprint(), omt_pos ) ) {
popup( _( "%s failed to start the %s basecamp, perhaps there is a vehicle in the way." ),
p.disp_name(), making.get_blueprint() );
return;
}
get_basecamp( p, camp_type.str() );
}
void talk_function::recover_camp( npc &p )
{
const tripoint_abs_omt omt_pos = p.global_omt_location();
const std::string &omt_ref = overmap_buffer.ter( omt_pos ).id().c_str();
if( omt_ref.find( "faction_base_camp" ) == std::string::npos ) {
popup( _( "There is no faction camp here to recover!" ) );
return;
}
get_basecamp( p );
}
void talk_function::remove_overseer( npc &p )
{
size_t suffix = p.name.find( _( ", Camp Manager" ) );
if( suffix != std::string::npos ) {
p.name = p.name.substr( 0, suffix );
}
add_msg( _( "%s has abandoned the camp." ), p.name );
p.companion_mission_role_id.clear();
stop_guard( p );
}
void talk_function::basecamp_mission( npc &p )
{
const std::string title = _( "Base Missions" );
const tripoint_abs_omt omt_pos = p.global_omt_location();
mission_data mission_key;
std::optional<basecamp *> temp_camp = get_basecamp( p );
if( !temp_camp ) {
return;
}
basecamp *bcp = *temp_camp;
bcp->set_by_radio( g->u.dialogue_by_radio );
if( bcp->get_dumping_spot() == tripoint_zero ) {
map &here = get_map();
auto &mgr = zone_manager::get_manager();
if( here.check_vehicle_zones( g->get_levz() ) ) {
mgr.cache_vzones();
}
tripoint src_loc;
const auto abspos = p.global_square_location();
if( mgr.has_near( zone_type_camp_storage, abspos, 60 ) ) {
const auto &src_set = mgr.get_near( zone_type_camp_storage, abspos );
const auto &src_sorted = get_sorted_tiles_by_distance( abspos, src_set );
// Find the nearest unsorted zone to dump objects at
for( auto &src : src_sorted ) {
src_loc = here.getlocal( src );
break;
}
}
bcp->set_dumping_spot( here.getabs( src_loc ) );
}
bcp->get_available_missions( mission_key );
if( display_and_choose_opts( mission_key, omt_pos, base_camps::id, title ) ) {
bcp->handle_mission( mission_key.cur_key.id, mission_key.cur_key.dir );
}
}
void basecamp::add_available_recipes( mission_data &mission_key, point dir,
const std::map<recipe_id, translation> &craft_recipes )
{
const std::string dir_id = base_camps::all_directions.at( dir ).id;
const std::string dir_abbr = base_camps::all_directions.at( dir ).bracket_abbr.translated();
for( const auto &recipe_data : craft_recipes ) {
const std::string id = dir_id + recipe_data.first.str();
const std::string &title_e = dir_abbr + recipe_data.second;
const std::string &entry = craft_description( recipe_data.first );
const recipe &recp = recipe_data.first.obj();
bool craftable = recp.deduped_requirements().can_make_with_inventory(
_inv, recp.get_component_filter() );
mission_key.add_start( id, title_e, dir, entry, craftable );
}
}
void basecamp::get_available_missions_by_dir( mission_data &mission_key, point dir )
{
std::string entry;
std::string gather_bldg = "null";
const std::string dir_id = base_camps::all_directions.at( dir ).id;
const std::string dir_abbr = base_camps::all_directions.at( dir ).bracket_abbr.translated();
const tripoint_abs_omt omt_trg = omt_pos + dir;
if( dir != base_camps::base_dir ) {
// return legacy workers
comp_list npc_list = get_mission_workers( "_faction_upgrade_exp_" + dir_id );
if( !npc_list.empty() ) {
const base_camps::miss_data &miss_info = base_camps::miss_info[ "_faction_upgrade_exp_" ];
entry = miss_info.action.translated();
bool avail = update_time_left( entry, npc_list );
mission_key.add_return( "Recover Ally, " + dir_id + " Expansion",
_( "Recover Ally, " ) + dir_abbr + _( " Expansion" ), dir,
entry, avail );
}
// Generate upgrade missions for expansions
for( const basecamp_upgrade &upgrade : available_upgrades( dir ) ) {
const base_camps::miss_data &miss_info = base_camps::miss_info[ "_faction_upgrade_exp_" ];
comp_list npc_list = get_mission_workers( upgrade.bldg + "_faction_upgrade_exp_" +
dir_id );
if( npc_list.empty() ) {
entry = om_upgrade_description( upgrade.bldg );
mission_key.add_start( dir_id + miss_info.miss_id + upgrade.bldg,
dir_abbr + miss_info.desc + " " + upgrade.name, dir, entry,
upgrade.avail );
} else {
entry = miss_info.action.translated();
bool avail = update_time_left( entry, npc_list );
mission_key.add_return( "Recover Ally, " + dir_id + " Expansion" + upgrade.bldg,
_( "Recover Ally, " ) + dir_abbr + _( " Expansion" ) +
" " + upgrade.name, dir, entry, avail );
}
}
}
if( has_provides( "gathering", dir ) ) {
comp_list npc_list = get_mission_workers( "_faction_camp_gathering" );
const base_camps::miss_data &miss_info = base_camps::miss_info[ "_faction_camp_gathering" ];
entry = string_format( _( "Notes:\n"
"Send a companion to gather materials for the next camp "
"upgrade.\n\n"
"Skill used: survival\n"
"Difficulty: N/A\n"
"Gathering Possibilities:\n"
"%s\n"
"Risk: Very Low\n"
"Time: 3 Hours, Repeated\n"
"Positions: %d/3\n" ), gathering_description( gather_bldg ),
npc_list.size() );
mission_key.add_start( miss_info.miss_id, miss_info.desc.translated(), dir,
entry, npc_list.size() < 3 );
if( !npc_list.empty() ) {
entry = miss_info.action.translated();
bool avail = update_time_fixed( entry, npc_list, 3_hours );
mission_key.add_return( miss_info.ret_miss_id, miss_info.ret_desc.translated(),
dir, entry, avail );
}
}
if( has_provides( "firewood", dir ) ) {
comp_list npc_list = get_mission_workers( "_faction_camp_firewood" );
const base_camps::miss_data &miss_info = base_camps::miss_info[ "_faction_camp_firewood" ];
entry = string_format( _( "Notes:\n"
"Send a companion to gather light brush and heavy sticks.\n\n"
"Skill used: survival\n"
"Difficulty: N/A\n"
"Gathering Possibilities:\n"
"> heavy sticks\n"
"> withered plants\n"
"> splintered wood\n\n"
"Risk: Very Low\n"
"Time: 3 Hours, Repeated\n"
"Positions: %d/3\n" ), npc_list.size() );
mission_key.add_start( miss_info.miss_id, miss_info.desc.translated(), std::nullopt,
entry, npc_list.size() < 3 );
if( !npc_list.empty() ) {
entry = miss_info.action.translated();
bool avail = update_time_fixed( entry, npc_list, 3_hours );
mission_key.add_return( miss_info.ret_miss_id, miss_info.ret_desc.translated(),
std::nullopt, entry, avail );
}
}
if( has_provides( "sorting", dir ) ) {
comp_list npc_list = get_mission_workers( "_faction_camp_menial" );
const base_camps::miss_data &miss_info = base_camps::miss_info[ "_faction_camp_menial" ];
entry = string_format( _( "Notes:\n"
"Send a companion to do low level chores and sort "
"supplies.\n\n"
"Skill used: fabrication\n"
"Difficulty: N/A\n"
"Effects:\n"
"> Material left in the unsorted loot zone will be sorted "
"into a defined loot zone."
"\n\nRisk: None\n"
"Time: 3 Hours\n"
"Positions: %d/1\n" ), npc_list.size() );
mission_key.add_start( miss_info.miss_id, miss_info.desc.translated(), std::nullopt,
entry, npc_list.empty() );
if( !npc_list.empty() ) {
entry = miss_info.action.translated();
bool avail = update_time_left( entry, npc_list );
mission_key.add_return( miss_info.ret_miss_id, miss_info.ret_desc.translated(),
std::nullopt, entry, avail );
}
}
if( has_provides( "logging", dir ) ) {
comp_list npc_list = get_mission_workers( "_faction_camp_cut_log" );
const base_camps::miss_data &miss_info = base_camps::miss_info[ "_faction_camp_cut_log" ];
entry = string_format( _( "Notes:\n"
"Send a companion to a nearby forest to cut logs.\n\n"
"Skill used: fabrication\n"
"Difficulty: 1\n"
"Effects:\n"
"> 50%% of trees/trunks at the forest position will be "
"cut down.\n"
"> 100%% of total material will be brought back.\n"
"> Repeatable with diminishing returns.\n"
"> Will eventually turn forests into fields.\n"
"Risk: None\n"
"Time: 6 Hour Base + Travel Time + Cutting Time\n"
"Positions: %d/1\n" ), npc_list.size() );
mission_key.add_start( miss_info.miss_id, miss_info.desc.translated(), std::nullopt,
entry, npc_list.empty() );
if( !npc_list.empty() ) {
entry = miss_info.action.translated();
bool avail = update_time_left( entry, npc_list );
mission_key.add_return( miss_info.ret_miss_id, miss_info.ret_desc.translated(),
std::nullopt, entry, avail );
}
}
if( has_provides( "logging", dir ) ) {
comp_list npc_list = get_mission_workers( "_faction_camp_clearcut" );
const base_camps::miss_data &miss_info = base_camps::miss_info[ "_faction_camp_clearcut" ];
entry = string_format( _( "Notes:\n"
"Send a companion to a clear a nearby forest.\n\n"
"Skill used: fabrication\n"
"Difficulty: 1\n"
"Effects:\n"
"> 95%% of trees/trunks at the forest position"
" will be cut down.\n"
"> 0%% of total material will be brought back.\n"
"> Forest should become a field tile.\n"
"> Useful for clearing land for another faction camp.\n\n"
"Risk: None\n"
"Time: 6 Hour Base + Travel Time + Cutting Time\n"
"Positions: %d/1\n" ), npc_list.size() );
mission_key.add_start( miss_info.miss_id, miss_info.desc.translated(), std::nullopt,
entry, npc_list.empty() );
if( !npc_list.empty() ) {
entry = miss_info.action.translated();
bool avail = update_time_left( entry, npc_list );
mission_key.add_return( miss_info.ret_miss_id, miss_info.ret_desc.translated(),
std::nullopt, entry, avail );
}
}
if( has_provides( "relaying", dir ) ) {
comp_list npc_list = get_mission_workers( "_faction_camp_hide_site" );
const base_camps::miss_data &miss_info = base_camps::miss_info[ "_faction_camp_hide_site" ];
entry = string_format( _( "Notes:\n"
"Send a companion to build an improvised shelter and stock it "
"with equipment at a distant map location.\n\n"
"Skill used: survival\n"
"Difficulty: 3\n"
"Effects:\n"
"> Good for setting up resupply or contingency points.\n"
"> Gear is left unattended and could be stolen.\n"
"> Time dependent on weight of equipment being sent forward.\n\n"
"Risk: Medium\n"
"Time: 6 Hour Construction + Travel\n"
"Positions: %d/1\n" ), npc_list.size() );
mission_key.add_start( miss_info.miss_id, miss_info.desc.translated(), std::nullopt,
entry, npc_list.empty() );
if( !npc_list.empty() ) {
entry = miss_info.action.translated();
bool avail = update_time_left( entry, npc_list );
mission_key.add_return( miss_info.ret_miss_id, miss_info.ret_desc.translated(),
std::nullopt, entry, avail );
}
}
if( has_provides( "relaying", dir ) ) {
comp_list npc_list = get_mission_workers( "_faction_camp_hide_trans" );
const base_camps::miss_data &miss_info = base_camps::miss_info[ "_faction_camp_hide_trans" ];
entry = string_format( _( "Notes:\n"
"Push gear out to a hide site or bring gear back from one.\n\n"
"Skill used: survival\n"
"Difficulty: 1\n"
"Effects:\n"
"> Good for returning equipment you left in the hide site "
"shelter.\n"
"> Gear is left unattended and could be stolen.\n"
"> Time dependent on weight of equipment being sent forward or "
"back.\n\n"
"Risk: Medium\n"
"Time: 1 Hour Base + Travel\n"
"Positions: %d/1\n" ), npc_list.size() );
mission_key.add_start( miss_info.miss_id, miss_info.desc.translated(), std::nullopt, entry,
npc_list.empty() );
if( !npc_list.empty() ) {
entry = miss_info.action.translated();
bool avail = update_time_left( entry, npc_list );
mission_key.add_return( miss_info.ret_miss_id, miss_info.ret_desc.translated(),
std::nullopt, entry, avail );
}
}
if( has_provides( "foraging", dir ) ) {
comp_list npc_list = get_mission_workers( "_faction_camp_foraging" );
const base_camps::miss_data &miss_info = base_camps::miss_info[ "_faction_camp_foraging" ];
entry = string_format( _( "Notes:\n"
"Send a companion to forage for edible plants.\n\n"
"Skill used: survival\n"
"Difficulty: N/A\n"
"Foraging Possibilities:\n"
"> wild vegetables\n"
"> fruits and nuts depending on season\n"
"May produce less food than consumed!\n"
"Risk: Very Low\n"
"Time: 4 Hours, Repeated\n"
"Positions: %d/3\n" ), npc_list.size() );
mission_key.add_start( miss_info.miss_id, miss_info.desc.translated(), dir,
entry, npc_list.size() < 3 );
if( !npc_list.empty() ) {
entry = miss_info.action.translated();
bool avail = update_time_fixed( entry, npc_list, 4_hours );
mission_key.add_return( miss_info.ret_miss_id, miss_info.ret_desc.translated(),
dir, entry, avail );
}
}
if( has_provides( "trapping", dir ) ) {
comp_list npc_list = get_mission_workers( "_faction_camp_trapping" );
const base_camps::miss_data &miss_info = base_camps::miss_info[ "_faction_camp_trapping" ];
entry = string_format( _( "Notes:\n"
"Send a companion to set traps for small game.\n\n"
"Skill used: trapping\n"
"Difficulty: N/A\n"
"Trapping Possibilities:\n"
"> small and tiny animal corpses\n"
"May produce less food than consumed!\n"
"Risk: Low\n"
"Time: 6 Hours, Repeated\n"
"Positions: %d/2\n" ), npc_list.size() );
mission_key.add_start( miss_info.miss_id, miss_info.desc.translated(), dir,
entry, npc_list.size() < 2 );
if( !npc_list.empty() ) {
entry = miss_info.action.translated();
bool avail = update_time_fixed( entry, npc_list, 6_hours );
mission_key.add_return( miss_info.ret_miss_id, miss_info.ret_desc.translated(),
dir, entry, avail );
}
}
if( has_provides( "hunting", dir ) ) {
comp_list npc_list = get_mission_workers( "_faction_camp_hunting" );
const base_camps::miss_data &miss_info = base_camps::miss_info[ "_faction_camp_hunting" ];
entry = string_format( _( "Notes:\n"
"Send a companion to hunt large animals.\n\n"
"Skill used: marksmanship\n"
"Difficulty: N/A\n"
"Hunting Possibilities:\n"
"> small, medium, or large animal corpses\n"
"May produce less food than consumed!\n"
"Risk: Medium\n"
"Time: 6 Hours, Repeated\n"
"Positions: %d/1\n" ), npc_list.size() );
mission_key.add_start( miss_info.miss_id, miss_info.desc.translated(), dir,
entry, npc_list.empty() );
if( !npc_list.empty() ) {
entry = miss_info.action.translated();
bool avail = update_time_fixed( entry, npc_list, 6_hours );
mission_key.add_return( miss_info.ret_miss_id, miss_info.ret_desc.translated(),
dir, entry, avail );
}
}
if( has_provides( "walls", dir ) ) {
comp_list npc_list = get_mission_workers( "_faction_camp_om_fortifications" );
const base_camps::miss_data &miss_info =
base_camps::miss_info[ "_faction_camp_om_fortifications" ];
entry = om_upgrade_description( "faction_wall_level_N_0" );
mission_key.add_start( "Construct Map Fort", _( "Construct Map Fortifications" ),
dir, entry, npc_list.empty() );
entry = om_upgrade_description( "faction_wall_level_N_1" );
mission_key.add_start( "Construct Trench", _( "Construct Spiked Trench" ), dir, entry,
npc_list.empty() );
if( !npc_list.empty() ) {
entry = miss_info.action.translated();
bool avail = update_time_left( entry, npc_list );
mission_key.add_return( miss_info.ret_miss_id, miss_info.ret_desc.translated(),
std::nullopt, entry, avail );
}
}
if( has_provides( "recruiting", dir ) ) {
comp_list npc_list = get_mission_workers( "_faction_camp_recruit_0" );
const base_camps::miss_data &miss_info = base_camps::miss_info[ "_faction_camp_recruit_0" ];
entry = recruit_description( npc_list.size() );
mission_key.add_start( miss_info.miss_id, miss_info.desc.translated(), dir, entry,
npc_list.empty() );
if( !npc_list.empty() ) {
entry = miss_info.action.translated();