forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
npc_talk_test.cpp
670 lines (624 loc) · 30.3 KB
/
npc_talk_test.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
#include <stdio.h>
#include <string>
#include <memory>
#include <vector>
#include "avatar.h"
#include "catch/catch.hpp"
#include "calendar.h"
#include "coordinate_conversions.h"
#include "dialogue.h"
#include "effect.h"
#include "faction.h"
#include "game.h"
#include "item_category.h"
#include "map.h"
#include "mission.h"
#include "npc.h"
#include "overmapbuffer.h"
#include "player.h"
#include "player_helpers.h"
#include "character.h"
#include "inventory.h"
#include "item.h"
#include "pimpl.h"
#include "string_id.h"
#include "npctalk.h"
#include "mapdata.h"
#include "material.h"
#include "type_id.h"
#include "point.h"
const efftype_id effect_gave_quest_item( "gave_quest_item" );
const efftype_id effect_currently_busy( "currently_busy" );
const efftype_id effect_infection( "infection" );
const efftype_id effect_infected( "infected" );
static const trait_id trait_PROF_FED( "PROF_FED" );
static const trait_id trait_PROF_SWAT( "PROF_SWAT" );
static npc &create_test_talker()
{
const string_id<npc_template> test_talker( "test_talker" );
const int model_id = g->m.place_npc( 25, 25, test_talker, true );
g->load_npcs();
npc *model_npc = g->find_npc( model_id );
REQUIRE( model_npc != nullptr );
for( const trait_id &tr : model_npc->get_mutations() ) {
model_npc->unset_mutation( tr );
}
model_npc->set_hunger( 0 );
model_npc->set_thirst( 0 );
model_npc->set_fatigue( 0 );
model_npc->remove_effect( efftype_id( "sleep" ) );
// An ugly hack to prevent NPC falling asleep during testing due to massive fatigue
model_npc->set_mutation( trait_id( "WEB_WEAVER" ) );
return *model_npc;
}
static void gen_response_lines( dialogue &d, size_t expected_count )
{
d.gen_responses( d.topic_stack.back() );
for( talk_response &response : d.responses ) {
response.create_option_line( d, ' ' );
}
if( d.responses.size() != expected_count ) {
printf( "Test failure in %s\n", d.topic_stack.back().id.c_str() );
for( talk_response &response : d.responses ) {
printf( "response: %s\n", response.text.c_str() );
}
}
REQUIRE( d.responses.size() == expected_count );
}
static void change_om_type( const std::string &new_type )
{
const tripoint omt_pos = ms_to_omt_copy( g->m.getabs( g->u.pos() ) );
oter_id &omt_ref = overmap_buffer.ter( omt_pos );
omt_ref = oter_id( new_type );
}
TEST_CASE( "npc_talk_test" )
{
clear_player();
CHECK( !g->u.in_vehicle );
const tripoint test_origin( 15, 15, 0 );
g->u.setpos( test_origin );
g->faction_manager_ptr->create_if_needed();
npc &talker_npc = create_test_talker();
dialogue d;
d.alpha = &g->u;
d.beta = &talker_npc;
d.add_topic( "TALK_TEST_START" );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
g->u.str_cur = 8;
g->u.dex_cur = 8;
g->u.int_cur = 8;
g->u.per_cur = 8;
d.add_topic( "TALK_TEST_SIMPLE_STATS" );
gen_response_lines( d, 5 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a strength test response." );
CHECK( d.responses[2].text == "This is a dexterity test response." );
CHECK( d.responses[3].text == "This is an intelligence test response." );
CHECK( d.responses[4].text == "This is a perception test response." );
g->u.str_cur = 6;
g->u.dex_cur = 6;
g->u.int_cur = 6;
g->u.per_cur = 6;
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
d.add_topic( "TALK_TEST_NEGATED_STATS" );
gen_response_lines( d, 5 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a low strength test response." );
CHECK( d.responses[2].text == "This is a low dexterity test response." );
CHECK( d.responses[3].text == "This is a low intelligence test response." );
CHECK( d.responses[4].text == "This is a low perception test response." );
g->u.str_cur = 8;
g->u.dex_cur = 8;
g->u.int_cur = 8;
g->u.per_cur = 8;
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
for( trait_id tr : g->u.get_mutations() ) {
g->u.unset_mutation( tr );
}
d.add_topic( "TALK_TEST_WEARING_AND_TRAIT" );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
g->u.toggle_trait( trait_id( "ELFA_EARS" ) );
gen_response_lines( d, 3 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a trait test response." );
CHECK( d.responses[2].text == "This is a short trait test response." );
g->u.wear_item( item( "badge_marshal" ) );
gen_response_lines( d, 4 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a trait test response." );
CHECK( d.responses[2].text == "This is a short trait test response." );
CHECK( d.responses[3].text == "This is a wearing test response." );
talker_npc.toggle_trait( trait_id( "ELFA_EARS" ) );
gen_response_lines( d, 6 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a trait test response." );
CHECK( d.responses[2].text == "This is a short trait test response." );
CHECK( d.responses[3].text == "This is a wearing test response." );
CHECK( d.responses[4].text == "This is a npc trait test response." );
CHECK( d.responses[5].text == "This is a npc short trait test response." );
g->u.toggle_trait( trait_id( "ELFA_EARS" ) );
talker_npc.toggle_trait( trait_id( "ELFA_EARS" ) );
g->u.toggle_trait( trait_id( "PSYCHOPATH" ) );
talker_npc.toggle_trait( trait_id( "SAPIOVORE" ) );
gen_response_lines( d, 4 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a wearing test response." );
CHECK( d.responses[2].text == "This is a trait flags test response." );
CHECK( d.responses[3].text == "This is a npc trait flags test response." );
g->u.toggle_trait( trait_id( "PSYCHOPATH" ) );
talker_npc.toggle_trait( trait_id( "SAPIOVORE" ) );
d.add_topic( "TALK_TEST_EFFECT" );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
talker_npc.add_effect( effect_gave_quest_item, 9999_turns );
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is an npc effect test response." );
g->u.add_effect( effect_gave_quest_item, 9999_turns );
d.gen_responses( d.topic_stack.back() );
gen_response_lines( d, 3 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is an npc effect test response." );
CHECK( d.responses[2].text == "This is a player effect test response." );
d.add_topic( "TALK_TEST_SERVICE" );
g->u.cash = 0;
talker_npc.add_effect( effect_currently_busy, 9999_turns );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
g->u.cash = 800;
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a cash test response." );
talker_npc.remove_effect( effect_currently_busy );
gen_response_lines( d, 4 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a cash test response." );
CHECK( d.responses[2].text == "This is an npc service test response." );
CHECK( d.responses[3].text == "This is an npc available test response." );
change_om_type( "pond_swamp_north" );
d.add_topic( "TALK_TEST_LOCATION" );
d.gen_responses( d.topic_stack.back() );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
change_om_type( "field" );
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a om_location_field test response." );
change_om_type( "faction_base_camp_11" );
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a faction camp any test response." );
d.add_topic( "TALK_TEST_NPC_ROLE" );
talker_npc.companion_mission_role_id = "NO_TEST_ROLE";
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
talker_npc.companion_mission_role_id = "TEST_ROLE";
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a nearby role test response." );
d.add_topic( "TALK_TEST_NPC_CLASS" );
talker_npc.myclass = npc_class_id( "NC_NONE" );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
talker_npc.myclass = npc_class_id( "NC_TEST_CLASS" );
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a class test response." );
for( npc *guy : g->allies() ) {
talk_function::leave( *guy );
}
talk_function::follow( talker_npc );
d.add_topic( "TALK_TEST_NPC_ALLIES" );
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a npc allies 1 test response." );
d.add_topic( "TALK_TEST_NPC_RULES" );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
talker_npc.rules.engagement = ENGAGE_ALL;
talker_npc.rules.aim = AIM_SPRAY;
talker_npc.rules.set_flag( ally_rule::use_silent );
gen_response_lines( d, 4 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a npc engagement rule test response." );
CHECK( d.responses[2].text == "This is a npc aim rule test response." );
CHECK( d.responses[3].text == "This is a npc rule test response." );
talker_npc.rules.clear_flag( ally_rule::use_silent );
d.add_topic( "TALK_TEST_NPC_NEEDS" );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
talker_npc.set_thirst( 90 );
talker_npc.set_hunger( 90 );
talker_npc.set_fatigue( EXHAUSTED );
gen_response_lines( d, 4 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a npc thirst test response." );
CHECK( d.responses[2].text == "This is a npc hunger test response." );
CHECK( d.responses[3].text == "This is a npc fatigue test response." );
d.add_topic( "TALK_TEST_MISSION_GOAL" );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
const std::vector<mission_type> &all_missions = mission_type::get_all();
bool set_mission = false;
for( const mission_type &some_mission : all_missions ) {
if( some_mission.goal == MGOAL_ASSASSINATE ) {
mission *assassinate = mission::reserve_new( some_mission.id, talker_npc.getID() );
talker_npc.chatbin.mission_selected = assassinate;
set_mission = true;
break;
}
}
CHECK( set_mission );
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a mission goal test response." );
const calendar old_calendar = calendar::turn;
calendar::turn = calendar::start;
d.add_topic( "TALK_TEST_SEASON" );
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a season spring test response." );
calendar::turn += to_turns<int>( calendar::season_length() );
gen_response_lines( d, 3 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a days since cataclysm 30 test response." );
CHECK( d.responses[2].text == "This is a season summer test response." );
calendar::turn += to_turns<int>( calendar::season_length() );
gen_response_lines( d, 4 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a days since cataclysm 30 test response." );
CHECK( d.responses[2].text == "This is a days since cataclysm 120 test response." );
CHECK( d.responses[3].text == "This is a season autumn test response." );
calendar::turn += to_turns<int>( calendar::season_length() );
gen_response_lines( d, 5 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a days since cataclysm 30 test response." );
CHECK( d.responses[2].text == "This is a days since cataclysm 120 test response." );
CHECK( d.responses[3].text == "This is a days since cataclysm 210 test response." );
CHECK( d.responses[4].text == "This is a season winter test response." );
calendar::turn += to_turns<int>( calendar::season_length() );
gen_response_lines( d, 6 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a season spring test response." );
CHECK( d.responses[2].text == "This is a days since cataclysm 30 test response." );
CHECK( d.responses[3].text == "This is a days since cataclysm 120 test response." );
CHECK( d.responses[4].text == "This is a days since cataclysm 210 test response." );
CHECK( d.responses[5].text == "This is a days since cataclysm 300 test response." );
calendar::turn = calendar::turn.sunrise() + HOURS( 4 );
d.add_topic( "TALK_TEST_TIME" );
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a is day test response." );
calendar::turn = calendar::turn.sunset() + HOURS( 2 );
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a is night test response." );
calendar::turn = old_calendar;
d.add_topic( "TALK_TEST_SWITCH" );
g->u.cash = 1000;
gen_response_lines( d, 3 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is an switch 1 test response." );
CHECK( d.responses[2].text == "This is another basic test response." );
g->u.cash = 100;
gen_response_lines( d, 3 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is an switch 2 test response." );
CHECK( d.responses[2].text == "This is another basic test response." );
g->u.cash = 10;
gen_response_lines( d, 4 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is an switch default 1 test response." );
CHECK( d.responses[2].text == "This is an switch default 2 test response." );
CHECK( d.responses[3].text == "This is another basic test response." );
g->u.cash = 0;
gen_response_lines( d, 3 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is an switch default 2 test response." );
CHECK( d.responses[2].text == "This is another basic test response." );
d.add_topic( "TALK_TEST_OR" );
g->u.cash = 0;
talker_npc.add_effect( effect_currently_busy, 9999_turns );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
g->u.toggle_trait( trait_id( "ELFA_EARS" ) );
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is an or trait test response." );
d.add_topic( "TALK_TEST_AND" );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
g->u.cash = 800;
talker_npc.remove_effect( effect_currently_busy );
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is an and cash, available, trait test response." );
d.add_topic( "TALK_TEST_NESTED" );
talker_npc.add_effect( effect_currently_busy, 9999_turns );
g->u.cash = 0;
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
g->u.cash = 800;
g->u.int_cur = 11;
gen_response_lines( d, 2 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a complex nested test response." );
d.add_topic( "TALK_TEST_TRUE_FALSE_CONDITIONAL" );
gen_response_lines( d, 3 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a true/false true response." );
CHECK( d.responses[2].text == "This is a conditional trial response." );
talk_response &chosen = d.responses[2];
bool trial_success = chosen.trial.roll( d );
CHECK( trial_success == true );
talk_effect_t &trial_effect = trial_success ? chosen.success : chosen.failure;
CHECK( trial_effect.next_topic.id == "TALK_TEST_TRUE_CONDITION_NEXT" );
g->u.cash = 0;
gen_response_lines( d, 3 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a true/false false response." );
CHECK( d.responses[2].text == "This is a conditional trial response." );
chosen = d.responses[2];
trial_success = chosen.trial.roll( d );
CHECK( trial_success == false );
trial_effect = trial_success ? chosen.success : chosen.failure;
CHECK( trial_effect.next_topic.id == "TALK_TEST_FALSE_CONDITION_NEXT" );
g->u.remove_items_with( []( const item & it ) {
return it.get_category().id() == "books" || it.get_category().id() == "food" ||
it.typeId() == "bottle_glass";
} );
d.add_topic( "TALK_TEST_HAS_ITEM" );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
d.add_topic( "TALK_TEST_ITEM_REPEAT" );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
const auto has_item = [&]( player & p, const std::string & id, int count ) {
item old_item = item( id );
if( old_item.count_by_charges() ) {
return p.has_charges( itype_id( id ), count );
} else {
return p.has_amount( itype_id( id ), count );
}
};
const auto has_beer_bottle = [&]( player & p, int count ) {
return has_item( p, "bottle_glass", 1 ) && has_item( p, "beer", count );
};
g->u.cash = 1000;
g->u.int_cur = 8;
d.add_topic( "TALK_TEST_EFFECTS" );
gen_response_lines( d, 19 );
// add and remove effect
REQUIRE( !g->u.has_effect( effect_infection ) );
talk_effect_t &effects = d.responses[1].success;
effects.apply( d );
CHECK( g->u.has_effect( effect_infection ) );
CHECK( g->u.get_effect_dur( effect_infection ) == time_duration::from_turns( 10 ) );
REQUIRE( !talker_npc.has_effect( effect_infection ) );
effects = d.responses[2].success;
effects.apply( d );
CHECK( talker_npc.has_effect( effect_infection ) );
CHECK( talker_npc.get_effect( effect_infection ).is_permanent() );
effects = d.responses[3].success;
effects.apply( d );
CHECK( !g->u.has_effect( effect_infection ) );
effects = d.responses[4].success;
effects.apply( d );
CHECK( !talker_npc.has_effect( effect_infection ) );
// add and remove trait
REQUIRE( !g->u.has_trait( trait_PROF_FED ) );
effects = d.responses[5].success;
effects.apply( d );
CHECK( g->u.has_trait( trait_PROF_FED ) );
REQUIRE( !talker_npc.has_trait( trait_PROF_FED ) );
effects = d.responses[6].success;
effects.apply( d );
CHECK( talker_npc.has_trait( trait_PROF_FED ) );
effects = d.responses[7].success;
effects.apply( d );
CHECK( !g->u.has_trait( trait_PROF_FED ) );
effects = d.responses[8].success;
effects.apply( d );
CHECK( !talker_npc.has_trait( trait_PROF_FED ) );
// buying and spending
talker_npc.op_of_u.owed = 1000;
REQUIRE( !has_beer_bottle( g->u, 2 ) );
REQUIRE( talker_npc.op_of_u.owed == 1000 );
effects = d.responses[9].success;
effects.apply( d );
CHECK( talker_npc.op_of_u.owed == 500 );
CHECK( has_beer_bottle( g->u, 2 ) );
REQUIRE( !has_item( g->u, "bottle_plastic", 1 ) );
effects = d.responses[10].success;
effects.apply( d );
CHECK( has_item( g->u, "bottle_plastic", 1 ) );
CHECK( talker_npc.op_of_u.owed == 500 );
effects = d.responses[11].success;
effects.apply( d );
CHECK( talker_npc.op_of_u.owed == 0 );
talker_npc.op_of_u.owed = 1000;
// effect chains
REQUIRE( !g->u.has_effect( effect_infected ) );
REQUIRE( !talker_npc.has_effect( effect_infected ) );
REQUIRE( !g->u.has_trait( trait_PROF_SWAT ) );
REQUIRE( !talker_npc.has_trait( trait_PROF_SWAT ) );
effects = d.responses[12].success;
effects.apply( d );
CHECK( g->u.has_effect( effect_infected ) );
CHECK( g->u.get_effect_dur( effect_infected ) == time_duration::from_turns( 10 ) );
CHECK( talker_npc.has_effect( effect_infected ) );
CHECK( talker_npc.get_effect( effect_infected ).is_permanent() );
CHECK( g->u.has_trait( trait_PROF_SWAT ) );
CHECK( talker_npc.has_trait( trait_PROF_SWAT ) );
CHECK( talker_npc.op_of_u.owed == 0 );
CHECK( talker_npc.get_attitude() == NPCATT_KILL );
// opinion changes
talker_npc.op_of_u = npc_opinion();
REQUIRE( !talker_npc.op_of_u.trust );
REQUIRE( !talker_npc.op_of_u.fear );
REQUIRE( !talker_npc.op_of_u.value );
REQUIRE( !talker_npc.op_of_u.anger );
REQUIRE( !talker_npc.op_of_u.owed );
effects = d.responses[13].success;
REQUIRE( effects.opinion.trust == 10 );
effects.apply( d );
CHECK( talker_npc.op_of_u.trust == 10 );
CHECK( talker_npc.op_of_u.fear == 11 );
CHECK( talker_npc.op_of_u.value == 12 );
CHECK( talker_npc.op_of_u.anger == 13 );
CHECK( talker_npc.op_of_u.owed == 14 );
d.add_topic( "TALK_TEST_HAS_ITEM" );
gen_response_lines( d, 7 );
CHECK( d.responses[1].text == "This is a basic test response." );
CHECK( d.responses[2].text == "This is a u_has_item beer test response." );
CHECK( d.responses[3].text == "This is a u_has_item bottle_glass test response." );
CHECK( d.responses[4].text == "This is a u_has_items beer test response." );
CHECK( d.responses[5].text == "This is a u_has_item_category books test response." );
CHECK( d.responses[6].text == "This is a u_has_item_category books count 2 test response." );
CHECK( d.responses[0].text == "This is a repeated item manual_speech test response" );
CHECK( d.responses[0].success.next_topic.item_type == "manual_speech" );
d.add_topic( "TALK_TEST_ITEM_REPEAT" );
gen_response_lines( d, 8 );
CHECK( d.responses[0].text == "This is a repeated category books, food test response" );
CHECK( d.responses[0].success.next_topic.item_type == "beer" );
CHECK( d.responses[1].text == "This is a repeated category books, food test response" );
CHECK( d.responses[1].success.next_topic.item_type == "dnd_handbook" );
CHECK( d.responses[2].text == "This is a repeated category books, food test response" );
CHECK( d.responses[2].success.next_topic.item_type == "manual_speech" );
CHECK( d.responses[3].text == "This is a repeated category books test response" );
CHECK( d.responses[3].success.next_topic.item_type == "dnd_handbook" );
CHECK( d.responses[4].text == "This is a repeated category books test response" );
CHECK( d.responses[4].success.next_topic.item_type == "manual_speech" );
CHECK( d.responses[5].text == "This is a repeated item beer, bottle_glass test response" );
CHECK( d.responses[5].success.next_topic.item_type == "bottle_glass" );
CHECK( d.responses[6].text == "This is a repeated item beer, bottle_glass test response" );
CHECK( d.responses[6].success.next_topic.item_type == "beer" );
CHECK( d.responses[7].text == "This is a basic test response." );
// test sell and consume
d.add_topic( "TALK_TEST_EFFECTS" );
gen_response_lines( d, 19 );
REQUIRE( has_item( g->u, "bottle_plastic", 1 ) );
REQUIRE( has_beer_bottle( g->u, 2 ) );
REQUIRE( g->u.wield( g->u.i_at( g->u.inv.position_by_type( "bottle_glass" ) ) ) );
effects = d.responses[14].success;
effects.apply( d );
CHECK( !has_item( g->u, "bottle_plastic", 1 ) );
CHECK( !has_item( g->u, "beer", 1 ) );
CHECK( has_item( talker_npc, "bottle_plastic", 1 ) );
CHECK( has_item( talker_npc, "beer", 2 ) );
effects = d.responses[15].success;
effects.apply( d );
CHECK( !has_item( talker_npc, "beer", 2 ) );
CHECK( has_item( talker_npc, "beer", 1 ) );
effects = d.responses[16].success;
effects.apply( d );
CHECK( has_item( g->u, "beer", 1 ) );
effects = d.responses[17].success;
effects.apply( d );
CHECK( has_item( g->u, "beer", 0 ) );
CHECK( !has_item( g->u, "beer", 1 ) );
d.add_topic( "TALK_COMBAT_COMMANDS" );
gen_response_lines( d, 10 );
CHECK( d.responses[0].text == "Change your engagement rules..." );
CHECK( d.responses[1].text == "Change your aiming rules..." );
CHECK( d.responses[2].text == "Stick close to me, no matter what." );
CHECK( d.responses[3].text == "<ally_rule_follow_distance_2_true_text>" );
CHECK( d.responses[4].text == "Don't use ranged weapons anymore." );
CHECK( d.responses[5].text == "Use only silent weapons." );
CHECK( d.responses[6].text == "Don't use grenades anymore." );
CHECK( d.responses[7].text == "Don't worry about shooting an ally." );
CHECK( d.responses[8].text == "Hold the line: don't move onto obstacles adjacent to me." );
CHECK( d.responses[9].text == "Never mind." );
d.add_topic( "TALK_TEST_VARS" );
gen_response_lines( d, 3 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a u_add_var test response." );
CHECK( d.responses[2].text == "This is a npc_add_var test response." );
effects = d.responses[1].success;
effects.apply( d );
effects = d.responses[2].success;
effects.apply( d );
gen_response_lines( d, 3 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a u_has_var, u_remove_var test response." );
CHECK( d.responses[2].text == "This is a npc_has_var, npc_remove_var test response." );
effects = d.responses[1].success;
effects.apply( d );
effects = d.responses[2].success;
effects.apply( d );
gen_response_lines( d, 3 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a u_add_var test response." );
CHECK( d.responses[2].text == "This is a npc_add_var test response." );
g->u.clear_bionics();
talker_npc.clear_bionics();
d.add_topic( "TALK_TEST_BIONICS" );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
g->u.add_bionic( bionic_id( "bio_ads" ) );
talker_npc.add_bionic( bionic_id( "bio_power_storage" ) );
gen_response_lines( d, 3 );
CHECK( d.responses[0].text == "This is a basic test response." );
CHECK( d.responses[1].text == "This is a u_has_bionics bio_ads test response." );
CHECK( d.responses[2].text == "This is a npc_has_bionics ANY response." );
// speaker effects just use are owed because I don't want to do anything complicated
talker_npc.op_of_u.owed = 2000;
CHECK( talker_npc.op_of_u.owed == 2000 );
d.add_topic( "TALK_TEST_SPEAKER_EFFECT_SIMPLE" );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 1500 );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 1000 );
d.add_topic( "TALK_TEST_SPEAKER_EFFECT_SIMPLE_CONDITIONAL" );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 500 );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 0 );
talker_npc.op_of_u.owed = 2000;
CHECK( talker_npc.op_of_u.owed == 2000 );
d.add_topic( "TALK_TEST_SPEAKER_EFFECT_SENTINEL" );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 1500 );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 1500 );
d.add_topic( "TALK_TEST_SPEAKER_EFFECT_SENTINEL_CONDITIONAL" );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 1000 );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 1000 );
talker_npc.op_of_u.owed = 4500;
CHECK( talker_npc.op_of_u.owed == 4500 );
d.add_topic( "TALK_TEST_SPEAKER_EFFECT_COMPOUND" );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 3500 );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 2500 );
d.add_topic( "TALK_TEST_SPEAKER_EFFECT_COMPOUND_CONDITIONAL" );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 1000 );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 500 );
talker_npc.op_of_u.owed = 3500;
CHECK( talker_npc.op_of_u.owed == 3500 );
d.add_topic( "TALK_TEST_SPEAKER_EFFECT_COMPOUND_SENTINEL" );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 2750 );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 2250 );
d.add_topic( "TALK_TEST_SPEAKER_EFFECT_COMPOUND_SENTINEL_CONDITIONAL" );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 1500 );
d.apply_speaker_effects( d.topic_stack.back() );
REQUIRE( talker_npc.op_of_u.owed == 1500 );
// test change class
REQUIRE( talker_npc.myclass == npc_class_id( "NC_TEST_CLASS" ) );
d.add_topic( "TALK_TEST_EFFECTS" );
gen_response_lines( d, 19 );
effects = d.responses[18].success;
effects.apply( d );
CHECK( talker_npc.myclass == npc_class_id( "NC_NONE" ) );
}