Home | History | Annotate | Line # | Download | only in phantasia
gamesupport.c revision 1.1
      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 /**/
    491 /************************************************************************
    492 /
    493 / FUNCTION NAME: monstlist()
    494 /
    495 / FUNCTION: print a monster listing
    496 /
    497 / AUTHOR: E. A. Estes, 2/27/86
    498 /
    499 / ARGUMENTS: none
    500 /
    501 / RETURN VALUE: none
    502 /
    503 / MODULES CALLED: puts(), fread(), fseek(), printf()
    504 /
    505 / GLOBAL INPUTS: Curmonster, *Monstfp
    506 /
    507 / GLOBAL OUTPUTS: none
    508 /
    509 / DESCRIPTION:
    510 /	Read monster file, and print a monster listing on standard output.
    511 /
    512 /************************************************************************/
    513 
    514 monstlist()
    515 {
    516 register int 	count = 0;		/* count in file */
    517 
    518     puts(" #)  Name                 Str  Brain  Quick  Energy  Exper  Treas  Type  Flock%\n");
    519     fseek(Monstfp, 0L, 0);
    520     while (fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp) == 1)
    521 	printf("%2d)  %-20.20s%4.0f   %4.0f     %2.0f   %5.0f  %5.0f     %2d    %2d     %3.0f\n", count++,
    522 	    Curmonster.m_name, Curmonster.m_strength, Curmonster.m_brains,
    523 	    Curmonster.m_speed, Curmonster.m_energy, Curmonster.m_experience,
    524 	    Curmonster.m_treasuretype, Curmonster.m_type, Curmonster.m_flock);
    525 }
    526 /**/
    528 /************************************************************************
    529 /
    530 / FUNCTION NAME: scorelist()
    531 /
    532 / FUNCTION: print player score board
    533 /
    534 / AUTHOR: E. A. Estes, 12/4/85
    535 /
    536 / ARGUMENTS: none
    537 /
    538 / RETURN VALUE: none
    539 /
    540 / MODULES CALLED: fread(), fopen(), printf(), fclose()
    541 /
    542 / GLOBAL INPUTS:
    543 /
    544 / GLOBAL OUTPUTS: none
    545 /
    546 / DESCRIPTION:
    547 /	Read the scoreboard file and print the contents.
    548 /
    549 /************************************************************************/
    550 
    551 scorelist()
    552 {
    553 struct	scoreboard	sbuf;	/* for reading entries */
    554 register FILE	*fp;		/* to open the file */
    555 
    556     if ((fp = fopen(_PATH_SCORE, "r")) != NULL)
    557 	{
    558 	while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
    559 	    printf("%-20s   (%-9s)  Level: %6.0f  Type: %s\n",
    560 		sbuf.sb_name, sbuf.sb_login, sbuf.sb_level, sbuf.sb_type);
    561 	fclose(fp);
    562 	}
    563 }
    564 /**/
    566 /************************************************************************
    567 /
    568 / FUNCTION NAME: activelist()
    569 /
    570 / FUNCTION: print list of active players to standard output
    571 /
    572 / AUTHOR: E. A. Estes, 3/7/86
    573 /
    574 / ARGUMENTS: none
    575 /
    576 / RETURN VALUE: none
    577 /
    578 / MODULES CALLED: descrstatus(), fread(), fseek(), printf(), descrtype()
    579 /
    580 / GLOBAL INPUTS: Other, *Playersfp
    581 /
    582 / GLOBAL OUTPUTS: none
    583 /
    584 / DESCRIPTION:
    585 /	Read player file, and print list of active records to standard output.
    586 /
    587 /************************************************************************/
    588 
    589 activelist()
    590 {
    591     fseek(Playersfp, 0L, 0);
    592     printf("Current characters on file are:\n\n");
    593 
    594     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
    595 	if (Other.p_status != S_NOTUSED)
    596 	    printf("%-20s   (%-9s)  Level: %6.0f  %s  (%s)\n",
    597 		Other.p_name, Other.p_login, Other.p_level,
    598 		descrtype(&Other, FALSE), descrstatus(&Other));
    599 
    600 }
    601 /**/
    603 /************************************************************************
    604 /
    605 / FUNCTION NAME: purgeoldplayers()
    606 /
    607 / FUNCTION: purge inactive players from player file
    608 /
    609 / AUTHOR: E. A. Estes, 12/4/85
    610 /
    611 / ARGUMENTS: none
    612 /
    613 / RETURN VALUE: none
    614 /
    615 / MODULES CALLED: freerecord(), time(), fread(), fseek(), localtime()
    616 /
    617 / GLOBAL INPUTS: Other, *Playersfp
    618 /
    619 / GLOBAL OUTPUTS: none
    620 /
    621 / DESCRIPTION:
    622 /	Delete characters which have not been used with the last
    623 /	three weeks.
    624 /
    625 /************************************************************************/
    626 
    627 purgeoldplayers()
    628 {
    629 int	today;		/* day of year for today */
    630 int	daysold;	/* how many days since the character has been used */
    631 long	ltime;		/* time in seconds */
    632 long	loc = 0L;	/* location in file */
    633 
    634     time(&ltime);
    635     today = localtime(&ltime)->tm_yday;
    636 
    637     for (;;)
    638 	{
    639 	fseek(Playersfp, loc, 0);
    640 	if (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) != 1)
    641 	    break;
    642 
    643 	daysold = today - Other.p_lastused;
    644 	if (daysold < 0)
    645 	    daysold += 365;
    646 
    647 	if (daysold > N_DAYSOLD)
    648 	    /* player hasn't been used in a while; delete */
    649 	    freerecord(&Other, loc);
    650 
    651 	loc += SZ_PLAYERSTRUCT;
    652 	}
    653 }
    654 /**/
    656 /************************************************************************
    657 /
    658 / FUNCTION NAME: enterscore()
    659 /
    660 / FUNCTION: enter player into scoreboard
    661 /
    662 / AUTHOR: E. A. Estes, 12/4/85
    663 /
    664 / ARGUMENTS: none
    665 /
    666 / RETURN VALUE: none
    667 /
    668 / MODULES CALLED: fread(), fseek(), fopen(), error(), strcmp(), fclose(),
    669 /	strcpy(), fwrite(), descrtype()
    670 /
    671 / GLOBAL INPUTS: Player
    672 /
    673 / GLOBAL OUTPUTS: none
    674 /
    675 / DESCRIPTION:
    676 /	The scoreboard keeps track of the highest character on a
    677 /	per-login basis.
    678 /	Search the scoreboard for an entry for the current login,
    679 /	if an entry is found, and it is lower than the current player,
    680 /	replace it, otherwise create an entry.
    681 /
    682 /************************************************************************/
    683 
    684 enterscore()
    685 {
    686 struct	scoreboard sbuf;		/* buffer to read in scoreboard entries */
    687 FILE	*fp;				/* to open scoreboard file */
    688 long	loc = 0L;			/* location in scoreboard file */
    689 bool	found = FALSE;			/* set if we found an entry for this login */
    690 
    691     if ((fp = fopen(_PATH_SCORE, "r+")) != NULL)
    692 	{
    693 	while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
    694 	    if (strcmp(Player.p_login, sbuf.sb_login) == 0)
    695 		{
    696 		found = TRUE;
    697 		break;
    698 		}
    699 	    else
    700 		loc += SZ_SCORESTRUCT;
    701 	}
    702     else
    703 	{
    704 	error(_PATH_SCORE);
    705 	/*NOTREACHED*/
    706 	}
    707 
    708     /*
    709      * At this point, 'loc' will either indicate a point beyond
    710      * the end of file, or the place where the previous entry
    711      * was found.
    712      */
    713 
    714     if ((!found) || Player.p_level > sbuf.sb_level)
    715 	/* put new entry in for this login */
    716 	{
    717 	strcpy(sbuf.sb_login, Player.p_login);
    718 	strcpy(sbuf.sb_name, Player.p_name);
    719 	sbuf.sb_level = Player.p_level;
    720 	strcpy(sbuf.sb_type, descrtype(&Player, TRUE));
    721 	}
    722 
    723     /* update entry */
    724     fseek(fp, loc, 0);
    725     fwrite((char *) &sbuf, SZ_SCORESTRUCT, 1, fp);
    726     fclose(fp);
    727 }
    728