1*11587Sleres #ifndef lint 2*11587Sleres static char *sccsid = "@(#)assorted.c 1.1 83/03/17"; 3*11587Sleres #endif 4*11587Sleres #define EXPLODE 5 5*11587Sleres #include "externs.h" 6*11587Sleres 7*11587Sleres table(rig, shot, hittable, onship, fromship, roll) 8*11587Sleres int rig, shot, hittable, onship, fromship, roll; 9*11587Sleres { 10*11587Sleres register int hhits = 0, chits = 0, ghits = 0, rhits = 0; 11*11587Sleres int Ghit = 0, Hhit = 0, Rhit = 0, Chit = 0; 12*11587Sleres int guns, car, pc, hull; 13*11587Sleres int crew[3]; 14*11587Sleres register int n; 15*11587Sleres int rigg[4]; 16*11587Sleres char message[60]; 17*11587Sleres struct shipspecs *ptr; 18*11587Sleres struct File *ptr1; 19*11587Sleres 20*11587Sleres ptr = &specs[scene[game].ship[onship].shipnum]; 21*11587Sleres ptr1 = scene[game].ship[onship].file; 22*11587Sleres pc = ptr1 -> pcrew; 23*11587Sleres hull = ptr -> hull; 24*11587Sleres crew[0] = ptr -> crew1; 25*11587Sleres crew[1] = ptr -> crew2; 26*11587Sleres crew[2] = ptr -> crew3; 27*11587Sleres rigg[0] = ptr -> rig1; 28*11587Sleres rigg[1] = ptr -> rig2; 29*11587Sleres rigg[2] = ptr -> rig3; 30*11587Sleres rigg[3] = ptr -> rig4; 31*11587Sleres if (shot == GRAPE) 32*11587Sleres Chit = chits = hittable; 33*11587Sleres else { 34*11587Sleres Chit = chits = rig ? RigTable[hittable][roll-1].C : HullTable[hittable][roll-1].C; 35*11587Sleres Rhit = rhits = rig ? RigTable[hittable][roll-1].R : HullTable[hittable][roll-1].R; 36*11587Sleres Hhit = hhits = rig ? RigTable[hittable][roll-1].H : HullTable[hittable][roll-1].H; 37*11587Sleres Ghit = ghits = rig ? RigTable[hittable][roll-1].G : HullTable[hittable][roll-1].G; 38*11587Sleres if (ptr1 -> FS) 39*11587Sleres rhits *= 2; 40*11587Sleres if (shot == CHAIN){ 41*11587Sleres Ghit = ghits = 0; 42*11587Sleres Hhit = hhits = 0; 43*11587Sleres } 44*11587Sleres } 45*11587Sleres if (ptr1 -> captured > -1){ 46*11587Sleres pc -= (chits + 1)/2; 47*11587Sleres chits /= 2; 48*11587Sleres } 49*11587Sleres for (n=0; n < 3; n++) 50*11587Sleres if (chits > crew[n]){ 51*11587Sleres chits -= crew[n]; 52*11587Sleres crew[n] = 0; 53*11587Sleres } 54*11587Sleres else { 55*11587Sleres crew[n] -= chits; 56*11587Sleres chits = 0; 57*11587Sleres } 58*11587Sleres for (n=0; n < 3; n++) 59*11587Sleres if (rhits > rigg[n]){ 60*11587Sleres rhits -= rigg[n]; 61*11587Sleres rigg[n] = 0; 62*11587Sleres } 63*11587Sleres else { 64*11587Sleres rigg[n] -= rhits; 65*11587Sleres rhits = 0; 66*11587Sleres } 67*11587Sleres if (rigg[3] != -1 && rhits > rigg[3]){ 68*11587Sleres rhits -= rigg[3]; 69*11587Sleres rigg[3] = 0; 70*11587Sleres } else if (rigg[3] != -1){ 71*11587Sleres rigg[3] -= rhits; 72*11587Sleres } 73*11587Sleres if (rig && !rigg[2] && (!rigg[3] || rigg[3] == -1)) 74*11587Sleres makesignal("dismasted!", 0, onship); 75*11587Sleres if (portside(fromship, onship, 0)){ 76*11587Sleres guns = ptr -> gunL; 77*11587Sleres car = ptr -> carL; 78*11587Sleres } else { 79*11587Sleres guns = ptr -> gunR; 80*11587Sleres car = ptr -> carR; 81*11587Sleres } 82*11587Sleres if (ghits > car){ 83*11587Sleres ghits -= car; 84*11587Sleres car = 0; 85*11587Sleres } 86*11587Sleres else { 87*11587Sleres car -= ghits; 88*11587Sleres ghits = 0; 89*11587Sleres } 90*11587Sleres if (ghits > guns){ 91*11587Sleres ghits -= guns; 92*11587Sleres guns = 0; 93*11587Sleres } 94*11587Sleres else { 95*11587Sleres guns -= ghits; 96*11587Sleres ghits = 0; 97*11587Sleres } 98*11587Sleres hull -= ghits; 99*11587Sleres if (portside(fromship, onship, 0) && Ghit){ 100*11587Sleres Write(SPECS + onship, 0, 20, guns); 101*11587Sleres Write(SPECS + onship, 0, 24, car); 102*11587Sleres } 103*11587Sleres else if (Ghit){ 104*11587Sleres Write(SPECS + onship, 0, 22, guns); 105*11587Sleres Write(SPECS + onship, 0, 26, car); 106*11587Sleres } 107*11587Sleres hull -= hhits; 108*11587Sleres hull = hull < 0 ? 0 : hull; 109*11587Sleres if (ptr1 -> captured > -1 && Chit){ 110*11587Sleres Write(FILES + onship, 0, 70, pc); 111*11587Sleres } 112*11587Sleres if (Hhit) 113*11587Sleres Write(SPECS + onship, 0, 10, hull); 114*11587Sleres if (Chit) 115*11587Sleres for (n=0; n < 3; n++) 116*11587Sleres Write(SPECS + onship, 0, 14 + 2*n, crew[n]); 117*11587Sleres if (Rhit) 118*11587Sleres for (n=0; n < 4; n++) 119*11587Sleres Write(SPECS + onship, 0, 28 + 2*n, rigg[n]); 120*11587Sleres switch(shot){ 121*11587Sleres case ROUND: 122*11587Sleres strcpy(message, "firing round"); 123*11587Sleres break; 124*11587Sleres case GRAPE: 125*11587Sleres strcpy(message, "firing grape"); 126*11587Sleres break; 127*11587Sleres case CHAIN: 128*11587Sleres strcpy(message, "firing chain"); 129*11587Sleres break; 130*11587Sleres case DOUBLE: 131*11587Sleres strcpy(message, "firing double"); 132*11587Sleres break; 133*11587Sleres case EXPLODE: 134*11587Sleres strcpy(message, "exploding"); 135*11587Sleres } 136*11587Sleres strcat(message, " shot on %s (%c%c)"); 137*11587Sleres makesignal(message, onship, fromship); 138*11587Sleres if (roll == 6 && rig){ 139*11587Sleres switch(Rhit){ 140*11587Sleres case 0: 141*11587Sleres strcpy(message, "fore topsail sheets parted"); 142*11587Sleres break; 143*11587Sleres case 1: 144*11587Sleres strcpy(message, "mizzen shrouds parted"); 145*11587Sleres break; 146*11587Sleres case 2: 147*11587Sleres strcpy(message, "main topsail yard shot away"); 148*11587Sleres break; 149*11587Sleres case 4: 150*11587Sleres strcpy(message, "fore topmast and foremast shrouds shot away"); 151*11587Sleres break; 152*11587Sleres case 5: 153*11587Sleres strcpy(message, "mizzen mast and yard shot through"); 154*11587Sleres break; 155*11587Sleres case 6: 156*11587Sleres strcpy(message, "foremast and spritsail yard shattered"); 157*11587Sleres break; 158*11587Sleres case 7: 159*11587Sleres strcpy(message, "main topmast and mizzen mast shattered"); 160*11587Sleres break; 161*11587Sleres } 162*11587Sleres makesignal(message, 0, onship); 163*11587Sleres } 164*11587Sleres else if (roll == 6) { 165*11587Sleres switch(Hhit){ 166*11587Sleres case 0: 167*11587Sleres strcpy(message, "anchor cables severed"); 168*11587Sleres break; 169*11587Sleres case 1: 170*11587Sleres strcpy(message, "two anchor stocks shot away"); 171*11587Sleres break; 172*11587Sleres case 2: 173*11587Sleres strcpy(message, "quarterdeck bulwarks damaged"); 174*11587Sleres break; 175*11587Sleres case 3: 176*11587Sleres strcpy(message, "three gun ports shot away"); 177*11587Sleres break; 178*11587Sleres case 4: 179*11587Sleres strcpy(message, "four guns dismounted"); 180*11587Sleres break; 181*11587Sleres case 5: 182*11587Sleres strcpy(message, "rudder cables shot through"); 183*11587Sleres Write(SPECS + onship, 0, 4, 0); 184*11587Sleres break; 185*11587Sleres case 6: 186*11587Sleres strcpy(message, "shot holes below the water line"); 187*11587Sleres break; 188*11587Sleres } 189*11587Sleres makesignal(message, 0, onship); 190*11587Sleres } 191*11587Sleres if ((Chit > 1 && ptr1 -> readyL <= -30000 && ptr1 -> readyR <= -30000) || Chit == 4){ 192*11587Sleres ptr -> qual--; 193*11587Sleres if (ptr -> qual <= 0){ 194*11587Sleres makesignal("crew mutinying!", 0, onship); 195*11587Sleres ptr -> qual = 5; 196*11587Sleres Write(FILES + onship, 0, 68, onship); 197*11587Sleres } else 198*11587Sleres makesignal("crew demoralized", 0, onship); 199*11587Sleres Write(SPECS + onship, 0, 12, ptr -> qual); 200*11587Sleres } 201*11587Sleres if (!hull) 202*11587Sleres strike(onship, fromship); 203*11587Sleres } 204*11587Sleres 205*11587Sleres 206*11587Sleres cleanfoul(fromship, toship, offset) 207*11587Sleres int fromship, toship, offset; 208*11587Sleres { 209*11587Sleres register int n = -1; 210*11587Sleres 211*11587Sleres Write(FILES + fromship, 0, 84 + offset*4, 0); 212*11587Sleres do { 213*11587Sleres n++; 214*11587Sleres } while ((!scene[game].ship[toship].file -> fouls[n].turnfoul || scene[game].ship[toship].file -> fouls[n].toship != fromship) && n < 10); 215*11587Sleres if (n < 10) 216*11587Sleres Write(FILES + toship, 0, 84 + 4*n, 0); 217*11587Sleres if (!grapple(fromship, toship) && !foul(fromship,toship)){ 218*11587Sleres if (!fouled(fromship) && !grappled(fromship)){ 219*11587Sleres unboard(fromship,fromship, 1); /* defense */ 220*11587Sleres unboard(fromship,fromship, 0); /* defense */ 221*11587Sleres } else 222*11587Sleres unboard(fromship,toship, 0); /* defense */ 223*11587Sleres if (!fouled(toship) && !grappled(toship)){ /* defense */ 224*11587Sleres unboard(toship,toship, 1); 225*11587Sleres unboard(toship,toship, 0); 226*11587Sleres } else 227*11587Sleres unboard(toship, fromship, 0); /* offense */ 228*11587Sleres } 229*11587Sleres } 230*11587Sleres 231*11587Sleres 232*11587Sleres cleangrapple(fromship, toship, offset) 233*11587Sleres int fromship, toship, offset; 234*11587Sleres { 235*11587Sleres register int n = -1; 236*11587Sleres 237*11587Sleres Write(FILES + fromship, 0, 124 + offset*4, 0); 238*11587Sleres do { 239*11587Sleres n++; 240*11587Sleres } while ((!scene[game].ship[toship].file -> grapples[n].turnfoul || scene[game].ship[toship].file -> grapples[n].toship != fromship) && n < 10); 241*11587Sleres if (n < 10) 242*11587Sleres Write(FILES + toship, 0, 124 + 4*n, 0); 243*11587Sleres if (!grapple(fromship, toship) && !foul(fromship,toship)){ 244*11587Sleres if (!fouled(fromship) && !grappled(fromship)){ 245*11587Sleres unboard(fromship,fromship, 1); /* defense */ 246*11587Sleres unboard(fromship,fromship, 0); /* defense */ 247*11587Sleres } else 248*11587Sleres unboard(fromship,toship, 0); /* defense */ 249*11587Sleres if (!fouled(toship) && !grappled(toship)){ /* defense */ 250*11587Sleres unboard(toship,toship, 1); 251*11587Sleres unboard(toship,toship, 0); 252*11587Sleres } else 253*11587Sleres unboard(toship, fromship, 0); /* offense */ 254*11587Sleres } 255*11587Sleres } 256*11587Sleres 257*11587Sleres 258*11587Sleres strike(shipnum, fromship) 259*11587Sleres int shipnum, fromship; 260*11587Sleres { 261*11587Sleres int points; 262*11587Sleres 263*11587Sleres if (!scene[game].ship[shipnum].file -> struck){ 264*11587Sleres Write(FILES + shipnum, 0, 66, 1); 265*11587Sleres points = specs[scene[game].ship[shipnum].shipnum].pts + scene[game].ship[fromship].file -> points; 266*11587Sleres Write(FILES + fromship, 0, 20, points); 267*11587Sleres unboard(shipnum, shipnum, 0); /* all offense */ 268*11587Sleres unboard(shipnum, shipnum, 1); /* all defense */ 269*11587Sleres switch(die()){ 270*11587Sleres 271*11587Sleres case 3: 272*11587Sleres case 4: /* ship may sink */ 273*11587Sleres Write(FILES + shipnum, 0, 234, 1); 274*11587Sleres break; 275*11587Sleres case 5: 276*11587Sleres case 6: /* ship may explode */ 277*11587Sleres Write(FILES + shipnum, 0, 232, 1); 278*11587Sleres break; 279*11587Sleres } 280*11587Sleres Write(FILES + shipnum, 1, 164, "striking her colours!"); 281*11587Sleres } 282*11587Sleres } 283*11587Sleres 284*11587Sleres 285