]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_main.c
1 /* $NetBSD: pl_main.c,v 1.6 1997/10/13 19:45:48 christos 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
39 static char sccsid
[] = "@(#)pl_main.c 8.1 (Berkeley) 5/31/93";
41 __RCSID("$NetBSD: pl_main.c,v 1.6 1997/10/13 19:45:48 christos Exp $");
46 #include <sys/types.h>
57 printf("Can't sail on this terminal.\n");
63 return 0; /* for lint, play() never returns */
69 register struct File
*fp
;
70 register struct ship
*sp
;
79 (void) puts("Choose a scenario:\n");
80 (void) puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
81 for (n
= 0; n
< NSCENE
; n
++) {
83 printf("\t%d):\t%d\t%s\t%s\n", n
, scene
[n
].vessels
,
84 sync_exists(n
) ? "YES" : "no",
88 printf("\nScenario number? ");
89 (void) fflush(stdout
);
90 (void) scanf("%d", &game
);
91 while (getchar() != '\n')
94 if (game
< 0 || game
>= NSCENE
) {
95 (void) puts("Very funny.");
99 ls
= SHIP(cc
->vessels
);
101 for (n
= 0; n
< NNATION
; n
++)
104 if (sp
->file
== NULL
&&
105 (sp
->file
= (struct File
*)calloc(1, sizeof (struct File
))) == NULL
) {
106 (void) puts("OUT OF MEMORY");
109 sp
->file
->index
= sp
- SHIP(0);
110 sp
->file
->stern
= nat
[sp
->nationality
]++;
111 sp
->file
->dir
= sp
->shipdir
;
112 sp
->file
->row
= sp
->shiprow
;
113 sp
->file
->col
= sp
->shipcol
;
115 windspeed
= cc
->windspeed
;
116 winddir
= cc
->winddir
;
118 (void) signal(SIGHUP
, choke
);
119 (void) signal(SIGINT
, choke
);
121 hasdriver
= sync_exists(game
);
122 if (sync_open() < 0) {
123 perror("sail: syncfile");
128 (void) puts("Synchronizing with the other players...");
129 (void) fflush(stdout
);
135 if (sp
->file
->captain
[0] == 0 && !sp
->file
->struck
136 && sp
->file
->captured
== 0)
139 (void) puts("All ships taken in that scenario.");
141 free((char *)sp
->file
);
147 player
= sp
- SHIP(0);
149 printf("%s\n\n", cc
->name
);
151 printf(" %2d: %-10s %-15s (%-2d pts) %s\n",
153 countryname
[sp
->nationality
],
157 printf("\nWhich ship (0-%d)? ", cc
->vessels
-1);
158 (void) fflush(stdout
);
159 if (scanf("%d", &player
) != 1 || player
< 0
160 || player
>= cc
->vessels
) {
161 while (getchar() != '\n')
163 (void) puts("Say what?");
166 while (getchar() != '\n')
173 fp
= SHIP(player
)->file
;
174 if (fp
->captain
[0] || fp
->struck
|| fp
->captured
!= 0)
175 (void) puts("That ship is taken.");
184 Write(W_BEGIN
, ms
, 0, 0, 0, 0, 0);
188 (void) 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
= (char *) getenv("SAILNAME")) && *nameptr
)
206 (void) strncpy(captain
, nameptr
, sizeof captain
);
208 (void) printf("Your name, Captain? ");
209 (void) fflush(stdout
);
210 (void) fgets(captain
, sizeof captain
, stdin
);
212 (void) strcpy(captain
, "no name");
214 captain
[strlen(captain
) - 1] = '\0';
216 captain
[sizeof captain
- 1] = '\0';
217 Write(W_CAPTAIN
, ms
, 1, (long)captain
, 0, 0, 0);
218 for (n
= 0; n
< 2; n
++) {
221 printf("\nInitial broadside %s (grape, chain, round, double): ",
222 n
? "right" : "left");
223 (void) fflush(stdout
);
224 (void) scanf("%s", buf
);
243 mf
->readyR
= R_LOADED
|R_INITIAL
;
246 mf
->readyL
= R_LOADED
|R_INITIAL
;
252 (void) sprintf(message
, "Captain %s assuming command", captain
);
253 Write(W_SIGNAL
, ms
, 1, (long)message
, 0, 0, 0);