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.2 2003/06/17 04:25:25 dillon Exp $
39 #include <sys/types.h>
42 void choke(), child();
49 printf("Can't sail on this terminal.\n");
53 Signal("Aye aye, Sir", (struct ship
*)0);
55 return 0; /* for lint, play() never returns */
60 register struct File
*fp
;
61 register struct ship
*sp
;
70 (void) puts("Choose a scenario:\n");
71 (void) puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
72 for (n
= 0; n
< NSCENE
; n
++) {
74 printf("\t%d):\t%d\t%s\t%s\n", n
, scene
[n
].vessels
,
75 sync_exists(n
) ? "YES" : "no",
79 printf("\nScenario number? ");
80 (void) fflush(stdout
);
81 (void) scanf("%d", &game
);
82 while (getchar() != '\n')
85 if (game
< 0 || game
>= NSCENE
) {
86 (void) puts("Very funny.");
90 ls
= SHIP(cc
->vessels
);
92 for (n
= 0; n
< NNATION
; n
++)
95 if (sp
->file
== NULL
&&
96 (sp
->file
= (struct File
*)calloc(1, sizeof (struct File
))) == NULL
) {
97 (void) puts("OUT OF MEMORY");
100 sp
->file
->index
= sp
- SHIP(0);
101 sp
->file
->stern
= nat
[sp
->nationality
]++;
102 sp
->file
->dir
= sp
->shipdir
;
103 sp
->file
->row
= sp
->shiprow
;
104 sp
->file
->col
= sp
->shipcol
;
106 windspeed
= cc
->windspeed
;
107 winddir
= cc
->winddir
;
109 (void) signal(SIGHUP
, choke
);
110 (void) signal(SIGINT
, choke
);
112 hasdriver
= sync_exists(game
);
113 if (sync_open() < 0) {
114 perror("sail: syncfile");
119 (void) puts("Synchronizing with the other players...");
120 (void) fflush(stdout
);
126 if (sp
->file
->captain
[0] == 0 && !sp
->file
->struck
127 && sp
->file
->captured
== 0)
130 (void) puts("All ships taken in that scenario.");
132 free((char *)sp
->file
);
138 player
= sp
- SHIP(0);
140 printf("%s\n\n", cc
->name
);
142 printf(" %2d: %-10s %-15s (%-2d pts) %s\n",
144 countryname
[sp
->nationality
],
148 printf("\nWhich ship (0-%d)? ", cc
->vessels
-1);
149 (void) fflush(stdout
);
150 if (scanf("%d", &player
) != 1 || player
< 0
151 || player
>= cc
->vessels
) {
152 while (getchar() != '\n')
154 (void) puts("Say what?");
157 while (getchar() != '\n')
164 fp
= SHIP(player
)->file
;
165 if (fp
->captain
[0] || fp
->struck
|| fp
->captured
!= 0)
166 (void) puts("That ship is taken.");
175 Write(W_BEGIN
, ms
, 0, 0, 0, 0, 0);
179 (void) signal(SIGCHLD
, child
);
183 longjmp(restart
, MODE_DRIVER
);
193 printf("Your ship is the %s, a %d gun %s (%s crew).\n",
194 ms
->shipname
, mc
->guns
, classname
[mc
->class],
196 if ((nameptr
= (char *) getenv("SAILNAME")) && *nameptr
)
197 (void) strncpy(captain
, nameptr
, sizeof captain
);
199 (void) printf("Your name, Captain? ");
200 (void) fflush(stdout
);
201 (void) fgets(captain
, sizeof captain
, stdin
);
203 (void) strcpy(captain
, "no name");
205 captain
[sizeof(captain
) - 1] = '\0';
207 Write(W_CAPTAIN
, ms
, 1, (long)captain
, 0, 0, 0);
208 for (n
= 0; n
< 2; n
++) {
211 printf("\nInitial broadside %s (grape, chain, round, double): ",
212 n
? "right" : "left");
213 (void) fflush(stdout
);
214 (void) scanf("%9s", buf
);
233 mf
->readyR
= R_LOADED
|R_INITIAL
;
236 mf
->readyL
= R_LOADED
|R_INITIAL
;
242 (void) sprintf(message
, "Captain %s assuming command", captain
);
243 Write(W_SIGNAL
, ms
, 1, (long)message
, 0, 0, 0);