forked from jwvhewitt/gearhead-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdlmap.pp
1613 lines (1370 loc) · 55.3 KB
/
sdlmap.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 sdlmap;
{$MODE FPC}
{
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 SDL,SDL_ttf,sdlgfx,gears,gearutil,damage,locale,movement,ability,action,randmaps,effects,ghmecha,ui4gh,ghprop;
const
{ DISPLAYSHOT CONSTANTS }
SHOT_Hit = 0;
SHOT_Dodge = 1;
SHOT_Parry = 2;
{ This constant is used by stairs and other portals. If a value }
{ is addigned to it, the player character should appear on that }
{ terrain after leaving the current level. }
SCRIPT_Terrain_To_Seek: Integer = 0;
Function TeamColor( GB: GameBoardPtr; G: GearPtr ): TSDL_Color;
Function OnTheScreen( X , Y: Integer ): Boolean;
Function OnTheScreen( Mek: GearPtr ): Boolean;
Function NeedsRecentering( X,Y: Integer ): Boolean;
Function GearSpriteName( GB: GameBoardPtr; M: GearPtr ): String;
Function TeamColorString( GB: GameBoardPtr; M: GearPtr ): String;
Procedure RedrawTile( gb: GameBoardPtr; X,Y: Integer );
procedure RedrawTile( gb: GameBoardPtr; Mek: GearPtr );
procedure IndicateTile( GB: GameBoardPtr; X , Y , Z: Integer; Primary: Boolean );
procedure IndicateTile( GB: GameBoardPtr; Mek: GearPtr; Primary: Boolean );
procedure IndicateTile( GB: GameBoardPtr; X,Y: Integer );
Procedure MouseAtTile( GB: GameBoardPtr; X,Y: Integer );
Procedure RevealMek( GB: GameBoardPtr; Mek,Spotter: GearPtr );
Procedure VisionCheck( GB: GameBoardPtr; Mek: GearPtr );
Procedure DeployMek( GB: GameBoardPtr; Mek: GearPtr; PutOnMap: Boolean );
Procedure DeployMek( GB: GameBoardPtr; Mek,Pilot: GearPtr; Team: Integer );
Function LocateMekByUID( GB: GameBoardPtr; UID: Integer ): GearPtr;
Function TimeString( ComTime: LongInt ): String;
Procedure SDLCombatDisplay( GB: GameBoardPtr );
Procedure FocusOnMek( GB: GameBoardPtr; Mek: GearPtr );
Function DisplayEffectAnimations( GB: GameBoardPtr; N: Integer ): Boolean;
Procedure DisplayConsoleHistory( GB: GameBoardPtr );
Procedure WriteCampaign( Camp: CampaignPtr; var F: Text );
Function ReadCampaign( var F: Text ): CampaignPtr;
Function ProcessMovement( GB: GameBoardPtr; Mek: GearPtr ): Boolean;
Procedure PrepOpening;
Procedure RedrawOpening;
Function ScreenToMap( X,Y: Integer ): Point;
Function MouseMapPos: Point;
Procedure BeginTurn( GB: GameBoardPtr; M: GearPtr );
Procedure InitMapDisplay( GB: GameBoardPtr; PC: GearPtr );
Procedure FinalizeMapDisplay;
implementation
uses texutil,menugear,ghchars,sdlinfo;
Type
Overlay_Description = Record
Sprite: SensibleSpritePtr;
F: Integer; { The frame to be displayed. }
SubIcon: Integer; { Substitute icon to show on map border. }
UseAlpha: Boolean; { Use alpha blending as appropriate. }
name: String; { if NAMES_ABOVE_HEADS, print this. }
end;
const
{ This array tells whether or not a given terrain type requires an overlay. }
Terrain_Toupee: Array [1..NumTerr] of Byte = (
0, 1, 2, 3, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 4, 0,
3, 3, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
0, 0
);
NumThinWalls = 8;
ThinWall_Earth = 1;
ThinWall_RustySteel = 2;
ThinWall_Stone = 3;
ThinWall_Industrial = 4;
ThinWall_Residential = 5;
ThinWall_Wood = 6;
ThinWall_Default = 7;
ThinWall_Fortress = 8;
Terrain_Image: Array [1..NumTerr] of SmallInt = (
1, 2, 3, 4, 5, 6, 7, 8, 9,10,
11,12,-5,14,-3, 16,17,18,19,20,
21,22,-Thinwall_Default,24,25, 26,-ThinWall_Wood,28,-ThinWall_RustySteel,30,
-1,32,-ThinWall_Fortress,34,-4, 36,37,38,39,40,
41,42
);
HalfTileWidth = 32;
HalfTileHeight = 16;
OriginX: LongInt = 80; { These constants tell what tile is being }
OriginY: LongInt = -260; { displayed in the upper left corner of the }
{ map area. }
Terrain_Sprite_Name = 'big_terrain.png';
Meta_Terrain_Sprite_Name = 'meta_terrain.png';
Terrain_Toupee_Sprite_Name = 'iso_64b.png';
Targeting_Srpite_Name = 'target64.png';
Items_Sprite_Name = 'default_items.png';
Default_Wreckage = 1;
{ Default_Dead_Thing = 2;}
Default_Dead_Thing = 5;
Default_Shadow = 3;
Default_Unknown = 4;
DefaultMaleSpriteName = 'cha_m_citizen.png';
DefaultFemaleSpriteName = 'cha_f_citizen.png';
DefaultMaleSpriteHead = 'cha_m_';
DefaultFemaleSpriteHead = 'cha_f_';
DefaultNonbinarySpriteHead = 'cha_*_';
Strong_Hit_Sprite_Name = 'blast64.png';
Weak_Hit_Sprite_Name = 'nodamage64.png';
Parry_Sprite_Name = 'misc_parry.png';
Miss_Sprite_Name = 'misc_miss.png';
FROZEN_MAP_CONTINUE = 1;
FROZEN_MAP_SENTINEL = -1;
LowAlt = -3; { Lowest altitude to render. }
HiAlt = 5; { Highest altitude to render. }
Altitude_Height = 20; { Pixel height of each altitude layer. }
NumOverlayLayers = 7;
NumConstantLayers = 6;
OVERLAY_Terrain = 0;
OVERLAY_ThinWall = 1;
OVERLAY_Shadow = 2;
OVERLAY_Item = 3;
OVERLAY_Metaterrain = 4;
OVERLAY_Master = 5;
OVERLAY_Toupee = 6;
OVERLAY_Image = 7;
SI_Ally = 3;
SI_Neutral = 2;
SI_Enemy = 1;
NumOMM = 16;
OM_North = 1;
OM_East = 2;
OM_South = 4;
OM_West = 3;
Map_Mid_X = 285;
Map_Mid_Y = 229;
var
OVERLAY_MAP: Array [ 1..XMax, 1..YMax, LowAlt..HiAlt, 0..NumOverlayLayers ] of Overlay_Description;
MINI_MAP: Array [1..XMax, 1..YMax] of Byte;
OFF_MAP_MODELS: Array [1..4,0..NumOMM] of Integer;
Terrain_Sprite,Meta_Terrain_Sprite,Terrain_Toupee_Sprite,Targeting_Srpite,Items_Sprite: SensibleSpritePtr;
Strong_Hit_Sprite,Weak_Hit_Sprite,Parry_Sprite,Miss_Sprite,Water_Sprite1,Water_Sprite2: SensibleSpritePtr;
Thin_wall_Cap: SensibleSpritePtr;
hill_1,hill_2,hill_3: SensibleSpritePtr;
Off_Map_Model_Sprite: SensibleSpritePtr;
Mini_Map_Sprite: SensibleSpritePtr;
Door_Sprite: SensibleSpritePtr;
Thin_Wall_Sprites: Array [1..NumThinWalls] of SensibleSpritePtr;
Opening_Last_Anim_Phase: Uint32;
Opening_X,Opening_Y: Integer;
Opening_Phase,Opening_Count: Integer;
ComDisplay_PC: GearPtr;
MoreText_GB: GameBoardPtr;
Procedure ClearOverlayLayer( L: Integer );
{ Clear sprite descriptions from the provided overlay layer. }
var
X,Y,Z: Integer;
begin
for X := 1 to XMax do begin
for Y := 1 to YMax do begin
for Z := LowAlt to HiAlt do begin
Overlay_Map[ X , Y , Z , L ].Sprite := Nil;
Overlay_Map[ X , Y , Z , L ].SubIcon := 0;
Overlay_Map[ X , Y , Z , L ].UseAlpha := False;
Overlay_Map[ X , Y , Z , L ].Name := '';
end;
end;
end;
end;
Procedure AddInstantOverlay( X,Y,Z,L,F: Integer; SS: SensibleSpritePtr );
{ Add an overlay image safely to the display. }
begin
if not OnTheMap( X , Y ) then Exit;
if ( Z < LowAlt ) or ( Z > HiAlt ) then Exit;
if ( L < 0 ) or ( L > NumOverlayLayers ) then Exit;
Overlay_MAP[ X , Y , Z , L ].Sprite := SS;
Overlay_MAP[ X , Y , Z , L ].F := F;
end;
Procedure AddOverlayIfClear( X,Y,Z,L,F: Integer; SS: SensibleSpritePtr );
{ If the requested overlay slot is empty, fill it. Otherwise leave it alone. }
begin
if not OnTheMap( X , Y ) then Exit;
if Overlay_Map[ X , Y , Z , L ].Sprite = Nil then AddInstantOverlay( X,Y,Z,L,F,SS );
end;
Procedure AddOverlay( X,Y,Z,L: Integer; Name,Color,GName: String; W,H,F: Integer );
{ Add an overlay image safely to the display. }
var
SS: SensibleSpritePtr;
begin
if not OnTheMap( X , Y ) then Exit;
if ( Z < LowAlt ) or ( Z > HiAlt ) then Exit;
if ( L < 0 ) or ( L > NumOverlayLayers ) then Exit;
SS := ConfirmSprite( Name , Color , W , H );
Overlay_MAP[ X , Y , Z , L ].Sprite := SS;
Overlay_MAP[ X , Y , Z , L ].F := F;
Overlay_MAP[ X , Y , Z , L ].Name := GName;
end;
Function TeamColor( GB: GameBoardPtr; G: GearPtr ): TSDL_Color;
{ Select a good color based upon the team this }
{ gear belongs to. }
var
color: TSDL_Color;
T: LongInt;
begin
if ( G = Nil ) or ( GB = Nil ) then begin
{ No gear provided - Neutral Gray. }
color := NeutralGrey;
end else if not GearOperational( G ) then begin
{ Nonfunctioning gear. Color = DarkGrey. }
color := DarkGrey;
end else begin
T := NAttValue( G^.NA , NAG_Location , NAS_Team );
if T = NAV_DefPlayerTeam then begin
{ Player team. Color = Blue. }
color := PlayerBlue;
end else if AreEnemies( GB , NAV_DefPlayerTeam , T ) then begin
{ Enemy team. Color = Red. }
color := EnemyRed;
end else if AreAllies( GB , NAV_DefPlayerTeam , T ) then begin
{ Ally team. Color = Purple. }
color := AllyPurple;
end else begin
{ Neutral team. Color = Brown. }
color := NeutralBrown;
end;
end;
TeamColor := Color;
end;
Function RelativeX( X,Y: Integer ): LongInt;
{ Return the relative position of tile X,Y. The UpLeft corner }
{ of tile [1,1] is the origin of our display. }
begin
RelativeX := ( (X-1) * HalfTileWidth ) - ( (Y-1) * HalfTileWidth );
end;
Function ScreenX( X,Y: Integer ): LongInt;
{ Return the screen coordinates of map column X. }
begin
ScreenX := RelativeX( X , Y ) + ZONE_Map.X + OriginX;
end;
Function RelativeY( X,Y: Integer ): LongInt;
{ Return the relative position of tile X,Y. The UpLeft corner }
{ of tile [1,1] is the origin of our display. }
begin
RelativeY := ( (Y-1) * HalfTileHeight ) + ( (X-1) * HalfTileHeight );
end;
Function ScreenY( X,Y: Integer ): Integer;
{ Return the screen coordinates of map row Y. }
begin
ScreenY := RelativeY( X , Y ) + ZONE_Map.Y + OriginY;
end;
Function OnTheScreen( X , Y: Integer ): Boolean;
{ This function returns TRUE if the specified point is visible }
{ on screen, FALSE if it isn't. }
var
SX,SY: LongInt; { Find Screen X and Screen Y and see if it's in the map area. }
begin
SX := ScreenX( X , Y );
SY := ScreenY( X , Y );
if ( SX >= ( ZONE_Map.X - 64 ) ) and ( SX <= (ZONE_Map.X+ZONE_Map.w + 64) ) and ( SY >= ( ZONE_Map.Y - 64 ) ) and ( SY <= (ZONE_Map.Y + ZONE_Map.h + 64) ) then begin
OnTheScreen := True;
end else begin
OnTheScreen := False;
end;
end;
Function OnTheScreen( Mek: GearPtr ): Boolean;
{ Check to see whether or not the specified mek is visible on screen. }
begin
OnTheScreen := OnTheScreen( NAttValue( Mek^.NA , NAG_Location , NAS_X ) , NAttValue( Mek^.NA , NAG_Location , NAS_Y ) );
end;
Procedure RecenterDisplay( X , Y: Integer );
{ Change the display so that point X,Y will be on screen. }
begin
OriginX := ( ZONE_Map.w div 2 ) - RelativeX( X , Y ) - 32;
OriginY := ( ZONE_Map.h div 2 ) - RelativeY( X , Y ) - 64;
end;
Function NeedsRecentering( X,Y: Integer ): Boolean;
{ Check point X,Y to see whether or not the screen needs to be }
{ centered upon it. }
begin
NeedsRecentering := False;
end;
Procedure DrawOffMap( Quad,N: Integer );
{ Draw an off-map model as indicated by the OFF_MAP_MODEL array. }
var
MyDest: TSDL_Rect;
begin
if Quad = OM_East then begin
MyDest.Y := ZONE_Map.Y + ( ZONE_Map.H * ( N + 1 ) ) div ( NumOMM + 2 );
MyDest.X := ZONE_Map.X + ZONE_Map.W - 16;
end else if Quad = OM_West then begin
MyDest.Y := ZONE_Map.Y + ( ZONE_Map.H * ( N + 1 ) ) div ( NumOMM + 2 );
MyDest.X := ZONE_Map.X + 8;
end else if Quad = OM_South then begin
MyDest.X := ZONE_Map.X + ( ( ZONE_Map.W * ( N + 1 ) ) div ( NumOMM + 2 ) );
MyDest.Y := ZONE_Map.Y + 8;
end else begin
MyDest.X := ZONE_Map.X + ( ( ZONE_Map.W * ( N + 1 ) ) div ( NumOMM + 2 ) );
MyDest.Y := ZONE_Map.Y + ZONE_Map.H - 16;
end;
DrawSprite( Off_Map_Model_Sprite , MyDest , OFF_MAP_MODELS[ Quad , N ] - 1 + ( Animation_Phase div 5 mod 2 ) * 3 );
end;
Procedure RenderMap;
{ Display the map and all its contents in the correct screen zone, }
{ but don't do a Flip afterwards. }
var
X,Y,Z,T,Quad: Integer;
MyDest: TSDL_Rect;
begin
{ Set the clip area. }
ZONE_Map.X := 0;
ZONE_Map.Y := 0;
ZONE_Map.W := Game_Screen^.W;
ZONE_Map.H := Game_Screen^.H;
ClrZone( ZONE_Map );
SDL_SetClipRect( Game_Screen , @ZONE_Map );
{ Clear the OFF_MAP_MODELS. }
for X := 1 to 4 do begin
for Y := 0 to NumOMM do begin
OFF_MAP_MODELS[ X , Y ] := 0;
end;
end;
{ Go through each tile on the map, displaying terrain and }
{ other contents. }
for X := 1 to XMax do begin
for Y := 1 to YMax do begin
if OnTheScreen( X , Y ) then begin
for Z := LowAlt to HiAlt do begin
for t := 0 to NumOverlayLayers do begin
if OVERLAY_MAP[ X ,Y , Z , T ].Sprite <> Nil then begin
MyDest.X := ScreenX( X , Y );
MyDest.Y := ScreenY( X , Y ) - Altitude_Height * Z;
if OVERLAY_MAP[ X ,Y , Z , T ].Sprite^.H > 64 then MyDest.Y := MyDest.Y - 32;
if Use_Alpha_Blending and OVERLAY_MAP[ X ,Y , Z , T ].UseAlpha and ( Abs( MyDest.Y - Map_Mid_Y ) < 64 ) and ( Abs( MyDest.X - Map_Mid_X ) < 128 ) then begin
DrawAlphaSprite( OVERLAY_MAP[ X ,Y , Z , T ].Sprite , MyDest , OVERLAY_MAP[ X ,Y , Z , T ].F );
end else begin
DrawSprite( OVERLAY_MAP[ X ,Y , Z , T ].Sprite , MyDest , OVERLAY_MAP[ X ,Y , Z , T ].F );
end;
if ( OVERLAY_MAP[ X ,Y , Z , T ].name <> '' ) and NAMES_ABOVE_HEADS then begin
MyDest.X := ScreenX( X , Y ) + HalfTileWidth;
MyDest.Y := ScreenY( X , Y ) - Altitude_Height * Z - 10;
QuickTinyText( OVERLAY_MAP[ X ,Y , Z , T ].name , MyDest , StdWhite );
end;
end;
end;
end; { For Z... }
end else if OVERLAY_MAP[ X , Y , 0 , OVERLAY_Master ].SubIcon > 0 then begin
{ This image is off the map, but has a substitute image }
{ so it should be indicated on the edge. }
{ Add a note to the OFF_MAP_MODELS array. }
{ Figure out its relative coordinates, with the center of the map }
{ as the origin. }
MyDest.X := ScreenX( X , Y ) - ( ZONE_Map.X + ZONE_Map.W div 2 );
MyDest.Y := ScreenY( X , Y ) - ( ZONE_Map.Y + ZONE_Map.H div 2 );
{ Use W to save the segment total length, and H to store the }
{ relative length. }
Quad := 1;
if MyDest.Y <= MyDest.X then Quad := Quad + 1;
if MyDest.Y <= -MyDest.X then Quad := Quad + 2;
if ( Quad = 1 ) or ( Quad = 4 ) then begin
MyDest.W := Abs( MyDest.Y ) * 2;
MyDest.H := MyDest.X + Abs( MyDest.Y );
end else begin
MyDest.W := Abs( MyDest.X ) * 2;
MyDest.H := MyDest.Y + Abs( MyDest.X );
end;
OFF_MAP_MODELS[ Quad , ( MyDest.H * NumOMM ) div MyDest.W ] := OVERLAY_MAP[ X , Y , 0 , OVERLAY_Master ].SubIcon;
end; { if OnTheScreen... }
end;
end;
{ Display the OFF_MAP_MODELS along the appropriate map edges. }
for t := 0 to NumOMM do begin
if Off_Map_Models[ OM_North , T ] > 0 then DrawOffMap( OM_North , T );
if Off_Map_Models[ OM_South , T ] > 0 then DrawOffMap( OM_South , T );
if Off_Map_Models[ OM_West , T ] > 0 then DrawOffMap( OM_West , T );
if Off_Map_Models[ OM_East , T ] > 0 then DrawOffMap( OM_East , T );
end;
{ Display the MINI_MAP }
if Display_Mini_Map then begin
for x := 1 to XMax do begin
for y := 1 to YMax do begin
MyDest.X := ZONE_Map.X + 8 + X*3;
MyDest.Y := ZONE_Map.Y + 8 + Y*3;
if ( Mini_Map[ X , Y ] > 0 ) and ( Mini_Map[ X , Y ] < 10 ) then begin
DrawSprite( Mini_Map_Sprite , MyDest , Mini_Map[ X , Y ] + ( Animation_Phase div 5 mod 2 ) );
end else begin
DrawSprite( Mini_Map_Sprite , MyDest , Mini_Map[ X , Y ] );
end;
end;
end;
end;
{ Restore the clip area. }
SDL_SetClipRect( Game_Screen , Nil );
end;
Function GearSpriteName( GB: GameBoardPtr; M: GearPtr ): String;
{ Locate the sprite name for this gear. If no sprite name is defined, }
{ set the default sprite name for the gear type & store it as a string }
{ attribute so we won't need to do this calculation later. }
const
FORM_DEFAULT: Array [1..NumForm] of String = (
'btr_buruburu.png','zoa_scylla.png','ghu_ultari.png',
'ara_kojedo.png', 'aer_wraith.png', 'orn_wasp.png',
'ger_harpy.png', 'aer_bluebird.png', 'gca_rover.png'
);
mini_sprite = 'cha_pilot.png';
var
it: String;
FList: SAttPtr;
gen: Integer;
begin
{ If this model is an out-of-scale character, return the mini-sprite. }
if ( M^.G = GG_Character ) and (GB <> Nil) and ( M^.Scale < GB^.Scale ) then Exit( mini_sprite );
it := SAttValue( M^.SA , 'SDL_SPRITE' );
if it = '' then begin
if M^.G = GG_Character then begin
gen := NAttValue( M^.NA , NAG_CharDescription , NAS_Gender );
if gen = NAV_Male then begin
it := DefaultMaleSpriteHead;
end else if gen = NAV_Female then begin
it := DefaultFemaleSpriteHead;
end else begin
it := DefaultNonbinarySpriteHead;
end;
it := it + LowerCase( SAttValue( M^.SA , 'JOB' ) ) + '.*';
FList := CreateFileList( Graphics_Directory + it );
if FList <> Nil then begin
it := SelectRandomSAtt( FList )^.Info;
DisposeSAtt( FList );
end else begin
if gen = NAV_Male then begin
it := DefaultMaleSpriteName;
end else if gen = NAV_Female then begin
it := DefaultFemaleSpriteName;
end else if random(2) = 1 then it := DefaultMaleSpriteName
else it := DefaultFemaleSpriteName;
end;
end else if ( M^.G = GG_Mecha ) and ( M^.S >= 0 ) and ( M^.S < NumForm ) then begin
it := FORM_DEFAULT[ M^.S + 1 ];
end else begin
it := Items_Sprite_Name;
end;
SetSAtt( M^.SA , 'SDL_SPRITE <' + it + '>' );
end;
GearSpriteName := it;
end;
Function TeamColorString( GB: GameBoardPtr; M: GearPtr ): String;
{ Determine the color string for this model. }
var
it: String;
T: Integer;
Team: GearPtr;
begin
it := SAttValue( M^.SA , 'SDL_COLORS' );
if ( it = '' ) and ( GB <> Nil ) then begin
T := NAttValue( M^.NA , NAG_Location , NAS_Team );
Team := LocateTeam( GB , T );
if Team <> Nil then it := SAttValue( Team^.SA , 'TEAM_COLORS' );
if it = '' then begin
if M^.G = GG_Character then begin
if T = NAV_DefPlayerTeam then begin
it := '66 121 179';
end else if AreEnemies( GB , T , NAV_DefPlayerTeam ) then begin
it := '180 10 120';
end else if AreAllies( GB , T , NAV_DefPlayerTeam ) then begin
it := '66 121 119';
end else begin
it := '175 175 171';
end;
end else begin
if T = NAV_DefPlayerTeam then begin
it := '66 121 179 210 215 80 205 25 0';
end else if AreEnemies( GB , T , NAV_DefPlayerTeam ) then begin
it := '180 10 120 125 125 125 170 205 75';
end else if AreAllies( GB , T , NAV_DefPlayerTeam ) then begin
it := '66 121 119 190 190 190 0 205 0';
end else begin
it := '175 175 171 100 100 120 0 200 200';
end;
end;
end;
if M^.G = GG_Character then begin
it := it + ' ' + RandomColorString( CS_Skin ) + ' ' + RandomColorString( CS_Hair );
end;
SetSAtt( M^.SA , 'SDL_COLORS <' + it + '>' );
end else if it = '' then begin
it := RandomColorString(CS_PrimaryMecha)+' '+RandomColorString(CS_SecondaryMecha)+' '+RandomColorString(CS_Detailing);
SetSAtt( M^.SA , 'SDL_COLORS <' + it + '>' );
end;
TeamColorString := it;
end;
procedure NFDisplayMap( gb: GameBoardPtr );
{ Actually display the map. }
Function EffectiveWall( X , Y : Integer ): Boolean;
{ Return TRUE if X,Y is a wall, a threshold, or not on the map. }
begin
if Not OnTheMap( X , Y ) then begin
EffectiveWall := True;
end else if GB^.Map[ X , Y ].terr = Terrain_Threshold then begin
EffectiveWall := True;
end else if TerrMan[ GB^.Map[ X , Y ].terr ].Pass < -99 then begin
EffectiveWall := True;
end else begin
EffectiveWall := False;
end;
end;
Function WallFrame( X , Y : Integer ): Integer;
{ Given 16 different thinwall frames, determine which one is right }
{ for this tile. }
var
F: Integer;
begin
F := 0;
if EffectiveWall( X - 1 , Y ) then F := 1;
if EffectiveWall( X , Y - 1 ) then F := F + 2;
if EffectiveWall( X + 1 , Y ) then F := F + 4;
if EffectiveWall( X , Y + 1 ) then F := F + 8;
WallFrame := F;
end;
Function WallCapFrame( X , Y : Integer ): Integer;
{ Given 16 different thinwall frames, determine which one is right }
{ for this tile. }
var
F: Integer;
begin
F := 0;
if EffectiveWall( X - 1 , Y - 1 ) and EffectiveWall( X - 1 , Y ) and EffectiveWall( X , Y - 1 ) then F := 1;
if EffectiveWall( X + 1 , Y - 1 ) and EffectiveWall( X + 1 , Y ) and EffectiveWall( X , Y - 1 ) then F := F + 2;
if EffectiveWall( X + 1 , Y + 1 ) and EffectiveWall( X + 1 , Y ) and EffectiveWall( X , Y + 1 ) then F := F + 4;
if EffectiveWall( X - 1 , Y + 1 ) and EffectiveWall( X - 1 , Y ) and EffectiveWall( X , Y + 1 ) then F := F + 8;
WallCapFrame := F;
end;
Function EffectiveFloor( X , Y: Integer ): Boolean;
{ Return TRUE if the listed tile is on the map and a non-threshold floor. }
begin
EffectiveFloor := OnTheMap( X , Y ) and ( GB^.Map[ X , Y ].terr <> terrain_threshold ) and ( TerrMan[ GB^.Map[ X , Y ].terr ].Obscurement = 0 );
end;
Function WallFloorFrame( X , Y: Integer ): Integer;
{ The thin walls don't come with their own floors. So, we'll pick a floor style }
{ from the surrounding terrain. }
begin
if EffectiveFloor( X + 1 , Y + 1 ) then WallFloorFrame := GB^.Map[ X + 1 , Y + 1 ].terr - 1
else if EffectiveFloor( X , Y + 1 ) then WallFloorFrame := GB^.Map[ X , Y + 1 ].terr - 1
else if EffectiveFloor( X + 1 , Y ) then WallFloorFrame := GB^.Map[ X + 1 , Y ].terr - 1
else WallFloorFrame := 5;
end;
Function EffectiveHill( X , Y , MinZ : Integer ): Boolean;
{ Return TRUE if X,Y is a hill, or not on the map. }
begin
if Not OnTheMap( X , Y ) then begin
EffectiveHill := True;
end else begin
EffectiveHill := TerrMan[ GB^.Map[ X , Y ].terr ].Altitude >= MinZ;
end;
end;
Function HillFrame( X , Y : Integer ): Integer;
{ Given 16 different thinwall frames, determine which one is right }
{ for this tile. }
var
F: Integer;
begin
F := 0;
if EffectiveHill( X - 1 , Y , TerrMan[ GB^.Map[ X , Y ].terr ].Altitude ) then F := 1;
if EffectiveHill( X , Y - 1 , TerrMan[ GB^.Map[ X , Y ].terr ].Altitude ) then F := F + 2;
if EffectiveHill( X + 1 , Y , TerrMan[ GB^.Map[ X , Y ].terr ].Altitude ) then F := F + 4;
if EffectiveHill( X , Y + 1 , TerrMan[ GB^.Map[ X , Y ].terr ].Altitude ) then F := F + 8;
HillFrame := F;
end;
var
X,Y,Z,T: Integer;
M: GearPtr;
begin
{ Clear the overlay grids. We'll be calculating everything fresh. }
for t := 0 to NumConstantLayers do ClearOverlayLayer( T );
{ Draw the terrain itself first. }
for x := 1 to XMax do begin
for Y := 1 to YMax do begin
if GB^.Map[ X , Y ].Visible then begin
Mini_Map[ X , Y ] := GB^.Map[ X , Y ].terr + 9;
if GB^.Map[ X , Y ].terr = 8 then begin
AddInstantOverlay( X , Y , 0 , OVERLAY_Terrain , HillFrame( X , Y ) , Hill_1 );
Overlay_Map[ X , Y , 0 , OVERLAY_Terrain ].UseAlpha := True;
end else if GB^.Map[ X , Y ].terr = 9 then begin
AddInstantOverlay( X , Y , 0 , OVERLAY_Terrain , HillFrame( X , Y ) , Hill_2 );
Overlay_Map[ X , Y , 0 , OVERLAY_Terrain ].UseAlpha := True;
end else if GB^.Map[ X , Y ].terr = 10 then begin
AddInstantOverlay( X , Y , 0 , OVERLAY_Terrain , HillFrame( X , Y ) , Hill_3 );
Overlay_Map[ X , Y , 0 , OVERLAY_Terrain ].UseAlpha := True;
end else if Terrain_Image[ GB^.Map[ X , Y ].terr ] < 0 then begin
T := WallCapFrame( X , Y );
if T < 15 then begin
AddInstantOverlay( X , Y , 0 , OVERLAY_Terrain , WallFloorFrame( X , Y ) , Terrain_Sprite );
AddInstantOverlay( X , Y , 0 , OVERLAY_ThinWall , WallFrame( X , Y ) , Thin_Wall_Sprites[ -Terrain_Image[ GB^.Map[ X , Y ].terr ] ] );
AddInstantOverlay( X , Y , 0 , OVERLAY_Toupee , T , Thin_Wall_Cap );
Overlay_Map[ X , Y , 0 , OVERLAY_ThinWall ].UseAlpha := True;
Overlay_Map[ X , Y , 0 , OVERLAY_Toupee ].UseAlpha := True;
end;
end else if GB^.Map[ X , Y ].terr = 4 then begin
AddInstantOverlay( X , Y , 0 , OVERLAY_Terrain , (Animation_Phase div 5 + ( (x+y) mod 2 ) * 4 ) mod 8 , Water_Sprite1 );
AddInstantOverlay( X , Y , 0 , OVERLAY_Toupee , (Animation_Phase div 5 + ( (x+y) mod 2 ) * 4 ) mod 8 , Water_Sprite2 );
end else if GB^.Map[ X , Y ].terr = 21 then begin
AddInstantOverlay( X , Y , 0 , OVERLAY_Terrain , (Animation_Phase div 5 + ( (x+y) mod 2 ) * 4 ) mod 8 + 8 , Water_Sprite1 );
AddInstantOverlay( X , Y , 0 , OVERLAY_Toupee , (Animation_Phase div 5 + ( (x+y) mod 2 ) * 4 ) mod 8 + 8 , Water_Sprite2 );
end else if GB^.Map[ X , Y ].terr = 22 then begin
AddInstantOverlay( X , Y , 0 , OVERLAY_Terrain , (Animation_Phase div 5 + ( (x+y) mod 2 ) * 4 ) mod 8 + 16 , Water_Sprite1 );
AddInstantOverlay( X , Y , 0 , OVERLAY_Toupee , (Animation_Phase div 5 + ( (x+y) mod 2 ) * 4 ) mod 8 + 16 , Water_Sprite2 );
end else begin
AddInstantOverlay( X , Y , 0 , OVERLAY_Terrain , GB^.Map[ X , Y ].terr - 1 , Terrain_Sprite );
if Terrain_Toupee[ GB^.Map[ X , Y ].terr ] <> 0 then AddInstantOverlay( X , Y , 0 , OVERLAY_Toupee , Terrain_Toupee[ GB^.Map[ X , Y ].terr ] - 1 , Terrain_Toupee_Sprite );
end;
end else begin
Mini_Map[ X , Y ] := 0;
AddInstantOverlay( X , Y , 0 , OVERLAY_Terrain , DEFAULT_Unknown , Items_Sprite );
end;
end;
end;
{ Next add the items to the map. }
M := GB^.Meks;
while M <> Nil do begin
X := NAttValue( M^.NA , NAG_Location , NAS_X );
Y := NAttValue( M^.NA , NAG_Location , NAS_Y );
Z := MekAltitude( GB , M );
if IsMasterGear(M) and NotDestroyed( M ) then begin
if OnTheMap( X , Y ) and MekVisible( GB , M ) then begin
if M^.G = GG_Prop then begin
AddOverlay( X , Y , Z , OVERLAY_Master , GearSpriteName( GB , M ) , '' , GearName( M ) , 64 , 64 , NAttValue( M^.NA , NAG_Display , NAS_PrimaryFrame ) );
end else begin
AddOverlay( X , Y , Z , OVERLAY_Master , GearSpriteName( GB , M ) , TeamColorString( GB , M ) , PilotName( M ) , 64 , 64 , ( NAttValue( M^.NA , NAG_Location , NAS_D ) + 1 ) mod 8 );
end;
{ Record what substitute icon to use if this model is off the map. }
if AreAllies( GB , NAV_DefPlayerTeam , NAttValue( M^.NA , NAG_Location , NAS_Team ) ) then begin
OVERLAY_MAP[ X , Y , 0 , OVERLAY_Master ].SubIcon := SI_Ally;
Mini_Map[ X , Y ] := 5;
end else if AreEnemies( GB , NAV_DefPlayerTeam , NAttValue( M^.NA , NAG_Location , NAS_Team ) ) then begin
OVERLAY_MAP[ X , Y , 0 , OVERLAY_Master ].SubIcon := SI_Enemy;
Mini_Map[ X , Y ] := 1;
end else begin
OVERLAY_MAP[ X , Y , 0 , OVERLAY_Master ].SubIcon := SI_Neutral;
Mini_Map[ X , Y ] := 3;
end;
{ Also record a shadow. }
AddInstantOverlay( X , Y , TerrMan[ GB^.Map[ X , Y ].terr ].altitude , OVERLAY_Shadow , Default_Shadow , Items_Sprite );
end;
end else begin
if OnTheMap( X , Y ) and GB^.Map[X,Y].Visible then begin
if ( M^.G = GG_Mecha ) or ( M^.G = GG_Prop ) then begin
AddInstantOverlay( X , Y , Z , OVERLAY_Item , Default_Wreckage , Items_Sprite );
end else if M^.G = GG_Character then begin
AddInstantOverlay( X , Y , Z , OVERLAY_Item , Default_Dead_Thing , Items_Sprite );
end else if M^.G = GG_MetaTerrain then begin
if NotDestroyed( M ) and MekVisible( GB , M ) then
if M^.S = GS_MetaCloud then begin
for t := Z to HiAlt do begin
AddOverlayIfClear( X , Y , T , OVERLAY_Metaterrain , NAttValue( M^.NA , NAG_Display , NAS_PrimaryFrame ) , Meta_Terrain_Sprite );
end;
end else if ( M^.S = GS_MetaFire ) and ( Z < 1 ) then begin
for t := Z to 1 do begin
AddInstantOverlay( X , Y , T , OVERLAY_Metaterrain , NAttValue( M^.NA , NAG_Display , NAS_PrimaryFrame ) , Meta_Terrain_Sprite );
end;
end else if ( M^.S = GS_MetaDoor ) then begin
{ New for 2016- thin doors to go with the thin walls. Yay! }
t := 0;
if EffectiveWall( X + 1, Y ) then t := t + 1;
if M^.stat[ STAT_Pass ] = 0 then t := t + 2;
AddInstantOverlay( X , Y , Z , OVERLAY_Metaterrain , t , Door_Sprite );
end else begin
AddInstantOverlay( X , Y , Z , OVERLAY_Metaterrain , NAttValue( M^.NA , NAG_Display , NAS_PrimaryFrame ) , Meta_Terrain_Sprite );
end;
end else begin
AddOverlay( X , Y , Z , OVERLAY_Item , GearSpriteName( GB , M ) , '' , '' , 64 , 64 , NAttValue( M^.NA , NAG_Display , NAS_PrimaryFrame ) );
end;
end;
end;
M := M^.Next;
end;
{ Call the main map rendering routine. }
RenderMap;
end;
Procedure RedrawTile( gb: GameBoardPtr; X,Y: Integer );
{ Just call the above procedure with a Hilight value of FASLE. }
var
T: Integer;
begin
if not OnTheMap( X , Y ) then Exit;
for t := LowAlt to HiAlt do begin
Overlay_MAP[ X , Y , T , OVERLAY_Image ].Sprite := Nil;
end;
end;
procedure RedrawTile( gb: GameBoardPtr; Mek: GearPtr );
{ Display the tile containing the listed gear. }
{ If the tile is not currently visible, the map will be recentered. }
var
P: Point;
begin
P := GearCurrentLocation( Mek );
if OnTheMap( p.X , P.Y ) then RedrawTile( gb , P.X , P.Y );
end;
procedure IndicateTile( GB: GameBoardPtr; X , Y , Z: Integer; Primary: Boolean );
{Indicate the desired tile with a rectangle of the requested color. }
begin
{ Check the range of the coordinates we've been given. }
if not OnTheMap( X , Y ) then exit;
if ( Z < LowAlt ) or ( Z > HiAlt ) then Z := 0;
Overlay_MAP[ X , Y , Z , OVERLAY_IMAGE ].Sprite := Targeting_Srpite;
Overlay_MAP[ X , Y , Z , OVERLAY_IMAGE ].F := 0;
if Primary then begin
RecenterDisplay( X , Y );
end;
end;
procedure IndicateTile( GB: GameBoardPtr; Mek: GearPtr; Primary: Boolean );
{ Indicate the tile containing the listed gear. }
var
team: Integer;
begin
team := NAttValue( Mek^.NA , NAG_Location , NAS_Team );
if MekVisible( GB , Mek ) and ( OnTheScreen( Mek ) or ( Team = NAV_DefPlayerTeam ) ) then IndicateTile( GB , NAttValue( Mek^.NA , NAG_Location , NAS_X ) , NAttValue( Mek^.NA , NAG_Location , NAS_Y ) , MekAltitude( GB , Mek ) , Primary );
end;
procedure IndicateTile( GB: GameBoardPtr; X,Y: Integer );
{ Indicate a tile. }
begin
if OnTheMap( X , Y ) then begin
IndicateTile( GB , X , Y , TerrMan[ GB^.Map[ X , Y ].terr ].Altitude , True );
end;
end;
Procedure MouseAtTile( GB: GameBoardPtr; X,Y: Integer );
{ The mouse is apparently hovering over this tile. Draw the mouse cursor here. }
begin
ClearOverlayLayer( OVERLAY_IMAGE );
if OnTheMap( X , Y ) then begin
Overlay_MAP[ X , Y , 0 , OVERLAY_IMAGE ].Sprite := Targeting_Srpite;
Overlay_MAP[ X , Y , 0 , OVERLAY_IMAGE ].F := 1;
end;
end;
Procedure RevealMek( GB: GameBoardPtr; Mek,Spotter: GearPtr );
{ This mek has been spotted. Light it up. }
var
team: Integer;
begin
team := NAttValue( Spotter^.NA , NAG_Location , NAS_Team );
SetNAtt( Mek^.NA , NAG_Visibility , Team , NAV_Spotted );
end;
Procedure CheckVisibleArea( GB: GameBoardPtr; Mek: GearPtr );
{ Expand the visual area around this model. }
var
P: Point;
X,Y,MZ,R,Obs: Integer;
begin
P := GearCurrentLocation( Mek );
R := MappingRange( Mek , GB^.Scale );
MZ := MekAltitude( GB , Mek );
{ Look through every tile within range. If it's on the map and }
{ not yet revealed, do a check to see if it should be. }
for X := ( P.X - R ) to ( P.X + R ) do begin
for Y := ( P.Y - R ) to ( P.Y + R ) do begin
if OnTheMap( X , Y ) and not GB^.Map[X,Y].Visible then begin
{ This tile will be revealed if Range + Obscurement }
{ is less than or equal to the mapping radius. }
Obs := CalcObscurement( X , Y , TerrMan[ GB^.Map[ X , Y ].Terr ].Altitude , P.X , P.Y , MZ , GB );
if (( Range( P.X , P.Y , X , Y ) + Obs ) <= R ) and ( Obs <> -1 ) then begin
GB^.Map[X,Y].Visible := True;
end;
end;
end;
end;
end;
Procedure VisionCheck( GB: GameBoardPtr; Mek: GearPtr );
{ Perform a sensor check for MEK. It might spot hidden enemy }
{ units; it may get spotted by enemy units itself. }
var
M2: GearPtr;
begin
if ( Mek = Nil ) or ( not GearOperational( Mek ) ) then exit;
{ Start by assuming that the mek will be hidden after this. }
{ Strip all of its visibility tokens. }
StripNAtt( Mek , NAG_Visibility );
M2 := GB^.Meks;
while M2 <> Nil do begin
{ We are only interested in this other mek if it's an }
{ enemy of the one we're checking. }
if OnTheMap( M2 ) then begin
if not MekCanSeeTarget( gb , Mek , M2 ) then begin
{ If this enemy mecha has not yet been spotted, }
{ there's a chance it will become visible. }
if IsMasterGear( M2 ) and CheckLOS( GB , Mek , M2 ) then begin
{ M2 has just been spotted. }
RevealMek( GB , M2 , Mek );
end;
end;
{ There is also a chance that M2 might spot Mek. }
if IsMasterGear( M2 ) and GearOperational( M2 ) and not MekCanSeeTarget( GB , M2 , Mek ) then begin
if CheckLOS( GB , M2 , Mek ) then RevealMek( GB , Mek , M2 );
end;
end;
M2 := M2^.Next;
end;
if (NAttValue( Mek^.NA , NAG_Location , NAS_Team ) = NAV_DefPlayerTeam) or (NAttValue( Mek^.NA , NAG_Location , NAS_Team ) = NAV_LancemateTeam) then begin
CheckVisibleArea( GB , Mek );
end;
end;
Procedure DeployMek( GB: GameBoardPtr; Mek: GearPtr; PutOnMap: Boolean );
{ Stick the provided MEK onto the game board. Assign a UID, }
{ and set the default orders for MEK's team. }
{ PRECONDITION: Mek must be unlinked. }
var
Team: GearPtr;
P: Point;
begin
if ( GB = Nil ) or ( Mek = Nil ) then Exit;
{ Find the team for this model. }
Team := LocateTeam( GB , NAttValue( Mek^.NA , NAG_Location , NAS_Team ) );
{ Gear up the mek. }
if PutOnMap then GearUp( Mek );
{ Determine the X and Y values for everything. }
{ If, according to the PutOnMap parameter, we aren't supposed to put }
{ this model on the map, set X and Y to 0. }
{ If the model has X and Y already defined within the map boundaries, }
{ place it on the map at its specified location. }
{ Otherwise, determine a good spot to place this mek based upon its }
{ assigned team. }
if not PutOnMap then begin
SetNAtt( mek^.NA , NAG_Location , NAS_X , 0 );
SetNAtt( mek^.NA , NAG_Location , NAS_Y , 0 );
end else if OnTheMap( Mek ) and ( SAttValue( Mek^.SA , 'HOME' ) = '' ) then begin
{ Just set a random direction. }
SetNAtt( mek^.NA , NAG_Location , NAS_D , Random( 8 ) );
end else begin
P := FindDeploymentSpot( GB , Mek );
SetNAtt( mek^.NA , NAG_Location , NAS_X , P.X );
SetNAtt( mek^.NA , NAG_Location , NAS_Y , P.Y );
SetNAtt( mek^.NA , NAG_Location , NAS_D , Random( 8 ) );
end;
{ Assign a unique ID for this model. }
SetNAtt( mek^.NA , NAG_EpisodeData, NAS_UID, MaxIdTag( GB^.Meks , NAG_EpisodeData, NAS_UID ) + 1 );
{ Stick mek on board. }
Mek^.Next := gb^.Meks;
gb^.Meks := Mek;
{ Set default orders. }
if Team <> Nil then begin
SetNAtt( Mek^.NA , NAG_EpisodeData , NAS_Orders , Team^.Stat[ STAT_TeamOrders ] );
end;
end;
Procedure DeployMek( GB: GameBoardPtr; Mek,Pilot: GearPtr; Team: Integer );
{ Insert the supplied pilot into the supplied mecha, then insert both }
{ into the provided scenario. Supply UIDs to mek and pilot. }
{ PRECONDITION: Mek and Pilot are both unlinked gears. }
begin
if ( GB = Nil ) or ( Mek = Nil ) or ( Pilot = Nil ) then Exit;
{ Set the correct values for everything. }
SetNAtt( mek^.NA , NAG_Location , NAS_Team , Team );
SetNAtt( Pilot^.NA , NAG_Location , NAS_Team , Team );
SetNAtt( mek^.NA , NAG_EpisodeData, NAS_UID, MaxIdTag( GB^.Meks , NAG_EpisodeData, NAS_UID ) + 2 );
{ Locate cockpit, and install pilot. }
if not BoardMecha( Mek , Pilot ) then begin
{ PILOT couldn't be installed in MEK. }
{ Stick PILOT off the map. }
DeployMek( GB , Pilot, False );