|
|
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_2.c 5.4 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: #include "driver.h" ! 25: ! 26: #define couldwin(f,t) (f->specs->crew2 > t->specs->crew2 * 1.5) ! 27: ! 28: thinkofgrapples() ! 29: { ! 30: register struct ship *sp, *sq; ! 31: char friendly; ! 32: ! 33: foreachship(sp) { ! 34: if (sp->file->captain[0] || sp->file->dir == 0) ! 35: continue; ! 36: foreachship(sq) { ! 37: friendly = sp->nationality == capship(sq)->nationality; ! 38: if (!friendly) { ! 39: if (sp->file->struck || sp->file->captured != 0) ! 40: continue; ! 41: if (range(sp, sq) != 1) ! 42: continue; ! 43: if (grappled2(sp, sq)) ! 44: if (toughmelee(sp, sq, 0, 0)) ! 45: ungrap(sp, sq); ! 46: else ! 47: grap(sp, sq); ! 48: else if (couldwin(sp, sq)) { ! 49: grap(sp, sq); ! 50: sp->file->loadwith = L_GRAPE; ! 51: } ! 52: } else ! 53: ungrap(sp, sq); ! 54: } ! 55: } ! 56: } ! 57: ! 58: checkup() ! 59: { ! 60: register struct ship *sp, *sq; ! 61: register char explode, sink; ! 62: ! 63: foreachship(sp) { ! 64: if (sp->file->dir == 0) ! 65: continue; ! 66: explode = sp->file->explode; ! 67: sink = sp->file->sink; ! 68: if (explode != 1 && sink != 1) ! 69: continue; ! 70: if (die() < 5) ! 71: continue; ! 72: Write(sink == 1 ? W_SINK : W_EXPLODE, sp, 0, 2, 0, 0, 0); ! 73: Write(W_DIR, sp, 0, 0, 0, 0, 0); ! 74: if (snagged(sp)) ! 75: foreachship(sq) ! 76: cleansnag(sp, sq, 1); ! 77: if (sink != 1) { ! 78: makesignal(sp, "exploding!", (struct ship *)0); ! 79: foreachship(sq) { ! 80: if (sp != sq && sq->file->dir && range(sp, sq) < 4) ! 81: table(RIGGING, L_EXPLODE, sp->specs->guns/13, sq, sp, 6); ! 82: } ! 83: } else ! 84: makesignal(sp, "sinking!", (struct ship *)0); ! 85: } ! 86: } ! 87: ! 88: prizecheck() ! 89: { ! 90: register struct ship *sp; ! 91: ! 92: foreachship(sp) { ! 93: if (sp->file->captured == 0) ! 94: continue; ! 95: if (sp->file->struck || sp->file->dir == 0) ! 96: continue; ! 97: if (sp->specs->crew1 + sp->specs->crew2 + sp->specs->crew3 > sp->file->pcrew * 6) { ! 98: Write(W_SIGNAL, sp, 1, ! 99: (int)"prize crew overthrown", 0, 0, 0); ! 100: Write(W_POINTS, sp->file->captured, 0, sp->file->captured->file->points - 2 * sp->specs->pts, 0, 0, 0); ! 101: Write(W_CAPTURED, sp, 0, -1, 0, 0, 0); ! 102: } ! 103: } ! 104: } ! 105: ! 106: strend(str) ! 107: char *str; ! 108: { ! 109: register char *p; ! 110: ! 111: for (p = str; *p; p++) ! 112: ; ! 113: return p == str ? 0 : p[-1]; ! 114: } ! 115: ! 116: closeon(from, to, command, ta, ma, af) ! 117: register struct ship *from, *to; ! 118: char command[]; ! 119: int ma, ta, af; ! 120: { ! 121: int high; ! 122: char temp[10]; ! 123: ! 124: temp[0] = command[0] = '\0'; ! 125: high = -30000; ! 126: try(command, temp, ma, ta, af, ma, from->file->dir, from, to, &high, 0); ! 127: } ! 128: ! 129: int dtab[] = {0,1,1,2,3,4,4,5}; /* diagonal distances in x==y */ ! 130: ! 131: score(movement, ship, to, onlytemp) ! 132: char movement[]; ! 133: register struct ship *ship, *to; ! 134: char onlytemp; ! 135: { ! 136: char drift; ! 137: int row, col, dir, total, ran; ! 138: register struct File *fp = ship->file; ! 139: ! 140: if ((dir = fp->dir) == 0) ! 141: return 0; ! 142: row = fp->row; ! 143: col = fp->col; ! 144: drift = fp->drift; ! 145: move(movement, ship, &fp->dir, &fp->row, &fp->col, &drift); ! 146: if (!*movement) ! 147: (void) strcpy(movement, "d"); ! 148: ! 149: ran = range(ship, to); ! 150: total = -50 * ran; ! 151: if (ran < 4 && gunsbear(ship, to)) ! 152: total += 60; ! 153: if ((ran = portside(ship, to, 1) - fp->dir) == 4 || ran == -4) ! 154: total = -30000; ! 155: ! 156: if (!onlytemp) { ! 157: fp->row = row; ! 158: fp->col = col; ! 159: fp->dir = dir; ! 160: } ! 161: return total; ! 162: } ! 163: ! 164: move(p, ship, dir, row, col, drift) ! 165: register char *p; ! 166: register struct ship *ship; ! 167: register char *dir; ! 168: register short *row, *col; ! 169: register char *drift; ! 170: { ! 171: int dist; ! 172: char moved = 0; ! 173: ! 174: for (; *p; p++) { ! 175: switch (*p) { ! 176: case 'r': ! 177: if (++*dir == 9) ! 178: *dir = 1; ! 179: break; ! 180: case 'l': ! 181: if (--*dir == 0) ! 182: *dir = 8; ! 183: break; ! 184: case '1': case '2': case '3': case '4': ! 185: case '5': case '6': case '7': ! 186: moved++; ! 187: if (*dir % 2 == 0) ! 188: dist = dtab[*p - '0']; ! 189: else ! 190: dist = *p - '0'; ! 191: *row -= dr[*dir] * dist; ! 192: *col -= dc[*dir] * dist; ! 193: break; ! 194: } ! 195: } ! 196: if (!moved) { ! 197: if (windspeed != 0 && ++*drift > 2) { ! 198: if (ship->specs->class >= 3 && !snagged(ship) ! 199: || (turn & 1) == 0) { ! 200: *row -= dr[winddir]; ! 201: *col -= dc[winddir]; ! 202: } ! 203: } ! 204: } else ! 205: *drift = 0; ! 206: } ! 207: ! 208: try(command, temp, ma, ta, af, vma, dir, f, t, high, rakeme) ! 209: register struct ship *f, *t; ! 210: int ma, ta, af, *high, rakeme; ! 211: char command[], temp[]; ! 212: { ! 213: register int new, n; ! 214: char st[4]; ! 215: #define rakeyou (gunsbear(f, t) && !gunsbear(t, f)) ! 216: ! 217: if ((n = strend(temp)) < '1' || n > '9') ! 218: for (n = 1; vma - n >= 0; n++) { ! 219: (void) sprintf(st, "%d", n); ! 220: (void) strcat(temp, st); ! 221: new = score(temp, f, t, rakeme); ! 222: if (new > *high && (!rakeme || rakeyou)) { ! 223: *high = new; ! 224: (void) strcpy(command, temp); ! 225: } ! 226: try(command, temp, ma-n, ta, af, vma-n, ! 227: dir, f, t, high, rakeme); ! 228: rmend(temp); ! 229: } ! 230: if (ma > 0 && ta > 0 && (n = strend(temp)) != 'l' && n != 'r' || !strlen(temp)) { ! 231: (void) strcat(temp, "r"); ! 232: new = score(temp, f, t, rakeme); ! 233: if (new > *high && (!rakeme || gunsbear(f, t) && !gunsbear(t, f))) { ! 234: *high = new; ! 235: (void) strcpy(command, temp); ! 236: } ! 237: try(command, temp, ma-1, ta-1, af, min(ma-1, maxmove(f, (dir == 8 ? 1 : dir+1), 0)), (dir == 8 ? 1 : dir+1),f,t,high,rakeme); ! 238: rmend(temp); ! 239: } ! 240: if ((ma > 0 && ta > 0 && (n = strend(temp)) != 'l' && n != 'r') || !strlen(temp)){ ! 241: (void) strcat(temp, "l"); ! 242: new = score(temp, f, t, rakeme); ! 243: if (new > *high && (!rakeme || (gunsbear(f, t) && !gunsbear(t, f)))){ ! 244: *high = new; ! 245: (void) strcpy(command, temp); ! 246: } ! 247: try(command, temp, ma-1, ta-1, af, (min(ma-1,maxmove(f, (dir-1 ? dir-1 : 8), 0))), (dir-1 ? dir -1 : 8), f, t, high, rakeme); ! 248: rmend(temp); ! 249: } ! 250: } ! 251: ! 252: rmend(str) ! 253: char *str; ! 254: { ! 255: register char *p; ! 256: ! 257: for (p = str; *p; p++) ! 258: ; ! 259: if (p != str) ! 260: *--p = 0; ! 261: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.