Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7142 siemargl 1
#include "sst.h"
2
#include 
3
#include 
4
#include 
5
 
6
void attakreport(void) {
7
	if (future[FCDBAS] < 1e30) {
8
		proutn("Starbase in ");
9
		cramlc(1, batx, baty);
10
		prout(" is currently under attack.");
11
		proutn("It can hold out until Stardate ");
12
		cramf(future[FCDBAS], 0,1);
13
		prout(".");
14
	}
15
	if (isatb == 1) {
16
		proutn("Starbase in ");
17
		cramlc(1, d.isx, d.isy);
18
		prout(" is under Super-commander attack.");
19
		proutn("It can hold out until Stardate ");
20
		cramf(future[FSCDBAS], 0, 1);
21
		prout(".");
22
	}
23
}
24
 
25
 
26
void report(int f) {
27
	char *s1,*s2,*s3;
28
 
29
	chew();
30
	s1 = (thawed?"thawed ":"");
31
	switch (length) {
32
		case 1: s2="short"; break;
33
		case 2: s2="medium"; break;
34
		case 4: s2="long"; break;
35
		default: s2="unknown length"; break;
36
	}
37
	switch (skill) {
38
		case SNOVICE: s3="novice"; break;
39
		case SFAIR: s3="fair"; break;
40
		case SGOOD: s3="good"; break;
41
		case SEXPERT: s3="expert"; break;
42
		case SEMERITUS: s3="emeritus"; break;
43
		default: s3="skilled"; break;
44
	}
45
	printf("\nYou %s playing a %s%s %s game.\n",
46
		   alldone? "were": "are now", s1, s2, s3);
47
	if (skill>SGOOD && thawed && !alldone) prout("No plaque is allowed.");
48
	if (tourn) printf("This is tournament game %d.\n", tourn);
49
	if (f) printf("Your secret password is \"%s\"\n",passwd);
50
	printf("%d of %d Klingon ships have been destroyed",
51
		   d.killk+d.killc+d.nsckill, inkling);
52
	if (d.killc) printf(", including %d Commander%s.\n", d.killc, d.killc==1?"":"s");
53
	else if (d.killk+d.nsckill > 0) prout(", but no Commanders.");
54
	else prout(".");
55
	if (skill > SFAIR) printf("The Super Commander has %sbeen destroyed.\n",
56
						  d.nscrem?"not ":"");
57
	if (d.rembase != inbase) {
58
		proutn("There ");
59
		if (inbase-d.rembase==1) proutn("has been 1 base");
60
		else {
61
			proutn("have been ");
62
			crami(inbase-d.rembase, 1);
63
			proutn(" bases");
64
		}
65
		proutn(" destroyed, ");
66
		crami(d.rembase, 1);
67
		prout(" remaining.");
68
	}
69
	else printf("There are %d bases.\n", inbase);
70
	if (REPORTS || iseenit) {
71
		/* Don't report this if not seen and
72
			either the radio is dead or not at base! */
73
		attakreport();
74
		iseenit = 1;
75
	}
76
	if (casual) printf("%d casualt%s suffered so far.\n",
77
					   casual, casual==1? "y" : "ies");
78
#ifdef CAPTURE
79
    if (brigcapacity != brigfree) printf("%d Klingon%s in brig.\n",
80
    							brigcapacity-brigfree, brigcapacity-brigfree>1 ? "s" : "");
81
    if (kcaptured > 0) printf("%d captured Klingon%s turned in to Star Fleet.\n",
82
                               kcaptured, kcaptured>1 ? "s" : "");
83
#endif
84
	if (nhelp) printf("There were %d call%s for help.\n",
85
					  nhelp, nhelp==1 ? "" : "s");
86
	if (ship == IHE) {
87
		proutn("You have ");
88
		if (nprobes) crami(nprobes,1);
89
		else proutn("no");
90
		proutn(" deep space probe");
91
		if (nprobes!=1) proutn("s");
92
		prout(".");
93
	}
94
	if (REPORTS && future[FDSPROB] != 1e30) {
95
		if (isarmed)
96
			proutn("An armed deep space probe is in");
97
		else
98
			proutn("A deep space probe is in");
99
		cramlc(1, probecx, probecy);
100
		prout(".");
101
	}
102
	if (icrystl) {
103
		if (cryprob <= .05)
104
			prout("Dilithium crystals aboard ship...not yet used.");
105
		else {
106
			int i=0;
107
			double ai = 0.05;
108
			while (cryprob > ai) {
109
				ai *= 2.0;
110
				i++;
111
			}
112
			printf("Dilithium crystals have been used %d time%s.\n",
113
				   i, i==1? "" : "s");
114
		}
115
	}
116
	skip(1);
117
}
118
 
119
void lrscan(void) {
120
	int x, y;
121
	chew();
122
	if (damage[DLRSENS] != 0.0) {
123
		/* Now allow base's sensors if docked */
124
		if (condit != IHDOCKED) {
125
			prout("LONG-RANGE SENSORS DAMAGED.");
126
			return;
127
		}
128
		skip(1);
129
		proutn("Starbase's long-range scan for");
130
	}
131
	else {
132
		skip(1);
133
		proutn("Long-range scan for");
134
	}
135
	cramlc(1, quadx, quady);
136
	skip(1);
137
	if (coordfixed)
138
	for (y = quady+1; y >= quady-1; y--) {
139
		for (x = quadx-1; x <= quadx+1; x++) {
140
			if (x == 0 || x > 8 || y == 0 || y > 8)
141
				printf("   -1");
142
			else {
143
				printf("%5d", d.galaxy[x][y]);
144
				// If radio works, mark star chart so
145
				// it will show current information.
146
				// Otherwise mark with current
147
				// value which is fixed.
148
				starch[x][y] = damage[DRADIO] > 0 ? d.galaxy[x][y]+1000 :1;
149
			}
150
		}
151
		putchar('\n');
152
	}
153
	else
154
	for (x = quadx-1; x <= quadx+1; x++) {
155
		for (y = quady-1; y <= quady+1; y++) {
156
			if (x == 0 || x > 8 || y == 0 || y > 8)
157
				printf("   -1");
158
			else {
159
				printf("%5d", d.galaxy[x][y]);
160
				// If radio works, mark star chart so
161
				// it will show current information.
162
				// Otherwise mark with current
163
				// value which is fixed.
164
				starch[x][y] = damage[DRADIO] > 0 ? d.galaxy[x][y]+1000 :1;
165
			}
166
		}
167
		putchar('\n');
168
	}
169
 
170
}
171
 
172
void dreprt(void) {
173
	int jdam = FALSE, i;
174
	chew();
175
 
176
	for (i = 1; i <= ndevice; i++) {
177
		if (damage[i] > 0.0) {
178
			if (!jdam) {
179
				skip(1);
180
				prout("DEVICE            -REPAIR TIMES-");
181
				prout("                IN FLIGHT   DOCKED");
182
				jdam = TRUE;
183
			}
184
			printf("  %16s ", device[i]);
185
			cramf(damage[i]+0.05, 8, 2);
186
			proutn("  ");
187
			cramf(docfac*damage[i]+0.005, 8, 2);
188
			skip(1);
189
		}
190
	}
191
	if (!jdam) prout("All devices functional.");
192
}
193
 
194
void chart(int nn) {
195
	int i,j;
196
 
197
	chew();
198
	skip(1);
199
	if (stdamtim != 1e30 && stdamtim != d.date && condit == IHDOCKED) {
200
		prout("Spock-  \"I revised the Star Chart from the");
201
		prout("  starbase's records.\"");
202
		skip(1);
203
	}
204
	if (nn == 0) prout("STAR CHART FOR THE KNOWN GALAXY");
205
	if (stdamtim != 1e30) {
206
		if (condit == IHDOCKED) {
207
			/* We are docked, so restore chart from base information -- these values won't update! */
208
			stdamtim = d.date;
209
			for (i=1; i <= 8 ; i++)
210
				for (j=1; j <= 8; j++)
211
					if (starch[i][j] == 1) starch[i][j] = d.galaxy[i][j]+1000;
212
		}
213
		else {
214
			proutn("(Last surveillance update ");
215
			cramf(d.date-stdamtim, 0, 1);
216
			prout(" stardates ago.)");
217
		}
218
	}
219
	if (nn ==0) skip(1);
220
 
221
	prout("      1    2    3    4    5    6    7    8");
222
	prout("    ----------------------------------------");
223
	if (nn==0) prout("  -");
224
	if (coordfixed)
225
	for (j = 8; j >= 1; j--) {
226
		printf("%d -", j);
227
		for (i = 1; i <= 8; i++) {
228
			if (starch[i][j] < 0) // We know only about the bases
229
				printf("  .1.");
230
			else if (starch[i][j] == 0) // Unknown
231
				printf("  ...");
232
			else if (starch[i][j] > 999) // Memorized value
233
				printf("%5d", starch[i][j]-1000);
234
			else
235
				printf("%5d", d.galaxy[i][j]); // What is actually there (happens when value is 1)
236
		}
237
		prout("  -");
238
	}
239
	else
240
	for (i = 1; i <= 8; i++) {
241
		printf("%d -", i);
242
		for (j = 1; j <= 8; j++) {
243
			if (starch[i][j] < 0) // We know only about the bases
244
				printf("  .1.");
245
			else if (starch[i][j] == 0) // Unknown
246
				printf("  ...");
247
			else if (starch[i][j] > 999) // Memorized value
248
				printf("%5d", starch[i][j]-1000);
249
			else
250
				printf("%5d", d.galaxy[i][j]); // What is actually there (happens when value is 1)
251
		}
252
		prout("  -");
253
	}
254
	if (nn == 0) {
255
		skip(1);
256
		crmshp();
257
		proutn(" is currently in");
258
		cramlc(1, quadx, quady);
259
		skip(1);
260
	}
261
}
262
 
263
 
264
void srscan(int l) {
265
	static char requests[][3] =
266
		{"","da","co","po","ls","wa","en","to","sh","kl","ti"};
267
	char *cp;
268
	int leftside=TRUE, rightside=TRUE, i, j, jj, k=0, nn=FALSE;
269
	int goodScan=TRUE;
270
	switch (l) {
271
		case 1: // SRSCAN
272
			if (damage[DSRSENS] != 0) {
273
				/* Allow base's sensors if docked */
274
				if (condit != IHDOCKED) {
275
					prout("SHORT-RANGE SENSORS DAMAGED");
276
					goodScan=FALSE;
277
				}
278
				else
279
					prout("[Using starbase's sensors]");
280
			}
281
			if (goodScan)
282
				starch[quadx][quady] = damage[DRADIO]>0.0 ?
283
									   d.galaxy[quadx][quady]+1000:1;
284
			scan();
285
			if (isit("chart")) nn = TRUE;
286
			if (isit("no")) rightside = FALSE;
287
			chew();
288
			prout("\n    1 2 3 4 5 6 7 8 9 10");
289
			break;
290
		case 2: // REQUEST
291
			while (scan() == IHEOL)
292
				printf("Information desired? ");
293
			chew();
294
			for (k = 1; k <= 10; k++)
295
				if (strncmp(citem,requests[k],min(2,strlen(citem)))==0)
296
					break;
297
			if (k > 10) {
298
				prout("UNRECOGNIZED REQUEST. Legal requests are:\n"
299
					 "  date, condition, position, lsupport, warpfactor,\n"
300
					 "  energy, torpedoes, shields, klingons, time.");
301
				return;
302
			}
303
			// no "break"
304
		case 3: // STATUS
305
			chew();
306
			leftside = FALSE;
307
			skip(1);
308
	}
309
	for (i = 1; i <= 10; i++) {
310
		int jj = (k!=0 ? k : i);
311
		if (leftside) {
312
			if (coordfixed) {
313
				printf("%2d  ", 11-i);
314
				for (j = 1; j <= 10; j++) {
315
					if (goodScan || (abs((11-i)-secty)<= 1 && abs(j-sectx) <= 1))
316
						printf("%c ",quad[j][11-i]);
317
					else
318
						printf("- ");
319
				}
320
			} else {
321
				printf("%2d  ", i);
322
				for (j = 1; j <= 10; j++) {
323
					if (goodScan || (abs(i-sectx)<= 1 && abs(j-secty) <= 1))
324
						printf("%c ",quad[i][j]);
325
					else
326
						printf("- ");
327
				}
328
			}
329
		}
330
		if (rightside) {
331
			switch (jj) {
332
				case 1:
333
					printf(" Stardate      %.1f", d.date);
334
					break;
335
				case 2:
336
					if (condit != IHDOCKED) newcnd();
337
					switch (condit) {
338
						case IHRED: cp = "RED"; break;
339
						case IHGREEN: cp = "GREEN"; break;
340
						case IHYELLOW: cp = "YELLOW"; break;
341
						case IHDOCKED: cp = "DOCKED"; break;
342
					}
343
					printf(" Condition     %s", cp);
344
#ifdef CLOAKING
345
				    if (iscloaked) printf(", CLOAKED");
346
#endif
347
					break;
348
				case 3:
349
					printf(" Position     ");
350
					cramlc(0, quadx, quady);
351
					putchar(',');
352
					cramlc(0, sectx, secty);
353
					break;
354
				case 4:
355
					printf(" Life Support  ");
356
					if (damage[DLIFSUP] != 0.0) {
357
						if (condit == IHDOCKED)
358
							printf("DAMAGED, supported by starbase");
359
						else
360
							printf("DAMAGED, reserves=%4.2f", lsupres);
361
					}
362
					else
363
						printf("ACTIVE");
364
					break;
365
				case 5:
366
					printf(" Warp Factor   %.1f", warpfac);
367
					break;
368
				case 6:
369
					printf(" Energy        %.2f", energy);
370
					break;
371
				case 7:
372
					printf(" Torpedoes     %d", torps);
373
					break;
374
				case 8:
375
					printf(" Shields       ");
376
					if (damage[DSHIELD] != 0)
377
						printf("DAMAGED,");
378
					else if (shldup)
379
						printf("UP,");
380
					else
381
						printf("DOWN,");
382
					printf(" %d%% %.1f units",
383
						   (int)((100.0*shield)/inshld + 0.5), shield);
384
					break;
385
				case 9:
386
					printf(" Klingons Left %d", d.remkl);
387
					break;
388
				case 10:
389
					printf(" Time Left     %.2f", d.remtime);
390
					break;
391
			}
392
 
393
		}
394
		skip(1);
395
		if (k!=0) return;
396
	}
397
	if (nn) chart(1);
398
}
399
 
400
 
401
void eta(void) {
402
	int key, ix1, ix2, iy1, iy2, prompt=FALSE;
403
	int wfl;
404
	double ttime, twarp, tpower;
405
	if (damage[DCOMPTR] != 0.0) {
406
		prout("COMPUTER DAMAGED, USE A POCKET CALCULATOR.");
407
		skip(1);
408
		return;
409
	}
410
	if (scan() != IHREAL) {
411
		prompt = TRUE;
412
		chew();
413
		proutn("Destination quadrant and/or sector? ");
414
		if (scan()!=IHREAL) {
415
			huh();
416
			return;
417
		}
418
	}
419
	iy1 = aaitem +0.5;
420
	if (scan() != IHREAL) {
421
		huh();
422
		return;
423
	}
424
	ix1 = aaitem + 0.5;
425
	if (scan() == IHREAL) {
426
		iy2 = aaitem + 0.5;
427
		if (scan() != IHREAL) {
428
			huh();
429
			return;
430
		}
431
		ix2 = aaitem + 0.5;
432
	}
433
	else {	// same quadrant
434
		ix2 = ix1;
435
		iy2 = iy1;
436
		ix1 = quady;	// ya got me why x and y are reversed!
437
		iy1 = quadx;
438
	}
439
 
440
	if (ix1 > 8 || ix1 < 1 || iy1 > 8 || iy1 < 1 ||
441
		ix2 > 10 || ix2 < 1 || iy2 > 10 || iy2 < 1) {
442
		huh();
443
		return;
444
	}
445
	dist = sqrt(square(iy1-quadx+0.1*(iy2-sectx))+
446
				square(ix1-quady+0.1*(ix2-secty)));
447
	wfl = FALSE;
448
 
449
	if (prompt) prout("Answer \"no\" if you don't know the value:");
450
	while (TRUE) {
451
		chew();
452
		proutn("Time or arrival date? ");
453
		if (scan()==IHREAL) {
454
			ttime = aaitem;
455
			if (ttime > d.date) ttime -= d.date; // Actually a star date
456
			if (ttime <= 1e-10 ||
457
				(twarp=(floor(sqrt((10.0*dist)/ttime)*10.0)+1.0)/10.0) > 10) {
458
				prout("We'll never make it, sir.");
459
				chew();
460
				return;
461
			}
462
			if (twarp < 1.0) twarp = 1.0;
463
			break;
464
		}
465
		chew();
466
		proutn("Warp factor? ");
467
		if (scan()== IHREAL) {
468
			wfl = TRUE;
469
			twarp = aaitem;
470
			if (twarp<1.0 || twarp > 10.0) {
471
				huh();
472
				return;
473
			}
474
			break;
475
		}
476
		prout("Captain, certainly you can give me one of these.");
477
	}
478
	while (TRUE) {
479
		chew();
480
		ttime = (10.0*dist)/square(twarp);
481
		tpower = dist*twarp*twarp*twarp*(shldup+1);
482
		if (tpower >= energy) { // Suggestion from Ethan Staffin -- give amount needed
483
			prout("Insufficient energy, sir: we would need ");
484
			cramf(tpower, 1, 1);
485
			proutn (" units.");
486
			if (shldup==0 || tpower > energy*2.0) {
487
				if (!wfl) return;
488
				proutn("New warp factor to try? ");
489
				if (scan() == IHREAL) {
490
					wfl = TRUE;
491
					twarp = aaitem;
492
					if (twarp<1.0 || twarp > 10.0) {
493
						huh();
494
						return;
495
					}
496
					continue;
497
				}
498
				else {
499
					chew();
500
					skip(1);
501
					return;
502
				}
503
			}
504
			prout("But if you lower your shields,");
505
			proutn("remaining");
506
			tpower /= 2;
507
		}
508
		else
509
			proutn("Remaining");
510
		proutn(" energy will be ");
511
		cramf(energy-tpower, 1, 1);
512
		prout(".");
513
		if (wfl) {
514
			proutn("And we will arrive at stardate ");
515
			cramf(d.date+ttime, 1, 1);
516
			prout(".");
517
		}
518
		else if (twarp==1.0)
519
			prout("Any warp speed is adequate.");
520
		else {
521
			proutn("Minimum warp needed is ");
522
			cramf(twarp, 1, 2);
523
			skip(1);
524
			proutn("and we will arrive at stardate ");
525
			cramf(d.date+ttime, 1, 2);
526
			prout(".");
527
		}
528
		if (d.remtime < ttime)
529
			prout("Unfortunately, the Federation will be destroyed by then.");
530
		if (twarp > 6.0)
531
			prout("You'll be taking risks at that speed, Captain");
532
		if ((isatb==1 && d.isy == ix1 && d.isx == iy1 &&
533
			 future[FSCDBAS]< ttime+d.date)||
534
			(future[FCDBAS]
535
			prout("The starbase there will be destroyed by then.");
536
		proutn("New warp factor to try? ");
537
		if (scan() == IHREAL) {
538
			wfl = TRUE;
539
			twarp = aaitem;
540
			if (twarp<1.0 || twarp > 10.0) {
541
				huh();
542
				return;
543
			}
544
		}
545
		else {
546
			chew();
547
			skip(1);
548
			return;
549
		}
550
	}
551
 
552
}