static char sccsid
[] = "@(#)computer.c 4.2 (Berkeley) %G%";
** A computer request is fetched from the captain. The requests
** chart -- print a star chart of the known galaxy. This includes
** every quadrant that has ever had a long range or
** a short range scan done of it, plus the location of
** all starbases. This is of course updated by any sub-
** space radio broadcasts (unless the radio is out).
** The format is the same as that of a long range scan
** except that ".1." indicates that a starbase exists
** but we know nothing else.
** trajectory -- gives the course and distance to every know
** Klingon in the quadrant. Obviously this fails if the
** short range scanners are out.
** course -- gives a course computation from whereever you are
** to any specified location. If the course begins
** with a slash, the current quadrant is taken.
** Otherwise the input is quadrant and sector coordi-
** nates of the target sector.
** move -- identical to course, except that the move is performed.
** score -- prints out the current score.
** pheff -- "PHaser EFFectiveness" at a given distance. Tells
** you how much stuff you need to make it work.
** warpcost -- Gives you the cost in time and units to move for
** a given distance under a given warp speed.
** impcost -- Same for the impulse engines.
** distresslist -- Gives a list of the currently known starsystems
** or starbases which are distressed, together with their
** If a command is terminated with a semicolon, you remain in
** the computer; otherwise, you escape immediately to the main
"ch", "art", (int (*)())1, 0,
"t", "rajectory", (int (*)())2, 0,
"c", "ourse", (int (*)())3, 0,
"m", "ove", (int (*)())3, 1,
"s", "core", (int (*)())4, 0,
"p", "heff", (int (*)())5, 0,
"w", "arpcost", (int (*)())6, 0,
"i", "mpcost", (int (*)())7, 0,
"d", "istresslist", (int (*)())8, 0,
register struct event
*e
;
r
= getcodpar("\nRequest", Cputab
);
printf("Computer record of galaxy for all long range sensor scans\n\n");
for (i
= 0; i
< NQUADS
; i
++)
for (i
= 0; i
< NQUADS
; i
++)
for (j
= 0; j
< NQUADS
; j
++)
if (i
== Ship
.quadx
&& j
== Ship
.quady
)
/* 1000 or 1001 is special case */
printf("%3d ", q
->scanned
);
/* print bottom footer */
for (i
= 0; i
< NQUADS
; i
++)
printf("No Klingons in this quadrant\n");
/* for each Klingon, give the course & distance */
for (i
= 0; i
< Etc
.nkling
; i
++)
printf("Klingon at %d,%d", Etc
.klingon
[i
].x
, Etc
.klingon
[i
].y
);
course
= kalc(Ship
.quadx
, Ship
.quady
, Etc
.klingon
[i
].x
, Etc
.klingon
[i
].y
, &dist
);
case 3: /* course calculation */
ix
= getintpar("Quadrant");
if (ix
< 0 || ix
>= NSECTS
)
if (iy
< 0 || iy
>= NSECTS
)
ix
= getintpar("Sector");
if (ix
< 0 || ix
>= NSECTS
)
if (iy
< 0 || iy
>= NSECTS
)
course
= kalc(tqx
, tqy
, ix
, iy
, &dist
);
printf("%d,%d/%d,%d to %d,%d/%d,%d",
Ship
.quadx
, Ship
.quady
, Ship
.sectx
, Ship
.secty
, tqx
, tqy
, ix
, iy
);
case 5: /* phaser effectiveness */
dist
= getfltpar("range");
cost
= pow(0.90, dist
) * 98.0 + 0.5;
printf("Phasers are %d%% effective at that range\n", cost
);
case 6: /* warp cost (time/energy) */
dist
= getfltpar("distance");
warpfact
= getfltpar("warp factor");
cost
= (dist
+ 0.05) * warpfact
* warpfact
* warpfact
;
time
= Param
.warptime
* dist
/ (warpfact
* warpfact
);
printf("Warp %.2f distance %.2f cost %.2f stardates %d (%d w/ shlds up) units\n",
warpfact
, dist
, time
, cost
, cost
+ cost
);
case 7: /* impulse cost */
dist
= getfltpar("distance");
printf("Distance %.2f cost %.2f stardates %d units\n",
case 8: /* distresslist */
/* scan the event list */
for (i
= 0; i
< MAXEVENTS
; i
++)
/* ignore hidden entries */
if (e
->evcode
& E_HIDDEN
)
switch (e
->evcode
& E_EVENT
)
printf("Klingon is attacking starbase in quadrant %d,%d\n",
printf("Starsystem %s in quadrant %d,%d is distressed\n",
systemname(e
), e
->x
, e
->y
);
printf("No known distress calls are active\n");
/* skip to next semicolon or newline. Semicolon
* means get new computer request; newline means
while ((i
= cgetc(0)) != ';')
** Computes and outputs the course and distance from position
** sqx,sqy/ssx,ssy to tqx,tqy/tsx,tsy.
kalc(tqx
, tqy
, tsx
, tsy
, dist
)
/* normalize to quadrant distances */
dx
= (Ship
.quadx
+ Ship
.sectx
/ quadsize
) - (tqx
+ tsx
/ quadsize
);
dy
= (tqy
+ tsy
/ quadsize
) - (Ship
.quady
+ Ship
.secty
/ quadsize
);
/* convert from radians to degrees */
course
= angle
* 57.29577951 + 0.5;
printf(": course %d dist %.3f\n", course
, dist
);