score.c revision 1.3 1 /* Header: /usr/src/games/warp/RCS/score.c,v 1.1 87/07/03 02:13:26 games Exp */
2
3 /* Log: score.c,v
4 * Revision 7.0.1.2a 87/07/03 02:13:26 games
5 * Fixed numerous long vs. int bugs in printfs, etc.
6 *
7 * Revision 7.0.1.2 86/10/20 12:06:56 lwall
8 * Made all exits reset tty.
9 *
10 * Revision 7.0.1.1 86/10/16 10:52:47 lwall
11 * Added Damage. Fixed random bugs.
12 *
13 * Revision 7.0 86/10/08 15:13:14 lwall
14 * Split into separate files. Added amoebas and pirates.
15 *
16 */
17
18 #include "EXTERN.h"
19 #include "warp.h"
20 #include "intrp.h"
21 #include "object.h"
22 #include "play.h"
23 #include "sig.h"
24 #include "term.h"
25 #include "us.h"
26 #include "util.h"
27 #include "weapon.h"
28 #include "INTERN.h"
29 #include "score.h"
30
31 void
32 score_init()
33 {
34 Reg1 char *s;
35 Reg2 int i;
36 FILE *savfil;
37
38 #if 0
39 if (stat(SAVEDIR,&filestat)) {
40 printf("Cannot access %s\r\n",SAVEDIR);
41 finalize(1);
42 }
43 if (filestat.st_uid != geteuid()) {
44 printf("Warp will not run right without being setuid.\r\n");
45 finalize(1);
46 }
47 if ((filestat.st_mode & 0605) != 0605) {
48 printf("%s is not protected correctly (must be u+rw o+rx).\r\n",SAVEDIR);
49 finalize(1);
50 }
51 #endif
52
53 #ifdef SCOREFULL
54 interp(longlognam, sizeof longlognam, "%N");
55 for (i=strlen(longlognam); i<24; i++)
56 longlognam[i] = ' '; /* make sure it is 24 long for strncmp */
57 longlognam[24] = '\0';
58 #else
59 interp(longlognam, sizeof longlognam, "%L");
60 for (i=strlen(longlognam); i<8; i++)
61 longlognam[i] = ' '; /* make sure it is 8 long for strncmp */
62 longlognam[8] = '\0';
63 #endif
64
65 if (scorespec)
66 wscore();
67
68 Sprintf(savefilename, "save.%s", logname);
69
70 savfil = experimenting ? NULL : fopen(savefilename,"r");
71 if (savfil != NULL && fgets(spbuf,100,savfil) != NULL) {
72 char tmpbuf[80];
73
74 spbuf[strlen(spbuf)-1] = '\0';
75 if (fgets(tmpbuf,80,savfil) != NULL) {
76 int processnum;
77
78 tmpbuf[strlen(tmpbuf)-1] = '\0';
79 printf("You seem to have left a game %s.\r\n",tmpbuf+9);
80 s = index(tmpbuf+9, ',');
81 *s = '\0';
82 processnum = atoi(s+11);
83 if (kill(processnum, SIGINT)) {
84 /* does process not exist? */
85 /* (warp ignores SIGINT) */
86 printf("\r\n\
87 That process does not seem to exist anymore, so you'll have to start the\r\n");
88 printf(
89 "last wave over.\r\n\n");
90 printf(
91 " [type anything to continue]");
92 Fflush(stdout);
93 eat_typeahead();
94 getcmd(tmpbuf);
95 if (*tmpbuf == INTRCH)
96 finalize(0);
97 printf("\r\n");
98 }
99 else {
100 if (strcmp(term+8,tmpbuf+23)) {
101 printf(
102 "That is not your current terminal--you are on %s.\r\n", term+5);
103 printf("\r\nYour options:\r\n");
104 printf(" 1) Exit and find the terminal it's running on\r\n");
105 }
106 else {
107 printf("\r\nYour options:\r\n");
108 printf(" 1) Exit and try to foreground it\r\n");
109 }
110 printf(" 2) Let me terminate the other game\r\n\n");
111 printf("What do you want to do? ");
112 Fflush(stdout);
113 eat_typeahead();
114 getcmd(tmpbuf);
115 printf("\r\n");
116 if (*tmpbuf == INTRCH)
117 finalize(0);
118 if (*tmpbuf == '1') {
119 printf(
120 "If you don't succeed, come back and do option 2 instead. Good luck.\r\n");
121 finalize(0);
122 }
123 printf(
124 "Ok, hang on a few moments \r\n");
125 Fclose(savfil);
126 if (kill(processnum, SIGQUIT)) {
127 printf("Unable to kill process #%d!\r\n",processnum);
128 roundsleep(2);
129 }
130 else {
131 #ifdef SIGCONT
132 kill(processnum, SIGCONT);
133 #endif
134 for (i=15; i; --i) {
135 sleep(1);
136 if (kill(processnum,SIGINT))
137 /* does process not exist? */
138 /* (warp ignores SIGINT) */
139 break;
140 }
141 didkill++;
142 }
143 savfil = fopen(savefilename,"r");
144 if (savfil != NULL) {
145 Fgets(spbuf,100,savfil);
146 }
147 }
148 }
149 }
150 else
151 savfil = NULL;
152 if (savfil == NULL) {
153 totalscore = smarts = cumsmarts = wave = 0;
154 numents = 5;
155 numbases = 3;
156 }
157 else {
158 totalscore = atol(spbuf+9);
159 smarts = atoi(spbuf+20);
160 cumsmarts = atoi(spbuf+24);
161 numents = atoi(spbuf+30);
162 numbases = atoi(spbuf+33);
163 wave = atoi(spbuf+36);
164 apolspec = (spbuf[40] == 'a');
165 beginner = (spbuf[41] == 'b');
166 crushspec = (spbuf[42] == 'c');
167 gornspec = (spbuf[43] == 'g');
168 massacre = (spbuf[44] == 'm');
169 romspec = (spbuf[45] == 'r');
170 tholspec = (spbuf[46] == 't');
171 lowspeed = (spbuf[47] == 'l') || lowspeed;
172 amoebaspec = (spbuf[48] == '&');
173 Fclose(savfil);
174 }
175
176 if (!ismarts) {
177 ismarts = 1;
178 clear();
179 page(NEWSFILE,FALSE);
180 if (smarts) {
181 printf("\r\nSaved game: SCORE DIFF CUMDIFF ENTERPRISES BASES WAVE");
182 printf("\r\n %7ld %2d %4d %1d %1d %3d",
183 totalscore,smarts,cumsmarts,numents,numbases,wave);
184 }
185 printf("\r\nWould you like instructions? ");
186 Fflush(stdout);
187 eat_typeahead();
188 getcmd(buf);
189 printf("\r\n");
190 if (*buf == INTRCH)
191 finalize(0);
192 if (*buf == 'Y' || *buf == 'y') {
193 page(HELPFILE,FALSE);
194 printf("\r\nWould you like to play easy games for a while? ");
195 Fflush(stdout);
196 eat_typeahead();
197 getcmd(buf);
198 printf("\r\n");
199 if (*buf == 'Y' || *buf == 'y') {
200 beginner = TRUE;
201 lowspeed = TRUE;
202 }
203 }
204 }
205 if (!smarts)
206 smarts = ismarts;
207 }
208
209 void
210 wscore()
211 {
212 clear();
213 printf(" TOP WARPISTS\r\n\n");
214 printf("RANK WHO AKA SCORE DIFF CUMDIFF WHEN\r\n");
215 page(SCOREBOARD,TRUE);
216 printf(" [Type anything to continue]");
217 Fflush(stdout);
218 getcmd(spbuf);
219 if (*spbuf == INTRCH)
220 finalize(0);
221 clear();
222 printf(" TOP LOW-SPEED WARPISTS\r\n\n");
223 printf("RANK WHO AKA SCORE DIFF CUMDIFF WHEN\r\n");
224 page(LSCOREBOARD,TRUE);
225 printf(" [Type anything to continue]");
226 Fflush(stdout);
227 getcmd(spbuf);
228 if (*spbuf == INTRCH)
229 finalize(0);
230 clear();
231 printf(" TOP FUNNY WARPISTS\r\n\n");
232 printf("RANK WHO AKA SCORE DIFF CUMDIFF WHEN\r\n");
233 page(FSCOREBOARD,TRUE);
234 printf(" [Type anything to continue]");
235 Fflush(stdout);
236 getcmd(spbuf);
237 if (*spbuf == INTRCH)
238 finalize(0);
239 clear();
240 printf(" GAMES SAVED OR IN PROGRESS\r\n\n");
241 printf("WHO SCORE DF CDF E B WV FLAGS\r\n");
242 resetty();
243 Sprintf(spbuf,"/bin/cat %ssave.*",SAVEDIR);
244 #ifndef lint
245 execl("/bin/sh", "sh", "-c", spbuf, 0);
246 #endif
247 finalize(1);
248 }
249
250
251 void
252 display_status()
253 {
254 Reg1 int tmp;
255 static char *status_names[] = {"Impl", "Warp", "Base", "****" };
256
257 if (oldstatus != status) {
258 Sprintf(spbuf,"%-4s",status_names[status]);
259 mvaddstr(0,0, spbuf);
260 oldstatus = status;
261 }
262 if (ent) {
263 if (ent->energy != oldeenergy) {
264 oldeenergy = ent->energy;
265 Sprintf(spbuf,"%4ld",oldeenergy);
266 mvaddstr(0,8, spbuf);
267 }
268 if (etorp != oldetorp) {
269 Sprintf(spbuf,"%2d",etorp);
270 mvaddstr(0,13, spbuf);
271 oldetorp = etorp;
272 }
273 }
274 else {
275 if (etorp >= 0) {
276 etorp = -1;
277 mvaddstr(0,8,"*******");
278 damage = 0;
279 }
280 }
281 if (base) {
282 if (base->energy != oldbenergy) {
283 oldbenergy = base->energy;
284 Sprintf(spbuf,"%5ld",oldbenergy);
285 mvaddstr(0,19, spbuf);
286 }
287 if (btorp != oldbtorp) {
288 Sprintf(spbuf,"%3d",btorp);
289 mvaddstr(0,25, spbuf);
290 oldbtorp = btorp;
291 }
292 }
293 else {
294 if (btorp >= 0) {
295 btorp = -1;
296 mvaddstr(0,19,"*********");
297 }
298 }
299 if (damage) {
300 if (!olddamage)
301 mvaddstr(0,42,"*** ");
302 if (damage > 1 || !damflag[dam]) {
303 do {
304 if (++dam == MAXDAMAGE)
305 dam = 0;
306 } while (!damflag[dam]);
307 }
308 if (!--damflag[dam]) {
309 olddamage = damage;
310 damage--;
311 Sprintf(spbuf,"%s OK *** ",dammess[dam]);
312 spbuf[15] = '\0';
313 mvaddstr(0,46,spbuf);
314 }
315 else if (dam == NOSHIELDS) {
316 olddamage = damage;
317 tmp = (34 - damflag[dam]) * 3 - rand_mod(3);
318 if (tmp < 0)
319 tmp = 0;
320 Sprintf(spbuf,"%d%% %s *** ",tmp,dammess[dam]);
321 spbuf[15] = '\0';
322 mvaddstr(0,46,spbuf);
323 }
324 else if (dam != lastdam || !olddamage) {
325 olddamage = damage;
326 Sprintf(spbuf,"NO %s *** ",dammess[dam]);
327 spbuf[15] = '\0';
328 mvaddstr(0,46,spbuf);
329 }
330 if (status < 2) {
331 if (dam == NOIMPULSE && !entmode)
332 status = entmode = 1;
333 if (dam == NOWARP && entmode)
334 status = entmode = 0;
335 }
336 tmp = damflag[dam] * damage;
337 Sprintf(spbuf,"%3d.%1d ETR",tmp/10,tmp%10);
338 mvaddstr(0,69,spbuf);
339 lastdam = dam;
340 }
341 else {
342 if (olddamage) {
343 Sprintf(spbuf,"Stars: %-3d Stardate",numstars);
344 mvaddstr(0,42,spbuf);
345 lastdam = -1;
346 olddamage = 0;
347 oldcurscore = -1;
348 }
349 else if (numstars != oldstrs) {
350 Sprintf(spbuf,"%-3d",numstars);
351 mvaddstr(0,49, spbuf);
352 }
353 oldstrs = numstars;
354 }
355 if (numenemies != oldenemies) {
356 Sprintf(spbuf,"%-3d",numenemies);
357 mvaddstr(0,38, spbuf);
358 oldenemies = numenemies;
359 }
360 if (tmp = timer%10) {
361 Sprintf(spbuf,"%1d",tmp);
362 mvaddstr(0,67, spbuf);
363 }
364 else {
365 Sprintf(spbuf,"%5d.%1d",timer/10+smarts*100,tmp);
366 mvaddstr(0,61, spbuf);
367 }
368 if ((!damage || !damflag[dam]) && curscore != oldcurscore) {
369 Sprintf(spbuf,"%9ld",curscore);
370 mvaddstr(0,69, spbuf);
371 oldcurscore = curscore;
372 }
373 }
374
375 void
376 wavescore()
377 {
378 double power, effectscore, starscore, pi_over_2;
379 long bonuses;
380 long tmp;
381 FILE *mapfp;
382 int row;
383 double pow();
384 #ifndef lint
385 double atan2();
386 #endif
387
388 clear();
389 if (curscore > possiblescore)
390 curscore = possiblescore;
391 pi_over_2 = 3.14159265 / 2.0;
392 power = pow((double)inumenemies+ /* total number of enemies */
393 inumroms*2+ /* count roms 3 times */
394 inumgorns+ /* count gorns 2 times */
395 inumthols+ /* count thols 2 times */
396 inumapollos*4+ /* count apollo 5 times */
397 inumcrushes*3+ /* count crushers 4 times */
398 inumamoebas*5 /* count amoebas 6 times */
399 , 0.50) * /* skew it a little */
400 (double)smarts; /* average energy and intelligence */
401 if (inumstars < 350 && inumenemies > 5)
402 power += (350.0 - (double)inumstars) * ((double)inumenemies - 5.0);
403 if (inumstars > 850 && inumenemies > 2)
404 power += ((double)inumstars - 850.0) * ((double)inumenemies - 2.0);
405 #ifndef lint
406 effectscore = ((double)curscore / possiblescore) *
407 atan2(power, (double) timer + 1.0) / pi_over_2;
408 #else
409 effectscore = pi_over_2;
410 #endif
411 if (inumstars)
412 starscore = (double) numstars / (double) inumstars;
413 else
414 starscore = 1.0;
415 wave++;
416 Sprintf(spbuf,"Wave = %d, Difficulty = %d, cumulative difficulty = %d",
417 wave, smarts, cumsmarts);
418 mvaddstr(1, 13+(smarts<10), spbuf);
419 mvaddstr( 4, 68, " BONUS");
420 Sprintf(spbuf,"Efficiency rating: %1.8f (diff=%0.2f,time=%d)",
421 effectscore, power, timer + 1);
422 mvaddstr( 5,5, spbuf);
423 if (effectscore < 0.8)
424 bonuses = tmp = 0;
425 else
426 bonuses = tmp = (long) ((effectscore-0.8) * smarts * 1000);
427 Sprintf(spbuf, "%6ld", tmp);
428 mvaddstr( 5, 68, spbuf);
429 Sprintf(spbuf,"Star save ratio: %1.8f (%d/%d)",
430 starscore, numstars, inumstars);
431 mvaddstr( 6,5, spbuf);
432 #ifndef lint
433 bonuses += tmp = (long) (((double)curscore / possiblescore) *
434 (starscore*starscore) * smarts * 20);
435 #endif
436 Sprintf(spbuf, "%6ld", tmp);
437 mvaddstr( 6, 68, spbuf);
438 row = 7;
439 if (inuminhab != numinhab) {
440 Sprintf(spbuf, "Inhabited stars depopulated: %5d", inuminhab-numinhab);
441 mvaddstr(row,5, spbuf);
442 bonuses += tmp = (long) (inuminhab-numinhab) * -500;
443 Sprintf(spbuf, "%6ld", tmp);
444 mvaddstr(row, 68, spbuf);
445 row++;
446 }
447 if (inumfriends != numfriends) {
448 Sprintf(spbuf, "Friendly craft destroyed: %5d",
449 inumfriends-numfriends);
450 mvaddstr(row,5, spbuf);
451 bonuses += tmp = (long) (inumfriends-numfriends) * -250;
452 Sprintf(spbuf, "%6ld", tmp);
453 mvaddstr(row, 68, spbuf);
454 row++;
455 }
456 if (deadmudds) {
457 mvaddstr(row,5,"For destroying Harry Mudd:");
458 bonuses += tmp = (long) rand_mod(deadmudds * 20 + 1) - deadmudds*10;
459 Sprintf(spbuf, "%6ld", tmp);
460 mvaddstr(row, 68, spbuf);
461 row++;
462 }
463 if (bombed_out) {
464 mvaddstr(row,5, "For running away from reality:");
465 bonuses += tmp = (long) -possiblescore/2;
466 Sprintf(spbuf, "%6ld", tmp);
467 mvaddstr(row, 68, spbuf);
468 row++;
469 }
470 if (row < 9)
471 row++;
472 Sprintf(spbuf, "Enterprise: %-9s%5d remaining",
473 !ient?"":ent?"saved":"destroyed", numents);
474 mvaddstr(row,5, spbuf);
475 bonuses += tmp = ent && !bombed_out ? (smarts+1)*15 : 0;
476 Sprintf(spbuf, "%6ld", tmp);
477 mvaddstr(row, 68, spbuf);
478 row++;
479 Sprintf(spbuf, "Base: %-9s %5d remaining",
480 !ibase?"":base?"saved":"destroyed", numbases);
481 mvaddstr(row,5, spbuf);
482 bonuses += tmp = base && !bombed_out ? (smarts+1)*10 : 0;
483 Sprintf(spbuf, "%6ld", tmp);
484 mvaddstr(row, 68, spbuf);
485 if (beginner) {
486 mvaddstr(13+(row>11),19, "(Special games count only a tenth as much)");
487 curscore /= 10;
488 bonuses /= 10;
489 }
490 Sprintf(spbuf, "Previous point total:%10ld",lastscore);
491 mvaddstr(15,24, spbuf);
492 Sprintf(spbuf, "Points this round: %10ld",curscore);
493 mvaddstr(16,24, spbuf);
494 Sprintf(spbuf, "Bonuses: %10ld",bonuses);
495 mvaddstr(17,24, spbuf);
496 totalscore = lastscore + curscore + bonuses;
497 Sprintf(spbuf, "New point total: %10ld",totalscore);
498 mvaddstr(18,24, spbuf);
499 if (lastscore / ENTBOUNDARY < totalscore / ENTBOUNDARY) {
500 mvaddstr(row-1,42,"+ 1 new");
501 numents++;
502 }
503 else if (numents>0 &&
504 lastscore / ENTBOUNDARY > totalscore / ENTBOUNDARY) {
505 mvaddstr(row-1,42,"- 1 obsolete");
506 numents--;
507 }
508 if (lastscore / BASEBOUNDARY < totalscore / BASEBOUNDARY) {
509 mvaddstr(row,42,"+ 1 new");
510 numbases++;
511 }
512 else if (numbases>0 &&
513 lastscore / BASEBOUNDARY > totalscore / BASEBOUNDARY) {
514 mvaddstr(row,42,"- 1 obsolete");
515 numbases--;
516 }
517 if (starscore < 0.8 && inumstars > 200 && numstars > 50) {
518 Sprintf(spbuf, "smap.%d",rand_mod(MAPS-PERMMAPS)+PERMMAPS);
519 if ((mapfp = fopen(spbuf,"w")) != NULL) {
520 Reg1 OBJECT *obj;
521
522 fprintf(mapfp,"%d\n",numstars);
523 for (obj = root.next; obj != &root; obj = obj->next) {
524 if (obj->type == Star) {
525 fprintf(mapfp,"%d %d\n",obj->posy,obj->posx);
526 }
527 }
528 Fclose(mapfp);
529 }
530 }
531 }
532
533 void
534 score()
535 {
536 char tmp, *retval, cdate[30];
537 Reg1 FILE *logfd;
538 Reg2 FILE *outfd;
539 Reg3 int i;
540 time_t nowtime;
541 char *scoreboard;
542
543 for (i=0; link(LOGFILE, LOCKFILE) == -1 && i<10; i++)
544 sleep(1);
545 nowtime = time(NULL);
546 strcpy(cdate,ctime(&nowtime));
547 if ((logfd = fopen(LOGFILE,"a")) != NULL) {
548 fprintf(logfd,
549 "%-24s%-9s%7ld%c%2d %4d %s",
550 realname, logname, totalscore, c,smarts, cumsmarts, cdate);
551 Fclose(logfd);
552 }
553 strcpy(cdate+11,cdate+20);
554 if (beginner)
555 scoreboard = FSCOREBOARD;
556 else if (lowspeed)
557 scoreboard = LSCOREBOARD;
558 else
559 scoreboard = SCOREBOARD;
560 if (eaccess(scoreboard,0)) {
561 if ((logfd = fopen(scoreboard,"w")) != NULL)
562 Fclose(logfd);
563 }
564 if ((logfd = fopen(scoreboard,"r")) != NULL &&
565 (outfd = fopen(TMPSCOREBOARD,"w")) != NULL) {
566 for (i=0; i<20; i++) {
567 if ((retval = fgets(buf, 100, logfd)) == NULL)
568 break;
569 if (atol(buf+32) < totalscore)
570 break;
571 if (strnEQ(buf+COMPOFF,COMPNAME,COMPLEN)) {
572 i = 100;
573 break;
574 }
575 fprintf(outfd, "%s", buf);
576 }
577 if (i == 100) {
578 mvaddstr(20,21, "You did not better your previous score");
579 Fclose(outfd);
580 unlink(TMPSCOREBOARD);
581 }
582 else if (i < 20) {
583 fprintf(outfd, "%-24s%-8s%8ld%c %2d %4d %s",
584 realname, logname, totalscore, c,smarts, cumsmarts, cdate);
585 i++;
586 Sprintf(spbuf, " Congratulations--you've placed %d%s",
587 i, i==1?"st":(i==2?"nd":(i==3?"rd":"th")));
588 if (retval != NULL) {
589 if (strnNE(buf+COMPOFF,COMPNAME,COMPLEN)) {
590 fprintf(outfd, "%s", buf);
591 i++;
592 }
593 else
594 strcpy(spbuf,"Congratulations--you've bettered your score");
595 while (i<20) {
596 if (fgets(buf, 100, logfd) == NULL)
597 break;
598 if (strnNE(buf+COMPOFF,COMPNAME,COMPLEN)) {
599 fprintf(outfd, "%s", buf);
600 i++;
601 }
602 }
603 }
604 mvaddstr(20,19, spbuf);
605 Fclose(logfd);
606 Fclose(outfd);
607 while (unlink(scoreboard) == 0)
608 ;
609 link(TMPSCOREBOARD,scoreboard);
610 unlink(TMPSCOREBOARD);
611 logfd = fopen(scoreboard,"r");
612 }
613 else {
614 mvaddstr(20,22,"You did not place within the top 20");
615 Fclose(outfd);
616 }
617 }
618 else {
619 Sprintf(spbuf,"(Cannot access %s file, error %d)",
620 (logfd==NULL?"log":"tmp"),errno);
621 mvaddstr(20,22,spbuf);
622 }
623 move(23,0,0);
624 erase_eol();
625 mvaddstr(23,11,
626 "[Hit space for scoreboard, 'r' for new game, 'q' to quit]");
627 unlink(LOCKFILE);
628 Fflush(stdout);
629 eat_typeahead();
630 do {
631 getcmd(&tmp);
632 } while (tmp != INTRCH && tmp != BREAKCH && !index(" rqQ",tmp));
633 if (index("qQr",tmp)) {
634 justonemoretime = (tmp == 'r');
635 if (logfd != NULL)
636 Fclose(logfd);
637 }
638 else {
639 clear();
640 if (logfd != NULL) {
641 fseek(logfd, 0L, 0);
642 if (beginner)
643 mvaddstr(0,31,"TOP FUNNY WARPISTS");
644 else if (lowspeed)
645 mvaddstr(0,29,"TOP LOW-SPEED WARPISTS");
646 else
647 mvaddstr(0,33,"TOP WARPISTS");
648 mvaddstr(2,0,"RANK WHO AKA SCORE DIFF CUMDIFF WHEN");
649 for (i=1; i<=20; i++) {
650 if (fgets(buf, 100, logfd) == NULL)
651 break;
652 buf[strlen(buf)-1] = '\0';
653 Sprintf(spbuf, " %2d %s", i, buf);
654 mvaddstr(i+2,0, spbuf);
655 }
656 Fclose(logfd);
657 }
658 roundsleep(1);
659 mvaddstr(23,25,"Would you like to play again?");
660 eat_typeahead();
661 do {
662 getcmd(&tmp);
663 } while (tmp != INTRCH && tmp != BREAKCH && !index("nNyY \n\r",tmp));
664 if (tmp == 'n' || tmp == 'N' || tmp == INTRCH || tmp == BREAKCH)
665 justonemoretime = FALSE;
666 }
667
668 smarts = ismarts;
669 totalscore = cumsmarts = wave = 0;
670 numents = 5;
671 numbases = 3;
672 apolspec = FALSE;
673 beginner = FALSE;
674 crushspec = FALSE;
675 gornspec = FALSE;
676 massacre = (ismarts >= 40);
677 romspec = FALSE;
678 tholspec = FALSE;
679 }
680
681 void
682 save_game()
683 {
684 FILE *savfil;
685
686 if (experimenting)
687 return;
688 if ((savfil = fopen(savefilename,"w")) == NULL) {
689 resetty();
690 printf("Cannot save game\r\n");
691 finalize(1);
692 }
693 fprintf(savfil, "%-8s %10ld, %2d,%5d,%2d,%2d,%3d %c%c%c%c%c%c%c%c\n",
694 logname, totalscore, smarts, cumsmarts, numents, numbases, wave,
695 apolspec ? 'a' : ' ',
696 beginner ? 'b' : ' ',
697 crushspec ? 'c' : ' ',
698 gornspec ? 'g' : ' ',
699 massacre ? 'm' : ' ',
700 romspec ? 'r' : ' ',
701 tholspec ? 't' : ' ',
702 lowspeed ? 'l' : ' ',
703 amoebaspec ? '&' : ' '
704 );
705 Fclose(savfil);
706 resetty();
707 if (panic)
708 finalize(0);
709 clear();
710 finalize(0);
711 }
712