1 /* $NetBSD: gamesupport.c,v 1.10 2009/05/25 23:08:45 dholland Exp $ */
4 * gamesupport.c - auxiliary routines for support of Phantasia
12 #include "phantdefs.h"
13 #include "phantstruct.h"
14 #include "phantglobs.h"
15 #include "pathnames.h"
21 changestats(phbool ingameflag
)
23 static char flag
[2] = /* for printing values of bools */
25 struct player
*playerp
; /* pointer to structure to alter */
26 const char *prompt
; /* pointer to prompt string */
28 int today
; /* day of year of today */
29 int temp
; /* temporary variable */
30 long loc
; /* location in player file */
31 time_t now
; /* time now */
32 double dtemp
; /* temporary variable */
33 phbool
*bptr
; /* pointer to bool item to change */
34 double *dptr
; /* pointer to double item to change */
35 short *sptr
; /* pointer to short item to change */
40 /* get name of player to examine/alter */
42 mvaddstr(5, 0, "Which character do you want to look at ? ");
43 getstring(Databuf
, SZ_DATABUF
);
46 if (Databuf
[0] == '\0')
55 /* use 'Player' structure */
58 if (strcmp(Databuf
, Player
.p_name
) == 0)
59 /* alter/examine current player */
64 /* use 'Other' structure */
67 /* find player on file */
68 if (loc
< 0L && (loc
= findname(Databuf
, playerp
)) < 0L)
69 /* didn't find player */
72 mvaddstr(11, 0, "Not found.");
76 today
= localtime(&now
)->tm_yday
;
81 /* print player structure, and prompt for action */
83 mvprintw(0, 0, "A:Name %s\n", playerp
->p_name
);
86 printw("B:Password %s\n", playerp
->p_password
);
88 addstr("B:Password XXXXXXXX\n");
90 printw(" :Login %s\n", playerp
->p_login
);
92 printw("C:Experience %.0f\n", playerp
->p_experience
);
93 printw("D:Level %.0f\n", playerp
->p_level
);
94 printw("E:Strength %.0f\n", playerp
->p_strength
);
95 printw("F:Sword %.0f\n", playerp
->p_sword
);
96 printw(" :Might %.0f\n", playerp
->p_might
);
97 printw("G:Energy %.0f\n", playerp
->p_energy
);
98 printw("H:Max-Energy %.0f\n", playerp
->p_maxenergy
);
99 printw("I:Shield %.0f\n", playerp
->p_shield
);
100 printw("J:Quickness %.0f\n", playerp
->p_quickness
);
101 printw("K:Quicksilver %.0f\n", playerp
->p_quksilver
);
102 printw(" :Speed %.0f\n", playerp
->p_speed
);
103 printw("L:Magic Level %.0f\n", playerp
->p_magiclvl
);
104 printw("M:Mana %.0f\n", playerp
->p_mana
);
105 printw("N:Brains %.0f\n", playerp
->p_brains
);
107 if (Wizard
|| playerp
->p_specialtype
!= SC_VALAR
)
108 mvaddstr(0, 40, descrstatus(playerp
));
110 mvprintw(1, 40, "O:Poison %0.3f\n", playerp
->p_poison
);
111 mvprintw(2, 40, "P:Gold %.0f\n", playerp
->p_gold
);
112 mvprintw(3, 40, "Q:Gem %.0f\n", playerp
->p_gems
);
113 mvprintw(4, 40, "R:Sin %0.3f\n", playerp
->p_sin
);
115 mvprintw(5, 40, "S:X-coord %.0f\n", playerp
->p_x
);
116 mvprintw(6, 40, "T:Y-coord %.0f\n", playerp
->p_y
);
118 mvaddstr(5, 40, "S:X-coord ?\n");
119 mvaddstr(6, 40, "T:Y-coord ?\n");
122 mvprintw(7, 40, "U:Age %ld\n", playerp
->p_age
);
123 mvprintw(8, 40, "V:Degenerated %d\n", playerp
->p_degenerated
);
125 mvprintw(9, 40, "W:Type %d (%s)\n",
126 playerp
->p_type
, descrtype(playerp
, FALSE
) + 1);
127 mvprintw(10, 40, "X:Special Type %d\n", playerp
->p_specialtype
);
128 mvprintw(11, 40, "Y:Lives %d\n", playerp
->p_lives
);
129 mvprintw(12, 40, "Z:Crowns %d\n", playerp
->p_crowns
);
130 mvprintw(13, 40, "0:Charms %d\n", playerp
->p_charms
);
131 mvprintw(14, 40, "1:Amulets %d\n", playerp
->p_amulets
);
132 mvprintw(15, 40, "2:Holy Water %d\n", playerp
->p_holywater
);
134 temp
= today
- playerp
->p_lastused
;
138 mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp
->p_lastused
, temp
);
140 mvprintw(18, 8, "4:Palantir %c 5:Blessing %c 6:Virgin %c 7:Blind %c",
141 flag
[(int)playerp
->p_palantir
],
142 flag
[(int)playerp
->p_blessing
],
143 flag
[(int)playerp
->p_virgin
],
144 flag
[(int)playerp
->p_blindness
]);
147 mvprintw(19, 8, "8:Ring %c",
148 flag
[playerp
->p_ring
.ring_type
!= R_NONE
]);
150 mvprintw(19, 8, "8:Ring %d 9:Duration %d",
151 playerp
->p_ring
.ring_type
, playerp
->p_ring
.ring_duration
);
155 && (ingameflag
|| strcmp(Login
, playerp
->p_login
) != 0))
156 /* in game or not examining own character */
166 mvaddstr(20, 0, "!:Quit ?:Delete");
167 mvaddstr(21, 0, "What would you like to change ? ");
170 c
= getanswer(" ", TRUE
);
172 /* examining own player; allow to change name and
174 c
= getanswer("!BA", FALSE
);
177 case 'A': /* change name */
178 case 'B': /* change password */
180 /* prompt for password */
182 mvaddstr(23, 0, "Password ? ");
184 getstring(Databuf
, 9);
186 if (strcmp(Databuf
, playerp
->p_password
) != 0)
192 mvaddstr(23, 0, "New name: ");
193 getstring(Databuf
, SZ_NAME
);
194 truncstring(Databuf
);
195 if (Databuf
[0] != '\0')
196 if (Wizard
|| findname(Databuf
, &Other
) < 0L)
197 strcpy(playerp
->p_name
, Databuf
);
199 /* get new password */
205 /* get two copies of new password
206 * until they match */
209 mvaddstr(23, 0, "New password ? ");
210 getstring(Databuf
, SZ_PASSWORD
);
211 if (Databuf
[0] == '\0')
214 /* get second copy */
215 mvaddstr(23, 0, "One more time ? ");
216 getstring(playerp
->p_password
, SZ_PASSWORD
);
218 while (strcmp(playerp
->p_password
, Databuf
) != 0);
225 case 'C': /* change experience */
226 prompt
= "experience";
227 dptr
= &playerp
->p_experience
;
230 case 'D': /* change level */
232 dptr
= &playerp
->p_level
;
235 case 'E': /* change strength */
237 dptr
= &playerp
->p_strength
;
240 case 'F': /* change swords */
242 dptr
= &playerp
->p_sword
;
245 case 'G': /* change energy */
247 dptr
= &playerp
->p_energy
;
250 case 'H': /* change maximum energy */
251 prompt
= "max energy";
252 dptr
= &playerp
->p_maxenergy
;
255 case 'I': /* change shields */
257 dptr
= &playerp
->p_shield
;
260 case 'J': /* change quickness */
261 prompt
= "quickness";
262 dptr
= &playerp
->p_quickness
;
265 case 'K': /* change quicksilver */
266 prompt
= "quicksilver";
267 dptr
= &playerp
->p_quksilver
;
270 case 'L': /* change magic */
271 prompt
= "magic level";
272 dptr
= &playerp
->p_magiclvl
;
275 case 'M': /* change mana */
277 dptr
= &playerp
->p_mana
;
280 case 'N': /* change brains */
282 dptr
= &playerp
->p_brains
;
285 case 'O': /* change poison */
287 dptr
= &playerp
->p_poison
;
290 case 'P': /* change gold */
292 dptr
= &playerp
->p_gold
;
295 case 'Q': /* change gems */
297 dptr
= &playerp
->p_gems
;
300 case 'R': /* change sin */
302 dptr
= &playerp
->p_sin
;
305 case 'S': /* change x coord */
307 dptr
= &playerp
->p_x
;
310 case 'T': /* change y coord */
312 dptr
= &playerp
->p_y
;
315 case 'U': /* change age */
316 mvprintw(23, 0, "age = %ld; age = ", playerp
->p_age
);
319 playerp
->p_age
= (long) dtemp
;
322 case 'V': /* change degen */
323 mvprintw(23, 0, "degen = %d; degen = ", playerp
->p_degenerated
);
326 playerp
->p_degenerated
= (int) dtemp
;
329 case 'W': /* change type */
331 sptr
= &playerp
->p_type
;
334 case 'X': /* change special type */
335 prompt
= "special type";
336 sptr
= &playerp
->p_specialtype
;
339 case 'Y': /* change lives */
341 sptr
= &playerp
->p_lives
;
344 case 'Z': /* change crowns */
346 sptr
= &playerp
->p_crowns
;
349 case '0': /* change charms */
351 sptr
= &playerp
->p_charms
;
354 case '1': /* change amulet */
356 sptr
= &playerp
->p_amulets
;
359 case '2': /* change holy water */
360 prompt
= "holy water";
361 sptr
= &playerp
->p_holywater
;
364 case '3': /* change last-used */
365 prompt
= "last-used";
366 sptr
= &playerp
->p_lastused
;
369 case '4': /* change palantir */
371 bptr
= &playerp
->p_palantir
;
374 case '5': /* change blessing */
376 bptr
= &playerp
->p_blessing
;
379 case '6': /* change virgin */
381 bptr
= &playerp
->p_virgin
;
384 case '7': /* change blindness */
385 prompt
= "blindness";
386 bptr
= &playerp
->p_blindness
;
389 case '8': /* change ring type */
390 prompt
= "ring-type";
391 sptr
= &playerp
->p_ring
.ring_type
;
394 case '9': /* change ring duration */
395 prompt
= "ring-duration";
396 sptr
= &playerp
->p_ring
.ring_duration
;
399 case '!': /* quit, update */
401 (!ingameflag
|| playerp
!= &Player
))
402 /* turn off status if not modifying self */
404 playerp
->p_status
= S_OFF
;
405 playerp
->p_tampered
= T_OFF
;
407 writerecord(playerp
, loc
);
411 case '?': /* delete player */
412 if (ingameflag
&& playerp
== &Player
)
413 /* cannot delete self */
416 freerecord(playerp
, loc
);
424 mvprintw(23, 0, "%s = %f; %s = ", prompt
, *dptr
, prompt
);
431 mvprintw(23, 0, "%s = %d; %s = ", prompt
, *sptr
, prompt
);
434 *sptr
= (short) dtemp
;
438 mvprintw(23, 0, "%s = %c; %s = ", prompt
, flag
[(int)*bptr
],
440 c
= getanswer("\nTF", TRUE
);
453 int count
= 0; /* count in file */
455 puts(" #) Name Str Brain Quick Energy Exper Treas Type Flock%\n");
456 fseek(Monstfp
, 0L, SEEK_SET
);
457 while (fread((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
) == 1)
458 printf("%2d) %-20.20s%4.0f %4.0f %2.0f %5.0f %5.0f %2d %2d %3.0f\n", count
++,
459 Curmonster
.m_name
, Curmonster
.m_strength
, Curmonster
.m_brains
,
460 Curmonster
.m_speed
, Curmonster
.m_energy
, Curmonster
.m_experience
,
461 Curmonster
.m_treasuretype
, Curmonster
.m_type
, Curmonster
.m_flock
);
467 struct scoreboard sbuf
; /* for reading entries */
468 FILE *fp
; /* to open the file */
470 if ((fp
= fopen(_PATH_SCORE
, "r")) != NULL
) {
471 while (fread((char *) &sbuf
, SZ_SCORESTRUCT
, 1, fp
) == 1)
472 printf("%-20s (%-9s) Level: %6.0f Type: %s\n",
473 sbuf
.sb_name
, sbuf
.sb_login
, sbuf
.sb_level
, sbuf
.sb_type
);
481 fseek(Playersfp
, 0L, SEEK_SET
);
482 printf("Current characters on file are:\n\n");
484 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
485 if (Other
.p_status
!= S_NOTUSED
)
486 printf("%-20s (%-9s) Level: %6.0f %s (%s)\n",
487 Other
.p_name
, Other
.p_login
, Other
.p_level
,
488 descrtype(&Other
, FALSE
), descrstatus(&Other
));
493 purgeoldplayers(void)
495 int today
; /* day of year for today */
496 int daysold
; /* how many days since the character has been
498 time_t ltime
; /* time in seconds */
499 long loc
= 0L; /* location in file */
502 today
= localtime(<ime
)->tm_yday
;
505 fseek(Playersfp
, loc
, SEEK_SET
);
506 if (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) != 1)
509 daysold
= today
- Other
.p_lastused
;
513 if (daysold
> N_DAYSOLD
)
514 /* player hasn't been used in a while; delete */
515 freerecord(&Other
, loc
);
517 loc
+= SZ_PLAYERSTRUCT
;
524 struct scoreboard sbuf
; /* buffer to read in scoreboard entries */
525 FILE *fp
; /* to open scoreboard file */
526 long loc
= 0L; /* location in scoreboard file */
527 bool found
= FALSE
; /* set if we found an entry for this login */
529 if ((fp
= fopen(_PATH_SCORE
, "r+")) != NULL
) {
530 while (fread((char *) &sbuf
, SZ_SCORESTRUCT
, 1, fp
) == 1)
531 if (strcmp(Player
.p_login
, sbuf
.sb_login
) == 0) {
535 loc
+= SZ_SCORESTRUCT
;
542 * At this point, 'loc' will either indicate a point beyond
543 * the end of file, or the place where the previous entry
547 if ((!found
) || Player
.p_level
> sbuf
.sb_level
)
548 /* put new entry in for this login */
550 strcpy(sbuf
.sb_login
, Player
.p_login
);
551 strcpy(sbuf
.sb_name
, Player
.p_name
);
552 sbuf
.sb_level
= Player
.p_level
;
553 strcpy(sbuf
.sb_type
, descrtype(&Player
, TRUE
));
556 fseek(fp
, loc
, SEEK_SET
);
557 fwrite((char *) &sbuf
, SZ_SCORESTRUCT
, 1, fp
);