jiml@sphinx.UChicago.UUCP (Jim Lichtenstein) (06/14/85)
------------------------- CUT HERE ------------------------- #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # sail/assorted.c # sail/boarders.c # sail/game.c # sail/globals.c # sail/grap.c # sail/misc.c # sail/parties.c # sail/sail.log.c # sail/sync.c # sail/version.c # This archive created: Wed Jan 23 19:50:19 1985 cat << \SHAR_EOF > sail/assorted.c #ifndef lint static char *sccsid = "@(#)assorted.c 2.4 84/02/03"; #endif #include "externs.h" table(rig, shot, hittable, on, from, roll) struct ship *on, *from; int rig, shot, hittable, roll; { register int hhits = 0, chits = 0, ghits = 0, rhits = 0; int Ghit = 0, Hhit = 0, Rhit = 0, Chit = 0; int guns, car, pc, hull; int crew[3]; register int n; int rigg[4]; char *message; struct Tables *tp; pc = on->file->pcrew; hull = on->specs->hull; crew[0] = on->specs->crew1; crew[1] = on->specs->crew2; crew[2] = on->specs->crew3; rigg[0] = on->specs->rig1; rigg[1] = on->specs->rig2; rigg[2] = on->specs->rig3; rigg[3] = on->specs->rig4; if (shot == L_GRAPE) Chit = chits = hittable; else { tp = &(rig ? RigTable : HullTable)[hittable][roll-1]; Chit = chits = tp->C; Rhit = rhits = tp->R; Hhit = hhits = tp->H; Ghit = ghits = tp->G; if (on->file->FS) rhits *= 2; if (shot == L_CHAIN) { Ghit = ghits = 0; Hhit = hhits = 0; } } if (on->file->captured != 0) { pc -= (chits + 1) / 2; chits /= 2; } for (n = 0; n < 3; n++) if (chits > crew[n]) { chits -= crew[n]; crew[n] = 0; } else { crew[n] -= chits; chits = 0; } for (n = 0; n < 3; n++) if (rhits > rigg[n]){ rhits -= rigg[n]; rigg[n] = 0; } else { rigg[n] -= rhits; rhits = 0; } if (rigg[3] != -1 && rhits > rigg[3]) { rhits -= rigg[3]; rigg[3] = 0; } else if (rigg[3] != -1) { rigg[3] -= rhits; } if (rig && !rigg[2] && (!rigg[3] || rigg[3] == -1)) makesignal(on, "dismasted!", (struct ship *)0); if (portside(from, on, 0)) { guns = on->specs->gunR; car = on->specs->carR; } else { guns = on->specs->gunL; car = on->specs->carL; } if (ghits > car) { ghits -= car; car = 0; } else { car -= ghits; ghits = 0; } if (ghits > guns){ ghits -= guns; guns = 0; } else { guns -= ghits; ghits = 0; } hull -= ghits; if (Ghit) Write(portside(from, on, 0) ? W_GUNR : W_GUNL, on, 0, guns, car, 0, 0); hull -= hhits; hull = hull < 0 ? 0 : hull; if (on->file->captured != 0 && Chit) Write(W_PCREW, on, 0, pc, 0, 0, 0); if (Hhit) Write(W_HULL, on, 0, hull, 0, 0, 0); if (Chit) Write(W_CREW, on, 0, crew[0], crew[1], crew[2], 0); if (Rhit) Write(W_RIGG, on, 0, rigg[0], rigg[1], rigg[2], rigg[3]); switch (shot) { case L_ROUND: message = "firing round shot on %s (%c%c)"; break; case L_GRAPE: message = "firing grape shot on %s (%c%c)"; break; case L_CHAIN: message = "firing chain shot on %s (%c%c)"; break; case L_DOUBLE: message = "firing double shot on %s (%c%c)"; break; case L_EXPLODE: message = "exploding shot on %s (%c%c)"; } makesignal(from, message, on); if (roll == 6 && rig) { switch(Rhit) { case 0: message = "fore topsail sheets parted"; break; case 1: message = "mizzen shrouds parted"; break; case 2: message = "main topsail yard shot away"; break; case 4: message = "fore topmast and foremast shrouds shot away"; break; case 5: message = "mizzen mast and yard shot through"; break; case 6: message = "foremast and spritsail yard shattered"; break; case 7: message = "main topmast and mizzen mast shattered"; break; } makesignal(on, message, (struct ship *)0); } else if (roll == 6) { switch (Hhit) { case 0: message = "anchor cables severed"; break; case 1: message = "two anchor stocks shot away"; break; case 2: message = "quarterdeck bulwarks damaged"; break; case 3: message = "three gun ports shot away"; break; case 4: message = "four guns dismounted"; break; case 5: message = "rudder cables shot through"; Write(W_TA, on, 0, 0, 0, 0, 0); break; case 6: message = "shot holes below the water line"; break; } makesignal(on, message, (struct ship *)0); } /* if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) { on->specs->qual--; if (on->specs->qual <= 0) { makesignal(on, "crew mutinying!", (struct ship *)0); on->specs->qual = 5; Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0); } else makesignal(on, "crew demoralized", (struct ship *)0); Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0); } */ if (!hull) strike(on, from); } Cleansnag(from, to, all, flag) register struct ship *from, *to; char all, flag; { if (flag & 1) { Write(W_UNGRAP, from, 0, to->file->index, all, 0, 0); Write(W_UNGRAP, to, 0, from->file->index, all, 0, 0); } if (flag & 2) { Write(W_UNFOUL, from, 0, to->file->index, all, 0, 0); Write(W_UNFOUL, to, 0, from->file->index, all, 0, 0); } if (!snagged2(from, to)) { if (!snagged(from)) { unboard(from, from, 1); /* defense */ unboard(from, from, 0); /* defense */ } else unboard(from, to, 0); /* offense */ if (!snagged(to)) { unboard(to, to, 1); /* defense */ unboard(to, to, 0); /* defense */ } else unboard(to, from, 0); /* offense */ } } strike(ship, from) register struct ship *ship, *from; { int points; if (ship->file->struck) return; Write(W_STRUCK, ship, 0, 1, 0, 0, 0); points = ship->specs->pts + from->file->points; Write(W_POINTS, from, 0, points, 0, 0, 0); unboard(ship, ship, 0); /* all offense */ unboard(ship, ship, 1); /* all defense */ switch (die()) { case 3: case 4: /* ship may sink */ Write(W_SINK, ship, 0, 1, 0, 0, 0); break; case 5: case 6: /* ship may explode */ Write(W_EXPLODE, ship, 0, 1, 0, 0, 0); break; } Write(W_SIGNAL, ship, 1, (int) "striking her colours!", 0, 0, 0); } SHAR_EOF if test 5526 -ne "`wc -c sail/assorted.c`" then echo shar: error transmitting sail/assorted.c '(should have been 5526 characters)' fi cat << \SHAR_EOF > sail/boarders.c #ifndef lint static char *sccsid = "@(#)boarders.c 2.1 83/10/31"; #endif #include "externs.h" subtract(from, totalfrom, crewfrom, fromcap, pcfrom) struct ship *from, *fromcap; int pcfrom; register int totalfrom, crewfrom[3]; { register int n; if (fromcap == from && totalfrom) { /* if not captured */ for (n = 0; n < 3; n++) { if (totalfrom > crewfrom[n]) { totalfrom -= crewfrom[n]; crewfrom[n] = 0; } else { crewfrom[n] -= totalfrom; totalfrom = 0; } } Write(W_CREW, from, 0, crewfrom[0], crewfrom[1], crewfrom[2], 0); } else if (totalfrom) { pcfrom -= totalfrom; pcfrom = pcfrom < 0 ? 0 : pcfrom; Write(W_PCREW, from, 0, pcfrom, 0, 0, 0); } } mensent(from, to, crew, captured, pc, isdefense) struct ship *from, *to, **captured; int crew[3], *pc; char isdefense; { /* returns # of crew squares sent */ int men = 0; register int n; int c1, c2, c3; register struct BP *bp; *pc = from->file->pcrew; *captured = from->file->captured; crew[0] = from->specs->crew1; crew[1] = from->specs->crew2; crew[2] = from->specs->crew3; bp = isdefense ? from->file->DBP : from->file->OBP; for (n=0; n < NBP; n++, bp++) { if (bp->turnsent && bp->toship == to) men += bp->mensent; } if (men) { c1 = men/100 ? crew[0] : 0; c2 = (men%100)/10 ? crew[1] : 0; c3 = men/10 ? crew[2] : 0; c3 = *captured == 0 ? crew[2] : *pc; } else c1 = c2 = c3 = 0; return(c1 + c2 + c3); } SHAR_EOF if test 1432 -ne "`wc -c sail/boarders.c`" then echo shar: error transmitting sail/boarders.c '(should have been 1432 characters)' fi cat << \SHAR_EOF > sail/game.c #ifndef lint static char *sccsid = "@(#)game.c 2.1 83/10/31"; #endif #include "externs.h" maxturns(ship, af) register struct ship *ship; char *af; { register int turns; turns = ship->specs->ta; if (*af = (ship->file->drift > 1 && turns)) { turns--; if (ship->file->FS == 1) turns = 0; } return turns; } maxmove(ship, dir, fs) register struct ship *ship; int dir, fs; { register int riggone = 0, Move, flank = 0; Move = ship->specs->bs; if (!ship->specs->rig1) riggone++; if (!ship->specs->rig2) riggone++; if (!ship->specs->rig3) riggone++; if (!ship->specs->rig4) riggone++; if ((ship->file->FS || fs) && fs != -1) { flank = 1; Move = ship->specs->fs; } if (dir == winddir) Move -= 1 + WET[windspeed][ship->specs->class-1].B; else if (dir == winddir + 2 || dir == winddir - 2 || dir == winddir - 6 || dir == winddir + 6) Move -= 1 + WET[windspeed][ship->specs->class-1].C; else if (dir == winddir + 3 || dir == winddir - 3 || dir == winddir - 5 || dir == winddir + 5) Move = (flank ? 2 : 1) - WET[windspeed][ship->specs->class-1].D; else if (dir == winddir + 4 || dir == winddir - 4) Move = 0; else Move -= WET[windspeed][ship->specs->class-1].A; Move -= riggone; Move = Move < 0 ? 0 : Move; return(Move); } SHAR_EOF if test 1265 -ne "`wc -c sail/game.c`" then echo shar: error transmitting sail/game.c '(should have been 1265 characters)' fi cat << \SHAR_EOF > sail/globals.c /*LINTLIBRARY*/ #ifndef lint static char *sccsid = "@(#)globals.c 2.1 83/10/31"; #endif #include "externs.h" struct scenario scene[] = { /* * int winddir; * int windspeed; * int windchange; * int vessels; * char *name; * struct ship ship[NSHIP]; */ 5, 3, 5, 2, "Ranger vs. Drake", { { "Ranger", specs+0, N_A, 7, 20, 4, 0 }, { "Drake", specs+1, N_B, 7, 31, 5, 0 } }, 1, 3, 6, 2, "The Battle of Flamborough Head", { { "Bonhomme Rich", specs+2, N_A, 13, 40, 2, 0 }, { "Serapis", specs+3, N_B, 2, 42, 2, 0 } }, 5, 5, 5, 10, "Arbuthnot and Des Touches", { { "America", specs+4, N_B, 7, 37, 4, 0 }, { "Befford", specs+5, N_B, 5, 35, 4, 0 }, { "Adamant", specs+6, N_B, 3, 33, 4, 0 }, { "London", specs+7, N_B, 1, 31, 4, 0 }, { "Royal Oak", specs+8, N_B, -1, 29, 4, 0 }, { "Neptune", specs+9, N_F, 6, 44, 4, 0 }, { "Duc Bougogne", specs+10, N_F, 8, 46, 4, 0 }, { "Conquerant", specs+48, N_F, 10, 48, 4, 0 }, { "Provence", specs+11, N_F, 12, 50, 4, 0 }, { "Romulus", specs+12, N_F, 20, 58, 4, 0 } }, 1, 3, 5, 10, "Suffren and Hughes", { { "Monmouth", specs+52, N_B, 9, 45, 2, 0 }, { "Hero", specs+5, N_B, 13, 49, 2, 0 }, { "Isis", specs+6, N_B, 12, 48, 2, 0 }, { "Superb", specs+50, N_B, 10, 46, 2, 0 }, { "Burford", specs+48, N_B, 11, 47, 2, 0 }, { "Flamband", specs+13, N_F, 7, 59, 4, 0 }, { "Annibal", specs+9, N_F, 4, 56, 4, 0 }, { "Severe", specs+11, N_F, 2, 54, 4, 0 }, { "Brilliant", specs+49, N_F, -1, 51, 4, 0 }, { "Sphinx", specs+51, N_F, -5, 47, 4, 0 } }, 1, 3, 4, 2, "Nymphe vs. Cleopatre", { { "Nymphe", specs+14, N_B, 13, 30, 2, 0 }, { "Cleopatre", specs+15, N_F, 3, 41, 2, 0 } }, 1, 3, 5, 2, "Mars vs. Hercule", { { "Mars", specs+16, N_B, 13, 30, 2, 0 }, { "Hercule", specs+17, N_F, 3, 41, 2, 0 } }, 5, 3, 5, 2, "Ambuscade vs. Baionnaise", { { "Ambuscade", specs+18, N_B, 13, 30, 2, 0 }, { "Baionnaise", specs+19, N_F, 3, 41, 2, 0 } }, 1, 5, 6, 2, "Constellation vs. Insurgent", { { "Constellation", specs+20, N_A, 9, 50, 8, 0 }, { "Insurgent", specs+22, N_F, 4, 24, 2, 0 } }, 1, 3, 5, 2, "Constellation vs. Vengeance", { { "Constellation", specs+20, N_A, 12, 40, 2, 0 }, { "Vengeance", specs+21, N_F, 1, 43, 2, 0 } }, 1, 3, 6, 10, "The Battle of Lissa", { { "Amphion", specs+23, N_B, 8, 50, 4, 0 }, { "Active", specs+24, N_B, 6, 48, 4, 0 }, { "Volage", specs+25, N_B, 4, 46, 4, 0 }, { "Cerberus", specs+26, N_B, 2, 44, 4, 0 }, { "Favorite", specs+27, N_F, 9, 34, 2, 0 }, { "Flore", specs+21, N_F, 13, 39, 2, 0 }, { "Danae", specs+64, N_F, 15, 37, 2, 0 }, { "Bellona", specs+28, N_F, 17, 35, 2, 0 }, { "Corona", specs+29, N_F, 12, 31, 2, 0 }, { "Carolina", specs+30, N_F, 15, 28, 2, 0 } }, 2, 5, 6, 2, "Constitution vs. Guerriere", { { "Constitution", specs+31, N_A, 7, 35, 1, 0 }, { "Guerriere", specs+32, N_B, 7, 47, 4, 0 } }, 1, 3, 5, 2, "United States vs. Macedonian", { { "United States", specs+33, N_A, 1, 52, 6, 0 }, { "Macedonian", specs+34, N_B, 14, 40, 1, 0 } }, 1, 3, 6, 2, "Constitution vs. Java", { { "Constitution", specs+31, N_A, 1, 40, 2, 0 }, { "Java", specs+35, N_B, 11, 40, 2, 0 } }, 1, 3, 5, 2, "Chesapeake vs. Shannon", { { "Chesapeake", specs+36, N_A, 13, 40, 2, 0 }, { "Shannon", specs+37, N_B, 1, 42, 2, 0 } }, 1, 1, 6, 5, "The Battle of Lake Erie", { { "Lawrence", specs+38, N_A, 4, 55, 8, 0 }, { "Niagara", specs+42, N_A, 7, 61, 8, 0 }, { "Lady Prevost", specs+39, N_B, 4, 25, 2, 0 }, { "Detroit", specs+40, N_B, 7, 22, 2, 0 }, { "Q. Charlotte", specs+41, N_B, 10, 19, 2, 0 } }, 1, 1, 5, 2, "Wasp vs. Reindeer", { { "Wasp", specs+42, N_A, 3, 41, 2, 0 }, { "Reindeer", specs+43, N_B, 10, 48, 2, 0 } }, 1, 2, 5, 3, "Constitution vs. Cyane and Levant", { { "Constitution", specs+31, N_A, 10, 45, 2, 0 }, { "Cyane", specs+44, N_B, 3, 37, 2, 0 }, { "Levant", specs+45, N_B, 5, 35, 2, 0 } }, 5, 5, 5, 3, "Pellew vs. Droits de L'Homme", { { "Indefatigable", specs+46, N_B, 12, 45, 6, 0 }, { "Amazon", specs+47, N_B, 9, 48, 6, 0 }, { "Droits L'Hom", specs+48, N_F, 3, 28, 5, 0 } }, 2, 2, 3, 10, "Algeciras", { { "Caesar", specs+49, N_B, 7, 70, 6, 0 }, { "Pompee", specs+50, N_B, 5, 72, 6, 0 }, { "Spencer", specs+5, N_B, 3, 74, 6, 0 }, { "Hannibal", specs+7, N_B, 1, 76, 6, 0 }, { "Real-Carlos", specs+53, N_S, 9, 20, 3, 0 }, { "San Fernando", specs+54, N_S, 11, 16, 3, 0 }, { "Argonauta", specs+55, N_S, 10, 14, 4, 0 }, { "San Augustine", specs+56, N_S, 6, 22, 4, 0 }, { "Indomptable", specs+51, N_F, 7, 23, 5, 0 }, { "Desaix", specs+52, N_F, 7, 27, 7, 0 } }, 5, 3, 6, 7, "Lake Champlain", { { "Saratoga", specs+60, N_A, 8, 10, 1, 0 }, { "Eagle", specs+61, N_A, 9, 13, 2, 0 }, { "Ticonderoga", specs+62, N_A, 12, 17, 3, 0 }, { "Preble", specs+63, N_A, 14, 20, 2, 0 }, { "Confiance", specs+57, N_B, 4, 70, 6, 0 }, { "Linnet", specs+58, N_B, 7, 68, 6, 0 }, { "Chubb", specs+59, N_B, 10, 65, 6, 0 } }, 5, 3, 6, 4, "Last Voyage of the USS President", { { "President", specs+67, N_A, 12, 42, 5, 0 }, { "Endymion", specs+64, N_B, 5, 42, 5, 0 }, { "Pomone", specs+65, N_B, 7, 82, 6, 0 }, { "Tenedos", specs+66, N_B, 7, -1, 4, 0 } }, 7, 5, 5, 2, "Hornblower and the Natividad", { { "Lydia", specs+68, N_B, 12, 40, 2, 0 }, { "Natividad", specs+69, N_S, 2, 40, 4, 0 } }, 1, 3, 6, 2, "Curse of the Flying Dutchman", { { "Piece of Cake", specs+19, N_S, 7, 40, 2, 0 }, { "Flying Dutchy", specs+71, N_F, 7, 41, 1, 0 } }, 1, 4, 1, 4, "The South Pacific", { { "USS Scurvy", specs+70, N_A, 7, 40, 1, 0 }, { "HMS Tahiti", specs+71, N_B, 12, 60, 1, 0 }, { "Australian", specs+18, N_S, 5, 20, 8, 0 }, { "Bikini Atoll", specs+63, N_F, 2, 60, 4, 0 } }, 7, 3, 6, 5, "Hornblower and the battle of Rosas bay", { { "Sutherland", specs+5, N_B, 13, 30, 2, 0 }, { "Turenne", specs+10, N_F, 9, 35, 6, 0 }, { "Nightmare", specs+9, N_F, 7, 37, 6, 0 }, { "Paris", specs+53, N_F, 3, 45, 4, 0 }, { "Napolean", specs+56, N_F, 1, 40, 6, 0 } }, 6, 4, 7, 5, "Cape Horn", { { "Concord", specs+51, N_A, 3, 20, 4, 0 }, { "Berkeley", specs+7, N_A, 5, 50, 5, 0 }, { "Thames", specs+71, N_B, 10, 40, 1, 0 }, { "Madrid", specs+53, N_S, 13, 60, 8, 0 }, { "Musket", specs+10, N_F, 10, 60, 7, 0 } }, 8, 3, 7, 3, "New Orleans", { { "Alligator", specs+71, N_A, 13, 5, 1, 0 }, { "Firefly", specs+50, N_B, 10, 20, 8, 0 }, { "Cypress", specs+46, N_B, 5, 10, 6, 0 } }, 5, 3, 7, 3, "Botany Bay", { { "Shark", specs+11, N_B, 6, 15, 4, 0 }, { "Coral Snake", specs+31, N_F, 3, 30, 6, 0 }, { "Sea Lion", specs+33, N_F, 13, 50, 8, 0 } }, 4, 3, 6, 4, "Voyage to the Bottom of the Sea", { { "Seaview", specs+71, N_A, 6, 3, 3, 0 }, { "Flying Sub", specs+64, N_A, 8, 3, 3, 0 }, { "Mermaid", specs+70, N_B, 2, 5, 5, 0 }, { "Giant Squid", specs+53, N_S, 10, 30, 8, 0 } }, 7, 3, 6, 3, "Frigate Action", { { "Killdeer", specs+21, N_A, 7, 20, 8, 0 }, { "Sandpiper", specs+27, N_B, 5, 40, 8, 0 }, { "Curlew", specs+34, N_S, 10, 60, 8, 0 } }, 7, 2, 5, 6, "The Battle of Midway", { { "Enterprise", specs+49, N_A, 10, 70, 8, 0 }, { "Yorktown", specs+51, N_A, 3, 70, 7, 0 }, { "Hornet", specs+52, N_A, 6, 70, 7, 0 }, { "Akagi", specs+53, N_J, 6, 10, 4, 0 }, { "Kaga", specs+54, N_J, 4, 12, 4, 0 }, { "Soryu", specs+55, N_J, 2, 14, 4, 0 } }, 1, 3, 4, 8, "Star Trek", { { "Enterprise", specs+76, N_D,-10, 60, 7, 0 }, { "Yorktown", specs+77, N_D, 0, 70, 7, 0 }, { "Reliant", specs+78, N_D, 10, 70, 7, 0 }, { "Galileo", specs+79, N_D, 20, 60, 7, 0 }, { "Kobayashi Maru", specs+80, N_K, 0,120, 7, 0 }, { "Klingon II", specs+81, N_K, 10,120, 7, 0 }, { "Red Orion", specs+82, N_O, 0, 0, 3, 0 }, { "Blue Orion", specs+83, N_O, 10, 0, 3, 0 } } }; int nscene = sizeof scene / sizeof (struct scenario); struct shipspecs specs[] = { /* bs fs ta guns hull crew1 crew3 gunR carR rig2 rig4 pts */ /* class qual crew2 gunL carL rig1 rig3 */ /*00*/ 4, 7, 3, 19, 5, 5, 4, 2, 2, 2, 2, 2, 0, 0, 4, 4, 4, 4, 7, /*01*/ 4, 7, 3, 17, 5, 5, 4, 2, 2, 2, 0, 0, 4, 4, 3, 3, 3, 3, 6, /*02*/ 3, 5, 2, 42, 4, 7, 4, 2, 2, 2, 2, 2, 0, 0, 5, 5, 5, -1, 11, /*03*/ 4, 6, 3, 44, 3, 7, 4, 2, 2, 2, 3, 3, 0, 0, 5, 5, 5, 5, 12, /*04*/ 3, 5, 2, 64, 2, 17, 4, 8, 6, 6, 12, 12, 2, 2, 7, 7, 7, -1, 20, /*05*/ 3, 5, 2, 74, 2, 20, 4, 8, 8, 8, 16, 16, 2, 2, 7, 7, 7, -1, 26, /*06*/ 3, 5, 2, 50, 2, 12, 4, 6, 4, 4, 8, 8, 2, 2, 6, 6, 6, -1, 17, /*07*/ 3, 5, 1, 98, 1, 23, 4, 10, 10, 10, 18, 18, 2, 2, 8, 8, 8, -1, 28, /*08*/ 3, 5, 2, 74, 2, 20, 4, 8, 8, 8, 16, 16, 2, 2, 7, 7, 7, -1, 26, /*09*/ 3, 5, 2, 74, 2, 21, 3, 10, 10, 8, 20, 20, 0, 0, 7, 7, 7, -1, 24, /*10*/ 3, 5, 1, 80, 1, 23, 3, 12, 12, 10, 22, 22, 0, 0, 7, 7, 7, -1, 27, /*11*/ 3, 5, 2, 64, 2, 18, 3, 8, 8, 6, 12, 12, 0, 0, 7, 7, 7, -1, 18, /*12*/ 3, 5, 2, 44, 2, 11, 3, 4, 4, 4, 6, 6, 2, 2, 5, 5, 5, -1, 10, /*13*/ 3, 5, 2, 50, 2, 14, 3, 6, 6, 4, 8, 8, 0, 0, 6, 6, 6, -1, 14, /*14*/ 4, 6, 3, 36, 3, 11, 4, 4, 4, 2, 4, 4, 2, 2, 5, 5, 5, 5, 11, /*15*/ 4, 6, 3, 36, 3, 11, 3, 4, 4, 4, 4, 4, 2, 2, 5, 5, 5, 5, 10, /*16*/ 3, 5, 2, 74, 2, 21, 4, 10, 8, 8, 18, 18, 2, 2, 7, 7, 7, -1, 26, /*17*/ 3, 5, 2, 74, 2, 21, 3, 10, 10, 8, 20, 20, 2, 2, 7, 7, 7, -1, 23, /*18*/ 4, 6, 3, 32, 3, 8, 3, 4, 2, 2, 4, 4, 2, 2, 5, 5, 5, 5, 9, /*19*/ 4, 6, 3, 24, 4, 6, 3, 4, 4, 4, 2, 2, 0, 0, 4, 4, 4, 4, 9, /*20*/ 4, 7, 3, 38, 4, 14, 5, 6, 4, 4, 4, 4, 6, 6, 5, 5, 5, 5, 17, /*21*/ 4, 6, 3, 40, 3, 15, 3, 8, 6, 6, 6, 6, 4, 4, 5, 5, 5, 5, 15, /*22*/ 4, 7, 3, 36, 4, 11, 3, 6, 6, 4, 4, 4, 2, 2, 5, 5, 5, 5, 11, /*23*/ 4, 6, 3, 32, 3, 11, 5, 4, 4, 2, 4, 4, 2, 2, 5, 5, 5, 5, 13, /*24*/ 4, 6, 3, 38, 3, 14, 5, 4, 4, 4, 6, 6, 4, 4, 5, 5, 5, 5, 18, /*25*/ 4, 6, 3, 22, 3, 6, 5, 2, 2, 2, 0, 0, 8, 8, 4, 4, 4, 4, 11, /*26*/ 4, 6, 3, 32, 3, 11, 5, 4, 4, 2, 4, 4, 2, 2, 5, 5, 5, 5, 13, /*27*/ 4, 6, 3, 40, 3, 14, 3, 6, 6, 4, 6, 6, 4, 4, 5, 5, 5, 5, 15, /*28*/ 4, 6, 3, 32, 3, 11, 2, 4, 4, 4, 4, 4, 0, 0, 5, 5, 5, 5, 9, /*29*/ 4, 6, 3, 40, 3, 14, 2, 6, 6, 4, 6, 6, 4, 4, 5, 5, 5, 5, 12, /*30*/ 4, 6, 3, 32, 3, 8, 2, 4, 4, 1, 2, 2, 0, 0, 4, 4, 4, 4, 7, /*31*/ 4, 7, 3, 44, 4, 18, 5, 6, 6, 6, 8, 8, 6, 6, 6, 6, 6, 6, 24, /*32*/ 4, 6, 3, 38, 3, 14, 4, 4, 4, 2, 6, 6, 4, 4, 5, 5, 5, 5, 15, /*33*/ 4, 5, 3, 44, 3, 18, 5, 8, 6, 6, 8, 8, 8, 8, 6, 6, 6, 6, 24, /*34*/ 4, 6, 3, 38, 3, 14, 4, 4, 4, 4, 6, 6, 4, 4, 5, 5, 5, 5, 16, /*35*/ 4, 7, 3, 38, 4, 14, 4, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 19, /*36*/ 4, 6, 3, 38, 3, 14, 3, 6, 6, 4, 6, 6, 6, 6, 5, 5, 5, 5, 14, /*37*/ 4, 6, 3, 38, 3, 14, 5, 6, 4, 4, 6, 6, 6, 6, 5, 5, 5, 5, 17, /*38*/ 4, 7, 3, 20, 5, 6, 4, 4, 2, 2, 0, 0, 6, 6, 4, 4, 4, 4, 9, /*39*/ 4, 7, 3, 13, 6, 3, 4, 0, 2, 2, 0, 0, 2, 2, 2, 2, 2, 2, 5, /*40*/ 4, 7, 3, 19, 5, 5, 4, 2, 2, 2, 2, 2, 0, 0, 4, 4, 4, 4, 7, /*41*/ 4, 7, 3, 17, 5, 5, 4, 2, 2, 2, 2, 2, 0, 0, 3, 3, 3, 3, 6, /*42*/ 4, 7, 3, 20, 5, 6, 5, 4, 2, 2, 0, 0, 6, 6, 4, 4, 4, 4, 12, /*43*/ 4, 7, 3, 18, 5, 5, 5, 2, 2, 2, 0, 0, 6, 6, 4, 4, 4, 4, 9, /*44*/ 4, 7, 3, 24, 5, 6, 4, 4, 2, 2, 0, 0,10,10, 4, 4, 4, 4, 11, /*45*/ 4, 7, 3, 20, 5, 6, 4, 2, 2, 2, 0, 0, 8, 8, 4, 4, 4, 4, 10, /*46*/ 4, 6, 3, 44, 3, 11, 5, 4, 4, 4, 4, 4, 2, 2, 5, 5, 5, 5, 14, /*47*/ 4, 6, 3, 36, 3, 12, 4, 4, 4, 4, 6, 6, 2, 2, 5, 5, 5, 5, 14, /*48*/ 3, 5, 2, 74, 2, 21, 3, 10, 8, 8, 20, 20, 2, 2, 4, 4, 7, -1, 24, /*49*/ 3, 5, 2, 80, 2, 24, 4, 10, 8, 8, 20, 20, 2, 2, 8, 8, 8, -1, 31, /*50*/ 3, 5, 2, 74, 2, 21, 4, 8, 8, 6, 16, 16, 4, 4, 7, 7, 7, -1, 27, /*51*/ 3, 5, 2, 80, 2, 24, 3, 12, 12, 10, 22, 22, 2, 2, 7, 7, 7, -1, 27, /*52*/ 3, 5, 2, 74, 2, 21, 3, 10, 10, 8, 20, 20, 2, 2, 7, 7, 7, -1, 24, /*53*/ 3, 5, 1, 112, 1, 27, 2, 12, 12, 12, 24, 24, 0, 0, 9, 9, 9, -1, 27, /*54*/ 3, 5, 1, 96, 1, 24, 2, 12, 12, 10, 20, 20, 0, 0, 8, 8, 8, -1, 24, /*55*/ 3, 5, 2, 80, 2, 23, 2, 10, 10, 8, 20, 20, 0, 0, 7, 7, 7, -1, 23, /*56*/ 3, 5, 2, 74, 2, 21, 2, 10, 8, 8, 16, 16, 4, 4, 7, 7, 7, -1, 20, /*57*/ 4, 6, 3, 37, 3, 12, 4, 4, 4, 2, 6, 6, 4, 4, 5, 5, 5, 5, 14, /*58*/ 4, 7, 3, 16, 5, 5, 5, 2, 2, 2, 0, 0, 4, 4, 4, 4, 4, 4, 10, /*59*/ 4, 7, 3, 11, 6, 3, 4, 2, 2, 2, 0, 0, 2, 2, 2, 2, 2, 2, 5, /*60*/ 4, 7, 3, 26, 5, 6, 4, 4, 2, 2, 2, 2, 6, 6, 4, 4, 4, 4, 12, /*61*/ 4, 7, 3, 20, 5, 6, 4, 4, 2, 2, 0, 0, 6, 6, 4, 4, 4, 4, 11, /*62*/ 4, 7, 3, 17, 5, 5, 4, 2, 2, 2, 0, 0, 6, 6, 4, 4, 4, 4, 9, /*63*/ 4, 7, 3, 7, 6, 3, 4, 0, 2, 2, 0, 0, 2, 2, 2, 2, 2, 2, 4, /*64*/ 4, 6, 3, 40, 3, 15, 4, 4, 4, 4, 8, 8, 6, 6, 5, 5, 5, 5, 17, /*65*/ 4, 6, 3, 44, 3, 15, 4, 8, 8, 6, 10, 10, 2, 2, 6, 6, 6, 6, 20, /*66*/ 4, 6, 3, 38, 3, 14, 4, 4, 4, 4, 6, 6, 6, 6, 5, 5, 5, 5, 15, /*67*/ 4, 5, 3, 44, 3, 18, 5, 8, 6, 6, 8, 8, 8, 8, 6, 6, 6, 6, 24, /*68*/ 4, 6, 3, 36, 3, 9, 5, 4, 4, 2, 4, 4, 2, 2, 5, 5, 5, 5, 13, /*69*/ 3, 5, 2, 50, 2, 14, 2, 6, 6, 6, 8, 8, 0, 0, 6, 6, 6, -1, 14, /*70*/ 3, 5, 1, 136, 1, 30, 1, 8, 14, 14, 28, 28, 0, 0, 9, 9, 9, -1, 27, /*71*/ 3, 5, 1, 120, 1, 27, 5, 16, 14, 14, 28, 28, 2, 2, 9, 9, 9, -1, 43, /*72*/ 3, 5, 1, 120, 2, 21, 5, 15, 17, 15, 25, 25, 7, 7, 9, 9, 9, -1, 36, /*73*/ 3, 5, 1, 90, 3, 18, 4, 13, 15, 13, 20, 20, 6, 6, 5, 5, 5, 5, 28, /*74*/ 4, 7, 3, 6, 6, 3, 4, 2, 2, 2, 20, 20, 6, 6, 2, 2, 3, 3, 5, /*75*/ 3, 5, 1, 110, 2, 20, 4, 14, 15, 11, 26, 26, 8, 8, 7, 8, 9, -1, 34, /*76*/ 4, 7, 3, 450, 1, 99, 5, 50, 40, 40, 50, 50,25,25, 9, 9, 9, -1, 75, /*77*/ 4, 7, 3, 450, 1, 99, 5, 50, 40, 40, 50, 50,25,25, 9, 9, 9, -1, 75, /*78*/ 4, 7, 3, 450, 1, 99, 5, 50, 40, 40, 50, 50,25,25, 9, 9, 9, -1, 75, /*79*/ 4, 7, 3, 450, 1, 99, 5, 50, 40, 40, 50, 50,25,25, 9, 9, 9, -1, 75, /*80*/ 4, 7, 3, 450, 1, 99, 5, 50, 40, 40, 50, 50,25,25, 9, 9, 9, -1, 75, /*81*/ 4, 7, 3, 450, 1, 99, 5, 50, 40, 40, 50, 50,25,25, 9, 9, 9, -1, 75, /*82*/ 4, 7, 3, 450, 1, 99, 5, 50, 40, 40, 50, 50,25,25, 9, 9, 9, -1, 75, /*83*/ 4, 7, 3, 450, 1, 99, 5, 50, 40, 40, 50, 50,25,25, 9, 9, 9, -1, 75, /* bs fs ta guns hull crew1 crew3 gunR carR rig2 rig4 pts */ /* class qual crew2 gunL carL rig1 rig3 */ }; struct windeffects WET[7][6] = { { {9,9,9,9}, {9,9,9,9}, {9,9,9,9}, {9,9,9,9}, {9,9,9,9}, {9,9,9,9} }, { {3,2,2,0}, {3,2,1,0}, {3,2,1,0}, {3,2,1,0}, {2,1,0,0}, {2,1,0,0} }, { {1,1,1,0}, {1,1,0,0}, {1,0,0,0}, {1,0,0,0}, {1,0,0,0}, {1,0,0,0} }, { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} }, { {0,0,0,0}, {1,0,0,0}, {1,1,0,0}, {1,1,0,0}, {2,2,1,0}, {2,2,1,0} }, { {1,0,0,0}, {1,1,0,0}, {1,1,1,0}, {1,1,1,0}, {3,2,2,0}, {3,2,2,0} }, { {2,1,1,0}, {3,2,1,0}, {3,2,1,0}, {3,2,1,0}, {3,3,2,0}, {3,3,2,0} } }; struct Tables RigTable[11][6] = { { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,1}, {0,0,1,0} }, { {0,0,0,0}, {0,0,0,0}, {0,0,0,1}, {0,0,1,0}, {1,0,0,1}, {0,1,1,1} }, { {0,0,0,0}, {0,0,0,1}, {0,0,1,1}, {0,1,0,1}, {0,1,0,1}, {1,0,1,2} }, { {0,0,0,0}, {0,0,1,1}, {0,1,0,1}, {0,0,0,2}, {0,1,0,2}, {1,0,1,2} }, { {0,1,0,1}, {1,0,0,1}, {0,1,1,2}, {0,1,0,2}, {0,0,1,3}, {1,0,1,4} }, { {0,0,1,1}, {0,1,0,2}, {1,0,0,3}, {0,1,1,3}, {1,0,0,4}, {1,1,1,4} }, { {0,0,1,2}, {0,1,1,2}, {1,1,0,3}, {0,1,0,4}, {1,0,0,4}, {1,0,1,5} }, { {0,0,1,2}, {0,1,0,3}, {1,1,0,3}, {1,0,2,4}, {0,2,1,5}, {2,1,0,5} }, { {0,2,1,3}, {1,0,0,3}, {2,1,0,4}, {0,1,1,4}, {0,1,0,5}, {1,0,2,6} }, { {1,1,0,4}, {1,0,1,4}, {2,0,0,5}, {0,2,1,5}, {0,1,2,6}, {0,2,0,7} }, { {1,0,1,5}, {0,2,0,6}, {1,2,0,6}, {1,1,1,6}, {2,0,2,6}, {1,1,2,7} } }; struct Tables HullTable[11][6] = { { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {1,0,0,0}, {0,1,0,0} }, { {0,0,0,0}, {0,0,0,0}, {0,1,0,0}, {1,1,0,0}, {1,0,1,0}, {1,0,1,1} }, { {0,1,0,0}, {1,0,0,0}, {1,1,0,0}, {1,0,1,0}, {1,0,1,1}, {2,1,0,0} }, { {0,1,1,0}, {1,0,0,0}, {1,1,1,0}, {2,0,0,1}, {2,0,1,0}, {2,2,0,0} }, { {0,1,1,0}, {1,0,0,1}, {2,1,0,1}, {2,2,1,0}, {3,0,1,0}, {3,1,0,0} }, { {1,1,1,0}, {2,0,2,1}, {2,1,1,0}, {2,2,0,0}, {3,1,0,1}, {3,1,1,0} }, { {1,2,2,0}, {2,0,2,1}, {2,1,0,1}, {2,2,0,0}, {3,1,1,0}, {4,2,1,0} }, { {2,1,1,0}, {2,0,1,1}, {3,2,2,0}, {3,2,0,0}, {4,2,1,0}, {4,2,1,1} }, { {2,1,2,0}, {3,1,1,1}, {3,2,2,0}, {4,2,1,0}, {4,1,0,2}, {4,2,2,0} }, { {2,3,1,0}, {3,2,2,0}, {3,2,2,1}, {4,2,2,0}, {4,1,0,3}, {5,1,2,0} }, { {2,2,4,0}, {3,3,1,1}, {4,2,1,1}, {5,1,0,2}, {5,1,2,1}, {6,2,2,0} }, }; char AMMO[9][4] = { { -1, 1, 0, 1 }, { -1, 1, 0, 1 }, { -1, 1, 0, 1 }, { -2, 1, 0, 2 }, { -2, 2, 0, 2 }, { -2, 2, 0, 2 }, { -3, 2, 0, 2 }, { -3, 2, 0, 3 }, { -3, 2, 0, 3 } }; char HDT[9][10] = { { 1, 0,-1,-2,-3,-3,-4,-4,-4,-4 }, { 1, 1, 0,-1,-2,-2,-3,-3,-3,-3 }, { 2, 1, 0,-1,-2,-2,-3,-3,-3,-3 }, { 2, 2, 1, 0,-1,-1,-2,-2,-2,-2 }, { 3, 2, 1, 0,-1,-1,-2,-2,-2,-2 }, { 3, 3, 2, 1, 0, 0,-1,-1,-1,-1 }, { 4, 3, 2, 1, 0, 0,-1,-1,-1,-1 }, { 4, 4, 3, 2, 1, 1, 0, 0, 0, 0 }, { 5, 4, 3, 2, 1, 1, 0, 0, 0, 0 } }; char HDTrake[9][10] = { { 2, 1, 0,-1,-2,-2,-3,-3,-3,-3 }, { 2, 2, 1, 0,-1,-1,-2,-2,-2,-2 }, { 3, 2, 1, 0,-1,-1,-2,-2,-2,-2 }, { 4, 3, 2, 1, 0, 0,-1,-1,-1,-1 }, { 5, 4, 3, 2, 1, 1, 0, 0, 0, 0 }, { 6, 5, 4, 3, 2, 2, 1, 1, 1, 1 }, { 7, 6, 5, 4, 3, 3, 2, 2, 2, 2 }, { 8, 7, 6, 5, 4, 4, 3, 3, 3, 3 }, { 9, 8, 7, 6, 5, 5, 4, 4, 4, 4 } }; char QUAL[9][5] = { { -1, 0, 0, 1, 1 }, { -1, 0, 0, 1, 1 }, { -1, 0, 0, 1, 2 }, { -1, 0, 0, 1, 2 }, { -1, 0, 0, 2, 2 }, { -1,-1, 0, 2, 2 }, { -2,-1, 0, 2, 2 }, { -2,-1, 0, 2, 2 }, { -2,-1, 0, 2, 3 } }; char MT[9][3] = { { 1, 0, 0 }, { 1, 1, 0 }, { 2, 1, 0 }, { 2, 1, 1 }, { 2, 2, 1 }, { 3, 2, 1 }, { 3, 2, 2 }, { 4, 3, 2 }, { 4, 4, 2 } }; char rangeofshot[] = { 0, 1, /* grape */ 3, /* chain */ 10, /* round */ 1 /* double */ }; char *countryname[] = { "American", "British", "Spanish", "French", "Japanese", "Federation", "Klingon", "Orion" }; char *classname[] = { "Drift wood", "Ship of the Line", "Ship of the Line", "Frigate", "Corvette", "Sloop", "Brig" }; char *directionname[] = { "dead ahead", "off the starboard bow", "off the starboard beam", "off the starboard quarter", "dead astern", "off the port quarter", "off the port beam", "off the port bow", "dead ahead" }; char *qualname[] = { "dead", "mutinous", "green", "mundane", "crack", "elite" }; char loadname[] = { '-', 'G', 'C', 'R', 'D', 'E' }; char dr[] = { 0, 1, 1, 0, -1, -1, -1, 0, 1 }; char dc[] = { 0, 0, -1, -1, -1, 0, 1, 1, 1 }; SHAR_EOF if test 18869 -ne "`wc -c sail/globals.c`" then echo shar: error transmitting sail/globals.c '(should have been 18869 characters)' fi cat << \SHAR_EOF > sail/grap.c #ifndef lint static char *sccsid = "@(#)grap.c 2.2 83/12/17"; #endif #include "externs.h" ungrap(from, to) register struct ship *from, *to; { register k; char friend; if ((k = grappled2(from, to)) == 0) return; friend = capship(from)->nationality == capship(to)->nationality; while (--k >= 0) { if (friend || die() < 3) { cleangrapple(from, to, 0); makesignal(from, "ungrappling %s (%c%c)", to); } } } grap(from, to) register struct ship *from, *to; { if (capship(from)->nationality != capship(to)->nationality && die() > 2) return; Write(W_GRAP, from, 0, to->file->index, 0, 0, 0); Write(W_GRAP, to, 0, from->file->index, 0, 0, 0); makesignal(from, "grappled with %s (%c%c)", to); } SHAR_EOF if test 711 -ne "`wc -c sail/grap.c`" then echo shar: error transmitting sail/grap.c '(should have been 711 characters)' fi cat << \SHAR_EOF > sail/misc.c #ifndef lint static char *sccsid = "@(#)misc.c 2.3 84/02/23"; #endif #include "externs.h" #define distance(x,y) (abs(x) >= abs(y) ? abs(x) + abs(y)/2 : abs(y) + abs(x)/2) /* XXX */ range(from, to) struct ship *from, *to; { register bow1r, bow1c, bow2r, bow2c; int stern1r, stern1c, stern2c, stern2r; register int bb, bs, sb, ss, result; if (!to->file->dir) return -1; stern1r = bow1r = from->file->row; stern1c = bow1c = from->file->col; stern2r = bow2r = to->file->row; stern2c = bow2c = to->file->col; result = bb = distance(bow2r - bow1r, bow2c - bow1c); if (bb < 5) { stern2r += dr[to->file->dir]; stern2c += dc[to->file->dir]; stern1r += dr[from->file->dir]; stern1c += dc[from->file->dir]; bs = distance((bow2r - stern1r), (bow2c - stern1c)); sb = distance((bow1r - stern2r), (bow1c - stern2c)); ss = distance((stern2r - stern1r) ,(stern2c - stern1c)); result = min(bb, min(bs, min(sb, ss))); } return result; } struct ship * closestenemy(from, side, anyship) register struct ship *from; char side, anyship; { register struct ship *sp; register char a; int olddist = 30000, dist; struct ship *closest = 0; a = capship(from)->nationality; foreachship(sp) { if (sp == from) continue; if (sp->file->dir == 0) continue; if (a == capship(sp)->nationality && !anyship) continue; if (side && gunsbear(from, sp) != side) continue; dist = range(from, sp); if (dist < olddist) { closest = sp; olddist = dist; } } return closest; } angle(dr, dc) register dr, dc; { register i; if (dc >= 0 && dr > 0) i = 0; else if (dr <= 0 && dc > 0) i = 2; else if (dc <= 0 && dr < 0) i = 4; else i = 6; dr = abs(dr); dc = abs(dc); if ((i == 0 || i == 4) && dc * 2.4 > dr) { i++; if (dc > dr * 2.4) i++; } else if ((i == 2 || i == 6) && dr * 2.4 > dc) { i++; if (dr > dc * 2.4) i++; } return i % 8 + 1; } gunsbear(from, to) /* checks for target bow or stern */ register struct ship *from, *to; { int Dr, Dc, i; register ang; Dr = from->file->row - to->file->row; Dc = to->file->col - from->file->col; for (i = 2; i; i--) { if ((ang = angle(Dr, Dc) - from->file->dir + 1) < 1) ang += 8; if (ang >= 2 && ang <= 4) return 'r'; if (ang >= 6 && ang <= 7) return 'l'; Dr += dr[to->file->dir]; Dc += dc[to->file->dir]; } return 0; } portside(from, on, quick) register struct ship *from, *on; int quick; /* returns true if fromship is */ { /* shooting at onship's starboard side */ register ang; register Dr, Dc; Dr = from->file->row - on->file->row; Dc = on->file->col - from->file->col; if (quick == -1) { Dr += dr[on->file->dir]; Dc += dc[on->file->dir]; } ang = angle(Dr, Dc); if (quick != 0) return ang; ang = (ang + 4 - on->file->dir - 1) % 8 + 1; return ang < 5; } colours(sp) register struct ship *sp; { register char flag; if (sp->file->struck) flag = '!'; if (sp->file->explode) flag = '#'; if (sp->file->sink) flag = '~'; if (sp->file->struck) return flag; flag = *countryname[capship(sp)->nationality]; return sp->file->FS ? flag : tolower(flag); } #include <sys/file.h> log(s) register struct ship *s; { FILE *fp; int persons; int n; struct logs log[NLOG]; float net; register struct logs *lp; if ((fp = fopen(LOGFILE, "r+")) == NULL) return; #ifdef LOCK_EX if (flock(fileno(fp), LOCK_EX) < 0) return; #endif net = (float)s->file->points / s->specs->pts; persons = getw(fp); n = fread((char *)log, sizeof(struct logs), NLOG, fp); for (lp = &log[n]; lp < &log[NLOG]; lp++) lp->l_name[0] = lp->l_uid = lp->l_shipnum = lp->l_gamenum = lp->l_netpoints = 0; rewind(fp); if (persons < 0) (void) putw(1, fp); else (void) putw(persons + 1, fp); for (lp = log; lp < &log[NLOG]; lp++) if (net > (float)lp->l_netpoints / scene[lp->l_gamenum].ship[lp->l_shipnum].specs->pts) { (void) fwrite((char *)log, sizeof (struct logs), lp - log, fp); (void) strcpy(log[NLOG-1].l_name, s->file->captain); log[NLOG-1].l_uid = getuid(); log[NLOG-1].l_shipnum = s->file->index; log[NLOG-1].l_gamenum = game; log[NLOG-1].l_netpoints = s->file->points; (void) fwrite((char *)&log[NLOG-1], sizeof (struct logs), 1, fp); (void) fwrite((char *)lp, sizeof (struct logs), &log[NLOG-1] - lp, fp); break; } #ifdef LOCK_EX (void) flock(fileno(fp), LOCK_UN); #endif (void) fclose(fp); } SHAR_EOF if test 4396 -ne "`wc -c sail/misc.c`" then echo shar: error transmitting sail/misc.c '(should have been 4396 characters)' fi cat << \SHAR_EOF > sail/parties.c #ifndef lint static char *sccsid = "@(#)parties.c 2.2 83/12/17"; #endif #include "externs.h" meleeing(from, to) struct ship *from; register struct ship *to; { register struct BP *p = from->file->OBP; register struct BP *q = p + NBP; for (; p < q; p++) if (p->turnsent && p->toship == to) return 1; return 0; } boarding(from, isdefense) register struct ship *from; char isdefense; { register struct BP *p = isdefense ? from->file->DBP : from->file->OBP; register struct BP *q = p + NBP; for (; p < q; p++) if (p->turnsent) return 1; return 0; } unboard(ship, to, isdefense) register struct ship *ship, *to; register char isdefense; { register struct BP *p = isdefense ? ship->file->DBP : ship->file->OBP; register n; for (n = 0; n < NBP; p++, n++) if (p->turnsent && (p->toship == to || isdefense || ship == to)) Write(isdefense ? W_DBP : W_OBP, ship, 0, n, 0, 0, 0); } SHAR_EOF if test 902 -ne "`wc -c sail/parties.c`" then echo shar: error transmitting sail/parties.c '(should have been 902 characters)' fi cat << \SHAR_EOF > sail/sail.log.c #ifndef lint static char *sccsid = "@(#)sail.log.c 2.1 83/10/31"; #endif /* * Print out the top ten SAILors * * sail.log [-s/l] * * -s force a short listing (without real usernames) * -l force a long listing (print out real usernames) */ #include <pwd.h> #include "externs.h" char *title[] = { "Admiral", "Commodore", "Captain", "Captain", "Captain", "Captain", "Captain", "Commander", "Commander", "Lieutenant" }; main(argc, argv) int argc; char **argv; { FILE *fp; char sbuf[32]; int n = 0, people; int usrnam = 0; struct passwd *getpwuid(), *pass; struct logs log; struct ship *ship; if (argc > 1 && argc == 2) if (strcmp(argv[1], "-s") == 0) usrnam = 0; else if (strcmp(argv[1], "-l") == 0) usrnam = 1; else { fprintf(stderr, "usage: %s: [-s/l]\n", argv[0]); exit(1); } if ((fp = fopen(LOGFILE, "r")) == 0) { perror(LOGFILE); exit(1); } switch (fread((char *)&people, sizeof people, 1, fp)) { case 0: printf("Nobody has sailed yet.\n"); exit(0); case 1: break; default: perror(LOGFILE); exit(1); } while (fread((char *)&log, sizeof log, 1, fp) == 1 && log.l_name[0] != '\0') { if (usrnam && (pass = getpwuid(log.l_uid)) != NULL) (void) sprintf(sbuf, "%10.10s (%s)", log.l_name, pass->pw_name); else (void) sprintf(sbuf, "%20.20s", log.l_name); ship = &scene[log.l_gamenum].ship[log.l_shipnum]; printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n", title[n++], sbuf, ship->shipname, log.l_netpoints, (float) log.l_netpoints / ship->specs->pts); } printf("\n%d people have played.\n", people); } SHAR_EOF if test 1603 -ne "`wc -c sail/sail.log.c`" then echo shar: error transmitting sail/sail.log.c '(should have been 1603 characters)' fi cat << \SHAR_EOF > sail/sync.c #ifndef lint static char *sccsid = "@(#)sync.c 2.6 84/04/28"; #endif #include "externs.h" #include <sys/file.h> #include <sys/errno.h> static char sync_buf[BUFSIZE]; static char *sync_bp = sync_buf; static char sync_lock[25]; static char sync_file[25]; static long sync_seek; static FILE *sync_fp; #define SF "/tmp/#sailsink.%d" #define LF "/tmp/#saillock.%d" /*VARARGS3*/ makesignal(from, fmt, ship, a, b, c) struct ship *from; char *fmt; register struct ship *ship; { char message[80]; if (ship == 0) (void) sprintf(message, fmt, a, b, c); else (void) sprintf(message, fmt, ship->shipname, colours(ship), sterncolour(ship), a, b, c); Write(W_SIGNAL, from, 1, (int)message, 0, 0, 0); } #include <sys/types.h> #include <sys/stat.h> sync_exists(game) { char buf[sizeof sync_file]; struct stat s; time_t t; (void) sprintf(buf, SF, game); (void) time(&t); if (stat(buf, &s) < 0) return 0; if (s.st_mtime < t - 60*60*2) { /* 2 hours */ (void) unlink(buf); (void) sprintf(buf, LF, game); (void) unlink(buf); return 0; } else return 1; } sync_open() { (void) sprintf(sync_lock, LF, game); (void) sprintf(sync_file, SF, game); if (access(sync_file, 0) < 0) { int omask; #ifdef SETUID omask = umask(077); #else omask = umask(011); #endif sync_fp = fopen(sync_file, "w+"); (void) umask(omask); } else sync_fp = fopen(sync_file, "r+"); if (sync_fp == 0) return -1; sync_seek == 0; return 0; } sync_close(remove) char remove; { if (sync_fp != 0) (void) fclose(sync_fp); if (remove) (void) unlink(sync_file); } Write(type, ship, isstr, a, b, c, d) int type; struct ship *ship; char isstr; int a, b, c, d; { if (isstr) (void) sprintf(sync_bp, "%d %d %d %s\n", type, ship->file->index, isstr, a); else (void) sprintf(sync_bp, "%d %d %d %d %d %d %d\n", type, ship->file->index, isstr, a, b, c, d); while (*sync_bp++) ; sync_bp--; if (sync_bp >= &sync_buf[sizeof sync_buf]) abort(); (void) sync_update(type, ship, a, b, c, d); } Sync() { int (*sig1)(), (*sig2)(); register n; int type, shipnum, isstr, a, b, c, d; char buf[80]; char erred = 0; extern errno; sig1 = signal(SIGHUP, SIG_IGN); sig2 = signal(SIGINT, SIG_IGN); for (n = TIMEOUT; --n >= 0;) { #ifdef LOCK_EX if (flock(fileno(sync_fp), LOCK_EX|LOCK_NB) >= 0) break; if (errno != EWOULDBLOCK) return -1; #else if (link(sync_file, sync_lock) >= 0) break; if (errno != EEXIST) return -1; #endif sleep(1); } if (n <= 0) return -1; (void) fseek(sync_fp, sync_seek, 0); for (;;) { switch (fscanf(sync_fp, "%d%d%d", &type, &shipnum, &isstr)) { case 3: break; case EOF: goto out; default: goto bad; } if (shipnum < 0 || shipnum >= cc->vessels) goto bad; if (isstr != 0 && isstr != 1) goto bad; if (isstr) { register char *p; for (p = buf;;) { switch (*p++ = getc(sync_fp)) { case '\n': p--; case EOF: break; default: if (p >= buf + sizeof buf) p--; continue; } break; } *p = 0; for (p = buf; *p == ' '; p++) ; a = (int)p; b = c = d = 0; } else if (fscanf(sync_fp, "%d%d%d%d", &a, &b, &c, &d) != 4) goto bad; if (sync_update(type, SHIP(shipnum), a, b, c, d) < 0) goto bad; } bad: erred++; out: if (!erred && sync_bp != sync_buf) { (void) fseek(sync_fp, 0L, 2); (void) fputs(sync_buf, sync_fp); (void) fflush(sync_fp); sync_bp = sync_buf; } sync_seek = ftell(sync_fp); #ifdef LOCK_EX (void) flock(fileno(sync_fp), LOCK_UN); #else (void) unlink(sync_lock); #endif (void) signal(SIGHUP, sig1); (void) signal(SIGINT, sig2); return erred ? -1 : 0; } sync_update(type, ship, a, b, c, d) int type; register struct ship *ship; int a, b, c, d; { switch (type) { case W_DBP: { register struct BP *p = &ship->file->DBP[a]; p->turnsent = b; p->toship = SHIP(c); p->mensent = d; break; } case W_OBP: { register struct BP *p = &ship->file->OBP[a]; p->turnsent = b; p->toship = SHIP(c); p->mensent = d; break; } case W_FOUL: { register struct snag *p = &ship->file->foul[a]; if (SHIP(a)->file->dir == 0) break; if (p->sn_count++ == 0) p->sn_turn = turn; ship->file->nfoul++; break; } case W_GRAP: { register struct snag *p = &ship->file->grap[a]; if (SHIP(a)->file->dir == 0) break; if (p->sn_count++ == 0) p->sn_turn = turn; ship->file->ngrap++; break; } case W_UNFOUL: { register struct snag *p = &ship->file->foul[a]; if (p->sn_count > 0) if (b) { ship->file->nfoul -= p->sn_count; p->sn_count = 0; } else { ship->file->nfoul--; p->sn_count--; } break; } case W_UNGRAP: { register struct snag *p = &ship->file->grap[a]; if (p->sn_count > 0) if (b) { ship->file->ngrap -= p->sn_count; p->sn_count = 0; } else { ship->file->ngrap--; p->sn_count--; } break; } case W_SIGNAL: if (isplayer) Signal("\7%s (%c%c): %s", ship, a); break; case W_CREW: { register struct shipspecs *s = ship->specs; s->crew1 = a; s->crew2 = b; s->crew3 = c; break; } case W_CAPTAIN: (void) strncpy(ship->file->captain, (char *)a, sizeof ship->file->captain - 1); ship->file->captain[sizeof ship->file->captain - 1] = 0; break; case W_CAPTURED: if (a < 0) ship->file->captured = 0; else ship->file->captured = SHIP(a); break; case W_CLASS: ship->specs->class = a; break; case W_DRIFT: ship->file->drift = a; break; case W_EXPLODE: if ((ship->file->explode = a) == 2) ship->file->dir = 0; break; case W_FS: ship->file->FS = a; break; case W_GUNL: { register struct shipspecs *s = ship->specs; s->gunL = a; s->carL = b; break; } case W_GUNR: { register struct shipspecs *s = ship->specs; s->gunR = a; s->carR = b; break; } case W_HULL: ship->specs->hull = a; break; case W_MOVE: (void) strncpy(ship->file->movebuf, (char *)a, sizeof ship->file->movebuf - 1); ship->file->movebuf[sizeof ship->file->movebuf - 1] = 0; break; case W_PCREW: ship->file->pcrew = a; break; case W_POINTS: ship->file->points = a; break; case W_QUAL: ship->specs->qual = a; break; case W_RIGG: { register struct shipspecs *s = ship->specs; s->rig1 = a; s->rig2 = b; s->rig3 = c; s->rig4 = d; break; } case W_RIG1: ship->specs->rig1 = a; break; case W_RIG2: ship->specs->rig2 = a; break; case W_RIG3: ship->specs->rig3 = a; break; case W_RIG4: ship->specs->rig4 = a; break; case W_COL: ship->file->col = a; break; case W_DIR: ship->file->dir = a; break; case W_ROW: ship->file->row = a; break; case W_SINK: if ((ship->file->sink = a) == 2) ship->file->dir = 0; break; case W_STRUCK: ship->file->struck = a; break; case W_TA: ship->specs->ta = a; break; case W_ALIVE: alive = 1; break; case W_TURN: turn = a; break; case W_WIND: winddir = a; windspeed = b; break; case W_BEGIN: (void) strcpy(ship->file->captain, "begin"); people++; break; case W_END: *ship->file->captain = 0; ship->file->points = 0; people--; break; case W_DDEAD: hasdriver = 0; break; default: fprintf(stderr, "sync_update: unknown type %d\r\n", type); return -1; } return 0; } SHAR_EOF if test 7246 -ne "`wc -c sail/sync.c`" then echo shar: error transmitting sail/sync.c '(should have been 7246 characters)' fi cat << \SHAR_EOF > sail/version.c char version[] = "Wooden Ships and Iron Men, Version 2.4 (84/02/23)"; SHAR_EOF if test 70 -ne "`wc -c sail/version.c`" then echo shar: error transmitting sail/version.c '(should have been 70 characters)' fi # End of shell archive exit 0