games@tekred.TEK.COM (04/14/88)
Submitted by: bostic@okeeffe.Berkeley.EDU (Keith Bostic) Comp.sources.games: Volume 4, Issue 11 Archive-name: sail/Part03 #! /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 3 (of 4)." # Contents: Makefile dr_2.c externs.h machdep.h misc.c pl_1.c pl_2.c # pl_3.c pl_4.c pl_6.c pl_main.c player.h # Wrapped by billr@saab on Wed Apr 13 13:38:22 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f Makefile -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"Makefile\" else echo shar: Extracting \"Makefile\" \(7030 characters\) sed "s/^X//" >Makefile <<'END_OF_Makefile' X# X# Copyright (c) 1987 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# @(#)Makefile 5.6 (Berkeley) 3/9/88 X# XCFLAGS= -O XLIBC= /lib/libc.a XLIBS= -lcurses -ltermlib XSRCS= main.c pl_main.c pl_1.c pl_2.c pl_3.c pl_4.c pl_5.c pl_6.c pl_7.c \ X dr_main.c dr_1.c dr_2.c dr_3.c dr_4.c dr_5.c lo_main.c \ X assorted.c game.c globals.c misc.c parties.c sync.c version.c XOBJS= main.o pl_main.o pl_1.o pl_2.o pl_3.o pl_4.o pl_5.o pl_6.o pl_7.o \ X dr_main.o dr_1.o dr_2.o dr_3.o dr_4.o dr_5.o lo_main.o \ X assorted.o game.o globals.o misc.o parties.o sync.o version.o X Xall: sail X Xsail: ${OBJS} ${LIBC} X ${CC} -o $@ ${OBJS} ${LIBS} X Xclean: FRC X rm -f ${OBJS} core sail X Xdepend: FRC X mkdep ${CFLAGS} ${SRCS} X Xinstall: FRC X install -c -o games -g bin -m 600 /dev/null ${DESTDIR}/usr/games/lib/saillog X install -s -o games -g bin -m 4700 sail ${DESTDIR}/usr/games/hide X (cd ${DESTDIR}/usr/games; rm -f sail; ln -s dm sail; chown games.bin sail) X Xlint: FRC X lint ${CFLAGS} ${SRCS} X Xtags: FRC X ctags ${SRCS} X XFRC: X X# DO NOT DELETE THIS LINE -- mkdep uses it. X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. X Xmain.o: main.c externs.h /usr/include/stdio.h /usr/include/signal.h Xmain.o: /usr/include/machine/trap.h /usr/include/ctype.h /usr/include/setjmp.h Xmain.o: machdep.h Xpl_main.o: pl_main.c player.h /usr/include/curses.h /usr/include/stdio.h Xpl_main.o: /usr/include/sgtty.h /usr/include/sys/ioctl.h Xpl_main.o: /usr/include/sys/ttychars.h /usr/include/sys/ttydev.h externs.h Xpl_main.o: /usr/include/stdio.h /usr/include/signal.h Xpl_main.o: /usr/include/machine/trap.h /usr/include/ctype.h Xpl_main.o: /usr/include/setjmp.h machdep.h /usr/include/sys/types.h Xpl_main.o: /usr/include/sys/wait.h /usr/include/machine/machparam.h Xpl_1.o: pl_1.c player.h /usr/include/curses.h /usr/include/stdio.h Xpl_1.o: /usr/include/sgtty.h /usr/include/sys/ioctl.h Xpl_1.o: /usr/include/sys/ttychars.h /usr/include/sys/ttydev.h externs.h Xpl_1.o: /usr/include/stdio.h /usr/include/signal.h /usr/include/machine/trap.h Xpl_1.o: /usr/include/ctype.h /usr/include/setjmp.h machdep.h Xpl_1.o: /usr/include/sys/types.h /usr/include/sys/wait.h Xpl_1.o: /usr/include/machine/machparam.h Xpl_2.o: pl_2.c player.h /usr/include/curses.h /usr/include/stdio.h Xpl_2.o: /usr/include/sgtty.h /usr/include/sys/ioctl.h Xpl_2.o: /usr/include/sys/ttychars.h /usr/include/sys/ttydev.h externs.h Xpl_2.o: /usr/include/stdio.h /usr/include/signal.h /usr/include/machine/trap.h Xpl_2.o: /usr/include/ctype.h /usr/include/setjmp.h machdep.h Xpl_3.o: pl_3.c player.h /usr/include/curses.h /usr/include/stdio.h Xpl_3.o: /usr/include/sgtty.h /usr/include/sys/ioctl.h Xpl_3.o: /usr/include/sys/ttychars.h /usr/include/sys/ttydev.h externs.h Xpl_3.o: /usr/include/stdio.h /usr/include/signal.h /usr/include/machine/trap.h Xpl_3.o: /usr/include/ctype.h /usr/include/setjmp.h machdep.h Xpl_4.o: pl_4.c player.h /usr/include/curses.h /usr/include/stdio.h Xpl_4.o: /usr/include/sgtty.h /usr/include/sys/ioctl.h Xpl_4.o: /usr/include/sys/ttychars.h /usr/include/sys/ttydev.h externs.h Xpl_4.o: /usr/include/stdio.h /usr/include/signal.h /usr/include/machine/trap.h Xpl_4.o: /usr/include/ctype.h /usr/include/setjmp.h machdep.h Xpl_5.o: pl_5.c player.h /usr/include/curses.h /usr/include/stdio.h Xpl_5.o: /usr/include/sgtty.h /usr/include/sys/ioctl.h Xpl_5.o: /usr/include/sys/ttychars.h /usr/include/sys/ttydev.h externs.h Xpl_5.o: /usr/include/stdio.h /usr/include/signal.h /usr/include/machine/trap.h Xpl_5.o: /usr/include/ctype.h /usr/include/setjmp.h machdep.h Xpl_6.o: pl_6.c player.h /usr/include/curses.h /usr/include/stdio.h Xpl_6.o: /usr/include/sgtty.h /usr/include/sys/ioctl.h Xpl_6.o: /usr/include/sys/ttychars.h /usr/include/sys/ttydev.h externs.h Xpl_6.o: /usr/include/stdio.h /usr/include/signal.h /usr/include/machine/trap.h Xpl_6.o: /usr/include/ctype.h /usr/include/setjmp.h machdep.h Xpl_7.o: pl_7.c player.h /usr/include/curses.h /usr/include/stdio.h Xpl_7.o: /usr/include/sgtty.h /usr/include/sys/ioctl.h Xpl_7.o: /usr/include/sys/ttychars.h /usr/include/sys/ttydev.h externs.h Xpl_7.o: /usr/include/stdio.h /usr/include/signal.h /usr/include/machine/trap.h Xpl_7.o: /usr/include/ctype.h /usr/include/setjmp.h machdep.h Xdr_main.o: dr_main.c driver.h externs.h /usr/include/stdio.h Xdr_main.o: /usr/include/signal.h /usr/include/machine/trap.h Xdr_main.o: /usr/include/ctype.h /usr/include/setjmp.h machdep.h Xdr_1.o: dr_1.c driver.h externs.h /usr/include/stdio.h /usr/include/signal.h Xdr_1.o: /usr/include/machine/trap.h /usr/include/ctype.h /usr/include/setjmp.h Xdr_1.o: machdep.h Xdr_2.o: dr_2.c driver.h externs.h /usr/include/stdio.h /usr/include/signal.h Xdr_2.o: /usr/include/machine/trap.h /usr/include/ctype.h /usr/include/setjmp.h Xdr_2.o: machdep.h Xdr_3.o: dr_3.c driver.h externs.h /usr/include/stdio.h /usr/include/signal.h Xdr_3.o: /usr/include/machine/trap.h /usr/include/ctype.h /usr/include/setjmp.h Xdr_3.o: machdep.h Xdr_4.o: dr_4.c externs.h /usr/include/stdio.h /usr/include/signal.h Xdr_4.o: /usr/include/machine/trap.h /usr/include/ctype.h /usr/include/setjmp.h Xdr_4.o: machdep.h Xdr_5.o: dr_5.c externs.h /usr/include/stdio.h /usr/include/signal.h Xdr_5.o: /usr/include/machine/trap.h /usr/include/ctype.h /usr/include/setjmp.h Xdr_5.o: machdep.h Xlo_main.o: lo_main.c /usr/include/pwd.h externs.h /usr/include/stdio.h Xlo_main.o: /usr/include/signal.h /usr/include/machine/trap.h Xlo_main.o: /usr/include/ctype.h /usr/include/setjmp.h machdep.h Xassorted.o: assorted.c externs.h /usr/include/stdio.h /usr/include/signal.h Xassorted.o: /usr/include/machine/trap.h /usr/include/ctype.h Xassorted.o: /usr/include/setjmp.h machdep.h Xgame.o: game.c externs.h /usr/include/stdio.h /usr/include/signal.h Xgame.o: /usr/include/machine/trap.h /usr/include/ctype.h /usr/include/setjmp.h Xgame.o: machdep.h Xglobals.o: globals.c externs.h /usr/include/stdio.h /usr/include/signal.h Xglobals.o: /usr/include/machine/trap.h /usr/include/ctype.h Xglobals.o: /usr/include/setjmp.h machdep.h Xmisc.o: misc.c externs.h /usr/include/stdio.h /usr/include/signal.h Xmisc.o: /usr/include/machine/trap.h /usr/include/ctype.h /usr/include/setjmp.h Xmisc.o: machdep.h /usr/include/sys/file.h Xparties.o: parties.c externs.h /usr/include/stdio.h /usr/include/signal.h Xparties.o: /usr/include/machine/trap.h /usr/include/ctype.h Xparties.o: /usr/include/setjmp.h machdep.h Xsync.o: sync.c externs.h /usr/include/stdio.h /usr/include/signal.h Xsync.o: /usr/include/machine/trap.h /usr/include/ctype.h /usr/include/setjmp.h Xsync.o: machdep.h /usr/include/sys/file.h /usr/include/sys/errno.h Xsync.o: /usr/include/sys/types.h /usr/include/sys/stat.h Xversion.o: version.c X X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY END_OF_Makefile if test 7030 -ne `wc -c <Makefile`; then echo shar: \"Makefile\" unpacked with wrong size! fi # end of overwriting check fi if test -f dr_2.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"dr_2.c\" else echo shar: Extracting \"dr_2.c\" \(5895 characters\) sed "s/^X//" >dr_2.c <<'END_OF_dr_2.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_2.c 5.2 (Berkeley) 3/9/88"; X#endif /* not lint */ X X#include "driver.h" X X#define couldwin(f,t) (f->specs->crew2 > t->specs->crew2 * 1.5) X Xthinkofgrapples() X{ X register struct ship *sp, *sq; X char friendly; X X foreachship(sp) { X if (sp->file->captain[0] || sp->file->dir == 0) X continue; X foreachship(sq) { X friendly = sp->nationality == capship(sq)->nationality; X if (!friendly) { X if (sp->file->struck || sp->file->captured != 0) X continue; X if (range(sp, sq) != 1) X continue; X if (grappled2(sp, sq)) X if (toughmelee(sp, sq, 0, 0)) X ungrap(sp, sq); X else X grap(sp, sq); X else if (couldwin(sp, sq)) { X grap(sp, sq); X sp->file->loadwith = L_GRAPE; X } X } else X ungrap(sp, sq); X } X } X} X Xcheckup() X{ X register struct ship *sp, *sq; X register char explode, sink; X X foreachship(sp) { X if (sp->file->dir == 0) X continue; X explode = sp->file->explode; X sink = sp->file->sink; X if (explode != 1 && sink != 1) X continue; X if (die() < 5) X continue; X Write(sink == 1 ? W_SINK : W_EXPLODE, sp, 0, 2, 0, 0, 0); X Write(W_DIR, sp, 0, 0, 0, 0, 0); X if (snagged(sp)) X foreachship(sq) X cleansnag(sp, sq, 1); X if (sink != 1) { X makesignal(sp, "exploding!", (struct ship *)0); X foreachship(sq) { X if (sp != sq && sq->file->dir && range(sp, sq) < 4) X table(RIGGING, L_EXPLODE, sp->specs->guns/13, sq, sp, 6); X } X } else X makesignal(sp, "sinking!", (struct ship *)0); X } X} X Xprizecheck() X{ X register struct ship *sp; X X foreachship(sp) { X if (sp->file->captured == 0) X continue; X if (sp->file->struck || sp->file->dir == 0) X continue; X if (sp->specs->crew1 + sp->specs->crew2 + sp->specs->crew3 > sp->file->pcrew * 6) { X Write(W_SIGNAL, sp, 1, X (int)"prize crew overthrown", 0, 0, 0); X Write(W_POINTS, sp->file->captured, 0, sp->file->captured->file->points - 2 * sp->specs->pts, 0, 0, 0); X Write(W_CAPTURED, sp, 0, -1, 0, 0, 0); X } X } X} X Xstrend(str) Xchar *str; X{ X register char *p; X X for (p = str; *p; p++) X ; X return p == str ? 0 : p[-1]; X} X Xcloseon(from, to, command, ta, ma, af) Xregister struct ship *from, *to; Xchar command[]; Xint ma, ta, af; X{ X int high; X char temp[10]; X X temp[0] = command[0] = '\0'; X high = -30000; X try(command, temp, ma, ta, af, ma, from->file->dir, from, to, &high, 0); X} X Xint dtab[] = {0,1,1,2,3,4,4,5}; /* diagonal distances in x==y */ X Xscore(movement, ship, to, onlytemp) Xchar movement[]; Xregister struct ship *ship, *to; Xchar onlytemp; X{ X char drift; X int row, col, dir, total, ran; X register struct File *fp = ship->file; X X if ((dir = fp->dir) == 0) X return 0; X row = fp->row; X col = fp->col; X drift = fp->drift; X move(movement, ship, &fp->dir, &fp->row, &fp->col, &drift); X if (!*movement) X (void) strcpy(movement, "d"); X X ran = range(ship, to); X total = -50 * ran; X if (ran < 4 && gunsbear(ship, to)) X total += 60; X if ((ran = portside(ship, to, 1) - fp->dir) == 4 || ran == -4) X total = -30000; X X if (!onlytemp) { X fp->row = row; X fp->col = col; X fp->dir = dir; X } X return total; X} X Xmove(p, ship, dir, row, col, drift) Xregister char *p; Xregister struct ship *ship; Xregister char *dir; Xregister short *row, *col; Xregister char *drift; X{ X int dist; X char moved = 0; X X for (; *p; p++) { X switch (*p) { X case 'r': X if (++*dir == 9) X *dir = 1; X break; X case 'l': X if (--*dir == 0) X *dir = 8; X break; X case '1': case '2': case '3': case '4': X case '5': case '6': case '7': X moved++; X if (*dir % 2 == 0) X dist = dtab[*p - '0']; X else X dist = *p - '0'; X *row -= dr[*dir] * dist; X *col -= dc[*dir] * dist; X break; X } X } X if (!moved) { X if (windspeed != 0 && ++*drift > 2) { X if (ship->specs->class >= 3 && !snagged(ship) X || (turn & 1) == 0) { X *row -= dr[winddir]; X *col -= dc[winddir]; X } X } X } else X *drift = 0; X} X Xtry(command, temp, ma, ta, af, vma, dir, f, t, high, rakeme) Xregister struct ship *f, *t; Xint ma, ta, af, *high, rakeme; Xchar command[], temp[]; X{ X register int new, n; X char st[4]; X#define rakeyou (gunsbear(f, t) && !gunsbear(t, f)) X X if ((n = strend(temp)) < '1' || n > '9') X for (n = 1; vma - n >= 0; n++) { X (void) sprintf(st, "%d", n); X (void) strcat(temp, st); X new = score(temp, f, t, rakeme); X if (new > *high && (!rakeme || rakeyou)) { X *high = new; X (void) strcpy(command, temp); X } X try(command, temp, ma-n, ta, af, vma-n, X dir, f, t, high, rakeme); X rmend(temp); X } X if (ma > 0 && ta > 0 && (n = strend(temp)) != 'l' && n != 'r' || !strlen(temp)) { X (void) strcat(temp, "r"); X new = score(temp, f, t, rakeme); X if (new > *high && (!rakeme || gunsbear(f, t) && !gunsbear(t, f))) { X *high = new; X (void) strcpy(command, temp); X } X try(command, temp, ma-1, ta-1, af, min(ma-1, maxmove(f, (dir == 8 ? 1 : dir+1), 0)), (dir == 8 ? 1 : dir+1),f,t,high,rakeme); X rmend(temp); X } X if ((ma > 0 && ta > 0 && (n = strend(temp)) != 'l' && n != 'r') || !strlen(temp)){ X (void) strcat(temp, "l"); X new = score(temp, f, t, rakeme); X if (new > *high && (!rakeme || (gunsbear(f, t) && !gunsbear(t, f)))){ X *high = new; X (void) strcpy(command, temp); X } X try(command, temp, ma-1, ta-1, af, (min(ma-1,maxmove(f, (dir-1 ? dir-1 : 8), 0))), (dir-1 ? dir -1 : 8), f, t, high, rakeme); X rmend(temp); X } X} X Xrmend(str) Xchar *str; X{ X register char *p; X X for (p = str; *p; p++) X ; X if (p != str) X *--p = 0; X} END_OF_dr_2.c if test 5895 -ne `wc -c <dr_2.c`; then echo shar: \"dr_2.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f externs.h -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"externs.h\" else echo shar: Extracting \"externs.h\" \(6214 characters\) sed "s/^X//" >externs.h <<'END_OF_externs.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 * @(#)externs.h 5.2 (Berkeley) 3/9/88 X */ X X#include <stdio.h> X#include <signal.h> X#include <ctype.h> X#include <setjmp.h> X#include "machdep.h" X X /* program mode */ Xint mode; Xjmp_buf restart; X#define MODE_PLAYER 1 X#define MODE_DRIVER 2 X#define MODE_LOGGER 3 X X /* command line flags */ Xchar debug; /* -D */ Xchar randomize; /* -x, give first available ship */ Xchar longfmt; /* -l, print score in long format */ Xchar nobells; /* -b, don't ring bell before Signal */ X X /* other initial modes */ Xchar issetuid; /* running setuid */ X X#define die() ((rand() >> 3) % 6 + 1) X#define sqr(a) ((a) * (a)) X#define abs(a) ((a) > 0 ? (a) : -(a)) X#define min(a,b) ((a) < (b) ? (a) : (b)) X X#define grappled(a) ((a)->file->ngrap) X#define fouled(a) ((a)->file->nfoul) X#define snagged(a) (grappled(a) + fouled(a)) X X#define grappled2(a, b) ((a)->file->grap[(b)->file->index].sn_count) X#define fouled2(a, b) ((a)->file->foul[(b)->file->index].sn_count) X#define snagged2(a, b) (grappled2(a, b) + fouled2(a, b)) X X#define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 ? grappled2(a, b) : 0) X#define Xfouled2(a, b) ((a)->file->foul[(b)->file->index].sn_turn < turn-1 ? fouled2(a, b) : 0) X#define Xsnagged2(a, b) (Xgrappled2(a, b) + Xfouled2(a, b)) X X#define cleangrapple(a, b, c) Cleansnag(a, b, c, 1) X#define cleanfoul(a, b, c) Cleansnag(a, b, c, 2) X#define cleansnag(a, b, c) Cleansnag(a, b, c, 3) X X#define sterncolour(sp) ((sp)->file->stern+'0'-((sp)->file->captured?10:0)) X#define sternrow(sp) ((sp)->file->row + dr[(sp)->file->dir]) X#define sterncol(sp) ((sp)->file->col + dc[(sp)->file->dir]) X X#define capship(sp) ((sp)->file->captured?(sp)->file->captured:(sp)) X X#define readyname(r) ((r) & R_LOADING ? '*' : ((r) & R_INITIAL ? '!' : ' ')) X X/* loadL and loadR, should match loadname[] */ X#define L_EMPTY 0 /* should be 0, don't change */ X#define L_GRAPE 1 X#define L_CHAIN 2 X#define L_ROUND 3 X#define L_DOUBLE 4 X#define L_EXPLODE 5 X X/* X * readyL and readyR, these are bits, except R_EMPTY X */ X#define R_EMPTY 0 /* not loaded and not loading */ X#define R_LOADING 1 /* loading */ X#define R_DOUBLE 2 /* loading double */ X#define R_LOADED 4 /* loaded */ X#define R_INITIAL 8 /* loaded initial */ X X#define HULL 0 X#define RIGGING 1 X X#define W_CAPTAIN 1 X#define W_CAPTURED 2 X#define W_CLASS 3 X#define W_CREW 4 X#define W_DBP 5 X#define W_DRIFT 6 X#define W_EXPLODE 7 X#define W_FILE 8 X#define W_FOUL 9 X#define W_GUNL 10 X#define W_GUNR 11 X#define W_HULL 12 X#define W_MOVE 13 X#define W_OBP 14 X#define W_PCREW 15 X#define W_UNFOUL 16 X#define W_POINTS 17 X#define W_QUAL 18 X#define W_UNGRAP 19 X#define W_RIGG 20 X#define W_COL 21 X#define W_DIR 22 X#define W_ROW 23 X#define W_SIGNAL 24 X#define W_SINK 25 X#define W_STRUCK 26 X#define W_TA 27 X#define W_ALIVE 28 X#define W_TURN 29 X#define W_WIND 30 X#define W_FS 31 X#define W_GRAP 32 X#define W_RIG1 33 X#define W_RIG2 34 X#define W_RIG3 35 X#define W_RIG4 36 X#define W_BEGIN 37 X#define W_END 38 X#define W_DDEAD 39 X X#define NLOG 10 Xstruct logs { X char l_name[20]; X int l_uid; X int l_shipnum; X int l_gamenum; X int l_netpoints; X}; X Xstruct BP { X short turnsent; X struct ship *toship; X short mensent; X}; X Xstruct snag { X short sn_count; X short sn_turn; X}; X X#define NSCENE nscene X#define NSHIP 10 X#define NBP 3 X X#define NNATION 8 X#define N_A 0 X#define N_B 1 X#define N_S 2 X#define N_F 3 X#define N_J 4 X#define N_D 5 X#define N_K 6 X#define N_O 7 X Xstruct File { X int index; X char captain[20]; /* 0 */ X short points; /* 20 */ X char loadL; /* 22 */ X char loadR; /* 24 */ X char readyL; /* 26 */ X char readyR; /* 28 */ X struct BP OBP[NBP]; /* 30 */ X struct BP DBP[NBP]; /* 48 */ X char struck; /* 66 */ X struct ship *captured; /* 68 */ X short pcrew; /* 70 */ X char movebuf[10]; /* 72 */ X char drift; /* 82 */ X short nfoul; X short ngrap; X struct snag foul[NSHIP]; /* 84 */ X struct snag grap[NSHIP]; /* 124 */ X char RH; /* 224 */ X char RG; /* 226 */ X char RR; /* 228 */ X char FS; /* 230 */ X char explode; /* 232 */ X char sink; /* 234 */ X char dir; X short col; X short row; X char loadwith; X char stern; X}; X Xstruct ship { X char *shipname; /* 0 */ X struct shipspecs *specs; /* 2 */ X char nationality; /* 4 */ X short shiprow; /* 6 */ X short shipcol; /* 8 */ X char shipdir; /* 10 */ X struct File *file; /* 12 */ X}; X Xstruct scenario { X char winddir; /* 0 */ X char windspeed; /* 2 */ X char windchange; /* 4 */ X char vessels; /* 12 */ X char *name; /* 14 */ X struct ship ship[NSHIP]; /* 16 */ X}; Xstruct scenario scene[]; Xint nscene; X Xstruct shipspecs { X char bs; X char fs; X char ta; X short guns; X char class; X char hull; X char qual; X char crew1; X char crew2; X char crew3; X char gunL; X char gunR; X char carL; X char carR; X char rig1; X char rig2; X char rig3; X char rig4; X short pts; X}; Xstruct shipspecs specs[]; X Xstruct scenario *cc; /* the current scenario */ Xstruct ship *ls; /* &cc->ship[cc->vessels] */ X X#define SHIP(s) (&cc->ship[s]) X#define foreachship(sp) for ((sp) = cc->ship; (sp) < ls; (sp)++) X Xstruct windeffects { X char A, B, C, D; X}; Xstruct windeffects WET[7][6]; X Xstruct Tables { X char H, G, C, R; X}; Xstruct Tables RigTable[11][6]; Xstruct Tables HullTable[11][6]; X Xchar AMMO[9][4]; Xchar HDT[9][10]; Xchar HDTrake[9][10]; Xchar QUAL[9][5]; Xchar MT[9][3]; X Xchar *countryname[]; Xchar *classname[]; Xchar *directionname[]; Xchar *qualname[]; Xchar loadname[]; X Xchar rangeofshot[]; X Xchar dr[], dc[]; X Xint winddir; Xint windspeed; Xint turn; Xint game; Xint alive; Xint people; Xchar hasdriver; X Xchar *info(); Xchar *quality(); Xdouble arctan(); Xchar *saywhat(); Xstruct ship *closestenemy(); X Xchar *calloc(); Xchar *rindex(); Xchar *strcpy(); Xchar *strcat(); Xchar *strncpy(); Xchar *getenv(); Xchar *gets(); END_OF_externs.h if test 6214 -ne `wc -c <externs.h`; then echo shar: \"externs.h\" unpacked with wrong size! fi # end of overwriting check fi if test -f machdep.h -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"machdep.h\" else echo shar: Extracting \"machdep.h\" \(988 characters\) sed "s/^X//" >machdep.h <<'END_OF_machdep.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 * @(#)machdep.h 5.2 (Berkeley) 3/9/88 X */ X X#define LOGFILE "/usr/games/lib/saillog" /* has to match the makefile */ X X#define TIMEOUT 300 /* Sync() timeout in seconds */ X X/* for 4.2bsd machines */ X#define blockalarm() ((void) sigblock(1 << SIGALRM-1)) X#define unblockalarm() ((void) sigsetmask(sigblock(0) & ~(1 << SIGALRM-1))) X X/* for 2.9bsd machines (onyx) Xtypedef int void; X#define blockalarm() ((void) sighold(SIGALRM)) X#define unblockalarm() ((void) sigrelse(SIGALRM)) X*/ END_OF_machdep.h if test 988 -ne `wc -c <machdep.h`; then echo shar: \"machdep.h\" unpacked with wrong size! fi # end of overwriting check fi if test -f misc.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"misc.c\" else echo shar: Extracting \"misc.c\" \(4932 characters\) sed "s/^X//" >misc.c <<'END_OF_misc.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[] = "@(#)misc.c 5.2 (Berkeley) 3/9/88"; X#endif /* not lint */ X X#include "externs.h" X X#define distance(x,y) (abs(x) >= abs(y) ? abs(x) + abs(y)/2 : abs(y) + abs(x)/2) X X/* XXX */ Xrange(from, to) Xstruct ship *from, *to; X{ X register bow1r, bow1c, bow2r, bow2c; X int stern1r, stern1c, stern2c, stern2r; X register int bb, bs, sb, ss, result; X X if (!to->file->dir) X return -1; X stern1r = bow1r = from->file->row; X stern1c = bow1c = from->file->col; X stern2r = bow2r = to->file->row; X stern2c = bow2c = to->file->col; X result = bb = distance(bow2r - bow1r, bow2c - bow1c); X if (bb < 5) { X stern2r += dr[to->file->dir]; X stern2c += dc[to->file->dir]; X stern1r += dr[from->file->dir]; X stern1c += dc[from->file->dir]; X bs = distance((bow2r - stern1r), (bow2c - stern1c)); X sb = distance((bow1r - stern2r), (bow1c - stern2c)); X ss = distance((stern2r - stern1r) ,(stern2c - stern1c)); X result = min(bb, min(bs, min(sb, ss))); X } X return result; X} X Xstruct ship * Xclosestenemy(from, side, anyship) Xregister struct ship *from; Xchar side, anyship; X{ X register struct ship *sp; X register char a; X int olddist = 30000, dist; X struct ship *closest = 0; X X a = capship(from)->nationality; X foreachship(sp) { X if (sp == from) X continue; X if (sp->file->dir == 0) X continue; X if (a == capship(sp)->nationality && !anyship) X continue; X if (side && gunsbear(from, sp) != side) X continue; X dist = range(from, sp); X if (dist < olddist) { X closest = sp; X olddist = dist; X } X } X return closest; X} X Xangle(dr, dc) Xregister dr, dc; X{ X register i; X X if (dc >= 0 && dr > 0) X i = 0; X else if (dr <= 0 && dc > 0) X i = 2; X else if (dc <= 0 && dr < 0) X i = 4; X else X i = 6; X dr = abs(dr); X dc = abs(dc); X if ((i == 0 || i == 4) && dc * 2.4 > dr) { X i++; X if (dc > dr * 2.4) X i++; X } else if ((i == 2 || i == 6) && dr * 2.4 > dc) { X i++; X if (dr > dc * 2.4) X i++; X } X return i % 8 + 1; X} X Xgunsbear(from, to) /* checks for target bow or stern */ Xregister struct ship *from, *to; X{ X int Dr, Dc, i; X register ang; X X Dr = from->file->row - to->file->row; X Dc = to->file->col - from->file->col; X for (i = 2; i; i--) { X if ((ang = angle(Dr, Dc) - from->file->dir + 1) < 1) X ang += 8; X if (ang >= 2 && ang <= 4) X return 'r'; X if (ang >= 6 && ang <= 7) X return 'l'; X Dr += dr[to->file->dir]; X Dc += dc[to->file->dir]; X } X return 0; X} X Xportside(from, on, quick) Xregister struct ship *from, *on; Xint quick; /* returns true if fromship is */ X{ /* shooting at onship's starboard side */ X register ang; X register Dr, Dc; X X Dr = from->file->row - on->file->row; X Dc = on->file->col - from->file->col; X if (quick == -1) { X Dr += dr[on->file->dir]; X Dc += dc[on->file->dir]; X } X ang = angle(Dr, Dc); X if (quick != 0) X return ang; X ang = (ang + 4 - on->file->dir - 1) % 8 + 1; X return ang < 5; X} X Xcolours(sp) Xregister struct ship *sp; X{ X register char flag; X X if (sp->file->struck) X flag = '!'; X if (sp->file->explode) X flag = '#'; X if (sp->file->sink) X flag = '~'; X if (sp->file->struck) X return flag; X flag = *countryname[capship(sp)->nationality]; X return sp->file->FS ? flag : tolower(flag); X} X X#include <sys/file.h> Xlog(s) Xregister struct ship *s; X{ X FILE *fp; X int persons; X int n; X struct logs log[NLOG]; X float net; X register struct logs *lp; X X if ((fp = fopen(LOGFILE, "r+")) == NULL) X return; X#ifdef LOCK_EX X if (flock(fileno(fp), LOCK_EX) < 0) X return; X#endif X net = (float)s->file->points / s->specs->pts; X persons = getw(fp); X n = fread((char *)log, sizeof(struct logs), NLOG, fp); X for (lp = &log[n]; lp < &log[NLOG]; lp++) X lp->l_name[0] = lp->l_uid = lp->l_shipnum X = lp->l_gamenum = lp->l_netpoints = 0; X rewind(fp); X if (persons < 0) X (void) putw(1, fp); X else X (void) putw(persons + 1, fp); X for (lp = log; lp < &log[NLOG]; lp++) X if (net > (float)lp->l_netpoints X / scene[lp->l_gamenum].ship[lp->l_shipnum].specs->pts) { X (void) fwrite((char *)log, X sizeof (struct logs), lp - log, fp); X (void) strcpy(log[NLOG-1].l_name, s->file->captain); X log[NLOG-1].l_uid = getuid(); X log[NLOG-1].l_shipnum = s->file->index; X log[NLOG-1].l_gamenum = game; X log[NLOG-1].l_netpoints = s->file->points; X (void) fwrite((char *)&log[NLOG-1], X sizeof (struct logs), 1, fp); X (void) fwrite((char *)lp, X sizeof (struct logs), &log[NLOG-1] - lp, fp); X break; X } X#ifdef LOCK_EX X (void) flock(fileno(fp), LOCK_UN); X#endif X (void) fclose(fp); X} END_OF_misc.c if test 4932 -ne `wc -c <misc.c`; then echo shar: \"misc.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f pl_1.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"pl_1.c\" else echo shar: Extracting \"pl_1.c\" \(2643 characters\) sed "s/^X//" >pl_1.c <<'END_OF_pl_1.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[] = "@(#)pl_1.c 5.2 (Berkeley) 3/9/88"; X#endif /* not lint */ X X#include "player.h" X#include <sys/types.h> X#include <sys/wait.h> X X/* X * If we get here before a ship is chosen, then ms == 0 and X * we don't want to update the score file, or do any Write's either. X * We can assume the sync file is already created and may need X * to be removed. X * Of course, we don't do any more Sync()'s if we got here X * because of a Sync() failure. X */ Xleave(conditions) Xint conditions; X{ X (void) signal(SIGHUP, SIG_IGN); X (void) signal(SIGINT, SIG_IGN); X (void) signal(SIGQUIT, SIG_IGN); X (void) signal(SIGALRM, SIG_IGN); X (void) signal(SIGCHLD, SIG_IGN); X X if (done_curses) { X Signal("It looks like you've had it!", X (struct ship *)0); X switch (conditions) { X case LEAVE_QUIT: X break; X case LEAVE_CAPTURED: X Signal("Your ship was captured.", X (struct ship *)0); X break; X case LEAVE_HURRICAN: X Signal("Hurricane! All ships destroyed.", X (struct ship *)0); X break; X case LEAVE_DRIVER: X Signal("The driver died.", (struct ship *)0); X break; X case LEAVE_SYNC: X Signal("Synchronization error.", (struct ship *)0); X break; X default: X Signal("A funny thing happened (%d).", X (struct ship *)0, conditions); X } X } else { X switch (conditions) { X case LEAVE_QUIT: X break; X case LEAVE_DRIVER: X printf("The driver died.\n"); X break; X case LEAVE_FORK: X perror("fork"); X break; X case LEAVE_SYNC: X printf("Synchronization error\n."); X break; X default: X printf("A funny thing happened (%d).\n", X conditions); X } X } X X if (ms != 0) { X log(ms); X if (conditions != LEAVE_SYNC) { X makesignal(ms, "Captain %s relinquishing.", X (struct ship *)0, mf->captain); X Write(W_END, ms, 0, 0, 0, 0, 0); X (void) Sync(); X } X } X sync_close(!hasdriver); X cleanupscreen(); X exit(0); X} X Xchoke() X{ X leave(LEAVE_QUIT); X} X Xchild() X{ X union wait status; X int pid; X X (void) signal(SIGCHLD, SIG_IGN); X do { X pid = wait3(&status, WNOHANG, (struct rusage *)0); X if (pid < 0 || pid > 0 && !WIFSTOPPED(status)) X hasdriver = 0; X } while (pid > 0); X (void) signal(SIGCHLD, child); X} END_OF_pl_1.c if test 2643 -ne `wc -c <pl_1.c`; then echo shar: \"pl_1.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f pl_2.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"pl_2.c\" else echo shar: Extracting \"pl_2.c\" \(2512 characters\) sed "s/^X//" >pl_2.c <<'END_OF_pl_2.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[] = "@(#)pl_2.c 5.2 (Berkeley) 3/9/88"; X#endif /* not lint */ X X#include "player.h" X Xplay() X{ X register struct ship *sp; X X for (;;) { X switch (sgetch("~\b", (struct ship *)0, 0)) { X case 'm': X acceptmove(); X break; X case 's': X acceptsignal(); X break; X case 'g': X grapungrap(); X break; X case 'u': X unfoulplayer(); X break; X case 'v': X Signal("%s", (struct ship *)0, version); X break; X case 'b': X acceptboard(); X break; X case 'f': X acceptcombat(); X break; X case 'l': X loadplayer(); X break; X case 'c': X changesail(); X break; X case 'r': X repair(); X break; X case 'B': X Signal("'Hands to stations!'", (struct ship *)0); X unboard(ms, ms, 1); /* cancel DBP's */ X unboard(ms, ms, 0); /* cancel offense */ X break; X case '\f': X centerview(); X blockalarm(); X draw_board(); X draw_screen(); X unblockalarm(); X break; X case 'L': X mf->loadL = L_EMPTY; X mf->loadR = L_EMPTY; X mf->readyL = R_EMPTY; X mf->readyR = R_EMPTY; X Signal("Broadsides unloaded", (struct ship *)0); X break; X case 'q': X Signal("Type 'Q' to quit", (struct ship *)0); X break; X case 'Q': X leave(LEAVE_QUIT); X break; X case 'I': X foreachship(sp) X if (sp != ms) X eyeball(sp); X break; X case 'i': X if ((sp = closestenemy(ms, 0, 1)) == 0) X Signal("No more ships left."); X else X eyeball(sp); X break; X case 'C': X centerview(); X blockalarm(); X draw_view(); X unblockalarm(); X break; X case 'U': X upview(); X blockalarm(); X draw_view(); X unblockalarm(); X break; X case 'D': X case 'N': X downview(); X blockalarm(); X draw_view(); X unblockalarm(); X break; X case 'H': X leftview(); X blockalarm(); X draw_view(); X unblockalarm(); X break; X case 'J': X rightview(); X blockalarm(); X draw_view(); X unblockalarm(); X break; X case 'F': X lookout(); X break; X case 'S': X dont_adjust = !dont_adjust; X blockalarm(); X draw_turn(); X unblockalarm(); X break; X } X } X} END_OF_pl_2.c if test 2512 -ne `wc -c <pl_2.c`; then echo shar: \"pl_2.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f pl_3.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"pl_3.c\" else echo shar: Extracting \"pl_3.c\" \(5916 characters\) sed "s/^X//" >pl_3.c <<'END_OF_pl_3.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[] = "@(#)pl_3.c 5.2 (Berkeley) 3/9/88"; X#endif /* not lint */ X X#include "player.h" X Xacceptcombat() X{ X int men = 0; X int target, temp; X int n, r; X int index, rakehim, sternrake; X int hhits = 0, ghits = 0, rhits = 0, chits = 0; X int crew[3]; X int load; X int guns, car, ready, shootat, hit; X int roll; X struct ship *closest; X X crew[0] = mc->crew1; X crew[1] = mc->crew2; X crew[2] = mc->crew3; X for (n = 0; n < 3; n++) { X if (mf->OBP[n].turnsent) X men += mf->OBP[n].mensent; X } X for (n = 0; n < 3; n++) { X if (mf->DBP[n].turnsent) X men += mf->DBP[n].mensent; X } X if (men) { X crew[0] = men/100 ? 0 : crew[0] != 0; X crew[1] = (men%100)/10 ? 0 : crew[1] != 0; X crew[2] = men%10 ? 0 : crew[2] != 0; X } X for (r = 0; r < 2; r++) { X if (r) { X ready = mf->readyR; X load = mf->loadR; X guns = mc->gunR; X car = mc->carR; X } else { X ready = mf->readyL; X load = mf->loadL; X guns = mc->gunL; X car = mc->carL; X } X if (!guns && !car || load == L_EMPTY || (ready & R_LOADED) == 0) X goto cant; X if (mf->struck || !crew[2]) X goto cant; X closest = closestenemy(ms, (r ? 'r' : 'l'), 1); X if (closest == 0) X goto cant; X if (closest->file->struck) X goto cant; X target = range(ms, closest); X if (target > rangeofshot[load] || !guns && target >= 3) X goto cant; X Signal("%s (%c%c) within range of %s broadside.", X closest, r ? "right" : "left"); X if (load > L_CHAIN && target < 6) { X switch (sgetch("Aim for hull or rigging? ", X (struct ship *)0, 1)) { X case 'r': X shootat = RIGGING; X break; X case 'h': X shootat = HULL; X break; X default: X shootat = -1; X Signal("'Avast there! Hold your fire.'", X (struct ship *)0); X } X } else { X if (sgetch("Fire? ", (struct ship *)0, 1) == 'n') { X shootat = -1; X Signal("Belay that! Hold your fire.", X (struct ship *)0); X } else X shootat = RIGGING; X } X if (shootat == -1) X continue; X fired = 1; X rakehim = gunsbear(ms, closest) && !gunsbear(closest, ms); X temp = portside(closest, ms, 1) - closest->file->dir + 1; X if (temp < 1) X temp += 8; X else if (temp > 8) X temp -= 8; X sternrake = temp > 4 && temp < 6; X if (rakehim) X if (!sternrake) X Signal("Raking the %s!", closest); X else X Signal("Stern Rake! %s splintering!", closest); X index = guns; X if (target < 3) X index += car; X index = (index - 1)/3; X index = index > 8 ? 8 : index; X if (!rakehim) X hit = HDT[index][target-1]; X else X hit = HDTrake[index][target-1]; X if (rakehim && sternrake) X hit++; X hit += QUAL[index][mc->qual-1]; X for (n = 0; n < 3 && mf->captured == 0; n++) X if (!crew[n]) X if (index <= 5) X hit--; X else X hit -= 2; X if (ready & R_INITIAL) X if (index <= 3) X hit++; X else X hit += 2; X if (mf->captured != 0) X if (index <= 1) X hit--; X else X hit -= 2; X hit += AMMO[index][load - 1]; X if (((temp = mc->class) >= 5 || temp == 1) && windspeed == 5) X hit--; X if (windspeed == 6 && temp == 4) X hit -= 2; X if (windspeed == 6 && temp <= 3) X hit--; X if (hit >= 0) { X roll = die(); X if (load == L_GRAPE) X chits = hit; X else { X struct Tables *t; X if (hit > 10) X hit = 10; X t = &(shootat == RIGGING ? RigTable : HullTable) X [hit][roll-1]; X chits = t->C; X rhits = t->R; X hhits = t->H; X ghits = t->G; X if (closest->file->FS) X rhits *= 2; X if (load == L_CHAIN) { X ghits = 0; X hhits = 0; X } X } X table(shootat, load, hit, closest, ms, roll); X } X Signal("Damage inflicted on the %s:", X (struct ship *)0, closest->shipname); X Signal("\t%d HULL, %d GUNS, %d CREW, %d RIGGING", X (struct ship *)0, hhits, ghits, chits, rhits); X if (!r) { X mf->loadL = L_EMPTY; X mf->readyL = R_EMPTY; X } else { X mf->loadR = L_EMPTY; X mf->readyR = R_EMPTY; X } X continue; X cant: X Signal("Unable to fire %s broadside", X (struct ship *)0, r ? "right" : "left"); X } X blockalarm(); X draw_stat(); X unblockalarm(); X} X Xgrapungrap() X{ X register struct ship *sp; X register int i; X X foreachship(sp) { X if (sp == ms || sp->file->dir == 0) X continue; X if (range(ms, sp) > 1 && !grappled2(ms, sp)) X continue; X switch (sgetch("Attempt to grapple or ungrapple %s (%c%c): ", X sp, 1)) { X case 'g': X if (die() < 3 X || ms->nationality == capship(sp)->nationality) { X Write(W_GRAP, ms, 0, sp->file->index, 0, 0, 0); X Write(W_GRAP, sp, 0, player, 0, 0, 0); X Signal("Attempt succeeds!", (struct ship *)0); X makesignal(ms, "grappled with %s (%c%c)", sp); X } else X Signal("Attempt fails.", (struct ship *)0); X break; X case 'u': X for (i = grappled2(ms, sp); --i >= 0;) { X if (ms->nationality X == capship(sp)->nationality X || die() < 3) { X cleangrapple(ms, sp, 0); X Signal("Attempt succeeds!", X (struct ship *)0); X makesignal(ms, X "ungrappling with %s (%c%c)", X sp); X } else X Signal("Attempt fails.", X (struct ship *)0); X } X break; X } X } X} X Xunfoulplayer() X{ X register struct ship *to; X register i; X X foreachship(to) { X if (fouled2(ms, to) == 0) X continue; X if (sgetch("Attempt to unfoul with the %s (%c%c)? ", to, 1) != 'y') X continue; X for (i = fouled2(ms, to); --i >= 0;) { X if (die() <= 2) { X cleanfoul(ms, to, 0); X Signal("Attempt succeeds!", (struct ship *)0); X makesignal(ms, "Unfouling %s (%c%c)", to); X } else X Signal("Attempt fails.", (struct ship *)0); X } X } X} END_OF_pl_3.c if test 5916 -ne `wc -c <pl_3.c`; then echo shar: \"pl_3.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f pl_4.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"pl_4.c\" else echo shar: Extracting \"pl_4.c\" \(2373 characters\) sed "s/^X//" >pl_4.c <<'END_OF_pl_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[] = "@(#)pl_4.c 5.2 (Berkeley) 3/9/88"; X#endif /* not lint */ X X#include "player.h" X Xchangesail() X{ X int rig, full; X X rig = mc->rig1; X full = mf->FS; X if (windspeed == 6 || windspeed == 5 && mc->class > 4) X rig = 0; X if (mc->crew3 && rig) { X if (!full) { X if (sgetch("Increase to Full sails? ", X (struct ship *)0, 1) == 'y') { X changed = 1; X Write(W_FS, ms, 0, 1, 0, 0, 0); X } X } else { X if (sgetch("Reduce to Battle sails? ", X (struct ship *)0, 1) == 'y') { X Write(W_FS, ms, 0, 0, 0, 0, 0); X changed = 1; X } X } X } else if (!rig) X Signal("Sails rent to pieces", (struct ship *)0); X} X Xacceptsignal() X{ X char buf[60]; X register char *p = buf; X X *p++ = '"'; X sgetstr("Message? ", p, sizeof buf - 2); X while (*p++) X ; X p[-1] = '"'; X *p = 0; X Write(W_SIGNAL, ms, 1, (int)buf, 0, 0, 0); X} X Xlookout() X{ X register struct ship *sp; X char buf[3]; X register char c; X X sgetstr("What ship? ", buf, sizeof buf); X foreachship(sp) { X c = *countryname[sp->nationality]; X if ((c == *buf || tolower(c) == *buf || colours(sp) == *buf) X && (sp->file->stern == buf[1] || sterncolour(sp) == buf[1] X || buf[1] == '?')) { X eyeball(sp); X } X } X} X Xchar * Xsaywhat(sp, flag) Xregister struct ship *sp; Xchar flag; X{ X if (sp->file->captain[0]) X return sp->file->captain; X else if (sp->file->struck) X return "(struck)"; X else if (sp->file->captured != 0) X return "(captured)"; X else if (flag) X return "(available)"; X else X return "(computer)"; X} X Xeyeball(ship) Xregister struct ship *ship; X{ X int i; X X if (ship->file->dir != 0) { X Signal("Sail ho! (range %d, %s)", X (struct ship *)0, range(ms, ship), saywhat(ship, 0)); X i = portside(ms, ship, 1) - mf->dir; X if (i <= 0) X i += 8; X Signal("%s (%c%c) %s %s %s.", X ship, countryname[ship->nationality], X classname[ship->specs->class], directionname[i]); X } X} END_OF_pl_4.c if test 2373 -ne `wc -c <pl_4.c`; then echo shar: \"pl_4.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f pl_6.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"pl_6.c\" else echo shar: Extracting \"pl_6.c\" \(3596 characters\) sed "s/^X//" >pl_6.c <<'END_OF_pl_6.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[] = "@(#)pl_6.c 5.2 (Berkeley) 3/9/88"; X#endif /* not lint */ X X#include "player.h" X Xrepair() X{ X char c; X register char *repairs; X register struct shipspecs *ptr = mc; X register int count; X X#define FIX(x, m) (m - ptr->x > count \ X ? (ptr->x += count, count = 0) : (count -= m - ptr->x, ptr->x = m)) X X if (repaired || loaded || fired || changed || turned()) { X Signal("No hands free to repair", (struct ship *)0); X return; X } X c = sgetch("Repair (hull, guns, rigging)? ", (struct ship *)0, 1); X switch (c) { X case 'h': X repairs = &mf->RH; X break; X case 'g': X repairs = &mf->RG; X break; X case 'r': X repairs = &mf->RR; X break; X default: X Signal("Avast heaving!", (struct ship *)0); X return; X } X if (++*repairs >= 3) { X count = 2; X switch (c) { X case 'h': { X int max = ptr->guns/4; X if (ptr->hull < max) { X FIX(hull, max); X Write(W_HULL, ms, 0, ptr->hull, 0, 0, 0); X } X break; X } X case 'g': X if (ptr->gunL < ptr->gunR) { X int max = ptr->guns/5 - ptr->carL; X if (ptr->gunL < max) { X FIX(gunL, max); X Write(W_GUNL, ms, 0, ptr->gunL, X ptr->carL, 0, 0); X } X } else { X int max = ptr->guns/5 - ptr->carR; X if (ptr->gunR < max) { X FIX(gunR, max); X Write(W_GUNR, ms, 0, ptr->gunR, X ptr->carR, 0, 0); X } X } X break; X case 'r': X#define X 2 X if (ptr->rig4 >= 0 && ptr->rig4 < X) { X FIX(rig4, X); X Write(W_RIG4, ms, 0, ptr->rig4, 0, 0, 0); X } X if (count && ptr->rig3 < X) { X FIX(rig3, X); X Write(W_RIG3, ms, 0, ptr->rig3, 0, 0, 0); X } X if (count && ptr->rig2 < X) { X FIX(rig2, X); X Write(W_RIG2, ms, 0, ptr->rig2, 0, 0, 0); X } X if (count && ptr->rig1 < X) { X FIX(rig1, X); X Write(W_RIG1, ms, 0, ptr->rig1, 0, 0, 0); X } X break; X } X if (count == 2) { X Signal("Repairs completed.", (struct ship *)0); X *repairs = 2; X } else { X *repairs = 0; X blockalarm(); X draw_stat(); X unblockalarm(); X } X } X blockalarm(); X draw_slot(); X unblockalarm(); X repaired = 1; X} X Xturned() X{ X register char *p; X X for (p = movebuf; *p; p++) X if (*p == 'r' || *p == 'l') X return 1; X return 0; X} X Xloadplayer() X{ X char c; X register loadL, loadR, ready, load; X X if (!mc->crew3) { X Signal("Out of crew", (struct ship *)0); X return; X } X loadL = mf->loadL; X loadR = mf->loadR; X if (!loadL && !loadR) { X c = sgetch("Load which broadside (left or right)? ", X (struct ship *)0, 1); X if (c == 'r') X loadL = 1; X else X loadR = 1; X } X if (!loadL && loadR || loadL && !loadR) { X c = sgetch("Reload with (round, double, chain, grape)? ", X (struct ship *)0, 1); X switch (c) { X case 'r': X load = L_ROUND; X ready = 0; X break; X case 'd': X load = L_DOUBLE; X ready = R_DOUBLE; X break; X case 'c': X load = L_CHAIN; X ready = 0; X break; X case 'g': X load = L_GRAPE; X ready = 0; X break; X default: X Signal("Broadside not loaded.", X (struct ship *)0); X return; X } X if (!loadR) { X mf->loadR = load; X mf->readyR = ready|R_LOADING; X } else { X mf->loadL = load; X mf->readyL = ready|R_LOADING; X } X loaded = 1; X } X} END_OF_pl_6.c if test 3596 -ne `wc -c <pl_6.c`; then echo shar: \"pl_6.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f pl_main.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"pl_main.c\" else echo shar: Extracting \"pl_main.c\" \(4998 characters\) sed "s/^X//" >pl_main.c <<'END_OF_pl_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[] = "@(#)pl_main.c 5.2 (Berkeley) 3/9/88"; X#endif /* not lint */ X X#include "player.h" X#include <sys/types.h> X#include <sys/wait.h> X Xint choke(), child(); X X/*ARGSUSED*/ Xpl_main() X{ X X if (!SCREENTEST()) { X printf("Can't sail on this terminal.\n"); X exit(1); X } X initialize(); X Signal("Aye aye, Sir", (struct ship *)0); X play(); X return 0; /* for lint, play() never returns */ X} X Xinitialize() X{ X register struct File *fp; X register struct ship *sp; X char captain[80]; X char message[60]; X int load; X register int n; X char *nameptr; X int nat[NNATION]; X X if (game < 0) { X (void) puts("Choose a scenario:\n"); X (void) puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE"); X for (n = 0; n < NSCENE; n++) { X /* ( */ X printf("\t%d):\t%d\t%s\t%s\n", n, scene[n].vessels, X sync_exists(n) ? "YES" : "no", X scene[n].name); X } Xreprint: X printf("\nScenario number? "); X (void) fflush(stdout); X (void) scanf("%d", &game); X while (getchar() != '\n') X ; X } X if (game < 0 || game >= NSCENE) { X (void) puts("Very funny."); X exit(1); X } X cc = &scene[game]; X ls = SHIP(cc->vessels); 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) puts("OUT OF MEMORY"); X exit(1); X } X sp->file->index = sp - SHIP(0); 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 X (void) signal(SIGHUP, choke); X (void) signal(SIGINT, choke); X X hasdriver = sync_exists(game); X if (sync_open() < 0) { X perror("sail: syncfile"); X exit(1); X } X X if (hasdriver) { X (void) puts("Synchronizing with the other players..."); X (void) fflush(stdout); X if (Sync() < 0) X leave(LEAVE_SYNC); X } X for (;;) { X foreachship(sp) X if (sp->file->captain[0] == 0 && !sp->file->struck X && sp->file->captured == 0) X break; X if (sp >= ls) { X (void) puts("All ships taken in that scenario."); X foreachship(sp) X free((char *)sp->file); X sync_close(0); X people = 0; X goto reprint; X } X if (randomize) { X player = sp - SHIP(0); X } else { X printf("%s\n\n", cc->name); X foreachship(sp) X printf(" %2d: %-10s %-15s (%-2d pts) %s\n", X sp->file->index, X countryname[sp->nationality], X sp->shipname, X sp->specs->pts, X saywhat(sp, 1)); X printf("\nWhich ship (0-%d)? ", cc->vessels-1); X (void) fflush(stdout); X if (scanf("%d", &player) != 1 || player < 0 X || player >= cc->vessels) { X while (getchar() != '\n') X ; X (void) puts("Say what?"); X player = -1; X } else X while (getchar() != '\n') X ; X } X if (player < 0) X continue; X if (Sync() < 0) X leave(LEAVE_SYNC); X fp = SHIP(player)->file; X if (fp->captain[0] || fp->struck || fp->captured != 0) X (void) puts("That ship is taken."); X else X break; X } X X ms = SHIP(player); X mf = ms->file; X mc = ms->specs; X X Write(W_BEGIN, ms, 0, 0, 0, 0, 0); X if (Sync() < 0) X leave(LEAVE_SYNC); X X (void) signal(SIGCHLD, child); X if (!hasdriver) X switch (fork()) { X case 0: X longjmp(restart, MODE_DRIVER); X /*NOTREACHED*/ X case -1: X perror("fork"); X leave(LEAVE_FORK); X break; X default: X hasdriver++; X } X X printf("Your ship is the %s, a %d gun %s (%s crew).\n", X ms->shipname, mc->guns, classname[mc->class], X qualname[mc->qual]); X if ((nameptr = (char *) getenv("SAILNAME")) && *nameptr) X (void) strncpy(captain, nameptr, sizeof captain); X else { X (void) printf("Your name, Captain? "); X (void) fflush(stdout); X (void) gets(captain); X if (!*captain) X (void) strcpy(captain, "no name"); X } X captain[sizeof captain - 1] = '\0'; X Write(W_CAPTAIN, ms, 1, (int)captain, 0, 0, 0); X for (n = 0; n < 2; n++) { X char buf[10]; X X printf("\nInitial broadside %s (grape, chain, round, double): ", X n ? "right" : "left"); X (void) fflush(stdout); X (void) scanf("%s", buf); X switch (*buf) { X case 'g': X load = L_GRAPE; X break; X case 'c': X load = L_CHAIN; X break; X case 'r': X load = L_ROUND; X break; X case 'd': X load = L_DOUBLE; X break; X default: X load = L_ROUND; X } X if (n) { X mf->loadR = load; X mf->readyR = R_LOADED|R_INITIAL; X } else { X mf->loadL = load; X mf->readyL = R_LOADED|R_INITIAL; X } X } X X initscreen(); X draw_board(); X (void) sprintf(message, "Captain %s assuming command", captain); X Write(W_SIGNAL, ms, 1, (int)message, 0, 0, 0); X newturn(); X} END_OF_pl_main.c if test 4998 -ne `wc -c <pl_main.c`; then echo shar: \"pl_main.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f player.h -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"player.h\" else echo shar: Extracting \"player.h\" \(2642 characters\) sed "s/^X//" >player.h <<'END_OF_player.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 * @(#)player.h 5.2 (Berkeley) 3/9/88 X */ X X#include <curses.h> X#include "externs.h" X X/* sizes and coordinates for the screen */ X X#define LINE_T 0 X#define LINE_L 0 X#define LINE_X COLS X#define LINE_Y 1 X#define LINE_B (LINE_T+LINE_Y-1) X#define LINE_R (LINE_L+LINE_X-1) X X#define BOX_T 1 X#define BOX_L 0 X#define BOX_X 65 X#define BOX_Y 16 X#define BOX_B (BOX_T+BOX_Y-1) X#define BOX_R (BOX_L+BOX_X-1) X X#define TURN_T BOX_B X#define TURN_Y 1 X#define TURN_L ((BOX_L+BOX_R-TURN_X)/2) X#define TURN_X 9 X#define TURN_B (TURN_T+TURN_Y+1) X#define TURN_R (TURN_L+TURN_X+1) X X#define STAT_T 0 X#define STAT_B BOX_B X#define STAT_L (BOX_R+2) X#define STAT_X 14 X#define STAT_Y (STAT_B-STAT_T+1) X#define STAT_R (STAT_L+STAT_X-1) X#define STAT_1 0 X#define STAT_2 (STAT_1+4) X#define STAT_3 (STAT_2+7) X X#define SCROLL_T (BOX_B+1) X#define SCROLL_L 0 X#define SCROLL_B (LINES-1) X#define SCROLL_R (COLS-1) X#define SCROLL_X (SCROLL_R-SCROLL_L+1) X#define SCROLL_Y (SCROLL_B-SCROLL_T+1) X X#define VIEW_T (BOX_T+1) X#define VIEW_L (BOX_L+1) X#define VIEW_X (BOX_X-5) X#define VIEW_Y (BOX_Y-2) X#define VIEW_B (VIEW_T+VIEW_Y-1) X#define VIEW_R (VIEW_L+VIEW_X-1) X X#define SLOT_T VIEW_T X#define SLOT_L (VIEW_R+1) X#define SLOT_X 3 X#define SLOT_Y VIEW_Y X#define SLOT_B VIEW_B X#define SLOT_R (SLOT_L+SLOT_X-1) X X#ifdef SIGTSTP X#define SCREENTEST() (initscr() != ERR && signal(SIGTSTP, SIG_DFL) != BADSIG && STAT_R < COLS && SCROLL_Y > 0) X#else X#define SCREENTEST() (initscr() != ERR && STAT_R < COLS && SCROLL_Y > 0) X#endif X XWINDOW *view_w; XWINDOW *slot_w; XWINDOW *scroll_w; XWINDOW *stat_w; XWINDOW *turn_w; X Xchar done_curses; Xchar loaded, fired, changed, repaired; Xchar dont_adjust; Xint viewrow, viewcol; Xchar movebuf[sizeof SHIP(0)->file->movebuf]; Xchar version[]; Xint player; Xstruct ship *ms; /* memorial structure, &cc->ship[player] */ Xstruct File *mf; /* ms->file */ Xstruct shipspecs *mc; /* ms->specs */ X X/* condition codes for leave() */ X#define LEAVE_QUIT 0 X#define LEAVE_CAPTURED 1 X#define LEAVE_HURRICAN 2 X#define LEAVE_DRIVER 3 X#define LEAVE_FORK 4 X#define LEAVE_SYNC 5 X X#ifndef CTRL X#define CTRL(c) ((c)&037) X#endif END_OF_player.h if test 2642 -ne `wc -c <player.h`; then echo shar: \"player.h\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of archive 3 \(of 4\). cp /dev/null ark3isdone 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