]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - trek/computer.c
2 * Copyright (c) 1980 Regents of the University of California.
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
35 /*static char sccsid[] = "from: @(#)computer.c 4.8 (Berkeley) 6/1/90";*/
36 static char rcsid
[] = "$Id: computer.c,v 1.2 1993/08/01 18:50:46 mycroft Exp $";
45 ** A computer request is fetched from the captain. The requests
48 ** chart -- print a star chart of the known galaxy. This includes
49 ** every quadrant that has ever had a long range or
50 ** a short range scan done of it, plus the location of
51 ** all starbases. This is of course updated by any sub-
52 ** space radio broadcasts (unless the radio is out).
53 ** The format is the same as that of a long range scan
54 ** except that ".1." indicates that a starbase exists
55 ** but we know nothing else.
57 ** trajectory -- gives the course and distance to every know
58 ** Klingon in the quadrant. Obviously this fails if the
59 ** short range scanners are out.
61 ** course -- gives a course computation from whereever you are
62 ** to any specified location. If the course begins
63 ** with a slash, the current quadrant is taken.
64 ** Otherwise the input is quadrant and sector coordi-
65 ** nates of the target sector.
67 ** move -- identical to course, except that the move is performed.
69 ** score -- prints out the current score.
71 ** pheff -- "PHaser EFFectiveness" at a given distance. Tells
72 ** you how much stuff you need to make it work.
74 ** warpcost -- Gives you the cost in time and units to move for
75 ** a given distance under a given warp speed.
77 ** impcost -- Same for the impulse engines.
79 ** distresslist -- Gives a list of the currently known starsystems
80 ** or starbases which are distressed, together with their
81 ** quadrant coordinates.
83 ** If a command is terminated with a semicolon, you remain in
84 ** the computer; otherwise, you escape immediately to the main
88 struct cvntab Cputab
[] =
90 "ch", "art", (int (*)())1, 0,
91 "t", "rajectory", (int (*)())2, 0,
92 "c", "ourse", (int (*)())3, 0,
93 "m", "ove", (int (*)())3, 1,
94 "s", "core", (int (*)())4, 0,
95 "p", "heff", (int (*)())5, 0,
96 "w", "arpcost", (int (*)())6, 0,
97 "i", "mpcost", (int (*)())7, 0,
98 "d", "istresslist", (int (*)())8, 0,
114 register struct event
*e
;
116 if (check_out(COMPUTER
))
120 r
= getcodpar("\nRequest", Cputab
);
121 switch ((int)r
->value
)
124 case 1: /* star chart */
125 printf("Computer record of galaxy for all long range sensor scans\n\n");
127 /* print top header */
128 for (i
= 0; i
< NQUADS
; i
++)
131 for (i
= 0; i
< NQUADS
; i
++)
134 for (j
= 0; j
< NQUADS
; j
++)
136 if (i
== Ship
.quadx
&& j
== Ship
.quady
)
142 /* 1000 or 1001 is special case */
143 if (q
->scanned
>= 1000)
144 if (q
->scanned
> 1000)
152 printf("%3d ", q
->scanned
);
157 /* print bottom footer */
158 for (i
= 0; i
< NQUADS
; i
++)
163 case 2: /* trajectory */
164 if (check_out(SRSCAN
))
170 printf("No Klingons in this quadrant\n");
173 /* for each Klingon, give the course & distance */
174 for (i
= 0; i
< Etc
.nkling
; i
++)
176 printf("Klingon at %d,%d", Etc
.klingon
[i
].x
, Etc
.klingon
[i
].y
);
177 course
= kalc(Ship
.quadx
, Ship
.quady
, Etc
.klingon
[i
].x
, Etc
.klingon
[i
].y
, &dist
);
178 prkalc(course
, dist
);
182 case 3: /* course calculation */
190 ix
= getintpar("Quadrant");
191 if (ix
< 0 || ix
>= NSECTS
)
193 iy
= getintpar("q-y");
194 if (iy
< 0 || iy
>= NSECTS
)
199 ix
= getintpar("Sector");
200 if (ix
< 0 || ix
>= NSECTS
)
202 iy
= getintpar("s-y");
203 if (iy
< 0 || iy
>= NSECTS
)
205 course
= kalc(tqx
, tqy
, ix
, iy
, &dist
);
208 warp(-1, course
, dist
);
211 printf("%d,%d/%d,%d to %d,%d/%d,%d",
212 Ship
.quadx
, Ship
.quady
, Ship
.sectx
, Ship
.secty
, tqx
, tqy
, ix
, iy
);
213 prkalc(course
, dist
);
220 case 5: /* phaser effectiveness */
221 dist
= getfltpar("range");
225 cost
= pow(0.90, dist
) * 98.0 + 0.5;
226 printf("Phasers are %d%% effective at that range\n", cost
);
229 case 6: /* warp cost (time/energy) */
230 dist
= getfltpar("distance");
233 warpfact
= getfltpar("warp factor");
235 warpfact
= Ship
.warp
;
236 cost
= (dist
+ 0.05) * warpfact
* warpfact
* warpfact
;
237 time
= Param
.warptime
* dist
/ (warpfact
* warpfact
);
238 printf("Warp %.2f distance %.2f cost %.2f stardates %d (%d w/ shlds up) units\n",
239 warpfact
, dist
, time
, cost
, cost
+ cost
);
242 case 7: /* impulse cost */
243 dist
= getfltpar("distance");
246 cost
= 20 + 100 * dist
;
248 printf("Distance %.2f cost %.2f stardates %d units\n",
252 case 8: /* distresslist */
255 /* scan the event list */
256 for (i
= 0; i
< MAXEVENTS
; i
++)
259 /* ignore hidden entries */
260 if (e
->evcode
& E_HIDDEN
)
262 switch (e
->evcode
& E_EVENT
)
266 printf("Klingon is attacking starbase in quadrant %d,%d\n",
273 printf("Starsystem %s in quadrant %d,%d is distressed\n",
274 Systemname
[e
->systemname
], e
->x
, e
->y
);
280 printf("No known distress calls are active\n");
285 /* skip to next semicolon or newline. Semicolon
286 * means get new computer request; newline means
287 * exit computer mode. */
288 while ((i
= cgetc(0)) != ';')
303 ** Course Calculation
305 ** Computes and outputs the course and distance from position
306 ** sqx,sqy/ssx,ssy to tqx,tqy/tsx,tsy.
309 kalc(tqx
, tqy
, tsx
, tsy
, dist
)
321 /* normalize to quadrant distances */
323 dx
= (Ship
.quadx
+ Ship
.sectx
/ quadsize
) - (tqx
+ tsx
/ quadsize
);
324 dy
= (tqy
+ tsy
/ quadsize
) - (Ship
.quady
+ Ship
.secty
/ quadsize
);
327 angle
= atan2(dy
, dx
);
328 /* make it 0 -> 2 pi */
330 angle
+= 6.283185307;
331 /* convert from radians to degrees */
332 course
= angle
* 57.29577951 + 0.5;
333 dx
= dx
* dx
+ dy
* dy
;
343 printf(": course %d dist %.3f\n", course
, dist
);