Commit | Line | Data |
---|---|---|
931d7dfa | 1 | #ifndef lint |
46c1696b | 2 | static char *sccsid = "@(#)assorted.c 1.3 83/10/28"; |
931d7dfa | 3 | #endif |
b3a57661 | 4 | |
931d7dfa CL |
5 | #include "externs.h" |
6 | ||
b3a57661 EW |
7 | table(rig, shot, hittable, on, from, roll) |
8 | struct ship *on, *from; | |
9 | int 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 | } |
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; | |
182 | Write(W_CAPTURED, on, 0, on-SHIP(0), 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 | ||
b3a57661 EW |
192 | cleanfoul(from, to, which) |
193 | register struct ship *from, *to; | |
194 | int which; | |
931d7dfa | 195 | { |
b3a57661 EW |
196 | register int n; |
197 | register struct snag *s = to->file->fouls; | |
931d7dfa | 198 | |
b3a57661 EW |
199 | Write(W_FOUL, from, 0, which, 0, 0, 0); |
200 | for (n = 0; n < NSHIP && (s->turnfoul || s->toship != from); n++, s++) | |
201 | ; | |
202 | if (n < NSHIP) | |
203 | Write(W_FOUL, to, 0, n, 0, 0, 0); | |
204 | if (!snagged2(from, to)) { | |
205 | if (!fouled(from) && !grappled(from)) { | |
206 | unboard(from, from, 1); /* defense */ | |
207 | unboard(from, from, 0); /* defense */ | |
931d7dfa | 208 | } else |
b3a57661 EW |
209 | unboard(from, to, 0); /* defense */ |
210 | if (!fouled(to) && !grappled(to)) { /* defense */ | |
211 | unboard(to, to, 1); | |
212 | unboard(to, to, 0); | |
931d7dfa | 213 | } else |
b3a57661 | 214 | unboard(to, from, 0); /* offense */ |
931d7dfa CL |
215 | } |
216 | } | |
217 | ||
b3a57661 EW |
218 | cleangrapple(from, to, which) |
219 | register struct ship *from, *to; | |
220 | int which; | |
931d7dfa | 221 | { |
b3a57661 EW |
222 | register int n; |
223 | register struct snag *s = to->file->grapples; | |
931d7dfa | 224 | |
b3a57661 EW |
225 | Write(W_GRAP, from, 0, which, 0, 0, 0); |
226 | for (n = 0; n < NSHIP && (s->turnfoul || s->toship != from); n++, s++) | |
227 | ; | |
228 | if (n < NSHIP) | |
229 | Write(W_FOUL, to, 0, n, 0, 0, 0); | |
230 | if (!snagged2(from, to)) { | |
231 | if (!fouled(from) && !grappled(from)) { | |
232 | unboard(from, from, 1); /* defense */ | |
233 | unboard(from, from, 0); /* defense */ | |
931d7dfa | 234 | } else |
b3a57661 EW |
235 | unboard(from, to, 0); /* defense */ |
236 | if (!fouled(to) && !grappled(to)) { /* defense */ | |
237 | unboard(to, to, 1); | |
238 | unboard(to, to, 0); | |
931d7dfa | 239 | } else |
b3a57661 | 240 | unboard(to, from, 0); /* offense */ |
931d7dfa CL |
241 | } |
242 | } | |
243 | ||
b3a57661 EW |
244 | strike(ship, from) |
245 | register struct ship *ship, *from; | |
931d7dfa CL |
246 | { |
247 | int points; | |
248 | ||
b3a57661 EW |
249 | if (ship->file->struck) |
250 | return; | |
251 | Write(W_STRUCK, ship, 0, 1, 0, 0, 0); | |
252 | points = ship->specs->pts + from->file->points; | |
253 | Write(W_POINTS, from, 0, points, 0, 0, 0); | |
254 | unboard(ship, ship, 0); /* all offense */ | |
255 | unboard(ship, ship, 1); /* all defense */ | |
256 | switch (die()) { | |
257 | case 3: | |
258 | case 4: /* ship may sink */ | |
259 | Write(W_SINK, ship, 0, 1, 0, 0, 0); | |
260 | break; | |
261 | case 5: | |
262 | case 6: /* ship may explode */ | |
263 | Write(W_EXPLODE, ship, 0, 1, 0, 0, 0); | |
264 | break; | |
931d7dfa | 265 | } |
b3a57661 | 266 | Write(W_SIGNAL, ship, 1, (int) "striking her colours!", 0, 0, 0); |
931d7dfa | 267 | } |