Annotation of researchv10no/games/sail/player1.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char *sccsid = "@(#)player1.c   1.10 83/07/03";
                      3: #endif
                      4: 
                      5: #include "player.h"
                      6: #include <sys/types.h>
                      7: 
                      8: WINDOW *view,*slot;
                      9: char done_curses = 0;
                     10: 
                     11: acceptcombat()
                     12: {
                     13:        int crew[3], men = 0, rangeofshot, target, temp;
                     14:        int n, r, guns[2], load[2], car[2], roll[2];
                     15:        int ready[2], index, rakehim, sternrake;
                     16:        int shootat[2], hit[2], closest[2], ship;
                     17:        int hhits = 0, ghits = 0, rhits = 0, chits = 0;
                     18:        int buf;
                     19:        struct shipspecs *ptr;
                     20:        struct File *ptr1;
                     21: 
                     22:        ptr = &specs[scene[game].ship[player].shipnum];
                     23:        ptr1 = scene[game].ship[player].file;
                     24:        crew[0] = ptr->crew1;
                     25:        crew[1] = ptr->crew2;
                     26:        crew[2] = ptr->crew3;
                     27:        ready[0] = ptr1->readyL;
                     28:        ready[1] = ptr1->readyR;
                     29:        load[0] = ptr1->loadL;
                     30:        load[1] = ptr1->loadR;
                     31:        guns[0] = ptr->gunL;
                     32:        guns[1] = ptr->gunR;
                     33:        car[0] = ptr->carL;
                     34:        car[1] = ptr->carR;
                     35:        for (n = 0; n < 3; n++) {
                     36:                if (ptr1->OBP[n].turnsent)
                     37:                        men += ptr1->OBP[n].mensent;
                     38:        }
                     39:        for (n = 0; n < 3; n++) {
                     40:                if (ptr1->DBP[n].turnsent)
                     41:                        men += ptr1->DBP[n].mensent;
                     42:        }
                     43:        if (men) {
                     44:                crew[0] = men/100 ? 0 : crew[0] != 0;
                     45:                crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
                     46:                crew[2] = men%10 ? 0 : crew[2] != 0;
                     47:        }
                     48:        for (r = 0; r < 2; r++) {
                     49:                if ((guns[r] || car[r]) && crew[2] && load[r] && ready[r] <= 0 && !ptr1->struck && ((closest[r] = closestenemy(player, (r ? 'r' : 'l'), 1)) != 30000)) {
                     50:                        switch(load[r]) {
                     51:                        case GRAPE:
                     52:                                rangeofshot = 1;
                     53:                                break;
                     54:                        case CHAIN:
                     55:                                rangeofshot = 3;
                     56:                                break;
                     57:                        case DOUBLE:
                     58:                                rangeofshot = 1;
                     59:                                break;
                     60:                        case ROUND:
                     61:                                rangeofshot = 10;
                     62:                                break;
                     63:                        }
                     64:                        if ((target = range(player, closest[r])) <= rangeofshot && !scene[game].ship[closest[r]].file->struck && (guns[r] || (car[r] && target < 3))) {
                     65:                                Signal("%s (%c%c) within range of %s broadside.", closest[r], (r?"right":"left"));
                     66:                                if (load[r] > CHAIN && target < 6) {
                     67:                                        Signal("Aim for hull or rigging? ", -1, 0);
                     68:                                        while ((buf = getch()) == EOF);
                     69:                                        addch(buf);
                     70:                                        if(buf == 'r')
                     71:                                                shootat[r] = RIGGING;
                     72:                                        else if (buf == 'h')
                     73:                                                shootat[r] = HULL;
                     74:                                        else {
                     75:                                                shootat[r] = -1;
                     76:                                                Signal("'Avast there! Hold your fire.'", -1, 0);
                     77:                                        }
                     78:                                } else {
                     79:                                        shootat[r] = RIGGING;
                     80:                                        Signal("Fire? ", -1, 0);
                     81:                                        while ((buf = getch()) == EOF);
                     82:                                        addch(buf);
                     83:                                        if (buf == 'n') {
                     84:                                                shootat[r] = -1;
                     85:                                                Signal("Belay that! Hold your fire.", -1, 0);
                     86:                                        }
                     87:                                }
                     88:                                if (shootat[r] != -1) {
                     89:                                        fired = 1;
                     90:                                        rakehim = gunsbear(player, closest[r]) && !gunsbear(closest[r], player);
                     91:                                        temp = portside(closest[r], player, 1) - pos[closest[r]].dir + 1;
                     92:                                        if (temp < 1)
                     93:                                                temp += 8;
                     94:                                        if (temp > 8)
                     95:                                                temp -= 8;
                     96:                                        sternrake = temp > 4 && temp < 6;
                     97:                                        if (rakehim && !sternrake)
                     98:                                                Signal("Raking the %s!", closest[r], 0);
                     99:                                        else if (rakehim && sternrake)
                    100:                                                Signal("Stern Rake! %s splintering!", closest[r], 0);
                    101:                                        index = guns[r];
                    102:                                        if (target < 3)
                    103:                                                index += car[r];
                    104:                                        index = (index - 1)/3;
                    105:                                        index = index > 8 ? 8 : index;
                    106:                                        if (!rakehim)
                    107:                                                hit[r] = HDT[index][target-1];
                    108:                                        else
                    109:                                                hit[r] = HDTrake[index][target-1];
                    110:                                        if (rakehim && sternrake)
                    111:                                                hit[r]++;
                    112:                                        hit[r] += QUAL[index][ptr->qual-1];
                    113:                                        for (n=0; n < 3 && ptr1->captured < 0; n++)
                    114:                                                if (!crew[n])
                    115:                                                        if (index <= 5)
                    116:                                                                hit[r]--;
                    117:                                                        else
                    118:                                                                hit[r] -= 2;
                    119:                                        if (ready[r] <= -30000)
                    120:                                                if (index <= 3)
                    121:                                                        hit[r]++;
                    122:                                                else
                    123:                                                        hit[r] += 2;
                    124:                                        if (ptr1->captured > -1)
                    125:                                                if (index <= 1)
                    126:                                                        hit[r]--;
                    127:                                                else
                    128:                                                        hit[r] -= 2;
                    129:                                        hit[r] += AMMO[index][load[r] - 1];
                    130:                                        if (((temp = ptr->class) >= 5 || temp == 1) && windspeed == 5)
                    131:                                                hit[r]--;
                    132:                                        if (windspeed == 6 && temp == 4)
                    133:                                                hit[r] -= 2;
                    134:                                        if (windspeed == 6 && temp <= 3)
                    135:                                                hit[r]--;
                    136:                                        if (hit[r] >= 0) {
                    137:                                                roll[r] = die();
                    138:                                                if (load[r] == GRAPE)
                    139:                                                        chits = hit[r];
                    140:                                                else {
                    141:                                                        struct Tables *t;
                    142:                                                        hit[r] = hit[r] > 10 ? 10 : hit[r];
                    143:                                                        t = &(shootat[r] ? RigTable : HullTable)[hit[r]][roll[r]-1];
                    144:                                                        chits = t->C;
                    145:                                                        rhits = t->R;
                    146:                                                        hhits = t->H;
                    147:                                                        ghits = t->G;
                    148:                                                        if (scene[game].ship[closest[r]].file->FS)
                    149:                                                                rhits *= 2;
                    150:                                                        if (load[r] == CHAIN) {
                    151:                                                                ghits = 0;
                    152:                                                                hhits = 0;
                    153:                                                        }
                    154:                                                }
                    155:                                                table(shootat[r], load[r], hit[r], closest[r], player, roll[r]);
                    156:                                        }
                    157:                                        scroll = 18;
                    158:                                        move(scroll++, 0);
                    159:                                        clearline();
                    160:                                        printw("Damage inflicted on the %s:", scene[game].ship[closest[r]].shipname);
                    161:                                        move(scroll++, 0);
                    162:                                        clearline();
                    163:                                        printw("\t%d HULL, %d GUNS, %d CREW, %d RIGGING", hhits, ghits, chits, rhits);
                    164:                                        load[r] = 0;
                    165:                                        if (!r) {
                    166:                                                ptr1->loadL = 0;
                    167:                                                ptr1->readyL = 0;
                    168:                                        } else {
                    169:                                                ptr1->loadR = 0;
                    170:                                                ptr1->readyR = 0;
                    171:                                        }
                    172:                                }
                    173:                        } else {
                    174:                                load[r] = 0;
                    175:                                Signal("Unable to fire %s broadside", -1, (r?"right":"left"));
                    176:                        }
                    177:                } else
                    178:                        Signal("Unable to fire %s broadside", -1, (r?"right":"left"));
                    179:        }
                    180: }
                    181: 
                    182: leave(conditions)
                    183: int conditions;
                    184: {
                    185:        FILE *fp;
                    186:        int people;
                    187:        float net;
                    188:        char * capn;
                    189:        char message[60];
                    190:        register int n;
                    191:        struct logs log[10], temp;
                    192: 
                    193:        signal(SIGHUP, SIG_IGN);
                    194:        signal(SIGINT, SIG_IGN);
                    195:        signal(SIGQUIT, SIG_IGN);
                    196:        signal(SIGALRM, SIG_IGN);
                    197:        signal(SIGCHLD, SIG_IGN);
                    198:        signal(SIGTSTP, SIG_IGN);
                    199: 
                    200:        if (conditions != -1) {
                    201:                capn = scene[game].ship[player].file->captain;
                    202:                sprintf(message,"Captain %s relinquishing.",capn);
                    203:                Write(FILES + player, 1, 164, message);
                    204: 
                    205:                if (fp = fopen(LOGFILE, "r+")) {
                    206:                        net = (float) (scene[game].ship[player].file->points) / specs[scene[game].ship[player].shipnum].pts;
                    207:                        (void) fread(&people, sizeof people, 1, fp);
                    208:                        n = fread(log, sizeof(struct logs), 10, fp);
                    209:                        for (; n < 10; n++) {
                    210:                                log[n].fname[0] = 0;
                    211:                                log[n].uid = 0;
                    212:                                log[n].fshipnum = 0;
                    213:                                log[n].fgamenum = 0;
                    214:                                log[n].netpoints = -1;
                    215:                        }
                    216:                        rewind(fp);
                    217:                        if(people < 0) {
                    218:                                people = 1;
                    219:                                (void) fwrite(&people, sizeof people, 1, fp);
                    220:                        }
                    221:                        else {
                    222:                                people++;
                    223:                                (void) fwrite(&people, sizeof people, 1, fp);
                    224:                        }
                    225:                        for (n=0; n < 10; n++)
                    226:                                if (net > (float) log[n].netpoints / specs[scene[log[n].fgamenum].ship[log[n].fshipnum].shipnum].pts) {
                    227:                                        fwrite(log, sizeof(struct logs), n, fp);
                    228:                                        strcpy(temp.fname, capn);
                    229:                                        temp.uid = getuid();
                    230:                                        temp.fshipnum = player;
                    231:                                        temp.fgamenum = game;
                    232:                                        temp.netpoints = scene[game].ship[player].file->points;
                    233:                                        fwrite(&temp, sizeof(struct logs), 1, fp);
                    234:                                        fwrite(log + n, sizeof(struct logs), 9 - n, fp);
                    235:                                        break;
                    236:                                }
                    237:                        fclose(fp);
                    238:                }
                    239:                Write(FILES + player, 1, 0, " ");
                    240:                Write(SCENARIO, 0, 8, scene[game].people - 1);
                    241:                if (done_curses) {
                    242:                        screen();
                    243:                        Signal("It looks like you've had it!", -1, 0);
                    244:                        if (conditions == 1)
                    245:                                Signal("Your ship was captured.", -1, 0);
                    246:                        else if (conditions == 2)
                    247:                                Signal("No more enemies.", -1, 0);
                    248:                        else if (conditions == 3)
                    249:                                Signal("Hurricane!  All ships destroyed.",
                    250:                                        -1, 0);
                    251:                        else if (conditions == 4)
                    252:                                Signal("The driver died.", -1, 0);
                    253:                        move(0, LINES-1);
                    254:                        scroll = LINES;
                    255:                        clearline();
                    256:                        refresh();
                    257:                } else {
                    258:                        if (conditions == 4)
                    259:                                printf("The driver died.\n");
                    260:                }
                    261:                fclose(syncfile);
                    262:        }
                    263:        if (done_curses) {
                    264:                nocrmode();
                    265:                echo();
                    266:                endwin();
                    267:        }
                    268:        exit(0);
                    269: }
                    270: 
                    271: choke()
                    272: {
                    273:        leave(0);
                    274: }
                    275: 
                    276: #include <wait.h>
                    277: 
                    278: child()
                    279: {
                    280:        union wait status;
                    281:        int pid;
                    282: 
                    283:        signal(SIGCHLD, SIG_IGN);
                    284:        do {
                    285:                pid = vwait(&status, WNOHANG|WUNTRACED, 0);
                    286:                if (pid < 0 || pid > 0 && !WIFSTOPPED(status))
                    287:                        leave(4);
                    288:        } while (pid != 0);
                    289:        signal(SIGCHLD, child);
                    290: }
                    291: 
                    292: grapungrap()
                    293: {
                    294:        register int n, k, l, number, captured;
                    295:        int buf;
                    296: 
                    297:        for (n=0; n < scene[game].vessels ; n++) {
                    298:                if (n != player && (range(player, n) <= 1 || grapple(player, n))) {
                    299:                        if ((captured = scene[game].ship[n].file->captured) < 0)
                    300:                                captured = n;
                    301:                        Signal("Attempt to grapple or ungrapple %s (%c%c): ", n, 0);
                    302:                        while ((buf = getch()) == EOF);
                    303:                        addch(buf);
                    304:                        if (buf == 'g') {
                    305:                                number = die() < 3;
                    306:                                if (!number && scene[game].ship[player].nationality == scene[game].ship[captured].nationality)
                    307:                                        number = 1;
                    308:                                if (number) {
                    309:                                        for (l=0; l < 10 && scene[game].ship[player].file->grapples[l].turnfoul; l++);
                    310:                                        if (!scene[game].ship[player].file->grapples[l].turnfoul) {
                    311:                                                Write(FILES + player, 0, 124 + l*4, turn);
                    312:                                                Write(FILES + player, 0, 124 + l*4 + 2, n);
                    313:                                        }
                    314:                                        for (l=0; l < 10 && scene[game].ship[n].file->grapples[l].turnfoul; l++);
                    315:                                        if (!scene[game].ship[n].file->grapples[l].turnfoul) {
                    316:                                                Write(FILES + n, 0, 124 + l*4, turn);
                    317:                                                Write(FILES + n, 0, 124 + l*4 + 2, player);
                    318:                                        }
                    319:                                }
                    320:                                if (number) {
                    321:                                        Signal("Attempt succeeds!", 0, 0);
                    322:                                        makesignal("grappled with %s (%c%c)", n, player);
                    323:                                } else
                    324:                                        Signal("Attempt fails.", 0, 0);
                    325:                        }
                    326:                        if (buf == 'u') {
                    327:                                for (k=0; k < 10; k++) {
                    328:                                        if (scene[game].ship[player].file->grapples[k].turnfoul && n == scene[game].ship[player].file->grapples[k].toship) {
                    329:                                                if (die() < 3 || scene[game].ship[player].nationality == scene[game].ship[captured].nationality) {
                    330:                                                        cleangrapple(player, n, k);
                    331:                                                        Signal("Attempt succeeds!", 0, 0);
                    332:                                                        makesignal("ungrappling with %s (%c%c)", n, player);
                    333:                                                } else
                    334:                                                        Signal("Attempt fails.", 0, 0);
                    335:                                        }
                    336:                                }
                    337:                        }
                    338:                }
                    339:        }
                    340: }
                    341: 
                    342: unfoulplayer()
                    343: {
                    344:        register int n, toship;
                    345:        int buf;
                    346: 
                    347:        for (n=0; n < 10; n++) {
                    348:                if (scene[game].ship[player].file->fouls[n].turnfoul) {
                    349:                        Signal("Attempt to unfoul with the %s (%c%c)? ", (toship = scene[game].ship[player].file->fouls[n].toship), 0);
                    350:                        while ((buf = getch()) == EOF);
                    351:                        addch(buf);
                    352:                        if (buf == 'y' && die() < 3) {
                    353:                                cleanfoul(player, toship, n);
                    354:                                Signal("Attempt succeeds!", 0, 0);
                    355:                                makesignal("unfouling %s (%c%c)", toship, player);
                    356:                        } else if (buf == 'y')
                    357:                                Signal("Attempt fails.", 0, 0);
                    358:                }
                    359:        }
                    360: }
                    361: 
                    362: initialize(nodriver, randomize, debug)
                    363: char randomize, nodriver, debug;
                    364: {
                    365:        char comm[80], file[25], capn;
                    366:        char message[60];
                    367:        int load = ROUND, ready = -30000;
                    368:        int people = 0;
                    369:        int pid;
                    370:        register int n;
                    371:        register int k;
                    372:        char *nameptr;
                    373: 
                    374:        srand(pid = getpid());
                    375: 
                    376:        if (game < 0) {
                    377:                puts("Choose a scenario:\n");
                    378:                puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
                    379:                for (n=0; n < NUMOFSCENES; n++) {
                    380:                        sprintf(file, "/tmp/.sail.%d", n);
                    381:                        printf("\t%d):\t%d", n, scene[n].vessels);
                    382:                        if (access(file, 0) >= 0)
                    383:                                printf("\tYES");
                    384:                        else
                    385:                                printf("\tno");
                    386:                        printf("\t%s\n", scene[n].name);
                    387:                }
                    388: reprint:
                    389:                printf("\nScenario number? ");
                    390:                fflush(stdout);
                    391:                scanf("%d", &game);
                    392:                while (getchar() != '\n');
                    393:        }
                    394:        if (game < 0 || game >= NUMOFSCENES) {
                    395:                puts("Very funny.");
                    396:                exit(1);
                    397:        }
                    398:        sprintf(file, "/tmp/.sail.%d", game);
                    399:        if (access(file, 0) < 0) {
                    400:                int omask;
                    401: #ifdef SETUID
                    402:                omask = umask(077);
                    403: #else
                    404:                omask = umask(011);
                    405: #endif
                    406:                syncfile = fopen(file, "w+");
                    407:                umask(omask);
                    408:        } else {
                    409:                syncfile = fopen(file, "r+");
                    410:                people = 1;
                    411:        }
                    412:        lastsync = 0;
                    413:        for (n=0; n < scene[game].vessels; n++) {
                    414:                nation[scene[game].ship[n].nationality + 1] = n + 1;
                    415:                if ((scene[game].ship[n].file =  (struct File *) calloc(1, sizeof(struct File))) == NULL) {
                    416:                        puts("OUT OF MEMORY");
                    417:                        exit(0);
                    418:                }
                    419:                scene[game].ship[n].file->captured = -1;
                    420:        }
                    421:        if (!nation[2])
                    422:                nation[2] = nation[1];
                    423:        if (!nation[3])
                    424:                nation[3] = nation[2];
                    425:        if (people > 0) {
                    426:                puts("Synchronizing with the other players...");
                    427:                fflush(stdout);
                    428:                sync();
                    429:                capn = 1;
                    430:                for (n=0; n < scene[game].vessels && capn; n++) {
                    431:                        capn = scene[game].ship[n].file->captain[0];
                    432:                        if (scene[game].ship[n].file->struck || scene[game].ship[n].file->captured > -1)
                    433:                                capn = 1;
                    434:                }
                    435:                if (!capn)
                    436:                        player = n-1;
                    437:                else {
                    438:                        puts("All ships taken in that scenario.");
                    439:                        for (n=0; n < scene[game].vessels; n++)
                    440:                                free(scene[game].ship[n].file);
                    441:                        people = 0;
                    442:                        for (n=0; n < 5; n++)
                    443:                                nation[n] = 0;
                    444:                        fclose(syncfile);
                    445:                        goto reprint;
                    446:                }
                    447:        } else
                    448:                player = 0;
                    449:        while (randomize) {
                    450:                static char *color[] =
                    451:                        { "(American)", "(British)", "(Spanish)", "(French)" };
                    452:                puts(scene[game].name);
                    453:                putchar('\n');
                    454:                for (n=0; n < scene[game].vessels; n++) {
                    455:                        printf("  %2d:  %-10s %-15s  (%-2d pts)   ",
                    456:                                n,
                    457:                                color[scene[game].ship[n].nationality],
                    458:                                scene[game].ship[n].shipname,
                    459:                                specs[scene[game].ship[n].shipnum].pts);
                    460:                        if(scene[game].ship[n].file->captain[0])
                    461:                                puts(scene[game].ship[n].file->captain);
                    462:                        else if (scene[game].ship[n].file->struck)
                    463:                                puts("(struck)");
                    464:                        else if(scene[game].ship[n].file->captured > -1)
                    465:                                puts("(captured)");
                    466:                        else
                    467:                                puts("(available)");
                    468:                }
                    469:                putchar('\n');
                    470:                printf("Which ship do you want (0-%d)? ",scene[game].vessels-1);
                    471:                fflush(stdout);
                    472:                if (scanf("%d",&player) != 1 || player < 0 || player >= scene[game].vessels) {
                    473:                        while (getchar() != '\n');
                    474:                        puts("Say what?");
                    475:                } else {
                    476:                        while (getchar() != '\n');
                    477:                        sync();
                    478:                        if (scene[game].ship[player].file->captain[0] || scene[game].ship[player].file->struck || scene[game].ship[player].file->captured > -1)
                    479:                                puts("Sorry, that ship is taken.");
                    480:                        else
                    481:                                break;
                    482:                }
                    483:        }
                    484: 
                    485:        signal(SIGHUP, choke);
                    486:        signal(SIGINT, choke);
                    487:        signal(SIGQUIT, choke);
                    488:        signal(SIGCHLD, child);
                    489:        signal(SIGTSTP, SIG_IGN);
                    490: 
                    491:        Write(FILES + player, 1, 0, "begin");  /* he now exists */
                    492:        if (people)
                    493:                Write(SCENARIO, 0, 8, scene[game].people + 1);
                    494:        sync();
                    495:        printf("Your ship is the %s, a %s (%s crew).\n", scene[game].ship[player].shipname, info(player, message), quality(player));
                    496:        if ((nameptr = (char *) getenv("NAME")) && *nameptr)
                    497:                strcpy(comm,nameptr);
                    498:        else {
                    499:                fputs("Your name, Captain? ", stdout);
                    500:                fflush(stdout);
                    501:                gets(comm);
                    502:                if (!*comm) strcpy(comm, "no name");
                    503:        }
                    504:        comm[19] = '\0';
                    505:        for (k=0; k < 2; k++) {
                    506:                printf("\nInitial broadside %s (grape, chain, round, double): ", (k ? "right" : "left"));
                    507:                fflush(stdout);
                    508:                scanf("%s", file);
                    509:                switch(*file) {
                    510:                case 'g':
                    511:                        load = GRAPE;
                    512:                        break;
                    513:                case 'c':
                    514:                        load = CHAIN;
                    515:                        break;
                    516:                case 'r':
                    517:                        load = ROUND;
                    518:                        break;
                    519:                case 'd':
                    520:                        load = DOUBLE;
                    521:                        break;
                    522:                }
                    523:                if (k) {
                    524:                        scene[game].ship[player].file->loadR = load;
                    525:                        scene[game].ship[player].file->readyR = ready;
                    526:                } else {
                    527:                        scene[game].ship[player].file->loadL = load;
                    528:                        scene[game].ship[player].file->readyL = ready;
                    529:                }
                    530:        }
                    531:        Write(FILES + player, 1, 0, comm);
                    532:        if (!people && !nodriver) {
                    533:                char num[10];
                    534:                sprintf(num, "%d", game);
                    535:                if (!fork()) {
                    536:                        if (debug)
                    537:                                execl(DEBUGDRIVER, DRIVERNAME, num, 0);
                    538:                        else
                    539:                                execl(DRIVER, DRIVERNAME, num, 0);
                    540:                        perror(DRIVER);
                    541:                        kill(pid, SIGKILL);
                    542:                        exit(1);
                    543:                }
                    544:        }
                    545: 
                    546:        initscr();
                    547:        view = newwin(ROWSINVIEW, COLSINVIEW, 2, 1);
                    548:        slot = newwin(ROWSINVIEW, 3, 2, 1+COLSINVIEW);
                    549:        done_curses++;
                    550:        noecho();
                    551:        crmode();
                    552: 
                    553:        board();
                    554:        sprintf(message, "Captain %s assuming command",comm);
                    555:        Write(FILES + player, 1, 164, message);
                    556:        windspeed = scene[game].windspeed;
                    557:        winddir = scene[game].winddir;
                    558:        turn = scene[game].turn;
                    559: 
                    560:        iplotships();   /* new turn */
                    561: }
                    562: 
                    563: /*
                    564:  * Returns the NUMBER of the closest ship
                    565:  */
                    566: closestenemy(fromship, side, anyship)
                    567: int fromship;
                    568: char side, anyship;
                    569: {
                    570:        register int n, olddist = 30000, ident, captured;
                    571:        register int dist, eclosest = 30000;
                    572: 
                    573:        if ((ident = scene[game].ship[fromship].file->captured) < 0)
                    574:                ident = fromship;
                    575:        for (n=0; n < scene[game].vessels; n++) {
                    576:                if ((captured = scene[game].ship[n].file->captured) < 0)
                    577:                        captured = n;
                    578:                if (n != fromship && pos[n].dir && (scene[game].ship[ident].nationality != scene[game].ship[captured].nationality || anyship)) {
                    579:                        if (!side || gunsbear(fromship, n) == side) {
                    580:                                dist = range(fromship, n);
                    581:                                if (dist < olddist) {
                    582:                                        eclosest = n;
                    583:                                        olddist = dist;
                    584:                                }
                    585:                        }
                    586:                }
                    587:        }
                    588:        if (!side && olddist == 30000)
                    589:                leave(2);
                    590:        return(eclosest);
                    591: }
                    592: 
                    593: main(argc, argv)
                    594: int argc;
                    595: char ** argv;
                    596: {
                    597:        register int crew, aheadfirst, ma, n;
                    598:        int ta;
                    599:        char message[60], ch;
                    600:        int uid;
                    601:        char nodrive = 0, randomize = 0, debug = 0;
                    602:        char *badstring();
                    603:        extern char _sobuf[];
                    604: 
                    605:        setbuf(stdout, _sobuf);
                    606: 
                    607:        while (*++argv && **argv == '-')
                    608:                switch (*++*argv) {
                    609:                case 'd':
                    610:                        nodrive = 1;
                    611:                        break;
                    612:                case 'D':
                    613:                        debug++;
                    614:                        break;
                    615:                case 'x':
                    616:                        randomize = 1;
                    617:                        break;
                    618:                default:
                    619:                        printf("Unknown flag '%s'\n",*argv);
                    620:                        break;
                    621:                }
                    622:        if (*argv)
                    623:                game = atoi(*argv);
                    624:        else
                    625:                game = -1;
                    626:        initialize(nodrive, randomize, debug);
                    627:        Signal("Aye aye, Sir", 0, 0);
                    628:        for(;;) {
                    629:                move(scroll++,0);
                    630:                clearline();
                    631:                addch('~');
                    632:                move(--scroll,0);
                    633:                refresh();
                    634:                ch = getch();
                    635:                switch(ch) {
                    636:                case 'm':
                    637:                        crew = specs[scene[game].ship[player].shipnum].crew3;
                    638:                        if (crew && !grappled(player) && !fouled(player) && windspeed) {
                    639:                                ta = maxturns(player);
                    640:                                aheadfirst = ta & 0100000;
                    641:                                ma = maxmove(player, pos[player].dir, 0);
                    642:                                ta &= 077777;
                    643:                                acceptmove(ma, ta, aheadfirst);
                    644:                        } else
                    645:                                Signal("Unable to move", 0, 0);
                    646:                        break;
                    647:                case 's':
                    648:                        acceptsignal();
                    649:                        break;
                    650:                case 'g':
                    651:                        grapungrap();
                    652:                        break;
                    653:                case 'u':
                    654:                        unfoulplayer();
                    655:                        break;
                    656:                case 'v':
                    657:                        version();
                    658:                        break;
                    659:                case 'b':
                    660:                        boarding();
                    661:                        break;
                    662:                case 'f':
                    663:                        acceptcombat();
                    664:                        break;
                    665:                case 'l':
                    666:                        loadplayer();
                    667:                        break;
                    668:                case 'c':
                    669:                        changesail();
                    670:                        break;
                    671:                case 'r':
                    672:                        repair();
                    673:                        break;
                    674:                case 'B':
                    675:                        Signal("'Hands to stations!'", 0, 0);
                    676:                        unboard(player, player, 1);     /* cancel DBP's */
                    677:                        unboard(player, player, 0);     /* cancel offense */
                    678:                        break;
                    679:                case '\f':
                    680:                        signal(SIGALRM, SIG_IGN);
                    681:                        viewrow = pos[player].row - ROWSINVIEW / 2;
                    682:                        viewcol = pos[player].col - COLSINVIEW / 2;
                    683:                        board();
                    684:                        plotships(); /* don't create new turn */
                    685:                        break;
                    686:                case 'L':
                    687:                        scene[game].ship[player].file->loadL = 0;
                    688:                        scene[game].ship[player].file->loadR = 0;
                    689:                        scene[game].ship[player].file->readyL = 0;
                    690:                        scene[game].ship[player].file->readyR = 0;
                    691:                        Signal("Broadsides unloaded", 0, 0);
                    692:                        break;
                    693:                case 'q':
                    694:                        Signal("Type 'Q' to quit", 0, 0);
                    695:                        break;
                    696:                case 'Q':
                    697:                        leave(0);
                    698:                        break;
                    699:                case 'I':
                    700:                        for (n = 0; n < scene[game].vessels; n++)
                    701:                                eyeball(player, n);
                    702:                        break;
                    703:                case 'i':
                    704:                        n = closestenemy(player, 0, 1);
                    705:                        eyeball(player, n);
                    706:                        break;
                    707:                }
                    708:                signalflags();
                    709:                lost();
                    710:        }
                    711: }
                    712: 
                    713: char *saywhat(n)
                    714: int n;
                    715: {
                    716:        if(scene[game].ship[n].file->captain[0])
                    717:                return(scene[game].ship[n].file->captain);
                    718:        else if (scene[game].ship[n].file->struck)
                    719:                return("(struck)");
                    720:        else if(scene[game].ship[n].file->captured > -1)
                    721:                return("(captured)");
                    722:        else
                    723:                return("(computer)");
                    724: }
                    725: 
                    726: eyeball(player, n)
                    727: int player, n;
                    728: {
                    729:        char message[80];
                    730:        register i;
                    731: 
                    732:        if (scene[game].ship[n].shipdir) {
                    733:                sprintf(message, "%d, %s", range(player, n), saywhat(n));
                    734:                Signal("Sail ho! (range %s)", -1, message);
                    735:                switch(scene[game].ship[n].nationality) {
                    736:                case 0:
                    737:                        strcpy(message, "American ");
                    738:                        break;
                    739:                case 1:
                    740:                        strcpy(message, "British ");
                    741:                        break;
                    742:                case 2:
                    743:                        strcpy(message, "Spanish ");
                    744:                        break;
                    745:                case 3:
                    746:                        strcpy(message, "French ");
                    747:                        break;
                    748:                default:
                    749:                        strcpy(message, "Gremlin ");
                    750:                        break;
                    751:                }
                    752:                switch(specs[scene[game].ship[n].shipnum].class) {
                    753:                case 1:
                    754:                case 2:
                    755:                        strcat(message, "Ship of the Line ");
                    756:                        break;
                    757:                case 3:
                    758:                case 4:
                    759:                        strcat(message, "Frigate ");
                    760:                        break;
                    761:                case 5:
                    762:                case 6:
                    763:                        strcat(message, "Sloop ");
                    764:                        break;
                    765:                }
                    766:                switch(portside(player, n, 1) - pos[player].dir) {
                    767:                case -7:
                    768:                case 1:
                    769:                        strcat(message, "off the starboard bow.");
                    770:                        break;
                    771:                case -6:
                    772:                case 2:
                    773:                        strcat(message, "off the starboard beam.");
                    774:                        break;
                    775:                case -5:
                    776:                case 3:
                    777:                        strcat(message, "off the starboard quarter.");
                    778:                        break;
                    779:                case -4:
                    780:                case 4:
                    781:                        strcat(message, "dead astern.");
                    782:                        break;
                    783:                case -3:
                    784:                case 5:
                    785:                        strcat(message, "off the port quarter.");
                    786:                        break;
                    787:                case -2:
                    788:                case 6:
                    789:                        strcat(message, "off the port beam.");
                    790:                        break;
                    791:                case -1:
                    792:                case 7:
                    793:                        strcat(message, "off the port bow.");
                    794:                        break;
                    795:                case 0:
                    796:                        strcat(message, "dead ahead.");
                    797:                        break;
                    798:                }
                    799:                Signal(message, 0, 0);
                    800:        }
                    801: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.