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
33 * @(#)assorted.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/sail/assorted.c,v 1.5 1999/11/30 03:49:31 billf Exp $
35 * $DragonFly: src/games/sail/assorted.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
40 table(rig
, shot
, hittable
, on
, from
, roll
)
41 struct ship
*on
, *from
;
42 int rig
, shot
, hittable
, roll
;
44 int hhits
= 0, chits
= 0, ghits
= 0, rhits
= 0;
45 int Ghit
= 0, Hhit
= 0, Rhit
= 0, Chit
= 0;
46 int guns
, car
, pc
, hull
;
54 hull
= on
->specs
->hull
;
55 crew
[0] = on
->specs
->crew1
;
56 crew
[1] = on
->specs
->crew2
;
57 crew
[2] = on
->specs
->crew3
;
58 rigg
[0] = on
->specs
->rig1
;
59 rigg
[1] = on
->specs
->rig2
;
60 rigg
[2] = on
->specs
->rig3
;
61 rigg
[3] = on
->specs
->rig4
;
63 Chit
= chits
= hittable
;
65 tp
= &(rig
? RigTable
: HullTable
)[hittable
][roll
-1];
72 if (shot
== L_CHAIN
) {
77 if (on
->file
->captured
!= 0) {
78 pc
-= (chits
+ 1) / 2;
81 for (n
= 0; n
< 3; n
++)
82 if (chits
> crew
[n
]) {
89 for (n
= 0; n
< 3; n
++)
97 if (rigg
[3] != -1 && rhits
> rigg
[3]) {
100 } else if (rigg
[3] != -1) {
103 if (rig
&& !rigg
[2] && (!rigg
[3] || rigg
[3] == -1))
104 makesignal(on
, "dismasted!", (struct ship
*)0);
105 if (portside(from
, on
, 0)) {
106 guns
= on
->specs
->gunR
;
107 car
= on
->specs
->carR
;
109 guns
= on
->specs
->gunL
;
110 car
= on
->specs
->carL
;
128 Write(portside(from
, on
, 0) ? W_GUNR
: W_GUNL
,
129 on
, 0, guns
, car
, 0, 0);
131 hull
= hull
< 0 ? 0 : hull
;
132 if (on
->file
->captured
!= 0 && Chit
)
133 Write(W_PCREW
, on
, 0, pc
, 0, 0, 0);
135 Write(W_HULL
, on
, 0, hull
, 0, 0, 0);
137 Write(W_CREW
, on
, 0, crew
[0], crew
[1], crew
[2], 0);
139 Write(W_RIGG
, on
, 0, rigg
[0], rigg
[1], rigg
[2], rigg
[3]);
142 message
= "firing round shot on %s (%c%c)";
145 message
= "firing grape shot on %s (%c%c)";
148 message
= "firing chain shot on %s (%c%c)";
151 message
= "firing double shot on %s (%c%c)";
154 message
= "exploding shot on %s (%c%c)";
156 makesignal(from
, message
, on
);
157 if (roll
== 6 && rig
) {
160 message
= "fore topsail sheets parted";
163 message
= "mizzen shrouds parted";
166 message
= "main topsail yard shot away";
169 message
= "fore topmast and foremast shrouds shot away";
172 message
= "mizzen mast and yard shot through";
175 message
= "foremast and spritsail yard shattered";
178 message
= "main topmast and mizzen mast shattered";
181 makesignal(on
, message
, (struct ship
*)0);
182 } else if (roll
== 6) {
185 message
= "anchor cables severed";
188 message
= "two anchor stocks shot away";
191 message
= "quarterdeck bulwarks damaged";
194 message
= "three gun ports shot away";
197 message
= "four guns dismounted";
200 message
= "rudder cables shot through";
201 Write(W_TA
, on
, 0, 0, 0, 0, 0);
204 message
= "shot holes below the water line";
207 makesignal(on
, message
, (struct ship
*)0);
210 if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) {
212 if (on->specs->qual <= 0) {
213 makesignal(on, "crew mutinying!", (struct ship *)0);
215 Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0);
217 makesignal(on, "crew demoralized", (struct ship *)0);
218 Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0);
225 Cleansnag(from
, to
, all
, flag
)
226 struct ship
*from
, *to
;
230 Write(W_UNGRAP
, from
, 0, to
->file
->index
, all
, 0, 0);
231 Write(W_UNGRAP
, to
, 0, from
->file
->index
, all
, 0, 0);
234 Write(W_UNFOUL
, from
, 0, to
->file
->index
, all
, 0, 0);
235 Write(W_UNFOUL
, to
, 0, from
->file
->index
, all
, 0, 0);
237 if (!snagged2(from
, to
)) {
238 if (!snagged(from
)) {
239 unboard(from
, from
, 1); /* defense */
240 unboard(from
, from
, 0); /* defense */
242 unboard(from
, to
, 0); /* offense */
244 unboard(to
, to
, 1); /* defense */
245 unboard(to
, to
, 0); /* defense */
247 unboard(to
, from
, 0); /* offense */
252 struct ship
*ship
, *from
;
256 if (ship
->file
->struck
)
258 Write(W_STRUCK
, ship
, 0, 1, 0, 0, 0);
259 points
= ship
->specs
->pts
+ from
->file
->points
;
260 Write(W_POINTS
, from
, 0, points
, 0, 0, 0);
261 unboard(ship
, ship
, 0); /* all offense */
262 unboard(ship
, ship
, 1); /* all defense */
265 case 4: /* ship may sink */
266 Write(W_SINK
, ship
, 0, 1, 0, 0, 0);
269 case 6: /* ship may explode */
270 Write(W_EXPLODE
, ship
, 0, 1, 0, 0, 0);
273 Write(W_SIGNAL
, ship
, 1, (int) "striking her colours!", 0, 0, 0);