]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - trek/torped.c
1 /* $NetBSD: torped.c,v 1.7 2003/08/07 09:37:54 agc 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)torped.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: torped.c,v 1.7 2003/08/07 09:37:54 agc Exp $");
48 ** PHOTON TORPEDO CONTROL
50 ** Either one or three photon torpedoes are fired. If three
51 ** are fired, it is called a "burst" and you also specify
54 ** Torpedoes are never 100% accurate. There is always a random
55 ** cludge factor in their course which is increased if you have
56 ** your shields up. Hence, you will find that they are more
57 ** accurate at close range. However, they have the advantage that
58 ** at long range they don't lose any of their power as phasers
59 ** do, i.e., a hit is a hit is a hit, by any other name.
61 ** When the course spreads too much, you get a misfire, and the
62 ** course is randomized even more. You also have the chance that
63 ** the misfire damages your torpedo tubes.
66 static int randcourse
__P((int));
71 int v
__attribute__((__unused__
));
85 printf("Federation regulations do not permit attack while cloaked.\n");
88 if (check_out(TORPED
))
92 printf("All photon torpedos expended\n");
97 course
= getintpar("Torpedo course");
98 if (course
< 0 || course
> 360)
102 /* need at least three torpedoes for a burst */
105 printf("No-burst mode selected\n");
110 /* see if the user wants one */
113 k
= ungetc(cgetc(0), stdin
);
114 if (k
>= '0' && k
<= '9')
120 burst
= getynpar("Do you want a burst");
124 burst
= getintpar("burst angle");
128 printf("Maximum burst angle is 15 degrees\n");
139 for (; n
&& n
<= 3; n
++)
141 /* select a nice random course */
142 course2
= course
+ randcourse(n
);
143 angle
= course2
* 0.0174532925; /* convert to radians */
152 x
= Ship
.sectx
+ 0.5;
153 y
= Ship
.secty
+ 0.5;
154 if (Ship
.cond
!= DOCKED
)
156 printf("Torpedo track");
158 printf(", torpedo number %d", n
);
159 printf(":\n%6.1f\t%4.1f\n", x
, y
);
164 if (x
< 0.0 || x
>= sectsize
|| y
< 0.0 || y
>= sectsize
)
166 printf("Torpedo missed\n");
169 printf("%6.1f\t%4.1f\n", x
, y
);
170 switch (Sect
[ix
][iy
])
176 printf("Torpedo disappears into a black hole\n");
180 for (k
= 0; k
< Etc
.nkling
; k
++)
182 if (Etc
.klingon
[k
].x
!= ix
|| Etc
.klingon
[k
].y
!= iy
)
184 Etc
.klingon
[k
].power
-= 500 + ranf(501);
185 if (Etc
.klingon
[k
].power
> 0)
187 printf("*** Hit on Klingon at %d,%d: extensive damages\n",
205 killb(Ship
.quadx
, Ship
.quady
);
209 printf("Unknown object %c at %d,%d destroyed\n",
210 Sect
[ix
][iy
], ix
, iy
);
211 Sect
[ix
][iy
] = EMPTY
;
216 if (damaged(TORPED
) || Quad
[Ship
.quadx
][Ship
.quady
].stars
< 0)
227 ** This routine randomizes the course for torpedo number 'n'.
228 ** Other things handled by this routine are misfires, damages
229 ** to the tubes, etc.
239 d
= ((franf() + franf()) - 1.0) * 20;
242 printf("Photon tubes misfire");
246 printf(" on torpedo %d\n", n
);
249 damage(TORPED
, 0.2 * abs(d
) * (franf() + 1.0));
251 d
*= 1.0 + 2.0 * franf();
253 if (Ship
.shldup
|| Ship
.cond
== DOCKED
)
256 r
= 1.0 + r
/ Param
.shield
;
257 if (Ship
.cond
== DOCKED
)