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
33 * @(#)dr_1.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/sail/dr_1.c,v 1.7 1999/11/30 03:49:32 billf Exp $
35 * $DragonFly: src/games/sail/dr_1.c,v 1.4 2006/09/03 17:33:13 pavalos Exp $
40 static int fightitout(struct ship *, struct ship *, int);
51 if (sp->file->captain[0])
53 nat = capship(sp)->nationality;
55 if (nat != capship(to)->nationality &&
56 !toughmelee(sp, to, 0, 0))
58 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;
131 fightitout(struct ship *from, struct ship *to, int key)
133 struct ship *fromcap, *tocap;
134 int crewfrom[3], crewto[3], menfrom, mento;
135 int pcto, pcfrom, fromstrength, strengthto, frominjured, toinjured;
137 int idx, totalfrom = 0, totalto = 0;
141 menfrom = mensent(from, to, crewfrom, &fromcap, &pcfrom, key);
142 mento = mensent(to, from, crewto, &tocap, &pcto, 0);
148 if (!menfrom) { /* if crew surprised */
150 menfrom = from->specs->crew1
152 + from->specs->crew3;
154 menfrom = from->file->pcrew;
156 menfrom *= 2; /* DBP's fight at an advantage */
159 fromstrength = menfrom * fromcap->specs->qual;
160 strengthto = mento * tocap->specs->qual;
162 ((fromstrength < strengthto * 3 && strengthto < fromstrength * 3)
163 || fromstrength == -1) && count < 4;
165 idx = fromstrength/10;
168 toinjured = MT[idx][2 - die() / 3];
169 totalto += toinjured;
173 frominjured = MT[idx][2 - die() / 3];
174 totalfrom += frominjured;
175 menfrom -= frominjured;
177 fromstrength = menfrom * fromcap->specs->qual;
178 strengthto = mento * tocap->specs->qual;
180 if (fromstrength >= strengthto * 3 || count == 4) {
181 unboard(to, from, 0);
182 subtract(from, totalfrom, crewfrom, fromcap, pcfrom);
183 subtract(to, totalto, crewto, tocap, pcto);
184 makesignal(from, "boarders from %s repelled", to);
185 sprintf(message, "killed in melee: %d. %s: %d",
186 totalto, from->shipname, totalfrom);
187 Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);
190 } else if (strengthto >= fromstrength * 3) {
191 unboard(from, to, 0);
192 subtract(from, totalfrom, crewfrom, fromcap, pcfrom);
193 subtract(to, totalto, crewto, tocap, pcto);
196 Write(W_POINTS, fromcap, 0,
197 fromcap->file->points -
200 : 2 * from->specs->pts,
203 /* ptr1 points to the shipspec for the ship that was just unboarded.
204 I guess that what is going on here is that the pointer is multiplied
207 Write(W_CAPTURED, from, 0, to->file->index, 0, 0, 0);
208 topoints = 2 * from->specs->pts + to->file->points;
209 if (from->file->struck)
210 topoints -= from->specs->pts;
211 Write(W_POINTS, to, 0, topoints, 0, 0, 0);
212 mento = crewto[0] ? crewto[0] : crewto[1];
214 subtract(to, mento, crewto, tocap, pcto);
215 subtract(from, - mento, crewfrom, to, 0);
217 sprintf(message, "captured by the %s!",
219 Write(W_SIGNAL, from, 1, (long) message, 0, 0, 0);
220 sprintf(message, "killed in melee: %d. %s: %d",
221 totalto, from->shipname, totalfrom);
222 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 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)
266 struct ship *closest;
267 int crew[3], men = 0, target, temp;
268 int r, guns, ready, load, car;
269 int idx, rakehim, sternrake;
273 if (sp->file->captain[0] || sp->file->dir == 0)
275 crew[0] = sp->specs->crew1;
276 crew[1] = sp->specs->crew2;
277 crew[2] = sp->specs->crew3;
278 for (n = 0; n < 3; n++) {
279 if (sp->file->OBP[n].turnsent)
280 men += sp->file->OBP[n].mensent;
282 for (n = 0; n < 3; n++) {
283 if (sp->file->DBP[n].turnsent)
284 men += sp->file->DBP[n].mensent;
287 crew[0] = men/100 ? 0 : crew[0] != 0;
288 crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
289 crew[2] = men%10 ? 0 : crew[2] != 0;
291 for (r = 0; r < 2; r++) {
294 if (sp->file->struck)
297 ready = sp->file->readyR;
298 guns = sp->specs->gunR;
299 car = sp->specs->carR;
301 ready = sp->file->readyL;
302 guns = sp->specs->gunL;
303 car = sp->specs->carL;
307 if ((ready & R_LOADED) == 0)
309 closest = closestenemy(sp, r ? 'r' : 'l', 0);
312 if (range(closest, sp) > range(sp, closestenemy(sp, r ? 'r' : 'l', 1)))
314 if (closest->file->struck)
316 target = range(sp, closest);
319 if (!guns && target >= 3)
322 if (target == 1 && sp->file->loadwith == L_GRAPE)
324 if (target <= 3 && closest->file->FS)
326 if (target == 1 && load != L_GRAPE)
328 if (load > L_CHAIN && target < 6)
332 rakehim = gunsbear(sp, closest)
333 && !gunsbear(closest, sp);
334 temp = portside(closest, sp, 1)
335 - closest->file->dir + 1;
340 sternrake = temp > 4 && temp < 6;
345 idx = idx > 8 ? 8 : idx;
347 hit = HDT[idx][target-1];
349 hit = HDTrake[idx][target-1];
350 if (rakehim && sternrake)
352 hit += QUAL[idx][capship(sp)->specs->qual - 1];
353 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) {
376 hit += AMMO[idx][load - 1];
377 temp = sp->specs->class;
378 if ((temp >= 5 || temp == 1) && windspeed == 5)
380 if (windspeed == 6 && temp == 4)
382 if (windspeed == 6 && temp <= 3)
386 hit = hit > 10 ? 10 : hit;
387 table(shootat, load, hit, closest, sp, die());
396 if (++turn % 55 == 0) {
402 if (people <= 0 || windspeed == 7) {
404 struct ship *bestship = NULL;
405 float net, best = 0.0;
407 if (*s->file->captain)
409 net = (float)s->file->points / s->specs->pts;
416 char *p = getenv("WOTD");
418 char buf[6] = "Driver";
423 strncpy(bestship->file->captain, p,
424 sizeof bestship->file->captain);
425 bestship->file->captain
426 [sizeof bestship->file->captain - 1] = 0;
431 Write(W_TURN, SHIP(0), 0, turn, 0, 0, 0);
432 if (turn % 7 == 0 && (die() >= cc->windchange || !windspeed)) {
469 Write(W_WIND, SHIP(0), 0, winddir, windspeed, 0, 0);