-
Notifications
You must be signed in to change notification settings - Fork 18
/
interact.pp
1477 lines (1279 loc) · 50.6 KB
/
interact.pp
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
unit interact;
{ This unit contains the rules for using interaction skills, }
{ such as Conversation, et cetera. }
{ It also, by reason of necessity, contains some procedures }
{ related to random plots. The main unit for plots is }
{ playwright.pp; see that unit for more details. }
{
GearHead: Arena, a roguelike mecha CRPG
Copyright (C) 2005 Joseph Hewitt
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
The full text of the LGPL can be found in license.txt.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
interface
uses gears,locale;
Const
{ *** PERSONA GEAR *** }
{ G = GG_Persona }
{ S = Character ID or Plot Element Number }
{ V = na }
{ *** FACTION GEAR *** }
{ G = GG_Faction }
{ S = Faction ID }
{ V = Undefined }
NAG_Personal = 5;
NAS_CID = 0; { Character ID }
NAS_FactionID = 2; { The character's faction. }
{ Note that the faction ID for NPCs is stored in the }
{ character gear, but for the PC it is stored in both }
{ the character gear and the root Adventure gear. }
NAS_ReTalk = 1; { Busy counter... after talking with an NPC once, }
{ you can't talk with that same NPC again for a few }
{ minutes. }
NAS_RandSeed = 3; { Individual seed for shopkeepers. }
NAS_RestockTime = 4;
NAS_PickPocketRestock = 5; { Recharge time for picking pockets. }
{ TACTICS SETTINGS }
NAS_OptMax = 6;
NAS_OptMin = 7;
NAS_PerformancePenalty = 8; { Harder to impress same NPCs after first few tries. }
{ This attribute records how well two characters like each other or }
{ hate each other. The "S" identifier is the CID of the character }
{ to which this reaction score applies. }
NAG_ReactionScore = 6;
{ This attribute records the relationship between two factions. }
NAG_FactionScore = 8;
{ This attribute records the relationship this NPC has with }
{ another NPC in the game. }
NAG_Relationship = 10;
{ S descriptor is the CID of the other NPC. }
{ ... or 0 for the PC. }
NAV_ArchEnemy = -1;
NAV_ArchAlly = 1; { Is there such a thing as an arch-ally? }
{ Who really knows. }
{ If the relationship type is greater than 0, the NPC can join the lance. }
NAV_Family = 2;
NAV_Lover = 3;
ArchEnemyReactionPenalty = 25;
Same_Faction_Bonus = 10;
MaxFactionScore = 25;
MinFactionScore = -50;
Function SeekFaction( Scene: GearPtr; ID: Integer ): GearPtr;
Function GetFactionID( Part: GearPtr ): Integer;
Function FactionIsInactive( Fac: GearPtr ): Boolean;
Function PlotElementID( Plot: GearPtr; Code: Char; ID: LongInt ): Integer;
Function FindPersonaPlot( Adventure: GearPtr; CID: Integer ): GearPtr;
Function SeekPlotElement( Adventure , Plot: GearPtr; N: Integer; GB: GameBoardPtr ): GearPtr;
Function PersonalityCompatability( PC, NPC: GearPtr ): Integer;
Function ReactionScore( Scene, PC, NPC: GearPtr ): Integer;
Function CreateRumorList( GB: gameBoardPtr; PC,NPC: GearPtr ): SAttPtr;
Function IdleChatter: String;
Function IsSexy( PC, NPC: GearPtr ): Boolean;
function DoChatting( GB: GameBoardPtr; var Rumors: SAttPtr; PC,NPC: GearPtr; Var Endurance,FreeRumors: Integer ): String;
Function SeekPersona( GB: GameBoardPtr; CID: LongInt ): GearPtr;
function SeekGearByCID( LList: GearPtr; CID: LongInt ): GearPtr;
Function NewCID( GB: GameBoardPtr; Adventure: GearPtr ): LongInt;
Function NewNID( GB: GameBoardPtr; Adventure: GearPtr ): LongInt;
Function IsArchEnemy( Adv,NPC: GearPtr ): Boolean;
Function IsArchAlly( Adv,NPC: GearPtr ): Boolean;
Function XNPCDesc( Adv,NPC: GearPtr ): String;
Function GenerateEnemyHook( Scene,PC,NPC: GearPtr; Desc: String ): GearPtr;
Function GenerateAllyHook( Scene,PC,NPC: GearPtr ): GearPtr;
Function LancematesPresent( GB: GameBoardPtr ): Integer;
Function FindNPCByKeyWord( GB: GameBoardPtr; KW: String ): GearPtr;
implementation
uses ability,gearutil,ghchars,rpgdice,texutil;
const
Num_Openings = 7; { Number of TraitChatter opening phrases. }
Num_Improve_Msg = 3; { Number of skill improvement messages. }
Chat_MOS_Measure = 10;
var
{ Strings for the random conversation generator. }
Noun_List,Phrase_List,Adjective_List,RLI_List,Chat_Msg_List,Threat_List: SAttPtr;
Trait_Chatter: Array [1..Num_Personality_Traits,1..2] of SAttPtr;
Function SeekFaction( Scene: GearPtr; ID: Integer ): GearPtr;
{ Look for a faction corresponding to the provided ID number. }
{ Return NIL if no such faction is found. }
var
F: GearPtr;
begin
{ Error check. }
if ( Scene = Nil ) or ( ID = 0 ) then Exit( Nil );
{ Find the root of SCENE, which should be the ADVENTURE. }
{ The faction should be located along the invcoms. }
F := FindRoot( Scene )^.InvCom;
while ( F <> Nil ) and (( F^.G <> GG_Faction ) or ( F^.S <> ID )) do F := F^.Next;
{ If the faction was not in the normal place, call the }
{ heavy-duty and cycle-wasteful search routine. }
if F = Nil then F := SeekGear( FindRoot( Scene ) , GG_Faction , ID );
SeekFaction := F;
end;
Function GetFactionID( Part: GearPtr ): Integer;
{ This function will return the Faction ID associated with }
{ any given part, if appropriate. }
{ FOr a faction this will be it's "S" descriptor. }
{ For anything else, faction affiliation is stored as a NAtt. }
begin
if Part^.G = GG_Faction then begin
GetFactionID := Part^.S;
end else begin
GetFactionID := NAttValue( Part^.NA , NAG_Personal , NAS_FactionID );
end;
end;
Function FactionIsInactive( Fac: GearPtr ): Boolean;
{ Return TRUE if this faction has an INACTIVE tag in its }
{ TYPE string attribute, or FALSE otherwise. }
begin
FactionIsInactive := AStringHasBString( SATtValue( Fac^.SA , 'TYPE' ) , 'INACTIVE' );
end;
Function PlotElementID( Plot: GearPtr; Code: Char; ID: LongInt ): Integer;
{ Determine which plot element is referred to by the supplied data. }
{ CODE indicates what kind of gear we're looking for, while ID }
{ is the identification number that should be listed in the Plot's }
{ stats. }
{ If the supplied ID number cannot be found within this plot, }
{ return 0. }
var
t,N: Integer;
EDesc: String;
begin
N := 0;
Code := UpCase( Code );
for t := 1 to NumGearStats do begin
if Plot^.Stat[T] = ID then begin
EDesc := UpCase( SAttValue( Plot^.SA , 'ELEMENT' + BStr( T ) ) );
DeleteWhiteSpace( EDesc );
if ( EDesc <> '' ) and ( EDesc[1] = Code ) then begin
N := T;
end;
end;
end;
PlotElementID := N;
end;
Function FindMetaPersona( Source: GearPtr; N: Integer ): GearPtr;
{ Locate the replacement persona from this PLOT or STORY. }
var
T,Meta: GearPtr;
begin
T := Source^.SubCom;
Meta := Nil;
while T <> Nil do begin
if ( T^.G = GG_Persona ) and ( T^.S = N ) then Meta := T;
T := T^.Next;
end;
FindMetaPersona := Meta;
end;
Function SeekPlotAlongPath( Part: GearPtr; Code: Char; ID: LongInt; SeekType: Integer; NeedsPersona: Boolean ): GearPtr;
{ Seek a gear which uses the specified element along the given }
{ path. If no such plot is found return Nil. Recursively search }
{ all active subcomponents. }
var
it: GearPtr;
begin
it := Nil;
while ( Part <> Nil ) and ( it = Nil ) do begin
if ( Part^.G = SeekType ) and ( PlotElementID( Part , Code , ID ) <> 0 ) then begin
if NeedsPersona then begin
if FindMetaPersona( Part , PlotElementID( Part , Code , ID ) ) <> Nil then begin
it := Part;
end;
end else begin
it := Part;
end;
end else if ( Part^.G = GG_Story ) or ( Part^.G = GG_Faction ) then begin
it := SeekPlotALongPath( Part^.InvCom , Code , ID , SeekType , NeedsPersona );
end;
Part := Part^.Next;
end;
SeekPlotAlongPath := it;
end;
Function FindPersonaPlot( Adventure: GearPtr; CID: Integer ): GearPtr;
{ Search all through ADVENTURE looking for a plot which }
{ involves PERSONA. If no such plot is found, return NIL. }
begin
{ Plots should be located along Adventure/InvCom. Plots which }
{ are not located there are probably sub-plots, so they probably }
{ don't yet have actors assigned. }
Adventure := FindRoot( Adventure );
if ( Adventure = Nil ) or ( Adventure^.G <> GG_Adventure ) then begin
FindPersonaPlot := Nil;
end else begin
FindPersonaPlot := SeekPlotAlongPath( Adventure^.InvCom , 'C' , CID , GG_Plot , False );
end;
end;
Function FindPersonaStory( Adventure: GearPtr; CID: Integer ): GearPtr;
{ Search all through ADVENTURE looking for a story which }
{ involves PERSONA. If no such story is found, return NIL. }
begin
Adventure := FindRoot( Adventure );
if ( Adventure = Nil ) or ( Adventure^.G <> GG_Adventure ) then begin
FindPersonaStory := Nil;
end else begin
FindPersonaStory := SeekPlotAlongPath( Adventure^.InvCom , 'C' , CID , GG_Story , True );
end;
end;
Function SeekPlotElement( Adventure , Plot: GearPtr; N: Integer; GB: GameBoardPtr ): GearPtr;
{ Find the gear referred to in the N'th element of PLOT. }
{ If no such element ay be found return Nil. }
var
Desc: String;
Part: GearPtr;
begin
{ Start by locating the element description string. }
Desc := UpCase( SAttValue( Plot^.SA , 'ELEMENT' + BStr( N ) ) );
Adventure := FindRoot( Adventure );
{ Look for the element in the sensible place, given the }
{ nature of the string. }
if Desc = '' then begin
Part := Nil;
end else if Desc[1] = 'C' then begin
{ Find a character. }
Part := SeekGearByCID( Adventure , Plot^.Stat[N] );
if ( Part = Nil ) and ( GB <> Nil ) then Part := SeekGearByCID( GB^.Meks , Plot^.Stat[N] );
end else if Desc[1] = 'S' then begin
{ Find a scene. }
if GB <> Nil then begin
Part := FindActualScene( GB , Plot^.Stat[ N ] );
end else begin
Part := SeekGear( Adventure , GG_Scene , Plot^.Stat[ N ] );
end;
end else if Desc[1] = 'F' then begin
{ Find a faction. }
Part := SeekGear( Adventure , GG_Faction , Plot^.Stat[ N ] );
end else if Desc[1] = 'I' then begin
{ Find an item. }
Part := SeekGearByIDTag( Adventure , NAG_Narrative , NAS_NID , Plot^.Stat[ N ] );
if ( Part = Nil ) and ( GB <> Nil ) then Part := SeekGearByIDTag( GB^.Meks , NAG_Narrative , NAS_NID , Plot^.Stat[ N ] );
end else begin
Part := Nil;
end;
{ Return the part that was found. }
SeekPlotElement := Part;
end;
Function PlotUsedHere( Plot: GearPtr; GB: GameBoardPtr ): Boolean;
{ See whether or not any of the elements of PLOT are in use on }
{ this game board or in its associated scene. }
var
PUH,EH: Boolean;
T: Integer;
Desc: String;
begin
{ Error check - Make sure both the plot and the game board are }
{ defined. }
if ( Plot = Nil ) or ( GB = Nil ) then begin
PlotUsedHere := False;
end else begin
{ Assume FALSE, then look for any element that's being used }
{ on the game board. }
PUH := False;
{ Search through all the elements. }
for t := 1 to NumGearStats do begin
{ Start by locating the element description string. }
Desc := UpCase( SAttValue( Plot^.SA , 'ELEMENT' + BStr( T ) ) );
{ Look for the element in the sensible place, given the }
{ nature of the string. }
if Desc = '' then begin
EH := False;
end else if Desc[1] = 'C' then begin
{ Find a character. }
EH := SeekGearByCID( GB^.Meks , Plot^.Stat[T] ) <> Nil;
end else if Desc[1] = 'S' then begin
{ Find a scene. }
if GB^.Scene <> Nil then EH := Plot^.Stat[ T ] = GB^.Scene^.S
else EH := False;
end else if Desc[1] = 'I' then begin
{ Find an item. }
EH := SeekGearByIDTag( GB^.Meks , NAG_Narrative , NAS_NID , Plot^.Stat[ T ] ) <> Nil;
end;
PUH := PUH or EH;
end;
{ Return whatever result was found. }
PlotUsedHere := PUH;
end;
end;
Function GeneralCompatability( PC1, PC2: GearPtr ): Integer;
{ This function will determine the general level of }
{ compatability between two characters. This is the }
{ modifier which will be applied to most interaction }
{ rolls. }
{ It is determined by several things - }
{ - Similarity of stats and skills }
var
T,S1,S2: Integer;
BCS: Integer; { Base compatability score }
begin
{ Error Check - Make sure both PCs are valid gears. }
if ( PC1 = Nil ) or ( PC2 = Nil ) then begin
GeneralCompatability := 0;
{ Error Check - Make sure both PCs are characters. }
end else if ( PC1^.G <> GG_Character ) or ( PC2^.G <> GG_Character ) then begin
GeneralCompatability := 0;
end else begin
{ Initialize the compatability score to 0. }
BCS := 0;
{ Check the stats. Every stat that is wildly different will }
{ cause a drop in compatability, while every stat which is }
{ very similar will cause a rise in compatability. }
for t := 1 to 8 do begin
if Abs( PC1^.Stat[t] - PC2^.Stat[t] ) > 8 then begin
Dec( BCS );
end else if ( PC1^.Stat[t] - PC2^.Stat[t] ) < 3 then begin
Inc( BCS );
end;
end;
{ Check the skills. Every skill that both PCs have will }
{ cause a rise in compatability. }
for t := 1 to NumSkill do begin
S1 := NAttValue( PC1^.NA , NAG_Skill , T );
S2 := NAttValue( PC2^.NA , NAG_Skill , T );
if ( S1 > 10 ) and ( S2 > 10 ) then begin
BCS := BCS + 3;
end else if ( S1 > 5 ) and ( S2 > 5 ) then begin
BCS := BCS + 2;
end else if ( S1 > 0 ) and ( S2 > 0 ) then begin
BCS := BCS + 1;
end;
end;
GeneralCompatability := BCS;
end;
end;
Function PersonalityCompatability( PC, NPC: GearPtr ): Integer;
{ Calculate the compatability between PC and NPC based on their }
{ personality traits. }
var
T,CS: Integer;
NPC_Score,PC_Score: Integer;
begin
{ Initialize the Compatability Score to 0. }
CS := 0;
{ Loop through all the personality traits. }
for t := 1 to Num_Personality_Traits do begin
{ Determine the scores of both PC and NPC with regard to this }
{ personality trait. }
PC_Score := NAttValue( PC^.NA , NAG_CharDescription , -T );
NPC_Score := NAttValue( NPC^.NA , NAG_CharDescription , -T );
{ If the personality trait being discussed here is Villainousness, }
{ this always causes a negative reaction. Otherwise, a reaction }
{ will only happen if both the PC and the NPC have points in }
{ this trait. }
if ( T = Abs( NAS_Heroic ) ) and (PC_Score < -10 ) then begin
CS := CS - Abs( PC_Score ) div 2;
end else if ( T = Abs( NAS_Renowned ) ) then begin
{ Being renowned is always good, while being wangtta is }
{ always bad. }
if PC_Score > 0 then begin
CS := CS + ( PC_Score div 10 );
end else begin
CS := CS - ( Abs( PC_Score ) div 10 );
end;
end else if ( PC_Score <> 0 ) and ( NPC_Score <> 0 ) then begin
if Sgn( PC_Score ) = Sgn( NPC_Score ) then begin
{ The traits are in agreement. Increase CS. }
CS := CS + Abs( PC_Score ) div 10;
end else if ( Abs( PC_Score ) > 10 ) and ( Abs( NPC_Score ) > 10 ) then begin
{ The traits are in opposition. Decrease CS. }
CS := CS - 5;
end;
end;
end;
PersonalityCompatability := CS;
end;
Function FactionScore( Scene: GearPtr; F0,F1: Integer ): Integer;
{ Given two factions, return the amount by which they are }
{ allied to each other or hate each other. }
var
Fac_0: GearPtr;
it: Integer;
begin
if ( F0 = 0 ) or ( F1 = 0 ) then begin
it := 0;
end else if F0 = F1 then begin
it := Same_Faction_Bonus;
end else begin
Fac_0 := SeekFaction( Scene , F0 );
if Fac_0 <> Nil then begin
it := NAttValue( Fac_0^.NA , NAG_FactionScore , F1 );
end else begin
it := 0;
end;
end;
FactionScore := it;
end;
Function FactionCompatability( Scene, PC, NPC: GearPtr ): Integer;
{ Determine the faction compatability scores between PC and NPC. }
{ + the PC's reputation with the NPC's faction. }
{ - if PC is enemy of allied faction. }
{ - if PC is ally of enemy faction. }
var
NPC_FID,PC_FID,it: Integer;
FAC: GearPtr;
begin
{ Step one - Locate the FACTION information of the NPC, and }
{ the PC's FACTION ID.. }
NPC_FID := NAttValue( NPC^.NA , NAG_Personal , NAS_FactionID );
Fac := SeekFaction( Scene , NPC_FID );
PC_FID := NAttValue( PC^.NA , NAG_Personal , NAS_FactionID );
it := FactionScore( Scene , NPC_FID , PC_FID );
if FAC <> Nil then it := it + PersonalityCompatability( PC , FAC );
if it > MaxFactionScore then it := MaxFactionScore
else if it < MinFactionScore then it := MinFactionScore;
FactionCompatability := it;
end;
Function ReactionScore( Scene, PC, NPC: GearPtr ): Integer;
{ Return a score in the range of -100..+100 which tells how much }
{ the NPC likes the PC. }
var
it,Persona: Integer;
begin
{ The basic Reaction Score is equal to GENERAL COMPATABILITY + the }
{ existing reaction modifier. }
Persona := NAttValue( NPC^.NA , NAG_Personal , NAS_CID );
it := GeneralCompatability( PC , NPC ) + PersonalityCompatability( PC , NPC ) + NAttValue( PC^.NA , NAG_ReactionScore , Persona );
{ If the scene is defined, add the faction compatability score. }
if Scene <> Nil then it := it + FactionCompatability( Scene , PC , NPC );
{ Make sure IT doesn't go out of bounds. }
if it > 100 then it := 100
else if it < -100 then it := -100;
if HasTalent( PC, NAS_Bishounen ) then begin
it := it + 10;
if it < 0 then it := 0;
end else if ( NAttValue( NPC^.NA , NAG_Relationship , NAttValue( PC^.NA , NAG_Personal , NAS_CID ) ) = NAV_ArchEnemy ) then begin
{ A true archenemy will never have a greater reaction score than 0. }
{ Unless you're very very good looking, of course. }
it := it - ArchEnemyReactionPenalty;
if it > 0 then it := 0;
end;
ReactionScore := it;
end;
Function BlowOff: String;
{ The NPC will just say something mostly useless to the PC. }
begin
{ At some point in time I will make a lovely procedure that will }
{ create all sorts of useless chatter. Right now, I'll just return }
{ the following constant string. }
BlowOff := 'I really don''t have much time to chat today, I have a lot of things to do.';
end;
function MadLibString( SList: SAttPtr ): String;
{ Given a list of string attributes, return one of them at random. }
var
SA: SAttPtr;
begin
SA := SelectRandomSAtt( SList );
if SA <> Nil then MadLibString := SA^.Info
else MadLibString := '***ERROR***';
end;
Function FormatChatString( Msg1: String ): String;
{ Do formatting on this string, adding nouns, adjectives, }
{ and threats as needed. }
var
msg2,w: String;
begin
msg2 := '';
while msg1 <> '' do begin
w := ExtractWord( msg1 );
if W[1] = '%' then begin
DeleteFirstChar( W );
if UpCase( W[1] ) = 'N' then begin
DeleteFirstChar( W );
W := MadLibString( Noun_List ) + W;
end else if UpCase( W[1] ) = 'T' then begin
DeleteFirstChar( W );
W := MadLibString( Threat_List ) + W;
end else begin
DeleteFirstChar( W );
W := MadLibString( Adjective_List ) + W;
end;
end;
msg2 := msg2 + ' ' + w;
end;
DeleteWhiteSpace( Msg2 );
FormatChatString := Msg2;
end;
Function IdleChatter: String;
{ Create a Mad-Libs style line for the NPC to tell the PC. }
{ Hopefully, these mad-libs will simulate the cheerfully nonsensical }
{ things that poorly tanslated anime characters often say to }
{ each other. }
{ After testing this procedure, the effect is more akin to the }
{ konglish slogans which adorn stationary & other character goods... }
{ Close enough! I've got a winner here... }
var
msg1: String;
begin
{ Start with a MadLib form in msg1, and nothing in Msg2. }
{ Transfer the message from M1 to M2 one word at a time, replacing }
{ nouns and adjectives along the way. }
msg1 := MadLibString( Phrase_List );
IdleChatter := FormatChatString( Msg1 );
end;
Function DoTraitChatter( NPC: GearPtr; Trait: Integer ): String;
{ The NPC needs to say a line which should give some indication }
{ as to his/her orientation with respect to the listed }
{ personality trait. }
const
Num_Phrase_Bases = 3;
var
Rk,Pro: Integer;
msg: String;
begin
{ To start with, find the trait rank. }
Rk := NAttValue( NPC^.NA , NAG_CharDescription , -Trait );
{ Insert a basic starting phrase in the message, or perhaps none }
{ at all... }
if Random( 10 ) <> 1 then begin
msg := SAttValue( Chat_Msg_List , 'TRAITCHAT_Lead' + BStr( Random( Num_Openings ) + 1 ) ) + ' ';
end else begin
msg := '';
end;
if Abs( Rk ) > 10 then begin
{ Determine which side of the trait the NPC is in favor of. }
if Rk > 0 then Pro := 1
else Pro := 2;
{ The NPC will either say that they like something from their own side, }
{ or that they dislike something from the other. }
if Random( 5 ) <> 1 then begin
{ Like something. }
msg := msg + SAttValue( Chat_Msg_List , 'TRAITCHAT_Like' + BStr( Random( Num_Phrase_Bases ) + 1 ) ) + ' ' + MadLibString( Trait_Chatter[ Trait , Pro ] ) + '.';
end else begin
{ Dislike something. }
msg := msg + SAttValue( Chat_Msg_List , 'TRAITCHAT_Hate' + BStr( Random( Num_Phrase_Bases ) + 1 ) ) + ' ' + MadLibString( Trait_Chatter[ Trait , 3 - Pro ] ) + '.';
end;
end else begin
Pro := Random( 2 ) + 1;
msg := msg + SAttValue( Chat_Msg_List , 'TRAITCHAT_Ehhh' + BStr( Random( Num_Phrase_Bases ) + 1 ) ) + ' ' + MadLibString( Trait_Chatter[ Trait , Pro ] ) + '.';
end;
DoTraitChatter := Msg;
end;
Function CreateRumorList( GB: gameBoardPtr; PC,NPC: GearPtr ): SAttPtr;
{ Scour the GB for information which can be passed to the PC. }
var
InfoList: SAttPtr;
Part: GearPtr;
{ Procedures Block }
Procedure ExtractData( P: GearPtr );
{ Store all relevant info from PART. }
var
Rumor: String;
Trait,Level: Integer;
Persona: GearPtr;
begin
if P <> NPC then begin
Rumor := SAttValue( P^.SA , 'RUMOR' );
if Rumor <> '' then StoreSAtt( InfoList , MadLibString( RLI_List ) + ' ' + Rumor );
if P^.G = GG_Character then begin
{ At most one personality trait per NPC will be added }
{ to the list. This is to keep them from overwhelming the }
{ rumors from plots & other stuff... }
Trait := Random( Num_Personality_Traits ) + 1;
Level := NAttValue( P^.NA , NAG_CharDescription , -Trait );
if Level <> 0 then begin
if P = PC then begin
StoreSAtt( InfoList , MadLibString( RLI_List ) + ' you are ' + LowerCase( PersonalityTraitDesc( Trait,Level ) ) + '.' );
end else begin
StoreSAtt( InfoList , MadLibString( RLI_List ) + ' ' + GearName( P ) + ' is ' + LowerCase( PersonalityTraitDesc( Trait,Level ) ) + '.' );
end;
end;
Persona := SeekPersona( GB , NAttValue( P^.NA , NAG_Personal , NAS_CID ) );
if Persona <> Nil then ExtractData( Persona );
end else if Part^.G = GG_Scene then begin
{ Include a rumor based on what faction controls this scene. }
Persona := SeekFaction( GB^.Scene , NAttValue( Part^.NA , NAG_Personal , NAS_FactionID ) );
if Persona <> Nil then begin
Rumor := MadLibString( RLI_List ) + ' ';
Rumor := Rumor + SAttValue( Chat_Msg_List , 'RUMOR_TownFac1' ) + GearName( Persona ) + SAttValue( Chat_Msg_List , 'RUMOR_TownFac2' );
StoreSAtt( InfoList , Rumor );
end;
end else if Part^.G = GG_Faction then begin
{ If the faction is active, tell about its traits. }
{ Otherwise, tell that it has been disbanded. }
if AStringHasBString( SAttValue( P^.SA , 'TYPE' ) , 'INACTIVE' ) then begin
StoreSAtt( InfoList , MadLibString( RLI_List ) + ' ' + GearName( P ) + SAttValue( chat_msg_list , 'FACTION_IS_INACTIVE' ) );
end else begin
Trait := Random( Num_Personality_Traits ) + 1;
Level := NAttValue( P^.NA , NAG_CharDescription , -Trait );
if Level <> 0 then begin
StoreSAtt( InfoList , MadLibString( RLI_List ) + ' ' + GearName( P ) + ' is ' + LowerCase( PersonalityTraitDesc( Trait,Level ) ) + '.' );
end;
end;
end;
end else begin
{ Include information about the NPC's faction, }
{ if appropriate. }
Persona := SeekFaction( GB^.Scene , NAttValue( NPC^.NA , NAG_Personal , NAS_FactionID ) );
if Persona <> Nil then begin
Rumor := SAttValue( Chat_Msg_List , 'TRAITCHAT_Lead' + BStr( Random( Num_Openings ) + 1 ) ) + ' ';
Rumor := Rumor + SAttValue( Chat_Msg_List , 'RUMOR_Membership1' ) + GearName( Persona ) + SAttValue( Chat_Msg_List , 'RUMOR_Membership2' );
StoreSAtt( InfoList , Rumor );
end;
end;
end;
Procedure CheckTrackForRumors( P: GearPtr );
{ Check along this path for rumors, calling the Extract Data }
{ procedure as needed. }
begin
while P <> Nil do begin
if P^.G = GG_Plot then begin
if PlotUsedHere( P , GB ) then ExtractData( P );
end else if ( P^.G = GG_Story ) or ( P^.G = GG_Faction ) then begin
ExtractData( P );
CheckTrackForRumors( P^.InvCom );
end;
P := P^.Next;
end;
end;
begin
{ Initialize INFOLIST to Nil. String Attributes will be used to store }
{ all the possible bits of information that might be given to the PC. }
InfoList := Nil;
{ Check all objects on the map for RUMOR SAtts. }
Part := GB^.Meks;
while Part <> Nil do begin
ExtractData( Part );
Part := Part^.Next;
end;
{ If this gameboard has a SCENE gear defined, check both the scene }
{ and all of its level one children for runors. }
if GB^.Scene <> Nil then begin
Part := GB^.Scene;
ExtractData( Part );
Part := GB^.Scene^.SubCom;
while Part <> Nil do begin
ExtractData( Part );
Part := Part^.Next;
end;
Part := GB^.Scene^.InvCom;
while Part <> Nil do begin
ExtractData( Part );
Part := Part^.Next;
end;
{ Look for an ADVENTURE gear, then extract rumors from the }
{ global plots. }
Part := FindRoot( GB^.Scene );
if ( Part^.G = GG_Adventure ) and ( not AStringHasBString( SAttValue( GB^.Scene^.SA , 'TYPE' ) , 'ISOLATED' ) ) then begin
CheckTrackForRumors( Part^.InvCom );
end;
end;
CreateRumorList := InfoList;
end;
function InOpposition( PC , NPC: GearPtr; Trait: Integer ): Boolean;
{ If the PC and the NPC disagree on this personality TRAIT, }
{ return TRUE. Otherwise return FALSE. }
var
T1,T2: Integer;
begin
T1 := NAttValue( PC^.NA , NAG_CharDescription , -Trait );
T2 := NAttValue( NPC^.NA , NAG_CharDescription , -Trait );
if ( Abs( T1 ) > 10 ) and ( Abs( T2 ) > 10 ) then begin
{ The characters are in opposition if their trait }
{ values are on opposite sides of 0. }
InOpposition := Sgn( T1 ) <> Sgn( T2 );
end else begin
{ If the traits aren't strongly held by both, then }
{ no real opposition. }
InOpposition := False;
end;
end;
function InHarmony( PC , NPC: GearPtr; Trait: Integer ): Boolean;
{ If the PC and the NPC agree on this personality TRAIT, }
{ return TRUE. Otherwise return FALSE. }
var
T1,T2: Integer;
begin
T1 := NAttValue( PC^.NA , NAG_CharDescription , -Trait );
T2 := NAttValue( NPC^.NA , NAG_CharDescription , -Trait );
if ( Abs( T1 ) > 10 ) and ( Abs( T2 ) > 10 ) then begin
{ The characters are in opposition if their trait }
{ values are on opposite sides of 0. }
InHarmony := Sgn( T1 ) = Sgn( T2 );
end else begin
{ If the traits aren't strongly held by both, then }
{ no real opposition. }
InHarmony := False;
end;
end;
Function IsSexy( PC, NPC: GearPtr ): Boolean;
{ Return TRUE if there are some potential sparks between }
{ the PC and NPC, or FALSE if there aren't. }
begin
if NAttValue( PC^.NA, NAG_CharDescription, NAS_RomanceType ) = NAV_RT_Anyone then begin
IsSexy := True;
end else if NAttValue( PC^.NA, NAG_CharDescription, NAS_RomanceType ) = NAV_RT_Male then begin
IsSexy := NAttValue( NPC^.NA , NAG_CharDescription , NAS_Gender ) = NAV_Male;
end else if NAttValue( PC^.NA, NAG_CharDescription, NAS_RomanceType ) = NAV_RT_Female then begin
IsSexy := NAttValue( NPC^.NA , NAG_CharDescription , NAS_Gender ) = NAV_Female;
end else IsSexy := False;
end;
Function DoleChatExperience( PC,NPC: GearPtr ): String;
{ Give a skill-specific experience award to either Conversation }
{ or Flirtation. }
var
Skill_To_Improve: Integer;
msg: sTRING;
begin
{ Give a single point of general experience or a }
{ skill-specific award. }
if Random( 2 ) = 1 then begin
DoleExperience( PC , XPA_GoodChat );
msg := '';
end else begin
Skill_To_Improve := 19;
if IsSexy( PC , NPC ) and ( Random( 3 ) = 1 ) then Skill_To_Improve := 27;
if DoleSkillExperience( PC , Skill_To_Improve , XPA_GoodChat ) then begin
msg := SAttValue( Chat_Msg_List , 'CHAT_Skill' + BStr( Skill_To_Improve ) + '_' + BStr( Random( Num_Improve_Msg ) + 1 ) );
end else begin
msg := '';
end;
end;
DoleChatExperience := msg;
end;
function DoChatting( GB: GameBoardPtr; var Rumors: SAttPtr; PC,NPC: GearPtr; Var Endurance,FreeRumors: Integer ): String;
{ This function will do chatting between the specified PC }
{ and NPC with the specified persona, adjust the Reaction and }
{ Endurance variables, then return a string that results }
{ from the chat session. }
var
SkRoll,SkTarget,MOS: Integer;
Persona: Integer;
msg,alt_msg: String;
RTemp: SAttPtr;
Trait: Integer; { The personality trait invoked by this conversation. }
Function TraitWeight( N : Integer ): Integer;
{ Return a value indicating how strongly this NPC }
{ feels about this particular personality trait. }
begin
TraitWeight := Abs( NAttValue( NPC^.NA , NAG_CharDescription , -N ) ) + 5;
end;
Function SelectTraitForChatter: Integer;
{ Decide what the subject of the conversation is going }
{ to be based on the NPC's traits. }
var
total,N,T: Integer;
begin
{ The trait to be used will be determined by the }
{ weight of the NPC's traits. }
{ Find the total of the NPC's trait points. }
total := 0;
for t := 1 to Num_Personality_Traits do total := total + TraitWeight( T );
{ Next, select a random value and find a trait based on that. }
N := Random( Total );
T := 1;
while N > TraitWeight( T ) do begin
N := N - TraitWeight( T );
Inc( T );
end;
SelectTraitForChatter := T;
end;
Procedure SelectChatter;
{ Normally idle chatter has been selected; this procedure may }
{ select a trait-based interaction instead. }
begin
if ( Trait <> 0 ) and ( Random( 2 ) = 1 ) then begin
{ Trait-Based Chatter. }
msg := DoTraitChatter( NPC , Trait );
end else begin
{ Regular Chatter. }
msg := IdleChatter;
end;
end;
begin
{ Start by making a social interaction roll for the PC. }
SkRoll := RollStep( SkillValue( PC , 19 ) );
{ Apply flirtation bonus to the skill roll, if appropriate. }
{ The bonus only applies if the PC has ranks in flirtation or is a Jack of all Trades. }
if ( NAttValue( PC^.NA , NAG_Skill , 27 ) > 0 ) or HasTalent( PC , NAS_JackOfAll ) then begin
if HasTalent( PC, NAS_Bishounen ) then begin
SkRoll := SkRoll + RollStep( SkillValue( PC , 27 ) );
end else if NAttValue( PC^.NA, NAG_CharDescription, NAS_RomanceType ) in [NAV_RT_NoOne,NAV_RT_Anyone] then begin
{ If looking for anyone, or looking for no-one, apply half the normal bonus. }
SkRoll := SkRoll + ( RollStep( SkillValue( PC , 27 ) ) div 2 );
end else if IsSexy( PC , NPC ) then begin
SkRoll := SkRoll + RollStep( SkillValue( PC , 27 ) );
end;
end;
{ Initialize TRAIT to random, and find the NPC's PERSONA value. }
{ These things will be needed later. }
if Random( 3 ) <> 1 then begin
Trait := SelectTraitForChatter;
end else begin
Trait := 0;
end;
Persona := NAttValue( NPC^.NA , NAG_Personal , NAS_CID );
{ Determine the effect target number. The more extreme the NPC's }
{ current opinion of the PC is, the more difficult it will be to }
{ change that opinion. In addition, if the opinion is a negative }
{ one, it'll be even harder to change the opinion. }
SkTarget := 10 + Abs( ReactionScore( GB^.Scene , PC , NPC ) - 10 ) div 3;
{ Reduce ENDURANCE. }
if ( SkRoll > SkTarget ) or ( Random ( 110 ) > ReactionScore( GB^.Scene , PC , NPC ) ) then Dec( Endurance );
if SkRoll < RollStep( 4 ) then Dec( Endurance );
{ Finally, decide what the result of all this die rolling will be. }
{ First see what useful (or useless) information the NPC will share. }
if ( SkRoll + ReactionScore( GB^.Scene , PC , NPC ) + Random(10) - Random(10) ) < 0 then begin
msg := BlowOff;
{ Since the NPC is trying to get rid of the PC, }
{ decrement ENDURANCE one more time. }
Dec( Endurance );
end else if ( FreeRumors > 0 ) and ( Rumors <> Nil ) then begin
RTemp := SelectRandomSAtt( Rumors );
msg := RTemp^.info;
RemoveSAtt( Rumors, RTemp );
Dec( FreeRumors );
end else if ( SkRoll + ( ReactionScore( GB^.Scene , PC , NPC ) div 10 ) ) < 10 then begin
SelectChatter;
end else begin
if ( Rumors <> Nil ) and ( SkRoll > ( 10 + Random( 21 ) ) ) then begin
RTemp := SelectRandomSAtt( Rumors );
msg := RTemp^.info;
RemoveSAtt( Rumors, RTemp );
end else begin
SelectChatter;
end;
end;
{ Secondly there's a chance that the chatting will improve relations }
{ between the PC and NPC. If a TRAIT conversation has taken place, }
{ this could make things harder. }
if ( Trait <> 0 ) then begin
if InOpposition( PC , NPC , Trait ) then begin
SkRoll := SkRoll - SkTarget;
end else if InHarmony( PC , NPC , Trait ) then begin
SkRoll := SkRoll + ( ( SkRoll * Abs( NAttValue( PC^.NA , NAG_CharDescription , -Trait ) ) ) div 100 );
end;
end;
if SkRoll > SkTarget then begin
MOS := 1 + ( SkRoll - SkTarget ) div Chat_MOS_Measure;
if Persona > 0 then begin
AddNAtt( PC^.NA , NAG_ReactionScore , Persona , MOS );
if ( MOS > 1 ) and ( SkTarget > 15 ) then DoleExperience( PC , MOS div 2 );
end;
end else if SkRoll < 0 then begin
{ A negative skill roll means that the reaction is going to worsen. }
MOS := 1 + Abs( SkRoll ) div 2;
{ If the PC has the DIPLOMATIC talent, this can be avoided. }