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
36 static char sccsid[] = "@(#)dr_1.c 8.1 (Berkeley) 5/31/93";
38 static const char rcsid[] =
52 if (sp->file->captain[0])
54 nat = capship(sp)->nationality;
56 if (nat != capship(to)->nationality &&
57 !toughmelee(sp, to, 0, 0))
59 for (i = fouled2(sp, to); --i >= 0;)
72 if (*sp->file->captain)
74 if (sp->file->dir == 0)
76 if (sp->file->struck || sp->file->captured != 0)
80 crew[0] = sp->specs->crew1 != 0;
81 crew[1] = sp->specs->crew2 != 0;
82 crew[2] = sp->specs->crew3 != 0;
84 if (!Xsnagged2(sp, sq))
89 || sp->nationality == capship(sq)->nationality)
91 switch (sp->specs->class - sq->specs->class) {
92 case -3: case -4: case -5:
95 sendbp(sp, sq, crew[0]*100, 0);
99 sendbp(sp, sq, crew[1]*10, 0);
104 if (crew[0] || crew[1]) {
106 sendbp(sp, sq, crew[0]*100+crew[1]*10,
108 crew[0] = crew[1] = 0;
111 case -1: case 0: case 1:
114 sendbp(sp, sq, crew[0]*100+crew[1]*10,
116 crew[0] = crew[1] = 0;
119 case 2: case 3: case 4: case 5:
121 sendbp(sp, sq, crew[0]*100+crew[1]*10+crew[2],
123 crew[0] = crew[1] = crew[2] = 0;
130 fightitout(from, to, key)
131 struct ship *from, *to;
134 struct ship *fromcap, *tocap;
135 int crewfrom[3], crewto[3], menfrom, mento;
136 int pcto, pcfrom, fromstrength, strengthto, frominjured, toinjured;
138 int index, totalfrom = 0, totalto = 0;
142 menfrom = mensent(from, to, crewfrom, &fromcap, &pcfrom, key);
143 mento = mensent(to, from, crewto, &tocap, &pcto, 0);
149 if (!menfrom) { /* if crew surprised */
151 menfrom = from->specs->crew1
153 + from->specs->crew3;
155 menfrom = from->file->pcrew;
157 menfrom *= 2; /* DBP's fight at an advantage */
160 fromstrength = menfrom * fromcap->specs->qual;
161 strengthto = mento * tocap->specs->qual;
163 (fromstrength < strengthto * 3 && strengthto < fromstrength * 3
164 || fromstrength == -1) && count < 4;
166 index = fromstrength/10;
169 toinjured = MT[index][2 - die() / 3];
170 totalto += toinjured;
171 index = strengthto/10;
174 frominjured = MT[index][2 - die() / 3];
175 totalfrom += frominjured;
176 menfrom -= frominjured;
178 fromstrength = menfrom * fromcap->specs->qual;
179 strengthto = mento * tocap->specs->qual;
181 if (fromstrength >= strengthto * 3 || count == 4) {
182 unboard(to, from, 0);
183 subtract(from, totalfrom, crewfrom, fromcap, pcfrom);
184 subtract(to, totalto, crewto, tocap, pcto);
185 makesignal(from, "boarders from %s repelled", to);
186 (void) sprintf(message, "killed in melee: %d. %s: %d",
187 totalto, from->shipname, totalfrom);
188 Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);
191 } else if (strengthto >= fromstrength * 3) {
192 unboard(from, to, 0);
193 subtract(from, totalfrom, crewfrom, fromcap, pcfrom);
194 subtract(to, totalto, crewto, tocap, pcto);
197 Write(W_POINTS, fromcap, 0,
198 fromcap->file->points -
201 : 2 * from->specs->pts,
204 /* ptr1 points to the shipspec for the ship that was just unboarded.
205 I guess that what is going on here is that the pointer is multiplied
208 Write(W_CAPTURED, from, 0, to->file->index, 0, 0, 0);
209 topoints = 2 * from->specs->pts + to->file->points;
210 if (from->file->struck)
211 topoints -= from->specs->pts;
212 Write(W_POINTS, to, 0, topoints, 0, 0, 0);
213 mento = crewto[0] ? crewto[0] : crewto[1];
215 subtract(to, mento, crewto, tocap, pcto);
216 subtract(from, - mento, crewfrom, to, 0);
218 (void) sprintf(message, "captured by the %s!",
220 Write(W_SIGNAL, from, 1, (long) message, 0, 0, 0);
221 (void) sprintf(message, "killed in melee: %d. %s: %d",
222 totalto, from->shipname, totalfrom);
223 Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);
234 struct ship *sp, *sq;
237 if (sp->file->dir == 0)
239 for (sq = sp + 1; sq < ls; sq++)
240 if (sq->file->dir && meleeing(sp, sq) && meleeing(sq, sp))
241 (void) fightitout(sp, sq, 0);
244 if (sq->file->dir && meleeing(sq, sp))
245 thwart = fightitout(sp, sq, 1);
251 if (sq->file->dir && meleeing(sq, sp))
256 } else if (thwart == 2)
265 struct ship *closest;
266 int crew[3], men = 0, target, temp;
267 int r, guns, ready, load, car;
268 int index, rakehim, sternrake;
272 if (sp->file->captain[0] || sp->file->dir == 0)
274 crew[0] = sp->specs->crew1;
275 crew[1] = sp->specs->crew2;
276 crew[2] = sp->specs->crew3;
277 for (n = 0; n < 3; n++) {
278 if (sp->file->OBP[n].turnsent)
279 men += sp->file->OBP[n].mensent;
281 for (n = 0; n < 3; n++) {
282 if (sp->file->DBP[n].turnsent)
283 men += sp->file->DBP[n].mensent;
286 crew[0] = men/100 ? 0 : crew[0] != 0;
287 crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
288 crew[2] = men%10 ? 0 : crew[2] != 0;
290 for (r = 0; r < 2; r++) {
293 if (sp->file->struck)
296 ready = sp->file->readyR;
297 guns = sp->specs->gunR;
298 car = sp->specs->carR;
300 ready = sp->file->readyL;
301 guns = sp->specs->gunL;
302 car = sp->specs->carL;
306 if ((ready & R_LOADED) == 0)
308 closest = closestenemy(sp, r ? 'r' : 'l', 0);
311 if (range(closest, sp) > range(sp, closestenemy(sp, r ? 'r' : 'l', 1)))
313 if (closest->file->struck)
315 target = range(sp, closest);
318 if (!guns && target >= 3)
321 if (target == 1 && sp->file->loadwith == L_GRAPE)
323 if (target <= 3 && closest->file->FS)
325 if (target == 1 && load != L_GRAPE)
327 if (load > L_CHAIN && target < 6)
331 rakehim = gunsbear(sp, closest)
332 && !gunsbear(closest, sp);
333 temp = portside(closest, sp, 1)
334 - closest->file->dir + 1;
339 sternrake = temp > 4 && temp < 6;
343 index = (index - 1) / 3;
344 index = index > 8 ? 8 : index;
346 hit = HDT[index][target-1];
348 hit = HDTrake[index][target-1];
349 if (rakehim && sternrake)
351 hit += QUAL[index][capship(sp)->specs->qual - 1];
352 for (n = 0; n < 3 && sp->file->captured == 0; n++)
359 if (ready & R_INITIAL) {
361 sp->file->readyL &= ~R_INITIAL;
363 sp->file->readyR &= ~R_INITIAL;
369 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) {
400 if (people <= 0 || windspeed == 7) {
402 struct ship *bestship;
403 float net, best = 0.0;
405 if (*s->file->captain)
407 net = (float)s->file->points / s->specs->pts;
414 char *p = getenv("WOTD");
419 (void) strncpy(bestship->file->captain, p,
420 sizeof bestship->file->captain);
421 bestship->file->captain
422 [sizeof bestship->file->captain - 1] = 0;
427 Write(W_TURN, SHIP(0), 0, turn, 0, 0, 0);
428 if (turn % 7 == 0 && (die() >= cc->windchange || !windspeed)) {
465 Write(W_WIND, SHIP(0), 0, winddir, windspeed, 0, 0);