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