2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
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
37 static char sccsid[] = "@(#)dr_1.c 8.1 (Berkeley) 5/31/93";
44 register struct ship *sp;
50 if (sp->file->captain[0])
52 nat = capship(sp)->nationality;
54 if (nat != capship(to)->nationality &&
55 !toughmelee(sp, to, 0, 0))
57 for (i = fouled2(sp, to); --i >= 0;)
67 register struct ship *sp, *sq;
70 if (*sp->file->captain)
72 if (sp->file->dir == 0)
74 if (sp->file->struck || sp->file->captured != 0)
78 crew[0] = sp->specs->crew1 != 0;
79 crew[1] = sp->specs->crew2 != 0;
80 crew[2] = sp->specs->crew3 != 0;
82 if (!Xsnagged2(sp, sq))
87 || sp->nationality == capship(sq)->nationality)
89 switch (sp->specs->class - sq->specs->class) {
90 case -3: case -4: case -5:
93 sendbp(sp, sq, crew[0]*100, 0);
97 sendbp(sp, sq, crew[1]*10, 0);
102 if (crew[0] || crew[1]) {
104 sendbp(sp, sq, crew[0]*100+crew[1]*10,
106 crew[0] = crew[1] = 0;
109 case -1: case 0: case 1:
112 sendbp(sp, sq, crew[0]*100+crew[1]*10,
114 crew[0] = crew[1] = 0;
117 case 2: case 3: case 4: case 5:
119 sendbp(sp, sq, crew[0]*100+crew[1]*10+crew[2],
121 crew[0] = crew[1] = crew[2] = 0;
128 fightitout(from, to, key)
129 struct ship *from, *to;
132 struct ship *fromcap, *tocap;
133 int crewfrom[3], crewto[3], menfrom, mento;
134 int pcto, pcfrom, fromstrength, strengthto, frominjured, toinjured;
136 int index, totalfrom = 0, totalto = 0;
140 menfrom = mensent(from, to, crewfrom, &fromcap, &pcfrom, key);
141 mento = mensent(to, from, crewto, &tocap, &pcto, 0);
147 if (!menfrom) { /* if crew surprised */
149 menfrom = from->specs->crew1
151 + from->specs->crew3;
153 menfrom = from->file->pcrew;
155 menfrom *= 2; /* DBP's fight at an advantage */
158 fromstrength = menfrom * fromcap->specs->qual;
159 strengthto = mento * tocap->specs->qual;
161 (fromstrength < strengthto * 3 && strengthto < fromstrength * 3
162 || fromstrength == -1) && count < 4;
164 index = fromstrength/10;
167 toinjured = MT[index][2 - die() / 3];
168 totalto += toinjured;
169 index = strengthto/10;
172 frominjured = MT[index][2 - die() / 3];
173 totalfrom += frominjured;
174 menfrom -= frominjured;
176 fromstrength = menfrom * fromcap->specs->qual;
177 strengthto = mento * tocap->specs->qual;
179 if (fromstrength >= strengthto * 3 || count == 4) {
180 unboard(to, from, 0);
181 subtract(from, totalfrom, crewfrom, fromcap, pcfrom);
182 subtract(to, totalto, crewto, tocap, pcto);
183 makesignal(from, "boarders from %s repelled", to);
184 (void) sprintf(message, "killed in melee: %d. %s: %d",
185 totalto, from->shipname, totalfrom);
186 Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);
189 } else if (strengthto >= fromstrength * 3) {
190 unboard(from, to, 0);
191 subtract(from, totalfrom, crewfrom, fromcap, pcfrom);
192 subtract(to, totalto, crewto, tocap, pcto);
195 Write(W_POINTS, fromcap, 0,
196 fromcap->file->points -
199 : 2 * from->specs->pts,
202 /* ptr1 points to the shipspec for the ship that was just unboarded.
203 I guess that what is going on here is that the pointer is multiplied
206 Write(W_CAPTURED, from, 0, to->file->index, 0, 0, 0);
207 topoints = 2 * from->specs->pts + to->file->points;
208 if (from->file->struck)
209 topoints -= from->specs->pts;
210 Write(W_POINTS, to, 0, topoints, 0, 0, 0);
211 mento = crewto[0] ? crewto[0] : crewto[1];
213 subtract(to, mento, crewto, tocap, pcto);
214 subtract(from, - mento, crewfrom, to, 0);
216 (void) sprintf(message, "captured by the %s!",
218 Write(W_SIGNAL, from, 1, (long) message, 0, 0, 0);
219 (void) sprintf(message, "killed in melee: %d. %s: %d",
220 totalto, from->shipname, totalfrom);
221 Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);
232 register struct ship *sp, *sq;
235 if (sp->file->dir == 0)
237 for (sq = sp + 1; sq < ls; sq++)
238 if (sq->file->dir && meleeing(sp, sq) && meleeing(sq, sp))
239 (void) fightitout(sp, sq, 0);
242 if (sq->file->dir && meleeing(sq, sp))
243 thwart = fightitout(sp, sq, 1);
249 if (sq->file->dir && meleeing(sq, sp))
254 } else if (thwart == 2)
262 register struct ship *sp;
263 struct ship *closest;
264 int crew[3], men = 0, target, temp;
265 int r, guns, ready, load, car;
266 int index, rakehim, sternrake;
270 if (sp->file->captain[0] || sp->file->dir == 0)
272 crew[0] = sp->specs->crew1;
273 crew[1] = sp->specs->crew2;
274 crew[2] = sp->specs->crew3;
275 for (n = 0; n < 3; n++) {
276 if (sp->file->OBP[n].turnsent)
277 men += sp->file->OBP[n].mensent;
279 for (n = 0; n < 3; n++) {
280 if (sp->file->DBP[n].turnsent)
281 men += sp->file->DBP[n].mensent;
284 crew[0] = men/100 ? 0 : crew[0] != 0;
285 crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
286 crew[2] = men%10 ? 0 : crew[2] != 0;
288 for (r = 0; r < 2; r++) {
291 if (sp->file->struck)
294 ready = sp->file->readyR;
295 guns = sp->specs->gunR;
296 car = sp->specs->carR;
298 ready = sp->file->readyL;
299 guns = sp->specs->gunL;
300 car = sp->specs->carL;
304 if ((ready & R_LOADED) == 0)
306 closest = closestenemy(sp, r ? 'r' : 'l', 0);
309 if (range(closest, sp) > range(sp, closestenemy(sp, r ? 'r' : 'l', 1)))
311 if (closest->file->struck)
313 target = range(sp, closest);
316 if (!guns && target >= 3)
319 if (target == 1 && sp->file->loadwith == L_GRAPE)
321 if (target <= 3 && closest->file->FS)
323 if (target == 1 && load != L_GRAPE)
325 if (load > L_CHAIN && target < 6)
329 rakehim = gunsbear(sp, closest)
330 && !gunsbear(closest, sp);
331 temp = portside(closest, sp, 1)
332 - closest->file->dir + 1;
337 sternrake = temp > 4 && temp < 6;
341 index = (index - 1) / 3;
342 index = index > 8 ? 8 : index;
344 hit = HDT[index][target-1];
346 hit = HDTrake[index][target-1];
347 if (rakehim && sternrake)
349 hit += QUAL[index][capship(sp)->specs->qual - 1];
350 for (n = 0; n < 3 && sp->file->captured == 0; n++)
357 if (ready & R_INITIAL) {
359 sp->file->readyL &= ~R_INITIAL;
361 sp->file->readyR &= ~R_INITIAL;
367 if (sp->file->captured != 0) {
373 hit += AMMO[index][load - 1];
374 temp = sp->specs->class;
375 if ((temp >= 5 || temp == 1) && windspeed == 5)
377 if (windspeed == 6 && temp == 4)
379 if (windspeed == 6 && temp <= 3)
383 hit = hit > 10 ? 10 : hit;
384 table(shootat, load, hit, closest, sp, die());
392 if (++turn % 55 == 0) {
398 if (people <= 0 || windspeed == 7) {
399 register struct ship *s;
400 struct ship *bestship;
401 float net, best = 0.0;
403 if (*s->file->captain)
405 net = (float)s->file->points / s->specs->pts;
412 char *p = getenv("WOTD");
417 (void) strncpy(bestship->file->captain, p,
418 sizeof bestship->file->captain);
419 bestship->file->captain
420 [sizeof bestship->file->captain - 1] = 0;
425 Write(W_TURN, SHIP(0), 0, turn, 0, 0, 0);
426 if (turn % 7 == 0 && (die() >= cc->windchange || !windspeed)) {
463 Write(W_WIND, SHIP(0), 0, winddir, windspeed, 0, 0);