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