]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/assorted.c
Normalize signature of ship handling functions -- struct ship * from and
[bsdgames-darwin.git] / sail / assorted.c
1 /* $NetBSD: assorted.c,v 1.13 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[] = "@(#)assorted.c 8.2 (Berkeley) 4/28/95";
40 #else
41 __RCSID("$NetBSD: assorted.c,v 1.13 2001/01/04 06:16:51 jwise Exp $");
42 #endif
43 #endif /* not lint */
44
45 #include <stdlib.h>
46 #include <err.h>
47 #include "extern.h"
48
49 void table(struct ship *, struct ship *, int, int, int, int);
50 void Cleansnag(struct ship *, struct ship *, int, int);
51 static void strike (struct ship *, struct ship *);
52
53 void
54 table(struct ship *from, struct ship *on, int rig, int shot, int hittable, int roll)
55 {
56 int hhits = 0, chits = 0, ghits = 0, rhits = 0;
57 int Ghit = 0, Hhit = 0, Rhit = 0, Chit = 0;
58 int guns, car, pc, hull;
59 int crew[3];
60 int n;
61 int rigg[4];
62 const char *message;
63 const struct Tables *tp;
64
65 pc = on->file->pcrew;
66 hull = on->specs->hull;
67 crew[0] = on->specs->crew1;
68 crew[1] = on->specs->crew2;
69 crew[2] = on->specs->crew3;
70 rigg[0] = on->specs->rig1;
71 rigg[1] = on->specs->rig2;
72 rigg[2] = on->specs->rig3;
73 rigg[3] = on->specs->rig4;
74 if (shot == L_GRAPE)
75 Chit = chits = hittable;
76 else {
77 tp = &(rig ? RigTable : HullTable)[hittable][roll-1];
78 Chit = chits = tp->C;
79 Rhit = rhits = tp->R;
80 Hhit = hhits = tp->H;
81 Ghit = ghits = tp->G;
82 if (on->file->FS)
83 rhits *= 2;
84 if (shot == L_CHAIN) {
85 Ghit = ghits = 0;
86 Hhit = hhits = 0;
87 }
88 }
89 if (on->file->captured != 0) {
90 pc -= (chits + 1) / 2;
91 chits /= 2;
92 }
93 for (n = 0; n < 3; n++)
94 if (chits > crew[n]) {
95 chits -= crew[n];
96 crew[n] = 0;
97 } else {
98 crew[n] -= chits;
99 chits = 0;
100 }
101 for (n = 0; n < 3; n++)
102 if (rhits > rigg[n]){
103 rhits -= rigg[n];
104 rigg[n] = 0;
105 } else {
106 rigg[n] -= rhits;
107 rhits = 0;
108 }
109 if (rigg[3] != -1 && rhits > rigg[3]) {
110 rhits -= rigg[3];
111 rigg[3] = 0;
112 } else if (rigg[3] != -1) {
113 rigg[3] -= rhits;
114 }
115 if (rig && !rigg[2] && (!rigg[3] || rigg[3] == -1))
116 makemsg(on, "dismasted!");
117 if (portside(from, on, 0)) {
118 guns = on->specs->gunR;
119 car = on->specs->carR;
120 } else {
121 guns = on->specs->gunL;
122 car = on->specs->carL;
123 }
124 if (ghits > car) {
125 ghits -= car;
126 car = 0;
127 } else {
128 car -= ghits;
129 ghits = 0;
130 }
131 if (ghits > guns){
132 ghits -= guns;
133 guns = 0;
134 } else {
135 guns -= ghits;
136 ghits = 0;
137 }
138 hull -= ghits;
139 if (Ghit)
140 Write(portside(from, on, 0) ? W_GUNR : W_GUNL,
141 on, guns, car, 0, 0);
142 hull -= hhits;
143 hull = hull < 0 ? 0 : hull;
144 if (on->file->captured != 0 && Chit)
145 Write(W_PCREW, on, pc, 0, 0, 0);
146 if (Hhit)
147 Write(W_HULL, on, hull, 0, 0, 0);
148 if (Chit)
149 Write(W_CREW, on, crew[0], crew[1], crew[2], 0);
150 if (Rhit)
151 Write(W_RIGG, on, rigg[0], rigg[1], rigg[2], rigg[3]);
152 switch (shot) {
153 case L_ROUND:
154 message = "firing round shot on $$";
155 break;
156 case L_GRAPE:
157 message = "firing grape shot on $$";
158 break;
159 case L_CHAIN:
160 message = "firing chain shot on $$";
161 break;
162 case L_DOUBLE:
163 message = "firing double shot on $$";
164 break;
165 case L_EXPLODE:
166 message = "exploding shot on $$";
167 break;
168 default:
169 errx(1, "Unknown shot type %d", shot);
170
171 }
172 makesignal(from, message, on);
173 if (roll == 6 && rig) {
174 switch(Rhit) {
175 case 0:
176 message = "fore topsail sheets parted";
177 break;
178 case 1:
179 message = "mizzen shrouds parted";
180 break;
181 case 2:
182 message = "main topsail yard shot away";
183 break;
184 case 4:
185 message = "fore topmast and foremast shrouds shot away";
186 break;
187 case 5:
188 message = "mizzen mast and yard shot through";
189 break;
190 case 6:
191 message = "foremast and spritsail yard shattered";
192 break;
193 case 7:
194 message = "main topmast and mizzen mast shattered";
195 break;
196 default:
197 errx(1, "Bad Rhit = %d", Rhit);
198 }
199 makemsg(on, message);
200 } else if (roll == 6) {
201 switch (Hhit) {
202 case 0:
203 message = "anchor cables severed";
204 break;
205 case 1:
206 message = "two anchor stocks shot away";
207 break;
208 case 2:
209 message = "quarterdeck bulwarks damaged";
210 break;
211 case 3:
212 message = "three gun ports shot away";
213 break;
214 case 4:
215 message = "four guns dismounted";
216 break;
217 case 5:
218 message = "rudder cables shot through";
219 Write(W_TA, on, 0, 0, 0, 0);
220 break;
221 case 6:
222 message = "shot holes below the water line";
223 break;
224 default:
225 errx(1, "Bad Hhit = %d", Hhit);
226 }
227 makemsg(on, message);
228 }
229 /*
230 if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) {
231 on->specs->qual--;
232 if (on->specs->qual <= 0) {
233 makemsg(on, "crew mutinying!");
234 on->specs->qual = 5;
235 Write(W_CAPTURED, on, on->file->index, 0, 0, 0);
236 } else
237 makemsg(on, "crew demoralized");
238 Write(W_QUAL, on, on->specs->qual, 0, 0, 0);
239 }
240 */
241 if (!hull)
242 strike(on, from);
243 }
244
245 void
246 Cleansnag(struct ship *from, struct ship *to, int all, int flag)
247 {
248 if (flag & 1) {
249 Write(W_UNGRAP, from, to->file->index, all, 0, 0);
250 Write(W_UNGRAP, to, from->file->index, all, 0, 0);
251 }
252 if (flag & 2) {
253 Write(W_UNFOUL, from, to->file->index, all, 0, 0);
254 Write(W_UNFOUL, to, from->file->index, all, 0, 0);
255 }
256 if (!snagged2(from, to)) {
257 if (!snagged(from)) {
258 unboard(from, from, 1); /* defense */
259 unboard(from, from, 0); /* defense */
260 } else
261 unboard(from, to, 0); /* offense */
262 if (!snagged(to)) {
263 unboard(to, to, 1); /* defense */
264 unboard(to, to, 0); /* defense */
265 } else
266 unboard(to, from, 0); /* offense */
267 }
268 }
269
270 static void
271 strike(struct ship *ship, struct ship *from)
272 {
273 int points;
274
275 if (ship->file->struck)
276 return;
277 Write(W_STRUCK, ship, 1, 0, 0, 0);
278 points = ship->specs->pts + from->file->points;
279 Write(W_POINTS, from, points, 0, 0, 0);
280 unboard(ship, ship, 0); /* all offense */
281 unboard(ship, ship, 1); /* all defense */
282 switch (dieroll()) {
283 case 3:
284 case 4: /* ship may sink */
285 Write(W_SINK, ship, 1, 0, 0, 0);
286 break;
287 case 5:
288 case 6: /* ship may explode */
289 Write(W_EXPLODE, ship, 1, 0, 0, 0);
290 break;
291 }
292 Writestr(W_SIGNAL, ship, "striking her colours!");
293 }