]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/pack.c
1 /* $NetBSD: pack.c,v 1.8 2007/12/27 23:53:00 dholland Exp $ */
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)pack.c 8.1 (Berkeley) 5/31/93";
40 __RCSID("$NetBSD: pack.c,v 1.8 2007/12/27 23:53:00 dholland Exp $");
47 * This source herein may be modified and/or distributed by anybody who
48 * so desires, with the following restrictions:
49 * 1.) No portion of this notice shall be removed.
50 * 2.) Credit shall not be taken for the creation of this source.
51 * 3.) This code is not to be traded, sold, or used for personal
58 const char *curse_message
= "you can't, it appears to be cursed";
61 add_to_pack(obj
, pack
, condense
)
68 if ((op
= check_duplicate(obj
, pack
)) != NULL
) {
72 obj
->ichar
= next_avail_ichar();
75 if (pack
->next_object
== 0) {
76 pack
->next_object
= obj
;
78 op
= pack
->next_object
;
80 while (op
->next_object
) {
83 op
->next_object
= obj
;
90 take_from_pack(obj
, pack
)
93 while (pack
->next_object
!= obj
) {
94 pack
= pack
->next_object
;
96 pack
->next_object
= pack
->next_object
->next_object
;
99 /* Note: *status is set to 0 if the rogue attempts to pick up a scroll
100 * of scare-monster and it turns to dust. *status is otherwise set to 1.
104 pick_up(row
, col
, status
)
113 messagef(0, "you're floating in the air!");
114 return((object
*) 0);
116 obj
= object_at(&level_objects
, row
, col
);
118 messagef(1, "pick_up(): inconsistent");
121 if ( (obj
->what_is
== SCROL
) &&
122 (obj
->which_kind
== SCARE_MONSTER
) &&
124 messagef(0, "the scroll turns to dust as you pick it up");
125 dungeon
[row
][col
] &= (~OBJECT
);
126 vanish(obj
, 0, &level_objects
);
128 if (id_scrolls
[SCARE_MONSTER
].id_status
== UNIDENTIFIED
) {
129 id_scrolls
[SCARE_MONSTER
].id_status
= IDENTIFIED
;
131 return((object
*) 0);
133 if (obj
->what_is
== GOLD
) {
134 rogue
.gold
+= obj
->quantity
;
135 dungeon
[row
][col
] &= ~(OBJECT
);
136 take_from_pack(obj
, &level_objects
);
137 print_stats(STAT_GOLD
);
138 return(obj
); /* obj will be free_object()ed in caller */
140 if (pack_count(obj
) >= MAX_PACK_COUNT
) {
141 messagef(1, "pack too full");
142 return((object
*) 0);
144 dungeon
[row
][col
] &= ~(OBJECT
);
145 take_from_pack(obj
, &level_objects
);
146 obj
= add_to_pack(obj
, &rogue
.pack
, 1);
158 if (dungeon
[rogue
.row
][rogue
.col
] & (OBJECT
| STAIRS
| TRAP
)) {
159 messagef(0, "there's already something there");
162 if (!rogue
.pack
.next_object
) {
163 messagef(0, "you have nothing to drop");
166 if ((ch
= pack_letter("drop what?", ALL_OBJECTS
)) == CANCEL
) {
169 if (!(obj
= get_letter_object(ch
))) {
170 messagef(0, "no such item.");
173 if (obj
->in_use_flags
& BEING_WIELDED
) {
174 if (obj
->is_cursed
) {
175 messagef(0, "%s", curse_message
);
178 unwield(rogue
.weapon
);
179 } else if (obj
->in_use_flags
& BEING_WORN
) {
180 if (obj
->is_cursed
) {
181 messagef(0, "%s", curse_message
);
186 print_stats(STAT_ARMOR
);
187 } else if (obj
->in_use_flags
& ON_EITHER_HAND
) {
188 if (obj
->is_cursed
) {
189 messagef(0, "%s", curse_message
);
194 obj
->row
= rogue
.row
;
195 obj
->col
= rogue
.col
;
197 if ((obj
->quantity
> 1) && (obj
->what_is
!= WEAPON
)) {
199 new = alloc_object();
205 take_from_pack(obj
, &rogue
.pack
);
207 place_at(obj
, rogue
.row
, rogue
.col
);
208 get_desc(obj
, desc
, sizeof(desc
));
209 messagef(0, "dropped %s", desc
);
214 check_duplicate(obj
, pack
)
219 if (!(obj
->what_is
& (WEAPON
| FOOD
| SCROL
| POTION
))) {
222 if ((obj
->what_is
== FOOD
) && (obj
->which_kind
== FRUIT
)) {
225 op
= pack
->next_object
;
228 if ((op
->what_is
== obj
->what_is
) &&
229 (op
->which_kind
== obj
->which_kind
)) {
231 if ((obj
->what_is
!= WEAPON
) ||
232 ((obj
->what_is
== WEAPON
) &&
233 ((obj
->which_kind
== ARROW
) ||
234 (obj
->which_kind
== DAGGER
) ||
235 (obj
->which_kind
== DART
) ||
236 (obj
->which_kind
== SHURIKEN
)) &&
237 (obj
->quiver
== op
->quiver
))) {
238 op
->quantity
+= obj
->quantity
;
242 op
= op
->next_object
;
254 for (i
= 0; i
< 26; i
++) {
257 obj
= rogue
.pack
.next_object
;
259 if (obj
->ichar
>= 'a' && obj
->ichar
<= 'z') {
260 ichars
[(obj
->ichar
- 'a')] = 1;
262 obj
= obj
->next_object
;
264 for (i
= 0; i
< 26; i
++) {
275 while (rgetchar() != ' ') ;
279 pack_letter(prompt
, mask
)
284 unsigned short tmask
= mask
;
286 if (!mask_pack(&rogue
.pack
, mask
)) {
287 messagef(0, "nothing appropriate");
292 messagef(0, "%s", prompt
);
296 if (!is_pack_letter(&ch
, &mask
)) {
306 inventory(&rogue
.pack
, mask
);
323 if (rogue
.armor
->is_cursed
) {
324 messagef(0, "%s", curse_message
);
329 get_desc(obj
, desc
, sizeof(desc
));
330 messagef(0, "was wearing %s", desc
);
331 print_stats(STAT_ARMOR
);
335 messagef(0, "not wearing any");
347 messagef(0, "you're already wearing some");
350 ch
= pack_letter("wear what?", ARMOR
);
355 if (!(obj
= get_letter_object(ch
))) {
356 messagef(0, "no such item.");
359 if (obj
->what_is
!= ARMOR
) {
360 messagef(0, "you can't wear that");
364 get_desc(obj
, desc
, sizeof(desc
));
365 messagef(0, "wearing %s", desc
);
367 print_stats(STAT_ARMOR
);
376 obj
->in_use_flags
&= (~BEING_WORN
);
378 rogue
.armor
= (object
*) 0;
386 obj
->in_use_flags
|= BEING_WORN
;
397 if (rogue
.weapon
&& rogue
.weapon
->is_cursed
) {
398 messagef(0, "%s", curse_message
);
401 ch
= pack_letter("wield what?", WEAPON
);
406 if (!(obj
= get_letter_object(ch
))) {
407 messagef(0, "No such item.");
410 if (obj
->what_is
& (ARMOR
| RING
)) {
411 messagef(0, "you can't wield %s",
412 ((obj
->what_is
== ARMOR
) ? "armor" : "rings"));
415 if (obj
->in_use_flags
& BEING_WIELDED
) {
416 messagef(0, "in use");
418 unwield(rogue
.weapon
);
419 get_desc(obj
, desc
, sizeof(desc
));
420 messagef(0, "wielding %s", desc
);
431 obj
->in_use_flags
|= BEING_WIELDED
;
439 obj
->in_use_flags
&= (~BEING_WIELDED
);
441 rogue
.weapon
= (object
*) 0;
450 char buf
[MAX_TITLE_LENGTH
+2];
452 ch
= pack_letter("call what?", (SCROL
| POTION
| WAND
| RING
));
457 if (!(obj
= get_letter_object(ch
))) {
458 messagef(0, "no such item.");
461 if (!(obj
->what_is
& (SCROL
| POTION
| WAND
| RING
))) {
462 messagef(0, "surely you already know what that's called");
465 id_table
= get_id_table(obj
);
467 if (get_input_line("call it:", "", buf
, sizeof(buf
),
468 id_table
[obj
->which_kind
].title
, 1, 1)) {
469 id_table
[obj
->which_kind
].id_status
= CALLED
;
470 (void) strlcpy(id_table
[obj
->which_kind
].title
, buf
,
471 sizeof(id_table
[obj
->which_kind
].title
));
477 const object
*new_obj
;
482 obj
= rogue
.pack
.next_object
;
485 if (obj
->what_is
!= WEAPON
) {
486 count
+= obj
->quantity
;
487 } else if (!new_obj
) {
489 } else if ((new_obj
->what_is
!= WEAPON
) ||
490 ((obj
->which_kind
!= ARROW
) &&
491 (obj
->which_kind
!= DAGGER
) &&
492 (obj
->which_kind
!= DART
) &&
493 (obj
->which_kind
!= SHURIKEN
)) ||
494 (new_obj
->which_kind
!= obj
->which_kind
) ||
495 (obj
->quiver
!= new_obj
->quiver
)) {
498 obj
= obj
->next_object
;
504 mask_pack(pack
, mask
)
508 while (pack
->next_object
) {
509 pack
= pack
->next_object
;
510 if (pack
->what_is
& mask
) {
518 is_pack_letter(c
, mask
)
520 unsigned short *mask
;
522 if (((*c
== '?') || (*c
== '!') || (*c
== ':') || (*c
== '=') ||
523 (*c
== ')') || (*c
== ']') || (*c
== '/') || (*c
== ','))) {
553 return(((*c
>= 'a') && (*c
<= 'z')) || (*c
== CANCEL
) || (*c
== LIST
));
559 return(mask_pack(&rogue
.pack
, AMULET
));
569 if (!(dungeon
[rogue
.row
][rogue
.col
] & OBJECT
)) {
570 messagef(0, "nothing here");
572 if ((obj
= pick_up(rogue
.row
, rogue
.col
, &stat
)) != NULL
) {
573 get_desc(obj
, desc
, sizeof(desc
));
574 if (obj
->what_is
== GOLD
) {
575 messagef(0, "%s", desc
);
578 messagef(0, "%s(%c)", desc
, obj
->ichar
);
581 if (obj
|| (!stat
)) {