Commit | Line | Data |
---|---|---|
5f9f07ce | 1 | #ifndef lint |
9224751f | 2 | static char *sccsid = "@(#)pl_2.c 1.7 83/10/14"; |
5f9f07ce | 3 | #endif |
7fc06086 | 4 | |
5f9f07ce CL |
5 | #include "player.h" |
6 | ||
789d5e82 | 7 | #define turnfirst(x) (*x == 'r' || *x == 'l') |
5f9f07ce CL |
8 | |
9 | lost() | |
10 | { | |
b3a57661 EW |
11 | if (mf->struck) |
12 | leave(LEAVE_QUIT); | |
13 | if (mf->captured != 0) | |
14 | leave(LEAVE_CAPTURED); | |
5f9f07ce | 15 | if (windspeed == 7) |
b3a57661 EW |
16 | leave(LEAVE_HURRICAN); |
17 | if (mf->FS && (!mc->rig1 || windspeed == 6)) | |
18 | Write(W_FS, ms, 0, 0, 0, 0, 0); | |
5f9f07ce CL |
19 | } |
20 | ||
5f9f07ce CL |
21 | acceptmove(ma, ta, af) |
22 | int ma, ta, af; | |
23 | { | |
5f9f07ce | 24 | int moved = 0; |
b3a57661 | 25 | int vma, dir; |
789d5e82 | 26 | char prompt[60]; |
5f9f07ce | 27 | char buf[60], last = '\0'; |
b3a57661 | 28 | register char *p; |
5f9f07ce | 29 | |
b3a57661 EW |
30 | if (*movebuf) { |
31 | Signal("Already moved.", (struct ship *)0); | |
32 | return; | |
5f9f07ce | 33 | } |
9224751f | 34 | (void) sprintf(prompt, "move (%d,%c%d): ", ma, af ? '\'' : ' ', ta); |
789d5e82 | 35 | sgetstr(prompt, buf, sizeof buf); |
b3a57661 | 36 | dir = mf->dir; |
5f9f07ce | 37 | vma = ma; |
b3a57661 EW |
38 | for (p = buf; *p; p++) |
39 | switch (*p) { | |
40 | case 'l': | |
41 | dir -= 2; | |
42 | case 'r': | |
43 | if (++dir == 0) | |
44 | dir = 8; | |
45 | else if (dir == 9) | |
46 | dir = 1; | |
47 | if (last == 't') { | |
48 | Signal("Ship can't turn that fast.", | |
49 | (struct ship *)0); | |
50 | *p-- = '\0'; | |
5f9f07ce | 51 | } |
b3a57661 EW |
52 | last = 't'; |
53 | ma--; | |
54 | ta--; | |
55 | vma = min(ma, maxmove(ms, dir, 0)); | |
56 | if (ta < 0 && moved || vma < 0 && moved) | |
57 | *p-- = '\0'; | |
58 | break; | |
59 | case 'b': | |
60 | ma--; | |
61 | vma--; | |
62 | last = 'b'; | |
63 | if (ta < 0 && moved || vma < 0 && moved) | |
64 | *p-- = '\0'; | |
65 | break; | |
66 | case '0': | |
67 | case 'd': | |
68 | *p-- = '\0'; | |
69 | break; | |
70 | case '\n': | |
71 | *p-- = '\0'; | |
72 | break; | |
73 | case '1': case '2': case '3': case '4': | |
74 | case '5': case '6': case '7': | |
75 | if (last == '0') { | |
76 | Signal("Can't move that fast.", | |
77 | (struct ship *)0); | |
78 | *p-- = '\0'; | |
79 | } | |
80 | last = '0'; | |
81 | moved = 1; | |
82 | ma -= *p - '0'; | |
83 | vma -= *p - '0'; | |
84 | if (ta < 0 && moved || vma < 0 && moved) | |
85 | *p-- = '\0'; | |
86 | break; | |
87 | default: | |
88 | if (!isspace(*p)) { | |
89 | Signal("Input error.", (struct ship *)0); | |
90 | *p-- = '\0'; | |
5f9f07ce CL |
91 | } |
92 | } | |
b3a57661 EW |
93 | if (ta < 0 && moved || vma < 0 && moved |
94 | || af && turnfirst(buf) && moved) { | |
95 | Signal("Movement error.", (struct ship *)0); | |
96 | if (ta < 0 && moved) { | |
97 | if (mf->FS == 1) { | |
98 | Write(W_FS, ms, 0, 0, 0, 0, 0); | |
99 | Signal("No hands to set full sails.", | |
100 | (struct ship *)0); | |
101 | } | |
102 | } else if (ma >= 0) | |
5f9f07ce CL |
103 | buf[1] = '\0'; |
104 | } | |
b3a57661 EW |
105 | if (af && !moved) { |
106 | if (mf->FS == 1) { | |
107 | Write(W_FS, ms, 0, 0, 0, 0, 0); | |
108 | Signal("No hands to set full sails.", | |
109 | (struct ship *)0); | |
5f9f07ce CL |
110 | } |
111 | } | |
b3a57661 EW |
112 | if (*buf) |
113 | (void) strcpy(movebuf, buf); | |
114 | else | |
115 | (void) strcpy(movebuf, "d"); | |
116 | Write(W_LAST, ms, 1, (int)movebuf, 0, 0, 0); | |
117 | Signal("Helm: %s.", (struct ship *)0, movebuf); | |
5f9f07ce CL |
118 | } |
119 | ||
b3a57661 | 120 | doboarding() |
5f9f07ce | 121 | { |
b3a57661 | 122 | register struct ship *sp; |
7fc06086 BJ |
123 | register int n; |
124 | int crew[3]; | |
b3a57661 | 125 | int men = 0; |
789d5e82 | 126 | char c; |
b3a57661 EW |
127 | |
128 | crew[0] = mc->crew1; | |
129 | crew[1] = mc->crew2; | |
130 | crew[2] = mc->crew3; | |
6c17b19a | 131 | for (n = 0; n < NBP; n++) { |
b3a57661 EW |
132 | if (mf->OBP[n].turnsent) |
133 | men += mf->OBP[n].turnsent; | |
5f9f07ce | 134 | } |
6c17b19a | 135 | for (n = 0; n < NBP; n++) { |
b3a57661 EW |
136 | if (mf->DBP[n].turnsent) |
137 | men += mf->DBP[n].turnsent; | |
5f9f07ce | 138 | } |
b3a57661 | 139 | if (men) { |
5f9f07ce CL |
140 | crew[0] = men/100 ? 0 : crew[0] != 0; |
141 | crew[1] = (men%100)/10 ? 0 : crew[1] != 0; | |
142 | crew[2] = men%10 ? 0 : crew[2] != 0; | |
143 | } else { | |
144 | crew[0] = crew[0] != 0; | |
145 | crew[1] = crew[1] != 0; | |
146 | crew[2] = crew[2] != 0; | |
147 | } | |
b3a57661 | 148 | foreachship(sp) { |
6c17b19a | 149 | if (sp == ms || sp->file->dir == 0 || range(ms, sp) > 1) |
b3a57661 EW |
150 | continue; |
151 | if (ms->nationality == capship(sp)->nationality) | |
152 | continue; | |
153 | if (meleeing(ms, sp) && crew[2]) { | |
789d5e82 EW |
154 | c = sgetch("How many more to board the %s (%c%c)? ", |
155 | sp, 1); | |
156 | parties(crew, sp, 0, c); | |
6c17b19a | 157 | } else if ((fouled2(ms, sp) || grappled2(ms, sp)) && crew[2]) { |
789d5e82 EW |
158 | c = sgetch("Crew sections to board the %s (%c%c) (3 max) ?", sp, 1); |
159 | parties(crew, sp, 0, c); | |
5f9f07ce CL |
160 | } |
161 | } | |
b3a57661 | 162 | if (crew[2]) { |
789d5e82 EW |
163 | c = sgetch("How many sections to repel boarders? ", |
164 | (struct ship *)0, 1); | |
165 | parties(crew, ms, 1, c); | |
5f9f07ce CL |
166 | } |
167 | } | |
168 | ||
789d5e82 | 169 | parties(crew, to, isdefense, buf) |
b3a57661 EW |
170 | register struct ship *to; |
171 | int crew[3]; | |
172 | char isdefense; | |
789d5e82 | 173 | char buf; |
5f9f07ce CL |
174 | { |
175 | register int k, j, men; | |
b3a57661 | 176 | struct BP *ptr; |
5f9f07ce CL |
177 | int temp[3]; |
178 | ||
b3a57661 | 179 | for (k = 0; k < 3; k++) |
5f9f07ce | 180 | temp[k] = crew[k]; |
b3a57661 EW |
181 | if (isdigit(buf)) { |
182 | ptr = isdefense ? to->file->DBP : to->file->OBP; | |
183 | for (j = 0; j < NBP && ptr[j].turnsent; j++) | |
184 | ; | |
185 | if (!ptr[j].turnsent && buf > '0') { | |
5f9f07ce | 186 | men = 0; |
b3a57661 EW |
187 | for (k=0; k < 3 && buf > '0'; k++) { |
188 | men += crew[k] * power(10, 2-k); | |
5f9f07ce | 189 | crew[k] = 0; |
b3a57661 EW |
190 | if (men) |
191 | buf -= 1; | |
5f9f07ce CL |
192 | } |
193 | if (buf > '0') | |
b3a57661 EW |
194 | Signal("Sending all crew sections.", |
195 | (struct ship *)0); | |
196 | Write(isdefense ? W_DBP : W_OBP, ms, 0, | |
197 | j, turn, to-SHIP(0), men); | |
198 | if (isdefense) { | |
199 | (void) wmove(slot_w, 2, 0); | |
200 | for (k=0; k < NBP; k++) | |
201 | if (temp[k] && !crew[k]) | |
202 | (void) waddch(slot_w, k + '1'); | |
203 | else | |
204 | (void) wmove(slot_w, 2, 1 + k); | |
205 | (void) mvwaddstr(slot_w, 3, 0, "DBP"); | |
206 | makesignal(ms, "repelling boarders", | |
207 | (struct ship *)0); | |
208 | } else { | |
209 | (void) wmove(slot_w, 0, 0); | |
210 | for (k=0; k < NBP; k++) | |
211 | if (temp[k] && !crew[k]) | |
212 | (void) waddch(slot_w, k + '1'); | |
213 | else | |
214 | (void) wmove(slot_w, 0, 1 + k); | |
215 | (void) mvwaddstr(slot_w, 1, 0, "OBP"); | |
216 | makesignal(ms, "boarding the %s (%c%c)", to); | |
5f9f07ce | 217 | } |
b3a57661 EW |
218 | (void) wrefresh(slot_w); |
219 | } else | |
220 | Signal("Sending no crew sections.", (struct ship *)0); | |
5f9f07ce CL |
221 | } |
222 | } | |
223 | ||
224 | power(base, exp) | |
225 | int base, exp; | |
226 | { | |
b3a57661 | 227 | switch (exp) { |
5f9f07ce | 228 | case 0: |
b3a57661 | 229 | return 1; |
5f9f07ce | 230 | case 1: |
b3a57661 | 231 | return base; |
5f9f07ce | 232 | case 2: |
b3a57661 | 233 | return base * base; |
5f9f07ce | 234 | } |
b3a57661 | 235 | return 0; |
5f9f07ce CL |
236 | } |
237 | ||
238 | repair() | |
239 | { | |
789d5e82 | 240 | char c; |
1eda8103 | 241 | char *repairs; |
5f9f07ce CL |
242 | struct shipspecs *ptr; |
243 | ||
b3a57661 EW |
244 | if (repaired || loaded || fired || changed || turned()) { |
245 | Signal("No hands free to repair", (struct ship *)0); | |
246 | return; | |
247 | } | |
248 | ptr = mc; | |
789d5e82 EW |
249 | c = sgetch("Repair (hull, guns, rigging)? ", (struct ship *)0, 1); |
250 | switch (c) { | |
b3a57661 EW |
251 | case 'h': |
252 | repairs = &mf->RH; | |
253 | break; | |
254 | case 'g': | |
255 | repairs = &mf->RG; | |
256 | break; | |
257 | case 'r': | |
258 | repairs = &mf->RR; | |
259 | break; | |
260 | default: | |
261 | Signal("Avast heaving!", (struct ship *)0); | |
262 | return; | |
263 | } | |
264 | repaired = 1; | |
265 | if (++*repairs >= 3) { | |
266 | *repairs = 0; | |
789d5e82 | 267 | switch (c) { |
b3a57661 EW |
268 | case 'h': |
269 | if (ptr->hull < ptr->guns/4) | |
270 | Write(W_HULL, ms, 0, | |
271 | ptr->hull + 2, 0, 0, 0); | |
272 | else | |
789d5e82 | 273 | c = 0; |
b3a57661 EW |
274 | break; |
275 | case 'g': | |
276 | if (ptr->gunL < ptr->gunR) { | |
277 | if (ptr->gunL + ptr->carL < ptr->guns/5) | |
278 | Write(W_GUNL, ms, 0, | |
279 | ptr->gunL + 2, ptr->carL, 0, 0); | |
280 | else | |
789d5e82 | 281 | c = 0; |
b3a57661 EW |
282 | } else |
283 | if (ptr->gunR + ptr->carR < ptr->guns/5) | |
284 | Write(W_GUNR, ms, 0, | |
285 | ptr->gunR + 2, ptr->carR, 0, 0); | |
286 | else | |
789d5e82 | 287 | c = 0; |
b3a57661 EW |
288 | break; |
289 | case 'r': | |
290 | if (!ptr->rig4) | |
291 | Write(W_RIG4, ms, 0, | |
292 | ptr->rig4 + 2, 0, 0, 0); | |
293 | else if (!ptr->rig3) | |
294 | Write(W_RIG3, ms, 0, 2, 0, 0, 0); | |
295 | else if (!ptr->rig2) | |
296 | Write(W_RIG2, ms, 0, 2, 0, 0, 0); | |
297 | else if (ptr->rig1 < 4) | |
298 | Write(W_RIG1, ms, 0, 2, 0, 0, 0); | |
299 | else | |
789d5e82 | 300 | c = 0; |
b3a57661 | 301 | break; |
5f9f07ce | 302 | } |
789d5e82 | 303 | if (!c) |
b3a57661 | 304 | Signal("Repairs completed.", (struct ship *)0); |
5f9f07ce | 305 | } |
5f9f07ce CL |
306 | } |
307 | ||
308 | turned() | |
309 | { | |
b3a57661 | 310 | register char *p; |
5f9f07ce | 311 | |
b3a57661 EW |
312 | for (p = movebuf; *p; p++) |
313 | if (*p == 'r' || *p == 'l') | |
314 | return 1; | |
315 | return 0; | |
5f9f07ce CL |
316 | } |
317 | ||
318 | loadplayer() | |
319 | { | |
789d5e82 | 320 | char c; |
b3a57661 | 321 | register loadL, loadR, ready, load; |
5f9f07ce | 322 | |
b3a57661 EW |
323 | if (!mc->crew3) { |
324 | Signal("Out of crew", (struct ship *)0); | |
325 | return; | |
5f9f07ce | 326 | } |
b3a57661 EW |
327 | loadL = mf->loadL; |
328 | loadR = mf->loadR; | |
329 | if (!loadL && !loadR) { | |
789d5e82 EW |
330 | c = sgetch("Load which broadside (left or right)? ", |
331 | (struct ship *)0, 1); | |
332 | if (c == 'r') | |
5f9f07ce CL |
333 | loadL = 1; |
334 | else | |
335 | loadR = 1; | |
336 | } | |
b3a57661 | 337 | if (!loadL && loadR || loadL && !loadR) { |
789d5e82 EW |
338 | c = sgetch("Reload with (round, double, chain, grape)? ", |
339 | (struct ship *)0, 1); | |
340 | switch (c) { | |
b3a57661 EW |
341 | case 'r': |
342 | load = L_ROUND; | |
343 | ready = 0; | |
5f9f07ce | 344 | break; |
b3a57661 EW |
345 | case 'd': |
346 | load = L_DOUBLE; | |
347 | ready = R_DOUBLE; | |
5f9f07ce | 348 | break; |
b3a57661 EW |
349 | case 'c': |
350 | load = L_CHAIN; | |
351 | ready = 0; | |
5f9f07ce | 352 | break; |
b3a57661 EW |
353 | case 'g': |
354 | load = L_GRAPE; | |
355 | ready = 0; | |
5f9f07ce | 356 | break; |
b3a57661 EW |
357 | default: |
358 | Signal("Broadside not loaded.", | |
359 | (struct ship *)0); | |
360 | return; | |
361 | } | |
362 | if (!loadR) { | |
363 | mf->loadR = load; | |
364 | mf->readyR = ready|R_LOADING; | |
365 | } else { | |
366 | mf->loadL = load; | |
367 | mf->readyL = ready|R_LOADING; | |
368 | } | |
369 | loaded = 1; | |
5f9f07ce | 370 | } |
5f9f07ce | 371 | } |