1 /* $NetBSD: pl_5.c,v 1.24 2009/03/15 00:35:42 dholland Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)pl_5.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: pl_5.c,v 1.24 2009/03/15 00:35:42 dholland Exp $");
49 #define turnfirst(x) (*x == 'r' || *x == 'l')
51 static void parties(struct ship
*, int *, int, int);
62 char buf
[60], last
= '\0';
65 if (!mc
->crew3
|| snagged(ms
) || !windspeed
) {
66 Msg("Unable to move");
70 ta
= maxturns(ms
, &af
);
71 ma
= maxmove(ms
, mf
->dir
, 0);
72 snprintf(promptstr
, sizeof(promptstr
),
73 "move (%d,%c%d): ", ma
, af
? '\'' : ' ', ta
);
74 sgetstr(promptstr
, buf
, sizeof buf
);
77 for (p
= buf
; *p
; p
++)
87 Msg("Ship can't turn that fast.");
93 vma
= min(ma
, maxmove(ms
, dir
, 0));
94 if ((ta
< 0 && moved
) || (vma
< 0 && moved
))
101 if ((ta
< 0 && moved
) || (vma
< 0 && moved
))
111 case '1': case '2': case '3': case '4':
112 case '5': case '6': case '7':
114 Msg("Can't move that fast.");
121 if ((ta
< 0 && moved
) || (vma
< 0 && moved
))
125 if (!isspace((unsigned char)*p
)) {
130 if ((ta
< 0 && moved
) || (vma
< 0 && moved
)
131 || (af
&& turnfirst(buf
) && moved
)) {
132 Msg("Movement error.");
133 if (ta
< 0 && moved
) {
136 Msg("No hands to set full sails.");
144 Msg("No hands to set full sails.");
148 strlcpy(movebuf
, buf
, sizeof(movebuf
));
150 strlcpy(movebuf
, "d", sizeof(movebuf
));
151 send_move(ms
, movebuf
);
152 Msg("Helm: %s.", movebuf
);
167 for (n
= 0; n
< NBP
; n
++) {
168 if (mf
->OBP
[n
].turnsent
)
169 men
+= mf
->OBP
[n
].mensent
;
171 for (n
= 0; n
< NBP
; n
++) {
172 if (mf
->DBP
[n
].turnsent
)
173 men
+= mf
->DBP
[n
].mensent
;
176 crew
[0] = men
/100 ? 0 : crew
[0] != 0;
177 crew
[1] = (men
%100)/10 ? 0 : crew
[1] != 0;
178 crew
[2] = men
%10 ? 0 : crew
[2] != 0;
180 crew
[0] = crew
[0] != 0;
181 crew
[1] = crew
[1] != 0;
182 crew
[2] = crew
[2] != 0;
185 if (sp
== ms
|| sp
->file
->dir
== 0 || range(ms
, sp
) > 1)
187 if (ms
->nationality
== capship(sp
)->nationality
)
189 if (meleeing(ms
, sp
) && crew
[2]) {
190 c
= sgetch("How many more to board the $$? ",
192 parties(sp
, crew
, 0, c
);
193 } else if ((fouled2(ms
, sp
) || grappled2(ms
, sp
)) && crew
[2]) {
194 c
= sgetch("Crew sections to board the $$ (3 max) ?",
196 parties(sp
, crew
, 0, c
);
200 c
= sgetch("How many sections to repel boarders? ",
201 (struct ship
*)0, 1);
202 parties(ms
, crew
, 1, c
);
207 parties(struct ship
*to
, int *crew
, int isdefense
, int buf
)
213 for (k
= 0; k
< 3; k
++)
216 ptr
= isdefense
? to
->file
->DBP
: to
->file
->OBP
;
217 for (j
= 0; j
< NBP
&& ptr
[j
].turnsent
; j
++)
219 if (j
< NBP
&& !ptr
[j
].turnsent
&& buf
> '0') {
221 for (k
= 0; k
< 3 && buf
> '0'; k
++) {
223 * (k
== 0 ? 100 : (k
== 1 ? 10 : 1));
229 Msg("Sending all crew sections.");
231 send_dbp(ms
, j
, turn
, to
->file
->index
, men
);
233 send_obp(ms
, j
, turn
, to
->file
->index
, men
);
236 for (k
=0; k
< NBP
; k
++)
238 temp
[k
] && !crew
[k
]);
239 makemsg(ms
, "repelling boarders");
241 for (k
=0; k
< NBP
; k
++)
243 temp
[k
] && !crew
[k
]);
244 makesignal(ms
, "boarding the $$", to
);
247 Msg("Sending no crew sections.");