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 * @(#)torped.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/trek/torped.c,v 1.5 1999/11/30 03:49:55 billf Exp $
35 * $DragonFly: src/games/trek/torped.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
41 static int randcourse(int);
44 ** PHOTON TORPEDO CONTROL
46 ** Either one or three photon torpedoes are fired. If three
47 ** are fired, it is called a "burst" and you also specify
50 ** Torpedoes are never 100% accurate. There is always a random
51 ** cludge factor in their course which is increased if you have
52 ** your shields up. Hence, you will find that they are more
53 ** accurate at close range. However, they have the advantage that
54 ** at long range they don't lose any of their power as phasers
55 ** do, i.e., a hit is a hit is a hit, by any other name.
57 ** When the course spreads too much, you get a misfire, and the
58 ** course is randomized even more. You also have the chance that
59 ** the misfire damages your torpedo tubes.
63 torped(__unused int unused)
77 printf("Federation regulations do not permit attack while cloaked.\n");
80 if (check_out(TORPED))
84 printf("All photon torpedos expended\n");
89 course = getintpar("Torpedo course");
90 if (course < 0 || course > 360)
94 /* need at least three torpedoes for a burst */
97 printf("No-burst mode selected\n");
102 /* see if the user wants one */
105 k = ungetc(cgetc(0), stdin);
106 if (k >= '0' && k <= '9')
112 burst = getynpar("Do you want a burst");
116 burst = getintpar("burst angle");
120 printf("Maximum burst angle is 15 degrees\n");
131 for (; n && n <= 3; n++)
133 /* select a nice random course */
134 course2 = course + randcourse(n);
135 angle = course2 * 0.0174532925; /* convert to radians */
144 x = Ship.sectx + 0.5;
145 y = Ship.secty + 0.5;
146 if (Ship.cond != DOCKED)
148 printf("Torpedo track");
150 printf(", torpedo number %d", n);
151 printf(":\n%6.1f\t%4.1f\n", x, y);
156 if (x < 0.0 || x >= sectsize || y < 0.0 || y >= sectsize)
158 printf("Torpedo missed\n");
161 printf("%6.1f\t%4.1f\n", x, y);
162 switch (Sect[ix][iy])
168 printf("Torpedo disappears into a black hole\n");
172 for (k = 0; k < Etc.nkling; k++)
174 if (Etc.klingon[k].x != ix || Etc.klingon[k].y != iy)
176 Etc.klingon[k].power -= 500 + ranf(501);
177 if (Etc.klingon[k].power > 0)
179 printf("*** Hit on Klingon at %d,%d: extensive damages\n",
197 killb(Ship.quadx, Ship.quady);
201 printf("Unknown object %c at %d,%d destroyed\n",
202 Sect[ix][iy], ix, iy);
203 Sect[ix][iy] = EMPTY;
208 if (damaged(TORPED) || Quad[Ship.quadx][Ship.quady].stars < 0)
219 ** This routine randomizes the course for torpedo number 'n'.
220 ** Other things handled by this routine are misfires, damages
221 ** to the tubes, etc.
230 d = ((franf() + franf()) - 1.0) * 20;
233 printf("Photon tubes misfire");
237 printf(" on torpedo %d\n", n);
240 damage(TORPED, 0.2 * abs(d) * (franf() + 1.0));
242 d *= 1.0 + 2.0 * franf();
244 if (Ship.shldup || Ship.cond == DOCKED)
247 r = 1.0 + r / Param.shield;
248 if (Ship.cond == DOCKED)