]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/dr_1.c
1 /* $NetBSD: dr_1.c,v 1.18 2001/02/05 01:10:08 christos Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
39 static char sccsid
[] = "@(#)dr_1.c 8.1 (Berkeley) 5/31/93";
41 __RCSID("$NetBSD: dr_1.c,v 1.18 2001/02/05 01:10:08 christos Exp $");
52 static int fightitout(struct ship
*, struct ship
*, int);
63 if (sp
->file
->captain
[0])
65 nat
= capship(sp
)->nationality
;
67 if (nat
!= capship(to
)->nationality
&&
68 !is_toughmelee(sp
, to
, 0, 0))
70 for (i
= fouled2(sp
, to
); --i
>= 0;)
84 if (*sp
->file
->captain
)
86 if (sp
->file
->dir
== 0)
88 if (sp
->file
->struck
|| sp
->file
->captured
!= 0)
92 crew
[0] = sp
->specs
->crew1
!= 0;
93 crew
[1] = sp
->specs
->crew2
!= 0;
94 crew
[2] = sp
->specs
->crew3
!= 0;
96 if (!Xsnagged2(sp
, sq
))
101 || sp
->nationality
== capship(sq
)->nationality
)
103 switch (sp
->specs
->class - sq
->specs
->class) {
104 case -3: case -4: case -5:
107 sendbp(sp
, sq
, crew
[0]*100, 0);
111 sendbp(sp
, sq
, crew
[1]*10, 0);
116 if (crew
[0] || crew
[1]) {
118 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
120 crew
[0] = crew
[1] = 0;
123 case -1: case 0: case 1:
126 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
128 crew
[0] = crew
[1] = 0;
131 case 2: case 3: case 4: case 5:
133 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10+crew
[2],
135 crew
[0] = crew
[1] = crew
[2] = 0;
143 fightitout(struct ship
*from
, struct ship
*to
, int key
)
145 struct ship
*fromcap
, *tocap
;
146 int crewfrom
[3], crewto
[3], menfrom
, mento
;
147 int pcto
, pcfrom
, fromstrength
, strengthto
, frominjured
, toinjured
;
149 int index
, totalfrom
= 0, totalto
= 0;
153 menfrom
= mensent(from
, to
, crewfrom
, &fromcap
, &pcfrom
, key
);
154 mento
= mensent(to
, from
, crewto
, &tocap
, &pcto
, 0);
160 if (!menfrom
) { /* if crew surprised */
162 menfrom
= from
->specs
->crew1
164 + from
->specs
->crew3
;
166 menfrom
= from
->file
->pcrew
;
168 menfrom
*= 2; /* DBP's fight at an advantage */
171 fromstrength
= menfrom
* fromcap
->specs
->qual
;
172 strengthto
= mento
* tocap
->specs
->qual
;
174 ((fromstrength
< strengthto
* 3 && strengthto
< fromstrength
* 3)
175 || fromstrength
== -1) && count
< 4;
177 index
= fromstrength
/10;
180 toinjured
= MT
[index
][2 - dieroll() / 3];
181 totalto
+= toinjured
;
182 index
= strengthto
/10;
185 frominjured
= MT
[index
][2 - dieroll() / 3];
186 totalfrom
+= frominjured
;
187 menfrom
-= frominjured
;
189 fromstrength
= menfrom
* fromcap
->specs
->qual
;
190 strengthto
= mento
* tocap
->specs
->qual
;
192 if (fromstrength
>= strengthto
* 3 || count
== 4) {
193 unboard(to
, from
, 0);
194 subtract(from
, fromcap
, totalfrom
, crewfrom
, pcfrom
);
195 subtract(to
, tocap
, totalto
, crewto
, pcto
);
196 makemsg(from
, "boarders from %s repelled", to
->shipname
);
197 sprintf(message
, "killed in melee: %d. %s: %d",
198 totalto
, from
->shipname
, totalfrom
);
199 Writestr(W_SIGNAL
, to
, message
);
202 } else if (strengthto
>= fromstrength
* 3) {
203 unboard(from
, to
, 0);
204 subtract(from
, fromcap
, totalfrom
, crewfrom
, pcfrom
);
205 subtract(to
, tocap
, totalto
, crewto
, pcto
);
208 Write(W_POINTS
, fromcap
,
209 fromcap
->file
->points
-
212 : 2 * from
->specs
->pts
,
215 /* ptr1 points to the shipspec for the ship that was just unboarded.
216 I guess that what is going on here is that the pointer is multiplied
219 Write(W_CAPTURED
, from
, to
->file
->index
, 0, 0, 0);
220 topoints
= 2 * from
->specs
->pts
+ to
->file
->points
;
221 if (from
->file
->struck
)
222 topoints
-= from
->specs
->pts
;
223 Write(W_POINTS
, to
, topoints
, 0, 0, 0);
224 mento
= crewto
[0] ? crewto
[0] : crewto
[1];
226 subtract(to
, tocap
, mento
, crewto
, pcto
);
227 subtract(from
, to
, - mento
, crewfrom
, 0);
229 sprintf(message
, "captured by the %s!", to
->shipname
);
230 Writestr(W_SIGNAL
, from
, message
);
231 sprintf(message
, "killed in melee: %d. %s: %d",
232 totalto
, from
->shipname
, totalfrom
);
233 Writestr(W_SIGNAL
, to
, message
);
245 struct ship
*sp
, *sq
;
248 if (sp
->file
->dir
== 0)
250 for (sq
= sp
+ 1; sq
< ls
; sq
++)
251 if (sq
->file
->dir
&& meleeing(sp
, sq
) && meleeing(sq
, sp
))
252 fightitout(sp
, sq
, 0);
255 if (sq
->file
->dir
&& meleeing(sq
, sp
))
256 thwart
= fightitout(sp
, sq
, 1);
262 if (sq
->file
->dir
&& meleeing(sq
, sp
))
267 } else if (thwart
== 2)
277 struct ship
*closest
;
278 int crew
[3], men
= 0, target
, temp
;
279 int r
, guns
, ready
, load
, car
;
280 int index
, rakehim
, sternrake
;
284 if (sp
->file
->captain
[0] || sp
->file
->dir
== 0)
286 crew
[0] = sp
->specs
->crew1
;
287 crew
[1] = sp
->specs
->crew2
;
288 crew
[2] = sp
->specs
->crew3
;
289 for (n
= 0; n
< 3; n
++) {
290 if (sp
->file
->OBP
[n
].turnsent
)
291 men
+= sp
->file
->OBP
[n
].mensent
;
293 for (n
= 0; n
< 3; n
++) {
294 if (sp
->file
->DBP
[n
].turnsent
)
295 men
+= sp
->file
->DBP
[n
].mensent
;
298 crew
[0] = men
/100 ? 0 : crew
[0] != 0;
299 crew
[1] = (men%100
)/10 ? 0 : crew
[1] != 0;
300 crew
[2] = men%10
? 0 : crew
[2] != 0;
302 for (r
= 0; r
< 2; r
++) {
305 if (sp
->file
->struck
)
308 ready
= sp
->file
->readyR
;
309 guns
= sp
->specs
->gunR
;
310 car
= sp
->specs
->carR
;
312 ready
= sp
->file
->readyL
;
313 guns
= sp
->specs
->gunL
;
314 car
= sp
->specs
->carL
;
318 if ((ready
& R_LOADED
) == 0)
320 closest
= closestenemy(sp
, r
? 'r' : 'l', 0);
323 if (range(closest
, sp
) > range(sp
, closestenemy(sp
, r
? 'r' : 'l', 1)))
325 if (closest
->file
->struck
)
327 target
= range(sp
, closest
);
330 if (!guns
&& target
>= 3)
333 if (target
== 1 && sp
->file
->loadwith
== L_GRAPE
)
335 if (target
<= 3 && closest
->file
->FS
)
337 if (target
== 1 && load
!= L_GRAPE
)
339 if (load
> L_CHAIN
&& target
< 6)
343 rakehim
= gunsbear(sp
, closest
)
344 && !gunsbear(closest
, sp
);
345 temp
= portside(closest
, sp
, 1)
346 - closest
->file
->dir
+ 1;
351 sternrake
= temp
> 4 && temp
< 6;
355 index
= (index
- 1) / 3;
356 index
= index
> 8 ? 8 : index
;
358 hit
= HDT
[index
][target
-1];
360 hit
= HDTrake
[index
][target
-1];
361 if (rakehim
&& sternrake
)
363 hit
+= QUAL
[index
][capship(sp
)->specs
->qual
- 1];
364 for (n
= 0; n
< 3 && sp
->file
->captured
== 0; n
++)
371 if (ready
& R_INITIAL
) {
373 sp
->file
->readyL
&= ~R_INITIAL
;
375 sp
->file
->readyR
&= ~R_INITIAL
;
381 if (sp
->file
->captured
!= 0) {
387 hit
+= AMMO
[index
][load
- 1];
388 temp
= sp
->specs
->class;
389 if ((temp
>= 5 || temp
== 1) && windspeed
== 5)
391 if (windspeed
== 6 && temp
== 4)
393 if (windspeed
== 6 && temp
<= 3)
397 hit
= hit
> 10 ? 10 : hit
;
398 table(sp
, closest
, shootat
, load
, hit
, dieroll());
407 if (++turn
% 55 == 0) {
413 if (people
<= 0 || windspeed
== 7) {
415 struct ship
*bestship
= NULL
;
416 float net
, best
= 0.0;
418 if (*s
->file
->captain
)
420 net
= (float)s
->file
->points
/ s
->specs
->pts
;
427 char *tp
= getenv("WOTD");
436 strncpy(bestship
->file
->captain
, p
,
437 sizeof bestship
->file
->captain
);
438 bestship
->file
->captain
439 [sizeof bestship
->file
->captain
- 1] = 0;
444 Write(W_TURN
, SHIP(0), turn
, 0, 0, 0);
445 if (turn
% 7 == 0 && (dieroll() >= cc
->windchange
|| !windspeed
)) {
482 Write(W_WIND
, SHIP(0), winddir
, windspeed
, 0, 0);