]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - battlestar/command2.c
off-by-one. aaron@openbsd
[bsdgames-darwin.git] / battlestar / command2.c
1 /* $NetBSD: command2.c,v 1.2 2003/08/07 09:37:00 agc 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 #ifndef lint
34 #if 0
35 static char sccsid[] = "@(#)com2.c 8.2 (Berkeley) 4/28/95";
36 #else
37 __RCSID("$NetBSD: command2.c,v 1.2 2003/08/07 09:37:00 agc Exp $");
38 #endif
39 #endif /* not lint */
40
41 #include "extern.h"
42
43 int
44 wearit()
45 { /* synonyms = {sheathe, sheath} */
46 int firstnumber, value;
47
48 firstnumber = wordnumber;
49 wordnumber++;
50 while (wordnumber <= wordcount && (wordtype[wordnumber] == OBJECT ||
51 wordtype[wordnumber] == NOUNS) && wordvalue[wordnumber] != DOOR) {
52 value = wordvalue[wordnumber];
53 if (value >= 0 && objsht[value] == NULL)
54 break;
55 switch (value) {
56
57 case -1:
58 puts("Wear what?");
59 return (firstnumber);
60
61 default:
62 printf("You can't wear %s%s!\n",
63 A_OR_AN_OR_BLANK(value), objsht[value]);
64 return (firstnumber);
65
66 case KNIFE:
67 /* case SHIRT: */
68 case ROBE:
69 case LEVIS: /* wearable things */
70 case SWORD:
71 case MAIL:
72 case HELM:
73 case SHOES:
74 case PAJAMAS:
75 case COMPASS:
76 case LASER:
77 case AMULET:
78 case TALISMAN:
79 case MEDALION:
80 case ROPE:
81 case RING:
82 case BRACELET:
83 case GRENADE:
84
85 if (testbit(inven, value)) {
86 clearbit(inven, value);
87 setbit(wear, value);
88 carrying -= objwt[value];
89 encumber -= objcumber[value];
90 ourtime++;
91 printf("You are now wearing %s%s.\n",
92 A_OR_AN_OR_THE(value), objsht[value]);
93 } else
94 if (testbit(wear, value))
95 printf("You are already wearing the %s.\n",
96 objsht[value]);
97 else
98 printf("You aren't holding the %s.\n",
99 objsht[value]);
100 if (wordnumber < wordcount - 1 &&
101 wordvalue[++wordnumber] == AND)
102 wordnumber++;
103 else
104 return (firstnumber);
105 } /* end switch */
106 } /* end while */
107 puts("Don't be ridiculous.");
108 return (firstnumber);
109 }
110
111 int
112 put()
113 { /* synonyms = {buckle, strap, tie} */
114 if (wordvalue[wordnumber + 1] == ON) {
115 wordvalue[++wordnumber] = PUTON;
116 wordtype[wordnumber] = VERB;
117 return (cypher());
118 }
119 if (wordvalue[wordnumber + 1] == DOWN) {
120 wordvalue[++wordnumber] = DROP;
121 wordtype[wordnumber] = VERB;
122 return (cypher());
123 }
124 puts("I don't understand what you want to put.");
125 return (-1);
126
127 }
128
129 int
130 draw()
131 { /* synonyms = {pull, carry} */
132 return (take(wear));
133 }
134
135 int
136 use()
137 {
138 wordnumber++;
139 if (wordvalue[wordnumber] == AMULET && testbit(inven, AMULET) &&
140 position != FINAL) {
141 puts("The amulet begins to glow.");
142 if (testbit(inven, MEDALION)) {
143 puts("The medallion comes to life too.");
144 if (position == 114) {
145 location[position].down = 160;
146 whichway(location[position]);
147 puts("The waves subside and it is possible to descend to the sea cave now.");
148 ourtime++;
149 return (-1);
150 }
151 }
152 puts("A light mist falls over your eyes and the sound of purling water trickles in");
153 puts("your ears. When the mist lifts you are standing beside a cool stream.");
154 if (position == 229)
155 position = 224;
156 else
157 position = 229;
158 ourtime++;
159 notes[CANTSEE] = 0;
160 return (0);
161 } else if (position == FINAL)
162 puts("The amulet won't work in here.");
163 else if (wordvalue[wordnumber] == COMPASS && testbit(inven, COMPASS))
164 printf("Your compass points %s.\n", truedirec(NORTH, '-'));
165 else if (wordvalue[wordnumber] == COMPASS)
166 puts("You aren't holding the compass.");
167 else if (wordvalue[wordnumber] == AMULET)
168 puts("You aren't holding the amulet.");
169 else
170 puts("There is no apparent use.");
171 return (-1);
172 }
173
174 void
175 murder()
176 {
177 int n;
178
179 for (n = 0; !((n == SWORD || n == KNIFE || n == TWO_HANDED || n == MACE || n == CLEAVER || n == BROAD || n == CHAIN || n == SHOVEL || n == HALBERD) && testbit(inven, n)) && n < NUMOFOBJECTS; n++);
180 if (n == NUMOFOBJECTS) {
181 if (testbit(inven, LASER)) {
182 printf("Your laser should do the trick.\n");
183 wordnumber++;
184 switch(wordvalue[wordnumber]) {
185 case NORMGOD:
186 case TIMER:
187 case NATIVE:
188 case MAN:
189 wordvalue[--wordnumber] = SHOOT;
190 cypher();
191 break;
192 case -1:
193 puts("Kill what?");
194 break;
195 default:
196 if (wordtype[wordnumber] != OBJECT ||
197 wordvalue[wordnumber] == EVERYTHING)
198 puts("You can't kill that!");
199 else
200 printf("You can't kill %s%s!\n",
201 A_OR_AN_OR_BLANK(wordvalue[wordnumber]),
202 objsht[wordvalue[wordnumber]]);
203 break;
204 }
205 } else
206 puts("You don't have suitable weapons to kill.");
207 } else {
208 printf("Your %s should do the trick.\n", objsht[n]);
209 wordnumber++;
210 switch (wordvalue[wordnumber]) {
211
212 case NORMGOD:
213 if (testbit(location[position].objects, BATHGOD)) {
214 puts("The goddess's head slices off. Her corpse floats in the water.");
215 clearbit(location[position].objects, BATHGOD);
216 setbit(location[position].objects, DEADGOD);
217 power += 5;
218 notes[JINXED]++;
219 } else
220 if (testbit(location[position].objects, NORMGOD)) {
221 puts("The goddess pleads but you strike her mercilessly. Her broken body lies in a\npool of blood.");
222 clearbit(location[position].objects, NORMGOD);
223 setbit(location[position].objects, DEADGOD);
224 power += 5;
225 notes[JINXED]++;
226 if (wintime)
227 live();
228 } else
229 puts("I don't see her anywhere.");
230 break;
231 case TIMER:
232 if (testbit(location[position].objects, TIMER)) {
233 puts("The old man offers no resistance.");
234 clearbit(location[position].objects, TIMER);
235 setbit(location[position].objects, DEADTIME);
236 power++;
237 notes[JINXED]++;
238 } else
239 puts("Who?");
240 break;
241 case NATIVE:
242 if (testbit(location[position].objects, NATIVE)) {
243 puts("The girl screams as you cut her body to shreds. She is dead.");
244 clearbit(location[position].objects, NATIVE);
245 setbit(location[position].objects, DEADNATIVE);
246 power += 5;
247 notes[JINXED]++;
248 } else
249 puts("What girl?");
250 break;
251 case MAN:
252 if (testbit(location[position].objects, MAN)) {
253 puts("You strike him to the ground, and he coughs up blood.");
254 puts("Your fantasy is over.");
255 die();
256 }
257 case -1:
258 puts("Kill what?");
259 break;
260
261 default:
262 if (wordtype[wordnumber] != OBJECT ||
263 wordvalue[wordnumber] == EVERYTHING)
264 puts("You can't kill that!");
265 else
266 printf("You can't kill the %s!\n",
267 objsht[wordvalue[wordnumber]]);
268 }
269 }
270 }
271
272 void
273 ravage()
274 {
275 while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount)
276 continue;
277 if (wordtype[wordnumber] == NOUNS && (testbit(location[position].objects, wordvalue[wordnumber])
278 || (wordvalue[wordnumber] == NORMGOD && testbit(location[position].objects, BATHGOD)))) {
279 ourtime++;
280 switch (wordvalue[wordnumber]) {
281 case NORMGOD:
282 puts("You attack the goddess, and she screams as you beat her. She falls down");
283 if (testbit(location[position].objects, BATHGOD))
284 puts("crying and tries to cover her nakedness.");
285 else
286 puts("crying and tries to hold her torn and bloodied dress around her.");
287 power += 5;
288 pleasure += 8;
289 ego -= 10;
290 wordnumber--;
291 godready = -30000;
292 murder();
293 win = -30000;
294 break;
295 case NATIVE:
296 puts("The girl tries to run, but you catch her and throw her down. Her face is");
297 puts("bleeding, and she screams as you tear off her clothes.");
298 power += 3;
299 pleasure += 5;
300 ego -= 10;
301 wordnumber--;
302 murder();
303 if (rnd(100) < 50) {
304 puts("Her screams have attracted attention. I think we are surrounded.");
305 setbit(location[ahead].objects, WOODSMAN);
306 setbit(location[ahead].objects, DEADWOOD);
307 setbit(location[ahead].objects, MALLET);
308 setbit(location[back].objects, WOODSMAN);
309 setbit(location[back].objects, DEADWOOD);
310 setbit(location[back].objects, MALLET);
311 setbit(location[left].objects, WOODSMAN);
312 setbit(location[left].objects, DEADWOOD);
313 setbit(location[left].objects, MALLET);
314 setbit(location[right].objects, WOODSMAN);
315 setbit(location[right].objects, DEADWOOD);
316 setbit(location[right].objects, MALLET);
317 }
318 break;
319 default:
320 puts("You are perverted.");
321 }
322 } else
323 puts("Who?");
324 }
325
326 int
327 follow()
328 {
329 if (followfight == ourtime) {
330 puts("The Dark Lord leaps away and runs down secret tunnels and corridors.");
331 puts("You chase him through the darkness and splash in pools of water.");
332 puts("You have cornered him. His laser sword extends as he steps forward.");
333 position = FINAL;
334 fight(DARK, 75);
335 setbit(location[position].objects, TALISMAN);
336 setbit(location[position].objects, AMULET);
337 return (0);
338 } else
339 if (followgod == ourtime) {
340 puts("The goddess leads you down a steamy tunnel and into a high, wide chamber.");
341 puts("She sits down on a throne.");
342 position = 268;
343 setbit(location[position].objects, NORMGOD);
344 notes[CANTSEE] = 1;
345 return (0);
346 } else
347 puts("There is no one to follow.");
348 return (-1);
349 }