forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
missiondef.cpp
557 lines (518 loc) · 25.7 KB
/
missiondef.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
#include "mission.h" // IWYU pragma: associated
#include <algorithm>
#include <cstdlib>
#include <set>
#include "assign.h"
#include "calendar.h"
#include "condition.h"
#include "debug.h"
#include "enum_conversions.h"
#include "generic_factory.h"
#include "init.h"
#include "item.h"
#include "json.h"
#include "npc.h"
#include "rng.h"
static const mission_type_id mission_MISSION_EXPLORE_SARCOPHAGUS( "MISSION_EXPLORE_SARCOPHAGUS" );
static const mission_type_id
mission_MISSION_FREE_MERCHANTS_EVAC_1( "MISSION_FREE_MERCHANTS_EVAC_1" );
static const mission_type_id
mission_MISSION_FREE_MERCHANTS_EVAC_2( "MISSION_FREE_MERCHANTS_EVAC_2" );
static const mission_type_id
mission_MISSION_FREE_MERCHANTS_EVAC_3( "MISSION_FREE_MERCHANTS_EVAC_3" );
static const mission_type_id
mission_MISSION_FREE_MERCHANTS_EVAC_4( "MISSION_FREE_MERCHANTS_EVAC_4" );
static const mission_type_id mission_MISSION_GET_ANTIBIOTICS( "MISSION_GET_ANTIBIOTICS" );
static const mission_type_id mission_MISSION_GET_BLACK_BOX( "MISSION_GET_BLACK_BOX" );
static const mission_type_id
mission_MISSION_GET_BLACK_BOX_TRANSCRIPT( "MISSION_GET_BLACK_BOX_TRANSCRIPT" );
static const mission_type_id mission_MISSION_GET_DEPUTY_BADGE( "MISSION_GET_DEPUTY_BADGE" );
static const mission_type_id mission_MISSION_GET_FLAG( "MISSION_GET_FLAG" );
static const mission_type_id
mission_MISSION_GET_RECORD_ACCOUNTING( "MISSION_GET_RECORD_ACCOUNTING" );
static const mission_type_id mission_MISSION_GET_RECORD_PATIENT( "MISSION_GET_RECORD_PATIENT" );
static const mission_type_id mission_MISSION_GET_RECORD_WEATHER( "MISSION_GET_RECORD_WEATHER" );
static const mission_type_id mission_MISSION_GET_RELIC( "MISSION_GET_RELIC" );
static const mission_type_id mission_MISSION_GET_SAFE_BOX( "MISSION_GET_SAFE_BOX" );
static const mission_type_id mission_MISSION_GET_SOFTWARE( "MISSION_GET_SOFTWARE" );
static const mission_type_id
mission_MISSION_GET_ZOMBIE_BLOOD_ANAL( "MISSION_GET_ZOMBIE_BLOOD_ANAL" );
static const mission_type_id mission_MISSION_INVESTIGATE_CULT( "MISSION_INVESTIGATE_CULT" );
static const mission_type_id
mission_MISSION_INVESTIGATE_PRISON_VISIONARY( "MISSION_INVESTIGATE_PRISON_VISIONARY" );
static const mission_type_id mission_MISSION_JOIN_TRACKER( "MISSION_JOIN_TRACKER" );
static const mission_type_id mission_MISSION_KILL_100_Z( "MISSION_KILL_100_Z" );
static const mission_type_id mission_MISSION_KILL_HORDE_MASTER( "MISSION_KILL_HORDE_MASTER" );
static const mission_type_id mission_MISSION_KILL_JABBERWOCK( "MISSION_KILL_JABBERWOCK" );
static const mission_type_id mission_MISSION_KILL_NEMESIS( "MISSION_KILL_NEMESIS" );
static const mission_type_id mission_MISSION_KILL_ZOMBIE_MOM( "MISSION_KILL_ZOMBIE_MOM" );
static const mission_type_id mission_MISSION_NULL( "MISSION_NULL" );
static const mission_type_id mission_MISSION_OLD_GUARD_NEC_1( "MISSION_OLD_GUARD_NEC_1" );
static const mission_type_id mission_MISSION_OLD_GUARD_NEC_2( "MISSION_OLD_GUARD_NEC_2" );
static const mission_type_id
mission_MISSION_OLD_GUARD_NEC_COMMO_1( "MISSION_OLD_GUARD_NEC_COMMO_1" );
static const mission_type_id
mission_MISSION_OLD_GUARD_NEC_COMMO_2( "MISSION_OLD_GUARD_NEC_COMMO_2" );
static const mission_type_id
mission_MISSION_OLD_GUARD_NEC_COMMO_3( "MISSION_OLD_GUARD_NEC_COMMO_3" );
static const mission_type_id
mission_MISSION_OLD_GUARD_NEC_COMMO_4( "MISSION_OLD_GUARD_NEC_COMMO_4" );
static const mission_type_id mission_MISSION_OLD_GUARD_REP_1( "MISSION_OLD_GUARD_REP_1" );
static const mission_type_id mission_MISSION_OLD_GUARD_REP_2( "MISSION_OLD_GUARD_REP_2" );
static const mission_type_id mission_MISSION_OLD_GUARD_REP_3( "MISSION_OLD_GUARD_REP_3" );
static const mission_type_id mission_MISSION_OLD_GUARD_REP_4( "MISSION_OLD_GUARD_REP_4" );
static const mission_type_id mission_MISSION_RANCH_BARTENDER_1( "MISSION_RANCH_BARTENDER_1" );
static const mission_type_id mission_MISSION_RANCH_BARTENDER_2( "MISSION_RANCH_BARTENDER_2" );
static const mission_type_id mission_MISSION_RANCH_BARTENDER_3( "MISSION_RANCH_BARTENDER_3" );
static const mission_type_id mission_MISSION_RANCH_BARTENDER_4( "MISSION_RANCH_BARTENDER_4" );
static const mission_type_id mission_MISSION_RANCH_BARTENDER_5( "MISSION_RANCH_BARTENDER_5" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_1( "MISSION_RANCH_FOREMAN_1" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_10( "MISSION_RANCH_FOREMAN_10" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_11( "MISSION_RANCH_FOREMAN_11" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_12( "MISSION_RANCH_FOREMAN_12" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_13( "MISSION_RANCH_FOREMAN_13" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_14( "MISSION_RANCH_FOREMAN_14" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_15( "MISSION_RANCH_FOREMAN_15" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_16( "MISSION_RANCH_FOREMAN_16" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_17( "MISSION_RANCH_FOREMAN_17" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_2( "MISSION_RANCH_FOREMAN_2" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_3( "MISSION_RANCH_FOREMAN_3" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_4( "MISSION_RANCH_FOREMAN_4" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_5( "MISSION_RANCH_FOREMAN_5" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_6( "MISSION_RANCH_FOREMAN_6" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_7( "MISSION_RANCH_FOREMAN_7" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_8( "MISSION_RANCH_FOREMAN_8" );
static const mission_type_id mission_MISSION_RANCH_FOREMAN_9( "MISSION_RANCH_FOREMAN_9" );
static const mission_type_id mission_MISSION_RANCH_NURSE_1( "MISSION_RANCH_NURSE_1" );
static const mission_type_id mission_MISSION_RANCH_NURSE_10( "MISSION_RANCH_NURSE_10" );
static const mission_type_id mission_MISSION_RANCH_NURSE_11( "MISSION_RANCH_NURSE_11" );
static const mission_type_id mission_MISSION_RANCH_NURSE_2( "MISSION_RANCH_NURSE_2" );
static const mission_type_id mission_MISSION_RANCH_NURSE_3( "MISSION_RANCH_NURSE_3" );
static const mission_type_id mission_MISSION_RANCH_NURSE_4( "MISSION_RANCH_NURSE_4" );
static const mission_type_id mission_MISSION_RANCH_NURSE_5( "MISSION_RANCH_NURSE_5" );
static const mission_type_id mission_MISSION_RANCH_NURSE_6( "MISSION_RANCH_NURSE_6" );
static const mission_type_id mission_MISSION_RANCH_NURSE_7( "MISSION_RANCH_NURSE_7" );
static const mission_type_id mission_MISSION_RANCH_NURSE_8( "MISSION_RANCH_NURSE_8" );
static const mission_type_id mission_MISSION_RANCH_NURSE_9( "MISSION_RANCH_NURSE_9" );
static const mission_type_id mission_MISSION_RANCH_SCAVENGER_1( "MISSION_RANCH_SCAVENGER_1" );
static const mission_type_id mission_MISSION_RANCH_SCAVENGER_2( "MISSION_RANCH_SCAVENGER_2" );
static const mission_type_id mission_MISSION_RANCH_SCAVENGER_3( "MISSION_RANCH_SCAVENGER_3" );
static const mission_type_id mission_MISSION_RANCH_SCAVENGER_4( "MISSION_RANCH_SCAVENGER_4" );
static const mission_type_id mission_MISSION_REACH_FARM_HOUSE( "MISSION_REACH_FARM_HOUSE" );
static const mission_type_id mission_MISSION_REACH_FEMA_CAMP( "MISSION_REACH_FEMA_CAMP" );
static const mission_type_id mission_MISSION_REACH_SAFETY( "MISSION_REACH_SAFETY" );
static const mission_type_id mission_MISSION_RECOVER_PRIEST_DIARY( "MISSION_RECOVER_PRIEST_DIARY" );
static const mission_type_id mission_MISSION_RECRUIT_TRACKER( "MISSION_RECRUIT_TRACKER" );
static const mission_type_id mission_MISSION_RESCUE_DOG( "MISSION_RESCUE_DOG" );
enum legacy_mission_type_id {
MISSION_NULL,
MISSION_GET_ANTIBIOTICS,
MISSION_GET_SOFTWARE,
MISSION_GET_ZOMBIE_BLOOD_ANAL,
MISSION_RESCUE_DOG,
MISSION_KILL_ZOMBIE_MOM,
MISSION_REACH_SAFETY,
MISSION_GET_FLAG, //patriot 1
MISSION_GET_BLACK_BOX, //patriot 2
MISSION_GET_BLACK_BOX_TRANSCRIPT, //patriot 3
MISSION_EXPLORE_SARCOPHAGUS, //patriot 4
MISSION_GET_RELIC, //martyr 1
MISSION_RECOVER_PRIEST_DIARY, //martyr 2
MISSION_INVESTIGATE_CULT, //martyr 3
MISSION_INVESTIGATE_PRISON_VISIONARY, //martyr 4
MISSION_GET_RECORD_WEATHER, //scientist 1
MISSION_GET_RECORD_PATIENT, //humanitarian 1
MISSION_REACH_FEMA_CAMP, //humanitarian 2
MISSION_REACH_FARM_HOUSE, //humanitarian 3
MISSION_GET_RECORD_ACCOUNTING, //vigilante 1
MISSION_GET_SAFE_BOX, //vigilante 2
MISSION_GET_DEPUTY_BADGE, //vigilante 3
MISSION_KILL_JABBERWOCK, //demon slayer 1
MISSION_KILL_100_Z, //demon slayer 2
MISSION_KILL_HORDE_MASTER, //demon slayer 3
MISSION_RECRUIT_TRACKER, //demon slayer 4
MISSION_JOIN_TRACKER, //demon slayer 4b
MISSION_FREE_MERCHANTS_EVAC_1, //Clear Back Bay
MISSION_FREE_MERCHANTS_EVAC_2, //Kill Raiders
MISSION_FREE_MERCHANTS_EVAC_4, //Acquire Plutonium Cells
MISSION_OLD_GUARD_REP_1, //Bandit Pair
MISSION_OLD_GUARD_REP_2, //Raider Informant
MISSION_OLD_GUARD_REP_3, //Missing without a trace
MISSION_OLD_GUARD_REP_4, //Raider Camp
MISSION_OLD_GUARD_NEC_1, //Locate Commo team for Necropolis Commander
MISSION_OLD_GUARD_NEC_2, //Cull Nightmares
MISSION_OLD_GUARD_NEC_COMMO_1, //Build a radio repeater mod
MISSION_OLD_GUARD_NEC_COMMO_2, //Disable external power connection
MISSION_OLD_GUARD_NEC_COMMO_3, //Install repeater mod in local radio station
MISSION_OLD_GUARD_NEC_COMMO_4, //Cyclical mission to install repeater mods
MISSION_RANCH_FOREMAN_1, //Rebuild civilization one 2x4 at a time
MISSION_RANCH_FOREMAN_2, //Beds need blankets to make
MISSION_RANCH_FOREMAN_3, //You can never have enough nails!
MISSION_RANCH_FOREMAN_4, //Need salt to trade for seed
MISSION_RANCH_FOREMAN_5, //Need liquid fertilizer
MISSION_RANCH_FOREMAN_6, //Need stone for well and fireplaces
MISSION_RANCH_FOREMAN_7, //Need pipes to finish well and parts for lumberyard
MISSION_RANCH_FOREMAN_8, //Need motors to finish sawmill
MISSION_RANCH_FOREMAN_9, //Need bleach to sterilize for clinic
MISSION_RANCH_FOREMAN_10, //Need first aid kits for clinic
MISSION_RANCH_FOREMAN_11, //Need welders for chop-shop
MISSION_RANCH_FOREMAN_12, //Need car batteries to power equipment
MISSION_RANCH_FOREMAN_13, //Need pair of two-way radios for scavengers
MISSION_RANCH_FOREMAN_14, //Need 5 backpacks for scavengers
MISSION_RANCH_FOREMAN_15, //Need Homebrewer's Bible for Bar
MISSION_RANCH_FOREMAN_16, //Need Sugar for Bar
MISSION_RANCH_FOREMAN_17, //Need glass sheets for 1st greenhouse
MISSION_RANCH_NURSE_1, //Need aspirin
MISSION_RANCH_NURSE_2, //Need hotplates
MISSION_RANCH_NURSE_3, //Need multivitamins
MISSION_RANCH_NURSE_4, //Need charcoal water filters
MISSION_RANCH_NURSE_5, //Need chemistry set
MISSION_RANCH_NURSE_6, //Need filter masks
MISSION_RANCH_NURSE_7, //Need rubber gloves
MISSION_RANCH_NURSE_8, //Need X-Acto
MISSION_RANCH_NURSE_9, //Need Guide to Advanced Emergency Care
MISSION_RANCH_NURSE_10, //Need flu shot
MISSION_RANCH_NURSE_11, //Need empty syringes
MISSION_RANCH_SCAVENGER_1, //Need knife spears
MISSION_RANCH_SCAVENGER_2, //Need wearable flashlights
MISSION_RANCH_SCAVENGER_3, //Need leather body armor
MISSION_RANCH_SCAVENGER_4, //Need Molotov cocktails
MISSION_RANCH_BARTENDER_1, //Need Stills
MISSION_RANCH_BARTENDER_2, //Need Yeast
MISSION_RANCH_BARTENDER_3, //Need Sugar Beet Seeds
MISSION_RANCH_BARTENDER_4, //Need Metal Tanks
MISSION_RANCH_BARTENDER_5, //Need 55-Gallon Drums
MISSION_FREE_MERCHANTS_EVAC_3, //Info from Commune
NUM_MISSION_IDS
};
static const std::map<std::string, std::function<void( mission * )>> mission_function_map = {{
// Starts
{ "standard", { } },
{ "place_dog", mission_start::place_dog },
{ "place_zombie_mom", mission_start::place_zombie_mom },
{ "kill_horde_master", mission_start::kill_horde_master },
{ "kill_nemesis", mission_start::kill_nemesis },
{ "place_npc_software", mission_start::place_npc_software },
{ "place_priest_diary", mission_start::place_priest_diary },
{ "place_deposit_box", mission_start::place_deposit_box },
{ "find_safety", mission_start::find_safety },
{ "place_book", mission_start::place_book },
{ "reveal_refugee_center", mission_start::reveal_refugee_center },
{ "create_lab_console", mission_start::create_lab_console },
{ "create_hidden_lab_console", mission_start::create_hidden_lab_console },
{ "create_ice_lab_console", mission_start::create_ice_lab_console },
{ "reveal_lab_train_depot", mission_start::reveal_lab_train_depot },
// Endings
{ "deposit_box", mission_end::deposit_box }
// Failures
}
};
static const std::map<std::string, std::function<bool( const tripoint_abs_omt & )>>
tripoint_function_map = {{
{ "never", mission_place::never },
{ "always", mission_place::always },
{ "near_town", mission_place::near_town }
}
};
namespace io
{
template<>
std::string enum_to_string<mission_origin>( mission_origin data )
{
switch( data ) {
// *INDENT-OFF*
case ORIGIN_NULL: return "ORIGIN_NULL";
case ORIGIN_GAME_START: return "ORIGIN_GAME_START";
case ORIGIN_OPENER_NPC: return "ORIGIN_OPENER_NPC";
case ORIGIN_ANY_NPC: return "ORIGIN_ANY_NPC";
case ORIGIN_SECONDARY: return "ORIGIN_SECONDARY";
case ORIGIN_COMPUTER: return "ORIGIN_COMPUTER";
// *INDENT-ON*
case mission_origin::NUM_ORIGIN:
break;
}
cata_fatal( "Invalid mission_origin" );
}
template<>
std::string enum_to_string<mission_goal>( mission_goal data )
{
switch( data ) {
// *INDENT-OFF*
case MGOAL_NULL: return "MGOAL_NULL";
case MGOAL_GO_TO: return "MGOAL_GO_TO";
case MGOAL_GO_TO_TYPE: return "MGOAL_GO_TO_TYPE";
case MGOAL_FIND_ITEM: return "MGOAL_FIND_ITEM";
case MGOAL_FIND_ANY_ITEM: return "MGOAL_FIND_ANY_ITEM";
case MGOAL_FIND_ITEM_GROUP: return "MGOAL_FIND_ITEM_GROUP";
case MGOAL_FIND_MONSTER: return "MGOAL_FIND_MONSTER";
case MGOAL_FIND_NPC: return "MGOAL_FIND_NPC";
case MGOAL_ASSASSINATE: return "MGOAL_ASSASSINATE";
case MGOAL_KILL_MONSTER: return "MGOAL_KILL_MONSTER";
case MGOAL_KILL_MONSTER_TYPE: return "MGOAL_KILL_MONSTER_TYPE";
case MGOAL_KILL_MONSTER_SPEC: return "MGOAL_KILL_MONSTER_SPEC";
case MGOAL_KILL_NEMESIS: return "MGOAL_KILL_NEMESIS";
case MGOAL_RECRUIT_NPC: return "MGOAL_RECRUIT_NPC";
case MGOAL_RECRUIT_NPC_CLASS: return "MGOAL_RECRUIT_NPC_CLASS";
case MGOAL_COMPUTER_TOGGLE: return "MGOAL_COMPUTER_TOGGLE";
case MGOAL_TALK_TO_NPC: return "MGOAL_TALK_TO_NPC";
case MGOAL_CONDITION: return "MGOAL_CONDITION";
// *INDENT-ON*
case mission_goal::NUM_MGOAL:
break;
}
cata_fatal( "Invalid mission_goal" );
}
} // namespace io
static generic_factory<mission_type> mission_type_factory( "mission_type" );
/** @relates string_id */
template<>
const mission_type &string_id<mission_type>::obj() const
{
return mission_type_factory.obj( *this );
}
/** @relates string_id */
template<>
bool string_id<mission_type>::is_valid() const
{
return mission_type_factory.is_valid( *this );
}
void mission_type::load_mission_type( const JsonObject &jo, const std::string &src )
{
mission_type_factory.load( jo, src );
}
void mission_type::reset()
{
mission_type_factory.reset();
}
template <typename Fun>
void assign_function( const JsonObject &jo, const std::string &id, Fun &target,
const std::map<std::string, Fun> &cont )
{
if( jo.has_string( id ) ) {
const auto iter = cont.find( jo.get_string( id ) );
if( iter != cont.end() ) {
target = iter->second;
} else {
jo.throw_error_at( id, "Invalid mission function" );
}
}
}
static DynamicDataLoader::deferred_json deferred;
void mission_type::load( const JsonObject &jo, const std::string &src )
{
const bool strict = src == "dda";
mandatory( jo, was_loaded, "name", name );
mandatory( jo, was_loaded, "difficulty", difficulty );
mandatory( jo, was_loaded, "value", value );
if( jo.has_member( "origins" ) ) {
origins.clear();
for( const std::string &m : jo.get_tags( "origins" ) ) {
origins.emplace_back( io::string_to_enum<mission_origin>( m ) );
}
}
if( std::any_of( origins.begin(), origins.end(), []( mission_origin origin ) {
return origin == ORIGIN_ANY_NPC || origin == ORIGIN_OPENER_NPC || origin == ORIGIN_SECONDARY;
} ) ) {
JsonObject djo = jo.get_object( "dialogue" );
// TODO: There should be a cleaner way to do it
mandatory( djo, was_loaded, "describe", dialogue[ "describe" ] );
mandatory( djo, was_loaded, "offer", dialogue[ "offer" ] );
mandatory( djo, was_loaded, "accepted", dialogue[ "accepted" ] );
mandatory( djo, was_loaded, "rejected", dialogue[ "rejected" ] );
mandatory( djo, was_loaded, "advice", dialogue[ "advice" ] );
mandatory( djo, was_loaded, "inquire", dialogue[ "inquire" ] );
mandatory( djo, was_loaded, "success", dialogue[ "success" ] );
mandatory( djo, was_loaded, "success_lie", dialogue[ "success_lie" ] );
mandatory( djo, was_loaded, "failure", dialogue[ "failure" ] );
}
optional( jo, was_loaded, "description", description );
optional( jo, was_loaded, "urgent", urgent );
optional( jo, was_loaded, "item", item_id );
optional( jo, was_loaded, "item_group", group_id );
optional( jo, was_loaded, "count", item_count, 1 );
optional( jo, was_loaded, "required_container", container_id );
optional( jo, was_loaded, "remove_container", remove_container );
//intended for situations where closed and open container are different
optional( jo, was_loaded, "empty_container", empty_container );
optional( jo, was_loaded, "has_generic_rewards", has_generic_rewards, true );
goal = jo.get_enum_value<decltype( goal )>( "goal" );
assign_function( jo, "place", place, tripoint_function_map );
const auto parse_phase = [&]( const std::string & phase,
std::function<void( mission * )> &phase_func ) {
if( jo.has_string( phase ) ) {
assign_function( jo, phase, phase_func, mission_function_map );
} else if( jo.has_member( phase ) ) {
JsonObject j_start = jo.get_object( phase );
if( !parse_funcs( j_start, phase_func ) ) {
deferred.emplace_back( jo.get_source_location(), src );
jo.allow_omitted_members();
j_start.allow_omitted_members();
return false;
}
}
return true;
};
if( !parse_phase( "start", start ) ) {
return;
}
if( !parse_phase( "end", end ) ) {
return;
}
if( !parse_phase( "fail", fail ) ) {
return;
}
assign( jo, "deadline_low", deadline_low, false, 1_days );
assign( jo, "deadline_high", deadline_high, false, 1_days );
if( jo.has_member( "followup" ) ) {
follow_up = mission_type_id( jo.get_string( "followup" ) );
}
if( jo.has_member( "monster_species" ) ) {
monster_species = species_id( jo.get_string( "monster_species" ) );
}
if( jo.has_member( "monster_type" ) ) {
monster_type = mtype_id( jo.get_string( "monster_type" ) );
}
if( jo.has_member( "monster_kill_goal" ) ) {
monster_kill_goal = jo.get_int( "monster_kill_goal" );
}
assign( jo, "destination", target_id, strict );
if( jo.has_member( "goal_condition" ) ) {
read_condition<mission_goal_condition_context>( jo, "goal_condition", goal_condition, true );
}
}
bool mission_type::test_goal_condition( const mission_goal_condition_context &d ) const
{
if( goal_condition ) {
return goal_condition( d );
}
return true;
}
void mission_type::finalize()
{
DynamicDataLoader::get_instance().load_deferred( deferred );
}
void mission_type::check_consistency()
{
for( const mission_type &m : get_all() ) {
if( !m.item_id.is_empty() && !item::type_is_defined( m.item_id ) ) {
debugmsg( "Mission %s has undefined item id %s", m.id.c_str(), m.item_id.c_str() );
}
}
}
mission_type_id mission_type::from_legacy( int old_id )
{
static const std::vector<mission_type_id> old_id_vec = {{
mission_MISSION_NULL,
mission_MISSION_GET_ANTIBIOTICS,
mission_MISSION_GET_SOFTWARE,
mission_MISSION_GET_ZOMBIE_BLOOD_ANAL,
mission_MISSION_RESCUE_DOG,
mission_MISSION_KILL_ZOMBIE_MOM,
mission_MISSION_REACH_SAFETY,
mission_MISSION_GET_FLAG,
mission_MISSION_GET_BLACK_BOX,
mission_MISSION_GET_BLACK_BOX_TRANSCRIPT,
mission_MISSION_EXPLORE_SARCOPHAGUS,
mission_MISSION_GET_RELIC,
mission_MISSION_RECOVER_PRIEST_DIARY,
mission_MISSION_INVESTIGATE_CULT,
mission_MISSION_INVESTIGATE_PRISON_VISIONARY,
mission_MISSION_GET_RECORD_WEATHER,
mission_MISSION_GET_RECORD_PATIENT,
mission_MISSION_REACH_FEMA_CAMP,
mission_MISSION_REACH_FARM_HOUSE,
mission_MISSION_GET_RECORD_ACCOUNTING,
mission_MISSION_GET_SAFE_BOX,
mission_MISSION_GET_DEPUTY_BADGE,
mission_MISSION_KILL_JABBERWOCK,
mission_MISSION_KILL_100_Z,
mission_MISSION_KILL_HORDE_MASTER,
mission_MISSION_KILL_NEMESIS,
mission_MISSION_RECRUIT_TRACKER,
mission_MISSION_JOIN_TRACKER,
mission_MISSION_FREE_MERCHANTS_EVAC_1,
mission_MISSION_FREE_MERCHANTS_EVAC_2,
mission_MISSION_FREE_MERCHANTS_EVAC_4,
mission_MISSION_OLD_GUARD_REP_1,
mission_MISSION_OLD_GUARD_REP_2,
mission_MISSION_OLD_GUARD_REP_3,
mission_MISSION_OLD_GUARD_REP_4,
mission_MISSION_OLD_GUARD_NEC_1,
mission_MISSION_OLD_GUARD_NEC_2,
mission_MISSION_OLD_GUARD_NEC_COMMO_1,
mission_MISSION_OLD_GUARD_NEC_COMMO_2,
mission_MISSION_OLD_GUARD_NEC_COMMO_3,
mission_MISSION_OLD_GUARD_NEC_COMMO_4,
mission_MISSION_RANCH_FOREMAN_1,
mission_MISSION_RANCH_FOREMAN_2,
mission_MISSION_RANCH_FOREMAN_3,
mission_MISSION_RANCH_FOREMAN_4,
mission_MISSION_RANCH_FOREMAN_5,
mission_MISSION_RANCH_FOREMAN_6,
mission_MISSION_RANCH_FOREMAN_7,
mission_MISSION_RANCH_FOREMAN_8,
mission_MISSION_RANCH_FOREMAN_9,
mission_MISSION_RANCH_FOREMAN_10,
mission_MISSION_RANCH_FOREMAN_11,
mission_MISSION_RANCH_FOREMAN_12,
mission_MISSION_RANCH_FOREMAN_13,
mission_MISSION_RANCH_FOREMAN_14,
mission_MISSION_RANCH_FOREMAN_15,
mission_MISSION_RANCH_FOREMAN_16,
mission_MISSION_RANCH_FOREMAN_17,
mission_MISSION_RANCH_NURSE_1,
mission_MISSION_RANCH_NURSE_2,
mission_MISSION_RANCH_NURSE_3,
mission_MISSION_RANCH_NURSE_4,
mission_MISSION_RANCH_NURSE_5,
mission_MISSION_RANCH_NURSE_6,
mission_MISSION_RANCH_NURSE_7,
mission_MISSION_RANCH_NURSE_8,
mission_MISSION_RANCH_NURSE_9,
mission_MISSION_RANCH_NURSE_10,
mission_MISSION_RANCH_NURSE_11,
mission_MISSION_RANCH_SCAVENGER_1,
mission_MISSION_RANCH_SCAVENGER_2,
mission_MISSION_RANCH_SCAVENGER_3,
mission_MISSION_RANCH_SCAVENGER_4,
mission_MISSION_RANCH_BARTENDER_1,
mission_MISSION_RANCH_BARTENDER_2,
mission_MISSION_RANCH_BARTENDER_3,
mission_MISSION_RANCH_BARTENDER_4,
mission_MISSION_RANCH_BARTENDER_5,
mission_MISSION_FREE_MERCHANTS_EVAC_3,
// This is to help with the bugged find book mission
mission_MISSION_NULL
}
};
if( old_id >= 0 && old_id < static_cast<int>( old_id_vec.size() ) ) {
return old_id_vec[ old_id ];
}
debugmsg( "Invalid legacy mission id: %d", old_id );
return mission_MISSION_NULL;
}
const mission_type *mission_type::get( const mission_type_id &id )
{
if( id.is_null() ) {
return nullptr;
}
return &id.obj();
}
const std::vector<mission_type> &mission_type::get_all()
{
return mission_type_factory.get_all();
}
mission_type_id mission_type::get_random_id( const mission_origin origin,
const tripoint_abs_omt &p )
{
std::vector<mission_type_id> valid;
for( const mission_type &t : get_all() ) {
if( std::find( t.origins.begin(), t.origins.end(), origin ) == t.origins.end() ) {
continue;
}
if( t.place( p ) ) {
valid.push_back( t.id );
}
}
return random_entry( valid, mission_type_id::NULL_ID() );
}