]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/assorted.c
1 /* $NetBSD: assorted.c,v 1.14 2001/02/05 01:10:08 christos 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. 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.
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
36 #include <sys/cdefs.h>
39 static char sccsid
[] = "@(#)assorted.c 8.2 (Berkeley) 4/28/95";
41 __RCSID("$NetBSD: assorted.c,v 1.14 2001/02/05 01:10:08 christos Exp $");
49 static void strike (struct ship
*, struct ship
*);
52 table(struct ship
*from
, struct ship
*on
, int rig
, int shot
, int hittable
, int roll
)
54 int hhits
= 0, chits
= 0, ghits
= 0, rhits
= 0;
55 int Ghit
= 0, Hhit
= 0, Rhit
= 0, Chit
= 0;
56 int guns
, car
, pc
, hull
;
61 const struct Tables
*tp
;
64 hull
= on
->specs
->hull
;
65 crew
[0] = on
->specs
->crew1
;
66 crew
[1] = on
->specs
->crew2
;
67 crew
[2] = on
->specs
->crew3
;
68 rigg
[0] = on
->specs
->rig1
;
69 rigg
[1] = on
->specs
->rig2
;
70 rigg
[2] = on
->specs
->rig3
;
71 rigg
[3] = on
->specs
->rig4
;
73 Chit
= chits
= hittable
;
75 tp
= &(rig
? RigTable
: HullTable
)[hittable
][roll
-1];
82 if (shot
== L_CHAIN
) {
87 if (on
->file
->captured
!= 0) {
88 pc
-= (chits
+ 1) / 2;
91 for (n
= 0; n
< 3; n
++)
92 if (chits
> crew
[n
]) {
99 for (n
= 0; n
< 3; n
++)
100 if (rhits
> rigg
[n
]){
107 if (rigg
[3] != -1 && rhits
> rigg
[3]) {
110 } else if (rigg
[3] != -1) {
113 if (rig
&& !rigg
[2] && (!rigg
[3] || rigg
[3] == -1))
114 makemsg(on
, "dismasted!");
115 if (portside(from
, on
, 0)) {
116 guns
= on
->specs
->gunR
;
117 car
= on
->specs
->carR
;
119 guns
= on
->specs
->gunL
;
120 car
= on
->specs
->carL
;
138 Write(portside(from
, on
, 0) ? W_GUNR
: W_GUNL
,
139 on
, guns
, car
, 0, 0);
141 hull
= hull
< 0 ? 0 : hull
;
142 if (on
->file
->captured
!= 0 && Chit
)
143 Write(W_PCREW
, on
, pc
, 0, 0, 0);
145 Write(W_HULL
, on
, hull
, 0, 0, 0);
147 Write(W_CREW
, on
, crew
[0], crew
[1], crew
[2], 0);
149 Write(W_RIGG
, on
, rigg
[0], rigg
[1], rigg
[2], rigg
[3]);
152 message
= "firing round shot on $$";
155 message
= "firing grape shot on $$";
158 message
= "firing chain shot on $$";
161 message
= "firing double shot on $$";
164 message
= "exploding shot on $$";
167 errx(1, "Unknown shot type %d", shot
);
170 makesignal(from
, message
, on
);
171 if (roll
== 6 && rig
) {
174 message
= "fore topsail sheets parted";
177 message
= "mizzen shrouds parted";
180 message
= "main topsail yard shot away";
183 message
= "fore topmast and foremast shrouds shot away";
186 message
= "mizzen mast and yard shot through";
189 message
= "foremast and spritsail yard shattered";
192 message
= "main topmast and mizzen mast shattered";
195 errx(1, "Bad Rhit = %d", Rhit
);
197 makemsg(on
, message
);
198 } else if (roll
== 6) {
201 message
= "anchor cables severed";
204 message
= "two anchor stocks shot away";
207 message
= "quarterdeck bulwarks damaged";
210 message
= "three gun ports shot away";
213 message
= "four guns dismounted";
216 message
= "rudder cables shot through";
217 Write(W_TA
, on
, 0, 0, 0, 0);
220 message
= "shot holes below the water line";
223 errx(1, "Bad Hhit = %d", Hhit
);
225 makemsg(on
, message
);
228 if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) {
230 if (on->specs->qual <= 0) {
231 makemsg(on, "crew mutinying!");
233 Write(W_CAPTURED, on, on->file->index, 0, 0, 0);
235 makemsg(on, "crew demoralized");
236 Write(W_QUAL, on, on->specs->qual, 0, 0, 0);
244 Cleansnag(struct ship
*from
, struct ship
*to
, int all
, int flag
)
247 Write(W_UNGRAP
, from
, to
->file
->index
, all
, 0, 0);
248 Write(W_UNGRAP
, to
, from
->file
->index
, all
, 0, 0);
251 Write(W_UNFOUL
, from
, to
->file
->index
, all
, 0, 0);
252 Write(W_UNFOUL
, to
, from
->file
->index
, all
, 0, 0);
254 if (!snagged2(from
, to
)) {
255 if (!snagged(from
)) {
256 unboard(from
, from
, 1); /* defense */
257 unboard(from
, from
, 0); /* defense */
259 unboard(from
, to
, 0); /* offense */
261 unboard(to
, to
, 1); /* defense */
262 unboard(to
, to
, 0); /* defense */
264 unboard(to
, from
, 0); /* offense */
269 strike(struct ship
*ship
, struct ship
*from
)
273 if (ship
->file
->struck
)
275 Write(W_STRUCK
, ship
, 1, 0, 0, 0);
276 points
= ship
->specs
->pts
+ from
->file
->points
;
277 Write(W_POINTS
, from
, points
, 0, 0, 0);
278 unboard(ship
, ship
, 0); /* all offense */
279 unboard(ship
, ship
, 1); /* all defense */
282 case 4: /* ship may sink */
283 Write(W_SINK
, ship
, 1, 0, 0, 0);
286 case 6: /* ship may explode */
287 Write(W_EXPLODE
, ship
, 1, 0, 0, 0);
290 Writestr(W_SIGNAL
, ship
, "striking her colours!");