2 * gamesupport.c - auxiliary routines for support of Phantasia
10 /************************************************************************
12 / FUNCTION NAME: changestats()
14 / FUNCTION: examine/change statistics for a player
16 / AUTHOR: E. A. Estes, 12/4/85
19 / bool ingameflag - set if called while playing game (Wizard only)
23 / MODULES CALLED: freerecord(), writerecord(), descrstatus(), truncstring(),
24 / time(), more(), wmove(), wclear(), strcmp(), printw(), strcpy(),
25 / infloat(), waddstr(), cleanup(), findname(), userlist(), mvprintw(),
26 / localtime(), getanswer(), descrtype(), getstring()
28 / GLOBAL INPUTS: LINES, *Login, Other, Wizard, Player, *stdscr, Databuf[],
31 / GLOBAL OUTPUTS: Echo
34 / Prompt for player name to examine/change.
35 / If the name is NULL, print a list of all players.
36 / If we are called from within the game, check for the
37 / desired name being the same as the current player's name.
38 / Only the 'Wizard' may alter players.
39 / Items are changed only if a non-zero value is specified.
40 / To change an item to 0, use 0.1; it will be truncated later.
42 / Players may alter their names and passwords, if the following
44 / - current login matches the character's logins
45 / - the password is known
46 / - the player is not in the middle of the game (ingameflag == FALSE)
48 / The last condition is imposed for two reasons:
49 / - the game could possibly get a bit hectic if a player were
50 / continually changing his/her name
51 / - another player structure would be necessary to check for names
54 *************************************************************************/
56 changestats(ingameflag)
59 static char flag[2] = /* for printing values of bools */
61 struct player *playerp;/* pointer to structure to alter */
62 char *prompt; /* pointer to prompt string */
64 int today; /* day of year of today */
65 int temp; /* temporary variable */
66 long loc; /* location in player file */
67 time_t now; /* time now */
68 double dtemp; /* temporary variable */
69 bool *bptr; /* pointer to bool item to change */
70 double *dptr; /* pointer to double item to change */
71 short *sptr; /* pointer to short item to change */
76 /* get name of player to examine/alter */
78 mvaddstr(5, 0, "Which character do you want to look at ? ");
79 getstring(Databuf, SZ_DATABUF);
82 if (Databuf[0] == '\0')
91 /* use 'Player' structure */
93 else if (strcmp(Databuf, Player.p_name) == 0)
94 /* alter/examine current player */
100 /* use 'Other' structure */
103 /* find player on file */
104 if (loc < 0L && (loc = findname(Databuf, playerp)) < 0L)
105 /* didn't find player */
108 mvaddstr(11, 0, "Not found.");
113 today = localtime(&now)->tm_yday;
118 /* print player structure, and prompt for action */
120 mvprintw(0, 0,"A:Name %s\n", playerp->p_name);
123 printw("B:Password %s\n", playerp->p_password);
125 addstr("B:Password XXXXXXXX\n");
127 printw(" :Login %s\n", playerp->p_login);
129 printw("C:Experience %.0f\n", playerp->p_experience);
130 printw("D:Level %.0f\n", playerp->p_level);
131 printw("E:Strength %.0f\n", playerp->p_strength);
132 printw("F:Sword %.0f\n", playerp->p_sword);
133 printw(" :Might %.0f\n", playerp->p_might);
134 printw("G:Energy %.0f\n", playerp->p_energy);
135 printw("H:Max-Energy %.0f\n", playerp->p_maxenergy);
136 printw("I:Shield %.0f\n", playerp->p_shield);
137 printw("J:Quickness %.0f\n", playerp->p_quickness);
138 printw("K:Quicksilver %.0f\n", playerp->p_quksilver);
139 printw(" :Speed %.0f\n", playerp->p_speed);
140 printw("L:Magic Level %.0f\n", playerp->p_magiclvl);
141 printw("M:Mana %.0f\n", playerp->p_mana);
142 printw("N:Brains %.0f\n", playerp->p_brains);
144 if (Wizard || playerp->p_specialtype != SC_VALAR)
145 mvaddstr(0, 40, descrstatus(playerp));
147 mvprintw(1, 40, "O:Poison %0.3f\n", playerp->p_poison);
148 mvprintw(2, 40, "P:Gold %.0f\n", playerp->p_gold);
149 mvprintw(3, 40, "Q:Gem %.0f\n", playerp->p_gems);
150 mvprintw(4, 40, "R:Sin %0.3f\n", playerp->p_sin);
153 mvprintw(5, 40, "S:X-coord %.0f\n", playerp->p_x);
154 mvprintw(6, 40, "T:Y-coord %.0f\n", playerp->p_y);
158 mvaddstr(5, 40, "S:X-coord ?\n");
159 mvaddstr(6, 40, "T:Y-coord ?\n");
162 mvprintw(7, 40, "U:Age %ld\n", playerp->p_age);
163 mvprintw(8, 40, "V:Degenerated %d\n", playerp->p_degenerated);
165 mvprintw(9, 40, "W:Type %d (%s)\n",
166 playerp->p_type, descrtype(playerp, FALSE) + 1);
167 mvprintw(10, 40, "X:Special Type %d\n", playerp->p_specialtype);
168 mvprintw(11, 40, "Y:Lives %d\n", playerp->p_lives);
169 mvprintw(12, 40, "Z:Crowns %d\n", playerp->p_crowns);
170 mvprintw(13, 40, "0:Charms %d\n", playerp->p_charms);
171 mvprintw(14, 40, "1:Amulets %d\n", playerp->p_amulets);
172 mvprintw(15, 40, "2:Holy Water %d\n", playerp->p_holywater);
174 temp = today - playerp->p_lastused;
178 mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp->p_lastused, temp);
180 mvprintw(18, 8, "4:Palantir %c 5:Blessing %c 6:Virgin %c 7:Blind %c",
181 flag[playerp->p_palantir],
182 flag[playerp->p_blessing],
183 flag[playerp->p_virgin],
184 flag[playerp->p_blindness]);
187 mvprintw(19, 8, "8:Ring %c",
188 flag[playerp->p_ring.ring_type != R_NONE]);
190 mvprintw(19, 8, "8:Ring %d 9:Duration %d",
191 playerp->p_ring.ring_type, playerp->p_ring.ring_duration);
195 && (ingameflag || strcmp(Login, playerp->p_login) != 0))
196 /* in game or not examining own character */
209 mvaddstr(20, 0, "!:Quit ?:Delete");
210 mvaddstr(21, 0, "What would you like to change ? ");
213 c = getanswer(" ", TRUE);
215 /* examining own player; allow to change name and password */
216 c = getanswer("!BA", FALSE);
220 case 'A': /* change name */
221 case 'B': /* change password */
223 /* prompt for password */
225 mvaddstr(23, 0, "Password ? ");
227 getstring(Databuf, 9);
229 if (strcmp(Databuf, playerp->p_password) != 0)
236 mvaddstr(23, 0, "New name: ");
237 getstring(Databuf, SZ_NAME);
238 truncstring(Databuf);
239 if (Databuf[0] != '\0')
240 if (Wizard || findname(Databuf, &Other) < 0L)
241 strcpy(playerp->p_name, Databuf);
244 /* get new password */
250 /* get two copies of new password until they match */
253 mvaddstr(23, 0, "New password ? ");
254 getstring(Databuf, SZ_PASSWORD);
255 if (Databuf[0] == '\0')
258 /* get second copy */
259 mvaddstr(23, 0, "One more time ? ");
260 getstring(playerp->p_password, SZ_PASSWORD);
262 while (strcmp(playerp->p_password, Databuf) != 0);
269 case 'C': /* change experience */
270 prompt = "experience";
271 dptr = &playerp->p_experience;
274 case 'D': /* change level */
276 dptr = &playerp->p_level;
279 case 'E': /* change strength */
281 dptr = &playerp->p_strength;
284 case 'F': /* change swords */
286 dptr = &playerp->p_sword;
289 case 'G': /* change energy */
291 dptr = &playerp->p_energy;
294 case 'H': /* change maximum energy */
295 prompt = "max energy";
296 dptr = &playerp->p_maxenergy;
299 case 'I': /* change shields */
301 dptr = &playerp->p_shield;
304 case 'J': /* change quickness */
305 prompt = "quickness";
306 dptr = &playerp->p_quickness;
309 case 'K': /* change quicksilver */
310 prompt = "quicksilver";
311 dptr = &playerp->p_quksilver;
314 case 'L': /* change magic */
315 prompt = "magic level";
316 dptr = &playerp->p_magiclvl;
319 case 'M': /* change mana */
321 dptr = &playerp->p_mana;
324 case 'N': /* change brains */
326 dptr = &playerp->p_brains;
329 case 'O': /* change poison */
331 dptr = &playerp->p_poison;
334 case 'P': /* change gold */
336 dptr = &playerp->p_gold;
339 case 'Q': /* change gems */
341 dptr = &playerp->p_gems;
344 case 'R': /* change sin */
346 dptr = &playerp->p_sin;
349 case 'S': /* change x coord */
351 dptr = &playerp->p_x;
354 case 'T': /* change y coord */
356 dptr = &playerp->p_y;
359 case 'U': /* change age */
360 mvprintw(23, 0, "age = %ld; age = ", playerp->p_age);
363 playerp->p_age = (long) dtemp;
366 case 'V': /* change degen */
367 mvprintw(23, 0, "degen = %d; degen = ", playerp->p_degenerated);
370 playerp->p_degenerated = (int) dtemp;
373 case 'W': /* change type */
375 sptr = &playerp->p_type;
378 case 'X': /* change special type */
379 prompt = "special type";
380 sptr = &playerp->p_specialtype;
383 case 'Y': /* change lives */
385 sptr = &playerp->p_lives;
388 case 'Z': /* change crowns */
390 sptr = &playerp->p_crowns;
393 case '0': /* change charms */
395 sptr = &playerp->p_charms;
398 case '1': /* change amulet */
400 sptr = &playerp->p_amulets;
403 case '2': /* change holy water */
404 prompt = "holy water";
405 sptr = &playerp->p_holywater;
408 case '3': /* change last-used */
409 prompt = "last-used";
410 sptr = &playerp->p_lastused;
413 case '4': /* change palantir */
415 bptr = &playerp->p_palantir;
418 case '5': /* change blessing */
420 bptr = &playerp->p_blessing;
423 case '6': /* change virgin */
425 bptr = &playerp->p_virgin;
428 case '7': /* change blindness */
429 prompt = "blindness";
430 bptr = &playerp->p_blindness;
433 case '8': /* change ring type */
434 prompt = "ring-type";
435 sptr = &playerp->p_ring.ring_type;
438 case '9': /* change ring duration */
439 prompt = "ring-duration";
440 sptr = &playerp->p_ring.ring_duration;
443 case '!': /* quit, update */
445 (!ingameflag || playerp != &Player))
446 /* turn off status if not modifying self */
448 playerp->p_status = S_OFF;
449 playerp->p_tampered = T_OFF;
452 writerecord(playerp, loc);
456 case '?': /* delete player */
457 if (ingameflag && playerp == &Player)
458 /* cannot delete self */
461 freerecord(playerp, loc);
469 mvprintw(23, 0, "%s = %f; %s = ", prompt, *dptr, prompt);
476 mvprintw(23, 0, "%s = %d; %s = ", prompt, *sptr, prompt);
479 *sptr = (short) dtemp;
483 mvprintw(23, 0, "%s = %c; %s = ", prompt, flag[*bptr], prompt);
484 c = getanswer("\nTF", TRUE);
493 /************************************************************************
495 / FUNCTION NAME: monstlist()
497 / FUNCTION: print a monster listing
499 / AUTHOR: E. A. Estes, 2/27/86
505 / MODULES CALLED: puts(), fread(), fseek(), printf()
507 / GLOBAL INPUTS: Curmonster, *Monstfp
509 / GLOBAL OUTPUTS: none
512 / Read monster file, and print a monster listing on standard output.
514 *************************************************************************/
518 int count = 0; /* count in file */
520 puts(" #) Name Str Brain Quick Energy Exper Treas Type Flock%\n");
521 fseek(Monstfp, 0L, 0);
522 while (fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp) == 1)
523 printf("%2d) %-20.20s%4.0f %4.0f %2.0f %5.0f %5.0f %2d %2d %3.0f\n", count++,
524 Curmonster.m_name, Curmonster.m_strength, Curmonster.m_brains,
525 Curmonster.m_speed, Curmonster.m_energy, Curmonster.m_experience,
526 Curmonster.m_treasuretype, Curmonster.m_type, Curmonster.m_flock);
529 /************************************************************************
531 / FUNCTION NAME: scorelist()
533 / FUNCTION: print player score board
535 / AUTHOR: E. A. Estes, 12/4/85
541 / MODULES CALLED: fread(), fopen(), printf(), fclose()
545 / GLOBAL OUTPUTS: none
548 / Read the scoreboard file and print the contents.
550 *************************************************************************/
554 struct scoreboard sbuf; /* for reading entries */
555 FILE *fp; /* to open the file */
557 if ((fp = fopen(_PATH_SCORE, "r")) != NULL)
559 while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
560 printf("%-20s (%-9s) Level: %6.0f Type: %s\n",
561 sbuf.sb_name, sbuf.sb_login, sbuf.sb_level, sbuf.sb_type);
566 /************************************************************************
568 / FUNCTION NAME: activelist()
570 / FUNCTION: print list of active players to standard output
572 / AUTHOR: E. A. Estes, 3/7/86
578 / MODULES CALLED: descrstatus(), fread(), fseek(), printf(), descrtype()
580 / GLOBAL INPUTS: Other, *Playersfp
582 / GLOBAL OUTPUTS: none
585 / Read player file, and print list of active records to standard output.
587 *************************************************************************/
591 fseek(Playersfp, 0L, 0);
592 printf("Current characters on file are:\n\n");
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));
602 /************************************************************************
604 / FUNCTION NAME: purgeoldplayers()
606 / FUNCTION: purge inactive players from player file
608 / AUTHOR: E. A. Estes, 12/4/85
614 / MODULES CALLED: freerecord(), time(), fread(), fseek(), localtime()
616 / GLOBAL INPUTS: Other, *Playersfp
618 / GLOBAL OUTPUTS: none
621 / Delete characters which have not been used with the last
624 *************************************************************************/
628 int today; /* day of year for today */
629 int daysold; /* how many days since the character has been used */
630 time_t ltime; /* time in seconds */
631 long loc = 0L; /* location in file */
634 today = localtime(<ime)->tm_yday;
638 fseek(Playersfp, loc, 0);
639 if (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) != 1)
642 daysold = today - Other.p_lastused;
646 if (daysold > N_DAYSOLD)
647 /* player hasn't been used in a while; delete */
648 freerecord(&Other, loc);
650 loc += SZ_PLAYERSTRUCT;
654 /************************************************************************
656 / FUNCTION NAME: enterscore()
658 / FUNCTION: enter player into scoreboard
660 / AUTHOR: E. A. Estes, 12/4/85
666 / MODULES CALLED: fread(), fseek(), fopen(), error(), strcmp(), fclose(),
667 / strcpy(), fwrite(), descrtype()
669 / GLOBAL INPUTS: Player
671 / GLOBAL OUTPUTS: none
674 / The scoreboard keeps track of the highest character on a
676 / Search the scoreboard for an entry for the current login,
677 / if an entry is found, and it is lower than the current player,
678 / replace it, otherwise create an entry.
680 *************************************************************************/
684 struct scoreboard sbuf; /* buffer to read in scoreboard entries */
685 FILE *fp; /* to open scoreboard file */
686 long loc = 0L; /* location in scoreboard file */
687 bool found = FALSE; /* set if we found an entry for this login */
689 if ((fp = fopen(_PATH_SCORE, "r+")) != NULL)
691 while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
692 if (strcmp(Player.p_login, sbuf.sb_login) == 0)
698 loc += SZ_SCORESTRUCT;
707 * At this point, 'loc' will either indicate a point beyond
708 * the end of file, or the place where the previous entry
712 if ((!found) || Player.p_level > sbuf.sb_level)
713 /* put new entry in for this login */
715 strcpy(sbuf.sb_login, Player.p_login);
716 strcpy(sbuf.sb_name, Player.p_name);
717 sbuf.sb_level = Player.p_level;
718 strcpy(sbuf.sb_type, descrtype(&Player, TRUE));
723 fwrite((char *) &sbuf, SZ_SCORESTRUCT, 1, fp);