1 /*
2 * Copyright (c) 1980, 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 copyright[] =
10 "@(#) Copyright (c) 1980, 1993\n\
11 The Regents of the University of California. All rights reserved.\n";
12 #endif /* not lint */
13
14 #ifndef lint
15 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 05/31/93";
16 #endif /* not lint */
17
18 # include "robots.h"
19 # include <signal.h>
20 # include <ctype.h>
21
main(ac,av)22 main(ac, av)
23 int ac;
24 char **av;
25 {
26 register char *sp;
27 register bool bad_arg;
28 register bool show_only;
29 extern char *Scorefile;
30 extern int Max_per_uid;
31 void quit();
32
33 show_only = FALSE;
34 if (ac > 1) {
35 bad_arg = FALSE;
36 for (++av; ac > 1 && *av[0]; av++, ac--)
37 if (av[0][0] != '-')
38 if (isdigit(av[0][0]))
39 Max_per_uid = atoi(av[0]);
40 else {
41 setuid(getuid());
42 setgid(getgid());
43 Scorefile = av[0];
44 # ifdef FANCY
45 sp = rindex(Scorefile, '/');
46 if (sp == NULL)
47 sp = Scorefile;
48 if (strcmp(sp, "pattern_roll") == 0)
49 Pattern_roll = TRUE;
50 else if (strcmp(sp, "stand_still") == 0)
51 Stand_still = TRUE;
52 if (Pattern_roll || Stand_still)
53 Teleport = TRUE;
54 # endif
55 }
56 else
57 for (sp = &av[0][1]; *sp; sp++)
58 switch (*sp) {
59 case 's':
60 show_only = TRUE;
61 break;
62 case 'r':
63 Real_time = TRUE;
64 break;
65 case 'a':
66 Start_level = 4;
67 break;
68 case 'j':
69 Jump = TRUE;
70 break;
71 case 't':
72 Teleport = TRUE;
73 break;
74 default:
75 fprintf(stderr, "robots: uknown option: %c\n", *sp);
76 bad_arg = TRUE;
77 break;
78 }
79 if (bad_arg) {
80 exit(1);
81 /* NOTREACHED */
82 }
83 }
84
85 if (show_only) {
86 show_score();
87 exit(0);
88 /* NOTREACHED */
89 }
90
91 initscr();
92 signal(SIGINT, quit);
93 crmode();
94 noecho();
95 nonl();
96 if (LINES != Y_SIZE || COLS != X_SIZE) {
97 if (LINES < Y_SIZE || COLS < X_SIZE) {
98 endwin();
99 printf("Need at least a %dx%d screen\n",
100 Y_SIZE, X_SIZE);
101 exit(1);
102 }
103 delwin(stdscr);
104 stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
105 }
106
107 srand(getpid());
108 if (Real_time)
109 signal(SIGALRM, move_robots);
110 do {
111 init_field();
112 for (Level = Start_level; !Dead; Level++) {
113 make_level();
114 play_level();
115 }
116 move(My_pos.y, My_pos.x);
117 printw("AARRrrgghhhh....");
118 refresh();
119 score();
120 } while (another());
121 quit();
122 }
123
124 void
__cputchar(ch)125 __cputchar(ch)
126 int ch;
127 {
128 (void)putchar(ch);
129 }
130
131 /*
132 * quit:
133 * Leave the program elegantly.
134 */
135 void
quit()136 quit()
137 {
138 endwin();
139 exit(0);
140 /* NOTREACHED */
141 }
142
143 /*
144 * another:
145 * See if another game is desired
146 */
another()147 another()
148 {
149 register int y;
150
151 #ifdef FANCY
152 if ((Stand_still || Pattern_roll) && !Newscore)
153 return TRUE;
154 #endif
155
156 if (query("Another game?")) {
157 if (Full_clear) {
158 for (y = 1; y <= Num_scores; y++) {
159 move(y, 1);
160 clrtoeol();
161 }
162 refresh();
163 }
164 return TRUE;
165 }
166 return FALSE;
167 }
168