static char *sccsid
= "@(#)pl_1.c 1.14 83/10/28";
char nodrive
= 0, randomize
= 0, debug
= 0;
while (*++argv
&& **argv
== '-')
printf("Unknown flag '%s'\n",*argv
);
initialize(nodrive
, randomize
, debug
);
Signal("Aye aye, Sir", (struct ship
*)0);
initialize(nodriver
, randomize
, debug
)
char randomize
, nodriver
, debug
;
register struct File
*fp
;
register struct ship
*sp
;
(void) puts("Choose a scenario:\n");
(void) puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
for (n
= 0; n
< NSCENE
; n
++) {
printf("\t%d):\t%d\t%s\t%s\n", n
, scene
[n
].vessels
,
sync_exists(n
) ? "YES" : "no",
printf("\nScenario number? ");
(void) scanf("%d", &game
);
while (getchar() != '\n')
if (game
< 0 || game
>= NSCENE
) {
(void) puts("Very funny.");
ls
= cc
->ship
+ cc
->vessels
;
active
= sync_exists(game
);
perror("sail: syncfile");
for (n
= 0; n
< NNATION
; n
++)
sp
->file
= (struct File
*) calloc(1, sizeof (struct File
));
(void) puts("OUT OF MEMORY");
sp
->file
->stern
= nat
[sp
->nationality
]++;
(void) puts("Synchronizing with the other players...");
if (sp
->file
->captain
[0] == 0 && !sp
->file
->struck
&& sp
->file
->captured
== 0)
(void) puts("All ships taken in that scenario.");
printf("%s\n\n", cc
->name
);
printf(" %2d: %-10s %-15s (%-2d pts) %s\n",
countryname
[sp
->nationality
],
printf("\nWhich ship (0-%d)? ", cc
->vessels
-1);
if (scanf("%d", &player
) != 1 || player
< 0
|| player
>= cc
->vessels
) {
while (getchar() != '\n')
(void) puts("Say what?");
while (getchar() != '\n')
if (fp
->captain
[0] || fp
->struck
|| fp
->captured
!= 0)
(void) puts("That ship is taken.");
(void) signal(SIGHUP
, choke
);
(void) signal(SIGINT
, choke
);
(void) signal(SIGQUIT
, choke
);
(void) signal(SIGCHLD
, child
);
Write(W_BEGIN
, ms
, 0, 0, 0, 0, 0);
printf("Your ship is the %s, a %d gun %s (%s crew).\n",
ms
->shipname
, mc
->guns
, classname
[mc
->class],
if ((nameptr
= (char *) getenv("SAILNAME")) && *nameptr
)
(void) strncpy(captain
, nameptr
, sizeof captain
);
(void) printf("Your name, Captain? ");
(void) strcpy(captain
, "no name");
captain
[sizeof captain
- 1] = '\0';
Write(W_CAPTAIN
, ms
, 1, (int)captain
, 0, 0, 0);
for (n
= 0; n
< 2; n
++) {
printf("\nInitial broadside %s (grape, chain, round, double): ",
mf
->readyR
= R_LOADED
|R_INITIAL
;
mf
->readyL
= R_LOADED
|R_INITIAL
;
if (!active
&& !nodriver
) {
(void) sprintf(num
, "%d", game
);
execl(DEBUGDRIVER
, DRIVERNAME
, num
, 0);
execl(DRIVER
, DRIVERNAME
, num
, 0);
sp
->file
->dir
= sp
->shipdir
;
sp
->file
->row
= sp
->shiprow
;
sp
->file
->col
= sp
->shipcol
;
windspeed
= cc
->windspeed
;
(void) sprintf(message
, "Captain %s assuming command", captain
);
Write(W_SIGNAL
, ms
, 1, (int)message
, 0, 0, 0);
struct logs log
[10], temp
;
(void) signal(SIGHUP
, SIG_IGN
);
(void) signal(SIGINT
, SIG_IGN
);
(void) signal(SIGQUIT
, SIG_IGN
);
(void) signal(SIGALRM
, SIG_IGN
);
(void) signal(SIGCHLD
, SIG_IGN
);
(void) sprintf(message
,"Captain %s relinquishing.",
Write(W_SIGNAL
, ms
, 1, (int)message
, 0, 0, 0);
Write(W_END
, ms
, 0, 0, 0, 0, 0);
if (fp
= fopen(LOGFILE
, "r+")) {
net
= (float)mf
->points
/ mc
->pts
;
n
= fread((char *)log
, sizeof(struct logs
), 10, fp
);
= log
[n
].l_netpoints
= 0;
(void) putw(people
+ 1, fp
);
if (net
> (float) log
[n
].l_netpoints
/ scene
[log
[n
].l_gamenum
].ship
[log
[n
].l_shipnum
].specs
->pts
) {
(void) fwrite((char *)log
,
sizeof (struct logs
), n
, fp
);
(void) strcpy(temp
.l_name
, mf
->captain
);
temp
.l_netpoints
= mf
->points
;
(void) fwrite((char *)&temp
,
(void) fwrite((char *)&log
[n
],
sizeof (struct logs
), 9-n
, fp
);
Signal("It looks like you've had it!",
Signal("Your ship was captured.",
Signal("Hurricane! All ships destroyed.",
Signal("The driver died.", (struct ship
*)0);
Signal("A funny thing happened (%d).",
(struct ship
*)0, conditions
);
printf("The driver died.\n");
printf("A funny thing happened (%d).\n",
(void) signal(SIGCHLD
, SIG_IGN
);
pid
= wait3(&status
, WNOHANG
|WUNTRACED
, (struct rusage
*)0);
if (pid
< 0 || pid
> 0 && !WIFSTOPPED(status
))
(void) signal(SIGCHLD
, child
);