]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - trek/computer.c
1 /* $NetBSD: computer.c,v 1.4 1995/04/24 12:25:51 cgd Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char sccsid
[] = "@(#)computer.c 8.1 (Berkeley) 5/31/93";
40 static char rcsid
[] = "$NetBSD: computer.c,v 1.4 1995/04/24 12:25:51 cgd Exp $";
50 ** A computer request is fetched from the captain. The requests
53 ** chart -- print a star chart of the known galaxy. This includes
54 ** every quadrant that has ever had a long range or
55 ** a short range scan done of it, plus the location of
56 ** all starbases. This is of course updated by any sub-
57 ** space radio broadcasts (unless the radio is out).
58 ** The format is the same as that of a long range scan
59 ** except that ".1." indicates that a starbase exists
60 ** but we know nothing else.
62 ** trajectory -- gives the course and distance to every know
63 ** Klingon in the quadrant. Obviously this fails if the
64 ** short range scanners are out.
66 ** course -- gives a course computation from whereever you are
67 ** to any specified location. If the course begins
68 ** with a slash, the current quadrant is taken.
69 ** Otherwise the input is quadrant and sector coordi-
70 ** nates of the target sector.
72 ** move -- identical to course, except that the move is performed.
74 ** score -- prints out the current score.
76 ** pheff -- "PHaser EFFectiveness" at a given distance. Tells
77 ** you how much stuff you need to make it work.
79 ** warpcost -- Gives you the cost in time and units to move for
80 ** a given distance under a given warp speed.
82 ** impcost -- Same for the impulse engines.
84 ** distresslist -- Gives a list of the currently known starsystems
85 ** or starbases which are distressed, together with their
86 ** quadrant coordinates.
88 ** If a command is terminated with a semicolon, you remain in
89 ** the computer; otherwise, you escape immediately to the main
93 struct cvntab Cputab
[] =
95 "ch", "art", (int (*)())1, 0,
96 "t", "rajectory", (int (*)())2, 0,
97 "c", "ourse", (int (*)())3, 0,
98 "m", "ove", (int (*)())3, 1,
99 "s", "core", (int (*)())4, 0,
100 "p", "heff", (int (*)())5, 0,
101 "w", "arpcost", (int (*)())6, 0,
102 "i", "mpcost", (int (*)())7, 0,
103 "d", "istresslist", (int (*)())8, 0,
119 register struct event
*e
;
121 if (check_out(COMPUTER
))
125 r
= getcodpar("\nRequest", Cputab
);
126 switch ((long)r
->value
)
129 case 1: /* star chart */
130 printf("Computer record of galaxy for all long range sensor scans\n\n");
132 /* print top header */
133 for (i
= 0; i
< NQUADS
; i
++)
136 for (i
= 0; i
< NQUADS
; i
++)
139 for (j
= 0; j
< NQUADS
; j
++)
141 if (i
== Ship
.quadx
&& j
== Ship
.quady
)
147 /* 1000 or 1001 is special case */
148 if (q
->scanned
>= 1000)
149 if (q
->scanned
> 1000)
157 printf("%3d ", q
->scanned
);
162 /* print bottom footer */
163 for (i
= 0; i
< NQUADS
; i
++)
168 case 2: /* trajectory */
169 if (check_out(SRSCAN
))
175 printf("No Klingons in this quadrant\n");
178 /* for each Klingon, give the course & distance */
179 for (i
= 0; i
< Etc
.nkling
; i
++)
181 printf("Klingon at %d,%d", Etc
.klingon
[i
].x
, Etc
.klingon
[i
].y
);
182 course
= kalc(Ship
.quadx
, Ship
.quady
, Etc
.klingon
[i
].x
, Etc
.klingon
[i
].y
, &dist
);
183 prkalc(course
, dist
);
187 case 3: /* course calculation */
195 ix
= getintpar("Quadrant");
196 if (ix
< 0 || ix
>= NSECTS
)
198 iy
= getintpar("q-y");
199 if (iy
< 0 || iy
>= NSECTS
)
204 ix
= getintpar("Sector");
205 if (ix
< 0 || ix
>= NSECTS
)
207 iy
= getintpar("s-y");
208 if (iy
< 0 || iy
>= NSECTS
)
210 course
= kalc(tqx
, tqy
, ix
, iy
, &dist
);
213 warp(-1, course
, dist
);
216 printf("%d,%d/%d,%d to %d,%d/%d,%d",
217 Ship
.quadx
, Ship
.quady
, Ship
.sectx
, Ship
.secty
, tqx
, tqy
, ix
, iy
);
218 prkalc(course
, dist
);
225 case 5: /* phaser effectiveness */
226 dist
= getfltpar("range");
230 cost
= pow(0.90, dist
) * 98.0 + 0.5;
231 printf("Phasers are %d%% effective at that range\n", cost
);
234 case 6: /* warp cost (time/energy) */
235 dist
= getfltpar("distance");
238 warpfact
= getfltpar("warp factor");
240 warpfact
= Ship
.warp
;
241 cost
= (dist
+ 0.05) * warpfact
* warpfact
* warpfact
;
242 time
= Param
.warptime
* dist
/ (warpfact
* warpfact
);
243 printf("Warp %.2f distance %.2f cost %.2f stardates %d (%d w/ shlds up) units\n",
244 warpfact
, dist
, time
, cost
, cost
+ cost
);
247 case 7: /* impulse cost */
248 dist
= getfltpar("distance");
251 cost
= 20 + 100 * dist
;
253 printf("Distance %.2f cost %.2f stardates %d units\n",
257 case 8: /* distresslist */
260 /* scan the event list */
261 for (i
= 0; i
< MAXEVENTS
; i
++)
264 /* ignore hidden entries */
265 if (e
->evcode
& E_HIDDEN
)
267 switch (e
->evcode
& E_EVENT
)
271 printf("Klingon is attacking starbase in quadrant %d,%d\n",
278 printf("Starsystem %s in quadrant %d,%d is distressed\n",
279 Systemname
[e
->systemname
], e
->x
, e
->y
);
285 printf("No known distress calls are active\n");
290 /* skip to next semicolon or newline. Semicolon
291 * means get new computer request; newline means
292 * exit computer mode. */
293 while ((i
= cgetc(0)) != ';')
308 ** Course Calculation
310 ** Computes and outputs the course and distance from position
311 ** sqx,sqy/ssx,ssy to tqx,tqy/tsx,tsy.
314 kalc(tqx
, tqy
, tsx
, tsy
, dist
)
326 /* normalize to quadrant distances */
328 dx
= (Ship
.quadx
+ Ship
.sectx
/ quadsize
) - (tqx
+ tsx
/ quadsize
);
329 dy
= (tqy
+ tsy
/ quadsize
) - (Ship
.quady
+ Ship
.secty
/ quadsize
);
332 angle
= atan2(dy
, dx
);
333 /* make it 0 -> 2 pi */
335 angle
+= 6.283185307;
336 /* convert from radians to degrees */
337 course
= angle
* 57.29577951 + 0.5;
338 dx
= dx
* dx
+ dy
* dy
;
348 printf(": course %d dist %.3f\n", course
, dist
);