|
|
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 the above copyright notice and this paragraph are ! 7: * duplicated in all such forms and that any documentation, ! 8: * advertising materials, and other materials related to such ! 9: * distribution and use acknowledge that the software was developed ! 10: * by the University of California, Berkeley. The name of the ! 11: * University may not be used to endorse or promote products derived ! 12: * from this software without specific prior written permission. ! 13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 16: */ ! 17: ! 18: #ifndef lint ! 19: static char sccsid[] = "@(#)assorted.c 5.3 (Berkeley) 6/18/88"; ! 20: #endif /* not lint */ ! 21: ! 22: #include "externs.h" ! 23: ! 24: table(rig, shot, hittable, on, from, roll) ! 25: struct ship *on, *from; ! 26: int rig, shot, hittable, roll; ! 27: { ! 28: register int hhits = 0, chits = 0, ghits = 0, rhits = 0; ! 29: int Ghit = 0, Hhit = 0, Rhit = 0, Chit = 0; ! 30: int guns, car, pc, hull; ! 31: int crew[3]; ! 32: register int n; ! 33: int rigg[4]; ! 34: char *message; ! 35: struct Tables *tp; ! 36: ! 37: pc = on->file->pcrew; ! 38: hull = on->specs->hull; ! 39: crew[0] = on->specs->crew1; ! 40: crew[1] = on->specs->crew2; ! 41: crew[2] = on->specs->crew3; ! 42: rigg[0] = on->specs->rig1; ! 43: rigg[1] = on->specs->rig2; ! 44: rigg[2] = on->specs->rig3; ! 45: rigg[3] = on->specs->rig4; ! 46: if (shot == L_GRAPE) ! 47: Chit = chits = hittable; ! 48: else { ! 49: tp = &(rig ? RigTable : HullTable)[hittable][roll-1]; ! 50: Chit = chits = tp->C; ! 51: Rhit = rhits = tp->R; ! 52: Hhit = hhits = tp->H; ! 53: Ghit = ghits = tp->G; ! 54: if (on->file->FS) ! 55: rhits *= 2; ! 56: if (shot == L_CHAIN) { ! 57: Ghit = ghits = 0; ! 58: Hhit = hhits = 0; ! 59: } ! 60: } ! 61: if (on->file->captured != 0) { ! 62: pc -= (chits + 1) / 2; ! 63: chits /= 2; ! 64: } ! 65: for (n = 0; n < 3; n++) ! 66: if (chits > crew[n]) { ! 67: chits -= crew[n]; ! 68: crew[n] = 0; ! 69: } else { ! 70: crew[n] -= chits; ! 71: chits = 0; ! 72: } ! 73: for (n = 0; n < 3; n++) ! 74: if (rhits > rigg[n]){ ! 75: rhits -= rigg[n]; ! 76: rigg[n] = 0; ! 77: } else { ! 78: rigg[n] -= rhits; ! 79: rhits = 0; ! 80: } ! 81: if (rigg[3] != -1 && rhits > rigg[3]) { ! 82: rhits -= rigg[3]; ! 83: rigg[3] = 0; ! 84: } else if (rigg[3] != -1) { ! 85: rigg[3] -= rhits; ! 86: } ! 87: if (rig && !rigg[2] && (!rigg[3] || rigg[3] == -1)) ! 88: makesignal(on, "dismasted!", (struct ship *)0); ! 89: if (portside(from, on, 0)) { ! 90: guns = on->specs->gunR; ! 91: car = on->specs->carR; ! 92: } else { ! 93: guns = on->specs->gunL; ! 94: car = on->specs->carL; ! 95: } ! 96: if (ghits > car) { ! 97: ghits -= car; ! 98: car = 0; ! 99: } else { ! 100: car -= ghits; ! 101: ghits = 0; ! 102: } ! 103: if (ghits > guns){ ! 104: ghits -= guns; ! 105: guns = 0; ! 106: } else { ! 107: guns -= ghits; ! 108: ghits = 0; ! 109: } ! 110: hull -= ghits; ! 111: if (Ghit) ! 112: Write(portside(from, on, 0) ? W_GUNR : W_GUNL, ! 113: on, 0, guns, car, 0, 0); ! 114: hull -= hhits; ! 115: hull = hull < 0 ? 0 : hull; ! 116: if (on->file->captured != 0 && Chit) ! 117: Write(W_PCREW, on, 0, pc, 0, 0, 0); ! 118: if (Hhit) ! 119: Write(W_HULL, on, 0, hull, 0, 0, 0); ! 120: if (Chit) ! 121: Write(W_CREW, on, 0, crew[0], crew[1], crew[2], 0); ! 122: if (Rhit) ! 123: Write(W_RIGG, on, 0, rigg[0], rigg[1], rigg[2], rigg[3]); ! 124: switch (shot) { ! 125: case L_ROUND: ! 126: message = "firing round shot on %s (%c%c)"; ! 127: break; ! 128: case L_GRAPE: ! 129: message = "firing grape shot on %s (%c%c)"; ! 130: break; ! 131: case L_CHAIN: ! 132: message = "firing chain shot on %s (%c%c)"; ! 133: break; ! 134: case L_DOUBLE: ! 135: message = "firing double shot on %s (%c%c)"; ! 136: break; ! 137: case L_EXPLODE: ! 138: message = "exploding shot on %s (%c%c)"; ! 139: } ! 140: makesignal(from, message, on); ! 141: if (roll == 6 && rig) { ! 142: switch(Rhit) { ! 143: case 0: ! 144: message = "fore topsail sheets parted"; ! 145: break; ! 146: case 1: ! 147: message = "mizzen shrouds parted"; ! 148: break; ! 149: case 2: ! 150: message = "main topsail yard shot away"; ! 151: break; ! 152: case 4: ! 153: message = "fore topmast and foremast shrouds shot away"; ! 154: break; ! 155: case 5: ! 156: message = "mizzen mast and yard shot through"; ! 157: break; ! 158: case 6: ! 159: message = "foremast and spritsail yard shattered"; ! 160: break; ! 161: case 7: ! 162: message = "main topmast and mizzen mast shattered"; ! 163: break; ! 164: } ! 165: makesignal(on, message, (struct ship *)0); ! 166: } else if (roll == 6) { ! 167: switch (Hhit) { ! 168: case 0: ! 169: message = "anchor cables severed"; ! 170: break; ! 171: case 1: ! 172: message = "two anchor stocks shot away"; ! 173: break; ! 174: case 2: ! 175: message = "quarterdeck bulwarks damaged"; ! 176: break; ! 177: case 3: ! 178: message = "three gun ports shot away"; ! 179: break; ! 180: case 4: ! 181: message = "four guns dismounted"; ! 182: break; ! 183: case 5: ! 184: message = "rudder cables shot through"; ! 185: Write(W_TA, on, 0, 0, 0, 0, 0); ! 186: break; ! 187: case 6: ! 188: message = "shot holes below the water line"; ! 189: break; ! 190: } ! 191: makesignal(on, message, (struct ship *)0); ! 192: } ! 193: /* ! 194: if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) { ! 195: on->specs->qual--; ! 196: if (on->specs->qual <= 0) { ! 197: makesignal(on, "crew mutinying!", (struct ship *)0); ! 198: on->specs->qual = 5; ! 199: Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0); ! 200: } else ! 201: makesignal(on, "crew demoralized", (struct ship *)0); ! 202: Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0); ! 203: } ! 204: */ ! 205: if (!hull) ! 206: strike(on, from); ! 207: } ! 208: ! 209: Cleansnag(from, to, all, flag) ! 210: register struct ship *from, *to; ! 211: char all, flag; ! 212: { ! 213: if (flag & 1) { ! 214: Write(W_UNGRAP, from, 0, to->file->index, all, 0, 0); ! 215: Write(W_UNGRAP, to, 0, from->file->index, all, 0, 0); ! 216: } ! 217: if (flag & 2) { ! 218: Write(W_UNFOUL, from, 0, to->file->index, all, 0, 0); ! 219: Write(W_UNFOUL, to, 0, from->file->index, all, 0, 0); ! 220: } ! 221: if (!snagged2(from, to)) { ! 222: if (!snagged(from)) { ! 223: unboard(from, from, 1); /* defense */ ! 224: unboard(from, from, 0); /* defense */ ! 225: } else ! 226: unboard(from, to, 0); /* offense */ ! 227: if (!snagged(to)) { ! 228: unboard(to, to, 1); /* defense */ ! 229: unboard(to, to, 0); /* defense */ ! 230: } else ! 231: unboard(to, from, 0); /* offense */ ! 232: } ! 233: } ! 234: ! 235: strike(ship, from) ! 236: register struct ship *ship, *from; ! 237: { ! 238: int points; ! 239: ! 240: if (ship->file->struck) ! 241: return; ! 242: Write(W_STRUCK, ship, 0, 1, 0, 0, 0); ! 243: points = ship->specs->pts + from->file->points; ! 244: Write(W_POINTS, from, 0, points, 0, 0, 0); ! 245: unboard(ship, ship, 0); /* all offense */ ! 246: unboard(ship, ship, 1); /* all defense */ ! 247: switch (die()) { ! 248: case 3: ! 249: case 4: /* ship may sink */ ! 250: Write(W_SINK, ship, 0, 1, 0, 0, 0); ! 251: break; ! 252: case 5: ! 253: case 6: /* ship may explode */ ! 254: Write(W_EXPLODE, ship, 0, 1, 0, 0, 0); ! 255: break; ! 256: } ! 257: Write(W_SIGNAL, ship, 1, (int) "striking her colours!", 0, 0, 0); ! 258: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.