|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: static char sccsid[] = "@(#)dr_1.c 5.4 (Berkeley) 6/1/90";
22: #endif /* not lint */
23:
24: #include "driver.h"
25:
26: unfoul()
27: {
28: register struct ship *sp;
29: struct ship *to;
30: register int nat;
31: register i;
32:
33: foreachship(sp) {
34: if (sp->file->captain[0])
35: continue;
36: nat = capship(sp)->nationality;
37: foreachship(to) {
38: if (nat != capship(to)->nationality &&
39: !toughmelee(sp, to, 0, 0))
40: continue;
41: for (i = fouled2(sp, to); --i >= 0;)
42: if (die() <= 2)
43: cleanfoul(sp, to, 0);
44: }
45: }
46: }
47:
48: boardcomp()
49: {
50: int crew[3];
51: register struct ship *sp, *sq;
52:
53: foreachship(sp) {
54: if (*sp->file->captain)
55: continue;
56: if (sp->file->dir == 0)
57: continue;
58: if (sp->file->struck || sp->file->captured != 0)
59: continue;
60: if (!snagged(sp))
61: continue;
62: crew[0] = sp->specs->crew1 != 0;
63: crew[1] = sp->specs->crew2 != 0;
64: crew[2] = sp->specs->crew3 != 0;
65: foreachship(sq) {
66: if (!Xsnagged2(sp, sq))
67: continue;
68: if (meleeing(sp, sq))
69: continue;
70: if (!sq->file->dir
71: || sp->nationality == capship(sq)->nationality)
72: continue;
73: switch (sp->specs->class - sq->specs->class) {
74: case -3: case -4: case -5:
75: if (crew[0]) {
76: /* OBP */
77: sendbp(sp, sq, crew[0]*100, 0);
78: crew[0] = 0;
79: } else if (crew[1]){
80: /* OBP */
81: sendbp(sp, sq, crew[1]*10, 0);
82: crew[1] = 0;
83: }
84: break;
85: case -2:
86: if (crew[0] || crew[1]) {
87: /* OBP */
88: sendbp(sp, sq, crew[0]*100+crew[1]*10,
89: 0);
90: crew[0] = crew[1] = 0;
91: }
92: break;
93: case -1: case 0: case 1:
94: if (crew[0]) {
95: /* OBP */
96: sendbp(sp, sq, crew[0]*100+crew[1]*10,
97: 0);
98: crew[0] = crew[1] = 0;
99: }
100: break;
101: case 2: case 3: case 4: case 5:
102: /* OBP */
103: sendbp(sp, sq, crew[0]*100+crew[1]*10+crew[2],
104: 0);
105: crew[0] = crew[1] = crew[2] = 0;
106: break;
107: }
108: }
109: }
110: }
111:
112: fightitout(from, to, key)
113: struct ship *from, *to;
114: int key;
115: {
116: struct ship *fromcap, *tocap;
117: int crewfrom[3], crewto[3], menfrom, mento;
118: int pcto, pcfrom, fromstrength, strengthto, frominjured, toinjured;
119: int topoints;
120: int index, totalfrom = 0, totalto = 0;
121: int count;
122: char message[60];
123:
124: menfrom = mensent(from, to, crewfrom, &fromcap, &pcfrom, key);
125: mento = mensent(to, from, crewto, &tocap, &pcto, 0);
126: if (fromcap == 0)
127: fromcap = from;
128: if (tocap == 0)
129: tocap = to;
130: if (key) {
131: if (!menfrom) { /* if crew surprised */
132: if (fromcap == from)
133: menfrom = from->specs->crew1
134: + from->specs->crew2
135: + from->specs->crew3;
136: else
137: menfrom = from->file->pcrew;
138: } else {
139: menfrom *= 2; /* DBP's fight at an advantage */
140: }
141: }
142: fromstrength = menfrom * fromcap->specs->qual;
143: strengthto = mento * tocap->specs->qual;
144: for (count = 0;
145: (fromstrength < strengthto * 3 && strengthto < fromstrength * 3
146: || fromstrength == -1) && count < 4;
147: count++) {
148: index = fromstrength/10;
149: if (index > 8)
150: index = 8;
151: toinjured = MT[index][2 - die() / 3];
152: totalto += toinjured;
153: index = strengthto/10;
154: if (index > 8)
155: index = 8;
156: frominjured = MT[index][2 - die() / 3];
157: totalfrom += frominjured;
158: menfrom -= frominjured;
159: mento -= toinjured;
160: fromstrength = menfrom * fromcap->specs->qual;
161: strengthto = mento * tocap->specs->qual;
162: }
163: if (fromstrength >= strengthto * 3 || count == 4) {
164: unboard(to, from, 0);
165: subtract(from, totalfrom, crewfrom, fromcap, pcfrom);
166: subtract(to, totalto, crewto, tocap, pcto);
167: makesignal(from, "boarders from %s repelled", to);
168: (void) sprintf(message, "killed in melee: %d. %s: %d",
169: totalto, from->shipname, totalfrom);
170: Write(W_SIGNAL, to, 1, (int) message, 0, 0, 0);
171: if (key)
172: return 1;
173: } else if (strengthto >= fromstrength * 3) {
174: unboard(from, to, 0);
175: subtract(from, totalfrom, crewfrom, fromcap, pcfrom);
176: subtract(to, totalto, crewto, tocap, pcto);
177: if (key) {
178: if (fromcap != from)
179: Write(W_POINTS, fromcap, 0,
180: fromcap->file->points -
181: from->file->struck
182: ? from->specs->pts
183: : 2 * from->specs->pts,
184: 0, 0, 0);
185:
186: /* ptr1 points to the shipspec for the ship that was just unboarded.
187: I guess that what is going on here is that the pointer is multiplied
188: or something. */
189:
190: Write(W_CAPTURED, from, 0, to->file->index, 0, 0, 0);
191: topoints = 2 * from->specs->pts + to->file->points;
192: if (from->file->struck)
193: topoints -= from->specs->pts;
194: Write(W_POINTS, to, 0, topoints, 0, 0, 0);
195: mento = crewto[0] ? crewto[0] : crewto[1];
196: if (mento) {
197: subtract(to, mento, crewto, tocap, pcto);
198: subtract(from, - mento, crewfrom, to, 0);
199: }
200: (void) sprintf(message, "captured by the %s!",
201: to->shipname);
202: Write(W_SIGNAL, from, 1, (int) message, 0, 0, 0);
203: (void) sprintf(message, "killed in melee: %d. %s: %d",
204: totalto, from->shipname, totalfrom);
205: Write(W_SIGNAL, to, 1, (int) message, 0, 0, 0);
206: mento = 0;
207: return 0;
208: }
209: }
210: return 0;
211: }
212:
213: resolve()
214: {
215: int thwart;
216: register struct ship *sp, *sq;
217:
218: foreachship(sp) {
219: if (sp->file->dir == 0)
220: continue;
221: for (sq = sp + 1; sq < ls; sq++)
222: if (sq->file->dir && meleeing(sp, sq) && meleeing(sq, sp))
223: (void) fightitout(sp, sq, 0);
224: thwart = 2;
225: foreachship(sq) {
226: if (sq->file->dir && meleeing(sq, sp))
227: thwart = fightitout(sp, sq, 1);
228: if (!thwart)
229: break;
230: }
231: if (!thwart) {
232: foreachship(sq) {
233: if (sq->file->dir && meleeing(sq, sp))
234: unboard(sq, sp, 0);
235: unboard(sp, sq, 0);
236: }
237: unboard(sp, sp, 1);
238: } else if (thwart == 2)
239: unboard(sp, sp, 1);
240: }
241: }
242:
243: compcombat()
244: {
245: register n;
246: register struct ship *sp;
247: struct ship *closest;
248: int crew[3], men = 0, target, temp;
249: int r, guns, ready, load, car;
250: int index, rakehim, sternrake;
251: int shootat, hit;
252:
253: foreachship(sp) {
254: if (sp->file->captain[0] || sp->file->dir == 0)
255: continue;
256: crew[0] = sp->specs->crew1;
257: crew[1] = sp->specs->crew2;
258: crew[2] = sp->specs->crew3;
259: for (n = 0; n < 3; n++) {
260: if (sp->file->OBP[n].turnsent)
261: men += sp->file->OBP[n].mensent;
262: }
263: for (n = 0; n < 3; n++) {
264: if (sp->file->DBP[n].turnsent)
265: men += sp->file->DBP[n].mensent;
266: }
267: if (men){
268: crew[0] = men/100 ? 0 : crew[0] != 0;
269: crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
270: crew[2] = men%10 ? 0 : crew[2] != 0;
271: }
272: for (r = 0; r < 2; r++) {
273: if (!crew[2])
274: continue;
275: if (sp->file->struck)
276: continue;
277: if (r) {
278: ready = sp->file->readyR;
279: guns = sp->specs->gunR;
280: car = sp->specs->carR;
281: } else {
282: ready = sp->file->readyL;
283: guns = sp->specs->gunL;
284: car = sp->specs->carL;
285: }
286: if (!guns && !car)
287: continue;
288: if ((ready & R_LOADED) == 0)
289: continue;
290: closest = closestenemy(sp, r ? 'r' : 'l', 0);
291: if (closest == 0)
292: continue;
293: if (range(closest, sp) > range(sp, closestenemy(sp, r ? 'r' : 'l', 1)))
294: continue;
295: if (closest->file->struck)
296: continue;
297: target = range(sp, closest);
298: if (target > 10)
299: continue;
300: if (!guns && target >= 3)
301: continue;
302: load = L_ROUND;
303: if (target == 1 && sp->file->loadwith == L_GRAPE)
304: load = L_GRAPE;
305: if (target <= 3 && closest->file->FS)
306: load = L_CHAIN;
307: if (target == 1 && load != L_GRAPE)
308: load = L_DOUBLE;
309: if (load > L_CHAIN && target < 6)
310: shootat = HULL;
311: else
312: shootat = RIGGING;
313: rakehim = gunsbear(sp, closest)
314: && !gunsbear(closest, sp);
315: temp = portside(closest, sp, 1)
316: - closest->file->dir + 1;
317: if (temp < 1)
318: temp += 8;
319: if (temp > 8)
320: temp -= 8;
321: sternrake = temp > 4 && temp < 6;
322: index = guns;
323: if (target < 3)
324: index += car;
325: index = (index - 1) / 3;
326: index = index > 8 ? 8 : index;
327: if (!rakehim)
328: hit = HDT[index][target-1];
329: else
330: hit = HDTrake[index][target-1];
331: if (rakehim && sternrake)
332: hit++;
333: hit += QUAL[index][capship(sp)->specs->qual - 1];
334: for (n = 0; n < 3 && sp->file->captured == 0; n++)
335: if (!crew[n])
336: if (index <= 5)
337: hit--;
338: else
339: hit -= 2;
340: if (ready & R_INITIAL) {
341: if (!r)
342: sp->file->readyL &= ~R_INITIAL;
343: else
344: sp->file->readyR &= ~R_INITIAL;
345: if (index <= 3)
346: hit++;
347: else
348: hit += 2;
349: }
350: if (sp->file->captured != 0)
351: if (index <= 1)
352: hit--;
353: else
354: hit -= 2;
355: hit += AMMO[index][load - 1];
356: temp = sp->specs->class;
357: if ((temp >= 5 || temp == 1) && windspeed == 5)
358: hit--;
359: if (windspeed == 6 && temp == 4)
360: hit -= 2;
361: if (windspeed == 6 && temp <= 3)
362: hit--;
363: if (hit >= 0) {
364: if (load != L_GRAPE)
365: hit = hit > 10 ? 10 : hit;
366: table(shootat, load, hit, closest, sp, die());
367: }
368: }
369: }
370: }
371:
372: next()
373: {
374: if (++turn % 55 == 0)
375: if (alive)
376: alive = 0;
377: else
378: people = 0;
379: if (people <= 0 || windspeed == 7) {
380: register struct ship *s;
381: struct ship *bestship;
382: float net, best = 0.0;
383: foreachship(s) {
384: if (*s->file->captain)
385: continue;
386: net = (float)s->file->points / s->specs->pts;
387: if (net > best) {
388: best = net;
389: bestship = s;
390: }
391: }
392: if (best > 0.0) {
393: char *p = getenv("WOTD");
394: if (p == 0)
395: p = "Driver";
396: if (islower(*p))
397: *p = toupper(*p);
398: (void) strncpy(bestship->file->captain, p,
399: sizeof bestship->file->captain);
400: bestship->file->captain
401: [sizeof bestship->file->captain - 1] = 0;
402: log(bestship);
403: }
404: return -1;
405: }
406: Write(W_TURN, SHIP(0), 0, turn, 0, 0, 0);
407: if (turn % 7 == 0 && (die() >= cc->windchange || !windspeed)) {
408: switch (die()) {
409: case 1:
410: winddir = 1;
411: break;
412: case 2:
413: break;
414: case 3:
415: winddir++;
416: break;
417: case 4:
418: winddir--;
419: break;
420: case 5:
421: winddir += 2;
422: break;
423: case 6:
424: winddir -= 2;
425: break;
426: }
427: if (winddir > 8)
428: winddir -= 8;
429: if (winddir < 1)
430: winddir += 8;
431: if (windspeed)
432: switch (die()) {
433: case 1:
434: case 2:
435: windspeed--;
436: break;
437: case 5:
438: case 6:
439: windspeed++;
440: break;
441: }
442: else
443: windspeed++;
444: Write(W_WIND, SHIP(0), 0, winddir, windspeed, 0, 0);
445: }
446: return 0;
447: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.