xref: /netbsd/games/battlestar/command6.c (revision bf9ec67e)
1 /*	$NetBSD: command6.c,v 1.1 2001/10/19 03:06:11 tv Exp $	*/
2 
3 /*
4  * Copyright (c) 1983, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)com6.c	8.2 (Berkeley) 4/28/95";
40 #else
41 __RCSID("$NetBSD: command6.c,v 1.1 2001/10/19 03:06:11 tv Exp $");
42 #endif
43 #endif				/* not lint */
44 
45 #include "extern.h"
46 #include "pathnames.h"
47 
48 int
49 launch()
50 {
51 	if (testbit(location[position].objects, VIPER) && !notes[CANTLAUNCH]) {
52 		if (fuel > 4) {
53 			clearbit(location[position].objects, VIPER);
54 			position = location[position].up;
55 			notes[LAUNCHED] = 1;
56 			ourtime++;
57 			fuel -= 4;
58 			puts("You climb into the viper and prepare for launch.");
59 			puts("With a touch of your thumb the turbo engines ignite, thrusting you back into\nyour seat.");
60 			return (1);
61 		} else
62 			puts("Not enough fuel to launch.");
63 	} else
64 		puts("Can't launch.");
65 	return (0);
66 }
67 
68 int
69 land()
70 {
71 	if (notes[LAUNCHED] && testbit(location[position].objects, LAND) &&
72 	    location[position].down) {
73 		notes[LAUNCHED] = 0;
74 		position = location[position].down;
75 		setbit(location[position].objects, VIPER);
76 		fuel -= 2;
77 		ourtime++;
78 		puts("You are down.");
79 		return (1);
80 	} else
81 		puts("You can't land here.");
82 	return (0);
83 }
84 
85 void
86 die()
87 {				/* endgame */
88 	printf("bye.\nYour rating was %s.\n", rate());
89 	post(' ');
90 	exit(0);
91 }
92 
93 void
94 diesig(dummy)
95 	int     dummy __attribute__((__unused__));
96 {
97 	die();
98 }
99 
100 void
101 live()
102 {
103 	puts("\nYou win!");
104 	post('!');
105 	exit(0);
106 }
107 
108 static FILE *score_fp;
109 
110 void
111 open_score_file()
112 {
113 	score_fp = fopen(_PATH_SCORE, "a");
114 	if (score_fp == NULL)
115 		warn("open %s for append", _PATH_SCORE);
116 	if (score_fp != NULL && fileno(score_fp) < 3)
117 		exit(1);
118 }
119 
120 void
121 post(ch)
122 	char    ch;
123 {
124 	time_t tv;
125 	char   *date;
126 	sigset_t sigset, osigset;
127 
128 	sigemptyset(&sigset);
129 	sigaddset(&sigset, SIGINT);
130 	sigprocmask(SIG_BLOCK, &sigset, &osigset);
131 	tv = time(NULL);
132 	date = ctime(&tv);
133 	date[24] = '\0';
134 	if (score_fp != NULL) {
135 		fprintf(score_fp, "%s  %8s  %c%20s", date, username, ch, rate());
136 		if (wiz)
137 			fprintf(score_fp, "   wizard\n");
138 		else
139 			if (tempwiz)
140 				fprintf(score_fp, "   WIZARD!\n");
141 			else
142 				fprintf(score_fp, "\n");
143 	}
144 	sigprocmask(SIG_SETMASK, &osigset, (sigset_t *) 0);
145 }
146 
147 const char   *
148 rate()
149 {
150 	int     score;
151 
152 	score = max(max(pleasure, power), ego);
153 	if (score == pleasure) {
154 		if (score < 5)
155 			return ("novice");
156 		else if (score < 20)
157 			return ("junior voyeur");
158 		else if (score < 35)
159 			return ("Don Juan");
160 		else
161 			return ("Marquis De Sade");
162 	} else if (score == power) {
163 		if (score < 5)
164 			return ("serf");
165 		else if (score < 8)
166 			return ("Samurai");
167 		else if (score < 13)
168 			return ("Klingon");
169 		else if (score < 22)
170 			return ("Darth Vader");
171 		else
172 			return ("Sauron the Great");
173 	} else {
174 		if (score < 5)
175 			return ("Polyanna");
176 		else if (score < 10)
177 			return ("philanthropist");
178 		else if (score < 20)
179 			return ("Tattoo");
180 		else
181 			return ("Mr. Roarke");
182 	}
183 }
184 
185 int
186 drive()
187 {
188 	if (testbit(location[position].objects, CAR)) {
189 		puts("You hop in the car and turn the key.  There is a perceptible grating noise,");
190 		puts("and an explosion knocks you unconscious...");
191 		clearbit(location[position].objects, CAR);
192 		setbit(location[position].objects, CRASH);
193 		injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
194 		ourtime += 15;
195 		zzz();
196 		return (0);
197 	} else
198 		puts("There is nothing to drive here.");
199 	return (-1);
200 }
201 
202 int
203 ride()
204 {
205 	if (testbit(location[position].objects, HORSE)) {
206 		puts("You climb onto the stallion and kick it in the guts.  The stupid steed launches");
207 		puts("forward through bush and fern.  You are thrown and the horse gallops off.");
208 		clearbit(location[position].objects, HORSE);
209 		while (!(position = rnd(NUMOFROOMS + 1)) || !OUTSIDE || !beenthere[position] || location[position].flyhere)
210 			continue;
211 		setbit(location[position].objects, HORSE);
212 		if (location[position].north)
213 			position = location[position].north;
214 		else if (location[position].south)
215 			position = location[position].south;
216 		else if (location[position].east)
217 			position = location[position].east;
218 		else
219 			position = location[position].west;
220 		return (0);
221 	} else
222 		puts("There is no horse here.");
223 	return (-1);
224 }
225 
226 void
227 light()
228 {				/* synonyms = {strike, smoke} *//* for
229 				 * matches, cigars */
230 	if (testbit(inven, MATCHES) && matchcount) {
231 		puts("Your match splutters to life.");
232 		ourtime++;
233 		matchlight = 1;
234 		matchcount--;
235 		if (position == 217) {
236 			puts("The whole bungalow explodes with an intense blast.");
237 			die();
238 		}
239 	} else
240 		puts("You're out of matches.");
241 }
242 
243 void
244 dooropen()
245 {				/* synonyms = {open, unlock} */
246 	wordnumber++;
247 	if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS
248 	    && wordvalue[wordnumber] == DOOR) {
249 		switch(position) {
250 		case 189:
251 		case 231:
252 			if (location[189].north == 231)
253 				puts("The door is already open.");
254 			else
255 				puts("The door does not budge.");
256 			break;
257 		case 30:
258 			if (location[30].west == 25)
259 				puts("The door is gone.");
260 			else
261 				puts("The door is locked tight.");
262 			break;
263 		case 31:
264 			puts("That's one immovable door.");
265 			break;
266 		case 20:
267 			puts("The door is already ajar.");
268 			break;
269 		default:
270 			puts("What door?");
271 		}
272 	} else
273 		puts("That doesn't open.");
274 }
275