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: #include <sys/cdefs.h>
33: #ifndef lint
34: #if 0
35: static char sccsid[] = "@(#)computer.c 8.1 (Berkeley) 5/31/93";
36: #else
37: __RCSID("$NetBSD: computer.c,v 1.10 2004/01/27 20:30:30 jsm Exp $");
38: #endif
39: #endif
40:
41: #include <stdio.h>
42: #include <stdlib.h>
43: #include <math.h>
44: #include "trek.h"
45: #include "getpar.h"
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: struct cvntab Cputab[] =
94: {
95: { "ch", "art", (cmdfun)1, 0 },
96: { "t", "rajectory", (cmdfun)2, 0 },
97: { "c", "ourse", (cmdfun)3, 0 },
98: { "m", "ove", (cmdfun)3, 1 },
99: { "s", "core", (cmdfun)4, 0 },
100: { "p", "heff", (cmdfun)5, 0 },
101: { "w", "arpcost", (cmdfun)6, 0 },
102: { "i", "mpcost", (cmdfun)7, 0 },
103: { "d", "istresslist", (cmdfun)8, 0 },
104: { NULL, NULL, NULL, 0 }
105: };
106:
107: static int kalc(int, int, int, int, double *);
108: static void prkalc(int, double);
109:
110:
111: void
112: computer(v)
113: int v __attribute__((__unused__));
114: {
115: int ix, iy;
116: int i, j;
117: int tqx, tqy;
118: const struct cvntab *r;
119: int cost;
120: int course;
121: double dist, time;
122: double warpfact;
123: struct quad *q;
124: struct event *e;
125:
126: if (check_out(COMPUTER))
127: return;
128: while (1)
129: {
130: r = getcodpar("\nRequest", Cputab);
131: switch ((long)r->value)
132: {
133:
134: case 1:
135: printf("Computer record of galaxy for all long range sensor scans\n\n");
136: printf(" ");
137:
138: for (i = 0; i < NQUADS; i++)
139: printf("-%d- ", i);
140: printf("\n");
141: for (i = 0; i < NQUADS; i++)
142: {
143: printf("%d ", i);
144: for (j = 0; j < NQUADS; j++)
145: {
146: if (i == Ship.quadx && j == Ship.quady)
147: {
148: printf("$$$ ");
149: continue;
150: }
151: q = &Quad[i][j];
152:
153: if (q->scanned >= 1000)
154: if (q->scanned > 1000)
155: printf(".1. ");
156: else
157: printf("/// ");
158: else
159: if (q->scanned < 0)
160: printf("... ");
161: else
162: printf("%3d ", q->scanned);
163: }
164: printf("%d\n", i);
165: }
166: printf(" ");
167:
168: for (i = 0; i < NQUADS; i++)
169: printf("-%d- ", i);
170: printf("\n");
171: break;
172:
173: case 2:
174: if (check_out(SRSCAN))
175: {
176: break;
177: }
178: if (Etc.nkling <= 0)
179: {
180: printf("No Klingons in this quadrant\n");
181: break;
182: }
183:
184: for (i = 0; i < Etc.nkling; i++)
185: {
186: printf("Klingon at %d,%d", Etc.klingon[i].x, Etc.klingon[i].y);
187: course = kalc(Ship.quadx, Ship.quady, Etc.klingon[i].x, Etc.klingon[i].y, &dist);
188: prkalc(course, dist);
189: }
190: break;
191:
192: case 3:
193: if (readdelim('/'))
194: {
195: tqx = Ship.quadx;
196: tqy = Ship.quady;
197: }
198: else
199: {
200: ix = getintpar("Quadrant");
201: if (ix < 0 || ix >= NSECTS)
202: break;
203: iy = getintpar("q-y");
204: if (iy < 0 || iy >= NSECTS)
205: break;
206: tqx = ix;
207: tqy = iy;
208: }
209: ix = getintpar("Sector");
210: if (ix < 0 || ix >= NSECTS)
211: break;
212: iy = getintpar("s-y");
213: if (iy < 0 || iy >= NSECTS)
214: break;
215: course = kalc(tqx, tqy, ix, iy, &dist);
216: if (r->value2)
217: {
218: warp(-1, course, dist);
219: break;
220: }
221: printf("%d,%d/%d,%d to %d,%d/%d,%d",
222: Ship.quadx, Ship.quady, Ship.sectx, Ship.secty, tqx, tqy, ix, iy);
223: prkalc(course, dist);
224: break;
225:
226: case 4:
227: score();
228: break;
229:
230: case 5:
231: dist = getfltpar("range");
232: if (dist < 0.0)
233: break;
234: dist *= 10.0;
235: cost = pow(0.90, dist) * 98.0 + 0.5;
236: printf("Phasers are %d%% effective at that range\n", cost);
237: break;
238:
239: case 6:
240: dist = getfltpar("distance");
241: if (dist < 0.0)
242: break;
243: warpfact = getfltpar("warp factor");
244: if (warpfact <= 0.0)
245: warpfact = Ship.warp;
246: cost = (dist + 0.05) * warpfact * warpfact * warpfact;
247: time = Param.warptime * dist / (warpfact * warpfact);
248: printf("Warp %.2f distance %.2f cost %.2f stardates %d (%d w/ shlds up) units\n",
249: warpfact, dist, time, cost, cost + cost);
250: break;
251:
252: case 7:
253: dist = getfltpar("distance");
254: if (dist < 0.0)
255: break;
256: cost = 20 + 100 * dist;
257: time = dist / 0.095;
258: printf("Distance %.2f cost %.2f stardates %d units\n",
259: dist, time, cost);
260: break;
261:
262: case 8:
263: j = 1;
264: printf("\n");
265:
266: for (i = 0; i < MAXEVENTS; i++)
267: {
268: e = &Event[i];
269:
270: if (e->evcode & E_HIDDEN)
271: continue;
272: switch (e->evcode & E_EVENT)
273: {
274:
275: case E_KDESB:
276: printf("Klingon is attacking starbase in quadrant %d,%d\n",
277: e->x, e->y);
278: j = 0;
279: break;
280:
281: case E_ENSLV:
282: case E_REPRO:
283: printf("Starsystem %s in quadrant %d,%d is distressed\n",
284: Systemname[e->systemname], e->x, e->y);
285: j = 0;
286: break;
287: }
288: }
289: if (j)
290: printf("No known distress calls are active\n");
291: break;
292:
293: }
294:
295:
296:
297:
298: while ((i = cgetc(0)) != ';')
299: {
300: if (i == '\0')
301: exit(1);
302: if (i == '\n')
303: {
304: ungetc(i, stdin);
305: return;
306: }
307: }
308: }
309: }
310:
311:
312:
313:
314:
315:
316:
317:
318:
319: static int
320: kalc(tqx, tqy, tsx, tsy, dist)
321: int tqx;
322: int tqy;
323: int tsx;
324: int tsy;
325: double *dist;
326: {
327: double dx, dy;
328: double quadsize;
329: double angle;
330: int course;
331:
332:
333: quadsize = NSECTS;
334: dx = (Ship.quadx + Ship.sectx / quadsize) - (tqx + tsx / quadsize);
335: dy = (tqy + tsy / quadsize) - (Ship.quady + Ship.secty / quadsize);
336:
337:
338: angle = atan2(dy, dx);
339:
340: if (angle < 0.0)
341: angle += 6.283185307;
342:
343: course = angle * 57.29577951 + 0.5;
344: dx = dx * dx + dy * dy;
345: *dist = sqrt(dx);
346: return (course);
347: }
348:
349: static void
350: prkalc(course, dist)
351: int course;
352: double dist;
353: {
354: printf(": course %d dist %.3f\n", course, dist);
355: }