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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)pl_main.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/sail/pl_main.c,v 1.6 1999/11/30 03:49:38 billf Exp $
35 * $DragonFly: src/games/sail/pl_main.c,v 1.4 2006/09/03 17:33:13 pavalos Exp $
39 #include <sys/types.h>
42 static void initialize(void);
50 printf("Can't sail on this terminal.\n");
54 Signal("Aye aye, Sir", NULL
);
56 return 0; /* for lint, play() never returns */
72 puts("Choose a scenario:\n");
73 puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
74 for (n
= 0; n
< NSCENE
; n
++) {
76 printf("\t%d):\t%d\t%s\t%s\n", n
, scene
[n
].vessels
,
77 sync_exists(n
) ? "YES" : "no",
81 printf("\nScenario number? ");
84 while (getchar() != '\n')
87 if (game
< 0 || game
>= NSCENE
) {
92 ls
= SHIP(cc
->vessels
);
94 for (n
= 0; n
< NNATION
; n
++)
97 if (sp
->file
== NULL
&&
98 (sp
->file
= (struct File
*)calloc(1, sizeof (struct File
))) == NULL
) {
99 puts("OUT OF MEMORY");
102 sp
->file
->index
= sp
- SHIP(0);
103 sp
->file
->stern
= nat
[sp
->nationality
]++;
104 sp
->file
->dir
= sp
->shipdir
;
105 sp
->file
->row
= sp
->shiprow
;
106 sp
->file
->col
= sp
->shipcol
;
108 windspeed
= cc
->windspeed
;
109 winddir
= cc
->winddir
;
111 signal(SIGHUP
, (sig_t
)choke
);
112 signal(SIGINT
, (sig_t
)choke
);
114 hasdriver
= sync_exists(game
);
115 if (sync_open() < 0) {
116 perror("sail: syncfile");
121 puts("Synchronizing with the other players...");
128 if (sp
->file
->captain
[0] == 0 && !sp
->file
->struck
129 && sp
->file
->captured
== 0)
132 puts("All ships taken in that scenario.");
134 free((char *)sp
->file
);
140 player
= sp
- SHIP(0);
142 printf("%s\n\n", cc
->name
);
144 printf(" %2d: %-10s %-15s (%-2d pts) %s\n",
146 countryname
[sp
->nationality
],
150 printf("\nWhich ship (0-%d)? ", cc
->vessels
-1);
152 if (scanf("%d", &player
) != 1 || player
< 0
153 || player
>= cc
->vessels
) {
154 while (getchar() != '\n')
159 while (getchar() != '\n')
166 fp
= SHIP(player
)->file
;
167 if (fp
->captain
[0] || fp
->struck
|| fp
->captured
!= 0)
168 puts("That ship is taken.");
177 Write(W_BEGIN
, ms
, 0, 0, 0, 0);
181 signal(SIGCHLD
, (sig_t
)child
);
185 longjmp(restart
, MODE_DRIVER
);
195 printf("Your ship is the %s, a %d gun %s (%s crew).\n",
196 ms
->shipname
, mc
->guns
, classname
[mc
->class],
198 if ((nameptr
= (char *) getenv("SAILNAME")) && *nameptr
)
199 strncpy(captain
, nameptr
, sizeof captain
);
201 printf("Your name, Captain? ");
203 fgets(captain
, sizeof captain
, stdin
);
205 strcpy(captain
, "no name");
207 captain
[sizeof(captain
) - 1] = '\0';
209 Writestr(W_CAPTAIN
, ms
, captain
);
210 for (n
= 0; n
< 2; n
++) {
213 printf("\nInitial broadside %s (grape, chain, round, double): ",
214 n
? "right" : "left");
235 mf
->readyR
= R_LOADED
|R_INITIAL
;
238 mf
->readyL
= R_LOADED
|R_INITIAL
;
244 snprintf(message
, sizeof message
, "Captain %s assuming command",
246 Writestr(W_SIGNAL
, ms
, message
);