134602Sbostic /*
234602Sbostic * gamesupport.c - auxiliary routines for support of Phantasia
334602Sbostic */
434602Sbostic
534602Sbostic #include "include.h"
634602Sbostic
734602Sbostic /************************************************************************
834602Sbostic /
934602Sbostic / FUNCTION NAME: changestats()
1034602Sbostic /
1134602Sbostic / FUNCTION: examine/change statistics for a player
1234602Sbostic /
1334602Sbostic / AUTHOR: E. A. Estes, 12/4/85
1434602Sbostic /
1534602Sbostic / ARGUMENTS:
1634602Sbostic / bool ingameflag - set if called while playing game (Wizard only)
1734602Sbostic /
1834602Sbostic / RETURN VALUE: none
1934602Sbostic /
2034602Sbostic / MODULES CALLED: freerecord(), writerecord(), descrstatus(), truncstring(),
2134602Sbostic / time(), more(), wmove(), wclear(), strcmp(), printw(), strcpy(),
2234602Sbostic / infloat(), waddstr(), cleanup(), findname(), userlist(), mvprintw(),
2334602Sbostic / localtime(), getanswer(), descrtype(), getstring()
2434602Sbostic /
2534602Sbostic / GLOBAL INPUTS: LINES, *Login, Other, Wizard, Player, *stdscr, Databuf[],
2634602Sbostic / Fileloc
2734602Sbostic /
2834602Sbostic / GLOBAL OUTPUTS: Echo
2934602Sbostic /
3034602Sbostic / DESCRIPTION:
3134602Sbostic / Prompt for player name to examine/change.
3234602Sbostic / If the name is NULL, print a list of all players.
3334602Sbostic / If we are called from within the game, check for the
3434602Sbostic / desired name being the same as the current player's name.
3534602Sbostic / Only the 'Wizard' may alter players.
3634602Sbostic / Items are changed only if a non-zero value is specified.
3734602Sbostic / To change an item to 0, use 0.1; it will be truncated later.
3834602Sbostic /
3934602Sbostic / Players may alter their names and passwords, if the following
4034602Sbostic / are true:
4134602Sbostic / - current login matches the character's logins
4234602Sbostic / - the password is known
4334602Sbostic / - the player is not in the middle of the game (ingameflag == FALSE)
4434602Sbostic /
4534602Sbostic / The last condition is imposed for two reasons:
4634602Sbostic / - the game could possibly get a bit hectic if a player were
4734602Sbostic / continually changing his/her name
4834602Sbostic / - another player structure would be necessary to check for names
4934602Sbostic / already in use
5034602Sbostic /
5134602Sbostic /************************************************************************/
5234602Sbostic
changestats(ingameflag)5334602Sbostic changestats(ingameflag)
5434602Sbostic bool ingameflag;
5534602Sbostic {
5634602Sbostic static char flag[2] = /* for printing values of bools */
5734602Sbostic {'F', 'T'};
5834602Sbostic register struct player *playerp;/* pointer to structure to alter */
5934602Sbostic register char *prompt; /* pointer to prompt string */
6034602Sbostic int c; /* input */
6134602Sbostic int today; /* day of year of today */
6234602Sbostic int temp; /* temporary variable */
6334602Sbostic long loc; /* location in player file */
6434602Sbostic long now; /* time now */
6534602Sbostic double dtemp; /* temporary variable */
6634602Sbostic bool *bptr; /* pointer to bool item to change */
6734602Sbostic double *dptr; /* pointer to double item to change */
6834602Sbostic short *sptr; /* pointer to short item to change */
6934602Sbostic
7034602Sbostic clear();
7134602Sbostic
7234602Sbostic for (;;)
7334602Sbostic /* get name of player to examine/alter */
7434602Sbostic {
7534602Sbostic mvaddstr(5, 0, "Which character do you want to look at ? ");
7634602Sbostic getstring(Databuf, SZ_DATABUF);
7734602Sbostic truncstring(Databuf);
7834602Sbostic
7934602Sbostic if (Databuf[0] == '\0')
8034602Sbostic userlist(ingameflag);
8134602Sbostic else
8234602Sbostic break;
8334602Sbostic }
8434602Sbostic
8534602Sbostic loc = -1L;
8634602Sbostic
8734602Sbostic if (!ingameflag)
8834602Sbostic /* use 'Player' structure */
8934602Sbostic playerp = &Player;
9034602Sbostic else if (strcmp(Databuf, Player.p_name) == 0)
9134602Sbostic /* alter/examine current player */
9234602Sbostic {
9334602Sbostic playerp = &Player;
9434602Sbostic loc = Fileloc;
9534602Sbostic }
9634602Sbostic else
9734602Sbostic /* use 'Other' structure */
9834602Sbostic playerp = &Other;
9934602Sbostic
10034602Sbostic /* find player on file */
10134602Sbostic if (loc < 0L && (loc = findname(Databuf, playerp)) < 0L)
10234602Sbostic /* didn't find player */
10334602Sbostic {
10434602Sbostic clear();
10534602Sbostic mvaddstr(11, 0, "Not found.");
10634602Sbostic return;
10734602Sbostic }
10834602Sbostic
10934602Sbostic time(&now);
11034602Sbostic today = localtime(&now)->tm_yday;
11134602Sbostic
11234602Sbostic clear();
11334602Sbostic
11434602Sbostic for (;;)
11534602Sbostic /* print player structure, and prompt for action */
11634602Sbostic {
11734602Sbostic mvprintw(0, 0,"A:Name %s\n", playerp->p_name);
11834602Sbostic
11934602Sbostic if (Wizard)
12034602Sbostic printw("B:Password %s\n", playerp->p_password);
12134602Sbostic else
12234602Sbostic addstr("B:Password XXXXXXXX\n");
12334602Sbostic
12434602Sbostic printw(" :Login %s\n", playerp->p_login);
12534602Sbostic
12634602Sbostic printw("C:Experience %.0f\n", playerp->p_experience);
12734602Sbostic printw("D:Level %.0f\n", playerp->p_level);
12834602Sbostic printw("E:Strength %.0f\n", playerp->p_strength);
12934602Sbostic printw("F:Sword %.0f\n", playerp->p_sword);
13034602Sbostic printw(" :Might %.0f\n", playerp->p_might);
13134602Sbostic printw("G:Energy %.0f\n", playerp->p_energy);
13234602Sbostic printw("H:Max-Energy %.0f\n", playerp->p_maxenergy);
13334602Sbostic printw("I:Shield %.0f\n", playerp->p_shield);
13434602Sbostic printw("J:Quickness %.0f\n", playerp->p_quickness);
13534602Sbostic printw("K:Quicksilver %.0f\n", playerp->p_quksilver);
13634602Sbostic printw(" :Speed %.0f\n", playerp->p_speed);
13734602Sbostic printw("L:Magic Level %.0f\n", playerp->p_magiclvl);
13834602Sbostic printw("M:Mana %.0f\n", playerp->p_mana);
13934602Sbostic printw("N:Brains %.0f\n", playerp->p_brains);
14034602Sbostic
14134602Sbostic if (Wizard || playerp->p_specialtype != SC_VALAR)
14234602Sbostic mvaddstr(0, 40, descrstatus(playerp));
14334602Sbostic
14434602Sbostic mvprintw(1, 40, "O:Poison %0.3f\n", playerp->p_poison);
14534602Sbostic mvprintw(2, 40, "P:Gold %.0f\n", playerp->p_gold);
14634602Sbostic mvprintw(3, 40, "Q:Gem %.0f\n", playerp->p_gems);
14734602Sbostic mvprintw(4, 40, "R:Sin %0.3f\n", playerp->p_sin);
14834602Sbostic if (Wizard)
14934602Sbostic {
15034602Sbostic mvprintw(5, 40, "S:X-coord %.0f\n", playerp->p_x);
15134602Sbostic mvprintw(6, 40, "T:Y-coord %.0f\n", playerp->p_y);
15234602Sbostic }
15334602Sbostic else
15434602Sbostic {
15534602Sbostic mvaddstr(5, 40, "S:X-coord ?\n");
15634602Sbostic mvaddstr(6, 40, "T:Y-coord ?\n");
15734602Sbostic }
15834602Sbostic
15934602Sbostic mvprintw(7, 40, "U:Age %ld\n", playerp->p_age);
16034602Sbostic mvprintw(8, 40, "V:Degenerated %d\n", playerp->p_degenerated);
16134602Sbostic
16234602Sbostic mvprintw(9, 40, "W:Type %d (%s)\n",
16334602Sbostic playerp->p_type, descrtype(playerp, FALSE) + 1);
16434602Sbostic mvprintw(10, 40, "X:Special Type %d\n", playerp->p_specialtype);
16534602Sbostic mvprintw(11, 40, "Y:Lives %d\n", playerp->p_lives);
16634602Sbostic mvprintw(12, 40, "Z:Crowns %d\n", playerp->p_crowns);
16734602Sbostic mvprintw(13, 40, "0:Charms %d\n", playerp->p_charms);
16834602Sbostic mvprintw(14, 40, "1:Amulets %d\n", playerp->p_amulets);
16934602Sbostic mvprintw(15, 40, "2:Holy Water %d\n", playerp->p_holywater);
17034602Sbostic
17134602Sbostic temp = today - playerp->p_lastused;
17234602Sbostic if (temp < 0)
17334602Sbostic /* last year */
17434602Sbostic temp += 365;
17534602Sbostic mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp->p_lastused, temp);
17634602Sbostic
17734602Sbostic mvprintw(18, 8, "4:Palantir %c 5:Blessing %c 6:Virgin %c 7:Blind %c",
17834602Sbostic flag[playerp->p_palantir],
17934602Sbostic flag[playerp->p_blessing],
18034602Sbostic flag[playerp->p_virgin],
18134602Sbostic flag[playerp->p_blindness]);
18234602Sbostic
18334602Sbostic if (!Wizard)
18434602Sbostic mvprintw(19, 8, "8:Ring %c",
18534602Sbostic flag[playerp->p_ring.ring_type != R_NONE]);
18634602Sbostic else
18734602Sbostic mvprintw(19, 8, "8:Ring %d 9:Duration %d",
18834602Sbostic playerp->p_ring.ring_type, playerp->p_ring.ring_duration);
18934602Sbostic
19034602Sbostic if (!Wizard
19134602Sbostic /* not wizard */
19234602Sbostic && (ingameflag || strcmp(Login, playerp->p_login) != 0))
19334602Sbostic /* in game or not examining own character */
19434602Sbostic {
19534602Sbostic if (ingameflag)
19634602Sbostic {
19734602Sbostic more(LINES - 1);
19834602Sbostic clear();
19934602Sbostic return;
20034602Sbostic }
20134602Sbostic else
20234602Sbostic cleanup(TRUE);
20334602Sbostic /*NOTREACHED*/
20434602Sbostic }
20534602Sbostic
20634602Sbostic mvaddstr(20, 0, "!:Quit ?:Delete");
20734602Sbostic mvaddstr(21, 0, "What would you like to change ? ");
20834602Sbostic
20934602Sbostic if (Wizard)
21034602Sbostic c = getanswer(" ", TRUE);
21134602Sbostic else
21234602Sbostic /* examining own player; allow to change name and password */
21334602Sbostic c = getanswer("!BA", FALSE);
21434602Sbostic
21534602Sbostic switch (c)
21634602Sbostic {
21734602Sbostic case 'A': /* change name */
21834602Sbostic case 'B': /* change password */
21934602Sbostic if (!Wizard)
22034602Sbostic /* prompt for password */
22134602Sbostic {
22234602Sbostic mvaddstr(23, 0, "Password ? ");
22334602Sbostic Echo = FALSE;
22434602Sbostic getstring(Databuf, 9);
22534602Sbostic Echo = TRUE;
22634602Sbostic if (strcmp(Databuf, playerp->p_password) != 0)
22734602Sbostic continue;
22834602Sbostic }
22934602Sbostic
23034602Sbostic if (c == 'A')
23134602Sbostic /* get new name */
23234602Sbostic {
23334602Sbostic mvaddstr(23, 0, "New name: ");
23434602Sbostic getstring(Databuf, SZ_NAME);
23534602Sbostic truncstring(Databuf);
23634602Sbostic if (Databuf[0] != '\0')
23734602Sbostic if (Wizard || findname(Databuf, &Other) < 0L)
23834602Sbostic strcpy(playerp->p_name, Databuf);
23934602Sbostic }
24034602Sbostic else
24134602Sbostic /* get new password */
24234602Sbostic {
24334602Sbostic if (!Wizard)
24434602Sbostic Echo = FALSE;
24534602Sbostic
24634602Sbostic do
24734602Sbostic /* get two copies of new password until they match */
24834602Sbostic {
24934602Sbostic /* get first copy */
25034602Sbostic mvaddstr(23, 0, "New password ? ");
25134602Sbostic getstring(Databuf, SZ_PASSWORD);
25234602Sbostic if (Databuf[0] == '\0')
25334602Sbostic break;
25434602Sbostic
25534602Sbostic /* get second copy */
25634602Sbostic mvaddstr(23, 0, "One more time ? ");
25734602Sbostic getstring(playerp->p_password, SZ_PASSWORD);
25834602Sbostic }
25934602Sbostic while (strcmp(playerp->p_password, Databuf) != 0);
26034602Sbostic
26134602Sbostic Echo = TRUE;
26234602Sbostic }
26334602Sbostic
26434602Sbostic continue;
26534602Sbostic
26634602Sbostic case 'C': /* change experience */
26734602Sbostic prompt = "experience";
26834602Sbostic dptr = &playerp->p_experience;
26934602Sbostic goto DALTER;
27034602Sbostic
27134602Sbostic case 'D': /* change level */
27234602Sbostic prompt = "level";
27334602Sbostic dptr = &playerp->p_level;
27434602Sbostic goto DALTER;
27534602Sbostic
27634602Sbostic case 'E': /* change strength */
27734602Sbostic prompt = "strength";
27834602Sbostic dptr = &playerp->p_strength;
27934602Sbostic goto DALTER;
28034602Sbostic
28134602Sbostic case 'F': /* change swords */
28234602Sbostic prompt = "sword";
28334602Sbostic dptr = &playerp->p_sword;
28434602Sbostic goto DALTER;
28534602Sbostic
28634602Sbostic case 'G': /* change energy */
28734602Sbostic prompt = "energy";
28834602Sbostic dptr = &playerp->p_energy;
28934602Sbostic goto DALTER;
29034602Sbostic
29134602Sbostic case 'H': /* change maximum energy */
29234602Sbostic prompt = "max energy";
29334602Sbostic dptr = &playerp->p_maxenergy;
29434602Sbostic goto DALTER;
29534602Sbostic
29634602Sbostic case 'I': /* change shields */
29734602Sbostic prompt = "shield";
29834602Sbostic dptr = &playerp->p_shield;
29934602Sbostic goto DALTER;
30034602Sbostic
30134602Sbostic case 'J': /* change quickness */
30234602Sbostic prompt = "quickness";
30334602Sbostic dptr = &playerp->p_quickness;
30434602Sbostic goto DALTER;
30534602Sbostic
30634602Sbostic case 'K': /* change quicksilver */
30734602Sbostic prompt = "quicksilver";
30834602Sbostic dptr = &playerp->p_quksilver;
30934602Sbostic goto DALTER;
31034602Sbostic
31134602Sbostic case 'L': /* change magic */
31234602Sbostic prompt = "magic level";
31334602Sbostic dptr = &playerp->p_magiclvl;
31434602Sbostic goto DALTER;
31534602Sbostic
31634602Sbostic case 'M': /* change mana */
31734602Sbostic prompt = "mana";
31834602Sbostic dptr = &playerp->p_mana;
31934602Sbostic goto DALTER;
32034602Sbostic
32134602Sbostic case 'N': /* change brains */
32234602Sbostic prompt = "brains";
32334602Sbostic dptr = &playerp->p_brains;
32434602Sbostic goto DALTER;
32534602Sbostic
32634602Sbostic case 'O': /* change poison */
32734602Sbostic prompt = "poison";
32834602Sbostic dptr = &playerp->p_poison;
32934602Sbostic goto DALTER;
33034602Sbostic
33134602Sbostic case 'P': /* change gold */
33234602Sbostic prompt = "gold";
33334602Sbostic dptr = &playerp->p_gold;
33434602Sbostic goto DALTER;
33534602Sbostic
33634602Sbostic case 'Q': /* change gems */
33734602Sbostic prompt = "gems";
33834602Sbostic dptr = &playerp->p_gems;
33934602Sbostic goto DALTER;
34034602Sbostic
34134602Sbostic case 'R': /* change sin */
34234602Sbostic prompt = "sin";
34334602Sbostic dptr = &playerp->p_sin;
34434602Sbostic goto DALTER;
34534602Sbostic
34634602Sbostic case 'S': /* change x coord */
34734602Sbostic prompt = "x";
34834602Sbostic dptr = &playerp->p_x;
34934602Sbostic goto DALTER;
35034602Sbostic
35134602Sbostic case 'T': /* change y coord */
35234602Sbostic prompt = "y";
35334602Sbostic dptr = &playerp->p_y;
35434602Sbostic goto DALTER;
35534602Sbostic
35634602Sbostic case 'U': /* change age */
35734602Sbostic mvprintw(23, 0, "age = %ld; age = ", playerp->p_age);
35834602Sbostic dtemp = infloat();
35934602Sbostic if (dtemp != 0.0)
36034602Sbostic playerp->p_age = (long) dtemp;
36134602Sbostic continue;
36234602Sbostic
36334602Sbostic case 'V': /* change degen */
36434602Sbostic mvprintw(23, 0, "degen = %d; degen = ", playerp->p_degenerated);
36534602Sbostic dtemp = infloat();
36634602Sbostic if (dtemp != 0.0)
36734602Sbostic playerp->p_degenerated = (int) dtemp;
36834602Sbostic continue;
36934602Sbostic
37034602Sbostic case 'W': /* change type */
37134602Sbostic prompt = "type";
37234602Sbostic sptr = &playerp->p_type;
37334602Sbostic goto SALTER;
37434602Sbostic
37534602Sbostic case 'X': /* change special type */
37634602Sbostic prompt = "special type";
37734602Sbostic sptr = &playerp->p_specialtype;
37834602Sbostic goto SALTER;
37934602Sbostic
38034602Sbostic case 'Y': /* change lives */
38134602Sbostic prompt = "lives";
38234602Sbostic sptr = &playerp->p_lives;
38334602Sbostic goto SALTER;
38434602Sbostic
38534602Sbostic case 'Z': /* change crowns */
38634602Sbostic prompt = "crowns";
38734602Sbostic sptr = &playerp->p_crowns;
38834602Sbostic goto SALTER;
38934602Sbostic
39034602Sbostic case '0': /* change charms */
39134602Sbostic prompt = "charm";
39234602Sbostic sptr = &playerp->p_charms;
39334602Sbostic goto SALTER;
39434602Sbostic
39534602Sbostic case '1': /* change amulet */
39634602Sbostic prompt = "amulet";
39734602Sbostic sptr = &playerp->p_amulets;
39834602Sbostic goto SALTER;
39934602Sbostic
40034602Sbostic case '2': /* change holy water */
40134602Sbostic prompt = "holy water";
40234602Sbostic sptr = &playerp->p_holywater;
40334602Sbostic goto SALTER;
40434602Sbostic
40534602Sbostic case '3': /* change last-used */
40634602Sbostic prompt = "last-used";
40734602Sbostic sptr = &playerp->p_lastused;
40834602Sbostic goto SALTER;
40934602Sbostic
41034602Sbostic case '4': /* change palantir */
41134602Sbostic prompt = "palantir";
41234602Sbostic bptr = &playerp->p_palantir;
41334602Sbostic goto BALTER;
41434602Sbostic
41534602Sbostic case '5': /* change blessing */
41634602Sbostic prompt = "blessing";
41734602Sbostic bptr = &playerp->p_blessing;
41834602Sbostic goto BALTER;
41934602Sbostic
42034602Sbostic case '6': /* change virgin */
42134602Sbostic prompt = "virgin";
42234602Sbostic bptr = &playerp->p_virgin;
42334602Sbostic goto BALTER;
42434602Sbostic
42534602Sbostic case '7': /* change blindness */
42634602Sbostic prompt = "blindness";
42734602Sbostic bptr = &playerp->p_blindness;
42834602Sbostic goto BALTER;
42934602Sbostic
43034602Sbostic case '8': /* change ring type */
43134602Sbostic prompt = "ring-type";
43234602Sbostic sptr = &playerp->p_ring.ring_type;
43334602Sbostic goto SALTER;
43434602Sbostic
43534602Sbostic case '9': /* change ring duration */
43634602Sbostic prompt = "ring-duration";
43734602Sbostic sptr = &playerp->p_ring.ring_duration;
43834602Sbostic goto SALTER;
43934602Sbostic
44034602Sbostic case '!': /* quit, update */
44134602Sbostic if (Wizard &&
44234602Sbostic (!ingameflag || playerp != &Player))
44334602Sbostic /* turn off status if not modifying self */
44434602Sbostic {
44534602Sbostic playerp->p_status = S_OFF;
44634602Sbostic playerp->p_tampered = T_OFF;
44734602Sbostic }
44834602Sbostic
44934602Sbostic writerecord(playerp, loc);
45034602Sbostic clear();
45134602Sbostic return;
45234602Sbostic
45334602Sbostic case '?': /* delete player */
45434602Sbostic if (ingameflag && playerp == &Player)
45534602Sbostic /* cannot delete self */
45634602Sbostic continue;
45734602Sbostic
45834602Sbostic freerecord(playerp, loc);
45934602Sbostic clear();
46034602Sbostic return;
46134602Sbostic
46234602Sbostic default:
46334602Sbostic continue;
46434602Sbostic }
46534602Sbostic DALTER:
46634602Sbostic mvprintw(23, 0, "%s = %f; %s = ", prompt, *dptr, prompt);
46734602Sbostic dtemp = infloat();
46834602Sbostic if (dtemp != 0.0)
46934602Sbostic *dptr = dtemp;
47034602Sbostic continue;
47134602Sbostic
47234602Sbostic SALTER:
47334602Sbostic mvprintw(23, 0, "%s = %d; %s = ", prompt, *sptr, prompt);
47434602Sbostic dtemp = infloat();
47534602Sbostic if (dtemp != 0.0)
47634602Sbostic *sptr = (short) dtemp;
47734602Sbostic continue;
47834602Sbostic
47934602Sbostic BALTER:
48034602Sbostic mvprintw(23, 0, "%s = %c; %s = ", prompt, flag[*bptr], prompt);
48134602Sbostic c = getanswer("\nTF", TRUE);
48234602Sbostic if (c == 'T')
48334602Sbostic *bptr = TRUE;
48434602Sbostic else if (c == 'F')
48534602Sbostic *bptr = FALSE;
48634602Sbostic continue;
48734602Sbostic }
48834602Sbostic }
48934602Sbostic /**/
49034602Sbostic /************************************************************************
49134602Sbostic /
49234602Sbostic / FUNCTION NAME: monstlist()
49334602Sbostic /
49434602Sbostic / FUNCTION: print a monster listing
49534602Sbostic /
49634602Sbostic / AUTHOR: E. A. Estes, 2/27/86
49734602Sbostic /
49834602Sbostic / ARGUMENTS: none
49934602Sbostic /
50034602Sbostic / RETURN VALUE: none
50134602Sbostic /
50234602Sbostic / MODULES CALLED: puts(), fread(), fseek(), printf()
50334602Sbostic /
50434602Sbostic / GLOBAL INPUTS: Curmonster, *Monstfp
50534602Sbostic /
50634602Sbostic / GLOBAL OUTPUTS: none
50734602Sbostic /
50834602Sbostic / DESCRIPTION:
50934602Sbostic / Read monster file, and print a monster listing on standard output.
51034602Sbostic /
51134602Sbostic /************************************************************************/
51234602Sbostic
monstlist()51334602Sbostic monstlist()
51434602Sbostic {
51534602Sbostic register int count = 0; /* count in file */
51634602Sbostic
51734602Sbostic puts(" #) Name Str Brain Quick Energy Exper Treas Type Flock%\n");
51834602Sbostic fseek(Monstfp, 0L, 0);
51934602Sbostic while (fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp) == 1)
52034602Sbostic printf("%2d) %-20.20s%4.0f %4.0f %2.0f %5.0f %5.0f %2d %2d %3.0f\n", count++,
52134602Sbostic Curmonster.m_name, Curmonster.m_strength, Curmonster.m_brains,
52234602Sbostic Curmonster.m_speed, Curmonster.m_energy, Curmonster.m_experience,
52334602Sbostic Curmonster.m_treasuretype, Curmonster.m_type, Curmonster.m_flock);
52434602Sbostic }
52534602Sbostic /**/
52634602Sbostic /************************************************************************
52734602Sbostic /
52834602Sbostic / FUNCTION NAME: scorelist()
52934602Sbostic /
53034602Sbostic / FUNCTION: print player score board
53134602Sbostic /
53234602Sbostic / AUTHOR: E. A. Estes, 12/4/85
53334602Sbostic /
53434602Sbostic / ARGUMENTS: none
53534602Sbostic /
53634602Sbostic / RETURN VALUE: none
53734602Sbostic /
53834602Sbostic / MODULES CALLED: fread(), fopen(), printf(), fclose()
53934602Sbostic /
540*40279Sbostic / GLOBAL INPUTS:
54134602Sbostic /
54234602Sbostic / GLOBAL OUTPUTS: none
54334602Sbostic /
54434602Sbostic / DESCRIPTION:
54534602Sbostic / Read the scoreboard file and print the contents.
54634602Sbostic /
54734602Sbostic /************************************************************************/
54834602Sbostic
scorelist()54934602Sbostic scorelist()
55034602Sbostic {
55134602Sbostic struct scoreboard sbuf; /* for reading entries */
55234602Sbostic register FILE *fp; /* to open the file */
55334602Sbostic
554*40279Sbostic if ((fp = fopen(_PATH_SCORE, "r")) != NULL)
55534602Sbostic {
55634602Sbostic while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
55734602Sbostic printf("%-20s (%-9s) Level: %6.0f Type: %s\n",
55834602Sbostic sbuf.sb_name, sbuf.sb_login, sbuf.sb_level, sbuf.sb_type);
55934602Sbostic fclose(fp);
56034602Sbostic }
56134602Sbostic }
56234602Sbostic /**/
56334602Sbostic /************************************************************************
56434602Sbostic /
56534602Sbostic / FUNCTION NAME: activelist()
56634602Sbostic /
56734602Sbostic / FUNCTION: print list of active players to standard output
56834602Sbostic /
56934602Sbostic / AUTHOR: E. A. Estes, 3/7/86
57034602Sbostic /
57134602Sbostic / ARGUMENTS: none
57234602Sbostic /
57334602Sbostic / RETURN VALUE: none
57434602Sbostic /
57534602Sbostic / MODULES CALLED: descrstatus(), fread(), fseek(), printf(), descrtype()
57634602Sbostic /
57734602Sbostic / GLOBAL INPUTS: Other, *Playersfp
57834602Sbostic /
57934602Sbostic / GLOBAL OUTPUTS: none
58034602Sbostic /
58134602Sbostic / DESCRIPTION:
58234602Sbostic / Read player file, and print list of active records to standard output.
58334602Sbostic /
58434602Sbostic /************************************************************************/
58534602Sbostic
activelist()58634602Sbostic activelist()
58734602Sbostic {
58834602Sbostic fseek(Playersfp, 0L, 0);
58934602Sbostic printf("Current characters on file are:\n\n");
59034602Sbostic
59134602Sbostic while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
59234602Sbostic if (Other.p_status != S_NOTUSED)
59334602Sbostic printf("%-20s (%-9s) Level: %6.0f %s (%s)\n",
59434602Sbostic Other.p_name, Other.p_login, Other.p_level,
59534602Sbostic descrtype(&Other, FALSE), descrstatus(&Other));
59634602Sbostic
59734602Sbostic }
59834602Sbostic /**/
59934602Sbostic /************************************************************************
60034602Sbostic /
60134602Sbostic / FUNCTION NAME: purgeoldplayers()
60234602Sbostic /
60334602Sbostic / FUNCTION: purge inactive players from player file
60434602Sbostic /
60534602Sbostic / AUTHOR: E. A. Estes, 12/4/85
60634602Sbostic /
60734602Sbostic / ARGUMENTS: none
60834602Sbostic /
60934602Sbostic / RETURN VALUE: none
61034602Sbostic /
61134602Sbostic / MODULES CALLED: freerecord(), time(), fread(), fseek(), localtime()
61234602Sbostic /
61334602Sbostic / GLOBAL INPUTS: Other, *Playersfp
61434602Sbostic /
61534602Sbostic / GLOBAL OUTPUTS: none
61634602Sbostic /
61734602Sbostic / DESCRIPTION:
61834602Sbostic / Delete characters which have not been used with the last
61934602Sbostic / three weeks.
62034602Sbostic /
62134602Sbostic /************************************************************************/
62234602Sbostic
purgeoldplayers()62334602Sbostic purgeoldplayers()
62434602Sbostic {
62534602Sbostic int today; /* day of year for today */
62634602Sbostic int daysold; /* how many days since the character has been used */
62734602Sbostic long ltime; /* time in seconds */
62834602Sbostic long loc = 0L; /* location in file */
62934602Sbostic
63034602Sbostic time(<ime);
63134602Sbostic today = localtime(<ime)->tm_yday;
63234602Sbostic
63334602Sbostic for (;;)
63434602Sbostic {
63534602Sbostic fseek(Playersfp, loc, 0);
63634602Sbostic if (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) != 1)
63734602Sbostic break;
63834602Sbostic
63934602Sbostic daysold = today - Other.p_lastused;
64034602Sbostic if (daysold < 0)
64134602Sbostic daysold += 365;
64234602Sbostic
64334602Sbostic if (daysold > N_DAYSOLD)
64434602Sbostic /* player hasn't been used in a while; delete */
64534602Sbostic freerecord(&Other, loc);
64634602Sbostic
64734602Sbostic loc += SZ_PLAYERSTRUCT;
64834602Sbostic }
64934602Sbostic }
65034602Sbostic /**/
65134602Sbostic /************************************************************************
65234602Sbostic /
65334602Sbostic / FUNCTION NAME: enterscore()
65434602Sbostic /
65534602Sbostic / FUNCTION: enter player into scoreboard
65634602Sbostic /
65734602Sbostic / AUTHOR: E. A. Estes, 12/4/85
65834602Sbostic /
65934602Sbostic / ARGUMENTS: none
66034602Sbostic /
66134602Sbostic / RETURN VALUE: none
66234602Sbostic /
66334602Sbostic / MODULES CALLED: fread(), fseek(), fopen(), error(), strcmp(), fclose(),
66434602Sbostic / strcpy(), fwrite(), descrtype()
66534602Sbostic /
666*40279Sbostic / GLOBAL INPUTS: Player
66734602Sbostic /
66834602Sbostic / GLOBAL OUTPUTS: none
66934602Sbostic /
67034602Sbostic / DESCRIPTION:
67134602Sbostic / The scoreboard keeps track of the highest character on a
67234602Sbostic / per-login basis.
67334602Sbostic / Search the scoreboard for an entry for the current login,
67434602Sbostic / if an entry is found, and it is lower than the current player,
67534602Sbostic / replace it, otherwise create an entry.
67634602Sbostic /
67734602Sbostic /************************************************************************/
67834602Sbostic
enterscore()67934602Sbostic enterscore()
68034602Sbostic {
68134602Sbostic struct scoreboard sbuf; /* buffer to read in scoreboard entries */
68234602Sbostic FILE *fp; /* to open scoreboard file */
68334602Sbostic long loc = 0L; /* location in scoreboard file */
68434602Sbostic bool found = FALSE; /* set if we found an entry for this login */
68534602Sbostic
686*40279Sbostic if ((fp = fopen(_PATH_SCORE, "r+")) != NULL)
68734602Sbostic {
68834602Sbostic while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
68934602Sbostic if (strcmp(Player.p_login, sbuf.sb_login) == 0)
69034602Sbostic {
69134602Sbostic found = TRUE;
69234602Sbostic break;
69334602Sbostic }
69434602Sbostic else
69534602Sbostic loc += SZ_SCORESTRUCT;
69634602Sbostic }
69734602Sbostic else
69834602Sbostic {
699*40279Sbostic error(_PATH_SCORE);
70034602Sbostic /*NOTREACHED*/
70134602Sbostic }
70234602Sbostic
70334602Sbostic /*
70434602Sbostic * At this point, 'loc' will either indicate a point beyond
70534602Sbostic * the end of file, or the place where the previous entry
70634602Sbostic * was found.
70734602Sbostic */
70834602Sbostic
70934602Sbostic if ((!found) || Player.p_level > sbuf.sb_level)
71034602Sbostic /* put new entry in for this login */
71134602Sbostic {
71234602Sbostic strcpy(sbuf.sb_login, Player.p_login);
71334602Sbostic strcpy(sbuf.sb_name, Player.p_name);
71434602Sbostic sbuf.sb_level = Player.p_level;
71534602Sbostic strcpy(sbuf.sb_type, descrtype(&Player, TRUE));
71634602Sbostic }
71734602Sbostic
71834602Sbostic /* update entry */
71934602Sbostic fseek(fp, loc, 0);
72034602Sbostic fwrite((char *) &sbuf, SZ_SCORESTRUCT, 1, fp);
72134602Sbostic fclose(fp);
72234602Sbostic }
723