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