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
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. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)com4.c 8.1 (Berkeley) 5/31/93
30 * $FreeBSD: src/games/battlestar/com4.c,v 1.8.2.1 2001/03/05 11:45:35 kris Exp $
31 * $DragonFly: src/games/battlestar/com4.c,v 1.3 2006/08/08 16:47:20 pavalos Exp $
37 take(unsigned int from
[])
39 int firstnumber
, heavy
, bulky
, value
;
42 firstnumber
= wordnumber
;
43 if (wordnumber
< wordcount
&& wordvalue
[wordnumber
+ 1] == OFF
) {
45 wordvalue
[wordnumber
] = TAKEOFF
;
48 while (wordtype
[++wordnumber
] == ADJS
)
50 while (wordnumber
<= wordcount
&& wordtype
[wordnumber
] ==
52 value
= wordvalue
[wordnumber
];
53 printf("%s:\n", objsht
[value
]);
54 for (n
= 0; objsht
[value
][n
]; n
++)
56 heavy
= (carrying
+ objwt
[value
]) <= WEIGHT
;
57 bulky
= (encumber
+ objcumber
[value
]) <= CUMBER
;
58 if ((testbit(from
, value
) || wiz
|| tempwiz
) &&
59 heavy
&& bulky
&& !testbit(inven
, value
)) {
61 carrying
+= objwt
[value
];
62 encumber
+= objcumber
[value
];
64 if (testbit(from
, value
))
67 printf("Zap! Taken from thin air.\n");
68 clearbit(from
, value
);
69 if (value
== MEDALION
)
71 } else if (testbit(inven
, value
))
72 printf("You're already holding%s%s.\n",
73 (objsht
[value
][n
- 1] ==
77 printf("The %s %s too heavy.\n", objsht
[value
],
78 (objsht
[value
][n
- 1] ==
82 "The %s %s too cumbersome to hold.\n",
84 (objsht
[value
][n
- 1] ==
87 printf("I dont see any %s around here.\n",
89 if (wordnumber
< wordcount
- 1 &&
90 wordvalue
[++wordnumber
] == AND
)
96 /* special cases with their own return()'s */
97 if (wordnumber
<= wordcount
&& wordtype
[wordnumber
] == NOUNS
)
98 switch (wordvalue
[wordnumber
]) {
100 if (testbit(from
, SWORD
)) {
101 wordtype
[wordnumber
--] = OBJECT
;
104 if (testbit(from
, TWO_HANDED
)) {
105 wordvalue
[wordnumber
] = TWO_HANDED
;
106 wordtype
[wordnumber
--] = OBJECT
;
109 wordvalue
[wordnumber
] = BROAD
;
110 wordtype
[wordnumber
--] = OBJECT
;
114 if (testbit(from
, MAID
)) {
115 wordvalue
[wordnumber
] = MAID
;
116 wordtype
[wordnumber
--] = OBJECT
;
118 } else if (testbit(from
, DEADWOOD
)) {
119 wordvalue
[wordnumber
] = DEADWOOD
;
120 wordtype
[wordnumber
--] = OBJECT
;
122 } else if (testbit(from
, DEADNATIVE
)) {
123 wordvalue
[wordnumber
] = DEADNATIVE
;
124 wordtype
[wordnumber
--] = OBJECT
;
127 if (testbit(from
, DEADGOD
)) {
128 wordvalue
[wordnumber
] = DEADGOD
;
129 wordtype
[wordnumber
--] = OBJECT
;
132 wordvalue
[wordnumber
] = DEADTIME
;
133 wordtype
[wordnumber
--] = OBJECT
;
140 if (testbit(location
[position
].objects
, AMULET
)) {
141 puts("The amulet is warm to the touch, and its beauty catches your breath.");
142 puts("A mist falls over your eyes, but then it is gone. Sounds seem clearer");
143 puts("and sharper but far away as if in a dream. The sound of purling water reaches");
144 puts("you from afar. The mist falls again, and your heart leaps in horror. The gold");
145 puts("freezes your hands and fathomless darkness engulfs your soul.");
147 wordtype
[wordnumber
--] = OBJECT
;
151 if (testbit(location
[position
].objects
, MEDALION
)) {
152 puts("The medallion is warm, and it rekindles your spirit with the warmth of life.");
153 puts("Your amulet begins to glow as the medallion is brought near to it, and together\nthey radiate.");
155 wordtype
[wordnumber
--] = OBJECT
;
159 if (testbit(location
[position
].objects
, TALISMAN
))
160 puts("The talisman is cold to the touch, and it sends a chill down your spine.");
161 wordtype
[wordnumber
--] = OBJECT
;
165 if (testbit(location
[position
].objects
, BATHGOD
) &&
166 (testbit(wear
, AMULET
) || testbit(inven
, AMULET
))) {
167 puts("She offers a delicate hand, and you help her out of the sparkling springs.");
168 puts("Water droplets like liquid silver bedew her golden skin, but when they part");
169 puts("from her, they fall as teardrops. She wraps a single cloth around her and");
170 puts("ties it at the waist. Around her neck hangs a golden amulet.");
171 puts("She bids you to follow her.");
174 clearbit(location
[position
].objects
, BATHGOD
);
176 if (!testbit(location
[position
].objects
, BATHGOD
))
177 puts("You're in no position to take her.");
179 puts("She moves away from you.");
183 puts("It doesn't seem to work.");
186 puts("You've got to be kidding.");
187 return (firstnumber
);
191 throw(const char *name
)
198 if (drop(name
) != -1) {
199 switch (wordvalue
[wordnumber
]) {
217 deposit
= location
[position
].up
*
218 (location
[position
].access
|| position
== FINAL
);
222 deposit
= location
[position
].down
;
226 while (wordtype
[++wordnumber
] == ADJS
)
228 while (wordnumber
<= wordcount
) {
229 value
= wordvalue
[wordnumber
];
231 testbit(location
[position
].objects
, value
)) {
232 clearbit(location
[position
].objects
, value
);
233 if (value
!= GRENADE
)
234 setbit(location
[deposit
].objects
, value
);
236 puts("A thundering explosion nearby sends up a cloud of smoke and shrapnel.");
237 for (n
= 0; n
< NUMOFWORDS
; n
++)
238 location
[deposit
].objects
[n
] = 0;
239 setbit(location
[deposit
].objects
, CHAR
);
241 if (value
== ROPE
&& position
== FINAL
)
242 location
[position
].access
= 1;
246 puts("The stone door is unhinged.");
247 location
[189].north
= 231;
248 location
[231].south
= 189;
251 puts("The wooden door is blown open.");
252 location
[30].west
= 25;
255 puts("The door is not damaged.");
258 if (value
== GRENADE
&&
259 testbit(location
[position
].objects
, value
)) {
260 puts("You are blown into shreds when your grenade explodes.");
263 if (wordnumber
< wordcount
- 1 &&
264 wordvalue
[++wordnumber
] == AND
)
275 drop(const char *name
)
277 int firstnumber
, value
;
279 firstnumber
= wordnumber
;
280 while (wordtype
[++wordnumber
] == ADJS
)
282 while (wordnumber
<= wordcount
&&
283 (wordtype
[wordnumber
] == OBJECT
|| wordtype
[wordnumber
] == NOUNS
)) {
284 value
= wordvalue
[wordnumber
];
285 printf("%s:\n", objsht
[value
]);
286 if (testbit(inven
, value
)) {
287 clearbit(inven
, value
);
288 carrying
-= objwt
[value
];
289 encumber
-= objcumber
[value
];
291 puts("The bomb explodes. A blinding white light and immense concussion obliterate us.");
294 if (value
!= AMULET
&& value
!= MEDALION
&& value
!=
296 setbit(location
[position
].objects
, value
);
301 puts("Drop kicked.");
303 printf("%s.\n", name
);
306 printf("You aren't holding the %s.\n",
308 if (testbit(location
[position
].objects
,
311 puts("Kicked instead.");
312 else if (*name
== 'G')
313 puts("Given anyway.");
318 if (wordnumber
< wordcount
- 1 &&
319 wordvalue
[++wordnumber
] == AND
)
322 return (firstnumber
);
331 wordnumber
= take(wear
);
332 return (drop("Dropped"));
338 wordnumber
= take(location
[position
].objects
);
345 int firstnumber
, value
;
347 firstnumber
= wordnumber
;
348 while (wordtype
[++wordnumber
] == ADJS
)
350 while (wordnumber
<= wordcount
) {
351 value
= wordvalue
[wordnumber
];
355 return (firstnumber
);
358 printf("You can't eat%s%s!\n",
359 wordtype
[wordnumber
] == OBJECT
&&
361 [strlen(objsht
[value
]) - 1] == 's' ?
364 return (firstnumber
);
369 case COCONUTS
: /* eatable things */
372 printf("%s:\n", objsht
[value
]);
373 if (testbit(inven
, value
) &&
374 gtime
> ate
- CYCLE
&&
375 testbit(inven
, KNIFE
)) {
376 clearbit(inven
, value
);
377 carrying
-= objwt
[value
];
378 encumber
-= objcumber
[value
];
379 ate
= max(gtime
, ate
) + CYCLE
/ 3;
380 snooze
+= CYCLE
/ 10;
382 puts("Eaten. You can explore a little longer now.");
383 } else if (gtime
< ate
- CYCLE
)
384 puts("You're stuffed.");
385 else if (!testbit(inven
, KNIFE
))
386 puts("You need a knife.");
388 printf("You aren't holding the %s.\n",
390 if (wordnumber
< wordcount
- 1 &&
391 wordvalue
[++wordnumber
] == AND
)
394 return (firstnumber
);
397 return (firstnumber
);