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
);
51 return 0; /* for lint, play() never returns */
67 puts("Choose a scenario:\n");
68 puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
69 for (n
= 0; n
< NSCENE
; n
++) {
71 printf("\t%d):\t%d\t%s\t%s\n", n
, scene
[n
].vessels
,
72 sync_exists(n
) ? "YES" : "no",
76 printf("\nScenario number? ");
79 while (getchar() != '\n')
82 if (game
< 0 || game
>= NSCENE
) {
87 ls
= SHIP(cc
->vessels
);
89 for (n
= 0; n
< NNATION
; n
++)
92 if (sp
->file
== NULL
&&
93 (sp
->file
= calloc(1, sizeof (struct File
))) == NULL
) {
94 puts("OUT OF MEMORY");
97 sp
->file
->index
= sp
- SHIP(0);
98 sp
->file
->stern
= nat
[sp
->nationality
]++;
99 sp
->file
->dir
= sp
->shipdir
;
100 sp
->file
->row
= sp
->shiprow
;
101 sp
->file
->col
= sp
->shipcol
;
103 windspeed
= cc
->windspeed
;
104 winddir
= cc
->winddir
;
106 signal(SIGHUP
, choke
);
107 signal(SIGINT
, choke
);
109 hasdriver
= sync_exists(game
);
110 if (sync_open() < 0) {
111 perror("sail: syncfile");
116 puts("Synchronizing with the other players...");
123 if (sp
->file
->captain
[0] == 0 && !sp
->file
->struck
124 && sp
->file
->captured
== 0)
127 puts("All ships taken in that scenario.");
135 player
= sp
- SHIP(0);
137 printf("%s\n\n", cc
->name
);
139 printf(" %2d: %-10s %-15s (%-2d pts) %s\n",
141 countryname
[sp
->nationality
],
145 printf("\nWhich ship (0-%d)? ", cc
->vessels
-1);
147 if (scanf("%d", &player
) != 1 || player
< 0
148 || player
>= cc
->vessels
) {
149 while (getchar() != '\n')
154 while (getchar() != '\n')
161 fp
= SHIP(player
)->file
;
162 if (fp
->captain
[0] || fp
->struck
|| fp
->captured
!= 0)
163 puts("That ship is taken.");
172 Write(W_BEGIN
, ms
, 0, 0, 0, 0);
176 signal(SIGCHLD
, child
);
180 longjmp(restart
, MODE_DRIVER
);
190 printf("Your ship is the %s, a %d gun %s (%s crew).\n",
191 ms
->shipname
, mc
->guns
, classname
[mc
->class],
193 if ((nameptr
= getenv("SAILNAME")) && *nameptr
)
194 strncpy(captain
, nameptr
, sizeof captain
);
196 printf("Your name, Captain? ");
198 fgets(captain
, sizeof captain
, stdin
);
200 strcpy(captain
, "no name");
202 captain
[sizeof(captain
) - 1] = '\0';
204 Writestr(W_CAPTAIN
, ms
, captain
);
205 for (n
= 0; n
< 2; n
++) {
208 printf("\nInitial broadside %s (grape, chain, round, double): ",
209 n
? "right" : "left");
230 mf
->readyR
= R_LOADED
|R_INITIAL
;
233 mf
->readyL
= R_LOADED
|R_INITIAL
;
239 snprintf(message
, sizeof message
, "Captain %s assuming command",
241 Writestr(W_SIGNAL
, ms
, message
);