gamesupport.c revision 1.1 1 1.1 jtc /*
2 1.1 jtc * gamesupport.c - auxiliary routines for support of Phantasia
3 1.1 jtc */
4 1.1 jtc
5 1.1 jtc #include "include.h"
6 1.1 jtc
7 1.1 jtc /************************************************************************
8 1.1 jtc /
9 1.1 jtc / FUNCTION NAME: changestats()
10 1.1 jtc /
11 1.1 jtc / FUNCTION: examine/change statistics for a player
12 1.1 jtc /
13 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
14 1.1 jtc /
15 1.1 jtc / ARGUMENTS:
16 1.1 jtc / bool ingameflag - set if called while playing game (Wizard only)
17 1.1 jtc /
18 1.1 jtc / RETURN VALUE: none
19 1.1 jtc /
20 1.1 jtc / MODULES CALLED: freerecord(), writerecord(), descrstatus(), truncstring(),
21 1.1 jtc / time(), more(), wmove(), wclear(), strcmp(), printw(), strcpy(),
22 1.1 jtc / infloat(), waddstr(), cleanup(), findname(), userlist(), mvprintw(),
23 1.1 jtc / localtime(), getanswer(), descrtype(), getstring()
24 1.1 jtc /
25 1.1 jtc / GLOBAL INPUTS: LINES, *Login, Other, Wizard, Player, *stdscr, Databuf[],
26 1.1 jtc / Fileloc
27 1.1 jtc /
28 1.1 jtc / GLOBAL OUTPUTS: Echo
29 1.1 jtc /
30 1.1 jtc / DESCRIPTION:
31 1.1 jtc / Prompt for player name to examine/change.
32 1.1 jtc / If the name is NULL, print a list of all players.
33 1.1 jtc / If we are called from within the game, check for the
34 1.1 jtc / desired name being the same as the current player's name.
35 1.1 jtc / Only the 'Wizard' may alter players.
36 1.1 jtc / Items are changed only if a non-zero value is specified.
37 1.1 jtc / To change an item to 0, use 0.1; it will be truncated later.
38 1.1 jtc /
39 1.1 jtc / Players may alter their names and passwords, if the following
40 1.1 jtc / are true:
41 1.1 jtc / - current login matches the character's logins
42 1.1 jtc / - the password is known
43 1.1 jtc / - the player is not in the middle of the game (ingameflag == FALSE)
44 1.1 jtc /
45 1.1 jtc / The last condition is imposed for two reasons:
46 1.1 jtc / - the game could possibly get a bit hectic if a player were
47 1.1 jtc / continually changing his/her name
48 1.1 jtc / - another player structure would be necessary to check for names
49 1.1 jtc / already in use
50 1.1 jtc /
51 1.1 jtc /************************************************************************/
52 1.1 jtc
53 1.1 jtc changestats(ingameflag)
54 1.1 jtc bool ingameflag;
55 1.1 jtc {
56 1.1 jtc static char flag[2] = /* for printing values of bools */
57 1.1 jtc {'F', 'T'};
58 1.1 jtc register struct player *playerp;/* pointer to structure to alter */
59 1.1 jtc register char *prompt; /* pointer to prompt string */
60 1.1 jtc int c; /* input */
61 1.1 jtc int today; /* day of year of today */
62 1.1 jtc int temp; /* temporary variable */
63 1.1 jtc long loc; /* location in player file */
64 1.1 jtc long now; /* time now */
65 1.1 jtc double dtemp; /* temporary variable */
66 1.1 jtc bool *bptr; /* pointer to bool item to change */
67 1.1 jtc double *dptr; /* pointer to double item to change */
68 1.1 jtc short *sptr; /* pointer to short item to change */
69 1.1 jtc
70 1.1 jtc clear();
71 1.1 jtc
72 1.1 jtc for (;;)
73 1.1 jtc /* get name of player to examine/alter */
74 1.1 jtc {
75 1.1 jtc mvaddstr(5, 0, "Which character do you want to look at ? ");
76 1.1 jtc getstring(Databuf, SZ_DATABUF);
77 1.1 jtc truncstring(Databuf);
78 1.1 jtc
79 1.1 jtc if (Databuf[0] == '\0')
80 1.1 jtc userlist(ingameflag);
81 1.1 jtc else
82 1.1 jtc break;
83 1.1 jtc }
84 1.1 jtc
85 1.1 jtc loc = -1L;
86 1.1 jtc
87 1.1 jtc if (!ingameflag)
88 1.1 jtc /* use 'Player' structure */
89 1.1 jtc playerp = &Player;
90 1.1 jtc else if (strcmp(Databuf, Player.p_name) == 0)
91 1.1 jtc /* alter/examine current player */
92 1.1 jtc {
93 1.1 jtc playerp = &Player;
94 1.1 jtc loc = Fileloc;
95 1.1 jtc }
96 1.1 jtc else
97 1.1 jtc /* use 'Other' structure */
98 1.1 jtc playerp = &Other;
99 1.1 jtc
100 1.1 jtc /* find player on file */
101 1.1 jtc if (loc < 0L && (loc = findname(Databuf, playerp)) < 0L)
102 1.1 jtc /* didn't find player */
103 1.1 jtc {
104 1.1 jtc clear();
105 1.1 jtc mvaddstr(11, 0, "Not found.");
106 1.1 jtc return;
107 1.1 jtc }
108 1.1 jtc
109 1.1 jtc time(&now);
110 1.1 jtc today = localtime(&now)->tm_yday;
111 1.1 jtc
112 1.1 jtc clear();
113 1.1 jtc
114 1.1 jtc for (;;)
115 1.1 jtc /* print player structure, and prompt for action */
116 1.1 jtc {
117 1.1 jtc mvprintw(0, 0,"A:Name %s\n", playerp->p_name);
118 1.1 jtc
119 1.1 jtc if (Wizard)
120 1.1 jtc printw("B:Password %s\n", playerp->p_password);
121 1.1 jtc else
122 1.1 jtc addstr("B:Password XXXXXXXX\n");
123 1.1 jtc
124 1.1 jtc printw(" :Login %s\n", playerp->p_login);
125 1.1 jtc
126 1.1 jtc printw("C:Experience %.0f\n", playerp->p_experience);
127 1.1 jtc printw("D:Level %.0f\n", playerp->p_level);
128 1.1 jtc printw("E:Strength %.0f\n", playerp->p_strength);
129 1.1 jtc printw("F:Sword %.0f\n", playerp->p_sword);
130 1.1 jtc printw(" :Might %.0f\n", playerp->p_might);
131 1.1 jtc printw("G:Energy %.0f\n", playerp->p_energy);
132 1.1 jtc printw("H:Max-Energy %.0f\n", playerp->p_maxenergy);
133 1.1 jtc printw("I:Shield %.0f\n", playerp->p_shield);
134 1.1 jtc printw("J:Quickness %.0f\n", playerp->p_quickness);
135 1.1 jtc printw("K:Quicksilver %.0f\n", playerp->p_quksilver);
136 1.1 jtc printw(" :Speed %.0f\n", playerp->p_speed);
137 1.1 jtc printw("L:Magic Level %.0f\n", playerp->p_magiclvl);
138 1.1 jtc printw("M:Mana %.0f\n", playerp->p_mana);
139 1.1 jtc printw("N:Brains %.0f\n", playerp->p_brains);
140 1.1 jtc
141 1.1 jtc if (Wizard || playerp->p_specialtype != SC_VALAR)
142 1.1 jtc mvaddstr(0, 40, descrstatus(playerp));
143 1.1 jtc
144 1.1 jtc mvprintw(1, 40, "O:Poison %0.3f\n", playerp->p_poison);
145 1.1 jtc mvprintw(2, 40, "P:Gold %.0f\n", playerp->p_gold);
146 1.1 jtc mvprintw(3, 40, "Q:Gem %.0f\n", playerp->p_gems);
147 1.1 jtc mvprintw(4, 40, "R:Sin %0.3f\n", playerp->p_sin);
148 1.1 jtc if (Wizard)
149 1.1 jtc {
150 1.1 jtc mvprintw(5, 40, "S:X-coord %.0f\n", playerp->p_x);
151 1.1 jtc mvprintw(6, 40, "T:Y-coord %.0f\n", playerp->p_y);
152 1.1 jtc }
153 1.1 jtc else
154 1.1 jtc {
155 1.1 jtc mvaddstr(5, 40, "S:X-coord ?\n");
156 1.1 jtc mvaddstr(6, 40, "T:Y-coord ?\n");
157 1.1 jtc }
158 1.1 jtc
159 1.1 jtc mvprintw(7, 40, "U:Age %ld\n", playerp->p_age);
160 1.1 jtc mvprintw(8, 40, "V:Degenerated %d\n", playerp->p_degenerated);
161 1.1 jtc
162 1.1 jtc mvprintw(9, 40, "W:Type %d (%s)\n",
163 1.1 jtc playerp->p_type, descrtype(playerp, FALSE) + 1);
164 1.1 jtc mvprintw(10, 40, "X:Special Type %d\n", playerp->p_specialtype);
165 1.1 jtc mvprintw(11, 40, "Y:Lives %d\n", playerp->p_lives);
166 1.1 jtc mvprintw(12, 40, "Z:Crowns %d\n", playerp->p_crowns);
167 1.1 jtc mvprintw(13, 40, "0:Charms %d\n", playerp->p_charms);
168 1.1 jtc mvprintw(14, 40, "1:Amulets %d\n", playerp->p_amulets);
169 1.1 jtc mvprintw(15, 40, "2:Holy Water %d\n", playerp->p_holywater);
170 1.1 jtc
171 1.1 jtc temp = today - playerp->p_lastused;
172 1.1 jtc if (temp < 0)
173 1.1 jtc /* last year */
174 1.1 jtc temp += 365;
175 1.1 jtc mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp->p_lastused, temp);
176 1.1 jtc
177 1.1 jtc mvprintw(18, 8, "4:Palantir %c 5:Blessing %c 6:Virgin %c 7:Blind %c",
178 1.1 jtc flag[playerp->p_palantir],
179 1.1 jtc flag[playerp->p_blessing],
180 1.1 jtc flag[playerp->p_virgin],
181 1.1 jtc flag[playerp->p_blindness]);
182 1.1 jtc
183 1.1 jtc if (!Wizard)
184 1.1 jtc mvprintw(19, 8, "8:Ring %c",
185 1.1 jtc flag[playerp->p_ring.ring_type != R_NONE]);
186 1.1 jtc else
187 1.1 jtc mvprintw(19, 8, "8:Ring %d 9:Duration %d",
188 1.1 jtc playerp->p_ring.ring_type, playerp->p_ring.ring_duration);
189 1.1 jtc
190 1.1 jtc if (!Wizard
191 1.1 jtc /* not wizard */
192 1.1 jtc && (ingameflag || strcmp(Login, playerp->p_login) != 0))
193 1.1 jtc /* in game or not examining own character */
194 1.1 jtc {
195 1.1 jtc if (ingameflag)
196 1.1 jtc {
197 1.1 jtc more(LINES - 1);
198 1.1 jtc clear();
199 1.1 jtc return;
200 1.1 jtc }
201 1.1 jtc else
202 1.1 jtc cleanup(TRUE);
203 1.1 jtc /*NOTREACHED*/
204 1.1 jtc }
205 1.1 jtc
206 1.1 jtc mvaddstr(20, 0, "!:Quit ?:Delete");
207 1.1 jtc mvaddstr(21, 0, "What would you like to change ? ");
208 1.1 jtc
209 1.1 jtc if (Wizard)
210 1.1 jtc c = getanswer(" ", TRUE);
211 1.1 jtc else
212 1.1 jtc /* examining own player; allow to change name and password */
213 1.1 jtc c = getanswer("!BA", FALSE);
214 1.1 jtc
215 1.1 jtc switch (c)
216 1.1 jtc {
217 1.1 jtc case 'A': /* change name */
218 1.1 jtc case 'B': /* change password */
219 1.1 jtc if (!Wizard)
220 1.1 jtc /* prompt for password */
221 1.1 jtc {
222 1.1 jtc mvaddstr(23, 0, "Password ? ");
223 1.1 jtc Echo = FALSE;
224 1.1 jtc getstring(Databuf, 9);
225 1.1 jtc Echo = TRUE;
226 1.1 jtc if (strcmp(Databuf, playerp->p_password) != 0)
227 1.1 jtc continue;
228 1.1 jtc }
229 1.1 jtc
230 1.1 jtc if (c == 'A')
231 1.1 jtc /* get new name */
232 1.1 jtc {
233 1.1 jtc mvaddstr(23, 0, "New name: ");
234 1.1 jtc getstring(Databuf, SZ_NAME);
235 1.1 jtc truncstring(Databuf);
236 1.1 jtc if (Databuf[0] != '\0')
237 1.1 jtc if (Wizard || findname(Databuf, &Other) < 0L)
238 1.1 jtc strcpy(playerp->p_name, Databuf);
239 1.1 jtc }
240 1.1 jtc else
241 1.1 jtc /* get new password */
242 1.1 jtc {
243 1.1 jtc if (!Wizard)
244 1.1 jtc Echo = FALSE;
245 1.1 jtc
246 1.1 jtc do
247 1.1 jtc /* get two copies of new password until they match */
248 1.1 jtc {
249 1.1 jtc /* get first copy */
250 1.1 jtc mvaddstr(23, 0, "New password ? ");
251 1.1 jtc getstring(Databuf, SZ_PASSWORD);
252 1.1 jtc if (Databuf[0] == '\0')
253 1.1 jtc break;
254 1.1 jtc
255 1.1 jtc /* get second copy */
256 1.1 jtc mvaddstr(23, 0, "One more time ? ");
257 1.1 jtc getstring(playerp->p_password, SZ_PASSWORD);
258 1.1 jtc }
259 1.1 jtc while (strcmp(playerp->p_password, Databuf) != 0);
260 1.1 jtc
261 1.1 jtc Echo = TRUE;
262 1.1 jtc }
263 1.1 jtc
264 1.1 jtc continue;
265 1.1 jtc
266 1.1 jtc case 'C': /* change experience */
267 1.1 jtc prompt = "experience";
268 1.1 jtc dptr = &playerp->p_experience;
269 1.1 jtc goto DALTER;
270 1.1 jtc
271 1.1 jtc case 'D': /* change level */
272 1.1 jtc prompt = "level";
273 1.1 jtc dptr = &playerp->p_level;
274 1.1 jtc goto DALTER;
275 1.1 jtc
276 1.1 jtc case 'E': /* change strength */
277 1.1 jtc prompt = "strength";
278 1.1 jtc dptr = &playerp->p_strength;
279 1.1 jtc goto DALTER;
280 1.1 jtc
281 1.1 jtc case 'F': /* change swords */
282 1.1 jtc prompt = "sword";
283 1.1 jtc dptr = &playerp->p_sword;
284 1.1 jtc goto DALTER;
285 1.1 jtc
286 1.1 jtc case 'G': /* change energy */
287 1.1 jtc prompt = "energy";
288 1.1 jtc dptr = &playerp->p_energy;
289 1.1 jtc goto DALTER;
290 1.1 jtc
291 1.1 jtc case 'H': /* change maximum energy */
292 1.1 jtc prompt = "max energy";
293 1.1 jtc dptr = &playerp->p_maxenergy;
294 1.1 jtc goto DALTER;
295 1.1 jtc
296 1.1 jtc case 'I': /* change shields */
297 1.1 jtc prompt = "shield";
298 1.1 jtc dptr = &playerp->p_shield;
299 1.1 jtc goto DALTER;
300 1.1 jtc
301 1.1 jtc case 'J': /* change quickness */
302 1.1 jtc prompt = "quickness";
303 1.1 jtc dptr = &playerp->p_quickness;
304 1.1 jtc goto DALTER;
305 1.1 jtc
306 1.1 jtc case 'K': /* change quicksilver */
307 1.1 jtc prompt = "quicksilver";
308 1.1 jtc dptr = &playerp->p_quksilver;
309 1.1 jtc goto DALTER;
310 1.1 jtc
311 1.1 jtc case 'L': /* change magic */
312 1.1 jtc prompt = "magic level";
313 1.1 jtc dptr = &playerp->p_magiclvl;
314 1.1 jtc goto DALTER;
315 1.1 jtc
316 1.1 jtc case 'M': /* change mana */
317 1.1 jtc prompt = "mana";
318 1.1 jtc dptr = &playerp->p_mana;
319 1.1 jtc goto DALTER;
320 1.1 jtc
321 1.1 jtc case 'N': /* change brains */
322 1.1 jtc prompt = "brains";
323 1.1 jtc dptr = &playerp->p_brains;
324 1.1 jtc goto DALTER;
325 1.1 jtc
326 1.1 jtc case 'O': /* change poison */
327 1.1 jtc prompt = "poison";
328 1.1 jtc dptr = &playerp->p_poison;
329 1.1 jtc goto DALTER;
330 1.1 jtc
331 1.1 jtc case 'P': /* change gold */
332 1.1 jtc prompt = "gold";
333 1.1 jtc dptr = &playerp->p_gold;
334 1.1 jtc goto DALTER;
335 1.1 jtc
336 1.1 jtc case 'Q': /* change gems */
337 1.1 jtc prompt = "gems";
338 1.1 jtc dptr = &playerp->p_gems;
339 1.1 jtc goto DALTER;
340 1.1 jtc
341 1.1 jtc case 'R': /* change sin */
342 1.1 jtc prompt = "sin";
343 1.1 jtc dptr = &playerp->p_sin;
344 1.1 jtc goto DALTER;
345 1.1 jtc
346 1.1 jtc case 'S': /* change x coord */
347 1.1 jtc prompt = "x";
348 1.1 jtc dptr = &playerp->p_x;
349 1.1 jtc goto DALTER;
350 1.1 jtc
351 1.1 jtc case 'T': /* change y coord */
352 1.1 jtc prompt = "y";
353 1.1 jtc dptr = &playerp->p_y;
354 1.1 jtc goto DALTER;
355 1.1 jtc
356 1.1 jtc case 'U': /* change age */
357 1.1 jtc mvprintw(23, 0, "age = %ld; age = ", playerp->p_age);
358 1.1 jtc dtemp = infloat();
359 1.1 jtc if (dtemp != 0.0)
360 1.1 jtc playerp->p_age = (long) dtemp;
361 1.1 jtc continue;
362 1.1 jtc
363 1.1 jtc case 'V': /* change degen */
364 1.1 jtc mvprintw(23, 0, "degen = %d; degen = ", playerp->p_degenerated);
365 1.1 jtc dtemp = infloat();
366 1.1 jtc if (dtemp != 0.0)
367 1.1 jtc playerp->p_degenerated = (int) dtemp;
368 1.1 jtc continue;
369 1.1 jtc
370 1.1 jtc case 'W': /* change type */
371 1.1 jtc prompt = "type";
372 1.1 jtc sptr = &playerp->p_type;
373 1.1 jtc goto SALTER;
374 1.1 jtc
375 1.1 jtc case 'X': /* change special type */
376 1.1 jtc prompt = "special type";
377 1.1 jtc sptr = &playerp->p_specialtype;
378 1.1 jtc goto SALTER;
379 1.1 jtc
380 1.1 jtc case 'Y': /* change lives */
381 1.1 jtc prompt = "lives";
382 1.1 jtc sptr = &playerp->p_lives;
383 1.1 jtc goto SALTER;
384 1.1 jtc
385 1.1 jtc case 'Z': /* change crowns */
386 1.1 jtc prompt = "crowns";
387 1.1 jtc sptr = &playerp->p_crowns;
388 1.1 jtc goto SALTER;
389 1.1 jtc
390 1.1 jtc case '0': /* change charms */
391 1.1 jtc prompt = "charm";
392 1.1 jtc sptr = &playerp->p_charms;
393 1.1 jtc goto SALTER;
394 1.1 jtc
395 1.1 jtc case '1': /* change amulet */
396 1.1 jtc prompt = "amulet";
397 1.1 jtc sptr = &playerp->p_amulets;
398 1.1 jtc goto SALTER;
399 1.1 jtc
400 1.1 jtc case '2': /* change holy water */
401 1.1 jtc prompt = "holy water";
402 1.1 jtc sptr = &playerp->p_holywater;
403 1.1 jtc goto SALTER;
404 1.1 jtc
405 1.1 jtc case '3': /* change last-used */
406 1.1 jtc prompt = "last-used";
407 1.1 jtc sptr = &playerp->p_lastused;
408 1.1 jtc goto SALTER;
409 1.1 jtc
410 1.1 jtc case '4': /* change palantir */
411 1.1 jtc prompt = "palantir";
412 1.1 jtc bptr = &playerp->p_palantir;
413 1.1 jtc goto BALTER;
414 1.1 jtc
415 1.1 jtc case '5': /* change blessing */
416 1.1 jtc prompt = "blessing";
417 1.1 jtc bptr = &playerp->p_blessing;
418 1.1 jtc goto BALTER;
419 1.1 jtc
420 1.1 jtc case '6': /* change virgin */
421 1.1 jtc prompt = "virgin";
422 1.1 jtc bptr = &playerp->p_virgin;
423 1.1 jtc goto BALTER;
424 1.1 jtc
425 1.1 jtc case '7': /* change blindness */
426 1.1 jtc prompt = "blindness";
427 1.1 jtc bptr = &playerp->p_blindness;
428 1.1 jtc goto BALTER;
429 1.1 jtc
430 1.1 jtc case '8': /* change ring type */
431 1.1 jtc prompt = "ring-type";
432 1.1 jtc sptr = &playerp->p_ring.ring_type;
433 1.1 jtc goto SALTER;
434 1.1 jtc
435 1.1 jtc case '9': /* change ring duration */
436 1.1 jtc prompt = "ring-duration";
437 1.1 jtc sptr = &playerp->p_ring.ring_duration;
438 1.1 jtc goto SALTER;
439 1.1 jtc
440 1.1 jtc case '!': /* quit, update */
441 1.1 jtc if (Wizard &&
442 1.1 jtc (!ingameflag || playerp != &Player))
443 1.1 jtc /* turn off status if not modifying self */
444 1.1 jtc {
445 1.1 jtc playerp->p_status = S_OFF;
446 1.1 jtc playerp->p_tampered = T_OFF;
447 1.1 jtc }
448 1.1 jtc
449 1.1 jtc writerecord(playerp, loc);
450 1.1 jtc clear();
451 1.1 jtc return;
452 1.1 jtc
453 1.1 jtc case '?': /* delete player */
454 1.1 jtc if (ingameflag && playerp == &Player)
455 1.1 jtc /* cannot delete self */
456 1.1 jtc continue;
457 1.1 jtc
458 1.1 jtc freerecord(playerp, loc);
459 1.1 jtc clear();
460 1.1 jtc return;
461 1.1 jtc
462 1.1 jtc default:
463 1.1 jtc continue;
464 1.1 jtc }
465 1.1 jtc DALTER:
466 1.1 jtc mvprintw(23, 0, "%s = %f; %s = ", prompt, *dptr, prompt);
467 1.1 jtc dtemp = infloat();
468 1.1 jtc if (dtemp != 0.0)
469 1.1 jtc *dptr = dtemp;
470 1.1 jtc continue;
471 1.1 jtc
472 1.1 jtc SALTER:
473 1.1 jtc mvprintw(23, 0, "%s = %d; %s = ", prompt, *sptr, prompt);
474 1.1 jtc dtemp = infloat();
475 1.1 jtc if (dtemp != 0.0)
476 1.1 jtc *sptr = (short) dtemp;
477 1.1 jtc continue;
478 1.1 jtc
479 1.1 jtc BALTER:
480 1.1 jtc mvprintw(23, 0, "%s = %c; %s = ", prompt, flag[*bptr], prompt);
481 1.1 jtc c = getanswer("\nTF", TRUE);
482 1.1 jtc if (c == 'T')
483 1.1 jtc *bptr = TRUE;
484 1.1 jtc else if (c == 'F')
485 1.1 jtc *bptr = FALSE;
486 1.1 jtc continue;
487 1.1 jtc }
488 1.1 jtc }
489 1.1 jtc /**/
491 1.1 jtc /************************************************************************
492 1.1 jtc /
493 1.1 jtc / FUNCTION NAME: monstlist()
494 1.1 jtc /
495 1.1 jtc / FUNCTION: print a monster listing
496 1.1 jtc /
497 1.1 jtc / AUTHOR: E. A. Estes, 2/27/86
498 1.1 jtc /
499 1.1 jtc / ARGUMENTS: none
500 1.1 jtc /
501 1.1 jtc / RETURN VALUE: none
502 1.1 jtc /
503 1.1 jtc / MODULES CALLED: puts(), fread(), fseek(), printf()
504 1.1 jtc /
505 1.1 jtc / GLOBAL INPUTS: Curmonster, *Monstfp
506 1.1 jtc /
507 1.1 jtc / GLOBAL OUTPUTS: none
508 1.1 jtc /
509 1.1 jtc / DESCRIPTION:
510 1.1 jtc / Read monster file, and print a monster listing on standard output.
511 1.1 jtc /
512 1.1 jtc /************************************************************************/
513 1.1 jtc
514 1.1 jtc monstlist()
515 1.1 jtc {
516 1.1 jtc register int count = 0; /* count in file */
517 1.1 jtc
518 1.1 jtc puts(" #) Name Str Brain Quick Energy Exper Treas Type Flock%\n");
519 1.1 jtc fseek(Monstfp, 0L, 0);
520 1.1 jtc while (fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp) == 1)
521 1.1 jtc printf("%2d) %-20.20s%4.0f %4.0f %2.0f %5.0f %5.0f %2d %2d %3.0f\n", count++,
522 1.1 jtc Curmonster.m_name, Curmonster.m_strength, Curmonster.m_brains,
523 1.1 jtc Curmonster.m_speed, Curmonster.m_energy, Curmonster.m_experience,
524 1.1 jtc Curmonster.m_treasuretype, Curmonster.m_type, Curmonster.m_flock);
525 1.1 jtc }
526 1.1 jtc /**/
528 1.1 jtc /************************************************************************
529 1.1 jtc /
530 1.1 jtc / FUNCTION NAME: scorelist()
531 1.1 jtc /
532 1.1 jtc / FUNCTION: print player score board
533 1.1 jtc /
534 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
535 1.1 jtc /
536 1.1 jtc / ARGUMENTS: none
537 1.1 jtc /
538 1.1 jtc / RETURN VALUE: none
539 1.1 jtc /
540 1.1 jtc / MODULES CALLED: fread(), fopen(), printf(), fclose()
541 1.1 jtc /
542 1.1 jtc / GLOBAL INPUTS:
543 1.1 jtc /
544 1.1 jtc / GLOBAL OUTPUTS: none
545 1.1 jtc /
546 1.1 jtc / DESCRIPTION:
547 1.1 jtc / Read the scoreboard file and print the contents.
548 1.1 jtc /
549 1.1 jtc /************************************************************************/
550 1.1 jtc
551 1.1 jtc scorelist()
552 1.1 jtc {
553 1.1 jtc struct scoreboard sbuf; /* for reading entries */
554 1.1 jtc register FILE *fp; /* to open the file */
555 1.1 jtc
556 1.1 jtc if ((fp = fopen(_PATH_SCORE, "r")) != NULL)
557 1.1 jtc {
558 1.1 jtc while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
559 1.1 jtc printf("%-20s (%-9s) Level: %6.0f Type: %s\n",
560 1.1 jtc sbuf.sb_name, sbuf.sb_login, sbuf.sb_level, sbuf.sb_type);
561 1.1 jtc fclose(fp);
562 1.1 jtc }
563 1.1 jtc }
564 1.1 jtc /**/
566 1.1 jtc /************************************************************************
567 1.1 jtc /
568 1.1 jtc / FUNCTION NAME: activelist()
569 1.1 jtc /
570 1.1 jtc / FUNCTION: print list of active players to standard output
571 1.1 jtc /
572 1.1 jtc / AUTHOR: E. A. Estes, 3/7/86
573 1.1 jtc /
574 1.1 jtc / ARGUMENTS: none
575 1.1 jtc /
576 1.1 jtc / RETURN VALUE: none
577 1.1 jtc /
578 1.1 jtc / MODULES CALLED: descrstatus(), fread(), fseek(), printf(), descrtype()
579 1.1 jtc /
580 1.1 jtc / GLOBAL INPUTS: Other, *Playersfp
581 1.1 jtc /
582 1.1 jtc / GLOBAL OUTPUTS: none
583 1.1 jtc /
584 1.1 jtc / DESCRIPTION:
585 1.1 jtc / Read player file, and print list of active records to standard output.
586 1.1 jtc /
587 1.1 jtc /************************************************************************/
588 1.1 jtc
589 1.1 jtc activelist()
590 1.1 jtc {
591 1.1 jtc fseek(Playersfp, 0L, 0);
592 1.1 jtc printf("Current characters on file are:\n\n");
593 1.1 jtc
594 1.1 jtc while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
595 1.1 jtc if (Other.p_status != S_NOTUSED)
596 1.1 jtc printf("%-20s (%-9s) Level: %6.0f %s (%s)\n",
597 1.1 jtc Other.p_name, Other.p_login, Other.p_level,
598 1.1 jtc descrtype(&Other, FALSE), descrstatus(&Other));
599 1.1 jtc
600 1.1 jtc }
601 1.1 jtc /**/
603 1.1 jtc /************************************************************************
604 1.1 jtc /
605 1.1 jtc / FUNCTION NAME: purgeoldplayers()
606 1.1 jtc /
607 1.1 jtc / FUNCTION: purge inactive players from player file
608 1.1 jtc /
609 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
610 1.1 jtc /
611 1.1 jtc / ARGUMENTS: none
612 1.1 jtc /
613 1.1 jtc / RETURN VALUE: none
614 1.1 jtc /
615 1.1 jtc / MODULES CALLED: freerecord(), time(), fread(), fseek(), localtime()
616 1.1 jtc /
617 1.1 jtc / GLOBAL INPUTS: Other, *Playersfp
618 1.1 jtc /
619 1.1 jtc / GLOBAL OUTPUTS: none
620 1.1 jtc /
621 1.1 jtc / DESCRIPTION:
622 1.1 jtc / Delete characters which have not been used with the last
623 1.1 jtc / three weeks.
624 1.1 jtc /
625 1.1 jtc /************************************************************************/
626 1.1 jtc
627 1.1 jtc purgeoldplayers()
628 1.1 jtc {
629 1.1 jtc int today; /* day of year for today */
630 1.1 jtc int daysold; /* how many days since the character has been used */
631 1.1 jtc long ltime; /* time in seconds */
632 1.1 jtc long loc = 0L; /* location in file */
633 1.1 jtc
634 1.1 jtc time(<ime);
635 1.1 jtc today = localtime(<ime)->tm_yday;
636 1.1 jtc
637 1.1 jtc for (;;)
638 1.1 jtc {
639 1.1 jtc fseek(Playersfp, loc, 0);
640 1.1 jtc if (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) != 1)
641 1.1 jtc break;
642 1.1 jtc
643 1.1 jtc daysold = today - Other.p_lastused;
644 1.1 jtc if (daysold < 0)
645 1.1 jtc daysold += 365;
646 1.1 jtc
647 1.1 jtc if (daysold > N_DAYSOLD)
648 1.1 jtc /* player hasn't been used in a while; delete */
649 1.1 jtc freerecord(&Other, loc);
650 1.1 jtc
651 1.1 jtc loc += SZ_PLAYERSTRUCT;
652 1.1 jtc }
653 1.1 jtc }
654 1.1 jtc /**/
656 1.1 jtc /************************************************************************
657 1.1 jtc /
658 1.1 jtc / FUNCTION NAME: enterscore()
659 1.1 jtc /
660 1.1 jtc / FUNCTION: enter player into scoreboard
661 1.1 jtc /
662 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
663 1.1 jtc /
664 1.1 jtc / ARGUMENTS: none
665 1.1 jtc /
666 1.1 jtc / RETURN VALUE: none
667 1.1 jtc /
668 1.1 jtc / MODULES CALLED: fread(), fseek(), fopen(), error(), strcmp(), fclose(),
669 1.1 jtc / strcpy(), fwrite(), descrtype()
670 1.1 jtc /
671 1.1 jtc / GLOBAL INPUTS: Player
672 1.1 jtc /
673 1.1 jtc / GLOBAL OUTPUTS: none
674 1.1 jtc /
675 1.1 jtc / DESCRIPTION:
676 1.1 jtc / The scoreboard keeps track of the highest character on a
677 1.1 jtc / per-login basis.
678 1.1 jtc / Search the scoreboard for an entry for the current login,
679 1.1 jtc / if an entry is found, and it is lower than the current player,
680 1.1 jtc / replace it, otherwise create an entry.
681 1.1 jtc /
682 1.1 jtc /************************************************************************/
683 1.1 jtc
684 1.1 jtc enterscore()
685 1.1 jtc {
686 1.1 jtc struct scoreboard sbuf; /* buffer to read in scoreboard entries */
687 1.1 jtc FILE *fp; /* to open scoreboard file */
688 1.1 jtc long loc = 0L; /* location in scoreboard file */
689 1.1 jtc bool found = FALSE; /* set if we found an entry for this login */
690 1.1 jtc
691 1.1 jtc if ((fp = fopen(_PATH_SCORE, "r+")) != NULL)
692 1.1 jtc {
693 1.1 jtc while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
694 1.1 jtc if (strcmp(Player.p_login, sbuf.sb_login) == 0)
695 1.1 jtc {
696 1.1 jtc found = TRUE;
697 1.1 jtc break;
698 1.1 jtc }
699 1.1 jtc else
700 1.1 jtc loc += SZ_SCORESTRUCT;
701 1.1 jtc }
702 1.1 jtc else
703 1.1 jtc {
704 1.1 jtc error(_PATH_SCORE);
705 1.1 jtc /*NOTREACHED*/
706 1.1 jtc }
707 1.1 jtc
708 1.1 jtc /*
709 1.1 jtc * At this point, 'loc' will either indicate a point beyond
710 1.1 jtc * the end of file, or the place where the previous entry
711 1.1 jtc * was found.
712 1.1 jtc */
713 1.1 jtc
714 1.1 jtc if ((!found) || Player.p_level > sbuf.sb_level)
715 1.1 jtc /* put new entry in for this login */
716 1.1 jtc {
717 1.1 jtc strcpy(sbuf.sb_login, Player.p_login);
718 1.1 jtc strcpy(sbuf.sb_name, Player.p_name);
719 1.1 jtc sbuf.sb_level = Player.p_level;
720 1.1 jtc strcpy(sbuf.sb_type, descrtype(&Player, TRUE));
721 1.1 jtc }
722 1.1 jtc
723 /* update entry */
724 fseek(fp, loc, 0);
725 fwrite((char *) &sbuf, SZ_SCORESTRUCT, 1, fp);
726 fclose(fp);
727 }
728