forked from jwvhewitt/gearhead-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheffects.pp
2653 lines (2270 loc) · 96.1 KB
/
effects.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 effects;
{ previosly attacker.pp }
{ This unit handles attack, defense, and spells in GearHead. }
{ Spells? What is this, a FRPG? Well, that's just how I usually }
{ describe "special effects" such as healing, status changes, etc. }
{ Eventually it may also describe psi powers and whatnot. }
{ This unit does not concern itself with UI, so requesting }
{ attacks and informing the user of their outcome }
{ has to be done elsewhere. The EFFECTS_History variable }
{ points to a list of SATTs describing the last processed }
{ effect in full. It's up to the calling procedure to pass }
{ this info on the user. }
{ I've been prettying up this unit for the eventual introduction }
{ of effects other than attacking. Getting rid of useless global }
{ history variables, combining code when appropriate, removing }
{ dependancy upon direct properties of gears... Still a long way }
{ to go before this unit can be called "elegant", but at least }
{ it's worlds better than pcaction.pp... }
{
GearHead: Arena, a roguelike mecha CRPG
Copyright (C) 2005 Joseph Hewitt
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
The full text of the LGPL can be found in license.txt.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
interface
uses gears,locale;
const
MOSMeasure = 5; { One Measure Of Success is gained for beating }
{ the opponent's defense roll by this many points. }
PenaltyPerDepth = 5; { Penalty for making called shots, per distance from root level. }
PenaltyPerScale = 4;
ClicksPerPenalty = 20; { For every 20dpr of a target's speed, there's a -1 modifier. }
StopPenalty = 3; { Stopped mecha are easier to hit. }
ImmobilePenalty = 15; { Broken down mecha are even easier. }
StopBonus = 3; { It's easier to aim if you're standing still. }
RunPenalty = 3; { It's harder to aim if you're traveling at full speed. }
Parry_Bonus = 3; { Bonus to parrying an attack. }
UnderwaterAttackPenalty = 3; { It's harder to aim if you're underwater. }
Non_Weapon_MOS_Penalty = 2; { Non-weapons are less effective against armor. }
{ This mostly applies to modules. }
FlyingPenalty = 3; { Penalty for firing at an airborne unit without AntiAir weapon. }
HighGroundBonus = 1; { Bonus for firing at a target lower than self. }
CritHitMinTar = 25; { Minimum target number for Spot Weakness rolls. }
LongRangePenalty = 3;
ShortRangeBonus = 2;
Has_Minimum_Range = 6; { Weapons with a range greater than this have a minimum useful range. }
{ Attacks against targets within this minimum range happen at a penalty. }
{ Animation directions are stored in the history list. }
{ An animation direction may require some additional information, }
{ as detailed below. }
SAtt_Anim_Direction = 'ANIM_';
GS_Shot = 1; { X1 Y1 Z1 X2 Y2 Z2 }
GS_DamagingHit = 2; { X Y Z }
GS_ArmorDefHit = 3; { X Y Z }
GS_Parry = 4; { X Y Z }
GS_Dodge = 5; { X Y Z }
GS_Backlash = 6; { X Y Z }
GS_AreaAttack = 7; { X Y Z }
{ Maximum length of line when adding list of destroyed parts. }
Damage_List_Text_Length = 170;
FX_DoDamage = 0;
FX_CauseStatusFX = 1;
FX_DoHealing = 2;
FX_Overload = 3;
var
{ The variables in this unit hold values which may then be }
{ examined by any calling procedures to determine the outcome }
{ of the attack. }
ATTACK_AttackRoll,ATTACK_HiDefRoll: Integer;
ATTACK_Error,ATTACK_ItHit,ATTACK_Dodge,ATTACK_Parry,ATTACK_Resist: Boolean;
ATTACK_DamageDone: Integer;
ATTACK_MOS: Integer; { Attack Margin Of Success }
ATTACK_NumberOfHits: Integer;
ATTACK_AttSkillRank,ATTACK_DefSkillRank: Integer;
ATTACK_AttackerDamage: Integer;
ATTACK_History: SAttPtr;
Function ReadyToFire( GB: GameBoardPtr; User,Weapon: GearPtr ): Boolean;
Function ArcCheck( X0,Y0,D0,X1,Y1,A: Integer ): Boolean;
Function ArcCheck( GB: GameBoardPtr; Master , Weapon: GearPtr; X,Y: Integer ): Boolean;
Function ArcCheck( GB: GameBoardPtr; Master , Weapon , Target: GearPtr ): Boolean;
Function RangeArcCheck( GB: GameBoardPtr; Master , Weapon: GearPtr; X,Y,Z: Integer ): Boolean;
Function RangeArcCheck( GB: GameBoardPtr; Master , Weapon , Target: GearPtr ): Boolean;
Function AttackSkillNeeded( Attacker: GearPtr ): Integer;
Function CalcTotalModifiers( gb: GameBoardPtr; Attacker,Target: GearPtr; AtOp: Integer; AtAt: String ): Integer;
Procedure DestroyTerrain( GB: GameBoardPtr; X,Y: Integer );
Function BlastRadius( GB: GameBoardPtr; Attacker: GearPtr; AList: String ): Integer;
Procedure Explosion( GB: GameBoardPtr; X0,Y0,DC,R: Integer );
Procedure DoAttack( GB: GameBoardPtr; Attacker,Target: GearPtr; X,Y,Z,AtOp,AMod: Integer);
Procedure HandleEffectString( GB: GameBoardPtr; Target: GearPtr; FX_String,FX_Desc: String );
implementation
uses ability,action,damage,gearutil,ghchars,ghmodule,ghguard,ghparser,
ghprop,ghsensor,ghsupport,ghweapon,movement,rpgdice,skilluse,texutil,
ghholder;
Type
AttackFlags = Record
CantCallShot: Boolean;
CanDodge,CanBlock,CanParry,CanResist,CanIntercept,CanECM: Boolean;
AtAt: String;
end;
EffectRequest = Record
FXName: String;
FXType: Integer;
Originator,Weapon,Target: GearPtr;
TX,TY: Integer;
FXDice,FXOption,FXSkill,FXMod: Integer;
AF: AttackFlags;
FXDesc: String;
end;
var
EFFECTS_Event_Order: Integer;
ATTACK_AMaster: GearPtr;
ATTACK_TMaster,ATTACK_TPilot: GearPtr;
ATTACK_TMasterOK: Boolean; { TRUE if master OK at start. }
ATTACK_TPilotOK: Boolean; { TRUE if pilot OK at start. }
ATTACK_TMasterMove: Boolean; { TRUE if master mobile at start. }
FX_Messages: SAttPtr;
Stencil: Array [ 1..XMax , 1..YMax ] of Boolean;
Procedure RecordAnnouncement( msg: String );
{ Record an announcememnt in the history list. }
begin
AddSAtt( ATTACK_History , 'ANNOUNCE_' + BStr( EFFECTS_Event_Order ) + '_' , msg );
end;
Procedure Add_Shot_Precisely( GB: GameBoardPtr; X0,Y0,Z0,X1,Y1,Z1: Integer );
{ Add a shot animation to the history list. }
var
msg: String;
begin
msg := BStr( GS_Shot ) + ' ' + BStr( X0 ) + ' ' + BStr( Y0 ) + ' ' + BStr( Z0 );
msg := msg + ' ' + BStr( X1 ) + ' ' + BStr( Y1 ) + ' ' + BStr( Z1 );
AddSAtt( ATTACK_History , SAtt_Anim_Direction + BStr( EFFECTS_Event_Order ) + '_' , msg );
end;
Procedure Add_Shot_Animation( GB: GameBoardPtr; Attacker , Target: GearPtr );
{ Add a shot animation to the history list. }
var
P0,P1: Point;
begin
Attacker := FindRoot( Attacker );
Target := FindRoot( Target );
P0 := GearCurrentLocation( Attacker );
P0.Z := MekAltitude( GB , FindRoot( Attacker ) );
P1 := GearCurrentLocation( Target );
P1.Z := MekAltitude( GB , FindRoot( Target ) );
Add_Shot_Precisely( GB , P0.X , P0.Y , P0.Z , P1.X , P1.Y , P1.Z );
end;
Procedure Add_Point_Animation( X,Y,Z: Integer; CMD: Integer );
{ Add a shot animation to the history list. }
var
msg: String;
begin
msg := BStr( cmd ) + ' ' + BStr( X ) + ' ' + BStr( Y ) + ' ' + BStr( Z );
AddSAtt( ATTACK_History , SAtt_Anim_Direction + BStr( EFFECTS_Event_Order ) + '_' , msg );
end;
Procedure Add_Mek_Animation( GB: GameBoardPtr; Target: GearPtr; CMD: Integer );
{ Add a shot animation to the history list. }
var
P: Point;
begin
{ Find the location of the target, and just pass that on to }
{ the point animation procedure above. }
Target := FindRoot( Target );
P := GearCurrentLocation( Target );
Add_Point_Animation( P.X , P.Y , MekAltitude( GB , Target ) , CMD );
end;
Procedure ClearAttackHistory;
{ Get rid of any history variables leftover from previous attacks. }
begin
DisposeSAtt( ATTACK_History );
EFFECTS_Event_Order := 0;
end;
Procedure INDICATE_Latest_Attack( GB: GameBoardPtr );
{ Take all the stuff from the attack history values, and store it in the history }
{ list. }
var
msg: String;
DP: SAttPtr;
begin
{ Msg always starts with the target's name. }
msg := PilotName( ATTACK_TMaster );
{ If a part can't take damage, don't record a damage announcement. }
if GearMaxDamage( ATTACK_TMAster ) = 0 then begin
Exit;
end else if ATTACK_Error then msg := msg + 'Error!'
else if ATTACK_ItHit then begin
if ATTACK_MOS > 3 then begin
msg := msg + SAttValue( FX_Messages , 'CFE_CritHit' );
end else begin
msg := msg + SAttValue( FX_Messages , 'CFE_NormHit' );
end;
{ indicate number of hits, if appropriate. }
if ATTACK_NumberOfHits > 1 then begin
msg := msg + BStr( ATTACK_NumberOfHits ) + SAttValue( FX_Messages , 'CFE_MultiHit' );
end;
{ indicate damage done. }
if ATTACK_DamageDone > 0 then begin
msg := msg + SAttValue( FX_Messages , 'CFE_Damage1' ) + BStr( ATTACK_DamageDone ) + SAttValue( FX_Messages , 'CFE_Damage2' );
msg := msg + '.';
{ Add the list of destroyed parts now. }
DP := Destroyed_Parts_List;
while ( DP <> Nil ) and ( Length( msg ) < Damage_List_Text_Length ) do begin
msg := msg + ' ' + DP^.Info + SAttValue( FX_Messages , 'CFE_Destroyed' );
DP := DP^.Next;
end;
end else begin
msg := msg + SAttValue( FX_Messages , 'CFE_NoDamage' );
end;
end else if ATTACK_Parry then begin
if ( ATTACK_AttSkillRank + 1 + Random( 8 ) ) < ATTACK_DefSkillRank then begin
msg := msg + SAttValue( FX_Messages , 'CFE_EasyParry' );
end else if ( ATTACK_AttSkillRank - 1 - Random( 8 ) ) > ATTACK_DefSkillRank then begin
msg := msg + SAttValue( FX_Messages , 'CFE_HardParry' );
end else begin
msg := msg + SAttValue( FX_Messages , 'CFE_Parry' );
end;
end else if ATTACK_Resist then begin
if ( ATTACK_AttSkillRank + 1 + Random( 8 ) ) < ATTACK_DefSkillRank then begin
msg := msg + SAttValue( FX_Messages , 'CFE_EasyResist' );
end else if ( ATTACK_AttSkillRank - 1 - Random( 8 ) ) > ATTACK_DefSkillRank then begin
msg := msg + SAttValue( FX_Messages , 'CFE_HardResist' );
end else begin
msg := msg + SAttValue( FX_Messages , 'CFE_Resist' );
end;
end else begin
if ( ATTACK_AttSkillRank + 1 + Random( 8 ) ) < ATTACK_DefSkillRank then begin
msg := msg + SAttValue( FX_Messages , 'CFE_EasyEvade' );
end else if ( ATTACK_AttSkillRank - 1 - Random( 8 ) ) > ATTACK_DefSkillRank then begin
msg := msg + SAttValue( FX_Messages , 'CFE_HardEvade' );
end else begin
msg := msg + SAttValue( FX_Messages , 'CFE_Evade' );
end;
end;
if ATTACK_TMasterOK and Destroyed(ATTACK_TMaster) then msg := msg + ' ' + GearName( ATTACK_TMaster ) + ' is destroyed!';
{ Gotta check that the attack hit, since if the DAMAGE procedure }
{ wasn't called the history variables might be holding leftover }
{ information. }
if ATTACK_TPilotOK and ATTACK_ItHit then begin
if DAMAGE_EjectRoll then begin
if DAMAGE_PilotDied then msg := msg + ' ' + GearName( ATTACK_TPilot ) + ' didn''t eject in time!'
else if DAMAGE_EjectOK then msg := msg + ' ' + GearName( ATTACK_TPilot ) + ' ejected!';
end else if Destroyed(ATTACK_TPilot) then msg := msg + ' ' + GearName( ATTACK_TPilot ) + ' died!';
end;
RecordAnnouncement( msg );
{ Add the correct animation. }
if ATTACK_Parry or ATTACK_Resist then begin
Add_Mek_Animation( GB , ATTACK_TMaster , GS_Parry );
end else if ATTACK_ItHit then begin
if ( ATTACK_DamageDone > 0 ) then begin
Add_Mek_Animation( GB , ATTACK_TMaster , GS_DamagingHit );
end else begin
Add_Mek_Animation( GB , ATTACK_TMaster , GS_ArmorDefHit );
end;
end else begin
Add_Mek_Animation( GB , ATTACK_TMaster , GS_Dodge );
end;
if ATTACK_AttackerDamage > 0 then begin
Add_Mek_Animation( GB , ATTACK_AMaster , GS_Backlash );
end;
end;
Procedure INDICATE_Attack_Effect( GB: GameBoardPtr; EffectDesc: String );
{ Indicate effect stuff here. }
var
msg: String;
DP: SAttPtr;
begin
{ Miscellaneous effect only reported if target suffered damage. }
if GearMaxDamage( ATTACK_TMAster ) = 0 then begin
Exit;
end else if ATTACK_ItHit and ( ATTACK_DamageDone > 0 ) then begin
{ Msg always starts with the target's name. }
msg := ReplaceHash( EffectDesc , PilotName( ATTACK_TMaster ) );
msg := ReplaceHash( msg , BStr( ATTACK_DamageDone ) );
{ Add the list of destroyed parts now. }
DP := Destroyed_Parts_List;
while ( DP <> Nil ) and ( Length( msg ) < Damage_List_Text_Length ) do begin
msg := msg + ' ' + DP^.Info + SAttValue( FX_Messages , 'CFE_Destroyed' );
DP := DP^.Next;
end;
if ATTACK_TMasterOK and Destroyed(ATTACK_TMaster) then msg := msg + ' ' + GearName( ATTACK_TMaster ) + ' is destroyed!';
if ATTACK_TPilotOK then begin
if DAMAGE_EjectRoll then begin
if DAMAGE_PilotDied then msg := msg + ' ' + GearName( ATTACK_TPilot ) + ' didn''t eject in time!'
else if DAMAGE_EjectOK then msg := msg + ' ' + GearName( ATTACK_TPilot ) + ' ejected!';
end else if Destroyed(ATTACK_TPilot) then msg := msg + ' ' + GearName( ATTACK_TPilot ) + ' died!';
end;
RecordAnnouncement( msg );
Add_Mek_Animation( GB , ATTACK_TMaster , GS_DamagingHit );
end;
if ATTACK_AttackerDamage > 0 then begin
Add_Mek_Animation( GB , ATTACK_AMaster , GS_Backlash );
end;
end;
Function InGeneralInventory( Part: GearPtr ): Boolean;
{ If in the general inventory, it may be thrown. }
begin
InGeneralInventory := IsInvCom( Part ) and ( Part^.Parent = FindMaster( Part ) );
end;
Function MustBeThrown( GB: GameBoardPtr; Master, Weapon: GearPtr; TX,TY: Integer ): Boolean;
{ Return TRUE if WEAPON must be thrown in order to hit TARGET. }
{ Return FALSE if WEAPON could be used normally, i.e. not thrown. }
{ A weapon will only be thrown if it could not be used against }
{ the target otherwise- this is because throwing a weapon is a }
{ pain in the arse. You've got to go pick it up afterwards. }
begin
if Weapon^.G = GG_Ammo then begin
{ If you're attacking with ammo, that better be a grenade. }
MustBeThrown := True;
end else if InGeneralInventory( Weapon ) then begin
{ If this weapon is in the general inventory, it must }
{ have been thrown. }
MustBeThrown := True;
end else begin
{ If the attack range is greater than the regular weapon }
{ range, then the weapon must have been thrown. }
MustBeThrown := ( ThrowingRange( GB , Master , Weapon ) > 0 ) and OnTheMap( TX , TY ) and ( Range( Master , TX , TY ) > WeaponRange( GB , Weapon ) );
end;
end;
Function ReadyToFire( GB: GameBoardPtr; User,Weapon: GearPtr ): Boolean;
{ Return TRUE if the gear in question is ready to perform an attack, }
{ or FALSE if it is currently unable to do so. }
{ Check to make sure that... }
{ 1) ATTACKER is a functional part. }
{ 2) ATTACKER is a part that can be used in attack. }
{ 3) ATTACKER has sufficient ammunition to attack. }
{ 4) COMTIME is greater or equal to the RECHARGE time. }
{ 5) ATTACKER is mounted in a usable limb. }
{ 6) ATTACKER's MASTER is the same as ATTACKER's ROOT. }
var
AttackOK: Boolean;
begin
{ This first check will return false if Weapon is nil, so I won't check here. }
{ Throwable weapons don't have to be in a good module- they can }
{ be in the general inventory. }
{ v0.909 - Added check for safety switch. }
if ( Weapon <> Nil ) and ( User <> Nil ) and ( ThrowingRange( GB, USer, Weapon ) > 0 ) then begin
AttackOK := PartActive( Weapon ) and ( NAttValue( Weapon^.NA , NAG_WeaponModifier , NAS_SafetySwitch ) = 0 );
end else begin
AttackOK := PartActive( Weapon ) and InGoodModule( Weapon ) and ( NAttValue( Weapon^.NA , NAG_WeaponModifier , NAS_SafetySwitch ) = 0 );
end;
if AttackOK then begin
{ Applicability Check }
if ( Weapon^.G = GG_Weapon ) then begin
{ Normally, all weapons may be used to attack. Duh. }
{ However, ballistic and missile weapons can't attack }
{ if they have no ammo left. }
if ( Weapon^.S = GS_Ballistic ) or ( Weapon^.S = GS_Missile ) then begin
if LocateGoodAmmo( Weapon ) = Nil then AttackOK := False;
end;
end else if Weapon^.G = GG_Module then begin
{ Only Arms, Legs, and Tails may be used. }
if ( Weapon^.S <> GS_Arm ) and ( Weapon^.S <> GS_Leg ) and ( Weapon^.S <> GS_Tail ) then begin
AttackOK := False;
end;
end else if Weapon^.G = GG_Ammo then begin
if Weapon^.S <> GS_Grenade then AttackOK := False;
if not InGeneralInventory( Weapon ) then AttackOK := False;
end else begin
{ No other parts may be used to attack. So, }
{ set AttackOK to False. }
AttackOK := False;
end;
{ ComTime Check }
if NAttValue( Weapon^.NA , NAG_WeaponModifier , NAS_Recharge ) > GB^.ComTime then AttackOK := False;
{ If yer piloting a mecha can't punch the other guy yourself Check }
if FindMaster( Weapon ) <> FindRoot( Weapon ) then AttackOK := False;
end;
ReadyToFire := AttackOK;
end;
Function ArcCheck( X0,Y0,D0,X1,Y1,A: Integer ): Boolean;
{ CHeck that point X1,Y1 falls within Arc A as relative to }
{ point X0,Y0 with direction D0. }
var
OK: Boolean;
begin
if A = ARC_360 then OK := True
else if A = ARC_F90 then begin
if CheckArc( X0 , Y0 , X1 , Y1 , D0 ) or CheckArc( X0 , Y0 , X1 , Y1 , ( D0 + 7 ) mod 8 ) then OK := True
else OK := False;
end else begin
{ ASSERT -> A is ARC_F180 }
if CheckArc( X0 , Y0 , X1 , Y1 , D0 ) or CheckArc( X0 , Y0 , X1 , Y1 , ( D0 + 7 ) mod 8 ) or CheckArc( X0 , Y0 , X1 , Y1 , ( D0 + 1 ) mod 8 ) or CheckArc( X0 , Y0 , X1 , Y1 , ( D0 + 6 ) mod 8 ) then OK := True
else OK := False;
end;
ArcCheck := OK;
end;
Function ArcCheck( GB: GameBoardPtr; Master , Weapon: GearPtr; X,Y: Integer ): Boolean;
{ Return TRUE if the target is in an appropriate fire arc for }
{ WEAPON, or FALSE otherwise. }
var
X0 , Y0 , D: Integer; { Position of the firer. }
A: Integer; { Range and Arc of the attack. }
begin
if ( Master = Nil ) or ( Weapon = Nil ) then Exit( False );
if Master^.Parent <> Nil then Master := FindRoot( Master );
X0 := NAttValue( Master^.NA , NAG_Location , NAS_X );
Y0 := NAttValue( Master^.NA , NAG_Location , NAS_Y );
D := NAttValue( Master^.NA , NAG_Location , NAS_D );
A := WeaponArc( Weapon );
{ Now check Range and Arc. }
ArcCheck := ArcCheck( X0 , Y0 , D , X , Y , A );
end;
Function ArcCheck( GB: GameBoardPtr; Master , Weapon , Target: GearPtr ): Boolean;
{ Return TRUE if the target is in an appropriate fire arc for }
{ WEAPON, or FALSE otherwise. }
var
X0 , Y0 , D , X , Y: Integer; { Position of the firer. }
A: Integer; { Range and Arc of the attack. }
begin
if ( Target = Nil ) or ( Master = Nil ) or ( Weapon = Nil ) then Exit( False );
if Target^.Parent <> Nil then Target := FindRoot( Target );
if Master^.Parent <> Nil then Master := FindRoot( Master );
X := NAttValue( Target^.NA , NAG_Location , NAS_X );
Y := NAttValue( Target^.NA , NAG_Location , NAS_Y );
X0 := NAttValue( Master^.NA , NAG_Location , NAS_X );
Y0 := NAttValue( Master^.NA , NAG_Location , NAS_Y );
D := NAttValue( Master^.NA , NAG_Location , NAS_D );
A := WeaponArc( Weapon );
{ Now check Range and Arc. }
ArcCheck := ArcCheck( X0 , Y0 , D , X , Y , A );
end;
Function RangeArcCheck( GB: GameBoardPtr; Master , Weapon: GearPtr; X,Y,Z: Integer ): Boolean;
{ Check the range, arc, and cover between the listed gear and the listed tile. }
{ Returns true if the shot can take place, false otherwise. }
var
X0,Y0,D,A: Integer;
rng: Integer; { Range and Arc of the attack. }
OK: Boolean;
begin
{ Calculate Range and Arc. }
rng := WeaponRange( GB , Weapon );
X0 := NAttValue( Master^.NA , NAG_Location , NAS_X );
Y0 := NAttValue( Master^.NA , NAG_Location , NAS_Y );
D := NAttValue( Master^.NA , NAG_Location , NAS_D );
A := WeaponArc( Weapon );
OK := ArcCheck( X0 , Y0 , D , X , Y , A );
{ If out of range, no shot is possible. }
if OK and ( Range( Master , X , Y ) > rng ) then begin
{ OK is false, unless the target is within throwing range. }
OK := ThrowingRange( GB , Master , Weapon ) >= Range( Master , X , Y );
end;
{ If Line of Sight is blocked, no shot is possible. }
if OK and ( CalcObscurement( X0 , Y0 , MekALtitude( GB , Master ) , X , Y , Z , gb ) = -1 ) then OK := False;
RangeArcCheck := OK;
end;
Function RangeArcCheck( GB: GameBoardPtr; Master , Weapon , Target: GearPtr ): Boolean;
{ Check the range, arc, and cover between the listed gear and the listed tile. }
{ Returns true if the shot can take place, false otherwise. }
var
X , Y: Integer; { Position of the firer. }
begin
{ Determine initial values for all the stuff. }
if Target = Nil then Exit( False );
if Target^.Parent <> Nil then Target := FindRoot( Target );
X := NAttValue( Target^.NA , NAG_Location , NAS_X );
Y := NAttValue( Target^.NA , NAG_Location , NAS_Y );
RangeArcCheck := RangeArcCheck( GB , Master , Weapon , X , Y , MekALtitude( GB , Target ) );
end;
Function RechargeTime( Attacker: GearPtr; AtOp: Integer ): Integer;
{ Return the modified recharge time for this weapon. }
var
WAO: GearPtr;
it: Integer;
begin
if Attacker^.G = GG_Weapon then begin
it := Attacker^.Stat[STAT_Recharge];
end else begin
it := 2;
end;
{ Modify for weapon token. }
WAO := Attacker^.InvCom;
while WAO <> Nil do begin
if ( WAO^.G = GG_WeaponAddOn ) and NotDestroyed( WAO ) then begin
it := it + WAO^.Stat[ STAT_Recharge ];
end;
WAO := WAO^.Next;
end;
if ( Attacker^.G = GG_Weapon ) and ( Attacker^.S = GS_BeamGun ) and ( AtOp > 0 ) then begin
{ Beamguns which use rapid fire take MUCH longer to recharge than normal. }
RechargeTime := 2 * ClicksPerRound div it;
end else begin
RechargeTime := ClicksPerRound div it;
end;
end;
Function ClearAttack( GB: GameBoardPtr; Attacker: GearPtr ; var AtOp: Integer ): Boolean;
{ This function sets up the weapon for performing an attack. }
{ It reduces ammo count by an appropriate amount. }
{ It sets the RECHARGE attribute. }
{ Return TRUE if everything is okay, FALSE if there's some reason }
{ why this attack can't take place. }
{ Note that this function does not do a range check. }
var
AttackOK: Boolean;
Ammo: GearPtr;
begin
{ First, make sure that this attack can even take place. }
{ Check to make sure that ATTACKER is active. }
AttackOK := ReadyToFire( GB , FindRoot( Attacker ) , Attacker );
if AttackOK and ( Attacker^.G = GG_Weapon ) then begin
{ Do an ammunition check for projectile weapons and missiles. }
if ( Attacker^.S = GS_Missile ) or (( Attacker^.S = GS_Ballistic ) and ( Attacker^.Stat[STAT_Magazine] > 0 )) then begin
{ Locate the ammo to be used. }
Ammo := LocateGoodAmmo( Attacker );
if Ammo <> Nil then begin
{ Reduce the ammo count by an appropriate amount. }
{ AtOp is the number of missiles being fired. }
{ If this goes over the number of missiles present, correct that problem. }
if ( AtOp > 0 ) then begin
if ( Ammo^.Stat[STAT_AmmoPresent] - NAttValue( Ammo^.NA , NAG_WeaponModifier , NAS_AmmoSpent ) ) < (AtOp + 1) then begin
AtOp := ( Ammo^.Stat[STAT_AmmoPresent] - NAttValue( Ammo^.NA , NAG_WeaponModifier , NAS_AmmoSpent ) ) - 1;
end;
end;
{ Do the actual ammo count thing here. }
AddNAtt( Ammo^.NA , NAG_WeaponModifier , NAS_AmmoSpent , AtOp + 1 );
end else begin
{ This weapon has no ammo. The attack cannot proceed. }
AttackOK := False;
end;
end;
end else if Attacker^.G = GG_Ammo then begin
{ Grenades don't get a choice what AtOp they use. }
AtOp := Attacker^.Stat[ STAT_BurstValue ];
end;
{ Set the recharge time now. }
if AttackOK then begin
SetNAtt( Attacker^.NA , NAG_WeaponModifier , NAS_Recharge , GB^.ComTime + RechargeTime( Attacker , AtOp ) );
end;
ClearAttack := AttackOK;
end;
Function AttackSkillNeeded( Attacker: GearPtr ): Integer;
{ Return the index number of the skill used to attack with this }
{ particular weapon. }
var
ASkill: Integer;
AMaster: GearPtr;
begin
{ The skills for human-scale and mecha-scale are set up in }
{ the same order, with the mecha skills being 1 to 5 and the }
{ personal skills being 6 to 10. So, just find the skill number }
{ based on ATTACKER's type, then add +5 if the master is a }
{ character instead of a mecha. }
if Attacker^.G = GG_Weapon then begin
if ( Attacker^.S = GS_Melee ) or ( Attacker^.S = GS_EMelee ) then begin
{ Use armed combat/weapons skill. }
ASkill := 3;
end else if ( Attacker^.S = GS_Ballistic ) or ( Attacker^.S = GS_BeamGun ) then begin
{ Use gunnery/small arms if DC is 10 or less, }
{ use artillery/heavy if DC is 11 or greater. }
if Attacker^.V <= 10 then begin
ASkill := 1;
end else begin
ASkill := 2;
end;
end else begin
{ Must be a missile launcher- use heavy/artillery skill. }
ASkill := 2;
end;
end else if Attacker^.G = GG_Ammo then begin
{ Grenades use Heavy Weapons/Artillery skill by }
{ default, but may redefine this freely. I did so }
{ to allow the creation of shurikens, cans of mace, }
{ and other derivitaves from the grenade code. }
ASkill := Attacker^.Stat[ STAT_GrenadeSkill ];
end else begin
{ Not a weapon- use Fighting/Martial Arts. }
ASkill := 4;
end;
{ If the master is a character, add +5 to the skill index. }
AMaster := FindMaster( Attacker );
if ( AMaster <> Nil ) and ( AMaster^.G = GG_Character ) then begin
ASkill := ASkill + 5;
end;
{ Return the value we found. }
AttackSkillNeeded := ASkill;
end;
Function AttemptShieldBlock(GB: GameBoardPtr; TMaster , Attacker: GearPtr; SkRoll: Integer ): Integer;
{ Attempt to block an attack using a shield. Return the defense }
{ roll result, or 0 if no shield could be found. }
var
DefGear: GearPtr;
DefSkill,DefRoll: Integer;
Procedure SeekShield( Part: GearPtr );
{ Seek a shield which is capable of parrying an attack. }
begin
while ( Part <> Nil ) do begin
if NotDestroyed( Part ) then begin
if ( Part^.G = GG_Shield ) and InGoodModule( Part ) then begin
if ( NAttValue( Part^.NA , NAG_WeaponModifier , NAS_Recharge ) <= GB^.ComTime ) and ( ( Attacker = Nil ) or ( Part^.Scale >= Attacker^.Scale ) ) then begin
if DefGear = Nil then DefGear := Part;
end;
end;
if ( Part^.SubCom <> Nil ) then SeekShield( Part^.SubCom );
if ( Part^.InvCom <> Nil ) then SeekShield( Part^.InvCom );
end;
Part := Part^.Next;
end;
end;
begin
{ Try to find a shield. }
DefGear := Nil;
DefRoll := 0;
SeekShield( TMaster^.SubCom );
{ If a shield is found, proceed with the defense roll... }
if DefGear <> Nil then begin
{ Find the appropriate skill value. }
if TMaster^.G = GG_Mecha then begin
{ For mecha, this will be Mecha Fighting }
DefSkill := 4;
end else begin
{ For characters, this will be Armed Combat }
DefSkill := 8;
end;
ATTACK_DefSkillRank := SkillValue( TMaster , DefSkill );
{ Set the recharge time for the shield. }
SetNAtt( DefGear^.NA , NAG_WeaponModifier , NAS_Recharge , GB^.ComTime + ( ClicksPerRound div 3 ) );
{ Give some skill-specific experience points. }
DoleSkillExperience( TMaster , DefSkill , XPA_SK_Basic );
{ Make the skill roll + Shield Bonus }
DefRoll := RollStep( ATTACK_DefSkillRank ) + DefGear^.Stat[ STAT_ShieldBonus ];
{ If the parry was successful, there will be some after-effects. }
if DefRoll >= SkRoll then begin
{ The shield is going to take damage from the hit, whether it was an }
{ energy shield or a beam shield- but beam shields only take damage }
{ from energy weapons. }
if ATtacker <> Nil then begin
if DefGear^.S = GS_EnergyShield then begin
if CanDamageBeamShield( Attacker ) then begin
DamageGear( GB , DefGear , Attacker , Attacker^.V , 0 , 1 , '' );
end;
end else begin
{ Physical shields take damage from everything. }
DamageGear( GB , DefGear , Attacker , Attacker^.V , 0 , 1 , '' );
end;
{ An energy shield will do damage back to any CC weapon that hits it. }
if ( DefGear^.S = GS_EnergyShield ) then begin
if ( Attacker^.G = GG_Module ) or ( Attacker^.S = GS_Melee ) then begin
ATTACK_AttackerDamage := ATTACK_AttackerDamage + DamageGear( GB , Attacker , DefGear , DefGear^.V , 0 , 1 , '' );
end;
end;
end;
end;
end;
AttemptShieldBlock := DefRoll;
end;
Function AttemptParry(GB: GameBoardPtr; TMaster , Attacker: GearPtr; SkRoll: Integer ): Integer;
{ Try to parry this attack, if it is in fact parryable. }
var
DefGear: GearPtr;
DefSkill,DefRoll: Integer;
Procedure SeekParryWeapon( Part: GearPtr );
{ Seek a weapon which is capable of parrying an attack. }
begin
while ( Part <> Nil ) do begin
if ( Part^.G = GG_Weapon ) and (( Part^.S = GS_Melee ) or ( Part^.S = GS_EMelee )) then begin
if ReadyToFire( GB , Nil , Part ) and InGoodModule( Part ) and ( ( Attacker = Nil ) or ( Part^.Scale >= Attacker^.Scale ) ) then begin
if DefGear = Nil then DefGear := Part
else if Part^.Stat[STAT_Accuracy] > DefGear^.Stat[STAT_Accuracy] then DefGear := Part;
end;
end;
if ( Part^.SubCom <> Nil ) then SeekParryWeapon( Part^.SubCom );
if ( Part^.InvCom <> Nil ) then SeekParryWeapon( Part^.InvCom );
Part := Part^.Next;
end;
end;
begin
DefRoll := 0;
{ Search for a usable CC weapon. }
DefGear := Nil;
SeekParryWeapon( TMaster^.SubCom );
{ If one was found, do the parry attempt. }
if DefGear <> Nil then begin
{ Make an attack roll to parry. }
DefSkill := AttackSkillNeeded( DefGear );
ATTACK_DefSkillRank := SkillValue( TMaster , DefSkill );
DefRoll := RollStep( ATTACK_DefSkillRank + Parry_Bonus ) + DefGear^.Stat[ STAT_Accuracy ];
{ Give some skill-specific experience points. }
DoleSkillExperience( TMaster , DefSkill , XPA_SK_Basic );
{ If the parry was successful, there will be some after-effects. }
if DefRoll >= SkRoll then begin
{ After a succeful parry, weapon is "tapped". }
DefSkill := 0;
ClearAttack( GB , DefGear , DefSkill );
{ If the parrying weapon is not an energy weapon, }
{ it will take damage from the parrying attempt. }
if Attacker <> Nil then begin
if ( DefGear^.S <> GS_EMelee ) then begin
if ( Attacker^.G = GG_Weapon ) and ( Attacker^.S = GS_EMelee ) then begin
DamageGear( GB , DefGear , Attacker , Attacker^.V , 0 , 1 , '' );
end else begin
DamageGear( GB , DefGear , Attacker , 1 , 0 , 1 , '' );
end;
{ If the parrying weapon is an energy weapon, then }
{ the attacker's weapon is going to take damage unless }
{ it too is an energy weapon. }
end else if ( Attacker^.G <> GG_Weapon ) or ( Attacker^.S <> GS_Emelee ) then begin
ATTACK_AttackerDamage := ATTACK_AttackerDamage + DamageGear( GB , Attacker , DefGear , DefGear^.V , 0 , 1 , '' );
end;
end;
end;
end;
{ Return the resultant defense roll. }
AttemptParry := DefRoll;
end;
Function AttemptIntercept(GB: GameBoardPtr; TMaster , Attacker: GearPtr; SkRoll: Integer ): Integer;
{ Try to intercept this attack. }
var
DefGear: GearPtr;
DefSkill,DefRoll: Integer;
Procedure SeekInterceptWeapon( Part: GearPtr );
{ Seek a weapon which is capable of intercepting an attack. }
begin
while ( Part <> Nil ) do begin
if ( Part^.G = GG_Weapon ) and HasAttackAttribute( WeaponAttackAttributes( Part ) , AA_Intercept ) then begin
if ReadyToFire( GB , Nil , Part ) and InGoodModule( Part ) and ( ( Attacker = Nil ) or ( Part^.Scale >= Attacker^.Scale ) ) then begin
if DefGear = Nil then DefGear := Part
else if Part^.Stat[STAT_Accuracy] > DefGear^.Stat[STAT_Accuracy] then DefGear := Part;
end;
end;
if ( Part^.SubCom <> Nil ) then SeekInterceptWeapon( Part^.SubCom );
if ( Part^.InvCom <> Nil ) then SeekInterceptWeapon( Part^.InvCom );
Part := Part^.Next;
end;
end;
begin
DefRoll := 0;
{ Search for a usable CC weapon. }
DefGear := Nil;
SeekInterceptWeapon( TMaster^.SubCom );
{ If one was found, do the parry attempt. }
if DefGear <> Nil then begin
{ Make an attack roll to parry. }
DefSkill := AttackSkillNeeded( DefGear );
ATTACK_DefSkillRank := SkillValue( TMaster , DefSkill );
DefRoll := RollStep( ATTACK_DefSkillRank + DefGear^.V ) + DefGear^.Stat[ STAT_Accuracy ] + DefGear^.Stat[ STAT_BurstValue ];
{ Give some skill-specific experience points. }
DoleSkillExperience( TMaster , DefSkill , XPA_SK_Basic );
{ If the parry was successful, there will be some after-effects. }
if DefRoll >= SkRoll then begin
{ After a succeful parry, weapon is "tapped". }
ClearAttack( GB , DefGear , DefSkill );
end;
end;
{ Return the resultant defense roll. }
AttemptIntercept := DefRoll;
end;
Function AttemptEWBlock(GB: GameBoardPtr; TMaster , Attacker: GearPtr; SkRoll: Integer ): Integer;
{ Try to stop this attack using Electronic Counter-Measures. }
var
DefGear: GearPtr;
DefRoll: Integer;
begin
DefRoll := 0;
{ Search for a usable CC weapon. }
DefGear := SeekActiveIntrinsic( TMaster , GG_Sensor , GS_ECM );
{ If one was found, do the parry attempt. }
if DefGear <> Nil then begin
{ Make an attack roll to block. }
ATTACK_DefSkillRank := SkillValue( TMaster , 17 );
DefRoll := RollStep( ATTACK_DefSkillRank + DefGear^.V - 5 );
{ Give some skill-specific experience points. }
DoleSkillExperience( TMaster , 17 , XPA_SK_Basic );
end;
{ Return the resultant defense roll. }
AttemptEWBlock := DefRoll;
end;
Function AttemptResist(GB: GameBoardPtr; TMaster: GearPtr ): Integer;
{ Attempt to resist damage using either the RESISTANCE or }
{ ELECTRONIC WARFARE skills, depending upon whether the target }
{ is a character or a mecha. }
begin
if TMaster^.G = GG_MEcha then begin
{ Mecha use ELECTRONIC WARFARE. }
ATTACK_DefSkillRank := SkillValue( TMaster , 17 );
DoleSkillExperience( TMaster , 17 , XPA_SK_Basic );
end else begin
{ Characters use RESISTANCE. }
ATTACK_DefSkillRank := SkillValue( TMaster , 36 );
DoleSkillExperience( TMaster , 36 , XPA_SK_Basic );
end;
{ Return the resultant defense roll. }
AttemptResist := RollStep( ATTACK_DefSkillRank );
end;
Function AttemptDefenses( GB: GameBoardPtr; TMaster,Attacker: GearPtr; SkRoll: Integer; AF: AttackFlags ): Integer;
{ The target has just been attacked. Roll any appropriate }
{ defenses. Return the highest defense roll. }
var
DefRoll,HiDefRoll: Integer;
begin
{ First, check to see if this attack will be ineffective. }
if HasAttackAttribute( AF.AtAt , AA_NoMetal ) and ( NAttValue( TMaster^.NA , NAG_GearOps , NAS_Material ) = NAV_Metal ) then begin
ATTACK_Dodge := True;
Exit( 256 );
end;
{ All attacks get a dodge attempt. }
{ Make the dodge roll, then dole appropriate experience. }
HiDefRoll := 0;
ATTACK_Dodge := False;
ATTACK_Parry := False;
ATTACK_Resist := False;
if AF.CanDodge then begin
if TMaster^.G = GG_MEcha then begin
{ Mecha use Mecha Piloting. }
ATTACK_DefSkillRank := SkillValue( TMaster , 5 );
DoleSkillExperience( TMaster , 5 , XPA_SK_Basic );
{ Adjust the dodge skill value for talents. }
if ( NAttValue( TMaster^.NA , NAG_Action , NAS_MoveMode ) = MM_Walk ) and HasTalent( TMaster , NAS_SureFooted ) then begin
ATTACK_DefSkillRank := ATTACK_DefSkillRank + 2;
end else if ( NAttValue( TMaster^.NA , NAG_Action , NAS_MoveMode ) = MM_Fly ) and HasTalent( TMaster , NAS_BornToFly ) then begin
ATTACK_DefSkillRank := ATTACK_DefSkillRank + 3;
end else if ( NAttValue( TMaster^.NA , NAG_Action , NAS_MoveMode ) = MM_Roll ) and HasTalent( TMaster , NAS_RoadHog ) then begin
ATTACK_DefSkillRank := ATTACK_DefSkillRank + 2;
end;