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