Fix mbuf handling for unsupported operations
[unix-history] / usr / src / games / sail / assorted.c
CommitLineData
931d7dfa 1#ifndef lint
0fc2c279 2static char *sccsid = "@(#)assorted.c 2.4 84/02/03";
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)) {
b3a57661
EW
73 guns = on->specs->gunR;
74 car = on->specs->carR;
0fc2c279
EW
75 } else {
76 guns = on->specs->gunL;
77 car = on->specs->carL;
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 94 if (Ghit)
0fc2c279 95 Write(portside(from, on, 0) ? W_GUNR : W_GUNL,
b3a57661 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 }
46c1696b
EW
176 /*
177 if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) {
b3a57661
EW
178 on->specs->qual--;
179 if (on->specs->qual <= 0) {
180 makesignal(on, "crew mutinying!", (struct ship *)0);
181 on->specs->qual = 5;
6ca45914 182 Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0);
931d7dfa 183 } else
b3a57661
EW
184 makesignal(on, "crew demoralized", (struct ship *)0);
185 Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0);
931d7dfa 186 }
46c1696b 187 */
931d7dfa 188 if (!hull)
b3a57661 189 strike(on, from);
931d7dfa
CL
190}
191
6ca45914 192Cleansnag(from, to, all, flag)
b3a57661 193register struct ship *from, *to;
6ca45914 194char all, flag;
931d7dfa 195{
6ca45914
EW
196 if (flag & 1) {
197 Write(W_UNGRAP, from, 0, to->file->index, all, 0, 0);
198 Write(W_UNGRAP, to, 0, from->file->index, all, 0, 0);
199 }
200 if (flag & 2) {
201 Write(W_UNFOUL, from, 0, to->file->index, all, 0, 0);
202 Write(W_UNFOUL, to, 0, from->file->index, all, 0, 0);
931d7dfa 203 }
b3a57661 204 if (!snagged2(from, to)) {
6ca45914 205 if (!snagged(from)) {
b3a57661
EW
206 unboard(from, from, 1); /* defense */
207 unboard(from, from, 0); /* defense */
931d7dfa 208 } else
6ca45914
EW
209 unboard(from, to, 0); /* offense */
210 if (!snagged(to)) {
211 unboard(to, to, 1); /* defense */
212 unboard(to, to, 0); /* defense */
931d7dfa 213 } else
b3a57661 214 unboard(to, from, 0); /* offense */
931d7dfa
CL
215 }
216}
217
b3a57661
EW
218strike(ship, from)
219register struct ship *ship, *from;
931d7dfa
CL
220{
221 int points;
222
b3a57661
EW
223 if (ship->file->struck)
224 return;
225 Write(W_STRUCK, ship, 0, 1, 0, 0, 0);
226 points = ship->specs->pts + from->file->points;
227 Write(W_POINTS, from, 0, points, 0, 0, 0);
228 unboard(ship, ship, 0); /* all offense */
229 unboard(ship, ship, 1); /* all defense */
230 switch (die()) {
231 case 3:
232 case 4: /* ship may sink */
233 Write(W_SINK, ship, 0, 1, 0, 0, 0);
234 break;
235 case 5:
236 case 6: /* ship may explode */
237 Write(W_EXPLODE, ship, 0, 1, 0, 0, 0);
238 break;
931d7dfa 239 }
b3a57661 240 Write(W_SIGNAL, ship, 1, (int) "striking her colours!", 0, 0, 0);
931d7dfa 241}