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.2 2003/06/17 04:25:25 dillon Exp $
48 if (sp->file->captain[0])
50 nat = capship(sp)->nationality;
52 if (nat != capship(to)->nationality &&
53 !toughmelee(sp, to, 0, 0))
55 for (i = fouled2(sp, to); --i >= 0;)
68 if (*sp->file->captain)
70 if (sp->file->dir == 0)
72 if (sp->file->struck || sp->file->captured != 0)
76 crew[0] = sp->specs->crew1 != 0;
77 crew[1] = sp->specs->crew2 != 0;
78 crew[2] = sp->specs->crew3 != 0;
80 if (!Xsnagged2(sp, sq))
85 || sp->nationality == capship(sq)->nationality)
87 switch (sp->specs->class - sq->specs->class) {
88 case -3: case -4: case -5:
91 sendbp(sp, sq, crew[0]*100, 0);
95 sendbp(sp, sq, crew[1]*10, 0);
100 if (crew[0] || crew[1]) {
102 sendbp(sp, sq, crew[0]*100+crew[1]*10,
104 crew[0] = crew[1] = 0;
107 case -1: case 0: case 1:
110 sendbp(sp, sq, crew[0]*100+crew[1]*10,
112 crew[0] = crew[1] = 0;
115 case 2: case 3: case 4: case 5:
117 sendbp(sp, sq, crew[0]*100+crew[1]*10+crew[2],
119 crew[0] = crew[1] = crew[2] = 0;
126 fightitout(from, to, key)
127 struct ship *from, *to;
130 struct ship *fromcap, *tocap;
131 int crewfrom[3], crewto[3], menfrom, mento;
132 int pcto, pcfrom, fromstrength, strengthto, frominjured, toinjured;
134 int index, totalfrom = 0, totalto = 0;
138 menfrom = mensent(from, to, crewfrom, &fromcap, &pcfrom, key);
139 mento = mensent(to, from, crewto, &tocap, &pcto, 0);
145 if (!menfrom) { /* if crew surprised */
147 menfrom = from->specs->crew1
149 + from->specs->crew3;
151 menfrom = from->file->pcrew;
153 menfrom *= 2; /* DBP's fight at an advantage */
156 fromstrength = menfrom * fromcap->specs->qual;
157 strengthto = mento * tocap->specs->qual;
159 (fromstrength < strengthto * 3 && strengthto < fromstrength * 3
160 || fromstrength == -1) && count < 4;
162 index = fromstrength/10;
165 toinjured = MT[index][2 - die() / 3];
166 totalto += toinjured;
167 index = strengthto/10;
170 frominjured = MT[index][2 - die() / 3];
171 totalfrom += frominjured;
172 menfrom -= frominjured;
174 fromstrength = menfrom * fromcap->specs->qual;
175 strengthto = mento * tocap->specs->qual;
177 if (fromstrength >= strengthto * 3 || count == 4) {
178 unboard(to, from, 0);
179 subtract(from, totalfrom, crewfrom, fromcap, pcfrom);
180 subtract(to, totalto, crewto, tocap, pcto);
181 makesignal(from, "boarders from %s repelled", to);
182 (void) sprintf(message, "killed in melee: %d. %s: %d",
183 totalto, from->shipname, totalfrom);
184 Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);
187 } else if (strengthto >= fromstrength * 3) {
188 unboard(from, to, 0);
189 subtract(from, totalfrom, crewfrom, fromcap, pcfrom);
190 subtract(to, totalto, crewto, tocap, pcto);
193 Write(W_POINTS, fromcap, 0,
194 fromcap->file->points -
197 : 2 * from->specs->pts,
200 /* ptr1 points to the shipspec for the ship that was just unboarded.
201 I guess that what is going on here is that the pointer is multiplied
204 Write(W_CAPTURED, from, 0, to->file->index, 0, 0, 0);
205 topoints = 2 * from->specs->pts + to->file->points;
206 if (from->file->struck)
207 topoints -= from->specs->pts;
208 Write(W_POINTS, to, 0, topoints, 0, 0, 0);
209 mento = crewto[0] ? crewto[0] : crewto[1];
211 subtract(to, mento, crewto, tocap, pcto);
212 subtract(from, - mento, crewfrom, to, 0);
214 (void) sprintf(message, "captured by the %s!",
216 Write(W_SIGNAL, from, 1, (long) message, 0, 0, 0);
217 (void) sprintf(message, "killed in melee: %d. %s: %d",
218 totalto, from->shipname, totalfrom);
219 Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);
230 struct ship *sp, *sq;
233 if (sp->file->dir == 0)
235 for (sq = sp + 1; sq < ls; sq++)
236 if (sq->file->dir && meleeing(sp, sq) && meleeing(sq, sp))
237 (void) fightitout(sp, sq, 0);
240 if (sq->file->dir && meleeing(sq, sp))
241 thwart = fightitout(sp, sq, 1);
247 if (sq->file->dir && meleeing(sq, sp))
252 } else if (thwart == 2)
261 struct ship *closest;
262 int crew[3], men = 0, target, temp;
263 int r, guns, ready, load, car;
264 int index, rakehim, sternrake;
268 if (sp->file->captain[0] || sp->file->dir == 0)
270 crew[0] = sp->specs->crew1;
271 crew[1] = sp->specs->crew2;
272 crew[2] = sp->specs->crew3;
273 for (n = 0; n < 3; n++) {
274 if (sp->file->OBP[n].turnsent)
275 men += sp->file->OBP[n].mensent;
277 for (n = 0; n < 3; n++) {
278 if (sp->file->DBP[n].turnsent)
279 men += sp->file->DBP[n].mensent;
282 crew[0] = men/100 ? 0 : crew[0] != 0;
283 crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
284 crew[2] = men%10 ? 0 : crew[2] != 0;
286 for (r = 0; r < 2; r++) {
289 if (sp->file->struck)
292 ready = sp->file->readyR;
293 guns = sp->specs->gunR;
294 car = sp->specs->carR;
296 ready = sp->file->readyL;
297 guns = sp->specs->gunL;
298 car = sp->specs->carL;
302 if ((ready & R_LOADED) == 0)
304 closest = closestenemy(sp, r ? 'r' : 'l', 0);
307 if (range(closest, sp) > range(sp, closestenemy(sp, r ? 'r' : 'l', 1)))
309 if (closest->file->struck)
311 target = range(sp, closest);
314 if (!guns && target >= 3)
317 if (target == 1 && sp->file->loadwith == L_GRAPE)
319 if (target <= 3 && closest->file->FS)
321 if (target == 1 && load != L_GRAPE)
323 if (load > L_CHAIN && target < 6)
327 rakehim = gunsbear(sp, closest)
328 && !gunsbear(closest, sp);
329 temp = portside(closest, sp, 1)
330 - closest->file->dir + 1;
335 sternrake = temp > 4 && temp < 6;
339 index = (index - 1) / 3;
340 index = index > 8 ? 8 : index;
342 hit = HDT[index][target-1];
344 hit = HDTrake[index][target-1];
345 if (rakehim && sternrake)
347 hit += QUAL[index][capship(sp)->specs->qual - 1];
348 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) {
371 hit += AMMO[index][load - 1];
372 temp = sp->specs->class;
373 if ((temp >= 5 || temp == 1) && windspeed == 5)
375 if (windspeed == 6 && temp == 4)
377 if (windspeed == 6 && temp <= 3)
381 hit = hit > 10 ? 10 : hit;
382 table(shootat, load, hit, closest, sp, die());
390 if (++turn % 55 == 0) {
396 if (people <= 0 || windspeed == 7) {
398 struct ship *bestship;
399 float net, best = 0.0;
401 if (*s->file->captain)
403 net = (float)s->file->points / s->specs->pts;
410 char *p = getenv("WOTD");
415 (void) strncpy(bestship->file->captain, p,
416 sizeof bestship->file->captain);
417 bestship->file->captain
418 [sizeof bestship->file->captain - 1] = 0;
423 Write(W_TURN, SHIP(0), 0, turn, 0, 0, 0);
424 if (turn % 7 == 0 && (die() >= cc->windchange || !windspeed)) {
461 Write(W_WIND, SHIP(0), 0, winddir, windspeed, 0, 0);