]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/gamesupport.c
1 /* $NetBSD: gamesupport.c,v 1.6 1999/09/08 21:57:19 jsm Exp $ */
4 * gamesupport.c - auxiliary routines for support of Phantasia
10 changestats(ingameflag
)
13 static char flag
[2] = /* for printing values of bools */
15 struct player
*playerp
; /* pointer to structure to alter */
16 const char *prompt
; /* pointer to prompt string */
18 int today
; /* day of year of today */
19 int temp
; /* temporary variable */
20 long loc
; /* location in player file */
21 time_t now
; /* time now */
22 double dtemp
; /* temporary variable */
23 bool *bptr
; /* pointer to bool item to change */
24 double *dptr
; /* pointer to double item to change */
25 short *sptr
; /* pointer to short item to change */
30 /* get name of player to examine/alter */
32 mvaddstr(5, 0, "Which character do you want to look at ? ");
33 getstring(Databuf
, SZ_DATABUF
);
36 if (Databuf
[0] == '\0')
45 /* use 'Player' structure */
48 if (strcmp(Databuf
, Player
.p_name
) == 0)
49 /* alter/examine current player */
54 /* use 'Other' structure */
57 /* find player on file */
58 if (loc
< 0L && (loc
= findname(Databuf
, playerp
)) < 0L)
59 /* didn't find player */
62 mvaddstr(11, 0, "Not found.");
66 today
= localtime(&now
)->tm_yday
;
71 /* print player structure, and prompt for action */
73 mvprintw(0, 0, "A:Name %s\n", playerp
->p_name
);
76 printw("B:Password %s\n", playerp
->p_password
);
78 addstr("B:Password XXXXXXXX\n");
80 printw(" :Login %s\n", playerp
->p_login
);
82 printw("C:Experience %.0f\n", playerp
->p_experience
);
83 printw("D:Level %.0f\n", playerp
->p_level
);
84 printw("E:Strength %.0f\n", playerp
->p_strength
);
85 printw("F:Sword %.0f\n", playerp
->p_sword
);
86 printw(" :Might %.0f\n", playerp
->p_might
);
87 printw("G:Energy %.0f\n", playerp
->p_energy
);
88 printw("H:Max-Energy %.0f\n", playerp
->p_maxenergy
);
89 printw("I:Shield %.0f\n", playerp
->p_shield
);
90 printw("J:Quickness %.0f\n", playerp
->p_quickness
);
91 printw("K:Quicksilver %.0f\n", playerp
->p_quksilver
);
92 printw(" :Speed %.0f\n", playerp
->p_speed
);
93 printw("L:Magic Level %.0f\n", playerp
->p_magiclvl
);
94 printw("M:Mana %.0f\n", playerp
->p_mana
);
95 printw("N:Brains %.0f\n", playerp
->p_brains
);
97 if (Wizard
|| playerp
->p_specialtype
!= SC_VALAR
)
98 mvaddstr(0, 40, descrstatus(playerp
));
100 mvprintw(1, 40, "O:Poison %0.3f\n", playerp
->p_poison
);
101 mvprintw(2, 40, "P:Gold %.0f\n", playerp
->p_gold
);
102 mvprintw(3, 40, "Q:Gem %.0f\n", playerp
->p_gems
);
103 mvprintw(4, 40, "R:Sin %0.3f\n", playerp
->p_sin
);
105 mvprintw(5, 40, "S:X-coord %.0f\n", playerp
->p_x
);
106 mvprintw(6, 40, "T:Y-coord %.0f\n", playerp
->p_y
);
108 mvaddstr(5, 40, "S:X-coord ?\n");
109 mvaddstr(6, 40, "T:Y-coord ?\n");
112 mvprintw(7, 40, "U:Age %ld\n", playerp
->p_age
);
113 mvprintw(8, 40, "V:Degenerated %d\n", playerp
->p_degenerated
);
115 mvprintw(9, 40, "W:Type %d (%s)\n",
116 playerp
->p_type
, descrtype(playerp
, FALSE
) + 1);
117 mvprintw(10, 40, "X:Special Type %d\n", playerp
->p_specialtype
);
118 mvprintw(11, 40, "Y:Lives %d\n", playerp
->p_lives
);
119 mvprintw(12, 40, "Z:Crowns %d\n", playerp
->p_crowns
);
120 mvprintw(13, 40, "0:Charms %d\n", playerp
->p_charms
);
121 mvprintw(14, 40, "1:Amulets %d\n", playerp
->p_amulets
);
122 mvprintw(15, 40, "2:Holy Water %d\n", playerp
->p_holywater
);
124 temp
= today
- playerp
->p_lastused
;
128 mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp
->p_lastused
, temp
);
130 mvprintw(18, 8, "4:Palantir %c 5:Blessing %c 6:Virgin %c 7:Blind %c",
131 flag
[(int)playerp
->p_palantir
],
132 flag
[(int)playerp
->p_blessing
],
133 flag
[(int)playerp
->p_virgin
],
134 flag
[(int)playerp
->p_blindness
]);
137 mvprintw(19, 8, "8:Ring %c",
138 flag
[playerp
->p_ring
.ring_type
!= R_NONE
]);
140 mvprintw(19, 8, "8:Ring %d 9:Duration %d",
141 playerp
->p_ring
.ring_type
, playerp
->p_ring
.ring_duration
);
145 && (ingameflag
|| strcmp(Login
, playerp
->p_login
) != 0))
146 /* in game or not examining own character */
156 mvaddstr(20, 0, "!:Quit ?:Delete");
157 mvaddstr(21, 0, "What would you like to change ? ");
160 c
= getanswer(" ", TRUE
);
162 /* examining own player; allow to change name and
164 c
= getanswer("!BA", FALSE
);
167 case 'A': /* change name */
168 case 'B': /* change password */
170 /* prompt for password */
172 mvaddstr(23, 0, "Password ? ");
174 getstring(Databuf
, 9);
176 if (strcmp(Databuf
, playerp
->p_password
) != 0)
182 mvaddstr(23, 0, "New name: ");
183 getstring(Databuf
, SZ_NAME
);
184 truncstring(Databuf
);
185 if (Databuf
[0] != '\0')
186 if (Wizard
|| findname(Databuf
, &Other
) < 0L)
187 strcpy(playerp
->p_name
, Databuf
);
189 /* get new password */
195 /* get two copies of new password
196 * until they match */
199 mvaddstr(23, 0, "New password ? ");
200 getstring(Databuf
, SZ_PASSWORD
);
201 if (Databuf
[0] == '\0')
204 /* get second copy */
205 mvaddstr(23, 0, "One more time ? ");
206 getstring(playerp
->p_password
, SZ_PASSWORD
);
208 while (strcmp(playerp
->p_password
, Databuf
) != 0);
215 case 'C': /* change experience */
216 prompt
= "experience";
217 dptr
= &playerp
->p_experience
;
220 case 'D': /* change level */
222 dptr
= &playerp
->p_level
;
225 case 'E': /* change strength */
227 dptr
= &playerp
->p_strength
;
230 case 'F': /* change swords */
232 dptr
= &playerp
->p_sword
;
235 case 'G': /* change energy */
237 dptr
= &playerp
->p_energy
;
240 case 'H': /* change maximum energy */
241 prompt
= "max energy";
242 dptr
= &playerp
->p_maxenergy
;
245 case 'I': /* change shields */
247 dptr
= &playerp
->p_shield
;
250 case 'J': /* change quickness */
251 prompt
= "quickness";
252 dptr
= &playerp
->p_quickness
;
255 case 'K': /* change quicksilver */
256 prompt
= "quicksilver";
257 dptr
= &playerp
->p_quksilver
;
260 case 'L': /* change magic */
261 prompt
= "magic level";
262 dptr
= &playerp
->p_magiclvl
;
265 case 'M': /* change mana */
267 dptr
= &playerp
->p_mana
;
270 case 'N': /* change brains */
272 dptr
= &playerp
->p_brains
;
275 case 'O': /* change poison */
277 dptr
= &playerp
->p_poison
;
280 case 'P': /* change gold */
282 dptr
= &playerp
->p_gold
;
285 case 'Q': /* change gems */
287 dptr
= &playerp
->p_gems
;
290 case 'R': /* change sin */
292 dptr
= &playerp
->p_sin
;
295 case 'S': /* change x coord */
297 dptr
= &playerp
->p_x
;
300 case 'T': /* change y coord */
302 dptr
= &playerp
->p_y
;
305 case 'U': /* change age */
306 mvprintw(23, 0, "age = %ld; age = ", playerp
->p_age
);
309 playerp
->p_age
= (long) dtemp
;
312 case 'V': /* change degen */
313 mvprintw(23, 0, "degen = %d; degen = ", playerp
->p_degenerated
);
316 playerp
->p_degenerated
= (int) dtemp
;
319 case 'W': /* change type */
321 sptr
= &playerp
->p_type
;
324 case 'X': /* change special type */
325 prompt
= "special type";
326 sptr
= &playerp
->p_specialtype
;
329 case 'Y': /* change lives */
331 sptr
= &playerp
->p_lives
;
334 case 'Z': /* change crowns */
336 sptr
= &playerp
->p_crowns
;
339 case '0': /* change charms */
341 sptr
= &playerp
->p_charms
;
344 case '1': /* change amulet */
346 sptr
= &playerp
->p_amulets
;
349 case '2': /* change holy water */
350 prompt
= "holy water";
351 sptr
= &playerp
->p_holywater
;
354 case '3': /* change last-used */
355 prompt
= "last-used";
356 sptr
= &playerp
->p_lastused
;
359 case '4': /* change palantir */
361 bptr
= &playerp
->p_palantir
;
364 case '5': /* change blessing */
366 bptr
= &playerp
->p_blessing
;
369 case '6': /* change virgin */
371 bptr
= &playerp
->p_virgin
;
374 case '7': /* change blindness */
375 prompt
= "blindness";
376 bptr
= &playerp
->p_blindness
;
379 case '8': /* change ring type */
380 prompt
= "ring-type";
381 sptr
= &playerp
->p_ring
.ring_type
;
384 case '9': /* change ring duration */
385 prompt
= "ring-duration";
386 sptr
= &playerp
->p_ring
.ring_duration
;
389 case '!': /* quit, update */
391 (!ingameflag
|| playerp
!= &Player
))
392 /* turn off status if not modifying self */
394 playerp
->p_status
= S_OFF
;
395 playerp
->p_tampered
= T_OFF
;
397 writerecord(playerp
, loc
);
401 case '?': /* delete player */
402 if (ingameflag
&& playerp
== &Player
)
403 /* cannot delete self */
406 freerecord(playerp
, loc
);
414 mvprintw(23, 0, "%s = %f; %s = ", prompt
, *dptr
, prompt
);
421 mvprintw(23, 0, "%s = %d; %s = ", prompt
, *sptr
, prompt
);
424 *sptr
= (short) dtemp
;
428 mvprintw(23, 0, "%s = %c; %s = ", prompt
, flag
[(int)*bptr
],
430 c
= getanswer("\nTF", TRUE
);
443 int count
= 0; /* count in file */
445 puts(" #) Name Str Brain Quick Energy Exper Treas Type Flock%\n");
446 fseek(Monstfp
, 0L, SEEK_SET
);
447 while (fread((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
) == 1)
448 printf("%2d) %-20.20s%4.0f %4.0f %2.0f %5.0f %5.0f %2d %2d %3.0f\n", count
++,
449 Curmonster
.m_name
, Curmonster
.m_strength
, Curmonster
.m_brains
,
450 Curmonster
.m_speed
, Curmonster
.m_energy
, Curmonster
.m_experience
,
451 Curmonster
.m_treasuretype
, Curmonster
.m_type
, Curmonster
.m_flock
);
457 struct scoreboard sbuf
; /* for reading entries */
458 FILE *fp
; /* to open the file */
460 if ((fp
= fopen(_PATH_SCORE
, "r")) != NULL
) {
461 while (fread((char *) &sbuf
, SZ_SCORESTRUCT
, 1, fp
) == 1)
462 printf("%-20s (%-9s) Level: %6.0f Type: %s\n",
463 sbuf
.sb_name
, sbuf
.sb_login
, sbuf
.sb_level
, sbuf
.sb_type
);
471 fseek(Playersfp
, 0L, SEEK_SET
);
472 printf("Current characters on file are:\n\n");
474 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
475 if (Other
.p_status
!= S_NOTUSED
)
476 printf("%-20s (%-9s) Level: %6.0f %s (%s)\n",
477 Other
.p_name
, Other
.p_login
, Other
.p_level
,
478 descrtype(&Other
, FALSE
), descrstatus(&Other
));
485 int today
; /* day of year for today */
486 int daysold
; /* how many days since the character has been
488 time_t ltime
; /* time in seconds */
489 long loc
= 0L; /* location in file */
492 today
= localtime(<ime
)->tm_yday
;
495 fseek(Playersfp
, loc
, SEEK_SET
);
496 if (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) != 1)
499 daysold
= today
- Other
.p_lastused
;
503 if (daysold
> N_DAYSOLD
)
504 /* player hasn't been used in a while; delete */
505 freerecord(&Other
, loc
);
507 loc
+= SZ_PLAYERSTRUCT
;
514 struct scoreboard sbuf
; /* buffer to read in scoreboard entries */
515 FILE *fp
; /* to open scoreboard file */
516 long loc
= 0L; /* location in scoreboard file */
517 bool found
= FALSE
; /* set if we found an entry for this login */
519 if ((fp
= fopen(_PATH_SCORE
, "r+")) != NULL
) {
520 while (fread((char *) &sbuf
, SZ_SCORESTRUCT
, 1, fp
) == 1)
521 if (strcmp(Player
.p_login
, sbuf
.sb_login
) == 0) {
525 loc
+= SZ_SCORESTRUCT
;
532 * At this point, 'loc' will either indicate a point beyond
533 * the end of file, or the place where the previous entry
537 if ((!found
) || Player
.p_level
> sbuf
.sb_level
)
538 /* put new entry in for this login */
540 strcpy(sbuf
.sb_login
, Player
.p_login
);
541 strcpy(sbuf
.sb_name
, Player
.p_name
);
542 sbuf
.sb_level
= Player
.p_level
;
543 strcpy(sbuf
.sb_type
, descrtype(&Player
, TRUE
));
546 fseek(fp
, loc
, SEEK_SET
);
547 fwrite((char *) &sbuf
, SZ_SCORESTRUCT
, 1, fp
);