Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7142 siemargl 1
 
2
#ifdef MSDOS
3
#include 
4
#endif
5
6
 
7
#include 
8
#else
9
#include 
10
#include 
11
#endif
12
13
 
14
#include "sst.h"
15
16
 
17
*/
18
19
 
20
static int linecount;	/* for paging */
21
22
 
23
24
 
25
   "call" and the "terminate" command to "quit" to better match
26
   user expectations. The DECUS version apparently made those changes
27
   as well as changing "freeze" to "save". However I like "freeze".
28
29
 
30
   from, I added the emexit command.
31
32
 
33
   docked (using the starbase's scanners), so I made some changes here
34
   to do this (and indicating that fact to the player), and then realized
35
   the base would have a subspace radio as well -- doing a Chart when docked
36
   updates the star chart, and all radio reports will be heard. The Dock
37
   command will also give a report if a base is under attack.
38
39
 
40
   otherwise know it.
41
42
 
43
44
 
45
46
 
47
48
 
49
50
 
51
      move in Expert and Emeritus games. This code could use improvement.
52
53
 
54
55
 
56
57
 
58
59
 
60
// want to invest the time to make this nice and table driven.
61
62
 
63
	"srscan",
64
	"lrscan",
65
	"phasers",
66
	"photons",
67
	"move",
68
	"shields",
69
	"dock",
70
	"damages",
71
	"chart",
72
	"impulse",
73
	"rest",
74
	"warp",
75
	"status",
76
	"sensors",
77
	"orbit",
78
	"transport",
79
	"mine",
80
	"crystals",
81
	"shuttle",
82
	"planets",
83
	"request",
84
	"report",
85
	"computer",
86
	"commands",
87
    "emexit",
88
    "probe",
89
    "cloak",
90
    "capture",
91
    "score",
92
	"abandon",
93
	"destruct",
94
	"freeze",
95
	"deathray",
96
	"debug",
97
	"call",
98
	"quit",
99
    "help"
100
101
 
102
103
 
104
105
 
106
	prout("   SRSCAN    MOVE      PHASERS   CALL\n"
107
		  "   STATUS    IMPULSE   PHOTONS   ABANDON\n"
108
		  "   LRSCAN    WARP      SHIELDS   DESTRUCT\n"
109
		  "   CHART     REST      DOCK      QUIT\n"
110
		  "   DAMAGES   REPORT    SENSORS   ORBIT\n"
111
		  "   TRANSPORT MINE      CRYSTALS  SHUTTLE\n"
112
		  "   PLANETS   REQUEST   DEATHRAY  FREEZE\n"
113
          "   COMPUTER  EMEXIT    PROBE     COMMANDS");
114
    proutn("   ");
115
#ifdef SCORE
116
    proutn("SCORE     ");
117
#endif
118
#ifdef CLOAKING
119
    proutn("CLOAK     ");
120
#endif
121
#ifdef CAPTURE
122
    proutn("CAPTURE   ");
123
#endif
124
    if (x) proutn("HELP     ");
125
    prout("");
126
}
127
128
 
129
	int i, j;
130
	char cmdbuf[32];
131
	char linebuf[132];
132
	FILE *fp;
133
	/* Give help on commands */
134
	int key;
135
	key = scan();
136
	while (TRUE) {
137
		if (key == IHEOL) {
138
			proutn("Help on what command?");
139
			key = scan();
140
		}
141
		if (key == IHEOL) return;
142
		for (i = 0; i < NUMCOMMANDS; i++) {
143
			if (strcmp(commands[i], citem)==0) break;
144
		}
145
		if (i != NUMCOMMANDS) break;
146
		skip(1);
147
		prout("Valid commands:");
148
		listCommands(FALSE);
149
		key = IHEOL;
150
		chew();
151
		skip(1);
152
	}
153
	if (i == 23) {
154
		strcpy(cmdbuf, " ABBREV");
155
	}
156
	else {
157
		strcpy(cmdbuf, "  Mnemonic:  ");
158
		j = 0;
159
		while ((cmdbuf[j+13] = toupper(commands[i][j])) != 0) j++;
160
	}
161
	fp = fopen("sst.doc", "r");
162
	if (fp == NULL) {
163
		prout("Spock-  \"Captain, that information is missing from the");
164
		prout("   computer. You need to find SST.DOC and put it in the");
165
		prout("   current directory.\"");
166
		return;
167
	}
168
	i = strlen(cmdbuf);
169
	do {
170
		if (fgets(linebuf, 132, fp) == NULL) {
171
			prout("Spock- \"Captain, there is no information on that command.\"");
172
			fclose(fp);
173
			return;
174
		}
175
	} while (strncmp(linebuf, cmdbuf, i) != 0);
176
177
 
178
	prout("Spock- \"Captain, I've found the following information:\"");
179
	skip(1);
180
181
 
182
		if (linebuf[0]!=12) { // ignore page break lines
183
			linebuf[strlen(linebuf)-1] = '\0'; // No \n at end
184
			prout(linebuf);
185
		}
186
		fgets(linebuf,132,fp);
187
	} while (strstr(linebuf, "******")==NULL);
188
	fclose(fp);
189
}
190
191
 
192
	int i, hitme;
193
	char ch;
194
	while (TRUE) { /* command loop */
195
		hitme = FALSE;
196
		justin = 0;
197
		Time = 0.0;
198
		i = -1;
199
		while (TRUE)  { /* get a command */
200
			chew();
201
			skip(1);
202
			proutn("COMMAND> ");
203
			if (scan() == IHEOL) continue;
204
			for (i=0; i < 29; i++) // Abbreviations allowed for the first 29 commands, only.
205
				if (isit(commands[i]))
206
					break;
207
			if (i < 29) break;
208
			for (; i < NUMCOMMANDS; i++)
209
				if (strcmp(commands[i], citem) == 0) break;
210
			if (i < NUMCOMMANDS
211
#ifndef CLOAKING
212
			    && i != 26 // ignore the CLOAK command
213
#endif
214
#ifndef CAPTURE
215
			    && i != 27 // ignore the CAPTURE command
216
#endif
217
#ifndef SCORE
218
			    && i != 28 // ignore the SCORE command
219
#endif
220
#ifndef DEBUG
221
			    && i != 33 // ignore the DEBUG command
222
#endif
223
			   ) break;
224
225
 
226
				prout("UNRECOGNIZED COMMAND. LEGAL COMMANDS ARE:");
227
				listCommands(TRUE);
228
			}
229
			else prout("UNRECOGNIZED COMMAND.");
230
		}
231
		switch (i) { /* command switch */
232
			case 0:			// srscan
233
				srscan(1);
234
				break;
235
			case 1:			// lrscan
236
				lrscan();
237
				break;
238
			case 2:			// phasers
239
				phasers();
240
                if (ididit) {
241
#ifdef CLOAKING
242
                    if (irhere && d.date >= ALGERON && !isviolreported && iscloaked) {
243
                        prout("The Romulan ship discovers you are breaking the Treaty of Algeron!");
244
                        ncviol++;
245
                        isviolreported = TRUE;
246
                    }
247
#endif
248
                    hitme = TRUE;
249
                }
250
				break;
251
			case 3:			// photons
252
				photon();
253
                if (ididit) {
254
#ifdef CLOAKING
255
                    if (irhere && d.date >= ALGERON && !isviolreported && iscloaked) {
256
                        prout("The Romulan ship discovers you are breaking the Treaty of Algeron!");
257
                        ncviol++;
258
                        isviolreported = TRUE;
259
                    }
260
#endif
261
                    hitme = TRUE;
262
                }
263
				break;
264
			case 4:			// move
265
				warp(1);
266
				break;
267
			case 5:			// shields
268
				sheild(1);
269
				if (ididit) {
270
					attack(2);
271
					shldchg = 0;
272
				}
273
				break;
274
			case 6:			// dock
275
				dock();
276
				break;
277
			case 7:			// damages
278
				dreprt();
279
				break;
280
			case 8:			// chart
281
				chart(0);
282
				break;
283
			case 9:			// impulse
284
				impuls();
285
				break;
286
			case 10:		// rest
287
				waiting();
288
				if (ididit) hitme = TRUE;
289
				break;
290
			case 11:		// warp
291
				setwrp();
292
				break;
293
			case 12:		// status
294
				srscan(3);
295
				break;
296
			case 13:			// sensors
297
				sensor();
298
				break;
299
			case 14:			// orbit
300
				orbit();
301
				if (ididit) hitme = TRUE;
302
				break;
303
			case 15:			// transport "beam"
304
				beam();
305
				break;
306
			case 16:			// mine
307
				mine();
308
				if (ididit) hitme = TRUE;
309
				break;
310
			case 17:			// crystals
311
				usecrystals();
312
				break;
313
			case 18:			// shuttle
314
				shuttle();
315
				if (ididit) hitme = TRUE;
316
				break;
317
			case 19:			// Planet list
318
				preport();
319
				break;
320
			case 20:			// Status information
321
				srscan(2);
322
				break;
323
			case 21:			// Game Report
324
				report(0);
325
				break;
326
			case 22:			// use COMPUTER!
327
				eta();
328
				break;
329
			case 23:
330
				listCommands(TRUE);
331
				break;
332
			case 24:		// Emergency exit
333
				clearscreen();	// Hide screen
334
				freeze(TRUE);	// forced save
335
#ifdef KOS32
336
				con_exit(1);
337
#endif
338
				exit(1);		// And quick exit
339
				break;
340
			case 25:
341
				probe();		// Launch probe
342
				break;
343
#ifdef CLOAKING
344
			case 26:
345
				cloak();        // turn on/off cloaking
346
				if (iscloaking) {
347
					attack(2); // We will be seen while we cloak
348
					iscloaking = FALSE;
349
					iscloaked = TRUE;
350
				}
351
				break;
352
#endif
353
#ifdef CAPTURE
354
			case 27:
355
				capture();      // Attempt to get Klingon ship to surrender
356
				if (ididit) hitme = TRUE;
357
				break;
358
#endif
359
#ifdef SCORE
360
			case 28:
361
				score(1);    // get the score
362
				break;
363
#endif
364
			case 29:			// Abandon Ship
365
				abandn();
366
				break;
367
			case 30:			// Self Destruct
368
				dstrct();
369
				break;
370
			case 31:			// Save Game
371
				freeze(FALSE);
372
				if (skill > SGOOD)
373
					prout("WARNING--Frozen games produce no plaques!");
374
				break;
375
			case 32:			// Try a desparation measure
376
				deathray();
377
				if (ididit) hitme = TRUE;
378
				break;
379
#ifdef DEBUG
380
			case 33:			// What do we want for debug???
381
				debugme();
382
				break;
383
#endif
384
			case 34:		// Call for help
385
				help();
386
				break;
387
			case 35:
388
				alldone = 1;	// quit the game
389
#ifdef DEBUG
390
				if (idebug) score(0);
391
#endif
392
				break;
393
			case 36:
394
				helpme();	// get help
395
				break;
396
		}
397
		for (;;) {
398
			if (alldone) break;		// Game has ended
399
#ifdef DEBUG
400
			if (idebug) prout("2500");
401
#endif
402
			if (Time != 0.0) {
403
				events();
404
				if (alldone) break;		// Events did us in
405
			}
406
			if (d.galaxy[quadx][quady] == 1000) { // Galaxy went Nova!
407
				atover(0);
408
				continue;
409
			}
410
			if (nenhere == 0) movetho();
411
			if (hitme && justin==0) {
412
				attack(2);
413
				if (alldone) break;
414
				if (d.galaxy[quadx][quady] == 1000) {	// went NOVA!
415
					atover(0);
416
					hitme = TRUE;
417
					continue;
418
				}
419
			}
420
			break;
421
		}
422
		if (alldone) break;
423
	}
424
}
425
426
 
427
 
428
	int i;
429
	int hitme;
430
	char ch;
431
432
 
433
	if (con_init_console_dll()) return 1; // init fail
434
	con_set_title("-SUPER- STAR TREK");
435
	con_set_flags(CON_COLOR_GREEN);
436
#endif
437
438
 
439
440
 
441
		if (strcmp(argv[1], "-f")== 0) {
442
			coordfixed = 1;
443
			argc--;
444
			argv++;
445
		}
446
	}
447
448
 
449
 
450
		fromcommandline = 1;
451
		line[0] = '\0';
452
		while (--argc > 0) {
453
			strcat(line, *(++argv));
454
			strcat(line, " ");
455
		}
456
	}
457
	else fromcommandline = 0;
458
459
 
460
 
461
		setup();
462
		if (alldone) {
463
			score(0);
464
			alldone = 0;
465
		}
466
		else makemoves();
467
		skip(2);
468
		stars();
469
		skip(1);
470
471
 
472
			printf("Do you want your score recorded?");
473
			if (ja()) {
474
				chew2();
475
				freeze(FALSE);
476
			}
477
		}
478
		printf("Do you want to play again?");
479
		if (!ja()) break;
480
	}
481
	skip(1);
482
	prout("May the Great Bird of the Galaxy roost upon your home planet.");
483
	return 0;
484
}
485
486
 
487
 
488
	/* return an enemy */
489
	char *s;
490
491
 
492
		case IHR: s = "Romulan"; break;
493
		case IHK: s = "Klingon"; break;
494
		case IHC: s = "Commander"; break;
495
		case IHS: s = "Super-commander"; break;
496
		case IHSTAR: s = "Star"; break;
497
		case IHP: s = "Planet"; break;
498
		case IHB: s = "Starbase"; break;
499
		case IHBLANK: s = "Black hole"; break;
500
		case IHT: s = "Tholean"; break;
501
		case IHWEB: s = "Tholean web"; break;
502
		default: s = "Unknown??"; break;
503
	}
504
	proutn(s);
505
}
506
507
 
508
	if (key == 1) proutn(" Quadrant");
509
	else if (key == 2) proutn(" Sector");
510
	proutn(" ");
511
	crami(x, 1);
512
	proutn(" - ");
513
	crami(y, 1);
514
}
515
516
 
517
	if (i == 1) proutn("***");
518
	cramen(enemy);
519
	proutn(" at");
520
	cramlc(key, x, y);
521
}
522
523
 
524
	char *s;
525
	switch (ship) {
526
		case IHE: s = "Enterprise"; break;
527
		case IHF: s = "Faerie Queene"; break;
528
		default:  s = "Ship???"; break;
529
	}
530
	proutn(s);
531
}
532
533
 
534
	prouts("******************************************************");
535
	skip(1);
536
}
537
538
 
539
	return -avrage*log(1e-7 + Rand());
540
}
541
542
 
543
	return rand()/(1.0 + (double)RAND_MAX);
544
}
545
546
 
547
	*i = Rand()*8.0 + 1.0;
548
	*j = Rand()*8.0 + 1.0;
549
}
550
551
 
552
	*i = Rand()*10.0 + 1.0;
553
	*j = Rand()*10.0 + 1.0;
554
}
555
556
 
557
	linecount = 0;
558
	linep = line;
559
	*linep = 0;
560
}
561
562
 
563
	/* return IHEOL next time */
564
	linecount = 0;
565
	linep = line+1;
566
	*linep = 0;
567
}
568
569
 
570
	int i;
571
	char *cp;
572
573
 
574
575
 
576
	aaitem = 0.0;
577
	*citem = 0;
578
579
 
580
	if (*linep == 0) {
581
		if (linep != line) {
582
			chew();
583
			return IHEOL;
584
		}
585
#ifdef KOS32
586
		cp = gets(line);
587
		if (!cp) exit();
588
#else
589
		// We should really be using fgets
590
		fgets(line,sizeof(line),stdin);
591
#endif
592
		if (line[strlen(line)-1] == '\n')
593
			line[strlen(line)-1] = '\0';
594
		linep = line;
595
	}
596
	// Skip leading white space
597
	while (*linep == ' ') linep++;
598
	// Nothing left
599
	if (*linep == 0) {
600
		chew();
601
		return IHEOL;
602
	}
603
	if (isdigit(*linep) || *linep=='+' || *linep=='-' || *linep=='.') {
604
		// treat as a number
605
	    if (sscanf(linep, "%lf%n", &aaitem, &i) < 1) {
606
		linep = line; // Invalid numbers are ignored
607
		*linep = 0;
608
		return IHEOL;
609
	    }
610
	    else {
611
		// skip to end
612
		linep += i;
613
		return IHREAL;
614
	    }
615
	}
616
	// Treat as alpha
617
	cp = citem;
618
	while (*linep && *linep!=' ') {
619
		if ((cp - citem) < 9) *cp++ = tolower(*linep);
620
		linep++;
621
	}
622
	*cp = 0;
623
	return IHALPHA;
624
}
625
626
 
627
	chew();
628
	while (TRUE) {
629
		scan();
630
		chew();
631
		if (*citem == 'y') return TRUE;
632
		if (*citem == 'n') return FALSE;
633
		proutn("Please answer with \"Y\" or \"N\":");
634
	}
635
}
636
637
 
638
	char buf[64];
639
	sprintf(buf, "%*.*f", w, d, x);
640
	proutn(buf);
641
}
642
643
 
644
	char buf[16];
645
	sprintf(buf, "%*d", w, i);
646
	proutn(buf);
647
}
648
649
 
650
651
 
652
	/* Somehow we need to clear the screen */
653
	proutn("\033[2J\033[0;0H");	/* Hope for an ANSI display */
654
}
655
656
 
657
658
 
659
#ifdef CLOAKING
660
	if (iscloaked) return;
661
#endif
662
	putchar('\n');
663
	if (i==1) {
664
		if (skill > SFAIR)
665
			prout("[ANNOUNCEMENT ARRIVING...]");
666
		else
667
			prout("[IMPORTANT ANNOUNCEMENT ARRIVING -- HIT ENTER TO CONTINUE]");
668
		getchar();
669
	}
670
	else {
671
		if (skill > SFAIR)
672
			proutn("[CONTINUE?]");
673
		else
674
			proutn("[HIT ENTER TO CONTINUE]");
675
		getchar();
676
		proutn("\r                           \r");
677
	}
678
	if (i != 0) {
679
		clearscreen();
680
	}
681
    linecount = 0;
682
}
683
684
 
685
 
686
	while (i-- > 0) {
687
		linecount++;
688
		if (linecount >= 23)
689
			pause(0);
690
		else
691
			putchar('\n');
692
	}
693
}
694
695
 
696
 
697
#ifndef KOS32
698
	fputs(s, stdout);
699
#else
700
	con_write_asciiz(s);
701
#endif
702
}
703
704
 
705
	proutn(s);
706
	skip(1);
707
}
708
709
 
710
#ifdef KOS32
711
#define clock_t long int
712
#define clock() get_tick_count()
713
#define CLOCKS_PER_SEC 100
714
#endif
715
716
 
717
	/* print slowly! */
718
	while (*s) {
719
		endTime = clock() + CLOCKS_PER_SEC*0.05;
720
		while (clock() < endTime) ;
721
		putchar(*s++);
722
#ifndef KOS32
723
		fflush(stdout);
724
#endif
725
	}
726
}
727
728
 
729
	chew();
730
	skip(1);
731
	prout("Beg your pardon, Captain?");
732
}
733
734
 
735
	/* New function -- compares s to scaned citem and returns true if it
736
	   matches to the length of s */
737
738
 
739
740
 
741
742
 
743
void debugme(void) {
744
	proutn("Reset levels? ");
745
	if (ja() != 0) {
746
		if (energy < inenrg) energy = inenrg;
747
		shield = inshld;
748
		torps = intorps;
749
		lsupres = inlsr;
750
	}
751
	proutn("Reset damage? ");
752
	if (ja() != 0) {
753
		int i;
754
		for (i=0; i <= ndevice; i++) if (damage[i] > 0.0) damage[i] = 0.0;
755
		stdamtim = 1e30;
756
	}
757
	proutn("Toggle idebug? ");
758
	if (ja() != 0) {
759
		idebug = !idebug;
760
		if (idebug) prout("Debug output ON");
761
		else prout("Debug output OFF");
762
	}
763
	proutn("Cause selective damage? ");
764
	if (ja() != 0) {
765
		int i, key;
766
		for (i=1; i <= ndevice; i++) {
767
			proutn("Kill ");
768
			proutn(device[i]);
769
			proutn("? ");
770
			chew();
771
			key = scan();
772
			if (key == IHALPHA &&  isit("y")) {
773
				damage[i] = 10.0;
774
				if (i == DRADIO) stdamtim = d.date;
775
			}
776
		}
777
	}
778
	proutn("Examine/change events? ");
779
	if (ja() != 0) {
780
		int i;
781
		for (i = 1; i < NEVENTS; i++) {
782
			int key;
783
			if (future[i] == 1e30) continue;
784
			switch (i) {
785
				case FSNOVA:  proutn("Supernova       "); break;
786
				case FTBEAM:  proutn("T Beam          "); break;
787
				case FSNAP:   proutn("Snapshot        "); break;
788
				case FBATTAK: proutn("Base Attack     "); break;
789
				case FCDBAS:  proutn("Base Destroy    "); break;
790
				case FSCMOVE: proutn("SC Move         "); break;
791
				case FSCDBAS: proutn("SC Base Destroy "); break;
792
			}
793
			cramf(future[i]-d.date, 8, 2);
794
			chew();
795
			proutn("  ?");
796
			key = scan();
797
			if (key == IHREAL) {
798
				future[i] = d.date + aaitem;
799
			}
800
		}
801
		chew();
802
	}
803
	proutn("Make universe visible? ");
804
	if (ja() != 0) {
805
		int i, j;
806
		for (i = 1; i < 9; i++)
807
		{
808
			for (j = 1; j < 9; j++)
809
			{
810
				starch[i][j] = 1;
811
			}
812
		}
813
	}
814
}
815
816
 
817
 
818