]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_main.c
1eb08f345f0481cbef332d374b8a2f1bb0c24b5b
1 /* $NetBSD: pl_main.c,v 1.9 2001/01/01 22:23:29 jwise 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.9 2001/01/01 22:23:29 jwise Exp $");
46 #include <sys/types.h>
59 return 0; /* for lint, play() never returns */
65 register struct File
*fp
;
66 register struct ship
*sp
;
75 puts("Choose a scenario:\n");
76 puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
77 for (n
= 0; n
< NSCENE
; n
++) {
79 printf("\t%d):\t%d\t%s\t%s\n", n
, scene
[n
].vessels
,
80 sync_exists(n
) ? "YES" : "no",
84 printf("\nScenario number? ");
87 while (getchar() != '\n')
90 if (game
< 0 || game
>= NSCENE
) {
95 ls
= SHIP(cc
->vessels
);
97 for (n
= 0; n
< NNATION
; n
++)
100 if (sp
->file
== NULL
&&
101 (sp
->file
= (struct File
*)calloc(1, sizeof (struct File
))) == NULL
) {
102 puts("OUT OF MEMORY");
105 sp
->file
->index
= sp
- SHIP(0);
106 sp
->file
->stern
= nat
[sp
->nationality
]++;
107 sp
->file
->dir
= sp
->shipdir
;
108 sp
->file
->row
= sp
->shiprow
;
109 sp
->file
->col
= sp
->shipcol
;
111 windspeed
= cc
->windspeed
;
112 winddir
= cc
->winddir
;
114 signal(SIGHUP
, choke
);
115 signal(SIGINT
, choke
);
117 hasdriver
= sync_exists(game
);
118 if (sync_open() < 0) {
119 perror("sail: syncfile");
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.");
137 free((char *)sp
->file
);
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')
162 while (getchar() != '\n')
169 fp
= SHIP(player
)->file
;
170 if (fp
->captain
[0] || fp
->struck
|| fp
->captured
!= 0)
171 puts("That ship is taken.");
180 Write(W_BEGIN
, ms
, 0, 0, 0, 0);
184 signal(SIGCHLD
, child
);
188 longjmp(restart
, MODE_DRIVER
);
198 printf("Your ship is the %s, a %d gun %s (%s crew).\n",
199 ms
->shipname
, mc
->guns
, classname
[mc
->class],
201 if ((nameptr
= (char *) getenv("SAILNAME")) && *nameptr
)
202 strncpy(captain
, nameptr
, sizeof captain
);
204 printf("Your name, Captain? ");
206 fgets(captain
, sizeof captain
, stdin
);
208 strcpy(captain
, "no name");
210 captain
[strlen(captain
) - 1] = '\0';
212 captain
[sizeof captain
- 1] = '\0';
213 Writestr(W_CAPTAIN
, ms
, captain
);
214 for (n
= 0; n
< 2; n
++) {
217 printf("\nInitial broadside %s (grape, chain, round, double): ",
218 n
? "right" : "left");
239 mf
->readyR
= R_LOADED
|R_INITIAL
;
242 mf
->readyL
= R_LOADED
|R_INITIAL
;
248 snprintf(message
, sizeof message
, "Captain %s assuming command",
250 Writestr(W_SIGNAL
, ms
, message
);