]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - robots/main.c
bogus lseek extern
[bsdgames-darwin.git] / robots / main.c
1 /*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 #ifndef lint
35 char copyright[] =
36 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
37 All rights reserved.\n";
38 #endif /* not lint */
39
40 #ifndef lint
41 /*static char sccsid[] = "from: @(#)main.c 5.5 (Berkeley) 2/28/91";*/
42 static char rcsid[] = "$Id: main.c,v 1.4 1993/08/10 15:39:40 mycroft Exp $";
43 #endif /* not lint */
44
45 # include "robots.h"
46 # include <signal.h>
47 # include <ctype.h>
48
49 main(ac, av)
50 int ac;
51 char **av;
52 {
53 register char *sp;
54 register bool bad_arg;
55 register bool show_only;
56 extern char *Scorefile;
57 extern int Max_per_uid;
58 void quit();
59
60 show_only = FALSE;
61 if (ac > 1) {
62 bad_arg = FALSE;
63 for (++av; ac > 1 && *av[0]; av++, ac--)
64 if (av[0][0] != '-')
65 if (isdigit(av[0][0]))
66 Max_per_uid = atoi(av[0]);
67 else {
68 setuid(getuid());
69 setgid(getgid());
70 Scorefile = av[0];
71 # ifdef FANCY
72 sp = rindex(Scorefile, '/');
73 if (sp == NULL)
74 sp = Scorefile;
75 if (strcmp(sp, "pattern_roll") == 0)
76 Pattern_roll = TRUE;
77 else if (strcmp(sp, "stand_still") == 0)
78 Stand_still = TRUE;
79 if (Pattern_roll || Stand_still)
80 Teleport = TRUE;
81 # endif
82 }
83 else
84 for (sp = &av[0][1]; *sp; sp++)
85 switch (*sp) {
86 case 's':
87 show_only = TRUE;
88 break;
89 case 'r':
90 Real_time = TRUE;
91 break;
92 case 'a':
93 Start_level = 4;
94 break;
95 case 'j':
96 Jump = TRUE;
97 break;
98 case 't':
99 Teleport = TRUE;
100 break;
101 default:
102 fprintf(stderr, "robots: uknown option: %c\n", *sp);
103 bad_arg = TRUE;
104 break;
105 }
106 if (bad_arg) {
107 exit(1);
108 /* NOTREACHED */
109 }
110 }
111
112 if (show_only) {
113 show_score();
114 exit(0);
115 /* NOTREACHED */
116 }
117
118 initscr();
119 signal(SIGINT, quit);
120 crmode();
121 noecho();
122 nonl();
123 if (LINES != Y_SIZE || COLS != X_SIZE) {
124 if (LINES < Y_SIZE || COLS < X_SIZE) {
125 endwin();
126 printf("Need at least a %dx%d screen\n",
127 Y_SIZE, X_SIZE);
128 exit(1);
129 }
130 delwin(stdscr);
131 stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
132 }
133
134 srand(getpid());
135 if (Real_time)
136 signal(SIGALRM, move_robots);
137 do {
138 init_field();
139 for (Level = Start_level; !Dead; Level++) {
140 make_level();
141 play_level();
142 }
143 move(My_pos.y, My_pos.x);
144 printw("AARRrrgghhhh....");
145 refresh();
146 score();
147 } while (another());
148 quit();
149 }
150
151 /*
152 * quit:
153 * Leave the program elegantly.
154 */
155 void
156 quit()
157 {
158 mvcur(0, X_SIZE - 1, Y_SIZE - 1, 0);
159 endwin();
160 printf("\n");
161 exit(0);
162 /* NOTREACHED */
163 }
164
165 /*
166 * another:
167 * See if another game is desired
168 */
169 another()
170 {
171 register int y;
172
173 #ifdef FANCY
174 if ((Stand_still || Pattern_roll) && !Newscore)
175 return TRUE;
176 #endif
177
178 if (query("Another game?")) {
179 if (Full_clear) {
180 for (y = 1; y <= Num_scores; y++) {
181 move(y, 1);
182 clrtoeol();
183 }
184 refresh();
185 }
186 return TRUE;
187 }
188 return FALSE;
189 }