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