1 /* $NetBSD: pl_main.c,v 1.25 2009/03/14 22:52:53 dholland Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)pl_main.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: pl_main.c,v 1.25 2009/03/14 22:52:53 dholland Exp $");
53 static void initialize(void);
62 return 0; /* for lint, play() never returns */
78 puts("Choose a scenario:\n");
79 puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
80 for (n
= 0; n
< NSCENE
; n
++) {
82 printf("\t%d):\t%d\t%s\t%s\n", n
, scene
[n
].vessels
,
83 sync_exists(n
) ? "YES" : "no",
87 printf("\nScenario number? ");
90 while (getchar() != '\n' && !feof(stdin
))
93 if (game
< 0 || game
>= NSCENE
) {
94 errx(1, "Very funny.");
97 ls
= SHIP(cc
->vessels
);
99 for (n
= 0; n
< NNATION
; n
++)
102 if (sp
->file
== NULL
&&
103 (sp
->file
= calloc(1, sizeof (struct File
))) == NULL
) {
106 sp
->file
->index
= sp
- SHIP(0);
107 sp
->file
->stern
= nat
[sp
->nationality
]++;
108 sp
->file
->dir
= sp
->shipdir
;
109 sp
->file
->row
= sp
->shiprow
;
110 sp
->file
->col
= sp
->shipcol
;
112 windspeed
= cc
->windspeed
;
113 winddir
= cc
->winddir
;
115 signal(SIGHUP
, choke
);
116 signal(SIGINT
, choke
);
118 hasdriver
= sync_exists(game
);
119 if (sync_open() < 0) {
124 puts("Synchronizing with the other players...");
131 if (sp
->file
->captain
[0] == 0 && !sp
->file
->struck
132 && sp
->file
->captured
== 0)
135 puts("All ships taken in that scenario.");
143 player
= sp
- SHIP(0);
145 printf("%s\n\n", cc
->name
);
147 printf(" %2d: %-10s %-15s (%-2d pts) %s\n",
149 countryname
[sp
->nationality
],
153 printf("\nWhich ship (0-%d)? ", cc
->vessels
-1);
155 if (scanf("%d", &player
) != 1 || player
< 0
156 || player
>= cc
->vessels
) {
157 while (getchar() != '\n' && !feof(stdin
))
162 while (getchar() != '\n' && !feof(stdin
))
165 printf("\nExiting...\n");
173 fp
= SHIP(player
)->file
;
174 if (fp
->captain
[0] || fp
->struck
|| fp
->captured
!= 0)
175 puts("That ship is taken.");
188 signal(SIGCHLD
, child
);
192 longjmp(restart
, MODE_DRIVER
);
202 printf("Your ship is the %s, a %d gun %s (%s crew).\n",
203 ms
->shipname
, mc
->guns
, classname
[mc
->class],
205 if ((nameptr
= getenv("SAILNAME")) && *nameptr
)
206 strlcpy(captain
, nameptr
, sizeof captain
);
208 printf("Your name, Captain? ");
210 if (fgets(captain
, sizeof captain
, stdin
) == NULL
)
211 strcpy(captain
, "no name");
212 else if (*captain
== '\0' || *captain
== '\n')
213 strcpy(captain
, "no name");
215 captain
[strlen(captain
) - 1] = '\0';
217 send_captain(ms
, captain
);
218 for (n
= 0; n
< 2; n
++) {
221 printf("\nInitial broadside %s (grape, chain, round, double): ",
222 n
? "right" : "left");
224 fgets(buf
, sizeof(buf
), stdin
);
243 mf
->readyR
= R_LOADED
|R_INITIAL
;
246 mf
->readyL
= R_LOADED
|R_INITIAL
;
254 snprintf(message
, sizeof message
, "Captain %s assuming command",
256 send_signal(ms
, message
);