forked from davidgiven/ack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartrek.c
2157 lines (1744 loc) · 43.3 KB
/
startrek.c
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
/*
* startrek.c
*
* Super Star Trek Classic (v1.1)
* Retro Star Trek Game
* C Port Copyright (C) 1996 <Chris Nystrom>
*
* This program is free software; you can redistribute it and/or modify
* in any way that you wish. _Star Trek_ is a trademark of Paramount
* I think.
*
* This program 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.
*
* This is a C port of an old BASIC program: the classic Super Star Trek
* game. It comes from the book _BASIC Computer Games_ edited by David Ahl
* of Creative Computing fame. It was published in 1978 by Workman Publishing,
* 1 West 39 Street, New York, New York, and the ISBN is: 0-89489-052-3.
*
* See http://www.cactus.org/~nystrom/startrek.html for more info.
*
* Contact Author of C port at:
*
* Chris Nystrom
* 1013 Prairie Dove Circle
* Austin, Texas 78758
*
* E-Mail: [email protected], [email protected]
*
* BASIC -> Conversion Issues
*
* - String Names changed from A$ to sA
* - Arrays changed from G(8,8) to g[9][9] so indexes can
* stay the same.
*
* Here is the original BASIC header:
*
* SUPER STARTREK - MAY 16, 1978 - REQUIRES 24K MEMORY
*
*** **** STAR TREK **** ****
*** SIMULATION OF A MISSION OF THE STARSHIP ENTERPRISE,
*** AS SEEN ON THE STAR TREK TV SHOW.
*** ORIGINAL PROGRAM BY MIKE MAYFIELD, MODIFIED VERSION
*** PUBLISHED IN DEC'S "101 BASIC GAMES", BY DAVE AHL.
*** MODIFICATIONS TO THE LATTER (PLUS DEBUGGING) BY BOB
*** LEEDOM - APRIL & DECEMBER 1974,
*** WITH A LITTLE HELP FROM HIS FRIENDS . . .
*** COMMENTS, EPITHETS, AND SUGGESTIONS SOLICITED --
*** SEND TO: R. C. LEEDOM
*** WESTINGHOUSE DEFENSE & ELECTRONICS SYSTEMS CNTR.
*** BOX 746, M.S. 338
*** BALTIMORE, MD 21203
***
*** CONVERTED TO MICROSOFT 8 K BASIC 3/16/78 BY JOHN BORDERS
*** LINE NUMBERS FROM VERSION STREK7 OF 1/12/75 PRESERVED AS
*** MUCH AS POSSIBLE WHILE USING MULTIPLE STATMENTS PER LINE
*
*/
/* For `ack -mcpm -fp`, the i80 code was too big. Make it smaller by
* removing the game's intro and replacing part of libc. */
#ifdef __i80
#define SMALL
#endif
#ifdef SMALL
#include <stdarg.h>
#include <unistd.h>
#else
#include <stdio.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE ! FALSE
#endif
/* Standard Line Length */
#define MAXLEN 255
/* Standard Terminal Sizes */
#define MAXROW 24
#define MAXCOL 80
/* Standard Page Size */
#define MAXLINES 66
/* Useful typedefs */
typedef int bool;
typedef char line[MAXCOL];
typedef char string[MAXLEN];
/* Function Declarations */
void intro(void);
void new_game(void);
void initialize(void);
void new_quadrant(void);
void course_control(void);
void complete_maneuver(void);
void exceed_quadrant_limits(void);
void maneuver_energy(void);
void short_range_scan(void);
void long_range_scan(void);
void phaser_control(void);
void photon_torpedoes(void);
void torpedo_hit(void);
void damage_control(void);
void shield_control(void);
void library_computer(void);
void galactic_record(void);
void status_report(void);
void torpedo_data(void);
void nav_data(void);
void dirdist_calc(void);
void galaxy_map(void);
void end_of_time(void);
void resign_commision(void);
void won_game(void);
void end_of_game(void);
void klingons_move(void);
void klingons_shoot(void);
void repair_damage(void);
void find_empty_place(void);
void insert_in_quadrant(void);
void get_device_name(void);
void string_compare(void);
void quadrant_name(void);
int function_d(int i);
int function_r(void);
void mid_str(char *a, char *b, int x, int y);
int cint(double d);
void compute_vector(void);
void sub1(void);
void sub2(void);
#ifndef SMALL
void showfile(char *filename);
int openfile(char * sFilename, char * sMode);
void closefile(void);
int get_line(char *s);
#endif
void randomize(void);
int get_rand(int iSpread);
double rnd(void);
#ifdef SMALL
#undef atof
#define atof trek_atof
#define getchar trek_getchar
#define putchar trek_putchar
#define printf trek_printf
double atof(const char *);
static int getchar(void);
static void putchar(int c);
void printf(const char *fmt, ...);
#endif
/* Global Variables */
int b3; /* Starbases in Quadrant */
int b4, b5; /* Starbase Location in sector */
int b9; /* Total Starbases */
/* @@@ int c[2][10] = */ /* Used for location and movement */
int c[3][10] = /* modified to match MS BASIC array indicies */
{
{ 0 },
{ 0, 0, -1, -1, -1, 0, 1, 1, 1, 0 },
{ 1, 1, 1, 0, -1, -1, -1, 0, 1, 1 }
};
int d0; /* Docked flag */
int d1; /* Damage Repair Flag */
int e; /* Current Energy */
int e0 = 3000; /* Starting Energy */
int g[9][9]; /* Galaxy */
int g5; /* Quadrant name flag */
int k[4][4]; /* Klingon Data */
int k3; /* Klingons in Quadrant */
int k7; /* Klingons at start */
int k9; /* Total Klingons left */
int n; /* Number of secors to travel */
int p; /* Photon Torpedoes left */
int p0 = 10; /* Photon Torpedo capacity */
int q1, q2; /* Quadrant Position of Enterprise */
int r1, r2; /* Temporary Location Corrdinates */
int s; /* Current shield value */
int s3; /* Stars in quadrant */
int s8; /* Quadrant locating index */
int s9 = 200; /* Klingon Power */
int t0; /* Starting Stardate */
int t9; /* End of time */
int z[9][9]; /* Cumulative Record of Galaxy */
int z3; /* string_compare return value */
int z1, z2; /* Temporary Sector Coordinates */
int z4, z5; /* Temporary quadrant coordinates */
double a, c1; /* Used by Library Computer */
double d[9]; /* Damage Array */
double d4; /* Used for computing damage repair time */
double s1, s2; /* Current Sector Position of Enterprise */
double t; /* Current Stardate */
double w1; /* Warp Factor */
double x, y, x1, x2; /* Navigational coordinates */
char sA[4]; /* An Object in a Sector */
char sC[7]; /* Condition */
char sQ[194]; /* Visual Display of Quadrant */
string sG2; /* Used to pass string results */
#ifndef SMALL
FILE *stream;
bool bFlag = FALSE; /* Prevent multiple file opens */
#endif
void
reads(char* buffer)
{
#ifdef SMALL
read(0, buffer, sizeof(string));
#else
fflush(stdout);
fgets(buffer, sizeof(string), stdin);
#endif
}
/* Main Program */
int
main(void)
{
intro();
new_game();
/* @@@ exit(0); */ /* causes a warning in C++ */
return(0);
}
void
intro(void)
{
string sTemp;
#ifndef SMALL
printf ("\n\n");
printf (" *************************************\n");
printf (" * *\n");
printf (" * *\n");
printf (" * * * Super Star Trek * * *\n");
printf (" * *\n");
printf (" * *\n");
printf (" *************************************\n\n\n\n\n");
printf("\nDo you need instructions (y/n): ");
reads(sTemp);
if (sTemp[0] == 'y' || sTemp[0] == 'Y')
showfile("startrek.doc");
#endif /* !SMALL */
printf ("\n\n\n\n\n\n\n");
printf(" ------*------\n");
printf(" ------------- `--- ------'\n");
printf(" `-------- --' / /\n");
printf(" \\\\------- --\n");
printf(" '-----------'\n");
printf("\n The USS Enterprise --- NCC - 1701\n\n\n");
randomize();
t = (get_rand(20) + 20) * 100;
}
void
new_game(void)
{
string sTemp;
initialize();
new_quadrant();
short_range_scan();
while(1)
{
if (s + e <= 10 && (e < 10 || d[7] < 0))
{
printf("\n** Fatal Error ** ");
printf("You've just stranded your ship in space.\n\n");
printf("You have insufficient maneuvering energy,");
printf(" and Shield Control is presently\n");
printf("incapable of cross circuiting to engine room!!\n\n");
end_of_time();
}
printf("Command? ");
reads(sTemp);
printf("\n");
if (! strncmp(sTemp, "nav", 3))
course_control();
else if (! strncmp(sTemp, "srs", 3))
short_range_scan();
else if (! strncmp(sTemp, "lrs", 3))
long_range_scan();
else if (! strncmp(sTemp, "pha", 3))
phaser_control();
else if (! strncmp(sTemp, "tor", 3))
photon_torpedoes();
else if (! strncmp(sTemp, "she", 3))
shield_control();
else if (! strncmp(sTemp, "dam", 3))
damage_control();
else if (! strncmp(sTemp, "com", 3))
library_computer();
else if (! strncmp(sTemp, "xxx", 3))
resign_commision();
else
{
printf("Enter one of the following:\n\n");
printf(" nav - To Set Course\n");
printf(" srs - Short Range Sensors\n");
printf(" lrs - Long Range Sensors\n");
printf(" pha - Phasers\n");
printf(" tor - Photon Torpedoes\n");
printf(" she - Shield Control\n");
printf(" dam - Damage Control\n");
printf(" com - Library Computer\n");
printf(" xxx - Resign Command\n");
printf("\n");
}
}
}
void
initialize(void)
{
int i, j;
char sX[2] = "";
char sX0[4] = "is";
/* InItialize time */
/* @@@ t0 = t; */
t0 = (int)t;
t9 = 25 + get_rand(10);
/* Initialize Enterprise */
d0 = 0;
e = e0;
p = p0;
s = 0;
q1 = function_r();
q2 = function_r();
s1 = (double) function_r();
s2 = (double) function_r();
for (i = 1; i <= 8; i++)
d[i] = 0.0;
/* Setup What Exists in Galaxy */
for (i = 1; i <= 8; i++)
for (j = 1; j <= 8; j++)
{
k3 = 0;
z[i][j] = 0;
r1 = get_rand(100);
if (r1 > 98)
k3 = 3;
else if (r1 > 95)
k3 = 2;
else if (r1 > 80)
k3 = 1;
k9 = k9 + k3;
b3 = 0;
if (get_rand(100) > 96)
b3 = 1;
b9 = b9 + b3;
g[i][j] = k3 * 100 + b3 * 10 + function_r();
}
if (k9 > t9)
t9 = k9 + 1;
if (b9 == 0)
{
if (g[q1][q2] < 200)
{
g[q1][q2] = g[q1][q2] + 100;
k9++;
}
g[q1][q2] = g[q1][q2] + 10;
b9++;
q1 = function_r();
q2 = function_r();
}
k7 = k9;
if (b9 != 1)
{
strcpy(sX, "s");
strcpy(sX0, "are");
}
printf("Your orders are as follows:\n\n");
printf(" Destroy the %d Klingon warships which have invaded\n", k9);
printf(" the galaxy before they can attack Federation Headquarters\n");
printf(" on stardate %d. This gives you %d days. There %s\n",
t0 + t9, t9, sX0);
printf(" %d starbase%s in the galaxy for resupplying your ship.\n\n",
b9, sX);
printf("Hit any key to accept command. ");
getchar();
}
void
new_quadrant(void)
{
int i;
z4 = q1;
z5 = q2;
k3 = 0;
b3 = 0;
s3 = 0;
g5 = 0;
d4 = (double) get_rand(100) / 100 / 50;
z[q1][q2] = g[q1][q2];
if (q1 >= 1 && q1 <= 8 && q2 >= 1 && q2 <= 8)
{
quadrant_name();
if (t0 != t)
printf("Now entering %s quadrant...\n\n", sG2);
else
{
printf("\nYour mission begins with your starship located\n");
printf("in the galactic quadrant %s.\n\n", sG2);
}
}
/* @@@ k3 = g[q1][q2] * .01; */
k3 = (int)(g[q1][q2] * .01);
/* @@@ b3 = g[q1][q2] * .1 - 10 * k3; */
b3 = (int)(g[q1][q2] * .1 - 10 * k3);
s3 = g[q1][q2] - 100 * k3 - 10 * b3;
if (k3 > 0)
{
printf("Combat Area Condition Red\n");
if (s < 200)
printf("Shields Dangerously Low\n");
}
for (i = 1; i <= 3; i++)
{
k[i][1] = 0;
k[i][2] = 0;
k[i][3] = 0;
}
for (i = 0; i <= 192; i++)
sQ[i] = ' ';
sQ[193] = '\0';
/* Position Enterprise, then Klingons, Starbases, and stars */
strcpy(sA, "<*>");
/* @@@ z1 = cint(s1); */
z1 = (int)s1;
/* @@@ z2 = cint(s2); */
z2 = (int)s2;
insert_in_quadrant();
if (k3 > 0)
{
for (i = 1; i <= k3; i++)
{
find_empty_place();
strcpy(sA, "+K+");
z1 = r1;
z2 = r2;
insert_in_quadrant();
k[i][1] = r1;
k[i][2] = r2;
k[i][3] = 100 + get_rand(200);
}
}
if (b3 > 0)
{
find_empty_place();
strcpy(sA, ">!<");
z1 = r1;
z2 = r2;
insert_in_quadrant();
b4 = r1;
b5 = r2;
}
for (i = 1; i <= s3; i++)
{
find_empty_place();
strcpy(sA, " * ");
z1 = r1;
z2 = r2;
insert_in_quadrant();
}
}
void
course_control(void)
{
register i;
/* @@@ int c2, c3, q4, q5; */
int q4, q5;
string sTemp;
double c1;
char sX[4] = "8";
printf("Course (0-9): ");
reads(sTemp);
printf("\n");
c1 = atof(sTemp);
if (c1 == 9.0)
c1 = 1.0;
if (c1 < 0 || c1 > 9.0)
{
printf("Lt. Sulu roports:\n");
printf(" Incorrect course data, sir!\n\n");
return;
}
if (d[1] < 0.0)
strcpy(sX, "0.2");
printf("Warp Factor (0-%s): ", sX);
reads(sTemp);
printf("\n");
w1 = atof(sTemp);
if (d[1] < 0.0 && w1 > 0.21)
{
printf("Warp Engines are damaged. ");
printf("Maximum speed = Warp 0.2.\n\n");
return;
}
if (w1 <= 0.0)
return;
if (w1 > 8.1)
{
printf("Chief Engineer Scott reports:\n");
printf(" The engines won't take warp %4.1f!\n\n", w1);
return;
}
n = cint(w1 * 8.0); /* @@@ note: this is a real round in the original basic */
if (e - n < 0)
{
printf("Engineering reports:\n");
printf(" Insufficient energy available for maneuvering");
printf(" at warp %4.1f!\n\n", w1);
if (s >= n && d[7] >= 0.0)
{
printf("Deflector Control Room acknowledges:\n");
printf(" %d units of energy presently deployed to shields.\n", s);
}
return;
}
klingons_move();
repair_damage();
strcpy(sA, " ");
/* @@@ z1 = cint(s1); */
z1 = (int)s1;
/* @@@ z2 = cint(s2); */
z2 = (int)s2;
insert_in_quadrant();
/* @@@ c2 = cint(c1); */
/* @@@ c3 = c2 + 1; */
/* @@@ x1 = c[0][c2] + (c[0][c3] - c[0][c2]) * (c1 - c2); */
/* @@@ x2 = c[1][c2] + (c[1][c3] - c[1][c2]) * (c1 - c2); */
x1 = c[1][(int)c1] + (c[1][(int)c1 + 1] - c[1][(int)c1]) * (c1 - (int)c1);
x2 = c[2][(int)c1] + (c[2][(int)c1 + 1] - c[2][(int)c1]) * (c1 - (int)c1);
x = s1;
y = s2;
q4 = q1;
q5 = q2;
for (i = 1; i <= n; i++)
{
s1 = s1 + x1;
s2 = s2 + x2;
/* @@@ z1 = cint(s1); */
z1 = (int)s1;
/* @@@ z2 = cint(s2); */
z2 = (int)s2;
if (z1 < 1 || z1 >= 9 || z2 < 1 || z2 >= 9)
{
exceed_quadrant_limits();
complete_maneuver();
return;
}
string_compare();
if (z3 != 1) /* Sector not empty */
{
s1 = s1 - x1;
s2 = s2 - x2;
printf("Warp Engines shut down at sector ");
printf("%d, %d due to bad navigation.\n\n", z1, z2);
i = n + 1;
}
}
complete_maneuver();
}
void
complete_maneuver(void)
{
double t8;
strcpy(sA, "<*>");
/* @@@ z1 = cint(s1); */
z1 = (int)s1;
/* @@@ z2 = cint(s2); */
z2 = (int)s2;
insert_in_quadrant();
maneuver_energy();
t8 = 1.0;
if (w1 < 1.0)
t8 = w1;
t = t + t8;
if (t > t0 + t9)
end_of_time();
short_range_scan();
}
void
exceed_quadrant_limits(void)
{
int x5 = 0; /* Outside galaxy flag */
/* @@@ x = (8 * (q1 - 1)) + x + (n * x1); */
x = (8 * q1) + x + (n * x1);
/* @@@ y = (8 * (q2 - 1)) + y + (n * x2); */
y = (8 * q2) + y + (n * x2);
/* @@@ q1 = cint(x / 8.0); */
q1 = (int)(x / 8.0);
/* @@@ q2 = cint(y / 8.0); */
q2 = (int)(y / 8.0);
/* @@@ s1 = x - ((q1 - 1) * 8); */
s1 = x - (q1 * 8);
/* @@@ s2 = y - ((q2 - 1) * 8); */
s2 = y - (q2 * 8);
/* @@@ if (cint(s1) == 0) */
if ((int)s1 == 0)
{
q1 = q1 - 1;
s1 = s1 + 8.0;
}
/* @@@ if (cint(s2) == 0) */
if ((int)s2 == 0)
{
q2 = q2 - 1;
s2 = s2 + 8.0;
}
/* check if outside galaxy */
if (q1 < 1)
{
x5 = 1;
q1 = 1;
s1 = 1.0;
}
if (q1 > 8)
{
x5 = 1;
q1 = 8;
s1 = 8.0;
}
if (q2 < 1)
{
x5 = 1;
q2 = 1;
s2 = 1.0;
}
if (q2 > 8)
{
x5 = 1;
q2 = 8;
s2 = 8.0;
}
if (x5 == 1)
{
printf("LT. Uhura reports:\n");
printf(" Message from Starfleet Command:\n\n");
printf(" Permission to attempt crossing of galactic perimeter\n");
printf(" is hereby *denied*. Shut down your engines.\n\n");
printf("Chief Engineer Scott reports:\n");
/* @@@ printf(" Warp Engines shut down at sector %d, ", cint(s1)); */
printf(" Warp Engines shut down at sector %d, ", (int)s1);
/* @@@ printf("%d of quadrant %d, %d.\n\n", cint(s2), q1, q2); */
printf("%d of quadrant %d, %d.\n\n", (int)s2, q1, q2);
}
/* else
new_quadrant(); @@@ this causes bugs when bouncing off galaxy walls.
basically, if you bounce very far, your quadrant contents
won't match your LRS. Cool huh? */
maneuver_energy();
/* this section has a different order in the original.
t = t + 1;
if (t > t0 + t9)
end_of_time();
*/
if (t > t0 + t9)
end_of_time();
/* @@@ what does this do?? It's in the original.
if (8 * q1 + q2 = 8 * q4 + q5)
{
complete_maneuver();
}
*/
t = t + 1;
new_quadrant();
}
void
maneuver_energy(void)
{
e = e - n - 10;
if (e >= 0)
return;
printf("Shield Control supplies energy to complete maneuver.\n\n");
s = s + e;
e = 0;
if (s <= 0)
s = 0;
}
void
short_range_scan(void)
{
register i, j;
strcpy(sC, "GREEN");
if (e < e0 * .1)
strcpy(sC, "YELLOW");
if (k3 > 0)
strcpy(sC, "*RED*");
/* @@@ need to clear the docked flag here */
d0 = 0;
/* @@@ for (i = s1 - 1; i <= s1 + 1; i++) */
for (i = (int)(s1 - 1); i <= (int)(s1 + 1); i++)
/* @@@ for (j = s2 - 1; j <= s2 + 1; j++) */
for (j = (int)(s2 - 1); j <= (int)(s2 + 1); j++)
if (i >= 1 && i <= 8 && j >= 1 && j <= 8)
{
strcpy(sA, ">!<");
z1 = i;
z2 = j;
string_compare();
if (z3 == 1)
{
d0 = 1;
strcpy(sC, "DOCKED");
e = e0;
p = p0;
printf("Shields dropped for docking purposes.\n");
s = 0;
}
}
if (d[2] < 0.0)
{
printf("\n*** Short Range Sensors are out ***\n");
return;
}
printf("------------------------\n");
for (i = 0; i < 8; i++)
{
for (j = 0; j < 24; j++)
putchar(sQ[i * 24 + j]);
if (i == 0)
printf(" Stardate %d\n", (int) t);
if (i == 1)
printf(" Condition %s\n", sC);
if (i == 2)
printf(" Quadrant %d, %d\n", q1, q2);
if (i == 3)
/* @@@ printf(" Sector %d, %d\n", cint(s1), cint(s2)); */
printf(" Sector %d, %d\n", (int)s1, (int)s2);
if (i == 4)
printf(" Photon Torpedoes %d\n", p);
if (i == 5)
printf(" Total Energy %d\n", e + s);
if (i == 6)
printf(" Shields %d\n", s);
if (i == 7)
printf(" Klingons Remaining %d\n", k9);
}
printf("------------------------\n\n");
return;
}
void
long_range_scan(void)
{
register i, j;
if (d[3] < 0.0)
{
printf("Long Range Sensors are inoperable.\n");
return;
}
printf("Long Range Scan for Quadrant %d, %d\n\n", q1, q2);
for (i = q1 - 1; i <= q1 + 1; i++)
{
printf("--------------------\n:");
for (j = q2 - 1; j <= q2 + 1; j++)
if (i > 0 && i <= 8 && j > 0 && j <= 8)
{
z[i][j] = g[i][j];
printf(" %3.3d :", z[i][j]);
}
else
printf(" *** :");
printf("\n");
}
printf("--------------------\n\n");
}
void
phaser_control(void)
{
register i;
int iEnergy;
int h1, h;
string sTemp;
if (d[4] < 0.0)
{
printf("Phasers Inoperative\n\n");
return;
}
if (k3 <= 0)
{
printf("Science Officer Spock reports:\n");
printf(" 'Sensors show no enemy ships in this quadrant'\n\n");
return;
}
if (d[8] < 0.0)
/* @@@ printf("Computer failure happers accuracy.\n"); */
printf("Computer failure hampers accuracy.\n");
printf("Phasers locked on target;\n");
printf("Energy available = %d units\n\n", e);
printf("Number of units to fire: ");
reads(sTemp);
printf("\n");
iEnergy = atoi(sTemp);
if (iEnergy <= 0)
return;
if (e - iEnergy < 0)
{
printf("Not enough energy available.\n\n");
return;
}
e = e - iEnergy;
if (d[8] < 0.0)
/* @@@ iEnergy = iEnergy * rnd(); */
iEnergy = (int)(iEnergy * rnd());
h1 = iEnergy / k3;
for (i = 1; i <= 3; i++)
{
if (k[i][3] > 0)
{
/* @@@ h = (h1 / function_d(0) * (rnd() + 2)); */
h = (int)(h1 / function_d(0) * (rnd() + 2));
if (h <= .15 * k[i][3])
{
printf("Sensors show no damage to enemy at ");
printf("%d, %d\n\n", k[i][1], k[i][2]);
}
else
{
k[i][3] = k[i][3] - h;
printf("%d unit hit on Klingon at sector ", h);
printf("%d, %d\n", k[i][1], k[i][2]);
if (k[i][3] <= 0)
{
printf("*** Klingon Destroyed ***\n\n");
k3--;