forked from Whales/Cataclysm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
npctalk.cpp
1390 lines (1263 loc) · 40.7 KB
/
npctalk.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 "npc.h"
#include "output.h"
#include "game.h"
#include "dialogue.h"
#include "rng.h"
#include "line.h"
#include "keypress.h"
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
// Every OWED_VAL that the NPC owes you counts as +1 towards convincing
#define OWED_VAL 250
// Some aliases to help with gen_responses
#define RESPONSE(txt) ret.push_back(talk_response());\
ret.back().text = txt
#define SELECT_MISS(txt, index) ret.push_back(talk_response());\
ret.back().text = txt;\
ret.back().mission_index = index
#define TRIAL(tr, diff) ret.back().trial = tr;\
ret.back().difficulty = diff
#define SUCCESS(topic) ret.back().success = topic
#define FAILURE(topic) ret.back().failure = topic
#define SUCCESS_OPINION(T, F, V, A, O) ret.back().opinion_success =\
npc_opinion(T, F, V, A, O)
#define FAILURE_OPINION(T, F, V, A, O) ret.back().opinion_failure =\
npc_opinion(T, F, V, A, O)
#define SUCCESS_ACTION(func) ret.back().effect_success = func
#define FAILURE_ACTION(func) ret.back().effect_failure = func
std::string dynamic_line(talk_topic topic, game *g, npc *p);
std::vector<talk_response> gen_responses(talk_topic topic, game *g, npc *p);
int topic_category(talk_topic topic);
talk_topic special_talk(char ch);
int trial_chance(talk_response response, player *u, npc *p);
bool trade(game *g, npc *p, int cost, std::string deal);
void npc::talk_to_u(game *g)
{
if (attitude == NPCATT_TALK)
attitude = NPCATT_NULL;
dialogue d;
d.alpha = &g->u;
d.beta = this;
d.topic_stack.push_back(chatbin.first_topic);
if (is_friend())
d.topic_stack.push_back(TALK_FRIEND);
int most_difficult_mission = 0;
for (int i = 0; i < chatbin.missions.size(); i++) {
mission_type *type = g->find_mission_type(chatbin.missions[i]);
if (type->urgent && type->difficulty > most_difficult_mission) {
d.topic_stack.push_back(TALK_MISSION_DESCRIBE);
chatbin.mission_selected = i;
most_difficult_mission = type->difficulty;
}
}
most_difficult_mission = 0;
bool chosen_urgent = false;
for (int i = 0; i < chatbin.missions_assigned.size(); i++) {
mission_type *type = g->find_mission_type(chatbin.missions_assigned[i]);
if ((type->urgent && !chosen_urgent) ||
(type->difficulty > most_difficult_mission &&
(type->urgent || !chosen_urgent) )) {
chosen_urgent = type->urgent;
d.topic_stack.push_back(TALK_MISSION_INQUIRE);
chatbin.mission_selected = i;
most_difficult_mission = type->difficulty;
}
}
if (d.topic_stack.back() == TALK_NONE) {
g->add_msg("%s says, \"Leave me alone.\"", name.c_str());
return;
}
moves -= 100;
decide_needs();
d.win = newwin(25, 80, 0, 0);
wborder(d.win, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
for (int i = 1; i < 24; i++)
mvwputch(d.win, i, 41, c_ltgray, LINE_XOXO);
mvwputch(d.win, 0, 41, c_ltgray, LINE_OXXX);
mvwputch(d.win, 24, 41, c_ltgray, LINE_XXOX);
mvwprintz(d.win, 1, 1, c_white, "Dialogue with %s", name.c_str());
mvwprintz(d.win, 1, 43, c_white, "Your response:");
// Main dialogue loop
do {
talk_topic next = d.opt(d.topic_stack.back(), g);
if (next == TALK_NONE) {
int cat = topic_category(d.topic_stack.back());
do
d.topic_stack.pop_back();
while (cat != -1 && topic_category(d.topic_stack.back()) == cat);
}
if (next == TALK_DONE || d.topic_stack.empty())
d.done = true;
else if (next != TALK_NONE)
d.topic_stack.push_back(next);
} while (!d.done);
delwin(d.win);
g->refresh_all();
}
std::string dynamic_line(talk_topic topic, game *g, npc *p)
{
// First, a sanity test for mission stuff
if (topic >= TALK_MISSION_START && topic <= TALK_MISSION_END) {
if (topic == TALK_MISSION_START)
return "Used TALK_MISSION_START - not meant to be used!";
if (topic == TALK_MISSION_END)
return "Used TALK_MISSION_END - not meant to be used!";
if (p->chatbin.mission_selected == -1)
return "mission_selected = -1; BUG!";
int id = -1;
if (topic == TALK_MISSION_INQUIRE || topic == TALK_MISSION_ACCEPTED ||
topic == TALK_MISSION_SUCCESS || topic == TALK_MISSION_ADVICE ||
topic == TALK_MISSION_FAILURE || topic == TALK_MISSION_SUCCESS_LIE) {
if (p->chatbin.mission_selected >= p->chatbin.missions_assigned.size())
return "mission_selected is too high; BUG!";
id = p->chatbin.missions_assigned[ p->chatbin.mission_selected ];
} else {
if (p->chatbin.mission_selected >= p->chatbin.missions.size())
return "mission_selected is too high; BUG!";
id = p->chatbin.missions[ p->chatbin.mission_selected ];
}
// Mission stuff is a special case, so we'll handle it up here
mission *miss = g->find_mission(id);
mission_type *type = miss->type;
std::string ret = mission_dialogue(mission_id(type->id), topic);
if (topic == TALK_MISSION_SUCCESS && miss->follow_up != MISSION_NULL)
return ret + " And I have more I'd like you to do.";
return ret;
}
switch (topic) {
case TALK_NONE:
case TALK_DONE:
return "";
case TALK_MISSION_LIST:
if (p->chatbin.missions.empty()) {
if (p->chatbin.missions_assigned.empty())
return "I don't have any jobs for you.";
else
return "I don't have any more jobs for you.";
} else if (p->chatbin.missions.size() == 1) {
if (p->chatbin.missions_assigned.empty())
return "I just have one job for you. Want to hear about it?";
else
return "I have other one job for you. Want to hear about it?";
} else if (p->chatbin.missions_assigned.empty())
return "I have several jobs for you. Which should I describe?";
else
return "I have several more jobs for you. Which should I describe?";
case TALK_MISSION_LIST_ASSIGNED:
if (p->chatbin.missions_assigned.empty())
return "You're not working on anything for me right now.";
else if (p->chatbin.missions_assigned.size() == 1)
return "What about it?";
else
return "Which job?";
case TALK_MISSION_REWARD:
return "Sure, here you go!";
case TALK_SHELTER:
switch (rng(1, 2)) {
case 1: return "Well, I guess it's just us.";
case 2: return "At least we've got shelter.";
}
case TALK_SHELTER_PLANS:
return "I don't know, look for supplies and other survivors I guess.";
case TALK_SHARE_EQUIPMENT:
return "Why should I share my equipment with you?";
case TALK_GIVE_EQUIPMENT:
return "Okay, here you go.";
case TALK_DENY_EQUIPMENT:
if (p->op_of_u.anger >= p->hostile_anger_level() - 4)
return "<no>, and if you ask again, <ill_kill_you>!";
else
return "<no><punc> <fuck_you>!";
case TALK_SUGGEST_FOLLOW:
if (p->has_disease(DI_INFECTION))
return "Not until I get some antibiotics...";
if (p->has_disease(DI_ASKED_TO_FOLLOW))
return "You asked me recently; ask again later.";
return "Why should I travel with you?";
case TALK_AGREE_FOLLOW:
return "You got it, I'm with you!";
case TALK_DENY_FOLLOW:
return "Yeah... I don't think so.";
case TALK_FRIEND:
return "What is it?";
case TALK_COMBAT_COMMANDS: {
std::stringstream status;
status << "*is "; // Prepending * makes this an action, not a phrase
switch (p->combat_rules.engagement) {
case ENGAGE_NONE: status << "not engaging enemies."; break;
case ENGAGE_CLOSE: status << "engaging nearby enemies."; break;
case ENGAGE_WEAK: status << "engaging weak enemies."; break;
case ENGAGE_HIT: status << "engaging enenmies you attack."; break;
case ENGAGE_ALL: status << "engaging all enemies."; break;
}
status << " " << (p->male ? "He" : "She") << " will " <<
(p->combat_rules.use_guns ? "" : "not ") << "use firearms.";
status << " " << (p->male ? "He" : "She") << " will " <<
(p->combat_rules.use_grenades ? "" : "not ") << "use grenades.";
return status.str();
}
case TALK_COMBAT_ENGAGEMENT:
return "What should I do?";
case TALK_SIZE_UP: {
int ability = g->u.per_cur * 3 + g->u.int_cur;
if (ability <= 10)
return "&You can't make anything out.";
std::stringstream info;
info << "&";
int str_range = int(100 / ability);
int str_min = int(p->str_max / str_range) * str_range;
info << "Str " << str_min << " - " << str_min + str_range;
if (ability >= 40) {
int dex_range = int(160 / ability);
int dex_min = int(p->dex_max / dex_range) * dex_range;
info << " Dex " << dex_min << " - " << dex_min + dex_range;
}
if (ability >= 50) {
int int_range = int(200 / ability);
int int_min = int(p->int_max / int_range) * int_range;
info << " Int " << int_min << " - " << int_min + int_range;
}
if (ability >= 60) {
int per_range = int(240 / ability);
int per_min = int(p->per_max / per_range) * per_range;
info << " Per " << per_min << " - " << per_min + per_range;
}
return info.str();
} break;
case TALK_LOOK_AT: {
std::stringstream look;
look << "&" << p->short_description();
return look.str();
} break;
case TALK_OPINION: {
std::stringstream opinion;
opinion << "&" << p->opinion_text();
return opinion.str();
} break;
}
return "I don't know what to say. (BUG)";
}
std::vector<talk_response> gen_responses(talk_topic topic, game *g, npc *p)
{
std::vector<talk_response> ret;
switch (topic) {
case TALK_MISSION_LIST:
if (p->chatbin.missions.empty()) {
RESPONSE("Oh, okay.");
SUCCESS(TALK_NONE);
} else if (p->chatbin.missions.size() == 1) {
SELECT_MISS("Tell me about it.", 0);
SUCCESS(TALK_MISSION_OFFER);
RESPONSE("Never mind, I'm not interested.");
SUCCESS(TALK_NONE);
} else {
for (int i = 0; i < p->chatbin.missions.size(); i++) {
SELECT_MISS(g->find_mission_type( p->chatbin.missions[i] )->name, i);
SUCCESS(TALK_MISSION_OFFER);
}
RESPONSE("Never mind, I'm not interested.");
SUCCESS(TALK_NONE);
}
break;
case TALK_MISSION_LIST_ASSIGNED:
if (p->chatbin.missions_assigned.empty()) {
RESPONSE("Never mind then.");
SUCCESS(TALK_NONE);
} else if (p->chatbin.missions_assigned.size() == 1) {
SELECT_MISS("I have news.", 0);
SUCCESS(TALK_MISSION_INQUIRE);
RESPONSE("Never mind.");
SUCCESS(TALK_NONE);
} else {
for (int i = 0; i < p->chatbin.missions_assigned.size(); i++) {
SELECT_MISS(g->find_mission_type( p->chatbin.missions_assigned[i] )->name,
i);
SUCCESS(TALK_MISSION_INQUIRE);
}
RESPONSE("Never mind.");
SUCCESS(TALK_NONE);
}
break;
case TALK_MISSION_DESCRIBE:
RESPONSE("What's the matter?");
SUCCESS(TALK_MISSION_OFFER);
RESPONSE("I don't care.");
SUCCESS(TALK_MISSION_REJECTED);
break;
case TALK_MISSION_OFFER:
RESPONSE("I'll do it!");
SUCCESS(TALK_MISSION_ACCEPTED);
SUCCESS_ACTION(&talk_function::assign_mission);
RESPONSE("Not interested.");
SUCCESS(TALK_MISSION_REJECTED);
break;
case TALK_MISSION_ACCEPTED:
RESPONSE("Not a problem.");
SUCCESS(TALK_NONE);
RESPONSE("Got any advice?");
SUCCESS(TALK_MISSION_ADVICE);
RESPONSE("Can you share some equipment?");
SUCCESS(TALK_SHARE_EQUIPMENT);
RESPONSE("I'll be back soon!");
SUCCESS(TALK_DONE);
break;
case TALK_MISSION_ADVICE:
RESPONSE("Sounds good, thanks.");
SUCCESS(TALK_NONE);
RESPONSE("Sounds good. Bye!");
SUCCESS(TALK_DONE);
break;
case TALK_MISSION_REJECTED:
RESPONSE("I'm sorry.");
SUCCESS(TALK_NONE);
RESPONSE("Whatever. Bye.");
SUCCESS(TALK_DONE);
break;
case TALK_MISSION_INQUIRE: {
int id = p->chatbin.missions_assigned[ p->chatbin.mission_selected ];
if (g->mission_failed(id)) {
RESPONSE("I'm sorry... I failed.");
SUCCESS(TALK_MISSION_FAILURE);
SUCCESS_OPINION(-1, 0, -1, 1, 0);
RESPONSE("Not yet.");
TRIAL(TALK_TRIAL_LIE, 10 + p->op_of_u.trust * 3);
SUCCESS(TALK_NONE);
FAILURE(TALK_MISSION_FAILURE);
FAILURE_OPINION(-3, 0, -1, 2, 0);
} else if (!g->mission_complete(id, p->id)) {
mission_type *type = g->find_mission_type(id);
RESPONSE("Not yet.");
SUCCESS(TALK_NONE);
if (type->goal == MGOAL_KILL_MONSTER) {
RESPONSE("Yup, I killed it.");
TRIAL(TALK_TRIAL_LIE, 10 + p->op_of_u.trust * 5);
SUCCESS(TALK_MISSION_SUCCESS);
SUCCESS_ACTION(&talk_function::mission_success);
FAILURE(TALK_MISSION_SUCCESS_LIE);
FAILURE_OPINION(-5, 0, -1, 5, 0);
FAILURE_ACTION(&talk_function::mission_failure);
}
RESPONSE("No. I'll get back to it, bye!");
SUCCESS(TALK_DONE);
} else {
// TODO: Lie about mission
mission_type *type = g->find_mission_type(id);
switch (type->goal) {
case MGOAL_FIND_ITEM:
case MGOAL_FIND_ANY_ITEM:
RESPONSE("Yup! Here it is!");
SUCCESS(TALK_MISSION_SUCCESS);
SUCCESS_ACTION(&talk_function::mission_success);
break;
case MGOAL_GO_TO:
case MGOAL_FIND_NPC:
RESPONSE("Here I am.");
SUCCESS(TALK_MISSION_SUCCESS);
SUCCESS_ACTION(&talk_function::mission_success);
break;
case MGOAL_FIND_MONSTER:
RESPONSE("Here it is!");
SUCCESS(TALK_MISSION_SUCCESS);
SUCCESS_ACTION(&talk_function::mission_success);
break;
case MGOAL_KILL_MONSTER:
RESPONSE("I killed it.");
SUCCESS(TALK_MISSION_SUCCESS);
SUCCESS_ACTION(&talk_function::mission_success);
break;
default:
RESPONSE("Mission success! I don't know what else to say.");
SUCCESS(TALK_MISSION_SUCCESS);
SUCCESS_ACTION(&talk_function::mission_success);
break;
}
}
} break;
case TALK_MISSION_SUCCESS:
RESPONSE("Glad to help. I need no payment.");
SUCCESS(TALK_NONE);
SUCCESS_OPINION(p->op_of_u.owed / (OWED_VAL * 4), -1,
p->op_of_u.owed / (OWED_VAL * 2), -1, 0 - p->op_of_u.owed);
SUCCESS_ACTION(&talk_function::clear_mission);
RESPONSE("How about payment?");
SUCCESS(TALK_MISSION_REWARD);
SUCCESS_ACTION(&talk_function::mission_reward);
RESPONSE("Glad to help. I need no payment. Bye!");
SUCCESS(TALK_DONE);
SUCCESS_ACTION(&talk_function::clear_mission);
SUCCESS_OPINION(p->op_of_u.owed / (OWED_VAL * 4), -1,
p->op_of_u.owed / (OWED_VAL * 2), -1, 0 - p->op_of_u.owed);
break;
case TALK_MISSION_SUCCESS_LIE:
RESPONSE("Well, um, sorry.");
SUCCESS(TALK_NONE);
SUCCESS_ACTION(&talk_function::clear_mission);
case TALK_MISSION_FAILURE:
RESPONSE("I'm sorry. I did what I could.");
SUCCESS(TALK_NONE);
break;
case TALK_MISSION_REWARD:
RESPONSE("Thank you.");
SUCCESS(TALK_NONE);
SUCCESS_ACTION(&talk_function::clear_mission);
RESPONSE("Thanks, bye.");
SUCCESS(TALK_DONE);
SUCCESS_ACTION(&talk_function::clear_mission);
break;
case TALK_SHELTER:
RESPONSE("What should we do now?");
SUCCESS(TALK_SHELTER_PLANS);
RESPONSE("Can I do anything for you?");
SUCCESS(TALK_MISSION_LIST);
if (!p->is_following()) {
RESPONSE("Want to travel with me?");
SUCCESS(TALK_SUGGEST_FOLLOW);
}
if (p->chatbin.missions_assigned.size() == 1) {
RESPONSE("About that job...");
SUCCESS(TALK_MISSION_INQUIRE);
} else if (p->chatbin.missions_assigned.size() >= 2) {
RESPONSE("About one of those jobs...");
SUCCESS(TALK_MISSION_LIST_ASSIGNED);
}
RESPONSE("I can't leave the shelter without equipment...");
SUCCESS(TALK_SHARE_EQUIPMENT);
RESPONSE("Well, bye.");
SUCCESS(TALK_DONE);
break;
case TALK_SHELTER_PLANS:
// TODO: Add "follow me"
RESPONSE("Hmm, okay. Bye.");
SUCCESS(TALK_DONE);
break;
case TALK_SHARE_EQUIPMENT: {
int score = p->op_of_u.trust + p->op_of_u.value * 3 +
p->personality.altruism * 2;
int missions_value = p->assigned_missions_value(g);
RESPONSE("Because I'm your friend!");
TRIAL(TALK_TRIAL_PERSUADE, 10 + score);
SUCCESS(TALK_GIVE_EQUIPMENT);
SUCCESS_ACTION(&talk_function::give_equipment);
SUCCESS_OPINION(0, 0, -1, 0, score * 300);
FAILURE(TALK_DENY_EQUIPMENT);
FAILURE_OPINION(0, 0, -1, 0, 0);
if (missions_value >= 1) {
RESPONSE("Well, I am helping you out...");
TRIAL(TALK_TRIAL_PERSUADE, 10 + score + p->op_of_u.owed / OWED_VAL);
SUCCESS(TALK_GIVE_EQUIPMENT);
SUCCESS_ACTION(&talk_function::give_equipment);
FAILURE(TALK_DENY_EQUIPMENT);
FAILURE_OPINION(0, 0, -1, 0, 0);
}
RESPONSE("I'll give it back!");
TRIAL(TALK_TRIAL_LIE, score * 1.5);
SUCCESS(TALK_GIVE_EQUIPMENT);
SUCCESS_ACTION(&talk_function::give_equipment);
SUCCESS_OPINION(0, 0, -1, 0, score * 300);
FAILURE(TALK_DENY_EQUIPMENT);
FAILURE_OPINION(0, -1, -1, 1, 0);
RESPONSE("Give it to me, or else!");
TRIAL(TALK_TRIAL_INTIMIDATE, 40);
SUCCESS(TALK_GIVE_EQUIPMENT);
SUCCESS_ACTION(&talk_function::give_equipment);
SUCCESS_OPINION(-3, 2, -2, 2,
(g->u.intimidation() + p->op_of_u.fear -
p->personality.bravery - p->intimidation()) * 500);
FAILURE(TALK_DENY_EQUIPMENT);
FAILURE_OPINION(-3, 1, -3, 5, 0);
RESPONSE("Eh, never mind.");
SUCCESS(TALK_NONE);
RESPONSE("Never mind, I'll do without. Bye.");
SUCCESS(TALK_DONE);
} break;
case TALK_GIVE_EQUIPMENT:
RESPONSE("Thank you!");
SUCCESS(TALK_NONE);
RESPONSE("Thanks! But can I have some more?");
SUCCESS(TALK_SHARE_EQUIPMENT);
RESPONSE("Thanks, see you later!");
SUCCESS(TALK_DONE);
break;
case TALK_DENY_EQUIPMENT:
RESPONSE("Okay, okay, sorry.");
SUCCESS(TALK_NONE);
RESPONSE("Seriously, give me more stuff!");
SUCCESS(TALK_SHARE_EQUIPMENT);
RESPONSE("Okay, fine, bye.");
SUCCESS(TALK_DONE);
break;
case TALK_SUGGEST_FOLLOW:
if (p->has_disease(DI_INFECTION)) {
RESPONSE("Understood. I'll get those antibiotics.");
SUCCESS(TALK_NONE);
} else if (p->has_disease(DI_ASKED_TO_FOLLOW)) {
RESPONSE("Right, right, I'll ask later.");
SUCCESS(TALK_NONE);
} else {
int strength = 3 * p->op_of_u.fear + p->op_of_u.value + p->op_of_u.trust +
(10 - p->personality.bravery);
int weakness = 3 * p->personality.altruism + p->personality.bravery -
p->op_of_u.fear + p->op_of_u.value;
int friends = 2 * p->op_of_u.trust + 2 * p->op_of_u.value -
2 * p->op_of_u.anger + p->op_of_u.owed / 50;
RESPONSE("I can keep you safe.");
TRIAL(TALK_TRIAL_PERSUADE, strength * 2);
SUCCESS(TALK_AGREE_FOLLOW);
SUCCESS_ACTION(&talk_function::follow);
SUCCESS_OPINION(1, 0, 1, 0, 0);
FAILURE(TALK_DENY_FOLLOW);
FAILURE_ACTION(&talk_function::deny_follow);
FAILURE_OPINION(0, 0, -1, 1, 0);
RESPONSE("You can keep me safe.");
TRIAL(TALK_TRIAL_PERSUADE, weakness * 2);
SUCCESS(TALK_AGREE_FOLLOW);
SUCCESS_ACTION(&talk_function::follow);
SUCCESS_OPINION(0, 0, -1, 0, 0);
FAILURE(TALK_DENY_FOLLOW);
FAILURE_ACTION(&talk_function::deny_follow);
FAILURE_OPINION(0, -1, -1, 1, 0);
RESPONSE("We're friends, aren't we?");
TRIAL(TALK_TRIAL_PERSUADE, friends * 1.5);
SUCCESS(TALK_AGREE_FOLLOW);
SUCCESS_ACTION(&talk_function::follow);
SUCCESS_OPINION(2, 0, 0, -1, 0);
FAILURE(TALK_DENY_FOLLOW);
FAILURE_ACTION(&talk_function::deny_follow);
FAILURE_OPINION(-1, -2, -1, 1, 0);
RESPONSE("!I'll kill you if you don't.");
TRIAL(TALK_TRIAL_INTIMIDATE, strength * 2);
SUCCESS(TALK_AGREE_FOLLOW);
SUCCESS_ACTION(&talk_function::follow);
SUCCESS_OPINION(-4, 3, -1, 4, 0);
FAILURE(TALK_DENY_FOLLOW);
FAILURE_OPINION(-4, 0, -5, 10, 0);
}
break;
case TALK_AGREE_FOLLOW:
RESPONSE("Awesome!");
SUCCESS(TALK_NONE);
RESPONSE("Okay, let's go!");
SUCCESS(TALK_DONE);
break;
case TALK_DENY_FOLLOW:
RESPONSE("Oh, okay.");
SUCCESS(TALK_NONE);
break;
case TALK_FRIEND:
RESPONSE("Combat commands...");
SUCCESS(TALK_COMBAT_COMMANDS);
RESPONSE("Can I do anything for you?");
SUCCESS(TALK_MISSION_LIST);
RESPONSE("Let's trade items.");
SUCCESS(TALK_NONE);
SUCCESS_ACTION(&talk_function::start_trade);
RESPONSE("Let's go.");
SUCCESS(TALK_DONE);
break;
case TALK_COMBAT_COMMANDS: {
RESPONSE("Change your engagement rules...");
SUCCESS(TALK_COMBAT_ENGAGEMENT);
if (p->combat_rules.use_guns) {
RESPONSE("Don't use guns anymore.");
SUCCESS(TALK_COMBAT_COMMANDS);
SUCCESS_ACTION(&talk_function::toggle_use_guns);
} else {
RESPONSE("You can use guns.");
SUCCESS(TALK_COMBAT_COMMANDS);
SUCCESS_ACTION(&talk_function::toggle_use_guns);
}
if (p->combat_rules.use_grenades) {
RESPONSE("Don't use grenades anymore.");
SUCCESS(TALK_COMBAT_COMMANDS);
SUCCESS_ACTION(&talk_function::toggle_use_grenades);
} else {
RESPONSE("You can use grenades.");
SUCCESS(TALK_COMBAT_COMMANDS);
SUCCESS_ACTION(&talk_function::toggle_use_grenades);
}
RESPONSE("Never mind.");
SUCCESS(TALK_NONE);
} break;
case TALK_COMBAT_ENGAGEMENT: {
if (p->combat_rules.engagement != ENGAGE_NONE) {
RESPONSE("Don't fight unless your life depends on it.");
SUCCESS(TALK_NONE);
SUCCESS_ACTION(&talk_function::set_engagement_none);
}
if (p->combat_rules.engagement != ENGAGE_CLOSE) {
RESPONSE("Attack enemies that get too close.");
SUCCESS(TALK_NONE);
SUCCESS_ACTION(&talk_function::set_engagement_close);
}
if (p->combat_rules.engagement != ENGAGE_WEAK) {
RESPONSE("Attack enemies that you can kill easily.");
SUCCESS(TALK_NONE);
SUCCESS_ACTION(&talk_function::set_engagement_weak);
}
if (p->combat_rules.engagement != ENGAGE_HIT) {
RESPONSE("Attack only enemies that I attack first.");
SUCCESS(TALK_NONE);
SUCCESS_ACTION(&talk_function::set_engagement_hit);
}
if (p->combat_rules.engagement != ENGAGE_ALL) {
RESPONSE("Attack anything you want.");
SUCCESS(TALK_NONE);
SUCCESS_ACTION(&talk_function::set_engagement_all);
}
RESPONSE("Never mind.");
SUCCESS(TALK_NONE);
} break;
case TALK_SIZE_UP:
case TALK_LOOK_AT:
case TALK_OPINION:
RESPONSE("Okay.");
SUCCESS(TALK_NONE);
break;
}
if (ret.empty()) {
RESPONSE("Bye.");
SUCCESS(TALK_DONE);
}
return ret;
}
int trial_chance(talk_response response, player *u, npc *p)
{
talk_trial trial = response.trial;
int chance = response.difficulty;
switch (trial) {
case TALK_TRIAL_LIE:
chance += u->talk_skill() - p->talk_skill() + p->op_of_u.trust * 3;
if (u->has_trait(PF_TRUTHTELLER))
chance -= 40;
break;
case TALK_TRIAL_PERSUADE:
chance += u->talk_skill() - int(p->talk_skill() / 2) +
p->op_of_u.trust * 2 + p->op_of_u.value;
if (u->has_trait(PF_GROWL))
chance -= 25;
if (u->has_trait(PF_SNARL))
chance -= 60;
break;
case TALK_TRIAL_INTIMIDATE:
chance += u->intimidation() - p->intimidation() + p->op_of_u.fear * 2 -
p->personality.bravery * 2;
if (u->has_trait(PF_TERRIFYING))
chance += 15;
if (p->has_trait(PF_TERRIFYING))
chance -= 15;
if (u->has_trait(PF_GROWL))
chance += 15;
if (u->has_trait(PF_SNARL))
chance += 30;
break;
}
if (chance < 0)
return 0;
if (chance > 100)
return 100;
return chance;
}
int topic_category(talk_topic topic)
{
switch (topic) {
case TALK_MISSION_START:
case TALK_MISSION_DESCRIBE:
case TALK_MISSION_OFFER:
case TALK_MISSION_ACCEPTED:
case TALK_MISSION_REJECTED:
case TALK_MISSION_ADVICE:
case TALK_MISSION_INQUIRE:
case TALK_MISSION_SUCCESS:
case TALK_MISSION_SUCCESS_LIE:
case TALK_MISSION_FAILURE:
case TALK_MISSION_REWARD:
case TALK_MISSION_END:
return 1;
case TALK_SHARE_EQUIPMENT:
case TALK_GIVE_EQUIPMENT:
case TALK_DENY_EQUIPMENT:
return 2;
case TALK_SUGGEST_FOLLOW:
case TALK_AGREE_FOLLOW:
case TALK_DENY_FOLLOW:
return 3;
case TALK_COMBAT_ENGAGEMENT:
return 4;
case TALK_COMBAT_COMMANDS:
return 5;
case TALK_SIZE_UP:
case TALK_LOOK_AT:
case TALK_OPINION:
return 99;
default:
return -1; // Not grouped with other topics
}
return -1;
}
void talk_function::assign_mission(game *g, npc *p)
{
int selected = p->chatbin.mission_selected;
if (selected == -1 || selected >= p->chatbin.missions.size()) {
debugmsg("mission_selected = %d; missions.size() = %d!",
selected, p->chatbin.missions.size());
return;
}
mission *miss = g->find_mission( p->chatbin.missions[selected] );
g->assign_mission(p->chatbin.missions[selected]);
miss->npc_id = p->id;
g->u.active_mission = g->u.active_missions.size() - 1;
p->chatbin.missions_assigned.push_back( p->chatbin.missions[selected] );
p->chatbin.missions.erase(p->chatbin.missions.begin() + selected);
}
void talk_function::mission_success(game *g, npc *p)
{
int selected = p->chatbin.mission_selected;
if (selected == -1 || selected >= p->chatbin.missions_assigned.size()) {
debugmsg("mission_selected = %d; missions_assigned.size() = %d!",
selected, p->chatbin.missions_assigned.size());
return;
}
int index = p->chatbin.missions_assigned[selected];
p->op_of_u.owed += g->find_mission(index)->value;
g->wrap_up_mission(index);
}
void talk_function::mission_failure(game *g, npc *p)
{
int selected = p->chatbin.mission_selected;
if (selected == -1 || selected >= p->chatbin.missions_assigned.size()) {
debugmsg("mission_selected = %d; missions_assigned.size() = %d!",
selected, p->chatbin.missions_assigned.size());
return;
}
g->mission_failed(p->chatbin.missions_assigned[selected]);
}
void talk_function::clear_mission(game *g, npc *p)
{
int selected = p->chatbin.mission_selected;
p->chatbin.mission_selected = -1;
if (selected == -1 || selected >= p->chatbin.missions_assigned.size()) {
debugmsg("mission_selected = %d; missions_assigned.size() = %d!",
selected, p->chatbin.missions_assigned.size());
return;
}
mission *miss = g->find_mission( p->chatbin.missions_assigned[selected] );
p->chatbin.missions_assigned.erase( p->chatbin.missions_assigned.begin() +
selected);
if (miss->follow_up != MISSION_NULL)
p->chatbin.missions.push_back( g->reserve_mission(miss->follow_up, p->id) );
}
void talk_function::mission_reward(game *g, npc *p)
{
int trade_amount = p->op_of_u.owed;
p->op_of_u.owed = 0;
trade(g, p, trade_amount, "Reward");
}
void talk_function::start_trade(game *g, npc *p)
{
int trade_amount = p->op_of_u.owed;
p->op_of_u.owed = 0;
trade(g, p, trade_amount, "Trade");
}
void talk_function::give_equipment(game *g, npc *p)
{
std::vector<int> giving;
std::vector<int> prices;
p->init_selling(giving, prices);
int chosen = -1;
if (giving.empty()) {
for (int i = 0; i < p->inv.size(); i++) {
int val = p->value(p->inv[i]) - p->inv[i].price() / 50;
giving.push_back(i);
prices.push_back(p->inv[i].price());
}
}
while (chosen == -1 && giving.size() > 1) {
int index = rng(0, giving.size() - 1);
if (prices[index] < p->op_of_u.owed)
chosen = index;
giving.erase(giving.begin() + index);
prices.erase(prices.begin() + index);
}
if (giving.empty()) {
popup("%s has nothing to give!", p->name.c_str());
return;
}
if (chosen == -1)
chosen = 0;
int item_index = giving[chosen];
popup("%s gives you a %s.", p->name.c_str(),
p->inv[item_index].tname().c_str());
g->u.i_add( p->i_remn(item_index) );
p->op_of_u.owed -= prices[chosen];
}
void talk_function::follow(game *g, npc *p)
{
p->attitude = NPCATT_FOLLOW;
}
void talk_function::deny_follow(game *g, npc *p)
{
p->add_disease(DI_ASKED_TO_FOLLOW, 3600, g);
}
void talk_function::toggle_use_guns(game *g, npc *p)
{
p->combat_rules.use_guns = !p->combat_rules.use_guns;
}
void talk_function::toggle_use_grenades(game *g, npc *p)
{
p->combat_rules.use_grenades = !p->combat_rules.use_grenades;
}
void talk_function::set_engagement_none(game *g, npc *p)
{
p->combat_rules.engagement = ENGAGE_NONE;
}
void talk_function::set_engagement_close(game *g, npc *p)
{
p->combat_rules.engagement = ENGAGE_CLOSE;
}
void talk_function::set_engagement_weak(game *g, npc *p)
{
p->combat_rules.engagement = ENGAGE_WEAK;
}
void talk_function::set_engagement_hit(game *g, npc *p)
{
p->combat_rules.engagement = ENGAGE_HIT;
}
void talk_function::set_engagement_all(game *g, npc *p)
{
p->combat_rules.engagement = ENGAGE_ALL;
}
void parse_tags(std::string &phrase, player *u, npc *me)
{
if (u == NULL || me == NULL) {
debugmsg("Called parse_tags() with NULL pointers!");
return;
}
size_t fa, fb;
std::string tag;
do {
fa = phrase.find("<");
fb = phrase.find(">");
int l = fb - fa + 1;
if (fa != std::string::npos && fb != std::string::npos)
tag = phrase.substr(fa, fb - fa + 1);
else
tag = "";
bool replaced = false;
for (int i = 0; i < NUM_STATIC_TAGS && !replaced; i++) {
if (tag == talk_tags[i].tag) {
phrase.replace(fa, l, (*talk_tags[i].replacement)[rng(0, 9)]);
replaced = true;
}
}
if (!replaced) { // Special, dynamic tags go here
if (tag == "<yrwp>")
phrase.replace(fa, l, u->weapon.tname());
if (tag == "<mywp>") {
if (me->weapon.type->id == 0)
phrase.replace(fa, l, "fists");
else
phrase.replace(fa, l, me->weapon.tname());
} else if (tag == "<ammo>") {
if (!me->weapon.is_gun())
phrase.replace(fa, l, "BADAMMO");
else {
it_gun* gun = dynamic_cast<it_gun*>(me->weapon.type);
phrase.replace(fa, l, ammo_name(gun->ammo));
}
} else if (tag == "<punc>") {
switch (rng(0, 2)) {
case 0: phrase.replace(fa, l, "."); break;
case 1: phrase.replace(fa, l, "..."); break;
case 2: phrase.replace(fa, l, "!"); break;
}
} else if (tag != "") {
debugmsg("Bad tag. '%s' (%d - %d)", tag.c_str(), fa, fb);
phrase.replace(fa, fb - fa + 1, "????");
}
}
} while (fa != std::string::npos && fb != std::string::npos);
}
talk_topic dialogue::opt(talk_topic topic, game *g)
{
std::string challenge = dynamic_line(topic, g, beta);
std::vector<talk_response> responses = gen_responses(topic, g, beta);
// Put quotes around challenge (unless it's an action)
if (challenge[0] != '*' && challenge[0] != '&') {
std::stringstream tmp;
tmp << "\"" << challenge << "\"";
}
// Parse any tags in challenge
parse_tags(challenge, alpha, beta);
if (challenge[0] >= 'a' && challenge[0] <= 'z')