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
33 * @(#)computer.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/trek/computer.c,v 1.5 1999/11/30 03:49:45 billf Exp $
35 * $DragonFly: src/games/trek/computer.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
44 ** A computer request is fetched from the captain. The requests
47 ** chart -- print a star chart of the known galaxy. This includes
48 ** every quadrant that has ever had a long range or
49 ** a short range scan done of it, plus the location of
50 ** all starbases. This is of course updated by any sub-
51 ** space radio broadcasts (unless the radio is out).
52 ** The format is the same as that of a long range scan
53 ** except that ".1." indicates that a starbase exists
54 ** but we know nothing else.
56 ** trajectory -- gives the course and distance to every know
57 ** Klingon in the quadrant. Obviously this fails if the
58 ** short range scanners are out.
60 ** course -- gives a course computation from whereever you are
61 ** to any specified location. If the course begins
62 ** with a slash, the current quadrant is taken.
63 ** Otherwise the input is quadrant and sector coordi-
64 ** nates of the target sector.
66 ** move -- identical to course, except that the move is performed.
68 ** score -- prints out the current score.
70 ** pheff -- "PHaser EFFectiveness" at a given distance. Tells
71 ** you how much stuff you need to make it work.
73 ** warpcost -- Gives you the cost in time and units to move for
74 ** a given distance under a given warp speed.
76 ** impcost -- Same for the impulse engines.
78 ** distresslist -- Gives a list of the currently known starsystems
79 ** or starbases which are distressed, together with their
80 ** quadrant coordinates.
82 ** If a command is terminated with a semicolon, you remain in
83 ** the computer; otherwise, you escape immediately to the main
87 struct cvntab Cputab
[] =
89 "ch", "art", (int (*)())1, 0,
90 "t", "rajectory", (int (*)())2, 0,
91 "c", "ourse", (int (*)())3, 0,
92 "m", "ove", (int (*)())3, 1,
93 "s", "core", (int (*)())4, 0,
94 "p", "heff", (int (*)())5, 0,
95 "w", "arpcost", (int (*)())6, 0,
96 "i", "mpcost", (int (*)())7, 0,
97 "d", "istresslist", (int (*)())8, 0,
115 if (check_out(COMPUTER
))
119 r
= getcodpar("\nRequest", Cputab
);
120 switch ((long)r
->value
)
123 case 1: /* star chart */
124 printf("Computer record of galaxy for all long range sensor scans\n\n");
126 /* print top header */
127 for (i
= 0; i
< NQUADS
; i
++)
130 for (i
= 0; i
< NQUADS
; i
++)
133 for (j
= 0; j
< NQUADS
; j
++)
135 if (i
== Ship
.quadx
&& j
== Ship
.quady
)
141 /* 1000 or 1001 is special case */
142 if (q
->scanned
>= 1000)
143 if (q
->scanned
> 1000)
151 printf("%3d ", q
->scanned
);
156 /* print bottom footer */
157 for (i
= 0; i
< NQUADS
; i
++)
162 case 2: /* trajectory */
163 if (check_out(SRSCAN
))
169 printf("No Klingons in this quadrant\n");
172 /* for each Klingon, give the course & distance */
173 for (i
= 0; i
< Etc
.nkling
; i
++)
175 printf("Klingon at %d,%d", Etc
.klingon
[i
].x
, Etc
.klingon
[i
].y
);
176 course
= kalc(Ship
.quadx
, Ship
.quady
, Etc
.klingon
[i
].x
, Etc
.klingon
[i
].y
, &dist
);
177 prkalc(course
, dist
);
181 case 3: /* course calculation */
189 ix
= getintpar("Quadrant");
190 if (ix
< 0 || ix
>= NSECTS
)
192 iy
= getintpar("q-y");
193 if (iy
< 0 || iy
>= NSECTS
)
198 ix
= getintpar("Sector");
199 if (ix
< 0 || ix
>= NSECTS
)
201 iy
= getintpar("s-y");
202 if (iy
< 0 || iy
>= NSECTS
)
204 course
= kalc(tqx
, tqy
, ix
, iy
, &dist
);
207 warp(-1, course
, dist
);
210 printf("%d,%d/%d,%d to %d,%d/%d,%d",
211 Ship
.quadx
, Ship
.quady
, Ship
.sectx
, Ship
.secty
, tqx
, tqy
, ix
, iy
);
212 prkalc(course
, dist
);
219 case 5: /* phaser effectiveness */
220 dist
= getfltpar("range");
224 cost
= pow(0.90, dist
) * 98.0 + 0.5;
225 printf("Phasers are %d%% effective at that range\n", cost
);
228 case 6: /* warp cost (time/energy) */
229 dist
= getfltpar("distance");
232 warpfact
= getfltpar("warp factor");
234 warpfact
= Ship
.warp
;
235 cost
= (dist
+ 0.05) * warpfact
* warpfact
* warpfact
;
236 time
= Param
.warptime
* dist
/ (warpfact
* warpfact
);
237 printf("Warp %.2f distance %.2f cost %.2f stardates %d (%d w/ shlds up) units\n",
238 warpfact
, dist
, time
, cost
, cost
+ cost
);
241 case 7: /* impulse cost */
242 dist
= getfltpar("distance");
245 cost
= 20 + 100 * dist
;
247 printf("Distance %.2f cost %.2f stardates %d units\n",
251 case 8: /* distresslist */
254 /* scan the event list */
255 for (i
= 0; i
< MAXEVENTS
; i
++)
258 /* ignore hidden entries */
259 if (e
->evcode
& E_HIDDEN
)
261 switch (e
->evcode
& E_EVENT
)
265 printf("Klingon is attacking starbase in quadrant %d,%d\n",
272 printf("Starsystem %s in quadrant %d,%d is distressed\n",
273 Systemname
[e
->systemname
], e
->x
, e
->y
);
279 printf("No known distress calls are active\n");
284 /* skip to next semicolon or newline. Semicolon
285 * means get new computer request; newline means
286 * exit computer mode. */
287 while ((i
= cgetc(0)) != ';')
302 ** Course Calculation
304 ** Computes and outputs the course and distance from position
305 ** sqx,sqy/ssx,ssy to tqx,tqy/tsx,tsy.
308 kalc(tqx
, tqy
, tsx
, tsy
, dist
)
320 /* normalize to quadrant distances */
322 dx
= (Ship
.quadx
+ Ship
.sectx
/ quadsize
) - (tqx
+ tsx
/ quadsize
);
323 dy
= (tqy
+ tsy
/ quadsize
) - (Ship
.quady
+ Ship
.secty
/ quadsize
);
326 angle
= atan2(dy
, dx
);
327 /* make it 0 -> 2 pi */
329 angle
+= 6.283185307;
330 /* convert from radians to degrees */
331 course
= angle
* 57.29577951 + 0.5;
332 dx
= dx
* dx
+ dy
* dy
;
342 printf(": course %d dist %.3f\n", course
, dist
);