]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/dr_1.c
1 /* $NetBSD: dr_1.c,v 1.23 2008/01/28 01:58:01 dholland 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)dr_1.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: dr_1.c,v 1.23 2008/01/28 01:58:01 dholland Exp $");
48 static int fightitout(struct ship
*, struct ship
*, int);
59 if (sp
->file
->captain
[0])
61 nat
= capship(sp
)->nationality
;
63 if (nat
!= capship(to
)->nationality
&&
64 !is_toughmelee(sp
, to
, 0, 0))
66 for (i
= fouled2(sp
, to
); --i
>= 0;)
80 if (*sp
->file
->captain
)
82 if (sp
->file
->dir
== 0)
84 if (sp
->file
->struck
|| sp
->file
->captured
!= 0)
88 crew
[0] = sp
->specs
->crew1
!= 0;
89 crew
[1] = sp
->specs
->crew2
!= 0;
90 crew
[2] = sp
->specs
->crew3
!= 0;
92 if (!Xsnagged2(sp
, sq
))
97 || sp
->nationality
== capship(sq
)->nationality
)
99 switch (sp
->specs
->class - sq
->specs
->class) {
100 case -3: case -4: case -5:
103 sendbp(sp
, sq
, crew
[0]*100, 0);
107 sendbp(sp
, sq
, crew
[1]*10, 0);
112 if (crew
[0] || crew
[1]) {
114 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
116 crew
[0] = crew
[1] = 0;
119 case -1: case 0: case 1:
122 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
124 crew
[0] = crew
[1] = 0;
127 case 2: case 3: case 4: case 5:
129 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10+crew
[2],
131 crew
[0] = crew
[1] = crew
[2] = 0;
139 fightitout(struct ship
*from
, struct ship
*to
, int key
)
141 struct ship
*fromcap
, *tocap
;
142 int crewfrom
[3], crewto
[3], menfrom
, mento
;
143 int pcto
, pcfrom
, fromstrength
, strengthto
, frominjured
, toinjured
;
145 int indx
, 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 indx
= fromstrength
/10;
176 toinjured
= MT
[indx
][2 - dieroll() / 3];
177 totalto
+= toinjured
;
178 indx
= strengthto
/10;
181 frominjured
= MT
[indx
][2 - dieroll() / 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
, fromcap
, totalfrom
, crewfrom
, pcfrom
);
191 subtract(to
, tocap
, totalto
, crewto
, pcto
);
192 makemsg(from
, "boarders from %s repelled", to
->shipname
);
193 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
, fromcap
, totalfrom
, crewfrom
, pcfrom
);
201 subtract(to
, tocap
, totalto
, crewto
, 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
, tocap
, mento
, crewto
, pcto
);
223 subtract(from
, to
, - mento
, crewfrom
, 0);
225 sprintf(message
, "captured by the %s!", to
->shipname
);
226 Writestr(W_SIGNAL
, from
, message
);
227 sprintf(message
, "killed in melee: %d. %s: %d",
228 totalto
, from
->shipname
, totalfrom
);
229 Writestr(W_SIGNAL
, to
, message
);
241 struct ship
*sp
, *sq
;
244 if (sp
->file
->dir
== 0)
246 for (sq
= sp
+ 1; sq
< ls
; sq
++)
247 if (sq
->file
->dir
&& meleeing(sp
, sq
) && meleeing(sq
, sp
))
248 fightitout(sp
, sq
, 0);
251 if (sq
->file
->dir
&& meleeing(sq
, sp
))
252 thwart
= fightitout(sp
, sq
, 1);
258 if (sq
->file
->dir
&& meleeing(sq
, sp
))
263 } else if (thwart
== 2)
273 struct ship
*closest
;
274 int crew
[3], men
= 0, target
, temp
;
275 int r
, guns
, ready
, load
, car
;
276 int indx
, rakehim
, sternrake
;
280 if (sp
->file
->captain
[0] || sp
->file
->dir
== 0)
282 crew
[0] = sp
->specs
->crew1
;
283 crew
[1] = sp
->specs
->crew2
;
284 crew
[2] = sp
->specs
->crew3
;
285 for (n
= 0; n
< 3; n
++) {
286 if (sp
->file
->OBP
[n
].turnsent
)
287 men
+= sp
->file
->OBP
[n
].mensent
;
289 for (n
= 0; n
< 3; n
++) {
290 if (sp
->file
->DBP
[n
].turnsent
)
291 men
+= sp
->file
->DBP
[n
].mensent
;
294 crew
[0] = men
/100 ? 0 : crew
[0] != 0;
295 crew
[1] = (men%100
)/10 ? 0 : crew
[1] != 0;
296 crew
[2] = men%10
? 0 : crew
[2] != 0;
298 for (r
= 0; r
< 2; r
++) {
301 if (sp
->file
->struck
)
304 ready
= sp
->file
->readyR
;
305 guns
= sp
->specs
->gunR
;
306 car
= sp
->specs
->carR
;
308 ready
= sp
->file
->readyL
;
309 guns
= sp
->specs
->gunL
;
310 car
= sp
->specs
->carL
;
314 if ((ready
& R_LOADED
) == 0)
316 closest
= closestenemy(sp
, r
? 'r' : 'l', 0);
319 if (range(closest
, sp
) > range(sp
, closestenemy(sp
, r
? 'r' : 'l', 1)))
321 if (closest
->file
->struck
)
323 target
= range(sp
, closest
);
326 if (!guns
&& target
>= 3)
329 if (target
== 1 && sp
->file
->loadwith
== L_GRAPE
)
331 if (target
<= 3 && closest
->file
->FS
)
333 if (target
== 1 && load
!= L_GRAPE
)
335 if (load
> L_CHAIN
&& target
< 6)
339 rakehim
= gunsbear(sp
, closest
)
340 && !gunsbear(closest
, sp
);
341 temp
= portside(closest
, sp
, 1)
342 - closest
->file
->dir
+ 1;
347 sternrake
= temp
> 4 && temp
< 6;
351 indx
= (indx
- 1) / 3;
352 indx
= indx
> 8 ? 8 : indx
;
354 hit
= HDT
[indx
][target
-1];
356 hit
= HDTrake
[indx
][target
-1];
357 if (rakehim
&& sternrake
)
359 hit
+= QUAL
[indx
][capship(sp
)->specs
->qual
- 1];
360 for (n
= 0; n
< 3 && sp
->file
->captured
== 0; n
++)
367 if (ready
& R_INITIAL
) {
369 sp
->file
->readyL
&= ~R_INITIAL
;
371 sp
->file
->readyR
&= ~R_INITIAL
;
377 if (sp
->file
->captured
!= 0) {
383 hit
+= AMMO
[indx
][load
- 1];
384 temp
= sp
->specs
->class;
385 if ((temp
>= 5 || temp
== 1) && windspeed
== 5)
387 if (windspeed
== 6 && temp
== 4)
389 if (windspeed
== 6 && temp
<= 3)
393 hit
= hit
> 10 ? 10 : hit
;
394 table(sp
, closest
, shootat
, load
, hit
, dieroll());
403 if (++turn
% 55 == 0) {
409 if (people
<= 0 || windspeed
== 7) {
411 struct ship
*bestship
= NULL
;
412 float net
, best
= 0.0;
414 if (*s
->file
->captain
)
416 net
= (float)s
->file
->points
/ s
->specs
->pts
;
422 if (best
> 0.0 && bestship
) {
423 char *tp
= getenv("WOTD");
428 *tp
= toupper((unsigned char)*tp
);
431 strlcpy(bestship
->file
->captain
, p
,
432 sizeof bestship
->file
->captain
);
437 Write(W_TURN
, SHIP(0), turn
, 0, 0, 0);
438 if (turn
% 7 == 0 && (dieroll() >= cc
->windchange
|| !windspeed
)) {
475 Write(W_WIND
, SHIP(0), winddir
, windspeed
, 0, 0);