]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/gamesupport.c
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 changestats(phbool ingameflag
)
14 static char flag
[2] = /* for printing values of bools */
16 struct player
*playerp
; /* pointer to structure to alter */
17 const char *prompt
; /* pointer to prompt string */
19 int today
; /* day of year of today */
20 int temp
; /* temporary variable */
21 long loc
; /* location in player file */
22 time_t now
; /* time now */
23 double dtemp
; /* temporary variable */
24 phbool
*bptr
; /* pointer to bool item to change */
25 double *dptr
; /* pointer to double item to change */
26 short *sptr
; /* pointer to short item to change */
31 /* get name of player to examine/alter */
33 mvaddstr(5, 0, "Which character do you want to look at ? ");
34 getstring(Databuf
, SZ_DATABUF
);
37 if (Databuf
[0] == '\0')
46 /* use 'Player' structure */
49 if (strcmp(Databuf
, Player
.p_name
) == 0)
50 /* alter/examine current player */
55 /* use 'Other' structure */
58 /* find player on file */
59 if (loc
< 0L && (loc
= findname(Databuf
, playerp
)) < 0L)
60 /* didn't find player */
63 mvaddstr(11, 0, "Not found.");
67 today
= localtime(&now
)->tm_yday
;
72 /* print player structure, and prompt for action */
74 mvprintw(0, 0, "A:Name %s\n", playerp
->p_name
);
77 printw("B:Password %s\n", playerp
->p_password
);
79 addstr("B:Password XXXXXXXX\n");
81 printw(" :Login %s\n", playerp
->p_login
);
83 printw("C:Experience %.0f\n", playerp
->p_experience
);
84 printw("D:Level %.0f\n", playerp
->p_level
);
85 printw("E:Strength %.0f\n", playerp
->p_strength
);
86 printw("F:Sword %.0f\n", playerp
->p_sword
);
87 printw(" :Might %.0f\n", playerp
->p_might
);
88 printw("G:Energy %.0f\n", playerp
->p_energy
);
89 printw("H:Max-Energy %.0f\n", playerp
->p_maxenergy
);
90 printw("I:Shield %.0f\n", playerp
->p_shield
);
91 printw("J:Quickness %.0f\n", playerp
->p_quickness
);
92 printw("K:Quicksilver %.0f\n", playerp
->p_quksilver
);
93 printw(" :Speed %.0f\n", playerp
->p_speed
);
94 printw("L:Magic Level %.0f\n", playerp
->p_magiclvl
);
95 printw("M:Mana %.0f\n", playerp
->p_mana
);
96 printw("N:Brains %.0f\n", playerp
->p_brains
);
98 if (Wizard
|| playerp
->p_specialtype
!= SC_VALAR
)
99 mvaddstr(0, 40, descrstatus(playerp
));
101 mvprintw(1, 40, "O:Poison %0.3f\n", playerp
->p_poison
);
102 mvprintw(2, 40, "P:Gold %.0f\n", playerp
->p_gold
);
103 mvprintw(3, 40, "Q:Gem %.0f\n", playerp
->p_gems
);
104 mvprintw(4, 40, "R:Sin %0.3f\n", playerp
->p_sin
);
106 mvprintw(5, 40, "S:X-coord %.0f\n", playerp
->p_x
);
107 mvprintw(6, 40, "T:Y-coord %.0f\n", playerp
->p_y
);
109 mvaddstr(5, 40, "S:X-coord ?\n");
110 mvaddstr(6, 40, "T:Y-coord ?\n");
113 mvprintw(7, 40, "U:Age %ld\n", playerp
->p_age
);
114 mvprintw(8, 40, "V:Degenerated %d\n", playerp
->p_degenerated
);
116 mvprintw(9, 40, "W:Type %d (%s)\n",
117 playerp
->p_type
, descrtype(playerp
, FALSE
) + 1);
118 mvprintw(10, 40, "X:Special Type %d\n", playerp
->p_specialtype
);
119 mvprintw(11, 40, "Y:Lives %d\n", playerp
->p_lives
);
120 mvprintw(12, 40, "Z:Crowns %d\n", playerp
->p_crowns
);
121 mvprintw(13, 40, "0:Charms %d\n", playerp
->p_charms
);
122 mvprintw(14, 40, "1:Amulets %d\n", playerp
->p_amulets
);
123 mvprintw(15, 40, "2:Holy Water %d\n", playerp
->p_holywater
);
125 temp
= today
- playerp
->p_lastused
;
129 mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp
->p_lastused
, temp
);
131 mvprintw(18, 8, "4:Palantir %c 5:Blessing %c 6:Virgin %c 7:Blind %c",
132 flag
[(int)playerp
->p_palantir
],
133 flag
[(int)playerp
->p_blessing
],
134 flag
[(int)playerp
->p_virgin
],
135 flag
[(int)playerp
->p_blindness
]);
138 mvprintw(19, 8, "8:Ring %c",
139 flag
[playerp
->p_ring
.ring_type
!= R_NONE
]);
141 mvprintw(19, 8, "8:Ring %d 9:Duration %d",
142 playerp
->p_ring
.ring_type
, playerp
->p_ring
.ring_duration
);
146 && (ingameflag
|| strcmp(Login
, playerp
->p_login
) != 0))
147 /* in game or not examining own character */
157 mvaddstr(20, 0, "!:Quit ?:Delete");
158 mvaddstr(21, 0, "What would you like to change ? ");
161 c
= getanswer(" ", TRUE
);
163 /* examining own player; allow to change name and
165 c
= getanswer("!BA", FALSE
);
168 case 'A': /* change name */
169 case 'B': /* change password */
171 /* prompt for password */
173 mvaddstr(23, 0, "Password ? ");
175 getstring(Databuf
, 9);
177 if (strcmp(Databuf
, playerp
->p_password
) != 0)
183 mvaddstr(23, 0, "New name: ");
184 getstring(Databuf
, SZ_NAME
);
185 truncstring(Databuf
);
186 if (Databuf
[0] != '\0')
187 if (Wizard
|| findname(Databuf
, &Other
) < 0L)
188 strcpy(playerp
->p_name
, Databuf
);
190 /* get new password */
196 /* get two copies of new password
197 * until they match */
200 mvaddstr(23, 0, "New password ? ");
201 getstring(Databuf
, SZ_PASSWORD
);
202 if (Databuf
[0] == '\0')
205 /* get second copy */
206 mvaddstr(23, 0, "One more time ? ");
207 getstring(playerp
->p_password
, SZ_PASSWORD
);
209 while (strcmp(playerp
->p_password
, Databuf
) != 0);
216 case 'C': /* change experience */
217 prompt
= "experience";
218 dptr
= &playerp
->p_experience
;
221 case 'D': /* change level */
223 dptr
= &playerp
->p_level
;
226 case 'E': /* change strength */
228 dptr
= &playerp
->p_strength
;
231 case 'F': /* change swords */
233 dptr
= &playerp
->p_sword
;
236 case 'G': /* change energy */
238 dptr
= &playerp
->p_energy
;
241 case 'H': /* change maximum energy */
242 prompt
= "max energy";
243 dptr
= &playerp
->p_maxenergy
;
246 case 'I': /* change shields */
248 dptr
= &playerp
->p_shield
;
251 case 'J': /* change quickness */
252 prompt
= "quickness";
253 dptr
= &playerp
->p_quickness
;
256 case 'K': /* change quicksilver */
257 prompt
= "quicksilver";
258 dptr
= &playerp
->p_quksilver
;
261 case 'L': /* change magic */
262 prompt
= "magic level";
263 dptr
= &playerp
->p_magiclvl
;
266 case 'M': /* change mana */
268 dptr
= &playerp
->p_mana
;
271 case 'N': /* change brains */
273 dptr
= &playerp
->p_brains
;
276 case 'O': /* change poison */
278 dptr
= &playerp
->p_poison
;
281 case 'P': /* change gold */
283 dptr
= &playerp
->p_gold
;
286 case 'Q': /* change gems */
288 dptr
= &playerp
->p_gems
;
291 case 'R': /* change sin */
293 dptr
= &playerp
->p_sin
;
296 case 'S': /* change x coord */
298 dptr
= &playerp
->p_x
;
301 case 'T': /* change y coord */
303 dptr
= &playerp
->p_y
;
306 case 'U': /* change age */
307 mvprintw(23, 0, "age = %ld; age = ", playerp
->p_age
);
310 playerp
->p_age
= (long) dtemp
;
313 case 'V': /* change degen */
314 mvprintw(23, 0, "degen = %d; degen = ", playerp
->p_degenerated
);
317 playerp
->p_degenerated
= (int) dtemp
;
320 case 'W': /* change type */
322 sptr
= &playerp
->p_type
;
325 case 'X': /* change special type */
326 prompt
= "special type";
327 sptr
= &playerp
->p_specialtype
;
330 case 'Y': /* change lives */
332 sptr
= &playerp
->p_lives
;
335 case 'Z': /* change crowns */
337 sptr
= &playerp
->p_crowns
;
340 case '0': /* change charms */
342 sptr
= &playerp
->p_charms
;
345 case '1': /* change amulet */
347 sptr
= &playerp
->p_amulets
;
350 case '2': /* change holy water */
351 prompt
= "holy water";
352 sptr
= &playerp
->p_holywater
;
355 case '3': /* change last-used */
356 prompt
= "last-used";
357 sptr
= &playerp
->p_lastused
;
360 case '4': /* change palantir */
362 bptr
= &playerp
->p_palantir
;
365 case '5': /* change blessing */
367 bptr
= &playerp
->p_blessing
;
370 case '6': /* change virgin */
372 bptr
= &playerp
->p_virgin
;
375 case '7': /* change blindness */
376 prompt
= "blindness";
377 bptr
= &playerp
->p_blindness
;
380 case '8': /* change ring type */
381 prompt
= "ring-type";
382 sptr
= &playerp
->p_ring
.ring_type
;
385 case '9': /* change ring duration */
386 prompt
= "ring-duration";
387 sptr
= &playerp
->p_ring
.ring_duration
;
390 case '!': /* quit, update */
392 (!ingameflag
|| playerp
!= &Player
))
393 /* turn off status if not modifying self */
395 playerp
->p_status
= S_OFF
;
396 playerp
->p_tampered
= T_OFF
;
398 writerecord(playerp
, loc
);
402 case '?': /* delete player */
403 if (ingameflag
&& playerp
== &Player
)
404 /* cannot delete self */
407 freerecord(playerp
, loc
);
415 mvprintw(23, 0, "%s = %f; %s = ", prompt
, *dptr
, prompt
);
422 mvprintw(23, 0, "%s = %d; %s = ", prompt
, *sptr
, prompt
);
425 *sptr
= (short) dtemp
;
429 mvprintw(23, 0, "%s = %c; %s = ", prompt
, flag
[(int)*bptr
],
431 c
= getanswer("\nTF", TRUE
);
444 int count
= 0; /* count in file */
446 puts(" #) Name Str Brain Quick Energy Exper Treas Type Flock%\n");
447 fseek(Monstfp
, 0L, SEEK_SET
);
448 while (fread((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
) == 1)
449 printf("%2d) %-20.20s%4.0f %4.0f %2.0f %5.0f %5.0f %2d %2d %3.0f\n", count
++,
450 Curmonster
.m_name
, Curmonster
.m_strength
, Curmonster
.m_brains
,
451 Curmonster
.m_speed
, Curmonster
.m_energy
, Curmonster
.m_experience
,
452 Curmonster
.m_treasuretype
, Curmonster
.m_type
, Curmonster
.m_flock
);
458 struct scoreboard sbuf
; /* for reading entries */
459 FILE *fp
; /* to open the file */
461 if ((fp
= fopen(_PATH_SCORE
, "r")) != NULL
) {
462 while (fread((char *) &sbuf
, SZ_SCORESTRUCT
, 1, fp
) == 1)
463 printf("%-20s (%-9s) Level: %6.0f Type: %s\n",
464 sbuf
.sb_name
, sbuf
.sb_login
, sbuf
.sb_level
, sbuf
.sb_type
);
472 fseek(Playersfp
, 0L, SEEK_SET
);
473 printf("Current characters on file are:\n\n");
475 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
476 if (Other
.p_status
!= S_NOTUSED
)
477 printf("%-20s (%-9s) Level: %6.0f %s (%s)\n",
478 Other
.p_name
, Other
.p_login
, Other
.p_level
,
479 descrtype(&Other
, FALSE
), descrstatus(&Other
));
484 purgeoldplayers(void)
486 int today
; /* day of year for today */
487 int daysold
; /* how many days since the character has been
489 time_t ltime
; /* time in seconds */
490 long loc
= 0L; /* location in file */
493 today
= localtime(<ime
)->tm_yday
;
496 fseek(Playersfp
, loc
, SEEK_SET
);
497 if (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) != 1)
500 daysold
= today
- Other
.p_lastused
;
504 if (daysold
> N_DAYSOLD
)
505 /* player hasn't been used in a while; delete */
506 freerecord(&Other
, loc
);
508 loc
+= SZ_PLAYERSTRUCT
;
515 struct scoreboard sbuf
; /* buffer to read in scoreboard entries */
516 FILE *fp
; /* to open scoreboard file */
517 long loc
= 0L; /* location in scoreboard file */
518 bool found
= FALSE
; /* set if we found an entry for this login */
520 if ((fp
= fopen(_PATH_SCORE
, "r+")) != NULL
) {
521 while (fread((char *) &sbuf
, SZ_SCORESTRUCT
, 1, fp
) == 1)
522 if (strcmp(Player
.p_login
, sbuf
.sb_login
) == 0) {
526 loc
+= SZ_SCORESTRUCT
;
533 * At this point, 'loc' will either indicate a point beyond
534 * the end of file, or the place where the previous entry
538 if ((!found
) || Player
.p_level
> sbuf
.sb_level
)
539 /* put new entry in for this login */
541 strcpy(sbuf
.sb_login
, Player
.p_login
);
542 strcpy(sbuf
.sb_name
, Player
.p_name
);
543 sbuf
.sb_level
= Player
.p_level
;
544 strcpy(sbuf
.sb_type
, descrtype(&Player
, TRUE
));
547 fseek(fp
, loc
, SEEK_SET
);
548 fwrite((char *) &sbuf
, SZ_SCORESTRUCT
, 1, fp
);