-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy patharenascript.pp
6137 lines (5385 loc) · 208 KB
/
arenascript.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 arenascript;
{ This unit holds the scripting language for GearHead. }
{ It's pretty similar to the scripts developed for DeadCold. }
{ Basically, certain game events will add a trigger to the }
{ list. In the main combat procedure, if there are any pending }
{ triggers, they will be checked against the events list to }
{ see if anything happens. }
{ Both the triggers and the event scripts will be stored as }
{ normal string attributes. }
{ This unit also handles conversations with NPCs, since those }
{ are written using the scripting language and may use any }
{ commands available there + a few special commands. }
{
GearHead2, 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
}
{$LONGSTRINGS ON}
interface
uses gears,locale,
{$IFDEF ASCII}
vidmenus,vidgfx;
{$ELSE}
sdlmenus,sdl;
{$ENDIF}
const
NAG_ScriptVar = 0;
NAG_SkillCounter = -16; { Counter for skill tests. }
Max_Plots_Per_Story = 5;
NAG_ArenaData = -18; { Used to store information about mecha arena combat }
NAS_ArenaState = 1; { Determines what exactly is happening at the arena now. }
NAV_AS_Vacant = 0; { No fight now, no fight scheduled }
NAV_AS_Ready = 1; { Start fight next time PC enters scene }
NAV_AS_Battle = 2; { Battle in progress }
NAV_AS_Win = 3; { PC has won the battle }
NAV_AS_Loss = 4; { PC hass lost the battle }
NAS_ArenaWins = 2; { # of times PC has won match }
NAS_ArenaThreat = 4; { Threat value of enemy mecha }
NAS_ArenaForces = 5; { % of generic enemies to fight }
NAS_ChallengerID = 6; { NPC challenger present during battle }
NAS_ChallengerHome = 7; { Where to return champion after fight }
NAS_ArenaRecharge = 8; { Time when next fight can take place }
{ When playing in arena mode, the following string attributes will be added to the scene }
{ following battle. }
ARENAREPORT_CharDied = 'AR_PCDIED';
ARENAREPORT_CharRecovered = 'AR_PCRECOVERED';
ARENAREPORT_MechaDestroyed = 'AR_MECHADIED';
ARENAREPORT_MechaRecovered = 'AR_MECHARECOVERED';
ARENAREPORT_MechaObtained = 'AR_MECHAOBTAINED';
ARENAREPORT_Personal = 'AR_PERSONAL';
var
{ This gear pointer will be created if a dynamic scene is requested. }
SCRIPT_DynamicEncounter: GearPtr;
{ **************************************** }
{ *** INTERACTION GLOBAL VARIABLES *** }
{ **************************************** }
{ These variables hold information that may be needed anywhere }
{ while interaction is taking place, but are undefined if }
{ interaction is not taking place. }
{ IntMenu should let procedures know whether or not interaction }
{ is currently happening or not- if IntMenu <> Nil, we're in the }
{ middle of a conversation and all other interaction variables }
{ should have good values. }
IntMenu: RPGMenuPtr; { Interaction Menu }
I_PC,I_NPC: GearPtr; { Pointers to the PC & NPC Chara gears }
I_Rumors: SAttPtr; { List of rumors. }
I_Persona: GearPtr; { The conversation currently being used. }
Grabbed_Gear: GearPtr; { This gear can be acted upon by }
{ generic commands. }
lancemate_tactics_persona: GearPtr; { Persona for setting lancemate tactics. }
BLANK_PERSONA: GearPtr; { Simple persona for default NPCs. }
rumor_leads: GearPtr; { Mini-conversations for finding rumors. }
NeedGC: Boolean;
Procedure SetLancemateOrders( GB: GameBoardPtr );
Function NumLancemateSlots( Adv,PC: GearPtr ): Integer;
Procedure BrowseMemoType( GB: GameBoardPtr; Tag: String );
Function BasicSkillTarget( Renown: Integer ): Integer;
Function HardSkillTarget( Renown: Integer ): Integer;
Function Calculate_Reward_Value( GB: GameBoardPtr; Renown,Percent: LongInt ): LongInt;
Function ScriptValue( var Event: String; GB: GameBoardPtr; Scene: GearPtr ): LongInt;
Function AS_GetString( Source: GearPtr; Key: String ): String;
Function ScriptMessage( msg_label: String; GB: GameBoardPtr; Source: GearPtr ): String;
Function NPCScriptMessage( const msg_label: String; GB: GameBoardPtr; NPC, Source: GearPtr ): String;
Procedure InvokeEvent( Event: String; GB: GameBoardPtr; Source: GearPtr; var Trigger: String );
Procedure AddLancemate( GB: GameBoardPtr; NPC: GearPtr );
Function AddLancemateFrontEnd( GB: GameBoardPtr; PC,NPC: GearPtr; CanCancel: Boolean ): Boolean;
Procedure RemoveLancemate( GB: GameBoardPtr; Mek: GearPtr; DoMessage: Boolean );
Procedure HandleInteract( GB: GameBoardPtr; PC,NPC,Persona: GearPtr );
Procedure DoTalkingWIthNPC( GB: GameBoardPtr; PC,Mek: GearPtr; ByTelephone: Boolean );
Function TriggerGearScript( GB: GameBoardPtr; Source: GearPtr; var Trigger: String ): Boolean;
Function CheckTriggerAlongPath( var T: String; GB: GameBoardPtr; Plot: GearPtr; CheckAll: Boolean ): Boolean;
Procedure HandleTriggers( GB: GameBoardPtr );
Function StartRescueScenario( GB: GameBoardPtr; PC: GearPtr; Context: String ): Boolean;
Procedure DoScriptGC( GB: GameBoardPtr );
implementation
uses action,arenacfe,ability,gearutil,ghchars,gearparser,ghmodule,backpack,
ghprop,ghweapon,grabgear,interact,menugear,playwright,rpgdice,
services,texutil,ui4gh,wmonster,narration,description,skilluse,
ghintrinsic,movement,minigame,customization,aibrain,mpbuilder,
{$IFDEF ASCII}
vidmap,vidinfo;
{$ELSE}
sdlgfx,sdlmap,sdlinfo;
{$ENDIF}
const
CMD_Chat = -2;
CMD_Join = -3;
CMD_Quit = -4;
CMD_WhereAreYou = -5;
CMD_AskAboutRumors = -6;
Debug_On: Boolean = False;
var
script_macros,value_macros,Default_Scene_Scripts: SAttPtr;
ASRD_GameBoard: GameBoardPtr;
ASRD_MemoMessage: String;
local_triggers: SAttPtr;
{ ****************************** }
{ *** REDRAW PROCEDURES *** }
{ ****************************** }
Procedure InteractRedraw;
{ Redraw the screen for whatever interaction is going to go on. }
begin
CombatDisplay( ASRD_GameBoard );
SetupInteractDisplay( PlayerBlue );
if I_NPC <> Nil then begin
DisplayInteractStatus( ASRD_GameBoard , I_NPC , CHAT_React , I_Endurance );
end;
GameMsg( CHAT_Message , ZONE_InteractMsg , InfoHiLight );
end;
Procedure ArenaScriptReDraw;
{ Redraw the combat screen for some menu usage. }
begin
if ASRD_GameBoard <> Nil then CombatDisplay( ASRD_GameBoard );
end;
Procedure MemoPageReDraw;
{ Redraw the combat screen for some menu usage. }
begin
if ASRD_GameBoard <> Nil then CombatDisplay( ASRD_GameBoard );
SetupMemoDisplay;
GameMsg( ASRD_MemoMessage , ZONE_MemoText , StdWhite );
end;
Procedure ChoiceReDraw;
{ Redraw the combat screen for some menu usage. }
begin
if ASRD_GameBoard <> Nil then CombatDisplay( ASRD_GameBoard );
SetupMemoDisplay;
GameMsg( ASRD_MemoMessage , ZONE_MemoMenu , StdWhite );
end;
{ **************************** }
{ *** EVERYTHING ELSE *** }
{ **************************** }
Function BasicSkillTarget( Renown: Integer ): Integer;
{ Return an appropriate target for skill rolls for someone of the listed renown. }
var
it: Integer;
begin
it := Renown div 8 + 3;
if it < 5 then it := 5;
BasicSkillTarget := it;
end;
Function HardSkillTarget( Renown: Integer ): Integer;
{ Return a difficult target for skill rolls for someone of the listed renown. }
var
it: Integer;
begin
it := Renown div 7 + 10;
if it < 9 then it := 9;
HardSkillTarget := it;
end;
Function SocSkillTarget( GB: GameBoardPtr; Renown: Integer ): Integer;
{ Return a social difficult target for skill rolls based on Renown and modified }
{ by the relationship between I_PC and I_NPC. }
var
it,react: Integer;
begin
it := Renown div 7 + 7;
if it < 10 then it := 10;
{ If the PC and NPC exist, apply the special modifier. }
if ( I_PC <> Nil ) and ( I_NPC <> Nil ) then begin
react := ReactionScore( GB^.Scene , I_PC , I_NPC );
it := it - ( react div 10 );
end;
SocSkillTarget := it;
end;
Function CreateRumorList( GB: GameBoardPtr; Rumor_Source: GearPtr; SkRoll: Integer; DoHarvest: Boolean; var Rumor_Error: Boolean; const Rumemo_Lead,Rumor_Head: String ): SAttPtr;
{ RUMOR_HEAD is the rumor type to collect: RUMORs or RUMEMOs. }
{ RUMEMO_LEAD is the leading message appended to a rumor if we're }
{ harvesting them for RUMEMOs. }
{ If DoHarvest is TRUE, all found rumors will be changed to RUMEMOs. }
{ ...if FALSE, then SkRoll is ignored and all messages are returned. }
{ Search through the adventure, revealing rumors as you go. When a rumor }
{ is discovered, do the following: }
{ - Check to see if SkRoll is high enough to reveal it. }
{ - If so, add it to the list of rumors. }
{ - Also convert the original rumor to a rumor memo. }
{ If no rumors are found at all, set RUMOR_ERROR to TRUE; otherwise FALSE. }
var
InfoList: SAttPtr;
Function RumorSKTarget( Part: gearPtr ): Integer;
{ Return the skill roll needed to learn this rumor. }
var
Plot: GearPtr;
it: Integer;
begin
{ If we're dealing with a plot-based rumor, get the difficulty number from the plot. }
Plot := PlotMaster( GB , Part );
if Plot <> Nil then begin
{ Use the difficulty rating for this plot. }
it := SocSkillTarget( GB , NAttValue( Plot^.NA , NAG_Narrative , NAS_DifficultyLevel ) );
end else begin
it := 5;
end;
{ In order to keep the process somewhat unpredictable, randomize the target }
{ just a bit. }
it := it - 5 + RollStep( 3 );
if Random( 3 ) = 1 then it := it + Random( 4 );
RumorSKTarget := it;
end;
Procedure AddThisRumor( Part: GearPtr; Rumor: SAttPtr );
{ Add this rumor to the list... maybe. }
var
msg,rh: String;
begin
msg := RetrieveAString( Rumor^.Info );
if DoHarvest then begin
if SkRoll > RumorSkTarget( Part ) then begin
{ This rumor has been retrieved. }
StoreSAtt( InfoList , msg );
rh := RetrieveAPreamble( rumor^.Info );
Rumor^.Info := 'RUMEMO' + Copy( rh , Length( Rumor_Head ) + 1 , Length( rh ) ) + ' <' + RuMemo_Lead + ' ' + msg + '>';
end;
end else begin
{ We aren't converting to RUMEMO right now. Ignore the skill roll }
{ and simply return the message without changing anything. }
StoreSAtt( InfoList , msg );
end;
{ Set RUMOR_ERROR to FALSE, since we just found one. }
RUMOR_ERROR := FALSE;
end;
Procedure GetRumorFromGear( P: GearPtr );
{ Retrieve the rumor info from this gear, without caring about }
{ what kind of gear it is. Well, for the most part, anyhow... }
var
Rumor: SAttPtr;
Level: LongInt;
begin
{ First add the basic rumor. }
Rumor := FindSAtt( P^.SA , Rumor_Head );
if Rumor <> Nil then AddThisRumor( P , Rumor );
{ Next add the quest rumor. }
Level := NAttValue( P^.NA , NAG_Narrative , NAS_PlotID );
if Level < 0 then begin
Rumor := FindSAtt( P^.SA , Rumor_Head + BStr( NAttValue( FindRoot( GB^.Scene )^.NA , NAG_PlotStatus , Level ) ) );
if Rumor <> Nil then AddThisRumor( P , Rumor );
end else if (( P^.G = GG_Persona ) or ( P^.G = GG_MetaScene )) and ( P^.Parent <> Nil ) and ( P^.Parent^.G = GG_Plot ) then begin
{ Finally add the plot rumor. }
Rumor := FindSAtt( P^.SA , Rumor_Head + BStr( NAttValue( FindRoot( GB^.Scene )^.NA , NAG_PlotStatus , Level ) ) );
if Rumor <> Nil then AddThisRumor( P , Rumor );
end;
end;
Procedure RumorWorkup( P: GearPtr ); Forward;
Procedure ExtractData( P: GearPtr );
{ Store all relevant info from PART. }
{ If P is of certain types, we're gonna have to harvest the data from }
{ its associated bits. Characters also need the data from their Personas, }
{ gates to metascenes need to check there, and scenes get faction data. }
var
Persona: GearPtr;
begin
if ( P <> Rumor_Source ) and ( P^.G <> GG_Persona ) then begin
if P <> GB^.Scene then GetRumorFromGear( P );
if P^.G = GG_Character then begin
Persona := SeekPersona( GB , NAttValue( P^.NA , NAG_Personal , NAS_CID ) );
if Persona <> Nil then begin
{ Previously we'd just collect the rumor from the persona }
{ and be done with it, but since Quests have been introduced }
{ the rumor associated with a given NPC can change depending }
{ on quest state. }
GetRumorFromGear( Persona );
end;
end else if ( P^.G = GG_MetaTerrain ) and ( P^.Stat[ STAT_Destination ] < 0 ) then begin
{ Find the metascene, and do a complete rumor work-up of it. }
Persona := FindActualScene( GB , P^.Stat[ STAT_Destination ] );
if Persona <> Nil then begin
RumorWorkup( Persona );
end;
end;
end;
end;
Procedure RumorWorkup( P: GearPtr );
{ Do a complete rumor workup on P, gathering info from it }
{ and all its child gears. }
var
P2: GearPtr;
begin
if P = Nil then Exit;
ExtractData( P );
P2 := P^.SubCom;
while P2 <> Nil do begin
RumorWorkup( P2 );
P2 := P2^.Next;
end;
P2 := P^.InvCom;
while P2 <> Nil do begin
RumorWorkup( P2 );
P2 := P2^.Next;
end;
end;
var
Part: GearPtr;
begin
{ Assume an error until we find a rumor to prove us wrong. }
Rumor_Error := TRUE;
InfoList := Nil;
Part := FindRootScene( GB^.Scene );
RumorWorkup( Part );
Part := GB^.Meks;
while Part <> Nil do begin
ExtractData( Part );
Part := Part^.Next;
end;
CreateRumorList := InfoList;
end;
Function RevealRumors( GB: GameBoardPtr; NPC: GearPtr; SkRoll: Integer; var Rumor_Error: Boolean ): SAttPtr;
{ Reveal some rumors! Call the CreateRumorList procedure with a standard reveal. }
begin
RevealRumors := CreateRumorList( GB, NPC, SkRoll, TRUE, Rumor_Error, ReplaceHash( MsgString( '#SaidThat' ) , PilotName( NPC ) ), 'RUMOR' );
end;
Function ReviewRumorMemos( GB: GameBoardPtr ): SAttPtr;
{ Create the list of rumor memos. }
var
Rumor_Error: Boolean; { A dummy variable. }
begin
ReviewRumorMemos := CreateRumorList( GB, Nil, 0, FALSE, Rumor_Error, '', 'RUMEMO' );
end;
Procedure BrowseMemoType( GB: GameBoardPtr; Tag: String );
{ Create a list, then browse the memos based upon this }
{ TAG type. Possible options are MEMO, NEWS, and EMAIL. }
var
MemoList,M: SAttPtr;
Adv: GearPtr;
Procedure HarvestPlotMemos( LList: SAttPtr );
{ This list may contain plot memos. How to tell? The first four }
{ characters will be "MEMO". It's just like harvesting the history. }
begin
while LList <> Nil do begin
if UpCase( Copy( LList^.Info , 1 , 4 ) ) = 'MEMO' then begin
StoreSAtt( MemoList , RetrieveAString( LList^.Info ) );
end;
LList := LList^.Next;
end;
end;
Procedure CreateMemoList( Part: GearPtr; Tag: String );
{ Look through all gears in the structure recursively, }
{ looking for MEMO string attributes to store in our list. }
var
msg: String;
QID: LongInt;
begin
while Part <> Nil do begin
if Part^.G <> GG_AbsolutelyNothing then begin
if ( tag = 'MEMO' ) and ( Part^.G = GG_Plot ) then begin
{ This is a plot. It may have subplot memos. These are }
{ memos that have the PLOTID attached to their butts. Why? }
{ Because I realized, somewhat late, that a plot which can }
{ contain multiple narrative threads really needs multiple }
{ memos as well. }
HarvestPlotMemos( Part^.SA );
end else begin
{ Not a plot. Just do the regular harvesting work, then. }
msg := SAttValue( Part^.SA , Tag );
if msg <> '' then StoreSAtt( MemoList , msg );
{ This part may also have a quest-related message attached }
{ to it. See if that's so. }
QID := NAttValue( Part^.NA , NAG_Narrative , NAS_PlotID );
if ( QID <> 0 ) then begin
msg := SAttValue( Part^.SA , Tag + '_' + BStr( NAttValue( Adv^.NA , NAG_PlotStatus , Qid ) ) );
if msg <> '' then StoreSAtt( MemoList , msg );
end;
end;
CreateMemoList( Part^.SubCom , Tag );
CreateMemoList( Part^.InvCom , Tag );
end; { if Part = AbsolutelyNothing }
Part := Part^.Next;
end;
end;
Procedure AddQuestMemos;
{ Quest memos work a bit differently than other memos. First, }
{ they only appear so long as the quest they're assigned to is }
{ active (i.e. it has a nonnegative QID). }
var
SA,SA2: SAttPtr;
msg_head: String;
qid: LongInt;
begin
SA := Adv^.SA;
while SA <> Nil do begin
SA2 := SA^.next;
{ If this string attribute is potentially a quest memo, }
{ try to extract its QuestID. If this memo is no longer }
{ valid then delete it. }
if HeadMatchesString( 'MEMO_' , SA^.Info ) then begin
msg_head := RetrieveAPreamble( SA^.Info );
msg_head := Copy( msg_head , 6 , Length( msg_head ) );
qid := ExtractValue( msg_head );
if ( qid <> 0 ) and ( NAttValue( Adv^.NA , NAG_PlotStatus , Qid ) > -1 ) then begin
{ Add it to the list. }
StoreSAtt( MemoList , RetrieveAString( SA^.Info ) );
end else begin
{ Invalid quest memo. Get rid of it. }
RemoveSAtt( Adv^.SA , SA );
end;
end;
SA := SA2;
end;
end;
Function PlaceMemoPhoneCall( PC: GearPtr; MMsg: String ): Boolean;
{ We want to make a phone call to someone mentioned in this memo. }
{ Search through all the NPCs on the game board and within the current city. }
{ Add them to a menu. Then, query the menu, and do talking with the selected NPC. }
{ Return TRUE if a conversation was had, or FALSE otherwise. }
Procedure CheckAlongList( RPM: RPGMenuPtr; LList: GearPtr );
{ Check along this list for NPCs mentioned in the memo, recursively }
{ searching through children as well. }
{ Add any good NPCs found to the menu, using their CID as the key. }
var
Name: String;
CID: LongInt;
begin
while LList <> Nil do begin
if LList^.G = GG_Character then begin
{ This is a character. Is it somebody we're looking for? }
Name := GearName( LList );
CID := NAttValue( LList^.NA , NAG_Personal , NAS_CID );
if ( CID <> 0 ) and ( Pos( Name , MMsg ) > 0 ) and CanContactByPhone( GB , LList ) then begin
AddRPGMenuItem( RPM , GearName( LList ) , CID );
end;
end else begin
{ Not a character. Recurse like mad! }
CheckAlongList( RPM , LList^.SubCom );
CheckAlongList( RPM , LList^.InvCom );
end;
LList := LList^.Next;
end;
end;
var
RPM: RPGMenuPtr;
city,NPC: GearPtr;
CID: LongInt;
begin
{ Step One- Create the menu. }
RPM := CreateRPGMenu( MenuItem , MenuSelect , ZONE_MemoMenu );
CheckAlongList( RPM , GB^.Meks );
City := FindRootScene( GB^.Scene );
if City <> Nil then begin
CheckAlongList( RPM , City^.SubCom );
CheckAlongList( RPM , City^.InvCom );
end;
RPMSortAlpha( RPM );
AlphaKeyMenu( RPM );
if RPM^.NumItem > 0 then begin
AddRPGMenuItem( RPM , MsgString( 'Cancel' ) , -1 );
end else begin
AddRPGMenuItem( RPM , MsgString( 'MEMO_CALL_NoPeople' ) , -1 );
end;
{ Step Two- Query the menu and locate the NPC. }
CID := SelectMenu( RPM , @MemoPageRedraw );
DisposeRPGMenu( RPM );
{ Step Three- Pass the request along to HandleInteract. }
if CID > -1 then begin
NPC := GG_LocateNPC( CID , GB , GB^.Scene );
if NPC <> Nil then begin
DoTalkingWithNPC( GB , PC , NPC , True );
end;
end else NPC := Nil;
PlaceMemoPhoneCall := NPC <> Nil;
end;
Procedure BrowseList;
{ Actually browse the created list. }
var
RPM: RPGMenuPtr;
N,D: Integer;
PC: GearPtr;
begin
{ Locate the PC. We need it for the PComm capability. }
PC := GG_LocatePC( GB );
if MemoList <> Nil then begin
RPM := CreateRPGMenu( MenuItem , MenuSelect , ZONE_MemoMenu );
AddRPGMenuItem( RPM , MsgString( 'MEMO_Next' ) , 1 );
AddRPGMenuItem( RPM , MsgString( 'MEMO_Prev' ) , 2 );
if ( PC <> Nil ) and HasPCommCapability( PC , PCC_Phone ) then AddRPGMenuItem( RPM , MsgString( 'MEMO_Call' ) , 3 );
AddRPGMenuKey( RPM , KeyMap[ KMC_East ].KCode , 1 );
AddRPGMenuKey( RPM , KeyMap[ KMC_West ].KCode , 2 );
AlphaKeyMenu( RPM );
RPM^.Mode := RPMNoCleanup;
N := 1;
repeat
M := RetrieveSAtt( MemoList , N );
ASRD_GameBoard := GB;
ASRD_MemoMessage := M^.Info;
D := SelectMenu( RPM , @MemoPageRedraw );
if D = 1 then begin
N := N + 1;
if N > NumSAtts( MemoList ) then N := 1;
end else if D = 2 then begin
N := N - 1;
if N < 1 then N := NumSAtts( MemoList );
end else if D = 3 then begin
{ We want to place a phone call to someone mentioned }
{ in this memo. Make it so. }
PlaceMemoPhoneCall( PC , M^.Info );
D := -1;
end;
until ( D = -1 ) or not KeepPlayingSC( GB );
DisposeSAtt( MemoList );
DisposeRPGMenu( RPM );
end;
end;
Function NoMemoError: String;
{ Return a string which will explain to the user that there are }
{ no memos of the selected type. }
var
msg: String;
begin
msg := MsgString( 'MEMO_No_' + Tag );
if msg = '' then msg := ReplaceHash( MsgString( 'MEMO_None' ) , LowerCase( Tag ) );
NoMemoError := msg;
end;
begin
{ Error check first - we need the GB and the scene for this. }
if ( GB = Nil ) or ( GB^.Scene = Nil ) then Exit;
tag := UpCase( Tag );
MemoList := Nil;
Adv := FindRoot( GB^.Scene );
if ( Tag = 'RUMEMO' ) then begin
MemoList := ReviewRumorMemos( GB );
end else begin
CreateMemoList( Adv , Tag );
end;
if Tag = 'MEMO' then AddQuestMemos;
{ Sort the memo list. }
if MemoList <> Nil then SortStringList( MemoList )
else StoreSAtt( MemoList , NoMemoError );
BrowseList;
end;
Function YesNoMenu( GB: GameBoardPtr; Prompt,YesMsg,NoMsg: String ): Boolean;
{ This will open up a small window in the middle of the map }
{ display, then prompt the user for a choice. }
{ Return TRUE if the "yes" option was selected, or FALSE if }
{ the "no" option was selected. }
{ This function performs no screen cleanup. }
var
rpm: RPGMenuPtr;
N: Integer;
begin
RPM := CreateRPGMenu( MenuItem , MenuSelect , ZONE_MemoMenu );
AddRPGMenuItem( RPM , YesMsg , 1 );
AddRPGMenuItem( RPM , NoMsg , -1 );
RPM^.Mode := RPMNoCancel;
ASRD_GameBoard := GB;
ASRD_MemoMessage := Prompt;
N := SelectMenu( RPM , @MemoPageRedraw );
DisposeRPGMenu( RPM );
{ Do cleanup before branching. }
CombatDisplay( GB );
YesNoMenu := N <> -1;
end;
Procedure SetLancemateOrders( GB: GameBoardPtr );
{ Go through the lancemates, and assign any orders they might need. }
var
PCUID,DefOrder: LongInt;
mek: gearPtr;
begin
{ Step one- find the PC's UID. }
mek := GB^.meks;
while mek <> Nil do begin
if ( NAttValue( mek^.NA , NAG_Location , NAS_Team ) = NAV_DefPlayerTeam ) and IsMasterGear( mek ) then begin
{ This must be the PC. }
PCUID := NAttValue( mek^.NA , NAG_EpisodeData , NAS_UID );
end;
mek := mek^.Next;
end;
{ Step two- look for the lancemates and set their orders. }
mek := GB^.meks;
while mek <> Nil do begin
if ( NAttValue( mek^.NA , NAG_Location , NAS_Team ) = NAV_LancemateTeam ) and IsMasterGear( mek ) then begin
DefOrder := NAttValue( mek^.NA , NAG_Personal , NAS_LancemateOrders );
if DefOrder = NAV_Passive then begin
SetNAtt( mek^.NA , NAG_EpisodeData , NAS_Orders , NAV_Passive );
end else if DefOrder = NAV_Follow then begin
SetNAtt( mek^.NA , NAG_EpisodeData , NAS_Orders , NAV_Follow );
SetNAtt( mek^.NA , NAG_EpisodeData , NAS_ATarget , PCUID );
end else begin
SetNAtt( mek^.NA , NAG_EpisodeData , NAS_Orders , NAV_SeekAndDestroy );
end;
end;
mek := mek^.Next;
end;
end;
Function NumLancemateSlots( Adv,PC: GearPtr ): Integer;
{ Return the number of freely-selected lancemates this PC can have. }
var
N: Integer;
begin
{ You get one lancemate for free. }
N := 1;
{ You can earn extra lancemates via merit badges. }
if HasMeritBadge( Adv , NAS_MB_Lancemate2 ) then begin
Inc( N );
if HasMeritBadge( Adv, NAS_MB_Lancemate3 ) then Inc( N );
end;
{ Or, you can take a talent for one extra. }
if HasTalent( PC , NAS_Entourage ) then begin
Inc( N );
end;
NumLancemateSlots := N;
end;
Function CanJoinLance( GB: GameBoardPtr; PC,NPC: GearPtr ): Boolean;
{ Return TRUE if NPC can join the lance right now, or FALSE otherwise. }
var
ERen: Integer; { Lancemate Points needed, Effective Renown }
CanJoin: Boolean;
begin
ERen := NAttValue( PC^.NA , NAG_CharDescription , NAS_Renowned );
if ERen < 15 then ERen := 15;
ERen := ERen + CStat( PC , STAT_Charm );
CanJoin := True;
if ( NPC = Nil ) or ( NPC^.G <> GG_Character ) then begin
CanJoin := False;
end else if NAttValue( NPC^.NA , NAG_CharDescription , NAS_Renowned ) > ERen then begin
CanJoin := False;
end else if ( GB <> Nil ) and ( ReactionScore( GB^.Scene , PC , NPC ) < 10 ) then begin
CanJoin := False;
end else if ( GB <> Nil ) and not ( OnTheMap( GB , FindRoot( NPC ) ) and IsFoundAlongTrack( GB^.Meks , FindRoot( NPC ) ) ) then begin
{ Can only join if in the same scene as the PC. }
CanJoin := False;
end else if PersonaUsedByQuest( FindRoot( GB^.Scene ) , NPC ) then begin
CanJoin := False;
end;
CanJoinLance := CanJoin;
end;
Function SceneName( GB: GameBoardPtr; ID: Integer; Exact: Boolean ): String;
{ Find the name of the scene with the given ID. If no such }
{ scene can be found, return a value that should let the player }
{ know an error has been commited. }
{ If EXACT=TRUE, use the EXACT_NAME attribute instead of the }
{ regular name. The reason for this is that sometimes there's }
{ some ambiguity with the common name of a scene: if I say "Cayley }
{ Rock", do I mean the city in general or the main station }
{ specifically? }
var
msg: String;
Part: GearPtr;
begin
if ( GB = Nil ) or ( GB^.Scene = Nil ) then begin
SceneName := 'XXX';
end else begin
{ Look for the scene along the subcomponents of the }
{ adventure. This is to make sure we don't accidentally }
{ pick a dynamic scene with the right ID. }
{ Also, if we have a metascene instead of a regular scene, then }
{ we want the name of the entrance instead of the name of the }
{ scene itself. }
if ID > 0 then begin
Part := FindActualScene( GB , ID );
end else begin
Part := FindSceneEntrance( FindRoot( GB^.Scene ) , GB , ID );
end;
if Exact then begin
msg := SAttValue( Part^.SA , 'EXACT_NAME' );
if msg = '' then msg := GearName( Part );
SceneName := msg;
end else begin
SceneName := GearName( Part );
end;
end;
end;
Function FindRandomMekID( GB: GameBoardPtr; Team: Integer ): LongInt;
{ Locate a random mek belonging to TEAM. }
var
NumMeks,N,T,MID: Integer;
Mek: GearPtr;
begin
{ Start out by finding out how many meks belong to this team }
{ anyways. }
NumMeks := NumOperationalMasters( GB , Team );
MID := 0;
{ If there are actually members on this team, select one randomly. }
if NumMeks > 0 then begin
{ Decide what mek to take, and initialize the }
{ search variables. }
N := Random( NumMeks ) + 1;
T := 0;
Mek := GB^.Meks;
while Mek <> Nil do begin
if ( NAttValue( Mek^.NA , NAG_Location , NAS_Team ) = Team ) and GearOperational( Mek ) then begin
Inc( T );
if T = N then MID := NAttValue( Mek^.NA , NAG_EpisodeData , NAS_UID );
end;
Mek := Mek^.Next;
end;
end;
FindRandomMekID := MID;
end;
Function FindRandomPilotID( GB: GameBoardPtr; Team: Integer ): LongInt;
{ Locate a random pilot belonging to TEAM. }
var
NumMeks,N,T,MID: Integer;
Mek,P: GearPtr;
begin
{ Start out by finding out how many meks belong to this team }
{ anyways. }
NumMeks := NumOperationalMasters( GB , Team );
MID := 0;
{ If there are actually members on this team, select one randomly. }
if NumMeks > 0 then begin
{ Decide what mek to take, and initialize the }
{ search variables. }
N := Random( NumMeks ) + 1;
T := 0;
Mek := GB^.Meks;
while Mek <> Nil do begin
if ( NAttValue( Mek^.NA , NAG_Location , NAS_Team ) = Team ) and GearOperational( Mek ) then begin
Inc( T );
if T = N then begin
P := LocatePilot( Mek );
if P <> Nil then MID := NAttValue( P^.NA , NAG_EpisodeData , NAS_UID );
end;
end;
Mek := Mek^.Next;
end;
end;
FindRandomPilotID := MID;
end;
Function FindRootUID( GB: GameBoardPtr; ID: LongInt ): LongInt;
{ Find the ID of the root of the specified gear. }
var
Part: GearPtr;
begin
{ First, find the part being pointed to. }
Part := LocateMekByUID( GB , ID );
{ Locate its root. }
if Part <> Nil then begin
Part := FindRoot( Part );
{ Return the root's UID. }
FindRootUID := NAttValue( Part^.NA , NAG_EpisodeData , NAS_UID );
{ If there was an error locating the part, return 0. }
end else FindRootUID := 0;
end;
Function NumPCMeks( GB: GameBoardPtr ): Integer;
{ Return the number of mecha belonging to team 1. }
{ It doesn't matter if they're on the board or not, nor whether or }
{ not they are destroyed. }
var
M: GearPtr;
N: Integer;
begin
N := 0;
if GB <> Nil then begin
M := GB^.Meks;
while M <> Nil do begin
{ If this is a mecha, and it belongs to team 1, }
{ increment the counter. }
if ( M^.G = GG_Mecha ) and ( NAttValue( M^.NA , NAG_Location , NAS_Team ) = NAV_DefPlayerTeam ) then Inc( N );
M := M^.Next;
end;
end;
NumPCMeks := N;
end;
Function FindPCScale( GB: GameBoardPtr ): Integer;
{ Return the scale of the PC. Generally this will be 0 if the }
{ PC is on foot, 1 or 2 if the PC is in a mecha, unless the PC }
{ is a storm giant or a zentradi in which case anything goes. }
var
PC: GearPtr;
begin
PC := GG_LocatePC( GB );
if PC <> Nil then begin
FindPCScale := FindRoot( PC )^.Scale;
end else begin
FindPCScale := 0;
end;
end;
Function Calculate_Reward_Value( GB: GameBoardPtr; Renown,Percent: LongInt ): LongInt;
{ Return an appropriate reward value, based on the listed }
{ threat level and percent scale. }
const
Min_Reward_Value = 3000;
var
RV: LongInt;
begin
{ Calculate the base reward value. }
RV := Calculate_Threat_Points( Renown + 10 , 100 ) div 64 * Percent div 100;
if RV < Min_Reward_Value then RV := Min_Reward_Value;
{ Modify this for the PC's talents. }
if GB <> Nil then begin
if TeamHasTalent( GB , NAV_DefPlayerTeam , NAS_BusinessSense ) then RV := ( RV * 5 ) div 4;
end;
Calculate_Reward_Value := RV;
end;
Function Calculate_Asking_Price( GB: GameBoardPtr; Renown,Percent: LongInt ): LongInt;
{ Return an appropriate asking price, based on the listed }
{ threat level, percent scale, and reaction score with I_NPC. }
const
Min_Asking_Price = 3000;
var
RV,React: LongInt;
begin
{ Calculate the base reward value. }
RV := Calculate_Threat_Points( Renown , 25 ) * Percent div 100;
if RV < Min_Asking_Price then RV := Min_Asking_Price;
{ Modify this for the reaction score. }
if ( I_NPC <> Nil ) and ( I_PC <> Nil ) and ( GB <> Nil ) then begin
React := ReactionScore( GB^.Scene , I_PC , I_NPC );
if React < 0 then RV := RV * ( 100 - 2 * React ) div 100
else if React > 20 then RV := RV * ( 220 - React ) div 200;
end;
Calculate_Asking_Price := RV;
end;
Function Count_Faction_Buddies( GB: GameBoardPtr; FacID: Integer ): Integer;
{ Return the number of positive relationships the PC has with this }
{ particular faction. }
function CountBuddies( LList: GearPtr ): LongInt;
{ Count the number of buddies along this path. }
var
N: LongInt;
begin
N := 0;
while LList <> Nil do begin
if ( LList^.G = GG_Character ) and ( NAttValue( LList^.NA , NAG_Relationship , 0 ) > 0 ) and ( GetFactionID( LList ) = FacID ) and NotDestroyed( LList ) then Inc( N );
N := N + CountBuddies( LList^.SubCom );
N := N + CountBuddies( LList^.InvCom );
LList := LList^.Next;
end;
CountBuddies := N;
end;
var
Adv: GearPtr;
begin
if ( GB = Nil ) or ( GB^.Scene = Nil ) then Exit( 0 );
Adv := FindRoot( GB^.Scene );
Count_Faction_Buddies := CountBuddies( GB^.Meks ) + CountBuddies( Adv^.SubCom ) + CountBuddies( Adv^.InvCom );
end;
Function FindLocalMacro( const cmd: String; GB: GameBoardPtr; Source: GearPtr ): String;
{ Locate the local macro described by "cmd". }
var
it: String;
Plot: GearPtr;
begin
it := SAttValue( Source^.SA , cmd );
if it = '' then begin
Plot := PlotMaster( GB , Source );
if Plot <> Nil then it := SAttValue( Plot^.SA , cmd );
if it = '' then begin
Plot := StoryMaster( GB , Source );
if Plot <> Nil then it := SAttValue( Plot^.SA , cmd );
end;
end;
if it = '' then DialogMsg( 'ERROR: Local macro ' + cmd + ' not found.' );
FindLocalMacro := it;
end;
Procedure InitiateMacro( GB: GameBoardPtr; Source: GearPtr; var Event: String; ProtoMacro: String );
{ Initialize the provided macro, and stick it to the head of }
{ event. To initialize just go through it word by word, replacing }
{ all question marks with words taken from EVENT. }
function NeededParameters( cmd: String ): Integer;
{ Return the number of parameters needed by this function. }
const