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