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 * @(#)dr_1.c 8.1 (Berkeley) 5/31/93
30 * $FreeBSD: src/games/sail/dr_1.c,v 1.7 1999/11/30 03:49:32 billf Exp $
35 static int fightitout(struct ship
*, struct ship
*, int);
46 if (sp
->file
->captain
[0])
48 nat
= capship(sp
)->nationality
;
50 if (nat
!= capship(to
)->nationality
&&
51 !toughmelee(sp
, to
, 0, 0))
53 for (i
= fouled2(sp
, to
); --i
>= 0;)
67 if (*sp
->file
->captain
)
69 if (sp
->file
->dir
== 0)
71 if (sp
->file
->struck
|| sp
->file
->captured
!= 0)
75 crew
[0] = sp
->specs
->crew1
!= 0;
76 crew
[1] = sp
->specs
->crew2
!= 0;
77 crew
[2] = sp
->specs
->crew3
!= 0;
79 if (!Xsnagged2(sp
, sq
))
84 || sp
->nationality
== capship(sq
)->nationality
)
86 switch (sp
->specs
->class - sq
->specs
->class) {
87 case -3: case -4: case -5:
90 sendbp(sp
, sq
, crew
[0]*100, 0);
94 sendbp(sp
, sq
, crew
[1]*10, 0);
99 if (crew
[0] || crew
[1]) {
101 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
103 crew
[0] = crew
[1] = 0;
106 case -1: case 0: case 1:
109 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
111 crew
[0] = crew
[1] = 0;
114 case 2: case 3: case 4: case 5:
116 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10+crew
[2],
118 crew
[0] = crew
[1] = crew
[2] = 0;
126 fightitout(struct ship
*from
, struct ship
*to
, int key
)
128 struct ship
*fromcap
, *tocap
;
129 int crewfrom
[3], crewto
[3], menfrom
, mento
;
130 int pcto
, pcfrom
, fromstrength
, strengthto
, frominjured
, toinjured
;
132 int idx
, totalfrom
= 0, totalto
= 0;
136 menfrom
= mensent(from
, to
, crewfrom
, &fromcap
, &pcfrom
, key
);
137 mento
= mensent(to
, from
, crewto
, &tocap
, &pcto
, 0);
143 if (!menfrom
) { /* if crew surprised */
145 menfrom
= from
->specs
->crew1
147 + from
->specs
->crew3
;
149 menfrom
= from
->file
->pcrew
;
151 menfrom
*= 2; /* DBP's fight at an advantage */
154 fromstrength
= menfrom
* fromcap
->specs
->qual
;
155 strengthto
= mento
* tocap
->specs
->qual
;
157 ((fromstrength
< strengthto
* 3 && strengthto
< fromstrength
* 3)
158 || fromstrength
== -1) && count
< 4;
160 idx
= fromstrength
/10;
163 toinjured
= MT
[idx
][2 - die() / 3];
164 totalto
+= toinjured
;
168 frominjured
= MT
[idx
][2 - die() / 3];
169 totalfrom
+= frominjured
;
170 menfrom
-= frominjured
;
172 fromstrength
= menfrom
* fromcap
->specs
->qual
;
173 strengthto
= mento
* tocap
->specs
->qual
;
175 if (fromstrength
>= strengthto
* 3 || count
== 4) {
176 unboard(to
, from
, 0);
177 subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
178 subtract(to
, totalto
, crewto
, tocap
, pcto
);
179 makesignal(from
, "boarders from %s repelled", to
);
180 sprintf(message
, "killed in melee: %d. %s: %d",
181 totalto
, from
->shipname
, totalfrom
);
182 Writestr(W_SIGNAL
, to
, message
);
185 } else if (strengthto
>= fromstrength
* 3) {
186 unboard(from
, to
, 0);
187 subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
188 subtract(to
, totalto
, crewto
, tocap
, pcto
);
191 Write(W_POINTS
, fromcap
,
192 fromcap
->file
->points
-
195 : 2 * from
->specs
->pts
,
198 /* ptr1 points to the shipspec for the ship that was just unboarded.
199 I guess that what is going on here is that the pointer is multiplied
202 Write(W_CAPTURED
, from
, to
->file
->index
, 0, 0, 0);
203 topoints
= 2 * from
->specs
->pts
+ to
->file
->points
;
204 if (from
->file
->struck
)
205 topoints
-= from
->specs
->pts
;
206 Write(W_POINTS
, to
, topoints
, 0, 0, 0);
207 mento
= crewto
[0] ? crewto
[0] : crewto
[1];
209 subtract(to
, mento
, crewto
, tocap
, pcto
);
210 subtract(from
, - mento
, crewfrom
, to
, 0);
212 sprintf(message
, "captured by the %s!",
214 Writestr(W_SIGNAL
, from
, message
);
215 sprintf(message
, "killed in melee: %d. %s: %d",
216 totalto
, from
->shipname
, totalfrom
);
217 Writestr(W_SIGNAL
, to
, message
);
229 struct ship
*sp
, *sq
;
232 if (sp
->file
->dir
== 0)
234 for (sq
= sp
+ 1; sq
< ls
; sq
++)
235 if (sq
->file
->dir
&& meleeing(sp
, sq
) &&
237 fightitout(sp
, sq
, 0);
240 if (sq
->file
->dir
&& meleeing(sq
, sp
))
241 thwart
= fightitout(sp
, sq
, 1);
247 if (sq
->file
->dir
&& meleeing(sq
, sp
))
252 } else if (thwart
== 2)
262 struct ship
*closest
;
263 int crew
[3], men
= 0, target
, temp
;
264 int r
, guns
, ready
, load
, car
;
265 int idx
, rakehim
, sternrake
;
269 if (sp
->file
->captain
[0] || sp
->file
->dir
== 0)
271 crew
[0] = sp
->specs
->crew1
;
272 crew
[1] = sp
->specs
->crew2
;
273 crew
[2] = sp
->specs
->crew3
;
274 for (n
= 0; n
< 3; n
++) {
275 if (sp
->file
->OBP
[n
].turnsent
)
276 men
+= sp
->file
->OBP
[n
].mensent
;
278 for (n
= 0; n
< 3; n
++) {
279 if (sp
->file
->DBP
[n
].turnsent
)
280 men
+= sp
->file
->DBP
[n
].mensent
;
283 crew
[0] = men
/100 ? 0 : crew
[0] != 0;
284 crew
[1] = (men
%100)/10 ? 0 : crew
[1] != 0;
285 crew
[2] = men
%10 ? 0 : crew
[2] != 0;
287 for (r
= 0; r
< 2; r
++) {
290 if (sp
->file
->struck
)
293 ready
= sp
->file
->readyR
;
294 guns
= sp
->specs
->gunR
;
295 car
= sp
->specs
->carR
;
297 ready
= sp
->file
->readyL
;
298 guns
= sp
->specs
->gunL
;
299 car
= sp
->specs
->carL
;
303 if ((ready
& R_LOADED
) == 0)
305 closest
= closestenemy(sp
, r
? 'r' : 'l', 0);
308 if (range(closest
, sp
) >
309 range(sp
, closestenemy(sp
, r
? 'r' : 'l', 1)))
311 if (closest
->file
->struck
)
313 target
= range(sp
, closest
);
316 if (!guns
&& target
>= 3)
319 if (target
== 1 && sp
->file
->loadwith
== L_GRAPE
)
321 if (target
<= 3 && closest
->file
->FS
)
323 if (target
== 1 && load
!= L_GRAPE
)
325 if (load
> L_CHAIN
&& target
< 6)
329 rakehim
= gunsbear(sp
, closest
)
330 && !gunsbear(closest
, sp
);
331 temp
= portside(closest
, sp
, 1)
332 - closest
->file
->dir
+ 1;
337 sternrake
= temp
> 4 && temp
< 6;
342 idx
= idx
> 8 ? 8 : idx
;
344 hit
= HDT
[idx
][target
-1];
346 hit
= HDTrake
[idx
][target
-1];
347 if (rakehim
&& sternrake
)
349 hit
+= QUAL
[idx
][capship(sp
)->specs
->qual
- 1];
350 for (n
= 0; n
< 3 && sp
->file
->captured
== 0; n
++) {
358 if (ready
& R_INITIAL
) {
360 sp
->file
->readyL
&= ~R_INITIAL
;
362 sp
->file
->readyR
&= ~R_INITIAL
;
368 if (sp
->file
->captured
!= 0) {
374 hit
+= AMMO
[idx
][load
- 1];
375 temp
= sp
->specs
->class;
376 if ((temp
>= 5 || temp
== 1) && windspeed
== 5)
378 if (windspeed
== 6 && temp
== 4)
380 if (windspeed
== 6 && temp
<= 3)
384 hit
= hit
> 10 ? 10 : hit
;
385 table(shootat
, load
, hit
, closest
, sp
, die());
394 if (++turn
% 55 == 0) {
400 if (people
<= 0 || windspeed
== 7) {
402 struct ship
*bestship
= NULL
;
403 float net
, best
= 0.0;
405 if (*s
->file
->captain
)
407 net
= (float)s
->file
->points
/ s
->specs
->pts
;
414 char *p
= getenv("WOTD");
416 char buf
[6] = "Driver";
421 strncpy(bestship
->file
->captain
, p
,
422 sizeof bestship
->file
->captain
);
423 bestship
->file
->captain
424 [sizeof bestship
->file
->captain
- 1] = 0;
429 Write(W_TURN
, SHIP(0), turn
, 0, 0, 0);
430 if (turn
% 7 == 0 && (die() >= cc
->windchange
|| !windspeed
)) {
467 Write(W_WIND
, SHIP(0), winddir
, windspeed
, 0, 0);