-
Notifications
You must be signed in to change notification settings - Fork 16
/
gearutil.pp
3290 lines (2865 loc) · 102 KB
/
gearutil.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 gearutil;
{
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,ghmecha,ghchars,ghmodule,ghweapon,ghmovers,ghholder,ghsensor,ghsupport,ghguard,ghswag,ghprop,texutil,ui4gh;
Const
NAG_Damage = 12;
NAS_StrucDamage = 0; {Structural Damage is what we would}
{normally refer to as HP loss.}
NAS_ArmorDamage = 1; {As armor gets hit, it loses its}
{protective ability.}
NAS_OutOfAction = 2; { if OutOfAction <> 0 , this model is OutOfAction }
Num_Perm_Injuries = 5;
Perm_Injury_List: Array [1..Num_Perm_Injuries] of Byte = (
21,22,23,24,25
);
Perm_Injury_Slot: Array [1..Num_Perm_Injuries] of String = (
'EYES','SPINE','MUSCULATURE','SKELETON','HEART'
);
Function GearsAreIdentical( A,B: GearPtr ): Boolean;
Function IsMasterGear(G: GearPtr): Boolean;
Procedure InitGear(Part: GearPtr);
function FindMaster( Part: GearPtr ): GearPtr;
function FindMasterOrRoot( Part: GearPtr ): GearPtr;
Function MasterSize(Part: GearPtr): Integer;
function FindModule( Part: GearPtr ): GearPtr;
function ModifiersSkillBonus( Part: GearPtr; Skill: Integer ): Integer;
Function CharaSkillRank( PC: GearPtr; Skill: Integer ): Integer;
function InGoodModule( Part: GearPtr ): Boolean;
Function ScaleDP( DP , Scale , Material: Integer ): Integer;
Function UnscaledMaxDamage( Part: GearPtr ): Integer;
Function GearMaxDamage(Part: GearPtr): Integer;
Function GearMaxArmor(Part: GearPtr): Integer;
Function GenericName(Part: GearPtr): String;
Function GearName(Part: GearPtr): String;
Function FullGearName(Part: GearPtr): String;
Function ComponentMass( Part: GearPtr ): Integer;
Function GearMass( Master: GearPtr ): Integer;
Function IntrinsicMass( Master: GearPtr ): LongInt;
Function EquipmentMass( Master: GearPtr ): LongInt;
Function MakeMassString( BaseMass: LongInt; Scale: Integer ): String;
Function MassString( Master: GearPtr ): String;
Function GearDepth( Part: GearPtr ): Integer;
Function ComponentComplexity( Part: GearPtr ): Integer;
Function SubComComplexity( Part: GearPtr ): Integer;
Function IsLegalInvcom( Parent, Equip: GearPtr ): Boolean;
Function IsLegalSubcom( Parent, Equip: GearPtr ): Boolean;
Function CanBeInstalled( Part , Equip: GearPtr ): Boolean;
Procedure CheckGearRange( Part: GearPtr );
Function SeekGear( Master: GearPtr; G,S: Integer; CheckInv: Boolean ): GearPtr;
Function SeekGear( Master: GearPtr; G,S: Integer ): GearPtr;
Function SeekCurrentLevelGear( Master: GearPtr; G,S: Integer ): GearPtr;
Function SeekSoftware( Mek: GearPtr; SW_Type,SW_Param: Integer; CasualUse: Boolean ): GearPtr;
Function GearEncumberance( Mek: GearPtr ): Integer;
Function BaseMVTVScore( Mek: GearPtr ): Integer;
Function ComponentValue( Part: GearPtr; CalcCost,FullLoad: Boolean ): LongInt;
Function GearCost( Master: GearPtr ): LongInt;
Function GearValue( Master: GearPtr ): LongInt;
function SeekGearByName( LList: GearPtr; Name: String ): GearPtr;
function SeekSibByFullName( LList: GearPtr; Name: String ): GearPtr;
function SeekChildByName( Parent: GearPtr; Name: String ): GearPtr;
function SeekGearByDesig( LList: GearPtr; Name: String ): GearPtr;
function SeekGearByIDTag( LList: GearPtr; G,S,V: LongInt ): GearPtr;
function CountGearsByIDTag( LList: GearPtr; G,S,V: LongInt ): LongInt;
function SeekGearByG( LList: GearPtr; G: Integer ): GearPtr;
function SeekSubsByG( LList: GearPtr; G: Integer ): GearPtr;
function MaxIDTag( LList: GearPtr; G,S: Integer ): LongInt;
function CStat( PC: GearPtr; Stat: Integer ): Integer;
Procedure WriteCGears( var F: Text; G: GearPtr );
Function ReadCGears( var F: Text ): GearPtr;
Function WeaponDC( Attacker: GearPtr ): Integer;
Function AmountOfDamage( Part: GearPtr; PlusArmor: Boolean ): LongInt;
Function GearCurrentDamage(Part: GearPtr): LongInt;
Function GearCurrentArmor(Part: GearPtr): Integer;
Function PercentDamaged( Master: GearPtr ): Integer;
Function NotDestroyed(Part: GearPtr): Boolean;
Function Destroyed(Part: GearPtr): Boolean;
Function PartActive( Part: GearPtr ): Boolean;
Function RollDamage( DC , Scale: Integer ): Integer;
Function NumActiveGears(Part: GearPtr): Integer;
Function FindActiveGear(Part: GearPtr; N: Integer): GearPtr;
Function CountActivePoints(Master: GearPtr; G,S: Integer): Integer;
Function CountActiveParts(Master: GearPtr; G,S: Integer): Integer;
Function CountTotalParts(Master: GearPtr; G,S: Integer): Integer;
Function EnergyCost( Part: GearPtr ): Integer;
Function EnergyPoints( Master: GearPtr ): LongInt;
Procedure SpendEnergy( Master: GearPtr; EP: Integer );
Function SeekActiveIntrinsic( Master: GearPtr; G,S: Integer ): GearPtr;
Function SeekItem( Master: GearPtr; G,S: Integer; CheckGeneralInv: Boolean ): GearPtr;
Function MechaManeuver( Mek: GearPtr ): Integer;
Function MechaTargeting( Mek: GearPtr ): Integer;
Function MechaSensorRating( Mek: GearPtr ): Integer;
Function MechaStealthRating( Mek: GearPtr ): Integer;
Function LocateGoodAmmo( Weapon: GearPtr ): GearPtr;
Function LocateAnyAmmo( Weapon: GearPtr ): GearPtr;
Function WeaponAttackAttributes( Attacker: GearPtr ): String;
Function HasAttackAttribute( AtAt: String; N: Integer ): Boolean;
Function HasAreaEffect( AtAt: String ): Boolean;
Function HasAreaEffect( Attacker: GearPtr ): Boolean;
Function NonDamagingAttack( AtAt: String ): Boolean;
Function NoCalledShots( AtAt: String; AtOp: Integer ): Boolean;
Function AmmoRemaining( Weapon: GearPtr ): Integer;
Function ScaleRange( Rng,Scale: Integer ): Integer;
Procedure ApplyPerminantInjury( PC: GearPtr );
Procedure ApplyCyberware( PC,Cyber: GearPtr );
Function NotAnAnimal( Master: GearPtr ): Boolean;
Function CreateComponentList( MasterList: GearPtr; const Context: String ): NAttPtr;
Function RandomComponentListEntry( ShoppingList: NAttPtr ): NAttPtr;
Function SelectComponentFromList( MasterList: GearPtr; var ShoppingList: NAttPtr ): GearPtr;
Function FindNextComponent( CList: GearPtr; const plot_desc: String ): GearPtr;
Function NumberOfSkillSlots( PC: GearPtr ): Integer;
Function TooManySkillsPenalty( PC: GearPtr; N: Integer ): Integer;
Function SkillAdvCost( PC: GearPtr; CurrentLevel: Integer ): LongInt;
Function IsExternalPart( Master,Part: GearPtr ): Boolean;
Function ToolBonus( Master: GearPtr; Skill: Integer ): Integer;
implementation
uses ghintrinsic,movement;
Const
SaveFileContinue = 0;
SaveFileSentinel = -1;
GMMODE_AddAll = 0;
GMMODE_Intrinsic = 1;
GMMODE_Equipment = 2;
Storage_Armor_Bonus = 2;
MVSensorPenalty = 1;
MVGyroPenalty = 6;
TRSensorPenalty = 5;
Function GearsAreIdentical( A,B: GearPtr ): Boolean;
{ Return TRUE if A and B are perfectly identical, including all child gears. }
Function StatsMatch: Boolean;
{ Return TRUE if all of A's and B's stats match. }
var
T: Integer;
AllOK: Boolean;
begin
AllOK := True;
for t := 1 to NumGearStats do AllOK := AllOK and ( A^.Stat[ T ] = B^.Stat[ T ] );
StatsMatch := AllOK;
end;
Function ChildrenMatch: Boolean;
{ Return TRUE if all of A's children are identical to B's children. Note that }
{ this procedure may result in false negatives- if two gears are effectively identical }
{ but their children are in a different order, this function will claim that they }
{ aren't identical. Oh well, not a big deal... }
var
AllOK: Boolean;
C1,C2: GearPtr;
begin
AllOK := True;
C1 := A^.SubCom;
C2 := B^.SubCom;
while ( C1 <> Nil ) and ( C2 <> Nil ) and AllOK do begin
AllOK := AllOK and GearsAreIdentical( C1 , C2 );
C1 := C1^.Next;
C2 := C2^.Next;
end;
AllOK := AllOK and ( C1 = Nil ) and ( C2 = Nil );
C1 := A^.InvCom;
C2 := B^.InvCom;
while ( C1 <> Nil ) and ( C2 <> Nil ) and AllOK do begin
AllOK := AllOK and GearsAreIdentical( C1 , C2 );
C1 := C1^.Next;
C2 := C2^.Next;
end;
AllOK := AllOK and ( C1 = Nil ) and ( C2 = Nil );
ChildrenMatch := AllOK;
end;
Function AllAttAcc4( G1,G2: GearPtr ): Boolean;
{ All Attributes Accounted For. All numeric and string attributes of G1 must }
{ be found in G2. }
var
SA: SAttPtr;
NA: NAttPtr;
AllOK: Boolean;
S_tag,S_data: String;
begin
AllOK := True;
SA := G1^.SA;
while ( SA <> Nil ) and AllOK do begin
S_tag := RetrieveAPreamble( SA^.Info );
S_data := RetrieveAString( SA^.Info );
AllOK := AllOK and ( SAttValue( G2^.SA , S_tag ) = S_data );
SA := SA^.Next;
end;
NA := G1^.NA;
while ( NA <> Nil ) and AllOK do begin
AllOK := AllOK and ( NAttValue( G2^.NA , NA^.G , NA^.S ) = NA^.V );
NA := NA^.Next;
end;
AllAttAcc4 := AllOK;
end;
begin
GearsAreIdentical := ( A <> Nil ) and ( B <> Nil ) and ( A^.G = B^.G ) and ( A^.S = B^.S ) and ( A^.V = B^.V ) and StatsMatch and ChildrenMatch and AllAttAcc4( A , B ) and AllAttAcc4( B , A );
end;
Function IsMasterGear(G: GearPtr): Boolean;
{This function checks gear G to see whether or not it counst}
{as a Master Gear. Currently the only gears which count}
{as masters are Mecha and Characters.}
var
it: Boolean;
begin
if G <> Nil then begin
if (G^.G = GG_Mecha) or (G^.G = GG_Character) or (G^.G = GG_Prop) then it := true
else it := false;
end else it := False;
IsMasterGear := it;
end;
Procedure InitGear(Part: GearPtr);
{ Part has just been created. G, S, and V have been defined but }
{ nothing else. Initialize its fields to the default values.}
var
T: Integer;
begin
{Error check- make sure we haven't just been sent a Nil.}
if Part = Nil then exit;
{ Clear all stats, to prevent nasty errors. }
for t := 1 to NumGearStats do Part^.Stat[ T ] := 0;
{For gears which are not master gears, take the scale}
{from its parent.}
if not IsMasterGear(Part) then begin
if Part^.Parent <> NIl then begin
Part^.Scale := Part^.Parent^.Scale;
{ In addition, sub-components inherit material from }
{ their parents. }
if IsSubCom( Part ) then begin
SetNAtt( Part^.NA , NAG_GearOps , NAS_Material , NAttValue( Part^.Parent^.NA , NAG_GearOps , NAS_Material ) );
end;
end;
end;
{Do the type-specific initialization routines here.}
case Part^.G of
GG_Mecha: InitMecha(Part);
GG_Character: InitChar(Part);
GG_Weapon: InitWeapon(Part);
GG_Ammo: InitAmmo(Part);
GG_MetaTerrain: InitMetaTerrain(Part);
GG_Module: InitModule( Part );
GG_MapFeature: InitMapFeature( Part );
end;
end;
function FindMaster( Part: GearPtr ): GearPtr;
{ Locate the master of PART. Return NIL if there is no master. }
begin
{ Move the pointer up to either root level or the first Master parent. }
while ( Part <> Nil ) and ( not IsMasterGear(Part) ) do Part := Part^.Parent;
FindMaster := Part;
end;
function FindMasterOrRoot( Part: GearPtr ): GearPtr;
{ Locate the master of PART. Failing that, find the root. }
{ Thanks Buffered, whoever you are. }
begin
{ Move the pointer up to either root level or the first Master parent. }
while ( Part <> Nil ) and ( Part^.Parent <> Nil ) and ( not IsMasterGear(Part) ) do Part := Part^.Parent;
FindMasterOrRoot := Part;
end;
Function MasterSize(Part: GearPtr): Integer;
{Determine the size of the Master for the current gear.}
{If the Master is a mecha, this will be its Value field.}
{If its a Character, this will be its Body stat.}
{If no Master can be found, return Nil.}
var
it: Integer;
begin
Part := FindMaster( Part );
if Part = Nil then it := 0
else if Part^.G = GG_Mecha then it := Part^.V
else if Part^.G = GG_Character then begin
{ The main purpose of this for character gears is to }
{ determine the size of the character's limbs. }
it := ( Part^.Stat[ STAT_Body ] + 2 ) div 3;
if it < 1 then it := 1
else if it > 10 then it := 10;
end else it := 0;
MasterSize := it;
end;
function FindModule( Part: GearPtr ): GearPtr;
{ Locate the module of PART. Return NIL if there is no master. }
begin
{ Move the pointer up to either root level or the first Master parent. }
while ( Part <> Nil ) and ( Part^.G <> GG_Module ) do Part := Part^.Parent;
FindModule := Part;
end;
function ModifiersSkillBonus( Part: GearPtr; Skill: Integer ): Integer;
{ Determine the total skill bonus gained from MODIFIER }
{ gears installed in PART. }
var
MD: GearPtr; { Modifier gears. }
it: Integer;
begin
MD := Part^.SubCom;
it := 0;
while MD <> Nil do begin
if ( MD^.G = GG_Modifier ) and ( MD^.S = GS_SkillModifier ) then begin
if ( MD^.Stat[ STAT_SkillToModify ] = Skill ) and ( MD^.Stat[ STAT_SkillModBonus ] > it ) then it := MD^.Stat[ STAT_SkillModBonus ];
end;
MD := MD^.Next;
end;
ModifiersSkillBonus := it;
end;
Function CharaSkillRank( PC: GearPtr; Skill: Integer ): Integer;
{ Return the PC's rank in this skill. }
{ Note that PC _MUST_ be the actual PC!!! This does not work on }
{ mecha, or props, or anything else!!! }
{ Also note that this function does not check the presence of tools. }
var
it: Integer;
begin
if ( PC <> Nil ) and ( PC^.G = GG_Character ) then begin
it := NAttValue( PC^.NA , NAG_Skill , Skill ) + ModifiersSkillBonus( PC , Skill );
{ Normally to check for a talent we'd use the HAStALENT function, }
{ but since that isn't available here and we know we're dealing with }
{ the PC and also because you can't be granted talents from items or }
{ mecha, I'll just check the NAtt to see if it's present. }
if ( it = 0 ) and ( NAttValue( PC^.NA , NAG_Talent , NAS_JackOfAll ) <> 0 ) then it := 1;
CharaSkillRank := it;
end else begin
CharaSkillRank := 0;
end;
end;
function InGoodModule( Part: GearPtr ): Boolean;
{ Check PART to make sure that it is mounted in a good module. }
var
Ms,Md: GearPtr; { Master and Module }
begin
Ms := FindMaster( Part );
Md := FindModule( Part );
{ If no master can be found, this function returns FALSE. }
if ( Ms = Nil ) then Exit( False );
if Ms^.G = GG_Mecha then begin
if Md = Nil then begin
{ This gear must be located in the general }
{ inventory, since it isn't in a module. Items }
{ in the general inventory can't be used until }
{ equipped. }
InGoodModule := False;
end else begin
{ With both the master and the module, look up }
{ this combo in the Form X Module array. }
InGoodModule := FormXModule[ Ms^.S , Md^.S ] and IsSubCom( Md );
end;
end else begin
{ For characters and whatever else, every module is a }
{ good module. If there's no module, i.e. the item is in }
{ the general inventory, that's not good. }
InGoodModule := ( Md <> Nil ) and IsSubCom( Md );
end;
end;
Function ScaleDP( DP , Scale , Material: Integer ): Integer;
{ Modify the damage point score DP for scale and construction. }
var
T: Integer;
begin
if DP > 0 then begin
if Scale < 1 then begin
if Material = NAV_Meat then DP := DP * 2
else DP := DP * 3;
end else begin
if Material = NAV_Meat then DP := DP * 4
else if Material = NAV_BioTech then DP := DP * 6
else if Material = NAV_Metal then DP := DP * 5;
if Scale > 1 then begin
for t := 2 to Scale do DP := DP * 5;
end;
end;
end;
ScaleDP := DP;
end;
Function UnscaledMaxDamage( Part: GearPtr ): Integer;
{ Return the maxdamage rating of this part, unadjusted for }
{ scale or construction. }
var
it: Integer;
begin
case Part^.G of
GG_Module: it := ModuleBaseDamage( Part );
GG_Mecha: it := -1;
GG_Character: it := CharBaseDamage(Part , CStat( Part , STAT_Body ) , CharaSkillRank( Part , NAS_Vitality ) );
GG_Cockpit: it := -1;
GG_Weapon: it := WeaponBaseDamage(Part);
GG_Ammo: it := AmmoBaseDamage(Part);
GG_MoveSys: it := MovesysBaseDamage(Part);
GG_Holder: it := 1;
GG_Sensor: it := SensorBaseDamage( Part );
GG_Support: it := SupportBaseDamage( Part );
GG_Shield: it := -1;
GG_ExArmor: it := -1;
GG_Treasure: it := 1;
GG_Prop: it := Part^.V;
GG_MetaTerrain: it := Part^.V;
GG_Tool: it := ToolDamage( Part );
GG_RepairFuel: it := 0;
GG_Consumable: it := 0;
GG_Modifier: it := 0;
GG_WeaponAddOn: it := 1;
GG_PowerSource: it := 1;
GG_Computer: it := 1;
GG_Software: it := 0;
GG_Harness: it := 0;
GG_Usable: it := 2;
else it := -1;
end;
UnscaledMaxDamage := it;
end;
Function GearMaxDamage(Part: GearPtr): Integer;
{Calculate how much damage this particular part can take}
{before being destroyed.}
var
it: Integer;
begin
{ Start with the unscaled mass damage. }
it := UnscaledMaxDamage( Part );
{Modify damage for scale and construction.}
it := ScaleDP( it , PART^.Scale , NAttValue( Part^.NA , NAG_GearOps , NAS_Material ) );
GearMaxDamage := it;
end;
Function UnscaledMaxArmor( Part: GearPtr ): Integer;
{ Calculate the unscaled armor value of this part. }
var
M: GearPtr;
it: Integer;
begin
{Error Check}
if Part = Nil then Exit(0);
{Modules and Cockpits have armor ratings.}
if Part^.G = GG_Module then begin
it := Part^.Stat[STAT_Armor];
if Part^.S = GS_Storage then it := it + Storage_Armor_Bonus;
end else if ( Part^.G = GG_Cockpit ) or ( Part^.G = GG_Support ) then it := Part^.Stat[STAT_Armor]
else if ( Part^.G = GG_Shield ) then it := Part^.V * 2
else if ( Part^.G = GG_ExArmor ) then it := Part^.V
else if ( Part^.G = GG_MetaTerrain ) then it := Part^.V
else if Part^.G = GG_Prop then it := Part^.V
else it := 0;
{ If this is an armored part, perform additional checks now. }
if it > 0 then begin
{ Modify armor for a GroundHugger or Arachnoid }
M := FindMaster( Part );
if ( M <> Nil ) and ( M^.G = GG_Mecha ) then begin
if M^.S = GS_GroundHugger then it := it + 2
else if M^.S = GS_Arachnoid then it := it + 1;
end;
end;
UnscaledMaxArmor := it;
end;
Function GearMaxArmor(Part: GearPtr): Integer;
{ Calculate how much armor protection PART has. This doesn't }
{ include any external equipped armor.}
var
it: Integer;
begin
it := UnscaledMaxArmor( Part );
if ( it > 0 ) and ( Part <> Nil ) then begin
{Modify it for scale.}
it := ScaleDP( it , Part^.Scale , NAV_Metal );
end;
GearMaxArmor := it;
end;
Function GenericName(Part: GearPtr): String;
{Determine the name of Part based upon}
{Part's type.}
begin
if Part = Nil then Exit( '' );
case Part^.G of
GG_Module: GenericName := ModuleName(Part);
GG_Mecha: GenericName := MechaName(Part);
GG_Character: GenericName := MsgString( 'CHARANAME' );
GG_Cockpit: GenericName := MsgString( 'CPITNAME' );
GG_Weapon: GenericName := WeaponName(Part);
GG_Ammo: GenericName := AmmoName(Part);
GG_MoveSys: GenericName := MoveSysName(Part);
GG_Holder: GenericName := HolderName( Part );
GG_Sensor: GenericName := SensorName( Part );
GG_Support: GenericName := SupportName( Part );
GG_Shield: GenericName := ShieldName( Part );
GG_ExArmor: GenericName := ArmorName( Part );
GG_Scene: GenericName := 'Scene ' + BStr( Part^.S );
GG_Treasure: GenericName := MsgString( 'SWAGNAME' );
GG_Prop: GenericName := MsgString( 'PROPNAME' );
GG_MetaTerrain: GenericName := MsgString( 'SCENERYNAME' );
GG_Tool: GenericName := MsgString( 'TOOLNAME' );
GG_RepairFuel: GenericName := RepairFuelName( Part );
GG_Consumable: GenericName := MsgString( 'FOODNAME' );
GG_WeaponAddOn: GenericName := MsgString( 'ACCNAME' );
GG_PowerSource: GenericName := MsgString( 'BATTERYNAME' );
GG_Computer: GenericName := MsgString( 'COMPUTERNAME' );
GG_Software: GenericName := MsgString( 'SOFTWARENAME' );
GG_Usable: GenericName := MsgString( 'USABLENAME_' + BStr( Part^.S ) );
GG_Modifier: GenericName := MsgString( 'MODIFIERNAME' );
GG_Set: GenericName := MsgString( 'SETNAME' );
else GenericName := {MsgString( 'UNKNOWNNAME' ) +} BStr( Part^.G ) + '/' + BStr( Part^.S ) + '/' + BStr( Part^.V );
end;
end;
Function GearName(Part: GearPtr): String;
{Determine the name of Part. If Part has a NAME attribute,}
{this is easy. If not, locate a default name based upon}
{Part's type.}
var
it: String;
begin
{Error check- make sure we aren't trying to find a name}
{for nothing.}
if Part = Nil then Exit( '' );
it := SAttValue(Part^.SA,'NAME');
if it = '' then it := GenericName( Part );
if Part^.g = GG_AbsolutelyNothing then it := '~!' + it;
GearName := it;
end;
Function FullGearName(Part: GearPtr): String;
{ Return the name + designation for this gear. }
var
it: String;
begin
it := SAttValue( Part^.SA , 'DESIG' );
if it <> '' then it := it + ' ';
FullGearName := it + GearName( Part );
end;
Function ComponentMass( Part: GearPtr ): Integer;
{Calculate the unscaled mas of PART, ignoring for the}
{moment its subcomponents.}
var
it,MAV: Integer;
begin
Case Part^.G of
GG_Module: it := ModuleBaseMass(Part);
GG_Cockpit: it := CockpitBaseMass(Part);
GG_Weapon: it := WeaponBaseMass(Part);
GG_Ammo: it := AmmoBaseMass(Part);
GG_MoveSys: it := MovesysBaseMass(Part);
GG_Holder: it := 1;
GG_Sensor: it := SensorBaseMass( Part );
GG_Support: it := SupportBaseMass( Part );
GG_Shield: it := ShieldBaseMass( Part );
GG_ExArmor: it := ArmorBaseMass( Part );
GG_Treasure: it := 1;
GG_Prop: it := Part^.V;
GG_MetaTerrain: it := Part^.V;
GG_Tool: it := ToolDamage( Part );
GG_Consumable: it := FoodMass( Part );
GG_WeaponAddOn: it := 1;
GG_PowerSource: it := Part^.V * 2;
GG_Computer: it := Part^.V * 2;
GG_Harness: if Part^.SubCom = Nil then it := 1 else it := 0;
GG_Usable: it := UsableBaseMass( Part );
{If a component type is not listed above, it has no mass.}
else it := 0
end;
{ Reduce component mass by mass adjustment value. }
MAV := NAttValue( Part^.NA , NAG_GearOps , NAS_MassAdjust );
it := it + MAV;
{ Mass adjustment can't result in a negative mass. }
if it < 0 then it := 0;
ComponentMass := it;
end;
Function MassScaleFactor( S: LongInt ): LongInt;
{ Return the mass scaling factor for this gear. }
{ As of right now, only scales 0, 1, and 2 will be covered. }
const
SFList: Array [0..2] of Integer = (1,200,1000);
begin
if S < 0 then S := 0
else if S > 2 then S := 2;
MassScaleFactor := SFList[ S ];
end;
Function ScaledComponentMass( Part: GearPtr ): LongInt;
{ Return the mass of this component, adjusted to SF:0 scale. }
begin
if Part = Nil then Exit( 0 );
ScaledComponentMass := ComponentMass( Part ) * MassScaleFactor( Part^.Scale );
end;
Function TrackMass( Part: GearPtr; Mode: Byte; AddThis: Boolean ): LongInt;
{Calculate the mass of this list of gears, including all}
{subcomponents. The mass returned will be adjusted to SF:0 units, so on }
{ the other end make sure you convert it back to the scale you want. }
var
it: LongInt;
begin
{Initialize the total Mass to 0.}
it := 0;
{Loop through all components.}
while Part <> Nil do begin
{Add the mass to the total.}
if AddThis then it := it + ScaledComponentMass(Part);
{Check for subcomponents and invcomponents.}
if Mode = GMMODE_AddAll then begin
if Part^.SubCom <> Nil then it := it + TrackMass(Part^.SubCom,Mode,True);
if Part^.InvCom <> Nil then it := it + TrackMass(Part^.InvCom,Mode,True);
end else if Mode = GMMODE_Intrinsic then begin
{ Calculate only the mass of pure SubComs. }
if Part^.SubCom <> Nil then it := it + TrackMass(Part^.SubCom,Mode,True);
end else begin
{ Calculate only the mass of InvComs. }
if Part^.SubCom <> Nil then it := it + TrackMass(Part^.SubCom,Mode,AddThis);
if Part^.InvCom <> Nil then it := it + TrackMass(Part^.InvCom,Mode,True);
end;
{Go to the next part in the series.}
Part := Part^.Next;
end;
{Return the value.}
TrackMass := it;
end;
Function GearMass( Master: GearPtr ): Integer;
{Calculate the mass of MASTER, including all of its}
{subcomponents.}
begin
{The formula to work out the total mass of this gear}
{is basic mass + SubCom mass + InvCom mass.}
if ( Master = Nil ) or ( Master^.G < 0 ) then begin
GearMass := 0;
end else begin
GearMass := ( ScaledComponentMass(Master) + TrackMass(Master^.SubCom,GMMODE_AddAll,True) + TrackMass(Master^.InvCom,GMMODE_AddAll,True) ) div MassScaleFactor( Master^.Scale );
end;
end;
Function IntrinsicMass( Master: GearPtr ): LongInt;
{ Return the mass of MASTER and all its subcomponents. Do not }
{ calculate the mass of inventory components. }
begin
if ( Master = Nil ) or ( Master^.G < 0 ) then begin
IntrinsicMass := 0;
end else begin
IntrinsicMass := ( ScaledComponentMass(Master) + TrackMass(Master^.SubCom,GMMODE_Intrinsic,True) ) div MassScaleFactor( Master^.Scale );
end;
end;
Function EquipmentMass( Master: GearPtr ): LongInt;
{ Return the mass of all inventory components of MASTER. Do not }
{ include the mass of intrinsic components. }
begin
if ( Master = Nil ) or ( Master^.G < 0 ) then begin
EquipmentMass := 0;
end else begin
EquipmentMass := ( TrackMass(Master^.SubCom,GMMODE_Equipment,False) + TrackMass(Master^.InvCom,GMMODE_Equipment,True) ) div MassScaleFactor( Master^.Scale );
end;
end;
Function MakeMassString( BaseMass: LongInt; Scale: Integer ): String;
{ Given a mass value and a scale, create a string to express }
{ said mass to the player. }
var
msg: String;
T: Integer;
begin
if Scale >= 2 then begin
for t := 3 to Scale do BaseMass := BaseMass * 5;
msg := BStr( BaseMass div 2 ) + '.' + BStr( ( BaseMass mod 2 ) * 5 ) + 't';
end else if Scale = 1 then begin
msg := BStr( BaseMass div 10 ) + '.' + BStr( BaseMass mod 10 ) + 't';
end else if Scale = 0 then begin
msg := BStr( BaseMass div 2 ) + '.' + BStr( ( BaseMass mod 2 ) * 5 ) + 'kg';
end else begin
msg := BStr( BaseMass ) + '!';
end;
MakeMassString := Msg;
end;
Function MassString( Master: GearPtr ): String;
{ Return a string describing how heavy this gear is, based upon its }
{ scale. }
var
BaseMass: LongInt;
begin
BaseMass := GearMass( Master );
MassString := MakeMassString( BaseMass , Master^.Scale );
end;
Function GearDepth( Part: GearPtr ): Integer;
{ Calculate the depth of PART. If PART is a root level component, }
{ depth is 0. }
var
D: Integer;
begin
{ Initialize D. }
D := 0;
{ Ascend up the structure to the root level. For each level }
{ we have to go up, increase D by one. }
while Part^.Parent <> Nil do begin
Part := Part^.Parent;
Inc( D );
end;
GearDepth := D;
end;
Function ComponentComplexity( Part: GearPtr ): Integer;
{ Return the basic complexity value of this part, and only }
{ this part. }
var
CC: Integer;
begin
if ( Part = Nil ) or ( Part^.G < 0 ) then begin
CC := 0;
end else begin
case Part^.G of
GG_Module: CC := ModuleComplexity( Part );
GG_ExArmor,GG_Shield: CC := ( Part^.V + 1 ) div 2;
GG_Weapon: CC := WeaponComplexity( Part );
GG_MoveSys,GG_PowerSource: CC := Part^.V;
GG_Computer: CC := Part^.V;
GG_Software: CC := 0;
GG_Support: CC := 0;
GG_Sensor: CC := SensorComplexity( Part );
GG_Harness: CC := Part^.V * 2;
GG_Usable: CC := UsableComplexity( Part );
else CC := 1;
end;
{ If the part is integral, and not a module, reduce complexity by 1 }
{ down to a minimum value of 1. }
if ( CC > 1 ) and ( Part^.G <> GG_Module ) and PartHasIntrinsic( Part , NAS_Integral ) then Dec( CC );
end;
ComponentComplexity := CC;
end;
Function SubComComplexity( Part: GearPtr ): Integer;
{ Return the overall complexity of all of PART's subcomponents. }
var
it: Integer;
S: GearPtr;
begin
it := 0;
S := Part^.SubCom;
while S <> Nil do begin
if S^.Scale >= Part^.Scale then begin
it := it + ComponentComplexity( S );
end else begin
Inc( it );
end;
S := S^.Next;
end;
SubComComplexity := it;
end;
Function IsLegalInvcom( Parent, Equip: GearPtr ): Boolean;
{ Check EQUIP to see if it can be installed as a sub-component }
{ of SLOT. Return TRUE if it can, FALSE if it can't. }
{ This procedure only checks to make sure the slot is legal; }
{ it doesn't check whether the slot is already occupied or }
{ anything else. }
begin
if ( Parent = Nil ) or ( Equip = Nil ) then begin
{ If either of the provided gears don't really exist, }
{ this can't very well be a legal installation, can it? }
IsLegalInvcom := False;
end else if Parent^.G < 0 then begin
{ Virtal slots can hold anything. }
IsLegalInvcom := True;
end else if IsMasterGear( Parent ) or ( Parent^.G = GG_MetaTerrain ) then begin
{ The inventory components of MASTER gears can hold just }
{ about anything, since they represent the "general }
{ inventory" from most RPGs. The only restrictions have }
{ to do with scale and weight. }
if Equip^.Scale > Parent^.Scale then IsLegalInvcom := False
else if Equip^.G = GG_MetaTerrain then IsLegalInvcom := False
else IsLegalInvcom := True;
end else if Equip^.Scale > Parent^.Scale then begin
{ Gears cannot equip items of a higher scale than themselves. }
IsLegalInvCom := False;
end else if AStringHasBString( SAttValue( Equip^.SA , 'TYPE' ) , 'CYBER' ) then begin
{ Gears marked as "cyber" can only be internally mounted. }
IsLegalInvcom := False;
end else if Parent^.G = GG_Holder then begin
{ Call the ghholder unit InvChecker to see what it says. }
IsLegalInvcom := IsLegalHolderInv( Parent , Equip );
end else if ( Parent^.G = GG_Weapon ) then begin
IsLegalInvcom := IsLegalWeaponInv( Parent , Equip );
end else if Parent^.G = GG_Module then begin
{ Call the ghmodule unit InvChecker to see what it says. }
if Equip^.G = GG_ExArmor then begin
IsLegalInvcom := IsLegalModuleInv( Parent , Equip ) and ArmorFItsMaster( Equip , FindMaster( Parent ) );
end else begin
IsLegalInvcom := IsLegalModuleInv( Parent , Equip );
end;
end else begin
{ No other slots may hold equipment. }
IsLegalInvcom := False;
end;
end;
Procedure CheckGearInv( Part: GearPtr );
{ Check through a gear's Inv components, and delete any illegal }
{ gears found. A gear is legal if it meets two requirements- }
{ it must be legal according to the IsLegalInvcom procedure above, }
{ and it must be the only gear with a given G value installed at }
{ this location. }
var
LG,LG2: GearPtr; { Loop Gear }
MG: GearPtr; { Multiplicity Gear }
N: Integer; { A number. That's all. }
begin
LG := Part^.InvCom;
while LG <> Nil do begin
{ We need to save the location of the next gear, }
{ since LG itself might get deleted. }
LG2 := LG^.Next;
if not IsLegalInvcom( Part , LG ) then begin
{ LG failed the legality check. Delete it. }
RemoveGear( Part^.InvCom , LG );
end else if Part^.G = GG_Holder then begin
{ Holders can only hold one item, regardless of type. }
if NumSiblingGears( Part^.InvCom ) > 1 then begin
RemoveGear( Part^.InvCom , LG );
end;
end else if ( Part^.G <> GG_MetaTerrain ) and not IsMasterGear( Part ) then begin
{ Perform the multiplicity test. }
N := 0;
MG := Part^.InvCom;
while MG <> Nil do begin
if MG^.G = LG^.G then Inc( N );
MG := MG^.Next;
end;
{ There's more than one gear here. Get rid of it. }
if N > 1 then RemoveGear( Part^.InvCom , LG );
end;
LG := LG2;
end;
end;
Function IsLegalSubcom( Parent, Equip: GearPtr ): Boolean;
{ Check EQUIP and see if it can be a legal subcomponent of Parent. }
{ The first rule is that EQUIP must be of a scale less than or }
{ equal to Parent; the second rule is that it must meet whatever }
{ conditions are set by Parent's type. }
{ Note that this procedure only checks the legality of installation; }
{ it does not do a multiplicity test or anything else. }
begin
if ( Parent = Nil ) or ( Equip = Nil ) then begin
{ If either of the provided gears don't really exist, }
{ this can't very well be a legal installation, can it? }
IsLegalSubcom := False;
end else if Parent^.G < 0 then begin
{ Virtal slots can hold anything. }
IsLegalSubcom := True;
end else if Equip^.Scale > Parent^.Scale then begin
{ Can't mount a gear of larger scale than the Parent. }
IsLegalSubcom := False;
end else begin
case Parent^.G of
GG_Mecha: IsLegalSubcom := IsLegalMechaSubCom( Parent, Equip );
GG_Module: IsLegalSubCom := IsLegalModuleSub( Parent, Equip );
GG_Character: IsLegalSubCom := IsLegalCharSub( Equip );
GG_Cockpit: IsLegalSubCom := IsLegalCPitSub( Parent , Equip );
GG_Shield: IsLegalSubCom := IsLegalShieldSub( Parent , Equip );
GG_ExArmor: IsLegalSubCom := IsLegalArmorSub( Equip );
GG_Weapon: IsLegalSubCom := IsLegalWeaponSub( Parent , Equip );
GG_Prop: IsLegalSubCom := True;
GG_MetaTerrain: IsLegalSubCom := True;
GG_WeaponAddOn: IsLegalSubCom := Equip^.G = GG_Weapon;
GG_Computer: IsLegalSubCom := IsLegalComputerSub( Parent , Equip );
GG_Harness: IsLegalSubCom := IsLegalHarnessSub( Equip );
GG_Tool: IsLegalSubCom := IsLegalToolSub( Equip );
else IsLegalSubcom := False
end;
end;
end;
Function MaximumInstancesAllowed( Slot: GearPtr; Equip_G,Equip_S: Integer ): Integer;
{ Return the maximum number of (G,S) gears that can be }
{ installed in SLOT, or 0 if as many as wanted can be installed. }
{ Note that the results of this function are undefined if the }
{ part cannot be legally installed in the slot in the first place. }