2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 static char sccsid[] = "@(#)computer.c 8.1 (Berkeley) 5/31/93";
38 static const char rcsid[] =
39 "$FreeBSD: src/games/trek/computer.c,v 1.5 1999/11/30 03:49:45 billf Exp $";
48 ** A computer request is fetched from the captain. The requests
51 ** chart -- print a star chart of the known galaxy. This includes
52 ** every quadrant that has ever had a long range or
53 ** a short range scan done of it, plus the location of
54 ** all starbases. This is of course updated by any sub-
55 ** space radio broadcasts (unless the radio is out).
56 ** The format is the same as that of a long range scan
57 ** except that ".1." indicates that a starbase exists
58 ** but we know nothing else.
60 ** trajectory -- gives the course and distance to every know
61 ** Klingon in the quadrant. Obviously this fails if the
62 ** short range scanners are out.
64 ** course -- gives a course computation from whereever you are
65 ** to any specified location. If the course begins
66 ** with a slash, the current quadrant is taken.
67 ** Otherwise the input is quadrant and sector coordi-
68 ** nates of the target sector.
70 ** move -- identical to course, except that the move is performed.
72 ** score -- prints out the current score.
74 ** pheff -- "PHaser EFFectiveness" at a given distance. Tells
75 ** you how much stuff you need to make it work.
77 ** warpcost -- Gives you the cost in time and units to move for
78 ** a given distance under a given warp speed.
80 ** impcost -- Same for the impulse engines.
82 ** distresslist -- Gives a list of the currently known starsystems
83 ** or starbases which are distressed, together with their
84 ** quadrant coordinates.
86 ** If a command is terminated with a semicolon, you remain in
87 ** the computer; otherwise, you escape immediately to the main
91 struct cvntab Cputab[] =
93 "ch", "art", (int (*)())1, 0,
94 "t", "rajectory", (int (*)())2, 0,
95 "c", "ourse", (int (*)())3, 0,
96 "m", "ove", (int (*)())3, 1,
97 "s", "core", (int (*)())4, 0,
98 "p", "heff", (int (*)())5, 0,
99 "w", "arpcost", (int (*)())6, 0,
100 "i", "mpcost", (int (*)())7, 0,
101 "d", "istresslist", (int (*)())8, 0,
119 if (check_out(COMPUTER))
123 r = getcodpar("\nRequest", Cputab);
124 switch ((long)r->value)
127 case 1: /* star chart */
128 printf("Computer record of galaxy for all long range sensor scans\n\n");
130 /* print top header */
131 for (i = 0; i < NQUADS; i++)
134 for (i = 0; i < NQUADS; i++)
137 for (j = 0; j < NQUADS; j++)
139 if (i == Ship.quadx && j == Ship.quady)
145 /* 1000 or 1001 is special case */
146 if (q->scanned >= 1000)
147 if (q->scanned > 1000)
155 printf("%3d ", q->scanned);
160 /* print bottom footer */
161 for (i = 0; i < NQUADS; i++)
166 case 2: /* trajectory */
167 if (check_out(SRSCAN))
173 printf("No Klingons in this quadrant\n");
176 /* for each Klingon, give the course & distance */
177 for (i = 0; i < Etc.nkling; i++)
179 printf("Klingon at %d,%d", Etc.klingon[i].x, Etc.klingon[i].y);
180 course = kalc(Ship.quadx, Ship.quady, Etc.klingon[i].x, Etc.klingon[i].y, &dist);
181 prkalc(course, dist);
185 case 3: /* course calculation */
193 ix = getintpar("Quadrant");
194 if (ix < 0 || ix >= NSECTS)
196 iy = getintpar("q-y");
197 if (iy < 0 || iy >= NSECTS)
202 ix = getintpar("Sector");
203 if (ix < 0 || ix >= NSECTS)
205 iy = getintpar("s-y");
206 if (iy < 0 || iy >= NSECTS)
208 course = kalc(tqx, tqy, ix, iy, &dist);
211 warp(-1, course, dist);
214 printf("%d,%d/%d,%d to %d,%d/%d,%d",
215 Ship.quadx, Ship.quady, Ship.sectx, Ship.secty, tqx, tqy, ix, iy);
216 prkalc(course, dist);
223 case 5: /* phaser effectiveness */
224 dist = getfltpar("range");
228 cost = pow(0.90, dist) * 98.0 + 0.5;
229 printf("Phasers are %d%% effective at that range\n", cost);
232 case 6: /* warp cost (time/energy) */
233 dist = getfltpar("distance");
236 warpfact = getfltpar("warp factor");
238 warpfact = Ship.warp;
239 cost = (dist + 0.05) * warpfact * warpfact * warpfact;
240 time = Param.warptime * dist / (warpfact * warpfact);
241 printf("Warp %.2f distance %.2f cost %.2f stardates %d (%d w/ shlds up) units\n",
242 warpfact, dist, time, cost, cost + cost);
245 case 7: /* impulse cost */
246 dist = getfltpar("distance");
249 cost = 20 + 100 * dist;
251 printf("Distance %.2f cost %.2f stardates %d units\n",
255 case 8: /* distresslist */
258 /* scan the event list */
259 for (i = 0; i < MAXEVENTS; i++)
262 /* ignore hidden entries */
263 if (e->evcode & E_HIDDEN)
265 switch (e->evcode & E_EVENT)
269 printf("Klingon is attacking starbase in quadrant %d,%d\n",
276 printf("Starsystem %s in quadrant %d,%d is distressed\n",
277 Systemname[e->systemname], e->x, e->y);
283 printf("No known distress calls are active\n");
288 /* skip to next semicolon or newline. Semicolon
289 * means get new computer request; newline means
290 * exit computer mode. */
291 while ((i = cgetc(0)) != ';')
306 ** Course Calculation
308 ** Computes and outputs the course and distance from position
309 ** sqx,sqy/ssx,ssy to tqx,tqy/tsx,tsy.
312 kalc(tqx, tqy, tsx, tsy, dist)
324 /* normalize to quadrant distances */
326 dx = (Ship.quadx + Ship.sectx / quadsize) - (tqx + tsx / quadsize);
327 dy = (tqy + tsy / quadsize) - (Ship.quady + Ship.secty / quadsize);
330 angle = atan2(dy, dx);
331 /* make it 0 -> 2 pi */
333 angle += 6.283185307;
334 /* convert from radians to degrees */
335 course = angle * 57.29577951 + 0.5;
336 dx = dx * dx + dy * dy;
346 printf(": course %d dist %.3f\n", course, dist);