1: /*
   2:  * func1.c	Phantasia support routines
   3:  */
   4: 
   5: #include "phant.h"
   6: 
   7: bool    findname(name)              /* return TRUE if name in use */
   8: reg char    *name;
   9: {
  10: FILE    *fp;
  11: struct  stats   buf;
  12: 
  13:     fp = fopen(peoplefile,"r");
  14:     while (fread((char *) &buf,sizeof(buf),1,fp))
  15:         if (!strcmp(buf.name,name))
  16:             {
  17:             fclose(fp);
  18:             mvaddstr(21,0,"Name already in use.\n");
  19:             refresh();
  20:             return (TRUE);
  21:             }
  22:     fclose(fp);
  23:     return (FALSE);
  24: }
  25: 
  26: int findspace()             /* allocate space for a character in peoplefile */
  27: {
  28: FILE    *fp;
  29: struct  stats   buf;
  30: reg int loc;
  31: 
  32:     loc = 0;
  33:     fp = fopen(peoplefile,"r");
  34:     while (fread((char *) &buf,sizeof(buf),1,fp))
  35:         {
  36:         if (!strcmp(buf.name,"<null>"))
  37:             {
  38:             fclose(fp);
  39:             return (loc);
  40:             }
  41:         else
  42:             ++loc;
  43:         }
  44:     fclose(fp);
  45:     fp = fopen(peoplefile,ACCESS);
  46:     fseek(fp,(long) loc * sizeof(buf),0);
  47:     initchar(&buf);
  48:     strcpy(buf.name,"inuse");
  49:     fwrite((char *) &buf,sizeof(buf),1,fp);
  50:     fclose(fp);
  51:     return (loc);
  52: }
  53: 
  54: int findchar(stat)              /* retrieve a character from file */
  55: reg struct  stats   *stat;
  56: {
  57: reg int loc = 0, loop;
  58: char    name[21];
  59: FILE    *fp;
  60: 
  61:     if (fp = fopen(peoplefile,"r"))
  62:         {
  63:         clear();
  64:         mvprintw(10,0,"What was your character's name ? ");
  65:         getstring(name,21);
  66:         trunc(name);
  67:         while (fread((char *) stat,sizeof(*stat),1,fp))
  68:             {
  69:             if (!strcmp(stat->name,name))
  70:                 {
  71:                 move(11,0);
  72:                 refresh();
  73:                 fclose(fp);
  74:                 nocrmode();
  75:                 for (loop = 0; loop < 2; ++loop)
  76:                     if (!strcmp(getpass("Password ? "),stat->pswd))
  77:                         {
  78:                         crmode();
  79:                         return (loc);
  80:                         }
  81:                     else
  82:                         printf("No good.\n");
  83:                 exit1();
  84:                 /*NOTREACHED*/
  85:                 }
  86:             ++loc;
  87:             }
  88:         }
  89:     fclose(fp);
  90:     addstr("\n\nNot found.\n");
  91:     exit1();
  92: /*NOTREACHED*/
  93: }
  94: 
  95: void    leave(stat)             /* save character in file */
  96: reg struct  stats   *stat;
  97: {
  98: long    ltemp;
  99: 
 100:     if (!stat->lvl)
 101:         strcpy(stat->name,"<null>");
 102:     stat->status = OFF;
 103:     time(&ltemp);
 104:     stat->age += ltemp - secs;
 105:     update(stat,fileloc);
 106:     exit1();
 107:     /*NOTREACHED*/
 108: }
 109: 
 110: void    talk(name)              /* send message to all players */
 111: reg char    *name;
 112: {
 113: FILE    *fp;
 114: char    aline[160];
 115: 
 116:     mvaddstr(5,0,"Message ? ");
 117:     getstring(aline,160);
 118:     fp = fopen(messfile,"w");
 119:     if (*aline)
 120:         fprintf(fp,"%s:  %s",name,aline);
 121:     fclose(fp);
 122: }
 123: 
 124: void    death(stat)             /* remove a player after dying */
 125: reg struct  stats   *stat;
 126: {
 127: FILE    *fp;
 128: char    aline[100];
 129: int ch;
 130: reg int loop;
 131: long    ltemp;
 132: 
 133:     clear();
 134:     if (stat->typ == 99)
 135:         if (stat->rng.duration)
 136:             {
 137:             addstr("Valar should be more cautious.  You've been killed.\n");
 138:             printw("You only have %d more chance(s).\n",--stat->rng.duration);
 139:             paws(3);
 140:             stat->nrg = stat->mxn;
 141:             return;
 142:             }
 143:         else
 144:             {
 145:             addstr("You had your chances, but Valar aren't totally\n");
 146:             addstr("immortal.  You are now left to wither and die . . .\n");
 147:             paws(3);
 148:             stat->brn = stat->lvl /25;
 149:             stat->nrg = stat->mxn;
 150:             stat->quks = stat->swd = 0;
 151:             stat->typ = 90;
 152:             return;
 153:             }
 154:     if (stat->lvl > 9999)
 155:         addstr("Characters greater than level 10K must be retired.  Sorry.");
 156:     switch(stat->rng.type)
 157:         {
 158:         case -DLREG:
 159:         case -NAZREG:
 160:             mvaddstr(4,0,"Your ring saved you from death!\n");
 161:             refresh();
 162:             stat->rng.type = NONE;
 163:             stat->nrg = stat->mxn/12+1;
 164:             stat->crn -= (stat->crn > 0);
 165:             return;
 166:         case DLBAD:
 167:         case -DLBAD:
 168:         case NAZBAD:
 169:         case -NAZBAD:
 170:         case -SPOILED:
 171:         case SPOILED:
 172:             mvaddstr(4,0,"Your ring has taken control of you and turned you into a monster!\n");
 173:             fp = fopen(monsterfile,"r");
 174:             for (loop = 0; loop <= 13; ++loop)
 175:                 fgets(aline,100,fp);
 176:             ltemp = ftell(fp);
 177:             fclose(fp);
 178:             fp = fopen(monsterfile,ACCESS);
 179:             fseek(fp,ltemp,0);
 180:             fprintf(fp,"%-20s",stat->name);
 181:             fclose(fp);
 182:         }
 183:     initchar(stat);
 184:     fp = fopen(lastdead,"w");
 185:     fprintf(fp,"%s   Login:  %s",stat->name,stat->login);
 186:     fclose(fp);
 187:     strcpy(stat->name,"<null>");
 188:     update(stat,fileloc);
 189:     clear();
 190:     move(10,0);
 191:     switch ((int) roll(1,5))
 192:         {
 193:         case 1:
 194:             addstr("You've crapped out!  ");
 195:             break;
 196:         case 2:
 197:             addstr("You have been disemboweled.  ");
 198:             break;
 199:         case 3:
 200:             addstr("You've been mashed, mauled, and spit upon.  (You're dead.)\n");
 201:             break;
 202:         case 4:
 203:             addstr("You died!  ");
 204:             break;
 205:         case 5:
 206:             addstr("You're a complete failure -- you've died!!\n");
 207:         }
 208:     addstr("Care to give it another try ? ");
 209:     ch = rgetch();
 210:     if (toupper(ch) == 'Y')
 211:         {
 212:         endwin();
 213:         execl(gameprog,"phantasia","-s",0);
 214:         }
 215:     exit1();
 216:     /*NOTREACHED*/
 217: }
 218: 
 219: void    update(stat,place)          /* update charac file */
 220: reg struct  stats   *stat;
 221: reg int place;
 222: {
 223: FILE    *fp;
 224: 
 225:     fp = fopen(peoplefile,ACCESS);
 226:     fseek(fp,(long) place*sizeof(*stat),0);
 227:     fwrite((char *) stat,sizeof(*stat),1,fp);
 228:     fclose(fp);
 229: }
 230: 
 231: void    printplayers(stat)          /* show users */
 232: reg struct  stats   *stat;
 233: {
 234: FILE    *fp;
 235: struct  stats   buf;
 236: reg int loop = 0;
 237: double  loc;
 238: long    ltmp;
 239: int ch;
 240: 
 241:     if (stat->blind)
 242:         {
 243:         mvaddstr(6,0,"You can't see anyone.\n");
 244:         return;
 245:         }
 246:     loc = circ(stat->x,stat->y);
 247:     mvaddstr(6,0,"Name                         X         Y       Lvl  Type  Login\n");
 248:     fp = fopen(peoplefile,"r");
 249:     while (fread((char *) &buf,sizeof(buf),1,fp))
 250:         {
 251:         if (buf.status)
 252:             {
 253:             ch = (buf.status == CLOAKED) ? '?' : 'W';
 254:             if (stat->typ > 10 || buf.typ > 10 || loc >= circ(buf.x,buf.y) || stat->pal)
 255:                 if (buf.status != CLOAKED || (stat->typ == 99 && stat->pal))
 256:                     if (buf.typ == 99)
 257:                         addstr("The Valar is watching you. . .\n");
 258:                     else if (buf.wormhole)
 259:                         printw("%-20s         %c         %c    %6u  %3d   %-9s\n",
 260:                             buf.name,ch,ch,buf.lvl,buf.typ,buf.login);
 261:                     else
 262:                         printw("%-20s  %8.0f  %8.0f    %6u  %3d   %-9s\n",
 263:                             buf.name,buf.x,buf.y,buf.lvl,buf.typ,buf.login);
 264:                 else
 265:                     if (buf.typ == 99)
 266:                         --loop;
 267:                     else
 268:                         printw("%-20s         ?         ?    %6u  %3d   %-9s\n",
 269:                             buf.name,buf.lvl,buf.typ,buf.login);
 270:             ++loop;
 271:             }
 272:         }
 273:     fclose(fp);
 274:     time(&ltmp);
 275:     printw("Total users = %d    %s\n",loop,ctime(&ltmp));
 276:     refresh();
 277: }
 278: 
 279: 
 280: void    printhelp()             /* print help file */
 281: {
 282: FILE    *fp;
 283: char    instr[100];
 284: 
 285:     fp = fopen(helpfile,"r");
 286:     while (fgets(instr,100,fp))
 287:         fputs(instr,stdout);
 288:     fclose(fp);
 289: }
 290: 
 291: void    titlestuff()                /* print out a header */
 292: {
 293: FILE    *fp;
 294: char    instr[80], hiname[21], nxtname[21], aline[80];
 295: bool    cowfound = FALSE, kingfound = FALSE;
 296: struct  stats   buf;
 297: double  hiexp, nxtexp;
 298: unsigned    hilvl, nxtlvl;
 299: reg int loop;
 300: 
 301:     mvaddstr(0,15,"W e l c o m e   t o   P h a n t a s i a (vers. 3.2)!");
 302:     fp = fopen(motd,"r");
 303:     if (fgets(instr,80,fp))
 304:         mvaddstr(2,40 - strlen(instr)/2,instr);
 305:     fclose(fp);
 306:     fp = fopen(peoplefile,"r");
 307:     while (fread((char *) &buf,sizeof(buf),1,fp))
 308:         if (buf.typ > 10 && buf.typ < 20)
 309:             {
 310:             sprintf(instr,"The present ruler is %s  Level:%d",buf.name,buf.lvl);
 311:             mvaddstr(4,40 - strlen(instr)/2,instr);
 312:             kingfound = TRUE;
 313:             break;
 314:             }
 315:     if (!kingfound)
 316:         mvaddstr(4,24,"There is no ruler at this time.");
 317:     fseek(fp,0L,0);
 318:     while (fread((char *) &buf,sizeof(buf),1,fp))
 319:         if (buf.typ == 99)
 320:             {
 321:             sprintf(instr,"The Valar is %s   Login:  %s",buf.name,buf.login);
 322:             mvaddstr(6,40 - strlen(instr)/2,instr);
 323:             break;
 324:             }
 325:     fseek(fp,0L,0);
 326:     while (fread((char *) &buf,sizeof(buf),1,fp))
 327:         if (buf.typ > 20 && buf.typ < 90)
 328:             {
 329:             if (!cowfound)
 330:                 {
 331:                 mvaddstr(8,30,"Council of the Wise:");
 332:                 loop = 10;
 333:                 cowfound = TRUE;
 334:                 }
 335:             /* This assumes a finite (<=7) number of C.O.W.: */
 336:             sprintf(instr,"%s   Login:  %s",buf.name,buf.login);
 337:             mvaddstr(loop++,40 - strlen(instr)/2,instr);
 338:             }
 339:     fseek(fp,0L,0);
 340:     *nxtname = *hiname = '\0';
 341:     hiexp = 0.0;
 342:     nxtlvl = hilvl = 0;
 343:     while (fread((char *) &buf,sizeof(buf),1,fp))
 344:         if (buf.exp > hiexp && buf.typ < 20)
 345:             {
 346:             nxtexp = hiexp;
 347:             hiexp = buf.exp;
 348:             nxtlvl = hilvl;
 349:             hilvl = buf.lvl;
 350:             strcpy(nxtname,hiname);
 351:             strcpy(hiname,buf.name);
 352:             }
 353:         else if (buf.exp > nxtexp && buf.typ < 20)
 354:             {
 355:             nxtexp = buf.exp;
 356:             nxtlvl = buf.lvl;
 357:             strcpy(nxtname,buf.name);
 358:             }
 359:     fclose(fp);
 360:     mvaddstr(17,28,"Highest characters are:");
 361:     sprintf(instr,"%s  Level:%d   and   %s  Level:%d",hiname,hilvl,nxtname,nxtlvl);
 362:     mvaddstr(19,40 - strlen(instr)/2,instr);
 363:     fp = fopen(lastdead,"r");
 364:     fgets(aline,80,fp);
 365:     sprintf(instr,"The last character to die is %s",aline);
 366:     mvaddstr(21,40 - strlen(instr)/2,instr);
 367:     fclose(fp);
 368:     refresh();
 369: }
 370: 
 371: 
 372: 
 373: void    printmonster()              /* do a monster list on the terminal */
 374: {
 375: FILE    *fp;
 376: reg int count = 0;
 377: char    instr[100];
 378: 
 379:     puts(" #  Name                    Str     Brains  Quick   Hits    Exp     Treas   Type    Flock%\n");
 380:     fp = fopen(monsterfile,"r");
 381:     while (fgets(instr,100,fp))
 382:         printf("%2d  %s",count++,instr);
 383:     fclose(fp);
 384: }
 385: 
 386: void    exit1()                 /* exit, but cleanup */
 387: {
 388:     move(23,0);
 389:     refresh();
 390:     nocrmode();
 391:     endwin();
 392:     exit(0);
 393:     /*NOTREACHED*/
 394: }
 395: 
 396: void    init1()                 /* set up for screen updating */
 397: {
 398:         /* catch/ingnore signals */
 399: #ifdef  BSD41
 400:     sigignore(SIGQUIT);
 401:     sigignore(SIGALRM);
 402:     sigignore(SIGTERM);
 403:     sigignore(SIGTSTP);
 404:     sigignore(SIGTTIN);
 405:     sigignore(SIGTTOU);
 406:     sighold(SIGINT);
 407: #endif
 408: #ifdef  BSD42
 409:     signal(SIGQUIT,interrupt,1);
 410:     signal(SIGALRM,interrupt,1);
 411:     signal(SIGTERM,interrupt,1);
 412:     signal(SIGTSTP,interrupt,1);
 413:     signal(SIGTTIN,interrupt,1);
 414:     signal(SIGTTOU,interrupt,1);
 415:     signal(SIGINT,interrupt,1);
 416: #endif
 417: #ifdef  USG3
 418:     signal(SIGINT,SIG_IGN);
 419:     signal(SIGQUIT,SIG_IGN);
 420:     signal(SIGTERM,SIG_IGN);
 421:     signal(SIGALRM,SIG_IGN);
 422: #endif
 423: #ifdef  USG5
 424:     signal(SIGINT,SIG_IGN);
 425:     signal(SIGQUIT,SIG_IGN);
 426:     signal(SIGTERM,SIG_IGN);
 427:     signal(SIGALRM,SIG_IGN);
 428: #endif
 429:     srand((unsigned) time((long *) NULL));  /* prime random numbers */
 430:     initscr();
 431:     noecho();
 432:     crmode();
 433:     clear();
 434:     refresh();
 435: }
 436: 
 437: void    getstring(cp,mx)                /* get a string from the stdscr at current y,x */
 438: reg char    *cp;
 439: reg int mx;
 440: {
 441: reg int loop = 0, x, y, xorig;
 442: int ch;
 443: 
 444:     getyx(stdscr,y,xorig);
 445:     clrtoeol();
 446:     refresh();
 447:     while((ch = getch()) != '\n' && loop < mx - 1)
 448:         switch (ch)
 449:             {
 450:             case '\033':    /* escape */
 451:             case '\010':    /* backspace */
 452:                 if (loop)
 453:                     {
 454:                     --loop;
 455:                     getyx(stdscr,y,x);
 456:                     mvaddch(y,x-1,' ');
 457:                     move(y,x-1);
 458:                     refresh();
 459:                     }
 460:                 break;
 461:             case '\030':    /* ctrl-x */
 462:                 loop = 0;
 463:                 move(y,xorig);
 464:                 clrtoeol();
 465:                 refresh();
 466:                 break;
 467:             default:
 468:                 if (ch >= ' ') /* printing char */
 469:                     {
 470:                     addch(ch);
 471:                     cp[loop++] = ch;
 472:                     refresh();
 473:                     }
 474:             }
 475:     cp[loop] = '\0';
 476: }
 477: 
 478: 
 479: void    showusers()             /* print a list of all characters */
 480: {
 481: struct  stats   buf;
 482: FILE    *fp;
 483: 
 484:     if (fp = fopen(peoplefile,"r"))
 485:         {
 486:         puts("Current characters on file are:\n");
 487:         while (fread((char *) &buf,sizeof(buf),1,fp))
 488:             if (strcmp("<null>",buf.name))
 489:                 printf("%-20s   Login: %-9s  Level: %6u\n",buf.name,buf.login,buf.lvl);
 490:         fclose(fp);
 491:         }
 492: }
 493: 
 494: void    kingstuff(stat)             /* stuff upon entering throne */
 495: reg struct  stats   *stat;
 496: {
 497: FILE    *fp;
 498: struct  stats   buf;
 499: struct  nrgvoid vbuf;
 500: reg int loc = 0;
 501: 
 502:     if (stat->typ < 10) /* check to see if king -- assumes crown */
 503:         {
 504:         fp = fopen(peoplefile,"r");
 505:         while (fread((char *) &buf,sizeof(buf),1,fp))
 506:             if (buf.typ > 10 && buf.typ < 20)   /* found old king */
 507:                 if (buf.status != OFF)
 508:                     {
 509:                     mvaddstr(6,0,"The king is playing, so you cannot steal his throne\n");
 510:                     stat->x = stat->y = 9;
 511:                     move(3,0);
 512:                     fclose(fp);
 513:                     return;
 514:                     }
 515:                 else
 516:                     {
 517:                     buf.typ -= 10;
 518:                     if (buf.crn)
 519:                         --buf.crn;
 520:                     fclose(fp);
 521:                     update(&buf,loc);
 522: KING:               stat->typ = abs(stat->typ) + 10;
 523:                     mvaddstr(6,0,"You have become king!\n");
 524:                     fp = fopen(messfile,"w");
 525:                     fprintf(fp,"All hail the new king!");
 526:                     fclose(fp);
 527:                     /* clear all energy voids */
 528:                     fp = fopen(voidfile,"r");
 529:                     fread((char *) &vbuf,sizeof(vbuf),1,fp);
 530:                     fclose(fp);
 531:                     fp = fopen(voidfile,"w");
 532:                     fwrite((char *) &vbuf,sizeof(vbuf),1,fp);
 533:                     fclose(fp);
 534:                     goto EXIT;
 535:                     }
 536:             else
 537:                 ++loc;
 538:         fclose(fp);   /* old king not found -- install new one */
 539:         goto KING;
 540:         }
 541: EXIT:   mvaddstr(3,0,"0:Decree  ");
 542: }
 543: 
 544: void    paws(where)             /* wait for input to continue */
 545: int where;
 546: {
 547:     mvaddstr(where,0,"-- more --");
 548:     rgetch();
 549: }
 550: 
 551: void    cstat()                 /* examine/change stats of a character */
 552: {
 553: struct  stats charac;
 554: char    s[60], flag[2];
 555: FILE    *fp;
 556: reg int loc = 0;
 557: int c, temp, today;
 558: long    ltemp;
 559: double  dtemp;
 560: 
 561:     flag[0] = 'F';  flag[1] = 'T';
 562:     mvaddstr(10,0,"Which character do you want to look at ? ");
 563:     getstring(s,60);
 564:     if (fp = fopen(peoplefile,"r"))
 565:         while (fread((char *) &charac,sizeof(charac),1,fp))
 566:             if (!strcmp(s,charac.name))
 567:                 goto FOUND;
 568:             else
 569:                 ++loc;
 570:     mvaddstr(11,0,"Not found.");
 571:     exit1();
 572:     /*NOTREACHED*/
 573: 
 574: FOUND:  fclose(fp);
 575:     time(&ltemp);
 576:     today = localtime(&ltemp)->tm_yday;
 577:     if (!su)
 578:         strcpy(charac.pswd,"XXXXXXXX");
 579:     clear();
 580: TOP:    mvprintw(0,0,"a:Name         %s\n",charac.name);
 581:     printw("b:Password     %s\n",charac.pswd);
 582:     printw(" :Login        %s\n",charac.login);
 583:     temp = today - charac.lastused;
 584:     if (temp < 0)
 585:         temp += 365;
 586:     printw("c:Used         %d\n",temp);
 587:     mvprintw(5,0,"d:Experience   %.0f\n",charac.exp);
 588:     printw("e:Level        %d\n",charac.lvl);
 589:     printw("f:Strength     %.0f\n",charac.str);
 590:     printw("g:Sword        %.0f\n",charac.swd);
 591:     printw("h:Quickness    %d\n",charac.quk);
 592:     printw("i:Quikslvr     %d\n",charac.quks);
 593:     printw("j:Energy       %.0f\n",charac.nrg);
 594:     printw("k:Max-Nrg      %.0f\n",charac.mxn);
 595:     printw("l:Shield       %.0f\n",charac.shd);
 596:     printw("m:Magic        %.0f\n",charac.mag);
 597:     printw("n:Manna        %.0f\n",charac.man);
 598:     printw("o:Brains       %.0f\n",charac.brn);
 599:     mvprintw(0,40,"p:X-coord      %.0f\n",charac.x);
 600:     mvprintw(1,40,"q:Y-coord      %.0f\n",charac.y);
 601:     if (su)
 602:         mvprintw(2,40,"r:Wormhole     %d\n",charac.wormhole);
 603:     else
 604:         mvprintw(2,40,"r:Wormhole     %c\n",flag[charac.wormhole != 0]);
 605:     mvprintw(3,40,"s:Type         %d\n",charac.typ);
 606:     mvprintw(5,40,"t:Sin          %0.3f\n",charac.sin);
 607:     mvprintw(6,40,"u:Poison       %0.3f\n",charac.psn);
 608:     mvprintw(7,40,"v:Gold         %.0f\n",charac.gld);
 609:     mvprintw(8,40,"w:Gem          %.0f\n",charac.gem);
 610:     mvprintw(9,40,"x:Holy Water   %d\n",charac.hw);
 611:     mvprintw(10,40,"y:Charms       %d\n",charac.chm);
 612:     mvprintw(11,40,"z:Crowns       %d\n",charac.crn);
 613:     mvprintw(12,40,"1:Amulets      %d\n",charac.amu);
 614:     mvprintw(13,40,"2:Age          %d\n",charac.age);
 615:     mvprintw(18,5,"3:Virgin %c  4:Blessed %c  5:Ring %c  6:Blind %c  7:Palantir %c",
 616:         flag[charac.vrg],flag[charac.bls],flag[charac.rng.type != 0],flag[charac.blind],flag[charac.pal]);
 617:     if (!su)
 618:         exit1();
 619:     mvaddstr(15,40,"!:Quit");
 620:     mvaddstr(16,40,"?:Delete");
 621:     mvaddstr(19,30,"8:Duration");
 622:     mvaddstr(21,0,"What would you like to change? ");
 623:     c = rgetch();
 624:     switch(c)
 625:         {
 626:         case 'p':   /* change x coord */
 627:             mvprintw(23,0,"x = %f; x = ",charac.x);
 628:             dtemp = inflt();
 629:             if (dtemp != 0.0)
 630:                 charac.x = dtemp;
 631:             break;
 632:         case 'q':   /* change y coord */
 633:             mvprintw(23,0,"y = %f; y = ",charac.y);
 634:             dtemp = inflt();
 635:             if (dtemp != 0.0)
 636:                 charac.y = dtemp;
 637:             break;
 638:         case 'd':   /* change Experience */
 639:             mvprintw(23,0,"exp = %f; exp = ",charac.exp);
 640:             dtemp = inflt();
 641:             if (dtemp != 0.0)
 642:                 charac.exp = dtemp;
 643:             break;
 644:         case 'e':   /* change level */
 645:             mvprintw(23,0,"lvl = %d; lvl;= ",charac.lvl);
 646:             dtemp = inflt();
 647:             if (dtemp != 0.0)
 648:                 charac.lvl = dtemp;
 649:             break;
 650:         case 'h':   /* change quickness */
 651:             mvprintw(23,0,"quk = %d; quk;= ",charac.quk);
 652:             dtemp = inflt();
 653:             if (dtemp != 0.0)
 654:                 charac.quk = dtemp;
 655:             break;
 656:         case 'f':   /* change strength */
 657:             mvprintw(23,0,"str = %f; str;= ",charac.str);
 658:             dtemp = inflt();
 659:             if (dtemp != 0.0)
 660:                 charac.str = dtemp;
 661:             break;
 662:         case 't':   /* change Sin */
 663:             mvprintw(23,0,"sin = %f; sin;= ",charac.sin);
 664:             dtemp = inflt();
 665:             if (dtemp != 0.0)
 666:                 charac.sin = dtemp;
 667:             break;
 668:         case 'n':   /* change manna */
 669:             mvprintw(23,0,"man = %f; man;= ",charac.man);
 670:             dtemp = inflt();
 671:             if (dtemp != 0.0)
 672:                 charac.man = dtemp;
 673:             break;
 674:         case 'v':   /* change gold */
 675:             mvprintw(23,0,"gld = %f; gld;= ",charac.gld);
 676:             dtemp = inflt();
 677:             if (dtemp != 0.0)
 678:                 charac.gld = dtemp;
 679:             break;
 680:         case 'j':   /* change energy */
 681:             mvprintw(23,0,"nrg = %f; nrg;= ",charac.nrg);
 682:             dtemp = inflt();
 683:             if (dtemp != 0.0)
 684:                 charac.nrg = dtemp;
 685:             break;
 686:         case 'k':   /* change Maximum energy */
 687:             mvprintw(23,0,"mxn = %f; mxn;= ",charac.mxn);
 688:             dtemp = inflt();
 689:             if (dtemp != 0.0)
 690:                 charac.mxn = dtemp;
 691:             break;
 692:         case 'm':   /* change magic */
 693:             mvprintw(23,0,"mag = %f; mag;= ",charac.mag);
 694:             dtemp = inflt();
 695:             if (dtemp != 0.0)
 696:                 charac.mag = dtemp;
 697:             break;
 698:         case 'o':   /* change brains */
 699:             mvprintw(23,0,"brn = %f; brn;= ",charac.brn);
 700:             dtemp = inflt();
 701:             if (dtemp != 0.0)
 702:                 charac.brn = dtemp;
 703:             break;
 704:         case 'z':   /* change crowns */
 705:             mvprintw(23,0,"crn = %d; crn;= ",charac.crn);
 706:             dtemp = inflt();
 707:             if (dtemp != 0.0)
 708:                 charac.crn = dtemp;
 709:             break;
 710:         case '5':   /* change ring type */
 711:             mvprintw(23,0,"rng-type = %d; rng-type;= ",charac.rng.type);
 712:             dtemp = inflt();
 713:             if (dtemp != 0.0)
 714:                 charac.rng.type = dtemp;
 715:             break;
 716:         case '8':   /* change ring duration */
 717:             mvprintw(23,0,"rng-duration = %d; rng-duration;= ",charac.rng.duration);
 718:             dtemp = inflt();
 719:             if (dtemp != 0.0)
 720:                 charac.rng.duration = dtemp;
 721:             break;
 722:         case '7':   /* change palantir */
 723:             mvprintw(23,0,"pal = %d; pal;= ",charac.pal);
 724:             dtemp = inflt();
 725:             if (dtemp != 0.0)
 726:                 {
 727:                 charac.pal = dtemp;
 728:                 charac.pal = (charac.pal != 0);
 729:                 }
 730:             break;
 731:         case 'u':   /* change poison */
 732:             mvprintw(23,0,"psn = %f; psn;= ",charac.psn);
 733:             dtemp = inflt();
 734:             if (dtemp != 0.0)
 735:                 charac.psn = dtemp;
 736:             break;
 737:         case 'x':   /* change holy water */
 738:             mvprintw(23,0,"hw = %d; hw;= ",charac.hw);
 739:             dtemp = inflt();
 740:             if (dtemp != 0.0)
 741:                 charac.hw = dtemp;
 742:             break;
 743:         case '1':   /* change amulet */
 744:             mvprintw(23,0,"amu = %d; amu;= ",charac.amu);
 745:             dtemp = inflt();
 746:             if (dtemp != 0.0)
 747:                 charac.amu = dtemp;
 748:             break;
 749:         case '4':   /* change Blessing */
 750:             mvprintw(23,0,"bls = %d; bls;= ",charac.bls);
 751:             dtemp = inflt();
 752:             if (dtemp != 0.0)
 753:                 {
 754:                 charac.bls = dtemp;
 755:                 charac.bls = (charac.bls != 0);
 756:                 }
 757:             break;
 758:         case 'y':   /* change Charm */
 759:             mvprintw(23,0,"chm = %d; chm;= ",charac.chm);
 760:             dtemp = inflt();
 761:             if (dtemp != 0.0)
 762:                 charac.chm = dtemp;
 763:             break;
 764:         case 'w':   /* change Gems */
 765:             mvprintw(23,0,"gem = %f; gem;= ",charac.gem);
 766:             dtemp = inflt();
 767:             if (dtemp != 0.0)
 768:                 charac.gem = dtemp;
 769:             break;
 770:         case 'i':   /* change Quicksilver */
 771:             mvprintw(23,0,"quks = %d; quks;= ",charac.quks);
 772:             dtemp = inflt();
 773:             if (dtemp != 0.0)
 774:                 charac.quks = dtemp;
 775:             break;
 776:         case 'g':   /* change swords */
 777:             mvprintw(23,0,"swd = %f; swd;= ",charac.swd);
 778:             dtemp = inflt();
 779:             if (dtemp != 0.0)
 780:                 charac.swd = dtemp;
 781:             break;
 782:         case 'l':   /* change shields */
 783:             mvprintw(23,0,"shd = %f; shd;= ",charac.shd);
 784:             dtemp = inflt();
 785:             if (dtemp != 0.0)
 786:                 charac.shd = dtemp;
 787:             break;
 788:         case 's':   /* change type */
 789:             mvprintw(23,0,"typ = %d; typ;= ",charac.typ);
 790:             dtemp = inflt();
 791:             if (dtemp != 0.0)
 792:                 charac.typ = dtemp;
 793:             break;
 794:         case '3':   /* change virgin */
 795:             mvprintw(23,0,"vrg = %d; vrg;= ",charac.vrg);
 796:             dtemp = inflt();
 797:             if (dtemp != 0.0)
 798:                 {
 799:                 charac.vrg = dtemp;
 800:                 charac.vrg = (charac.vrg != 0);
 801:                 }
 802:             break;
 803:         case 'c':   /* change last-used */
 804:             mvprintw(23,0,"last-used = %d; last-used;= ",charac.lastused);
 805:             dtemp = inflt();
 806:             if (dtemp != 0.0)
 807:                 charac.lastused = dtemp;
 808:             break;
 809:         case 'b':       /* change password */
 810:             mvaddstr(23,0,"New password: ");
 811:             getstring(s,60);
 812:             if (*s)
 813:                 strcpy(charac.pswd,s);
 814:             break;
 815:         case 'a':       /* change name */
 816:             mvaddstr(23,0,"New name: ");
 817:             getstring(s,60);
 818:             if (*s)
 819:                 strcpy(charac.name,s);
 820:             break;
 821:         case 'r':   /* change wormhole */
 822:             mvprintw(23,0,"wormhole = %d; wormhole;= ",charac.wormhole);
 823:             dtemp = inflt();
 824:             if (dtemp != 0.0)
 825:                 charac.wormhole = dtemp;
 826:             break;
 827:         case '2':   /* change age */
 828:             mvprintw(23,0,"age = %d; age;= ",charac.age);
 829:             dtemp = inflt();
 830:             if (dtemp != 0.0)
 831:                 charac.age = dtemp;
 832:             break;
 833:         case '6':   /* change blindness */
 834:             mvprintw(23,0,"blind = %d; blind;= ",charac.blind);
 835:             dtemp = inflt();
 836:             if (dtemp != 0.0)
 837:                 {
 838:                 charac.blind = dtemp;
 839:                 charac.blind = (charac.blind != 0);
 840:                 }
 841:             break;
 842:         case '!':   /* quit, update */
 843:             goto LEAVE;
 844:         case '?':   /* delete char */
 845:             strcpy(charac.name,"<null>");
 846:             initchar(&charac);
 847:             goto LEAVE;
 848:         }
 849:     goto TOP;
 850: LEAVE:  charac.status = OFF;
 851:     update(&charac,loc);
 852: }
 853: 
 854: unsigned level(expr)            /* calculate level */
 855: double  expr;
 856: {
 857:     if (expr < 1.1e+7)
 858:         return (pow((expr/1000.0), 0.4875));
 859:     else
 860:         return (pow((expr/1250.0), 0.4865));
 861: }
 862: 
 863: void    trunc(str)              /* remove blank spaces at the end of str[] */
 864: reg char    *str;
 865: {
 866: reg int loop;
 867:     loop = strlen(str) - 1;
 868:     while (str[--loop] == ' ')
 869:         str[loop] = '\0';
 870: }
 871: 
 872: double  inflt()             /* get a floating point # from the terminal */
 873: {
 874: char    aline[80];
 875: double  res;
 876:     getstring(aline,80);
 877:     if (sscanf(aline,"%F",&res) < 1)
 878:         res = 0;
 879:     return (res);
 880: }
 881: 
 882: void    checkmov(stat)              /* see if beyond PONR */
 883: reg struct  stats   *stat;
 884: {
 885:     if (beyond)
 886:         {
 887:         stat->x = sgn(stat->x) * max(abs(stat->x),1.1e+6);
 888:         stat->y = sgn(stat->y) * max(abs(stat->y),1.1e+6);
 889:         }
 890: }
 891: void    scramble(stat)          /* mix up some stats */
 892: reg struct  stats   *stat;
 893: {
 894: double  buf[5], temp;
 895: reg int first, second;
 896: reg double  *bp;
 897: 
 898:     bp = buf;
 899:     *bp++ = stat->str;
 900:     *bp++ = stat->man;
 901:     *bp++ = stat->brn;
 902:     *bp++ = stat->mag;
 903:     *bp++ = stat->nrg;
 904: 
 905:     bp = buf;
 906:     first = roll(0,5);
 907:     second = roll(0,5);
 908:     temp = bp[first];
 909:     bp[first] = bp[second];
 910:     bp[second] = temp;
 911: 
 912:     stat->str = *bp++;
 913:     stat->man = *bp++;
 914:     stat->brn = *bp++;
 915:     stat->mag = *bp++;
 916:     stat->nrg = *bp++;
 917: }

Defined functions

cstat defined in line 551; used 2 times
exit1 defined in line 386; used 10 times
findname defined in line 7; used 2 times
init1 defined in line 396; used 2 times
leave defined in line 95; used 6 times
scramble defined in line 891; used 1 times
talk defined in line 110; used 3 times
Last modified: 1986-05-20
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 6253
Valid CSS Valid XHTML 1.0 Strict