forked from rochus-keller/OberonSystem3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Asteroids.Mod
1782 lines (1625 loc) · 51.2 KB
/
Asteroids.Mod
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
(* OBERON System 3, Release 2.3.
Copyright 1999 ETH Zürich Institute for Computer Systems,
ETH Center, CH-8092 Zürich. e-mail: [email protected].
This module may be used under the conditions of the general Oberon
System 3 license contract. The full text can be downloaded from
"ftp://ftp.inf.ethz.ch/pub/software/Oberon/System3/license.txt;A"
Under the license terms stated it is in particular (a) prohibited to modify
the interface of this module in any way that disagrees with the style
or content of the system and (b) requested to provide all conversions
of the source code to another platform with the name OBERON. *)
MODULE Asteroids; (** portable *) (* by W. Ibl *)
(*
Aug '96 V 1.0 first release
Sep '96 V1.1 added ship placement
Feb '97 V1.2 fixed the marker trap
Feb '97 V1.3 ported to release 2.2
July '97 V1.4 FileMessage Bug removed
Aug '97 V1.4 drawing of selected panel updated
Okt '97 V1.5 added pause button
*)
IMPORT Attributes,Desktops,Display,Display3,Documents,Effects,Files,Fonts,
Gadgets,Strings,Modules,Math,Oberon,Objects,Out,Panels,
RandomNumbers;
CONST
(* Program version *)
Version = "V 1.5";
Date = "August '97";
(* last compatible Program version *)
CompVers = "V 1.5";
(* Standard Document strings *)
DefName = "Asteroids.Doc";
DocMenu1 = "Desktops.StoreDoc[Store] Asteroids.NewGame[New] Asteroids.PauseGame[Pause]";
DocMenu2 = "Desktops.StoreDoc[Store] Asteroids.NewGame[New] Asteroids.ResumeGame[Cont]";
DocIcon = "Icons3.Asteroids";
(* who wants to live forever? *)
Indestructable = FALSE;
(* standard timer delay *)
BaseDelay = 16;
(* Control: Turn Left, Turn Right, Accelerate and Brake *)
ChThrust = 0C1X;
ChTurnRight = 0C3X;
ChTurnLeft = 0C4X;
ChFire = " ";
ChShield = "z";
ChWarp = "x";
(* amount of ships in credit *)
StartShips = 3;
(* spaceship parameters and starting values *)
ShipRotvel = 0.05; (* rotation velocity inc/decrement per keypress *)
ShipThrust = 0.3; (* thrust inc/decrement per keypress *)
ShipShield = 100; (* shield energy on stock *)
ShipWarp = 10; (* warps on stock *)
(* ship's bullet parameters and starting values *)
SBulletMax = 5; (* Max. of ships' bullets in space at a time *)
SBulletSpd = 5.0; (* Speed of ships' bullets *)
SBulletGrant = 100; (* amount of ticks a bullet is active *)
SBulletCost = 10; (* score decrement per fired bullet *)
(* timer rounds where shield is stable *)
SShieldGrant = 5;
(* factor for ufo appearance - less is more seldom *)
EAppear = 8000; (* RAND < (frame/EAppear) *)
(* ufo's bullet parameters and starting values *)
EBulletMax = 1; (* Max. of ufos' bullets in space at a time *)
EBulletSpd = 2.0; (* Speed of ufos' bullets *)
EBulletGrant = 200; (* amount of ticks a bullet is active *)
(* detonation parameters *)
DetonationMax = 50; (* Max. radius of a detonation circle *)
DetonationStep = 1; (* radius increment per tick *)
(* score adds *)
HitScoreE1 = 100; (* hit ufo *)
HitScoreA1 = 50; (* hit big asteroid *)
HitScoreA2 = 70; (* hit medium asteroid *)
HitScoreA3 = 80; (* hit small asteroid *)
StartAsts = 4; (* amount of asteroids at first level *)
SplitAsts = 2; (* amount of asteroids appearing after detonation *)
TYPE
Object = Objects.Object;
Document = Documents.Document;
(* Message Shortcuts *)
AttrMsg = Objects.AttrMsg;
CopyMsg = Objects.CopyMsg;
DisplayMsg = Display.DisplayMsg;
FileMsg = Objects.FileMsg;
InputMsg = Oberon.InputMsg;
LinkMsg = Objects.LinkMsg;
ModifyMsg = Display.ModifyMsg;
UpdateMsg = Gadgets.UpdateMsg;
(* used for updating the Document's Menu Buttons *)
MenuMsg = RECORD(Display.FrameMsg)
frame: Display.Frame;
paused: BOOLEAN;
END;
Vertices = POINTER TO ARRAY OF INTEGER;
(* the asteroid field *)
Starfield = POINTER TO StarfieldDesc;
StarfieldDesc = RECORD(Panels.PanelDesc)
scaleX,scaleY: REAL;
fdx: INTEGER;
END;
(* vertices of game figures *)
Shape = POINTER TO ShapeDesc;
ShapeDesc = RECORD
n: INTEGER;
px,py: Vertices;
END;
(* object in the starfield space *)
SpaceObj = POINTER TO SpaceObjDesc;
SpaceObjDesc = RECORD
x,y,x0,y0: REAL;
alive: BOOLEAN;
next: SpaceObj;
END;
(* Detonation - a continuous expanding circle *)
Detonation = POINTER TO DetonationDesc;
DetonationDesc = RECORD(SpaceObjDesc)
r0,r: INTEGER;
END;
(* hitable object in the starfield space *)
Mass = POINTER TO MassDesc;
MassDesc = RECORD(SpaceObjDesc)
mass: LONGREAL;
rot,xvel,yvel,rotvel: REAL;
shape: Shape;
n0,u,v,w,h: INTEGER;
px0,py0,px1,py1: Vertices;
END;
(* controlled moving object *)
FlyingObj = POINTER TO FlyingObjDesc;
FlyingObjDesc = RECORD(MassDesc)
bullets: INTEGER;
END;
(* fired bullet *)
Bullet = POINTER TO BulletDesc;
BulletDesc = RECORD(MassDesc)
time,rpos: INTEGER;
ship: FlyingObj;
END;
(* player's ship *)
Ship = POINTER TO ShipDesc;
ShipDesc = RECORD(FlyingObjDesc)
thrust0,thrust: BOOLEAN;
shield0,shield: SHORTINT;
shieldval,warpval: INTEGER;
shape0: Shape;
px2,py2: Vertices;
END;
(* an ufo - god knows where it comes from and why *)
Enemy = POINTER TO EnemyDesc;
EnemyDesc = RECORD(FlyingObjDesc)
END;
(* ship's bullet *)
SBullet = POINTER TO SBulletDesc;
SBulletDesc = RECORD(BulletDesc)
END;
(* ufo's bullet *)
EBullet = POINTER TO EBulletDesc;
EBulletDesc = RECORD(BulletDesc)
END;
(* the "real" enemies *)
Asteroid = POINTER TO AsteroidDesc;
AsteroidDesc = RECORD(MassDesc)
END;
(* the game's model *)
Field = POINTER TO FieldDesc;
FieldDesc = RECORD(Gadgets.ObjDesc)
ship: Ship;
started,changed,paused: BOOLEAN;
ships,ufos,frames: INTEGER;
score,high0,high: LONGINT;
line0,line: ARRAY 80 OF CHAR;
objects: SpaceObj;
END;
(* sometimes, we need a kick... *)
Timer = POINTER TO TimerDesc;
TimerDesc = RECORD(Oberon.TaskDesc)
model: Field;
trigger: LONGINT;
tnext: Timer;
END;
VAR
shAsteroid1,shAsteroid2,shAsteroid3, (* standard shapes *)
shEnemy,shEBullet,
shShip,shThrShip,shSBullet: Shape;
hitscore: ARRAY 4 OF INTEGER; (* score increments per figure *)
fnt: ARRAY 7 OF Fonts.Font; (* score line resize *)
fw,fh: ARRAY 7 OF INTEGER;
b,w: INTEGER; (* drawing colors *)
timer: Timer; (* active kickers *)
PROCEDURE FontGeometry(IN dim: ARRAY OF CHAR; fdx: INTEGER);
(* query font's parameters for zooming *)
VAR
fn: Objects.Name;
fd: INTEGER;
BEGIN
fn := "Oberon";
Strings.Append(fn,dim); Strings.Append(fn,".Scn.Fnt");
fnt[fdx]:= Fonts.This(fn); Display3.StringSize("X",fnt[fdx],fw[fdx],fh[fdx],fd);
END FontGeometry;
PROCEDURE Intersect(x11,y11,x12,y12,x21,y21,x22,y22: INTEGER; VAR x3,y3: INTEGER): BOOLEAN;
(* calculate intersection between two lines, point is in (x3,y3) *)
VAR
k1,k2,d1,d2: REAL;
h1,h2: BOOLEAN;
PROCEDURE Within(c,a,b: INTEGER): BOOLEAN;
(* interval calculation *)
BEGIN
IF (a < b) THEN RETURN((c>a)&(c<b)); ELSE RETURN((c>=b)&(c<=a)); END;
END Within;
BEGIN
h1:= (x11 = x12); h2:= (x21 = x22);
IF ~h1 THEN
k1:= (y12 - y11) / (x12 - x11); d1:= y11 - (k1 * x11);
END;
IF ~h2 THEN
k2:= (y22 - y21) / (x22 - x21); d2:= y21 - (k2 * x21);
END;
IF ~h1 & ~h2 THEN
IF (k1 = k2) THEN x3:= -1; y3:= -1; RETURN(FALSE); END;
x3:= SHORT(ENTIER((d2 - d1) / (k1 - k2)));
y3:= SHORT(ENTIER((k1 * x3) + d1));
ELSIF ~h1 & h2 THEN
x3:= x21; y3:= SHORT(ENTIER((k1 * x3) + d1));
ELSIF h1 & ~h2 THEN
x3:= x11; y3:= SHORT(ENTIER((k2 * x3) + d2));
ELSE
x3:= x11; y3:= y11; RETURN(x11 = x21);
END;
RETURN(Within(x3,x11,x12) & Within(x3,x21,x22) &
Within(y3,y11,y12) & Within(y3,y21,y22));
END Intersect;
PROCEDURE Sign(v: REAL): INTEGER;
(* get the sign of a real (+1|-1) *)
BEGIN
IF (v < 0.0) THEN RETURN(-1); ELSE RETURN(1); END;
END Sign;
PROCEDURE TransX(x,y: INTEGER; p,v: REAL): REAL;
(* Transform x-coord - shift and rotate *)
BEGIN
RETURN((x*Math.cos(p)+y*Math.sin(p))+v);
END TransX;
PROCEDURE TransY(x,y: INTEGER; p,v: REAL): REAL;
(* Transform y-coord - shift and rotate *)
BEGIN
RETURN((-x*Math.sin(p)+y*Math.cos(p))+v);
END TransY;
PROCEDURE Model(D: Object): Field;
(* return the game's model *)
VAR
model: Object;
BEGIN
WITH D: Starfield DO model:= D.obj; END;
WITH model: Field DO RETURN(model); END;
END Model;
PROCEDURE Score(F: Field; score: INTEGER);
(* calculate player's current score *)
BEGIN
F.score:= F.score + score; F.changed:= TRUE;
IF (F.score > F.high0) THEN F.high:= F.score; ELSE F.high:= F.high0; END;
END Score;
PROCEDURE Pair(sh: Shape; n,x,y: INTEGER);
(* shape initialization *)
BEGIN
sh.px[n]:= x; sh.py[n]:= y;
END Pair;
PROCEDURE Tag(obj: SpaceObj; VAR tag: Objects.Name);
(* string tag for loading/storing *)
BEGIN
WITH
obj: Asteroid DO tag := "Asteroid";
| obj: EBullet DO tag := "EBullet";
| obj: SBullet DO tag := "SBullet";
| obj: Enemy DO tag := "Enemy";
| obj: Ship DO tag := "Ship";
| obj: Detonation DO tag := "Detonation";
END;
END Tag;
PROCEDURE ShowStatus(obj: Field; VAR status: ARRAY OF CHAR);
(* create a up-to-date status line *)
VAR
nr: ARRAY 16 OF CHAR;
BEGIN
IF obj.started THEN
status := "Ships: ";
Strings.IntToStr(obj.ships,nr); Strings.Append(status,nr);
Strings.Append(status," Warps: ");
Strings.IntToStr(obj.ship.warpval,nr); Strings.Append(status,nr);
Strings.Append(status," Shield: ");
Strings.IntToStr(obj.ship.shieldval,nr); Strings.Append(status,nr);
Strings.Append(status," Field: ");
Strings.IntToStr(obj.frames,nr); Strings.Append(status,nr);
Strings.Append(status," Score: ");
Strings.IntToStr(obj.score,nr); Strings.Append(status,nr);
Strings.Append(status," High: ");
Strings.IntToStr(obj.high,nr); Strings.Append(status,nr);
ELSE
status := "Asteroids for Oberon ";
Strings.Append(status,Version);
Strings.Append(status," by W. Ibl, ");
Strings.Append(status,Date);
END;
END ShowStatus;
(*** Game object shapes ***)
PROCEDURE Asteroid1Shape(VAR sh: Shape);
(* Shape of a big asteroid *)
BEGIN
NEW(sh); sh.n:= 11; NEW(sh.px,sh.n); NEW(sh.py,sh.n);
Pair(sh,0,0,0); Pair(sh,1,0,-40); Pair(sh,2,20,-40); Pair(sh,3,40,-20);
Pair(sh,4,40,20); Pair(sh,5,20,40); Pair(sh,6,-20,40); Pair(sh,7,-40,20);
Pair(sh,8,-40,-20); Pair(sh,9,-20,-40); Pair(sh,10,0,-40);
END Asteroid1Shape;
PROCEDURE Asteroid2Shape(VAR sh: Shape);
(* Shape of a medium asteroid *)
BEGIN
NEW(sh); sh.n:= 11; NEW(sh.px,sh.n); NEW(sh.py,sh.n);
Pair(sh,0,0,0); Pair(sh,1,0,-20); Pair(sh,2,10,-20); Pair(sh,3,20,-10);
Pair(sh,4,20,10); Pair(sh,5,10,20); Pair(sh,6,-10,20); Pair(sh,7,-20,10);
Pair(sh,8,-20,-10); Pair(sh,9,-10,-20); Pair(sh,10,0,-20);
END Asteroid2Shape;
PROCEDURE Asteroid3Shape(VAR sh: Shape);
(* Shape of a small asteroid *)
BEGIN
NEW(sh); sh.n:= 11; NEW(sh.px,sh.n); NEW(sh.py,sh.n);
Pair(sh,0,0,0); Pair(sh,1,0,-10); Pair(sh,2,5,-10); Pair(sh,3,10,-5);
Pair(sh,4,10,5); Pair(sh,5,5,10); Pair(sh,6,-5,10); Pair(sh,7,-10,5);
Pair(sh,8,-10,-5); Pair(sh,9,-5,-10); Pair(sh,10,0,-10);
END Asteroid3Shape;
PROCEDURE EnemyShape(VAR sh: Shape);
(* Shape of an ufo *)
BEGIN
NEW(sh); sh.n:= 5; NEW(sh.px,sh.n); NEW(sh.py,sh.n);
Pair(sh,0,-10,0); Pair(sh,1,0,-15); Pair(sh,2,10,0); Pair(sh,3,0,15);
Pair(sh,4,-10,0);
END EnemyShape;
PROCEDURE EBulletShape(VAR sh: Shape);
(* Shape of an ufo's bullet *)
BEGIN
NEW(sh); sh.n:= 5; NEW(sh.px,sh.n); NEW(sh.py,sh.n);
Pair(sh,0,0,0); Pair(sh,1,3,-3); Pair(sh,2,6,0); Pair(sh,3,3,3);
Pair(sh,4,0,0);
END EBulletShape;
PROCEDURE ShipShape(VAR sh: Shape);
(* Shape of the player's ship *)
BEGIN
NEW(sh); sh.n:= 7; NEW(sh.px,sh.n); NEW(sh.py,sh.n);
Pair(sh,0,0,0); Pair(sh,1,-20,-20); Pair(sh,2,0,-20); Pair(sh,3,20,0);
Pair(sh,4,0,20); Pair(sh,5,-20,20); Pair(sh,6,0,0);
END ShipShape;
PROCEDURE ThrShipShape(VAR sh: Shape);
(* Shape of the player's ship thrusting *)
BEGIN
NEW(sh); sh.n:= 10; NEW(sh.px,sh.n); NEW(sh.py,sh.n);
Pair(sh,0,0,0); Pair(sh,1,-20,-20); Pair(sh,2,0,-20); Pair(sh,3,20,0);
Pair(sh,4,0,20); Pair(sh,5,-20,20); Pair(sh,6,0,0); Pair(sh,7,-5,5);
Pair(sh,8,-20,0); Pair(sh,9,-7,-5);
END ThrShipShape;
PROCEDURE SBulletShape(VAR sh: Shape);
(* Shape of the player's ship's bullet *)
BEGIN
NEW(sh); sh.n:= 2; NEW(sh.px,sh.n); NEW(sh.py,sh.n);
Pair(sh,0,0,0); Pair(sh,1,10,0);
END SBulletShape;
(*** Object initialization ***)
PROCEDURE InitSpaceObj(obj: SpaceObj);
BEGIN
obj.x:= 0.0; obj.y:= 0.0; obj.alive:= TRUE; obj.next:= NIL;
END InitSpaceObj;
PROCEDURE InitMass(obj: Mass; shape: Shape);
BEGIN
InitSpaceObj(obj);
obj.shape:= shape; obj.n0:= shape.n;
NEW(obj.px0,obj.n0); NEW(obj.py0,obj.n0);
NEW(obj.px1,obj.n0); NEW(obj.py1,obj.n0);
obj.rot:= 0.0; obj.xvel:= 0.0; obj.yvel:= 0.0; obj.rotvel:= 0.0;
END InitMass;
PROCEDURE InitFlyingObj(obj: FlyingObj; shape: Shape);
BEGIN
InitMass(obj,shape); obj.bullets:= 0;
END InitFlyingObj;
PROCEDURE InitBullet(obj: Bullet; shape: Shape; ship: FlyingObj; grant: INTEGER);
BEGIN
InitMass(obj,shape); obj.ship:= ship; obj.time:= grant; obj.rpos:= -1;
END InitBullet;
PROCEDURE InitShip(obj: Ship; x,y: REAL);
BEGIN
InitFlyingObj(obj,shThrShip); obj.shape:= shShip; obj.shape0:= shThrShip;
IF (obj.px2 = NIL) THEN NEW(obj.px2,shThrShip.n); END;
IF (obj.py2 = NIL) THEN NEW(obj.py2,shThrShip.n); END;
obj.thrust:= FALSE; obj.thrust0:= FALSE;
obj.shield:= 0; obj.shield0:= 0;
obj.shieldval:= ShipShield; obj.warpval:= ShipWarp;
obj.x:= x; obj.y:= y;
END InitShip;
PROCEDURE InitSBullet(obj: SBullet; ship: Ship);
BEGIN
InitBullet(obj,shSBullet,ship,SBulletGrant);
obj.x:= ship.px1[3]; obj.y:= ship.py1[3]; obj.rot:= ship.rot;
obj.xvel:= SBulletSpd * ((ship.px1[3] - ship.px1[0]) / 20);
obj.yvel:= SBulletSpd * ((ship.py1[3] - ship.py1[0]) / 20);
obj.rotvel:= 0.0;
END InitSBullet;
PROCEDURE InitEnemy(obj: Enemy);
BEGIN
InitFlyingObj(obj,shEnemy);
obj.x:= RandomNumbers.Uniform() * Display.Width;
obj.y:= RandomNumbers.Uniform() * Display.Height;
obj.xvel:= RandomNumbers.Uniform() - 0.5;
obj.yvel:= RandomNumbers.Uniform() - 0.5;
obj.rotvel:= 0.3;
END InitEnemy;
PROCEDURE InitEBullet(obj: EBullet; ufo: Enemy; ship: Ship);
VAR
dw,dx,dy,dz: REAL;
BEGIN
InitBullet(obj,shEBullet,ufo,EBulletGrant);
obj.x:= ufo.px1[0]; obj.y:= ufo.py1[0];
dx:= (ship.px1[0]-ufo.px1[0]); dy:= (ship.py1[0]-ufo.py1[0]); dz:= dy/dx;
IF (ABS(dz) > 1.0) THEN dw:= ABS(dz); ELSE dw:= 1.0; END;
obj.xvel:= Sign(dx) * (EBulletSpd / dw);
obj.yvel:= Sign(dy) * (EBulletSpd / dw) * dz;
obj.rotvel:= 0.0;
END InitEBullet;
PROCEDURE InitAsteroid(obj,father: Asteroid; shape: Shape; hx,hy: INTEGER);
BEGIN
InitMass(obj,shape);
IF (father # NIL) THEN
obj.x:= father.px1[0]; obj.y:= father.py1[0];
obj.xvel:= RandomNumbers.Uniform()-(-(0.5)*Sign(father.px1[0]-hx));
obj.yvel:= RandomNumbers.Uniform()-(-(0.5)*Sign(father.py1[0]-hy));
ELSE
obj.x:= RandomNumbers.Uniform() * Display.Width;
obj.y:= RandomNumbers.Uniform() * Display.Height;
obj.xvel:= RandomNumbers.Uniform() - (0.5 * hx);
obj.yvel:= RandomNumbers.Uniform() - (0.5 * hy);
END;
obj.rot:= (RandomNumbers.Uniform() - 0.5) / 10;
obj.rotvel:= (RandomNumbers.Uniform() - 0.5) / 10;
END InitAsteroid;
PROCEDURE InitField(obj: Field);
BEGIN
obj.ships:= StartShips; obj.ufos:= 0; obj.frames:= 0; obj.score:= 0;
obj.high0:= obj.high; obj.objects:= NIL;
obj.started:= FALSE; obj.changed:= FALSE; obj.paused:= FALSE;
ShowStatus(obj,obj.line);
END InitField;
PROCEDURE StoreShapeRef(VAR R: Files.Rider; shape: Shape);
(* store a given tag string *)
BEGIN
IF (shape = shAsteroid1) THEN
Files.WriteString(R,"shAsteroid1");
ELSIF (shape = shAsteroid2) THEN
Files.WriteString(R,"shAsteroid2");
ELSIF (shape = shAsteroid3) THEN
Files.WriteString(R,"shAsteroid3");
ELSIF (shape = shEnemy) THEN
Files.WriteString(R,"shEnemy");
ELSIF (shape = shEBullet) THEN
Files.WriteString(R,"shEBullet");
ELSIF (shape = shShip) THEN
Files.WriteString(R,"shShip");
ELSIF (shape = shThrShip) THEN
Files.WriteString(R,"shThrShip");
ELSIF (shape = shSBullet) THEN
Files.WriteString(R,"shSBullet");
END;
END StoreShapeRef;
PROCEDURE LoadShapeRef(VAR R: Files.Rider; VAR shape: Shape);
(* return shape depending on the tag string *)
VAR
str: Objects.Name;
BEGIN
Files.ReadString(R,str);
IF (str = "shAsteroid1") THEN
shape:= shAsteroid1;
ELSIF (str = "shAsteroid2") THEN
shape:= shAsteroid2;
ELSIF (str = "shAsteroid3") THEN
shape:= shAsteroid3;
ELSIF (str = "shEnemy") THEN
shape:= shEnemy;
ELSIF (str = "shEBullet") THEN
shape:= shEBullet;
ELSIF (str = "shShip") THEN
shape:= shShip;
ELSIF (str = "shThrShip") THEN
shape:= shThrShip;
ELSIF (str = "shSBullet") THEN
shape:= shSBullet;
ELSE
shape:= NIL;
END;
END LoadShapeRef;
(*** Game Object loading/storing ***)
PROCEDURE FileSpaceObj(VAR R: Files.Rider; id: INTEGER; obj,root: SpaceObj);
BEGIN
IF (id = Objects.store) THEN
Files.WriteReal(R,obj.x); Files.WriteReal(R,obj.y);
Files.WriteReal(R,obj.x0); Files.WriteReal(R,obj.y0);
Files.WriteBool(R,obj.alive);
ELSIF (id = Objects.load) THEN
Files.ReadReal(R,obj.x); Files.ReadReal(R,obj.y);
Files.ReadReal(R,obj.x0); Files.ReadReal(R,obj.y0);
Files.ReadBool(R,obj.alive);
END;
END FileSpaceObj;
PROCEDURE FileDetonation(VAR R: Files.Rider; id: INTEGER; obj: Detonation; root: SpaceObj);
BEGIN
FileSpaceObj(R,id,obj,root);
IF (id = Objects.store) THEN
Files.WriteInt(R,obj.r0); Files.WriteInt(R,obj.r);
ELSIF (id = Objects.load) THEN
Files.ReadInt(R,obj.r0); Files.ReadInt(R,obj.r);
END;
END FileDetonation;
PROCEDURE FileMass(VAR R: Files.Rider; id: INTEGER; obj: Mass; root: SpaceObj);
VAR
i,j: LONGINT;
BEGIN
FileSpaceObj(R,id,obj,root);
IF (id = Objects.store) THEN
Files.WriteLReal(R,obj.mass); Files.WriteReal(R,obj.rot);
Files.WriteReal(R,obj.xvel); Files.WriteReal(R,obj.yvel);
StoreShapeRef(R,obj.shape);
Files.WriteReal(R,obj.rotvel); Files.WriteInt(R,obj.n0);
Files.WriteInt(R,obj.u); Files.WriteInt(R,obj.v);
Files.WriteInt(R,obj.w); Files.WriteInt(R,obj.h);
j:= LEN(obj.px0^); Files.WriteLInt(R,j);
FOR i:= 0 TO j-1 DO
Files.WriteInt(R,obj.px0[i]); Files.WriteInt(R,obj.py0[i]);
Files.WriteInt(R,obj.px1[i]); Files.WriteInt(R,obj.py1[i]);
END;
ELSIF (id = Objects.load) THEN
Files.ReadLReal(R,obj.mass); Files.ReadReal(R,obj.rot);
Files.ReadReal(R,obj.xvel); Files.ReadReal(R,obj.yvel);
LoadShapeRef(R,obj.shape);
Files.ReadReal(R,obj.rotvel); Files.ReadInt(R,obj.n0);
Files.ReadInt(R,obj.u); Files.ReadInt(R,obj.v);
Files.ReadInt(R,obj.w); Files.ReadInt(R,obj.h);
Files.ReadLInt(R,j);
NEW(obj.px0,j); NEW(obj.py0,j);
NEW(obj.px1,j); NEW(obj.py1,j);
FOR i:= 0 TO j-1 DO
Files.ReadInt(R,obj.px0[i]); Files.ReadInt(R,obj.py0[i]);
Files.ReadInt(R,obj.px1[i]); Files.ReadInt(R,obj.py1[i]);
END;
END;
END FileMass;
PROCEDURE FileFlyingObj(VAR R: Files.Rider; id: INTEGER; obj: FlyingObj; root: SpaceObj);
BEGIN
FileMass(R,id,obj,root);
IF (id = Objects.store) THEN
Files.WriteInt(R,obj.bullets);
ELSIF (id = Objects.load) THEN
Files.ReadInt(R,obj.bullets);
END;
END FileFlyingObj;
PROCEDURE FileBullet(VAR R: Files.Rider; id: INTEGER; obj: Bullet; root: SpaceObj);
VAR
rpos: INTEGER;
BEGIN
FileMass(R,id,obj,root);
IF (id = Objects.store) THEN
rpos:= 0; WHILE (root # obj.ship) DO INC(rpos); root:= root.next; END;
Files.WriteInt(R,obj.time); Files.WriteInt(R,rpos);
ELSIF (id = Objects.load) THEN
Files.ReadInt(R,obj.time); Files.ReadInt(R,obj.rpos);
END;
END FileBullet;
PROCEDURE FileShip(VAR R: Files.Rider; id: INTEGER; obj: Ship; root: SpaceObj);
VAR
i: INTEGER;
BEGIN
FileFlyingObj(R,id,obj,root);
IF (id = Objects.store) THEN
Files.WriteBool(R,obj.thrust0); Files.WriteBool(R,obj.thrust);
Files.Write(R,obj.shield0); Files.Write(R,obj.shield);
Files.WriteInt(R,obj.shieldval); Files.WriteInt(R,obj.warpval);
StoreShapeRef(R,obj.shape0);
FOR i:= 0 TO obj.shape0.n-1 DO
Files.WriteInt(R,obj.px2[i]); Files.WriteInt(R,obj.py2[i]);
END;
ELSIF (id = Objects.load) THEN
Files.ReadBool(R,obj.thrust0); Files.ReadBool(R,obj.thrust);
Files.ReadSInt(R,obj.shield0); Files.ReadSInt(R,obj.shield);
Files.ReadInt(R,obj.shieldval); Files.ReadInt(R,obj.warpval);
LoadShapeRef(R,obj.shape0);
NEW(obj.px2,shThrShip.n); NEW(obj.py2,shThrShip.n);
FOR i:= 0 TO shThrShip.n-1 DO
Files.ReadInt(R,obj.px2[i]); Files.ReadInt(R,obj.py2[i]);
END;
END;
END FileShip;
PROCEDURE FileEnemy(VAR R: Files.Rider; id: INTEGER; obj: Enemy; root: SpaceObj);
BEGIN
FileFlyingObj(R,id,obj,root);
END FileEnemy;
PROCEDURE FileSBullet(VAR R: Files.Rider; id: INTEGER; obj: SBullet; root: SpaceObj);
BEGIN
FileBullet(R,id,obj,root);
END FileSBullet;
PROCEDURE FileEBullet(VAR R: Files.Rider; id: INTEGER; obj: EBullet; root: SpaceObj);
BEGIN
FileBullet(R,id,obj,root);
END FileEBullet;
PROCEDURE FileAsteroid(VAR R: Files.Rider; id: INTEGER; obj: Asteroid; root: SpaceObj);
BEGIN
FileMass(R,id,obj,root);
END FileAsteroid;
(*** end of loading/storing ***)
PROCEDURE ModifyStatus(F: Starfield; obj: Field; mx,my: INTEGER);
(* create a new status line and display it *)
BEGIN
ShowStatus(obj,obj.line);
Oberon.RemoveMarks(F.mask.X,F.mask.Y+5,F.mask.W,fh[F.fdx]);
Display3.String(F.mask,F.col,mx+F.X+5,my+F.Y+5,fnt[F.fdx],obj.line0,Display3.paint);
Display3.String(F.mask,w,mx+F.X+5,my+F.Y+5,fnt[F.fdx],obj.line,Display3.paint);
END ModifyStatus;
PROCEDURE RestoreStatus(F: Starfield; obj: Field; mx,my: INTEGER);
(* display the current status line *)
BEGIN
Oberon.RemoveMarks(F.mask.X,F.mask.Y+5,F.mask.W,fh[F.fdx]);
IF (obj.line0 # obj.line) THEN
Display3.String(F.mask,F.col,mx+F.X+5,my+F.Y+5,fnt[F.fdx],obj.line0,Display3.paint);
obj.line0 := obj.line;
END;
Display3.String(F.mask,w,mx+F.X+5,my+F.Y+5,fnt[F.fdx],obj.line,Display3.paint);
END RestoreStatus;
(* Game Object drawing *)
PROCEDURE DrawDetonation(F: Starfield; obj: Detonation; mx,my: INTEGER): INTEGER;
VAR
sx,sy,sr: INTEGER;
BEGIN
sx:= SHORT(ENTIER(obj.x*F.scaleX)); sy:= SHORT(ENTIER(obj.y*F.scaleY));
sr:= SHORT(ENTIER(obj.r0*((F.scaleX+F.scaleY)/2)));
Oberon.RemoveMarks(F.mask.X+sx-sr,F.mask.Y+sy-sr,sr*2,sr*2);
Display3.Circle(F.mask,F.col,Display.solid,mx+F.X+sx,my+F.Y+sy,sr,1,{},Display3.replace);
IF obj.alive THEN
sr:= SHORT(ENTIER(obj.r*((F.scaleX+F.scaleY)/2)));
Oberon.RemoveMarks(F.mask.X+sx-sr,F.mask.Y+sy-sr,sr*2,sr*2);
Display3.Circle(F.mask,w,Display.grey2,mx+F.X+sx,my+F.Y+sy,sr,1,{},Display3.replace);
END;
RETURN(sy-sr);
END DrawDetonation;
PROCEDURE DrawMass(F: Starfield; obj: Mass; mx,my: INTEGER): INTEGER;
VAR
su,sv,sw,sh: INTEGER;
PROCEDURE Poly(x,y: ARRAY OF INTEGER; n,dx,dy,c: INTEGER);
(* add offset to every point in array and draw *)
VAR
i: INTEGER;
BEGIN
FOR i:= 0 TO n-1 DO
x[i]:= SHORT(ENTIER(x[i]*F.scaleX))+dx;
y[i]:= SHORT(ENTIER(y[i]*F.scaleY))+dy;
END;
Display3.Poly(F.mask,c,Display.solid,x,y,n,1,{},Display3.replace);
END Poly;
BEGIN
su:= SHORT(ENTIER(obj.u*F.scaleX)); sv:= SHORT(ENTIER(obj.v*F.scaleY));
sw:= SHORT(ENTIER(obj.w*F.scaleX)); sh:= SHORT(ENTIER(obj.h*F.scaleY));
Oberon.RemoveMarks(F.mask.X+su,F.mask.Y+sv,sw,sh);
Poly(obj.px0^,obj.py0^,obj.n0,mx+F.X,my+F.Y,F.col);
IF obj.alive THEN
Poly(obj.px1^,obj.py1^,obj.shape.n,mx+F.X,my+F.Y,w);
END;
RETURN(sv);
END DrawMass;
PROCEDURE DrawShip(F: Starfield; obj: Ship; mx,my: INTEGER): INTEGER;
VAR
sx,sy,sr,sv: INTEGER;
BEGIN
sr:= SHORT(ENTIER(34*((F.scaleX+F.scaleY)/2)));
IF (obj.shield0 > 0) THEN
sx:= SHORT(ENTIER(obj.x0*F.scaleX));
sy:= SHORT(ENTIER(obj.y0*F.scaleY));
Oberon.RemoveMarks(F.mask.X+sx-sr,F.mask.Y+sy-sr,sr*2,sr*2);
Display3.Circle(F.mask,F.col,Display.solid,mx+F.X+sx,my+F.Y+sy,sr,1,{},Display3.replace);
END;
sv:= DrawMass(F,obj,mx,my);
IF obj.alive & (obj.shield > 0) THEN
Oberon.RemoveMarks(F.mask.X+sx-sr,F.mask.Y+sy-sr,sr*2,sr*2);
sx:= SHORT(ENTIER(obj.x*F.scaleX));
sy:= SHORT(ENTIER(obj.y*F.scaleY));
sv:= sy - sr;
Display3.Circle(F.mask,w,Display.solid,mx+F.X+sx,my+F.Y+sy,sr,1,{},Display3.replace);
END;
RETURN(sv);
END DrawShip;
PROCEDURE MoveMass(obj: Mass);
(* calculate new position of shape vertices using velocities for x, y and rot *)
VAR
i,w1,h1,w2,h2: INTEGER;
shp: Shape;
BEGIN
w1:= 0; h1:= 0; w2:= 0; h2:= 0; shp:= obj.shape;
obj.x0:= obj.x; obj.y0:= obj.y;
obj.x:= obj.x + obj.xvel; obj.y:= obj.y + obj.yvel;
obj.rot:= obj.rot + obj.rotvel;
FOR i:= 0 TO shp.n-1 DO
obj.px1[i]:= SHORT(ENTIER(TransX(shp.px[i],shp.py[i],obj.rot,obj.x)));
obj.py1[i]:= SHORT(ENTIER(TransY(shp.px[i],shp.py[i],obj.rot,obj.y)));
IF (obj.px1[i] > Display.Width) THEN INC(w1); END;
IF (obj.px1[i] < 0) THEN INC(w2); END;
IF (obj.py1[i] > Display.Height) THEN INC(h1); END;
IF (obj.py1[i] < 0) THEN INC(h2); END;
END;
(* if an object disappeared completly, let it fully appear on the opposite *)
IF (w1 = shp.n) THEN
obj.x:= obj.x - Display.Width;
FOR i:= 0 TO shp.n-1 DO DEC(obj.px1[i],Display.Width); END;
ELSIF (w2 = shp.n) THEN
obj.x:= obj.x + Display.Width;
FOR i:= 0 TO shp.n-1 DO INC(obj.px1[i],Display.Width); END;
END;
IF (h1 = shp.n) THEN
obj.y:= obj.y - Display.Height;
FOR i:= 0 TO shp.n-1 DO DEC(obj.py1[i],Display.Height); END;
ELSIF (h2 = shp.n) THEN
obj.y:= obj.y + Display.Height;
FOR i:= 0 TO obj.shape.n-1 DO DEC(obj.py1[i],Display.Height); END;
END;
(* calculate the objects hull (x,y,u,v) for easier intersection and redraw *)
w1:= MAX(INTEGER); h1:= MAX(INTEGER);
w2:= MIN(INTEGER); h2:= MIN(INTEGER);
FOR i:= 0 TO shp.n-1 DO
IF (obj.px1[i] < w1) THEN w1:= obj.px1[i]; END;
IF (obj.py1[i] < h1) THEN h1:= obj.py1[i]; END;
IF (obj.px1[i] > w2) THEN w2:= obj.px1[i]; END;
IF (obj.py1[i] > h2) THEN h2:= obj.py1[i]; END;
END;
obj.u:= w1; obj.v:= h1; obj.w:= w2 - w1; obj.h:= h2 - h1;
END MoveMass;
PROCEDURE IntersectMass(obj1,obj2: Mass; VAR x,y: INTEGER): BOOLEAN;
(* calculate intersection of two objects *)
VAR
i,j: INTEGER;
PROCEDURE In(v,min,max: INTEGER): BOOLEAN;
BEGIN
RETURN((v >= min) & (v <= max));
END In;
PROCEDURE InBound(i,j: Mass): BOOLEAN;
(* intersect the hulls *)
BEGIN
RETURN((In(i.u,j.u,j.u+j.w) OR In(i.u+i.w,j.u,j.u+j.w)) & (In(i.v,j.v,j.v+j.h) OR In(i.v+i.h,j.v,j.v+j.h)));
END InBound;
BEGIN
(* if hulls don't intersect, skip line checking *)
IF InBound(obj1,obj2) OR InBound(obj2,obj1) THEN
(* just a speedup for small asteroids *)
IF (obj1.shape = shAsteroid3) OR (obj2.shape = shAsteroid3) THEN
RETURN(TRUE);
END;
FOR i:= 0 TO obj1.shape.n-2 DO
FOR j:= 0 TO obj2.shape.n-2 DO
IF Intersect(obj1.px1[i],obj1.py1[i],obj1.px1[i+1],obj1.py1[i+1],
obj2.px1[j],obj2.py1[j],obj2.px1[j+1],obj2.py1[j+1],x,y) THEN
RETURN(TRUE);
END;
END;
END;
END;
RETURN(FALSE);
END IntersectMass;
PROCEDURE SFire(F: Field; ship: Ship);
(* fire a ship's bullet - if possible *)
VAR
bullet: SBullet;
BEGIN
IF (ship.bullets < SBulletMax) THEN
NEW(bullet); InitSBullet(bullet,ship); INC(ship.bullets);
bullet.next:= F.objects; F.objects:= bullet;
Score(F,-SBulletCost);
END;
END SFire;
PROCEDURE SShield(F: Field; ship: Ship);
(* activate ship's shield - if possible *)
BEGIN
IF (ship.shieldval > 0) THEN
ship.shield:= SShieldGrant; DEC(ship.shieldval); F.changed:= TRUE;
END;
END SShield;
PROCEDURE SWarp(F: Field; ship: Ship);
(* warp to another position - if possible *)
BEGIN
IF (ship.warpval > 0) THEN
DEC(ship.warpval);
ship.x:= RandomNumbers.Uniform() * Display.Width;
ship.y:= RandomNumbers.Uniform() * Display.Height;
ship.xvel:= 0.0; ship.yvel:= 0.0; ship.rot:= 0.0; ship.rotvel:= 0.0;
F.changed:= TRUE;
END;
END SWarp;
PROCEDURE EFire(F: Field; ufo: Enemy);
(* fire an ufo's bullet - if possible *)
VAR
bullet: EBullet;
BEGIN
IF (ufo.bullets < EBulletMax) THEN
NEW(bullet); InitEBullet(bullet,ufo,F.ship); INC(ufo.bullets);
bullet.next:= F.objects; F.objects:= bullet;
END;
END EFire;
PROCEDURE Hit(F: Field; x,y: REAL);
(* produce a nice detonation *)
VAR
det: Detonation;
BEGIN
NEW(det); InitSpaceObj(det); det.x:= x; det.y:= y; det.r0:= 0; det.r:= 0;
det.next:= F.objects; F.objects:= det;
END Hit;
PROCEDURE HitShip(F: Field; obj: Ship);
(* maybe, you're gone. draw detonation and update status *)
BEGIN
IF (obj.shield = 0) & ~Indestructable THEN
Hit(F,obj.px1[0],obj.py1[0]); obj.alive:= FALSE;
DEC(F.ships); F.changed:= TRUE;
END;
END HitShip;
PROCEDURE SplitAsteroid(F: Field; obj: Asteroid; x,y: INTEGER): INTEGER;
(* split asteroid into pieces (ast1->ast2*SplitAsts->ast3*SplitAsts->none *)
VAR
ast: Asteroid;
shp: Shape;
size,i: INTEGER;
BEGIN
IF (obj.shape = shAsteroid1) THEN (* Big Asteroid *)
size:= 1; shp:= shAsteroid2;
ELSIF (obj.shape = shAsteroid2) THEN (* Medium Asteroid *)
size:= 2; shp:= shAsteroid3;
ELSE (* Small Asteroid *)
size:= 3; obj.alive:= FALSE;
END;
IF obj.alive THEN
FOR i:= 1 TO SplitAsts DO
NEW(ast); InitAsteroid(ast,obj,shp,x,y);
ast.next:= F.objects; F.objects:= ast;
END;
END;
RETURN(size);
END SplitAsteroid;
PROCEDURE NewShip(F: Field; x,y: REAL);
(* initialize a new ship and place it somewhere into the field *)
BEGIN
IF (F.ships > 0) THEN
IF (F.ships = StartShips) THEN
NEW(F.ship); F.ship.px2:= NIL; F.ship.py2:= NIL;
END;
InitShip(F.ship,x,y); (* new ships are always static *)
F.ship.next:= F.objects; F.objects:= F.ship; F.changed:= TRUE;
END;
END NewShip;
PROCEDURE NewEnemy(F: Field);
(* initialize a new ufo and place it somewhere into the field *)
VAR
obj: Enemy;
BEGIN
NEW(obj); InitEnemy(obj); INC(F.ufos); (* ufo's are moving *)
obj.next:= F.objects; F.objects:= obj;
END NewEnemy;
PROCEDURE NewRound(F: Field; amt: INTEGER);
(* produce new, big asteroids and place them, amount depends on level *)
VAR
ast: Asteroid;
i: INTEGER;
BEGIN
FOR i:= 1 TO amt DO
NEW(ast); InitAsteroid(ast,NIL,shAsteroid1,1,1);
ast.next:= F.objects; F.objects:= ast;
END;
END NewRound;
PROCEDURE MoveShip(F: Field; obj: Ship);
(* calculate new position of ships' vertices using velocities and thrust *)
VAR
tgt: SpaceObj;
hit: BOOLEAN;
x,y: INTEGER;
swpV: Vertices;
swpS: Shape;
BEGIN
IF (obj.thrust0 # obj.thrust) THEN (* change shapes if or not thrusting *)
swpV:= obj.px1; obj.px1:= obj.px2; obj.px2:= swpV;
swpV:= obj.py1; obj.py1:= obj.py2; obj.py2:= swpV;
swpS:= obj.shape; obj.shape:= obj.shape0; obj.shape0:= swpS;
END;
IF obj.thrust THEN
obj.xvel:= obj.xvel + ShipThrust * ((obj.px1[3] - obj.px1[0]) / 20);
obj.yvel:= obj.yvel + ShipThrust * ((obj.py1[3] - obj.py1[0]) / 20);
END;
MoveMass(obj); obj.rotvel:= 0.0;
tgt:= F.objects; hit:= FALSE;
WHILE ~hit & (tgt # NIL) DO (* check, if ship is hitten *)
IF (tgt IS Asteroid) OR (tgt IS Enemy) THEN
WITH tgt: Mass DO hit:= IntersectMass(obj,tgt,x,y); END;
END;
IF ~hit THEN tgt:= tgt.next; END;