]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/assorted.c
Use standard AUTHORS section header. From YOMURA Masanori in private mail
[bsdgames-darwin.git] / sail / assorted.c
1 /* $NetBSD: assorted.c,v 1.15 2003/08/07 09:37:41 agc 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. 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.
18 *
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
29 * SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 #ifndef lint
34 #if 0
35 static char sccsid[] = "@(#)assorted.c 8.2 (Berkeley) 4/28/95";
36 #else
37 __RCSID("$NetBSD: assorted.c,v 1.15 2003/08/07 09:37:41 agc Exp $");
38 #endif
39 #endif /* not lint */
40
41 #include <stdlib.h>
42 #include <err.h>
43 #include "extern.h"
44
45 static void strike (struct ship *, struct ship *);
46
47 void
48 table(struct ship *from, struct ship *on, int rig, int shot, int hittable, int roll)
49 {
50 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 int n;
55 int rigg[4];
56 const char *message;
57 const 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 makemsg(on, "dismasted!");
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, 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, pc, 0, 0, 0);
140 if (Hhit)
141 Write(W_HULL, on, hull, 0, 0, 0);
142 if (Chit)
143 Write(W_CREW, on, crew[0], crew[1], crew[2], 0);
144 if (Rhit)
145 Write(W_RIGG, on, rigg[0], rigg[1], rigg[2], rigg[3]);
146 switch (shot) {
147 case L_ROUND:
148 message = "firing round shot on $$";
149 break;
150 case L_GRAPE:
151 message = "firing grape shot on $$";
152 break;
153 case L_CHAIN:
154 message = "firing chain shot on $$";
155 break;
156 case L_DOUBLE:
157 message = "firing double shot on $$";
158 break;
159 case L_EXPLODE:
160 message = "exploding shot on $$";
161 break;
162 default:
163 errx(1, "Unknown shot type %d", shot);
164
165 }
166 makesignal(from, message, on);
167 if (roll == 6 && rig) {
168 switch(Rhit) {
169 case 0:
170 message = "fore topsail sheets parted";
171 break;
172 case 1:
173 message = "mizzen shrouds parted";
174 break;
175 case 2:
176 message = "main topsail yard shot away";
177 break;
178 case 4:
179 message = "fore topmast and foremast shrouds shot away";
180 break;
181 case 5:
182 message = "mizzen mast and yard shot through";
183 break;
184 case 6:
185 message = "foremast and spritsail yard shattered";
186 break;
187 case 7:
188 message = "main topmast and mizzen mast shattered";
189 break;
190 default:
191 errx(1, "Bad Rhit = %d", Rhit);
192 }
193 makemsg(on, message);
194 } else if (roll == 6) {
195 switch (Hhit) {
196 case 0:
197 message = "anchor cables severed";
198 break;
199 case 1:
200 message = "two anchor stocks shot away";
201 break;
202 case 2:
203 message = "quarterdeck bulwarks damaged";
204 break;
205 case 3:
206 message = "three gun ports shot away";
207 break;
208 case 4:
209 message = "four guns dismounted";
210 break;
211 case 5:
212 message = "rudder cables shot through";
213 Write(W_TA, on, 0, 0, 0, 0);
214 break;
215 case 6:
216 message = "shot holes below the water line";
217 break;
218 default:
219 errx(1, "Bad Hhit = %d", Hhit);
220 }
221 makemsg(on, message);
222 }
223 /*
224 if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) {
225 on->specs->qual--;
226 if (on->specs->qual <= 0) {
227 makemsg(on, "crew mutinying!");
228 on->specs->qual = 5;
229 Write(W_CAPTURED, on, on->file->index, 0, 0, 0);
230 } else
231 makemsg(on, "crew demoralized");
232 Write(W_QUAL, on, on->specs->qual, 0, 0, 0);
233 }
234 */
235 if (!hull)
236 strike(on, from);
237 }
238
239 void
240 Cleansnag(struct ship *from, struct ship *to, int all, int flag)
241 {
242 if (flag & 1) {
243 Write(W_UNGRAP, from, to->file->index, all, 0, 0);
244 Write(W_UNGRAP, to, from->file->index, all, 0, 0);
245 }
246 if (flag & 2) {
247 Write(W_UNFOUL, from, to->file->index, all, 0, 0);
248 Write(W_UNFOUL, to, from->file->index, all, 0, 0);
249 }
250 if (!snagged2(from, to)) {
251 if (!snagged(from)) {
252 unboard(from, from, 1); /* defense */
253 unboard(from, from, 0); /* defense */
254 } else
255 unboard(from, to, 0); /* offense */
256 if (!snagged(to)) {
257 unboard(to, to, 1); /* defense */
258 unboard(to, to, 0); /* defense */
259 } else
260 unboard(to, from, 0); /* offense */
261 }
262 }
263
264 static void
265 strike(struct ship *ship, struct ship *from)
266 {
267 int points;
268
269 if (ship->file->struck)
270 return;
271 Write(W_STRUCK, ship, 1, 0, 0, 0);
272 points = ship->specs->pts + from->file->points;
273 Write(W_POINTS, from, points, 0, 0, 0);
274 unboard(ship, ship, 0); /* all offense */
275 unboard(ship, ship, 1); /* all defense */
276 switch (dieroll()) {
277 case 3:
278 case 4: /* ship may sink */
279 Write(W_SINK, ship, 1, 0, 0, 0);
280 break;
281 case 5:
282 case 6: /* ship may explode */
283 Write(W_EXPLODE, ship, 1, 0, 0, 0);
284 break;
285 }
286 Writestr(W_SIGNAL, ship, "striking her colours!");
287 }