121466Smckusick /* 221466Smckusick * Copyright (c) 1980 Regents of the University of California. 3*33690Sbostic * All rights reserved. 4*33690Sbostic * 5*33690Sbostic * Redistribution and use in source and binary forms are permitted 6*33690Sbostic * provided that this notice is preserved and that due credit is given 7*33690Sbostic * to the University of California at Berkeley. The name of the University 8*33690Sbostic * may not be used to endorse or promote products derived from this 9*33690Sbostic * software without specific prior written permission. This software 10*33690Sbostic * is provided ``as is'' without express or implied warranty. 1121466Smckusick */ 1221466Smckusick 1321466Smckusick #ifndef lint 1421466Smckusick char copyright[] = 1521466Smckusick "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 1621466Smckusick All rights reserved.\n"; 17*33690Sbostic #endif /* not lint */ 1821466Smckusick 1921466Smckusick #ifndef lint 20*33690Sbostic static char sccsid[] = "@(#)main.c 5.2 (Berkeley) 03/09/88"; 21*33690Sbostic #endif /* not lint */ 2221466Smckusick 2321466Smckusick # include "robots.h" 2421466Smckusick # include <signal.h> 2521466Smckusick # include <ctype.h> 2621466Smckusick 2721466Smckusick main(ac, av) 2821466Smckusick int ac; 2921466Smckusick char **av; 3021466Smckusick { 3121466Smckusick register char *sp; 3221466Smckusick register bool bad_arg; 3321466Smckusick register bool show_only; 3421466Smckusick extern char *Scorefile; 3521466Smckusick extern int Max_per_uid; 3621466Smckusick extern char *rindex(); 3721466Smckusick 3821466Smckusick show_only = FALSE; 3921466Smckusick if (ac > 1) { 4021466Smckusick bad_arg = FALSE; 4121466Smckusick for (++av; ac > 1 && *av[0]; av++, ac--) 4221466Smckusick if (av[0][0] != '-') 4321466Smckusick if (isdigit(av[0][0])) 4421466Smckusick Max_per_uid = atoi(av[0]); 4521466Smckusick else { 4621466Smckusick setuid(getuid()); 4721466Smckusick setgid(getgid()); 4821466Smckusick Scorefile = av[0]; 4921466Smckusick # ifdef FANCY 5021466Smckusick sp = rindex(Scorefile, '/'); 5121466Smckusick if (sp == NULL) 5221466Smckusick sp = Scorefile; 5321466Smckusick if (strcmp(sp, "pattern_roll") == 0) 5421466Smckusick Pattern_roll = TRUE; 5521466Smckusick else if (strcmp(sp, "stand_still") == 0) 5621466Smckusick Stand_still = TRUE; 5721466Smckusick if (Pattern_roll || Stand_still) 5821466Smckusick Teleport = TRUE; 5921466Smckusick # endif 6021466Smckusick } 6121466Smckusick else 6221466Smckusick for (sp = &av[0][1]; *sp; sp++) 6321466Smckusick switch (*sp) { 6421466Smckusick case 's': 6521466Smckusick show_only = TRUE; 6621466Smckusick break; 6721466Smckusick case 'r': 6821466Smckusick Real_time = TRUE; 6921466Smckusick break; 7021466Smckusick case 'a': 7121466Smckusick Start_level = 4; 7221466Smckusick break; 7321466Smckusick case 'j': 7421466Smckusick Jump = TRUE; 7521466Smckusick break; 7621466Smckusick case 't': 7721466Smckusick Teleport = TRUE; 7821466Smckusick break; 7921466Smckusick default: 8021466Smckusick fprintf(stderr, "robots: uknown option: %c\n", *sp); 8121466Smckusick bad_arg = TRUE; 8221466Smckusick break; 8321466Smckusick } 8421466Smckusick if (bad_arg) { 8521466Smckusick exit(1); 8621466Smckusick /* NOTREACHED */ 8721466Smckusick } 8821466Smckusick } 8921466Smckusick 9021466Smckusick if (show_only) { 9121466Smckusick show_score(); 9221466Smckusick exit(0); 9321466Smckusick /* NOTREACHED */ 9421466Smckusick } 9521466Smckusick 9621466Smckusick initscr(); 9721466Smckusick signal(SIGINT, quit); 9821466Smckusick crmode(); 9921466Smckusick noecho(); 10021466Smckusick nonl(); 10121466Smckusick if (LINES != Y_SIZE || COLS != X_SIZE) { 10221466Smckusick if (LINES < Y_SIZE || COLS < X_SIZE) { 10321466Smckusick endwin(); 10421466Smckusick printf("Need at least a %dx%d screen\n", Y_SIZE, X_SIZE); 10521466Smckusick exit(1); 10621466Smckusick } 10721466Smckusick delwin(stdscr); 10821466Smckusick stdscr = newwin(Y_SIZE, X_SIZE, 0, 0); 10921466Smckusick } 11021466Smckusick 11121466Smckusick srand(getpid()); 11221466Smckusick if (Real_time) 11321466Smckusick signal(SIGALRM, move_robots); 11421466Smckusick do { 11521466Smckusick init_field(); 11621466Smckusick for (Level = Start_level; !Dead; Level++) { 11721466Smckusick make_level(); 11821466Smckusick play_level(); 11921466Smckusick } 12021466Smckusick move(My_pos.y, My_pos.x); 12121466Smckusick printw("AARRrrgghhhh...."); 12221466Smckusick refresh(); 12321466Smckusick score(); 12421466Smckusick } while (another()); 12521466Smckusick quit(); 12621466Smckusick } 12721466Smckusick 12821466Smckusick /* 12921466Smckusick * quit: 13021466Smckusick * Leave the program elegantly. 13121466Smckusick */ 13221466Smckusick quit() 13321466Smckusick { 13421466Smckusick extern int _putchar(); 13521466Smckusick 13621466Smckusick mvcur(0, COLS - 1, LINES - 1, 0); 13721466Smckusick if (CE) { 13821466Smckusick tputs(CE, 1, _putchar); 13921466Smckusick endwin(); 14021466Smckusick } 14121466Smckusick else { 14221466Smckusick endwin(); 14321466Smckusick putchar('\n'); 14421466Smckusick } 14521466Smckusick exit(0); 14621466Smckusick /* NOTREACHED */ 14721466Smckusick } 14821466Smckusick 14921466Smckusick /* 15021466Smckusick * another: 15121466Smckusick * See if another game is desired 15221466Smckusick */ 15321466Smckusick another() 15421466Smckusick { 15521466Smckusick register int y; 15621466Smckusick 15721466Smckusick #ifdef FANCY 15821466Smckusick if ((Stand_still || Pattern_roll) && !Newscore) 15921466Smckusick return TRUE; 16021466Smckusick #endif 16121466Smckusick 16221466Smckusick if (query("Another game?")) { 16321466Smckusick if (Full_clear) { 16421466Smckusick for (y = 1; y <= Num_scores; y++) { 16521466Smckusick move(y, 1); 16621466Smckusick clrtoeol(); 16721466Smckusick } 16821466Smckusick refresh(); 16921466Smckusick } 17021466Smckusick return TRUE; 17121466Smckusick } 17221466Smckusick return FALSE; 17321466Smckusick } 174