1 /* $NetBSD: command4.c,v 1.2 2003/08/07 09:37:00 agc Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)com4.c 8.2 (Berkeley) 4/28/95";
37 __RCSID("$NetBSD: command4.c,v 1.2 2003/08/07 09:37:00 agc Exp $");
44 take(unsigned int from
[])
46 int firstnumber
, heavy
, bulky
, value
;
48 firstnumber
= wordnumber
;
49 if (wordnumber
< wordcount
&& wordvalue
[wordnumber
+ 1] == OFF
) {
51 wordvalue
[wordnumber
] = TAKEOFF
;
52 wordtype
[wordnumber
] = VERB
;
56 while (wordnumber
<= wordcount
&& wordtype
[wordnumber
] ==
58 value
= wordvalue
[wordnumber
];
59 printf("%s:\n", objsht
[value
]);
60 heavy
= (carrying
+ objwt
[value
]) <= WEIGHT
;
61 bulky
= (encumber
+ objcumber
[value
]) <= CUMBER
;
62 if ((testbit(from
, value
) || wiz
|| tempwiz
) &&
63 heavy
&& bulky
&& !testbit(inven
, value
)) {
65 carrying
+= objwt
[value
];
66 encumber
+= objcumber
[value
];
68 if (testbit(from
, value
))
71 printf("Zap! Taken from thin air.\n");
72 clearbit(from
, value
);
73 if (value
== MEDALION
)
75 } else if (testbit(inven
, value
))
76 printf("You're already holding %s%s.\n",
77 A_OR_AN_OR_BLANK(value
),
79 else if (!testbit(from
, value
))
80 printf("I don't see any %s around here.\n",
83 printf("The %s %stoo heavy.\n", objsht
[value
],
86 printf("The %s %stoo cumbersome to hold.\n",
87 objsht
[value
], IS_OR_ARE(value
));
88 if (wordnumber
< wordcount
- 1 &&
89 wordvalue
[++wordnumber
] == AND
)
95 /* special cases with their own return()'s */
97 if (wordnumber
<= wordcount
&& wordtype
[wordnumber
] == NOUNS
)
98 switch (wordvalue
[wordnumber
]) {
101 if (testbit(from
, SWORD
)) {
102 wordtype
[wordnumber
--] = OBJECT
;
105 if (testbit(from
, TWO_HANDED
)) {
106 wordvalue
[wordnumber
] = TWO_HANDED
;
107 wordtype
[wordnumber
--] = OBJECT
;
110 wordvalue
[wordnumber
] = BROAD
;
111 wordtype
[wordnumber
--] = OBJECT
;
115 if (testbit(from
, MAID
)) {
116 wordvalue
[wordnumber
] = MAID
;
117 wordtype
[wordnumber
--] = OBJECT
;
119 } else if (testbit(from
, DEADWOOD
)) {
120 wordvalue
[wordnumber
] = DEADWOOD
;
121 wordtype
[wordnumber
--] = OBJECT
;
123 } else if (testbit(from
, DEADNATIVE
)) {
124 wordvalue
[wordnumber
] = DEADNATIVE
;
125 wordtype
[wordnumber
--] = OBJECT
;
128 if (testbit(from
, DEADGOD
)) {
129 wordvalue
[wordnumber
] = DEADGOD
;
130 wordtype
[wordnumber
--] = OBJECT
;
133 wordvalue
[wordnumber
] = DEADTIME
;
134 wordtype
[wordnumber
--] = OBJECT
;
141 if (testbit(location
[position
].objects
, AMULET
)) {
142 printf("The amulet is warm to the touch, and ");
143 puts("its beauty catches your breath.");
144 printf("A mist falls over your eyes, but ");
145 puts("then it is gone. Sounds seem clearer");
146 printf("and sharper but far away as if in a ");
147 puts("dream. The sound of purling water");
148 printf("reaches you from afar. The mist ");
149 printf("falls again, and your heart leaps in ");
151 printf("The gold freezes your hands and ");
152 puts("fathomless darkness engulfs your soul.");
154 wordtype
[wordnumber
--] = OBJECT
;
158 if (testbit(location
[position
].objects
, MEDALION
)) {
159 printf("The medallion is warm, and it ");
160 printf("rekindles your spirit with the ");
161 puts("warmth of life.");
162 printf("Your amulet begins to glow as the ");
163 printf("medallion is brought near to it, ");
164 printf("and together\nthey radiate.\n");
166 wordtype
[wordnumber
--] = OBJECT
;
170 if (testbit(location
[position
].objects
, TALISMAN
)) {
171 printf("The talisman is cold to the touch, ");
172 puts("and it sends a chill down your spine.");
174 wordtype
[wordnumber
--] = OBJECT
;
178 if (testbit(location
[position
].objects
, BATHGOD
) &&
179 (testbit(wear
, AMULET
) || testbit(inven
, AMULET
))) {
180 printf("She offers a delicate hand, and you ");
181 puts("help her out of the sparkling springs.");
182 printf("Water droplets like liquid silver ");
183 printf("bedew her golden skin, but when ");
185 printf("from her, they fall as teardrops. ");
186 puts("She wraps a single cloth around her and");
187 printf("ties it at the waist. Around her ");
188 puts("neck hangs a golden amulet.");
189 printf("She bids you to follow her, and ");
193 clearbit(location
[position
].objects
, BATHGOD
);
195 if (!testbit(location
[position
].objects
,
197 printf("You're in no position to ");
200 puts("She moves away from you.");
204 puts("It doesn't seem to work.");
207 puts("You've got to be kidding.");
208 return (firstnumber
);
212 throw(const char *name
)
219 if (drop(name
) != -1) {
220 switch (wordvalue
[wordnumber
]) {
239 deposit
= location
[position
].up
*
240 (location
[position
].access
|| position
== FINAL
);
244 deposit
= location
[position
].down
;
247 wordnumber
= first
+ 1;
248 while (wordnumber
<= wordcount
) {
249 value
= wordvalue
[wordnumber
];
251 testbit(location
[position
].objects
, value
)) {
252 clearbit(location
[position
].objects
, value
);
253 if (value
!= GRENADE
)
254 setbit(location
[deposit
].objects
,
257 printf("A thundering explosion ");
258 printf("nearby sends up a cloud of ");
259 puts("smoke and shrapnel.");
260 for (n
= 0; n
< NUMOFWORDS
; n
++)
261 location
[deposit
].objects
[n
] =
263 setbit(location
[deposit
].objects
, CHAR
);
265 if (value
== ROPE
&& position
== FINAL
)
266 location
[position
].access
= 1;
270 puts("The stone door is unhinged.");
271 location
[189].north
= 231;
272 location
[231].south
= 189;
275 puts("The wooden door is blown open.");
276 location
[30].west
= 25;
279 puts("The door is not damaged.");
282 if (value
== GRENADE
&&
283 testbit(location
[position
].objects
,
285 printf("You are blown into shreds ");
286 puts("when your grenade explodes.");
289 if (wordnumber
< wordcount
- 1 &&
290 wordvalue
[++wordnumber
] == AND
)
301 drop(const char *name
)
304 int firstnumber
, value
;
306 firstnumber
= wordnumber
;
308 while (wordnumber
<= wordcount
&&
309 (wordtype
[wordnumber
] == OBJECT
|| wordtype
[wordnumber
] == NOUNS
)) {
310 value
= wordvalue
[wordnumber
];
311 if (value
== BODY
) { /* special case */
312 wordtype
[wordnumber
] = OBJECT
;
313 if (testbit(inven
, MAID
) ||
314 testbit(location
[position
].objects
, MAID
))
316 else if (testbit(inven
, DEADWOOD
) ||
317 testbit(location
[position
].objects
, DEADWOOD
))
319 else if (testbit(inven
, DEADGOD
) ||
320 testbit(location
[position
].objects
, DEADGOD
))
322 else if (testbit(inven
, DEADTIME
) ||
323 testbit(location
[position
].objects
, DEADTIME
))
325 else if (testbit(inven
, DEADNATIVE
) ||
326 testbit(location
[position
].objects
, DEADNATIVE
))
329 if (wordtype
[wordnumber
] == NOUNS
&& value
== DOOR
) {
331 puts("You hurt your foot.");
333 puts("You're not holding a door.");
334 } else if (objsht
[value
] == NULL
) {
336 puts("That's not for kicking!");
338 puts("You don't have that.");
340 printf("%s:\n", objsht
[value
]);
341 if (testbit(inven
, value
)) {
342 clearbit(inven
, value
);
343 carrying
-= objwt
[value
];
344 encumber
-= objcumber
[value
];
346 printf("The bomb explodes. A ");
347 printf("blinding white light and ");
348 printf("immense concussion ");
349 puts("obliterate us.");
352 if (value
!= AMULET
&& value
!= MEDALION
&&
354 setbit(location
[position
].objects
,
360 puts("Drop kicked.");
362 printf("%s.\n", name
);
365 printf("You aren't holding the %s.\n",
367 if (testbit(location
[position
].objects
,
370 puts("Kicked instead.");
371 else if (*name
== 'G')
372 puts("Given anyway.");
374 } else if (testbit(location
[position
].objects
,
377 else if (testbit(wear
, value
))
378 puts("Not while it's being worn.");
383 if (wordnumber
< wordcount
- 1 &&
384 wordvalue
[++wordnumber
] == AND
)
387 return (firstnumber
);
396 wordnumber
= take(wear
);
397 return (drop("Dropped"));
403 wordnumber
= take(location
[position
].objects
);
410 int firstnumber
, value
;
412 firstnumber
= wordnumber
;
414 while (wordnumber
<= wordcount
) {
415 value
= wordvalue
[wordnumber
];
416 if (wordtype
[wordnumber
] != OBJECT
|| objsht
[value
] == NULL
)
421 puts("You can't eat that!");
422 return (firstnumber
);
426 return (firstnumber
);
429 printf("You can't eat %s%s!\n",
430 A_OR_AN_OR_BLANK(value
), objsht
[value
]);
431 return (firstnumber
);
436 case COCONUTS
: /* eatable things */
439 printf("%s:\n", objsht
[value
]);
440 if (testbit(inven
, value
) &&
441 ourtime
> ate
- CYCLE
&&
442 testbit(inven
, KNIFE
)) {
443 clearbit(inven
, value
);
444 carrying
-= objwt
[value
];
445 encumber
-= objcumber
[value
];
446 ate
= max(ourtime
, ate
) + CYCLE
/ 3;
447 snooze
+= CYCLE
/ 10;
449 printf("Eaten. You can explore a little ");
451 } else if (!testbit(inven
, value
)) {
452 printf("You aren't holding the %s.\n",
454 } else if (!testbit(inven
, KNIFE
))
455 puts("You need a knife.");
457 puts("You're stuffed.");
458 if (wordnumber
< wordcount
- 1 &&
459 wordvalue
[++wordnumber
] == AND
)
462 return (firstnumber
);
465 return (firstnumber
);