2 * Copyright (c) 1983, 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
36 static char sccsid[] = "@(#)pl_3.c 8.1 (Berkeley) 5/31/93";
38 static const char rcsid[] =
39 "$FreeBSD: src/games/sail/pl_3.c,v 1.6 1999/11/30 03:49:37 billf Exp $";
49 int index, rakehim, sternrake;
50 int hhits = 0, ghits = 0, rhits = 0, chits = 0;
53 int guns, car, ready, shootat, hit;
60 for (n = 0; n < 3; n++) {
61 if (mf->OBP[n].turnsent)
62 men += mf->OBP[n].mensent;
64 for (n = 0; n < 3; n++) {
65 if (mf->DBP[n].turnsent)
66 men += mf->DBP[n].mensent;
69 crew[0] = men/100 ? 0 : crew[0] != 0;
70 crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
71 crew[2] = men%10 ? 0 : crew[2] != 0;
73 for (r = 0; r < 2; r++) {
85 if (!guns && !car || load == L_EMPTY || (ready & R_LOADED) == 0)
87 if (mf->struck || !crew[2])
89 closest = closestenemy(ms, (r ? 'r' : 'l'), 1);
92 if (closest->file->struck)
94 target = range(ms, closest);
95 if (target > rangeofshot[load] || !guns && target >= 3)
97 Signal("%s (%c%c) within range of %s broadside.",
98 closest, r ? "right" : "left");
99 if (load > L_CHAIN && target < 6) {
100 switch (sgetch("Aim for hull or rigging? ",
101 (struct ship *)0, 1)) {
110 Signal("'Avast there! Hold your fire.'",
114 if (sgetch("Fire? ", (struct ship *)0, 1) == 'n') {
116 Signal("Belay that! Hold your fire.",
124 rakehim = gunsbear(ms, closest) && !gunsbear(closest, ms);
125 temp = portside(closest, ms, 1) - closest->file->dir + 1;
130 sternrake = temp > 4 && temp < 6;
133 Signal("Raking the %s!", closest);
135 Signal("Stern Rake! %s splintering!", closest);
140 index = (index - 1)/3;
141 index = index > 8 ? 8 : index;
143 hit = HDT[index][target-1];
145 hit = HDTrake[index][target-1];
146 if (rakehim && sternrake)
148 hit += QUAL[index][mc->qual-1];
149 for (n = 0; n < 3 && mf->captured == 0; n++)
156 if (ready & R_INITIAL) {
162 if (mf->captured != 0) {
168 hit += AMMO[index][load - 1];
169 if (((temp = mc->class) >= 5 || temp == 1) && windspeed == 5)
171 if (windspeed == 6 && temp == 4)
173 if (windspeed == 6 && temp <= 3)
183 t = &(shootat == RIGGING ? RigTable : HullTable)
189 if (closest->file->FS)
191 if (load == L_CHAIN) {
196 table(shootat, load, hit, closest, ms, roll);
198 Signal("Damage inflicted on the %s:",
199 (struct ship *)0, closest->shipname);
200 Signal("\t%d HULL, %d GUNS, %d CREW, %d RIGGING",
201 (struct ship *)0, hhits, ghits, chits, rhits);
204 mf->readyL = R_EMPTY;
207 mf->readyR = R_EMPTY;
211 Signal("Unable to fire %s broadside",
212 (struct ship *)0, r ? "right" : "left");
225 if (sp == ms || sp->file->dir == 0)
227 if (range(ms, sp) > 1 && !grappled2(ms, sp))
229 switch (sgetch("Attempt to grapple or ungrapple %s (%c%c): ",
233 || ms->nationality == capship(sp)->nationality) {
234 Write(W_GRAP, ms, 0, sp->file->index, 0, 0, 0);
235 Write(W_GRAP, sp, 0, player, 0, 0, 0);
236 Signal("Attempt succeeds!", (struct ship *)0);
237 makesignal(ms, "grappled with %s (%c%c)", sp);
239 Signal("Attempt fails.", (struct ship *)0);
242 for (i = grappled2(ms, sp); --i >= 0;) {
244 == capship(sp)->nationality
246 cleangrapple(ms, sp, 0);
247 Signal("Attempt succeeds!",
250 "ungrappling with %s (%c%c)",
253 Signal("Attempt fails.",
267 if (fouled2(ms, to) == 0)
269 if (sgetch("Attempt to unfoul with the %s (%c%c)? ", to, 1) != 'y')
271 for (i = fouled2(ms, to); --i >= 0;) {
273 cleanfoul(ms, to, 0);
274 Signal("Attempt succeeds!", (struct ship *)0);
275 makesignal(ms, "Unfouling %s (%c%c)", to);
277 Signal("Attempt fails.", (struct ship *)0);