1 /* $NetBSD: assorted.c,v 1.16 2009/03/14 19:35:13 dholland Exp $ */
4 * Copyright (c) 1983, 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
[] = "@(#)assorted.c 8.2 (Berkeley) 4/28/95";
37 __RCSID("$NetBSD: assorted.c,v 1.16 2009/03/14 19:35:13 dholland Exp $");
45 static void strike(struct ship
*, struct ship
*);
48 table(struct ship
*from
, struct ship
*on
,
49 int rig
, int shot
, int hittable
, int roll
)
51 int hhits
= 0, chits
= 0, ghits
= 0, rhits
= 0;
52 int Ghit
= 0, Hhit
= 0, Rhit
= 0, Chit
= 0;
53 int guns
, car
, pc
, hull
;
58 const struct Tables
*tp
;
61 hull
= on
->specs
->hull
;
62 crew
[0] = on
->specs
->crew1
;
63 crew
[1] = on
->specs
->crew2
;
64 crew
[2] = on
->specs
->crew3
;
65 rigg
[0] = on
->specs
->rig1
;
66 rigg
[1] = on
->specs
->rig2
;
67 rigg
[2] = on
->specs
->rig3
;
68 rigg
[3] = on
->specs
->rig4
;
69 if (shot
== L_GRAPE
) {
70 Chit
= chits
= hittable
;
72 tp
= &(rig
? RigTable
: HullTable
)[hittable
][roll
-1];
79 if (shot
== L_CHAIN
) {
84 if (on
->file
->captured
!= 0) {
85 pc
-= (chits
+ 1) / 2;
88 for (n
= 0; n
< 3; n
++) {
89 if (chits
> crew
[n
]) {
97 for (n
= 0; n
< 3; n
++) {
98 if (rhits
> rigg
[n
]) {
106 if (rigg
[3] != -1 && rhits
> rigg
[3]) {
109 } else if (rigg
[3] != -1) {
112 if (rig
&& !rigg
[2] && (!rigg
[3] || rigg
[3] == -1))
113 makemsg(on
, "dismasted!");
114 if (portside(from
, on
, 0)) {
115 guns
= on
->specs
->gunR
;
116 car
= on
->specs
->carR
;
118 guns
= on
->specs
->gunL
;
119 car
= on
->specs
->carL
;
137 if (portside(from
, on
, 0)) {
138 send_gunr(on
, guns
, car
);
140 send_gunl(on
, guns
, car
);
144 hull
= hull
< 0 ? 0 : hull
;
145 if (on
->file
->captured
!= 0 && Chit
)
150 send_crew(on
, crew
[0], crew
[1], crew
[2]);
152 send_rigg(on
, rigg
[0], rigg
[1], rigg
[2], rigg
[3]);
155 message
= "firing round shot on $$";
158 message
= "firing grape shot on $$";
161 message
= "firing chain shot on $$";
164 message
= "firing double shot on $$";
167 message
= "exploding shot on $$";
170 errx(1, "Unknown shot type %d", shot
);
173 makesignal(from
, message
, on
);
174 if (roll
== 6 && rig
) {
177 message
= "fore topsail sheets parted";
180 message
= "mizzen shrouds parted";
183 message
= "main topsail yard shot away";
186 message
= "fore topmast and foremast shrouds shot away";
189 message
= "mizzen mast and yard shot through";
192 message
= "foremast and spritsail yard shattered";
195 message
= "main topmast and mizzen mast shattered";
198 errx(1, "Bad Rhit = %d", Rhit
);
200 makemsg(on
, message
);
201 } else if (roll
== 6) {
204 message
= "anchor cables severed";
207 message
= "two anchor stocks shot away";
210 message
= "quarterdeck bulwarks damaged";
213 message
= "three gun ports shot away";
216 message
= "four guns dismounted";
219 message
= "rudder cables shot through";
223 message
= "shot holes below the water line";
226 errx(1, "Bad Hhit = %d", Hhit
);
228 makemsg(on
, message
);
231 if (Chit > 1 && on->file->readyL & R_INITIAL &&
232 on->file->readyR & R_INITIAL) {
234 if (on->specs->qual <= 0) {
235 makemsg(on, "crew mutinying!");
237 Write(W_CAPTURED, on, on->file->index, 0, 0, 0);
239 makemsg(on, "crew demoralized");
241 Write(W_QUAL, on, on->specs->qual, 0, 0, 0);
249 Cleansnag(struct ship
*from
, struct ship
*to
, int all
, int flag
)
252 send_ungrap(from
, to
->file
->index
, all
);
253 send_ungrap(to
, from
->file
->index
, all
);
256 send_unfoul(from
, to
->file
->index
, all
);
257 send_unfoul(to
, from
->file
->index
, all
);
259 if (!snagged2(from
, to
)) {
260 if (!snagged(from
)) {
261 unboard(from
, from
, 1); /* defense */
262 unboard(from
, from
, 0); /* defense */
264 unboard(from
, to
, 0); /* offense */
266 unboard(to
, to
, 1); /* defense */
267 unboard(to
, to
, 0); /* defense */
269 unboard(to
, from
, 0); /* offense */
274 strike(struct ship
*ship
, struct ship
*from
)
278 if (ship
->file
->struck
)
280 send_struck(ship
, 1);
281 points
= ship
->specs
->pts
+ from
->file
->points
;
282 send_points(from
, points
);
283 unboard(ship
, ship
, 0); /* all offense */
284 unboard(ship
, ship
, 1); /* all defense */
287 case 4: /* ship may sink */
291 case 6: /* ship may explode */
292 send_explode(ship
, 1);
295 send_signal(ship
, "striking her colours!");