mirror of
https://github.com/vattam/BSDGames.git
synced 2025-12-21 03:14:50 +00:00
copy in from cvs; cvs2svn fucked up big time
git-svn-id: file:///srv/svn/joey/trunk/src/packages/bsdgames@9775 a4a2c43b-8ac3-0310-8836-e0e880c912e2
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pl_main.c,v 1.6 1997/10/13 19:45:48 christos Exp $ */
|
||||
/* $NetBSD: pl_main.c,v 1.15 2001/02/05 01:10:11 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@@ -38,19 +38,25 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)pl_main.c 8.1 (Berkeley) 5/31/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: pl_main.c,v 1.6 1997/10/13 19:45:48 christos Exp $");
|
||||
__RCSID("$NetBSD: pl_main.c,v 1.15 2001/02/05 01:10:11 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include "player.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "extern.h"
|
||||
#include "player.h"
|
||||
#include "restart.h"
|
||||
|
||||
static void initialize(void);
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
pl_main()
|
||||
pl_main(void)
|
||||
{
|
||||
|
||||
initialize();
|
||||
@@ -59,21 +65,21 @@ pl_main()
|
||||
return 0; /* for lint, play() never returns */
|
||||
}
|
||||
|
||||
void
|
||||
initialize()
|
||||
static void
|
||||
initialize(void)
|
||||
{
|
||||
register struct File *fp;
|
||||
register struct ship *sp;
|
||||
struct File *fp;
|
||||
struct ship *sp;
|
||||
char captain[80];
|
||||
char message[60];
|
||||
int load;
|
||||
register int n;
|
||||
int n;
|
||||
char *nameptr;
|
||||
int nat[NNATION];
|
||||
|
||||
if (game < 0) {
|
||||
(void) puts("Choose a scenario:\n");
|
||||
(void) puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
|
||||
puts("Choose a scenario:\n");
|
||||
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,
|
||||
@@ -82,13 +88,13 @@ initialize()
|
||||
}
|
||||
reprint:
|
||||
printf("\nScenario number? ");
|
||||
(void) fflush(stdout);
|
||||
(void) scanf("%d", &game);
|
||||
fflush(stdout);
|
||||
scanf("%d", &game);
|
||||
while (getchar() != '\n')
|
||||
;
|
||||
}
|
||||
if (game < 0 || game >= NSCENE) {
|
||||
(void) puts("Very funny.");
|
||||
puts("Very funny.");
|
||||
exit(1);
|
||||
}
|
||||
cc = &scene[game];
|
||||
@@ -99,7 +105,7 @@ reprint:
|
||||
foreachship(sp) {
|
||||
if (sp->file == NULL &&
|
||||
(sp->file = (struct File *)calloc(1, sizeof (struct File))) == NULL) {
|
||||
(void) puts("OUT OF MEMORY");
|
||||
puts("OUT OF MEMORY");
|
||||
exit(1);
|
||||
}
|
||||
sp->file->index = sp - SHIP(0);
|
||||
@@ -111,8 +117,8 @@ reprint:
|
||||
windspeed = cc->windspeed;
|
||||
winddir = cc->winddir;
|
||||
|
||||
(void) signal(SIGHUP, choke);
|
||||
(void) signal(SIGINT, choke);
|
||||
signal(SIGHUP, choke);
|
||||
signal(SIGINT, choke);
|
||||
|
||||
hasdriver = sync_exists(game);
|
||||
if (sync_open() < 0) {
|
||||
@@ -121,8 +127,8 @@ reprint:
|
||||
}
|
||||
|
||||
if (hasdriver) {
|
||||
(void) puts("Synchronizing with the other players...");
|
||||
(void) fflush(stdout);
|
||||
puts("Synchronizing with the other players...");
|
||||
fflush(stdout);
|
||||
if (Sync() < 0)
|
||||
leave(LEAVE_SYNC);
|
||||
}
|
||||
@@ -132,7 +138,7 @@ reprint:
|
||||
&& sp->file->captured == 0)
|
||||
break;
|
||||
if (sp >= ls) {
|
||||
(void) puts("All ships taken in that scenario.");
|
||||
puts("All ships taken in that scenario.");
|
||||
foreachship(sp)
|
||||
free((char *)sp->file);
|
||||
sync_close(0);
|
||||
@@ -151,12 +157,12 @@ reprint:
|
||||
sp->specs->pts,
|
||||
saywhat(sp, 1));
|
||||
printf("\nWhich ship (0-%d)? ", cc->vessels-1);
|
||||
(void) fflush(stdout);
|
||||
fflush(stdout);
|
||||
if (scanf("%d", &player) != 1 || player < 0
|
||||
|| player >= cc->vessels) {
|
||||
while (getchar() != '\n')
|
||||
;
|
||||
(void) puts("Say what?");
|
||||
puts("Say what?");
|
||||
player = -1;
|
||||
} else
|
||||
while (getchar() != '\n')
|
||||
@@ -168,7 +174,7 @@ reprint:
|
||||
leave(LEAVE_SYNC);
|
||||
fp = SHIP(player)->file;
|
||||
if (fp->captain[0] || fp->struck || fp->captured != 0)
|
||||
(void) puts("That ship is taken.");
|
||||
puts("That ship is taken.");
|
||||
else
|
||||
break;
|
||||
}
|
||||
@@ -177,11 +183,11 @@ reprint:
|
||||
mf = ms->file;
|
||||
mc = ms->specs;
|
||||
|
||||
Write(W_BEGIN, ms, 0, 0, 0, 0, 0);
|
||||
Write(W_BEGIN, ms, 0, 0, 0, 0);
|
||||
if (Sync() < 0)
|
||||
leave(LEAVE_SYNC);
|
||||
|
||||
(void) signal(SIGCHLD, child);
|
||||
signal(SIGCHLD, child);
|
||||
if (!hasdriver)
|
||||
switch (fork()) {
|
||||
case 0:
|
||||
@@ -199,25 +205,25 @@ reprint:
|
||||
ms->shipname, mc->guns, classname[mc->class],
|
||||
qualname[mc->qual]);
|
||||
if ((nameptr = (char *) getenv("SAILNAME")) && *nameptr)
|
||||
(void) strncpy(captain, nameptr, sizeof captain);
|
||||
strncpy(captain, nameptr, sizeof captain);
|
||||
else {
|
||||
(void) printf("Your name, Captain? ");
|
||||
(void) fflush(stdout);
|
||||
(void) fgets(captain, sizeof captain, stdin);
|
||||
printf("Your name, Captain? ");
|
||||
fflush(stdout);
|
||||
fgets(captain, sizeof captain, stdin);
|
||||
if (!*captain)
|
||||
(void) strcpy(captain, "no name");
|
||||
strcpy(captain, "no name");
|
||||
else
|
||||
captain[strlen(captain) - 1] = '\0';
|
||||
}
|
||||
captain[sizeof captain - 1] = '\0';
|
||||
Write(W_CAPTAIN, ms, 1, (long)captain, 0, 0, 0);
|
||||
Writestr(W_CAPTAIN, ms, captain);
|
||||
for (n = 0; n < 2; n++) {
|
||||
char buf[10];
|
||||
|
||||
printf("\nInitial broadside %s (grape, chain, round, double): ",
|
||||
n ? "right" : "left");
|
||||
(void) fflush(stdout);
|
||||
(void) scanf("%s", buf);
|
||||
fflush(stdout);
|
||||
scanf("%s", buf);
|
||||
switch (*buf) {
|
||||
case 'g':
|
||||
load = L_GRAPE;
|
||||
@@ -245,7 +251,8 @@ reprint:
|
||||
|
||||
initscreen();
|
||||
draw_board();
|
||||
(void) sprintf(message, "Captain %s assuming command", captain);
|
||||
Write(W_SIGNAL, ms, 1, (long)message, 0, 0, 0);
|
||||
snprintf(message, sizeof message, "Captain %s assuming command",
|
||||
captain);
|
||||
Writestr(W_SIGNAL, ms, message);
|
||||
newturn(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user