games@tekred.TEK.COM (04/14/88)
Submitted by: bostic@okeeffe.Berkeley.EDU (Keith Bostic)
Comp.sources.games: Volume 4, Issue 12
Archive-name: sail/Part04
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 4 (of 4)."
# Contents: :file :scene :ship dr_4.c dr_5.c dr_main.c driver.h game.c
# lo_main.c main.c parties.c version.c
# Wrapped by billr@saab on Wed Apr 13 13:38:23 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f :file -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \":file\"
else
echo shar: Extracting \":file\" \(391 characters\)
sed "s/^X//" >:file <<'END_OF_:file'
X./"index"16t"captain"nD20C
X+/"points"8t"loadL"8t"loadR"8t"readyL"8t"readyL"ndbbbb2+36+36+
X+/"struck"8t"capture"8t"pcrew"8t"movebuf"nb3+pd10C
X+/"drift"8t"nfoul"8t"ngrap"nb1+dd
X+/"foul:"8t"count"8t"turn"16t"count"8t"turn"
X+,5/8tdd16tddn
X+/"grap:"8t"count"8t"turn"16t"count"8t"turn"
X+,5/8tdd16tddn
X+/"RH"8t"RG"8t"RR"8t"FS"8t"explode"8t"sink"n6b
X+/"dir"8t"col"8t"row"8t"loadwit"8t"stern"nb+2d2b
END_OF_:file
if test 391 -ne `wc -c <:file`; then
echo shar: \":file\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f :scene -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \":scene\"
else
echo shar: Extracting \":scene\" \(62 characters\)
sed "s/^X//" >:scene <<'END_OF_:scene'
X./"winddir windspd windchg vessels"n4b
X.+8/"ship: "a
X*(.-4)/S
END_OF_:scene
if test 62 -ne `wc -c <:scene`; then
echo shar: \":scene\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f :ship -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \":ship\"
else
echo shar: Extracting \":ship\" \(77 characters\)
sed "s/^X//" >:ship <<'END_OF_:ship'
X./"name"16t"specs"16t"nation"nppb+
X+/"row"8t"col"8t"dir"nddb+
X+/"file"np
X+/t
END_OF_:ship
if test 77 -ne `wc -c <:ship`; then
echo shar: \":ship\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f dr_4.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"dr_4.c\"
else
echo shar: Extracting \"dr_4.c\" \(1247 characters\)
sed "s/^X//" >dr_4.c <<'END_OF_dr_4.c'
X/*
X * Copyright (c) 1983 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)dr_4.c 5.2 (Berkeley) 3/9/88";
X#endif /* not lint */
X
X#include "externs.h"
X
Xungrap(from, to)
Xregister struct ship *from, *to;
X{
X register k;
X char friend;
X
X if ((k = grappled2(from, to)) == 0)
X return;
X friend = capship(from)->nationality == capship(to)->nationality;
X while (--k >= 0) {
X if (friend || die() < 3) {
X cleangrapple(from, to, 0);
X makesignal(from, "ungrappling %s (%c%c)", to);
X }
X }
X}
X
Xgrap(from, to)
Xregister struct ship *from, *to;
X{
X if (capship(from)->nationality != capship(to)->nationality && die() > 2)
X return;
X Write(W_GRAP, from, 0, to->file->index, 0, 0, 0);
X Write(W_GRAP, to, 0, from->file->index, 0, 0, 0);
X makesignal(from, "grappled with %s (%c%c)", to);
X}
END_OF_dr_4.c
if test 1247 -ne `wc -c <dr_4.c`; then
echo shar: \"dr_4.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f dr_5.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"dr_5.c\"
else
echo shar: Extracting \"dr_5.c\" \(1964 characters\)
sed "s/^X//" >dr_5.c <<'END_OF_dr_5.c'
X/*
X * Copyright (c) 1983 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)dr_5.c 5.2 (Berkeley) 3/9/88";
X#endif /* not lint */
X
X#include "externs.h"
X
Xsubtract(from, totalfrom, crewfrom, fromcap, pcfrom)
Xstruct ship *from, *fromcap;
Xint pcfrom;
Xregister int totalfrom, crewfrom[3];
X{
X register int n;
X
X if (fromcap == from && totalfrom) { /* if not captured */
X for (n = 0; n < 3; n++) {
X if (totalfrom > crewfrom[n]) {
X totalfrom -= crewfrom[n];
X crewfrom[n] = 0;
X } else {
X crewfrom[n] -= totalfrom;
X totalfrom = 0;
X }
X }
X Write(W_CREW, from, 0, crewfrom[0], crewfrom[1], crewfrom[2], 0);
X } else if (totalfrom) {
X pcfrom -= totalfrom;
X pcfrom = pcfrom < 0 ? 0 : pcfrom;
X Write(W_PCREW, from, 0, pcfrom, 0, 0, 0);
X }
X}
X
Xmensent(from, to, crew, captured, pc, isdefense)
Xstruct ship *from, *to, **captured;
Xint crew[3], *pc;
Xchar isdefense;
X{ /* returns # of crew squares sent */
X int men = 0;
X register int n;
X int c1, c2, c3;
X register struct BP *bp;
X
X *pc = from->file->pcrew;
X *captured = from->file->captured;
X crew[0] = from->specs->crew1;
X crew[1] = from->specs->crew2;
X crew[2] = from->specs->crew3;
X bp = isdefense ? from->file->DBP : from->file->OBP;
X for (n=0; n < NBP; n++, bp++) {
X if (bp->turnsent && bp->toship == to)
X men += bp->mensent;
X }
X if (men) {
X c1 = men/100 ? crew[0] : 0;
X c2 = (men%100)/10 ? crew[1] : 0;
X c3 = men/10 ? crew[2] : 0;
X c3 = *captured == 0 ? crew[2] : *pc;
X } else
X c1 = c2 = c3 = 0;
X return(c1 + c2 + c3);
X}
END_OF_dr_5.c
if test 1964 -ne `wc -c <dr_5.c`; then
echo shar: \"dr_5.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f dr_main.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"dr_main.c\"
else
echo shar: Extracting \"dr_main.c\" \(2033 characters\)
sed "s/^X//" >dr_main.c <<'END_OF_dr_main.c'
X/*
X * Copyright (c) 1983 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)dr_main.c 5.3 (Berkeley) 3/9/88";
X#endif /* not lint */
X
X#include "driver.h"
X
Xdr_main()
X{
X register int n;
X register struct ship *sp;
X int nat[NNATION];
X int value = 0;
X
X (void) signal(SIGINT, SIG_IGN);
X (void) signal(SIGQUIT, SIG_IGN);
X (void) signal(SIGTSTP, SIG_IGN);
X if (issetuid)
X (void) setruid(geteuid());
X if (game < 0 || game >= NSCENE) {
X fprintf(stderr, "DRIVER: Bad game number %d\n", game);
X exit(1);
X }
X cc = &scene[game];
X ls = SHIP(cc->vessels);
X if (sync_open() < 0) {
X perror("driver: syncfile");
X exit(1);
X }
X for (n = 0; n < NNATION; n++)
X nat[n] = 0;
X foreachship(sp) {
X if (sp->file == NULL &&
X (sp->file = (struct File *)calloc(1, sizeof (struct File))) == NULL) {
X (void) fprintf(stderr, "DRIVER: Out of memory.\n");
X exit(1);
X }
X sp->file->index = sp - SHIP(0);
X sp->file->loadL = L_ROUND;
X sp->file->loadR = L_ROUND;
X sp->file->readyR = R_LOADED|R_INITIAL;
X sp->file->readyL = R_LOADED|R_INITIAL;
X sp->file->stern = nat[sp->nationality]++;
X sp->file->dir = sp->shipdir;
X sp->file->row = sp->shiprow;
X sp->file->col = sp->shipcol;
X }
X windspeed = cc->windspeed;
X winddir = cc->winddir;
X people = 0;
X for (;;) {
X sleep(7);
X if (Sync() < 0) {
X value = 1;
X break;
X }
X if (next() < 0)
X break;
X unfoul();
X checkup();
X prizecheck();
X moveall();
X thinkofgrapples();
X boardcomp();
X compcombat();
X resolve();
X reload();
X checksails();
X if (Sync() < 0) {
X value = 1;
X break;
X }
X }
X sync_close(1);
X return value;
X}
END_OF_dr_main.c
if test 2033 -ne `wc -c <dr_main.c`; then
echo shar: \"dr_main.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f driver.h -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"driver.h\"
else
echo shar: Extracting \"driver.h\" \(585 characters\)
sed "s/^X//" >driver.h <<'END_OF_driver.h'
X/*
X * Copyright (c) 1983 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X *
X * @(#)driver.h 5.2 (Berkeley) 3/9/88
X */
X
X#include "externs.h"
X
Xint dtab[];
END_OF_driver.h
if test 585 -ne `wc -c <driver.h`; then
echo shar: \"driver.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f game.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"game.c\"
else
echo shar: Extracting \"game.c\" \(1800 characters\)
sed "s/^X//" >game.c <<'END_OF_game.c'
X/*
X * Copyright (c) 1983 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)game.c 5.2 (Berkeley) 3/9/88";
X#endif /* not lint */
X
X#include "externs.h"
X
Xmaxturns(ship, af)
Xregister struct ship *ship;
Xchar *af;
X{
X register int turns;
X
X turns = ship->specs->ta;
X if (*af = (ship->file->drift > 1 && turns)) {
X turns--;
X if (ship->file->FS == 1)
X turns = 0;
X }
X return turns;
X}
X
Xmaxmove(ship, dir, fs)
Xregister struct ship *ship;
Xint dir, fs;
X{
X register int riggone = 0, Move, flank = 0;
X
X Move = ship->specs->bs;
X if (!ship->specs->rig1)
X riggone++;
X if (!ship->specs->rig2)
X riggone++;
X if (!ship->specs->rig3)
X riggone++;
X if (!ship->specs->rig4)
X riggone++;
X if ((ship->file->FS || fs) && fs != -1) {
X flank = 1;
X Move = ship->specs->fs;
X }
X if (dir == winddir)
X Move -= 1 + WET[windspeed][ship->specs->class-1].B;
X else if (dir == winddir + 2 || dir == winddir - 2 || dir == winddir - 6 || dir == winddir + 6)
X Move -= 1 + WET[windspeed][ship->specs->class-1].C;
X else if (dir == winddir + 3 || dir == winddir - 3 || dir == winddir - 5 || dir == winddir + 5)
X Move = (flank ? 2 : 1) - WET[windspeed][ship->specs->class-1].D;
X else if (dir == winddir + 4 || dir == winddir - 4)
X Move = 0;
X else
X Move -= WET[windspeed][ship->specs->class-1].A;
X Move -= riggone;
X Move = Move < 0 ? 0 : Move;
X return(Move);
X}
END_OF_game.c
if test 1800 -ne `wc -c <game.c`; then
echo shar: \"game.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f lo_main.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"lo_main.c\"
else
echo shar: Extracting \"lo_main.c\" \(1817 characters\)
sed "s/^X//" >lo_main.c <<'END_OF_lo_main.c'
X/*
X * Copyright (c) 1983 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)lo_main.c 5.2 (Berkeley) 3/9/88";
X#endif /* not lint */
X
X/*
X * Print out the top ten SAILors
X *
X * -l force a long listing (print out real usernames)
X */
X#include <pwd.h>
X#include "externs.h"
X
Xchar *title[] = {
X "Admiral", "Commodore", "Captain", "Captain",
X "Captain", "Captain", "Captain", "Commander",
X "Commander", "Lieutenant"
X};
X
Xlo_main()
X{
X FILE *fp;
X char sbuf[32];
X int n = 0, people;
X struct passwd *getpwuid(), *pass;
X struct logs log;
X struct ship *ship;
X
X if ((fp = fopen(LOGFILE, "r")) == 0) {
X perror(LOGFILE);
X exit(1);
X }
X switch (fread((char *)&people, sizeof people, 1, fp)) {
X case 0:
X printf("Nobody has sailed yet.\n");
X exit(0);
X case 1:
X break;
X default:
X perror(LOGFILE);
X exit(1);
X }
X while (fread((char *)&log, sizeof log, 1, fp) == 1 &&
X log.l_name[0] != '\0') {
X if (longfmt && (pass = getpwuid(log.l_uid)) != NULL)
X (void) sprintf(sbuf, "%10.10s (%s)",
X log.l_name, pass->pw_name);
X else
X (void) sprintf(sbuf, "%20.20s", log.l_name);
X ship = &scene[log.l_gamenum].ship[log.l_shipnum];
X printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n",
X title[n++], sbuf, ship->shipname, log.l_netpoints,
X (float) log.l_netpoints / ship->specs->pts);
X }
X printf("\n%d people have played.\n", people);
X return 0;
X}
END_OF_lo_main.c
if test 1817 -ne `wc -c <lo_main.c`; then
echo shar: \"lo_main.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f main.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"main.c\"
else
echo shar: Extracting \"main.c\" \(1843 characters\)
sed "s/^X//" >main.c <<'END_OF_main.c'
X/*
X * Copyright (c) 1983 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xchar copyright[] =
X"@(#) Copyright (c) 1983 Regents of the University of California.\n\
X All rights reserved.\n";
X#endif /* not lint */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)main.c 5.3 (Berkeley) 4/4/88";
X#endif /* not lint */
X
X#include "externs.h"
X
X/*ARGSUSED*/
Xmain(argc, argv)
X int argc;
X register char **argv;
X{
X register char *p;
X int i;
X
X (void) srand(getpid());
X issetuid = getuid() != geteuid();
X if (p = rindex(*argv, '/'))
X p++;
X else
X p = *argv;
X if (strcmp(p, "driver") == 0 || strcmp(p, "saildriver") == 0)
X mode = MODE_DRIVER;
X else if (strcmp(p, "sail.log") == 0)
X mode = MODE_LOGGER;
X else
X mode = MODE_PLAYER;
X while ((p = *++argv) && *p == '-')
X switch (p[1]) {
X case 'd':
X mode = MODE_DRIVER;
X break;
X case 's':
X mode = MODE_LOGGER;
X break;
X case 'D':
X debug++;
X break;
X case 'x':
X randomize;
X break;
X case 'l':
X longfmt++;
X break;
X case 'b':
X nobells++;
X break;
X default:
X fprintf(stderr, "SAIL: Unknown flag %s.\n", p);
X exit(1);
X }
X if (*argv)
X game = atoi(*argv);
X else
X game = -1;
X if (i = setjmp(restart))
X mode = i;
X switch (mode) {
X case MODE_PLAYER:
X return pl_main();
X case MODE_DRIVER:
X return dr_main();
X case MODE_LOGGER:
X return lo_main();
X default:
X fprintf(stderr, "SAIL: Unknown mode %d.\n", mode);
X abort();
X }
X /*NOTREACHED*/
X}
END_OF_main.c
if test 1843 -ne `wc -c <main.c`; then
echo shar: \"main.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f parties.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"parties.c\"
else
echo shar: Extracting \"parties.c\" \(1437 characters\)
sed "s/^X//" >parties.c <<'END_OF_parties.c'
X/*
X * Copyright (c) 1983 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)parties.c 5.2 (Berkeley) 3/9/88";
X#endif /* not lint */
X
X#include "externs.h"
X
Xmeleeing(from, to)
Xstruct ship *from;
Xregister struct ship *to;
X{
X register struct BP *p = from->file->OBP;
X register struct BP *q = p + NBP;
X
X for (; p < q; p++)
X if (p->turnsent && p->toship == to)
X return 1;
X return 0;
X}
X
Xboarding(from, isdefense)
Xregister struct ship *from;
Xchar isdefense;
X{
X register struct BP *p = isdefense ? from->file->DBP : from->file->OBP;
X register struct BP *q = p + NBP;
X
X for (; p < q; p++)
X if (p->turnsent)
X return 1;
X return 0;
X}
X
Xunboard(ship, to, isdefense)
Xregister struct ship *ship, *to;
Xregister char isdefense;
X{
X register struct BP *p = isdefense ? ship->file->DBP : ship->file->OBP;
X register n;
X
X for (n = 0; n < NBP; p++, n++)
X if (p->turnsent && (p->toship == to || isdefense || ship == to))
X Write(isdefense ? W_DBP : W_OBP, ship, 0, n, 0, 0, 0);
X}
END_OF_parties.c
if test 1437 -ne `wc -c <parties.c`; then
echo shar: \"parties.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f version.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"version.c\"
else
echo shar: Extracting \"version.c\" \(678 characters\)
sed "s/^X//" >version.c <<'END_OF_version.c'
X/*
X * Copyright (c) 1983 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)version.c 5.2 (Berkeley) 3/9/88";
X#endif /* not lint */
X
Xchar version[] = "Wooden Ships and Iron Men, Version 5.2 (88/03/09)";
END_OF_version.c
if test 678 -ne `wc -c <version.c`; then
echo shar: \"version.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 4 \(of 4\).
cp /dev/null ark4isdone
MISSING=""
for I in 1 2 3 4 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 4 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0