]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_3.c
Rationalize inclusion of header files: cut down on `include everything
[bsdgames-darwin.git] / sail / pl_3.c
1 /* $NetBSD: pl_3.c,v 1.12 2001/01/04 03:21:17 jwise Exp $ */
2
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)pl_3.c 8.1 (Berkeley) 5/31/93";
40 #else
41 __RCSID("$NetBSD: pl_3.c,v 1.12 2001/01/04 03:21:17 jwise Exp $");
42 #endif
43 #endif /* not lint */
44
45 #include <stdlib.h>
46 #include "player.h"
47
48 void acceptcombat(void);
49 void grapungrap(void);
50 void unfoulplayer(void);
51
52 void
53 acceptcombat(void)
54 {
55 int men = 0;
56 int target, temp;
57 int n, r;
58 int index, rakehim, sternrake;
59 int hhits = 0, ghits = 0, rhits = 0, chits = 0;
60 int crew[3];
61 int load;
62 int guns, car, ready, shootat, hit;
63 int roll;
64 struct ship *closest;
65
66 crew[0] = mc->crew1;
67 crew[1] = mc->crew2;
68 crew[2] = mc->crew3;
69 for (n = 0; n < 3; n++) {
70 if (mf->OBP[n].turnsent)
71 men += mf->OBP[n].mensent;
72 }
73 for (n = 0; n < 3; n++) {
74 if (mf->DBP[n].turnsent)
75 men += mf->DBP[n].mensent;
76 }
77 if (men) {
78 crew[0] = men/100 ? 0 : crew[0] != 0;
79 crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
80 crew[2] = men%10 ? 0 : crew[2] != 0;
81 }
82 for (r = 0; r < 2; r++) {
83 if (r) {
84 ready = mf->readyR;
85 load = mf->loadR;
86 guns = mc->gunR;
87 car = mc->carR;
88 } else {
89 ready = mf->readyL;
90 load = mf->loadL;
91 guns = mc->gunL;
92 car = mc->carL;
93 }
94 if ((!guns && !car) || load == L_EMPTY || (ready & R_LOADED) == 0)
95 goto cant;
96 if (mf->struck || !crew[2])
97 goto cant;
98 closest = closestenemy(ms, (r ? 'r' : 'l'), 1);
99 if (closest == 0)
100 goto cant;
101 if (closest->file->struck)
102 goto cant;
103 target = range(ms, closest);
104 if (target > rangeofshot[load] || (!guns && target >= 3))
105 goto cant;
106 Signal("$$ within range of %s broadside.",
107 closest, r ? "right" : "left");
108 if (load > L_CHAIN && target < 6) {
109 switch (sgetch("Aim for hull or rigging? ",
110 (struct ship *)0, 1)) {
111 case 'r':
112 shootat = RIGGING;
113 break;
114 case 'h':
115 shootat = HULL;
116 break;
117 default:
118 shootat = -1;
119 Msg("'Avast there! Hold your fire.'");
120 }
121 } else {
122 if (sgetch("Fire? ", (struct ship *)0, 1) == 'n') {
123 shootat = -1;
124 Msg("Belay that! Hold your fire.");
125 } else
126 shootat = RIGGING;
127 }
128 if (shootat == -1)
129 continue;
130 fired = 1;
131 rakehim = gunsbear(ms, closest) && !gunsbear(closest, ms);
132 temp = portside(closest, ms, 1) - closest->file->dir + 1;
133 if (temp < 1)
134 temp += 8;
135 else if (temp > 8)
136 temp -= 8;
137 sternrake = temp > 4 && temp < 6;
138 if (rakehim) {
139 if (!sternrake)
140 Msg("Raking the %s!", closest->shipname);
141 else
142 Msg("Stern Rake! %s splintering!",
143 closest->shipname);
144 }
145 index = guns;
146 if (target < 3)
147 index += car;
148 index = (index - 1)/3;
149 index = index > 8 ? 8 : index;
150 if (!rakehim)
151 hit = HDT[index][target-1];
152 else
153 hit = HDTrake[index][target-1];
154 if (rakehim && sternrake)
155 hit++;
156 hit += QUAL[index][mc->qual-1];
157 for (n = 0; n < 3 && mf->captured == 0; n++)
158 if (!crew[n]) {
159 if (index <= 5)
160 hit--;
161 else
162 hit -= 2;
163 }
164 if (ready & R_INITIAL) {
165 if (index <= 3)
166 hit++;
167 else
168 hit += 2;
169 }
170 if (mf->captured != 0) {
171 if (index <= 1)
172 hit--;
173 else
174 hit -= 2;
175 }
176 hit += AMMO[index][load - 1];
177 if (((temp = mc->class) >= 5 || temp == 1) && windspeed == 5)
178 hit--;
179 if (windspeed == 6 && temp == 4)
180 hit -= 2;
181 if (windspeed == 6 && temp <= 3)
182 hit--;
183 if (hit >= 0) {
184 roll = dieroll();
185 if (load == L_GRAPE)
186 chits = hit;
187 else {
188 const struct Tables *t;
189 if (hit > 10)
190 hit = 10;
191 t = &(shootat == RIGGING ? RigTable : HullTable)
192 [hit][roll-1];
193 chits = t->C;
194 rhits = t->R;
195 hhits = t->H;
196 ghits = t->G;
197 if (closest->file->FS)
198 rhits *= 2;
199 if (load == L_CHAIN) {
200 ghits = 0;
201 hhits = 0;
202 }
203 }
204 table(shootat, load, hit, closest, ms, roll);
205 }
206 Msg("Damage inflicted on the %s:", closest->shipname);
207 Msg("\t%d HULL, %d GUNS, %d CREW, %d RIGGING",
208 hhits, ghits, chits, rhits);
209 if (!r) {
210 mf->loadL = L_EMPTY;
211 mf->readyL = R_EMPTY;
212 } else {
213 mf->loadR = L_EMPTY;
214 mf->readyR = R_EMPTY;
215 }
216 continue;
217 cant:
218 Msg("Unable to fire %s broadside", r ? "right" : "left");
219 }
220 blockalarm();
221 draw_stat();
222 unblockalarm();
223 }
224
225 void
226 grapungrap(void)
227 {
228 struct ship *sp;
229 int i;
230
231 foreachship(sp) {
232 if (sp == ms || sp->file->dir == 0)
233 continue;
234 if (range(ms, sp) > 1 && !grappled2(ms, sp))
235 continue;
236 switch (sgetch("Attempt to grapple or ungrapple $$: ",
237 sp, 1)) {
238 case 'g':
239 if (dieroll() < 3
240 || ms->nationality == capship(sp)->nationality) {
241 Write(W_GRAP, ms, sp->file->index, 0, 0, 0);
242 Write(W_GRAP, sp, player, 0, 0, 0);
243 Msg("Attempt succeeds!");
244 makesignal(ms, "grappled with $$", sp);
245 } else
246 Msg("Attempt fails.");
247 break;
248 case 'u':
249 for (i = grappled2(ms, sp); --i >= 0;) {
250 if (ms->nationality
251 == capship(sp)->nationality
252 || dieroll() < 3) {
253 cleangrapple(ms, sp, 0);
254 Msg("Attempt succeeds!");
255 makesignal(ms, "ungrappling with $$",
256 sp);
257 } else
258 Msg("Attempt fails.");
259 }
260 break;
261 }
262 }
263 }
264
265 void
266 unfoulplayer(void)
267 {
268 struct ship *to;
269 int i;
270
271 foreachship(to) {
272 if (fouled2(ms, to) == 0)
273 continue;
274 if (sgetch("Attempt to unfoul with the $$? ", to, 1) != 'y')
275 continue;
276 for (i = fouled2(ms, to); --i >= 0;) {
277 if (dieroll() <= 2) {
278 cleanfoul(ms, to, 0);
279 Msg("Attempt succeeds!");
280 makesignal(ms, "Unfouling $$", to);
281 } else
282 Msg("Attempt fails.");
283 }
284 }
285 }