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