X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/6ca4591420310dcf4b7d0556c5cc0858ab7f6763..2916bca5320494d58815d8bb74a3274aebf3fefc:/usr/src/games/sail/dr_1.c diff --git a/usr/src/games/sail/dr_1.c b/usr/src/games/sail/dr_1.c index c805e28d1f..b054c967c7 100644 --- a/usr/src/games/sail/dr_1.c +++ b/usr/src/games/sail/dr_1.c @@ -1,69 +1,26 @@ +/* + * Copyright (c) 1983 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + #ifndef lint -static char *sccsid = "@(#)dr_1.c 2.6 83/12/17"; -#endif +static char sccsid[] = "@(#)dr_1.c 5.3 (Berkeley) %G%"; +#endif /* not lint */ #include "driver.h" -main(argc, argv) -int argc; -char **argv; -{ - register int n; - register struct ship *sp; - int nat[NNATION]; - - if (argc != 2) - exit(1); - (void) signal(SIGINT, SIG_IGN); - (void) signal(SIGQUIT, SIG_IGN); - (void) signal(SIGTSTP, SIG_IGN); - (void) srand(getpid()); - /* ;;; add code here to check the game number. */ - game = atoi(argv[1]); - cc = &scene[game]; - ls = &cc->ship[cc->vessels]; - if (sync_open() < 0) { - perror("driver: 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 == NULL) { - (void) printf("driver: OUT OF MEMORY\n"); - exit(0); - } - sp->file->index = sp - SHIP(0); - sp->file->loadL = L_ROUND; - sp->file->loadR = L_ROUND; - sp->file->readyR = R_LOADED|R_INITIAL; - sp->file->readyL = R_LOADED|R_INITIAL; - 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; - for (;;) { - sleep(7); - Sync(); - next(); - unfoul(); - checkup(); - prizecheck(); - moveall(); - thinkofgrapples(); - boardcomp(); - compcombat(); - resolve(); - reload(); - checksails(); - Sync(); - } -} - unfoul() { register struct ship *sp; @@ -76,8 +33,8 @@ unfoul() continue; nat = capship(sp)->nationality; foreachship(to) { - if (nat != capship(to)->nationality - && !toughmelee(sp, to, 0, 0)) + if (nat != capship(to)->nationality && + !toughmelee(sp, to, 0, 0)) continue; for (i = fouled2(sp, to); --i >= 0;) if (die() <= 2) @@ -418,57 +375,71 @@ next() else people = 0; if (people <= 0 || windspeed == 7) { - sync_close(1); - exit(0); + register struct ship *s; + struct ship *bestship; + float net, best = 0.0; + foreachship(s) { + if (*s->file->captain) + continue; + net = (float)s->file->points / s->specs->pts; + if (net > best) { + best = net; + bestship = s; + } + } + if (best > 0.0) { + char *p = getenv("WOTD"); + if (p == 0) + p = "Driver"; + if (islower(*p)) + *p = toupper(*p); + (void) strncpy(bestship->file->captain, p, + sizeof bestship->file->captain); + bestship->file->captain + [sizeof bestship->file->captain - 1] = 0; + log(bestship); + } + return -1; } Write(W_TURN, SHIP(0), 0, turn, 0, 0, 0); - if (turn % 7 == 0) { - if (die() >= cc->windchange || !windspeed) { + if (turn % 7 == 0 && (die() >= cc->windchange || !windspeed)) { + switch (die()) { + case 1: + winddir = 1; + break; + case 2: + break; + case 3: + winddir++; + break; + case 4: + winddir--; + break; + case 5: + winddir += 2; + break; + case 6: + winddir -= 2; + break; + } + if (winddir > 8) + winddir -= 8; + if (winddir < 1) + winddir += 8; + if (windspeed) switch (die()) { case 1: - winddir = 1; - break; case 2: - break; - case 3: - winddir++; - break; - case 4: - winddir--; + windspeed--; break; case 5: - winddir += 2; - break; case 6: - winddir -= 2; + windspeed++; break; } - if (winddir > 8) - winddir -= 8; - if (winddir < 1) - winddir += 8; - if (windspeed) - switch (die()) { - case 1: - case 2: - windspeed--; - break; - case 5: - case 6: - windspeed++; - break; - } - else - windspeed++; - Write(W_WIND, SHIP(0), 0, winddir, windspeed, 0, 0); - } + else + windspeed++; + Write(W_WIND, SHIP(0), 0, winddir, windspeed, 0, 0); } -} - -/*ARGSUSED*/ -/*VARARGS2*/ -Signal(fmt, ship, a, b, c) -char *fmt; -struct ship *ship; -{ + return 0; }