1 /* 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. 5 */ 6 7 #ifndef lint 8 static char sccsid[] = "@(#)dr_main.c 5.1 (Berkeley) 05/29/85"; 9 #endif not lint 10 11 #include "driver.h" 12 13 dr_main() 14 { 15 register int n; 16 register struct ship *sp; 17 int nat[NNATION]; 18 int value = 0; 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; 55 for (;;) { 56 sleep(7); 57 if (Sync() < 0) { 58 value = 1; 59 break; 60 } 61 if (next() < 0) 62 break; 63 unfoul(); 64 checkup(); 65 prizecheck(); 66 moveall(); 67 thinkofgrapples(); 68 boardcomp(); 69 compcombat(); 70 resolve(); 71 reload(); 72 checksails(); 73 if (Sync() < 0) { 74 value = 1; 75 break; 76 } 77 } 78 sync_close(1); 79 return value; 80 } 81