date and time created 88/06/01 18:39:47 by bostic
[unix-history] / usr / src / games / sail / assorted.c
CommitLineData
b5f0675e 1/*
1e008c14 2 * Copyright (c) 1983 Regents of the University of California.
c0ca48ec
KB
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of California at Berkeley. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
b5f0675e
EW
11 */
12
931d7dfa 13#ifndef lint
c0ca48ec
KB
14static char sccsid[] = "@(#)assorted.c 5.2 (Berkeley) %G%";
15#endif /* not lint */
b3a57661 16
931d7dfa
CL
17#include "externs.h"
18
b3a57661
EW
19table(rig, shot, hittable, on, from, roll)
20struct ship *on, *from;
21int rig, shot, hittable, roll;
931d7dfa
CL
22{
23 register int hhits = 0, chits = 0, ghits = 0, rhits = 0;
24 int Ghit = 0, Hhit = 0, Rhit = 0, Chit = 0;
25 int guns, car, pc, hull;
26 int crew[3];
27 register int n;
28 int rigg[4];
b3a57661
EW
29 char *message;
30 struct Tables *tp;
931d7dfa 31
b3a57661
EW
32 pc = on->file->pcrew;
33 hull = on->specs->hull;
34 crew[0] = on->specs->crew1;
35 crew[1] = on->specs->crew2;
36 crew[2] = on->specs->crew3;
37 rigg[0] = on->specs->rig1;
38 rigg[1] = on->specs->rig2;
39 rigg[2] = on->specs->rig3;
40 rigg[3] = on->specs->rig4;
41 if (shot == L_GRAPE)
931d7dfa
CL
42 Chit = chits = hittable;
43 else {
b3a57661
EW
44 tp = &(rig ? RigTable : HullTable)[hittable][roll-1];
45 Chit = chits = tp->C;
46 Rhit = rhits = tp->R;
47 Hhit = hhits = tp->H;
48 Ghit = ghits = tp->G;
49 if (on->file->FS)
931d7dfa 50 rhits *= 2;
b3a57661 51 if (shot == L_CHAIN) {
931d7dfa
CL
52 Ghit = ghits = 0;
53 Hhit = hhits = 0;
54 }
55 }
b3a57661
EW
56 if (on->file->captured != 0) {
57 pc -= (chits + 1) / 2;
931d7dfa
CL
58 chits /= 2;
59 }
b3a57661
EW
60 for (n = 0; n < 3; n++)
61 if (chits > crew[n]) {
931d7dfa
CL
62 chits -= crew[n];
63 crew[n] = 0;
b3a57661 64 } else {
931d7dfa
CL
65 crew[n] -= chits;
66 chits = 0;
67 }
b3a57661 68 for (n = 0; n < 3; n++)
931d7dfa
CL
69 if (rhits > rigg[n]){
70 rhits -= rigg[n];
71 rigg[n] = 0;
b3a57661 72 } else {
931d7dfa
CL
73 rigg[n] -= rhits;
74 rhits = 0;
75 }
b3a57661 76 if (rigg[3] != -1 && rhits > rigg[3]) {
931d7dfa
CL
77 rhits -= rigg[3];
78 rigg[3] = 0;
b3a57661 79 } else if (rigg[3] != -1) {
931d7dfa
CL
80 rigg[3] -= rhits;
81 }
82 if (rig && !rigg[2] && (!rigg[3] || rigg[3] == -1))
b3a57661
EW
83 makesignal(on, "dismasted!", (struct ship *)0);
84 if (portside(from, on, 0)) {
b3a57661
EW
85 guns = on->specs->gunR;
86 car = on->specs->carR;
0fc2c279
EW
87 } else {
88 guns = on->specs->gunL;
89 car = on->specs->carL;
931d7dfa 90 }
b3a57661 91 if (ghits > car) {
931d7dfa
CL
92 ghits -= car;
93 car = 0;
b3a57661 94 } else {
931d7dfa
CL
95 car -= ghits;
96 ghits = 0;
97 }
98 if (ghits > guns){
99 ghits -= guns;
100 guns = 0;
b3a57661 101 } else {
931d7dfa
CL
102 guns -= ghits;
103 ghits = 0;
104 }
105 hull -= ghits;
b3a57661 106 if (Ghit)
0fc2c279 107 Write(portside(from, on, 0) ? W_GUNR : W_GUNL,
b3a57661 108 on, 0, guns, car, 0, 0);
931d7dfa
CL
109 hull -= hhits;
110 hull = hull < 0 ? 0 : hull;
b3a57661
EW
111 if (on->file->captured != 0 && Chit)
112 Write(W_PCREW, on, 0, pc, 0, 0, 0);
931d7dfa 113 if (Hhit)
b3a57661 114 Write(W_HULL, on, 0, hull, 0, 0, 0);
931d7dfa 115 if (Chit)
b3a57661 116 Write(W_CREW, on, 0, crew[0], crew[1], crew[2], 0);
931d7dfa 117 if (Rhit)
b3a57661
EW
118 Write(W_RIGG, on, 0, rigg[0], rigg[1], rigg[2], rigg[3]);
119 switch (shot) {
120 case L_ROUND:
121 message = "firing round shot on %s (%c%c)";
122 break;
123 case L_GRAPE:
124 message = "firing grape shot on %s (%c%c)";
125 break;
126 case L_CHAIN:
127 message = "firing chain shot on %s (%c%c)";
128 break;
129 case L_DOUBLE:
130 message = "firing double shot on %s (%c%c)";
131 break;
132 case L_EXPLODE:
133 message = "exploding shot on %s (%c%c)";
134 }
135 makesignal(from, message, on);
136 if (roll == 6 && rig) {
137 switch(Rhit) {
138 case 0:
139 message = "fore topsail sheets parted";
931d7dfa 140 break;
b3a57661
EW
141 case 1:
142 message = "mizzen shrouds parted";
931d7dfa 143 break;
b3a57661
EW
144 case 2:
145 message = "main topsail yard shot away";
931d7dfa 146 break;
b3a57661
EW
147 case 4:
148 message = "fore topmast and foremast shrouds shot away";
149 break;
150 case 5:
151 message = "mizzen mast and yard shot through";
152 break;
153 case 6:
154 message = "foremast and spritsail yard shattered";
155 break;
156 case 7:
157 message = "main topmast and mizzen mast shattered";
931d7dfa 158 break;
931d7dfa 159 }
b3a57661
EW
160 makesignal(on, message, (struct ship *)0);
161 } else if (roll == 6) {
162 switch (Hhit) {
163 case 0:
164 message = "anchor cables severed";
165 break;
166 case 1:
167 message = "two anchor stocks shot away";
168 break;
169 case 2:
170 message = "quarterdeck bulwarks damaged";
171 break;
172 case 3:
173 message = "three gun ports shot away";
174 break;
175 case 4:
176 message = "four guns dismounted";
177 break;
178 case 5:
179 message = "rudder cables shot through";
180 Write(W_TA, on, 0, 0, 0, 0, 0);
181 break;
182 case 6:
183 message = "shot holes below the water line";
184 break;
931d7dfa 185 }
b3a57661 186 makesignal(on, message, (struct ship *)0);
931d7dfa 187 }
46c1696b
EW
188 /*
189 if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) {
b3a57661
EW
190 on->specs->qual--;
191 if (on->specs->qual <= 0) {
192 makesignal(on, "crew mutinying!", (struct ship *)0);
193 on->specs->qual = 5;
6ca45914 194 Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0);
931d7dfa 195 } else
b3a57661
EW
196 makesignal(on, "crew demoralized", (struct ship *)0);
197 Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0);
931d7dfa 198 }
46c1696b 199 */
931d7dfa 200 if (!hull)
b3a57661 201 strike(on, from);
931d7dfa
CL
202}
203
6ca45914 204Cleansnag(from, to, all, flag)
b3a57661 205register struct ship *from, *to;
6ca45914 206char all, flag;
931d7dfa 207{
6ca45914
EW
208 if (flag & 1) {
209 Write(W_UNGRAP, from, 0, to->file->index, all, 0, 0);
210 Write(W_UNGRAP, to, 0, from->file->index, all, 0, 0);
211 }
212 if (flag & 2) {
213 Write(W_UNFOUL, from, 0, to->file->index, all, 0, 0);
214 Write(W_UNFOUL, to, 0, from->file->index, all, 0, 0);
931d7dfa 215 }
b3a57661 216 if (!snagged2(from, to)) {
6ca45914 217 if (!snagged(from)) {
b3a57661
EW
218 unboard(from, from, 1); /* defense */
219 unboard(from, from, 0); /* defense */
931d7dfa 220 } else
6ca45914
EW
221 unboard(from, to, 0); /* offense */
222 if (!snagged(to)) {
223 unboard(to, to, 1); /* defense */
224 unboard(to, to, 0); /* defense */
931d7dfa 225 } else
b3a57661 226 unboard(to, from, 0); /* offense */
931d7dfa
CL
227 }
228}
229
b3a57661
EW
230strike(ship, from)
231register struct ship *ship, *from;
931d7dfa
CL
232{
233 int points;
234
b3a57661
EW
235 if (ship->file->struck)
236 return;
237 Write(W_STRUCK, ship, 0, 1, 0, 0, 0);
238 points = ship->specs->pts + from->file->points;
239 Write(W_POINTS, from, 0, points, 0, 0, 0);
240 unboard(ship, ship, 0); /* all offense */
241 unboard(ship, ship, 1); /* all defense */
242 switch (die()) {
243 case 3:
244 case 4: /* ship may sink */
245 Write(W_SINK, ship, 0, 1, 0, 0, 0);
246 break;
247 case 5:
248 case 6: /* ship may explode */
249 Write(W_EXPLODE, ship, 0, 1, 0, 0, 0);
250 break;
931d7dfa 251 }
b3a57661 252 Write(W_SIGNAL, ship, 1, (int) "striking her colours!", 0, 0, 0);
931d7dfa 253}