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