1*18695Sedward /* 2*18695Sedward * Copyright (c) 1983 Regents of the University of California, 3*18695Sedward * All rights reserved. Redistribution permitted subject to 4*18695Sedward * the terms of the Berkeley Software License Agreement. 5*18695Sedward */ 6*18695Sedward 711587Sleres #ifndef lint 8*18695Sedward static char *sccsid = "@(#)assorted.c 2.5 85/04/23"; 911587Sleres #endif 1014008Sedward 1111587Sleres #include "externs.h" 1211587Sleres 1314008Sedward table(rig, shot, hittable, on, from, roll) 1414008Sedward struct ship *on, *from; 1514008Sedward int rig, shot, hittable, roll; 1611587Sleres { 1711587Sleres register int hhits = 0, chits = 0, ghits = 0, rhits = 0; 1811587Sleres int Ghit = 0, Hhit = 0, Rhit = 0, Chit = 0; 1911587Sleres int guns, car, pc, hull; 2011587Sleres int crew[3]; 2111587Sleres register int n; 2211587Sleres int rigg[4]; 2314008Sedward char *message; 2414008Sedward struct Tables *tp; 2511587Sleres 2614008Sedward pc = on->file->pcrew; 2714008Sedward hull = on->specs->hull; 2814008Sedward crew[0] = on->specs->crew1; 2914008Sedward crew[1] = on->specs->crew2; 3014008Sedward crew[2] = on->specs->crew3; 3114008Sedward rigg[0] = on->specs->rig1; 3214008Sedward rigg[1] = on->specs->rig2; 3314008Sedward rigg[2] = on->specs->rig3; 3414008Sedward rigg[3] = on->specs->rig4; 3514008Sedward if (shot == L_GRAPE) 3611587Sleres Chit = chits = hittable; 3711587Sleres else { 3814008Sedward tp = &(rig ? RigTable : HullTable)[hittable][roll-1]; 3914008Sedward Chit = chits = tp->C; 4014008Sedward Rhit = rhits = tp->R; 4114008Sedward Hhit = hhits = tp->H; 4214008Sedward Ghit = ghits = tp->G; 4314008Sedward if (on->file->FS) 4411587Sleres rhits *= 2; 4514008Sedward if (shot == L_CHAIN) { 4611587Sleres Ghit = ghits = 0; 4711587Sleres Hhit = hhits = 0; 4811587Sleres } 4911587Sleres } 5014008Sedward if (on->file->captured != 0) { 5114008Sedward pc -= (chits + 1) / 2; 5211587Sleres chits /= 2; 5311587Sleres } 5414008Sedward for (n = 0; n < 3; n++) 5514008Sedward if (chits > crew[n]) { 5611587Sleres chits -= crew[n]; 5711587Sleres crew[n] = 0; 5814008Sedward } else { 5911587Sleres crew[n] -= chits; 6011587Sleres chits = 0; 6111587Sleres } 6214008Sedward for (n = 0; n < 3; n++) 6311587Sleres if (rhits > rigg[n]){ 6411587Sleres rhits -= rigg[n]; 6511587Sleres rigg[n] = 0; 6614008Sedward } else { 6711587Sleres rigg[n] -= rhits; 6811587Sleres rhits = 0; 6911587Sleres } 7014008Sedward if (rigg[3] != -1 && rhits > rigg[3]) { 7111587Sleres rhits -= rigg[3]; 7211587Sleres rigg[3] = 0; 7314008Sedward } else if (rigg[3] != -1) { 7411587Sleres rigg[3] -= rhits; 7511587Sleres } 7611587Sleres if (rig && !rigg[2] && (!rigg[3] || rigg[3] == -1)) 7714008Sedward makesignal(on, "dismasted!", (struct ship *)0); 7814008Sedward if (portside(from, on, 0)) { 7915924Sedward guns = on->specs->gunR; 8015924Sedward car = on->specs->carR; 8115924Sedward } else { 8214008Sedward guns = on->specs->gunL; 8314008Sedward car = on->specs->carL; 8411587Sleres } 8514008Sedward if (ghits > car) { 8611587Sleres ghits -= car; 8711587Sleres car = 0; 8814008Sedward } else { 8911587Sleres car -= ghits; 9011587Sleres ghits = 0; 9111587Sleres } 9211587Sleres if (ghits > guns){ 9311587Sleres ghits -= guns; 9411587Sleres guns = 0; 9514008Sedward } else { 9611587Sleres guns -= ghits; 9711587Sleres ghits = 0; 9811587Sleres } 9911587Sleres hull -= ghits; 10014008Sedward if (Ghit) 10115924Sedward Write(portside(from, on, 0) ? W_GUNR : W_GUNL, 10214008Sedward on, 0, guns, car, 0, 0); 10311587Sleres hull -= hhits; 10411587Sleres hull = hull < 0 ? 0 : hull; 10514008Sedward if (on->file->captured != 0 && Chit) 10614008Sedward Write(W_PCREW, on, 0, pc, 0, 0, 0); 10711587Sleres if (Hhit) 10814008Sedward Write(W_HULL, on, 0, hull, 0, 0, 0); 10911587Sleres if (Chit) 11014008Sedward Write(W_CREW, on, 0, crew[0], crew[1], crew[2], 0); 11111587Sleres if (Rhit) 11214008Sedward Write(W_RIGG, on, 0, rigg[0], rigg[1], rigg[2], rigg[3]); 11314008Sedward switch (shot) { 11414008Sedward case L_ROUND: 11514008Sedward message = "firing round shot on %s (%c%c)"; 11614008Sedward break; 11714008Sedward case L_GRAPE: 11814008Sedward message = "firing grape shot on %s (%c%c)"; 11914008Sedward break; 12014008Sedward case L_CHAIN: 12114008Sedward message = "firing chain shot on %s (%c%c)"; 12214008Sedward break; 12314008Sedward case L_DOUBLE: 12414008Sedward message = "firing double shot on %s (%c%c)"; 12514008Sedward break; 12614008Sedward case L_EXPLODE: 12714008Sedward message = "exploding shot on %s (%c%c)"; 12814008Sedward } 12914008Sedward makesignal(from, message, on); 13014008Sedward if (roll == 6 && rig) { 13114008Sedward switch(Rhit) { 13214008Sedward case 0: 13314008Sedward message = "fore topsail sheets parted"; 13411587Sleres break; 13514008Sedward case 1: 13614008Sedward message = "mizzen shrouds parted"; 13711587Sleres break; 13814008Sedward case 2: 13914008Sedward message = "main topsail yard shot away"; 14011587Sleres break; 14114008Sedward case 4: 14214008Sedward message = "fore topmast and foremast shrouds shot away"; 14311587Sleres break; 14414008Sedward case 5: 14514008Sedward message = "mizzen mast and yard shot through"; 14614008Sedward break; 14714008Sedward case 6: 14814008Sedward message = "foremast and spritsail yard shattered"; 14914008Sedward break; 15014008Sedward case 7: 15114008Sedward message = "main topmast and mizzen mast shattered"; 15214008Sedward break; 15311587Sleres } 15414008Sedward makesignal(on, message, (struct ship *)0); 15514008Sedward } else if (roll == 6) { 15614008Sedward switch (Hhit) { 15714008Sedward case 0: 15814008Sedward message = "anchor cables severed"; 15914008Sedward break; 16014008Sedward case 1: 16114008Sedward message = "two anchor stocks shot away"; 16214008Sedward break; 16314008Sedward case 2: 16414008Sedward message = "quarterdeck bulwarks damaged"; 16514008Sedward break; 16614008Sedward case 3: 16714008Sedward message = "three gun ports shot away"; 16814008Sedward break; 16914008Sedward case 4: 17014008Sedward message = "four guns dismounted"; 17114008Sedward break; 17214008Sedward case 5: 17314008Sedward message = "rudder cables shot through"; 17414008Sedward Write(W_TA, on, 0, 0, 0, 0, 0); 17514008Sedward break; 17614008Sedward case 6: 17714008Sedward message = "shot holes below the water line"; 17814008Sedward break; 17911587Sleres } 18014008Sedward makesignal(on, message, (struct ship *)0); 18111587Sleres } 18215317Sedward /* 18315317Sedward if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) { 18414008Sedward on->specs->qual--; 18514008Sedward if (on->specs->qual <= 0) { 18614008Sedward makesignal(on, "crew mutinying!", (struct ship *)0); 18714008Sedward on->specs->qual = 5; 18815722Sedward Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0); 18911587Sleres } else 19014008Sedward makesignal(on, "crew demoralized", (struct ship *)0); 19114008Sedward Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0); 19211587Sleres } 19315317Sedward */ 19411587Sleres if (!hull) 19514008Sedward strike(on, from); 19611587Sleres } 19711587Sleres 19815722Sedward Cleansnag(from, to, all, flag) 19914008Sedward register struct ship *from, *to; 20015722Sedward char all, flag; 20111587Sleres { 20215722Sedward if (flag & 1) { 20315722Sedward Write(W_UNGRAP, from, 0, to->file->index, all, 0, 0); 20415722Sedward Write(W_UNGRAP, to, 0, from->file->index, all, 0, 0); 20511587Sleres } 20615722Sedward if (flag & 2) { 20715722Sedward Write(W_UNFOUL, from, 0, to->file->index, all, 0, 0); 20815722Sedward Write(W_UNFOUL, to, 0, from->file->index, all, 0, 0); 20915722Sedward } 21014008Sedward if (!snagged2(from, to)) { 21115722Sedward if (!snagged(from)) { 21214008Sedward unboard(from, from, 1); /* defense */ 21314008Sedward unboard(from, from, 0); /* defense */ 21411587Sleres } else 21515722Sedward unboard(from, to, 0); /* offense */ 21615722Sedward if (!snagged(to)) { 21715722Sedward unboard(to, to, 1); /* defense */ 21815722Sedward unboard(to, to, 0); /* defense */ 21911587Sleres } else 22014008Sedward unboard(to, from, 0); /* offense */ 22111587Sleres } 22211587Sleres } 22311587Sleres 22414008Sedward strike(ship, from) 22514008Sedward register struct ship *ship, *from; 22611587Sleres { 22711587Sleres int points; 22811587Sleres 22914008Sedward if (ship->file->struck) 23014008Sedward return; 23114008Sedward Write(W_STRUCK, ship, 0, 1, 0, 0, 0); 23214008Sedward points = ship->specs->pts + from->file->points; 23314008Sedward Write(W_POINTS, from, 0, points, 0, 0, 0); 23414008Sedward unboard(ship, ship, 0); /* all offense */ 23514008Sedward unboard(ship, ship, 1); /* all defense */ 23614008Sedward switch (die()) { 23714008Sedward case 3: 23814008Sedward case 4: /* ship may sink */ 23914008Sedward Write(W_SINK, ship, 0, 1, 0, 0, 0); 24014008Sedward break; 24114008Sedward case 5: 24214008Sedward case 6: /* ship may explode */ 24314008Sedward Write(W_EXPLODE, ship, 0, 1, 0, 0, 0); 24414008Sedward break; 24511587Sleres } 24614008Sedward Write(W_SIGNAL, ship, 1, (int) "striking her colours!", 0, 0, 0); 24711587Sleres } 248