]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/gamesupport.c
1 /* $NetBSD: gamesupport.c,v 1.2 1995/03/24 03:58:43 cgd Exp $ */
4 * gamesupport.c - auxiliary routines for support of Phantasia
9 /************************************************************************
11 / FUNCTION NAME: changestats()
13 / FUNCTION: examine/change statistics for a player
15 / AUTHOR: E. A. Estes, 12/4/85
18 / bool ingameflag - set if called while playing game (Wizard only)
22 / MODULES CALLED: freerecord(), writerecord(), descrstatus(), truncstring(),
23 / time(), more(), wmove(), wclear(), strcmp(), printw(), strcpy(),
24 / infloat(), waddstr(), cleanup(), findname(), userlist(), mvprintw(),
25 / localtime(), getanswer(), descrtype(), getstring()
27 / GLOBAL INPUTS: LINES, *Login, Other, Wizard, Player, *stdscr, Databuf[],
30 / GLOBAL OUTPUTS: Echo
33 / Prompt for player name to examine/change.
34 / If the name is NULL, print a list of all players.
35 / If we are called from within the game, check for the
36 / desired name being the same as the current player's name.
37 / Only the 'Wizard' may alter players.
38 / Items are changed only if a non-zero value is specified.
39 / To change an item to 0, use 0.1; it will be truncated later.
41 / Players may alter their names and passwords, if the following
43 / - current login matches the character's logins
44 / - the password is known
45 / - the player is not in the middle of the game (ingameflag == FALSE)
47 / The last condition is imposed for two reasons:
48 / - the game could possibly get a bit hectic if a player were
49 / continually changing his/her name
50 / - another player structure would be necessary to check for names
53 /************************************************************************/
55 changestats(ingameflag
)
58 static char flag
[2] = /* for printing values of bools */
60 register struct player
*playerp
;/* pointer to structure to alter */
61 register char *prompt
; /* pointer to prompt string */
63 int today
; /* day of year of today */
64 int temp
; /* temporary variable */
65 long loc
; /* location in player file */
66 long now
; /* time now */
67 double dtemp
; /* temporary variable */
68 bool *bptr
; /* pointer to bool item to change */
69 double *dptr
; /* pointer to double item to change */
70 short *sptr
; /* pointer to short item to change */
75 /* get name of player to examine/alter */
77 mvaddstr(5, 0, "Which character do you want to look at ? ");
78 getstring(Databuf
, SZ_DATABUF
);
81 if (Databuf
[0] == '\0')
90 /* use 'Player' structure */
92 else if (strcmp(Databuf
, Player
.p_name
) == 0)
93 /* alter/examine current player */
99 /* use 'Other' structure */
102 /* find player on file */
103 if (loc
< 0L && (loc
= findname(Databuf
, playerp
)) < 0L)
104 /* didn't find player */
107 mvaddstr(11, 0, "Not found.");
112 today
= localtime(&now
)->tm_yday
;
117 /* print player structure, and prompt for action */
119 mvprintw(0, 0,"A:Name %s\n", playerp
->p_name
);
122 printw("B:Password %s\n", playerp
->p_password
);
124 addstr("B:Password XXXXXXXX\n");
126 printw(" :Login %s\n", playerp
->p_login
);
128 printw("C:Experience %.0f\n", playerp
->p_experience
);
129 printw("D:Level %.0f\n", playerp
->p_level
);
130 printw("E:Strength %.0f\n", playerp
->p_strength
);
131 printw("F:Sword %.0f\n", playerp
->p_sword
);
132 printw(" :Might %.0f\n", playerp
->p_might
);
133 printw("G:Energy %.0f\n", playerp
->p_energy
);
134 printw("H:Max-Energy %.0f\n", playerp
->p_maxenergy
);
135 printw("I:Shield %.0f\n", playerp
->p_shield
);
136 printw("J:Quickness %.0f\n", playerp
->p_quickness
);
137 printw("K:Quicksilver %.0f\n", playerp
->p_quksilver
);
138 printw(" :Speed %.0f\n", playerp
->p_speed
);
139 printw("L:Magic Level %.0f\n", playerp
->p_magiclvl
);
140 printw("M:Mana %.0f\n", playerp
->p_mana
);
141 printw("N:Brains %.0f\n", playerp
->p_brains
);
143 if (Wizard
|| playerp
->p_specialtype
!= SC_VALAR
)
144 mvaddstr(0, 40, descrstatus(playerp
));
146 mvprintw(1, 40, "O:Poison %0.3f\n", playerp
->p_poison
);
147 mvprintw(2, 40, "P:Gold %.0f\n", playerp
->p_gold
);
148 mvprintw(3, 40, "Q:Gem %.0f\n", playerp
->p_gems
);
149 mvprintw(4, 40, "R:Sin %0.3f\n", playerp
->p_sin
);
152 mvprintw(5, 40, "S:X-coord %.0f\n", playerp
->p_x
);
153 mvprintw(6, 40, "T:Y-coord %.0f\n", playerp
->p_y
);
157 mvaddstr(5, 40, "S:X-coord ?\n");
158 mvaddstr(6, 40, "T:Y-coord ?\n");
161 mvprintw(7, 40, "U:Age %ld\n", playerp
->p_age
);
162 mvprintw(8, 40, "V:Degenerated %d\n", playerp
->p_degenerated
);
164 mvprintw(9, 40, "W:Type %d (%s)\n",
165 playerp
->p_type
, descrtype(playerp
, FALSE
) + 1);
166 mvprintw(10, 40, "X:Special Type %d\n", playerp
->p_specialtype
);
167 mvprintw(11, 40, "Y:Lives %d\n", playerp
->p_lives
);
168 mvprintw(12, 40, "Z:Crowns %d\n", playerp
->p_crowns
);
169 mvprintw(13, 40, "0:Charms %d\n", playerp
->p_charms
);
170 mvprintw(14, 40, "1:Amulets %d\n", playerp
->p_amulets
);
171 mvprintw(15, 40, "2:Holy Water %d\n", playerp
->p_holywater
);
173 temp
= today
- playerp
->p_lastused
;
177 mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp
->p_lastused
, temp
);
179 mvprintw(18, 8, "4:Palantir %c 5:Blessing %c 6:Virgin %c 7:Blind %c",
180 flag
[playerp
->p_palantir
],
181 flag
[playerp
->p_blessing
],
182 flag
[playerp
->p_virgin
],
183 flag
[playerp
->p_blindness
]);
186 mvprintw(19, 8, "8:Ring %c",
187 flag
[playerp
->p_ring
.ring_type
!= R_NONE
]);
189 mvprintw(19, 8, "8:Ring %d 9:Duration %d",
190 playerp
->p_ring
.ring_type
, playerp
->p_ring
.ring_duration
);
194 && (ingameflag
|| strcmp(Login
, playerp
->p_login
) != 0))
195 /* in game or not examining own character */
208 mvaddstr(20, 0, "!:Quit ?:Delete");
209 mvaddstr(21, 0, "What would you like to change ? ");
212 c
= getanswer(" ", TRUE
);
214 /* examining own player; allow to change name and password */
215 c
= getanswer("!BA", FALSE
);
219 case 'A': /* change name */
220 case 'B': /* change password */
222 /* prompt for password */
224 mvaddstr(23, 0, "Password ? ");
226 getstring(Databuf
, 9);
228 if (strcmp(Databuf
, playerp
->p_password
) != 0)
235 mvaddstr(23, 0, "New name: ");
236 getstring(Databuf
, SZ_NAME
);
237 truncstring(Databuf
);
238 if (Databuf
[0] != '\0')
239 if (Wizard
|| findname(Databuf
, &Other
) < 0L)
240 strcpy(playerp
->p_name
, Databuf
);
243 /* get new password */
249 /* get two copies of new password until they match */
252 mvaddstr(23, 0, "New password ? ");
253 getstring(Databuf
, SZ_PASSWORD
);
254 if (Databuf
[0] == '\0')
257 /* get second copy */
258 mvaddstr(23, 0, "One more time ? ");
259 getstring(playerp
->p_password
, SZ_PASSWORD
);
261 while (strcmp(playerp
->p_password
, Databuf
) != 0);
268 case 'C': /* change experience */
269 prompt
= "experience";
270 dptr
= &playerp
->p_experience
;
273 case 'D': /* change level */
275 dptr
= &playerp
->p_level
;
278 case 'E': /* change strength */
280 dptr
= &playerp
->p_strength
;
283 case 'F': /* change swords */
285 dptr
= &playerp
->p_sword
;
288 case 'G': /* change energy */
290 dptr
= &playerp
->p_energy
;
293 case 'H': /* change maximum energy */
294 prompt
= "max energy";
295 dptr
= &playerp
->p_maxenergy
;
298 case 'I': /* change shields */
300 dptr
= &playerp
->p_shield
;
303 case 'J': /* change quickness */
304 prompt
= "quickness";
305 dptr
= &playerp
->p_quickness
;
308 case 'K': /* change quicksilver */
309 prompt
= "quicksilver";
310 dptr
= &playerp
->p_quksilver
;
313 case 'L': /* change magic */
314 prompt
= "magic level";
315 dptr
= &playerp
->p_magiclvl
;
318 case 'M': /* change mana */
320 dptr
= &playerp
->p_mana
;
323 case 'N': /* change brains */
325 dptr
= &playerp
->p_brains
;
328 case 'O': /* change poison */
330 dptr
= &playerp
->p_poison
;
333 case 'P': /* change gold */
335 dptr
= &playerp
->p_gold
;
338 case 'Q': /* change gems */
340 dptr
= &playerp
->p_gems
;
343 case 'R': /* change sin */
345 dptr
= &playerp
->p_sin
;
348 case 'S': /* change x coord */
350 dptr
= &playerp
->p_x
;
353 case 'T': /* change y coord */
355 dptr
= &playerp
->p_y
;
358 case 'U': /* change age */
359 mvprintw(23, 0, "age = %ld; age = ", playerp
->p_age
);
362 playerp
->p_age
= (long) dtemp
;
365 case 'V': /* change degen */
366 mvprintw(23, 0, "degen = %d; degen = ", playerp
->p_degenerated
);
369 playerp
->p_degenerated
= (int) dtemp
;
372 case 'W': /* change type */
374 sptr
= &playerp
->p_type
;
377 case 'X': /* change special type */
378 prompt
= "special type";
379 sptr
= &playerp
->p_specialtype
;
382 case 'Y': /* change lives */
384 sptr
= &playerp
->p_lives
;
387 case 'Z': /* change crowns */
389 sptr
= &playerp
->p_crowns
;
392 case '0': /* change charms */
394 sptr
= &playerp
->p_charms
;
397 case '1': /* change amulet */
399 sptr
= &playerp
->p_amulets
;
402 case '2': /* change holy water */
403 prompt
= "holy water";
404 sptr
= &playerp
->p_holywater
;
407 case '3': /* change last-used */
408 prompt
= "last-used";
409 sptr
= &playerp
->p_lastused
;
412 case '4': /* change palantir */
414 bptr
= &playerp
->p_palantir
;
417 case '5': /* change blessing */
419 bptr
= &playerp
->p_blessing
;
422 case '6': /* change virgin */
424 bptr
= &playerp
->p_virgin
;
427 case '7': /* change blindness */
428 prompt
= "blindness";
429 bptr
= &playerp
->p_blindness
;
432 case '8': /* change ring type */
433 prompt
= "ring-type";
434 sptr
= &playerp
->p_ring
.ring_type
;
437 case '9': /* change ring duration */
438 prompt
= "ring-duration";
439 sptr
= &playerp
->p_ring
.ring_duration
;
442 case '!': /* quit, update */
444 (!ingameflag
|| playerp
!= &Player
))
445 /* turn off status if not modifying self */
447 playerp
->p_status
= S_OFF
;
448 playerp
->p_tampered
= T_OFF
;
451 writerecord(playerp
, loc
);
455 case '?': /* delete player */
456 if (ingameflag
&& playerp
== &Player
)
457 /* cannot delete self */
460 freerecord(playerp
, loc
);
468 mvprintw(23, 0, "%s = %f; %s = ", prompt
, *dptr
, prompt
);
475 mvprintw(23, 0, "%s = %d; %s = ", prompt
, *sptr
, prompt
);
478 *sptr
= (short) dtemp
;
482 mvprintw(23, 0, "%s = %c; %s = ", prompt
, flag
[*bptr
], prompt
);
483 c
= getanswer("\nTF", TRUE
);
492 /************************************************************************
494 / FUNCTION NAME: monstlist()
496 / FUNCTION: print a monster listing
498 / AUTHOR: E. A. Estes, 2/27/86
504 / MODULES CALLED: puts(), fread(), fseek(), printf()
506 / GLOBAL INPUTS: Curmonster, *Monstfp
508 / GLOBAL OUTPUTS: none
511 / Read monster file, and print a monster listing on standard output.
513 /************************************************************************/
517 register int count
= 0; /* count in file */
519 puts(" #) Name Str Brain Quick Energy Exper Treas Type Flock%\n");
520 fseek(Monstfp
, 0L, 0);
521 while (fread((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
) == 1)
522 printf("%2d) %-20.20s%4.0f %4.0f %2.0f %5.0f %5.0f %2d %2d %3.0f\n", count
++,
523 Curmonster
.m_name
, Curmonster
.m_strength
, Curmonster
.m_brains
,
524 Curmonster
.m_speed
, Curmonster
.m_energy
, Curmonster
.m_experience
,
525 Curmonster
.m_treasuretype
, Curmonster
.m_type
, Curmonster
.m_flock
);
528 /************************************************************************
530 / FUNCTION NAME: scorelist()
532 / FUNCTION: print player score board
534 / AUTHOR: E. A. Estes, 12/4/85
540 / MODULES CALLED: fread(), fopen(), printf(), fclose()
544 / GLOBAL OUTPUTS: none
547 / Read the scoreboard file and print the contents.
549 /************************************************************************/
553 struct scoreboard sbuf
; /* for reading entries */
554 register FILE *fp
; /* to open the file */
556 if ((fp
= fopen(_PATH_SCORE
, "r")) != NULL
)
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
);
565 /************************************************************************
567 / FUNCTION NAME: activelist()
569 / FUNCTION: print list of active players to standard output
571 / AUTHOR: E. A. Estes, 3/7/86
577 / MODULES CALLED: descrstatus(), fread(), fseek(), printf(), descrtype()
579 / GLOBAL INPUTS: Other, *Playersfp
581 / GLOBAL OUTPUTS: none
584 / Read player file, and print list of active records to standard output.
586 /************************************************************************/
590 fseek(Playersfp
, 0L, 0);
591 printf("Current characters on file are:\n\n");
593 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
594 if (Other
.p_status
!= S_NOTUSED
)
595 printf("%-20s (%-9s) Level: %6.0f %s (%s)\n",
596 Other
.p_name
, Other
.p_login
, Other
.p_level
,
597 descrtype(&Other
, FALSE
), descrstatus(&Other
));
601 /************************************************************************
603 / FUNCTION NAME: purgeoldplayers()
605 / FUNCTION: purge inactive players from player file
607 / AUTHOR: E. A. Estes, 12/4/85
613 / MODULES CALLED: freerecord(), time(), fread(), fseek(), localtime()
615 / GLOBAL INPUTS: Other, *Playersfp
617 / GLOBAL OUTPUTS: none
620 / Delete characters which have not been used with the last
623 /************************************************************************/
627 int today
; /* day of year for today */
628 int daysold
; /* how many days since the character has been used */
629 long ltime
; /* time in seconds */
630 long loc
= 0L; /* location in file */
633 today
= localtime(<ime
)->tm_yday
;
637 fseek(Playersfp
, loc
, 0);
638 if (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) != 1)
641 daysold
= today
- Other
.p_lastused
;
645 if (daysold
> N_DAYSOLD
)
646 /* player hasn't been used in a while; delete */
647 freerecord(&Other
, loc
);
649 loc
+= SZ_PLAYERSTRUCT
;
653 /************************************************************************
655 / FUNCTION NAME: enterscore()
657 / FUNCTION: enter player into scoreboard
659 / AUTHOR: E. A. Estes, 12/4/85
665 / MODULES CALLED: fread(), fseek(), fopen(), error(), strcmp(), fclose(),
666 / strcpy(), fwrite(), descrtype()
668 / GLOBAL INPUTS: Player
670 / GLOBAL OUTPUTS: none
673 / The scoreboard keeps track of the highest character on a
675 / Search the scoreboard for an entry for the current login,
676 / if an entry is found, and it is lower than the current player,
677 / replace it, otherwise create an entry.
679 /************************************************************************/
683 struct scoreboard sbuf
; /* buffer to read in scoreboard entries */
684 FILE *fp
; /* to open scoreboard file */
685 long loc
= 0L; /* location in scoreboard file */
686 bool found
= FALSE
; /* set if we found an entry for this login */
688 if ((fp
= fopen(_PATH_SCORE
, "r+")) != NULL
)
690 while (fread((char *) &sbuf
, SZ_SCORESTRUCT
, 1, fp
) == 1)
691 if (strcmp(Player
.p_login
, sbuf
.sb_login
) == 0)
697 loc
+= SZ_SCORESTRUCT
;
706 * At this point, 'loc' will either indicate a point beyond
707 * the end of file, or the place where the previous entry
711 if ((!found
) || Player
.p_level
> sbuf
.sb_level
)
712 /* put new entry in for this login */
714 strcpy(sbuf
.sb_login
, Player
.p_login
);
715 strcpy(sbuf
.sb_name
, Player
.p_name
);
716 sbuf
.sb_level
= Player
.p_level
;
717 strcpy(sbuf
.sb_type
, descrtype(&Player
, TRUE
));
722 fwrite((char *) &sbuf
, SZ_SCORESTRUCT
, 1, fp
);