1999-09-09 01:57:16 +04:00
|
|
|
/* $NetBSD: gamesupport.c,v 1.6 1999/09/08 21:57:19 jsm Exp $ */
|
1995-03-24 06:58:08 +03:00
|
|
|
|
1994-10-22 00:19:39 +03:00
|
|
|
/*
|
|
|
|
* gamesupport.c - auxiliary routines for support of Phantasia
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "include.h"
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
void
|
1994-10-22 00:19:39 +03:00
|
|
|
changestats(ingameflag)
|
1997-10-13 06:18:06 +04:00
|
|
|
bool ingameflag;
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
static char flag[2] = /* for printing values of bools */
|
1994-10-22 00:19:39 +03:00
|
|
|
{'F', 'T'};
|
1997-10-13 06:18:06 +04:00
|
|
|
struct player *playerp; /* pointer to structure to alter */
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
const char *prompt; /* pointer to prompt string */
|
1997-10-13 06:18:06 +04:00
|
|
|
int c; /* input */
|
|
|
|
int today; /* day of year of today */
|
|
|
|
int temp; /* temporary variable */
|
|
|
|
long loc; /* location in player file */
|
|
|
|
time_t now; /* time now */
|
|
|
|
double dtemp; /* temporary variable */
|
|
|
|
bool *bptr; /* pointer to bool item to change */
|
|
|
|
double *dptr; /* pointer to double item to change */
|
|
|
|
short *sptr; /* pointer to short item to change */
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
/* get name of player to examine/alter */
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
mvaddstr(5, 0, "Which character do you want to look at ? ");
|
|
|
|
getstring(Databuf, SZ_DATABUF);
|
|
|
|
truncstring(Databuf);
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
if (Databuf[0] == '\0')
|
|
|
|
userlist(ingameflag);
|
|
|
|
else
|
|
|
|
break;
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
loc = -1L;
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
if (!ingameflag)
|
|
|
|
/* use 'Player' structure */
|
|
|
|
playerp = &Player;
|
|
|
|
else
|
|
|
|
if (strcmp(Databuf, Player.p_name) == 0)
|
|
|
|
/* alter/examine current player */
|
|
|
|
{
|
|
|
|
playerp = &Player;
|
|
|
|
loc = Fileloc;
|
|
|
|
} else
|
|
|
|
/* use 'Other' structure */
|
|
|
|
playerp = &Other;
|
|
|
|
|
|
|
|
/* find player on file */
|
|
|
|
if (loc < 0L && (loc = findname(Databuf, playerp)) < 0L)
|
|
|
|
/* didn't find player */
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
clear();
|
|
|
|
mvaddstr(11, 0, "Not found.");
|
|
|
|
return;
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
1997-10-13 06:18:06 +04:00
|
|
|
time(&now);
|
|
|
|
today = localtime(&now)->tm_yday;
|
1994-10-22 00:19:39 +03:00
|
|
|
|
|
|
|
clear();
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
for (;;)
|
|
|
|
/* print player structure, and prompt for action */
|
|
|
|
{
|
|
|
|
mvprintw(0, 0, "A:Name %s\n", playerp->p_name);
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
if (Wizard)
|
|
|
|
printw("B:Password %s\n", playerp->p_password);
|
|
|
|
else
|
|
|
|
addstr("B:Password XXXXXXXX\n");
|
|
|
|
|
|
|
|
printw(" :Login %s\n", playerp->p_login);
|
|
|
|
|
|
|
|
printw("C:Experience %.0f\n", playerp->p_experience);
|
|
|
|
printw("D:Level %.0f\n", playerp->p_level);
|
|
|
|
printw("E:Strength %.0f\n", playerp->p_strength);
|
|
|
|
printw("F:Sword %.0f\n", playerp->p_sword);
|
|
|
|
printw(" :Might %.0f\n", playerp->p_might);
|
|
|
|
printw("G:Energy %.0f\n", playerp->p_energy);
|
|
|
|
printw("H:Max-Energy %.0f\n", playerp->p_maxenergy);
|
|
|
|
printw("I:Shield %.0f\n", playerp->p_shield);
|
|
|
|
printw("J:Quickness %.0f\n", playerp->p_quickness);
|
|
|
|
printw("K:Quicksilver %.0f\n", playerp->p_quksilver);
|
|
|
|
printw(" :Speed %.0f\n", playerp->p_speed);
|
|
|
|
printw("L:Magic Level %.0f\n", playerp->p_magiclvl);
|
|
|
|
printw("M:Mana %.0f\n", playerp->p_mana);
|
|
|
|
printw("N:Brains %.0f\n", playerp->p_brains);
|
|
|
|
|
|
|
|
if (Wizard || playerp->p_specialtype != SC_VALAR)
|
|
|
|
mvaddstr(0, 40, descrstatus(playerp));
|
|
|
|
|
|
|
|
mvprintw(1, 40, "O:Poison %0.3f\n", playerp->p_poison);
|
|
|
|
mvprintw(2, 40, "P:Gold %.0f\n", playerp->p_gold);
|
|
|
|
mvprintw(3, 40, "Q:Gem %.0f\n", playerp->p_gems);
|
|
|
|
mvprintw(4, 40, "R:Sin %0.3f\n", playerp->p_sin);
|
|
|
|
if (Wizard) {
|
|
|
|
mvprintw(5, 40, "S:X-coord %.0f\n", playerp->p_x);
|
|
|
|
mvprintw(6, 40, "T:Y-coord %.0f\n", playerp->p_y);
|
|
|
|
} else {
|
|
|
|
mvaddstr(5, 40, "S:X-coord ?\n");
|
|
|
|
mvaddstr(6, 40, "T:Y-coord ?\n");
|
|
|
|
}
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
mvprintw(7, 40, "U:Age %ld\n", playerp->p_age);
|
|
|
|
mvprintw(8, 40, "V:Degenerated %d\n", playerp->p_degenerated);
|
|
|
|
|
|
|
|
mvprintw(9, 40, "W:Type %d (%s)\n",
|
|
|
|
playerp->p_type, descrtype(playerp, FALSE) + 1);
|
|
|
|
mvprintw(10, 40, "X:Special Type %d\n", playerp->p_specialtype);
|
|
|
|
mvprintw(11, 40, "Y:Lives %d\n", playerp->p_lives);
|
|
|
|
mvprintw(12, 40, "Z:Crowns %d\n", playerp->p_crowns);
|
|
|
|
mvprintw(13, 40, "0:Charms %d\n", playerp->p_charms);
|
|
|
|
mvprintw(14, 40, "1:Amulets %d\n", playerp->p_amulets);
|
|
|
|
mvprintw(15, 40, "2:Holy Water %d\n", playerp->p_holywater);
|
|
|
|
|
|
|
|
temp = today - playerp->p_lastused;
|
|
|
|
if (temp < 0)
|
|
|
|
/* last year */
|
|
|
|
temp += 365;
|
|
|
|
mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp->p_lastused, temp);
|
|
|
|
|
|
|
|
mvprintw(18, 8, "4:Palantir %c 5:Blessing %c 6:Virgin %c 7:Blind %c",
|
|
|
|
flag[(int)playerp->p_palantir],
|
|
|
|
flag[(int)playerp->p_blessing],
|
|
|
|
flag[(int)playerp->p_virgin],
|
|
|
|
flag[(int)playerp->p_blindness]);
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
if (!Wizard)
|
|
|
|
mvprintw(19, 8, "8:Ring %c",
|
|
|
|
flag[playerp->p_ring.ring_type != R_NONE]);
|
|
|
|
else
|
|
|
|
mvprintw(19, 8, "8:Ring %d 9:Duration %d",
|
|
|
|
playerp->p_ring.ring_type, playerp->p_ring.ring_duration);
|
|
|
|
|
|
|
|
if (!Wizard
|
|
|
|
/* not wizard */
|
|
|
|
&& (ingameflag || strcmp(Login, playerp->p_login) != 0))
|
|
|
|
/* in game or not examining own character */
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
if (ingameflag) {
|
|
|
|
more(LINES - 1);
|
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
cleanup(TRUE);
|
|
|
|
/* NOTREACHED */
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
1997-10-13 06:18:06 +04:00
|
|
|
mvaddstr(20, 0, "!:Quit ?:Delete");
|
|
|
|
mvaddstr(21, 0, "What would you like to change ? ");
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
if (Wizard)
|
|
|
|
c = getanswer(" ", TRUE);
|
|
|
|
else
|
|
|
|
/* examining own player; allow to change name and
|
|
|
|
* password */
|
|
|
|
c = getanswer("!BA", FALSE);
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'A': /* change name */
|
|
|
|
case 'B': /* change password */
|
|
|
|
if (!Wizard)
|
|
|
|
/* prompt for password */
|
|
|
|
{
|
|
|
|
mvaddstr(23, 0, "Password ? ");
|
|
|
|
Echo = FALSE;
|
|
|
|
getstring(Databuf, 9);
|
|
|
|
Echo = TRUE;
|
|
|
|
if (strcmp(Databuf, playerp->p_password) != 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (c == 'A')
|
|
|
|
/* get new name */
|
|
|
|
{
|
|
|
|
mvaddstr(23, 0, "New name: ");
|
|
|
|
getstring(Databuf, SZ_NAME);
|
|
|
|
truncstring(Databuf);
|
|
|
|
if (Databuf[0] != '\0')
|
|
|
|
if (Wizard || findname(Databuf, &Other) < 0L)
|
|
|
|
strcpy(playerp->p_name, Databuf);
|
|
|
|
} else
|
|
|
|
/* get new password */
|
|
|
|
{
|
|
|
|
if (!Wizard)
|
|
|
|
Echo = FALSE;
|
|
|
|
|
|
|
|
do
|
|
|
|
/* get two copies of new password
|
|
|
|
* until they match */
|
|
|
|
{
|
|
|
|
/* get first copy */
|
|
|
|
mvaddstr(23, 0, "New password ? ");
|
|
|
|
getstring(Databuf, SZ_PASSWORD);
|
|
|
|
if (Databuf[0] == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* get second copy */
|
|
|
|
mvaddstr(23, 0, "One more time ? ");
|
|
|
|
getstring(playerp->p_password, SZ_PASSWORD);
|
|
|
|
}
|
|
|
|
while (strcmp(playerp->p_password, Databuf) != 0);
|
|
|
|
|
|
|
|
Echo = TRUE;
|
|
|
|
}
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
continue;
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
case 'C': /* change experience */
|
|
|
|
prompt = "experience";
|
|
|
|
dptr = &playerp->p_experience;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'D': /* change level */
|
|
|
|
prompt = "level";
|
|
|
|
dptr = &playerp->p_level;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'E': /* change strength */
|
|
|
|
prompt = "strength";
|
|
|
|
dptr = &playerp->p_strength;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'F': /* change swords */
|
|
|
|
prompt = "sword";
|
|
|
|
dptr = &playerp->p_sword;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'G': /* change energy */
|
|
|
|
prompt = "energy";
|
|
|
|
dptr = &playerp->p_energy;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'H': /* change maximum energy */
|
|
|
|
prompt = "max energy";
|
|
|
|
dptr = &playerp->p_maxenergy;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'I': /* change shields */
|
|
|
|
prompt = "shield";
|
|
|
|
dptr = &playerp->p_shield;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'J': /* change quickness */
|
|
|
|
prompt = "quickness";
|
|
|
|
dptr = &playerp->p_quickness;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'K': /* change quicksilver */
|
|
|
|
prompt = "quicksilver";
|
|
|
|
dptr = &playerp->p_quksilver;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'L': /* change magic */
|
|
|
|
prompt = "magic level";
|
|
|
|
dptr = &playerp->p_magiclvl;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'M': /* change mana */
|
|
|
|
prompt = "mana";
|
|
|
|
dptr = &playerp->p_mana;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'N': /* change brains */
|
|
|
|
prompt = "brains";
|
|
|
|
dptr = &playerp->p_brains;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'O': /* change poison */
|
|
|
|
prompt = "poison";
|
|
|
|
dptr = &playerp->p_poison;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'P': /* change gold */
|
|
|
|
prompt = "gold";
|
|
|
|
dptr = &playerp->p_gold;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'Q': /* change gems */
|
|
|
|
prompt = "gems";
|
|
|
|
dptr = &playerp->p_gems;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'R': /* change sin */
|
|
|
|
prompt = "sin";
|
|
|
|
dptr = &playerp->p_sin;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'S': /* change x coord */
|
|
|
|
prompt = "x";
|
|
|
|
dptr = &playerp->p_x;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'T': /* change y coord */
|
|
|
|
prompt = "y";
|
|
|
|
dptr = &playerp->p_y;
|
|
|
|
goto DALTER;
|
|
|
|
|
|
|
|
case 'U': /* change age */
|
|
|
|
mvprintw(23, 0, "age = %ld; age = ", playerp->p_age);
|
|
|
|
dtemp = infloat();
|
|
|
|
if (dtemp != 0.0)
|
|
|
|
playerp->p_age = (long) dtemp;
|
1994-10-22 00:19:39 +03:00
|
|
|
continue;
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
case 'V': /* change degen */
|
|
|
|
mvprintw(23, 0, "degen = %d; degen = ", playerp->p_degenerated);
|
|
|
|
dtemp = infloat();
|
|
|
|
if (dtemp != 0.0)
|
|
|
|
playerp->p_degenerated = (int) dtemp;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case 'W': /* change type */
|
|
|
|
prompt = "type";
|
|
|
|
sptr = &playerp->p_type;
|
|
|
|
goto SALTER;
|
|
|
|
|
|
|
|
case 'X': /* change special type */
|
|
|
|
prompt = "special type";
|
|
|
|
sptr = &playerp->p_specialtype;
|
|
|
|
goto SALTER;
|
|
|
|
|
|
|
|
case 'Y': /* change lives */
|
|
|
|
prompt = "lives";
|
|
|
|
sptr = &playerp->p_lives;
|
|
|
|
goto SALTER;
|
|
|
|
|
|
|
|
case 'Z': /* change crowns */
|
|
|
|
prompt = "crowns";
|
|
|
|
sptr = &playerp->p_crowns;
|
|
|
|
goto SALTER;
|
|
|
|
|
|
|
|
case '0': /* change charms */
|
|
|
|
prompt = "charm";
|
|
|
|
sptr = &playerp->p_charms;
|
|
|
|
goto SALTER;
|
|
|
|
|
|
|
|
case '1': /* change amulet */
|
|
|
|
prompt = "amulet";
|
|
|
|
sptr = &playerp->p_amulets;
|
|
|
|
goto SALTER;
|
|
|
|
|
|
|
|
case '2': /* change holy water */
|
|
|
|
prompt = "holy water";
|
|
|
|
sptr = &playerp->p_holywater;
|
|
|
|
goto SALTER;
|
|
|
|
|
|
|
|
case '3': /* change last-used */
|
|
|
|
prompt = "last-used";
|
|
|
|
sptr = &playerp->p_lastused;
|
|
|
|
goto SALTER;
|
|
|
|
|
|
|
|
case '4': /* change palantir */
|
|
|
|
prompt = "palantir";
|
|
|
|
bptr = &playerp->p_palantir;
|
|
|
|
goto BALTER;
|
|
|
|
|
|
|
|
case '5': /* change blessing */
|
|
|
|
prompt = "blessing";
|
|
|
|
bptr = &playerp->p_blessing;
|
|
|
|
goto BALTER;
|
|
|
|
|
|
|
|
case '6': /* change virgin */
|
|
|
|
prompt = "virgin";
|
|
|
|
bptr = &playerp->p_virgin;
|
|
|
|
goto BALTER;
|
|
|
|
|
|
|
|
case '7': /* change blindness */
|
|
|
|
prompt = "blindness";
|
|
|
|
bptr = &playerp->p_blindness;
|
|
|
|
goto BALTER;
|
|
|
|
|
|
|
|
case '8': /* change ring type */
|
|
|
|
prompt = "ring-type";
|
|
|
|
sptr = &playerp->p_ring.ring_type;
|
|
|
|
goto SALTER;
|
|
|
|
|
|
|
|
case '9': /* change ring duration */
|
|
|
|
prompt = "ring-duration";
|
|
|
|
sptr = &playerp->p_ring.ring_duration;
|
|
|
|
goto SALTER;
|
|
|
|
|
|
|
|
case '!': /* quit, update */
|
|
|
|
if (Wizard &&
|
|
|
|
(!ingameflag || playerp != &Player))
|
|
|
|
/* turn off status if not modifying self */
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
playerp->p_status = S_OFF;
|
|
|
|
playerp->p_tampered = T_OFF;
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
1997-10-13 06:18:06 +04:00
|
|
|
writerecord(playerp, loc);
|
|
|
|
clear();
|
|
|
|
return;
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
case '?': /* delete player */
|
|
|
|
if (ingameflag && playerp == &Player)
|
|
|
|
/* cannot delete self */
|
|
|
|
continue;
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
freerecord(playerp, loc);
|
|
|
|
clear();
|
|
|
|
return;
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DALTER:
|
|
|
|
mvprintw(23, 0, "%s = %f; %s = ", prompt, *dptr, prompt);
|
1994-10-22 00:19:39 +03:00
|
|
|
dtemp = infloat();
|
|
|
|
if (dtemp != 0.0)
|
1997-10-13 06:18:06 +04:00
|
|
|
*dptr = dtemp;
|
1994-10-22 00:19:39 +03:00
|
|
|
continue;
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
SALTER:
|
|
|
|
mvprintw(23, 0, "%s = %d; %s = ", prompt, *sptr, prompt);
|
1994-10-22 00:19:39 +03:00
|
|
|
dtemp = infloat();
|
|
|
|
if (dtemp != 0.0)
|
1997-10-13 06:18:06 +04:00
|
|
|
*sptr = (short) dtemp;
|
1994-10-22 00:19:39 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
BALTER:
|
1997-10-13 06:18:06 +04:00
|
|
|
mvprintw(23, 0, "%s = %c; %s = ", prompt, flag[(int)*bptr],
|
|
|
|
prompt);
|
|
|
|
c = getanswer("\nTF", TRUE);
|
|
|
|
if (c == 'T')
|
|
|
|
*bptr = TRUE;
|
|
|
|
else
|
|
|
|
if (c == 'F')
|
|
|
|
*bptr = FALSE;
|
|
|
|
continue;
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
void
|
1994-10-22 00:19:39 +03:00
|
|
|
monstlist()
|
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
int count = 0; /* count in file */
|
|
|
|
|
|
|
|
puts(" #) Name Str Brain Quick Energy Exper Treas Type Flock%\n");
|
1999-09-09 01:57:16 +04:00
|
|
|
fseek(Monstfp, 0L, SEEK_SET);
|
1997-10-13 06:18:06 +04:00
|
|
|
while (fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp) == 1)
|
|
|
|
printf("%2d) %-20.20s%4.0f %4.0f %2.0f %5.0f %5.0f %2d %2d %3.0f\n", count++,
|
|
|
|
Curmonster.m_name, Curmonster.m_strength, Curmonster.m_brains,
|
|
|
|
Curmonster.m_speed, Curmonster.m_energy, Curmonster.m_experience,
|
|
|
|
Curmonster.m_treasuretype, Curmonster.m_type, Curmonster.m_flock);
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
void
|
1994-10-22 00:19:39 +03:00
|
|
|
scorelist()
|
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
struct scoreboard sbuf; /* for reading entries */
|
|
|
|
FILE *fp; /* to open the file */
|
|
|
|
|
|
|
|
if ((fp = fopen(_PATH_SCORE, "r")) != NULL) {
|
|
|
|
while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
|
|
|
|
printf("%-20s (%-9s) Level: %6.0f Type: %s\n",
|
|
|
|
sbuf.sb_name, sbuf.sb_login, sbuf.sb_level, sbuf.sb_type);
|
|
|
|
fclose(fp);
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
void
|
1994-10-22 00:19:39 +03:00
|
|
|
activelist()
|
|
|
|
{
|
1999-09-09 01:57:16 +04:00
|
|
|
fseek(Playersfp, 0L, SEEK_SET);
|
1997-10-13 06:18:06 +04:00
|
|
|
printf("Current characters on file are:\n\n");
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
|
|
|
|
if (Other.p_status != S_NOTUSED)
|
|
|
|
printf("%-20s (%-9s) Level: %6.0f %s (%s)\n",
|
|
|
|
Other.p_name, Other.p_login, Other.p_level,
|
|
|
|
descrtype(&Other, FALSE), descrstatus(&Other));
|
1994-10-22 00:19:39 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
void
|
1994-10-22 00:19:39 +03:00
|
|
|
purgeoldplayers()
|
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
int today; /* day of year for today */
|
|
|
|
int daysold; /* how many days since the character has been
|
|
|
|
* used */
|
|
|
|
time_t ltime; /* time in seconds */
|
|
|
|
long loc = 0L; /* location in file */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
time(<ime);
|
|
|
|
today = localtime(<ime)->tm_yday;
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
for (;;) {
|
1999-09-09 01:57:16 +04:00
|
|
|
fseek(Playersfp, loc, SEEK_SET);
|
1997-10-13 06:18:06 +04:00
|
|
|
if (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) != 1)
|
|
|
|
break;
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
daysold = today - Other.p_lastused;
|
|
|
|
if (daysold < 0)
|
|
|
|
daysold += 365;
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
if (daysold > N_DAYSOLD)
|
|
|
|
/* player hasn't been used in a while; delete */
|
|
|
|
freerecord(&Other, loc);
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
loc += SZ_PLAYERSTRUCT;
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
void
|
1994-10-22 00:19:39 +03:00
|
|
|
enterscore()
|
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
struct scoreboard sbuf; /* buffer to read in scoreboard entries */
|
|
|
|
FILE *fp; /* to open scoreboard file */
|
|
|
|
long loc = 0L; /* location in scoreboard file */
|
|
|
|
bool found = FALSE; /* set if we found an entry for this login */
|
|
|
|
|
|
|
|
if ((fp = fopen(_PATH_SCORE, "r+")) != NULL) {
|
|
|
|
while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
|
|
|
|
if (strcmp(Player.p_login, sbuf.sb_login) == 0) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
loc += SZ_SCORESTRUCT;
|
|
|
|
} else {
|
|
|
|
error(_PATH_SCORE);
|
|
|
|
/* NOTREACHED */
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
/*
|
|
|
|
* At this point, 'loc' will either indicate a point beyond
|
|
|
|
* the end of file, or the place where the previous entry
|
|
|
|
* was found.
|
|
|
|
*/
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
if ((!found) || Player.p_level > sbuf.sb_level)
|
|
|
|
/* put new entry in for this login */
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
strcpy(sbuf.sb_login, Player.p_login);
|
|
|
|
strcpy(sbuf.sb_name, Player.p_name);
|
|
|
|
sbuf.sb_level = Player.p_level;
|
|
|
|
strcpy(sbuf.sb_type, descrtype(&Player, TRUE));
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
1997-10-13 06:18:06 +04:00
|
|
|
/* update entry */
|
1999-09-09 01:57:16 +04:00
|
|
|
fseek(fp, loc, SEEK_SET);
|
1997-10-13 06:18:06 +04:00
|
|
|
fwrite((char *) &sbuf, SZ_SCORESTRUCT, 1, fp);
|
|
|
|
fclose(fp);
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|