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