]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/dr_1.c
1 /* $NetBSD: dr_1.c,v 1.14 2001/01/04 03:21:16 jwise 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.14 2001/01/04 03:21:16 jwise Exp $");
52 static int fightitout(struct ship
*, struct ship
*, int);
54 void compcombat(void);
66 if (sp
->file
->captain
[0])
68 nat
= capship(sp
)->nationality
;
70 if (nat
!= capship(to
)->nationality
&&
71 !is_toughmelee(sp
, to
, 0, 0))
73 for (i
= fouled2(sp
, to
); --i
>= 0;)
87 if (*sp
->file
->captain
)
89 if (sp
->file
->dir
== 0)
91 if (sp
->file
->struck
|| sp
->file
->captured
!= 0)
95 crew
[0] = sp
->specs
->crew1
!= 0;
96 crew
[1] = sp
->specs
->crew2
!= 0;
97 crew
[2] = sp
->specs
->crew3
!= 0;
99 if (!Xsnagged2(sp
, sq
))
101 if (meleeing(sp
, sq
))
104 || sp
->nationality
== capship(sq
)->nationality
)
106 switch (sp
->specs
->class - sq
->specs
->class) {
107 case -3: case -4: case -5:
110 sendbp(sp
, sq
, crew
[0]*100, 0);
114 sendbp(sp
, sq
, crew
[1]*10, 0);
119 if (crew
[0] || crew
[1]) {
121 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
123 crew
[0] = crew
[1] = 0;
126 case -1: case 0: case 1:
129 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
131 crew
[0] = crew
[1] = 0;
134 case 2: case 3: case 4: case 5:
136 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10+crew
[2],
138 crew
[0] = crew
[1] = crew
[2] = 0;
146 fightitout(struct ship
*from
, struct ship
*to
, int key
)
148 struct ship
*fromcap
, *tocap
;
149 int crewfrom
[3], crewto
[3], menfrom
, mento
;
150 int pcto
, pcfrom
, fromstrength
, strengthto
, frominjured
, toinjured
;
152 int index
, totalfrom
= 0, totalto
= 0;
156 menfrom
= mensent(from
, to
, crewfrom
, &fromcap
, &pcfrom
, key
);
157 mento
= mensent(to
, from
, crewto
, &tocap
, &pcto
, 0);
163 if (!menfrom
) { /* if crew surprised */
165 menfrom
= from
->specs
->crew1
167 + from
->specs
->crew3
;
169 menfrom
= from
->file
->pcrew
;
171 menfrom
*= 2; /* DBP's fight at an advantage */
174 fromstrength
= menfrom
* fromcap
->specs
->qual
;
175 strengthto
= mento
* tocap
->specs
->qual
;
177 ((fromstrength
< strengthto
* 3 && strengthto
< fromstrength
* 3)
178 || fromstrength
== -1) && count
< 4;
180 index
= fromstrength
/10;
183 toinjured
= MT
[index
][2 - dieroll() / 3];
184 totalto
+= toinjured
;
185 index
= strengthto
/10;
188 frominjured
= MT
[index
][2 - dieroll() / 3];
189 totalfrom
+= frominjured
;
190 menfrom
-= frominjured
;
192 fromstrength
= menfrom
* fromcap
->specs
->qual
;
193 strengthto
= mento
* tocap
->specs
->qual
;
195 if (fromstrength
>= strengthto
* 3 || count
== 4) {
196 unboard(to
, from
, 0);
197 subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
198 subtract(to
, totalto
, crewto
, tocap
, pcto
);
199 makemsg(from
, "boarders from %s repelled", to
->shipname
);
200 sprintf(message
, "killed in melee: %d. %s: %d",
201 totalto
, from
->shipname
, totalfrom
);
202 Writestr(W_SIGNAL
, to
, message
);
205 } else if (strengthto
>= fromstrength
* 3) {
206 unboard(from
, to
, 0);
207 subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
208 subtract(to
, totalto
, crewto
, tocap
, pcto
);
211 Write(W_POINTS
, fromcap
,
212 fromcap
->file
->points
-
215 : 2 * from
->specs
->pts
,
218 /* ptr1 points to the shipspec for the ship that was just unboarded.
219 I guess that what is going on here is that the pointer is multiplied
222 Write(W_CAPTURED
, from
, to
->file
->index
, 0, 0, 0);
223 topoints
= 2 * from
->specs
->pts
+ to
->file
->points
;
224 if (from
->file
->struck
)
225 topoints
-= from
->specs
->pts
;
226 Write(W_POINTS
, to
, topoints
, 0, 0, 0);
227 mento
= crewto
[0] ? crewto
[0] : crewto
[1];
229 subtract(to
, mento
, crewto
, tocap
, pcto
);
230 subtract(from
, - mento
, crewfrom
, to
, 0);
232 sprintf(message
, "captured by the %s!", to
->shipname
);
233 Writestr(W_SIGNAL
, from
, message
);
234 (void) sprintf(message
, "killed in melee: %d. %s: %d",
235 totalto
, from
->shipname
, totalfrom
);
236 Writestr(W_SIGNAL
, to
, message
);
248 struct ship
*sp
, *sq
;
251 if (sp
->file
->dir
== 0)
253 for (sq
= sp
+ 1; sq
< ls
; sq
++)
254 if (sq
->file
->dir
&& meleeing(sp
, sq
) && meleeing(sq
, sp
))
255 fightitout(sp
, sq
, 0);
258 if (sq
->file
->dir
&& meleeing(sq
, sp
))
259 thwart
= fightitout(sp
, sq
, 1);
265 if (sq
->file
->dir
&& meleeing(sq
, sp
))
270 } else if (thwart
== 2)
280 struct ship
*closest
;
281 int crew
[3], men
= 0, target
, temp
;
282 int r
, guns
, ready
, load
, car
;
283 int index
, rakehim
, sternrake
;
287 if (sp
->file
->captain
[0] || sp
->file
->dir
== 0)
289 crew
[0] = sp
->specs
->crew1
;
290 crew
[1] = sp
->specs
->crew2
;
291 crew
[2] = sp
->specs
->crew3
;
292 for (n
= 0; n
< 3; n
++) {
293 if (sp
->file
->OBP
[n
].turnsent
)
294 men
+= sp
->file
->OBP
[n
].mensent
;
296 for (n
= 0; n
< 3; n
++) {
297 if (sp
->file
->DBP
[n
].turnsent
)
298 men
+= sp
->file
->DBP
[n
].mensent
;
301 crew
[0] = men
/100 ? 0 : crew
[0] != 0;
302 crew
[1] = (men%100
)/10 ? 0 : crew
[1] != 0;
303 crew
[2] = men%10
? 0 : crew
[2] != 0;
305 for (r
= 0; r
< 2; r
++) {
308 if (sp
->file
->struck
)
311 ready
= sp
->file
->readyR
;
312 guns
= sp
->specs
->gunR
;
313 car
= sp
->specs
->carR
;
315 ready
= sp
->file
->readyL
;
316 guns
= sp
->specs
->gunL
;
317 car
= sp
->specs
->carL
;
321 if ((ready
& R_LOADED
) == 0)
323 closest
= closestenemy(sp
, r
? 'r' : 'l', 0);
326 if (range(closest
, sp
) > range(sp
, closestenemy(sp
, r
? 'r' : 'l', 1)))
328 if (closest
->file
->struck
)
330 target
= range(sp
, closest
);
333 if (!guns
&& target
>= 3)
336 if (target
== 1 && sp
->file
->loadwith
== L_GRAPE
)
338 if (target
<= 3 && closest
->file
->FS
)
340 if (target
== 1 && load
!= L_GRAPE
)
342 if (load
> L_CHAIN
&& target
< 6)
346 rakehim
= gunsbear(sp
, closest
)
347 && !gunsbear(closest
, sp
);
348 temp
= portside(closest
, sp
, 1)
349 - closest
->file
->dir
+ 1;
354 sternrake
= temp
> 4 && temp
< 6;
358 index
= (index
- 1) / 3;
359 index
= index
> 8 ? 8 : index
;
361 hit
= HDT
[index
][target
-1];
363 hit
= HDTrake
[index
][target
-1];
364 if (rakehim
&& sternrake
)
366 hit
+= QUAL
[index
][capship(sp
)->specs
->qual
- 1];
367 for (n
= 0; n
< 3 && sp
->file
->captured
== 0; n
++)
374 if (ready
& R_INITIAL
) {
376 sp
->file
->readyL
&= ~R_INITIAL
;
378 sp
->file
->readyR
&= ~R_INITIAL
;
384 if (sp
->file
->captured
!= 0) {
390 hit
+= AMMO
[index
][load
- 1];
391 temp
= sp
->specs
->class;
392 if ((temp
>= 5 || temp
== 1) && windspeed
== 5)
394 if (windspeed
== 6 && temp
== 4)
396 if (windspeed
== 6 && temp
<= 3)
400 hit
= hit
> 10 ? 10 : hit
;
401 table(shootat
, load
, hit
, closest
, sp
, dieroll());
410 if (++turn
% 55 == 0) {
416 if (people
<= 0 || windspeed
== 7) {
418 struct ship
*bestship
= NULL
;
419 float net
, best
= 0.0;
421 if (*s
->file
->captain
)
423 net
= (float)s
->file
->points
/ s
->specs
->pts
;
430 char *tp
= getenv("WOTD");
439 strncpy(bestship
->file
->captain
, p
,
440 sizeof bestship
->file
->captain
);
441 bestship
->file
->captain
442 [sizeof bestship
->file
->captain
- 1] = 0;
447 Write(W_TURN
, SHIP(0), turn
, 0, 0, 0);
448 if (turn
% 7 == 0 && (dieroll() >= cc
->windchange
|| !windspeed
)) {
485 Write(W_WIND
, SHIP(0), winddir
, windspeed
, 0, 0);