-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
game.cpp
14157 lines (12718 loc) · 548 KB
/
game.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 "game.h"
#include <algorithm>
#include <bitset>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cwctype>
#include <exception>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#if defined(EMSCRIPTEN)
#include <emscripten.h>
#endif
#include "achievement.h"
#include "action.h"
#include "activity_actor_definitions.h"
#include "activity_handlers.h"
#include "activity_type.h"
#include "ascii_art.h"
#include "auto_note.h"
#include "auto_pickup.h"
#include "avatar.h"
#include "avatar_action.h"
#include "basecamp.h"
#include "bionics.h"
#include "body_part_set.h"
#include "bodygraph.h"
#include "bodypart.h"
#include "butchery_requirements.h"
#include "cached_options.h"
#include "cata_imgui.h"
#include "cata_path.h"
#include "cata_scope_helpers.h"
#include "cata_utility.h"
#include "cata_variant.h"
#include "catacharset.h"
#include "character.h"
#include "character_attire.h"
#include "character_martial_arts.h"
#include "char_validity_check.h"
#include "city.h"
#include "climbing.h"
#include "clzones.h"
#include "colony.h"
#include "color.h"
#include "computer.h"
#include "computer_session.h"
#include "construction.h"
#include "construction_group.h"
#include "contents_change_handler.h"
#include "coordinates.h"
#include "creature_tracker.h"
#include "cuboid_rectangle.h"
#include "cursesport.h" // IWYU pragma: keep
#include "damage.h"
#include "debug.h"
#include "debug_menu.h"
#include "dependency_tree.h"
#include "dialogue.h"
#include "dialogue_chatbin.h"
#include "diary.h"
#include "distraction_manager.h"
#include "editmap.h"
#include "effect.h"
#include "effect_on_condition.h"
#include "end_screen.h"
#include "enums.h"
#include "event.h"
#include "event_bus.h"
#include "faction.h"
#include "fault.h"
#include "field.h"
#include "field_type.h"
#include "filesystem.h"
#include "flag.h"
#include "flexbuffer_json-inl.h"
#include "flexbuffer_json.h"
#include "game_constants.h"
#include "game_inventory.h"
#include "game_ui.h"
#include "gamemode.h"
#include "gates.h"
#include "get_version.h"
#include "harvest.h"
#include "iexamine.h"
#include "imgui/imgui_stdlib.h"
#include "init.h"
#include "input.h"
#include "input_context.h"
#include "input_enums.h"
#include "input_popup.h"
#include "inventory.h"
#include "item.h"
#include "item_category.h"
#include "item_contents.h"
#include "item_location.h"
#include "item_pocket.h"
#include "item_search.h"
#include "item_stack.h"
#include "iteminfo_query.h"
#include "itype.h"
#include "iuse.h"
#include "iuse_actor.h"
#include "json.h"
#include "kill_tracker.h"
#include "level_cache.h"
#include "lightmap.h"
#include "line.h"
#include "live_view.h"
#include "loading_ui.h"
#include "magic.h"
#include "magic_enchantment.h"
#include "main_menu.h"
#include "make_static.h"
#include "map.h"
#include "map_item_stack.h"
#include "map_iterator.h"
#include "map_selector.h"
#include "mapbuffer.h"
#include "mapdata.h"
#include "mapsharing.h"
#include "maptile_fwd.h"
#include "memorial_logger.h"
#include "messages.h"
#include "mission.h"
#include "mod_manager.h"
#include "monexamine.h"
#include "mongroup.h"
#include "monster.h"
#include "monstergenerator.h"
#include "move_mode.h"
#include "mtype.h"
#include "npc.h"
#include "npctrade.h"
#include "omdata.h"
#include "options.h"
#include "output.h"
#include "overmap.h"
#include "overmap_ui.h"
#include "overmapbuffer.h"
#include "panels.h"
#include "past_achievements_info.h"
#include "path_info.h"
#include "pathfinding.h"
#include "pickup.h"
#include "player_activity.h"
#include "popup.h"
#include "profession.h"
#include "proficiency.h"
#include "recipe.h"
#include "recipe_dictionary.h"
#include "ret_val.h"
#include "rng.h"
#include "safemode_ui.h"
#include "scenario.h"
#include "scent_map.h"
#include "scores_ui.h"
#include "sdltiles.h" // IWYU pragma: keep
#include "sounds.h"
#include "start_location.h"
#include "stats_tracker.h"
#include "string_formatter.h"
#include "string_input_popup.h"
#include "talker.h"
#include "text_snippets.h"
#include "tileray.h"
#include "timed_event.h"
#include "translation.h"
#include "translation_cache.h"
#include "translations.h"
#include "trap.h"
#include "ui.h"
#include "ui_extended_description.h"
#include "ui_manager.h"
#include "uistate.h"
#include "units.h"
#include "value_ptr.h"
#include "veh_appliance.h"
#include "veh_interact.h"
#include "veh_type.h"
#include "vehicle.h"
#include "viewer.h"
#include "visitable.h"
#include "vpart_position.h"
#include "vpart_range.h"
#include "wcwidth.h"
#include "weakpoint.h"
#include "weather.h"
#include "weather_type.h"
#include "worldfactory.h"
#if defined(TILES)
#include "sdl_utils.h"
#endif // TILES
#if defined(__clang__) || defined(__GNUC__)
#define UNUSED __attribute__((unused))
#else
#define UNUSED
#endif
static const activity_id ACT_BLEED( "ACT_BLEED" );
static const activity_id ACT_BUTCHER( "ACT_BUTCHER" );
static const activity_id ACT_BUTCHER_FULL( "ACT_BUTCHER_FULL" );
static const activity_id ACT_DISMEMBER( "ACT_DISMEMBER" );
static const activity_id ACT_DISSECT( "ACT_DISSECT" );
static const activity_id ACT_FIELD_DRESS( "ACT_FIELD_DRESS" );
static const activity_id ACT_QUARTER( "ACT_QUARTER" );
static const activity_id ACT_SKIN( "ACT_SKIN" );
static const activity_id ACT_TRAIN( "ACT_TRAIN" );
static const activity_id ACT_TRAIN_TEACHER( "ACT_TRAIN_TEACHER" );
static const activity_id ACT_TRAVELLING( "ACT_TRAVELLING" );
static const ascii_art_id ascii_art_ascii_tombstone( "ascii_tombstone" );
static const bionic_id bio_jointservo( "bio_jointservo" );
static const bionic_id bio_probability_travel( "bio_probability_travel" );
static const bionic_id bio_remote( "bio_remote" );
static const character_modifier_id character_modifier_slip_prevent_mod( "slip_prevent_mod" );
static const climbing_aid_id climbing_aid_ability_WALL_CLING( "ability_WALL_CLING" );
static const climbing_aid_id climbing_aid_default( "default" );
static const climbing_aid_id climbing_aid_furn_CLIMBABLE( "furn_CLIMBABLE" );
static const damage_type_id damage_acid( "acid" );
static const damage_type_id damage_bash( "bash" );
static const damage_type_id damage_cut( "cut" );
static const efftype_id effect_adrenaline_mycus( "adrenaline_mycus" );
static const efftype_id effect_asked_to_train( "asked_to_train" );
static const efftype_id effect_blind( "blind" );
static const efftype_id effect_bouldering( "bouldering" );
static const efftype_id effect_contacts( "contacts" );
static const efftype_id effect_cramped_space( "cramped_space" );
static const efftype_id effect_docile( "docile" );
static const efftype_id effect_downed( "downed" );
static const efftype_id effect_fake_common_cold( "fake_common_cold" );
static const efftype_id effect_fake_flu( "fake_flu" );
static const efftype_id effect_gliding( "gliding" );
static const efftype_id effect_laserlocked( "laserlocked" );
static const efftype_id effect_led_by_leash( "led_by_leash" );
static const efftype_id effect_no_sight( "no_sight" );
static const efftype_id effect_onfire( "onfire" );
static const efftype_id effect_pet( "pet" );
static const efftype_id effect_psi_stunned( "psi_stunned" );
static const efftype_id effect_ridden( "ridden" );
static const efftype_id effect_riding( "riding" );
static const efftype_id effect_stunned( "stunned" );
static const efftype_id effect_tetanus( "tetanus" );
static const efftype_id effect_tied( "tied" );
static const efftype_id effect_took_xanax( "took_xanax" );
static const efftype_id effect_transition_contacts( "transition_contacts" );
static const efftype_id effect_winded( "winded" );
static const faction_id faction_no_faction( "no_faction" );
static const faction_id faction_your_followers( "your_followers" );
static const flag_id json_flag_CANNOT_MOVE( "CANNOT_MOVE" );
static const flag_id json_flag_CONVECTS_TEMPERATURE( "CONVECTS_TEMPERATURE" );
static const flag_id json_flag_LEVITATION( "LEVITATION" );
static const flag_id json_flag_NO_RELOAD( "NO_RELOAD" );
static const flag_id json_flag_SPLINT( "SPLINT" );
static const flag_id json_flag_WATERWALKING( "WATERWALKING" );
static const furn_str_id furn_f_rope_up( "f_rope_up" );
static const furn_str_id furn_f_vine_up( "f_vine_up" );
static const furn_str_id furn_f_web_up( "f_web_up" );
static const harvest_drop_type_id harvest_drop_blood( "blood" );
static const harvest_drop_type_id harvest_drop_offal( "offal" );
static const harvest_drop_type_id harvest_drop_skin( "skin" );
static const itype_id fuel_type_animal( "animal" );
static const itype_id itype_battery( "battery" );
static const itype_id itype_disassembly( "disassembly" );
static const itype_id itype_grapnel( "grapnel" );
static const itype_id itype_manhole_cover( "manhole_cover" );
static const itype_id itype_remotevehcontrol( "remotevehcontrol" );
static const itype_id itype_rope_30( "rope_30" );
static const itype_id itype_swim_fins( "swim_fins" );
static const itype_id itype_towel( "towel" );
static const itype_id itype_towel_wet( "towel_wet" );
static const json_character_flag json_flag_ALL_TERRAIN_NAVIGATION( "ALL_TERRAIN_NAVIGATION" );
static const json_character_flag json_flag_CLIMB_FLYING( "CLIMB_FLYING" );
static const json_character_flag json_flag_CLIMB_NO_LADDER( "CLIMB_NO_LADDER" );
static const json_character_flag json_flag_GRAB( "GRAB" );
static const json_character_flag json_flag_HYPEROPIC( "HYPEROPIC" );
static const json_character_flag json_flag_INFECTION_IMMUNE( "INFECTION_IMMUNE" );
static const json_character_flag json_flag_ITEM_WATERPROOFING( "ITEM_WATERPROOFING" );
static const json_character_flag json_flag_NYCTOPHOBIA( "NYCTOPHOBIA" );
static const json_character_flag json_flag_VINE_RAPPEL( "VINE_RAPPEL" );
static const json_character_flag json_flag_WALL_CLING( "WALL_CLING" );
static const json_character_flag json_flag_WEB_RAPPEL( "WEB_RAPPEL" );
static const mod_id MOD_INFORMATION_Graphical_Overmap( "Graphical_Overmap" );
static const mod_id MOD_INFORMATION_dda( "dda" );
static const mod_id MOD_INFORMATION_sees_player_hitbutton( "sees_player_hitbutton" );
static const mongroup_id GROUP_BLACK_ROAD( "GROUP_BLACK_ROAD" );
static const mtype_id mon_manhack( "mon_manhack" );
static const npc_class_id NC_DOCTOR( "NC_DOCTOR" );
static const npc_class_id NC_HALLU( "NC_HALLU" );
static const overmap_special_id overmap_special_world( "world" );
static const proficiency_id proficiency_prof_parkour( "prof_parkour" );
static const proficiency_id proficiency_prof_wound_care( "prof_wound_care" );
static const proficiency_id proficiency_prof_wound_care_expert( "prof_wound_care_expert" );
static const quality_id qual_BUTCHER( "BUTCHER" );
static const quality_id qual_CUT_FINE( "CUT_FINE" );
static const skill_id skill_dodge( "dodge" );
static const skill_id skill_firstaid( "firstaid" );
static const skill_id skill_gun( "gun" );
static const skill_id skill_survival( "survival" );
static const species_id species_PLANT( "PLANT" );
static const string_id<npc_template> npc_template_cyborg_rescued( "cyborg_rescued" );
static const ter_str_id ter_t_elevator( "t_elevator" );
static const ter_str_id ter_t_grave_new( "t_grave_new" );
static const ter_str_id ter_t_lava( "t_lava" );
static const ter_str_id ter_t_manhole( "t_manhole" );
static const ter_str_id ter_t_manhole_cover( "t_manhole_cover" );
static const ter_str_id ter_t_pit( "t_pit" );
static const ter_str_id ter_t_pit_shallow( "t_pit_shallow" );
static const trait_id trait_BADKNEES( "BADKNEES" );
static const trait_id trait_CENOBITE( "CENOBITE" );
static const trait_id trait_ILLITERATE( "ILLITERATE" );
static const trait_id trait_INATTENTIVE( "INATTENTIVE" );
static const trait_id trait_INFRESIST( "INFRESIST" );
static const trait_id trait_LEG_TENT_BRACE( "LEG_TENT_BRACE" );
static const trait_id trait_MASOCHIST( "MASOCHIST" );
static const trait_id trait_MASOCHIST_MED( "MASOCHIST_MED" );
static const trait_id trait_M_DEFENDER( "M_DEFENDER" );
static const trait_id trait_M_IMMUNE( "M_IMMUNE" );
static const trait_id trait_NPC_STARTING_NPC( "NPC_STARTING_NPC" );
static const trait_id trait_NPC_STATIC_NPC( "NPC_STATIC_NPC" );
static const trait_id trait_PROF_CHURL( "PROF_CHURL" );
static const trait_id trait_THICKSKIN( "THICKSKIN" );
static const trait_id trait_VINES2( "VINES2" );
static const trait_id trait_VINES3( "VINES3" );
static const trait_id trait_WAYFARER( "WAYFARER" );
static const zone_type_id zone_type_LOOT_CUSTOM( "LOOT_CUSTOM" );
static const zone_type_id zone_type_NO_AUTO_PICKUP( "NO_AUTO_PICKUP" );
#if defined(TILES)
#include "cata_tiles.h"
#endif // TILES
#if defined(_WIN32)
#if 1 // HACK: Hack to prevent reordering of #include "platform_win.h" by IWYU
# include "platform_win.h"
#endif
# include <tchar.h>
#endif
#define dbg(x) DebugLog((x),D_GAME) << __FILE__ << ":" << __LINE__ << ": "
static constexpr int DANGEROUS_PROXIMITY = 5;
#if defined(__ANDROID__)
extern bool add_key_to_quick_shortcuts( int key, const std::string &category, bool back ); // NOLINT
#endif
//The one and only game instance
std::unique_ptr<game> g;
//The one and only uistate instance
uistatedata uistate;
bool is_valid_in_w_terrain( const point_rel_ms &p )
{
return p.x() >= 0 && p.x() < TERRAIN_WINDOW_WIDTH && p.y() >= 0 && p.y() < TERRAIN_WINDOW_HEIGHT;
}
static void achievement_attained( const achievement *a, bool achievements_enabled )
{
if( achievements_enabled ) {
add_msg( m_good, _( "You completed the achievement \"%s\"." ),
a->name() );
std::string popup_option = get_option<std::string>( "ACHIEVEMENT_COMPLETED_POPUP" );
bool show_popup;
if( test_mode || popup_option == "never" ) {
show_popup = false;
} else if( popup_option == "always" ) {
show_popup = true;
} else if( popup_option == "first" ) {
show_popup = !get_past_achievements().is_completed( a->id );
} else {
debugmsg( "Unexpected ACHIEVEMENT_COMPLETED_POPUP option value %s", popup_option );
show_popup = false;
}
if( show_popup ) {
std::string message = colorize( _( "Achievement completed!" ), c_light_green );
message += "\n\n";
message += get_achievements().ui_text_for( a );
message += "\n";
message += colorize( _( "Achievement completion popups can be\nconfigured via the "
"Interface options" ), c_dark_gray );
popup( message );
}
}
get_event_bus().send<event_type::player_gets_achievement>( a->id, achievements_enabled );
}
static void achievement_failed( const achievement *a, bool achievements_enabled )
{
if( !a->is_conduct() ) {
return;
}
if( achievements_enabled ) {
add_msg( m_bad, _( "You lost the conduct \"%s\"." ), a->name() );
}
get_event_bus().send<event_type::player_fails_conduct>( a->id, achievements_enabled );
}
// This is the main game set-up process.
game::game() :
liveview( *liveview_ptr ),
scent_ptr( *this ),
achievements_tracker_ptr( *stats_tracker_ptr, achievement_attained, achievement_failed, true ),
m( *map_ptr ),
u( *u_ptr ),
scent( *scent_ptr ),
timed_events( *timed_event_manager_ptr ),
uquit( QUIT_NO ),
safe_mode( SAFE_MODE_ON ),
u_shared_ptr( &u, null_deleter{} ),
next_npc_id( 1 ),
next_mission_id( 1 ),
remoteveh_cache_time( calendar::before_time_starts ),
tileset_zoom( DEFAULT_TILESET_ZOOM ),
last_mouse_edge_scroll( std::chrono::steady_clock::now() )
{
first_redraw_since_waiting_started = true;
reset_light_level();
events().subscribe( &*stats_tracker_ptr );
events().subscribe( &*kill_tracker_ptr );
events().subscribe( &*memorial_logger_ptr );
events().subscribe( &*achievements_tracker_ptr );
events().subscribe( &*spell_events_ptr );
events().subscribe( &*eoc_events_ptr );
world_generator = std::make_unique<worldfactory>();
// do nothing, everything that was in here is moved to init_data() which is called immediately after g = new game; in main.cpp
// The reason for this move is so that g is not uninitialized when it gets to installing the parts into vehicles.
}
game::~game() = default;
// Load everything that will not depend on any mods
void game::load_static_data()
{
// UI stuff, not mod-specific per definition
inp_mngr.init(); // Load input config JSON
// Init mappings for loading the json stuff
DynamicDataLoader::get_instance();
fullscreen = false;
was_fullscreen = false;
show_panel_adm = false;
// These functions do not load stuff from json.
// The content they load/initialize is hardcoded into the program.
// Therefore they can be loaded here.
// If this changes (if they load data from json), they have to
// be moved to game::load_mod or game::load_core_data
get_auto_pickup().load_global();
get_auto_notes_settings().load( false );
get_safemode().load_global();
}
bool game::check_mod_data( const std::vector<mod_id> &opts )
{
dependency_tree &tree = world_generator->get_mod_manager().get_tree();
// deduplicated list of mods to check
std::set<mod_id> check( opts.begin(), opts.end() );
// if no specific mods specified check all non-obsolete mods
if( check.empty() ) {
for( const mod_id &e : world_generator->get_mod_manager().all_mods() ) {
if( !e->obsolete ) {
check.emplace( e );
}
}
}
if( check.empty() ) {
world_generator->set_active_world( nullptr );
world_generator->init();
const std::vector<mod_id> mods_empty;
WORLD *test_world = world_generator->make_new_world( mods_empty );
world_generator->set_active_world( test_world );
// if no loadable mods then test core data only
try {
load_core_data();
DynamicDataLoader::get_instance().finalize_loaded_data();
} catch( const std::exception &err ) {
std::cerr << "Error loading data from json: " << err.what() << std::endl;
}
std::string world_name = world_generator->active_world->world_name;
world_generator->delete_world( world_name, true );
MAPBUFFER.clear();
overmap_buffer.clear();
}
for( const auto &e : check ) {
world_generator->set_active_world( nullptr );
world_generator->init();
const std::vector<mod_id> mods_empty;
WORLD *test_world = world_generator->make_new_world( mods_empty );
world_generator->set_active_world( test_world );
if( !e.is_valid() ) {
std::cerr << "Unknown mod: " << e.str() << std::endl;
return false;
}
const MOD_INFORMATION &mod = *e;
if( !tree.is_available( mod.ident ) ) {
std::cerr << "Missing dependencies: " << mod.name() << "\n"
<< tree.get_node( mod.ident )->s_errors() << std::endl;
return false;
}
std::cout << "Checking mod " << mod.name() << " [" << mod.ident.str() << "]" << std::endl;
try {
load_core_data();
// Load any dependencies and de-duplicate them
std::vector<mod_id> dep_vector = tree.get_dependencies_of_X_as_strings( mod.ident );
std::set<mod_id> dep_set( dep_vector.begin(), dep_vector.end() );
for( const auto &dep : dep_set ) {
load_data_from_dir( dep->path, dep->ident.str() );
}
// Load mod itself
load_data_from_dir( mod.path, mod.ident.str() );
DynamicDataLoader::get_instance().finalize_loaded_data();
} catch( const std::exception &err ) {
std::cerr << "Error loading data: " << err.what() << std::endl;
}
std::string world_name = world_generator->active_world->world_name;
world_generator->delete_world( world_name, true );
MAPBUFFER.clear();
overmap_buffer.clear();
}
return true;
}
bool game::is_core_data_loaded() const
{
return DynamicDataLoader::get_instance().is_data_finalized();
}
void game::load_core_data()
{
// core data can be loaded only once and must be first
// anyway.
DynamicDataLoader::get_instance().unload_data();
load_data_from_dir( PATH_INFO::jsondir(), "core" );
}
void game::load_data_from_dir( const cata_path &path, const std::string &src )
{
DynamicDataLoader::get_instance().load_data_from_path( path, src );
}
void game::load_mod_data_from_dir( const cata_path &path, const std::string &src )
{
DynamicDataLoader::get_instance().load_mod_data_from_path( path, src );
}
void game::load_mod_interaction_data_from_dir( const cata_path &path, const std::string &src )
{
DynamicDataLoader::get_instance().load_mod_interaction_files_from_path( path, src );
}
#if defined(TUI)
// in ncurses_def.cpp
extern void check_encoding(); // NOLINT
extern void ensure_term_size(); // NOLINT
#endif
void game_ui::init_ui()
{
// clear the screen
static bool first_init = true;
if( first_init ) {
#if defined(TUI)
check_encoding();
#endif
first_init = false;
#if defined(TILES)
//class variable to track the option being active
//only set once, toggle action is used to change during game
pixel_minimap_option = get_option<bool>( "PIXEL_MINIMAP" );
if( get_option<std::string>( "PIXEL_MINIMAP_BG" ) == "theme" ) {
SDL_Color pixel_minimap_color = curses_color_to_SDL( c_black );
pixel_minimap_r = pixel_minimap_color.r;
pixel_minimap_g = pixel_minimap_color.g;
pixel_minimap_b = pixel_minimap_color.b;
pixel_minimap_a = pixel_minimap_color.a;
} else {
pixel_minimap_r = 0x00;
pixel_minimap_g = 0x00;
pixel_minimap_b = 0x00;
pixel_minimap_a = 0xFF;
}
#endif // TILES
}
// First get TERMX, TERMY
#if !defined(TUI)
TERMX = get_terminal_width();
TERMY = get_terminal_height();
get_options().get_option( "TERMINAL_X" ).setValue( TERMX * get_scaling_factor() );
get_options().get_option( "TERMINAL_Y" ).setValue( TERMY * get_scaling_factor() );
get_options().save();
#else
TERMY = getmaxy( catacurses::stdscr );
TERMX = getmaxx( catacurses::stdscr );
ensure_term_size();
// try to make FULL_SCREEN_HEIGHT symmetric according to TERMY
if( TERMY % 2 ) {
FULL_SCREEN_HEIGHT = EVEN_MINIMUM_TERM_HEIGHT + 1;
} else {
FULL_SCREEN_HEIGHT = EVEN_MINIMUM_TERM_HEIGHT;
}
#endif
}
void game::toggle_fullscreen()
{
#if !defined(TILES)
fullscreen = !fullscreen;
mark_main_ui_adaptor_resize();
#else
toggle_fullscreen_window();
#endif
}
void game::toggle_pixel_minimap() const
{
#if defined(TILES)
if( pixel_minimap_option ) {
clear_window_area( w_pixel_minimap );
}
pixel_minimap_option = !pixel_minimap_option;
mark_main_ui_adaptor_resize();
#endif // TILES
}
void game::toggle_language_to_en()
{
// No-op if we aren't complied with localization
#if defined(LOCALIZE)
const std::string english = "en" ;
static std::string secondary_lang = english;
std::string current_lang = TranslationManager::GetInstance().GetCurrentLanguage();
secondary_lang = current_lang != english ? current_lang : secondary_lang;
std::string new_lang = current_lang != english ? english : secondary_lang;
set_language( new_lang );
#endif
}
bool game::is_tileset_isometric() const
{
#if defined(TILES)
return use_tiles && tilecontext && tilecontext->is_isometric();
#else
return false;
#endif
}
void game::reload_tileset()
{
#if defined(TILES)
// Disable UIs below to avoid accessing the tile context during loading.
ui_adaptor ui( ui_adaptor::disable_uis_below {} );
try {
closetilecontext->reinit();
closetilecontext->load_tileset( get_option<std::string>( "TILES" ),
/*precheck=*/false, /*force=*/true,
/*pump_events=*/true, /*terrain=*/false );
closetilecontext->do_tile_loading_report();
tilecontext = closetilecontext;
} catch( const std::exception &err ) {
popup( _( "Loading the tileset failed: %s" ), err.what() );
}
if( use_far_tiles ) {
try {
if( fartilecontext->is_valid() ) {
fartilecontext->reinit();
}
fartilecontext->load_tileset( get_option<std::string>( "DISTANT_TILES" ),
/*precheck=*/false, /*force=*/true,
/*pump_events=*/true, /*terrain=*/false );
fartilecontext->do_tile_loading_report();
} catch( const std::exception &err ) {
popup( _( "Loading the zoomed out tileset failed: %s" ), err.what() );
}
}
try {
overmap_tilecontext->reinit();
overmap_tilecontext->load_tileset( get_option<std::string>( "OVERMAP_TILES" ),
/*precheck=*/false, /*force=*/true,
/*pump_events=*/true, /*terrain=*/true );
overmap_tilecontext->do_tile_loading_report();
} catch( const std::exception &err ) {
popup( _( "Loading the overmap tileset failed: %s" ), err.what() );
}
g->reset_zoom();
g->mark_main_ui_adaptor_resize();
#endif // TILES
}
// temporarily switch out of fullscreen for functions that rely
// on displaying some part of the sidebar
void game::temp_exit_fullscreen()
{
if( fullscreen ) {
was_fullscreen = true;
toggle_fullscreen();
} else {
was_fullscreen = false;
}
}
void game::reenter_fullscreen()
{
if( was_fullscreen ) {
if( !fullscreen ) {
toggle_fullscreen();
}
}
}
/*
* Initialize more stuff after mapbuffer is loaded.
*/
void game::setup()
{
new_game = true;
{
static_popup popup;
popup.message( "%s", _( "Please wait while the world data loads…\nLoading core data" ) );
ui_manager::redraw();
refresh_display();
load_core_data();
}
load_world_modfiles();
// Panel manager needs JSON data to be loaded before init
panel_manager::get_manager().init();
m = map();
next_npc_id = character_id( 1 );
next_mission_id = 1;
uquit = QUIT_NO; // We haven't quit the game
bVMonsterLookFire = true;
// invalidate calendar caches in case we were previously playing
// a different world
calendar::set_eternal_season( ::get_option<bool>( "ETERNAL_SEASON" ) );
calendar::set_season_length( ::get_option<int>( "SEASON_LENGTH" ) );
calendar::set_eternal_night( ::get_option<std::string>( "ETERNAL_TIME_OF_DAY" ) == "night" );
calendar::set_eternal_day( ::get_option<std::string>( "ETERNAL_TIME_OF_DAY" ) == "day" );
calendar::set_location( ::get_option<float>( "LATITUDE" ), ::get_option<float>( "LONGITUDE" ) );
weather.weather_id = WEATHER_CLEAR;
// Weather shift in 30
weather.nextweather = calendar::start_of_game + 30_minutes;
turnssincelastmon = 0_turns; //Auto safe mode init
sounds::reset_sounds();
clear_zombies();
critter_tracker->clear_npcs();
faction_manager_ptr->clear();
mission::clear_all();
Messages::clear_messages();
timed_events = timed_event_manager();
SCT.vSCT.clear(); //Delete pending messages
stats().clear();
// reset kill counts
kill_tracker_ptr->clear();
achievements_tracker_ptr->clear();
eoc_events_ptr->clear();
// reset follower list
follower_ids.clear();
scent.reset();
effect_on_conditions::clear( u );
u.character_mood_face( true );
remoteveh_cache_time = calendar::before_time_starts;
remoteveh_cache = nullptr;
global_variables &globvars = get_globals();
globvars.clear_global_values();
unique_npcs.clear();
get_weather().weather_override = WEATHER_NULL;
// back to menu for save loading, new game etc
}
bool game::has_gametype() const
{
return gamemode && gamemode->id() != special_game_type::NONE;
}
special_game_type game::gametype() const
{
return gamemode ? gamemode->id() : special_game_type::NONE;
}
void game::load_map( const tripoint_abs_sm &pos_sm,
const bool pump_events )
{
m.load( pos_sm, true, pump_events );
}
void game::legacy_migrate_npctalk_var_prefix( std::unordered_map<std::string, std::string>
&map_of_vars )
{
// migrate existing variables with npctalk_var prefix to no prefix (npctalk_var_foo to just foo)
// remove after 0.J
if( savegame_loading_version >= 36 ) {
return;
}
const std::string prefix = "npctalk_var_";
for( auto i = map_of_vars.begin(); i != map_of_vars.end(); ) {
if( i->first.rfind( prefix, 0 ) == 0 ) {
auto extracted = map_of_vars.extract( i++ );
std::string new_key = extracted.key().substr( prefix.size() );
extracted.key() = new_key;
map_of_vars.insert( std::move( extracted ) );
} else {
++i;
}
}
}
// Set up all default values for a new game
bool game::start_game()
{
if( !gamemode ) {
gamemode = std::make_unique<special_game>();
}
seed = rng_bits();
new_game = true;
start_calendar();
weather.nextweather = calendar::turn;
safe_mode = ( get_option<bool>( "SAFEMODE" ) ? SAFE_MODE_ON : SAFE_MODE_OFF );
mostseen = 0; // ...and mostseen is 0, we haven't seen any monsters yet.
get_safemode().load_global();
init_autosave();
background_pane background;
static_popup popup;
popup.message( "%s", _( "Please wait as we build your world" ) );
ui_manager::redraw();
refresh_display();
load_master();
u.setID( assign_npc_id() ); // should be as soon as possible, but *after* load_master
// Make sure the items are added after the calendar is started
u.add_profession_items();
// Move items from the raw inventory to item_location s. See header TODO.
u.migrate_items_to_storage( true );
const start_location &start_loc = u.random_start_location ? scen->random_start_location().obj() :
u.start_location.obj();
tripoint_abs_omt omtstart = tripoint_abs_omt::invalid;
std::unordered_map<std::string, std::string> associated_parameters;
const bool select_starting_city = get_option<bool>( "SELECT_STARTING_CITY" );
do {
if( select_starting_city ) {
if( !u.starting_city.has_value() ) {
u.starting_city = random_entry( city::get_all() );
u.world_origin = u.starting_city->pos_om;
}
auto ret = start_loc.find_player_initial_location( u.starting_city.value() );
omtstart = ret.first;
associated_parameters = ret.second;
} else {
auto ret = start_loc.find_player_initial_location( u.world_origin.value_or( point_abs_om() ) );
omtstart = ret.first;
associated_parameters = ret.second;
}
if( omtstart.is_invalid() ) {
MAPBUFFER.clear();
overmap_buffer.clear();
if( !query_yn(
_( "Try again?\n\nIt may require several attempts until the game finds a valid starting location." ) ) ) {
return false;
}
}
} while( omtstart.is_invalid() );
// Set parameter(s) if specified in chosen start_loc
start_loc.set_parameters( omtstart, associated_parameters );
start_loc.prepare_map( omtstart );
if( scen->has_map_extra() ) {
// Map extras can add monster spawn points and similar and should be done before the main
// map is loaded.
start_loc.add_map_extra( omtstart, scen->get_map_extra() );
}
tripoint_abs_sm lev = project_to<coords::sm>( omtstart );
// The player is centered in the map, but lev[xyz] refers to the top left point of the map
lev -= point( HALF_MAPSIZE, HALF_MAPSIZE );
load_map( lev, /*pump_events=*/true );
start_loc.place_player( u, omtstart );
int level = m.get_abs_sub().z();
// Rebuild map cache because we want visibility cache to avoid spawning monsters in sight
m.invalidate_map_cache( level );
m.build_map_cache( level );
// Start the overmap with out immediate neighborhood visible, this needs to be after place_player
overmap_buffer.reveal( u.global_omt_location().xy(),
get_option<int>( "DISTANCE_INITIAL_VISIBILITY" ), 0 );
const int city_size = get_option<int>( "CITY_SIZE" );
if( get_scenario()->get_reveal_locale() && city_size > 0 ) {
city_reference nearest_city = overmap_buffer.closest_city( m.get_abs_sub() );
const tripoint_abs_omt city_center_omt = project_to<coords::omt>( nearest_city.abs_sm_pos );
// Very necessary little hack: We look for roads around our start, and path from the closest. Because the most common start(evac shelter) cannot be pathed through...
const tripoint_abs_omt nearest_road = overmap_buffer.find_closest( omtstart, "road", 3, false );
// Reveal route to closest city and a 3 tile radius around the route
overmap_buffer.reveal_route( nearest_road, city_center_omt, 3 );
// Reveal destination city (scaling with city size setting)
overmap_buffer.reveal( city_center_omt, city_size );
}
u.set_moves( 0 );
u.process_turn(); // process_turn adds the initial move points
u.set_stamina( u.get_stamina_max() );
weather.temperature = SPRING_TEMPERATURE;
weather.update_weather();