forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.cpp
821 lines (773 loc) · 31.1 KB
/
init.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
#include "init.h"
#include <cstddef>
#include <memory>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
#include "achievement.h"
#include "activity_type.h"
#include "ammo.h"
#include "ammo_effect.h"
#include "anatomy.h"
#include "ascii_art.h"
#include "behavior.h"
#include "bionics.h"
#include "bodypart.h"
#include "butchery_requirements.h"
#include "cata_assert.h"
#include "cata_utility.h"
#include "character_modifier.h"
#include "clothing_mod.h"
#include "clzones.h"
#include "construction.h"
#include "construction_category.h"
#include "construction_group.h"
#include "crafting_gui.h"
#include "creature.h"
#include "debug.h"
#include "dialogue.h"
#include "disease.h"
#include "effect.h"
#include "effect_on_condition.h"
#include "emit.h"
#include "event_statistics.h"
#include "faction.h"
#include "fault.h"
#include "field_type.h"
#include "filesystem.h"
#include "flag.h"
#include "gates.h"
#include "harvest.h"
#include "item_action.h"
#include "item_category.h"
#include "item_factory.h"
#include "itype.h"
#include "json.h"
#include "loading_ui.h"
#include "lru_cache.h"
#include "magic.h"
#include "magic_enchantment.h"
#include "magic_ter_furn_transform.h"
#include "map_extras.h"
#include "mapdata.h"
#include "mapgen.h"
#include "martialarts.h"
#include "material.h"
#include "mission.h"
#include "mod_tileset.h"
#include "monfaction.h"
#include "mongroup.h"
#include "monstergenerator.h"
#include "mood_face.h"
#include "morale_types.h"
#include "move_mode.h"
#include "mutation.h"
#include "npc.h"
#include "npc_class.h"
#include "omdata.h"
#include "overlay_ordering.h"
#include "overmap.h"
#include "overmap_connection.h"
#include "overmap_location.h"
#include "profession.h"
#include "proficiency.h"
#include "recipe_dictionary.h"
#include "recipe_groups.h"
#include "regional_settings.h"
#include "relic.h"
#include "requirements.h"
#include "rotatable_symbols.h"
#include "scenario.h"
#include "scent_map.h"
#include "sdltiles.h" // IWYU pragma: keep
#include "skill.h"
#include "skill_boost.h"
#include "sounds.h"
#include "speech.h"
#include "speed_description.h"
#include "start_location.h"
#include "string_formatter.h"
#include "text_snippets.h"
#include "translations.h"
#include "trap.h"
#include "type_id.h"
#include "veh_type.h"
#include "vehicle_group.h"
#include "vitamin.h"
#include "weakpoint.h"
#include "weather_type.h"
#include "widget.h"
#include "worldfactory.h"
DynamicDataLoader::DynamicDataLoader()
{
initialize();
}
DynamicDataLoader::~DynamicDataLoader() = default;
DynamicDataLoader &DynamicDataLoader::get_instance()
{
static DynamicDataLoader theDynamicDataLoader;
return theDynamicDataLoader;
}
void DynamicDataLoader::load_object( const JsonObject &jo, const std::string &src,
const std::string &base_path,
const std::string &full_path )
{
const std::string type = jo.get_string( "type" );
const t_type_function_map::iterator it = type_function_map.find( type );
if( it == type_function_map.end() ) {
jo.throw_error( "unrecognized JSON object", "type" );
}
it->second( jo, src, base_path, full_path );
}
struct DynamicDataLoader::cached_streams {
lru_cache<std::string, shared_ptr_fast<std::istringstream>> cache;
};
shared_ptr_fast<std::istream> DynamicDataLoader::get_cached_stream( const std::string &path )
{
cata_assert( !finalized &&
"Cannot open data file after finalization." );
cata_assert( stream_cache &&
"Stream cache is only available during finalization" );
shared_ptr_fast<std::istringstream> cached = stream_cache->cache.get( path, nullptr );
// Create a new stream if the file is not opened yet, or if some code is still
// using the previous stream (in such case, `cached` and `stream_cache` have
// two references to the stream, hence the test for > 2).
if( !cached ) {
cached = make_shared_fast<std::istringstream>( read_entire_file( path ) );
} else if( cached.use_count() > 2 ) {
cached = make_shared_fast<std::istringstream>( cached->str() );
}
stream_cache->cache.insert( 8, path, cached );
return cached;
}
void DynamicDataLoader::load_deferred( deferred_json &data )
{
while( !data.empty() ) {
const size_t n = data.size();
auto it = data.begin();
for( size_t idx = 0; idx != n; ++idx ) {
if( !it->first.path ) {
debugmsg( "JSON source location has null path, data may load incorrectly" );
} else {
try {
shared_ptr_fast<std::istream> stream = get_cached_stream( *it->first.path );
JsonIn jsin( *stream, it->first );
JsonObject jo = jsin.get_object();
load_object( jo, it->second );
} catch( const JsonError &err ) {
debugmsg( "(json-error)\n%s", err.what() );
}
}
++it;
inp_mngr.pump_events();
}
data.erase( data.begin(), it );
if( data.size() == n ) {
for( const auto &elem : data ) {
if( !elem.first.path ) {
debugmsg( "JSON source location has null path when reporting circular dependency" );
} else {
try {
shared_ptr_fast<std::istream> stream = get_cached_stream( *it->first.path );
JsonIn jsin( *stream, elem.first );
jsin.error( "JSON contains circular dependency, this object is discarded" );
} catch( const JsonError &err ) {
debugmsg( "(json-error)\n%s", err.what() );
}
}
inp_mngr.pump_events();
}
data.clear();
return; // made no progress on this cycle so abort
}
}
}
static void load_ignored_type( const JsonObject &jo )
{
// This does nothing!
// This function is used for types that are to be ignored
// (for example for testing or for unimplemented types)
jo.allow_omitted_members();
}
void DynamicDataLoader::add( const std::string &type,
const std::function<void( const JsonObject &, const std::string &, const std::string &, const std::string & )>
&f )
{
const auto pair = type_function_map.emplace( type, f );
if( !pair.second ) {
debugmsg( "tried to insert a second handler for type %s into the DynamicDataLoader", type.c_str() );
}
}
void DynamicDataLoader::add( const std::string &type,
const std::function<void( const JsonObject &, const std::string & )> &f )
{
const auto pair = type_function_map.emplace( type, [f]( const JsonObject & obj,
const std::string & src,
const std::string &, const std::string & ) {
f( obj, src );
} );
if( !pair.second ) {
debugmsg( "tried to insert a second handler for type %s into the DynamicDataLoader", type.c_str() );
}
}
void DynamicDataLoader::add( const std::string &type,
const std::function<void( const JsonObject & )> &f )
{
const auto pair = type_function_map.emplace( type, [f]( const JsonObject & obj, const std::string &,
const std::string &, const std::string & ) {
f( obj );
} );
if( !pair.second ) {
debugmsg( "tried to insert a second handler for type %s into the DynamicDataLoader", type.c_str() );
}
}
void DynamicDataLoader::initialize()
{
// Initialize loading data that must be in place before any loading functions are called
init_mapdata();
// all of the applicable types that can be loaded, along with their loading functions
// Add to this as needed with new StaticFunctionAccessors or new ClassFunctionAccessors for new applicable types
// Static Function Access
add( "WORLD_OPTION", &load_world_option );
add( "EXTERNAL_OPTION", &load_external_option );
add( "json_flag", &json_flag::load_all );
add( "fault", &fault::load_fault );
add( "relic_procgen_data", &relic_procgen_data::load_relic_procgen_data );
add( "effect_on_condition", &effect_on_conditions::load );
add( "field_type", &field_types::load );
add( "weather_type", &weather_types::load );
add( "ammo_effect", &ammo_effects::load );
add( "emit", &emit::load_emit );
add( "activity_type", &activity_type::load );
add( "movement_mode", &move_mode::load_move_mode );
add( "vitamin", &vitamin::load_vitamin );
add( "material", &materials::load );
add( "bionic", &bionic_data::load_bionic );
add( "profession", &profession::load_profession );
add( "profession_item_substitutions", &profession::load_item_substitutions );
add( "proficiency", &proficiency::load_proficiencies );
add( "speed_description", &speed_description::load_speed_descriptions );
add( "mood_face", &mood_face::load_mood_faces );
add( "skill", &Skill::load_skill );
add( "skill_display_type", &SkillDisplayType::load );
add( "dream", &dream::load );
add( "mutation_category", &mutation_category_trait::load );
add( "mutation_type", &load_mutation_type );
add( "mutation", &mutation_branch::load_trait );
add( "furniture", &load_furniture );
add( "terrain", &load_terrain );
add( "monstergroup", &MonsterGroupManager::LoadMonsterGroup );
add( "MONSTER_BLACKLIST", &MonsterGroupManager::LoadMonsterBlacklist );
add( "MONSTER_WHITELIST", &MonsterGroupManager::LoadMonsterWhitelist );
add( "speech", &load_speech );
add( "ammunition_type", &ammunition_type::load_ammunition_type );
add( "start_location", &start_locations::load );
add( "scenario", &scenario::load_scenario );
add( "SCENARIO_BLACKLIST", &scen_blacklist::load_scen_blacklist );
add( "skill_boost", &skill_boost::load_boost );
add( "enchantment", &enchantment::load_enchantment );
add( "hit_range", &Creature::load_hit_range );
add( "scent_type", &scent_type::load_scent_type );
add( "disease_type", &disease_type::load_disease_type );
add( "ascii_art", &ascii_art::load_ascii_art );
// json/colors.json would be listed here, but it's loaded before the others (see init_colors())
// Non Static Function Access
add( "snippet", []( const JsonObject & jo ) {
SNIPPET.load_snippet( jo );
} );
add( "item_group", []( const JsonObject & jo ) {
item_controller->load_item_group( jo );
} );
add( "trait_group", []( const JsonObject & jo ) {
mutation_branch::load_trait_group( jo );
} );
add( "item_action", []( const JsonObject & jo ) {
item_action_generator::generator().load_item_action( jo );
} );
add( "vehicle_part", &vpart_info::load );
add( "vehicle_part_category", &vpart_category::load );
add( "vehicle", &vehicle_prototype::load );
add( "vehicle_group", &VehicleGroup::load );
add( "vehicle_placement", &VehiclePlacement::load );
add( "vehicle_spawn", &VehicleSpawn::load );
add( "requirement", []( const JsonObject & jo ) {
requirement_data::load_requirement( jo );
} );
add( "trap", &trap::load_trap );
add( "AMMO", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_ammo( jo, src );
} );
add( "GUN", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_gun( jo, src );
} );
add( "ARMOR", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_armor( jo, src );
} );
add( "PET_ARMOR", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_pet_armor( jo, src );
} );
add( "TOOL", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_tool( jo, src );
} );
add( "TOOLMOD", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_toolmod( jo, src );
} );
add( "TOOL_ARMOR", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_tool_armor( jo, src );
} );
add( "BOOK", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_book( jo, src );
} );
add( "COMESTIBLE", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_comestible( jo, src );
} );
add( "ENGINE", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_engine( jo, src );
} );
add( "WHEEL", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_wheel( jo, src );
} );
add( "GUNMOD", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_gunmod( jo, src );
} );
add( "MAGAZINE", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_magazine( jo, src );
} );
add( "BATTERY", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_battery( jo, src );
} );
add( "GENERIC", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_generic( jo, src );
} );
add( "BIONIC_ITEM", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_bionic( jo, src );
} );
add( "ITEM_CATEGORY", &item_category::load_item_cat );
add( "MIGRATION", []( const JsonObject & jo ) {
item_controller->load_migration( jo );
} );
add( "charge_removal_blacklist", load_charge_removal_blacklist );
add( "charge_migration_blacklist", load_charge_migration_blacklist );
add( "MONSTER", []( const JsonObject & jo, const std::string & src ) {
MonsterGenerator::generator().load_monster( jo, src );
} );
add( "SPECIES", []( const JsonObject & jo, const std::string & src ) {
MonsterGenerator::generator().load_species( jo, src );
} );
add( "LOOT_ZONE", &zone_type::load_zones );
add( "monster_adjustment", &load_monster_adjustment );
add( "recipe_category", &load_recipe_category );
add( "recipe", &recipe_dictionary::load_recipe );
add( "uncraft", &recipe_dictionary::load_uncraft );
add( "practice", &recipe_dictionary::load_practice );
add( "recipe_group", &recipe_group::load );
add( "tool_quality", &quality::load_static );
add( "technique", &load_technique );
add( "weapon_category", &weapon_category::load_weapon_categories );
add( "martial_art", &load_martial_art );
add( "effect_type", &load_effect_type );
add( "obsolete_terrain", &overmap::load_obsolete_terrains );
add( "overmap_terrain", &overmap_terrains::load );
add( "construction_category", &construction_categories::load );
add( "construction_group", &construction_groups::load );
add( "construction", &load_construction );
add( "mapgen", &load_mapgen );
add( "overmap_land_use_code", &overmap_land_use_codes::load );
add( "overmap_connection", &overmap_connections::load );
add( "overmap_location", &overmap_locations::load );
add( "overmap_special", &overmap_specials::load );
add( "overmap_special_migration", &overmap_special_migration::load_migrations );
add( "city_building", &city_buildings::load );
add( "map_extra", &MapExtras::load );
add( "region_settings", &load_region_settings );
add( "region_overlay", &load_region_overlay );
add( "ITEM_BLACKLIST", []( const JsonObject & jo ) {
item_controller->load_item_blacklist( jo );
} );
add( "TRAIT_BLACKLIST", []( const JsonObject & jo ) {
mutation_branch::load_trait_blacklist( jo );
} );
// loaded earlier.
add( "colordef", &load_ignored_type );
// mod information, ignored, handled by the mod manager
add( "MOD_INFO", &load_ignored_type );
add( "faction", &faction_template::load );
add( "npc", &npc_template::load );
add( "npc_class", &npc_class::load_npc_class );
add( "talk_topic", &load_talk_topic );
add( "behavior", &behavior::load_behavior );
add( "MONSTER_FACTION", &monfactions::load_monster_faction );
add( "sound_effect", &sfx::load_sound_effects );
add( "sound_effect_preload", &sfx::load_sound_effect_preload );
add( "playlist", &sfx::load_playlist );
add( "gate", &gates::load );
add( "overlay_order", &load_overlay_ordering );
add( "mission_definition", []( const JsonObject & jo, const std::string & src ) {
mission_type::load_mission_type( jo, src );
} );
add( "butchery_requirement", &butchery_requirements::load_butchery_req );
add( "harvest_drop_type", &harvest_drop_type::load_harvest_drop_types );
add( "harvest", &harvest_list::load_harvest_list );
add( "monster_attack", []( const JsonObject & jo, const std::string & src ) {
MonsterGenerator::generator().load_monster_attack( jo, src );
} );
add( "palette", mapgen_palette::load );
add( "rotatable_symbol", &rotatable_symbols::load );
add( "limb_score", &limb_score::load_limb_scores );
add( "character_mod", &character_modifier::load_character_modifiers );
add( "body_part", &body_part_type::load_bp );
add( "sub_body_part", &sub_body_part_type::load_bp );
add( "anatomy", &anatomy::load_anatomy );
add( "morale_type", &morale_type_data::load_type );
add( "SPELL", &spell_type::load_spell );
add( "clothing_mod", &clothing_mods::load );
add( "ter_furn_transform", &ter_furn_transform::load_transform );
add( "event_transformation", &event_transformation::load_transformation );
add( "event_statistic", &event_statistic::load_statistic );
add( "score", &score::load_score );
add( "achievement", &achievement::load_achievement );
add( "conduct", &achievement::load_achievement );
add( "widget", &widget::load_widget );
add( "weakpoint_set", &weakpoints::load_weakpoint_sets );
#if defined(TILES)
add( "mod_tileset", &load_mod_tileset );
#else
// Dummy function
add( "mod_tileset", load_ignored_type );
#endif
}
void DynamicDataLoader::load_data_from_path( const std::string &path, const std::string &src,
loading_ui &ui )
{
cata_assert( !finalized &&
"Can't load additional data after finalization. Must be unloaded first." );
// We assume that each folder is consistent in itself,
// and all the previously loaded folders.
// E.g. the core might provide a vpart "frame-x"
// the first loaded mode might provide a vehicle that uses that frame
// But not the other way round.
// get a list of all files in the directory
str_vec files = get_files_from_path( ".json", path, true, true );
if( files.empty() ) {
cata::ifstream tmp( fs::u8path( path ), std::ios::in );
if( tmp ) {
// path is actually a file, don't checking the extension,
// assume we want to load this file anyway
files.push_back( path );
}
}
// iterate over each file
for( const std::string &file : files ) {
// and stuff it into ram
std::istringstream iss( read_entire_file( file ) );
try {
// parse it
JsonIn jsin( iss, file );
load_all_from_json( jsin, src, ui, path, file );
} catch( const JsonError &err ) {
throw std::runtime_error( err.what() );
}
}
}
void DynamicDataLoader::load_all_from_json( JsonIn &jsin, const std::string &src, loading_ui &,
const std::string &base_path, const std::string &full_path )
{
if( jsin.test_object() ) {
// find type and dispatch single object
JsonObject jo = jsin.get_object();
load_object( jo, src, base_path, full_path );
jo.finish();
// if there's anything else in the file, it's an error.
jsin.eat_whitespace();
if( jsin.good() ) {
jsin.error( string_format( "expected single-object file but found '%c'", jsin.peek() ) );
}
} else if( jsin.test_array() ) {
jsin.start_array();
// find type and dispatch each object until array close
while( !jsin.end_array() ) {
JsonObject jo = jsin.get_object();
load_object( jo, src, base_path, full_path );
jo.finish();
}
} else {
// not an object or an array?
jsin.error( "expected object or array" );
}
inp_mngr.pump_events();
}
void DynamicDataLoader::unload_data()
{
finalized = false;
achievement::reset();
activity_type::reset();
ammo_effects::reset();
ammunition_type::reset();
anatomy::reset();
behavior::reset();
body_part_type::reset();
sub_body_part_type::reset();
weapon_category::reset();
clear_techniques_and_martial_arts();
character_modifier::reset();
clothing_mods::reset();
construction_categories::reset();
construction_groups::reset();
dreams.clear();
emit::reset();
enchantment::reset();
event_statistic::reset();
effect_on_conditions::reset();
event_transformation::reset();
faction_template::reset();
fault::reset();
field_types::reset();
gates::reset();
harvest_drop_type::reset();
harvest_list::reset();
item_controller->reset();
json_flag::reset();
limb_score::reset();
mapgen_palette::reset();
materials::reset();
mission_type::reset();
move_mode::reset();
monfactions::reset();
MonsterGenerator::generator().reset();
MonsterGroupManager::ClearMonsterGroups();
morale_type_data::reset();
mutation_branch::reset_all();
mutation_category_trait::reset();
mutations_category.clear();
npc_class::reset_npc_classes();
npc_template::reset();
overmap_connections::reset();
overmap_land_use_codes::reset();
overmap_locations::reset();
overmap_specials::reset();
overmap_special_migration::reset();
overmap_terrains::reset();
profession::reset();
proficiency::reset();
mood_face::reset();
speed_description::reset();
quality::reset();
reset_monster_adjustment();
recipe_dictionary::reset();
recipe_group::reset();
requirement_data::reset();
reset_bionics();
reset_constructions();
reset_effect_types();
reset_furn_ter();
reset_mapgens();
MapExtras::clear();
reset_mod_tileset();
reset_overlay_ordering();
reset_recipe_categories();
reset_region_settings();
reset_scenarios_blacklist();
reset_speech();
rotatable_symbols::reset();
scenario::reset();
scent_type::reset();
score::reset();
Skill::reset();
skill_boost::reset();
SNIPPET.clear_snippets();
spell_type::reset_all();
start_locations::reset();
trap::reset();
unload_talk_topics();
VehicleGroup::reset();
VehiclePlacement::reset();
VehicleSpawn::reset();
vehicle_prototype::reset();
vitamin::reset();
vpart_info::reset();
vpart_category::reset();
weakpoints::reset();
weather_types::reset();
widget::reset();
}
void DynamicDataLoader::finalize_loaded_data()
{
// Create a dummy that will not display anything
// TODO: Make it print to stdout?
loading_ui ui( false );
finalize_loaded_data( ui );
}
void DynamicDataLoader::finalize_loaded_data( loading_ui &ui )
{
cata_assert( !finalized && "Can't finalize the data twice." );
cata_assert( !stream_cache && "Expected stream cache to be null before finalization" );
on_out_of_scope reset_stream_cache( [this]() {
stream_cache.reset();
} );
stream_cache = std::make_unique<cached_streams>();
ui.new_context( _( "Finalizing" ) );
using named_entry = std::pair<std::string, std::function<void()>>;
const std::vector<named_entry> entries = {{
{ _( "Flags" ), &json_flag::finalize_all },
{ _( "Body parts" ), &body_part_type::finalize_all },
{ _( "Sub body parts" ), &sub_body_part_type::finalize_all },
{ _( "Weather types" ), &weather_types::finalize_all },
{ _( "Effect on conditions" ), &effect_on_conditions::finalize_all },
{ _( "Field types" ), &field_types::finalize_all },
{ _( "Ammo effects" ), &ammo_effects::finalize_all },
{ _( "Emissions" ), &emit::finalize },
{
_( "Items" ), []()
{
item_controller->finalize();
}
},
{
_( "Crafting requirements" ), []()
{
requirement_data::finalize();
}
},
{ _( "Vehicle part categories" ), &vpart_category::finalize },
{ _( "Vehicle parts" ), &vpart_info::finalize },
{ _( "Traps" ), &trap::finalize },
{ _( "Terrain" ), &set_ter_ids },
{ _( "Furniture" ), &set_furn_ids },
{ _( "Overmap land use codes" ), &overmap_land_use_codes::finalize },
{ _( "Overmap terrain" ), &overmap_terrains::finalize },
{ _( "Overmap connections" ), &overmap_connections::finalize },
{ _( "Overmap specials" ), &overmap_specials::finalize },
{ _( "Overmap locations" ), &overmap_locations::finalize },
{ _( "Start locations" ), &start_locations::finalize_all },
{ _( "Vehicle prototypes" ), &vehicle_prototype::finalize },
{ _( "Mapgen weights" ), &calculate_mapgen_weights },
{ _( "Mapgen parameters" ), &overmap_specials::finalize_mapgen_parameters },
{ _( "Behaviors" ), &behavior::finalize },
{
_( "Monster types" ), []()
{
MonsterGenerator::generator().finalize_mtypes();
}
},
{ _( "Monster groups" ), &MonsterGroupManager::FinalizeMonsterGroups },
{ _( "Monster factions" ), &monfactions::finalize },
{ _( "Factions" ), &npc_factions::finalize },
{ _( "Move modes" ), &move_mode::finalize },
{ _( "Constructions" ), &finalize_constructions },
{ _( "Crafting recipes" ), &recipe_dictionary::finalize },
{ _( "Recipe groups" ), &recipe_group::check },
{ _( "Martial arts" ), &finalize_martial_arts },
{ _( "NPC classes" ), &npc_class::finalize_all },
{ _( "Missions" ), &mission_type::finalize },
{ _( "Harvest lists" ), &harvest_list::finalize_all },
{ _( "Anatomies" ), &anatomy::finalize_all },
{ _( "Mutations" ), &mutation_branch::finalize },
{ _( "Achievements" ), &achievement::finalize },
{ _( "Widgets" ), &widget::finalize },
#if defined(TILES)
{ _( "Tileset" ), &load_tileset },
#endif
}
};
for( const named_entry &e : entries ) {
ui.add_entry( e.first );
}
ui.show();
for( const named_entry &e : entries ) {
e.second();
ui.proceed();
}
check_consistency( ui );
finalized = true;
}
void DynamicDataLoader::check_consistency( loading_ui &ui )
{
ui.new_context( _( "Verifying" ) );
using named_entry = std::pair<std::string, std::function<void()>>;
const std::vector<named_entry> entries = {{
{ _( "Flags" ), &json_flag::check_consistency },
{
_( "Crafting requirements" ), []()
{
requirement_data::check_consistency();
}
},
{ _( "Vitamins" ), &vitamin::check_consistency },
{ _( "Weather types" ), &weather_types::check_consistency },
{ _( "Effect on conditions" ), &effect_on_conditions::check_consistency },
{ _( "Field types" ), &field_types::check_consistency },
{ _( "Ammo effects" ), &ammo_effects::check_consistency },
{ _( "Emissions" ), &emit::check_consistency },
{ _( "Effect Types" ), &effect_type::check_consistency },
{ _( "Activities" ), &activity_type::check_consistency },
{
_( "Items" ), []()
{
item_controller->check_definitions();
}
},
{ _( "Materials" ), &materials::check },
{ _( "Engine faults" ), &fault::check_consistency },
{ _( "Vehicle parts" ), &vpart_info::check },
{ _( "Mapgen definitions" ), &check_mapgen_definitions },
{ _( "Mapgen palettes" ), &mapgen_palette::check_definitions },
{
_( "Monster types" ), []()
{
MonsterGenerator::generator().check_monster_definitions();
}
},
{ _( "Monster groups" ), &MonsterGroupManager::check_group_definitions },
{ _( "Furniture and terrain" ), &check_furniture_and_terrain },
{ _( "Constructions" ), &check_constructions },
{ _( "Crafting recipes" ), &recipe_dictionary::check_consistency },
{ _( "Professions" ), &profession::check_definitions },
{ _( "Scenarios" ), &scenario::check_definitions },
{ _( "Martial arts" ), &check_martialarts },
{ _( "Mutations" ), &mutation_branch::check_consistency },
{ _( "Mutation Categories" ), &mutation_category_trait::check_consistency },
{ _( "Region settings" ), check_region_settings },
{ _( "Overmap land use codes" ), &overmap_land_use_codes::check_consistency },
{ _( "Overmap connections" ), &overmap_connections::check_consistency },
{ _( "Overmap terrain" ), &overmap_terrains::check_consistency },
{ _( "Overmap locations" ), &overmap_locations::check_consistency },
{ _( "Overmap specials" ), &overmap_specials::check_consistency },
{ _( "Map extras" ), &MapExtras::check_consistency },
{ _( "Start locations" ), &start_locations::check_consistency },
{ _( "Ammunition types" ), &ammunition_type::check_consistency },
{ _( "Traps" ), &trap::check_consistency },
{ _( "Bionics" ), &bionic_data::check_bionic_consistency },
{ _( "Gates" ), &gates::check },
{ _( "NPC classes" ), &npc_class::check_consistency },
{ _( "Behaviors" ), &behavior::check_consistency },
{ _( "Mission types" ), &mission_type::check_consistency },
{
_( "Item actions" ), []()
{
item_action_generator::generator().check_consistency();
}
},
{ _( "Harvest lists" ), &harvest_list::check_consistency },
{ _( "NPC templates" ), &npc_template::check_consistency },
{ _( "Body parts" ), &body_part_type::check_consistency },
{ _( "Anatomies" ), &anatomy::check_consistency },
{ _( "Spells" ), &spell_type::check_consistency },
{ _( "Transformations" ), &event_transformation::check_consistency },
{ _( "Statistics" ), &event_statistic::check_consistency },
{ _( "Scent types" ), &scent_type::check_scent_consistency },
{ _( "Scores" ), &score::check_consistency },
{ _( "Achievements" ), &achievement::check_consistency },
{ _( "Disease types" ), &disease_type::check_disease_consistency },
{ _( "Factions" ), &faction_template::check_consistency },
}
};
for( const named_entry &e : entries ) {
ui.add_entry( e.first );
}
ui.show();
for( const named_entry &e : entries ) {
e.second();
ui.proceed();
}
}