- char comm[80], num[5], file[25], capn;
- char message[60];
- int load = ROUND, ready = -30000;
- int people = 0;
- int pid, omask;
- register int n;
- register int k;
- struct stat Stat;
- char *nameptr;
-
- srand(pid = getpid());
- initscr();
- view = newwin(ROWSINVIEW, COLSINVIEW, 2, 1);
- slot = newwin(ROWSINVIEW, 3, 2, 1+COLSINVIEW);
-
- 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 (stat(file, &Stat) >= 0)
- printf("\tYES");
- else
- printf("\tno");
- printf("\t%s\n", scene[n].name);
- }
-reprint:
- printf("\nScenario number? ");
- scanf("%d", &game);
- while (getchar() != '\n');
- }
- if (game < 0 || game >= NUMOFSCENES) {
- puts("Very funny.");
- endwin();
- exit(1);
- }
- sprintf(file, "/tmp/.%d", game);
- if (stat(file, &Stat) < 0 ) {
-#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");
- endwin();
- 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;
- 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);
- 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(2, choke);
- signal(1, choke);
- Write(FILES + player, 1, 0, "begin"); /* he now exits */
- 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);
- 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"));
- scanf("%s", file);
- switch(*file) {
- case 'g':
- load = GRAPE;
- break;
- case 'c':
- load = CHAIN;
- break;
- case 'r':
- load = ROUND;
- break;
- case 'd':
- load = DOUBLE;
- break;
- }
- if (k) {
- scene[game].ship[player].file -> loadR = load;
- scene[game].ship[player].file -> readyR = ready;
- } else {
- scene[game].ship[player].file -> loadL = load;
- scene[game].ship[player].file -> readyL = ready;
- }
- }
- Write(FILES + player, 1, 0, comm);
- if (!people && !nodriver) {
- sprintf(num, "%d", game);
- if (!fork()) {
- execl(DRIVER, DRIVERNAME, num, 0);
- perror(DRIVER);
- kill(pid,9);
- exit(1);
- }
- }
- board();
- sprintf(message, "Captain %s assuming command",comm);
- Write(FILES + player, 1, 164, message);
- windspeed = scene[game].windspeed;
- winddir = scene[game].winddir;
- turn = scene[game].turn;
- iplotships(); /* new turn */
-}
-
-/*
- * Returns the NUMBER of the closest ship
- */
-closestenemy(fromship, side, anyship)
-int fromship;
-char side, anyship;
-{
- register int n, olddist = 30000, ident, captured;
- register int dist, eclosest = 30000;
-
- if ((ident = scene[game].ship[fromship].file -> captured) < 0)
- ident = fromship;
- for (n=0; n < scene[game].vessels; n++) {
- if ((captured = scene[game].ship[n].file -> captured) < 0)
- captured = n;
- if (n != fromship && pos[n].dir && (scene[game].ship[ident].nationality != scene[game].ship[captured].nationality || anyship)) {
- if (!side || gunsbear(fromship, n) == side) {
- dist = range(fromship, n);
- if (dist < olddist){
- eclosest = n;
- olddist = dist;
- }
- }
- }
- }
- if (!side && olddist == 30000)
- leave(2);
- return(eclosest);
-}
-
-finalexit()
-{
- endwin();
- nocrmode();
- echo();
- exit(1);
-}
-
-main(argc, argv)
-int argc;
-char ** argv;
-{
- register int crew, aheadfirst, ta, ma, n;
- char message[60], ch;
- int uid;
- char nodrive = 0, randomize = 0, *badstring();
-
- signal(SIGINT, finalexit);
- signal(SIGQUIT, finalexit);
- signal(SIGHUP, finalexit);
-
- if (timetoplay() != 0 && gooduid(uid) != 0)
- {
- printf("Sorry Captain, but since you are not an Admiral and this is\n");
- printf("a weekday between %s, you are not permitted to\n",badstring());
- printf("sail. Come back again some time when the harbor is open.\n");
- exit(1);
- }
-
- while (*++argv && **argv == '-')
- switch (*++*argv)
- {
- case 'd':
- nodrive = 1;
- break;
- case 'x':
- randomize = 1;
- break;
- default:
- printf("Unknown flag '%s'\n",*argv);
- break;
- }
- if (*argv)
- game = atoi(*argv);
- else
- game = -1;
- initialize(nodrive, randomize);
- noecho();
- crmode();
- Signal("Aye aye, Sir", 0, 0);
- for(;;)
- {
- move(scroll++,0);
- clearline();
- addch('~');
- move(--scroll,0);
- refresh();
- ch = getch();
- switch(ch)
- {
- case 'm':
- crew = specs[scene[game].ship[player].shipnum].crew3;
- /* for (n=0; n < 3; n++)
- {
- if (ptr -> OBP[n].turnsent && ptr -> OBP[n].mensent % 10)
- crew = 0;
- }
- for (n=0; n < 3; n++)
- {
- if (ptr -> DBP[n].turnsent && ptr -> DBP[n].mensent % 10)
- crew = 0;
- } */
- if (crew && !grappled(player) && !fouled(player) && windspeed)
- {
- ta = maxturns(player);
- aheadfirst = ta & 0100000;
- ma = maxmove(player, pos[player].dir, 0);
- ta &= 077777;
- acceptmove(ma, ta, aheadfirst);
- }
- else
- Signal("Unable to move", 0, 0);
- break;
- case 's':
- acceptsignal();
- break;
- case 'g':
- grapungrap();
- break;
- case 'u':
- unfoulplayer();
- break;
- case 'v':
- version();
- break;
- case 'b':
- boarding();
- break;
-/* case '[':
- devestate = 1;
- acceptcombat();
- break; */
- case 'f':
- acceptcombat();
- break;
- case 'l':
- loadplayer();
- break;
- case 'c':
- changesail();
- break;
- case 'r':
- repair();
- break;
- case 'B':
- Signal("'Hands to stations!'", 0, 0);
- unboard(player, player, 1); /* cancel DBP's */
- unboard(player, player, 0); /* cancel offense */
- break;
- case '\f':
- signal(SIGALRM, SIG_IGN);
- viewrow = pos[player].row - ROWSINVIEW / 2;
- viewcol = pos[player].col - COLSINVIEW / 2;
- board();
- plotships(); /* don't create new turn */
- break;
- case 'L':
- scene[game].ship[player].file -> loadL = 0;
- scene[game].ship[player].file -> loadR = 0;
- scene[game].ship[player].file -> readyL = 0;
- scene[game].ship[player].file -> readyR = 0;
- Signal("Broadsides unloaded", 0, 0);
- break;
- case 'q':
- Signal("Type 'Q' to quit", 0, 0);
- break;
- case 'Q':
- leave(0);
- break;
- case 'I':
- for (n = 0; n < scene[game].vessels; n++)
- eyeball(player, n);
- break;
- case 'i':
- n = closestenemy(player, 0, 1);
- eyeball(player, n);
- break;
- }
- signalflags();
- lost();
- }
- }
-
-char *saywhat(n)
-int n;
-{
- if(scene[game].ship[n].file -> captain[0])
- return(scene[game].ship[n].file -> captain);
- else if (scene[game].ship[n].file -> struck)
- return("(struck)");
- else if(scene[game].ship[n].file -> captured > -1)
- return("(captured)");
- else
- return("(computer)");
-}
-
-eyeball(player, n)
-int player, n;
-{
- char message[80];
- register i;
-
- if (scene[game].ship[n].shipdir){
- sprintf(message, "%d, %s", range(player, n), saywhat(n));
- Signal("Sail ho! (range %s)", -1, message);
- switch(scene[game].ship[n].nationality)
- {
- case 0:
- strcpy(message, "American ");
- break;
- case 1:
- strcpy(message, "British ");
- break;
- case 2:
- strcpy(message, "Spanish ");
- break;
- case 3:
- strcpy(message, "French ");
- break;
- default:
- strcpy(message, "Gremlin ");
- break;
- }
- switch(specs[scene[game].ship[n].shipnum].class)
- {
- case 1:
- case 2:
- strcat(message, "Ship of the Line ");
- break;
- case 3:
- case 4:
- strcat(message, "Frigate ");
- break;
- case 5:
- case 6:
- strcat(message, "Sloop ");
- break;
- }
- switch(portside(player, n, 1) - pos[player].dir)
- {
- case -7:
- case 1:
- strcat(message, "off the starboard bow.");
- break;
- case -6:
- case 2:
- strcat(message, "off the starboard beam.");
- break;
- case -5:
- case 3:
- strcat(message, "off the starboard quarter.");
- break;
- case -4:
- case 4:
- strcat(message, "dead astern.");
- break;
- case -3:
- case 5:
- strcat(message, "off the port quarter.");
- break;
- case -2:
- case 6:
- strcat(message, "off the port beam.");
- break;
- case -1:
- case 7:
- strcat(message, "off the port bow.");
- break;
- case 0:
- strcat(message, "dead ahead.");
- break;
- }
- Signal(message, 0, 0);
- }