1: /* 2: * func2.c Phantasia support routines 3: */ 4: 5: #include "phant.h" 6: 7: void decree(stat) /* king and valar stuff */ 8: reg struct stats *stat; 9: { 10: FILE *fp; 11: short arg; 12: char aline[80], *cp; 13: struct stats sbuf; 14: struct nrgvoid vbuf; 15: double temp1 = 0.0, temp2 = 0.0; 16: int ch; 17: reg int loc = 0; 18: 19: move(3,0); 20: clrtoeol(); 21: if (stat->typ < 20 && !su) /* king */ 22: { 23: addstr("1:Transport 2:Curse 3:Energy Void 4:Bestow 5:Collect Taxes "); 24: ch = rgetch(); 25: move(3,0); 26: clrtoeol(); 27: switch (ch) 28: { 29: case '1': 30: arg = TRANSPORT; 31: cp = "transport"; 32: break; 33: case '2': 34: arg = CURSED; 35: cp = "curse"; 36: break; 37: case '3': 38: addstr("Enter the X Y coordinates of void ? "); 39: getstring(aline,30); 40: sscanf(aline,"%F %F",&temp1,&temp2); 41: vbuf.x = floor(temp1); 42: vbuf.y = floor(temp2); 43: vbuf.active = TRUE; 44: voidupdate(&vbuf,allocvoid()); 45: goto EXIT; 46: case '4': 47: arg = GOLD; 48: addstr("How much gold to bestow ? "); 49: temp1 = inflt(); 50: if (temp1 > stat->gld || temp1 < 0) 51: { 52: mvaddstr(6,0,"You don't have that !\n"); 53: return; 54: } 55: stat->gld -= floor(temp1); 56: cp = "give gold to"; 57: break; 58: case '5': 59: fp = fopen(goldfile,"r"); 60: fread((char *) &temp1,sizeof(double),1,fp); 61: fclose(fp); 62: mvprintw(6,0,"You have collected %.0f in gold.\n",temp1); 63: stat->gld += floor(temp1); 64: fp = fopen(goldfile,"w"); 65: temp1 = 0.0; 66: fwrite((char *) &temp1,sizeof(double),1,fp); 67: fclose(fp); 68: return; 69: default: 70: return; 71: } 72: } 73: else /* council of wise, valar, etc. */ 74: { 75: addstr("1:Heal "); 76: if (stat->pal || su) 77: addstr("2:Seek Grail "); 78: if (stat->typ == 99 || su) 79: addstr("3:Throw Monster 4:Relocate 5:Bless "); 80: if (su) 81: addstr("6:Vaporize "); 82: ch = rgetch(); 83: if (!su && ch > '2' && stat->typ != 99) 84: { 85: illcmd(); 86: return; 87: } 88: switch (ch) 89: { 90: case '1': 91: arg = HEAL; 92: cp = "heal"; 93: break; 94: case '2': 95: if (stat->pal) 96: { 97: fp = fopen(voidfile,"r"); 98: fread((char *) &vbuf,sizeof(vbuf),1,fp); 99: fclose(fp); 100: temp1 = hypot(stat->x - vbuf.x,stat->y - vbuf.y); 101: temp1 = floor(temp1 + roll(-temp1/10.0,temp1/5.0)); 102: mvprintw(6,0,"The palantir says the Grail is about %.0f away.\n",temp1); 103: return; 104: } 105: else 106: { 107: mvaddstr(6,0,"You need a palantir to seek the Grail.\n"); 108: return; 109: } 110: case '3': 111: mvaddstr(3,0,"Which monster [0-99] ? "); 112: temp1 = inflt(); 113: temp1 = max(0,min(99,temp1)); 114: cp = "throw a monster at"; 115: arg = MONSTER; 116: break; 117: case '4': 118: mvaddstr(3,0,"New X Y coordinates ? "); 119: getstring(aline,30); 120: sscanf(aline,"%F %F",&temp1,&temp2); 121: cp = "relocate"; 122: arg = MOVED; 123: break; 124: case '5': 125: arg = BLESS; 126: cp = "bless"; 127: break; 128: case '6': 129: if (su) 130: { 131: cp = "vaporize"; 132: arg = VAPORIZED; 133: break; 134: } 135: default: 136: return; 137: } 138: } 139: mvprintw(3,0,"Who do you want to %s ? ",cp); 140: getstring(aline,21); 141: trunc(aline); 142: if (strcmp(stat->name,aline)) 143: { 144: fp = fopen(peoplefile,"r"); 145: while (fread((char *) &sbuf,sizeof(sbuf),1,fp)) 146: if (strcmp(aline,sbuf.name)) 147: ++loc; 148: else 149: { 150: fclose(fp); 151: if (sbuf.tampered) 152: { 153: mvaddstr(6,0,"That person has something pending already.\n"); 154: return; 155: } 156: else 157: { 158: sbuf.tampered = arg; 159: sbuf.scratch1 = floor(temp1); 160: sbuf.scratch2 = floor(temp2); 161: update(&sbuf,loc); 162: EXIT: mvaddstr(6,0,"It is done.\n"); 163: return; 164: } 165: } 166: fclose(fp); 167: mvaddstr(6,0,"There is no one by that name.\n"); 168: } 169: else 170: mvaddstr(6,0,"You may not do it to yourself!\n"); 171: } 172: 173: void checktampered(stat) /* see if decree'd etc. */ 174: reg struct stats *stat; 175: { 176: struct nrgvoid vbuf; 177: struct stats sbuf; 178: FILE *fp; 179: reg int loc = 0; 180: 181: /* first check for energy voids */ 182: fp = fopen(voidfile,"r"); 183: while (fread((char *) &vbuf,sizeof(vbuf),1,fp)) 184: if (vbuf.active && vbuf.x == stat->x && vbuf.y == stat->y) 185: { 186: fclose(fp); 187: if (loc) 188: { 189: vbuf.active = FALSE; 190: voidupdate(&vbuf,loc); 191: tampered(stat,NRGVOID,&sbuf); 192: } 193: else if (stat->status != CLOAKED) 194: tampered(stat,GRAIL,&sbuf); 195: break; 196: } 197: else 198: ++loc; 199: fclose(fp); 200: /* now check for other things */ 201: statread(&sbuf,fileloc); 202: if (sbuf.tampered) 203: tampered(stat,sbuf.tampered,&sbuf); 204: } 205: 206: void voidupdate(vp,loc) /* update an energy void */ 207: reg struct nrgvoid *vp; 208: reg int loc; 209: { 210: FILE *fp; 211: 212: fp = fopen(voidfile,ACCESS); 213: fseek(fp,(long) loc*sizeof(*vp),0); 214: fwrite((char *) vp,sizeof(*vp),1,fp); 215: fclose(fp); 216: } 217: 218: int allocvoid() /* find a space to put an energy void */ 219: { 220: FILE *fp; 221: reg int loc = 0; 222: struct nrgvoid vbuf; 223: 224: fp = fopen(voidfile,"r"); 225: while (fread((char *) &vbuf,sizeof(vbuf),1,fp)) 226: if (vbuf.active) 227: ++loc; 228: else 229: { 230: fclose(fp); 231: return (loc); 232: } 233: fclose(fp); 234: return (loc); 235: } 236: 237: void statread(stat,loc) /* read a charac. structure */ 238: reg struct stats *stat; 239: reg int loc; 240: { 241: FILE *fp; 242: 243: fp = fopen(peoplefile,"r"); 244: fseek(fp,(long) loc * sizeof(*stat),0); 245: fread((char *) stat,sizeof(*stat),1,fp); 246: fclose(fp); 247: } 248: 249: void tampered(stat,what,bufp) /* decree'd, intervened, etc. */ 250: reg struct stats *stat, *bufp; 251: short what; 252: { 253: struct nrgvoid vbuf; 254: reg int loc; 255: struct stats sbuf; 256: FILE *fp; 257: 258: changed = TRUE; 259: move(6,0); 260: stat->tampered = OFF; 261: switch ((int) what) 262: { 263: case NRGVOID: 264: addstr("You've hit an energy void !\n"); 265: stat->man /= 3; 266: stat->nrg /= 2; 267: stat->gld = floor(stat->gld/1.25) + 0.1; 268: stat->x += 10; 269: break; 270: case TRANSPORT: 271: addstr("The king transported you ! "); 272: if (stat->chm) 273: { 274: addstr("But your charm save you. . .\n"); 275: --stat->chm; 276: } 277: else 278: { 279: stat->x += roll(-50,100) * circ(stat->x,stat->y); 280: stat->y += roll(-50,100) * circ(stat->x,stat->y); 281: addch('\n'); 282: } 283: break; 284: case GOLD: 285: printw("The king has bestowed %.0f gold pieces on you !\n",bufp->scratch1); 286: stat->gld += bufp->scratch1; 287: break; 288: case CURSED: 289: addstr("You've been cursed ! "); 290: if (stat->bls) 291: { 292: addstr("But your blessing saved you. . .\n"); 293: stat->bls = FALSE; 294: } 295: else 296: { 297: addch('\n'); 298: stat->psn += 2; 299: stat->nrg = 10; 300: stat->mxn *= 0.95; 301: stat->status = PLAYING; 302: } 303: break; 304: case VAPORIZED: 305: addstr("Woops! You've been vaporized!\n"); 306: death(stat); 307: break; 308: case MONSTER: 309: addstr("The Valar zapped you with a monster!\n"); 310: paws(7); 311: fight(stat,(int) bufp->scratch1); 312: return; 313: case BLESS: 314: addstr("The Valar has blessed you!\n"); 315: stat->nrg = (stat->mxn *= 1.05) + stat->shd; 316: stat->man += 500; 317: stat->str += 0.5; 318: stat->brn += 0.5; 319: stat->mag += 0.5; 320: stat->psn = min(0.5,stat->psn); 321: break; 322: case MOVED: 323: addstr("You've been relocated. . .\n"); 324: stat->x = bufp->scratch1; 325: stat->y = bufp->scratch2; 326: break; 327: case HEAL: 328: addstr("You've been healed!\n"); 329: stat->psn -= 0.25; 330: stat->nrg = stat->mxn + stat->shd; 331: break; 332: case STOLEN: 333: addstr("You'Ve been bumped off as Valar!\n"); 334: stat->typ = 20 + roll(1,6); 335: break; 336: case GRAIL: 337: addstr("You have found The Holy Grail!!\n"); 338: if (stat->typ < 20) 339: { 340: addstr("However, you are not experienced enough to behold it.\n"); 341: stat->sin *= stat->sin; 342: stat->man += 1000; 343: } 344: else if (stat->typ == 99 || stat->typ == 90) 345: { 346: addstr("You have made it to the position of Valar once already.\n"); 347: addstr("The Grail is of no more use to you now.\n"); 348: } 349: else 350: { 351: addstr("It is now time to see if you are worthy to behold it. . .\n"); 352: refresh(); 353: sleep(4); 354: if (rnd() / 2.0 < stat->sin) 355: { 356: addstr("You blew this one!\n"); 357: stat->str = stat->man = stat->quk = stat->nrg = stat->mxn = stat->x = stat->y = 358: stat->mag = stat->brn = stat->exp =1; 359: stat->lvl = 0; 360: } 361: else 362: { 363: addstr("You made to position of Valar!\n"); 364: stat->typ = 99; 365: fp = fopen(peoplefile,"r"); 366: loc = 0; 367: while (fread((char *) &sbuf,sizeof(sbuf),1,fp)) 368: if (sbuf.typ == 99) 369: { 370: sbuf.tampered = STOLEN; 371: update(&sbuf,loc); 372: break; 373: } 374: else 375: ++loc; 376: fclose(fp); 377: } 378: } 379: vbuf.active = TRUE; 380: vbuf.x = roll(-1e6,2e6); 381: vbuf.y = roll(-1e6,2e6); 382: voidupdate(&vbuf,0); 383: break; 384: } 385: } 386: 387: void adjuststats(stat) /* make sure things are within limits, etc. */ 388: reg struct stats *stat; 389: { 390: long ltemp; 391: reg int temp; 392: stat->x = floor(stat->x); 393: stat->y = floor(stat->y); 394: valhala = (stat->typ == 99); 395: throne = (stat->x == 0.0 && stat->y == 0.0); 396: temp = abs(stat->x)/400; 397: if (temp > 16) 398: temp = 0; 399: if (stat->y == 0.0 && !throne && !valhala && temp == abs(stat->x)/400 && sgn(stat->x) == (int) pow(-1.0, (double) temp)) 400: { 401: if (!wmhl) 402: stat->wormhole = temp; 403: wmhl = TRUE; 404: } 405: else 406: wmhl = FALSE; 407: speed = stat->quk + stat->quks - spdcalc(stat->lvl,stat->gld,stat->gem); 408: strength = stat->str + stat->swd - strcalc(stat->str,stat->psn); 409: time(<emp); 410: stat->age += ltemp - secs; 411: secs = ltemp; 412: stat->quks = min(99,stat->quks); 413: stat->man = min(stat->man,stat->lvl*15 + 5000); 414: stat->chm = min(stat->chm,stat->lvl + 10); 415: stat->typ = (stat->crn && stat->typ < 10) ? -abs(stat->typ) : abs(stat->typ); 416: if (level(stat->exp) > stat->lvl) 417: movelvl(stat); 418: stat->gld = floor(stat->gld) + 0.1; 419: stat->gem = floor(stat->gem) + 0.1; 420: if (stat->rng.type) 421: stat->nrg = stat->mxn + stat->shd; 422: if (stat->rng.type && stat->rng.duration <= 0) /* clean up rings */ 423: switch (stat->rng.type) 424: { 425: case DLBAD: 426: case NAZBAD: 427: stat->rng.type = SPOILED; 428: stat->rng.duration = roll(10,25); 429: break; 430: case NAZREG: 431: stat->rng.type = NONE; 432: break; 433: case SPOILED: 434: death(stat); 435: break; 436: } /* DLREG is ok, so do nothing with it */ 437: stat->nrg += (stat->mxn+stat->shd)/15+stat->lvl/3+2; 438: stat->nrg = min(stat->nrg,stat->mxn + stat->shd); 439: if (stat->age > stat->degen * 2500) 440: { 441: ++stat->degen; 442: if (stat->quk > 23) 443: --stat->quk; 444: stat->str *= 0.97; 445: stat->brn *= 0.95; 446: stat->mag *= 0.97; 447: stat->mxn *= 0.95; 448: if (stat->quks) 449: --stat->quks; 450: stat->swd *= 0.93; 451: stat->shd *= 0.95; 452: } 453: } 454: 455: void checkinterm(stat) /* see if other person on same x,y */ 456: reg struct stats *stat; 457: { 458: FILE *fp; 459: struct stats sbuf; 460: reg int foeloc = 0; 461: 462: users = 0; 463: fp = fopen(peoplefile,"r"); 464: while (fread((char *) &sbuf,sizeof(sbuf),1,fp)) 465: { 466: if (sbuf.status && (sbuf.status != CLOAKED || sbuf.typ != 99)) 467: { 468: ++users; 469: if (stat->x == sbuf.x && stat->y == sbuf.y 470: && foeloc != fileloc && sbuf.typ != 99 471: && stat->typ !=99 && !stat->wormhole && !sbuf.wormhole) 472: { 473: fclose(fp); 474: interm(stat,foeloc); 475: return; 476: } 477: } 478: ++foeloc; 479: } 480: fclose(fp); 481: } 482: 483: int gch(rngtyp) /* get a character from terminal, but check ring if crazy */ 484: short rngtyp; 485: { 486: refresh(); 487: if (abs(rngtyp) != SPOILED) 488: return (getch()); 489: else 490: { 491: getch(); 492: return (roll(0,5) + '0'); 493: } 494: } 495: 496: int rngcalc(chartyp) /* pick a duration of a ring */ 497: short chartyp; 498: { 499: static int rngtab[] = { 0, 10, 20, 13, 25, 40, 20}; 500: 501: if (chartyp > 10) 502: chartyp -= 10; 503: return (rngtab[chartyp - 1]); 504: } 505: 506: void interm(stat,who) /* interterminal battle routine */ 507: reg struct stats *stat; 508: int who; 509: { 510: #define MAXWAIT 20 511: #define BLOCK sizeof(struct stats) 512: #define RAN 1 513: #define STUCK 2 514: #define BLEWIT 3 515: #define KILLED 4 516: #define readfoe() fseek(fin,foeplace,0); \ 517: fread((char *) foe,BLOCK,1,fin) 518: #define updateme() fseek(fout,myplace,0); \ 519: fwrite((char *) stat,BLOCK,1,fout); \ 520: fflush(fout) 521: 522: FILE *fin, *fout; /* pointers for input, output */ 523: double temp, foespeed, oldhits = 0.0, myhits; 524: struct stats sbuf; 525: reg struct stats *foe; 526: reg int loop, lines = 5; 527: int ch; 528: long myplace, foeplace; 529: short oldtags; 530: bool luckout = FALSE; 531: char foename[21]; 532: 533: fghting = TRUE; 534: mvaddstr(4,0,"Preparing for battle!\n"); 535: refresh(); 536: /* set up variables, file, etc. */ 537: myplace = fileloc * BLOCK; 538: foeplace = who * BLOCK; 539: fin = fopen(peoplefile,"r"); 540: setbuf(fin, (char *) NULL); 541: fout = fopen(peoplefile,ACCESS); 542: stat->status = INBATTLE; 543: myhits = stat->nrg; 544: stat->tampered = oldtags = 1; /* this must be non-zero to prevent a king or valar from trashing it */ 545: stat->scratch1 = stat->scratch2 = 0.0; 546: updateme(); 547: foe = &sbuf; 548: readfoe(); 549: foespeed = foe->quk + foe->quks - spdcalc(foe->lvl,foe->gld,foe->gem); 550: if (abs(stat->lvl - foe->lvl) > 20) /* see if greatly mismatched */ 551: { 552: temp = ((double) (stat->lvl - foe->lvl))/((double) max(stat->lvl,foe->lvl)); 553: if (temp > 0.5) /* this one outweighs his/her foe */ 554: foespeed *= 2.0; 555: else if (temp < -0.5) /* foe outweighs this one */ 556: speed *= 2.0; 557: } 558: if (stat->blind) 559: strcpy(foename,"someone"); 560: else 561: strcpy(foename,foe->name); 562: mvprintw(3,0,"You have encountered %s Level: %d\n",foename,foe->lvl); 563: refresh(); 564: /* now wait for foe to respond */ 565: for (loop = 1.5*MAXWAIT; foe->status != INBATTLE && loop; --loop) 566: { 567: readfoe(); 568: sleep(1); 569: } 570: if (foe->status != INBATTLE) 571: { 572: mvprintw(4,0,"%s is not responding.\n",foename); 573: goto LEAVE; 574: } 575: 576: /* otherwise, everything is set to go */ 577: move(4,0); 578: clrtoeol(); 579: /* check to see who goes first */ 580: if (speed > foespeed) 581: goto HITFOE; 582: else if (foespeed > speed) 583: goto WAIT; 584: else if (stat->lvl > foe->lvl) 585: goto HITFOE; 586: else if (foe->lvl > stat->lvl) 587: goto WAIT; 588: else /* no one is faster */ 589: { 590: printw("You can't fight %s yet.",foename); 591: goto LEAVE; 592: } 593: 594: /* routine to hit, etc */ 595: HITFOE: printstats(stat); 596: mvprintw(1,26,"%20.0f",myhits); 597: mvaddstr(4,0,"1:Fight 2:Run Away! 3:Power Blast "); 598: if (luckout) 599: clrtoeol(); 600: else 601: addstr("4:Luckout "); 602: ch = gch(stat->rng.type); 603: move(lines = 5,0); 604: clrtobot(); 605: switch (ch) 606: { 607: default: /* fight */ 608: temp = roll(2,strength); 609: HIT: mvprintw(lines++,0,"You hit %s %.0f times!",foename,temp); 610: stat->sin += 0.5; 611: stat->scratch1 += temp; 612: stat->scratch2 = FALSE; 613: break; 614: case '2': /* run away */ 615: --stat->scratch1; /* this value changes to indicate action */ 616: if (rnd() > 0.25) 617: { 618: mvaddstr(lines++,0,"You got away!"); 619: stat->scratch2 = RAN; 620: goto LEAVE; 621: } 622: mvprintw(lines++,0,"%s is still after you!",foename); 623: stat->scratch2 = STUCK; 624: break; 625: case '3': /* power blast */ 626: temp = min(stat->man,stat->lvl*5); 627: stat->man -= temp; 628: temp = (rnd() + 0.5) * temp * stat->mag * 0.2 + 2; 629: mvprintw(lines++,0,"You blasted %s !",foename); 630: goto HIT; 631: case '4': /* luckout */ 632: if (luckout || rnd() > 0.1) 633: { 634: luckout = TRUE; 635: mvaddstr(lines++,0,"Not this time..."); 636: --stat->scratch1; 637: stat->scratch2 = BLEWIT; 638: } 639: else 640: { 641: mvaddstr(lines++,0,"You just lucked out!"); 642: stat->scratch1 = foe->nrg + 5; 643: } 644: break; 645: } 646: refresh(); 647: stat->scratch1 = floor(stat->scratch1); /* clean up any mess */ 648: if (stat->scratch1 > foe->nrg) 649: stat->scratch2 = KILLED; 650: else if (rnd() * speed < rnd() * foespeed) 651: { /* foe's turn */ 652: ++stat->tampered; 653: updateme(); 654: goto WAIT; 655: } 656: updateme(); 657: 658: if (((int) stat->scratch2) == KILLED) 659: { 660: mvprintw(lines++,0,"You killed %s!",foename); 661: stat->exp += foe->exp; 662: stat->crn += (stat->lvl < 1000) ? foe->crn : 0; 663: stat->amu += foe->amu; 664: stat->chm += foe->chm; 665: stat->gld += foe->gld; 666: stat->gem += foe->gem; 667: stat->swd = max(stat->swd,foe->swd); 668: stat->shd = max(stat->shd,foe->shd); 669: stat->quks = max(stat->quks,foe->quks); 670: sleep(3); /* give other person time to die */ 671: goto LEAVE; 672: } 673: goto HITFOE; /* otherwise, my turn again */ 674: 675: /* routine to wait for foe to do something */ 676: WAIT: printstats(stat); 677: mvprintw(1,26,"%20.0f",myhits); 678: mvaddstr(4,0,"Waiting...\n"); 679: refresh(); 680: for (loop = MAXWAIT; loop; --loop) 681: { 682: readfoe(); 683: if (foe->scratch1 != oldhits) 684: switch ((int) foe->scratch2) 685: { 686: case RAN: 687: mvprintw(lines++,0,"%s ran away!",foename); 688: goto LEAVE; 689: case STUCK: 690: mvprintw(lines++,0,"%s tried to run away.",foename); 691: goto BOT; 692: case BLEWIT: 693: mvprintw(lines++,0,"%s tried to luckout!",foename); 694: goto BOT; 695: default: 696: temp = foe->scratch1 - oldhits; 697: mvprintw(lines++,0,"%s hit you %.0f times!",foename,temp); 698: myhits -= temp; 699: goto BOT; 700: } 701: sleep(1); 702: } 703: /* timeout */ 704: mvaddstr(23,0,"Timeout: waiting for response. Do you want to wait ? "); 705: refresh(); 706: ch = getch(); 707: move(23,0); 708: clrtoeol(); 709: if (toupper(ch) == 'Y') 710: goto WAIT; 711: goto LEAVE; 712: 713: /* routine to decide what happens next */ 714: BOT: refresh(); 715: if (lines > 21) 716: { 717: paws(lines); 718: move(lines = 5,0); 719: clrtobot(); 720: } 721: if (((int) foe->scratch2) == KILLED || myhits < 0.0) 722: { 723: myhits = -2; 724: goto LEAVE; /* main will pick up death */ 725: } 726: oldhits = foe->scratch1; 727: if (foe->tampered != oldtags) 728: { 729: oldtags = foe->tampered; 730: goto HITFOE; 731: } 732: goto WAIT; 733: 734: /* routine to clean up things and leave */ 735: LEAVE: updateme(); 736: fclose(fin); 737: fclose(fout); 738: stat->x += roll(5,-10); 739: stat->y += roll(5,-10); 740: stat->nrg = myhits; 741: stat->tampered = OFF; 742: stat->status = PLAYING; 743: changed = TRUE; 744: paws(lines); 745: move(3,0); 746: clrtobot(); 747: } 748: 749: int interrupt() /* call when break key is hit */ 750: { 751: char line[81]; 752: reg int loop; 753: int x, y, ch; 754: 755: #ifdef USG3 756: signal(SIGINT,SIG_IGN); 757: #endif 758: #ifdef USG5 759: signal(SIGINT,SIG_IGN); 760: #endif 761: getyx(stdscr,y,x); 762: for (loop = 79; loop >= 0; --loop) /* snarf line */ 763: { 764: move(4,loop); 765: line[loop] = inch(); 766: } 767: line[80] = '\0'; 768: clrtoeol(); 769: if (fghting) 770: { 771: move(4,0); 772: clrtoeol(); 773: addstr("Quitting now will automatically kill your character. Still want to ? "); 774: ch = rgetch(); 775: if (toupper(ch) == 'Y') 776: longjmp(mainenv,DIE); 777: } 778: else 779: { 780: move(4,0); 781: clrtoeol(); 782: addstr("Do you really want to quit ? "); 783: ch = rgetch(); 784: if (toupper(ch) == 'Y') 785: longjmp(mainenv,QUIT); 786: } 787: mvaddstr(4,0,line); /* return screen to previous state */ 788: move(y,x); 789: refresh(); 790: #ifdef USG3 791: signal(SIGINT,interrupt); 792: #endif 793: #ifdef USG5 794: signal(SIGINT,interrupt); 795: #endif 796: } 797: 798: int rgetch() /* refresh, then get a char. */ 799: { 800: refresh(); 801: return (getch()); 802: } 803: 804: void purge() /* remove old players */ 805: { 806: FILE *fin, *fout; 807: struct stats sbuf; 808: reg int loc, today, temp; 809: long ltime; 810: 811: loc = 0; 812: time(<ime); 813: today = localtime(<ime)->tm_yday; 814: fin = fopen(peoplefile,"r"); 815: fout = fopen(peoplefile,ACCESS); 816: while(fread((char *) &sbuf,sizeof(sbuf),1,fin)) 817: { 818: temp = today - sbuf.lastused; 819: if (temp < 0) 820: temp += 365; 821: if (temp > 9) /* ten days old --> delete */ 822: { 823: initchar(&sbuf); 824: strcpy(sbuf.name,"<null>"); 825: fseek(fout,(long) loc * sizeof(sbuf),0); 826: fwrite((char *) &sbuf,sizeof(sbuf),1,fout); 827: } 828: ++loc; 829: } 830: fclose(fin); 831: fclose(fout); 832: }