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. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)pl_3.c 8.1 (Berkeley) 5/31/93
30 * $FreeBSD: src/games/sail/pl_3.c,v 1.6 1999/11/30 03:49:37 billf Exp $
41 int idx
, rakehim
, sternrake
;
42 int hhits
= 0, ghits
= 0, rhits
= 0, chits
= 0;
45 int guns
, car
, ready
, shootat
, hit
;
52 for (n
= 0; n
< 3; n
++) {
53 if (mf
->OBP
[n
].turnsent
)
54 men
+= mf
->OBP
[n
].mensent
;
56 for (n
= 0; n
< 3; n
++) {
57 if (mf
->DBP
[n
].turnsent
)
58 men
+= mf
->DBP
[n
].mensent
;
61 crew
[0] = men
/100 ? 0 : crew
[0] != 0;
62 crew
[1] = (men
%100)/10 ? 0 : crew
[1] != 0;
63 crew
[2] = men
%10 ? 0 : crew
[2] != 0;
65 for (r
= 0; r
< 2; r
++) {
77 if ((!guns
&& !car
) || load
== L_EMPTY
||
78 (ready
& R_LOADED
) == 0)
80 if (mf
->struck
|| !crew
[2])
82 closest
= closestenemy(ms
, (r
? 'r' : 'l'), 1);
85 if (closest
->file
->struck
)
87 target
= range(ms
, closest
);
88 if (target
> rangeofshot
[load
] || (!guns
&& target
>= 3))
90 Signal("%s (%c%c) within range of %s broadside.",
91 closest
, r
? "right" : "left");
92 if (load
> L_CHAIN
&& target
< 6) {
93 switch (sgetch("Aim for hull or rigging? ",
103 Signal("'Avast there! Hold your fire.'",
107 if (sgetch("Fire? ", NULL
, 1) == 'n') {
109 Signal("Belay that! Hold your fire.",
117 rakehim
= gunsbear(ms
, closest
) && !gunsbear(closest
, ms
);
118 temp
= portside(closest
, ms
, 1) - closest
->file
->dir
+ 1;
123 sternrake
= temp
> 4 && temp
< 6;
126 Signal("Raking the %s!", closest
);
128 Signal("Stern Rake! %s splintering!", closest
);
134 idx
= idx
> 8 ? 8 : idx
;
136 hit
= HDT
[idx
][target
-1];
138 hit
= HDTrake
[idx
][target
-1];
139 if (rakehim
&& sternrake
)
141 hit
+= QUAL
[idx
][mc
->qual
-1];
142 for (n
= 0; n
< 3 && mf
->captured
== 0; n
++)
149 if (ready
& R_INITIAL
) {
155 if (mf
->captured
!= 0) {
161 hit
+= AMMO
[idx
][load
- 1];
162 if (((temp
= mc
->class) >= 5 || temp
== 1) && windspeed
== 5)
164 if (windspeed
== 6 && temp
== 4)
166 if (windspeed
== 6 && temp
<= 3)
176 t
= &(shootat
== RIGGING
? RigTable
: HullTable
)
182 if (closest
->file
->FS
)
184 if (load
== L_CHAIN
) {
189 table(shootat
, load
, hit
, closest
, ms
, roll
);
191 Signal("Damage inflicted on the %s:",
192 NULL
, closest
->shipname
);
193 Signal("\t%d HULL, %d GUNS, %d CREW, %d RIGGING",
194 NULL
, hhits
, ghits
, chits
, rhits
);
197 mf
->readyL
= R_EMPTY
;
200 mf
->readyR
= R_EMPTY
;
204 Signal("Unable to fire %s broadside",
205 NULL
, r
? "right" : "left");
219 if (sp
== ms
|| sp
->file
->dir
== 0)
221 if (range(ms
, sp
) > 1 && !grappled2(ms
, sp
))
223 switch (sgetch("Attempt to grapple or ungrapple %s (%c%c): ",
227 || ms
->nationality
== capship(sp
)->nationality
) {
228 Write(W_GRAP
, ms
, sp
->file
->index
, 0, 0, 0);
229 Write(W_GRAP
, sp
, player
, 0, 0, 0);
230 Signal("Attempt succeeds!", NULL
);
231 makesignal(ms
, "grappled with %s (%c%c)", sp
);
233 Signal("Attempt fails.", NULL
);
236 for (i
= grappled2(ms
, sp
); --i
>= 0;) {
238 == capship(sp
)->nationality
240 cleangrapple(ms
, sp
, 0);
241 Signal("Attempt succeeds!",
244 "ungrappling with %s (%c%c)",
247 Signal("Attempt fails.",
262 if (fouled2(ms
, to
) == 0)
264 if (sgetch("Attempt to unfoul with the %s (%c%c)? ", to
, 1) != 'y')
266 for (i
= fouled2(ms
, to
); --i
>= 0;) {
268 cleanfoul(ms
, to
, 0);
269 Signal("Attempt succeeds!", NULL
);
270 makesignal(ms
, "Unfouling %s (%c%c)", to
);
272 Signal("Attempt fails.", NULL
);