]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/pack.c
46c580cfba36f9efbf6d1c7fc02305497dc2b27f
2 * Copyright (c) 1988 The Regents of the University of California.
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. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 /*static char sccsid[] = "from: @(#)pack.c 5.3 (Berkeley) 6/1/90";*/
39 static char rcsid
[] = "$Id: pack.c,v 1.2 1993/08/01 18:52:20 mycroft Exp $";
45 * This source herein may be modified and/or distributed by anybody who
46 * so desires, with the following restrictions:
47 * 1.) No portion of this notice shall be removed.
48 * 2.) Credit shall not be taken for the creation of this source.
49 * 3.) This code is not to be traded, sold, or used for personal
56 char *curse_message
= "you can't, it appears to be cursed";
58 extern short levitate
;
61 add_to_pack(obj
, pack
, condense
)
67 if (op
= check_duplicate(obj
, pack
)) {
71 obj
->ichar
= next_avail_ichar();
74 if (pack
->next_object
== 0) {
75 pack
->next_object
= obj
;
77 op
= pack
->next_object
;
79 while (op
->next_object
) {
82 op
->next_object
= obj
;
88 take_from_pack(obj
, pack
)
91 while (pack
->next_object
!= obj
) {
92 pack
= pack
->next_object
;
94 pack
->next_object
= pack
->next_object
->next_object
;
97 /* Note: *status is set to 0 if the rogue attempts to pick up a scroll
98 * of scare-monster and it turns to dust. *status is otherwise set to 1.
102 pick_up(row
, col
, status
)
110 message("you're floating in the air!", 0);
111 return((object
*) 0);
113 obj
= object_at(&level_objects
, row
, col
);
115 message("pick_up(): inconsistent", 1);
118 if ( (obj
->what_is
== SCROL
) &&
119 (obj
->which_kind
== SCARE_MONSTER
) &&
121 message("the scroll turns to dust as you pick it up", 0);
122 dungeon
[row
][col
] &= (~OBJECT
);
123 vanish(obj
, 0, &level_objects
);
125 if (id_scrolls
[SCARE_MONSTER
].id_status
== UNIDENTIFIED
) {
126 id_scrolls
[SCARE_MONSTER
].id_status
= IDENTIFIED
;
128 return((object
*) 0);
130 if (obj
->what_is
== GOLD
) {
131 rogue
.gold
+= obj
->quantity
;
132 dungeon
[row
][col
] &= ~(OBJECT
);
133 take_from_pack(obj
, &level_objects
);
134 print_stats(STAT_GOLD
);
135 return(obj
); /* obj will be free_object()ed in caller */
137 if (pack_count(obj
) >= MAX_PACK_COUNT
) {
138 message("pack too full", 1);
139 return((object
*) 0);
141 dungeon
[row
][col
] &= ~(OBJECT
);
142 take_from_pack(obj
, &level_objects
);
143 obj
= add_to_pack(obj
, &rogue
.pack
, 1);
154 if (dungeon
[rogue
.row
][rogue
.col
] & (OBJECT
| STAIRS
| TRAP
)) {
155 message("there's already something there", 0);
158 if (!rogue
.pack
.next_object
) {
159 message("you have nothing to drop", 0);
162 if ((ch
= pack_letter("drop what?", ALL_OBJECTS
)) == CANCEL
) {
165 if (!(obj
= get_letter_object(ch
))) {
166 message("no such item.", 0);
169 if (obj
->in_use_flags
& BEING_WIELDED
) {
170 if (obj
->is_cursed
) {
171 message(curse_message
, 0);
174 unwield(rogue
.weapon
);
175 } else if (obj
->in_use_flags
& BEING_WORN
) {
176 if (obj
->is_cursed
) {
177 message(curse_message
, 0);
182 print_stats(STAT_ARMOR
);
183 } else if (obj
->in_use_flags
& ON_EITHER_HAND
) {
184 if (obj
->is_cursed
) {
185 message(curse_message
, 0);
190 obj
->row
= rogue
.row
;
191 obj
->col
= rogue
.col
;
193 if ((obj
->quantity
> 1) && (obj
->what_is
!= WEAPON
)) {
195 new = alloc_object();
201 take_from_pack(obj
, &rogue
.pack
);
203 place_at(obj
, rogue
.row
, rogue
.col
);
204 (void) strcpy(desc
, "dropped ");
205 get_desc(obj
, desc
+8);
211 check_duplicate(obj
, pack
)
216 if (!(obj
->what_is
& (WEAPON
| FOOD
| SCROL
| POTION
))) {
219 if ((obj
->what_is
== FOOD
) && (obj
->which_kind
== FRUIT
)) {
222 op
= pack
->next_object
;
225 if ((op
->what_is
== obj
->what_is
) &&
226 (op
->which_kind
== obj
->which_kind
)) {
228 if ((obj
->what_is
!= WEAPON
) ||
229 ((obj
->what_is
== WEAPON
) &&
230 ((obj
->which_kind
== ARROW
) ||
231 (obj
->which_kind
== DAGGER
) ||
232 (obj
->which_kind
== DART
) ||
233 (obj
->which_kind
== SHURIKEN
)) &&
234 (obj
->quiver
== op
->quiver
))) {
235 op
->quantity
+= obj
->quantity
;
239 op
= op
->next_object
;
246 register object
*obj
;
250 for (i
= 0; i
< 26; i
++) {
253 obj
= rogue
.pack
.next_object
;
255 ichars
[(obj
->ichar
- 'a')] = 1;
256 obj
= obj
->next_object
;
258 for (i
= 0; i
< 26; i
++) {
268 while (rgetchar() != ' ') ;
271 pack_letter(prompt
, mask
)
276 unsigned short tmask
= mask
;
278 if (!mask_pack(&rogue
.pack
, mask
)) {
279 message("nothing appropriate", 0);
288 if (!is_pack_letter(&ch
, &mask
)) {
297 inventory(&rogue
.pack
, mask
);
313 if (rogue
.armor
->is_cursed
) {
314 message(curse_message
, 0);
319 (void) strcpy(desc
, "was wearing ");
320 get_desc(obj
, desc
+12);
322 print_stats(STAT_ARMOR
);
326 message("not wearing any", 0);
333 register object
*obj
;
337 message("your already wearing some", 0);
340 ch
= pack_letter("wear what?", ARMOR
);
345 if (!(obj
= get_letter_object(ch
))) {
346 message("no such item.", 0);
349 if (obj
->what_is
!= ARMOR
) {
350 message("you can't wear that", 0);
354 (void) strcpy(desc
, "wearing ");
355 get_desc(obj
, desc
+ 8);
358 print_stats(STAT_ARMOR
);
366 obj
->in_use_flags
&= (~BEING_WORN
);
368 rogue
.armor
= (object
*) 0;
375 obj
->in_use_flags
|= BEING_WORN
;
382 register object
*obj
;
385 if (rogue
.weapon
&& rogue
.weapon
->is_cursed
) {
386 message(curse_message
, 0);
389 ch
= pack_letter("wield what?", WEAPON
);
394 if (!(obj
= get_letter_object(ch
))) {
395 message("No such item.", 0);
398 if (obj
->what_is
& (ARMOR
| RING
)) {
399 sprintf(desc
, "you can't wield %s",
400 ((obj
->what_is
== ARMOR
) ? "armor" : "rings"));
404 if (obj
->in_use_flags
& BEING_WIELDED
) {
405 message("in use", 0);
407 unwield(rogue
.weapon
);
408 (void) strcpy(desc
, "wielding ");
409 get_desc(obj
, desc
+ 9);
420 obj
->in_use_flags
|= BEING_WIELDED
;
427 obj
->in_use_flags
&= (~BEING_WIELDED
);
429 rogue
.weapon
= (object
*) 0;
435 register object
*obj
;
437 char buf
[MAX_TITLE_LENGTH
+2];
439 ch
= pack_letter("call what?", (SCROL
| POTION
| WAND
| RING
));
444 if (!(obj
= get_letter_object(ch
))) {
445 message("no such item.", 0);
448 if (!(obj
->what_is
& (SCROL
| POTION
| WAND
| RING
))) {
449 message("surely you already know what that's called", 0);
452 id_table
= get_id_table(obj
);
454 if (get_input_line("call it:","",buf
,id_table
[obj
->which_kind
].title
,1,1)) {
455 id_table
[obj
->which_kind
].id_status
= CALLED
;
456 (void) strcpy(id_table
[obj
->which_kind
].title
, buf
);
466 obj
= rogue
.pack
.next_object
;
469 if (obj
->what_is
!= WEAPON
) {
470 count
+= obj
->quantity
;
471 } else if (!new_obj
) {
473 } else if ((new_obj
->what_is
!= WEAPON
) ||
474 ((obj
->which_kind
!= ARROW
) &&
475 (obj
->which_kind
!= DAGGER
) &&
476 (obj
->which_kind
!= DART
) &&
477 (obj
->which_kind
!= SHURIKEN
)) ||
478 (new_obj
->which_kind
!= obj
->which_kind
) ||
479 (obj
->quiver
!= new_obj
->quiver
)) {
482 obj
= obj
->next_object
;
488 mask_pack(pack
, mask
)
492 while (pack
->next_object
) {
493 pack
= pack
->next_object
;
494 if (pack
->what_is
& mask
) {
501 is_pack_letter(c
, mask
)
503 unsigned short *mask
;
505 if (((*c
== '?') || (*c
== '!') || (*c
== ':') || (*c
== '=') ||
506 (*c
== ')') || (*c
== ']') || (*c
== '/') || (*c
== ','))) {
536 return(((*c
>= 'a') && (*c
<= 'z')) || (*c
== CANCEL
) || (*c
== LIST
));
541 return(mask_pack(&rogue
.pack
, AMULET
));
550 if (!(dungeon
[rogue
.row
][rogue
.col
] & OBJECT
)) {
551 message("nothing here", 0);
553 if (obj
= pick_up(rogue
.row
, rogue
.col
, &stat
)) {
555 if (obj
->what_is
== GOLD
) {
561 desc
[n
+1] = obj
->ichar
;
567 if (obj
|| (!stat
)) {