xref: /original-bsd/games/battlestar/com6.c (revision 77936e01)
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 the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 static char sccsid[] = "@(#)com6.c	5.4 (Berkeley) 05/07/90";
20 #endif /* not lint */
21 
22 #include "externs.h"
23 #include "pathnames.h"
24 
25 launch()
26 {
27 	if (testbit(location[position].objects,VIPER) && !notes[CANTLAUNCH]){
28 		if (fuel > 4){
29 			clearbit(location[position].objects,VIPER);
30 			position = location[position].up;
31 			notes[LAUNCHED] = 1;
32 			time++;
33 			fuel -= 4;
34 			puts("You climb into the viper and prepare for launch.");
35 			puts("With a touch of your thumb the turbo engines ignite, thrusting you back into\nyour seat.");
36 			return(1);
37 		}
38 		else
39 			puts("Not enough fuel to launch.");
40 	 }
41 	 else
42 		puts("Can't launch.");
43 	 return(0);
44 }
45 
46 land()
47 {
48 	if (notes[LAUNCHED] && testbit(location[position].objects,LAND) && location[position].down){
49 		notes[LAUNCHED] = 0;
50 		position = location[position].down;
51 		setbit(location[position].objects,VIPER);
52 		fuel -= 2;
53 		time++;
54 		puts("You are down.");
55 		return(1);
56 	}
57 	else
58 		puts("You can't land here.");
59 	return(0);
60 }
61 
62 die() 		/* endgame */
63 {
64 	printf("bye.\nYour rating was %s.\n", rate());
65 	post(' ');
66 	exit(0);
67 }
68 
69 live()
70 {
71 	puts("\nYou win!");
72 	post('!');
73 	exit(0);
74 }
75 
76 /*
77  * sigh -- this program thinks "time" is an int.  It's easier to not load
78  * <time.h> than try and fix it.
79  */
80 #define KERNEL
81 #include <sys/time.h>
82 #undef KERNEL
83 
84 post(ch)
85 char ch;
86 {
87 	FILE *fp;
88 	struct timeval tv;
89 	char *date, *ctime();
90 	int s = sigblock(sigmask(SIGINT));
91 
92 	gettimeofday(&tv, (struct timezone *)0);	/* can't call time */
93 	date = ctime(&tv.tv_sec);
94 	date[24] = '\0';
95 	if (fp = fopen(_PATH_SCORE,"a")) {
96 		fprintf(fp, "%s  %8s  %c%20s", date, uname, ch, rate());
97 		if (wiz)
98 			fprintf(fp, "   wizard\n");
99 		else if (tempwiz)
100 			fprintf(fp, "   WIZARD!\n");
101 		else
102 			fprintf(fp, "\n");
103 	} else
104 		perror(_PATH_SCORE);
105 	sigsetmask(s);
106 }
107 
108 char *
109 rate()
110 {
111 	int score;
112 
113 	score = max(max(pleasure,power),ego);
114 	if (score == pleasure){
115 		if (score < 5)
116 			return("novice");
117 		else if (score < 20)
118 			return("junior voyeur");
119 		else if (score < 35)
120 			return("Don Juan");
121 		else return("Marquis De Sade");
122 	}
123 	else if (score == power){
124 		if (score < 5)
125 			return("serf");
126 		else if (score < 8)
127 			return("Samurai");
128 		else if (score < 13)
129 			return("Klingon");
130 		else if (score < 22)
131 			return("Darth Vader");
132 		else return("Sauron the Great");
133 	}
134 	else{
135 		if (score < 5)
136 			return("Polyanna");
137 		else if (score < 10)
138 			return("philanthropist");
139 		else if (score < 20)
140 			return("Tattoo");
141 		else return("Mr. Roarke");
142 	}
143 }
144 
145 drive()
146 {
147 	if (testbit(location[position].objects,CAR)){
148 		puts("You hop in the car and turn the key.  There is a perceptible grating noise,");
149 		puts("and an explosion knocks you unconscious...");
150 		clearbit(location[position].objects,CAR);
151 		setbit(location[position].objects,CRASH);
152 		injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
153 		time += 15;
154 		zzz();
155 		return(0);
156 	}
157 	else
158 		puts("There is nothing to drive here.");
159 	return(-1);
160 }
161 
162 ride()
163 {
164 	if (testbit(location[position].objects,HORSE)){
165 		puts("You climb onto the stallion and kick it in the guts.  The stupid steed launches");
166 		puts("forward through bush and fern.  You are thrown and the horse gallups off.");
167 		clearbit(location[position].objects,HORSE);
168 		while (!(position = rnd(NUMOFROOMS+1)) || !OUTSIDE || !beenthere[position] || location[position].flyhere);
169 		setbit(location[position].objects,HORSE);
170 		if (location[position].north)
171 			position = location[position].north;
172 		else if (location[position].south)
173 			position = location[position].south;
174 		else if (location[position].east)
175 			position = location[position].east;
176 		else
177 			position = location[position].west;
178 		return(0);
179 	}
180 	else puts("There is no horse here.");
181 	return(-1);
182 }
183 
184 light()		/* synonyms = {strike, smoke} */
185 {		/* for matches, cigars */
186 	if (testbit(inven,MATCHES) && matchcount){
187 		puts("Your match splutters to life.");
188 		time++;
189 		matchlight = 1;
190 		matchcount--;
191 		if (position == 217){
192 			puts("The whole bungalow explodes with an intense blast.");
193 			die();
194 		}
195 	}
196 	else puts("You're out of matches.");
197 }
198