-
Notifications
You must be signed in to change notification settings - Fork 18
/
backpack.pp
2058 lines (1807 loc) · 62.9 KB
/
backpack.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 backpack;
{ This unit handles both the inventory display and the }
{ FieldHQ interface, which uses many of the same things. }
{
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
{$IFDEF SDLMODE}
uses gears,locale,sdlgfx,ui4gh;
{$ELSE}
uses gears,locale,ui4gh;
{$ENDIF}
const
TRIGGER_GetItem = 'GET';
{$IFDEF SDLMODE}
Procedure SelectColors( M: GearPtr; Redrawer: RedrawProcedureType );
Procedure SelectSprite( M: GearPtr; Redrawer: RedrawProcedureType );
{$ENDIF}
Function FindNextPC( GB: GameBoardPtr; CurrentPC: GearPtr; AllowPets: Boolean ): GearPtr;
Function FindPrevPC( GB: GameBoardPtr; CurrentPC: GearPtr; AllowPets: Boolean ): GearPtr;
Function CanBeExtracted( Item: GearPtr ): Boolean;
Procedure GivePartToPC( GB: GameBoardPtr; Part, PC: GearPtr );
Function SelectRobotParts( GB: GameBoardPtr; PC: GearPtr ): GearPtr;
Procedure DoFieldRepair( GB: GameBoardPtr; PC , Item: GearPtr; Skill: Integer );
Function Handless( Mek: GearPtr ): Boolean;
Function ShakeDown( GB: GameBoardPtr; Part: GearPtr; X,Y: Integer ): LongInt;
Procedure PCGetItem( GB: GameBoardPtr; PC: GearPtr );
Procedure StartContinuousUseItem( GB: GameBoardPtr; TruePC , Item: GearPtr );
Procedure FHQ_SelectMechaForPilot( GB: GameBoardPtr; NPC: GearPtr );
Procedure LancemateBackpack( GB: GameBoardPtr; PC,NPC: GearPtr );
Procedure BackpackMenu( GB: GameBoardPtr; PC: GearPtr; StartWithInv: Boolean );
{$IFDEF SDLMODE}
Procedure MechaPartBrowser( Mek: GearPtr; RDP: RedrawProcedureType );
{$ELSE}
Procedure MechaPartBrowser( Mek: GearPtr );
{$ENDIF}
Procedure FHQ_ThisWargearWasSelected( GB: GameBoardPtr; var LList: GearPtr; PC,M: GearPtr );
implementation
{$IFDEF SDLMODE}
uses ability,action,arenacfe,arenascript,damage,gearutil,ghchars,ghholder,
ghmodule,ghprop,ghswag,interact,menugear,rpgdice,skilluse,texutil,
sdlinfo,sdlmap,sdlmenus,ghweapon,ghintrinsic,colormenu,sdl;
{$ELSE}
uses ability,action,arenacfe,arenascript,damage,gearutil,ghchars,ghholder,
ghmodule,ghprop,ghswag,interact,menugear,rpgdice,skilluse,texutil,
congfx,coninfo,conmap,conmenus,context,ghweapon,ghintrinsic;
{$ENDIF}
var
ForceQuit: Boolean;
EqpRPM,InvRPM: RPGMenuPtr;
{$IFDEF SDLMODE}
InfoGear: GearPtr; { Gear to appear in the INFO menu. }
BP_Source: GearPtr; { Gear whose inventory is being examined. }
BP_Focus: GearPtr; { Gear which is being focused on for FocusOnOneItemRedraw }
BP_SeekSibs: Boolean; { TRUE if the menu lists sibling gears; FALSE if it lists child gears. }
BP_ActiveMenu: RPGMenuPtr; { The active menu. Used to determine the gear to show info about. }
BPRD_Caption: String;
InfoGB: GameBoardPtr;
MPB_Redraw: RedrawProcedureType;
Procedure PlainRedraw;
{ Miscellaneous menu redraw procedure. }
begin
if InfoGB <> Nil then SDLCombatDisplay( InfoGB );
{if InfoGear <> Nil then DisplayGearInfo( InfoGear , InfoGB );}
end;
Procedure EqpRedraw;
{ Show Inventory, select Equipment. }
var
N: Integer;
Part: GearPtr;
begin
SDLCombatDisplay( InfoGB );
DrawBPBorder;
DisplayMenu( InvRPM , Nil );
DrawBackpackHeader( BP_Source );
GameMsg( MsgString( 'BACKPACK_Directions' ) , ZONE_BPInstructions.GetRect() , MenuItem );
if ( BP_ActiveMenu <> Nil ) and ( BP_Source <> Nil ) then begin
N := CurrentMenuItemValue( BP_ActiveMenu );
if N > 0 then begin
if BP_SeekSibs then Part := RetrieveGearSib( BP_Source , N )
else Part := LocateGearByNumber( BP_Source , N );
if Part <> Nil then begin
LongformGearInfo( Part , InfoGB, ZONE_BPInfo );
end;
end;
end;
end;
Procedure InvRedraw;
{ Show Equipment, select Inventory. }
var
N: Integer;
Part: GearPtr;
begin
SDLCombatDisplay( InfoGB );
DrawBPBorder;
DisplayMenu( EqpRPM , Nil );
DrawBackpackHeader( BP_Source );
GameMsg( MsgString( 'BACKPACK_Directions' ) , ZONE_BPInstructions.GetRect() , MenuItem );
if ( BP_ActiveMenu <> Nil ) and ( BP_Source <> Nil ) then begin
N := CurrentMenuItemValue( BP_ActiveMenu );
if N > 0 then begin
if BP_SeekSibs then Part := RetrieveGearSib( BP_Source , N )
else Part := LocateGearByNumber( BP_Source , N );
if Part <> Nil then begin
LongformGearInfo( Part , InfoGB, ZONE_BPInfo );
end;
end;
end;
end;
Procedure FocusOnOneItemRedraw;
{ Miscellaneous menu redraw procedure. The Eqp display will be shown; }
{ the INV display won't be. }
begin
if InfoGB <> Nil then SDLCombatDisplay( InfoGB );
DrawBPBorder;
LongformGearInfo( BP_Focus , InfoGB, ZONE_BPInfo );
DrawBackpackHeader( BP_Source );
if EqpRPM <> Nil then begin
DisplayMenu( EqpRPM , Nil );
GameMsg( MsgString( 'BACKPACK_Directions' ) , ZONE_BPInstructions.GetRect() , MenuItem );
end;
end;
Procedure FHQWargearRedraw;
{ Do a redraw for the Field HQ. }
begin
if InfoGB <> Nil then SDLCombatDisplay( InfoGB );
if BPRD_CAPTION <> '' then begin
InfoBox( ZONE_FHQTitle.GetRect() );
CMessage( BPRD_CAPTION , ZONE_FHQTitle.GetRect() , InfoHilight );
end;
InfoBox( ZONE_FHQMenu.GetRect() );
InfoBox( ZONE_FHQInfo.GetRect() );
LongformGearInfo( InfoGear , InfoGB, ZONE_FHQInfo );
end;
Procedure TransferRedraw;
{ The redrawer for the transfer frontend. }
var
Part: GearPtr;
begin
SDLCombatDisplay( InfoGB );
if BPRD_CAPTION <> '' then begin
InfoBox( ZONE_FHQTitle.GetRect() );
CMessage( BPRD_CAPTION , ZONE_FHQTitle.GetRect() , InfoHilight );
end;
InfoBox( ZONE_FHQMenu.GetRect() );
InfoBox( ZONE_FHQInfo.GetRect() );
if ( BP_ActiveMenu <> Nil ) and ( BP_Source <> Nil ) then begin
Part := RetrieveGearSib( BP_Source , CurrentMenuItemValue( BP_ActiveMenu ) );
if Part <> Nil then begin
LongformGearInfo( Part , InfoGB, ZONE_FHQInfo );
end;
end;
end;
Procedure RobotPartRedraw;
{ Redraw procedure for the robot part selector. }
begin
if InfoGB <> Nil then SDLCombatDisplay( InfoGB );
DrawBPBorder;
{if InfoGear <> Nil then DisplayGearInfo( InfoGear , InfoGB );}
GameMsg( MsgString( 'SELECT_ROBOT_PARTS' ) , ZONE_EqpMenu.GetRect() , MenuItem );
end;
Procedure SelectColors( M: GearPtr; Redrawer: RedrawProcedureType );
{ The player wants to change the colors for this part. Make it so. }
{ Use the colormenu unit, backported from GH2. }
var
mysprite,startpal,mypal: String;
begin
startpal := SAttValue( m^.SA, 'SDL_COLORS' );
if M^.G = GG_Character then begin
mypal := SelectColorPalette( colormenu_mode_character, SAttValue( m^.SA, 'SDL_PORTRAIT' ), startpal, 100, 150, 0, Redrawer );
end else begin
mypal := SelectColorPalette( colormenu_mode_mecha, SAttValue( m^.SA, 'SDL_SPRITE' ), startpal, 64, 64, 8, Redrawer );
end;
SetSAtt( M^.SA, 'SDL_COLORS <' + mypal + '>' );
end;
Procedure SelectSprite( M: GearPtr; Redrawer: RedrawProcedureType );
{ The player wants to change the colors for sprite for this character. }
{ The menu will be placed in the Menu area; assume the redrawer will }
{ show whatever changes are made here. }
var
RPM: RPGMenuPtr;
fname: String;
begin
RPM := CreateRPGMenu( MenuItem , MenuSelect , ZONE_CharViewMenu );
if NAttValue( M^.NA , NAG_CharDescription , NAS_Gender ) = NAV_Female then begin
BuildFileMenu( RPM , Graphics_Directory + 'cha_f_*.*' );
end else if NAttValue( M^.NA , NAG_CharDescription , NAS_Gender ) = NAV_Male then begin
BuildFileMenu( RPM , Graphics_Directory + 'cha_m_*.*' );
end else begin
BuildFileMenu( RPM , Graphics_Directory + 'cha_*_*.*' );
end;
AddRPGMenuItem( RPM , MsgString( 'EXIT' ) , -1 );
fname := SelectFile( RPM , Redrawer );
if fname <> '' then begin
SetSAtt( M^.SA , 'SDL_SPRITE <' + fname + '>' );
end;
DisposeRPGMenu( RPM );
end;
{$ENDIF}
Function FindNextPC( GB: GameBoardPtr; CurrentPC: GearPtr; AllowPets: Boolean ): GearPtr;
{ Locate the next player character on the gameboard. }
Function IsPC( PC: GearPtr ): Boolean;
{ Return True if this is a PC, or False otherwise. }
var
team: Longint;
Pilot: GearPtr;
begin
if IsMasterGear( PC ) and GearActive(PC) then begin
team := NAttValue( PC^.NA , NAG_Location, NAS_Team );
Pilot := LocatePilot( PC );
if team = NAV_DefPlayerTeam then IsPC := True
else if team = NAV_LancemateTeam then IsPC := AllowPets or ( NAttValue( Pilot^.NA , NAG_Personal , NAS_CID ) <> 0 )
else IsPC := False;
end else IsPC := False;
end;
var
PC,NextPC,FirstPC: GearPtr;
FoundStart: Boolean;
begin
NextPC := Nil;
FirstPC := Nil;
FoundStart := CurrentPC = Nil;
PC := GB^.Meks;
while ( PC <> Nil ) and ( NextPC = Nil ) do begin
if IsPC(PC) then begin
if FirstPC = Nil then FirstPC := PC;
if FoundStart and (NextPC = Nil) then NextPC := PC;
if PC = CurrentPC then FoundStart := True;
end;
PC := PC^.Next;
end;
if NextPC = Nil then begin
if FirstPC = Nil then FindNextPC := CurrentPC
else FindNextPC := FirstPC;
end else FindNextPC := NextPC;
end;
Function FindPrevPC( GB: GameBoardPtr; CurrentPC: GearPtr; AllowPets: Boolean ): GearPtr;
{ Locate the previous player character on the gameboard. }
Function IsPC( PC: GearPtr ): Boolean;
{ Return True if this is a PC, or False otherwise. }
var
team: Longint;
Pilot: GearPtr;
begin
if IsMasterGear( PC ) and GearActive(PC) then begin
team := NAttValue( PC^.NA , NAG_Location, NAS_Team );
Pilot := LocatePilot( PC );
if team = NAV_DefPlayerTeam then IsPC := True
else if team = NAV_LancemateTeam then IsPC := AllowPets or ( NAttValue( Pilot^.NA , NAG_Personal , NAS_CID ) <> 0 )
else IsPC := False;
end else IsPC := False;
end;
var
PC,PrevPC,LastPC: GearPtr;
FoundStart: Boolean;
begin
PrevPC := Nil;
LastPC := Nil;
FoundStart := CurrentPC = Nil;
PC := GB^.Meks;
while ( PC <> Nil ) and not FoundStart do begin
if IsPC(PC) then begin
PrevPC := LastPC;
if PC <> CurrentPC then LastPC := PC
else if PrevPC <> Nil then FoundStart := True;
end;
PC := PC^.Next;
end;
if not FoundStart then begin
if LastPC = Nil then FindPrevPC := CurrentPC
else FindPrevPC := LastPC;
end else FindPrevPC := PrevPC;
end;
Function SelectRobotParts( GB: GameBoardPtr; PC: GearPtr ): GearPtr;
{ Select up to 10 parts to build a robot with. }
{ Delink them from the INVENTORY and return them as a list. }
var
Ingredients,Part,P2: GearPtr;
RPM: RPGMenuPtr;
N: Integer;
begin
{$IFNDEF SDLMODE}
DrawBPBorder;
GameMsg( MsgString( 'SELECT_ROBOT_PARTS' ) , ZONE_EqpMenu , MenuItem );
{$ELSE}
InfoGB := GB;
InfoGear := PC;
{$ENDIF}
Ingredients := Nil;
repeat
RPM := CreateRPGMenu( MenuItem , MenuSelect , ZONE_InvMenu );
RPM^.Mode := RPMNoCleanup;
Part := PC^.InvCom;
N := 1;
while Part <> Nil do begin
if ( Part^.G = GG_Weapon ) or ( Part^.G = GG_Shield ) or ( Part^.G = GG_ExArmor ) or ( Part^.G = GG_Sensor ) or ( Part^.G = GG_Electronics ) then begin
AddRPGMenuItem( RPM , GearName( Part ) , N );
end else if ( Part^.G = GG_RepairFuel ) and ( ( Part^.S = 15 ) or ( Part^.S = 23 ) ) then begin
AddRPGMenuItem( RPM , GearName( Part ) , N );
end;
Part := Part^.Next;
Inc( N );
end;
RPMSortAlpha( RPM );
AlphaKeyMenu( RPM );
AddRPGMenuItem( RPM , MsgString( 'EXIT' ) , -1 );
{$IFDEF SDLMODE}
N := SelectMenu( RPM , @RobotPartRedraw );
{$ELSE}
N := SelectMenu( RPM );
{$ENDIF}
DisposeRPGMenu( RPM );
if N > -1 then begin
Part := RetrieveGearSib( PC^.InvCom , N );
DelinkGear( PC^.InvCom , Part );
while Part^.InvCom <> Nil do begin
P2 := Part^.InvCom;
DelinkGear( Part^.InvCom , P2 );
InsertInvCom( PC , P2 );
end;
AppendGear( Ingredients , Part );
end;
until ( NumSiblingGears( Ingredients ) > 9 ) or ( N = -1 );
SelectRobotParts := Ingredients;
end;
Procedure AddRepairOptions( RPM: RPGMenuPtr; PC,Item: GearPtr );
{ Check the object in question, then add options to the }
{ provided menu if the item is in need of repairs which the }
{ PC can provide. Repair items will be numbered 100 + RSN }
var
N: Integer;
begin
PC := LocatePilot( PC );
if PC <> Nil then begin
for N := 1 to NumRepairSkills do begin
{ The repair option will only be added to the menu if: }
{ - The PC has the required skill. }
{ - The item is in need of repair (using this skill). }
if ( NAttValue( PC^.NA , NAG_Skill , RepairSkillIndex[N] ) > 0 ) and ( TotalRepairableDamage( Item , RepairSkillIndex[N] ) > 0 ) then begin
AddRPGMenuItem( RPM , MsgString( 'BACKPACK_Repair' ) + SkillMan[ RepairSkillIndex[N] ].Name , 100 + N );
end;
end;
end;
end;
Procedure DoFieldRepair( GB: GameBoardPtr; PC , Item: GearPtr; Skill: Integer );
{ The PC is going to use one of the repair skills. Call the }
{ standard procedure, then print output. }
var
msg: String;
N: LongInt;
RepairFuel,RMaster: GearPtr;
begin
{ Error check - if no repair is needed, display an appropraite }
{ response. }
if TotalRepairableDamage( Item , Skill ) < 1 then begin
DialogMsg( MsgString( 'PCREPAIR_NoDamageDone' ) );
Exit;
end;
{ Locate the "repair fuel". }
RepairFuel := SeekGear( PC , GG_RepairFuel , Skill );
if RepairFuel = Nil then begin
DialogMsg( MsgString( 'PCREPAIR_NoRepairFuel' ) );
Exit;
end;
{ Locate the root item. If this is a character, and the repair attempt }
{ fails, and the master is destroyed, that's a bad thing. }
RMaster := FindRoot( Item );
N := UseRepairSkill( GB , PC , Item , Skill );
msg := ReplaceHash( MsgString( 'PCREPAIR_UseSkill' + BStr( Skill ) ) , GearName( Item ) );
{ Inform the user of the success. }
if ( RMaster^.G = GG_Character ) and Destroyed( RMaster ) then begin
AddNAtt( RMaster^.NA , NAG_Damage , NAS_StrucDamage , 30 );
msg := msg + ReplaceHash( MsgString( 'PCREPAIR_DEAD' ) , GearName( RMaster ) );
end else if N > 0 then begin
msg := msg + BStr( N ) + MsgString( 'PCREPAIR_Success' + BStr( Skill ) );
end else begin
msg := msg + MsgString( 'PCREPAIR_Failure' + BStr( Skill ) );
end;
DialogMsg( msg );
{ Deplete the fuel. }
RepairFuel^.V := RepairFuel^.V - N;
if RepairFuel^.V < 1 then begin
DialogMsg( ReplaceHash( MsgString( 'PCREPAIR_FuelUsedUp' ) , GearName( RepairFuel ) ) );
if IsSubCom( RepairFuel ) then begin
RemoveGear( RepairFuel^.Parent^.SubCom , RepairFuel );
end else if IsInvCom( RepairFuel ) then begin
RemoveGear( RepairFuel^.Parent^.InvCom , RepairFuel );
end;
end;
end;
Function ShakeDown( GB: GameBoardPtr; Part: GearPtr; X,Y: Integer ): LongInt;
{ This is the workhorse for this function. It does the }
{ dirty work of separating inventory from (former) owner. }
const
V_MAX = 2147483647;
V_MIN = -2147483648;
var
Cash: Int64;
SPart: GearPtr; { Sub-Part }
begin
{ Start by removing the cash from this part. }
cash := NAttValue( Part^.NA , NAG_Experience , NAS_Credits );
SetNAtt( Part^.NA , NAG_Experience , NAS_Credits , 0 );
SetNAtt( Part^.NA , NAG_EpisodeData , NAS_Ransacked , 1 );
{ Remove all InvComs, and place them on the map. }
While Part^.InvCom <> Nil do begin
SPart := Part^.InvCom;
DelinkGear( Part^.InvCom , SPart );
{ If this invcom isn't destroyed, put it on the }
{ ground for the PC to pick up. Otherwise delete it. }
if NotDestroyed( SPart ) then begin
SetNAtt( SPart^.NA , NAG_Location , NAS_X , X );
SetNAtt( SPart^.NA , NAG_Location , NAS_Y , Y );
SPart^.Next := GB^.Meks;
GB^.Meks := SPart;
end else begin
DisposeGear( SPart );
end;
end;
{ Shake down this gear's subcoms. }
SPart := Part^.SubCOm;
while SPart <> Nil do begin
if SPart^.G <> GG_Cockpit then cash := cash + ShakeDown( GB , SPart , X , Y );
SPart := SPart^.Next;
end;
if (V_MAX < Cash) then begin
Cash := V_MAX;
end else if (Cash < V_MIN) then begin
Cash := V_MIN;
end;
ShakeDown := Cash;
end;
Function Ransack( GB: GameBoardPtr; X,Y: Integer ): LongInt;
{ Yay! Loot and pillage! This function has two purposes: }
{ first, it separates all Inventory gears from any non-operational }
{ masters standing in this tile. Secondly, it collects the }
{ money from all those non-operational masters and returns the }
{ total amount as the function result. }
var
it: LongInt;
Mek: GearPtr;
begin
it := 0;
Mek := GB^.Meks;
while Mek <> Nil do begin
{ If this is a broken-down master, check to see if it's }
{ one we want to pillage. }
if IsMasterGear( Mek ) and not GearOperational( Mek ) then begin
{ We will ransack this gear if it's in the correct location. }
if ( NAttValue( Mek^.NA , NAG_Location , NAS_X ) = X ) and ( NAttValue( Mek^.NA , NAG_Location , NAS_Y ) = Y ) then begin
it := it + ShakeDown( GB , Mek , X , Y );
end;
end else if ( Mek^.G = GG_MetaTerrain ) and ( ( Mek^.Stat[ STAT_Lock ] = 0 ) or Destroyed( Mek ) ) then begin
{ Metaterrain gets ransacked if it's unlocked, }
{ or wrecked. }
if ( NAttValue( Mek^.NA , NAG_Location , NAS_X ) = X ) and ( NAttValue( Mek^.NA , NAG_Location , NAS_Y ) = Y ) then begin
it := it + ShakeDown( GB , Mek , X , Y );
end;
end;
Mek := Mek^.Next;
end;
Ransack := it;
end;
Function Handless( Mek: GearPtr ): Boolean;
{ Return TRUE if Mek either has no hands or can't use its hands }
{ at the moment (say, because it's transformed into tank mode). }
{ Return TRUE if Mek has hands and they are in perfect working order. }
var
Hand: GearPtr;
begin
Hand := SeekActiveIntrinsic( Mek , GG_Holder , GS_Hand );
if Hand = Nil then Handless := True
else Handless := not InGoodModule( Hand );
end;
{$IFDEF SDLMODE}
Procedure GetItemRedraw;
begin
SDLCombatDisplay( InfoGB );
InfoBox( ZONE_CenterMenu.GetRect() );
{DisplayGearInfo( InfoGear , InfoGB );}
end;
{$ENDIF}
Function SelectVisibleItem( GB: GameBoardPtr; PC: GearPtr; X,Y: Integer ): GearPtr;
{ Attempt to select a visible item from gameboard tile X,Y. }
{ If more than one item is present, prompt the user for which one }
{ to pick up. }
var
N,T: Integer;
RPM: RPGMenuPtr;
begin
{ First count the number of items in this spot. }
N := NumVisibleItemsAtSpot( GB , X , Y );
{ If it's just 0 or 1, then our job is simple... }
if N = 0 then begin
SelectVisibleItem := Nil;
end else if N = 1 then begin
SelectVisibleItem := FindVisibleItemAtSpot( GB , X , Y );
{ If it's more than one, better create a menu and let the user }
{ pick one. }
end else if N > 1 then begin
DialogMsg( MsgString( 'GET_WHICH_ITEM?' ) );
{$IFDEF SDLMODE}
RPM := CreateRPGMenu( MenuItem , MenuSelect , ZONE_CenterMenu );
{$ELSE}
RPM := CreateRPGMenu( MenuItem , MenuSelect , ZONE_Menu );
{$ENDIF}
for t := 1 to N do begin
AddRPGMenuItem( RPM , GearName( GetVisibleItemAtSpot( GB , X , Y , T ) ) , T );
end;
{$IFDEF SDLMODE}
InfoGear := PC;
InfoGB := GB;
N := SelectMenu( RPM , @GetItemRedraw );
{$ELSE}
N := SelectMenu( RPM );
{$ENDIF}
DisposeRPGMenu( RPM );
if N > -1 then begin
SelectVisibleItem := GetVisibleItemAtSpot( GB , X , Y , N );
end else begin
SelectVisibleItem := Nil;
end;
end;
end;
Procedure PCGetItem( GB: GameBoardPtr; PC: GearPtr );
{ The PC will attempt to pick up something lying on the ground. }
var
Cash,NID: LongInt;
P: Point;
item: GearPtr;
begin
if Handless( PC ) then begin
{ Start by checking something that other RPGs would }
{ just assume- does the PC have any hands? }
DialogMsg( 'You need hands in order to use this command.' );
end else begin
P := GearCurrentLocation( PC );
{ Before attempting to get an item, ransack whatever }
{ fallen enemies lie in this spot. }
Cash := Ransack( GB , P.X , P.Y );
{ Perform an immediate vision check- without it, items }
{ freed by the Ransack procedure above will remain unseen. }
VisionCheck( GB , PC );
Item := SelectVisibleItem( GB , PC , P.X , P.Y );
if Item <> Nil then begin
if IsLegalSlot( PC , Item ) then begin
DelinkGear( GB^.Meks , Item );
{ Clear the item's location values. }
StripNAtt( Item , NAG_Location );
InsertInvCom( PC , Item );
{ Clear the home, to prevent wandering items. }
SetSAtt( Item^.SA , 'HOME <>' );
DialogMsg( ReplaceHash( MsgString( 'YOU_GET_?' ) , GearName( Item ) ) );
NID := NAttValue( Item^.NA , NAG_Narrative , NAS_NID );
if NID <> 0 then SetTrigger( GB , TRIGGER_GetItem + BStr( NID ) );
end else if Cash = 0 then begin
DialogMsg( ReplaceHash( MsgString( 'CANT_GET_?' ) , GearName( Item ) ) );
end;
end else if Cash = 0 then begin
DialogMSG( 'No item found.' );
end;
if Cash > 0 then begin
DialogMsg( ReplaceHash( MsgString( 'YouFind$' ) , BStr( Cash ) ) );
AddNAtt( LocatePilot( PC )^.NA , NAG_Experience , NAS_Credits , Cash );
end;
{ Picking up an item takes time. }
WaitAMinute( GB , PC , ReactionTime( PC ) );
end;
end;
Procedure CreateInvMenu( PC: GearPtr );
{ Allocate the Inventory menu and fill it up with the PC's inventory. }
begin
if InvRPM <> Nil then DisposeRPGMenu( InvRPM );
InvRPM := CreateRPGMenu( MenuItem , MenuSelect , ZONE_InvMenu );
InvRPM^.Mode := RPMNoCleanup;
BuildInventoryMenu( InvRPM , PC );
{$IFNDEF SDLMODE}
AttachMenuDesc( InvRPM , ZONE_Menu2 );
{$ENDIF}
RPMSortAlpha( InvRPM );
{ If the menu is empty, add a message saying so. }
If InvRPM^.NumItem < 1 then AddRPGMenuItem( InvRPM , '[no inventory items]' , -1 )
else AlphaKeyMenu( InvRPM );
{ Add the menu keys. }
AddRPGMenuKey(InvRPM,'/',-2);
{$IFDEF SDLMODE}
AddRPGMenuKey( InvRPM , RPK_Right , -3 );
AddRPGMenuKey( InvRPM , RPK_Left , -4 );
{$ELSE}
AddRPGMenuKey( InvRPM , KeyMap[ KMC_East ].KCode , -3 );
AddRPGMenuKey( InvRPM , KeyMap[ KMC_West ].KCode , -4 );
{$ENDIF}
end;
Procedure CreateEqpMenu( PC: GearPtr );
{ Allocate the equipment menu and fill it up with the PC's gear. }
begin
if EqpRPM <> Nil then DisposeRPGMenu( EqpRPM );
EqpRPM := CreateRPGMenu( MenuItem , MenuSelect , ZONE_EqpMenu );
EqpRPM^.Mode := RPMNoCleanup;
{$IFNDEF SDLMODE}
AttachMenuDesc( EqpRPM , ZONE_Menu2 );
{$ENDIF}
BuildEquipmentMenu( EqpRPM , PC );
{ If the menu is empty, add a message saying so. }
If EqpRPM^.NumItem < 1 then AddRPGMenuItem( EqpRPM , '[no equipped items]' , -1 );
{ Add the menu keys. }
AddRPGMenuKey(EqpRPM,'/',-2);
{$IFDEF SDLMODE}
AddRPGMenuKey( EqpRPM , RPK_Right , -3 );
AddRPGMenuKey( EqpRPM , RPK_Left , -4 );
{$ELSE}
AddRPGMenuKey( EqpRPM , KeyMap[ KMC_East ].KCode , -3 );
AddRPGMenuKey( EqpRPM , KeyMap[ KMC_West ].KCode , -4 );
{$ENDIF}
end;
Procedure UpdateBackpack( PC: GearPtr );
{ Redo all the menus, and display them on the screen. }
begin
CreateInvMenu( PC );
CreateEqpMenu( PC );
{$IFNDEF SDLMODE}
DisplayMenu( InvRPM );
DisplayMenu( EqpRPM );
{$ENDIF}
end;
Procedure GivePartToPC( GB: GameBoardPtr; Part, PC: GearPtr );
{ Give the specified part to the PC. If the part cannot be }
{ held by the PC, store it so that it can be recovered using }
{ the FieldHQ Wargear Explorer. }
var
team: Integer;
begin
if ( PC <> Nil ) and IsLegalSlot( PC , Part ) then begin
InsertInvCom( PC , Part );
end else begin
{ If the PC can't carry this equipment, }
{ stick it off the map. }
team := NattValue( PC^.NA , NAG_Location , NAS_Team );
if team = NAV_LancemateTeam then team := NAV_DefPlayerTeam;
SetNAtt( Part^.NA , NAG_Location , NAS_Team , team );
DeployMek( GB , Part , False );
end;
end;
Procedure UnequipItem( GB: GameBoardPtr; PC , Item: GearPtr );
{ Delink ITEM from its parent, and stick it in the general inventory... }
{ If possible. Otherwise drop it. }
begin
{ First, delink Item from its parent. }
DelinkGear( Item^.Parent^.InvCom , Item );
{ HOW'D YA LIKE THEM CARROT DOTS, EH!?!? }
{ Next, link ITEM into the general inventory. }
GivePartToPC( GB , Item , PC );
{ Unequipping takes time. }
if GB <> Nil then WaitAMinute( GB , PC , ReactionTime( PC ) );
end;
Procedure UnequipFrontend( GB: GameBoardPtr; PC , Item: GearPtr );
{ Simply unequip the provided item. }
{ PRECOND: PC and ITEM had better be correct, dagnabbit... }
begin
DialogMsg( 'You unequip ' + GearName( Item ) + '.' );
UnequipItem( GB , PC , Item );
end;
Function CanBeExtracted( Item: GearPtr ): Boolean;
{ Return TRUE if the listed part can be extracted from a mecha, }
{ or FALSE if it cannot normally be extracted. }
begin
if ( Item^.G = GG_Support ) or ( Item^.G = GG_Cockpit ) or IsMasterGear( Item ) or ( Item^.Parent = Nil ) or ( Item^.Parent^.Scale = 0 ) or ( Item^.G = GG_Modifier ) then begin
CanBeExtracted := False;
end else if ( Item^.G = GG_Module ) and ( Item^.S = GS_Body ) then begin
CanBeExtracted := False;
end else if SeekGear( Item , GG_Cockpit , 0 , False ) <> Nil then begin
{ If the item contains the cockpit, it can't be extracted. }
CanBeExtracted := False;
end else begin
CanBeExtracted := Not PartHasIntrinsic( Item , NAS_Integral );
end;
end;
Function ExtractItem( GB: GameBoardPtr; TruePC , PC: GearPtr; var Item: GearPtr ): Boolean;
{ Delink ITEM from its parent, and stick it in the general inventory. }
{ Note that pulling a gear out of its mecha may well wreck it }
{ beyond any repair! Therefore, after this call, ITEM might no }
{ longer exist... i.e. it may equal NIL. }
var
it: Boolean;
SkTarget,SkRoll,WreckTarget: Integer;
begin
{ First, calculate the skill target. }
SkTarget := 2 + ComponentComplexity( Item );
if Item^.G = GG_Module then begin
WreckTarget := SkTarget + 8 - Item^.V;
end else if Item^.Scale < Item^.Parent^.Scale then begin
WreckTarget := SkTarget + 5;
end else begin
WreckTarget := SkTarget + 10 - UnscaledMaxDamage( Item );
end;
if WreckTarget < SkTarget then WreckTarget := SkTarget + 1;
SkRoll := RollStep( TeamSkill( GB , NAV_DefPlayerTeam , 31 ) );
DoleSkillExperience( TruePC , 31 , 1 );
AddMentalDown( TruePC , 1 );
WaitAMinute( GB , TruePC , ReactionTime( TruePC ) * 5 );
if SkRoll > WreckTarget then begin
{ First, delink Item from its parent. }
DelinkGear( Item^.Parent^.SubCom , Item );
{ Stick the part in the general inventory, if legal. }
GivePartToPC( GB , Item , PC );
DoleSkillExperience( TruePC , 31 , 2 );
DoleExperience( TruePC , 1 );
it := True;
end else if SkRoll > SkTarget then begin
RemoveGear( Item^.Parent^.SubCom , Item );
Item := Nil;
it := True;
end else begin
it := False;
end;
ExtractItem := it;
end;
Procedure ExtractFrontend( GB: GameBoardPtr; TruePC , PC , Item: GearPtr );
{ Simply remove the provided item. }
{ PRECOND: PC and ITEM had better be correct, dagnabbit... }
var
name: String;
begin
name := GearName( Item );
if GearActive( PC ) then begin
DialogMsg( MsgString( 'EXTRACT_NOTACTIVE' ) );
end else if ExtractItem( GB , TruePC , PC , Item ) then begin
if Item = Nil then begin
DialogMsg( ReplaceHash( MsgString( 'EXTRACT_WRECK' ) , name ) );
end else begin
DialogMsg( ReplaceHash( MsgString( 'EXTRACT_OK' ) , name ) );
end;
end else begin
DialogMsg( ReplaceHash( MsgString( 'EXTRACT_FAIL' ) , name ) );
end;
end;
Procedure EquipItem( GB: GameBoardPtr; PC , Slot , Item: GearPtr );
{ This is the real equipping procedure. Stuff ITEM into SLOT. }
{ As noted in TheRules.txt, any nonmaster gear can only have one }
{ item of any particular "G" type equipped at a time. So, if }
{ SLOT already has equipment of type ITEM^.G, unequip that and }
{ stuff it into PC's general inventory. }
var
I2,I3: GearPtr;
begin
{ First, check for already equipped items. }
I2 := Slot^.InvCom;
while I2 <> Nil do begin
I3 := I2^.Next; { This next step might delink I2, so... }
if I2^.G = Item^.G then begin
UnequipItem( GB , PC , I2 );
end;
I2 := I3;
end;
{ Next, delink Item from PC. }
DelinkGear( PC^.InvCom , Item );
{ Next, link ITEM into SLOT. }
InsertInvCom( Slot , Item );
{ Equipping an item takes time. }
if GB <> Nil then WaitAMinute( GB , PC , ReactionTime( PC ) );
end;
Procedure EquipItemFrontend( GB: GameBoardPtr; PC , Item: GearPtr );
{ Assign ITEM to a legal equipment slot. Move it from the }
{ general inventory into its new home. }
var
EI_Menu: RPGMenuPtr;
N: Integer;
begin
{ Build the slot selection menu. }
EI_Menu := CreateRPGMenu( MenuItem , MenuSelect , ZONE_InvMenu );
BuildSlotMenu( EI_Menu , PC , Item );
if EI_Menu^.NumItem < 1 then AddRPGMenuItem( EI_Menu , '[cannot equip ' + GearName( Item ) + ']' , -1 );
{ Select a slot for the item to go into. }
{$IFDEF SDLMODE}
BP_Source := PC;
BP_Focus := Item;
N := SelectMenu( EI_Menu , @FocusOnOneItemRedraw);
{$ELSE}
N := SelectMenu( EI_Menu );
{$ENDIF}
DisposeRPGMenu( EI_Menu );
{ If a slot was selected, pass that info on to the workhorse. }
if N <> -1 then begin
DialogMsg( 'You equip ' + GearName( Item ) + '.' );
EquipItem( GB , PC , LocateGearByNumber( PC , N ) , Item );
end;
end;
Function InstallItem( GB: GameBoardPtr; TruePC , Slot: GearPtr; var Item: GearPtr ): Boolean;
{ Attempt the skill rolls needed to install ITEM into the }
{ requested slot. }
var
SlotCom,ItemCom,UsedCom: Integer;
SkTarget,WreckTarget,SkRoll: Integer;
begin
{ Error Check - no circular references! }
if ( FindGearIndex( Item , Slot ) <> -1 ) then Exit( False );
{ Also, can't engineer things when you're exhausted. }
if CurrentMental( TruePC ) < 1 then Exit( False );
{ Can't install into a personal-scale slot. }
if Slot^.Scale = 0 then Exit( False );
SlotCom := ComponentComplexity( Slot );
ItemCom := ComponentComplexity( Item );
UsedCom := SubComComplexity( Slot );
case Item^.G of
GG_Weapon,GG_MoveSys: SkTarget := 10;
GG_Module: SkTarget := 15;
GG_Sensor: SkTarget := 30;
GG_Modifier: SkTarget := 25;
else SkTarget := 20;
end;
if Item^.Scale < Slot^.Scale then SkTarget := SkTarget div 2;
{ The WreckTarget is the target number that must be beat }
{ in order to avoid accidentally destroying the part... }
if ( Item^.G = GG_Module ) then begin
WreckTarget := 8 - Item^.V;
end else if ( UnscaledMaxDamage( Item ) < 1 ) or ( Item^.Scale < Slot^.Scale ) then begin
WreckTarget := 7;
end else begin
WreckTarget := 10 - UnscaledMaxDamage( Item );
end;
if WreckTarget < 3 then WreckTarget := 3;
{ If the SLOT is going to be overstuffed, better raise the }
{ number of successes and the target number drastically. }
if ( ( ItemCom + UsedCom ) > SlotCom ) and ( Not IsMasterGear( Slot ) ) then begin
SkTarget := SkTarget + ItemCom + UsedCom - SlotCom + 5;
end;
WaitAMinute( GB , TruePC , ReactionTime( TruePC ) * 5 );
SkRoll := RollStep( TeamSkill( GB , NAV_DefPlayerTeam , 31 ) );
if SkRoll > SkTarget then begin
{ Install the item. }
DoleSkillExperience( TruePC , 31 , 5 );
DoleExperience( TruePC , 10 );
DelinkGear( Item^.Parent^.InvCom , Item );
InsertSubCom( Slot , Item );
end else if SkRoll < WreckTarget then begin
RemoveGear( Item^.Parent^.InvCom , Item );
Item := Nil;
end;
AddMentalDown( TruePC , 1 );
DoleSkillExperience( TruePC , 31 , 1 );
InstallItem := SkRoll > SkTarget;
end;
Procedure InstallFrontend( GB: GameBoardPtr; TruePC , PC , Item: GearPtr );
{ Assign ITEM to a legal equipment slot. Move it from the }
{ general inventory into its new home. }
var
EI_Menu: RPGMenuPtr;
N: Integer;
name: String;
begin
{ Error check- can't install into an active master. }
if GearActive( PC ) then begin
DialogMsg( MsgString( 'INSTALL_NOTACTIVE' ) );
Exit;
end;