2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)pl_main.c 8.1 (Berkeley) 5/31/93
30 * $FreeBSD: src/games/sail/pl_main.c,v 1.6 1999/11/30 03:49:38 billf Exp $
33 #include <sys/types.h>
37 static void initialize(void);
45 printf("Can't sail on this terminal.\n");
49 Signal("Aye aye, Sir", NULL
);
66 puts("Choose a scenario:\n");
67 puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
68 for (n
= 0; n
< NSCENE
; n
++) {
70 printf("\t%d):\t%d\t%s\t%s\n", n
, scene
[n
].vessels
,
71 sync_exists(n
) ? "YES" : "no",
75 printf("\nScenario number? ");
78 while (getchar() != '\n' && !feof(stdin
))
81 if (game
< 0 || game
>= NSCENE
) {
86 ls
= SHIP(cc
->vessels
);
88 for (n
= 0; n
< NNATION
; n
++)
91 if (sp
->file
== NULL
&&
92 (sp
->file
= calloc(1, sizeof (struct File
))) == NULL
) {
93 puts("OUT OF MEMORY");
96 sp
->file
->index
= sp
- SHIP(0);
97 sp
->file
->stern
= nat
[sp
->nationality
]++;
98 sp
->file
->dir
= sp
->shipdir
;
99 sp
->file
->row
= sp
->shiprow
;
100 sp
->file
->col
= sp
->shipcol
;
102 windspeed
= cc
->windspeed
;
103 winddir
= cc
->winddir
;
105 signal(SIGHUP
, choke
);
106 signal(SIGINT
, choke
);
108 hasdriver
= sync_exists(game
);
109 if (sync_open() < 0) {
110 perror("sail: syncfile");
115 puts("Synchronizing with the other players...");
122 if (sp
->file
->captain
[0] == 0 && !sp
->file
->struck
123 && sp
->file
->captured
== 0)
126 puts("All ships taken in that scenario.");
134 player
= sp
- SHIP(0);
136 printf("%s\n\n", cc
->name
);
138 printf(" %2d: %-10s %-15s (%-2d pts) %s\n",
140 countryname
[sp
->nationality
],
144 printf("\nWhich ship (0-%d)? ", cc
->vessels
-1);
146 if (scanf("%d", &player
) != 1 || player
< 0
147 || player
>= cc
->vessels
) {
148 while (getchar() != '\n')
153 while (getchar() != '\n')
160 fp
= SHIP(player
)->file
;
161 if (fp
->captain
[0] || fp
->struck
|| fp
->captured
!= 0)
162 puts("That ship is taken.");
171 Write(W_BEGIN
, ms
, 0, 0, 0, 0);
175 signal(SIGCHLD
, child
);
179 longjmp(restart
, MODE_DRIVER
);
189 printf("Your ship is the %s, a %d gun %s (%s crew).\n",
190 ms
->shipname
, mc
->guns
, classname
[mc
->class],
192 if ((nameptr
= getenv("SAILNAME")) && *nameptr
)
193 strncpy(captain
, nameptr
, sizeof captain
);
195 printf("Your name, Captain? ");
197 fgets(captain
, sizeof captain
, stdin
);
199 strcpy(captain
, "no name");
201 captain
[sizeof(captain
) - 1] = '\0';
203 Writestr(W_CAPTAIN
, ms
, captain
);
204 for (n
= 0; n
< 2; n
++) {
207 printf("\nInitial broadside %s (grape, chain, round, double): ",
208 n
? "right" : "left");
229 mf
->readyR
= R_LOADED
|R_INITIAL
;
232 mf
->readyL
= R_LOADED
|R_INITIAL
;
238 snprintf(message
, sizeof message
, "Captain %s assuming command",
240 Writestr(W_SIGNAL
, ms
, message
);