2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)pack.c 8.1 (Berkeley) 5/31/93
33 * $FreeBSD: src/games/rogue/pack.c,v 1.8 1999/11/30 03:49:25 billf Exp $
39 * This source herein may be modified and/or distributed by anybody who
40 * so desires, with the following restrictions:
41 * 1.) No portion of this notice shall be removed.
42 * 2.) Credit shall not be taken for the creation of this source.
43 * 3.) This code is not to be traded, sold, or used for personal
51 const char curse_message
[] = "you can't, it appears to be cursed";
53 static object
*check_duplicate(object
*, object
*);
54 static boolean
is_pack_letter(short *, unsigned short *);
55 static boolean
mask_pack(const object
*, unsigned short);
56 static int next_avail_ichar(void);
59 add_to_pack(object
*obj
, object
*pack
, int condense
)
64 if ((op
= check_duplicate(obj
, pack
)) != NULL
) {
68 obj
->ichar
= next_avail_ichar();
71 if (pack
->next_object
== 0) {
72 pack
->next_object
= obj
;
74 op
= pack
->next_object
;
76 while (op
->next_object
) {
79 op
->next_object
= obj
;
86 take_from_pack(object
*obj
, object
*pack
)
88 while (pack
->next_object
!= obj
) {
89 pack
= pack
->next_object
;
91 pack
->next_object
= pack
->next_object
->next_object
;
94 /* Note: *status is set to 0 if the rogue attempts to pick up a scroll
95 * of scare-monster and it turns to dust. *status is otherwise set to 1.
99 pick_up(int row
, int col
, short *status
)
106 message("you're floating in the air!", 0);
109 obj
= object_at(&level_objects
, row
, col
);
111 message("pick_up(): inconsistent", 1);
114 if ( (obj
->what_is
== SCROL
) &&
115 (obj
->which_kind
== SCARE_MONSTER
) &&
117 message("the scroll turns to dust as you pick it up", 0);
118 dungeon
[row
][col
] &= (~OBJECT
);
119 vanish(obj
, 0, &level_objects
);
121 if (id_scrolls
[SCARE_MONSTER
].id_status
== UNIDENTIFIED
) {
122 id_scrolls
[SCARE_MONSTER
].id_status
= IDENTIFIED
;
126 if (obj
->what_is
== GOLD
) {
127 rogue
.gold
+= obj
->quantity
;
128 dungeon
[row
][col
] &= ~(OBJECT
);
129 take_from_pack(obj
, &level_objects
);
130 print_stats(STAT_GOLD
);
131 return(obj
); /* obj will be free_object()ed in caller */
133 if (pack_count(obj
) >= MAX_PACK_COUNT
) {
134 message("pack too full", 1);
137 dungeon
[row
][col
] &= ~(OBJECT
);
138 take_from_pack(obj
, &level_objects
);
139 obj
= add_to_pack(obj
, &rogue
.pack
, 1);
151 if (dungeon
[rogue
.row
][rogue
.col
] & (OBJECT
| STAIRS
| TRAP
)) {
152 message("there's already something there", 0);
155 if (!rogue
.pack
.next_object
) {
156 message("you have nothing to drop", 0);
159 if ((ch
= pack_letter("drop what?", ALL_OBJECTS
)) == CANCEL
) {
162 if (!(obj
= get_letter_object(ch
))) {
163 message("no such item.", 0);
166 if (obj
->in_use_flags
& BEING_WIELDED
) {
167 if (obj
->is_cursed
) {
168 message(curse_message
, 0);
171 unwield(rogue
.weapon
);
172 } else if (obj
->in_use_flags
& BEING_WORN
) {
173 if (obj
->is_cursed
) {
174 message(curse_message
, 0);
179 print_stats(STAT_ARMOR
);
180 } else if (obj
->in_use_flags
& ON_EITHER_HAND
) {
181 if (obj
->is_cursed
) {
182 message(curse_message
, 0);
187 obj
->row
= rogue
.row
;
188 obj
->col
= rogue
.col
;
190 if ((obj
->quantity
> 1) && (obj
->what_is
!= WEAPON
)) {
192 new = alloc_object();
198 take_from_pack(obj
, &rogue
.pack
);
200 place_at(obj
, rogue
.row
, rogue
.col
);
201 strcpy(desc
, "dropped ");
202 get_desc(obj
, desc
+ 8);
208 check_duplicate(object
*obj
, object
*pack
)
212 if (!(obj
->what_is
& (WEAPON
| FOOD
| SCROL
| POTION
))) {
215 if ((obj
->what_is
== FOOD
) && (obj
->which_kind
== FRUIT
)) {
218 op
= pack
->next_object
;
221 if ((op
->what_is
== obj
->what_is
) &&
222 (op
->which_kind
== obj
->which_kind
)) {
224 if ((obj
->what_is
!= WEAPON
) ||
225 ((obj
->what_is
== WEAPON
) &&
226 ((obj
->which_kind
== ARROW
) ||
227 (obj
->which_kind
== DAGGER
) ||
228 (obj
->which_kind
== DART
) ||
229 (obj
->which_kind
== SHURIKEN
)) &&
230 (obj
->quiver
== op
->quiver
))) {
231 op
->quantity
+= obj
->quantity
;
235 op
= op
->next_object
;
241 next_avail_ichar(void)
247 for (i
= 0; i
< 26; i
++) {
250 obj
= rogue
.pack
.next_object
;
252 if (obj
->ichar
>= 'a' && obj
->ichar
<= 'z') {
253 ichars
[(obj
->ichar
- 'a')] = 1;
255 obj
= obj
->next_object
;
257 for (i
= 0; i
< 26; i
++) {
268 if (!isatty(0) || !isatty(1))
270 while (rgetchar() != ' ')
275 pack_letter(const char *prompt
, unsigned short mask
)
278 unsigned short tmask
= mask
;
280 if (!mask_pack(&rogue
.pack
, mask
)) {
281 message("nothing appropriate", 0);
290 if (!is_pack_letter(&ch
, &mask
)) {
300 inventory(&rogue
.pack
, mask
);
317 if (rogue
.armor
->is_cursed
) {
318 message(curse_message
, 0);
323 strcpy(desc
, "was wearing ");
324 get_desc(obj
, desc
+12);
326 print_stats(STAT_ARMOR
);
330 message("not wearing any", 0);
342 message("you're already wearing some", 0);
345 ch
= pack_letter("wear what?", ARMOR
);
350 if (!(obj
= get_letter_object(ch
))) {
351 message("no such item.", 0);
354 if (obj
->what_is
!= ARMOR
) {
355 message("you can't wear that", 0);
359 strcpy(desc
, "wearing ");
360 get_desc(obj
, desc
+ 8);
363 print_stats(STAT_ARMOR
);
371 obj
->in_use_flags
&= (~BEING_WORN
);
380 obj
->in_use_flags
|= BEING_WORN
;
391 if (rogue
.weapon
&& rogue
.weapon
->is_cursed
) {
392 message(curse_message
, 0);
395 ch
= pack_letter("wield what?", WEAPON
);
400 if (!(obj
= get_letter_object(ch
))) {
401 message("No such item.", 0);
404 if (obj
->what_is
& (ARMOR
| RING
)) {
405 sprintf(desc
, "you can't wield %s",
406 ((obj
->what_is
== ARMOR
) ? "armor" : "rings"));
410 if (obj
->in_use_flags
& BEING_WIELDED
) {
411 message("in use", 0);
413 unwield(rogue
.weapon
);
414 strcpy(desc
, "wielding ");
415 get_desc(obj
, desc
+ 9);
423 do_wield(object
*obj
)
426 obj
->in_use_flags
|= BEING_WIELDED
;
433 obj
->in_use_flags
&= (~BEING_WIELDED
);
444 char buf
[MAX_TITLE_LENGTH
+2];
446 ch
= pack_letter("call what?", (SCROL
| POTION
| WAND
| RING
));
451 if (!(obj
= get_letter_object(ch
))) {
452 message("no such item.", 0);
455 if (!(obj
->what_is
& (SCROL
| POTION
| WAND
| RING
))) {
456 message("surely you already know what that's called", 0);
459 id_table
= get_id_table(obj
);
461 if (get_input_line("call it:","",buf
,id_table
[obj
->which_kind
].title
,1,1)) {
462 id_table
[obj
->which_kind
].id_status
= CALLED
;
463 strcpy(id_table
[obj
->which_kind
].title
, buf
);
468 pack_count(const object
*new_obj
)
473 obj
= rogue
.pack
.next_object
;
476 if (obj
->what_is
!= WEAPON
) {
477 count
+= obj
->quantity
;
478 } else if (!new_obj
) {
480 } else if ((new_obj
->what_is
!= WEAPON
) ||
481 ((obj
->which_kind
!= ARROW
) &&
482 (obj
->which_kind
!= DAGGER
) &&
483 (obj
->which_kind
!= DART
) &&
484 (obj
->which_kind
!= SHURIKEN
)) ||
485 (new_obj
->which_kind
!= obj
->which_kind
) ||
486 (obj
->quiver
!= new_obj
->quiver
)) {
489 obj
= obj
->next_object
;
495 mask_pack(const object
*pack
, unsigned short mask
)
497 while (pack
->next_object
) {
498 pack
= pack
->next_object
;
499 if (pack
->what_is
& mask
) {
507 is_pack_letter(short *c
, unsigned short *mask
)
509 if (((*c
== '?') || (*c
== '!') || (*c
== ':') || (*c
== '=') ||
510 (*c
== ')') || (*c
== ']') || (*c
== '/') || (*c
== ','))) {
540 return(((*c
>= 'a') && (*c
<= 'z')) || (*c
== CANCEL
) || (*c
== LIST
));
546 return(mask_pack(&rogue
.pack
, AMULET
));
556 if (!(dungeon
[rogue
.row
][rogue
.col
] & OBJECT
)) {
557 message("nothing here", 0);
559 if ((obj
= pick_up(rogue
.row
, rogue
.col
, &stat
)) != NULL
) {
561 if (obj
->what_is
== GOLD
) {
567 desc
[n
+1] = obj
->ichar
;
573 if (obj
|| (!stat
)) {