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