2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)pl_5.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/sail/pl_5.c,v 1.6 1999/11/30 03:49:37 billf Exp $
35 * $DragonFly: src/games/sail/pl_5.c,v 1.3 2006/09/03 17:33:13 pavalos Exp $
41 #define turnfirst(x) (*x == 'r' || *x == 'l')
43 static void parties(int [3], struct ship
*, char, char);
54 char buf
[60], last
= '\0';
57 if (!mc
->crew3
|| snagged(ms
) || !windspeed
) {
58 Signal("Unable to move", NULL
);
62 ta
= maxturns(ms
, &af
);
63 ma
= maxmove(ms
, mf
->dir
, 0);
64 sprintf(prompt
, "move (%d,%c%d): ", ma
, af
? '\'' : ' ', ta
);
65 sgetstr(prompt
, buf
, sizeof buf
);
68 for (p
= buf
; *p
; p
++)
78 Signal("Ship can't turn that fast.",
85 vma
= min(ma
, maxmove(ms
, dir
, 0));
86 if ((ta
< 0 && moved
) || (vma
< 0 && moved
))
93 if ((ta
< 0 && moved
) || (vma
< 0 && moved
))
103 case '1': case '2': case '3': case '4':
104 case '5': case '6': case '7':
106 Signal("Can't move that fast.",
114 if ((ta
< 0 && moved
) || (vma
< 0 && moved
))
119 Signal("Input error.", NULL
);
123 if ((ta
< 0 && moved
) || (vma
< 0 && moved
)
124 || (af
&& turnfirst(buf
) && moved
)) {
125 Signal("Movement error.", NULL
);
126 if (ta
< 0 && moved
) {
128 Write(W_FS
, ms
, 0, 0, 0, 0);
129 Signal("No hands to set full sails.",
137 Write(W_FS
, ms
, 0, 0, 0, 0);
138 Signal("No hands to set full sails.",
143 strcpy(movebuf
, buf
);
145 strcpy(movebuf
, "d");
146 Writestr(W_MOVE
, ms
, movebuf
);
147 Signal("Helm: %s.", NULL
, movebuf
);
162 for (n
= 0; n
< NBP
; n
++) {
163 if (mf
->OBP
[n
].turnsent
)
164 men
+= mf
->OBP
[n
].mensent
;
166 for (n
= 0; n
< NBP
; n
++) {
167 if (mf
->DBP
[n
].turnsent
)
168 men
+= mf
->DBP
[n
].mensent
;
171 crew
[0] = men
/100 ? 0 : crew
[0] != 0;
172 crew
[1] = (men
%100)/10 ? 0 : crew
[1] != 0;
173 crew
[2] = men
%10 ? 0 : crew
[2] != 0;
175 crew
[0] = crew
[0] != 0;
176 crew
[1] = crew
[1] != 0;
177 crew
[2] = crew
[2] != 0;
180 if (sp
== ms
|| sp
->file
->dir
== 0 || range(ms
, sp
) > 1)
182 if (ms
->nationality
== capship(sp
)->nationality
)
184 if (meleeing(ms
, sp
) && crew
[2]) {
185 c
= sgetch("How many more to board the %s (%c%c)? ",
187 parties(crew
, sp
, 0, c
);
188 } else if ((fouled2(ms
, sp
) || grappled2(ms
, sp
)) && crew
[2]) {
189 c
= sgetch("Crew sections to board the %s (%c%c) (3 max) ?", sp
, 1);
190 parties(crew
, sp
, 0, c
);
194 c
= sgetch("How many sections to repel boarders? ",
196 parties(crew
, ms
, 1, c
);
204 parties(int crew
[3], struct ship
*to
, char isdefense
, char buf
)
210 for (k
= 0; k
< 3; k
++)
213 ptr
= isdefense
? to
->file
->DBP
: to
->file
->OBP
;
214 for (j
= 0; j
< NBP
&& ptr
[j
].turnsent
; j
++)
216 if (!ptr
[j
].turnsent
&& buf
> '0') {
218 for (k
= 0; k
< 3 && buf
> '0'; k
++) {
220 * (k
== 0 ? 100 : (k
== 1 ? 10 : 1));
226 Signal("Sending all crew sections.",
228 Write(isdefense
? W_DBP
: W_OBP
, ms
,
229 j
, turn
, to
->file
->index
, men
);
232 for (k
=0; k
< NBP
; k
++)
233 if (temp
[k
] && !crew
[k
])
234 waddch(slot_w
, k
+ '1');
236 wmove(slot_w
, 2, 1 + k
);
237 mvwaddstr(slot_w
, 3, 0, "DBP");
238 makesignal(ms
, "repelling boarders",
242 for (k
=0; k
< NBP
; k
++)
243 if (temp
[k
] && !crew
[k
])
244 waddch(slot_w
, k
+ '1');
246 wmove(slot_w
, 0, 1 + k
);
247 mvwaddstr(slot_w
, 1, 0, "OBP");
248 makesignal(ms
, "boarding the %s (%c%c)", to
);
254 Signal("Sending no crew sections.", NULL
);