|
|
1.1 ! root 1: /* ! 2: * gamesupport.c - auxiliary routines for support of Phantasia ! 3: */ ! 4: ! 5: #include "include.h" ! 6: ! 7: /************************************************************************ ! 8: / ! 9: / FUNCTION NAME: changestats() ! 10: / ! 11: / FUNCTION: examine/change statistics for a player ! 12: / ! 13: / AUTHOR: E. A. Estes, 12/4/85 ! 14: / ! 15: / ARGUMENTS: ! 16: / bool ingameflag - set if called while playing game (Wizard only) ! 17: / ! 18: / RETURN VALUE: none ! 19: / ! 20: / MODULES CALLED: freerecord(), writerecord(), descrstatus(), truncstring(), ! 21: / time(), more(), wmove(), wclear(), strcmp(), printw(), strcpy(), ! 22: / infloat(), waddstr(), cleanup(), findname(), userlist(), mvprintw(), ! 23: / localtime(), getanswer(), descrtype(), getstring() ! 24: / ! 25: / GLOBAL INPUTS: LINES, *Login, Other, Wizard, Player, *stdscr, Databuf[], ! 26: / Fileloc ! 27: / ! 28: / GLOBAL OUTPUTS: Echo ! 29: / ! 30: / DESCRIPTION: ! 31: / Prompt for player name to examine/change. ! 32: / If the name is NULL, print a list of all players. ! 33: / If we are called from within the game, check for the ! 34: / desired name being the same as the current player's name. ! 35: / Only the 'Wizard' may alter players. ! 36: / Items are changed only if a non-zero value is specified. ! 37: / To change an item to 0, use 0.1; it will be truncated later. ! 38: / ! 39: / Players may alter their names and passwords, if the following ! 40: / are true: ! 41: / - current login matches the character's logins ! 42: / - the password is known ! 43: / - the player is not in the middle of the game (ingameflag == FALSE) ! 44: / ! 45: / The last condition is imposed for two reasons: ! 46: / - the game could possibly get a bit hectic if a player were ! 47: / continually changing his/her name ! 48: / - another player structure would be necessary to check for names ! 49: / already in use ! 50: / ! 51: /************************************************************************/ ! 52: ! 53: changestats(ingameflag) ! 54: bool ingameflag; ! 55: { ! 56: static char flag[2] = /* for printing values of bools */ ! 57: {'F', 'T'}; ! 58: register struct player *playerp;/* pointer to structure to alter */ ! 59: register char *prompt; /* pointer to prompt string */ ! 60: int c; /* input */ ! 61: int today; /* day of year of today */ ! 62: int temp; /* temporary variable */ ! 63: long loc; /* location in player file */ ! 64: long now; /* time now */ ! 65: double dtemp; /* temporary variable */ ! 66: bool *bptr; /* pointer to bool item to change */ ! 67: double *dptr; /* pointer to double item to change */ ! 68: short *sptr; /* pointer to short item to change */ ! 69: ! 70: clear(); ! 71: ! 72: for (;;) ! 73: /* get name of player to examine/alter */ ! 74: { ! 75: mvaddstr(5, 0, "Which character do you want to look at ? "); ! 76: getstring(Databuf, SZ_DATABUF); ! 77: truncstring(Databuf); ! 78: ! 79: if (Databuf[0] == '\0') ! 80: userlist(ingameflag); ! 81: else ! 82: break; ! 83: } ! 84: ! 85: loc = -1L; ! 86: ! 87: if (!ingameflag) ! 88: /* use 'Player' structure */ ! 89: playerp = &Player; ! 90: else if (strcmp(Databuf, Player.p_name) == 0) ! 91: /* alter/examine current player */ ! 92: { ! 93: playerp = &Player; ! 94: loc = Fileloc; ! 95: } ! 96: else ! 97: /* use 'Other' structure */ ! 98: playerp = &Other; ! 99: ! 100: /* find player on file */ ! 101: if (loc < 0L && (loc = findname(Databuf, playerp)) < 0L) ! 102: /* didn't find player */ ! 103: { ! 104: clear(); ! 105: mvaddstr(11, 0, "Not found."); ! 106: return; ! 107: } ! 108: ! 109: time(&now); ! 110: today = localtime(&now)->tm_yday; ! 111: ! 112: clear(); ! 113: ! 114: for (;;) ! 115: /* print player structure, and prompt for action */ ! 116: { ! 117: mvprintw(0, 0,"A:Name %s\n", playerp->p_name); ! 118: ! 119: if (Wizard) ! 120: printw("B:Password %s\n", playerp->p_password); ! 121: else ! 122: addstr("B:Password XXXXXXXX\n"); ! 123: ! 124: printw(" :Login %s\n", playerp->p_login); ! 125: ! 126: printw("C:Experience %.0f\n", playerp->p_experience); ! 127: printw("D:Level %.0f\n", playerp->p_level); ! 128: printw("E:Strength %.0f\n", playerp->p_strength); ! 129: printw("F:Sword %.0f\n", playerp->p_sword); ! 130: printw(" :Might %.0f\n", playerp->p_might); ! 131: printw("G:Energy %.0f\n", playerp->p_energy); ! 132: printw("H:Max-Energy %.0f\n", playerp->p_maxenergy); ! 133: printw("I:Shield %.0f\n", playerp->p_shield); ! 134: printw("J:Quickness %.0f\n", playerp->p_quickness); ! 135: printw("K:Quicksilver %.0f\n", playerp->p_quksilver); ! 136: printw(" :Speed %.0f\n", playerp->p_speed); ! 137: printw("L:Magic Level %.0f\n", playerp->p_magiclvl); ! 138: printw("M:Mana %.0f\n", playerp->p_mana); ! 139: printw("N:Brains %.0f\n", playerp->p_brains); ! 140: ! 141: if (Wizard || playerp->p_specialtype != SC_VALAR) ! 142: mvaddstr(0, 40, descrstatus(playerp)); ! 143: ! 144: mvprintw(1, 40, "O:Poison %0.3f\n", playerp->p_poison); ! 145: mvprintw(2, 40, "P:Gold %.0f\n", playerp->p_gold); ! 146: mvprintw(3, 40, "Q:Gem %.0f\n", playerp->p_gems); ! 147: mvprintw(4, 40, "R:Sin %0.3f\n", playerp->p_sin); ! 148: if (Wizard) ! 149: { ! 150: mvprintw(5, 40, "S:X-coord %.0f\n", playerp->p_x); ! 151: mvprintw(6, 40, "T:Y-coord %.0f\n", playerp->p_y); ! 152: } ! 153: else ! 154: { ! 155: mvaddstr(5, 40, "S:X-coord ?\n"); ! 156: mvaddstr(6, 40, "T:Y-coord ?\n"); ! 157: } ! 158: ! 159: mvprintw(7, 40, "U:Age %ld\n", playerp->p_age); ! 160: mvprintw(8, 40, "V:Degenerated %d\n", playerp->p_degenerated); ! 161: ! 162: mvprintw(9, 40, "W:Type %d (%s)\n", ! 163: playerp->p_type, descrtype(playerp, FALSE) + 1); ! 164: mvprintw(10, 40, "X:Special Type %d\n", playerp->p_specialtype); ! 165: mvprintw(11, 40, "Y:Lives %d\n", playerp->p_lives); ! 166: mvprintw(12, 40, "Z:Crowns %d\n", playerp->p_crowns); ! 167: mvprintw(13, 40, "0:Charms %d\n", playerp->p_charms); ! 168: mvprintw(14, 40, "1:Amulets %d\n", playerp->p_amulets); ! 169: mvprintw(15, 40, "2:Holy Water %d\n", playerp->p_holywater); ! 170: ! 171: temp = today - playerp->p_lastused; ! 172: if (temp < 0) ! 173: /* last year */ ! 174: temp += 365; ! 175: mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp->p_lastused, temp); ! 176: ! 177: mvprintw(18, 8, "4:Palantir %c 5:Blessing %c 6:Virgin %c 7:Blind %c", ! 178: flag[playerp->p_palantir], ! 179: flag[playerp->p_blessing], ! 180: flag[playerp->p_virgin], ! 181: flag[playerp->p_blindness]); ! 182: ! 183: if (!Wizard) ! 184: mvprintw(19, 8, "8:Ring %c", ! 185: flag[playerp->p_ring.ring_type != R_NONE]); ! 186: else ! 187: mvprintw(19, 8, "8:Ring %d 9:Duration %d", ! 188: playerp->p_ring.ring_type, playerp->p_ring.ring_duration); ! 189: ! 190: if (!Wizard ! 191: /* not wizard */ ! 192: && (ingameflag || strcmp(Login, playerp->p_login) != 0)) ! 193: /* in game or not examining own character */ ! 194: { ! 195: if (ingameflag) ! 196: { ! 197: more(LINES - 1); ! 198: clear(); ! 199: return; ! 200: } ! 201: else ! 202: cleanup(TRUE); ! 203: /*NOTREACHED*/ ! 204: } ! 205: ! 206: mvaddstr(20, 0, "!:Quit ?:Delete"); ! 207: mvaddstr(21, 0, "What would you like to change ? "); ! 208: ! 209: if (Wizard) ! 210: c = getanswer(" ", TRUE); ! 211: else ! 212: /* examining own player; allow to change name and password */ ! 213: c = getanswer("!BA", FALSE); ! 214: ! 215: switch (c) ! 216: { ! 217: case 'A': /* change name */ ! 218: case 'B': /* change password */ ! 219: if (!Wizard) ! 220: /* prompt for password */ ! 221: { ! 222: mvaddstr(23, 0, "Password ? "); ! 223: Echo = FALSE; ! 224: getstring(Databuf, 9); ! 225: Echo = TRUE; ! 226: if (strcmp(Databuf, playerp->p_password) != 0) ! 227: continue; ! 228: } ! 229: ! 230: if (c == 'A') ! 231: /* get new name */ ! 232: { ! 233: mvaddstr(23, 0, "New name: "); ! 234: getstring(Databuf, SZ_NAME); ! 235: truncstring(Databuf); ! 236: if (Databuf[0] != '\0') ! 237: if (Wizard || findname(Databuf, &Other) < 0L) ! 238: strcpy(playerp->p_name, Databuf); ! 239: } ! 240: else ! 241: /* get new password */ ! 242: { ! 243: if (!Wizard) ! 244: Echo = FALSE; ! 245: ! 246: do ! 247: /* get two copies of new password until they match */ ! 248: { ! 249: /* get first copy */ ! 250: mvaddstr(23, 0, "New password ? "); ! 251: getstring(Databuf, SZ_PASSWORD); ! 252: if (Databuf[0] == '\0') ! 253: break; ! 254: ! 255: /* get second copy */ ! 256: mvaddstr(23, 0, "One more time ? "); ! 257: getstring(playerp->p_password, SZ_PASSWORD); ! 258: } ! 259: while (strcmp(playerp->p_password, Databuf) != 0); ! 260: ! 261: Echo = TRUE; ! 262: } ! 263: ! 264: continue; ! 265: ! 266: case 'C': /* change experience */ ! 267: prompt = "experience"; ! 268: dptr = &playerp->p_experience; ! 269: goto DALTER; ! 270: ! 271: case 'D': /* change level */ ! 272: prompt = "level"; ! 273: dptr = &playerp->p_level; ! 274: goto DALTER; ! 275: ! 276: case 'E': /* change strength */ ! 277: prompt = "strength"; ! 278: dptr = &playerp->p_strength; ! 279: goto DALTER; ! 280: ! 281: case 'F': /* change swords */ ! 282: prompt = "sword"; ! 283: dptr = &playerp->p_sword; ! 284: goto DALTER; ! 285: ! 286: case 'G': /* change energy */ ! 287: prompt = "energy"; ! 288: dptr = &playerp->p_energy; ! 289: goto DALTER; ! 290: ! 291: case 'H': /* change maximum energy */ ! 292: prompt = "max energy"; ! 293: dptr = &playerp->p_maxenergy; ! 294: goto DALTER; ! 295: ! 296: case 'I': /* change shields */ ! 297: prompt = "shield"; ! 298: dptr = &playerp->p_shield; ! 299: goto DALTER; ! 300: ! 301: case 'J': /* change quickness */ ! 302: prompt = "quickness"; ! 303: dptr = &playerp->p_quickness; ! 304: goto DALTER; ! 305: ! 306: case 'K': /* change quicksilver */ ! 307: prompt = "quicksilver"; ! 308: dptr = &playerp->p_quksilver; ! 309: goto DALTER; ! 310: ! 311: case 'L': /* change magic */ ! 312: prompt = "magic level"; ! 313: dptr = &playerp->p_magiclvl; ! 314: goto DALTER; ! 315: ! 316: case 'M': /* change mana */ ! 317: prompt = "mana"; ! 318: dptr = &playerp->p_mana; ! 319: goto DALTER; ! 320: ! 321: case 'N': /* change brains */ ! 322: prompt = "brains"; ! 323: dptr = &playerp->p_brains; ! 324: goto DALTER; ! 325: ! 326: case 'O': /* change poison */ ! 327: prompt = "poison"; ! 328: dptr = &playerp->p_poison; ! 329: goto DALTER; ! 330: ! 331: case 'P': /* change gold */ ! 332: prompt = "gold"; ! 333: dptr = &playerp->p_gold; ! 334: goto DALTER; ! 335: ! 336: case 'Q': /* change gems */ ! 337: prompt = "gems"; ! 338: dptr = &playerp->p_gems; ! 339: goto DALTER; ! 340: ! 341: case 'R': /* change sin */ ! 342: prompt = "sin"; ! 343: dptr = &playerp->p_sin; ! 344: goto DALTER; ! 345: ! 346: case 'S': /* change x coord */ ! 347: prompt = "x"; ! 348: dptr = &playerp->p_x; ! 349: goto DALTER; ! 350: ! 351: case 'T': /* change y coord */ ! 352: prompt = "y"; ! 353: dptr = &playerp->p_y; ! 354: goto DALTER; ! 355: ! 356: case 'U': /* change age */ ! 357: mvprintw(23, 0, "age = %ld; age = ", playerp->p_age); ! 358: dtemp = infloat(); ! 359: if (dtemp != 0.0) ! 360: playerp->p_age = (long) dtemp; ! 361: continue; ! 362: ! 363: case 'V': /* change degen */ ! 364: mvprintw(23, 0, "degen = %d; degen = ", playerp->p_degenerated); ! 365: dtemp = infloat(); ! 366: if (dtemp != 0.0) ! 367: playerp->p_degenerated = (int) dtemp; ! 368: continue; ! 369: ! 370: case 'W': /* change type */ ! 371: prompt = "type"; ! 372: sptr = &playerp->p_type; ! 373: goto SALTER; ! 374: ! 375: case 'X': /* change special type */ ! 376: prompt = "special type"; ! 377: sptr = &playerp->p_specialtype; ! 378: goto SALTER; ! 379: ! 380: case 'Y': /* change lives */ ! 381: prompt = "lives"; ! 382: sptr = &playerp->p_lives; ! 383: goto SALTER; ! 384: ! 385: case 'Z': /* change crowns */ ! 386: prompt = "crowns"; ! 387: sptr = &playerp->p_crowns; ! 388: goto SALTER; ! 389: ! 390: case '0': /* change charms */ ! 391: prompt = "charm"; ! 392: sptr = &playerp->p_charms; ! 393: goto SALTER; ! 394: ! 395: case '1': /* change amulet */ ! 396: prompt = "amulet"; ! 397: sptr = &playerp->p_amulets; ! 398: goto SALTER; ! 399: ! 400: case '2': /* change holy water */ ! 401: prompt = "holy water"; ! 402: sptr = &playerp->p_holywater; ! 403: goto SALTER; ! 404: ! 405: case '3': /* change last-used */ ! 406: prompt = "last-used"; ! 407: sptr = &playerp->p_lastused; ! 408: goto SALTER; ! 409: ! 410: case '4': /* change palantir */ ! 411: prompt = "palantir"; ! 412: bptr = &playerp->p_palantir; ! 413: goto BALTER; ! 414: ! 415: case '5': /* change blessing */ ! 416: prompt = "blessing"; ! 417: bptr = &playerp->p_blessing; ! 418: goto BALTER; ! 419: ! 420: case '6': /* change virgin */ ! 421: prompt = "virgin"; ! 422: bptr = &playerp->p_virgin; ! 423: goto BALTER; ! 424: ! 425: case '7': /* change blindness */ ! 426: prompt = "blindness"; ! 427: bptr = &playerp->p_blindness; ! 428: goto BALTER; ! 429: ! 430: case '8': /* change ring type */ ! 431: prompt = "ring-type"; ! 432: sptr = &playerp->p_ring.ring_type; ! 433: goto SALTER; ! 434: ! 435: case '9': /* change ring duration */ ! 436: prompt = "ring-duration"; ! 437: sptr = &playerp->p_ring.ring_duration; ! 438: goto SALTER; ! 439: ! 440: case '!': /* quit, update */ ! 441: if (Wizard && ! 442: (!ingameflag || playerp != &Player)) ! 443: /* turn off status if not modifying self */ ! 444: { ! 445: playerp->p_status = S_OFF; ! 446: playerp->p_tampered = T_OFF; ! 447: } ! 448: ! 449: writerecord(playerp, loc); ! 450: clear(); ! 451: return; ! 452: ! 453: case '?': /* delete player */ ! 454: if (ingameflag && playerp == &Player) ! 455: /* cannot delete self */ ! 456: continue; ! 457: ! 458: freerecord(playerp, loc); ! 459: clear(); ! 460: return; ! 461: ! 462: default: ! 463: continue; ! 464: } ! 465: DALTER: ! 466: mvprintw(23, 0, "%s = %f; %s = ", prompt, *dptr, prompt); ! 467: dtemp = infloat(); ! 468: if (dtemp != 0.0) ! 469: *dptr = dtemp; ! 470: continue; ! 471: ! 472: SALTER: ! 473: mvprintw(23, 0, "%s = %d; %s = ", prompt, *sptr, prompt); ! 474: dtemp = infloat(); ! 475: if (dtemp != 0.0) ! 476: *sptr = (short) dtemp; ! 477: continue; ! 478: ! 479: BALTER: ! 480: mvprintw(23, 0, "%s = %c; %s = ", prompt, flag[*bptr], prompt); ! 481: c = getanswer("\nTF", TRUE); ! 482: if (c == 'T') ! 483: *bptr = TRUE; ! 484: else if (c == 'F') ! 485: *bptr = FALSE; ! 486: continue; ! 487: } ! 488: } ! 489: /**/ ! 490: /************************************************************************ ! 491: / ! 492: / FUNCTION NAME: monstlist() ! 493: / ! 494: / FUNCTION: print a monster listing ! 495: / ! 496: / AUTHOR: E. A. Estes, 2/27/86 ! 497: / ! 498: / ARGUMENTS: none ! 499: / ! 500: / RETURN VALUE: none ! 501: / ! 502: / MODULES CALLED: puts(), fread(), fseek(), printf() ! 503: / ! 504: / GLOBAL INPUTS: Curmonster, *Monstfp ! 505: / ! 506: / GLOBAL OUTPUTS: none ! 507: / ! 508: / DESCRIPTION: ! 509: / Read monster file, and print a monster listing on standard output. ! 510: / ! 511: /************************************************************************/ ! 512: ! 513: monstlist() ! 514: { ! 515: register int count = 0; /* count in file */ ! 516: ! 517: puts(" #) Name Str Brain Quick Energy Exper Treas Type Flock%\n"); ! 518: fseek(Monstfp, 0L, 0); ! 519: while (fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp) == 1) ! 520: printf("%2d) %-20.20s%4.0f %4.0f %2.0f %5.0f %5.0f %2d %2d %3.0f\n", count++, ! 521: Curmonster.m_name, Curmonster.m_strength, Curmonster.m_brains, ! 522: Curmonster.m_speed, Curmonster.m_energy, Curmonster.m_experience, ! 523: Curmonster.m_treasuretype, Curmonster.m_type, Curmonster.m_flock); ! 524: } ! 525: /**/ ! 526: /************************************************************************ ! 527: / ! 528: / FUNCTION NAME: scorelist() ! 529: / ! 530: / FUNCTION: print player score board ! 531: / ! 532: / AUTHOR: E. A. Estes, 12/4/85 ! 533: / ! 534: / ARGUMENTS: none ! 535: / ! 536: / RETURN VALUE: none ! 537: / ! 538: / MODULES CALLED: fread(), fopen(), printf(), fclose() ! 539: / ! 540: / GLOBAL INPUTS: ! 541: / ! 542: / GLOBAL OUTPUTS: none ! 543: / ! 544: / DESCRIPTION: ! 545: / Read the scoreboard file and print the contents. ! 546: / ! 547: /************************************************************************/ ! 548: ! 549: scorelist() ! 550: { ! 551: struct scoreboard sbuf; /* for reading entries */ ! 552: register FILE *fp; /* to open the file */ ! 553: ! 554: if ((fp = fopen(_PATH_SCORE, "r")) != NULL) ! 555: { ! 556: while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1) ! 557: printf("%-20s (%-9s) Level: %6.0f Type: %s\n", ! 558: sbuf.sb_name, sbuf.sb_login, sbuf.sb_level, sbuf.sb_type); ! 559: fclose(fp); ! 560: } ! 561: } ! 562: /**/ ! 563: /************************************************************************ ! 564: / ! 565: / FUNCTION NAME: activelist() ! 566: / ! 567: / FUNCTION: print list of active players to standard output ! 568: / ! 569: / AUTHOR: E. A. Estes, 3/7/86 ! 570: / ! 571: / ARGUMENTS: none ! 572: / ! 573: / RETURN VALUE: none ! 574: / ! 575: / MODULES CALLED: descrstatus(), fread(), fseek(), printf(), descrtype() ! 576: / ! 577: / GLOBAL INPUTS: Other, *Playersfp ! 578: / ! 579: / GLOBAL OUTPUTS: none ! 580: / ! 581: / DESCRIPTION: ! 582: / Read player file, and print list of active records to standard output. ! 583: / ! 584: /************************************************************************/ ! 585: ! 586: activelist() ! 587: { ! 588: fseek(Playersfp, 0L, 0); ! 589: printf("Current characters on file are:\n\n"); ! 590: ! 591: while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) ! 592: if (Other.p_status != S_NOTUSED) ! 593: printf("%-20s (%-9s) Level: %6.0f %s (%s)\n", ! 594: Other.p_name, Other.p_login, Other.p_level, ! 595: descrtype(&Other, FALSE), descrstatus(&Other)); ! 596: ! 597: } ! 598: /**/ ! 599: /************************************************************************ ! 600: / ! 601: / FUNCTION NAME: purgeoldplayers() ! 602: / ! 603: / FUNCTION: purge inactive players from player file ! 604: / ! 605: / AUTHOR: E. A. Estes, 12/4/85 ! 606: / ! 607: / ARGUMENTS: none ! 608: / ! 609: / RETURN VALUE: none ! 610: / ! 611: / MODULES CALLED: freerecord(), time(), fread(), fseek(), localtime() ! 612: / ! 613: / GLOBAL INPUTS: Other, *Playersfp ! 614: / ! 615: / GLOBAL OUTPUTS: none ! 616: / ! 617: / DESCRIPTION: ! 618: / Delete characters which have not been used with the last ! 619: / three weeks. ! 620: / ! 621: /************************************************************************/ ! 622: ! 623: purgeoldplayers() ! 624: { ! 625: int today; /* day of year for today */ ! 626: int daysold; /* how many days since the character has been used */ ! 627: long ltime; /* time in seconds */ ! 628: long loc = 0L; /* location in file */ ! 629: ! 630: time(<ime); ! 631: today = localtime(<ime)->tm_yday; ! 632: ! 633: for (;;) ! 634: { ! 635: fseek(Playersfp, loc, 0); ! 636: if (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) != 1) ! 637: break; ! 638: ! 639: daysold = today - Other.p_lastused; ! 640: if (daysold < 0) ! 641: daysold += 365; ! 642: ! 643: if (daysold > N_DAYSOLD) ! 644: /* player hasn't been used in a while; delete */ ! 645: freerecord(&Other, loc); ! 646: ! 647: loc += SZ_PLAYERSTRUCT; ! 648: } ! 649: } ! 650: /**/ ! 651: /************************************************************************ ! 652: / ! 653: / FUNCTION NAME: enterscore() ! 654: / ! 655: / FUNCTION: enter player into scoreboard ! 656: / ! 657: / AUTHOR: E. A. Estes, 12/4/85 ! 658: / ! 659: / ARGUMENTS: none ! 660: / ! 661: / RETURN VALUE: none ! 662: / ! 663: / MODULES CALLED: fread(), fseek(), fopen(), error(), strcmp(), fclose(), ! 664: / strcpy(), fwrite(), descrtype() ! 665: / ! 666: / GLOBAL INPUTS: Player ! 667: / ! 668: / GLOBAL OUTPUTS: none ! 669: / ! 670: / DESCRIPTION: ! 671: / The scoreboard keeps track of the highest character on a ! 672: / per-login basis. ! 673: / Search the scoreboard for an entry for the current login, ! 674: / if an entry is found, and it is lower than the current player, ! 675: / replace it, otherwise create an entry. ! 676: / ! 677: /************************************************************************/ ! 678: ! 679: enterscore() ! 680: { ! 681: struct scoreboard sbuf; /* buffer to read in scoreboard entries */ ! 682: FILE *fp; /* to open scoreboard file */ ! 683: long loc = 0L; /* location in scoreboard file */ ! 684: bool found = FALSE; /* set if we found an entry for this login */ ! 685: ! 686: if ((fp = fopen(_PATH_SCORE, "r+")) != NULL) ! 687: { ! 688: while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1) ! 689: if (strcmp(Player.p_login, sbuf.sb_login) == 0) ! 690: { ! 691: found = TRUE; ! 692: break; ! 693: } ! 694: else ! 695: loc += SZ_SCORESTRUCT; ! 696: } ! 697: else ! 698: { ! 699: error(_PATH_SCORE); ! 700: /*NOTREACHED*/ ! 701: } ! 702: ! 703: /* ! 704: * At this point, 'loc' will either indicate a point beyond ! 705: * the end of file, or the place where the previous entry ! 706: * was found. ! 707: */ ! 708: ! 709: if ((!found) || Player.p_level > sbuf.sb_level) ! 710: /* put new entry in for this login */ ! 711: { ! 712: strcpy(sbuf.sb_login, Player.p_login); ! 713: strcpy(sbuf.sb_name, Player.p_name); ! 714: sbuf.sb_level = Player.p_level; ! 715: strcpy(sbuf.sb_type, descrtype(&Player, TRUE)); ! 716: } ! 717: ! 718: /* update entry */ ! 719: fseek(fp, loc, 0); ! 720: fwrite((char *) &sbuf, SZ_SCORESTRUCT, 1, fp); ! 721: fclose(fp); ! 722: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.