]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_3.c
Normalize signature of ship handling functions -- struct ship * from and
[bsdgames-darwin.git] / sail / pl_3.c
1 /* $NetBSD: pl_3.c,v 1.15 2001/01/04 06:16:51 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.15 2001/01/04 06:16:51 jwise Exp $");
42 #endif
43 #endif /* not lint */
44
45 #include <signal.h>
46 #include <stdlib.h>
47 #include "extern.h"
48 #include "player.h"
49
50 void acceptcombat(void);
51 void grapungrap(void);
52 void unfoulplayer(void);
53
54 void
55 acceptcombat(void)
56 {
57 int men = 0;
58 int target, temp;
59 int n, r;
60 int index, rakehim, sternrake;
61 int hhits = 0, ghits = 0, rhits = 0, chits = 0;
62 int crew[3];
63 int load;
64 int guns, car, ready, shootat, hit;
65 int roll;
66 struct ship *closest;
67
68 crew[0] = mc->crew1;
69 crew[1] = mc->crew2;
70 crew[2] = mc->crew3;
71 for (n = 0; n < 3; n++) {
72 if (mf->OBP[n].turnsent)
73 men += mf->OBP[n].mensent;
74 }
75 for (n = 0; n < 3; n++) {
76 if (mf->DBP[n].turnsent)
77 men += mf->DBP[n].mensent;
78 }
79 if (men) {
80 crew[0] = men/100 ? 0 : crew[0] != 0;
81 crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
82 crew[2] = men%10 ? 0 : crew[2] != 0;
83 }
84 for (r = 0; r < 2; r++) {
85 if (r) {
86 ready = mf->readyR;
87 load = mf->loadR;
88 guns = mc->gunR;
89 car = mc->carR;
90 } else {
91 ready = mf->readyL;
92 load = mf->loadL;
93 guns = mc->gunL;
94 car = mc->carL;
95 }
96 if ((!guns && !car) || load == L_EMPTY || (ready & R_LOADED) == 0)
97 goto cant;
98 if (mf->struck || !crew[2])
99 goto cant;
100 closest = closestenemy(ms, (r ? 'r' : 'l'), 1);
101 if (closest == 0)
102 goto cant;
103 if (closest->file->struck)
104 goto cant;
105 target = range(ms, closest);
106 if (target > rangeofshot[load] || (!guns && target >= 3))
107 goto cant;
108 Signal("$$ within range of %s broadside.",
109 closest, r ? "right" : "left");
110 if (load > L_CHAIN && target < 6) {
111 switch (sgetch("Aim for hull or rigging? ",
112 (struct ship *)0, 1)) {
113 case 'r':
114 shootat = RIGGING;
115 break;
116 case 'h':
117 shootat = HULL;
118 break;
119 default:
120 shootat = -1;
121 Msg("'Avast there! Hold your fire.'");
122 }
123 } else {
124 if (sgetch("Fire? ", (struct ship *)0, 1) == 'n') {
125 shootat = -1;
126 Msg("Belay that! Hold your fire.");
127 } else
128 shootat = RIGGING;
129 }
130 if (shootat == -1)
131 continue;
132 fired = 1;
133 rakehim = gunsbear(ms, closest) && !gunsbear(closest, ms);
134 temp = portside(closest, ms, 1) - closest->file->dir + 1;
135 if (temp < 1)
136 temp += 8;
137 else if (temp > 8)
138 temp -= 8;
139 sternrake = temp > 4 && temp < 6;
140 if (rakehim) {
141 if (!sternrake)
142 Msg("Raking the %s!", closest->shipname);
143 else
144 Msg("Stern Rake! %s splintering!",
145 closest->shipname);
146 }
147 index = guns;
148 if (target < 3)
149 index += car;
150 index = (index - 1)/3;
151 index = index > 8 ? 8 : index;
152 if (!rakehim)
153 hit = HDT[index][target-1];
154 else
155 hit = HDTrake[index][target-1];
156 if (rakehim && sternrake)
157 hit++;
158 hit += QUAL[index][mc->qual-1];
159 for (n = 0; n < 3 && mf->captured == 0; n++)
160 if (!crew[n]) {
161 if (index <= 5)
162 hit--;
163 else
164 hit -= 2;
165 }
166 if (ready & R_INITIAL) {
167 if (index <= 3)
168 hit++;
169 else
170 hit += 2;
171 }
172 if (mf->captured != 0) {
173 if (index <= 1)
174 hit--;
175 else
176 hit -= 2;
177 }
178 hit += AMMO[index][load - 1];
179 if (((temp = mc->class) >= 5 || temp == 1) && windspeed == 5)
180 hit--;
181 if (windspeed == 6 && temp == 4)
182 hit -= 2;
183 if (windspeed == 6 && temp <= 3)
184 hit--;
185 if (hit >= 0) {
186 roll = dieroll();
187 if (load == L_GRAPE)
188 chits = hit;
189 else {
190 const struct Tables *t;
191 if (hit > 10)
192 hit = 10;
193 t = &(shootat == RIGGING ? RigTable : HullTable)
194 [hit][roll-1];
195 chits = t->C;
196 rhits = t->R;
197 hhits = t->H;
198 ghits = t->G;
199 if (closest->file->FS)
200 rhits *= 2;
201 if (load == L_CHAIN) {
202 ghits = 0;
203 hhits = 0;
204 }
205 }
206 table(ms, closest, shootat, load, hit, roll);
207 }
208 Msg("Damage inflicted on the %s:", closest->shipname);
209 Msg("\t%d HULL, %d GUNS, %d CREW, %d RIGGING",
210 hhits, ghits, chits, rhits);
211 if (!r) {
212 mf->loadL = L_EMPTY;
213 mf->readyL = R_EMPTY;
214 } else {
215 mf->loadR = L_EMPTY;
216 mf->readyR = R_EMPTY;
217 }
218 continue;
219 cant:
220 Msg("Unable to fire %s broadside", r ? "right" : "left");
221 }
222 blockalarm();
223 draw_stat();
224 unblockalarm();
225 }
226
227 void
228 grapungrap(void)
229 {
230 struct ship *sp;
231 int i;
232
233 foreachship(sp) {
234 if (sp == ms || sp->file->dir == 0)
235 continue;
236 if (range(ms, sp) > 1 && !grappled2(ms, sp))
237 continue;
238 switch (sgetch("Attempt to grapple or ungrapple $$: ",
239 sp, 1)) {
240 case 'g':
241 if (dieroll() < 3
242 || ms->nationality == capship(sp)->nationality) {
243 Write(W_GRAP, ms, sp->file->index, 0, 0, 0);
244 Write(W_GRAP, sp, player, 0, 0, 0);
245 Msg("Attempt succeeds!");
246 makesignal(ms, "grappled with $$", sp);
247 } else
248 Msg("Attempt fails.");
249 break;
250 case 'u':
251 for (i = grappled2(ms, sp); --i >= 0;) {
252 if (ms->nationality
253 == capship(sp)->nationality
254 || dieroll() < 3) {
255 cleangrapple(ms, sp, 0);
256 Msg("Attempt succeeds!");
257 makesignal(ms, "ungrappling with $$",
258 sp);
259 } else
260 Msg("Attempt fails.");
261 }
262 break;
263 }
264 }
265 }
266
267 void
268 unfoulplayer(void)
269 {
270 struct ship *to;
271 int i;
272
273 foreachship(to) {
274 if (fouled2(ms, to) == 0)
275 continue;
276 if (sgetch("Attempt to unfoul with the $$? ", to, 1) != 'y')
277 continue;
278 for (i = fouled2(ms, to); --i >= 0;) {
279 if (dieroll() <= 2) {
280 cleanfoul(ms, to, 0);
281 Msg("Attempt succeeds!");
282 makesignal(ms, "Unfouling $$", to);
283 } else
284 Msg("Attempt fails.");
285 }
286 }
287 }