]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/dr_1.c
1 /* $NetBSD: dr_1.c,v 1.10 1999/09/30 18:01:33 jsm 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.10 1999/09/30 18:01:33 jsm Exp $");
57 if (sp
->file
->captain
[0])
59 nat
= capship(sp
)->nationality
;
61 if (nat
!= capship(to
)->nationality
&&
62 !is_toughmelee(sp
, to
, 0, 0))
64 for (i
= fouled2(sp
, to
); --i
>= 0;)
78 if (*sp
->file
->captain
)
80 if (sp
->file
->dir
== 0)
82 if (sp
->file
->struck
|| sp
->file
->captured
!= 0)
86 crew
[0] = sp
->specs
->crew1
!= 0;
87 crew
[1] = sp
->specs
->crew2
!= 0;
88 crew
[2] = sp
->specs
->crew3
!= 0;
90 if (!Xsnagged2(sp
, sq
))
95 || sp
->nationality
== capship(sq
)->nationality
)
97 switch (sp
->specs
->class - sq
->specs
->class) {
98 case -3: case -4: case -5:
101 sendbp(sp
, sq
, crew
[0]*100, 0);
105 sendbp(sp
, sq
, crew
[1]*10, 0);
110 if (crew
[0] || crew
[1]) {
112 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
114 crew
[0] = crew
[1] = 0;
117 case -1: case 0: case 1:
120 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
122 crew
[0] = crew
[1] = 0;
125 case 2: case 3: case 4: case 5:
127 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10+crew
[2],
129 crew
[0] = crew
[1] = crew
[2] = 0;
137 fightitout(from
, to
, key
)
138 struct ship
*from
, *to
;
141 struct ship
*fromcap
, *tocap
;
142 int crewfrom
[3], crewto
[3], menfrom
, mento
;
143 int pcto
, pcfrom
, fromstrength
, strengthto
, frominjured
, toinjured
;
145 int index
, totalfrom
= 0, totalto
= 0;
149 menfrom
= mensent(from
, to
, crewfrom
, &fromcap
, &pcfrom
, key
);
150 mento
= mensent(to
, from
, crewto
, &tocap
, &pcto
, 0);
156 if (!menfrom
) { /* if crew surprised */
158 menfrom
= from
->specs
->crew1
160 + from
->specs
->crew3
;
162 menfrom
= from
->file
->pcrew
;
164 menfrom
*= 2; /* DBP's fight at an advantage */
167 fromstrength
= menfrom
* fromcap
->specs
->qual
;
168 strengthto
= mento
* tocap
->specs
->qual
;
170 ((fromstrength
< strengthto
* 3 && strengthto
< fromstrength
* 3)
171 || fromstrength
== -1) && count
< 4;
173 index
= fromstrength
/10;
176 toinjured
= MT
[index
][2 - die() / 3];
177 totalto
+= toinjured
;
178 index
= strengthto
/10;
181 frominjured
= MT
[index
][2 - die() / 3];
182 totalfrom
+= frominjured
;
183 menfrom
-= frominjured
;
185 fromstrength
= menfrom
* fromcap
->specs
->qual
;
186 strengthto
= mento
* tocap
->specs
->qual
;
188 if (fromstrength
>= strengthto
* 3 || count
== 4) {
189 unboard(to
, from
, 0);
190 subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
191 subtract(to
, totalto
, crewto
, tocap
, pcto
);
192 makemsg(from
, "boarders from %s repelled", to
->shipname
);
193 (void) sprintf(message
, "killed in melee: %d. %s: %d",
194 totalto
, from
->shipname
, totalfrom
);
195 Writestr(W_SIGNAL
, to
, message
);
198 } else if (strengthto
>= fromstrength
* 3) {
199 unboard(from
, to
, 0);
200 subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
201 subtract(to
, totalto
, crewto
, tocap
, pcto
);
204 Write(W_POINTS
, fromcap
,
205 fromcap
->file
->points
-
208 : 2 * from
->specs
->pts
,
211 /* ptr1 points to the shipspec for the ship that was just unboarded.
212 I guess that what is going on here is that the pointer is multiplied
215 Write(W_CAPTURED
, from
, to
->file
->index
, 0, 0, 0);
216 topoints
= 2 * from
->specs
->pts
+ to
->file
->points
;
217 if (from
->file
->struck
)
218 topoints
-= from
->specs
->pts
;
219 Write(W_POINTS
, to
, topoints
, 0, 0, 0);
220 mento
= crewto
[0] ? crewto
[0] : crewto
[1];
222 subtract(to
, mento
, crewto
, tocap
, pcto
);
223 subtract(from
, - mento
, crewfrom
, to
, 0);
225 (void) sprintf(message
, "captured by the %s!",
227 Writestr(W_SIGNAL
, from
, message
);
228 (void) sprintf(message
, "killed in melee: %d. %s: %d",
229 totalto
, from
->shipname
, totalfrom
);
230 Writestr(W_SIGNAL
, to
, message
);
242 struct ship
*sp
, *sq
;
245 if (sp
->file
->dir
== 0)
247 for (sq
= sp
+ 1; sq
< ls
; sq
++)
248 if (sq
->file
->dir
&& meleeing(sp
, sq
) && meleeing(sq
, sp
))
249 (void) fightitout(sp
, sq
, 0);
252 if (sq
->file
->dir
&& meleeing(sq
, sp
))
253 thwart
= fightitout(sp
, sq
, 1);
259 if (sq
->file
->dir
&& meleeing(sq
, sp
))
264 } else if (thwart
== 2)
274 struct ship
*closest
;
275 int crew
[3], men
= 0, target
, temp
;
276 int r
, guns
, ready
, load
, car
;
277 int index
, rakehim
, sternrake
;
281 if (sp
->file
->captain
[0] || sp
->file
->dir
== 0)
283 crew
[0] = sp
->specs
->crew1
;
284 crew
[1] = sp
->specs
->crew2
;
285 crew
[2] = sp
->specs
->crew3
;
286 for (n
= 0; n
< 3; n
++) {
287 if (sp
->file
->OBP
[n
].turnsent
)
288 men
+= sp
->file
->OBP
[n
].mensent
;
290 for (n
= 0; n
< 3; n
++) {
291 if (sp
->file
->DBP
[n
].turnsent
)
292 men
+= sp
->file
->DBP
[n
].mensent
;
295 crew
[0] = men
/100 ? 0 : crew
[0] != 0;
296 crew
[1] = (men%100
)/10 ? 0 : crew
[1] != 0;
297 crew
[2] = men%10
? 0 : crew
[2] != 0;
299 for (r
= 0; r
< 2; r
++) {
302 if (sp
->file
->struck
)
305 ready
= sp
->file
->readyR
;
306 guns
= sp
->specs
->gunR
;
307 car
= sp
->specs
->carR
;
309 ready
= sp
->file
->readyL
;
310 guns
= sp
->specs
->gunL
;
311 car
= sp
->specs
->carL
;
315 if ((ready
& R_LOADED
) == 0)
317 closest
= closestenemy(sp
, r
? 'r' : 'l', 0);
320 if (range(closest
, sp
) > range(sp
, closestenemy(sp
, r
? 'r' : 'l', 1)))
322 if (closest
->file
->struck
)
324 target
= range(sp
, closest
);
327 if (!guns
&& target
>= 3)
330 if (target
== 1 && sp
->file
->loadwith
== L_GRAPE
)
332 if (target
<= 3 && closest
->file
->FS
)
334 if (target
== 1 && load
!= L_GRAPE
)
336 if (load
> L_CHAIN
&& target
< 6)
340 rakehim
= gunsbear(sp
, closest
)
341 && !gunsbear(closest
, sp
);
342 temp
= portside(closest
, sp
, 1)
343 - closest
->file
->dir
+ 1;
348 sternrake
= temp
> 4 && temp
< 6;
352 index
= (index
- 1) / 3;
353 index
= index
> 8 ? 8 : index
;
355 hit
= HDT
[index
][target
-1];
357 hit
= HDTrake
[index
][target
-1];
358 if (rakehim
&& sternrake
)
360 hit
+= QUAL
[index
][capship(sp
)->specs
->qual
- 1];
361 for (n
= 0; n
< 3 && sp
->file
->captured
== 0; n
++)
368 if (ready
& R_INITIAL
) {
370 sp
->file
->readyL
&= ~R_INITIAL
;
372 sp
->file
->readyR
&= ~R_INITIAL
;
378 if (sp
->file
->captured
!= 0) {
384 hit
+= AMMO
[index
][load
- 1];
385 temp
= sp
->specs
->class;
386 if ((temp
>= 5 || temp
== 1) && windspeed
== 5)
388 if (windspeed
== 6 && temp
== 4)
390 if (windspeed
== 6 && temp
<= 3)
394 hit
= hit
> 10 ? 10 : hit
;
395 table(shootat
, load
, hit
, closest
, sp
, die());
404 if (++turn
% 55 == 0) {
410 if (people
<= 0 || windspeed
== 7) {
412 struct ship
*bestship
= NULL
;
413 float net
, best
= 0.0;
415 if (*s
->file
->captain
)
417 net
= (float)s
->file
->points
/ s
->specs
->pts
;
424 char *tp
= getenv("WOTD");
433 (void) strncpy(bestship
->file
->captain
, p
,
434 sizeof bestship
->file
->captain
);
435 bestship
->file
->captain
436 [sizeof bestship
->file
->captain
- 1] = 0;
441 Write(W_TURN
, SHIP(0), turn
, 0, 0, 0);
442 if (turn
% 7 == 0 && (die() >= cc
->windchange
|| !windspeed
)) {
479 Write(W_WIND
, SHIP(0), winddir
, windspeed
, 0, 0);