]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/dr_1.c
2 * Copyright (c) 1983 Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 /*static char sccsid[] = "from: @(#)dr_1.c 5.4 (Berkeley) 6/1/90";*/
36 static char rcsid
[] = "$Id: dr_1.c,v 1.2 1993/08/01 18:51:52 mycroft Exp $";
43 register struct ship
*sp
;
49 if (sp
->file
->captain
[0])
51 nat
= capship(sp
)->nationality
;
53 if (nat
!= capship(to
)->nationality
&&
54 !toughmelee(sp
, to
, 0, 0))
56 for (i
= fouled2(sp
, to
); --i
>= 0;)
66 register struct ship
*sp
, *sq
;
69 if (*sp
->file
->captain
)
71 if (sp
->file
->dir
== 0)
73 if (sp
->file
->struck
|| sp
->file
->captured
!= 0)
77 crew
[0] = sp
->specs
->crew1
!= 0;
78 crew
[1] = sp
->specs
->crew2
!= 0;
79 crew
[2] = sp
->specs
->crew3
!= 0;
81 if (!Xsnagged2(sp
, sq
))
86 || sp
->nationality
== capship(sq
)->nationality
)
88 switch (sp
->specs
->class - sq
->specs
->class) {
89 case -3: case -4: case -5:
92 sendbp(sp
, sq
, crew
[0]*100, 0);
96 sendbp(sp
, sq
, crew
[1]*10, 0);
101 if (crew
[0] || crew
[1]) {
103 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
105 crew
[0] = crew
[1] = 0;
108 case -1: case 0: case 1:
111 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10,
113 crew
[0] = crew
[1] = 0;
116 case 2: case 3: case 4: case 5:
118 sendbp(sp
, sq
, crew
[0]*100+crew
[1]*10+crew
[2],
120 crew
[0] = crew
[1] = crew
[2] = 0;
127 fightitout(from
, to
, key
)
128 struct ship
*from
, *to
;
131 struct ship
*fromcap
, *tocap
;
132 int crewfrom
[3], crewto
[3], menfrom
, mento
;
133 int pcto
, pcfrom
, fromstrength
, strengthto
, frominjured
, toinjured
;
135 int index
, totalfrom
= 0, totalto
= 0;
139 menfrom
= mensent(from
, to
, crewfrom
, &fromcap
, &pcfrom
, key
);
140 mento
= mensent(to
, from
, crewto
, &tocap
, &pcto
, 0);
146 if (!menfrom
) { /* if crew surprised */
148 menfrom
= from
->specs
->crew1
150 + from
->specs
->crew3
;
152 menfrom
= from
->file
->pcrew
;
154 menfrom
*= 2; /* DBP's fight at an advantage */
157 fromstrength
= menfrom
* fromcap
->specs
->qual
;
158 strengthto
= mento
* tocap
->specs
->qual
;
160 (fromstrength
< strengthto
* 3 && strengthto
< fromstrength
* 3
161 || fromstrength
== -1) && count
< 4;
163 index
= fromstrength
/10;
166 toinjured
= MT
[index
][2 - die() / 3];
167 totalto
+= toinjured
;
168 index
= strengthto
/10;
171 frominjured
= MT
[index
][2 - die() / 3];
172 totalfrom
+= frominjured
;
173 menfrom
-= frominjured
;
175 fromstrength
= menfrom
* fromcap
->specs
->qual
;
176 strengthto
= mento
* tocap
->specs
->qual
;
178 if (fromstrength
>= strengthto
* 3 || count
== 4) {
179 unboard(to
, from
, 0);
180 subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
181 subtract(to
, totalto
, crewto
, tocap
, pcto
);
182 makesignal(from
, "boarders from %s repelled", to
);
183 (void) sprintf(message
, "killed in melee: %d. %s: %d",
184 totalto
, from
->shipname
, totalfrom
);
185 Write(W_SIGNAL
, to
, 1, (int) message
, 0, 0, 0);
188 } else if (strengthto
>= fromstrength
* 3) {
189 unboard(from
, to
, 0);
190 subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
191 subtract(to
, totalto
, crewto
, tocap
, pcto
);
194 Write(W_POINTS
, fromcap
, 0,
195 fromcap
->file
->points
-
198 : 2 * from
->specs
->pts
,
201 /* ptr1 points to the shipspec for the ship that was just unboarded.
202 I guess that what is going on here is that the pointer is multiplied
205 Write(W_CAPTURED
, from
, 0, to
->file
->index
, 0, 0, 0);
206 topoints
= 2 * from
->specs
->pts
+ to
->file
->points
;
207 if (from
->file
->struck
)
208 topoints
-= from
->specs
->pts
;
209 Write(W_POINTS
, to
, 0, topoints
, 0, 0, 0);
210 mento
= crewto
[0] ? crewto
[0] : crewto
[1];
212 subtract(to
, mento
, crewto
, tocap
, pcto
);
213 subtract(from
, - mento
, crewfrom
, to
, 0);
215 (void) sprintf(message
, "captured by the %s!",
217 Write(W_SIGNAL
, from
, 1, (int) message
, 0, 0, 0);
218 (void) sprintf(message
, "killed in melee: %d. %s: %d",
219 totalto
, from
->shipname
, totalfrom
);
220 Write(W_SIGNAL
, to
, 1, (int) message
, 0, 0, 0);
231 register struct ship
*sp
, *sq
;
234 if (sp
->file
->dir
== 0)
236 for (sq
= sp
+ 1; sq
< ls
; sq
++)
237 if (sq
->file
->dir
&& meleeing(sp
, sq
) && meleeing(sq
, sp
))
238 (void) fightitout(sp
, sq
, 0);
241 if (sq
->file
->dir
&& meleeing(sq
, sp
))
242 thwart
= fightitout(sp
, sq
, 1);
248 if (sq
->file
->dir
&& meleeing(sq
, sp
))
253 } else if (thwart
== 2)
261 register struct ship
*sp
;
262 struct ship
*closest
;
263 int crew
[3], men
= 0, target
, temp
;
264 int r
, guns
, ready
, load
, car
;
265 int index
, rakehim
, sternrake
;
269 if (sp
->file
->captain
[0] || sp
->file
->dir
== 0)
271 crew
[0] = sp
->specs
->crew1
;
272 crew
[1] = sp
->specs
->crew2
;
273 crew
[2] = sp
->specs
->crew3
;
274 for (n
= 0; n
< 3; n
++) {
275 if (sp
->file
->OBP
[n
].turnsent
)
276 men
+= sp
->file
->OBP
[n
].mensent
;
278 for (n
= 0; n
< 3; n
++) {
279 if (sp
->file
->DBP
[n
].turnsent
)
280 men
+= sp
->file
->DBP
[n
].mensent
;
283 crew
[0] = men
/100 ? 0 : crew
[0] != 0;
284 crew
[1] = (men%100
)/10 ? 0 : crew
[1] != 0;
285 crew
[2] = men%10
? 0 : crew
[2] != 0;
287 for (r
= 0; r
< 2; r
++) {
290 if (sp
->file
->struck
)
293 ready
= sp
->file
->readyR
;
294 guns
= sp
->specs
->gunR
;
295 car
= sp
->specs
->carR
;
297 ready
= sp
->file
->readyL
;
298 guns
= sp
->specs
->gunL
;
299 car
= sp
->specs
->carL
;
303 if ((ready
& R_LOADED
) == 0)
305 closest
= closestenemy(sp
, r
? 'r' : 'l', 0);
308 if (range(closest
, sp
) > range(sp
, closestenemy(sp
, r
? 'r' : 'l', 1)))
310 if (closest
->file
->struck
)
312 target
= range(sp
, closest
);
315 if (!guns
&& target
>= 3)
318 if (target
== 1 && sp
->file
->loadwith
== L_GRAPE
)
320 if (target
<= 3 && closest
->file
->FS
)
322 if (target
== 1 && load
!= L_GRAPE
)
324 if (load
> L_CHAIN
&& target
< 6)
328 rakehim
= gunsbear(sp
, closest
)
329 && !gunsbear(closest
, sp
);
330 temp
= portside(closest
, sp
, 1)
331 - closest
->file
->dir
+ 1;
336 sternrake
= temp
> 4 && temp
< 6;
340 index
= (index
- 1) / 3;
341 index
= index
> 8 ? 8 : index
;
343 hit
= HDT
[index
][target
-1];
345 hit
= HDTrake
[index
][target
-1];
346 if (rakehim
&& sternrake
)
348 hit
+= QUAL
[index
][capship(sp
)->specs
->qual
- 1];
349 for (n
= 0; n
< 3 && sp
->file
->captured
== 0; n
++)
355 if (ready
& R_INITIAL
) {
357 sp
->file
->readyL
&= ~R_INITIAL
;
359 sp
->file
->readyR
&= ~R_INITIAL
;
365 if (sp
->file
->captured
!= 0)
370 hit
+= AMMO
[index
][load
- 1];
371 temp
= sp
->specs
->class;
372 if ((temp
>= 5 || temp
== 1) && windspeed
== 5)
374 if (windspeed
== 6 && temp
== 4)
376 if (windspeed
== 6 && temp
<= 3)
380 hit
= hit
> 10 ? 10 : hit
;
381 table(shootat
, load
, hit
, closest
, sp
, die());
389 if (++turn
% 55 == 0)
394 if (people
<= 0 || windspeed
== 7) {
395 register struct ship
*s
;
396 struct ship
*bestship
;
397 float net
, best
= 0.0;
399 if (*s
->file
->captain
)
401 net
= (float)s
->file
->points
/ s
->specs
->pts
;
408 char *p
= getenv("WOTD");
413 (void) strncpy(bestship
->file
->captain
, p
,
414 sizeof bestship
->file
->captain
);
415 bestship
->file
->captain
416 [sizeof bestship
->file
->captain
- 1] = 0;
421 Write(W_TURN
, SHIP(0), 0, turn
, 0, 0, 0);
422 if (turn
% 7 == 0 && (die() >= cc
->windchange
|| !windspeed
)) {
459 Write(W_WIND
, SHIP(0), 0, winddir
, windspeed
, 0, 0);