118695Sedward /* 221227Sdist * Copyright (c) 1983 Regents of the University of California. 3*33695Sbostic * All rights reserved. 4*33695Sbostic * 5*33695Sbostic * Redistribution and use in source and binary forms are permitted 6*33695Sbostic * provided that this notice is preserved and that due credit is given 7*33695Sbostic * to the University of California at Berkeley. The name of the University 8*33695Sbostic * may not be used to endorse or promote products derived from this 9*33695Sbostic * software without specific prior written permission. This software 10*33695Sbostic * is provided ``as is'' without express or implied warranty. 1118695Sedward */ 1218695Sedward 1311587Sleres #ifndef lint 14*33695Sbostic static char sccsid[] = "@(#)assorted.c 5.2 (Berkeley) 03/09/88"; 15*33695Sbostic #endif /* not lint */ 1614008Sedward 1711587Sleres #include "externs.h" 1811587Sleres 1914008Sedward table(rig, shot, hittable, on, from, roll) 2014008Sedward struct ship *on, *from; 2114008Sedward int rig, shot, hittable, roll; 2211587Sleres { 2311587Sleres register int hhits = 0, chits = 0, ghits = 0, rhits = 0; 2411587Sleres int Ghit = 0, Hhit = 0, Rhit = 0, Chit = 0; 2511587Sleres int guns, car, pc, hull; 2611587Sleres int crew[3]; 2711587Sleres register int n; 2811587Sleres int rigg[4]; 2914008Sedward char *message; 3014008Sedward struct Tables *tp; 3111587Sleres 3214008Sedward pc = on->file->pcrew; 3314008Sedward hull = on->specs->hull; 3414008Sedward crew[0] = on->specs->crew1; 3514008Sedward crew[1] = on->specs->crew2; 3614008Sedward crew[2] = on->specs->crew3; 3714008Sedward rigg[0] = on->specs->rig1; 3814008Sedward rigg[1] = on->specs->rig2; 3914008Sedward rigg[2] = on->specs->rig3; 4014008Sedward rigg[3] = on->specs->rig4; 4114008Sedward if (shot == L_GRAPE) 4211587Sleres Chit = chits = hittable; 4311587Sleres else { 4414008Sedward tp = &(rig ? RigTable : HullTable)[hittable][roll-1]; 4514008Sedward Chit = chits = tp->C; 4614008Sedward Rhit = rhits = tp->R; 4714008Sedward Hhit = hhits = tp->H; 4814008Sedward Ghit = ghits = tp->G; 4914008Sedward if (on->file->FS) 5011587Sleres rhits *= 2; 5114008Sedward if (shot == L_CHAIN) { 5211587Sleres Ghit = ghits = 0; 5311587Sleres Hhit = hhits = 0; 5411587Sleres } 5511587Sleres } 5614008Sedward if (on->file->captured != 0) { 5714008Sedward pc -= (chits + 1) / 2; 5811587Sleres chits /= 2; 5911587Sleres } 6014008Sedward for (n = 0; n < 3; n++) 6114008Sedward if (chits > crew[n]) { 6211587Sleres chits -= crew[n]; 6311587Sleres crew[n] = 0; 6414008Sedward } else { 6511587Sleres crew[n] -= chits; 6611587Sleres chits = 0; 6711587Sleres } 6814008Sedward for (n = 0; n < 3; n++) 6911587Sleres if (rhits > rigg[n]){ 7011587Sleres rhits -= rigg[n]; 7111587Sleres rigg[n] = 0; 7214008Sedward } else { 7311587Sleres rigg[n] -= rhits; 7411587Sleres rhits = 0; 7511587Sleres } 7614008Sedward if (rigg[3] != -1 && rhits > rigg[3]) { 7711587Sleres rhits -= rigg[3]; 7811587Sleres rigg[3] = 0; 7914008Sedward } else if (rigg[3] != -1) { 8011587Sleres rigg[3] -= rhits; 8111587Sleres } 8211587Sleres if (rig && !rigg[2] && (!rigg[3] || rigg[3] == -1)) 8314008Sedward makesignal(on, "dismasted!", (struct ship *)0); 8414008Sedward if (portside(from, on, 0)) { 8515924Sedward guns = on->specs->gunR; 8615924Sedward car = on->specs->carR; 8715924Sedward } else { 8814008Sedward guns = on->specs->gunL; 8914008Sedward car = on->specs->carL; 9011587Sleres } 9114008Sedward if (ghits > car) { 9211587Sleres ghits -= car; 9311587Sleres car = 0; 9414008Sedward } else { 9511587Sleres car -= ghits; 9611587Sleres ghits = 0; 9711587Sleres } 9811587Sleres if (ghits > guns){ 9911587Sleres ghits -= guns; 10011587Sleres guns = 0; 10114008Sedward } else { 10211587Sleres guns -= ghits; 10311587Sleres ghits = 0; 10411587Sleres } 10511587Sleres hull -= ghits; 10614008Sedward if (Ghit) 10715924Sedward Write(portside(from, on, 0) ? W_GUNR : W_GUNL, 10814008Sedward on, 0, guns, car, 0, 0); 10911587Sleres hull -= hhits; 11011587Sleres hull = hull < 0 ? 0 : hull; 11114008Sedward if (on->file->captured != 0 && Chit) 11214008Sedward Write(W_PCREW, on, 0, pc, 0, 0, 0); 11311587Sleres if (Hhit) 11414008Sedward Write(W_HULL, on, 0, hull, 0, 0, 0); 11511587Sleres if (Chit) 11614008Sedward Write(W_CREW, on, 0, crew[0], crew[1], crew[2], 0); 11711587Sleres if (Rhit) 11814008Sedward Write(W_RIGG, on, 0, rigg[0], rigg[1], rigg[2], rigg[3]); 11914008Sedward switch (shot) { 12014008Sedward case L_ROUND: 12114008Sedward message = "firing round shot on %s (%c%c)"; 12214008Sedward break; 12314008Sedward case L_GRAPE: 12414008Sedward message = "firing grape shot on %s (%c%c)"; 12514008Sedward break; 12614008Sedward case L_CHAIN: 12714008Sedward message = "firing chain shot on %s (%c%c)"; 12814008Sedward break; 12914008Sedward case L_DOUBLE: 13014008Sedward message = "firing double shot on %s (%c%c)"; 13114008Sedward break; 13214008Sedward case L_EXPLODE: 13314008Sedward message = "exploding shot on %s (%c%c)"; 13414008Sedward } 13514008Sedward makesignal(from, message, on); 13614008Sedward if (roll == 6 && rig) { 13714008Sedward switch(Rhit) { 13814008Sedward case 0: 13914008Sedward message = "fore topsail sheets parted"; 14011587Sleres break; 14114008Sedward case 1: 14214008Sedward message = "mizzen shrouds parted"; 14311587Sleres break; 14414008Sedward case 2: 14514008Sedward message = "main topsail yard shot away"; 14611587Sleres break; 14714008Sedward case 4: 14814008Sedward message = "fore topmast and foremast shrouds shot away"; 14911587Sleres break; 15014008Sedward case 5: 15114008Sedward message = "mizzen mast and yard shot through"; 15214008Sedward break; 15314008Sedward case 6: 15414008Sedward message = "foremast and spritsail yard shattered"; 15514008Sedward break; 15614008Sedward case 7: 15714008Sedward message = "main topmast and mizzen mast shattered"; 15814008Sedward break; 15911587Sleres } 16014008Sedward makesignal(on, message, (struct ship *)0); 16114008Sedward } else if (roll == 6) { 16214008Sedward switch (Hhit) { 16314008Sedward case 0: 16414008Sedward message = "anchor cables severed"; 16514008Sedward break; 16614008Sedward case 1: 16714008Sedward message = "two anchor stocks shot away"; 16814008Sedward break; 16914008Sedward case 2: 17014008Sedward message = "quarterdeck bulwarks damaged"; 17114008Sedward break; 17214008Sedward case 3: 17314008Sedward message = "three gun ports shot away"; 17414008Sedward break; 17514008Sedward case 4: 17614008Sedward message = "four guns dismounted"; 17714008Sedward break; 17814008Sedward case 5: 17914008Sedward message = "rudder cables shot through"; 18014008Sedward Write(W_TA, on, 0, 0, 0, 0, 0); 18114008Sedward break; 18214008Sedward case 6: 18314008Sedward message = "shot holes below the water line"; 18414008Sedward break; 18511587Sleres } 18614008Sedward makesignal(on, message, (struct ship *)0); 18711587Sleres } 18815317Sedward /* 18915317Sedward if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) { 19014008Sedward on->specs->qual--; 19114008Sedward if (on->specs->qual <= 0) { 19214008Sedward makesignal(on, "crew mutinying!", (struct ship *)0); 19314008Sedward on->specs->qual = 5; 19415722Sedward Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0); 19511587Sleres } else 19614008Sedward makesignal(on, "crew demoralized", (struct ship *)0); 19714008Sedward Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0); 19811587Sleres } 19915317Sedward */ 20011587Sleres if (!hull) 20114008Sedward strike(on, from); 20211587Sleres } 20311587Sleres 20415722Sedward Cleansnag(from, to, all, flag) 20514008Sedward register struct ship *from, *to; 20615722Sedward char all, flag; 20711587Sleres { 20815722Sedward if (flag & 1) { 20915722Sedward Write(W_UNGRAP, from, 0, to->file->index, all, 0, 0); 21015722Sedward Write(W_UNGRAP, to, 0, from->file->index, all, 0, 0); 21111587Sleres } 21215722Sedward if (flag & 2) { 21315722Sedward Write(W_UNFOUL, from, 0, to->file->index, all, 0, 0); 21415722Sedward Write(W_UNFOUL, to, 0, from->file->index, all, 0, 0); 21515722Sedward } 21614008Sedward if (!snagged2(from, to)) { 21715722Sedward if (!snagged(from)) { 21814008Sedward unboard(from, from, 1); /* defense */ 21914008Sedward unboard(from, from, 0); /* defense */ 22011587Sleres } else 22115722Sedward unboard(from, to, 0); /* offense */ 22215722Sedward if (!snagged(to)) { 22315722Sedward unboard(to, to, 1); /* defense */ 22415722Sedward unboard(to, to, 0); /* defense */ 22511587Sleres } else 22614008Sedward unboard(to, from, 0); /* offense */ 22711587Sleres } 22811587Sleres } 22911587Sleres 23014008Sedward strike(ship, from) 23114008Sedward register struct ship *ship, *from; 23211587Sleres { 23311587Sleres int points; 23411587Sleres 23514008Sedward if (ship->file->struck) 23614008Sedward return; 23714008Sedward Write(W_STRUCK, ship, 0, 1, 0, 0, 0); 23814008Sedward points = ship->specs->pts + from->file->points; 23914008Sedward Write(W_POINTS, from, 0, points, 0, 0, 0); 24014008Sedward unboard(ship, ship, 0); /* all offense */ 24114008Sedward unboard(ship, ship, 1); /* all defense */ 24214008Sedward switch (die()) { 24314008Sedward case 3: 24414008Sedward case 4: /* ship may sink */ 24514008Sedward Write(W_SINK, ship, 0, 1, 0, 0, 0); 24614008Sedward break; 24714008Sedward case 5: 24814008Sedward case 6: /* ship may explode */ 24914008Sedward Write(W_EXPLODE, ship, 0, 1, 0, 0, 0); 25014008Sedward break; 25111587Sleres } 25214008Sedward Write(W_SIGNAL, ship, 1, (int) "striking her colours!", 0, 0, 0); 25311587Sleres } 254