118695Sedward /* 221227Sdist * Copyright (c) 1983 Regents of the University of California. 333695Sbostic * All rights reserved. 433695Sbostic * 5*42601Sbostic * %sccs.include.redist.c% 618695Sedward */ 718695Sedward 811587Sleres #ifndef lint 9*42601Sbostic static char sccsid[] = "@(#)assorted.c 5.4 (Berkeley) 06/01/90"; 1033695Sbostic #endif /* not lint */ 1114008Sedward 1211587Sleres #include "externs.h" 1311587Sleres 1414008Sedward table(rig, shot, hittable, on, from, roll) 1514008Sedward struct ship *on, *from; 1614008Sedward int rig, shot, hittable, roll; 1711587Sleres { 1811587Sleres register int hhits = 0, chits = 0, ghits = 0, rhits = 0; 1911587Sleres int Ghit = 0, Hhit = 0, Rhit = 0, Chit = 0; 2011587Sleres int guns, car, pc, hull; 2111587Sleres int crew[3]; 2211587Sleres register int n; 2311587Sleres int rigg[4]; 2414008Sedward char *message; 2514008Sedward struct Tables *tp; 2611587Sleres 2714008Sedward pc = on->file->pcrew; 2814008Sedward hull = on->specs->hull; 2914008Sedward crew[0] = on->specs->crew1; 3014008Sedward crew[1] = on->specs->crew2; 3114008Sedward crew[2] = on->specs->crew3; 3214008Sedward rigg[0] = on->specs->rig1; 3314008Sedward rigg[1] = on->specs->rig2; 3414008Sedward rigg[2] = on->specs->rig3; 3514008Sedward rigg[3] = on->specs->rig4; 3614008Sedward if (shot == L_GRAPE) 3711587Sleres Chit = chits = hittable; 3811587Sleres else { 3914008Sedward tp = &(rig ? RigTable : HullTable)[hittable][roll-1]; 4014008Sedward Chit = chits = tp->C; 4114008Sedward Rhit = rhits = tp->R; 4214008Sedward Hhit = hhits = tp->H; 4314008Sedward Ghit = ghits = tp->G; 4414008Sedward if (on->file->FS) 4511587Sleres rhits *= 2; 4614008Sedward if (shot == L_CHAIN) { 4711587Sleres Ghit = ghits = 0; 4811587Sleres Hhit = hhits = 0; 4911587Sleres } 5011587Sleres } 5114008Sedward if (on->file->captured != 0) { 5214008Sedward pc -= (chits + 1) / 2; 5311587Sleres chits /= 2; 5411587Sleres } 5514008Sedward for (n = 0; n < 3; n++) 5614008Sedward if (chits > crew[n]) { 5711587Sleres chits -= crew[n]; 5811587Sleres crew[n] = 0; 5914008Sedward } else { 6011587Sleres crew[n] -= chits; 6111587Sleres chits = 0; 6211587Sleres } 6314008Sedward for (n = 0; n < 3; n++) 6411587Sleres if (rhits > rigg[n]){ 6511587Sleres rhits -= rigg[n]; 6611587Sleres rigg[n] = 0; 6714008Sedward } else { 6811587Sleres rigg[n] -= rhits; 6911587Sleres rhits = 0; 7011587Sleres } 7114008Sedward if (rigg[3] != -1 && rhits > rigg[3]) { 7211587Sleres rhits -= rigg[3]; 7311587Sleres rigg[3] = 0; 7414008Sedward } else if (rigg[3] != -1) { 7511587Sleres rigg[3] -= rhits; 7611587Sleres } 7711587Sleres if (rig && !rigg[2] && (!rigg[3] || rigg[3] == -1)) 7814008Sedward makesignal(on, "dismasted!", (struct ship *)0); 7914008Sedward if (portside(from, on, 0)) { 8015924Sedward guns = on->specs->gunR; 8115924Sedward car = on->specs->carR; 8215924Sedward } else { 8314008Sedward guns = on->specs->gunL; 8414008Sedward car = on->specs->carL; 8511587Sleres } 8614008Sedward if (ghits > car) { 8711587Sleres ghits -= car; 8811587Sleres car = 0; 8914008Sedward } else { 9011587Sleres car -= ghits; 9111587Sleres ghits = 0; 9211587Sleres } 9311587Sleres if (ghits > guns){ 9411587Sleres ghits -= guns; 9511587Sleres guns = 0; 9614008Sedward } else { 9711587Sleres guns -= ghits; 9811587Sleres ghits = 0; 9911587Sleres } 10011587Sleres hull -= ghits; 10114008Sedward if (Ghit) 10215924Sedward Write(portside(from, on, 0) ? W_GUNR : W_GUNL, 10314008Sedward on, 0, guns, car, 0, 0); 10411587Sleres hull -= hhits; 10511587Sleres hull = hull < 0 ? 0 : hull; 10614008Sedward if (on->file->captured != 0 && Chit) 10714008Sedward Write(W_PCREW, on, 0, pc, 0, 0, 0); 10811587Sleres if (Hhit) 10914008Sedward Write(W_HULL, on, 0, hull, 0, 0, 0); 11011587Sleres if (Chit) 11114008Sedward Write(W_CREW, on, 0, crew[0], crew[1], crew[2], 0); 11211587Sleres if (Rhit) 11314008Sedward Write(W_RIGG, on, 0, rigg[0], rigg[1], rigg[2], rigg[3]); 11414008Sedward switch (shot) { 11514008Sedward case L_ROUND: 11614008Sedward message = "firing round shot on %s (%c%c)"; 11714008Sedward break; 11814008Sedward case L_GRAPE: 11914008Sedward message = "firing grape shot on %s (%c%c)"; 12014008Sedward break; 12114008Sedward case L_CHAIN: 12214008Sedward message = "firing chain shot on %s (%c%c)"; 12314008Sedward break; 12414008Sedward case L_DOUBLE: 12514008Sedward message = "firing double shot on %s (%c%c)"; 12614008Sedward break; 12714008Sedward case L_EXPLODE: 12814008Sedward message = "exploding shot on %s (%c%c)"; 12914008Sedward } 13014008Sedward makesignal(from, message, on); 13114008Sedward if (roll == 6 && rig) { 13214008Sedward switch(Rhit) { 13314008Sedward case 0: 13414008Sedward message = "fore topsail sheets parted"; 13511587Sleres break; 13614008Sedward case 1: 13714008Sedward message = "mizzen shrouds parted"; 13811587Sleres break; 13914008Sedward case 2: 14014008Sedward message = "main topsail yard shot away"; 14111587Sleres break; 14214008Sedward case 4: 14314008Sedward message = "fore topmast and foremast shrouds shot away"; 14411587Sleres break; 14514008Sedward case 5: 14614008Sedward message = "mizzen mast and yard shot through"; 14714008Sedward break; 14814008Sedward case 6: 14914008Sedward message = "foremast and spritsail yard shattered"; 15014008Sedward break; 15114008Sedward case 7: 15214008Sedward message = "main topmast and mizzen mast shattered"; 15314008Sedward break; 15411587Sleres } 15514008Sedward makesignal(on, message, (struct ship *)0); 15614008Sedward } else if (roll == 6) { 15714008Sedward switch (Hhit) { 15814008Sedward case 0: 15914008Sedward message = "anchor cables severed"; 16014008Sedward break; 16114008Sedward case 1: 16214008Sedward message = "two anchor stocks shot away"; 16314008Sedward break; 16414008Sedward case 2: 16514008Sedward message = "quarterdeck bulwarks damaged"; 16614008Sedward break; 16714008Sedward case 3: 16814008Sedward message = "three gun ports shot away"; 16914008Sedward break; 17014008Sedward case 4: 17114008Sedward message = "four guns dismounted"; 17214008Sedward break; 17314008Sedward case 5: 17414008Sedward message = "rudder cables shot through"; 17514008Sedward Write(W_TA, on, 0, 0, 0, 0, 0); 17614008Sedward break; 17714008Sedward case 6: 17814008Sedward message = "shot holes below the water line"; 17914008Sedward break; 18011587Sleres } 18114008Sedward makesignal(on, message, (struct ship *)0); 18211587Sleres } 18315317Sedward /* 18415317Sedward if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) { 18514008Sedward on->specs->qual--; 18614008Sedward if (on->specs->qual <= 0) { 18714008Sedward makesignal(on, "crew mutinying!", (struct ship *)0); 18814008Sedward on->specs->qual = 5; 18915722Sedward Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0); 19011587Sleres } else 19114008Sedward makesignal(on, "crew demoralized", (struct ship *)0); 19214008Sedward Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0); 19311587Sleres } 19415317Sedward */ 19511587Sleres if (!hull) 19614008Sedward strike(on, from); 19711587Sleres } 19811587Sleres 19915722Sedward Cleansnag(from, to, all, flag) 20014008Sedward register struct ship *from, *to; 20115722Sedward char all, flag; 20211587Sleres { 20315722Sedward if (flag & 1) { 20415722Sedward Write(W_UNGRAP, from, 0, to->file->index, all, 0, 0); 20515722Sedward Write(W_UNGRAP, to, 0, from->file->index, all, 0, 0); 20611587Sleres } 20715722Sedward if (flag & 2) { 20815722Sedward Write(W_UNFOUL, from, 0, to->file->index, all, 0, 0); 20915722Sedward Write(W_UNFOUL, to, 0, from->file->index, all, 0, 0); 21015722Sedward } 21114008Sedward if (!snagged2(from, to)) { 21215722Sedward if (!snagged(from)) { 21314008Sedward unboard(from, from, 1); /* defense */ 21414008Sedward unboard(from, from, 0); /* defense */ 21511587Sleres } else 21615722Sedward unboard(from, to, 0); /* offense */ 21715722Sedward if (!snagged(to)) { 21815722Sedward unboard(to, to, 1); /* defense */ 21915722Sedward unboard(to, to, 0); /* defense */ 22011587Sleres } else 22114008Sedward unboard(to, from, 0); /* offense */ 22211587Sleres } 22311587Sleres } 22411587Sleres 22514008Sedward strike(ship, from) 22614008Sedward register struct ship *ship, *from; 22711587Sleres { 22811587Sleres int points; 22911587Sleres 23014008Sedward if (ship->file->struck) 23114008Sedward return; 23214008Sedward Write(W_STRUCK, ship, 0, 1, 0, 0, 0); 23314008Sedward points = ship->specs->pts + from->file->points; 23414008Sedward Write(W_POINTS, from, 0, points, 0, 0, 0); 23514008Sedward unboard(ship, ship, 0); /* all offense */ 23614008Sedward unboard(ship, ship, 1); /* all defense */ 23714008Sedward switch (die()) { 23814008Sedward case 3: 23914008Sedward case 4: /* ship may sink */ 24014008Sedward Write(W_SINK, ship, 0, 1, 0, 0, 0); 24114008Sedward break; 24214008Sedward case 5: 24314008Sedward case 6: /* ship may explode */ 24414008Sedward Write(W_EXPLODE, ship, 0, 1, 0, 0, 0); 24514008Sedward break; 24611587Sleres } 24714008Sedward Write(W_SIGNAL, ship, 1, (int) "striking her colours!", 0, 0, 0); 24811587Sleres } 249