* gamesupport.c - auxiliary routines for support of Phantasia
/************************************************************************
/ FUNCTION NAME: changestats()
/ FUNCTION: examine/change statistics for a player
/ AUTHOR: E. A. Estes, 12/4/85
/ bool ingameflag - set if called while playing game (Wizard only)
/ MODULES CALLED: freerecord(), writerecord(), descrstatus(), truncstring(),
/ time(), more(), wmove(), wclear(), strcmp(), printw(), strcpy(),
/ infloat(), waddstr(), cleanup(), findname(), userlist(), mvprintw(),
/ localtime(), getanswer(), descrtype(), getstring()
/ GLOBAL INPUTS: LINES, *Login, Other, Wizard, Player, *stdscr, Databuf[],
/ Prompt for player name to examine/change.
/ If the name is NULL, print a list of all players.
/ If we are called from within the game, check for the
/ desired name being the same as the current player's name.
/ Only the 'Wizard' may alter players.
/ Items are changed only if a non-zero value is specified.
/ To change an item to 0, use 0.1; it will be truncated later.
/ Players may alter their names and passwords, if the following
/ - current login matches the character's logins
/ - the password is known
/ - the player is not in the middle of the game (ingameflag == FALSE)
/ The last condition is imposed for two reasons:
/ - the game could possibly get a bit hectic if a player were
/ continually changing his/her name
/ - another player structure would be necessary to check for names
/************************************************************************/
static char flag
[2] = /* for printing values of bools */
register struct player
*playerp
;/* pointer to structure to alter */
register char *prompt
; /* pointer to prompt string */
int today
; /* day of year of today */
int temp
; /* temporary variable */
long loc
; /* location in player file */
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 */
/* get name of player to examine/alter */
mvaddstr(5, 0, "Which character do you want to look at ? ");
getstring(Databuf
, SZ_DATABUF
);
/* use 'Player' structure */
else if (strcmp(Databuf
, Player
.p_name
) == 0)
/* alter/examine current player */
/* use 'Other' structure */
/* find player on file */
if (loc
< 0L && (loc
= findname(Databuf
, playerp
)) < 0L)
mvaddstr(11, 0, "Not found.");
today
= localtime(&now
)->tm_yday
;
/* print player structure, and prompt for action */
mvprintw(0, 0,"A:Name %s\n", playerp
->p_name
);
printw("B:Password %s\n", playerp
->p_password
);
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
);
mvprintw(5, 40, "S:X-coord %.0f\n", playerp
->p_x
);
mvprintw(6, 40, "T:Y-coord %.0f\n", playerp
->p_y
);
mvaddstr(5, 40, "S:X-coord ?\n");
mvaddstr(6, 40, "T:Y-coord ?\n");
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
;
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
[playerp
->p_palantir
],
flag
[playerp
->p_blessing
],
flag
[playerp
->p_blindness
]);
mvprintw(19, 8, "8:Ring %c",
flag
[playerp
->p_ring
.ring_type
!= R_NONE
]);
mvprintw(19, 8, "8:Ring %d 9:Duration %d",
playerp
->p_ring
.ring_type
, playerp
->p_ring
.ring_duration
);
&& (ingameflag
|| strcmp(Login
, playerp
->p_login
) != 0))
/* in game or not examining own character */
mvaddstr(20, 0, "!:Quit ?:Delete");
mvaddstr(21, 0, "What would you like to change ? ");
c
= getanswer(" ", TRUE
);
/* examining own player; allow to change name and password */
c
= getanswer("!BA", FALSE
);
case 'A': /* change name */
case 'B': /* change password */
/* prompt for password */
mvaddstr(23, 0, "Password ? ");
if (strcmp(Databuf
, playerp
->p_password
) != 0)
mvaddstr(23, 0, "New name: ");
getstring(Databuf
, SZ_NAME
);
if (Wizard
|| findname(Databuf
, &Other
) < 0L)
strcpy(playerp
->p_name
, Databuf
);
/* get two copies of new password until they match */
mvaddstr(23, 0, "New password ? ");
getstring(Databuf
, SZ_PASSWORD
);
mvaddstr(23, 0, "One more time ? ");
getstring(playerp
->p_password
, SZ_PASSWORD
);
while (strcmp(playerp
->p_password
, Databuf
) != 0);
case 'C': /* change experience */
dptr
= &playerp
->p_experience
;
case 'D': /* change level */
dptr
= &playerp
->p_level
;
case 'E': /* change strength */
dptr
= &playerp
->p_strength
;
case 'F': /* change swords */
dptr
= &playerp
->p_sword
;
case 'G': /* change energy */
dptr
= &playerp
->p_energy
;
case 'H': /* change maximum energy */
dptr
= &playerp
->p_maxenergy
;
case 'I': /* change shields */
dptr
= &playerp
->p_shield
;
case 'J': /* change quickness */
dptr
= &playerp
->p_quickness
;
case 'K': /* change quicksilver */
dptr
= &playerp
->p_quksilver
;
case 'L': /* change magic */
dptr
= &playerp
->p_magiclvl
;
case 'M': /* change mana */
case 'N': /* change brains */
dptr
= &playerp
->p_brains
;
case 'O': /* change poison */
dptr
= &playerp
->p_poison
;
case 'P': /* change gold */
case 'Q': /* change gems */
case 'R': /* change sin */
case 'S': /* change x coord */
case 'T': /* change y coord */
case 'U': /* change age */
mvprintw(23, 0, "age = %ld; age = ", playerp
->p_age
);
playerp
->p_age
= (long) dtemp
;
case 'V': /* change degen */
mvprintw(23, 0, "degen = %d; degen = ", playerp
->p_degenerated
);
playerp
->p_degenerated
= (int) dtemp
;
case 'W': /* change type */
case 'X': /* change special type */
sptr
= &playerp
->p_specialtype
;
case 'Y': /* change lives */
sptr
= &playerp
->p_lives
;
case 'Z': /* change crowns */
sptr
= &playerp
->p_crowns
;
case '0': /* change charms */
sptr
= &playerp
->p_charms
;
case '1': /* change amulet */
sptr
= &playerp
->p_amulets
;
case '2': /* change holy water */
sptr
= &playerp
->p_holywater
;
case '3': /* change last-used */
sptr
= &playerp
->p_lastused
;
case '4': /* change palantir */
bptr
= &playerp
->p_palantir
;
case '5': /* change blessing */
bptr
= &playerp
->p_blessing
;
case '6': /* change virgin */
bptr
= &playerp
->p_virgin
;
case '7': /* change blindness */
bptr
= &playerp
->p_blindness
;
case '8': /* change ring type */
sptr
= &playerp
->p_ring
.ring_type
;
case '9': /* change ring duration */
prompt
= "ring-duration";
sptr
= &playerp
->p_ring
.ring_duration
;
case '!': /* quit, update */
(!ingameflag
|| playerp
!= &Player
))
/* turn off status if not modifying self */
playerp
->p_status
= S_OFF
;
playerp
->p_tampered
= T_OFF
;
writerecord(playerp
, loc
);
case '?': /* delete player */
if (ingameflag
&& playerp
== &Player
)
freerecord(playerp
, loc
);
mvprintw(23, 0, "%s = %f; %s = ", prompt
, *dptr
, prompt
);
mvprintw(23, 0, "%s = %d; %s = ", prompt
, *sptr
, prompt
);
mvprintw(23, 0, "%s = %c; %s = ", prompt
, flag
[*bptr
], prompt
);
c
= getanswer("\nTF", TRUE
);
/************************************************************************
/ FUNCTION NAME: monstlist()
/ FUNCTION: print a monster listing
/ AUTHOR: E. A. Estes, 2/27/86
/ MODULES CALLED: puts(), fread(), fseek(), printf()
/ GLOBAL INPUTS: Curmonster, *Monstfp
/ Read monster file, and print a monster listing on standard output.
/************************************************************************/
register int count
= 0; /* count in file */
puts(" #) Name Str Brain Quick Energy Exper Treas Type Flock%\n");
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
);
/************************************************************************
/ FUNCTION NAME: scorelist()
/ FUNCTION: print player score board
/ AUTHOR: E. A. Estes, 12/4/85
/ MODULES CALLED: fread(), fopen(), printf(), fclose()
/ GLOBAL INPUTS: Scorefile[]
/ Read the scoreboard file and print the contents.
/************************************************************************/
struct scoreboard sbuf
; /* for reading entries */
register FILE *fp
; /* to open the file */
if ((fp
= fopen(Scorefile
, "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
);
/************************************************************************
/ FUNCTION NAME: activelist()
/ FUNCTION: print list of active players to standard output
/ AUTHOR: E. A. Estes, 3/7/86
/ MODULES CALLED: descrstatus(), fread(), fseek(), printf(), descrtype()
/ GLOBAL INPUTS: Other, *Playersfp
/ Read player file, and print list of active records to standard output.
/************************************************************************/
printf("Current characters on file are:\n\n");
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
));
/************************************************************************
/ FUNCTION NAME: purgeoldplayers()
/ FUNCTION: purge inactive players from player file
/ AUTHOR: E. A. Estes, 12/4/85
/ MODULES CALLED: freerecord(), time(), fread(), fseek(), localtime()
/ GLOBAL INPUTS: Other, *Playersfp
/ Delete characters which have not been used with the last
/************************************************************************/
int today
; /* day of year for today */
int daysold
; /* how many days since the character has been used */
long ltime
; /* time in seconds */
long loc
= 0L; /* location in file */
today
= localtime(<ime
)->tm_yday
;
fseek(Playersfp
, loc
, 0);
if (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) != 1)
daysold
= today
- Other
.p_lastused
;
/* player hasn't been used in a while; delete */
/************************************************************************
/ FUNCTION NAME: enterscore()
/ FUNCTION: enter player into scoreboard
/ AUTHOR: E. A. Estes, 12/4/85
/ MODULES CALLED: fread(), fseek(), fopen(), error(), strcmp(), fclose(),
/ strcpy(), fwrite(), descrtype()
/ GLOBAL INPUTS: Player, Scorefile[]
/ The scoreboard keeps track of the highest character on a
/ Search the scoreboard for an entry for the current login,
/ if an entry is found, and it is lower than the current player,
/ replace it, otherwise create an entry.
/************************************************************************/
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(Scorefile
, "r+")) != NULL
)
while (fread((char *) &sbuf
, SZ_SCORESTRUCT
, 1, fp
) == 1)
if (strcmp(Player
.p_login
, sbuf
.sb_login
) == 0)
* At this point, 'loc' will either indicate a point beyond
* the end of file, or the place where the previous entry
if ((!found
) || Player
.p_level
> sbuf
.sb_level
)
/* put new entry in for this login */
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
));
fwrite((char *) &sbuf
, SZ_SCORESTRUCT
, 1, fp
);