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