]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/pack.c
1 /* $NetBSD: pack.c,v 1.5 1998/09/11 14:10:39 hubertf 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. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/cdefs.h>
42 static char sccsid
[] = "@(#)pack.c 8.1 (Berkeley) 5/31/93";
44 __RCSID("$NetBSD: pack.c,v 1.5 1998/09/11 14:10:39 hubertf Exp $");
51 * This source herein may be modified and/or distributed by anybody who
52 * so desires, with the following restrictions:
53 * 1.) No portion of this notice shall be removed.
54 * 2.) Credit shall not be taken for the creation of this source.
55 * 3.) This code is not to be traded, sold, or used for personal
62 char *curse_message
= "you can't, it appears to be cursed";
65 add_to_pack(obj
, pack
, condense
)
72 if ((op
= check_duplicate(obj
, pack
)) != NULL
) {
76 obj
->ichar
= next_avail_ichar();
79 if (pack
->next_object
== 0) {
80 pack
->next_object
= obj
;
82 op
= pack
->next_object
;
84 while (op
->next_object
) {
87 op
->next_object
= obj
;
94 take_from_pack(obj
, pack
)
97 while (pack
->next_object
!= obj
) {
98 pack
= pack
->next_object
;
100 pack
->next_object
= pack
->next_object
->next_object
;
103 /* Note: *status is set to 0 if the rogue attempts to pick up a scroll
104 * of scare-monster and it turns to dust. *status is otherwise set to 1.
108 pick_up(row
, col
, status
)
117 message("you're floating in the air!", 0);
118 return((object
*) 0);
120 obj
= object_at(&level_objects
, row
, col
);
122 message("pick_up(): inconsistent", 1);
125 if ( (obj
->what_is
== SCROL
) &&
126 (obj
->which_kind
== SCARE_MONSTER
) &&
128 message("the scroll turns to dust as you pick it up", 0);
129 dungeon
[row
][col
] &= (~OBJECT
);
130 vanish(obj
, 0, &level_objects
);
132 if (id_scrolls
[SCARE_MONSTER
].id_status
== UNIDENTIFIED
) {
133 id_scrolls
[SCARE_MONSTER
].id_status
= IDENTIFIED
;
135 return((object
*) 0);
137 if (obj
->what_is
== GOLD
) {
138 rogue
.gold
+= obj
->quantity
;
139 dungeon
[row
][col
] &= ~(OBJECT
);
140 take_from_pack(obj
, &level_objects
);
141 print_stats(STAT_GOLD
);
142 return(obj
); /* obj will be free_object()ed in caller */
144 if (pack_count(obj
) >= MAX_PACK_COUNT
) {
145 message("pack too full", 1);
146 return((object
*) 0);
148 dungeon
[row
][col
] &= ~(OBJECT
);
149 take_from_pack(obj
, &level_objects
);
150 obj
= add_to_pack(obj
, &rogue
.pack
, 1);
162 if (dungeon
[rogue
.row
][rogue
.col
] & (OBJECT
| STAIRS
| TRAP
)) {
163 message("there's already something there", 0);
166 if (!rogue
.pack
.next_object
) {
167 message("you have nothing to drop", 0);
170 if ((ch
= pack_letter("drop what?", ALL_OBJECTS
)) == CANCEL
) {
173 if (!(obj
= get_letter_object(ch
))) {
174 message("no such item.", 0);
177 if (obj
->in_use_flags
& BEING_WIELDED
) {
178 if (obj
->is_cursed
) {
179 message(curse_message
, 0);
182 unwield(rogue
.weapon
);
183 } else if (obj
->in_use_flags
& BEING_WORN
) {
184 if (obj
->is_cursed
) {
185 message(curse_message
, 0);
190 print_stats(STAT_ARMOR
);
191 } else if (obj
->in_use_flags
& ON_EITHER_HAND
) {
192 if (obj
->is_cursed
) {
193 message(curse_message
, 0);
198 obj
->row
= rogue
.row
;
199 obj
->col
= rogue
.col
;
201 if ((obj
->quantity
> 1) && (obj
->what_is
!= WEAPON
)) {
203 new = alloc_object();
209 take_from_pack(obj
, &rogue
.pack
);
211 place_at(obj
, rogue
.row
, rogue
.col
);
212 (void) strcpy(desc
, "dropped ");
213 get_desc(obj
, desc
+8);
219 check_duplicate(obj
, pack
)
224 if (!(obj
->what_is
& (WEAPON
| FOOD
| SCROL
| POTION
))) {
227 if ((obj
->what_is
== FOOD
) && (obj
->which_kind
== FRUIT
)) {
230 op
= pack
->next_object
;
233 if ((op
->what_is
== obj
->what_is
) &&
234 (op
->which_kind
== obj
->which_kind
)) {
236 if ((obj
->what_is
!= WEAPON
) ||
237 ((obj
->what_is
== WEAPON
) &&
238 ((obj
->which_kind
== ARROW
) ||
239 (obj
->which_kind
== DAGGER
) ||
240 (obj
->which_kind
== DART
) ||
241 (obj
->which_kind
== SHURIKEN
)) &&
242 (obj
->quiver
== op
->quiver
))) {
243 op
->quantity
+= obj
->quantity
;
247 op
= op
->next_object
;
259 for (i
= 0; i
< 26; i
++) {
262 obj
= rogue
.pack
.next_object
;
264 ichars
[(obj
->ichar
- 'a')] = 1;
265 obj
= obj
->next_object
;
267 for (i
= 0; i
< 26; i
++) {
278 while (rgetchar() != ' ') ;
282 pack_letter(prompt
, mask
)
287 unsigned short tmask
= mask
;
289 if (!mask_pack(&rogue
.pack
, mask
)) {
290 message("nothing appropriate", 0);
299 if (!is_pack_letter(&ch
, &mask
)) {
309 inventory(&rogue
.pack
, mask
);
326 if (rogue
.armor
->is_cursed
) {
327 message(curse_message
, 0);
332 (void) strcpy(desc
, "was wearing ");
333 get_desc(obj
, desc
+12);
335 print_stats(STAT_ARMOR
);
339 message("not wearing any", 0);
351 message("your already wearing some", 0);
354 ch
= pack_letter("wear what?", ARMOR
);
359 if (!(obj
= get_letter_object(ch
))) {
360 message("no such item.", 0);
363 if (obj
->what_is
!= ARMOR
) {
364 message("you can't wear that", 0);
368 (void) strcpy(desc
, "wearing ");
369 get_desc(obj
, desc
+ 8);
372 print_stats(STAT_ARMOR
);
381 obj
->in_use_flags
&= (~BEING_WORN
);
383 rogue
.armor
= (object
*) 0;
391 obj
->in_use_flags
|= BEING_WORN
;
402 if (rogue
.weapon
&& rogue
.weapon
->is_cursed
) {
403 message(curse_message
, 0);
406 ch
= pack_letter("wield what?", WEAPON
);
411 if (!(obj
= get_letter_object(ch
))) {
412 message("No such item.", 0);
415 if (obj
->what_is
& (ARMOR
| RING
)) {
416 sprintf(desc
, "you can't wield %s",
417 ((obj
->what_is
== ARMOR
) ? "armor" : "rings"));
421 if (obj
->in_use_flags
& BEING_WIELDED
) {
422 message("in use", 0);
424 unwield(rogue
.weapon
);
425 (void) strcpy(desc
, "wielding ");
426 get_desc(obj
, desc
+ 9);
438 obj
->in_use_flags
|= BEING_WIELDED
;
446 obj
->in_use_flags
&= (~BEING_WIELDED
);
448 rogue
.weapon
= (object
*) 0;
457 char buf
[MAX_TITLE_LENGTH
+2];
459 ch
= pack_letter("call what?", (SCROL
| POTION
| WAND
| RING
));
464 if (!(obj
= get_letter_object(ch
))) {
465 message("no such item.", 0);
468 if (!(obj
->what_is
& (SCROL
| POTION
| WAND
| RING
))) {
469 message("surely you already know what that's called", 0);
472 id_table
= get_id_table(obj
);
474 if (get_input_line("call it:","",buf
,id_table
[obj
->which_kind
].title
,1,1)) {
475 id_table
[obj
->which_kind
].id_status
= CALLED
;
476 (void) strcpy(id_table
[obj
->which_kind
].title
, buf
);
487 obj
= rogue
.pack
.next_object
;
490 if (obj
->what_is
!= WEAPON
) {
491 count
+= obj
->quantity
;
492 } else if (!new_obj
) {
494 } else if ((new_obj
->what_is
!= WEAPON
) ||
495 ((obj
->which_kind
!= ARROW
) &&
496 (obj
->which_kind
!= DAGGER
) &&
497 (obj
->which_kind
!= DART
) &&
498 (obj
->which_kind
!= SHURIKEN
)) ||
499 (new_obj
->which_kind
!= obj
->which_kind
) ||
500 (obj
->quiver
!= new_obj
->quiver
)) {
503 obj
= obj
->next_object
;
509 mask_pack(pack
, mask
)
513 while (pack
->next_object
) {
514 pack
= pack
->next_object
;
515 if (pack
->what_is
& mask
) {
523 is_pack_letter(c
, mask
)
525 unsigned short *mask
;
527 if (((*c
== '?') || (*c
== '!') || (*c
== ':') || (*c
== '=') ||
528 (*c
== ')') || (*c
== ']') || (*c
== '/') || (*c
== ','))) {
558 return(((*c
>= 'a') && (*c
<= 'z')) || (*c
== CANCEL
) || (*c
== LIST
));
564 return(mask_pack(&rogue
.pack
, AMULET
));
574 if (!(dungeon
[rogue
.row
][rogue
.col
] & OBJECT
)) {
575 message("nothing here", 0);
577 if ((obj
= pick_up(rogue
.row
, rogue
.col
, &stat
)) != NULL
) {
579 if (obj
->what_is
== GOLD
) {
585 desc
[n
+1] = obj
->ichar
;
591 if (obj
|| (!stat
)) {