-
Notifications
You must be signed in to change notification settings - Fork 16
/
gh2arena.pp
2319 lines (2038 loc) · 74.5 KB
/
gh2arena.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 gh2arena;
{ Oct 23, 2006: }
{ This is it. I've been programming GH2 for a while now, and even though }
{ it's getting more and more playable all the time it'll still be a long }
{ time before it's really playable. So I started to think back to the humble }
{ beginnings of GH1. I decided that development of GH2 could be improved if }
{ I added arena mode; a simple, combat-focused use of the engine that would }
{ provide a fun game while the RPG campaign gets bulked up. I also got a few }
{ comments on the forum indicating that I should put more work into tactics }
{ mode. So here it is, the new humble beginning of GearHead arena, Mk2. }
{
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}
vidgfx;
{$ELSE}
sdlgfx;
{$ENDIF}
const
{ ArenaMissionInfo moved to playwright.pp }
NAG_MissionCoupon = 24; { Certain missions can only be taken a set number }
{ of times. }
NumMissionCouponTypes = 2;
NAS_SkillTrain_Coupon = 1;
NAS_MechaFac_Coupon = 2;
NAG_AHQSkillTrainer = 25; { Tells what skill trainers the PC has acquired. }
NAG_AHQMechaSource = 26; { Tells what mecha factions the PC has acquired. }
Procedure StartArenaCampaign;
Procedure RestoreArenaCampaign( RDP: RedrawProcedureType );
implementation
uses arenaplay,arenascript,interact,gearutil,narration,texutil,ghprop,rpgdice,ability,
ghchars,ghweapon,movement,ui4gh,gearparser,playwright,randmaps,wmonster,
pcaction,menugear,navigate,services,skilluse,training,backpack,chargen,
description,
{$IFDEF ASCII}
vidinfo,vidmap,vidmenus;
{$ELSE}
sdlmap,sdlmenus,sdlinfo;
{$ENDIF}
Const
GS_CharacterSet = 1;
GS_CoreMissionSet = 2;
NumArenaNPCs = 6;
ANPC_FactionHead = 1;
ANPC_Commander = 2;
ANPC_Mechanic = 3;
ANPC_Medic = 4;
ANPC_Supply = 5;
ANPC_Intel = 6;
{ Play Arena Mission selection types. }
PAM_Regular = 0;
PAM_Debug_Missions = 1;
PAM_Debug_Core = 2;
SaleFactor = 25;
var
ADR_Source: GearPtr; { Source gear for various redrawers. }
ADR_SourceMenu: RPGMenuPtr;
ADR_HQCamp: CampaignPtr;
ADR_NumPilotsSelected,ADR_PilotsAllowed: Integer;
ADR_PilotMenu,ADR_MechaMenu: RPGMenuPtr;
ANPC_MasterPersona: GearPtr;
Arena_Mission_Master_List,Core_Mission_Master_List: GearPtr;
{ *** REDRAW PROCEDURES *** }
Procedure BasicArenaRedraw;
{ Just draw the basic setup for the arena mode menus. }
begin
SetupArenaDisplay;
if ADR_PilotMenu <> Nil then DisplayMenu( ADR_PilotMenu , Nil );
if ADR_MechaMenu <> Nil then DisplayMenu( ADR_MechaMenu , Nil );
if ADR_HQCamp <> Nil then ArenaTeamInfo( ADR_HQCamp^.Source , ZONE_PCStatus );
end;
Procedure HQMonologue( Adv: GearPtr; ArenaNPC: LongInt; Msg: String );
{ NPC is about to deliver a line. }
var
NPC: GearPtr;
A: Char;
begin
NPC := SeekGearByCID( Adv^.InvCom , ArenaNPC );
repeat
BasicArenaRedraw;
DoMonologueDisplay( Nil , NPC , Msg );
DoFlip;
A := RPGKey;
until IsMoreKey( A );
DialogMsg( '[' + GearName( NPC ) + ']: ' + Msg );
end;
Procedure SelectAMissionRedraw;
{ Do the basic display, then draw the select forces dialog on top of that. }
begin
BasicArenaRedraw;
SetupArenaMissionMenu;
end;
Procedure SelectAMForcesRedraw;
{ Do the basic display, then draw the select forces dialog on top of that. }
begin
BasicArenaRedraw;
SetupMemoDisplay;
CMessage( BStr( ADR_NumPilotsSelected ) + '/' + Bstr( ADR_PilotsAllowed ) + ' ' + MsgString( 'ARENA_SAMFRD_PilotsSelected' ) , ZONE_MemoMenu , InfoGreen );
end;
Procedure ViewMechaRedraw;
{ The PC is viewing the mecha list. }
var
N: Integer;
Part: GearPtr;
begin
SetupArenaDisplay;
if ADR_PilotMenu <> Nil then DisplayMenu( ADR_PilotMenu , Nil );
if ADR_HQCamp <> Nil then ArenaTeamInfo( ADR_HQCamp^.Source , ZONE_PCStatus );
if ( ADR_SourceMenu <> Nil ) and ( ADR_Source <> Nil ) then begin
N := CurrentMenuItemValue( ADR_SourceMenu );
if N > 0 then begin
Part := RetrieveGearSib( ADR_Source , N );
if Part <> Nil then begin
BrowserInterfaceInfo( Nil , Part , ZONE_ArenaInfo );
end;
end;
end;
end;
Procedure ViewPilotRedraw;
{ The PC is viewing the mecha list. }
var
N: Integer;
Part: GearPtr;
begin
SetupArenaDisplay;
if ADR_MechaMenu <> Nil then DisplayMenu( ADR_MechaMenu , Nil );
if ADR_HQCamp <> Nil then ArenaTeamInfo( ADR_HQCamp^.Source , ZONE_PCStatus );
if ( ADR_SourceMenu <> Nil ) and ( ADR_Source <> Nil ) then begin
N := CurrentMenuItemValue( ADR_SourceMenu );
if N > 0 then begin
Part := RetrieveGearSib( ADR_Source , N );
if Part <> Nil then begin
BrowserInterfaceInfo( Nil , Part , ZONE_ArenaInfo );
end;
end;
end;
end;
Procedure ViewSourcePilotRedraw;
{ The PC is viewing a specific gear. }
begin
SetupArenaDisplay;
if ADR_MechaMenu <> Nil then DisplayMenu( ADR_MechaMenu , Nil );
if ADR_HQCamp <> Nil then ArenaTeamInfo( ADR_HQCamp^.Source , ZONE_PCStatus );
if ADR_Source <> Nil then begin
BrowserInterfaceInfo( Nil , ADR_Source , ZONE_ArenaInfo );
end;
end;
Procedure ViewSourceMechaRedraw;
{ The PC is viewing a specific gear. }
begin
SetupArenaDisplay;
if ADR_PilotMenu <> Nil then DisplayMenu( ADR_PilotMenu , Nil );
if ADR_HQCamp <> Nil then ArenaTeamInfo( ADR_HQCamp^.Source , ZONE_PCStatus );
if ADR_Source <> Nil then begin
BrowserInterfaceInfo( Nil , ADR_Source , ZONE_ArenaInfo );
end;
end;
Procedure AddPilotRedraw;
{ Draw the basic setup for the arena mode menus, then display character info }
{ for ADR_SOURCE. }
begin
BasicArenaRedraw;
if ADR_Source <> Nil then CharacterDisplay( ADR_Source , Nil, ZONE_CharViewChar );
end;
Procedure PurchaseHardwareRedraw;
{ The PC is buying hardware. Open the shopping display! }
var
N: Integer;
Part: GearPtr;
begin
BasicArenaRedraw;
SetupFHQDisplay;
if ( ADR_SourceMenu <> Nil ) and ( ADR_Source <> Nil ) then begin
N := CurrentMenuItemValue( ADR_SourceMenu );
if N > 0 then begin
Part := RetrieveGearSib( ADR_Source , N );
if Part <> Nil then begin
BrowserInterfaceInfo( Nil , Part , ZONE_ItemsInfo );
end;
end;
end;
end;
Procedure ViewListRedraw;
{ The PC is viewing either the pilots list or the mecha list. }
var
N: Integer;
Part: GearPtr;
begin
BasicArenaRedraw;
if ( ADR_SourceMenu <> Nil ) and ( ADR_Source <> Nil ) then begin
N := CurrentMenuItemValue( ADR_SourceMenu );
if N > 0 then begin
Part := RetrieveGearSib( ADR_Source , N );
if Part <> Nil then begin
BrowserInterfaceInfo( Nil , Part , ZONE_ArenaInfo );
end;
end;
end;
end;
Procedure ViewSourceRedraw;
{ The PC is viewing a specific gear. }
begin
BasicArenaRedraw;
if ADR_Source <> Nil then begin
BrowserInterfaceInfo( Nil , ADR_Source , ZONE_ArenaInfo );
end;
end;
Procedure DoPurchaseRedraw;
{ The PC has browsed, and is now making a real purchase. }
begin
BasicArenaRedraw;
SetupFHQDisplay;
if ADR_Source <> Nil then begin
BrowserInterfaceInfo( Nil , ADR_Source , ZONE_ItemsInfo );
end;
end;
{ *** UTILITY FUNCTIONS *** }
Function ArenaNPCMessage( Adv: GearPtr; ArenaNPC: LongInt; const Msg_Key: String ): String;
{ Try to find an appropriate message for the requested NPC to say. }
var
NPC: GearPtr;
begin
NPC := SeekGearByCID( Adv^.InvCom , ArenaNPC );
ArenaNPCMessage := NPCScriptMessage( Msg_Key , Nil , NPC , ANPC_MasterPersona );
end;
Function FindMechasPilot( U , Mek: GearPtr ): GearPtr;
{ Search unit U to locate whatever pilot is assigned to mecha Mek. }
{ If no such pilot is found, clear Mek's PILOT attribute and }
{ return Nil. }
var
pc,mpc: GearPtr;
name: String;
begin
{ Begin by finding the pilot's name. }
name := SAttValue( Mek^.SA , 'pilot' );
{ Search through the unit's Sub looking for a character of }
{ this name. }
pc := U^.SubCom;
mpc := Nil;
while ( pc <> Nil ) and ( mpc = Nil ) do begin
if pc^.G = GG_Character then begin
if GearName( PC ) = name then mpc := pc;
end;
pc := pc^.Next;
end;
{ If the required pilot could not be found, }
{ delete this mecha's PILOT attribute. }
if mpc = Nil then begin
SetSAtt( Mek^.SA , 'pilot <>' );
end;
FindMechasPilot := mpc;
end;
Function UnitSkill( HQCamp: CampaignPtr; Skill,SkStat: Integer ): Integer;
{ Return the "unit skill" value for the requested skill. Usually this }
{ will be the highest skill rank in the unit. }
begin
{ Check through every mek on the board. }
UnitSkill := SkillValue( HQCamp^.Source , Skill , SkStat );
end;
Function ModifiedCost( HQCamp: CampaignPtr; BaseCost: LongInt; Skill: Integer ): LongInt;
{ The unit has to spend money on something, but this amount of money can be }
{ reduced based on a certain skill. When buying things the skill is shopping. }
{ When fixing things the skill is the appropriate repair skill. }
begin
{ Determine the unit skill value. }
if ( Skill >= 1 ) and ( Skill <= NumSkill ) then begin
Skill := UnitSkill( HQCamp , Skill , STAT_Charm );
end else Skill := 0;
{ Each point of skill gives a 2% discount on the cost. }
Skill := Skill * 2;
{ You can't get more than a 75% discount, no matter how you try. }
if Skill > 75 then Skill := 75;
{ Return the modified cost. }
ModifiedCost := BaseCost * ( 100 - Skill ) div 100;
end;
Function AHQRepairCost( HQCamp: CampaignPtr; Part: GearPtr ): LongInt;
{ Return the cash cost to repair this gear completely. }
var
Material: Integer;
Total: LongInt;
begin
Total := 0;
for Material := 0 to NumMaterial do begin
Total := Total + ModifiedCost( HQCamp , RepairMasterCost( Part , Material ) , Repair_Skill_Needed[ Material ] );
end;
AHQRepairCost := Total;
end;
Procedure DoFullRepair( HQCamp: CampaignPtr; Part: GearPtr );
{ Do all the repair that this gear needs. }
var
Material: Integer;
Cost,TRD: LongInt;
begin
for Material := 0 to NumMaterial do begin
Cost := RepairMasterCost( Part , Material );
if Cost > 0 then begin
TRD := TotalRepairableDamage( Part , Material );
ApplyRepairPoints( Part , Material , TRD , True );
AddNAtt( HQCamp^.Source^.NA , NAG_Experience , NAS_Credits , -Cost );
end;
end;
end;
Function HQCash( HQCamp: CampaignPtr ): LongInt;
{ This is pretty much just a macro for returning the amount of }
{ cash this arena unit has. }
begin
HQCash := NAttValue( HQCamp^.Source^.NA , NAG_Experience , NAS_Credits );
end;
Function HQRenown( HQCamp: CampaignPtr ): LongInt;
{ This is pretty much just a macro for returning the amount of }
{ renown this arena unit has. }
{ This procedure will also check to make sure the renown doesn't }
{ drop below zero. }
var
it: LongInt;
begin
it := NAttValue( HQCamp^.Source^.NA , NAG_CharDescription , NAS_Renowned );
if it < 0 then begin
it := 0;
SetNAtt( HQCamp^.Source^.NA , NAG_CharDescription , NAS_Renowned , 0 );
end;
HQRenown := it;
end;
Function HQFac( HQCamp: CampaignPtr ): Integer;
{ Return the faction of this arena unit. }
begin
HQFac := NAttValue( HQCamp^.Source^.NA , NAG_Personal , NAS_FactionID );
end;
Function HQMaxMissions( HQCamp: CampaignPtr ): Integer;
{ Return the maximum number of missions this unit can have available. }
{ This number is based on the unit's conversation skill. }
var
C: Integer;
begin
C := ( UnitSkill( HQCamp , NAS_Conversation , STAT_Charm ) + 4 ) div 3;
if C < 3 then C := 3;
HQMaxMissions := C;
end;
Procedure ArenaReloadMaster( HQCamp: CampaignPtr; PC: GearPtr );
{ Reload the mecha, and make the unit PAY!!! Money, that is. }
{ Bullets aren't free. }
begin
AddNAtt( HQCamp^.Source^.NA , NAG_Experience , NAS_Credits , -ReloadMasterCost( PC , Reload_All_Weapons ) );
DoReloadMaster( PC , Reload_All_Weapons );
end;
Function ExpectedMissionReward( HQCamp: CampaignPtr; Scene: GearPtr ): LongInt;
{ Return the amount of cash the PC can expect if he completes this }
{ mission. }
var
TL,PayRate: LongInt;
begin
TL := HQRenown( HQCamp );
PayRate := NAttValue( Scene^.NA , NAG_ArenaMissionInfo , NAS_PayRate );
if PayRate = 0 then PayRate := 400;
ExpectedMissionReward := Calculate_Reward_Value( Nil , TL , PaYRate );
end;
Procedure PrepMission( HQCamp: CampaignPtr; Scene: GearPtr );
{ Prepare the mission right before combat. Mostly, this just }
{ involves initializing the cash payout counter and NPCs. }
var
F,TL: LongInt;
M: GearPtr;
Desc: String;
begin
TL := HQRenown( HQCamp );
SetNAtt( Scene^.NA , NAG_ArenaMissionInfo , NAS_Pay , ExpectedMissionReward( HQCamp , Scene ) );
SetSAtt( Scene^.SA , 'name <>' );
Desc := SAttValue( Scene^.SA , 'TYPE' ) + ' ' + DifficulcyContext( TL );
SetSAtt( Scene^.SA , 'TYPE <' + Desc + '>' );
{ Prep the NPCs to the correct level. }
M := Scene^.InvCom;
while M <> Nil do begin
if M^.G = GG_Character then begin
{ Set the faction. }
F := NAttValue( M^.NA , NAG_Personal , NAS_FactionID );
if F < 0 then SetNAtt( M^.NA , NAG_Personal , NAS_FactionID , ElementID( Scene , Abs( F ) ) );
SetSkillsAtLevel( M , TL );
end;
M := M^.Next;
end;
end;
Function NumMissions( HQCamp: CampaignPtr ): Integer;
{ Return the number of missions currently waiting for the PC. }
var
M: GearPtr;
N: Integer;
begin
N := 0;
M := HQCamp^.Source^.InvCom;
while M <> Nil do begin
if M^.G = GG_Scene then Inc( N );
M := M^.Next;
end;
NumMissions := N;
end;
Function GetMission( HQCamp: CampaignPtr; N: Integer ): GearPtr;
{ Retrieve mission N. }
var
it,M: GearPtr;
begin
M := HQCamp^.Source^.InvCom;
it := Nil;
while ( M <> Nil ) and ( it = Nil ) do begin
if M^.G = GG_Scene then begin
Dec( N );
if N = 0 then it := M;
end;
M := M^.Next;
end;
GetMission := it;
end;
Function HQContext( HQCamp: CampaignPtr ): String;
{ Return a context for this arena unit. }
{ The context is used to determine what missions can be }
{ loaded. }
var
Fac: GearPtr;
HQC: String;
Renown,T: Integer;
begin
{ Start with the faction designation. }
Fac := SeekCurrentLevelGear( HQCamp^.Source^.InvCom , GG_Faction , HQFac( HQCamp ) );
if Fac <> Nil then begin
HQC := SAttValue( Fac^.SA , 'TYPE' ) + ' ' + SAttValue( Fac^.SA , 'DESIG' );
end else begin
HQC := 'FDFOR MILITARY';
end;
{ Add the difficulcy level. }
Renown := HQRenown( HQCamp );
HQC := HQC + ' ' + DifficulcyContext( Renown );
{ Add tags for the skills and mecha factions that the PC hasn't earned yet. }
for t := 1 to NumSkill do begin
if NAttValue( HQCamp^.Source^.NA , NAG_AHQSkillTrainer , T ) = 0 then begin
HQC := HQC + ' [s' + BStr( T ) + ']';
end;
end;
Fac := Factions_List;
while Fac <> Nil do begin
if NAttValue( HQCamp^.Source^.NA , NAG_AHQMechaSource , Fac^.S ) = 0 then begin
HQC := HQC + ' [f' + BStr( Fac^.S ) + ']';
end;
Fac := Fac^.Next;
end;
HQContext := HQC;
end;
Function HQCoupons( HQCamp: CampaignPtr ): STring;
{ Return the coupons this campaign has. }
const
Coupons_Per_Level: Array [1..NumMissionCouponTypes,1..5] of Byte = (
( 2, 4, 6, 8, 10 ), { Skill Trainers }
( 1, 2, 3, 4, 5 ) { Mecha Factions }
);
Coupon_Tag: Array [1..NumMissionCouponTypes] of String = (
'SKILL_TRAIN_MISSION',
'MECHA_SOURCE_MISSION'
);
Function CanAddCoupon( N: Integer ): Boolean;
{ You can add this coupon if no currently loaded mission is using it. }
var
M: GearPtr;
CAC:Boolean;
begin
{ Assume true until shown false. }
CAC := True;
M := HQCamp^.Source^.InvCom;
while M <> Nil do begin
if ( M^.G = GG_Scene ) and AStringHasBString( SAttValue( M^.SA , 'REQUIRES' ) , Coupon_Tag[ N ] ) then CAC := False;
M := M^.Next;
end;
CanAddCoupon := CAC;
end;
var
HQC: String;
Renown,T: Integer;
begin
HQC := '';
{ Add any mission coupons that haven't been spent yet. }
{ Determine the faction level. }
Renown := HQRenown( HQCamp );
if Renown < 1 then Renown := 1;
Renown := ( Renown + 19 ) div 20;
{ Check for coupons. }
for t := 1 to NumMissionCouponTypes do begin
if ( Coupons_Per_Level[ T , Renown ] - NAttValue( HQCamp^.Source^.NA , NAG_MissionCoupon , T ) ) > 0 then begin
{ We have a coupon left. Add a note. }
if CanAddCoupon( T ) then begin
HQC := HQC + ' ' + Coupon_Tag[ T ];
end;
end;
end;
HQCoupons := HQC;
end;
Function AddCoreMission( HQCamp: CampaignPtr ): Boolean;
{ Add a core mission. If there's a mission stored in the core mission holder, }
{ and it hasn't been completed yet (check CoreMissionID against the CoreMissionStep) }
{ then use that one. Otherwise generate a new mission. }
{ Return TRUE if the core mission was generated successfully, or FALSE if the }
{ generation fails. This procedure should print an error message if the generation }
{ fails, since that's a pretty serious thing. }
Function CoreCampaignContext( CMStep: Integer ): String;
{ Return the context of the core campaign. This includes the }
{ story state, the difficulcy level, the context of the player's faction (P:), }
{ and the context of the enemy faction (F:). }
var
Context: String;
Fac: GearPtr;
begin
{ Determine the campaign context. This is stored right in the adventure gear itself. }
Context := SAttValue( HQCamp^.Source^.SA , 'CORE_CONTEXT' );
if Context = '' then begin
Context := '+P--';
SetSAtt( HQCamp^.Source^.SA , 'CORE_CONTEXT <+P-->' );
end;
{ Locate the player faction and the element faction. Provide context for both. }
Fac := SeekCurrentLevelGear( HQCamp^.Source^.InvCom , GG_Faction , HQFac( HQCamp ) );
AddGearXRContext( Nil , HQCamp^.Source , Fac , Context , 'P' );
Fac := SeekCurrentLevelGear( HQCamp^.Source^.InvCom , GG_Faction , NAttValue( HQCamp^.Source^.NA , NAG_AHQData , NAS_CoreMissionEnemy ) );
AddGearXRContext( Nil , HQCamp^.Source , Fac , Context , 'F' );
{ Add the difficulcy context. }
Context := COntext + ' ' + DifficulcyContext( CMStep * 10 + 5 );
CoreCampaignContext := Context;
end;
Function NewCoreMissionPrototype( CMSet: GearPtr ): GearPtr;
{ Select a new core mission for the next step in the progress. }
{ Set its core mission ID, and return a pointer to it. }
{ If no appropriate mission can be found, print an error message and return Nil. }
var
CMStep: Integer;
Context: String;
CM,CMProto,CMTest: GearPtr;
ShoppingList: NAttPtr;
begin
{ Determine the threat level of this mission. }
CMStep := NAttValue( HQCamp^.Source^.NA , NAG_AHQData , NAS_CoreMissionStep ) + 1;
{ Determine the campaign context. }
Context := CoreCampaignContext( CMStep );
{ Create the shopping list of potential candidates. }
ShoppingList := CreateComponentList( Core_Mission_Master_List , Context );
{ As long as we still have candidates, look for one to select. }
{ Attempt to load it into the adventure- if loading succeeds, it's }
{ a good one. Delete the temporary copy and stick the clone in the set. }
CMProto := Nil;
while ( ShoppingList <> Nil ) and ( CMProto = Nil ) do begin
CM := SelectComponentFromList( Core_Mission_Master_List , ShoppingList );
CMTest := CloneGear( CM );
if InsertArenaMission( HQCamp^.Source , CMTest , HQRenown( HQCamp ) ) then begin
CMProto := CloneGear( CM );
InsertInvCom( CMSet , CMProto );
RemoveGear( HQCamp^.Source^.InvCom , CMTest );
end;
end;
{ If no mission was found, print a debugging message along with the }
{ context so that future generations can learn from my mistakes. Or }
{ so I can add a new mission to fill in the gap. }
if CMProto = Nil then begin
Dialogmsg( 'ERROR: Core mission not found for context:' + Context );
end;
{ Dispose of the shopping list. }
DisposeNAtt( ShoppingList );
{ Return a pointer to the new mission. }
NewCoreMissionPrototype := CMProto;
end;
var
CMSet,CMProto,CM: GearPtr;
AddOK: Boolean;
begin
AddOK := False;
{ Start by locating the core mission set, if it exists. }
CMSet := SeekCurrentLevelGear( HQCamp^.Source^.InvCom , GG_Set , GS_CoreMissionSet );
if CMSet = Nil then begin
{ We don't have a Core Mission Set. Horrors! Better add one. }
CMSet := NewGear( Nil );
CMSet^.G := GG_Set;
CMSet^.S := GS_CoreMissionSet;
InsertInvCom( HQCamp^.Source , CMSet );
end;
{ This set should contain a single gear- the core mission. If this mission }
{ doesn't exist, or if it has already been completed, better generate another }
{ one. }
CMProto := CMSet^.InvCom;
if CMProto = Nil then begin
CMProto := NewCoreMissionPrototype( CMSet );
end else if NAttValue( CMProto^.NA , NAG_ArenaMissionInfo , NAS_IsCoreMission ) <= NAttValue( HQCamp^.Source^.NA , NAG_AHQData , NAS_CoreMissionStep ) then begin
RemoveGear( CMSet^.InvCom , CMProto );
CMProto := NewCoreMissionPrototype( CMSet );
end;
{ If the prototype was found, insert a clone. }
if CMProto <> Nil then begin
CM := CloneGear( CMProto );
AddOK := InsertArenaMission( HQCamp^.Source , CM , HQRenown( HQCamp ) );
if not AddOK then begin
DialogMsg( 'ERROR: Insertion of core mission ' + GearName( CMProto ) + ' failed.' );
end;
end;
AddCoreMission := AddOK;
end;
Procedure AddMissions( HQCamp: CampaignPtr; N: Integer );
{ Refresh the missions. Yay! Basically make sure there are some missions to }
{ choose between. }
Procedure AddAMission( var ShoppingList: NAttPtr );
{ Add a mission from the provided list. }
var
MissionOK: Boolean;
M: GearPtr;
begin
MissionOK := False;
while ( ShoppingList <> Nil ) and not MissionOK do begin
M := CloneGear( SelectComponentFromList( Arena_Mission_Master_List , ShoppingList ) );
if InsertArenaMission( HQCamp^.Source , M , HQRenown( HQCamp ) ) then begin
MissionOK := True;
end;
end;
end;
Function NoCoreMissionFound: Boolean;
{ Return TRUE if none of the pending missions belong to the core campaign, }
{ or FALSE if one of them does. }
var
M: GearPtr;
NCMF: Boolean;
begin
{ Assume true unless proven otherwise. }
NCMF := True;
M := HQCamp^.Source^.InvCom;
while M <> Nil do begin
if ( M^.G = GG_Scene ) and ( NAttValue( M^.NA , NAG_ArenaMissionInfo , NAS_IsCoreMission ) <> 0 ) then NCMF := False;
M := M^.Next;
end;
NoCoreMissionFound := NCMF;
end;
Function CanAddCoreMission: Boolean;
{ Return TRUE if a core mission can currently be loaded, or FALSE if }
{ it can't be. It can be loaded if: }
{ A) the player hasn't already completed the core campaign }
{ B) the unit's renown is high enough to load the next step }
{ C) there isn't currently a core mission in the pending list }
var
CMS: Integer;
begin
{ Determine the core mission step. }
CMS := NAttValue( HQCamp^.Source^.NA , NAG_AHQData , NAS_CoreMissionStep );
CanAddCoreMission := ( CMS < 8 ) and ( ( ( CMS + 1 ) * 10 ) <= HQRenown( HQCamp ) ) and NoCoreMissionFound;
end;
var
Context: String;
MissionList,RewardList: NAttPtr;
begin
{ Start by determining the arena unit's context. This is determied by the }
{ current faction being fought for plus the arena unit's renown. }
Context := HQContext( HQCamp );
{ Next create the list of potential content to add. }
{ There are two content lists- regular content, and reward content. One reward mission }
{ should be loaded per five regular missions. A core campaign mission could also be selected, }
{ but this is handled differently. }
MissionList := CreateComponentList( Arena_Mission_Master_List , '*MISSION ' + Context );
RewardList := Nil;
while N > 0 do begin
{ Decrement the mission timers, and add special mission types as appropriate. }
AddNAtt( HQCamp^.Source^.NA , NAG_AHQData , NAS_RewardMissionTimer , -1 );
if CanAddCoreMission then AddNAtt( HQCamp^.Source^.NA , NAG_AHQData , NAS_CoreMissionTimer , -1 );
if ( NAttValue( HQCamp^.Source^.NA , NAG_AHQData , NAS_CoreMissionTimer ) < 0 ) and CanAddCoreMission then begin
if AddCoreMission( HQCamp ) then begin
{ Set the mission recharge timer to something large. }
SetNAtt( HQCamp^.Source^.NA , NAG_AHQData , NAS_CoreMissionTimer , 20 + Random( 10 ) + N );
end else begin
{ Adding the core mission failed for some reason, probably }
{ a plot deadend. }
SetNAtt( HQCamp^.Source^.NA , NAG_AHQData , NAS_CoreMissionTimer , 10 + N );
Inc( N );
end;
end else if ( NAttValue( HQCamp^.Source^.NA , NAG_AHQData , NAS_RewardMissionTimer ) < 0 ) then begin
RewardList := CreateComponentList( Arena_Mission_Master_List , '*REWARD ' + Context + ' ' + HQCoupons( HQCamp ) );
if RewardList <> Nil then begin
AddAMission( RewardList );
end else begin
AddAMission( MissionList );
end;
SetNAtt( HQCamp^.Source^.NA , NAG_AHQData , NAS_RewardMissionTimer , 4 );
DisposeNAtt( RewardList );
end else begin
AddAMission( MissionList );
end;
Dec( N );
end;
DisposeNAtt( MissionList );
DisposeNAtt( RewardList );
end;
Procedure UpdateMissions( HQCamp: CampaignPtr );
{ Check to see if there are enough missions. Maybe delete some of them. }
{ Bring the total back to max. }
var
N: Integer;
M: GearPtr;
begin
{ Step one- delete some missions at random. }
N := NumMissions( HQCamp );
Repeat
if N > 1 then begin
M := GetMission( HQCamp , Random( N ) + 1 );
if M <> Nil then RemoveGear( HQCamp^.Source^.InvCom , M );
end;
Dec( N );
until ( N < 1 ) or ( Random( 3 ) <> 1 );
{ Step one point five- remove the core campaign mission if the unit's }
{ renown has fallen beneath the critical threshold. }
M := HQCamp^.Source^.InvCom;
while M <> Nil do begin
if ( M^.G = GG_Scene ) and ( NAttValue( M^.NA , NAG_ArenaMissionInfo , NAS_IsCoreMission ) <> 0 ) then begin
if HQRenown( HQCamp ) < ( ( NAttValue( M^.NA , NAG_ArenaMissionInfo , NAS_IsCoreMission ) + 1 ) * 10 ) then begin
RemoveGear( HQCamp^.Source^.InvCom , M );
Break;
end;
end;
M := M^.Next;
end;
{ Step two- make sure we have enough missions. }
AddMissions( HQCamp , HQMaxMissions( HQCamp ) - NumMissions( HQCamp ) );
end;
Procedure ClearWeaponRecharge( LList: GearPtr );
{ To prevent strange bugs from happening, clear all weapon recharge times }
{ upon leaving combat. }
begin
while LList <> Nil do begin
SetNAtt( LList^.NA , NAG_WeaponModifier , NAS_Recharge , 0 );
ClearWeaponRecharge( LList^.InvCom );
ClearWeaponRecharge( LList^.SubCom );
LList := LList^.Next;
end;
end;
Procedure PostMissionCleanup( HQCamp: CampaignPtr; PCForces: GearPtr );
{ After a battle is over, deal with the survivors. There are survivors? }
{ I must not have made the mission hard enough... }
var
PC: GearPtr;
Cost: LongInt;
begin
{ To start with, recharge/repair everyone in the list. }
{ We'll make three passes: First, "repair" all characters. }
{ Second, repair all mecha. Third, restock all mecha and characters. }
{ First pass- medical attention for characters. }
PC := PCForces;
while PC <> Nil do begin
{ Status effects get repaired for free- otherwise, a low-on-cash }
{ arena unit could enter the next battle with a mecha still on fire from their }
{ last battle, and that would suck. Also remove conditions now, since }
{ everybody needs that done. }
StripNAtt( PC , NAG_StatusEffect );
StripNAtt( PC , NAG_Condition );
ClearWeaponRecharge( PC^.SubCom );
ClearWeaponRecharge( PC^.InvCom );
if PC^.G = GG_Character then begin
Cost := AHQRepairCost( HQCamp , PC );
if ( Cost > 0 ) and ( HQCash( HQCamp ) >= Cost ) then begin
DoFullRepair( HQCamp , PC );
end;
end;
PC := PC^.Next;
end;
{ Second pass- repair all mecha. }
PC := PCForces;
while PC <> Nil do begin
if PC^.G = GG_Mecha then begin
Cost := AHQRepairCost( HQCamp , PC );
if ( Cost > 0 ) and ( HQCash( HQCamp ) >= Cost ) then begin
DoFullRepair( HQCamp , PC );
end;
end;
PC := PC^.Next;
end;
{ Third pass- reload all weapons. }
PC := PCForces;
while PC <> Nil do begin
Cost := ReloadMasterCost( PC , Reload_All_Weapons );
if ( Cost > 0 ) and ( HQCash( HQCamp ) >= Cost ) then begin
ArenaReloadMaster( HQCamp , PC );
end;
PC := PC^.Next;
end;
{ Once that's been taken care of, stick the PCs back in the unit. }
InsertSubCom( HQCamp^.Source , PCForces );
{ Finally update the missions. }
UpdateMissions( HQCamp );
end;
Procedure AddDamageReloadStatus( HQCamp: CampaignPtr; M: GearPtr; var msg: String );
{ If this model needs repairs or reloading, indicate that here. }
var
POK: Integer; { Percent OK }
begin
if AHQRepairCost( HQCamp , M ) > 0 then begin
POK := PercentDamaged( M );
if POK = 100 then POK := 99;
msg := msg + ' (%' + BStr( POK ) + ')';
end;
if ReloadMasterCost( M , Reload_All_Weapons ) > 0 then msg := msg + ' -ammo-';
end;
Function AHQMechaName( HQCamp: CampaignPtr; Mek: GearPtr ): String;
{ Return the name of this mecha along with its pilot. }
{ If the mecha's pilot can't be found, clear the PILOT string attribute. }
var
name,pname: String;
Pilot: GearPtr;
begin
name := FullGearName( Mek );
pname := SAttValue( Mek^.SA , 'pilot' );
if pname <> '' then begin
Pilot := SeekGearByName( HQCamp^.Source^.SubCom , pname );
if Pilot = Nil then begin
{ Oops, no pilot. Must have died or been removed }
{ from the unit. Fix this mecha's data. }
SetSatt( Mek^.SA , 'pilot <>' );
end else begin
{ Pilot has been found. Add to the name. }
name := name + ' [' + pname + ']';
end;
end;
AddDamageReloadStatus( HQCamp , Mek , name );
AHQMechaName := name;
end;
Procedure UpdatePilotMechaMenus( HQCamp: CampaignPtr );
{ Add the pilots and the mecha to their respective menus. }
{ If any mecha/pilot matchups are invalid, clear them. }
{ This is done via the above function, BTW. }
var
N,PMI,MMI: Integer;
M: GearPtr;
name: String;
begin
{ If either of the menus currently exist, dispose of them. }
if ADR_PilotMenu <> Nil then begin
PMI := ADR_PilotMenu^.selectitem;
DisposeRPGMenu( ADR_PilotMenu );
end else begin
PMI := 1;
end;
if ADR_MechaMenu <> Nil then begin
MMI := ADR_MechaMenu^.selectitem;
DisposeRPGMenu( ADR_MechaMenu );
end else begin
MMI := 1;
end;
{ Allocate the menus. }
ADR_PilotMenu := CreateRPGMenu( MenuItem , MenuSelect , ZONE_ArenaPilotMenu );
ADR_MechaMenu := CreateRPGMenu( MenuItem , MenuSelect , ZONE_ArenaMechaMenu );
{ Go through the unit contents, adding to whichever menu is appropriate. }
M := HQCamp^.Source^.SubCom;
N := 1;
while M <> Nil do begin
if M^.G = GG_Character then begin
name := GearName( M );
AddDamageReloadStatus( HQCamp , M , name );
AddRPGMenuItem( ADR_PilotMenu , name , N );
end else if M^.G = GG_Mecha then begin
{ For a mecha, add not just the mecha's name but also the }
{ pilot's name. If no pilot can be found, clean up that mess. }
name := AHQMechaName( HQCamp , M );
AddRPGMenuItem( ADR_MechaMenu , name , N );
end else begin
AddRPGMenuItem( ADR_MechaMenu , '*' + GearName( M ) , N );
end;
Inc( N );
M := M^.Next;
end;
{ Sort the menus. }
RPMSortAlpha( ADR_PilotMenu );
RPMSortAlpha( ADR_MechaMenu );
SetItemByPosition( ADR_PilotMenu , PMI );
SetItemByPosition( ADR_MechaMenu , MMI );
end;
Procedure StripAllMecha( var PC: GearPtr );
{ We've been provided with a linked list. Remove everything }
{ that isn't a mecha. }
var