Fix a bug in close(). When a descriptor is closed, all process leaders
[dragonfly.git] / games / battlestar / com6.c
blobc880d3406000f5fd6c7b013f8e8d83459e7b28bb
1 /*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
33 * @(#)com6.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/battlestar/com6.c,v 1.9.2.1 2001/03/05 11:45:35 kris Exp $
35 * $DragonFly: src/games/battlestar/com6.c,v 1.3 2003/11/12 14:53:52 eirikn Exp $
38 #include <signal.h>
39 #include "externs.h"
40 #include "pathnames.h"
42 static void post (unsigned int ch);
44 int
45 launch()
47 if (testbit(location[position].objects,VIPER) && !notes[CANTLAUNCH]){
48 if (fuel > 4){
49 clearbit(location[position].objects,VIPER);
50 position = location[position].up;
51 notes[LAUNCHED] = 1;
52 gtime++;
53 fuel -= 4;
54 puts("You climb into the viper and prepare for launch.");
55 puts("With a touch of your thumb the turbo engines ignite, thrusting you back into\nyour seat.");
56 return(1);
58 else
59 puts("Not enough fuel to launch.");
61 else
62 puts("Can't launch.");
63 return(0);
66 int
67 land()
69 if (notes[LAUNCHED] && testbit(location[position].objects,LAND) && location[position].down){
70 notes[LAUNCHED] = 0;
71 position = location[position].down;
72 setbit(location[position].objects,VIPER);
73 fuel -= 2;
74 gtime++;
75 puts("You are down.");
76 return(1);
78 else
79 puts("You can't land here.");
80 return(0);
83 void
84 die(sig) /* endgame */
85 int sig;
87 sig = 0;
88 printf("bye.\nYour rating was %s.\n", rate());
89 post(' ');
90 exit(0);
93 void
94 live()
96 puts("\nYou win!");
97 post('!');
98 exit(0);
101 #include <sys/time.h>
103 static FILE *score_fp;
105 void
106 open_score_file()
108 if ((score_fp = fopen(_PATH_SCORE,"a")) == NULL)
109 perror(_PATH_SCORE);
112 static void
113 post(ch)
114 unsigned int ch;
116 struct timeval tv;
117 char *date;
118 time_t tvsec;
119 int s;
121 if (score_fp == NULL)
122 return;
124 s = sigblock(sigmask(SIGINT));
126 gettimeofday(&tv, (struct timezone *)0); /* can't call time */
127 tvsec = (time_t) tv.tv_sec;
128 date = ctime(&tvsec);
129 date[24] = '\0';
131 fprintf(score_fp, "%s %8s %c%20s", date, uname, ch, rate());
132 if (wiz)
133 fprintf(score_fp, " wizard\n");
134 else if (tempwiz)
135 fprintf(score_fp, " WIZARD!\n");
136 else
137 fprintf(score_fp, "\n");
139 sigsetmask(s);
142 const char *
143 rate()
145 int score;
147 score = max(max(pleasure,power),ego);
148 if (score == pleasure){
149 if (score < 5)
150 return("novice");
151 else if (score < 20)
152 return("junior voyeur");
153 else if (score < 35)
154 return("Don Juan");
155 else return("Marquis De Sade");
157 else if (score == power){
158 if (score < 5)
159 return("serf");
160 else if (score < 8)
161 return("Samurai");
162 else if (score < 13)
163 return("Klingon");
164 else if (score < 22)
165 return("Darth Vader");
166 else return("Sauron the Great");
168 else{
169 if (score < 5)
170 return("Polyanna");
171 else if (score < 10)
172 return("philanthropist");
173 else if (score < 20)
174 return("Tattoo");
175 else return("Mr. Roarke");
180 drive()
182 if (testbit(location[position].objects,CAR)){
183 puts("You hop in the car and turn the key. There is a perceptible grating noise,");
184 puts("and an explosion knocks you unconscious...");
185 clearbit(location[position].objects,CAR);
186 setbit(location[position].objects,CRASH);
187 injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
188 gtime += 15;
189 zzz();
190 return(0);
192 else
193 puts("There is nothing to drive here.");
194 return(-1);
198 ride()
200 if (testbit(location[position].objects,HORSE)){
201 puts("You climb onto the stallion and kick it in the guts. The stupid steed launches");
202 puts("forward through bush and fern. You are thrown and the horse gallups off.");
203 clearbit(location[position].objects,HORSE);
204 while (!(position = rnd(NUMOFROOMS+1)) || !OUTSIDE || !beenthere[position] || location[position].flyhere);
205 setbit(location[position].objects,HORSE);
206 if (location[position].north)
207 position = location[position].north;
208 else if (location[position].south)
209 position = location[position].south;
210 else if (location[position].east)
211 position = location[position].east;
212 else
213 position = location[position].west;
214 return(0);
216 else puts("There is no horse here.");
217 return(-1);
220 void
221 light() /* synonyms = {strike, smoke} */
222 { /* for matches, cigars */
223 if (testbit(inven,MATCHES) && matchcount){
224 puts("Your match splutters to life.");
225 gtime++;
226 matchlight = 1;
227 matchcount--;
228 if (position == 217){
229 puts("The whole bungalow explodes with an intense blast.");
230 die(0);
233 else puts("You're out of matches.");