Commit | Line | Data |
---|---|---|
b1823ffa | 1 | #ifndef lint |
70461436 | 2 | static char *sccsid = "@(#)pl_3.c 1.3 83/10/14"; |
b1823ffa EW |
3 | #endif |
4 | ||
5 | #include "player.h" | |
6 | ||
7 | acceptcombat() | |
8 | { | |
9 | int men = 0; | |
10 | int target, temp; | |
11 | int n, r; | |
12 | int index, rakehim, sternrake; | |
13 | int hhits = 0, ghits = 0, rhits = 0, chits = 0; | |
14 | int crew[3]; | |
15 | int load; | |
16 | int guns, car, ready, shootat, hit; | |
17 | int roll; | |
18 | struct ship *closest; | |
19 | ||
20 | crew[0] = mc->crew1; | |
21 | crew[1] = mc->crew2; | |
22 | crew[2] = mc->crew3; | |
23 | for (n = 0; n < 3; n++) { | |
24 | if (mf->OBP[n].turnsent) | |
25 | men += mf->OBP[n].mensent; | |
26 | } | |
27 | for (n = 0; n < 3; n++) { | |
28 | if (mf->DBP[n].turnsent) | |
29 | men += mf->DBP[n].mensent; | |
30 | } | |
31 | if (men) { | |
32 | crew[0] = men/100 ? 0 : crew[0] != 0; | |
33 | crew[1] = (men%100)/10 ? 0 : crew[1] != 0; | |
34 | crew[2] = men%10 ? 0 : crew[2] != 0; | |
35 | } | |
36 | for (r = 0; r < 2; r++) { | |
37 | if (r) { | |
38 | ready = mf->readyR; | |
39 | load = mf->loadR; | |
40 | guns = mc->gunR; | |
41 | car = mc->carR; | |
42 | } else { | |
43 | ready = mf->readyL; | |
44 | load = mf->loadL; | |
45 | guns = mc->gunL; | |
46 | car = mc->carL; | |
47 | } | |
48 | if (!guns && !car || load == L_EMPTY || (ready & R_LOADED) == 0) | |
49 | goto cant; | |
50 | if (mf->struck || !crew[2]) | |
51 | goto cant; | |
52 | closest = closestenemy(ms, (r ? 'r' : 'l'), 1); | |
53 | if (closest == 0) | |
54 | goto cant; | |
55 | if (closest->file->struck) | |
56 | goto cant; | |
57 | target = range(ms, closest); | |
58 | if (target > rangeofshot[load] || !guns && target >= 3) | |
59 | goto cant; | |
60 | Signal("%s (%c%c) within range of %s broadside.", | |
61 | closest, r ? "right" : "left"); | |
62 | if (load > L_CHAIN && target < 6) { | |
63 | Signal("Aim for hull or rigging? ", (struct ship *)0); | |
64 | switch (sgetch(1)) { | |
65 | case 'r': | |
66 | shootat = RIGGING; | |
67 | break; | |
68 | case 'h': | |
69 | shootat = HULL; | |
70 | break; | |
71 | default: | |
72 | shootat = -1; | |
73 | Signal("'Avast there! Hold your fire.'", | |
74 | (struct ship *)0); | |
75 | } | |
76 | } else { | |
77 | Signal("Fire? ", (struct ship *)0); | |
78 | if (sgetch(1) == 'n') { | |
79 | shootat = -1; | |
80 | Signal("Belay that! Hold your fire.", | |
81 | (struct ship *)0); | |
82 | } else | |
83 | shootat = RIGGING; | |
84 | } | |
85 | if (shootat == -1) | |
86 | continue; | |
87 | fired = 1; | |
88 | rakehim = gunsbear(ms, closest) && !gunsbear(closest, ms); | |
89 | temp = portside(closest, ms, 1) - closest->file->dir + 1; | |
90 | if (temp < 1) | |
91 | temp += 8; | |
92 | else if (temp > 8) | |
93 | temp -= 8; | |
94 | sternrake = temp > 4 && temp < 6; | |
95 | if (rakehim) | |
96 | if (!sternrake) | |
97 | Signal("Raking the %s!", closest); | |
98 | else | |
99 | Signal("Stern Rake! %s splintering!", closest); | |
100 | index = guns; | |
101 | if (target < 3) | |
102 | index += car; | |
103 | index = (index - 1)/3; | |
104 | index = index > 8 ? 8 : index; | |
105 | if (!rakehim) | |
106 | hit = HDT[index][target-1]; | |
107 | else | |
108 | hit = HDTrake[index][target-1]; | |
109 | if (rakehim && sternrake) | |
110 | hit++; | |
111 | hit += QUAL[index][mc->qual-1]; | |
112 | for (n = 0; n < 3 && mf->captured == 0; n++) | |
113 | if (!crew[n]) | |
114 | if (index <= 5) | |
115 | hit--; | |
116 | else | |
117 | hit -= 2; | |
118 | if (ready & R_INITIAL) | |
119 | if (index <= 3) | |
120 | hit++; | |
121 | else | |
122 | hit += 2; | |
123 | if (mf->captured != 0) | |
124 | if (index <= 1) | |
125 | hit--; | |
126 | else | |
127 | hit -= 2; | |
128 | hit += AMMO[index][load - 1]; | |
129 | if (((temp = mc->class) >= 5 || temp == 1) && windspeed == 5) | |
130 | hit--; | |
131 | if (windspeed == 6 && temp == 4) | |
132 | hit -= 2; | |
133 | if (windspeed == 6 && temp <= 3) | |
134 | hit--; | |
135 | if (hit >= 0) { | |
136 | roll = die(); | |
137 | if (load == L_GRAPE) | |
138 | chits = hit; | |
139 | else { | |
140 | struct Tables *t; | |
141 | if (hit > 10) | |
142 | hit = 10; | |
143 | t = &(shootat == RIGGING ? RigTable : HullTable) | |
144 | [hit][roll-1]; | |
145 | chits = t->C; | |
146 | rhits = t->R; | |
147 | hhits = t->H; | |
148 | ghits = t->G; | |
149 | if (closest->file->FS) | |
150 | rhits *= 2; | |
151 | if (load == L_CHAIN) { | |
152 | ghits = 0; | |
153 | hhits = 0; | |
154 | } | |
155 | } | |
156 | table(shootat, load, hit, closest, ms, roll); | |
157 | } | |
158 | Scroll2(); | |
159 | (void) wprintw(scroll_w, "Damage inflicted on the %s:", | |
160 | closest->shipname); | |
161 | Scroll(); | |
162 | (void) wprintw(scroll_w, | |
163 | "\t%d HULL, %d GUNS, %d CREW, %d RIGGING", | |
164 | hhits, ghits, chits, rhits); | |
165 | if (!r) { | |
166 | mf->loadL = L_EMPTY; | |
167 | mf->readyL = R_EMPTY; | |
168 | } else { | |
169 | mf->loadR = L_EMPTY; | |
170 | mf->readyR = R_EMPTY; | |
171 | } | |
172 | continue; | |
173 | cant: | |
174 | Signal("Unable to fire %s broadside", | |
175 | (struct ship *)0, r ? "right" : "left"); | |
176 | } | |
177 | } | |
178 | ||
179 | grapungrap() | |
180 | { | |
181 | register struct ship *sp; | |
182 | register int n, k; | |
183 | register struct snag *p; | |
70461436 | 184 | int r; |
b1823ffa EW |
185 | |
186 | n = -1; | |
187 | foreachship(sp) { | |
188 | n++; | |
189 | if (sp == ms) | |
190 | continue; | |
70461436 EW |
191 | r = range(ms, sp); |
192 | if (r < 0 || r > 1 && !grappled2(ms, sp)) | |
b1823ffa EW |
193 | continue; |
194 | Signal("Attempt to grapple or ungrapple %s (%c%c): ", sp); | |
195 | switch (sgetch(1)) { | |
196 | case 'g': | |
197 | if (die() < 3 | |
198 | || ms->nationality == capship(sp)->nationality) { | |
199 | for (k = 0, p = mf->grapples; | |
200 | k < NSHIP && p->turnfoul; k++, p++) | |
201 | ; /* XXX */ | |
202 | if (k < NSHIP) | |
203 | Write(W_GRAP, ms, 0, k, turn, n, 0); | |
204 | for (k = 0, p = sp->file->grapples; | |
205 | k < NSHIP && p->turnfoul; k++, p++) | |
206 | ; /* XXX */ | |
207 | if (k < NSHIP) | |
208 | Write(W_GRAP, sp, 0, | |
209 | k, turn, player, 0); | |
210 | Signal("Attempt succeeds!", (struct ship *)0); | |
211 | makesignal(ms, "grappled with %s (%c%c)", sp); | |
212 | } else | |
213 | Signal("Attempt fails.", (struct ship *)0); | |
214 | break; | |
215 | case 'u': | |
216 | for (k = 0; k < NSHIP; k++) { | |
217 | if (!mf->grapples[k].turnfoul) | |
218 | continue; | |
219 | if (sp != mf->grapples[k].toship) | |
220 | continue; | |
221 | if (die() < 3 || ms->nationality | |
222 | == capship(sp)->nationality) { | |
223 | cleangrapple(ms, sp, k); | |
224 | Signal("Attempt succeeds!", | |
225 | (struct ship *)0); | |
226 | makesignal(ms, | |
227 | "ungrappling with %s (%c%c)", | |
228 | sp); | |
229 | } else | |
230 | Signal("Attempt fails.", | |
231 | (struct ship *)0); | |
232 | } | |
233 | } | |
234 | } | |
235 | } | |
236 | ||
237 | unfoulplayer() | |
238 | { | |
239 | register struct snag *s = mf->fouls; | |
240 | register struct ship *to; | |
241 | int n; | |
242 | ||
243 | for (n = 0; n < NSHIP; n++, s++) { | |
244 | if (s->turnfoul == 0) | |
245 | continue; | |
246 | to = s->toship; | |
247 | Signal("Attempt to unfoul with the %s (%c%c)? ", to); | |
248 | if (sgetch(1) == 'y') { | |
249 | if (die() < 3) { | |
250 | cleanfoul(ms, to, n); | |
251 | Signal("Attempt succeeds!", | |
252 | (struct ship *)0); | |
253 | makesignal(ms, "Unfouling %s (%c%c)", to); | |
254 | } else | |
255 | Signal("Attempt fails.", (struct ship *)0); | |
256 | } | |
257 | } | |
258 | } | |
259 | ||
260 | lookout() | |
261 | { | |
262 | register struct ship *sp; | |
263 | char buf[3]; | |
264 | register char c; | |
265 | ||
266 | Signal("What ship? ", (struct ship *)0); | |
267 | sgetstr(buf, sizeof buf); | |
268 | foreachship(sp) { | |
269 | c = *countryname[sp->nationality]; | |
270 | if ((c == *buf || tolower(c) == *buf || colours(sp) == *buf) | |
271 | && (sp->file->stern == buf[1] || sterncolour(sp) == buf[1])) | |
70461436 EW |
272 | { |
273 | eyeball(sp); | |
274 | return; | |
275 | } | |
b1823ffa | 276 | } |
70461436 | 277 | Signal("No such ship.", (struct ship *)0); |
b1823ffa EW |
278 | } |
279 | ||
280 | char * | |
281 | saywhat(sp, flag) | |
282 | register struct ship *sp; | |
283 | char flag; | |
284 | { | |
285 | if (sp->file->captain[0]) | |
286 | return sp->file->captain; | |
287 | else if (sp->file->struck) | |
288 | return "(struck)"; | |
289 | else if (sp->file->captured != 0) | |
290 | return "(captured)"; | |
291 | else if (flag) | |
292 | return "(available)"; | |
293 | else | |
294 | return "(computer)"; | |
295 | } | |
296 | ||
297 | eyeball(ship) | |
298 | register struct ship *ship; | |
299 | { | |
300 | int i; | |
301 | ||
302 | if (ship == 0) | |
303 | Signal("No more ships left.", (struct ship *)0); | |
6c17b19a | 304 | else if (ship->file->dir != 0) { |
b1823ffa EW |
305 | Signal("Sail ho! (range %d, %s)", |
306 | (struct ship *)0, range(ms, ship), saywhat(ship, 0)); | |
307 | i = portside(ms, ship, 1) - mf->dir; | |
308 | if (i <= 0) | |
309 | i += 8; | |
310 | Signal("%s (%c%c) %s %s %s.", | |
311 | ship, countryname[ship->nationality], | |
312 | classname[ship->specs->class], directionname[i]); | |
313 | } | |
314 | } |