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 $
31 * $DragonFly: src/games/sail/pl_3.c,v 1.3 2006/09/03 17:33:13 pavalos Exp $
42 int idx
, rakehim
, sternrake
;
43 int hhits
= 0, ghits
= 0, rhits
= 0, chits
= 0;
46 int guns
, car
, ready
, shootat
, hit
;
53 for (n
= 0; n
< 3; n
++) {
54 if (mf
->OBP
[n
].turnsent
)
55 men
+= mf
->OBP
[n
].mensent
;
57 for (n
= 0; n
< 3; n
++) {
58 if (mf
->DBP
[n
].turnsent
)
59 men
+= mf
->DBP
[n
].mensent
;
62 crew
[0] = men
/100 ? 0 : crew
[0] != 0;
63 crew
[1] = (men
%100)/10 ? 0 : crew
[1] != 0;
64 crew
[2] = men
%10 ? 0 : crew
[2] != 0;
66 for (r
= 0; r
< 2; r
++) {
78 if ((!guns
&& !car
) || load
== L_EMPTY
||
79 (ready
& R_LOADED
) == 0)
81 if (mf
->struck
|| !crew
[2])
83 closest
= closestenemy(ms
, (r
? 'r' : 'l'), 1);
86 if (closest
->file
->struck
)
88 target
= range(ms
, closest
);
89 if (target
> rangeofshot
[load
] || (!guns
&& target
>= 3))
91 Signal("%s (%c%c) within range of %s broadside.",
92 closest
, r
? "right" : "left");
93 if (load
> L_CHAIN
&& target
< 6) {
94 switch (sgetch("Aim for hull or rigging? ",
104 Signal("'Avast there! Hold your fire.'",
108 if (sgetch("Fire? ", NULL
, 1) == 'n') {
110 Signal("Belay that! Hold your fire.",
118 rakehim
= gunsbear(ms
, closest
) && !gunsbear(closest
, ms
);
119 temp
= portside(closest
, ms
, 1) - closest
->file
->dir
+ 1;
124 sternrake
= temp
> 4 && temp
< 6;
127 Signal("Raking the %s!", closest
);
129 Signal("Stern Rake! %s splintering!", closest
);
135 idx
= idx
> 8 ? 8 : idx
;
137 hit
= HDT
[idx
][target
-1];
139 hit
= HDTrake
[idx
][target
-1];
140 if (rakehim
&& sternrake
)
142 hit
+= QUAL
[idx
][mc
->qual
-1];
143 for (n
= 0; n
< 3 && mf
->captured
== 0; n
++)
150 if (ready
& R_INITIAL
) {
156 if (mf
->captured
!= 0) {
162 hit
+= AMMO
[idx
][load
- 1];
163 if (((temp
= mc
->class) >= 5 || temp
== 1) && windspeed
== 5)
165 if (windspeed
== 6 && temp
== 4)
167 if (windspeed
== 6 && temp
<= 3)
177 t
= &(shootat
== RIGGING
? RigTable
: HullTable
)
183 if (closest
->file
->FS
)
185 if (load
== L_CHAIN
) {
190 table(shootat
, load
, hit
, closest
, ms
, roll
);
192 Signal("Damage inflicted on the %s:",
193 NULL
, closest
->shipname
);
194 Signal("\t%d HULL, %d GUNS, %d CREW, %d RIGGING",
195 NULL
, hhits
, ghits
, chits
, rhits
);
198 mf
->readyL
= R_EMPTY
;
201 mf
->readyR
= R_EMPTY
;
205 Signal("Unable to fire %s broadside",
206 NULL
, r
? "right" : "left");
220 if (sp
== ms
|| sp
->file
->dir
== 0)
222 if (range(ms
, sp
) > 1 && !grappled2(ms
, sp
))
224 switch (sgetch("Attempt to grapple or ungrapple %s (%c%c): ",
228 || ms
->nationality
== capship(sp
)->nationality
) {
229 Write(W_GRAP
, ms
, sp
->file
->index
, 0, 0, 0);
230 Write(W_GRAP
, sp
, player
, 0, 0, 0);
231 Signal("Attempt succeeds!", NULL
);
232 makesignal(ms
, "grappled with %s (%c%c)", sp
);
234 Signal("Attempt fails.", NULL
);
237 for (i
= grappled2(ms
, sp
); --i
>= 0;) {
239 == capship(sp
)->nationality
241 cleangrapple(ms
, sp
, 0);
242 Signal("Attempt succeeds!",
245 "ungrappling with %s (%c%c)",
248 Signal("Attempt fails.",
263 if (fouled2(ms
, to
) == 0)
265 if (sgetch("Attempt to unfoul with the %s (%c%c)? ", to
, 1) != 'y')
267 for (i
= fouled2(ms
, to
); --i
>= 0;) {
269 cleanfoul(ms
, to
, 0);
270 Signal("Attempt succeeds!", NULL
);
271 makesignal(ms
, "Unfouling %s (%c%c)", to
);
273 Signal("Attempt fails.", NULL
);