]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/dr_1.c
1 /* $NetBSD: dr_1.c,v 1.3 1995/04/22 10:36:46 cgd 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
38 static char sccsid
[] = "@(#)dr_1.c 8.1 (Berkeley) 5/31/93";
40 static char rcsid
[] = "$NetBSD: dr_1.c,v 1.3 1995/04/22 10:36:46 cgd Exp $";
48 register struct ship
*sp
;
54 if (sp
->file
->captain
[0])
56 nat
= capship(sp
)->nationality
;
58 if (nat
!= capship(to
)->nationality
&&
59 !toughmelee(sp
, to
, 0, 0))
61 for (i
= fouled2(sp
, to
); --i
>= 0;)
71 register struct ship
*sp
, *sq
;
74 if (*sp
->file
->captain
)
76 if (sp
->file
->dir
== 0)
78 if (sp
->file
->struck
|| sp
->file
->captured
!= 0)
82 crew
[0] = sp
->specs
->crew1
!= 0;
83 crew
[1] = sp
->specs
->crew2
!= 0;
84 crew
[2] = sp
->specs
->crew3
!= 0;
86 if (!Xsnagged2(sp
, sq
))
91 || sp
->nationality
== capship(sq
)->nationality
)
93 switch (sp
->specs
->class - sq
->specs
->class) {
94 case -3: case -4: case -5:
97 sendbp(sp
, sq
, crew
[0]*100, 0);
101 sendbp(sp
, sq
, crew
[1]*10, 0);
106 if (crew
[0] || crew
[1]) {
108 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
110 crew
[0] = crew
[1] = 0;
113 case -1: case 0: case 1:
116 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
118 crew
[0] = crew
[1] = 0;
121 case 2: case 3: case 4: case 5:
123 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10+crew
[2],
125 crew
[0] = crew
[1] = crew
[2] = 0;
132 fightitout(from
, to
, key
)
133 struct ship
*from
, *to
;
136 struct ship
*fromcap
, *tocap
;
137 int crewfrom
[3], crewto
[3], menfrom
, mento
;
138 int pcto
, pcfrom
, fromstrength
, strengthto
, frominjured
, toinjured
;
140 int index
, totalfrom
= 0, totalto
= 0;
144 menfrom
= mensent(from
, to
, crewfrom
, &fromcap
, &pcfrom
, key
);
145 mento
= mensent(to
, from
, crewto
, &tocap
, &pcto
, 0);
151 if (!menfrom
) { /* if crew surprised */
153 menfrom
= from
->specs
->crew1
155 + from
->specs
->crew3
;
157 menfrom
= from
->file
->pcrew
;
159 menfrom
*= 2; /* DBP's fight at an advantage */
162 fromstrength
= menfrom
* fromcap
->specs
->qual
;
163 strengthto
= mento
* tocap
->specs
->qual
;
165 (fromstrength
< strengthto
* 3 && strengthto
< fromstrength
* 3
166 || fromstrength
== -1) && count
< 4;
168 index
= fromstrength
/10;
171 toinjured
= MT
[index
][2 - die() / 3];
172 totalto
+= toinjured
;
173 index
= strengthto
/10;
176 frominjured
= MT
[index
][2 - die() / 3];
177 totalfrom
+= frominjured
;
178 menfrom
-= frominjured
;
180 fromstrength
= menfrom
* fromcap
->specs
->qual
;
181 strengthto
= mento
* tocap
->specs
->qual
;
183 if (fromstrength
>= strengthto
* 3 || count
== 4) {
184 unboard(to
, from
, 0);
185 subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
186 subtract(to
, totalto
, crewto
, tocap
, pcto
);
187 makesignal(from
, "boarders from %s repelled", to
);
188 (void) sprintf(message
, "killed in melee: %d. %s: %d",
189 totalto
, from
->shipname
, totalfrom
);
190 Write(W_SIGNAL
, to
, 1, (int) message
, 0, 0, 0);
193 } else if (strengthto
>= fromstrength
* 3) {
194 unboard(from
, to
, 0);
195 subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
196 subtract(to
, totalto
, crewto
, tocap
, pcto
);
199 Write(W_POINTS
, fromcap
, 0,
200 fromcap
->file
->points
-
203 : 2 * from
->specs
->pts
,
206 /* ptr1 points to the shipspec for the ship that was just unboarded.
207 I guess that what is going on here is that the pointer is multiplied
210 Write(W_CAPTURED
, from
, 0, to
->file
->index
, 0, 0, 0);
211 topoints
= 2 * from
->specs
->pts
+ to
->file
->points
;
212 if (from
->file
->struck
)
213 topoints
-= from
->specs
->pts
;
214 Write(W_POINTS
, to
, 0, topoints
, 0, 0, 0);
215 mento
= crewto
[0] ? crewto
[0] : crewto
[1];
217 subtract(to
, mento
, crewto
, tocap
, pcto
);
218 subtract(from
, - mento
, crewfrom
, to
, 0);
220 (void) sprintf(message
, "captured by the %s!",
222 Write(W_SIGNAL
, from
, 1, (int) message
, 0, 0, 0);
223 (void) sprintf(message
, "killed in melee: %d. %s: %d",
224 totalto
, from
->shipname
, totalfrom
);
225 Write(W_SIGNAL
, to
, 1, (int) message
, 0, 0, 0);
236 register struct ship
*sp
, *sq
;
239 if (sp
->file
->dir
== 0)
241 for (sq
= sp
+ 1; sq
< ls
; sq
++)
242 if (sq
->file
->dir
&& meleeing(sp
, sq
) && meleeing(sq
, sp
))
243 (void) fightitout(sp
, sq
, 0);
246 if (sq
->file
->dir
&& meleeing(sq
, sp
))
247 thwart
= fightitout(sp
, sq
, 1);
253 if (sq
->file
->dir
&& meleeing(sq
, sp
))
258 } else if (thwart
== 2)
266 register struct ship
*sp
;
267 struct ship
*closest
;
268 int crew
[3], men
= 0, target
, temp
;
269 int r
, guns
, ready
, load
, car
;
270 int index
, rakehim
, sternrake
;
274 if (sp
->file
->captain
[0] || sp
->file
->dir
== 0)
276 crew
[0] = sp
->specs
->crew1
;
277 crew
[1] = sp
->specs
->crew2
;
278 crew
[2] = sp
->specs
->crew3
;
279 for (n
= 0; n
< 3; n
++) {
280 if (sp
->file
->OBP
[n
].turnsent
)
281 men
+= sp
->file
->OBP
[n
].mensent
;
283 for (n
= 0; n
< 3; n
++) {
284 if (sp
->file
->DBP
[n
].turnsent
)
285 men
+= sp
->file
->DBP
[n
].mensent
;
288 crew
[0] = men
/100 ? 0 : crew
[0] != 0;
289 crew
[1] = (men%100
)/10 ? 0 : crew
[1] != 0;
290 crew
[2] = men%10
? 0 : crew
[2] != 0;
292 for (r
= 0; r
< 2; r
++) {
295 if (sp
->file
->struck
)
298 ready
= sp
->file
->readyR
;
299 guns
= sp
->specs
->gunR
;
300 car
= sp
->specs
->carR
;
302 ready
= sp
->file
->readyL
;
303 guns
= sp
->specs
->gunL
;
304 car
= sp
->specs
->carL
;
308 if ((ready
& R_LOADED
) == 0)
310 closest
= closestenemy(sp
, r
? 'r' : 'l', 0);
313 if (range(closest
, sp
) > range(sp
, closestenemy(sp
, r
? 'r' : 'l', 1)))
315 if (closest
->file
->struck
)
317 target
= range(sp
, closest
);
320 if (!guns
&& target
>= 3)
323 if (target
== 1 && sp
->file
->loadwith
== L_GRAPE
)
325 if (target
<= 3 && closest
->file
->FS
)
327 if (target
== 1 && load
!= L_GRAPE
)
329 if (load
> L_CHAIN
&& target
< 6)
333 rakehim
= gunsbear(sp
, closest
)
334 && !gunsbear(closest
, sp
);
335 temp
= portside(closest
, sp
, 1)
336 - closest
->file
->dir
+ 1;
341 sternrake
= temp
> 4 && temp
< 6;
345 index
= (index
- 1) / 3;
346 index
= index
> 8 ? 8 : index
;
348 hit
= HDT
[index
][target
-1];
350 hit
= HDTrake
[index
][target
-1];
351 if (rakehim
&& sternrake
)
353 hit
+= QUAL
[index
][capship(sp
)->specs
->qual
- 1];
354 for (n
= 0; n
< 3 && sp
->file
->captured
== 0; n
++)
360 if (ready
& R_INITIAL
) {
362 sp
->file
->readyL
&= ~R_INITIAL
;
364 sp
->file
->readyR
&= ~R_INITIAL
;
370 if (sp
->file
->captured
!= 0)
375 hit
+= AMMO
[index
][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());
394 if (++turn
% 55 == 0)
399 if (people
<= 0 || windspeed
== 7) {
400 register struct ship
*s
;
401 struct ship
*bestship
;
402 float net
, best
= 0.0;
404 if (*s
->file
->captain
)
406 net
= (float)s
->file
->points
/ s
->specs
->pts
;
413 char *p
= getenv("WOTD");
418 (void) strncpy(bestship
->file
->captain
, p
,
419 sizeof bestship
->file
->captain
);
420 bestship
->file
->captain
421 [sizeof bestship
->file
->captain
- 1] = 0;
426 Write(W_TURN
, SHIP(0), 0, turn
, 0, 0, 0);
427 if (turn
% 7 == 0 && (die() >= cc
->windchange
|| !windspeed
)) {
464 Write(W_WIND
, SHIP(0), 0, winddir
, windspeed
, 0, 0);