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