]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/pack.c
1 /* $NetBSD: pack.c,v 1.10 2008/01/14 03:50:02 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.10 2008/01/14 03:50:02 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(object
*obj
, object
*pack
, int condense
)
66 if ((op
= check_duplicate(obj
, pack
)) != NULL
) {
70 obj
->ichar
= next_avail_ichar();
73 if (pack
->next_object
== 0) {
74 pack
->next_object
= obj
;
76 op
= pack
->next_object
;
78 while (op
->next_object
) {
81 op
->next_object
= obj
;
88 take_from_pack(object
*obj
, object
*pack
)
90 while (pack
->next_object
!= obj
) {
91 pack
= pack
->next_object
;
93 pack
->next_object
= pack
->next_object
->next_object
;
96 /* Note: *status is set to 0 if the rogue attempts to pick up a scroll
97 * of scare-monster and it turns to dust. *status is otherwise set to 1.
101 pick_up(int row
, int col
, short *status
)
108 messagef(0, "you're floating in the air!");
111 obj
= object_at(&level_objects
, row
, col
);
113 messagef(1, "pick_up(): inconsistent");
116 if ( (obj
->what_is
== SCROL
) &&
117 (obj
->which_kind
== SCARE_MONSTER
) &&
119 messagef(0, "the scroll turns to dust as you pick it up");
120 dungeon
[row
][col
] &= (~OBJECT
);
121 vanish(obj
, 0, &level_objects
);
123 if (id_scrolls
[SCARE_MONSTER
].id_status
== UNIDENTIFIED
) {
124 id_scrolls
[SCARE_MONSTER
].id_status
= IDENTIFIED
;
128 if (obj
->what_is
== GOLD
) {
129 rogue
.gold
+= obj
->quantity
;
130 dungeon
[row
][col
] &= ~(OBJECT
);
131 take_from_pack(obj
, &level_objects
);
132 print_stats(STAT_GOLD
);
133 return(obj
); /* obj will be free_object()ed in caller */
135 if (pack_count(obj
) >= MAX_PACK_COUNT
) {
136 messagef(1, "pack too full");
139 dungeon
[row
][col
] &= ~(OBJECT
);
140 take_from_pack(obj
, &level_objects
);
141 obj
= add_to_pack(obj
, &rogue
.pack
, 1);
153 if (dungeon
[rogue
.row
][rogue
.col
] & (OBJECT
| STAIRS
| TRAP
)) {
154 messagef(0, "there's already something there");
157 if (!rogue
.pack
.next_object
) {
158 messagef(0, "you have nothing to drop");
161 if ((ch
= pack_letter("drop what?", ALL_OBJECTS
)) == CANCEL
) {
164 if (!(obj
= get_letter_object(ch
))) {
165 messagef(0, "no such item.");
168 if (obj
->in_use_flags
& BEING_WIELDED
) {
169 if (obj
->is_cursed
) {
170 messagef(0, "%s", curse_message
);
173 unwield(rogue
.weapon
);
174 } else if (obj
->in_use_flags
& BEING_WORN
) {
175 if (obj
->is_cursed
) {
176 messagef(0, "%s", curse_message
);
181 print_stats(STAT_ARMOR
);
182 } else if (obj
->in_use_flags
& ON_EITHER_HAND
) {
183 if (obj
->is_cursed
) {
184 messagef(0, "%s", curse_message
);
189 obj
->row
= rogue
.row
;
190 obj
->col
= rogue
.col
;
192 if ((obj
->quantity
> 1) && (obj
->what_is
!= WEAPON
)) {
194 new = alloc_object();
200 take_from_pack(obj
, &rogue
.pack
);
202 place_at(obj
, rogue
.row
, rogue
.col
);
203 get_desc(obj
, desc
, sizeof(desc
));
204 messagef(0, "dropped %s", desc
);
209 check_duplicate(object
*obj
, object
*pack
)
213 if (!(obj
->what_is
& (WEAPON
| FOOD
| SCROL
| POTION
))) {
216 if ((obj
->what_is
== FOOD
) && (obj
->which_kind
== FRUIT
)) {
219 op
= pack
->next_object
;
222 if ((op
->what_is
== obj
->what_is
) &&
223 (op
->which_kind
== obj
->which_kind
)) {
225 if ((obj
->what_is
!= WEAPON
) ||
226 ((obj
->what_is
== WEAPON
) &&
227 ((obj
->which_kind
== ARROW
) ||
228 (obj
->which_kind
== DAGGER
) ||
229 (obj
->which_kind
== DART
) ||
230 (obj
->which_kind
== SHURIKEN
)) &&
231 (obj
->quiver
== op
->quiver
))) {
232 op
->quantity
+= obj
->quantity
;
236 op
= op
->next_object
;
242 next_avail_ichar(void)
248 for (i
= 0; i
< 26; i
++) {
251 obj
= rogue
.pack
.next_object
;
253 if (obj
->ichar
>= 'a' && obj
->ichar
<= 'z') {
254 ichars
[(obj
->ichar
- 'a')] = 1;
256 obj
= obj
->next_object
;
258 for (i
= 0; i
< 26; i
++) {
269 while (rgetchar() != ' ')
274 pack_letter(const char *prompt
, unsigned short mask
)
277 unsigned short tmask
= mask
;
279 if (!mask_pack(&rogue
.pack
, mask
)) {
280 messagef(0, "nothing appropriate");
285 messagef(0, "%s", prompt
);
289 if (!is_pack_letter(&ch
, &mask
)) {
299 inventory(&rogue
.pack
, mask
);
316 if (rogue
.armor
->is_cursed
) {
317 messagef(0, "%s", curse_message
);
322 get_desc(obj
, desc
, sizeof(desc
));
323 messagef(0, "was wearing %s", desc
);
324 print_stats(STAT_ARMOR
);
328 messagef(0, "not wearing any");
340 messagef(0, "you're already wearing some");
343 ch
= pack_letter("wear what?", ARMOR
);
348 if (!(obj
= get_letter_object(ch
))) {
349 messagef(0, "no such item.");
352 if (obj
->what_is
!= ARMOR
) {
353 messagef(0, "you can't wear that");
357 get_desc(obj
, desc
, sizeof(desc
));
358 messagef(0, "wearing %s", desc
);
360 print_stats(STAT_ARMOR
);
368 obj
->in_use_flags
&= (~BEING_WORN
);
377 obj
->in_use_flags
|= BEING_WORN
;
388 if (rogue
.weapon
&& rogue
.weapon
->is_cursed
) {
389 messagef(0, "%s", curse_message
);
392 ch
= pack_letter("wield what?", WEAPON
);
397 if (!(obj
= get_letter_object(ch
))) {
398 messagef(0, "No such item.");
401 if (obj
->what_is
& (ARMOR
| RING
)) {
402 messagef(0, "you can't wield %s",
403 ((obj
->what_is
== ARMOR
) ? "armor" : "rings"));
406 if (obj
->in_use_flags
& BEING_WIELDED
) {
407 messagef(0, "in use");
409 unwield(rogue
.weapon
);
410 get_desc(obj
, desc
, sizeof(desc
));
411 messagef(0, "wielding %s", desc
);
418 do_wield(object
*obj
)
421 obj
->in_use_flags
|= BEING_WIELDED
;
428 obj
->in_use_flags
&= (~BEING_WIELDED
);
439 char buf
[MAX_TITLE_LENGTH
+2];
441 ch
= pack_letter("call what?", (SCROL
| POTION
| WAND
| RING
));
446 if (!(obj
= get_letter_object(ch
))) {
447 messagef(0, "no such item.");
450 if (!(obj
->what_is
& (SCROL
| POTION
| WAND
| RING
))) {
451 messagef(0, "surely you already know what that's called");
454 id_table
= get_id_table(obj
);
456 if (get_input_line("call it:", "", buf
, sizeof(buf
),
457 id_table
[obj
->which_kind
].title
, 1, 1)) {
458 id_table
[obj
->which_kind
].id_status
= CALLED
;
459 (void)strlcpy(id_table
[obj
->which_kind
].title
, buf
,
460 sizeof(id_table
[obj
->which_kind
].title
));
465 pack_count(const object
*new_obj
)
470 obj
= rogue
.pack
.next_object
;
473 if (obj
->what_is
!= WEAPON
) {
474 count
+= obj
->quantity
;
475 } else if (!new_obj
) {
477 } else if ((new_obj
->what_is
!= WEAPON
) ||
478 ((obj
->which_kind
!= ARROW
) &&
479 (obj
->which_kind
!= DAGGER
) &&
480 (obj
->which_kind
!= DART
) &&
481 (obj
->which_kind
!= SHURIKEN
)) ||
482 (new_obj
->which_kind
!= obj
->which_kind
) ||
483 (obj
->quiver
!= new_obj
->quiver
)) {
486 obj
= obj
->next_object
;
492 mask_pack(const object
*pack
, unsigned short mask
)
494 while (pack
->next_object
) {
495 pack
= pack
->next_object
;
496 if (pack
->what_is
& mask
) {
504 is_pack_letter(short *c
, unsigned short *mask
)
506 if (((*c
== '?') || (*c
== '!') || (*c
== ':') || (*c
== '=') ||
507 (*c
== ')') || (*c
== ']') || (*c
== '/') || (*c
== ','))) {
537 return(((*c
>= 'a') && (*c
<= 'z')) || (*c
== CANCEL
) || (*c
== LIST
));
543 return(mask_pack(&rogue
.pack
, AMULET
));
553 if (!(dungeon
[rogue
.row
][rogue
.col
] & OBJECT
)) {
554 messagef(0, "nothing here");
556 if ((obj
= pick_up(rogue
.row
, rogue
.col
, &stat
)) != NULL
) {
557 get_desc(obj
, desc
, sizeof(desc
));
558 if (obj
->what_is
== GOLD
) {
559 messagef(0, "%s", desc
);
562 messagef(0, "%s(%c)", desc
, obj
->ichar
);
565 if (obj
|| (!stat
)) {