- nocrmode();
- echo();
- endwin();
- }
- exit(0);
-}
-
-choke()
-{
- leave(0);
-}
-
-grapungrap()
-{
- register int n, k, l, number, captured;
- int buf;
-
- for (n=0; n < scene[game].vessels ; n++) {
- if (n != player && (range(player, n) <= 1 || grapple(player, n))) {
- if ((captured = scene[game].ship[n].file -> captured) < 0)
- captured = n;
- Signal("Attempt to grapple or ungrapple %s (%c%c): ", n, 0);
- while ((buf = getch()) == EOF);
- addch(buf);
- if (buf == 'g') {
- number = die() < 3;
- if (!number && scene[game].ship[player].nationality == scene[game].ship[captured].nationality)
- number = 1;
- if (number) {
- for (l=0; l < 10 && scene[game].ship[player].file -> grapples[l].turnfoul; l++);
- if (!scene[game].ship[player].file -> grapples[l].turnfoul) {
- Write(FILES + player, 0, 124 + l*4, turn);
- Write(FILES + player, 0, 124 + l*4 + 2, n);
- }
- for (l=0; l < 10 && scene[game].ship[n].file -> grapples[l].turnfoul; l++);
- if (!scene[game].ship[n].file -> grapples[l].turnfoul) {
- Write(FILES + n, 0, 124 + l*4, turn);
- Write(FILES + n, 0, 124 + l*4 + 2, player);
- }
- }
- if (number) {
- Signal("Attempt succeeds!", 0, 0);
- makesignal("grappled with %s (%c%c)", n, player);
- } else
- Signal("Attempt fails.", 0, 0);
- }
- if (buf == 'u') {
- for (k=0; k < 10; k++) {
- if (scene[game].ship[player].file -> grapples[k].turnfoul && n == scene[game].ship[player].file -> grapples[k].toship) {
- if (die() < 3 || scene[game].ship[player].nationality == scene[game].ship[captured].nationality) {
- cleangrapple(player, n, k);
- Signal("Attempt succeeds!", 0, 0);
- makesignal("ungrappling with %s (%c%c)", n, player);
- } else
- Signal("Attempt fails.", 0, 0);
- }
- }
- }
- }
- }
-}
-
-unfoulplayer()
-{
- register int n, toship;
- int buf;
-
- for (n=0; n < 10; n++) {
- if (scene[game].ship[player].file -> fouls[n].turnfoul) {
- Signal("Attempt to unfoul with the %s (%c%c)? ", (toship = scene[game].ship[player].file -> fouls[n].toship), 0);
- while ((buf = getch()) == EOF);
- addch(buf);
- if (buf == 'y' && die() < 3) {
- cleanfoul(player, toship, n);
- Signal("Attempt succeeds!", 0, 0);
- makesignal("unfouling %s (%c%c)", toship, player);
- } else if (buf == 'y')
- Signal("Attempt fails.", 0, 0);
- }
- }
-}
-
-initialize(nodriver, randomize)
-char randomize, nodriver;
-{
- char comm[80], file[25], capn;
- char message[60];
- int load = ROUND, ready = -30000;
- int people = 0;
- int pid;
- register int n;
- register int k;
- char *nameptr;
-
- srand(pid = getpid());
-
- if (game < 0) {
- puts("Choose a scenario:\n");
- puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
- for (n=0; n < NUMOFSCENES; n++) {
- sprintf(file, "/tmp/.%d", n);
- printf("\t%d):\t%d", n, scene[n].vessels);
- if (access(file, 0) >= 0)
- printf("\tYES");
- else
- printf("\tno");
- printf("\t%s\n", scene[n].name);
- }
-reprint:
- printf("\nScenario number? ");
- fflush(stdout);
- scanf("%d", &game);
- while (getchar() != '\n');
- }
- if (game < 0 || game >= NUMOFSCENES) {
- puts("Very funny.");
- exit(1);
- }
- sprintf(file, "/tmp/.%d", game);
- if (access(file, 0) < 0) {
- int omask;
-#ifdef SETUID
- omask = umask(077);
-#else
- omask = umask(011);
-#endif
- syncfile = fopen(file, "w+");
- umask(omask);
- } else {
- syncfile = fopen(file, "r+");
- people = 1;
- }
- lastsync = 0;
- for (n=0; n < scene[game].vessels; n++) {
- nation[scene[game].ship[n].nationality + 1] = n + 1;
- if ((scene[game].ship[n].file = (struct File *) calloc(1, sizeof(struct File))) == NULL) {
- puts("OUT OF MEMORY");
- exit(0);
- }
- scene[game].ship[n].file -> captured = -1;
- }
- if (!nation[2])
- nation[2] = nation[1];
- if (!nation[3])
- nation[3] = nation[2];
- if (people > 0) {
- puts("Synchronizing with the other players...");
- fflush(stdout);
- sync();
- capn = 1;
- for (n=0; n < scene[game].vessels && capn; n++) {
- capn = scene[game].ship[n].file -> captain[0];
- if (scene[game].ship[n].file -> struck || scene[game].ship[n].file -> captured > -1)
- capn = 1;
- }
- if (!capn)
- player = n-1;
- else {
- puts("All ships taken in that scenario.");
- for (n=0; n < scene[game].vessels; n++)
- free(scene[game].ship[n].file);
- people = 0;
- for (n=0; n < 5; n++)
- nation[n] = 0;
- fclose(syncfile);
- goto reprint;
- }
- } else
- player = 0;
- while (randomize) {
- static char *color[] =
- { "(American)", "(British)", "(Spanish)", "(French)" };
- puts(scene[game].name);
- putchar('\n');
- for (n=0; n < scene[game].vessels; n++) {
- printf(" %2d: %-10s %-15s (%-2d pts) ",
- n,
- color[scene[game].ship[n].nationality],
- scene[game].ship[n].shipname,
- specs[scene[game].ship[n].shipnum].pts);
- if(scene[game].ship[n].file -> captain[0])
- puts(scene[game].ship[n].file -> captain);
- else if (scene[game].ship[n].file -> struck)
- puts("(struck)");
- else if(scene[game].ship[n].file -> captured > -1)
- puts("(captured)");
- else
- puts("(available)");
- }
- putchar('\n');
- printf("Which ship do you want (0-%d)? ",scene[game].vessels-1);
- fflush(stdout);
- if (scanf("%d",&player) != 1 || player < 0 || player >= scene[game].vessels) {
- while (getchar() != '\n');
- puts("Say what?");
- } else {
- while (getchar() != '\n');
- sync();
- if (scene[game].ship[player].file -> captain[0] || scene[game].ship[player].file -> struck || scene[game].ship[player].file -> captured > -1)
- puts("Sorry, that ship is taken.");
- else
- break;
- }
- }
-
- signal(SIGHUP, choke);
- signal(SIGINT, choke);
- signal(SIGQUIT, choke);
-
- Write(FILES + player, 1, 0, "begin"); /* he now exists */
- if (people)
- Write(SCENARIO, 0, 8, scene[game].people + 1);
- sync();
- printf("Your ship is the %s, a %s (%s crew).\n", scene[game].ship[player].shipname, info(player, message), quality(player));
- if ((nameptr = (char *) getenv("NAME")) && *nameptr)
- strcpy(comm,nameptr);
- else {
- fputs("Your name, Captain? ", stdout);
- fflush(stdout);
- gets(comm);
- if (!*comm) strcpy(comm, "no name");
- }
- comm[19] = '\0';
- for (k=0; k < 2; k++) {
- printf("\nInitial broadside %s (grape, chain, round, double): ", (k ? "right" : "left"));
- fflush(stdout);
- scanf("%s", file);
- switch(*file) {
- case 'g':
- load = GRAPE;
- break;
- case 'c':
- load = CHAIN;