]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_main.c
2 * Copyright (c) 1983 Regents of the University of California.
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
35 /*static char sccsid[] = "from: @(#)pl_main.c 5.5 (Berkeley) 2/28/91";*/
36 static char rcsid
[] = "$Id: pl_main.c,v 1.3 1994/01/13 19:22:29 glass Exp $";
40 #include <sys/types.h>
43 void choke(), child();
50 printf("Can't sail on this terminal.\n");
54 Signal("Aye aye, Sir", (struct ship
*)0);
56 return 0; /* for lint, play() never returns */
61 register struct File
*fp
;
62 register struct ship
*sp
;
71 (void) puts("Choose a scenario:\n");
72 (void) puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
73 for (n
= 0; n
< NSCENE
; n
++) {
75 printf("\t%d):\t%d\t%s\t%s\n", n
, scene
[n
].vessels
,
76 sync_exists(n
) ? "YES" : "no",
80 printf("\nScenario number? ");
81 (void) fflush(stdout
);
82 (void) scanf("%d", &game
);
83 while (getchar() != '\n')
86 if (game
< 0 || game
>= NSCENE
) {
87 (void) puts("Very funny.");
91 ls
= SHIP(cc
->vessels
);
93 for (n
= 0; n
< NNATION
; n
++)
96 if (sp
->file
== NULL
&&
97 (sp
->file
= (struct File
*)calloc(1, sizeof (struct File
))) == NULL
) {
98 (void) puts("OUT OF MEMORY");
101 sp
->file
->index
= sp
- SHIP(0);
102 sp
->file
->stern
= nat
[sp
->nationality
]++;
103 sp
->file
->dir
= sp
->shipdir
;
104 sp
->file
->row
= sp
->shiprow
;
105 sp
->file
->col
= sp
->shipcol
;
107 windspeed
= cc
->windspeed
;
108 winddir
= cc
->winddir
;
110 (void) signal(SIGHUP
, choke
);
111 (void) signal(SIGINT
, choke
);
113 hasdriver
= sync_exists(game
);
114 if (sync_open() < 0) {
115 perror("sail: syncfile");
120 (void) puts("Synchronizing with the other players...");
121 (void) fflush(stdout
);
127 if (sp
->file
->captain
[0] == 0 && !sp
->file
->struck
128 && sp
->file
->captured
== 0)
131 (void) puts("All ships taken in that scenario.");
133 free((char *)sp
->file
);
139 player
= sp
- SHIP(0);
141 printf("%s\n\n", cc
->name
);
143 printf(" %2d: %-10s %-15s (%-2d pts) %s\n",
145 countryname
[sp
->nationality
],
149 printf("\nWhich ship (0-%d)? ", cc
->vessels
-1);
150 (void) fflush(stdout
);
151 if (scanf("%d", &player
) != 1 || player
< 0
152 || player
>= cc
->vessels
) {
153 while (getchar() != '\n')
155 (void) puts("Say what?");
158 while (getchar() != '\n')
165 fp
= SHIP(player
)->file
;
166 if (fp
->captain
[0] || fp
->struck
|| fp
->captured
!= 0)
167 (void) puts("That ship is taken.");
176 Write(W_BEGIN
, ms
, 0, 0, 0, 0, 0);
180 (void) signal(SIGCHLD
, child
);
184 longjmp(restart
, MODE_DRIVER
);
194 printf("Your ship is the %s, a %d gun %s (%s crew).\n",
195 ms
->shipname
, mc
->guns
, classname
[mc
->class],
197 if ((nameptr
= (char *) getenv("SAILNAME")) && *nameptr
)
198 (void) strncpy(captain
, nameptr
, sizeof captain
);
200 (void) printf("Your name, Captain? ");
201 (void) fflush(stdout
);
202 (void) fgets(captain
, sizeof captain
, stdin
);
204 (void) strcpy(captain
, "no name");
206 captain
[strlen(captain
) - 1] = '\0';
208 captain
[sizeof captain
- 1] = '\0';
209 Write(W_CAPTAIN
, ms
, 1, (int)captain
, 0, 0, 0);
210 for (n
= 0; n
< 2; n
++) {
213 printf("\nInitial broadside %s (grape, chain, round, double): ",
214 n
? "right" : "left");
215 (void) fflush(stdout
);
216 (void) scanf("%s", buf
);
235 mf
->readyR
= R_LOADED
|R_INITIAL
;
238 mf
->readyL
= R_LOADED
|R_INITIAL
;
244 (void) sprintf(message
, "Captain %s assuming command", captain
);
245 Write(W_SIGNAL
, ms
, 1, (int)message
, 0, 0, 0);