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