- }
- if (*argv)
- game = atoi(*argv);
- else
- game = -1;
- initialize(nodrive, randomize, debug);
- Signal("Aye aye, Sir", (struct ship *)0);
- play();
-}
-
-initialize(nodriver, randomize, debug)
-char randomize, nodriver, debug;
-{
- register struct File *fp;
- register struct ship *sp;
- char captain[80];
- char message[60];
- int load;
- int active;
- register int n;
- char *nameptr;
- int nat[NNATION];
-
- (void) srand(getpid());
-
- if (game < 0) {
- (void) puts("Choose a scenario:\n");
- (void) puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
- for (n = 0; n < NSCENE; n++) {
- /* ( */
- printf("\t%d):\t%d\t%s\t%s\n", n, scene[n].vessels,
- sync_exists(n) ? "YES" : "no",
- scene[n].name);
- }
-reprint:
- printf("\nScenario number? ");
- (void) fflush(stdout);
- (void) scanf("%d", &game);
- while (getchar() != '\n')
- ;
- }
- if (game < 0 || game >= NSCENE) {
- (void) puts("Very funny.");
- exit(1);
- }
- cc = &scene[game];
- ls = cc->ship + cc->vessels;
-
- (void) signal(SIGHUP, choke);
- (void) signal(SIGINT, choke);
- (void) signal(SIGQUIT, choke);
-
- active = sync_exists(game);
- if (sync_open() < 0) {
- perror("sail: syncfile");
- exit(1);
- }
-
- for (n = 0; n < NNATION; n++)
- nat[n] = 0;
- foreachship(sp) {
- sp->file = (struct File *) calloc(1, sizeof (struct File));
- if (sp->file == NULL) {
- (void) puts("OUT OF MEMORY");
- exit(0);
- }
- sp->file->stern = nat[sp->nationality]++;
- sp->file->dir = sp->shipdir;
- sp->file->row = sp->shiprow;
- sp->file->col = sp->shipcol;
- }
- windspeed = cc->windspeed;
- winddir = cc->winddir;
-
- if (active) {
- (void) puts("Synchronizing with the other players...");
- (void) fflush(stdout);
- Sync();
- }
- for (;;) {
- foreachship(sp)
- if (sp->file->captain[0] == 0 && !sp->file->struck
- && sp->file->captured == 0)
- break;
- if (sp >= ls) {
- (void) puts("All ships taken in that scenario.");
- foreachship(sp)
- free((char *)sp->file);
- sync_close(0);
- people = 0;
- goto reprint;
- }
- if (randomize) {
- player = sp - cc->ship;
- } else {
- printf("%s\n\n", cc->name);
- foreachship(sp)
- printf(" %2d: %-10s %-15s (%-2d pts) %s\n",
- sp - SHIP(0),
- countryname[sp->nationality],
- sp->shipname,
- sp->specs->pts,
- saywhat(sp, 1));
- printf("\nWhich ship (0-%d)? ", cc->vessels-1);
- (void) fflush(stdout);
- if (scanf("%d", &player) != 1 || player < 0
- || player >= cc->vessels) {
- while (getchar() != '\n')
- ;
- (void) puts("Say what?");
- player = -1;
- } else
- while (getchar() != '\n')
- ;
- }
- if (player < 0)
- continue;
- Sync();
- fp = SHIP(player)->file;
- if (fp->captain[0] || fp->struck || fp->captured != 0)
- (void) puts("That ship is taken.");
- else