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