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 $
31 * $DragonFly: src/games/sail/dr_1.c,v 1.4 2006/09/03 17:33:13 pavalos Exp $
36 static int fightitout(struct ship
*, struct ship
*, int);
47 if (sp
->file
->captain
[0])
49 nat
= capship(sp
)->nationality
;
51 if (nat
!= capship(to
)->nationality
&&
52 !toughmelee(sp
, to
, 0, 0))
54 for (i
= fouled2(sp
, to
); --i
>= 0;)
68 if (*sp
->file
->captain
)
70 if (sp
->file
->dir
== 0)
72 if (sp
->file
->struck
|| sp
->file
->captured
!= 0)
76 crew
[0] = sp
->specs
->crew1
!= 0;
77 crew
[1] = sp
->specs
->crew2
!= 0;
78 crew
[2] = sp
->specs
->crew3
!= 0;
80 if (!Xsnagged2(sp
, sq
))
85 || sp
->nationality
== capship(sq
)->nationality
)
87 switch (sp
->specs
->class - sq
->specs
->class) {
88 case -3: case -4: case -5:
91 sendbp(sp
, sq
, crew
[0]*100, 0);
95 sendbp(sp
, sq
, crew
[1]*10, 0);
100 if (crew
[0] || crew
[1]) {
102 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
104 crew
[0] = crew
[1] = 0;
107 case -1: case 0: case 1:
110 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
112 crew
[0] = crew
[1] = 0;
115 case 2: case 3: case 4: case 5:
117 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10+crew
[2],
119 crew
[0] = crew
[1] = crew
[2] = 0;
127 fightitout(struct ship
*from
, struct ship
*to
, int key
)
129 struct ship
*fromcap
, *tocap
;
130 int crewfrom
[3], crewto
[3], menfrom
, mento
;
131 int pcto
, pcfrom
, fromstrength
, strengthto
, frominjured
, toinjured
;
133 int idx
, totalfrom
= 0, totalto
= 0;
137 menfrom
= mensent(from
, to
, crewfrom
, &fromcap
, &pcfrom
, key
);
138 mento
= mensent(to
, from
, crewto
, &tocap
, &pcto
, 0);
144 if (!menfrom
) { /* if crew surprised */
146 menfrom
= from
->specs
->crew1
148 + from
->specs
->crew3
;
150 menfrom
= from
->file
->pcrew
;
152 menfrom
*= 2; /* DBP's fight at an advantage */
155 fromstrength
= menfrom
* fromcap
->specs
->qual
;
156 strengthto
= mento
* tocap
->specs
->qual
;
158 ((fromstrength
< strengthto
* 3 && strengthto
< fromstrength
* 3)
159 || fromstrength
== -1) && count
< 4;
161 idx
= fromstrength
/10;
164 toinjured
= MT
[idx
][2 - die() / 3];
165 totalto
+= toinjured
;
169 frominjured
= MT
[idx
][2 - die() / 3];
170 totalfrom
+= frominjured
;
171 menfrom
-= frominjured
;
173 fromstrength
= menfrom
* fromcap
->specs
->qual
;
174 strengthto
= mento
* tocap
->specs
->qual
;
176 if (fromstrength
>= strengthto
* 3 || count
== 4) {
177 unboard(to
, from
, 0);
178 subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
179 subtract(to
, totalto
, crewto
, tocap
, pcto
);
180 makesignal(from
, "boarders from %s repelled", to
);
181 sprintf(message
, "killed in melee: %d. %s: %d",
182 totalto
, from
->shipname
, totalfrom
);
183 Writestr(W_SIGNAL
, to
, message
);
186 } else if (strengthto
>= fromstrength
* 3) {
187 unboard(from
, to
, 0);
188 subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
189 subtract(to
, totalto
, crewto
, tocap
, pcto
);
192 Write(W_POINTS
, fromcap
,
193 fromcap
->file
->points
-
196 : 2 * from
->specs
->pts
,
199 /* ptr1 points to the shipspec for the ship that was just unboarded.
200 I guess that what is going on here is that the pointer is multiplied
203 Write(W_CAPTURED
, from
, to
->file
->index
, 0, 0, 0);
204 topoints
= 2 * from
->specs
->pts
+ to
->file
->points
;
205 if (from
->file
->struck
)
206 topoints
-= from
->specs
->pts
;
207 Write(W_POINTS
, to
, topoints
, 0, 0, 0);
208 mento
= crewto
[0] ? crewto
[0] : crewto
[1];
210 subtract(to
, mento
, crewto
, tocap
, pcto
);
211 subtract(from
, - mento
, crewfrom
, to
, 0);
213 sprintf(message
, "captured by the %s!",
215 Writestr(W_SIGNAL
, from
, message
);
216 sprintf(message
, "killed in melee: %d. %s: %d",
217 totalto
, from
->shipname
, totalfrom
);
218 Writestr(W_SIGNAL
, to
, message
);
230 struct ship
*sp
, *sq
;
233 if (sp
->file
->dir
== 0)
235 for (sq
= sp
+ 1; sq
< ls
; sq
++)
236 if (sq
->file
->dir
&& meleeing(sp
, sq
) &&
238 fightitout(sp
, sq
, 0);
241 if (sq
->file
->dir
&& meleeing(sq
, sp
))
242 thwart
= fightitout(sp
, sq
, 1);
248 if (sq
->file
->dir
&& meleeing(sq
, sp
))
253 } else if (thwart
== 2)
263 struct ship
*closest
;
264 int crew
[3], men
= 0, target
, temp
;
265 int r
, guns
, ready
, load
, car
;
266 int idx
, rakehim
, sternrake
;
270 if (sp
->file
->captain
[0] || sp
->file
->dir
== 0)
272 crew
[0] = sp
->specs
->crew1
;
273 crew
[1] = sp
->specs
->crew2
;
274 crew
[2] = sp
->specs
->crew3
;
275 for (n
= 0; n
< 3; n
++) {
276 if (sp
->file
->OBP
[n
].turnsent
)
277 men
+= sp
->file
->OBP
[n
].mensent
;
279 for (n
= 0; n
< 3; n
++) {
280 if (sp
->file
->DBP
[n
].turnsent
)
281 men
+= sp
->file
->DBP
[n
].mensent
;
284 crew
[0] = men
/100 ? 0 : crew
[0] != 0;
285 crew
[1] = (men
%100)/10 ? 0 : crew
[1] != 0;
286 crew
[2] = men
%10 ? 0 : crew
[2] != 0;
288 for (r
= 0; r
< 2; r
++) {
291 if (sp
->file
->struck
)
294 ready
= sp
->file
->readyR
;
295 guns
= sp
->specs
->gunR
;
296 car
= sp
->specs
->carR
;
298 ready
= sp
->file
->readyL
;
299 guns
= sp
->specs
->gunL
;
300 car
= sp
->specs
->carL
;
304 if ((ready
& R_LOADED
) == 0)
306 closest
= closestenemy(sp
, r
? 'r' : 'l', 0);
309 if (range(closest
, sp
) >
310 range(sp
, closestenemy(sp
, r
? 'r' : 'l', 1)))
312 if (closest
->file
->struck
)
314 target
= range(sp
, closest
);
317 if (!guns
&& target
>= 3)
320 if (target
== 1 && sp
->file
->loadwith
== L_GRAPE
)
322 if (target
<= 3 && closest
->file
->FS
)
324 if (target
== 1 && load
!= L_GRAPE
)
326 if (load
> L_CHAIN
&& target
< 6)
330 rakehim
= gunsbear(sp
, closest
)
331 && !gunsbear(closest
, sp
);
332 temp
= portside(closest
, sp
, 1)
333 - closest
->file
->dir
+ 1;
338 sternrake
= temp
> 4 && temp
< 6;
343 idx
= idx
> 8 ? 8 : idx
;
345 hit
= HDT
[idx
][target
-1];
347 hit
= HDTrake
[idx
][target
-1];
348 if (rakehim
&& sternrake
)
350 hit
+= QUAL
[idx
][capship(sp
)->specs
->qual
- 1];
351 for (n
= 0; n
< 3 && sp
->file
->captured
== 0; n
++) {
359 if (ready
& R_INITIAL
) {
361 sp
->file
->readyL
&= ~R_INITIAL
;
363 sp
->file
->readyR
&= ~R_INITIAL
;
369 if (sp
->file
->captured
!= 0) {
375 hit
+= AMMO
[idx
][load
- 1];
376 temp
= sp
->specs
->class;
377 if ((temp
>= 5 || temp
== 1) && windspeed
== 5)
379 if (windspeed
== 6 && temp
== 4)
381 if (windspeed
== 6 && temp
<= 3)
385 hit
= hit
> 10 ? 10 : hit
;
386 table(shootat
, load
, hit
, closest
, sp
, die());
395 if (++turn
% 55 == 0) {
401 if (people
<= 0 || windspeed
== 7) {
403 struct ship
*bestship
= NULL
;
404 float net
, best
= 0.0;
406 if (*s
->file
->captain
)
408 net
= (float)s
->file
->points
/ s
->specs
->pts
;
415 char *p
= getenv("WOTD");
417 char buf
[6] = "Driver";
422 strncpy(bestship
->file
->captain
, p
,
423 sizeof bestship
->file
->captain
);
424 bestship
->file
->captain
425 [sizeof bestship
->file
->captain
- 1] = 0;
430 Write(W_TURN
, SHIP(0), turn
, 0, 0, 0);
431 if (turn
% 7 == 0 && (die() >= cc
->windchange
|| !windspeed
)) {
468 Write(W_WIND
, SHIP(0), winddir
, windspeed
, 0, 0);