1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 static char sccsid[] = "@(#)init.c 5.1 (Berkeley) 05/08/88"; 15 #endif /* not lint */ 16 17 #include "externs.h" 18 #include <pwd.h> 19 20 initialize(startup) 21 char startup; 22 { 23 register struct objs *p; 24 int die(); 25 26 puts("Version 4.2, fall 1984."); 27 puts("First Adventure game written by His Lordship, the honorable"); 28 puts("Admiral D.W. Riggle\n"); 29 srand(getpid()); 30 getutmp(uname); 31 wiz = wizard(uname); 32 wordinit(); 33 if (startup) { 34 location = dayfile; 35 direction = NORTH; 36 time = 0; 37 snooze = CYCLE * 1.5; 38 position = 22; 39 setbit(wear, PAJAMAS); 40 fuel = TANKFULL; 41 torps = TORPEDOES; 42 for (p = dayobjs; p->room != 0; p++) 43 setbit(location[p->room].objects, p->obj); 44 } else 45 restore(); 46 signal(SIGINT, die); 47 } 48 49 getutmp(uname) 50 char *uname; 51 { 52 struct passwd *ptr; 53 54 ptr = getpwuid(getuid()); 55 strcpy(uname, ptr ? ptr->pw_name : ""); 56 } 57 58 char *list[] = { /* hereditary wizards */ 59 "riggle", 60 "chris", 61 "edward", 62 "comay", 63 "yee", 64 "dmr", 65 "ken", 66 0 67 }; 68 69 char *badguys[] = { 70 "wnj", 71 "root", 72 "ted", 73 0 74 }; 75 76 wizard(uname) 77 char *uname; 78 { 79 char flag; 80 81 if (flag = checkout(uname)) 82 printf("You are the Great wizard %s.\n", uname); 83 return flag; 84 } 85 86 checkout(uname) 87 register char *uname; 88 { 89 register char **ptr; 90 91 for (ptr = list; *ptr; ptr++) 92 if (strcmp(*ptr, uname) == 0) 93 return 1; 94 for (ptr = badguys; *ptr; ptr++) 95 if (strcmp(*ptr, uname) == 0) { 96 printf("You are the Poor anti-wizard %s. Good Luck!\n", 97 uname); 98 CUMBER = 3; 99 WEIGHT = 9; /* that'll get him! */ 100 clock = 10; 101 setbit(location[7].objects, WOODSMAN); /* viper room */ 102 setbit(location[20].objects, WOODSMAN); /* laser " */ 103 setbit(location[13].objects, DARK); /* amulet " */ 104 setbit(location[8].objects, ELF); /* closet */ 105 return 0; /* anything else, Chris? */ 106 } 107 return 0; 108 } 109