Commit | Line | Data |
---|---|---|
b5f0675e | 1 | /* |
1e008c14 DF |
2 | * Copyright (c) 1983 Regents of the University of California. |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
b5f0675e EW |
5 | */ |
6 | ||
7cd9dc3d | 7 | #ifndef lint |
c4fc53a1 | 8 | static char sccsid[] = "@(#)dr_main.c 5.2 (Berkeley) %G%"; |
1e008c14 | 9 | #endif not lint |
7cd9dc3d EW |
10 | |
11 | #include "driver.h" | |
12 | ||
13 | dr_main() | |
14 | { | |
15 | register int n; | |
16 | register struct ship *sp; | |
17 | int nat[NNATION]; | |
a3a7a20d | 18 | int value = 0; |
7cd9dc3d EW |
19 | |
20 | (void) signal(SIGINT, SIG_IGN); | |
21 | (void) signal(SIGQUIT, SIG_IGN); | |
22 | (void) signal(SIGTSTP, SIG_IGN); | |
23 | if (issetuid) | |
24 | (void) setruid(geteuid()); | |
25 | if (game < 0 || game >= NSCENE) { | |
26 | fprintf(stderr, "DRIVER: Bad game number %d\n", game); | |
27 | exit(1); | |
28 | } | |
29 | cc = &scene[game]; | |
30 | ls = SHIP(cc->vessels); | |
31 | if (sync_open() < 0) { | |
32 | perror("driver: syncfile"); | |
33 | exit(1); | |
34 | } | |
35 | for (n = 0; n < NNATION; n++) | |
36 | nat[n] = 0; | |
37 | foreachship(sp) { | |
38 | if (sp->file == NULL && | |
39 | (sp->file = (struct File *)calloc(1, sizeof (struct File))) == NULL) { | |
40 | (void) fprintf(stderr, "DRIVER: Out of memory.\n"); | |
41 | exit(1); | |
42 | } | |
43 | sp->file->index = sp - SHIP(0); | |
44 | sp->file->loadL = L_ROUND; | |
45 | sp->file->loadR = L_ROUND; | |
46 | sp->file->readyR = R_LOADED|R_INITIAL; | |
47 | sp->file->readyL = R_LOADED|R_INITIAL; | |
48 | sp->file->stern = nat[sp->nationality]++; | |
49 | sp->file->dir = sp->shipdir; | |
50 | sp->file->row = sp->shiprow; | |
51 | sp->file->col = sp->shipcol; | |
52 | } | |
53 | windspeed = cc->windspeed; | |
54 | winddir = cc->winddir; | |
c4fc53a1 | 55 | people = 0; |
7cd9dc3d EW |
56 | for (;;) { |
57 | sleep(7); | |
58 | if (Sync() < 0) { | |
a3a7a20d EW |
59 | value = 1; |
60 | break; | |
7cd9dc3d | 61 | } |
a3a7a20d EW |
62 | if (next() < 0) |
63 | break; | |
7cd9dc3d EW |
64 | unfoul(); |
65 | checkup(); | |
66 | prizecheck(); | |
67 | moveall(); | |
68 | thinkofgrapples(); | |
69 | boardcomp(); | |
70 | compcombat(); | |
71 | resolve(); | |
72 | reload(); | |
73 | checksails(); | |
74 | if (Sync() < 0) { | |
a3a7a20d EW |
75 | value = 1; |
76 | break; | |
7cd9dc3d EW |
77 | } |
78 | } | |
a3a7a20d EW |
79 | sync_close(1); |
80 | return value; | |
7cd9dc3d | 81 | } |