1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32: #include <sys/cdefs.h>
33: #ifndef lint
34: #if 0
35: static char sccsid[] = "@(#)torped.c 8.1 (Berkeley) 5/31/93";
36: #else
37: __RCSID("$NetBSD: torped.c,v 1.8 2004/01/27 20:30:31 jsm Exp $");
38: #endif
39: #endif
40:
41: #include <stdio.h>
42: #include <stdlib.h>
43: #include <math.h>
44: #include "trek.h"
45: #include "getpar.h"
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66: static int randcourse(int);
67:
68:
69: void
70: torped(v)
71: int v __attribute__((__unused__));
72: {
73: int ix, iy;
74: double x, y, dx, dy;
75: double angle;
76: int course, course2;
77: int k;
78: double bigger;
79: double sectsize;
80: int burst;
81: int n;
82:
83: if (Ship.cloaked)
84: {
85: printf("Federation regulations do not permit attack while cloaked.\n");
86: return;
87: }
88: if (check_out(TORPED))
89: return;
90: if (Ship.torped <= 0)
91: {
92: printf("All photon torpedos expended\n");
93: return;
94: }
95:
96:
97: course = getintpar("Torpedo course");
98: if (course < 0 || course > 360)
99: return;
100: burst = -1;
101:
102:
103: if (Ship.torped < 3)
104: {
105: printf("No-burst mode selected\n");
106: burst = 0;
107: }
108: else
109: {
110:
111: if (!testnl())
112: {
113: k = ungetc(cgetc(0), stdin);
114: if (k >= '0' && k <= '9')
115: burst = 1;
116: }
117: }
118: if (burst < 0)
119: {
120: burst = getynpar("Do you want a burst");
121: }
122: if (burst)
123: {
124: burst = getintpar("burst angle");
125: if (burst <= 0)
126: return;
127: if (burst > 15) {
128: printf("Maximum burst angle is 15 degrees\n");
129: return;
130: }
131: }
132: sectsize = NSECTS;
133: n = -1;
134: if (burst)
135: {
136: n = 1;
137: course -= burst;
138: }
139: for (; n && n <= 3; n++)
140: {
141:
142: course2 = course + randcourse(n);
143: angle = course2 * 0.0174532925;
144: dx = -cos(angle);
145: dy = sin(angle);
146: bigger = fabs(dx);
147: x = fabs(dy);
148: if (x > bigger)
149: bigger = x;
150: dx /= bigger;
151: dy /= bigger;
152: x = Ship.sectx + 0.5;
153: y = Ship.secty + 0.5;
154: if (Ship.cond != DOCKED)
155: Ship.torped -= 1;
156: printf("Torpedo track");
157: if (n > 0)
158: printf(", torpedo number %d", n);
159: printf(":\n%6.1f\t%4.1f\n", x, y);
160: while (1)
161: {
162: ix = x += dx;
163: iy = y += dy;
164: if (x < 0.0 || x >= sectsize || y < 0.0 || y >= sectsize)
165: {
166: printf("Torpedo missed\n");
167: break;
168: }
169: printf("%6.1f\t%4.1f\n", x, y);
170: switch (Sect[ix][iy])
171: {
172: case EMPTY:
173: continue;
174:
175: case HOLE:
176: printf("Torpedo disappears into a black hole\n");
177: break;
178:
179: case KLINGON:
180: for (k = 0; k < Etc.nkling; k++)
181: {
182: if (Etc.klingon[k].x != ix || Etc.klingon[k].y != iy)
183: continue;
184: Etc.klingon[k].power -= 500 + ranf(501);
185: if (Etc.klingon[k].power > 0)
186: {
187: printf("*** Hit on Klingon at %d,%d: extensive damages\n",
188: ix, iy);
189: break;
190: }
191: killk(ix, iy);
192: break;
193: }
194: break;
195:
196: case STAR:
197: nova(ix, iy);
198: break;
199:
200: case INHABIT:
201: kills(ix, iy, -1);
202: break;
203:
204: case BASE:
205: killb(Ship.quadx, Ship.quady);
206: Game.killb += 1;
207: break;
208: default:
209: printf("Unknown object %c at %d,%d destroyed\n",
210: Sect[ix][iy], ix, iy);
211: Sect[ix][iy] = EMPTY;
212: break;
213: }
214: break;
215: }
216: if (damaged(TORPED) || Quad[Ship.quadx][Ship.quady].stars < 0)
217: break;
218: course += burst;
219: }
220: Move.free = 0;
221: }
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232: static int
233: randcourse(n)
234: int n;
235: {
236: double r;
237: int d;
238:
239: d = ((franf() + franf()) - 1.0) * 20;
240: if (abs(d) > 12)
241: {
242: printf("Photon tubes misfire");
243: if (n < 0)
244: printf("\n");
245: else
246: printf(" on torpedo %d\n", n);
247: if (ranf(2))
248: {
249: damage(TORPED, 0.2 * abs(d) * (franf() + 1.0));
250: }
251: d *= 1.0 + 2.0 * franf();
252: }
253: if (Ship.shldup || Ship.cond == DOCKED)
254: {
255: r = Ship.shield;
256: r = 1.0 + r / Param.shield;
257: if (Ship.cond == DOCKED)
258: r = 2.0;
259: d *= r;
260: }
261: return (d);
262: }