]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/gamesupport.c
ANSIfy function declarations. Object file diffs cross-checked.
[bsdgames-darwin.git] / phantasia / gamesupport.c
1 /* $NetBSD: gamesupport.c,v 1.10 2009/05/25 23:08:45 dholland Exp $ */
2
3 /*
4 * gamesupport.c - auxiliary routines for support of Phantasia
5 */
6
7 #include "include.h"
8 #undef bool
9 #include <curses.h>
10
11 void
12 changestats(phbool ingameflag)
13 {
14 static char flag[2] = /* for printing values of bools */
15 {'F', 'T'};
16 struct player *playerp; /* pointer to structure to alter */
17 const char *prompt; /* pointer to prompt string */
18 int c; /* input */
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 */
27
28 clear();
29
30 for (;;)
31 /* get name of player to examine/alter */
32 {
33 mvaddstr(5, 0, "Which character do you want to look at ? ");
34 getstring(Databuf, SZ_DATABUF);
35 truncstring(Databuf);
36
37 if (Databuf[0] == '\0')
38 userlist(ingameflag);
39 else
40 break;
41 }
42
43 loc = -1L;
44
45 if (!ingameflag)
46 /* use 'Player' structure */
47 playerp = &Player;
48 else
49 if (strcmp(Databuf, Player.p_name) == 0)
50 /* alter/examine current player */
51 {
52 playerp = &Player;
53 loc = Fileloc;
54 } else
55 /* use 'Other' structure */
56 playerp = &Other;
57
58 /* find player on file */
59 if (loc < 0L && (loc = findname(Databuf, playerp)) < 0L)
60 /* didn't find player */
61 {
62 clear();
63 mvaddstr(11, 0, "Not found.");
64 return;
65 }
66 time(&now);
67 today = localtime(&now)->tm_yday;
68
69 clear();
70
71 for (;;)
72 /* print player structure, and prompt for action */
73 {
74 mvprintw(0, 0, "A:Name %s\n", playerp->p_name);
75
76 if (Wizard)
77 printw("B:Password %s\n", playerp->p_password);
78 else
79 addstr("B:Password XXXXXXXX\n");
80
81 printw(" :Login %s\n", playerp->p_login);
82
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);
97
98 if (Wizard || playerp->p_specialtype != SC_VALAR)
99 mvaddstr(0, 40, descrstatus(playerp));
100
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);
105 if (Wizard) {
106 mvprintw(5, 40, "S:X-coord %.0f\n", playerp->p_x);
107 mvprintw(6, 40, "T:Y-coord %.0f\n", playerp->p_y);
108 } else {
109 mvaddstr(5, 40, "S:X-coord ?\n");
110 mvaddstr(6, 40, "T:Y-coord ?\n");
111 }
112
113 mvprintw(7, 40, "U:Age %ld\n", playerp->p_age);
114 mvprintw(8, 40, "V:Degenerated %d\n", playerp->p_degenerated);
115
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);
124
125 temp = today - playerp->p_lastused;
126 if (temp < 0)
127 /* last year */
128 temp += 365;
129 mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp->p_lastused, temp);
130
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]);
136
137 if (!Wizard)
138 mvprintw(19, 8, "8:Ring %c",
139 flag[playerp->p_ring.ring_type != R_NONE]);
140 else
141 mvprintw(19, 8, "8:Ring %d 9:Duration %d",
142 playerp->p_ring.ring_type, playerp->p_ring.ring_duration);
143
144 if (!Wizard
145 /* not wizard */
146 && (ingameflag || strcmp(Login, playerp->p_login) != 0))
147 /* in game or not examining own character */
148 {
149 if (ingameflag) {
150 more(LINES - 1);
151 clear();
152 return;
153 } else
154 cleanup(TRUE);
155 /* NOTREACHED */
156 }
157 mvaddstr(20, 0, "!:Quit ?:Delete");
158 mvaddstr(21, 0, "What would you like to change ? ");
159
160 if (Wizard)
161 c = getanswer(" ", TRUE);
162 else
163 /* examining own player; allow to change name and
164 * password */
165 c = getanswer("!BA", FALSE);
166
167 switch (c) {
168 case 'A': /* change name */
169 case 'B': /* change password */
170 if (!Wizard)
171 /* prompt for password */
172 {
173 mvaddstr(23, 0, "Password ? ");
174 Echo = FALSE;
175 getstring(Databuf, 9);
176 Echo = TRUE;
177 if (strcmp(Databuf, playerp->p_password) != 0)
178 continue;
179 }
180 if (c == 'A')
181 /* get new name */
182 {
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);
189 } else
190 /* get new password */
191 {
192 if (!Wizard)
193 Echo = FALSE;
194
195 do
196 /* get two copies of new password
197 * until they match */
198 {
199 /* get first copy */
200 mvaddstr(23, 0, "New password ? ");
201 getstring(Databuf, SZ_PASSWORD);
202 if (Databuf[0] == '\0')
203 break;
204
205 /* get second copy */
206 mvaddstr(23, 0, "One more time ? ");
207 getstring(playerp->p_password, SZ_PASSWORD);
208 }
209 while (strcmp(playerp->p_password, Databuf) != 0);
210
211 Echo = TRUE;
212 }
213
214 continue;
215
216 case 'C': /* change experience */
217 prompt = "experience";
218 dptr = &playerp->p_experience;
219 goto DALTER;
220
221 case 'D': /* change level */
222 prompt = "level";
223 dptr = &playerp->p_level;
224 goto DALTER;
225
226 case 'E': /* change strength */
227 prompt = "strength";
228 dptr = &playerp->p_strength;
229 goto DALTER;
230
231 case 'F': /* change swords */
232 prompt = "sword";
233 dptr = &playerp->p_sword;
234 goto DALTER;
235
236 case 'G': /* change energy */
237 prompt = "energy";
238 dptr = &playerp->p_energy;
239 goto DALTER;
240
241 case 'H': /* change maximum energy */
242 prompt = "max energy";
243 dptr = &playerp->p_maxenergy;
244 goto DALTER;
245
246 case 'I': /* change shields */
247 prompt = "shield";
248 dptr = &playerp->p_shield;
249 goto DALTER;
250
251 case 'J': /* change quickness */
252 prompt = "quickness";
253 dptr = &playerp->p_quickness;
254 goto DALTER;
255
256 case 'K': /* change quicksilver */
257 prompt = "quicksilver";
258 dptr = &playerp->p_quksilver;
259 goto DALTER;
260
261 case 'L': /* change magic */
262 prompt = "magic level";
263 dptr = &playerp->p_magiclvl;
264 goto DALTER;
265
266 case 'M': /* change mana */
267 prompt = "mana";
268 dptr = &playerp->p_mana;
269 goto DALTER;
270
271 case 'N': /* change brains */
272 prompt = "brains";
273 dptr = &playerp->p_brains;
274 goto DALTER;
275
276 case 'O': /* change poison */
277 prompt = "poison";
278 dptr = &playerp->p_poison;
279 goto DALTER;
280
281 case 'P': /* change gold */
282 prompt = "gold";
283 dptr = &playerp->p_gold;
284 goto DALTER;
285
286 case 'Q': /* change gems */
287 prompt = "gems";
288 dptr = &playerp->p_gems;
289 goto DALTER;
290
291 case 'R': /* change sin */
292 prompt = "sin";
293 dptr = &playerp->p_sin;
294 goto DALTER;
295
296 case 'S': /* change x coord */
297 prompt = "x";
298 dptr = &playerp->p_x;
299 goto DALTER;
300
301 case 'T': /* change y coord */
302 prompt = "y";
303 dptr = &playerp->p_y;
304 goto DALTER;
305
306 case 'U': /* change age */
307 mvprintw(23, 0, "age = %ld; age = ", playerp->p_age);
308 dtemp = infloat();
309 if (dtemp != 0.0)
310 playerp->p_age = (long) dtemp;
311 continue;
312
313 case 'V': /* change degen */
314 mvprintw(23, 0, "degen = %d; degen = ", playerp->p_degenerated);
315 dtemp = infloat();
316 if (dtemp != 0.0)
317 playerp->p_degenerated = (int) dtemp;
318 continue;
319
320 case 'W': /* change type */
321 prompt = "type";
322 sptr = &playerp->p_type;
323 goto SALTER;
324
325 case 'X': /* change special type */
326 prompt = "special type";
327 sptr = &playerp->p_specialtype;
328 goto SALTER;
329
330 case 'Y': /* change lives */
331 prompt = "lives";
332 sptr = &playerp->p_lives;
333 goto SALTER;
334
335 case 'Z': /* change crowns */
336 prompt = "crowns";
337 sptr = &playerp->p_crowns;
338 goto SALTER;
339
340 case '0': /* change charms */
341 prompt = "charm";
342 sptr = &playerp->p_charms;
343 goto SALTER;
344
345 case '1': /* change amulet */
346 prompt = "amulet";
347 sptr = &playerp->p_amulets;
348 goto SALTER;
349
350 case '2': /* change holy water */
351 prompt = "holy water";
352 sptr = &playerp->p_holywater;
353 goto SALTER;
354
355 case '3': /* change last-used */
356 prompt = "last-used";
357 sptr = &playerp->p_lastused;
358 goto SALTER;
359
360 case '4': /* change palantir */
361 prompt = "palantir";
362 bptr = &playerp->p_palantir;
363 goto BALTER;
364
365 case '5': /* change blessing */
366 prompt = "blessing";
367 bptr = &playerp->p_blessing;
368 goto BALTER;
369
370 case '6': /* change virgin */
371 prompt = "virgin";
372 bptr = &playerp->p_virgin;
373 goto BALTER;
374
375 case '7': /* change blindness */
376 prompt = "blindness";
377 bptr = &playerp->p_blindness;
378 goto BALTER;
379
380 case '8': /* change ring type */
381 prompt = "ring-type";
382 sptr = &playerp->p_ring.ring_type;
383 goto SALTER;
384
385 case '9': /* change ring duration */
386 prompt = "ring-duration";
387 sptr = &playerp->p_ring.ring_duration;
388 goto SALTER;
389
390 case '!': /* quit, update */
391 if (Wizard &&
392 (!ingameflag || playerp != &Player))
393 /* turn off status if not modifying self */
394 {
395 playerp->p_status = S_OFF;
396 playerp->p_tampered = T_OFF;
397 }
398 writerecord(playerp, loc);
399 clear();
400 return;
401
402 case '?': /* delete player */
403 if (ingameflag && playerp == &Player)
404 /* cannot delete self */
405 continue;
406
407 freerecord(playerp, loc);
408 clear();
409 return;
410
411 default:
412 continue;
413 }
414 DALTER:
415 mvprintw(23, 0, "%s = %f; %s = ", prompt, *dptr, prompt);
416 dtemp = infloat();
417 if (dtemp != 0.0)
418 *dptr = dtemp;
419 continue;
420
421 SALTER:
422 mvprintw(23, 0, "%s = %d; %s = ", prompt, *sptr, prompt);
423 dtemp = infloat();
424 if (dtemp != 0.0)
425 *sptr = (short) dtemp;
426 continue;
427
428 BALTER:
429 mvprintw(23, 0, "%s = %c; %s = ", prompt, flag[(int)*bptr],
430 prompt);
431 c = getanswer("\nTF", TRUE);
432 if (c == 'T')
433 *bptr = TRUE;
434 else
435 if (c == 'F')
436 *bptr = FALSE;
437 continue;
438 }
439 }
440
441 void
442 monstlist(void)
443 {
444 int count = 0; /* count in file */
445
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);
453 }
454
455 void
456 scorelist(void)
457 {
458 struct scoreboard sbuf; /* for reading entries */
459 FILE *fp; /* to open the file */
460
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);
465 fclose(fp);
466 }
467 }
468
469 void
470 activelist(void)
471 {
472 fseek(Playersfp, 0L, SEEK_SET);
473 printf("Current characters on file are:\n\n");
474
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));
480
481 }
482
483 void
484 purgeoldplayers(void)
485 {
486 int today; /* day of year for today */
487 int daysold; /* how many days since the character has been
488 * used */
489 time_t ltime; /* time in seconds */
490 long loc = 0L; /* location in file */
491
492 time(&ltime);
493 today = localtime(&ltime)->tm_yday;
494
495 for (;;) {
496 fseek(Playersfp, loc, SEEK_SET);
497 if (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) != 1)
498 break;
499
500 daysold = today - Other.p_lastused;
501 if (daysold < 0)
502 daysold += 365;
503
504 if (daysold > N_DAYSOLD)
505 /* player hasn't been used in a while; delete */
506 freerecord(&Other, loc);
507
508 loc += SZ_PLAYERSTRUCT;
509 }
510 }
511
512 void
513 enterscore(void)
514 {
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 */
519
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) {
523 found = TRUE;
524 break;
525 } else
526 loc += SZ_SCORESTRUCT;
527 } else {
528 error(_PATH_SCORE);
529 /* NOTREACHED */
530 }
531
532 /*
533 * At this point, 'loc' will either indicate a point beyond
534 * the end of file, or the place where the previous entry
535 * was found.
536 */
537
538 if ((!found) || Player.p_level > sbuf.sb_level)
539 /* put new entry in for this login */
540 {
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));
545 }
546 /* update entry */
547 fseek(fp, loc, SEEK_SET);
548 fwrite((char *) &sbuf, SZ_SCORESTRUCT, 1, fp);
549 fclose(fp);
550 }