warp.c revision 1.4 1 char rcsid[] = "@(#)Header: warp.c,v 7.0.1.3 86/12/12 17:07:44 lwall Exp";
2
3 /* warp -- a real-time space war program
4 * author: Larry Wall
5 * helpers: Jonathan and Mark Biggar, and Dan Faigin
6 * special thanks to my sweetie Gloria who suggested the Planet Crusher
7 *
8 * Copyright (C) 1986, Larry Wall
9 *
10 * This program may be copied as long as this copyright notice is
11 * included, and as long as it is not being copied for purposes
12 * of profit. If you want to modify this program in any way other
13 * than normal configuration changes, common decency would suggest
14 * that you also modify the name of the program so that my good name
15 * (what there is of it) is not impugned. (Calling it something like
16 * "warpx" or "superwarp" would be fine.) Also, give it another
17 * WARPDIR so that the scoreboards don't get confused.
18 *
19 * version 5.0 04/20/83
20 * 5.1 05/05/83 various tidbits
21 * 5.2 05/12/83 VAX -> vax, ifdef'ed a SIGCONT
22 * 5.3 05/24/83 RCS
23 *
24 * Log: warp.c,v
25 * Revision 7.0.1.3 86/12/12 17:07:44 lwall
26 * Baseline for net release.
27 *
28 * Revision 7.0.1.2 86/10/20 12:08:00 lwall
29 * Made all exits reset tty.
30 *
31 * Revision 7.0.1.1 86/10/16 10:54:13 lwall
32 * Added Damage. Fixed random bugs.
33 *
34 * Revision 7.0 86/10/08 15:14:47 lwall
35 * Split into separate files. Added amoebas and pirates.
36 *
37 * Revision 6.4 83/12/16 13:11:45 lwall
38 * Handled 15 bit random number generators.
39 *
40 * Fixed array overflow bug on multiple zaps.
41 *
42 * Multiple zaps now consolidated to minimize output.
43 *
44 * Tholian jackpot games outlawed under difficulty 15.
45 *
46 * Revision 6.3 83/08/24 11:17:49 lwall
47 * Fixed array overflow bug on multiple zap.
48 *
49 * Revision 6.2 83/08/23 18:06:37 lwall
50 * Added zap command.
51 * Warp -s should now work on dumb terminals
52 * Specifying difficulty >= 40 now just makes it a special game.
53 * SIGTTOU #ifdef'ed.
54 * No-delay read provided as alternative to FIONREAD.
55 * Warp won't report "-1 obsolete" when there are no Enterprises left.
56 * Some high-difficulty tuning.
57 *
58 * Revision 6.1 83/08/17 08:49:03 lwall
59 * Fixed obscure bug in storing UP that caused a %. in CM to occasionally
60 * foist garbage onto the screen.
61 *
62 * Revision 6.0 83/08/08 17:09:26 lwall
63 * New baseline version for net release.
64 *
65 * Revision 5.5 83/08/01 10:59:56 lwall
66 * Cloaking for the Enterprise.
67 * Difficulty now goes to 99, and many activities depending on difficulty
68 * have been adjusted in frequency.
69 * Simplified exit sequence, and reduced dependencies on control
70 * characters. You needn't see the scoreboard if you don't want to.
71 * Hitting i,w,c, or v switches to Enterprise. Hitting p switches to Base.
72 * Excessive use of q is not allowed.
73 * Excessive use of D is not allowed.
74 * Scoreboard may depend on either full name or login name.
75 * Integrated scoreboard lister. Login name now shows up on scoreboard.
76 * "Hidden" startup options are now upper case.
77 * Checks upon startup for no cursor movement, or screen too small.
78 * Checks upon startup that WARPDIR is correctly protected, and that warp
79 * is running setuid. As an additional bonus this prevents root from
80 * running warp, which mucks things up, UN*X be blessed.
81 * All gets's turned into fgets's for safety.
82 * Bonus Enterprises and Bases.
83 * Escalating bonuses for saving Base and Enterprise.
84 * Escalating Enterprise energy.
85 * Turbolasers decrease with distance.
86 * Really smart enemies can see through stars occasionally.
87 * Occasional Tholian jackpot waves. Tholians are a trifle nastier.
88 * Choleric Gorns.
89 * An O or o can miss seeing you. Enemies can avoid a stationary O, o, or X.
90 * Warp 3 enemies and other nastinesses are possible in massacre mode.
91 * Enemies that decide to navigate when they see you can do other things than
92 * just come toward you.
93 * Gorns occasionally launch a salvo for the fun of it.
94 * Only star and enemy explosions can keep the round going now.
95 * Bounces don't always go back to starting spot now.
96 * Better full name processing. USG quirks handled. & substitution also
97 * handled now (whoever dreamed up that one must have been in the middle
98 * of the night before the morning after).
99 * Catch ^D on fgets.
100 * Version number printer.
101 * Less signal catching during debugging.
102 *
103 * Revision 5.4 83/06/24 09:28:38 lwall
104 * 16 bit random number generators are now supported.
105 * Made warp not blow up on a null save file.
106 * Warp now prints E and B before the stars.
107 * Fixed bug which caused torp count to get decremented even when no torp
108 * was launched because of an obstacle.
109 * Put %<n>ld formats where appropriate.
110 * Fixed E: 0 0 bug on refresh.
111 *
112 * Revision 5.3 83/05/24 14:03:10 lwall
113 * Starting RCS
114 *
115 */
116
117 #include "INTERN.h"
118 #include "warp.h"
119 #include "EXTERN.h"
120 #include "bang.h"
121 #include "init.h"
122 #include "intrp.h"
123 #include "object.h"
124 #include "move.h"
125 #include "play.h"
126 #include "score.h"
127 #include "sig.h"
128 #include "term.h"
129 #include "them.h"
130 #include "us.h"
131 #include "util.h"
132 #include "version.h"
133 #include "weapon.h"
134
135 int
136 main(int argc, char *argv[])
137 {
138 char tmp, *s, *tcbuf;
139
140 FILE *savfil;
141
142 #if RANDBITS > 16
143 for (i=100; i; i--)
144 if (rand() >= 65536)
145 goto rand_ok;
146 printf("Recompile with RANDBITS = 15 or 16.\n");
147 exit(1);
148 #else
149 #if RANDBITS > 15
150 for (i=100; i; i--) {
151 if (rand() >= 32768)
152 goto rand_ok;
153 }
154 printf("Recompile with RANDBITS = 15.\n");
155 exit(1);
156 #endif
157 #endif
158
159 #ifdef lint /* to suppress "defined but never used" */
160 # ifdef SIGTSTP
161 (void)stop_catcher();
162 # endif
163 # ifdef SIGCONT
164 (void)cont_catcher();
165 # endif
166 #endif
167
168 while (--argc > 0 && (*++argv)[0] == '-')
169 for (s = argv[0]+1; *s != '\0'; s++)
170 switch (*s) {
171 case '&':
172 amoebaspec = true;
173 beginner = true;
174 break;
175 case 'A':
176 apolspec = true;
177 beginner = true;
178 break;
179 case 'b':
180 beginner = true;
181 break;
182 case 'C':
183 crushspec = true;
184 beginner = true;
185 break;
186 case 'D':
187 debugging = true;
188 #ifdef DEBUGGING
189 debug = atoi(++s);
190 #endif
191 s += strlen(s)-1;
192 break;
193 case 'd':
194 s++;
195 if (*s == '=') s++;
196 ismarts = atoi(s);
197 if (ismarts <= 0)
198 ismarts = 1;
199 if (ismarts > 99)
200 ismarts = 99;
201 if (ismarts > 40)
202 beginner = true;
203 s += strlen(s)-1;
204 break;
205 case 'E':
206 klingspec = true;
207 beginner = true;
208 s++;
209 if (*s == '=') s++;
210 inumenemies = atoi(s);
211 s += strlen(s)-1;
212 break;
213 case 'F':
214 friendspec = true;
215 beginner = true;
216 s++;
217 if (*s == '=') s++;
218 inumfriends = atoi(s);
219 s += strlen(s)-1;
220 break;
221 case 'G':
222 gornspec = true;
223 beginner = true;
224 break;
225 case 'l':
226 lowspeed = true;
227 break;
228 case 'm':
229 metakey = true;
230 break;
231 case 'M':
232 massacre = true;
233 break;
234 case 'P':
235 piratespec = true;
236 beginner = true;
237 s++;
238 if (*s == '=') s++;
239 inumpirates = atoi(s);
240 s += strlen(s)-1;
241 break;
242 case 'S':
243 prespec = true;
244 beginner = true;
245 s++;
246 if (*s == '=') s++;
247 if (*s)
248 prescene = atoi(s);
249 else
250 prescene = -1;
251 s += strlen(s)-1;
252 break;
253 case 'R':
254 romspec = true;
255 beginner = true;
256 break;
257 case '*':
258 starspec = true;
259 beginner = true;
260 s++;
261 if (*s == '=') s++;
262 inumstars = atoi(s);
263 s += strlen(s)-1;
264 break;
265 case 's':
266 scorespec = true;
267 break;
268 case 'T':
269 tholspec = true;
270 beginner = true;
271 break;
272 case 'x':
273 experimenting = true;
274 break;
275 case 'v':
276 version();
277 exit(0);
278 break;
279 default:
280 fprintf(stderr,"warp: illegal option %c\n", *s);
281 fprintf(stderr, "Usage: warp -dn -b -x -v -s\n");
282 exit(1);
283 }
284 if (argc != 0) {
285 fprintf(stderr, "Usage: warp -dn -b -x -v -s\n");
286 exit(1);
287 }
288 bang_init();
289 move_init();
290 object_init();
291 play_init();
292 them_init();
293 us_init();
294 util_init();
295 weapon_init();
296
297 tcbuf = malloc(1024);
298 intrp_init(tcbuf);
299
300 if (chdir(warplib) < 0)
301 fprintf(stderr,NOCD,warplib);
302
303 term_init();
304
305 term_set(tcbuf);
306 free(tcbuf);
307
308 umask(022); /* mustn't rely on incoming umask--could be 033 which */
309 /* would disable people from running wscore */
310
311 score_init();
312
313 sig_init();
314
315 if (totalscore) {
316 clear();
317 mvaddstr(12,25,"*** restoring saved game ***");
318 roundsleep(1);
319 }
320
321 srand(getpid());
322
323 do {
324 for (keepgoing = true;;) {
325 if (!experimenting) {
326 if ((savfil = fopen(savefilename,"w")) == NULL) {
327 resetty();
328 printf("Can't open savefile\r\n");
329 finalize(1);
330 }
331 fprintf(savfil,
332 "%-8s %10ld, %2d,%5d,%2d,%2d,%3d %c%c%c%c%c%c%c%c%c\n",
333 logname, totalscore, smarts, cumsmarts,
334 numents, numbases, wave,
335 apolspec ? 'a' : ' ',
336 beginner ? 'b' : ' ',
337 crushspec ? 'c' : ' ',
338 gornspec ? 'g' : ' ',
339 massacre ? 'm' : ' ',
340 romspec ? 'r' : ' ',
341 tholspec ? 't' : ' ',
342 lowspeed ? 'l' : ' ',
343 amoebaspec ? '&' : ' '
344 );
345 fprintf(savfil," running on %s, process #%d\n",
346 term+5,getpid());
347 fclose(savfil);
348 }
349
350 lastscore = totalscore;
351 initialize();
352 play();
353 cumsmarts += smarts;
354 wavescore();
355 if (numents<=0 && numbases<=0)
356 keepgoing = false;
357 if (!keepgoing) break;
358 do {
359 if (experimenting) {
360 mvaddstr(23,15,
361 " [Hit space to continue, 'q' to quit] ");
362 }
363 else {
364 mvaddstr(23,15,
365 "[Hit space to continue, 's' to save, 'q' to quit]");
366 }
367 sleep(1);
368 fflush(stdout);
369 eat_typeahead();
370 getcmd(&tmp);
371 if (tmp == BREAKCH || tmp == INTRCH) {
372 mvaddstr(23,15,
373 " ");
374 mvaddstr(23,33,
375 "Really quit? ");
376 getcmd(&tmp);
377 if (tmp == 'y' || tmp == 'Y')
378 tmp = 'q';
379 else
380 tmp = 1;
381 }
382 } while (tmp != INTRCH && tmp != BREAKCH && !index(" qQs",tmp));
383 if (tmp != ' ' && tmp != 's') break;
384 if (!beginner && smarts < 20)
385 smarts += 4;
386 else if (!beginner && smarts < 35)
387 smarts += 2;
388 else if (smarts < 99)
389 smarts++;
390 if (tmp == 's') save_game();
391 }
392 score();
393
394 } while (justonemoretime);
395
396 if (!experimenting)
397 unlink(savefilename);
398
399 clear();
400 resetty();
401 exit(0);
402 }
403